message.c 476 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521752275237524752575267527752875297530753175327533753475357536753775387539754075417542754375447545754675477548754975507551755275537554755575567557755875597560756175627563756475657566756775687569757075717572757375747575757675777578757975807581758275837584758575867587758875897590759175927593759475957596759775987599760076017602760376047605760676077608760976107611761276137614761576167617761876197620762176227623762476257626762776287629763076317632763376347635763676377638763976407641764276437644764576467647764876497650765176527653765476557656765776587659766076617662766376647665766676677668766976707671767276737674767576767677767876797680768176827683768476857686768776887689769076917692769376947695769676977698769977007701770277037704770577067707770877097710771177127713771477157716771777187719772077217722772377247725772677277728772977307731773277337734773577367737773877397740774177427743774477457746774777487749775077517752775377547755775677577758775977607761776277637764776577667767776877697770777177727773777477757776777777787779778077817782778377847785778677877788778977907791779277937794779577967797779877997800780178027803780478057806780778087809781078117812781378147815781678177818781978207821782278237824782578267827782878297830783178327833783478357836783778387839784078417842784378447845784678477848784978507851785278537854785578567857785878597860786178627863786478657866786778687869787078717872787378747875787678777878787978807881788278837884788578867887788878897890789178927893789478957896789778987899790079017902790379047905790679077908790979107911791279137914791579167917791879197920792179227923792479257926792779287929793079317932793379347935793679377938793979407941794279437944794579467947794879497950795179527953795479557956795779587959796079617962796379647965796679677968796979707971797279737974797579767977797879797980798179827983798479857986798779887989799079917992799379947995799679977998799980008001800280038004800580068007800880098010801180128013801480158016801780188019802080218022802380248025802680278028802980308031803280338034803580368037803880398040804180428043804480458046804780488049805080518052805380548055805680578058805980608061806280638064806580668067806880698070807180728073807480758076807780788079808080818082808380848085808680878088808980908091809280938094809580968097809880998100810181028103810481058106810781088109811081118112811381148115811681178118811981208121812281238124812581268127812881298130813181328133813481358136813781388139814081418142814381448145814681478148814981508151815281538154815581568157815881598160816181628163816481658166816781688169817081718172817381748175817681778178817981808181818281838184818581868187818881898190819181928193819481958196819781988199820082018202820382048205820682078208820982108211821282138214821582168217821882198220822182228223822482258226822782288229823082318232823382348235823682378238823982408241824282438244824582468247824882498250825182528253825482558256825782588259826082618262826382648265826682678268826982708271827282738274827582768277827882798280828182828283828482858286828782888289829082918292829382948295829682978298829983008301830283038304830583068307830883098310831183128313831483158316831783188319832083218322832383248325832683278328832983308331833283338334833583368337833883398340834183428343834483458346834783488349835083518352835383548355835683578358835983608361836283638364836583668367836883698370837183728373837483758376837783788379838083818382838383848385838683878388838983908391839283938394839583968397839883998400840184028403840484058406840784088409841084118412841384148415841684178418841984208421842284238424842584268427842884298430843184328433843484358436843784388439844084418442844384448445844684478448844984508451845284538454845584568457845884598460846184628463846484658466846784688469847084718472847384748475847684778478847984808481848284838484848584868487848884898490849184928493849484958496849784988499850085018502850385048505850685078508850985108511851285138514851585168517851885198520852185228523852485258526852785288529853085318532853385348535853685378538853985408541854285438544854585468547854885498550855185528553855485558556855785588559856085618562856385648565856685678568856985708571857285738574857585768577857885798580858185828583858485858586858785888589859085918592859385948595859685978598859986008601860286038604860586068607860886098610861186128613861486158616861786188619862086218622862386248625862686278628862986308631863286338634863586368637863886398640864186428643864486458646864786488649865086518652865386548655865686578658865986608661866286638664866586668667866886698670867186728673867486758676867786788679868086818682868386848685868686878688868986908691869286938694869586968697869886998700870187028703870487058706870787088709871087118712871387148715871687178718871987208721872287238724872587268727872887298730873187328733873487358736873787388739874087418742874387448745874687478748874987508751875287538754875587568757875887598760876187628763876487658766876787688769877087718772877387748775877687778778877987808781878287838784878587868787878887898790879187928793879487958796879787988799880088018802880388048805880688078808880988108811881288138814881588168817881888198820882188228823882488258826882788288829883088318832883388348835883688378838883988408841884288438844884588468847884888498850885188528853885488558856885788588859886088618862886388648865886688678868886988708871887288738874887588768877887888798880888188828883888488858886888788888889889088918892889388948895889688978898889989008901890289038904890589068907890889098910891189128913891489158916891789188919892089218922892389248925892689278928892989308931893289338934893589368937893889398940894189428943894489458946894789488949895089518952895389548955895689578958895989608961896289638964896589668967896889698970897189728973897489758976897789788979898089818982898389848985898689878988898989908991899289938994899589968997899889999000900190029003900490059006900790089009901090119012901390149015901690179018901990209021902290239024902590269027902890299030903190329033903490359036903790389039904090419042904390449045904690479048904990509051905290539054905590569057905890599060906190629063906490659066906790689069907090719072907390749075907690779078907990809081908290839084908590869087908890899090909190929093909490959096909790989099910091019102910391049105910691079108910991109111911291139114911591169117911891199120912191229123912491259126912791289129913091319132913391349135913691379138913991409141914291439144914591469147914891499150915191529153915491559156915791589159916091619162916391649165916691679168916991709171917291739174917591769177917891799180918191829183918491859186918791889189919091919192919391949195919691979198919992009201920292039204920592069207920892099210921192129213921492159216921792189219922092219222922392249225922692279228922992309231923292339234923592369237923892399240924192429243924492459246924792489249925092519252925392549255925692579258925992609261926292639264926592669267926892699270927192729273927492759276927792789279928092819282928392849285928692879288928992909291929292939294929592969297929892999300930193029303930493059306930793089309931093119312931393149315931693179318931993209321932293239324932593269327932893299330933193329333933493359336933793389339934093419342934393449345934693479348934993509351935293539354935593569357935893599360936193629363936493659366936793689369937093719372937393749375937693779378937993809381938293839384938593869387938893899390939193929393939493959396939793989399940094019402940394049405940694079408940994109411941294139414941594169417941894199420942194229423942494259426942794289429943094319432943394349435943694379438943994409441944294439444944594469447944894499450945194529453945494559456945794589459946094619462946394649465946694679468946994709471947294739474947594769477947894799480948194829483948494859486948794889489949094919492949394949495949694979498949995009501950295039504950595069507950895099510951195129513951495159516951795189519952095219522952395249525952695279528952995309531953295339534953595369537953895399540954195429543954495459546954795489549955095519552955395549555955695579558955995609561956295639564956595669567956895699570957195729573957495759576957795789579958095819582958395849585958695879588958995909591959295939594959595969597959895999600960196029603960496059606960796089609961096119612961396149615961696179618961996209621962296239624962596269627962896299630963196329633963496359636963796389639964096419642964396449645964696479648964996509651965296539654965596569657965896599660966196629663966496659666966796689669967096719672967396749675967696779678967996809681968296839684968596869687968896899690969196929693969496959696969796989699970097019702970397049705970697079708970997109711971297139714971597169717971897199720972197229723972497259726972797289729973097319732973397349735973697379738973997409741974297439744974597469747974897499750975197529753975497559756975797589759976097619762976397649765976697679768976997709771977297739774977597769777977897799780978197829783978497859786978797889789979097919792979397949795979697979798979998009801980298039804980598069807980898099810981198129813981498159816981798189819982098219822982398249825982698279828982998309831983298339834983598369837983898399840984198429843984498459846984798489849985098519852985398549855985698579858985998609861986298639864986598669867986898699870987198729873987498759876987798789879988098819882988398849885988698879888988998909891989298939894989598969897989898999900990199029903990499059906990799089909991099119912991399149915991699179918991999209921992299239924992599269927992899299930993199329933993499359936993799389939994099419942994399449945994699479948994999509951995299539954995599569957995899599960996199629963996499659966996799689969997099719972997399749975997699779978997999809981998299839984998599869987998899899990999199929993999499959996999799989999100001000110002100031000410005100061000710008100091001010011100121001310014100151001610017100181001910020100211002210023100241002510026100271002810029100301003110032100331003410035100361003710038100391004010041100421004310044100451004610047100481004910050100511005210053100541005510056100571005810059100601006110062100631006410065100661006710068100691007010071100721007310074100751007610077100781007910080100811008210083100841008510086100871008810089100901009110092100931009410095100961009710098100991010010101101021010310104101051010610107101081010910110101111011210113101141011510116101171011810119101201012110122101231012410125101261012710128101291013010131101321013310134101351013610137101381013910140101411014210143101441014510146101471014810149101501015110152101531015410155101561015710158101591016010161101621016310164101651016610167101681016910170101711017210173101741017510176101771017810179101801018110182101831018410185101861018710188101891019010191101921019310194101951019610197101981019910200102011020210203102041020510206102071020810209102101021110212102131021410215102161021710218102191022010221102221022310224102251022610227102281022910230102311023210233102341023510236102371023810239102401024110242102431024410245102461024710248102491025010251102521025310254102551025610257102581025910260102611026210263102641026510266102671026810269102701027110272102731027410275102761027710278102791028010281102821028310284102851028610287102881028910290102911029210293102941029510296102971029810299103001030110302103031030410305103061030710308103091031010311103121031310314103151031610317103181031910320103211032210323103241032510326103271032810329103301033110332103331033410335103361033710338103391034010341103421034310344103451034610347103481034910350103511035210353103541035510356103571035810359103601036110362103631036410365103661036710368103691037010371103721037310374103751037610377103781037910380103811038210383103841038510386103871038810389103901039110392103931039410395103961039710398103991040010401104021040310404104051040610407104081040910410104111041210413104141041510416104171041810419104201042110422104231042410425104261042710428104291043010431104321043310434104351043610437104381043910440104411044210443104441044510446104471044810449104501045110452104531045410455104561045710458104591046010461104621046310464104651046610467104681046910470104711047210473104741047510476104771047810479104801048110482104831048410485104861048710488104891049010491104921049310494104951049610497104981049910500105011050210503105041050510506105071050810509105101051110512105131051410515105161051710518105191052010521105221052310524105251052610527105281052910530105311053210533105341053510536105371053810539105401054110542105431054410545105461054710548105491055010551105521055310554105551055610557105581055910560105611056210563105641056510566105671056810569105701057110572105731057410575105761057710578105791058010581105821058310584105851058610587105881058910590105911059210593105941059510596105971059810599106001060110602106031060410605106061060710608106091061010611106121061310614106151061610617106181061910620106211062210623106241062510626106271062810629106301063110632106331063410635106361063710638106391064010641106421064310644106451064610647106481064910650106511065210653106541065510656106571065810659106601066110662106631066410665106661066710668106691067010671106721067310674106751067610677106781067910680106811068210683106841068510686106871068810689106901069110692106931069410695106961069710698106991070010701107021070310704107051070610707107081070910710107111071210713107141071510716107171071810719107201072110722107231072410725107261072710728107291073010731107321073310734107351073610737107381073910740107411074210743107441074510746107471074810749107501075110752107531075410755107561075710758107591076010761107621076310764107651076610767107681076910770107711077210773107741077510776107771077810779107801078110782107831078410785107861078710788107891079010791107921079310794107951079610797107981079910800108011080210803108041080510806108071080810809108101081110812108131081410815108161081710818108191082010821108221082310824108251082610827108281082910830108311083210833108341083510836108371083810839108401084110842108431084410845108461084710848108491085010851108521085310854108551085610857108581085910860108611086210863108641086510866108671086810869108701087110872108731087410875108761087710878108791088010881108821088310884108851088610887108881088910890108911089210893108941089510896108971089810899109001090110902109031090410905109061090710908109091091010911109121091310914109151091610917109181091910920109211092210923109241092510926109271092810929109301093110932109331093410935109361093710938109391094010941109421094310944109451094610947109481094910950109511095210953109541095510956109571095810959109601096110962109631096410965109661096710968109691097010971109721097310974109751097610977109781097910980109811098210983109841098510986109871098810989109901099110992109931099410995109961099710998109991100011001110021100311004110051100611007110081100911010110111101211013110141101511016110171101811019110201102111022110231102411025110261102711028110291103011031110321103311034110351103611037110381103911040110411104211043110441104511046110471104811049110501105111052110531105411055110561105711058110591106011061110621106311064110651106611067110681106911070110711107211073110741107511076110771107811079110801108111082110831108411085110861108711088110891109011091110921109311094110951109611097110981109911100111011110211103111041110511106111071110811109111101111111112111131111411115111161111711118111191112011121111221112311124111251112611127111281112911130111311113211133111341113511136111371113811139111401114111142111431114411145111461114711148111491115011151111521115311154111551115611157111581115911160111611116211163111641116511166111671116811169111701117111172111731117411175111761117711178111791118011181111821118311184111851118611187111881118911190111911119211193111941119511196111971119811199112001120111202112031120411205112061120711208112091121011211112121121311214112151121611217112181121911220112211122211223112241122511226112271122811229112301123111232112331123411235112361123711238112391124011241112421124311244112451124611247112481124911250112511125211253112541125511256112571125811259112601126111262112631126411265112661126711268112691127011271112721127311274112751127611277112781127911280112811128211283112841128511286112871128811289112901129111292112931129411295112961129711298112991130011301113021130311304113051130611307113081130911310113111131211313113141131511316113171131811319113201132111322113231132411325113261132711328113291133011331113321133311334113351133611337113381133911340113411134211343113441134511346113471134811349113501135111352113531135411355113561135711358113591136011361113621136311364113651136611367113681136911370113711137211373113741137511376113771137811379113801138111382113831138411385113861138711388113891139011391113921139311394113951139611397113981139911400114011140211403114041140511406114071140811409114101141111412114131141411415114161141711418114191142011421114221142311424114251142611427114281142911430114311143211433114341143511436114371143811439114401144111442114431144411445114461144711448114491145011451114521145311454114551145611457114581145911460114611146211463114641146511466114671146811469114701147111472114731147411475114761147711478114791148011481114821148311484114851148611487114881148911490114911149211493114941149511496114971149811499115001150111502115031150411505115061150711508115091151011511115121151311514115151151611517115181151911520115211152211523115241152511526115271152811529115301153111532115331153411535115361153711538115391154011541115421154311544115451154611547115481154911550115511155211553115541155511556115571155811559115601156111562115631156411565115661156711568115691157011571115721157311574115751157611577115781157911580115811158211583115841158511586115871158811589115901159111592115931159411595115961159711598115991160011601116021160311604116051160611607116081160911610116111161211613116141161511616116171161811619116201162111622116231162411625116261162711628116291163011631116321163311634116351163611637116381163911640116411164211643116441164511646116471164811649116501165111652116531165411655116561165711658116591166011661116621166311664116651166611667116681166911670116711167211673116741167511676116771167811679116801168111682116831168411685116861168711688116891169011691116921169311694116951169611697116981169911700117011170211703117041170511706117071170811709117101171111712117131171411715117161171711718117191172011721117221172311724117251172611727117281172911730117311173211733117341173511736117371173811739117401174111742117431174411745117461174711748117491175011751117521175311754117551175611757117581175911760117611176211763117641176511766117671176811769117701177111772117731177411775117761177711778117791178011781117821178311784117851178611787117881178911790117911179211793117941179511796117971179811799118001180111802118031180411805118061180711808118091181011811118121181311814118151181611817118181181911820118211182211823118241182511826118271182811829118301183111832118331183411835118361183711838118391184011841118421184311844118451184611847118481184911850118511185211853118541185511856118571185811859118601186111862118631186411865118661186711868118691187011871118721187311874118751187611877118781187911880118811188211883118841188511886118871188811889118901189111892118931189411895118961189711898118991190011901119021190311904119051190611907119081190911910119111191211913119141191511916119171191811919119201192111922119231192411925119261192711928119291193011931119321193311934119351193611937119381193911940119411194211943119441194511946119471194811949119501195111952119531195411955119561195711958119591196011961119621196311964119651196611967119681196911970119711197211973119741197511976119771197811979119801198111982119831198411985119861198711988119891199011991119921199311994119951199611997119981199912000120011200212003120041200512006120071200812009120101201112012120131201412015120161201712018120191202012021120221202312024120251202612027120281202912030120311203212033120341203512036120371203812039120401204112042120431204412045120461204712048120491205012051120521205312054120551205612057120581205912060120611206212063120641206512066120671206812069120701207112072120731207412075120761207712078120791208012081120821208312084120851208612087120881208912090120911209212093120941209512096120971209812099121001210112102121031210412105121061210712108121091211012111121121211312114121151211612117121181211912120121211212212123121241212512126121271212812129121301213112132121331213412135121361213712138121391214012141121421214312144121451214612147121481214912150121511215212153121541215512156121571215812159121601216112162121631216412165121661216712168121691217012171121721217312174121751217612177121781217912180121811218212183121841218512186121871218812189121901219112192121931219412195121961219712198121991220012201122021220312204122051220612207122081220912210122111221212213122141221512216122171221812219122201222112222122231222412225122261222712228122291223012231122321223312234122351223612237122381223912240122411224212243122441224512246122471224812249122501225112252122531225412255122561225712258122591226012261122621226312264122651226612267122681226912270122711227212273122741227512276122771227812279122801228112282122831228412285122861228712288122891229012291122921229312294122951229612297122981229912300123011230212303123041230512306123071230812309123101231112312123131231412315123161231712318123191232012321123221232312324123251232612327123281232912330123311233212333123341233512336123371233812339123401234112342123431234412345123461234712348123491235012351123521235312354123551235612357123581235912360123611236212363123641236512366123671236812369123701237112372123731237412375123761237712378123791238012381123821238312384123851238612387123881238912390123911239212393123941239512396123971239812399124001240112402124031240412405124061240712408124091241012411124121241312414124151241612417124181241912420124211242212423124241242512426124271242812429124301243112432124331243412435124361243712438124391244012441124421244312444124451244612447124481244912450124511245212453124541245512456124571245812459124601246112462124631246412465124661246712468124691247012471124721247312474124751247612477124781247912480124811248212483124841248512486124871248812489124901249112492124931249412495124961249712498124991250012501125021250312504125051250612507125081250912510125111251212513125141251512516125171251812519125201252112522125231252412525125261252712528125291253012531125321253312534125351253612537125381253912540125411254212543125441254512546125471254812549125501255112552125531255412555125561255712558125591256012561125621256312564125651256612567125681256912570125711257212573125741257512576125771257812579125801258112582125831258412585125861258712588125891259012591125921259312594125951259612597125981259912600126011260212603126041260512606126071260812609126101261112612126131261412615126161261712618126191262012621126221262312624126251262612627126281262912630126311263212633126341263512636126371263812639126401264112642126431264412645126461264712648126491265012651126521265312654126551265612657126581265912660126611266212663126641266512666126671266812669126701267112672126731267412675126761267712678126791268012681126821268312684126851268612687126881268912690126911269212693126941269512696126971269812699127001270112702127031270412705127061270712708127091271012711127121271312714127151271612717127181271912720127211272212723127241272512726127271272812729127301273112732127331273412735127361273712738127391274012741127421274312744127451274612747127481274912750127511275212753127541275512756127571275812759127601276112762127631276412765127661276712768127691277012771127721277312774127751277612777127781277912780127811278212783127841278512786127871278812789127901279112792127931279412795127961279712798127991280012801128021280312804128051280612807128081280912810128111281212813128141281512816128171281812819128201282112822128231282412825128261282712828128291283012831128321283312834128351283612837128381283912840128411284212843128441284512846128471284812849128501285112852128531285412855128561285712858128591286012861128621286312864128651286612867128681286912870128711287212873128741287512876128771287812879128801288112882128831288412885128861288712888128891289012891128921289312894128951289612897128981289912900129011290212903129041290512906129071290812909129101291112912129131291412915129161291712918129191292012921129221292312924129251292612927129281292912930129311293212933129341293512936129371293812939129401294112942129431294412945129461294712948129491295012951129521295312954129551295612957129581295912960129611296212963129641296512966129671296812969129701297112972129731297412975129761297712978129791298012981129821298312984129851298612987129881298912990129911299212993129941299512996129971299812999130001300113002130031300413005130061300713008130091301013011130121301313014130151301613017130181301913020130211302213023130241302513026130271302813029130301303113032130331303413035130361303713038130391304013041130421304313044130451304613047130481304913050130511305213053130541305513056130571305813059130601306113062130631306413065130661306713068130691307013071130721307313074130751307613077130781307913080130811308213083130841308513086130871308813089130901309113092130931309413095130961309713098130991310013101131021310313104131051310613107131081310913110131111311213113131141311513116131171311813119131201312113122131231312413125131261312713128131291313013131131321313313134131351313613137131381313913140131411314213143131441314513146131471314813149131501315113152131531315413155131561315713158131591316013161131621316313164131651316613167131681316913170131711317213173131741317513176131771317813179131801318113182131831318413185131861318713188131891319013191131921319313194131951319613197131981319913200132011320213203132041320513206132071320813209132101321113212132131321413215132161321713218132191322013221132221322313224132251322613227132281322913230132311323213233132341323513236132371323813239132401324113242132431324413245132461324713248132491325013251132521325313254132551325613257132581325913260132611326213263132641326513266132671326813269132701327113272132731327413275132761327713278132791328013281132821328313284132851328613287132881328913290132911329213293132941329513296132971329813299133001330113302133031330413305133061330713308133091331013311133121331313314133151331613317133181331913320133211332213323133241332513326133271332813329133301333113332133331333413335133361333713338133391334013341133421334313344133451334613347133481334913350133511335213353133541335513356133571335813359133601336113362133631336413365133661336713368133691337013371133721337313374133751337613377133781337913380133811338213383133841338513386133871338813389133901339113392133931339413395133961339713398133991340013401134021340313404134051340613407134081340913410134111341213413134141341513416134171341813419134201342113422134231342413425134261342713428134291343013431134321343313434134351343613437134381343913440134411344213443134441344513446134471344813449134501345113452134531345413455134561345713458134591346013461134621346313464134651346613467134681346913470134711347213473134741347513476134771347813479134801348113482134831348413485134861348713488134891349013491134921349313494134951349613497134981349913500135011350213503135041350513506135071350813509135101351113512135131351413515135161351713518135191352013521135221352313524135251352613527135281352913530135311353213533135341353513536135371353813539135401354113542135431354413545135461354713548135491355013551135521355313554135551355613557135581355913560135611356213563135641356513566135671356813569135701357113572135731357413575135761357713578135791358013581135821358313584135851358613587135881358913590135911359213593135941359513596135971359813599136001360113602136031360413605136061360713608136091361013611136121361313614136151361613617136181361913620136211362213623136241362513626136271362813629136301363113632136331363413635136361363713638136391364013641136421364313644136451364613647136481364913650136511365213653136541365513656136571365813659136601366113662136631366413665136661366713668136691367013671136721367313674136751367613677136781367913680136811368213683136841368513686136871368813689136901369113692136931369413695136961369713698136991370013701137021370313704137051370613707137081370913710137111371213713137141371513716137171371813719137201372113722137231372413725137261372713728137291373013731137321373313734137351373613737137381373913740137411374213743137441374513746137471374813749137501375113752137531375413755137561375713758137591376013761137621376313764137651376613767137681376913770137711377213773137741377513776137771377813779137801378113782137831378413785137861378713788137891379013791137921379313794137951379613797137981379913800138011380213803138041380513806138071380813809138101381113812138131381413815138161381713818138191382013821138221382313824138251382613827138281382913830138311383213833138341383513836138371383813839138401384113842138431384413845138461384713848138491385013851138521385313854138551385613857138581385913860138611386213863138641386513866138671386813869138701387113872138731387413875138761387713878138791388013881138821388313884138851388613887138881388913890138911389213893138941389513896138971389813899139001390113902139031390413905139061390713908139091391013911139121391313914139151391613917139181391913920139211392213923139241392513926139271392813929139301393113932139331393413935139361393713938139391394013941139421394313944139451394613947139481394913950139511395213953139541395513956139571395813959139601396113962139631396413965139661396713968139691397013971139721397313974139751397613977139781397913980139811398213983139841398513986139871398813989139901399113992139931399413995139961399713998139991400014001140021400314004140051400614007140081400914010140111401214013140141401514016140171401814019140201402114022140231402414025140261402714028140291403014031140321403314034140351403614037140381403914040140411404214043140441404514046140471404814049140501405114052140531405414055140561405714058140591406014061140621406314064140651406614067140681406914070140711407214073140741407514076140771407814079140801408114082140831408414085140861408714088140891409014091140921409314094140951409614097140981409914100141011410214103141041410514106141071410814109141101411114112141131411414115141161411714118141191412014121141221412314124141251412614127141281412914130141311413214133141341413514136141371413814139141401414114142141431414414145141461414714148141491415014151141521415314154141551415614157141581415914160141611416214163141641416514166141671416814169141701417114172141731417414175141761417714178141791418014181141821418314184141851418614187141881418914190141911419214193141941419514196141971419814199142001420114202142031420414205142061420714208142091421014211142121421314214142151421614217142181421914220142211422214223142241422514226142271422814229142301423114232142331423414235142361423714238142391424014241142421424314244142451424614247142481424914250142511425214253142541425514256142571425814259142601426114262142631426414265142661426714268142691427014271142721427314274142751427614277142781427914280142811428214283142841428514286142871428814289142901429114292142931429414295142961429714298142991430014301143021430314304143051430614307143081430914310143111431214313143141431514316143171431814319143201432114322143231432414325143261432714328143291433014331143321433314334143351433614337143381433914340143411434214343143441434514346143471434814349143501435114352143531435414355143561435714358143591436014361143621436314364143651436614367143681436914370143711437214373143741437514376143771437814379143801438114382143831438414385143861438714388143891439014391143921439314394143951439614397143981439914400144011440214403144041440514406144071440814409144101441114412144131441414415144161441714418144191442014421144221442314424144251442614427144281442914430144311443214433144341443514436144371443814439144401444114442144431444414445144461444714448144491445014451144521445314454144551445614457144581445914460144611446214463144641446514466144671446814469144701447114472144731447414475144761447714478144791448014481144821448314484144851448614487144881448914490144911449214493144941449514496144971449814499145001450114502145031450414505145061450714508145091451014511145121451314514145151451614517145181451914520145211452214523145241452514526145271452814529145301453114532145331453414535145361453714538145391454014541145421454314544145451454614547145481454914550145511455214553145541455514556145571455814559145601456114562145631456414565145661456714568145691457014571145721457314574145751457614577145781457914580145811458214583145841458514586145871458814589145901459114592145931459414595145961459714598145991460014601146021460314604146051460614607146081460914610146111461214613146141461514616146171461814619146201462114622146231462414625146261462714628146291463014631146321463314634146351463614637146381463914640146411464214643146441464514646146471464814649146501465114652146531465414655146561465714658146591466014661146621466314664146651466614667146681466914670146711467214673146741467514676146771467814679146801468114682146831468414685146861468714688146891469014691146921469314694146951469614697146981469914700147011470214703147041470514706147071470814709147101471114712147131471414715147161471714718147191472014721147221472314724147251472614727147281472914730147311473214733147341473514736147371473814739147401474114742147431474414745147461474714748147491475014751147521475314754147551475614757147581475914760147611476214763147641476514766147671476814769147701477114772147731477414775147761477714778147791478014781147821478314784147851478614787147881478914790147911479214793147941479514796147971479814799148001480114802148031480414805148061480714808148091481014811148121481314814148151481614817148181481914820148211482214823148241482514826148271482814829148301483114832148331483414835148361483714838148391484014841148421484314844148451484614847148481484914850148511485214853148541485514856148571485814859148601486114862148631486414865148661486714868148691487014871148721487314874148751487614877148781487914880148811488214883148841488514886148871488814889148901489114892148931489414895148961489714898148991490014901149021490314904149051490614907149081490914910149111491214913149141491514916149171491814919149201492114922149231492414925149261492714928149291493014931149321493314934149351493614937149381493914940149411494214943149441494514946149471494814949149501495114952149531495414955149561495714958149591496014961149621496314964149651496614967149681496914970149711497214973149741497514976149771497814979149801498114982149831498414985149861498714988149891499014991149921499314994149951499614997149981499915000150011500215003150041500515006150071500815009150101501115012150131501415015150161501715018150191502015021150221502315024150251502615027150281502915030150311503215033150341503515036150371503815039150401504115042150431504415045150461504715048150491505015051
  1. /*
  2. *
  3. Copyright (c) Eicon Networks, 2002.
  4. *
  5. This source file is supplied for the use with
  6. Eicon Networks range of DIVA Server Adapters.
  7. *
  8. Eicon File Revision : 2.1
  9. *
  10. This program is free software; you can redistribute it and/or modify
  11. it under the terms of the GNU General Public License as published by
  12. the Free Software Foundation; either version 2, or (at your option)
  13. any later version.
  14. *
  15. This program is distributed in the hope that it will be useful,
  16. but WITHOUT ANY WARRANTY OF ANY KIND WHATSOEVER INCLUDING ANY
  17. implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  18. See the GNU General Public License for more details.
  19. *
  20. You should have received a copy of the GNU General Public License
  21. along with this program; if not, write to the Free Software
  22. Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  23. *
  24. */
  25. #include "platform.h"
  26. #include "di_defs.h"
  27. #include "pc.h"
  28. #include "capi20.h"
  29. #include "divacapi.h"
  30. #include "mdm_msg.h"
  31. #include "divasync.h"
  32. #define FILE_ "MESSAGE.C"
  33. #define dprintf
  34. /*------------------------------------------------------------------*/
  35. /* This is options supported for all adapters that are server by */
  36. /* XDI driver. Allo it is not necessary to ask it from every adapter*/
  37. /* and it is not necessary to save it separate for every adapter */
  38. /* Macrose defined here have only local meaning */
  39. /*------------------------------------------------------------------*/
  40. static dword diva_xdi_extended_features = 0;
  41. #define DIVA_CAPI_USE_CMA 0x00000001
  42. #define DIVA_CAPI_XDI_PROVIDES_SDRAM_BAR 0x00000002
  43. #define DIVA_CAPI_XDI_PROVIDES_NO_CANCEL 0x00000004
  44. #define DIVA_CAPI_XDI_PROVIDES_RX_DMA 0x00000008
  45. /*
  46. CAPI can request to process all return codes self only if:
  47. protocol code supports this && xdi supports this
  48. */
  49. #define DIVA_CAPI_SUPPORTS_NO_CANCEL(__a__) (((__a__)->manufacturer_features&MANUFACTURER_FEATURE_XONOFF_FLOW_CONTROL)&& ((__a__)->manufacturer_features & MANUFACTURER_FEATURE_OK_FC_LABEL) && (diva_xdi_extended_features & DIVA_CAPI_XDI_PROVIDES_NO_CANCEL))
  50. /*------------------------------------------------------------------*/
  51. /* local function prototypes */
  52. /*------------------------------------------------------------------*/
  53. static void group_optimization(DIVA_CAPI_ADAPTER * a, PLCI * plci);
  54. static void set_group_ind_mask (PLCI *plci);
  55. static void clear_group_ind_mask_bit (PLCI *plci, word b);
  56. static byte test_group_ind_mask_bit (PLCI *plci, word b);
  57. void AutomaticLaw(DIVA_CAPI_ADAPTER *);
  58. word CapiRelease(word);
  59. word CapiRegister(word);
  60. word api_put(APPL *, CAPI_MSG *);
  61. static word api_parse(byte *, word, byte *, API_PARSE *);
  62. static void api_save_msg(API_PARSE *in, byte *format, API_SAVE *out);
  63. static void api_load_msg(API_SAVE *in, API_PARSE *out);
  64. word api_remove_start(void);
  65. void api_remove_complete(void);
  66. static void plci_remove(PLCI *);
  67. static void diva_get_extended_adapter_features (DIVA_CAPI_ADAPTER * a);
  68. static void diva_ask_for_xdi_sdram_bar (DIVA_CAPI_ADAPTER *, IDI_SYNC_REQ *);
  69. void callback(ENTITY *);
  70. static void control_rc(PLCI *, byte, byte, byte, byte, byte);
  71. static void data_rc(PLCI *, byte);
  72. static void data_ack(PLCI *, byte);
  73. static void sig_ind(PLCI *);
  74. static void SendInfo(PLCI *, dword, byte * *, byte);
  75. static void SendSetupInfo(APPL *, PLCI *, dword, byte * *, byte);
  76. static void SendSSExtInd(APPL *, PLCI * plci, dword Id, byte * * parms);
  77. static void VSwitchReqInd(PLCI *plci, dword Id, byte **parms);
  78. static void nl_ind(PLCI *);
  79. static byte connect_req(dword, word, DIVA_CAPI_ADAPTER *, PLCI *, APPL *, API_PARSE *);
  80. static byte connect_res(dword, word, DIVA_CAPI_ADAPTER *, PLCI *, APPL *, API_PARSE *);
  81. static byte connect_a_res(dword,word, DIVA_CAPI_ADAPTER *, PLCI *, APPL *, API_PARSE *);
  82. static byte disconnect_req(dword, word, DIVA_CAPI_ADAPTER *, PLCI *, APPL *, API_PARSE *);
  83. static byte disconnect_res(dword, word, DIVA_CAPI_ADAPTER *, PLCI *, APPL *, API_PARSE *);
  84. static byte listen_req(dword, word, DIVA_CAPI_ADAPTER *, PLCI *, APPL *, API_PARSE *);
  85. static byte info_req(dword, word, DIVA_CAPI_ADAPTER *, PLCI *, APPL *, API_PARSE *);
  86. static byte info_res(dword, word, DIVA_CAPI_ADAPTER *, PLCI *, APPL *, API_PARSE *);
  87. static byte alert_req(dword, word, DIVA_CAPI_ADAPTER *, PLCI *, APPL *, API_PARSE *);
  88. static byte facility_req(dword, word, DIVA_CAPI_ADAPTER *, PLCI *, APPL *, API_PARSE *);
  89. static byte facility_res(dword, word, DIVA_CAPI_ADAPTER *, PLCI *, APPL *, API_PARSE *);
  90. static byte connect_b3_req(dword, word, DIVA_CAPI_ADAPTER *, PLCI *, APPL *, API_PARSE *);
  91. static byte connect_b3_res(dword, word, DIVA_CAPI_ADAPTER *, PLCI *, APPL *, API_PARSE *);
  92. static byte connect_b3_a_res(dword, word, DIVA_CAPI_ADAPTER *, PLCI *, APPL *, API_PARSE *);
  93. static byte disconnect_b3_req(dword, word, DIVA_CAPI_ADAPTER *, PLCI *, APPL *, API_PARSE *);
  94. static byte disconnect_b3_res(dword, word, DIVA_CAPI_ADAPTER *, PLCI *, APPL *, API_PARSE *);
  95. static byte data_b3_req(dword, word, DIVA_CAPI_ADAPTER *, PLCI *, APPL *, API_PARSE *);
  96. static byte data_b3_res(dword, word, DIVA_CAPI_ADAPTER *, PLCI *, APPL *, API_PARSE *);
  97. static byte reset_b3_req(dword, word, DIVA_CAPI_ADAPTER *, PLCI *, APPL *, API_PARSE *);
  98. static byte reset_b3_res(dword, word, DIVA_CAPI_ADAPTER *, PLCI *, APPL *, API_PARSE *);
  99. static byte connect_b3_t90_a_res(dword, word, DIVA_CAPI_ADAPTER *, PLCI *, APPL *, API_PARSE *);
  100. static byte select_b_req(dword, word, DIVA_CAPI_ADAPTER *, PLCI *, APPL *, API_PARSE *);
  101. static byte manufacturer_req(dword, word, DIVA_CAPI_ADAPTER *, PLCI *, APPL *, API_PARSE *);
  102. static byte manufacturer_res(dword, word, DIVA_CAPI_ADAPTER *, PLCI *, APPL *, API_PARSE *);
  103. static word get_plci(DIVA_CAPI_ADAPTER *);
  104. static void add_p(PLCI *, byte, byte *);
  105. static void add_s(PLCI * plci, byte code, API_PARSE * p);
  106. static void add_ss(PLCI * plci, byte code, API_PARSE * p);
  107. static void add_ie(PLCI * plci, byte code, byte * p, word p_length);
  108. static void add_d(PLCI *, word, byte *);
  109. static void add_ai(PLCI *, API_PARSE *);
  110. static word add_b1(PLCI *, API_PARSE *, word, word);
  111. static word add_b23(PLCI *, API_PARSE *);
  112. static word add_modem_b23 (PLCI * plci, API_PARSE* bp_parms);
  113. static void sig_req(PLCI *, byte, byte);
  114. static void nl_req_ncci(PLCI *, byte, byte);
  115. static void send_req(PLCI *);
  116. static void send_data(PLCI *);
  117. static word plci_remove_check(PLCI *);
  118. static void listen_check(DIVA_CAPI_ADAPTER *);
  119. static byte AddInfo(byte **, byte **, byte *, byte *);
  120. static byte getChannel(API_PARSE *);
  121. static void IndParse(PLCI *, word *, byte **, byte);
  122. static byte ie_compare(byte *, byte *);
  123. static word find_cip(DIVA_CAPI_ADAPTER *, byte *, byte *);
  124. static word CPN_filter_ok(byte *cpn,DIVA_CAPI_ADAPTER *,word);
  125. /*
  126. XON protocol helpers
  127. */
  128. static void channel_flow_control_remove (PLCI * plci);
  129. static void channel_x_off (PLCI * plci, byte ch, byte flag);
  130. static void channel_x_on (PLCI * plci, byte ch);
  131. static void channel_request_xon (PLCI * plci, byte ch);
  132. static void channel_xmit_xon (PLCI * plci);
  133. static int channel_can_xon (PLCI * plci, byte ch);
  134. static void channel_xmit_extended_xon (PLCI * plci);
  135. static byte SendMultiIE(PLCI * plci, dword Id, byte * * parms, byte ie_type, dword info_mask, byte setupParse);
  136. static word AdvCodecSupport(DIVA_CAPI_ADAPTER *, PLCI *, APPL *, byte);
  137. static void CodecIdCheck(DIVA_CAPI_ADAPTER *, PLCI *);
  138. static void SetVoiceChannel(PLCI *, byte *, DIVA_CAPI_ADAPTER * );
  139. static void VoiceChannelOff(PLCI *plci);
  140. static void adv_voice_write_coefs (PLCI *plci, word write_command);
  141. static void adv_voice_clear_config (PLCI *plci);
  142. static word get_b1_facilities (PLCI * plci, byte b1_resource);
  143. static byte add_b1_facilities (PLCI * plci, byte b1_resource, word b1_facilities);
  144. static void adjust_b1_facilities (PLCI *plci, byte new_b1_resource, word new_b1_facilities);
  145. static word adjust_b_process (dword Id, PLCI *plci, byte Rc);
  146. static void adjust_b1_resource (dword Id, PLCI *plci, API_SAVE *bp_msg, word b1_facilities, word internal_command);
  147. static void adjust_b_restore (dword Id, PLCI *plci, byte Rc);
  148. static void reset_b3_command (dword Id, PLCI *plci, byte Rc);
  149. static void select_b_command (dword Id, PLCI *plci, byte Rc);
  150. static void fax_connect_ack_command (dword Id, PLCI *plci, byte Rc);
  151. static void fax_edata_ack_command (dword Id, PLCI *plci, byte Rc);
  152. static void fax_connect_info_command (dword Id, PLCI *plci, byte Rc);
  153. static void fax_adjust_b23_command (dword Id, PLCI *plci, byte Rc);
  154. static void fax_disconnect_command (dword Id, PLCI *plci, byte Rc);
  155. static void hold_save_command (dword Id, PLCI *plci, byte Rc);
  156. static void retrieve_restore_command (dword Id, PLCI *plci, byte Rc);
  157. static void init_b1_config (PLCI *plci);
  158. static void clear_b1_config (PLCI *plci);
  159. static void dtmf_command (dword Id, PLCI *plci, byte Rc);
  160. static byte dtmf_request (dword Id, word Number, DIVA_CAPI_ADAPTER *a, PLCI *plci, APPL *appl, API_PARSE *msg);
  161. static void dtmf_confirmation (dword Id, PLCI *plci);
  162. static void dtmf_indication (dword Id, PLCI *plci, byte *msg, word length);
  163. static void dtmf_parameter_write (PLCI *plci);
  164. static void mixer_set_bchannel_id_esc (PLCI *plci, byte bchannel_id);
  165. static void mixer_set_bchannel_id (PLCI *plci, byte *chi);
  166. static void mixer_clear_config (PLCI *plci);
  167. static void mixer_notify_update (PLCI *plci, byte others);
  168. static void mixer_command (dword Id, PLCI *plci, byte Rc);
  169. static byte mixer_request (dword Id, word Number, DIVA_CAPI_ADAPTER *a, PLCI *plci, APPL *appl, API_PARSE *msg);
  170. static void mixer_indication_coefs_set (dword Id, PLCI *plci);
  171. static void mixer_indication_xconnect_from (dword Id, PLCI *plci, byte *msg, word length);
  172. static void mixer_indication_xconnect_to (dword Id, PLCI *plci, byte *msg, word length);
  173. static void mixer_remove (PLCI *plci);
  174. static void ec_command (dword Id, PLCI *plci, byte Rc);
  175. static byte ec_request (dword Id, word Number, DIVA_CAPI_ADAPTER *a, PLCI *plci, APPL *appl, API_PARSE *msg);
  176. static void ec_indication (dword Id, PLCI *plci, byte *msg, word length);
  177. static void rtp_connect_b3_req_command (dword Id, PLCI *plci, byte Rc);
  178. static void rtp_connect_b3_res_command (dword Id, PLCI *plci, byte Rc);
  179. static int diva_get_dma_descriptor (PLCI *plci, dword *dma_magic);
  180. static void diva_free_dma_descriptor (PLCI *plci, int nr);
  181. /*------------------------------------------------------------------*/
  182. /* external function prototypes */
  183. /*------------------------------------------------------------------*/
  184. extern byte MapController (byte);
  185. extern byte UnMapController (byte);
  186. #define MapId(Id) (((Id) & 0xffffff00L) | MapController ((byte)(Id)))
  187. #define UnMapId(Id) (((Id) & 0xffffff00L) | UnMapController ((byte)(Id)))
  188. void sendf(APPL *, word, dword, word, byte *, ...);
  189. void * TransmitBufferSet(APPL * appl, dword ref);
  190. void * TransmitBufferGet(APPL * appl, void * p);
  191. void TransmitBufferFree(APPL * appl, void * p);
  192. void * ReceiveBufferGet(APPL * appl, int Num);
  193. int fax_head_line_time (char *buffer);
  194. /*------------------------------------------------------------------*/
  195. /* Global data definitions */
  196. /*------------------------------------------------------------------*/
  197. extern byte max_adapter;
  198. extern byte max_appl;
  199. extern DIVA_CAPI_ADAPTER * adapter;
  200. extern APPL * application;
  201. static byte remove_started = false;
  202. static PLCI dummy_plci;
  203. static struct _ftable {
  204. word command;
  205. byte * format;
  206. byte (* function)(dword, word, DIVA_CAPI_ADAPTER *, PLCI *, APPL *, API_PARSE *);
  207. } ftable[] = {
  208. {_DATA_B3_R, "dwww", data_b3_req},
  209. {_DATA_B3_I|RESPONSE, "w", data_b3_res},
  210. {_INFO_R, "ss", info_req},
  211. {_INFO_I|RESPONSE, "", info_res},
  212. {_CONNECT_R, "wsssssssss", connect_req},
  213. {_CONNECT_I|RESPONSE, "wsssss", connect_res},
  214. {_CONNECT_ACTIVE_I|RESPONSE, "", connect_a_res},
  215. {_DISCONNECT_R, "s", disconnect_req},
  216. {_DISCONNECT_I|RESPONSE, "", disconnect_res},
  217. {_LISTEN_R, "dddss", listen_req},
  218. {_ALERT_R, "s", alert_req},
  219. {_FACILITY_R, "ws", facility_req},
  220. {_FACILITY_I|RESPONSE, "ws", facility_res},
  221. {_CONNECT_B3_R, "s", connect_b3_req},
  222. {_CONNECT_B3_I|RESPONSE, "ws", connect_b3_res},
  223. {_CONNECT_B3_ACTIVE_I|RESPONSE, "", connect_b3_a_res},
  224. {_DISCONNECT_B3_R, "s", disconnect_b3_req},
  225. {_DISCONNECT_B3_I|RESPONSE, "", disconnect_b3_res},
  226. {_RESET_B3_R, "s", reset_b3_req},
  227. {_RESET_B3_I|RESPONSE, "", reset_b3_res},
  228. {_CONNECT_B3_T90_ACTIVE_I|RESPONSE, "ws", connect_b3_t90_a_res},
  229. {_CONNECT_B3_T90_ACTIVE_I|RESPONSE, "", connect_b3_t90_a_res},
  230. {_SELECT_B_REQ, "s", select_b_req},
  231. {_MANUFACTURER_R, "dws", manufacturer_req},
  232. {_MANUFACTURER_I|RESPONSE, "dws", manufacturer_res},
  233. {_MANUFACTURER_I|RESPONSE, "", manufacturer_res}
  234. };
  235. static byte * cip_bc[29][2] = {
  236. { "", "" }, /* 0 */
  237. { "\x03\x80\x90\xa3", "\x03\x80\x90\xa2" }, /* 1 */
  238. { "\x02\x88\x90", "\x02\x88\x90" }, /* 2 */
  239. { "\x02\x89\x90", "\x02\x89\x90" }, /* 3 */
  240. { "\x03\x90\x90\xa3", "\x03\x90\x90\xa2" }, /* 4 */
  241. { "\x03\x91\x90\xa5", "\x03\x91\x90\xa5" }, /* 5 */
  242. { "\x02\x98\x90", "\x02\x98\x90" }, /* 6 */
  243. { "\x04\x88\xc0\xc6\xe6", "\x04\x88\xc0\xc6\xe6" }, /* 7 */
  244. { "\x04\x88\x90\x21\x8f", "\x04\x88\x90\x21\x8f" }, /* 8 */
  245. { "\x03\x91\x90\xa5", "\x03\x91\x90\xa5" }, /* 9 */
  246. { "", "" }, /* 10 */
  247. { "", "" }, /* 11 */
  248. { "", "" }, /* 12 */
  249. { "", "" }, /* 13 */
  250. { "", "" }, /* 14 */
  251. { "", "" }, /* 15 */
  252. { "\x03\x80\x90\xa3", "\x03\x80\x90\xa2" }, /* 16 */
  253. { "\x03\x90\x90\xa3", "\x03\x90\x90\xa2" }, /* 17 */
  254. { "\x02\x88\x90", "\x02\x88\x90" }, /* 18 */
  255. { "\x02\x88\x90", "\x02\x88\x90" }, /* 19 */
  256. { "\x02\x88\x90", "\x02\x88\x90" }, /* 20 */
  257. { "\x02\x88\x90", "\x02\x88\x90" }, /* 21 */
  258. { "\x02\x88\x90", "\x02\x88\x90" }, /* 22 */
  259. { "\x02\x88\x90", "\x02\x88\x90" }, /* 23 */
  260. { "\x02\x88\x90", "\x02\x88\x90" }, /* 24 */
  261. { "\x02\x88\x90", "\x02\x88\x90" }, /* 25 */
  262. { "\x03\x91\x90\xa5", "\x03\x91\x90\xa5" }, /* 26 */
  263. { "\x03\x91\x90\xa5", "\x03\x91\x90\xa5" }, /* 27 */
  264. { "\x02\x88\x90", "\x02\x88\x90" } /* 28 */
  265. };
  266. static byte * cip_hlc[29] = {
  267. "", /* 0 */
  268. "", /* 1 */
  269. "", /* 2 */
  270. "", /* 3 */
  271. "", /* 4 */
  272. "", /* 5 */
  273. "", /* 6 */
  274. "", /* 7 */
  275. "", /* 8 */
  276. "", /* 9 */
  277. "", /* 10 */
  278. "", /* 11 */
  279. "", /* 12 */
  280. "", /* 13 */
  281. "", /* 14 */
  282. "", /* 15 */
  283. "\x02\x91\x81", /* 16 */
  284. "\x02\x91\x84", /* 17 */
  285. "\x02\x91\xa1", /* 18 */
  286. "\x02\x91\xa4", /* 19 */
  287. "\x02\x91\xa8", /* 20 */
  288. "\x02\x91\xb1", /* 21 */
  289. "\x02\x91\xb2", /* 22 */
  290. "\x02\x91\xb5", /* 23 */
  291. "\x02\x91\xb8", /* 24 */
  292. "\x02\x91\xc1", /* 25 */
  293. "\x02\x91\x81", /* 26 */
  294. "\x03\x91\xe0\x01", /* 27 */
  295. "\x03\x91\xe0\x02" /* 28 */
  296. };
  297. /*------------------------------------------------------------------*/
  298. #define V120_HEADER_LENGTH 1
  299. #define V120_HEADER_EXTEND_BIT 0x80
  300. #define V120_HEADER_BREAK_BIT 0x40
  301. #define V120_HEADER_C1_BIT 0x04
  302. #define V120_HEADER_C2_BIT 0x08
  303. #define V120_HEADER_FLUSH_COND (V120_HEADER_BREAK_BIT | V120_HEADER_C1_BIT | V120_HEADER_C2_BIT)
  304. static byte v120_default_header[] =
  305. {
  306. 0x83 /* Ext, BR , res, res, C2 , C1 , B , F */
  307. };
  308. static byte v120_break_header[] =
  309. {
  310. 0xc3 | V120_HEADER_BREAK_BIT /* Ext, BR , res, res, C2 , C1 , B , F */
  311. };
  312. /*------------------------------------------------------------------*/
  313. /* API_PUT function */
  314. /*------------------------------------------------------------------*/
  315. word api_put(APPL * appl, CAPI_MSG * msg)
  316. {
  317. word i, j, k, l, n;
  318. word ret;
  319. byte c;
  320. byte controller;
  321. DIVA_CAPI_ADAPTER * a;
  322. PLCI * plci;
  323. NCCI * ncci_ptr;
  324. word ncci;
  325. CAPI_MSG *m;
  326. API_PARSE msg_parms[MAX_MSG_PARMS+1];
  327. if (msg->header.length < sizeof (msg->header) ||
  328. msg->header.length > MAX_MSG_SIZE) {
  329. dbug(1,dprintf("bad len"));
  330. return _BAD_MSG;
  331. }
  332. controller = (byte)((msg->header.controller &0x7f)-1);
  333. /* controller starts with 0 up to (max_adapter - 1) */
  334. if ( controller >= max_adapter )
  335. {
  336. dbug(1,dprintf("invalid ctrl"));
  337. return _BAD_MSG;
  338. }
  339. a = &adapter[controller];
  340. plci = NULL;
  341. if ((msg->header.plci != 0) && (msg->header.plci <= a->max_plci) && !a->adapter_disabled)
  342. {
  343. dbug(1,dprintf("plci=%x",msg->header.plci));
  344. plci = &a->plci[msg->header.plci-1];
  345. ncci = GET_WORD(&msg->header.ncci);
  346. if (plci->Id
  347. && (plci->appl
  348. || (plci->State == INC_CON_PENDING)
  349. || (plci->State == INC_CON_ALERT)
  350. || (msg->header.command == (_DISCONNECT_I|RESPONSE)))
  351. && ((ncci == 0)
  352. || (msg->header.command == (_DISCONNECT_B3_I|RESPONSE))
  353. || ((ncci < MAX_NCCI+1) && (a->ncci_plci[ncci] == plci->Id))))
  354. {
  355. i = plci->msg_in_read_pos;
  356. j = plci->msg_in_write_pos;
  357. if (j >= i)
  358. {
  359. if (j + msg->header.length + MSG_IN_OVERHEAD <= MSG_IN_QUEUE_SIZE)
  360. i += MSG_IN_QUEUE_SIZE - j;
  361. else
  362. j = 0;
  363. }
  364. else
  365. {
  366. n = (((CAPI_MSG *)(plci->msg_in_queue))->header.length + MSG_IN_OVERHEAD + 3) & 0xfffc;
  367. if (i > MSG_IN_QUEUE_SIZE - n)
  368. i = MSG_IN_QUEUE_SIZE - n + 1;
  369. i -= j;
  370. }
  371. if (i <= ((msg->header.length + MSG_IN_OVERHEAD + 3) & 0xfffc))
  372. {
  373. dbug(0,dprintf("Q-FULL1(msg) - len=%d write=%d read=%d wrap=%d free=%d",
  374. msg->header.length, plci->msg_in_write_pos,
  375. plci->msg_in_read_pos, plci->msg_in_wrap_pos, i));
  376. return _QUEUE_FULL;
  377. }
  378. c = false;
  379. if ((((byte *) msg) < ((byte *)(plci->msg_in_queue)))
  380. || (((byte *) msg) >= ((byte *)(plci->msg_in_queue)) + sizeof(plci->msg_in_queue)))
  381. {
  382. if (plci->msg_in_write_pos != plci->msg_in_read_pos)
  383. c = true;
  384. }
  385. if (msg->header.command == _DATA_B3_R)
  386. {
  387. if (msg->header.length < 20)
  388. {
  389. dbug(1,dprintf("DATA_B3 REQ wrong length %d", msg->header.length));
  390. return _BAD_MSG;
  391. }
  392. ncci_ptr = &(a->ncci[ncci]);
  393. n = ncci_ptr->data_pending;
  394. l = ncci_ptr->data_ack_pending;
  395. k = plci->msg_in_read_pos;
  396. while (k != plci->msg_in_write_pos)
  397. {
  398. if (k == plci->msg_in_wrap_pos)
  399. k = 0;
  400. if ((((CAPI_MSG *)(&((byte *)(plci->msg_in_queue))[k]))->header.command == _DATA_B3_R)
  401. && (((CAPI_MSG *)(&((byte *)(plci->msg_in_queue))[k]))->header.ncci == ncci))
  402. {
  403. n++;
  404. if (((CAPI_MSG *)(&((byte *)(plci->msg_in_queue))[k]))->info.data_b3_req.Flags & 0x0004)
  405. l++;
  406. }
  407. k += (((CAPI_MSG *)(&((byte *)(plci->msg_in_queue))[k]))->header.length +
  408. MSG_IN_OVERHEAD + 3) & 0xfffc;
  409. }
  410. if ((n >= MAX_DATA_B3) || (l >= MAX_DATA_ACK))
  411. {
  412. dbug(0,dprintf("Q-FULL2(data) - pending=%d/%d ack_pending=%d/%d",
  413. ncci_ptr->data_pending, n, ncci_ptr->data_ack_pending, l));
  414. return _QUEUE_FULL;
  415. }
  416. if (plci->req_in || plci->internal_command)
  417. {
  418. if ((((byte *) msg) >= ((byte *)(plci->msg_in_queue)))
  419. && (((byte *) msg) < ((byte *)(plci->msg_in_queue)) + sizeof(plci->msg_in_queue)))
  420. {
  421. dbug(0,dprintf("Q-FULL3(requeue)"));
  422. return _QUEUE_FULL;
  423. }
  424. c = true;
  425. }
  426. }
  427. else
  428. {
  429. if (plci->req_in || plci->internal_command)
  430. c = true;
  431. else
  432. {
  433. plci->command = msg->header.command;
  434. plci->number = msg->header.number;
  435. }
  436. }
  437. if (c)
  438. {
  439. dbug(1,dprintf("enqueue msg(0x%04x,0x%x,0x%x) - len=%d write=%d read=%d wrap=%d free=%d",
  440. msg->header.command, plci->req_in, plci->internal_command,
  441. msg->header.length, plci->msg_in_write_pos,
  442. plci->msg_in_read_pos, plci->msg_in_wrap_pos, i));
  443. if (j == 0)
  444. plci->msg_in_wrap_pos = plci->msg_in_write_pos;
  445. m = (CAPI_MSG *)(&((byte *)(plci->msg_in_queue))[j]);
  446. for (i = 0; i < msg->header.length; i++)
  447. ((byte *)(plci->msg_in_queue))[j++] = ((byte *) msg)[i];
  448. if (m->header.command == _DATA_B3_R)
  449. {
  450. m->info.data_b3_req.Data = (dword)(long)(TransmitBufferSet (appl, m->info.data_b3_req.Data));
  451. }
  452. j = (j + 3) & 0xfffc;
  453. *((APPL * *)(&((byte *)(plci->msg_in_queue))[j])) = appl;
  454. plci->msg_in_write_pos = j + MSG_IN_OVERHEAD;
  455. return 0;
  456. }
  457. }
  458. else
  459. {
  460. plci = NULL;
  461. }
  462. }
  463. dbug(1,dprintf("com=%x",msg->header.command));
  464. for(j=0;j<MAX_MSG_PARMS+1;j++) msg_parms[j].length = 0;
  465. for(i=0, ret = _BAD_MSG;
  466. i<(sizeof(ftable)/sizeof(struct _ftable));
  467. i++) {
  468. if(ftable[i].command==msg->header.command) {
  469. /* break loop if the message is correct, otherwise continue scan */
  470. /* (for example: CONNECT_B3_T90_ACT_RES has two specifications) */
  471. if(!api_parse(msg->info.b,(word)(msg->header.length-12),ftable[i].format,msg_parms)) {
  472. ret = 0;
  473. break;
  474. }
  475. for(j=0;j<MAX_MSG_PARMS+1;j++) msg_parms[j].length = 0;
  476. }
  477. }
  478. if(ret) {
  479. dbug(1,dprintf("BAD_MSG"));
  480. if(plci) plci->command = 0;
  481. return ret;
  482. }
  483. c = ftable[i].function(GET_DWORD(&msg->header.controller),
  484. msg->header.number,
  485. a,
  486. plci,
  487. appl,
  488. msg_parms);
  489. channel_xmit_extended_xon (plci);
  490. if(c==1) send_req(plci);
  491. if(c==2 && plci) plci->req_in = plci->req_in_start = plci->req_out = 0;
  492. if(plci && !plci->req_in) plci->command = 0;
  493. return 0;
  494. }
  495. /*------------------------------------------------------------------*/
  496. /* api_parse function, check the format of api messages */
  497. /*------------------------------------------------------------------*/
  498. static word api_parse(byte *msg, word length, byte *format, API_PARSE *parms)
  499. {
  500. word i;
  501. word p;
  502. for(i=0,p=0; format[i]; i++) {
  503. if(parms)
  504. {
  505. parms[i].info = &msg[p];
  506. }
  507. switch(format[i]) {
  508. case 'b':
  509. p +=1;
  510. break;
  511. case 'w':
  512. p +=2;
  513. break;
  514. case 'd':
  515. p +=4;
  516. break;
  517. case 's':
  518. if(msg[p]==0xff) {
  519. parms[i].info +=2;
  520. parms[i].length = msg[p+1] + (msg[p+2]<<8);
  521. p +=(parms[i].length +3);
  522. }
  523. else {
  524. parms[i].length = msg[p];
  525. p +=(parms[i].length +1);
  526. }
  527. break;
  528. }
  529. if(p>length) return true;
  530. }
  531. if(parms) parms[i].info = NULL;
  532. return false;
  533. }
  534. static void api_save_msg(API_PARSE *in, byte *format, API_SAVE *out)
  535. {
  536. word i, j, n = 0;
  537. byte *p;
  538. p = out->info;
  539. for (i = 0; format[i] != '\0'; i++)
  540. {
  541. out->parms[i].info = p;
  542. out->parms[i].length = in[i].length;
  543. switch (format[i])
  544. {
  545. case 'b':
  546. n = 1;
  547. break;
  548. case 'w':
  549. n = 2;
  550. break;
  551. case 'd':
  552. n = 4;
  553. break;
  554. case 's':
  555. n = in[i].length + 1;
  556. break;
  557. }
  558. for (j = 0; j < n; j++)
  559. *(p++) = in[i].info[j];
  560. }
  561. out->parms[i].info = NULL;
  562. out->parms[i].length = 0;
  563. }
  564. static void api_load_msg(API_SAVE *in, API_PARSE *out)
  565. {
  566. word i;
  567. i = 0;
  568. do
  569. {
  570. out[i].info = in->parms[i].info;
  571. out[i].length = in->parms[i].length;
  572. } while (in->parms[i++].info);
  573. }
  574. /*------------------------------------------------------------------*/
  575. /* CAPI remove function */
  576. /*------------------------------------------------------------------*/
  577. word api_remove_start(void)
  578. {
  579. word i;
  580. word j;
  581. if(!remove_started) {
  582. remove_started = true;
  583. for(i=0;i<max_adapter;i++) {
  584. if(adapter[i].request) {
  585. for(j=0;j<adapter[i].max_plci;j++) {
  586. if(adapter[i].plci[j].Sig.Id) plci_remove(&adapter[i].plci[j]);
  587. }
  588. }
  589. }
  590. return 1;
  591. }
  592. else {
  593. for(i=0;i<max_adapter;i++) {
  594. if(adapter[i].request) {
  595. for(j=0;j<adapter[i].max_plci;j++) {
  596. if(adapter[i].plci[j].Sig.Id) return 1;
  597. }
  598. }
  599. }
  600. }
  601. api_remove_complete();
  602. return 0;
  603. }
  604. /*------------------------------------------------------------------*/
  605. /* internal command queue */
  606. /*------------------------------------------------------------------*/
  607. static void init_internal_command_queue (PLCI *plci)
  608. {
  609. word i;
  610. dbug (1, dprintf ("%s,%d: init_internal_command_queue",
  611. (char *)(FILE_), __LINE__));
  612. plci->internal_command = 0;
  613. for (i = 0; i < MAX_INTERNAL_COMMAND_LEVELS; i++)
  614. plci->internal_command_queue[i] = NULL;
  615. }
  616. static void start_internal_command (dword Id, PLCI *plci, t_std_internal_command command_function)
  617. {
  618. word i;
  619. dbug (1, dprintf ("[%06lx] %s,%d: start_internal_command",
  620. UnMapId (Id), (char *)(FILE_), __LINE__));
  621. if (plci->internal_command == 0)
  622. {
  623. plci->internal_command_queue[0] = command_function;
  624. (* command_function)(Id, plci, OK);
  625. }
  626. else
  627. {
  628. i = 1;
  629. while (plci->internal_command_queue[i] != NULL)
  630. i++;
  631. plci->internal_command_queue[i] = command_function;
  632. }
  633. }
  634. static void next_internal_command (dword Id, PLCI *plci)
  635. {
  636. word i;
  637. dbug (1, dprintf ("[%06lx] %s,%d: next_internal_command",
  638. UnMapId (Id), (char *)(FILE_), __LINE__));
  639. plci->internal_command = 0;
  640. plci->internal_command_queue[0] = NULL;
  641. while (plci->internal_command_queue[1] != NULL)
  642. {
  643. for (i = 0; i < MAX_INTERNAL_COMMAND_LEVELS - 1; i++)
  644. plci->internal_command_queue[i] = plci->internal_command_queue[i+1];
  645. plci->internal_command_queue[MAX_INTERNAL_COMMAND_LEVELS - 1] = NULL;
  646. (*(plci->internal_command_queue[0]))(Id, plci, OK);
  647. if (plci->internal_command != 0)
  648. return;
  649. plci->internal_command_queue[0] = NULL;
  650. }
  651. }
  652. /*------------------------------------------------------------------*/
  653. /* NCCI allocate/remove function */
  654. /*------------------------------------------------------------------*/
  655. static dword ncci_mapping_bug = 0;
  656. static word get_ncci (PLCI *plci, byte ch, word force_ncci)
  657. {
  658. DIVA_CAPI_ADAPTER *a;
  659. word ncci, i, j, k;
  660. a = plci->adapter;
  661. if (!ch || a->ch_ncci[ch])
  662. {
  663. ncci_mapping_bug++;
  664. dbug(1,dprintf("NCCI mapping exists %ld %02x %02x %02x-%02x",
  665. ncci_mapping_bug, ch, force_ncci, a->ncci_ch[a->ch_ncci[ch]], a->ch_ncci[ch]));
  666. ncci = ch;
  667. }
  668. else
  669. {
  670. if (force_ncci)
  671. ncci = force_ncci;
  672. else
  673. {
  674. if ((ch < MAX_NCCI+1) && !a->ncci_ch[ch])
  675. ncci = ch;
  676. else
  677. {
  678. ncci = 1;
  679. while ((ncci < MAX_NCCI+1) && a->ncci_ch[ncci])
  680. ncci++;
  681. if (ncci == MAX_NCCI+1)
  682. {
  683. ncci_mapping_bug++;
  684. i = 1;
  685. do
  686. {
  687. j = 1;
  688. while ((j < MAX_NCCI+1) && (a->ncci_ch[j] != i))
  689. j++;
  690. k = j;
  691. if (j < MAX_NCCI+1)
  692. {
  693. do
  694. {
  695. j++;
  696. } while ((j < MAX_NCCI+1) && (a->ncci_ch[j] != i));
  697. }
  698. } while ((i < MAX_NL_CHANNEL+1) && (j < MAX_NCCI+1));
  699. if (i < MAX_NL_CHANNEL+1)
  700. {
  701. dbug(1,dprintf("NCCI mapping overflow %ld %02x %02x %02x-%02x-%02x",
  702. ncci_mapping_bug, ch, force_ncci, i, k, j));
  703. }
  704. else
  705. {
  706. dbug(1,dprintf("NCCI mapping overflow %ld %02x %02x",
  707. ncci_mapping_bug, ch, force_ncci));
  708. }
  709. ncci = ch;
  710. }
  711. }
  712. a->ncci_plci[ncci] = plci->Id;
  713. a->ncci_state[ncci] = IDLE;
  714. if (!plci->ncci_ring_list)
  715. plci->ncci_ring_list = ncci;
  716. else
  717. a->ncci_next[ncci] = a->ncci_next[plci->ncci_ring_list];
  718. a->ncci_next[plci->ncci_ring_list] = (byte) ncci;
  719. }
  720. a->ncci_ch[ncci] = ch;
  721. a->ch_ncci[ch] = (byte) ncci;
  722. dbug(1,dprintf("NCCI mapping established %ld %02x %02x %02x-%02x",
  723. ncci_mapping_bug, ch, force_ncci, ch, ncci));
  724. }
  725. return (ncci);
  726. }
  727. static void ncci_free_receive_buffers (PLCI *plci, word ncci)
  728. {
  729. DIVA_CAPI_ADAPTER *a;
  730. APPL *appl;
  731. word i, ncci_code;
  732. dword Id;
  733. a = plci->adapter;
  734. Id = (((dword) ncci) << 16) | (((word)(plci->Id)) << 8) | a->Id;
  735. if (ncci)
  736. {
  737. if (a->ncci_plci[ncci] == plci->Id)
  738. {
  739. if (!plci->appl)
  740. {
  741. ncci_mapping_bug++;
  742. dbug(1,dprintf("NCCI mapping appl expected %ld %08lx",
  743. ncci_mapping_bug, Id));
  744. }
  745. else
  746. {
  747. appl = plci->appl;
  748. ncci_code = ncci | (((word) a->Id) << 8);
  749. for (i = 0; i < appl->MaxBuffer; i++)
  750. {
  751. if ((appl->DataNCCI[i] == ncci_code)
  752. && (((byte)(appl->DataFlags[i] >> 8)) == plci->Id))
  753. {
  754. appl->DataNCCI[i] = 0;
  755. }
  756. }
  757. }
  758. }
  759. }
  760. else
  761. {
  762. for (ncci = 1; ncci < MAX_NCCI+1; ncci++)
  763. {
  764. if (a->ncci_plci[ncci] == plci->Id)
  765. {
  766. if (!plci->appl)
  767. {
  768. ncci_mapping_bug++;
  769. dbug(1,dprintf("NCCI mapping no appl %ld %08lx",
  770. ncci_mapping_bug, Id));
  771. }
  772. else
  773. {
  774. appl = plci->appl;
  775. ncci_code = ncci | (((word) a->Id) << 8);
  776. for (i = 0; i < appl->MaxBuffer; i++)
  777. {
  778. if ((appl->DataNCCI[i] == ncci_code)
  779. && (((byte)(appl->DataFlags[i] >> 8)) == plci->Id))
  780. {
  781. appl->DataNCCI[i] = 0;
  782. }
  783. }
  784. }
  785. }
  786. }
  787. }
  788. }
  789. static void cleanup_ncci_data (PLCI *plci, word ncci)
  790. {
  791. NCCI *ncci_ptr;
  792. if (ncci && (plci->adapter->ncci_plci[ncci] == plci->Id))
  793. {
  794. ncci_ptr = &(plci->adapter->ncci[ncci]);
  795. if (plci->appl)
  796. {
  797. while (ncci_ptr->data_pending != 0)
  798. {
  799. if (!plci->data_sent || (ncci_ptr->DBuffer[ncci_ptr->data_out].P != plci->data_sent_ptr))
  800. TransmitBufferFree (plci->appl, ncci_ptr->DBuffer[ncci_ptr->data_out].P);
  801. (ncci_ptr->data_out)++;
  802. if (ncci_ptr->data_out == MAX_DATA_B3)
  803. ncci_ptr->data_out = 0;
  804. (ncci_ptr->data_pending)--;
  805. }
  806. }
  807. ncci_ptr->data_out = 0;
  808. ncci_ptr->data_pending = 0;
  809. ncci_ptr->data_ack_out = 0;
  810. ncci_ptr->data_ack_pending = 0;
  811. }
  812. }
  813. static void ncci_remove (PLCI *plci, word ncci, byte preserve_ncci)
  814. {
  815. DIVA_CAPI_ADAPTER *a;
  816. dword Id;
  817. word i;
  818. a = plci->adapter;
  819. Id = (((dword) ncci) << 16) | (((word)(plci->Id)) << 8) | a->Id;
  820. if (!preserve_ncci)
  821. ncci_free_receive_buffers (plci, ncci);
  822. if (ncci)
  823. {
  824. if (a->ncci_plci[ncci] != plci->Id)
  825. {
  826. ncci_mapping_bug++;
  827. dbug(1,dprintf("NCCI mapping doesn't exist %ld %08lx %02x",
  828. ncci_mapping_bug, Id, preserve_ncci));
  829. }
  830. else
  831. {
  832. cleanup_ncci_data (plci, ncci);
  833. dbug(1,dprintf("NCCI mapping released %ld %08lx %02x %02x-%02x",
  834. ncci_mapping_bug, Id, preserve_ncci, a->ncci_ch[ncci], ncci));
  835. a->ch_ncci[a->ncci_ch[ncci]] = 0;
  836. if (!preserve_ncci)
  837. {
  838. a->ncci_ch[ncci] = 0;
  839. a->ncci_plci[ncci] = 0;
  840. a->ncci_state[ncci] = IDLE;
  841. i = plci->ncci_ring_list;
  842. while ((i != 0) && (a->ncci_next[i] != plci->ncci_ring_list) && (a->ncci_next[i] != ncci))
  843. i = a->ncci_next[i];
  844. if ((i != 0) && (a->ncci_next[i] == ncci))
  845. {
  846. if (i == ncci)
  847. plci->ncci_ring_list = 0;
  848. else if (plci->ncci_ring_list == ncci)
  849. plci->ncci_ring_list = i;
  850. a->ncci_next[i] = a->ncci_next[ncci];
  851. }
  852. a->ncci_next[ncci] = 0;
  853. }
  854. }
  855. }
  856. else
  857. {
  858. for (ncci = 1; ncci < MAX_NCCI+1; ncci++)
  859. {
  860. if (a->ncci_plci[ncci] == plci->Id)
  861. {
  862. cleanup_ncci_data (plci, ncci);
  863. dbug(1,dprintf("NCCI mapping released %ld %08lx %02x %02x-%02x",
  864. ncci_mapping_bug, Id, preserve_ncci, a->ncci_ch[ncci], ncci));
  865. a->ch_ncci[a->ncci_ch[ncci]] = 0;
  866. if (!preserve_ncci)
  867. {
  868. a->ncci_ch[ncci] = 0;
  869. a->ncci_plci[ncci] = 0;
  870. a->ncci_state[ncci] = IDLE;
  871. a->ncci_next[ncci] = 0;
  872. }
  873. }
  874. }
  875. if (!preserve_ncci)
  876. plci->ncci_ring_list = 0;
  877. }
  878. }
  879. /*------------------------------------------------------------------*/
  880. /* PLCI remove function */
  881. /*------------------------------------------------------------------*/
  882. static void plci_free_msg_in_queue (PLCI *plci)
  883. {
  884. word i;
  885. if (plci->appl)
  886. {
  887. i = plci->msg_in_read_pos;
  888. while (i != plci->msg_in_write_pos)
  889. {
  890. if (i == plci->msg_in_wrap_pos)
  891. i = 0;
  892. if (((CAPI_MSG *)(&((byte *)(plci->msg_in_queue))[i]))->header.command == _DATA_B3_R)
  893. {
  894. TransmitBufferFree (plci->appl,
  895. (byte *)(long)(((CAPI_MSG *)(&((byte *)(plci->msg_in_queue))[i]))->info.data_b3_req.Data));
  896. }
  897. i += (((CAPI_MSG *)(&((byte *)(plci->msg_in_queue))[i]))->header.length +
  898. MSG_IN_OVERHEAD + 3) & 0xfffc;
  899. }
  900. }
  901. plci->msg_in_write_pos = MSG_IN_QUEUE_SIZE;
  902. plci->msg_in_read_pos = MSG_IN_QUEUE_SIZE;
  903. plci->msg_in_wrap_pos = MSG_IN_QUEUE_SIZE;
  904. }
  905. static void plci_remove(PLCI * plci)
  906. {
  907. if(!plci) {
  908. dbug(1,dprintf("plci_remove(no plci)"));
  909. return;
  910. }
  911. init_internal_command_queue (plci);
  912. dbug(1,dprintf("plci_remove(%x,tel=%x)",plci->Id,plci->tel));
  913. if(plci_remove_check(plci))
  914. {
  915. return;
  916. }
  917. if (plci->Sig.Id == 0xff)
  918. {
  919. dbug(1,dprintf("D-channel X.25 plci->NL.Id:%0x", plci->NL.Id));
  920. if (plci->NL.Id && !plci->nl_remove_id)
  921. {
  922. nl_req_ncci(plci,REMOVE,0);
  923. send_req(plci);
  924. }
  925. }
  926. else
  927. {
  928. if (!plci->sig_remove_id
  929. && (plci->Sig.Id
  930. || (plci->req_in!=plci->req_out)
  931. || (plci->nl_req || plci->sig_req)))
  932. {
  933. sig_req(plci,HANGUP,0);
  934. send_req(plci);
  935. }
  936. }
  937. ncci_remove (plci, 0, false);
  938. plci_free_msg_in_queue (plci);
  939. plci->channels = 0;
  940. plci->appl = NULL;
  941. if ((plci->State == INC_CON_PENDING) || (plci->State == INC_CON_ALERT))
  942. plci->State = OUTG_DIS_PENDING;
  943. }
  944. /*------------------------------------------------------------------*/
  945. /* Application Group function helpers */
  946. /*------------------------------------------------------------------*/
  947. static void set_group_ind_mask (PLCI *plci)
  948. {
  949. word i;
  950. for (i = 0; i < C_IND_MASK_DWORDS; i++)
  951. plci->group_optimization_mask_table[i] = 0xffffffffL;
  952. }
  953. static void clear_group_ind_mask_bit (PLCI *plci, word b)
  954. {
  955. plci->group_optimization_mask_table[b >> 5] &= ~(1L << (b & 0x1f));
  956. }
  957. static byte test_group_ind_mask_bit (PLCI *plci, word b)
  958. {
  959. return ((plci->group_optimization_mask_table[b >> 5] & (1L << (b & 0x1f))) != 0);
  960. }
  961. /*------------------------------------------------------------------*/
  962. /* c_ind_mask operations for arbitrary MAX_APPL */
  963. /*------------------------------------------------------------------*/
  964. static void clear_c_ind_mask (PLCI *plci)
  965. {
  966. word i;
  967. for (i = 0; i < C_IND_MASK_DWORDS; i++)
  968. plci->c_ind_mask_table[i] = 0;
  969. }
  970. static byte c_ind_mask_empty (PLCI *plci)
  971. {
  972. word i;
  973. i = 0;
  974. while ((i < C_IND_MASK_DWORDS) && (plci->c_ind_mask_table[i] == 0))
  975. i++;
  976. return (i == C_IND_MASK_DWORDS);
  977. }
  978. static void set_c_ind_mask_bit (PLCI *plci, word b)
  979. {
  980. plci->c_ind_mask_table[b >> 5] |= (1L << (b & 0x1f));
  981. }
  982. static void clear_c_ind_mask_bit (PLCI *plci, word b)
  983. {
  984. plci->c_ind_mask_table[b >> 5] &= ~(1L << (b & 0x1f));
  985. }
  986. static byte test_c_ind_mask_bit (PLCI *plci, word b)
  987. {
  988. return ((plci->c_ind_mask_table[b >> 5] & (1L << (b & 0x1f))) != 0);
  989. }
  990. static void dump_c_ind_mask (PLCI *plci)
  991. {
  992. static char hex_digit_table[0x10] =
  993. {'0','1','2','3','4','5','6','7','8','9','a','b','c','d','e','f'};
  994. word i, j, k;
  995. dword d;
  996. char *p;
  997. char buf[40];
  998. for (i = 0; i < C_IND_MASK_DWORDS; i += 4)
  999. {
  1000. p = buf + 36;
  1001. *p = '\0';
  1002. for (j = 0; j < 4; j++)
  1003. {
  1004. if (i+j < C_IND_MASK_DWORDS)
  1005. {
  1006. d = plci->c_ind_mask_table[i+j];
  1007. for (k = 0; k < 8; k++)
  1008. {
  1009. *(--p) = hex_digit_table[d & 0xf];
  1010. d >>= 4;
  1011. }
  1012. }
  1013. else if (i != 0)
  1014. {
  1015. for (k = 0; k < 8; k++)
  1016. *(--p) = ' ';
  1017. }
  1018. *(--p) = ' ';
  1019. }
  1020. dbug(1,dprintf ("c_ind_mask =%s", (char *) p));
  1021. }
  1022. }
  1023. #define dump_plcis(a)
  1024. /*------------------------------------------------------------------*/
  1025. /* translation function for each message */
  1026. /*------------------------------------------------------------------*/
  1027. byte connect_req(dword Id, word Number, DIVA_CAPI_ADAPTER * a, PLCI * plci, APPL * appl, API_PARSE * parms)
  1028. {
  1029. word ch;
  1030. word i;
  1031. word Info;
  1032. word CIP;
  1033. byte LinkLayer;
  1034. API_PARSE * ai;
  1035. API_PARSE * bp;
  1036. API_PARSE ai_parms[5];
  1037. word channel = 0;
  1038. dword ch_mask;
  1039. byte m;
  1040. static byte esc_chi[35] = {0x02,0x18,0x01};
  1041. static byte lli[2] = {0x01,0x00};
  1042. byte noCh = 0;
  1043. word dir = 0;
  1044. byte *p_chi = "";
  1045. for(i=0;i<5;i++) ai_parms[i].length = 0;
  1046. dbug(1,dprintf("connect_req(%d)",parms->length));
  1047. Info = _WRONG_IDENTIFIER;
  1048. if(a)
  1049. {
  1050. if(a->adapter_disabled)
  1051. {
  1052. dbug(1,dprintf("adapter disabled"));
  1053. Id = ((word)1<<8)|a->Id;
  1054. sendf(appl,_CONNECT_R|CONFIRM,Id,Number,"w",0);
  1055. sendf(appl, _DISCONNECT_I, Id, 0, "w", _L1_ERROR);
  1056. return false;
  1057. }
  1058. Info = _OUT_OF_PLCI;
  1059. if((i=get_plci(a)))
  1060. {
  1061. Info = 0;
  1062. plci = &a->plci[i-1];
  1063. plci->appl = appl;
  1064. plci->call_dir = CALL_DIR_OUT | CALL_DIR_ORIGINATE;
  1065. /* check 'external controller' bit for codec support */
  1066. if(Id & EXT_CONTROLLER)
  1067. {
  1068. if(AdvCodecSupport(a, plci, appl, 0) )
  1069. {
  1070. plci->Id = 0;
  1071. sendf(appl, _CONNECT_R|CONFIRM, Id, Number, "w", _WRONG_IDENTIFIER);
  1072. return 2;
  1073. }
  1074. }
  1075. ai = &parms[9];
  1076. bp = &parms[5];
  1077. ch = 0;
  1078. if(bp->length)LinkLayer = bp->info[3];
  1079. else LinkLayer = 0;
  1080. if(ai->length)
  1081. {
  1082. ch=0xffff;
  1083. if(!api_parse(&ai->info[1],(word)ai->length,"ssss",ai_parms))
  1084. {
  1085. ch = 0;
  1086. if(ai_parms[0].length)
  1087. {
  1088. ch = GET_WORD(ai_parms[0].info+1);
  1089. if(ch>4) ch=0; /* safety -> ignore ChannelID */
  1090. if(ch==4) /* explizit CHI in message */
  1091. {
  1092. /* check length of B-CH struct */
  1093. if((ai_parms[0].info)[3]>=1)
  1094. {
  1095. if((ai_parms[0].info)[4]==CHI)
  1096. {
  1097. p_chi = &((ai_parms[0].info)[5]);
  1098. }
  1099. else
  1100. {
  1101. p_chi = &((ai_parms[0].info)[3]);
  1102. }
  1103. if(p_chi[0]>35) /* check length of channel ID */
  1104. {
  1105. Info = _WRONG_MESSAGE_FORMAT;
  1106. }
  1107. }
  1108. else Info = _WRONG_MESSAGE_FORMAT;
  1109. }
  1110. if(ch==3 && ai_parms[0].length>=7 && ai_parms[0].length<=36)
  1111. {
  1112. dir = GET_WORD(ai_parms[0].info+3);
  1113. ch_mask = 0;
  1114. m = 0x3f;
  1115. for(i=0; i+5<=ai_parms[0].length; i++)
  1116. {
  1117. if(ai_parms[0].info[i+5]!=0)
  1118. {
  1119. if((ai_parms[0].info[i+5] | m) != 0xff)
  1120. Info = _WRONG_MESSAGE_FORMAT;
  1121. else
  1122. {
  1123. if (ch_mask == 0)
  1124. channel = i;
  1125. ch_mask |= 1L << i;
  1126. }
  1127. }
  1128. m = 0;
  1129. }
  1130. if (ch_mask == 0)
  1131. Info = _WRONG_MESSAGE_FORMAT;
  1132. if (!Info)
  1133. {
  1134. if ((ai_parms[0].length == 36) || (ch_mask != ((dword)(1L << channel))))
  1135. {
  1136. esc_chi[0] = (byte)(ai_parms[0].length - 2);
  1137. for(i=0; i+5<=ai_parms[0].length; i++)
  1138. esc_chi[i+3] = ai_parms[0].info[i+5];
  1139. }
  1140. else
  1141. esc_chi[0] = 2;
  1142. esc_chi[2] = (byte)channel;
  1143. plci->b_channel = (byte)channel; /* not correct for ETSI ch 17..31 */
  1144. add_p(plci,LLI,lli);
  1145. add_p(plci,ESC,esc_chi);
  1146. plci->State = LOCAL_CONNECT;
  1147. if(!dir) plci->call_dir |= CALL_DIR_FORCE_OUTG_NL; /* dir 0=DTE, 1=DCE */
  1148. }
  1149. }
  1150. }
  1151. }
  1152. else Info = _WRONG_MESSAGE_FORMAT;
  1153. }
  1154. dbug(1,dprintf("ch=%x,dir=%x,p_ch=%d",ch,dir,channel));
  1155. plci->command = _CONNECT_R;
  1156. plci->number = Number;
  1157. /* x.31 or D-ch free SAPI in LinkLayer? */
  1158. if(ch==1 && LinkLayer!=3 && LinkLayer!=12) noCh = true;
  1159. if((ch==0 || ch==2 || noCh || ch==3 || ch==4) && !Info)
  1160. {
  1161. /* B-channel used for B3 connections (ch==0), or no B channel */
  1162. /* is used (ch==2) or perm. connection (3) is used do a CALL */
  1163. if(noCh) Info = add_b1(plci,&parms[5],2,0); /* no resource */
  1164. else Info = add_b1(plci,&parms[5],ch,0);
  1165. add_s(plci,OAD,&parms[2]);
  1166. add_s(plci,OSA,&parms[4]);
  1167. add_s(plci,BC,&parms[6]);
  1168. add_s(plci,LLC,&parms[7]);
  1169. add_s(plci,HLC,&parms[8]);
  1170. CIP = GET_WORD(parms[0].info);
  1171. if (a->Info_Mask[appl->Id-1] & 0x200)
  1172. {
  1173. /* early B3 connect (CIP mask bit 9) no release after a disc */
  1174. add_p(plci,LLI,"\x01\x01");
  1175. }
  1176. if(GET_WORD(parms[0].info)<29) {
  1177. add_p(plci,BC,cip_bc[GET_WORD(parms[0].info)][a->u_law]);
  1178. add_p(plci,HLC,cip_hlc[GET_WORD(parms[0].info)]);
  1179. }
  1180. add_p(plci,UID,"\x06\x43\x61\x70\x69\x32\x30");
  1181. sig_req(plci,ASSIGN,DSIG_ID);
  1182. }
  1183. else if(ch==1) {
  1184. /* D-Channel used for B3 connections */
  1185. plci->Sig.Id = 0xff;
  1186. Info = 0;
  1187. }
  1188. if(!Info && ch!=2 && !noCh ) {
  1189. Info = add_b23(plci,&parms[5]);
  1190. if(!Info) {
  1191. if(!(plci->tel && !plci->adv_nl))nl_req_ncci(plci,ASSIGN,0);
  1192. }
  1193. }
  1194. if(!Info)
  1195. {
  1196. if(ch==0 || ch==2 || ch==3 || noCh || ch==4)
  1197. {
  1198. if(plci->spoofed_msg==SPOOFING_REQUIRED)
  1199. {
  1200. api_save_msg(parms, "wsssssssss", &plci->saved_msg);
  1201. plci->spoofed_msg = CALL_REQ;
  1202. plci->internal_command = BLOCK_PLCI;
  1203. plci->command = 0;
  1204. dbug(1,dprintf("Spoof"));
  1205. send_req(plci);
  1206. return false;
  1207. }
  1208. if(ch==4)add_p(plci,CHI,p_chi);
  1209. add_s(plci,CPN,&parms[1]);
  1210. add_s(plci,DSA,&parms[3]);
  1211. if(noCh) add_p(plci,ESC,"\x02\x18\xfd"); /* D-channel, no B-L3 */
  1212. add_ai(plci,&parms[9]);
  1213. if(!dir)sig_req(plci,CALL_REQ,0);
  1214. else
  1215. {
  1216. plci->command = PERM_LIST_REQ;
  1217. plci->appl = appl;
  1218. sig_req(plci,LISTEN_REQ,0);
  1219. send_req(plci);
  1220. return false;
  1221. }
  1222. }
  1223. send_req(plci);
  1224. return false;
  1225. }
  1226. plci->Id = 0;
  1227. }
  1228. }
  1229. sendf(appl,
  1230. _CONNECT_R|CONFIRM,
  1231. Id,
  1232. Number,
  1233. "w",Info);
  1234. return 2;
  1235. }
  1236. byte connect_res(dword Id, word Number, DIVA_CAPI_ADAPTER * a, PLCI * plci, APPL * appl, API_PARSE * parms)
  1237. {
  1238. word i, Info;
  1239. word Reject;
  1240. static byte cau_t[] = {0,0,0x90,0x91,0xac,0x9d,0x86,0xd8,0x9b};
  1241. static byte esc_t[] = {0x03,0x08,0x00,0x00};
  1242. API_PARSE * ai;
  1243. API_PARSE ai_parms[5];
  1244. word ch=0;
  1245. if(!plci) {
  1246. dbug(1,dprintf("connect_res(no plci)"));
  1247. return 0; /* no plci, no send */
  1248. }
  1249. dbug(1,dprintf("connect_res(State=0x%x)",plci->State));
  1250. for(i=0;i<5;i++) ai_parms[i].length = 0;
  1251. ai = &parms[5];
  1252. dbug(1,dprintf("ai->length=%d",ai->length));
  1253. if(ai->length)
  1254. {
  1255. if(!api_parse(&ai->info[1],(word)ai->length,"ssss",ai_parms))
  1256. {
  1257. dbug(1,dprintf("ai_parms[0].length=%d/0x%x",ai_parms[0].length,GET_WORD(ai_parms[0].info+1)));
  1258. ch = 0;
  1259. if(ai_parms[0].length)
  1260. {
  1261. ch = GET_WORD(ai_parms[0].info+1);
  1262. dbug(1,dprintf("BCH-I=0x%x",ch));
  1263. }
  1264. }
  1265. }
  1266. if(plci->State==INC_CON_CONNECTED_ALERT)
  1267. {
  1268. dbug(1,dprintf("Connected Alert Call_Res"));
  1269. if (a->Info_Mask[appl->Id-1] & 0x200)
  1270. {
  1271. /* early B3 connect (CIP mask bit 9) no release after a disc */
  1272. add_p(plci,LLI,"\x01\x01");
  1273. }
  1274. add_s(plci, CONN_NR, &parms[2]);
  1275. add_s(plci, LLC, &parms[4]);
  1276. add_ai(plci, &parms[5]);
  1277. plci->State = INC_CON_ACCEPT;
  1278. sig_req(plci, CALL_RES,0);
  1279. return 1;
  1280. }
  1281. else if(plci->State==INC_CON_PENDING || plci->State==INC_CON_ALERT) {
  1282. clear_c_ind_mask_bit (plci, (word)(appl->Id-1));
  1283. dump_c_ind_mask (plci);
  1284. Reject = GET_WORD(parms[0].info);
  1285. dbug(1,dprintf("Reject=0x%x",Reject));
  1286. if(Reject)
  1287. {
  1288. if(c_ind_mask_empty (plci))
  1289. {
  1290. if((Reject&0xff00)==0x3400)
  1291. {
  1292. esc_t[2] = ((byte)(Reject&0x00ff)) | 0x80;
  1293. add_p(plci,ESC,esc_t);
  1294. add_ai(plci, &parms[5]);
  1295. sig_req(plci,REJECT,0);
  1296. }
  1297. else if(Reject==1 || Reject>9)
  1298. {
  1299. add_ai(plci, &parms[5]);
  1300. sig_req(plci,HANGUP,0);
  1301. }
  1302. else
  1303. {
  1304. esc_t[2] = cau_t[(Reject&0x000f)];
  1305. add_p(plci,ESC,esc_t);
  1306. add_ai(plci, &parms[5]);
  1307. sig_req(plci,REJECT,0);
  1308. }
  1309. plci->appl = appl;
  1310. }
  1311. else
  1312. {
  1313. sendf(appl, _DISCONNECT_I, Id, 0, "w", _OTHER_APPL_CONNECTED);
  1314. }
  1315. }
  1316. else {
  1317. plci->appl = appl;
  1318. if(Id & EXT_CONTROLLER){
  1319. if(AdvCodecSupport(a, plci, appl, 0)){
  1320. dbug(1,dprintf("connect_res(error from AdvCodecSupport)"));
  1321. sig_req(plci,HANGUP,0);
  1322. return 1;
  1323. }
  1324. if(plci->tel == ADV_VOICE && a->AdvCodecPLCI)
  1325. {
  1326. Info = add_b23(plci, &parms[1]);
  1327. if (Info)
  1328. {
  1329. dbug(1,dprintf("connect_res(error from add_b23)"));
  1330. sig_req(plci,HANGUP,0);
  1331. return 1;
  1332. }
  1333. if(plci->adv_nl)
  1334. {
  1335. nl_req_ncci(plci, ASSIGN, 0);
  1336. }
  1337. }
  1338. }
  1339. else
  1340. {
  1341. plci->tel = 0;
  1342. if(ch!=2)
  1343. {
  1344. Info = add_b23(plci, &parms[1]);
  1345. if (Info)
  1346. {
  1347. dbug(1,dprintf("connect_res(error from add_b23 2)"));
  1348. sig_req(plci,HANGUP,0);
  1349. return 1;
  1350. }
  1351. }
  1352. nl_req_ncci(plci, ASSIGN, 0);
  1353. }
  1354. if(plci->spoofed_msg==SPOOFING_REQUIRED)
  1355. {
  1356. api_save_msg(parms, "wsssss", &plci->saved_msg);
  1357. plci->spoofed_msg = CALL_RES;
  1358. plci->internal_command = BLOCK_PLCI;
  1359. plci->command = 0;
  1360. dbug(1,dprintf("Spoof"));
  1361. }
  1362. else
  1363. {
  1364. add_b1 (plci, &parms[1], ch, plci->B1_facilities);
  1365. if (a->Info_Mask[appl->Id-1] & 0x200)
  1366. {
  1367. /* early B3 connect (CIP mask bit 9) no release after a disc */
  1368. add_p(plci,LLI,"\x01\x01");
  1369. }
  1370. add_s(plci, CONN_NR, &parms[2]);
  1371. add_s(plci, LLC, &parms[4]);
  1372. add_ai(plci, &parms[5]);
  1373. plci->State = INC_CON_ACCEPT;
  1374. sig_req(plci, CALL_RES,0);
  1375. }
  1376. for(i=0; i<max_appl; i++) {
  1377. if(test_c_ind_mask_bit (plci, i)) {
  1378. sendf(&application[i], _DISCONNECT_I, Id, 0, "w", _OTHER_APPL_CONNECTED);
  1379. }
  1380. }
  1381. }
  1382. }
  1383. return 1;
  1384. }
  1385. byte connect_a_res(dword Id, word Number, DIVA_CAPI_ADAPTER * a, PLCI * plci, APPL * appl, API_PARSE * msg)
  1386. {
  1387. dbug(1,dprintf("connect_a_res"));
  1388. return false;
  1389. }
  1390. byte disconnect_req(dword Id, word Number, DIVA_CAPI_ADAPTER * a, PLCI * plci, APPL * appl, API_PARSE * msg)
  1391. {
  1392. word Info;
  1393. word i;
  1394. dbug(1,dprintf("disconnect_req"));
  1395. Info = _WRONG_IDENTIFIER;
  1396. if(plci)
  1397. {
  1398. if(plci->State==INC_CON_PENDING || plci->State==INC_CON_ALERT)
  1399. {
  1400. clear_c_ind_mask_bit (plci, (word)(appl->Id-1));
  1401. plci->appl = appl;
  1402. for(i=0; i<max_appl; i++)
  1403. {
  1404. if(test_c_ind_mask_bit (plci, i))
  1405. sendf(&application[i], _DISCONNECT_I, Id, 0, "w", 0);
  1406. }
  1407. plci->State = OUTG_DIS_PENDING;
  1408. }
  1409. if(plci->Sig.Id && plci->appl)
  1410. {
  1411. Info = 0;
  1412. if(plci->Sig.Id!=0xff)
  1413. {
  1414. if(plci->State!=INC_DIS_PENDING)
  1415. {
  1416. add_ai(plci, &msg[0]);
  1417. sig_req(plci,HANGUP,0);
  1418. plci->State = OUTG_DIS_PENDING;
  1419. return 1;
  1420. }
  1421. }
  1422. else
  1423. {
  1424. if (plci->NL.Id && !plci->nl_remove_id)
  1425. {
  1426. mixer_remove (plci);
  1427. nl_req_ncci(plci,REMOVE,0);
  1428. sendf(appl,_DISCONNECT_R|CONFIRM,Id,Number,"w",0);
  1429. sendf(appl, _DISCONNECT_I, Id, 0, "w", 0);
  1430. plci->State = INC_DIS_PENDING;
  1431. }
  1432. return 1;
  1433. }
  1434. }
  1435. }
  1436. if(!appl) return false;
  1437. sendf(appl, _DISCONNECT_R|CONFIRM, Id, Number, "w",Info);
  1438. return false;
  1439. }
  1440. byte disconnect_res(dword Id, word Number, DIVA_CAPI_ADAPTER * a, PLCI * plci, APPL * appl, API_PARSE * msg)
  1441. {
  1442. dbug(1,dprintf("disconnect_res"));
  1443. if(plci)
  1444. {
  1445. /* clear ind mask bit, just in case of collsion of */
  1446. /* DISCONNECT_IND and CONNECT_RES */
  1447. clear_c_ind_mask_bit (plci, (word)(appl->Id-1));
  1448. ncci_free_receive_buffers (plci, 0);
  1449. if(plci_remove_check(plci))
  1450. {
  1451. return 0;
  1452. }
  1453. if(plci->State==INC_DIS_PENDING
  1454. || plci->State==SUSPENDING) {
  1455. if(c_ind_mask_empty (plci)) {
  1456. if(plci->State!=SUSPENDING)plci->State = IDLE;
  1457. dbug(1,dprintf("chs=%d",plci->channels));
  1458. if(!plci->channels) {
  1459. plci_remove(plci);
  1460. }
  1461. }
  1462. }
  1463. }
  1464. return 0;
  1465. }
  1466. byte listen_req(dword Id, word Number, DIVA_CAPI_ADAPTER * a, PLCI * plci, APPL * appl, API_PARSE * parms)
  1467. {
  1468. word Info;
  1469. byte i;
  1470. dbug(1,dprintf("listen_req(Appl=0x%x)",appl->Id));
  1471. Info = _WRONG_IDENTIFIER;
  1472. if(a) {
  1473. Info = 0;
  1474. a->Info_Mask[appl->Id-1] = GET_DWORD(parms[0].info);
  1475. a->CIP_Mask[appl->Id-1] = GET_DWORD(parms[1].info);
  1476. dbug(1,dprintf("CIP_MASK=0x%lx",GET_DWORD(parms[1].info)));
  1477. if (a->Info_Mask[appl->Id-1] & 0x200){ /* early B3 connect provides */
  1478. a->Info_Mask[appl->Id-1] |= 0x10; /* call progression infos */
  1479. }
  1480. /* check if external controller listen and switch listen on or off*/
  1481. if(Id&EXT_CONTROLLER && GET_DWORD(parms[1].info)){
  1482. if(a->profile.Global_Options & ON_BOARD_CODEC) {
  1483. dummy_plci.State = IDLE;
  1484. a->codec_listen[appl->Id-1] = &dummy_plci;
  1485. a->TelOAD[0] = (byte)(parms[3].length);
  1486. for(i=1;parms[3].length>=i && i<22;i++) {
  1487. a->TelOAD[i] = parms[3].info[i];
  1488. }
  1489. a->TelOAD[i] = 0;
  1490. a->TelOSA[0] = (byte)(parms[4].length);
  1491. for(i=1;parms[4].length>=i && i<22;i++) {
  1492. a->TelOSA[i] = parms[4].info[i];
  1493. }
  1494. a->TelOSA[i] = 0;
  1495. }
  1496. else Info = 0x2002; /* wrong controller, codec not supported */
  1497. }
  1498. else{ /* clear listen */
  1499. a->codec_listen[appl->Id-1] = (PLCI *)0;
  1500. }
  1501. }
  1502. sendf(appl,
  1503. _LISTEN_R|CONFIRM,
  1504. Id,
  1505. Number,
  1506. "w",Info);
  1507. if (a) listen_check(a);
  1508. return false;
  1509. }
  1510. byte info_req(dword Id, word Number, DIVA_CAPI_ADAPTER * a, PLCI * plci, APPL * appl, API_PARSE * msg)
  1511. {
  1512. word i;
  1513. API_PARSE * ai;
  1514. PLCI * rc_plci = NULL;
  1515. API_PARSE ai_parms[5];
  1516. word Info = 0;
  1517. dbug(1,dprintf("info_req"));
  1518. for(i=0;i<5;i++) ai_parms[i].length = 0;
  1519. ai = &msg[1];
  1520. if(ai->length)
  1521. {
  1522. if(api_parse(&ai->info[1],(word)ai->length,"ssss",ai_parms))
  1523. {
  1524. dbug(1,dprintf("AddInfo wrong"));
  1525. Info = _WRONG_MESSAGE_FORMAT;
  1526. }
  1527. }
  1528. if(!a) Info = _WRONG_STATE;
  1529. if(!Info && plci)
  1530. { /* no fac, with CPN, or KEY */
  1531. rc_plci = plci;
  1532. if(!ai_parms[3].length && plci->State && (msg[0].length || ai_parms[1].length) )
  1533. {
  1534. /* overlap sending option */
  1535. dbug(1,dprintf("OvlSnd"));
  1536. add_s(plci,CPN,&msg[0]);
  1537. add_s(plci,KEY,&ai_parms[1]);
  1538. sig_req(plci,INFO_REQ,0);
  1539. send_req(plci);
  1540. return false;
  1541. }
  1542. if(plci->State && ai_parms[2].length)
  1543. {
  1544. /* User_Info option */
  1545. dbug(1,dprintf("UUI"));
  1546. add_s(plci,UUI,&ai_parms[2]);
  1547. sig_req(plci,USER_DATA,0);
  1548. }
  1549. else if(plci->State && ai_parms[3].length)
  1550. {
  1551. /* Facility option */
  1552. dbug(1,dprintf("FAC"));
  1553. add_s(plci,CPN,&msg[0]);
  1554. add_ai(plci, &msg[1]);
  1555. sig_req(plci,FACILITY_REQ,0);
  1556. }
  1557. else
  1558. {
  1559. Info = _WRONG_STATE;
  1560. }
  1561. }
  1562. else if((ai_parms[1].length || ai_parms[2].length || ai_parms[3].length) && !Info)
  1563. {
  1564. /* NCR_Facility option -> send UUI and Keypad too */
  1565. dbug(1,dprintf("NCR_FAC"));
  1566. if((i=get_plci(a)))
  1567. {
  1568. rc_plci = &a->plci[i-1];
  1569. appl->NullCREnable = true;
  1570. rc_plci->internal_command = C_NCR_FAC_REQ;
  1571. rc_plci->appl = appl;
  1572. add_p(rc_plci,CAI,"\x01\x80");
  1573. add_p(rc_plci,UID,"\x06\x43\x61\x70\x69\x32\x30");
  1574. sig_req(rc_plci,ASSIGN,DSIG_ID);
  1575. send_req(rc_plci);
  1576. }
  1577. else
  1578. {
  1579. Info = _OUT_OF_PLCI;
  1580. }
  1581. if(!Info)
  1582. {
  1583. add_s(rc_plci,CPN,&msg[0]);
  1584. add_ai(rc_plci, &msg[1]);
  1585. sig_req(rc_plci,NCR_FACILITY,0);
  1586. send_req(rc_plci);
  1587. return false;
  1588. /* for application controlled supplementary services */
  1589. }
  1590. }
  1591. if (!rc_plci)
  1592. {
  1593. Info = _WRONG_MESSAGE_FORMAT;
  1594. }
  1595. if(!Info)
  1596. {
  1597. send_req(rc_plci);
  1598. }
  1599. else
  1600. { /* appl is not assigned to a PLCI or error condition */
  1601. dbug(1,dprintf("localInfoCon"));
  1602. sendf(appl,
  1603. _INFO_R|CONFIRM,
  1604. Id,
  1605. Number,
  1606. "w",Info);
  1607. }
  1608. return false;
  1609. }
  1610. byte info_res(dword Id, word Number, DIVA_CAPI_ADAPTER * a, PLCI * plci, APPL * appl, API_PARSE * msg)
  1611. {
  1612. dbug(1,dprintf("info_res"));
  1613. return false;
  1614. }
  1615. byte alert_req(dword Id, word Number, DIVA_CAPI_ADAPTER * a, PLCI * plci, APPL * appl, API_PARSE * msg)
  1616. {
  1617. word Info;
  1618. byte ret;
  1619. dbug(1,dprintf("alert_req"));
  1620. Info = _WRONG_IDENTIFIER;
  1621. ret = false;
  1622. if(plci) {
  1623. Info = _ALERT_IGNORED;
  1624. if(plci->State!=INC_CON_ALERT) {
  1625. Info = _WRONG_STATE;
  1626. if(plci->State==INC_CON_PENDING) {
  1627. Info = 0;
  1628. plci->State=INC_CON_ALERT;
  1629. add_ai(plci, &msg[0]);
  1630. sig_req(plci,CALL_ALERT,0);
  1631. ret = 1;
  1632. }
  1633. }
  1634. }
  1635. sendf(appl,
  1636. _ALERT_R|CONFIRM,
  1637. Id,
  1638. Number,
  1639. "w",Info);
  1640. return ret;
  1641. }
  1642. byte facility_req(dword Id, word Number, DIVA_CAPI_ADAPTER * a, PLCI * plci, APPL * appl, API_PARSE * msg)
  1643. {
  1644. word Info = 0;
  1645. word i = 0;
  1646. word selector;
  1647. word SSreq;
  1648. long relatedPLCIvalue;
  1649. DIVA_CAPI_ADAPTER * relatedadapter;
  1650. byte * SSparms = "";
  1651. byte RCparms[] = "\x05\x00\x00\x02\x00\x00";
  1652. byte SSstruct[] = "\x09\x00\x00\x06\x00\x00\x00\x00\x00\x00";
  1653. API_PARSE * parms;
  1654. API_PARSE ss_parms[11];
  1655. PLCI *rplci;
  1656. byte cai[15];
  1657. dword d;
  1658. API_PARSE dummy;
  1659. dbug(1,dprintf("facility_req"));
  1660. for(i=0;i<9;i++) ss_parms[i].length = 0;
  1661. parms = &msg[1];
  1662. if(!a)
  1663. {
  1664. dbug(1,dprintf("wrong Ctrl"));
  1665. Info = _WRONG_IDENTIFIER;
  1666. }
  1667. selector = GET_WORD(msg[0].info);
  1668. if(!Info)
  1669. {
  1670. switch(selector)
  1671. {
  1672. case SELECTOR_HANDSET:
  1673. Info = AdvCodecSupport(a, plci, appl, HOOK_SUPPORT);
  1674. break;
  1675. case SELECTOR_SU_SERV:
  1676. if(!msg[1].length)
  1677. {
  1678. Info = _WRONG_MESSAGE_FORMAT;
  1679. break;
  1680. }
  1681. SSreq = GET_WORD(&(msg[1].info[1]));
  1682. PUT_WORD(&RCparms[1],SSreq);
  1683. SSparms = RCparms;
  1684. switch(SSreq)
  1685. {
  1686. case S_GET_SUPPORTED_SERVICES:
  1687. if((i=get_plci(a)))
  1688. {
  1689. rplci = &a->plci[i-1];
  1690. rplci->appl = appl;
  1691. add_p(rplci,CAI,"\x01\x80");
  1692. add_p(rplci,UID,"\x06\x43\x61\x70\x69\x32\x30");
  1693. sig_req(rplci,ASSIGN,DSIG_ID);
  1694. send_req(rplci);
  1695. }
  1696. else
  1697. {
  1698. PUT_DWORD(&SSstruct[6], MASK_TERMINAL_PORTABILITY);
  1699. SSparms = (byte *)SSstruct;
  1700. break;
  1701. }
  1702. rplci->internal_command = GETSERV_REQ_PEND;
  1703. rplci->number = Number;
  1704. rplci->appl = appl;
  1705. sig_req(rplci,S_SUPPORTED,0);
  1706. send_req(rplci);
  1707. return false;
  1708. break;
  1709. case S_LISTEN:
  1710. if(parms->length==7)
  1711. {
  1712. if(api_parse(&parms->info[1],(word)parms->length,"wbd",ss_parms))
  1713. {
  1714. dbug(1,dprintf("format wrong"));
  1715. Info = _WRONG_MESSAGE_FORMAT;
  1716. break;
  1717. }
  1718. }
  1719. else
  1720. {
  1721. Info = _WRONG_MESSAGE_FORMAT;
  1722. break;
  1723. }
  1724. a->Notification_Mask[appl->Id-1] = GET_DWORD(ss_parms[2].info);
  1725. if(a->Notification_Mask[appl->Id-1] & SMASK_MWI) /* MWI active? */
  1726. {
  1727. if((i=get_plci(a)))
  1728. {
  1729. rplci = &a->plci[i-1];
  1730. rplci->appl = appl;
  1731. add_p(rplci,CAI,"\x01\x80");
  1732. add_p(rplci,UID,"\x06\x43\x61\x70\x69\x32\x30");
  1733. sig_req(rplci,ASSIGN,DSIG_ID);
  1734. send_req(rplci);
  1735. }
  1736. else
  1737. {
  1738. break;
  1739. }
  1740. rplci->internal_command = GET_MWI_STATE;
  1741. rplci->number = Number;
  1742. sig_req(rplci,MWI_POLL,0);
  1743. send_req(rplci);
  1744. }
  1745. break;
  1746. case S_HOLD:
  1747. api_parse(&parms->info[1],(word)parms->length,"ws",ss_parms);
  1748. if(plci && plci->State && plci->SuppState==IDLE)
  1749. {
  1750. plci->SuppState = HOLD_REQUEST;
  1751. plci->command = C_HOLD_REQ;
  1752. add_s(plci,CAI,&ss_parms[1]);
  1753. sig_req(plci,CALL_HOLD,0);
  1754. send_req(plci);
  1755. return false;
  1756. }
  1757. else Info = 0x3010; /* wrong state */
  1758. break;
  1759. case S_RETRIEVE:
  1760. if(plci && plci->State && plci->SuppState==CALL_HELD)
  1761. {
  1762. if(Id & EXT_CONTROLLER)
  1763. {
  1764. if(AdvCodecSupport(a, plci, appl, 0))
  1765. {
  1766. Info = 0x3010; /* wrong state */
  1767. break;
  1768. }
  1769. }
  1770. else plci->tel = 0;
  1771. plci->SuppState = RETRIEVE_REQUEST;
  1772. plci->command = C_RETRIEVE_REQ;
  1773. if(plci->spoofed_msg==SPOOFING_REQUIRED)
  1774. {
  1775. plci->spoofed_msg = CALL_RETRIEVE;
  1776. plci->internal_command = BLOCK_PLCI;
  1777. plci->command = 0;
  1778. dbug(1,dprintf("Spoof"));
  1779. return false;
  1780. }
  1781. else
  1782. {
  1783. sig_req(plci,CALL_RETRIEVE,0);
  1784. send_req(plci);
  1785. return false;
  1786. }
  1787. }
  1788. else Info = 0x3010; /* wrong state */
  1789. break;
  1790. case S_SUSPEND:
  1791. if(parms->length)
  1792. {
  1793. if(api_parse(&parms->info[1],(word)parms->length,"wbs",ss_parms))
  1794. {
  1795. dbug(1,dprintf("format wrong"));
  1796. Info = _WRONG_MESSAGE_FORMAT;
  1797. break;
  1798. }
  1799. }
  1800. if(plci && plci->State)
  1801. {
  1802. add_s(plci,CAI,&ss_parms[2]);
  1803. plci->command = SUSPEND_REQ;
  1804. sig_req(plci,SUSPEND,0);
  1805. plci->State = SUSPENDING;
  1806. send_req(plci);
  1807. }
  1808. else Info = 0x3010; /* wrong state */
  1809. break;
  1810. case S_RESUME:
  1811. if(!(i=get_plci(a)) )
  1812. {
  1813. Info = _OUT_OF_PLCI;
  1814. break;
  1815. }
  1816. rplci = &a->plci[i-1];
  1817. rplci->appl = appl;
  1818. rplci->number = Number;
  1819. rplci->tel = 0;
  1820. rplci->call_dir = CALL_DIR_OUT | CALL_DIR_ORIGINATE;
  1821. /* check 'external controller' bit for codec support */
  1822. if(Id & EXT_CONTROLLER)
  1823. {
  1824. if(AdvCodecSupport(a, rplci, appl, 0) )
  1825. {
  1826. rplci->Id = 0;
  1827. Info = 0x300A;
  1828. break;
  1829. }
  1830. }
  1831. if(parms->length)
  1832. {
  1833. if(api_parse(&parms->info[1],(word)parms->length,"wbs",ss_parms))
  1834. {
  1835. dbug(1,dprintf("format wrong"));
  1836. rplci->Id = 0;
  1837. Info = _WRONG_MESSAGE_FORMAT;
  1838. break;
  1839. }
  1840. }
  1841. dummy.length = 0;
  1842. dummy.info = "\x00";
  1843. add_b1(rplci, &dummy, 0, 0);
  1844. if (a->Info_Mask[appl->Id-1] & 0x200)
  1845. {
  1846. /* early B3 connect (CIP mask bit 9) no release after a disc */
  1847. add_p(rplci,LLI,"\x01\x01");
  1848. }
  1849. add_p(rplci,UID,"\x06\x43\x61\x70\x69\x32\x30");
  1850. sig_req(rplci,ASSIGN,DSIG_ID);
  1851. send_req(rplci);
  1852. add_s(rplci,CAI,&ss_parms[2]);
  1853. rplci->command = RESUME_REQ;
  1854. sig_req(rplci,RESUME,0);
  1855. rplci->State = RESUMING;
  1856. send_req(rplci);
  1857. break;
  1858. case S_CONF_BEGIN: /* Request */
  1859. case S_CONF_DROP:
  1860. case S_CONF_ISOLATE:
  1861. case S_CONF_REATTACH:
  1862. if(api_parse(&parms->info[1],(word)parms->length,"wbd",ss_parms))
  1863. {
  1864. dbug(1,dprintf("format wrong"));
  1865. Info = _WRONG_MESSAGE_FORMAT;
  1866. break;
  1867. }
  1868. if(plci && plci->State && ((plci->SuppState==IDLE)||(plci->SuppState==CALL_HELD)))
  1869. {
  1870. d = GET_DWORD(ss_parms[2].info);
  1871. if(d>=0x80)
  1872. {
  1873. dbug(1,dprintf("format wrong"));
  1874. Info = _WRONG_MESSAGE_FORMAT;
  1875. break;
  1876. }
  1877. plci->ptyState = (byte)SSreq;
  1878. plci->command = 0;
  1879. cai[0] = 2;
  1880. switch(SSreq)
  1881. {
  1882. case S_CONF_BEGIN:
  1883. cai[1] = CONF_BEGIN;
  1884. plci->internal_command = CONF_BEGIN_REQ_PEND;
  1885. break;
  1886. case S_CONF_DROP:
  1887. cai[1] = CONF_DROP;
  1888. plci->internal_command = CONF_DROP_REQ_PEND;
  1889. break;
  1890. case S_CONF_ISOLATE:
  1891. cai[1] = CONF_ISOLATE;
  1892. plci->internal_command = CONF_ISOLATE_REQ_PEND;
  1893. break;
  1894. case S_CONF_REATTACH:
  1895. cai[1] = CONF_REATTACH;
  1896. plci->internal_command = CONF_REATTACH_REQ_PEND;
  1897. break;
  1898. }
  1899. cai[2] = (byte)d; /* Conference Size resp. PartyId */
  1900. add_p(plci,CAI,cai);
  1901. sig_req(plci,S_SERVICE,0);
  1902. send_req(plci);
  1903. return false;
  1904. }
  1905. else Info = 0x3010; /* wrong state */
  1906. break;
  1907. case S_ECT:
  1908. case S_3PTY_BEGIN:
  1909. case S_3PTY_END:
  1910. case S_CONF_ADD:
  1911. if(parms->length==7)
  1912. {
  1913. if(api_parse(&parms->info[1],(word)parms->length,"wbd",ss_parms))
  1914. {
  1915. dbug(1,dprintf("format wrong"));
  1916. Info = _WRONG_MESSAGE_FORMAT;
  1917. break;
  1918. }
  1919. }
  1920. else if(parms->length==8) /* workaround for the T-View-S */
  1921. {
  1922. if(api_parse(&parms->info[1],(word)parms->length,"wbdb",ss_parms))
  1923. {
  1924. dbug(1,dprintf("format wrong"));
  1925. Info = _WRONG_MESSAGE_FORMAT;
  1926. break;
  1927. }
  1928. }
  1929. else
  1930. {
  1931. Info = _WRONG_MESSAGE_FORMAT;
  1932. break;
  1933. }
  1934. if(!msg[1].length)
  1935. {
  1936. Info = _WRONG_MESSAGE_FORMAT;
  1937. break;
  1938. }
  1939. if (!plci)
  1940. {
  1941. Info = _WRONG_IDENTIFIER;
  1942. break;
  1943. }
  1944. relatedPLCIvalue = GET_DWORD(ss_parms[2].info);
  1945. relatedPLCIvalue &= 0x0000FFFF;
  1946. dbug(1,dprintf("PTY/ECT/addCONF,relPLCI=%lx",relatedPLCIvalue));
  1947. /* controller starts with 0 up to (max_adapter - 1) */
  1948. if (((relatedPLCIvalue & 0x7f) == 0)
  1949. || (MapController ((byte)(relatedPLCIvalue & 0x7f)) == 0)
  1950. || (MapController ((byte)(relatedPLCIvalue & 0x7f)) > max_adapter))
  1951. {
  1952. if(SSreq==S_3PTY_END)
  1953. {
  1954. dbug(1, dprintf("wrong Controller use 2nd PLCI=PLCI"));
  1955. rplci = plci;
  1956. }
  1957. else
  1958. {
  1959. Info = 0x3010; /* wrong state */
  1960. break;
  1961. }
  1962. }
  1963. else
  1964. {
  1965. relatedadapter = &adapter[MapController ((byte)(relatedPLCIvalue & 0x7f))-1];
  1966. relatedPLCIvalue >>=8;
  1967. /* find PLCI PTR*/
  1968. for(i=0,rplci=NULL;i<relatedadapter->max_plci;i++)
  1969. {
  1970. if(relatedadapter->plci[i].Id == (byte)relatedPLCIvalue)
  1971. {
  1972. rplci = &relatedadapter->plci[i];
  1973. }
  1974. }
  1975. if(!rplci || !relatedPLCIvalue)
  1976. {
  1977. if(SSreq==S_3PTY_END)
  1978. {
  1979. dbug(1, dprintf("use 2nd PLCI=PLCI"));
  1980. rplci = plci;
  1981. }
  1982. else
  1983. {
  1984. Info = 0x3010; /* wrong state */
  1985. break;
  1986. }
  1987. }
  1988. }
  1989. /*
  1990. dbug(1,dprintf("rplci:%x",rplci));
  1991. dbug(1,dprintf("plci:%x",plci));
  1992. dbug(1,dprintf("rplci->ptyState:%x",rplci->ptyState));
  1993. dbug(1,dprintf("plci->ptyState:%x",plci->ptyState));
  1994. dbug(1,dprintf("SSreq:%x",SSreq));
  1995. dbug(1,dprintf("rplci->internal_command:%x",rplci->internal_command));
  1996. dbug(1,dprintf("rplci->appl:%x",rplci->appl));
  1997. dbug(1,dprintf("rplci->Id:%x",rplci->Id));
  1998. */
  1999. /* send PTY/ECT req, cannot check all states because of US stuff */
  2000. if( !rplci->internal_command && rplci->appl )
  2001. {
  2002. plci->command = 0;
  2003. rplci->relatedPTYPLCI = plci;
  2004. plci->relatedPTYPLCI = rplci;
  2005. rplci->ptyState = (byte)SSreq;
  2006. if(SSreq==S_ECT)
  2007. {
  2008. rplci->internal_command = ECT_REQ_PEND;
  2009. cai[1] = ECT_EXECUTE;
  2010. rplci->vswitchstate=0;
  2011. rplci->vsprot=0;
  2012. rplci->vsprotdialect=0;
  2013. plci->vswitchstate=0;
  2014. plci->vsprot=0;
  2015. plci->vsprotdialect=0;
  2016. }
  2017. else if(SSreq==S_CONF_ADD)
  2018. {
  2019. rplci->internal_command = CONF_ADD_REQ_PEND;
  2020. cai[1] = CONF_ADD;
  2021. }
  2022. else
  2023. {
  2024. rplci->internal_command = PTY_REQ_PEND;
  2025. cai[1] = (byte)(SSreq-3);
  2026. }
  2027. rplci->number = Number;
  2028. if(plci!=rplci) /* explicit invocation */
  2029. {
  2030. cai[0] = 2;
  2031. cai[2] = plci->Sig.Id;
  2032. dbug(1,dprintf("explicit invocation"));
  2033. }
  2034. else
  2035. {
  2036. dbug(1,dprintf("implicit invocation"));
  2037. cai[0] = 1;
  2038. }
  2039. add_p(rplci,CAI,cai);
  2040. sig_req(rplci,S_SERVICE,0);
  2041. send_req(rplci);
  2042. return false;
  2043. }
  2044. else
  2045. {
  2046. dbug(0,dprintf("Wrong line"));
  2047. Info = 0x3010; /* wrong state */
  2048. break;
  2049. }
  2050. break;
  2051. case S_CALL_DEFLECTION:
  2052. if(api_parse(&parms->info[1],(word)parms->length,"wbwss",ss_parms))
  2053. {
  2054. dbug(1,dprintf("format wrong"));
  2055. Info = _WRONG_MESSAGE_FORMAT;
  2056. break;
  2057. }
  2058. if (!plci)
  2059. {
  2060. Info = _WRONG_IDENTIFIER;
  2061. break;
  2062. }
  2063. /* reuse unused screening indicator */
  2064. ss_parms[3].info[3] = (byte)GET_WORD(&(ss_parms[2].info[0]));
  2065. plci->command = 0;
  2066. plci->internal_command = CD_REQ_PEND;
  2067. appl->CDEnable = true;
  2068. cai[0] = 1;
  2069. cai[1] = CALL_DEFLECTION;
  2070. add_p(plci,CAI,cai);
  2071. add_p(plci,CPN,ss_parms[3].info);
  2072. sig_req(plci,S_SERVICE,0);
  2073. send_req(plci);
  2074. return false;
  2075. break;
  2076. case S_CALL_FORWARDING_START:
  2077. if(api_parse(&parms->info[1],(word)parms->length,"wbdwwsss",ss_parms))
  2078. {
  2079. dbug(1,dprintf("format wrong"));
  2080. Info = _WRONG_MESSAGE_FORMAT;
  2081. break;
  2082. }
  2083. if((i=get_plci(a)))
  2084. {
  2085. rplci = &a->plci[i-1];
  2086. rplci->appl = appl;
  2087. add_p(rplci,CAI,"\x01\x80");
  2088. add_p(rplci,UID,"\x06\x43\x61\x70\x69\x32\x30");
  2089. sig_req(rplci,ASSIGN,DSIG_ID);
  2090. send_req(rplci);
  2091. }
  2092. else
  2093. {
  2094. Info = _OUT_OF_PLCI;
  2095. break;
  2096. }
  2097. /* reuse unused screening indicator */
  2098. rplci->internal_command = CF_START_PEND;
  2099. rplci->appl = appl;
  2100. rplci->number = Number;
  2101. appl->S_Handle = GET_DWORD(&(ss_parms[2].info[0]));
  2102. cai[0] = 2;
  2103. cai[1] = 0x70|(byte)GET_WORD(&(ss_parms[3].info[0])); /* Function */
  2104. cai[2] = (byte)GET_WORD(&(ss_parms[4].info[0])); /* Basic Service */
  2105. add_p(rplci,CAI,cai);
  2106. add_p(rplci,OAD,ss_parms[5].info);
  2107. add_p(rplci,CPN,ss_parms[6].info);
  2108. sig_req(rplci,S_SERVICE,0);
  2109. send_req(rplci);
  2110. return false;
  2111. break;
  2112. case S_INTERROGATE_DIVERSION:
  2113. case S_INTERROGATE_NUMBERS:
  2114. case S_CALL_FORWARDING_STOP:
  2115. case S_CCBS_REQUEST:
  2116. case S_CCBS_DEACTIVATE:
  2117. case S_CCBS_INTERROGATE:
  2118. switch(SSreq)
  2119. {
  2120. case S_INTERROGATE_NUMBERS:
  2121. if(api_parse(&parms->info[1],(word)parms->length,"wbd",ss_parms))
  2122. {
  2123. dbug(0,dprintf("format wrong"));
  2124. Info = _WRONG_MESSAGE_FORMAT;
  2125. }
  2126. break;
  2127. case S_CCBS_REQUEST:
  2128. case S_CCBS_DEACTIVATE:
  2129. if(api_parse(&parms->info[1],(word)parms->length,"wbdw",ss_parms))
  2130. {
  2131. dbug(0,dprintf("format wrong"));
  2132. Info = _WRONG_MESSAGE_FORMAT;
  2133. }
  2134. break;
  2135. case S_CCBS_INTERROGATE:
  2136. if(api_parse(&parms->info[1],(word)parms->length,"wbdws",ss_parms))
  2137. {
  2138. dbug(0,dprintf("format wrong"));
  2139. Info = _WRONG_MESSAGE_FORMAT;
  2140. }
  2141. break;
  2142. default:
  2143. if(api_parse(&parms->info[1],(word)parms->length,"wbdwws",ss_parms))
  2144. {
  2145. dbug(0,dprintf("format wrong"));
  2146. Info = _WRONG_MESSAGE_FORMAT;
  2147. break;
  2148. }
  2149. break;
  2150. }
  2151. if(Info) break;
  2152. if((i=get_plci(a)))
  2153. {
  2154. rplci = &a->plci[i-1];
  2155. switch(SSreq)
  2156. {
  2157. case S_INTERROGATE_DIVERSION: /* use cai with S_SERVICE below */
  2158. cai[1] = 0x60|(byte)GET_WORD(&(ss_parms[3].info[0])); /* Function */
  2159. rplci->internal_command = INTERR_DIVERSION_REQ_PEND; /* move to rplci if assigned */
  2160. break;
  2161. case S_INTERROGATE_NUMBERS: /* use cai with S_SERVICE below */
  2162. cai[1] = DIVERSION_INTERROGATE_NUM; /* Function */
  2163. rplci->internal_command = INTERR_NUMBERS_REQ_PEND; /* move to rplci if assigned */
  2164. break;
  2165. case S_CALL_FORWARDING_STOP:
  2166. rplci->internal_command = CF_STOP_PEND;
  2167. cai[1] = 0x80|(byte)GET_WORD(&(ss_parms[3].info[0])); /* Function */
  2168. break;
  2169. case S_CCBS_REQUEST:
  2170. cai[1] = CCBS_REQUEST;
  2171. rplci->internal_command = CCBS_REQUEST_REQ_PEND;
  2172. break;
  2173. case S_CCBS_DEACTIVATE:
  2174. cai[1] = CCBS_DEACTIVATE;
  2175. rplci->internal_command = CCBS_DEACTIVATE_REQ_PEND;
  2176. break;
  2177. case S_CCBS_INTERROGATE:
  2178. cai[1] = CCBS_INTERROGATE;
  2179. rplci->internal_command = CCBS_INTERROGATE_REQ_PEND;
  2180. break;
  2181. default:
  2182. cai[1] = 0;
  2183. break;
  2184. }
  2185. rplci->appl = appl;
  2186. rplci->number = Number;
  2187. add_p(rplci,CAI,"\x01\x80");
  2188. add_p(rplci,UID,"\x06\x43\x61\x70\x69\x32\x30");
  2189. sig_req(rplci,ASSIGN,DSIG_ID);
  2190. send_req(rplci);
  2191. }
  2192. else
  2193. {
  2194. Info = _OUT_OF_PLCI;
  2195. break;
  2196. }
  2197. appl->S_Handle = GET_DWORD(&(ss_parms[2].info[0]));
  2198. switch(SSreq)
  2199. {
  2200. case S_INTERROGATE_NUMBERS:
  2201. cai[0] = 1;
  2202. add_p(rplci,CAI,cai);
  2203. break;
  2204. case S_CCBS_REQUEST:
  2205. case S_CCBS_DEACTIVATE:
  2206. cai[0] = 3;
  2207. PUT_WORD(&cai[2],GET_WORD(&(ss_parms[3].info[0])));
  2208. add_p(rplci,CAI,cai);
  2209. break;
  2210. case S_CCBS_INTERROGATE:
  2211. cai[0] = 3;
  2212. PUT_WORD(&cai[2],GET_WORD(&(ss_parms[3].info[0])));
  2213. add_p(rplci,CAI,cai);
  2214. add_p(rplci,OAD,ss_parms[4].info);
  2215. break;
  2216. default:
  2217. cai[0] = 2;
  2218. cai[2] = (byte)GET_WORD(&(ss_parms[4].info[0])); /* Basic Service */
  2219. add_p(rplci,CAI,cai);
  2220. add_p(rplci,OAD,ss_parms[5].info);
  2221. break;
  2222. }
  2223. sig_req(rplci,S_SERVICE,0);
  2224. send_req(rplci);
  2225. return false;
  2226. break;
  2227. case S_MWI_ACTIVATE:
  2228. if(api_parse(&parms->info[1],(word)parms->length,"wbwdwwwssss",ss_parms))
  2229. {
  2230. dbug(1,dprintf("format wrong"));
  2231. Info = _WRONG_MESSAGE_FORMAT;
  2232. break;
  2233. }
  2234. if(!plci)
  2235. {
  2236. if((i=get_plci(a)))
  2237. {
  2238. rplci = &a->plci[i-1];
  2239. rplci->appl = appl;
  2240. rplci->cr_enquiry=true;
  2241. add_p(rplci,CAI,"\x01\x80");
  2242. add_p(rplci,UID,"\x06\x43\x61\x70\x69\x32\x30");
  2243. sig_req(rplci,ASSIGN,DSIG_ID);
  2244. send_req(rplci);
  2245. }
  2246. else
  2247. {
  2248. Info = _OUT_OF_PLCI;
  2249. break;
  2250. }
  2251. }
  2252. else
  2253. {
  2254. rplci = plci;
  2255. rplci->cr_enquiry=false;
  2256. }
  2257. rplci->command = 0;
  2258. rplci->internal_command = MWI_ACTIVATE_REQ_PEND;
  2259. rplci->appl = appl;
  2260. rplci->number = Number;
  2261. cai[0] = 13;
  2262. cai[1] = ACTIVATION_MWI; /* Function */
  2263. PUT_WORD(&cai[2],GET_WORD(&(ss_parms[2].info[0]))); /* Basic Service */
  2264. PUT_DWORD(&cai[4],GET_DWORD(&(ss_parms[3].info[0]))); /* Number of Messages */
  2265. PUT_WORD(&cai[8],GET_WORD(&(ss_parms[4].info[0]))); /* Message Status */
  2266. PUT_WORD(&cai[10],GET_WORD(&(ss_parms[5].info[0]))); /* Message Reference */
  2267. PUT_WORD(&cai[12],GET_WORD(&(ss_parms[6].info[0]))); /* Invocation Mode */
  2268. add_p(rplci,CAI,cai);
  2269. add_p(rplci,CPN,ss_parms[7].info); /* Receiving User Number */
  2270. add_p(rplci,OAD,ss_parms[8].info); /* Controlling User Number */
  2271. add_p(rplci,OSA,ss_parms[9].info); /* Controlling User Provided Number */
  2272. add_p(rplci,UID,ss_parms[10].info); /* Time */
  2273. sig_req(rplci,S_SERVICE,0);
  2274. send_req(rplci);
  2275. return false;
  2276. case S_MWI_DEACTIVATE:
  2277. if(api_parse(&parms->info[1],(word)parms->length,"wbwwss",ss_parms))
  2278. {
  2279. dbug(1,dprintf("format wrong"));
  2280. Info = _WRONG_MESSAGE_FORMAT;
  2281. break;
  2282. }
  2283. if(!plci)
  2284. {
  2285. if((i=get_plci(a)))
  2286. {
  2287. rplci = &a->plci[i-1];
  2288. rplci->appl = appl;
  2289. rplci->cr_enquiry=true;
  2290. add_p(rplci,CAI,"\x01\x80");
  2291. add_p(rplci,UID,"\x06\x43\x61\x70\x69\x32\x30");
  2292. sig_req(rplci,ASSIGN,DSIG_ID);
  2293. send_req(rplci);
  2294. }
  2295. else
  2296. {
  2297. Info = _OUT_OF_PLCI;
  2298. break;
  2299. }
  2300. }
  2301. else
  2302. {
  2303. rplci = plci;
  2304. rplci->cr_enquiry=false;
  2305. }
  2306. rplci->command = 0;
  2307. rplci->internal_command = MWI_DEACTIVATE_REQ_PEND;
  2308. rplci->appl = appl;
  2309. rplci->number = Number;
  2310. cai[0] = 5;
  2311. cai[1] = DEACTIVATION_MWI; /* Function */
  2312. PUT_WORD(&cai[2],GET_WORD(&(ss_parms[2].info[0]))); /* Basic Service */
  2313. PUT_WORD(&cai[4],GET_WORD(&(ss_parms[3].info[0]))); /* Invocation Mode */
  2314. add_p(rplci,CAI,cai);
  2315. add_p(rplci,CPN,ss_parms[4].info); /* Receiving User Number */
  2316. add_p(rplci,OAD,ss_parms[5].info); /* Controlling User Number */
  2317. sig_req(rplci,S_SERVICE,0);
  2318. send_req(rplci);
  2319. return false;
  2320. default:
  2321. Info = 0x300E; /* not supported */
  2322. break;
  2323. }
  2324. break; /* case SELECTOR_SU_SERV: end */
  2325. case SELECTOR_DTMF:
  2326. return (dtmf_request (Id, Number, a, plci, appl, msg));
  2327. case SELECTOR_LINE_INTERCONNECT:
  2328. return (mixer_request (Id, Number, a, plci, appl, msg));
  2329. case PRIV_SELECTOR_ECHO_CANCELLER:
  2330. appl->appl_flags |= APPL_FLAG_PRIV_EC_SPEC;
  2331. return (ec_request (Id, Number, a, plci, appl, msg));
  2332. case SELECTOR_ECHO_CANCELLER:
  2333. appl->appl_flags &= ~APPL_FLAG_PRIV_EC_SPEC;
  2334. return (ec_request (Id, Number, a, plci, appl, msg));
  2335. case SELECTOR_V42BIS:
  2336. default:
  2337. Info = _FACILITY_NOT_SUPPORTED;
  2338. break;
  2339. } /* end of switch(selector) */
  2340. }
  2341. dbug(1,dprintf("SendFacRc"));
  2342. sendf(appl,
  2343. _FACILITY_R|CONFIRM,
  2344. Id,
  2345. Number,
  2346. "wws",Info,selector,SSparms);
  2347. return false;
  2348. }
  2349. byte facility_res(dword Id, word Number, DIVA_CAPI_ADAPTER * a, PLCI * plci, APPL * appl, API_PARSE * msg)
  2350. {
  2351. dbug(1,dprintf("facility_res"));
  2352. return false;
  2353. }
  2354. byte connect_b3_req(dword Id, word Number, DIVA_CAPI_ADAPTER * a, PLCI * plci, APPL * appl, API_PARSE * parms)
  2355. {
  2356. word Info = 0;
  2357. byte req;
  2358. byte len;
  2359. word w;
  2360. word fax_control_bits, fax_feature_bits, fax_info_change;
  2361. API_PARSE * ncpi;
  2362. byte pvc[2];
  2363. API_PARSE fax_parms[9];
  2364. word i;
  2365. dbug(1,dprintf("connect_b3_req"));
  2366. if(plci)
  2367. {
  2368. if ((plci->State == IDLE) || (plci->State == OUTG_DIS_PENDING)
  2369. || (plci->State == INC_DIS_PENDING) || (plci->SuppState != IDLE))
  2370. {
  2371. Info = _WRONG_STATE;
  2372. }
  2373. else
  2374. {
  2375. /* local reply if assign unsuccessfull
  2376. or B3 protocol allows only one layer 3 connection
  2377. and already connected
  2378. or B2 protocol not any LAPD
  2379. and connect_b3_req contradicts originate/answer direction */
  2380. if (!plci->NL.Id
  2381. || (((plci->B3_prot != B3_T90NL) && (plci->B3_prot != B3_ISO8208) && (plci->B3_prot != B3_X25_DCE))
  2382. && ((plci->channels != 0)
  2383. || (((plci->B2_prot != B2_SDLC) && (plci->B2_prot != B2_LAPD) && (plci->B2_prot != B2_LAPD_FREE_SAPI_SEL))
  2384. && ((plci->call_dir & CALL_DIR_ANSWER) && !(plci->call_dir & CALL_DIR_FORCE_OUTG_NL))))))
  2385. {
  2386. dbug(1,dprintf("B3 already connected=%d or no NL.Id=0x%x, dir=%d sstate=0x%x",
  2387. plci->channels,plci->NL.Id,plci->call_dir,plci->SuppState));
  2388. Info = _WRONG_STATE;
  2389. sendf(appl,
  2390. _CONNECT_B3_R|CONFIRM,
  2391. Id,
  2392. Number,
  2393. "w",Info);
  2394. return false;
  2395. }
  2396. plci->requested_options_conn = 0;
  2397. req = N_CONNECT;
  2398. ncpi = &parms[0];
  2399. if(plci->B3_prot==2 || plci->B3_prot==3)
  2400. {
  2401. if(ncpi->length>2)
  2402. {
  2403. /* check for PVC */
  2404. if(ncpi->info[2] || ncpi->info[3])
  2405. {
  2406. pvc[0] = ncpi->info[3];
  2407. pvc[1] = ncpi->info[2];
  2408. add_d(plci,2,pvc);
  2409. req = N_RESET;
  2410. }
  2411. else
  2412. {
  2413. if(ncpi->info[1] &1) req = N_CONNECT | N_D_BIT;
  2414. add_d(plci,(word)(ncpi->length-3),&ncpi->info[4]);
  2415. }
  2416. }
  2417. }
  2418. else if(plci->B3_prot==5)
  2419. {
  2420. if (plci->NL.Id && !plci->nl_remove_id)
  2421. {
  2422. fax_control_bits = GET_WORD(&((T30_INFO *)plci->fax_connect_info_buffer)->control_bits_low);
  2423. fax_feature_bits = GET_WORD(&((T30_INFO *)plci->fax_connect_info_buffer)->feature_bits_low);
  2424. if (!(fax_control_bits & T30_CONTROL_BIT_MORE_DOCUMENTS)
  2425. || (fax_feature_bits & T30_FEATURE_BIT_MORE_DOCUMENTS))
  2426. {
  2427. len = (byte)(&(((T30_INFO *) 0)->universal_6));
  2428. fax_info_change = false;
  2429. if (ncpi->length >= 4)
  2430. {
  2431. w = GET_WORD(&ncpi->info[3]);
  2432. if ((w & 0x0001) != ((word)(((T30_INFO *)(plci->fax_connect_info_buffer))->resolution & 0x0001)))
  2433. {
  2434. ((T30_INFO *)(plci->fax_connect_info_buffer))->resolution =
  2435. (byte)((((T30_INFO *)(plci->fax_connect_info_buffer))->resolution & ~T30_RESOLUTION_R8_0770_OR_200) |
  2436. ((w & 0x0001) ? T30_RESOLUTION_R8_0770_OR_200 : 0));
  2437. fax_info_change = true;
  2438. }
  2439. fax_control_bits &= ~(T30_CONTROL_BIT_REQUEST_POLLING | T30_CONTROL_BIT_MORE_DOCUMENTS);
  2440. if (w & 0x0002) /* Fax-polling request */
  2441. fax_control_bits |= T30_CONTROL_BIT_REQUEST_POLLING;
  2442. if ((w & 0x0004) /* Request to send / poll another document */
  2443. && (a->manufacturer_features & MANUFACTURER_FEATURE_FAX_MORE_DOCUMENTS))
  2444. {
  2445. fax_control_bits |= T30_CONTROL_BIT_MORE_DOCUMENTS;
  2446. }
  2447. if (ncpi->length >= 6)
  2448. {
  2449. w = GET_WORD(&ncpi->info[5]);
  2450. if (((byte) w) != ((T30_INFO *)(plci->fax_connect_info_buffer))->data_format)
  2451. {
  2452. ((T30_INFO *)(plci->fax_connect_info_buffer))->data_format = (byte) w;
  2453. fax_info_change = true;
  2454. }
  2455. if ((a->man_profile.private_options & (1L << PRIVATE_FAX_SUB_SEP_PWD))
  2456. && (GET_WORD(&ncpi->info[5]) & 0x8000)) /* Private SEP/SUB/PWD enable */
  2457. {
  2458. plci->requested_options_conn |= (1L << PRIVATE_FAX_SUB_SEP_PWD);
  2459. }
  2460. if ((a->man_profile.private_options & (1L << PRIVATE_FAX_NONSTANDARD))
  2461. && (GET_WORD(&ncpi->info[5]) & 0x4000)) /* Private non-standard facilities enable */
  2462. {
  2463. plci->requested_options_conn |= (1L << PRIVATE_FAX_NONSTANDARD);
  2464. }
  2465. fax_control_bits &= ~(T30_CONTROL_BIT_ACCEPT_SUBADDRESS | T30_CONTROL_BIT_ACCEPT_SEL_POLLING |
  2466. T30_CONTROL_BIT_ACCEPT_PASSWORD);
  2467. if ((plci->requested_options_conn | plci->requested_options | a->requested_options_table[appl->Id-1])
  2468. & ((1L << PRIVATE_FAX_SUB_SEP_PWD) | (1L << PRIVATE_FAX_NONSTANDARD)))
  2469. {
  2470. if (api_parse (&ncpi->info[1], ncpi->length, "wwwwsss", fax_parms))
  2471. Info = _WRONG_MESSAGE_FORMAT;
  2472. else
  2473. {
  2474. if ((plci->requested_options_conn | plci->requested_options | a->requested_options_table[appl->Id-1])
  2475. & (1L << PRIVATE_FAX_SUB_SEP_PWD))
  2476. {
  2477. fax_control_bits |= T30_CONTROL_BIT_ACCEPT_SUBADDRESS | T30_CONTROL_BIT_ACCEPT_PASSWORD;
  2478. if (fax_control_bits & T30_CONTROL_BIT_ACCEPT_POLLING)
  2479. fax_control_bits |= T30_CONTROL_BIT_ACCEPT_SEL_POLLING;
  2480. }
  2481. w = fax_parms[4].length;
  2482. if (w > 20)
  2483. w = 20;
  2484. ((T30_INFO *)(plci->fax_connect_info_buffer))->station_id_len = (byte) w;
  2485. for (i = 0; i < w; i++)
  2486. ((T30_INFO *)(plci->fax_connect_info_buffer))->station_id[i] = fax_parms[4].info[1+i];
  2487. ((T30_INFO *)(plci->fax_connect_info_buffer))->head_line_len = 0;
  2488. len = (byte)(((T30_INFO *) 0)->station_id + 20);
  2489. w = fax_parms[5].length;
  2490. if (w > 20)
  2491. w = 20;
  2492. plci->fax_connect_info_buffer[len++] = (byte) w;
  2493. for (i = 0; i < w; i++)
  2494. plci->fax_connect_info_buffer[len++] = fax_parms[5].info[1+i];
  2495. w = fax_parms[6].length;
  2496. if (w > 20)
  2497. w = 20;
  2498. plci->fax_connect_info_buffer[len++] = (byte) w;
  2499. for (i = 0; i < w; i++)
  2500. plci->fax_connect_info_buffer[len++] = fax_parms[6].info[1+i];
  2501. if ((plci->requested_options_conn | plci->requested_options | a->requested_options_table[appl->Id-1])
  2502. & (1L << PRIVATE_FAX_NONSTANDARD))
  2503. {
  2504. if (api_parse (&ncpi->info[1], ncpi->length, "wwwwssss", fax_parms))
  2505. {
  2506. dbug(1,dprintf("non-standard facilities info missing or wrong format"));
  2507. plci->fax_connect_info_buffer[len++] = 0;
  2508. }
  2509. else
  2510. {
  2511. if ((fax_parms[7].length >= 3) && (fax_parms[7].info[1] >= 2))
  2512. plci->nsf_control_bits = GET_WORD(&fax_parms[7].info[2]);
  2513. plci->fax_connect_info_buffer[len++] = (byte)(fax_parms[7].length);
  2514. for (i = 0; i < fax_parms[7].length; i++)
  2515. plci->fax_connect_info_buffer[len++] = fax_parms[7].info[1+i];
  2516. }
  2517. }
  2518. }
  2519. }
  2520. else
  2521. {
  2522. len = (byte)(&(((T30_INFO *) 0)->universal_6));
  2523. }
  2524. fax_info_change = true;
  2525. }
  2526. if (fax_control_bits != GET_WORD(&((T30_INFO *)plci->fax_connect_info_buffer)->control_bits_low))
  2527. {
  2528. PUT_WORD (&((T30_INFO *)plci->fax_connect_info_buffer)->control_bits_low, fax_control_bits);
  2529. fax_info_change = true;
  2530. }
  2531. }
  2532. if (Info == GOOD)
  2533. {
  2534. plci->fax_connect_info_length = len;
  2535. if (fax_info_change)
  2536. {
  2537. if (fax_feature_bits & T30_FEATURE_BIT_MORE_DOCUMENTS)
  2538. {
  2539. start_internal_command (Id, plci, fax_connect_info_command);
  2540. return false;
  2541. }
  2542. else
  2543. {
  2544. start_internal_command (Id, plci, fax_adjust_b23_command);
  2545. return false;
  2546. }
  2547. }
  2548. }
  2549. }
  2550. else Info = _WRONG_STATE;
  2551. }
  2552. else Info = _WRONG_STATE;
  2553. }
  2554. else if (plci->B3_prot == B3_RTP)
  2555. {
  2556. plci->internal_req_buffer[0] = ncpi->length + 1;
  2557. plci->internal_req_buffer[1] = UDATA_REQUEST_RTP_RECONFIGURE;
  2558. for (w = 0; w < ncpi->length; w++)
  2559. plci->internal_req_buffer[2+w] = ncpi->info[1+w];
  2560. start_internal_command (Id, plci, rtp_connect_b3_req_command);
  2561. return false;
  2562. }
  2563. if(!Info)
  2564. {
  2565. nl_req_ncci(plci,req,0);
  2566. return 1;
  2567. }
  2568. }
  2569. }
  2570. else Info = _WRONG_IDENTIFIER;
  2571. sendf(appl,
  2572. _CONNECT_B3_R|CONFIRM,
  2573. Id,
  2574. Number,
  2575. "w",Info);
  2576. return false;
  2577. }
  2578. byte connect_b3_res(dword Id, word Number, DIVA_CAPI_ADAPTER * a, PLCI * plci, APPL * appl, API_PARSE * parms)
  2579. {
  2580. word ncci;
  2581. API_PARSE * ncpi;
  2582. byte req;
  2583. word w;
  2584. API_PARSE fax_parms[9];
  2585. word i;
  2586. byte len;
  2587. dbug(1,dprintf("connect_b3_res"));
  2588. ncci = (word)(Id>>16);
  2589. if(plci && ncci) {
  2590. if(a->ncci_state[ncci]==INC_CON_PENDING) {
  2591. if (GET_WORD (&parms[0].info[0]) != 0)
  2592. {
  2593. a->ncci_state[ncci] = OUTG_REJ_PENDING;
  2594. channel_request_xon (plci, a->ncci_ch[ncci]);
  2595. channel_xmit_xon (plci);
  2596. cleanup_ncci_data (plci, ncci);
  2597. nl_req_ncci(plci,N_DISC,(byte)ncci);
  2598. return 1;
  2599. }
  2600. a->ncci_state[ncci] = INC_ACT_PENDING;
  2601. req = N_CONNECT_ACK;
  2602. ncpi = &parms[1];
  2603. if ((plci->B3_prot == 4) || (plci->B3_prot == 5) || (plci->B3_prot == 7))
  2604. {
  2605. if ((plci->requested_options_conn | plci->requested_options | a->requested_options_table[plci->appl->Id-1])
  2606. & (1L << PRIVATE_FAX_NONSTANDARD))
  2607. {
  2608. if (((plci->B3_prot == 4) || (plci->B3_prot == 5))
  2609. && (plci->nsf_control_bits & T30_NSF_CONTROL_BIT_ENABLE_NSF)
  2610. && (plci->nsf_control_bits & T30_NSF_CONTROL_BIT_NEGOTIATE_RESP))
  2611. {
  2612. len = ((byte)(((T30_INFO *) 0)->station_id + 20));
  2613. if (plci->fax_connect_info_length < len)
  2614. {
  2615. ((T30_INFO *)(plci->fax_connect_info_buffer))->station_id_len = 0;
  2616. ((T30_INFO *)(plci->fax_connect_info_buffer))->head_line_len = 0;
  2617. }
  2618. if (api_parse (&ncpi->info[1], ncpi->length, "wwwwssss", fax_parms))
  2619. {
  2620. dbug(1,dprintf("non-standard facilities info missing or wrong format"));
  2621. }
  2622. else
  2623. {
  2624. if (plci->fax_connect_info_length <= len)
  2625. plci->fax_connect_info_buffer[len] = 0;
  2626. len += 1 + plci->fax_connect_info_buffer[len];
  2627. if (plci->fax_connect_info_length <= len)
  2628. plci->fax_connect_info_buffer[len] = 0;
  2629. len += 1 + plci->fax_connect_info_buffer[len];
  2630. if ((fax_parms[7].length >= 3) && (fax_parms[7].info[1] >= 2))
  2631. plci->nsf_control_bits = GET_WORD(&fax_parms[7].info[2]);
  2632. plci->fax_connect_info_buffer[len++] = (byte)(fax_parms[7].length);
  2633. for (i = 0; i < fax_parms[7].length; i++)
  2634. plci->fax_connect_info_buffer[len++] = fax_parms[7].info[1+i];
  2635. }
  2636. plci->fax_connect_info_length = len;
  2637. ((T30_INFO *)(plci->fax_connect_info_buffer))->code = 0;
  2638. start_internal_command (Id, plci, fax_connect_ack_command);
  2639. return false;
  2640. }
  2641. }
  2642. nl_req_ncci(plci,req,(byte)ncci);
  2643. if ((plci->ncpi_state & NCPI_VALID_CONNECT_B3_ACT)
  2644. && !(plci->ncpi_state & NCPI_CONNECT_B3_ACT_SENT))
  2645. {
  2646. if (plci->B3_prot == 4)
  2647. sendf(appl,_CONNECT_B3_ACTIVE_I,Id,0,"s","");
  2648. else
  2649. sendf(appl,_CONNECT_B3_ACTIVE_I,Id,0,"S",plci->ncpi_buffer);
  2650. plci->ncpi_state |= NCPI_CONNECT_B3_ACT_SENT;
  2651. }
  2652. }
  2653. else if (plci->B3_prot == B3_RTP)
  2654. {
  2655. plci->internal_req_buffer[0] = ncpi->length + 1;
  2656. plci->internal_req_buffer[1] = UDATA_REQUEST_RTP_RECONFIGURE;
  2657. for (w = 0; w < ncpi->length; w++)
  2658. plci->internal_req_buffer[2+w] = ncpi->info[1+w];
  2659. start_internal_command (Id, plci, rtp_connect_b3_res_command);
  2660. return false;
  2661. }
  2662. else
  2663. {
  2664. if(ncpi->length>2) {
  2665. if(ncpi->info[1] &1) req = N_CONNECT_ACK | N_D_BIT;
  2666. add_d(plci,(word)(ncpi->length-3),&ncpi->info[4]);
  2667. }
  2668. nl_req_ncci(plci,req,(byte)ncci);
  2669. sendf(appl,_CONNECT_B3_ACTIVE_I,Id,0,"s","");
  2670. if (plci->adjust_b_restore)
  2671. {
  2672. plci->adjust_b_restore = false;
  2673. start_internal_command (Id, plci, adjust_b_restore);
  2674. }
  2675. }
  2676. return 1;
  2677. }
  2678. }
  2679. return false;
  2680. }
  2681. byte connect_b3_a_res(dword Id, word Number, DIVA_CAPI_ADAPTER * a, PLCI * plci, APPL * appl, API_PARSE * parms)
  2682. {
  2683. word ncci;
  2684. ncci = (word)(Id>>16);
  2685. dbug(1,dprintf("connect_b3_a_res(ncci=0x%x)",ncci));
  2686. if (plci && ncci && (plci->State != IDLE) && (plci->State != INC_DIS_PENDING)
  2687. && (plci->State != OUTG_DIS_PENDING))
  2688. {
  2689. if(a->ncci_state[ncci]==INC_ACT_PENDING) {
  2690. a->ncci_state[ncci] = CONNECTED;
  2691. if(plci->State!=INC_CON_CONNECTED_ALERT) plci->State = CONNECTED;
  2692. channel_request_xon (plci, a->ncci_ch[ncci]);
  2693. channel_xmit_xon (plci);
  2694. }
  2695. }
  2696. return false;
  2697. }
  2698. byte disconnect_b3_req(dword Id, word Number, DIVA_CAPI_ADAPTER * a, PLCI * plci, APPL * appl, API_PARSE * parms)
  2699. {
  2700. word Info;
  2701. word ncci;
  2702. API_PARSE * ncpi;
  2703. dbug(1,dprintf("disconnect_b3_req"));
  2704. Info = _WRONG_IDENTIFIER;
  2705. ncci = (word)(Id>>16);
  2706. if (plci && ncci)
  2707. {
  2708. Info = _WRONG_STATE;
  2709. if ((a->ncci_state[ncci] == CONNECTED)
  2710. || (a->ncci_state[ncci] == OUTG_CON_PENDING)
  2711. || (a->ncci_state[ncci] == INC_CON_PENDING)
  2712. || (a->ncci_state[ncci] == INC_ACT_PENDING))
  2713. {
  2714. a->ncci_state[ncci] = OUTG_DIS_PENDING;
  2715. channel_request_xon (plci, a->ncci_ch[ncci]);
  2716. channel_xmit_xon (plci);
  2717. if (a->ncci[ncci].data_pending
  2718. && ((plci->B3_prot == B3_TRANSPARENT)
  2719. || (plci->B3_prot == B3_T30)
  2720. || (plci->B3_prot == B3_T30_WITH_EXTENSIONS)))
  2721. {
  2722. plci->send_disc = (byte)ncci;
  2723. plci->command = 0;
  2724. return false;
  2725. }
  2726. else
  2727. {
  2728. cleanup_ncci_data (plci, ncci);
  2729. if(plci->B3_prot==2 || plci->B3_prot==3)
  2730. {
  2731. ncpi = &parms[0];
  2732. if(ncpi->length>3)
  2733. {
  2734. add_d(plci, (word)(ncpi->length - 3) ,(byte *)&(ncpi->info[4]));
  2735. }
  2736. }
  2737. nl_req_ncci(plci,N_DISC,(byte)ncci);
  2738. }
  2739. return 1;
  2740. }
  2741. }
  2742. sendf(appl,
  2743. _DISCONNECT_B3_R|CONFIRM,
  2744. Id,
  2745. Number,
  2746. "w",Info);
  2747. return false;
  2748. }
  2749. byte disconnect_b3_res(dword Id, word Number, DIVA_CAPI_ADAPTER * a, PLCI * plci, APPL * appl, API_PARSE * parms)
  2750. {
  2751. word ncci;
  2752. word i;
  2753. ncci = (word)(Id>>16);
  2754. dbug(1,dprintf("disconnect_b3_res(ncci=0x%x",ncci));
  2755. if(plci && ncci) {
  2756. plci->requested_options_conn = 0;
  2757. plci->fax_connect_info_length = 0;
  2758. plci->ncpi_state = 0x00;
  2759. if (((plci->B3_prot != B3_T90NL) && (plci->B3_prot != B3_ISO8208) && (plci->B3_prot != B3_X25_DCE))
  2760. && ((plci->B2_prot != B2_LAPD) && (plci->B2_prot != B2_LAPD_FREE_SAPI_SEL)))
  2761. {
  2762. plci->call_dir |= CALL_DIR_FORCE_OUTG_NL;
  2763. }
  2764. for(i=0; i<MAX_CHANNELS_PER_PLCI && plci->inc_dis_ncci_table[i]!=(byte)ncci; i++);
  2765. if(i<MAX_CHANNELS_PER_PLCI) {
  2766. if(plci->channels)plci->channels--;
  2767. for(; i<MAX_CHANNELS_PER_PLCI-1; i++) plci->inc_dis_ncci_table[i] = plci->inc_dis_ncci_table[i+1];
  2768. plci->inc_dis_ncci_table[MAX_CHANNELS_PER_PLCI-1] = 0;
  2769. ncci_free_receive_buffers (plci, ncci);
  2770. if((plci->State==IDLE || plci->State==SUSPENDING) && !plci->channels){
  2771. if(plci->State == SUSPENDING){
  2772. sendf(plci->appl,
  2773. _FACILITY_I,
  2774. Id & 0xffffL,
  2775. 0,
  2776. "ws", (word)3, "\x03\x04\x00\x00");
  2777. sendf(plci->appl, _DISCONNECT_I, Id & 0xffffL, 0, "w", 0);
  2778. }
  2779. plci_remove(plci);
  2780. plci->State=IDLE;
  2781. }
  2782. }
  2783. else
  2784. {
  2785. if ((a->manufacturer_features & MANUFACTURER_FEATURE_FAX_PAPER_FORMATS)
  2786. && ((plci->B3_prot == 4) || (plci->B3_prot == 5))
  2787. && (a->ncci_state[ncci] == INC_DIS_PENDING))
  2788. {
  2789. ncci_free_receive_buffers (plci, ncci);
  2790. nl_req_ncci(plci,N_EDATA,(byte)ncci);
  2791. plci->adapter->ncci_state[ncci] = IDLE;
  2792. start_internal_command (Id, plci, fax_disconnect_command);
  2793. return 1;
  2794. }
  2795. }
  2796. }
  2797. return false;
  2798. }
  2799. byte data_b3_req(dword Id, word Number, DIVA_CAPI_ADAPTER * a, PLCI * plci, APPL * appl, API_PARSE * parms)
  2800. {
  2801. NCCI *ncci_ptr;
  2802. DATA_B3_DESC *data;
  2803. word Info;
  2804. word ncci;
  2805. word i;
  2806. dbug(1,dprintf("data_b3_req"));
  2807. Info = _WRONG_IDENTIFIER;
  2808. ncci = (word)(Id>>16);
  2809. dbug(1,dprintf("ncci=0x%x, plci=0x%x",ncci,plci));
  2810. if (plci && ncci)
  2811. {
  2812. Info = _WRONG_STATE;
  2813. if ((a->ncci_state[ncci] == CONNECTED)
  2814. || (a->ncci_state[ncci] == INC_ACT_PENDING))
  2815. {
  2816. /* queue data */
  2817. ncci_ptr = &(a->ncci[ncci]);
  2818. i = ncci_ptr->data_out + ncci_ptr->data_pending;
  2819. if (i >= MAX_DATA_B3)
  2820. i -= MAX_DATA_B3;
  2821. data = &(ncci_ptr->DBuffer[i]);
  2822. data->Number = Number;
  2823. if ((((byte *)(parms[0].info)) >= ((byte *)(plci->msg_in_queue)))
  2824. && (((byte *)(parms[0].info)) < ((byte *)(plci->msg_in_queue)) + sizeof(plci->msg_in_queue)))
  2825. {
  2826. data->P = (byte *)(long)(*((dword *)(parms[0].info)));
  2827. }
  2828. else
  2829. data->P = TransmitBufferSet(appl,*(dword *)parms[0].info);
  2830. data->Length = GET_WORD(parms[1].info);
  2831. data->Handle = GET_WORD(parms[2].info);
  2832. data->Flags = GET_WORD(parms[3].info);
  2833. (ncci_ptr->data_pending)++;
  2834. /* check for delivery confirmation */
  2835. if (data->Flags & 0x0004)
  2836. {
  2837. i = ncci_ptr->data_ack_out + ncci_ptr->data_ack_pending;
  2838. if (i >= MAX_DATA_ACK)
  2839. i -= MAX_DATA_ACK;
  2840. ncci_ptr->DataAck[i].Number = data->Number;
  2841. ncci_ptr->DataAck[i].Handle = data->Handle;
  2842. (ncci_ptr->data_ack_pending)++;
  2843. }
  2844. send_data(plci);
  2845. return false;
  2846. }
  2847. }
  2848. if (appl)
  2849. {
  2850. if (plci)
  2851. {
  2852. if ((((byte *)(parms[0].info)) >= ((byte *)(plci->msg_in_queue)))
  2853. && (((byte *)(parms[0].info)) < ((byte *)(plci->msg_in_queue)) + sizeof(plci->msg_in_queue)))
  2854. {
  2855. TransmitBufferFree (appl, (byte *)(long)(*((dword *)(parms[0].info))));
  2856. }
  2857. }
  2858. sendf(appl,
  2859. _DATA_B3_R|CONFIRM,
  2860. Id,
  2861. Number,
  2862. "ww",GET_WORD(parms[2].info),Info);
  2863. }
  2864. return false;
  2865. }
  2866. byte data_b3_res(dword Id, word Number, DIVA_CAPI_ADAPTER * a, PLCI * plci, APPL * appl, API_PARSE * parms)
  2867. {
  2868. word n;
  2869. word ncci;
  2870. word NCCIcode;
  2871. dbug(1,dprintf("data_b3_res"));
  2872. ncci = (word)(Id>>16);
  2873. if(plci && ncci) {
  2874. n = GET_WORD(parms[0].info);
  2875. dbug(1,dprintf("free(%d)",n));
  2876. NCCIcode = ncci | (((word) a->Id) << 8);
  2877. if(n<appl->MaxBuffer &&
  2878. appl->DataNCCI[n]==NCCIcode &&
  2879. (byte)(appl->DataFlags[n]>>8)==plci->Id) {
  2880. dbug(1,dprintf("found"));
  2881. appl->DataNCCI[n] = 0;
  2882. if (channel_can_xon (plci, a->ncci_ch[ncci])) {
  2883. channel_request_xon (plci, a->ncci_ch[ncci]);
  2884. }
  2885. channel_xmit_xon (plci);
  2886. if(appl->DataFlags[n] &4) {
  2887. nl_req_ncci(plci,N_DATA_ACK,(byte)ncci);
  2888. return 1;
  2889. }
  2890. }
  2891. }
  2892. return false;
  2893. }
  2894. byte reset_b3_req(dword Id, word Number, DIVA_CAPI_ADAPTER * a, PLCI * plci, APPL * appl, API_PARSE * parms)
  2895. {
  2896. word Info;
  2897. word ncci;
  2898. dbug(1,dprintf("reset_b3_req"));
  2899. Info = _WRONG_IDENTIFIER;
  2900. ncci = (word)(Id>>16);
  2901. if(plci && ncci)
  2902. {
  2903. Info = _WRONG_STATE;
  2904. switch (plci->B3_prot)
  2905. {
  2906. case B3_ISO8208:
  2907. case B3_X25_DCE:
  2908. if(a->ncci_state[ncci]==CONNECTED)
  2909. {
  2910. nl_req_ncci(plci,N_RESET,(byte)ncci);
  2911. send_req(plci);
  2912. Info = GOOD;
  2913. }
  2914. break;
  2915. case B3_TRANSPARENT:
  2916. if(a->ncci_state[ncci]==CONNECTED)
  2917. {
  2918. start_internal_command (Id, plci, reset_b3_command);
  2919. Info = GOOD;
  2920. }
  2921. break;
  2922. }
  2923. }
  2924. /* reset_b3 must result in a reset_b3_con & reset_b3_Ind */
  2925. sendf(appl,
  2926. _RESET_B3_R|CONFIRM,
  2927. Id,
  2928. Number,
  2929. "w",Info);
  2930. return false;
  2931. }
  2932. byte reset_b3_res(dword Id, word Number, DIVA_CAPI_ADAPTER * a, PLCI * plci, APPL * appl, API_PARSE * parms)
  2933. {
  2934. word ncci;
  2935. dbug(1,dprintf("reset_b3_res"));
  2936. ncci = (word)(Id>>16);
  2937. if(plci && ncci) {
  2938. switch (plci->B3_prot)
  2939. {
  2940. case B3_ISO8208:
  2941. case B3_X25_DCE:
  2942. if(a->ncci_state[ncci]==INC_RES_PENDING)
  2943. {
  2944. a->ncci_state[ncci] = CONNECTED;
  2945. nl_req_ncci(plci,N_RESET_ACK,(byte)ncci);
  2946. return true;
  2947. }
  2948. break;
  2949. }
  2950. }
  2951. return false;
  2952. }
  2953. byte connect_b3_t90_a_res(dword Id, word Number, DIVA_CAPI_ADAPTER * a, PLCI * plci, APPL * appl, API_PARSE * parms)
  2954. {
  2955. word ncci;
  2956. API_PARSE * ncpi;
  2957. byte req;
  2958. dbug(1,dprintf("connect_b3_t90_a_res"));
  2959. ncci = (word)(Id>>16);
  2960. if(plci && ncci) {
  2961. if(a->ncci_state[ncci]==INC_ACT_PENDING) {
  2962. a->ncci_state[ncci] = CONNECTED;
  2963. }
  2964. else if(a->ncci_state[ncci]==INC_CON_PENDING) {
  2965. a->ncci_state[ncci] = CONNECTED;
  2966. req = N_CONNECT_ACK;
  2967. /* parms[0]==0 for CAPI original message definition! */
  2968. if(parms[0].info) {
  2969. ncpi = &parms[1];
  2970. if(ncpi->length>2) {
  2971. if(ncpi->info[1] &1) req = N_CONNECT_ACK | N_D_BIT;
  2972. add_d(plci,(word)(ncpi->length-3),&ncpi->info[4]);
  2973. }
  2974. }
  2975. nl_req_ncci(plci,req,(byte)ncci);
  2976. return 1;
  2977. }
  2978. }
  2979. return false;
  2980. }
  2981. byte select_b_req(dword Id, word Number, DIVA_CAPI_ADAPTER * a, PLCI * plci, APPL * appl, API_PARSE * msg)
  2982. {
  2983. word Info=0;
  2984. word i;
  2985. byte tel;
  2986. API_PARSE bp_parms[7];
  2987. if(!plci || !msg)
  2988. {
  2989. Info = _WRONG_IDENTIFIER;
  2990. }
  2991. else
  2992. {
  2993. dbug(1,dprintf("select_b_req[%d],PLCI=0x%x,Tel=0x%x,NL=0x%x,appl=0x%x,sstate=0x%x",
  2994. msg->length,plci->Id,plci->tel,plci->NL.Id,plci->appl,plci->SuppState));
  2995. dbug(1,dprintf("PlciState=0x%x",plci->State));
  2996. for(i=0;i<7;i++) bp_parms[i].length = 0;
  2997. /* check if no channel is open, no B3 connected only */
  2998. if((plci->State == IDLE) || (plci->State == OUTG_DIS_PENDING) || (plci->State == INC_DIS_PENDING)
  2999. || (plci->SuppState != IDLE) || plci->channels || plci->nl_remove_id)
  3000. {
  3001. Info = _WRONG_STATE;
  3002. }
  3003. /* check message format and fill bp_parms pointer */
  3004. else if(msg->length && api_parse(&msg->info[1], (word)msg->length, "wwwsss", bp_parms))
  3005. {
  3006. Info = _WRONG_MESSAGE_FORMAT;
  3007. }
  3008. else
  3009. {
  3010. if((plci->State==INC_CON_PENDING) || (plci->State==INC_CON_ALERT)) /* send alert tone inband to the network, */
  3011. { /* e.g. Qsig or RBS or Cornet-N or xess PRI */
  3012. if(Id & EXT_CONTROLLER)
  3013. {
  3014. sendf(appl, _SELECT_B_REQ|CONFIRM, Id, Number, "w", 0x2002); /* wrong controller */
  3015. return 0;
  3016. }
  3017. plci->State=INC_CON_CONNECTED_ALERT;
  3018. plci->appl = appl;
  3019. clear_c_ind_mask_bit (plci, (word)(appl->Id-1));
  3020. dump_c_ind_mask (plci);
  3021. for(i=0; i<max_appl; i++) /* disconnect the other appls */
  3022. { /* its quasi a connect */
  3023. if(test_c_ind_mask_bit (plci, i))
  3024. sendf(&application[i], _DISCONNECT_I, Id, 0, "w", _OTHER_APPL_CONNECTED);
  3025. }
  3026. }
  3027. api_save_msg(msg, "s", &plci->saved_msg);
  3028. tel = plci->tel;
  3029. if(Id & EXT_CONTROLLER)
  3030. {
  3031. if(tel) /* external controller in use by this PLCI */
  3032. {
  3033. if(a->AdvSignalAppl && a->AdvSignalAppl!=appl)
  3034. {
  3035. dbug(1,dprintf("Ext_Ctrl in use 1"));
  3036. Info = _WRONG_STATE;
  3037. }
  3038. }
  3039. else /* external controller NOT in use by this PLCI ? */
  3040. {
  3041. if(a->AdvSignalPLCI)
  3042. {
  3043. dbug(1,dprintf("Ext_Ctrl in use 2"));
  3044. Info = _WRONG_STATE;
  3045. }
  3046. else /* activate the codec */
  3047. {
  3048. dbug(1,dprintf("Ext_Ctrl start"));
  3049. if(AdvCodecSupport(a, plci, appl, 0) )
  3050. {
  3051. dbug(1,dprintf("Error in codec procedures"));
  3052. Info = _WRONG_STATE;
  3053. }
  3054. else if(plci->spoofed_msg==SPOOFING_REQUIRED) /* wait until codec is active */
  3055. {
  3056. plci->spoofed_msg = AWAITING_SELECT_B;
  3057. plci->internal_command = BLOCK_PLCI; /* lock other commands */
  3058. plci->command = 0;
  3059. dbug(1,dprintf("continue if codec loaded"));
  3060. return false;
  3061. }
  3062. }
  3063. }
  3064. }
  3065. else /* external controller bit is OFF */
  3066. {
  3067. if(tel) /* external controller in use, need to switch off */
  3068. {
  3069. if(a->AdvSignalAppl==appl)
  3070. {
  3071. CodecIdCheck(a, plci);
  3072. plci->tel = 0;
  3073. plci->adv_nl = 0;
  3074. dbug(1,dprintf("Ext_Ctrl disable"));
  3075. }
  3076. else
  3077. {
  3078. dbug(1,dprintf("Ext_Ctrl not requested"));
  3079. }
  3080. }
  3081. }
  3082. if (!Info)
  3083. {
  3084. if (plci->call_dir & CALL_DIR_OUT)
  3085. plci->call_dir = CALL_DIR_OUT | CALL_DIR_ORIGINATE;
  3086. else if (plci->call_dir & CALL_DIR_IN)
  3087. plci->call_dir = CALL_DIR_IN | CALL_DIR_ANSWER;
  3088. start_internal_command (Id, plci, select_b_command);
  3089. return false;
  3090. }
  3091. }
  3092. }
  3093. sendf(appl, _SELECT_B_REQ|CONFIRM, Id, Number, "w", Info);
  3094. return false;
  3095. }
  3096. static byte manufacturer_req(dword Id, word Number, DIVA_CAPI_ADAPTER *a,
  3097. PLCI *plci, APPL *appl, API_PARSE *parms)
  3098. {
  3099. word command;
  3100. word i;
  3101. word ncci;
  3102. API_PARSE * m;
  3103. API_PARSE m_parms[5];
  3104. word codec;
  3105. byte req;
  3106. byte ch;
  3107. byte dir;
  3108. static byte chi[2] = {0x01,0x00};
  3109. static byte lli[2] = {0x01,0x00};
  3110. static byte codec_cai[2] = {0x01,0x01};
  3111. static byte null_msg = {0};
  3112. static API_PARSE null_parms = { 0, &null_msg };
  3113. PLCI * v_plci;
  3114. word Info=0;
  3115. dbug(1,dprintf("manufacturer_req"));
  3116. for(i=0;i<5;i++) m_parms[i].length = 0;
  3117. if(GET_DWORD(parms[0].info)!=_DI_MANU_ID) {
  3118. Info = _WRONG_MESSAGE_FORMAT;
  3119. }
  3120. command = GET_WORD(parms[1].info);
  3121. m = &parms[2];
  3122. if (!Info)
  3123. {
  3124. switch(command) {
  3125. case _DI_ASSIGN_PLCI:
  3126. if(api_parse(&m->info[1],(word)m->length,"wbbs",m_parms)) {
  3127. Info = _WRONG_MESSAGE_FORMAT;
  3128. break;
  3129. }
  3130. codec = GET_WORD(m_parms[0].info);
  3131. ch = m_parms[1].info[0];
  3132. dir = m_parms[2].info[0];
  3133. if((i=get_plci(a))) {
  3134. plci = &a->plci[i-1];
  3135. plci->appl = appl;
  3136. plci->command = _MANUFACTURER_R;
  3137. plci->m_command = command;
  3138. plci->number = Number;
  3139. plci->State = LOCAL_CONNECT;
  3140. Id = ( ((word)plci->Id<<8)|plci->adapter->Id|0x80);
  3141. dbug(1,dprintf("ManCMD,plci=0x%x",Id));
  3142. if((ch==1 || ch==2) && (dir<=2)) {
  3143. chi[1] = (byte)(0x80|ch);
  3144. lli[1] = 0;
  3145. plci->call_dir = CALL_DIR_OUT | CALL_DIR_ORIGINATE;
  3146. switch(codec)
  3147. {
  3148. case 0:
  3149. Info = add_b1(plci,&m_parms[3],0,0);
  3150. break;
  3151. case 1:
  3152. add_p(plci,CAI,codec_cai);
  3153. break;
  3154. /* manual 'swich on' to the codec support without signalling */
  3155. /* first 'assign plci' with this function, then use */
  3156. case 2:
  3157. if(AdvCodecSupport(a, plci, appl, 0) ) {
  3158. Info = _RESOURCE_ERROR;
  3159. }
  3160. else {
  3161. Info = add_b1(plci,&null_parms,0,B1_FACILITY_LOCAL);
  3162. lli[1] = 0x10; /* local call codec stream */
  3163. }
  3164. break;
  3165. }
  3166. plci->State = LOCAL_CONNECT;
  3167. plci->manufacturer = true;
  3168. plci->command = _MANUFACTURER_R;
  3169. plci->m_command = command;
  3170. plci->number = Number;
  3171. if(!Info)
  3172. {
  3173. add_p(plci,LLI,lli);
  3174. add_p(plci,CHI,chi);
  3175. add_p(plci,UID,"\x06\x43\x61\x70\x69\x32\x30");
  3176. sig_req(plci,ASSIGN,DSIG_ID);
  3177. if(!codec)
  3178. {
  3179. Info = add_b23(plci,&m_parms[3]);
  3180. if(!Info)
  3181. {
  3182. nl_req_ncci(plci,ASSIGN,0);
  3183. send_req(plci);
  3184. }
  3185. }
  3186. if(!Info)
  3187. {
  3188. dbug(1,dprintf("dir=0x%x,spoof=0x%x",dir,plci->spoofed_msg));
  3189. if (plci->spoofed_msg==SPOOFING_REQUIRED)
  3190. {
  3191. api_save_msg (m_parms, "wbbs", &plci->saved_msg);
  3192. plci->spoofed_msg = AWAITING_MANUF_CON;
  3193. plci->internal_command = BLOCK_PLCI; /* reject other req meanwhile */
  3194. plci->command = 0;
  3195. send_req(plci);
  3196. return false;
  3197. }
  3198. if(dir==1) {
  3199. sig_req(plci,CALL_REQ,0);
  3200. }
  3201. else if(!dir){
  3202. sig_req(plci,LISTEN_REQ,0);
  3203. }
  3204. send_req(plci);
  3205. }
  3206. else
  3207. {
  3208. sendf(appl,
  3209. _MANUFACTURER_R|CONFIRM,
  3210. Id,
  3211. Number,
  3212. "dww",_DI_MANU_ID,command,Info);
  3213. return 2;
  3214. }
  3215. }
  3216. }
  3217. }
  3218. else Info = _OUT_OF_PLCI;
  3219. break;
  3220. case _DI_IDI_CTRL:
  3221. if(!plci)
  3222. {
  3223. Info = _WRONG_IDENTIFIER;
  3224. break;
  3225. }
  3226. if(api_parse(&m->info[1],(word)m->length,"bs",m_parms)) {
  3227. Info = _WRONG_MESSAGE_FORMAT;
  3228. break;
  3229. }
  3230. req = m_parms[0].info[0];
  3231. plci->command = _MANUFACTURER_R;
  3232. plci->m_command = command;
  3233. plci->number = Number;
  3234. if(req==CALL_REQ)
  3235. {
  3236. plci->b_channel = getChannel(&m_parms[1]);
  3237. mixer_set_bchannel_id_esc (plci, plci->b_channel);
  3238. if(plci->spoofed_msg==SPOOFING_REQUIRED)
  3239. {
  3240. plci->spoofed_msg = CALL_REQ | AWAITING_MANUF_CON;
  3241. plci->internal_command = BLOCK_PLCI; /* reject other req meanwhile */
  3242. plci->command = 0;
  3243. break;
  3244. }
  3245. }
  3246. else if(req==LAW_REQ)
  3247. {
  3248. plci->cr_enquiry = true;
  3249. }
  3250. add_ss(plci,FTY,&m_parms[1]);
  3251. sig_req(plci,req,0);
  3252. send_req(plci);
  3253. if(req==HANGUP)
  3254. {
  3255. if (plci->NL.Id && !plci->nl_remove_id)
  3256. {
  3257. if (plci->channels)
  3258. {
  3259. for (ncci = 1; ncci < MAX_NCCI+1; ncci++)
  3260. {
  3261. if ((a->ncci_plci[ncci] == plci->Id) && (a->ncci_state[ncci] == CONNECTED))
  3262. {
  3263. a->ncci_state[ncci] = OUTG_DIS_PENDING;
  3264. cleanup_ncci_data (plci, ncci);
  3265. nl_req_ncci(plci,N_DISC,(byte)ncci);
  3266. }
  3267. }
  3268. }
  3269. mixer_remove (plci);
  3270. nl_req_ncci(plci,REMOVE,0);
  3271. send_req(plci);
  3272. }
  3273. }
  3274. break;
  3275. case _DI_SIG_CTRL:
  3276. /* signalling control for loop activation B-channel */
  3277. if(!plci)
  3278. {
  3279. Info = _WRONG_IDENTIFIER;
  3280. break;
  3281. }
  3282. if(m->length){
  3283. plci->command = _MANUFACTURER_R;
  3284. plci->number = Number;
  3285. add_ss(plci,FTY,m);
  3286. sig_req(plci,SIG_CTRL,0);
  3287. send_req(plci);
  3288. }
  3289. else Info = _WRONG_MESSAGE_FORMAT;
  3290. break;
  3291. case _DI_RXT_CTRL:
  3292. /* activation control for receiver/transmitter B-channel */
  3293. if(!plci)
  3294. {
  3295. Info = _WRONG_IDENTIFIER;
  3296. break;
  3297. }
  3298. if(m->length){
  3299. plci->command = _MANUFACTURER_R;
  3300. plci->number = Number;
  3301. add_ss(plci,FTY,m);
  3302. sig_req(plci,DSP_CTRL,0);
  3303. send_req(plci);
  3304. }
  3305. else Info = _WRONG_MESSAGE_FORMAT;
  3306. break;
  3307. case _DI_ADV_CODEC:
  3308. case _DI_DSP_CTRL:
  3309. /* TEL_CTRL commands to support non standard adjustments: */
  3310. /* Ring on/off, Handset micro volume, external micro vol. */
  3311. /* handset+external speaker volume, receiver+transm. gain,*/
  3312. /* handsfree on (hookinfo off), set mixer command */
  3313. if(command == _DI_ADV_CODEC)
  3314. {
  3315. if(!a->AdvCodecPLCI) {
  3316. Info = _WRONG_STATE;
  3317. break;
  3318. }
  3319. v_plci = a->AdvCodecPLCI;
  3320. }
  3321. else
  3322. {
  3323. if (plci
  3324. && (m->length >= 3)
  3325. && (m->info[1] == 0x1c)
  3326. && (m->info[2] >= 1))
  3327. {
  3328. if (m->info[3] == DSP_CTRL_OLD_SET_MIXER_COEFFICIENTS)
  3329. {
  3330. if ((plci->tel != ADV_VOICE) || (plci != a->AdvSignalPLCI))
  3331. {
  3332. Info = _WRONG_STATE;
  3333. break;
  3334. }
  3335. a->adv_voice_coef_length = m->info[2] - 1;
  3336. if (a->adv_voice_coef_length > m->length - 3)
  3337. a->adv_voice_coef_length = (byte)(m->length - 3);
  3338. if (a->adv_voice_coef_length > ADV_VOICE_COEF_BUFFER_SIZE)
  3339. a->adv_voice_coef_length = ADV_VOICE_COEF_BUFFER_SIZE;
  3340. for (i = 0; i < a->adv_voice_coef_length; i++)
  3341. a->adv_voice_coef_buffer[i] = m->info[4 + i];
  3342. if (plci->B1_facilities & B1_FACILITY_VOICE)
  3343. adv_voice_write_coefs (plci, ADV_VOICE_WRITE_UPDATE);
  3344. break;
  3345. }
  3346. else if (m->info[3] == DSP_CTRL_SET_DTMF_PARAMETERS)
  3347. {
  3348. if (!(a->manufacturer_features & MANUFACTURER_FEATURE_DTMF_PARAMETERS))
  3349. {
  3350. Info = _FACILITY_NOT_SUPPORTED;
  3351. break;
  3352. }
  3353. plci->dtmf_parameter_length = m->info[2] - 1;
  3354. if (plci->dtmf_parameter_length > m->length - 3)
  3355. plci->dtmf_parameter_length = (byte)(m->length - 3);
  3356. if (plci->dtmf_parameter_length > DTMF_PARAMETER_BUFFER_SIZE)
  3357. plci->dtmf_parameter_length = DTMF_PARAMETER_BUFFER_SIZE;
  3358. for (i = 0; i < plci->dtmf_parameter_length; i++)
  3359. plci->dtmf_parameter_buffer[i] = m->info[4+i];
  3360. if (plci->B1_facilities & B1_FACILITY_DTMFR)
  3361. dtmf_parameter_write (plci);
  3362. break;
  3363. }
  3364. }
  3365. v_plci = plci;
  3366. }
  3367. if(!v_plci)
  3368. {
  3369. Info = _WRONG_IDENTIFIER;
  3370. break;
  3371. }
  3372. if(m->length){
  3373. add_ss(v_plci,FTY,m);
  3374. sig_req(v_plci,TEL_CTRL,0);
  3375. send_req(v_plci);
  3376. }
  3377. else Info = _WRONG_MESSAGE_FORMAT;
  3378. break;
  3379. case _DI_OPTIONS_REQUEST:
  3380. if(api_parse(&m->info[1],(word)m->length,"d",m_parms)) {
  3381. Info = _WRONG_MESSAGE_FORMAT;
  3382. break;
  3383. }
  3384. if (GET_DWORD (m_parms[0].info) & ~a->man_profile.private_options)
  3385. {
  3386. Info = _FACILITY_NOT_SUPPORTED;
  3387. break;
  3388. }
  3389. a->requested_options_table[appl->Id-1] = GET_DWORD (m_parms[0].info);
  3390. break;
  3391. default:
  3392. Info = _WRONG_MESSAGE_FORMAT;
  3393. break;
  3394. }
  3395. }
  3396. sendf(appl,
  3397. _MANUFACTURER_R|CONFIRM,
  3398. Id,
  3399. Number,
  3400. "dww",_DI_MANU_ID,command,Info);
  3401. return false;
  3402. }
  3403. static byte manufacturer_res(dword Id, word Number, DIVA_CAPI_ADAPTER *a,
  3404. PLCI *plci, APPL *appl, API_PARSE *msg)
  3405. {
  3406. word indication;
  3407. API_PARSE m_parms[3];
  3408. API_PARSE *ncpi;
  3409. API_PARSE fax_parms[9];
  3410. word i;
  3411. byte len;
  3412. dbug(1,dprintf("manufacturer_res"));
  3413. if ((msg[0].length == 0)
  3414. || (msg[1].length == 0)
  3415. || (GET_DWORD(msg[0].info)!=_DI_MANU_ID))
  3416. {
  3417. return false;
  3418. }
  3419. indication = GET_WORD(msg[1].info);
  3420. switch (indication)
  3421. {
  3422. case _DI_NEGOTIATE_B3:
  3423. if(!plci)
  3424. break;
  3425. if (((plci->B3_prot != 4) && (plci->B3_prot != 5))
  3426. || !(plci->ncpi_state & NCPI_NEGOTIATE_B3_SENT))
  3427. {
  3428. dbug(1,dprintf("wrong state for NEGOTIATE_B3 parameters"));
  3429. break;
  3430. }
  3431. if (api_parse (&msg[2].info[1], msg[2].length, "ws", m_parms))
  3432. {
  3433. dbug(1,dprintf("wrong format in NEGOTIATE_B3 parameters"));
  3434. break;
  3435. }
  3436. ncpi = &m_parms[1];
  3437. len = ((byte)(((T30_INFO *) 0)->station_id + 20));
  3438. if (plci->fax_connect_info_length < len)
  3439. {
  3440. ((T30_INFO *)(plci->fax_connect_info_buffer))->station_id_len = 0;
  3441. ((T30_INFO *)(plci->fax_connect_info_buffer))->head_line_len = 0;
  3442. }
  3443. if (api_parse (&ncpi->info[1], ncpi->length, "wwwwssss", fax_parms))
  3444. {
  3445. dbug(1,dprintf("non-standard facilities info missing or wrong format"));
  3446. }
  3447. else
  3448. {
  3449. if (plci->fax_connect_info_length <= len)
  3450. plci->fax_connect_info_buffer[len] = 0;
  3451. len += 1 + plci->fax_connect_info_buffer[len];
  3452. if (plci->fax_connect_info_length <= len)
  3453. plci->fax_connect_info_buffer[len] = 0;
  3454. len += 1 + plci->fax_connect_info_buffer[len];
  3455. if ((fax_parms[7].length >= 3) && (fax_parms[7].info[1] >= 2))
  3456. plci->nsf_control_bits = GET_WORD(&fax_parms[7].info[2]);
  3457. plci->fax_connect_info_buffer[len++] = (byte)(fax_parms[7].length);
  3458. for (i = 0; i < fax_parms[7].length; i++)
  3459. plci->fax_connect_info_buffer[len++] = fax_parms[7].info[1+i];
  3460. }
  3461. plci->fax_connect_info_length = len;
  3462. plci->fax_edata_ack_length = plci->fax_connect_info_length;
  3463. start_internal_command (Id, plci, fax_edata_ack_command);
  3464. break;
  3465. }
  3466. return false;
  3467. }
  3468. /*------------------------------------------------------------------*/
  3469. /* IDI callback function */
  3470. /*------------------------------------------------------------------*/
  3471. void callback(ENTITY * e)
  3472. {
  3473. DIVA_CAPI_ADAPTER * a;
  3474. APPL * appl;
  3475. PLCI * plci;
  3476. CAPI_MSG *m;
  3477. word i, j;
  3478. byte rc;
  3479. byte ch;
  3480. byte req;
  3481. byte global_req;
  3482. int no_cancel_rc;
  3483. dbug(1,dprintf("%x:CB(%x:Req=%x,Rc=%x,Ind=%x)",
  3484. (e->user[0]+1)&0x7fff,e->Id,e->Req,e->Rc,e->Ind));
  3485. a = &(adapter[(byte)e->user[0]]);
  3486. plci = &(a->plci[e->user[1]]);
  3487. no_cancel_rc = DIVA_CAPI_SUPPORTS_NO_CANCEL(a);
  3488. /*
  3489. If new protocol code and new XDI is used then CAPI should work
  3490. fully in accordance with IDI cpec an look on callback field instead
  3491. of Rc field for return codes.
  3492. */
  3493. if (((e->complete == 0xff) && no_cancel_rc) ||
  3494. (e->Rc && !no_cancel_rc)) {
  3495. rc = e->Rc;
  3496. ch = e->RcCh;
  3497. req = e->Req;
  3498. e->Rc = 0;
  3499. if (e->user[0] & 0x8000)
  3500. {
  3501. /*
  3502. If REMOVE request was sent then we have to wait until
  3503. return code with Id set to zero arrives.
  3504. All other return codes should be ignored.
  3505. */
  3506. if (req == REMOVE)
  3507. {
  3508. if (e->Id)
  3509. {
  3510. dbug(1,dprintf("cancel RC in REMOVE state"));
  3511. return;
  3512. }
  3513. channel_flow_control_remove (plci);
  3514. for (i = 0; i < 256; i++)
  3515. {
  3516. if (a->FlowControlIdTable[i] == plci->nl_remove_id)
  3517. a->FlowControlIdTable[i] = 0;
  3518. }
  3519. plci->nl_remove_id = 0;
  3520. if (plci->rx_dma_descriptor > 0) {
  3521. diva_free_dma_descriptor (plci, plci->rx_dma_descriptor - 1);
  3522. plci->rx_dma_descriptor = 0;
  3523. }
  3524. }
  3525. if (rc == OK_FC)
  3526. {
  3527. a->FlowControlIdTable[ch] = e->Id;
  3528. a->FlowControlSkipTable[ch] = 0;
  3529. a->ch_flow_control[ch] |= N_OK_FC_PENDING;
  3530. a->ch_flow_plci[ch] = plci->Id;
  3531. plci->nl_req = 0;
  3532. }
  3533. else
  3534. {
  3535. /*
  3536. Cancel return codes self, if feature was requested
  3537. */
  3538. if (no_cancel_rc && (a->FlowControlIdTable[ch] == e->Id) && e->Id) {
  3539. a->FlowControlIdTable[ch] = 0;
  3540. if ((rc == OK) && a->FlowControlSkipTable[ch]) {
  3541. dbug(3,dprintf ("XDI CAPI: RC cancelled Id:0x02, Ch:%02x", e->Id, ch));
  3542. return;
  3543. }
  3544. }
  3545. if (a->ch_flow_control[ch] & N_OK_FC_PENDING)
  3546. {
  3547. a->ch_flow_control[ch] &= ~N_OK_FC_PENDING;
  3548. if (ch == e->ReqCh)
  3549. plci->nl_req = 0;
  3550. }
  3551. else
  3552. plci->nl_req = 0;
  3553. }
  3554. if (plci->nl_req)
  3555. control_rc (plci, 0, rc, ch, 0, true);
  3556. else
  3557. {
  3558. if (req == N_XON)
  3559. {
  3560. channel_x_on (plci, ch);
  3561. if (plci->internal_command)
  3562. control_rc (plci, req, rc, ch, 0, true);
  3563. }
  3564. else
  3565. {
  3566. if (plci->nl_global_req)
  3567. {
  3568. global_req = plci->nl_global_req;
  3569. plci->nl_global_req = 0;
  3570. if (rc != ASSIGN_OK) {
  3571. e->Id = 0;
  3572. if (plci->rx_dma_descriptor > 0) {
  3573. diva_free_dma_descriptor (plci, plci->rx_dma_descriptor - 1);
  3574. plci->rx_dma_descriptor = 0;
  3575. }
  3576. }
  3577. channel_xmit_xon (plci);
  3578. control_rc (plci, 0, rc, ch, global_req, true);
  3579. }
  3580. else if (plci->data_sent)
  3581. {
  3582. channel_xmit_xon (plci);
  3583. plci->data_sent = false;
  3584. plci->NL.XNum = 1;
  3585. data_rc (plci, ch);
  3586. if (plci->internal_command)
  3587. control_rc (plci, req, rc, ch, 0, true);
  3588. }
  3589. else
  3590. {
  3591. channel_xmit_xon (plci);
  3592. control_rc (plci, req, rc, ch, 0, true);
  3593. }
  3594. }
  3595. }
  3596. }
  3597. else
  3598. {
  3599. /*
  3600. If REMOVE request was sent then we have to wait until
  3601. return code with Id set to zero arrives.
  3602. All other return codes should be ignored.
  3603. */
  3604. if (req == REMOVE)
  3605. {
  3606. if (e->Id)
  3607. {
  3608. dbug(1,dprintf("cancel RC in REMOVE state"));
  3609. return;
  3610. }
  3611. plci->sig_remove_id = 0;
  3612. }
  3613. plci->sig_req = 0;
  3614. if (plci->sig_global_req)
  3615. {
  3616. global_req = plci->sig_global_req;
  3617. plci->sig_global_req = 0;
  3618. if (rc != ASSIGN_OK)
  3619. e->Id = 0;
  3620. channel_xmit_xon (plci);
  3621. control_rc (plci, 0, rc, ch, global_req, false);
  3622. }
  3623. else
  3624. {
  3625. channel_xmit_xon (plci);
  3626. control_rc (plci, req, rc, ch, 0, false);
  3627. }
  3628. }
  3629. /*
  3630. Again: in accordance with IDI spec Rc and Ind can't be delivered in the
  3631. same callback. Also if new XDI and protocol code used then jump
  3632. direct to finish.
  3633. */
  3634. if (no_cancel_rc) {
  3635. channel_xmit_xon(plci);
  3636. goto capi_callback_suffix;
  3637. }
  3638. }
  3639. channel_xmit_xon(plci);
  3640. if (e->Ind) {
  3641. if (e->user[0] &0x8000) {
  3642. byte Ind = e->Ind & 0x0f;
  3643. byte Ch = e->IndCh;
  3644. if (((Ind==N_DISC) || (Ind==N_DISC_ACK)) &&
  3645. (a->ch_flow_plci[Ch] == plci->Id)) {
  3646. if (a->ch_flow_control[Ch] & N_RX_FLOW_CONTROL_MASK) {
  3647. dbug(3,dprintf ("XDI CAPI: I: pending N-XON Ch:%02x", Ch));
  3648. }
  3649. a->ch_flow_control[Ch] &= ~N_RX_FLOW_CONTROL_MASK;
  3650. }
  3651. nl_ind(plci);
  3652. if ((e->RNR != 1) &&
  3653. (a->ch_flow_plci[Ch] == plci->Id) &&
  3654. (a->ch_flow_control[Ch] & N_RX_FLOW_CONTROL_MASK)) {
  3655. a->ch_flow_control[Ch] &= ~N_RX_FLOW_CONTROL_MASK;
  3656. dbug(3,dprintf ("XDI CAPI: I: remove faked N-XON Ch:%02x", Ch));
  3657. }
  3658. } else {
  3659. sig_ind(plci);
  3660. }
  3661. e->Ind = 0;
  3662. }
  3663. capi_callback_suffix:
  3664. while (!plci->req_in
  3665. && !plci->internal_command
  3666. && (plci->msg_in_write_pos != plci->msg_in_read_pos))
  3667. {
  3668. j = (plci->msg_in_read_pos == plci->msg_in_wrap_pos) ? 0 : plci->msg_in_read_pos;
  3669. i = (((CAPI_MSG *)(&((byte *)(plci->msg_in_queue))[j]))->header.length + 3) & 0xfffc;
  3670. m = (CAPI_MSG *)(&((byte *)(plci->msg_in_queue))[j]);
  3671. appl = *((APPL * *)(&((byte *)(plci->msg_in_queue))[j+i]));
  3672. dbug(1,dprintf("dequeue msg(0x%04x) - write=%d read=%d wrap=%d",
  3673. m->header.command, plci->msg_in_write_pos, plci->msg_in_read_pos, plci->msg_in_wrap_pos));
  3674. if (plci->msg_in_read_pos == plci->msg_in_wrap_pos)
  3675. {
  3676. plci->msg_in_wrap_pos = MSG_IN_QUEUE_SIZE;
  3677. plci->msg_in_read_pos = i + MSG_IN_OVERHEAD;
  3678. }
  3679. else
  3680. {
  3681. plci->msg_in_read_pos = j + i + MSG_IN_OVERHEAD;
  3682. }
  3683. if (plci->msg_in_read_pos == plci->msg_in_write_pos)
  3684. {
  3685. plci->msg_in_write_pos = MSG_IN_QUEUE_SIZE;
  3686. plci->msg_in_read_pos = MSG_IN_QUEUE_SIZE;
  3687. }
  3688. else if (plci->msg_in_read_pos == plci->msg_in_wrap_pos)
  3689. {
  3690. plci->msg_in_read_pos = MSG_IN_QUEUE_SIZE;
  3691. plci->msg_in_wrap_pos = MSG_IN_QUEUE_SIZE;
  3692. }
  3693. i = api_put (appl, m);
  3694. if (i != 0)
  3695. {
  3696. if (m->header.command == _DATA_B3_R)
  3697. TransmitBufferFree (appl, (byte *)(long)(m->info.data_b3_req.Data));
  3698. dbug(1,dprintf("Error 0x%04x from msg(0x%04x)", i, m->header.command));
  3699. break;
  3700. }
  3701. if (plci->li_notify_update)
  3702. {
  3703. plci->li_notify_update = false;
  3704. mixer_notify_update (plci, false);
  3705. }
  3706. }
  3707. send_data(plci);
  3708. send_req(plci);
  3709. }
  3710. static void control_rc(PLCI *plci, byte req, byte rc, byte ch, byte global_req,
  3711. byte nl_rc)
  3712. {
  3713. dword Id;
  3714. dword rId;
  3715. word Number;
  3716. word Info=0;
  3717. word i;
  3718. word ncci;
  3719. DIVA_CAPI_ADAPTER * a;
  3720. APPL * appl;
  3721. PLCI * rplci;
  3722. byte SSparms[] = "\x05\x00\x00\x02\x00\x00";
  3723. byte SSstruct[] = "\x09\x00\x00\x06\x00\x00\x00\x00\x00\x00";
  3724. if (!plci) {
  3725. dbug(0,dprintf("A: control_rc, no plci %02x:%02x:%02x:%02x:%02x", req, rc, ch, global_req, nl_rc));
  3726. return;
  3727. }
  3728. dbug(1,dprintf("req0_in/out=%d/%d",plci->req_in,plci->req_out));
  3729. if(plci->req_in!=plci->req_out)
  3730. {
  3731. if (nl_rc || (global_req != ASSIGN) || (rc == ASSIGN_OK))
  3732. {
  3733. dbug(1,dprintf("req_1return"));
  3734. return;
  3735. }
  3736. /* cancel outstanding request on the PLCI after SIG ASSIGN failure */
  3737. }
  3738. plci->req_in = plci->req_in_start = plci->req_out = 0;
  3739. dbug(1,dprintf("control_rc"));
  3740. appl = plci->appl;
  3741. a = plci->adapter;
  3742. ncci = a->ch_ncci[ch];
  3743. if(appl)
  3744. {
  3745. Id = (((dword)(ncci ? ncci : ch)) << 16) | ((word)plci->Id << 8) | a->Id;
  3746. if(plci->tel && plci->SuppState!=CALL_HELD) Id|=EXT_CONTROLLER;
  3747. Number = plci->number;
  3748. dbug(1,dprintf("Contr_RC-Id=%08lx,plci=%x,tel=%x, entity=0x%x, command=0x%x, int_command=0x%x",Id,plci->Id,plci->tel,plci->Sig.Id,plci->command,plci->internal_command));
  3749. dbug(1,dprintf("channels=0x%x",plci->channels));
  3750. if (plci_remove_check(plci))
  3751. return;
  3752. if(req==REMOVE && rc==ASSIGN_OK)
  3753. {
  3754. sig_req(plci,HANGUP,0);
  3755. sig_req(plci,REMOVE,0);
  3756. send_req(plci);
  3757. }
  3758. if(plci->command)
  3759. {
  3760. switch(plci->command)
  3761. {
  3762. case C_HOLD_REQ:
  3763. dbug(1,dprintf("HoldRC=0x%x",rc));
  3764. SSparms[1] = (byte)S_HOLD;
  3765. if(rc!=OK)
  3766. {
  3767. plci->SuppState = IDLE;
  3768. Info = 0x2001;
  3769. }
  3770. sendf(appl,_FACILITY_R|CONFIRM,Id,Number,"wws",Info,3,SSparms);
  3771. break;
  3772. case C_RETRIEVE_REQ:
  3773. dbug(1,dprintf("RetrieveRC=0x%x",rc));
  3774. SSparms[1] = (byte)S_RETRIEVE;
  3775. if(rc!=OK)
  3776. {
  3777. plci->SuppState = CALL_HELD;
  3778. Info = 0x2001;
  3779. }
  3780. sendf(appl,_FACILITY_R|CONFIRM,Id,Number,"wws",Info,3,SSparms);
  3781. break;
  3782. case _INFO_R:
  3783. dbug(1,dprintf("InfoRC=0x%x",rc));
  3784. if(rc!=OK) Info=_WRONG_STATE;
  3785. sendf(appl,_INFO_R|CONFIRM,Id,Number,"w",Info);
  3786. break;
  3787. case _CONNECT_R:
  3788. dbug(1,dprintf("Connect_R=0x%x/0x%x/0x%x/0x%x",req,rc,global_req,nl_rc));
  3789. if (plci->State == INC_DIS_PENDING)
  3790. break;
  3791. if(plci->Sig.Id!=0xff)
  3792. {
  3793. if (((global_req == ASSIGN) && (rc != ASSIGN_OK))
  3794. || (!nl_rc && (req == CALL_REQ) && (rc != OK)))
  3795. {
  3796. dbug(1,dprintf("No more IDs/Call_Req failed"));
  3797. sendf(appl,_CONNECT_R|CONFIRM,Id&0xffL,Number,"w",_OUT_OF_PLCI);
  3798. plci_remove(plci);
  3799. plci->State = IDLE;
  3800. break;
  3801. }
  3802. if(plci->State!=LOCAL_CONNECT)plci->State = OUTG_CON_PENDING;
  3803. sendf(appl,_CONNECT_R|CONFIRM,Id,Number,"w",0);
  3804. }
  3805. else /* D-ch activation */
  3806. {
  3807. if (rc != ASSIGN_OK)
  3808. {
  3809. dbug(1,dprintf("No more IDs/X.25 Call_Req failed"));
  3810. sendf(appl,_CONNECT_R|CONFIRM,Id&0xffL,Number,"w",_OUT_OF_PLCI);
  3811. plci_remove(plci);
  3812. plci->State = IDLE;
  3813. break;
  3814. }
  3815. sendf(appl,_CONNECT_R|CONFIRM,Id,Number,"w",0);
  3816. sendf(plci->appl,_CONNECT_ACTIVE_I,Id,0,"sss","","","");
  3817. plci->State = INC_ACT_PENDING;
  3818. }
  3819. break;
  3820. case _CONNECT_I|RESPONSE:
  3821. if (plci->State != INC_DIS_PENDING)
  3822. plci->State = INC_CON_ACCEPT;
  3823. break;
  3824. case _DISCONNECT_R:
  3825. if (plci->State == INC_DIS_PENDING)
  3826. break;
  3827. if(plci->Sig.Id!=0xff)
  3828. {
  3829. plci->State = OUTG_DIS_PENDING;
  3830. sendf(appl,_DISCONNECT_R|CONFIRM,Id,Number,"w",0);
  3831. }
  3832. break;
  3833. case SUSPEND_REQ:
  3834. break;
  3835. case RESUME_REQ:
  3836. break;
  3837. case _CONNECT_B3_R:
  3838. if(rc!=OK)
  3839. {
  3840. sendf(appl,_CONNECT_B3_R|CONFIRM,Id,Number,"w",_WRONG_IDENTIFIER);
  3841. break;
  3842. }
  3843. ncci = get_ncci (plci, ch, 0);
  3844. Id = (Id & 0xffff) | (((dword) ncci) << 16);
  3845. plci->channels++;
  3846. if(req==N_RESET)
  3847. {
  3848. a->ncci_state[ncci] = INC_ACT_PENDING;
  3849. sendf(appl,_CONNECT_B3_R|CONFIRM,Id,Number,"w",0);
  3850. sendf(appl,_CONNECT_B3_ACTIVE_I,Id,0,"s","");
  3851. }
  3852. else
  3853. {
  3854. a->ncci_state[ncci] = OUTG_CON_PENDING;
  3855. sendf(appl,_CONNECT_B3_R|CONFIRM,Id,Number,"w",0);
  3856. }
  3857. break;
  3858. case _CONNECT_B3_I|RESPONSE:
  3859. break;
  3860. case _RESET_B3_R:
  3861. /* sendf(appl,_RESET_B3_R|CONFIRM,Id,Number,"w",0);*/
  3862. break;
  3863. case _DISCONNECT_B3_R:
  3864. sendf(appl,_DISCONNECT_B3_R|CONFIRM,Id,Number,"w",0);
  3865. break;
  3866. case _MANUFACTURER_R:
  3867. break;
  3868. case PERM_LIST_REQ:
  3869. if(rc!=OK)
  3870. {
  3871. Info = _WRONG_IDENTIFIER;
  3872. sendf(plci->appl,_CONNECT_R|CONFIRM,Id,Number,"w",Info);
  3873. plci_remove(plci);
  3874. }
  3875. else
  3876. sendf(plci->appl,_CONNECT_R|CONFIRM,Id,Number,"w",Info);
  3877. break;
  3878. default:
  3879. break;
  3880. }
  3881. plci->command = 0;
  3882. }
  3883. else if (plci->internal_command)
  3884. {
  3885. switch(plci->internal_command)
  3886. {
  3887. case BLOCK_PLCI:
  3888. return;
  3889. case GET_MWI_STATE:
  3890. if(rc==OK) /* command supported, wait for indication */
  3891. {
  3892. return;
  3893. }
  3894. plci_remove(plci);
  3895. break;
  3896. /* Get Supported Services */
  3897. case GETSERV_REQ_PEND:
  3898. if(rc==OK) /* command supported, wait for indication */
  3899. {
  3900. break;
  3901. }
  3902. PUT_DWORD(&SSstruct[6], MASK_TERMINAL_PORTABILITY);
  3903. sendf(appl, _FACILITY_R|CONFIRM, Id, Number, "wws",0,3,SSstruct);
  3904. plci_remove(plci);
  3905. break;
  3906. case INTERR_DIVERSION_REQ_PEND: /* Interrogate Parameters */
  3907. case INTERR_NUMBERS_REQ_PEND:
  3908. case CF_START_PEND: /* Call Forwarding Start pending */
  3909. case CF_STOP_PEND: /* Call Forwarding Stop pending */
  3910. case CCBS_REQUEST_REQ_PEND:
  3911. case CCBS_DEACTIVATE_REQ_PEND:
  3912. case CCBS_INTERROGATE_REQ_PEND:
  3913. switch(plci->internal_command)
  3914. {
  3915. case INTERR_DIVERSION_REQ_PEND:
  3916. SSparms[1] = S_INTERROGATE_DIVERSION;
  3917. break;
  3918. case INTERR_NUMBERS_REQ_PEND:
  3919. SSparms[1] = S_INTERROGATE_NUMBERS;
  3920. break;
  3921. case CF_START_PEND:
  3922. SSparms[1] = S_CALL_FORWARDING_START;
  3923. break;
  3924. case CF_STOP_PEND:
  3925. SSparms[1] = S_CALL_FORWARDING_STOP;
  3926. break;
  3927. case CCBS_REQUEST_REQ_PEND:
  3928. SSparms[1] = S_CCBS_REQUEST;
  3929. break;
  3930. case CCBS_DEACTIVATE_REQ_PEND:
  3931. SSparms[1] = S_CCBS_DEACTIVATE;
  3932. break;
  3933. case CCBS_INTERROGATE_REQ_PEND:
  3934. SSparms[1] = S_CCBS_INTERROGATE;
  3935. break;
  3936. }
  3937. if(global_req==ASSIGN)
  3938. {
  3939. dbug(1,dprintf("AssignDiversion_RC=0x%x/0x%x",req,rc));
  3940. return;
  3941. }
  3942. if(!plci->appl) break;
  3943. if(rc==ISDN_GUARD_REJ)
  3944. {
  3945. Info = _CAPI_GUARD_ERROR;
  3946. }
  3947. else if(rc!=OK)
  3948. {
  3949. Info = _SUPPLEMENTARY_SERVICE_NOT_SUPPORTED;
  3950. }
  3951. sendf(plci->appl,_FACILITY_R|CONFIRM,Id&0x7,
  3952. plci->number,"wws",Info,(word)3,SSparms);
  3953. if(Info) plci_remove(plci);
  3954. break;
  3955. /* 3pty conference pending */
  3956. case PTY_REQ_PEND:
  3957. if(!plci->relatedPTYPLCI) break;
  3958. rplci = plci->relatedPTYPLCI;
  3959. SSparms[1] = plci->ptyState;
  3960. rId = ((word)rplci->Id<<8)|rplci->adapter->Id;
  3961. if(rplci->tel) rId|=EXT_CONTROLLER;
  3962. if(rc!=OK)
  3963. {
  3964. Info = 0x300E; /* not supported */
  3965. plci->relatedPTYPLCI = NULL;
  3966. plci->ptyState = 0;
  3967. }
  3968. sendf(rplci->appl,
  3969. _FACILITY_R|CONFIRM,
  3970. rId,
  3971. plci->number,
  3972. "wws",Info,(word)3,SSparms);
  3973. break;
  3974. /* Explicit Call Transfer pending */
  3975. case ECT_REQ_PEND:
  3976. dbug(1,dprintf("ECT_RC=0x%x/0x%x",req,rc));
  3977. if(!plci->relatedPTYPLCI) break;
  3978. rplci = plci->relatedPTYPLCI;
  3979. SSparms[1] = S_ECT;
  3980. rId = ((word)rplci->Id<<8)|rplci->adapter->Id;
  3981. if(rplci->tel) rId|=EXT_CONTROLLER;
  3982. if(rc!=OK)
  3983. {
  3984. Info = 0x300E; /* not supported */
  3985. plci->relatedPTYPLCI = NULL;
  3986. plci->ptyState = 0;
  3987. }
  3988. sendf(rplci->appl,
  3989. _FACILITY_R|CONFIRM,
  3990. rId,
  3991. plci->number,
  3992. "wws",Info,(word)3,SSparms);
  3993. break;
  3994. case _MANUFACTURER_R:
  3995. dbug(1,dprintf("_Manufacturer_R=0x%x/0x%x",req,rc));
  3996. if ((global_req == ASSIGN) && (rc != ASSIGN_OK))
  3997. {
  3998. dbug(1,dprintf("No more IDs"));
  3999. sendf(appl,_MANUFACTURER_R|CONFIRM,Id,Number,"dww",_DI_MANU_ID,_MANUFACTURER_R,_OUT_OF_PLCI);
  4000. plci_remove(plci); /* after codec init, internal codec commands pending */
  4001. }
  4002. break;
  4003. case _CONNECT_R:
  4004. dbug(1,dprintf("_Connect_R=0x%x/0x%x",req,rc));
  4005. if ((global_req == ASSIGN) && (rc != ASSIGN_OK))
  4006. {
  4007. dbug(1,dprintf("No more IDs"));
  4008. sendf(appl,_CONNECT_R|CONFIRM,Id&0xffL,Number,"w",_OUT_OF_PLCI);
  4009. plci_remove(plci); /* after codec init, internal codec commands pending */
  4010. }
  4011. break;
  4012. case PERM_COD_HOOK: /* finished with Hook_Ind */
  4013. return;
  4014. case PERM_COD_CALL:
  4015. dbug(1,dprintf("***Codec Connect_Pending A, Rc = 0x%x",rc));
  4016. plci->internal_command = PERM_COD_CONN_PEND;
  4017. return;
  4018. case PERM_COD_ASSIGN:
  4019. dbug(1,dprintf("***Codec Assign A, Rc = 0x%x",rc));
  4020. if(rc!=ASSIGN_OK) break;
  4021. sig_req(plci,CALL_REQ,0);
  4022. send_req(plci);
  4023. plci->internal_command = PERM_COD_CALL;
  4024. return;
  4025. /* Null Call Reference Request pending */
  4026. case C_NCR_FAC_REQ:
  4027. dbug(1,dprintf("NCR_FAC=0x%x/0x%x",req,rc));
  4028. if(global_req==ASSIGN)
  4029. {
  4030. if(rc==ASSIGN_OK)
  4031. {
  4032. return;
  4033. }
  4034. else
  4035. {
  4036. sendf(appl,_INFO_R|CONFIRM,Id&0xf,Number,"w",_WRONG_STATE);
  4037. appl->NullCREnable = false;
  4038. plci_remove(plci);
  4039. }
  4040. }
  4041. else if(req==NCR_FACILITY)
  4042. {
  4043. if(rc==OK)
  4044. {
  4045. sendf(appl,_INFO_R|CONFIRM,Id&0xf,Number,"w",0);
  4046. }
  4047. else
  4048. {
  4049. sendf(appl,_INFO_R|CONFIRM,Id&0xf,Number,"w",_WRONG_STATE);
  4050. appl->NullCREnable = false;
  4051. }
  4052. plci_remove(plci);
  4053. }
  4054. break;
  4055. case HOOK_ON_REQ:
  4056. if(plci->channels)
  4057. {
  4058. if(a->ncci_state[ncci]==CONNECTED)
  4059. {
  4060. a->ncci_state[ncci] = OUTG_DIS_PENDING;
  4061. cleanup_ncci_data (plci, ncci);
  4062. nl_req_ncci(plci,N_DISC,(byte)ncci);
  4063. }
  4064. break;
  4065. }
  4066. break;
  4067. case HOOK_OFF_REQ:
  4068. if (plci->State == INC_DIS_PENDING)
  4069. break;
  4070. sig_req(plci,CALL_REQ,0);
  4071. send_req(plci);
  4072. plci->State=OUTG_CON_PENDING;
  4073. break;
  4074. case MWI_ACTIVATE_REQ_PEND:
  4075. case MWI_DEACTIVATE_REQ_PEND:
  4076. if(global_req == ASSIGN && rc==ASSIGN_OK)
  4077. {
  4078. dbug(1,dprintf("MWI_REQ assigned"));
  4079. return;
  4080. }
  4081. else if(rc!=OK)
  4082. {
  4083. if(rc==WRONG_IE)
  4084. {
  4085. Info = 0x2007; /* Illegal message parameter coding */
  4086. dbug(1,dprintf("MWI_REQ invalid parameter"));
  4087. }
  4088. else
  4089. {
  4090. Info = 0x300B; /* not supported */
  4091. dbug(1,dprintf("MWI_REQ not supported"));
  4092. }
  4093. /* 0x3010: Request not allowed in this state */
  4094. PUT_WORD(&SSparms[4],0x300E); /* SS not supported */
  4095. }
  4096. if(plci->internal_command==MWI_ACTIVATE_REQ_PEND)
  4097. {
  4098. PUT_WORD(&SSparms[1],S_MWI_ACTIVATE);
  4099. }
  4100. else PUT_WORD(&SSparms[1],S_MWI_DEACTIVATE);
  4101. if(plci->cr_enquiry)
  4102. {
  4103. sendf(plci->appl,
  4104. _FACILITY_R|CONFIRM,
  4105. Id&0xf,
  4106. plci->number,
  4107. "wws",Info,(word)3,SSparms);
  4108. if(rc!=OK) plci_remove(plci);
  4109. }
  4110. else
  4111. {
  4112. sendf(plci->appl,
  4113. _FACILITY_R|CONFIRM,
  4114. Id,
  4115. plci->number,
  4116. "wws",Info,(word)3,SSparms);
  4117. }
  4118. break;
  4119. case CONF_BEGIN_REQ_PEND:
  4120. case CONF_ADD_REQ_PEND:
  4121. case CONF_SPLIT_REQ_PEND:
  4122. case CONF_DROP_REQ_PEND:
  4123. case CONF_ISOLATE_REQ_PEND:
  4124. case CONF_REATTACH_REQ_PEND:
  4125. dbug(1,dprintf("CONF_RC=0x%x/0x%x",req,rc));
  4126. if((plci->internal_command==CONF_ADD_REQ_PEND)&&(!plci->relatedPTYPLCI)) break;
  4127. rplci = plci;
  4128. rId = Id;
  4129. switch(plci->internal_command)
  4130. {
  4131. case CONF_BEGIN_REQ_PEND:
  4132. SSparms[1] = S_CONF_BEGIN;
  4133. break;
  4134. case CONF_ADD_REQ_PEND:
  4135. SSparms[1] = S_CONF_ADD;
  4136. rplci = plci->relatedPTYPLCI;
  4137. rId = ((word)rplci->Id<<8)|rplci->adapter->Id;
  4138. break;
  4139. case CONF_SPLIT_REQ_PEND:
  4140. SSparms[1] = S_CONF_SPLIT;
  4141. break;
  4142. case CONF_DROP_REQ_PEND:
  4143. SSparms[1] = S_CONF_DROP;
  4144. break;
  4145. case CONF_ISOLATE_REQ_PEND:
  4146. SSparms[1] = S_CONF_ISOLATE;
  4147. break;
  4148. case CONF_REATTACH_REQ_PEND:
  4149. SSparms[1] = S_CONF_REATTACH;
  4150. break;
  4151. }
  4152. if(rc!=OK)
  4153. {
  4154. Info = 0x300E; /* not supported */
  4155. plci->relatedPTYPLCI = NULL;
  4156. plci->ptyState = 0;
  4157. }
  4158. sendf(rplci->appl,
  4159. _FACILITY_R|CONFIRM,
  4160. rId,
  4161. plci->number,
  4162. "wws",Info,(word)3,SSparms);
  4163. break;
  4164. case VSWITCH_REQ_PEND:
  4165. if(rc!=OK)
  4166. {
  4167. if(plci->relatedPTYPLCI)
  4168. {
  4169. plci->relatedPTYPLCI->vswitchstate=0;
  4170. plci->relatedPTYPLCI->vsprot=0;
  4171. plci->relatedPTYPLCI->vsprotdialect=0;
  4172. }
  4173. plci->vswitchstate=0;
  4174. plci->vsprot=0;
  4175. plci->vsprotdialect=0;
  4176. }
  4177. else
  4178. {
  4179. if(plci->relatedPTYPLCI &&
  4180. plci->vswitchstate==1 &&
  4181. plci->relatedPTYPLCI->vswitchstate==3) /* join complete */
  4182. plci->vswitchstate=3;
  4183. }
  4184. break;
  4185. /* Call Deflection Request pending (SSCT) */
  4186. case CD_REQ_PEND:
  4187. SSparms[1] = S_CALL_DEFLECTION;
  4188. if(rc!=OK)
  4189. {
  4190. Info = 0x300E; /* not supported */
  4191. plci->appl->CDEnable = 0;
  4192. }
  4193. sendf(plci->appl,_FACILITY_R|CONFIRM,Id,
  4194. plci->number,"wws",Info,(word)3,SSparms);
  4195. break;
  4196. case RTP_CONNECT_B3_REQ_COMMAND_2:
  4197. if (rc == OK)
  4198. {
  4199. ncci = get_ncci (plci, ch, 0);
  4200. Id = (Id & 0xffff) | (((dword) ncci) << 16);
  4201. plci->channels++;
  4202. a->ncci_state[ncci] = OUTG_CON_PENDING;
  4203. }
  4204. default:
  4205. if (plci->internal_command_queue[0])
  4206. {
  4207. (*(plci->internal_command_queue[0]))(Id, plci, rc);
  4208. if (plci->internal_command)
  4209. return;
  4210. }
  4211. break;
  4212. }
  4213. next_internal_command (Id, plci);
  4214. }
  4215. }
  4216. else /* appl==0 */
  4217. {
  4218. Id = ((word)plci->Id<<8)|plci->adapter->Id;
  4219. if(plci->tel) Id|=EXT_CONTROLLER;
  4220. switch(plci->internal_command)
  4221. {
  4222. case BLOCK_PLCI:
  4223. return;
  4224. case START_L1_SIG_ASSIGN_PEND:
  4225. case REM_L1_SIG_ASSIGN_PEND:
  4226. if(global_req == ASSIGN)
  4227. {
  4228. break;
  4229. }
  4230. else
  4231. {
  4232. dbug(1,dprintf("***L1 Req rem PLCI"));
  4233. plci->internal_command = 0;
  4234. sig_req(plci,REMOVE,0);
  4235. send_req(plci);
  4236. }
  4237. break;
  4238. /* Call Deflection Request pending, just no appl ptr assigned */
  4239. case CD_REQ_PEND:
  4240. SSparms[1] = S_CALL_DEFLECTION;
  4241. if(rc!=OK)
  4242. {
  4243. Info = 0x300E; /* not supported */
  4244. }
  4245. for(i=0; i<max_appl; i++)
  4246. {
  4247. if(application[i].CDEnable)
  4248. {
  4249. if(!application[i].Id) application[i].CDEnable = 0;
  4250. else
  4251. {
  4252. sendf(&application[i],_FACILITY_R|CONFIRM,Id,
  4253. plci->number,"wws",Info,(word)3,SSparms);
  4254. if(Info) application[i].CDEnable = 0;
  4255. }
  4256. }
  4257. }
  4258. plci->internal_command = 0;
  4259. break;
  4260. case PERM_COD_HOOK: /* finished with Hook_Ind */
  4261. return;
  4262. case PERM_COD_CALL:
  4263. plci->internal_command = PERM_COD_CONN_PEND;
  4264. dbug(1,dprintf("***Codec Connect_Pending, Rc = 0x%x",rc));
  4265. return;
  4266. case PERM_COD_ASSIGN:
  4267. dbug(1,dprintf("***Codec Assign, Rc = 0x%x",rc));
  4268. plci->internal_command = 0;
  4269. if(rc!=ASSIGN_OK) break;
  4270. plci->internal_command = PERM_COD_CALL;
  4271. sig_req(plci,CALL_REQ,0);
  4272. send_req(plci);
  4273. return;
  4274. case LISTEN_SIG_ASSIGN_PEND:
  4275. if(rc == ASSIGN_OK)
  4276. {
  4277. plci->internal_command = 0;
  4278. dbug(1,dprintf("ListenCheck, new SIG_ID = 0x%x",plci->Sig.Id));
  4279. add_p(plci,ESC,"\x02\x18\x00"); /* support call waiting */
  4280. sig_req(plci,INDICATE_REQ,0);
  4281. send_req(plci);
  4282. }
  4283. else
  4284. {
  4285. dbug(1,dprintf("ListenCheck failed (assignRc=0x%x)",rc));
  4286. a->listen_active--;
  4287. plci_remove(plci);
  4288. plci->State = IDLE;
  4289. }
  4290. break;
  4291. case USELAW_REQ:
  4292. if(global_req == ASSIGN)
  4293. {
  4294. if (rc==ASSIGN_OK)
  4295. {
  4296. sig_req(plci,LAW_REQ,0);
  4297. send_req(plci);
  4298. dbug(1,dprintf("Auto-Law assigned"));
  4299. }
  4300. else
  4301. {
  4302. dbug(1,dprintf("Auto-Law assign failed"));
  4303. a->automatic_law = 3;
  4304. plci->internal_command = 0;
  4305. a->automatic_lawPLCI = NULL;
  4306. }
  4307. break;
  4308. }
  4309. else if(req == LAW_REQ && rc==OK)
  4310. {
  4311. dbug(1,dprintf("Auto-Law initiated"));
  4312. a->automatic_law = 2;
  4313. plci->internal_command = 0;
  4314. }
  4315. else
  4316. {
  4317. dbug(1,dprintf("Auto-Law not supported"));
  4318. a->automatic_law = 3;
  4319. plci->internal_command = 0;
  4320. sig_req(plci,REMOVE,0);
  4321. send_req(plci);
  4322. a->automatic_lawPLCI = NULL;
  4323. }
  4324. break;
  4325. }
  4326. plci_remove_check(plci);
  4327. }
  4328. }
  4329. static void data_rc(PLCI *plci, byte ch)
  4330. {
  4331. dword Id;
  4332. DIVA_CAPI_ADAPTER * a;
  4333. NCCI *ncci_ptr;
  4334. DATA_B3_DESC *data;
  4335. word ncci;
  4336. if (plci->appl)
  4337. {
  4338. TransmitBufferFree (plci->appl, plci->data_sent_ptr);
  4339. a = plci->adapter;
  4340. ncci = a->ch_ncci[ch];
  4341. if (ncci && (a->ncci_plci[ncci] == plci->Id))
  4342. {
  4343. ncci_ptr = &(a->ncci[ncci]);
  4344. dbug(1,dprintf("data_out=%d, data_pending=%d",ncci_ptr->data_out,ncci_ptr->data_pending));
  4345. if (ncci_ptr->data_pending)
  4346. {
  4347. data = &(ncci_ptr->DBuffer[ncci_ptr->data_out]);
  4348. if (!(data->Flags &4) && a->ncci_state[ncci])
  4349. {
  4350. Id = (((dword)ncci)<<16)|((word)plci->Id<<8)|a->Id;
  4351. if(plci->tel) Id|=EXT_CONTROLLER;
  4352. sendf(plci->appl,_DATA_B3_R|CONFIRM,Id,data->Number,
  4353. "ww",data->Handle,0);
  4354. }
  4355. (ncci_ptr->data_out)++;
  4356. if (ncci_ptr->data_out == MAX_DATA_B3)
  4357. ncci_ptr->data_out = 0;
  4358. (ncci_ptr->data_pending)--;
  4359. }
  4360. }
  4361. }
  4362. }
  4363. static void data_ack(PLCI *plci, byte ch)
  4364. {
  4365. dword Id;
  4366. DIVA_CAPI_ADAPTER * a;
  4367. NCCI *ncci_ptr;
  4368. word ncci;
  4369. a = plci->adapter;
  4370. ncci = a->ch_ncci[ch];
  4371. ncci_ptr = &(a->ncci[ncci]);
  4372. if (ncci_ptr->data_ack_pending)
  4373. {
  4374. if (a->ncci_state[ncci] && (a->ncci_plci[ncci] == plci->Id))
  4375. {
  4376. Id = (((dword)ncci)<<16)|((word)plci->Id<<8)|a->Id;
  4377. if(plci->tel) Id|=EXT_CONTROLLER;
  4378. sendf(plci->appl,_DATA_B3_R|CONFIRM,Id,ncci_ptr->DataAck[ncci_ptr->data_ack_out].Number,
  4379. "ww",ncci_ptr->DataAck[ncci_ptr->data_ack_out].Handle,0);
  4380. }
  4381. (ncci_ptr->data_ack_out)++;
  4382. if (ncci_ptr->data_ack_out == MAX_DATA_ACK)
  4383. ncci_ptr->data_ack_out = 0;
  4384. (ncci_ptr->data_ack_pending)--;
  4385. }
  4386. }
  4387. static void sig_ind(PLCI *plci)
  4388. {
  4389. dword x_Id;
  4390. dword Id;
  4391. dword rId;
  4392. word Number = 0;
  4393. word i;
  4394. word cip;
  4395. dword cip_mask;
  4396. byte *ie;
  4397. DIVA_CAPI_ADAPTER * a;
  4398. API_PARSE saved_parms[MAX_MSG_PARMS+1];
  4399. #define MAXPARMSIDS 31
  4400. byte * parms[MAXPARMSIDS];
  4401. byte * add_i[4];
  4402. byte * multi_fac_parms[MAX_MULTI_IE];
  4403. byte * multi_pi_parms [MAX_MULTI_IE];
  4404. byte * multi_ssext_parms [MAX_MULTI_IE];
  4405. byte * multi_CiPN_parms [MAX_MULTI_IE];
  4406. byte * multi_vswitch_parms [MAX_MULTI_IE];
  4407. byte ai_len;
  4408. byte *esc_chi = "";
  4409. byte *esc_law = "";
  4410. byte *pty_cai = "";
  4411. byte *esc_cr = "";
  4412. byte *esc_profile = "";
  4413. byte facility[256];
  4414. PLCI * tplci = NULL;
  4415. byte chi[] = "\x02\x18\x01";
  4416. byte voice_cai[] = "\x06\x14\x00\x00\x00\x00\x08";
  4417. byte resume_cau[] = "\x05\x05\x00\x02\x00\x00";
  4418. /* ESC_MSGTYPE must be the last but one message, a new IE has to be */
  4419. /* included before the ESC_MSGTYPE and MAXPARMSIDS has to be incremented */
  4420. /* SMSG is situated at the end because its 0 (for compatibility reasons */
  4421. /* (see Info_Mask Bit 4, first IE. then the message type) */
  4422. word parms_id[] =
  4423. {MAXPARMSIDS, CPN, 0xff, DSA, OSA, BC, LLC, HLC, ESC_CAUSE, DSP, DT, CHA,
  4424. UUI, CONG_RR, CONG_RNR, ESC_CHI, KEY, CHI, CAU, ESC_LAW,
  4425. RDN, RDX, CONN_NR, RIN, NI, CAI, ESC_CR,
  4426. CST, ESC_PROFILE, 0xff, ESC_MSGTYPE, SMSG};
  4427. /* 14 FTY repl by ESC_CHI */
  4428. /* 18 PI repl by ESC_LAW */
  4429. /* removed OAD changed to 0xff for future use, OAD is multiIE now */
  4430. word multi_fac_id[] = {1, FTY};
  4431. word multi_pi_id[] = {1, PI};
  4432. word multi_CiPN_id[] = {1, OAD};
  4433. word multi_ssext_id[] = {1, ESC_SSEXT};
  4434. word multi_vswitch_id[] = {1, ESC_VSWITCH};
  4435. byte * cau;
  4436. word ncci;
  4437. byte SS_Ind[] = "\x05\x02\x00\x02\x00\x00"; /* Hold_Ind struct*/
  4438. byte CF_Ind[] = "\x09\x02\x00\x06\x00\x00\x00\x00\x00\x00";
  4439. byte Interr_Err_Ind[] = "\x0a\x02\x00\x07\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00";
  4440. byte CONF_Ind[] = "\x09\x16\x00\x06\x00\x00\0x00\0x00\0x00\0x00";
  4441. byte force_mt_info = false;
  4442. byte dir;
  4443. dword d;
  4444. word w;
  4445. a = plci->adapter;
  4446. Id = ((word)plci->Id<<8)|a->Id;
  4447. PUT_WORD(&SS_Ind[4],0x0000);
  4448. if (plci->sig_remove_id)
  4449. {
  4450. plci->Sig.RNR = 2; /* discard */
  4451. dbug(1,dprintf("SIG discard while remove pending"));
  4452. return;
  4453. }
  4454. if(plci->tel && plci->SuppState!=CALL_HELD) Id|=EXT_CONTROLLER;
  4455. dbug(1,dprintf("SigInd-Id=%08lx,plci=%x,tel=%x,state=0x%x,channels=%d,Discflowcl=%d",
  4456. Id,plci->Id,plci->tel,plci->State,plci->channels,plci->hangup_flow_ctrl_timer));
  4457. if(plci->Sig.Ind==CALL_HOLD_ACK && plci->channels)
  4458. {
  4459. plci->Sig.RNR = 1;
  4460. return;
  4461. }
  4462. if(plci->Sig.Ind==HANGUP && plci->channels)
  4463. {
  4464. plci->Sig.RNR = 1;
  4465. plci->hangup_flow_ctrl_timer++;
  4466. /* recover the network layer after timeout */
  4467. if(plci->hangup_flow_ctrl_timer==100)
  4468. {
  4469. dbug(1,dprintf("Exceptional disc"));
  4470. plci->Sig.RNR = 0;
  4471. plci->hangup_flow_ctrl_timer = 0;
  4472. for (ncci = 1; ncci < MAX_NCCI+1; ncci++)
  4473. {
  4474. if (a->ncci_plci[ncci] == plci->Id)
  4475. {
  4476. cleanup_ncci_data (plci, ncci);
  4477. if(plci->channels)plci->channels--;
  4478. if (plci->appl)
  4479. sendf(plci->appl,_DISCONNECT_B3_I, (((dword) ncci) << 16) | Id,0,"ws",0,"");
  4480. }
  4481. }
  4482. if (plci->appl)
  4483. sendf(plci->appl, _DISCONNECT_I, Id, 0, "w", 0);
  4484. plci_remove(plci);
  4485. plci->State=IDLE;
  4486. }
  4487. return;
  4488. }
  4489. /* do first parse the info with no OAD in, because OAD will be converted */
  4490. /* first the multiple facility IE, then mult. progress ind. */
  4491. /* then the parameters for the info_ind + conn_ind */
  4492. IndParse(plci,multi_fac_id,multi_fac_parms,MAX_MULTI_IE);
  4493. IndParse(plci,multi_pi_id,multi_pi_parms,MAX_MULTI_IE);
  4494. IndParse(plci,multi_ssext_id,multi_ssext_parms,MAX_MULTI_IE);
  4495. IndParse(plci,multi_vswitch_id,multi_vswitch_parms,MAX_MULTI_IE);
  4496. IndParse(plci,parms_id,parms,0);
  4497. IndParse(plci,multi_CiPN_id,multi_CiPN_parms,MAX_MULTI_IE);
  4498. esc_chi = parms[14];
  4499. esc_law = parms[18];
  4500. pty_cai = parms[24];
  4501. esc_cr = parms[25];
  4502. esc_profile = parms[27];
  4503. if(esc_cr[0] && plci)
  4504. {
  4505. if(plci->cr_enquiry && plci->appl)
  4506. {
  4507. plci->cr_enquiry = false;
  4508. /* d = MANU_ID */
  4509. /* w = m_command */
  4510. /* b = total length */
  4511. /* b = indication type */
  4512. /* b = length of all IEs */
  4513. /* b = IE1 */
  4514. /* S = IE1 length + cont. */
  4515. /* b = IE2 */
  4516. /* S = IE2 length + cont. */
  4517. sendf(plci->appl,
  4518. _MANUFACTURER_I,
  4519. Id,
  4520. 0,
  4521. "dwbbbbSbS",_DI_MANU_ID,plci->m_command,
  4522. 2+1+1+esc_cr[0]+1+1+esc_law[0],plci->Sig.Ind,1+1+esc_cr[0]+1+1+esc_law[0],ESC,esc_cr,ESC,esc_law);
  4523. }
  4524. }
  4525. /* create the additional info structure */
  4526. add_i[1] = parms[15]; /* KEY of additional info */
  4527. add_i[2] = parms[11]; /* UUI of additional info */
  4528. ai_len = AddInfo(add_i,multi_fac_parms, esc_chi, facility);
  4529. /* the ESC_LAW indicates if u-Law or a-Law is actually used by the card */
  4530. /* indication returns by the card if requested by the function */
  4531. /* AutomaticLaw() after driver init */
  4532. if (a->automatic_law<4)
  4533. {
  4534. if(esc_law[0]){
  4535. if(esc_law[2]){
  4536. dbug(0,dprintf("u-Law selected"));
  4537. a->u_law = 1;
  4538. }
  4539. else {
  4540. dbug(0,dprintf("a-Law selected"));
  4541. a->u_law = 0;
  4542. }
  4543. a->automatic_law = 4;
  4544. if(plci==a->automatic_lawPLCI) {
  4545. plci->internal_command = 0;
  4546. sig_req(plci,REMOVE,0);
  4547. send_req(plci);
  4548. a->automatic_lawPLCI = NULL;
  4549. }
  4550. }
  4551. if (esc_profile[0])
  4552. {
  4553. dbug (1, dprintf ("[%06x] CardProfile: %lx %lx %lx %lx %lx",
  4554. UnMapController (a->Id), GET_DWORD (&esc_profile[6]),
  4555. GET_DWORD (&esc_profile[10]), GET_DWORD (&esc_profile[14]),
  4556. GET_DWORD (&esc_profile[18]), GET_DWORD (&esc_profile[46])));
  4557. a->profile.Global_Options &= 0x000000ffL;
  4558. a->profile.B1_Protocols &= 0x000003ffL;
  4559. a->profile.B2_Protocols &= 0x00001fdfL;
  4560. a->profile.B3_Protocols &= 0x000000b7L;
  4561. a->profile.Global_Options &= GET_DWORD (&esc_profile[6]) |
  4562. GL_BCHANNEL_OPERATION_SUPPORTED;
  4563. a->profile.B1_Protocols &= GET_DWORD (&esc_profile[10]);
  4564. a->profile.B2_Protocols &= GET_DWORD (&esc_profile[14]);
  4565. a->profile.B3_Protocols &= GET_DWORD (&esc_profile[18]);
  4566. a->manufacturer_features = GET_DWORD (&esc_profile[46]);
  4567. a->man_profile.private_options = 0;
  4568. if (a->manufacturer_features & MANUFACTURER_FEATURE_ECHO_CANCELLER)
  4569. {
  4570. a->man_profile.private_options |= 1L << PRIVATE_ECHO_CANCELLER;
  4571. a->profile.Global_Options |= GL_ECHO_CANCELLER_SUPPORTED;
  4572. }
  4573. if (a->manufacturer_features & MANUFACTURER_FEATURE_RTP)
  4574. a->man_profile.private_options |= 1L << PRIVATE_RTP;
  4575. a->man_profile.rtp_primary_payloads = GET_DWORD (&esc_profile[50]);
  4576. a->man_profile.rtp_additional_payloads = GET_DWORD (&esc_profile[54]);
  4577. if (a->manufacturer_features & MANUFACTURER_FEATURE_T38)
  4578. a->man_profile.private_options |= 1L << PRIVATE_T38;
  4579. if (a->manufacturer_features & MANUFACTURER_FEATURE_FAX_SUB_SEP_PWD)
  4580. a->man_profile.private_options |= 1L << PRIVATE_FAX_SUB_SEP_PWD;
  4581. if (a->manufacturer_features & MANUFACTURER_FEATURE_V18)
  4582. a->man_profile.private_options |= 1L << PRIVATE_V18;
  4583. if (a->manufacturer_features & MANUFACTURER_FEATURE_DTMF_TONE)
  4584. a->man_profile.private_options |= 1L << PRIVATE_DTMF_TONE;
  4585. if (a->manufacturer_features & MANUFACTURER_FEATURE_PIAFS)
  4586. a->man_profile.private_options |= 1L << PRIVATE_PIAFS;
  4587. if (a->manufacturer_features & MANUFACTURER_FEATURE_FAX_PAPER_FORMATS)
  4588. a->man_profile.private_options |= 1L << PRIVATE_FAX_PAPER_FORMATS;
  4589. if (a->manufacturer_features & MANUFACTURER_FEATURE_VOWN)
  4590. a->man_profile.private_options |= 1L << PRIVATE_VOWN;
  4591. if (a->manufacturer_features & MANUFACTURER_FEATURE_FAX_NONSTANDARD)
  4592. a->man_profile.private_options |= 1L << PRIVATE_FAX_NONSTANDARD;
  4593. }
  4594. else
  4595. {
  4596. a->profile.Global_Options &= 0x0000007fL;
  4597. a->profile.B1_Protocols &= 0x000003dfL;
  4598. a->profile.B2_Protocols &= 0x00001adfL;
  4599. a->profile.B3_Protocols &= 0x000000b7L;
  4600. a->manufacturer_features &= MANUFACTURER_FEATURE_HARDDTMF;
  4601. }
  4602. if (a->manufacturer_features & (MANUFACTURER_FEATURE_HARDDTMF |
  4603. MANUFACTURER_FEATURE_SOFTDTMF_SEND | MANUFACTURER_FEATURE_SOFTDTMF_RECEIVE))
  4604. {
  4605. a->profile.Global_Options |= GL_DTMF_SUPPORTED;
  4606. }
  4607. a->manufacturer_features &= ~MANUFACTURER_FEATURE_OOB_CHANNEL;
  4608. dbug (1, dprintf ("[%06x] Profile: %lx %lx %lx %lx %lx",
  4609. UnMapController (a->Id), a->profile.Global_Options,
  4610. a->profile.B1_Protocols, a->profile.B2_Protocols,
  4611. a->profile.B3_Protocols, a->manufacturer_features));
  4612. }
  4613. /* codec plci for the handset/hook state support is just an internal id */
  4614. if(plci!=a->AdvCodecPLCI)
  4615. {
  4616. force_mt_info = SendMultiIE(plci,Id,multi_fac_parms, FTY, 0x20, 0);
  4617. force_mt_info |= SendMultiIE(plci,Id,multi_pi_parms, PI, 0x210, 0);
  4618. SendSSExtInd(NULL,plci,Id,multi_ssext_parms);
  4619. SendInfo(plci,Id, parms, force_mt_info);
  4620. VSwitchReqInd(plci,Id,multi_vswitch_parms);
  4621. }
  4622. /* switch the codec to the b-channel */
  4623. if(esc_chi[0] && plci && !plci->SuppState){
  4624. plci->b_channel = esc_chi[esc_chi[0]]&0x1f;
  4625. mixer_set_bchannel_id_esc (plci, plci->b_channel);
  4626. dbug(1,dprintf("storeChannel=0x%x",plci->b_channel));
  4627. if(plci->tel==ADV_VOICE && plci->appl) {
  4628. SetVoiceChannel(a->AdvCodecPLCI, esc_chi, a);
  4629. }
  4630. }
  4631. if(plci->appl) Number = plci->appl->Number++;
  4632. switch(plci->Sig.Ind) {
  4633. /* Response to Get_Supported_Services request */
  4634. case S_SUPPORTED:
  4635. dbug(1,dprintf("S_Supported"));
  4636. if(!plci->appl) break;
  4637. if(pty_cai[0]==4)
  4638. {
  4639. PUT_DWORD(&CF_Ind[6],GET_DWORD(&pty_cai[1]) );
  4640. }
  4641. else
  4642. {
  4643. PUT_DWORD(&CF_Ind[6],MASK_TERMINAL_PORTABILITY | MASK_HOLD_RETRIEVE);
  4644. }
  4645. PUT_WORD (&CF_Ind[1], 0);
  4646. PUT_WORD (&CF_Ind[4], 0);
  4647. sendf(plci->appl,_FACILITY_R|CONFIRM,Id&0x7,plci->number, "wws",0,3,CF_Ind);
  4648. plci_remove(plci);
  4649. break;
  4650. /* Supplementary Service rejected */
  4651. case S_SERVICE_REJ:
  4652. dbug(1,dprintf("S_Reject=0x%x",pty_cai[5]));
  4653. if(!pty_cai[0]) break;
  4654. switch (pty_cai[5])
  4655. {
  4656. case ECT_EXECUTE:
  4657. case THREE_PTY_END:
  4658. case THREE_PTY_BEGIN:
  4659. if(!plci->relatedPTYPLCI) break;
  4660. tplci = plci->relatedPTYPLCI;
  4661. rId = ( (word)tplci->Id<<8)|tplci->adapter->Id;
  4662. if(tplci->tel) rId|=EXT_CONTROLLER;
  4663. if(pty_cai[5]==ECT_EXECUTE)
  4664. {
  4665. PUT_WORD(&SS_Ind[1],S_ECT);
  4666. plci->vswitchstate=0;
  4667. plci->relatedPTYPLCI->vswitchstate=0;
  4668. }
  4669. else
  4670. {
  4671. PUT_WORD(&SS_Ind[1],pty_cai[5]+3);
  4672. }
  4673. if(pty_cai[2]!=0xff)
  4674. {
  4675. PUT_WORD(&SS_Ind[4],0x3600|(word)pty_cai[2]);
  4676. }
  4677. else
  4678. {
  4679. PUT_WORD(&SS_Ind[4],0x300E);
  4680. }
  4681. plci->relatedPTYPLCI = NULL;
  4682. plci->ptyState = 0;
  4683. sendf(tplci->appl,_FACILITY_I,rId,0,"ws",3, SS_Ind);
  4684. break;
  4685. case CALL_DEFLECTION:
  4686. if(pty_cai[2]!=0xff)
  4687. {
  4688. PUT_WORD(&SS_Ind[4],0x3600|(word)pty_cai[2]);
  4689. }
  4690. else
  4691. {
  4692. PUT_WORD(&SS_Ind[4],0x300E);
  4693. }
  4694. PUT_WORD(&SS_Ind[1],pty_cai[5]);
  4695. for(i=0; i<max_appl; i++)
  4696. {
  4697. if(application[i].CDEnable)
  4698. {
  4699. if(application[i].Id) sendf(&application[i],_FACILITY_I,Id,0,"ws",3, SS_Ind);
  4700. application[i].CDEnable = false;
  4701. }
  4702. }
  4703. break;
  4704. case DEACTIVATION_DIVERSION:
  4705. case ACTIVATION_DIVERSION:
  4706. case DIVERSION_INTERROGATE_CFU:
  4707. case DIVERSION_INTERROGATE_CFB:
  4708. case DIVERSION_INTERROGATE_CFNR:
  4709. case DIVERSION_INTERROGATE_NUM:
  4710. case CCBS_REQUEST:
  4711. case CCBS_DEACTIVATE:
  4712. case CCBS_INTERROGATE:
  4713. if(!plci->appl) break;
  4714. if(pty_cai[2]!=0xff)
  4715. {
  4716. PUT_WORD(&Interr_Err_Ind[4],0x3600|(word)pty_cai[2]);
  4717. }
  4718. else
  4719. {
  4720. PUT_WORD(&Interr_Err_Ind[4],0x300E);
  4721. }
  4722. switch (pty_cai[5])
  4723. {
  4724. case DEACTIVATION_DIVERSION:
  4725. dbug(1,dprintf("Deact_Div"));
  4726. Interr_Err_Ind[0]=0x9;
  4727. Interr_Err_Ind[3]=0x6;
  4728. PUT_WORD(&Interr_Err_Ind[1],S_CALL_FORWARDING_STOP);
  4729. break;
  4730. case ACTIVATION_DIVERSION:
  4731. dbug(1,dprintf("Act_Div"));
  4732. Interr_Err_Ind[0]=0x9;
  4733. Interr_Err_Ind[3]=0x6;
  4734. PUT_WORD(&Interr_Err_Ind[1],S_CALL_FORWARDING_START);
  4735. break;
  4736. case DIVERSION_INTERROGATE_CFU:
  4737. case DIVERSION_INTERROGATE_CFB:
  4738. case DIVERSION_INTERROGATE_CFNR:
  4739. dbug(1,dprintf("Interr_Div"));
  4740. Interr_Err_Ind[0]=0xa;
  4741. Interr_Err_Ind[3]=0x7;
  4742. PUT_WORD(&Interr_Err_Ind[1],S_INTERROGATE_DIVERSION);
  4743. break;
  4744. case DIVERSION_INTERROGATE_NUM:
  4745. dbug(1,dprintf("Interr_Num"));
  4746. Interr_Err_Ind[0]=0xa;
  4747. Interr_Err_Ind[3]=0x7;
  4748. PUT_WORD(&Interr_Err_Ind[1],S_INTERROGATE_NUMBERS);
  4749. break;
  4750. case CCBS_REQUEST:
  4751. dbug(1,dprintf("CCBS Request"));
  4752. Interr_Err_Ind[0]=0xd;
  4753. Interr_Err_Ind[3]=0xa;
  4754. PUT_WORD(&Interr_Err_Ind[1],S_CCBS_REQUEST);
  4755. break;
  4756. case CCBS_DEACTIVATE:
  4757. dbug(1,dprintf("CCBS Deactivate"));
  4758. Interr_Err_Ind[0]=0x9;
  4759. Interr_Err_Ind[3]=0x6;
  4760. PUT_WORD(&Interr_Err_Ind[1],S_CCBS_DEACTIVATE);
  4761. break;
  4762. case CCBS_INTERROGATE:
  4763. dbug(1,dprintf("CCBS Interrogate"));
  4764. Interr_Err_Ind[0]=0xb;
  4765. Interr_Err_Ind[3]=0x8;
  4766. PUT_WORD(&Interr_Err_Ind[1],S_CCBS_INTERROGATE);
  4767. break;
  4768. }
  4769. PUT_DWORD(&Interr_Err_Ind[6],plci->appl->S_Handle);
  4770. sendf(plci->appl,_FACILITY_I,Id&0x7,0,"ws",3, Interr_Err_Ind);
  4771. plci_remove(plci);
  4772. break;
  4773. case ACTIVATION_MWI:
  4774. case DEACTIVATION_MWI:
  4775. if(pty_cai[5]==ACTIVATION_MWI)
  4776. {
  4777. PUT_WORD(&SS_Ind[1],S_MWI_ACTIVATE);
  4778. }
  4779. else PUT_WORD(&SS_Ind[1],S_MWI_DEACTIVATE);
  4780. if(pty_cai[2]!=0xff)
  4781. {
  4782. PUT_WORD(&SS_Ind[4],0x3600|(word)pty_cai[2]);
  4783. }
  4784. else
  4785. {
  4786. PUT_WORD(&SS_Ind[4],0x300E);
  4787. }
  4788. if(plci->cr_enquiry)
  4789. {
  4790. sendf(plci->appl,_FACILITY_I,Id&0xf,0,"ws",3, SS_Ind);
  4791. plci_remove(plci);
  4792. }
  4793. else
  4794. {
  4795. sendf(plci->appl,_FACILITY_I,Id,0,"ws",3, SS_Ind);
  4796. }
  4797. break;
  4798. case CONF_ADD: /* ERROR */
  4799. case CONF_BEGIN:
  4800. case CONF_DROP:
  4801. case CONF_ISOLATE:
  4802. case CONF_REATTACH:
  4803. CONF_Ind[0]=9;
  4804. CONF_Ind[3]=6;
  4805. switch(pty_cai[5])
  4806. {
  4807. case CONF_BEGIN:
  4808. PUT_WORD(&CONF_Ind[1],S_CONF_BEGIN);
  4809. plci->ptyState = 0;
  4810. break;
  4811. case CONF_DROP:
  4812. CONF_Ind[0]=5;
  4813. CONF_Ind[3]=2;
  4814. PUT_WORD(&CONF_Ind[1],S_CONF_DROP);
  4815. plci->ptyState = CONNECTED;
  4816. break;
  4817. case CONF_ISOLATE:
  4818. CONF_Ind[0]=5;
  4819. CONF_Ind[3]=2;
  4820. PUT_WORD(&CONF_Ind[1],S_CONF_ISOLATE);
  4821. plci->ptyState = CONNECTED;
  4822. break;
  4823. case CONF_REATTACH:
  4824. CONF_Ind[0]=5;
  4825. CONF_Ind[3]=2;
  4826. PUT_WORD(&CONF_Ind[1],S_CONF_REATTACH);
  4827. plci->ptyState = CONNECTED;
  4828. break;
  4829. case CONF_ADD:
  4830. PUT_WORD(&CONF_Ind[1],S_CONF_ADD);
  4831. plci->relatedPTYPLCI = NULL;
  4832. tplci=plci->relatedPTYPLCI;
  4833. if(tplci) tplci->ptyState = CONNECTED;
  4834. plci->ptyState = CONNECTED;
  4835. break;
  4836. }
  4837. if(pty_cai[2]!=0xff)
  4838. {
  4839. PUT_WORD(&CONF_Ind[4],0x3600|(word)pty_cai[2]);
  4840. }
  4841. else
  4842. {
  4843. PUT_WORD(&CONF_Ind[4],0x3303); /* Time-out: network did not respond
  4844. within the required time */
  4845. }
  4846. PUT_DWORD(&CONF_Ind[6],0x0);
  4847. sendf(plci->appl,_FACILITY_I,Id,0,"ws",3, CONF_Ind);
  4848. break;
  4849. }
  4850. break;
  4851. /* Supplementary Service indicates success */
  4852. case S_SERVICE:
  4853. dbug(1,dprintf("Service_Ind"));
  4854. PUT_WORD (&CF_Ind[4], 0);
  4855. switch (pty_cai[5])
  4856. {
  4857. case THREE_PTY_END:
  4858. case THREE_PTY_BEGIN:
  4859. case ECT_EXECUTE:
  4860. if(!plci->relatedPTYPLCI) break;
  4861. tplci = plci->relatedPTYPLCI;
  4862. rId = ( (word)tplci->Id<<8)|tplci->adapter->Id;
  4863. if(tplci->tel) rId|=EXT_CONTROLLER;
  4864. if(pty_cai[5]==ECT_EXECUTE)
  4865. {
  4866. PUT_WORD(&SS_Ind[1],S_ECT);
  4867. if(plci->vswitchstate!=3)
  4868. {
  4869. plci->ptyState = IDLE;
  4870. plci->relatedPTYPLCI = NULL;
  4871. plci->ptyState = 0;
  4872. }
  4873. dbug(1,dprintf("ECT OK"));
  4874. sendf(tplci->appl,_FACILITY_I,rId,0,"ws",3, SS_Ind);
  4875. }
  4876. else
  4877. {
  4878. switch (plci->ptyState)
  4879. {
  4880. case S_3PTY_BEGIN:
  4881. plci->ptyState = CONNECTED;
  4882. dbug(1,dprintf("3PTY ON"));
  4883. break;
  4884. case S_3PTY_END:
  4885. plci->ptyState = IDLE;
  4886. plci->relatedPTYPLCI = NULL;
  4887. plci->ptyState = 0;
  4888. dbug(1,dprintf("3PTY OFF"));
  4889. break;
  4890. }
  4891. PUT_WORD(&SS_Ind[1],pty_cai[5]+3);
  4892. sendf(tplci->appl,_FACILITY_I,rId,0,"ws",3, SS_Ind);
  4893. }
  4894. break;
  4895. case CALL_DEFLECTION:
  4896. PUT_WORD(&SS_Ind[1],pty_cai[5]);
  4897. for(i=0; i<max_appl; i++)
  4898. {
  4899. if(application[i].CDEnable)
  4900. {
  4901. if(application[i].Id) sendf(&application[i],_FACILITY_I,Id,0,"ws",3, SS_Ind);
  4902. application[i].CDEnable = false;
  4903. }
  4904. }
  4905. break;
  4906. case DEACTIVATION_DIVERSION:
  4907. case ACTIVATION_DIVERSION:
  4908. if(!plci->appl) break;
  4909. PUT_WORD(&CF_Ind[1],pty_cai[5]+2);
  4910. PUT_DWORD(&CF_Ind[6],plci->appl->S_Handle);
  4911. sendf(plci->appl,_FACILITY_I,Id&0x7,0,"ws",3, CF_Ind);
  4912. plci_remove(plci);
  4913. break;
  4914. case DIVERSION_INTERROGATE_CFU:
  4915. case DIVERSION_INTERROGATE_CFB:
  4916. case DIVERSION_INTERROGATE_CFNR:
  4917. case DIVERSION_INTERROGATE_NUM:
  4918. case CCBS_REQUEST:
  4919. case CCBS_DEACTIVATE:
  4920. case CCBS_INTERROGATE:
  4921. if(!plci->appl) break;
  4922. switch (pty_cai[5])
  4923. {
  4924. case DIVERSION_INTERROGATE_CFU:
  4925. case DIVERSION_INTERROGATE_CFB:
  4926. case DIVERSION_INTERROGATE_CFNR:
  4927. dbug(1,dprintf("Interr_Div"));
  4928. PUT_WORD(&pty_cai[1],S_INTERROGATE_DIVERSION);
  4929. pty_cai[3]=pty_cai[0]-3; /* Supplementary Service-specific parameter len */
  4930. break;
  4931. case DIVERSION_INTERROGATE_NUM:
  4932. dbug(1,dprintf("Interr_Num"));
  4933. PUT_WORD(&pty_cai[1],S_INTERROGATE_NUMBERS);
  4934. pty_cai[3]=pty_cai[0]-3; /* Supplementary Service-specific parameter len */
  4935. break;
  4936. case CCBS_REQUEST:
  4937. dbug(1,dprintf("CCBS Request"));
  4938. PUT_WORD(&pty_cai[1],S_CCBS_REQUEST);
  4939. pty_cai[3]=pty_cai[0]-3; /* Supplementary Service-specific parameter len */
  4940. break;
  4941. case CCBS_DEACTIVATE:
  4942. dbug(1,dprintf("CCBS Deactivate"));
  4943. PUT_WORD(&pty_cai[1],S_CCBS_DEACTIVATE);
  4944. pty_cai[3]=pty_cai[0]-3; /* Supplementary Service-specific parameter len */
  4945. break;
  4946. case CCBS_INTERROGATE:
  4947. dbug(1,dprintf("CCBS Interrogate"));
  4948. PUT_WORD(&pty_cai[1],S_CCBS_INTERROGATE);
  4949. pty_cai[3]=pty_cai[0]-3; /* Supplementary Service-specific parameter len */
  4950. break;
  4951. }
  4952. PUT_WORD(&pty_cai[4],0); /* Supplementary Service Reason */
  4953. PUT_DWORD(&pty_cai[6],plci->appl->S_Handle);
  4954. sendf(plci->appl,_FACILITY_I,Id&0x7,0,"wS",3, pty_cai);
  4955. plci_remove(plci);
  4956. break;
  4957. case ACTIVATION_MWI:
  4958. case DEACTIVATION_MWI:
  4959. if(pty_cai[5]==ACTIVATION_MWI)
  4960. {
  4961. PUT_WORD(&SS_Ind[1],S_MWI_ACTIVATE);
  4962. }
  4963. else PUT_WORD(&SS_Ind[1],S_MWI_DEACTIVATE);
  4964. if(plci->cr_enquiry)
  4965. {
  4966. sendf(plci->appl,_FACILITY_I,Id&0xf,0,"ws",3, SS_Ind);
  4967. plci_remove(plci);
  4968. }
  4969. else
  4970. {
  4971. sendf(plci->appl,_FACILITY_I,Id,0,"ws",3, SS_Ind);
  4972. }
  4973. break;
  4974. case MWI_INDICATION:
  4975. if(pty_cai[0]>=0x12)
  4976. {
  4977. PUT_WORD(&pty_cai[3],S_MWI_INDICATE);
  4978. pty_cai[2]=pty_cai[0]-2; /* len Parameter */
  4979. pty_cai[5]=pty_cai[0]-5; /* Supplementary Service-specific parameter len */
  4980. if(plci->appl && (a->Notification_Mask[plci->appl->Id-1]&SMASK_MWI))
  4981. {
  4982. if(plci->internal_command==GET_MWI_STATE) /* result on Message Waiting Listen */
  4983. {
  4984. sendf(plci->appl,_FACILITY_I,Id&0xf,0,"wS",3, &pty_cai[2]);
  4985. plci_remove(plci);
  4986. return;
  4987. }
  4988. else sendf(plci->appl,_FACILITY_I,Id,0,"wS",3, &pty_cai[2]);
  4989. pty_cai[0]=0;
  4990. }
  4991. else
  4992. {
  4993. for(i=0; i<max_appl; i++)
  4994. {
  4995. if(a->Notification_Mask[i]&SMASK_MWI)
  4996. {
  4997. sendf(&application[i],_FACILITY_I,Id&0x7,0,"wS",3, &pty_cai[2]);
  4998. pty_cai[0]=0;
  4999. }
  5000. }
  5001. }
  5002. if(!pty_cai[0])
  5003. { /* acknowledge */
  5004. facility[2]= 0; /* returncode */
  5005. }
  5006. else facility[2]= 0xff;
  5007. }
  5008. else
  5009. {
  5010. /* reject */
  5011. facility[2]= 0xff; /* returncode */
  5012. }
  5013. facility[0]= 2;
  5014. facility[1]= MWI_RESPONSE; /* Function */
  5015. add_p(plci,CAI,facility);
  5016. add_p(plci,ESC,multi_ssext_parms[0]); /* remembered parameter -> only one possible */
  5017. sig_req(plci,S_SERVICE,0);
  5018. send_req(plci);
  5019. plci->command = 0;
  5020. next_internal_command (Id, plci);
  5021. break;
  5022. case CONF_ADD: /* OK */
  5023. case CONF_BEGIN:
  5024. case CONF_DROP:
  5025. case CONF_ISOLATE:
  5026. case CONF_REATTACH:
  5027. case CONF_PARTYDISC:
  5028. CONF_Ind[0]=9;
  5029. CONF_Ind[3]=6;
  5030. switch(pty_cai[5])
  5031. {
  5032. case CONF_BEGIN:
  5033. PUT_WORD(&CONF_Ind[1],S_CONF_BEGIN);
  5034. if(pty_cai[0]==6)
  5035. {
  5036. d=pty_cai[6];
  5037. PUT_DWORD(&CONF_Ind[6],d); /* PartyID */
  5038. }
  5039. else
  5040. {
  5041. PUT_DWORD(&CONF_Ind[6],0x0);
  5042. }
  5043. break;
  5044. case CONF_ISOLATE:
  5045. PUT_WORD(&CONF_Ind[1],S_CONF_ISOLATE);
  5046. CONF_Ind[0]=5;
  5047. CONF_Ind[3]=2;
  5048. break;
  5049. case CONF_REATTACH:
  5050. PUT_WORD(&CONF_Ind[1],S_CONF_REATTACH);
  5051. CONF_Ind[0]=5;
  5052. CONF_Ind[3]=2;
  5053. break;
  5054. case CONF_DROP:
  5055. PUT_WORD(&CONF_Ind[1],S_CONF_DROP);
  5056. CONF_Ind[0]=5;
  5057. CONF_Ind[3]=2;
  5058. break;
  5059. case CONF_ADD:
  5060. PUT_WORD(&CONF_Ind[1],S_CONF_ADD);
  5061. d=pty_cai[6];
  5062. PUT_DWORD(&CONF_Ind[6],d); /* PartyID */
  5063. tplci=plci->relatedPTYPLCI;
  5064. if(tplci) tplci->ptyState = CONNECTED;
  5065. break;
  5066. case CONF_PARTYDISC:
  5067. CONF_Ind[0]=7;
  5068. CONF_Ind[3]=4;
  5069. PUT_WORD(&CONF_Ind[1],S_CONF_PARTYDISC);
  5070. d=pty_cai[6];
  5071. PUT_DWORD(&CONF_Ind[4],d); /* PartyID */
  5072. break;
  5073. }
  5074. plci->ptyState = CONNECTED;
  5075. sendf(plci->appl,_FACILITY_I,Id,0,"ws",3, CONF_Ind);
  5076. break;
  5077. case CCBS_INFO_RETAIN:
  5078. case CCBS_ERASECALLLINKAGEID:
  5079. case CCBS_STOP_ALERTING:
  5080. CONF_Ind[0]=5;
  5081. CONF_Ind[3]=2;
  5082. switch(pty_cai[5])
  5083. {
  5084. case CCBS_INFO_RETAIN:
  5085. PUT_WORD(&CONF_Ind[1],S_CCBS_INFO_RETAIN);
  5086. break;
  5087. case CCBS_STOP_ALERTING:
  5088. PUT_WORD(&CONF_Ind[1],S_CCBS_STOP_ALERTING);
  5089. break;
  5090. case CCBS_ERASECALLLINKAGEID:
  5091. PUT_WORD(&CONF_Ind[1],S_CCBS_ERASECALLLINKAGEID);
  5092. CONF_Ind[0]=7;
  5093. CONF_Ind[3]=4;
  5094. CONF_Ind[6]=0;
  5095. CONF_Ind[7]=0;
  5096. break;
  5097. }
  5098. w=pty_cai[6];
  5099. PUT_WORD(&CONF_Ind[4],w); /* PartyID */
  5100. if(plci->appl && (a->Notification_Mask[plci->appl->Id-1]&SMASK_CCBS))
  5101. {
  5102. sendf(plci->appl,_FACILITY_I,Id,0,"ws",3, CONF_Ind);
  5103. }
  5104. else
  5105. {
  5106. for(i=0; i<max_appl; i++)
  5107. if(a->Notification_Mask[i]&SMASK_CCBS)
  5108. sendf(&application[i],_FACILITY_I,Id&0x7,0,"ws",3, CONF_Ind);
  5109. }
  5110. break;
  5111. }
  5112. break;
  5113. case CALL_HOLD_REJ:
  5114. cau = parms[7];
  5115. if(cau)
  5116. {
  5117. i = _L3_CAUSE | cau[2];
  5118. if(cau[2]==0) i = 0x3603;
  5119. }
  5120. else
  5121. {
  5122. i = 0x3603;
  5123. }
  5124. PUT_WORD(&SS_Ind[1],S_HOLD);
  5125. PUT_WORD(&SS_Ind[4],i);
  5126. if(plci->SuppState == HOLD_REQUEST)
  5127. {
  5128. plci->SuppState = IDLE;
  5129. sendf(plci->appl,_FACILITY_I,Id,0,"ws",3, SS_Ind);
  5130. }
  5131. break;
  5132. case CALL_HOLD_ACK:
  5133. if(plci->SuppState == HOLD_REQUEST)
  5134. {
  5135. plci->SuppState = CALL_HELD;
  5136. CodecIdCheck(a, plci);
  5137. start_internal_command (Id, plci, hold_save_command);
  5138. }
  5139. break;
  5140. case CALL_RETRIEVE_REJ:
  5141. cau = parms[7];
  5142. if(cau)
  5143. {
  5144. i = _L3_CAUSE | cau[2];
  5145. if(cau[2]==0) i = 0x3603;
  5146. }
  5147. else
  5148. {
  5149. i = 0x3603;
  5150. }
  5151. PUT_WORD(&SS_Ind[1],S_RETRIEVE);
  5152. PUT_WORD(&SS_Ind[4],i);
  5153. if(plci->SuppState == RETRIEVE_REQUEST)
  5154. {
  5155. plci->SuppState = CALL_HELD;
  5156. CodecIdCheck(a, plci);
  5157. sendf(plci->appl,_FACILITY_I,Id,0,"ws",3, SS_Ind);
  5158. }
  5159. break;
  5160. case CALL_RETRIEVE_ACK:
  5161. PUT_WORD(&SS_Ind[1],S_RETRIEVE);
  5162. if(plci->SuppState == RETRIEVE_REQUEST)
  5163. {
  5164. plci->SuppState = IDLE;
  5165. plci->call_dir |= CALL_DIR_FORCE_OUTG_NL;
  5166. plci->b_channel = esc_chi[esc_chi[0]]&0x1f;
  5167. if(plci->tel)
  5168. {
  5169. mixer_set_bchannel_id_esc (plci, plci->b_channel);
  5170. dbug(1,dprintf("RetrChannel=0x%x",plci->b_channel));
  5171. SetVoiceChannel(a->AdvCodecPLCI, esc_chi, a);
  5172. if(plci->B2_prot==B2_TRANSPARENT && plci->B3_prot==B3_TRANSPARENT)
  5173. {
  5174. dbug(1,dprintf("Get B-ch"));
  5175. start_internal_command (Id, plci, retrieve_restore_command);
  5176. }
  5177. else
  5178. sendf(plci->appl,_FACILITY_I,Id,0,"ws",3, SS_Ind);
  5179. }
  5180. else
  5181. start_internal_command (Id, plci, retrieve_restore_command);
  5182. }
  5183. break;
  5184. case INDICATE_IND:
  5185. if(plci->State != LISTENING) {
  5186. sig_req(plci,HANGUP,0);
  5187. send_req(plci);
  5188. break;
  5189. }
  5190. cip = find_cip(a,parms[4],parms[6]);
  5191. cip_mask = 1L<<cip;
  5192. dbug(1,dprintf("cip=%d,cip_mask=%lx",cip,cip_mask));
  5193. clear_c_ind_mask (plci);
  5194. if (!remove_started && !a->adapter_disabled)
  5195. {
  5196. set_c_ind_mask_bit (plci, MAX_APPL);
  5197. group_optimization(a, plci);
  5198. for(i=0; i<max_appl; i++) {
  5199. if(application[i].Id
  5200. && (a->CIP_Mask[i]&1 || a->CIP_Mask[i]&cip_mask)
  5201. && CPN_filter_ok(parms[0],a,i)
  5202. && test_group_ind_mask_bit (plci, i) ) {
  5203. dbug(1,dprintf("storedcip_mask[%d]=0x%lx",i,a->CIP_Mask[i] ));
  5204. set_c_ind_mask_bit (plci, i);
  5205. dump_c_ind_mask (plci);
  5206. plci->State = INC_CON_PENDING;
  5207. plci->call_dir = (plci->call_dir & ~(CALL_DIR_OUT | CALL_DIR_ORIGINATE)) |
  5208. CALL_DIR_IN | CALL_DIR_ANSWER;
  5209. if(esc_chi[0]) {
  5210. plci->b_channel = esc_chi[esc_chi[0]]&0x1f;
  5211. mixer_set_bchannel_id_esc (plci, plci->b_channel);
  5212. }
  5213. /* if a listen on the ext controller is done, check if hook states */
  5214. /* are supported or if just a on board codec must be activated */
  5215. if(a->codec_listen[i] && !a->AdvSignalPLCI) {
  5216. if(a->profile.Global_Options & HANDSET)
  5217. plci->tel = ADV_VOICE;
  5218. else if(a->profile.Global_Options & ON_BOARD_CODEC)
  5219. plci->tel = CODEC;
  5220. if(plci->tel) Id|=EXT_CONTROLLER;
  5221. a->codec_listen[i] = plci;
  5222. }
  5223. sendf(&application[i],_CONNECT_I,Id,0,
  5224. "wSSSSSSSbSSSSS", cip, /* CIP */
  5225. parms[0], /* CalledPartyNumber */
  5226. multi_CiPN_parms[0], /* CallingPartyNumber */
  5227. parms[2], /* CalledPartySubad */
  5228. parms[3], /* CallingPartySubad */
  5229. parms[4], /* BearerCapability */
  5230. parms[5], /* LowLC */
  5231. parms[6], /* HighLC */
  5232. ai_len, /* nested struct add_i */
  5233. add_i[0], /* B channel info */
  5234. add_i[1], /* keypad facility */
  5235. add_i[2], /* user user data */
  5236. add_i[3], /* nested facility */
  5237. multi_CiPN_parms[1] /* second CiPN(SCR) */
  5238. );
  5239. SendSSExtInd(&application[i],
  5240. plci,
  5241. Id,
  5242. multi_ssext_parms);
  5243. SendSetupInfo(&application[i],
  5244. plci,
  5245. Id,
  5246. parms,
  5247. SendMultiIE(plci,Id,multi_pi_parms, PI, 0x210, true));
  5248. }
  5249. }
  5250. clear_c_ind_mask_bit (plci, MAX_APPL);
  5251. dump_c_ind_mask (plci);
  5252. }
  5253. if(c_ind_mask_empty (plci)) {
  5254. sig_req(plci,HANGUP,0);
  5255. send_req(plci);
  5256. plci->State = IDLE;
  5257. }
  5258. plci->notifiedcall = 0;
  5259. a->listen_active--;
  5260. listen_check(a);
  5261. break;
  5262. case CALL_PEND_NOTIFY:
  5263. plci->notifiedcall = 1;
  5264. listen_check(a);
  5265. break;
  5266. case CALL_IND:
  5267. case CALL_CON:
  5268. if(plci->State==ADVANCED_VOICE_SIG || plci->State==ADVANCED_VOICE_NOSIG)
  5269. {
  5270. if(plci->internal_command==PERM_COD_CONN_PEND)
  5271. {
  5272. if(plci->State==ADVANCED_VOICE_NOSIG)
  5273. {
  5274. dbug(1,dprintf("***Codec OK"));
  5275. if(a->AdvSignalPLCI)
  5276. {
  5277. tplci = a->AdvSignalPLCI;
  5278. if(tplci->spoofed_msg)
  5279. {
  5280. dbug(1,dprintf("***Spoofed Msg(0x%x)",tplci->spoofed_msg));
  5281. tplci->command = 0;
  5282. tplci->internal_command = 0;
  5283. x_Id = ((word)tplci->Id<<8)|tplci->adapter->Id | 0x80;
  5284. switch (tplci->spoofed_msg)
  5285. {
  5286. case CALL_RES:
  5287. tplci->command = _CONNECT_I|RESPONSE;
  5288. api_load_msg (&tplci->saved_msg, saved_parms);
  5289. add_b1(tplci,&saved_parms[1],0,tplci->B1_facilities);
  5290. if (tplci->adapter->Info_Mask[tplci->appl->Id-1] & 0x200)
  5291. {
  5292. /* early B3 connect (CIP mask bit 9) no release after a disc */
  5293. add_p(tplci,LLI,"\x01\x01");
  5294. }
  5295. add_s(tplci, CONN_NR, &saved_parms[2]);
  5296. add_s(tplci, LLC, &saved_parms[4]);
  5297. add_ai(tplci, &saved_parms[5]);
  5298. tplci->State = INC_CON_ACCEPT;
  5299. sig_req(tplci, CALL_RES,0);
  5300. send_req(tplci);
  5301. break;
  5302. case AWAITING_SELECT_B:
  5303. dbug(1,dprintf("Select_B continue"));
  5304. start_internal_command (x_Id, tplci, select_b_command);
  5305. break;
  5306. case AWAITING_MANUF_CON: /* Get_Plci per Manufacturer_Req to ext controller */
  5307. if(!tplci->Sig.Id)
  5308. {
  5309. dbug(1,dprintf("No SigID!"));
  5310. sendf(tplci->appl, _MANUFACTURER_R|CONFIRM,x_Id,tplci->number, "dww",_DI_MANU_ID,_MANUFACTURER_R,_OUT_OF_PLCI);
  5311. plci_remove(tplci);
  5312. break;
  5313. }
  5314. tplci->command = _MANUFACTURER_R;
  5315. api_load_msg (&tplci->saved_msg, saved_parms);
  5316. dir = saved_parms[2].info[0];
  5317. if(dir==1) {
  5318. sig_req(tplci,CALL_REQ,0);
  5319. }
  5320. else if(!dir){
  5321. sig_req(tplci,LISTEN_REQ,0);
  5322. }
  5323. send_req(tplci);
  5324. sendf(tplci->appl, _MANUFACTURER_R|CONFIRM,x_Id,tplci->number, "dww",_DI_MANU_ID,_MANUFACTURER_R,0);
  5325. break;
  5326. case (CALL_REQ|AWAITING_MANUF_CON):
  5327. sig_req(tplci,CALL_REQ,0);
  5328. send_req(tplci);
  5329. break;
  5330. case CALL_REQ:
  5331. if(!tplci->Sig.Id)
  5332. {
  5333. dbug(1,dprintf("No SigID!"));
  5334. sendf(tplci->appl,_CONNECT_R|CONFIRM,tplci->adapter->Id,0,"w",_OUT_OF_PLCI);
  5335. plci_remove(tplci);
  5336. break;
  5337. }
  5338. tplci->command = _CONNECT_R;
  5339. api_load_msg (&tplci->saved_msg, saved_parms);
  5340. add_s(tplci,CPN,&saved_parms[1]);
  5341. add_s(tplci,DSA,&saved_parms[3]);
  5342. add_ai(tplci,&saved_parms[9]);
  5343. sig_req(tplci,CALL_REQ,0);
  5344. send_req(tplci);
  5345. break;
  5346. case CALL_RETRIEVE:
  5347. tplci->command = C_RETRIEVE_REQ;
  5348. sig_req(tplci,CALL_RETRIEVE,0);
  5349. send_req(tplci);
  5350. break;
  5351. }
  5352. tplci->spoofed_msg = 0;
  5353. if (tplci->internal_command == 0)
  5354. next_internal_command (x_Id, tplci);
  5355. }
  5356. }
  5357. next_internal_command (Id, plci);
  5358. break;
  5359. }
  5360. dbug(1,dprintf("***Codec Hook Init Req"));
  5361. plci->internal_command = PERM_COD_HOOK;
  5362. add_p(plci,FTY,"\x01\x09"); /* Get Hook State*/
  5363. sig_req(plci,TEL_CTRL,0);
  5364. send_req(plci);
  5365. }
  5366. }
  5367. else if(plci->command != _MANUFACTURER_R /* old style permanent connect */
  5368. && plci->State!=INC_ACT_PENDING)
  5369. {
  5370. mixer_set_bchannel_id_esc (plci, plci->b_channel);
  5371. if(plci->tel == ADV_VOICE && plci->SuppState == IDLE) /* with permanent codec switch on immediately */
  5372. {
  5373. chi[2] = plci->b_channel;
  5374. SetVoiceChannel(a->AdvCodecPLCI, chi, a);
  5375. }
  5376. sendf(plci->appl,_CONNECT_ACTIVE_I,Id,0,"Sss",parms[21],"","");
  5377. plci->State = INC_ACT_PENDING;
  5378. }
  5379. break;
  5380. case TEL_CTRL:
  5381. Number = 0;
  5382. ie = multi_fac_parms[0]; /* inspect the facility hook indications */
  5383. if(plci->State==ADVANCED_VOICE_SIG && ie[0]){
  5384. switch (ie[1]&0x91) {
  5385. case 0x80: /* hook off */
  5386. case 0x81:
  5387. if(plci->internal_command==PERM_COD_HOOK)
  5388. {
  5389. dbug(1,dprintf("init:hook_off"));
  5390. plci->hook_state = ie[1];
  5391. next_internal_command (Id, plci);
  5392. break;
  5393. }
  5394. else /* ignore doubled hook indications */
  5395. {
  5396. if( ((plci->hook_state)&0xf0)==0x80)
  5397. {
  5398. dbug(1,dprintf("ignore hook"));
  5399. break;
  5400. }
  5401. plci->hook_state = ie[1]&0x91;
  5402. }
  5403. /* check for incoming call pending */
  5404. /* and signal '+'.Appl must decide */
  5405. /* with connect_res if call must */
  5406. /* accepted or not */
  5407. for(i=0, tplci=NULL;i<max_appl;i++){
  5408. if(a->codec_listen[i]
  5409. && (a->codec_listen[i]->State==INC_CON_PENDING
  5410. ||a->codec_listen[i]->State==INC_CON_ALERT) ){
  5411. tplci = a->codec_listen[i];
  5412. tplci->appl = &application[i];
  5413. }
  5414. }
  5415. /* no incoming call, do outgoing call */
  5416. /* and signal '+' if outg. setup */
  5417. if(!a->AdvSignalPLCI && !tplci){
  5418. if((i=get_plci(a))) {
  5419. a->AdvSignalPLCI = &a->plci[i-1];
  5420. tplci = a->AdvSignalPLCI;
  5421. tplci->tel = ADV_VOICE;
  5422. PUT_WORD(&voice_cai[5],a->AdvSignalAppl->MaxDataLength);
  5423. if (a->Info_Mask[a->AdvSignalAppl->Id-1] & 0x200){
  5424. /* early B3 connect (CIP mask bit 9) no release after a disc */
  5425. add_p(tplci,LLI,"\x01\x01");
  5426. }
  5427. add_p(tplci, CAI, voice_cai);
  5428. add_p(tplci, OAD, a->TelOAD);
  5429. add_p(tplci, OSA, a->TelOSA);
  5430. add_p(tplci,SHIFT|6,NULL);
  5431. add_p(tplci,SIN,"\x02\x01\x00");
  5432. add_p(tplci,UID,"\x06\x43\x61\x70\x69\x32\x30");
  5433. sig_req(tplci,ASSIGN,DSIG_ID);
  5434. a->AdvSignalPLCI->internal_command = HOOK_OFF_REQ;
  5435. a->AdvSignalPLCI->command = 0;
  5436. tplci->appl = a->AdvSignalAppl;
  5437. tplci->call_dir = CALL_DIR_OUT | CALL_DIR_ORIGINATE;
  5438. send_req(tplci);
  5439. }
  5440. }
  5441. if(!tplci) break;
  5442. Id = ((word)tplci->Id<<8)|a->Id;
  5443. Id|=EXT_CONTROLLER;
  5444. sendf(tplci->appl,
  5445. _FACILITY_I,
  5446. Id,
  5447. 0,
  5448. "ws", (word)0, "\x01+");
  5449. break;
  5450. case 0x90: /* hook on */
  5451. case 0x91:
  5452. if(plci->internal_command==PERM_COD_HOOK)
  5453. {
  5454. dbug(1,dprintf("init:hook_on"));
  5455. plci->hook_state = ie[1]&0x91;
  5456. next_internal_command (Id, plci);
  5457. break;
  5458. }
  5459. else /* ignore doubled hook indications */
  5460. {
  5461. if( ((plci->hook_state)&0xf0)==0x90) break;
  5462. plci->hook_state = ie[1]&0x91;
  5463. }
  5464. /* hangup the adv. voice call and signal '-' to the appl */
  5465. if(a->AdvSignalPLCI) {
  5466. Id = ((word)a->AdvSignalPLCI->Id<<8)|a->Id;
  5467. if(plci->tel) Id|=EXT_CONTROLLER;
  5468. sendf(a->AdvSignalAppl,
  5469. _FACILITY_I,
  5470. Id,
  5471. 0,
  5472. "ws", (word)0, "\x01-");
  5473. a->AdvSignalPLCI->internal_command = HOOK_ON_REQ;
  5474. a->AdvSignalPLCI->command = 0;
  5475. sig_req(a->AdvSignalPLCI,HANGUP,0);
  5476. send_req(a->AdvSignalPLCI);
  5477. }
  5478. break;
  5479. }
  5480. }
  5481. break;
  5482. case RESUME:
  5483. clear_c_ind_mask_bit (plci, (word)(plci->appl->Id-1));
  5484. PUT_WORD(&resume_cau[4],GOOD);
  5485. sendf(plci->appl,_FACILITY_I,Id,0,"ws", (word)3, resume_cau);
  5486. break;
  5487. case SUSPEND:
  5488. clear_c_ind_mask (plci);
  5489. if (plci->NL.Id && !plci->nl_remove_id) {
  5490. mixer_remove (plci);
  5491. nl_req_ncci(plci,REMOVE,0);
  5492. }
  5493. if (!plci->sig_remove_id) {
  5494. plci->internal_command = 0;
  5495. sig_req(plci,REMOVE,0);
  5496. }
  5497. send_req(plci);
  5498. if(!plci->channels) {
  5499. sendf(plci->appl,_FACILITY_I,Id,0,"ws", (word)3, "\x05\x04\x00\x02\x00\x00");
  5500. sendf(plci->appl, _DISCONNECT_I, Id, 0, "w", 0);
  5501. }
  5502. break;
  5503. case SUSPEND_REJ:
  5504. break;
  5505. case HANGUP:
  5506. plci->hangup_flow_ctrl_timer=0;
  5507. if(plci->manufacturer && plci->State==LOCAL_CONNECT) break;
  5508. cau = parms[7];
  5509. if(cau) {
  5510. i = _L3_CAUSE | cau[2];
  5511. if(cau[2]==0) i = 0;
  5512. else if(cau[2]==8) i = _L1_ERROR;
  5513. else if(cau[2]==9 || cau[2]==10) i = _L2_ERROR;
  5514. else if(cau[2]==5) i = _CAPI_GUARD_ERROR;
  5515. }
  5516. else {
  5517. i = _L3_ERROR;
  5518. }
  5519. if(plci->State==INC_CON_PENDING || plci->State==INC_CON_ALERT)
  5520. {
  5521. for(i=0; i<max_appl; i++)
  5522. {
  5523. if(test_c_ind_mask_bit (plci, i))
  5524. sendf(&application[i], _DISCONNECT_I, Id, 0, "w", 0);
  5525. }
  5526. }
  5527. else
  5528. {
  5529. clear_c_ind_mask (plci);
  5530. }
  5531. if(!plci->appl)
  5532. {
  5533. if (plci->State == LISTENING)
  5534. {
  5535. plci->notifiedcall=0;
  5536. a->listen_active--;
  5537. }
  5538. plci->State = INC_DIS_PENDING;
  5539. if(c_ind_mask_empty (plci))
  5540. {
  5541. plci->State = IDLE;
  5542. if (plci->NL.Id && !plci->nl_remove_id)
  5543. {
  5544. mixer_remove (plci);
  5545. nl_req_ncci(plci,REMOVE,0);
  5546. }
  5547. if (!plci->sig_remove_id)
  5548. {
  5549. plci->internal_command = 0;
  5550. sig_req(plci,REMOVE,0);
  5551. }
  5552. send_req(plci);
  5553. }
  5554. }
  5555. else
  5556. {
  5557. /* collision of DISCONNECT or CONNECT_RES with HANGUP can */
  5558. /* result in a second HANGUP! Don't generate another */
  5559. /* DISCONNECT */
  5560. if(plci->State!=IDLE && plci->State!=INC_DIS_PENDING)
  5561. {
  5562. if(plci->State==RESUMING)
  5563. {
  5564. PUT_WORD(&resume_cau[4],i);
  5565. sendf(plci->appl,_FACILITY_I,Id,0,"ws", (word)3, resume_cau);
  5566. }
  5567. plci->State = INC_DIS_PENDING;
  5568. sendf(plci->appl,_DISCONNECT_I,Id,0,"w",i);
  5569. }
  5570. }
  5571. break;
  5572. case SSEXT_IND:
  5573. SendSSExtInd(NULL,plci,Id,multi_ssext_parms);
  5574. break;
  5575. case VSWITCH_REQ:
  5576. VSwitchReqInd(plci,Id,multi_vswitch_parms);
  5577. break;
  5578. case VSWITCH_IND:
  5579. if(plci->relatedPTYPLCI &&
  5580. plci->vswitchstate==3 &&
  5581. plci->relatedPTYPLCI->vswitchstate==3 &&
  5582. parms[MAXPARMSIDS-1][0])
  5583. {
  5584. add_p(plci->relatedPTYPLCI,SMSG,parms[MAXPARMSIDS-1]);
  5585. sig_req(plci->relatedPTYPLCI,VSWITCH_REQ,0);
  5586. send_req(plci->relatedPTYPLCI);
  5587. }
  5588. else VSwitchReqInd(plci,Id,multi_vswitch_parms);
  5589. break;
  5590. }
  5591. }
  5592. static void SendSetupInfo(APPL * appl, PLCI * plci, dword Id, byte * * parms, byte Info_Sent_Flag)
  5593. {
  5594. word i;
  5595. byte * ie;
  5596. word Info_Number;
  5597. byte * Info_Element;
  5598. word Info_Mask = 0;
  5599. dbug(1,dprintf("SetupInfo"));
  5600. for(i=0; i<MAXPARMSIDS; i++) {
  5601. ie = parms[i];
  5602. Info_Number = 0;
  5603. Info_Element = ie;
  5604. if(ie[0]) {
  5605. switch(i) {
  5606. case 0:
  5607. dbug(1,dprintf("CPN "));
  5608. Info_Number = 0x0070;
  5609. Info_Mask = 0x80;
  5610. Info_Sent_Flag = true;
  5611. break;
  5612. case 8: /* display */
  5613. dbug(1,dprintf("display(%d)",i));
  5614. Info_Number = 0x0028;
  5615. Info_Mask = 0x04;
  5616. Info_Sent_Flag = true;
  5617. break;
  5618. case 16: /* Channel Id */
  5619. dbug(1,dprintf("CHI"));
  5620. Info_Number = 0x0018;
  5621. Info_Mask = 0x100;
  5622. Info_Sent_Flag = true;
  5623. mixer_set_bchannel_id (plci, Info_Element);
  5624. break;
  5625. case 19: /* Redirected Number */
  5626. dbug(1,dprintf("RDN"));
  5627. Info_Number = 0x0074;
  5628. Info_Mask = 0x400;
  5629. Info_Sent_Flag = true;
  5630. break;
  5631. case 20: /* Redirected Number extended */
  5632. dbug(1,dprintf("RDX"));
  5633. Info_Number = 0x0073;
  5634. Info_Mask = 0x400;
  5635. Info_Sent_Flag = true;
  5636. break;
  5637. case 22: /* Redirecing Number */
  5638. dbug(1,dprintf("RIN"));
  5639. Info_Number = 0x0076;
  5640. Info_Mask = 0x400;
  5641. Info_Sent_Flag = true;
  5642. break;
  5643. default:
  5644. Info_Number = 0;
  5645. break;
  5646. }
  5647. }
  5648. if(i==MAXPARMSIDS-2){ /* to indicate the message type "Setup" */
  5649. Info_Number = 0x8000 |5;
  5650. Info_Mask = 0x10;
  5651. Info_Element = "";
  5652. }
  5653. if(Info_Sent_Flag && Info_Number){
  5654. if(plci->adapter->Info_Mask[appl->Id-1] & Info_Mask) {
  5655. sendf(appl,_INFO_I,Id,0,"wS",Info_Number,Info_Element);
  5656. }
  5657. }
  5658. }
  5659. }
  5660. static void SendInfo(PLCI *plci, dword Id, byte **parms, byte iesent)
  5661. {
  5662. word i;
  5663. word j;
  5664. word k;
  5665. byte * ie;
  5666. word Info_Number;
  5667. byte * Info_Element;
  5668. word Info_Mask = 0;
  5669. static byte charges[5] = {4,0,0,0,0};
  5670. static byte cause[] = {0x02,0x80,0x00};
  5671. APPL *appl;
  5672. dbug(1,dprintf("InfoParse "));
  5673. if(
  5674. !plci->appl
  5675. && !plci->State
  5676. && plci->Sig.Ind!=NCR_FACILITY
  5677. )
  5678. {
  5679. dbug(1,dprintf("NoParse "));
  5680. return;
  5681. }
  5682. cause[2] = 0;
  5683. for(i=0; i<MAXPARMSIDS; i++) {
  5684. ie = parms[i];
  5685. Info_Number = 0;
  5686. Info_Element = ie;
  5687. if(ie[0]) {
  5688. switch(i) {
  5689. case 0:
  5690. dbug(1,dprintf("CPN "));
  5691. Info_Number = 0x0070;
  5692. Info_Mask = 0x80;
  5693. break;
  5694. case 7: /* ESC_CAU */
  5695. dbug(1,dprintf("cau(0x%x)",ie[2]));
  5696. Info_Number = 0x0008;
  5697. Info_Mask = 0x00;
  5698. cause[2] = ie[2];
  5699. Info_Element = NULL;
  5700. break;
  5701. case 8: /* display */
  5702. dbug(1,dprintf("display(%d)",i));
  5703. Info_Number = 0x0028;
  5704. Info_Mask = 0x04;
  5705. break;
  5706. case 9: /* Date display */
  5707. dbug(1,dprintf("date(%d)",i));
  5708. Info_Number = 0x0029;
  5709. Info_Mask = 0x02;
  5710. break;
  5711. case 10: /* charges */
  5712. for(j=0;j<4;j++) charges[1+j] = 0;
  5713. for(j=0; j<ie[0] && !(ie[1+j]&0x80); j++);
  5714. for(k=1,j++; j<ie[0] && k<=4; j++,k++) charges[k] = ie[1+j];
  5715. Info_Number = 0x4000;
  5716. Info_Mask = 0x40;
  5717. Info_Element = charges;
  5718. break;
  5719. case 11: /* user user info */
  5720. dbug(1,dprintf("uui"));
  5721. Info_Number = 0x007E;
  5722. Info_Mask = 0x08;
  5723. break;
  5724. case 12: /* congestion receiver ready */
  5725. dbug(1,dprintf("clRDY"));
  5726. Info_Number = 0x00B0;
  5727. Info_Mask = 0x08;
  5728. Info_Element = "";
  5729. break;
  5730. case 13: /* congestion receiver not ready */
  5731. dbug(1,dprintf("clNRDY"));
  5732. Info_Number = 0x00BF;
  5733. Info_Mask = 0x08;
  5734. Info_Element = "";
  5735. break;
  5736. case 15: /* Keypad Facility */
  5737. dbug(1,dprintf("KEY"));
  5738. Info_Number = 0x002C;
  5739. Info_Mask = 0x20;
  5740. break;
  5741. case 16: /* Channel Id */
  5742. dbug(1,dprintf("CHI"));
  5743. Info_Number = 0x0018;
  5744. Info_Mask = 0x100;
  5745. mixer_set_bchannel_id (plci, Info_Element);
  5746. break;
  5747. case 17: /* if no 1tr6 cause, send full cause, else esc_cause */
  5748. dbug(1,dprintf("q9cau(0x%x)",ie[2]));
  5749. if(!cause[2] || cause[2]<0x80) break; /* eg. layer 1 error */
  5750. Info_Number = 0x0008;
  5751. Info_Mask = 0x01;
  5752. if(cause[2] != ie[2]) Info_Element = cause;
  5753. break;
  5754. case 19: /* Redirected Number */
  5755. dbug(1,dprintf("RDN"));
  5756. Info_Number = 0x0074;
  5757. Info_Mask = 0x400;
  5758. break;
  5759. case 22: /* Redirecing Number */
  5760. dbug(1,dprintf("RIN"));
  5761. Info_Number = 0x0076;
  5762. Info_Mask = 0x400;
  5763. break;
  5764. case 23: /* Notification Indicator */
  5765. dbug(1,dprintf("NI"));
  5766. Info_Number = (word)NI;
  5767. Info_Mask = 0x210;
  5768. break;
  5769. case 26: /* Call State */
  5770. dbug(1,dprintf("CST"));
  5771. Info_Number = (word)CST;
  5772. Info_Mask = 0x01; /* do with cause i.e. for now */
  5773. break;
  5774. case MAXPARMSIDS-2: /* Escape Message Type, must be the last indication */
  5775. dbug(1,dprintf("ESC/MT[0x%x]",ie[3]));
  5776. Info_Number = 0x8000 |ie[3];
  5777. if(iesent) Info_Mask = 0xffff;
  5778. else Info_Mask = 0x10;
  5779. Info_Element = "";
  5780. break;
  5781. default:
  5782. Info_Number = 0;
  5783. Info_Mask = 0;
  5784. Info_Element = "";
  5785. break;
  5786. }
  5787. }
  5788. if(plci->Sig.Ind==NCR_FACILITY) /* check controller broadcast */
  5789. {
  5790. for(j=0; j<max_appl; j++)
  5791. {
  5792. appl = &application[j];
  5793. if(Info_Number
  5794. && appl->Id
  5795. && plci->adapter->Info_Mask[appl->Id-1] &Info_Mask)
  5796. {
  5797. dbug(1,dprintf("NCR_Ind"));
  5798. iesent=true;
  5799. sendf(&application[j],_INFO_I,Id&0x0f,0,"wS",Info_Number,Info_Element);
  5800. }
  5801. }
  5802. }
  5803. else if(!plci->appl)
  5804. { /* overlap receiving broadcast */
  5805. if(Info_Number==CPN
  5806. || Info_Number==KEY
  5807. || Info_Number==NI
  5808. || Info_Number==DSP
  5809. || Info_Number==UUI )
  5810. {
  5811. for(j=0; j<max_appl; j++)
  5812. {
  5813. if(test_c_ind_mask_bit (plci, j))
  5814. {
  5815. dbug(1,dprintf("Ovl_Ind"));
  5816. iesent=true;
  5817. sendf(&application[j],_INFO_I,Id,0,"wS",Info_Number,Info_Element);
  5818. }
  5819. }
  5820. }
  5821. } /* all other signalling states */
  5822. else if(Info_Number
  5823. && plci->adapter->Info_Mask[plci->appl->Id-1] &Info_Mask)
  5824. {
  5825. dbug(1,dprintf("Std_Ind"));
  5826. iesent=true;
  5827. sendf(plci->appl,_INFO_I,Id,0,"wS",Info_Number,Info_Element);
  5828. }
  5829. }
  5830. }
  5831. static byte SendMultiIE(PLCI *plci, dword Id, byte **parms, byte ie_type,
  5832. dword info_mask, byte setupParse)
  5833. {
  5834. word i;
  5835. word j;
  5836. byte * ie;
  5837. word Info_Number;
  5838. byte * Info_Element;
  5839. APPL *appl;
  5840. word Info_Mask = 0;
  5841. byte iesent=0;
  5842. if(
  5843. !plci->appl
  5844. && !plci->State
  5845. && plci->Sig.Ind!=NCR_FACILITY
  5846. && !setupParse
  5847. )
  5848. {
  5849. dbug(1,dprintf("NoM-IEParse "));
  5850. return 0;
  5851. }
  5852. dbug(1,dprintf("M-IEParse "));
  5853. for(i=0; i<MAX_MULTI_IE; i++)
  5854. {
  5855. ie = parms[i];
  5856. Info_Number = 0;
  5857. Info_Element = ie;
  5858. if(ie[0])
  5859. {
  5860. dbug(1,dprintf("[Ind0x%x]:IE=0x%x",plci->Sig.Ind,ie_type));
  5861. Info_Number = (word)ie_type;
  5862. Info_Mask = (word)info_mask;
  5863. }
  5864. if(plci->Sig.Ind==NCR_FACILITY) /* check controller broadcast */
  5865. {
  5866. for(j=0; j<max_appl; j++)
  5867. {
  5868. appl = &application[j];
  5869. if(Info_Number
  5870. && appl->Id
  5871. && plci->adapter->Info_Mask[appl->Id-1] &Info_Mask)
  5872. {
  5873. iesent = true;
  5874. dbug(1,dprintf("Mlt_NCR_Ind"));
  5875. sendf(&application[j],_INFO_I,Id&0x0f,0,"wS",Info_Number,Info_Element);
  5876. }
  5877. }
  5878. }
  5879. else if(!plci->appl && Info_Number)
  5880. { /* overlap receiving broadcast */
  5881. for(j=0; j<max_appl; j++)
  5882. {
  5883. if(test_c_ind_mask_bit (plci, j))
  5884. {
  5885. iesent = true;
  5886. dbug(1,dprintf("Mlt_Ovl_Ind"));
  5887. sendf(&application[j],_INFO_I,Id,0,"wS",Info_Number,Info_Element);
  5888. }
  5889. }
  5890. } /* all other signalling states */
  5891. else if(Info_Number
  5892. && plci->adapter->Info_Mask[plci->appl->Id-1] &Info_Mask)
  5893. {
  5894. iesent = true;
  5895. dbug(1,dprintf("Mlt_Std_Ind"));
  5896. sendf(plci->appl,_INFO_I,Id,0,"wS",Info_Number,Info_Element);
  5897. }
  5898. }
  5899. return iesent;
  5900. }
  5901. static void SendSSExtInd(APPL * appl, PLCI * plci, dword Id, byte * * parms)
  5902. {
  5903. word i;
  5904. /* Format of multi_ssext_parms[i][]:
  5905. 0 byte length
  5906. 1 byte SSEXTIE
  5907. 2 byte SSEXT_REQ/SSEXT_IND
  5908. 3 byte length
  5909. 4 word SSExtCommand
  5910. 6... Params
  5911. */
  5912. if(
  5913. plci
  5914. && plci->State
  5915. && plci->Sig.Ind!=NCR_FACILITY
  5916. )
  5917. for(i=0;i<MAX_MULTI_IE;i++)
  5918. {
  5919. if(parms[i][0]<6) continue;
  5920. if(parms[i][2]==SSEXT_REQ) continue;
  5921. if(appl)
  5922. {
  5923. parms[i][0]=0; /* kill it */
  5924. sendf(appl,_MANUFACTURER_I,
  5925. Id,
  5926. 0,
  5927. "dwS",
  5928. _DI_MANU_ID,
  5929. _DI_SSEXT_CTRL,
  5930. &parms[i][3]);
  5931. }
  5932. else if(plci->appl)
  5933. {
  5934. parms[i][0]=0; /* kill it */
  5935. sendf(plci->appl,_MANUFACTURER_I,
  5936. Id,
  5937. 0,
  5938. "dwS",
  5939. _DI_MANU_ID,
  5940. _DI_SSEXT_CTRL,
  5941. &parms[i][3]);
  5942. }
  5943. }
  5944. };
  5945. static void nl_ind(PLCI *plci)
  5946. {
  5947. byte ch;
  5948. word ncci;
  5949. dword Id;
  5950. DIVA_CAPI_ADAPTER * a;
  5951. word NCCIcode;
  5952. APPL * APPLptr;
  5953. word count;
  5954. word Num;
  5955. word i, ncpi_state;
  5956. byte len, ncci_state;
  5957. word msg;
  5958. word info = 0;
  5959. word fax_feature_bits;
  5960. byte fax_send_edata_ack;
  5961. static byte v120_header_buffer[2 + 3];
  5962. static word fax_info[] = {
  5963. 0, /* T30_SUCCESS */
  5964. _FAX_NO_CONNECTION, /* T30_ERR_NO_DIS_RECEIVED */
  5965. _FAX_PROTOCOL_ERROR, /* T30_ERR_TIMEOUT_NO_RESPONSE */
  5966. _FAX_PROTOCOL_ERROR, /* T30_ERR_RETRY_NO_RESPONSE */
  5967. _FAX_PROTOCOL_ERROR, /* T30_ERR_TOO_MANY_REPEATS */
  5968. _FAX_PROTOCOL_ERROR, /* T30_ERR_UNEXPECTED_MESSAGE */
  5969. _FAX_REMOTE_ABORT, /* T30_ERR_UNEXPECTED_DCN */
  5970. _FAX_LOCAL_ABORT, /* T30_ERR_DTC_UNSUPPORTED */
  5971. _FAX_TRAINING_ERROR, /* T30_ERR_ALL_RATES_FAILED */
  5972. _FAX_TRAINING_ERROR, /* T30_ERR_TOO_MANY_TRAINS */
  5973. _FAX_PARAMETER_ERROR, /* T30_ERR_RECEIVE_CORRUPTED */
  5974. _FAX_REMOTE_ABORT, /* T30_ERR_UNEXPECTED_DISC */
  5975. _FAX_LOCAL_ABORT, /* T30_ERR_APPLICATION_DISC */
  5976. _FAX_REMOTE_REJECT, /* T30_ERR_INCOMPATIBLE_DIS */
  5977. _FAX_LOCAL_ABORT, /* T30_ERR_INCOMPATIBLE_DCS */
  5978. _FAX_PROTOCOL_ERROR, /* T30_ERR_TIMEOUT_NO_COMMAND */
  5979. _FAX_PROTOCOL_ERROR, /* T30_ERR_RETRY_NO_COMMAND */
  5980. _FAX_PROTOCOL_ERROR, /* T30_ERR_TIMEOUT_COMMAND_TOO_LONG */
  5981. _FAX_PROTOCOL_ERROR, /* T30_ERR_TIMEOUT_RESPONSE_TOO_LONG */
  5982. _FAX_NO_CONNECTION, /* T30_ERR_NOT_IDENTIFIED */
  5983. _FAX_PROTOCOL_ERROR, /* T30_ERR_SUPERVISORY_TIMEOUT */
  5984. _FAX_PARAMETER_ERROR, /* T30_ERR_TOO_LONG_SCAN_LINE */
  5985. _FAX_PROTOCOL_ERROR, /* T30_ERR_RETRY_NO_PAGE_AFTER_MPS */
  5986. _FAX_PROTOCOL_ERROR, /* T30_ERR_RETRY_NO_PAGE_AFTER_CFR */
  5987. _FAX_PROTOCOL_ERROR, /* T30_ERR_RETRY_NO_DCS_AFTER_FTT */
  5988. _FAX_PROTOCOL_ERROR, /* T30_ERR_RETRY_NO_DCS_AFTER_EOM */
  5989. _FAX_PROTOCOL_ERROR, /* T30_ERR_RETRY_NO_DCS_AFTER_MPS */
  5990. _FAX_PROTOCOL_ERROR, /* T30_ERR_RETRY_NO_DCN_AFTER_MCF */
  5991. _FAX_PROTOCOL_ERROR, /* T30_ERR_RETRY_NO_DCN_AFTER_RTN */
  5992. _FAX_PROTOCOL_ERROR, /* T30_ERR_RETRY_NO_CFR */
  5993. _FAX_PROTOCOL_ERROR, /* T30_ERR_RETRY_NO_MCF_AFTER_EOP */
  5994. _FAX_PROTOCOL_ERROR, /* T30_ERR_RETRY_NO_MCF_AFTER_EOM */
  5995. _FAX_PROTOCOL_ERROR, /* T30_ERR_RETRY_NO_MCF_AFTER_MPS */
  5996. 0x331d, /* T30_ERR_SUB_SEP_UNSUPPORTED */
  5997. 0x331e, /* T30_ERR_PWD_UNSUPPORTED */
  5998. 0x331f, /* T30_ERR_SUB_SEP_PWD_UNSUPPORTED */
  5999. _FAX_PROTOCOL_ERROR, /* T30_ERR_INVALID_COMMAND_FRAME */
  6000. _FAX_PARAMETER_ERROR, /* T30_ERR_UNSUPPORTED_PAGE_CODING */
  6001. _FAX_PARAMETER_ERROR, /* T30_ERR_INVALID_PAGE_CODING */
  6002. _FAX_REMOTE_REJECT, /* T30_ERR_INCOMPATIBLE_PAGE_CONFIG */
  6003. _FAX_LOCAL_ABORT, /* T30_ERR_TIMEOUT_FROM_APPLICATION */
  6004. _FAX_PROTOCOL_ERROR, /* T30_ERR_V34FAX_NO_REACTION_ON_MARK */
  6005. _FAX_PROTOCOL_ERROR, /* T30_ERR_V34FAX_TRAINING_TIMEOUT */
  6006. _FAX_PROTOCOL_ERROR, /* T30_ERR_V34FAX_UNEXPECTED_V21 */
  6007. _FAX_PROTOCOL_ERROR, /* T30_ERR_V34FAX_PRIMARY_CTS_ON */
  6008. _FAX_LOCAL_ABORT, /* T30_ERR_V34FAX_TURNAROUND_POLLING */
  6009. _FAX_LOCAL_ABORT /* T30_ERR_V34FAX_V8_INCOMPATIBILITY */
  6010. };
  6011. byte dtmf_code_buffer[CAPIDTMF_RECV_DIGIT_BUFFER_SIZE + 1];
  6012. static word rtp_info[] = {
  6013. GOOD, /* RTP_SUCCESS */
  6014. 0x3600 /* RTP_ERR_SSRC_OR_PAYLOAD_CHANGE */
  6015. };
  6016. static dword udata_forwarding_table[0x100 / sizeof(dword)] =
  6017. {
  6018. 0x0020301e, 0x00000000, 0x00000000, 0x00000000,
  6019. 0x00000000, 0x00000000, 0x00000000, 0x00000000
  6020. };
  6021. ch = plci->NL.IndCh;
  6022. a = plci->adapter;
  6023. ncci = a->ch_ncci[ch];
  6024. Id = (((dword)(ncci ? ncci : ch)) << 16) | (((word) plci->Id) << 8) | a->Id;
  6025. if(plci->tel) Id|=EXT_CONTROLLER;
  6026. APPLptr = plci->appl;
  6027. dbug(1,dprintf("NL_IND-Id(NL:0x%x)=0x%08lx,plci=%x,tel=%x,state=0x%x,ch=0x%x,chs=%d,Ind=%x",
  6028. plci->NL.Id,Id,plci->Id,plci->tel,plci->State,ch,plci->channels,plci->NL.Ind &0x0f));
  6029. /* in the case if no connect_active_Ind was sent to the appl we wait for */
  6030. if (plci->nl_remove_id)
  6031. {
  6032. plci->NL.RNR = 2; /* discard */
  6033. dbug(1,dprintf("NL discard while remove pending"));
  6034. return;
  6035. }
  6036. if((plci->NL.Ind &0x0f)==N_CONNECT)
  6037. {
  6038. if(plci->State==INC_DIS_PENDING
  6039. || plci->State==OUTG_DIS_PENDING
  6040. || plci->State==IDLE)
  6041. {
  6042. plci->NL.RNR = 2; /* discard */
  6043. dbug(1,dprintf("discard n_connect"));
  6044. return;
  6045. }
  6046. if(plci->State < INC_ACT_PENDING)
  6047. {
  6048. plci->NL.RNR = 1; /* flow control */
  6049. channel_x_off (plci, ch, N_XON_CONNECT_IND);
  6050. return;
  6051. }
  6052. }
  6053. if(!APPLptr) /* no application or invalid data */
  6054. { /* while reloading the DSP */
  6055. dbug(1,dprintf("discard1"));
  6056. plci->NL.RNR = 2;
  6057. return;
  6058. }
  6059. if (((plci->NL.Ind &0x0f) == N_UDATA)
  6060. && (((plci->B2_prot != B2_SDLC) && ((plci->B1_resource == 17) || (plci->B1_resource == 18)))
  6061. || (plci->B2_prot == 7)
  6062. || (plci->B3_prot == 7)) )
  6063. {
  6064. plci->ncpi_buffer[0] = 0;
  6065. ncpi_state = plci->ncpi_state;
  6066. if (plci->NL.complete == 1)
  6067. {
  6068. byte * data = &plci->NL.RBuffer->P[0];
  6069. if ((plci->NL.RBuffer->length >= 12)
  6070. &&( (*data == DSP_UDATA_INDICATION_DCD_ON)
  6071. ||(*data == DSP_UDATA_INDICATION_CTS_ON)) )
  6072. {
  6073. word conn_opt, ncpi_opt = 0x00;
  6074. /* HexDump ("MDM N_UDATA:", plci->NL.RBuffer->length, data); */
  6075. if (*data == DSP_UDATA_INDICATION_DCD_ON)
  6076. plci->ncpi_state |= NCPI_MDM_DCD_ON_RECEIVED;
  6077. if (*data == DSP_UDATA_INDICATION_CTS_ON)
  6078. plci->ncpi_state |= NCPI_MDM_CTS_ON_RECEIVED;
  6079. data++; /* indication code */
  6080. data += 2; /* timestamp */
  6081. if ((*data == DSP_CONNECTED_NORM_V18) || (*data == DSP_CONNECTED_NORM_VOWN))
  6082. ncpi_state &= ~(NCPI_MDM_DCD_ON_RECEIVED | NCPI_MDM_CTS_ON_RECEIVED);
  6083. data++; /* connected norm */
  6084. conn_opt = GET_WORD(data);
  6085. data += 2; /* connected options */
  6086. PUT_WORD (&(plci->ncpi_buffer[1]), (word)(GET_DWORD(data) & 0x0000FFFF));
  6087. if (conn_opt & DSP_CONNECTED_OPTION_MASK_V42)
  6088. {
  6089. ncpi_opt |= MDM_NCPI_ECM_V42;
  6090. }
  6091. else if (conn_opt & DSP_CONNECTED_OPTION_MASK_MNP)
  6092. {
  6093. ncpi_opt |= MDM_NCPI_ECM_MNP;
  6094. }
  6095. else
  6096. {
  6097. ncpi_opt |= MDM_NCPI_TRANSPARENT;
  6098. }
  6099. if (conn_opt & DSP_CONNECTED_OPTION_MASK_COMPRESSION)
  6100. {
  6101. ncpi_opt |= MDM_NCPI_COMPRESSED;
  6102. }
  6103. PUT_WORD (&(plci->ncpi_buffer[3]), ncpi_opt);
  6104. plci->ncpi_buffer[0] = 4;
  6105. plci->ncpi_state |= NCPI_VALID_CONNECT_B3_IND | NCPI_VALID_CONNECT_B3_ACT | NCPI_VALID_DISC_B3_IND;
  6106. }
  6107. }
  6108. if (plci->B3_prot == 7)
  6109. {
  6110. if (((a->ncci_state[ncci] == INC_ACT_PENDING) || (a->ncci_state[ncci] == OUTG_CON_PENDING))
  6111. && (plci->ncpi_state & NCPI_VALID_CONNECT_B3_ACT)
  6112. && !(plci->ncpi_state & NCPI_CONNECT_B3_ACT_SENT))
  6113. {
  6114. a->ncci_state[ncci] = INC_ACT_PENDING;
  6115. sendf(plci->appl,_CONNECT_B3_ACTIVE_I,Id,0,"S",plci->ncpi_buffer);
  6116. plci->ncpi_state |= NCPI_CONNECT_B3_ACT_SENT;
  6117. }
  6118. }
  6119. if (!((plci->requested_options_conn | plci->requested_options | plci->adapter->requested_options_table[plci->appl->Id-1])
  6120. & ((1L << PRIVATE_V18) | (1L << PRIVATE_VOWN)))
  6121. || !(ncpi_state & NCPI_MDM_DCD_ON_RECEIVED)
  6122. || !(ncpi_state & NCPI_MDM_CTS_ON_RECEIVED))
  6123. {
  6124. plci->NL.RNR = 2;
  6125. return;
  6126. }
  6127. }
  6128. if(plci->NL.complete == 2)
  6129. {
  6130. if (((plci->NL.Ind &0x0f) == N_UDATA)
  6131. && !(udata_forwarding_table[plci->RData[0].P[0] >> 5] & (1L << (plci->RData[0].P[0] & 0x1f))))
  6132. {
  6133. switch(plci->RData[0].P[0])
  6134. {
  6135. case DTMF_UDATA_INDICATION_FAX_CALLING_TONE:
  6136. if (plci->dtmf_rec_active & DTMF_LISTEN_ACTIVE_FLAG)
  6137. sendf(plci->appl, _FACILITY_I, Id & 0xffffL, 0,"ws", SELECTOR_DTMF, "\x01X");
  6138. break;
  6139. case DTMF_UDATA_INDICATION_ANSWER_TONE:
  6140. if (plci->dtmf_rec_active & DTMF_LISTEN_ACTIVE_FLAG)
  6141. sendf(plci->appl, _FACILITY_I, Id & 0xffffL, 0,"ws", SELECTOR_DTMF, "\x01Y");
  6142. break;
  6143. case DTMF_UDATA_INDICATION_DIGITS_RECEIVED:
  6144. dtmf_indication (Id, plci, plci->RData[0].P, plci->RData[0].PLength);
  6145. break;
  6146. case DTMF_UDATA_INDICATION_DIGITS_SENT:
  6147. dtmf_confirmation (Id, plci);
  6148. break;
  6149. case UDATA_INDICATION_MIXER_TAP_DATA:
  6150. capidtmf_recv_process_block (&(plci->capidtmf_state), plci->RData[0].P + 1, (word)(plci->RData[0].PLength - 1));
  6151. i = capidtmf_indication (&(plci->capidtmf_state), dtmf_code_buffer + 1);
  6152. if (i != 0)
  6153. {
  6154. dtmf_code_buffer[0] = DTMF_UDATA_INDICATION_DIGITS_RECEIVED;
  6155. dtmf_indication (Id, plci, dtmf_code_buffer, (word)(i + 1));
  6156. }
  6157. break;
  6158. case UDATA_INDICATION_MIXER_COEFS_SET:
  6159. mixer_indication_coefs_set (Id, plci);
  6160. break;
  6161. case UDATA_INDICATION_XCONNECT_FROM:
  6162. mixer_indication_xconnect_from (Id, plci, plci->RData[0].P, plci->RData[0].PLength);
  6163. break;
  6164. case UDATA_INDICATION_XCONNECT_TO:
  6165. mixer_indication_xconnect_to (Id, plci, plci->RData[0].P, plci->RData[0].PLength);
  6166. break;
  6167. case LEC_UDATA_INDICATION_DISABLE_DETECT:
  6168. ec_indication (Id, plci, plci->RData[0].P, plci->RData[0].PLength);
  6169. break;
  6170. default:
  6171. break;
  6172. }
  6173. }
  6174. else
  6175. {
  6176. if ((plci->RData[0].PLength != 0)
  6177. && ((plci->B2_prot == B2_V120_ASYNC)
  6178. || (plci->B2_prot == B2_V120_ASYNC_V42BIS)
  6179. || (plci->B2_prot == B2_V120_BIT_TRANSPARENT)))
  6180. {
  6181. sendf(plci->appl,_DATA_B3_I,Id,0,
  6182. "dwww",
  6183. plci->RData[1].P,
  6184. (plci->NL.RNum < 2) ? 0 : plci->RData[1].PLength,
  6185. plci->RNum,
  6186. plci->RFlags);
  6187. }
  6188. else
  6189. {
  6190. sendf(plci->appl,_DATA_B3_I,Id,0,
  6191. "dwww",
  6192. plci->RData[0].P,
  6193. plci->RData[0].PLength,
  6194. plci->RNum,
  6195. plci->RFlags);
  6196. }
  6197. }
  6198. return;
  6199. }
  6200. fax_feature_bits = 0;
  6201. if((plci->NL.Ind &0x0f)==N_CONNECT ||
  6202. (plci->NL.Ind &0x0f)==N_CONNECT_ACK ||
  6203. (plci->NL.Ind &0x0f)==N_DISC ||
  6204. (plci->NL.Ind &0x0f)==N_EDATA ||
  6205. (plci->NL.Ind &0x0f)==N_DISC_ACK)
  6206. {
  6207. info = 0;
  6208. plci->ncpi_buffer[0] = 0;
  6209. switch (plci->B3_prot) {
  6210. case 0: /*XPARENT*/
  6211. case 1: /*T.90 NL*/
  6212. break; /* no network control protocol info - jfr */
  6213. case 2: /*ISO8202*/
  6214. case 3: /*X25 DCE*/
  6215. for(i=0; i<plci->NL.RLength; i++) plci->ncpi_buffer[4+i] = plci->NL.RBuffer->P[i];
  6216. plci->ncpi_buffer[0] = (byte)(i+3);
  6217. plci->ncpi_buffer[1] = (byte)(plci->NL.Ind &N_D_BIT? 1:0);
  6218. plci->ncpi_buffer[2] = 0;
  6219. plci->ncpi_buffer[3] = 0;
  6220. break;
  6221. case 4: /*T.30 - FAX*/
  6222. case 5: /*T.30 - FAX*/
  6223. if(plci->NL.RLength>=sizeof(T30_INFO))
  6224. {
  6225. dbug(1,dprintf("FaxStatus %04x", ((T30_INFO *)plci->NL.RBuffer->P)->code));
  6226. len = 9;
  6227. PUT_WORD(&(plci->ncpi_buffer[1]),((T30_INFO *)plci->NL.RBuffer->P)->rate_div_2400 * 2400);
  6228. fax_feature_bits = GET_WORD(&((T30_INFO *)plci->NL.RBuffer->P)->feature_bits_low);
  6229. i = (((T30_INFO *)plci->NL.RBuffer->P)->resolution & T30_RESOLUTION_R8_0770_OR_200) ? 0x0001 : 0x0000;
  6230. if (plci->B3_prot == 5)
  6231. {
  6232. if (!(fax_feature_bits & T30_FEATURE_BIT_ECM))
  6233. i |= 0x8000; /* This is not an ECM connection */
  6234. if (fax_feature_bits & T30_FEATURE_BIT_T6_CODING)
  6235. i |= 0x4000; /* This is a connection with MMR compression */
  6236. if (fax_feature_bits & T30_FEATURE_BIT_2D_CODING)
  6237. i |= 0x2000; /* This is a connection with MR compression */
  6238. if (fax_feature_bits & T30_FEATURE_BIT_MORE_DOCUMENTS)
  6239. i |= 0x0004; /* More documents */
  6240. if (fax_feature_bits & T30_FEATURE_BIT_POLLING)
  6241. i |= 0x0002; /* Fax-polling indication */
  6242. }
  6243. dbug(1,dprintf("FAX Options %04x %04x",fax_feature_bits,i));
  6244. PUT_WORD(&(plci->ncpi_buffer[3]),i);
  6245. PUT_WORD(&(plci->ncpi_buffer[5]),((T30_INFO *)plci->NL.RBuffer->P)->data_format);
  6246. plci->ncpi_buffer[7] = ((T30_INFO *)plci->NL.RBuffer->P)->pages_low;
  6247. plci->ncpi_buffer[8] = ((T30_INFO *)plci->NL.RBuffer->P)->pages_high;
  6248. plci->ncpi_buffer[len] = 0;
  6249. if(((T30_INFO *)plci->NL.RBuffer->P)->station_id_len)
  6250. {
  6251. plci->ncpi_buffer[len] = 20;
  6252. for (i = 0; i < 20; i++)
  6253. plci->ncpi_buffer[++len] = ((T30_INFO *)plci->NL.RBuffer->P)->station_id[i];
  6254. }
  6255. if (((plci->NL.Ind & 0x0f) == N_DISC) || ((plci->NL.Ind & 0x0f) == N_DISC_ACK))
  6256. {
  6257. if (((T30_INFO *)plci->NL.RBuffer->P)->code < ARRAY_SIZE(fax_info))
  6258. info = fax_info[((T30_INFO *)plci->NL.RBuffer->P)->code];
  6259. else
  6260. info = _FAX_PROTOCOL_ERROR;
  6261. }
  6262. if ((plci->requested_options_conn | plci->requested_options | a->requested_options_table[plci->appl->Id-1])
  6263. & ((1L << PRIVATE_FAX_SUB_SEP_PWD) | (1L << PRIVATE_FAX_NONSTANDARD)))
  6264. {
  6265. i = ((word)(((T30_INFO *) 0)->station_id + 20)) + ((T30_INFO *)plci->NL.RBuffer->P)->head_line_len;
  6266. while (i < plci->NL.RBuffer->length)
  6267. plci->ncpi_buffer[++len] = plci->NL.RBuffer->P[i++];
  6268. }
  6269. plci->ncpi_buffer[0] = len;
  6270. fax_feature_bits = GET_WORD(&((T30_INFO *)plci->NL.RBuffer->P)->feature_bits_low);
  6271. PUT_WORD(&((T30_INFO *)plci->fax_connect_info_buffer)->feature_bits_low, fax_feature_bits);
  6272. plci->ncpi_state |= NCPI_VALID_CONNECT_B3_IND;
  6273. if (((plci->NL.Ind &0x0f) == N_CONNECT_ACK)
  6274. || (((plci->NL.Ind &0x0f) == N_CONNECT)
  6275. && (fax_feature_bits & T30_FEATURE_BIT_POLLING))
  6276. || (((plci->NL.Ind &0x0f) == N_EDATA)
  6277. && ((((T30_INFO *)plci->NL.RBuffer->P)->code == EDATA_T30_TRAIN_OK)
  6278. || (((T30_INFO *)plci->NL.RBuffer->P)->code == EDATA_T30_DIS)
  6279. || (((T30_INFO *)plci->NL.RBuffer->P)->code == EDATA_T30_DTC))))
  6280. {
  6281. plci->ncpi_state |= NCPI_VALID_CONNECT_B3_ACT;
  6282. }
  6283. if (((plci->NL.Ind &0x0f) == N_DISC)
  6284. || ((plci->NL.Ind &0x0f) == N_DISC_ACK)
  6285. || (((plci->NL.Ind &0x0f) == N_EDATA)
  6286. && (((T30_INFO *)plci->NL.RBuffer->P)->code == EDATA_T30_EOP_CAPI)))
  6287. {
  6288. plci->ncpi_state |= NCPI_VALID_CONNECT_B3_ACT | NCPI_VALID_DISC_B3_IND;
  6289. }
  6290. }
  6291. break;
  6292. case B3_RTP:
  6293. if (((plci->NL.Ind & 0x0f) == N_DISC) || ((plci->NL.Ind & 0x0f) == N_DISC_ACK))
  6294. {
  6295. if (plci->NL.RLength != 0)
  6296. {
  6297. info = rtp_info[plci->NL.RBuffer->P[0]];
  6298. plci->ncpi_buffer[0] = plci->NL.RLength - 1;
  6299. for (i = 1; i < plci->NL.RLength; i++)
  6300. plci->ncpi_buffer[i] = plci->NL.RBuffer->P[i];
  6301. }
  6302. }
  6303. break;
  6304. }
  6305. plci->NL.RNR = 2;
  6306. }
  6307. switch(plci->NL.Ind &0x0f) {
  6308. case N_EDATA:
  6309. if ((plci->B3_prot == 4) || (plci->B3_prot == 5))
  6310. {
  6311. dbug(1,dprintf("EDATA ncci=0x%x state=%d code=%02x", ncci, a->ncci_state[ncci],
  6312. ((T30_INFO *)plci->NL.RBuffer->P)->code));
  6313. fax_send_edata_ack = (((T30_INFO *)(plci->fax_connect_info_buffer))->operating_mode == T30_OPERATING_MODE_CAPI_NEG);
  6314. if ((plci->nsf_control_bits & T30_NSF_CONTROL_BIT_ENABLE_NSF)
  6315. && (plci->nsf_control_bits & (T30_NSF_CONTROL_BIT_NEGOTIATE_IND | T30_NSF_CONTROL_BIT_NEGOTIATE_RESP))
  6316. && (((T30_INFO *)plci->NL.RBuffer->P)->code == EDATA_T30_DIS)
  6317. && (a->ncci_state[ncci] == OUTG_CON_PENDING)
  6318. && (plci->ncpi_state & NCPI_VALID_CONNECT_B3_ACT)
  6319. && !(plci->ncpi_state & NCPI_NEGOTIATE_B3_SENT))
  6320. {
  6321. ((T30_INFO *)(plci->fax_connect_info_buffer))->code = ((T30_INFO *)plci->NL.RBuffer->P)->code;
  6322. sendf(plci->appl,_MANUFACTURER_I,Id,0,"dwbS",_DI_MANU_ID,_DI_NEGOTIATE_B3,
  6323. (byte)(plci->ncpi_buffer[0] + 1), plci->ncpi_buffer);
  6324. plci->ncpi_state |= NCPI_NEGOTIATE_B3_SENT;
  6325. if (plci->nsf_control_bits & T30_NSF_CONTROL_BIT_NEGOTIATE_RESP)
  6326. fax_send_edata_ack = false;
  6327. }
  6328. if (a->manufacturer_features & MANUFACTURER_FEATURE_FAX_PAPER_FORMATS)
  6329. {
  6330. switch (((T30_INFO *)plci->NL.RBuffer->P)->code)
  6331. {
  6332. case EDATA_T30_DIS:
  6333. if ((a->ncci_state[ncci] == OUTG_CON_PENDING)
  6334. && !(GET_WORD(&((T30_INFO *)plci->fax_connect_info_buffer)->control_bits_low) & T30_CONTROL_BIT_REQUEST_POLLING)
  6335. && (plci->ncpi_state & NCPI_VALID_CONNECT_B3_ACT)
  6336. && !(plci->ncpi_state & NCPI_CONNECT_B3_ACT_SENT))
  6337. {
  6338. a->ncci_state[ncci] = INC_ACT_PENDING;
  6339. if (plci->B3_prot == 4)
  6340. sendf(plci->appl,_CONNECT_B3_ACTIVE_I,Id,0,"s","");
  6341. else
  6342. sendf(plci->appl,_CONNECT_B3_ACTIVE_I,Id,0,"S",plci->ncpi_buffer);
  6343. plci->ncpi_state |= NCPI_CONNECT_B3_ACT_SENT;
  6344. }
  6345. break;
  6346. case EDATA_T30_TRAIN_OK:
  6347. if ((a->ncci_state[ncci] == INC_ACT_PENDING)
  6348. && (plci->ncpi_state & NCPI_VALID_CONNECT_B3_ACT)
  6349. && !(plci->ncpi_state & NCPI_CONNECT_B3_ACT_SENT))
  6350. {
  6351. if (plci->B3_prot == 4)
  6352. sendf(plci->appl,_CONNECT_B3_ACTIVE_I,Id,0,"s","");
  6353. else
  6354. sendf(plci->appl,_CONNECT_B3_ACTIVE_I,Id,0,"S",plci->ncpi_buffer);
  6355. plci->ncpi_state |= NCPI_CONNECT_B3_ACT_SENT;
  6356. }
  6357. break;
  6358. case EDATA_T30_EOP_CAPI:
  6359. if (a->ncci_state[ncci] == CONNECTED)
  6360. {
  6361. sendf(plci->appl,_DISCONNECT_B3_I,Id,0,"wS",GOOD,plci->ncpi_buffer);
  6362. a->ncci_state[ncci] = INC_DIS_PENDING;
  6363. plci->ncpi_state = 0;
  6364. fax_send_edata_ack = false;
  6365. }
  6366. break;
  6367. }
  6368. }
  6369. else
  6370. {
  6371. switch (((T30_INFO *)plci->NL.RBuffer->P)->code)
  6372. {
  6373. case EDATA_T30_TRAIN_OK:
  6374. if ((a->ncci_state[ncci] == INC_ACT_PENDING)
  6375. && (plci->ncpi_state & NCPI_VALID_CONNECT_B3_ACT)
  6376. && !(plci->ncpi_state & NCPI_CONNECT_B3_ACT_SENT))
  6377. {
  6378. if (plci->B3_prot == 4)
  6379. sendf(plci->appl,_CONNECT_B3_ACTIVE_I,Id,0,"s","");
  6380. else
  6381. sendf(plci->appl,_CONNECT_B3_ACTIVE_I,Id,0,"S",plci->ncpi_buffer);
  6382. plci->ncpi_state |= NCPI_CONNECT_B3_ACT_SENT;
  6383. }
  6384. break;
  6385. }
  6386. }
  6387. if (fax_send_edata_ack)
  6388. {
  6389. ((T30_INFO *)(plci->fax_connect_info_buffer))->code = ((T30_INFO *)plci->NL.RBuffer->P)->code;
  6390. plci->fax_edata_ack_length = 1;
  6391. start_internal_command (Id, plci, fax_edata_ack_command);
  6392. }
  6393. }
  6394. else
  6395. {
  6396. dbug(1,dprintf("EDATA ncci=0x%x state=%d", ncci, a->ncci_state[ncci]));
  6397. }
  6398. break;
  6399. case N_CONNECT:
  6400. if (!a->ch_ncci[ch])
  6401. {
  6402. ncci = get_ncci (plci, ch, 0);
  6403. Id = (Id & 0xffff) | (((dword) ncci) << 16);
  6404. }
  6405. dbug(1,dprintf("N_CONNECT: ch=%d state=%d plci=%lx plci_Id=%lx plci_State=%d",
  6406. ch, a->ncci_state[ncci], a->ncci_plci[ncci], plci->Id, plci->State));
  6407. msg = _CONNECT_B3_I;
  6408. if (a->ncci_state[ncci] == IDLE)
  6409. plci->channels++;
  6410. else if (plci->B3_prot == 1)
  6411. msg = _CONNECT_B3_T90_ACTIVE_I;
  6412. a->ncci_state[ncci] = INC_CON_PENDING;
  6413. if(plci->B3_prot == 4)
  6414. sendf(plci->appl,msg,Id,0,"s","");
  6415. else
  6416. sendf(plci->appl,msg,Id,0,"S",plci->ncpi_buffer);
  6417. break;
  6418. case N_CONNECT_ACK:
  6419. dbug(1,dprintf("N_connect_Ack"));
  6420. if (plci->internal_command_queue[0]
  6421. && ((plci->adjust_b_state == ADJUST_B_CONNECT_2)
  6422. || (plci->adjust_b_state == ADJUST_B_CONNECT_3)
  6423. || (plci->adjust_b_state == ADJUST_B_CONNECT_4)))
  6424. {
  6425. (*(plci->internal_command_queue[0]))(Id, plci, 0);
  6426. if (!plci->internal_command)
  6427. next_internal_command (Id, plci);
  6428. break;
  6429. }
  6430. msg = _CONNECT_B3_ACTIVE_I;
  6431. if (plci->B3_prot == 1)
  6432. {
  6433. if (a->ncci_state[ncci] != OUTG_CON_PENDING)
  6434. msg = _CONNECT_B3_T90_ACTIVE_I;
  6435. a->ncci_state[ncci] = INC_ACT_PENDING;
  6436. sendf(plci->appl,msg,Id,0,"S",plci->ncpi_buffer);
  6437. }
  6438. else if ((plci->B3_prot == 4) || (plci->B3_prot == 5) || (plci->B3_prot == 7))
  6439. {
  6440. if ((a->ncci_state[ncci] == OUTG_CON_PENDING)
  6441. && (plci->ncpi_state & NCPI_VALID_CONNECT_B3_ACT)
  6442. && !(plci->ncpi_state & NCPI_CONNECT_B3_ACT_SENT))
  6443. {
  6444. a->ncci_state[ncci] = INC_ACT_PENDING;
  6445. if (plci->B3_prot == 4)
  6446. sendf(plci->appl,msg,Id,0,"s","");
  6447. else
  6448. sendf(plci->appl,msg,Id,0,"S",plci->ncpi_buffer);
  6449. plci->ncpi_state |= NCPI_CONNECT_B3_ACT_SENT;
  6450. }
  6451. }
  6452. else
  6453. {
  6454. a->ncci_state[ncci] = INC_ACT_PENDING;
  6455. sendf(plci->appl,msg,Id,0,"S",plci->ncpi_buffer);
  6456. }
  6457. if (plci->adjust_b_restore)
  6458. {
  6459. plci->adjust_b_restore = false;
  6460. start_internal_command (Id, plci, adjust_b_restore);
  6461. }
  6462. break;
  6463. case N_DISC:
  6464. case N_DISC_ACK:
  6465. if (plci->internal_command_queue[0]
  6466. && ((plci->internal_command == FAX_DISCONNECT_COMMAND_1)
  6467. || (plci->internal_command == FAX_DISCONNECT_COMMAND_2)
  6468. || (plci->internal_command == FAX_DISCONNECT_COMMAND_3)))
  6469. {
  6470. (*(plci->internal_command_queue[0]))(Id, plci, 0);
  6471. if (!plci->internal_command)
  6472. next_internal_command (Id, plci);
  6473. }
  6474. ncci_state = a->ncci_state[ncci];
  6475. ncci_remove (plci, ncci, false);
  6476. /* with N_DISC or N_DISC_ACK the IDI frees the respective */
  6477. /* channel, so we cannot store the state in ncci_state! The */
  6478. /* information which channel we received a N_DISC is thus */
  6479. /* stored in the inc_dis_ncci_table buffer. */
  6480. for(i=0; plci->inc_dis_ncci_table[i]; i++);
  6481. plci->inc_dis_ncci_table[i] = (byte) ncci;
  6482. /* need a connect_b3_ind before a disconnect_b3_ind with FAX */
  6483. if (!plci->channels
  6484. && (plci->B1_resource == 16)
  6485. && (plci->State <= CONNECTED))
  6486. {
  6487. len = 9;
  6488. i = ((T30_INFO *)plci->fax_connect_info_buffer)->rate_div_2400 * 2400;
  6489. PUT_WORD (&plci->ncpi_buffer[1], i);
  6490. PUT_WORD (&plci->ncpi_buffer[3], 0);
  6491. i = ((T30_INFO *)plci->fax_connect_info_buffer)->data_format;
  6492. PUT_WORD (&plci->ncpi_buffer[5], i);
  6493. PUT_WORD (&plci->ncpi_buffer[7], 0);
  6494. plci->ncpi_buffer[len] = 0;
  6495. plci->ncpi_buffer[0] = len;
  6496. if(plci->B3_prot == 4)
  6497. sendf(plci->appl,_CONNECT_B3_I,Id,0,"s","");
  6498. else
  6499. {
  6500. if ((plci->requested_options_conn | plci->requested_options | a->requested_options_table[plci->appl->Id-1])
  6501. & ((1L << PRIVATE_FAX_SUB_SEP_PWD) | (1L << PRIVATE_FAX_NONSTANDARD)))
  6502. {
  6503. plci->ncpi_buffer[++len] = 0;
  6504. plci->ncpi_buffer[++len] = 0;
  6505. plci->ncpi_buffer[++len] = 0;
  6506. plci->ncpi_buffer[0] = len;
  6507. }
  6508. sendf(plci->appl,_CONNECT_B3_I,Id,0,"S",plci->ncpi_buffer);
  6509. }
  6510. sendf(plci->appl,_DISCONNECT_B3_I,Id,0,"wS",info,plci->ncpi_buffer);
  6511. plci->ncpi_state = 0;
  6512. sig_req(plci,HANGUP,0);
  6513. send_req(plci);
  6514. plci->State = OUTG_DIS_PENDING;
  6515. /* disc here */
  6516. }
  6517. else if ((a->manufacturer_features & MANUFACTURER_FEATURE_FAX_PAPER_FORMATS)
  6518. && ((plci->B3_prot == 4) || (plci->B3_prot == 5))
  6519. && ((ncci_state == INC_DIS_PENDING) || (ncci_state == IDLE)))
  6520. {
  6521. if (ncci_state == IDLE)
  6522. {
  6523. if (plci->channels)
  6524. plci->channels--;
  6525. if((plci->State==IDLE || plci->State==SUSPENDING) && !plci->channels){
  6526. if(plci->State == SUSPENDING){
  6527. sendf(plci->appl,
  6528. _FACILITY_I,
  6529. Id & 0xffffL,
  6530. 0,
  6531. "ws", (word)3, "\x03\x04\x00\x00");
  6532. sendf(plci->appl, _DISCONNECT_I, Id & 0xffffL, 0, "w", 0);
  6533. }
  6534. plci_remove(plci);
  6535. plci->State=IDLE;
  6536. }
  6537. }
  6538. }
  6539. else if (plci->channels)
  6540. {
  6541. sendf(plci->appl,_DISCONNECT_B3_I,Id,0,"wS",info,plci->ncpi_buffer);
  6542. plci->ncpi_state = 0;
  6543. if ((ncci_state == OUTG_REJ_PENDING)
  6544. && ((plci->B3_prot != B3_T90NL) && (plci->B3_prot != B3_ISO8208) && (plci->B3_prot != B3_X25_DCE)))
  6545. {
  6546. sig_req(plci,HANGUP,0);
  6547. send_req(plci);
  6548. plci->State = OUTG_DIS_PENDING;
  6549. }
  6550. }
  6551. break;
  6552. case N_RESET:
  6553. a->ncci_state[ncci] = INC_RES_PENDING;
  6554. sendf(plci->appl,_RESET_B3_I,Id,0,"S",plci->ncpi_buffer);
  6555. break;
  6556. case N_RESET_ACK:
  6557. a->ncci_state[ncci] = CONNECTED;
  6558. sendf(plci->appl,_RESET_B3_I,Id,0,"S",plci->ncpi_buffer);
  6559. break;
  6560. case N_UDATA:
  6561. if (!(udata_forwarding_table[plci->NL.RBuffer->P[0] >> 5] & (1L << (plci->NL.RBuffer->P[0] & 0x1f))))
  6562. {
  6563. plci->RData[0].P = plci->internal_ind_buffer + (-((int)(long)(plci->internal_ind_buffer)) & 3);
  6564. plci->RData[0].PLength = INTERNAL_IND_BUFFER_SIZE;
  6565. plci->NL.R = plci->RData;
  6566. plci->NL.RNum = 1;
  6567. return;
  6568. }
  6569. case N_BDATA:
  6570. case N_DATA:
  6571. if (((a->ncci_state[ncci] != CONNECTED) && (plci->B2_prot == 1)) /* transparent */
  6572. || (a->ncci_state[ncci] == IDLE)
  6573. || (a->ncci_state[ncci] == INC_DIS_PENDING))
  6574. {
  6575. plci->NL.RNR = 2;
  6576. break;
  6577. }
  6578. if ((a->ncci_state[ncci] != CONNECTED)
  6579. && (a->ncci_state[ncci] != OUTG_DIS_PENDING)
  6580. && (a->ncci_state[ncci] != OUTG_REJ_PENDING))
  6581. {
  6582. dbug(1,dprintf("flow control"));
  6583. plci->NL.RNR = 1; /* flow control */
  6584. channel_x_off (plci, ch, 0);
  6585. break;
  6586. }
  6587. NCCIcode = ncci | (((word)a->Id) << 8);
  6588. /* count all buffers within the Application pool */
  6589. /* belonging to the same NCCI. If this is below the */
  6590. /* number of buffers available per NCCI we accept */
  6591. /* this packet, otherwise we reject it */
  6592. count = 0;
  6593. Num = 0xffff;
  6594. for(i=0; i<APPLptr->MaxBuffer; i++) {
  6595. if(NCCIcode==APPLptr->DataNCCI[i]) count++;
  6596. if(!APPLptr->DataNCCI[i] && Num==0xffff) Num = i;
  6597. }
  6598. if(count>=APPLptr->MaxNCCIData || Num==0xffff)
  6599. {
  6600. dbug(3,dprintf("Flow-Control"));
  6601. plci->NL.RNR = 1;
  6602. if( ++(APPLptr->NCCIDataFlowCtrlTimer)>=
  6603. (word)((a->manufacturer_features & MANUFACTURER_FEATURE_OOB_CHANNEL) ? 40 : 2000))
  6604. {
  6605. plci->NL.RNR = 2;
  6606. dbug(3,dprintf("DiscardData"));
  6607. } else {
  6608. channel_x_off (plci, ch, 0);
  6609. }
  6610. break;
  6611. }
  6612. else
  6613. {
  6614. APPLptr->NCCIDataFlowCtrlTimer = 0;
  6615. }
  6616. plci->RData[0].P = ReceiveBufferGet(APPLptr,Num);
  6617. if(!plci->RData[0].P) {
  6618. plci->NL.RNR = 1;
  6619. channel_x_off (plci, ch, 0);
  6620. break;
  6621. }
  6622. APPLptr->DataNCCI[Num] = NCCIcode;
  6623. APPLptr->DataFlags[Num] = (plci->Id<<8) | (plci->NL.Ind>>4);
  6624. dbug(3,dprintf("Buffer(%d), Max = %d",Num,APPLptr->MaxBuffer));
  6625. plci->RNum = Num;
  6626. plci->RFlags = plci->NL.Ind>>4;
  6627. plci->RData[0].PLength = APPLptr->MaxDataLength;
  6628. plci->NL.R = plci->RData;
  6629. if ((plci->NL.RLength != 0)
  6630. && ((plci->B2_prot == B2_V120_ASYNC)
  6631. || (plci->B2_prot == B2_V120_ASYNC_V42BIS)
  6632. || (plci->B2_prot == B2_V120_BIT_TRANSPARENT)))
  6633. {
  6634. plci->RData[1].P = plci->RData[0].P;
  6635. plci->RData[1].PLength = plci->RData[0].PLength;
  6636. plci->RData[0].P = v120_header_buffer + (-((int) v120_header_buffer) & 3);
  6637. if ((plci->NL.RBuffer->P[0] & V120_HEADER_EXTEND_BIT) || (plci->NL.RLength == 1))
  6638. plci->RData[0].PLength = 1;
  6639. else
  6640. plci->RData[0].PLength = 2;
  6641. if (plci->NL.RBuffer->P[0] & V120_HEADER_BREAK_BIT)
  6642. plci->RFlags |= 0x0010;
  6643. if (plci->NL.RBuffer->P[0] & (V120_HEADER_C1_BIT | V120_HEADER_C2_BIT))
  6644. plci->RFlags |= 0x8000;
  6645. plci->NL.RNum = 2;
  6646. }
  6647. else
  6648. {
  6649. if((plci->NL.Ind &0x0f)==N_UDATA)
  6650. plci->RFlags |= 0x0010;
  6651. else if ((plci->B3_prot == B3_RTP) && ((plci->NL.Ind & 0x0f) == N_BDATA))
  6652. plci->RFlags |= 0x0001;
  6653. plci->NL.RNum = 1;
  6654. }
  6655. break;
  6656. case N_DATA_ACK:
  6657. data_ack (plci, ch);
  6658. break;
  6659. default:
  6660. plci->NL.RNR = 2;
  6661. break;
  6662. }
  6663. }
  6664. /*------------------------------------------------------------------*/
  6665. /* find a free PLCI */
  6666. /*------------------------------------------------------------------*/
  6667. static word get_plci(DIVA_CAPI_ADAPTER *a)
  6668. {
  6669. word i,j;
  6670. PLCI * plci;
  6671. dump_plcis (a);
  6672. for(i=0;i<a->max_plci && a->plci[i].Id;i++);
  6673. if(i==a->max_plci) {
  6674. dbug(1,dprintf("get_plci: out of PLCIs"));
  6675. return 0;
  6676. }
  6677. plci = &a->plci[i];
  6678. plci->Id = (byte)(i+1);
  6679. plci->Sig.Id = 0;
  6680. plci->NL.Id = 0;
  6681. plci->sig_req = 0;
  6682. plci->nl_req = 0;
  6683. plci->appl = NULL;
  6684. plci->relatedPTYPLCI = NULL;
  6685. plci->State = IDLE;
  6686. plci->SuppState = IDLE;
  6687. plci->channels = 0;
  6688. plci->tel = 0;
  6689. plci->B1_resource = 0;
  6690. plci->B2_prot = 0;
  6691. plci->B3_prot = 0;
  6692. plci->command = 0;
  6693. plci->m_command = 0;
  6694. init_internal_command_queue (plci);
  6695. plci->number = 0;
  6696. plci->req_in_start = 0;
  6697. plci->req_in = 0;
  6698. plci->req_out = 0;
  6699. plci->msg_in_write_pos = MSG_IN_QUEUE_SIZE;
  6700. plci->msg_in_read_pos = MSG_IN_QUEUE_SIZE;
  6701. plci->msg_in_wrap_pos = MSG_IN_QUEUE_SIZE;
  6702. plci->data_sent = false;
  6703. plci->send_disc = 0;
  6704. plci->sig_global_req = 0;
  6705. plci->sig_remove_id = 0;
  6706. plci->nl_global_req = 0;
  6707. plci->nl_remove_id = 0;
  6708. plci->adv_nl = 0;
  6709. plci->manufacturer = false;
  6710. plci->call_dir = CALL_DIR_OUT | CALL_DIR_ORIGINATE;
  6711. plci->spoofed_msg = 0;
  6712. plci->ptyState = 0;
  6713. plci->cr_enquiry = false;
  6714. plci->hangup_flow_ctrl_timer = 0;
  6715. plci->ncci_ring_list = 0;
  6716. for(j=0;j<MAX_CHANNELS_PER_PLCI;j++) plci->inc_dis_ncci_table[j] = 0;
  6717. clear_c_ind_mask (plci);
  6718. set_group_ind_mask (plci);
  6719. plci->fax_connect_info_length = 0;
  6720. plci->nsf_control_bits = 0;
  6721. plci->ncpi_state = 0x00;
  6722. plci->ncpi_buffer[0] = 0;
  6723. plci->requested_options_conn = 0;
  6724. plci->requested_options = 0;
  6725. plci->notifiedcall = 0;
  6726. plci->vswitchstate = 0;
  6727. plci->vsprot = 0;
  6728. plci->vsprotdialect = 0;
  6729. init_b1_config (plci);
  6730. dbug(1,dprintf("get_plci(%x)",plci->Id));
  6731. return i+1;
  6732. }
  6733. /*------------------------------------------------------------------*/
  6734. /* put a parameter in the parameter buffer */
  6735. /*------------------------------------------------------------------*/
  6736. static void add_p(PLCI * plci, byte code, byte * p)
  6737. {
  6738. word p_length;
  6739. p_length = 0;
  6740. if(p) p_length = p[0];
  6741. add_ie(plci, code, p, p_length);
  6742. }
  6743. /*------------------------------------------------------------------*/
  6744. /* put a structure in the parameter buffer */
  6745. /*------------------------------------------------------------------*/
  6746. static void add_s(PLCI * plci, byte code, API_PARSE * p)
  6747. {
  6748. if(p) add_ie(plci, code, p->info, (word)p->length);
  6749. }
  6750. /*------------------------------------------------------------------*/
  6751. /* put multiple structures in the parameter buffer */
  6752. /*------------------------------------------------------------------*/
  6753. static void add_ss(PLCI * plci, byte code, API_PARSE * p)
  6754. {
  6755. byte i;
  6756. if(p){
  6757. dbug(1,dprintf("add_ss(%x,len=%d)",code,p->length));
  6758. for(i=2;i<(byte)p->length;i+=p->info[i]+2){
  6759. dbug(1,dprintf("add_ss_ie(%x,len=%d)",p->info[i-1],p->info[i]));
  6760. add_ie(plci, p->info[i-1], (byte *)&(p->info[i]), (word)p->info[i]);
  6761. }
  6762. }
  6763. }
  6764. /*------------------------------------------------------------------*/
  6765. /* return the channel number sent by the application in a esc_chi */
  6766. /*------------------------------------------------------------------*/
  6767. static byte getChannel(API_PARSE * p)
  6768. {
  6769. byte i;
  6770. if(p){
  6771. for(i=2;i<(byte)p->length;i+=p->info[i]+2){
  6772. if(p->info[i]==2){
  6773. if(p->info[i-1]==ESC && p->info[i+1]==CHI) return (p->info[i+2]);
  6774. }
  6775. }
  6776. }
  6777. return 0;
  6778. }
  6779. /*------------------------------------------------------------------*/
  6780. /* put an information element in the parameter buffer */
  6781. /*------------------------------------------------------------------*/
  6782. static void add_ie(PLCI * plci, byte code, byte * p, word p_length)
  6783. {
  6784. word i;
  6785. if(!(code &0x80) && !p_length) return;
  6786. if(plci->req_in==plci->req_in_start) {
  6787. plci->req_in +=2;
  6788. }
  6789. else {
  6790. plci->req_in--;
  6791. }
  6792. plci->RBuffer[plci->req_in++] = code;
  6793. if(p) {
  6794. plci->RBuffer[plci->req_in++] = (byte)p_length;
  6795. for(i=0;i<p_length;i++) plci->RBuffer[plci->req_in++] = p[1+i];
  6796. }
  6797. plci->RBuffer[plci->req_in++] = 0;
  6798. }
  6799. /*------------------------------------------------------------------*/
  6800. /* put a unstructured data into the buffer */
  6801. /*------------------------------------------------------------------*/
  6802. static void add_d(PLCI *plci, word length, byte *p)
  6803. {
  6804. word i;
  6805. if(plci->req_in==plci->req_in_start) {
  6806. plci->req_in +=2;
  6807. }
  6808. else {
  6809. plci->req_in--;
  6810. }
  6811. for(i=0;i<length;i++) plci->RBuffer[plci->req_in++] = p[i];
  6812. }
  6813. /*------------------------------------------------------------------*/
  6814. /* put parameters from the Additional Info parameter in the */
  6815. /* parameter buffer */
  6816. /*------------------------------------------------------------------*/
  6817. static void add_ai(PLCI *plci, API_PARSE *ai)
  6818. {
  6819. word i;
  6820. API_PARSE ai_parms[5];
  6821. for(i=0;i<5;i++) ai_parms[i].length = 0;
  6822. if(!ai->length)
  6823. return;
  6824. if(api_parse(&ai->info[1], (word)ai->length, "ssss", ai_parms))
  6825. return;
  6826. add_s (plci,KEY,&ai_parms[1]);
  6827. add_s (plci,UUI,&ai_parms[2]);
  6828. add_ss(plci,FTY,&ai_parms[3]);
  6829. }
  6830. /*------------------------------------------------------------------*/
  6831. /* put parameter for b1 protocol in the parameter buffer */
  6832. /*------------------------------------------------------------------*/
  6833. static word add_b1(PLCI *plci, API_PARSE *bp, word b_channel_info,
  6834. word b1_facilities)
  6835. {
  6836. API_PARSE bp_parms[8];
  6837. API_PARSE mdm_cfg[9];
  6838. API_PARSE global_config[2];
  6839. byte cai[256];
  6840. byte resource[] = {5,9,13,12,16,39,9,17,17,18};
  6841. byte voice_cai[] = "\x06\x14\x00\x00\x00\x00\x08";
  6842. word i;
  6843. API_PARSE mdm_cfg_v18[4];
  6844. word j, n, w;
  6845. dword d;
  6846. for(i=0;i<8;i++) bp_parms[i].length = 0;
  6847. for(i=0;i<2;i++) global_config[i].length = 0;
  6848. dbug(1,dprintf("add_b1"));
  6849. api_save_msg(bp, "s", &plci->B_protocol);
  6850. if(b_channel_info==2){
  6851. plci->B1_resource = 0;
  6852. adjust_b1_facilities (plci, plci->B1_resource, b1_facilities);
  6853. add_p(plci, CAI, "\x01\x00");
  6854. dbug(1,dprintf("Cai=1,0 (no resource)"));
  6855. return 0;
  6856. }
  6857. if(plci->tel == CODEC_PERMANENT) return 0;
  6858. else if(plci->tel == CODEC){
  6859. plci->B1_resource = 1;
  6860. adjust_b1_facilities (plci, plci->B1_resource, b1_facilities);
  6861. add_p(plci, CAI, "\x01\x01");
  6862. dbug(1,dprintf("Cai=1,1 (Codec)"));
  6863. return 0;
  6864. }
  6865. else if(plci->tel == ADV_VOICE){
  6866. plci->B1_resource = add_b1_facilities (plci, 9, (word)(b1_facilities | B1_FACILITY_VOICE));
  6867. adjust_b1_facilities (plci, plci->B1_resource, (word)(b1_facilities | B1_FACILITY_VOICE));
  6868. voice_cai[1] = plci->B1_resource;
  6869. PUT_WORD (&voice_cai[5], plci->appl->MaxDataLength);
  6870. add_p(plci, CAI, voice_cai);
  6871. dbug(1,dprintf("Cai=1,0x%x (AdvVoice)",voice_cai[1]));
  6872. return 0;
  6873. }
  6874. plci->call_dir &= ~(CALL_DIR_ORIGINATE | CALL_DIR_ANSWER);
  6875. if (plci->call_dir & CALL_DIR_OUT)
  6876. plci->call_dir |= CALL_DIR_ORIGINATE;
  6877. else if (plci->call_dir & CALL_DIR_IN)
  6878. plci->call_dir |= CALL_DIR_ANSWER;
  6879. if(!bp->length){
  6880. plci->B1_resource = 0x5;
  6881. adjust_b1_facilities (plci, plci->B1_resource, b1_facilities);
  6882. add_p(plci, CAI, "\x01\x05");
  6883. return 0;
  6884. }
  6885. dbug(1,dprintf("b_prot_len=%d",(word)bp->length));
  6886. if(bp->length>256) return _WRONG_MESSAGE_FORMAT;
  6887. if(api_parse(&bp->info[1], (word)bp->length, "wwwsssb", bp_parms))
  6888. {
  6889. bp_parms[6].length = 0;
  6890. if(api_parse(&bp->info[1], (word)bp->length, "wwwsss", bp_parms))
  6891. {
  6892. dbug(1,dprintf("b-form.!"));
  6893. return _WRONG_MESSAGE_FORMAT;
  6894. }
  6895. }
  6896. else if (api_parse(&bp->info[1], (word)bp->length, "wwwssss", bp_parms))
  6897. {
  6898. dbug(1,dprintf("b-form.!"));
  6899. return _WRONG_MESSAGE_FORMAT;
  6900. }
  6901. if(bp_parms[6].length)
  6902. {
  6903. if(api_parse(&bp_parms[6].info[1], (word)bp_parms[6].length, "w", global_config))
  6904. {
  6905. return _WRONG_MESSAGE_FORMAT;
  6906. }
  6907. switch(GET_WORD(global_config[0].info))
  6908. {
  6909. case 1:
  6910. plci->call_dir = (plci->call_dir & ~CALL_DIR_ANSWER) | CALL_DIR_ORIGINATE;
  6911. break;
  6912. case 2:
  6913. plci->call_dir = (plci->call_dir & ~CALL_DIR_ORIGINATE) | CALL_DIR_ANSWER;
  6914. break;
  6915. }
  6916. }
  6917. dbug(1,dprintf("call_dir=%04x", plci->call_dir));
  6918. if ((GET_WORD(bp_parms[0].info) == B1_RTP)
  6919. && (plci->adapter->man_profile.private_options & (1L << PRIVATE_RTP)))
  6920. {
  6921. plci->B1_resource = add_b1_facilities (plci, 31, (word)(b1_facilities & ~B1_FACILITY_VOICE));
  6922. adjust_b1_facilities (plci, plci->B1_resource, (word)(b1_facilities & ~B1_FACILITY_VOICE));
  6923. cai[1] = plci->B1_resource;
  6924. cai[2] = 0;
  6925. cai[3] = 0;
  6926. cai[4] = 0;
  6927. PUT_WORD(&cai[5],plci->appl->MaxDataLength);
  6928. for (i = 0; i < bp_parms[3].length; i++)
  6929. cai[7+i] = bp_parms[3].info[1+i];
  6930. cai[0] = 6 + bp_parms[3].length;
  6931. add_p(plci, CAI, cai);
  6932. return 0;
  6933. }
  6934. if ((GET_WORD(bp_parms[0].info) == B1_PIAFS)
  6935. && (plci->adapter->man_profile.private_options & (1L << PRIVATE_PIAFS)))
  6936. {
  6937. plci->B1_resource = add_b1_facilities (plci, 35/* PIAFS HARDWARE FACILITY */, (word)(b1_facilities & ~B1_FACILITY_VOICE));
  6938. adjust_b1_facilities (plci, plci->B1_resource, (word)(b1_facilities & ~B1_FACILITY_VOICE));
  6939. cai[1] = plci->B1_resource;
  6940. cai[2] = 0;
  6941. cai[3] = 0;
  6942. cai[4] = 0;
  6943. PUT_WORD(&cai[5],plci->appl->MaxDataLength);
  6944. cai[0] = 6;
  6945. add_p(plci, CAI, cai);
  6946. return 0;
  6947. }
  6948. if ((GET_WORD(bp_parms[0].info) >= 32)
  6949. || (!((1L << GET_WORD(bp_parms[0].info)) & plci->adapter->profile.B1_Protocols)
  6950. && ((GET_WORD(bp_parms[0].info) != 3)
  6951. || !((1L << B1_HDLC) & plci->adapter->profile.B1_Protocols)
  6952. || ((bp_parms[3].length != 0) && (GET_WORD(&bp_parms[3].info[1]) != 0) && (GET_WORD(&bp_parms[3].info[1]) != 56000)))))
  6953. {
  6954. return _B1_NOT_SUPPORTED;
  6955. }
  6956. plci->B1_resource = add_b1_facilities (plci, resource[GET_WORD(bp_parms[0].info)],
  6957. (word)(b1_facilities & ~B1_FACILITY_VOICE));
  6958. adjust_b1_facilities (plci, plci->B1_resource, (word)(b1_facilities & ~B1_FACILITY_VOICE));
  6959. cai[0] = 6;
  6960. cai[1] = plci->B1_resource;
  6961. for (i=2;i<sizeof(cai);i++) cai[i] = 0;
  6962. if ((GET_WORD(bp_parms[0].info) == B1_MODEM_ALL_NEGOTIATE)
  6963. || (GET_WORD(bp_parms[0].info) == B1_MODEM_ASYNC)
  6964. || (GET_WORD(bp_parms[0].info) == B1_MODEM_SYNC_HDLC))
  6965. { /* B1 - modem */
  6966. for (i=0;i<7;i++) mdm_cfg[i].length = 0;
  6967. if (bp_parms[3].length)
  6968. {
  6969. if(api_parse(&bp_parms[3].info[1],(word)bp_parms[3].length,"wwwwww", mdm_cfg))
  6970. {
  6971. return (_WRONG_MESSAGE_FORMAT);
  6972. }
  6973. cai[2] = 0; /* Bit rate for adaptation */
  6974. dbug(1,dprintf("MDM Max Bit Rate:<%d>", GET_WORD(mdm_cfg[0].info)));
  6975. PUT_WORD (&cai[13], 0); /* Min Tx speed */
  6976. PUT_WORD (&cai[15], GET_WORD(mdm_cfg[0].info)); /* Max Tx speed */
  6977. PUT_WORD (&cai[17], 0); /* Min Rx speed */
  6978. PUT_WORD (&cai[19], GET_WORD(mdm_cfg[0].info)); /* Max Rx speed */
  6979. cai[3] = 0; /* Async framing parameters */
  6980. switch (GET_WORD (mdm_cfg[2].info))
  6981. { /* Parity */
  6982. case 1: /* odd parity */
  6983. cai[3] |= (DSP_CAI_ASYNC_PARITY_ENABLE | DSP_CAI_ASYNC_PARITY_ODD);
  6984. dbug(1,dprintf("MDM: odd parity"));
  6985. break;
  6986. case 2: /* even parity */
  6987. cai[3] |= (DSP_CAI_ASYNC_PARITY_ENABLE | DSP_CAI_ASYNC_PARITY_EVEN);
  6988. dbug(1,dprintf("MDM: even parity"));
  6989. break;
  6990. default:
  6991. dbug(1,dprintf("MDM: no parity"));
  6992. break;
  6993. }
  6994. switch (GET_WORD (mdm_cfg[3].info))
  6995. { /* stop bits */
  6996. case 1: /* 2 stop bits */
  6997. cai[3] |= DSP_CAI_ASYNC_TWO_STOP_BITS;
  6998. dbug(1,dprintf("MDM: 2 stop bits"));
  6999. break;
  7000. default:
  7001. dbug(1,dprintf("MDM: 1 stop bit"));
  7002. break;
  7003. }
  7004. switch (GET_WORD (mdm_cfg[1].info))
  7005. { /* char length */
  7006. case 5:
  7007. cai[3] |= DSP_CAI_ASYNC_CHAR_LENGTH_5;
  7008. dbug(1,dprintf("MDM: 5 bits"));
  7009. break;
  7010. case 6:
  7011. cai[3] |= DSP_CAI_ASYNC_CHAR_LENGTH_6;
  7012. dbug(1,dprintf("MDM: 6 bits"));
  7013. break;
  7014. case 7:
  7015. cai[3] |= DSP_CAI_ASYNC_CHAR_LENGTH_7;
  7016. dbug(1,dprintf("MDM: 7 bits"));
  7017. break;
  7018. default:
  7019. dbug(1,dprintf("MDM: 8 bits"));
  7020. break;
  7021. }
  7022. cai[7] = 0; /* Line taking options */
  7023. cai[8] = 0; /* Modulation negotiation options */
  7024. cai[9] = 0; /* Modulation options */
  7025. if (((plci->call_dir & CALL_DIR_ORIGINATE) != 0) ^ ((plci->call_dir & CALL_DIR_OUT) != 0))
  7026. {
  7027. cai[9] |= DSP_CAI_MODEM_REVERSE_DIRECTION;
  7028. dbug(1, dprintf("MDM: Reverse direction"));
  7029. }
  7030. if (GET_WORD (mdm_cfg[4].info) & MDM_CAPI_DISABLE_RETRAIN)
  7031. {
  7032. cai[9] |= DSP_CAI_MODEM_DISABLE_RETRAIN;
  7033. dbug(1, dprintf("MDM: Disable retrain"));
  7034. }
  7035. if (GET_WORD (mdm_cfg[4].info) & MDM_CAPI_DISABLE_RING_TONE)
  7036. {
  7037. cai[7] |= DSP_CAI_MODEM_DISABLE_CALLING_TONE | DSP_CAI_MODEM_DISABLE_ANSWER_TONE;
  7038. dbug(1, dprintf("MDM: Disable ring tone"));
  7039. }
  7040. if (GET_WORD (mdm_cfg[4].info) & MDM_CAPI_GUARD_1800)
  7041. {
  7042. cai[8] |= DSP_CAI_MODEM_GUARD_TONE_1800HZ;
  7043. dbug(1, dprintf("MDM: 1800 guard tone"));
  7044. }
  7045. else if (GET_WORD (mdm_cfg[4].info) & MDM_CAPI_GUARD_550 )
  7046. {
  7047. cai[8] |= DSP_CAI_MODEM_GUARD_TONE_550HZ;
  7048. dbug(1, dprintf("MDM: 550 guard tone"));
  7049. }
  7050. if ((GET_WORD (mdm_cfg[5].info) & 0x00ff) == MDM_CAPI_NEG_V100)
  7051. {
  7052. cai[8] |= DSP_CAI_MODEM_NEGOTIATE_V100;
  7053. dbug(1, dprintf("MDM: V100"));
  7054. }
  7055. else if ((GET_WORD (mdm_cfg[5].info) & 0x00ff) == MDM_CAPI_NEG_MOD_CLASS)
  7056. {
  7057. cai[8] |= DSP_CAI_MODEM_NEGOTIATE_IN_CLASS;
  7058. dbug(1, dprintf("MDM: IN CLASS"));
  7059. }
  7060. else if ((GET_WORD (mdm_cfg[5].info) & 0x00ff) == MDM_CAPI_NEG_DISABLED)
  7061. {
  7062. cai[8] |= DSP_CAI_MODEM_NEGOTIATE_DISABLED;
  7063. dbug(1, dprintf("MDM: DISABLED"));
  7064. }
  7065. cai[0] = 20;
  7066. if ((plci->adapter->man_profile.private_options & (1L << PRIVATE_V18))
  7067. && (GET_WORD(mdm_cfg[5].info) & 0x8000)) /* Private V.18 enable */
  7068. {
  7069. plci->requested_options |= 1L << PRIVATE_V18;
  7070. }
  7071. if (GET_WORD(mdm_cfg[5].info) & 0x4000) /* Private VOWN enable */
  7072. plci->requested_options |= 1L << PRIVATE_VOWN;
  7073. if ((plci->requested_options_conn | plci->requested_options | plci->adapter->requested_options_table[plci->appl->Id-1])
  7074. & ((1L << PRIVATE_V18) | (1L << PRIVATE_VOWN)))
  7075. {
  7076. if (!api_parse(&bp_parms[3].info[1],(word)bp_parms[3].length,"wwwwwws", mdm_cfg))
  7077. {
  7078. i = 27;
  7079. if (mdm_cfg[6].length >= 4)
  7080. {
  7081. d = GET_DWORD(&mdm_cfg[6].info[1]);
  7082. cai[7] |= (byte) d; /* line taking options */
  7083. cai[9] |= (byte)(d >> 8); /* modulation options */
  7084. cai[++i] = (byte)(d >> 16); /* vown modulation options */
  7085. cai[++i] = (byte)(d >> 24);
  7086. if (mdm_cfg[6].length >= 8)
  7087. {
  7088. d = GET_DWORD(&mdm_cfg[6].info[5]);
  7089. cai[10] |= (byte) d; /* disabled modulations mask */
  7090. cai[11] |= (byte)(d >> 8);
  7091. if (mdm_cfg[6].length >= 12)
  7092. {
  7093. d = GET_DWORD(&mdm_cfg[6].info[9]);
  7094. cai[12] = (byte) d; /* enabled modulations mask */
  7095. cai[++i] = (byte)(d >> 8); /* vown enabled modulations */
  7096. cai[++i] = (byte)(d >> 16);
  7097. cai[++i] = (byte)(d >> 24);
  7098. cai[++i] = 0;
  7099. if (mdm_cfg[6].length >= 14)
  7100. {
  7101. w = GET_WORD(&mdm_cfg[6].info[13]);
  7102. if (w != 0)
  7103. PUT_WORD(&cai[13], w); /* min tx speed */
  7104. if (mdm_cfg[6].length >= 16)
  7105. {
  7106. w = GET_WORD(&mdm_cfg[6].info[15]);
  7107. if (w != 0)
  7108. PUT_WORD(&cai[15], w); /* max tx speed */
  7109. if (mdm_cfg[6].length >= 18)
  7110. {
  7111. w = GET_WORD(&mdm_cfg[6].info[17]);
  7112. if (w != 0)
  7113. PUT_WORD(&cai[17], w); /* min rx speed */
  7114. if (mdm_cfg[6].length >= 20)
  7115. {
  7116. w = GET_WORD(&mdm_cfg[6].info[19]);
  7117. if (w != 0)
  7118. PUT_WORD(&cai[19], w); /* max rx speed */
  7119. if (mdm_cfg[6].length >= 22)
  7120. {
  7121. w = GET_WORD(&mdm_cfg[6].info[21]);
  7122. cai[23] = (byte)(-((short) w)); /* transmit level */
  7123. if (mdm_cfg[6].length >= 24)
  7124. {
  7125. w = GET_WORD(&mdm_cfg[6].info[23]);
  7126. cai[22] |= (byte) w; /* info options mask */
  7127. cai[21] |= (byte)(w >> 8); /* disabled symbol rates */
  7128. }
  7129. }
  7130. }
  7131. }
  7132. }
  7133. }
  7134. }
  7135. }
  7136. }
  7137. cai[27] = i - 27;
  7138. i++;
  7139. if (!api_parse(&bp_parms[3].info[1],(word)bp_parms[3].length,"wwwwwwss", mdm_cfg))
  7140. {
  7141. if (!api_parse(&mdm_cfg[7].info[1],(word)mdm_cfg[7].length,"sss", mdm_cfg_v18))
  7142. {
  7143. for (n = 0; n < 3; n++)
  7144. {
  7145. cai[i] = (byte)(mdm_cfg_v18[n].length);
  7146. for (j = 1; j < ((word)(cai[i] + 1)); j++)
  7147. cai[i+j] = mdm_cfg_v18[n].info[j];
  7148. i += cai[i] + 1;
  7149. }
  7150. }
  7151. }
  7152. cai[0] = (byte)(i - 1);
  7153. }
  7154. }
  7155. }
  7156. }
  7157. if(GET_WORD(bp_parms[0].info)==2 || /* V.110 async */
  7158. GET_WORD(bp_parms[0].info)==3 ) /* V.110 sync */
  7159. {
  7160. if(bp_parms[3].length){
  7161. dbug(1,dprintf("V.110,%d",GET_WORD(&bp_parms[3].info[1])));
  7162. switch(GET_WORD(&bp_parms[3].info[1])){ /* Rate */
  7163. case 0:
  7164. case 56000:
  7165. if(GET_WORD(bp_parms[0].info)==3){ /* V.110 sync 56k */
  7166. dbug(1,dprintf("56k sync HSCX"));
  7167. cai[1] = 8;
  7168. cai[2] = 0;
  7169. cai[3] = 0;
  7170. }
  7171. else if(GET_WORD(bp_parms[0].info)==2){
  7172. dbug(1,dprintf("56k async DSP"));
  7173. cai[2] = 9;
  7174. }
  7175. break;
  7176. case 50: cai[2] = 1; break;
  7177. case 75: cai[2] = 1; break;
  7178. case 110: cai[2] = 1; break;
  7179. case 150: cai[2] = 1; break;
  7180. case 200: cai[2] = 1; break;
  7181. case 300: cai[2] = 1; break;
  7182. case 600: cai[2] = 1; break;
  7183. case 1200: cai[2] = 2; break;
  7184. case 2400: cai[2] = 3; break;
  7185. case 4800: cai[2] = 4; break;
  7186. case 7200: cai[2] = 10; break;
  7187. case 9600: cai[2] = 5; break;
  7188. case 12000: cai[2] = 13; break;
  7189. case 24000: cai[2] = 0; break;
  7190. case 14400: cai[2] = 11; break;
  7191. case 19200: cai[2] = 6; break;
  7192. case 28800: cai[2] = 12; break;
  7193. case 38400: cai[2] = 7; break;
  7194. case 48000: cai[2] = 8; break;
  7195. case 76: cai[2] = 15; break; /* 75/1200 */
  7196. case 1201: cai[2] = 14; break; /* 1200/75 */
  7197. case 56001: cai[2] = 9; break; /* V.110 56000 */
  7198. default:
  7199. return _B1_PARM_NOT_SUPPORTED;
  7200. }
  7201. cai[3] = 0;
  7202. if (cai[1] == 13) /* v.110 async */
  7203. {
  7204. if (bp_parms[3].length >= 8)
  7205. {
  7206. switch (GET_WORD (&bp_parms[3].info[3]))
  7207. { /* char length */
  7208. case 5:
  7209. cai[3] |= DSP_CAI_ASYNC_CHAR_LENGTH_5;
  7210. break;
  7211. case 6:
  7212. cai[3] |= DSP_CAI_ASYNC_CHAR_LENGTH_6;
  7213. break;
  7214. case 7:
  7215. cai[3] |= DSP_CAI_ASYNC_CHAR_LENGTH_7;
  7216. break;
  7217. }
  7218. switch (GET_WORD (&bp_parms[3].info[5]))
  7219. { /* Parity */
  7220. case 1: /* odd parity */
  7221. cai[3] |= (DSP_CAI_ASYNC_PARITY_ENABLE | DSP_CAI_ASYNC_PARITY_ODD);
  7222. break;
  7223. case 2: /* even parity */
  7224. cai[3] |= (DSP_CAI_ASYNC_PARITY_ENABLE | DSP_CAI_ASYNC_PARITY_EVEN);
  7225. break;
  7226. }
  7227. switch (GET_WORD (&bp_parms[3].info[7]))
  7228. { /* stop bits */
  7229. case 1: /* 2 stop bits */
  7230. cai[3] |= DSP_CAI_ASYNC_TWO_STOP_BITS;
  7231. break;
  7232. }
  7233. }
  7234. }
  7235. }
  7236. else if(cai[1]==8 || GET_WORD(bp_parms[0].info)==3 ){
  7237. dbug(1,dprintf("V.110 default 56k sync"));
  7238. cai[1] = 8;
  7239. cai[2] = 0;
  7240. cai[3] = 0;
  7241. }
  7242. else {
  7243. dbug(1,dprintf("V.110 default 9600 async"));
  7244. cai[2] = 5;
  7245. }
  7246. }
  7247. PUT_WORD(&cai[5],plci->appl->MaxDataLength);
  7248. dbug(1,dprintf("CAI[%d]=%x,%x,%x,%x,%x,%x", cai[0], cai[1], cai[2], cai[3], cai[4], cai[5], cai[6]));
  7249. /* HexDump ("CAI", sizeof(cai), &cai[0]); */
  7250. add_p(plci, CAI, cai);
  7251. return 0;
  7252. }
  7253. /*------------------------------------------------------------------*/
  7254. /* put parameter for b2 and B3 protocol in the parameter buffer */
  7255. /*------------------------------------------------------------------*/
  7256. static word add_b23(PLCI *plci, API_PARSE *bp)
  7257. {
  7258. word i, fax_control_bits;
  7259. byte pos, len;
  7260. byte SAPI = 0x40; /* default SAPI 16 for x.31 */
  7261. API_PARSE bp_parms[8];
  7262. API_PARSE * b1_config;
  7263. API_PARSE * b2_config;
  7264. API_PARSE b2_config_parms[8];
  7265. API_PARSE * b3_config;
  7266. API_PARSE b3_config_parms[6];
  7267. API_PARSE global_config[2];
  7268. static byte llc[3] = {2,0,0};
  7269. static byte dlc[20] = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
  7270. static byte nlc[256];
  7271. static byte lli[12] = {1,1};
  7272. const byte llc2_out[] = {1,2,4,6,2,0,0,0, X75_V42BIS,V120_L2,V120_V42BIS,V120_L2,6};
  7273. const byte llc2_in[] = {1,3,4,6,3,0,0,0, X75_V42BIS,V120_L2,V120_V42BIS,V120_L2,6};
  7274. const byte llc3[] = {4,3,2,2,6,6,0};
  7275. const byte header[] = {0,2,3,3,0,0,0};
  7276. for(i=0;i<8;i++) bp_parms[i].length = 0;
  7277. for(i=0;i<6;i++) b2_config_parms[i].length = 0;
  7278. for(i=0;i<5;i++) b3_config_parms[i].length = 0;
  7279. lli[0] = 1;
  7280. lli[1] = 1;
  7281. if (plci->adapter->manufacturer_features & MANUFACTURER_FEATURE_XONOFF_FLOW_CONTROL)
  7282. lli[1] |= 2;
  7283. if (plci->adapter->manufacturer_features & MANUFACTURER_FEATURE_OOB_CHANNEL)
  7284. lli[1] |= 4;
  7285. if ((lli[1] & 0x02) && (diva_xdi_extended_features & DIVA_CAPI_USE_CMA)) {
  7286. lli[1] |= 0x10;
  7287. if (plci->rx_dma_descriptor <= 0) {
  7288. plci->rx_dma_descriptor=diva_get_dma_descriptor(plci,&plci->rx_dma_magic);
  7289. if (plci->rx_dma_descriptor >= 0)
  7290. plci->rx_dma_descriptor++;
  7291. }
  7292. if (plci->rx_dma_descriptor > 0) {
  7293. lli[0] = 6;
  7294. lli[1] |= 0x40;
  7295. lli[2] = (byte)(plci->rx_dma_descriptor - 1);
  7296. lli[3] = (byte)plci->rx_dma_magic;
  7297. lli[4] = (byte)(plci->rx_dma_magic >> 8);
  7298. lli[5] = (byte)(plci->rx_dma_magic >> 16);
  7299. lli[6] = (byte)(plci->rx_dma_magic >> 24);
  7300. }
  7301. }
  7302. if (DIVA_CAPI_SUPPORTS_NO_CANCEL(plci->adapter)) {
  7303. lli[1] |= 0x20;
  7304. }
  7305. dbug(1,dprintf("add_b23"));
  7306. api_save_msg(bp, "s", &plci->B_protocol);
  7307. if(!bp->length && plci->tel)
  7308. {
  7309. plci->adv_nl = true;
  7310. dbug(1,dprintf("Default adv.Nl"));
  7311. add_p(plci,LLI,lli);
  7312. plci->B2_prot = 1 /*XPARENT*/;
  7313. plci->B3_prot = 0 /*XPARENT*/;
  7314. llc[1] = 2;
  7315. llc[2] = 4;
  7316. add_p(plci, LLC, llc);
  7317. dlc[0] = 2;
  7318. PUT_WORD(&dlc[1],plci->appl->MaxDataLength);
  7319. add_p(plci, DLC, dlc);
  7320. return 0;
  7321. }
  7322. if(!bp->length) /*default*/
  7323. {
  7324. dbug(1,dprintf("ret default"));
  7325. add_p(plci,LLI,lli);
  7326. plci->B2_prot = 0 /*X.75 */;
  7327. plci->B3_prot = 0 /*XPARENT*/;
  7328. llc[1] = 1;
  7329. llc[2] = 4;
  7330. add_p(plci, LLC, llc);
  7331. dlc[0] = 2;
  7332. PUT_WORD(&dlc[1],plci->appl->MaxDataLength);
  7333. add_p(plci, DLC, dlc);
  7334. return 0;
  7335. }
  7336. dbug(1,dprintf("b_prot_len=%d",(word)bp->length));
  7337. if((word)bp->length > 256) return _WRONG_MESSAGE_FORMAT;
  7338. if(api_parse(&bp->info[1], (word)bp->length, "wwwsssb", bp_parms))
  7339. {
  7340. bp_parms[6].length = 0;
  7341. if(api_parse(&bp->info[1], (word)bp->length, "wwwsss", bp_parms))
  7342. {
  7343. dbug(1,dprintf("b-form.!"));
  7344. return _WRONG_MESSAGE_FORMAT;
  7345. }
  7346. }
  7347. else if (api_parse(&bp->info[1], (word)bp->length, "wwwssss", bp_parms))
  7348. {
  7349. dbug(1,dprintf("b-form.!"));
  7350. return _WRONG_MESSAGE_FORMAT;
  7351. }
  7352. if(plci->tel==ADV_VOICE) /* transparent B on advanced voice */
  7353. {
  7354. if(GET_WORD(bp_parms[1].info)!=1
  7355. || GET_WORD(bp_parms[2].info)!=0) return _B2_NOT_SUPPORTED;
  7356. plci->adv_nl = true;
  7357. }
  7358. else if(plci->tel) return _B2_NOT_SUPPORTED;
  7359. if ((GET_WORD(bp_parms[1].info) == B2_RTP)
  7360. && (GET_WORD(bp_parms[2].info) == B3_RTP)
  7361. && (plci->adapter->man_profile.private_options & (1L << PRIVATE_RTP)))
  7362. {
  7363. add_p(plci,LLI,lli);
  7364. plci->B2_prot = (byte) GET_WORD(bp_parms[1].info);
  7365. plci->B3_prot = (byte) GET_WORD(bp_parms[2].info);
  7366. llc[1] = (plci->call_dir & (CALL_DIR_ORIGINATE | CALL_DIR_FORCE_OUTG_NL)) ? 14 : 13;
  7367. llc[2] = 4;
  7368. add_p(plci, LLC, llc);
  7369. dlc[0] = 2;
  7370. PUT_WORD(&dlc[1],plci->appl->MaxDataLength);
  7371. dlc[3] = 3; /* Addr A */
  7372. dlc[4] = 1; /* Addr B */
  7373. dlc[5] = 7; /* modulo mode */
  7374. dlc[6] = 7; /* window size */
  7375. dlc[7] = 0; /* XID len Lo */
  7376. dlc[8] = 0; /* XID len Hi */
  7377. for (i = 0; i < bp_parms[4].length; i++)
  7378. dlc[9+i] = bp_parms[4].info[1+i];
  7379. dlc[0] = (byte)(8 + bp_parms[4].length);
  7380. add_p(plci, DLC, dlc);
  7381. for (i = 0; i < bp_parms[5].length; i++)
  7382. nlc[1+i] = bp_parms[5].info[1+i];
  7383. nlc[0] = (byte)(bp_parms[5].length);
  7384. add_p(plci, NLC, nlc);
  7385. return 0;
  7386. }
  7387. if ((GET_WORD(bp_parms[1].info) >= 32)
  7388. || (!((1L << GET_WORD(bp_parms[1].info)) & plci->adapter->profile.B2_Protocols)
  7389. && ((GET_WORD(bp_parms[1].info) != B2_PIAFS)
  7390. || !(plci->adapter->man_profile.private_options & (1L << PRIVATE_PIAFS)))))
  7391. {
  7392. return _B2_NOT_SUPPORTED;
  7393. }
  7394. if ((GET_WORD(bp_parms[2].info) >= 32)
  7395. || !((1L << GET_WORD(bp_parms[2].info)) & plci->adapter->profile.B3_Protocols))
  7396. {
  7397. return _B3_NOT_SUPPORTED;
  7398. }
  7399. if ((GET_WORD(bp_parms[1].info) != B2_SDLC)
  7400. && ((GET_WORD(bp_parms[0].info) == B1_MODEM_ALL_NEGOTIATE)
  7401. || (GET_WORD(bp_parms[0].info) == B1_MODEM_ASYNC)
  7402. || (GET_WORD(bp_parms[0].info) == B1_MODEM_SYNC_HDLC)))
  7403. {
  7404. return (add_modem_b23 (plci, bp_parms));
  7405. }
  7406. add_p(plci,LLI,lli);
  7407. plci->B2_prot = (byte) GET_WORD(bp_parms[1].info);
  7408. plci->B3_prot = (byte) GET_WORD(bp_parms[2].info);
  7409. if(plci->B2_prot==12) SAPI = 0; /* default SAPI D-channel */
  7410. if(bp_parms[6].length)
  7411. {
  7412. if(api_parse(&bp_parms[6].info[1], (word)bp_parms[6].length, "w", global_config))
  7413. {
  7414. return _WRONG_MESSAGE_FORMAT;
  7415. }
  7416. switch(GET_WORD(global_config[0].info))
  7417. {
  7418. case 1:
  7419. plci->call_dir = (plci->call_dir & ~CALL_DIR_ANSWER) | CALL_DIR_ORIGINATE;
  7420. break;
  7421. case 2:
  7422. plci->call_dir = (plci->call_dir & ~CALL_DIR_ORIGINATE) | CALL_DIR_ANSWER;
  7423. break;
  7424. }
  7425. }
  7426. dbug(1,dprintf("call_dir=%04x", plci->call_dir));
  7427. if (plci->B2_prot == B2_PIAFS)
  7428. llc[1] = PIAFS_CRC;
  7429. else
  7430. /* IMPLEMENT_PIAFS */
  7431. {
  7432. llc[1] = (plci->call_dir & (CALL_DIR_ORIGINATE | CALL_DIR_FORCE_OUTG_NL)) ?
  7433. llc2_out[GET_WORD(bp_parms[1].info)] : llc2_in[GET_WORD(bp_parms[1].info)];
  7434. }
  7435. llc[2] = llc3[GET_WORD(bp_parms[2].info)];
  7436. add_p(plci, LLC, llc);
  7437. dlc[0] = 2;
  7438. PUT_WORD(&dlc[1], plci->appl->MaxDataLength +
  7439. header[GET_WORD(bp_parms[2].info)]);
  7440. b1_config = &bp_parms[3];
  7441. nlc[0] = 0;
  7442. if(plci->B3_prot == 4
  7443. || plci->B3_prot == 5)
  7444. {
  7445. for (i=0;i<sizeof(T30_INFO);i++) nlc[i] = 0;
  7446. nlc[0] = sizeof(T30_INFO);
  7447. if (plci->adapter->manufacturer_features & MANUFACTURER_FEATURE_FAX_PAPER_FORMATS)
  7448. ((T30_INFO *)&nlc[1])->operating_mode = T30_OPERATING_MODE_CAPI;
  7449. ((T30_INFO *)&nlc[1])->rate_div_2400 = 0xff;
  7450. if(b1_config->length>=2)
  7451. {
  7452. ((T30_INFO *)&nlc[1])->rate_div_2400 = (byte)(GET_WORD(&b1_config->info[1])/2400);
  7453. }
  7454. }
  7455. b2_config = &bp_parms[4];
  7456. if (llc[1] == PIAFS_CRC)
  7457. {
  7458. if (plci->B3_prot != B3_TRANSPARENT)
  7459. {
  7460. return _B_STACK_NOT_SUPPORTED;
  7461. }
  7462. if(b2_config->length && api_parse(&b2_config->info[1], (word)b2_config->length, "bwww", b2_config_parms)) {
  7463. return _WRONG_MESSAGE_FORMAT;
  7464. }
  7465. PUT_WORD(&dlc[1],plci->appl->MaxDataLength);
  7466. dlc[3] = 0; /* Addr A */
  7467. dlc[4] = 0; /* Addr B */
  7468. dlc[5] = 0; /* modulo mode */
  7469. dlc[6] = 0; /* window size */
  7470. if (b2_config->length >= 7){
  7471. dlc[ 7] = 7;
  7472. dlc[ 8] = 0;
  7473. dlc[ 9] = b2_config_parms[0].info[0]; /* PIAFS protocol Speed configuration */
  7474. dlc[10] = b2_config_parms[1].info[0]; /* V.42bis P0 */
  7475. dlc[11] = b2_config_parms[1].info[1]; /* V.42bis P0 */
  7476. dlc[12] = b2_config_parms[2].info[0]; /* V.42bis P1 */
  7477. dlc[13] = b2_config_parms[2].info[1]; /* V.42bis P1 */
  7478. dlc[14] = b2_config_parms[3].info[0]; /* V.42bis P2 */
  7479. dlc[15] = b2_config_parms[3].info[1]; /* V.42bis P2 */
  7480. dlc[ 0] = 15;
  7481. if(b2_config->length >= 8) { /* PIAFS control abilities */
  7482. dlc[ 7] = 10;
  7483. dlc[16] = 2; /* Length of PIAFS extention */
  7484. dlc[17] = PIAFS_UDATA_ABILITIES; /* control (UDATA) ability */
  7485. dlc[18] = b2_config_parms[4].info[0]; /* value */
  7486. dlc[ 0] = 18;
  7487. }
  7488. }
  7489. else /* default values, 64K, variable, no compression */
  7490. {
  7491. dlc[ 7] = 7;
  7492. dlc[ 8] = 0;
  7493. dlc[ 9] = 0x03; /* PIAFS protocol Speed configuration */
  7494. dlc[10] = 0x03; /* V.42bis P0 */
  7495. dlc[11] = 0; /* V.42bis P0 */
  7496. dlc[12] = 0; /* V.42bis P1 */
  7497. dlc[13] = 0; /* V.42bis P1 */
  7498. dlc[14] = 0; /* V.42bis P2 */
  7499. dlc[15] = 0; /* V.42bis P2 */
  7500. dlc[ 0] = 15;
  7501. }
  7502. add_p(plci, DLC, dlc);
  7503. }
  7504. else
  7505. if ((llc[1] == V120_L2) || (llc[1] == V120_V42BIS))
  7506. {
  7507. if (plci->B3_prot != B3_TRANSPARENT)
  7508. return _B_STACK_NOT_SUPPORTED;
  7509. dlc[0] = 6;
  7510. PUT_WORD (&dlc[1], GET_WORD (&dlc[1]) + 2);
  7511. dlc[3] = 0x08;
  7512. dlc[4] = 0x01;
  7513. dlc[5] = 127;
  7514. dlc[6] = 7;
  7515. if (b2_config->length != 0)
  7516. {
  7517. if((llc[1]==V120_V42BIS) && api_parse(&b2_config->info[1], (word)b2_config->length, "bbbbwww", b2_config_parms)) {
  7518. return _WRONG_MESSAGE_FORMAT;
  7519. }
  7520. dlc[3] = (byte)((b2_config->info[2] << 3) | ((b2_config->info[1] >> 5) & 0x04));
  7521. dlc[4] = (byte)((b2_config->info[1] << 1) | 0x01);
  7522. if (b2_config->info[3] != 128)
  7523. {
  7524. dbug(1,dprintf("1D-dlc= %x %x %x %x %x", dlc[0], dlc[1], dlc[2], dlc[3], dlc[4]));
  7525. return _B2_PARM_NOT_SUPPORTED;
  7526. }
  7527. dlc[5] = (byte)(b2_config->info[3] - 1);
  7528. dlc[6] = b2_config->info[4];
  7529. if(llc[1]==V120_V42BIS){
  7530. if (b2_config->length >= 10){
  7531. dlc[ 7] = 6;
  7532. dlc[ 8] = 0;
  7533. dlc[ 9] = b2_config_parms[4].info[0];
  7534. dlc[10] = b2_config_parms[4].info[1];
  7535. dlc[11] = b2_config_parms[5].info[0];
  7536. dlc[12] = b2_config_parms[5].info[1];
  7537. dlc[13] = b2_config_parms[6].info[0];
  7538. dlc[14] = b2_config_parms[6].info[1];
  7539. dlc[ 0] = 14;
  7540. dbug(1,dprintf("b2_config_parms[4].info[0] [1]: %x %x", b2_config_parms[4].info[0], b2_config_parms[4].info[1]));
  7541. dbug(1,dprintf("b2_config_parms[5].info[0] [1]: %x %x", b2_config_parms[5].info[0], b2_config_parms[5].info[1]));
  7542. dbug(1,dprintf("b2_config_parms[6].info[0] [1]: %x %x", b2_config_parms[6].info[0], b2_config_parms[6].info[1]));
  7543. }
  7544. else {
  7545. dlc[ 6] = 14;
  7546. }
  7547. }
  7548. }
  7549. }
  7550. else
  7551. {
  7552. if(b2_config->length)
  7553. {
  7554. dbug(1,dprintf("B2-Config"));
  7555. if(llc[1]==X75_V42BIS){
  7556. if(api_parse(&b2_config->info[1], (word)b2_config->length, "bbbbwww", b2_config_parms))
  7557. {
  7558. return _WRONG_MESSAGE_FORMAT;
  7559. }
  7560. }
  7561. else {
  7562. if(api_parse(&b2_config->info[1], (word)b2_config->length, "bbbbs", b2_config_parms))
  7563. {
  7564. return _WRONG_MESSAGE_FORMAT;
  7565. }
  7566. }
  7567. /* if B2 Protocol is LAPD, b2_config structure is different */
  7568. if(llc[1]==6)
  7569. {
  7570. dlc[0] = 4;
  7571. if(b2_config->length>=1) dlc[2] = b2_config->info[1]; /* TEI */
  7572. else dlc[2] = 0x01;
  7573. if( (b2_config->length>=2) && (plci->B2_prot==12) )
  7574. {
  7575. SAPI = b2_config->info[2]; /* SAPI */
  7576. }
  7577. dlc[1] = SAPI;
  7578. if( (b2_config->length>=3) && (b2_config->info[3]==128) )
  7579. {
  7580. dlc[3] = 127; /* Mode */
  7581. }
  7582. else
  7583. {
  7584. dlc[3] = 7; /* Mode */
  7585. }
  7586. if(b2_config->length>=4) dlc[4] = b2_config->info[4]; /* Window */
  7587. else dlc[4] = 1;
  7588. dbug(1,dprintf("D-dlc[%d]=%x,%x,%x,%x", dlc[0], dlc[1], dlc[2], dlc[3], dlc[4]));
  7589. if(b2_config->length>5) return _B2_PARM_NOT_SUPPORTED;
  7590. }
  7591. else
  7592. {
  7593. dlc[0] = (byte)(b2_config_parms[4].length+6);
  7594. dlc[3] = b2_config->info[1];
  7595. dlc[4] = b2_config->info[2];
  7596. if(b2_config->info[3]!=8 && b2_config->info[3]!=128){
  7597. dbug(1,dprintf("1D-dlc= %x %x %x %x %x", dlc[0], dlc[1], dlc[2], dlc[3], dlc[4]));
  7598. return _B2_PARM_NOT_SUPPORTED;
  7599. }
  7600. dlc[5] = (byte)(b2_config->info[3]-1);
  7601. dlc[6] = b2_config->info[4];
  7602. if(dlc[6]>dlc[5]){
  7603. dbug(1,dprintf("2D-dlc= %x %x %x %x %x %x %x", dlc[0], dlc[1], dlc[2], dlc[3], dlc[4], dlc[5], dlc[6]));
  7604. return _B2_PARM_NOT_SUPPORTED;
  7605. }
  7606. if(llc[1]==X75_V42BIS) {
  7607. if (b2_config->length >= 10){
  7608. dlc[ 7] = 6;
  7609. dlc[ 8] = 0;
  7610. dlc[ 9] = b2_config_parms[4].info[0];
  7611. dlc[10] = b2_config_parms[4].info[1];
  7612. dlc[11] = b2_config_parms[5].info[0];
  7613. dlc[12] = b2_config_parms[5].info[1];
  7614. dlc[13] = b2_config_parms[6].info[0];
  7615. dlc[14] = b2_config_parms[6].info[1];
  7616. dlc[ 0] = 14;
  7617. dbug(1,dprintf("b2_config_parms[4].info[0] [1]: %x %x", b2_config_parms[4].info[0], b2_config_parms[4].info[1]));
  7618. dbug(1,dprintf("b2_config_parms[5].info[0] [1]: %x %x", b2_config_parms[5].info[0], b2_config_parms[5].info[1]));
  7619. dbug(1,dprintf("b2_config_parms[6].info[0] [1]: %x %x", b2_config_parms[6].info[0], b2_config_parms[6].info[1]));
  7620. }
  7621. else {
  7622. dlc[ 6] = 14;
  7623. }
  7624. }
  7625. else {
  7626. PUT_WORD(&dlc[7], (word)b2_config_parms[4].length);
  7627. for(i=0; i<b2_config_parms[4].length; i++)
  7628. dlc[11+i] = b2_config_parms[4].info[1+i];
  7629. }
  7630. }
  7631. }
  7632. }
  7633. add_p(plci, DLC, dlc);
  7634. b3_config = &bp_parms[5];
  7635. if(b3_config->length)
  7636. {
  7637. if(plci->B3_prot == 4
  7638. || plci->B3_prot == 5)
  7639. {
  7640. if(api_parse(&b3_config->info[1], (word)b3_config->length, "wwss", b3_config_parms))
  7641. {
  7642. return _WRONG_MESSAGE_FORMAT;
  7643. }
  7644. i = GET_WORD((byte *)(b3_config_parms[0].info));
  7645. ((T30_INFO *)&nlc[1])->resolution = (byte)(((i & 0x0001) ||
  7646. ((plci->B3_prot == 4) && (((byte)(GET_WORD((byte *)b3_config_parms[1].info))) != 5))) ? T30_RESOLUTION_R8_0770_OR_200 : 0);
  7647. ((T30_INFO *)&nlc[1])->data_format = (byte)(GET_WORD((byte *)b3_config_parms[1].info));
  7648. fax_control_bits = T30_CONTROL_BIT_ALL_FEATURES;
  7649. if ((((T30_INFO *)&nlc[1])->rate_div_2400 != 0) && (((T30_INFO *)&nlc[1])->rate_div_2400 <= 6))
  7650. fax_control_bits &= ~T30_CONTROL_BIT_ENABLE_V34FAX;
  7651. if (plci->adapter->manufacturer_features & MANUFACTURER_FEATURE_FAX_PAPER_FORMATS)
  7652. {
  7653. if ((plci->requested_options_conn | plci->requested_options | plci->adapter->requested_options_table[plci->appl->Id-1])
  7654. & (1L << PRIVATE_FAX_PAPER_FORMATS))
  7655. {
  7656. ((T30_INFO *)&nlc[1])->resolution |= T30_RESOLUTION_R8_1540 |
  7657. T30_RESOLUTION_R16_1540_OR_400 | T30_RESOLUTION_300_300 |
  7658. T30_RESOLUTION_INCH_BASED | T30_RESOLUTION_METRIC_BASED;
  7659. }
  7660. ((T30_INFO *)&nlc[1])->recording_properties =
  7661. T30_RECORDING_WIDTH_ISO_A3 |
  7662. (T30_RECORDING_LENGTH_UNLIMITED << 2) |
  7663. (T30_MIN_SCANLINE_TIME_00_00_00 << 4);
  7664. }
  7665. if(plci->B3_prot == 5)
  7666. {
  7667. if (i & 0x0002) /* Accept incoming fax-polling requests */
  7668. fax_control_bits |= T30_CONTROL_BIT_ACCEPT_POLLING;
  7669. if (i & 0x2000) /* Do not use MR compression */
  7670. fax_control_bits &= ~T30_CONTROL_BIT_ENABLE_2D_CODING;
  7671. if (i & 0x4000) /* Do not use MMR compression */
  7672. fax_control_bits &= ~T30_CONTROL_BIT_ENABLE_T6_CODING;
  7673. if (i & 0x8000) /* Do not use ECM */
  7674. fax_control_bits &= ~T30_CONTROL_BIT_ENABLE_ECM;
  7675. if (plci->fax_connect_info_length != 0)
  7676. {
  7677. ((T30_INFO *)&nlc[1])->resolution = ((T30_INFO *)plci->fax_connect_info_buffer)->resolution;
  7678. ((T30_INFO *)&nlc[1])->data_format = ((T30_INFO *)plci->fax_connect_info_buffer)->data_format;
  7679. ((T30_INFO *)&nlc[1])->recording_properties = ((T30_INFO *)plci->fax_connect_info_buffer)->recording_properties;
  7680. fax_control_bits |= GET_WORD(&((T30_INFO *)plci->fax_connect_info_buffer)->control_bits_low) &
  7681. (T30_CONTROL_BIT_REQUEST_POLLING | T30_CONTROL_BIT_MORE_DOCUMENTS);
  7682. }
  7683. }
  7684. /* copy station id to NLC */
  7685. for(i=0; i<20; i++)
  7686. {
  7687. if(i<b3_config_parms[2].length)
  7688. {
  7689. ((T30_INFO *)&nlc[1])->station_id[i] = ((byte *)b3_config_parms[2].info)[1+i];
  7690. }
  7691. else
  7692. {
  7693. ((T30_INFO *)&nlc[1])->station_id[i] = ' ';
  7694. }
  7695. }
  7696. ((T30_INFO *)&nlc[1])->station_id_len = 20;
  7697. /* copy head line to NLC */
  7698. if(b3_config_parms[3].length)
  7699. {
  7700. pos = (byte)(fax_head_line_time (&(((T30_INFO *)&nlc[1])->station_id[20])));
  7701. if (pos != 0)
  7702. {
  7703. if (CAPI_MAX_DATE_TIME_LENGTH + 2 + b3_config_parms[3].length > CAPI_MAX_HEAD_LINE_SPACE)
  7704. pos = 0;
  7705. else
  7706. {
  7707. ((T30_INFO *)&nlc[1])->station_id[20 + pos++] = ' ';
  7708. ((T30_INFO *)&nlc[1])->station_id[20 + pos++] = ' ';
  7709. len = (byte)b3_config_parms[2].length;
  7710. if (len > 20)
  7711. len = 20;
  7712. if (CAPI_MAX_DATE_TIME_LENGTH + 2 + len + 2 + b3_config_parms[3].length <= CAPI_MAX_HEAD_LINE_SPACE)
  7713. {
  7714. for (i = 0; i < len; i++)
  7715. ((T30_INFO *)&nlc[1])->station_id[20 + pos++] = ((byte *)b3_config_parms[2].info)[1+i];
  7716. ((T30_INFO *)&nlc[1])->station_id[20 + pos++] = ' ';
  7717. ((T30_INFO *)&nlc[1])->station_id[20 + pos++] = ' ';
  7718. }
  7719. }
  7720. }
  7721. len = (byte)b3_config_parms[3].length;
  7722. if (len > CAPI_MAX_HEAD_LINE_SPACE - pos)
  7723. len = (byte)(CAPI_MAX_HEAD_LINE_SPACE - pos);
  7724. ((T30_INFO *)&nlc[1])->head_line_len = (byte)(pos + len);
  7725. nlc[0] += (byte)(pos + len);
  7726. for (i = 0; i < len; i++)
  7727. ((T30_INFO *)&nlc[1])->station_id[20 + pos++] = ((byte *)b3_config_parms[3].info)[1+i];
  7728. }
  7729. else
  7730. ((T30_INFO *)&nlc[1])->head_line_len = 0;
  7731. plci->nsf_control_bits = 0;
  7732. if(plci->B3_prot == 5)
  7733. {
  7734. if ((plci->adapter->man_profile.private_options & (1L << PRIVATE_FAX_SUB_SEP_PWD))
  7735. && (GET_WORD((byte *)b3_config_parms[1].info) & 0x8000)) /* Private SUB/SEP/PWD enable */
  7736. {
  7737. plci->requested_options |= 1L << PRIVATE_FAX_SUB_SEP_PWD;
  7738. }
  7739. if ((plci->adapter->man_profile.private_options & (1L << PRIVATE_FAX_NONSTANDARD))
  7740. && (GET_WORD((byte *)b3_config_parms[1].info) & 0x4000)) /* Private non-standard facilities enable */
  7741. {
  7742. plci->requested_options |= 1L << PRIVATE_FAX_NONSTANDARD;
  7743. }
  7744. if ((plci->requested_options_conn | plci->requested_options | plci->adapter->requested_options_table[plci->appl->Id-1])
  7745. & ((1L << PRIVATE_FAX_SUB_SEP_PWD) | (1L << PRIVATE_FAX_NONSTANDARD)))
  7746. {
  7747. if ((plci->requested_options_conn | plci->requested_options | plci->adapter->requested_options_table[plci->appl->Id-1])
  7748. & (1L << PRIVATE_FAX_SUB_SEP_PWD))
  7749. {
  7750. fax_control_bits |= T30_CONTROL_BIT_ACCEPT_SUBADDRESS | T30_CONTROL_BIT_ACCEPT_PASSWORD;
  7751. if (fax_control_bits & T30_CONTROL_BIT_ACCEPT_POLLING)
  7752. fax_control_bits |= T30_CONTROL_BIT_ACCEPT_SEL_POLLING;
  7753. }
  7754. len = nlc[0];
  7755. pos = ((byte)(((T30_INFO *) 0)->station_id + 20));
  7756. if (pos < plci->fax_connect_info_length)
  7757. {
  7758. for (i = 1 + plci->fax_connect_info_buffer[pos]; i != 0; i--)
  7759. nlc[++len] = plci->fax_connect_info_buffer[pos++];
  7760. }
  7761. else
  7762. nlc[++len] = 0;
  7763. if (pos < plci->fax_connect_info_length)
  7764. {
  7765. for (i = 1 + plci->fax_connect_info_buffer[pos]; i != 0; i--)
  7766. nlc[++len] = plci->fax_connect_info_buffer[pos++];
  7767. }
  7768. else
  7769. nlc[++len] = 0;
  7770. if ((plci->requested_options_conn | plci->requested_options | plci->adapter->requested_options_table[plci->appl->Id-1])
  7771. & (1L << PRIVATE_FAX_NONSTANDARD))
  7772. {
  7773. if ((pos < plci->fax_connect_info_length) && (plci->fax_connect_info_buffer[pos] != 0))
  7774. {
  7775. if ((plci->fax_connect_info_buffer[pos] >= 3) && (plci->fax_connect_info_buffer[pos+1] >= 2))
  7776. plci->nsf_control_bits = GET_WORD(&plci->fax_connect_info_buffer[pos+2]);
  7777. for (i = 1 + plci->fax_connect_info_buffer[pos]; i != 0; i--)
  7778. nlc[++len] = plci->fax_connect_info_buffer[pos++];
  7779. }
  7780. else
  7781. {
  7782. if(api_parse(&b3_config->info[1], (word)b3_config->length, "wwsss", b3_config_parms))
  7783. {
  7784. dbug(1,dprintf("non-standard facilities info missing or wrong format"));
  7785. nlc[++len] = 0;
  7786. }
  7787. else
  7788. {
  7789. if ((b3_config_parms[4].length >= 3) && (b3_config_parms[4].info[1] >= 2))
  7790. plci->nsf_control_bits = GET_WORD(&b3_config_parms[4].info[2]);
  7791. nlc[++len] = (byte)(b3_config_parms[4].length);
  7792. for (i = 0; i < b3_config_parms[4].length; i++)
  7793. nlc[++len] = b3_config_parms[4].info[1+i];
  7794. }
  7795. }
  7796. }
  7797. nlc[0] = len;
  7798. if ((plci->nsf_control_bits & T30_NSF_CONTROL_BIT_ENABLE_NSF)
  7799. && (plci->nsf_control_bits & T30_NSF_CONTROL_BIT_NEGOTIATE_RESP))
  7800. {
  7801. ((T30_INFO *)&nlc[1])->operating_mode = T30_OPERATING_MODE_CAPI_NEG;
  7802. }
  7803. }
  7804. }
  7805. PUT_WORD(&(((T30_INFO *)&nlc[1])->control_bits_low), fax_control_bits);
  7806. len = ((byte)(((T30_INFO *) 0)->station_id + 20));
  7807. for (i = 0; i < len; i++)
  7808. plci->fax_connect_info_buffer[i] = nlc[1+i];
  7809. ((T30_INFO *) plci->fax_connect_info_buffer)->head_line_len = 0;
  7810. i += ((T30_INFO *)&nlc[1])->head_line_len;
  7811. while (i < nlc[0])
  7812. plci->fax_connect_info_buffer[len++] = nlc[++i];
  7813. plci->fax_connect_info_length = len;
  7814. }
  7815. else
  7816. {
  7817. nlc[0] = 14;
  7818. if(b3_config->length!=16)
  7819. return _B3_PARM_NOT_SUPPORTED;
  7820. for(i=0; i<12; i++) nlc[1+i] = b3_config->info[1+i];
  7821. if(GET_WORD(&b3_config->info[13])!=8 && GET_WORD(&b3_config->info[13])!=128)
  7822. return _B3_PARM_NOT_SUPPORTED;
  7823. nlc[13] = b3_config->info[13];
  7824. if(GET_WORD(&b3_config->info[15])>=nlc[13])
  7825. return _B3_PARM_NOT_SUPPORTED;
  7826. nlc[14] = b3_config->info[15];
  7827. }
  7828. }
  7829. else
  7830. {
  7831. if (plci->B3_prot == 4
  7832. || plci->B3_prot == 5 /*T.30 - FAX*/ ) return _B3_PARM_NOT_SUPPORTED;
  7833. }
  7834. add_p(plci, NLC, nlc);
  7835. return 0;
  7836. }
  7837. /*----------------------------------------------------------------*/
  7838. /* make the same as add_b23, but only for the modem related */
  7839. /* L2 and L3 B-Chan protocol. */
  7840. /* */
  7841. /* Enabled L2 and L3 Configurations: */
  7842. /* If L1 == Modem all negotiation */
  7843. /* only L2 == Modem with full negotiation is allowed */
  7844. /* If L1 == Modem async or sync */
  7845. /* only L2 == Transparent is allowed */
  7846. /* L3 == Modem or L3 == Transparent are allowed */
  7847. /* B2 Configuration for modem: */
  7848. /* word : enable/disable compression, bitoptions */
  7849. /* B3 Configuration for modem: */
  7850. /* empty */
  7851. /*----------------------------------------------------------------*/
  7852. static word add_modem_b23 (PLCI * plci, API_PARSE* bp_parms)
  7853. {
  7854. static byte lli[12] = {1,1};
  7855. static byte llc[3] = {2,0,0};
  7856. static byte dlc[16] = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
  7857. API_PARSE mdm_config[2];
  7858. word i;
  7859. word b2_config = 0;
  7860. for(i=0;i<2;i++) mdm_config[i].length = 0;
  7861. for(i=0;i<sizeof(dlc);i++) dlc[i] = 0;
  7862. if (((GET_WORD(bp_parms[0].info) == B1_MODEM_ALL_NEGOTIATE)
  7863. && (GET_WORD(bp_parms[1].info) != B2_MODEM_EC_COMPRESSION))
  7864. || ((GET_WORD(bp_parms[0].info) != B1_MODEM_ALL_NEGOTIATE)
  7865. && (GET_WORD(bp_parms[1].info) != B2_TRANSPARENT)))
  7866. {
  7867. return (_B_STACK_NOT_SUPPORTED);
  7868. }
  7869. if ((GET_WORD(bp_parms[2].info) != B3_MODEM)
  7870. && (GET_WORD(bp_parms[2].info) != B3_TRANSPARENT))
  7871. {
  7872. return (_B_STACK_NOT_SUPPORTED);
  7873. }
  7874. plci->B2_prot = (byte) GET_WORD(bp_parms[1].info);
  7875. plci->B3_prot = (byte) GET_WORD(bp_parms[2].info);
  7876. if ((GET_WORD(bp_parms[1].info) == B2_MODEM_EC_COMPRESSION) && bp_parms[4].length)
  7877. {
  7878. if (api_parse (&bp_parms[4].info[1],
  7879. (word)bp_parms[4].length, "w",
  7880. mdm_config))
  7881. {
  7882. return (_WRONG_MESSAGE_FORMAT);
  7883. }
  7884. b2_config = GET_WORD(mdm_config[0].info);
  7885. }
  7886. /* OK, L2 is modem */
  7887. lli[0] = 1;
  7888. lli[1] = 1;
  7889. if (plci->adapter->manufacturer_features & MANUFACTURER_FEATURE_XONOFF_FLOW_CONTROL)
  7890. lli[1] |= 2;
  7891. if (plci->adapter->manufacturer_features & MANUFACTURER_FEATURE_OOB_CHANNEL)
  7892. lli[1] |= 4;
  7893. if ((lli[1] & 0x02) && (diva_xdi_extended_features & DIVA_CAPI_USE_CMA)) {
  7894. lli[1] |= 0x10;
  7895. if (plci->rx_dma_descriptor <= 0) {
  7896. plci->rx_dma_descriptor=diva_get_dma_descriptor(plci,&plci->rx_dma_magic);
  7897. if (plci->rx_dma_descriptor >= 0)
  7898. plci->rx_dma_descriptor++;
  7899. }
  7900. if (plci->rx_dma_descriptor > 0) {
  7901. lli[1] |= 0x40;
  7902. lli[0] = 6;
  7903. lli[2] = (byte)(plci->rx_dma_descriptor - 1);
  7904. lli[3] = (byte)plci->rx_dma_magic;
  7905. lli[4] = (byte)(plci->rx_dma_magic >> 8);
  7906. lli[5] = (byte)(plci->rx_dma_magic >> 16);
  7907. lli[6] = (byte)(plci->rx_dma_magic >> 24);
  7908. }
  7909. }
  7910. if (DIVA_CAPI_SUPPORTS_NO_CANCEL(plci->adapter)) {
  7911. lli[1] |= 0x20;
  7912. }
  7913. llc[1] = (plci->call_dir & (CALL_DIR_ORIGINATE | CALL_DIR_FORCE_OUTG_NL)) ?
  7914. /*V42*/ 10 : /*V42_IN*/ 9;
  7915. llc[2] = 4; /* pass L3 always transparent */
  7916. add_p(plci, LLI, lli);
  7917. add_p(plci, LLC, llc);
  7918. i = 1;
  7919. PUT_WORD (&dlc[i], plci->appl->MaxDataLength);
  7920. i += 2;
  7921. if (GET_WORD(bp_parms[1].info) == B2_MODEM_EC_COMPRESSION)
  7922. {
  7923. if (bp_parms[4].length)
  7924. {
  7925. dbug(1, dprintf("MDM b2_config=%02x", b2_config));
  7926. dlc[i++] = 3; /* Addr A */
  7927. dlc[i++] = 1; /* Addr B */
  7928. dlc[i++] = 7; /* modulo mode */
  7929. dlc[i++] = 7; /* window size */
  7930. dlc[i++] = 0; /* XID len Lo */
  7931. dlc[i++] = 0; /* XID len Hi */
  7932. if (b2_config & MDM_B2_DISABLE_V42bis)
  7933. {
  7934. dlc[i] |= DLC_MODEMPROT_DISABLE_V42_V42BIS;
  7935. }
  7936. if (b2_config & MDM_B2_DISABLE_MNP)
  7937. {
  7938. dlc[i] |= DLC_MODEMPROT_DISABLE_MNP_MNP5;
  7939. }
  7940. if (b2_config & MDM_B2_DISABLE_TRANS)
  7941. {
  7942. dlc[i] |= DLC_MODEMPROT_REQUIRE_PROTOCOL;
  7943. }
  7944. if (b2_config & MDM_B2_DISABLE_V42)
  7945. {
  7946. dlc[i] |= DLC_MODEMPROT_DISABLE_V42_DETECT;
  7947. }
  7948. if (b2_config & MDM_B2_DISABLE_COMP)
  7949. {
  7950. dlc[i] |= DLC_MODEMPROT_DISABLE_COMPRESSION;
  7951. }
  7952. i++;
  7953. }
  7954. }
  7955. else
  7956. {
  7957. dlc[i++] = 3; /* Addr A */
  7958. dlc[i++] = 1; /* Addr B */
  7959. dlc[i++] = 7; /* modulo mode */
  7960. dlc[i++] = 7; /* window size */
  7961. dlc[i++] = 0; /* XID len Lo */
  7962. dlc[i++] = 0; /* XID len Hi */
  7963. dlc[i++] = DLC_MODEMPROT_DISABLE_V42_V42BIS |
  7964. DLC_MODEMPROT_DISABLE_MNP_MNP5 |
  7965. DLC_MODEMPROT_DISABLE_V42_DETECT |
  7966. DLC_MODEMPROT_DISABLE_COMPRESSION;
  7967. }
  7968. dlc[0] = (byte)(i - 1);
  7969. /* HexDump ("DLC", sizeof(dlc), &dlc[0]); */
  7970. add_p(plci, DLC, dlc);
  7971. return (0);
  7972. }
  7973. /*------------------------------------------------------------------*/
  7974. /* send a request for the signaling entity */
  7975. /*------------------------------------------------------------------*/
  7976. void sig_req(PLCI * plci, byte req, byte Id)
  7977. {
  7978. if(!plci) return;
  7979. if(plci->adapter->adapter_disabled) return;
  7980. dbug(1,dprintf("sig_req(%x)",req));
  7981. if (req == REMOVE)
  7982. plci->sig_remove_id = plci->Sig.Id;
  7983. if(plci->req_in==plci->req_in_start) {
  7984. plci->req_in +=2;
  7985. plci->RBuffer[plci->req_in++] = 0;
  7986. }
  7987. PUT_WORD(&plci->RBuffer[plci->req_in_start], plci->req_in-plci->req_in_start-2);
  7988. plci->RBuffer[plci->req_in++] = Id; /* sig/nl flag */
  7989. plci->RBuffer[plci->req_in++] = req; /* request */
  7990. plci->RBuffer[plci->req_in++] = 0; /* channel */
  7991. plci->req_in_start = plci->req_in;
  7992. }
  7993. /*------------------------------------------------------------------*/
  7994. /* send a request for the network layer entity */
  7995. /*------------------------------------------------------------------*/
  7996. static void nl_req_ncci(PLCI *plci, byte req, byte ncci)
  7997. {
  7998. if(!plci) return;
  7999. if(plci->adapter->adapter_disabled) return;
  8000. dbug(1,dprintf("nl_req %02x %02x %02x", plci->Id, req, ncci));
  8001. if (req == REMOVE)
  8002. {
  8003. plci->nl_remove_id = plci->NL.Id;
  8004. ncci_remove (plci, 0, (byte)(ncci != 0));
  8005. ncci = 0;
  8006. }
  8007. if(plci->req_in==plci->req_in_start) {
  8008. plci->req_in +=2;
  8009. plci->RBuffer[plci->req_in++] = 0;
  8010. }
  8011. PUT_WORD(&plci->RBuffer[plci->req_in_start], plci->req_in-plci->req_in_start-2);
  8012. plci->RBuffer[plci->req_in++] = 1; /* sig/nl flag */
  8013. plci->RBuffer[plci->req_in++] = req; /* request */
  8014. plci->RBuffer[plci->req_in++] = plci->adapter->ncci_ch[ncci]; /* channel */
  8015. plci->req_in_start = plci->req_in;
  8016. }
  8017. static void send_req(PLCI *plci)
  8018. {
  8019. ENTITY * e;
  8020. word l;
  8021. /* word i; */
  8022. if(!plci) return;
  8023. if(plci->adapter->adapter_disabled) return;
  8024. channel_xmit_xon (plci);
  8025. /* if nothing to do, return */
  8026. if(plci->req_in==plci->req_out) return;
  8027. dbug(1,dprintf("send_req(in=%d,out=%d)",plci->req_in,plci->req_out));
  8028. if(plci->nl_req || plci->sig_req) return;
  8029. l = GET_WORD(&plci->RBuffer[plci->req_out]);
  8030. plci->req_out += 2;
  8031. plci->XData[0].P = &plci->RBuffer[plci->req_out];
  8032. plci->req_out += l;
  8033. if(plci->RBuffer[plci->req_out]==1)
  8034. {
  8035. e = &plci->NL;
  8036. plci->req_out++;
  8037. e->Req = plci->nl_req = plci->RBuffer[plci->req_out++];
  8038. e->ReqCh = plci->RBuffer[plci->req_out++];
  8039. if(!(e->Id & 0x1f))
  8040. {
  8041. e->Id = NL_ID;
  8042. plci->RBuffer[plci->req_out-4] = CAI;
  8043. plci->RBuffer[plci->req_out-3] = 1;
  8044. plci->RBuffer[plci->req_out-2] = (plci->Sig.Id==0xff) ? 0 : plci->Sig.Id;
  8045. plci->RBuffer[plci->req_out-1] = 0;
  8046. l+=3;
  8047. plci->nl_global_req = plci->nl_req;
  8048. }
  8049. dbug(1,dprintf("%x:NLREQ(%x:%x:%x)",plci->adapter->Id,e->Id,e->Req,e->ReqCh));
  8050. }
  8051. else
  8052. {
  8053. e = &plci->Sig;
  8054. if(plci->RBuffer[plci->req_out])
  8055. e->Id = plci->RBuffer[plci->req_out];
  8056. plci->req_out++;
  8057. e->Req = plci->sig_req = plci->RBuffer[plci->req_out++];
  8058. e->ReqCh = plci->RBuffer[plci->req_out++];
  8059. if(!(e->Id & 0x1f))
  8060. plci->sig_global_req = plci->sig_req;
  8061. dbug(1,dprintf("%x:SIGREQ(%x:%x:%x)",plci->adapter->Id,e->Id,e->Req,e->ReqCh));
  8062. }
  8063. plci->XData[0].PLength = l;
  8064. e->X = plci->XData;
  8065. plci->adapter->request(e);
  8066. dbug(1,dprintf("send_ok"));
  8067. }
  8068. void send_data(PLCI * plci)
  8069. {
  8070. DIVA_CAPI_ADAPTER * a;
  8071. DATA_B3_DESC * data;
  8072. NCCI *ncci_ptr;
  8073. word ncci;
  8074. if (!plci->nl_req && plci->ncci_ring_list)
  8075. {
  8076. a = plci->adapter;
  8077. ncci = plci->ncci_ring_list;
  8078. do
  8079. {
  8080. ncci = a->ncci_next[ncci];
  8081. ncci_ptr = &(a->ncci[ncci]);
  8082. if (!(a->ncci_ch[ncci]
  8083. && (a->ch_flow_control[a->ncci_ch[ncci]] & N_OK_FC_PENDING)))
  8084. {
  8085. if (ncci_ptr->data_pending)
  8086. {
  8087. if ((a->ncci_state[ncci] == CONNECTED)
  8088. || (a->ncci_state[ncci] == INC_ACT_PENDING)
  8089. || (plci->send_disc == ncci))
  8090. {
  8091. data = &(ncci_ptr->DBuffer[ncci_ptr->data_out]);
  8092. if ((plci->B2_prot == B2_V120_ASYNC)
  8093. || (plci->B2_prot == B2_V120_ASYNC_V42BIS)
  8094. || (plci->B2_prot == B2_V120_BIT_TRANSPARENT))
  8095. {
  8096. plci->NData[1].P = TransmitBufferGet (plci->appl, data->P);
  8097. plci->NData[1].PLength = data->Length;
  8098. if (data->Flags & 0x10)
  8099. plci->NData[0].P = v120_break_header;
  8100. else
  8101. plci->NData[0].P = v120_default_header;
  8102. plci->NData[0].PLength = 1 ;
  8103. plci->NL.XNum = 2;
  8104. plci->NL.Req = plci->nl_req = (byte)((data->Flags&0x07)<<4 |N_DATA);
  8105. }
  8106. else
  8107. {
  8108. plci->NData[0].P = TransmitBufferGet (plci->appl, data->P);
  8109. plci->NData[0].PLength = data->Length;
  8110. if (data->Flags & 0x10)
  8111. plci->NL.Req = plci->nl_req = (byte)N_UDATA;
  8112. else if ((plci->B3_prot == B3_RTP) && (data->Flags & 0x01))
  8113. plci->NL.Req = plci->nl_req = (byte)N_BDATA;
  8114. else
  8115. plci->NL.Req = plci->nl_req = (byte)((data->Flags&0x07)<<4 |N_DATA);
  8116. }
  8117. plci->NL.X = plci->NData;
  8118. plci->NL.ReqCh = a->ncci_ch[ncci];
  8119. dbug(1,dprintf("%x:DREQ(%x:%x)",a->Id,plci->NL.Id,plci->NL.Req));
  8120. plci->data_sent = true;
  8121. plci->data_sent_ptr = data->P;
  8122. a->request(&plci->NL);
  8123. }
  8124. else {
  8125. cleanup_ncci_data (plci, ncci);
  8126. }
  8127. }
  8128. else if (plci->send_disc == ncci)
  8129. {
  8130. /* dprintf("N_DISC"); */
  8131. plci->NData[0].PLength = 0;
  8132. plci->NL.ReqCh = a->ncci_ch[ncci];
  8133. plci->NL.Req = plci->nl_req = N_DISC;
  8134. a->request(&plci->NL);
  8135. plci->command = _DISCONNECT_B3_R;
  8136. plci->send_disc = 0;
  8137. }
  8138. }
  8139. } while (!plci->nl_req && (ncci != plci->ncci_ring_list));
  8140. plci->ncci_ring_list = ncci;
  8141. }
  8142. }
  8143. static void listen_check(DIVA_CAPI_ADAPTER *a)
  8144. {
  8145. word i,j;
  8146. PLCI * plci;
  8147. byte activnotifiedcalls = 0;
  8148. dbug(1,dprintf("listen_check(%d,%d)",a->listen_active,a->max_listen));
  8149. if (!remove_started && !a->adapter_disabled)
  8150. {
  8151. for(i=0;i<a->max_plci;i++)
  8152. {
  8153. plci = &(a->plci[i]);
  8154. if(plci->notifiedcall) activnotifiedcalls++;
  8155. }
  8156. dbug(1,dprintf("listen_check(%d)",activnotifiedcalls));
  8157. for(i=a->listen_active; i < ((word)(a->max_listen+activnotifiedcalls)); i++) {
  8158. if((j=get_plci(a))) {
  8159. a->listen_active++;
  8160. plci = &a->plci[j-1];
  8161. plci->State = LISTENING;
  8162. add_p(plci,OAD,"\x01\xfd");
  8163. add_p(plci,KEY,"\x04\x43\x41\x32\x30");
  8164. add_p(plci,CAI,"\x01\xc0");
  8165. add_p(plci,UID,"\x06\x43\x61\x70\x69\x32\x30");
  8166. add_p(plci,LLI,"\x01\xc4"); /* support Dummy CR FAC + MWI + SpoofNotify */
  8167. add_p(plci,SHIFT|6,NULL);
  8168. add_p(plci,SIN,"\x02\x00\x00");
  8169. plci->internal_command = LISTEN_SIG_ASSIGN_PEND; /* do indicate_req if OK */
  8170. sig_req(plci,ASSIGN,DSIG_ID);
  8171. send_req(plci);
  8172. }
  8173. }
  8174. }
  8175. }
  8176. /*------------------------------------------------------------------*/
  8177. /* functions for all parameters sent in INDs */
  8178. /*------------------------------------------------------------------*/
  8179. static void IndParse(PLCI *plci, word *parms_id, byte **parms, byte multiIEsize)
  8180. {
  8181. word ploc; /* points to current location within packet */
  8182. byte w;
  8183. byte wlen;
  8184. byte codeset,lock;
  8185. byte * in;
  8186. word i;
  8187. word code;
  8188. word mIEindex = 0;
  8189. ploc = 0;
  8190. codeset = 0;
  8191. lock = 0;
  8192. in = plci->Sig.RBuffer->P;
  8193. for(i=0; i<parms_id[0]; i++) /* multiIE parms_id contains just the 1st */
  8194. { /* element but parms array is larger */
  8195. parms[i] = (byte *)"";
  8196. }
  8197. for(i=0; i<multiIEsize; i++)
  8198. {
  8199. parms[i] = (byte *)"";
  8200. }
  8201. while(ploc<plci->Sig.RBuffer->length-1) {
  8202. /* read information element id and length */
  8203. w = in[ploc];
  8204. if(w & 0x80) {
  8205. /* w &=0xf0; removed, cannot detect congestion levels */
  8206. /* upper 4 bit masked with w==SHIFT now */
  8207. wlen = 0;
  8208. }
  8209. else {
  8210. wlen = (byte)(in[ploc+1]+1);
  8211. }
  8212. /* check if length valid (not exceeding end of packet) */
  8213. if((ploc+wlen) > 270) return ;
  8214. if(lock & 0x80) lock &=0x7f;
  8215. else codeset = lock;
  8216. if((w&0xf0)==SHIFT) {
  8217. codeset = in[ploc];
  8218. if(!(codeset & 0x08)) lock = (byte)(codeset & 7);
  8219. codeset &=7;
  8220. lock |=0x80;
  8221. }
  8222. else {
  8223. if(w==ESC && wlen>=3) code = in[ploc+2] |0x800;
  8224. else code = w;
  8225. code |= (codeset<<8);
  8226. for(i=1; i<parms_id[0]+1 && parms_id[i]!=code; i++);
  8227. if(i<parms_id[0]+1) {
  8228. if(!multiIEsize) { /* with multiIEs use next field index, */
  8229. mIEindex = i-1; /* with normal IEs use same index like parms_id */
  8230. }
  8231. parms[mIEindex] = &in[ploc+1];
  8232. dbug(1,dprintf("mIE[%d]=0x%x",*parms[mIEindex],in[ploc]));
  8233. if(parms_id[i]==OAD
  8234. || parms_id[i]==CONN_NR
  8235. || parms_id[i]==CAD) {
  8236. if(in[ploc+2] &0x80) {
  8237. in[ploc+0] = (byte)(in[ploc+1]+1);
  8238. in[ploc+1] = (byte)(in[ploc+2] &0x7f);
  8239. in[ploc+2] = 0x80;
  8240. parms[mIEindex] = &in[ploc];
  8241. }
  8242. }
  8243. mIEindex++; /* effects multiIEs only */
  8244. }
  8245. }
  8246. ploc +=(wlen+1);
  8247. }
  8248. return ;
  8249. }
  8250. /*------------------------------------------------------------------*/
  8251. /* try to match a cip from received BC and HLC */
  8252. /*------------------------------------------------------------------*/
  8253. static byte ie_compare(byte *ie1, byte *ie2)
  8254. {
  8255. word i;
  8256. if(!ie1 || ! ie2) return false;
  8257. if(!ie1[0]) return false;
  8258. for(i=0;i<(word)(ie1[0]+1);i++) if(ie1[i]!=ie2[i]) return false;
  8259. return true;
  8260. }
  8261. static word find_cip(DIVA_CAPI_ADAPTER *a, byte *bc, byte *hlc)
  8262. {
  8263. word i;
  8264. word j;
  8265. for(i=9;i && !ie_compare(bc,cip_bc[i][a->u_law]);i--);
  8266. for(j=16;j<29 &&
  8267. (!ie_compare(bc,cip_bc[j][a->u_law]) || !ie_compare(hlc,cip_hlc[j])); j++);
  8268. if(j==29) return i;
  8269. return j;
  8270. }
  8271. static byte AddInfo(byte **add_i,
  8272. byte **fty_i,
  8273. byte *esc_chi,
  8274. byte *facility)
  8275. {
  8276. byte i;
  8277. byte j;
  8278. byte k;
  8279. byte flen;
  8280. byte len=0;
  8281. /* facility is a nested structure */
  8282. /* FTY can be more than once */
  8283. if (esc_chi[0] && !(esc_chi[esc_chi[0]] & 0x7f))
  8284. {
  8285. add_i[0] = (byte *)"\x02\x02\x00"; /* use neither b nor d channel */
  8286. }
  8287. else
  8288. {
  8289. add_i[0] = (byte *)"";
  8290. }
  8291. if(!fty_i[0][0])
  8292. {
  8293. add_i[3] = (byte *)"";
  8294. }
  8295. else
  8296. { /* facility array found */
  8297. for(i=0,j=1;i<MAX_MULTI_IE && fty_i[i][0];i++)
  8298. {
  8299. dbug(1,dprintf("AddIFac[%d]",fty_i[i][0]));
  8300. len += fty_i[i][0];
  8301. len += 2;
  8302. flen=fty_i[i][0];
  8303. facility[j++]=0x1c; /* copy fac IE */
  8304. for(k=0;k<=flen;k++,j++)
  8305. {
  8306. facility[j]=fty_i[i][k];
  8307. /* dbug(1,dprintf("%x ",facility[j])); */
  8308. }
  8309. }
  8310. facility[0] = len;
  8311. add_i[3] = facility;
  8312. }
  8313. /* dbug(1,dprintf("FacArrLen=%d ",len)); */
  8314. len = add_i[0][0]+add_i[1][0]+add_i[2][0]+add_i[3][0];
  8315. len += 4; /* calculate length of all */
  8316. return(len);
  8317. }
  8318. /*------------------------------------------------------------------*/
  8319. /* voice and codec features */
  8320. /*------------------------------------------------------------------*/
  8321. static void SetVoiceChannel(PLCI *plci, byte *chi, DIVA_CAPI_ADAPTER *a)
  8322. {
  8323. byte voice_chi[] = "\x02\x18\x01";
  8324. byte channel;
  8325. channel = chi[chi[0]]&0x3;
  8326. dbug(1,dprintf("ExtDevON(Ch=0x%x)",channel));
  8327. voice_chi[2] = (channel) ? channel : 1;
  8328. add_p(plci,FTY,"\x02\x01\x07"); /* B On, default on 1 */
  8329. add_p(plci,ESC,voice_chi); /* Channel */
  8330. sig_req(plci,TEL_CTRL,0);
  8331. send_req(plci);
  8332. if(a->AdvSignalPLCI)
  8333. {
  8334. adv_voice_write_coefs (a->AdvSignalPLCI, ADV_VOICE_WRITE_ACTIVATION);
  8335. }
  8336. }
  8337. static void VoiceChannelOff(PLCI *plci)
  8338. {
  8339. dbug(1,dprintf("ExtDevOFF"));
  8340. add_p(plci,FTY,"\x02\x01\x08"); /* B Off */
  8341. sig_req(plci,TEL_CTRL,0);
  8342. send_req(plci);
  8343. if(plci->adapter->AdvSignalPLCI)
  8344. {
  8345. adv_voice_clear_config (plci->adapter->AdvSignalPLCI);
  8346. }
  8347. }
  8348. static word AdvCodecSupport(DIVA_CAPI_ADAPTER *a, PLCI *plci, APPL *appl,
  8349. byte hook_listen)
  8350. {
  8351. word j;
  8352. PLCI *splci;
  8353. /* check if hardware supports handset with hook states (adv.codec) */
  8354. /* or if just a on board codec is supported */
  8355. /* the advanced codec plci is just for internal use */
  8356. /* diva Pro with on-board codec: */
  8357. if(a->profile.Global_Options & HANDSET)
  8358. {
  8359. /* new call, but hook states are already signalled */
  8360. if(a->AdvCodecFLAG)
  8361. {
  8362. if(a->AdvSignalAppl!=appl || a->AdvSignalPLCI)
  8363. {
  8364. dbug(1,dprintf("AdvSigPlci=0x%x",a->AdvSignalPLCI));
  8365. return 0x2001; /* codec in use by another application */
  8366. }
  8367. if(plci!=NULL)
  8368. {
  8369. a->AdvSignalPLCI = plci;
  8370. plci->tel=ADV_VOICE;
  8371. }
  8372. return 0; /* adv codec still used */
  8373. }
  8374. if((j=get_plci(a)))
  8375. {
  8376. splci = &a->plci[j-1];
  8377. splci->tel = CODEC_PERMANENT;
  8378. /* hook_listen indicates if a facility_req with handset/hook support */
  8379. /* was sent. Otherwise if just a call on an external device was made */
  8380. /* the codec will be used but the hook info will be discarded (just */
  8381. /* the external controller is in use */
  8382. if(hook_listen) splci->State = ADVANCED_VOICE_SIG;
  8383. else
  8384. {
  8385. splci->State = ADVANCED_VOICE_NOSIG;
  8386. if(plci)
  8387. {
  8388. plci->spoofed_msg = SPOOFING_REQUIRED;
  8389. }
  8390. /* indicate D-ch connect if */
  8391. } /* codec is connected OK */
  8392. if(plci!=NULL)
  8393. {
  8394. a->AdvSignalPLCI = plci;
  8395. plci->tel=ADV_VOICE;
  8396. }
  8397. a->AdvSignalAppl = appl;
  8398. a->AdvCodecFLAG = true;
  8399. a->AdvCodecPLCI = splci;
  8400. add_p(splci,CAI,"\x01\x15");
  8401. add_p(splci,LLI,"\x01\x00");
  8402. add_p(splci,ESC,"\x02\x18\x00");
  8403. add_p(splci,UID,"\x06\x43\x61\x70\x69\x32\x30");
  8404. splci->internal_command = PERM_COD_ASSIGN;
  8405. dbug(1,dprintf("Codec Assign"));
  8406. sig_req(splci,ASSIGN,DSIG_ID);
  8407. send_req(splci);
  8408. }
  8409. else
  8410. {
  8411. return 0x2001; /* wrong state, no more plcis */
  8412. }
  8413. }
  8414. else if(a->profile.Global_Options & ON_BOARD_CODEC)
  8415. {
  8416. if(hook_listen) return 0x300B; /* Facility not supported */
  8417. /* no hook with SCOM */
  8418. if(plci!=NULL) plci->tel = CODEC;
  8419. dbug(1,dprintf("S/SCOM codec"));
  8420. /* first time we use the scom-s codec we must shut down the internal */
  8421. /* handset application of the card. This can be done by an assign with */
  8422. /* a cai with the 0x80 bit set. Assign return code is 'out of resource'*/
  8423. if(!a->scom_appl_disable){
  8424. if((j=get_plci(a))) {
  8425. splci = &a->plci[j-1];
  8426. add_p(splci,CAI,"\x01\x80");
  8427. add_p(splci,UID,"\x06\x43\x61\x70\x69\x32\x30");
  8428. sig_req(splci,ASSIGN,0xC0); /* 0xc0 is the TEL_ID */
  8429. send_req(splci);
  8430. a->scom_appl_disable = true;
  8431. }
  8432. else{
  8433. return 0x2001; /* wrong state, no more plcis */
  8434. }
  8435. }
  8436. }
  8437. else return 0x300B; /* Facility not supported */
  8438. return 0;
  8439. }
  8440. static void CodecIdCheck(DIVA_CAPI_ADAPTER *a, PLCI *plci)
  8441. {
  8442. dbug(1,dprintf("CodecIdCheck"));
  8443. if(a->AdvSignalPLCI == plci)
  8444. {
  8445. dbug(1,dprintf("PLCI owns codec"));
  8446. VoiceChannelOff(a->AdvCodecPLCI);
  8447. if(a->AdvCodecPLCI->State == ADVANCED_VOICE_NOSIG)
  8448. {
  8449. dbug(1,dprintf("remove temp codec PLCI"));
  8450. plci_remove(a->AdvCodecPLCI);
  8451. a->AdvCodecFLAG = 0;
  8452. a->AdvCodecPLCI = NULL;
  8453. a->AdvSignalAppl = NULL;
  8454. }
  8455. a->AdvSignalPLCI = NULL;
  8456. }
  8457. }
  8458. /* -------------------------------------------------------------------
  8459. Ask for physical address of card on PCI bus
  8460. ------------------------------------------------------------------- */
  8461. static void diva_ask_for_xdi_sdram_bar (DIVA_CAPI_ADAPTER * a,
  8462. IDI_SYNC_REQ * preq) {
  8463. a->sdram_bar = 0;
  8464. if (diva_xdi_extended_features & DIVA_CAPI_XDI_PROVIDES_SDRAM_BAR) {
  8465. ENTITY * e = (ENTITY *)preq;
  8466. e->user[0] = a->Id - 1;
  8467. preq->xdi_sdram_bar.info.bar = 0;
  8468. preq->xdi_sdram_bar.Req = 0;
  8469. preq->xdi_sdram_bar.Rc = IDI_SYNC_REQ_XDI_GET_ADAPTER_SDRAM_BAR;
  8470. (*(a->request))(e);
  8471. a->sdram_bar = preq->xdi_sdram_bar.info.bar;
  8472. dbug(3,dprintf("A(%d) SDRAM BAR = %08x", a->Id, a->sdram_bar));
  8473. }
  8474. }
  8475. /* -------------------------------------------------------------------
  8476. Ask XDI about extended features
  8477. ------------------------------------------------------------------- */
  8478. static void diva_get_extended_adapter_features (DIVA_CAPI_ADAPTER * a) {
  8479. IDI_SYNC_REQ * preq;
  8480. char buffer[ ((sizeof(preq->xdi_extended_features)+4) > sizeof(ENTITY)) ? (sizeof(preq->xdi_extended_features)+4) : sizeof(ENTITY)];
  8481. char features[4];
  8482. preq = (IDI_SYNC_REQ *)&buffer[0];
  8483. if (!diva_xdi_extended_features) {
  8484. ENTITY * e = (ENTITY *)preq;
  8485. diva_xdi_extended_features |= 0x80000000;
  8486. e->user[0] = a->Id - 1;
  8487. preq->xdi_extended_features.Req = 0;
  8488. preq->xdi_extended_features.Rc = IDI_SYNC_REQ_XDI_GET_EXTENDED_FEATURES;
  8489. preq->xdi_extended_features.info.buffer_length_in_bytes = sizeof(features);
  8490. preq->xdi_extended_features.info.features = &features[0];
  8491. (*(a->request))(e);
  8492. if (features[0] & DIVA_XDI_EXTENDED_FEATURES_VALID) {
  8493. /*
  8494. Check features located in the byte '0'
  8495. */
  8496. if (features[0] & DIVA_XDI_EXTENDED_FEATURE_CMA) {
  8497. diva_xdi_extended_features |= DIVA_CAPI_USE_CMA;
  8498. }
  8499. if (features[0] & DIVA_XDI_EXTENDED_FEATURE_RX_DMA) {
  8500. diva_xdi_extended_features |= DIVA_CAPI_XDI_PROVIDES_RX_DMA;
  8501. dbug(1,dprintf("XDI provides RxDMA"));
  8502. }
  8503. if (features[0] & DIVA_XDI_EXTENDED_FEATURE_SDRAM_BAR) {
  8504. diva_xdi_extended_features |= DIVA_CAPI_XDI_PROVIDES_SDRAM_BAR;
  8505. }
  8506. if (features[0] & DIVA_XDI_EXTENDED_FEATURE_NO_CANCEL_RC) {
  8507. diva_xdi_extended_features |= DIVA_CAPI_XDI_PROVIDES_NO_CANCEL;
  8508. dbug(3,dprintf("XDI provides NO_CANCEL_RC feature"));
  8509. }
  8510. }
  8511. }
  8512. diva_ask_for_xdi_sdram_bar (a, preq);
  8513. }
  8514. /*------------------------------------------------------------------*/
  8515. /* automatic law */
  8516. /*------------------------------------------------------------------*/
  8517. /* called from OS specific part after init time to get the Law */
  8518. /* a-law (Euro) and u-law (us,japan) use different BCs in the Setup message */
  8519. void AutomaticLaw(DIVA_CAPI_ADAPTER *a)
  8520. {
  8521. word j;
  8522. PLCI *splci;
  8523. if(a->automatic_law) {
  8524. return;
  8525. }
  8526. if((j=get_plci(a))) {
  8527. diva_get_extended_adapter_features (a);
  8528. splci = &a->plci[j-1];
  8529. a->automatic_lawPLCI = splci;
  8530. a->automatic_law = 1;
  8531. add_p(splci,CAI,"\x01\x80");
  8532. add_p(splci,UID,"\x06\x43\x61\x70\x69\x32\x30");
  8533. splci->internal_command = USELAW_REQ;
  8534. splci->command = 0;
  8535. splci->number = 0;
  8536. sig_req(splci,ASSIGN,DSIG_ID);
  8537. send_req(splci);
  8538. }
  8539. }
  8540. /* called from OS specific part if an application sends an Capi20Release */
  8541. word CapiRelease(word Id)
  8542. {
  8543. word i, j, appls_found;
  8544. PLCI *plci;
  8545. APPL *this;
  8546. DIVA_CAPI_ADAPTER *a;
  8547. if (!Id)
  8548. {
  8549. dbug(0,dprintf("A: CapiRelease(Id==0)"));
  8550. return (_WRONG_APPL_ID);
  8551. }
  8552. this = &application[Id-1]; /* get application pointer */
  8553. for(i=0,appls_found=0; i<max_appl; i++)
  8554. {
  8555. if(application[i].Id) /* an application has been found */
  8556. {
  8557. appls_found++;
  8558. }
  8559. }
  8560. for(i=0; i<max_adapter; i++) /* scan all adapters... */
  8561. {
  8562. a = &adapter[i];
  8563. if (a->request)
  8564. {
  8565. a->Info_Mask[Id-1] = 0;
  8566. a->CIP_Mask[Id-1] = 0;
  8567. a->Notification_Mask[Id-1] = 0;
  8568. a->codec_listen[Id-1] = NULL;
  8569. a->requested_options_table[Id-1] = 0;
  8570. for(j=0; j<a->max_plci; j++) /* and all PLCIs connected */
  8571. { /* with this application */
  8572. plci = &a->plci[j];
  8573. if(plci->Id) /* if plci owns no application */
  8574. { /* it may be not jet connected */
  8575. if(plci->State==INC_CON_PENDING
  8576. || plci->State==INC_CON_ALERT)
  8577. {
  8578. if(test_c_ind_mask_bit (plci, (word)(Id-1)))
  8579. {
  8580. clear_c_ind_mask_bit (plci, (word)(Id-1));
  8581. if(c_ind_mask_empty (plci))
  8582. {
  8583. sig_req(plci,HANGUP,0);
  8584. send_req(plci);
  8585. plci->State = OUTG_DIS_PENDING;
  8586. }
  8587. }
  8588. }
  8589. if(test_c_ind_mask_bit (plci, (word)(Id-1)))
  8590. {
  8591. clear_c_ind_mask_bit (plci, (word)(Id-1));
  8592. if(c_ind_mask_empty (plci))
  8593. {
  8594. if(!plci->appl)
  8595. {
  8596. plci_remove(plci);
  8597. plci->State = IDLE;
  8598. }
  8599. }
  8600. }
  8601. if(plci->appl==this)
  8602. {
  8603. plci->appl = NULL;
  8604. plci_remove(plci);
  8605. plci->State = IDLE;
  8606. }
  8607. }
  8608. }
  8609. listen_check(a);
  8610. if(a->flag_dynamic_l1_down)
  8611. {
  8612. if(appls_found==1) /* last application does a capi release */
  8613. {
  8614. if((j=get_plci(a)))
  8615. {
  8616. plci = &a->plci[j-1];
  8617. plci->command = 0;
  8618. add_p(plci,OAD,"\x01\xfd");
  8619. add_p(plci,CAI,"\x01\x80");
  8620. add_p(plci,UID,"\x06\x43\x61\x70\x69\x32\x30");
  8621. add_p(plci,SHIFT|6,NULL);
  8622. add_p(plci,SIN,"\x02\x00\x00");
  8623. plci->internal_command = REM_L1_SIG_ASSIGN_PEND;
  8624. sig_req(plci,ASSIGN,DSIG_ID);
  8625. add_p(plci,FTY,"\x02\xff\x06"); /* l1 down */
  8626. sig_req(plci,SIG_CTRL,0);
  8627. send_req(plci);
  8628. }
  8629. }
  8630. }
  8631. if(a->AdvSignalAppl==this)
  8632. {
  8633. this->NullCREnable = false;
  8634. if (a->AdvCodecPLCI)
  8635. {
  8636. plci_remove(a->AdvCodecPLCI);
  8637. a->AdvCodecPLCI->tel = 0;
  8638. a->AdvCodecPLCI->adv_nl = 0;
  8639. }
  8640. a->AdvSignalAppl = NULL;
  8641. a->AdvSignalPLCI = NULL;
  8642. a->AdvCodecFLAG = 0;
  8643. a->AdvCodecPLCI = NULL;
  8644. }
  8645. }
  8646. }
  8647. this->Id = 0;
  8648. return GOOD;
  8649. }
  8650. static word plci_remove_check(PLCI *plci)
  8651. {
  8652. if(!plci) return true;
  8653. if(!plci->NL.Id && c_ind_mask_empty (plci))
  8654. {
  8655. if(plci->Sig.Id == 0xff)
  8656. plci->Sig.Id = 0;
  8657. if(!plci->Sig.Id)
  8658. {
  8659. dbug(1,dprintf("plci_remove_complete(%x)",plci->Id));
  8660. dbug(1,dprintf("tel=0x%x,Sig=0x%x",plci->tel,plci->Sig.Id));
  8661. if (plci->Id)
  8662. {
  8663. CodecIdCheck(plci->adapter, plci);
  8664. clear_b1_config (plci);
  8665. ncci_remove (plci, 0, false);
  8666. plci_free_msg_in_queue (plci);
  8667. channel_flow_control_remove (plci);
  8668. plci->Id = 0;
  8669. plci->State = IDLE;
  8670. plci->channels = 0;
  8671. plci->appl = NULL;
  8672. plci->notifiedcall = 0;
  8673. }
  8674. listen_check(plci->adapter);
  8675. return true;
  8676. }
  8677. }
  8678. return false;
  8679. }
  8680. /*------------------------------------------------------------------*/
  8681. static byte plci_nl_busy (PLCI *plci)
  8682. {
  8683. /* only applicable for non-multiplexed protocols */
  8684. return (plci->nl_req
  8685. || (plci->ncci_ring_list
  8686. && plci->adapter->ncci_ch[plci->ncci_ring_list]
  8687. && (plci->adapter->ch_flow_control[plci->adapter->ncci_ch[plci->ncci_ring_list]] & N_OK_FC_PENDING)));
  8688. }
  8689. /*------------------------------------------------------------------*/
  8690. /* DTMF facilities */
  8691. /*------------------------------------------------------------------*/
  8692. static struct
  8693. {
  8694. byte send_mask;
  8695. byte listen_mask;
  8696. byte character;
  8697. byte code;
  8698. } dtmf_digit_map[] =
  8699. {
  8700. { 0x01, 0x01, 0x23, DTMF_DIGIT_TONE_CODE_HASHMARK },
  8701. { 0x01, 0x01, 0x2a, DTMF_DIGIT_TONE_CODE_STAR },
  8702. { 0x01, 0x01, 0x30, DTMF_DIGIT_TONE_CODE_0 },
  8703. { 0x01, 0x01, 0x31, DTMF_DIGIT_TONE_CODE_1 },
  8704. { 0x01, 0x01, 0x32, DTMF_DIGIT_TONE_CODE_2 },
  8705. { 0x01, 0x01, 0x33, DTMF_DIGIT_TONE_CODE_3 },
  8706. { 0x01, 0x01, 0x34, DTMF_DIGIT_TONE_CODE_4 },
  8707. { 0x01, 0x01, 0x35, DTMF_DIGIT_TONE_CODE_5 },
  8708. { 0x01, 0x01, 0x36, DTMF_DIGIT_TONE_CODE_6 },
  8709. { 0x01, 0x01, 0x37, DTMF_DIGIT_TONE_CODE_7 },
  8710. { 0x01, 0x01, 0x38, DTMF_DIGIT_TONE_CODE_8 },
  8711. { 0x01, 0x01, 0x39, DTMF_DIGIT_TONE_CODE_9 },
  8712. { 0x01, 0x01, 0x41, DTMF_DIGIT_TONE_CODE_A },
  8713. { 0x01, 0x01, 0x42, DTMF_DIGIT_TONE_CODE_B },
  8714. { 0x01, 0x01, 0x43, DTMF_DIGIT_TONE_CODE_C },
  8715. { 0x01, 0x01, 0x44, DTMF_DIGIT_TONE_CODE_D },
  8716. { 0x01, 0x00, 0x61, DTMF_DIGIT_TONE_CODE_A },
  8717. { 0x01, 0x00, 0x62, DTMF_DIGIT_TONE_CODE_B },
  8718. { 0x01, 0x00, 0x63, DTMF_DIGIT_TONE_CODE_C },
  8719. { 0x01, 0x00, 0x64, DTMF_DIGIT_TONE_CODE_D },
  8720. { 0x04, 0x04, 0x80, DTMF_SIGNAL_NO_TONE },
  8721. { 0x00, 0x04, 0x81, DTMF_SIGNAL_UNIDENTIFIED_TONE },
  8722. { 0x04, 0x04, 0x82, DTMF_SIGNAL_DIAL_TONE },
  8723. { 0x04, 0x04, 0x83, DTMF_SIGNAL_PABX_INTERNAL_DIAL_TONE },
  8724. { 0x04, 0x04, 0x84, DTMF_SIGNAL_SPECIAL_DIAL_TONE },
  8725. { 0x04, 0x04, 0x85, DTMF_SIGNAL_SECOND_DIAL_TONE },
  8726. { 0x04, 0x04, 0x86, DTMF_SIGNAL_RINGING_TONE },
  8727. { 0x04, 0x04, 0x87, DTMF_SIGNAL_SPECIAL_RINGING_TONE },
  8728. { 0x04, 0x04, 0x88, DTMF_SIGNAL_BUSY_TONE },
  8729. { 0x04, 0x04, 0x89, DTMF_SIGNAL_CONGESTION_TONE },
  8730. { 0x04, 0x04, 0x8a, DTMF_SIGNAL_SPECIAL_INFORMATION_TONE },
  8731. { 0x04, 0x04, 0x8b, DTMF_SIGNAL_COMFORT_TONE },
  8732. { 0x04, 0x04, 0x8c, DTMF_SIGNAL_HOLD_TONE },
  8733. { 0x04, 0x04, 0x8d, DTMF_SIGNAL_RECORD_TONE },
  8734. { 0x04, 0x04, 0x8e, DTMF_SIGNAL_CALLER_WAITING_TONE },
  8735. { 0x04, 0x04, 0x8f, DTMF_SIGNAL_CALL_WAITING_TONE },
  8736. { 0x04, 0x04, 0x90, DTMF_SIGNAL_PAY_TONE },
  8737. { 0x04, 0x04, 0x91, DTMF_SIGNAL_POSITIVE_INDICATION_TONE },
  8738. { 0x04, 0x04, 0x92, DTMF_SIGNAL_NEGATIVE_INDICATION_TONE },
  8739. { 0x04, 0x04, 0x93, DTMF_SIGNAL_WARNING_TONE },
  8740. { 0x04, 0x04, 0x94, DTMF_SIGNAL_INTRUSION_TONE },
  8741. { 0x04, 0x04, 0x95, DTMF_SIGNAL_CALLING_CARD_SERVICE_TONE },
  8742. { 0x04, 0x04, 0x96, DTMF_SIGNAL_PAYPHONE_RECOGNITION_TONE },
  8743. { 0x04, 0x04, 0x97, DTMF_SIGNAL_CPE_ALERTING_SIGNAL },
  8744. { 0x04, 0x04, 0x98, DTMF_SIGNAL_OFF_HOOK_WARNING_TONE },
  8745. { 0x04, 0x04, 0xbf, DTMF_SIGNAL_INTERCEPT_TONE },
  8746. { 0x04, 0x04, 0xc0, DTMF_SIGNAL_MODEM_CALLING_TONE },
  8747. { 0x04, 0x04, 0xc1, DTMF_SIGNAL_FAX_CALLING_TONE },
  8748. { 0x04, 0x04, 0xc2, DTMF_SIGNAL_ANSWER_TONE },
  8749. { 0x04, 0x04, 0xc3, DTMF_SIGNAL_REVERSED_ANSWER_TONE },
  8750. { 0x04, 0x04, 0xc4, DTMF_SIGNAL_ANSAM_TONE },
  8751. { 0x04, 0x04, 0xc5, DTMF_SIGNAL_REVERSED_ANSAM_TONE },
  8752. { 0x04, 0x04, 0xc6, DTMF_SIGNAL_BELL103_ANSWER_TONE },
  8753. { 0x04, 0x04, 0xc7, DTMF_SIGNAL_FAX_FLAGS },
  8754. { 0x04, 0x04, 0xc8, DTMF_SIGNAL_G2_FAX_GROUP_ID },
  8755. { 0x00, 0x04, 0xc9, DTMF_SIGNAL_HUMAN_SPEECH },
  8756. { 0x04, 0x04, 0xca, DTMF_SIGNAL_ANSWERING_MACHINE_390 },
  8757. { 0x02, 0x02, 0xf1, DTMF_MF_DIGIT_TONE_CODE_1 },
  8758. { 0x02, 0x02, 0xf2, DTMF_MF_DIGIT_TONE_CODE_2 },
  8759. { 0x02, 0x02, 0xf3, DTMF_MF_DIGIT_TONE_CODE_3 },
  8760. { 0x02, 0x02, 0xf4, DTMF_MF_DIGIT_TONE_CODE_4 },
  8761. { 0x02, 0x02, 0xf5, DTMF_MF_DIGIT_TONE_CODE_5 },
  8762. { 0x02, 0x02, 0xf6, DTMF_MF_DIGIT_TONE_CODE_6 },
  8763. { 0x02, 0x02, 0xf7, DTMF_MF_DIGIT_TONE_CODE_7 },
  8764. { 0x02, 0x02, 0xf8, DTMF_MF_DIGIT_TONE_CODE_8 },
  8765. { 0x02, 0x02, 0xf9, DTMF_MF_DIGIT_TONE_CODE_9 },
  8766. { 0x02, 0x02, 0xfa, DTMF_MF_DIGIT_TONE_CODE_0 },
  8767. { 0x02, 0x02, 0xfb, DTMF_MF_DIGIT_TONE_CODE_K1 },
  8768. { 0x02, 0x02, 0xfc, DTMF_MF_DIGIT_TONE_CODE_K2 },
  8769. { 0x02, 0x02, 0xfd, DTMF_MF_DIGIT_TONE_CODE_KP },
  8770. { 0x02, 0x02, 0xfe, DTMF_MF_DIGIT_TONE_CODE_S1 },
  8771. { 0x02, 0x02, 0xff, DTMF_MF_DIGIT_TONE_CODE_ST },
  8772. };
  8773. #define DTMF_DIGIT_MAP_ENTRIES ARRAY_SIZE(dtmf_digit_map)
  8774. static void dtmf_enable_receiver (PLCI *plci, byte enable_mask)
  8775. {
  8776. word min_digit_duration, min_gap_duration;
  8777. dbug (1, dprintf ("[%06lx] %s,%d: dtmf_enable_receiver %02x",
  8778. (dword)((plci->Id << 8) | UnMapController (plci->adapter->Id)),
  8779. (char *)(FILE_), __LINE__, enable_mask));
  8780. if (enable_mask != 0)
  8781. {
  8782. min_digit_duration = (plci->dtmf_rec_pulse_ms == 0) ? 40 : plci->dtmf_rec_pulse_ms;
  8783. min_gap_duration = (plci->dtmf_rec_pause_ms == 0) ? 40 : plci->dtmf_rec_pause_ms;
  8784. plci->internal_req_buffer[0] = DTMF_UDATA_REQUEST_ENABLE_RECEIVER;
  8785. PUT_WORD (&plci->internal_req_buffer[1], min_digit_duration);
  8786. PUT_WORD (&plci->internal_req_buffer[3], min_gap_duration);
  8787. plci->NData[0].PLength = 5;
  8788. PUT_WORD (&plci->internal_req_buffer[5], INTERNAL_IND_BUFFER_SIZE);
  8789. plci->NData[0].PLength += 2;
  8790. capidtmf_recv_enable (&(plci->capidtmf_state), min_digit_duration, min_gap_duration);
  8791. }
  8792. else
  8793. {
  8794. plci->internal_req_buffer[0] = DTMF_UDATA_REQUEST_DISABLE_RECEIVER;
  8795. plci->NData[0].PLength = 1;
  8796. capidtmf_recv_disable (&(plci->capidtmf_state));
  8797. }
  8798. plci->NData[0].P = plci->internal_req_buffer;
  8799. plci->NL.X = plci->NData;
  8800. plci->NL.ReqCh = 0;
  8801. plci->NL.Req = plci->nl_req = (byte) N_UDATA;
  8802. plci->adapter->request (&plci->NL);
  8803. }
  8804. static void dtmf_send_digits (PLCI *plci, byte *digit_buffer, word digit_count)
  8805. {
  8806. word w, i;
  8807. dbug (1, dprintf ("[%06lx] %s,%d: dtmf_send_digits %d",
  8808. (dword)((plci->Id << 8) | UnMapController (plci->adapter->Id)),
  8809. (char *)(FILE_), __LINE__, digit_count));
  8810. plci->internal_req_buffer[0] = DTMF_UDATA_REQUEST_SEND_DIGITS;
  8811. w = (plci->dtmf_send_pulse_ms == 0) ? 40 : plci->dtmf_send_pulse_ms;
  8812. PUT_WORD (&plci->internal_req_buffer[1], w);
  8813. w = (plci->dtmf_send_pause_ms == 0) ? 40 : plci->dtmf_send_pause_ms;
  8814. PUT_WORD (&plci->internal_req_buffer[3], w);
  8815. for (i = 0; i < digit_count; i++)
  8816. {
  8817. w = 0;
  8818. while ((w < DTMF_DIGIT_MAP_ENTRIES)
  8819. && (digit_buffer[i] != dtmf_digit_map[w].character))
  8820. {
  8821. w++;
  8822. }
  8823. plci->internal_req_buffer[5+i] = (w < DTMF_DIGIT_MAP_ENTRIES) ?
  8824. dtmf_digit_map[w].code : DTMF_DIGIT_TONE_CODE_STAR;
  8825. }
  8826. plci->NData[0].PLength = 5 + digit_count;
  8827. plci->NData[0].P = plci->internal_req_buffer;
  8828. plci->NL.X = plci->NData;
  8829. plci->NL.ReqCh = 0;
  8830. plci->NL.Req = plci->nl_req = (byte) N_UDATA;
  8831. plci->adapter->request (&plci->NL);
  8832. }
  8833. static void dtmf_rec_clear_config (PLCI *plci)
  8834. {
  8835. dbug (1, dprintf ("[%06lx] %s,%d: dtmf_rec_clear_config",
  8836. (dword)((plci->Id << 8) | UnMapController (plci->adapter->Id)),
  8837. (char *)(FILE_), __LINE__));
  8838. plci->dtmf_rec_active = 0;
  8839. plci->dtmf_rec_pulse_ms = 0;
  8840. plci->dtmf_rec_pause_ms = 0;
  8841. capidtmf_init (&(plci->capidtmf_state), plci->adapter->u_law);
  8842. }
  8843. static void dtmf_send_clear_config (PLCI *plci)
  8844. {
  8845. dbug (1, dprintf ("[%06lx] %s,%d: dtmf_send_clear_config",
  8846. (dword)((plci->Id << 8) | UnMapController (plci->adapter->Id)),
  8847. (char *)(FILE_), __LINE__));
  8848. plci->dtmf_send_requests = 0;
  8849. plci->dtmf_send_pulse_ms = 0;
  8850. plci->dtmf_send_pause_ms = 0;
  8851. }
  8852. static void dtmf_prepare_switch (dword Id, PLCI *plci)
  8853. {
  8854. dbug (1, dprintf ("[%06lx] %s,%d: dtmf_prepare_switch",
  8855. UnMapId (Id), (char *)(FILE_), __LINE__));
  8856. while (plci->dtmf_send_requests != 0)
  8857. dtmf_confirmation (Id, plci);
  8858. }
  8859. static word dtmf_save_config (dword Id, PLCI *plci, byte Rc)
  8860. {
  8861. dbug (1, dprintf ("[%06lx] %s,%d: dtmf_save_config %02x %d",
  8862. UnMapId (Id), (char *)(FILE_), __LINE__, Rc, plci->adjust_b_state));
  8863. return (GOOD);
  8864. }
  8865. static word dtmf_restore_config (dword Id, PLCI *plci, byte Rc)
  8866. {
  8867. word Info;
  8868. dbug (1, dprintf ("[%06lx] %s,%d: dtmf_restore_config %02x %d",
  8869. UnMapId (Id), (char *)(FILE_), __LINE__, Rc, plci->adjust_b_state));
  8870. Info = GOOD;
  8871. if (plci->B1_facilities & B1_FACILITY_DTMFR)
  8872. {
  8873. switch (plci->adjust_b_state)
  8874. {
  8875. case ADJUST_B_RESTORE_DTMF_1:
  8876. plci->internal_command = plci->adjust_b_command;
  8877. if (plci_nl_busy (plci))
  8878. {
  8879. plci->adjust_b_state = ADJUST_B_RESTORE_DTMF_1;
  8880. break;
  8881. }
  8882. dtmf_enable_receiver (plci, plci->dtmf_rec_active);
  8883. plci->adjust_b_state = ADJUST_B_RESTORE_DTMF_2;
  8884. break;
  8885. case ADJUST_B_RESTORE_DTMF_2:
  8886. if ((Rc != OK) && (Rc != OK_FC))
  8887. {
  8888. dbug (1, dprintf ("[%06lx] %s,%d: Reenable DTMF receiver failed %02x",
  8889. UnMapId (Id), (char *)(FILE_), __LINE__, Rc));
  8890. Info = _WRONG_STATE;
  8891. break;
  8892. }
  8893. break;
  8894. }
  8895. }
  8896. return (Info);
  8897. }
  8898. static void dtmf_command (dword Id, PLCI *plci, byte Rc)
  8899. {
  8900. word internal_command, Info;
  8901. byte mask;
  8902. byte result[4];
  8903. dbug (1, dprintf ("[%06lx] %s,%d: dtmf_command %02x %04x %04x %d %d %d %d",
  8904. UnMapId (Id), (char *)(FILE_), __LINE__, Rc, plci->internal_command,
  8905. plci->dtmf_cmd, plci->dtmf_rec_pulse_ms, plci->dtmf_rec_pause_ms,
  8906. plci->dtmf_send_pulse_ms, plci->dtmf_send_pause_ms));
  8907. Info = GOOD;
  8908. result[0] = 2;
  8909. PUT_WORD (&result[1], DTMF_SUCCESS);
  8910. internal_command = plci->internal_command;
  8911. plci->internal_command = 0;
  8912. mask = 0x01;
  8913. switch (plci->dtmf_cmd)
  8914. {
  8915. case DTMF_LISTEN_TONE_START:
  8916. mask <<= 1;
  8917. case DTMF_LISTEN_MF_START:
  8918. mask <<= 1;
  8919. case DTMF_LISTEN_START:
  8920. switch (internal_command)
  8921. {
  8922. default:
  8923. adjust_b1_resource (Id, plci, NULL, (word)(plci->B1_facilities |
  8924. B1_FACILITY_DTMFR), DTMF_COMMAND_1);
  8925. case DTMF_COMMAND_1:
  8926. if (adjust_b_process (Id, plci, Rc) != GOOD)
  8927. {
  8928. dbug (1, dprintf ("[%06lx] %s,%d: Load DTMF failed",
  8929. UnMapId (Id), (char *)(FILE_), __LINE__));
  8930. Info = _FACILITY_NOT_SUPPORTED;
  8931. break;
  8932. }
  8933. if (plci->internal_command)
  8934. return;
  8935. case DTMF_COMMAND_2:
  8936. if (plci_nl_busy (plci))
  8937. {
  8938. plci->internal_command = DTMF_COMMAND_2;
  8939. return;
  8940. }
  8941. plci->internal_command = DTMF_COMMAND_3;
  8942. dtmf_enable_receiver (plci, (byte)(plci->dtmf_rec_active | mask));
  8943. return;
  8944. case DTMF_COMMAND_3:
  8945. if ((Rc != OK) && (Rc != OK_FC))
  8946. {
  8947. dbug (1, dprintf ("[%06lx] %s,%d: Enable DTMF receiver failed %02x",
  8948. UnMapId (Id), (char *)(FILE_), __LINE__, Rc));
  8949. Info = _FACILITY_NOT_SUPPORTED;
  8950. break;
  8951. }
  8952. plci->tone_last_indication_code = DTMF_SIGNAL_NO_TONE;
  8953. plci->dtmf_rec_active |= mask;
  8954. break;
  8955. }
  8956. break;
  8957. case DTMF_LISTEN_TONE_STOP:
  8958. mask <<= 1;
  8959. case DTMF_LISTEN_MF_STOP:
  8960. mask <<= 1;
  8961. case DTMF_LISTEN_STOP:
  8962. switch (internal_command)
  8963. {
  8964. default:
  8965. plci->dtmf_rec_active &= ~mask;
  8966. if (plci->dtmf_rec_active)
  8967. break;
  8968. /*
  8969. case DTMF_COMMAND_1:
  8970. if (plci->dtmf_rec_active)
  8971. {
  8972. if (plci_nl_busy (plci))
  8973. {
  8974. plci->internal_command = DTMF_COMMAND_1;
  8975. return;
  8976. }
  8977. plci->dtmf_rec_active &= ~mask;
  8978. plci->internal_command = DTMF_COMMAND_2;
  8979. dtmf_enable_receiver (plci, false);
  8980. return;
  8981. }
  8982. Rc = OK;
  8983. case DTMF_COMMAND_2:
  8984. if ((Rc != OK) && (Rc != OK_FC))
  8985. {
  8986. dbug (1, dprintf ("[%06lx] %s,%d: Disable DTMF receiver failed %02x",
  8987. UnMapId (Id), (char far *)(FILE_), __LINE__, Rc));
  8988. Info = _FACILITY_NOT_SUPPORTED;
  8989. break;
  8990. }
  8991. */
  8992. adjust_b1_resource (Id, plci, NULL, (word)(plci->B1_facilities &
  8993. ~(B1_FACILITY_DTMFX | B1_FACILITY_DTMFR)), DTMF_COMMAND_3);
  8994. case DTMF_COMMAND_3:
  8995. if (adjust_b_process (Id, plci, Rc) != GOOD)
  8996. {
  8997. dbug (1, dprintf ("[%06lx] %s,%d: Unload DTMF failed",
  8998. UnMapId (Id), (char *)(FILE_), __LINE__));
  8999. Info = _FACILITY_NOT_SUPPORTED;
  9000. break;
  9001. }
  9002. if (plci->internal_command)
  9003. return;
  9004. break;
  9005. }
  9006. break;
  9007. case DTMF_SEND_TONE:
  9008. mask <<= 1;
  9009. case DTMF_SEND_MF:
  9010. mask <<= 1;
  9011. case DTMF_DIGITS_SEND:
  9012. switch (internal_command)
  9013. {
  9014. default:
  9015. adjust_b1_resource (Id, plci, NULL, (word)(plci->B1_facilities |
  9016. ((plci->dtmf_parameter_length != 0) ? B1_FACILITY_DTMFX | B1_FACILITY_DTMFR : B1_FACILITY_DTMFX)),
  9017. DTMF_COMMAND_1);
  9018. case DTMF_COMMAND_1:
  9019. if (adjust_b_process (Id, plci, Rc) != GOOD)
  9020. {
  9021. dbug (1, dprintf ("[%06lx] %s,%d: Load DTMF failed",
  9022. UnMapId (Id), (char *)(FILE_), __LINE__));
  9023. Info = _FACILITY_NOT_SUPPORTED;
  9024. break;
  9025. }
  9026. if (plci->internal_command)
  9027. return;
  9028. case DTMF_COMMAND_2:
  9029. if (plci_nl_busy (plci))
  9030. {
  9031. plci->internal_command = DTMF_COMMAND_2;
  9032. return;
  9033. }
  9034. plci->dtmf_msg_number_queue[(plci->dtmf_send_requests)++] = plci->number;
  9035. plci->internal_command = DTMF_COMMAND_3;
  9036. dtmf_send_digits (plci, &plci->saved_msg.parms[3].info[1], plci->saved_msg.parms[3].length);
  9037. return;
  9038. case DTMF_COMMAND_3:
  9039. if ((Rc != OK) && (Rc != OK_FC))
  9040. {
  9041. dbug (1, dprintf ("[%06lx] %s,%d: Send DTMF digits failed %02x",
  9042. UnMapId (Id), (char *)(FILE_), __LINE__, Rc));
  9043. if (plci->dtmf_send_requests != 0)
  9044. (plci->dtmf_send_requests)--;
  9045. Info = _FACILITY_NOT_SUPPORTED;
  9046. break;
  9047. }
  9048. return;
  9049. }
  9050. break;
  9051. }
  9052. sendf (plci->appl, _FACILITY_R | CONFIRM, Id & 0xffffL, plci->number,
  9053. "wws", Info, SELECTOR_DTMF, result);
  9054. }
  9055. static byte dtmf_request (dword Id, word Number, DIVA_CAPI_ADAPTER *a, PLCI *plci, APPL *appl, API_PARSE *msg)
  9056. {
  9057. word Info;
  9058. word i, j;
  9059. byte mask;
  9060. API_PARSE dtmf_parms[5];
  9061. byte result[40];
  9062. dbug (1, dprintf ("[%06lx] %s,%d: dtmf_request",
  9063. UnMapId (Id), (char *)(FILE_), __LINE__));
  9064. Info = GOOD;
  9065. result[0] = 2;
  9066. PUT_WORD (&result[1], DTMF_SUCCESS);
  9067. if (!(a->profile.Global_Options & GL_DTMF_SUPPORTED))
  9068. {
  9069. dbug (1, dprintf ("[%06lx] %s,%d: Facility not supported",
  9070. UnMapId (Id), (char *)(FILE_), __LINE__));
  9071. Info = _FACILITY_NOT_SUPPORTED;
  9072. }
  9073. else if (api_parse (&msg[1].info[1], msg[1].length, "w", dtmf_parms))
  9074. {
  9075. dbug (1, dprintf ("[%06lx] %s,%d: Wrong message format",
  9076. UnMapId (Id), (char *)(FILE_), __LINE__));
  9077. Info = _WRONG_MESSAGE_FORMAT;
  9078. }
  9079. else if ((GET_WORD (dtmf_parms[0].info) == DTMF_GET_SUPPORTED_DETECT_CODES)
  9080. || (GET_WORD (dtmf_parms[0].info) == DTMF_GET_SUPPORTED_SEND_CODES))
  9081. {
  9082. if (!((a->requested_options_table[appl->Id-1])
  9083. & (1L << PRIVATE_DTMF_TONE)))
  9084. {
  9085. dbug (1, dprintf ("[%06lx] %s,%d: DTMF unknown request %04x",
  9086. UnMapId (Id), (char *)(FILE_), __LINE__, GET_WORD (dtmf_parms[0].info)));
  9087. PUT_WORD (&result[1], DTMF_UNKNOWN_REQUEST);
  9088. }
  9089. else
  9090. {
  9091. for (i = 0; i < 32; i++)
  9092. result[4 + i] = 0;
  9093. if (GET_WORD (dtmf_parms[0].info) == DTMF_GET_SUPPORTED_DETECT_CODES)
  9094. {
  9095. for (i = 0; i < DTMF_DIGIT_MAP_ENTRIES; i++)
  9096. {
  9097. if (dtmf_digit_map[i].listen_mask != 0)
  9098. result[4 + (dtmf_digit_map[i].character >> 3)] |= (1 << (dtmf_digit_map[i].character & 0x7));
  9099. }
  9100. }
  9101. else
  9102. {
  9103. for (i = 0; i < DTMF_DIGIT_MAP_ENTRIES; i++)
  9104. {
  9105. if (dtmf_digit_map[i].send_mask != 0)
  9106. result[4 + (dtmf_digit_map[i].character >> 3)] |= (1 << (dtmf_digit_map[i].character & 0x7));
  9107. }
  9108. }
  9109. result[0] = 3 + 32;
  9110. result[3] = 32;
  9111. }
  9112. }
  9113. else if (plci == NULL)
  9114. {
  9115. dbug (1, dprintf ("[%06lx] %s,%d: Wrong PLCI",
  9116. UnMapId (Id), (char *)(FILE_), __LINE__));
  9117. Info = _WRONG_IDENTIFIER;
  9118. }
  9119. else
  9120. {
  9121. if (!plci->State
  9122. || !plci->NL.Id || plci->nl_remove_id)
  9123. {
  9124. dbug (1, dprintf ("[%06lx] %s,%d: Wrong state",
  9125. UnMapId (Id), (char *)(FILE_), __LINE__));
  9126. Info = _WRONG_STATE;
  9127. }
  9128. else
  9129. {
  9130. plci->command = 0;
  9131. plci->dtmf_cmd = GET_WORD (dtmf_parms[0].info);
  9132. mask = 0x01;
  9133. switch (plci->dtmf_cmd)
  9134. {
  9135. case DTMF_LISTEN_TONE_START:
  9136. case DTMF_LISTEN_TONE_STOP:
  9137. mask <<= 1;
  9138. case DTMF_LISTEN_MF_START:
  9139. case DTMF_LISTEN_MF_STOP:
  9140. mask <<= 1;
  9141. if (!((plci->requested_options_conn | plci->requested_options | plci->adapter->requested_options_table[appl->Id-1])
  9142. & (1L << PRIVATE_DTMF_TONE)))
  9143. {
  9144. dbug (1, dprintf ("[%06lx] %s,%d: DTMF unknown request %04x",
  9145. UnMapId (Id), (char *)(FILE_), __LINE__, GET_WORD (dtmf_parms[0].info)));
  9146. PUT_WORD (&result[1], DTMF_UNKNOWN_REQUEST);
  9147. break;
  9148. }
  9149. case DTMF_LISTEN_START:
  9150. case DTMF_LISTEN_STOP:
  9151. if (!(a->manufacturer_features & MANUFACTURER_FEATURE_HARDDTMF)
  9152. && !(a->manufacturer_features & MANUFACTURER_FEATURE_SOFTDTMF_RECEIVE))
  9153. {
  9154. dbug (1, dprintf ("[%06lx] %s,%d: Facility not supported",
  9155. UnMapId (Id), (char *)(FILE_), __LINE__));
  9156. Info = _FACILITY_NOT_SUPPORTED;
  9157. break;
  9158. }
  9159. if (mask & DTMF_LISTEN_ACTIVE_FLAG)
  9160. {
  9161. if (api_parse (&msg[1].info[1], msg[1].length, "wwws", dtmf_parms))
  9162. {
  9163. plci->dtmf_rec_pulse_ms = 0;
  9164. plci->dtmf_rec_pause_ms = 0;
  9165. }
  9166. else
  9167. {
  9168. plci->dtmf_rec_pulse_ms = GET_WORD (dtmf_parms[1].info);
  9169. plci->dtmf_rec_pause_ms = GET_WORD (dtmf_parms[2].info);
  9170. }
  9171. }
  9172. start_internal_command (Id, plci, dtmf_command);
  9173. return (false);
  9174. case DTMF_SEND_TONE:
  9175. mask <<= 1;
  9176. case DTMF_SEND_MF:
  9177. mask <<= 1;
  9178. if (!((plci->requested_options_conn | plci->requested_options | plci->adapter->requested_options_table[appl->Id-1])
  9179. & (1L << PRIVATE_DTMF_TONE)))
  9180. {
  9181. dbug (1, dprintf ("[%06lx] %s,%d: DTMF unknown request %04x",
  9182. UnMapId (Id), (char *)(FILE_), __LINE__, GET_WORD (dtmf_parms[0].info)));
  9183. PUT_WORD (&result[1], DTMF_UNKNOWN_REQUEST);
  9184. break;
  9185. }
  9186. case DTMF_DIGITS_SEND:
  9187. if (api_parse (&msg[1].info[1], msg[1].length, "wwws", dtmf_parms))
  9188. {
  9189. dbug (1, dprintf ("[%06lx] %s,%d: Wrong message format",
  9190. UnMapId (Id), (char *)(FILE_), __LINE__));
  9191. Info = _WRONG_MESSAGE_FORMAT;
  9192. break;
  9193. }
  9194. if (mask & DTMF_LISTEN_ACTIVE_FLAG)
  9195. {
  9196. plci->dtmf_send_pulse_ms = GET_WORD (dtmf_parms[1].info);
  9197. plci->dtmf_send_pause_ms = GET_WORD (dtmf_parms[2].info);
  9198. }
  9199. i = 0;
  9200. j = 0;
  9201. while ((i < dtmf_parms[3].length) && (j < DTMF_DIGIT_MAP_ENTRIES))
  9202. {
  9203. j = 0;
  9204. while ((j < DTMF_DIGIT_MAP_ENTRIES)
  9205. && ((dtmf_parms[3].info[i+1] != dtmf_digit_map[j].character)
  9206. || ((dtmf_digit_map[j].send_mask & mask) == 0)))
  9207. {
  9208. j++;
  9209. }
  9210. i++;
  9211. }
  9212. if (j == DTMF_DIGIT_MAP_ENTRIES)
  9213. {
  9214. dbug (1, dprintf ("[%06lx] %s,%d: Incorrect DTMF digit %02x",
  9215. UnMapId (Id), (char *)(FILE_), __LINE__, dtmf_parms[3].info[i]));
  9216. PUT_WORD (&result[1], DTMF_INCORRECT_DIGIT);
  9217. break;
  9218. }
  9219. if (plci->dtmf_send_requests >= ARRAY_SIZE(plci->dtmf_msg_number_queue))
  9220. {
  9221. dbug (1, dprintf ("[%06lx] %s,%d: DTMF request overrun",
  9222. UnMapId (Id), (char *)(FILE_), __LINE__));
  9223. Info = _WRONG_STATE;
  9224. break;
  9225. }
  9226. api_save_msg (dtmf_parms, "wwws", &plci->saved_msg);
  9227. start_internal_command (Id, plci, dtmf_command);
  9228. return (false);
  9229. default:
  9230. dbug (1, dprintf ("[%06lx] %s,%d: DTMF unknown request %04x",
  9231. UnMapId (Id), (char *)(FILE_), __LINE__, plci->dtmf_cmd));
  9232. PUT_WORD (&result[1], DTMF_UNKNOWN_REQUEST);
  9233. }
  9234. }
  9235. }
  9236. sendf (appl, _FACILITY_R | CONFIRM, Id & 0xffffL, Number,
  9237. "wws", Info, SELECTOR_DTMF, result);
  9238. return (false);
  9239. }
  9240. static void dtmf_confirmation (dword Id, PLCI *plci)
  9241. {
  9242. word Info;
  9243. word i;
  9244. byte result[4];
  9245. dbug (1, dprintf ("[%06lx] %s,%d: dtmf_confirmation",
  9246. UnMapId (Id), (char *)(FILE_), __LINE__));
  9247. Info = GOOD;
  9248. result[0] = 2;
  9249. PUT_WORD (&result[1], DTMF_SUCCESS);
  9250. if (plci->dtmf_send_requests != 0)
  9251. {
  9252. sendf (plci->appl, _FACILITY_R | CONFIRM, Id & 0xffffL, plci->dtmf_msg_number_queue[0],
  9253. "wws", GOOD, SELECTOR_DTMF, result);
  9254. (plci->dtmf_send_requests)--;
  9255. for (i = 0; i < plci->dtmf_send_requests; i++)
  9256. plci->dtmf_msg_number_queue[i] = plci->dtmf_msg_number_queue[i+1];
  9257. }
  9258. }
  9259. static void dtmf_indication (dword Id, PLCI *plci, byte *msg, word length)
  9260. {
  9261. word i, j, n;
  9262. dbug (1, dprintf ("[%06lx] %s,%d: dtmf_indication",
  9263. UnMapId (Id), (char *)(FILE_), __LINE__));
  9264. n = 0;
  9265. for (i = 1; i < length; i++)
  9266. {
  9267. j = 0;
  9268. while ((j < DTMF_DIGIT_MAP_ENTRIES)
  9269. && ((msg[i] != dtmf_digit_map[j].code)
  9270. || ((dtmf_digit_map[j].listen_mask & plci->dtmf_rec_active) == 0)))
  9271. {
  9272. j++;
  9273. }
  9274. if (j < DTMF_DIGIT_MAP_ENTRIES)
  9275. {
  9276. if ((dtmf_digit_map[j].listen_mask & DTMF_TONE_LISTEN_ACTIVE_FLAG)
  9277. && (plci->tone_last_indication_code == DTMF_SIGNAL_NO_TONE)
  9278. && (dtmf_digit_map[j].character != DTMF_SIGNAL_UNIDENTIFIED_TONE))
  9279. {
  9280. if (n + 1 == i)
  9281. {
  9282. for (i = length; i > n + 1; i--)
  9283. msg[i] = msg[i - 1];
  9284. length++;
  9285. i++;
  9286. }
  9287. msg[++n] = DTMF_SIGNAL_UNIDENTIFIED_TONE;
  9288. }
  9289. plci->tone_last_indication_code = dtmf_digit_map[j].character;
  9290. msg[++n] = dtmf_digit_map[j].character;
  9291. }
  9292. }
  9293. if (n != 0)
  9294. {
  9295. msg[0] = (byte) n;
  9296. sendf (plci->appl, _FACILITY_I, Id & 0xffffL, 0, "wS", SELECTOR_DTMF, msg);
  9297. }
  9298. }
  9299. /*------------------------------------------------------------------*/
  9300. /* DTMF parameters */
  9301. /*------------------------------------------------------------------*/
  9302. static void dtmf_parameter_write (PLCI *plci)
  9303. {
  9304. word i;
  9305. byte parameter_buffer[DTMF_PARAMETER_BUFFER_SIZE + 2];
  9306. dbug (1, dprintf ("[%06lx] %s,%d: dtmf_parameter_write",
  9307. (dword)((plci->Id << 8) | UnMapController (plci->adapter->Id)),
  9308. (char *)(FILE_), __LINE__));
  9309. parameter_buffer[0] = plci->dtmf_parameter_length + 1;
  9310. parameter_buffer[1] = DSP_CTRL_SET_DTMF_PARAMETERS;
  9311. for (i = 0; i < plci->dtmf_parameter_length; i++)
  9312. parameter_buffer[2+i] = plci->dtmf_parameter_buffer[i];
  9313. add_p (plci, FTY, parameter_buffer);
  9314. sig_req (plci, TEL_CTRL, 0);
  9315. send_req (plci);
  9316. }
  9317. static void dtmf_parameter_clear_config (PLCI *plci)
  9318. {
  9319. dbug (1, dprintf ("[%06lx] %s,%d: dtmf_parameter_clear_config",
  9320. (dword)((plci->Id << 8) | UnMapController (plci->adapter->Id)),
  9321. (char *)(FILE_), __LINE__));
  9322. plci->dtmf_parameter_length = 0;
  9323. }
  9324. static void dtmf_parameter_prepare_switch (dword Id, PLCI *plci)
  9325. {
  9326. dbug (1, dprintf ("[%06lx] %s,%d: dtmf_parameter_prepare_switch",
  9327. UnMapId (Id), (char *)(FILE_), __LINE__));
  9328. }
  9329. static word dtmf_parameter_save_config (dword Id, PLCI *plci, byte Rc)
  9330. {
  9331. dbug (1, dprintf ("[%06lx] %s,%d: dtmf_parameter_save_config %02x %d",
  9332. UnMapId (Id), (char *)(FILE_), __LINE__, Rc, plci->adjust_b_state));
  9333. return (GOOD);
  9334. }
  9335. static word dtmf_parameter_restore_config (dword Id, PLCI *plci, byte Rc)
  9336. {
  9337. word Info;
  9338. dbug (1, dprintf ("[%06lx] %s,%d: dtmf_parameter_restore_config %02x %d",
  9339. UnMapId (Id), (char *)(FILE_), __LINE__, Rc, plci->adjust_b_state));
  9340. Info = GOOD;
  9341. if ((plci->B1_facilities & B1_FACILITY_DTMFR)
  9342. && (plci->dtmf_parameter_length != 0))
  9343. {
  9344. switch (plci->adjust_b_state)
  9345. {
  9346. case ADJUST_B_RESTORE_DTMF_PARAMETER_1:
  9347. plci->internal_command = plci->adjust_b_command;
  9348. if (plci->sig_req)
  9349. {
  9350. plci->adjust_b_state = ADJUST_B_RESTORE_DTMF_PARAMETER_1;
  9351. break;
  9352. }
  9353. dtmf_parameter_write (plci);
  9354. plci->adjust_b_state = ADJUST_B_RESTORE_DTMF_PARAMETER_2;
  9355. break;
  9356. case ADJUST_B_RESTORE_DTMF_PARAMETER_2:
  9357. if ((Rc != OK) && (Rc != OK_FC))
  9358. {
  9359. dbug (1, dprintf ("[%06lx] %s,%d: Restore DTMF parameters failed %02x",
  9360. UnMapId (Id), (char *)(FILE_), __LINE__, Rc));
  9361. Info = _WRONG_STATE;
  9362. break;
  9363. }
  9364. break;
  9365. }
  9366. }
  9367. return (Info);
  9368. }
  9369. /*------------------------------------------------------------------*/
  9370. /* Line interconnect facilities */
  9371. /*------------------------------------------------------------------*/
  9372. LI_CONFIG *li_config_table;
  9373. word li_total_channels;
  9374. /*------------------------------------------------------------------*/
  9375. /* translate a CHI information element to a channel number */
  9376. /* returns 0xff - any channel */
  9377. /* 0xfe - chi wrong coding */
  9378. /* 0xfd - D-channel */
  9379. /* 0x00 - no channel */
  9380. /* else channel number / PRI: timeslot */
  9381. /* if channels is provided we accept more than one channel. */
  9382. /*------------------------------------------------------------------*/
  9383. static byte chi_to_channel (byte *chi, dword *pchannelmap)
  9384. {
  9385. int p;
  9386. int i;
  9387. dword map;
  9388. byte excl;
  9389. byte ofs;
  9390. byte ch;
  9391. if (pchannelmap) *pchannelmap = 0;
  9392. if(!chi[0]) return 0xff;
  9393. excl = 0;
  9394. if(chi[1] & 0x20) {
  9395. if(chi[0]==1 && chi[1]==0xac) return 0xfd; /* exclusive d-channel */
  9396. for(i=1; i<chi[0] && !(chi[i] &0x80); i++);
  9397. if(i==chi[0] || !(chi[i] &0x80)) return 0xfe;
  9398. if((chi[1] |0xc8)!=0xe9) return 0xfe;
  9399. if(chi[1] &0x08) excl = 0x40;
  9400. /* int. id present */
  9401. if(chi[1] &0x40) {
  9402. p=i+1;
  9403. for(i=p; i<chi[0] && !(chi[i] &0x80); i++);
  9404. if(i==chi[0] || !(chi[i] &0x80)) return 0xfe;
  9405. }
  9406. /* coding standard, Number/Map, Channel Type */
  9407. p=i+1;
  9408. for(i=p; i<chi[0] && !(chi[i] &0x80); i++);
  9409. if(i==chi[0] || !(chi[i] &0x80)) return 0xfe;
  9410. if((chi[p]|0xd0)!=0xd3) return 0xfe;
  9411. /* Number/Map */
  9412. if(chi[p] &0x10) {
  9413. /* map */
  9414. if((chi[0]-p)==4) ofs = 0;
  9415. else if((chi[0]-p)==3) ofs = 1;
  9416. else return 0xfe;
  9417. ch = 0;
  9418. map = 0;
  9419. for(i=0; i<4 && p<chi[0]; i++) {
  9420. p++;
  9421. ch += 8;
  9422. map <<= 8;
  9423. if(chi[p]) {
  9424. for (ch=0; !(chi[p] & (1 << ch)); ch++);
  9425. map |= chi[p];
  9426. }
  9427. }
  9428. ch += ofs;
  9429. map <<= ofs;
  9430. }
  9431. else {
  9432. /* number */
  9433. p=i+1;
  9434. ch = chi[p] &0x3f;
  9435. if(pchannelmap) {
  9436. if((byte)(chi[0]-p)>30) return 0xfe;
  9437. map = 0;
  9438. for(i=p; i<=chi[0]; i++) {
  9439. if ((chi[i] &0x7f) > 31) return 0xfe;
  9440. map |= (1L << (chi[i] &0x7f));
  9441. }
  9442. }
  9443. else {
  9444. if(p!=chi[0]) return 0xfe;
  9445. if (ch > 31) return 0xfe;
  9446. map = (1L << ch);
  9447. }
  9448. if(chi[p] &0x40) return 0xfe;
  9449. }
  9450. if (pchannelmap) *pchannelmap = map;
  9451. else if (map != ((dword)(1L << ch))) return 0xfe;
  9452. return (byte)(excl | ch);
  9453. }
  9454. else { /* not PRI */
  9455. for(i=1; i<chi[0] && !(chi[i] &0x80); i++);
  9456. if(i!=chi[0] || !(chi[i] &0x80)) return 0xfe;
  9457. if(chi[1] &0x08) excl = 0x40;
  9458. switch(chi[1] |0x98) {
  9459. case 0x98: return 0;
  9460. case 0x99:
  9461. if (pchannelmap) *pchannelmap = 2;
  9462. return excl |1;
  9463. case 0x9a:
  9464. if (pchannelmap) *pchannelmap = 4;
  9465. return excl |2;
  9466. case 0x9b: return 0xff;
  9467. case 0x9c: return 0xfd; /* d-ch */
  9468. default: return 0xfe;
  9469. }
  9470. }
  9471. }
  9472. static void mixer_set_bchannel_id_esc (PLCI *plci, byte bchannel_id)
  9473. {
  9474. DIVA_CAPI_ADAPTER *a;
  9475. PLCI *splci;
  9476. byte old_id;
  9477. a = plci->adapter;
  9478. old_id = plci->li_bchannel_id;
  9479. if (a->li_pri)
  9480. {
  9481. if ((old_id != 0) && (li_config_table[a->li_base + (old_id - 1)].plci == plci))
  9482. li_config_table[a->li_base + (old_id - 1)].plci = NULL;
  9483. plci->li_bchannel_id = (bchannel_id & 0x1f) + 1;
  9484. if (li_config_table[a->li_base + (plci->li_bchannel_id - 1)].plci == NULL)
  9485. li_config_table[a->li_base + (plci->li_bchannel_id - 1)].plci = plci;
  9486. }
  9487. else
  9488. {
  9489. if (((bchannel_id & 0x03) == 1) || ((bchannel_id & 0x03) == 2))
  9490. {
  9491. if ((old_id != 0) && (li_config_table[a->li_base + (old_id - 1)].plci == plci))
  9492. li_config_table[a->li_base + (old_id - 1)].plci = NULL;
  9493. plci->li_bchannel_id = bchannel_id & 0x03;
  9494. if ((a->AdvSignalPLCI != NULL) && (a->AdvSignalPLCI != plci) && (a->AdvSignalPLCI->tel == ADV_VOICE))
  9495. {
  9496. splci = a->AdvSignalPLCI;
  9497. if (li_config_table[a->li_base + (2 - plci->li_bchannel_id)].plci == NULL)
  9498. {
  9499. if ((splci->li_bchannel_id != 0)
  9500. && (li_config_table[a->li_base + (splci->li_bchannel_id - 1)].plci == splci))
  9501. {
  9502. li_config_table[a->li_base + (splci->li_bchannel_id - 1)].plci = NULL;
  9503. }
  9504. splci->li_bchannel_id = 3 - plci->li_bchannel_id;
  9505. li_config_table[a->li_base + (2 - plci->li_bchannel_id)].plci = splci;
  9506. dbug (1, dprintf ("[%06lx] %s,%d: adv_voice_set_bchannel_id_esc %d",
  9507. (dword)((splci->Id << 8) | UnMapController (splci->adapter->Id)),
  9508. (char *)(FILE_), __LINE__, splci->li_bchannel_id));
  9509. }
  9510. }
  9511. if (li_config_table[a->li_base + (plci->li_bchannel_id - 1)].plci == NULL)
  9512. li_config_table[a->li_base + (plci->li_bchannel_id - 1)].plci = plci;
  9513. }
  9514. }
  9515. if ((old_id == 0) && (plci->li_bchannel_id != 0)
  9516. && (li_config_table[a->li_base + (plci->li_bchannel_id - 1)].plci == plci))
  9517. {
  9518. mixer_clear_config (plci);
  9519. }
  9520. dbug (1, dprintf ("[%06lx] %s,%d: mixer_set_bchannel_id_esc %d %d",
  9521. (dword)((plci->Id << 8) | UnMapController (plci->adapter->Id)),
  9522. (char *)(FILE_), __LINE__, bchannel_id, plci->li_bchannel_id));
  9523. }
  9524. static void mixer_set_bchannel_id (PLCI *plci, byte *chi)
  9525. {
  9526. DIVA_CAPI_ADAPTER *a;
  9527. PLCI *splci;
  9528. byte ch, old_id;
  9529. a = plci->adapter;
  9530. old_id = plci->li_bchannel_id;
  9531. ch = chi_to_channel (chi, NULL);
  9532. if (!(ch & 0x80))
  9533. {
  9534. if (a->li_pri)
  9535. {
  9536. if ((old_id != 0) && (li_config_table[a->li_base + (old_id - 1)].plci == plci))
  9537. li_config_table[a->li_base + (old_id - 1)].plci = NULL;
  9538. plci->li_bchannel_id = (ch & 0x1f) + 1;
  9539. if (li_config_table[a->li_base + (plci->li_bchannel_id - 1)].plci == NULL)
  9540. li_config_table[a->li_base + (plci->li_bchannel_id - 1)].plci = plci;
  9541. }
  9542. else
  9543. {
  9544. if (((ch & 0x1f) == 1) || ((ch & 0x1f) == 2))
  9545. {
  9546. if ((old_id != 0) && (li_config_table[a->li_base + (old_id - 1)].plci == plci))
  9547. li_config_table[a->li_base + (old_id - 1)].plci = NULL;
  9548. plci->li_bchannel_id = ch & 0x1f;
  9549. if ((a->AdvSignalPLCI != NULL) && (a->AdvSignalPLCI != plci) && (a->AdvSignalPLCI->tel == ADV_VOICE))
  9550. {
  9551. splci = a->AdvSignalPLCI;
  9552. if (li_config_table[a->li_base + (2 - plci->li_bchannel_id)].plci == NULL)
  9553. {
  9554. if ((splci->li_bchannel_id != 0)
  9555. && (li_config_table[a->li_base + (splci->li_bchannel_id - 1)].plci == splci))
  9556. {
  9557. li_config_table[a->li_base + (splci->li_bchannel_id - 1)].plci = NULL;
  9558. }
  9559. splci->li_bchannel_id = 3 - plci->li_bchannel_id;
  9560. li_config_table[a->li_base + (2 - plci->li_bchannel_id)].plci = splci;
  9561. dbug (1, dprintf ("[%06lx] %s,%d: adv_voice_set_bchannel_id %d",
  9562. (dword)((splci->Id << 8) | UnMapController (splci->adapter->Id)),
  9563. (char *)(FILE_), __LINE__, splci->li_bchannel_id));
  9564. }
  9565. }
  9566. if (li_config_table[a->li_base + (plci->li_bchannel_id - 1)].plci == NULL)
  9567. li_config_table[a->li_base + (plci->li_bchannel_id - 1)].plci = plci;
  9568. }
  9569. }
  9570. }
  9571. if ((old_id == 0) && (plci->li_bchannel_id != 0)
  9572. && (li_config_table[a->li_base + (plci->li_bchannel_id - 1)].plci == plci))
  9573. {
  9574. mixer_clear_config (plci);
  9575. }
  9576. dbug (1, dprintf ("[%06lx] %s,%d: mixer_set_bchannel_id %02x %d",
  9577. (dword)((plci->Id << 8) | UnMapController (plci->adapter->Id)),
  9578. (char *)(FILE_), __LINE__, ch, plci->li_bchannel_id));
  9579. }
  9580. #define MIXER_MAX_DUMP_CHANNELS 34
  9581. static void mixer_calculate_coefs (DIVA_CAPI_ADAPTER *a)
  9582. {
  9583. static char hex_digit_table[0x10] = {'0','1','2','3','4','5','6','7','8','9','a','b','c','d','e','f'};
  9584. word n, i, j;
  9585. char *p;
  9586. char hex_line[2 * MIXER_MAX_DUMP_CHANNELS + MIXER_MAX_DUMP_CHANNELS / 8 + 4];
  9587. dbug (1, dprintf ("[%06lx] %s,%d: mixer_calculate_coefs",
  9588. (dword)(UnMapController (a->Id)), (char *)(FILE_), __LINE__));
  9589. for (i = 0; i < li_total_channels; i++)
  9590. {
  9591. li_config_table[i].channel &= LI_CHANNEL_ADDRESSES_SET;
  9592. if (li_config_table[i].chflags != 0)
  9593. li_config_table[i].channel |= LI_CHANNEL_INVOLVED;
  9594. else
  9595. {
  9596. for (j = 0; j < li_total_channels; j++)
  9597. {
  9598. if (((li_config_table[i].flag_table[j]) != 0)
  9599. || ((li_config_table[j].flag_table[i]) != 0))
  9600. {
  9601. li_config_table[i].channel |= LI_CHANNEL_INVOLVED;
  9602. }
  9603. if (((li_config_table[i].flag_table[j] & LI_FLAG_CONFERENCE) != 0)
  9604. || ((li_config_table[j].flag_table[i] & LI_FLAG_CONFERENCE) != 0))
  9605. {
  9606. li_config_table[i].channel |= LI_CHANNEL_CONFERENCE;
  9607. }
  9608. }
  9609. }
  9610. }
  9611. for (i = 0; i < li_total_channels; i++)
  9612. {
  9613. for (j = 0; j < li_total_channels; j++)
  9614. {
  9615. li_config_table[i].coef_table[j] &= ~(LI_COEF_CH_CH | LI_COEF_CH_PC | LI_COEF_PC_CH | LI_COEF_PC_PC);
  9616. if (li_config_table[i].flag_table[j] & LI_FLAG_CONFERENCE)
  9617. li_config_table[i].coef_table[j] |= LI_COEF_CH_CH;
  9618. }
  9619. }
  9620. for (n = 0; n < li_total_channels; n++)
  9621. {
  9622. if (li_config_table[n].channel & LI_CHANNEL_CONFERENCE)
  9623. {
  9624. for (i = 0; i < li_total_channels; i++)
  9625. {
  9626. if (li_config_table[i].channel & LI_CHANNEL_CONFERENCE)
  9627. {
  9628. for (j = 0; j < li_total_channels; j++)
  9629. {
  9630. li_config_table[i].coef_table[j] |=
  9631. li_config_table[i].coef_table[n] & li_config_table[n].coef_table[j];
  9632. }
  9633. }
  9634. }
  9635. }
  9636. }
  9637. for (i = 0; i < li_total_channels; i++)
  9638. {
  9639. if (li_config_table[i].channel & LI_CHANNEL_INVOLVED)
  9640. {
  9641. li_config_table[i].coef_table[i] &= ~LI_COEF_CH_CH;
  9642. for (j = 0; j < li_total_channels; j++)
  9643. {
  9644. if (li_config_table[i].coef_table[j] & LI_COEF_CH_CH)
  9645. li_config_table[i].flag_table[j] |= LI_FLAG_CONFERENCE;
  9646. }
  9647. if (li_config_table[i].flag_table[i] & LI_FLAG_CONFERENCE)
  9648. li_config_table[i].coef_table[i] |= LI_COEF_CH_CH;
  9649. }
  9650. }
  9651. for (i = 0; i < li_total_channels; i++)
  9652. {
  9653. if (li_config_table[i].channel & LI_CHANNEL_INVOLVED)
  9654. {
  9655. for (j = 0; j < li_total_channels; j++)
  9656. {
  9657. if (li_config_table[i].flag_table[j] & LI_FLAG_INTERCONNECT)
  9658. li_config_table[i].coef_table[j] |= LI_COEF_CH_CH;
  9659. if (li_config_table[i].flag_table[j] & LI_FLAG_MONITOR)
  9660. li_config_table[i].coef_table[j] |= LI_COEF_CH_PC;
  9661. if (li_config_table[i].flag_table[j] & LI_FLAG_MIX)
  9662. li_config_table[i].coef_table[j] |= LI_COEF_PC_CH;
  9663. if (li_config_table[i].flag_table[j] & LI_FLAG_PCCONNECT)
  9664. li_config_table[i].coef_table[j] |= LI_COEF_PC_PC;
  9665. }
  9666. if (li_config_table[i].chflags & LI_CHFLAG_MONITOR)
  9667. {
  9668. for (j = 0; j < li_total_channels; j++)
  9669. {
  9670. if (li_config_table[i].flag_table[j] & LI_FLAG_INTERCONNECT)
  9671. {
  9672. li_config_table[i].coef_table[j] |= LI_COEF_CH_PC;
  9673. if (li_config_table[j].chflags & LI_CHFLAG_MIX)
  9674. li_config_table[i].coef_table[j] |= LI_COEF_PC_CH | LI_COEF_PC_PC;
  9675. }
  9676. }
  9677. }
  9678. if (li_config_table[i].chflags & LI_CHFLAG_MIX)
  9679. {
  9680. for (j = 0; j < li_total_channels; j++)
  9681. {
  9682. if (li_config_table[j].flag_table[i] & LI_FLAG_INTERCONNECT)
  9683. li_config_table[j].coef_table[i] |= LI_COEF_PC_CH;
  9684. }
  9685. }
  9686. if (li_config_table[i].chflags & LI_CHFLAG_LOOP)
  9687. {
  9688. for (j = 0; j < li_total_channels; j++)
  9689. {
  9690. if (li_config_table[i].flag_table[j] & LI_FLAG_INTERCONNECT)
  9691. {
  9692. for (n = 0; n < li_total_channels; n++)
  9693. {
  9694. if (li_config_table[n].flag_table[i] & LI_FLAG_INTERCONNECT)
  9695. {
  9696. li_config_table[n].coef_table[j] |= LI_COEF_CH_CH;
  9697. if (li_config_table[j].chflags & LI_CHFLAG_MIX)
  9698. {
  9699. li_config_table[n].coef_table[j] |= LI_COEF_PC_CH;
  9700. if (li_config_table[n].chflags & LI_CHFLAG_MONITOR)
  9701. li_config_table[n].coef_table[j] |= LI_COEF_CH_PC | LI_COEF_PC_PC;
  9702. }
  9703. else if (li_config_table[n].chflags & LI_CHFLAG_MONITOR)
  9704. li_config_table[n].coef_table[j] |= LI_COEF_CH_PC;
  9705. }
  9706. }
  9707. }
  9708. }
  9709. }
  9710. }
  9711. }
  9712. for (i = 0; i < li_total_channels; i++)
  9713. {
  9714. if (li_config_table[i].channel & LI_CHANNEL_INVOLVED)
  9715. {
  9716. if (li_config_table[i].chflags & (LI_CHFLAG_MONITOR | LI_CHFLAG_MIX | LI_CHFLAG_LOOP))
  9717. li_config_table[i].channel |= LI_CHANNEL_ACTIVE;
  9718. if (li_config_table[i].chflags & LI_CHFLAG_MONITOR)
  9719. li_config_table[i].channel |= LI_CHANNEL_RX_DATA;
  9720. if (li_config_table[i].chflags & LI_CHFLAG_MIX)
  9721. li_config_table[i].channel |= LI_CHANNEL_TX_DATA;
  9722. for (j = 0; j < li_total_channels; j++)
  9723. {
  9724. if ((li_config_table[i].flag_table[j] &
  9725. (LI_FLAG_INTERCONNECT | LI_FLAG_PCCONNECT | LI_FLAG_CONFERENCE | LI_FLAG_MONITOR))
  9726. || (li_config_table[j].flag_table[i] &
  9727. (LI_FLAG_INTERCONNECT | LI_FLAG_PCCONNECT | LI_FLAG_CONFERENCE | LI_FLAG_ANNOUNCEMENT | LI_FLAG_MIX)))
  9728. {
  9729. li_config_table[i].channel |= LI_CHANNEL_ACTIVE;
  9730. }
  9731. if (li_config_table[i].flag_table[j] & (LI_FLAG_PCCONNECT | LI_FLAG_MONITOR))
  9732. li_config_table[i].channel |= LI_CHANNEL_RX_DATA;
  9733. if (li_config_table[j].flag_table[i] & (LI_FLAG_PCCONNECT | LI_FLAG_ANNOUNCEMENT | LI_FLAG_MIX))
  9734. li_config_table[i].channel |= LI_CHANNEL_TX_DATA;
  9735. }
  9736. if (!(li_config_table[i].channel & LI_CHANNEL_ACTIVE))
  9737. {
  9738. li_config_table[i].coef_table[i] |= LI_COEF_PC_CH | LI_COEF_CH_PC;
  9739. li_config_table[i].channel |= LI_CHANNEL_TX_DATA | LI_CHANNEL_RX_DATA;
  9740. }
  9741. }
  9742. }
  9743. for (i = 0; i < li_total_channels; i++)
  9744. {
  9745. if (li_config_table[i].channel & LI_CHANNEL_INVOLVED)
  9746. {
  9747. j = 0;
  9748. while ((j < li_total_channels) && !(li_config_table[i].flag_table[j] & LI_FLAG_ANNOUNCEMENT))
  9749. j++;
  9750. if (j < li_total_channels)
  9751. {
  9752. for (j = 0; j < li_total_channels; j++)
  9753. {
  9754. li_config_table[i].coef_table[j] &= ~(LI_COEF_CH_CH | LI_COEF_PC_CH);
  9755. if (li_config_table[i].flag_table[j] & LI_FLAG_ANNOUNCEMENT)
  9756. li_config_table[i].coef_table[j] |= LI_COEF_PC_CH;
  9757. }
  9758. }
  9759. }
  9760. }
  9761. n = li_total_channels;
  9762. if (n > MIXER_MAX_DUMP_CHANNELS)
  9763. n = MIXER_MAX_DUMP_CHANNELS;
  9764. p = hex_line;
  9765. for (j = 0; j < n; j++)
  9766. {
  9767. if ((j & 0x7) == 0)
  9768. *(p++) = ' ';
  9769. *(p++) = hex_digit_table[li_config_table[j].curchnl >> 4];
  9770. *(p++) = hex_digit_table[li_config_table[j].curchnl & 0xf];
  9771. }
  9772. *p = '\0';
  9773. dbug (1, dprintf ("[%06lx] CURRENT %s",
  9774. (dword)(UnMapController (a->Id)), (char *) hex_line));
  9775. p = hex_line;
  9776. for (j = 0; j < n; j++)
  9777. {
  9778. if ((j & 0x7) == 0)
  9779. *(p++) = ' ';
  9780. *(p++) = hex_digit_table[li_config_table[j].channel >> 4];
  9781. *(p++) = hex_digit_table[li_config_table[j].channel & 0xf];
  9782. }
  9783. *p = '\0';
  9784. dbug (1, dprintf ("[%06lx] CHANNEL %s",
  9785. (dword)(UnMapController (a->Id)), (char *) hex_line));
  9786. p = hex_line;
  9787. for (j = 0; j < n; j++)
  9788. {
  9789. if ((j & 0x7) == 0)
  9790. *(p++) = ' ';
  9791. *(p++) = hex_digit_table[li_config_table[j].chflags >> 4];
  9792. *(p++) = hex_digit_table[li_config_table[j].chflags & 0xf];
  9793. }
  9794. *p = '\0';
  9795. dbug (1, dprintf ("[%06lx] CHFLAG %s",
  9796. (dword)(UnMapController (a->Id)), (char *) hex_line));
  9797. for (i = 0; i < n; i++)
  9798. {
  9799. p = hex_line;
  9800. for (j = 0; j < n; j++)
  9801. {
  9802. if ((j & 0x7) == 0)
  9803. *(p++) = ' ';
  9804. *(p++) = hex_digit_table[li_config_table[i].flag_table[j] >> 4];
  9805. *(p++) = hex_digit_table[li_config_table[i].flag_table[j] & 0xf];
  9806. }
  9807. *p = '\0';
  9808. dbug (1, dprintf ("[%06lx] FLAG[%02x]%s",
  9809. (dword)(UnMapController (a->Id)), i, (char *) hex_line));
  9810. }
  9811. for (i = 0; i < n; i++)
  9812. {
  9813. p = hex_line;
  9814. for (j = 0; j < n; j++)
  9815. {
  9816. if ((j & 0x7) == 0)
  9817. *(p++) = ' ';
  9818. *(p++) = hex_digit_table[li_config_table[i].coef_table[j] >> 4];
  9819. *(p++) = hex_digit_table[li_config_table[i].coef_table[j] & 0xf];
  9820. }
  9821. *p = '\0';
  9822. dbug (1, dprintf ("[%06lx] COEF[%02x]%s",
  9823. (dword)(UnMapController (a->Id)), i, (char *) hex_line));
  9824. }
  9825. }
  9826. static struct
  9827. {
  9828. byte mask;
  9829. byte line_flags;
  9830. } mixer_write_prog_pri[] =
  9831. {
  9832. { LI_COEF_CH_CH, 0 },
  9833. { LI_COEF_CH_PC, MIXER_COEF_LINE_TO_PC_FLAG },
  9834. { LI_COEF_PC_CH, MIXER_COEF_LINE_FROM_PC_FLAG },
  9835. { LI_COEF_PC_PC, MIXER_COEF_LINE_TO_PC_FLAG | MIXER_COEF_LINE_FROM_PC_FLAG }
  9836. };
  9837. static struct
  9838. {
  9839. byte from_ch;
  9840. byte to_ch;
  9841. byte mask;
  9842. byte xconnect_override;
  9843. } mixer_write_prog_bri[] =
  9844. {
  9845. { 0, 0, LI_COEF_CH_CH, 0x01 }, /* B to B */
  9846. { 1, 0, LI_COEF_CH_CH, 0x01 }, /* Alt B to B */
  9847. { 0, 0, LI_COEF_PC_CH, 0x80 }, /* PC to B */
  9848. { 1, 0, LI_COEF_PC_CH, 0x01 }, /* Alt PC to B */
  9849. { 2, 0, LI_COEF_CH_CH, 0x00 }, /* IC to B */
  9850. { 3, 0, LI_COEF_CH_CH, 0x00 }, /* Alt IC to B */
  9851. { 0, 0, LI_COEF_CH_PC, 0x80 }, /* B to PC */
  9852. { 1, 0, LI_COEF_CH_PC, 0x01 }, /* Alt B to PC */
  9853. { 0, 0, LI_COEF_PC_PC, 0x01 }, /* PC to PC */
  9854. { 1, 0, LI_COEF_PC_PC, 0x01 }, /* Alt PC to PC */
  9855. { 2, 0, LI_COEF_CH_PC, 0x00 }, /* IC to PC */
  9856. { 3, 0, LI_COEF_CH_PC, 0x00 }, /* Alt IC to PC */
  9857. { 0, 2, LI_COEF_CH_CH, 0x00 }, /* B to IC */
  9858. { 1, 2, LI_COEF_CH_CH, 0x00 }, /* Alt B to IC */
  9859. { 0, 2, LI_COEF_PC_CH, 0x00 }, /* PC to IC */
  9860. { 1, 2, LI_COEF_PC_CH, 0x00 }, /* Alt PC to IC */
  9861. { 2, 2, LI_COEF_CH_CH, 0x00 }, /* IC to IC */
  9862. { 3, 2, LI_COEF_CH_CH, 0x00 }, /* Alt IC to IC */
  9863. { 1, 1, LI_COEF_CH_CH, 0x01 }, /* Alt B to Alt B */
  9864. { 0, 1, LI_COEF_CH_CH, 0x01 }, /* B to Alt B */
  9865. { 1, 1, LI_COEF_PC_CH, 0x80 }, /* Alt PC to Alt B */
  9866. { 0, 1, LI_COEF_PC_CH, 0x01 }, /* PC to Alt B */
  9867. { 3, 1, LI_COEF_CH_CH, 0x00 }, /* Alt IC to Alt B */
  9868. { 2, 1, LI_COEF_CH_CH, 0x00 }, /* IC to Alt B */
  9869. { 1, 1, LI_COEF_CH_PC, 0x80 }, /* Alt B to Alt PC */
  9870. { 0, 1, LI_COEF_CH_PC, 0x01 }, /* B to Alt PC */
  9871. { 1, 1, LI_COEF_PC_PC, 0x01 }, /* Alt PC to Alt PC */
  9872. { 0, 1, LI_COEF_PC_PC, 0x01 }, /* PC to Alt PC */
  9873. { 3, 1, LI_COEF_CH_PC, 0x00 }, /* Alt IC to Alt PC */
  9874. { 2, 1, LI_COEF_CH_PC, 0x00 }, /* IC to Alt PC */
  9875. { 1, 3, LI_COEF_CH_CH, 0x00 }, /* Alt B to Alt IC */
  9876. { 0, 3, LI_COEF_CH_CH, 0x00 }, /* B to Alt IC */
  9877. { 1, 3, LI_COEF_PC_CH, 0x00 }, /* Alt PC to Alt IC */
  9878. { 0, 3, LI_COEF_PC_CH, 0x00 }, /* PC to Alt IC */
  9879. { 3, 3, LI_COEF_CH_CH, 0x00 }, /* Alt IC to Alt IC */
  9880. { 2, 3, LI_COEF_CH_CH, 0x00 } /* IC to Alt IC */
  9881. };
  9882. static byte mixer_swapped_index_bri[] =
  9883. {
  9884. 18, /* B to B */
  9885. 19, /* Alt B to B */
  9886. 20, /* PC to B */
  9887. 21, /* Alt PC to B */
  9888. 22, /* IC to B */
  9889. 23, /* Alt IC to B */
  9890. 24, /* B to PC */
  9891. 25, /* Alt B to PC */
  9892. 26, /* PC to PC */
  9893. 27, /* Alt PC to PC */
  9894. 28, /* IC to PC */
  9895. 29, /* Alt IC to PC */
  9896. 30, /* B to IC */
  9897. 31, /* Alt B to IC */
  9898. 32, /* PC to IC */
  9899. 33, /* Alt PC to IC */
  9900. 34, /* IC to IC */
  9901. 35, /* Alt IC to IC */
  9902. 0, /* Alt B to Alt B */
  9903. 1, /* B to Alt B */
  9904. 2, /* Alt PC to Alt B */
  9905. 3, /* PC to Alt B */
  9906. 4, /* Alt IC to Alt B */
  9907. 5, /* IC to Alt B */
  9908. 6, /* Alt B to Alt PC */
  9909. 7, /* B to Alt PC */
  9910. 8, /* Alt PC to Alt PC */
  9911. 9, /* PC to Alt PC */
  9912. 10, /* Alt IC to Alt PC */
  9913. 11, /* IC to Alt PC */
  9914. 12, /* Alt B to Alt IC */
  9915. 13, /* B to Alt IC */
  9916. 14, /* Alt PC to Alt IC */
  9917. 15, /* PC to Alt IC */
  9918. 16, /* Alt IC to Alt IC */
  9919. 17 /* IC to Alt IC */
  9920. };
  9921. static struct
  9922. {
  9923. byte mask;
  9924. byte from_pc;
  9925. byte to_pc;
  9926. } xconnect_write_prog[] =
  9927. {
  9928. { LI_COEF_CH_CH, false, false },
  9929. { LI_COEF_CH_PC, false, true },
  9930. { LI_COEF_PC_CH, true, false },
  9931. { LI_COEF_PC_PC, true, true }
  9932. };
  9933. static void xconnect_query_addresses (PLCI *plci)
  9934. {
  9935. DIVA_CAPI_ADAPTER *a;
  9936. word w, ch;
  9937. byte *p;
  9938. dbug (1, dprintf ("[%06lx] %s,%d: xconnect_query_addresses",
  9939. (dword)((plci->Id << 8) | UnMapController (plci->adapter->Id)),
  9940. (char *)(FILE_), __LINE__));
  9941. a = plci->adapter;
  9942. if (a->li_pri && ((plci->li_bchannel_id == 0)
  9943. || (li_config_table[a->li_base + (plci->li_bchannel_id - 1)].plci != plci)))
  9944. {
  9945. dbug (1, dprintf ("[%06x] %s,%d: Channel id wiped out",
  9946. (dword)((plci->Id << 8) | UnMapController (plci->adapter->Id)),
  9947. (char *)(FILE_), __LINE__));
  9948. return;
  9949. }
  9950. p = plci->internal_req_buffer;
  9951. ch = (a->li_pri) ? plci->li_bchannel_id - 1 : 0;
  9952. *(p++) = UDATA_REQUEST_XCONNECT_FROM;
  9953. w = ch;
  9954. *(p++) = (byte) w;
  9955. *(p++) = (byte)(w >> 8);
  9956. w = ch | XCONNECT_CHANNEL_PORT_PC;
  9957. *(p++) = (byte) w;
  9958. *(p++) = (byte)(w >> 8);
  9959. plci->NData[0].P = plci->internal_req_buffer;
  9960. plci->NData[0].PLength = p - plci->internal_req_buffer;
  9961. plci->NL.X = plci->NData;
  9962. plci->NL.ReqCh = 0;
  9963. plci->NL.Req = plci->nl_req = (byte) N_UDATA;
  9964. plci->adapter->request (&plci->NL);
  9965. }
  9966. static void xconnect_write_coefs (PLCI *plci, word internal_command)
  9967. {
  9968. dbug (1, dprintf ("[%06lx] %s,%d: xconnect_write_coefs %04x",
  9969. (dword)((plci->Id << 8) | UnMapController (plci->adapter->Id)),
  9970. (char *)(FILE_), __LINE__, internal_command));
  9971. plci->li_write_command = internal_command;
  9972. plci->li_write_channel = 0;
  9973. }
  9974. static byte xconnect_write_coefs_process (dword Id, PLCI *plci, byte Rc)
  9975. {
  9976. DIVA_CAPI_ADAPTER *a;
  9977. word w, n, i, j, r, s, to_ch;
  9978. dword d;
  9979. byte *p;
  9980. struct xconnect_transfer_address_s *transfer_address;
  9981. byte ch_map[MIXER_CHANNELS_BRI];
  9982. dbug (1, dprintf ("[%06x] %s,%d: xconnect_write_coefs_process %02x %d",
  9983. UnMapId (Id), (char *)(FILE_), __LINE__, Rc, plci->li_write_channel));
  9984. a = plci->adapter;
  9985. if ((plci->li_bchannel_id == 0)
  9986. || (li_config_table[a->li_base + (plci->li_bchannel_id - 1)].plci != plci))
  9987. {
  9988. dbug (1, dprintf ("[%06x] %s,%d: Channel id wiped out",
  9989. UnMapId (Id), (char *)(FILE_), __LINE__));
  9990. return (true);
  9991. }
  9992. i = a->li_base + (plci->li_bchannel_id - 1);
  9993. j = plci->li_write_channel;
  9994. p = plci->internal_req_buffer;
  9995. if (j != 0)
  9996. {
  9997. if ((Rc != OK) && (Rc != OK_FC))
  9998. {
  9999. dbug (1, dprintf ("[%06lx] %s,%d: LI write coefs failed %02x",
  10000. UnMapId (Id), (char *)(FILE_), __LINE__, Rc));
  10001. return (false);
  10002. }
  10003. }
  10004. if (li_config_table[i].adapter->manufacturer_features & MANUFACTURER_FEATURE_XCONNECT)
  10005. {
  10006. r = 0;
  10007. s = 0;
  10008. if (j < li_total_channels)
  10009. {
  10010. if (li_config_table[i].channel & LI_CHANNEL_ADDRESSES_SET)
  10011. {
  10012. s = ((li_config_table[i].send_b.card_address.low | li_config_table[i].send_b.card_address.high) ?
  10013. (LI_COEF_CH_CH | LI_COEF_CH_PC | LI_COEF_PC_CH | LI_COEF_PC_PC) : (LI_COEF_CH_PC | LI_COEF_PC_PC)) &
  10014. ((li_config_table[i].send_pc.card_address.low | li_config_table[i].send_pc.card_address.high) ?
  10015. (LI_COEF_CH_CH | LI_COEF_CH_PC | LI_COEF_PC_CH | LI_COEF_PC_PC) : (LI_COEF_CH_CH | LI_COEF_PC_CH));
  10016. }
  10017. r = ((li_config_table[i].coef_table[j] & 0xf) ^ (li_config_table[i].coef_table[j] >> 4));
  10018. while ((j < li_total_channels)
  10019. && ((r == 0)
  10020. || (!(li_config_table[j].channel & LI_CHANNEL_ADDRESSES_SET))
  10021. || (!li_config_table[j].adapter->li_pri
  10022. && (j >= li_config_table[j].adapter->li_base + MIXER_BCHANNELS_BRI))
  10023. || (((li_config_table[j].send_b.card_address.low != li_config_table[i].send_b.card_address.low)
  10024. || (li_config_table[j].send_b.card_address.high != li_config_table[i].send_b.card_address.high))
  10025. && (!(a->manufacturer_features & MANUFACTURER_FEATURE_DMACONNECT)
  10026. || !(li_config_table[j].adapter->manufacturer_features & MANUFACTURER_FEATURE_DMACONNECT)))
  10027. || ((li_config_table[j].adapter->li_base != a->li_base)
  10028. && !(r & s &
  10029. ((li_config_table[j].send_b.card_address.low | li_config_table[j].send_b.card_address.high) ?
  10030. (LI_COEF_CH_CH | LI_COEF_CH_PC | LI_COEF_PC_CH | LI_COEF_PC_PC) : (LI_COEF_PC_CH | LI_COEF_PC_PC)) &
  10031. ((li_config_table[j].send_pc.card_address.low | li_config_table[j].send_pc.card_address.high) ?
  10032. (LI_COEF_CH_CH | LI_COEF_CH_PC | LI_COEF_PC_CH | LI_COEF_PC_PC) : (LI_COEF_CH_CH | LI_COEF_CH_PC))))))
  10033. {
  10034. j++;
  10035. if (j < li_total_channels)
  10036. r = ((li_config_table[i].coef_table[j] & 0xf) ^ (li_config_table[i].coef_table[j] >> 4));
  10037. }
  10038. }
  10039. if (j < li_total_channels)
  10040. {
  10041. plci->internal_command = plci->li_write_command;
  10042. if (plci_nl_busy (plci))
  10043. return (true);
  10044. to_ch = (a->li_pri) ? plci->li_bchannel_id - 1 : 0;
  10045. *(p++) = UDATA_REQUEST_XCONNECT_TO;
  10046. do
  10047. {
  10048. if (li_config_table[j].adapter->li_base != a->li_base)
  10049. {
  10050. r &= s &
  10051. ((li_config_table[j].send_b.card_address.low | li_config_table[j].send_b.card_address.high) ?
  10052. (LI_COEF_CH_CH | LI_COEF_CH_PC | LI_COEF_PC_CH | LI_COEF_PC_PC) : (LI_COEF_PC_CH | LI_COEF_PC_PC)) &
  10053. ((li_config_table[j].send_pc.card_address.low | li_config_table[j].send_pc.card_address.high) ?
  10054. (LI_COEF_CH_CH | LI_COEF_CH_PC | LI_COEF_PC_CH | LI_COEF_PC_PC) : (LI_COEF_CH_CH | LI_COEF_CH_PC));
  10055. }
  10056. n = 0;
  10057. do
  10058. {
  10059. if (r & xconnect_write_prog[n].mask)
  10060. {
  10061. if (xconnect_write_prog[n].from_pc)
  10062. transfer_address = &(li_config_table[j].send_pc);
  10063. else
  10064. transfer_address = &(li_config_table[j].send_b);
  10065. d = transfer_address->card_address.low;
  10066. *(p++) = (byte) d;
  10067. *(p++) = (byte)(d >> 8);
  10068. *(p++) = (byte)(d >> 16);
  10069. *(p++) = (byte)(d >> 24);
  10070. d = transfer_address->card_address.high;
  10071. *(p++) = (byte) d;
  10072. *(p++) = (byte)(d >> 8);
  10073. *(p++) = (byte)(d >> 16);
  10074. *(p++) = (byte)(d >> 24);
  10075. d = transfer_address->offset;
  10076. *(p++) = (byte) d;
  10077. *(p++) = (byte)(d >> 8);
  10078. *(p++) = (byte)(d >> 16);
  10079. *(p++) = (byte)(d >> 24);
  10080. w = xconnect_write_prog[n].to_pc ? to_ch | XCONNECT_CHANNEL_PORT_PC : to_ch;
  10081. *(p++) = (byte) w;
  10082. *(p++) = (byte)(w >> 8);
  10083. w = ((li_config_table[i].coef_table[j] & xconnect_write_prog[n].mask) == 0) ? 0x01 :
  10084. (li_config_table[i].adapter->u_law ?
  10085. (li_config_table[j].adapter->u_law ? 0x80 : 0x86) :
  10086. (li_config_table[j].adapter->u_law ? 0x7a : 0x80));
  10087. *(p++) = (byte) w;
  10088. *(p++) = (byte) 0;
  10089. li_config_table[i].coef_table[j] ^= xconnect_write_prog[n].mask << 4;
  10090. }
  10091. n++;
  10092. } while ((n < ARRAY_SIZE(xconnect_write_prog))
  10093. && ((p - plci->internal_req_buffer) + 16 < INTERNAL_REQ_BUFFER_SIZE));
  10094. if (n == ARRAY_SIZE(xconnect_write_prog))
  10095. {
  10096. do
  10097. {
  10098. j++;
  10099. if (j < li_total_channels)
  10100. r = ((li_config_table[i].coef_table[j] & 0xf) ^ (li_config_table[i].coef_table[j] >> 4));
  10101. } while ((j < li_total_channels)
  10102. && ((r == 0)
  10103. || (!(li_config_table[j].channel & LI_CHANNEL_ADDRESSES_SET))
  10104. || (!li_config_table[j].adapter->li_pri
  10105. && (j >= li_config_table[j].adapter->li_base + MIXER_BCHANNELS_BRI))
  10106. || (((li_config_table[j].send_b.card_address.low != li_config_table[i].send_b.card_address.low)
  10107. || (li_config_table[j].send_b.card_address.high != li_config_table[i].send_b.card_address.high))
  10108. && (!(a->manufacturer_features & MANUFACTURER_FEATURE_DMACONNECT)
  10109. || !(li_config_table[j].adapter->manufacturer_features & MANUFACTURER_FEATURE_DMACONNECT)))
  10110. || ((li_config_table[j].adapter->li_base != a->li_base)
  10111. && !(r & s &
  10112. ((li_config_table[j].send_b.card_address.low | li_config_table[j].send_b.card_address.high) ?
  10113. (LI_COEF_CH_CH | LI_COEF_CH_PC | LI_COEF_PC_CH | LI_COEF_PC_PC) : (LI_COEF_PC_CH | LI_COEF_PC_PC)) &
  10114. ((li_config_table[j].send_pc.card_address.low | li_config_table[j].send_pc.card_address.high) ?
  10115. (LI_COEF_CH_CH | LI_COEF_CH_PC | LI_COEF_PC_CH | LI_COEF_PC_PC) : (LI_COEF_CH_CH | LI_COEF_CH_PC))))));
  10116. }
  10117. } while ((j < li_total_channels)
  10118. && ((p - plci->internal_req_buffer) + 16 < INTERNAL_REQ_BUFFER_SIZE));
  10119. }
  10120. else if (j == li_total_channels)
  10121. {
  10122. plci->internal_command = plci->li_write_command;
  10123. if (plci_nl_busy (plci))
  10124. return (true);
  10125. if (a->li_pri)
  10126. {
  10127. *(p++) = UDATA_REQUEST_SET_MIXER_COEFS_PRI_SYNC;
  10128. w = 0;
  10129. if (li_config_table[i].channel & LI_CHANNEL_TX_DATA)
  10130. w |= MIXER_FEATURE_ENABLE_TX_DATA;
  10131. if (li_config_table[i].channel & LI_CHANNEL_RX_DATA)
  10132. w |= MIXER_FEATURE_ENABLE_RX_DATA;
  10133. *(p++) = (byte) w;
  10134. *(p++) = (byte)(w >> 8);
  10135. }
  10136. else
  10137. {
  10138. *(p++) = UDATA_REQUEST_SET_MIXER_COEFS_BRI;
  10139. w = 0;
  10140. if ((plci->tel == ADV_VOICE) && (plci == a->AdvSignalPLCI)
  10141. && (ADV_VOICE_NEW_COEF_BASE + sizeof(word) <= a->adv_voice_coef_length))
  10142. {
  10143. w = GET_WORD (a->adv_voice_coef_buffer + ADV_VOICE_NEW_COEF_BASE);
  10144. }
  10145. if (li_config_table[i].channel & LI_CHANNEL_TX_DATA)
  10146. w |= MIXER_FEATURE_ENABLE_TX_DATA;
  10147. if (li_config_table[i].channel & LI_CHANNEL_RX_DATA)
  10148. w |= MIXER_FEATURE_ENABLE_RX_DATA;
  10149. *(p++) = (byte) w;
  10150. *(p++) = (byte)(w >> 8);
  10151. for (j = 0; j < sizeof(ch_map); j += 2)
  10152. {
  10153. if (plci->li_bchannel_id == 2)
  10154. {
  10155. ch_map[j] = (byte)(j+1);
  10156. ch_map[j+1] = (byte) j;
  10157. }
  10158. else
  10159. {
  10160. ch_map[j] = (byte) j;
  10161. ch_map[j+1] = (byte)(j+1);
  10162. }
  10163. }
  10164. for (n = 0; n < ARRAY_SIZE(mixer_write_prog_bri); n++)
  10165. {
  10166. i = a->li_base + ch_map[mixer_write_prog_bri[n].to_ch];
  10167. j = a->li_base + ch_map[mixer_write_prog_bri[n].from_ch];
  10168. if (li_config_table[i].channel & li_config_table[j].channel & LI_CHANNEL_INVOLVED)
  10169. {
  10170. *p = (mixer_write_prog_bri[n].xconnect_override != 0) ?
  10171. mixer_write_prog_bri[n].xconnect_override :
  10172. ((li_config_table[i].coef_table[j] & mixer_write_prog_bri[n].mask) ? 0x80 : 0x01);
  10173. if ((i >= a->li_base + MIXER_BCHANNELS_BRI) || (j >= a->li_base + MIXER_BCHANNELS_BRI))
  10174. {
  10175. w = ((li_config_table[i].coef_table[j] & 0xf) ^ (li_config_table[i].coef_table[j] >> 4));
  10176. li_config_table[i].coef_table[j] ^= (w & mixer_write_prog_bri[n].mask) << 4;
  10177. }
  10178. }
  10179. else
  10180. {
  10181. *p = 0x00;
  10182. if ((a->AdvSignalPLCI != NULL) && (a->AdvSignalPLCI->tel == ADV_VOICE))
  10183. {
  10184. w = (plci == a->AdvSignalPLCI) ? n : mixer_swapped_index_bri[n];
  10185. if (ADV_VOICE_NEW_COEF_BASE + sizeof(word) + w < a->adv_voice_coef_length)
  10186. *p = a->adv_voice_coef_buffer[ADV_VOICE_NEW_COEF_BASE + sizeof(word) + w];
  10187. }
  10188. }
  10189. p++;
  10190. }
  10191. }
  10192. j = li_total_channels + 1;
  10193. }
  10194. }
  10195. else
  10196. {
  10197. if (j <= li_total_channels)
  10198. {
  10199. plci->internal_command = plci->li_write_command;
  10200. if (plci_nl_busy (plci))
  10201. return (true);
  10202. if (j < a->li_base)
  10203. j = a->li_base;
  10204. if (a->li_pri)
  10205. {
  10206. *(p++) = UDATA_REQUEST_SET_MIXER_COEFS_PRI_SYNC;
  10207. w = 0;
  10208. if (li_config_table[i].channel & LI_CHANNEL_TX_DATA)
  10209. w |= MIXER_FEATURE_ENABLE_TX_DATA;
  10210. if (li_config_table[i].channel & LI_CHANNEL_RX_DATA)
  10211. w |= MIXER_FEATURE_ENABLE_RX_DATA;
  10212. *(p++) = (byte) w;
  10213. *(p++) = (byte)(w >> 8);
  10214. for (n = 0; n < ARRAY_SIZE(mixer_write_prog_pri); n++)
  10215. {
  10216. *(p++) = (byte)((plci->li_bchannel_id - 1) | mixer_write_prog_pri[n].line_flags);
  10217. for (j = a->li_base; j < a->li_base + MIXER_CHANNELS_PRI; j++)
  10218. {
  10219. w = ((li_config_table[i].coef_table[j] & 0xf) ^ (li_config_table[i].coef_table[j] >> 4));
  10220. if (w & mixer_write_prog_pri[n].mask)
  10221. {
  10222. *(p++) = (li_config_table[i].coef_table[j] & mixer_write_prog_pri[n].mask) ? 0x80 : 0x01;
  10223. li_config_table[i].coef_table[j] ^= mixer_write_prog_pri[n].mask << 4;
  10224. }
  10225. else
  10226. *(p++) = 0x00;
  10227. }
  10228. *(p++) = (byte)((plci->li_bchannel_id - 1) | MIXER_COEF_LINE_ROW_FLAG | mixer_write_prog_pri[n].line_flags);
  10229. for (j = a->li_base; j < a->li_base + MIXER_CHANNELS_PRI; j++)
  10230. {
  10231. w = ((li_config_table[j].coef_table[i] & 0xf) ^ (li_config_table[j].coef_table[i] >> 4));
  10232. if (w & mixer_write_prog_pri[n].mask)
  10233. {
  10234. *(p++) = (li_config_table[j].coef_table[i] & mixer_write_prog_pri[n].mask) ? 0x80 : 0x01;
  10235. li_config_table[j].coef_table[i] ^= mixer_write_prog_pri[n].mask << 4;
  10236. }
  10237. else
  10238. *(p++) = 0x00;
  10239. }
  10240. }
  10241. }
  10242. else
  10243. {
  10244. *(p++) = UDATA_REQUEST_SET_MIXER_COEFS_BRI;
  10245. w = 0;
  10246. if ((plci->tel == ADV_VOICE) && (plci == a->AdvSignalPLCI)
  10247. && (ADV_VOICE_NEW_COEF_BASE + sizeof(word) <= a->adv_voice_coef_length))
  10248. {
  10249. w = GET_WORD (a->adv_voice_coef_buffer + ADV_VOICE_NEW_COEF_BASE);
  10250. }
  10251. if (li_config_table[i].channel & LI_CHANNEL_TX_DATA)
  10252. w |= MIXER_FEATURE_ENABLE_TX_DATA;
  10253. if (li_config_table[i].channel & LI_CHANNEL_RX_DATA)
  10254. w |= MIXER_FEATURE_ENABLE_RX_DATA;
  10255. *(p++) = (byte) w;
  10256. *(p++) = (byte)(w >> 8);
  10257. for (j = 0; j < sizeof(ch_map); j += 2)
  10258. {
  10259. if (plci->li_bchannel_id == 2)
  10260. {
  10261. ch_map[j] = (byte)(j+1);
  10262. ch_map[j+1] = (byte) j;
  10263. }
  10264. else
  10265. {
  10266. ch_map[j] = (byte) j;
  10267. ch_map[j+1] = (byte)(j+1);
  10268. }
  10269. }
  10270. for (n = 0; n < ARRAY_SIZE(mixer_write_prog_bri); n++)
  10271. {
  10272. i = a->li_base + ch_map[mixer_write_prog_bri[n].to_ch];
  10273. j = a->li_base + ch_map[mixer_write_prog_bri[n].from_ch];
  10274. if (li_config_table[i].channel & li_config_table[j].channel & LI_CHANNEL_INVOLVED)
  10275. {
  10276. *p = ((li_config_table[i].coef_table[j] & mixer_write_prog_bri[n].mask) ? 0x80 : 0x01);
  10277. w = ((li_config_table[i].coef_table[j] & 0xf) ^ (li_config_table[i].coef_table[j] >> 4));
  10278. li_config_table[i].coef_table[j] ^= (w & mixer_write_prog_bri[n].mask) << 4;
  10279. }
  10280. else
  10281. {
  10282. *p = 0x00;
  10283. if ((a->AdvSignalPLCI != NULL) && (a->AdvSignalPLCI->tel == ADV_VOICE))
  10284. {
  10285. w = (plci == a->AdvSignalPLCI) ? n : mixer_swapped_index_bri[n];
  10286. if (ADV_VOICE_NEW_COEF_BASE + sizeof(word) + w < a->adv_voice_coef_length)
  10287. *p = a->adv_voice_coef_buffer[ADV_VOICE_NEW_COEF_BASE + sizeof(word) + w];
  10288. }
  10289. }
  10290. p++;
  10291. }
  10292. }
  10293. j = li_total_channels + 1;
  10294. }
  10295. }
  10296. plci->li_write_channel = j;
  10297. if (p != plci->internal_req_buffer)
  10298. {
  10299. plci->NData[0].P = plci->internal_req_buffer;
  10300. plci->NData[0].PLength = p - plci->internal_req_buffer;
  10301. plci->NL.X = plci->NData;
  10302. plci->NL.ReqCh = 0;
  10303. plci->NL.Req = plci->nl_req = (byte) N_UDATA;
  10304. plci->adapter->request (&plci->NL);
  10305. }
  10306. return (true);
  10307. }
  10308. static void mixer_notify_update (PLCI *plci, byte others)
  10309. {
  10310. DIVA_CAPI_ADAPTER *a;
  10311. word i, w;
  10312. PLCI *notify_plci;
  10313. byte msg[sizeof(CAPI_MSG_HEADER) + 6];
  10314. dbug (1, dprintf ("[%06lx] %s,%d: mixer_notify_update %d",
  10315. (dword)((plci->Id << 8) | UnMapController (plci->adapter->Id)),
  10316. (char *)(FILE_), __LINE__, others));
  10317. a = plci->adapter;
  10318. if (a->profile.Global_Options & GL_LINE_INTERCONNECT_SUPPORTED)
  10319. {
  10320. if (others)
  10321. plci->li_notify_update = true;
  10322. i = 0;
  10323. do
  10324. {
  10325. notify_plci = NULL;
  10326. if (others)
  10327. {
  10328. while ((i < li_total_channels) && (li_config_table[i].plci == NULL))
  10329. i++;
  10330. if (i < li_total_channels)
  10331. notify_plci = li_config_table[i++].plci;
  10332. }
  10333. else
  10334. {
  10335. if ((plci->li_bchannel_id != 0)
  10336. && (li_config_table[a->li_base + (plci->li_bchannel_id - 1)].plci == plci))
  10337. {
  10338. notify_plci = plci;
  10339. }
  10340. }
  10341. if ((notify_plci != NULL)
  10342. && !notify_plci->li_notify_update
  10343. && (notify_plci->appl != NULL)
  10344. && (notify_plci->State)
  10345. && notify_plci->NL.Id && !notify_plci->nl_remove_id)
  10346. {
  10347. notify_plci->li_notify_update = true;
  10348. ((CAPI_MSG *) msg)->header.length = 18;
  10349. ((CAPI_MSG *) msg)->header.appl_id = notify_plci->appl->Id;
  10350. ((CAPI_MSG *) msg)->header.command = _FACILITY_R;
  10351. ((CAPI_MSG *) msg)->header.number = 0;
  10352. ((CAPI_MSG *) msg)->header.controller = notify_plci->adapter->Id;
  10353. ((CAPI_MSG *) msg)->header.plci = notify_plci->Id;
  10354. ((CAPI_MSG *) msg)->header.ncci = 0;
  10355. ((CAPI_MSG *) msg)->info.facility_req.Selector = SELECTOR_LINE_INTERCONNECT;
  10356. ((CAPI_MSG *) msg)->info.facility_req.structs[0] = 3;
  10357. PUT_WORD (&(((CAPI_MSG *) msg)->info.facility_req.structs[1]), LI_REQ_SILENT_UPDATE);
  10358. ((CAPI_MSG *) msg)->info.facility_req.structs[3] = 0;
  10359. w = api_put (notify_plci->appl, (CAPI_MSG *) msg);
  10360. if (w != _QUEUE_FULL)
  10361. {
  10362. if (w != 0)
  10363. {
  10364. dbug (1, dprintf ("[%06lx] %s,%d: Interconnect notify failed %06x %d",
  10365. (dword)((plci->Id << 8) | UnMapController (plci->adapter->Id)),
  10366. (char *)(FILE_), __LINE__,
  10367. (dword)((notify_plci->Id << 8) | UnMapController (notify_plci->adapter->Id)), w));
  10368. }
  10369. notify_plci->li_notify_update = false;
  10370. }
  10371. }
  10372. } while (others && (notify_plci != NULL));
  10373. if (others)
  10374. plci->li_notify_update = false;
  10375. }
  10376. }
  10377. static void mixer_clear_config (PLCI *plci)
  10378. {
  10379. DIVA_CAPI_ADAPTER *a;
  10380. word i, j;
  10381. dbug (1, dprintf ("[%06lx] %s,%d: mixer_clear_config",
  10382. (dword)((plci->Id << 8) | UnMapController (plci->adapter->Id)),
  10383. (char *)(FILE_), __LINE__));
  10384. plci->li_notify_update = false;
  10385. plci->li_plci_b_write_pos = 0;
  10386. plci->li_plci_b_read_pos = 0;
  10387. plci->li_plci_b_req_pos = 0;
  10388. a = plci->adapter;
  10389. if ((plci->li_bchannel_id != 0)
  10390. && (li_config_table[a->li_base + (plci->li_bchannel_id - 1)].plci == plci))
  10391. {
  10392. i = a->li_base + (plci->li_bchannel_id - 1);
  10393. li_config_table[i].curchnl = 0;
  10394. li_config_table[i].channel = 0;
  10395. li_config_table[i].chflags = 0;
  10396. for (j = 0; j < li_total_channels; j++)
  10397. {
  10398. li_config_table[j].flag_table[i] = 0;
  10399. li_config_table[i].flag_table[j] = 0;
  10400. li_config_table[i].coef_table[j] = 0;
  10401. li_config_table[j].coef_table[i] = 0;
  10402. }
  10403. if (!a->li_pri)
  10404. {
  10405. li_config_table[i].coef_table[i] |= LI_COEF_CH_PC_SET | LI_COEF_PC_CH_SET;
  10406. if ((plci->tel == ADV_VOICE) && (plci == a->AdvSignalPLCI))
  10407. {
  10408. i = a->li_base + MIXER_IC_CHANNEL_BASE + (plci->li_bchannel_id - 1);
  10409. li_config_table[i].curchnl = 0;
  10410. li_config_table[i].channel = 0;
  10411. li_config_table[i].chflags = 0;
  10412. for (j = 0; j < li_total_channels; j++)
  10413. {
  10414. li_config_table[i].flag_table[j] = 0;
  10415. li_config_table[j].flag_table[i] = 0;
  10416. li_config_table[i].coef_table[j] = 0;
  10417. li_config_table[j].coef_table[i] = 0;
  10418. }
  10419. if (a->manufacturer_features & MANUFACTURER_FEATURE_SLAVE_CODEC)
  10420. {
  10421. i = a->li_base + MIXER_IC_CHANNEL_BASE + (2 - plci->li_bchannel_id);
  10422. li_config_table[i].curchnl = 0;
  10423. li_config_table[i].channel = 0;
  10424. li_config_table[i].chflags = 0;
  10425. for (j = 0; j < li_total_channels; j++)
  10426. {
  10427. li_config_table[i].flag_table[j] = 0;
  10428. li_config_table[j].flag_table[i] = 0;
  10429. li_config_table[i].coef_table[j] = 0;
  10430. li_config_table[j].coef_table[i] = 0;
  10431. }
  10432. }
  10433. }
  10434. }
  10435. }
  10436. }
  10437. static void mixer_prepare_switch (dword Id, PLCI *plci)
  10438. {
  10439. dbug (1, dprintf ("[%06lx] %s,%d: mixer_prepare_switch",
  10440. UnMapId (Id), (char *)(FILE_), __LINE__));
  10441. do
  10442. {
  10443. mixer_indication_coefs_set (Id, plci);
  10444. } while (plci->li_plci_b_read_pos != plci->li_plci_b_req_pos);
  10445. }
  10446. static word mixer_save_config (dword Id, PLCI *plci, byte Rc)
  10447. {
  10448. DIVA_CAPI_ADAPTER *a;
  10449. word i, j;
  10450. dbug (1, dprintf ("[%06lx] %s,%d: mixer_save_config %02x %d",
  10451. UnMapId (Id), (char *)(FILE_), __LINE__, Rc, plci->adjust_b_state));
  10452. a = plci->adapter;
  10453. if ((plci->li_bchannel_id != 0)
  10454. && (li_config_table[a->li_base + (plci->li_bchannel_id - 1)].plci == plci))
  10455. {
  10456. i = a->li_base + (plci->li_bchannel_id - 1);
  10457. for (j = 0; j < li_total_channels; j++)
  10458. {
  10459. li_config_table[i].coef_table[j] &= 0xf;
  10460. li_config_table[j].coef_table[i] &= 0xf;
  10461. }
  10462. if (!a->li_pri)
  10463. li_config_table[i].coef_table[i] |= LI_COEF_CH_PC_SET | LI_COEF_PC_CH_SET;
  10464. }
  10465. return (GOOD);
  10466. }
  10467. static word mixer_restore_config (dword Id, PLCI *plci, byte Rc)
  10468. {
  10469. DIVA_CAPI_ADAPTER *a;
  10470. word Info;
  10471. dbug (1, dprintf ("[%06lx] %s,%d: mixer_restore_config %02x %d",
  10472. UnMapId (Id), (char *)(FILE_), __LINE__, Rc, plci->adjust_b_state));
  10473. Info = GOOD;
  10474. a = plci->adapter;
  10475. if ((plci->B1_facilities & B1_FACILITY_MIXER)
  10476. && (plci->li_bchannel_id != 0)
  10477. && (li_config_table[a->li_base + (plci->li_bchannel_id - 1)].plci == plci))
  10478. {
  10479. switch (plci->adjust_b_state)
  10480. {
  10481. case ADJUST_B_RESTORE_MIXER_1:
  10482. if (a->manufacturer_features & MANUFACTURER_FEATURE_XCONNECT)
  10483. {
  10484. plci->internal_command = plci->adjust_b_command;
  10485. if (plci_nl_busy (plci))
  10486. {
  10487. plci->adjust_b_state = ADJUST_B_RESTORE_MIXER_1;
  10488. break;
  10489. }
  10490. xconnect_query_addresses (plci);
  10491. plci->adjust_b_state = ADJUST_B_RESTORE_MIXER_2;
  10492. break;
  10493. }
  10494. plci->adjust_b_state = ADJUST_B_RESTORE_MIXER_5;
  10495. Rc = OK;
  10496. case ADJUST_B_RESTORE_MIXER_2:
  10497. case ADJUST_B_RESTORE_MIXER_3:
  10498. case ADJUST_B_RESTORE_MIXER_4:
  10499. if ((Rc != OK) && (Rc != OK_FC) && (Rc != 0))
  10500. {
  10501. dbug (1, dprintf ("[%06lx] %s,%d: Adjust B query addresses failed %02x",
  10502. UnMapId (Id), (char *)(FILE_), __LINE__, Rc));
  10503. Info = _WRONG_STATE;
  10504. break;
  10505. }
  10506. if (Rc == OK)
  10507. {
  10508. if (plci->adjust_b_state == ADJUST_B_RESTORE_MIXER_2)
  10509. plci->adjust_b_state = ADJUST_B_RESTORE_MIXER_3;
  10510. else if (plci->adjust_b_state == ADJUST_B_RESTORE_MIXER_4)
  10511. plci->adjust_b_state = ADJUST_B_RESTORE_MIXER_5;
  10512. }
  10513. else if (Rc == 0)
  10514. {
  10515. if (plci->adjust_b_state == ADJUST_B_RESTORE_MIXER_2)
  10516. plci->adjust_b_state = ADJUST_B_RESTORE_MIXER_4;
  10517. else if (plci->adjust_b_state == ADJUST_B_RESTORE_MIXER_3)
  10518. plci->adjust_b_state = ADJUST_B_RESTORE_MIXER_5;
  10519. }
  10520. if (plci->adjust_b_state != ADJUST_B_RESTORE_MIXER_5)
  10521. {
  10522. plci->internal_command = plci->adjust_b_command;
  10523. break;
  10524. }
  10525. case ADJUST_B_RESTORE_MIXER_5:
  10526. xconnect_write_coefs (plci, plci->adjust_b_command);
  10527. plci->adjust_b_state = ADJUST_B_RESTORE_MIXER_6;
  10528. Rc = OK;
  10529. case ADJUST_B_RESTORE_MIXER_6:
  10530. if (!xconnect_write_coefs_process (Id, plci, Rc))
  10531. {
  10532. dbug (1, dprintf ("[%06lx] %s,%d: Write mixer coefs failed",
  10533. UnMapId (Id), (char *)(FILE_), __LINE__));
  10534. Info = _FACILITY_NOT_SUPPORTED;
  10535. break;
  10536. }
  10537. if (plci->internal_command)
  10538. break;
  10539. plci->adjust_b_state = ADJUST_B_RESTORE_MIXER_7;
  10540. case ADJUST_B_RESTORE_MIXER_7:
  10541. break;
  10542. }
  10543. }
  10544. return (Info);
  10545. }
  10546. static void mixer_command (dword Id, PLCI *plci, byte Rc)
  10547. {
  10548. DIVA_CAPI_ADAPTER *a;
  10549. word i, internal_command, Info;
  10550. dbug (1, dprintf ("[%06lx] %s,%d: mixer_command %02x %04x %04x",
  10551. UnMapId (Id), (char *)(FILE_), __LINE__, Rc, plci->internal_command,
  10552. plci->li_cmd));
  10553. Info = GOOD;
  10554. a = plci->adapter;
  10555. internal_command = plci->internal_command;
  10556. plci->internal_command = 0;
  10557. switch (plci->li_cmd)
  10558. {
  10559. case LI_REQ_CONNECT:
  10560. case LI_REQ_DISCONNECT:
  10561. case LI_REQ_SILENT_UPDATE:
  10562. switch (internal_command)
  10563. {
  10564. default:
  10565. if (plci->li_channel_bits & LI_CHANNEL_INVOLVED)
  10566. {
  10567. adjust_b1_resource (Id, plci, NULL, (word)(plci->B1_facilities |
  10568. B1_FACILITY_MIXER), MIXER_COMMAND_1);
  10569. }
  10570. case MIXER_COMMAND_1:
  10571. if (plci->li_channel_bits & LI_CHANNEL_INVOLVED)
  10572. {
  10573. if (adjust_b_process (Id, plci, Rc) != GOOD)
  10574. {
  10575. dbug (1, dprintf ("[%06lx] %s,%d: Load mixer failed",
  10576. UnMapId (Id), (char *)(FILE_), __LINE__));
  10577. Info = _FACILITY_NOT_SUPPORTED;
  10578. break;
  10579. }
  10580. if (plci->internal_command)
  10581. return;
  10582. }
  10583. plci->li_plci_b_req_pos = plci->li_plci_b_write_pos;
  10584. if ((plci->li_channel_bits & LI_CHANNEL_INVOLVED)
  10585. || ((get_b1_facilities (plci, plci->B1_resource) & B1_FACILITY_MIXER)
  10586. && (add_b1_facilities (plci, plci->B1_resource, (word)(plci->B1_facilities &
  10587. ~B1_FACILITY_MIXER)) == plci->B1_resource)))
  10588. {
  10589. xconnect_write_coefs (plci, MIXER_COMMAND_2);
  10590. }
  10591. else
  10592. {
  10593. do
  10594. {
  10595. mixer_indication_coefs_set (Id, plci);
  10596. } while (plci->li_plci_b_read_pos != plci->li_plci_b_req_pos);
  10597. }
  10598. case MIXER_COMMAND_2:
  10599. if ((plci->li_channel_bits & LI_CHANNEL_INVOLVED)
  10600. || ((get_b1_facilities (plci, plci->B1_resource) & B1_FACILITY_MIXER)
  10601. && (add_b1_facilities (plci, plci->B1_resource, (word)(plci->B1_facilities &
  10602. ~B1_FACILITY_MIXER)) == plci->B1_resource)))
  10603. {
  10604. if (!xconnect_write_coefs_process (Id, plci, Rc))
  10605. {
  10606. dbug (1, dprintf ("[%06lx] %s,%d: Write mixer coefs failed",
  10607. UnMapId (Id), (char *)(FILE_), __LINE__));
  10608. if (plci->li_plci_b_write_pos != plci->li_plci_b_req_pos)
  10609. {
  10610. do
  10611. {
  10612. plci->li_plci_b_write_pos = (plci->li_plci_b_write_pos == 0) ?
  10613. LI_PLCI_B_QUEUE_ENTRIES-1 : plci->li_plci_b_write_pos - 1;
  10614. i = (plci->li_plci_b_write_pos == 0) ?
  10615. LI_PLCI_B_QUEUE_ENTRIES-1 : plci->li_plci_b_write_pos - 1;
  10616. } while ((plci->li_plci_b_write_pos != plci->li_plci_b_req_pos)
  10617. && !(plci->li_plci_b_queue[i] & LI_PLCI_B_LAST_FLAG));
  10618. }
  10619. Info = _FACILITY_NOT_SUPPORTED;
  10620. break;
  10621. }
  10622. if (plci->internal_command)
  10623. return;
  10624. }
  10625. if (!(plci->li_channel_bits & LI_CHANNEL_INVOLVED))
  10626. {
  10627. adjust_b1_resource (Id, plci, NULL, (word)(plci->B1_facilities &
  10628. ~B1_FACILITY_MIXER), MIXER_COMMAND_3);
  10629. }
  10630. case MIXER_COMMAND_3:
  10631. if (!(plci->li_channel_bits & LI_CHANNEL_INVOLVED))
  10632. {
  10633. if (adjust_b_process (Id, plci, Rc) != GOOD)
  10634. {
  10635. dbug (1, dprintf ("[%06lx] %s,%d: Unload mixer failed",
  10636. UnMapId (Id), (char *)(FILE_), __LINE__));
  10637. Info = _FACILITY_NOT_SUPPORTED;
  10638. break;
  10639. }
  10640. if (plci->internal_command)
  10641. return;
  10642. }
  10643. break;
  10644. }
  10645. break;
  10646. }
  10647. if ((plci->li_bchannel_id == 0)
  10648. || (li_config_table[a->li_base + (plci->li_bchannel_id - 1)].plci != plci))
  10649. {
  10650. dbug (1, dprintf ("[%06x] %s,%d: Channel id wiped out %d",
  10651. UnMapId (Id), (char *)(FILE_), __LINE__, (int)(plci->li_bchannel_id)));
  10652. }
  10653. else
  10654. {
  10655. i = a->li_base + (plci->li_bchannel_id - 1);
  10656. li_config_table[i].curchnl = plci->li_channel_bits;
  10657. if (!a->li_pri && (plci->tel == ADV_VOICE) && (plci == a->AdvSignalPLCI))
  10658. {
  10659. i = a->li_base + MIXER_IC_CHANNEL_BASE + (plci->li_bchannel_id - 1);
  10660. li_config_table[i].curchnl = plci->li_channel_bits;
  10661. if (a->manufacturer_features & MANUFACTURER_FEATURE_SLAVE_CODEC)
  10662. {
  10663. i = a->li_base + MIXER_IC_CHANNEL_BASE + (2 - plci->li_bchannel_id);
  10664. li_config_table[i].curchnl = plci->li_channel_bits;
  10665. }
  10666. }
  10667. }
  10668. }
  10669. static void li_update_connect (dword Id, DIVA_CAPI_ADAPTER *a, PLCI *plci,
  10670. dword plci_b_id, byte connect, dword li_flags)
  10671. {
  10672. word i, ch_a, ch_a_v, ch_a_s, ch_b, ch_b_v, ch_b_s;
  10673. PLCI *plci_b;
  10674. DIVA_CAPI_ADAPTER *a_b;
  10675. a_b = &(adapter[MapController ((byte)(plci_b_id & 0x7f)) - 1]);
  10676. plci_b = &(a_b->plci[((plci_b_id >> 8) & 0xff) - 1]);
  10677. ch_a = a->li_base + (plci->li_bchannel_id - 1);
  10678. if (!a->li_pri && (plci->tel == ADV_VOICE)
  10679. && (plci == a->AdvSignalPLCI) && (Id & EXT_CONTROLLER))
  10680. {
  10681. ch_a_v = ch_a + MIXER_IC_CHANNEL_BASE;
  10682. ch_a_s = (a->manufacturer_features & MANUFACTURER_FEATURE_SLAVE_CODEC) ?
  10683. a->li_base + MIXER_IC_CHANNEL_BASE + (2 - plci->li_bchannel_id) : ch_a_v;
  10684. }
  10685. else
  10686. {
  10687. ch_a_v = ch_a;
  10688. ch_a_s = ch_a;
  10689. }
  10690. ch_b = a_b->li_base + (plci_b->li_bchannel_id - 1);
  10691. if (!a_b->li_pri && (plci_b->tel == ADV_VOICE)
  10692. && (plci_b == a_b->AdvSignalPLCI) && (plci_b_id & EXT_CONTROLLER))
  10693. {
  10694. ch_b_v = ch_b + MIXER_IC_CHANNEL_BASE;
  10695. ch_b_s = (a_b->manufacturer_features & MANUFACTURER_FEATURE_SLAVE_CODEC) ?
  10696. a_b->li_base + MIXER_IC_CHANNEL_BASE + (2 - plci_b->li_bchannel_id) : ch_b_v;
  10697. }
  10698. else
  10699. {
  10700. ch_b_v = ch_b;
  10701. ch_b_s = ch_b;
  10702. }
  10703. if (connect)
  10704. {
  10705. li_config_table[ch_a].flag_table[ch_a_v] &= ~LI_FLAG_MONITOR;
  10706. li_config_table[ch_a].flag_table[ch_a_s] &= ~LI_FLAG_MONITOR;
  10707. li_config_table[ch_a_v].flag_table[ch_a] &= ~(LI_FLAG_ANNOUNCEMENT | LI_FLAG_MIX);
  10708. li_config_table[ch_a_s].flag_table[ch_a] &= ~(LI_FLAG_ANNOUNCEMENT | LI_FLAG_MIX);
  10709. }
  10710. li_config_table[ch_a].flag_table[ch_b_v] &= ~LI_FLAG_MONITOR;
  10711. li_config_table[ch_a].flag_table[ch_b_s] &= ~LI_FLAG_MONITOR;
  10712. li_config_table[ch_b_v].flag_table[ch_a] &= ~(LI_FLAG_ANNOUNCEMENT | LI_FLAG_MIX);
  10713. li_config_table[ch_b_s].flag_table[ch_a] &= ~(LI_FLAG_ANNOUNCEMENT | LI_FLAG_MIX);
  10714. if (ch_a_v == ch_b_v)
  10715. {
  10716. li_config_table[ch_a_v].flag_table[ch_b_v] &= ~LI_FLAG_CONFERENCE;
  10717. li_config_table[ch_a_s].flag_table[ch_b_s] &= ~LI_FLAG_CONFERENCE;
  10718. }
  10719. else
  10720. {
  10721. if (li_config_table[ch_a_v].flag_table[ch_b_v] & LI_FLAG_CONFERENCE)
  10722. {
  10723. for (i = 0; i < li_total_channels; i++)
  10724. {
  10725. if (i != ch_a_v)
  10726. li_config_table[ch_a_v].flag_table[i] &= ~LI_FLAG_CONFERENCE;
  10727. }
  10728. }
  10729. if (li_config_table[ch_a_s].flag_table[ch_b_v] & LI_FLAG_CONFERENCE)
  10730. {
  10731. for (i = 0; i < li_total_channels; i++)
  10732. {
  10733. if (i != ch_a_s)
  10734. li_config_table[ch_a_s].flag_table[i] &= ~LI_FLAG_CONFERENCE;
  10735. }
  10736. }
  10737. if (li_config_table[ch_b_v].flag_table[ch_a_v] & LI_FLAG_CONFERENCE)
  10738. {
  10739. for (i = 0; i < li_total_channels; i++)
  10740. {
  10741. if (i != ch_a_v)
  10742. li_config_table[i].flag_table[ch_a_v] &= ~LI_FLAG_CONFERENCE;
  10743. }
  10744. }
  10745. if (li_config_table[ch_b_v].flag_table[ch_a_s] & LI_FLAG_CONFERENCE)
  10746. {
  10747. for (i = 0; i < li_total_channels; i++)
  10748. {
  10749. if (i != ch_a_s)
  10750. li_config_table[i].flag_table[ch_a_s] &= ~LI_FLAG_CONFERENCE;
  10751. }
  10752. }
  10753. }
  10754. if (li_flags & LI_FLAG_CONFERENCE_A_B)
  10755. {
  10756. li_config_table[ch_b_v].flag_table[ch_a_v] |= LI_FLAG_CONFERENCE;
  10757. li_config_table[ch_b_s].flag_table[ch_a_v] |= LI_FLAG_CONFERENCE;
  10758. li_config_table[ch_b_v].flag_table[ch_a_s] |= LI_FLAG_CONFERENCE;
  10759. li_config_table[ch_b_s].flag_table[ch_a_s] |= LI_FLAG_CONFERENCE;
  10760. }
  10761. if (li_flags & LI_FLAG_CONFERENCE_B_A)
  10762. {
  10763. li_config_table[ch_a_v].flag_table[ch_b_v] |= LI_FLAG_CONFERENCE;
  10764. li_config_table[ch_a_v].flag_table[ch_b_s] |= LI_FLAG_CONFERENCE;
  10765. li_config_table[ch_a_s].flag_table[ch_b_v] |= LI_FLAG_CONFERENCE;
  10766. li_config_table[ch_a_s].flag_table[ch_b_s] |= LI_FLAG_CONFERENCE;
  10767. }
  10768. if (li_flags & LI_FLAG_MONITOR_A)
  10769. {
  10770. li_config_table[ch_a].flag_table[ch_a_v] |= LI_FLAG_MONITOR;
  10771. li_config_table[ch_a].flag_table[ch_a_s] |= LI_FLAG_MONITOR;
  10772. }
  10773. if (li_flags & LI_FLAG_MONITOR_B)
  10774. {
  10775. li_config_table[ch_a].flag_table[ch_b_v] |= LI_FLAG_MONITOR;
  10776. li_config_table[ch_a].flag_table[ch_b_s] |= LI_FLAG_MONITOR;
  10777. }
  10778. if (li_flags & LI_FLAG_ANNOUNCEMENT_A)
  10779. {
  10780. li_config_table[ch_a_v].flag_table[ch_a] |= LI_FLAG_ANNOUNCEMENT;
  10781. li_config_table[ch_a_s].flag_table[ch_a] |= LI_FLAG_ANNOUNCEMENT;
  10782. }
  10783. if (li_flags & LI_FLAG_ANNOUNCEMENT_B)
  10784. {
  10785. li_config_table[ch_b_v].flag_table[ch_a] |= LI_FLAG_ANNOUNCEMENT;
  10786. li_config_table[ch_b_s].flag_table[ch_a] |= LI_FLAG_ANNOUNCEMENT;
  10787. }
  10788. if (li_flags & LI_FLAG_MIX_A)
  10789. {
  10790. li_config_table[ch_a_v].flag_table[ch_a] |= LI_FLAG_MIX;
  10791. li_config_table[ch_a_s].flag_table[ch_a] |= LI_FLAG_MIX;
  10792. }
  10793. if (li_flags & LI_FLAG_MIX_B)
  10794. {
  10795. li_config_table[ch_b_v].flag_table[ch_a] |= LI_FLAG_MIX;
  10796. li_config_table[ch_b_s].flag_table[ch_a] |= LI_FLAG_MIX;
  10797. }
  10798. if (ch_a_v != ch_a_s)
  10799. {
  10800. li_config_table[ch_a_v].flag_table[ch_a_s] |= LI_FLAG_CONFERENCE;
  10801. li_config_table[ch_a_s].flag_table[ch_a_v] |= LI_FLAG_CONFERENCE;
  10802. }
  10803. if (ch_b_v != ch_b_s)
  10804. {
  10805. li_config_table[ch_b_v].flag_table[ch_b_s] |= LI_FLAG_CONFERENCE;
  10806. li_config_table[ch_b_s].flag_table[ch_b_v] |= LI_FLAG_CONFERENCE;
  10807. }
  10808. }
  10809. static void li2_update_connect (dword Id, DIVA_CAPI_ADAPTER *a, PLCI *plci,
  10810. dword plci_b_id, byte connect, dword li_flags)
  10811. {
  10812. word ch_a, ch_a_v, ch_a_s, ch_b, ch_b_v, ch_b_s;
  10813. PLCI *plci_b;
  10814. DIVA_CAPI_ADAPTER *a_b;
  10815. a_b = &(adapter[MapController ((byte)(plci_b_id & 0x7f)) - 1]);
  10816. plci_b = &(a_b->plci[((plci_b_id >> 8) & 0xff) - 1]);
  10817. ch_a = a->li_base + (plci->li_bchannel_id - 1);
  10818. if (!a->li_pri && (plci->tel == ADV_VOICE)
  10819. && (plci == a->AdvSignalPLCI) && (Id & EXT_CONTROLLER))
  10820. {
  10821. ch_a_v = ch_a + MIXER_IC_CHANNEL_BASE;
  10822. ch_a_s = (a->manufacturer_features & MANUFACTURER_FEATURE_SLAVE_CODEC) ?
  10823. a->li_base + MIXER_IC_CHANNEL_BASE + (2 - plci->li_bchannel_id) : ch_a_v;
  10824. }
  10825. else
  10826. {
  10827. ch_a_v = ch_a;
  10828. ch_a_s = ch_a;
  10829. }
  10830. ch_b = a_b->li_base + (plci_b->li_bchannel_id - 1);
  10831. if (!a_b->li_pri && (plci_b->tel == ADV_VOICE)
  10832. && (plci_b == a_b->AdvSignalPLCI) && (plci_b_id & EXT_CONTROLLER))
  10833. {
  10834. ch_b_v = ch_b + MIXER_IC_CHANNEL_BASE;
  10835. ch_b_s = (a_b->manufacturer_features & MANUFACTURER_FEATURE_SLAVE_CODEC) ?
  10836. a_b->li_base + MIXER_IC_CHANNEL_BASE + (2 - plci_b->li_bchannel_id) : ch_b_v;
  10837. }
  10838. else
  10839. {
  10840. ch_b_v = ch_b;
  10841. ch_b_s = ch_b;
  10842. }
  10843. if (connect)
  10844. {
  10845. li_config_table[ch_b].flag_table[ch_b_v] &= ~LI_FLAG_MONITOR;
  10846. li_config_table[ch_b].flag_table[ch_b_s] &= ~LI_FLAG_MONITOR;
  10847. li_config_table[ch_b_v].flag_table[ch_b] &= ~LI_FLAG_MIX;
  10848. li_config_table[ch_b_s].flag_table[ch_b] &= ~LI_FLAG_MIX;
  10849. li_config_table[ch_b].flag_table[ch_b] &= ~LI_FLAG_PCCONNECT;
  10850. li_config_table[ch_b].chflags &= ~(LI_CHFLAG_MONITOR | LI_CHFLAG_MIX | LI_CHFLAG_LOOP);
  10851. }
  10852. li_config_table[ch_b_v].flag_table[ch_a_v] &= ~(LI_FLAG_INTERCONNECT | LI_FLAG_CONFERENCE);
  10853. li_config_table[ch_b_s].flag_table[ch_a_v] &= ~(LI_FLAG_INTERCONNECT | LI_FLAG_CONFERENCE);
  10854. li_config_table[ch_b_v].flag_table[ch_a_s] &= ~(LI_FLAG_INTERCONNECT | LI_FLAG_CONFERENCE);
  10855. li_config_table[ch_b_s].flag_table[ch_a_s] &= ~(LI_FLAG_INTERCONNECT | LI_FLAG_CONFERENCE);
  10856. li_config_table[ch_a_v].flag_table[ch_b_v] &= ~(LI_FLAG_INTERCONNECT | LI_FLAG_CONFERENCE);
  10857. li_config_table[ch_a_v].flag_table[ch_b_s] &= ~(LI_FLAG_INTERCONNECT | LI_FLAG_CONFERENCE);
  10858. li_config_table[ch_a_s].flag_table[ch_b_v] &= ~(LI_FLAG_INTERCONNECT | LI_FLAG_CONFERENCE);
  10859. li_config_table[ch_a_s].flag_table[ch_b_s] &= ~(LI_FLAG_INTERCONNECT | LI_FLAG_CONFERENCE);
  10860. if (li_flags & LI2_FLAG_INTERCONNECT_A_B)
  10861. {
  10862. li_config_table[ch_b_v].flag_table[ch_a_v] |= LI_FLAG_INTERCONNECT;
  10863. li_config_table[ch_b_s].flag_table[ch_a_v] |= LI_FLAG_INTERCONNECT;
  10864. li_config_table[ch_b_v].flag_table[ch_a_s] |= LI_FLAG_INTERCONNECT;
  10865. li_config_table[ch_b_s].flag_table[ch_a_s] |= LI_FLAG_INTERCONNECT;
  10866. }
  10867. if (li_flags & LI2_FLAG_INTERCONNECT_B_A)
  10868. {
  10869. li_config_table[ch_a_v].flag_table[ch_b_v] |= LI_FLAG_INTERCONNECT;
  10870. li_config_table[ch_a_v].flag_table[ch_b_s] |= LI_FLAG_INTERCONNECT;
  10871. li_config_table[ch_a_s].flag_table[ch_b_v] |= LI_FLAG_INTERCONNECT;
  10872. li_config_table[ch_a_s].flag_table[ch_b_s] |= LI_FLAG_INTERCONNECT;
  10873. }
  10874. if (li_flags & LI2_FLAG_MONITOR_B)
  10875. {
  10876. li_config_table[ch_b].flag_table[ch_b_v] |= LI_FLAG_MONITOR;
  10877. li_config_table[ch_b].flag_table[ch_b_s] |= LI_FLAG_MONITOR;
  10878. }
  10879. if (li_flags & LI2_FLAG_MIX_B)
  10880. {
  10881. li_config_table[ch_b_v].flag_table[ch_b] |= LI_FLAG_MIX;
  10882. li_config_table[ch_b_s].flag_table[ch_b] |= LI_FLAG_MIX;
  10883. }
  10884. if (li_flags & LI2_FLAG_MONITOR_X)
  10885. li_config_table[ch_b].chflags |= LI_CHFLAG_MONITOR;
  10886. if (li_flags & LI2_FLAG_MIX_X)
  10887. li_config_table[ch_b].chflags |= LI_CHFLAG_MIX;
  10888. if (li_flags & LI2_FLAG_LOOP_B)
  10889. {
  10890. li_config_table[ch_b_v].flag_table[ch_b_v] |= LI_FLAG_INTERCONNECT;
  10891. li_config_table[ch_b_s].flag_table[ch_b_v] |= LI_FLAG_INTERCONNECT;
  10892. li_config_table[ch_b_v].flag_table[ch_b_s] |= LI_FLAG_INTERCONNECT;
  10893. li_config_table[ch_b_s].flag_table[ch_b_s] |= LI_FLAG_INTERCONNECT;
  10894. }
  10895. if (li_flags & LI2_FLAG_LOOP_PC)
  10896. li_config_table[ch_b].flag_table[ch_b] |= LI_FLAG_PCCONNECT;
  10897. if (li_flags & LI2_FLAG_LOOP_X)
  10898. li_config_table[ch_b].chflags |= LI_CHFLAG_LOOP;
  10899. if (li_flags & LI2_FLAG_PCCONNECT_A_B)
  10900. li_config_table[ch_b_s].flag_table[ch_a_s] |= LI_FLAG_PCCONNECT;
  10901. if (li_flags & LI2_FLAG_PCCONNECT_B_A)
  10902. li_config_table[ch_a_s].flag_table[ch_b_s] |= LI_FLAG_PCCONNECT;
  10903. if (ch_a_v != ch_a_s)
  10904. {
  10905. li_config_table[ch_a_v].flag_table[ch_a_s] |= LI_FLAG_CONFERENCE;
  10906. li_config_table[ch_a_s].flag_table[ch_a_v] |= LI_FLAG_CONFERENCE;
  10907. }
  10908. if (ch_b_v != ch_b_s)
  10909. {
  10910. li_config_table[ch_b_v].flag_table[ch_b_s] |= LI_FLAG_CONFERENCE;
  10911. li_config_table[ch_b_s].flag_table[ch_b_v] |= LI_FLAG_CONFERENCE;
  10912. }
  10913. }
  10914. static word li_check_main_plci (dword Id, PLCI *plci)
  10915. {
  10916. if (plci == NULL)
  10917. {
  10918. dbug (1, dprintf ("[%06lx] %s,%d: Wrong PLCI",
  10919. UnMapId (Id), (char *)(FILE_), __LINE__));
  10920. return (_WRONG_IDENTIFIER);
  10921. }
  10922. if (!plci->State
  10923. || !plci->NL.Id || plci->nl_remove_id
  10924. || (plci->li_bchannel_id == 0))
  10925. {
  10926. dbug (1, dprintf ("[%06lx] %s,%d: Wrong state",
  10927. UnMapId (Id), (char *)(FILE_), __LINE__));
  10928. return (_WRONG_STATE);
  10929. }
  10930. li_config_table[plci->adapter->li_base + (plci->li_bchannel_id - 1)].plci = plci;
  10931. return (GOOD);
  10932. }
  10933. static PLCI *li_check_plci_b (dword Id, PLCI *plci,
  10934. dword plci_b_id, word plci_b_write_pos, byte *p_result)
  10935. {
  10936. byte ctlr_b;
  10937. PLCI *plci_b;
  10938. if (((plci->li_plci_b_read_pos > plci_b_write_pos) ? plci->li_plci_b_read_pos :
  10939. LI_PLCI_B_QUEUE_ENTRIES + plci->li_plci_b_read_pos) - plci_b_write_pos - 1 < 2)
  10940. {
  10941. dbug (1, dprintf ("[%06lx] %s,%d: LI request overrun",
  10942. UnMapId (Id), (char *)(FILE_), __LINE__));
  10943. PUT_WORD (p_result, _REQUEST_NOT_ALLOWED_IN_THIS_STATE);
  10944. return (NULL);
  10945. }
  10946. ctlr_b = 0;
  10947. if ((plci_b_id & 0x7f) != 0)
  10948. {
  10949. ctlr_b = MapController ((byte)(plci_b_id & 0x7f));
  10950. if ((ctlr_b > max_adapter) || ((ctlr_b != 0) && (adapter[ctlr_b - 1].request == NULL)))
  10951. ctlr_b = 0;
  10952. }
  10953. if ((ctlr_b == 0)
  10954. || (((plci_b_id >> 8) & 0xff) == 0)
  10955. || (((plci_b_id >> 8) & 0xff) > adapter[ctlr_b - 1].max_plci))
  10956. {
  10957. dbug (1, dprintf ("[%06lx] %s,%d: LI invalid second PLCI %08lx",
  10958. UnMapId (Id), (char *)(FILE_), __LINE__, plci_b_id));
  10959. PUT_WORD (p_result, _WRONG_IDENTIFIER);
  10960. return (NULL);
  10961. }
  10962. plci_b = &(adapter[ctlr_b - 1].plci[((plci_b_id >> 8) & 0xff) - 1]);
  10963. if (!plci_b->State
  10964. || !plci_b->NL.Id || plci_b->nl_remove_id
  10965. || (plci_b->li_bchannel_id == 0))
  10966. {
  10967. dbug (1, dprintf ("[%06lx] %s,%d: LI peer in wrong state %08lx",
  10968. UnMapId (Id), (char *)(FILE_), __LINE__, plci_b_id));
  10969. PUT_WORD (p_result, _REQUEST_NOT_ALLOWED_IN_THIS_STATE);
  10970. return (NULL);
  10971. }
  10972. li_config_table[plci_b->adapter->li_base + (plci_b->li_bchannel_id - 1)].plci = plci_b;
  10973. if (((byte)(plci_b_id & ~EXT_CONTROLLER)) !=
  10974. ((byte)(UnMapController (plci->adapter->Id) & ~EXT_CONTROLLER))
  10975. && (!(plci->adapter->manufacturer_features & MANUFACTURER_FEATURE_XCONNECT)
  10976. || !(plci_b->adapter->manufacturer_features & MANUFACTURER_FEATURE_XCONNECT)))
  10977. {
  10978. dbug (1, dprintf ("[%06lx] %s,%d: LI not on same ctrl %08lx",
  10979. UnMapId (Id), (char *)(FILE_), __LINE__, plci_b_id));
  10980. PUT_WORD (p_result, _WRONG_IDENTIFIER);
  10981. return (NULL);
  10982. }
  10983. if (!(get_b1_facilities (plci_b, add_b1_facilities (plci_b, plci_b->B1_resource,
  10984. (word)(plci_b->B1_facilities | B1_FACILITY_MIXER))) & B1_FACILITY_MIXER))
  10985. {
  10986. dbug (1, dprintf ("[%06lx] %s,%d: Interconnect peer cannot mix %d",
  10987. UnMapId (Id), (char *)(FILE_), __LINE__, plci_b->B1_resource));
  10988. PUT_WORD (p_result, _REQUEST_NOT_ALLOWED_IN_THIS_STATE);
  10989. return (NULL);
  10990. }
  10991. return (plci_b);
  10992. }
  10993. static PLCI *li2_check_plci_b (dword Id, PLCI *plci,
  10994. dword plci_b_id, word plci_b_write_pos, byte *p_result)
  10995. {
  10996. byte ctlr_b;
  10997. PLCI *plci_b;
  10998. if (((plci->li_plci_b_read_pos > plci_b_write_pos) ? plci->li_plci_b_read_pos :
  10999. LI_PLCI_B_QUEUE_ENTRIES + plci->li_plci_b_read_pos) - plci_b_write_pos - 1 < 2)
  11000. {
  11001. dbug (1, dprintf ("[%06lx] %s,%d: LI request overrun",
  11002. UnMapId (Id), (char *)(FILE_), __LINE__));
  11003. PUT_WORD (p_result, _WRONG_STATE);
  11004. return (NULL);
  11005. }
  11006. ctlr_b = 0;
  11007. if ((plci_b_id & 0x7f) != 0)
  11008. {
  11009. ctlr_b = MapController ((byte)(plci_b_id & 0x7f));
  11010. if ((ctlr_b > max_adapter) || ((ctlr_b != 0) && (adapter[ctlr_b - 1].request == NULL)))
  11011. ctlr_b = 0;
  11012. }
  11013. if ((ctlr_b == 0)
  11014. || (((plci_b_id >> 8) & 0xff) == 0)
  11015. || (((plci_b_id >> 8) & 0xff) > adapter[ctlr_b - 1].max_plci))
  11016. {
  11017. dbug (1, dprintf ("[%06lx] %s,%d: LI invalid second PLCI %08lx",
  11018. UnMapId (Id), (char *)(FILE_), __LINE__, plci_b_id));
  11019. PUT_WORD (p_result, _WRONG_IDENTIFIER);
  11020. return (NULL);
  11021. }
  11022. plci_b = &(adapter[ctlr_b - 1].plci[((plci_b_id >> 8) & 0xff) - 1]);
  11023. if (!plci_b->State
  11024. || !plci_b->NL.Id || plci_b->nl_remove_id
  11025. || (plci_b->li_bchannel_id == 0)
  11026. || (li_config_table[plci_b->adapter->li_base + (plci_b->li_bchannel_id - 1)].plci != plci_b))
  11027. {
  11028. dbug (1, dprintf ("[%06lx] %s,%d: LI peer in wrong state %08lx",
  11029. UnMapId (Id), (char *)(FILE_), __LINE__, plci_b_id));
  11030. PUT_WORD (p_result, _WRONG_STATE);
  11031. return (NULL);
  11032. }
  11033. if (((byte)(plci_b_id & ~EXT_CONTROLLER)) !=
  11034. ((byte)(UnMapController (plci->adapter->Id) & ~EXT_CONTROLLER))
  11035. && (!(plci->adapter->manufacturer_features & MANUFACTURER_FEATURE_XCONNECT)
  11036. || !(plci_b->adapter->manufacturer_features & MANUFACTURER_FEATURE_XCONNECT)))
  11037. {
  11038. dbug (1, dprintf ("[%06lx] %s,%d: LI not on same ctrl %08lx",
  11039. UnMapId (Id), (char *)(FILE_), __LINE__, plci_b_id));
  11040. PUT_WORD (p_result, _WRONG_IDENTIFIER);
  11041. return (NULL);
  11042. }
  11043. if (!(get_b1_facilities (plci_b, add_b1_facilities (plci_b, plci_b->B1_resource,
  11044. (word)(plci_b->B1_facilities | B1_FACILITY_MIXER))) & B1_FACILITY_MIXER))
  11045. {
  11046. dbug (1, dprintf ("[%06lx] %s,%d: Interconnect peer cannot mix %d",
  11047. UnMapId (Id), (char *)(FILE_), __LINE__, plci_b->B1_resource));
  11048. PUT_WORD (p_result, _WRONG_STATE);
  11049. return (NULL);
  11050. }
  11051. return (plci_b);
  11052. }
  11053. static byte mixer_request (dword Id, word Number, DIVA_CAPI_ADAPTER *a, PLCI *plci, APPL *appl, API_PARSE *msg)
  11054. {
  11055. word Info;
  11056. word i;
  11057. dword d, li_flags, plci_b_id;
  11058. PLCI *plci_b;
  11059. API_PARSE li_parms[3];
  11060. API_PARSE li_req_parms[3];
  11061. API_PARSE li_participant_struct[2];
  11062. API_PARSE li_participant_parms[3];
  11063. word participant_parms_pos;
  11064. byte result_buffer[32];
  11065. byte *result;
  11066. word result_pos;
  11067. word plci_b_write_pos;
  11068. dbug (1, dprintf ("[%06lx] %s,%d: mixer_request",
  11069. UnMapId (Id), (char *)(FILE_), __LINE__));
  11070. Info = GOOD;
  11071. result = result_buffer;
  11072. result_buffer[0] = 0;
  11073. if (!(a->profile.Global_Options & GL_LINE_INTERCONNECT_SUPPORTED))
  11074. {
  11075. dbug (1, dprintf ("[%06lx] %s,%d: Facility not supported",
  11076. UnMapId (Id), (char *)(FILE_), __LINE__));
  11077. Info = _FACILITY_NOT_SUPPORTED;
  11078. }
  11079. else if (api_parse (&msg[1].info[1], msg[1].length, "ws", li_parms))
  11080. {
  11081. dbug (1, dprintf ("[%06lx] %s,%d: Wrong message format",
  11082. UnMapId (Id), (char *)(FILE_), __LINE__));
  11083. Info = _WRONG_MESSAGE_FORMAT;
  11084. }
  11085. else
  11086. {
  11087. result_buffer[0] = 3;
  11088. PUT_WORD (&result_buffer[1], GET_WORD (li_parms[0].info));
  11089. result_buffer[3] = 0;
  11090. switch (GET_WORD (li_parms[0].info))
  11091. {
  11092. case LI_GET_SUPPORTED_SERVICES:
  11093. if (appl->appl_flags & APPL_FLAG_OLD_LI_SPEC)
  11094. {
  11095. result_buffer[0] = 17;
  11096. result_buffer[3] = 14;
  11097. PUT_WORD (&result_buffer[4], GOOD);
  11098. d = 0;
  11099. if (a->manufacturer_features & MANUFACTURER_FEATURE_MIXER_CH_CH)
  11100. d |= LI_CONFERENCING_SUPPORTED;
  11101. if (a->manufacturer_features & MANUFACTURER_FEATURE_MIXER_CH_PC)
  11102. d |= LI_MONITORING_SUPPORTED;
  11103. if (a->manufacturer_features & MANUFACTURER_FEATURE_MIXER_PC_CH)
  11104. d |= LI_ANNOUNCEMENTS_SUPPORTED | LI_MIXING_SUPPORTED;
  11105. if (a->manufacturer_features & MANUFACTURER_FEATURE_XCONNECT)
  11106. d |= LI_CROSS_CONTROLLER_SUPPORTED;
  11107. PUT_DWORD (&result_buffer[6], d);
  11108. if (a->manufacturer_features & MANUFACTURER_FEATURE_XCONNECT)
  11109. {
  11110. d = 0;
  11111. for (i = 0; i < li_total_channels; i++)
  11112. {
  11113. if ((li_config_table[i].adapter->manufacturer_features & MANUFACTURER_FEATURE_XCONNECT)
  11114. && (li_config_table[i].adapter->li_pri
  11115. || (i < li_config_table[i].adapter->li_base + MIXER_BCHANNELS_BRI)))
  11116. {
  11117. d++;
  11118. }
  11119. }
  11120. }
  11121. else
  11122. {
  11123. d = a->li_pri ? a->li_channels : MIXER_BCHANNELS_BRI;
  11124. }
  11125. PUT_DWORD (&result_buffer[10], d / 2);
  11126. PUT_DWORD (&result_buffer[14], d);
  11127. }
  11128. else
  11129. {
  11130. result_buffer[0] = 25;
  11131. result_buffer[3] = 22;
  11132. PUT_WORD (&result_buffer[4], GOOD);
  11133. d = LI2_ASYMMETRIC_SUPPORTED | LI2_B_LOOPING_SUPPORTED | LI2_X_LOOPING_SUPPORTED;
  11134. if (a->manufacturer_features & MANUFACTURER_FEATURE_MIXER_CH_PC)
  11135. d |= LI2_MONITORING_SUPPORTED | LI2_REMOTE_MONITORING_SUPPORTED;
  11136. if (a->manufacturer_features & MANUFACTURER_FEATURE_MIXER_PC_CH)
  11137. d |= LI2_MIXING_SUPPORTED | LI2_REMOTE_MIXING_SUPPORTED;
  11138. if (a->manufacturer_features & MANUFACTURER_FEATURE_MIXER_PC_PC)
  11139. d |= LI2_PC_LOOPING_SUPPORTED;
  11140. if (a->manufacturer_features & MANUFACTURER_FEATURE_XCONNECT)
  11141. d |= LI2_CROSS_CONTROLLER_SUPPORTED;
  11142. PUT_DWORD (&result_buffer[6], d);
  11143. d = a->li_pri ? a->li_channels : MIXER_BCHANNELS_BRI;
  11144. PUT_DWORD (&result_buffer[10], d / 2);
  11145. PUT_DWORD (&result_buffer[14], d - 1);
  11146. if (a->manufacturer_features & MANUFACTURER_FEATURE_XCONNECT)
  11147. {
  11148. d = 0;
  11149. for (i = 0; i < li_total_channels; i++)
  11150. {
  11151. if ((li_config_table[i].adapter->manufacturer_features & MANUFACTURER_FEATURE_XCONNECT)
  11152. && (li_config_table[i].adapter->li_pri
  11153. || (i < li_config_table[i].adapter->li_base + MIXER_BCHANNELS_BRI)))
  11154. {
  11155. d++;
  11156. }
  11157. }
  11158. }
  11159. PUT_DWORD (&result_buffer[18], d / 2);
  11160. PUT_DWORD (&result_buffer[22], d - 1);
  11161. }
  11162. break;
  11163. case LI_REQ_CONNECT:
  11164. if (li_parms[1].length == 8)
  11165. {
  11166. appl->appl_flags |= APPL_FLAG_OLD_LI_SPEC;
  11167. if (api_parse (&li_parms[1].info[1], li_parms[1].length, "dd", li_req_parms))
  11168. {
  11169. dbug (1, dprintf ("[%06lx] %s,%d: Wrong message format",
  11170. UnMapId (Id), (char *)(FILE_), __LINE__));
  11171. Info = _WRONG_MESSAGE_FORMAT;
  11172. break;
  11173. }
  11174. plci_b_id = GET_DWORD (li_req_parms[0].info) & 0xffff;
  11175. li_flags = GET_DWORD (li_req_parms[1].info);
  11176. Info = li_check_main_plci (Id, plci);
  11177. result_buffer[0] = 9;
  11178. result_buffer[3] = 6;
  11179. PUT_DWORD (&result_buffer[4], plci_b_id);
  11180. PUT_WORD (&result_buffer[8], GOOD);
  11181. if (Info != GOOD)
  11182. break;
  11183. result = plci->saved_msg.info;
  11184. for (i = 0; i <= result_buffer[0]; i++)
  11185. result[i] = result_buffer[i];
  11186. plci_b_write_pos = plci->li_plci_b_write_pos;
  11187. plci_b = li_check_plci_b (Id, plci, plci_b_id, plci_b_write_pos, &result[8]);
  11188. if (plci_b == NULL)
  11189. break;
  11190. li_update_connect (Id, a, plci, plci_b_id, true, li_flags);
  11191. plci->li_plci_b_queue[plci_b_write_pos] = plci_b_id | LI_PLCI_B_LAST_FLAG;
  11192. plci_b_write_pos = (plci_b_write_pos == LI_PLCI_B_QUEUE_ENTRIES-1) ? 0 : plci_b_write_pos + 1;
  11193. plci->li_plci_b_write_pos = plci_b_write_pos;
  11194. }
  11195. else
  11196. {
  11197. appl->appl_flags &= ~APPL_FLAG_OLD_LI_SPEC;
  11198. if (api_parse (&li_parms[1].info[1], li_parms[1].length, "ds", li_req_parms))
  11199. {
  11200. dbug (1, dprintf ("[%06lx] %s,%d: Wrong message format",
  11201. UnMapId (Id), (char *)(FILE_), __LINE__));
  11202. Info = _WRONG_MESSAGE_FORMAT;
  11203. break;
  11204. }
  11205. li_flags = GET_DWORD (li_req_parms[0].info) & ~(LI2_FLAG_INTERCONNECT_A_B | LI2_FLAG_INTERCONNECT_B_A);
  11206. Info = li_check_main_plci (Id, plci);
  11207. result_buffer[0] = 7;
  11208. result_buffer[3] = 4;
  11209. PUT_WORD (&result_buffer[4], Info);
  11210. result_buffer[6] = 0;
  11211. if (Info != GOOD)
  11212. break;
  11213. result = plci->saved_msg.info;
  11214. for (i = 0; i <= result_buffer[0]; i++)
  11215. result[i] = result_buffer[i];
  11216. plci_b_write_pos = plci->li_plci_b_write_pos;
  11217. participant_parms_pos = 0;
  11218. result_pos = 7;
  11219. li2_update_connect (Id, a, plci, UnMapId (Id), true, li_flags);
  11220. while (participant_parms_pos < li_req_parms[1].length)
  11221. {
  11222. result[result_pos] = 6;
  11223. result_pos += 7;
  11224. PUT_DWORD (&result[result_pos - 6], 0);
  11225. PUT_WORD (&result[result_pos - 2], GOOD);
  11226. if (api_parse (&li_req_parms[1].info[1 + participant_parms_pos],
  11227. (word)(li_parms[1].length - participant_parms_pos), "s", li_participant_struct))
  11228. {
  11229. dbug (1, dprintf ("[%06lx] %s,%d: Wrong message format",
  11230. UnMapId (Id), (char *)(FILE_), __LINE__));
  11231. PUT_WORD (&result[result_pos - 2], _WRONG_MESSAGE_FORMAT);
  11232. break;
  11233. }
  11234. if (api_parse (&li_participant_struct[0].info[1],
  11235. li_participant_struct[0].length, "dd", li_participant_parms))
  11236. {
  11237. dbug (1, dprintf ("[%06lx] %s,%d: Wrong message format",
  11238. UnMapId (Id), (char *)(FILE_), __LINE__));
  11239. PUT_WORD (&result[result_pos - 2], _WRONG_MESSAGE_FORMAT);
  11240. break;
  11241. }
  11242. plci_b_id = GET_DWORD (li_participant_parms[0].info) & 0xffff;
  11243. li_flags = GET_DWORD (li_participant_parms[1].info);
  11244. PUT_DWORD (&result[result_pos - 6], plci_b_id);
  11245. if (sizeof(result) - result_pos < 7)
  11246. {
  11247. dbug (1, dprintf ("[%06lx] %s,%d: LI result overrun",
  11248. UnMapId (Id), (char *)(FILE_), __LINE__));
  11249. PUT_WORD (&result[result_pos - 2], _WRONG_STATE);
  11250. break;
  11251. }
  11252. plci_b = li2_check_plci_b (Id, plci, plci_b_id, plci_b_write_pos, &result[result_pos - 2]);
  11253. if (plci_b != NULL)
  11254. {
  11255. li2_update_connect (Id, a, plci, plci_b_id, true, li_flags);
  11256. plci->li_plci_b_queue[plci_b_write_pos] = plci_b_id |
  11257. ((li_flags & (LI2_FLAG_INTERCONNECT_A_B | LI2_FLAG_INTERCONNECT_B_A |
  11258. LI2_FLAG_PCCONNECT_A_B | LI2_FLAG_PCCONNECT_B_A)) ? 0 : LI_PLCI_B_DISC_FLAG);
  11259. plci_b_write_pos = (plci_b_write_pos == LI_PLCI_B_QUEUE_ENTRIES-1) ? 0 : plci_b_write_pos + 1;
  11260. }
  11261. participant_parms_pos = (word)((&li_participant_struct[0].info[1 + li_participant_struct[0].length]) -
  11262. (&li_req_parms[1].info[1]));
  11263. }
  11264. result[0] = (byte)(result_pos - 1);
  11265. result[3] = (byte)(result_pos - 4);
  11266. result[6] = (byte)(result_pos - 7);
  11267. i = (plci_b_write_pos == 0) ? LI_PLCI_B_QUEUE_ENTRIES-1 : plci_b_write_pos - 1;
  11268. if ((plci_b_write_pos == plci->li_plci_b_read_pos)
  11269. || (plci->li_plci_b_queue[i] & LI_PLCI_B_LAST_FLAG))
  11270. {
  11271. plci->li_plci_b_queue[plci_b_write_pos] = LI_PLCI_B_SKIP_FLAG | LI_PLCI_B_LAST_FLAG;
  11272. plci_b_write_pos = (plci_b_write_pos == LI_PLCI_B_QUEUE_ENTRIES-1) ? 0 : plci_b_write_pos + 1;
  11273. }
  11274. else
  11275. plci->li_plci_b_queue[i] |= LI_PLCI_B_LAST_FLAG;
  11276. plci->li_plci_b_write_pos = plci_b_write_pos;
  11277. }
  11278. mixer_calculate_coefs (a);
  11279. plci->li_channel_bits = li_config_table[a->li_base + (plci->li_bchannel_id - 1)].channel;
  11280. mixer_notify_update (plci, true);
  11281. sendf (appl, _FACILITY_R | CONFIRM, Id & 0xffffL, Number,
  11282. "wwS", Info, SELECTOR_LINE_INTERCONNECT, result);
  11283. plci->command = 0;
  11284. plci->li_cmd = GET_WORD (li_parms[0].info);
  11285. start_internal_command (Id, plci, mixer_command);
  11286. return (false);
  11287. case LI_REQ_DISCONNECT:
  11288. if (li_parms[1].length == 4)
  11289. {
  11290. appl->appl_flags |= APPL_FLAG_OLD_LI_SPEC;
  11291. if (api_parse (&li_parms[1].info[1], li_parms[1].length, "d", li_req_parms))
  11292. {
  11293. dbug (1, dprintf ("[%06lx] %s,%d: Wrong message format",
  11294. UnMapId (Id), (char *)(FILE_), __LINE__));
  11295. Info = _WRONG_MESSAGE_FORMAT;
  11296. break;
  11297. }
  11298. plci_b_id = GET_DWORD (li_req_parms[0].info) & 0xffff;
  11299. Info = li_check_main_plci (Id, plci);
  11300. result_buffer[0] = 9;
  11301. result_buffer[3] = 6;
  11302. PUT_DWORD (&result_buffer[4], GET_DWORD (li_req_parms[0].info));
  11303. PUT_WORD (&result_buffer[8], GOOD);
  11304. if (Info != GOOD)
  11305. break;
  11306. result = plci->saved_msg.info;
  11307. for (i = 0; i <= result_buffer[0]; i++)
  11308. result[i] = result_buffer[i];
  11309. plci_b_write_pos = plci->li_plci_b_write_pos;
  11310. plci_b = li_check_plci_b (Id, plci, plci_b_id, plci_b_write_pos, &result[8]);
  11311. if (plci_b == NULL)
  11312. break;
  11313. li_update_connect (Id, a, plci, plci_b_id, false, 0);
  11314. plci->li_plci_b_queue[plci_b_write_pos] = plci_b_id | LI_PLCI_B_DISC_FLAG | LI_PLCI_B_LAST_FLAG;
  11315. plci_b_write_pos = (plci_b_write_pos == LI_PLCI_B_QUEUE_ENTRIES-1) ? 0 : plci_b_write_pos + 1;
  11316. plci->li_plci_b_write_pos = plci_b_write_pos;
  11317. }
  11318. else
  11319. {
  11320. appl->appl_flags &= ~APPL_FLAG_OLD_LI_SPEC;
  11321. if (api_parse (&li_parms[1].info[1], li_parms[1].length, "s", li_req_parms))
  11322. {
  11323. dbug (1, dprintf ("[%06lx] %s,%d: Wrong message format",
  11324. UnMapId (Id), (char *)(FILE_), __LINE__));
  11325. Info = _WRONG_MESSAGE_FORMAT;
  11326. break;
  11327. }
  11328. Info = li_check_main_plci (Id, plci);
  11329. result_buffer[0] = 7;
  11330. result_buffer[3] = 4;
  11331. PUT_WORD (&result_buffer[4], Info);
  11332. result_buffer[6] = 0;
  11333. if (Info != GOOD)
  11334. break;
  11335. result = plci->saved_msg.info;
  11336. for (i = 0; i <= result_buffer[0]; i++)
  11337. result[i] = result_buffer[i];
  11338. plci_b_write_pos = plci->li_plci_b_write_pos;
  11339. participant_parms_pos = 0;
  11340. result_pos = 7;
  11341. while (participant_parms_pos < li_req_parms[0].length)
  11342. {
  11343. result[result_pos] = 6;
  11344. result_pos += 7;
  11345. PUT_DWORD (&result[result_pos - 6], 0);
  11346. PUT_WORD (&result[result_pos - 2], GOOD);
  11347. if (api_parse (&li_req_parms[0].info[1 + participant_parms_pos],
  11348. (word)(li_parms[1].length - participant_parms_pos), "s", li_participant_struct))
  11349. {
  11350. dbug (1, dprintf ("[%06lx] %s,%d: Wrong message format",
  11351. UnMapId (Id), (char *)(FILE_), __LINE__));
  11352. PUT_WORD (&result[result_pos - 2], _WRONG_MESSAGE_FORMAT);
  11353. break;
  11354. }
  11355. if (api_parse (&li_participant_struct[0].info[1],
  11356. li_participant_struct[0].length, "d", li_participant_parms))
  11357. {
  11358. dbug (1, dprintf ("[%06lx] %s,%d: Wrong message format",
  11359. UnMapId (Id), (char *)(FILE_), __LINE__));
  11360. PUT_WORD (&result[result_pos - 2], _WRONG_MESSAGE_FORMAT);
  11361. break;
  11362. }
  11363. plci_b_id = GET_DWORD (li_participant_parms[0].info) & 0xffff;
  11364. PUT_DWORD (&result[result_pos - 6], plci_b_id);
  11365. if (sizeof(result) - result_pos < 7)
  11366. {
  11367. dbug (1, dprintf ("[%06lx] %s,%d: LI result overrun",
  11368. UnMapId (Id), (char *)(FILE_), __LINE__));
  11369. PUT_WORD (&result[result_pos - 2], _WRONG_STATE);
  11370. break;
  11371. }
  11372. plci_b = li2_check_plci_b (Id, plci, plci_b_id, plci_b_write_pos, &result[result_pos - 2]);
  11373. if (plci_b != NULL)
  11374. {
  11375. li2_update_connect (Id, a, plci, plci_b_id, false, 0);
  11376. plci->li_plci_b_queue[plci_b_write_pos] = plci_b_id | LI_PLCI_B_DISC_FLAG;
  11377. plci_b_write_pos = (plci_b_write_pos == LI_PLCI_B_QUEUE_ENTRIES-1) ? 0 : plci_b_write_pos + 1;
  11378. }
  11379. participant_parms_pos = (word)((&li_participant_struct[0].info[1 + li_participant_struct[0].length]) -
  11380. (&li_req_parms[0].info[1]));
  11381. }
  11382. result[0] = (byte)(result_pos - 1);
  11383. result[3] = (byte)(result_pos - 4);
  11384. result[6] = (byte)(result_pos - 7);
  11385. i = (plci_b_write_pos == 0) ? LI_PLCI_B_QUEUE_ENTRIES-1 : plci_b_write_pos - 1;
  11386. if ((plci_b_write_pos == plci->li_plci_b_read_pos)
  11387. || (plci->li_plci_b_queue[i] & LI_PLCI_B_LAST_FLAG))
  11388. {
  11389. plci->li_plci_b_queue[plci_b_write_pos] = LI_PLCI_B_SKIP_FLAG | LI_PLCI_B_LAST_FLAG;
  11390. plci_b_write_pos = (plci_b_write_pos == LI_PLCI_B_QUEUE_ENTRIES-1) ? 0 : plci_b_write_pos + 1;
  11391. }
  11392. else
  11393. plci->li_plci_b_queue[i] |= LI_PLCI_B_LAST_FLAG;
  11394. plci->li_plci_b_write_pos = plci_b_write_pos;
  11395. }
  11396. mixer_calculate_coefs (a);
  11397. plci->li_channel_bits = li_config_table[a->li_base + (plci->li_bchannel_id - 1)].channel;
  11398. mixer_notify_update (plci, true);
  11399. sendf (appl, _FACILITY_R | CONFIRM, Id & 0xffffL, Number,
  11400. "wwS", Info, SELECTOR_LINE_INTERCONNECT, result);
  11401. plci->command = 0;
  11402. plci->li_cmd = GET_WORD (li_parms[0].info);
  11403. start_internal_command (Id, plci, mixer_command);
  11404. return (false);
  11405. case LI_REQ_SILENT_UPDATE:
  11406. if (!plci || !plci->State
  11407. || !plci->NL.Id || plci->nl_remove_id
  11408. || (plci->li_bchannel_id == 0)
  11409. || (li_config_table[plci->adapter->li_base + (plci->li_bchannel_id - 1)].plci != plci))
  11410. {
  11411. dbug (1, dprintf ("[%06lx] %s,%d: Wrong state",
  11412. UnMapId (Id), (char *)(FILE_), __LINE__));
  11413. return (false);
  11414. }
  11415. plci_b_write_pos = plci->li_plci_b_write_pos;
  11416. if (((plci->li_plci_b_read_pos > plci_b_write_pos) ? plci->li_plci_b_read_pos :
  11417. LI_PLCI_B_QUEUE_ENTRIES + plci->li_plci_b_read_pos) - plci_b_write_pos - 1 < 2)
  11418. {
  11419. dbug (1, dprintf ("[%06lx] %s,%d: LI request overrun",
  11420. UnMapId (Id), (char *)(FILE_), __LINE__));
  11421. return (false);
  11422. }
  11423. i = (plci_b_write_pos == 0) ? LI_PLCI_B_QUEUE_ENTRIES-1 : plci_b_write_pos - 1;
  11424. if ((plci_b_write_pos == plci->li_plci_b_read_pos)
  11425. || (plci->li_plci_b_queue[i] & LI_PLCI_B_LAST_FLAG))
  11426. {
  11427. plci->li_plci_b_queue[plci_b_write_pos] = LI_PLCI_B_SKIP_FLAG | LI_PLCI_B_LAST_FLAG;
  11428. plci_b_write_pos = (plci_b_write_pos == LI_PLCI_B_QUEUE_ENTRIES-1) ? 0 : plci_b_write_pos + 1;
  11429. }
  11430. else
  11431. plci->li_plci_b_queue[i] |= LI_PLCI_B_LAST_FLAG;
  11432. plci->li_plci_b_write_pos = plci_b_write_pos;
  11433. plci->li_channel_bits = li_config_table[a->li_base + (plci->li_bchannel_id - 1)].channel;
  11434. plci->command = 0;
  11435. plci->li_cmd = GET_WORD (li_parms[0].info);
  11436. start_internal_command (Id, plci, mixer_command);
  11437. return (false);
  11438. default:
  11439. dbug (1, dprintf ("[%06lx] %s,%d: LI unknown request %04x",
  11440. UnMapId (Id), (char *)(FILE_), __LINE__, GET_WORD (li_parms[0].info)));
  11441. Info = _FACILITY_NOT_SUPPORTED;
  11442. }
  11443. }
  11444. sendf (appl, _FACILITY_R | CONFIRM, Id & 0xffffL, Number,
  11445. "wwS", Info, SELECTOR_LINE_INTERCONNECT, result);
  11446. return (false);
  11447. }
  11448. static void mixer_indication_coefs_set (dword Id, PLCI *plci)
  11449. {
  11450. dword d;
  11451. DIVA_CAPI_ADAPTER *a;
  11452. byte result[12];
  11453. dbug (1, dprintf ("[%06lx] %s,%d: mixer_indication_coefs_set",
  11454. UnMapId (Id), (char *)(FILE_), __LINE__));
  11455. a = plci->adapter;
  11456. if (plci->li_plci_b_read_pos != plci->li_plci_b_req_pos)
  11457. {
  11458. do
  11459. {
  11460. d = plci->li_plci_b_queue[plci->li_plci_b_read_pos];
  11461. if (!(d & LI_PLCI_B_SKIP_FLAG))
  11462. {
  11463. if (plci->appl->appl_flags & APPL_FLAG_OLD_LI_SPEC)
  11464. {
  11465. if (d & LI_PLCI_B_DISC_FLAG)
  11466. {
  11467. result[0] = 5;
  11468. PUT_WORD (&result[1], LI_IND_DISCONNECT);
  11469. result[3] = 2;
  11470. PUT_WORD (&result[4], _LI_USER_INITIATED);
  11471. }
  11472. else
  11473. {
  11474. result[0] = 7;
  11475. PUT_WORD (&result[1], LI_IND_CONNECT_ACTIVE);
  11476. result[3] = 4;
  11477. PUT_DWORD (&result[4], d & ~LI_PLCI_B_FLAG_MASK);
  11478. }
  11479. }
  11480. else
  11481. {
  11482. if (d & LI_PLCI_B_DISC_FLAG)
  11483. {
  11484. result[0] = 9;
  11485. PUT_WORD (&result[1], LI_IND_DISCONNECT);
  11486. result[3] = 6;
  11487. PUT_DWORD (&result[4], d & ~LI_PLCI_B_FLAG_MASK);
  11488. PUT_WORD (&result[8], _LI_USER_INITIATED);
  11489. }
  11490. else
  11491. {
  11492. result[0] = 7;
  11493. PUT_WORD (&result[1], LI_IND_CONNECT_ACTIVE);
  11494. result[3] = 4;
  11495. PUT_DWORD (&result[4], d & ~LI_PLCI_B_FLAG_MASK);
  11496. }
  11497. }
  11498. sendf (plci->appl, _FACILITY_I, Id & 0xffffL, 0,
  11499. "ws", SELECTOR_LINE_INTERCONNECT, result);
  11500. }
  11501. plci->li_plci_b_read_pos = (plci->li_plci_b_read_pos == LI_PLCI_B_QUEUE_ENTRIES-1) ?
  11502. 0 : plci->li_plci_b_read_pos + 1;
  11503. } while (!(d & LI_PLCI_B_LAST_FLAG) && (plci->li_plci_b_read_pos != plci->li_plci_b_req_pos));
  11504. }
  11505. }
  11506. static void mixer_indication_xconnect_from (dword Id, PLCI *plci, byte *msg, word length)
  11507. {
  11508. word i, j, ch;
  11509. struct xconnect_transfer_address_s s, *p;
  11510. DIVA_CAPI_ADAPTER *a;
  11511. dbug (1, dprintf ("[%06lx] %s,%d: mixer_indication_xconnect_from %d",
  11512. UnMapId (Id), (char *)(FILE_), __LINE__, (int) length));
  11513. a = plci->adapter;
  11514. i = 1;
  11515. for (i = 1; i < length; i += 16)
  11516. {
  11517. s.card_address.low = msg[i] | (msg[i+1] << 8) | (((dword)(msg[i+2])) << 16) | (((dword)(msg[i+3])) << 24);
  11518. s.card_address.high = msg[i+4] | (msg[i+5] << 8) | (((dword)(msg[i+6])) << 16) | (((dword)(msg[i+7])) << 24);
  11519. s.offset = msg[i+8] | (msg[i+9] << 8) | (((dword)(msg[i+10])) << 16) | (((dword)(msg[i+11])) << 24);
  11520. ch = msg[i+12] | (msg[i+13] << 8);
  11521. j = ch & XCONNECT_CHANNEL_NUMBER_MASK;
  11522. if (!a->li_pri && (plci->li_bchannel_id == 2))
  11523. j = 1 - j;
  11524. j += a->li_base;
  11525. if (ch & XCONNECT_CHANNEL_PORT_PC)
  11526. p = &(li_config_table[j].send_pc);
  11527. else
  11528. p = &(li_config_table[j].send_b);
  11529. p->card_address.low = s.card_address.low;
  11530. p->card_address.high = s.card_address.high;
  11531. p->offset = s.offset;
  11532. li_config_table[j].channel |= LI_CHANNEL_ADDRESSES_SET;
  11533. }
  11534. if (plci->internal_command_queue[0]
  11535. && ((plci->adjust_b_state == ADJUST_B_RESTORE_MIXER_2)
  11536. || (plci->adjust_b_state == ADJUST_B_RESTORE_MIXER_3)
  11537. || (plci->adjust_b_state == ADJUST_B_RESTORE_MIXER_4)))
  11538. {
  11539. (*(plci->internal_command_queue[0]))(Id, plci, 0);
  11540. if (!plci->internal_command)
  11541. next_internal_command (Id, plci);
  11542. }
  11543. mixer_notify_update (plci, true);
  11544. }
  11545. static void mixer_indication_xconnect_to (dword Id, PLCI *plci, byte *msg, word length)
  11546. {
  11547. dbug (1, dprintf ("[%06lx] %s,%d: mixer_indication_xconnect_to %d",
  11548. UnMapId (Id), (char *)(FILE_), __LINE__, (int) length));
  11549. }
  11550. static byte mixer_notify_source_removed (PLCI *plci, dword plci_b_id)
  11551. {
  11552. word plci_b_write_pos;
  11553. plci_b_write_pos = plci->li_plci_b_write_pos;
  11554. if (((plci->li_plci_b_read_pos > plci_b_write_pos) ? plci->li_plci_b_read_pos :
  11555. LI_PLCI_B_QUEUE_ENTRIES + plci->li_plci_b_read_pos) - plci_b_write_pos - 1 < 1)
  11556. {
  11557. dbug (1, dprintf ("[%06lx] %s,%d: LI request overrun",
  11558. (dword)((plci->Id << 8) | UnMapController (plci->adapter->Id)),
  11559. (char *)(FILE_), __LINE__));
  11560. return (false);
  11561. }
  11562. plci->li_plci_b_queue[plci_b_write_pos] = plci_b_id | LI_PLCI_B_DISC_FLAG;
  11563. plci_b_write_pos = (plci_b_write_pos == LI_PLCI_B_QUEUE_ENTRIES-1) ? 0 : plci_b_write_pos + 1;
  11564. plci->li_plci_b_write_pos = plci_b_write_pos;
  11565. return (true);
  11566. }
  11567. static void mixer_remove (PLCI *plci)
  11568. {
  11569. DIVA_CAPI_ADAPTER *a;
  11570. PLCI *notify_plci;
  11571. dword plci_b_id;
  11572. word i, j;
  11573. dbug (1, dprintf ("[%06lx] %s,%d: mixer_remove",
  11574. (dword)((plci->Id << 8) | UnMapController (plci->adapter->Id)),
  11575. (char *)(FILE_), __LINE__));
  11576. a = plci->adapter;
  11577. plci_b_id = (plci->Id << 8) | UnMapController (plci->adapter->Id);
  11578. if (a->profile.Global_Options & GL_LINE_INTERCONNECT_SUPPORTED)
  11579. {
  11580. if ((plci->li_bchannel_id != 0)
  11581. && (li_config_table[a->li_base + (plci->li_bchannel_id - 1)].plci == plci))
  11582. {
  11583. i = a->li_base + (plci->li_bchannel_id - 1);
  11584. if ((li_config_table[i].curchnl | li_config_table[i].channel) & LI_CHANNEL_INVOLVED)
  11585. {
  11586. for (j = 0; j < li_total_channels; j++)
  11587. {
  11588. if ((li_config_table[i].flag_table[j] & LI_FLAG_INTERCONNECT)
  11589. || (li_config_table[j].flag_table[i] & LI_FLAG_INTERCONNECT))
  11590. {
  11591. notify_plci = li_config_table[j].plci;
  11592. if ((notify_plci != NULL)
  11593. && (notify_plci != plci)
  11594. && (notify_plci->appl != NULL)
  11595. && !(notify_plci->appl->appl_flags & APPL_FLAG_OLD_LI_SPEC)
  11596. && (notify_plci->State)
  11597. && notify_plci->NL.Id && !notify_plci->nl_remove_id)
  11598. {
  11599. mixer_notify_source_removed (notify_plci, plci_b_id);
  11600. }
  11601. }
  11602. }
  11603. mixer_clear_config (plci);
  11604. mixer_calculate_coefs (a);
  11605. mixer_notify_update (plci, true);
  11606. }
  11607. li_config_table[i].plci = NULL;
  11608. plci->li_bchannel_id = 0;
  11609. }
  11610. }
  11611. }
  11612. /*------------------------------------------------------------------*/
  11613. /* Echo canceller facilities */
  11614. /*------------------------------------------------------------------*/
  11615. static void ec_write_parameters (PLCI *plci)
  11616. {
  11617. word w;
  11618. byte parameter_buffer[6];
  11619. dbug (1, dprintf ("[%06lx] %s,%d: ec_write_parameters",
  11620. (dword)((plci->Id << 8) | UnMapController (plci->adapter->Id)),
  11621. (char *)(FILE_), __LINE__));
  11622. parameter_buffer[0] = 5;
  11623. parameter_buffer[1] = DSP_CTRL_SET_LEC_PARAMETERS;
  11624. PUT_WORD (&parameter_buffer[2], plci->ec_idi_options);
  11625. plci->ec_idi_options &= ~LEC_RESET_COEFFICIENTS;
  11626. w = (plci->ec_tail_length == 0) ? 128 : plci->ec_tail_length;
  11627. PUT_WORD (&parameter_buffer[4], w);
  11628. add_p (plci, FTY, parameter_buffer);
  11629. sig_req (plci, TEL_CTRL, 0);
  11630. send_req (plci);
  11631. }
  11632. static void ec_clear_config (PLCI *plci)
  11633. {
  11634. dbug (1, dprintf ("[%06lx] %s,%d: ec_clear_config",
  11635. (dword)((plci->Id << 8) | UnMapController (plci->adapter->Id)),
  11636. (char *)(FILE_), __LINE__));
  11637. plci->ec_idi_options = LEC_ENABLE_ECHO_CANCELLER |
  11638. LEC_MANUAL_DISABLE | LEC_ENABLE_NONLINEAR_PROCESSING;
  11639. plci->ec_tail_length = 0;
  11640. }
  11641. static void ec_prepare_switch (dword Id, PLCI *plci)
  11642. {
  11643. dbug (1, dprintf ("[%06lx] %s,%d: ec_prepare_switch",
  11644. UnMapId (Id), (char *)(FILE_), __LINE__));
  11645. }
  11646. static word ec_save_config (dword Id, PLCI *plci, byte Rc)
  11647. {
  11648. dbug (1, dprintf ("[%06lx] %s,%d: ec_save_config %02x %d",
  11649. UnMapId (Id), (char *)(FILE_), __LINE__, Rc, plci->adjust_b_state));
  11650. return (GOOD);
  11651. }
  11652. static word ec_restore_config (dword Id, PLCI *plci, byte Rc)
  11653. {
  11654. word Info;
  11655. dbug (1, dprintf ("[%06lx] %s,%d: ec_restore_config %02x %d",
  11656. UnMapId (Id), (char *)(FILE_), __LINE__, Rc, plci->adjust_b_state));
  11657. Info = GOOD;
  11658. if (plci->B1_facilities & B1_FACILITY_EC)
  11659. {
  11660. switch (plci->adjust_b_state)
  11661. {
  11662. case ADJUST_B_RESTORE_EC_1:
  11663. plci->internal_command = plci->adjust_b_command;
  11664. if (plci->sig_req)
  11665. {
  11666. plci->adjust_b_state = ADJUST_B_RESTORE_EC_1;
  11667. break;
  11668. }
  11669. ec_write_parameters (plci);
  11670. plci->adjust_b_state = ADJUST_B_RESTORE_EC_2;
  11671. break;
  11672. case ADJUST_B_RESTORE_EC_2:
  11673. if ((Rc != OK) && (Rc != OK_FC))
  11674. {
  11675. dbug (1, dprintf ("[%06lx] %s,%d: Restore EC failed %02x",
  11676. UnMapId (Id), (char *)(FILE_), __LINE__, Rc));
  11677. Info = _WRONG_STATE;
  11678. break;
  11679. }
  11680. break;
  11681. }
  11682. }
  11683. return (Info);
  11684. }
  11685. static void ec_command (dword Id, PLCI *plci, byte Rc)
  11686. {
  11687. word internal_command, Info;
  11688. byte result[8];
  11689. dbug (1, dprintf ("[%06lx] %s,%d: ec_command %02x %04x %04x %04x %d",
  11690. UnMapId (Id), (char *)(FILE_), __LINE__, Rc, plci->internal_command,
  11691. plci->ec_cmd, plci->ec_idi_options, plci->ec_tail_length));
  11692. Info = GOOD;
  11693. if (plci->appl->appl_flags & APPL_FLAG_PRIV_EC_SPEC)
  11694. {
  11695. result[0] = 2;
  11696. PUT_WORD (&result[1], EC_SUCCESS);
  11697. }
  11698. else
  11699. {
  11700. result[0] = 5;
  11701. PUT_WORD (&result[1], plci->ec_cmd);
  11702. result[3] = 2;
  11703. PUT_WORD (&result[4], GOOD);
  11704. }
  11705. internal_command = plci->internal_command;
  11706. plci->internal_command = 0;
  11707. switch (plci->ec_cmd)
  11708. {
  11709. case EC_ENABLE_OPERATION:
  11710. case EC_FREEZE_COEFFICIENTS:
  11711. case EC_RESUME_COEFFICIENT_UPDATE:
  11712. case EC_RESET_COEFFICIENTS:
  11713. switch (internal_command)
  11714. {
  11715. default:
  11716. adjust_b1_resource (Id, plci, NULL, (word)(plci->B1_facilities |
  11717. B1_FACILITY_EC), EC_COMMAND_1);
  11718. case EC_COMMAND_1:
  11719. if (adjust_b_process (Id, plci, Rc) != GOOD)
  11720. {
  11721. dbug (1, dprintf ("[%06lx] %s,%d: Load EC failed",
  11722. UnMapId (Id), (char *)(FILE_), __LINE__));
  11723. Info = _FACILITY_NOT_SUPPORTED;
  11724. break;
  11725. }
  11726. if (plci->internal_command)
  11727. return;
  11728. case EC_COMMAND_2:
  11729. if (plci->sig_req)
  11730. {
  11731. plci->internal_command = EC_COMMAND_2;
  11732. return;
  11733. }
  11734. plci->internal_command = EC_COMMAND_3;
  11735. ec_write_parameters (plci);
  11736. return;
  11737. case EC_COMMAND_3:
  11738. if ((Rc != OK) && (Rc != OK_FC))
  11739. {
  11740. dbug (1, dprintf ("[%06lx] %s,%d: Enable EC failed %02x",
  11741. UnMapId (Id), (char *)(FILE_), __LINE__, Rc));
  11742. Info = _FACILITY_NOT_SUPPORTED;
  11743. break;
  11744. }
  11745. break;
  11746. }
  11747. break;
  11748. case EC_DISABLE_OPERATION:
  11749. switch (internal_command)
  11750. {
  11751. default:
  11752. case EC_COMMAND_1:
  11753. if (plci->B1_facilities & B1_FACILITY_EC)
  11754. {
  11755. if (plci->sig_req)
  11756. {
  11757. plci->internal_command = EC_COMMAND_1;
  11758. return;
  11759. }
  11760. plci->internal_command = EC_COMMAND_2;
  11761. ec_write_parameters (plci);
  11762. return;
  11763. }
  11764. Rc = OK;
  11765. case EC_COMMAND_2:
  11766. if ((Rc != OK) && (Rc != OK_FC))
  11767. {
  11768. dbug (1, dprintf ("[%06lx] %s,%d: Disable EC failed %02x",
  11769. UnMapId (Id), (char *)(FILE_), __LINE__, Rc));
  11770. Info = _FACILITY_NOT_SUPPORTED;
  11771. break;
  11772. }
  11773. adjust_b1_resource (Id, plci, NULL, (word)(plci->B1_facilities &
  11774. ~B1_FACILITY_EC), EC_COMMAND_3);
  11775. case EC_COMMAND_3:
  11776. if (adjust_b_process (Id, plci, Rc) != GOOD)
  11777. {
  11778. dbug (1, dprintf ("[%06lx] %s,%d: Unload EC failed",
  11779. UnMapId (Id), (char *)(FILE_), __LINE__));
  11780. Info = _FACILITY_NOT_SUPPORTED;
  11781. break;
  11782. }
  11783. if (plci->internal_command)
  11784. return;
  11785. break;
  11786. }
  11787. break;
  11788. }
  11789. sendf (plci->appl, _FACILITY_R | CONFIRM, Id & 0xffffL, plci->number,
  11790. "wws", Info, (plci->appl->appl_flags & APPL_FLAG_PRIV_EC_SPEC) ?
  11791. PRIV_SELECTOR_ECHO_CANCELLER : SELECTOR_ECHO_CANCELLER, result);
  11792. }
  11793. static byte ec_request (dword Id, word Number, DIVA_CAPI_ADAPTER *a, PLCI *plci, APPL *appl, API_PARSE *msg)
  11794. {
  11795. word Info;
  11796. word opt;
  11797. API_PARSE ec_parms[3];
  11798. byte result[16];
  11799. dbug (1, dprintf ("[%06lx] %s,%d: ec_request",
  11800. UnMapId (Id), (char *)(FILE_), __LINE__));
  11801. Info = GOOD;
  11802. result[0] = 0;
  11803. if (!(a->man_profile.private_options & (1L << PRIVATE_ECHO_CANCELLER)))
  11804. {
  11805. dbug (1, dprintf ("[%06lx] %s,%d: Facility not supported",
  11806. UnMapId (Id), (char *)(FILE_), __LINE__));
  11807. Info = _FACILITY_NOT_SUPPORTED;
  11808. }
  11809. else
  11810. {
  11811. if (appl->appl_flags & APPL_FLAG_PRIV_EC_SPEC)
  11812. {
  11813. if (api_parse (&msg[1].info[1], msg[1].length, "w", ec_parms))
  11814. {
  11815. dbug (1, dprintf ("[%06lx] %s,%d: Wrong message format",
  11816. UnMapId (Id), (char *)(FILE_), __LINE__));
  11817. Info = _WRONG_MESSAGE_FORMAT;
  11818. }
  11819. else
  11820. {
  11821. if (plci == NULL)
  11822. {
  11823. dbug (1, dprintf ("[%06lx] %s,%d: Wrong PLCI",
  11824. UnMapId (Id), (char *)(FILE_), __LINE__));
  11825. Info = _WRONG_IDENTIFIER;
  11826. }
  11827. else if (!plci->State || !plci->NL.Id || plci->nl_remove_id)
  11828. {
  11829. dbug (1, dprintf ("[%06lx] %s,%d: Wrong state",
  11830. UnMapId (Id), (char *)(FILE_), __LINE__));
  11831. Info = _WRONG_STATE;
  11832. }
  11833. else
  11834. {
  11835. plci->command = 0;
  11836. plci->ec_cmd = GET_WORD (ec_parms[0].info);
  11837. plci->ec_idi_options &= ~(LEC_MANUAL_DISABLE | LEC_RESET_COEFFICIENTS);
  11838. result[0] = 2;
  11839. PUT_WORD (&result[1], EC_SUCCESS);
  11840. if (msg[1].length >= 4)
  11841. {
  11842. opt = GET_WORD (&ec_parms[0].info[2]);
  11843. plci->ec_idi_options &= ~(LEC_ENABLE_NONLINEAR_PROCESSING |
  11844. LEC_ENABLE_2100HZ_DETECTOR | LEC_REQUIRE_2100HZ_REVERSALS);
  11845. if (!(opt & EC_DISABLE_NON_LINEAR_PROCESSING))
  11846. plci->ec_idi_options |= LEC_ENABLE_NONLINEAR_PROCESSING;
  11847. if (opt & EC_DETECT_DISABLE_TONE)
  11848. plci->ec_idi_options |= LEC_ENABLE_2100HZ_DETECTOR;
  11849. if (!(opt & EC_DO_NOT_REQUIRE_REVERSALS))
  11850. plci->ec_idi_options |= LEC_REQUIRE_2100HZ_REVERSALS;
  11851. if (msg[1].length >= 6)
  11852. {
  11853. plci->ec_tail_length = GET_WORD (&ec_parms[0].info[4]);
  11854. }
  11855. }
  11856. switch (plci->ec_cmd)
  11857. {
  11858. case EC_ENABLE_OPERATION:
  11859. plci->ec_idi_options &= ~LEC_FREEZE_COEFFICIENTS;
  11860. start_internal_command (Id, plci, ec_command);
  11861. return (false);
  11862. case EC_DISABLE_OPERATION:
  11863. plci->ec_idi_options = LEC_ENABLE_ECHO_CANCELLER |
  11864. LEC_MANUAL_DISABLE | LEC_ENABLE_NONLINEAR_PROCESSING |
  11865. LEC_RESET_COEFFICIENTS;
  11866. start_internal_command (Id, plci, ec_command);
  11867. return (false);
  11868. case EC_FREEZE_COEFFICIENTS:
  11869. plci->ec_idi_options |= LEC_FREEZE_COEFFICIENTS;
  11870. start_internal_command (Id, plci, ec_command);
  11871. return (false);
  11872. case EC_RESUME_COEFFICIENT_UPDATE:
  11873. plci->ec_idi_options &= ~LEC_FREEZE_COEFFICIENTS;
  11874. start_internal_command (Id, plci, ec_command);
  11875. return (false);
  11876. case EC_RESET_COEFFICIENTS:
  11877. plci->ec_idi_options |= LEC_RESET_COEFFICIENTS;
  11878. start_internal_command (Id, plci, ec_command);
  11879. return (false);
  11880. default:
  11881. dbug (1, dprintf ("[%06lx] %s,%d: EC unknown request %04x",
  11882. UnMapId (Id), (char *)(FILE_), __LINE__, plci->ec_cmd));
  11883. PUT_WORD (&result[1], EC_UNSUPPORTED_OPERATION);
  11884. }
  11885. }
  11886. }
  11887. }
  11888. else
  11889. {
  11890. if (api_parse (&msg[1].info[1], msg[1].length, "ws", ec_parms))
  11891. {
  11892. dbug (1, dprintf ("[%06lx] %s,%d: Wrong message format",
  11893. UnMapId (Id), (char *)(FILE_), __LINE__));
  11894. Info = _WRONG_MESSAGE_FORMAT;
  11895. }
  11896. else
  11897. {
  11898. if (GET_WORD (ec_parms[0].info) == EC_GET_SUPPORTED_SERVICES)
  11899. {
  11900. result[0] = 11;
  11901. PUT_WORD (&result[1], EC_GET_SUPPORTED_SERVICES);
  11902. result[3] = 8;
  11903. PUT_WORD (&result[4], GOOD);
  11904. PUT_WORD (&result[6], 0x0007);
  11905. PUT_WORD (&result[8], LEC_MAX_SUPPORTED_TAIL_LENGTH);
  11906. PUT_WORD (&result[10], 0);
  11907. }
  11908. else if (plci == NULL)
  11909. {
  11910. dbug (1, dprintf ("[%06lx] %s,%d: Wrong PLCI",
  11911. UnMapId (Id), (char *)(FILE_), __LINE__));
  11912. Info = _WRONG_IDENTIFIER;
  11913. }
  11914. else if (!plci->State || !plci->NL.Id || plci->nl_remove_id)
  11915. {
  11916. dbug (1, dprintf ("[%06lx] %s,%d: Wrong state",
  11917. UnMapId (Id), (char *)(FILE_), __LINE__));
  11918. Info = _WRONG_STATE;
  11919. }
  11920. else
  11921. {
  11922. plci->command = 0;
  11923. plci->ec_cmd = GET_WORD (ec_parms[0].info);
  11924. plci->ec_idi_options &= ~(LEC_MANUAL_DISABLE | LEC_RESET_COEFFICIENTS);
  11925. result[0] = 5;
  11926. PUT_WORD (&result[1], plci->ec_cmd);
  11927. result[3] = 2;
  11928. PUT_WORD (&result[4], GOOD);
  11929. plci->ec_idi_options &= ~(LEC_ENABLE_NONLINEAR_PROCESSING |
  11930. LEC_ENABLE_2100HZ_DETECTOR | LEC_REQUIRE_2100HZ_REVERSALS);
  11931. plci->ec_tail_length = 0;
  11932. if (ec_parms[1].length >= 2)
  11933. {
  11934. opt = GET_WORD (&ec_parms[1].info[1]);
  11935. if (opt & EC_ENABLE_NON_LINEAR_PROCESSING)
  11936. plci->ec_idi_options |= LEC_ENABLE_NONLINEAR_PROCESSING;
  11937. if (opt & EC_DETECT_DISABLE_TONE)
  11938. plci->ec_idi_options |= LEC_ENABLE_2100HZ_DETECTOR;
  11939. if (!(opt & EC_DO_NOT_REQUIRE_REVERSALS))
  11940. plci->ec_idi_options |= LEC_REQUIRE_2100HZ_REVERSALS;
  11941. if (ec_parms[1].length >= 4)
  11942. {
  11943. plci->ec_tail_length = GET_WORD (&ec_parms[1].info[3]);
  11944. }
  11945. }
  11946. switch (plci->ec_cmd)
  11947. {
  11948. case EC_ENABLE_OPERATION:
  11949. plci->ec_idi_options &= ~LEC_FREEZE_COEFFICIENTS;
  11950. start_internal_command (Id, plci, ec_command);
  11951. return (false);
  11952. case EC_DISABLE_OPERATION:
  11953. plci->ec_idi_options = LEC_ENABLE_ECHO_CANCELLER |
  11954. LEC_MANUAL_DISABLE | LEC_ENABLE_NONLINEAR_PROCESSING |
  11955. LEC_RESET_COEFFICIENTS;
  11956. start_internal_command (Id, plci, ec_command);
  11957. return (false);
  11958. default:
  11959. dbug (1, dprintf ("[%06lx] %s,%d: EC unknown request %04x",
  11960. UnMapId (Id), (char *)(FILE_), __LINE__, plci->ec_cmd));
  11961. PUT_WORD (&result[4], _FACILITY_SPECIFIC_FUNCTION_NOT_SUPP);
  11962. }
  11963. }
  11964. }
  11965. }
  11966. }
  11967. sendf (appl, _FACILITY_R | CONFIRM, Id & 0xffffL, Number,
  11968. "wws", Info, (appl->appl_flags & APPL_FLAG_PRIV_EC_SPEC) ?
  11969. PRIV_SELECTOR_ECHO_CANCELLER : SELECTOR_ECHO_CANCELLER, result);
  11970. return (false);
  11971. }
  11972. static void ec_indication (dword Id, PLCI *plci, byte *msg, word length)
  11973. {
  11974. byte result[8];
  11975. dbug (1, dprintf ("[%06lx] %s,%d: ec_indication",
  11976. UnMapId (Id), (char *)(FILE_), __LINE__));
  11977. if (!(plci->ec_idi_options & LEC_MANUAL_DISABLE))
  11978. {
  11979. if (plci->appl->appl_flags & APPL_FLAG_PRIV_EC_SPEC)
  11980. {
  11981. result[0] = 2;
  11982. PUT_WORD (&result[1], 0);
  11983. switch (msg[1])
  11984. {
  11985. case LEC_DISABLE_TYPE_CONTIGNUOUS_2100HZ:
  11986. PUT_WORD (&result[1], EC_BYPASS_DUE_TO_CONTINUOUS_2100HZ);
  11987. break;
  11988. case LEC_DISABLE_TYPE_REVERSED_2100HZ:
  11989. PUT_WORD (&result[1], EC_BYPASS_DUE_TO_REVERSED_2100HZ);
  11990. break;
  11991. case LEC_DISABLE_RELEASED:
  11992. PUT_WORD (&result[1], EC_BYPASS_RELEASED);
  11993. break;
  11994. }
  11995. }
  11996. else
  11997. {
  11998. result[0] = 5;
  11999. PUT_WORD (&result[1], EC_BYPASS_INDICATION);
  12000. result[3] = 2;
  12001. PUT_WORD (&result[4], 0);
  12002. switch (msg[1])
  12003. {
  12004. case LEC_DISABLE_TYPE_CONTIGNUOUS_2100HZ:
  12005. PUT_WORD (&result[4], EC_BYPASS_DUE_TO_CONTINUOUS_2100HZ);
  12006. break;
  12007. case LEC_DISABLE_TYPE_REVERSED_2100HZ:
  12008. PUT_WORD (&result[4], EC_BYPASS_DUE_TO_REVERSED_2100HZ);
  12009. break;
  12010. case LEC_DISABLE_RELEASED:
  12011. PUT_WORD (&result[4], EC_BYPASS_RELEASED);
  12012. break;
  12013. }
  12014. }
  12015. sendf (plci->appl, _FACILITY_I, Id & 0xffffL, 0, "ws", (plci->appl->appl_flags & APPL_FLAG_PRIV_EC_SPEC) ?
  12016. PRIV_SELECTOR_ECHO_CANCELLER : SELECTOR_ECHO_CANCELLER, result);
  12017. }
  12018. }
  12019. /*------------------------------------------------------------------*/
  12020. /* Advanced voice */
  12021. /*------------------------------------------------------------------*/
  12022. static void adv_voice_write_coefs (PLCI *plci, word write_command)
  12023. {
  12024. DIVA_CAPI_ADAPTER *a;
  12025. word i;
  12026. byte *p;
  12027. word w, n, j, k;
  12028. byte ch_map[MIXER_CHANNELS_BRI];
  12029. byte coef_buffer[ADV_VOICE_COEF_BUFFER_SIZE + 2];
  12030. dbug (1, dprintf ("[%06lx] %s,%d: adv_voice_write_coefs %d",
  12031. (dword)((plci->Id << 8) | UnMapController (plci->adapter->Id)),
  12032. (char *)(FILE_), __LINE__, write_command));
  12033. a = plci->adapter;
  12034. p = coef_buffer + 1;
  12035. *(p++) = DSP_CTRL_OLD_SET_MIXER_COEFFICIENTS;
  12036. i = 0;
  12037. while (i + sizeof(word) <= a->adv_voice_coef_length)
  12038. {
  12039. PUT_WORD (p, GET_WORD (a->adv_voice_coef_buffer + i));
  12040. p += 2;
  12041. i += 2;
  12042. }
  12043. while (i < ADV_VOICE_OLD_COEF_COUNT * sizeof(word))
  12044. {
  12045. PUT_WORD (p, 0x8000);
  12046. p += 2;
  12047. i += 2;
  12048. }
  12049. if (!a->li_pri && (plci->li_bchannel_id == 0))
  12050. {
  12051. if ((li_config_table[a->li_base].plci == NULL) && (li_config_table[a->li_base + 1].plci != NULL))
  12052. {
  12053. plci->li_bchannel_id = 1;
  12054. li_config_table[a->li_base].plci = plci;
  12055. dbug (1, dprintf ("[%06lx] %s,%d: adv_voice_set_bchannel_id %d",
  12056. (dword)((plci->Id << 8) | UnMapController (plci->adapter->Id)),
  12057. (char *)(FILE_), __LINE__, plci->li_bchannel_id));
  12058. }
  12059. else if ((li_config_table[a->li_base].plci != NULL) && (li_config_table[a->li_base + 1].plci == NULL))
  12060. {
  12061. plci->li_bchannel_id = 2;
  12062. li_config_table[a->li_base + 1].plci = plci;
  12063. dbug (1, dprintf ("[%06lx] %s,%d: adv_voice_set_bchannel_id %d",
  12064. (dword)((plci->Id << 8) | UnMapController (plci->adapter->Id)),
  12065. (char *)(FILE_), __LINE__, plci->li_bchannel_id));
  12066. }
  12067. }
  12068. if (!a->li_pri && (plci->li_bchannel_id != 0)
  12069. && (li_config_table[a->li_base + (plci->li_bchannel_id - 1)].plci == plci))
  12070. {
  12071. i = a->li_base + (plci->li_bchannel_id - 1);
  12072. switch (write_command)
  12073. {
  12074. case ADV_VOICE_WRITE_ACTIVATION:
  12075. j = a->li_base + MIXER_IC_CHANNEL_BASE + (plci->li_bchannel_id - 1);
  12076. k = a->li_base + MIXER_IC_CHANNEL_BASE + (2 - plci->li_bchannel_id);
  12077. if (!(plci->B1_facilities & B1_FACILITY_MIXER))
  12078. {
  12079. li_config_table[j].flag_table[i] |= LI_FLAG_CONFERENCE | LI_FLAG_MIX;
  12080. li_config_table[i].flag_table[j] |= LI_FLAG_CONFERENCE | LI_FLAG_MONITOR;
  12081. }
  12082. if (a->manufacturer_features & MANUFACTURER_FEATURE_SLAVE_CODEC)
  12083. {
  12084. li_config_table[k].flag_table[i] |= LI_FLAG_CONFERENCE | LI_FLAG_MIX;
  12085. li_config_table[i].flag_table[k] |= LI_FLAG_CONFERENCE | LI_FLAG_MONITOR;
  12086. li_config_table[k].flag_table[j] |= LI_FLAG_CONFERENCE;
  12087. li_config_table[j].flag_table[k] |= LI_FLAG_CONFERENCE;
  12088. }
  12089. mixer_calculate_coefs (a);
  12090. li_config_table[i].curchnl = li_config_table[i].channel;
  12091. li_config_table[j].curchnl = li_config_table[j].channel;
  12092. if (a->manufacturer_features & MANUFACTURER_FEATURE_SLAVE_CODEC)
  12093. li_config_table[k].curchnl = li_config_table[k].channel;
  12094. break;
  12095. case ADV_VOICE_WRITE_DEACTIVATION:
  12096. for (j = 0; j < li_total_channels; j++)
  12097. {
  12098. li_config_table[i].flag_table[j] = 0;
  12099. li_config_table[j].flag_table[i] = 0;
  12100. }
  12101. k = a->li_base + MIXER_IC_CHANNEL_BASE + (plci->li_bchannel_id - 1);
  12102. for (j = 0; j < li_total_channels; j++)
  12103. {
  12104. li_config_table[k].flag_table[j] = 0;
  12105. li_config_table[j].flag_table[k] = 0;
  12106. }
  12107. if (a->manufacturer_features & MANUFACTURER_FEATURE_SLAVE_CODEC)
  12108. {
  12109. k = a->li_base + MIXER_IC_CHANNEL_BASE + (2 - plci->li_bchannel_id);
  12110. for (j = 0; j < li_total_channels; j++)
  12111. {
  12112. li_config_table[k].flag_table[j] = 0;
  12113. li_config_table[j].flag_table[k] = 0;
  12114. }
  12115. }
  12116. mixer_calculate_coefs (a);
  12117. break;
  12118. }
  12119. if (plci->B1_facilities & B1_FACILITY_MIXER)
  12120. {
  12121. w = 0;
  12122. if (ADV_VOICE_NEW_COEF_BASE + sizeof(word) <= a->adv_voice_coef_length)
  12123. w = GET_WORD (a->adv_voice_coef_buffer + ADV_VOICE_NEW_COEF_BASE);
  12124. if (li_config_table[i].channel & LI_CHANNEL_TX_DATA)
  12125. w |= MIXER_FEATURE_ENABLE_TX_DATA;
  12126. if (li_config_table[i].channel & LI_CHANNEL_RX_DATA)
  12127. w |= MIXER_FEATURE_ENABLE_RX_DATA;
  12128. *(p++) = (byte) w;
  12129. *(p++) = (byte)(w >> 8);
  12130. for (j = 0; j < sizeof(ch_map); j += 2)
  12131. {
  12132. ch_map[j] = (byte)(j + (plci->li_bchannel_id - 1));
  12133. ch_map[j+1] = (byte)(j + (2 - plci->li_bchannel_id));
  12134. }
  12135. for (n = 0; n < ARRAY_SIZE(mixer_write_prog_bri); n++)
  12136. {
  12137. i = a->li_base + ch_map[mixer_write_prog_bri[n].to_ch];
  12138. j = a->li_base + ch_map[mixer_write_prog_bri[n].from_ch];
  12139. if (li_config_table[i].channel & li_config_table[j].channel & LI_CHANNEL_INVOLVED)
  12140. {
  12141. *(p++) = ((li_config_table[i].coef_table[j] & mixer_write_prog_bri[n].mask) ? 0x80 : 0x01);
  12142. w = ((li_config_table[i].coef_table[j] & 0xf) ^ (li_config_table[i].coef_table[j] >> 4));
  12143. li_config_table[i].coef_table[j] ^= (w & mixer_write_prog_bri[n].mask) << 4;
  12144. }
  12145. else
  12146. {
  12147. *(p++) = (ADV_VOICE_NEW_COEF_BASE + sizeof(word) + n < a->adv_voice_coef_length) ?
  12148. a->adv_voice_coef_buffer[ADV_VOICE_NEW_COEF_BASE + sizeof(word) + n] : 0x00;
  12149. }
  12150. }
  12151. }
  12152. else
  12153. {
  12154. for (i = ADV_VOICE_NEW_COEF_BASE; i < a->adv_voice_coef_length; i++)
  12155. *(p++) = a->adv_voice_coef_buffer[i];
  12156. }
  12157. }
  12158. else
  12159. {
  12160. for (i = ADV_VOICE_NEW_COEF_BASE; i < a->adv_voice_coef_length; i++)
  12161. *(p++) = a->adv_voice_coef_buffer[i];
  12162. }
  12163. coef_buffer[0] = (p - coef_buffer) - 1;
  12164. add_p (plci, FTY, coef_buffer);
  12165. sig_req (plci, TEL_CTRL, 0);
  12166. send_req (plci);
  12167. }
  12168. static void adv_voice_clear_config (PLCI *plci)
  12169. {
  12170. DIVA_CAPI_ADAPTER *a;
  12171. word i, j;
  12172. dbug (1, dprintf ("[%06lx] %s,%d: adv_voice_clear_config",
  12173. (dword)((plci->Id << 8) | UnMapController (plci->adapter->Id)),
  12174. (char *)(FILE_), __LINE__));
  12175. a = plci->adapter;
  12176. if ((plci->tel == ADV_VOICE) && (plci == a->AdvSignalPLCI))
  12177. {
  12178. a->adv_voice_coef_length = 0;
  12179. if (!a->li_pri && (plci->li_bchannel_id != 0)
  12180. && (li_config_table[a->li_base + (plci->li_bchannel_id - 1)].plci == plci))
  12181. {
  12182. i = a->li_base + (plci->li_bchannel_id - 1);
  12183. li_config_table[i].curchnl = 0;
  12184. li_config_table[i].channel = 0;
  12185. li_config_table[i].chflags = 0;
  12186. for (j = 0; j < li_total_channels; j++)
  12187. {
  12188. li_config_table[i].flag_table[j] = 0;
  12189. li_config_table[j].flag_table[i] = 0;
  12190. li_config_table[i].coef_table[j] = 0;
  12191. li_config_table[j].coef_table[i] = 0;
  12192. }
  12193. li_config_table[i].coef_table[i] |= LI_COEF_CH_PC_SET | LI_COEF_PC_CH_SET;
  12194. i = a->li_base + MIXER_IC_CHANNEL_BASE + (plci->li_bchannel_id - 1);
  12195. li_config_table[i].curchnl = 0;
  12196. li_config_table[i].channel = 0;
  12197. li_config_table[i].chflags = 0;
  12198. for (j = 0; j < li_total_channels; j++)
  12199. {
  12200. li_config_table[i].flag_table[j] = 0;
  12201. li_config_table[j].flag_table[i] = 0;
  12202. li_config_table[i].coef_table[j] = 0;
  12203. li_config_table[j].coef_table[i] = 0;
  12204. }
  12205. if (a->manufacturer_features & MANUFACTURER_FEATURE_SLAVE_CODEC)
  12206. {
  12207. i = a->li_base + MIXER_IC_CHANNEL_BASE + (2 - plci->li_bchannel_id);
  12208. li_config_table[i].curchnl = 0;
  12209. li_config_table[i].channel = 0;
  12210. li_config_table[i].chflags = 0;
  12211. for (j = 0; j < li_total_channels; j++)
  12212. {
  12213. li_config_table[i].flag_table[j] = 0;
  12214. li_config_table[j].flag_table[i] = 0;
  12215. li_config_table[i].coef_table[j] = 0;
  12216. li_config_table[j].coef_table[i] = 0;
  12217. }
  12218. }
  12219. }
  12220. }
  12221. }
  12222. static void adv_voice_prepare_switch (dword Id, PLCI *plci)
  12223. {
  12224. dbug (1, dprintf ("[%06lx] %s,%d: adv_voice_prepare_switch",
  12225. UnMapId (Id), (char *)(FILE_), __LINE__));
  12226. }
  12227. static word adv_voice_save_config (dword Id, PLCI *plci, byte Rc)
  12228. {
  12229. dbug (1, dprintf ("[%06lx] %s,%d: adv_voice_save_config %02x %d",
  12230. UnMapId (Id), (char *)(FILE_), __LINE__, Rc, plci->adjust_b_state));
  12231. return (GOOD);
  12232. }
  12233. static word adv_voice_restore_config (dword Id, PLCI *plci, byte Rc)
  12234. {
  12235. DIVA_CAPI_ADAPTER *a;
  12236. word Info;
  12237. dbug (1, dprintf ("[%06lx] %s,%d: adv_voice_restore_config %02x %d",
  12238. UnMapId (Id), (char *)(FILE_), __LINE__, Rc, plci->adjust_b_state));
  12239. Info = GOOD;
  12240. a = plci->adapter;
  12241. if ((plci->B1_facilities & B1_FACILITY_VOICE)
  12242. && (plci->tel == ADV_VOICE) && (plci == a->AdvSignalPLCI))
  12243. {
  12244. switch (plci->adjust_b_state)
  12245. {
  12246. case ADJUST_B_RESTORE_VOICE_1:
  12247. plci->internal_command = plci->adjust_b_command;
  12248. if (plci->sig_req)
  12249. {
  12250. plci->adjust_b_state = ADJUST_B_RESTORE_VOICE_1;
  12251. break;
  12252. }
  12253. adv_voice_write_coefs (plci, ADV_VOICE_WRITE_UPDATE);
  12254. plci->adjust_b_state = ADJUST_B_RESTORE_VOICE_2;
  12255. break;
  12256. case ADJUST_B_RESTORE_VOICE_2:
  12257. if ((Rc != OK) && (Rc != OK_FC))
  12258. {
  12259. dbug (1, dprintf ("[%06lx] %s,%d: Restore voice config failed %02x",
  12260. UnMapId (Id), (char *)(FILE_), __LINE__, Rc));
  12261. Info = _WRONG_STATE;
  12262. break;
  12263. }
  12264. break;
  12265. }
  12266. }
  12267. return (Info);
  12268. }
  12269. /*------------------------------------------------------------------*/
  12270. /* B1 resource switching */
  12271. /*------------------------------------------------------------------*/
  12272. static byte b1_facilities_table[] =
  12273. {
  12274. 0x00, /* 0 No bchannel resources */
  12275. 0x00, /* 1 Codec (automatic law) */
  12276. 0x00, /* 2 Codec (A-law) */
  12277. 0x00, /* 3 Codec (y-law) */
  12278. 0x00, /* 4 HDLC for X.21 */
  12279. 0x00, /* 5 HDLC */
  12280. 0x00, /* 6 External Device 0 */
  12281. 0x00, /* 7 External Device 1 */
  12282. 0x00, /* 8 HDLC 56k */
  12283. 0x00, /* 9 Transparent */
  12284. 0x00, /* 10 Loopback to network */
  12285. 0x00, /* 11 Test pattern to net */
  12286. 0x00, /* 12 Rate adaptation sync */
  12287. 0x00, /* 13 Rate adaptation async */
  12288. 0x00, /* 14 R-Interface */
  12289. 0x00, /* 15 HDLC 128k leased line */
  12290. 0x00, /* 16 FAX */
  12291. 0x00, /* 17 Modem async */
  12292. 0x00, /* 18 Modem sync HDLC */
  12293. 0x00, /* 19 V.110 async HDLC */
  12294. 0x12, /* 20 Adv voice (Trans,mixer) */
  12295. 0x00, /* 21 Codec connected to IC */
  12296. 0x0c, /* 22 Trans,DTMF */
  12297. 0x1e, /* 23 Trans,DTMF+mixer */
  12298. 0x1f, /* 24 Trans,DTMF+mixer+local */
  12299. 0x13, /* 25 Trans,mixer+local */
  12300. 0x12, /* 26 HDLC,mixer */
  12301. 0x12, /* 27 HDLC 56k,mixer */
  12302. 0x2c, /* 28 Trans,LEC+DTMF */
  12303. 0x3e, /* 29 Trans,LEC+DTMF+mixer */
  12304. 0x3f, /* 30 Trans,LEC+DTMF+mixer+local */
  12305. 0x2c, /* 31 RTP,LEC+DTMF */
  12306. 0x3e, /* 32 RTP,LEC+DTMF+mixer */
  12307. 0x3f, /* 33 RTP,LEC+DTMF+mixer+local */
  12308. 0x00, /* 34 Signaling task */
  12309. 0x00, /* 35 PIAFS */
  12310. 0x0c, /* 36 Trans,DTMF+TONE */
  12311. 0x1e, /* 37 Trans,DTMF+TONE+mixer */
  12312. 0x1f /* 38 Trans,DTMF+TONE+mixer+local*/
  12313. };
  12314. static word get_b1_facilities (PLCI * plci, byte b1_resource)
  12315. {
  12316. word b1_facilities;
  12317. b1_facilities = b1_facilities_table[b1_resource];
  12318. if ((b1_resource == 9) || (b1_resource == 20) || (b1_resource == 25))
  12319. {
  12320. if (!(((plci->requested_options_conn | plci->requested_options) & (1L << PRIVATE_DTMF_TONE))
  12321. || (plci->appl && (plci->adapter->requested_options_table[plci->appl->Id-1] & (1L << PRIVATE_DTMF_TONE)))))
  12322. {
  12323. if (plci->adapter->manufacturer_features & MANUFACTURER_FEATURE_SOFTDTMF_SEND)
  12324. b1_facilities |= B1_FACILITY_DTMFX;
  12325. if (plci->adapter->manufacturer_features & MANUFACTURER_FEATURE_SOFTDTMF_RECEIVE)
  12326. b1_facilities |= B1_FACILITY_DTMFR;
  12327. }
  12328. }
  12329. if ((b1_resource == 17) || (b1_resource == 18))
  12330. {
  12331. if (plci->adapter->manufacturer_features & (MANUFACTURER_FEATURE_V18 | MANUFACTURER_FEATURE_VOWN))
  12332. b1_facilities |= B1_FACILITY_DTMFX | B1_FACILITY_DTMFR;
  12333. }
  12334. /*
  12335. dbug (1, dprintf ("[%06lx] %s,%d: get_b1_facilities %d %04x",
  12336. (dword)((plci->Id << 8) | UnMapController (plci->adapter->Id)),
  12337. (char far *)(FILE_), __LINE__, b1_resource, b1_facilites));
  12338. */
  12339. return (b1_facilities);
  12340. }
  12341. static byte add_b1_facilities (PLCI * plci, byte b1_resource, word b1_facilities)
  12342. {
  12343. byte b;
  12344. switch (b1_resource)
  12345. {
  12346. case 5:
  12347. case 26:
  12348. if (b1_facilities & (B1_FACILITY_MIXER | B1_FACILITY_VOICE))
  12349. b = 26;
  12350. else
  12351. b = 5;
  12352. break;
  12353. case 8:
  12354. case 27:
  12355. if (b1_facilities & (B1_FACILITY_MIXER | B1_FACILITY_VOICE))
  12356. b = 27;
  12357. else
  12358. b = 8;
  12359. break;
  12360. case 9:
  12361. case 20:
  12362. case 22:
  12363. case 23:
  12364. case 24:
  12365. case 25:
  12366. case 28:
  12367. case 29:
  12368. case 30:
  12369. case 36:
  12370. case 37:
  12371. case 38:
  12372. if (b1_facilities & B1_FACILITY_EC)
  12373. {
  12374. if (b1_facilities & B1_FACILITY_LOCAL)
  12375. b = 30;
  12376. else if (b1_facilities & (B1_FACILITY_MIXER | B1_FACILITY_VOICE))
  12377. b = 29;
  12378. else
  12379. b = 28;
  12380. }
  12381. else if ((b1_facilities & (B1_FACILITY_DTMFX | B1_FACILITY_DTMFR | B1_FACILITY_MIXER))
  12382. && (((plci->requested_options_conn | plci->requested_options) & (1L << PRIVATE_DTMF_TONE))
  12383. || (plci->appl && (plci->adapter->requested_options_table[plci->appl->Id-1] & (1L << PRIVATE_DTMF_TONE)))))
  12384. {
  12385. if (b1_facilities & B1_FACILITY_LOCAL)
  12386. b = 38;
  12387. else if (b1_facilities & (B1_FACILITY_MIXER | B1_FACILITY_VOICE))
  12388. b = 37;
  12389. else
  12390. b = 36;
  12391. }
  12392. else if (((plci->adapter->manufacturer_features & MANUFACTURER_FEATURE_HARDDTMF)
  12393. && !(plci->adapter->manufacturer_features & MANUFACTURER_FEATURE_SOFTDTMF_RECEIVE))
  12394. || ((b1_facilities & B1_FACILITY_DTMFR)
  12395. && ((b1_facilities & B1_FACILITY_MIXER)
  12396. || !(plci->adapter->manufacturer_features & MANUFACTURER_FEATURE_SOFTDTMF_RECEIVE)))
  12397. || ((b1_facilities & B1_FACILITY_DTMFX)
  12398. && ((b1_facilities & B1_FACILITY_MIXER)
  12399. || !(plci->adapter->manufacturer_features & MANUFACTURER_FEATURE_SOFTDTMF_SEND))))
  12400. {
  12401. if (b1_facilities & B1_FACILITY_LOCAL)
  12402. b = 24;
  12403. else if (b1_facilities & (B1_FACILITY_MIXER | B1_FACILITY_VOICE))
  12404. b = 23;
  12405. else
  12406. b = 22;
  12407. }
  12408. else
  12409. {
  12410. if (b1_facilities & B1_FACILITY_LOCAL)
  12411. b = 25;
  12412. else if (b1_facilities & (B1_FACILITY_MIXER | B1_FACILITY_VOICE))
  12413. b = 20;
  12414. else
  12415. b = 9;
  12416. }
  12417. break;
  12418. case 31:
  12419. case 32:
  12420. case 33:
  12421. if (b1_facilities & B1_FACILITY_LOCAL)
  12422. b = 33;
  12423. else if (b1_facilities & (B1_FACILITY_MIXER | B1_FACILITY_VOICE))
  12424. b = 32;
  12425. else
  12426. b = 31;
  12427. break;
  12428. default:
  12429. b = b1_resource;
  12430. }
  12431. dbug (1, dprintf ("[%06lx] %s,%d: add_b1_facilities %d %04x %d %04x",
  12432. (dword)((plci->Id << 8) | UnMapController (plci->adapter->Id)),
  12433. (char *)(FILE_), __LINE__,
  12434. b1_resource, b1_facilities, b, get_b1_facilities (plci, b)));
  12435. return (b);
  12436. }
  12437. static void adjust_b1_facilities (PLCI *plci, byte new_b1_resource, word new_b1_facilities)
  12438. {
  12439. word removed_facilities;
  12440. dbug (1, dprintf ("[%06lx] %s,%d: adjust_b1_facilities %d %04x %04x",
  12441. (dword)((plci->Id << 8) | UnMapController (plci->adapter->Id)),
  12442. (char *)(FILE_), __LINE__, new_b1_resource, new_b1_facilities,
  12443. new_b1_facilities & get_b1_facilities (plci, new_b1_resource)));
  12444. new_b1_facilities &= get_b1_facilities (plci, new_b1_resource);
  12445. removed_facilities = plci->B1_facilities & ~new_b1_facilities;
  12446. if (removed_facilities & B1_FACILITY_EC)
  12447. ec_clear_config (plci);
  12448. if (removed_facilities & B1_FACILITY_DTMFR)
  12449. {
  12450. dtmf_rec_clear_config (plci);
  12451. dtmf_parameter_clear_config (plci);
  12452. }
  12453. if (removed_facilities & B1_FACILITY_DTMFX)
  12454. dtmf_send_clear_config (plci);
  12455. if (removed_facilities & B1_FACILITY_MIXER)
  12456. mixer_clear_config (plci);
  12457. if (removed_facilities & B1_FACILITY_VOICE)
  12458. adv_voice_clear_config (plci);
  12459. plci->B1_facilities = new_b1_facilities;
  12460. }
  12461. static void adjust_b_clear (PLCI *plci)
  12462. {
  12463. dbug (1, dprintf ("[%06lx] %s,%d: adjust_b_clear",
  12464. (dword)((plci->Id << 8) | UnMapController (plci->adapter->Id)),
  12465. (char *)(FILE_), __LINE__));
  12466. plci->adjust_b_restore = false;
  12467. }
  12468. static word adjust_b_process (dword Id, PLCI *plci, byte Rc)
  12469. {
  12470. word Info;
  12471. byte b1_resource;
  12472. NCCI * ncci_ptr;
  12473. API_PARSE bp[2];
  12474. dbug (1, dprintf ("[%06lx] %s,%d: adjust_b_process %02x %d",
  12475. UnMapId (Id), (char *)(FILE_), __LINE__, Rc, plci->adjust_b_state));
  12476. Info = GOOD;
  12477. switch (plci->adjust_b_state)
  12478. {
  12479. case ADJUST_B_START:
  12480. if ((plci->adjust_b_parms_msg == NULL)
  12481. && (plci->adjust_b_mode & ADJUST_B_MODE_SWITCH_L1)
  12482. && ((plci->adjust_b_mode & ~(ADJUST_B_MODE_SAVE | ADJUST_B_MODE_SWITCH_L1 |
  12483. ADJUST_B_MODE_NO_RESOURCE | ADJUST_B_MODE_RESTORE)) == 0))
  12484. {
  12485. b1_resource = (plci->adjust_b_mode == ADJUST_B_MODE_NO_RESOURCE) ?
  12486. 0 : add_b1_facilities (plci, plci->B1_resource, plci->adjust_b_facilities);
  12487. if (b1_resource == plci->B1_resource)
  12488. {
  12489. adjust_b1_facilities (plci, b1_resource, plci->adjust_b_facilities);
  12490. break;
  12491. }
  12492. if (plci->adjust_b_facilities & ~get_b1_facilities (plci, b1_resource))
  12493. {
  12494. dbug (1, dprintf ("[%06lx] %s,%d: Adjust B nonsupported facilities %d %d %04x",
  12495. UnMapId (Id), (char *)(FILE_), __LINE__,
  12496. plci->B1_resource, b1_resource, plci->adjust_b_facilities));
  12497. Info = _WRONG_STATE;
  12498. break;
  12499. }
  12500. }
  12501. if (plci->adjust_b_mode & ADJUST_B_MODE_SAVE)
  12502. {
  12503. mixer_prepare_switch (Id, plci);
  12504. dtmf_prepare_switch (Id, plci);
  12505. dtmf_parameter_prepare_switch (Id, plci);
  12506. ec_prepare_switch (Id, plci);
  12507. adv_voice_prepare_switch (Id, plci);
  12508. }
  12509. plci->adjust_b_state = ADJUST_B_SAVE_MIXER_1;
  12510. Rc = OK;
  12511. case ADJUST_B_SAVE_MIXER_1:
  12512. if (plci->adjust_b_mode & ADJUST_B_MODE_SAVE)
  12513. {
  12514. Info = mixer_save_config (Id, plci, Rc);
  12515. if ((Info != GOOD) || plci->internal_command)
  12516. break;
  12517. }
  12518. plci->adjust_b_state = ADJUST_B_SAVE_DTMF_1;
  12519. Rc = OK;
  12520. case ADJUST_B_SAVE_DTMF_1:
  12521. if (plci->adjust_b_mode & ADJUST_B_MODE_SAVE)
  12522. {
  12523. Info = dtmf_save_config (Id, plci, Rc);
  12524. if ((Info != GOOD) || plci->internal_command)
  12525. break;
  12526. }
  12527. plci->adjust_b_state = ADJUST_B_REMOVE_L23_1;
  12528. case ADJUST_B_REMOVE_L23_1:
  12529. if ((plci->adjust_b_mode & ADJUST_B_MODE_REMOVE_L23)
  12530. && plci->NL.Id && !plci->nl_remove_id)
  12531. {
  12532. plci->internal_command = plci->adjust_b_command;
  12533. if (plci->adjust_b_ncci != 0)
  12534. {
  12535. ncci_ptr = &(plci->adapter->ncci[plci->adjust_b_ncci]);
  12536. while (ncci_ptr->data_pending)
  12537. {
  12538. plci->data_sent_ptr = ncci_ptr->DBuffer[ncci_ptr->data_out].P;
  12539. data_rc (plci, plci->adapter->ncci_ch[plci->adjust_b_ncci]);
  12540. }
  12541. while (ncci_ptr->data_ack_pending)
  12542. data_ack (plci, plci->adapter->ncci_ch[plci->adjust_b_ncci]);
  12543. }
  12544. nl_req_ncci (plci, REMOVE,
  12545. (byte)((plci->adjust_b_mode & ADJUST_B_MODE_CONNECT) ? plci->adjust_b_ncci : 0));
  12546. send_req (plci);
  12547. plci->adjust_b_state = ADJUST_B_REMOVE_L23_2;
  12548. break;
  12549. }
  12550. plci->adjust_b_state = ADJUST_B_REMOVE_L23_2;
  12551. Rc = OK;
  12552. case ADJUST_B_REMOVE_L23_2:
  12553. if ((Rc != OK) && (Rc != OK_FC))
  12554. {
  12555. dbug (1, dprintf ("[%06lx] %s,%d: Adjust B remove failed %02x",
  12556. UnMapId (Id), (char *)(FILE_), __LINE__, Rc));
  12557. Info = _WRONG_STATE;
  12558. break;
  12559. }
  12560. if (plci->adjust_b_mode & ADJUST_B_MODE_REMOVE_L23)
  12561. {
  12562. if (plci_nl_busy (plci))
  12563. {
  12564. plci->internal_command = plci->adjust_b_command;
  12565. break;
  12566. }
  12567. }
  12568. plci->adjust_b_state = ADJUST_B_SAVE_EC_1;
  12569. Rc = OK;
  12570. case ADJUST_B_SAVE_EC_1:
  12571. if (plci->adjust_b_mode & ADJUST_B_MODE_SAVE)
  12572. {
  12573. Info = ec_save_config (Id, plci, Rc);
  12574. if ((Info != GOOD) || plci->internal_command)
  12575. break;
  12576. }
  12577. plci->adjust_b_state = ADJUST_B_SAVE_DTMF_PARAMETER_1;
  12578. Rc = OK;
  12579. case ADJUST_B_SAVE_DTMF_PARAMETER_1:
  12580. if (plci->adjust_b_mode & ADJUST_B_MODE_SAVE)
  12581. {
  12582. Info = dtmf_parameter_save_config (Id, plci, Rc);
  12583. if ((Info != GOOD) || plci->internal_command)
  12584. break;
  12585. }
  12586. plci->adjust_b_state = ADJUST_B_SAVE_VOICE_1;
  12587. Rc = OK;
  12588. case ADJUST_B_SAVE_VOICE_1:
  12589. if (plci->adjust_b_mode & ADJUST_B_MODE_SAVE)
  12590. {
  12591. Info = adv_voice_save_config (Id, plci, Rc);
  12592. if ((Info != GOOD) || plci->internal_command)
  12593. break;
  12594. }
  12595. plci->adjust_b_state = ADJUST_B_SWITCH_L1_1;
  12596. case ADJUST_B_SWITCH_L1_1:
  12597. if (plci->adjust_b_mode & ADJUST_B_MODE_SWITCH_L1)
  12598. {
  12599. if (plci->sig_req)
  12600. {
  12601. plci->internal_command = plci->adjust_b_command;
  12602. break;
  12603. }
  12604. if (plci->adjust_b_parms_msg != NULL)
  12605. api_load_msg (plci->adjust_b_parms_msg, bp);
  12606. else
  12607. api_load_msg (&plci->B_protocol, bp);
  12608. Info = add_b1 (plci, bp,
  12609. (word)((plci->adjust_b_mode & ADJUST_B_MODE_NO_RESOURCE) ? 2 : 0),
  12610. plci->adjust_b_facilities);
  12611. if (Info != GOOD)
  12612. {
  12613. dbug (1, dprintf ("[%06lx] %s,%d: Adjust B invalid L1 parameters %d %04x",
  12614. UnMapId (Id), (char *)(FILE_), __LINE__,
  12615. plci->B1_resource, plci->adjust_b_facilities));
  12616. break;
  12617. }
  12618. plci->internal_command = plci->adjust_b_command;
  12619. sig_req (plci, RESOURCES, 0);
  12620. send_req (plci);
  12621. plci->adjust_b_state = ADJUST_B_SWITCH_L1_2;
  12622. break;
  12623. }
  12624. plci->adjust_b_state = ADJUST_B_SWITCH_L1_2;
  12625. Rc = OK;
  12626. case ADJUST_B_SWITCH_L1_2:
  12627. if ((Rc != OK) && (Rc != OK_FC))
  12628. {
  12629. dbug (1, dprintf ("[%06lx] %s,%d: Adjust B switch failed %02x %d %04x",
  12630. UnMapId (Id), (char *)(FILE_), __LINE__,
  12631. Rc, plci->B1_resource, plci->adjust_b_facilities));
  12632. Info = _WRONG_STATE;
  12633. break;
  12634. }
  12635. plci->adjust_b_state = ADJUST_B_RESTORE_VOICE_1;
  12636. Rc = OK;
  12637. case ADJUST_B_RESTORE_VOICE_1:
  12638. case ADJUST_B_RESTORE_VOICE_2:
  12639. if (plci->adjust_b_mode & ADJUST_B_MODE_RESTORE)
  12640. {
  12641. Info = adv_voice_restore_config (Id, plci, Rc);
  12642. if ((Info != GOOD) || plci->internal_command)
  12643. break;
  12644. }
  12645. plci->adjust_b_state = ADJUST_B_RESTORE_DTMF_PARAMETER_1;
  12646. Rc = OK;
  12647. case ADJUST_B_RESTORE_DTMF_PARAMETER_1:
  12648. case ADJUST_B_RESTORE_DTMF_PARAMETER_2:
  12649. if (plci->adjust_b_mode & ADJUST_B_MODE_RESTORE)
  12650. {
  12651. Info = dtmf_parameter_restore_config (Id, plci, Rc);
  12652. if ((Info != GOOD) || plci->internal_command)
  12653. break;
  12654. }
  12655. plci->adjust_b_state = ADJUST_B_RESTORE_EC_1;
  12656. Rc = OK;
  12657. case ADJUST_B_RESTORE_EC_1:
  12658. case ADJUST_B_RESTORE_EC_2:
  12659. if (plci->adjust_b_mode & ADJUST_B_MODE_RESTORE)
  12660. {
  12661. Info = ec_restore_config (Id, plci, Rc);
  12662. if ((Info != GOOD) || plci->internal_command)
  12663. break;
  12664. }
  12665. plci->adjust_b_state = ADJUST_B_ASSIGN_L23_1;
  12666. case ADJUST_B_ASSIGN_L23_1:
  12667. if (plci->adjust_b_mode & ADJUST_B_MODE_ASSIGN_L23)
  12668. {
  12669. if (plci_nl_busy (plci))
  12670. {
  12671. plci->internal_command = plci->adjust_b_command;
  12672. break;
  12673. }
  12674. if (plci->adjust_b_mode & ADJUST_B_MODE_CONNECT)
  12675. plci->call_dir |= CALL_DIR_FORCE_OUTG_NL;
  12676. if (plci->adjust_b_parms_msg != NULL)
  12677. api_load_msg (plci->adjust_b_parms_msg, bp);
  12678. else
  12679. api_load_msg (&plci->B_protocol, bp);
  12680. Info = add_b23 (plci, bp);
  12681. if (Info != GOOD)
  12682. {
  12683. dbug (1, dprintf ("[%06lx] %s,%d: Adjust B invalid L23 parameters %04x",
  12684. UnMapId (Id), (char *)(FILE_), __LINE__, Info));
  12685. break;
  12686. }
  12687. plci->internal_command = plci->adjust_b_command;
  12688. nl_req_ncci (plci, ASSIGN, 0);
  12689. send_req (plci);
  12690. plci->adjust_b_state = ADJUST_B_ASSIGN_L23_2;
  12691. break;
  12692. }
  12693. plci->adjust_b_state = ADJUST_B_ASSIGN_L23_2;
  12694. Rc = ASSIGN_OK;
  12695. case ADJUST_B_ASSIGN_L23_2:
  12696. if ((Rc != OK) && (Rc != OK_FC) && (Rc != ASSIGN_OK))
  12697. {
  12698. dbug (1, dprintf ("[%06lx] %s,%d: Adjust B assign failed %02x",
  12699. UnMapId (Id), (char *)(FILE_), __LINE__, Rc));
  12700. Info = _WRONG_STATE;
  12701. break;
  12702. }
  12703. if (plci->adjust_b_mode & ADJUST_B_MODE_ASSIGN_L23)
  12704. {
  12705. if (Rc != ASSIGN_OK)
  12706. {
  12707. plci->internal_command = plci->adjust_b_command;
  12708. break;
  12709. }
  12710. }
  12711. if (plci->adjust_b_mode & ADJUST_B_MODE_USER_CONNECT)
  12712. {
  12713. plci->adjust_b_restore = true;
  12714. break;
  12715. }
  12716. plci->adjust_b_state = ADJUST_B_CONNECT_1;
  12717. case ADJUST_B_CONNECT_1:
  12718. if (plci->adjust_b_mode & ADJUST_B_MODE_CONNECT)
  12719. {
  12720. plci->internal_command = plci->adjust_b_command;
  12721. if (plci_nl_busy (plci))
  12722. break;
  12723. nl_req_ncci (plci, N_CONNECT, 0);
  12724. send_req (plci);
  12725. plci->adjust_b_state = ADJUST_B_CONNECT_2;
  12726. break;
  12727. }
  12728. plci->adjust_b_state = ADJUST_B_RESTORE_DTMF_1;
  12729. Rc = OK;
  12730. case ADJUST_B_CONNECT_2:
  12731. case ADJUST_B_CONNECT_3:
  12732. case ADJUST_B_CONNECT_4:
  12733. if ((Rc != OK) && (Rc != OK_FC) && (Rc != 0))
  12734. {
  12735. dbug (1, dprintf ("[%06lx] %s,%d: Adjust B connect failed %02x",
  12736. UnMapId (Id), (char *)(FILE_), __LINE__, Rc));
  12737. Info = _WRONG_STATE;
  12738. break;
  12739. }
  12740. if (Rc == OK)
  12741. {
  12742. if (plci->adjust_b_mode & ADJUST_B_MODE_CONNECT)
  12743. {
  12744. get_ncci (plci, (byte)(Id >> 16), plci->adjust_b_ncci);
  12745. Id = (Id & 0xffff) | (((dword)(plci->adjust_b_ncci)) << 16);
  12746. }
  12747. if (plci->adjust_b_state == ADJUST_B_CONNECT_2)
  12748. plci->adjust_b_state = ADJUST_B_CONNECT_3;
  12749. else if (plci->adjust_b_state == ADJUST_B_CONNECT_4)
  12750. plci->adjust_b_state = ADJUST_B_RESTORE_DTMF_1;
  12751. }
  12752. else if (Rc == 0)
  12753. {
  12754. if (plci->adjust_b_state == ADJUST_B_CONNECT_2)
  12755. plci->adjust_b_state = ADJUST_B_CONNECT_4;
  12756. else if (plci->adjust_b_state == ADJUST_B_CONNECT_3)
  12757. plci->adjust_b_state = ADJUST_B_RESTORE_DTMF_1;
  12758. }
  12759. if (plci->adjust_b_state != ADJUST_B_RESTORE_DTMF_1)
  12760. {
  12761. plci->internal_command = plci->adjust_b_command;
  12762. break;
  12763. }
  12764. Rc = OK;
  12765. case ADJUST_B_RESTORE_DTMF_1:
  12766. case ADJUST_B_RESTORE_DTMF_2:
  12767. if (plci->adjust_b_mode & ADJUST_B_MODE_RESTORE)
  12768. {
  12769. Info = dtmf_restore_config (Id, plci, Rc);
  12770. if ((Info != GOOD) || plci->internal_command)
  12771. break;
  12772. }
  12773. plci->adjust_b_state = ADJUST_B_RESTORE_MIXER_1;
  12774. Rc = OK;
  12775. case ADJUST_B_RESTORE_MIXER_1:
  12776. case ADJUST_B_RESTORE_MIXER_2:
  12777. case ADJUST_B_RESTORE_MIXER_3:
  12778. case ADJUST_B_RESTORE_MIXER_4:
  12779. case ADJUST_B_RESTORE_MIXER_5:
  12780. case ADJUST_B_RESTORE_MIXER_6:
  12781. case ADJUST_B_RESTORE_MIXER_7:
  12782. if (plci->adjust_b_mode & ADJUST_B_MODE_RESTORE)
  12783. {
  12784. Info = mixer_restore_config (Id, plci, Rc);
  12785. if ((Info != GOOD) || plci->internal_command)
  12786. break;
  12787. }
  12788. plci->adjust_b_state = ADJUST_B_END;
  12789. case ADJUST_B_END:
  12790. break;
  12791. }
  12792. return (Info);
  12793. }
  12794. static void adjust_b1_resource (dword Id, PLCI *plci, API_SAVE *bp_msg, word b1_facilities, word internal_command)
  12795. {
  12796. dbug (1, dprintf ("[%06lx] %s,%d: adjust_b1_resource %d %04x",
  12797. UnMapId (Id), (char *)(FILE_), __LINE__,
  12798. plci->B1_resource, b1_facilities));
  12799. plci->adjust_b_parms_msg = bp_msg;
  12800. plci->adjust_b_facilities = b1_facilities;
  12801. plci->adjust_b_command = internal_command;
  12802. plci->adjust_b_ncci = (word)(Id >> 16);
  12803. if ((bp_msg == NULL) && (plci->B1_resource == 0))
  12804. plci->adjust_b_mode = ADJUST_B_MODE_SAVE | ADJUST_B_MODE_NO_RESOURCE | ADJUST_B_MODE_SWITCH_L1;
  12805. else
  12806. plci->adjust_b_mode = ADJUST_B_MODE_SAVE | ADJUST_B_MODE_SWITCH_L1 | ADJUST_B_MODE_RESTORE;
  12807. plci->adjust_b_state = ADJUST_B_START;
  12808. dbug (1, dprintf ("[%06lx] %s,%d: Adjust B1 resource %d %04x...",
  12809. UnMapId (Id), (char *)(FILE_), __LINE__,
  12810. plci->B1_resource, b1_facilities));
  12811. }
  12812. static void adjust_b_restore (dword Id, PLCI *plci, byte Rc)
  12813. {
  12814. word internal_command;
  12815. dbug (1, dprintf ("[%06lx] %s,%d: adjust_b_restore %02x %04x",
  12816. UnMapId (Id), (char *)(FILE_), __LINE__, Rc, plci->internal_command));
  12817. internal_command = plci->internal_command;
  12818. plci->internal_command = 0;
  12819. switch (internal_command)
  12820. {
  12821. default:
  12822. plci->command = 0;
  12823. if (plci->req_in != 0)
  12824. {
  12825. plci->internal_command = ADJUST_B_RESTORE_1;
  12826. break;
  12827. }
  12828. Rc = OK;
  12829. case ADJUST_B_RESTORE_1:
  12830. if ((Rc != OK) && (Rc != OK_FC))
  12831. {
  12832. dbug (1, dprintf ("[%06lx] %s,%d: Adjust B enqueued failed %02x",
  12833. UnMapId (Id), (char *)(FILE_), __LINE__, Rc));
  12834. }
  12835. plci->adjust_b_parms_msg = NULL;
  12836. plci->adjust_b_facilities = plci->B1_facilities;
  12837. plci->adjust_b_command = ADJUST_B_RESTORE_2;
  12838. plci->adjust_b_ncci = (word)(Id >> 16);
  12839. plci->adjust_b_mode = ADJUST_B_MODE_RESTORE;
  12840. plci->adjust_b_state = ADJUST_B_START;
  12841. dbug (1, dprintf ("[%06lx] %s,%d: Adjust B restore...",
  12842. UnMapId (Id), (char *)(FILE_), __LINE__));
  12843. case ADJUST_B_RESTORE_2:
  12844. if (adjust_b_process (Id, plci, Rc) != GOOD)
  12845. {
  12846. dbug (1, dprintf ("[%06lx] %s,%d: Adjust B restore failed",
  12847. UnMapId (Id), (char *)(FILE_), __LINE__));
  12848. }
  12849. if (plci->internal_command)
  12850. break;
  12851. break;
  12852. }
  12853. }
  12854. static void reset_b3_command (dword Id, PLCI *plci, byte Rc)
  12855. {
  12856. word Info;
  12857. word internal_command;
  12858. dbug (1, dprintf ("[%06lx] %s,%d: reset_b3_command %02x %04x",
  12859. UnMapId (Id), (char *)(FILE_), __LINE__, Rc, plci->internal_command));
  12860. Info = GOOD;
  12861. internal_command = plci->internal_command;
  12862. plci->internal_command = 0;
  12863. switch (internal_command)
  12864. {
  12865. default:
  12866. plci->command = 0;
  12867. plci->adjust_b_parms_msg = NULL;
  12868. plci->adjust_b_facilities = plci->B1_facilities;
  12869. plci->adjust_b_command = RESET_B3_COMMAND_1;
  12870. plci->adjust_b_ncci = (word)(Id >> 16);
  12871. plci->adjust_b_mode = ADJUST_B_MODE_REMOVE_L23 | ADJUST_B_MODE_ASSIGN_L23 | ADJUST_B_MODE_CONNECT;
  12872. plci->adjust_b_state = ADJUST_B_START;
  12873. dbug (1, dprintf ("[%06lx] %s,%d: Reset B3...",
  12874. UnMapId (Id), (char *)(FILE_), __LINE__));
  12875. case RESET_B3_COMMAND_1:
  12876. Info = adjust_b_process (Id, plci, Rc);
  12877. if (Info != GOOD)
  12878. {
  12879. dbug (1, dprintf ("[%06lx] %s,%d: Reset failed",
  12880. UnMapId (Id), (char *)(FILE_), __LINE__));
  12881. break;
  12882. }
  12883. if (plci->internal_command)
  12884. return;
  12885. break;
  12886. }
  12887. /* sendf (plci->appl, _RESET_B3_R | CONFIRM, Id, plci->number, "w", Info);*/
  12888. sendf(plci->appl,_RESET_B3_I,Id,0,"s","");
  12889. }
  12890. static void select_b_command (dword Id, PLCI *plci, byte Rc)
  12891. {
  12892. word Info;
  12893. word internal_command;
  12894. byte esc_chi[3];
  12895. dbug (1, dprintf ("[%06lx] %s,%d: select_b_command %02x %04x",
  12896. UnMapId (Id), (char *)(FILE_), __LINE__, Rc, plci->internal_command));
  12897. Info = GOOD;
  12898. internal_command = plci->internal_command;
  12899. plci->internal_command = 0;
  12900. switch (internal_command)
  12901. {
  12902. default:
  12903. plci->command = 0;
  12904. plci->adjust_b_parms_msg = &plci->saved_msg;
  12905. if ((plci->tel == ADV_VOICE) && (plci == plci->adapter->AdvSignalPLCI))
  12906. plci->adjust_b_facilities = plci->B1_facilities | B1_FACILITY_VOICE;
  12907. else
  12908. plci->adjust_b_facilities = plci->B1_facilities & ~B1_FACILITY_VOICE;
  12909. plci->adjust_b_command = SELECT_B_COMMAND_1;
  12910. plci->adjust_b_ncci = (word)(Id >> 16);
  12911. if (plci->saved_msg.parms[0].length == 0)
  12912. {
  12913. plci->adjust_b_mode = ADJUST_B_MODE_SAVE | ADJUST_B_MODE_REMOVE_L23 | ADJUST_B_MODE_SWITCH_L1 |
  12914. ADJUST_B_MODE_NO_RESOURCE;
  12915. }
  12916. else
  12917. {
  12918. plci->adjust_b_mode = ADJUST_B_MODE_SAVE | ADJUST_B_MODE_REMOVE_L23 | ADJUST_B_MODE_SWITCH_L1 |
  12919. ADJUST_B_MODE_ASSIGN_L23 | ADJUST_B_MODE_USER_CONNECT | ADJUST_B_MODE_RESTORE;
  12920. }
  12921. plci->adjust_b_state = ADJUST_B_START;
  12922. dbug (1, dprintf ("[%06lx] %s,%d: Select B protocol...",
  12923. UnMapId (Id), (char *)(FILE_), __LINE__));
  12924. case SELECT_B_COMMAND_1:
  12925. Info = adjust_b_process (Id, plci, Rc);
  12926. if (Info != GOOD)
  12927. {
  12928. dbug (1, dprintf ("[%06lx] %s,%d: Select B protocol failed",
  12929. UnMapId (Id), (char *)(FILE_), __LINE__));
  12930. break;
  12931. }
  12932. if (plci->internal_command)
  12933. return;
  12934. if (plci->tel == ADV_VOICE)
  12935. {
  12936. esc_chi[0] = 0x02;
  12937. esc_chi[1] = 0x18;
  12938. esc_chi[2] = plci->b_channel;
  12939. SetVoiceChannel (plci->adapter->AdvCodecPLCI, esc_chi, plci->adapter);
  12940. }
  12941. break;
  12942. }
  12943. sendf (plci->appl, _SELECT_B_REQ | CONFIRM, Id, plci->number, "w", Info);
  12944. }
  12945. static void fax_connect_ack_command (dword Id, PLCI *plci, byte Rc)
  12946. {
  12947. word Info;
  12948. word internal_command;
  12949. dbug (1, dprintf ("[%06lx] %s,%d: fax_connect_ack_command %02x %04x",
  12950. UnMapId (Id), (char *)(FILE_), __LINE__, Rc, plci->internal_command));
  12951. Info = GOOD;
  12952. internal_command = plci->internal_command;
  12953. plci->internal_command = 0;
  12954. switch (internal_command)
  12955. {
  12956. default:
  12957. plci->command = 0;
  12958. case FAX_CONNECT_ACK_COMMAND_1:
  12959. if (plci_nl_busy (plci))
  12960. {
  12961. plci->internal_command = FAX_CONNECT_ACK_COMMAND_1;
  12962. return;
  12963. }
  12964. plci->internal_command = FAX_CONNECT_ACK_COMMAND_2;
  12965. plci->NData[0].P = plci->fax_connect_info_buffer;
  12966. plci->NData[0].PLength = plci->fax_connect_info_length;
  12967. plci->NL.X = plci->NData;
  12968. plci->NL.ReqCh = 0;
  12969. plci->NL.Req = plci->nl_req = (byte) N_CONNECT_ACK;
  12970. plci->adapter->request (&plci->NL);
  12971. return;
  12972. case FAX_CONNECT_ACK_COMMAND_2:
  12973. if ((Rc != OK) && (Rc != OK_FC))
  12974. {
  12975. dbug (1, dprintf ("[%06lx] %s,%d: FAX issue CONNECT ACK failed %02x",
  12976. UnMapId (Id), (char *)(FILE_), __LINE__, Rc));
  12977. break;
  12978. }
  12979. }
  12980. if ((plci->ncpi_state & NCPI_VALID_CONNECT_B3_ACT)
  12981. && !(plci->ncpi_state & NCPI_CONNECT_B3_ACT_SENT))
  12982. {
  12983. if (plci->B3_prot == 4)
  12984. sendf(plci->appl,_CONNECT_B3_ACTIVE_I,Id,0,"s","");
  12985. else
  12986. sendf(plci->appl,_CONNECT_B3_ACTIVE_I,Id,0,"S",plci->ncpi_buffer);
  12987. plci->ncpi_state |= NCPI_CONNECT_B3_ACT_SENT;
  12988. }
  12989. }
  12990. static void fax_edata_ack_command (dword Id, PLCI *plci, byte Rc)
  12991. {
  12992. word Info;
  12993. word internal_command;
  12994. dbug (1, dprintf ("[%06lx] %s,%d: fax_edata_ack_command %02x %04x",
  12995. UnMapId (Id), (char *)(FILE_), __LINE__, Rc, plci->internal_command));
  12996. Info = GOOD;
  12997. internal_command = plci->internal_command;
  12998. plci->internal_command = 0;
  12999. switch (internal_command)
  13000. {
  13001. default:
  13002. plci->command = 0;
  13003. case FAX_EDATA_ACK_COMMAND_1:
  13004. if (plci_nl_busy (plci))
  13005. {
  13006. plci->internal_command = FAX_EDATA_ACK_COMMAND_1;
  13007. return;
  13008. }
  13009. plci->internal_command = FAX_EDATA_ACK_COMMAND_2;
  13010. plci->NData[0].P = plci->fax_connect_info_buffer;
  13011. plci->NData[0].PLength = plci->fax_edata_ack_length;
  13012. plci->NL.X = plci->NData;
  13013. plci->NL.ReqCh = 0;
  13014. plci->NL.Req = plci->nl_req = (byte) N_EDATA;
  13015. plci->adapter->request (&plci->NL);
  13016. return;
  13017. case FAX_EDATA_ACK_COMMAND_2:
  13018. if ((Rc != OK) && (Rc != OK_FC))
  13019. {
  13020. dbug (1, dprintf ("[%06lx] %s,%d: FAX issue EDATA ACK failed %02x",
  13021. UnMapId (Id), (char *)(FILE_), __LINE__, Rc));
  13022. break;
  13023. }
  13024. }
  13025. }
  13026. static void fax_connect_info_command (dword Id, PLCI *plci, byte Rc)
  13027. {
  13028. word Info;
  13029. word internal_command;
  13030. dbug (1, dprintf ("[%06lx] %s,%d: fax_connect_info_command %02x %04x",
  13031. UnMapId (Id), (char *)(FILE_), __LINE__, Rc, plci->internal_command));
  13032. Info = GOOD;
  13033. internal_command = plci->internal_command;
  13034. plci->internal_command = 0;
  13035. switch (internal_command)
  13036. {
  13037. default:
  13038. plci->command = 0;
  13039. case FAX_CONNECT_INFO_COMMAND_1:
  13040. if (plci_nl_busy (plci))
  13041. {
  13042. plci->internal_command = FAX_CONNECT_INFO_COMMAND_1;
  13043. return;
  13044. }
  13045. plci->internal_command = FAX_CONNECT_INFO_COMMAND_2;
  13046. plci->NData[0].P = plci->fax_connect_info_buffer;
  13047. plci->NData[0].PLength = plci->fax_connect_info_length;
  13048. plci->NL.X = plci->NData;
  13049. plci->NL.ReqCh = 0;
  13050. plci->NL.Req = plci->nl_req = (byte) N_EDATA;
  13051. plci->adapter->request (&plci->NL);
  13052. return;
  13053. case FAX_CONNECT_INFO_COMMAND_2:
  13054. if ((Rc != OK) && (Rc != OK_FC))
  13055. {
  13056. dbug (1, dprintf ("[%06lx] %s,%d: FAX setting connect info failed %02x",
  13057. UnMapId (Id), (char *)(FILE_), __LINE__, Rc));
  13058. Info = _WRONG_STATE;
  13059. break;
  13060. }
  13061. if (plci_nl_busy (plci))
  13062. {
  13063. plci->internal_command = FAX_CONNECT_INFO_COMMAND_2;
  13064. return;
  13065. }
  13066. plci->command = _CONNECT_B3_R;
  13067. nl_req_ncci (plci, N_CONNECT, 0);
  13068. send_req (plci);
  13069. return;
  13070. }
  13071. sendf (plci->appl, _CONNECT_B3_R | CONFIRM, Id, plci->number, "w", Info);
  13072. }
  13073. static void fax_adjust_b23_command (dword Id, PLCI *plci, byte Rc)
  13074. {
  13075. word Info;
  13076. word internal_command;
  13077. dbug (1, dprintf ("[%06lx] %s,%d: fax_adjust_b23_command %02x %04x",
  13078. UnMapId (Id), (char *)(FILE_), __LINE__, Rc, plci->internal_command));
  13079. Info = GOOD;
  13080. internal_command = plci->internal_command;
  13081. plci->internal_command = 0;
  13082. switch (internal_command)
  13083. {
  13084. default:
  13085. plci->command = 0;
  13086. plci->adjust_b_parms_msg = NULL;
  13087. plci->adjust_b_facilities = plci->B1_facilities;
  13088. plci->adjust_b_command = FAX_ADJUST_B23_COMMAND_1;
  13089. plci->adjust_b_ncci = (word)(Id >> 16);
  13090. plci->adjust_b_mode = ADJUST_B_MODE_REMOVE_L23 | ADJUST_B_MODE_ASSIGN_L23;
  13091. plci->adjust_b_state = ADJUST_B_START;
  13092. dbug (1, dprintf ("[%06lx] %s,%d: FAX adjust B23...",
  13093. UnMapId (Id), (char *)(FILE_), __LINE__));
  13094. case FAX_ADJUST_B23_COMMAND_1:
  13095. Info = adjust_b_process (Id, plci, Rc);
  13096. if (Info != GOOD)
  13097. {
  13098. dbug (1, dprintf ("[%06lx] %s,%d: FAX adjust failed",
  13099. UnMapId (Id), (char *)(FILE_), __LINE__));
  13100. break;
  13101. }
  13102. if (plci->internal_command)
  13103. return;
  13104. case FAX_ADJUST_B23_COMMAND_2:
  13105. if (plci_nl_busy (plci))
  13106. {
  13107. plci->internal_command = FAX_ADJUST_B23_COMMAND_2;
  13108. return;
  13109. }
  13110. plci->command = _CONNECT_B3_R;
  13111. nl_req_ncci (plci, N_CONNECT, 0);
  13112. send_req (plci);
  13113. return;
  13114. }
  13115. sendf (plci->appl, _CONNECT_B3_R | CONFIRM, Id, plci->number, "w", Info);
  13116. }
  13117. static void fax_disconnect_command (dword Id, PLCI *plci, byte Rc)
  13118. {
  13119. word internal_command;
  13120. dbug (1, dprintf ("[%06lx] %s,%d: fax_disconnect_command %02x %04x",
  13121. UnMapId (Id), (char *)(FILE_), __LINE__, Rc, plci->internal_command));
  13122. internal_command = plci->internal_command;
  13123. plci->internal_command = 0;
  13124. switch (internal_command)
  13125. {
  13126. default:
  13127. plci->command = 0;
  13128. plci->internal_command = FAX_DISCONNECT_COMMAND_1;
  13129. return;
  13130. case FAX_DISCONNECT_COMMAND_1:
  13131. case FAX_DISCONNECT_COMMAND_2:
  13132. case FAX_DISCONNECT_COMMAND_3:
  13133. if ((Rc != OK) && (Rc != OK_FC) && (Rc != 0))
  13134. {
  13135. dbug (1, dprintf ("[%06lx] %s,%d: FAX disconnect EDATA failed %02x",
  13136. UnMapId (Id), (char *)(FILE_), __LINE__, Rc));
  13137. break;
  13138. }
  13139. if (Rc == OK)
  13140. {
  13141. if ((internal_command == FAX_DISCONNECT_COMMAND_1)
  13142. || (internal_command == FAX_DISCONNECT_COMMAND_2))
  13143. {
  13144. plci->internal_command = FAX_DISCONNECT_COMMAND_2;
  13145. }
  13146. }
  13147. else if (Rc == 0)
  13148. {
  13149. if (internal_command == FAX_DISCONNECT_COMMAND_1)
  13150. plci->internal_command = FAX_DISCONNECT_COMMAND_3;
  13151. }
  13152. return;
  13153. }
  13154. }
  13155. static void rtp_connect_b3_req_command (dword Id, PLCI *plci, byte Rc)
  13156. {
  13157. word Info;
  13158. word internal_command;
  13159. dbug (1, dprintf ("[%06lx] %s,%d: rtp_connect_b3_req_command %02x %04x",
  13160. UnMapId (Id), (char *)(FILE_), __LINE__, Rc, plci->internal_command));
  13161. Info = GOOD;
  13162. internal_command = plci->internal_command;
  13163. plci->internal_command = 0;
  13164. switch (internal_command)
  13165. {
  13166. default:
  13167. plci->command = 0;
  13168. case RTP_CONNECT_B3_REQ_COMMAND_1:
  13169. if (plci_nl_busy (plci))
  13170. {
  13171. plci->internal_command = RTP_CONNECT_B3_REQ_COMMAND_1;
  13172. return;
  13173. }
  13174. plci->internal_command = RTP_CONNECT_B3_REQ_COMMAND_2;
  13175. nl_req_ncci (plci, N_CONNECT, 0);
  13176. send_req (plci);
  13177. return;
  13178. case RTP_CONNECT_B3_REQ_COMMAND_2:
  13179. if ((Rc != OK) && (Rc != OK_FC))
  13180. {
  13181. dbug (1, dprintf ("[%06lx] %s,%d: RTP setting connect info failed %02x",
  13182. UnMapId (Id), (char *)(FILE_), __LINE__, Rc));
  13183. Info = _WRONG_STATE;
  13184. break;
  13185. }
  13186. if (plci_nl_busy (plci))
  13187. {
  13188. plci->internal_command = RTP_CONNECT_B3_REQ_COMMAND_2;
  13189. return;
  13190. }
  13191. plci->internal_command = RTP_CONNECT_B3_REQ_COMMAND_3;
  13192. plci->NData[0].PLength = plci->internal_req_buffer[0];
  13193. plci->NData[0].P = plci->internal_req_buffer + 1;
  13194. plci->NL.X = plci->NData;
  13195. plci->NL.ReqCh = 0;
  13196. plci->NL.Req = plci->nl_req = (byte) N_UDATA;
  13197. plci->adapter->request (&plci->NL);
  13198. break;
  13199. case RTP_CONNECT_B3_REQ_COMMAND_3:
  13200. return;
  13201. }
  13202. sendf (plci->appl, _CONNECT_B3_R | CONFIRM, Id, plci->number, "w", Info);
  13203. }
  13204. static void rtp_connect_b3_res_command (dword Id, PLCI *plci, byte Rc)
  13205. {
  13206. word Info;
  13207. word internal_command;
  13208. dbug (1, dprintf ("[%06lx] %s,%d: rtp_connect_b3_res_command %02x %04x",
  13209. UnMapId (Id), (char *)(FILE_), __LINE__, Rc, plci->internal_command));
  13210. Info = GOOD;
  13211. internal_command = plci->internal_command;
  13212. plci->internal_command = 0;
  13213. switch (internal_command)
  13214. {
  13215. default:
  13216. plci->command = 0;
  13217. case RTP_CONNECT_B3_RES_COMMAND_1:
  13218. if (plci_nl_busy (plci))
  13219. {
  13220. plci->internal_command = RTP_CONNECT_B3_RES_COMMAND_1;
  13221. return;
  13222. }
  13223. plci->internal_command = RTP_CONNECT_B3_RES_COMMAND_2;
  13224. nl_req_ncci (plci, N_CONNECT_ACK, (byte)(Id >> 16));
  13225. send_req (plci);
  13226. return;
  13227. case RTP_CONNECT_B3_RES_COMMAND_2:
  13228. if ((Rc != OK) && (Rc != OK_FC))
  13229. {
  13230. dbug (1, dprintf ("[%06lx] %s,%d: RTP setting connect resp info failed %02x",
  13231. UnMapId (Id), (char *)(FILE_), __LINE__, Rc));
  13232. Info = _WRONG_STATE;
  13233. break;
  13234. }
  13235. if (plci_nl_busy (plci))
  13236. {
  13237. plci->internal_command = RTP_CONNECT_B3_RES_COMMAND_2;
  13238. return;
  13239. }
  13240. sendf (plci->appl, _CONNECT_B3_ACTIVE_I, Id, 0, "s", "");
  13241. plci->internal_command = RTP_CONNECT_B3_RES_COMMAND_3;
  13242. plci->NData[0].PLength = plci->internal_req_buffer[0];
  13243. plci->NData[0].P = plci->internal_req_buffer + 1;
  13244. plci->NL.X = plci->NData;
  13245. plci->NL.ReqCh = 0;
  13246. plci->NL.Req = plci->nl_req = (byte) N_UDATA;
  13247. plci->adapter->request (&plci->NL);
  13248. return;
  13249. case RTP_CONNECT_B3_RES_COMMAND_3:
  13250. return;
  13251. }
  13252. }
  13253. static void hold_save_command (dword Id, PLCI *plci, byte Rc)
  13254. {
  13255. byte SS_Ind[] = "\x05\x02\x00\x02\x00\x00"; /* Hold_Ind struct*/
  13256. word Info;
  13257. word internal_command;
  13258. dbug (1, dprintf ("[%06lx] %s,%d: hold_save_command %02x %04x",
  13259. UnMapId (Id), (char *)(FILE_), __LINE__, Rc, plci->internal_command));
  13260. Info = GOOD;
  13261. internal_command = plci->internal_command;
  13262. plci->internal_command = 0;
  13263. switch (internal_command)
  13264. {
  13265. default:
  13266. if (!plci->NL.Id)
  13267. break;
  13268. plci->command = 0;
  13269. plci->adjust_b_parms_msg = NULL;
  13270. plci->adjust_b_facilities = plci->B1_facilities;
  13271. plci->adjust_b_command = HOLD_SAVE_COMMAND_1;
  13272. plci->adjust_b_ncci = (word)(Id >> 16);
  13273. plci->adjust_b_mode = ADJUST_B_MODE_SAVE | ADJUST_B_MODE_REMOVE_L23;
  13274. plci->adjust_b_state = ADJUST_B_START;
  13275. dbug (1, dprintf ("[%06lx] %s,%d: HOLD save...",
  13276. UnMapId (Id), (char *)(FILE_), __LINE__));
  13277. case HOLD_SAVE_COMMAND_1:
  13278. Info = adjust_b_process (Id, plci, Rc);
  13279. if (Info != GOOD)
  13280. {
  13281. dbug (1, dprintf ("[%06lx] %s,%d: HOLD save failed",
  13282. UnMapId (Id), (char *)(FILE_), __LINE__));
  13283. break;
  13284. }
  13285. if (plci->internal_command)
  13286. return;
  13287. }
  13288. sendf (plci->appl, _FACILITY_I, Id & 0xffffL, 0, "ws", 3, SS_Ind);
  13289. }
  13290. static void retrieve_restore_command (dword Id, PLCI *plci, byte Rc)
  13291. {
  13292. byte SS_Ind[] = "\x05\x03\x00\x02\x00\x00"; /* Retrieve_Ind struct*/
  13293. word Info;
  13294. word internal_command;
  13295. dbug (1, dprintf ("[%06lx] %s,%d: retrieve_restore_command %02x %04x",
  13296. UnMapId (Id), (char *)(FILE_), __LINE__, Rc, plci->internal_command));
  13297. Info = GOOD;
  13298. internal_command = plci->internal_command;
  13299. plci->internal_command = 0;
  13300. switch (internal_command)
  13301. {
  13302. default:
  13303. plci->command = 0;
  13304. plci->adjust_b_parms_msg = NULL;
  13305. plci->adjust_b_facilities = plci->B1_facilities;
  13306. plci->adjust_b_command = RETRIEVE_RESTORE_COMMAND_1;
  13307. plci->adjust_b_ncci = (word)(Id >> 16);
  13308. plci->adjust_b_mode = ADJUST_B_MODE_ASSIGN_L23 | ADJUST_B_MODE_USER_CONNECT | ADJUST_B_MODE_RESTORE;
  13309. plci->adjust_b_state = ADJUST_B_START;
  13310. dbug (1, dprintf ("[%06lx] %s,%d: RETRIEVE restore...",
  13311. UnMapId (Id), (char *)(FILE_), __LINE__));
  13312. case RETRIEVE_RESTORE_COMMAND_1:
  13313. Info = adjust_b_process (Id, plci, Rc);
  13314. if (Info != GOOD)
  13315. {
  13316. dbug (1, dprintf ("[%06lx] %s,%d: RETRIEVE restore failed",
  13317. UnMapId (Id), (char *)(FILE_), __LINE__));
  13318. break;
  13319. }
  13320. if (plci->internal_command)
  13321. return;
  13322. }
  13323. sendf (plci->appl, _FACILITY_I, Id & 0xffffL, 0, "ws", 3, SS_Ind);
  13324. }
  13325. static void init_b1_config (PLCI *plci)
  13326. {
  13327. dbug (1, dprintf ("[%06lx] %s,%d: init_b1_config",
  13328. (dword)((plci->Id << 8) | UnMapController (plci->adapter->Id)),
  13329. (char *)(FILE_), __LINE__));
  13330. plci->B1_resource = 0;
  13331. plci->B1_facilities = 0;
  13332. plci->li_bchannel_id = 0;
  13333. mixer_clear_config (plci);
  13334. ec_clear_config (plci);
  13335. dtmf_rec_clear_config (plci);
  13336. dtmf_send_clear_config (plci);
  13337. dtmf_parameter_clear_config (plci);
  13338. adv_voice_clear_config (plci);
  13339. adjust_b_clear (plci);
  13340. }
  13341. static void clear_b1_config (PLCI *plci)
  13342. {
  13343. dbug (1, dprintf ("[%06lx] %s,%d: clear_b1_config",
  13344. (dword)((plci->Id << 8) | UnMapController (plci->adapter->Id)),
  13345. (char *)(FILE_), __LINE__));
  13346. adv_voice_clear_config (plci);
  13347. adjust_b_clear (plci);
  13348. ec_clear_config (plci);
  13349. dtmf_rec_clear_config (plci);
  13350. dtmf_send_clear_config (plci);
  13351. dtmf_parameter_clear_config (plci);
  13352. if ((plci->li_bchannel_id != 0)
  13353. && (li_config_table[plci->adapter->li_base + (plci->li_bchannel_id - 1)].plci == plci))
  13354. {
  13355. mixer_clear_config (plci);
  13356. li_config_table[plci->adapter->li_base + (plci->li_bchannel_id - 1)].plci = NULL;
  13357. plci->li_bchannel_id = 0;
  13358. }
  13359. plci->B1_resource = 0;
  13360. plci->B1_facilities = 0;
  13361. }
  13362. /* -----------------------------------------------------------------
  13363. XON protocol local helpers
  13364. ----------------------------------------------------------------- */
  13365. static void channel_flow_control_remove (PLCI * plci) {
  13366. DIVA_CAPI_ADAPTER * a = plci->adapter;
  13367. word i;
  13368. for(i=1;i<MAX_NL_CHANNEL+1;i++) {
  13369. if (a->ch_flow_plci[i] == plci->Id) {
  13370. a->ch_flow_plci[i] = 0;
  13371. a->ch_flow_control[i] = 0;
  13372. }
  13373. }
  13374. }
  13375. static void channel_x_on (PLCI * plci, byte ch) {
  13376. DIVA_CAPI_ADAPTER * a = plci->adapter;
  13377. if (a->ch_flow_control[ch] & N_XON_SENT) {
  13378. a->ch_flow_control[ch] &= ~N_XON_SENT;
  13379. }
  13380. }
  13381. static void channel_x_off (PLCI * plci, byte ch, byte flag) {
  13382. DIVA_CAPI_ADAPTER * a = plci->adapter;
  13383. if ((a->ch_flow_control[ch] & N_RX_FLOW_CONTROL_MASK) == 0) {
  13384. a->ch_flow_control[ch] |= (N_CH_XOFF | flag);
  13385. a->ch_flow_plci[ch] = plci->Id;
  13386. a->ch_flow_control_pending++;
  13387. }
  13388. }
  13389. static void channel_request_xon (PLCI * plci, byte ch) {
  13390. DIVA_CAPI_ADAPTER * a = plci->adapter;
  13391. if (a->ch_flow_control[ch] & N_CH_XOFF) {
  13392. a->ch_flow_control[ch] |= N_XON_REQ;
  13393. a->ch_flow_control[ch] &= ~N_CH_XOFF;
  13394. a->ch_flow_control[ch] &= ~N_XON_CONNECT_IND;
  13395. }
  13396. }
  13397. static void channel_xmit_extended_xon (PLCI * plci) {
  13398. DIVA_CAPI_ADAPTER * a;
  13399. int max_ch = ARRAY_SIZE(a->ch_flow_control);
  13400. int i, one_requested = 0;
  13401. if ((!plci) || (!plci->Id) || ((a = plci->adapter) == NULL)) {
  13402. return;
  13403. }
  13404. for (i = 0; i < max_ch; i++) {
  13405. if ((a->ch_flow_control[i] & N_CH_XOFF) &&
  13406. (a->ch_flow_control[i] & N_XON_CONNECT_IND) &&
  13407. (plci->Id == a->ch_flow_plci[i])) {
  13408. channel_request_xon (plci, (byte)i);
  13409. one_requested = 1;
  13410. }
  13411. }
  13412. if (one_requested) {
  13413. channel_xmit_xon (plci);
  13414. }
  13415. }
  13416. /*
  13417. Try to xmit next X_ON
  13418. */
  13419. static int find_channel_with_pending_x_on (DIVA_CAPI_ADAPTER * a, PLCI * plci) {
  13420. int max_ch = ARRAY_SIZE(a->ch_flow_control);
  13421. int i;
  13422. if (!(plci->adapter->manufacturer_features & MANUFACTURER_FEATURE_XONOFF_FLOW_CONTROL)) {
  13423. return (0);
  13424. }
  13425. if (a->last_flow_control_ch >= max_ch) {
  13426. a->last_flow_control_ch = 1;
  13427. }
  13428. for (i=a->last_flow_control_ch; i < max_ch; i++) {
  13429. if ((a->ch_flow_control[i] & N_XON_REQ) &&
  13430. (plci->Id == a->ch_flow_plci[i])) {
  13431. a->last_flow_control_ch = i+1;
  13432. return (i);
  13433. }
  13434. }
  13435. for (i = 1; i < a->last_flow_control_ch; i++) {
  13436. if ((a->ch_flow_control[i] & N_XON_REQ) &&
  13437. (plci->Id == a->ch_flow_plci[i])) {
  13438. a->last_flow_control_ch = i+1;
  13439. return (i);
  13440. }
  13441. }
  13442. return (0);
  13443. }
  13444. static void channel_xmit_xon (PLCI * plci) {
  13445. DIVA_CAPI_ADAPTER * a = plci->adapter;
  13446. byte ch;
  13447. if (plci->nl_req || !plci->NL.Id || plci->nl_remove_id) {
  13448. return;
  13449. }
  13450. if ((ch = (byte)find_channel_with_pending_x_on (a, plci)) == 0) {
  13451. return;
  13452. }
  13453. a->ch_flow_control[ch] &= ~N_XON_REQ;
  13454. a->ch_flow_control[ch] |= N_XON_SENT;
  13455. plci->NL.Req = plci->nl_req = (byte)N_XON;
  13456. plci->NL.ReqCh = ch;
  13457. plci->NL.X = plci->NData;
  13458. plci->NL.XNum = 1;
  13459. plci->NData[0].P = &plci->RBuffer[0];
  13460. plci->NData[0].PLength = 0;
  13461. plci->adapter->request(&plci->NL);
  13462. }
  13463. static int channel_can_xon (PLCI * plci, byte ch) {
  13464. APPL * APPLptr;
  13465. DIVA_CAPI_ADAPTER * a;
  13466. word NCCIcode;
  13467. dword count;
  13468. word Num;
  13469. word i;
  13470. APPLptr = plci->appl;
  13471. a = plci->adapter;
  13472. if (!APPLptr)
  13473. return (0);
  13474. NCCIcode = a->ch_ncci[ch] | (((word) a->Id) << 8);
  13475. /* count all buffers within the Application pool */
  13476. /* belonging to the same NCCI. XON if a first is */
  13477. /* used. */
  13478. count = 0;
  13479. Num = 0xffff;
  13480. for(i=0; i<APPLptr->MaxBuffer; i++) {
  13481. if(NCCIcode==APPLptr->DataNCCI[i]) count++;
  13482. if(!APPLptr->DataNCCI[i] && Num==0xffff) Num = i;
  13483. }
  13484. if ((count > 2) || (Num == 0xffff)) {
  13485. return (0);
  13486. }
  13487. return (1);
  13488. }
  13489. /*------------------------------------------------------------------*/
  13490. static word CPN_filter_ok(byte *cpn,DIVA_CAPI_ADAPTER * a,word offset)
  13491. {
  13492. return 1;
  13493. }
  13494. /**********************************************************************************/
  13495. /* function groups the listening applications according to the CIP mask and the */
  13496. /* Info_Mask. Each group gets just one Connect_Ind. Some application manufacturer */
  13497. /* are not multi-instance capable, so they start e.g. 30 applications what causes */
  13498. /* big problems on application level (one call, 30 Connect_Ind, ect). The */
  13499. /* function must be enabled by setting "a->group_optimization_enabled" from the */
  13500. /* OS specific part (per adapter). */
  13501. /**********************************************************************************/
  13502. static void group_optimization(DIVA_CAPI_ADAPTER * a, PLCI * plci)
  13503. {
  13504. word i,j,k,busy,group_found;
  13505. dword info_mask_group[MAX_CIP_TYPES];
  13506. dword cip_mask_group[MAX_CIP_TYPES];
  13507. word appl_number_group_type[MAX_APPL];
  13508. PLCI *auxplci;
  13509. set_group_ind_mask (plci); /* all APPLs within this inc. call are allowed to dial in */
  13510. if(!a->group_optimization_enabled)
  13511. {
  13512. dbug(1,dprintf("No group optimization"));
  13513. return;
  13514. }
  13515. dbug(1,dprintf("Group optimization = 0x%x...", a->group_optimization_enabled));
  13516. for(i=0;i<MAX_CIP_TYPES;i++)
  13517. {
  13518. info_mask_group[i] = 0;
  13519. cip_mask_group [i] = 0;
  13520. }
  13521. for(i=0;i<MAX_APPL;i++)
  13522. {
  13523. appl_number_group_type[i] = 0;
  13524. }
  13525. for(i=0; i<max_appl; i++) /* check if any multi instance capable application is present */
  13526. { /* group_optimization set to 1 means not to optimize multi-instance capable applications (default) */
  13527. if(application[i].Id && (application[i].MaxNCCI) > 1 && (a->CIP_Mask[i]) && (a->group_optimization_enabled ==1) )
  13528. {
  13529. dbug(1,dprintf("Multi-Instance capable, no optimization required"));
  13530. return; /* allow good application unfiltered access */
  13531. }
  13532. }
  13533. for(i=0; i<max_appl; i++) /* Build CIP Groups */
  13534. {
  13535. if(application[i].Id && a->CIP_Mask[i] )
  13536. {
  13537. for(k=0,busy=false; k<a->max_plci; k++)
  13538. {
  13539. if(a->plci[k].Id)
  13540. {
  13541. auxplci = &a->plci[k];
  13542. if(auxplci->appl == &application[i]) /* application has a busy PLCI */
  13543. {
  13544. busy = true;
  13545. dbug(1,dprintf("Appl 0x%x is busy",i+1));
  13546. }
  13547. else if(test_c_ind_mask_bit (auxplci, i)) /* application has an incoming call pending */
  13548. {
  13549. busy = true;
  13550. dbug(1,dprintf("Appl 0x%x has inc. call pending",i+1));
  13551. }
  13552. }
  13553. }
  13554. for(j=0,group_found=0; j<=(MAX_CIP_TYPES) && !busy &&!group_found; j++) /* build groups with free applications only */
  13555. {
  13556. if(j==MAX_CIP_TYPES) /* all groups are in use but group still not found */
  13557. { /* the MAX_CIP_TYPES group enables all calls because of field overflow */
  13558. appl_number_group_type[i] = MAX_CIP_TYPES;
  13559. group_found=true;
  13560. dbug(1,dprintf("Field overflow appl 0x%x",i+1));
  13561. }
  13562. else if( (info_mask_group[j]==a->CIP_Mask[i]) && (cip_mask_group[j]==a->Info_Mask[i]) )
  13563. { /* is group already present ? */
  13564. appl_number_group_type[i] = j|0x80; /* store the group number for each application */
  13565. group_found=true;
  13566. dbug(1,dprintf("Group 0x%x found with appl 0x%x, CIP=0x%lx",appl_number_group_type[i],i+1,info_mask_group[j]));
  13567. }
  13568. else if(!info_mask_group[j])
  13569. { /* establish a new group */
  13570. appl_number_group_type[i] = j|0x80; /* store the group number for each application */
  13571. info_mask_group[j] = a->CIP_Mask[i]; /* store the new CIP mask for the new group */
  13572. cip_mask_group[j] = a->Info_Mask[i]; /* store the new Info_Mask for this new group */
  13573. group_found=true;
  13574. dbug(1,dprintf("New Group 0x%x established with appl 0x%x, CIP=0x%lx",appl_number_group_type[i],i+1,info_mask_group[j]));
  13575. }
  13576. }
  13577. }
  13578. }
  13579. for(i=0; i<max_appl; i++) /* Build group_optimization_mask_table */
  13580. {
  13581. if(appl_number_group_type[i]) /* application is free, has listens and is member of a group */
  13582. {
  13583. if(appl_number_group_type[i] == MAX_CIP_TYPES)
  13584. {
  13585. dbug(1,dprintf("OverflowGroup 0x%x, valid appl = 0x%x, call enabled",appl_number_group_type[i],i+1));
  13586. }
  13587. else
  13588. {
  13589. dbug(1,dprintf("Group 0x%x, valid appl = 0x%x",appl_number_group_type[i],i+1));
  13590. for(j=i+1; j<max_appl; j++) /* search other group members and mark them as busy */
  13591. {
  13592. if(appl_number_group_type[i] == appl_number_group_type[j])
  13593. {
  13594. dbug(1,dprintf("Appl 0x%x is member of group 0x%x, no call",j+1,appl_number_group_type[j]));
  13595. clear_group_ind_mask_bit (plci, j); /* disable call on other group members */
  13596. appl_number_group_type[j] = 0; /* remove disabled group member from group list */
  13597. }
  13598. }
  13599. }
  13600. }
  13601. else /* application should not get a call */
  13602. {
  13603. clear_group_ind_mask_bit (plci, i);
  13604. }
  13605. }
  13606. }
  13607. /* OS notifies the driver about a application Capi_Register */
  13608. word CapiRegister(word id)
  13609. {
  13610. word i,j,appls_found;
  13611. PLCI *plci;
  13612. DIVA_CAPI_ADAPTER *a;
  13613. for(i=0,appls_found=0; i<max_appl; i++)
  13614. {
  13615. if( application[i].Id && (application[i].Id!=id) )
  13616. {
  13617. appls_found++; /* an application has been found */
  13618. }
  13619. }
  13620. if(appls_found) return true;
  13621. for(i=0; i<max_adapter; i++) /* scan all adapters... */
  13622. {
  13623. a = &adapter[i];
  13624. if(a->request)
  13625. {
  13626. if(a->flag_dynamic_l1_down) /* remove adapter from L1 tristate (Huntgroup) */
  13627. {
  13628. if(!appls_found) /* first application does a capi register */
  13629. {
  13630. if((j=get_plci(a))) /* activate L1 of all adapters */
  13631. {
  13632. plci = &a->plci[j-1];
  13633. plci->command = 0;
  13634. add_p(plci,OAD,"\x01\xfd");
  13635. add_p(plci,CAI,"\x01\x80");
  13636. add_p(plci,UID,"\x06\x43\x61\x70\x69\x32\x30");
  13637. add_p(plci,SHIFT|6,NULL);
  13638. add_p(plci,SIN,"\x02\x00\x00");
  13639. plci->internal_command = START_L1_SIG_ASSIGN_PEND;
  13640. sig_req(plci,ASSIGN,DSIG_ID);
  13641. add_p(plci,FTY,"\x02\xff\x07"); /* l1 start */
  13642. sig_req(plci,SIG_CTRL,0);
  13643. send_req(plci);
  13644. }
  13645. }
  13646. }
  13647. }
  13648. }
  13649. return false;
  13650. }
  13651. /*------------------------------------------------------------------*/
  13652. /* Functions for virtual Switching e.g. Transfer by join, Conference */
  13653. static void VSwitchReqInd(PLCI *plci, dword Id, byte **parms)
  13654. {
  13655. word i;
  13656. /* Format of vswitch_t:
  13657. 0 byte length
  13658. 1 byte VSWITCHIE
  13659. 2 byte VSWITCH_REQ/VSWITCH_IND
  13660. 3 byte reserved
  13661. 4 word VSwitchcommand
  13662. 6 word returnerror
  13663. 8... Params
  13664. */
  13665. if(!plci ||
  13666. !plci->appl ||
  13667. !plci->State ||
  13668. plci->Sig.Ind==NCR_FACILITY
  13669. )
  13670. return;
  13671. for(i=0;i<MAX_MULTI_IE;i++)
  13672. {
  13673. if(!parms[i][0]) continue;
  13674. if(parms[i][0]<7)
  13675. {
  13676. parms[i][0]=0; /* kill it */
  13677. continue;
  13678. }
  13679. dbug(1,dprintf("VSwitchReqInd(%d)",parms[i][4]));
  13680. switch(parms[i][4])
  13681. {
  13682. case VSJOIN:
  13683. if(!plci->relatedPTYPLCI ||
  13684. (plci->ptyState!=S_ECT && plci->relatedPTYPLCI->ptyState!=S_ECT))
  13685. { /* Error */
  13686. break;
  13687. }
  13688. /* remember all necessary informations */
  13689. if(parms[i][0]!=11 || parms[i][8]!=3) /* Length Test */
  13690. {
  13691. break;
  13692. }
  13693. if(parms[i][2]==VSWITCH_IND && parms[i][9]==1)
  13694. { /* first indication after ECT-Request on Consultation Call */
  13695. plci->vswitchstate=parms[i][9];
  13696. parms[i][9]=2; /* State */
  13697. /* now ask first Call to join */
  13698. }
  13699. else if(parms[i][2]==VSWITCH_REQ && parms[i][9]==3)
  13700. { /* Answer of VSWITCH_REQ from first Call */
  13701. plci->vswitchstate=parms[i][9];
  13702. /* tell consultation call to join
  13703. and the protocol capabilities of the first call */
  13704. }
  13705. else
  13706. { /* Error */
  13707. break;
  13708. }
  13709. plci->vsprot=parms[i][10]; /* protocol */
  13710. plci->vsprotdialect=parms[i][11]; /* protocoldialect */
  13711. /* send join request to related PLCI */
  13712. parms[i][1]=VSWITCHIE;
  13713. parms[i][2]=VSWITCH_REQ;
  13714. plci->relatedPTYPLCI->command = 0;
  13715. plci->relatedPTYPLCI->internal_command = VSWITCH_REQ_PEND;
  13716. add_p(plci->relatedPTYPLCI,ESC,&parms[i][0]);
  13717. sig_req(plci->relatedPTYPLCI,VSWITCH_REQ,0);
  13718. send_req(plci->relatedPTYPLCI);
  13719. break;
  13720. case VSTRANSPORT:
  13721. default:
  13722. if(plci->relatedPTYPLCI &&
  13723. plci->vswitchstate==3 &&
  13724. plci->relatedPTYPLCI->vswitchstate==3)
  13725. {
  13726. add_p(plci->relatedPTYPLCI,ESC,&parms[i][0]);
  13727. sig_req(plci->relatedPTYPLCI,VSWITCH_REQ,0);
  13728. send_req(plci->relatedPTYPLCI);
  13729. }
  13730. break;
  13731. }
  13732. parms[i][0]=0; /* kill it */
  13733. }
  13734. }
  13735. /*------------------------------------------------------------------*/
  13736. static int diva_get_dma_descriptor (PLCI *plci, dword *dma_magic) {
  13737. ENTITY e;
  13738. IDI_SYNC_REQ* pReq = (IDI_SYNC_REQ*)&e;
  13739. if (!(diva_xdi_extended_features & DIVA_CAPI_XDI_PROVIDES_RX_DMA)) {
  13740. return (-1);
  13741. }
  13742. pReq->xdi_dma_descriptor_operation.Req = 0;
  13743. pReq->xdi_dma_descriptor_operation.Rc = IDI_SYNC_REQ_DMA_DESCRIPTOR_OPERATION;
  13744. pReq->xdi_dma_descriptor_operation.info.operation = IDI_SYNC_REQ_DMA_DESCRIPTOR_ALLOC;
  13745. pReq->xdi_dma_descriptor_operation.info.descriptor_number = -1;
  13746. pReq->xdi_dma_descriptor_operation.info.descriptor_address = NULL;
  13747. pReq->xdi_dma_descriptor_operation.info.descriptor_magic = 0;
  13748. e.user[0] = plci->adapter->Id - 1;
  13749. plci->adapter->request((ENTITY*)pReq);
  13750. if (!pReq->xdi_dma_descriptor_operation.info.operation &&
  13751. (pReq->xdi_dma_descriptor_operation.info.descriptor_number >= 0) &&
  13752. pReq->xdi_dma_descriptor_operation.info.descriptor_magic) {
  13753. *dma_magic = pReq->xdi_dma_descriptor_operation.info.descriptor_magic;
  13754. dbug(3,dprintf("dma_alloc, a:%d (%d-%08x)",
  13755. plci->adapter->Id,
  13756. pReq->xdi_dma_descriptor_operation.info.descriptor_number,
  13757. *dma_magic));
  13758. return (pReq->xdi_dma_descriptor_operation.info.descriptor_number);
  13759. } else {
  13760. dbug(1,dprintf("dma_alloc failed"));
  13761. return (-1);
  13762. }
  13763. }
  13764. static void diva_free_dma_descriptor (PLCI *plci, int nr) {
  13765. ENTITY e;
  13766. IDI_SYNC_REQ* pReq = (IDI_SYNC_REQ*)&e;
  13767. if (nr < 0) {
  13768. return;
  13769. }
  13770. pReq->xdi_dma_descriptor_operation.Req = 0;
  13771. pReq->xdi_dma_descriptor_operation.Rc = IDI_SYNC_REQ_DMA_DESCRIPTOR_OPERATION;
  13772. pReq->xdi_dma_descriptor_operation.info.operation = IDI_SYNC_REQ_DMA_DESCRIPTOR_FREE;
  13773. pReq->xdi_dma_descriptor_operation.info.descriptor_number = nr;
  13774. pReq->xdi_dma_descriptor_operation.info.descriptor_address = NULL;
  13775. pReq->xdi_dma_descriptor_operation.info.descriptor_magic = 0;
  13776. e.user[0] = plci->adapter->Id - 1;
  13777. plci->adapter->request((ENTITY*)pReq);
  13778. if (!pReq->xdi_dma_descriptor_operation.info.operation) {
  13779. dbug(1,dprintf("dma_free(%d)", nr));
  13780. } else {
  13781. dbug(1,dprintf("dma_free failed (%d)", nr));
  13782. }
  13783. }
  13784. /*------------------------------------------------------------------*/