message.c 435 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521752275237524752575267527752875297530753175327533753475357536753775387539754075417542754375447545754675477548754975507551755275537554755575567557755875597560756175627563756475657566756775687569757075717572757375747575757675777578757975807581758275837584758575867587758875897590759175927593759475957596759775987599760076017602760376047605760676077608760976107611761276137614761576167617761876197620762176227623762476257626762776287629763076317632763376347635763676377638763976407641764276437644764576467647764876497650765176527653765476557656765776587659766076617662766376647665766676677668766976707671767276737674767576767677767876797680768176827683768476857686768776887689769076917692769376947695769676977698769977007701770277037704770577067707770877097710771177127713771477157716771777187719772077217722772377247725772677277728772977307731773277337734773577367737773877397740774177427743774477457746774777487749775077517752775377547755775677577758775977607761776277637764776577667767776877697770777177727773777477757776777777787779778077817782778377847785778677877788778977907791779277937794779577967797779877997800780178027803780478057806780778087809781078117812781378147815781678177818781978207821782278237824782578267827782878297830783178327833783478357836783778387839784078417842784378447845784678477848784978507851785278537854785578567857785878597860786178627863786478657866786778687869787078717872787378747875787678777878787978807881788278837884788578867887788878897890789178927893789478957896789778987899790079017902790379047905790679077908790979107911791279137914791579167917791879197920792179227923792479257926792779287929793079317932793379347935793679377938793979407941794279437944794579467947794879497950795179527953795479557956795779587959796079617962796379647965796679677968796979707971797279737974797579767977797879797980798179827983798479857986798779887989799079917992799379947995799679977998799980008001800280038004800580068007800880098010801180128013801480158016801780188019802080218022802380248025802680278028802980308031803280338034803580368037803880398040804180428043804480458046804780488049805080518052805380548055805680578058805980608061806280638064806580668067806880698070807180728073807480758076807780788079808080818082808380848085808680878088808980908091809280938094809580968097809880998100810181028103810481058106810781088109811081118112811381148115811681178118811981208121812281238124812581268127812881298130813181328133813481358136813781388139814081418142814381448145814681478148814981508151815281538154815581568157815881598160816181628163816481658166816781688169817081718172817381748175817681778178817981808181818281838184818581868187818881898190819181928193819481958196819781988199820082018202820382048205820682078208820982108211821282138214821582168217821882198220822182228223822482258226822782288229823082318232823382348235823682378238823982408241824282438244824582468247824882498250825182528253825482558256825782588259826082618262826382648265826682678268826982708271827282738274827582768277827882798280828182828283828482858286828782888289829082918292829382948295829682978298829983008301830283038304830583068307830883098310831183128313831483158316831783188319832083218322832383248325832683278328832983308331833283338334833583368337833883398340834183428343834483458346834783488349835083518352835383548355835683578358835983608361836283638364836583668367836883698370837183728373837483758376837783788379838083818382838383848385838683878388838983908391839283938394839583968397839883998400840184028403840484058406840784088409841084118412841384148415841684178418841984208421842284238424842584268427842884298430843184328433843484358436843784388439844084418442844384448445844684478448844984508451845284538454845584568457845884598460846184628463846484658466846784688469847084718472847384748475847684778478847984808481848284838484848584868487848884898490849184928493849484958496849784988499850085018502850385048505850685078508850985108511851285138514851585168517851885198520852185228523852485258526852785288529853085318532853385348535853685378538853985408541854285438544854585468547854885498550855185528553855485558556855785588559856085618562856385648565856685678568856985708571857285738574857585768577857885798580858185828583858485858586858785888589859085918592859385948595859685978598859986008601860286038604860586068607860886098610861186128613861486158616861786188619862086218622862386248625862686278628862986308631863286338634863586368637863886398640864186428643864486458646864786488649865086518652865386548655865686578658865986608661866286638664866586668667866886698670867186728673867486758676867786788679868086818682868386848685868686878688868986908691869286938694869586968697869886998700870187028703870487058706870787088709871087118712871387148715871687178718871987208721872287238724872587268727872887298730873187328733873487358736873787388739874087418742874387448745874687478748874987508751875287538754875587568757875887598760876187628763876487658766876787688769877087718772877387748775877687778778877987808781878287838784878587868787878887898790879187928793879487958796879787988799880088018802880388048805880688078808880988108811881288138814881588168817881888198820882188228823882488258826882788288829883088318832883388348835883688378838883988408841884288438844884588468847884888498850885188528853885488558856885788588859886088618862886388648865886688678868886988708871887288738874887588768877887888798880888188828883888488858886888788888889889088918892889388948895889688978898889989008901890289038904890589068907890889098910891189128913891489158916891789188919892089218922892389248925892689278928892989308931893289338934893589368937893889398940894189428943894489458946894789488949895089518952895389548955895689578958895989608961896289638964896589668967896889698970897189728973897489758976897789788979898089818982898389848985898689878988898989908991899289938994899589968997899889999000900190029003900490059006900790089009901090119012901390149015901690179018901990209021902290239024902590269027902890299030903190329033903490359036903790389039904090419042904390449045904690479048904990509051905290539054905590569057905890599060906190629063906490659066906790689069907090719072907390749075907690779078907990809081908290839084908590869087908890899090909190929093909490959096909790989099910091019102910391049105910691079108910991109111911291139114911591169117911891199120912191229123912491259126912791289129913091319132913391349135913691379138913991409141914291439144914591469147914891499150915191529153915491559156915791589159916091619162916391649165916691679168916991709171917291739174917591769177917891799180918191829183918491859186918791889189919091919192919391949195919691979198919992009201920292039204920592069207920892099210921192129213921492159216921792189219922092219222922392249225922692279228922992309231923292339234923592369237923892399240924192429243924492459246924792489249925092519252925392549255925692579258925992609261926292639264926592669267926892699270927192729273927492759276927792789279928092819282928392849285928692879288928992909291929292939294929592969297929892999300930193029303930493059306930793089309931093119312931393149315931693179318931993209321932293239324932593269327932893299330933193329333933493359336933793389339934093419342934393449345934693479348934993509351935293539354935593569357935893599360936193629363936493659366936793689369937093719372937393749375937693779378937993809381938293839384938593869387938893899390939193929393939493959396939793989399940094019402940394049405940694079408940994109411941294139414941594169417941894199420942194229423942494259426942794289429943094319432943394349435943694379438943994409441944294439444944594469447944894499450945194529453945494559456945794589459946094619462946394649465946694679468946994709471947294739474947594769477947894799480948194829483948494859486948794889489949094919492949394949495949694979498949995009501950295039504950595069507950895099510951195129513951495159516951795189519952095219522952395249525952695279528952995309531953295339534953595369537953895399540954195429543954495459546954795489549955095519552955395549555955695579558955995609561956295639564956595669567956895699570957195729573957495759576957795789579958095819582958395849585958695879588958995909591959295939594959595969597959895999600960196029603960496059606960796089609961096119612961396149615961696179618961996209621962296239624962596269627962896299630963196329633963496359636963796389639964096419642964396449645964696479648964996509651965296539654965596569657965896599660966196629663966496659666966796689669967096719672967396749675967696779678967996809681968296839684968596869687968896899690969196929693969496959696969796989699970097019702970397049705970697079708970997109711971297139714971597169717971897199720972197229723972497259726972797289729973097319732973397349735973697379738973997409741974297439744974597469747974897499750975197529753975497559756975797589759976097619762976397649765976697679768976997709771977297739774977597769777977897799780978197829783978497859786978797889789979097919792979397949795979697979798979998009801980298039804980598069807980898099810981198129813981498159816981798189819982098219822982398249825982698279828982998309831983298339834983598369837983898399840984198429843984498459846984798489849985098519852985398549855985698579858985998609861986298639864986598669867986898699870987198729873987498759876987798789879988098819882988398849885988698879888988998909891989298939894989598969897989898999900990199029903990499059906990799089909991099119912991399149915991699179918991999209921992299239924992599269927992899299930993199329933993499359936993799389939994099419942994399449945994699479948994999509951995299539954995599569957995899599960996199629963996499659966996799689969997099719972997399749975997699779978997999809981998299839984998599869987998899899990999199929993999499959996999799989999100001000110002100031000410005100061000710008100091001010011100121001310014100151001610017100181001910020100211002210023100241002510026100271002810029100301003110032100331003410035100361003710038100391004010041100421004310044100451004610047100481004910050100511005210053100541005510056100571005810059100601006110062100631006410065100661006710068100691007010071100721007310074100751007610077100781007910080100811008210083100841008510086100871008810089100901009110092100931009410095100961009710098100991010010101101021010310104101051010610107101081010910110101111011210113101141011510116101171011810119101201012110122101231012410125101261012710128101291013010131101321013310134101351013610137101381013910140101411014210143101441014510146101471014810149101501015110152101531015410155101561015710158101591016010161101621016310164101651016610167101681016910170101711017210173101741017510176101771017810179101801018110182101831018410185101861018710188101891019010191101921019310194101951019610197101981019910200102011020210203102041020510206102071020810209102101021110212102131021410215102161021710218102191022010221102221022310224102251022610227102281022910230102311023210233102341023510236102371023810239102401024110242102431024410245102461024710248102491025010251102521025310254102551025610257102581025910260102611026210263102641026510266102671026810269102701027110272102731027410275102761027710278102791028010281102821028310284102851028610287102881028910290102911029210293102941029510296102971029810299103001030110302103031030410305103061030710308103091031010311103121031310314103151031610317103181031910320103211032210323103241032510326103271032810329103301033110332103331033410335103361033710338103391034010341103421034310344103451034610347103481034910350103511035210353103541035510356103571035810359103601036110362103631036410365103661036710368103691037010371103721037310374103751037610377103781037910380103811038210383103841038510386103871038810389103901039110392103931039410395103961039710398103991040010401104021040310404104051040610407104081040910410104111041210413104141041510416104171041810419104201042110422104231042410425104261042710428104291043010431104321043310434104351043610437104381043910440104411044210443104441044510446104471044810449104501045110452104531045410455104561045710458104591046010461104621046310464104651046610467104681046910470104711047210473104741047510476104771047810479104801048110482104831048410485104861048710488104891049010491104921049310494104951049610497104981049910500105011050210503105041050510506105071050810509105101051110512105131051410515105161051710518105191052010521105221052310524105251052610527105281052910530105311053210533105341053510536105371053810539105401054110542105431054410545105461054710548105491055010551105521055310554105551055610557105581055910560105611056210563105641056510566105671056810569105701057110572105731057410575105761057710578105791058010581105821058310584105851058610587105881058910590105911059210593105941059510596105971059810599106001060110602106031060410605106061060710608106091061010611106121061310614106151061610617106181061910620106211062210623106241062510626106271062810629106301063110632106331063410635106361063710638106391064010641106421064310644106451064610647106481064910650106511065210653106541065510656106571065810659106601066110662106631066410665106661066710668106691067010671106721067310674106751067610677106781067910680106811068210683106841068510686106871068810689106901069110692106931069410695106961069710698106991070010701107021070310704107051070610707107081070910710107111071210713107141071510716107171071810719107201072110722107231072410725107261072710728107291073010731107321073310734107351073610737107381073910740107411074210743107441074510746107471074810749107501075110752107531075410755107561075710758107591076010761107621076310764107651076610767107681076910770107711077210773107741077510776107771077810779107801078110782107831078410785107861078710788107891079010791107921079310794107951079610797107981079910800108011080210803108041080510806108071080810809108101081110812108131081410815108161081710818108191082010821108221082310824108251082610827108281082910830108311083210833108341083510836108371083810839108401084110842108431084410845108461084710848108491085010851108521085310854108551085610857108581085910860108611086210863108641086510866108671086810869108701087110872108731087410875108761087710878108791088010881108821088310884108851088610887108881088910890108911089210893108941089510896108971089810899109001090110902109031090410905109061090710908109091091010911109121091310914109151091610917109181091910920109211092210923109241092510926109271092810929109301093110932109331093410935109361093710938109391094010941109421094310944109451094610947109481094910950109511095210953109541095510956109571095810959109601096110962109631096410965109661096710968109691097010971109721097310974109751097610977109781097910980109811098210983109841098510986109871098810989109901099110992109931099410995109961099710998109991100011001110021100311004110051100611007110081100911010110111101211013110141101511016110171101811019110201102111022110231102411025110261102711028110291103011031110321103311034110351103611037110381103911040110411104211043110441104511046110471104811049110501105111052110531105411055110561105711058110591106011061110621106311064110651106611067110681106911070110711107211073110741107511076110771107811079110801108111082110831108411085110861108711088110891109011091110921109311094110951109611097110981109911100111011110211103111041110511106111071110811109111101111111112111131111411115111161111711118111191112011121111221112311124111251112611127111281112911130111311113211133111341113511136111371113811139111401114111142111431114411145111461114711148111491115011151111521115311154111551115611157111581115911160111611116211163111641116511166111671116811169111701117111172111731117411175111761117711178111791118011181111821118311184111851118611187111881118911190111911119211193111941119511196111971119811199112001120111202112031120411205112061120711208112091121011211112121121311214112151121611217112181121911220112211122211223112241122511226112271122811229112301123111232112331123411235112361123711238112391124011241112421124311244112451124611247112481124911250112511125211253112541125511256112571125811259112601126111262112631126411265112661126711268112691127011271112721127311274112751127611277112781127911280112811128211283112841128511286112871128811289112901129111292112931129411295112961129711298112991130011301113021130311304113051130611307113081130911310113111131211313113141131511316113171131811319113201132111322113231132411325113261132711328113291133011331113321133311334113351133611337113381133911340113411134211343113441134511346113471134811349113501135111352113531135411355113561135711358113591136011361113621136311364113651136611367113681136911370113711137211373113741137511376113771137811379113801138111382113831138411385113861138711388113891139011391113921139311394113951139611397113981139911400114011140211403114041140511406114071140811409114101141111412114131141411415114161141711418114191142011421114221142311424114251142611427114281142911430114311143211433114341143511436114371143811439114401144111442114431144411445114461144711448114491145011451114521145311454114551145611457114581145911460114611146211463114641146511466114671146811469114701147111472114731147411475114761147711478114791148011481114821148311484114851148611487114881148911490114911149211493114941149511496114971149811499115001150111502115031150411505115061150711508115091151011511115121151311514115151151611517115181151911520115211152211523115241152511526115271152811529115301153111532115331153411535115361153711538115391154011541115421154311544115451154611547115481154911550115511155211553115541155511556115571155811559115601156111562115631156411565115661156711568115691157011571115721157311574115751157611577115781157911580115811158211583115841158511586115871158811589115901159111592115931159411595115961159711598115991160011601116021160311604116051160611607116081160911610116111161211613116141161511616116171161811619116201162111622116231162411625116261162711628116291163011631116321163311634116351163611637116381163911640116411164211643116441164511646116471164811649116501165111652116531165411655116561165711658116591166011661116621166311664116651166611667116681166911670116711167211673116741167511676116771167811679116801168111682116831168411685116861168711688116891169011691116921169311694116951169611697116981169911700117011170211703117041170511706117071170811709117101171111712117131171411715117161171711718117191172011721117221172311724117251172611727117281172911730117311173211733117341173511736117371173811739117401174111742117431174411745117461174711748117491175011751117521175311754117551175611757117581175911760117611176211763117641176511766117671176811769117701177111772117731177411775117761177711778117791178011781117821178311784117851178611787117881178911790117911179211793117941179511796117971179811799118001180111802118031180411805118061180711808118091181011811118121181311814118151181611817118181181911820118211182211823118241182511826118271182811829118301183111832118331183411835118361183711838118391184011841118421184311844118451184611847118481184911850118511185211853118541185511856118571185811859118601186111862118631186411865118661186711868118691187011871118721187311874118751187611877118781187911880118811188211883118841188511886118871188811889118901189111892118931189411895118961189711898118991190011901119021190311904119051190611907119081190911910119111191211913119141191511916119171191811919119201192111922119231192411925119261192711928119291193011931119321193311934119351193611937119381193911940119411194211943119441194511946119471194811949119501195111952119531195411955119561195711958119591196011961119621196311964119651196611967119681196911970119711197211973119741197511976119771197811979119801198111982119831198411985119861198711988119891199011991119921199311994119951199611997119981199912000120011200212003120041200512006120071200812009120101201112012120131201412015120161201712018120191202012021120221202312024120251202612027120281202912030120311203212033120341203512036120371203812039120401204112042120431204412045120461204712048120491205012051120521205312054120551205612057120581205912060120611206212063120641206512066120671206812069120701207112072120731207412075120761207712078120791208012081120821208312084120851208612087120881208912090120911209212093120941209512096120971209812099121001210112102121031210412105121061210712108121091211012111121121211312114121151211612117121181211912120121211212212123121241212512126121271212812129121301213112132121331213412135121361213712138121391214012141121421214312144121451214612147121481214912150121511215212153121541215512156121571215812159121601216112162121631216412165121661216712168121691217012171121721217312174121751217612177121781217912180121811218212183121841218512186121871218812189121901219112192121931219412195121961219712198121991220012201122021220312204122051220612207122081220912210122111221212213122141221512216122171221812219122201222112222122231222412225122261222712228122291223012231122321223312234122351223612237122381223912240122411224212243122441224512246122471224812249122501225112252122531225412255122561225712258122591226012261122621226312264122651226612267122681226912270122711227212273122741227512276122771227812279122801228112282122831228412285122861228712288122891229012291122921229312294122951229612297122981229912300123011230212303123041230512306123071230812309123101231112312123131231412315123161231712318123191232012321123221232312324123251232612327123281232912330123311233212333123341233512336123371233812339123401234112342123431234412345123461234712348123491235012351123521235312354123551235612357123581235912360123611236212363123641236512366123671236812369123701237112372123731237412375123761237712378123791238012381123821238312384123851238612387123881238912390123911239212393123941239512396123971239812399124001240112402124031240412405124061240712408124091241012411124121241312414124151241612417124181241912420124211242212423124241242512426124271242812429124301243112432124331243412435124361243712438124391244012441124421244312444124451244612447124481244912450124511245212453124541245512456124571245812459124601246112462124631246412465124661246712468124691247012471124721247312474124751247612477124781247912480124811248212483124841248512486124871248812489124901249112492124931249412495124961249712498124991250012501125021250312504125051250612507125081250912510125111251212513125141251512516125171251812519125201252112522125231252412525125261252712528125291253012531125321253312534125351253612537125381253912540125411254212543125441254512546125471254812549125501255112552125531255412555125561255712558125591256012561125621256312564125651256612567125681256912570125711257212573125741257512576125771257812579125801258112582125831258412585125861258712588125891259012591125921259312594125951259612597125981259912600126011260212603126041260512606126071260812609126101261112612126131261412615126161261712618126191262012621126221262312624126251262612627126281262912630126311263212633126341263512636126371263812639126401264112642126431264412645126461264712648126491265012651126521265312654126551265612657126581265912660126611266212663126641266512666126671266812669126701267112672126731267412675126761267712678126791268012681126821268312684126851268612687126881268912690126911269212693126941269512696126971269812699127001270112702127031270412705127061270712708127091271012711127121271312714127151271612717127181271912720127211272212723127241272512726127271272812729127301273112732127331273412735127361273712738127391274012741127421274312744127451274612747127481274912750127511275212753127541275512756127571275812759127601276112762127631276412765127661276712768127691277012771127721277312774127751277612777127781277912780127811278212783127841278512786127871278812789127901279112792127931279412795127961279712798127991280012801128021280312804128051280612807128081280912810128111281212813128141281512816128171281812819128201282112822128231282412825128261282712828128291283012831128321283312834128351283612837128381283912840128411284212843128441284512846128471284812849128501285112852128531285412855128561285712858128591286012861128621286312864128651286612867128681286912870128711287212873128741287512876128771287812879128801288112882128831288412885128861288712888128891289012891128921289312894128951289612897128981289912900129011290212903129041290512906129071290812909129101291112912129131291412915129161291712918129191292012921129221292312924129251292612927129281292912930129311293212933129341293512936129371293812939129401294112942129431294412945129461294712948129491295012951129521295312954129551295612957129581295912960129611296212963129641296512966129671296812969129701297112972129731297412975129761297712978129791298012981129821298312984129851298612987129881298912990129911299212993129941299512996129971299812999130001300113002130031300413005130061300713008130091301013011130121301313014130151301613017130181301913020130211302213023130241302513026130271302813029130301303113032130331303413035130361303713038130391304013041130421304313044130451304613047130481304913050130511305213053130541305513056130571305813059130601306113062130631306413065130661306713068130691307013071130721307313074130751307613077130781307913080130811308213083130841308513086130871308813089130901309113092130931309413095130961309713098130991310013101131021310313104131051310613107131081310913110131111311213113131141311513116131171311813119131201312113122131231312413125131261312713128131291313013131131321313313134131351313613137131381313913140131411314213143131441314513146131471314813149131501315113152131531315413155131561315713158131591316013161131621316313164131651316613167131681316913170131711317213173131741317513176131771317813179131801318113182131831318413185131861318713188131891319013191131921319313194131951319613197131981319913200132011320213203132041320513206132071320813209132101321113212132131321413215132161321713218132191322013221132221322313224132251322613227132281322913230132311323213233132341323513236132371323813239132401324113242132431324413245132461324713248132491325013251132521325313254132551325613257132581325913260132611326213263132641326513266132671326813269132701327113272132731327413275132761327713278132791328013281132821328313284132851328613287132881328913290132911329213293132941329513296132971329813299133001330113302133031330413305133061330713308133091331013311133121331313314133151331613317133181331913320133211332213323133241332513326133271332813329133301333113332133331333413335133361333713338133391334013341133421334313344133451334613347133481334913350133511335213353133541335513356133571335813359133601336113362133631336413365133661336713368133691337013371133721337313374133751337613377133781337913380133811338213383133841338513386133871338813389133901339113392133931339413395133961339713398133991340013401134021340313404134051340613407134081340913410134111341213413134141341513416134171341813419134201342113422134231342413425134261342713428134291343013431134321343313434134351343613437134381343913440134411344213443134441344513446134471344813449134501345113452134531345413455134561345713458134591346013461134621346313464134651346613467134681346913470134711347213473134741347513476134771347813479134801348113482134831348413485134861348713488134891349013491134921349313494134951349613497134981349913500135011350213503135041350513506135071350813509135101351113512135131351413515135161351713518135191352013521135221352313524135251352613527135281352913530135311353213533135341353513536135371353813539135401354113542135431354413545135461354713548135491355013551135521355313554135551355613557135581355913560135611356213563135641356513566135671356813569135701357113572135731357413575135761357713578135791358013581135821358313584135851358613587135881358913590135911359213593135941359513596135971359813599136001360113602136031360413605136061360713608136091361013611136121361313614136151361613617136181361913620136211362213623136241362513626136271362813629136301363113632136331363413635136361363713638136391364013641136421364313644136451364613647136481364913650136511365213653136541365513656136571365813659136601366113662136631366413665136661366713668136691367013671136721367313674136751367613677136781367913680136811368213683136841368513686136871368813689136901369113692136931369413695136961369713698136991370013701137021370313704137051370613707137081370913710137111371213713137141371513716137171371813719137201372113722137231372413725137261372713728137291373013731137321373313734137351373613737137381373913740137411374213743137441374513746137471374813749137501375113752137531375413755137561375713758137591376013761137621376313764137651376613767137681376913770137711377213773137741377513776137771377813779137801378113782137831378413785137861378713788137891379013791137921379313794137951379613797137981379913800138011380213803138041380513806138071380813809138101381113812138131381413815138161381713818138191382013821138221382313824138251382613827138281382913830138311383213833138341383513836138371383813839138401384113842138431384413845138461384713848138491385013851138521385313854138551385613857138581385913860138611386213863138641386513866138671386813869138701387113872138731387413875138761387713878138791388013881138821388313884138851388613887138881388913890138911389213893138941389513896138971389813899139001390113902139031390413905139061390713908139091391013911139121391313914139151391613917139181391913920139211392213923139241392513926139271392813929139301393113932139331393413935139361393713938139391394013941139421394313944139451394613947139481394913950139511395213953139541395513956139571395813959139601396113962139631396413965139661396713968139691397013971139721397313974139751397613977139781397913980139811398213983139841398513986139871398813989139901399113992139931399413995139961399713998139991400014001140021400314004140051400614007140081400914010140111401214013140141401514016140171401814019140201402114022140231402414025140261402714028140291403014031140321403314034140351403614037140381403914040140411404214043140441404514046140471404814049140501405114052140531405414055140561405714058140591406014061140621406314064140651406614067140681406914070140711407214073140741407514076140771407814079140801408114082140831408414085140861408714088140891409014091140921409314094140951409614097140981409914100141011410214103141041410514106141071410814109141101411114112141131411414115141161411714118141191412014121141221412314124141251412614127141281412914130141311413214133141341413514136141371413814139141401414114142141431414414145141461414714148141491415014151141521415314154141551415614157141581415914160141611416214163141641416514166141671416814169141701417114172141731417414175141761417714178141791418014181141821418314184141851418614187141881418914190141911419214193141941419514196141971419814199142001420114202142031420414205142061420714208142091421014211142121421314214142151421614217142181421914220142211422214223142241422514226142271422814229142301423114232142331423414235142361423714238142391424014241142421424314244142451424614247142481424914250142511425214253142541425514256142571425814259142601426114262142631426414265142661426714268142691427014271142721427314274142751427614277142781427914280142811428214283142841428514286142871428814289142901429114292142931429414295142961429714298142991430014301143021430314304143051430614307143081430914310143111431214313143141431514316143171431814319143201432114322143231432414325143261432714328143291433014331143321433314334143351433614337143381433914340143411434214343143441434514346143471434814349143501435114352143531435414355143561435714358143591436014361143621436314364143651436614367143681436914370143711437214373143741437514376143771437814379143801438114382143831438414385143861438714388143891439014391143921439314394143951439614397143981439914400144011440214403144041440514406144071440814409144101441114412144131441414415144161441714418144191442014421144221442314424144251442614427144281442914430144311443214433144341443514436144371443814439144401444114442144431444414445144461444714448144491445014451144521445314454144551445614457144581445914460144611446214463144641446514466144671446814469144701447114472144731447414475144761447714478144791448014481144821448314484144851448614487144881448914490144911449214493144941449514496144971449814499145001450114502145031450414505145061450714508145091451014511145121451314514145151451614517145181451914520145211452214523145241452514526145271452814529145301453114532145331453414535145361453714538145391454014541145421454314544145451454614547145481454914550145511455214553145541455514556145571455814559145601456114562145631456414565145661456714568145691457014571145721457314574145751457614577145781457914580145811458214583145841458514586145871458814589145901459114592145931459414595145961459714598145991460014601146021460314604146051460614607146081460914610146111461214613146141461514616146171461814619146201462114622146231462414625146261462714628146291463014631146321463314634146351463614637146381463914640146411464214643146441464514646146471464814649146501465114652146531465414655146561465714658146591466014661146621466314664146651466614667146681466914670146711467214673146741467514676146771467814679146801468114682146831468414685146861468714688146891469014691146921469314694146951469614697146981469914700147011470214703147041470514706147071470814709147101471114712147131471414715147161471714718147191472014721147221472314724147251472614727147281472914730147311473214733147341473514736147371473814739147401474114742147431474414745147461474714748147491475014751147521475314754147551475614757147581475914760147611476214763147641476514766147671476814769147701477114772147731477414775147761477714778147791478014781147821478314784147851478614787147881478914790147911479214793147941479514796147971479814799148001480114802148031480414805148061480714808148091481014811148121481314814148151481614817148181481914820148211482214823148241482514826148271482814829148301483114832148331483414835148361483714838148391484014841148421484314844148451484614847148481484914850148511485214853148541485514856148571485814859148601486114862148631486414865148661486714868148691487014871148721487314874148751487614877148781487914880148811488214883148841488514886148871488814889148901489114892148931489414895148961489714898148991490014901149021490314904149051490614907149081490914910149111491214913149141491514916149171491814919149201492114922149231492414925149261492714928149291493014931149321493314934149351493614937149381493914940149411494214943149441494514946149471494814949149501495114952149531495414955
  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 <linux/bitmap.h>
  26. #include "platform.h"
  27. #include "di_defs.h"
  28. #include "pc.h"
  29. #include "capi20.h"
  30. #include "divacapi.h"
  31. #include "mdm_msg.h"
  32. #include "divasync.h"
  33. #define FILE_ "MESSAGE.C"
  34. #define dprintf
  35. /*------------------------------------------------------------------*/
  36. /* This is options supported for all adapters that are server by */
  37. /* XDI driver. Allo it is not necessary to ask it from every adapter*/
  38. /* and it is not necessary to save it separate for every adapter */
  39. /* Macrose defined here have only local meaning */
  40. /*------------------------------------------------------------------*/
  41. static dword diva_xdi_extended_features = 0;
  42. #define DIVA_CAPI_USE_CMA 0x00000001
  43. #define DIVA_CAPI_XDI_PROVIDES_SDRAM_BAR 0x00000002
  44. #define DIVA_CAPI_XDI_PROVIDES_NO_CANCEL 0x00000004
  45. #define DIVA_CAPI_XDI_PROVIDES_RX_DMA 0x00000008
  46. /*
  47. CAPI can request to process all return codes self only if:
  48. protocol code supports this && xdi supports this
  49. */
  50. #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))
  51. /*------------------------------------------------------------------*/
  52. /* local function prototypes */
  53. /*------------------------------------------------------------------*/
  54. static void group_optimization(DIVA_CAPI_ADAPTER *a, PLCI *plci);
  55. void AutomaticLaw(DIVA_CAPI_ADAPTER *);
  56. word CapiRelease(word);
  57. word CapiRegister(word);
  58. word api_put(APPL *, CAPI_MSG *);
  59. static word api_parse(byte *, word, byte *, API_PARSE *);
  60. static void api_save_msg(API_PARSE *in, byte *format, API_SAVE *out);
  61. static void api_load_msg(API_SAVE *in, API_PARSE *out);
  62. word api_remove_start(void);
  63. void api_remove_complete(void);
  64. static void plci_remove(PLCI *);
  65. static void diva_get_extended_adapter_features(DIVA_CAPI_ADAPTER *a);
  66. static void diva_ask_for_xdi_sdram_bar(DIVA_CAPI_ADAPTER *, IDI_SYNC_REQ *);
  67. void callback(ENTITY *);
  68. static void control_rc(PLCI *, byte, byte, byte, byte, byte);
  69. static void data_rc(PLCI *, byte);
  70. static void data_ack(PLCI *, byte);
  71. static void sig_ind(PLCI *);
  72. static void SendInfo(PLCI *, dword, byte **, byte);
  73. static void SendSetupInfo(APPL *, PLCI *, dword, byte **, byte);
  74. static void SendSSExtInd(APPL *, PLCI *plci, dword Id, byte **parms);
  75. static void VSwitchReqInd(PLCI *plci, dword Id, byte **parms);
  76. static void nl_ind(PLCI *);
  77. static byte connect_req(dword, word, DIVA_CAPI_ADAPTER *, PLCI *, APPL *, API_PARSE *);
  78. static byte connect_res(dword, word, DIVA_CAPI_ADAPTER *, PLCI *, APPL *, API_PARSE *);
  79. static byte connect_a_res(dword, word, DIVA_CAPI_ADAPTER *, PLCI *, APPL *, API_PARSE *);
  80. static byte disconnect_req(dword, word, DIVA_CAPI_ADAPTER *, PLCI *, APPL *, API_PARSE *);
  81. static byte disconnect_res(dword, word, DIVA_CAPI_ADAPTER *, PLCI *, APPL *, API_PARSE *);
  82. static byte listen_req(dword, word, DIVA_CAPI_ADAPTER *, PLCI *, APPL *, API_PARSE *);
  83. static byte info_req(dword, word, DIVA_CAPI_ADAPTER *, PLCI *, APPL *, API_PARSE *);
  84. static byte info_res(dword, word, DIVA_CAPI_ADAPTER *, PLCI *, APPL *, API_PARSE *);
  85. static byte alert_req(dword, word, DIVA_CAPI_ADAPTER *, PLCI *, APPL *, API_PARSE *);
  86. static byte facility_req(dword, word, DIVA_CAPI_ADAPTER *, PLCI *, APPL *, API_PARSE *);
  87. static byte facility_res(dword, word, DIVA_CAPI_ADAPTER *, PLCI *, APPL *, API_PARSE *);
  88. static byte connect_b3_req(dword, word, DIVA_CAPI_ADAPTER *, PLCI *, APPL *, API_PARSE *);
  89. static byte connect_b3_res(dword, word, DIVA_CAPI_ADAPTER *, PLCI *, APPL *, API_PARSE *);
  90. static byte connect_b3_a_res(dword, word, DIVA_CAPI_ADAPTER *, PLCI *, APPL *, API_PARSE *);
  91. static byte disconnect_b3_req(dword, word, DIVA_CAPI_ADAPTER *, PLCI *, APPL *, API_PARSE *);
  92. static byte disconnect_b3_res(dword, word, DIVA_CAPI_ADAPTER *, PLCI *, APPL *, API_PARSE *);
  93. static byte data_b3_req(dword, word, DIVA_CAPI_ADAPTER *, PLCI *, APPL *, API_PARSE *);
  94. static byte data_b3_res(dword, word, DIVA_CAPI_ADAPTER *, PLCI *, APPL *, API_PARSE *);
  95. static byte reset_b3_req(dword, word, DIVA_CAPI_ADAPTER *, PLCI *, APPL *, API_PARSE *);
  96. static byte reset_b3_res(dword, word, DIVA_CAPI_ADAPTER *, PLCI *, APPL *, API_PARSE *);
  97. static byte connect_b3_t90_a_res(dword, word, DIVA_CAPI_ADAPTER *, PLCI *, APPL *, API_PARSE *);
  98. static byte select_b_req(dword, word, DIVA_CAPI_ADAPTER *, PLCI *, APPL *, API_PARSE *);
  99. static byte manufacturer_req(dword, word, DIVA_CAPI_ADAPTER *, PLCI *, APPL *, API_PARSE *);
  100. static byte manufacturer_res(dword, word, DIVA_CAPI_ADAPTER *, PLCI *, APPL *, API_PARSE *);
  101. static word get_plci(DIVA_CAPI_ADAPTER *);
  102. static void add_p(PLCI *, byte, byte *);
  103. static void add_s(PLCI *plci, byte code, API_PARSE *p);
  104. static void add_ss(PLCI *plci, byte code, API_PARSE *p);
  105. static void add_ie(PLCI *plci, byte code, byte *p, word p_length);
  106. static void add_d(PLCI *, word, byte *);
  107. static void add_ai(PLCI *, API_PARSE *);
  108. static word add_b1(PLCI *, API_PARSE *, word, word);
  109. static word add_b23(PLCI *, API_PARSE *);
  110. static word add_modem_b23(PLCI *plci, API_PARSE *bp_parms);
  111. static void sig_req(PLCI *, byte, byte);
  112. static void nl_req_ncci(PLCI *, byte, byte);
  113. static void send_req(PLCI *);
  114. static void send_data(PLCI *);
  115. static word plci_remove_check(PLCI *);
  116. static void listen_check(DIVA_CAPI_ADAPTER *);
  117. static byte AddInfo(byte **, byte **, byte *, byte *);
  118. static byte getChannel(API_PARSE *);
  119. static void IndParse(PLCI *, const word *, byte **, byte);
  120. static byte ie_compare(byte *, byte *);
  121. static word find_cip(DIVA_CAPI_ADAPTER *, byte *, byte *);
  122. static word CPN_filter_ok(byte *cpn, DIVA_CAPI_ADAPTER *, word);
  123. /*
  124. XON protocol helpers
  125. */
  126. static void channel_flow_control_remove(PLCI *plci);
  127. static void channel_x_off(PLCI *plci, byte ch, byte flag);
  128. static void channel_x_on(PLCI *plci, byte ch);
  129. static void channel_request_xon(PLCI *plci, byte ch);
  130. static void channel_xmit_xon(PLCI *plci);
  131. static int channel_can_xon(PLCI *plci, byte ch);
  132. static void channel_xmit_extended_xon(PLCI *plci);
  133. static byte SendMultiIE(PLCI *plci, dword Id, byte **parms, byte ie_type, dword info_mask, byte setupParse);
  134. static word AdvCodecSupport(DIVA_CAPI_ADAPTER *, PLCI *, APPL *, byte);
  135. static void CodecIdCheck(DIVA_CAPI_ADAPTER *, PLCI *);
  136. static void SetVoiceChannel(PLCI *, byte *, DIVA_CAPI_ADAPTER *);
  137. static void VoiceChannelOff(PLCI *plci);
  138. static void adv_voice_write_coefs(PLCI *plci, word write_command);
  139. static void adv_voice_clear_config(PLCI *plci);
  140. static word get_b1_facilities(PLCI *plci, byte b1_resource);
  141. static byte add_b1_facilities(PLCI *plci, byte b1_resource, word b1_facilities);
  142. static void adjust_b1_facilities(PLCI *plci, byte new_b1_resource, word new_b1_facilities);
  143. static word adjust_b_process(dword Id, PLCI *plci, byte Rc);
  144. static void adjust_b1_resource(dword Id, PLCI *plci, API_SAVE *bp_msg, word b1_facilities, word internal_command);
  145. static void adjust_b_restore(dword Id, PLCI *plci, byte Rc);
  146. static void reset_b3_command(dword Id, PLCI *plci, byte Rc);
  147. static void select_b_command(dword Id, PLCI *plci, byte Rc);
  148. static void fax_connect_ack_command(dword Id, PLCI *plci, byte Rc);
  149. static void fax_edata_ack_command(dword Id, PLCI *plci, byte Rc);
  150. static void fax_connect_info_command(dword Id, PLCI *plci, byte Rc);
  151. static void fax_adjust_b23_command(dword Id, PLCI *plci, byte Rc);
  152. static void fax_disconnect_command(dword Id, PLCI *plci, byte Rc);
  153. static void hold_save_command(dword Id, PLCI *plci, byte Rc);
  154. static void retrieve_restore_command(dword Id, PLCI *plci, byte Rc);
  155. static void init_b1_config(PLCI *plci);
  156. static void clear_b1_config(PLCI *plci);
  157. static void dtmf_command(dword Id, PLCI *plci, byte Rc);
  158. static byte dtmf_request(dword Id, word Number, DIVA_CAPI_ADAPTER *a, PLCI *plci, APPL *appl, API_PARSE *msg);
  159. static void dtmf_confirmation(dword Id, PLCI *plci);
  160. static void dtmf_indication(dword Id, PLCI *plci, byte *msg, word length);
  161. static void dtmf_parameter_write(PLCI *plci);
  162. static void mixer_set_bchannel_id_esc(PLCI *plci, byte bchannel_id);
  163. static void mixer_set_bchannel_id(PLCI *plci, byte *chi);
  164. static void mixer_clear_config(PLCI *plci);
  165. static void mixer_notify_update(PLCI *plci, byte others);
  166. static void mixer_command(dword Id, PLCI *plci, byte Rc);
  167. static byte mixer_request(dword Id, word Number, DIVA_CAPI_ADAPTER *a, PLCI *plci, APPL *appl, API_PARSE *msg);
  168. static void mixer_indication_coefs_set(dword Id, PLCI *plci);
  169. static void mixer_indication_xconnect_from(dword Id, PLCI *plci, byte *msg, word length);
  170. static void mixer_indication_xconnect_to(dword Id, PLCI *plci, byte *msg, word length);
  171. static void mixer_remove(PLCI *plci);
  172. static void ec_command(dword Id, PLCI *plci, byte Rc);
  173. static byte ec_request(dword Id, word Number, DIVA_CAPI_ADAPTER *a, PLCI *plci, APPL *appl, API_PARSE *msg);
  174. static void ec_indication(dword Id, PLCI *plci, byte *msg, word length);
  175. static void rtp_connect_b3_req_command(dword Id, PLCI *plci, byte Rc);
  176. static void rtp_connect_b3_res_command(dword Id, PLCI *plci, byte Rc);
  177. static int diva_get_dma_descriptor(PLCI *plci, dword *dma_magic);
  178. static void diva_free_dma_descriptor(PLCI *plci, int nr);
  179. /*------------------------------------------------------------------*/
  180. /* external function prototypes */
  181. /*------------------------------------------------------------------*/
  182. extern byte MapController(byte);
  183. extern byte UnMapController(byte);
  184. #define MapId(Id)(((Id) & 0xffffff00L) | MapController((byte)(Id)))
  185. #define UnMapId(Id)(((Id) & 0xffffff00L) | UnMapController((byte)(Id)))
  186. void sendf(APPL *, word, dword, word, byte *, ...);
  187. void *TransmitBufferSet(APPL *appl, dword ref);
  188. void *TransmitBufferGet(APPL *appl, void *p);
  189. void TransmitBufferFree(APPL *appl, void *p);
  190. void *ReceiveBufferGet(APPL *appl, int Num);
  191. int fax_head_line_time(char *buffer);
  192. /*------------------------------------------------------------------*/
  193. /* Global data definitions */
  194. /*------------------------------------------------------------------*/
  195. extern byte max_adapter;
  196. extern byte max_appl;
  197. extern DIVA_CAPI_ADAPTER *adapter;
  198. extern APPL *application;
  199. static byte remove_started = false;
  200. static PLCI dummy_plci;
  201. static struct _ftable {
  202. word command;
  203. byte *format;
  204. byte (*function)(dword, word, DIVA_CAPI_ADAPTER *, PLCI *, APPL *, API_PARSE *);
  205. } ftable[] = {
  206. {_DATA_B3_R, "dwww", data_b3_req},
  207. {_DATA_B3_I | RESPONSE, "w", data_b3_res},
  208. {_INFO_R, "ss", info_req},
  209. {_INFO_I | RESPONSE, "", info_res},
  210. {_CONNECT_R, "wsssssssss", connect_req},
  211. {_CONNECT_I | RESPONSE, "wsssss", connect_res},
  212. {_CONNECT_ACTIVE_I | RESPONSE, "", connect_a_res},
  213. {_DISCONNECT_R, "s", disconnect_req},
  214. {_DISCONNECT_I | RESPONSE, "", disconnect_res},
  215. {_LISTEN_R, "dddss", listen_req},
  216. {_ALERT_R, "s", alert_req},
  217. {_FACILITY_R, "ws", facility_req},
  218. {_FACILITY_I | RESPONSE, "ws", facility_res},
  219. {_CONNECT_B3_R, "s", connect_b3_req},
  220. {_CONNECT_B3_I | RESPONSE, "ws", connect_b3_res},
  221. {_CONNECT_B3_ACTIVE_I | RESPONSE, "", connect_b3_a_res},
  222. {_DISCONNECT_B3_R, "s", disconnect_b3_req},
  223. {_DISCONNECT_B3_I | RESPONSE, "", disconnect_b3_res},
  224. {_RESET_B3_R, "s", reset_b3_req},
  225. {_RESET_B3_I | RESPONSE, "", reset_b3_res},
  226. {_CONNECT_B3_T90_ACTIVE_I | RESPONSE, "ws", connect_b3_t90_a_res},
  227. {_CONNECT_B3_T90_ACTIVE_I | RESPONSE, "", connect_b3_t90_a_res},
  228. {_SELECT_B_REQ, "s", select_b_req},
  229. {_MANUFACTURER_R, "dws", manufacturer_req},
  230. {_MANUFACTURER_I | RESPONSE, "dws", manufacturer_res},
  231. {_MANUFACTURER_I | RESPONSE, "", manufacturer_res}
  232. };
  233. static byte *cip_bc[29][2] = {
  234. { "", "" }, /* 0 */
  235. { "\x03\x80\x90\xa3", "\x03\x80\x90\xa2" }, /* 1 */
  236. { "\x02\x88\x90", "\x02\x88\x90" }, /* 2 */
  237. { "\x02\x89\x90", "\x02\x89\x90" }, /* 3 */
  238. { "\x03\x90\x90\xa3", "\x03\x90\x90\xa2" }, /* 4 */
  239. { "\x03\x91\x90\xa5", "\x03\x91\x90\xa5" }, /* 5 */
  240. { "\x02\x98\x90", "\x02\x98\x90" }, /* 6 */
  241. { "\x04\x88\xc0\xc6\xe6", "\x04\x88\xc0\xc6\xe6" }, /* 7 */
  242. { "\x04\x88\x90\x21\x8f", "\x04\x88\x90\x21\x8f" }, /* 8 */
  243. { "\x03\x91\x90\xa5", "\x03\x91\x90\xa5" }, /* 9 */
  244. { "", "" }, /* 10 */
  245. { "", "" }, /* 11 */
  246. { "", "" }, /* 12 */
  247. { "", "" }, /* 13 */
  248. { "", "" }, /* 14 */
  249. { "", "" }, /* 15 */
  250. { "\x03\x80\x90\xa3", "\x03\x80\x90\xa2" }, /* 16 */
  251. { "\x03\x90\x90\xa3", "\x03\x90\x90\xa2" }, /* 17 */
  252. { "\x02\x88\x90", "\x02\x88\x90" }, /* 18 */
  253. { "\x02\x88\x90", "\x02\x88\x90" }, /* 19 */
  254. { "\x02\x88\x90", "\x02\x88\x90" }, /* 20 */
  255. { "\x02\x88\x90", "\x02\x88\x90" }, /* 21 */
  256. { "\x02\x88\x90", "\x02\x88\x90" }, /* 22 */
  257. { "\x02\x88\x90", "\x02\x88\x90" }, /* 23 */
  258. { "\x02\x88\x90", "\x02\x88\x90" }, /* 24 */
  259. { "\x02\x88\x90", "\x02\x88\x90" }, /* 25 */
  260. { "\x03\x91\x90\xa5", "\x03\x91\x90\xa5" }, /* 26 */
  261. { "\x03\x91\x90\xa5", "\x03\x91\x90\xa5" }, /* 27 */
  262. { "\x02\x88\x90", "\x02\x88\x90" } /* 28 */
  263. };
  264. static byte *cip_hlc[29] = {
  265. "", /* 0 */
  266. "", /* 1 */
  267. "", /* 2 */
  268. "", /* 3 */
  269. "", /* 4 */
  270. "", /* 5 */
  271. "", /* 6 */
  272. "", /* 7 */
  273. "", /* 8 */
  274. "", /* 9 */
  275. "", /* 10 */
  276. "", /* 11 */
  277. "", /* 12 */
  278. "", /* 13 */
  279. "", /* 14 */
  280. "", /* 15 */
  281. "\x02\x91\x81", /* 16 */
  282. "\x02\x91\x84", /* 17 */
  283. "\x02\x91\xa1", /* 18 */
  284. "\x02\x91\xa4", /* 19 */
  285. "\x02\x91\xa8", /* 20 */
  286. "\x02\x91\xb1", /* 21 */
  287. "\x02\x91\xb2", /* 22 */
  288. "\x02\x91\xb5", /* 23 */
  289. "\x02\x91\xb8", /* 24 */
  290. "\x02\x91\xc1", /* 25 */
  291. "\x02\x91\x81", /* 26 */
  292. "\x03\x91\xe0\x01", /* 27 */
  293. "\x03\x91\xe0\x02" /* 28 */
  294. };
  295. /*------------------------------------------------------------------*/
  296. #define V120_HEADER_LENGTH 1
  297. #define V120_HEADER_EXTEND_BIT 0x80
  298. #define V120_HEADER_BREAK_BIT 0x40
  299. #define V120_HEADER_C1_BIT 0x04
  300. #define V120_HEADER_C2_BIT 0x08
  301. #define V120_HEADER_FLUSH_COND (V120_HEADER_BREAK_BIT | V120_HEADER_C1_BIT | V120_HEADER_C2_BIT)
  302. static byte v120_default_header[] =
  303. {
  304. 0x83 /* Ext, BR , res, res, C2 , C1 , B , F */
  305. };
  306. static byte v120_break_header[] =
  307. {
  308. 0xc3 | V120_HEADER_BREAK_BIT /* Ext, BR , res, res, C2 , C1 , B , F */
  309. };
  310. /*------------------------------------------------------------------*/
  311. /* API_PUT function */
  312. /*------------------------------------------------------------------*/
  313. word api_put(APPL *appl, CAPI_MSG *msg)
  314. {
  315. word i, j, k, l, n;
  316. word ret;
  317. byte c;
  318. byte controller;
  319. DIVA_CAPI_ADAPTER *a;
  320. PLCI *plci;
  321. NCCI *ncci_ptr;
  322. word ncci;
  323. CAPI_MSG *m;
  324. API_PARSE msg_parms[MAX_MSG_PARMS + 1];
  325. if (msg->header.length < sizeof(msg->header) ||
  326. msg->header.length > MAX_MSG_SIZE) {
  327. dbug(1, dprintf("bad len"));
  328. return _BAD_MSG;
  329. }
  330. controller = (byte)((msg->header.controller & 0x7f) - 1);
  331. /* controller starts with 0 up to (max_adapter - 1) */
  332. if (controller >= max_adapter)
  333. {
  334. dbug(1, dprintf("invalid ctrl"));
  335. return _BAD_MSG;
  336. }
  337. a = &adapter[controller];
  338. plci = NULL;
  339. if ((msg->header.plci != 0) && (msg->header.plci <= a->max_plci) && !a->adapter_disabled)
  340. {
  341. dbug(1, dprintf("plci=%x", msg->header.plci));
  342. plci = &a->plci[msg->header.plci - 1];
  343. ncci = GET_WORD(&msg->header.ncci);
  344. if (plci->Id
  345. && (plci->appl
  346. || (plci->State == INC_CON_PENDING)
  347. || (plci->State == INC_CON_ALERT)
  348. || (msg->header.command == (_DISCONNECT_I | RESPONSE)))
  349. && ((ncci == 0)
  350. || (msg->header.command == (_DISCONNECT_B3_I | RESPONSE))
  351. || ((ncci < MAX_NCCI + 1) && (a->ncci_plci[ncci] == plci->Id))))
  352. {
  353. i = plci->msg_in_read_pos;
  354. j = plci->msg_in_write_pos;
  355. if (j >= i)
  356. {
  357. if (j + msg->header.length + MSG_IN_OVERHEAD <= MSG_IN_QUEUE_SIZE)
  358. i += MSG_IN_QUEUE_SIZE - j;
  359. else
  360. j = 0;
  361. }
  362. else
  363. {
  364. n = (((CAPI_MSG *)(plci->msg_in_queue))->header.length + MSG_IN_OVERHEAD + 3) & 0xfffc;
  365. if (i > MSG_IN_QUEUE_SIZE - n)
  366. i = MSG_IN_QUEUE_SIZE - n + 1;
  367. i -= j;
  368. }
  369. if (i <= ((msg->header.length + MSG_IN_OVERHEAD + 3) & 0xfffc))
  370. {
  371. dbug(0, dprintf("Q-FULL1(msg) - len=%d write=%d read=%d wrap=%d free=%d",
  372. msg->header.length, plci->msg_in_write_pos,
  373. plci->msg_in_read_pos, plci->msg_in_wrap_pos, i));
  374. return _QUEUE_FULL;
  375. }
  376. c = false;
  377. if ((((byte *) msg) < ((byte *)(plci->msg_in_queue)))
  378. || (((byte *) msg) >= ((byte *)(plci->msg_in_queue)) + sizeof(plci->msg_in_queue)))
  379. {
  380. if (plci->msg_in_write_pos != plci->msg_in_read_pos)
  381. c = true;
  382. }
  383. if (msg->header.command == _DATA_B3_R)
  384. {
  385. if (msg->header.length < 20)
  386. {
  387. dbug(1, dprintf("DATA_B3 REQ wrong length %d", msg->header.length));
  388. return _BAD_MSG;
  389. }
  390. ncci_ptr = &(a->ncci[ncci]);
  391. n = ncci_ptr->data_pending;
  392. l = ncci_ptr->data_ack_pending;
  393. k = plci->msg_in_read_pos;
  394. while (k != plci->msg_in_write_pos)
  395. {
  396. if (k == plci->msg_in_wrap_pos)
  397. k = 0;
  398. if ((((CAPI_MSG *)(&((byte *)(plci->msg_in_queue))[k]))->header.command == _DATA_B3_R)
  399. && (((CAPI_MSG *)(&((byte *)(plci->msg_in_queue))[k]))->header.ncci == ncci))
  400. {
  401. n++;
  402. if (((CAPI_MSG *)(&((byte *)(plci->msg_in_queue))[k]))->info.data_b3_req.Flags & 0x0004)
  403. l++;
  404. }
  405. k += (((CAPI_MSG *)(&((byte *)(plci->msg_in_queue))[k]))->header.length +
  406. MSG_IN_OVERHEAD + 3) & 0xfffc;
  407. }
  408. if ((n >= MAX_DATA_B3) || (l >= MAX_DATA_ACK))
  409. {
  410. dbug(0, dprintf("Q-FULL2(data) - pending=%d/%d ack_pending=%d/%d",
  411. ncci_ptr->data_pending, n, ncci_ptr->data_ack_pending, l));
  412. return _QUEUE_FULL;
  413. }
  414. if (plci->req_in || plci->internal_command)
  415. {
  416. if ((((byte *) msg) >= ((byte *)(plci->msg_in_queue)))
  417. && (((byte *) msg) < ((byte *)(plci->msg_in_queue)) + sizeof(plci->msg_in_queue)))
  418. {
  419. dbug(0, dprintf("Q-FULL3(requeue)"));
  420. return _QUEUE_FULL;
  421. }
  422. c = true;
  423. }
  424. }
  425. else
  426. {
  427. if (plci->req_in || plci->internal_command)
  428. c = true;
  429. else
  430. {
  431. plci->command = msg->header.command;
  432. plci->number = msg->header.number;
  433. }
  434. }
  435. if (c)
  436. {
  437. dbug(1, dprintf("enqueue msg(0x%04x,0x%x,0x%x) - len=%d write=%d read=%d wrap=%d free=%d",
  438. msg->header.command, plci->req_in, plci->internal_command,
  439. msg->header.length, plci->msg_in_write_pos,
  440. plci->msg_in_read_pos, plci->msg_in_wrap_pos, i));
  441. if (j == 0)
  442. plci->msg_in_wrap_pos = plci->msg_in_write_pos;
  443. m = (CAPI_MSG *)(&((byte *)(plci->msg_in_queue))[j]);
  444. for (i = 0; i < msg->header.length; i++)
  445. ((byte *)(plci->msg_in_queue))[j++] = ((byte *) msg)[i];
  446. if (m->header.command == _DATA_B3_R)
  447. {
  448. m->info.data_b3_req.Data = (dword)(long)(TransmitBufferSet(appl, m->info.data_b3_req.Data));
  449. }
  450. j = (j + 3) & 0xfffc;
  451. *((APPL **)(&((byte *)(plci->msg_in_queue))[j])) = appl;
  452. plci->msg_in_write_pos = j + MSG_IN_OVERHEAD;
  453. return 0;
  454. }
  455. }
  456. else
  457. {
  458. plci = NULL;
  459. }
  460. }
  461. dbug(1, dprintf("com=%x", msg->header.command));
  462. for (j = 0; j < MAX_MSG_PARMS + 1; j++) msg_parms[j].length = 0;
  463. for (i = 0, ret = _BAD_MSG; i < ARRAY_SIZE(ftable); i++) {
  464. if (ftable[i].command == msg->header.command) {
  465. /* break loop if the message is correct, otherwise continue scan */
  466. /* (for example: CONNECT_B3_T90_ACT_RES has two specifications) */
  467. if (!api_parse(msg->info.b, (word)(msg->header.length - 12), ftable[i].format, msg_parms)) {
  468. ret = 0;
  469. break;
  470. }
  471. for (j = 0; j < MAX_MSG_PARMS + 1; j++) msg_parms[j].length = 0;
  472. }
  473. }
  474. if (ret) {
  475. dbug(1, dprintf("BAD_MSG"));
  476. if (plci) plci->command = 0;
  477. return ret;
  478. }
  479. c = ftable[i].function(GET_DWORD(&msg->header.controller),
  480. msg->header.number,
  481. a,
  482. plci,
  483. appl,
  484. msg_parms);
  485. channel_xmit_extended_xon(plci);
  486. if (c == 1) send_req(plci);
  487. if (c == 2 && plci) plci->req_in = plci->req_in_start = plci->req_out = 0;
  488. if (plci && !plci->req_in) plci->command = 0;
  489. return 0;
  490. }
  491. /*------------------------------------------------------------------*/
  492. /* api_parse function, check the format of api messages */
  493. /*------------------------------------------------------------------*/
  494. static word api_parse(byte *msg, word length, byte *format, API_PARSE *parms)
  495. {
  496. word i;
  497. word p;
  498. for (i = 0, p = 0; format[i]; i++) {
  499. if (parms)
  500. {
  501. parms[i].info = &msg[p];
  502. }
  503. switch (format[i]) {
  504. case 'b':
  505. p += 1;
  506. break;
  507. case 'w':
  508. p += 2;
  509. break;
  510. case 'd':
  511. p += 4;
  512. break;
  513. case 's':
  514. if (msg[p] == 0xff) {
  515. parms[i].info += 2;
  516. parms[i].length = msg[p + 1] + (msg[p + 2] << 8);
  517. p += (parms[i].length + 3);
  518. }
  519. else {
  520. parms[i].length = msg[p];
  521. p += (parms[i].length + 1);
  522. }
  523. break;
  524. }
  525. if (p > length) return true;
  526. }
  527. if (parms) parms[i].info = NULL;
  528. return false;
  529. }
  530. static void api_save_msg(API_PARSE *in, byte *format, API_SAVE *out)
  531. {
  532. word i, j, n = 0;
  533. byte *p;
  534. p = out->info;
  535. for (i = 0; format[i] != '\0'; i++)
  536. {
  537. out->parms[i].info = p;
  538. out->parms[i].length = in[i].length;
  539. switch (format[i])
  540. {
  541. case 'b':
  542. n = 1;
  543. break;
  544. case 'w':
  545. n = 2;
  546. break;
  547. case 'd':
  548. n = 4;
  549. break;
  550. case 's':
  551. n = in[i].length + 1;
  552. break;
  553. }
  554. for (j = 0; j < n; j++)
  555. *(p++) = in[i].info[j];
  556. }
  557. out->parms[i].info = NULL;
  558. out->parms[i].length = 0;
  559. }
  560. static void api_load_msg(API_SAVE *in, API_PARSE *out)
  561. {
  562. word i;
  563. i = 0;
  564. do
  565. {
  566. out[i].info = in->parms[i].info;
  567. out[i].length = in->parms[i].length;
  568. } while (in->parms[i++].info);
  569. }
  570. /*------------------------------------------------------------------*/
  571. /* CAPI remove function */
  572. /*------------------------------------------------------------------*/
  573. word api_remove_start(void)
  574. {
  575. word i;
  576. word j;
  577. if (!remove_started) {
  578. remove_started = true;
  579. for (i = 0; i < max_adapter; i++) {
  580. if (adapter[i].request) {
  581. for (j = 0; j < adapter[i].max_plci; j++) {
  582. if (adapter[i].plci[j].Sig.Id) plci_remove(&adapter[i].plci[j]);
  583. }
  584. }
  585. }
  586. return 1;
  587. }
  588. else {
  589. for (i = 0; i < max_adapter; i++) {
  590. if (adapter[i].request) {
  591. for (j = 0; j < adapter[i].max_plci; j++) {
  592. if (adapter[i].plci[j].Sig.Id) return 1;
  593. }
  594. }
  595. }
  596. }
  597. api_remove_complete();
  598. return 0;
  599. }
  600. /*------------------------------------------------------------------*/
  601. /* internal command queue */
  602. /*------------------------------------------------------------------*/
  603. static void init_internal_command_queue(PLCI *plci)
  604. {
  605. word i;
  606. dbug(1, dprintf("%s,%d: init_internal_command_queue",
  607. (char *)(FILE_), __LINE__));
  608. plci->internal_command = 0;
  609. for (i = 0; i < MAX_INTERNAL_COMMAND_LEVELS; i++)
  610. plci->internal_command_queue[i] = NULL;
  611. }
  612. static void start_internal_command(dword Id, PLCI *plci, t_std_internal_command command_function)
  613. {
  614. word i;
  615. dbug(1, dprintf("[%06lx] %s,%d: start_internal_command",
  616. UnMapId(Id), (char *)(FILE_), __LINE__));
  617. if (plci->internal_command == 0)
  618. {
  619. plci->internal_command_queue[0] = command_function;
  620. (*command_function)(Id, plci, OK);
  621. }
  622. else
  623. {
  624. i = 1;
  625. while (plci->internal_command_queue[i] != NULL)
  626. i++;
  627. plci->internal_command_queue[i] = command_function;
  628. }
  629. }
  630. static void next_internal_command(dword Id, PLCI *plci)
  631. {
  632. word i;
  633. dbug(1, dprintf("[%06lx] %s,%d: next_internal_command",
  634. UnMapId(Id), (char *)(FILE_), __LINE__));
  635. plci->internal_command = 0;
  636. plci->internal_command_queue[0] = NULL;
  637. while (plci->internal_command_queue[1] != NULL)
  638. {
  639. for (i = 0; i < MAX_INTERNAL_COMMAND_LEVELS - 1; i++)
  640. plci->internal_command_queue[i] = plci->internal_command_queue[i + 1];
  641. plci->internal_command_queue[MAX_INTERNAL_COMMAND_LEVELS - 1] = NULL;
  642. (*(plci->internal_command_queue[0]))(Id, plci, OK);
  643. if (plci->internal_command != 0)
  644. return;
  645. plci->internal_command_queue[0] = NULL;
  646. }
  647. }
  648. /*------------------------------------------------------------------*/
  649. /* NCCI allocate/remove function */
  650. /*------------------------------------------------------------------*/
  651. static dword ncci_mapping_bug = 0;
  652. static word get_ncci(PLCI *plci, byte ch, word force_ncci)
  653. {
  654. DIVA_CAPI_ADAPTER *a;
  655. word ncci, i, j, k;
  656. a = plci->adapter;
  657. if (!ch || a->ch_ncci[ch])
  658. {
  659. ncci_mapping_bug++;
  660. dbug(1, dprintf("NCCI mapping exists %ld %02x %02x %02x-%02x",
  661. ncci_mapping_bug, ch, force_ncci, a->ncci_ch[a->ch_ncci[ch]], a->ch_ncci[ch]));
  662. ncci = ch;
  663. }
  664. else
  665. {
  666. if (force_ncci)
  667. ncci = force_ncci;
  668. else
  669. {
  670. if ((ch < MAX_NCCI + 1) && !a->ncci_ch[ch])
  671. ncci = ch;
  672. else
  673. {
  674. ncci = 1;
  675. while ((ncci < MAX_NCCI + 1) && a->ncci_ch[ncci])
  676. ncci++;
  677. if (ncci == MAX_NCCI + 1)
  678. {
  679. ncci_mapping_bug++;
  680. i = 1;
  681. do
  682. {
  683. j = 1;
  684. while ((j < MAX_NCCI + 1) && (a->ncci_ch[j] != i))
  685. j++;
  686. k = j;
  687. if (j < MAX_NCCI + 1)
  688. {
  689. do
  690. {
  691. j++;
  692. } while ((j < MAX_NCCI + 1) && (a->ncci_ch[j] != i));
  693. }
  694. } while ((i < MAX_NL_CHANNEL + 1) && (j < MAX_NCCI + 1));
  695. if (i < MAX_NL_CHANNEL + 1)
  696. {
  697. dbug(1, dprintf("NCCI mapping overflow %ld %02x %02x %02x-%02x-%02x",
  698. ncci_mapping_bug, ch, force_ncci, i, k, j));
  699. }
  700. else
  701. {
  702. dbug(1, dprintf("NCCI mapping overflow %ld %02x %02x",
  703. ncci_mapping_bug, ch, force_ncci));
  704. }
  705. ncci = ch;
  706. }
  707. }
  708. a->ncci_plci[ncci] = plci->Id;
  709. a->ncci_state[ncci] = IDLE;
  710. if (!plci->ncci_ring_list)
  711. plci->ncci_ring_list = ncci;
  712. else
  713. a->ncci_next[ncci] = a->ncci_next[plci->ncci_ring_list];
  714. a->ncci_next[plci->ncci_ring_list] = (byte) ncci;
  715. }
  716. a->ncci_ch[ncci] = ch;
  717. a->ch_ncci[ch] = (byte) ncci;
  718. dbug(1, dprintf("NCCI mapping established %ld %02x %02x %02x-%02x",
  719. ncci_mapping_bug, ch, force_ncci, ch, ncci));
  720. }
  721. return (ncci);
  722. }
  723. static void ncci_free_receive_buffers(PLCI *plci, word ncci)
  724. {
  725. DIVA_CAPI_ADAPTER *a;
  726. APPL *appl;
  727. word i, ncci_code;
  728. dword Id;
  729. a = plci->adapter;
  730. Id = (((dword) ncci) << 16) | (((word)(plci->Id)) << 8) | a->Id;
  731. if (ncci)
  732. {
  733. if (a->ncci_plci[ncci] == plci->Id)
  734. {
  735. if (!plci->appl)
  736. {
  737. ncci_mapping_bug++;
  738. dbug(1, dprintf("NCCI mapping appl expected %ld %08lx",
  739. ncci_mapping_bug, Id));
  740. }
  741. else
  742. {
  743. appl = plci->appl;
  744. ncci_code = ncci | (((word) a->Id) << 8);
  745. for (i = 0; i < appl->MaxBuffer; i++)
  746. {
  747. if ((appl->DataNCCI[i] == ncci_code)
  748. && (((byte)(appl->DataFlags[i] >> 8)) == plci->Id))
  749. {
  750. appl->DataNCCI[i] = 0;
  751. }
  752. }
  753. }
  754. }
  755. }
  756. else
  757. {
  758. for (ncci = 1; ncci < MAX_NCCI + 1; ncci++)
  759. {
  760. if (a->ncci_plci[ncci] == plci->Id)
  761. {
  762. if (!plci->appl)
  763. {
  764. ncci_mapping_bug++;
  765. dbug(1, dprintf("NCCI mapping no appl %ld %08lx",
  766. ncci_mapping_bug, Id));
  767. }
  768. else
  769. {
  770. appl = plci->appl;
  771. ncci_code = ncci | (((word) a->Id) << 8);
  772. for (i = 0; i < appl->MaxBuffer; i++)
  773. {
  774. if ((appl->DataNCCI[i] == ncci_code)
  775. && (((byte)(appl->DataFlags[i] >> 8)) == plci->Id))
  776. {
  777. appl->DataNCCI[i] = 0;
  778. }
  779. }
  780. }
  781. }
  782. }
  783. }
  784. }
  785. static void cleanup_ncci_data(PLCI *plci, word ncci)
  786. {
  787. NCCI *ncci_ptr;
  788. if (ncci && (plci->adapter->ncci_plci[ncci] == plci->Id))
  789. {
  790. ncci_ptr = &(plci->adapter->ncci[ncci]);
  791. if (plci->appl)
  792. {
  793. while (ncci_ptr->data_pending != 0)
  794. {
  795. if (!plci->data_sent || (ncci_ptr->DBuffer[ncci_ptr->data_out].P != plci->data_sent_ptr))
  796. TransmitBufferFree(plci->appl, ncci_ptr->DBuffer[ncci_ptr->data_out].P);
  797. (ncci_ptr->data_out)++;
  798. if (ncci_ptr->data_out == MAX_DATA_B3)
  799. ncci_ptr->data_out = 0;
  800. (ncci_ptr->data_pending)--;
  801. }
  802. }
  803. ncci_ptr->data_out = 0;
  804. ncci_ptr->data_pending = 0;
  805. ncci_ptr->data_ack_out = 0;
  806. ncci_ptr->data_ack_pending = 0;
  807. }
  808. }
  809. static void ncci_remove(PLCI *plci, word ncci, byte preserve_ncci)
  810. {
  811. DIVA_CAPI_ADAPTER *a;
  812. dword Id;
  813. word i;
  814. a = plci->adapter;
  815. Id = (((dword) ncci) << 16) | (((word)(plci->Id)) << 8) | a->Id;
  816. if (!preserve_ncci)
  817. ncci_free_receive_buffers(plci, ncci);
  818. if (ncci)
  819. {
  820. if (a->ncci_plci[ncci] != plci->Id)
  821. {
  822. ncci_mapping_bug++;
  823. dbug(1, dprintf("NCCI mapping doesn't exist %ld %08lx %02x",
  824. ncci_mapping_bug, Id, preserve_ncci));
  825. }
  826. else
  827. {
  828. cleanup_ncci_data(plci, ncci);
  829. dbug(1, dprintf("NCCI mapping released %ld %08lx %02x %02x-%02x",
  830. ncci_mapping_bug, Id, preserve_ncci, a->ncci_ch[ncci], ncci));
  831. a->ch_ncci[a->ncci_ch[ncci]] = 0;
  832. if (!preserve_ncci)
  833. {
  834. a->ncci_ch[ncci] = 0;
  835. a->ncci_plci[ncci] = 0;
  836. a->ncci_state[ncci] = IDLE;
  837. i = plci->ncci_ring_list;
  838. while ((i != 0) && (a->ncci_next[i] != plci->ncci_ring_list) && (a->ncci_next[i] != ncci))
  839. i = a->ncci_next[i];
  840. if ((i != 0) && (a->ncci_next[i] == ncci))
  841. {
  842. if (i == ncci)
  843. plci->ncci_ring_list = 0;
  844. else if (plci->ncci_ring_list == ncci)
  845. plci->ncci_ring_list = i;
  846. a->ncci_next[i] = a->ncci_next[ncci];
  847. }
  848. a->ncci_next[ncci] = 0;
  849. }
  850. }
  851. }
  852. else
  853. {
  854. for (ncci = 1; ncci < MAX_NCCI + 1; ncci++)
  855. {
  856. if (a->ncci_plci[ncci] == plci->Id)
  857. {
  858. cleanup_ncci_data(plci, ncci);
  859. dbug(1, dprintf("NCCI mapping released %ld %08lx %02x %02x-%02x",
  860. ncci_mapping_bug, Id, preserve_ncci, a->ncci_ch[ncci], ncci));
  861. a->ch_ncci[a->ncci_ch[ncci]] = 0;
  862. if (!preserve_ncci)
  863. {
  864. a->ncci_ch[ncci] = 0;
  865. a->ncci_plci[ncci] = 0;
  866. a->ncci_state[ncci] = IDLE;
  867. a->ncci_next[ncci] = 0;
  868. }
  869. }
  870. }
  871. if (!preserve_ncci)
  872. plci->ncci_ring_list = 0;
  873. }
  874. }
  875. /*------------------------------------------------------------------*/
  876. /* PLCI remove function */
  877. /*------------------------------------------------------------------*/
  878. static void plci_free_msg_in_queue(PLCI *plci)
  879. {
  880. word i;
  881. if (plci->appl)
  882. {
  883. i = plci->msg_in_read_pos;
  884. while (i != plci->msg_in_write_pos)
  885. {
  886. if (i == plci->msg_in_wrap_pos)
  887. i = 0;
  888. if (((CAPI_MSG *)(&((byte *)(plci->msg_in_queue))[i]))->header.command == _DATA_B3_R)
  889. {
  890. TransmitBufferFree(plci->appl,
  891. (byte *)(long)(((CAPI_MSG *)(&((byte *)(plci->msg_in_queue))[i]))->info.data_b3_req.Data));
  892. }
  893. i += (((CAPI_MSG *)(&((byte *)(plci->msg_in_queue))[i]))->header.length +
  894. MSG_IN_OVERHEAD + 3) & 0xfffc;
  895. }
  896. }
  897. plci->msg_in_write_pos = MSG_IN_QUEUE_SIZE;
  898. plci->msg_in_read_pos = MSG_IN_QUEUE_SIZE;
  899. plci->msg_in_wrap_pos = MSG_IN_QUEUE_SIZE;
  900. }
  901. static void plci_remove(PLCI *plci)
  902. {
  903. if (!plci) {
  904. dbug(1, dprintf("plci_remove(no plci)"));
  905. return;
  906. }
  907. init_internal_command_queue(plci);
  908. dbug(1, dprintf("plci_remove(%x,tel=%x)", plci->Id, plci->tel));
  909. if (plci_remove_check(plci))
  910. {
  911. return;
  912. }
  913. if (plci->Sig.Id == 0xff)
  914. {
  915. dbug(1, dprintf("D-channel X.25 plci->NL.Id:%0x", plci->NL.Id));
  916. if (plci->NL.Id && !plci->nl_remove_id)
  917. {
  918. nl_req_ncci(plci, REMOVE, 0);
  919. send_req(plci);
  920. }
  921. }
  922. else
  923. {
  924. if (!plci->sig_remove_id
  925. && (plci->Sig.Id
  926. || (plci->req_in != plci->req_out)
  927. || (plci->nl_req || plci->sig_req)))
  928. {
  929. sig_req(plci, HANGUP, 0);
  930. send_req(plci);
  931. }
  932. }
  933. ncci_remove(plci, 0, false);
  934. plci_free_msg_in_queue(plci);
  935. plci->channels = 0;
  936. plci->appl = NULL;
  937. if ((plci->State == INC_CON_PENDING) || (plci->State == INC_CON_ALERT))
  938. plci->State = OUTG_DIS_PENDING;
  939. }
  940. /*------------------------------------------------------------------*/
  941. /* translation function for each message */
  942. /*------------------------------------------------------------------*/
  943. static byte connect_req(dword Id, word Number, DIVA_CAPI_ADAPTER *a,
  944. PLCI *plci, APPL *appl, API_PARSE *parms)
  945. {
  946. word ch;
  947. word i;
  948. word Info;
  949. byte LinkLayer;
  950. API_PARSE *ai;
  951. API_PARSE *bp;
  952. API_PARSE ai_parms[5];
  953. word channel = 0;
  954. dword ch_mask;
  955. byte m;
  956. static byte esc_chi[35] = {0x02, 0x18, 0x01};
  957. static byte lli[2] = {0x01, 0x00};
  958. byte noCh = 0;
  959. word dir = 0;
  960. byte *p_chi = "";
  961. for (i = 0; i < 5; i++) ai_parms[i].length = 0;
  962. dbug(1, dprintf("connect_req(%d)", parms->length));
  963. Info = _WRONG_IDENTIFIER;
  964. if (a)
  965. {
  966. if (a->adapter_disabled)
  967. {
  968. dbug(1, dprintf("adapter disabled"));
  969. Id = ((word)1 << 8) | a->Id;
  970. sendf(appl, _CONNECT_R | CONFIRM, Id, Number, "w", 0);
  971. sendf(appl, _DISCONNECT_I, Id, 0, "w", _L1_ERROR);
  972. return false;
  973. }
  974. Info = _OUT_OF_PLCI;
  975. if ((i = get_plci(a)))
  976. {
  977. Info = 0;
  978. plci = &a->plci[i - 1];
  979. plci->appl = appl;
  980. plci->call_dir = CALL_DIR_OUT | CALL_DIR_ORIGINATE;
  981. /* check 'external controller' bit for codec support */
  982. if (Id & EXT_CONTROLLER)
  983. {
  984. if (AdvCodecSupport(a, plci, appl, 0))
  985. {
  986. plci->Id = 0;
  987. sendf(appl, _CONNECT_R | CONFIRM, Id, Number, "w", _WRONG_IDENTIFIER);
  988. return 2;
  989. }
  990. }
  991. ai = &parms[9];
  992. bp = &parms[5];
  993. ch = 0;
  994. if (bp->length)LinkLayer = bp->info[3];
  995. else LinkLayer = 0;
  996. if (ai->length)
  997. {
  998. ch = 0xffff;
  999. if (!api_parse(&ai->info[1], (word)ai->length, "ssss", ai_parms))
  1000. {
  1001. ch = 0;
  1002. if (ai_parms[0].length)
  1003. {
  1004. ch = GET_WORD(ai_parms[0].info + 1);
  1005. if (ch > 4) ch = 0; /* safety -> ignore ChannelID */
  1006. if (ch == 4) /* explizit CHI in message */
  1007. {
  1008. /* check length of B-CH struct */
  1009. if ((ai_parms[0].info)[3] >= 1)
  1010. {
  1011. if ((ai_parms[0].info)[4] == CHI)
  1012. {
  1013. p_chi = &((ai_parms[0].info)[5]);
  1014. }
  1015. else
  1016. {
  1017. p_chi = &((ai_parms[0].info)[3]);
  1018. }
  1019. if (p_chi[0] > 35) /* check length of channel ID */
  1020. {
  1021. Info = _WRONG_MESSAGE_FORMAT;
  1022. }
  1023. }
  1024. else Info = _WRONG_MESSAGE_FORMAT;
  1025. }
  1026. if (ch == 3 && ai_parms[0].length >= 7 && ai_parms[0].length <= 36)
  1027. {
  1028. dir = GET_WORD(ai_parms[0].info + 3);
  1029. ch_mask = 0;
  1030. m = 0x3f;
  1031. for (i = 0; i + 5 <= ai_parms[0].length; i++)
  1032. {
  1033. if (ai_parms[0].info[i + 5] != 0)
  1034. {
  1035. if ((ai_parms[0].info[i + 5] | m) != 0xff)
  1036. Info = _WRONG_MESSAGE_FORMAT;
  1037. else
  1038. {
  1039. if (ch_mask == 0)
  1040. channel = i;
  1041. ch_mask |= 1L << i;
  1042. }
  1043. }
  1044. m = 0;
  1045. }
  1046. if (ch_mask == 0)
  1047. Info = _WRONG_MESSAGE_FORMAT;
  1048. if (!Info)
  1049. {
  1050. if ((ai_parms[0].length == 36) || (ch_mask != ((dword)(1L << channel))))
  1051. {
  1052. esc_chi[0] = (byte)(ai_parms[0].length - 2);
  1053. for (i = 0; i + 5 <= ai_parms[0].length; i++)
  1054. esc_chi[i + 3] = ai_parms[0].info[i + 5];
  1055. }
  1056. else
  1057. esc_chi[0] = 2;
  1058. esc_chi[2] = (byte)channel;
  1059. plci->b_channel = (byte)channel; /* not correct for ETSI ch 17..31 */
  1060. add_p(plci, LLI, lli);
  1061. add_p(plci, ESC, esc_chi);
  1062. plci->State = LOCAL_CONNECT;
  1063. if (!dir) plci->call_dir |= CALL_DIR_FORCE_OUTG_NL; /* dir 0=DTE, 1=DCE */
  1064. }
  1065. }
  1066. }
  1067. }
  1068. else Info = _WRONG_MESSAGE_FORMAT;
  1069. }
  1070. dbug(1, dprintf("ch=%x,dir=%x,p_ch=%d", ch, dir, channel));
  1071. plci->command = _CONNECT_R;
  1072. plci->number = Number;
  1073. /* x.31 or D-ch free SAPI in LinkLayer? */
  1074. if (ch == 1 && LinkLayer != 3 && LinkLayer != 12) noCh = true;
  1075. if ((ch == 0 || ch == 2 || noCh || ch == 3 || ch == 4) && !Info)
  1076. {
  1077. /* B-channel used for B3 connections (ch==0), or no B channel */
  1078. /* is used (ch==2) or perm. connection (3) is used do a CALL */
  1079. if (noCh) Info = add_b1(plci, &parms[5], 2, 0); /* no resource */
  1080. else Info = add_b1(plci, &parms[5], ch, 0);
  1081. add_s(plci, OAD, &parms[2]);
  1082. add_s(plci, OSA, &parms[4]);
  1083. add_s(plci, BC, &parms[6]);
  1084. add_s(plci, LLC, &parms[7]);
  1085. add_s(plci, HLC, &parms[8]);
  1086. if (a->Info_Mask[appl->Id - 1] & 0x200)
  1087. {
  1088. /* early B3 connect (CIP mask bit 9) no release after a disc */
  1089. add_p(plci, LLI, "\x01\x01");
  1090. }
  1091. if (GET_WORD(parms[0].info) < 29) {
  1092. add_p(plci, BC, cip_bc[GET_WORD(parms[0].info)][a->u_law]);
  1093. add_p(plci, HLC, cip_hlc[GET_WORD(parms[0].info)]);
  1094. }
  1095. add_p(plci, UID, "\x06\x43\x61\x70\x69\x32\x30");
  1096. sig_req(plci, ASSIGN, DSIG_ID);
  1097. }
  1098. else if (ch == 1) {
  1099. /* D-Channel used for B3 connections */
  1100. plci->Sig.Id = 0xff;
  1101. Info = 0;
  1102. }
  1103. if (!Info && ch != 2 && !noCh) {
  1104. Info = add_b23(plci, &parms[5]);
  1105. if (!Info) {
  1106. if (!(plci->tel && !plci->adv_nl))nl_req_ncci(plci, ASSIGN, 0);
  1107. }
  1108. }
  1109. if (!Info)
  1110. {
  1111. if (ch == 0 || ch == 2 || ch == 3 || noCh || ch == 4)
  1112. {
  1113. if (plci->spoofed_msg == SPOOFING_REQUIRED)
  1114. {
  1115. api_save_msg(parms, "wsssssssss", &plci->saved_msg);
  1116. plci->spoofed_msg = CALL_REQ;
  1117. plci->internal_command = BLOCK_PLCI;
  1118. plci->command = 0;
  1119. dbug(1, dprintf("Spoof"));
  1120. send_req(plci);
  1121. return false;
  1122. }
  1123. if (ch == 4)add_p(plci, CHI, p_chi);
  1124. add_s(plci, CPN, &parms[1]);
  1125. add_s(plci, DSA, &parms[3]);
  1126. if (noCh) add_p(plci, ESC, "\x02\x18\xfd"); /* D-channel, no B-L3 */
  1127. add_ai(plci, &parms[9]);
  1128. if (!dir)sig_req(plci, CALL_REQ, 0);
  1129. else
  1130. {
  1131. plci->command = PERM_LIST_REQ;
  1132. plci->appl = appl;
  1133. sig_req(plci, LISTEN_REQ, 0);
  1134. send_req(plci);
  1135. return false;
  1136. }
  1137. }
  1138. send_req(plci);
  1139. return false;
  1140. }
  1141. plci->Id = 0;
  1142. }
  1143. }
  1144. sendf(appl,
  1145. _CONNECT_R | CONFIRM,
  1146. Id,
  1147. Number,
  1148. "w", Info);
  1149. return 2;
  1150. }
  1151. static byte connect_res(dword Id, word Number, DIVA_CAPI_ADAPTER *a,
  1152. PLCI *plci, APPL *appl, API_PARSE *parms)
  1153. {
  1154. word i, Info;
  1155. word Reject;
  1156. static byte cau_t[] = {0, 0, 0x90, 0x91, 0xac, 0x9d, 0x86, 0xd8, 0x9b};
  1157. static byte esc_t[] = {0x03, 0x08, 0x00, 0x00};
  1158. API_PARSE *ai;
  1159. API_PARSE ai_parms[5];
  1160. word ch = 0;
  1161. if (!plci) {
  1162. dbug(1, dprintf("connect_res(no plci)"));
  1163. return 0; /* no plci, no send */
  1164. }
  1165. dbug(1, dprintf("connect_res(State=0x%x)", plci->State));
  1166. for (i = 0; i < 5; i++) ai_parms[i].length = 0;
  1167. ai = &parms[5];
  1168. dbug(1, dprintf("ai->length=%d", ai->length));
  1169. if (ai->length)
  1170. {
  1171. if (!api_parse(&ai->info[1], (word)ai->length, "ssss", ai_parms))
  1172. {
  1173. dbug(1, dprintf("ai_parms[0].length=%d/0x%x", ai_parms[0].length, GET_WORD(ai_parms[0].info + 1)));
  1174. ch = 0;
  1175. if (ai_parms[0].length)
  1176. {
  1177. ch = GET_WORD(ai_parms[0].info + 1);
  1178. dbug(1, dprintf("BCH-I=0x%x", ch));
  1179. }
  1180. }
  1181. }
  1182. if (plci->State == INC_CON_CONNECTED_ALERT)
  1183. {
  1184. dbug(1, dprintf("Connected Alert Call_Res"));
  1185. if (a->Info_Mask[appl->Id - 1] & 0x200)
  1186. {
  1187. /* early B3 connect (CIP mask bit 9) no release after a disc */
  1188. add_p(plci, LLI, "\x01\x01");
  1189. }
  1190. add_s(plci, CONN_NR, &parms[2]);
  1191. add_s(plci, LLC, &parms[4]);
  1192. add_ai(plci, &parms[5]);
  1193. plci->State = INC_CON_ACCEPT;
  1194. sig_req(plci, CALL_RES, 0);
  1195. return 1;
  1196. }
  1197. else if (plci->State == INC_CON_PENDING || plci->State == INC_CON_ALERT) {
  1198. __clear_bit(appl->Id - 1, plci->c_ind_mask_table);
  1199. dbug(1, dprintf("c_ind_mask =%*pb", MAX_APPL, plci->c_ind_mask_table));
  1200. Reject = GET_WORD(parms[0].info);
  1201. dbug(1, dprintf("Reject=0x%x", Reject));
  1202. if (Reject)
  1203. {
  1204. if (bitmap_empty(plci->c_ind_mask_table, MAX_APPL))
  1205. {
  1206. if ((Reject & 0xff00) == 0x3400)
  1207. {
  1208. esc_t[2] = ((byte)(Reject & 0x00ff)) | 0x80;
  1209. add_p(plci, ESC, esc_t);
  1210. add_ai(plci, &parms[5]);
  1211. sig_req(plci, REJECT, 0);
  1212. }
  1213. else if (Reject == 1 || Reject >= 9)
  1214. {
  1215. add_ai(plci, &parms[5]);
  1216. sig_req(plci, HANGUP, 0);
  1217. }
  1218. else
  1219. {
  1220. esc_t[2] = cau_t[(Reject&0x000f)];
  1221. add_p(plci, ESC, esc_t);
  1222. add_ai(plci, &parms[5]);
  1223. sig_req(plci, REJECT, 0);
  1224. }
  1225. plci->appl = appl;
  1226. }
  1227. else
  1228. {
  1229. sendf(appl, _DISCONNECT_I, Id, 0, "w", _OTHER_APPL_CONNECTED);
  1230. }
  1231. }
  1232. else {
  1233. plci->appl = appl;
  1234. if (Id & EXT_CONTROLLER) {
  1235. if (AdvCodecSupport(a, plci, appl, 0)) {
  1236. dbug(1, dprintf("connect_res(error from AdvCodecSupport)"));
  1237. sig_req(plci, HANGUP, 0);
  1238. return 1;
  1239. }
  1240. if (plci->tel == ADV_VOICE && a->AdvCodecPLCI)
  1241. {
  1242. Info = add_b23(plci, &parms[1]);
  1243. if (Info)
  1244. {
  1245. dbug(1, dprintf("connect_res(error from add_b23)"));
  1246. sig_req(plci, HANGUP, 0);
  1247. return 1;
  1248. }
  1249. if (plci->adv_nl)
  1250. {
  1251. nl_req_ncci(plci, ASSIGN, 0);
  1252. }
  1253. }
  1254. }
  1255. else
  1256. {
  1257. plci->tel = 0;
  1258. if (ch != 2)
  1259. {
  1260. Info = add_b23(plci, &parms[1]);
  1261. if (Info)
  1262. {
  1263. dbug(1, dprintf("connect_res(error from add_b23 2)"));
  1264. sig_req(plci, HANGUP, 0);
  1265. return 1;
  1266. }
  1267. }
  1268. nl_req_ncci(plci, ASSIGN, 0);
  1269. }
  1270. if (plci->spoofed_msg == SPOOFING_REQUIRED)
  1271. {
  1272. api_save_msg(parms, "wsssss", &plci->saved_msg);
  1273. plci->spoofed_msg = CALL_RES;
  1274. plci->internal_command = BLOCK_PLCI;
  1275. plci->command = 0;
  1276. dbug(1, dprintf("Spoof"));
  1277. }
  1278. else
  1279. {
  1280. add_b1(plci, &parms[1], ch, plci->B1_facilities);
  1281. if (a->Info_Mask[appl->Id - 1] & 0x200)
  1282. {
  1283. /* early B3 connect (CIP mask bit 9) no release after a disc */
  1284. add_p(plci, LLI, "\x01\x01");
  1285. }
  1286. add_s(plci, CONN_NR, &parms[2]);
  1287. add_s(plci, LLC, &parms[4]);
  1288. add_ai(plci, &parms[5]);
  1289. plci->State = INC_CON_ACCEPT;
  1290. sig_req(plci, CALL_RES, 0);
  1291. }
  1292. for_each_set_bit(i, plci->c_ind_mask_table, max_appl)
  1293. sendf(&application[i], _DISCONNECT_I, Id, 0, "w", _OTHER_APPL_CONNECTED);
  1294. }
  1295. }
  1296. return 1;
  1297. }
  1298. static byte connect_a_res(dword Id, word Number, DIVA_CAPI_ADAPTER *a,
  1299. PLCI *plci, APPL *appl, API_PARSE *msg)
  1300. {
  1301. dbug(1, dprintf("connect_a_res"));
  1302. return false;
  1303. }
  1304. static byte disconnect_req(dword Id, word Number, DIVA_CAPI_ADAPTER *a,
  1305. PLCI *plci, APPL *appl, API_PARSE *msg)
  1306. {
  1307. word Info;
  1308. word i;
  1309. dbug(1, dprintf("disconnect_req"));
  1310. Info = _WRONG_IDENTIFIER;
  1311. if (plci)
  1312. {
  1313. if (plci->State == INC_CON_PENDING || plci->State == INC_CON_ALERT)
  1314. {
  1315. __clear_bit(appl->Id - 1, plci->c_ind_mask_table);
  1316. plci->appl = appl;
  1317. for_each_set_bit(i, plci->c_ind_mask_table, max_appl)
  1318. sendf(&application[i], _DISCONNECT_I, Id, 0, "w", 0);
  1319. plci->State = OUTG_DIS_PENDING;
  1320. }
  1321. if (plci->Sig.Id && plci->appl)
  1322. {
  1323. Info = 0;
  1324. if (plci->Sig.Id != 0xff)
  1325. {
  1326. if (plci->State != INC_DIS_PENDING)
  1327. {
  1328. add_ai(plci, &msg[0]);
  1329. sig_req(plci, HANGUP, 0);
  1330. plci->State = OUTG_DIS_PENDING;
  1331. return 1;
  1332. }
  1333. }
  1334. else
  1335. {
  1336. if (plci->NL.Id && !plci->nl_remove_id)
  1337. {
  1338. mixer_remove(plci);
  1339. nl_req_ncci(plci, REMOVE, 0);
  1340. sendf(appl, _DISCONNECT_R | CONFIRM, Id, Number, "w", 0);
  1341. sendf(appl, _DISCONNECT_I, Id, 0, "w", 0);
  1342. plci->State = INC_DIS_PENDING;
  1343. }
  1344. return 1;
  1345. }
  1346. }
  1347. }
  1348. if (!appl) return false;
  1349. sendf(appl, _DISCONNECT_R | CONFIRM, Id, Number, "w", Info);
  1350. return false;
  1351. }
  1352. static byte disconnect_res(dword Id, word Number, DIVA_CAPI_ADAPTER *a,
  1353. PLCI *plci, APPL *appl, API_PARSE *msg)
  1354. {
  1355. dbug(1, dprintf("disconnect_res"));
  1356. if (plci)
  1357. {
  1358. /* clear ind mask bit, just in case of collsion of */
  1359. /* DISCONNECT_IND and CONNECT_RES */
  1360. __clear_bit(appl->Id - 1, plci->c_ind_mask_table);
  1361. ncci_free_receive_buffers(plci, 0);
  1362. if (plci_remove_check(plci))
  1363. {
  1364. return 0;
  1365. }
  1366. if (plci->State == INC_DIS_PENDING
  1367. || plci->State == SUSPENDING) {
  1368. if (bitmap_empty(plci->c_ind_mask_table, MAX_APPL)) {
  1369. if (plci->State != SUSPENDING) plci->State = IDLE;
  1370. dbug(1, dprintf("chs=%d", plci->channels));
  1371. if (!plci->channels) {
  1372. plci_remove(plci);
  1373. }
  1374. }
  1375. }
  1376. }
  1377. return 0;
  1378. }
  1379. static byte listen_req(dword Id, word Number, DIVA_CAPI_ADAPTER *a,
  1380. PLCI *plci, APPL *appl, API_PARSE *parms)
  1381. {
  1382. word Info;
  1383. byte i;
  1384. dbug(1, dprintf("listen_req(Appl=0x%x)", appl->Id));
  1385. Info = _WRONG_IDENTIFIER;
  1386. if (a) {
  1387. Info = 0;
  1388. a->Info_Mask[appl->Id - 1] = GET_DWORD(parms[0].info);
  1389. a->CIP_Mask[appl->Id - 1] = GET_DWORD(parms[1].info);
  1390. dbug(1, dprintf("CIP_MASK=0x%lx", GET_DWORD(parms[1].info)));
  1391. if (a->Info_Mask[appl->Id - 1] & 0x200) { /* early B3 connect provides */
  1392. a->Info_Mask[appl->Id - 1] |= 0x10; /* call progression infos */
  1393. }
  1394. /* check if external controller listen and switch listen on or off*/
  1395. if (Id&EXT_CONTROLLER && GET_DWORD(parms[1].info)) {
  1396. if (a->profile.Global_Options & ON_BOARD_CODEC) {
  1397. dummy_plci.State = IDLE;
  1398. a->codec_listen[appl->Id - 1] = &dummy_plci;
  1399. a->TelOAD[0] = (byte)(parms[3].length);
  1400. for (i = 1; parms[3].length >= i && i < 22; i++) {
  1401. a->TelOAD[i] = parms[3].info[i];
  1402. }
  1403. a->TelOAD[i] = 0;
  1404. a->TelOSA[0] = (byte)(parms[4].length);
  1405. for (i = 1; parms[4].length >= i && i < 22; i++) {
  1406. a->TelOSA[i] = parms[4].info[i];
  1407. }
  1408. a->TelOSA[i] = 0;
  1409. }
  1410. else Info = 0x2002; /* wrong controller, codec not supported */
  1411. }
  1412. else{ /* clear listen */
  1413. a->codec_listen[appl->Id - 1] = (PLCI *)0;
  1414. }
  1415. }
  1416. sendf(appl,
  1417. _LISTEN_R | CONFIRM,
  1418. Id,
  1419. Number,
  1420. "w", Info);
  1421. if (a) listen_check(a);
  1422. return false;
  1423. }
  1424. static byte info_req(dword Id, word Number, DIVA_CAPI_ADAPTER *a,
  1425. PLCI *plci, APPL *appl, API_PARSE *msg)
  1426. {
  1427. word i;
  1428. API_PARSE *ai;
  1429. PLCI *rc_plci = NULL;
  1430. API_PARSE ai_parms[5];
  1431. word Info = 0;
  1432. dbug(1, dprintf("info_req"));
  1433. for (i = 0; i < 5; i++) ai_parms[i].length = 0;
  1434. ai = &msg[1];
  1435. if (ai->length)
  1436. {
  1437. if (api_parse(&ai->info[1], (word)ai->length, "ssss", ai_parms))
  1438. {
  1439. dbug(1, dprintf("AddInfo wrong"));
  1440. Info = _WRONG_MESSAGE_FORMAT;
  1441. }
  1442. }
  1443. if (!a) Info = _WRONG_STATE;
  1444. if (!Info && plci)
  1445. { /* no fac, with CPN, or KEY */
  1446. rc_plci = plci;
  1447. if (!ai_parms[3].length && plci->State && (msg[0].length || ai_parms[1].length))
  1448. {
  1449. /* overlap sending option */
  1450. dbug(1, dprintf("OvlSnd"));
  1451. add_s(plci, CPN, &msg[0]);
  1452. add_s(plci, KEY, &ai_parms[1]);
  1453. sig_req(plci, INFO_REQ, 0);
  1454. send_req(plci);
  1455. return false;
  1456. }
  1457. if (plci->State && ai_parms[2].length)
  1458. {
  1459. /* User_Info option */
  1460. dbug(1, dprintf("UUI"));
  1461. add_s(plci, UUI, &ai_parms[2]);
  1462. sig_req(plci, USER_DATA, 0);
  1463. }
  1464. else if (plci->State && ai_parms[3].length)
  1465. {
  1466. /* Facility option */
  1467. dbug(1, dprintf("FAC"));
  1468. add_s(plci, CPN, &msg[0]);
  1469. add_ai(plci, &msg[1]);
  1470. sig_req(plci, FACILITY_REQ, 0);
  1471. }
  1472. else
  1473. {
  1474. Info = _WRONG_STATE;
  1475. }
  1476. }
  1477. else if ((ai_parms[1].length || ai_parms[2].length || ai_parms[3].length) && !Info)
  1478. {
  1479. /* NCR_Facility option -> send UUI and Keypad too */
  1480. dbug(1, dprintf("NCR_FAC"));
  1481. if ((i = get_plci(a)))
  1482. {
  1483. rc_plci = &a->plci[i - 1];
  1484. appl->NullCREnable = true;
  1485. rc_plci->internal_command = C_NCR_FAC_REQ;
  1486. rc_plci->appl = appl;
  1487. add_p(rc_plci, CAI, "\x01\x80");
  1488. add_p(rc_plci, UID, "\x06\x43\x61\x70\x69\x32\x30");
  1489. sig_req(rc_plci, ASSIGN, DSIG_ID);
  1490. send_req(rc_plci);
  1491. }
  1492. else
  1493. {
  1494. Info = _OUT_OF_PLCI;
  1495. }
  1496. if (!Info)
  1497. {
  1498. add_s(rc_plci, CPN, &msg[0]);
  1499. add_ai(rc_plci, &msg[1]);
  1500. sig_req(rc_plci, NCR_FACILITY, 0);
  1501. send_req(rc_plci);
  1502. return false;
  1503. /* for application controlled supplementary services */
  1504. }
  1505. }
  1506. if (!rc_plci)
  1507. {
  1508. Info = _WRONG_MESSAGE_FORMAT;
  1509. }
  1510. if (!Info)
  1511. {
  1512. send_req(rc_plci);
  1513. }
  1514. else
  1515. { /* appl is not assigned to a PLCI or error condition */
  1516. dbug(1, dprintf("localInfoCon"));
  1517. sendf(appl,
  1518. _INFO_R | CONFIRM,
  1519. Id,
  1520. Number,
  1521. "w", Info);
  1522. }
  1523. return false;
  1524. }
  1525. static byte info_res(dword Id, word Number, DIVA_CAPI_ADAPTER *a,
  1526. PLCI *plci, APPL *appl, API_PARSE *msg)
  1527. {
  1528. dbug(1, dprintf("info_res"));
  1529. return false;
  1530. }
  1531. static byte alert_req(dword Id, word Number, DIVA_CAPI_ADAPTER *a,
  1532. PLCI *plci, APPL *appl, API_PARSE *msg)
  1533. {
  1534. word Info;
  1535. byte ret;
  1536. dbug(1, dprintf("alert_req"));
  1537. Info = _WRONG_IDENTIFIER;
  1538. ret = false;
  1539. if (plci) {
  1540. Info = _ALERT_IGNORED;
  1541. if (plci->State != INC_CON_ALERT) {
  1542. Info = _WRONG_STATE;
  1543. if (plci->State == INC_CON_PENDING) {
  1544. Info = 0;
  1545. plci->State = INC_CON_ALERT;
  1546. add_ai(plci, &msg[0]);
  1547. sig_req(plci, CALL_ALERT, 0);
  1548. ret = 1;
  1549. }
  1550. }
  1551. }
  1552. sendf(appl,
  1553. _ALERT_R | CONFIRM,
  1554. Id,
  1555. Number,
  1556. "w", Info);
  1557. return ret;
  1558. }
  1559. static byte facility_req(dword Id, word Number, DIVA_CAPI_ADAPTER *a,
  1560. PLCI *plci, APPL *appl, API_PARSE *msg)
  1561. {
  1562. word Info = 0;
  1563. word i = 0;
  1564. word selector;
  1565. word SSreq;
  1566. long relatedPLCIvalue;
  1567. DIVA_CAPI_ADAPTER *relatedadapter;
  1568. byte *SSparms = "";
  1569. byte RCparms[] = "\x05\x00\x00\x02\x00\x00";
  1570. byte SSstruct[] = "\x09\x00\x00\x06\x00\x00\x00\x00\x00\x00";
  1571. API_PARSE *parms;
  1572. API_PARSE ss_parms[11];
  1573. PLCI *rplci;
  1574. byte cai[15];
  1575. dword d;
  1576. API_PARSE dummy;
  1577. dbug(1, dprintf("facility_req"));
  1578. for (i = 0; i < 9; i++) ss_parms[i].length = 0;
  1579. parms = &msg[1];
  1580. if (!a)
  1581. {
  1582. dbug(1, dprintf("wrong Ctrl"));
  1583. Info = _WRONG_IDENTIFIER;
  1584. }
  1585. selector = GET_WORD(msg[0].info);
  1586. if (!Info)
  1587. {
  1588. switch (selector)
  1589. {
  1590. case SELECTOR_HANDSET:
  1591. Info = AdvCodecSupport(a, plci, appl, HOOK_SUPPORT);
  1592. break;
  1593. case SELECTOR_SU_SERV:
  1594. if (!msg[1].length)
  1595. {
  1596. Info = _WRONG_MESSAGE_FORMAT;
  1597. break;
  1598. }
  1599. SSreq = GET_WORD(&(msg[1].info[1]));
  1600. PUT_WORD(&RCparms[1], SSreq);
  1601. SSparms = RCparms;
  1602. switch (SSreq)
  1603. {
  1604. case S_GET_SUPPORTED_SERVICES:
  1605. if ((i = get_plci(a)))
  1606. {
  1607. rplci = &a->plci[i - 1];
  1608. rplci->appl = appl;
  1609. add_p(rplci, CAI, "\x01\x80");
  1610. add_p(rplci, UID, "\x06\x43\x61\x70\x69\x32\x30");
  1611. sig_req(rplci, ASSIGN, DSIG_ID);
  1612. send_req(rplci);
  1613. }
  1614. else
  1615. {
  1616. PUT_DWORD(&SSstruct[6], MASK_TERMINAL_PORTABILITY);
  1617. SSparms = (byte *)SSstruct;
  1618. break;
  1619. }
  1620. rplci->internal_command = GETSERV_REQ_PEND;
  1621. rplci->number = Number;
  1622. rplci->appl = appl;
  1623. sig_req(rplci, S_SUPPORTED, 0);
  1624. send_req(rplci);
  1625. return false;
  1626. break;
  1627. case S_LISTEN:
  1628. if (parms->length == 7)
  1629. {
  1630. if (api_parse(&parms->info[1], (word)parms->length, "wbd", ss_parms))
  1631. {
  1632. dbug(1, dprintf("format wrong"));
  1633. Info = _WRONG_MESSAGE_FORMAT;
  1634. break;
  1635. }
  1636. }
  1637. else
  1638. {
  1639. Info = _WRONG_MESSAGE_FORMAT;
  1640. break;
  1641. }
  1642. a->Notification_Mask[appl->Id - 1] = GET_DWORD(ss_parms[2].info);
  1643. if (a->Notification_Mask[appl->Id - 1] & SMASK_MWI) /* MWI active? */
  1644. {
  1645. if ((i = get_plci(a)))
  1646. {
  1647. rplci = &a->plci[i - 1];
  1648. rplci->appl = appl;
  1649. add_p(rplci, CAI, "\x01\x80");
  1650. add_p(rplci, UID, "\x06\x43\x61\x70\x69\x32\x30");
  1651. sig_req(rplci, ASSIGN, DSIG_ID);
  1652. send_req(rplci);
  1653. }
  1654. else
  1655. {
  1656. break;
  1657. }
  1658. rplci->internal_command = GET_MWI_STATE;
  1659. rplci->number = Number;
  1660. sig_req(rplci, MWI_POLL, 0);
  1661. send_req(rplci);
  1662. }
  1663. break;
  1664. case S_HOLD:
  1665. api_parse(&parms->info[1], (word)parms->length, "ws", ss_parms);
  1666. if (plci && plci->State && plci->SuppState == IDLE)
  1667. {
  1668. plci->SuppState = HOLD_REQUEST;
  1669. plci->command = C_HOLD_REQ;
  1670. add_s(plci, CAI, &ss_parms[1]);
  1671. sig_req(plci, CALL_HOLD, 0);
  1672. send_req(plci);
  1673. return false;
  1674. }
  1675. else Info = 0x3010; /* wrong state */
  1676. break;
  1677. case S_RETRIEVE:
  1678. if (plci && plci->State && plci->SuppState == CALL_HELD)
  1679. {
  1680. if (Id & EXT_CONTROLLER)
  1681. {
  1682. if (AdvCodecSupport(a, plci, appl, 0))
  1683. {
  1684. Info = 0x3010; /* wrong state */
  1685. break;
  1686. }
  1687. }
  1688. else plci->tel = 0;
  1689. plci->SuppState = RETRIEVE_REQUEST;
  1690. plci->command = C_RETRIEVE_REQ;
  1691. if (plci->spoofed_msg == SPOOFING_REQUIRED)
  1692. {
  1693. plci->spoofed_msg = CALL_RETRIEVE;
  1694. plci->internal_command = BLOCK_PLCI;
  1695. plci->command = 0;
  1696. dbug(1, dprintf("Spoof"));
  1697. return false;
  1698. }
  1699. else
  1700. {
  1701. sig_req(plci, CALL_RETRIEVE, 0);
  1702. send_req(plci);
  1703. return false;
  1704. }
  1705. }
  1706. else Info = 0x3010; /* wrong state */
  1707. break;
  1708. case S_SUSPEND:
  1709. if (parms->length)
  1710. {
  1711. if (api_parse(&parms->info[1], (word)parms->length, "wbs", ss_parms))
  1712. {
  1713. dbug(1, dprintf("format wrong"));
  1714. Info = _WRONG_MESSAGE_FORMAT;
  1715. break;
  1716. }
  1717. }
  1718. if (plci && plci->State)
  1719. {
  1720. add_s(plci, CAI, &ss_parms[2]);
  1721. plci->command = SUSPEND_REQ;
  1722. sig_req(plci, SUSPEND, 0);
  1723. plci->State = SUSPENDING;
  1724. send_req(plci);
  1725. }
  1726. else Info = 0x3010; /* wrong state */
  1727. break;
  1728. case S_RESUME:
  1729. if (!(i = get_plci(a)))
  1730. {
  1731. Info = _OUT_OF_PLCI;
  1732. break;
  1733. }
  1734. rplci = &a->plci[i - 1];
  1735. rplci->appl = appl;
  1736. rplci->number = Number;
  1737. rplci->tel = 0;
  1738. rplci->call_dir = CALL_DIR_OUT | CALL_DIR_ORIGINATE;
  1739. /* check 'external controller' bit for codec support */
  1740. if (Id & EXT_CONTROLLER)
  1741. {
  1742. if (AdvCodecSupport(a, rplci, appl, 0))
  1743. {
  1744. rplci->Id = 0;
  1745. Info = 0x300A;
  1746. break;
  1747. }
  1748. }
  1749. if (parms->length)
  1750. {
  1751. if (api_parse(&parms->info[1], (word)parms->length, "wbs", ss_parms))
  1752. {
  1753. dbug(1, dprintf("format wrong"));
  1754. rplci->Id = 0;
  1755. Info = _WRONG_MESSAGE_FORMAT;
  1756. break;
  1757. }
  1758. }
  1759. dummy.length = 0;
  1760. dummy.info = "\x00";
  1761. add_b1(rplci, &dummy, 0, 0);
  1762. if (a->Info_Mask[appl->Id - 1] & 0x200)
  1763. {
  1764. /* early B3 connect (CIP mask bit 9) no release after a disc */
  1765. add_p(rplci, LLI, "\x01\x01");
  1766. }
  1767. add_p(rplci, UID, "\x06\x43\x61\x70\x69\x32\x30");
  1768. sig_req(rplci, ASSIGN, DSIG_ID);
  1769. send_req(rplci);
  1770. add_s(rplci, CAI, &ss_parms[2]);
  1771. rplci->command = RESUME_REQ;
  1772. sig_req(rplci, RESUME, 0);
  1773. rplci->State = RESUMING;
  1774. send_req(rplci);
  1775. break;
  1776. case S_CONF_BEGIN: /* Request */
  1777. case S_CONF_DROP:
  1778. case S_CONF_ISOLATE:
  1779. case S_CONF_REATTACH:
  1780. if (api_parse(&parms->info[1], (word)parms->length, "wbd", ss_parms))
  1781. {
  1782. dbug(1, dprintf("format wrong"));
  1783. Info = _WRONG_MESSAGE_FORMAT;
  1784. break;
  1785. }
  1786. if (plci && plci->State && ((plci->SuppState == IDLE) || (plci->SuppState == CALL_HELD)))
  1787. {
  1788. d = GET_DWORD(ss_parms[2].info);
  1789. if (d >= 0x80)
  1790. {
  1791. dbug(1, dprintf("format wrong"));
  1792. Info = _WRONG_MESSAGE_FORMAT;
  1793. break;
  1794. }
  1795. plci->ptyState = (byte)SSreq;
  1796. plci->command = 0;
  1797. cai[0] = 2;
  1798. switch (SSreq)
  1799. {
  1800. case S_CONF_BEGIN:
  1801. cai[1] = CONF_BEGIN;
  1802. plci->internal_command = CONF_BEGIN_REQ_PEND;
  1803. break;
  1804. case S_CONF_DROP:
  1805. cai[1] = CONF_DROP;
  1806. plci->internal_command = CONF_DROP_REQ_PEND;
  1807. break;
  1808. case S_CONF_ISOLATE:
  1809. cai[1] = CONF_ISOLATE;
  1810. plci->internal_command = CONF_ISOLATE_REQ_PEND;
  1811. break;
  1812. case S_CONF_REATTACH:
  1813. cai[1] = CONF_REATTACH;
  1814. plci->internal_command = CONF_REATTACH_REQ_PEND;
  1815. break;
  1816. }
  1817. cai[2] = (byte)d; /* Conference Size resp. PartyId */
  1818. add_p(plci, CAI, cai);
  1819. sig_req(plci, S_SERVICE, 0);
  1820. send_req(plci);
  1821. return false;
  1822. }
  1823. else Info = 0x3010; /* wrong state */
  1824. break;
  1825. case S_ECT:
  1826. case S_3PTY_BEGIN:
  1827. case S_3PTY_END:
  1828. case S_CONF_ADD:
  1829. if (parms->length == 7)
  1830. {
  1831. if (api_parse(&parms->info[1], (word)parms->length, "wbd", ss_parms))
  1832. {
  1833. dbug(1, dprintf("format wrong"));
  1834. Info = _WRONG_MESSAGE_FORMAT;
  1835. break;
  1836. }
  1837. }
  1838. else if (parms->length == 8) /* workaround for the T-View-S */
  1839. {
  1840. if (api_parse(&parms->info[1], (word)parms->length, "wbdb", ss_parms))
  1841. {
  1842. dbug(1, dprintf("format wrong"));
  1843. Info = _WRONG_MESSAGE_FORMAT;
  1844. break;
  1845. }
  1846. }
  1847. else
  1848. {
  1849. Info = _WRONG_MESSAGE_FORMAT;
  1850. break;
  1851. }
  1852. if (!msg[1].length)
  1853. {
  1854. Info = _WRONG_MESSAGE_FORMAT;
  1855. break;
  1856. }
  1857. if (!plci)
  1858. {
  1859. Info = _WRONG_IDENTIFIER;
  1860. break;
  1861. }
  1862. relatedPLCIvalue = GET_DWORD(ss_parms[2].info);
  1863. relatedPLCIvalue &= 0x0000FFFF;
  1864. dbug(1, dprintf("PTY/ECT/addCONF,relPLCI=%lx", relatedPLCIvalue));
  1865. /* controller starts with 0 up to (max_adapter - 1) */
  1866. if (((relatedPLCIvalue & 0x7f) == 0)
  1867. || (MapController((byte)(relatedPLCIvalue & 0x7f)) == 0)
  1868. || (MapController((byte)(relatedPLCIvalue & 0x7f)) > max_adapter))
  1869. {
  1870. if (SSreq == S_3PTY_END)
  1871. {
  1872. dbug(1, dprintf("wrong Controller use 2nd PLCI=PLCI"));
  1873. rplci = plci;
  1874. }
  1875. else
  1876. {
  1877. Info = 0x3010; /* wrong state */
  1878. break;
  1879. }
  1880. }
  1881. else
  1882. {
  1883. relatedadapter = &adapter[MapController((byte)(relatedPLCIvalue & 0x7f)) - 1];
  1884. relatedPLCIvalue >>= 8;
  1885. /* find PLCI PTR*/
  1886. for (i = 0, rplci = NULL; i < relatedadapter->max_plci; i++)
  1887. {
  1888. if (relatedadapter->plci[i].Id == (byte)relatedPLCIvalue)
  1889. {
  1890. rplci = &relatedadapter->plci[i];
  1891. }
  1892. }
  1893. if (!rplci || !relatedPLCIvalue)
  1894. {
  1895. if (SSreq == S_3PTY_END)
  1896. {
  1897. dbug(1, dprintf("use 2nd PLCI=PLCI"));
  1898. rplci = plci;
  1899. }
  1900. else
  1901. {
  1902. Info = 0x3010; /* wrong state */
  1903. break;
  1904. }
  1905. }
  1906. }
  1907. /*
  1908. dbug(1, dprintf("rplci:%x", rplci));
  1909. dbug(1, dprintf("plci:%x", plci));
  1910. dbug(1, dprintf("rplci->ptyState:%x", rplci->ptyState));
  1911. dbug(1, dprintf("plci->ptyState:%x", plci->ptyState));
  1912. dbug(1, dprintf("SSreq:%x", SSreq));
  1913. dbug(1, dprintf("rplci->internal_command:%x", rplci->internal_command));
  1914. dbug(1, dprintf("rplci->appl:%x", rplci->appl));
  1915. dbug(1, dprintf("rplci->Id:%x", rplci->Id));
  1916. */
  1917. /* send PTY/ECT req, cannot check all states because of US stuff */
  1918. if (!rplci->internal_command && rplci->appl)
  1919. {
  1920. plci->command = 0;
  1921. rplci->relatedPTYPLCI = plci;
  1922. plci->relatedPTYPLCI = rplci;
  1923. rplci->ptyState = (byte)SSreq;
  1924. if (SSreq == S_ECT)
  1925. {
  1926. rplci->internal_command = ECT_REQ_PEND;
  1927. cai[1] = ECT_EXECUTE;
  1928. rplci->vswitchstate = 0;
  1929. rplci->vsprot = 0;
  1930. rplci->vsprotdialect = 0;
  1931. plci->vswitchstate = 0;
  1932. plci->vsprot = 0;
  1933. plci->vsprotdialect = 0;
  1934. }
  1935. else if (SSreq == S_CONF_ADD)
  1936. {
  1937. rplci->internal_command = CONF_ADD_REQ_PEND;
  1938. cai[1] = CONF_ADD;
  1939. }
  1940. else
  1941. {
  1942. rplci->internal_command = PTY_REQ_PEND;
  1943. cai[1] = (byte)(SSreq - 3);
  1944. }
  1945. rplci->number = Number;
  1946. if (plci != rplci) /* explicit invocation */
  1947. {
  1948. cai[0] = 2;
  1949. cai[2] = plci->Sig.Id;
  1950. dbug(1, dprintf("explicit invocation"));
  1951. }
  1952. else
  1953. {
  1954. dbug(1, dprintf("implicit invocation"));
  1955. cai[0] = 1;
  1956. }
  1957. add_p(rplci, CAI, cai);
  1958. sig_req(rplci, S_SERVICE, 0);
  1959. send_req(rplci);
  1960. return false;
  1961. }
  1962. else
  1963. {
  1964. dbug(0, dprintf("Wrong line"));
  1965. Info = 0x3010; /* wrong state */
  1966. break;
  1967. }
  1968. break;
  1969. case S_CALL_DEFLECTION:
  1970. if (api_parse(&parms->info[1], (word)parms->length, "wbwss", ss_parms))
  1971. {
  1972. dbug(1, dprintf("format wrong"));
  1973. Info = _WRONG_MESSAGE_FORMAT;
  1974. break;
  1975. }
  1976. if (!plci)
  1977. {
  1978. Info = _WRONG_IDENTIFIER;
  1979. break;
  1980. }
  1981. /* reuse unused screening indicator */
  1982. ss_parms[3].info[3] = (byte)GET_WORD(&(ss_parms[2].info[0]));
  1983. plci->command = 0;
  1984. plci->internal_command = CD_REQ_PEND;
  1985. appl->CDEnable = true;
  1986. cai[0] = 1;
  1987. cai[1] = CALL_DEFLECTION;
  1988. add_p(plci, CAI, cai);
  1989. add_p(plci, CPN, ss_parms[3].info);
  1990. sig_req(plci, S_SERVICE, 0);
  1991. send_req(plci);
  1992. return false;
  1993. break;
  1994. case S_CALL_FORWARDING_START:
  1995. if (api_parse(&parms->info[1], (word)parms->length, "wbdwwsss", ss_parms))
  1996. {
  1997. dbug(1, dprintf("format wrong"));
  1998. Info = _WRONG_MESSAGE_FORMAT;
  1999. break;
  2000. }
  2001. if ((i = get_plci(a)))
  2002. {
  2003. rplci = &a->plci[i - 1];
  2004. rplci->appl = appl;
  2005. add_p(rplci, CAI, "\x01\x80");
  2006. add_p(rplci, UID, "\x06\x43\x61\x70\x69\x32\x30");
  2007. sig_req(rplci, ASSIGN, DSIG_ID);
  2008. send_req(rplci);
  2009. }
  2010. else
  2011. {
  2012. Info = _OUT_OF_PLCI;
  2013. break;
  2014. }
  2015. /* reuse unused screening indicator */
  2016. rplci->internal_command = CF_START_PEND;
  2017. rplci->appl = appl;
  2018. rplci->number = Number;
  2019. appl->S_Handle = GET_DWORD(&(ss_parms[2].info[0]));
  2020. cai[0] = 2;
  2021. cai[1] = 0x70 | (byte)GET_WORD(&(ss_parms[3].info[0])); /* Function */
  2022. cai[2] = (byte)GET_WORD(&(ss_parms[4].info[0])); /* Basic Service */
  2023. add_p(rplci, CAI, cai);
  2024. add_p(rplci, OAD, ss_parms[5].info);
  2025. add_p(rplci, CPN, ss_parms[6].info);
  2026. sig_req(rplci, S_SERVICE, 0);
  2027. send_req(rplci);
  2028. return false;
  2029. break;
  2030. case S_INTERROGATE_DIVERSION:
  2031. case S_INTERROGATE_NUMBERS:
  2032. case S_CALL_FORWARDING_STOP:
  2033. case S_CCBS_REQUEST:
  2034. case S_CCBS_DEACTIVATE:
  2035. case S_CCBS_INTERROGATE:
  2036. switch (SSreq)
  2037. {
  2038. case S_INTERROGATE_NUMBERS:
  2039. if (api_parse(&parms->info[1], (word)parms->length, "wbd", ss_parms))
  2040. {
  2041. dbug(0, dprintf("format wrong"));
  2042. Info = _WRONG_MESSAGE_FORMAT;
  2043. }
  2044. break;
  2045. case S_CCBS_REQUEST:
  2046. case S_CCBS_DEACTIVATE:
  2047. if (api_parse(&parms->info[1], (word)parms->length, "wbdw", ss_parms))
  2048. {
  2049. dbug(0, dprintf("format wrong"));
  2050. Info = _WRONG_MESSAGE_FORMAT;
  2051. }
  2052. break;
  2053. case S_CCBS_INTERROGATE:
  2054. if (api_parse(&parms->info[1], (word)parms->length, "wbdws", ss_parms))
  2055. {
  2056. dbug(0, dprintf("format wrong"));
  2057. Info = _WRONG_MESSAGE_FORMAT;
  2058. }
  2059. break;
  2060. default:
  2061. if (api_parse(&parms->info[1], (word)parms->length, "wbdwws", ss_parms))
  2062. {
  2063. dbug(0, dprintf("format wrong"));
  2064. Info = _WRONG_MESSAGE_FORMAT;
  2065. break;
  2066. }
  2067. break;
  2068. }
  2069. if (Info) break;
  2070. if ((i = get_plci(a)))
  2071. {
  2072. rplci = &a->plci[i - 1];
  2073. switch (SSreq)
  2074. {
  2075. case S_INTERROGATE_DIVERSION: /* use cai with S_SERVICE below */
  2076. cai[1] = 0x60 | (byte)GET_WORD(&(ss_parms[3].info[0])); /* Function */
  2077. rplci->internal_command = INTERR_DIVERSION_REQ_PEND; /* move to rplci if assigned */
  2078. break;
  2079. case S_INTERROGATE_NUMBERS: /* use cai with S_SERVICE below */
  2080. cai[1] = DIVERSION_INTERROGATE_NUM; /* Function */
  2081. rplci->internal_command = INTERR_NUMBERS_REQ_PEND; /* move to rplci if assigned */
  2082. break;
  2083. case S_CALL_FORWARDING_STOP:
  2084. rplci->internal_command = CF_STOP_PEND;
  2085. cai[1] = 0x80 | (byte)GET_WORD(&(ss_parms[3].info[0])); /* Function */
  2086. break;
  2087. case S_CCBS_REQUEST:
  2088. cai[1] = CCBS_REQUEST;
  2089. rplci->internal_command = CCBS_REQUEST_REQ_PEND;
  2090. break;
  2091. case S_CCBS_DEACTIVATE:
  2092. cai[1] = CCBS_DEACTIVATE;
  2093. rplci->internal_command = CCBS_DEACTIVATE_REQ_PEND;
  2094. break;
  2095. case S_CCBS_INTERROGATE:
  2096. cai[1] = CCBS_INTERROGATE;
  2097. rplci->internal_command = CCBS_INTERROGATE_REQ_PEND;
  2098. break;
  2099. default:
  2100. cai[1] = 0;
  2101. break;
  2102. }
  2103. rplci->appl = appl;
  2104. rplci->number = Number;
  2105. add_p(rplci, CAI, "\x01\x80");
  2106. add_p(rplci, UID, "\x06\x43\x61\x70\x69\x32\x30");
  2107. sig_req(rplci, ASSIGN, DSIG_ID);
  2108. send_req(rplci);
  2109. }
  2110. else
  2111. {
  2112. Info = _OUT_OF_PLCI;
  2113. break;
  2114. }
  2115. appl->S_Handle = GET_DWORD(&(ss_parms[2].info[0]));
  2116. switch (SSreq)
  2117. {
  2118. case S_INTERROGATE_NUMBERS:
  2119. cai[0] = 1;
  2120. add_p(rplci, CAI, cai);
  2121. break;
  2122. case S_CCBS_REQUEST:
  2123. case S_CCBS_DEACTIVATE:
  2124. cai[0] = 3;
  2125. PUT_WORD(&cai[2], GET_WORD(&(ss_parms[3].info[0])));
  2126. add_p(rplci, CAI, cai);
  2127. break;
  2128. case S_CCBS_INTERROGATE:
  2129. cai[0] = 3;
  2130. PUT_WORD(&cai[2], GET_WORD(&(ss_parms[3].info[0])));
  2131. add_p(rplci, CAI, cai);
  2132. add_p(rplci, OAD, ss_parms[4].info);
  2133. break;
  2134. default:
  2135. cai[0] = 2;
  2136. cai[2] = (byte)GET_WORD(&(ss_parms[4].info[0])); /* Basic Service */
  2137. add_p(rplci, CAI, cai);
  2138. add_p(rplci, OAD, ss_parms[5].info);
  2139. break;
  2140. }
  2141. sig_req(rplci, S_SERVICE, 0);
  2142. send_req(rplci);
  2143. return false;
  2144. break;
  2145. case S_MWI_ACTIVATE:
  2146. if (api_parse(&parms->info[1], (word)parms->length, "wbwdwwwssss", ss_parms))
  2147. {
  2148. dbug(1, dprintf("format wrong"));
  2149. Info = _WRONG_MESSAGE_FORMAT;
  2150. break;
  2151. }
  2152. if (!plci)
  2153. {
  2154. if ((i = get_plci(a)))
  2155. {
  2156. rplci = &a->plci[i - 1];
  2157. rplci->appl = appl;
  2158. rplci->cr_enquiry = true;
  2159. add_p(rplci, CAI, "\x01\x80");
  2160. add_p(rplci, UID, "\x06\x43\x61\x70\x69\x32\x30");
  2161. sig_req(rplci, ASSIGN, DSIG_ID);
  2162. send_req(rplci);
  2163. }
  2164. else
  2165. {
  2166. Info = _OUT_OF_PLCI;
  2167. break;
  2168. }
  2169. }
  2170. else
  2171. {
  2172. rplci = plci;
  2173. rplci->cr_enquiry = false;
  2174. }
  2175. rplci->command = 0;
  2176. rplci->internal_command = MWI_ACTIVATE_REQ_PEND;
  2177. rplci->appl = appl;
  2178. rplci->number = Number;
  2179. cai[0] = 13;
  2180. cai[1] = ACTIVATION_MWI; /* Function */
  2181. PUT_WORD(&cai[2], GET_WORD(&(ss_parms[2].info[0]))); /* Basic Service */
  2182. PUT_DWORD(&cai[4], GET_DWORD(&(ss_parms[3].info[0]))); /* Number of Messages */
  2183. PUT_WORD(&cai[8], GET_WORD(&(ss_parms[4].info[0]))); /* Message Status */
  2184. PUT_WORD(&cai[10], GET_WORD(&(ss_parms[5].info[0]))); /* Message Reference */
  2185. PUT_WORD(&cai[12], GET_WORD(&(ss_parms[6].info[0]))); /* Invocation Mode */
  2186. add_p(rplci, CAI, cai);
  2187. add_p(rplci, CPN, ss_parms[7].info); /* Receiving User Number */
  2188. add_p(rplci, OAD, ss_parms[8].info); /* Controlling User Number */
  2189. add_p(rplci, OSA, ss_parms[9].info); /* Controlling User Provided Number */
  2190. add_p(rplci, UID, ss_parms[10].info); /* Time */
  2191. sig_req(rplci, S_SERVICE, 0);
  2192. send_req(rplci);
  2193. return false;
  2194. case S_MWI_DEACTIVATE:
  2195. if (api_parse(&parms->info[1], (word)parms->length, "wbwwss", ss_parms))
  2196. {
  2197. dbug(1, dprintf("format wrong"));
  2198. Info = _WRONG_MESSAGE_FORMAT;
  2199. break;
  2200. }
  2201. if (!plci)
  2202. {
  2203. if ((i = get_plci(a)))
  2204. {
  2205. rplci = &a->plci[i - 1];
  2206. rplci->appl = appl;
  2207. rplci->cr_enquiry = true;
  2208. add_p(rplci, CAI, "\x01\x80");
  2209. add_p(rplci, UID, "\x06\x43\x61\x70\x69\x32\x30");
  2210. sig_req(rplci, ASSIGN, DSIG_ID);
  2211. send_req(rplci);
  2212. }
  2213. else
  2214. {
  2215. Info = _OUT_OF_PLCI;
  2216. break;
  2217. }
  2218. }
  2219. else
  2220. {
  2221. rplci = plci;
  2222. rplci->cr_enquiry = false;
  2223. }
  2224. rplci->command = 0;
  2225. rplci->internal_command = MWI_DEACTIVATE_REQ_PEND;
  2226. rplci->appl = appl;
  2227. rplci->number = Number;
  2228. cai[0] = 5;
  2229. cai[1] = DEACTIVATION_MWI; /* Function */
  2230. PUT_WORD(&cai[2], GET_WORD(&(ss_parms[2].info[0]))); /* Basic Service */
  2231. PUT_WORD(&cai[4], GET_WORD(&(ss_parms[3].info[0]))); /* Invocation Mode */
  2232. add_p(rplci, CAI, cai);
  2233. add_p(rplci, CPN, ss_parms[4].info); /* Receiving User Number */
  2234. add_p(rplci, OAD, ss_parms[5].info); /* Controlling User Number */
  2235. sig_req(rplci, S_SERVICE, 0);
  2236. send_req(rplci);
  2237. return false;
  2238. default:
  2239. Info = 0x300E; /* not supported */
  2240. break;
  2241. }
  2242. break; /* case SELECTOR_SU_SERV: end */
  2243. case SELECTOR_DTMF:
  2244. return (dtmf_request(Id, Number, a, plci, appl, msg));
  2245. case SELECTOR_LINE_INTERCONNECT:
  2246. return (mixer_request(Id, Number, a, plci, appl, msg));
  2247. case PRIV_SELECTOR_ECHO_CANCELLER:
  2248. appl->appl_flags |= APPL_FLAG_PRIV_EC_SPEC;
  2249. return (ec_request(Id, Number, a, plci, appl, msg));
  2250. case SELECTOR_ECHO_CANCELLER:
  2251. appl->appl_flags &= ~APPL_FLAG_PRIV_EC_SPEC;
  2252. return (ec_request(Id, Number, a, plci, appl, msg));
  2253. case SELECTOR_V42BIS:
  2254. default:
  2255. Info = _FACILITY_NOT_SUPPORTED;
  2256. break;
  2257. } /* end of switch (selector) */
  2258. }
  2259. dbug(1, dprintf("SendFacRc"));
  2260. sendf(appl,
  2261. _FACILITY_R | CONFIRM,
  2262. Id,
  2263. Number,
  2264. "wws", Info, selector, SSparms);
  2265. return false;
  2266. }
  2267. static byte facility_res(dword Id, word Number, DIVA_CAPI_ADAPTER *a,
  2268. PLCI *plci, APPL *appl, API_PARSE *msg)
  2269. {
  2270. dbug(1, dprintf("facility_res"));
  2271. return false;
  2272. }
  2273. static byte connect_b3_req(dword Id, word Number, DIVA_CAPI_ADAPTER *a,
  2274. PLCI *plci, APPL *appl, API_PARSE *parms)
  2275. {
  2276. word Info = 0;
  2277. byte req;
  2278. byte len;
  2279. word w;
  2280. word fax_control_bits, fax_feature_bits, fax_info_change;
  2281. API_PARSE *ncpi;
  2282. byte pvc[2];
  2283. API_PARSE fax_parms[9];
  2284. word i;
  2285. dbug(1, dprintf("connect_b3_req"));
  2286. if (plci)
  2287. {
  2288. if ((plci->State == IDLE) || (plci->State == OUTG_DIS_PENDING)
  2289. || (plci->State == INC_DIS_PENDING) || (plci->SuppState != IDLE))
  2290. {
  2291. Info = _WRONG_STATE;
  2292. }
  2293. else
  2294. {
  2295. /* local reply if assign unsuccessful
  2296. or B3 protocol allows only one layer 3 connection
  2297. and already connected
  2298. or B2 protocol not any LAPD
  2299. and connect_b3_req contradicts originate/answer direction */
  2300. if (!plci->NL.Id
  2301. || (((plci->B3_prot != B3_T90NL) && (plci->B3_prot != B3_ISO8208) && (plci->B3_prot != B3_X25_DCE))
  2302. && ((plci->channels != 0)
  2303. || (((plci->B2_prot != B2_SDLC) && (plci->B2_prot != B2_LAPD) && (plci->B2_prot != B2_LAPD_FREE_SAPI_SEL))
  2304. && ((plci->call_dir & CALL_DIR_ANSWER) && !(plci->call_dir & CALL_DIR_FORCE_OUTG_NL))))))
  2305. {
  2306. dbug(1, dprintf("B3 already connected=%d or no NL.Id=0x%x, dir=%d sstate=0x%x",
  2307. plci->channels, plci->NL.Id, plci->call_dir, plci->SuppState));
  2308. Info = _WRONG_STATE;
  2309. sendf(appl,
  2310. _CONNECT_B3_R | CONFIRM,
  2311. Id,
  2312. Number,
  2313. "w", Info);
  2314. return false;
  2315. }
  2316. plci->requested_options_conn = 0;
  2317. req = N_CONNECT;
  2318. ncpi = &parms[0];
  2319. if (plci->B3_prot == 2 || plci->B3_prot == 3)
  2320. {
  2321. if (ncpi->length > 2)
  2322. {
  2323. /* check for PVC */
  2324. if (ncpi->info[2] || ncpi->info[3])
  2325. {
  2326. pvc[0] = ncpi->info[3];
  2327. pvc[1] = ncpi->info[2];
  2328. add_d(plci, 2, pvc);
  2329. req = N_RESET;
  2330. }
  2331. else
  2332. {
  2333. if (ncpi->info[1] & 1) req = N_CONNECT | N_D_BIT;
  2334. add_d(plci, (word)(ncpi->length - 3), &ncpi->info[4]);
  2335. }
  2336. }
  2337. }
  2338. else if (plci->B3_prot == 5)
  2339. {
  2340. if (plci->NL.Id && !plci->nl_remove_id)
  2341. {
  2342. fax_control_bits = GET_WORD(&((T30_INFO *)plci->fax_connect_info_buffer)->control_bits_low);
  2343. fax_feature_bits = GET_WORD(&((T30_INFO *)plci->fax_connect_info_buffer)->feature_bits_low);
  2344. if (!(fax_control_bits & T30_CONTROL_BIT_MORE_DOCUMENTS)
  2345. || (fax_feature_bits & T30_FEATURE_BIT_MORE_DOCUMENTS))
  2346. {
  2347. len = offsetof(T30_INFO, universal_6);
  2348. fax_info_change = false;
  2349. if (ncpi->length >= 4)
  2350. {
  2351. w = GET_WORD(&ncpi->info[3]);
  2352. if ((w & 0x0001) != ((word)(((T30_INFO *)(plci->fax_connect_info_buffer))->resolution & 0x0001)))
  2353. {
  2354. ((T30_INFO *)(plci->fax_connect_info_buffer))->resolution =
  2355. (byte)((((T30_INFO *)(plci->fax_connect_info_buffer))->resolution & ~T30_RESOLUTION_R8_0770_OR_200) |
  2356. ((w & 0x0001) ? T30_RESOLUTION_R8_0770_OR_200 : 0));
  2357. fax_info_change = true;
  2358. }
  2359. fax_control_bits &= ~(T30_CONTROL_BIT_REQUEST_POLLING | T30_CONTROL_BIT_MORE_DOCUMENTS);
  2360. if (w & 0x0002) /* Fax-polling request */
  2361. fax_control_bits |= T30_CONTROL_BIT_REQUEST_POLLING;
  2362. if ((w & 0x0004) /* Request to send / poll another document */
  2363. && (a->manufacturer_features & MANUFACTURER_FEATURE_FAX_MORE_DOCUMENTS))
  2364. {
  2365. fax_control_bits |= T30_CONTROL_BIT_MORE_DOCUMENTS;
  2366. }
  2367. if (ncpi->length >= 6)
  2368. {
  2369. w = GET_WORD(&ncpi->info[5]);
  2370. if (((byte) w) != ((T30_INFO *)(plci->fax_connect_info_buffer))->data_format)
  2371. {
  2372. ((T30_INFO *)(plci->fax_connect_info_buffer))->data_format = (byte) w;
  2373. fax_info_change = true;
  2374. }
  2375. if ((a->man_profile.private_options & (1L << PRIVATE_FAX_SUB_SEP_PWD))
  2376. && (GET_WORD(&ncpi->info[5]) & 0x8000)) /* Private SEP/SUB/PWD enable */
  2377. {
  2378. plci->requested_options_conn |= (1L << PRIVATE_FAX_SUB_SEP_PWD);
  2379. }
  2380. if ((a->man_profile.private_options & (1L << PRIVATE_FAX_NONSTANDARD))
  2381. && (GET_WORD(&ncpi->info[5]) & 0x4000)) /* Private non-standard facilities enable */
  2382. {
  2383. plci->requested_options_conn |= (1L << PRIVATE_FAX_NONSTANDARD);
  2384. }
  2385. fax_control_bits &= ~(T30_CONTROL_BIT_ACCEPT_SUBADDRESS | T30_CONTROL_BIT_ACCEPT_SEL_POLLING |
  2386. T30_CONTROL_BIT_ACCEPT_PASSWORD);
  2387. if ((plci->requested_options_conn | plci->requested_options | a->requested_options_table[appl->Id - 1])
  2388. & ((1L << PRIVATE_FAX_SUB_SEP_PWD) | (1L << PRIVATE_FAX_NONSTANDARD)))
  2389. {
  2390. if (api_parse(&ncpi->info[1], ncpi->length, "wwwwsss", fax_parms))
  2391. Info = _WRONG_MESSAGE_FORMAT;
  2392. else
  2393. {
  2394. if ((plci->requested_options_conn | plci->requested_options | a->requested_options_table[appl->Id - 1])
  2395. & (1L << PRIVATE_FAX_SUB_SEP_PWD))
  2396. {
  2397. fax_control_bits |= T30_CONTROL_BIT_ACCEPT_SUBADDRESS | T30_CONTROL_BIT_ACCEPT_PASSWORD;
  2398. if (fax_control_bits & T30_CONTROL_BIT_ACCEPT_POLLING)
  2399. fax_control_bits |= T30_CONTROL_BIT_ACCEPT_SEL_POLLING;
  2400. }
  2401. w = fax_parms[4].length;
  2402. if (w > 20)
  2403. w = 20;
  2404. ((T30_INFO *)(plci->fax_connect_info_buffer))->station_id_len = (byte) w;
  2405. for (i = 0; i < w; i++)
  2406. ((T30_INFO *)(plci->fax_connect_info_buffer))->station_id[i] = fax_parms[4].info[1 + i];
  2407. ((T30_INFO *)(plci->fax_connect_info_buffer))->head_line_len = 0;
  2408. len = offsetof(T30_INFO, station_id) + T30_MAX_STATION_ID_LENGTH;
  2409. w = fax_parms[5].length;
  2410. if (w > 20)
  2411. w = 20;
  2412. plci->fax_connect_info_buffer[len++] = (byte) w;
  2413. for (i = 0; i < w; i++)
  2414. plci->fax_connect_info_buffer[len++] = fax_parms[5].info[1 + i];
  2415. w = fax_parms[6].length;
  2416. if (w > 20)
  2417. w = 20;
  2418. plci->fax_connect_info_buffer[len++] = (byte) w;
  2419. for (i = 0; i < w; i++)
  2420. plci->fax_connect_info_buffer[len++] = fax_parms[6].info[1 + i];
  2421. if ((plci->requested_options_conn | plci->requested_options | a->requested_options_table[appl->Id - 1])
  2422. & (1L << PRIVATE_FAX_NONSTANDARD))
  2423. {
  2424. if (api_parse(&ncpi->info[1], ncpi->length, "wwwwssss", fax_parms))
  2425. {
  2426. dbug(1, dprintf("non-standard facilities info missing or wrong format"));
  2427. plci->fax_connect_info_buffer[len++] = 0;
  2428. }
  2429. else
  2430. {
  2431. if ((fax_parms[7].length >= 3) && (fax_parms[7].info[1] >= 2))
  2432. plci->nsf_control_bits = GET_WORD(&fax_parms[7].info[2]);
  2433. plci->fax_connect_info_buffer[len++] = (byte)(fax_parms[7].length);
  2434. for (i = 0; i < fax_parms[7].length; i++)
  2435. plci->fax_connect_info_buffer[len++] = fax_parms[7].info[1 + i];
  2436. }
  2437. }
  2438. }
  2439. }
  2440. else
  2441. {
  2442. len = offsetof(T30_INFO, universal_6);
  2443. }
  2444. fax_info_change = true;
  2445. }
  2446. if (fax_control_bits != GET_WORD(&((T30_INFO *)plci->fax_connect_info_buffer)->control_bits_low))
  2447. {
  2448. PUT_WORD(&((T30_INFO *)plci->fax_connect_info_buffer)->control_bits_low, fax_control_bits);
  2449. fax_info_change = true;
  2450. }
  2451. }
  2452. if (Info == GOOD)
  2453. {
  2454. plci->fax_connect_info_length = len;
  2455. if (fax_info_change)
  2456. {
  2457. if (fax_feature_bits & T30_FEATURE_BIT_MORE_DOCUMENTS)
  2458. {
  2459. start_internal_command(Id, plci, fax_connect_info_command);
  2460. return false;
  2461. }
  2462. else
  2463. {
  2464. start_internal_command(Id, plci, fax_adjust_b23_command);
  2465. return false;
  2466. }
  2467. }
  2468. }
  2469. }
  2470. else Info = _WRONG_STATE;
  2471. }
  2472. else Info = _WRONG_STATE;
  2473. }
  2474. else if (plci->B3_prot == B3_RTP)
  2475. {
  2476. plci->internal_req_buffer[0] = ncpi->length + 1;
  2477. plci->internal_req_buffer[1] = UDATA_REQUEST_RTP_RECONFIGURE;
  2478. for (w = 0; w < ncpi->length; w++)
  2479. plci->internal_req_buffer[2 + w] = ncpi->info[1 + w];
  2480. start_internal_command(Id, plci, rtp_connect_b3_req_command);
  2481. return false;
  2482. }
  2483. if (!Info)
  2484. {
  2485. nl_req_ncci(plci, req, 0);
  2486. return 1;
  2487. }
  2488. }
  2489. }
  2490. else Info = _WRONG_IDENTIFIER;
  2491. sendf(appl,
  2492. _CONNECT_B3_R | CONFIRM,
  2493. Id,
  2494. Number,
  2495. "w", Info);
  2496. return false;
  2497. }
  2498. static byte connect_b3_res(dword Id, word Number, DIVA_CAPI_ADAPTER *a,
  2499. PLCI *plci, APPL *appl, API_PARSE *parms)
  2500. {
  2501. word ncci;
  2502. API_PARSE *ncpi;
  2503. byte req;
  2504. word w;
  2505. API_PARSE fax_parms[9];
  2506. word i;
  2507. byte len;
  2508. dbug(1, dprintf("connect_b3_res"));
  2509. ncci = (word)(Id >> 16);
  2510. if (plci && ncci) {
  2511. if (a->ncci_state[ncci] == INC_CON_PENDING) {
  2512. if (GET_WORD(&parms[0].info[0]) != 0)
  2513. {
  2514. a->ncci_state[ncci] = OUTG_REJ_PENDING;
  2515. channel_request_xon(plci, a->ncci_ch[ncci]);
  2516. channel_xmit_xon(plci);
  2517. cleanup_ncci_data(plci, ncci);
  2518. nl_req_ncci(plci, N_DISC, (byte)ncci);
  2519. return 1;
  2520. }
  2521. a->ncci_state[ncci] = INC_ACT_PENDING;
  2522. req = N_CONNECT_ACK;
  2523. ncpi = &parms[1];
  2524. if ((plci->B3_prot == 4) || (plci->B3_prot == 5) || (plci->B3_prot == 7))
  2525. {
  2526. if ((plci->requested_options_conn | plci->requested_options | a->requested_options_table[plci->appl->Id - 1])
  2527. & (1L << PRIVATE_FAX_NONSTANDARD))
  2528. {
  2529. if (((plci->B3_prot == 4) || (plci->B3_prot == 5))
  2530. && (plci->nsf_control_bits & T30_NSF_CONTROL_BIT_ENABLE_NSF)
  2531. && (plci->nsf_control_bits & T30_NSF_CONTROL_BIT_NEGOTIATE_RESP))
  2532. {
  2533. len = offsetof(T30_INFO, station_id) + T30_MAX_STATION_ID_LENGTH;
  2534. if (plci->fax_connect_info_length < len)
  2535. {
  2536. ((T30_INFO *)(plci->fax_connect_info_buffer))->station_id_len = 0;
  2537. ((T30_INFO *)(plci->fax_connect_info_buffer))->head_line_len = 0;
  2538. }
  2539. if (api_parse(&ncpi->info[1], ncpi->length, "wwwwssss", fax_parms))
  2540. {
  2541. dbug(1, dprintf("non-standard facilities info missing or wrong format"));
  2542. }
  2543. else
  2544. {
  2545. if (plci->fax_connect_info_length <= len)
  2546. plci->fax_connect_info_buffer[len] = 0;
  2547. len += 1 + plci->fax_connect_info_buffer[len];
  2548. if (plci->fax_connect_info_length <= len)
  2549. plci->fax_connect_info_buffer[len] = 0;
  2550. len += 1 + plci->fax_connect_info_buffer[len];
  2551. if ((fax_parms[7].length >= 3) && (fax_parms[7].info[1] >= 2))
  2552. plci->nsf_control_bits = GET_WORD(&fax_parms[7].info[2]);
  2553. plci->fax_connect_info_buffer[len++] = (byte)(fax_parms[7].length);
  2554. for (i = 0; i < fax_parms[7].length; i++)
  2555. plci->fax_connect_info_buffer[len++] = fax_parms[7].info[1 + i];
  2556. }
  2557. plci->fax_connect_info_length = len;
  2558. ((T30_INFO *)(plci->fax_connect_info_buffer))->code = 0;
  2559. start_internal_command(Id, plci, fax_connect_ack_command);
  2560. return false;
  2561. }
  2562. }
  2563. nl_req_ncci(plci, req, (byte)ncci);
  2564. if ((plci->ncpi_state & NCPI_VALID_CONNECT_B3_ACT)
  2565. && !(plci->ncpi_state & NCPI_CONNECT_B3_ACT_SENT))
  2566. {
  2567. if (plci->B3_prot == 4)
  2568. sendf(appl, _CONNECT_B3_ACTIVE_I, Id, 0, "s", "");
  2569. else
  2570. sendf(appl, _CONNECT_B3_ACTIVE_I, Id, 0, "S", plci->ncpi_buffer);
  2571. plci->ncpi_state |= NCPI_CONNECT_B3_ACT_SENT;
  2572. }
  2573. }
  2574. else if (plci->B3_prot == B3_RTP)
  2575. {
  2576. plci->internal_req_buffer[0] = ncpi->length + 1;
  2577. plci->internal_req_buffer[1] = UDATA_REQUEST_RTP_RECONFIGURE;
  2578. for (w = 0; w < ncpi->length; w++)
  2579. plci->internal_req_buffer[2 + w] = ncpi->info[1+w];
  2580. start_internal_command(Id, plci, rtp_connect_b3_res_command);
  2581. return false;
  2582. }
  2583. else
  2584. {
  2585. if (ncpi->length > 2) {
  2586. if (ncpi->info[1] & 1) req = N_CONNECT_ACK | N_D_BIT;
  2587. add_d(plci, (word)(ncpi->length - 3), &ncpi->info[4]);
  2588. }
  2589. nl_req_ncci(plci, req, (byte)ncci);
  2590. sendf(appl, _CONNECT_B3_ACTIVE_I, Id, 0, "s", "");
  2591. if (plci->adjust_b_restore)
  2592. {
  2593. plci->adjust_b_restore = false;
  2594. start_internal_command(Id, plci, adjust_b_restore);
  2595. }
  2596. }
  2597. return 1;
  2598. }
  2599. }
  2600. return false;
  2601. }
  2602. static byte connect_b3_a_res(dword Id, word Number, DIVA_CAPI_ADAPTER *a,
  2603. PLCI *plci, APPL *appl, API_PARSE *parms)
  2604. {
  2605. word ncci;
  2606. ncci = (word)(Id >> 16);
  2607. dbug(1, dprintf("connect_b3_a_res(ncci=0x%x)", ncci));
  2608. if (plci && ncci && (plci->State != IDLE) && (plci->State != INC_DIS_PENDING)
  2609. && (plci->State != OUTG_DIS_PENDING))
  2610. {
  2611. if (a->ncci_state[ncci] == INC_ACT_PENDING) {
  2612. a->ncci_state[ncci] = CONNECTED;
  2613. if (plci->State != INC_CON_CONNECTED_ALERT) plci->State = CONNECTED;
  2614. channel_request_xon(plci, a->ncci_ch[ncci]);
  2615. channel_xmit_xon(plci);
  2616. }
  2617. }
  2618. return false;
  2619. }
  2620. static byte disconnect_b3_req(dword Id, word Number, DIVA_CAPI_ADAPTER *a,
  2621. PLCI *plci, APPL *appl, API_PARSE *parms)
  2622. {
  2623. word Info;
  2624. word ncci;
  2625. API_PARSE *ncpi;
  2626. dbug(1, dprintf("disconnect_b3_req"));
  2627. Info = _WRONG_IDENTIFIER;
  2628. ncci = (word)(Id >> 16);
  2629. if (plci && ncci)
  2630. {
  2631. Info = _WRONG_STATE;
  2632. if ((a->ncci_state[ncci] == CONNECTED)
  2633. || (a->ncci_state[ncci] == OUTG_CON_PENDING)
  2634. || (a->ncci_state[ncci] == INC_CON_PENDING)
  2635. || (a->ncci_state[ncci] == INC_ACT_PENDING))
  2636. {
  2637. a->ncci_state[ncci] = OUTG_DIS_PENDING;
  2638. channel_request_xon(plci, a->ncci_ch[ncci]);
  2639. channel_xmit_xon(plci);
  2640. if (a->ncci[ncci].data_pending
  2641. && ((plci->B3_prot == B3_TRANSPARENT)
  2642. || (plci->B3_prot == B3_T30)
  2643. || (plci->B3_prot == B3_T30_WITH_EXTENSIONS)))
  2644. {
  2645. plci->send_disc = (byte)ncci;
  2646. plci->command = 0;
  2647. return false;
  2648. }
  2649. else
  2650. {
  2651. cleanup_ncci_data(plci, ncci);
  2652. if (plci->B3_prot == 2 || plci->B3_prot == 3)
  2653. {
  2654. ncpi = &parms[0];
  2655. if (ncpi->length > 3)
  2656. {
  2657. add_d(plci, (word)(ncpi->length - 3), (byte *)&(ncpi->info[4]));
  2658. }
  2659. }
  2660. nl_req_ncci(plci, N_DISC, (byte)ncci);
  2661. }
  2662. return 1;
  2663. }
  2664. }
  2665. sendf(appl,
  2666. _DISCONNECT_B3_R | CONFIRM,
  2667. Id,
  2668. Number,
  2669. "w", Info);
  2670. return false;
  2671. }
  2672. static byte disconnect_b3_res(dword Id, word Number, DIVA_CAPI_ADAPTER *a,
  2673. PLCI *plci, APPL *appl, API_PARSE *parms)
  2674. {
  2675. word ncci;
  2676. word i;
  2677. ncci = (word)(Id >> 16);
  2678. dbug(1, dprintf("disconnect_b3_res(ncci=0x%x", ncci));
  2679. if (plci && ncci) {
  2680. plci->requested_options_conn = 0;
  2681. plci->fax_connect_info_length = 0;
  2682. plci->ncpi_state = 0x00;
  2683. if (((plci->B3_prot != B3_T90NL) && (plci->B3_prot != B3_ISO8208) && (plci->B3_prot != B3_X25_DCE))
  2684. && ((plci->B2_prot != B2_LAPD) && (plci->B2_prot != B2_LAPD_FREE_SAPI_SEL)))
  2685. {
  2686. plci->call_dir |= CALL_DIR_FORCE_OUTG_NL;
  2687. }
  2688. for (i = 0; i < MAX_CHANNELS_PER_PLCI && plci->inc_dis_ncci_table[i] != (byte)ncci; i++);
  2689. if (i < MAX_CHANNELS_PER_PLCI) {
  2690. if (plci->channels)plci->channels--;
  2691. for (; i < MAX_CHANNELS_PER_PLCI - 1; i++) plci->inc_dis_ncci_table[i] = plci->inc_dis_ncci_table[i + 1];
  2692. plci->inc_dis_ncci_table[MAX_CHANNELS_PER_PLCI - 1] = 0;
  2693. ncci_free_receive_buffers(plci, ncci);
  2694. if ((plci->State == IDLE || plci->State == SUSPENDING) && !plci->channels) {
  2695. if (plci->State == SUSPENDING) {
  2696. sendf(plci->appl,
  2697. _FACILITY_I,
  2698. Id & 0xffffL,
  2699. 0,
  2700. "ws", (word)3, "\x03\x04\x00\x00");
  2701. sendf(plci->appl, _DISCONNECT_I, Id & 0xffffL, 0, "w", 0);
  2702. }
  2703. plci_remove(plci);
  2704. plci->State = IDLE;
  2705. }
  2706. }
  2707. else
  2708. {
  2709. if ((a->manufacturer_features & MANUFACTURER_FEATURE_FAX_PAPER_FORMATS)
  2710. && ((plci->B3_prot == 4) || (plci->B3_prot == 5))
  2711. && (a->ncci_state[ncci] == INC_DIS_PENDING))
  2712. {
  2713. ncci_free_receive_buffers(plci, ncci);
  2714. nl_req_ncci(plci, N_EDATA, (byte)ncci);
  2715. plci->adapter->ncci_state[ncci] = IDLE;
  2716. start_internal_command(Id, plci, fax_disconnect_command);
  2717. return 1;
  2718. }
  2719. }
  2720. }
  2721. return false;
  2722. }
  2723. static byte data_b3_req(dword Id, word Number, DIVA_CAPI_ADAPTER *a,
  2724. PLCI *plci, APPL *appl, API_PARSE *parms)
  2725. {
  2726. NCCI *ncci_ptr;
  2727. DATA_B3_DESC *data;
  2728. word Info;
  2729. word ncci;
  2730. word i;
  2731. dbug(1, dprintf("data_b3_req"));
  2732. Info = _WRONG_IDENTIFIER;
  2733. ncci = (word)(Id >> 16);
  2734. dbug(1, dprintf("ncci=0x%x, plci=0x%x", ncci, plci));
  2735. if (plci && ncci)
  2736. {
  2737. Info = _WRONG_STATE;
  2738. if ((a->ncci_state[ncci] == CONNECTED)
  2739. || (a->ncci_state[ncci] == INC_ACT_PENDING))
  2740. {
  2741. /* queue data */
  2742. ncci_ptr = &(a->ncci[ncci]);
  2743. i = ncci_ptr->data_out + ncci_ptr->data_pending;
  2744. if (i >= MAX_DATA_B3)
  2745. i -= MAX_DATA_B3;
  2746. data = &(ncci_ptr->DBuffer[i]);
  2747. data->Number = Number;
  2748. if ((((byte *)(parms[0].info)) >= ((byte *)(plci->msg_in_queue)))
  2749. && (((byte *)(parms[0].info)) < ((byte *)(plci->msg_in_queue)) + sizeof(plci->msg_in_queue)))
  2750. {
  2751. data->P = (byte *)(long)(*((dword *)(parms[0].info)));
  2752. }
  2753. else
  2754. data->P = TransmitBufferSet(appl, *(dword *)parms[0].info);
  2755. data->Length = GET_WORD(parms[1].info);
  2756. data->Handle = GET_WORD(parms[2].info);
  2757. data->Flags = GET_WORD(parms[3].info);
  2758. (ncci_ptr->data_pending)++;
  2759. /* check for delivery confirmation */
  2760. if (data->Flags & 0x0004)
  2761. {
  2762. i = ncci_ptr->data_ack_out + ncci_ptr->data_ack_pending;
  2763. if (i >= MAX_DATA_ACK)
  2764. i -= MAX_DATA_ACK;
  2765. ncci_ptr->DataAck[i].Number = data->Number;
  2766. ncci_ptr->DataAck[i].Handle = data->Handle;
  2767. (ncci_ptr->data_ack_pending)++;
  2768. }
  2769. send_data(plci);
  2770. return false;
  2771. }
  2772. }
  2773. if (appl)
  2774. {
  2775. if (plci)
  2776. {
  2777. if ((((byte *)(parms[0].info)) >= ((byte *)(plci->msg_in_queue)))
  2778. && (((byte *)(parms[0].info)) < ((byte *)(plci->msg_in_queue)) + sizeof(plci->msg_in_queue)))
  2779. {
  2780. TransmitBufferFree(appl, (byte *)(long)(*((dword *)(parms[0].info))));
  2781. }
  2782. }
  2783. sendf(appl,
  2784. _DATA_B3_R | CONFIRM,
  2785. Id,
  2786. Number,
  2787. "ww", GET_WORD(parms[2].info), Info);
  2788. }
  2789. return false;
  2790. }
  2791. static byte data_b3_res(dword Id, word Number, DIVA_CAPI_ADAPTER *a,
  2792. PLCI *plci, APPL *appl, API_PARSE *parms)
  2793. {
  2794. word n;
  2795. word ncci;
  2796. word NCCIcode;
  2797. dbug(1, dprintf("data_b3_res"));
  2798. ncci = (word)(Id >> 16);
  2799. if (plci && ncci) {
  2800. n = GET_WORD(parms[0].info);
  2801. dbug(1, dprintf("free(%d)", n));
  2802. NCCIcode = ncci | (((word) a->Id) << 8);
  2803. if (n < appl->MaxBuffer &&
  2804. appl->DataNCCI[n] == NCCIcode &&
  2805. (byte)(appl->DataFlags[n] >> 8) == plci->Id) {
  2806. dbug(1, dprintf("found"));
  2807. appl->DataNCCI[n] = 0;
  2808. if (channel_can_xon(plci, a->ncci_ch[ncci])) {
  2809. channel_request_xon(plci, a->ncci_ch[ncci]);
  2810. }
  2811. channel_xmit_xon(plci);
  2812. if (appl->DataFlags[n] & 4) {
  2813. nl_req_ncci(plci, N_DATA_ACK, (byte)ncci);
  2814. return 1;
  2815. }
  2816. }
  2817. }
  2818. return false;
  2819. }
  2820. static byte reset_b3_req(dword Id, word Number, DIVA_CAPI_ADAPTER *a,
  2821. PLCI *plci, APPL *appl, API_PARSE *parms)
  2822. {
  2823. word Info;
  2824. word ncci;
  2825. dbug(1, dprintf("reset_b3_req"));
  2826. Info = _WRONG_IDENTIFIER;
  2827. ncci = (word)(Id >> 16);
  2828. if (plci && ncci)
  2829. {
  2830. Info = _WRONG_STATE;
  2831. switch (plci->B3_prot)
  2832. {
  2833. case B3_ISO8208:
  2834. case B3_X25_DCE:
  2835. if (a->ncci_state[ncci] == CONNECTED)
  2836. {
  2837. nl_req_ncci(plci, N_RESET, (byte)ncci);
  2838. send_req(plci);
  2839. Info = GOOD;
  2840. }
  2841. break;
  2842. case B3_TRANSPARENT:
  2843. if (a->ncci_state[ncci] == CONNECTED)
  2844. {
  2845. start_internal_command(Id, plci, reset_b3_command);
  2846. Info = GOOD;
  2847. }
  2848. break;
  2849. }
  2850. }
  2851. /* reset_b3 must result in a reset_b3_con & reset_b3_Ind */
  2852. sendf(appl,
  2853. _RESET_B3_R | CONFIRM,
  2854. Id,
  2855. Number,
  2856. "w", Info);
  2857. return false;
  2858. }
  2859. static byte reset_b3_res(dword Id, word Number, DIVA_CAPI_ADAPTER *a,
  2860. PLCI *plci, APPL *appl, API_PARSE *parms)
  2861. {
  2862. word ncci;
  2863. dbug(1, dprintf("reset_b3_res"));
  2864. ncci = (word)(Id >> 16);
  2865. if (plci && ncci) {
  2866. switch (plci->B3_prot)
  2867. {
  2868. case B3_ISO8208:
  2869. case B3_X25_DCE:
  2870. if (a->ncci_state[ncci] == INC_RES_PENDING)
  2871. {
  2872. a->ncci_state[ncci] = CONNECTED;
  2873. nl_req_ncci(plci, N_RESET_ACK, (byte)ncci);
  2874. return true;
  2875. }
  2876. break;
  2877. }
  2878. }
  2879. return false;
  2880. }
  2881. static byte connect_b3_t90_a_res(dword Id, word Number, DIVA_CAPI_ADAPTER *a,
  2882. PLCI *plci, APPL *appl, API_PARSE *parms)
  2883. {
  2884. word ncci;
  2885. API_PARSE *ncpi;
  2886. byte req;
  2887. dbug(1, dprintf("connect_b3_t90_a_res"));
  2888. ncci = (word)(Id >> 16);
  2889. if (plci && ncci) {
  2890. if (a->ncci_state[ncci] == INC_ACT_PENDING) {
  2891. a->ncci_state[ncci] = CONNECTED;
  2892. }
  2893. else if (a->ncci_state[ncci] == INC_CON_PENDING) {
  2894. a->ncci_state[ncci] = CONNECTED;
  2895. req = N_CONNECT_ACK;
  2896. /* parms[0]==0 for CAPI original message definition! */
  2897. if (parms[0].info) {
  2898. ncpi = &parms[1];
  2899. if (ncpi->length > 2) {
  2900. if (ncpi->info[1] & 1) req = N_CONNECT_ACK | N_D_BIT;
  2901. add_d(plci, (word)(ncpi->length - 3), &ncpi->info[4]);
  2902. }
  2903. }
  2904. nl_req_ncci(plci, req, (byte)ncci);
  2905. return 1;
  2906. }
  2907. }
  2908. return false;
  2909. }
  2910. static byte select_b_req(dword Id, word Number, DIVA_CAPI_ADAPTER *a,
  2911. PLCI *plci, APPL *appl, API_PARSE *msg)
  2912. {
  2913. word Info = 0;
  2914. word i;
  2915. byte tel;
  2916. API_PARSE bp_parms[7];
  2917. if (!plci || !msg)
  2918. {
  2919. Info = _WRONG_IDENTIFIER;
  2920. }
  2921. else
  2922. {
  2923. dbug(1, dprintf("select_b_req[%d],PLCI=0x%x,Tel=0x%x,NL=0x%x,appl=0x%x,sstate=0x%x",
  2924. msg->length, plci->Id, plci->tel, plci->NL.Id, plci->appl, plci->SuppState));
  2925. dbug(1, dprintf("PlciState=0x%x", plci->State));
  2926. for (i = 0; i < 7; i++) bp_parms[i].length = 0;
  2927. /* check if no channel is open, no B3 connected only */
  2928. if ((plci->State == IDLE) || (plci->State == OUTG_DIS_PENDING) || (plci->State == INC_DIS_PENDING)
  2929. || (plci->SuppState != IDLE) || plci->channels || plci->nl_remove_id)
  2930. {
  2931. Info = _WRONG_STATE;
  2932. }
  2933. /* check message format and fill bp_parms pointer */
  2934. else if (msg->length && api_parse(&msg->info[1], (word)msg->length, "wwwsss", bp_parms))
  2935. {
  2936. Info = _WRONG_MESSAGE_FORMAT;
  2937. }
  2938. else
  2939. {
  2940. if ((plci->State == INC_CON_PENDING) || (plci->State == INC_CON_ALERT)) /* send alert tone inband to the network, */
  2941. { /* e.g. Qsig or RBS or Cornet-N or xess PRI */
  2942. if (Id & EXT_CONTROLLER)
  2943. {
  2944. sendf(appl, _SELECT_B_REQ | CONFIRM, Id, Number, "w", 0x2002); /* wrong controller */
  2945. return 0;
  2946. }
  2947. plci->State = INC_CON_CONNECTED_ALERT;
  2948. plci->appl = appl;
  2949. __clear_bit(appl->Id - 1, plci->c_ind_mask_table);
  2950. dbug(1, dprintf("c_ind_mask =%*pb", MAX_APPL, plci->c_ind_mask_table));
  2951. /* disconnect the other appls its quasi a connect */
  2952. for_each_set_bit(i, plci->c_ind_mask_table, max_appl)
  2953. sendf(&application[i], _DISCONNECT_I, Id, 0, "w", _OTHER_APPL_CONNECTED);
  2954. }
  2955. api_save_msg(msg, "s", &plci->saved_msg);
  2956. tel = plci->tel;
  2957. if (Id & EXT_CONTROLLER)
  2958. {
  2959. if (tel) /* external controller in use by this PLCI */
  2960. {
  2961. if (a->AdvSignalAppl && a->AdvSignalAppl != appl)
  2962. {
  2963. dbug(1, dprintf("Ext_Ctrl in use 1"));
  2964. Info = _WRONG_STATE;
  2965. }
  2966. }
  2967. else /* external controller NOT in use by this PLCI ? */
  2968. {
  2969. if (a->AdvSignalPLCI)
  2970. {
  2971. dbug(1, dprintf("Ext_Ctrl in use 2"));
  2972. Info = _WRONG_STATE;
  2973. }
  2974. else /* activate the codec */
  2975. {
  2976. dbug(1, dprintf("Ext_Ctrl start"));
  2977. if (AdvCodecSupport(a, plci, appl, 0))
  2978. {
  2979. dbug(1, dprintf("Error in codec procedures"));
  2980. Info = _WRONG_STATE;
  2981. }
  2982. else if (plci->spoofed_msg == SPOOFING_REQUIRED) /* wait until codec is active */
  2983. {
  2984. plci->spoofed_msg = AWAITING_SELECT_B;
  2985. plci->internal_command = BLOCK_PLCI; /* lock other commands */
  2986. plci->command = 0;
  2987. dbug(1, dprintf("continue if codec loaded"));
  2988. return false;
  2989. }
  2990. }
  2991. }
  2992. }
  2993. else /* external controller bit is OFF */
  2994. {
  2995. if (tel) /* external controller in use, need to switch off */
  2996. {
  2997. if (a->AdvSignalAppl == appl)
  2998. {
  2999. CodecIdCheck(a, plci);
  3000. plci->tel = 0;
  3001. plci->adv_nl = 0;
  3002. dbug(1, dprintf("Ext_Ctrl disable"));
  3003. }
  3004. else
  3005. {
  3006. dbug(1, dprintf("Ext_Ctrl not requested"));
  3007. }
  3008. }
  3009. }
  3010. if (!Info)
  3011. {
  3012. if (plci->call_dir & CALL_DIR_OUT)
  3013. plci->call_dir = CALL_DIR_OUT | CALL_DIR_ORIGINATE;
  3014. else if (plci->call_dir & CALL_DIR_IN)
  3015. plci->call_dir = CALL_DIR_IN | CALL_DIR_ANSWER;
  3016. start_internal_command(Id, plci, select_b_command);
  3017. return false;
  3018. }
  3019. }
  3020. }
  3021. sendf(appl, _SELECT_B_REQ | CONFIRM, Id, Number, "w", Info);
  3022. return false;
  3023. }
  3024. static byte manufacturer_req(dword Id, word Number, DIVA_CAPI_ADAPTER *a,
  3025. PLCI *plci, APPL *appl, API_PARSE *parms)
  3026. {
  3027. word command;
  3028. word i;
  3029. word ncci;
  3030. API_PARSE *m;
  3031. API_PARSE m_parms[5];
  3032. word codec;
  3033. byte req;
  3034. byte ch;
  3035. byte dir;
  3036. static byte chi[2] = {0x01, 0x00};
  3037. static byte lli[2] = {0x01, 0x00};
  3038. static byte codec_cai[2] = {0x01, 0x01};
  3039. static byte null_msg = {0};
  3040. static API_PARSE null_parms = { 0, &null_msg };
  3041. PLCI *v_plci;
  3042. word Info = 0;
  3043. dbug(1, dprintf("manufacturer_req"));
  3044. for (i = 0; i < 5; i++) m_parms[i].length = 0;
  3045. if (GET_DWORD(parms[0].info) != _DI_MANU_ID) {
  3046. Info = _WRONG_MESSAGE_FORMAT;
  3047. }
  3048. command = GET_WORD(parms[1].info);
  3049. m = &parms[2];
  3050. if (!Info)
  3051. {
  3052. switch (command) {
  3053. case _DI_ASSIGN_PLCI:
  3054. if (api_parse(&m->info[1], (word)m->length, "wbbs", m_parms)) {
  3055. Info = _WRONG_MESSAGE_FORMAT;
  3056. break;
  3057. }
  3058. codec = GET_WORD(m_parms[0].info);
  3059. ch = m_parms[1].info[0];
  3060. dir = m_parms[2].info[0];
  3061. if ((i = get_plci(a))) {
  3062. plci = &a->plci[i - 1];
  3063. plci->appl = appl;
  3064. plci->command = _MANUFACTURER_R;
  3065. plci->m_command = command;
  3066. plci->number = Number;
  3067. plci->State = LOCAL_CONNECT;
  3068. Id = (((word)plci->Id << 8) | plci->adapter->Id | 0x80);
  3069. dbug(1, dprintf("ManCMD,plci=0x%x", Id));
  3070. if ((ch == 1 || ch == 2) && (dir <= 2)) {
  3071. chi[1] = (byte)(0x80 | ch);
  3072. lli[1] = 0;
  3073. plci->call_dir = CALL_DIR_OUT | CALL_DIR_ORIGINATE;
  3074. switch (codec)
  3075. {
  3076. case 0:
  3077. Info = add_b1(plci, &m_parms[3], 0, 0);
  3078. break;
  3079. case 1:
  3080. add_p(plci, CAI, codec_cai);
  3081. break;
  3082. /* manual 'swich on' to the codec support without signalling */
  3083. /* first 'assign plci' with this function, then use */
  3084. case 2:
  3085. if (AdvCodecSupport(a, plci, appl, 0)) {
  3086. Info = _RESOURCE_ERROR;
  3087. }
  3088. else {
  3089. Info = add_b1(plci, &null_parms, 0, B1_FACILITY_LOCAL);
  3090. lli[1] = 0x10; /* local call codec stream */
  3091. }
  3092. break;
  3093. }
  3094. plci->State = LOCAL_CONNECT;
  3095. plci->manufacturer = true;
  3096. plci->command = _MANUFACTURER_R;
  3097. plci->m_command = command;
  3098. plci->number = Number;
  3099. if (!Info)
  3100. {
  3101. add_p(plci, LLI, lli);
  3102. add_p(plci, CHI, chi);
  3103. add_p(plci, UID, "\x06\x43\x61\x70\x69\x32\x30");
  3104. sig_req(plci, ASSIGN, DSIG_ID);
  3105. if (!codec)
  3106. {
  3107. Info = add_b23(plci, &m_parms[3]);
  3108. if (!Info)
  3109. {
  3110. nl_req_ncci(plci, ASSIGN, 0);
  3111. send_req(plci);
  3112. }
  3113. }
  3114. if (!Info)
  3115. {
  3116. dbug(1, dprintf("dir=0x%x,spoof=0x%x", dir, plci->spoofed_msg));
  3117. if (plci->spoofed_msg == SPOOFING_REQUIRED)
  3118. {
  3119. api_save_msg(m_parms, "wbbs", &plci->saved_msg);
  3120. plci->spoofed_msg = AWAITING_MANUF_CON;
  3121. plci->internal_command = BLOCK_PLCI; /* reject other req meanwhile */
  3122. plci->command = 0;
  3123. send_req(plci);
  3124. return false;
  3125. }
  3126. if (dir == 1) {
  3127. sig_req(plci, CALL_REQ, 0);
  3128. }
  3129. else if (!dir) {
  3130. sig_req(plci, LISTEN_REQ, 0);
  3131. }
  3132. send_req(plci);
  3133. }
  3134. else
  3135. {
  3136. sendf(appl,
  3137. _MANUFACTURER_R | CONFIRM,
  3138. Id,
  3139. Number,
  3140. "dww", _DI_MANU_ID, command, Info);
  3141. return 2;
  3142. }
  3143. }
  3144. }
  3145. }
  3146. else Info = _OUT_OF_PLCI;
  3147. break;
  3148. case _DI_IDI_CTRL:
  3149. if (!plci)
  3150. {
  3151. Info = _WRONG_IDENTIFIER;
  3152. break;
  3153. }
  3154. if (api_parse(&m->info[1], (word)m->length, "bs", m_parms)) {
  3155. Info = _WRONG_MESSAGE_FORMAT;
  3156. break;
  3157. }
  3158. req = m_parms[0].info[0];
  3159. plci->command = _MANUFACTURER_R;
  3160. plci->m_command = command;
  3161. plci->number = Number;
  3162. if (req == CALL_REQ)
  3163. {
  3164. plci->b_channel = getChannel(&m_parms[1]);
  3165. mixer_set_bchannel_id_esc(plci, plci->b_channel);
  3166. if (plci->spoofed_msg == SPOOFING_REQUIRED)
  3167. {
  3168. plci->spoofed_msg = CALL_REQ | AWAITING_MANUF_CON;
  3169. plci->internal_command = BLOCK_PLCI; /* reject other req meanwhile */
  3170. plci->command = 0;
  3171. break;
  3172. }
  3173. }
  3174. else if (req == LAW_REQ)
  3175. {
  3176. plci->cr_enquiry = true;
  3177. }
  3178. add_ss(plci, FTY, &m_parms[1]);
  3179. sig_req(plci, req, 0);
  3180. send_req(plci);
  3181. if (req == HANGUP)
  3182. {
  3183. if (plci->NL.Id && !plci->nl_remove_id)
  3184. {
  3185. if (plci->channels)
  3186. {
  3187. for (ncci = 1; ncci < MAX_NCCI + 1; ncci++)
  3188. {
  3189. if ((a->ncci_plci[ncci] == plci->Id) && (a->ncci_state[ncci] == CONNECTED))
  3190. {
  3191. a->ncci_state[ncci] = OUTG_DIS_PENDING;
  3192. cleanup_ncci_data(plci, ncci);
  3193. nl_req_ncci(plci, N_DISC, (byte)ncci);
  3194. }
  3195. }
  3196. }
  3197. mixer_remove(plci);
  3198. nl_req_ncci(plci, REMOVE, 0);
  3199. send_req(plci);
  3200. }
  3201. }
  3202. break;
  3203. case _DI_SIG_CTRL:
  3204. /* signalling control for loop activation B-channel */
  3205. if (!plci)
  3206. {
  3207. Info = _WRONG_IDENTIFIER;
  3208. break;
  3209. }
  3210. if (m->length) {
  3211. plci->command = _MANUFACTURER_R;
  3212. plci->number = Number;
  3213. add_ss(plci, FTY, m);
  3214. sig_req(plci, SIG_CTRL, 0);
  3215. send_req(plci);
  3216. }
  3217. else Info = _WRONG_MESSAGE_FORMAT;
  3218. break;
  3219. case _DI_RXT_CTRL:
  3220. /* activation control for receiver/transmitter B-channel */
  3221. if (!plci)
  3222. {
  3223. Info = _WRONG_IDENTIFIER;
  3224. break;
  3225. }
  3226. if (m->length) {
  3227. plci->command = _MANUFACTURER_R;
  3228. plci->number = Number;
  3229. add_ss(plci, FTY, m);
  3230. sig_req(plci, DSP_CTRL, 0);
  3231. send_req(plci);
  3232. }
  3233. else Info = _WRONG_MESSAGE_FORMAT;
  3234. break;
  3235. case _DI_ADV_CODEC:
  3236. case _DI_DSP_CTRL:
  3237. /* TEL_CTRL commands to support non standard adjustments: */
  3238. /* Ring on/off, Handset micro volume, external micro vol. */
  3239. /* handset+external speaker volume, receiver+transm. gain,*/
  3240. /* handsfree on (hookinfo off), set mixer command */
  3241. if (command == _DI_ADV_CODEC)
  3242. {
  3243. if (!a->AdvCodecPLCI) {
  3244. Info = _WRONG_STATE;
  3245. break;
  3246. }
  3247. v_plci = a->AdvCodecPLCI;
  3248. }
  3249. else
  3250. {
  3251. if (plci
  3252. && (m->length >= 3)
  3253. && (m->info[1] == 0x1c)
  3254. && (m->info[2] >= 1))
  3255. {
  3256. if (m->info[3] == DSP_CTRL_OLD_SET_MIXER_COEFFICIENTS)
  3257. {
  3258. if ((plci->tel != ADV_VOICE) || (plci != a->AdvSignalPLCI))
  3259. {
  3260. Info = _WRONG_STATE;
  3261. break;
  3262. }
  3263. a->adv_voice_coef_length = m->info[2] - 1;
  3264. if (a->adv_voice_coef_length > m->length - 3)
  3265. a->adv_voice_coef_length = (byte)(m->length - 3);
  3266. if (a->adv_voice_coef_length > ADV_VOICE_COEF_BUFFER_SIZE)
  3267. a->adv_voice_coef_length = ADV_VOICE_COEF_BUFFER_SIZE;
  3268. for (i = 0; i < a->adv_voice_coef_length; i++)
  3269. a->adv_voice_coef_buffer[i] = m->info[4 + i];
  3270. if (plci->B1_facilities & B1_FACILITY_VOICE)
  3271. adv_voice_write_coefs(plci, ADV_VOICE_WRITE_UPDATE);
  3272. break;
  3273. }
  3274. else if (m->info[3] == DSP_CTRL_SET_DTMF_PARAMETERS)
  3275. {
  3276. if (!(a->manufacturer_features & MANUFACTURER_FEATURE_DTMF_PARAMETERS))
  3277. {
  3278. Info = _FACILITY_NOT_SUPPORTED;
  3279. break;
  3280. }
  3281. plci->dtmf_parameter_length = m->info[2] - 1;
  3282. if (plci->dtmf_parameter_length > m->length - 3)
  3283. plci->dtmf_parameter_length = (byte)(m->length - 3);
  3284. if (plci->dtmf_parameter_length > DTMF_PARAMETER_BUFFER_SIZE)
  3285. plci->dtmf_parameter_length = DTMF_PARAMETER_BUFFER_SIZE;
  3286. for (i = 0; i < plci->dtmf_parameter_length; i++)
  3287. plci->dtmf_parameter_buffer[i] = m->info[4 + i];
  3288. if (plci->B1_facilities & B1_FACILITY_DTMFR)
  3289. dtmf_parameter_write(plci);
  3290. break;
  3291. }
  3292. }
  3293. v_plci = plci;
  3294. }
  3295. if (!v_plci)
  3296. {
  3297. Info = _WRONG_IDENTIFIER;
  3298. break;
  3299. }
  3300. if (m->length) {
  3301. add_ss(v_plci, FTY, m);
  3302. sig_req(v_plci, TEL_CTRL, 0);
  3303. send_req(v_plci);
  3304. }
  3305. else Info = _WRONG_MESSAGE_FORMAT;
  3306. break;
  3307. case _DI_OPTIONS_REQUEST:
  3308. if (api_parse(&m->info[1], (word)m->length, "d", m_parms)) {
  3309. Info = _WRONG_MESSAGE_FORMAT;
  3310. break;
  3311. }
  3312. if (GET_DWORD(m_parms[0].info) & ~a->man_profile.private_options)
  3313. {
  3314. Info = _FACILITY_NOT_SUPPORTED;
  3315. break;
  3316. }
  3317. a->requested_options_table[appl->Id - 1] = GET_DWORD(m_parms[0].info);
  3318. break;
  3319. default:
  3320. Info = _WRONG_MESSAGE_FORMAT;
  3321. break;
  3322. }
  3323. }
  3324. sendf(appl,
  3325. _MANUFACTURER_R | CONFIRM,
  3326. Id,
  3327. Number,
  3328. "dww", _DI_MANU_ID, command, Info);
  3329. return false;
  3330. }
  3331. static byte manufacturer_res(dword Id, word Number, DIVA_CAPI_ADAPTER *a,
  3332. PLCI *plci, APPL *appl, API_PARSE *msg)
  3333. {
  3334. word indication;
  3335. API_PARSE m_parms[3];
  3336. API_PARSE *ncpi;
  3337. API_PARSE fax_parms[9];
  3338. word i;
  3339. byte len;
  3340. dbug(1, dprintf("manufacturer_res"));
  3341. if ((msg[0].length == 0)
  3342. || (msg[1].length == 0)
  3343. || (GET_DWORD(msg[0].info) != _DI_MANU_ID))
  3344. {
  3345. return false;
  3346. }
  3347. indication = GET_WORD(msg[1].info);
  3348. switch (indication)
  3349. {
  3350. case _DI_NEGOTIATE_B3:
  3351. if (!plci)
  3352. break;
  3353. if (((plci->B3_prot != 4) && (plci->B3_prot != 5))
  3354. || !(plci->ncpi_state & NCPI_NEGOTIATE_B3_SENT))
  3355. {
  3356. dbug(1, dprintf("wrong state for NEGOTIATE_B3 parameters"));
  3357. break;
  3358. }
  3359. if (api_parse(&msg[2].info[1], msg[2].length, "ws", m_parms))
  3360. {
  3361. dbug(1, dprintf("wrong format in NEGOTIATE_B3 parameters"));
  3362. break;
  3363. }
  3364. ncpi = &m_parms[1];
  3365. len = offsetof(T30_INFO, station_id) + T30_MAX_STATION_ID_LENGTH;
  3366. if (plci->fax_connect_info_length < len)
  3367. {
  3368. ((T30_INFO *)(plci->fax_connect_info_buffer))->station_id_len = 0;
  3369. ((T30_INFO *)(plci->fax_connect_info_buffer))->head_line_len = 0;
  3370. }
  3371. if (api_parse(&ncpi->info[1], ncpi->length, "wwwwssss", fax_parms))
  3372. {
  3373. dbug(1, dprintf("non-standard facilities info missing or wrong format"));
  3374. }
  3375. else
  3376. {
  3377. if (plci->fax_connect_info_length <= len)
  3378. plci->fax_connect_info_buffer[len] = 0;
  3379. len += 1 + plci->fax_connect_info_buffer[len];
  3380. if (plci->fax_connect_info_length <= len)
  3381. plci->fax_connect_info_buffer[len] = 0;
  3382. len += 1 + plci->fax_connect_info_buffer[len];
  3383. if ((fax_parms[7].length >= 3) && (fax_parms[7].info[1] >= 2))
  3384. plci->nsf_control_bits = GET_WORD(&fax_parms[7].info[2]);
  3385. plci->fax_connect_info_buffer[len++] = (byte)(fax_parms[7].length);
  3386. for (i = 0; i < fax_parms[7].length; i++)
  3387. plci->fax_connect_info_buffer[len++] = fax_parms[7].info[1 + i];
  3388. }
  3389. plci->fax_connect_info_length = len;
  3390. plci->fax_edata_ack_length = plci->fax_connect_info_length;
  3391. start_internal_command(Id, plci, fax_edata_ack_command);
  3392. break;
  3393. }
  3394. return false;
  3395. }
  3396. /*------------------------------------------------------------------*/
  3397. /* IDI callback function */
  3398. /*------------------------------------------------------------------*/
  3399. void callback(ENTITY *e)
  3400. {
  3401. DIVA_CAPI_ADAPTER *a;
  3402. APPL *appl;
  3403. PLCI *plci;
  3404. CAPI_MSG *m;
  3405. word i, j;
  3406. byte rc;
  3407. byte ch;
  3408. byte req;
  3409. byte global_req;
  3410. int no_cancel_rc;
  3411. dbug(1, dprintf("%x:CB(%x:Req=%x,Rc=%x,Ind=%x)",
  3412. (e->user[0] + 1) & 0x7fff, e->Id, e->Req, e->Rc, e->Ind));
  3413. a = &(adapter[(byte)e->user[0]]);
  3414. plci = &(a->plci[e->user[1]]);
  3415. no_cancel_rc = DIVA_CAPI_SUPPORTS_NO_CANCEL(a);
  3416. /*
  3417. If new protocol code and new XDI is used then CAPI should work
  3418. fully in accordance with IDI cpec an look on callback field instead
  3419. of Rc field for return codes.
  3420. */
  3421. if (((e->complete == 0xff) && no_cancel_rc) ||
  3422. (e->Rc && !no_cancel_rc)) {
  3423. rc = e->Rc;
  3424. ch = e->RcCh;
  3425. req = e->Req;
  3426. e->Rc = 0;
  3427. if (e->user[0] & 0x8000)
  3428. {
  3429. /*
  3430. If REMOVE request was sent then we have to wait until
  3431. return code with Id set to zero arrives.
  3432. All other return codes should be ignored.
  3433. */
  3434. if (req == REMOVE)
  3435. {
  3436. if (e->Id)
  3437. {
  3438. dbug(1, dprintf("cancel RC in REMOVE state"));
  3439. return;
  3440. }
  3441. channel_flow_control_remove(plci);
  3442. for (i = 0; i < 256; i++)
  3443. {
  3444. if (a->FlowControlIdTable[i] == plci->nl_remove_id)
  3445. a->FlowControlIdTable[i] = 0;
  3446. }
  3447. plci->nl_remove_id = 0;
  3448. if (plci->rx_dma_descriptor > 0) {
  3449. diva_free_dma_descriptor(plci, plci->rx_dma_descriptor - 1);
  3450. plci->rx_dma_descriptor = 0;
  3451. }
  3452. }
  3453. if (rc == OK_FC)
  3454. {
  3455. a->FlowControlIdTable[ch] = e->Id;
  3456. a->FlowControlSkipTable[ch] = 0;
  3457. a->ch_flow_control[ch] |= N_OK_FC_PENDING;
  3458. a->ch_flow_plci[ch] = plci->Id;
  3459. plci->nl_req = 0;
  3460. }
  3461. else
  3462. {
  3463. /*
  3464. Cancel return codes self, if feature was requested
  3465. */
  3466. if (no_cancel_rc && (a->FlowControlIdTable[ch] == e->Id) && e->Id) {
  3467. a->FlowControlIdTable[ch] = 0;
  3468. if ((rc == OK) && a->FlowControlSkipTable[ch]) {
  3469. dbug(3, dprintf("XDI CAPI: RC cancelled Id:0x02, Ch:%02x", e->Id, ch));
  3470. return;
  3471. }
  3472. }
  3473. if (a->ch_flow_control[ch] & N_OK_FC_PENDING)
  3474. {
  3475. a->ch_flow_control[ch] &= ~N_OK_FC_PENDING;
  3476. if (ch == e->ReqCh)
  3477. plci->nl_req = 0;
  3478. }
  3479. else
  3480. plci->nl_req = 0;
  3481. }
  3482. if (plci->nl_req)
  3483. control_rc(plci, 0, rc, ch, 0, true);
  3484. else
  3485. {
  3486. if (req == N_XON)
  3487. {
  3488. channel_x_on(plci, ch);
  3489. if (plci->internal_command)
  3490. control_rc(plci, req, rc, ch, 0, true);
  3491. }
  3492. else
  3493. {
  3494. if (plci->nl_global_req)
  3495. {
  3496. global_req = plci->nl_global_req;
  3497. plci->nl_global_req = 0;
  3498. if (rc != ASSIGN_OK) {
  3499. e->Id = 0;
  3500. if (plci->rx_dma_descriptor > 0) {
  3501. diva_free_dma_descriptor(plci, plci->rx_dma_descriptor - 1);
  3502. plci->rx_dma_descriptor = 0;
  3503. }
  3504. }
  3505. channel_xmit_xon(plci);
  3506. control_rc(plci, 0, rc, ch, global_req, true);
  3507. }
  3508. else if (plci->data_sent)
  3509. {
  3510. channel_xmit_xon(plci);
  3511. plci->data_sent = false;
  3512. plci->NL.XNum = 1;
  3513. data_rc(plci, ch);
  3514. if (plci->internal_command)
  3515. control_rc(plci, req, rc, ch, 0, true);
  3516. }
  3517. else
  3518. {
  3519. channel_xmit_xon(plci);
  3520. control_rc(plci, req, rc, ch, 0, true);
  3521. }
  3522. }
  3523. }
  3524. }
  3525. else
  3526. {
  3527. /*
  3528. If REMOVE request was sent then we have to wait until
  3529. return code with Id set to zero arrives.
  3530. All other return codes should be ignored.
  3531. */
  3532. if (req == REMOVE)
  3533. {
  3534. if (e->Id)
  3535. {
  3536. dbug(1, dprintf("cancel RC in REMOVE state"));
  3537. return;
  3538. }
  3539. plci->sig_remove_id = 0;
  3540. }
  3541. plci->sig_req = 0;
  3542. if (plci->sig_global_req)
  3543. {
  3544. global_req = plci->sig_global_req;
  3545. plci->sig_global_req = 0;
  3546. if (rc != ASSIGN_OK)
  3547. e->Id = 0;
  3548. channel_xmit_xon(plci);
  3549. control_rc(plci, 0, rc, ch, global_req, false);
  3550. }
  3551. else
  3552. {
  3553. channel_xmit_xon(plci);
  3554. control_rc(plci, req, rc, ch, 0, false);
  3555. }
  3556. }
  3557. /*
  3558. Again: in accordance with IDI spec Rc and Ind can't be delivered in the
  3559. same callback. Also if new XDI and protocol code used then jump
  3560. direct to finish.
  3561. */
  3562. if (no_cancel_rc) {
  3563. channel_xmit_xon(plci);
  3564. goto capi_callback_suffix;
  3565. }
  3566. }
  3567. channel_xmit_xon(plci);
  3568. if (e->Ind) {
  3569. if (e->user[0] & 0x8000) {
  3570. byte Ind = e->Ind & 0x0f;
  3571. byte Ch = e->IndCh;
  3572. if (((Ind == N_DISC) || (Ind == N_DISC_ACK)) &&
  3573. (a->ch_flow_plci[Ch] == plci->Id)) {
  3574. if (a->ch_flow_control[Ch] & N_RX_FLOW_CONTROL_MASK) {
  3575. dbug(3, dprintf("XDI CAPI: I: pending N-XON Ch:%02x", Ch));
  3576. }
  3577. a->ch_flow_control[Ch] &= ~N_RX_FLOW_CONTROL_MASK;
  3578. }
  3579. nl_ind(plci);
  3580. if ((e->RNR != 1) &&
  3581. (a->ch_flow_plci[Ch] == plci->Id) &&
  3582. (a->ch_flow_control[Ch] & N_RX_FLOW_CONTROL_MASK)) {
  3583. a->ch_flow_control[Ch] &= ~N_RX_FLOW_CONTROL_MASK;
  3584. dbug(3, dprintf("XDI CAPI: I: remove faked N-XON Ch:%02x", Ch));
  3585. }
  3586. } else {
  3587. sig_ind(plci);
  3588. }
  3589. e->Ind = 0;
  3590. }
  3591. capi_callback_suffix:
  3592. while (!plci->req_in
  3593. && !plci->internal_command
  3594. && (plci->msg_in_write_pos != plci->msg_in_read_pos))
  3595. {
  3596. j = (plci->msg_in_read_pos == plci->msg_in_wrap_pos) ? 0 : plci->msg_in_read_pos;
  3597. i = (((CAPI_MSG *)(&((byte *)(plci->msg_in_queue))[j]))->header.length + 3) & 0xfffc;
  3598. m = (CAPI_MSG *)(&((byte *)(plci->msg_in_queue))[j]);
  3599. appl = *((APPL **)(&((byte *)(plci->msg_in_queue))[j + i]));
  3600. dbug(1, dprintf("dequeue msg(0x%04x) - write=%d read=%d wrap=%d",
  3601. m->header.command, plci->msg_in_write_pos, plci->msg_in_read_pos, plci->msg_in_wrap_pos));
  3602. if (plci->msg_in_read_pos == plci->msg_in_wrap_pos)
  3603. {
  3604. plci->msg_in_wrap_pos = MSG_IN_QUEUE_SIZE;
  3605. plci->msg_in_read_pos = i + MSG_IN_OVERHEAD;
  3606. }
  3607. else
  3608. {
  3609. plci->msg_in_read_pos = j + i + MSG_IN_OVERHEAD;
  3610. }
  3611. if (plci->msg_in_read_pos == plci->msg_in_write_pos)
  3612. {
  3613. plci->msg_in_write_pos = MSG_IN_QUEUE_SIZE;
  3614. plci->msg_in_read_pos = MSG_IN_QUEUE_SIZE;
  3615. }
  3616. else if (plci->msg_in_read_pos == plci->msg_in_wrap_pos)
  3617. {
  3618. plci->msg_in_read_pos = MSG_IN_QUEUE_SIZE;
  3619. plci->msg_in_wrap_pos = MSG_IN_QUEUE_SIZE;
  3620. }
  3621. i = api_put(appl, m);
  3622. if (i != 0)
  3623. {
  3624. if (m->header.command == _DATA_B3_R)
  3625. TransmitBufferFree(appl, (byte *)(long)(m->info.data_b3_req.Data));
  3626. dbug(1, dprintf("Error 0x%04x from msg(0x%04x)", i, m->header.command));
  3627. break;
  3628. }
  3629. if (plci->li_notify_update)
  3630. {
  3631. plci->li_notify_update = false;
  3632. mixer_notify_update(plci, false);
  3633. }
  3634. }
  3635. send_data(plci);
  3636. send_req(plci);
  3637. }
  3638. static void control_rc(PLCI *plci, byte req, byte rc, byte ch, byte global_req,
  3639. byte nl_rc)
  3640. {
  3641. dword Id;
  3642. dword rId;
  3643. word Number;
  3644. word Info = 0;
  3645. word i;
  3646. word ncci;
  3647. DIVA_CAPI_ADAPTER *a;
  3648. APPL *appl;
  3649. PLCI *rplci;
  3650. byte SSparms[] = "\x05\x00\x00\x02\x00\x00";
  3651. byte SSstruct[] = "\x09\x00\x00\x06\x00\x00\x00\x00\x00\x00";
  3652. if (!plci) {
  3653. dbug(0, dprintf("A: control_rc, no plci %02x:%02x:%02x:%02x:%02x", req, rc, ch, global_req, nl_rc));
  3654. return;
  3655. }
  3656. dbug(1, dprintf("req0_in/out=%d/%d", plci->req_in, plci->req_out));
  3657. if (plci->req_in != plci->req_out)
  3658. {
  3659. if (nl_rc || (global_req != ASSIGN) || (rc == ASSIGN_OK))
  3660. {
  3661. dbug(1, dprintf("req_1return"));
  3662. return;
  3663. }
  3664. /* cancel outstanding request on the PLCI after SIG ASSIGN failure */
  3665. }
  3666. plci->req_in = plci->req_in_start = plci->req_out = 0;
  3667. dbug(1, dprintf("control_rc"));
  3668. appl = plci->appl;
  3669. a = plci->adapter;
  3670. ncci = a->ch_ncci[ch];
  3671. if (appl)
  3672. {
  3673. Id = (((dword)(ncci ? ncci : ch)) << 16) | ((word)plci->Id << 8) | a->Id;
  3674. if (plci->tel && plci->SuppState != CALL_HELD) Id |= EXT_CONTROLLER;
  3675. Number = plci->number;
  3676. 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));
  3677. dbug(1, dprintf("channels=0x%x", plci->channels));
  3678. if (plci_remove_check(plci))
  3679. return;
  3680. if (req == REMOVE && rc == ASSIGN_OK)
  3681. {
  3682. sig_req(plci, HANGUP, 0);
  3683. sig_req(plci, REMOVE, 0);
  3684. send_req(plci);
  3685. }
  3686. if (plci->command)
  3687. {
  3688. switch (plci->command)
  3689. {
  3690. case C_HOLD_REQ:
  3691. dbug(1, dprintf("HoldRC=0x%x", rc));
  3692. SSparms[1] = (byte)S_HOLD;
  3693. if (rc != OK)
  3694. {
  3695. plci->SuppState = IDLE;
  3696. Info = 0x2001;
  3697. }
  3698. sendf(appl, _FACILITY_R | CONFIRM, Id, Number, "wws", Info, 3, SSparms);
  3699. break;
  3700. case C_RETRIEVE_REQ:
  3701. dbug(1, dprintf("RetrieveRC=0x%x", rc));
  3702. SSparms[1] = (byte)S_RETRIEVE;
  3703. if (rc != OK)
  3704. {
  3705. plci->SuppState = CALL_HELD;
  3706. Info = 0x2001;
  3707. }
  3708. sendf(appl, _FACILITY_R | CONFIRM, Id, Number, "wws", Info, 3, SSparms);
  3709. break;
  3710. case _INFO_R:
  3711. dbug(1, dprintf("InfoRC=0x%x", rc));
  3712. if (rc != OK) Info = _WRONG_STATE;
  3713. sendf(appl, _INFO_R | CONFIRM, Id, Number, "w", Info);
  3714. break;
  3715. case _CONNECT_R:
  3716. dbug(1, dprintf("Connect_R=0x%x/0x%x/0x%x/0x%x", req, rc, global_req, nl_rc));
  3717. if (plci->State == INC_DIS_PENDING)
  3718. break;
  3719. if (plci->Sig.Id != 0xff)
  3720. {
  3721. if (((global_req == ASSIGN) && (rc != ASSIGN_OK))
  3722. || (!nl_rc && (req == CALL_REQ) && (rc != OK)))
  3723. {
  3724. dbug(1, dprintf("No more IDs/Call_Req failed"));
  3725. sendf(appl, _CONNECT_R | CONFIRM, Id & 0xffL, Number, "w", _OUT_OF_PLCI);
  3726. plci_remove(plci);
  3727. plci->State = IDLE;
  3728. break;
  3729. }
  3730. if (plci->State != LOCAL_CONNECT) plci->State = OUTG_CON_PENDING;
  3731. sendf(appl, _CONNECT_R | CONFIRM, Id, Number, "w", 0);
  3732. }
  3733. else /* D-ch activation */
  3734. {
  3735. if (rc != ASSIGN_OK)
  3736. {
  3737. dbug(1, dprintf("No more IDs/X.25 Call_Req failed"));
  3738. sendf(appl, _CONNECT_R | CONFIRM, Id & 0xffL, Number, "w", _OUT_OF_PLCI);
  3739. plci_remove(plci);
  3740. plci->State = IDLE;
  3741. break;
  3742. }
  3743. sendf(appl, _CONNECT_R | CONFIRM, Id, Number, "w", 0);
  3744. sendf(plci->appl, _CONNECT_ACTIVE_I, Id, 0, "sss", "", "", "");
  3745. plci->State = INC_ACT_PENDING;
  3746. }
  3747. break;
  3748. case _CONNECT_I | RESPONSE:
  3749. if (plci->State != INC_DIS_PENDING)
  3750. plci->State = INC_CON_ACCEPT;
  3751. break;
  3752. case _DISCONNECT_R:
  3753. if (plci->State == INC_DIS_PENDING)
  3754. break;
  3755. if (plci->Sig.Id != 0xff)
  3756. {
  3757. plci->State = OUTG_DIS_PENDING;
  3758. sendf(appl, _DISCONNECT_R | CONFIRM, Id, Number, "w", 0);
  3759. }
  3760. break;
  3761. case SUSPEND_REQ:
  3762. break;
  3763. case RESUME_REQ:
  3764. break;
  3765. case _CONNECT_B3_R:
  3766. if (rc != OK)
  3767. {
  3768. sendf(appl, _CONNECT_B3_R | CONFIRM, Id, Number, "w", _WRONG_IDENTIFIER);
  3769. break;
  3770. }
  3771. ncci = get_ncci(plci, ch, 0);
  3772. Id = (Id & 0xffff) | (((dword) ncci) << 16);
  3773. plci->channels++;
  3774. if (req == N_RESET)
  3775. {
  3776. a->ncci_state[ncci] = INC_ACT_PENDING;
  3777. sendf(appl, _CONNECT_B3_R | CONFIRM, Id, Number, "w", 0);
  3778. sendf(appl, _CONNECT_B3_ACTIVE_I, Id, 0, "s", "");
  3779. }
  3780. else
  3781. {
  3782. a->ncci_state[ncci] = OUTG_CON_PENDING;
  3783. sendf(appl, _CONNECT_B3_R | CONFIRM, Id, Number, "w", 0);
  3784. }
  3785. break;
  3786. case _CONNECT_B3_I | RESPONSE:
  3787. break;
  3788. case _RESET_B3_R:
  3789. /* sendf(appl, _RESET_B3_R | CONFIRM, Id, Number, "w", 0);*/
  3790. break;
  3791. case _DISCONNECT_B3_R:
  3792. sendf(appl, _DISCONNECT_B3_R | CONFIRM, Id, Number, "w", 0);
  3793. break;
  3794. case _MANUFACTURER_R:
  3795. break;
  3796. case PERM_LIST_REQ:
  3797. if (rc != OK)
  3798. {
  3799. Info = _WRONG_IDENTIFIER;
  3800. sendf(plci->appl, _CONNECT_R | CONFIRM, Id, Number, "w", Info);
  3801. plci_remove(plci);
  3802. }
  3803. else
  3804. sendf(plci->appl, _CONNECT_R | CONFIRM, Id, Number, "w", Info);
  3805. break;
  3806. default:
  3807. break;
  3808. }
  3809. plci->command = 0;
  3810. }
  3811. else if (plci->internal_command)
  3812. {
  3813. switch (plci->internal_command)
  3814. {
  3815. case BLOCK_PLCI:
  3816. return;
  3817. case GET_MWI_STATE:
  3818. if (rc == OK) /* command supported, wait for indication */
  3819. {
  3820. return;
  3821. }
  3822. plci_remove(plci);
  3823. break;
  3824. /* Get Supported Services */
  3825. case GETSERV_REQ_PEND:
  3826. if (rc == OK) /* command supported, wait for indication */
  3827. {
  3828. break;
  3829. }
  3830. PUT_DWORD(&SSstruct[6], MASK_TERMINAL_PORTABILITY);
  3831. sendf(appl, _FACILITY_R | CONFIRM, Id, Number, "wws", 0, 3, SSstruct);
  3832. plci_remove(plci);
  3833. break;
  3834. case INTERR_DIVERSION_REQ_PEND: /* Interrogate Parameters */
  3835. case INTERR_NUMBERS_REQ_PEND:
  3836. case CF_START_PEND: /* Call Forwarding Start pending */
  3837. case CF_STOP_PEND: /* Call Forwarding Stop pending */
  3838. case CCBS_REQUEST_REQ_PEND:
  3839. case CCBS_DEACTIVATE_REQ_PEND:
  3840. case CCBS_INTERROGATE_REQ_PEND:
  3841. switch (plci->internal_command)
  3842. {
  3843. case INTERR_DIVERSION_REQ_PEND:
  3844. SSparms[1] = S_INTERROGATE_DIVERSION;
  3845. break;
  3846. case INTERR_NUMBERS_REQ_PEND:
  3847. SSparms[1] = S_INTERROGATE_NUMBERS;
  3848. break;
  3849. case CF_START_PEND:
  3850. SSparms[1] = S_CALL_FORWARDING_START;
  3851. break;
  3852. case CF_STOP_PEND:
  3853. SSparms[1] = S_CALL_FORWARDING_STOP;
  3854. break;
  3855. case CCBS_REQUEST_REQ_PEND:
  3856. SSparms[1] = S_CCBS_REQUEST;
  3857. break;
  3858. case CCBS_DEACTIVATE_REQ_PEND:
  3859. SSparms[1] = S_CCBS_DEACTIVATE;
  3860. break;
  3861. case CCBS_INTERROGATE_REQ_PEND:
  3862. SSparms[1] = S_CCBS_INTERROGATE;
  3863. break;
  3864. }
  3865. if (global_req == ASSIGN)
  3866. {
  3867. dbug(1, dprintf("AssignDiversion_RC=0x%x/0x%x", req, rc));
  3868. return;
  3869. }
  3870. if (!plci->appl) break;
  3871. if (rc == ISDN_GUARD_REJ)
  3872. {
  3873. Info = _CAPI_GUARD_ERROR;
  3874. }
  3875. else if (rc != OK)
  3876. {
  3877. Info = _SUPPLEMENTARY_SERVICE_NOT_SUPPORTED;
  3878. }
  3879. sendf(plci->appl, _FACILITY_R | CONFIRM, Id & 0x7,
  3880. plci->number, "wws", Info, (word)3, SSparms);
  3881. if (Info) plci_remove(plci);
  3882. break;
  3883. /* 3pty conference pending */
  3884. case PTY_REQ_PEND:
  3885. if (!plci->relatedPTYPLCI) break;
  3886. rplci = plci->relatedPTYPLCI;
  3887. SSparms[1] = plci->ptyState;
  3888. rId = ((word)rplci->Id << 8) | rplci->adapter->Id;
  3889. if (rplci->tel) rId |= EXT_CONTROLLER;
  3890. if (rc != OK)
  3891. {
  3892. Info = 0x300E; /* not supported */
  3893. plci->relatedPTYPLCI = NULL;
  3894. plci->ptyState = 0;
  3895. }
  3896. sendf(rplci->appl,
  3897. _FACILITY_R | CONFIRM,
  3898. rId,
  3899. plci->number,
  3900. "wws", Info, (word)3, SSparms);
  3901. break;
  3902. /* Explicit Call Transfer pending */
  3903. case ECT_REQ_PEND:
  3904. dbug(1, dprintf("ECT_RC=0x%x/0x%x", req, rc));
  3905. if (!plci->relatedPTYPLCI) break;
  3906. rplci = plci->relatedPTYPLCI;
  3907. SSparms[1] = S_ECT;
  3908. rId = ((word)rplci->Id << 8) | rplci->adapter->Id;
  3909. if (rplci->tel) rId |= EXT_CONTROLLER;
  3910. if (rc != OK)
  3911. {
  3912. Info = 0x300E; /* not supported */
  3913. plci->relatedPTYPLCI = NULL;
  3914. plci->ptyState = 0;
  3915. }
  3916. sendf(rplci->appl,
  3917. _FACILITY_R | CONFIRM,
  3918. rId,
  3919. plci->number,
  3920. "wws", Info, (word)3, SSparms);
  3921. break;
  3922. case _MANUFACTURER_R:
  3923. dbug(1, dprintf("_Manufacturer_R=0x%x/0x%x", req, rc));
  3924. if ((global_req == ASSIGN) && (rc != ASSIGN_OK))
  3925. {
  3926. dbug(1, dprintf("No more IDs"));
  3927. sendf(appl, _MANUFACTURER_R | CONFIRM, Id, Number, "dww", _DI_MANU_ID, _MANUFACTURER_R, _OUT_OF_PLCI);
  3928. plci_remove(plci); /* after codec init, internal codec commands pending */
  3929. }
  3930. break;
  3931. case _CONNECT_R:
  3932. dbug(1, dprintf("_Connect_R=0x%x/0x%x", req, rc));
  3933. if ((global_req == ASSIGN) && (rc != ASSIGN_OK))
  3934. {
  3935. dbug(1, dprintf("No more IDs"));
  3936. sendf(appl, _CONNECT_R | CONFIRM, Id & 0xffL, Number, "w", _OUT_OF_PLCI);
  3937. plci_remove(plci); /* after codec init, internal codec commands pending */
  3938. }
  3939. break;
  3940. case PERM_COD_HOOK: /* finished with Hook_Ind */
  3941. return;
  3942. case PERM_COD_CALL:
  3943. dbug(1, dprintf("***Codec Connect_Pending A, Rc = 0x%x", rc));
  3944. plci->internal_command = PERM_COD_CONN_PEND;
  3945. return;
  3946. case PERM_COD_ASSIGN:
  3947. dbug(1, dprintf("***Codec Assign A, Rc = 0x%x", rc));
  3948. if (rc != ASSIGN_OK) break;
  3949. sig_req(plci, CALL_REQ, 0);
  3950. send_req(plci);
  3951. plci->internal_command = PERM_COD_CALL;
  3952. return;
  3953. /* Null Call Reference Request pending */
  3954. case C_NCR_FAC_REQ:
  3955. dbug(1, dprintf("NCR_FAC=0x%x/0x%x", req, rc));
  3956. if (global_req == ASSIGN)
  3957. {
  3958. if (rc == ASSIGN_OK)
  3959. {
  3960. return;
  3961. }
  3962. else
  3963. {
  3964. sendf(appl, _INFO_R | CONFIRM, Id & 0xf, Number, "w", _WRONG_STATE);
  3965. appl->NullCREnable = false;
  3966. plci_remove(plci);
  3967. }
  3968. }
  3969. else if (req == NCR_FACILITY)
  3970. {
  3971. if (rc == OK)
  3972. {
  3973. sendf(appl, _INFO_R | CONFIRM, Id & 0xf, Number, "w", 0);
  3974. }
  3975. else
  3976. {
  3977. sendf(appl, _INFO_R | CONFIRM, Id & 0xf, Number, "w", _WRONG_STATE);
  3978. appl->NullCREnable = false;
  3979. }
  3980. plci_remove(plci);
  3981. }
  3982. break;
  3983. case HOOK_ON_REQ:
  3984. if (plci->channels)
  3985. {
  3986. if (a->ncci_state[ncci] == CONNECTED)
  3987. {
  3988. a->ncci_state[ncci] = OUTG_DIS_PENDING;
  3989. cleanup_ncci_data(plci, ncci);
  3990. nl_req_ncci(plci, N_DISC, (byte)ncci);
  3991. }
  3992. break;
  3993. }
  3994. break;
  3995. case HOOK_OFF_REQ:
  3996. if (plci->State == INC_DIS_PENDING)
  3997. break;
  3998. sig_req(plci, CALL_REQ, 0);
  3999. send_req(plci);
  4000. plci->State = OUTG_CON_PENDING;
  4001. break;
  4002. case MWI_ACTIVATE_REQ_PEND:
  4003. case MWI_DEACTIVATE_REQ_PEND:
  4004. if (global_req == ASSIGN && rc == ASSIGN_OK)
  4005. {
  4006. dbug(1, dprintf("MWI_REQ assigned"));
  4007. return;
  4008. }
  4009. else if (rc != OK)
  4010. {
  4011. if (rc == WRONG_IE)
  4012. {
  4013. Info = 0x2007; /* Illegal message parameter coding */
  4014. dbug(1, dprintf("MWI_REQ invalid parameter"));
  4015. }
  4016. else
  4017. {
  4018. Info = 0x300B; /* not supported */
  4019. dbug(1, dprintf("MWI_REQ not supported"));
  4020. }
  4021. /* 0x3010: Request not allowed in this state */
  4022. PUT_WORD(&SSparms[4], 0x300E); /* SS not supported */
  4023. }
  4024. if (plci->internal_command == MWI_ACTIVATE_REQ_PEND)
  4025. {
  4026. PUT_WORD(&SSparms[1], S_MWI_ACTIVATE);
  4027. }
  4028. else PUT_WORD(&SSparms[1], S_MWI_DEACTIVATE);
  4029. if (plci->cr_enquiry)
  4030. {
  4031. sendf(plci->appl,
  4032. _FACILITY_R | CONFIRM,
  4033. Id & 0xf,
  4034. plci->number,
  4035. "wws", Info, (word)3, SSparms);
  4036. if (rc != OK) plci_remove(plci);
  4037. }
  4038. else
  4039. {
  4040. sendf(plci->appl,
  4041. _FACILITY_R | CONFIRM,
  4042. Id,
  4043. plci->number,
  4044. "wws", Info, (word)3, SSparms);
  4045. }
  4046. break;
  4047. case CONF_BEGIN_REQ_PEND:
  4048. case CONF_ADD_REQ_PEND:
  4049. case CONF_SPLIT_REQ_PEND:
  4050. case CONF_DROP_REQ_PEND:
  4051. case CONF_ISOLATE_REQ_PEND:
  4052. case CONF_REATTACH_REQ_PEND:
  4053. dbug(1, dprintf("CONF_RC=0x%x/0x%x", req, rc));
  4054. if ((plci->internal_command == CONF_ADD_REQ_PEND) && (!plci->relatedPTYPLCI)) break;
  4055. rplci = plci;
  4056. rId = Id;
  4057. switch (plci->internal_command)
  4058. {
  4059. case CONF_BEGIN_REQ_PEND:
  4060. SSparms[1] = S_CONF_BEGIN;
  4061. break;
  4062. case CONF_ADD_REQ_PEND:
  4063. SSparms[1] = S_CONF_ADD;
  4064. rplci = plci->relatedPTYPLCI;
  4065. rId = ((word)rplci->Id << 8) | rplci->adapter->Id;
  4066. break;
  4067. case CONF_SPLIT_REQ_PEND:
  4068. SSparms[1] = S_CONF_SPLIT;
  4069. break;
  4070. case CONF_DROP_REQ_PEND:
  4071. SSparms[1] = S_CONF_DROP;
  4072. break;
  4073. case CONF_ISOLATE_REQ_PEND:
  4074. SSparms[1] = S_CONF_ISOLATE;
  4075. break;
  4076. case CONF_REATTACH_REQ_PEND:
  4077. SSparms[1] = S_CONF_REATTACH;
  4078. break;
  4079. }
  4080. if (rc != OK)
  4081. {
  4082. Info = 0x300E; /* not supported */
  4083. plci->relatedPTYPLCI = NULL;
  4084. plci->ptyState = 0;
  4085. }
  4086. sendf(rplci->appl,
  4087. _FACILITY_R | CONFIRM,
  4088. rId,
  4089. plci->number,
  4090. "wws", Info, (word)3, SSparms);
  4091. break;
  4092. case VSWITCH_REQ_PEND:
  4093. if (rc != OK)
  4094. {
  4095. if (plci->relatedPTYPLCI)
  4096. {
  4097. plci->relatedPTYPLCI->vswitchstate = 0;
  4098. plci->relatedPTYPLCI->vsprot = 0;
  4099. plci->relatedPTYPLCI->vsprotdialect = 0;
  4100. }
  4101. plci->vswitchstate = 0;
  4102. plci->vsprot = 0;
  4103. plci->vsprotdialect = 0;
  4104. }
  4105. else
  4106. {
  4107. if (plci->relatedPTYPLCI &&
  4108. plci->vswitchstate == 1 &&
  4109. plci->relatedPTYPLCI->vswitchstate == 3) /* join complete */
  4110. plci->vswitchstate = 3;
  4111. }
  4112. break;
  4113. /* Call Deflection Request pending (SSCT) */
  4114. case CD_REQ_PEND:
  4115. SSparms[1] = S_CALL_DEFLECTION;
  4116. if (rc != OK)
  4117. {
  4118. Info = 0x300E; /* not supported */
  4119. plci->appl->CDEnable = 0;
  4120. }
  4121. sendf(plci->appl, _FACILITY_R | CONFIRM, Id,
  4122. plci->number, "wws", Info, (word)3, SSparms);
  4123. break;
  4124. case RTP_CONNECT_B3_REQ_COMMAND_2:
  4125. if (rc == OK)
  4126. {
  4127. ncci = get_ncci(plci, ch, 0);
  4128. Id = (Id & 0xffff) | (((dword) ncci) << 16);
  4129. plci->channels++;
  4130. a->ncci_state[ncci] = OUTG_CON_PENDING;
  4131. }
  4132. /* fall through */
  4133. default:
  4134. if (plci->internal_command_queue[0])
  4135. {
  4136. (*(plci->internal_command_queue[0]))(Id, plci, rc);
  4137. if (plci->internal_command)
  4138. return;
  4139. }
  4140. break;
  4141. }
  4142. next_internal_command(Id, plci);
  4143. }
  4144. }
  4145. else /* appl==0 */
  4146. {
  4147. Id = ((word)plci->Id << 8) | plci->adapter->Id;
  4148. if (plci->tel) Id |= EXT_CONTROLLER;
  4149. switch (plci->internal_command)
  4150. {
  4151. case BLOCK_PLCI:
  4152. return;
  4153. case START_L1_SIG_ASSIGN_PEND:
  4154. case REM_L1_SIG_ASSIGN_PEND:
  4155. if (global_req == ASSIGN)
  4156. {
  4157. break;
  4158. }
  4159. else
  4160. {
  4161. dbug(1, dprintf("***L1 Req rem PLCI"));
  4162. plci->internal_command = 0;
  4163. sig_req(plci, REMOVE, 0);
  4164. send_req(plci);
  4165. }
  4166. break;
  4167. /* Call Deflection Request pending, just no appl ptr assigned */
  4168. case CD_REQ_PEND:
  4169. SSparms[1] = S_CALL_DEFLECTION;
  4170. if (rc != OK)
  4171. {
  4172. Info = 0x300E; /* not supported */
  4173. }
  4174. for (i = 0; i < max_appl; i++)
  4175. {
  4176. if (application[i].CDEnable)
  4177. {
  4178. if (!application[i].Id) application[i].CDEnable = 0;
  4179. else
  4180. {
  4181. sendf(&application[i], _FACILITY_R | CONFIRM, Id,
  4182. plci->number, "wws", Info, (word)3, SSparms);
  4183. if (Info) application[i].CDEnable = 0;
  4184. }
  4185. }
  4186. }
  4187. plci->internal_command = 0;
  4188. break;
  4189. case PERM_COD_HOOK: /* finished with Hook_Ind */
  4190. return;
  4191. case PERM_COD_CALL:
  4192. plci->internal_command = PERM_COD_CONN_PEND;
  4193. dbug(1, dprintf("***Codec Connect_Pending, Rc = 0x%x", rc));
  4194. return;
  4195. case PERM_COD_ASSIGN:
  4196. dbug(1, dprintf("***Codec Assign, Rc = 0x%x", rc));
  4197. plci->internal_command = 0;
  4198. if (rc != ASSIGN_OK) break;
  4199. plci->internal_command = PERM_COD_CALL;
  4200. sig_req(plci, CALL_REQ, 0);
  4201. send_req(plci);
  4202. return;
  4203. case LISTEN_SIG_ASSIGN_PEND:
  4204. if (rc == ASSIGN_OK)
  4205. {
  4206. plci->internal_command = 0;
  4207. dbug(1, dprintf("ListenCheck, new SIG_ID = 0x%x", plci->Sig.Id));
  4208. add_p(plci, ESC, "\x02\x18\x00"); /* support call waiting */
  4209. sig_req(plci, INDICATE_REQ, 0);
  4210. send_req(plci);
  4211. }
  4212. else
  4213. {
  4214. dbug(1, dprintf("ListenCheck failed (assignRc=0x%x)", rc));
  4215. a->listen_active--;
  4216. plci_remove(plci);
  4217. plci->State = IDLE;
  4218. }
  4219. break;
  4220. case USELAW_REQ:
  4221. if (global_req == ASSIGN)
  4222. {
  4223. if (rc == ASSIGN_OK)
  4224. {
  4225. sig_req(plci, LAW_REQ, 0);
  4226. send_req(plci);
  4227. dbug(1, dprintf("Auto-Law assigned"));
  4228. }
  4229. else
  4230. {
  4231. dbug(1, dprintf("Auto-Law assign failed"));
  4232. a->automatic_law = 3;
  4233. plci->internal_command = 0;
  4234. a->automatic_lawPLCI = NULL;
  4235. }
  4236. break;
  4237. }
  4238. else if (req == LAW_REQ && rc == OK)
  4239. {
  4240. dbug(1, dprintf("Auto-Law initiated"));
  4241. a->automatic_law = 2;
  4242. plci->internal_command = 0;
  4243. }
  4244. else
  4245. {
  4246. dbug(1, dprintf("Auto-Law not supported"));
  4247. a->automatic_law = 3;
  4248. plci->internal_command = 0;
  4249. sig_req(plci, REMOVE, 0);
  4250. send_req(plci);
  4251. a->automatic_lawPLCI = NULL;
  4252. }
  4253. break;
  4254. }
  4255. plci_remove_check(plci);
  4256. }
  4257. }
  4258. static void data_rc(PLCI *plci, byte ch)
  4259. {
  4260. dword Id;
  4261. DIVA_CAPI_ADAPTER *a;
  4262. NCCI *ncci_ptr;
  4263. DATA_B3_DESC *data;
  4264. word ncci;
  4265. if (plci->appl)
  4266. {
  4267. TransmitBufferFree(plci->appl, plci->data_sent_ptr);
  4268. a = plci->adapter;
  4269. ncci = a->ch_ncci[ch];
  4270. if (ncci && (a->ncci_plci[ncci] == plci->Id))
  4271. {
  4272. ncci_ptr = &(a->ncci[ncci]);
  4273. dbug(1, dprintf("data_out=%d, data_pending=%d", ncci_ptr->data_out, ncci_ptr->data_pending));
  4274. if (ncci_ptr->data_pending)
  4275. {
  4276. data = &(ncci_ptr->DBuffer[ncci_ptr->data_out]);
  4277. if (!(data->Flags & 4) && a->ncci_state[ncci])
  4278. {
  4279. Id = (((dword)ncci) << 16) | ((word)plci->Id << 8) | a->Id;
  4280. if (plci->tel) Id |= EXT_CONTROLLER;
  4281. sendf(plci->appl, _DATA_B3_R | CONFIRM, Id, data->Number,
  4282. "ww", data->Handle, 0);
  4283. }
  4284. (ncci_ptr->data_out)++;
  4285. if (ncci_ptr->data_out == MAX_DATA_B3)
  4286. ncci_ptr->data_out = 0;
  4287. (ncci_ptr->data_pending)--;
  4288. }
  4289. }
  4290. }
  4291. }
  4292. static void data_ack(PLCI *plci, byte ch)
  4293. {
  4294. dword Id;
  4295. DIVA_CAPI_ADAPTER *a;
  4296. NCCI *ncci_ptr;
  4297. word ncci;
  4298. a = plci->adapter;
  4299. ncci = a->ch_ncci[ch];
  4300. ncci_ptr = &(a->ncci[ncci]);
  4301. if (ncci_ptr->data_ack_pending)
  4302. {
  4303. if (a->ncci_state[ncci] && (a->ncci_plci[ncci] == plci->Id))
  4304. {
  4305. Id = (((dword)ncci) << 16) | ((word)plci->Id << 8) | a->Id;
  4306. if (plci->tel) Id |= EXT_CONTROLLER;
  4307. sendf(plci->appl, _DATA_B3_R | CONFIRM, Id, ncci_ptr->DataAck[ncci_ptr->data_ack_out].Number,
  4308. "ww", ncci_ptr->DataAck[ncci_ptr->data_ack_out].Handle, 0);
  4309. }
  4310. (ncci_ptr->data_ack_out)++;
  4311. if (ncci_ptr->data_ack_out == MAX_DATA_ACK)
  4312. ncci_ptr->data_ack_out = 0;
  4313. (ncci_ptr->data_ack_pending)--;
  4314. }
  4315. }
  4316. static void sig_ind(PLCI *plci)
  4317. {
  4318. dword x_Id;
  4319. dword Id;
  4320. dword rId;
  4321. word i;
  4322. word cip;
  4323. dword cip_mask;
  4324. byte *ie;
  4325. DIVA_CAPI_ADAPTER *a;
  4326. API_PARSE saved_parms[MAX_MSG_PARMS + 1];
  4327. #define MAXPARMSIDS 31
  4328. byte *parms[MAXPARMSIDS];
  4329. byte *add_i[4];
  4330. byte *multi_fac_parms[MAX_MULTI_IE];
  4331. byte *multi_pi_parms[MAX_MULTI_IE];
  4332. byte *multi_ssext_parms[MAX_MULTI_IE];
  4333. byte *multi_CiPN_parms[MAX_MULTI_IE];
  4334. byte *multi_vswitch_parms[MAX_MULTI_IE];
  4335. byte ai_len;
  4336. byte *esc_chi = "";
  4337. byte *esc_law = "";
  4338. byte *pty_cai = "";
  4339. byte *esc_cr = "";
  4340. byte *esc_profile = "";
  4341. byte facility[256];
  4342. PLCI *tplci = NULL;
  4343. byte chi[] = "\x02\x18\x01";
  4344. byte voice_cai[] = "\x06\x14\x00\x00\x00\x00\x08";
  4345. byte resume_cau[] = "\x05\x05\x00\x02\x00\x00";
  4346. /* ESC_MSGTYPE must be the last but one message, a new IE has to be */
  4347. /* included before the ESC_MSGTYPE and MAXPARMSIDS has to be incremented */
  4348. /* SMSG is situated at the end because its 0 (for compatibility reasons */
  4349. /* (see Info_Mask Bit 4, first IE. then the message type) */
  4350. static const word parms_id[] =
  4351. {MAXPARMSIDS, CPN, 0xff, DSA, OSA, BC, LLC, HLC, ESC_CAUSE, DSP, DT, CHA,
  4352. UUI, CONG_RR, CONG_RNR, ESC_CHI, KEY, CHI, CAU, ESC_LAW,
  4353. RDN, RDX, CONN_NR, RIN, NI, CAI, ESC_CR,
  4354. CST, ESC_PROFILE, 0xff, ESC_MSGTYPE, SMSG};
  4355. /* 14 FTY repl by ESC_CHI */
  4356. /* 18 PI repl by ESC_LAW */
  4357. /* removed OAD changed to 0xff for future use, OAD is multiIE now */
  4358. static const word multi_fac_id[] = {1, FTY};
  4359. static const word multi_pi_id[] = {1, PI};
  4360. static const word multi_CiPN_id[] = {1, OAD};
  4361. static const word multi_ssext_id[] = {1, ESC_SSEXT};
  4362. static const word multi_vswitch_id[] = {1, ESC_VSWITCH};
  4363. byte *cau;
  4364. word ncci;
  4365. byte SS_Ind[] = "\x05\x02\x00\x02\x00\x00"; /* Hold_Ind struct*/
  4366. byte CF_Ind[] = "\x09\x02\x00\x06\x00\x00\x00\x00\x00\x00";
  4367. byte Interr_Err_Ind[] = "\x0a\x02\x00\x07\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00";
  4368. byte CONF_Ind[] = "\x09\x16\x00\x06\x00\x00\x00\x00\x00\x00";
  4369. byte force_mt_info = false;
  4370. byte dir;
  4371. dword d;
  4372. word w;
  4373. a = plci->adapter;
  4374. Id = ((word)plci->Id << 8) | a->Id;
  4375. PUT_WORD(&SS_Ind[4], 0x0000);
  4376. if (plci->sig_remove_id)
  4377. {
  4378. plci->Sig.RNR = 2; /* discard */
  4379. dbug(1, dprintf("SIG discard while remove pending"));
  4380. return;
  4381. }
  4382. if (plci->tel && plci->SuppState != CALL_HELD) Id |= EXT_CONTROLLER;
  4383. dbug(1, dprintf("SigInd-Id=%08lx,plci=%x,tel=%x,state=0x%x,channels=%d,Discflowcl=%d",
  4384. Id, plci->Id, plci->tel, plci->State, plci->channels, plci->hangup_flow_ctrl_timer));
  4385. if (plci->Sig.Ind == CALL_HOLD_ACK && plci->channels)
  4386. {
  4387. plci->Sig.RNR = 1;
  4388. return;
  4389. }
  4390. if (plci->Sig.Ind == HANGUP && plci->channels)
  4391. {
  4392. plci->Sig.RNR = 1;
  4393. plci->hangup_flow_ctrl_timer++;
  4394. /* recover the network layer after timeout */
  4395. if (plci->hangup_flow_ctrl_timer == 100)
  4396. {
  4397. dbug(1, dprintf("Exceptional disc"));
  4398. plci->Sig.RNR = 0;
  4399. plci->hangup_flow_ctrl_timer = 0;
  4400. for (ncci = 1; ncci < MAX_NCCI + 1; ncci++)
  4401. {
  4402. if (a->ncci_plci[ncci] == plci->Id)
  4403. {
  4404. cleanup_ncci_data(plci, ncci);
  4405. if (plci->channels)plci->channels--;
  4406. if (plci->appl)
  4407. sendf(plci->appl, _DISCONNECT_B3_I, (((dword) ncci) << 16) | Id, 0, "ws", 0, "");
  4408. }
  4409. }
  4410. if (plci->appl)
  4411. sendf(plci->appl, _DISCONNECT_I, Id, 0, "w", 0);
  4412. plci_remove(plci);
  4413. plci->State = IDLE;
  4414. }
  4415. return;
  4416. }
  4417. /* do first parse the info with no OAD in, because OAD will be converted */
  4418. /* first the multiple facility IE, then mult. progress ind. */
  4419. /* then the parameters for the info_ind + conn_ind */
  4420. IndParse(plci, multi_fac_id, multi_fac_parms, MAX_MULTI_IE);
  4421. IndParse(plci, multi_pi_id, multi_pi_parms, MAX_MULTI_IE);
  4422. IndParse(plci, multi_ssext_id, multi_ssext_parms, MAX_MULTI_IE);
  4423. IndParse(plci, multi_vswitch_id, multi_vswitch_parms, MAX_MULTI_IE);
  4424. IndParse(plci, parms_id, parms, 0);
  4425. IndParse(plci, multi_CiPN_id, multi_CiPN_parms, MAX_MULTI_IE);
  4426. esc_chi = parms[14];
  4427. esc_law = parms[18];
  4428. pty_cai = parms[24];
  4429. esc_cr = parms[25];
  4430. esc_profile = parms[27];
  4431. if (esc_cr[0] && plci)
  4432. {
  4433. if (plci->cr_enquiry && plci->appl)
  4434. {
  4435. plci->cr_enquiry = false;
  4436. /* d = MANU_ID */
  4437. /* w = m_command */
  4438. /* b = total length */
  4439. /* b = indication type */
  4440. /* b = length of all IEs */
  4441. /* b = IE1 */
  4442. /* S = IE1 length + cont. */
  4443. /* b = IE2 */
  4444. /* S = IE2 length + cont. */
  4445. sendf(plci->appl,
  4446. _MANUFACTURER_I,
  4447. Id,
  4448. 0,
  4449. "dwbbbbSbS", _DI_MANU_ID, plci->m_command,
  4450. 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);
  4451. }
  4452. }
  4453. /* create the additional info structure */
  4454. add_i[1] = parms[15]; /* KEY of additional info */
  4455. add_i[2] = parms[11]; /* UUI of additional info */
  4456. ai_len = AddInfo(add_i, multi_fac_parms, esc_chi, facility);
  4457. /* the ESC_LAW indicates if u-Law or a-Law is actually used by the card */
  4458. /* indication returns by the card if requested by the function */
  4459. /* AutomaticLaw() after driver init */
  4460. if (a->automatic_law < 4)
  4461. {
  4462. if (esc_law[0]) {
  4463. if (esc_law[2]) {
  4464. dbug(0, dprintf("u-Law selected"));
  4465. a->u_law = 1;
  4466. }
  4467. else {
  4468. dbug(0, dprintf("a-Law selected"));
  4469. a->u_law = 0;
  4470. }
  4471. a->automatic_law = 4;
  4472. if (plci == a->automatic_lawPLCI) {
  4473. plci->internal_command = 0;
  4474. sig_req(plci, REMOVE, 0);
  4475. send_req(plci);
  4476. a->automatic_lawPLCI = NULL;
  4477. }
  4478. }
  4479. if (esc_profile[0])
  4480. {
  4481. dbug(1, dprintf("[%06x] CardProfile: %lx %lx %lx %lx %lx",
  4482. UnMapController(a->Id), GET_DWORD(&esc_profile[6]),
  4483. GET_DWORD(&esc_profile[10]), GET_DWORD(&esc_profile[14]),
  4484. GET_DWORD(&esc_profile[18]), GET_DWORD(&esc_profile[46])));
  4485. a->profile.Global_Options &= 0x000000ffL;
  4486. a->profile.B1_Protocols &= 0x000003ffL;
  4487. a->profile.B2_Protocols &= 0x00001fdfL;
  4488. a->profile.B3_Protocols &= 0x000000b7L;
  4489. a->profile.Global_Options &= GET_DWORD(&esc_profile[6]) |
  4490. GL_BCHANNEL_OPERATION_SUPPORTED;
  4491. a->profile.B1_Protocols &= GET_DWORD(&esc_profile[10]);
  4492. a->profile.B2_Protocols &= GET_DWORD(&esc_profile[14]);
  4493. a->profile.B3_Protocols &= GET_DWORD(&esc_profile[18]);
  4494. a->manufacturer_features = GET_DWORD(&esc_profile[46]);
  4495. a->man_profile.private_options = 0;
  4496. if (a->manufacturer_features & MANUFACTURER_FEATURE_ECHO_CANCELLER)
  4497. {
  4498. a->man_profile.private_options |= 1L << PRIVATE_ECHO_CANCELLER;
  4499. a->profile.Global_Options |= GL_ECHO_CANCELLER_SUPPORTED;
  4500. }
  4501. if (a->manufacturer_features & MANUFACTURER_FEATURE_RTP)
  4502. a->man_profile.private_options |= 1L << PRIVATE_RTP;
  4503. a->man_profile.rtp_primary_payloads = GET_DWORD(&esc_profile[50]);
  4504. a->man_profile.rtp_additional_payloads = GET_DWORD(&esc_profile[54]);
  4505. if (a->manufacturer_features & MANUFACTURER_FEATURE_T38)
  4506. a->man_profile.private_options |= 1L << PRIVATE_T38;
  4507. if (a->manufacturer_features & MANUFACTURER_FEATURE_FAX_SUB_SEP_PWD)
  4508. a->man_profile.private_options |= 1L << PRIVATE_FAX_SUB_SEP_PWD;
  4509. if (a->manufacturer_features & MANUFACTURER_FEATURE_V18)
  4510. a->man_profile.private_options |= 1L << PRIVATE_V18;
  4511. if (a->manufacturer_features & MANUFACTURER_FEATURE_DTMF_TONE)
  4512. a->man_profile.private_options |= 1L << PRIVATE_DTMF_TONE;
  4513. if (a->manufacturer_features & MANUFACTURER_FEATURE_PIAFS)
  4514. a->man_profile.private_options |= 1L << PRIVATE_PIAFS;
  4515. if (a->manufacturer_features & MANUFACTURER_FEATURE_FAX_PAPER_FORMATS)
  4516. a->man_profile.private_options |= 1L << PRIVATE_FAX_PAPER_FORMATS;
  4517. if (a->manufacturer_features & MANUFACTURER_FEATURE_VOWN)
  4518. a->man_profile.private_options |= 1L << PRIVATE_VOWN;
  4519. if (a->manufacturer_features & MANUFACTURER_FEATURE_FAX_NONSTANDARD)
  4520. a->man_profile.private_options |= 1L << PRIVATE_FAX_NONSTANDARD;
  4521. }
  4522. else
  4523. {
  4524. a->profile.Global_Options &= 0x0000007fL;
  4525. a->profile.B1_Protocols &= 0x000003dfL;
  4526. a->profile.B2_Protocols &= 0x00001adfL;
  4527. a->profile.B3_Protocols &= 0x000000b7L;
  4528. a->manufacturer_features &= MANUFACTURER_FEATURE_HARDDTMF;
  4529. }
  4530. if (a->manufacturer_features & (MANUFACTURER_FEATURE_HARDDTMF |
  4531. MANUFACTURER_FEATURE_SOFTDTMF_SEND | MANUFACTURER_FEATURE_SOFTDTMF_RECEIVE))
  4532. {
  4533. a->profile.Global_Options |= GL_DTMF_SUPPORTED;
  4534. }
  4535. a->manufacturer_features &= ~MANUFACTURER_FEATURE_OOB_CHANNEL;
  4536. dbug(1, dprintf("[%06x] Profile: %lx %lx %lx %lx %lx",
  4537. UnMapController(a->Id), a->profile.Global_Options,
  4538. a->profile.B1_Protocols, a->profile.B2_Protocols,
  4539. a->profile.B3_Protocols, a->manufacturer_features));
  4540. }
  4541. /* codec plci for the handset/hook state support is just an internal id */
  4542. if (plci != a->AdvCodecPLCI)
  4543. {
  4544. force_mt_info = SendMultiIE(plci, Id, multi_fac_parms, FTY, 0x20, 0);
  4545. force_mt_info |= SendMultiIE(plci, Id, multi_pi_parms, PI, 0x210, 0);
  4546. SendSSExtInd(NULL, plci, Id, multi_ssext_parms);
  4547. SendInfo(plci, Id, parms, force_mt_info);
  4548. VSwitchReqInd(plci, Id, multi_vswitch_parms);
  4549. }
  4550. /* switch the codec to the b-channel */
  4551. if (esc_chi[0] && plci && !plci->SuppState) {
  4552. plci->b_channel = esc_chi[esc_chi[0]]&0x1f;
  4553. mixer_set_bchannel_id_esc(plci, plci->b_channel);
  4554. dbug(1, dprintf("storeChannel=0x%x", plci->b_channel));
  4555. if (plci->tel == ADV_VOICE && plci->appl) {
  4556. SetVoiceChannel(a->AdvCodecPLCI, esc_chi, a);
  4557. }
  4558. }
  4559. if (plci->appl) plci->appl->Number++;
  4560. switch (plci->Sig.Ind) {
  4561. /* Response to Get_Supported_Services request */
  4562. case S_SUPPORTED:
  4563. dbug(1, dprintf("S_Supported"));
  4564. if (!plci->appl) break;
  4565. if (pty_cai[0] == 4)
  4566. {
  4567. PUT_DWORD(&CF_Ind[6], GET_DWORD(&pty_cai[1]));
  4568. }
  4569. else
  4570. {
  4571. PUT_DWORD(&CF_Ind[6], MASK_TERMINAL_PORTABILITY | MASK_HOLD_RETRIEVE);
  4572. }
  4573. PUT_WORD(&CF_Ind[1], 0);
  4574. PUT_WORD(&CF_Ind[4], 0);
  4575. sendf(plci->appl, _FACILITY_R | CONFIRM, Id & 0x7, plci->number, "wws", 0, 3, CF_Ind);
  4576. plci_remove(plci);
  4577. break;
  4578. /* Supplementary Service rejected */
  4579. case S_SERVICE_REJ:
  4580. dbug(1, dprintf("S_Reject=0x%x", pty_cai[5]));
  4581. if (!pty_cai[0]) break;
  4582. switch (pty_cai[5])
  4583. {
  4584. case ECT_EXECUTE:
  4585. case THREE_PTY_END:
  4586. case THREE_PTY_BEGIN:
  4587. if (!plci->relatedPTYPLCI) break;
  4588. tplci = plci->relatedPTYPLCI;
  4589. rId = ((word)tplci->Id << 8) | tplci->adapter->Id;
  4590. if (tplci->tel) rId |= EXT_CONTROLLER;
  4591. if (pty_cai[5] == ECT_EXECUTE)
  4592. {
  4593. PUT_WORD(&SS_Ind[1], S_ECT);
  4594. plci->vswitchstate = 0;
  4595. plci->relatedPTYPLCI->vswitchstate = 0;
  4596. }
  4597. else
  4598. {
  4599. PUT_WORD(&SS_Ind[1], pty_cai[5] + 3);
  4600. }
  4601. if (pty_cai[2] != 0xff)
  4602. {
  4603. PUT_WORD(&SS_Ind[4], 0x3600 | (word)pty_cai[2]);
  4604. }
  4605. else
  4606. {
  4607. PUT_WORD(&SS_Ind[4], 0x300E);
  4608. }
  4609. plci->relatedPTYPLCI = NULL;
  4610. plci->ptyState = 0;
  4611. sendf(tplci->appl, _FACILITY_I, rId, 0, "ws", 3, SS_Ind);
  4612. break;
  4613. case CALL_DEFLECTION:
  4614. if (pty_cai[2] != 0xff)
  4615. {
  4616. PUT_WORD(&SS_Ind[4], 0x3600 | (word)pty_cai[2]);
  4617. }
  4618. else
  4619. {
  4620. PUT_WORD(&SS_Ind[4], 0x300E);
  4621. }
  4622. PUT_WORD(&SS_Ind[1], pty_cai[5]);
  4623. for (i = 0; i < max_appl; i++)
  4624. {
  4625. if (application[i].CDEnable)
  4626. {
  4627. if (application[i].Id) sendf(&application[i], _FACILITY_I, Id, 0, "ws", 3, SS_Ind);
  4628. application[i].CDEnable = false;
  4629. }
  4630. }
  4631. break;
  4632. case DEACTIVATION_DIVERSION:
  4633. case ACTIVATION_DIVERSION:
  4634. case DIVERSION_INTERROGATE_CFU:
  4635. case DIVERSION_INTERROGATE_CFB:
  4636. case DIVERSION_INTERROGATE_CFNR:
  4637. case DIVERSION_INTERROGATE_NUM:
  4638. case CCBS_REQUEST:
  4639. case CCBS_DEACTIVATE:
  4640. case CCBS_INTERROGATE:
  4641. if (!plci->appl) break;
  4642. if (pty_cai[2] != 0xff)
  4643. {
  4644. PUT_WORD(&Interr_Err_Ind[4], 0x3600 | (word)pty_cai[2]);
  4645. }
  4646. else
  4647. {
  4648. PUT_WORD(&Interr_Err_Ind[4], 0x300E);
  4649. }
  4650. switch (pty_cai[5])
  4651. {
  4652. case DEACTIVATION_DIVERSION:
  4653. dbug(1, dprintf("Deact_Div"));
  4654. Interr_Err_Ind[0] = 0x9;
  4655. Interr_Err_Ind[3] = 0x6;
  4656. PUT_WORD(&Interr_Err_Ind[1], S_CALL_FORWARDING_STOP);
  4657. break;
  4658. case ACTIVATION_DIVERSION:
  4659. dbug(1, dprintf("Act_Div"));
  4660. Interr_Err_Ind[0] = 0x9;
  4661. Interr_Err_Ind[3] = 0x6;
  4662. PUT_WORD(&Interr_Err_Ind[1], S_CALL_FORWARDING_START);
  4663. break;
  4664. case DIVERSION_INTERROGATE_CFU:
  4665. case DIVERSION_INTERROGATE_CFB:
  4666. case DIVERSION_INTERROGATE_CFNR:
  4667. dbug(1, dprintf("Interr_Div"));
  4668. Interr_Err_Ind[0] = 0xa;
  4669. Interr_Err_Ind[3] = 0x7;
  4670. PUT_WORD(&Interr_Err_Ind[1], S_INTERROGATE_DIVERSION);
  4671. break;
  4672. case DIVERSION_INTERROGATE_NUM:
  4673. dbug(1, dprintf("Interr_Num"));
  4674. Interr_Err_Ind[0] = 0xa;
  4675. Interr_Err_Ind[3] = 0x7;
  4676. PUT_WORD(&Interr_Err_Ind[1], S_INTERROGATE_NUMBERS);
  4677. break;
  4678. case CCBS_REQUEST:
  4679. dbug(1, dprintf("CCBS Request"));
  4680. Interr_Err_Ind[0] = 0xd;
  4681. Interr_Err_Ind[3] = 0xa;
  4682. PUT_WORD(&Interr_Err_Ind[1], S_CCBS_REQUEST);
  4683. break;
  4684. case CCBS_DEACTIVATE:
  4685. dbug(1, dprintf("CCBS Deactivate"));
  4686. Interr_Err_Ind[0] = 0x9;
  4687. Interr_Err_Ind[3] = 0x6;
  4688. PUT_WORD(&Interr_Err_Ind[1], S_CCBS_DEACTIVATE);
  4689. break;
  4690. case CCBS_INTERROGATE:
  4691. dbug(1, dprintf("CCBS Interrogate"));
  4692. Interr_Err_Ind[0] = 0xb;
  4693. Interr_Err_Ind[3] = 0x8;
  4694. PUT_WORD(&Interr_Err_Ind[1], S_CCBS_INTERROGATE);
  4695. break;
  4696. }
  4697. PUT_DWORD(&Interr_Err_Ind[6], plci->appl->S_Handle);
  4698. sendf(plci->appl, _FACILITY_I, Id & 0x7, 0, "ws", 3, Interr_Err_Ind);
  4699. plci_remove(plci);
  4700. break;
  4701. case ACTIVATION_MWI:
  4702. case DEACTIVATION_MWI:
  4703. if (pty_cai[5] == ACTIVATION_MWI)
  4704. {
  4705. PUT_WORD(&SS_Ind[1], S_MWI_ACTIVATE);
  4706. }
  4707. else PUT_WORD(&SS_Ind[1], S_MWI_DEACTIVATE);
  4708. if (pty_cai[2] != 0xff)
  4709. {
  4710. PUT_WORD(&SS_Ind[4], 0x3600 | (word)pty_cai[2]);
  4711. }
  4712. else
  4713. {
  4714. PUT_WORD(&SS_Ind[4], 0x300E);
  4715. }
  4716. if (plci->cr_enquiry)
  4717. {
  4718. sendf(plci->appl, _FACILITY_I, Id & 0xf, 0, "ws", 3, SS_Ind);
  4719. plci_remove(plci);
  4720. }
  4721. else
  4722. {
  4723. sendf(plci->appl, _FACILITY_I, Id, 0, "ws", 3, SS_Ind);
  4724. }
  4725. break;
  4726. case CONF_ADD: /* ERROR */
  4727. case CONF_BEGIN:
  4728. case CONF_DROP:
  4729. case CONF_ISOLATE:
  4730. case CONF_REATTACH:
  4731. CONF_Ind[0] = 9;
  4732. CONF_Ind[3] = 6;
  4733. switch (pty_cai[5])
  4734. {
  4735. case CONF_BEGIN:
  4736. PUT_WORD(&CONF_Ind[1], S_CONF_BEGIN);
  4737. plci->ptyState = 0;
  4738. break;
  4739. case CONF_DROP:
  4740. CONF_Ind[0] = 5;
  4741. CONF_Ind[3] = 2;
  4742. PUT_WORD(&CONF_Ind[1], S_CONF_DROP);
  4743. plci->ptyState = CONNECTED;
  4744. break;
  4745. case CONF_ISOLATE:
  4746. CONF_Ind[0] = 5;
  4747. CONF_Ind[3] = 2;
  4748. PUT_WORD(&CONF_Ind[1], S_CONF_ISOLATE);
  4749. plci->ptyState = CONNECTED;
  4750. break;
  4751. case CONF_REATTACH:
  4752. CONF_Ind[0] = 5;
  4753. CONF_Ind[3] = 2;
  4754. PUT_WORD(&CONF_Ind[1], S_CONF_REATTACH);
  4755. plci->ptyState = CONNECTED;
  4756. break;
  4757. case CONF_ADD:
  4758. PUT_WORD(&CONF_Ind[1], S_CONF_ADD);
  4759. plci->relatedPTYPLCI = NULL;
  4760. tplci = plci->relatedPTYPLCI;
  4761. if (tplci) tplci->ptyState = CONNECTED;
  4762. plci->ptyState = CONNECTED;
  4763. break;
  4764. }
  4765. if (pty_cai[2] != 0xff)
  4766. {
  4767. PUT_WORD(&CONF_Ind[4], 0x3600 | (word)pty_cai[2]);
  4768. }
  4769. else
  4770. {
  4771. PUT_WORD(&CONF_Ind[4], 0x3303); /* Time-out: network did not respond
  4772. within the required time */
  4773. }
  4774. PUT_DWORD(&CONF_Ind[6], 0x0);
  4775. sendf(plci->appl, _FACILITY_I, Id, 0, "ws", 3, CONF_Ind);
  4776. break;
  4777. }
  4778. break;
  4779. /* Supplementary Service indicates success */
  4780. case S_SERVICE:
  4781. dbug(1, dprintf("Service_Ind"));
  4782. PUT_WORD(&CF_Ind[4], 0);
  4783. switch (pty_cai[5])
  4784. {
  4785. case THREE_PTY_END:
  4786. case THREE_PTY_BEGIN:
  4787. case ECT_EXECUTE:
  4788. if (!plci->relatedPTYPLCI) break;
  4789. tplci = plci->relatedPTYPLCI;
  4790. rId = ((word)tplci->Id << 8) | tplci->adapter->Id;
  4791. if (tplci->tel) rId |= EXT_CONTROLLER;
  4792. if (pty_cai[5] == ECT_EXECUTE)
  4793. {
  4794. PUT_WORD(&SS_Ind[1], S_ECT);
  4795. if (plci->vswitchstate != 3)
  4796. {
  4797. plci->ptyState = IDLE;
  4798. plci->relatedPTYPLCI = NULL;
  4799. plci->ptyState = 0;
  4800. }
  4801. dbug(1, dprintf("ECT OK"));
  4802. sendf(tplci->appl, _FACILITY_I, rId, 0, "ws", 3, SS_Ind);
  4803. }
  4804. else
  4805. {
  4806. switch (plci->ptyState)
  4807. {
  4808. case S_3PTY_BEGIN:
  4809. plci->ptyState = CONNECTED;
  4810. dbug(1, dprintf("3PTY ON"));
  4811. break;
  4812. case S_3PTY_END:
  4813. plci->ptyState = IDLE;
  4814. plci->relatedPTYPLCI = NULL;
  4815. plci->ptyState = 0;
  4816. dbug(1, dprintf("3PTY OFF"));
  4817. break;
  4818. }
  4819. PUT_WORD(&SS_Ind[1], pty_cai[5] + 3);
  4820. sendf(tplci->appl, _FACILITY_I, rId, 0, "ws", 3, SS_Ind);
  4821. }
  4822. break;
  4823. case CALL_DEFLECTION:
  4824. PUT_WORD(&SS_Ind[1], pty_cai[5]);
  4825. for (i = 0; i < max_appl; i++)
  4826. {
  4827. if (application[i].CDEnable)
  4828. {
  4829. if (application[i].Id) sendf(&application[i], _FACILITY_I, Id, 0, "ws", 3, SS_Ind);
  4830. application[i].CDEnable = false;
  4831. }
  4832. }
  4833. break;
  4834. case DEACTIVATION_DIVERSION:
  4835. case ACTIVATION_DIVERSION:
  4836. if (!plci->appl) break;
  4837. PUT_WORD(&CF_Ind[1], pty_cai[5] + 2);
  4838. PUT_DWORD(&CF_Ind[6], plci->appl->S_Handle);
  4839. sendf(plci->appl, _FACILITY_I, Id & 0x7, 0, "ws", 3, CF_Ind);
  4840. plci_remove(plci);
  4841. break;
  4842. case DIVERSION_INTERROGATE_CFU:
  4843. case DIVERSION_INTERROGATE_CFB:
  4844. case DIVERSION_INTERROGATE_CFNR:
  4845. case DIVERSION_INTERROGATE_NUM:
  4846. case CCBS_REQUEST:
  4847. case CCBS_DEACTIVATE:
  4848. case CCBS_INTERROGATE:
  4849. if (!plci->appl) break;
  4850. switch (pty_cai[5])
  4851. {
  4852. case DIVERSION_INTERROGATE_CFU:
  4853. case DIVERSION_INTERROGATE_CFB:
  4854. case DIVERSION_INTERROGATE_CFNR:
  4855. dbug(1, dprintf("Interr_Div"));
  4856. PUT_WORD(&pty_cai[1], S_INTERROGATE_DIVERSION);
  4857. pty_cai[3] = pty_cai[0] - 3; /* Supplementary Service-specific parameter len */
  4858. break;
  4859. case DIVERSION_INTERROGATE_NUM:
  4860. dbug(1, dprintf("Interr_Num"));
  4861. PUT_WORD(&pty_cai[1], S_INTERROGATE_NUMBERS);
  4862. pty_cai[3] = pty_cai[0] - 3; /* Supplementary Service-specific parameter len */
  4863. break;
  4864. case CCBS_REQUEST:
  4865. dbug(1, dprintf("CCBS Request"));
  4866. PUT_WORD(&pty_cai[1], S_CCBS_REQUEST);
  4867. pty_cai[3] = pty_cai[0] - 3; /* Supplementary Service-specific parameter len */
  4868. break;
  4869. case CCBS_DEACTIVATE:
  4870. dbug(1, dprintf("CCBS Deactivate"));
  4871. PUT_WORD(&pty_cai[1], S_CCBS_DEACTIVATE);
  4872. pty_cai[3] = pty_cai[0] - 3; /* Supplementary Service-specific parameter len */
  4873. break;
  4874. case CCBS_INTERROGATE:
  4875. dbug(1, dprintf("CCBS Interrogate"));
  4876. PUT_WORD(&pty_cai[1], S_CCBS_INTERROGATE);
  4877. pty_cai[3] = pty_cai[0] - 3; /* Supplementary Service-specific parameter len */
  4878. break;
  4879. }
  4880. PUT_WORD(&pty_cai[4], 0); /* Supplementary Service Reason */
  4881. PUT_DWORD(&pty_cai[6], plci->appl->S_Handle);
  4882. sendf(plci->appl, _FACILITY_I, Id & 0x7, 0, "wS", 3, pty_cai);
  4883. plci_remove(plci);
  4884. break;
  4885. case ACTIVATION_MWI:
  4886. case DEACTIVATION_MWI:
  4887. if (pty_cai[5] == ACTIVATION_MWI)
  4888. {
  4889. PUT_WORD(&SS_Ind[1], S_MWI_ACTIVATE);
  4890. }
  4891. else PUT_WORD(&SS_Ind[1], S_MWI_DEACTIVATE);
  4892. if (plci->cr_enquiry)
  4893. {
  4894. sendf(plci->appl, _FACILITY_I, Id & 0xf, 0, "ws", 3, SS_Ind);
  4895. plci_remove(plci);
  4896. }
  4897. else
  4898. {
  4899. sendf(plci->appl, _FACILITY_I, Id, 0, "ws", 3, SS_Ind);
  4900. }
  4901. break;
  4902. case MWI_INDICATION:
  4903. if (pty_cai[0] >= 0x12)
  4904. {
  4905. PUT_WORD(&pty_cai[3], S_MWI_INDICATE);
  4906. pty_cai[2] = pty_cai[0] - 2; /* len Parameter */
  4907. pty_cai[5] = pty_cai[0] - 5; /* Supplementary Service-specific parameter len */
  4908. if (plci->appl && (a->Notification_Mask[plci->appl->Id - 1] & SMASK_MWI))
  4909. {
  4910. if (plci->internal_command == GET_MWI_STATE) /* result on Message Waiting Listen */
  4911. {
  4912. sendf(plci->appl, _FACILITY_I, Id & 0xf, 0, "wS", 3, &pty_cai[2]);
  4913. plci_remove(plci);
  4914. return;
  4915. }
  4916. else sendf(plci->appl, _FACILITY_I, Id, 0, "wS", 3, &pty_cai[2]);
  4917. pty_cai[0] = 0;
  4918. }
  4919. else
  4920. {
  4921. for (i = 0; i < max_appl; i++)
  4922. {
  4923. if (a->Notification_Mask[i]&SMASK_MWI)
  4924. {
  4925. sendf(&application[i], _FACILITY_I, Id & 0x7, 0, "wS", 3, &pty_cai[2]);
  4926. pty_cai[0] = 0;
  4927. }
  4928. }
  4929. }
  4930. if (!pty_cai[0])
  4931. { /* acknowledge */
  4932. facility[2] = 0; /* returncode */
  4933. }
  4934. else facility[2] = 0xff;
  4935. }
  4936. else
  4937. {
  4938. /* reject */
  4939. facility[2] = 0xff; /* returncode */
  4940. }
  4941. facility[0] = 2;
  4942. facility[1] = MWI_RESPONSE; /* Function */
  4943. add_p(plci, CAI, facility);
  4944. add_p(plci, ESC, multi_ssext_parms[0]); /* remembered parameter -> only one possible */
  4945. sig_req(plci, S_SERVICE, 0);
  4946. send_req(plci);
  4947. plci->command = 0;
  4948. next_internal_command(Id, plci);
  4949. break;
  4950. case CONF_ADD: /* OK */
  4951. case CONF_BEGIN:
  4952. case CONF_DROP:
  4953. case CONF_ISOLATE:
  4954. case CONF_REATTACH:
  4955. case CONF_PARTYDISC:
  4956. CONF_Ind[0] = 9;
  4957. CONF_Ind[3] = 6;
  4958. switch (pty_cai[5])
  4959. {
  4960. case CONF_BEGIN:
  4961. PUT_WORD(&CONF_Ind[1], S_CONF_BEGIN);
  4962. if (pty_cai[0] == 6)
  4963. {
  4964. d = pty_cai[6];
  4965. PUT_DWORD(&CONF_Ind[6], d); /* PartyID */
  4966. }
  4967. else
  4968. {
  4969. PUT_DWORD(&CONF_Ind[6], 0x0);
  4970. }
  4971. break;
  4972. case CONF_ISOLATE:
  4973. PUT_WORD(&CONF_Ind[1], S_CONF_ISOLATE);
  4974. CONF_Ind[0] = 5;
  4975. CONF_Ind[3] = 2;
  4976. break;
  4977. case CONF_REATTACH:
  4978. PUT_WORD(&CONF_Ind[1], S_CONF_REATTACH);
  4979. CONF_Ind[0] = 5;
  4980. CONF_Ind[3] = 2;
  4981. break;
  4982. case CONF_DROP:
  4983. PUT_WORD(&CONF_Ind[1], S_CONF_DROP);
  4984. CONF_Ind[0] = 5;
  4985. CONF_Ind[3] = 2;
  4986. break;
  4987. case CONF_ADD:
  4988. PUT_WORD(&CONF_Ind[1], S_CONF_ADD);
  4989. d = pty_cai[6];
  4990. PUT_DWORD(&CONF_Ind[6], d); /* PartyID */
  4991. tplci = plci->relatedPTYPLCI;
  4992. if (tplci) tplci->ptyState = CONNECTED;
  4993. break;
  4994. case CONF_PARTYDISC:
  4995. CONF_Ind[0] = 7;
  4996. CONF_Ind[3] = 4;
  4997. PUT_WORD(&CONF_Ind[1], S_CONF_PARTYDISC);
  4998. d = pty_cai[6];
  4999. PUT_DWORD(&CONF_Ind[4], d); /* PartyID */
  5000. break;
  5001. }
  5002. plci->ptyState = CONNECTED;
  5003. sendf(plci->appl, _FACILITY_I, Id, 0, "ws", 3, CONF_Ind);
  5004. break;
  5005. case CCBS_INFO_RETAIN:
  5006. case CCBS_ERASECALLLINKAGEID:
  5007. case CCBS_STOP_ALERTING:
  5008. CONF_Ind[0] = 5;
  5009. CONF_Ind[3] = 2;
  5010. switch (pty_cai[5])
  5011. {
  5012. case CCBS_INFO_RETAIN:
  5013. PUT_WORD(&CONF_Ind[1], S_CCBS_INFO_RETAIN);
  5014. break;
  5015. case CCBS_STOP_ALERTING:
  5016. PUT_WORD(&CONF_Ind[1], S_CCBS_STOP_ALERTING);
  5017. break;
  5018. case CCBS_ERASECALLLINKAGEID:
  5019. PUT_WORD(&CONF_Ind[1], S_CCBS_ERASECALLLINKAGEID);
  5020. CONF_Ind[0] = 7;
  5021. CONF_Ind[3] = 4;
  5022. CONF_Ind[6] = 0;
  5023. CONF_Ind[7] = 0;
  5024. break;
  5025. }
  5026. w = pty_cai[6];
  5027. PUT_WORD(&CONF_Ind[4], w); /* PartyID */
  5028. if (plci->appl && (a->Notification_Mask[plci->appl->Id - 1] & SMASK_CCBS))
  5029. {
  5030. sendf(plci->appl, _FACILITY_I, Id, 0, "ws", 3, CONF_Ind);
  5031. }
  5032. else
  5033. {
  5034. for (i = 0; i < max_appl; i++)
  5035. if (a->Notification_Mask[i] & SMASK_CCBS)
  5036. sendf(&application[i], _FACILITY_I, Id & 0x7, 0, "ws", 3, CONF_Ind);
  5037. }
  5038. break;
  5039. }
  5040. break;
  5041. case CALL_HOLD_REJ:
  5042. cau = parms[7];
  5043. if (cau)
  5044. {
  5045. i = _L3_CAUSE | cau[2];
  5046. if (cau[2] == 0) i = 0x3603;
  5047. }
  5048. else
  5049. {
  5050. i = 0x3603;
  5051. }
  5052. PUT_WORD(&SS_Ind[1], S_HOLD);
  5053. PUT_WORD(&SS_Ind[4], i);
  5054. if (plci->SuppState == HOLD_REQUEST)
  5055. {
  5056. plci->SuppState = IDLE;
  5057. sendf(plci->appl, _FACILITY_I, Id, 0, "ws", 3, SS_Ind);
  5058. }
  5059. break;
  5060. case CALL_HOLD_ACK:
  5061. if (plci->SuppState == HOLD_REQUEST)
  5062. {
  5063. plci->SuppState = CALL_HELD;
  5064. CodecIdCheck(a, plci);
  5065. start_internal_command(Id, plci, hold_save_command);
  5066. }
  5067. break;
  5068. case CALL_RETRIEVE_REJ:
  5069. cau = parms[7];
  5070. if (cau)
  5071. {
  5072. i = _L3_CAUSE | cau[2];
  5073. if (cau[2] == 0) i = 0x3603;
  5074. }
  5075. else
  5076. {
  5077. i = 0x3603;
  5078. }
  5079. PUT_WORD(&SS_Ind[1], S_RETRIEVE);
  5080. PUT_WORD(&SS_Ind[4], i);
  5081. if (plci->SuppState == RETRIEVE_REQUEST)
  5082. {
  5083. plci->SuppState = CALL_HELD;
  5084. CodecIdCheck(a, plci);
  5085. sendf(plci->appl, _FACILITY_I, Id, 0, "ws", 3, SS_Ind);
  5086. }
  5087. break;
  5088. case CALL_RETRIEVE_ACK:
  5089. PUT_WORD(&SS_Ind[1], S_RETRIEVE);
  5090. if (plci->SuppState == RETRIEVE_REQUEST)
  5091. {
  5092. plci->SuppState = IDLE;
  5093. plci->call_dir |= CALL_DIR_FORCE_OUTG_NL;
  5094. plci->b_channel = esc_chi[esc_chi[0]]&0x1f;
  5095. if (plci->tel)
  5096. {
  5097. mixer_set_bchannel_id_esc(plci, plci->b_channel);
  5098. dbug(1, dprintf("RetrChannel=0x%x", plci->b_channel));
  5099. SetVoiceChannel(a->AdvCodecPLCI, esc_chi, a);
  5100. if (plci->B2_prot == B2_TRANSPARENT && plci->B3_prot == B3_TRANSPARENT)
  5101. {
  5102. dbug(1, dprintf("Get B-ch"));
  5103. start_internal_command(Id, plci, retrieve_restore_command);
  5104. }
  5105. else
  5106. sendf(plci->appl, _FACILITY_I, Id, 0, "ws", 3, SS_Ind);
  5107. }
  5108. else
  5109. start_internal_command(Id, plci, retrieve_restore_command);
  5110. }
  5111. break;
  5112. case INDICATE_IND:
  5113. if (plci->State != LISTENING) {
  5114. sig_req(plci, HANGUP, 0);
  5115. send_req(plci);
  5116. break;
  5117. }
  5118. cip = find_cip(a, parms[4], parms[6]);
  5119. cip_mask = 1L << cip;
  5120. dbug(1, dprintf("cip=%d,cip_mask=%lx", cip, cip_mask));
  5121. bitmap_zero(plci->c_ind_mask_table, MAX_APPL);
  5122. if (!remove_started && !a->adapter_disabled)
  5123. {
  5124. group_optimization(a, plci);
  5125. for_each_set_bit(i, plci->group_optimization_mask_table, max_appl) {
  5126. if (application[i].Id
  5127. && (a->CIP_Mask[i] & 1 || a->CIP_Mask[i] & cip_mask)
  5128. && CPN_filter_ok(parms[0], a, i)) {
  5129. dbug(1, dprintf("storedcip_mask[%d]=0x%lx", i, a->CIP_Mask[i]));
  5130. __set_bit(i, plci->c_ind_mask_table);
  5131. dbug(1, dprintf("c_ind_mask =%*pb", MAX_APPL, plci->c_ind_mask_table));
  5132. plci->State = INC_CON_PENDING;
  5133. plci->call_dir = (plci->call_dir & ~(CALL_DIR_OUT | CALL_DIR_ORIGINATE)) |
  5134. CALL_DIR_IN | CALL_DIR_ANSWER;
  5135. if (esc_chi[0]) {
  5136. plci->b_channel = esc_chi[esc_chi[0]] & 0x1f;
  5137. mixer_set_bchannel_id_esc(plci, plci->b_channel);
  5138. }
  5139. /* if a listen on the ext controller is done, check if hook states */
  5140. /* are supported or if just a on board codec must be activated */
  5141. if (a->codec_listen[i] && !a->AdvSignalPLCI) {
  5142. if (a->profile.Global_Options & HANDSET)
  5143. plci->tel = ADV_VOICE;
  5144. else if (a->profile.Global_Options & ON_BOARD_CODEC)
  5145. plci->tel = CODEC;
  5146. if (plci->tel) Id |= EXT_CONTROLLER;
  5147. a->codec_listen[i] = plci;
  5148. }
  5149. sendf(&application[i], _CONNECT_I, Id, 0,
  5150. "wSSSSSSSbSSSSS", cip, /* CIP */
  5151. parms[0], /* CalledPartyNumber */
  5152. multi_CiPN_parms[0], /* CallingPartyNumber */
  5153. parms[2], /* CalledPartySubad */
  5154. parms[3], /* CallingPartySubad */
  5155. parms[4], /* BearerCapability */
  5156. parms[5], /* LowLC */
  5157. parms[6], /* HighLC */
  5158. ai_len, /* nested struct add_i */
  5159. add_i[0], /* B channel info */
  5160. add_i[1], /* keypad facility */
  5161. add_i[2], /* user user data */
  5162. add_i[3], /* nested facility */
  5163. multi_CiPN_parms[1] /* second CiPN(SCR) */
  5164. );
  5165. SendSSExtInd(&application[i],
  5166. plci,
  5167. Id,
  5168. multi_ssext_parms);
  5169. SendSetupInfo(&application[i],
  5170. plci,
  5171. Id,
  5172. parms,
  5173. SendMultiIE(plci, Id, multi_pi_parms, PI, 0x210, true));
  5174. }
  5175. }
  5176. dbug(1, dprintf("c_ind_mask =%*pb", MAX_APPL, plci->c_ind_mask_table));
  5177. }
  5178. if (bitmap_empty(plci->c_ind_mask_table, MAX_APPL)) {
  5179. sig_req(plci, HANGUP, 0);
  5180. send_req(plci);
  5181. plci->State = IDLE;
  5182. }
  5183. plci->notifiedcall = 0;
  5184. a->listen_active--;
  5185. listen_check(a);
  5186. break;
  5187. case CALL_PEND_NOTIFY:
  5188. plci->notifiedcall = 1;
  5189. listen_check(a);
  5190. break;
  5191. case CALL_IND:
  5192. case CALL_CON:
  5193. if (plci->State == ADVANCED_VOICE_SIG || plci->State == ADVANCED_VOICE_NOSIG)
  5194. {
  5195. if (plci->internal_command == PERM_COD_CONN_PEND)
  5196. {
  5197. if (plci->State == ADVANCED_VOICE_NOSIG)
  5198. {
  5199. dbug(1, dprintf("***Codec OK"));
  5200. if (a->AdvSignalPLCI)
  5201. {
  5202. tplci = a->AdvSignalPLCI;
  5203. if (tplci->spoofed_msg)
  5204. {
  5205. dbug(1, dprintf("***Spoofed Msg(0x%x)", tplci->spoofed_msg));
  5206. tplci->command = 0;
  5207. tplci->internal_command = 0;
  5208. x_Id = ((word)tplci->Id << 8) | tplci->adapter->Id | 0x80;
  5209. switch (tplci->spoofed_msg)
  5210. {
  5211. case CALL_RES:
  5212. tplci->command = _CONNECT_I | RESPONSE;
  5213. api_load_msg(&tplci->saved_msg, saved_parms);
  5214. add_b1(tplci, &saved_parms[1], 0, tplci->B1_facilities);
  5215. if (tplci->adapter->Info_Mask[tplci->appl->Id - 1] & 0x200)
  5216. {
  5217. /* early B3 connect (CIP mask bit 9) no release after a disc */
  5218. add_p(tplci, LLI, "\x01\x01");
  5219. }
  5220. add_s(tplci, CONN_NR, &saved_parms[2]);
  5221. add_s(tplci, LLC, &saved_parms[4]);
  5222. add_ai(tplci, &saved_parms[5]);
  5223. tplci->State = INC_CON_ACCEPT;
  5224. sig_req(tplci, CALL_RES, 0);
  5225. send_req(tplci);
  5226. break;
  5227. case AWAITING_SELECT_B:
  5228. dbug(1, dprintf("Select_B continue"));
  5229. start_internal_command(x_Id, tplci, select_b_command);
  5230. break;
  5231. case AWAITING_MANUF_CON: /* Get_Plci per Manufacturer_Req to ext controller */
  5232. if (!tplci->Sig.Id)
  5233. {
  5234. dbug(1, dprintf("No SigID!"));
  5235. sendf(tplci->appl, _MANUFACTURER_R | CONFIRM, x_Id, tplci->number, "dww", _DI_MANU_ID, _MANUFACTURER_R, _OUT_OF_PLCI);
  5236. plci_remove(tplci);
  5237. break;
  5238. }
  5239. tplci->command = _MANUFACTURER_R;
  5240. api_load_msg(&tplci->saved_msg, saved_parms);
  5241. dir = saved_parms[2].info[0];
  5242. if (dir == 1) {
  5243. sig_req(tplci, CALL_REQ, 0);
  5244. }
  5245. else if (!dir) {
  5246. sig_req(tplci, LISTEN_REQ, 0);
  5247. }
  5248. send_req(tplci);
  5249. sendf(tplci->appl, _MANUFACTURER_R | CONFIRM, x_Id, tplci->number, "dww", _DI_MANU_ID, _MANUFACTURER_R, 0);
  5250. break;
  5251. case (CALL_REQ | AWAITING_MANUF_CON):
  5252. sig_req(tplci, CALL_REQ, 0);
  5253. send_req(tplci);
  5254. break;
  5255. case CALL_REQ:
  5256. if (!tplci->Sig.Id)
  5257. {
  5258. dbug(1, dprintf("No SigID!"));
  5259. sendf(tplci->appl, _CONNECT_R | CONFIRM, tplci->adapter->Id, 0, "w", _OUT_OF_PLCI);
  5260. plci_remove(tplci);
  5261. break;
  5262. }
  5263. tplci->command = _CONNECT_R;
  5264. api_load_msg(&tplci->saved_msg, saved_parms);
  5265. add_s(tplci, CPN, &saved_parms[1]);
  5266. add_s(tplci, DSA, &saved_parms[3]);
  5267. add_ai(tplci, &saved_parms[9]);
  5268. sig_req(tplci, CALL_REQ, 0);
  5269. send_req(tplci);
  5270. break;
  5271. case CALL_RETRIEVE:
  5272. tplci->command = C_RETRIEVE_REQ;
  5273. sig_req(tplci, CALL_RETRIEVE, 0);
  5274. send_req(tplci);
  5275. break;
  5276. }
  5277. tplci->spoofed_msg = 0;
  5278. if (tplci->internal_command == 0)
  5279. next_internal_command(x_Id, tplci);
  5280. }
  5281. }
  5282. next_internal_command(Id, plci);
  5283. break;
  5284. }
  5285. dbug(1, dprintf("***Codec Hook Init Req"));
  5286. plci->internal_command = PERM_COD_HOOK;
  5287. add_p(plci, FTY, "\x01\x09"); /* Get Hook State*/
  5288. sig_req(plci, TEL_CTRL, 0);
  5289. send_req(plci);
  5290. }
  5291. }
  5292. else if (plci->command != _MANUFACTURER_R /* old style permanent connect */
  5293. && plci->State != INC_ACT_PENDING)
  5294. {
  5295. mixer_set_bchannel_id_esc(plci, plci->b_channel);
  5296. if (plci->tel == ADV_VOICE && plci->SuppState == IDLE) /* with permanent codec switch on immediately */
  5297. {
  5298. chi[2] = plci->b_channel;
  5299. SetVoiceChannel(a->AdvCodecPLCI, chi, a);
  5300. }
  5301. sendf(plci->appl, _CONNECT_ACTIVE_I, Id, 0, "Sss", parms[21], "", "");
  5302. plci->State = INC_ACT_PENDING;
  5303. }
  5304. break;
  5305. case TEL_CTRL:
  5306. ie = multi_fac_parms[0]; /* inspect the facility hook indications */
  5307. if (plci->State == ADVANCED_VOICE_SIG && ie[0]) {
  5308. switch (ie[1] & 0x91) {
  5309. case 0x80: /* hook off */
  5310. case 0x81:
  5311. if (plci->internal_command == PERM_COD_HOOK)
  5312. {
  5313. dbug(1, dprintf("init:hook_off"));
  5314. plci->hook_state = ie[1];
  5315. next_internal_command(Id, plci);
  5316. break;
  5317. }
  5318. else /* ignore doubled hook indications */
  5319. {
  5320. if (((plci->hook_state) & 0xf0) == 0x80)
  5321. {
  5322. dbug(1, dprintf("ignore hook"));
  5323. break;
  5324. }
  5325. plci->hook_state = ie[1]&0x91;
  5326. }
  5327. /* check for incoming call pending */
  5328. /* and signal '+'.Appl must decide */
  5329. /* with connect_res if call must */
  5330. /* accepted or not */
  5331. for (i = 0, tplci = NULL; i < max_appl; i++) {
  5332. if (a->codec_listen[i]
  5333. && (a->codec_listen[i]->State == INC_CON_PENDING
  5334. || a->codec_listen[i]->State == INC_CON_ALERT)) {
  5335. tplci = a->codec_listen[i];
  5336. tplci->appl = &application[i];
  5337. }
  5338. }
  5339. /* no incoming call, do outgoing call */
  5340. /* and signal '+' if outg. setup */
  5341. if (!a->AdvSignalPLCI && !tplci) {
  5342. if ((i = get_plci(a))) {
  5343. a->AdvSignalPLCI = &a->plci[i - 1];
  5344. tplci = a->AdvSignalPLCI;
  5345. tplci->tel = ADV_VOICE;
  5346. PUT_WORD(&voice_cai[5], a->AdvSignalAppl->MaxDataLength);
  5347. if (a->Info_Mask[a->AdvSignalAppl->Id - 1] & 0x200) {
  5348. /* early B3 connect (CIP mask bit 9) no release after a disc */
  5349. add_p(tplci, LLI, "\x01\x01");
  5350. }
  5351. add_p(tplci, CAI, voice_cai);
  5352. add_p(tplci, OAD, a->TelOAD);
  5353. add_p(tplci, OSA, a->TelOSA);
  5354. add_p(tplci, SHIFT | 6, NULL);
  5355. add_p(tplci, SIN, "\x02\x01\x00");
  5356. add_p(tplci, UID, "\x06\x43\x61\x70\x69\x32\x30");
  5357. sig_req(tplci, ASSIGN, DSIG_ID);
  5358. a->AdvSignalPLCI->internal_command = HOOK_OFF_REQ;
  5359. a->AdvSignalPLCI->command = 0;
  5360. tplci->appl = a->AdvSignalAppl;
  5361. tplci->call_dir = CALL_DIR_OUT | CALL_DIR_ORIGINATE;
  5362. send_req(tplci);
  5363. }
  5364. }
  5365. if (!tplci) break;
  5366. Id = ((word)tplci->Id << 8) | a->Id;
  5367. Id |= EXT_CONTROLLER;
  5368. sendf(tplci->appl,
  5369. _FACILITY_I,
  5370. Id,
  5371. 0,
  5372. "ws", (word)0, "\x01+");
  5373. break;
  5374. case 0x90: /* hook on */
  5375. case 0x91:
  5376. if (plci->internal_command == PERM_COD_HOOK)
  5377. {
  5378. dbug(1, dprintf("init:hook_on"));
  5379. plci->hook_state = ie[1] & 0x91;
  5380. next_internal_command(Id, plci);
  5381. break;
  5382. }
  5383. else /* ignore doubled hook indications */
  5384. {
  5385. if (((plci->hook_state) & 0xf0) == 0x90) break;
  5386. plci->hook_state = ie[1] & 0x91;
  5387. }
  5388. /* hangup the adv. voice call and signal '-' to the appl */
  5389. if (a->AdvSignalPLCI) {
  5390. Id = ((word)a->AdvSignalPLCI->Id << 8) | a->Id;
  5391. if (plci->tel) Id |= EXT_CONTROLLER;
  5392. sendf(a->AdvSignalAppl,
  5393. _FACILITY_I,
  5394. Id,
  5395. 0,
  5396. "ws", (word)0, "\x01-");
  5397. a->AdvSignalPLCI->internal_command = HOOK_ON_REQ;
  5398. a->AdvSignalPLCI->command = 0;
  5399. sig_req(a->AdvSignalPLCI, HANGUP, 0);
  5400. send_req(a->AdvSignalPLCI);
  5401. }
  5402. break;
  5403. }
  5404. }
  5405. break;
  5406. case RESUME:
  5407. __clear_bit(plci->appl->Id - 1, plci->c_ind_mask_table);
  5408. PUT_WORD(&resume_cau[4], GOOD);
  5409. sendf(plci->appl, _FACILITY_I, Id, 0, "ws", (word)3, resume_cau);
  5410. break;
  5411. case SUSPEND:
  5412. bitmap_zero(plci->c_ind_mask_table, MAX_APPL);
  5413. if (plci->NL.Id && !plci->nl_remove_id) {
  5414. mixer_remove(plci);
  5415. nl_req_ncci(plci, REMOVE, 0);
  5416. }
  5417. if (!plci->sig_remove_id) {
  5418. plci->internal_command = 0;
  5419. sig_req(plci, REMOVE, 0);
  5420. }
  5421. send_req(plci);
  5422. if (!plci->channels) {
  5423. sendf(plci->appl, _FACILITY_I, Id, 0, "ws", (word)3, "\x05\x04\x00\x02\x00\x00");
  5424. sendf(plci->appl, _DISCONNECT_I, Id, 0, "w", 0);
  5425. }
  5426. break;
  5427. case SUSPEND_REJ:
  5428. break;
  5429. case HANGUP:
  5430. plci->hangup_flow_ctrl_timer = 0;
  5431. if (plci->manufacturer && plci->State == LOCAL_CONNECT) break;
  5432. cau = parms[7];
  5433. if (cau) {
  5434. i = _L3_CAUSE | cau[2];
  5435. if (cau[2] == 0) i = 0;
  5436. else if (cau[2] == 8) i = _L1_ERROR;
  5437. else if (cau[2] == 9 || cau[2] == 10) i = _L2_ERROR;
  5438. else if (cau[2] == 5) i = _CAPI_GUARD_ERROR;
  5439. }
  5440. else {
  5441. i = _L3_ERROR;
  5442. }
  5443. if (plci->State == INC_CON_PENDING || plci->State == INC_CON_ALERT)
  5444. {
  5445. for_each_set_bit(i, plci->c_ind_mask_table, max_appl)
  5446. sendf(&application[i], _DISCONNECT_I, Id, 0, "w", 0);
  5447. }
  5448. else
  5449. {
  5450. bitmap_zero(plci->c_ind_mask_table, MAX_APPL);
  5451. }
  5452. if (!plci->appl)
  5453. {
  5454. if (plci->State == LISTENING)
  5455. {
  5456. plci->notifiedcall = 0;
  5457. a->listen_active--;
  5458. }
  5459. plci->State = INC_DIS_PENDING;
  5460. if (bitmap_empty(plci->c_ind_mask_table, MAX_APPL))
  5461. {
  5462. plci->State = IDLE;
  5463. if (plci->NL.Id && !plci->nl_remove_id)
  5464. {
  5465. mixer_remove(plci);
  5466. nl_req_ncci(plci, REMOVE, 0);
  5467. }
  5468. if (!plci->sig_remove_id)
  5469. {
  5470. plci->internal_command = 0;
  5471. sig_req(plci, REMOVE, 0);
  5472. }
  5473. send_req(plci);
  5474. }
  5475. }
  5476. else
  5477. {
  5478. /* collision of DISCONNECT or CONNECT_RES with HANGUP can */
  5479. /* result in a second HANGUP! Don't generate another */
  5480. /* DISCONNECT */
  5481. if (plci->State != IDLE && plci->State != INC_DIS_PENDING)
  5482. {
  5483. if (plci->State == RESUMING)
  5484. {
  5485. PUT_WORD(&resume_cau[4], i);
  5486. sendf(plci->appl, _FACILITY_I, Id, 0, "ws", (word)3, resume_cau);
  5487. }
  5488. plci->State = INC_DIS_PENDING;
  5489. sendf(plci->appl, _DISCONNECT_I, Id, 0, "w", i);
  5490. }
  5491. }
  5492. break;
  5493. case SSEXT_IND:
  5494. SendSSExtInd(NULL, plci, Id, multi_ssext_parms);
  5495. break;
  5496. case VSWITCH_REQ:
  5497. VSwitchReqInd(plci, Id, multi_vswitch_parms);
  5498. break;
  5499. case VSWITCH_IND:
  5500. if (plci->relatedPTYPLCI &&
  5501. plci->vswitchstate == 3 &&
  5502. plci->relatedPTYPLCI->vswitchstate == 3 &&
  5503. parms[MAXPARMSIDS - 1][0])
  5504. {
  5505. add_p(plci->relatedPTYPLCI, SMSG, parms[MAXPARMSIDS - 1]);
  5506. sig_req(plci->relatedPTYPLCI, VSWITCH_REQ, 0);
  5507. send_req(plci->relatedPTYPLCI);
  5508. }
  5509. else VSwitchReqInd(plci, Id, multi_vswitch_parms);
  5510. break;
  5511. }
  5512. }
  5513. static void SendSetupInfo(APPL *appl, PLCI *plci, dword Id, byte **parms, byte Info_Sent_Flag)
  5514. {
  5515. word i;
  5516. byte *ie;
  5517. word Info_Number;
  5518. byte *Info_Element;
  5519. word Info_Mask = 0;
  5520. dbug(1, dprintf("SetupInfo"));
  5521. for (i = 0; i < MAXPARMSIDS; i++) {
  5522. ie = parms[i];
  5523. Info_Number = 0;
  5524. Info_Element = ie;
  5525. if (ie[0]) {
  5526. switch (i) {
  5527. case 0:
  5528. dbug(1, dprintf("CPN "));
  5529. Info_Number = 0x0070;
  5530. Info_Mask = 0x80;
  5531. Info_Sent_Flag = true;
  5532. break;
  5533. case 8: /* display */
  5534. dbug(1, dprintf("display(%d)", i));
  5535. Info_Number = 0x0028;
  5536. Info_Mask = 0x04;
  5537. Info_Sent_Flag = true;
  5538. break;
  5539. case 16: /* Channel Id */
  5540. dbug(1, dprintf("CHI"));
  5541. Info_Number = 0x0018;
  5542. Info_Mask = 0x100;
  5543. Info_Sent_Flag = true;
  5544. mixer_set_bchannel_id(plci, Info_Element);
  5545. break;
  5546. case 19: /* Redirected Number */
  5547. dbug(1, dprintf("RDN"));
  5548. Info_Number = 0x0074;
  5549. Info_Mask = 0x400;
  5550. Info_Sent_Flag = true;
  5551. break;
  5552. case 20: /* Redirected Number extended */
  5553. dbug(1, dprintf("RDX"));
  5554. Info_Number = 0x0073;
  5555. Info_Mask = 0x400;
  5556. Info_Sent_Flag = true;
  5557. break;
  5558. case 22: /* Redirecing Number */
  5559. dbug(1, dprintf("RIN"));
  5560. Info_Number = 0x0076;
  5561. Info_Mask = 0x400;
  5562. Info_Sent_Flag = true;
  5563. break;
  5564. default:
  5565. Info_Number = 0;
  5566. break;
  5567. }
  5568. }
  5569. if (i == MAXPARMSIDS - 2) { /* to indicate the message type "Setup" */
  5570. Info_Number = 0x8000 | 5;
  5571. Info_Mask = 0x10;
  5572. Info_Element = "";
  5573. }
  5574. if (Info_Sent_Flag && Info_Number) {
  5575. if (plci->adapter->Info_Mask[appl->Id - 1] & Info_Mask) {
  5576. sendf(appl, _INFO_I, Id, 0, "wS", Info_Number, Info_Element);
  5577. }
  5578. }
  5579. }
  5580. }
  5581. static void SendInfo(PLCI *plci, dword Id, byte **parms, byte iesent)
  5582. {
  5583. word i;
  5584. word j;
  5585. word k;
  5586. byte *ie;
  5587. word Info_Number;
  5588. byte *Info_Element;
  5589. word Info_Mask = 0;
  5590. static byte charges[5] = {4, 0, 0, 0, 0};
  5591. static byte cause[] = {0x02, 0x80, 0x00};
  5592. APPL *appl;
  5593. dbug(1, dprintf("InfoParse "));
  5594. if (
  5595. !plci->appl
  5596. && !plci->State
  5597. && plci->Sig.Ind != NCR_FACILITY
  5598. )
  5599. {
  5600. dbug(1, dprintf("NoParse "));
  5601. return;
  5602. }
  5603. cause[2] = 0;
  5604. for (i = 0; i < MAXPARMSIDS; i++) {
  5605. ie = parms[i];
  5606. Info_Number = 0;
  5607. Info_Element = ie;
  5608. if (ie[0]) {
  5609. switch (i) {
  5610. case 0:
  5611. dbug(1, dprintf("CPN "));
  5612. Info_Number = 0x0070;
  5613. Info_Mask = 0x80;
  5614. break;
  5615. case 7: /* ESC_CAU */
  5616. dbug(1, dprintf("cau(0x%x)", ie[2]));
  5617. Info_Number = 0x0008;
  5618. Info_Mask = 0x00;
  5619. cause[2] = ie[2];
  5620. Info_Element = NULL;
  5621. break;
  5622. case 8: /* display */
  5623. dbug(1, dprintf("display(%d)", i));
  5624. Info_Number = 0x0028;
  5625. Info_Mask = 0x04;
  5626. break;
  5627. case 9: /* Date display */
  5628. dbug(1, dprintf("date(%d)", i));
  5629. Info_Number = 0x0029;
  5630. Info_Mask = 0x02;
  5631. break;
  5632. case 10: /* charges */
  5633. for (j = 0; j < 4; j++) charges[1 + j] = 0;
  5634. for (j = 0; j < ie[0] && !(ie[1 + j] & 0x80); j++);
  5635. for (k = 1, j++; j < ie[0] && k <= 4; j++, k++) charges[k] = ie[1 + j];
  5636. Info_Number = 0x4000;
  5637. Info_Mask = 0x40;
  5638. Info_Element = charges;
  5639. break;
  5640. case 11: /* user user info */
  5641. dbug(1, dprintf("uui"));
  5642. Info_Number = 0x007E;
  5643. Info_Mask = 0x08;
  5644. break;
  5645. case 12: /* congestion receiver ready */
  5646. dbug(1, dprintf("clRDY"));
  5647. Info_Number = 0x00B0;
  5648. Info_Mask = 0x08;
  5649. Info_Element = "";
  5650. break;
  5651. case 13: /* congestion receiver not ready */
  5652. dbug(1, dprintf("clNRDY"));
  5653. Info_Number = 0x00BF;
  5654. Info_Mask = 0x08;
  5655. Info_Element = "";
  5656. break;
  5657. case 15: /* Keypad Facility */
  5658. dbug(1, dprintf("KEY"));
  5659. Info_Number = 0x002C;
  5660. Info_Mask = 0x20;
  5661. break;
  5662. case 16: /* Channel Id */
  5663. dbug(1, dprintf("CHI"));
  5664. Info_Number = 0x0018;
  5665. Info_Mask = 0x100;
  5666. mixer_set_bchannel_id(plci, Info_Element);
  5667. break;
  5668. case 17: /* if no 1tr6 cause, send full cause, else esc_cause */
  5669. dbug(1, dprintf("q9cau(0x%x)", ie[2]));
  5670. if (!cause[2] || cause[2] < 0x80) break; /* eg. layer 1 error */
  5671. Info_Number = 0x0008;
  5672. Info_Mask = 0x01;
  5673. if (cause[2] != ie[2]) Info_Element = cause;
  5674. break;
  5675. case 19: /* Redirected Number */
  5676. dbug(1, dprintf("RDN"));
  5677. Info_Number = 0x0074;
  5678. Info_Mask = 0x400;
  5679. break;
  5680. case 22: /* Redirecing Number */
  5681. dbug(1, dprintf("RIN"));
  5682. Info_Number = 0x0076;
  5683. Info_Mask = 0x400;
  5684. break;
  5685. case 23: /* Notification Indicator */
  5686. dbug(1, dprintf("NI"));
  5687. Info_Number = (word)NI;
  5688. Info_Mask = 0x210;
  5689. break;
  5690. case 26: /* Call State */
  5691. dbug(1, dprintf("CST"));
  5692. Info_Number = (word)CST;
  5693. Info_Mask = 0x01; /* do with cause i.e. for now */
  5694. break;
  5695. case MAXPARMSIDS - 2: /* Escape Message Type, must be the last indication */
  5696. dbug(1, dprintf("ESC/MT[0x%x]", ie[3]));
  5697. Info_Number = 0x8000 | ie[3];
  5698. if (iesent) Info_Mask = 0xffff;
  5699. else Info_Mask = 0x10;
  5700. Info_Element = "";
  5701. break;
  5702. default:
  5703. Info_Number = 0;
  5704. Info_Mask = 0;
  5705. Info_Element = "";
  5706. break;
  5707. }
  5708. }
  5709. if (plci->Sig.Ind == NCR_FACILITY) /* check controller broadcast */
  5710. {
  5711. for (j = 0; j < max_appl; j++)
  5712. {
  5713. appl = &application[j];
  5714. if (Info_Number
  5715. && appl->Id
  5716. && plci->adapter->Info_Mask[appl->Id - 1] & Info_Mask)
  5717. {
  5718. dbug(1, dprintf("NCR_Ind"));
  5719. iesent = true;
  5720. sendf(&application[j], _INFO_I, Id & 0x0f, 0, "wS", Info_Number, Info_Element);
  5721. }
  5722. }
  5723. }
  5724. else if (!plci->appl)
  5725. { /* overlap receiving broadcast */
  5726. if (Info_Number == CPN
  5727. || Info_Number == KEY
  5728. || Info_Number == NI
  5729. || Info_Number == DSP
  5730. || Info_Number == UUI)
  5731. {
  5732. for_each_set_bit(j, plci->c_ind_mask_table, max_appl) {
  5733. dbug(1, dprintf("Ovl_Ind"));
  5734. iesent = true;
  5735. sendf(&application[j], _INFO_I, Id, 0, "wS", Info_Number, Info_Element);
  5736. }
  5737. }
  5738. } /* all other signalling states */
  5739. else if (Info_Number
  5740. && plci->adapter->Info_Mask[plci->appl->Id - 1] & Info_Mask)
  5741. {
  5742. dbug(1, dprintf("Std_Ind"));
  5743. iesent = true;
  5744. sendf(plci->appl, _INFO_I, Id, 0, "wS", Info_Number, Info_Element);
  5745. }
  5746. }
  5747. }
  5748. static byte SendMultiIE(PLCI *plci, dword Id, byte **parms, byte ie_type,
  5749. dword info_mask, byte setupParse)
  5750. {
  5751. word i;
  5752. word j;
  5753. byte *ie;
  5754. word Info_Number;
  5755. byte *Info_Element;
  5756. APPL *appl;
  5757. word Info_Mask = 0;
  5758. byte iesent = 0;
  5759. if (
  5760. !plci->appl
  5761. && !plci->State
  5762. && plci->Sig.Ind != NCR_FACILITY
  5763. && !setupParse
  5764. )
  5765. {
  5766. dbug(1, dprintf("NoM-IEParse "));
  5767. return 0;
  5768. }
  5769. dbug(1, dprintf("M-IEParse "));
  5770. for (i = 0; i < MAX_MULTI_IE; i++)
  5771. {
  5772. ie = parms[i];
  5773. Info_Number = 0;
  5774. Info_Element = ie;
  5775. if (ie[0])
  5776. {
  5777. dbug(1, dprintf("[Ind0x%x]:IE=0x%x", plci->Sig.Ind, ie_type));
  5778. Info_Number = (word)ie_type;
  5779. Info_Mask = (word)info_mask;
  5780. }
  5781. if (plci->Sig.Ind == NCR_FACILITY) /* check controller broadcast */
  5782. {
  5783. for (j = 0; j < max_appl; j++)
  5784. {
  5785. appl = &application[j];
  5786. if (Info_Number
  5787. && appl->Id
  5788. && plci->adapter->Info_Mask[appl->Id - 1] & Info_Mask)
  5789. {
  5790. iesent = true;
  5791. dbug(1, dprintf("Mlt_NCR_Ind"));
  5792. sendf(&application[j], _INFO_I, Id & 0x0f, 0, "wS", Info_Number, Info_Element);
  5793. }
  5794. }
  5795. }
  5796. else if (!plci->appl && Info_Number)
  5797. { /* overlap receiving broadcast */
  5798. for_each_set_bit(j, plci->c_ind_mask_table, max_appl) {
  5799. iesent = true;
  5800. dbug(1, dprintf("Mlt_Ovl_Ind"));
  5801. sendf(&application[j] , _INFO_I, Id, 0, "wS", Info_Number, Info_Element);
  5802. }
  5803. } /* all other signalling states */
  5804. else if (Info_Number
  5805. && plci->adapter->Info_Mask[plci->appl->Id - 1] & Info_Mask)
  5806. {
  5807. iesent = true;
  5808. dbug(1, dprintf("Mlt_Std_Ind"));
  5809. sendf(plci->appl, _INFO_I, Id, 0, "wS", Info_Number, Info_Element);
  5810. }
  5811. }
  5812. return iesent;
  5813. }
  5814. static void SendSSExtInd(APPL *appl, PLCI *plci, dword Id, byte **parms)
  5815. {
  5816. word i;
  5817. /* Format of multi_ssext_parms[i][]:
  5818. 0 byte length
  5819. 1 byte SSEXTIE
  5820. 2 byte SSEXT_REQ/SSEXT_IND
  5821. 3 byte length
  5822. 4 word SSExtCommand
  5823. 6... Params
  5824. */
  5825. if (
  5826. plci
  5827. && plci->State
  5828. && plci->Sig.Ind != NCR_FACILITY
  5829. )
  5830. for (i = 0; i < MAX_MULTI_IE; i++)
  5831. {
  5832. if (parms[i][0] < 6) continue;
  5833. if (parms[i][2] == SSEXT_REQ) continue;
  5834. if (appl)
  5835. {
  5836. parms[i][0] = 0; /* kill it */
  5837. sendf(appl, _MANUFACTURER_I,
  5838. Id,
  5839. 0,
  5840. "dwS",
  5841. _DI_MANU_ID,
  5842. _DI_SSEXT_CTRL,
  5843. &parms[i][3]);
  5844. }
  5845. else if (plci->appl)
  5846. {
  5847. parms[i][0] = 0; /* kill it */
  5848. sendf(plci->appl, _MANUFACTURER_I,
  5849. Id,
  5850. 0,
  5851. "dwS",
  5852. _DI_MANU_ID,
  5853. _DI_SSEXT_CTRL,
  5854. &parms[i][3]);
  5855. }
  5856. }
  5857. };
  5858. static void nl_ind(PLCI *plci)
  5859. {
  5860. byte ch;
  5861. word ncci;
  5862. dword Id;
  5863. DIVA_CAPI_ADAPTER *a;
  5864. word NCCIcode;
  5865. APPL *APPLptr;
  5866. word count;
  5867. word Num;
  5868. word i, ncpi_state;
  5869. byte len, ncci_state;
  5870. word msg;
  5871. word info = 0;
  5872. word fax_feature_bits;
  5873. byte fax_send_edata_ack;
  5874. static byte v120_header_buffer[2 + 3];
  5875. static word fax_info[] = {
  5876. 0, /* T30_SUCCESS */
  5877. _FAX_NO_CONNECTION, /* T30_ERR_NO_DIS_RECEIVED */
  5878. _FAX_PROTOCOL_ERROR, /* T30_ERR_TIMEOUT_NO_RESPONSE */
  5879. _FAX_PROTOCOL_ERROR, /* T30_ERR_RETRY_NO_RESPONSE */
  5880. _FAX_PROTOCOL_ERROR, /* T30_ERR_TOO_MANY_REPEATS */
  5881. _FAX_PROTOCOL_ERROR, /* T30_ERR_UNEXPECTED_MESSAGE */
  5882. _FAX_REMOTE_ABORT, /* T30_ERR_UNEXPECTED_DCN */
  5883. _FAX_LOCAL_ABORT, /* T30_ERR_DTC_UNSUPPORTED */
  5884. _FAX_TRAINING_ERROR, /* T30_ERR_ALL_RATES_FAILED */
  5885. _FAX_TRAINING_ERROR, /* T30_ERR_TOO_MANY_TRAINS */
  5886. _FAX_PARAMETER_ERROR, /* T30_ERR_RECEIVE_CORRUPTED */
  5887. _FAX_REMOTE_ABORT, /* T30_ERR_UNEXPECTED_DISC */
  5888. _FAX_LOCAL_ABORT, /* T30_ERR_APPLICATION_DISC */
  5889. _FAX_REMOTE_REJECT, /* T30_ERR_INCOMPATIBLE_DIS */
  5890. _FAX_LOCAL_ABORT, /* T30_ERR_INCOMPATIBLE_DCS */
  5891. _FAX_PROTOCOL_ERROR, /* T30_ERR_TIMEOUT_NO_COMMAND */
  5892. _FAX_PROTOCOL_ERROR, /* T30_ERR_RETRY_NO_COMMAND */
  5893. _FAX_PROTOCOL_ERROR, /* T30_ERR_TIMEOUT_COMMAND_TOO_LONG */
  5894. _FAX_PROTOCOL_ERROR, /* T30_ERR_TIMEOUT_RESPONSE_TOO_LONG */
  5895. _FAX_NO_CONNECTION, /* T30_ERR_NOT_IDENTIFIED */
  5896. _FAX_PROTOCOL_ERROR, /* T30_ERR_SUPERVISORY_TIMEOUT */
  5897. _FAX_PARAMETER_ERROR, /* T30_ERR_TOO_LONG_SCAN_LINE */
  5898. _FAX_PROTOCOL_ERROR, /* T30_ERR_RETRY_NO_PAGE_AFTER_MPS */
  5899. _FAX_PROTOCOL_ERROR, /* T30_ERR_RETRY_NO_PAGE_AFTER_CFR */
  5900. _FAX_PROTOCOL_ERROR, /* T30_ERR_RETRY_NO_DCS_AFTER_FTT */
  5901. _FAX_PROTOCOL_ERROR, /* T30_ERR_RETRY_NO_DCS_AFTER_EOM */
  5902. _FAX_PROTOCOL_ERROR, /* T30_ERR_RETRY_NO_DCS_AFTER_MPS */
  5903. _FAX_PROTOCOL_ERROR, /* T30_ERR_RETRY_NO_DCN_AFTER_MCF */
  5904. _FAX_PROTOCOL_ERROR, /* T30_ERR_RETRY_NO_DCN_AFTER_RTN */
  5905. _FAX_PROTOCOL_ERROR, /* T30_ERR_RETRY_NO_CFR */
  5906. _FAX_PROTOCOL_ERROR, /* T30_ERR_RETRY_NO_MCF_AFTER_EOP */
  5907. _FAX_PROTOCOL_ERROR, /* T30_ERR_RETRY_NO_MCF_AFTER_EOM */
  5908. _FAX_PROTOCOL_ERROR, /* T30_ERR_RETRY_NO_MCF_AFTER_MPS */
  5909. 0x331d, /* T30_ERR_SUB_SEP_UNSUPPORTED */
  5910. 0x331e, /* T30_ERR_PWD_UNSUPPORTED */
  5911. 0x331f, /* T30_ERR_SUB_SEP_PWD_UNSUPPORTED */
  5912. _FAX_PROTOCOL_ERROR, /* T30_ERR_INVALID_COMMAND_FRAME */
  5913. _FAX_PARAMETER_ERROR, /* T30_ERR_UNSUPPORTED_PAGE_CODING */
  5914. _FAX_PARAMETER_ERROR, /* T30_ERR_INVALID_PAGE_CODING */
  5915. _FAX_REMOTE_REJECT, /* T30_ERR_INCOMPATIBLE_PAGE_CONFIG */
  5916. _FAX_LOCAL_ABORT, /* T30_ERR_TIMEOUT_FROM_APPLICATION */
  5917. _FAX_PROTOCOL_ERROR, /* T30_ERR_V34FAX_NO_REACTION_ON_MARK */
  5918. _FAX_PROTOCOL_ERROR, /* T30_ERR_V34FAX_TRAINING_TIMEOUT */
  5919. _FAX_PROTOCOL_ERROR, /* T30_ERR_V34FAX_UNEXPECTED_V21 */
  5920. _FAX_PROTOCOL_ERROR, /* T30_ERR_V34FAX_PRIMARY_CTS_ON */
  5921. _FAX_LOCAL_ABORT, /* T30_ERR_V34FAX_TURNAROUND_POLLING */
  5922. _FAX_LOCAL_ABORT /* T30_ERR_V34FAX_V8_INCOMPATIBILITY */
  5923. };
  5924. byte dtmf_code_buffer[CAPIDTMF_RECV_DIGIT_BUFFER_SIZE + 1];
  5925. static word rtp_info[] = {
  5926. GOOD, /* RTP_SUCCESS */
  5927. 0x3600 /* RTP_ERR_SSRC_OR_PAYLOAD_CHANGE */
  5928. };
  5929. static dword udata_forwarding_table[0x100 / sizeof(dword)] =
  5930. {
  5931. 0x0020301e, 0x00000000, 0x00000000, 0x00000000,
  5932. 0x00000000, 0x00000000, 0x00000000, 0x00000000
  5933. };
  5934. ch = plci->NL.IndCh;
  5935. a = plci->adapter;
  5936. ncci = a->ch_ncci[ch];
  5937. Id = (((dword)(ncci ? ncci : ch)) << 16) | (((word) plci->Id) << 8) | a->Id;
  5938. if (plci->tel) Id |= EXT_CONTROLLER;
  5939. APPLptr = plci->appl;
  5940. 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",
  5941. plci->NL.Id, Id, plci->Id, plci->tel, plci->State, ch, plci->channels, plci->NL.Ind & 0x0f));
  5942. /* in the case if no connect_active_Ind was sent to the appl we wait for */
  5943. if (plci->nl_remove_id)
  5944. {
  5945. plci->NL.RNR = 2; /* discard */
  5946. dbug(1, dprintf("NL discard while remove pending"));
  5947. return;
  5948. }
  5949. if ((plci->NL.Ind & 0x0f) == N_CONNECT)
  5950. {
  5951. if (plci->State == INC_DIS_PENDING
  5952. || plci->State == OUTG_DIS_PENDING
  5953. || plci->State == IDLE)
  5954. {
  5955. plci->NL.RNR = 2; /* discard */
  5956. dbug(1, dprintf("discard n_connect"));
  5957. return;
  5958. }
  5959. if (plci->State < INC_ACT_PENDING)
  5960. {
  5961. plci->NL.RNR = 1; /* flow control */
  5962. channel_x_off(plci, ch, N_XON_CONNECT_IND);
  5963. return;
  5964. }
  5965. }
  5966. if (!APPLptr) /* no application or invalid data */
  5967. { /* while reloading the DSP */
  5968. dbug(1, dprintf("discard1"));
  5969. plci->NL.RNR = 2;
  5970. return;
  5971. }
  5972. if (((plci->NL.Ind & 0x0f) == N_UDATA)
  5973. && (((plci->B2_prot != B2_SDLC) && ((plci->B1_resource == 17) || (plci->B1_resource == 18)))
  5974. || (plci->B2_prot == 7)
  5975. || (plci->B3_prot == 7)))
  5976. {
  5977. plci->ncpi_buffer[0] = 0;
  5978. ncpi_state = plci->ncpi_state;
  5979. if (plci->NL.complete == 1)
  5980. {
  5981. byte *data = &plci->NL.RBuffer->P[0];
  5982. if ((plci->NL.RBuffer->length >= 12)
  5983. && ((*data == DSP_UDATA_INDICATION_DCD_ON)
  5984. || (*data == DSP_UDATA_INDICATION_CTS_ON)))
  5985. {
  5986. word conn_opt, ncpi_opt = 0x00;
  5987. /* HexDump ("MDM N_UDATA:", plci->NL.RBuffer->length, data); */
  5988. if (*data == DSP_UDATA_INDICATION_DCD_ON)
  5989. plci->ncpi_state |= NCPI_MDM_DCD_ON_RECEIVED;
  5990. if (*data == DSP_UDATA_INDICATION_CTS_ON)
  5991. plci->ncpi_state |= NCPI_MDM_CTS_ON_RECEIVED;
  5992. data++; /* indication code */
  5993. data += 2; /* timestamp */
  5994. if ((*data == DSP_CONNECTED_NORM_V18) || (*data == DSP_CONNECTED_NORM_VOWN))
  5995. ncpi_state &= ~(NCPI_MDM_DCD_ON_RECEIVED | NCPI_MDM_CTS_ON_RECEIVED);
  5996. data++; /* connected norm */
  5997. conn_opt = GET_WORD(data);
  5998. data += 2; /* connected options */
  5999. PUT_WORD(&(plci->ncpi_buffer[1]), (word)(GET_DWORD(data) & 0x0000FFFF));
  6000. if (conn_opt & DSP_CONNECTED_OPTION_MASK_V42)
  6001. {
  6002. ncpi_opt |= MDM_NCPI_ECM_V42;
  6003. }
  6004. else if (conn_opt & DSP_CONNECTED_OPTION_MASK_MNP)
  6005. {
  6006. ncpi_opt |= MDM_NCPI_ECM_MNP;
  6007. }
  6008. else
  6009. {
  6010. ncpi_opt |= MDM_NCPI_TRANSPARENT;
  6011. }
  6012. if (conn_opt & DSP_CONNECTED_OPTION_MASK_COMPRESSION)
  6013. {
  6014. ncpi_opt |= MDM_NCPI_COMPRESSED;
  6015. }
  6016. PUT_WORD(&(plci->ncpi_buffer[3]), ncpi_opt);
  6017. plci->ncpi_buffer[0] = 4;
  6018. plci->ncpi_state |= NCPI_VALID_CONNECT_B3_IND | NCPI_VALID_CONNECT_B3_ACT | NCPI_VALID_DISC_B3_IND;
  6019. }
  6020. }
  6021. if (plci->B3_prot == 7)
  6022. {
  6023. if (((a->ncci_state[ncci] == INC_ACT_PENDING) || (a->ncci_state[ncci] == OUTG_CON_PENDING))
  6024. && (plci->ncpi_state & NCPI_VALID_CONNECT_B3_ACT)
  6025. && !(plci->ncpi_state & NCPI_CONNECT_B3_ACT_SENT))
  6026. {
  6027. a->ncci_state[ncci] = INC_ACT_PENDING;
  6028. sendf(plci->appl, _CONNECT_B3_ACTIVE_I, Id, 0, "S", plci->ncpi_buffer);
  6029. plci->ncpi_state |= NCPI_CONNECT_B3_ACT_SENT;
  6030. }
  6031. }
  6032. if (!((plci->requested_options_conn | plci->requested_options | plci->adapter->requested_options_table[plci->appl->Id - 1])
  6033. & ((1L << PRIVATE_V18) | (1L << PRIVATE_VOWN)))
  6034. || !(ncpi_state & NCPI_MDM_DCD_ON_RECEIVED)
  6035. || !(ncpi_state & NCPI_MDM_CTS_ON_RECEIVED))
  6036. {
  6037. plci->NL.RNR = 2;
  6038. return;
  6039. }
  6040. }
  6041. if (plci->NL.complete == 2)
  6042. {
  6043. if (((plci->NL.Ind & 0x0f) == N_UDATA)
  6044. && !(udata_forwarding_table[plci->RData[0].P[0] >> 5] & (1L << (plci->RData[0].P[0] & 0x1f))))
  6045. {
  6046. switch (plci->RData[0].P[0])
  6047. {
  6048. case DTMF_UDATA_INDICATION_FAX_CALLING_TONE:
  6049. if (plci->dtmf_rec_active & DTMF_LISTEN_ACTIVE_FLAG)
  6050. sendf(plci->appl, _FACILITY_I, Id & 0xffffL, 0, "ws", SELECTOR_DTMF, "\x01X");
  6051. break;
  6052. case DTMF_UDATA_INDICATION_ANSWER_TONE:
  6053. if (plci->dtmf_rec_active & DTMF_LISTEN_ACTIVE_FLAG)
  6054. sendf(plci->appl, _FACILITY_I, Id & 0xffffL, 0, "ws", SELECTOR_DTMF, "\x01Y");
  6055. break;
  6056. case DTMF_UDATA_INDICATION_DIGITS_RECEIVED:
  6057. dtmf_indication(Id, plci, plci->RData[0].P, plci->RData[0].PLength);
  6058. break;
  6059. case DTMF_UDATA_INDICATION_DIGITS_SENT:
  6060. dtmf_confirmation(Id, plci);
  6061. break;
  6062. case UDATA_INDICATION_MIXER_TAP_DATA:
  6063. capidtmf_recv_process_block(&(plci->capidtmf_state), plci->RData[0].P + 1, (word)(plci->RData[0].PLength - 1));
  6064. i = capidtmf_indication(&(plci->capidtmf_state), dtmf_code_buffer + 1);
  6065. if (i != 0)
  6066. {
  6067. dtmf_code_buffer[0] = DTMF_UDATA_INDICATION_DIGITS_RECEIVED;
  6068. dtmf_indication(Id, plci, dtmf_code_buffer, (word)(i + 1));
  6069. }
  6070. break;
  6071. case UDATA_INDICATION_MIXER_COEFS_SET:
  6072. mixer_indication_coefs_set(Id, plci);
  6073. break;
  6074. case UDATA_INDICATION_XCONNECT_FROM:
  6075. mixer_indication_xconnect_from(Id, plci, plci->RData[0].P, plci->RData[0].PLength);
  6076. break;
  6077. case UDATA_INDICATION_XCONNECT_TO:
  6078. mixer_indication_xconnect_to(Id, plci, plci->RData[0].P, plci->RData[0].PLength);
  6079. break;
  6080. case LEC_UDATA_INDICATION_DISABLE_DETECT:
  6081. ec_indication(Id, plci, plci->RData[0].P, plci->RData[0].PLength);
  6082. break;
  6083. default:
  6084. break;
  6085. }
  6086. }
  6087. else
  6088. {
  6089. if ((plci->RData[0].PLength != 0)
  6090. && ((plci->B2_prot == B2_V120_ASYNC)
  6091. || (plci->B2_prot == B2_V120_ASYNC_V42BIS)
  6092. || (plci->B2_prot == B2_V120_BIT_TRANSPARENT)))
  6093. {
  6094. sendf(plci->appl, _DATA_B3_I, Id, 0,
  6095. "dwww",
  6096. plci->RData[1].P,
  6097. (plci->NL.RNum < 2) ? 0 : plci->RData[1].PLength,
  6098. plci->RNum,
  6099. plci->RFlags);
  6100. }
  6101. else
  6102. {
  6103. sendf(plci->appl, _DATA_B3_I, Id, 0,
  6104. "dwww",
  6105. plci->RData[0].P,
  6106. plci->RData[0].PLength,
  6107. plci->RNum,
  6108. plci->RFlags);
  6109. }
  6110. }
  6111. return;
  6112. }
  6113. fax_feature_bits = 0;
  6114. if ((plci->NL.Ind & 0x0f) == N_CONNECT ||
  6115. (plci->NL.Ind & 0x0f) == N_CONNECT_ACK ||
  6116. (plci->NL.Ind & 0x0f) == N_DISC ||
  6117. (plci->NL.Ind & 0x0f) == N_EDATA ||
  6118. (plci->NL.Ind & 0x0f) == N_DISC_ACK)
  6119. {
  6120. info = 0;
  6121. plci->ncpi_buffer[0] = 0;
  6122. switch (plci->B3_prot) {
  6123. case 0: /*XPARENT*/
  6124. case 1: /*T.90 NL*/
  6125. break; /* no network control protocol info - jfr */
  6126. case 2: /*ISO8202*/
  6127. case 3: /*X25 DCE*/
  6128. for (i = 0; i < plci->NL.RLength; i++) plci->ncpi_buffer[4 + i] = plci->NL.RBuffer->P[i];
  6129. plci->ncpi_buffer[0] = (byte)(i + 3);
  6130. plci->ncpi_buffer[1] = (byte)(plci->NL.Ind & N_D_BIT ? 1 : 0);
  6131. plci->ncpi_buffer[2] = 0;
  6132. plci->ncpi_buffer[3] = 0;
  6133. break;
  6134. case 4: /*T.30 - FAX*/
  6135. case 5: /*T.30 - FAX*/
  6136. if (plci->NL.RLength >= sizeof(T30_INFO))
  6137. {
  6138. dbug(1, dprintf("FaxStatus %04x", ((T30_INFO *)plci->NL.RBuffer->P)->code));
  6139. len = 9;
  6140. PUT_WORD(&(plci->ncpi_buffer[1]), ((T30_INFO *)plci->NL.RBuffer->P)->rate_div_2400 * 2400);
  6141. fax_feature_bits = GET_WORD(&((T30_INFO *)plci->NL.RBuffer->P)->feature_bits_low);
  6142. i = (((T30_INFO *)plci->NL.RBuffer->P)->resolution & T30_RESOLUTION_R8_0770_OR_200) ? 0x0001 : 0x0000;
  6143. if (plci->B3_prot == 5)
  6144. {
  6145. if (!(fax_feature_bits & T30_FEATURE_BIT_ECM))
  6146. i |= 0x8000; /* This is not an ECM connection */
  6147. if (fax_feature_bits & T30_FEATURE_BIT_T6_CODING)
  6148. i |= 0x4000; /* This is a connection with MMR compression */
  6149. if (fax_feature_bits & T30_FEATURE_BIT_2D_CODING)
  6150. i |= 0x2000; /* This is a connection with MR compression */
  6151. if (fax_feature_bits & T30_FEATURE_BIT_MORE_DOCUMENTS)
  6152. i |= 0x0004; /* More documents */
  6153. if (fax_feature_bits & T30_FEATURE_BIT_POLLING)
  6154. i |= 0x0002; /* Fax-polling indication */
  6155. }
  6156. dbug(1, dprintf("FAX Options %04x %04x", fax_feature_bits, i));
  6157. PUT_WORD(&(plci->ncpi_buffer[3]), i);
  6158. PUT_WORD(&(plci->ncpi_buffer[5]), ((T30_INFO *)plci->NL.RBuffer->P)->data_format);
  6159. plci->ncpi_buffer[7] = ((T30_INFO *)plci->NL.RBuffer->P)->pages_low;
  6160. plci->ncpi_buffer[8] = ((T30_INFO *)plci->NL.RBuffer->P)->pages_high;
  6161. plci->ncpi_buffer[len] = 0;
  6162. if (((T30_INFO *)plci->NL.RBuffer->P)->station_id_len)
  6163. {
  6164. plci->ncpi_buffer[len] = 20;
  6165. for (i = 0; i < T30_MAX_STATION_ID_LENGTH; i++)
  6166. plci->ncpi_buffer[++len] = ((T30_INFO *)plci->NL.RBuffer->P)->station_id[i];
  6167. }
  6168. if (((plci->NL.Ind & 0x0f) == N_DISC) || ((plci->NL.Ind & 0x0f) == N_DISC_ACK))
  6169. {
  6170. if (((T30_INFO *)plci->NL.RBuffer->P)->code < ARRAY_SIZE(fax_info))
  6171. info = fax_info[((T30_INFO *)plci->NL.RBuffer->P)->code];
  6172. else
  6173. info = _FAX_PROTOCOL_ERROR;
  6174. }
  6175. if ((plci->requested_options_conn | plci->requested_options | a->requested_options_table[plci->appl->Id - 1])
  6176. & ((1L << PRIVATE_FAX_SUB_SEP_PWD) | (1L << PRIVATE_FAX_NONSTANDARD)))
  6177. {
  6178. i = offsetof(T30_INFO, station_id) + T30_MAX_STATION_ID_LENGTH + ((T30_INFO *)plci->NL.RBuffer->P)->head_line_len;
  6179. while (i < plci->NL.RBuffer->length)
  6180. plci->ncpi_buffer[++len] = plci->NL.RBuffer->P[i++];
  6181. }
  6182. plci->ncpi_buffer[0] = len;
  6183. fax_feature_bits = GET_WORD(&((T30_INFO *)plci->NL.RBuffer->P)->feature_bits_low);
  6184. PUT_WORD(&((T30_INFO *)plci->fax_connect_info_buffer)->feature_bits_low, fax_feature_bits);
  6185. plci->ncpi_state |= NCPI_VALID_CONNECT_B3_IND;
  6186. if (((plci->NL.Ind & 0x0f) == N_CONNECT_ACK)
  6187. || (((plci->NL.Ind & 0x0f) == N_CONNECT)
  6188. && (fax_feature_bits & T30_FEATURE_BIT_POLLING))
  6189. || (((plci->NL.Ind & 0x0f) == N_EDATA)
  6190. && ((((T30_INFO *)plci->NL.RBuffer->P)->code == EDATA_T30_TRAIN_OK)
  6191. || (((T30_INFO *)plci->NL.RBuffer->P)->code == EDATA_T30_DIS)
  6192. || (((T30_INFO *)plci->NL.RBuffer->P)->code == EDATA_T30_DTC))))
  6193. {
  6194. plci->ncpi_state |= NCPI_VALID_CONNECT_B3_ACT;
  6195. }
  6196. if (((plci->NL.Ind & 0x0f) == N_DISC)
  6197. || ((plci->NL.Ind & 0x0f) == N_DISC_ACK)
  6198. || (((plci->NL.Ind & 0x0f) == N_EDATA)
  6199. && (((T30_INFO *)plci->NL.RBuffer->P)->code == EDATA_T30_EOP_CAPI)))
  6200. {
  6201. plci->ncpi_state |= NCPI_VALID_CONNECT_B3_ACT | NCPI_VALID_DISC_B3_IND;
  6202. }
  6203. }
  6204. break;
  6205. case B3_RTP:
  6206. if (((plci->NL.Ind & 0x0f) == N_DISC) || ((plci->NL.Ind & 0x0f) == N_DISC_ACK))
  6207. {
  6208. if (plci->NL.RLength != 0)
  6209. {
  6210. info = rtp_info[plci->NL.RBuffer->P[0]];
  6211. plci->ncpi_buffer[0] = plci->NL.RLength - 1;
  6212. for (i = 1; i < plci->NL.RLength; i++)
  6213. plci->ncpi_buffer[i] = plci->NL.RBuffer->P[i];
  6214. }
  6215. }
  6216. break;
  6217. }
  6218. plci->NL.RNR = 2;
  6219. }
  6220. switch (plci->NL.Ind & 0x0f) {
  6221. case N_EDATA:
  6222. if ((plci->B3_prot == 4) || (plci->B3_prot == 5))
  6223. {
  6224. dbug(1, dprintf("EDATA ncci=0x%x state=%d code=%02x", ncci, a->ncci_state[ncci],
  6225. ((T30_INFO *)plci->NL.RBuffer->P)->code));
  6226. fax_send_edata_ack = (((T30_INFO *)(plci->fax_connect_info_buffer))->operating_mode == T30_OPERATING_MODE_CAPI_NEG);
  6227. if ((plci->nsf_control_bits & T30_NSF_CONTROL_BIT_ENABLE_NSF)
  6228. && (plci->nsf_control_bits & (T30_NSF_CONTROL_BIT_NEGOTIATE_IND | T30_NSF_CONTROL_BIT_NEGOTIATE_RESP))
  6229. && (((T30_INFO *)plci->NL.RBuffer->P)->code == EDATA_T30_DIS)
  6230. && (a->ncci_state[ncci] == OUTG_CON_PENDING)
  6231. && (plci->ncpi_state & NCPI_VALID_CONNECT_B3_ACT)
  6232. && !(plci->ncpi_state & NCPI_NEGOTIATE_B3_SENT))
  6233. {
  6234. ((T30_INFO *)(plci->fax_connect_info_buffer))->code = ((T30_INFO *)plci->NL.RBuffer->P)->code;
  6235. sendf(plci->appl, _MANUFACTURER_I, Id, 0, "dwbS", _DI_MANU_ID, _DI_NEGOTIATE_B3,
  6236. (byte)(plci->ncpi_buffer[0] + 1), plci->ncpi_buffer);
  6237. plci->ncpi_state |= NCPI_NEGOTIATE_B3_SENT;
  6238. if (plci->nsf_control_bits & T30_NSF_CONTROL_BIT_NEGOTIATE_RESP)
  6239. fax_send_edata_ack = false;
  6240. }
  6241. if (a->manufacturer_features & MANUFACTURER_FEATURE_FAX_PAPER_FORMATS)
  6242. {
  6243. switch (((T30_INFO *)plci->NL.RBuffer->P)->code)
  6244. {
  6245. case EDATA_T30_DIS:
  6246. if ((a->ncci_state[ncci] == OUTG_CON_PENDING)
  6247. && !(GET_WORD(&((T30_INFO *)plci->fax_connect_info_buffer)->control_bits_low) & T30_CONTROL_BIT_REQUEST_POLLING)
  6248. && (plci->ncpi_state & NCPI_VALID_CONNECT_B3_ACT)
  6249. && !(plci->ncpi_state & NCPI_CONNECT_B3_ACT_SENT))
  6250. {
  6251. a->ncci_state[ncci] = INC_ACT_PENDING;
  6252. if (plci->B3_prot == 4)
  6253. sendf(plci->appl, _CONNECT_B3_ACTIVE_I, Id, 0, "s", "");
  6254. else
  6255. sendf(plci->appl, _CONNECT_B3_ACTIVE_I, Id, 0, "S", plci->ncpi_buffer);
  6256. plci->ncpi_state |= NCPI_CONNECT_B3_ACT_SENT;
  6257. }
  6258. break;
  6259. case EDATA_T30_TRAIN_OK:
  6260. if ((a->ncci_state[ncci] == INC_ACT_PENDING)
  6261. && (plci->ncpi_state & NCPI_VALID_CONNECT_B3_ACT)
  6262. && !(plci->ncpi_state & NCPI_CONNECT_B3_ACT_SENT))
  6263. {
  6264. if (plci->B3_prot == 4)
  6265. sendf(plci->appl, _CONNECT_B3_ACTIVE_I, Id, 0, "s", "");
  6266. else
  6267. sendf(plci->appl, _CONNECT_B3_ACTIVE_I, Id, 0, "S", plci->ncpi_buffer);
  6268. plci->ncpi_state |= NCPI_CONNECT_B3_ACT_SENT;
  6269. }
  6270. break;
  6271. case EDATA_T30_EOP_CAPI:
  6272. if (a->ncci_state[ncci] == CONNECTED)
  6273. {
  6274. sendf(plci->appl, _DISCONNECT_B3_I, Id, 0, "wS", GOOD, plci->ncpi_buffer);
  6275. a->ncci_state[ncci] = INC_DIS_PENDING;
  6276. plci->ncpi_state = 0;
  6277. fax_send_edata_ack = false;
  6278. }
  6279. break;
  6280. }
  6281. }
  6282. else
  6283. {
  6284. switch (((T30_INFO *)plci->NL.RBuffer->P)->code)
  6285. {
  6286. case EDATA_T30_TRAIN_OK:
  6287. if ((a->ncci_state[ncci] == INC_ACT_PENDING)
  6288. && (plci->ncpi_state & NCPI_VALID_CONNECT_B3_ACT)
  6289. && !(plci->ncpi_state & NCPI_CONNECT_B3_ACT_SENT))
  6290. {
  6291. if (plci->B3_prot == 4)
  6292. sendf(plci->appl, _CONNECT_B3_ACTIVE_I, Id, 0, "s", "");
  6293. else
  6294. sendf(plci->appl, _CONNECT_B3_ACTIVE_I, Id, 0, "S", plci->ncpi_buffer);
  6295. plci->ncpi_state |= NCPI_CONNECT_B3_ACT_SENT;
  6296. }
  6297. break;
  6298. }
  6299. }
  6300. if (fax_send_edata_ack)
  6301. {
  6302. ((T30_INFO *)(plci->fax_connect_info_buffer))->code = ((T30_INFO *)plci->NL.RBuffer->P)->code;
  6303. plci->fax_edata_ack_length = 1;
  6304. start_internal_command(Id, plci, fax_edata_ack_command);
  6305. }
  6306. }
  6307. else
  6308. {
  6309. dbug(1, dprintf("EDATA ncci=0x%x state=%d", ncci, a->ncci_state[ncci]));
  6310. }
  6311. break;
  6312. case N_CONNECT:
  6313. if (!a->ch_ncci[ch])
  6314. {
  6315. ncci = get_ncci(plci, ch, 0);
  6316. Id = (Id & 0xffff) | (((dword) ncci) << 16);
  6317. }
  6318. dbug(1, dprintf("N_CONNECT: ch=%d state=%d plci=%lx plci_Id=%lx plci_State=%d",
  6319. ch, a->ncci_state[ncci], a->ncci_plci[ncci], plci->Id, plci->State));
  6320. msg = _CONNECT_B3_I;
  6321. if (a->ncci_state[ncci] == IDLE)
  6322. plci->channels++;
  6323. else if (plci->B3_prot == 1)
  6324. msg = _CONNECT_B3_T90_ACTIVE_I;
  6325. a->ncci_state[ncci] = INC_CON_PENDING;
  6326. if (plci->B3_prot == 4)
  6327. sendf(plci->appl, msg, Id, 0, "s", "");
  6328. else
  6329. sendf(plci->appl, msg, Id, 0, "S", plci->ncpi_buffer);
  6330. break;
  6331. case N_CONNECT_ACK:
  6332. dbug(1, dprintf("N_connect_Ack"));
  6333. if (plci->internal_command_queue[0]
  6334. && ((plci->adjust_b_state == ADJUST_B_CONNECT_2)
  6335. || (plci->adjust_b_state == ADJUST_B_CONNECT_3)
  6336. || (plci->adjust_b_state == ADJUST_B_CONNECT_4)))
  6337. {
  6338. (*(plci->internal_command_queue[0]))(Id, plci, 0);
  6339. if (!plci->internal_command)
  6340. next_internal_command(Id, plci);
  6341. break;
  6342. }
  6343. msg = _CONNECT_B3_ACTIVE_I;
  6344. if (plci->B3_prot == 1)
  6345. {
  6346. if (a->ncci_state[ncci] != OUTG_CON_PENDING)
  6347. msg = _CONNECT_B3_T90_ACTIVE_I;
  6348. a->ncci_state[ncci] = INC_ACT_PENDING;
  6349. sendf(plci->appl, msg, Id, 0, "S", plci->ncpi_buffer);
  6350. }
  6351. else if ((plci->B3_prot == 4) || (plci->B3_prot == 5) || (plci->B3_prot == 7))
  6352. {
  6353. if ((a->ncci_state[ncci] == OUTG_CON_PENDING)
  6354. && (plci->ncpi_state & NCPI_VALID_CONNECT_B3_ACT)
  6355. && !(plci->ncpi_state & NCPI_CONNECT_B3_ACT_SENT))
  6356. {
  6357. a->ncci_state[ncci] = INC_ACT_PENDING;
  6358. if (plci->B3_prot == 4)
  6359. sendf(plci->appl, msg, Id, 0, "s", "");
  6360. else
  6361. sendf(plci->appl, msg, Id, 0, "S", plci->ncpi_buffer);
  6362. plci->ncpi_state |= NCPI_CONNECT_B3_ACT_SENT;
  6363. }
  6364. }
  6365. else
  6366. {
  6367. a->ncci_state[ncci] = INC_ACT_PENDING;
  6368. sendf(plci->appl, msg, Id, 0, "S", plci->ncpi_buffer);
  6369. }
  6370. if (plci->adjust_b_restore)
  6371. {
  6372. plci->adjust_b_restore = false;
  6373. start_internal_command(Id, plci, adjust_b_restore);
  6374. }
  6375. break;
  6376. case N_DISC:
  6377. case N_DISC_ACK:
  6378. if (plci->internal_command_queue[0]
  6379. && ((plci->internal_command == FAX_DISCONNECT_COMMAND_1)
  6380. || (plci->internal_command == FAX_DISCONNECT_COMMAND_2)
  6381. || (plci->internal_command == FAX_DISCONNECT_COMMAND_3)))
  6382. {
  6383. (*(plci->internal_command_queue[0]))(Id, plci, 0);
  6384. if (!plci->internal_command)
  6385. next_internal_command(Id, plci);
  6386. }
  6387. ncci_state = a->ncci_state[ncci];
  6388. ncci_remove(plci, ncci, false);
  6389. /* with N_DISC or N_DISC_ACK the IDI frees the respective */
  6390. /* channel, so we cannot store the state in ncci_state! The */
  6391. /* information which channel we received a N_DISC is thus */
  6392. /* stored in the inc_dis_ncci_table buffer. */
  6393. for (i = 0; plci->inc_dis_ncci_table[i]; i++);
  6394. plci->inc_dis_ncci_table[i] = (byte) ncci;
  6395. /* need a connect_b3_ind before a disconnect_b3_ind with FAX */
  6396. if (!plci->channels
  6397. && (plci->B1_resource == 16)
  6398. && (plci->State <= CONNECTED))
  6399. {
  6400. len = 9;
  6401. i = ((T30_INFO *)plci->fax_connect_info_buffer)->rate_div_2400 * 2400;
  6402. PUT_WORD(&plci->ncpi_buffer[1], i);
  6403. PUT_WORD(&plci->ncpi_buffer[3], 0);
  6404. i = ((T30_INFO *)plci->fax_connect_info_buffer)->data_format;
  6405. PUT_WORD(&plci->ncpi_buffer[5], i);
  6406. PUT_WORD(&plci->ncpi_buffer[7], 0);
  6407. plci->ncpi_buffer[len] = 0;
  6408. plci->ncpi_buffer[0] = len;
  6409. if (plci->B3_prot == 4)
  6410. sendf(plci->appl, _CONNECT_B3_I, Id, 0, "s", "");
  6411. else
  6412. {
  6413. if ((plci->requested_options_conn | plci->requested_options | a->requested_options_table[plci->appl->Id - 1])
  6414. & ((1L << PRIVATE_FAX_SUB_SEP_PWD) | (1L << PRIVATE_FAX_NONSTANDARD)))
  6415. {
  6416. plci->ncpi_buffer[++len] = 0;
  6417. plci->ncpi_buffer[++len] = 0;
  6418. plci->ncpi_buffer[++len] = 0;
  6419. plci->ncpi_buffer[0] = len;
  6420. }
  6421. sendf(plci->appl, _CONNECT_B3_I, Id, 0, "S", plci->ncpi_buffer);
  6422. }
  6423. sendf(plci->appl, _DISCONNECT_B3_I, Id, 0, "wS", info, plci->ncpi_buffer);
  6424. plci->ncpi_state = 0;
  6425. sig_req(plci, HANGUP, 0);
  6426. send_req(plci);
  6427. plci->State = OUTG_DIS_PENDING;
  6428. /* disc here */
  6429. }
  6430. else if ((a->manufacturer_features & MANUFACTURER_FEATURE_FAX_PAPER_FORMATS)
  6431. && ((plci->B3_prot == 4) || (plci->B3_prot == 5))
  6432. && ((ncci_state == INC_DIS_PENDING) || (ncci_state == IDLE)))
  6433. {
  6434. if (ncci_state == IDLE)
  6435. {
  6436. if (plci->channels)
  6437. plci->channels--;
  6438. if ((plci->State == IDLE || plci->State == SUSPENDING) && !plci->channels) {
  6439. if (plci->State == SUSPENDING) {
  6440. sendf(plci->appl,
  6441. _FACILITY_I,
  6442. Id & 0xffffL,
  6443. 0,
  6444. "ws", (word)3, "\x03\x04\x00\x00");
  6445. sendf(plci->appl, _DISCONNECT_I, Id & 0xffffL, 0, "w", 0);
  6446. }
  6447. plci_remove(plci);
  6448. plci->State = IDLE;
  6449. }
  6450. }
  6451. }
  6452. else if (plci->channels)
  6453. {
  6454. sendf(plci->appl, _DISCONNECT_B3_I, Id, 0, "wS", info, plci->ncpi_buffer);
  6455. plci->ncpi_state = 0;
  6456. if ((ncci_state == OUTG_REJ_PENDING)
  6457. && ((plci->B3_prot != B3_T90NL) && (plci->B3_prot != B3_ISO8208) && (plci->B3_prot != B3_X25_DCE)))
  6458. {
  6459. sig_req(plci, HANGUP, 0);
  6460. send_req(plci);
  6461. plci->State = OUTG_DIS_PENDING;
  6462. }
  6463. }
  6464. break;
  6465. case N_RESET:
  6466. a->ncci_state[ncci] = INC_RES_PENDING;
  6467. sendf(plci->appl, _RESET_B3_I, Id, 0, "S", plci->ncpi_buffer);
  6468. break;
  6469. case N_RESET_ACK:
  6470. a->ncci_state[ncci] = CONNECTED;
  6471. sendf(plci->appl, _RESET_B3_I, Id, 0, "S", plci->ncpi_buffer);
  6472. break;
  6473. case N_UDATA:
  6474. if (!(udata_forwarding_table[plci->NL.RBuffer->P[0] >> 5] & (1L << (plci->NL.RBuffer->P[0] & 0x1f))))
  6475. {
  6476. plci->RData[0].P = plci->internal_ind_buffer + (-((int)(long)(plci->internal_ind_buffer)) & 3);
  6477. plci->RData[0].PLength = INTERNAL_IND_BUFFER_SIZE;
  6478. plci->NL.R = plci->RData;
  6479. plci->NL.RNum = 1;
  6480. return;
  6481. }
  6482. /* fall through */
  6483. case N_BDATA:
  6484. case N_DATA:
  6485. if (((a->ncci_state[ncci] != CONNECTED) && (plci->B2_prot == 1)) /* transparent */
  6486. || (a->ncci_state[ncci] == IDLE)
  6487. || (a->ncci_state[ncci] == INC_DIS_PENDING))
  6488. {
  6489. plci->NL.RNR = 2;
  6490. break;
  6491. }
  6492. if ((a->ncci_state[ncci] != CONNECTED)
  6493. && (a->ncci_state[ncci] != OUTG_DIS_PENDING)
  6494. && (a->ncci_state[ncci] != OUTG_REJ_PENDING))
  6495. {
  6496. dbug(1, dprintf("flow control"));
  6497. plci->NL.RNR = 1; /* flow control */
  6498. channel_x_off(plci, ch, 0);
  6499. break;
  6500. }
  6501. NCCIcode = ncci | (((word)a->Id) << 8);
  6502. /* count all buffers within the Application pool */
  6503. /* belonging to the same NCCI. If this is below the */
  6504. /* number of buffers available per NCCI we accept */
  6505. /* this packet, otherwise we reject it */
  6506. count = 0;
  6507. Num = 0xffff;
  6508. for (i = 0; i < APPLptr->MaxBuffer; i++) {
  6509. if (NCCIcode == APPLptr->DataNCCI[i]) count++;
  6510. if (!APPLptr->DataNCCI[i] && Num == 0xffff) Num = i;
  6511. }
  6512. if (count >= APPLptr->MaxNCCIData || Num == 0xffff)
  6513. {
  6514. dbug(3, dprintf("Flow-Control"));
  6515. plci->NL.RNR = 1;
  6516. if (++(APPLptr->NCCIDataFlowCtrlTimer) >=
  6517. (word)((a->manufacturer_features & MANUFACTURER_FEATURE_OOB_CHANNEL) ? 40 : 2000))
  6518. {
  6519. plci->NL.RNR = 2;
  6520. dbug(3, dprintf("DiscardData"));
  6521. } else {
  6522. channel_x_off(plci, ch, 0);
  6523. }
  6524. break;
  6525. }
  6526. else
  6527. {
  6528. APPLptr->NCCIDataFlowCtrlTimer = 0;
  6529. }
  6530. plci->RData[0].P = ReceiveBufferGet(APPLptr, Num);
  6531. if (!plci->RData[0].P) {
  6532. plci->NL.RNR = 1;
  6533. channel_x_off(plci, ch, 0);
  6534. break;
  6535. }
  6536. APPLptr->DataNCCI[Num] = NCCIcode;
  6537. APPLptr->DataFlags[Num] = (plci->Id << 8) | (plci->NL.Ind >> 4);
  6538. dbug(3, dprintf("Buffer(%d), Max = %d", Num, APPLptr->MaxBuffer));
  6539. plci->RNum = Num;
  6540. plci->RFlags = plci->NL.Ind >> 4;
  6541. plci->RData[0].PLength = APPLptr->MaxDataLength;
  6542. plci->NL.R = plci->RData;
  6543. if ((plci->NL.RLength != 0)
  6544. && ((plci->B2_prot == B2_V120_ASYNC)
  6545. || (plci->B2_prot == B2_V120_ASYNC_V42BIS)
  6546. || (plci->B2_prot == B2_V120_BIT_TRANSPARENT)))
  6547. {
  6548. plci->RData[1].P = plci->RData[0].P;
  6549. plci->RData[1].PLength = plci->RData[0].PLength;
  6550. plci->RData[0].P = v120_header_buffer + (-((unsigned long)v120_header_buffer) & 3);
  6551. if ((plci->NL.RBuffer->P[0] & V120_HEADER_EXTEND_BIT) || (plci->NL.RLength == 1))
  6552. plci->RData[0].PLength = 1;
  6553. else
  6554. plci->RData[0].PLength = 2;
  6555. if (plci->NL.RBuffer->P[0] & V120_HEADER_BREAK_BIT)
  6556. plci->RFlags |= 0x0010;
  6557. if (plci->NL.RBuffer->P[0] & (V120_HEADER_C1_BIT | V120_HEADER_C2_BIT))
  6558. plci->RFlags |= 0x8000;
  6559. plci->NL.RNum = 2;
  6560. }
  6561. else
  6562. {
  6563. if ((plci->NL.Ind & 0x0f) == N_UDATA)
  6564. plci->RFlags |= 0x0010;
  6565. else if ((plci->B3_prot == B3_RTP) && ((plci->NL.Ind & 0x0f) == N_BDATA))
  6566. plci->RFlags |= 0x0001;
  6567. plci->NL.RNum = 1;
  6568. }
  6569. break;
  6570. case N_DATA_ACK:
  6571. data_ack(plci, ch);
  6572. break;
  6573. default:
  6574. plci->NL.RNR = 2;
  6575. break;
  6576. }
  6577. }
  6578. /*------------------------------------------------------------------*/
  6579. /* find a free PLCI */
  6580. /*------------------------------------------------------------------*/
  6581. static word get_plci(DIVA_CAPI_ADAPTER *a)
  6582. {
  6583. word i, j;
  6584. PLCI *plci;
  6585. for (i = 0; i < a->max_plci && a->plci[i].Id; i++);
  6586. if (i == a->max_plci) {
  6587. dbug(1, dprintf("get_plci: out of PLCIs"));
  6588. return 0;
  6589. }
  6590. plci = &a->plci[i];
  6591. plci->Id = (byte)(i + 1);
  6592. plci->Sig.Id = 0;
  6593. plci->NL.Id = 0;
  6594. plci->sig_req = 0;
  6595. plci->nl_req = 0;
  6596. plci->appl = NULL;
  6597. plci->relatedPTYPLCI = NULL;
  6598. plci->State = IDLE;
  6599. plci->SuppState = IDLE;
  6600. plci->channels = 0;
  6601. plci->tel = 0;
  6602. plci->B1_resource = 0;
  6603. plci->B2_prot = 0;
  6604. plci->B3_prot = 0;
  6605. plci->command = 0;
  6606. plci->m_command = 0;
  6607. init_internal_command_queue(plci);
  6608. plci->number = 0;
  6609. plci->req_in_start = 0;
  6610. plci->req_in = 0;
  6611. plci->req_out = 0;
  6612. plci->msg_in_write_pos = MSG_IN_QUEUE_SIZE;
  6613. plci->msg_in_read_pos = MSG_IN_QUEUE_SIZE;
  6614. plci->msg_in_wrap_pos = MSG_IN_QUEUE_SIZE;
  6615. plci->data_sent = false;
  6616. plci->send_disc = 0;
  6617. plci->sig_global_req = 0;
  6618. plci->sig_remove_id = 0;
  6619. plci->nl_global_req = 0;
  6620. plci->nl_remove_id = 0;
  6621. plci->adv_nl = 0;
  6622. plci->manufacturer = false;
  6623. plci->call_dir = CALL_DIR_OUT | CALL_DIR_ORIGINATE;
  6624. plci->spoofed_msg = 0;
  6625. plci->ptyState = 0;
  6626. plci->cr_enquiry = false;
  6627. plci->hangup_flow_ctrl_timer = 0;
  6628. plci->ncci_ring_list = 0;
  6629. for (j = 0; j < MAX_CHANNELS_PER_PLCI; j++) plci->inc_dis_ncci_table[j] = 0;
  6630. bitmap_zero(plci->c_ind_mask_table, MAX_APPL);
  6631. bitmap_fill(plci->group_optimization_mask_table, MAX_APPL);
  6632. plci->fax_connect_info_length = 0;
  6633. plci->nsf_control_bits = 0;
  6634. plci->ncpi_state = 0x00;
  6635. plci->ncpi_buffer[0] = 0;
  6636. plci->requested_options_conn = 0;
  6637. plci->requested_options = 0;
  6638. plci->notifiedcall = 0;
  6639. plci->vswitchstate = 0;
  6640. plci->vsprot = 0;
  6641. plci->vsprotdialect = 0;
  6642. init_b1_config(plci);
  6643. dbug(1, dprintf("get_plci(%x)", plci->Id));
  6644. return i + 1;
  6645. }
  6646. /*------------------------------------------------------------------*/
  6647. /* put a parameter in the parameter buffer */
  6648. /*------------------------------------------------------------------*/
  6649. static void add_p(PLCI *plci, byte code, byte *p)
  6650. {
  6651. word p_length;
  6652. p_length = 0;
  6653. if (p) p_length = p[0];
  6654. add_ie(plci, code, p, p_length);
  6655. }
  6656. /*------------------------------------------------------------------*/
  6657. /* put a structure in the parameter buffer */
  6658. /*------------------------------------------------------------------*/
  6659. static void add_s(PLCI *plci, byte code, API_PARSE *p)
  6660. {
  6661. if (p) add_ie(plci, code, p->info, (word)p->length);
  6662. }
  6663. /*------------------------------------------------------------------*/
  6664. /* put multiple structures in the parameter buffer */
  6665. /*------------------------------------------------------------------*/
  6666. static void add_ss(PLCI *plci, byte code, API_PARSE *p)
  6667. {
  6668. byte i;
  6669. if (p) {
  6670. dbug(1, dprintf("add_ss(%x,len=%d)", code, p->length));
  6671. for (i = 2; i < (byte)p->length; i += p->info[i] + 2) {
  6672. dbug(1, dprintf("add_ss_ie(%x,len=%d)", p->info[i - 1], p->info[i]));
  6673. add_ie(plci, p->info[i - 1], (byte *)&(p->info[i]), (word)p->info[i]);
  6674. }
  6675. }
  6676. }
  6677. /*------------------------------------------------------------------*/
  6678. /* return the channel number sent by the application in a esc_chi */
  6679. /*------------------------------------------------------------------*/
  6680. static byte getChannel(API_PARSE *p)
  6681. {
  6682. byte i;
  6683. if (p) {
  6684. for (i = 2; i < (byte)p->length; i += p->info[i] + 2) {
  6685. if (p->info[i] == 2) {
  6686. if (p->info[i - 1] == ESC && p->info[i + 1] == CHI) return (p->info[i + 2]);
  6687. }
  6688. }
  6689. }
  6690. return 0;
  6691. }
  6692. /*------------------------------------------------------------------*/
  6693. /* put an information element in the parameter buffer */
  6694. /*------------------------------------------------------------------*/
  6695. static void add_ie(PLCI *plci, byte code, byte *p, word p_length)
  6696. {
  6697. word i;
  6698. if (!(code & 0x80) && !p_length) return;
  6699. if (plci->req_in == plci->req_in_start) {
  6700. plci->req_in += 2;
  6701. }
  6702. else {
  6703. plci->req_in--;
  6704. }
  6705. plci->RBuffer[plci->req_in++] = code;
  6706. if (p) {
  6707. plci->RBuffer[plci->req_in++] = (byte)p_length;
  6708. for (i = 0; i < p_length; i++) plci->RBuffer[plci->req_in++] = p[1 + i];
  6709. }
  6710. plci->RBuffer[plci->req_in++] = 0;
  6711. }
  6712. /*------------------------------------------------------------------*/
  6713. /* put a unstructured data into the buffer */
  6714. /*------------------------------------------------------------------*/
  6715. static void add_d(PLCI *plci, word length, byte *p)
  6716. {
  6717. word i;
  6718. if (plci->req_in == plci->req_in_start) {
  6719. plci->req_in += 2;
  6720. }
  6721. else {
  6722. plci->req_in--;
  6723. }
  6724. for (i = 0; i < length; i++) plci->RBuffer[plci->req_in++] = p[i];
  6725. }
  6726. /*------------------------------------------------------------------*/
  6727. /* put parameters from the Additional Info parameter in the */
  6728. /* parameter buffer */
  6729. /*------------------------------------------------------------------*/
  6730. static void add_ai(PLCI *plci, API_PARSE *ai)
  6731. {
  6732. word i;
  6733. API_PARSE ai_parms[5];
  6734. for (i = 0; i < 5; i++) ai_parms[i].length = 0;
  6735. if (!ai->length)
  6736. return;
  6737. if (api_parse(&ai->info[1], (word)ai->length, "ssss", ai_parms))
  6738. return;
  6739. add_s(plci, KEY, &ai_parms[1]);
  6740. add_s(plci, UUI, &ai_parms[2]);
  6741. add_ss(plci, FTY, &ai_parms[3]);
  6742. }
  6743. /*------------------------------------------------------------------*/
  6744. /* put parameter for b1 protocol in the parameter buffer */
  6745. /*------------------------------------------------------------------*/
  6746. static word add_b1(PLCI *plci, API_PARSE *bp, word b_channel_info,
  6747. word b1_facilities)
  6748. {
  6749. API_PARSE bp_parms[8];
  6750. API_PARSE mdm_cfg[9];
  6751. API_PARSE global_config[2];
  6752. byte cai[256];
  6753. byte resource[] = {5, 9, 13, 12, 16, 39, 9, 17, 17, 18};
  6754. byte voice_cai[] = "\x06\x14\x00\x00\x00\x00\x08";
  6755. word i;
  6756. API_PARSE mdm_cfg_v18[4];
  6757. word j, n, w;
  6758. dword d;
  6759. for (i = 0; i < 8; i++) bp_parms[i].length = 0;
  6760. for (i = 0; i < 2; i++) global_config[i].length = 0;
  6761. dbug(1, dprintf("add_b1"));
  6762. api_save_msg(bp, "s", &plci->B_protocol);
  6763. if (b_channel_info == 2) {
  6764. plci->B1_resource = 0;
  6765. adjust_b1_facilities(plci, plci->B1_resource, b1_facilities);
  6766. add_p(plci, CAI, "\x01\x00");
  6767. dbug(1, dprintf("Cai=1,0 (no resource)"));
  6768. return 0;
  6769. }
  6770. if (plci->tel == CODEC_PERMANENT) return 0;
  6771. else if (plci->tel == CODEC) {
  6772. plci->B1_resource = 1;
  6773. adjust_b1_facilities(plci, plci->B1_resource, b1_facilities);
  6774. add_p(plci, CAI, "\x01\x01");
  6775. dbug(1, dprintf("Cai=1,1 (Codec)"));
  6776. return 0;
  6777. }
  6778. else if (plci->tel == ADV_VOICE) {
  6779. plci->B1_resource = add_b1_facilities(plci, 9, (word)(b1_facilities | B1_FACILITY_VOICE));
  6780. adjust_b1_facilities(plci, plci->B1_resource, (word)(b1_facilities | B1_FACILITY_VOICE));
  6781. voice_cai[1] = plci->B1_resource;
  6782. PUT_WORD(&voice_cai[5], plci->appl->MaxDataLength);
  6783. add_p(plci, CAI, voice_cai);
  6784. dbug(1, dprintf("Cai=1,0x%x (AdvVoice)", voice_cai[1]));
  6785. return 0;
  6786. }
  6787. plci->call_dir &= ~(CALL_DIR_ORIGINATE | CALL_DIR_ANSWER);
  6788. if (plci->call_dir & CALL_DIR_OUT)
  6789. plci->call_dir |= CALL_DIR_ORIGINATE;
  6790. else if (plci->call_dir & CALL_DIR_IN)
  6791. plci->call_dir |= CALL_DIR_ANSWER;
  6792. if (!bp->length) {
  6793. plci->B1_resource = 0x5;
  6794. adjust_b1_facilities(plci, plci->B1_resource, b1_facilities);
  6795. add_p(plci, CAI, "\x01\x05");
  6796. return 0;
  6797. }
  6798. dbug(1, dprintf("b_prot_len=%d", (word)bp->length));
  6799. if (bp->length > 256) return _WRONG_MESSAGE_FORMAT;
  6800. if (api_parse(&bp->info[1], (word)bp->length, "wwwsssb", bp_parms))
  6801. {
  6802. bp_parms[6].length = 0;
  6803. if (api_parse(&bp->info[1], (word)bp->length, "wwwsss", bp_parms))
  6804. {
  6805. dbug(1, dprintf("b-form.!"));
  6806. return _WRONG_MESSAGE_FORMAT;
  6807. }
  6808. }
  6809. else if (api_parse(&bp->info[1], (word)bp->length, "wwwssss", bp_parms))
  6810. {
  6811. dbug(1, dprintf("b-form.!"));
  6812. return _WRONG_MESSAGE_FORMAT;
  6813. }
  6814. if (bp_parms[6].length)
  6815. {
  6816. if (api_parse(&bp_parms[6].info[1], (word)bp_parms[6].length, "w", global_config))
  6817. {
  6818. return _WRONG_MESSAGE_FORMAT;
  6819. }
  6820. switch (GET_WORD(global_config[0].info))
  6821. {
  6822. case 1:
  6823. plci->call_dir = (plci->call_dir & ~CALL_DIR_ANSWER) | CALL_DIR_ORIGINATE;
  6824. break;
  6825. case 2:
  6826. plci->call_dir = (plci->call_dir & ~CALL_DIR_ORIGINATE) | CALL_DIR_ANSWER;
  6827. break;
  6828. }
  6829. }
  6830. dbug(1, dprintf("call_dir=%04x", plci->call_dir));
  6831. if ((GET_WORD(bp_parms[0].info) == B1_RTP)
  6832. && (plci->adapter->man_profile.private_options & (1L << PRIVATE_RTP)))
  6833. {
  6834. plci->B1_resource = add_b1_facilities(plci, 31, (word)(b1_facilities & ~B1_FACILITY_VOICE));
  6835. adjust_b1_facilities(plci, plci->B1_resource, (word)(b1_facilities & ~B1_FACILITY_VOICE));
  6836. cai[1] = plci->B1_resource;
  6837. cai[2] = 0;
  6838. cai[3] = 0;
  6839. cai[4] = 0;
  6840. PUT_WORD(&cai[5], plci->appl->MaxDataLength);
  6841. for (i = 0; i < bp_parms[3].length; i++)
  6842. cai[7 + i] = bp_parms[3].info[1 + i];
  6843. cai[0] = 6 + bp_parms[3].length;
  6844. add_p(plci, CAI, cai);
  6845. return 0;
  6846. }
  6847. if ((GET_WORD(bp_parms[0].info) == B1_PIAFS)
  6848. && (plci->adapter->man_profile.private_options & (1L << PRIVATE_PIAFS)))
  6849. {
  6850. plci->B1_resource = add_b1_facilities(plci, 35/* PIAFS HARDWARE FACILITY */, (word)(b1_facilities & ~B1_FACILITY_VOICE));
  6851. adjust_b1_facilities(plci, plci->B1_resource, (word)(b1_facilities & ~B1_FACILITY_VOICE));
  6852. cai[1] = plci->B1_resource;
  6853. cai[2] = 0;
  6854. cai[3] = 0;
  6855. cai[4] = 0;
  6856. PUT_WORD(&cai[5], plci->appl->MaxDataLength);
  6857. cai[0] = 6;
  6858. add_p(plci, CAI, cai);
  6859. return 0;
  6860. }
  6861. if ((GET_WORD(bp_parms[0].info) >= 32)
  6862. || (!((1L << GET_WORD(bp_parms[0].info)) & plci->adapter->profile.B1_Protocols)
  6863. && ((GET_WORD(bp_parms[0].info) != 3)
  6864. || !((1L << B1_HDLC) & plci->adapter->profile.B1_Protocols)
  6865. || ((bp_parms[3].length != 0) && (GET_WORD(&bp_parms[3].info[1]) != 0) && (GET_WORD(&bp_parms[3].info[1]) != 56000)))))
  6866. {
  6867. return _B1_NOT_SUPPORTED;
  6868. }
  6869. plci->B1_resource = add_b1_facilities(plci, resource[GET_WORD(bp_parms[0].info)],
  6870. (word)(b1_facilities & ~B1_FACILITY_VOICE));
  6871. adjust_b1_facilities(plci, plci->B1_resource, (word)(b1_facilities & ~B1_FACILITY_VOICE));
  6872. cai[0] = 6;
  6873. cai[1] = plci->B1_resource;
  6874. for (i = 2; i < sizeof(cai); i++) cai[i] = 0;
  6875. if ((GET_WORD(bp_parms[0].info) == B1_MODEM_ALL_NEGOTIATE)
  6876. || (GET_WORD(bp_parms[0].info) == B1_MODEM_ASYNC)
  6877. || (GET_WORD(bp_parms[0].info) == B1_MODEM_SYNC_HDLC))
  6878. { /* B1 - modem */
  6879. for (i = 0; i < 7; i++) mdm_cfg[i].length = 0;
  6880. if (bp_parms[3].length)
  6881. {
  6882. if (api_parse(&bp_parms[3].info[1], (word)bp_parms[3].length, "wwwwww", mdm_cfg))
  6883. {
  6884. return (_WRONG_MESSAGE_FORMAT);
  6885. }
  6886. cai[2] = 0; /* Bit rate for adaptation */
  6887. dbug(1, dprintf("MDM Max Bit Rate:<%d>", GET_WORD(mdm_cfg[0].info)));
  6888. PUT_WORD(&cai[13], 0); /* Min Tx speed */
  6889. PUT_WORD(&cai[15], GET_WORD(mdm_cfg[0].info)); /* Max Tx speed */
  6890. PUT_WORD(&cai[17], 0); /* Min Rx speed */
  6891. PUT_WORD(&cai[19], GET_WORD(mdm_cfg[0].info)); /* Max Rx speed */
  6892. cai[3] = 0; /* Async framing parameters */
  6893. switch (GET_WORD(mdm_cfg[2].info))
  6894. { /* Parity */
  6895. case 1: /* odd parity */
  6896. cai[3] |= (DSP_CAI_ASYNC_PARITY_ENABLE | DSP_CAI_ASYNC_PARITY_ODD);
  6897. dbug(1, dprintf("MDM: odd parity"));
  6898. break;
  6899. case 2: /* even parity */
  6900. cai[3] |= (DSP_CAI_ASYNC_PARITY_ENABLE | DSP_CAI_ASYNC_PARITY_EVEN);
  6901. dbug(1, dprintf("MDM: even parity"));
  6902. break;
  6903. default:
  6904. dbug(1, dprintf("MDM: no parity"));
  6905. break;
  6906. }
  6907. switch (GET_WORD(mdm_cfg[3].info))
  6908. { /* stop bits */
  6909. case 1: /* 2 stop bits */
  6910. cai[3] |= DSP_CAI_ASYNC_TWO_STOP_BITS;
  6911. dbug(1, dprintf("MDM: 2 stop bits"));
  6912. break;
  6913. default:
  6914. dbug(1, dprintf("MDM: 1 stop bit"));
  6915. break;
  6916. }
  6917. switch (GET_WORD(mdm_cfg[1].info))
  6918. { /* char length */
  6919. case 5:
  6920. cai[3] |= DSP_CAI_ASYNC_CHAR_LENGTH_5;
  6921. dbug(1, dprintf("MDM: 5 bits"));
  6922. break;
  6923. case 6:
  6924. cai[3] |= DSP_CAI_ASYNC_CHAR_LENGTH_6;
  6925. dbug(1, dprintf("MDM: 6 bits"));
  6926. break;
  6927. case 7:
  6928. cai[3] |= DSP_CAI_ASYNC_CHAR_LENGTH_7;
  6929. dbug(1, dprintf("MDM: 7 bits"));
  6930. break;
  6931. default:
  6932. dbug(1, dprintf("MDM: 8 bits"));
  6933. break;
  6934. }
  6935. cai[7] = 0; /* Line taking options */
  6936. cai[8] = 0; /* Modulation negotiation options */
  6937. cai[9] = 0; /* Modulation options */
  6938. if (((plci->call_dir & CALL_DIR_ORIGINATE) != 0) ^ ((plci->call_dir & CALL_DIR_OUT) != 0))
  6939. {
  6940. cai[9] |= DSP_CAI_MODEM_REVERSE_DIRECTION;
  6941. dbug(1, dprintf("MDM: Reverse direction"));
  6942. }
  6943. if (GET_WORD(mdm_cfg[4].info) & MDM_CAPI_DISABLE_RETRAIN)
  6944. {
  6945. cai[9] |= DSP_CAI_MODEM_DISABLE_RETRAIN;
  6946. dbug(1, dprintf("MDM: Disable retrain"));
  6947. }
  6948. if (GET_WORD(mdm_cfg[4].info) & MDM_CAPI_DISABLE_RING_TONE)
  6949. {
  6950. cai[7] |= DSP_CAI_MODEM_DISABLE_CALLING_TONE | DSP_CAI_MODEM_DISABLE_ANSWER_TONE;
  6951. dbug(1, dprintf("MDM: Disable ring tone"));
  6952. }
  6953. if (GET_WORD(mdm_cfg[4].info) & MDM_CAPI_GUARD_1800)
  6954. {
  6955. cai[8] |= DSP_CAI_MODEM_GUARD_TONE_1800HZ;
  6956. dbug(1, dprintf("MDM: 1800 guard tone"));
  6957. }
  6958. else if (GET_WORD(mdm_cfg[4].info) & MDM_CAPI_GUARD_550)
  6959. {
  6960. cai[8] |= DSP_CAI_MODEM_GUARD_TONE_550HZ;
  6961. dbug(1, dprintf("MDM: 550 guard tone"));
  6962. }
  6963. if ((GET_WORD(mdm_cfg[5].info) & 0x00ff) == MDM_CAPI_NEG_V100)
  6964. {
  6965. cai[8] |= DSP_CAI_MODEM_NEGOTIATE_V100;
  6966. dbug(1, dprintf("MDM: V100"));
  6967. }
  6968. else if ((GET_WORD(mdm_cfg[5].info) & 0x00ff) == MDM_CAPI_NEG_MOD_CLASS)
  6969. {
  6970. cai[8] |= DSP_CAI_MODEM_NEGOTIATE_IN_CLASS;
  6971. dbug(1, dprintf("MDM: IN CLASS"));
  6972. }
  6973. else if ((GET_WORD(mdm_cfg[5].info) & 0x00ff) == MDM_CAPI_NEG_DISABLED)
  6974. {
  6975. cai[8] |= DSP_CAI_MODEM_NEGOTIATE_DISABLED;
  6976. dbug(1, dprintf("MDM: DISABLED"));
  6977. }
  6978. cai[0] = 20;
  6979. if ((plci->adapter->man_profile.private_options & (1L << PRIVATE_V18))
  6980. && (GET_WORD(mdm_cfg[5].info) & 0x8000)) /* Private V.18 enable */
  6981. {
  6982. plci->requested_options |= 1L << PRIVATE_V18;
  6983. }
  6984. if (GET_WORD(mdm_cfg[5].info) & 0x4000) /* Private VOWN enable */
  6985. plci->requested_options |= 1L << PRIVATE_VOWN;
  6986. if ((plci->requested_options_conn | plci->requested_options | plci->adapter->requested_options_table[plci->appl->Id - 1])
  6987. & ((1L << PRIVATE_V18) | (1L << PRIVATE_VOWN)))
  6988. {
  6989. if (!api_parse(&bp_parms[3].info[1], (word)bp_parms[3].length, "wwwwwws", mdm_cfg))
  6990. {
  6991. i = 27;
  6992. if (mdm_cfg[6].length >= 4)
  6993. {
  6994. d = GET_DWORD(&mdm_cfg[6].info[1]);
  6995. cai[7] |= (byte) d; /* line taking options */
  6996. cai[9] |= (byte)(d >> 8); /* modulation options */
  6997. cai[++i] = (byte)(d >> 16); /* vown modulation options */
  6998. cai[++i] = (byte)(d >> 24);
  6999. if (mdm_cfg[6].length >= 8)
  7000. {
  7001. d = GET_DWORD(&mdm_cfg[6].info[5]);
  7002. cai[10] |= (byte) d; /* disabled modulations mask */
  7003. cai[11] |= (byte)(d >> 8);
  7004. if (mdm_cfg[6].length >= 12)
  7005. {
  7006. d = GET_DWORD(&mdm_cfg[6].info[9]);
  7007. cai[12] = (byte) d; /* enabled modulations mask */
  7008. cai[++i] = (byte)(d >> 8); /* vown enabled modulations */
  7009. cai[++i] = (byte)(d >> 16);
  7010. cai[++i] = (byte)(d >> 24);
  7011. cai[++i] = 0;
  7012. if (mdm_cfg[6].length >= 14)
  7013. {
  7014. w = GET_WORD(&mdm_cfg[6].info[13]);
  7015. if (w != 0)
  7016. PUT_WORD(&cai[13], w); /* min tx speed */
  7017. if (mdm_cfg[6].length >= 16)
  7018. {
  7019. w = GET_WORD(&mdm_cfg[6].info[15]);
  7020. if (w != 0)
  7021. PUT_WORD(&cai[15], w); /* max tx speed */
  7022. if (mdm_cfg[6].length >= 18)
  7023. {
  7024. w = GET_WORD(&mdm_cfg[6].info[17]);
  7025. if (w != 0)
  7026. PUT_WORD(&cai[17], w); /* min rx speed */
  7027. if (mdm_cfg[6].length >= 20)
  7028. {
  7029. w = GET_WORD(&mdm_cfg[6].info[19]);
  7030. if (w != 0)
  7031. PUT_WORD(&cai[19], w); /* max rx speed */
  7032. if (mdm_cfg[6].length >= 22)
  7033. {
  7034. w = GET_WORD(&mdm_cfg[6].info[21]);
  7035. cai[23] = (byte)(-((short) w)); /* transmit level */
  7036. if (mdm_cfg[6].length >= 24)
  7037. {
  7038. w = GET_WORD(&mdm_cfg[6].info[23]);
  7039. cai[22] |= (byte) w; /* info options mask */
  7040. cai[21] |= (byte)(w >> 8); /* disabled symbol rates */
  7041. }
  7042. }
  7043. }
  7044. }
  7045. }
  7046. }
  7047. }
  7048. }
  7049. }
  7050. cai[27] = i - 27;
  7051. i++;
  7052. if (!api_parse(&bp_parms[3].info[1], (word)bp_parms[3].length, "wwwwwwss", mdm_cfg))
  7053. {
  7054. if (!api_parse(&mdm_cfg[7].info[1], (word)mdm_cfg[7].length, "sss", mdm_cfg_v18))
  7055. {
  7056. for (n = 0; n < 3; n++)
  7057. {
  7058. cai[i] = (byte)(mdm_cfg_v18[n].length);
  7059. for (j = 1; j < ((word)(cai[i] + 1)); j++)
  7060. cai[i + j] = mdm_cfg_v18[n].info[j];
  7061. i += cai[i] + 1;
  7062. }
  7063. }
  7064. }
  7065. cai[0] = (byte)(i - 1);
  7066. }
  7067. }
  7068. }
  7069. }
  7070. if (GET_WORD(bp_parms[0].info) == 2 || /* V.110 async */
  7071. GET_WORD(bp_parms[0].info) == 3) /* V.110 sync */
  7072. {
  7073. if (bp_parms[3].length) {
  7074. dbug(1, dprintf("V.110,%d", GET_WORD(&bp_parms[3].info[1])));
  7075. switch (GET_WORD(&bp_parms[3].info[1])) { /* Rate */
  7076. case 0:
  7077. case 56000:
  7078. if (GET_WORD(bp_parms[0].info) == 3) { /* V.110 sync 56k */
  7079. dbug(1, dprintf("56k sync HSCX"));
  7080. cai[1] = 8;
  7081. cai[2] = 0;
  7082. cai[3] = 0;
  7083. }
  7084. else if (GET_WORD(bp_parms[0].info) == 2) {
  7085. dbug(1, dprintf("56k async DSP"));
  7086. cai[2] = 9;
  7087. }
  7088. break;
  7089. case 50: cai[2] = 1; break;
  7090. case 75: cai[2] = 1; break;
  7091. case 110: cai[2] = 1; break;
  7092. case 150: cai[2] = 1; break;
  7093. case 200: cai[2] = 1; break;
  7094. case 300: cai[2] = 1; break;
  7095. case 600: cai[2] = 1; break;
  7096. case 1200: cai[2] = 2; break;
  7097. case 2400: cai[2] = 3; break;
  7098. case 4800: cai[2] = 4; break;
  7099. case 7200: cai[2] = 10; break;
  7100. case 9600: cai[2] = 5; break;
  7101. case 12000: cai[2] = 13; break;
  7102. case 24000: cai[2] = 0; break;
  7103. case 14400: cai[2] = 11; break;
  7104. case 19200: cai[2] = 6; break;
  7105. case 28800: cai[2] = 12; break;
  7106. case 38400: cai[2] = 7; break;
  7107. case 48000: cai[2] = 8; break;
  7108. case 76: cai[2] = 15; break; /* 75/1200 */
  7109. case 1201: cai[2] = 14; break; /* 1200/75 */
  7110. case 56001: cai[2] = 9; break; /* V.110 56000 */
  7111. default:
  7112. return _B1_PARM_NOT_SUPPORTED;
  7113. }
  7114. cai[3] = 0;
  7115. if (cai[1] == 13) /* v.110 async */
  7116. {
  7117. if (bp_parms[3].length >= 8)
  7118. {
  7119. switch (GET_WORD(&bp_parms[3].info[3]))
  7120. { /* char length */
  7121. case 5:
  7122. cai[3] |= DSP_CAI_ASYNC_CHAR_LENGTH_5;
  7123. break;
  7124. case 6:
  7125. cai[3] |= DSP_CAI_ASYNC_CHAR_LENGTH_6;
  7126. break;
  7127. case 7:
  7128. cai[3] |= DSP_CAI_ASYNC_CHAR_LENGTH_7;
  7129. break;
  7130. }
  7131. switch (GET_WORD(&bp_parms[3].info[5]))
  7132. { /* Parity */
  7133. case 1: /* odd parity */
  7134. cai[3] |= (DSP_CAI_ASYNC_PARITY_ENABLE | DSP_CAI_ASYNC_PARITY_ODD);
  7135. break;
  7136. case 2: /* even parity */
  7137. cai[3] |= (DSP_CAI_ASYNC_PARITY_ENABLE | DSP_CAI_ASYNC_PARITY_EVEN);
  7138. break;
  7139. }
  7140. switch (GET_WORD(&bp_parms[3].info[7]))
  7141. { /* stop bits */
  7142. case 1: /* 2 stop bits */
  7143. cai[3] |= DSP_CAI_ASYNC_TWO_STOP_BITS;
  7144. break;
  7145. }
  7146. }
  7147. }
  7148. }
  7149. else if (cai[1] == 8 || GET_WORD(bp_parms[0].info) == 3) {
  7150. dbug(1, dprintf("V.110 default 56k sync"));
  7151. cai[1] = 8;
  7152. cai[2] = 0;
  7153. cai[3] = 0;
  7154. }
  7155. else {
  7156. dbug(1, dprintf("V.110 default 9600 async"));
  7157. cai[2] = 5;
  7158. }
  7159. }
  7160. PUT_WORD(&cai[5], plci->appl->MaxDataLength);
  7161. 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]));
  7162. /* HexDump ("CAI", sizeof(cai), &cai[0]); */
  7163. add_p(plci, CAI, cai);
  7164. return 0;
  7165. }
  7166. /*------------------------------------------------------------------*/
  7167. /* put parameter for b2 and B3 protocol in the parameter buffer */
  7168. /*------------------------------------------------------------------*/
  7169. static word add_b23(PLCI *plci, API_PARSE *bp)
  7170. {
  7171. word i, fax_control_bits;
  7172. byte pos, len;
  7173. byte SAPI = 0x40; /* default SAPI 16 for x.31 */
  7174. API_PARSE bp_parms[8];
  7175. API_PARSE *b1_config;
  7176. API_PARSE *b2_config;
  7177. API_PARSE b2_config_parms[8];
  7178. API_PARSE *b3_config;
  7179. API_PARSE b3_config_parms[6];
  7180. API_PARSE global_config[2];
  7181. static byte llc[3] = {2,0,0};
  7182. static byte dlc[20] = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
  7183. static byte nlc[256];
  7184. static byte lli[12] = {1,1};
  7185. const byte llc2_out[] = {1,2,4,6,2,0,0,0, X75_V42BIS,V120_L2,V120_V42BIS,V120_L2,6};
  7186. const byte llc2_in[] = {1,3,4,6,3,0,0,0, X75_V42BIS,V120_L2,V120_V42BIS,V120_L2,6};
  7187. const byte llc3[] = {4,3,2,2,6,6,0};
  7188. const byte header[] = {0,2,3,3,0,0,0};
  7189. for (i = 0; i < 8; i++) bp_parms[i].length = 0;
  7190. for (i = 0; i < 6; i++) b2_config_parms[i].length = 0;
  7191. for (i = 0; i < 5; i++) b3_config_parms[i].length = 0;
  7192. lli[0] = 1;
  7193. lli[1] = 1;
  7194. if (plci->adapter->manufacturer_features & MANUFACTURER_FEATURE_XONOFF_FLOW_CONTROL)
  7195. lli[1] |= 2;
  7196. if (plci->adapter->manufacturer_features & MANUFACTURER_FEATURE_OOB_CHANNEL)
  7197. lli[1] |= 4;
  7198. if ((lli[1] & 0x02) && (diva_xdi_extended_features & DIVA_CAPI_USE_CMA)) {
  7199. lli[1] |= 0x10;
  7200. if (plci->rx_dma_descriptor <= 0) {
  7201. plci->rx_dma_descriptor = diva_get_dma_descriptor(plci, &plci->rx_dma_magic);
  7202. if (plci->rx_dma_descriptor >= 0)
  7203. plci->rx_dma_descriptor++;
  7204. }
  7205. if (plci->rx_dma_descriptor > 0) {
  7206. lli[0] = 6;
  7207. lli[1] |= 0x40;
  7208. lli[2] = (byte)(plci->rx_dma_descriptor - 1);
  7209. lli[3] = (byte)plci->rx_dma_magic;
  7210. lli[4] = (byte)(plci->rx_dma_magic >> 8);
  7211. lli[5] = (byte)(plci->rx_dma_magic >> 16);
  7212. lli[6] = (byte)(plci->rx_dma_magic >> 24);
  7213. }
  7214. }
  7215. if (DIVA_CAPI_SUPPORTS_NO_CANCEL(plci->adapter)) {
  7216. lli[1] |= 0x20;
  7217. }
  7218. dbug(1, dprintf("add_b23"));
  7219. api_save_msg(bp, "s", &plci->B_protocol);
  7220. if (!bp->length && plci->tel)
  7221. {
  7222. plci->adv_nl = true;
  7223. dbug(1, dprintf("Default adv.Nl"));
  7224. add_p(plci, LLI, lli);
  7225. plci->B2_prot = 1 /*XPARENT*/;
  7226. plci->B3_prot = 0 /*XPARENT*/;
  7227. llc[1] = 2;
  7228. llc[2] = 4;
  7229. add_p(plci, LLC, llc);
  7230. dlc[0] = 2;
  7231. PUT_WORD(&dlc[1], plci->appl->MaxDataLength);
  7232. add_p(plci, DLC, dlc);
  7233. return 0;
  7234. }
  7235. if (!bp->length) /*default*/
  7236. {
  7237. dbug(1, dprintf("ret default"));
  7238. add_p(plci, LLI, lli);
  7239. plci->B2_prot = 0 /*X.75 */;
  7240. plci->B3_prot = 0 /*XPARENT*/;
  7241. llc[1] = 1;
  7242. llc[2] = 4;
  7243. add_p(plci, LLC, llc);
  7244. dlc[0] = 2;
  7245. PUT_WORD(&dlc[1], plci->appl->MaxDataLength);
  7246. add_p(plci, DLC, dlc);
  7247. return 0;
  7248. }
  7249. dbug(1, dprintf("b_prot_len=%d", (word)bp->length));
  7250. if ((word)bp->length > 256) return _WRONG_MESSAGE_FORMAT;
  7251. if (api_parse(&bp->info[1], (word)bp->length, "wwwsssb", bp_parms))
  7252. {
  7253. bp_parms[6].length = 0;
  7254. if (api_parse(&bp->info[1], (word)bp->length, "wwwsss", bp_parms))
  7255. {
  7256. dbug(1, dprintf("b-form.!"));
  7257. return _WRONG_MESSAGE_FORMAT;
  7258. }
  7259. }
  7260. else if (api_parse(&bp->info[1], (word)bp->length, "wwwssss", bp_parms))
  7261. {
  7262. dbug(1, dprintf("b-form.!"));
  7263. return _WRONG_MESSAGE_FORMAT;
  7264. }
  7265. if (plci->tel == ADV_VOICE) /* transparent B on advanced voice */
  7266. {
  7267. if (GET_WORD(bp_parms[1].info) != 1
  7268. || GET_WORD(bp_parms[2].info) != 0) return _B2_NOT_SUPPORTED;
  7269. plci->adv_nl = true;
  7270. }
  7271. else if (plci->tel) return _B2_NOT_SUPPORTED;
  7272. if ((GET_WORD(bp_parms[1].info) == B2_RTP)
  7273. && (GET_WORD(bp_parms[2].info) == B3_RTP)
  7274. && (plci->adapter->man_profile.private_options & (1L << PRIVATE_RTP)))
  7275. {
  7276. add_p(plci, LLI, lli);
  7277. plci->B2_prot = (byte) GET_WORD(bp_parms[1].info);
  7278. plci->B3_prot = (byte) GET_WORD(bp_parms[2].info);
  7279. llc[1] = (plci->call_dir & (CALL_DIR_ORIGINATE | CALL_DIR_FORCE_OUTG_NL)) ? 14 : 13;
  7280. llc[2] = 4;
  7281. add_p(plci, LLC, llc);
  7282. dlc[0] = 2;
  7283. PUT_WORD(&dlc[1], plci->appl->MaxDataLength);
  7284. dlc[3] = 3; /* Addr A */
  7285. dlc[4] = 1; /* Addr B */
  7286. dlc[5] = 7; /* modulo mode */
  7287. dlc[6] = 7; /* window size */
  7288. dlc[7] = 0; /* XID len Lo */
  7289. dlc[8] = 0; /* XID len Hi */
  7290. for (i = 0; i < bp_parms[4].length; i++)
  7291. dlc[9 + i] = bp_parms[4].info[1 + i];
  7292. dlc[0] = (byte)(8 + bp_parms[4].length);
  7293. add_p(plci, DLC, dlc);
  7294. for (i = 0; i < bp_parms[5].length; i++)
  7295. nlc[1 + i] = bp_parms[5].info[1 + i];
  7296. nlc[0] = (byte)(bp_parms[5].length);
  7297. add_p(plci, NLC, nlc);
  7298. return 0;
  7299. }
  7300. if ((GET_WORD(bp_parms[1].info) >= 32)
  7301. || (!((1L << GET_WORD(bp_parms[1].info)) & plci->adapter->profile.B2_Protocols)
  7302. && ((GET_WORD(bp_parms[1].info) != B2_PIAFS)
  7303. || !(plci->adapter->man_profile.private_options & (1L << PRIVATE_PIAFS)))))
  7304. {
  7305. return _B2_NOT_SUPPORTED;
  7306. }
  7307. if ((GET_WORD(bp_parms[2].info) >= 32)
  7308. || !((1L << GET_WORD(bp_parms[2].info)) & plci->adapter->profile.B3_Protocols))
  7309. {
  7310. return _B3_NOT_SUPPORTED;
  7311. }
  7312. if ((GET_WORD(bp_parms[1].info) != B2_SDLC)
  7313. && ((GET_WORD(bp_parms[0].info) == B1_MODEM_ALL_NEGOTIATE)
  7314. || (GET_WORD(bp_parms[0].info) == B1_MODEM_ASYNC)
  7315. || (GET_WORD(bp_parms[0].info) == B1_MODEM_SYNC_HDLC)))
  7316. {
  7317. return (add_modem_b23(plci, bp_parms));
  7318. }
  7319. add_p(plci, LLI, lli);
  7320. plci->B2_prot = (byte)GET_WORD(bp_parms[1].info);
  7321. plci->B3_prot = (byte)GET_WORD(bp_parms[2].info);
  7322. if (plci->B2_prot == 12) SAPI = 0; /* default SAPI D-channel */
  7323. if (bp_parms[6].length)
  7324. {
  7325. if (api_parse(&bp_parms[6].info[1], (word)bp_parms[6].length, "w", global_config))
  7326. {
  7327. return _WRONG_MESSAGE_FORMAT;
  7328. }
  7329. switch (GET_WORD(global_config[0].info))
  7330. {
  7331. case 1:
  7332. plci->call_dir = (plci->call_dir & ~CALL_DIR_ANSWER) | CALL_DIR_ORIGINATE;
  7333. break;
  7334. case 2:
  7335. plci->call_dir = (plci->call_dir & ~CALL_DIR_ORIGINATE) | CALL_DIR_ANSWER;
  7336. break;
  7337. }
  7338. }
  7339. dbug(1, dprintf("call_dir=%04x", plci->call_dir));
  7340. if (plci->B2_prot == B2_PIAFS)
  7341. llc[1] = PIAFS_CRC;
  7342. else
  7343. /* IMPLEMENT_PIAFS */
  7344. {
  7345. llc[1] = (plci->call_dir & (CALL_DIR_ORIGINATE | CALL_DIR_FORCE_OUTG_NL)) ?
  7346. llc2_out[GET_WORD(bp_parms[1].info)] : llc2_in[GET_WORD(bp_parms[1].info)];
  7347. }
  7348. llc[2] = llc3[GET_WORD(bp_parms[2].info)];
  7349. add_p(plci, LLC, llc);
  7350. dlc[0] = 2;
  7351. PUT_WORD(&dlc[1], plci->appl->MaxDataLength +
  7352. header[GET_WORD(bp_parms[2].info)]);
  7353. b1_config = &bp_parms[3];
  7354. nlc[0] = 0;
  7355. if (plci->B3_prot == 4
  7356. || plci->B3_prot == 5)
  7357. {
  7358. for (i = 0; i < sizeof(T30_INFO); i++) nlc[i] = 0;
  7359. nlc[0] = sizeof(T30_INFO);
  7360. if (plci->adapter->manufacturer_features & MANUFACTURER_FEATURE_FAX_PAPER_FORMATS)
  7361. ((T30_INFO *)&nlc[1])->operating_mode = T30_OPERATING_MODE_CAPI;
  7362. ((T30_INFO *)&nlc[1])->rate_div_2400 = 0xff;
  7363. if (b1_config->length >= 2)
  7364. {
  7365. ((T30_INFO *)&nlc[1])->rate_div_2400 = (byte)(GET_WORD(&b1_config->info[1]) / 2400);
  7366. }
  7367. }
  7368. b2_config = &bp_parms[4];
  7369. if (llc[1] == PIAFS_CRC)
  7370. {
  7371. if (plci->B3_prot != B3_TRANSPARENT)
  7372. {
  7373. return _B_STACK_NOT_SUPPORTED;
  7374. }
  7375. if (b2_config->length && api_parse(&b2_config->info[1], (word)b2_config->length, "bwww", b2_config_parms)) {
  7376. return _WRONG_MESSAGE_FORMAT;
  7377. }
  7378. PUT_WORD(&dlc[1], plci->appl->MaxDataLength);
  7379. dlc[3] = 0; /* Addr A */
  7380. dlc[4] = 0; /* Addr B */
  7381. dlc[5] = 0; /* modulo mode */
  7382. dlc[6] = 0; /* window size */
  7383. if (b2_config->length >= 7) {
  7384. dlc[7] = 7;
  7385. dlc[8] = 0;
  7386. dlc[9] = b2_config_parms[0].info[0]; /* PIAFS protocol Speed configuration */
  7387. dlc[10] = b2_config_parms[1].info[0]; /* V.42bis P0 */
  7388. dlc[11] = b2_config_parms[1].info[1]; /* V.42bis P0 */
  7389. dlc[12] = b2_config_parms[2].info[0]; /* V.42bis P1 */
  7390. dlc[13] = b2_config_parms[2].info[1]; /* V.42bis P1 */
  7391. dlc[14] = b2_config_parms[3].info[0]; /* V.42bis P2 */
  7392. dlc[15] = b2_config_parms[3].info[1]; /* V.42bis P2 */
  7393. dlc[0] = 15;
  7394. if (b2_config->length >= 8) { /* PIAFS control abilities */
  7395. dlc[7] = 10;
  7396. dlc[16] = 2; /* Length of PIAFS extension */
  7397. dlc[17] = PIAFS_UDATA_ABILITIES; /* control (UDATA) ability */
  7398. dlc[18] = b2_config_parms[4].info[0]; /* value */
  7399. dlc[0] = 18;
  7400. }
  7401. }
  7402. else /* default values, 64K, variable, no compression */
  7403. {
  7404. dlc[7] = 7;
  7405. dlc[8] = 0;
  7406. dlc[9] = 0x03; /* PIAFS protocol Speed configuration */
  7407. dlc[10] = 0x03; /* V.42bis P0 */
  7408. dlc[11] = 0; /* V.42bis P0 */
  7409. dlc[12] = 0; /* V.42bis P1 */
  7410. dlc[13] = 0; /* V.42bis P1 */
  7411. dlc[14] = 0; /* V.42bis P2 */
  7412. dlc[15] = 0; /* V.42bis P2 */
  7413. dlc[0] = 15;
  7414. }
  7415. add_p(plci, DLC, dlc);
  7416. }
  7417. else
  7418. if ((llc[1] == V120_L2) || (llc[1] == V120_V42BIS))
  7419. {
  7420. if (plci->B3_prot != B3_TRANSPARENT)
  7421. return _B_STACK_NOT_SUPPORTED;
  7422. dlc[0] = 6;
  7423. PUT_WORD(&dlc[1], GET_WORD(&dlc[1]) + 2);
  7424. dlc[3] = 0x08;
  7425. dlc[4] = 0x01;
  7426. dlc[5] = 127;
  7427. dlc[6] = 7;
  7428. if (b2_config->length != 0)
  7429. {
  7430. if ((llc[1] == V120_V42BIS) && api_parse(&b2_config->info[1], (word)b2_config->length, "bbbbwww", b2_config_parms)) {
  7431. return _WRONG_MESSAGE_FORMAT;
  7432. }
  7433. dlc[3] = (byte)((b2_config->info[2] << 3) | ((b2_config->info[1] >> 5) & 0x04));
  7434. dlc[4] = (byte)((b2_config->info[1] << 1) | 0x01);
  7435. if (b2_config->info[3] != 128)
  7436. {
  7437. dbug(1, dprintf("1D-dlc= %x %x %x %x %x", dlc[0], dlc[1], dlc[2], dlc[3], dlc[4]));
  7438. return _B2_PARM_NOT_SUPPORTED;
  7439. }
  7440. dlc[5] = (byte)(b2_config->info[3] - 1);
  7441. dlc[6] = b2_config->info[4];
  7442. if (llc[1] == V120_V42BIS) {
  7443. if (b2_config->length >= 10) {
  7444. dlc[7] = 6;
  7445. dlc[8] = 0;
  7446. dlc[9] = b2_config_parms[4].info[0];
  7447. dlc[10] = b2_config_parms[4].info[1];
  7448. dlc[11] = b2_config_parms[5].info[0];
  7449. dlc[12] = b2_config_parms[5].info[1];
  7450. dlc[13] = b2_config_parms[6].info[0];
  7451. dlc[14] = b2_config_parms[6].info[1];
  7452. dlc[0] = 14;
  7453. dbug(1, dprintf("b2_config_parms[4].info[0] [1]: %x %x", b2_config_parms[4].info[0], b2_config_parms[4].info[1]));
  7454. dbug(1, dprintf("b2_config_parms[5].info[0] [1]: %x %x", b2_config_parms[5].info[0], b2_config_parms[5].info[1]));
  7455. dbug(1, dprintf("b2_config_parms[6].info[0] [1]: %x %x", b2_config_parms[6].info[0], b2_config_parms[6].info[1]));
  7456. }
  7457. else {
  7458. dlc[6] = 14;
  7459. }
  7460. }
  7461. }
  7462. }
  7463. else
  7464. {
  7465. if (b2_config->length)
  7466. {
  7467. dbug(1, dprintf("B2-Config"));
  7468. if (llc[1] == X75_V42BIS) {
  7469. if (api_parse(&b2_config->info[1], (word)b2_config->length, "bbbbwww", b2_config_parms))
  7470. {
  7471. return _WRONG_MESSAGE_FORMAT;
  7472. }
  7473. }
  7474. else {
  7475. if (api_parse(&b2_config->info[1], (word)b2_config->length, "bbbbs", b2_config_parms))
  7476. {
  7477. return _WRONG_MESSAGE_FORMAT;
  7478. }
  7479. }
  7480. /* if B2 Protocol is LAPD, b2_config structure is different */
  7481. if (llc[1] == 6)
  7482. {
  7483. dlc[0] = 4;
  7484. if (b2_config->length >= 1) dlc[2] = b2_config->info[1]; /* TEI */
  7485. else dlc[2] = 0x01;
  7486. if ((b2_config->length >= 2) && (plci->B2_prot == 12))
  7487. {
  7488. SAPI = b2_config->info[2]; /* SAPI */
  7489. }
  7490. dlc[1] = SAPI;
  7491. if ((b2_config->length >= 3) && (b2_config->info[3] == 128))
  7492. {
  7493. dlc[3] = 127; /* Mode */
  7494. }
  7495. else
  7496. {
  7497. dlc[3] = 7; /* Mode */
  7498. }
  7499. if (b2_config->length >= 4) dlc[4] = b2_config->info[4]; /* Window */
  7500. else dlc[4] = 1;
  7501. dbug(1, dprintf("D-dlc[%d]=%x,%x,%x,%x", dlc[0], dlc[1], dlc[2], dlc[3], dlc[4]));
  7502. if (b2_config->length > 5) return _B2_PARM_NOT_SUPPORTED;
  7503. }
  7504. else
  7505. {
  7506. dlc[0] = (byte)(b2_config_parms[4].length + 6);
  7507. dlc[3] = b2_config->info[1];
  7508. dlc[4] = b2_config->info[2];
  7509. if (b2_config->info[3] != 8 && b2_config->info[3] != 128) {
  7510. dbug(1, dprintf("1D-dlc= %x %x %x %x %x", dlc[0], dlc[1], dlc[2], dlc[3], dlc[4]));
  7511. return _B2_PARM_NOT_SUPPORTED;
  7512. }
  7513. dlc[5] = (byte)(b2_config->info[3] - 1);
  7514. dlc[6] = b2_config->info[4];
  7515. if (dlc[6] > dlc[5]) {
  7516. 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]));
  7517. return _B2_PARM_NOT_SUPPORTED;
  7518. }
  7519. if (llc[1] == X75_V42BIS) {
  7520. if (b2_config->length >= 10) {
  7521. dlc[7] = 6;
  7522. dlc[8] = 0;
  7523. dlc[9] = b2_config_parms[4].info[0];
  7524. dlc[10] = b2_config_parms[4].info[1];
  7525. dlc[11] = b2_config_parms[5].info[0];
  7526. dlc[12] = b2_config_parms[5].info[1];
  7527. dlc[13] = b2_config_parms[6].info[0];
  7528. dlc[14] = b2_config_parms[6].info[1];
  7529. dlc[0] = 14;
  7530. dbug(1, dprintf("b2_config_parms[4].info[0] [1]: %x %x", b2_config_parms[4].info[0], b2_config_parms[4].info[1]));
  7531. dbug(1, dprintf("b2_config_parms[5].info[0] [1]: %x %x", b2_config_parms[5].info[0], b2_config_parms[5].info[1]));
  7532. dbug(1, dprintf("b2_config_parms[6].info[0] [1]: %x %x", b2_config_parms[6].info[0], b2_config_parms[6].info[1]));
  7533. }
  7534. else {
  7535. dlc[6] = 14;
  7536. }
  7537. }
  7538. else {
  7539. PUT_WORD(&dlc[7], (word)b2_config_parms[4].length);
  7540. for (i = 0; i < b2_config_parms[4].length; i++)
  7541. dlc[11 + i] = b2_config_parms[4].info[1 + i];
  7542. }
  7543. }
  7544. }
  7545. }
  7546. add_p(plci, DLC, dlc);
  7547. b3_config = &bp_parms[5];
  7548. if (b3_config->length)
  7549. {
  7550. if (plci->B3_prot == 4
  7551. || plci->B3_prot == 5)
  7552. {
  7553. if (api_parse(&b3_config->info[1], (word)b3_config->length, "wwss", b3_config_parms))
  7554. {
  7555. return _WRONG_MESSAGE_FORMAT;
  7556. }
  7557. i = GET_WORD((byte *)(b3_config_parms[0].info));
  7558. ((T30_INFO *)&nlc[1])->resolution = (byte)(((i & 0x0001) ||
  7559. ((plci->B3_prot == 4) && (((byte)(GET_WORD((byte *)b3_config_parms[1].info))) != 5))) ? T30_RESOLUTION_R8_0770_OR_200 : 0);
  7560. ((T30_INFO *)&nlc[1])->data_format = (byte)(GET_WORD((byte *)b3_config_parms[1].info));
  7561. fax_control_bits = T30_CONTROL_BIT_ALL_FEATURES;
  7562. if ((((T30_INFO *)&nlc[1])->rate_div_2400 != 0) && (((T30_INFO *)&nlc[1])->rate_div_2400 <= 6))
  7563. fax_control_bits &= ~T30_CONTROL_BIT_ENABLE_V34FAX;
  7564. if (plci->adapter->manufacturer_features & MANUFACTURER_FEATURE_FAX_PAPER_FORMATS)
  7565. {
  7566. if ((plci->requested_options_conn | plci->requested_options | plci->adapter->requested_options_table[plci->appl->Id - 1])
  7567. & (1L << PRIVATE_FAX_PAPER_FORMATS))
  7568. {
  7569. ((T30_INFO *)&nlc[1])->resolution |= T30_RESOLUTION_R8_1540 |
  7570. T30_RESOLUTION_R16_1540_OR_400 | T30_RESOLUTION_300_300 |
  7571. T30_RESOLUTION_INCH_BASED | T30_RESOLUTION_METRIC_BASED;
  7572. }
  7573. ((T30_INFO *)&nlc[1])->recording_properties =
  7574. T30_RECORDING_WIDTH_ISO_A3 |
  7575. (T30_RECORDING_LENGTH_UNLIMITED << 2) |
  7576. (T30_MIN_SCANLINE_TIME_00_00_00 << 4);
  7577. }
  7578. if (plci->B3_prot == 5)
  7579. {
  7580. if (i & 0x0002) /* Accept incoming fax-polling requests */
  7581. fax_control_bits |= T30_CONTROL_BIT_ACCEPT_POLLING;
  7582. if (i & 0x2000) /* Do not use MR compression */
  7583. fax_control_bits &= ~T30_CONTROL_BIT_ENABLE_2D_CODING;
  7584. if (i & 0x4000) /* Do not use MMR compression */
  7585. fax_control_bits &= ~T30_CONTROL_BIT_ENABLE_T6_CODING;
  7586. if (i & 0x8000) /* Do not use ECM */
  7587. fax_control_bits &= ~T30_CONTROL_BIT_ENABLE_ECM;
  7588. if (plci->fax_connect_info_length != 0)
  7589. {
  7590. ((T30_INFO *)&nlc[1])->resolution = ((T30_INFO *)plci->fax_connect_info_buffer)->resolution;
  7591. ((T30_INFO *)&nlc[1])->data_format = ((T30_INFO *)plci->fax_connect_info_buffer)->data_format;
  7592. ((T30_INFO *)&nlc[1])->recording_properties = ((T30_INFO *)plci->fax_connect_info_buffer)->recording_properties;
  7593. fax_control_bits |= GET_WORD(&((T30_INFO *)plci->fax_connect_info_buffer)->control_bits_low) &
  7594. (T30_CONTROL_BIT_REQUEST_POLLING | T30_CONTROL_BIT_MORE_DOCUMENTS);
  7595. }
  7596. }
  7597. /* copy station id to NLC */
  7598. for (i = 0; i < T30_MAX_STATION_ID_LENGTH; i++)
  7599. {
  7600. if (i < b3_config_parms[2].length)
  7601. {
  7602. ((T30_INFO *)&nlc[1])->station_id[i] = ((byte *)b3_config_parms[2].info)[1 + i];
  7603. }
  7604. else
  7605. {
  7606. ((T30_INFO *)&nlc[1])->station_id[i] = ' ';
  7607. }
  7608. }
  7609. ((T30_INFO *)&nlc[1])->station_id_len = T30_MAX_STATION_ID_LENGTH;
  7610. /* copy head line to NLC */
  7611. if (b3_config_parms[3].length)
  7612. {
  7613. pos = (byte)(fax_head_line_time(&(((T30_INFO *)&nlc[1])->station_id[T30_MAX_STATION_ID_LENGTH])));
  7614. if (pos != 0)
  7615. {
  7616. if (CAPI_MAX_DATE_TIME_LENGTH + 2 + b3_config_parms[3].length > CAPI_MAX_HEAD_LINE_SPACE)
  7617. pos = 0;
  7618. else
  7619. {
  7620. nlc[1 + offsetof(T30_INFO, station_id) + T30_MAX_STATION_ID_LENGTH + pos++] = ' ';
  7621. nlc[1 + offsetof(T30_INFO, station_id) + T30_MAX_STATION_ID_LENGTH + pos++] = ' ';
  7622. len = (byte)b3_config_parms[2].length;
  7623. if (len > 20)
  7624. len = 20;
  7625. if (CAPI_MAX_DATE_TIME_LENGTH + 2 + len + 2 + b3_config_parms[3].length <= CAPI_MAX_HEAD_LINE_SPACE)
  7626. {
  7627. for (i = 0; i < len; i++)
  7628. nlc[1 + offsetof(T30_INFO, station_id) + T30_MAX_STATION_ID_LENGTH + pos++] = ((byte *)b3_config_parms[2].info)[1 + i];
  7629. nlc[1 + offsetof(T30_INFO, station_id) + T30_MAX_STATION_ID_LENGTH + pos++] = ' ';
  7630. nlc[1 + offsetof(T30_INFO, station_id) + T30_MAX_STATION_ID_LENGTH + pos++] = ' ';
  7631. }
  7632. }
  7633. }
  7634. len = (byte)b3_config_parms[3].length;
  7635. if (len > CAPI_MAX_HEAD_LINE_SPACE - pos)
  7636. len = (byte)(CAPI_MAX_HEAD_LINE_SPACE - pos);
  7637. ((T30_INFO *)&nlc[1])->head_line_len = (byte)(pos + len);
  7638. nlc[0] += (byte)(pos + len);
  7639. for (i = 0; i < len; i++)
  7640. nlc[1 + offsetof(T30_INFO, station_id) + T30_MAX_STATION_ID_LENGTH + pos++] = ((byte *)b3_config_parms[3].info)[1 + i];
  7641. } else
  7642. ((T30_INFO *)&nlc[1])->head_line_len = 0;
  7643. plci->nsf_control_bits = 0;
  7644. if (plci->B3_prot == 5)
  7645. {
  7646. if ((plci->adapter->man_profile.private_options & (1L << PRIVATE_FAX_SUB_SEP_PWD))
  7647. && (GET_WORD((byte *)b3_config_parms[1].info) & 0x8000)) /* Private SUB/SEP/PWD enable */
  7648. {
  7649. plci->requested_options |= 1L << PRIVATE_FAX_SUB_SEP_PWD;
  7650. }
  7651. if ((plci->adapter->man_profile.private_options & (1L << PRIVATE_FAX_NONSTANDARD))
  7652. && (GET_WORD((byte *)b3_config_parms[1].info) & 0x4000)) /* Private non-standard facilities enable */
  7653. {
  7654. plci->requested_options |= 1L << PRIVATE_FAX_NONSTANDARD;
  7655. }
  7656. if ((plci->requested_options_conn | plci->requested_options | plci->adapter->requested_options_table[plci->appl->Id - 1])
  7657. & ((1L << PRIVATE_FAX_SUB_SEP_PWD) | (1L << PRIVATE_FAX_NONSTANDARD)))
  7658. {
  7659. if ((plci->requested_options_conn | plci->requested_options | plci->adapter->requested_options_table[plci->appl->Id - 1])
  7660. & (1L << PRIVATE_FAX_SUB_SEP_PWD))
  7661. {
  7662. fax_control_bits |= T30_CONTROL_BIT_ACCEPT_SUBADDRESS | T30_CONTROL_BIT_ACCEPT_PASSWORD;
  7663. if (fax_control_bits & T30_CONTROL_BIT_ACCEPT_POLLING)
  7664. fax_control_bits |= T30_CONTROL_BIT_ACCEPT_SEL_POLLING;
  7665. }
  7666. len = nlc[0];
  7667. pos = offsetof(T30_INFO, station_id) + T30_MAX_STATION_ID_LENGTH;
  7668. if (pos < plci->fax_connect_info_length)
  7669. {
  7670. for (i = 1 + plci->fax_connect_info_buffer[pos]; i != 0; i--)
  7671. nlc[++len] = plci->fax_connect_info_buffer[pos++];
  7672. }
  7673. else
  7674. nlc[++len] = 0;
  7675. if (pos < plci->fax_connect_info_length)
  7676. {
  7677. for (i = 1 + plci->fax_connect_info_buffer[pos]; i != 0; i--)
  7678. nlc[++len] = plci->fax_connect_info_buffer[pos++];
  7679. }
  7680. else
  7681. nlc[++len] = 0;
  7682. if ((plci->requested_options_conn | plci->requested_options | plci->adapter->requested_options_table[plci->appl->Id - 1])
  7683. & (1L << PRIVATE_FAX_NONSTANDARD))
  7684. {
  7685. if ((pos < plci->fax_connect_info_length) && (plci->fax_connect_info_buffer[pos] != 0))
  7686. {
  7687. if ((plci->fax_connect_info_buffer[pos] >= 3) && (plci->fax_connect_info_buffer[pos + 1] >= 2))
  7688. plci->nsf_control_bits = GET_WORD(&plci->fax_connect_info_buffer[pos + 2]);
  7689. for (i = 1 + plci->fax_connect_info_buffer[pos]; i != 0; i--)
  7690. nlc[++len] = plci->fax_connect_info_buffer[pos++];
  7691. }
  7692. else
  7693. {
  7694. if (api_parse(&b3_config->info[1], (word)b3_config->length, "wwsss", b3_config_parms))
  7695. {
  7696. dbug(1, dprintf("non-standard facilities info missing or wrong format"));
  7697. nlc[++len] = 0;
  7698. }
  7699. else
  7700. {
  7701. if ((b3_config_parms[4].length >= 3) && (b3_config_parms[4].info[1] >= 2))
  7702. plci->nsf_control_bits = GET_WORD(&b3_config_parms[4].info[2]);
  7703. nlc[++len] = (byte)(b3_config_parms[4].length);
  7704. for (i = 0; i < b3_config_parms[4].length; i++)
  7705. nlc[++len] = b3_config_parms[4].info[1 + i];
  7706. }
  7707. }
  7708. }
  7709. nlc[0] = len;
  7710. if ((plci->nsf_control_bits & T30_NSF_CONTROL_BIT_ENABLE_NSF)
  7711. && (plci->nsf_control_bits & T30_NSF_CONTROL_BIT_NEGOTIATE_RESP))
  7712. {
  7713. ((T30_INFO *)&nlc[1])->operating_mode = T30_OPERATING_MODE_CAPI_NEG;
  7714. }
  7715. }
  7716. }
  7717. PUT_WORD(&(((T30_INFO *)&nlc[1])->control_bits_low), fax_control_bits);
  7718. len = offsetof(T30_INFO, station_id) + T30_MAX_STATION_ID_LENGTH;
  7719. for (i = 0; i < len; i++)
  7720. plci->fax_connect_info_buffer[i] = nlc[1 + i];
  7721. ((T30_INFO *) plci->fax_connect_info_buffer)->head_line_len = 0;
  7722. i += ((T30_INFO *)&nlc[1])->head_line_len;
  7723. while (i < nlc[0])
  7724. plci->fax_connect_info_buffer[len++] = nlc[++i];
  7725. plci->fax_connect_info_length = len;
  7726. }
  7727. else
  7728. {
  7729. nlc[0] = 14;
  7730. if (b3_config->length != 16)
  7731. return _B3_PARM_NOT_SUPPORTED;
  7732. for (i = 0; i < 12; i++) nlc[1 + i] = b3_config->info[1 + i];
  7733. if (GET_WORD(&b3_config->info[13]) != 8 && GET_WORD(&b3_config->info[13]) != 128)
  7734. return _B3_PARM_NOT_SUPPORTED;
  7735. nlc[13] = b3_config->info[13];
  7736. if (GET_WORD(&b3_config->info[15]) >= nlc[13])
  7737. return _B3_PARM_NOT_SUPPORTED;
  7738. nlc[14] = b3_config->info[15];
  7739. }
  7740. }
  7741. else
  7742. {
  7743. if (plci->B3_prot == 4
  7744. || plci->B3_prot == 5 /*T.30 - FAX*/) return _B3_PARM_NOT_SUPPORTED;
  7745. }
  7746. add_p(plci, NLC, nlc);
  7747. return 0;
  7748. }
  7749. /*----------------------------------------------------------------*/
  7750. /* make the same as add_b23, but only for the modem related */
  7751. /* L2 and L3 B-Chan protocol. */
  7752. /* */
  7753. /* Enabled L2 and L3 Configurations: */
  7754. /* If L1 == Modem all negotiation */
  7755. /* only L2 == Modem with full negotiation is allowed */
  7756. /* If L1 == Modem async or sync */
  7757. /* only L2 == Transparent is allowed */
  7758. /* L3 == Modem or L3 == Transparent are allowed */
  7759. /* B2 Configuration for modem: */
  7760. /* word : enable/disable compression, bitoptions */
  7761. /* B3 Configuration for modem: */
  7762. /* empty */
  7763. /*----------------------------------------------------------------*/
  7764. static word add_modem_b23(PLCI *plci, API_PARSE *bp_parms)
  7765. {
  7766. static byte lli[12] = {1,1};
  7767. static byte llc[3] = {2,0,0};
  7768. static byte dlc[16] = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
  7769. API_PARSE mdm_config[2];
  7770. word i;
  7771. word b2_config = 0;
  7772. for (i = 0; i < 2; i++) mdm_config[i].length = 0;
  7773. for (i = 0; i < sizeof(dlc); i++) dlc[i] = 0;
  7774. if (((GET_WORD(bp_parms[0].info) == B1_MODEM_ALL_NEGOTIATE)
  7775. && (GET_WORD(bp_parms[1].info) != B2_MODEM_EC_COMPRESSION))
  7776. || ((GET_WORD(bp_parms[0].info) != B1_MODEM_ALL_NEGOTIATE)
  7777. && (GET_WORD(bp_parms[1].info) != B2_TRANSPARENT)))
  7778. {
  7779. return (_B_STACK_NOT_SUPPORTED);
  7780. }
  7781. if ((GET_WORD(bp_parms[2].info) != B3_MODEM)
  7782. && (GET_WORD(bp_parms[2].info) != B3_TRANSPARENT))
  7783. {
  7784. return (_B_STACK_NOT_SUPPORTED);
  7785. }
  7786. plci->B2_prot = (byte) GET_WORD(bp_parms[1].info);
  7787. plci->B3_prot = (byte) GET_WORD(bp_parms[2].info);
  7788. if ((GET_WORD(bp_parms[1].info) == B2_MODEM_EC_COMPRESSION) && bp_parms[4].length)
  7789. {
  7790. if (api_parse(&bp_parms[4].info[1],
  7791. (word)bp_parms[4].length, "w",
  7792. mdm_config))
  7793. {
  7794. return (_WRONG_MESSAGE_FORMAT);
  7795. }
  7796. b2_config = GET_WORD(mdm_config[0].info);
  7797. }
  7798. /* OK, L2 is modem */
  7799. lli[0] = 1;
  7800. lli[1] = 1;
  7801. if (plci->adapter->manufacturer_features & MANUFACTURER_FEATURE_XONOFF_FLOW_CONTROL)
  7802. lli[1] |= 2;
  7803. if (plci->adapter->manufacturer_features & MANUFACTURER_FEATURE_OOB_CHANNEL)
  7804. lli[1] |= 4;
  7805. if ((lli[1] & 0x02) && (diva_xdi_extended_features & DIVA_CAPI_USE_CMA)) {
  7806. lli[1] |= 0x10;
  7807. if (plci->rx_dma_descriptor <= 0) {
  7808. plci->rx_dma_descriptor = diva_get_dma_descriptor(plci, &plci->rx_dma_magic);
  7809. if (plci->rx_dma_descriptor >= 0)
  7810. plci->rx_dma_descriptor++;
  7811. }
  7812. if (plci->rx_dma_descriptor > 0) {
  7813. lli[1] |= 0x40;
  7814. lli[0] = 6;
  7815. lli[2] = (byte)(plci->rx_dma_descriptor - 1);
  7816. lli[3] = (byte)plci->rx_dma_magic;
  7817. lli[4] = (byte)(plci->rx_dma_magic >> 8);
  7818. lli[5] = (byte)(plci->rx_dma_magic >> 16);
  7819. lli[6] = (byte)(plci->rx_dma_magic >> 24);
  7820. }
  7821. }
  7822. if (DIVA_CAPI_SUPPORTS_NO_CANCEL(plci->adapter)) {
  7823. lli[1] |= 0x20;
  7824. }
  7825. llc[1] = (plci->call_dir & (CALL_DIR_ORIGINATE | CALL_DIR_FORCE_OUTG_NL)) ?
  7826. /*V42*/ 10 : /*V42_IN*/ 9;
  7827. llc[2] = 4; /* pass L3 always transparent */
  7828. add_p(plci, LLI, lli);
  7829. add_p(plci, LLC, llc);
  7830. i = 1;
  7831. PUT_WORD(&dlc[i], plci->appl->MaxDataLength);
  7832. i += 2;
  7833. if (GET_WORD(bp_parms[1].info) == B2_MODEM_EC_COMPRESSION)
  7834. {
  7835. if (bp_parms[4].length)
  7836. {
  7837. dbug(1, dprintf("MDM b2_config=%02x", b2_config));
  7838. dlc[i++] = 3; /* Addr A */
  7839. dlc[i++] = 1; /* Addr B */
  7840. dlc[i++] = 7; /* modulo mode */
  7841. dlc[i++] = 7; /* window size */
  7842. dlc[i++] = 0; /* XID len Lo */
  7843. dlc[i++] = 0; /* XID len Hi */
  7844. if (b2_config & MDM_B2_DISABLE_V42bis)
  7845. {
  7846. dlc[i] |= DLC_MODEMPROT_DISABLE_V42_V42BIS;
  7847. }
  7848. if (b2_config & MDM_B2_DISABLE_MNP)
  7849. {
  7850. dlc[i] |= DLC_MODEMPROT_DISABLE_MNP_MNP5;
  7851. }
  7852. if (b2_config & MDM_B2_DISABLE_TRANS)
  7853. {
  7854. dlc[i] |= DLC_MODEMPROT_REQUIRE_PROTOCOL;
  7855. }
  7856. if (b2_config & MDM_B2_DISABLE_V42)
  7857. {
  7858. dlc[i] |= DLC_MODEMPROT_DISABLE_V42_DETECT;
  7859. }
  7860. if (b2_config & MDM_B2_DISABLE_COMP)
  7861. {
  7862. dlc[i] |= DLC_MODEMPROT_DISABLE_COMPRESSION;
  7863. }
  7864. i++;
  7865. }
  7866. }
  7867. else
  7868. {
  7869. dlc[i++] = 3; /* Addr A */
  7870. dlc[i++] = 1; /* Addr B */
  7871. dlc[i++] = 7; /* modulo mode */
  7872. dlc[i++] = 7; /* window size */
  7873. dlc[i++] = 0; /* XID len Lo */
  7874. dlc[i++] = 0; /* XID len Hi */
  7875. dlc[i++] = DLC_MODEMPROT_DISABLE_V42_V42BIS |
  7876. DLC_MODEMPROT_DISABLE_MNP_MNP5 |
  7877. DLC_MODEMPROT_DISABLE_V42_DETECT |
  7878. DLC_MODEMPROT_DISABLE_COMPRESSION;
  7879. }
  7880. dlc[0] = (byte)(i - 1);
  7881. /* HexDump ("DLC", sizeof(dlc), &dlc[0]); */
  7882. add_p(plci, DLC, dlc);
  7883. return (0);
  7884. }
  7885. /*------------------------------------------------------------------*/
  7886. /* send a request for the signaling entity */
  7887. /*------------------------------------------------------------------*/
  7888. static void sig_req(PLCI *plci, byte req, byte Id)
  7889. {
  7890. if (!plci) return;
  7891. if (plci->adapter->adapter_disabled) return;
  7892. dbug(1, dprintf("sig_req(%x)", req));
  7893. if (req == REMOVE)
  7894. plci->sig_remove_id = plci->Sig.Id;
  7895. if (plci->req_in == plci->req_in_start) {
  7896. plci->req_in += 2;
  7897. plci->RBuffer[plci->req_in++] = 0;
  7898. }
  7899. PUT_WORD(&plci->RBuffer[plci->req_in_start], plci->req_in-plci->req_in_start - 2);
  7900. plci->RBuffer[plci->req_in++] = Id; /* sig/nl flag */
  7901. plci->RBuffer[plci->req_in++] = req; /* request */
  7902. plci->RBuffer[plci->req_in++] = 0; /* channel */
  7903. plci->req_in_start = plci->req_in;
  7904. }
  7905. /*------------------------------------------------------------------*/
  7906. /* send a request for the network layer entity */
  7907. /*------------------------------------------------------------------*/
  7908. static void nl_req_ncci(PLCI *plci, byte req, byte ncci)
  7909. {
  7910. if (!plci) return;
  7911. if (plci->adapter->adapter_disabled) return;
  7912. dbug(1, dprintf("nl_req %02x %02x %02x", plci->Id, req, ncci));
  7913. if (req == REMOVE)
  7914. {
  7915. plci->nl_remove_id = plci->NL.Id;
  7916. ncci_remove(plci, 0, (byte)(ncci != 0));
  7917. ncci = 0;
  7918. }
  7919. if (plci->req_in == plci->req_in_start) {
  7920. plci->req_in += 2;
  7921. plci->RBuffer[plci->req_in++] = 0;
  7922. }
  7923. PUT_WORD(&plci->RBuffer[plci->req_in_start], plci->req_in-plci->req_in_start - 2);
  7924. plci->RBuffer[plci->req_in++] = 1; /* sig/nl flag */
  7925. plci->RBuffer[plci->req_in++] = req; /* request */
  7926. plci->RBuffer[plci->req_in++] = plci->adapter->ncci_ch[ncci]; /* channel */
  7927. plci->req_in_start = plci->req_in;
  7928. }
  7929. static void send_req(PLCI *plci)
  7930. {
  7931. ENTITY *e;
  7932. word l;
  7933. /* word i; */
  7934. if (!plci) return;
  7935. if (plci->adapter->adapter_disabled) return;
  7936. channel_xmit_xon(plci);
  7937. /* if nothing to do, return */
  7938. if (plci->req_in == plci->req_out) return;
  7939. dbug(1, dprintf("send_req(in=%d,out=%d)", plci->req_in, plci->req_out));
  7940. if (plci->nl_req || plci->sig_req) return;
  7941. l = GET_WORD(&plci->RBuffer[plci->req_out]);
  7942. plci->req_out += 2;
  7943. plci->XData[0].P = &plci->RBuffer[plci->req_out];
  7944. plci->req_out += l;
  7945. if (plci->RBuffer[plci->req_out] == 1)
  7946. {
  7947. e = &plci->NL;
  7948. plci->req_out++;
  7949. e->Req = plci->nl_req = plci->RBuffer[plci->req_out++];
  7950. e->ReqCh = plci->RBuffer[plci->req_out++];
  7951. if (!(e->Id & 0x1f))
  7952. {
  7953. e->Id = NL_ID;
  7954. plci->RBuffer[plci->req_out - 4] = CAI;
  7955. plci->RBuffer[plci->req_out - 3] = 1;
  7956. plci->RBuffer[plci->req_out - 2] = (plci->Sig.Id == 0xff) ? 0 : plci->Sig.Id;
  7957. plci->RBuffer[plci->req_out - 1] = 0;
  7958. l += 3;
  7959. plci->nl_global_req = plci->nl_req;
  7960. }
  7961. dbug(1, dprintf("%x:NLREQ(%x:%x:%x)", plci->adapter->Id, e->Id, e->Req, e->ReqCh));
  7962. }
  7963. else
  7964. {
  7965. e = &plci->Sig;
  7966. if (plci->RBuffer[plci->req_out])
  7967. e->Id = plci->RBuffer[plci->req_out];
  7968. plci->req_out++;
  7969. e->Req = plci->sig_req = plci->RBuffer[plci->req_out++];
  7970. e->ReqCh = plci->RBuffer[plci->req_out++];
  7971. if (!(e->Id & 0x1f))
  7972. plci->sig_global_req = plci->sig_req;
  7973. dbug(1, dprintf("%x:SIGREQ(%x:%x:%x)", plci->adapter->Id, e->Id, e->Req, e->ReqCh));
  7974. }
  7975. plci->XData[0].PLength = l;
  7976. e->X = plci->XData;
  7977. plci->adapter->request(e);
  7978. dbug(1, dprintf("send_ok"));
  7979. }
  7980. static void send_data(PLCI *plci)
  7981. {
  7982. DIVA_CAPI_ADAPTER *a;
  7983. DATA_B3_DESC *data;
  7984. NCCI *ncci_ptr;
  7985. word ncci;
  7986. if (!plci->nl_req && plci->ncci_ring_list)
  7987. {
  7988. a = plci->adapter;
  7989. ncci = plci->ncci_ring_list;
  7990. do
  7991. {
  7992. ncci = a->ncci_next[ncci];
  7993. ncci_ptr = &(a->ncci[ncci]);
  7994. if (!(a->ncci_ch[ncci]
  7995. && (a->ch_flow_control[a->ncci_ch[ncci]] & N_OK_FC_PENDING)))
  7996. {
  7997. if (ncci_ptr->data_pending)
  7998. {
  7999. if ((a->ncci_state[ncci] == CONNECTED)
  8000. || (a->ncci_state[ncci] == INC_ACT_PENDING)
  8001. || (plci->send_disc == ncci))
  8002. {
  8003. data = &(ncci_ptr->DBuffer[ncci_ptr->data_out]);
  8004. if ((plci->B2_prot == B2_V120_ASYNC)
  8005. || (plci->B2_prot == B2_V120_ASYNC_V42BIS)
  8006. || (plci->B2_prot == B2_V120_BIT_TRANSPARENT))
  8007. {
  8008. plci->NData[1].P = TransmitBufferGet(plci->appl, data->P);
  8009. plci->NData[1].PLength = data->Length;
  8010. if (data->Flags & 0x10)
  8011. plci->NData[0].P = v120_break_header;
  8012. else
  8013. plci->NData[0].P = v120_default_header;
  8014. plci->NData[0].PLength = 1;
  8015. plci->NL.XNum = 2;
  8016. plci->NL.Req = plci->nl_req = (byte)((data->Flags & 0x07) << 4 | N_DATA);
  8017. }
  8018. else
  8019. {
  8020. plci->NData[0].P = TransmitBufferGet(plci->appl, data->P);
  8021. plci->NData[0].PLength = data->Length;
  8022. if (data->Flags & 0x10)
  8023. plci->NL.Req = plci->nl_req = (byte)N_UDATA;
  8024. else if ((plci->B3_prot == B3_RTP) && (data->Flags & 0x01))
  8025. plci->NL.Req = plci->nl_req = (byte)N_BDATA;
  8026. else
  8027. plci->NL.Req = plci->nl_req = (byte)((data->Flags & 0x07) << 4 | N_DATA);
  8028. }
  8029. plci->NL.X = plci->NData;
  8030. plci->NL.ReqCh = a->ncci_ch[ncci];
  8031. dbug(1, dprintf("%x:DREQ(%x:%x)", a->Id, plci->NL.Id, plci->NL.Req));
  8032. plci->data_sent = true;
  8033. plci->data_sent_ptr = data->P;
  8034. a->request(&plci->NL);
  8035. }
  8036. else {
  8037. cleanup_ncci_data(plci, ncci);
  8038. }
  8039. }
  8040. else if (plci->send_disc == ncci)
  8041. {
  8042. /* dprintf("N_DISC"); */
  8043. plci->NData[0].PLength = 0;
  8044. plci->NL.ReqCh = a->ncci_ch[ncci];
  8045. plci->NL.Req = plci->nl_req = N_DISC;
  8046. a->request(&plci->NL);
  8047. plci->command = _DISCONNECT_B3_R;
  8048. plci->send_disc = 0;
  8049. }
  8050. }
  8051. } while (!plci->nl_req && (ncci != plci->ncci_ring_list));
  8052. plci->ncci_ring_list = ncci;
  8053. }
  8054. }
  8055. static void listen_check(DIVA_CAPI_ADAPTER *a)
  8056. {
  8057. word i, j;
  8058. PLCI *plci;
  8059. byte activnotifiedcalls = 0;
  8060. dbug(1, dprintf("listen_check(%d,%d)", a->listen_active, a->max_listen));
  8061. if (!remove_started && !a->adapter_disabled)
  8062. {
  8063. for (i = 0; i < a->max_plci; i++)
  8064. {
  8065. plci = &(a->plci[i]);
  8066. if (plci->notifiedcall) activnotifiedcalls++;
  8067. }
  8068. dbug(1, dprintf("listen_check(%d)", activnotifiedcalls));
  8069. for (i = a->listen_active; i < ((word)(a->max_listen + activnotifiedcalls)); i++) {
  8070. if ((j = get_plci(a))) {
  8071. a->listen_active++;
  8072. plci = &a->plci[j - 1];
  8073. plci->State = LISTENING;
  8074. add_p(plci, OAD, "\x01\xfd");
  8075. add_p(plci, KEY, "\x04\x43\x41\x32\x30");
  8076. add_p(plci, CAI, "\x01\xc0");
  8077. add_p(plci, UID, "\x06\x43\x61\x70\x69\x32\x30");
  8078. add_p(plci, LLI, "\x01\xc4"); /* support Dummy CR FAC + MWI + SpoofNotify */
  8079. add_p(plci, SHIFT | 6, NULL);
  8080. add_p(plci, SIN, "\x02\x00\x00");
  8081. plci->internal_command = LISTEN_SIG_ASSIGN_PEND; /* do indicate_req if OK */
  8082. sig_req(plci, ASSIGN, DSIG_ID);
  8083. send_req(plci);
  8084. }
  8085. }
  8086. }
  8087. }
  8088. /*------------------------------------------------------------------*/
  8089. /* functions for all parameters sent in INDs */
  8090. /*------------------------------------------------------------------*/
  8091. static void IndParse(PLCI *plci, const word *parms_id, byte **parms, byte multiIEsize)
  8092. {
  8093. word ploc; /* points to current location within packet */
  8094. byte w;
  8095. byte wlen;
  8096. byte codeset, lock;
  8097. byte *in;
  8098. word i;
  8099. word code;
  8100. word mIEindex = 0;
  8101. ploc = 0;
  8102. codeset = 0;
  8103. lock = 0;
  8104. in = plci->Sig.RBuffer->P;
  8105. for (i = 0; i < parms_id[0]; i++) /* multiIE parms_id contains just the 1st */
  8106. { /* element but parms array is larger */
  8107. parms[i] = (byte *)"";
  8108. }
  8109. for (i = 0; i < multiIEsize; i++)
  8110. {
  8111. parms[i] = (byte *)"";
  8112. }
  8113. while (ploc < plci->Sig.RBuffer->length - 1) {
  8114. /* read information element id and length */
  8115. w = in[ploc];
  8116. if (w & 0x80) {
  8117. /* w &=0xf0; removed, cannot detect congestion levels */
  8118. /* upper 4 bit masked with w==SHIFT now */
  8119. wlen = 0;
  8120. }
  8121. else {
  8122. wlen = (byte)(in[ploc + 1] + 1);
  8123. }
  8124. /* check if length valid (not exceeding end of packet) */
  8125. if ((ploc + wlen) > 270) return;
  8126. if (lock & 0x80) lock &= 0x7f;
  8127. else codeset = lock;
  8128. if ((w & 0xf0) == SHIFT) {
  8129. codeset = in[ploc];
  8130. if (!(codeset & 0x08)) lock = (byte)(codeset & 7);
  8131. codeset &= 7;
  8132. lock |= 0x80;
  8133. }
  8134. else {
  8135. if (w == ESC && wlen >= 3) code = in[ploc + 2] | 0x800;
  8136. else code = w;
  8137. code |= (codeset << 8);
  8138. for (i = 1; i < parms_id[0] + 1 && parms_id[i] != code; i++);
  8139. if (i < parms_id[0] + 1) {
  8140. if (!multiIEsize) { /* with multiIEs use next field index, */
  8141. mIEindex = i - 1; /* with normal IEs use same index like parms_id */
  8142. }
  8143. parms[mIEindex] = &in[ploc + 1];
  8144. dbug(1, dprintf("mIE[%d]=0x%x", *parms[mIEindex], in[ploc]));
  8145. if (parms_id[i] == OAD
  8146. || parms_id[i] == CONN_NR
  8147. || parms_id[i] == CAD) {
  8148. if (in[ploc + 2] & 0x80) {
  8149. in[ploc + 0] = (byte)(in[ploc + 1] + 1);
  8150. in[ploc + 1] = (byte)(in[ploc + 2] & 0x7f);
  8151. in[ploc + 2] = 0x80;
  8152. parms[mIEindex] = &in[ploc];
  8153. }
  8154. }
  8155. mIEindex++; /* effects multiIEs only */
  8156. }
  8157. }
  8158. ploc += (wlen + 1);
  8159. }
  8160. return;
  8161. }
  8162. /*------------------------------------------------------------------*/
  8163. /* try to match a cip from received BC and HLC */
  8164. /*------------------------------------------------------------------*/
  8165. static byte ie_compare(byte *ie1, byte *ie2)
  8166. {
  8167. word i;
  8168. if (!ie1 || !ie2) return false;
  8169. if (!ie1[0]) return false;
  8170. for (i = 0; i < (word)(ie1[0] + 1); i++) if (ie1[i] != ie2[i]) return false;
  8171. return true;
  8172. }
  8173. static word find_cip(DIVA_CAPI_ADAPTER *a, byte *bc, byte *hlc)
  8174. {
  8175. word i;
  8176. word j;
  8177. for (i = 9; i && !ie_compare(bc, cip_bc[i][a->u_law]); i--);
  8178. for (j = 16; j < 29 &&
  8179. (!ie_compare(bc, cip_bc[j][a->u_law]) || !ie_compare(hlc, cip_hlc[j])); j++);
  8180. if (j == 29) return i;
  8181. return j;
  8182. }
  8183. static byte AddInfo(byte **add_i,
  8184. byte **fty_i,
  8185. byte *esc_chi,
  8186. byte *facility)
  8187. {
  8188. byte i;
  8189. byte j;
  8190. byte k;
  8191. byte flen;
  8192. byte len = 0;
  8193. /* facility is a nested structure */
  8194. /* FTY can be more than once */
  8195. if (esc_chi[0] && !(esc_chi[esc_chi[0]] & 0x7f))
  8196. {
  8197. add_i[0] = (byte *)"\x02\x02\x00"; /* use neither b nor d channel */
  8198. }
  8199. else
  8200. {
  8201. add_i[0] = (byte *)"";
  8202. }
  8203. if (!fty_i[0][0])
  8204. {
  8205. add_i[3] = (byte *)"";
  8206. }
  8207. else
  8208. { /* facility array found */
  8209. for (i = 0, j = 1; i < MAX_MULTI_IE && fty_i[i][0]; i++)
  8210. {
  8211. dbug(1, dprintf("AddIFac[%d]", fty_i[i][0]));
  8212. len += fty_i[i][0];
  8213. len += 2;
  8214. flen = fty_i[i][0];
  8215. facility[j++] = 0x1c; /* copy fac IE */
  8216. for (k = 0; k <= flen; k++, j++)
  8217. {
  8218. facility[j] = fty_i[i][k];
  8219. /* dbug(1, dprintf("%x ",facility[j])); */
  8220. }
  8221. }
  8222. facility[0] = len;
  8223. add_i[3] = facility;
  8224. }
  8225. /* dbug(1, dprintf("FacArrLen=%d ",len)); */
  8226. len = add_i[0][0] + add_i[1][0] + add_i[2][0] + add_i[3][0];
  8227. len += 4; /* calculate length of all */
  8228. return (len);
  8229. }
  8230. /*------------------------------------------------------------------*/
  8231. /* voice and codec features */
  8232. /*------------------------------------------------------------------*/
  8233. static void SetVoiceChannel(PLCI *plci, byte *chi, DIVA_CAPI_ADAPTER *a)
  8234. {
  8235. byte voice_chi[] = "\x02\x18\x01";
  8236. byte channel;
  8237. channel = chi[chi[0]] & 0x3;
  8238. dbug(1, dprintf("ExtDevON(Ch=0x%x)", channel));
  8239. voice_chi[2] = (channel) ? channel : 1;
  8240. add_p(plci, FTY, "\x02\x01\x07"); /* B On, default on 1 */
  8241. add_p(plci, ESC, voice_chi); /* Channel */
  8242. sig_req(plci, TEL_CTRL, 0);
  8243. send_req(plci);
  8244. if (a->AdvSignalPLCI)
  8245. {
  8246. adv_voice_write_coefs(a->AdvSignalPLCI, ADV_VOICE_WRITE_ACTIVATION);
  8247. }
  8248. }
  8249. static void VoiceChannelOff(PLCI *plci)
  8250. {
  8251. dbug(1, dprintf("ExtDevOFF"));
  8252. add_p(plci, FTY, "\x02\x01\x08"); /* B Off */
  8253. sig_req(plci, TEL_CTRL, 0);
  8254. send_req(plci);
  8255. if (plci->adapter->AdvSignalPLCI)
  8256. {
  8257. adv_voice_clear_config(plci->adapter->AdvSignalPLCI);
  8258. }
  8259. }
  8260. static word AdvCodecSupport(DIVA_CAPI_ADAPTER *a, PLCI *plci, APPL *appl,
  8261. byte hook_listen)
  8262. {
  8263. word j;
  8264. PLCI *splci;
  8265. /* check if hardware supports handset with hook states (adv.codec) */
  8266. /* or if just a on board codec is supported */
  8267. /* the advanced codec plci is just for internal use */
  8268. /* diva Pro with on-board codec: */
  8269. if (a->profile.Global_Options & HANDSET)
  8270. {
  8271. /* new call, but hook states are already signalled */
  8272. if (a->AdvCodecFLAG)
  8273. {
  8274. if (a->AdvSignalAppl != appl || a->AdvSignalPLCI)
  8275. {
  8276. dbug(1, dprintf("AdvSigPlci=0x%x", a->AdvSignalPLCI));
  8277. return 0x2001; /* codec in use by another application */
  8278. }
  8279. if (plci != NULL)
  8280. {
  8281. a->AdvSignalPLCI = plci;
  8282. plci->tel = ADV_VOICE;
  8283. }
  8284. return 0; /* adv codec still used */
  8285. }
  8286. if ((j = get_plci(a)))
  8287. {
  8288. splci = &a->plci[j - 1];
  8289. splci->tel = CODEC_PERMANENT;
  8290. /* hook_listen indicates if a facility_req with handset/hook support */
  8291. /* was sent. Otherwise if just a call on an external device was made */
  8292. /* the codec will be used but the hook info will be discarded (just */
  8293. /* the external controller is in use */
  8294. if (hook_listen) splci->State = ADVANCED_VOICE_SIG;
  8295. else
  8296. {
  8297. splci->State = ADVANCED_VOICE_NOSIG;
  8298. if (plci)
  8299. {
  8300. plci->spoofed_msg = SPOOFING_REQUIRED;
  8301. }
  8302. /* indicate D-ch connect if */
  8303. } /* codec is connected OK */
  8304. if (plci != NULL)
  8305. {
  8306. a->AdvSignalPLCI = plci;
  8307. plci->tel = ADV_VOICE;
  8308. }
  8309. a->AdvSignalAppl = appl;
  8310. a->AdvCodecFLAG = true;
  8311. a->AdvCodecPLCI = splci;
  8312. add_p(splci, CAI, "\x01\x15");
  8313. add_p(splci, LLI, "\x01\x00");
  8314. add_p(splci, ESC, "\x02\x18\x00");
  8315. add_p(splci, UID, "\x06\x43\x61\x70\x69\x32\x30");
  8316. splci->internal_command = PERM_COD_ASSIGN;
  8317. dbug(1, dprintf("Codec Assign"));
  8318. sig_req(splci, ASSIGN, DSIG_ID);
  8319. send_req(splci);
  8320. }
  8321. else
  8322. {
  8323. return 0x2001; /* wrong state, no more plcis */
  8324. }
  8325. }
  8326. else if (a->profile.Global_Options & ON_BOARD_CODEC)
  8327. {
  8328. if (hook_listen) return 0x300B; /* Facility not supported */
  8329. /* no hook with SCOM */
  8330. if (plci != NULL) plci->tel = CODEC;
  8331. dbug(1, dprintf("S/SCOM codec"));
  8332. /* first time we use the scom-s codec we must shut down the internal */
  8333. /* handset application of the card. This can be done by an assign with */
  8334. /* a cai with the 0x80 bit set. Assign return code is 'out of resource'*/
  8335. if (!a->scom_appl_disable) {
  8336. if ((j = get_plci(a))) {
  8337. splci = &a->plci[j - 1];
  8338. add_p(splci, CAI, "\x01\x80");
  8339. add_p(splci, UID, "\x06\x43\x61\x70\x69\x32\x30");
  8340. sig_req(splci, ASSIGN, 0xC0); /* 0xc0 is the TEL_ID */
  8341. send_req(splci);
  8342. a->scom_appl_disable = true;
  8343. }
  8344. else{
  8345. return 0x2001; /* wrong state, no more plcis */
  8346. }
  8347. }
  8348. }
  8349. else return 0x300B; /* Facility not supported */
  8350. return 0;
  8351. }
  8352. static void CodecIdCheck(DIVA_CAPI_ADAPTER *a, PLCI *plci)
  8353. {
  8354. dbug(1, dprintf("CodecIdCheck"));
  8355. if (a->AdvSignalPLCI == plci)
  8356. {
  8357. dbug(1, dprintf("PLCI owns codec"));
  8358. VoiceChannelOff(a->AdvCodecPLCI);
  8359. if (a->AdvCodecPLCI->State == ADVANCED_VOICE_NOSIG)
  8360. {
  8361. dbug(1, dprintf("remove temp codec PLCI"));
  8362. plci_remove(a->AdvCodecPLCI);
  8363. a->AdvCodecFLAG = 0;
  8364. a->AdvCodecPLCI = NULL;
  8365. a->AdvSignalAppl = NULL;
  8366. }
  8367. a->AdvSignalPLCI = NULL;
  8368. }
  8369. }
  8370. /* -------------------------------------------------------------------
  8371. Ask for physical address of card on PCI bus
  8372. ------------------------------------------------------------------- */
  8373. static void diva_ask_for_xdi_sdram_bar(DIVA_CAPI_ADAPTER *a,
  8374. IDI_SYNC_REQ *preq) {
  8375. a->sdram_bar = 0;
  8376. if (diva_xdi_extended_features & DIVA_CAPI_XDI_PROVIDES_SDRAM_BAR) {
  8377. ENTITY *e = (ENTITY *)preq;
  8378. e->user[0] = a->Id - 1;
  8379. preq->xdi_sdram_bar.info.bar = 0;
  8380. preq->xdi_sdram_bar.Req = 0;
  8381. preq->xdi_sdram_bar.Rc = IDI_SYNC_REQ_XDI_GET_ADAPTER_SDRAM_BAR;
  8382. (*(a->request))(e);
  8383. a->sdram_bar = preq->xdi_sdram_bar.info.bar;
  8384. dbug(3, dprintf("A(%d) SDRAM BAR = %08x", a->Id, a->sdram_bar));
  8385. }
  8386. }
  8387. /* -------------------------------------------------------------------
  8388. Ask XDI about extended features
  8389. ------------------------------------------------------------------- */
  8390. static void diva_get_extended_adapter_features(DIVA_CAPI_ADAPTER *a) {
  8391. IDI_SYNC_REQ *preq;
  8392. char buffer[((sizeof(preq->xdi_extended_features) + 4) > sizeof(ENTITY)) ? (sizeof(preq->xdi_extended_features) + 4) : sizeof(ENTITY)];
  8393. char features[4];
  8394. preq = (IDI_SYNC_REQ *)&buffer[0];
  8395. if (!diva_xdi_extended_features) {
  8396. ENTITY *e = (ENTITY *)preq;
  8397. diva_xdi_extended_features |= 0x80000000;
  8398. e->user[0] = a->Id - 1;
  8399. preq->xdi_extended_features.Req = 0;
  8400. preq->xdi_extended_features.Rc = IDI_SYNC_REQ_XDI_GET_EXTENDED_FEATURES;
  8401. preq->xdi_extended_features.info.buffer_length_in_bytes = sizeof(features);
  8402. preq->xdi_extended_features.info.features = &features[0];
  8403. (*(a->request))(e);
  8404. if (features[0] & DIVA_XDI_EXTENDED_FEATURES_VALID) {
  8405. /*
  8406. Check features located in the byte '0'
  8407. */
  8408. if (features[0] & DIVA_XDI_EXTENDED_FEATURE_CMA) {
  8409. diva_xdi_extended_features |= DIVA_CAPI_USE_CMA;
  8410. }
  8411. if (features[0] & DIVA_XDI_EXTENDED_FEATURE_RX_DMA) {
  8412. diva_xdi_extended_features |= DIVA_CAPI_XDI_PROVIDES_RX_DMA;
  8413. dbug(1, dprintf("XDI provides RxDMA"));
  8414. }
  8415. if (features[0] & DIVA_XDI_EXTENDED_FEATURE_SDRAM_BAR) {
  8416. diva_xdi_extended_features |= DIVA_CAPI_XDI_PROVIDES_SDRAM_BAR;
  8417. }
  8418. if (features[0] & DIVA_XDI_EXTENDED_FEATURE_NO_CANCEL_RC) {
  8419. diva_xdi_extended_features |= DIVA_CAPI_XDI_PROVIDES_NO_CANCEL;
  8420. dbug(3, dprintf("XDI provides NO_CANCEL_RC feature"));
  8421. }
  8422. }
  8423. }
  8424. diva_ask_for_xdi_sdram_bar(a, preq);
  8425. }
  8426. /*------------------------------------------------------------------*/
  8427. /* automatic law */
  8428. /*------------------------------------------------------------------*/
  8429. /* called from OS specific part after init time to get the Law */
  8430. /* a-law (Euro) and u-law (us,japan) use different BCs in the Setup message */
  8431. void AutomaticLaw(DIVA_CAPI_ADAPTER *a)
  8432. {
  8433. word j;
  8434. PLCI *splci;
  8435. if (a->automatic_law) {
  8436. return;
  8437. }
  8438. if ((j = get_plci(a))) {
  8439. diva_get_extended_adapter_features(a);
  8440. splci = &a->plci[j - 1];
  8441. a->automatic_lawPLCI = splci;
  8442. a->automatic_law = 1;
  8443. add_p(splci, CAI, "\x01\x80");
  8444. add_p(splci, UID, "\x06\x43\x61\x70\x69\x32\x30");
  8445. splci->internal_command = USELAW_REQ;
  8446. splci->command = 0;
  8447. splci->number = 0;
  8448. sig_req(splci, ASSIGN, DSIG_ID);
  8449. send_req(splci);
  8450. }
  8451. }
  8452. /* called from OS specific part if an application sends an Capi20Release */
  8453. word CapiRelease(word Id)
  8454. {
  8455. word i, j, appls_found;
  8456. PLCI *plci;
  8457. APPL *this;
  8458. DIVA_CAPI_ADAPTER *a;
  8459. if (!Id)
  8460. {
  8461. dbug(0, dprintf("A: CapiRelease(Id==0)"));
  8462. return (_WRONG_APPL_ID);
  8463. }
  8464. this = &application[Id - 1]; /* get application pointer */
  8465. for (i = 0, appls_found = 0; i < max_appl; i++)
  8466. {
  8467. if (application[i].Id) /* an application has been found */
  8468. {
  8469. appls_found++;
  8470. }
  8471. }
  8472. for (i = 0; i < max_adapter; i++) /* scan all adapters... */
  8473. {
  8474. a = &adapter[i];
  8475. if (a->request)
  8476. {
  8477. a->Info_Mask[Id - 1] = 0;
  8478. a->CIP_Mask[Id - 1] = 0;
  8479. a->Notification_Mask[Id - 1] = 0;
  8480. a->codec_listen[Id - 1] = NULL;
  8481. a->requested_options_table[Id - 1] = 0;
  8482. for (j = 0; j < a->max_plci; j++) /* and all PLCIs connected */
  8483. { /* with this application */
  8484. plci = &a->plci[j];
  8485. if (plci->Id) /* if plci owns no application */
  8486. { /* it may be not jet connected */
  8487. if (plci->State == INC_CON_PENDING
  8488. || plci->State == INC_CON_ALERT)
  8489. {
  8490. if (test_bit(Id - 1, plci->c_ind_mask_table))
  8491. {
  8492. __clear_bit(Id - 1, plci->c_ind_mask_table);
  8493. if (bitmap_empty(plci->c_ind_mask_table, MAX_APPL))
  8494. {
  8495. sig_req(plci, HANGUP, 0);
  8496. send_req(plci);
  8497. plci->State = OUTG_DIS_PENDING;
  8498. }
  8499. }
  8500. }
  8501. if (test_bit(Id - 1, plci->c_ind_mask_table))
  8502. {
  8503. __clear_bit(Id - 1, plci->c_ind_mask_table);
  8504. if (bitmap_empty(plci->c_ind_mask_table, MAX_APPL))
  8505. {
  8506. if (!plci->appl)
  8507. {
  8508. plci_remove(plci);
  8509. plci->State = IDLE;
  8510. }
  8511. }
  8512. }
  8513. if (plci->appl == this)
  8514. {
  8515. plci->appl = NULL;
  8516. plci_remove(plci);
  8517. plci->State = IDLE;
  8518. }
  8519. }
  8520. }
  8521. listen_check(a);
  8522. if (a->flag_dynamic_l1_down)
  8523. {
  8524. if (appls_found == 1) /* last application does a capi release */
  8525. {
  8526. if ((j = get_plci(a)))
  8527. {
  8528. plci = &a->plci[j - 1];
  8529. plci->command = 0;
  8530. add_p(plci, OAD, "\x01\xfd");
  8531. add_p(plci, CAI, "\x01\x80");
  8532. add_p(plci, UID, "\x06\x43\x61\x70\x69\x32\x30");
  8533. add_p(plci, SHIFT | 6, NULL);
  8534. add_p(plci, SIN, "\x02\x00\x00");
  8535. plci->internal_command = REM_L1_SIG_ASSIGN_PEND;
  8536. sig_req(plci, ASSIGN, DSIG_ID);
  8537. add_p(plci, FTY, "\x02\xff\x06"); /* l1 down */
  8538. sig_req(plci, SIG_CTRL, 0);
  8539. send_req(plci);
  8540. }
  8541. }
  8542. }
  8543. if (a->AdvSignalAppl == this)
  8544. {
  8545. this->NullCREnable = false;
  8546. if (a->AdvCodecPLCI)
  8547. {
  8548. plci_remove(a->AdvCodecPLCI);
  8549. a->AdvCodecPLCI->tel = 0;
  8550. a->AdvCodecPLCI->adv_nl = 0;
  8551. }
  8552. a->AdvSignalAppl = NULL;
  8553. a->AdvSignalPLCI = NULL;
  8554. a->AdvCodecFLAG = 0;
  8555. a->AdvCodecPLCI = NULL;
  8556. }
  8557. }
  8558. }
  8559. this->Id = 0;
  8560. return GOOD;
  8561. }
  8562. static word plci_remove_check(PLCI *plci)
  8563. {
  8564. if (!plci) return true;
  8565. if (!plci->NL.Id && bitmap_empty(plci->c_ind_mask_table, MAX_APPL))
  8566. {
  8567. if (plci->Sig.Id == 0xff)
  8568. plci->Sig.Id = 0;
  8569. if (!plci->Sig.Id)
  8570. {
  8571. dbug(1, dprintf("plci_remove_complete(%x)", plci->Id));
  8572. dbug(1, dprintf("tel=0x%x,Sig=0x%x", plci->tel, plci->Sig.Id));
  8573. if (plci->Id)
  8574. {
  8575. CodecIdCheck(plci->adapter, plci);
  8576. clear_b1_config(plci);
  8577. ncci_remove(plci, 0, false);
  8578. plci_free_msg_in_queue(plci);
  8579. channel_flow_control_remove(plci);
  8580. plci->Id = 0;
  8581. plci->State = IDLE;
  8582. plci->channels = 0;
  8583. plci->appl = NULL;
  8584. plci->notifiedcall = 0;
  8585. }
  8586. listen_check(plci->adapter);
  8587. return true;
  8588. }
  8589. }
  8590. return false;
  8591. }
  8592. /*------------------------------------------------------------------*/
  8593. static byte plci_nl_busy(PLCI *plci)
  8594. {
  8595. /* only applicable for non-multiplexed protocols */
  8596. return (plci->nl_req
  8597. || (plci->ncci_ring_list
  8598. && plci->adapter->ncci_ch[plci->ncci_ring_list]
  8599. && (plci->adapter->ch_flow_control[plci->adapter->ncci_ch[plci->ncci_ring_list]] & N_OK_FC_PENDING)));
  8600. }
  8601. /*------------------------------------------------------------------*/
  8602. /* DTMF facilities */
  8603. /*------------------------------------------------------------------*/
  8604. static struct
  8605. {
  8606. byte send_mask;
  8607. byte listen_mask;
  8608. byte character;
  8609. byte code;
  8610. } dtmf_digit_map[] =
  8611. {
  8612. { 0x01, 0x01, 0x23, DTMF_DIGIT_TONE_CODE_HASHMARK },
  8613. { 0x01, 0x01, 0x2a, DTMF_DIGIT_TONE_CODE_STAR },
  8614. { 0x01, 0x01, 0x30, DTMF_DIGIT_TONE_CODE_0 },
  8615. { 0x01, 0x01, 0x31, DTMF_DIGIT_TONE_CODE_1 },
  8616. { 0x01, 0x01, 0x32, DTMF_DIGIT_TONE_CODE_2 },
  8617. { 0x01, 0x01, 0x33, DTMF_DIGIT_TONE_CODE_3 },
  8618. { 0x01, 0x01, 0x34, DTMF_DIGIT_TONE_CODE_4 },
  8619. { 0x01, 0x01, 0x35, DTMF_DIGIT_TONE_CODE_5 },
  8620. { 0x01, 0x01, 0x36, DTMF_DIGIT_TONE_CODE_6 },
  8621. { 0x01, 0x01, 0x37, DTMF_DIGIT_TONE_CODE_7 },
  8622. { 0x01, 0x01, 0x38, DTMF_DIGIT_TONE_CODE_8 },
  8623. { 0x01, 0x01, 0x39, DTMF_DIGIT_TONE_CODE_9 },
  8624. { 0x01, 0x01, 0x41, DTMF_DIGIT_TONE_CODE_A },
  8625. { 0x01, 0x01, 0x42, DTMF_DIGIT_TONE_CODE_B },
  8626. { 0x01, 0x01, 0x43, DTMF_DIGIT_TONE_CODE_C },
  8627. { 0x01, 0x01, 0x44, DTMF_DIGIT_TONE_CODE_D },
  8628. { 0x01, 0x00, 0x61, DTMF_DIGIT_TONE_CODE_A },
  8629. { 0x01, 0x00, 0x62, DTMF_DIGIT_TONE_CODE_B },
  8630. { 0x01, 0x00, 0x63, DTMF_DIGIT_TONE_CODE_C },
  8631. { 0x01, 0x00, 0x64, DTMF_DIGIT_TONE_CODE_D },
  8632. { 0x04, 0x04, 0x80, DTMF_SIGNAL_NO_TONE },
  8633. { 0x00, 0x04, 0x81, DTMF_SIGNAL_UNIDENTIFIED_TONE },
  8634. { 0x04, 0x04, 0x82, DTMF_SIGNAL_DIAL_TONE },
  8635. { 0x04, 0x04, 0x83, DTMF_SIGNAL_PABX_INTERNAL_DIAL_TONE },
  8636. { 0x04, 0x04, 0x84, DTMF_SIGNAL_SPECIAL_DIAL_TONE },
  8637. { 0x04, 0x04, 0x85, DTMF_SIGNAL_SECOND_DIAL_TONE },
  8638. { 0x04, 0x04, 0x86, DTMF_SIGNAL_RINGING_TONE },
  8639. { 0x04, 0x04, 0x87, DTMF_SIGNAL_SPECIAL_RINGING_TONE },
  8640. { 0x04, 0x04, 0x88, DTMF_SIGNAL_BUSY_TONE },
  8641. { 0x04, 0x04, 0x89, DTMF_SIGNAL_CONGESTION_TONE },
  8642. { 0x04, 0x04, 0x8a, DTMF_SIGNAL_SPECIAL_INFORMATION_TONE },
  8643. { 0x04, 0x04, 0x8b, DTMF_SIGNAL_COMFORT_TONE },
  8644. { 0x04, 0x04, 0x8c, DTMF_SIGNAL_HOLD_TONE },
  8645. { 0x04, 0x04, 0x8d, DTMF_SIGNAL_RECORD_TONE },
  8646. { 0x04, 0x04, 0x8e, DTMF_SIGNAL_CALLER_WAITING_TONE },
  8647. { 0x04, 0x04, 0x8f, DTMF_SIGNAL_CALL_WAITING_TONE },
  8648. { 0x04, 0x04, 0x90, DTMF_SIGNAL_PAY_TONE },
  8649. { 0x04, 0x04, 0x91, DTMF_SIGNAL_POSITIVE_INDICATION_TONE },
  8650. { 0x04, 0x04, 0x92, DTMF_SIGNAL_NEGATIVE_INDICATION_TONE },
  8651. { 0x04, 0x04, 0x93, DTMF_SIGNAL_WARNING_TONE },
  8652. { 0x04, 0x04, 0x94, DTMF_SIGNAL_INTRUSION_TONE },
  8653. { 0x04, 0x04, 0x95, DTMF_SIGNAL_CALLING_CARD_SERVICE_TONE },
  8654. { 0x04, 0x04, 0x96, DTMF_SIGNAL_PAYPHONE_RECOGNITION_TONE },
  8655. { 0x04, 0x04, 0x97, DTMF_SIGNAL_CPE_ALERTING_SIGNAL },
  8656. { 0x04, 0x04, 0x98, DTMF_SIGNAL_OFF_HOOK_WARNING_TONE },
  8657. { 0x04, 0x04, 0xbf, DTMF_SIGNAL_INTERCEPT_TONE },
  8658. { 0x04, 0x04, 0xc0, DTMF_SIGNAL_MODEM_CALLING_TONE },
  8659. { 0x04, 0x04, 0xc1, DTMF_SIGNAL_FAX_CALLING_TONE },
  8660. { 0x04, 0x04, 0xc2, DTMF_SIGNAL_ANSWER_TONE },
  8661. { 0x04, 0x04, 0xc3, DTMF_SIGNAL_REVERSED_ANSWER_TONE },
  8662. { 0x04, 0x04, 0xc4, DTMF_SIGNAL_ANSAM_TONE },
  8663. { 0x04, 0x04, 0xc5, DTMF_SIGNAL_REVERSED_ANSAM_TONE },
  8664. { 0x04, 0x04, 0xc6, DTMF_SIGNAL_BELL103_ANSWER_TONE },
  8665. { 0x04, 0x04, 0xc7, DTMF_SIGNAL_FAX_FLAGS },
  8666. { 0x04, 0x04, 0xc8, DTMF_SIGNAL_G2_FAX_GROUP_ID },
  8667. { 0x00, 0x04, 0xc9, DTMF_SIGNAL_HUMAN_SPEECH },
  8668. { 0x04, 0x04, 0xca, DTMF_SIGNAL_ANSWERING_MACHINE_390 },
  8669. { 0x02, 0x02, 0xf1, DTMF_MF_DIGIT_TONE_CODE_1 },
  8670. { 0x02, 0x02, 0xf2, DTMF_MF_DIGIT_TONE_CODE_2 },
  8671. { 0x02, 0x02, 0xf3, DTMF_MF_DIGIT_TONE_CODE_3 },
  8672. { 0x02, 0x02, 0xf4, DTMF_MF_DIGIT_TONE_CODE_4 },
  8673. { 0x02, 0x02, 0xf5, DTMF_MF_DIGIT_TONE_CODE_5 },
  8674. { 0x02, 0x02, 0xf6, DTMF_MF_DIGIT_TONE_CODE_6 },
  8675. { 0x02, 0x02, 0xf7, DTMF_MF_DIGIT_TONE_CODE_7 },
  8676. { 0x02, 0x02, 0xf8, DTMF_MF_DIGIT_TONE_CODE_8 },
  8677. { 0x02, 0x02, 0xf9, DTMF_MF_DIGIT_TONE_CODE_9 },
  8678. { 0x02, 0x02, 0xfa, DTMF_MF_DIGIT_TONE_CODE_0 },
  8679. { 0x02, 0x02, 0xfb, DTMF_MF_DIGIT_TONE_CODE_K1 },
  8680. { 0x02, 0x02, 0xfc, DTMF_MF_DIGIT_TONE_CODE_K2 },
  8681. { 0x02, 0x02, 0xfd, DTMF_MF_DIGIT_TONE_CODE_KP },
  8682. { 0x02, 0x02, 0xfe, DTMF_MF_DIGIT_TONE_CODE_S1 },
  8683. { 0x02, 0x02, 0xff, DTMF_MF_DIGIT_TONE_CODE_ST },
  8684. };
  8685. #define DTMF_DIGIT_MAP_ENTRIES ARRAY_SIZE(dtmf_digit_map)
  8686. static void dtmf_enable_receiver(PLCI *plci, byte enable_mask)
  8687. {
  8688. word min_digit_duration, min_gap_duration;
  8689. dbug(1, dprintf("[%06lx] %s,%d: dtmf_enable_receiver %02x",
  8690. (dword)((plci->Id << 8) | UnMapController(plci->adapter->Id)),
  8691. (char *)(FILE_), __LINE__, enable_mask));
  8692. if (enable_mask != 0)
  8693. {
  8694. min_digit_duration = (plci->dtmf_rec_pulse_ms == 0) ? 40 : plci->dtmf_rec_pulse_ms;
  8695. min_gap_duration = (plci->dtmf_rec_pause_ms == 0) ? 40 : plci->dtmf_rec_pause_ms;
  8696. plci->internal_req_buffer[0] = DTMF_UDATA_REQUEST_ENABLE_RECEIVER;
  8697. PUT_WORD(&plci->internal_req_buffer[1], min_digit_duration);
  8698. PUT_WORD(&plci->internal_req_buffer[3], min_gap_duration);
  8699. plci->NData[0].PLength = 5;
  8700. PUT_WORD(&plci->internal_req_buffer[5], INTERNAL_IND_BUFFER_SIZE);
  8701. plci->NData[0].PLength += 2;
  8702. capidtmf_recv_enable(&(plci->capidtmf_state), min_digit_duration, min_gap_duration);
  8703. }
  8704. else
  8705. {
  8706. plci->internal_req_buffer[0] = DTMF_UDATA_REQUEST_DISABLE_RECEIVER;
  8707. plci->NData[0].PLength = 1;
  8708. capidtmf_recv_disable(&(plci->capidtmf_state));
  8709. }
  8710. plci->NData[0].P = plci->internal_req_buffer;
  8711. plci->NL.X = plci->NData;
  8712. plci->NL.ReqCh = 0;
  8713. plci->NL.Req = plci->nl_req = (byte) N_UDATA;
  8714. plci->adapter->request(&plci->NL);
  8715. }
  8716. static void dtmf_send_digits(PLCI *plci, byte *digit_buffer, word digit_count)
  8717. {
  8718. word w, i;
  8719. dbug(1, dprintf("[%06lx] %s,%d: dtmf_send_digits %d",
  8720. (dword)((plci->Id << 8) | UnMapController(plci->adapter->Id)),
  8721. (char *)(FILE_), __LINE__, digit_count));
  8722. plci->internal_req_buffer[0] = DTMF_UDATA_REQUEST_SEND_DIGITS;
  8723. w = (plci->dtmf_send_pulse_ms == 0) ? 40 : plci->dtmf_send_pulse_ms;
  8724. PUT_WORD(&plci->internal_req_buffer[1], w);
  8725. w = (plci->dtmf_send_pause_ms == 0) ? 40 : plci->dtmf_send_pause_ms;
  8726. PUT_WORD(&plci->internal_req_buffer[3], w);
  8727. for (i = 0; i < digit_count; i++)
  8728. {
  8729. w = 0;
  8730. while ((w < DTMF_DIGIT_MAP_ENTRIES)
  8731. && (digit_buffer[i] != dtmf_digit_map[w].character))
  8732. {
  8733. w++;
  8734. }
  8735. plci->internal_req_buffer[5 + i] = (w < DTMF_DIGIT_MAP_ENTRIES) ?
  8736. dtmf_digit_map[w].code : DTMF_DIGIT_TONE_CODE_STAR;
  8737. }
  8738. plci->NData[0].PLength = 5 + digit_count;
  8739. plci->NData[0].P = plci->internal_req_buffer;
  8740. plci->NL.X = plci->NData;
  8741. plci->NL.ReqCh = 0;
  8742. plci->NL.Req = plci->nl_req = (byte) N_UDATA;
  8743. plci->adapter->request(&plci->NL);
  8744. }
  8745. static void dtmf_rec_clear_config(PLCI *plci)
  8746. {
  8747. dbug(1, dprintf("[%06lx] %s,%d: dtmf_rec_clear_config",
  8748. (dword)((plci->Id << 8) | UnMapController(plci->adapter->Id)),
  8749. (char *)(FILE_), __LINE__));
  8750. plci->dtmf_rec_active = 0;
  8751. plci->dtmf_rec_pulse_ms = 0;
  8752. plci->dtmf_rec_pause_ms = 0;
  8753. capidtmf_init(&(plci->capidtmf_state), plci->adapter->u_law);
  8754. }
  8755. static void dtmf_send_clear_config(PLCI *plci)
  8756. {
  8757. dbug(1, dprintf("[%06lx] %s,%d: dtmf_send_clear_config",
  8758. (dword)((plci->Id << 8) | UnMapController(plci->adapter->Id)),
  8759. (char *)(FILE_), __LINE__));
  8760. plci->dtmf_send_requests = 0;
  8761. plci->dtmf_send_pulse_ms = 0;
  8762. plci->dtmf_send_pause_ms = 0;
  8763. }
  8764. static void dtmf_prepare_switch(dword Id, PLCI *plci)
  8765. {
  8766. dbug(1, dprintf("[%06lx] %s,%d: dtmf_prepare_switch",
  8767. UnMapId(Id), (char *)(FILE_), __LINE__));
  8768. while (plci->dtmf_send_requests != 0)
  8769. dtmf_confirmation(Id, plci);
  8770. }
  8771. static word dtmf_save_config(dword Id, PLCI *plci, byte Rc)
  8772. {
  8773. dbug(1, dprintf("[%06lx] %s,%d: dtmf_save_config %02x %d",
  8774. UnMapId(Id), (char *)(FILE_), __LINE__, Rc, plci->adjust_b_state));
  8775. return (GOOD);
  8776. }
  8777. static word dtmf_restore_config(dword Id, PLCI *plci, byte Rc)
  8778. {
  8779. word Info;
  8780. dbug(1, dprintf("[%06lx] %s,%d: dtmf_restore_config %02x %d",
  8781. UnMapId(Id), (char *)(FILE_), __LINE__, Rc, plci->adjust_b_state));
  8782. Info = GOOD;
  8783. if (plci->B1_facilities & B1_FACILITY_DTMFR)
  8784. {
  8785. switch (plci->adjust_b_state)
  8786. {
  8787. case ADJUST_B_RESTORE_DTMF_1:
  8788. plci->internal_command = plci->adjust_b_command;
  8789. if (plci_nl_busy(plci))
  8790. {
  8791. plci->adjust_b_state = ADJUST_B_RESTORE_DTMF_1;
  8792. break;
  8793. }
  8794. dtmf_enable_receiver(plci, plci->dtmf_rec_active);
  8795. plci->adjust_b_state = ADJUST_B_RESTORE_DTMF_2;
  8796. break;
  8797. case ADJUST_B_RESTORE_DTMF_2:
  8798. if ((Rc != OK) && (Rc != OK_FC))
  8799. {
  8800. dbug(1, dprintf("[%06lx] %s,%d: Reenable DTMF receiver failed %02x",
  8801. UnMapId(Id), (char *)(FILE_), __LINE__, Rc));
  8802. Info = _WRONG_STATE;
  8803. break;
  8804. }
  8805. break;
  8806. }
  8807. }
  8808. return (Info);
  8809. }
  8810. static void dtmf_command(dword Id, PLCI *plci, byte Rc)
  8811. {
  8812. word internal_command, Info;
  8813. byte mask;
  8814. byte result[4];
  8815. dbug(1, dprintf("[%06lx] %s,%d: dtmf_command %02x %04x %04x %d %d %d %d",
  8816. UnMapId(Id), (char *)(FILE_), __LINE__, Rc, plci->internal_command,
  8817. plci->dtmf_cmd, plci->dtmf_rec_pulse_ms, plci->dtmf_rec_pause_ms,
  8818. plci->dtmf_send_pulse_ms, plci->dtmf_send_pause_ms));
  8819. Info = GOOD;
  8820. result[0] = 2;
  8821. PUT_WORD(&result[1], DTMF_SUCCESS);
  8822. internal_command = plci->internal_command;
  8823. plci->internal_command = 0;
  8824. mask = 0x01;
  8825. switch (plci->dtmf_cmd)
  8826. {
  8827. case DTMF_LISTEN_TONE_START:
  8828. mask <<= 1; /* fall through */
  8829. case DTMF_LISTEN_MF_START:
  8830. mask <<= 1; /* fall through */
  8831. case DTMF_LISTEN_START:
  8832. switch (internal_command)
  8833. {
  8834. default:
  8835. adjust_b1_resource(Id, plci, NULL, (word)(plci->B1_facilities |
  8836. B1_FACILITY_DTMFR), DTMF_COMMAND_1);
  8837. /* fall through */
  8838. case DTMF_COMMAND_1:
  8839. if (adjust_b_process(Id, plci, Rc) != GOOD)
  8840. {
  8841. dbug(1, dprintf("[%06lx] %s,%d: Load DTMF failed",
  8842. UnMapId(Id), (char *)(FILE_), __LINE__));
  8843. Info = _FACILITY_NOT_SUPPORTED;
  8844. break;
  8845. }
  8846. if (plci->internal_command)
  8847. return;
  8848. /* fall through */
  8849. case DTMF_COMMAND_2:
  8850. if (plci_nl_busy(plci))
  8851. {
  8852. plci->internal_command = DTMF_COMMAND_2;
  8853. return;
  8854. }
  8855. plci->internal_command = DTMF_COMMAND_3;
  8856. dtmf_enable_receiver(plci, (byte)(plci->dtmf_rec_active | mask));
  8857. return;
  8858. case DTMF_COMMAND_3:
  8859. if ((Rc != OK) && (Rc != OK_FC))
  8860. {
  8861. dbug(1, dprintf("[%06lx] %s,%d: Enable DTMF receiver failed %02x",
  8862. UnMapId(Id), (char *)(FILE_), __LINE__, Rc));
  8863. Info = _FACILITY_NOT_SUPPORTED;
  8864. break;
  8865. }
  8866. plci->tone_last_indication_code = DTMF_SIGNAL_NO_TONE;
  8867. plci->dtmf_rec_active |= mask;
  8868. break;
  8869. }
  8870. break;
  8871. case DTMF_LISTEN_TONE_STOP:
  8872. mask <<= 1; /* fall through */
  8873. case DTMF_LISTEN_MF_STOP:
  8874. mask <<= 1; /* fall through */
  8875. case DTMF_LISTEN_STOP:
  8876. switch (internal_command)
  8877. {
  8878. default:
  8879. plci->dtmf_rec_active &= ~mask;
  8880. if (plci->dtmf_rec_active)
  8881. break;
  8882. /*
  8883. case DTMF_COMMAND_1:
  8884. if (plci->dtmf_rec_active)
  8885. {
  8886. if (plci_nl_busy (plci))
  8887. {
  8888. plci->internal_command = DTMF_COMMAND_1;
  8889. return;
  8890. }
  8891. plci->dtmf_rec_active &= ~mask;
  8892. plci->internal_command = DTMF_COMMAND_2;
  8893. dtmf_enable_receiver (plci, false);
  8894. return;
  8895. }
  8896. Rc = OK;
  8897. case DTMF_COMMAND_2:
  8898. if ((Rc != OK) && (Rc != OK_FC))
  8899. {
  8900. dbug (1, dprintf("[%06lx] %s,%d: Disable DTMF receiver failed %02x",
  8901. UnMapId (Id), (char far *)(FILE_), __LINE__, Rc));
  8902. Info = _FACILITY_NOT_SUPPORTED;
  8903. break;
  8904. }
  8905. */
  8906. adjust_b1_resource(Id, plci, NULL, (word)(plci->B1_facilities &
  8907. ~(B1_FACILITY_DTMFX | B1_FACILITY_DTMFR)), DTMF_COMMAND_3);
  8908. /* fall through */
  8909. case DTMF_COMMAND_3:
  8910. if (adjust_b_process(Id, plci, Rc) != GOOD)
  8911. {
  8912. dbug(1, dprintf("[%06lx] %s,%d: Unload DTMF failed",
  8913. UnMapId(Id), (char *)(FILE_), __LINE__));
  8914. Info = _FACILITY_NOT_SUPPORTED;
  8915. break;
  8916. }
  8917. if (plci->internal_command)
  8918. return;
  8919. break;
  8920. }
  8921. break;
  8922. case DTMF_SEND_TONE:
  8923. mask <<= 1; /* fall through */
  8924. case DTMF_SEND_MF:
  8925. mask <<= 1; /* fall through */
  8926. case DTMF_DIGITS_SEND:
  8927. switch (internal_command)
  8928. {
  8929. default:
  8930. adjust_b1_resource(Id, plci, NULL, (word)(plci->B1_facilities |
  8931. ((plci->dtmf_parameter_length != 0) ? B1_FACILITY_DTMFX | B1_FACILITY_DTMFR : B1_FACILITY_DTMFX)),
  8932. DTMF_COMMAND_1);
  8933. /* fall through */
  8934. case DTMF_COMMAND_1:
  8935. if (adjust_b_process(Id, plci, Rc) != GOOD)
  8936. {
  8937. dbug(1, dprintf("[%06lx] %s,%d: Load DTMF failed",
  8938. UnMapId(Id), (char *)(FILE_), __LINE__));
  8939. Info = _FACILITY_NOT_SUPPORTED;
  8940. break;
  8941. }
  8942. if (plci->internal_command)
  8943. return;
  8944. /* fall through */
  8945. case DTMF_COMMAND_2:
  8946. if (plci_nl_busy(plci))
  8947. {
  8948. plci->internal_command = DTMF_COMMAND_2;
  8949. return;
  8950. }
  8951. plci->dtmf_msg_number_queue[(plci->dtmf_send_requests)++] = plci->number;
  8952. plci->internal_command = DTMF_COMMAND_3;
  8953. dtmf_send_digits(plci, &plci->saved_msg.parms[3].info[1], plci->saved_msg.parms[3].length);
  8954. return;
  8955. case DTMF_COMMAND_3:
  8956. if ((Rc != OK) && (Rc != OK_FC))
  8957. {
  8958. dbug(1, dprintf("[%06lx] %s,%d: Send DTMF digits failed %02x",
  8959. UnMapId(Id), (char *)(FILE_), __LINE__, Rc));
  8960. if (plci->dtmf_send_requests != 0)
  8961. (plci->dtmf_send_requests)--;
  8962. Info = _FACILITY_NOT_SUPPORTED;
  8963. break;
  8964. }
  8965. return;
  8966. }
  8967. break;
  8968. }
  8969. sendf(plci->appl, _FACILITY_R | CONFIRM, Id & 0xffffL, plci->number,
  8970. "wws", Info, SELECTOR_DTMF, result);
  8971. }
  8972. static byte dtmf_request(dword Id, word Number, DIVA_CAPI_ADAPTER *a, PLCI *plci, APPL *appl, API_PARSE *msg)
  8973. {
  8974. word Info;
  8975. word i, j;
  8976. byte mask;
  8977. API_PARSE dtmf_parms[5];
  8978. byte result[40];
  8979. dbug(1, dprintf("[%06lx] %s,%d: dtmf_request",
  8980. UnMapId(Id), (char *)(FILE_), __LINE__));
  8981. Info = GOOD;
  8982. result[0] = 2;
  8983. PUT_WORD(&result[1], DTMF_SUCCESS);
  8984. if (!(a->profile.Global_Options & GL_DTMF_SUPPORTED))
  8985. {
  8986. dbug(1, dprintf("[%06lx] %s,%d: Facility not supported",
  8987. UnMapId(Id), (char *)(FILE_), __LINE__));
  8988. Info = _FACILITY_NOT_SUPPORTED;
  8989. }
  8990. else if (api_parse(&msg[1].info[1], msg[1].length, "w", dtmf_parms))
  8991. {
  8992. dbug(1, dprintf("[%06lx] %s,%d: Wrong message format",
  8993. UnMapId(Id), (char *)(FILE_), __LINE__));
  8994. Info = _WRONG_MESSAGE_FORMAT;
  8995. }
  8996. else if ((GET_WORD(dtmf_parms[0].info) == DTMF_GET_SUPPORTED_DETECT_CODES)
  8997. || (GET_WORD(dtmf_parms[0].info) == DTMF_GET_SUPPORTED_SEND_CODES))
  8998. {
  8999. if (!((a->requested_options_table[appl->Id - 1])
  9000. & (1L << PRIVATE_DTMF_TONE)))
  9001. {
  9002. dbug(1, dprintf("[%06lx] %s,%d: DTMF unknown request %04x",
  9003. UnMapId(Id), (char *)(FILE_), __LINE__, GET_WORD(dtmf_parms[0].info)));
  9004. PUT_WORD(&result[1], DTMF_UNKNOWN_REQUEST);
  9005. }
  9006. else
  9007. {
  9008. for (i = 0; i < 32; i++)
  9009. result[4 + i] = 0;
  9010. if (GET_WORD(dtmf_parms[0].info) == DTMF_GET_SUPPORTED_DETECT_CODES)
  9011. {
  9012. for (i = 0; i < DTMF_DIGIT_MAP_ENTRIES; i++)
  9013. {
  9014. if (dtmf_digit_map[i].listen_mask != 0)
  9015. result[4 + (dtmf_digit_map[i].character >> 3)] |= (1 << (dtmf_digit_map[i].character & 0x7));
  9016. }
  9017. }
  9018. else
  9019. {
  9020. for (i = 0; i < DTMF_DIGIT_MAP_ENTRIES; i++)
  9021. {
  9022. if (dtmf_digit_map[i].send_mask != 0)
  9023. result[4 + (dtmf_digit_map[i].character >> 3)] |= (1 << (dtmf_digit_map[i].character & 0x7));
  9024. }
  9025. }
  9026. result[0] = 3 + 32;
  9027. result[3] = 32;
  9028. }
  9029. }
  9030. else if (plci == NULL)
  9031. {
  9032. dbug(1, dprintf("[%06lx] %s,%d: Wrong PLCI",
  9033. UnMapId(Id), (char *)(FILE_), __LINE__));
  9034. Info = _WRONG_IDENTIFIER;
  9035. }
  9036. else
  9037. {
  9038. if (!plci->State
  9039. || !plci->NL.Id || plci->nl_remove_id)
  9040. {
  9041. dbug(1, dprintf("[%06lx] %s,%d: Wrong state",
  9042. UnMapId(Id), (char *)(FILE_), __LINE__));
  9043. Info = _WRONG_STATE;
  9044. }
  9045. else
  9046. {
  9047. plci->command = 0;
  9048. plci->dtmf_cmd = GET_WORD(dtmf_parms[0].info);
  9049. mask = 0x01;
  9050. switch (plci->dtmf_cmd)
  9051. {
  9052. case DTMF_LISTEN_TONE_START:
  9053. case DTMF_LISTEN_TONE_STOP:
  9054. mask <<= 1; /* fall through */
  9055. case DTMF_LISTEN_MF_START:
  9056. case DTMF_LISTEN_MF_STOP:
  9057. mask <<= 1;
  9058. if (!((plci->requested_options_conn | plci->requested_options | plci->adapter->requested_options_table[appl->Id - 1])
  9059. & (1L << PRIVATE_DTMF_TONE)))
  9060. {
  9061. dbug(1, dprintf("[%06lx] %s,%d: DTMF unknown request %04x",
  9062. UnMapId(Id), (char *)(FILE_), __LINE__, GET_WORD(dtmf_parms[0].info)));
  9063. PUT_WORD(&result[1], DTMF_UNKNOWN_REQUEST);
  9064. break;
  9065. }
  9066. /* fall through */
  9067. case DTMF_LISTEN_START:
  9068. case DTMF_LISTEN_STOP:
  9069. if (!(a->manufacturer_features & MANUFACTURER_FEATURE_HARDDTMF)
  9070. && !(a->manufacturer_features & MANUFACTURER_FEATURE_SOFTDTMF_RECEIVE))
  9071. {
  9072. dbug(1, dprintf("[%06lx] %s,%d: Facility not supported",
  9073. UnMapId(Id), (char *)(FILE_), __LINE__));
  9074. Info = _FACILITY_NOT_SUPPORTED;
  9075. break;
  9076. }
  9077. if (mask & DTMF_LISTEN_ACTIVE_FLAG)
  9078. {
  9079. if (api_parse(&msg[1].info[1], msg[1].length, "wwws", dtmf_parms))
  9080. {
  9081. plci->dtmf_rec_pulse_ms = 0;
  9082. plci->dtmf_rec_pause_ms = 0;
  9083. }
  9084. else
  9085. {
  9086. plci->dtmf_rec_pulse_ms = GET_WORD(dtmf_parms[1].info);
  9087. plci->dtmf_rec_pause_ms = GET_WORD(dtmf_parms[2].info);
  9088. }
  9089. }
  9090. start_internal_command(Id, plci, dtmf_command);
  9091. return (false);
  9092. case DTMF_SEND_TONE:
  9093. mask <<= 1; /* fall through */
  9094. case DTMF_SEND_MF:
  9095. mask <<= 1;
  9096. if (!((plci->requested_options_conn | plci->requested_options | plci->adapter->requested_options_table[appl->Id - 1])
  9097. & (1L << PRIVATE_DTMF_TONE)))
  9098. {
  9099. dbug(1, dprintf("[%06lx] %s,%d: DTMF unknown request %04x",
  9100. UnMapId(Id), (char *)(FILE_), __LINE__, GET_WORD(dtmf_parms[0].info)));
  9101. PUT_WORD(&result[1], DTMF_UNKNOWN_REQUEST);
  9102. break;
  9103. }
  9104. /* fall through */
  9105. case DTMF_DIGITS_SEND:
  9106. if (api_parse(&msg[1].info[1], msg[1].length, "wwws", dtmf_parms))
  9107. {
  9108. dbug(1, dprintf("[%06lx] %s,%d: Wrong message format",
  9109. UnMapId(Id), (char *)(FILE_), __LINE__));
  9110. Info = _WRONG_MESSAGE_FORMAT;
  9111. break;
  9112. }
  9113. if (mask & DTMF_LISTEN_ACTIVE_FLAG)
  9114. {
  9115. plci->dtmf_send_pulse_ms = GET_WORD(dtmf_parms[1].info);
  9116. plci->dtmf_send_pause_ms = GET_WORD(dtmf_parms[2].info);
  9117. }
  9118. i = 0;
  9119. j = 0;
  9120. while ((i < dtmf_parms[3].length) && (j < DTMF_DIGIT_MAP_ENTRIES))
  9121. {
  9122. j = 0;
  9123. while ((j < DTMF_DIGIT_MAP_ENTRIES)
  9124. && ((dtmf_parms[3].info[i + 1] != dtmf_digit_map[j].character)
  9125. || ((dtmf_digit_map[j].send_mask & mask) == 0)))
  9126. {
  9127. j++;
  9128. }
  9129. i++;
  9130. }
  9131. if (j == DTMF_DIGIT_MAP_ENTRIES)
  9132. {
  9133. dbug(1, dprintf("[%06lx] %s,%d: Incorrect DTMF digit %02x",
  9134. UnMapId(Id), (char *)(FILE_), __LINE__, dtmf_parms[3].info[i]));
  9135. PUT_WORD(&result[1], DTMF_INCORRECT_DIGIT);
  9136. break;
  9137. }
  9138. if (plci->dtmf_send_requests >= ARRAY_SIZE(plci->dtmf_msg_number_queue))
  9139. {
  9140. dbug(1, dprintf("[%06lx] %s,%d: DTMF request overrun",
  9141. UnMapId(Id), (char *)(FILE_), __LINE__));
  9142. Info = _WRONG_STATE;
  9143. break;
  9144. }
  9145. api_save_msg(dtmf_parms, "wwws", &plci->saved_msg);
  9146. start_internal_command(Id, plci, dtmf_command);
  9147. return (false);
  9148. default:
  9149. dbug(1, dprintf("[%06lx] %s,%d: DTMF unknown request %04x",
  9150. UnMapId(Id), (char *)(FILE_), __LINE__, plci->dtmf_cmd));
  9151. PUT_WORD(&result[1], DTMF_UNKNOWN_REQUEST);
  9152. }
  9153. }
  9154. }
  9155. sendf(appl, _FACILITY_R | CONFIRM, Id & 0xffffL, Number,
  9156. "wws", Info, SELECTOR_DTMF, result);
  9157. return (false);
  9158. }
  9159. static void dtmf_confirmation(dword Id, PLCI *plci)
  9160. {
  9161. word i;
  9162. byte result[4];
  9163. dbug(1, dprintf("[%06lx] %s,%d: dtmf_confirmation",
  9164. UnMapId(Id), (char *)(FILE_), __LINE__));
  9165. result[0] = 2;
  9166. PUT_WORD(&result[1], DTMF_SUCCESS);
  9167. if (plci->dtmf_send_requests != 0)
  9168. {
  9169. sendf(plci->appl, _FACILITY_R | CONFIRM, Id & 0xffffL, plci->dtmf_msg_number_queue[0],
  9170. "wws", GOOD, SELECTOR_DTMF, result);
  9171. (plci->dtmf_send_requests)--;
  9172. for (i = 0; i < plci->dtmf_send_requests; i++)
  9173. plci->dtmf_msg_number_queue[i] = plci->dtmf_msg_number_queue[i + 1];
  9174. }
  9175. }
  9176. static void dtmf_indication(dword Id, PLCI *plci, byte *msg, word length)
  9177. {
  9178. word i, j, n;
  9179. dbug(1, dprintf("[%06lx] %s,%d: dtmf_indication",
  9180. UnMapId(Id), (char *)(FILE_), __LINE__));
  9181. n = 0;
  9182. for (i = 1; i < length; i++)
  9183. {
  9184. j = 0;
  9185. while ((j < DTMF_DIGIT_MAP_ENTRIES)
  9186. && ((msg[i] != dtmf_digit_map[j].code)
  9187. || ((dtmf_digit_map[j].listen_mask & plci->dtmf_rec_active) == 0)))
  9188. {
  9189. j++;
  9190. }
  9191. if (j < DTMF_DIGIT_MAP_ENTRIES)
  9192. {
  9193. if ((dtmf_digit_map[j].listen_mask & DTMF_TONE_LISTEN_ACTIVE_FLAG)
  9194. && (plci->tone_last_indication_code == DTMF_SIGNAL_NO_TONE)
  9195. && (dtmf_digit_map[j].character != DTMF_SIGNAL_UNIDENTIFIED_TONE))
  9196. {
  9197. if (n + 1 == i)
  9198. {
  9199. for (i = length; i > n + 1; i--)
  9200. msg[i] = msg[i - 1];
  9201. length++;
  9202. i++;
  9203. }
  9204. msg[++n] = DTMF_SIGNAL_UNIDENTIFIED_TONE;
  9205. }
  9206. plci->tone_last_indication_code = dtmf_digit_map[j].character;
  9207. msg[++n] = dtmf_digit_map[j].character;
  9208. }
  9209. }
  9210. if (n != 0)
  9211. {
  9212. msg[0] = (byte) n;
  9213. sendf(plci->appl, _FACILITY_I, Id & 0xffffL, 0, "wS", SELECTOR_DTMF, msg);
  9214. }
  9215. }
  9216. /*------------------------------------------------------------------*/
  9217. /* DTMF parameters */
  9218. /*------------------------------------------------------------------*/
  9219. static void dtmf_parameter_write(PLCI *plci)
  9220. {
  9221. word i;
  9222. byte parameter_buffer[DTMF_PARAMETER_BUFFER_SIZE + 2];
  9223. dbug(1, dprintf("[%06lx] %s,%d: dtmf_parameter_write",
  9224. (dword)((plci->Id << 8) | UnMapController(plci->adapter->Id)),
  9225. (char *)(FILE_), __LINE__));
  9226. parameter_buffer[0] = plci->dtmf_parameter_length + 1;
  9227. parameter_buffer[1] = DSP_CTRL_SET_DTMF_PARAMETERS;
  9228. for (i = 0; i < plci->dtmf_parameter_length; i++)
  9229. parameter_buffer[2 + i] = plci->dtmf_parameter_buffer[i];
  9230. add_p(plci, FTY, parameter_buffer);
  9231. sig_req(plci, TEL_CTRL, 0);
  9232. send_req(plci);
  9233. }
  9234. static void dtmf_parameter_clear_config(PLCI *plci)
  9235. {
  9236. dbug(1, dprintf("[%06lx] %s,%d: dtmf_parameter_clear_config",
  9237. (dword)((plci->Id << 8) | UnMapController(plci->adapter->Id)),
  9238. (char *)(FILE_), __LINE__));
  9239. plci->dtmf_parameter_length = 0;
  9240. }
  9241. static void dtmf_parameter_prepare_switch(dword Id, PLCI *plci)
  9242. {
  9243. dbug(1, dprintf("[%06lx] %s,%d: dtmf_parameter_prepare_switch",
  9244. UnMapId(Id), (char *)(FILE_), __LINE__));
  9245. }
  9246. static word dtmf_parameter_save_config(dword Id, PLCI *plci, byte Rc)
  9247. {
  9248. dbug(1, dprintf("[%06lx] %s,%d: dtmf_parameter_save_config %02x %d",
  9249. UnMapId(Id), (char *)(FILE_), __LINE__, Rc, plci->adjust_b_state));
  9250. return (GOOD);
  9251. }
  9252. static word dtmf_parameter_restore_config(dword Id, PLCI *plci, byte Rc)
  9253. {
  9254. word Info;
  9255. dbug(1, dprintf("[%06lx] %s,%d: dtmf_parameter_restore_config %02x %d",
  9256. UnMapId(Id), (char *)(FILE_), __LINE__, Rc, plci->adjust_b_state));
  9257. Info = GOOD;
  9258. if ((plci->B1_facilities & B1_FACILITY_DTMFR)
  9259. && (plci->dtmf_parameter_length != 0))
  9260. {
  9261. switch (plci->adjust_b_state)
  9262. {
  9263. case ADJUST_B_RESTORE_DTMF_PARAMETER_1:
  9264. plci->internal_command = plci->adjust_b_command;
  9265. if (plci->sig_req)
  9266. {
  9267. plci->adjust_b_state = ADJUST_B_RESTORE_DTMF_PARAMETER_1;
  9268. break;
  9269. }
  9270. dtmf_parameter_write(plci);
  9271. plci->adjust_b_state = ADJUST_B_RESTORE_DTMF_PARAMETER_2;
  9272. break;
  9273. case ADJUST_B_RESTORE_DTMF_PARAMETER_2:
  9274. if ((Rc != OK) && (Rc != OK_FC))
  9275. {
  9276. dbug(1, dprintf("[%06lx] %s,%d: Restore DTMF parameters failed %02x",
  9277. UnMapId(Id), (char *)(FILE_), __LINE__, Rc));
  9278. Info = _WRONG_STATE;
  9279. break;
  9280. }
  9281. break;
  9282. }
  9283. }
  9284. return (Info);
  9285. }
  9286. /*------------------------------------------------------------------*/
  9287. /* Line interconnect facilities */
  9288. /*------------------------------------------------------------------*/
  9289. LI_CONFIG *li_config_table;
  9290. word li_total_channels;
  9291. /*------------------------------------------------------------------*/
  9292. /* translate a CHI information element to a channel number */
  9293. /* returns 0xff - any channel */
  9294. /* 0xfe - chi wrong coding */
  9295. /* 0xfd - D-channel */
  9296. /* 0x00 - no channel */
  9297. /* else channel number / PRI: timeslot */
  9298. /* if channels is provided we accept more than one channel. */
  9299. /*------------------------------------------------------------------*/
  9300. static byte chi_to_channel(byte *chi, dword *pchannelmap)
  9301. {
  9302. int p;
  9303. int i;
  9304. dword map;
  9305. byte excl;
  9306. byte ofs;
  9307. byte ch;
  9308. if (pchannelmap) *pchannelmap = 0;
  9309. if (!chi[0]) return 0xff;
  9310. excl = 0;
  9311. if (chi[1] & 0x20) {
  9312. if (chi[0] == 1 && chi[1] == 0xac) return 0xfd; /* exclusive d-channel */
  9313. for (i = 1; i < chi[0] && !(chi[i] & 0x80); i++);
  9314. if (i == chi[0] || !(chi[i] & 0x80)) return 0xfe;
  9315. if ((chi[1] | 0xc8) != 0xe9) return 0xfe;
  9316. if (chi[1] & 0x08) excl = 0x40;
  9317. /* int. id present */
  9318. if (chi[1] & 0x40) {
  9319. p = i + 1;
  9320. for (i = p; i < chi[0] && !(chi[i] & 0x80); i++);
  9321. if (i == chi[0] || !(chi[i] & 0x80)) return 0xfe;
  9322. }
  9323. /* coding standard, Number/Map, Channel Type */
  9324. p = i + 1;
  9325. for (i = p; i < chi[0] && !(chi[i] & 0x80); i++);
  9326. if (i == chi[0] || !(chi[i] & 0x80)) return 0xfe;
  9327. if ((chi[p] | 0xd0) != 0xd3) return 0xfe;
  9328. /* Number/Map */
  9329. if (chi[p] & 0x10) {
  9330. /* map */
  9331. if ((chi[0] - p) == 4) ofs = 0;
  9332. else if ((chi[0] - p) == 3) ofs = 1;
  9333. else return 0xfe;
  9334. ch = 0;
  9335. map = 0;
  9336. for (i = 0; i < 4 && p < chi[0]; i++) {
  9337. p++;
  9338. ch += 8;
  9339. map <<= 8;
  9340. if (chi[p]) {
  9341. for (ch = 0; !(chi[p] & (1 << ch)); ch++);
  9342. map |= chi[p];
  9343. }
  9344. }
  9345. ch += ofs;
  9346. map <<= ofs;
  9347. }
  9348. else {
  9349. /* number */
  9350. p = i + 1;
  9351. ch = chi[p] & 0x3f;
  9352. if (pchannelmap) {
  9353. if ((byte)(chi[0] - p) > 30) return 0xfe;
  9354. map = 0;
  9355. for (i = p; i <= chi[0]; i++) {
  9356. if ((chi[i] & 0x7f) > 31) return 0xfe;
  9357. map |= (1L << (chi[i] & 0x7f));
  9358. }
  9359. }
  9360. else {
  9361. if (p != chi[0]) return 0xfe;
  9362. if (ch > 31) return 0xfe;
  9363. map = (1L << ch);
  9364. }
  9365. if (chi[p] & 0x40) return 0xfe;
  9366. }
  9367. if (pchannelmap) *pchannelmap = map;
  9368. else if (map != ((dword)(1L << ch))) return 0xfe;
  9369. return (byte)(excl | ch);
  9370. }
  9371. else { /* not PRI */
  9372. for (i = 1; i < chi[0] && !(chi[i] & 0x80); i++);
  9373. if (i != chi[0] || !(chi[i] & 0x80)) return 0xfe;
  9374. if (chi[1] & 0x08) excl = 0x40;
  9375. switch (chi[1] | 0x98) {
  9376. case 0x98: return 0;
  9377. case 0x99:
  9378. if (pchannelmap) *pchannelmap = 2;
  9379. return excl | 1;
  9380. case 0x9a:
  9381. if (pchannelmap) *pchannelmap = 4;
  9382. return excl | 2;
  9383. case 0x9b: return 0xff;
  9384. case 0x9c: return 0xfd; /* d-ch */
  9385. default: return 0xfe;
  9386. }
  9387. }
  9388. }
  9389. static void mixer_set_bchannel_id_esc(PLCI *plci, byte bchannel_id)
  9390. {
  9391. DIVA_CAPI_ADAPTER *a;
  9392. PLCI *splci;
  9393. byte old_id;
  9394. a = plci->adapter;
  9395. old_id = plci->li_bchannel_id;
  9396. if (a->li_pri)
  9397. {
  9398. if ((old_id != 0) && (li_config_table[a->li_base + (old_id - 1)].plci == plci))
  9399. li_config_table[a->li_base + (old_id - 1)].plci = NULL;
  9400. plci->li_bchannel_id = (bchannel_id & 0x1f) + 1;
  9401. if (li_config_table[a->li_base + (plci->li_bchannel_id - 1)].plci == NULL)
  9402. li_config_table[a->li_base + (plci->li_bchannel_id - 1)].plci = plci;
  9403. }
  9404. else
  9405. {
  9406. if (((bchannel_id & 0x03) == 1) || ((bchannel_id & 0x03) == 2))
  9407. {
  9408. if ((old_id != 0) && (li_config_table[a->li_base + (old_id - 1)].plci == plci))
  9409. li_config_table[a->li_base + (old_id - 1)].plci = NULL;
  9410. plci->li_bchannel_id = bchannel_id & 0x03;
  9411. if ((a->AdvSignalPLCI != NULL) && (a->AdvSignalPLCI != plci) && (a->AdvSignalPLCI->tel == ADV_VOICE))
  9412. {
  9413. splci = a->AdvSignalPLCI;
  9414. if (li_config_table[a->li_base + (2 - plci->li_bchannel_id)].plci == NULL)
  9415. {
  9416. if ((splci->li_bchannel_id != 0)
  9417. && (li_config_table[a->li_base + (splci->li_bchannel_id - 1)].plci == splci))
  9418. {
  9419. li_config_table[a->li_base + (splci->li_bchannel_id - 1)].plci = NULL;
  9420. }
  9421. splci->li_bchannel_id = 3 - plci->li_bchannel_id;
  9422. li_config_table[a->li_base + (2 - plci->li_bchannel_id)].plci = splci;
  9423. dbug(1, dprintf("[%06lx] %s,%d: adv_voice_set_bchannel_id_esc %d",
  9424. (dword)((splci->Id << 8) | UnMapController(splci->adapter->Id)),
  9425. (char *)(FILE_), __LINE__, splci->li_bchannel_id));
  9426. }
  9427. }
  9428. if (li_config_table[a->li_base + (plci->li_bchannel_id - 1)].plci == NULL)
  9429. li_config_table[a->li_base + (plci->li_bchannel_id - 1)].plci = plci;
  9430. }
  9431. }
  9432. if ((old_id == 0) && (plci->li_bchannel_id != 0)
  9433. && (li_config_table[a->li_base + (plci->li_bchannel_id - 1)].plci == plci))
  9434. {
  9435. mixer_clear_config(plci);
  9436. }
  9437. dbug(1, dprintf("[%06lx] %s,%d: mixer_set_bchannel_id_esc %d %d",
  9438. (dword)((plci->Id << 8) | UnMapController(plci->adapter->Id)),
  9439. (char *)(FILE_), __LINE__, bchannel_id, plci->li_bchannel_id));
  9440. }
  9441. static void mixer_set_bchannel_id(PLCI *plci, byte *chi)
  9442. {
  9443. DIVA_CAPI_ADAPTER *a;
  9444. PLCI *splci;
  9445. byte ch, old_id;
  9446. a = plci->adapter;
  9447. old_id = plci->li_bchannel_id;
  9448. ch = chi_to_channel(chi, NULL);
  9449. if (!(ch & 0x80))
  9450. {
  9451. if (a->li_pri)
  9452. {
  9453. if ((old_id != 0) && (li_config_table[a->li_base + (old_id - 1)].plci == plci))
  9454. li_config_table[a->li_base + (old_id - 1)].plci = NULL;
  9455. plci->li_bchannel_id = (ch & 0x1f) + 1;
  9456. if (li_config_table[a->li_base + (plci->li_bchannel_id - 1)].plci == NULL)
  9457. li_config_table[a->li_base + (plci->li_bchannel_id - 1)].plci = plci;
  9458. }
  9459. else
  9460. {
  9461. if (((ch & 0x1f) == 1) || ((ch & 0x1f) == 2))
  9462. {
  9463. if ((old_id != 0) && (li_config_table[a->li_base + (old_id - 1)].plci == plci))
  9464. li_config_table[a->li_base + (old_id - 1)].plci = NULL;
  9465. plci->li_bchannel_id = ch & 0x1f;
  9466. if ((a->AdvSignalPLCI != NULL) && (a->AdvSignalPLCI != plci) && (a->AdvSignalPLCI->tel == ADV_VOICE))
  9467. {
  9468. splci = a->AdvSignalPLCI;
  9469. if (li_config_table[a->li_base + (2 - plci->li_bchannel_id)].plci == NULL)
  9470. {
  9471. if ((splci->li_bchannel_id != 0)
  9472. && (li_config_table[a->li_base + (splci->li_bchannel_id - 1)].plci == splci))
  9473. {
  9474. li_config_table[a->li_base + (splci->li_bchannel_id - 1)].plci = NULL;
  9475. }
  9476. splci->li_bchannel_id = 3 - plci->li_bchannel_id;
  9477. li_config_table[a->li_base + (2 - plci->li_bchannel_id)].plci = splci;
  9478. dbug(1, dprintf("[%06lx] %s,%d: adv_voice_set_bchannel_id %d",
  9479. (dword)((splci->Id << 8) | UnMapController(splci->adapter->Id)),
  9480. (char *)(FILE_), __LINE__, splci->li_bchannel_id));
  9481. }
  9482. }
  9483. if (li_config_table[a->li_base + (plci->li_bchannel_id - 1)].plci == NULL)
  9484. li_config_table[a->li_base + (plci->li_bchannel_id - 1)].plci = plci;
  9485. }
  9486. }
  9487. }
  9488. if ((old_id == 0) && (plci->li_bchannel_id != 0)
  9489. && (li_config_table[a->li_base + (plci->li_bchannel_id - 1)].plci == plci))
  9490. {
  9491. mixer_clear_config(plci);
  9492. }
  9493. dbug(1, dprintf("[%06lx] %s,%d: mixer_set_bchannel_id %02x %d",
  9494. (dword)((plci->Id << 8) | UnMapController(plci->adapter->Id)),
  9495. (char *)(FILE_), __LINE__, ch, plci->li_bchannel_id));
  9496. }
  9497. #define MIXER_MAX_DUMP_CHANNELS 34
  9498. static void mixer_calculate_coefs(DIVA_CAPI_ADAPTER *a)
  9499. {
  9500. word n, i, j;
  9501. char *p;
  9502. char hex_line[2 * MIXER_MAX_DUMP_CHANNELS + MIXER_MAX_DUMP_CHANNELS / 8 + 4];
  9503. dbug(1, dprintf("[%06lx] %s,%d: mixer_calculate_coefs",
  9504. (dword)(UnMapController(a->Id)), (char *)(FILE_), __LINE__));
  9505. for (i = 0; i < li_total_channels; i++)
  9506. {
  9507. li_config_table[i].channel &= LI_CHANNEL_ADDRESSES_SET;
  9508. if (li_config_table[i].chflags != 0)
  9509. li_config_table[i].channel |= LI_CHANNEL_INVOLVED;
  9510. else
  9511. {
  9512. for (j = 0; j < li_total_channels; j++)
  9513. {
  9514. if (((li_config_table[i].flag_table[j]) != 0)
  9515. || ((li_config_table[j].flag_table[i]) != 0))
  9516. {
  9517. li_config_table[i].channel |= LI_CHANNEL_INVOLVED;
  9518. }
  9519. if (((li_config_table[i].flag_table[j] & LI_FLAG_CONFERENCE) != 0)
  9520. || ((li_config_table[j].flag_table[i] & LI_FLAG_CONFERENCE) != 0))
  9521. {
  9522. li_config_table[i].channel |= LI_CHANNEL_CONFERENCE;
  9523. }
  9524. }
  9525. }
  9526. }
  9527. for (i = 0; i < li_total_channels; i++)
  9528. {
  9529. for (j = 0; j < li_total_channels; j++)
  9530. {
  9531. li_config_table[i].coef_table[j] &= ~(LI_COEF_CH_CH | LI_COEF_CH_PC | LI_COEF_PC_CH | LI_COEF_PC_PC);
  9532. if (li_config_table[i].flag_table[j] & LI_FLAG_CONFERENCE)
  9533. li_config_table[i].coef_table[j] |= LI_COEF_CH_CH;
  9534. }
  9535. }
  9536. for (n = 0; n < li_total_channels; n++)
  9537. {
  9538. if (li_config_table[n].channel & LI_CHANNEL_CONFERENCE)
  9539. {
  9540. for (i = 0; i < li_total_channels; i++)
  9541. {
  9542. if (li_config_table[i].channel & LI_CHANNEL_CONFERENCE)
  9543. {
  9544. for (j = 0; j < li_total_channels; j++)
  9545. {
  9546. li_config_table[i].coef_table[j] |=
  9547. li_config_table[i].coef_table[n] & li_config_table[n].coef_table[j];
  9548. }
  9549. }
  9550. }
  9551. }
  9552. }
  9553. for (i = 0; i < li_total_channels; i++)
  9554. {
  9555. if (li_config_table[i].channel & LI_CHANNEL_INVOLVED)
  9556. {
  9557. li_config_table[i].coef_table[i] &= ~LI_COEF_CH_CH;
  9558. for (j = 0; j < li_total_channels; j++)
  9559. {
  9560. if (li_config_table[i].coef_table[j] & LI_COEF_CH_CH)
  9561. li_config_table[i].flag_table[j] |= LI_FLAG_CONFERENCE;
  9562. }
  9563. if (li_config_table[i].flag_table[i] & LI_FLAG_CONFERENCE)
  9564. li_config_table[i].coef_table[i] |= LI_COEF_CH_CH;
  9565. }
  9566. }
  9567. for (i = 0; i < li_total_channels; i++)
  9568. {
  9569. if (li_config_table[i].channel & LI_CHANNEL_INVOLVED)
  9570. {
  9571. for (j = 0; j < li_total_channels; j++)
  9572. {
  9573. if (li_config_table[i].flag_table[j] & LI_FLAG_INTERCONNECT)
  9574. li_config_table[i].coef_table[j] |= LI_COEF_CH_CH;
  9575. if (li_config_table[i].flag_table[j] & LI_FLAG_MONITOR)
  9576. li_config_table[i].coef_table[j] |= LI_COEF_CH_PC;
  9577. if (li_config_table[i].flag_table[j] & LI_FLAG_MIX)
  9578. li_config_table[i].coef_table[j] |= LI_COEF_PC_CH;
  9579. if (li_config_table[i].flag_table[j] & LI_FLAG_PCCONNECT)
  9580. li_config_table[i].coef_table[j] |= LI_COEF_PC_PC;
  9581. }
  9582. if (li_config_table[i].chflags & LI_CHFLAG_MONITOR)
  9583. {
  9584. for (j = 0; j < li_total_channels; j++)
  9585. {
  9586. if (li_config_table[i].flag_table[j] & LI_FLAG_INTERCONNECT)
  9587. {
  9588. li_config_table[i].coef_table[j] |= LI_COEF_CH_PC;
  9589. if (li_config_table[j].chflags & LI_CHFLAG_MIX)
  9590. li_config_table[i].coef_table[j] |= LI_COEF_PC_CH | LI_COEF_PC_PC;
  9591. }
  9592. }
  9593. }
  9594. if (li_config_table[i].chflags & LI_CHFLAG_MIX)
  9595. {
  9596. for (j = 0; j < li_total_channels; j++)
  9597. {
  9598. if (li_config_table[j].flag_table[i] & LI_FLAG_INTERCONNECT)
  9599. li_config_table[j].coef_table[i] |= LI_COEF_PC_CH;
  9600. }
  9601. }
  9602. if (li_config_table[i].chflags & LI_CHFLAG_LOOP)
  9603. {
  9604. for (j = 0; j < li_total_channels; j++)
  9605. {
  9606. if (li_config_table[i].flag_table[j] & LI_FLAG_INTERCONNECT)
  9607. {
  9608. for (n = 0; n < li_total_channels; n++)
  9609. {
  9610. if (li_config_table[n].flag_table[i] & LI_FLAG_INTERCONNECT)
  9611. {
  9612. li_config_table[n].coef_table[j] |= LI_COEF_CH_CH;
  9613. if (li_config_table[j].chflags & LI_CHFLAG_MIX)
  9614. {
  9615. li_config_table[n].coef_table[j] |= LI_COEF_PC_CH;
  9616. if (li_config_table[n].chflags & LI_CHFLAG_MONITOR)
  9617. li_config_table[n].coef_table[j] |= LI_COEF_CH_PC | LI_COEF_PC_PC;
  9618. }
  9619. else if (li_config_table[n].chflags & LI_CHFLAG_MONITOR)
  9620. li_config_table[n].coef_table[j] |= LI_COEF_CH_PC;
  9621. }
  9622. }
  9623. }
  9624. }
  9625. }
  9626. }
  9627. }
  9628. for (i = 0; i < li_total_channels; i++)
  9629. {
  9630. if (li_config_table[i].channel & LI_CHANNEL_INVOLVED)
  9631. {
  9632. if (li_config_table[i].chflags & (LI_CHFLAG_MONITOR | LI_CHFLAG_MIX | LI_CHFLAG_LOOP))
  9633. li_config_table[i].channel |= LI_CHANNEL_ACTIVE;
  9634. if (li_config_table[i].chflags & LI_CHFLAG_MONITOR)
  9635. li_config_table[i].channel |= LI_CHANNEL_RX_DATA;
  9636. if (li_config_table[i].chflags & LI_CHFLAG_MIX)
  9637. li_config_table[i].channel |= LI_CHANNEL_TX_DATA;
  9638. for (j = 0; j < li_total_channels; j++)
  9639. {
  9640. if ((li_config_table[i].flag_table[j] &
  9641. (LI_FLAG_INTERCONNECT | LI_FLAG_PCCONNECT | LI_FLAG_CONFERENCE | LI_FLAG_MONITOR))
  9642. || (li_config_table[j].flag_table[i] &
  9643. (LI_FLAG_INTERCONNECT | LI_FLAG_PCCONNECT | LI_FLAG_CONFERENCE | LI_FLAG_ANNOUNCEMENT | LI_FLAG_MIX)))
  9644. {
  9645. li_config_table[i].channel |= LI_CHANNEL_ACTIVE;
  9646. }
  9647. if (li_config_table[i].flag_table[j] & (LI_FLAG_PCCONNECT | LI_FLAG_MONITOR))
  9648. li_config_table[i].channel |= LI_CHANNEL_RX_DATA;
  9649. if (li_config_table[j].flag_table[i] & (LI_FLAG_PCCONNECT | LI_FLAG_ANNOUNCEMENT | LI_FLAG_MIX))
  9650. li_config_table[i].channel |= LI_CHANNEL_TX_DATA;
  9651. }
  9652. if (!(li_config_table[i].channel & LI_CHANNEL_ACTIVE))
  9653. {
  9654. li_config_table[i].coef_table[i] |= LI_COEF_PC_CH | LI_COEF_CH_PC;
  9655. li_config_table[i].channel |= LI_CHANNEL_TX_DATA | LI_CHANNEL_RX_DATA;
  9656. }
  9657. }
  9658. }
  9659. for (i = 0; i < li_total_channels; i++)
  9660. {
  9661. if (li_config_table[i].channel & LI_CHANNEL_INVOLVED)
  9662. {
  9663. j = 0;
  9664. while ((j < li_total_channels) && !(li_config_table[i].flag_table[j] & LI_FLAG_ANNOUNCEMENT))
  9665. j++;
  9666. if (j < li_total_channels)
  9667. {
  9668. for (j = 0; j < li_total_channels; j++)
  9669. {
  9670. li_config_table[i].coef_table[j] &= ~(LI_COEF_CH_CH | LI_COEF_PC_CH);
  9671. if (li_config_table[i].flag_table[j] & LI_FLAG_ANNOUNCEMENT)
  9672. li_config_table[i].coef_table[j] |= LI_COEF_PC_CH;
  9673. }
  9674. }
  9675. }
  9676. }
  9677. n = li_total_channels;
  9678. if (n > MIXER_MAX_DUMP_CHANNELS)
  9679. n = MIXER_MAX_DUMP_CHANNELS;
  9680. p = hex_line;
  9681. for (j = 0; j < n; j++)
  9682. {
  9683. if ((j & 0x7) == 0)
  9684. *(p++) = ' ';
  9685. p = hex_byte_pack(p, li_config_table[j].curchnl);
  9686. }
  9687. *p = '\0';
  9688. dbug(1, dprintf("[%06lx] CURRENT %s",
  9689. (dword)(UnMapController(a->Id)), (char *)hex_line));
  9690. p = hex_line;
  9691. for (j = 0; j < n; j++)
  9692. {
  9693. if ((j & 0x7) == 0)
  9694. *(p++) = ' ';
  9695. p = hex_byte_pack(p, li_config_table[j].channel);
  9696. }
  9697. *p = '\0';
  9698. dbug(1, dprintf("[%06lx] CHANNEL %s",
  9699. (dword)(UnMapController(a->Id)), (char *)hex_line));
  9700. p = hex_line;
  9701. for (j = 0; j < n; j++)
  9702. {
  9703. if ((j & 0x7) == 0)
  9704. *(p++) = ' ';
  9705. p = hex_byte_pack(p, li_config_table[j].chflags);
  9706. }
  9707. *p = '\0';
  9708. dbug(1, dprintf("[%06lx] CHFLAG %s",
  9709. (dword)(UnMapController(a->Id)), (char *)hex_line));
  9710. for (i = 0; i < n; i++)
  9711. {
  9712. p = hex_line;
  9713. for (j = 0; j < n; j++)
  9714. {
  9715. if ((j & 0x7) == 0)
  9716. *(p++) = ' ';
  9717. p = hex_byte_pack(p, li_config_table[i].flag_table[j]);
  9718. }
  9719. *p = '\0';
  9720. dbug(1, dprintf("[%06lx] FLAG[%02x]%s",
  9721. (dword)(UnMapController(a->Id)), i, (char *)hex_line));
  9722. }
  9723. for (i = 0; i < n; i++)
  9724. {
  9725. p = hex_line;
  9726. for (j = 0; j < n; j++)
  9727. {
  9728. if ((j & 0x7) == 0)
  9729. *(p++) = ' ';
  9730. p = hex_byte_pack(p, li_config_table[i].coef_table[j]);
  9731. }
  9732. *p = '\0';
  9733. dbug(1, dprintf("[%06lx] COEF[%02x]%s",
  9734. (dword)(UnMapController(a->Id)), i, (char *)hex_line));
  9735. }
  9736. }
  9737. static struct
  9738. {
  9739. byte mask;
  9740. byte line_flags;
  9741. } mixer_write_prog_pri[] =
  9742. {
  9743. { LI_COEF_CH_CH, 0 },
  9744. { LI_COEF_CH_PC, MIXER_COEF_LINE_TO_PC_FLAG },
  9745. { LI_COEF_PC_CH, MIXER_COEF_LINE_FROM_PC_FLAG },
  9746. { LI_COEF_PC_PC, MIXER_COEF_LINE_TO_PC_FLAG | MIXER_COEF_LINE_FROM_PC_FLAG }
  9747. };
  9748. static struct
  9749. {
  9750. byte from_ch;
  9751. byte to_ch;
  9752. byte mask;
  9753. byte xconnect_override;
  9754. } mixer_write_prog_bri[] =
  9755. {
  9756. { 0, 0, LI_COEF_CH_CH, 0x01 }, /* B to B */
  9757. { 1, 0, LI_COEF_CH_CH, 0x01 }, /* Alt B to B */
  9758. { 0, 0, LI_COEF_PC_CH, 0x80 }, /* PC to B */
  9759. { 1, 0, LI_COEF_PC_CH, 0x01 }, /* Alt PC to B */
  9760. { 2, 0, LI_COEF_CH_CH, 0x00 }, /* IC to B */
  9761. { 3, 0, LI_COEF_CH_CH, 0x00 }, /* Alt IC to B */
  9762. { 0, 0, LI_COEF_CH_PC, 0x80 }, /* B to PC */
  9763. { 1, 0, LI_COEF_CH_PC, 0x01 }, /* Alt B to PC */
  9764. { 0, 0, LI_COEF_PC_PC, 0x01 }, /* PC to PC */
  9765. { 1, 0, LI_COEF_PC_PC, 0x01 }, /* Alt PC to PC */
  9766. { 2, 0, LI_COEF_CH_PC, 0x00 }, /* IC to PC */
  9767. { 3, 0, LI_COEF_CH_PC, 0x00 }, /* Alt IC to PC */
  9768. { 0, 2, LI_COEF_CH_CH, 0x00 }, /* B to IC */
  9769. { 1, 2, LI_COEF_CH_CH, 0x00 }, /* Alt B to IC */
  9770. { 0, 2, LI_COEF_PC_CH, 0x00 }, /* PC to IC */
  9771. { 1, 2, LI_COEF_PC_CH, 0x00 }, /* Alt PC to IC */
  9772. { 2, 2, LI_COEF_CH_CH, 0x00 }, /* IC to IC */
  9773. { 3, 2, LI_COEF_CH_CH, 0x00 }, /* Alt IC to IC */
  9774. { 1, 1, LI_COEF_CH_CH, 0x01 }, /* Alt B to Alt B */
  9775. { 0, 1, LI_COEF_CH_CH, 0x01 }, /* B to Alt B */
  9776. { 1, 1, LI_COEF_PC_CH, 0x80 }, /* Alt PC to Alt B */
  9777. { 0, 1, LI_COEF_PC_CH, 0x01 }, /* PC to Alt B */
  9778. { 3, 1, LI_COEF_CH_CH, 0x00 }, /* Alt IC to Alt B */
  9779. { 2, 1, LI_COEF_CH_CH, 0x00 }, /* IC to Alt B */
  9780. { 1, 1, LI_COEF_CH_PC, 0x80 }, /* Alt B to Alt PC */
  9781. { 0, 1, LI_COEF_CH_PC, 0x01 }, /* B to Alt PC */
  9782. { 1, 1, LI_COEF_PC_PC, 0x01 }, /* Alt PC to Alt PC */
  9783. { 0, 1, LI_COEF_PC_PC, 0x01 }, /* PC to Alt PC */
  9784. { 3, 1, LI_COEF_CH_PC, 0x00 }, /* Alt IC to Alt PC */
  9785. { 2, 1, LI_COEF_CH_PC, 0x00 }, /* IC to Alt PC */
  9786. { 1, 3, LI_COEF_CH_CH, 0x00 }, /* Alt B to Alt IC */
  9787. { 0, 3, LI_COEF_CH_CH, 0x00 }, /* B to Alt IC */
  9788. { 1, 3, LI_COEF_PC_CH, 0x00 }, /* Alt PC to Alt IC */
  9789. { 0, 3, LI_COEF_PC_CH, 0x00 }, /* PC to Alt IC */
  9790. { 3, 3, LI_COEF_CH_CH, 0x00 }, /* Alt IC to Alt IC */
  9791. { 2, 3, LI_COEF_CH_CH, 0x00 } /* IC to Alt IC */
  9792. };
  9793. static byte mixer_swapped_index_bri[] =
  9794. {
  9795. 18, /* B to B */
  9796. 19, /* Alt B to B */
  9797. 20, /* PC to B */
  9798. 21, /* Alt PC to B */
  9799. 22, /* IC to B */
  9800. 23, /* Alt IC to B */
  9801. 24, /* B to PC */
  9802. 25, /* Alt B to PC */
  9803. 26, /* PC to PC */
  9804. 27, /* Alt PC to PC */
  9805. 28, /* IC to PC */
  9806. 29, /* Alt IC to PC */
  9807. 30, /* B to IC */
  9808. 31, /* Alt B to IC */
  9809. 32, /* PC to IC */
  9810. 33, /* Alt PC to IC */
  9811. 34, /* IC to IC */
  9812. 35, /* Alt IC to IC */
  9813. 0, /* Alt B to Alt B */
  9814. 1, /* B to Alt B */
  9815. 2, /* Alt PC to Alt B */
  9816. 3, /* PC to Alt B */
  9817. 4, /* Alt IC to Alt B */
  9818. 5, /* IC to Alt B */
  9819. 6, /* Alt B to Alt PC */
  9820. 7, /* B to Alt PC */
  9821. 8, /* Alt PC to Alt PC */
  9822. 9, /* PC to Alt PC */
  9823. 10, /* Alt IC to Alt PC */
  9824. 11, /* IC to Alt PC */
  9825. 12, /* Alt B to Alt IC */
  9826. 13, /* B to Alt IC */
  9827. 14, /* Alt PC to Alt IC */
  9828. 15, /* PC to Alt IC */
  9829. 16, /* Alt IC to Alt IC */
  9830. 17 /* IC to Alt IC */
  9831. };
  9832. static struct
  9833. {
  9834. byte mask;
  9835. byte from_pc;
  9836. byte to_pc;
  9837. } xconnect_write_prog[] =
  9838. {
  9839. { LI_COEF_CH_CH, false, false },
  9840. { LI_COEF_CH_PC, false, true },
  9841. { LI_COEF_PC_CH, true, false },
  9842. { LI_COEF_PC_PC, true, true }
  9843. };
  9844. static void xconnect_query_addresses(PLCI *plci)
  9845. {
  9846. DIVA_CAPI_ADAPTER *a;
  9847. word w, ch;
  9848. byte *p;
  9849. dbug(1, dprintf("[%06lx] %s,%d: xconnect_query_addresses",
  9850. (dword)((plci->Id << 8) | UnMapController(plci->adapter->Id)),
  9851. (char *)(FILE_), __LINE__));
  9852. a = plci->adapter;
  9853. if (a->li_pri && ((plci->li_bchannel_id == 0)
  9854. || (li_config_table[a->li_base + (plci->li_bchannel_id - 1)].plci != plci)))
  9855. {
  9856. dbug(1, dprintf("[%06x] %s,%d: Channel id wiped out",
  9857. (dword)((plci->Id << 8) | UnMapController(plci->adapter->Id)),
  9858. (char *)(FILE_), __LINE__));
  9859. return;
  9860. }
  9861. p = plci->internal_req_buffer;
  9862. ch = (a->li_pri) ? plci->li_bchannel_id - 1 : 0;
  9863. *(p++) = UDATA_REQUEST_XCONNECT_FROM;
  9864. w = ch;
  9865. *(p++) = (byte) w;
  9866. *(p++) = (byte)(w >> 8);
  9867. w = ch | XCONNECT_CHANNEL_PORT_PC;
  9868. *(p++) = (byte) w;
  9869. *(p++) = (byte)(w >> 8);
  9870. plci->NData[0].P = plci->internal_req_buffer;
  9871. plci->NData[0].PLength = p - plci->internal_req_buffer;
  9872. plci->NL.X = plci->NData;
  9873. plci->NL.ReqCh = 0;
  9874. plci->NL.Req = plci->nl_req = (byte) N_UDATA;
  9875. plci->adapter->request(&plci->NL);
  9876. }
  9877. static void xconnect_write_coefs(PLCI *plci, word internal_command)
  9878. {
  9879. dbug(1, dprintf("[%06lx] %s,%d: xconnect_write_coefs %04x",
  9880. (dword)((plci->Id << 8) | UnMapController(plci->adapter->Id)),
  9881. (char *)(FILE_), __LINE__, internal_command));
  9882. plci->li_write_command = internal_command;
  9883. plci->li_write_channel = 0;
  9884. }
  9885. static byte xconnect_write_coefs_process(dword Id, PLCI *plci, byte Rc)
  9886. {
  9887. DIVA_CAPI_ADAPTER *a;
  9888. word w, n, i, j, r, s, to_ch;
  9889. dword d;
  9890. byte *p;
  9891. struct xconnect_transfer_address_s *transfer_address;
  9892. byte ch_map[MIXER_CHANNELS_BRI];
  9893. dbug(1, dprintf("[%06x] %s,%d: xconnect_write_coefs_process %02x %d",
  9894. UnMapId(Id), (char *)(FILE_), __LINE__, Rc, plci->li_write_channel));
  9895. a = plci->adapter;
  9896. if ((plci->li_bchannel_id == 0)
  9897. || (li_config_table[a->li_base + (plci->li_bchannel_id - 1)].plci != plci))
  9898. {
  9899. dbug(1, dprintf("[%06x] %s,%d: Channel id wiped out",
  9900. UnMapId(Id), (char *)(FILE_), __LINE__));
  9901. return (true);
  9902. }
  9903. i = a->li_base + (plci->li_bchannel_id - 1);
  9904. j = plci->li_write_channel;
  9905. p = plci->internal_req_buffer;
  9906. if (j != 0)
  9907. {
  9908. if ((Rc != OK) && (Rc != OK_FC))
  9909. {
  9910. dbug(1, dprintf("[%06lx] %s,%d: LI write coefs failed %02x",
  9911. UnMapId(Id), (char *)(FILE_), __LINE__, Rc));
  9912. return (false);
  9913. }
  9914. }
  9915. if (li_config_table[i].adapter->manufacturer_features & MANUFACTURER_FEATURE_XCONNECT)
  9916. {
  9917. r = 0;
  9918. s = 0;
  9919. if (j < li_total_channels)
  9920. {
  9921. if (li_config_table[i].channel & LI_CHANNEL_ADDRESSES_SET)
  9922. {
  9923. s = ((li_config_table[i].send_b.card_address.low | li_config_table[i].send_b.card_address.high) ?
  9924. (LI_COEF_CH_CH | LI_COEF_CH_PC | LI_COEF_PC_CH | LI_COEF_PC_PC) : (LI_COEF_CH_PC | LI_COEF_PC_PC)) &
  9925. ((li_config_table[i].send_pc.card_address.low | li_config_table[i].send_pc.card_address.high) ?
  9926. (LI_COEF_CH_CH | LI_COEF_CH_PC | LI_COEF_PC_CH | LI_COEF_PC_PC) : (LI_COEF_CH_CH | LI_COEF_PC_CH));
  9927. }
  9928. r = ((li_config_table[i].coef_table[j] & 0xf) ^ (li_config_table[i].coef_table[j] >> 4));
  9929. while ((j < li_total_channels)
  9930. && ((r == 0)
  9931. || (!(li_config_table[j].channel & LI_CHANNEL_ADDRESSES_SET))
  9932. || (!li_config_table[j].adapter->li_pri
  9933. && (j >= li_config_table[j].adapter->li_base + MIXER_BCHANNELS_BRI))
  9934. || (((li_config_table[j].send_b.card_address.low != li_config_table[i].send_b.card_address.low)
  9935. || (li_config_table[j].send_b.card_address.high != li_config_table[i].send_b.card_address.high))
  9936. && (!(a->manufacturer_features & MANUFACTURER_FEATURE_DMACONNECT)
  9937. || !(li_config_table[j].adapter->manufacturer_features & MANUFACTURER_FEATURE_DMACONNECT)))
  9938. || ((li_config_table[j].adapter->li_base != a->li_base)
  9939. && !(r & s &
  9940. ((li_config_table[j].send_b.card_address.low | li_config_table[j].send_b.card_address.high) ?
  9941. (LI_COEF_CH_CH | LI_COEF_CH_PC | LI_COEF_PC_CH | LI_COEF_PC_PC) : (LI_COEF_PC_CH | LI_COEF_PC_PC)) &
  9942. ((li_config_table[j].send_pc.card_address.low | li_config_table[j].send_pc.card_address.high) ?
  9943. (LI_COEF_CH_CH | LI_COEF_CH_PC | LI_COEF_PC_CH | LI_COEF_PC_PC) : (LI_COEF_CH_CH | LI_COEF_CH_PC))))))
  9944. {
  9945. j++;
  9946. if (j < li_total_channels)
  9947. r = ((li_config_table[i].coef_table[j] & 0xf) ^ (li_config_table[i].coef_table[j] >> 4));
  9948. }
  9949. }
  9950. if (j < li_total_channels)
  9951. {
  9952. plci->internal_command = plci->li_write_command;
  9953. if (plci_nl_busy(plci))
  9954. return (true);
  9955. to_ch = (a->li_pri) ? plci->li_bchannel_id - 1 : 0;
  9956. *(p++) = UDATA_REQUEST_XCONNECT_TO;
  9957. do
  9958. {
  9959. if (li_config_table[j].adapter->li_base != a->li_base)
  9960. {
  9961. r &= s &
  9962. ((li_config_table[j].send_b.card_address.low | li_config_table[j].send_b.card_address.high) ?
  9963. (LI_COEF_CH_CH | LI_COEF_CH_PC | LI_COEF_PC_CH | LI_COEF_PC_PC) : (LI_COEF_PC_CH | LI_COEF_PC_PC)) &
  9964. ((li_config_table[j].send_pc.card_address.low | li_config_table[j].send_pc.card_address.high) ?
  9965. (LI_COEF_CH_CH | LI_COEF_CH_PC | LI_COEF_PC_CH | LI_COEF_PC_PC) : (LI_COEF_CH_CH | LI_COEF_CH_PC));
  9966. }
  9967. n = 0;
  9968. do
  9969. {
  9970. if (r & xconnect_write_prog[n].mask)
  9971. {
  9972. if (xconnect_write_prog[n].from_pc)
  9973. transfer_address = &(li_config_table[j].send_pc);
  9974. else
  9975. transfer_address = &(li_config_table[j].send_b);
  9976. d = transfer_address->card_address.low;
  9977. *(p++) = (byte) d;
  9978. *(p++) = (byte)(d >> 8);
  9979. *(p++) = (byte)(d >> 16);
  9980. *(p++) = (byte)(d >> 24);
  9981. d = transfer_address->card_address.high;
  9982. *(p++) = (byte) d;
  9983. *(p++) = (byte)(d >> 8);
  9984. *(p++) = (byte)(d >> 16);
  9985. *(p++) = (byte)(d >> 24);
  9986. d = transfer_address->offset;
  9987. *(p++) = (byte) d;
  9988. *(p++) = (byte)(d >> 8);
  9989. *(p++) = (byte)(d >> 16);
  9990. *(p++) = (byte)(d >> 24);
  9991. w = xconnect_write_prog[n].to_pc ? to_ch | XCONNECT_CHANNEL_PORT_PC : to_ch;
  9992. *(p++) = (byte) w;
  9993. *(p++) = (byte)(w >> 8);
  9994. w = ((li_config_table[i].coef_table[j] & xconnect_write_prog[n].mask) == 0) ? 0x01 :
  9995. (li_config_table[i].adapter->u_law ?
  9996. (li_config_table[j].adapter->u_law ? 0x80 : 0x86) :
  9997. (li_config_table[j].adapter->u_law ? 0x7a : 0x80));
  9998. *(p++) = (byte) w;
  9999. *(p++) = (byte) 0;
  10000. li_config_table[i].coef_table[j] ^= xconnect_write_prog[n].mask << 4;
  10001. }
  10002. n++;
  10003. } while ((n < ARRAY_SIZE(xconnect_write_prog))
  10004. && ((p - plci->internal_req_buffer) + 16 < INTERNAL_REQ_BUFFER_SIZE));
  10005. if (n == ARRAY_SIZE(xconnect_write_prog))
  10006. {
  10007. do
  10008. {
  10009. j++;
  10010. if (j < li_total_channels)
  10011. r = ((li_config_table[i].coef_table[j] & 0xf) ^ (li_config_table[i].coef_table[j] >> 4));
  10012. } while ((j < li_total_channels)
  10013. && ((r == 0)
  10014. || (!(li_config_table[j].channel & LI_CHANNEL_ADDRESSES_SET))
  10015. || (!li_config_table[j].adapter->li_pri
  10016. && (j >= li_config_table[j].adapter->li_base + MIXER_BCHANNELS_BRI))
  10017. || (((li_config_table[j].send_b.card_address.low != li_config_table[i].send_b.card_address.low)
  10018. || (li_config_table[j].send_b.card_address.high != li_config_table[i].send_b.card_address.high))
  10019. && (!(a->manufacturer_features & MANUFACTURER_FEATURE_DMACONNECT)
  10020. || !(li_config_table[j].adapter->manufacturer_features & MANUFACTURER_FEATURE_DMACONNECT)))
  10021. || ((li_config_table[j].adapter->li_base != a->li_base)
  10022. && !(r & s &
  10023. ((li_config_table[j].send_b.card_address.low | li_config_table[j].send_b.card_address.high) ?
  10024. (LI_COEF_CH_CH | LI_COEF_CH_PC | LI_COEF_PC_CH | LI_COEF_PC_PC) : (LI_COEF_PC_CH | LI_COEF_PC_PC)) &
  10025. ((li_config_table[j].send_pc.card_address.low | li_config_table[j].send_pc.card_address.high) ?
  10026. (LI_COEF_CH_CH | LI_COEF_CH_PC | LI_COEF_PC_CH | LI_COEF_PC_PC) : (LI_COEF_CH_CH | LI_COEF_CH_PC))))));
  10027. }
  10028. } while ((j < li_total_channels)
  10029. && ((p - plci->internal_req_buffer) + 16 < INTERNAL_REQ_BUFFER_SIZE));
  10030. }
  10031. else if (j == li_total_channels)
  10032. {
  10033. plci->internal_command = plci->li_write_command;
  10034. if (plci_nl_busy(plci))
  10035. return (true);
  10036. if (a->li_pri)
  10037. {
  10038. *(p++) = UDATA_REQUEST_SET_MIXER_COEFS_PRI_SYNC;
  10039. w = 0;
  10040. if (li_config_table[i].channel & LI_CHANNEL_TX_DATA)
  10041. w |= MIXER_FEATURE_ENABLE_TX_DATA;
  10042. if (li_config_table[i].channel & LI_CHANNEL_RX_DATA)
  10043. w |= MIXER_FEATURE_ENABLE_RX_DATA;
  10044. *(p++) = (byte) w;
  10045. *(p++) = (byte)(w >> 8);
  10046. }
  10047. else
  10048. {
  10049. *(p++) = UDATA_REQUEST_SET_MIXER_COEFS_BRI;
  10050. w = 0;
  10051. if ((plci->tel == ADV_VOICE) && (plci == a->AdvSignalPLCI)
  10052. && (ADV_VOICE_NEW_COEF_BASE + sizeof(word) <= a->adv_voice_coef_length))
  10053. {
  10054. w = GET_WORD(a->adv_voice_coef_buffer + ADV_VOICE_NEW_COEF_BASE);
  10055. }
  10056. if (li_config_table[i].channel & LI_CHANNEL_TX_DATA)
  10057. w |= MIXER_FEATURE_ENABLE_TX_DATA;
  10058. if (li_config_table[i].channel & LI_CHANNEL_RX_DATA)
  10059. w |= MIXER_FEATURE_ENABLE_RX_DATA;
  10060. *(p++) = (byte) w;
  10061. *(p++) = (byte)(w >> 8);
  10062. for (j = 0; j < sizeof(ch_map); j += 2)
  10063. {
  10064. if (plci->li_bchannel_id == 2)
  10065. {
  10066. ch_map[j] = (byte)(j + 1);
  10067. ch_map[j + 1] = (byte) j;
  10068. }
  10069. else
  10070. {
  10071. ch_map[j] = (byte) j;
  10072. ch_map[j + 1] = (byte)(j + 1);
  10073. }
  10074. }
  10075. for (n = 0; n < ARRAY_SIZE(mixer_write_prog_bri); n++)
  10076. {
  10077. i = a->li_base + ch_map[mixer_write_prog_bri[n].to_ch];
  10078. j = a->li_base + ch_map[mixer_write_prog_bri[n].from_ch];
  10079. if (li_config_table[i].channel & li_config_table[j].channel & LI_CHANNEL_INVOLVED)
  10080. {
  10081. *p = (mixer_write_prog_bri[n].xconnect_override != 0) ?
  10082. mixer_write_prog_bri[n].xconnect_override :
  10083. ((li_config_table[i].coef_table[j] & mixer_write_prog_bri[n].mask) ? 0x80 : 0x01);
  10084. if ((i >= a->li_base + MIXER_BCHANNELS_BRI) || (j >= a->li_base + MIXER_BCHANNELS_BRI))
  10085. {
  10086. w = ((li_config_table[i].coef_table[j] & 0xf) ^ (li_config_table[i].coef_table[j] >> 4));
  10087. li_config_table[i].coef_table[j] ^= (w & mixer_write_prog_bri[n].mask) << 4;
  10088. }
  10089. }
  10090. else
  10091. {
  10092. *p = 0x00;
  10093. if ((a->AdvSignalPLCI != NULL) && (a->AdvSignalPLCI->tel == ADV_VOICE))
  10094. {
  10095. w = (plci == a->AdvSignalPLCI) ? n : mixer_swapped_index_bri[n];
  10096. if (ADV_VOICE_NEW_COEF_BASE + sizeof(word) + w < a->adv_voice_coef_length)
  10097. *p = a->adv_voice_coef_buffer[ADV_VOICE_NEW_COEF_BASE + sizeof(word) + w];
  10098. }
  10099. }
  10100. p++;
  10101. }
  10102. }
  10103. j = li_total_channels + 1;
  10104. }
  10105. }
  10106. else
  10107. {
  10108. if (j <= li_total_channels)
  10109. {
  10110. plci->internal_command = plci->li_write_command;
  10111. if (plci_nl_busy(plci))
  10112. return (true);
  10113. if (j < a->li_base)
  10114. j = a->li_base;
  10115. if (a->li_pri)
  10116. {
  10117. *(p++) = UDATA_REQUEST_SET_MIXER_COEFS_PRI_SYNC;
  10118. w = 0;
  10119. if (li_config_table[i].channel & LI_CHANNEL_TX_DATA)
  10120. w |= MIXER_FEATURE_ENABLE_TX_DATA;
  10121. if (li_config_table[i].channel & LI_CHANNEL_RX_DATA)
  10122. w |= MIXER_FEATURE_ENABLE_RX_DATA;
  10123. *(p++) = (byte) w;
  10124. *(p++) = (byte)(w >> 8);
  10125. for (n = 0; n < ARRAY_SIZE(mixer_write_prog_pri); n++)
  10126. {
  10127. *(p++) = (byte)((plci->li_bchannel_id - 1) | mixer_write_prog_pri[n].line_flags);
  10128. for (j = a->li_base; j < a->li_base + MIXER_CHANNELS_PRI; j++)
  10129. {
  10130. w = ((li_config_table[i].coef_table[j] & 0xf) ^ (li_config_table[i].coef_table[j] >> 4));
  10131. if (w & mixer_write_prog_pri[n].mask)
  10132. {
  10133. *(p++) = (li_config_table[i].coef_table[j] & mixer_write_prog_pri[n].mask) ? 0x80 : 0x01;
  10134. li_config_table[i].coef_table[j] ^= mixer_write_prog_pri[n].mask << 4;
  10135. }
  10136. else
  10137. *(p++) = 0x00;
  10138. }
  10139. *(p++) = (byte)((plci->li_bchannel_id - 1) | MIXER_COEF_LINE_ROW_FLAG | mixer_write_prog_pri[n].line_flags);
  10140. for (j = a->li_base; j < a->li_base + MIXER_CHANNELS_PRI; j++)
  10141. {
  10142. w = ((li_config_table[j].coef_table[i] & 0xf) ^ (li_config_table[j].coef_table[i] >> 4));
  10143. if (w & mixer_write_prog_pri[n].mask)
  10144. {
  10145. *(p++) = (li_config_table[j].coef_table[i] & mixer_write_prog_pri[n].mask) ? 0x80 : 0x01;
  10146. li_config_table[j].coef_table[i] ^= mixer_write_prog_pri[n].mask << 4;
  10147. }
  10148. else
  10149. *(p++) = 0x00;
  10150. }
  10151. }
  10152. }
  10153. else
  10154. {
  10155. *(p++) = UDATA_REQUEST_SET_MIXER_COEFS_BRI;
  10156. w = 0;
  10157. if ((plci->tel == ADV_VOICE) && (plci == a->AdvSignalPLCI)
  10158. && (ADV_VOICE_NEW_COEF_BASE + sizeof(word) <= a->adv_voice_coef_length))
  10159. {
  10160. w = GET_WORD(a->adv_voice_coef_buffer + ADV_VOICE_NEW_COEF_BASE);
  10161. }
  10162. if (li_config_table[i].channel & LI_CHANNEL_TX_DATA)
  10163. w |= MIXER_FEATURE_ENABLE_TX_DATA;
  10164. if (li_config_table[i].channel & LI_CHANNEL_RX_DATA)
  10165. w |= MIXER_FEATURE_ENABLE_RX_DATA;
  10166. *(p++) = (byte) w;
  10167. *(p++) = (byte)(w >> 8);
  10168. for (j = 0; j < sizeof(ch_map); j += 2)
  10169. {
  10170. if (plci->li_bchannel_id == 2)
  10171. {
  10172. ch_map[j] = (byte)(j + 1);
  10173. ch_map[j + 1] = (byte) j;
  10174. }
  10175. else
  10176. {
  10177. ch_map[j] = (byte) j;
  10178. ch_map[j + 1] = (byte)(j + 1);
  10179. }
  10180. }
  10181. for (n = 0; n < ARRAY_SIZE(mixer_write_prog_bri); n++)
  10182. {
  10183. i = a->li_base + ch_map[mixer_write_prog_bri[n].to_ch];
  10184. j = a->li_base + ch_map[mixer_write_prog_bri[n].from_ch];
  10185. if (li_config_table[i].channel & li_config_table[j].channel & LI_CHANNEL_INVOLVED)
  10186. {
  10187. *p = ((li_config_table[i].coef_table[j] & mixer_write_prog_bri[n].mask) ? 0x80 : 0x01);
  10188. w = ((li_config_table[i].coef_table[j] & 0xf) ^ (li_config_table[i].coef_table[j] >> 4));
  10189. li_config_table[i].coef_table[j] ^= (w & mixer_write_prog_bri[n].mask) << 4;
  10190. }
  10191. else
  10192. {
  10193. *p = 0x00;
  10194. if ((a->AdvSignalPLCI != NULL) && (a->AdvSignalPLCI->tel == ADV_VOICE))
  10195. {
  10196. w = (plci == a->AdvSignalPLCI) ? n : mixer_swapped_index_bri[n];
  10197. if (ADV_VOICE_NEW_COEF_BASE + sizeof(word) + w < a->adv_voice_coef_length)
  10198. *p = a->adv_voice_coef_buffer[ADV_VOICE_NEW_COEF_BASE + sizeof(word) + w];
  10199. }
  10200. }
  10201. p++;
  10202. }
  10203. }
  10204. j = li_total_channels + 1;
  10205. }
  10206. }
  10207. plci->li_write_channel = j;
  10208. if (p != plci->internal_req_buffer)
  10209. {
  10210. plci->NData[0].P = plci->internal_req_buffer;
  10211. plci->NData[0].PLength = p - plci->internal_req_buffer;
  10212. plci->NL.X = plci->NData;
  10213. plci->NL.ReqCh = 0;
  10214. plci->NL.Req = plci->nl_req = (byte) N_UDATA;
  10215. plci->adapter->request(&plci->NL);
  10216. }
  10217. return (true);
  10218. }
  10219. static void mixer_notify_update(PLCI *plci, byte others)
  10220. {
  10221. DIVA_CAPI_ADAPTER *a;
  10222. word i, w;
  10223. PLCI *notify_plci;
  10224. byte msg[sizeof(CAPI_MSG_HEADER) + 6];
  10225. dbug(1, dprintf("[%06lx] %s,%d: mixer_notify_update %d",
  10226. (dword)((plci->Id << 8) | UnMapController(plci->adapter->Id)),
  10227. (char *)(FILE_), __LINE__, others));
  10228. a = plci->adapter;
  10229. if (a->profile.Global_Options & GL_LINE_INTERCONNECT_SUPPORTED)
  10230. {
  10231. if (others)
  10232. plci->li_notify_update = true;
  10233. i = 0;
  10234. do
  10235. {
  10236. notify_plci = NULL;
  10237. if (others)
  10238. {
  10239. while ((i < li_total_channels) && (li_config_table[i].plci == NULL))
  10240. i++;
  10241. if (i < li_total_channels)
  10242. notify_plci = li_config_table[i++].plci;
  10243. }
  10244. else
  10245. {
  10246. if ((plci->li_bchannel_id != 0)
  10247. && (li_config_table[a->li_base + (plci->li_bchannel_id - 1)].plci == plci))
  10248. {
  10249. notify_plci = plci;
  10250. }
  10251. }
  10252. if ((notify_plci != NULL)
  10253. && !notify_plci->li_notify_update
  10254. && (notify_plci->appl != NULL)
  10255. && (notify_plci->State)
  10256. && notify_plci->NL.Id && !notify_plci->nl_remove_id)
  10257. {
  10258. notify_plci->li_notify_update = true;
  10259. ((CAPI_MSG *) msg)->header.length = 18;
  10260. ((CAPI_MSG *) msg)->header.appl_id = notify_plci->appl->Id;
  10261. ((CAPI_MSG *) msg)->header.command = _FACILITY_R;
  10262. ((CAPI_MSG *) msg)->header.number = 0;
  10263. ((CAPI_MSG *) msg)->header.controller = notify_plci->adapter->Id;
  10264. ((CAPI_MSG *) msg)->header.plci = notify_plci->Id;
  10265. ((CAPI_MSG *) msg)->header.ncci = 0;
  10266. ((CAPI_MSG *) msg)->info.facility_req.Selector = SELECTOR_LINE_INTERCONNECT;
  10267. ((CAPI_MSG *) msg)->info.facility_req.structs[0] = 3;
  10268. ((CAPI_MSG *) msg)->info.facility_req.structs[1] = LI_REQ_SILENT_UPDATE & 0xff;
  10269. ((CAPI_MSG *) msg)->info.facility_req.structs[2] = LI_REQ_SILENT_UPDATE >> 8;
  10270. ((CAPI_MSG *) msg)->info.facility_req.structs[3] = 0;
  10271. w = api_put(notify_plci->appl, (CAPI_MSG *) msg);
  10272. if (w != _QUEUE_FULL)
  10273. {
  10274. if (w != 0)
  10275. {
  10276. dbug(1, dprintf("[%06lx] %s,%d: Interconnect notify failed %06x %d",
  10277. (dword)((plci->Id << 8) | UnMapController(plci->adapter->Id)),
  10278. (char *)(FILE_), __LINE__,
  10279. (dword)((notify_plci->Id << 8) | UnMapController(notify_plci->adapter->Id)), w));
  10280. }
  10281. notify_plci->li_notify_update = false;
  10282. }
  10283. }
  10284. } while (others && (notify_plci != NULL));
  10285. if (others)
  10286. plci->li_notify_update = false;
  10287. }
  10288. }
  10289. static void mixer_clear_config(PLCI *plci)
  10290. {
  10291. DIVA_CAPI_ADAPTER *a;
  10292. word i, j;
  10293. dbug(1, dprintf("[%06lx] %s,%d: mixer_clear_config",
  10294. (dword)((plci->Id << 8) | UnMapController(plci->adapter->Id)),
  10295. (char *)(FILE_), __LINE__));
  10296. plci->li_notify_update = false;
  10297. plci->li_plci_b_write_pos = 0;
  10298. plci->li_plci_b_read_pos = 0;
  10299. plci->li_plci_b_req_pos = 0;
  10300. a = plci->adapter;
  10301. if ((plci->li_bchannel_id != 0)
  10302. && (li_config_table[a->li_base + (plci->li_bchannel_id - 1)].plci == plci))
  10303. {
  10304. i = a->li_base + (plci->li_bchannel_id - 1);
  10305. li_config_table[i].curchnl = 0;
  10306. li_config_table[i].channel = 0;
  10307. li_config_table[i].chflags = 0;
  10308. for (j = 0; j < li_total_channels; j++)
  10309. {
  10310. li_config_table[j].flag_table[i] = 0;
  10311. li_config_table[i].flag_table[j] = 0;
  10312. li_config_table[i].coef_table[j] = 0;
  10313. li_config_table[j].coef_table[i] = 0;
  10314. }
  10315. if (!a->li_pri)
  10316. {
  10317. li_config_table[i].coef_table[i] |= LI_COEF_CH_PC_SET | LI_COEF_PC_CH_SET;
  10318. if ((plci->tel == ADV_VOICE) && (plci == a->AdvSignalPLCI))
  10319. {
  10320. i = a->li_base + MIXER_IC_CHANNEL_BASE + (plci->li_bchannel_id - 1);
  10321. li_config_table[i].curchnl = 0;
  10322. li_config_table[i].channel = 0;
  10323. li_config_table[i].chflags = 0;
  10324. for (j = 0; j < li_total_channels; j++)
  10325. {
  10326. li_config_table[i].flag_table[j] = 0;
  10327. li_config_table[j].flag_table[i] = 0;
  10328. li_config_table[i].coef_table[j] = 0;
  10329. li_config_table[j].coef_table[i] = 0;
  10330. }
  10331. if (a->manufacturer_features & MANUFACTURER_FEATURE_SLAVE_CODEC)
  10332. {
  10333. i = a->li_base + MIXER_IC_CHANNEL_BASE + (2 - plci->li_bchannel_id);
  10334. li_config_table[i].curchnl = 0;
  10335. li_config_table[i].channel = 0;
  10336. li_config_table[i].chflags = 0;
  10337. for (j = 0; j < li_total_channels; j++)
  10338. {
  10339. li_config_table[i].flag_table[j] = 0;
  10340. li_config_table[j].flag_table[i] = 0;
  10341. li_config_table[i].coef_table[j] = 0;
  10342. li_config_table[j].coef_table[i] = 0;
  10343. }
  10344. }
  10345. }
  10346. }
  10347. }
  10348. }
  10349. static void mixer_prepare_switch(dword Id, PLCI *plci)
  10350. {
  10351. dbug(1, dprintf("[%06lx] %s,%d: mixer_prepare_switch",
  10352. UnMapId(Id), (char *)(FILE_), __LINE__));
  10353. do
  10354. {
  10355. mixer_indication_coefs_set(Id, plci);
  10356. } while (plci->li_plci_b_read_pos != plci->li_plci_b_req_pos);
  10357. }
  10358. static word mixer_save_config(dword Id, PLCI *plci, byte Rc)
  10359. {
  10360. DIVA_CAPI_ADAPTER *a;
  10361. word i, j;
  10362. dbug(1, dprintf("[%06lx] %s,%d: mixer_save_config %02x %d",
  10363. UnMapId(Id), (char *)(FILE_), __LINE__, Rc, plci->adjust_b_state));
  10364. a = plci->adapter;
  10365. if ((plci->li_bchannel_id != 0)
  10366. && (li_config_table[a->li_base + (plci->li_bchannel_id - 1)].plci == plci))
  10367. {
  10368. i = a->li_base + (plci->li_bchannel_id - 1);
  10369. for (j = 0; j < li_total_channels; j++)
  10370. {
  10371. li_config_table[i].coef_table[j] &= 0xf;
  10372. li_config_table[j].coef_table[i] &= 0xf;
  10373. }
  10374. if (!a->li_pri)
  10375. li_config_table[i].coef_table[i] |= LI_COEF_CH_PC_SET | LI_COEF_PC_CH_SET;
  10376. }
  10377. return (GOOD);
  10378. }
  10379. static word mixer_restore_config(dword Id, PLCI *plci, byte Rc)
  10380. {
  10381. DIVA_CAPI_ADAPTER *a;
  10382. word Info;
  10383. dbug(1, dprintf("[%06lx] %s,%d: mixer_restore_config %02x %d",
  10384. UnMapId(Id), (char *)(FILE_), __LINE__, Rc, plci->adjust_b_state));
  10385. Info = GOOD;
  10386. a = plci->adapter;
  10387. if ((plci->B1_facilities & B1_FACILITY_MIXER)
  10388. && (plci->li_bchannel_id != 0)
  10389. && (li_config_table[a->li_base + (plci->li_bchannel_id - 1)].plci == plci))
  10390. {
  10391. switch (plci->adjust_b_state)
  10392. {
  10393. case ADJUST_B_RESTORE_MIXER_1:
  10394. if (a->manufacturer_features & MANUFACTURER_FEATURE_XCONNECT)
  10395. {
  10396. plci->internal_command = plci->adjust_b_command;
  10397. if (plci_nl_busy(plci))
  10398. {
  10399. plci->adjust_b_state = ADJUST_B_RESTORE_MIXER_1;
  10400. break;
  10401. }
  10402. xconnect_query_addresses(plci);
  10403. plci->adjust_b_state = ADJUST_B_RESTORE_MIXER_2;
  10404. break;
  10405. }
  10406. plci->adjust_b_state = ADJUST_B_RESTORE_MIXER_5;
  10407. Rc = OK;
  10408. /* fall through */
  10409. case ADJUST_B_RESTORE_MIXER_2:
  10410. case ADJUST_B_RESTORE_MIXER_3:
  10411. case ADJUST_B_RESTORE_MIXER_4:
  10412. if ((Rc != OK) && (Rc != OK_FC) && (Rc != 0))
  10413. {
  10414. dbug(1, dprintf("[%06lx] %s,%d: Adjust B query addresses failed %02x",
  10415. UnMapId(Id), (char *)(FILE_), __LINE__, Rc));
  10416. Info = _WRONG_STATE;
  10417. break;
  10418. }
  10419. if (Rc == OK)
  10420. {
  10421. if (plci->adjust_b_state == ADJUST_B_RESTORE_MIXER_2)
  10422. plci->adjust_b_state = ADJUST_B_RESTORE_MIXER_3;
  10423. else if (plci->adjust_b_state == ADJUST_B_RESTORE_MIXER_4)
  10424. plci->adjust_b_state = ADJUST_B_RESTORE_MIXER_5;
  10425. }
  10426. else if (Rc == 0)
  10427. {
  10428. if (plci->adjust_b_state == ADJUST_B_RESTORE_MIXER_2)
  10429. plci->adjust_b_state = ADJUST_B_RESTORE_MIXER_4;
  10430. else if (plci->adjust_b_state == ADJUST_B_RESTORE_MIXER_3)
  10431. plci->adjust_b_state = ADJUST_B_RESTORE_MIXER_5;
  10432. }
  10433. if (plci->adjust_b_state != ADJUST_B_RESTORE_MIXER_5)
  10434. {
  10435. plci->internal_command = plci->adjust_b_command;
  10436. break;
  10437. }
  10438. /* fall through */
  10439. case ADJUST_B_RESTORE_MIXER_5:
  10440. xconnect_write_coefs(plci, plci->adjust_b_command);
  10441. plci->adjust_b_state = ADJUST_B_RESTORE_MIXER_6;
  10442. Rc = OK;
  10443. /* fall through */
  10444. case ADJUST_B_RESTORE_MIXER_6:
  10445. if (!xconnect_write_coefs_process(Id, plci, Rc))
  10446. {
  10447. dbug(1, dprintf("[%06lx] %s,%d: Write mixer coefs failed",
  10448. UnMapId(Id), (char *)(FILE_), __LINE__));
  10449. Info = _FACILITY_NOT_SUPPORTED;
  10450. break;
  10451. }
  10452. if (plci->internal_command)
  10453. break;
  10454. plci->adjust_b_state = ADJUST_B_RESTORE_MIXER_7;
  10455. case ADJUST_B_RESTORE_MIXER_7:
  10456. break;
  10457. }
  10458. }
  10459. return (Info);
  10460. }
  10461. static void mixer_command(dword Id, PLCI *plci, byte Rc)
  10462. {
  10463. DIVA_CAPI_ADAPTER *a;
  10464. word i, internal_command;
  10465. dbug(1, dprintf("[%06lx] %s,%d: mixer_command %02x %04x %04x",
  10466. UnMapId(Id), (char *)(FILE_), __LINE__, Rc, plci->internal_command,
  10467. plci->li_cmd));
  10468. a = plci->adapter;
  10469. internal_command = plci->internal_command;
  10470. plci->internal_command = 0;
  10471. switch (plci->li_cmd)
  10472. {
  10473. case LI_REQ_CONNECT:
  10474. case LI_REQ_DISCONNECT:
  10475. case LI_REQ_SILENT_UPDATE:
  10476. switch (internal_command)
  10477. {
  10478. default:
  10479. if (plci->li_channel_bits & LI_CHANNEL_INVOLVED)
  10480. {
  10481. adjust_b1_resource(Id, plci, NULL, (word)(plci->B1_facilities |
  10482. B1_FACILITY_MIXER), MIXER_COMMAND_1);
  10483. }
  10484. /* fall through */
  10485. case MIXER_COMMAND_1:
  10486. if (plci->li_channel_bits & LI_CHANNEL_INVOLVED)
  10487. {
  10488. if (adjust_b_process(Id, plci, Rc) != GOOD)
  10489. {
  10490. dbug(1, dprintf("[%06lx] %s,%d: Load mixer failed",
  10491. UnMapId(Id), (char *)(FILE_), __LINE__));
  10492. break;
  10493. }
  10494. if (plci->internal_command)
  10495. return;
  10496. }
  10497. plci->li_plci_b_req_pos = plci->li_plci_b_write_pos;
  10498. if ((plci->li_channel_bits & LI_CHANNEL_INVOLVED)
  10499. || ((get_b1_facilities(plci, plci->B1_resource) & B1_FACILITY_MIXER)
  10500. && (add_b1_facilities(plci, plci->B1_resource, (word)(plci->B1_facilities &
  10501. ~B1_FACILITY_MIXER)) == plci->B1_resource)))
  10502. {
  10503. xconnect_write_coefs(plci, MIXER_COMMAND_2);
  10504. }
  10505. else
  10506. {
  10507. do
  10508. {
  10509. mixer_indication_coefs_set(Id, plci);
  10510. } while (plci->li_plci_b_read_pos != plci->li_plci_b_req_pos);
  10511. }
  10512. /* fall through */
  10513. case MIXER_COMMAND_2:
  10514. if ((plci->li_channel_bits & LI_CHANNEL_INVOLVED)
  10515. || ((get_b1_facilities(plci, plci->B1_resource) & B1_FACILITY_MIXER)
  10516. && (add_b1_facilities(plci, plci->B1_resource, (word)(plci->B1_facilities &
  10517. ~B1_FACILITY_MIXER)) == plci->B1_resource)))
  10518. {
  10519. if (!xconnect_write_coefs_process(Id, plci, Rc))
  10520. {
  10521. dbug(1, dprintf("[%06lx] %s,%d: Write mixer coefs failed",
  10522. UnMapId(Id), (char *)(FILE_), __LINE__));
  10523. if (plci->li_plci_b_write_pos != plci->li_plci_b_req_pos)
  10524. {
  10525. do
  10526. {
  10527. plci->li_plci_b_write_pos = (plci->li_plci_b_write_pos == 0) ?
  10528. LI_PLCI_B_QUEUE_ENTRIES - 1 : plci->li_plci_b_write_pos - 1;
  10529. i = (plci->li_plci_b_write_pos == 0) ?
  10530. LI_PLCI_B_QUEUE_ENTRIES - 1 : plci->li_plci_b_write_pos - 1;
  10531. } while ((plci->li_plci_b_write_pos != plci->li_plci_b_req_pos)
  10532. && !(plci->li_plci_b_queue[i] & LI_PLCI_B_LAST_FLAG));
  10533. }
  10534. break;
  10535. }
  10536. if (plci->internal_command)
  10537. return;
  10538. }
  10539. if (!(plci->li_channel_bits & LI_CHANNEL_INVOLVED))
  10540. {
  10541. adjust_b1_resource(Id, plci, NULL, (word)(plci->B1_facilities &
  10542. ~B1_FACILITY_MIXER), MIXER_COMMAND_3);
  10543. }
  10544. /* fall through */
  10545. case MIXER_COMMAND_3:
  10546. if (!(plci->li_channel_bits & LI_CHANNEL_INVOLVED))
  10547. {
  10548. if (adjust_b_process(Id, plci, Rc) != GOOD)
  10549. {
  10550. dbug(1, dprintf("[%06lx] %s,%d: Unload mixer failed",
  10551. UnMapId(Id), (char *)(FILE_), __LINE__));
  10552. break;
  10553. }
  10554. if (plci->internal_command)
  10555. return;
  10556. }
  10557. break;
  10558. }
  10559. break;
  10560. }
  10561. if ((plci->li_bchannel_id == 0)
  10562. || (li_config_table[a->li_base + (plci->li_bchannel_id - 1)].plci != plci))
  10563. {
  10564. dbug(1, dprintf("[%06x] %s,%d: Channel id wiped out %d",
  10565. UnMapId(Id), (char *)(FILE_), __LINE__, (int)(plci->li_bchannel_id)));
  10566. }
  10567. else
  10568. {
  10569. i = a->li_base + (plci->li_bchannel_id - 1);
  10570. li_config_table[i].curchnl = plci->li_channel_bits;
  10571. if (!a->li_pri && (plci->tel == ADV_VOICE) && (plci == a->AdvSignalPLCI))
  10572. {
  10573. i = a->li_base + MIXER_IC_CHANNEL_BASE + (plci->li_bchannel_id - 1);
  10574. li_config_table[i].curchnl = plci->li_channel_bits;
  10575. if (a->manufacturer_features & MANUFACTURER_FEATURE_SLAVE_CODEC)
  10576. {
  10577. i = a->li_base + MIXER_IC_CHANNEL_BASE + (2 - plci->li_bchannel_id);
  10578. li_config_table[i].curchnl = plci->li_channel_bits;
  10579. }
  10580. }
  10581. }
  10582. }
  10583. static void li_update_connect(dword Id, DIVA_CAPI_ADAPTER *a, PLCI *plci,
  10584. dword plci_b_id, byte connect, dword li_flags)
  10585. {
  10586. word i, ch_a, ch_a_v, ch_a_s, ch_b, ch_b_v, ch_b_s;
  10587. PLCI *plci_b;
  10588. DIVA_CAPI_ADAPTER *a_b;
  10589. a_b = &(adapter[MapController((byte)(plci_b_id & 0x7f)) - 1]);
  10590. plci_b = &(a_b->plci[((plci_b_id >> 8) & 0xff) - 1]);
  10591. ch_a = a->li_base + (plci->li_bchannel_id - 1);
  10592. if (!a->li_pri && (plci->tel == ADV_VOICE)
  10593. && (plci == a->AdvSignalPLCI) && (Id & EXT_CONTROLLER))
  10594. {
  10595. ch_a_v = ch_a + MIXER_IC_CHANNEL_BASE;
  10596. ch_a_s = (a->manufacturer_features & MANUFACTURER_FEATURE_SLAVE_CODEC) ?
  10597. a->li_base + MIXER_IC_CHANNEL_BASE + (2 - plci->li_bchannel_id) : ch_a_v;
  10598. }
  10599. else
  10600. {
  10601. ch_a_v = ch_a;
  10602. ch_a_s = ch_a;
  10603. }
  10604. ch_b = a_b->li_base + (plci_b->li_bchannel_id - 1);
  10605. if (!a_b->li_pri && (plci_b->tel == ADV_VOICE)
  10606. && (plci_b == a_b->AdvSignalPLCI) && (plci_b_id & EXT_CONTROLLER))
  10607. {
  10608. ch_b_v = ch_b + MIXER_IC_CHANNEL_BASE;
  10609. ch_b_s = (a_b->manufacturer_features & MANUFACTURER_FEATURE_SLAVE_CODEC) ?
  10610. a_b->li_base + MIXER_IC_CHANNEL_BASE + (2 - plci_b->li_bchannel_id) : ch_b_v;
  10611. }
  10612. else
  10613. {
  10614. ch_b_v = ch_b;
  10615. ch_b_s = ch_b;
  10616. }
  10617. if (connect)
  10618. {
  10619. li_config_table[ch_a].flag_table[ch_a_v] &= ~LI_FLAG_MONITOR;
  10620. li_config_table[ch_a].flag_table[ch_a_s] &= ~LI_FLAG_MONITOR;
  10621. li_config_table[ch_a_v].flag_table[ch_a] &= ~(LI_FLAG_ANNOUNCEMENT | LI_FLAG_MIX);
  10622. li_config_table[ch_a_s].flag_table[ch_a] &= ~(LI_FLAG_ANNOUNCEMENT | LI_FLAG_MIX);
  10623. }
  10624. li_config_table[ch_a].flag_table[ch_b_v] &= ~LI_FLAG_MONITOR;
  10625. li_config_table[ch_a].flag_table[ch_b_s] &= ~LI_FLAG_MONITOR;
  10626. li_config_table[ch_b_v].flag_table[ch_a] &= ~(LI_FLAG_ANNOUNCEMENT | LI_FLAG_MIX);
  10627. li_config_table[ch_b_s].flag_table[ch_a] &= ~(LI_FLAG_ANNOUNCEMENT | LI_FLAG_MIX);
  10628. if (ch_a_v == ch_b_v)
  10629. {
  10630. li_config_table[ch_a_v].flag_table[ch_b_v] &= ~LI_FLAG_CONFERENCE;
  10631. li_config_table[ch_a_s].flag_table[ch_b_s] &= ~LI_FLAG_CONFERENCE;
  10632. }
  10633. else
  10634. {
  10635. if (li_config_table[ch_a_v].flag_table[ch_b_v] & LI_FLAG_CONFERENCE)
  10636. {
  10637. for (i = 0; i < li_total_channels; i++)
  10638. {
  10639. if (i != ch_a_v)
  10640. li_config_table[ch_a_v].flag_table[i] &= ~LI_FLAG_CONFERENCE;
  10641. }
  10642. }
  10643. if (li_config_table[ch_a_s].flag_table[ch_b_v] & LI_FLAG_CONFERENCE)
  10644. {
  10645. for (i = 0; i < li_total_channels; i++)
  10646. {
  10647. if (i != ch_a_s)
  10648. li_config_table[ch_a_s].flag_table[i] &= ~LI_FLAG_CONFERENCE;
  10649. }
  10650. }
  10651. if (li_config_table[ch_b_v].flag_table[ch_a_v] & LI_FLAG_CONFERENCE)
  10652. {
  10653. for (i = 0; i < li_total_channels; i++)
  10654. {
  10655. if (i != ch_a_v)
  10656. li_config_table[i].flag_table[ch_a_v] &= ~LI_FLAG_CONFERENCE;
  10657. }
  10658. }
  10659. if (li_config_table[ch_b_v].flag_table[ch_a_s] & LI_FLAG_CONFERENCE)
  10660. {
  10661. for (i = 0; i < li_total_channels; i++)
  10662. {
  10663. if (i != ch_a_s)
  10664. li_config_table[i].flag_table[ch_a_s] &= ~LI_FLAG_CONFERENCE;
  10665. }
  10666. }
  10667. }
  10668. if (li_flags & LI_FLAG_CONFERENCE_A_B)
  10669. {
  10670. li_config_table[ch_b_v].flag_table[ch_a_v] |= LI_FLAG_CONFERENCE;
  10671. li_config_table[ch_b_s].flag_table[ch_a_v] |= LI_FLAG_CONFERENCE;
  10672. li_config_table[ch_b_v].flag_table[ch_a_s] |= LI_FLAG_CONFERENCE;
  10673. li_config_table[ch_b_s].flag_table[ch_a_s] |= LI_FLAG_CONFERENCE;
  10674. }
  10675. if (li_flags & LI_FLAG_CONFERENCE_B_A)
  10676. {
  10677. li_config_table[ch_a_v].flag_table[ch_b_v] |= LI_FLAG_CONFERENCE;
  10678. li_config_table[ch_a_v].flag_table[ch_b_s] |= LI_FLAG_CONFERENCE;
  10679. li_config_table[ch_a_s].flag_table[ch_b_v] |= LI_FLAG_CONFERENCE;
  10680. li_config_table[ch_a_s].flag_table[ch_b_s] |= LI_FLAG_CONFERENCE;
  10681. }
  10682. if (li_flags & LI_FLAG_MONITOR_A)
  10683. {
  10684. li_config_table[ch_a].flag_table[ch_a_v] |= LI_FLAG_MONITOR;
  10685. li_config_table[ch_a].flag_table[ch_a_s] |= LI_FLAG_MONITOR;
  10686. }
  10687. if (li_flags & LI_FLAG_MONITOR_B)
  10688. {
  10689. li_config_table[ch_a].flag_table[ch_b_v] |= LI_FLAG_MONITOR;
  10690. li_config_table[ch_a].flag_table[ch_b_s] |= LI_FLAG_MONITOR;
  10691. }
  10692. if (li_flags & LI_FLAG_ANNOUNCEMENT_A)
  10693. {
  10694. li_config_table[ch_a_v].flag_table[ch_a] |= LI_FLAG_ANNOUNCEMENT;
  10695. li_config_table[ch_a_s].flag_table[ch_a] |= LI_FLAG_ANNOUNCEMENT;
  10696. }
  10697. if (li_flags & LI_FLAG_ANNOUNCEMENT_B)
  10698. {
  10699. li_config_table[ch_b_v].flag_table[ch_a] |= LI_FLAG_ANNOUNCEMENT;
  10700. li_config_table[ch_b_s].flag_table[ch_a] |= LI_FLAG_ANNOUNCEMENT;
  10701. }
  10702. if (li_flags & LI_FLAG_MIX_A)
  10703. {
  10704. li_config_table[ch_a_v].flag_table[ch_a] |= LI_FLAG_MIX;
  10705. li_config_table[ch_a_s].flag_table[ch_a] |= LI_FLAG_MIX;
  10706. }
  10707. if (li_flags & LI_FLAG_MIX_B)
  10708. {
  10709. li_config_table[ch_b_v].flag_table[ch_a] |= LI_FLAG_MIX;
  10710. li_config_table[ch_b_s].flag_table[ch_a] |= LI_FLAG_MIX;
  10711. }
  10712. if (ch_a_v != ch_a_s)
  10713. {
  10714. li_config_table[ch_a_v].flag_table[ch_a_s] |= LI_FLAG_CONFERENCE;
  10715. li_config_table[ch_a_s].flag_table[ch_a_v] |= LI_FLAG_CONFERENCE;
  10716. }
  10717. if (ch_b_v != ch_b_s)
  10718. {
  10719. li_config_table[ch_b_v].flag_table[ch_b_s] |= LI_FLAG_CONFERENCE;
  10720. li_config_table[ch_b_s].flag_table[ch_b_v] |= LI_FLAG_CONFERENCE;
  10721. }
  10722. }
  10723. static void li2_update_connect(dword Id, DIVA_CAPI_ADAPTER *a, PLCI *plci,
  10724. dword plci_b_id, byte connect, dword li_flags)
  10725. {
  10726. word ch_a, ch_a_v, ch_a_s, ch_b, ch_b_v, ch_b_s;
  10727. PLCI *plci_b;
  10728. DIVA_CAPI_ADAPTER *a_b;
  10729. a_b = &(adapter[MapController((byte)(plci_b_id & 0x7f)) - 1]);
  10730. plci_b = &(a_b->plci[((plci_b_id >> 8) & 0xff) - 1]);
  10731. ch_a = a->li_base + (plci->li_bchannel_id - 1);
  10732. if (!a->li_pri && (plci->tel == ADV_VOICE)
  10733. && (plci == a->AdvSignalPLCI) && (Id & EXT_CONTROLLER))
  10734. {
  10735. ch_a_v = ch_a + MIXER_IC_CHANNEL_BASE;
  10736. ch_a_s = (a->manufacturer_features & MANUFACTURER_FEATURE_SLAVE_CODEC) ?
  10737. a->li_base + MIXER_IC_CHANNEL_BASE + (2 - plci->li_bchannel_id) : ch_a_v;
  10738. }
  10739. else
  10740. {
  10741. ch_a_v = ch_a;
  10742. ch_a_s = ch_a;
  10743. }
  10744. ch_b = a_b->li_base + (plci_b->li_bchannel_id - 1);
  10745. if (!a_b->li_pri && (plci_b->tel == ADV_VOICE)
  10746. && (plci_b == a_b->AdvSignalPLCI) && (plci_b_id & EXT_CONTROLLER))
  10747. {
  10748. ch_b_v = ch_b + MIXER_IC_CHANNEL_BASE;
  10749. ch_b_s = (a_b->manufacturer_features & MANUFACTURER_FEATURE_SLAVE_CODEC) ?
  10750. a_b->li_base + MIXER_IC_CHANNEL_BASE + (2 - plci_b->li_bchannel_id) : ch_b_v;
  10751. }
  10752. else
  10753. {
  10754. ch_b_v = ch_b;
  10755. ch_b_s = ch_b;
  10756. }
  10757. if (connect)
  10758. {
  10759. li_config_table[ch_b].flag_table[ch_b_v] &= ~LI_FLAG_MONITOR;
  10760. li_config_table[ch_b].flag_table[ch_b_s] &= ~LI_FLAG_MONITOR;
  10761. li_config_table[ch_b_v].flag_table[ch_b] &= ~LI_FLAG_MIX;
  10762. li_config_table[ch_b_s].flag_table[ch_b] &= ~LI_FLAG_MIX;
  10763. li_config_table[ch_b].flag_table[ch_b] &= ~LI_FLAG_PCCONNECT;
  10764. li_config_table[ch_b].chflags &= ~(LI_CHFLAG_MONITOR | LI_CHFLAG_MIX | LI_CHFLAG_LOOP);
  10765. }
  10766. li_config_table[ch_b_v].flag_table[ch_a_v] &= ~(LI_FLAG_INTERCONNECT | LI_FLAG_CONFERENCE);
  10767. li_config_table[ch_b_s].flag_table[ch_a_v] &= ~(LI_FLAG_INTERCONNECT | LI_FLAG_CONFERENCE);
  10768. li_config_table[ch_b_v].flag_table[ch_a_s] &= ~(LI_FLAG_INTERCONNECT | LI_FLAG_CONFERENCE);
  10769. li_config_table[ch_b_s].flag_table[ch_a_s] &= ~(LI_FLAG_INTERCONNECT | LI_FLAG_CONFERENCE);
  10770. li_config_table[ch_a_v].flag_table[ch_b_v] &= ~(LI_FLAG_INTERCONNECT | LI_FLAG_CONFERENCE);
  10771. li_config_table[ch_a_v].flag_table[ch_b_s] &= ~(LI_FLAG_INTERCONNECT | LI_FLAG_CONFERENCE);
  10772. li_config_table[ch_a_s].flag_table[ch_b_v] &= ~(LI_FLAG_INTERCONNECT | LI_FLAG_CONFERENCE);
  10773. li_config_table[ch_a_s].flag_table[ch_b_s] &= ~(LI_FLAG_INTERCONNECT | LI_FLAG_CONFERENCE);
  10774. if (li_flags & LI2_FLAG_INTERCONNECT_A_B)
  10775. {
  10776. li_config_table[ch_b_v].flag_table[ch_a_v] |= LI_FLAG_INTERCONNECT;
  10777. li_config_table[ch_b_s].flag_table[ch_a_v] |= LI_FLAG_INTERCONNECT;
  10778. li_config_table[ch_b_v].flag_table[ch_a_s] |= LI_FLAG_INTERCONNECT;
  10779. li_config_table[ch_b_s].flag_table[ch_a_s] |= LI_FLAG_INTERCONNECT;
  10780. }
  10781. if (li_flags & LI2_FLAG_INTERCONNECT_B_A)
  10782. {
  10783. li_config_table[ch_a_v].flag_table[ch_b_v] |= LI_FLAG_INTERCONNECT;
  10784. li_config_table[ch_a_v].flag_table[ch_b_s] |= LI_FLAG_INTERCONNECT;
  10785. li_config_table[ch_a_s].flag_table[ch_b_v] |= LI_FLAG_INTERCONNECT;
  10786. li_config_table[ch_a_s].flag_table[ch_b_s] |= LI_FLAG_INTERCONNECT;
  10787. }
  10788. if (li_flags & LI2_FLAG_MONITOR_B)
  10789. {
  10790. li_config_table[ch_b].flag_table[ch_b_v] |= LI_FLAG_MONITOR;
  10791. li_config_table[ch_b].flag_table[ch_b_s] |= LI_FLAG_MONITOR;
  10792. }
  10793. if (li_flags & LI2_FLAG_MIX_B)
  10794. {
  10795. li_config_table[ch_b_v].flag_table[ch_b] |= LI_FLAG_MIX;
  10796. li_config_table[ch_b_s].flag_table[ch_b] |= LI_FLAG_MIX;
  10797. }
  10798. if (li_flags & LI2_FLAG_MONITOR_X)
  10799. li_config_table[ch_b].chflags |= LI_CHFLAG_MONITOR;
  10800. if (li_flags & LI2_FLAG_MIX_X)
  10801. li_config_table[ch_b].chflags |= LI_CHFLAG_MIX;
  10802. if (li_flags & LI2_FLAG_LOOP_B)
  10803. {
  10804. li_config_table[ch_b_v].flag_table[ch_b_v] |= LI_FLAG_INTERCONNECT;
  10805. li_config_table[ch_b_s].flag_table[ch_b_v] |= LI_FLAG_INTERCONNECT;
  10806. li_config_table[ch_b_v].flag_table[ch_b_s] |= LI_FLAG_INTERCONNECT;
  10807. li_config_table[ch_b_s].flag_table[ch_b_s] |= LI_FLAG_INTERCONNECT;
  10808. }
  10809. if (li_flags & LI2_FLAG_LOOP_PC)
  10810. li_config_table[ch_b].flag_table[ch_b] |= LI_FLAG_PCCONNECT;
  10811. if (li_flags & LI2_FLAG_LOOP_X)
  10812. li_config_table[ch_b].chflags |= LI_CHFLAG_LOOP;
  10813. if (li_flags & LI2_FLAG_PCCONNECT_A_B)
  10814. li_config_table[ch_b_s].flag_table[ch_a_s] |= LI_FLAG_PCCONNECT;
  10815. if (li_flags & LI2_FLAG_PCCONNECT_B_A)
  10816. li_config_table[ch_a_s].flag_table[ch_b_s] |= LI_FLAG_PCCONNECT;
  10817. if (ch_a_v != ch_a_s)
  10818. {
  10819. li_config_table[ch_a_v].flag_table[ch_a_s] |= LI_FLAG_CONFERENCE;
  10820. li_config_table[ch_a_s].flag_table[ch_a_v] |= LI_FLAG_CONFERENCE;
  10821. }
  10822. if (ch_b_v != ch_b_s)
  10823. {
  10824. li_config_table[ch_b_v].flag_table[ch_b_s] |= LI_FLAG_CONFERENCE;
  10825. li_config_table[ch_b_s].flag_table[ch_b_v] |= LI_FLAG_CONFERENCE;
  10826. }
  10827. }
  10828. static word li_check_main_plci(dword Id, PLCI *plci)
  10829. {
  10830. if (plci == NULL)
  10831. {
  10832. dbug(1, dprintf("[%06lx] %s,%d: Wrong PLCI",
  10833. UnMapId(Id), (char *)(FILE_), __LINE__));
  10834. return (_WRONG_IDENTIFIER);
  10835. }
  10836. if (!plci->State
  10837. || !plci->NL.Id || plci->nl_remove_id
  10838. || (plci->li_bchannel_id == 0))
  10839. {
  10840. dbug(1, dprintf("[%06lx] %s,%d: Wrong state",
  10841. UnMapId(Id), (char *)(FILE_), __LINE__));
  10842. return (_WRONG_STATE);
  10843. }
  10844. li_config_table[plci->adapter->li_base + (plci->li_bchannel_id - 1)].plci = plci;
  10845. return (GOOD);
  10846. }
  10847. static PLCI *li_check_plci_b(dword Id, PLCI *plci,
  10848. dword plci_b_id, word plci_b_write_pos, byte *p_result)
  10849. {
  10850. byte ctlr_b;
  10851. PLCI *plci_b;
  10852. if (((plci->li_plci_b_read_pos > plci_b_write_pos) ? plci->li_plci_b_read_pos :
  10853. LI_PLCI_B_QUEUE_ENTRIES + plci->li_plci_b_read_pos) - plci_b_write_pos - 1 < 2)
  10854. {
  10855. dbug(1, dprintf("[%06lx] %s,%d: LI request overrun",
  10856. UnMapId(Id), (char *)(FILE_), __LINE__));
  10857. PUT_WORD(p_result, _REQUEST_NOT_ALLOWED_IN_THIS_STATE);
  10858. return (NULL);
  10859. }
  10860. ctlr_b = 0;
  10861. if ((plci_b_id & 0x7f) != 0)
  10862. {
  10863. ctlr_b = MapController((byte)(plci_b_id & 0x7f));
  10864. if ((ctlr_b > max_adapter) || ((ctlr_b != 0) && (adapter[ctlr_b - 1].request == NULL)))
  10865. ctlr_b = 0;
  10866. }
  10867. if ((ctlr_b == 0)
  10868. || (((plci_b_id >> 8) & 0xff) == 0)
  10869. || (((plci_b_id >> 8) & 0xff) > adapter[ctlr_b - 1].max_plci))
  10870. {
  10871. dbug(1, dprintf("[%06lx] %s,%d: LI invalid second PLCI %08lx",
  10872. UnMapId(Id), (char *)(FILE_), __LINE__, plci_b_id));
  10873. PUT_WORD(p_result, _WRONG_IDENTIFIER);
  10874. return (NULL);
  10875. }
  10876. plci_b = &(adapter[ctlr_b - 1].plci[((plci_b_id >> 8) & 0xff) - 1]);
  10877. if (!plci_b->State
  10878. || !plci_b->NL.Id || plci_b->nl_remove_id
  10879. || (plci_b->li_bchannel_id == 0))
  10880. {
  10881. dbug(1, dprintf("[%06lx] %s,%d: LI peer in wrong state %08lx",
  10882. UnMapId(Id), (char *)(FILE_), __LINE__, plci_b_id));
  10883. PUT_WORD(p_result, _REQUEST_NOT_ALLOWED_IN_THIS_STATE);
  10884. return (NULL);
  10885. }
  10886. li_config_table[plci_b->adapter->li_base + (plci_b->li_bchannel_id - 1)].plci = plci_b;
  10887. if (((byte)(plci_b_id & ~EXT_CONTROLLER)) !=
  10888. ((byte)(UnMapController(plci->adapter->Id) & ~EXT_CONTROLLER))
  10889. && (!(plci->adapter->manufacturer_features & MANUFACTURER_FEATURE_XCONNECT)
  10890. || !(plci_b->adapter->manufacturer_features & MANUFACTURER_FEATURE_XCONNECT)))
  10891. {
  10892. dbug(1, dprintf("[%06lx] %s,%d: LI not on same ctrl %08lx",
  10893. UnMapId(Id), (char *)(FILE_), __LINE__, plci_b_id));
  10894. PUT_WORD(p_result, _WRONG_IDENTIFIER);
  10895. return (NULL);
  10896. }
  10897. if (!(get_b1_facilities(plci_b, add_b1_facilities(plci_b, plci_b->B1_resource,
  10898. (word)(plci_b->B1_facilities | B1_FACILITY_MIXER))) & B1_FACILITY_MIXER))
  10899. {
  10900. dbug(1, dprintf("[%06lx] %s,%d: Interconnect peer cannot mix %d",
  10901. UnMapId(Id), (char *)(FILE_), __LINE__, plci_b->B1_resource));
  10902. PUT_WORD(p_result, _REQUEST_NOT_ALLOWED_IN_THIS_STATE);
  10903. return (NULL);
  10904. }
  10905. return (plci_b);
  10906. }
  10907. static PLCI *li2_check_plci_b(dword Id, PLCI *plci,
  10908. dword plci_b_id, word plci_b_write_pos, byte *p_result)
  10909. {
  10910. byte ctlr_b;
  10911. PLCI *plci_b;
  10912. if (((plci->li_plci_b_read_pos > plci_b_write_pos) ? plci->li_plci_b_read_pos :
  10913. LI_PLCI_B_QUEUE_ENTRIES + plci->li_plci_b_read_pos) - plci_b_write_pos - 1 < 2)
  10914. {
  10915. dbug(1, dprintf("[%06lx] %s,%d: LI request overrun",
  10916. UnMapId(Id), (char *)(FILE_), __LINE__));
  10917. PUT_WORD(p_result, _WRONG_STATE);
  10918. return (NULL);
  10919. }
  10920. ctlr_b = 0;
  10921. if ((plci_b_id & 0x7f) != 0)
  10922. {
  10923. ctlr_b = MapController((byte)(plci_b_id & 0x7f));
  10924. if ((ctlr_b > max_adapter) || ((ctlr_b != 0) && (adapter[ctlr_b - 1].request == NULL)))
  10925. ctlr_b = 0;
  10926. }
  10927. if ((ctlr_b == 0)
  10928. || (((plci_b_id >> 8) & 0xff) == 0)
  10929. || (((plci_b_id >> 8) & 0xff) > adapter[ctlr_b - 1].max_plci))
  10930. {
  10931. dbug(1, dprintf("[%06lx] %s,%d: LI invalid second PLCI %08lx",
  10932. UnMapId(Id), (char *)(FILE_), __LINE__, plci_b_id));
  10933. PUT_WORD(p_result, _WRONG_IDENTIFIER);
  10934. return (NULL);
  10935. }
  10936. plci_b = &(adapter[ctlr_b - 1].plci[((plci_b_id >> 8) & 0xff) - 1]);
  10937. if (!plci_b->State
  10938. || !plci_b->NL.Id || plci_b->nl_remove_id
  10939. || (plci_b->li_bchannel_id == 0)
  10940. || (li_config_table[plci_b->adapter->li_base + (plci_b->li_bchannel_id - 1)].plci != plci_b))
  10941. {
  10942. dbug(1, dprintf("[%06lx] %s,%d: LI peer in wrong state %08lx",
  10943. UnMapId(Id), (char *)(FILE_), __LINE__, plci_b_id));
  10944. PUT_WORD(p_result, _WRONG_STATE);
  10945. return (NULL);
  10946. }
  10947. if (((byte)(plci_b_id & ~EXT_CONTROLLER)) !=
  10948. ((byte)(UnMapController(plci->adapter->Id) & ~EXT_CONTROLLER))
  10949. && (!(plci->adapter->manufacturer_features & MANUFACTURER_FEATURE_XCONNECT)
  10950. || !(plci_b->adapter->manufacturer_features & MANUFACTURER_FEATURE_XCONNECT)))
  10951. {
  10952. dbug(1, dprintf("[%06lx] %s,%d: LI not on same ctrl %08lx",
  10953. UnMapId(Id), (char *)(FILE_), __LINE__, plci_b_id));
  10954. PUT_WORD(p_result, _WRONG_IDENTIFIER);
  10955. return (NULL);
  10956. }
  10957. if (!(get_b1_facilities(plci_b, add_b1_facilities(plci_b, plci_b->B1_resource,
  10958. (word)(plci_b->B1_facilities | B1_FACILITY_MIXER))) & B1_FACILITY_MIXER))
  10959. {
  10960. dbug(1, dprintf("[%06lx] %s,%d: Interconnect peer cannot mix %d",
  10961. UnMapId(Id), (char *)(FILE_), __LINE__, plci_b->B1_resource));
  10962. PUT_WORD(p_result, _WRONG_STATE);
  10963. return (NULL);
  10964. }
  10965. return (plci_b);
  10966. }
  10967. static byte mixer_request(dword Id, word Number, DIVA_CAPI_ADAPTER *a, PLCI *plci, APPL *appl, API_PARSE *msg)
  10968. {
  10969. word Info;
  10970. word i;
  10971. dword d, li_flags, plci_b_id;
  10972. PLCI *plci_b;
  10973. API_PARSE li_parms[3];
  10974. API_PARSE li_req_parms[3];
  10975. API_PARSE li_participant_struct[2];
  10976. API_PARSE li_participant_parms[3];
  10977. word participant_parms_pos;
  10978. byte result_buffer[32];
  10979. byte *result;
  10980. word result_pos;
  10981. word plci_b_write_pos;
  10982. dbug(1, dprintf("[%06lx] %s,%d: mixer_request",
  10983. UnMapId(Id), (char *)(FILE_), __LINE__));
  10984. Info = GOOD;
  10985. result = result_buffer;
  10986. result_buffer[0] = 0;
  10987. if (!(a->profile.Global_Options & GL_LINE_INTERCONNECT_SUPPORTED))
  10988. {
  10989. dbug(1, dprintf("[%06lx] %s,%d: Facility not supported",
  10990. UnMapId(Id), (char *)(FILE_), __LINE__));
  10991. Info = _FACILITY_NOT_SUPPORTED;
  10992. }
  10993. else if (api_parse(&msg[1].info[1], msg[1].length, "ws", li_parms))
  10994. {
  10995. dbug(1, dprintf("[%06lx] %s,%d: Wrong message format",
  10996. UnMapId(Id), (char *)(FILE_), __LINE__));
  10997. Info = _WRONG_MESSAGE_FORMAT;
  10998. }
  10999. else
  11000. {
  11001. result_buffer[0] = 3;
  11002. PUT_WORD(&result_buffer[1], GET_WORD(li_parms[0].info));
  11003. result_buffer[3] = 0;
  11004. switch (GET_WORD(li_parms[0].info))
  11005. {
  11006. case LI_GET_SUPPORTED_SERVICES:
  11007. if (appl->appl_flags & APPL_FLAG_OLD_LI_SPEC)
  11008. {
  11009. result_buffer[0] = 17;
  11010. result_buffer[3] = 14;
  11011. PUT_WORD(&result_buffer[4], GOOD);
  11012. d = 0;
  11013. if (a->manufacturer_features & MANUFACTURER_FEATURE_MIXER_CH_CH)
  11014. d |= LI_CONFERENCING_SUPPORTED;
  11015. if (a->manufacturer_features & MANUFACTURER_FEATURE_MIXER_CH_PC)
  11016. d |= LI_MONITORING_SUPPORTED;
  11017. if (a->manufacturer_features & MANUFACTURER_FEATURE_MIXER_PC_CH)
  11018. d |= LI_ANNOUNCEMENTS_SUPPORTED | LI_MIXING_SUPPORTED;
  11019. if (a->manufacturer_features & MANUFACTURER_FEATURE_XCONNECT)
  11020. d |= LI_CROSS_CONTROLLER_SUPPORTED;
  11021. PUT_DWORD(&result_buffer[6], d);
  11022. if (a->manufacturer_features & MANUFACTURER_FEATURE_XCONNECT)
  11023. {
  11024. d = 0;
  11025. for (i = 0; i < li_total_channels; i++)
  11026. {
  11027. if ((li_config_table[i].adapter->manufacturer_features & MANUFACTURER_FEATURE_XCONNECT)
  11028. && (li_config_table[i].adapter->li_pri
  11029. || (i < li_config_table[i].adapter->li_base + MIXER_BCHANNELS_BRI)))
  11030. {
  11031. d++;
  11032. }
  11033. }
  11034. }
  11035. else
  11036. {
  11037. d = a->li_pri ? a->li_channels : MIXER_BCHANNELS_BRI;
  11038. }
  11039. PUT_DWORD(&result_buffer[10], d / 2);
  11040. PUT_DWORD(&result_buffer[14], d);
  11041. }
  11042. else
  11043. {
  11044. result_buffer[0] = 25;
  11045. result_buffer[3] = 22;
  11046. PUT_WORD(&result_buffer[4], GOOD);
  11047. d = LI2_ASYMMETRIC_SUPPORTED | LI2_B_LOOPING_SUPPORTED | LI2_X_LOOPING_SUPPORTED;
  11048. if (a->manufacturer_features & MANUFACTURER_FEATURE_MIXER_CH_PC)
  11049. d |= LI2_MONITORING_SUPPORTED | LI2_REMOTE_MONITORING_SUPPORTED;
  11050. if (a->manufacturer_features & MANUFACTURER_FEATURE_MIXER_PC_CH)
  11051. d |= LI2_MIXING_SUPPORTED | LI2_REMOTE_MIXING_SUPPORTED;
  11052. if (a->manufacturer_features & MANUFACTURER_FEATURE_MIXER_PC_PC)
  11053. d |= LI2_PC_LOOPING_SUPPORTED;
  11054. if (a->manufacturer_features & MANUFACTURER_FEATURE_XCONNECT)
  11055. d |= LI2_CROSS_CONTROLLER_SUPPORTED;
  11056. PUT_DWORD(&result_buffer[6], d);
  11057. d = a->li_pri ? a->li_channels : MIXER_BCHANNELS_BRI;
  11058. PUT_DWORD(&result_buffer[10], d / 2);
  11059. PUT_DWORD(&result_buffer[14], d - 1);
  11060. if (a->manufacturer_features & MANUFACTURER_FEATURE_XCONNECT)
  11061. {
  11062. d = 0;
  11063. for (i = 0; i < li_total_channels; i++)
  11064. {
  11065. if ((li_config_table[i].adapter->manufacturer_features & MANUFACTURER_FEATURE_XCONNECT)
  11066. && (li_config_table[i].adapter->li_pri
  11067. || (i < li_config_table[i].adapter->li_base + MIXER_BCHANNELS_BRI)))
  11068. {
  11069. d++;
  11070. }
  11071. }
  11072. }
  11073. PUT_DWORD(&result_buffer[18], d / 2);
  11074. PUT_DWORD(&result_buffer[22], d - 1);
  11075. }
  11076. break;
  11077. case LI_REQ_CONNECT:
  11078. if (li_parms[1].length == 8)
  11079. {
  11080. appl->appl_flags |= APPL_FLAG_OLD_LI_SPEC;
  11081. if (api_parse(&li_parms[1].info[1], li_parms[1].length, "dd", li_req_parms))
  11082. {
  11083. dbug(1, dprintf("[%06lx] %s,%d: Wrong message format",
  11084. UnMapId(Id), (char *)(FILE_), __LINE__));
  11085. Info = _WRONG_MESSAGE_FORMAT;
  11086. break;
  11087. }
  11088. plci_b_id = GET_DWORD(li_req_parms[0].info) & 0xffff;
  11089. li_flags = GET_DWORD(li_req_parms[1].info);
  11090. Info = li_check_main_plci(Id, plci);
  11091. result_buffer[0] = 9;
  11092. result_buffer[3] = 6;
  11093. PUT_DWORD(&result_buffer[4], plci_b_id);
  11094. PUT_WORD(&result_buffer[8], GOOD);
  11095. if (Info != GOOD)
  11096. break;
  11097. result = plci->saved_msg.info;
  11098. for (i = 0; i <= result_buffer[0]; i++)
  11099. result[i] = result_buffer[i];
  11100. plci_b_write_pos = plci->li_plci_b_write_pos;
  11101. plci_b = li_check_plci_b(Id, plci, plci_b_id, plci_b_write_pos, &result[8]);
  11102. if (plci_b == NULL)
  11103. break;
  11104. li_update_connect(Id, a, plci, plci_b_id, true, li_flags);
  11105. plci->li_plci_b_queue[plci_b_write_pos] = plci_b_id | LI_PLCI_B_LAST_FLAG;
  11106. plci_b_write_pos = (plci_b_write_pos == LI_PLCI_B_QUEUE_ENTRIES - 1) ? 0 : plci_b_write_pos + 1;
  11107. plci->li_plci_b_write_pos = plci_b_write_pos;
  11108. }
  11109. else
  11110. {
  11111. appl->appl_flags &= ~APPL_FLAG_OLD_LI_SPEC;
  11112. if (api_parse(&li_parms[1].info[1], li_parms[1].length, "ds", li_req_parms))
  11113. {
  11114. dbug(1, dprintf("[%06lx] %s,%d: Wrong message format",
  11115. UnMapId(Id), (char *)(FILE_), __LINE__));
  11116. Info = _WRONG_MESSAGE_FORMAT;
  11117. break;
  11118. }
  11119. li_flags = GET_DWORD(li_req_parms[0].info) & ~(LI2_FLAG_INTERCONNECT_A_B | LI2_FLAG_INTERCONNECT_B_A);
  11120. Info = li_check_main_plci(Id, plci);
  11121. result_buffer[0] = 7;
  11122. result_buffer[3] = 4;
  11123. PUT_WORD(&result_buffer[4], Info);
  11124. result_buffer[6] = 0;
  11125. if (Info != GOOD)
  11126. break;
  11127. result = plci->saved_msg.info;
  11128. for (i = 0; i <= result_buffer[0]; i++)
  11129. result[i] = result_buffer[i];
  11130. plci_b_write_pos = plci->li_plci_b_write_pos;
  11131. participant_parms_pos = 0;
  11132. result_pos = 7;
  11133. li2_update_connect(Id, a, plci, UnMapId(Id), true, li_flags);
  11134. while (participant_parms_pos < li_req_parms[1].length)
  11135. {
  11136. result[result_pos] = 6;
  11137. result_pos += 7;
  11138. PUT_DWORD(&result[result_pos - 6], 0);
  11139. PUT_WORD(&result[result_pos - 2], GOOD);
  11140. if (api_parse(&li_req_parms[1].info[1 + participant_parms_pos],
  11141. (word)(li_parms[1].length - participant_parms_pos), "s", li_participant_struct))
  11142. {
  11143. dbug(1, dprintf("[%06lx] %s,%d: Wrong message format",
  11144. UnMapId(Id), (char *)(FILE_), __LINE__));
  11145. PUT_WORD(&result[result_pos - 2], _WRONG_MESSAGE_FORMAT);
  11146. break;
  11147. }
  11148. if (api_parse(&li_participant_struct[0].info[1],
  11149. li_participant_struct[0].length, "dd", li_participant_parms))
  11150. {
  11151. dbug(1, dprintf("[%06lx] %s,%d: Wrong message format",
  11152. UnMapId(Id), (char *)(FILE_), __LINE__));
  11153. PUT_WORD(&result[result_pos - 2], _WRONG_MESSAGE_FORMAT);
  11154. break;
  11155. }
  11156. plci_b_id = GET_DWORD(li_participant_parms[0].info) & 0xffff;
  11157. li_flags = GET_DWORD(li_participant_parms[1].info);
  11158. PUT_DWORD(&result[result_pos - 6], plci_b_id);
  11159. if (sizeof(result) - result_pos < 7)
  11160. {
  11161. dbug(1, dprintf("[%06lx] %s,%d: LI result overrun",
  11162. UnMapId(Id), (char *)(FILE_), __LINE__));
  11163. PUT_WORD(&result[result_pos - 2], _WRONG_STATE);
  11164. break;
  11165. }
  11166. plci_b = li2_check_plci_b(Id, plci, plci_b_id, plci_b_write_pos, &result[result_pos - 2]);
  11167. if (plci_b != NULL)
  11168. {
  11169. li2_update_connect(Id, a, plci, plci_b_id, true, li_flags);
  11170. plci->li_plci_b_queue[plci_b_write_pos] = plci_b_id |
  11171. ((li_flags & (LI2_FLAG_INTERCONNECT_A_B | LI2_FLAG_INTERCONNECT_B_A |
  11172. LI2_FLAG_PCCONNECT_A_B | LI2_FLAG_PCCONNECT_B_A)) ? 0 : LI_PLCI_B_DISC_FLAG);
  11173. plci_b_write_pos = (plci_b_write_pos == LI_PLCI_B_QUEUE_ENTRIES - 1) ? 0 : plci_b_write_pos + 1;
  11174. }
  11175. participant_parms_pos = (word)((&li_participant_struct[0].info[1 + li_participant_struct[0].length]) -
  11176. (&li_req_parms[1].info[1]));
  11177. }
  11178. result[0] = (byte)(result_pos - 1);
  11179. result[3] = (byte)(result_pos - 4);
  11180. result[6] = (byte)(result_pos - 7);
  11181. i = (plci_b_write_pos == 0) ? LI_PLCI_B_QUEUE_ENTRIES - 1 : plci_b_write_pos - 1;
  11182. if ((plci_b_write_pos == plci->li_plci_b_read_pos)
  11183. || (plci->li_plci_b_queue[i] & LI_PLCI_B_LAST_FLAG))
  11184. {
  11185. plci->li_plci_b_queue[plci_b_write_pos] = LI_PLCI_B_SKIP_FLAG | LI_PLCI_B_LAST_FLAG;
  11186. plci_b_write_pos = (plci_b_write_pos == LI_PLCI_B_QUEUE_ENTRIES - 1) ? 0 : plci_b_write_pos + 1;
  11187. }
  11188. else
  11189. plci->li_plci_b_queue[i] |= LI_PLCI_B_LAST_FLAG;
  11190. plci->li_plci_b_write_pos = plci_b_write_pos;
  11191. }
  11192. mixer_calculate_coefs(a);
  11193. plci->li_channel_bits = li_config_table[a->li_base + (plci->li_bchannel_id - 1)].channel;
  11194. mixer_notify_update(plci, true);
  11195. sendf(appl, _FACILITY_R | CONFIRM, Id & 0xffffL, Number,
  11196. "wwS", Info, SELECTOR_LINE_INTERCONNECT, result);
  11197. plci->command = 0;
  11198. plci->li_cmd = GET_WORD(li_parms[0].info);
  11199. start_internal_command(Id, plci, mixer_command);
  11200. return (false);
  11201. case LI_REQ_DISCONNECT:
  11202. if (li_parms[1].length == 4)
  11203. {
  11204. appl->appl_flags |= APPL_FLAG_OLD_LI_SPEC;
  11205. if (api_parse(&li_parms[1].info[1], li_parms[1].length, "d", li_req_parms))
  11206. {
  11207. dbug(1, dprintf("[%06lx] %s,%d: Wrong message format",
  11208. UnMapId(Id), (char *)(FILE_), __LINE__));
  11209. Info = _WRONG_MESSAGE_FORMAT;
  11210. break;
  11211. }
  11212. plci_b_id = GET_DWORD(li_req_parms[0].info) & 0xffff;
  11213. Info = li_check_main_plci(Id, plci);
  11214. result_buffer[0] = 9;
  11215. result_buffer[3] = 6;
  11216. PUT_DWORD(&result_buffer[4], GET_DWORD(li_req_parms[0].info));
  11217. PUT_WORD(&result_buffer[8], GOOD);
  11218. if (Info != GOOD)
  11219. break;
  11220. result = plci->saved_msg.info;
  11221. for (i = 0; i <= result_buffer[0]; i++)
  11222. result[i] = result_buffer[i];
  11223. plci_b_write_pos = plci->li_plci_b_write_pos;
  11224. plci_b = li_check_plci_b(Id, plci, plci_b_id, plci_b_write_pos, &result[8]);
  11225. if (plci_b == NULL)
  11226. break;
  11227. li_update_connect(Id, a, plci, plci_b_id, false, 0);
  11228. plci->li_plci_b_queue[plci_b_write_pos] = plci_b_id | LI_PLCI_B_DISC_FLAG | LI_PLCI_B_LAST_FLAG;
  11229. plci_b_write_pos = (plci_b_write_pos == LI_PLCI_B_QUEUE_ENTRIES - 1) ? 0 : plci_b_write_pos + 1;
  11230. plci->li_plci_b_write_pos = plci_b_write_pos;
  11231. }
  11232. else
  11233. {
  11234. appl->appl_flags &= ~APPL_FLAG_OLD_LI_SPEC;
  11235. if (api_parse(&li_parms[1].info[1], li_parms[1].length, "s", li_req_parms))
  11236. {
  11237. dbug(1, dprintf("[%06lx] %s,%d: Wrong message format",
  11238. UnMapId(Id), (char *)(FILE_), __LINE__));
  11239. Info = _WRONG_MESSAGE_FORMAT;
  11240. break;
  11241. }
  11242. Info = li_check_main_plci(Id, plci);
  11243. result_buffer[0] = 7;
  11244. result_buffer[3] = 4;
  11245. PUT_WORD(&result_buffer[4], Info);
  11246. result_buffer[6] = 0;
  11247. if (Info != GOOD)
  11248. break;
  11249. result = plci->saved_msg.info;
  11250. for (i = 0; i <= result_buffer[0]; i++)
  11251. result[i] = result_buffer[i];
  11252. plci_b_write_pos = plci->li_plci_b_write_pos;
  11253. participant_parms_pos = 0;
  11254. result_pos = 7;
  11255. while (participant_parms_pos < li_req_parms[0].length)
  11256. {
  11257. result[result_pos] = 6;
  11258. result_pos += 7;
  11259. PUT_DWORD(&result[result_pos - 6], 0);
  11260. PUT_WORD(&result[result_pos - 2], GOOD);
  11261. if (api_parse(&li_req_parms[0].info[1 + participant_parms_pos],
  11262. (word)(li_parms[1].length - participant_parms_pos), "s", li_participant_struct))
  11263. {
  11264. dbug(1, dprintf("[%06lx] %s,%d: Wrong message format",
  11265. UnMapId(Id), (char *)(FILE_), __LINE__));
  11266. PUT_WORD(&result[result_pos - 2], _WRONG_MESSAGE_FORMAT);
  11267. break;
  11268. }
  11269. if (api_parse(&li_participant_struct[0].info[1],
  11270. li_participant_struct[0].length, "d", li_participant_parms))
  11271. {
  11272. dbug(1, dprintf("[%06lx] %s,%d: Wrong message format",
  11273. UnMapId(Id), (char *)(FILE_), __LINE__));
  11274. PUT_WORD(&result[result_pos - 2], _WRONG_MESSAGE_FORMAT);
  11275. break;
  11276. }
  11277. plci_b_id = GET_DWORD(li_participant_parms[0].info) & 0xffff;
  11278. PUT_DWORD(&result[result_pos - 6], plci_b_id);
  11279. if (sizeof(result) - result_pos < 7)
  11280. {
  11281. dbug(1, dprintf("[%06lx] %s,%d: LI result overrun",
  11282. UnMapId(Id), (char *)(FILE_), __LINE__));
  11283. PUT_WORD(&result[result_pos - 2], _WRONG_STATE);
  11284. break;
  11285. }
  11286. plci_b = li2_check_plci_b(Id, plci, plci_b_id, plci_b_write_pos, &result[result_pos - 2]);
  11287. if (plci_b != NULL)
  11288. {
  11289. li2_update_connect(Id, a, plci, plci_b_id, false, 0);
  11290. plci->li_plci_b_queue[plci_b_write_pos] = plci_b_id | LI_PLCI_B_DISC_FLAG;
  11291. plci_b_write_pos = (plci_b_write_pos == LI_PLCI_B_QUEUE_ENTRIES - 1) ? 0 : plci_b_write_pos + 1;
  11292. }
  11293. participant_parms_pos = (word)((&li_participant_struct[0].info[1 + li_participant_struct[0].length]) -
  11294. (&li_req_parms[0].info[1]));
  11295. }
  11296. result[0] = (byte)(result_pos - 1);
  11297. result[3] = (byte)(result_pos - 4);
  11298. result[6] = (byte)(result_pos - 7);
  11299. i = (plci_b_write_pos == 0) ? LI_PLCI_B_QUEUE_ENTRIES - 1 : plci_b_write_pos - 1;
  11300. if ((plci_b_write_pos == plci->li_plci_b_read_pos)
  11301. || (plci->li_plci_b_queue[i] & LI_PLCI_B_LAST_FLAG))
  11302. {
  11303. plci->li_plci_b_queue[plci_b_write_pos] = LI_PLCI_B_SKIP_FLAG | LI_PLCI_B_LAST_FLAG;
  11304. plci_b_write_pos = (plci_b_write_pos == LI_PLCI_B_QUEUE_ENTRIES - 1) ? 0 : plci_b_write_pos + 1;
  11305. }
  11306. else
  11307. plci->li_plci_b_queue[i] |= LI_PLCI_B_LAST_FLAG;
  11308. plci->li_plci_b_write_pos = plci_b_write_pos;
  11309. }
  11310. mixer_calculate_coefs(a);
  11311. plci->li_channel_bits = li_config_table[a->li_base + (plci->li_bchannel_id - 1)].channel;
  11312. mixer_notify_update(plci, true);
  11313. sendf(appl, _FACILITY_R | CONFIRM, Id & 0xffffL, Number,
  11314. "wwS", Info, SELECTOR_LINE_INTERCONNECT, result);
  11315. plci->command = 0;
  11316. plci->li_cmd = GET_WORD(li_parms[0].info);
  11317. start_internal_command(Id, plci, mixer_command);
  11318. return (false);
  11319. case LI_REQ_SILENT_UPDATE:
  11320. if (!plci || !plci->State
  11321. || !plci->NL.Id || plci->nl_remove_id
  11322. || (plci->li_bchannel_id == 0)
  11323. || (li_config_table[plci->adapter->li_base + (plci->li_bchannel_id - 1)].plci != plci))
  11324. {
  11325. dbug(1, dprintf("[%06lx] %s,%d: Wrong state",
  11326. UnMapId(Id), (char *)(FILE_), __LINE__));
  11327. return (false);
  11328. }
  11329. plci_b_write_pos = plci->li_plci_b_write_pos;
  11330. if (((plci->li_plci_b_read_pos > plci_b_write_pos) ? plci->li_plci_b_read_pos :
  11331. LI_PLCI_B_QUEUE_ENTRIES + plci->li_plci_b_read_pos) - plci_b_write_pos - 1 < 2)
  11332. {
  11333. dbug(1, dprintf("[%06lx] %s,%d: LI request overrun",
  11334. UnMapId(Id), (char *)(FILE_), __LINE__));
  11335. return (false);
  11336. }
  11337. i = (plci_b_write_pos == 0) ? LI_PLCI_B_QUEUE_ENTRIES - 1 : plci_b_write_pos - 1;
  11338. if ((plci_b_write_pos == plci->li_plci_b_read_pos)
  11339. || (plci->li_plci_b_queue[i] & LI_PLCI_B_LAST_FLAG))
  11340. {
  11341. plci->li_plci_b_queue[plci_b_write_pos] = LI_PLCI_B_SKIP_FLAG | LI_PLCI_B_LAST_FLAG;
  11342. plci_b_write_pos = (plci_b_write_pos == LI_PLCI_B_QUEUE_ENTRIES - 1) ? 0 : plci_b_write_pos + 1;
  11343. }
  11344. else
  11345. plci->li_plci_b_queue[i] |= LI_PLCI_B_LAST_FLAG;
  11346. plci->li_plci_b_write_pos = plci_b_write_pos;
  11347. plci->li_channel_bits = li_config_table[a->li_base + (plci->li_bchannel_id - 1)].channel;
  11348. plci->command = 0;
  11349. plci->li_cmd = GET_WORD(li_parms[0].info);
  11350. start_internal_command(Id, plci, mixer_command);
  11351. return (false);
  11352. default:
  11353. dbug(1, dprintf("[%06lx] %s,%d: LI unknown request %04x",
  11354. UnMapId(Id), (char *)(FILE_), __LINE__, GET_WORD(li_parms[0].info)));
  11355. Info = _FACILITY_NOT_SUPPORTED;
  11356. }
  11357. }
  11358. sendf(appl, _FACILITY_R | CONFIRM, Id & 0xffffL, Number,
  11359. "wwS", Info, SELECTOR_LINE_INTERCONNECT, result);
  11360. return (false);
  11361. }
  11362. static void mixer_indication_coefs_set(dword Id, PLCI *plci)
  11363. {
  11364. dword d;
  11365. byte result[12];
  11366. dbug(1, dprintf("[%06lx] %s,%d: mixer_indication_coefs_set",
  11367. UnMapId(Id), (char *)(FILE_), __LINE__));
  11368. if (plci->li_plci_b_read_pos != plci->li_plci_b_req_pos)
  11369. {
  11370. do
  11371. {
  11372. d = plci->li_plci_b_queue[plci->li_plci_b_read_pos];
  11373. if (!(d & LI_PLCI_B_SKIP_FLAG))
  11374. {
  11375. if (plci->appl->appl_flags & APPL_FLAG_OLD_LI_SPEC)
  11376. {
  11377. if (d & LI_PLCI_B_DISC_FLAG)
  11378. {
  11379. result[0] = 5;
  11380. PUT_WORD(&result[1], LI_IND_DISCONNECT);
  11381. result[3] = 2;
  11382. PUT_WORD(&result[4], _LI_USER_INITIATED);
  11383. }
  11384. else
  11385. {
  11386. result[0] = 7;
  11387. PUT_WORD(&result[1], LI_IND_CONNECT_ACTIVE);
  11388. result[3] = 4;
  11389. PUT_DWORD(&result[4], d & ~LI_PLCI_B_FLAG_MASK);
  11390. }
  11391. }
  11392. else
  11393. {
  11394. if (d & LI_PLCI_B_DISC_FLAG)
  11395. {
  11396. result[0] = 9;
  11397. PUT_WORD(&result[1], LI_IND_DISCONNECT);
  11398. result[3] = 6;
  11399. PUT_DWORD(&result[4], d & ~LI_PLCI_B_FLAG_MASK);
  11400. PUT_WORD(&result[8], _LI_USER_INITIATED);
  11401. }
  11402. else
  11403. {
  11404. result[0] = 7;
  11405. PUT_WORD(&result[1], LI_IND_CONNECT_ACTIVE);
  11406. result[3] = 4;
  11407. PUT_DWORD(&result[4], d & ~LI_PLCI_B_FLAG_MASK);
  11408. }
  11409. }
  11410. sendf(plci->appl, _FACILITY_I, Id & 0xffffL, 0,
  11411. "ws", SELECTOR_LINE_INTERCONNECT, result);
  11412. }
  11413. plci->li_plci_b_read_pos = (plci->li_plci_b_read_pos == LI_PLCI_B_QUEUE_ENTRIES - 1) ?
  11414. 0 : plci->li_plci_b_read_pos + 1;
  11415. } while (!(d & LI_PLCI_B_LAST_FLAG) && (plci->li_plci_b_read_pos != plci->li_plci_b_req_pos));
  11416. }
  11417. }
  11418. static void mixer_indication_xconnect_from(dword Id, PLCI *plci, byte *msg, word length)
  11419. {
  11420. word i, j, ch;
  11421. struct xconnect_transfer_address_s s, *p;
  11422. DIVA_CAPI_ADAPTER *a;
  11423. dbug(1, dprintf("[%06lx] %s,%d: mixer_indication_xconnect_from %d",
  11424. UnMapId(Id), (char *)(FILE_), __LINE__, (int)length));
  11425. a = plci->adapter;
  11426. i = 1;
  11427. for (i = 1; i < length; i += 16)
  11428. {
  11429. s.card_address.low = msg[i] | (msg[i + 1] << 8) | (((dword)(msg[i + 2])) << 16) | (((dword)(msg[i + 3])) << 24);
  11430. s.card_address.high = msg[i + 4] | (msg[i + 5] << 8) | (((dword)(msg[i + 6])) << 16) | (((dword)(msg[i + 7])) << 24);
  11431. s.offset = msg[i + 8] | (msg[i + 9] << 8) | (((dword)(msg[i + 10])) << 16) | (((dword)(msg[i + 11])) << 24);
  11432. ch = msg[i + 12] | (msg[i + 13] << 8);
  11433. j = ch & XCONNECT_CHANNEL_NUMBER_MASK;
  11434. if (!a->li_pri && (plci->li_bchannel_id == 2))
  11435. j = 1 - j;
  11436. j += a->li_base;
  11437. if (ch & XCONNECT_CHANNEL_PORT_PC)
  11438. p = &(li_config_table[j].send_pc);
  11439. else
  11440. p = &(li_config_table[j].send_b);
  11441. p->card_address.low = s.card_address.low;
  11442. p->card_address.high = s.card_address.high;
  11443. p->offset = s.offset;
  11444. li_config_table[j].channel |= LI_CHANNEL_ADDRESSES_SET;
  11445. }
  11446. if (plci->internal_command_queue[0]
  11447. && ((plci->adjust_b_state == ADJUST_B_RESTORE_MIXER_2)
  11448. || (plci->adjust_b_state == ADJUST_B_RESTORE_MIXER_3)
  11449. || (plci->adjust_b_state == ADJUST_B_RESTORE_MIXER_4)))
  11450. {
  11451. (*(plci->internal_command_queue[0]))(Id, plci, 0);
  11452. if (!plci->internal_command)
  11453. next_internal_command(Id, plci);
  11454. }
  11455. mixer_notify_update(plci, true);
  11456. }
  11457. static void mixer_indication_xconnect_to(dword Id, PLCI *plci, byte *msg, word length)
  11458. {
  11459. dbug(1, dprintf("[%06lx] %s,%d: mixer_indication_xconnect_to %d",
  11460. UnMapId(Id), (char *)(FILE_), __LINE__, (int) length));
  11461. }
  11462. static byte mixer_notify_source_removed(PLCI *plci, dword plci_b_id)
  11463. {
  11464. word plci_b_write_pos;
  11465. plci_b_write_pos = plci->li_plci_b_write_pos;
  11466. if (((plci->li_plci_b_read_pos > plci_b_write_pos) ? plci->li_plci_b_read_pos :
  11467. LI_PLCI_B_QUEUE_ENTRIES + plci->li_plci_b_read_pos) - plci_b_write_pos - 1 < 1)
  11468. {
  11469. dbug(1, dprintf("[%06lx] %s,%d: LI request overrun",
  11470. (dword)((plci->Id << 8) | UnMapController(plci->adapter->Id)),
  11471. (char *)(FILE_), __LINE__));
  11472. return (false);
  11473. }
  11474. plci->li_plci_b_queue[plci_b_write_pos] = plci_b_id | LI_PLCI_B_DISC_FLAG;
  11475. plci_b_write_pos = (plci_b_write_pos == LI_PLCI_B_QUEUE_ENTRIES - 1) ? 0 : plci_b_write_pos + 1;
  11476. plci->li_plci_b_write_pos = plci_b_write_pos;
  11477. return (true);
  11478. }
  11479. static void mixer_remove(PLCI *plci)
  11480. {
  11481. DIVA_CAPI_ADAPTER *a;
  11482. PLCI *notify_plci;
  11483. dword plci_b_id;
  11484. word i, j;
  11485. dbug(1, dprintf("[%06lx] %s,%d: mixer_remove",
  11486. (dword)((plci->Id << 8) | UnMapController(plci->adapter->Id)),
  11487. (char *)(FILE_), __LINE__));
  11488. a = plci->adapter;
  11489. plci_b_id = (plci->Id << 8) | UnMapController(plci->adapter->Id);
  11490. if (a->profile.Global_Options & GL_LINE_INTERCONNECT_SUPPORTED)
  11491. {
  11492. if ((plci->li_bchannel_id != 0)
  11493. && (li_config_table[a->li_base + (plci->li_bchannel_id - 1)].plci == plci))
  11494. {
  11495. i = a->li_base + (plci->li_bchannel_id - 1);
  11496. if ((li_config_table[i].curchnl | li_config_table[i].channel) & LI_CHANNEL_INVOLVED)
  11497. {
  11498. for (j = 0; j < li_total_channels; j++)
  11499. {
  11500. if ((li_config_table[i].flag_table[j] & LI_FLAG_INTERCONNECT)
  11501. || (li_config_table[j].flag_table[i] & LI_FLAG_INTERCONNECT))
  11502. {
  11503. notify_plci = li_config_table[j].plci;
  11504. if ((notify_plci != NULL)
  11505. && (notify_plci != plci)
  11506. && (notify_plci->appl != NULL)
  11507. && !(notify_plci->appl->appl_flags & APPL_FLAG_OLD_LI_SPEC)
  11508. && (notify_plci->State)
  11509. && notify_plci->NL.Id && !notify_plci->nl_remove_id)
  11510. {
  11511. mixer_notify_source_removed(notify_plci, plci_b_id);
  11512. }
  11513. }
  11514. }
  11515. mixer_clear_config(plci);
  11516. mixer_calculate_coefs(a);
  11517. mixer_notify_update(plci, true);
  11518. }
  11519. li_config_table[i].plci = NULL;
  11520. plci->li_bchannel_id = 0;
  11521. }
  11522. }
  11523. }
  11524. /*------------------------------------------------------------------*/
  11525. /* Echo canceller facilities */
  11526. /*------------------------------------------------------------------*/
  11527. static void ec_write_parameters(PLCI *plci)
  11528. {
  11529. word w;
  11530. byte parameter_buffer[6];
  11531. dbug(1, dprintf("[%06lx] %s,%d: ec_write_parameters",
  11532. (dword)((plci->Id << 8) | UnMapController(plci->adapter->Id)),
  11533. (char *)(FILE_), __LINE__));
  11534. parameter_buffer[0] = 5;
  11535. parameter_buffer[1] = DSP_CTRL_SET_LEC_PARAMETERS;
  11536. PUT_WORD(&parameter_buffer[2], plci->ec_idi_options);
  11537. plci->ec_idi_options &= ~LEC_RESET_COEFFICIENTS;
  11538. w = (plci->ec_tail_length == 0) ? 128 : plci->ec_tail_length;
  11539. PUT_WORD(&parameter_buffer[4], w);
  11540. add_p(plci, FTY, parameter_buffer);
  11541. sig_req(plci, TEL_CTRL, 0);
  11542. send_req(plci);
  11543. }
  11544. static void ec_clear_config(PLCI *plci)
  11545. {
  11546. dbug(1, dprintf("[%06lx] %s,%d: ec_clear_config",
  11547. (dword)((plci->Id << 8) | UnMapController(plci->adapter->Id)),
  11548. (char *)(FILE_), __LINE__));
  11549. plci->ec_idi_options = LEC_ENABLE_ECHO_CANCELLER |
  11550. LEC_MANUAL_DISABLE | LEC_ENABLE_NONLINEAR_PROCESSING;
  11551. plci->ec_tail_length = 0;
  11552. }
  11553. static void ec_prepare_switch(dword Id, PLCI *plci)
  11554. {
  11555. dbug(1, dprintf("[%06lx] %s,%d: ec_prepare_switch",
  11556. UnMapId(Id), (char *)(FILE_), __LINE__));
  11557. }
  11558. static word ec_save_config(dword Id, PLCI *plci, byte Rc)
  11559. {
  11560. dbug(1, dprintf("[%06lx] %s,%d: ec_save_config %02x %d",
  11561. UnMapId(Id), (char *)(FILE_), __LINE__, Rc, plci->adjust_b_state));
  11562. return (GOOD);
  11563. }
  11564. static word ec_restore_config(dword Id, PLCI *plci, byte Rc)
  11565. {
  11566. word Info;
  11567. dbug(1, dprintf("[%06lx] %s,%d: ec_restore_config %02x %d",
  11568. UnMapId(Id), (char *)(FILE_), __LINE__, Rc, plci->adjust_b_state));
  11569. Info = GOOD;
  11570. if (plci->B1_facilities & B1_FACILITY_EC)
  11571. {
  11572. switch (plci->adjust_b_state)
  11573. {
  11574. case ADJUST_B_RESTORE_EC_1:
  11575. plci->internal_command = plci->adjust_b_command;
  11576. if (plci->sig_req)
  11577. {
  11578. plci->adjust_b_state = ADJUST_B_RESTORE_EC_1;
  11579. break;
  11580. }
  11581. ec_write_parameters(plci);
  11582. plci->adjust_b_state = ADJUST_B_RESTORE_EC_2;
  11583. break;
  11584. case ADJUST_B_RESTORE_EC_2:
  11585. if ((Rc != OK) && (Rc != OK_FC))
  11586. {
  11587. dbug(1, dprintf("[%06lx] %s,%d: Restore EC failed %02x",
  11588. UnMapId(Id), (char *)(FILE_), __LINE__, Rc));
  11589. Info = _WRONG_STATE;
  11590. break;
  11591. }
  11592. break;
  11593. }
  11594. }
  11595. return (Info);
  11596. }
  11597. static void ec_command(dword Id, PLCI *plci, byte Rc)
  11598. {
  11599. word internal_command, Info;
  11600. byte result[8];
  11601. dbug(1, dprintf("[%06lx] %s,%d: ec_command %02x %04x %04x %04x %d",
  11602. UnMapId(Id), (char *)(FILE_), __LINE__, Rc, plci->internal_command,
  11603. plci->ec_cmd, plci->ec_idi_options, plci->ec_tail_length));
  11604. Info = GOOD;
  11605. if (plci->appl->appl_flags & APPL_FLAG_PRIV_EC_SPEC)
  11606. {
  11607. result[0] = 2;
  11608. PUT_WORD(&result[1], EC_SUCCESS);
  11609. }
  11610. else
  11611. {
  11612. result[0] = 5;
  11613. PUT_WORD(&result[1], plci->ec_cmd);
  11614. result[3] = 2;
  11615. PUT_WORD(&result[4], GOOD);
  11616. }
  11617. internal_command = plci->internal_command;
  11618. plci->internal_command = 0;
  11619. switch (plci->ec_cmd)
  11620. {
  11621. case EC_ENABLE_OPERATION:
  11622. case EC_FREEZE_COEFFICIENTS:
  11623. case EC_RESUME_COEFFICIENT_UPDATE:
  11624. case EC_RESET_COEFFICIENTS:
  11625. switch (internal_command)
  11626. {
  11627. default:
  11628. adjust_b1_resource(Id, plci, NULL, (word)(plci->B1_facilities |
  11629. B1_FACILITY_EC), EC_COMMAND_1);
  11630. /* fall through */
  11631. case EC_COMMAND_1:
  11632. if (adjust_b_process(Id, plci, Rc) != GOOD)
  11633. {
  11634. dbug(1, dprintf("[%06lx] %s,%d: Load EC failed",
  11635. UnMapId(Id), (char *)(FILE_), __LINE__));
  11636. Info = _FACILITY_NOT_SUPPORTED;
  11637. break;
  11638. }
  11639. if (plci->internal_command)
  11640. return;
  11641. /* fall through */
  11642. case EC_COMMAND_2:
  11643. if (plci->sig_req)
  11644. {
  11645. plci->internal_command = EC_COMMAND_2;
  11646. return;
  11647. }
  11648. plci->internal_command = EC_COMMAND_3;
  11649. ec_write_parameters(plci);
  11650. return;
  11651. case EC_COMMAND_3:
  11652. if ((Rc != OK) && (Rc != OK_FC))
  11653. {
  11654. dbug(1, dprintf("[%06lx] %s,%d: Enable EC failed %02x",
  11655. UnMapId(Id), (char *)(FILE_), __LINE__, Rc));
  11656. Info = _FACILITY_NOT_SUPPORTED;
  11657. break;
  11658. }
  11659. break;
  11660. }
  11661. break;
  11662. case EC_DISABLE_OPERATION:
  11663. switch (internal_command)
  11664. {
  11665. default:
  11666. case EC_COMMAND_1:
  11667. if (plci->B1_facilities & B1_FACILITY_EC)
  11668. {
  11669. if (plci->sig_req)
  11670. {
  11671. plci->internal_command = EC_COMMAND_1;
  11672. return;
  11673. }
  11674. plci->internal_command = EC_COMMAND_2;
  11675. ec_write_parameters(plci);
  11676. return;
  11677. }
  11678. Rc = OK;
  11679. /* fall through */
  11680. case EC_COMMAND_2:
  11681. if ((Rc != OK) && (Rc != OK_FC))
  11682. {
  11683. dbug(1, dprintf("[%06lx] %s,%d: Disable EC failed %02x",
  11684. UnMapId(Id), (char *)(FILE_), __LINE__, Rc));
  11685. Info = _FACILITY_NOT_SUPPORTED;
  11686. break;
  11687. }
  11688. adjust_b1_resource(Id, plci, NULL, (word)(plci->B1_facilities &
  11689. ~B1_FACILITY_EC), EC_COMMAND_3);
  11690. /* fall through */
  11691. case EC_COMMAND_3:
  11692. if (adjust_b_process(Id, plci, Rc) != GOOD)
  11693. {
  11694. dbug(1, dprintf("[%06lx] %s,%d: Unload EC failed",
  11695. UnMapId(Id), (char *)(FILE_), __LINE__));
  11696. Info = _FACILITY_NOT_SUPPORTED;
  11697. break;
  11698. }
  11699. if (plci->internal_command)
  11700. return;
  11701. break;
  11702. }
  11703. break;
  11704. }
  11705. sendf(plci->appl, _FACILITY_R | CONFIRM, Id & 0xffffL, plci->number,
  11706. "wws", Info, (plci->appl->appl_flags & APPL_FLAG_PRIV_EC_SPEC) ?
  11707. PRIV_SELECTOR_ECHO_CANCELLER : SELECTOR_ECHO_CANCELLER, result);
  11708. }
  11709. static byte ec_request(dword Id, word Number, DIVA_CAPI_ADAPTER *a, PLCI *plci, APPL *appl, API_PARSE *msg)
  11710. {
  11711. word Info;
  11712. word opt;
  11713. API_PARSE ec_parms[3];
  11714. byte result[16];
  11715. dbug(1, dprintf("[%06lx] %s,%d: ec_request",
  11716. UnMapId(Id), (char *)(FILE_), __LINE__));
  11717. Info = GOOD;
  11718. result[0] = 0;
  11719. if (!(a->man_profile.private_options & (1L << PRIVATE_ECHO_CANCELLER)))
  11720. {
  11721. dbug(1, dprintf("[%06lx] %s,%d: Facility not supported",
  11722. UnMapId(Id), (char *)(FILE_), __LINE__));
  11723. Info = _FACILITY_NOT_SUPPORTED;
  11724. }
  11725. else
  11726. {
  11727. if (appl->appl_flags & APPL_FLAG_PRIV_EC_SPEC)
  11728. {
  11729. if (api_parse(&msg[1].info[1], msg[1].length, "w", ec_parms))
  11730. {
  11731. dbug(1, dprintf("[%06lx] %s,%d: Wrong message format",
  11732. UnMapId(Id), (char *)(FILE_), __LINE__));
  11733. Info = _WRONG_MESSAGE_FORMAT;
  11734. }
  11735. else
  11736. {
  11737. if (plci == NULL)
  11738. {
  11739. dbug(1, dprintf("[%06lx] %s,%d: Wrong PLCI",
  11740. UnMapId(Id), (char *)(FILE_), __LINE__));
  11741. Info = _WRONG_IDENTIFIER;
  11742. }
  11743. else if (!plci->State || !plci->NL.Id || plci->nl_remove_id)
  11744. {
  11745. dbug(1, dprintf("[%06lx] %s,%d: Wrong state",
  11746. UnMapId(Id), (char *)(FILE_), __LINE__));
  11747. Info = _WRONG_STATE;
  11748. }
  11749. else
  11750. {
  11751. plci->command = 0;
  11752. plci->ec_cmd = GET_WORD(ec_parms[0].info);
  11753. plci->ec_idi_options &= ~(LEC_MANUAL_DISABLE | LEC_RESET_COEFFICIENTS);
  11754. result[0] = 2;
  11755. PUT_WORD(&result[1], EC_SUCCESS);
  11756. if (msg[1].length >= 4)
  11757. {
  11758. opt = GET_WORD(&ec_parms[0].info[2]);
  11759. plci->ec_idi_options &= ~(LEC_ENABLE_NONLINEAR_PROCESSING |
  11760. LEC_ENABLE_2100HZ_DETECTOR | LEC_REQUIRE_2100HZ_REVERSALS);
  11761. if (!(opt & EC_DISABLE_NON_LINEAR_PROCESSING))
  11762. plci->ec_idi_options |= LEC_ENABLE_NONLINEAR_PROCESSING;
  11763. if (opt & EC_DETECT_DISABLE_TONE)
  11764. plci->ec_idi_options |= LEC_ENABLE_2100HZ_DETECTOR;
  11765. if (!(opt & EC_DO_NOT_REQUIRE_REVERSALS))
  11766. plci->ec_idi_options |= LEC_REQUIRE_2100HZ_REVERSALS;
  11767. if (msg[1].length >= 6)
  11768. {
  11769. plci->ec_tail_length = GET_WORD(&ec_parms[0].info[4]);
  11770. }
  11771. }
  11772. switch (plci->ec_cmd)
  11773. {
  11774. case EC_ENABLE_OPERATION:
  11775. plci->ec_idi_options &= ~LEC_FREEZE_COEFFICIENTS;
  11776. start_internal_command(Id, plci, ec_command);
  11777. return (false);
  11778. case EC_DISABLE_OPERATION:
  11779. plci->ec_idi_options = LEC_ENABLE_ECHO_CANCELLER |
  11780. LEC_MANUAL_DISABLE | LEC_ENABLE_NONLINEAR_PROCESSING |
  11781. LEC_RESET_COEFFICIENTS;
  11782. start_internal_command(Id, plci, ec_command);
  11783. return (false);
  11784. case EC_FREEZE_COEFFICIENTS:
  11785. plci->ec_idi_options |= LEC_FREEZE_COEFFICIENTS;
  11786. start_internal_command(Id, plci, ec_command);
  11787. return (false);
  11788. case EC_RESUME_COEFFICIENT_UPDATE:
  11789. plci->ec_idi_options &= ~LEC_FREEZE_COEFFICIENTS;
  11790. start_internal_command(Id, plci, ec_command);
  11791. return (false);
  11792. case EC_RESET_COEFFICIENTS:
  11793. plci->ec_idi_options |= LEC_RESET_COEFFICIENTS;
  11794. start_internal_command(Id, plci, ec_command);
  11795. return (false);
  11796. default:
  11797. dbug(1, dprintf("[%06lx] %s,%d: EC unknown request %04x",
  11798. UnMapId(Id), (char *)(FILE_), __LINE__, plci->ec_cmd));
  11799. PUT_WORD(&result[1], EC_UNSUPPORTED_OPERATION);
  11800. }
  11801. }
  11802. }
  11803. }
  11804. else
  11805. {
  11806. if (api_parse(&msg[1].info[1], msg[1].length, "ws", ec_parms))
  11807. {
  11808. dbug(1, dprintf("[%06lx] %s,%d: Wrong message format",
  11809. UnMapId(Id), (char *)(FILE_), __LINE__));
  11810. Info = _WRONG_MESSAGE_FORMAT;
  11811. }
  11812. else
  11813. {
  11814. if (GET_WORD(ec_parms[0].info) == EC_GET_SUPPORTED_SERVICES)
  11815. {
  11816. result[0] = 11;
  11817. PUT_WORD(&result[1], EC_GET_SUPPORTED_SERVICES);
  11818. result[3] = 8;
  11819. PUT_WORD(&result[4], GOOD);
  11820. PUT_WORD(&result[6], 0x0007);
  11821. PUT_WORD(&result[8], LEC_MAX_SUPPORTED_TAIL_LENGTH);
  11822. PUT_WORD(&result[10], 0);
  11823. }
  11824. else if (plci == NULL)
  11825. {
  11826. dbug(1, dprintf("[%06lx] %s,%d: Wrong PLCI",
  11827. UnMapId(Id), (char *)(FILE_), __LINE__));
  11828. Info = _WRONG_IDENTIFIER;
  11829. }
  11830. else if (!plci->State || !plci->NL.Id || plci->nl_remove_id)
  11831. {
  11832. dbug(1, dprintf("[%06lx] %s,%d: Wrong state",
  11833. UnMapId(Id), (char *)(FILE_), __LINE__));
  11834. Info = _WRONG_STATE;
  11835. }
  11836. else
  11837. {
  11838. plci->command = 0;
  11839. plci->ec_cmd = GET_WORD(ec_parms[0].info);
  11840. plci->ec_idi_options &= ~(LEC_MANUAL_DISABLE | LEC_RESET_COEFFICIENTS);
  11841. result[0] = 5;
  11842. PUT_WORD(&result[1], plci->ec_cmd);
  11843. result[3] = 2;
  11844. PUT_WORD(&result[4], GOOD);
  11845. plci->ec_idi_options &= ~(LEC_ENABLE_NONLINEAR_PROCESSING |
  11846. LEC_ENABLE_2100HZ_DETECTOR | LEC_REQUIRE_2100HZ_REVERSALS);
  11847. plci->ec_tail_length = 0;
  11848. if (ec_parms[1].length >= 2)
  11849. {
  11850. opt = GET_WORD(&ec_parms[1].info[1]);
  11851. if (opt & EC_ENABLE_NON_LINEAR_PROCESSING)
  11852. plci->ec_idi_options |= LEC_ENABLE_NONLINEAR_PROCESSING;
  11853. if (opt & EC_DETECT_DISABLE_TONE)
  11854. plci->ec_idi_options |= LEC_ENABLE_2100HZ_DETECTOR;
  11855. if (!(opt & EC_DO_NOT_REQUIRE_REVERSALS))
  11856. plci->ec_idi_options |= LEC_REQUIRE_2100HZ_REVERSALS;
  11857. if (ec_parms[1].length >= 4)
  11858. {
  11859. plci->ec_tail_length = GET_WORD(&ec_parms[1].info[3]);
  11860. }
  11861. }
  11862. switch (plci->ec_cmd)
  11863. {
  11864. case EC_ENABLE_OPERATION:
  11865. plci->ec_idi_options &= ~LEC_FREEZE_COEFFICIENTS;
  11866. start_internal_command(Id, plci, ec_command);
  11867. return (false);
  11868. case EC_DISABLE_OPERATION:
  11869. plci->ec_idi_options = LEC_ENABLE_ECHO_CANCELLER |
  11870. LEC_MANUAL_DISABLE | LEC_ENABLE_NONLINEAR_PROCESSING |
  11871. LEC_RESET_COEFFICIENTS;
  11872. start_internal_command(Id, plci, ec_command);
  11873. return (false);
  11874. default:
  11875. dbug(1, dprintf("[%06lx] %s,%d: EC unknown request %04x",
  11876. UnMapId(Id), (char *)(FILE_), __LINE__, plci->ec_cmd));
  11877. PUT_WORD(&result[4], _FACILITY_SPECIFIC_FUNCTION_NOT_SUPP);
  11878. }
  11879. }
  11880. }
  11881. }
  11882. }
  11883. sendf(appl, _FACILITY_R | CONFIRM, Id & 0xffffL, Number,
  11884. "wws", Info, (appl->appl_flags & APPL_FLAG_PRIV_EC_SPEC) ?
  11885. PRIV_SELECTOR_ECHO_CANCELLER : SELECTOR_ECHO_CANCELLER, result);
  11886. return (false);
  11887. }
  11888. static void ec_indication(dword Id, PLCI *plci, byte *msg, word length)
  11889. {
  11890. byte result[8];
  11891. dbug(1, dprintf("[%06lx] %s,%d: ec_indication",
  11892. UnMapId(Id), (char *)(FILE_), __LINE__));
  11893. if (!(plci->ec_idi_options & LEC_MANUAL_DISABLE))
  11894. {
  11895. if (plci->appl->appl_flags & APPL_FLAG_PRIV_EC_SPEC)
  11896. {
  11897. result[0] = 2;
  11898. PUT_WORD(&result[1], 0);
  11899. switch (msg[1])
  11900. {
  11901. case LEC_DISABLE_TYPE_CONTIGNUOUS_2100HZ:
  11902. PUT_WORD(&result[1], EC_BYPASS_DUE_TO_CONTINUOUS_2100HZ);
  11903. break;
  11904. case LEC_DISABLE_TYPE_REVERSED_2100HZ:
  11905. PUT_WORD(&result[1], EC_BYPASS_DUE_TO_REVERSED_2100HZ);
  11906. break;
  11907. case LEC_DISABLE_RELEASED:
  11908. PUT_WORD(&result[1], EC_BYPASS_RELEASED);
  11909. break;
  11910. }
  11911. }
  11912. else
  11913. {
  11914. result[0] = 5;
  11915. PUT_WORD(&result[1], EC_BYPASS_INDICATION);
  11916. result[3] = 2;
  11917. PUT_WORD(&result[4], 0);
  11918. switch (msg[1])
  11919. {
  11920. case LEC_DISABLE_TYPE_CONTIGNUOUS_2100HZ:
  11921. PUT_WORD(&result[4], EC_BYPASS_DUE_TO_CONTINUOUS_2100HZ);
  11922. break;
  11923. case LEC_DISABLE_TYPE_REVERSED_2100HZ:
  11924. PUT_WORD(&result[4], EC_BYPASS_DUE_TO_REVERSED_2100HZ);
  11925. break;
  11926. case LEC_DISABLE_RELEASED:
  11927. PUT_WORD(&result[4], EC_BYPASS_RELEASED);
  11928. break;
  11929. }
  11930. }
  11931. sendf(plci->appl, _FACILITY_I, Id & 0xffffL, 0, "ws", (plci->appl->appl_flags & APPL_FLAG_PRIV_EC_SPEC) ?
  11932. PRIV_SELECTOR_ECHO_CANCELLER : SELECTOR_ECHO_CANCELLER, result);
  11933. }
  11934. }
  11935. /*------------------------------------------------------------------*/
  11936. /* Advanced voice */
  11937. /*------------------------------------------------------------------*/
  11938. static void adv_voice_write_coefs(PLCI *plci, word write_command)
  11939. {
  11940. DIVA_CAPI_ADAPTER *a;
  11941. word i;
  11942. byte *p;
  11943. word w, n, j, k;
  11944. byte ch_map[MIXER_CHANNELS_BRI];
  11945. byte coef_buffer[ADV_VOICE_COEF_BUFFER_SIZE + 2];
  11946. dbug(1, dprintf("[%06lx] %s,%d: adv_voice_write_coefs %d",
  11947. (dword)((plci->Id << 8) | UnMapController(plci->adapter->Id)),
  11948. (char *)(FILE_), __LINE__, write_command));
  11949. a = plci->adapter;
  11950. p = coef_buffer + 1;
  11951. *(p++) = DSP_CTRL_OLD_SET_MIXER_COEFFICIENTS;
  11952. i = 0;
  11953. while (i + sizeof(word) <= a->adv_voice_coef_length)
  11954. {
  11955. PUT_WORD(p, GET_WORD(a->adv_voice_coef_buffer + i));
  11956. p += 2;
  11957. i += 2;
  11958. }
  11959. while (i < ADV_VOICE_OLD_COEF_COUNT * sizeof(word))
  11960. {
  11961. PUT_WORD(p, 0x8000);
  11962. p += 2;
  11963. i += 2;
  11964. }
  11965. if (!a->li_pri && (plci->li_bchannel_id == 0))
  11966. {
  11967. if ((li_config_table[a->li_base].plci == NULL) && (li_config_table[a->li_base + 1].plci != NULL))
  11968. {
  11969. plci->li_bchannel_id = 1;
  11970. li_config_table[a->li_base].plci = plci;
  11971. dbug(1, dprintf("[%06lx] %s,%d: adv_voice_set_bchannel_id %d",
  11972. (dword)((plci->Id << 8) | UnMapController(plci->adapter->Id)),
  11973. (char *)(FILE_), __LINE__, plci->li_bchannel_id));
  11974. }
  11975. else if ((li_config_table[a->li_base].plci != NULL) && (li_config_table[a->li_base + 1].plci == NULL))
  11976. {
  11977. plci->li_bchannel_id = 2;
  11978. li_config_table[a->li_base + 1].plci = plci;
  11979. dbug(1, dprintf("[%06lx] %s,%d: adv_voice_set_bchannel_id %d",
  11980. (dword)((plci->Id << 8) | UnMapController(plci->adapter->Id)),
  11981. (char *)(FILE_), __LINE__, plci->li_bchannel_id));
  11982. }
  11983. }
  11984. if (!a->li_pri && (plci->li_bchannel_id != 0)
  11985. && (li_config_table[a->li_base + (plci->li_bchannel_id - 1)].plci == plci))
  11986. {
  11987. i = a->li_base + (plci->li_bchannel_id - 1);
  11988. switch (write_command)
  11989. {
  11990. case ADV_VOICE_WRITE_ACTIVATION:
  11991. j = a->li_base + MIXER_IC_CHANNEL_BASE + (plci->li_bchannel_id - 1);
  11992. k = a->li_base + MIXER_IC_CHANNEL_BASE + (2 - plci->li_bchannel_id);
  11993. if (!(plci->B1_facilities & B1_FACILITY_MIXER))
  11994. {
  11995. li_config_table[j].flag_table[i] |= LI_FLAG_CONFERENCE | LI_FLAG_MIX;
  11996. li_config_table[i].flag_table[j] |= LI_FLAG_CONFERENCE | LI_FLAG_MONITOR;
  11997. }
  11998. if (a->manufacturer_features & MANUFACTURER_FEATURE_SLAVE_CODEC)
  11999. {
  12000. li_config_table[k].flag_table[i] |= LI_FLAG_CONFERENCE | LI_FLAG_MIX;
  12001. li_config_table[i].flag_table[k] |= LI_FLAG_CONFERENCE | LI_FLAG_MONITOR;
  12002. li_config_table[k].flag_table[j] |= LI_FLAG_CONFERENCE;
  12003. li_config_table[j].flag_table[k] |= LI_FLAG_CONFERENCE;
  12004. }
  12005. mixer_calculate_coefs(a);
  12006. li_config_table[i].curchnl = li_config_table[i].channel;
  12007. li_config_table[j].curchnl = li_config_table[j].channel;
  12008. if (a->manufacturer_features & MANUFACTURER_FEATURE_SLAVE_CODEC)
  12009. li_config_table[k].curchnl = li_config_table[k].channel;
  12010. break;
  12011. case ADV_VOICE_WRITE_DEACTIVATION:
  12012. for (j = 0; j < li_total_channels; j++)
  12013. {
  12014. li_config_table[i].flag_table[j] = 0;
  12015. li_config_table[j].flag_table[i] = 0;
  12016. }
  12017. k = a->li_base + MIXER_IC_CHANNEL_BASE + (plci->li_bchannel_id - 1);
  12018. for (j = 0; j < li_total_channels; j++)
  12019. {
  12020. li_config_table[k].flag_table[j] = 0;
  12021. li_config_table[j].flag_table[k] = 0;
  12022. }
  12023. if (a->manufacturer_features & MANUFACTURER_FEATURE_SLAVE_CODEC)
  12024. {
  12025. k = a->li_base + MIXER_IC_CHANNEL_BASE + (2 - plci->li_bchannel_id);
  12026. for (j = 0; j < li_total_channels; j++)
  12027. {
  12028. li_config_table[k].flag_table[j] = 0;
  12029. li_config_table[j].flag_table[k] = 0;
  12030. }
  12031. }
  12032. mixer_calculate_coefs(a);
  12033. break;
  12034. }
  12035. if (plci->B1_facilities & B1_FACILITY_MIXER)
  12036. {
  12037. w = 0;
  12038. if (ADV_VOICE_NEW_COEF_BASE + sizeof(word) <= a->adv_voice_coef_length)
  12039. w = GET_WORD(a->adv_voice_coef_buffer + ADV_VOICE_NEW_COEF_BASE);
  12040. if (li_config_table[i].channel & LI_CHANNEL_TX_DATA)
  12041. w |= MIXER_FEATURE_ENABLE_TX_DATA;
  12042. if (li_config_table[i].channel & LI_CHANNEL_RX_DATA)
  12043. w |= MIXER_FEATURE_ENABLE_RX_DATA;
  12044. *(p++) = (byte) w;
  12045. *(p++) = (byte)(w >> 8);
  12046. for (j = 0; j < sizeof(ch_map); j += 2)
  12047. {
  12048. ch_map[j] = (byte)(j + (plci->li_bchannel_id - 1));
  12049. ch_map[j + 1] = (byte)(j + (2 - plci->li_bchannel_id));
  12050. }
  12051. for (n = 0; n < ARRAY_SIZE(mixer_write_prog_bri); n++)
  12052. {
  12053. i = a->li_base + ch_map[mixer_write_prog_bri[n].to_ch];
  12054. j = a->li_base + ch_map[mixer_write_prog_bri[n].from_ch];
  12055. if (li_config_table[i].channel & li_config_table[j].channel & LI_CHANNEL_INVOLVED)
  12056. {
  12057. *(p++) = ((li_config_table[i].coef_table[j] & mixer_write_prog_bri[n].mask) ? 0x80 : 0x01);
  12058. w = ((li_config_table[i].coef_table[j] & 0xf) ^ (li_config_table[i].coef_table[j] >> 4));
  12059. li_config_table[i].coef_table[j] ^= (w & mixer_write_prog_bri[n].mask) << 4;
  12060. }
  12061. else
  12062. {
  12063. *(p++) = (ADV_VOICE_NEW_COEF_BASE + sizeof(word) + n < a->adv_voice_coef_length) ?
  12064. a->adv_voice_coef_buffer[ADV_VOICE_NEW_COEF_BASE + sizeof(word) + n] : 0x00;
  12065. }
  12066. }
  12067. }
  12068. else
  12069. {
  12070. for (i = ADV_VOICE_NEW_COEF_BASE; i < a->adv_voice_coef_length; i++)
  12071. *(p++) = a->adv_voice_coef_buffer[i];
  12072. }
  12073. }
  12074. else
  12075. {
  12076. for (i = ADV_VOICE_NEW_COEF_BASE; i < a->adv_voice_coef_length; i++)
  12077. *(p++) = a->adv_voice_coef_buffer[i];
  12078. }
  12079. coef_buffer[0] = (p - coef_buffer) - 1;
  12080. add_p(plci, FTY, coef_buffer);
  12081. sig_req(plci, TEL_CTRL, 0);
  12082. send_req(plci);
  12083. }
  12084. static void adv_voice_clear_config(PLCI *plci)
  12085. {
  12086. DIVA_CAPI_ADAPTER *a;
  12087. word i, j;
  12088. dbug(1, dprintf("[%06lx] %s,%d: adv_voice_clear_config",
  12089. (dword)((plci->Id << 8) | UnMapController(plci->adapter->Id)),
  12090. (char *)(FILE_), __LINE__));
  12091. a = plci->adapter;
  12092. if ((plci->tel == ADV_VOICE) && (plci == a->AdvSignalPLCI))
  12093. {
  12094. a->adv_voice_coef_length = 0;
  12095. if (!a->li_pri && (plci->li_bchannel_id != 0)
  12096. && (li_config_table[a->li_base + (plci->li_bchannel_id - 1)].plci == plci))
  12097. {
  12098. i = a->li_base + (plci->li_bchannel_id - 1);
  12099. li_config_table[i].curchnl = 0;
  12100. li_config_table[i].channel = 0;
  12101. li_config_table[i].chflags = 0;
  12102. for (j = 0; j < li_total_channels; j++)
  12103. {
  12104. li_config_table[i].flag_table[j] = 0;
  12105. li_config_table[j].flag_table[i] = 0;
  12106. li_config_table[i].coef_table[j] = 0;
  12107. li_config_table[j].coef_table[i] = 0;
  12108. }
  12109. li_config_table[i].coef_table[i] |= LI_COEF_CH_PC_SET | LI_COEF_PC_CH_SET;
  12110. i = a->li_base + MIXER_IC_CHANNEL_BASE + (plci->li_bchannel_id - 1);
  12111. li_config_table[i].curchnl = 0;
  12112. li_config_table[i].channel = 0;
  12113. li_config_table[i].chflags = 0;
  12114. for (j = 0; j < li_total_channels; j++)
  12115. {
  12116. li_config_table[i].flag_table[j] = 0;
  12117. li_config_table[j].flag_table[i] = 0;
  12118. li_config_table[i].coef_table[j] = 0;
  12119. li_config_table[j].coef_table[i] = 0;
  12120. }
  12121. if (a->manufacturer_features & MANUFACTURER_FEATURE_SLAVE_CODEC)
  12122. {
  12123. i = a->li_base + MIXER_IC_CHANNEL_BASE + (2 - plci->li_bchannel_id);
  12124. li_config_table[i].curchnl = 0;
  12125. li_config_table[i].channel = 0;
  12126. li_config_table[i].chflags = 0;
  12127. for (j = 0; j < li_total_channels; j++)
  12128. {
  12129. li_config_table[i].flag_table[j] = 0;
  12130. li_config_table[j].flag_table[i] = 0;
  12131. li_config_table[i].coef_table[j] = 0;
  12132. li_config_table[j].coef_table[i] = 0;
  12133. }
  12134. }
  12135. }
  12136. }
  12137. }
  12138. static void adv_voice_prepare_switch(dword Id, PLCI *plci)
  12139. {
  12140. dbug(1, dprintf("[%06lx] %s,%d: adv_voice_prepare_switch",
  12141. UnMapId(Id), (char *)(FILE_), __LINE__));
  12142. }
  12143. static word adv_voice_save_config(dword Id, PLCI *plci, byte Rc)
  12144. {
  12145. dbug(1, dprintf("[%06lx] %s,%d: adv_voice_save_config %02x %d",
  12146. UnMapId(Id), (char *)(FILE_), __LINE__, Rc, plci->adjust_b_state));
  12147. return (GOOD);
  12148. }
  12149. static word adv_voice_restore_config(dword Id, PLCI *plci, byte Rc)
  12150. {
  12151. DIVA_CAPI_ADAPTER *a;
  12152. word Info;
  12153. dbug(1, dprintf("[%06lx] %s,%d: adv_voice_restore_config %02x %d",
  12154. UnMapId(Id), (char *)(FILE_), __LINE__, Rc, plci->adjust_b_state));
  12155. Info = GOOD;
  12156. a = plci->adapter;
  12157. if ((plci->B1_facilities & B1_FACILITY_VOICE)
  12158. && (plci->tel == ADV_VOICE) && (plci == a->AdvSignalPLCI))
  12159. {
  12160. switch (plci->adjust_b_state)
  12161. {
  12162. case ADJUST_B_RESTORE_VOICE_1:
  12163. plci->internal_command = plci->adjust_b_command;
  12164. if (plci->sig_req)
  12165. {
  12166. plci->adjust_b_state = ADJUST_B_RESTORE_VOICE_1;
  12167. break;
  12168. }
  12169. adv_voice_write_coefs(plci, ADV_VOICE_WRITE_UPDATE);
  12170. plci->adjust_b_state = ADJUST_B_RESTORE_VOICE_2;
  12171. break;
  12172. case ADJUST_B_RESTORE_VOICE_2:
  12173. if ((Rc != OK) && (Rc != OK_FC))
  12174. {
  12175. dbug(1, dprintf("[%06lx] %s,%d: Restore voice config failed %02x",
  12176. UnMapId(Id), (char *)(FILE_), __LINE__, Rc));
  12177. Info = _WRONG_STATE;
  12178. break;
  12179. }
  12180. break;
  12181. }
  12182. }
  12183. return (Info);
  12184. }
  12185. /*------------------------------------------------------------------*/
  12186. /* B1 resource switching */
  12187. /*------------------------------------------------------------------*/
  12188. static byte b1_facilities_table[] =
  12189. {
  12190. 0x00, /* 0 No bchannel resources */
  12191. 0x00, /* 1 Codec (automatic law) */
  12192. 0x00, /* 2 Codec (A-law) */
  12193. 0x00, /* 3 Codec (y-law) */
  12194. 0x00, /* 4 HDLC for X.21 */
  12195. 0x00, /* 5 HDLC */
  12196. 0x00, /* 6 External Device 0 */
  12197. 0x00, /* 7 External Device 1 */
  12198. 0x00, /* 8 HDLC 56k */
  12199. 0x00, /* 9 Transparent */
  12200. 0x00, /* 10 Loopback to network */
  12201. 0x00, /* 11 Test pattern to net */
  12202. 0x00, /* 12 Rate adaptation sync */
  12203. 0x00, /* 13 Rate adaptation async */
  12204. 0x00, /* 14 R-Interface */
  12205. 0x00, /* 15 HDLC 128k leased line */
  12206. 0x00, /* 16 FAX */
  12207. 0x00, /* 17 Modem async */
  12208. 0x00, /* 18 Modem sync HDLC */
  12209. 0x00, /* 19 V.110 async HDLC */
  12210. 0x12, /* 20 Adv voice (Trans,mixer) */
  12211. 0x00, /* 21 Codec connected to IC */
  12212. 0x0c, /* 22 Trans,DTMF */
  12213. 0x1e, /* 23 Trans,DTMF+mixer */
  12214. 0x1f, /* 24 Trans,DTMF+mixer+local */
  12215. 0x13, /* 25 Trans,mixer+local */
  12216. 0x12, /* 26 HDLC,mixer */
  12217. 0x12, /* 27 HDLC 56k,mixer */
  12218. 0x2c, /* 28 Trans,LEC+DTMF */
  12219. 0x3e, /* 29 Trans,LEC+DTMF+mixer */
  12220. 0x3f, /* 30 Trans,LEC+DTMF+mixer+local */
  12221. 0x2c, /* 31 RTP,LEC+DTMF */
  12222. 0x3e, /* 32 RTP,LEC+DTMF+mixer */
  12223. 0x3f, /* 33 RTP,LEC+DTMF+mixer+local */
  12224. 0x00, /* 34 Signaling task */
  12225. 0x00, /* 35 PIAFS */
  12226. 0x0c, /* 36 Trans,DTMF+TONE */
  12227. 0x1e, /* 37 Trans,DTMF+TONE+mixer */
  12228. 0x1f /* 38 Trans,DTMF+TONE+mixer+local*/
  12229. };
  12230. static word get_b1_facilities(PLCI *plci, byte b1_resource)
  12231. {
  12232. word b1_facilities;
  12233. b1_facilities = b1_facilities_table[b1_resource];
  12234. if ((b1_resource == 9) || (b1_resource == 20) || (b1_resource == 25))
  12235. {
  12236. if (!(((plci->requested_options_conn | plci->requested_options) & (1L << PRIVATE_DTMF_TONE))
  12237. || (plci->appl && (plci->adapter->requested_options_table[plci->appl->Id - 1] & (1L << PRIVATE_DTMF_TONE)))))
  12238. {
  12239. if (plci->adapter->manufacturer_features & MANUFACTURER_FEATURE_SOFTDTMF_SEND)
  12240. b1_facilities |= B1_FACILITY_DTMFX;
  12241. if (plci->adapter->manufacturer_features & MANUFACTURER_FEATURE_SOFTDTMF_RECEIVE)
  12242. b1_facilities |= B1_FACILITY_DTMFR;
  12243. }
  12244. }
  12245. if ((b1_resource == 17) || (b1_resource == 18))
  12246. {
  12247. if (plci->adapter->manufacturer_features & (MANUFACTURER_FEATURE_V18 | MANUFACTURER_FEATURE_VOWN))
  12248. b1_facilities |= B1_FACILITY_DTMFX | B1_FACILITY_DTMFR;
  12249. }
  12250. /*
  12251. dbug (1, dprintf("[%06lx] %s,%d: get_b1_facilities %d %04x",
  12252. (dword)((plci->Id << 8) | UnMapController(plci->adapter->Id)),
  12253. (char far *)(FILE_), __LINE__, b1_resource, b1_facilites));
  12254. */
  12255. return (b1_facilities);
  12256. }
  12257. static byte add_b1_facilities(PLCI *plci, byte b1_resource, word b1_facilities)
  12258. {
  12259. byte b;
  12260. switch (b1_resource)
  12261. {
  12262. case 5:
  12263. case 26:
  12264. if (b1_facilities & (B1_FACILITY_MIXER | B1_FACILITY_VOICE))
  12265. b = 26;
  12266. else
  12267. b = 5;
  12268. break;
  12269. case 8:
  12270. case 27:
  12271. if (b1_facilities & (B1_FACILITY_MIXER | B1_FACILITY_VOICE))
  12272. b = 27;
  12273. else
  12274. b = 8;
  12275. break;
  12276. case 9:
  12277. case 20:
  12278. case 22:
  12279. case 23:
  12280. case 24:
  12281. case 25:
  12282. case 28:
  12283. case 29:
  12284. case 30:
  12285. case 36:
  12286. case 37:
  12287. case 38:
  12288. if (b1_facilities & B1_FACILITY_EC)
  12289. {
  12290. if (b1_facilities & B1_FACILITY_LOCAL)
  12291. b = 30;
  12292. else if (b1_facilities & (B1_FACILITY_MIXER | B1_FACILITY_VOICE))
  12293. b = 29;
  12294. else
  12295. b = 28;
  12296. }
  12297. else if ((b1_facilities & (B1_FACILITY_DTMFX | B1_FACILITY_DTMFR | B1_FACILITY_MIXER))
  12298. && (((plci->requested_options_conn | plci->requested_options) & (1L << PRIVATE_DTMF_TONE))
  12299. || (plci->appl && (plci->adapter->requested_options_table[plci->appl->Id - 1] & (1L << PRIVATE_DTMF_TONE)))))
  12300. {
  12301. if (b1_facilities & B1_FACILITY_LOCAL)
  12302. b = 38;
  12303. else if (b1_facilities & (B1_FACILITY_MIXER | B1_FACILITY_VOICE))
  12304. b = 37;
  12305. else
  12306. b = 36;
  12307. }
  12308. else if (((plci->adapter->manufacturer_features & MANUFACTURER_FEATURE_HARDDTMF)
  12309. && !(plci->adapter->manufacturer_features & MANUFACTURER_FEATURE_SOFTDTMF_RECEIVE))
  12310. || ((b1_facilities & B1_FACILITY_DTMFR)
  12311. && ((b1_facilities & B1_FACILITY_MIXER)
  12312. || !(plci->adapter->manufacturer_features & MANUFACTURER_FEATURE_SOFTDTMF_RECEIVE)))
  12313. || ((b1_facilities & B1_FACILITY_DTMFX)
  12314. && ((b1_facilities & B1_FACILITY_MIXER)
  12315. || !(plci->adapter->manufacturer_features & MANUFACTURER_FEATURE_SOFTDTMF_SEND))))
  12316. {
  12317. if (b1_facilities & B1_FACILITY_LOCAL)
  12318. b = 24;
  12319. else if (b1_facilities & (B1_FACILITY_MIXER | B1_FACILITY_VOICE))
  12320. b = 23;
  12321. else
  12322. b = 22;
  12323. }
  12324. else
  12325. {
  12326. if (b1_facilities & B1_FACILITY_LOCAL)
  12327. b = 25;
  12328. else if (b1_facilities & (B1_FACILITY_MIXER | B1_FACILITY_VOICE))
  12329. b = 20;
  12330. else
  12331. b = 9;
  12332. }
  12333. break;
  12334. case 31:
  12335. case 32:
  12336. case 33:
  12337. if (b1_facilities & B1_FACILITY_LOCAL)
  12338. b = 33;
  12339. else if (b1_facilities & (B1_FACILITY_MIXER | B1_FACILITY_VOICE))
  12340. b = 32;
  12341. else
  12342. b = 31;
  12343. break;
  12344. default:
  12345. b = b1_resource;
  12346. }
  12347. dbug(1, dprintf("[%06lx] %s,%d: add_b1_facilities %d %04x %d %04x",
  12348. (dword)((plci->Id << 8) | UnMapController(plci->adapter->Id)),
  12349. (char *)(FILE_), __LINE__,
  12350. b1_resource, b1_facilities, b, get_b1_facilities(plci, b)));
  12351. return (b);
  12352. }
  12353. static void adjust_b1_facilities(PLCI *plci, byte new_b1_resource, word new_b1_facilities)
  12354. {
  12355. word removed_facilities;
  12356. dbug(1, dprintf("[%06lx] %s,%d: adjust_b1_facilities %d %04x %04x",
  12357. (dword)((plci->Id << 8) | UnMapController(plci->adapter->Id)),
  12358. (char *)(FILE_), __LINE__, new_b1_resource, new_b1_facilities,
  12359. new_b1_facilities & get_b1_facilities(plci, new_b1_resource)));
  12360. new_b1_facilities &= get_b1_facilities(plci, new_b1_resource);
  12361. removed_facilities = plci->B1_facilities & ~new_b1_facilities;
  12362. if (removed_facilities & B1_FACILITY_EC)
  12363. ec_clear_config(plci);
  12364. if (removed_facilities & B1_FACILITY_DTMFR)
  12365. {
  12366. dtmf_rec_clear_config(plci);
  12367. dtmf_parameter_clear_config(plci);
  12368. }
  12369. if (removed_facilities & B1_FACILITY_DTMFX)
  12370. dtmf_send_clear_config(plci);
  12371. if (removed_facilities & B1_FACILITY_MIXER)
  12372. mixer_clear_config(plci);
  12373. if (removed_facilities & B1_FACILITY_VOICE)
  12374. adv_voice_clear_config(plci);
  12375. plci->B1_facilities = new_b1_facilities;
  12376. }
  12377. static void adjust_b_clear(PLCI *plci)
  12378. {
  12379. dbug(1, dprintf("[%06lx] %s,%d: adjust_b_clear",
  12380. (dword)((plci->Id << 8) | UnMapController(plci->adapter->Id)),
  12381. (char *)(FILE_), __LINE__));
  12382. plci->adjust_b_restore = false;
  12383. }
  12384. static word adjust_b_process(dword Id, PLCI *plci, byte Rc)
  12385. {
  12386. word Info;
  12387. byte b1_resource;
  12388. NCCI *ncci_ptr;
  12389. API_PARSE bp[2];
  12390. dbug(1, dprintf("[%06lx] %s,%d: adjust_b_process %02x %d",
  12391. UnMapId(Id), (char *)(FILE_), __LINE__, Rc, plci->adjust_b_state));
  12392. Info = GOOD;
  12393. switch (plci->adjust_b_state)
  12394. {
  12395. case ADJUST_B_START:
  12396. if ((plci->adjust_b_parms_msg == NULL)
  12397. && (plci->adjust_b_mode & ADJUST_B_MODE_SWITCH_L1)
  12398. && ((plci->adjust_b_mode & ~(ADJUST_B_MODE_SAVE | ADJUST_B_MODE_SWITCH_L1 |
  12399. ADJUST_B_MODE_NO_RESOURCE | ADJUST_B_MODE_RESTORE)) == 0))
  12400. {
  12401. b1_resource = (plci->adjust_b_mode == ADJUST_B_MODE_NO_RESOURCE) ?
  12402. 0 : add_b1_facilities(plci, plci->B1_resource, plci->adjust_b_facilities);
  12403. if (b1_resource == plci->B1_resource)
  12404. {
  12405. adjust_b1_facilities(plci, b1_resource, plci->adjust_b_facilities);
  12406. break;
  12407. }
  12408. if (plci->adjust_b_facilities & ~get_b1_facilities(plci, b1_resource))
  12409. {
  12410. dbug(1, dprintf("[%06lx] %s,%d: Adjust B nonsupported facilities %d %d %04x",
  12411. UnMapId(Id), (char *)(FILE_), __LINE__,
  12412. plci->B1_resource, b1_resource, plci->adjust_b_facilities));
  12413. Info = _WRONG_STATE;
  12414. break;
  12415. }
  12416. }
  12417. if (plci->adjust_b_mode & ADJUST_B_MODE_SAVE)
  12418. {
  12419. mixer_prepare_switch(Id, plci);
  12420. dtmf_prepare_switch(Id, plci);
  12421. dtmf_parameter_prepare_switch(Id, plci);
  12422. ec_prepare_switch(Id, plci);
  12423. adv_voice_prepare_switch(Id, plci);
  12424. }
  12425. plci->adjust_b_state = ADJUST_B_SAVE_MIXER_1;
  12426. Rc = OK;
  12427. /* fall through */
  12428. case ADJUST_B_SAVE_MIXER_1:
  12429. if (plci->adjust_b_mode & ADJUST_B_MODE_SAVE)
  12430. {
  12431. Info = mixer_save_config(Id, plci, Rc);
  12432. if ((Info != GOOD) || plci->internal_command)
  12433. break;
  12434. }
  12435. plci->adjust_b_state = ADJUST_B_SAVE_DTMF_1;
  12436. Rc = OK;
  12437. /* fall through */
  12438. case ADJUST_B_SAVE_DTMF_1:
  12439. if (plci->adjust_b_mode & ADJUST_B_MODE_SAVE)
  12440. {
  12441. Info = dtmf_save_config(Id, plci, Rc);
  12442. if ((Info != GOOD) || plci->internal_command)
  12443. break;
  12444. }
  12445. plci->adjust_b_state = ADJUST_B_REMOVE_L23_1;
  12446. /* fall through */
  12447. case ADJUST_B_REMOVE_L23_1:
  12448. if ((plci->adjust_b_mode & ADJUST_B_MODE_REMOVE_L23)
  12449. && plci->NL.Id && !plci->nl_remove_id)
  12450. {
  12451. plci->internal_command = plci->adjust_b_command;
  12452. if (plci->adjust_b_ncci != 0)
  12453. {
  12454. ncci_ptr = &(plci->adapter->ncci[plci->adjust_b_ncci]);
  12455. while (ncci_ptr->data_pending)
  12456. {
  12457. plci->data_sent_ptr = ncci_ptr->DBuffer[ncci_ptr->data_out].P;
  12458. data_rc(plci, plci->adapter->ncci_ch[plci->adjust_b_ncci]);
  12459. }
  12460. while (ncci_ptr->data_ack_pending)
  12461. data_ack(plci, plci->adapter->ncci_ch[plci->adjust_b_ncci]);
  12462. }
  12463. nl_req_ncci(plci, REMOVE,
  12464. (byte)((plci->adjust_b_mode & ADJUST_B_MODE_CONNECT) ? plci->adjust_b_ncci : 0));
  12465. send_req(plci);
  12466. plci->adjust_b_state = ADJUST_B_REMOVE_L23_2;
  12467. break;
  12468. }
  12469. plci->adjust_b_state = ADJUST_B_REMOVE_L23_2;
  12470. Rc = OK;
  12471. /* fall through */
  12472. case ADJUST_B_REMOVE_L23_2:
  12473. if ((Rc != OK) && (Rc != OK_FC))
  12474. {
  12475. dbug(1, dprintf("[%06lx] %s,%d: Adjust B remove failed %02x",
  12476. UnMapId(Id), (char *)(FILE_), __LINE__, Rc));
  12477. Info = _WRONG_STATE;
  12478. break;
  12479. }
  12480. if (plci->adjust_b_mode & ADJUST_B_MODE_REMOVE_L23)
  12481. {
  12482. if (plci_nl_busy(plci))
  12483. {
  12484. plci->internal_command = plci->adjust_b_command;
  12485. break;
  12486. }
  12487. }
  12488. plci->adjust_b_state = ADJUST_B_SAVE_EC_1;
  12489. Rc = OK;
  12490. /* fall through */
  12491. case ADJUST_B_SAVE_EC_1:
  12492. if (plci->adjust_b_mode & ADJUST_B_MODE_SAVE)
  12493. {
  12494. Info = ec_save_config(Id, plci, Rc);
  12495. if ((Info != GOOD) || plci->internal_command)
  12496. break;
  12497. }
  12498. plci->adjust_b_state = ADJUST_B_SAVE_DTMF_PARAMETER_1;
  12499. Rc = OK;
  12500. /* fall through */
  12501. case ADJUST_B_SAVE_DTMF_PARAMETER_1:
  12502. if (plci->adjust_b_mode & ADJUST_B_MODE_SAVE)
  12503. {
  12504. Info = dtmf_parameter_save_config(Id, plci, Rc);
  12505. if ((Info != GOOD) || plci->internal_command)
  12506. break;
  12507. }
  12508. plci->adjust_b_state = ADJUST_B_SAVE_VOICE_1;
  12509. Rc = OK;
  12510. /* fall through */
  12511. case ADJUST_B_SAVE_VOICE_1:
  12512. if (plci->adjust_b_mode & ADJUST_B_MODE_SAVE)
  12513. {
  12514. Info = adv_voice_save_config(Id, plci, Rc);
  12515. if ((Info != GOOD) || plci->internal_command)
  12516. break;
  12517. }
  12518. plci->adjust_b_state = ADJUST_B_SWITCH_L1_1;
  12519. /* fall through */
  12520. case ADJUST_B_SWITCH_L1_1:
  12521. if (plci->adjust_b_mode & ADJUST_B_MODE_SWITCH_L1)
  12522. {
  12523. if (plci->sig_req)
  12524. {
  12525. plci->internal_command = plci->adjust_b_command;
  12526. break;
  12527. }
  12528. if (plci->adjust_b_parms_msg != NULL)
  12529. api_load_msg(plci->adjust_b_parms_msg, bp);
  12530. else
  12531. api_load_msg(&plci->B_protocol, bp);
  12532. Info = add_b1(plci, bp,
  12533. (word)((plci->adjust_b_mode & ADJUST_B_MODE_NO_RESOURCE) ? 2 : 0),
  12534. plci->adjust_b_facilities);
  12535. if (Info != GOOD)
  12536. {
  12537. dbug(1, dprintf("[%06lx] %s,%d: Adjust B invalid L1 parameters %d %04x",
  12538. UnMapId(Id), (char *)(FILE_), __LINE__,
  12539. plci->B1_resource, plci->adjust_b_facilities));
  12540. break;
  12541. }
  12542. plci->internal_command = plci->adjust_b_command;
  12543. sig_req(plci, RESOURCES, 0);
  12544. send_req(plci);
  12545. plci->adjust_b_state = ADJUST_B_SWITCH_L1_2;
  12546. break;
  12547. }
  12548. plci->adjust_b_state = ADJUST_B_SWITCH_L1_2;
  12549. Rc = OK;
  12550. /* fall through */
  12551. case ADJUST_B_SWITCH_L1_2:
  12552. if ((Rc != OK) && (Rc != OK_FC))
  12553. {
  12554. dbug(1, dprintf("[%06lx] %s,%d: Adjust B switch failed %02x %d %04x",
  12555. UnMapId(Id), (char *)(FILE_), __LINE__,
  12556. Rc, plci->B1_resource, plci->adjust_b_facilities));
  12557. Info = _WRONG_STATE;
  12558. break;
  12559. }
  12560. plci->adjust_b_state = ADJUST_B_RESTORE_VOICE_1;
  12561. Rc = OK;
  12562. /* fall through */
  12563. case ADJUST_B_RESTORE_VOICE_1:
  12564. case ADJUST_B_RESTORE_VOICE_2:
  12565. if (plci->adjust_b_mode & ADJUST_B_MODE_RESTORE)
  12566. {
  12567. Info = adv_voice_restore_config(Id, plci, Rc);
  12568. if ((Info != GOOD) || plci->internal_command)
  12569. break;
  12570. }
  12571. plci->adjust_b_state = ADJUST_B_RESTORE_DTMF_PARAMETER_1;
  12572. Rc = OK;
  12573. /* fall through */
  12574. case ADJUST_B_RESTORE_DTMF_PARAMETER_1:
  12575. case ADJUST_B_RESTORE_DTMF_PARAMETER_2:
  12576. if (plci->adjust_b_mode & ADJUST_B_MODE_RESTORE)
  12577. {
  12578. Info = dtmf_parameter_restore_config(Id, plci, Rc);
  12579. if ((Info != GOOD) || plci->internal_command)
  12580. break;
  12581. }
  12582. plci->adjust_b_state = ADJUST_B_RESTORE_EC_1;
  12583. Rc = OK;
  12584. /* fall through */
  12585. case ADJUST_B_RESTORE_EC_1:
  12586. case ADJUST_B_RESTORE_EC_2:
  12587. if (plci->adjust_b_mode & ADJUST_B_MODE_RESTORE)
  12588. {
  12589. Info = ec_restore_config(Id, plci, Rc);
  12590. if ((Info != GOOD) || plci->internal_command)
  12591. break;
  12592. }
  12593. plci->adjust_b_state = ADJUST_B_ASSIGN_L23_1;
  12594. /* fall through */
  12595. case ADJUST_B_ASSIGN_L23_1:
  12596. if (plci->adjust_b_mode & ADJUST_B_MODE_ASSIGN_L23)
  12597. {
  12598. if (plci_nl_busy(plci))
  12599. {
  12600. plci->internal_command = plci->adjust_b_command;
  12601. break;
  12602. }
  12603. if (plci->adjust_b_mode & ADJUST_B_MODE_CONNECT)
  12604. plci->call_dir |= CALL_DIR_FORCE_OUTG_NL;
  12605. if (plci->adjust_b_parms_msg != NULL)
  12606. api_load_msg(plci->adjust_b_parms_msg, bp);
  12607. else
  12608. api_load_msg(&plci->B_protocol, bp);
  12609. Info = add_b23(plci, bp);
  12610. if (Info != GOOD)
  12611. {
  12612. dbug(1, dprintf("[%06lx] %s,%d: Adjust B invalid L23 parameters %04x",
  12613. UnMapId(Id), (char *)(FILE_), __LINE__, Info));
  12614. break;
  12615. }
  12616. plci->internal_command = plci->adjust_b_command;
  12617. nl_req_ncci(plci, ASSIGN, 0);
  12618. send_req(plci);
  12619. plci->adjust_b_state = ADJUST_B_ASSIGN_L23_2;
  12620. break;
  12621. }
  12622. plci->adjust_b_state = ADJUST_B_ASSIGN_L23_2;
  12623. Rc = ASSIGN_OK;
  12624. /* fall through */
  12625. case ADJUST_B_ASSIGN_L23_2:
  12626. if ((Rc != OK) && (Rc != OK_FC) && (Rc != ASSIGN_OK))
  12627. {
  12628. dbug(1, dprintf("[%06lx] %s,%d: Adjust B assign failed %02x",
  12629. UnMapId(Id), (char *)(FILE_), __LINE__, Rc));
  12630. Info = _WRONG_STATE;
  12631. break;
  12632. }
  12633. if (plci->adjust_b_mode & ADJUST_B_MODE_ASSIGN_L23)
  12634. {
  12635. if (Rc != ASSIGN_OK)
  12636. {
  12637. plci->internal_command = plci->adjust_b_command;
  12638. break;
  12639. }
  12640. }
  12641. if (plci->adjust_b_mode & ADJUST_B_MODE_USER_CONNECT)
  12642. {
  12643. plci->adjust_b_restore = true;
  12644. break;
  12645. }
  12646. plci->adjust_b_state = ADJUST_B_CONNECT_1;
  12647. /* fall through */
  12648. case ADJUST_B_CONNECT_1:
  12649. if (plci->adjust_b_mode & ADJUST_B_MODE_CONNECT)
  12650. {
  12651. plci->internal_command = plci->adjust_b_command;
  12652. if (plci_nl_busy(plci))
  12653. break;
  12654. nl_req_ncci(plci, N_CONNECT, 0);
  12655. send_req(plci);
  12656. plci->adjust_b_state = ADJUST_B_CONNECT_2;
  12657. break;
  12658. }
  12659. plci->adjust_b_state = ADJUST_B_RESTORE_DTMF_1;
  12660. Rc = OK;
  12661. /* fall through */
  12662. case ADJUST_B_CONNECT_2:
  12663. case ADJUST_B_CONNECT_3:
  12664. case ADJUST_B_CONNECT_4:
  12665. if ((Rc != OK) && (Rc != OK_FC) && (Rc != 0))
  12666. {
  12667. dbug(1, dprintf("[%06lx] %s,%d: Adjust B connect failed %02x",
  12668. UnMapId(Id), (char *)(FILE_), __LINE__, Rc));
  12669. Info = _WRONG_STATE;
  12670. break;
  12671. }
  12672. if (Rc == OK)
  12673. {
  12674. if (plci->adjust_b_mode & ADJUST_B_MODE_CONNECT)
  12675. {
  12676. get_ncci(plci, (byte)(Id >> 16), plci->adjust_b_ncci);
  12677. Id = (Id & 0xffff) | (((dword)(plci->adjust_b_ncci)) << 16);
  12678. }
  12679. if (plci->adjust_b_state == ADJUST_B_CONNECT_2)
  12680. plci->adjust_b_state = ADJUST_B_CONNECT_3;
  12681. else if (plci->adjust_b_state == ADJUST_B_CONNECT_4)
  12682. plci->adjust_b_state = ADJUST_B_RESTORE_DTMF_1;
  12683. }
  12684. else if (Rc == 0)
  12685. {
  12686. if (plci->adjust_b_state == ADJUST_B_CONNECT_2)
  12687. plci->adjust_b_state = ADJUST_B_CONNECT_4;
  12688. else if (plci->adjust_b_state == ADJUST_B_CONNECT_3)
  12689. plci->adjust_b_state = ADJUST_B_RESTORE_DTMF_1;
  12690. }
  12691. if (plci->adjust_b_state != ADJUST_B_RESTORE_DTMF_1)
  12692. {
  12693. plci->internal_command = plci->adjust_b_command;
  12694. break;
  12695. }
  12696. Rc = OK;
  12697. /* fall through */
  12698. case ADJUST_B_RESTORE_DTMF_1:
  12699. case ADJUST_B_RESTORE_DTMF_2:
  12700. if (plci->adjust_b_mode & ADJUST_B_MODE_RESTORE)
  12701. {
  12702. Info = dtmf_restore_config(Id, plci, Rc);
  12703. if ((Info != GOOD) || plci->internal_command)
  12704. break;
  12705. }
  12706. plci->adjust_b_state = ADJUST_B_RESTORE_MIXER_1;
  12707. Rc = OK;
  12708. /* fall through */
  12709. case ADJUST_B_RESTORE_MIXER_1:
  12710. case ADJUST_B_RESTORE_MIXER_2:
  12711. case ADJUST_B_RESTORE_MIXER_3:
  12712. case ADJUST_B_RESTORE_MIXER_4:
  12713. case ADJUST_B_RESTORE_MIXER_5:
  12714. case ADJUST_B_RESTORE_MIXER_6:
  12715. case ADJUST_B_RESTORE_MIXER_7:
  12716. if (plci->adjust_b_mode & ADJUST_B_MODE_RESTORE)
  12717. {
  12718. Info = mixer_restore_config(Id, plci, Rc);
  12719. if ((Info != GOOD) || plci->internal_command)
  12720. break;
  12721. }
  12722. plci->adjust_b_state = ADJUST_B_END;
  12723. case ADJUST_B_END:
  12724. break;
  12725. }
  12726. return (Info);
  12727. }
  12728. static void adjust_b1_resource(dword Id, PLCI *plci, API_SAVE *bp_msg, word b1_facilities, word internal_command)
  12729. {
  12730. dbug(1, dprintf("[%06lx] %s,%d: adjust_b1_resource %d %04x",
  12731. UnMapId(Id), (char *)(FILE_), __LINE__,
  12732. plci->B1_resource, b1_facilities));
  12733. plci->adjust_b_parms_msg = bp_msg;
  12734. plci->adjust_b_facilities = b1_facilities;
  12735. plci->adjust_b_command = internal_command;
  12736. plci->adjust_b_ncci = (word)(Id >> 16);
  12737. if ((bp_msg == NULL) && (plci->B1_resource == 0))
  12738. plci->adjust_b_mode = ADJUST_B_MODE_SAVE | ADJUST_B_MODE_NO_RESOURCE | ADJUST_B_MODE_SWITCH_L1;
  12739. else
  12740. plci->adjust_b_mode = ADJUST_B_MODE_SAVE | ADJUST_B_MODE_SWITCH_L1 | ADJUST_B_MODE_RESTORE;
  12741. plci->adjust_b_state = ADJUST_B_START;
  12742. dbug(1, dprintf("[%06lx] %s,%d: Adjust B1 resource %d %04x...",
  12743. UnMapId(Id), (char *)(FILE_), __LINE__,
  12744. plci->B1_resource, b1_facilities));
  12745. }
  12746. static void adjust_b_restore(dword Id, PLCI *plci, byte Rc)
  12747. {
  12748. word internal_command;
  12749. dbug(1, dprintf("[%06lx] %s,%d: adjust_b_restore %02x %04x",
  12750. UnMapId(Id), (char *)(FILE_), __LINE__, Rc, plci->internal_command));
  12751. internal_command = plci->internal_command;
  12752. plci->internal_command = 0;
  12753. switch (internal_command)
  12754. {
  12755. default:
  12756. plci->command = 0;
  12757. if (plci->req_in != 0)
  12758. {
  12759. plci->internal_command = ADJUST_B_RESTORE_1;
  12760. break;
  12761. }
  12762. Rc = OK;
  12763. /* fall through */
  12764. case ADJUST_B_RESTORE_1:
  12765. if ((Rc != OK) && (Rc != OK_FC))
  12766. {
  12767. dbug(1, dprintf("[%06lx] %s,%d: Adjust B enqueued failed %02x",
  12768. UnMapId(Id), (char *)(FILE_), __LINE__, Rc));
  12769. }
  12770. plci->adjust_b_parms_msg = NULL;
  12771. plci->adjust_b_facilities = plci->B1_facilities;
  12772. plci->adjust_b_command = ADJUST_B_RESTORE_2;
  12773. plci->adjust_b_ncci = (word)(Id >> 16);
  12774. plci->adjust_b_mode = ADJUST_B_MODE_RESTORE;
  12775. plci->adjust_b_state = ADJUST_B_START;
  12776. dbug(1, dprintf("[%06lx] %s,%d: Adjust B restore...",
  12777. UnMapId(Id), (char *)(FILE_), __LINE__));
  12778. /* fall through */
  12779. case ADJUST_B_RESTORE_2:
  12780. if (adjust_b_process(Id, plci, Rc) != GOOD)
  12781. {
  12782. dbug(1, dprintf("[%06lx] %s,%d: Adjust B restore failed",
  12783. UnMapId(Id), (char *)(FILE_), __LINE__));
  12784. }
  12785. if (plci->internal_command)
  12786. break;
  12787. break;
  12788. }
  12789. }
  12790. static void reset_b3_command(dword Id, PLCI *plci, byte Rc)
  12791. {
  12792. word Info;
  12793. word internal_command;
  12794. dbug(1, dprintf("[%06lx] %s,%d: reset_b3_command %02x %04x",
  12795. UnMapId(Id), (char *)(FILE_), __LINE__, Rc, plci->internal_command));
  12796. Info = GOOD;
  12797. internal_command = plci->internal_command;
  12798. plci->internal_command = 0;
  12799. switch (internal_command)
  12800. {
  12801. default:
  12802. plci->command = 0;
  12803. plci->adjust_b_parms_msg = NULL;
  12804. plci->adjust_b_facilities = plci->B1_facilities;
  12805. plci->adjust_b_command = RESET_B3_COMMAND_1;
  12806. plci->adjust_b_ncci = (word)(Id >> 16);
  12807. plci->adjust_b_mode = ADJUST_B_MODE_REMOVE_L23 | ADJUST_B_MODE_ASSIGN_L23 | ADJUST_B_MODE_CONNECT;
  12808. plci->adjust_b_state = ADJUST_B_START;
  12809. dbug(1, dprintf("[%06lx] %s,%d: Reset B3...",
  12810. UnMapId(Id), (char *)(FILE_), __LINE__));
  12811. /* fall through */
  12812. case RESET_B3_COMMAND_1:
  12813. Info = adjust_b_process(Id, plci, Rc);
  12814. if (Info != GOOD)
  12815. {
  12816. dbug(1, dprintf("[%06lx] %s,%d: Reset failed",
  12817. UnMapId(Id), (char *)(FILE_), __LINE__));
  12818. break;
  12819. }
  12820. if (plci->internal_command)
  12821. return;
  12822. break;
  12823. }
  12824. /* sendf (plci->appl, _RESET_B3_R | CONFIRM, Id, plci->number, "w", Info);*/
  12825. sendf(plci->appl, _RESET_B3_I, Id, 0, "s", "");
  12826. }
  12827. static void select_b_command(dword Id, PLCI *plci, byte Rc)
  12828. {
  12829. word Info;
  12830. word internal_command;
  12831. byte esc_chi[3];
  12832. dbug(1, dprintf("[%06lx] %s,%d: select_b_command %02x %04x",
  12833. UnMapId(Id), (char *)(FILE_), __LINE__, Rc, plci->internal_command));
  12834. Info = GOOD;
  12835. internal_command = plci->internal_command;
  12836. plci->internal_command = 0;
  12837. switch (internal_command)
  12838. {
  12839. default:
  12840. plci->command = 0;
  12841. plci->adjust_b_parms_msg = &plci->saved_msg;
  12842. if ((plci->tel == ADV_VOICE) && (plci == plci->adapter->AdvSignalPLCI))
  12843. plci->adjust_b_facilities = plci->B1_facilities | B1_FACILITY_VOICE;
  12844. else
  12845. plci->adjust_b_facilities = plci->B1_facilities & ~B1_FACILITY_VOICE;
  12846. plci->adjust_b_command = SELECT_B_COMMAND_1;
  12847. plci->adjust_b_ncci = (word)(Id >> 16);
  12848. if (plci->saved_msg.parms[0].length == 0)
  12849. {
  12850. plci->adjust_b_mode = ADJUST_B_MODE_SAVE | ADJUST_B_MODE_REMOVE_L23 | ADJUST_B_MODE_SWITCH_L1 |
  12851. ADJUST_B_MODE_NO_RESOURCE;
  12852. }
  12853. else
  12854. {
  12855. plci->adjust_b_mode = ADJUST_B_MODE_SAVE | ADJUST_B_MODE_REMOVE_L23 | ADJUST_B_MODE_SWITCH_L1 |
  12856. ADJUST_B_MODE_ASSIGN_L23 | ADJUST_B_MODE_USER_CONNECT | ADJUST_B_MODE_RESTORE;
  12857. }
  12858. plci->adjust_b_state = ADJUST_B_START;
  12859. dbug(1, dprintf("[%06lx] %s,%d: Select B protocol...",
  12860. UnMapId(Id), (char *)(FILE_), __LINE__));
  12861. /* fall through */
  12862. case SELECT_B_COMMAND_1:
  12863. Info = adjust_b_process(Id, plci, Rc);
  12864. if (Info != GOOD)
  12865. {
  12866. dbug(1, dprintf("[%06lx] %s,%d: Select B protocol failed",
  12867. UnMapId(Id), (char *)(FILE_), __LINE__));
  12868. break;
  12869. }
  12870. if (plci->internal_command)
  12871. return;
  12872. if (plci->tel == ADV_VOICE)
  12873. {
  12874. esc_chi[0] = 0x02;
  12875. esc_chi[1] = 0x18;
  12876. esc_chi[2] = plci->b_channel;
  12877. SetVoiceChannel(plci->adapter->AdvCodecPLCI, esc_chi, plci->adapter);
  12878. }
  12879. break;
  12880. }
  12881. sendf(plci->appl, _SELECT_B_REQ | CONFIRM, Id, plci->number, "w", Info);
  12882. }
  12883. static void fax_connect_ack_command(dword Id, PLCI *plci, byte Rc)
  12884. {
  12885. word internal_command;
  12886. dbug(1, dprintf("[%06lx] %s,%d: fax_connect_ack_command %02x %04x",
  12887. UnMapId(Id), (char *)(FILE_), __LINE__, Rc, plci->internal_command));
  12888. internal_command = plci->internal_command;
  12889. plci->internal_command = 0;
  12890. switch (internal_command)
  12891. {
  12892. default:
  12893. plci->command = 0; /* fall through */
  12894. case FAX_CONNECT_ACK_COMMAND_1:
  12895. if (plci_nl_busy(plci))
  12896. {
  12897. plci->internal_command = FAX_CONNECT_ACK_COMMAND_1;
  12898. return;
  12899. }
  12900. plci->internal_command = FAX_CONNECT_ACK_COMMAND_2;
  12901. plci->NData[0].P = plci->fax_connect_info_buffer;
  12902. plci->NData[0].PLength = plci->fax_connect_info_length;
  12903. plci->NL.X = plci->NData;
  12904. plci->NL.ReqCh = 0;
  12905. plci->NL.Req = plci->nl_req = (byte) N_CONNECT_ACK;
  12906. plci->adapter->request(&plci->NL);
  12907. return;
  12908. case FAX_CONNECT_ACK_COMMAND_2:
  12909. if ((Rc != OK) && (Rc != OK_FC))
  12910. {
  12911. dbug(1, dprintf("[%06lx] %s,%d: FAX issue CONNECT ACK failed %02x",
  12912. UnMapId(Id), (char *)(FILE_), __LINE__, Rc));
  12913. break;
  12914. }
  12915. }
  12916. if ((plci->ncpi_state & NCPI_VALID_CONNECT_B3_ACT)
  12917. && !(plci->ncpi_state & NCPI_CONNECT_B3_ACT_SENT))
  12918. {
  12919. if (plci->B3_prot == 4)
  12920. sendf(plci->appl, _CONNECT_B3_ACTIVE_I, Id, 0, "s", "");
  12921. else
  12922. sendf(plci->appl, _CONNECT_B3_ACTIVE_I, Id, 0, "S", plci->ncpi_buffer);
  12923. plci->ncpi_state |= NCPI_CONNECT_B3_ACT_SENT;
  12924. }
  12925. }
  12926. static void fax_edata_ack_command(dword Id, PLCI *plci, byte Rc)
  12927. {
  12928. word internal_command;
  12929. dbug(1, dprintf("[%06lx] %s,%d: fax_edata_ack_command %02x %04x",
  12930. UnMapId(Id), (char *)(FILE_), __LINE__, Rc, plci->internal_command));
  12931. internal_command = plci->internal_command;
  12932. plci->internal_command = 0;
  12933. switch (internal_command)
  12934. {
  12935. default:
  12936. plci->command = 0;
  12937. /* fall through */
  12938. case FAX_EDATA_ACK_COMMAND_1:
  12939. if (plci_nl_busy(plci))
  12940. {
  12941. plci->internal_command = FAX_EDATA_ACK_COMMAND_1;
  12942. return;
  12943. }
  12944. plci->internal_command = FAX_EDATA_ACK_COMMAND_2;
  12945. plci->NData[0].P = plci->fax_connect_info_buffer;
  12946. plci->NData[0].PLength = plci->fax_edata_ack_length;
  12947. plci->NL.X = plci->NData;
  12948. plci->NL.ReqCh = 0;
  12949. plci->NL.Req = plci->nl_req = (byte) N_EDATA;
  12950. plci->adapter->request(&plci->NL);
  12951. return;
  12952. case FAX_EDATA_ACK_COMMAND_2:
  12953. if ((Rc != OK) && (Rc != OK_FC))
  12954. {
  12955. dbug(1, dprintf("[%06lx] %s,%d: FAX issue EDATA ACK failed %02x",
  12956. UnMapId(Id), (char *)(FILE_), __LINE__, Rc));
  12957. break;
  12958. }
  12959. }
  12960. }
  12961. static void fax_connect_info_command(dword Id, PLCI *plci, byte Rc)
  12962. {
  12963. word Info;
  12964. word internal_command;
  12965. dbug(1, dprintf("[%06lx] %s,%d: fax_connect_info_command %02x %04x",
  12966. UnMapId(Id), (char *)(FILE_), __LINE__, Rc, plci->internal_command));
  12967. Info = GOOD;
  12968. internal_command = plci->internal_command;
  12969. plci->internal_command = 0;
  12970. switch (internal_command)
  12971. {
  12972. default:
  12973. plci->command = 0; /* fall through */
  12974. case FAX_CONNECT_INFO_COMMAND_1:
  12975. if (plci_nl_busy(plci))
  12976. {
  12977. plci->internal_command = FAX_CONNECT_INFO_COMMAND_1;
  12978. return;
  12979. }
  12980. plci->internal_command = FAX_CONNECT_INFO_COMMAND_2;
  12981. plci->NData[0].P = plci->fax_connect_info_buffer;
  12982. plci->NData[0].PLength = plci->fax_connect_info_length;
  12983. plci->NL.X = plci->NData;
  12984. plci->NL.ReqCh = 0;
  12985. plci->NL.Req = plci->nl_req = (byte) N_EDATA;
  12986. plci->adapter->request(&plci->NL);
  12987. return;
  12988. case FAX_CONNECT_INFO_COMMAND_2:
  12989. if ((Rc != OK) && (Rc != OK_FC))
  12990. {
  12991. dbug(1, dprintf("[%06lx] %s,%d: FAX setting connect info failed %02x",
  12992. UnMapId(Id), (char *)(FILE_), __LINE__, Rc));
  12993. Info = _WRONG_STATE;
  12994. break;
  12995. }
  12996. if (plci_nl_busy(plci))
  12997. {
  12998. plci->internal_command = FAX_CONNECT_INFO_COMMAND_2;
  12999. return;
  13000. }
  13001. plci->command = _CONNECT_B3_R;
  13002. nl_req_ncci(plci, N_CONNECT, 0);
  13003. send_req(plci);
  13004. return;
  13005. }
  13006. sendf(plci->appl, _CONNECT_B3_R | CONFIRM, Id, plci->number, "w", Info);
  13007. }
  13008. static void fax_adjust_b23_command(dword Id, PLCI *plci, byte Rc)
  13009. {
  13010. word Info;
  13011. word internal_command;
  13012. dbug(1, dprintf("[%06lx] %s,%d: fax_adjust_b23_command %02x %04x",
  13013. UnMapId(Id), (char *)(FILE_), __LINE__, Rc, plci->internal_command));
  13014. Info = GOOD;
  13015. internal_command = plci->internal_command;
  13016. plci->internal_command = 0;
  13017. switch (internal_command)
  13018. {
  13019. default:
  13020. plci->command = 0;
  13021. plci->adjust_b_parms_msg = NULL;
  13022. plci->adjust_b_facilities = plci->B1_facilities;
  13023. plci->adjust_b_command = FAX_ADJUST_B23_COMMAND_1;
  13024. plci->adjust_b_ncci = (word)(Id >> 16);
  13025. plci->adjust_b_mode = ADJUST_B_MODE_REMOVE_L23 | ADJUST_B_MODE_ASSIGN_L23;
  13026. plci->adjust_b_state = ADJUST_B_START;
  13027. dbug(1, dprintf("[%06lx] %s,%d: FAX adjust B23...",
  13028. UnMapId(Id), (char *)(FILE_), __LINE__));
  13029. /* fall through */
  13030. case FAX_ADJUST_B23_COMMAND_1:
  13031. Info = adjust_b_process(Id, plci, Rc);
  13032. if (Info != GOOD)
  13033. {
  13034. dbug(1, dprintf("[%06lx] %s,%d: FAX adjust failed",
  13035. UnMapId(Id), (char *)(FILE_), __LINE__));
  13036. break;
  13037. }
  13038. if (plci->internal_command)
  13039. return;
  13040. /* fall through */
  13041. case FAX_ADJUST_B23_COMMAND_2:
  13042. if (plci_nl_busy(plci))
  13043. {
  13044. plci->internal_command = FAX_ADJUST_B23_COMMAND_2;
  13045. return;
  13046. }
  13047. plci->command = _CONNECT_B3_R;
  13048. nl_req_ncci(plci, N_CONNECT, 0);
  13049. send_req(plci);
  13050. return;
  13051. }
  13052. sendf(plci->appl, _CONNECT_B3_R | CONFIRM, Id, plci->number, "w", Info);
  13053. }
  13054. static void fax_disconnect_command(dword Id, PLCI *plci, byte Rc)
  13055. {
  13056. word internal_command;
  13057. dbug(1, dprintf("[%06lx] %s,%d: fax_disconnect_command %02x %04x",
  13058. UnMapId(Id), (char *)(FILE_), __LINE__, Rc, plci->internal_command));
  13059. internal_command = plci->internal_command;
  13060. plci->internal_command = 0;
  13061. switch (internal_command)
  13062. {
  13063. default:
  13064. plci->command = 0;
  13065. plci->internal_command = FAX_DISCONNECT_COMMAND_1;
  13066. return;
  13067. case FAX_DISCONNECT_COMMAND_1:
  13068. case FAX_DISCONNECT_COMMAND_2:
  13069. case FAX_DISCONNECT_COMMAND_3:
  13070. if ((Rc != OK) && (Rc != OK_FC) && (Rc != 0))
  13071. {
  13072. dbug(1, dprintf("[%06lx] %s,%d: FAX disconnect EDATA failed %02x",
  13073. UnMapId(Id), (char *)(FILE_), __LINE__, Rc));
  13074. break;
  13075. }
  13076. if (Rc == OK)
  13077. {
  13078. if ((internal_command == FAX_DISCONNECT_COMMAND_1)
  13079. || (internal_command == FAX_DISCONNECT_COMMAND_2))
  13080. {
  13081. plci->internal_command = FAX_DISCONNECT_COMMAND_2;
  13082. }
  13083. }
  13084. else if (Rc == 0)
  13085. {
  13086. if (internal_command == FAX_DISCONNECT_COMMAND_1)
  13087. plci->internal_command = FAX_DISCONNECT_COMMAND_3;
  13088. }
  13089. return;
  13090. }
  13091. }
  13092. static void rtp_connect_b3_req_command(dword Id, PLCI *plci, byte Rc)
  13093. {
  13094. word Info;
  13095. word internal_command;
  13096. dbug(1, dprintf("[%06lx] %s,%d: rtp_connect_b3_req_command %02x %04x",
  13097. UnMapId(Id), (char *)(FILE_), __LINE__, Rc, plci->internal_command));
  13098. Info = GOOD;
  13099. internal_command = plci->internal_command;
  13100. plci->internal_command = 0;
  13101. switch (internal_command)
  13102. {
  13103. default:
  13104. plci->command = 0; /* fall through */
  13105. case RTP_CONNECT_B3_REQ_COMMAND_1:
  13106. if (plci_nl_busy(plci))
  13107. {
  13108. plci->internal_command = RTP_CONNECT_B3_REQ_COMMAND_1;
  13109. return;
  13110. }
  13111. plci->internal_command = RTP_CONNECT_B3_REQ_COMMAND_2;
  13112. nl_req_ncci(plci, N_CONNECT, 0);
  13113. send_req(plci);
  13114. return;
  13115. case RTP_CONNECT_B3_REQ_COMMAND_2:
  13116. if ((Rc != OK) && (Rc != OK_FC))
  13117. {
  13118. dbug(1, dprintf("[%06lx] %s,%d: RTP setting connect info failed %02x",
  13119. UnMapId(Id), (char *)(FILE_), __LINE__, Rc));
  13120. Info = _WRONG_STATE;
  13121. break;
  13122. }
  13123. if (plci_nl_busy(plci))
  13124. {
  13125. plci->internal_command = RTP_CONNECT_B3_REQ_COMMAND_2;
  13126. return;
  13127. }
  13128. plci->internal_command = RTP_CONNECT_B3_REQ_COMMAND_3;
  13129. plci->NData[0].PLength = plci->internal_req_buffer[0];
  13130. plci->NData[0].P = plci->internal_req_buffer + 1;
  13131. plci->NL.X = plci->NData;
  13132. plci->NL.ReqCh = 0;
  13133. plci->NL.Req = plci->nl_req = (byte) N_UDATA;
  13134. plci->adapter->request(&plci->NL);
  13135. break;
  13136. case RTP_CONNECT_B3_REQ_COMMAND_3:
  13137. return;
  13138. }
  13139. sendf(plci->appl, _CONNECT_B3_R | CONFIRM, Id, plci->number, "w", Info);
  13140. }
  13141. static void rtp_connect_b3_res_command(dword Id, PLCI *plci, byte Rc)
  13142. {
  13143. word internal_command;
  13144. dbug(1, dprintf("[%06lx] %s,%d: rtp_connect_b3_res_command %02x %04x",
  13145. UnMapId(Id), (char *)(FILE_), __LINE__, Rc, plci->internal_command));
  13146. internal_command = plci->internal_command;
  13147. plci->internal_command = 0;
  13148. switch (internal_command)
  13149. {
  13150. default:
  13151. plci->command = 0; /* fall through */
  13152. case RTP_CONNECT_B3_RES_COMMAND_1:
  13153. if (plci_nl_busy(plci))
  13154. {
  13155. plci->internal_command = RTP_CONNECT_B3_RES_COMMAND_1;
  13156. return;
  13157. }
  13158. plci->internal_command = RTP_CONNECT_B3_RES_COMMAND_2;
  13159. nl_req_ncci(plci, N_CONNECT_ACK, (byte)(Id >> 16));
  13160. send_req(plci);
  13161. return;
  13162. case RTP_CONNECT_B3_RES_COMMAND_2:
  13163. if ((Rc != OK) && (Rc != OK_FC))
  13164. {
  13165. dbug(1, dprintf("[%06lx] %s,%d: RTP setting connect resp info failed %02x",
  13166. UnMapId(Id), (char *)(FILE_), __LINE__, Rc));
  13167. break;
  13168. }
  13169. if (plci_nl_busy(plci))
  13170. {
  13171. plci->internal_command = RTP_CONNECT_B3_RES_COMMAND_2;
  13172. return;
  13173. }
  13174. sendf(plci->appl, _CONNECT_B3_ACTIVE_I, Id, 0, "s", "");
  13175. plci->internal_command = RTP_CONNECT_B3_RES_COMMAND_3;
  13176. plci->NData[0].PLength = plci->internal_req_buffer[0];
  13177. plci->NData[0].P = plci->internal_req_buffer + 1;
  13178. plci->NL.X = plci->NData;
  13179. plci->NL.ReqCh = 0;
  13180. plci->NL.Req = plci->nl_req = (byte) N_UDATA;
  13181. plci->adapter->request(&plci->NL);
  13182. return;
  13183. case RTP_CONNECT_B3_RES_COMMAND_3:
  13184. return;
  13185. }
  13186. }
  13187. static void hold_save_command(dword Id, PLCI *plci, byte Rc)
  13188. {
  13189. byte SS_Ind[] = "\x05\x02\x00\x02\x00\x00"; /* Hold_Ind struct*/
  13190. word Info;
  13191. word internal_command;
  13192. dbug(1, dprintf("[%06lx] %s,%d: hold_save_command %02x %04x",
  13193. UnMapId(Id), (char *)(FILE_), __LINE__, Rc, plci->internal_command));
  13194. Info = GOOD;
  13195. internal_command = plci->internal_command;
  13196. plci->internal_command = 0;
  13197. switch (internal_command)
  13198. {
  13199. default:
  13200. if (!plci->NL.Id)
  13201. break;
  13202. plci->command = 0;
  13203. plci->adjust_b_parms_msg = NULL;
  13204. plci->adjust_b_facilities = plci->B1_facilities;
  13205. plci->adjust_b_command = HOLD_SAVE_COMMAND_1;
  13206. plci->adjust_b_ncci = (word)(Id >> 16);
  13207. plci->adjust_b_mode = ADJUST_B_MODE_SAVE | ADJUST_B_MODE_REMOVE_L23;
  13208. plci->adjust_b_state = ADJUST_B_START;
  13209. dbug(1, dprintf("[%06lx] %s,%d: HOLD save...",
  13210. UnMapId(Id), (char *)(FILE_), __LINE__));
  13211. /* fall through */
  13212. case HOLD_SAVE_COMMAND_1:
  13213. Info = adjust_b_process(Id, plci, Rc);
  13214. if (Info != GOOD)
  13215. {
  13216. dbug(1, dprintf("[%06lx] %s,%d: HOLD save failed",
  13217. UnMapId(Id), (char *)(FILE_), __LINE__));
  13218. break;
  13219. }
  13220. if (plci->internal_command)
  13221. return;
  13222. }
  13223. sendf(plci->appl, _FACILITY_I, Id & 0xffffL, 0, "ws", 3, SS_Ind);
  13224. }
  13225. static void retrieve_restore_command(dword Id, PLCI *plci, byte Rc)
  13226. {
  13227. byte SS_Ind[] = "\x05\x03\x00\x02\x00\x00"; /* Retrieve_Ind struct*/
  13228. word Info;
  13229. word internal_command;
  13230. dbug(1, dprintf("[%06lx] %s,%d: retrieve_restore_command %02x %04x",
  13231. UnMapId(Id), (char *)(FILE_), __LINE__, Rc, plci->internal_command));
  13232. Info = GOOD;
  13233. internal_command = plci->internal_command;
  13234. plci->internal_command = 0;
  13235. switch (internal_command)
  13236. {
  13237. default:
  13238. plci->command = 0;
  13239. plci->adjust_b_parms_msg = NULL;
  13240. plci->adjust_b_facilities = plci->B1_facilities;
  13241. plci->adjust_b_command = RETRIEVE_RESTORE_COMMAND_1;
  13242. plci->adjust_b_ncci = (word)(Id >> 16);
  13243. plci->adjust_b_mode = ADJUST_B_MODE_ASSIGN_L23 | ADJUST_B_MODE_USER_CONNECT | ADJUST_B_MODE_RESTORE;
  13244. plci->adjust_b_state = ADJUST_B_START;
  13245. dbug(1, dprintf("[%06lx] %s,%d: RETRIEVE restore...",
  13246. UnMapId(Id), (char *)(FILE_), __LINE__));
  13247. /* fall through */
  13248. case RETRIEVE_RESTORE_COMMAND_1:
  13249. Info = adjust_b_process(Id, plci, Rc);
  13250. if (Info != GOOD)
  13251. {
  13252. dbug(1, dprintf("[%06lx] %s,%d: RETRIEVE restore failed",
  13253. UnMapId(Id), (char *)(FILE_), __LINE__));
  13254. break;
  13255. }
  13256. if (plci->internal_command)
  13257. return;
  13258. }
  13259. sendf(plci->appl, _FACILITY_I, Id & 0xffffL, 0, "ws", 3, SS_Ind);
  13260. }
  13261. static void init_b1_config(PLCI *plci)
  13262. {
  13263. dbug(1, dprintf("[%06lx] %s,%d: init_b1_config",
  13264. (dword)((plci->Id << 8) | UnMapController(plci->adapter->Id)),
  13265. (char *)(FILE_), __LINE__));
  13266. plci->B1_resource = 0;
  13267. plci->B1_facilities = 0;
  13268. plci->li_bchannel_id = 0;
  13269. mixer_clear_config(plci);
  13270. ec_clear_config(plci);
  13271. dtmf_rec_clear_config(plci);
  13272. dtmf_send_clear_config(plci);
  13273. dtmf_parameter_clear_config(plci);
  13274. adv_voice_clear_config(plci);
  13275. adjust_b_clear(plci);
  13276. }
  13277. static void clear_b1_config(PLCI *plci)
  13278. {
  13279. dbug(1, dprintf("[%06lx] %s,%d: clear_b1_config",
  13280. (dword)((plci->Id << 8) | UnMapController(plci->adapter->Id)),
  13281. (char *)(FILE_), __LINE__));
  13282. adv_voice_clear_config(plci);
  13283. adjust_b_clear(plci);
  13284. ec_clear_config(plci);
  13285. dtmf_rec_clear_config(plci);
  13286. dtmf_send_clear_config(plci);
  13287. dtmf_parameter_clear_config(plci);
  13288. if ((plci->li_bchannel_id != 0)
  13289. && (li_config_table[plci->adapter->li_base + (plci->li_bchannel_id - 1)].plci == plci))
  13290. {
  13291. mixer_clear_config(plci);
  13292. li_config_table[plci->adapter->li_base + (plci->li_bchannel_id - 1)].plci = NULL;
  13293. plci->li_bchannel_id = 0;
  13294. }
  13295. plci->B1_resource = 0;
  13296. plci->B1_facilities = 0;
  13297. }
  13298. /* -----------------------------------------------------------------
  13299. XON protocol local helpers
  13300. ----------------------------------------------------------------- */
  13301. static void channel_flow_control_remove(PLCI *plci) {
  13302. DIVA_CAPI_ADAPTER *a = plci->adapter;
  13303. word i;
  13304. for (i = 1; i < MAX_NL_CHANNEL + 1; i++) {
  13305. if (a->ch_flow_plci[i] == plci->Id) {
  13306. a->ch_flow_plci[i] = 0;
  13307. a->ch_flow_control[i] = 0;
  13308. }
  13309. }
  13310. }
  13311. static void channel_x_on(PLCI *plci, byte ch) {
  13312. DIVA_CAPI_ADAPTER *a = plci->adapter;
  13313. if (a->ch_flow_control[ch] & N_XON_SENT) {
  13314. a->ch_flow_control[ch] &= ~N_XON_SENT;
  13315. }
  13316. }
  13317. static void channel_x_off(PLCI *plci, byte ch, byte flag) {
  13318. DIVA_CAPI_ADAPTER *a = plci->adapter;
  13319. if ((a->ch_flow_control[ch] & N_RX_FLOW_CONTROL_MASK) == 0) {
  13320. a->ch_flow_control[ch] |= (N_CH_XOFF | flag);
  13321. a->ch_flow_plci[ch] = plci->Id;
  13322. a->ch_flow_control_pending++;
  13323. }
  13324. }
  13325. static void channel_request_xon(PLCI *plci, byte ch) {
  13326. DIVA_CAPI_ADAPTER *a = plci->adapter;
  13327. if (a->ch_flow_control[ch] & N_CH_XOFF) {
  13328. a->ch_flow_control[ch] |= N_XON_REQ;
  13329. a->ch_flow_control[ch] &= ~N_CH_XOFF;
  13330. a->ch_flow_control[ch] &= ~N_XON_CONNECT_IND;
  13331. }
  13332. }
  13333. static void channel_xmit_extended_xon(PLCI *plci) {
  13334. DIVA_CAPI_ADAPTER *a;
  13335. int max_ch = ARRAY_SIZE(a->ch_flow_control);
  13336. int i, one_requested = 0;
  13337. if ((!plci) || (!plci->Id) || ((a = plci->adapter) == NULL)) {
  13338. return;
  13339. }
  13340. for (i = 0; i < max_ch; i++) {
  13341. if ((a->ch_flow_control[i] & N_CH_XOFF) &&
  13342. (a->ch_flow_control[i] & N_XON_CONNECT_IND) &&
  13343. (plci->Id == a->ch_flow_plci[i])) {
  13344. channel_request_xon(plci, (byte)i);
  13345. one_requested = 1;
  13346. }
  13347. }
  13348. if (one_requested) {
  13349. channel_xmit_xon(plci);
  13350. }
  13351. }
  13352. /*
  13353. Try to xmit next X_ON
  13354. */
  13355. static int find_channel_with_pending_x_on(DIVA_CAPI_ADAPTER *a, PLCI *plci) {
  13356. int max_ch = ARRAY_SIZE(a->ch_flow_control);
  13357. int i;
  13358. if (!(plci->adapter->manufacturer_features & MANUFACTURER_FEATURE_XONOFF_FLOW_CONTROL)) {
  13359. return (0);
  13360. }
  13361. if (a->last_flow_control_ch >= max_ch) {
  13362. a->last_flow_control_ch = 1;
  13363. }
  13364. for (i = a->last_flow_control_ch; i < max_ch; i++) {
  13365. if ((a->ch_flow_control[i] & N_XON_REQ) &&
  13366. (plci->Id == a->ch_flow_plci[i])) {
  13367. a->last_flow_control_ch = i + 1;
  13368. return (i);
  13369. }
  13370. }
  13371. for (i = 1; i < a->last_flow_control_ch; i++) {
  13372. if ((a->ch_flow_control[i] & N_XON_REQ) &&
  13373. (plci->Id == a->ch_flow_plci[i])) {
  13374. a->last_flow_control_ch = i + 1;
  13375. return (i);
  13376. }
  13377. }
  13378. return (0);
  13379. }
  13380. static void channel_xmit_xon(PLCI *plci) {
  13381. DIVA_CAPI_ADAPTER *a = plci->adapter;
  13382. byte ch;
  13383. if (plci->nl_req || !plci->NL.Id || plci->nl_remove_id) {
  13384. return;
  13385. }
  13386. if ((ch = (byte)find_channel_with_pending_x_on(a, plci)) == 0) {
  13387. return;
  13388. }
  13389. a->ch_flow_control[ch] &= ~N_XON_REQ;
  13390. a->ch_flow_control[ch] |= N_XON_SENT;
  13391. plci->NL.Req = plci->nl_req = (byte)N_XON;
  13392. plci->NL.ReqCh = ch;
  13393. plci->NL.X = plci->NData;
  13394. plci->NL.XNum = 1;
  13395. plci->NData[0].P = &plci->RBuffer[0];
  13396. plci->NData[0].PLength = 0;
  13397. plci->adapter->request(&plci->NL);
  13398. }
  13399. static int channel_can_xon(PLCI *plci, byte ch) {
  13400. APPL *APPLptr;
  13401. DIVA_CAPI_ADAPTER *a;
  13402. word NCCIcode;
  13403. dword count;
  13404. word Num;
  13405. word i;
  13406. APPLptr = plci->appl;
  13407. a = plci->adapter;
  13408. if (!APPLptr)
  13409. return (0);
  13410. NCCIcode = a->ch_ncci[ch] | (((word) a->Id) << 8);
  13411. /* count all buffers within the Application pool */
  13412. /* belonging to the same NCCI. XON if a first is */
  13413. /* used. */
  13414. count = 0;
  13415. Num = 0xffff;
  13416. for (i = 0; i < APPLptr->MaxBuffer; i++) {
  13417. if (NCCIcode == APPLptr->DataNCCI[i]) count++;
  13418. if (!APPLptr->DataNCCI[i] && Num == 0xffff) Num = i;
  13419. }
  13420. if ((count > 2) || (Num == 0xffff)) {
  13421. return (0);
  13422. }
  13423. return (1);
  13424. }
  13425. /*------------------------------------------------------------------*/
  13426. static word CPN_filter_ok(byte *cpn, DIVA_CAPI_ADAPTER *a, word offset)
  13427. {
  13428. return 1;
  13429. }
  13430. /**********************************************************************************/
  13431. /* function groups the listening applications according to the CIP mask and the */
  13432. /* Info_Mask. Each group gets just one Connect_Ind. Some application manufacturer */
  13433. /* are not multi-instance capable, so they start e.g. 30 applications what causes */
  13434. /* big problems on application level (one call, 30 Connect_Ind, ect). The */
  13435. /* function must be enabled by setting "a->group_optimization_enabled" from the */
  13436. /* OS specific part (per adapter). */
  13437. /**********************************************************************************/
  13438. static void group_optimization(DIVA_CAPI_ADAPTER *a, PLCI *plci)
  13439. {
  13440. word i, j, k, busy, group_found;
  13441. dword info_mask_group[MAX_CIP_TYPES];
  13442. dword cip_mask_group[MAX_CIP_TYPES];
  13443. word appl_number_group_type[MAX_APPL];
  13444. PLCI *auxplci;
  13445. /* all APPLs within this inc. call are allowed to dial in */
  13446. bitmap_fill(plci->group_optimization_mask_table, MAX_APPL);
  13447. if (!a->group_optimization_enabled)
  13448. {
  13449. dbug(1, dprintf("No group optimization"));
  13450. return;
  13451. }
  13452. dbug(1, dprintf("Group optimization = 0x%x...", a->group_optimization_enabled));
  13453. for (i = 0; i < MAX_CIP_TYPES; i++)
  13454. {
  13455. info_mask_group[i] = 0;
  13456. cip_mask_group[i] = 0;
  13457. }
  13458. for (i = 0; i < MAX_APPL; i++)
  13459. {
  13460. appl_number_group_type[i] = 0;
  13461. }
  13462. for (i = 0; i < max_appl; i++) /* check if any multi instance capable application is present */
  13463. { /* group_optimization set to 1 means not to optimize multi-instance capable applications (default) */
  13464. if (application[i].Id && (application[i].MaxNCCI) > 1 && (a->CIP_Mask[i]) && (a->group_optimization_enabled == 1))
  13465. {
  13466. dbug(1, dprintf("Multi-Instance capable, no optimization required"));
  13467. return; /* allow good application unfiltered access */
  13468. }
  13469. }
  13470. for (i = 0; i < max_appl; i++) /* Build CIP Groups */
  13471. {
  13472. if (application[i].Id && a->CIP_Mask[i])
  13473. {
  13474. for (k = 0, busy = false; k < a->max_plci; k++)
  13475. {
  13476. if (a->plci[k].Id)
  13477. {
  13478. auxplci = &a->plci[k];
  13479. if (auxplci->appl == &application[i]) {
  13480. /* application has a busy PLCI */
  13481. busy = true;
  13482. dbug(1, dprintf("Appl 0x%x is busy", i + 1));
  13483. } else if (test_bit(i, plci->c_ind_mask_table)) {
  13484. /* application has an incoming call pending */
  13485. busy = true;
  13486. dbug(1, dprintf("Appl 0x%x has inc. call pending", i + 1));
  13487. }
  13488. }
  13489. }
  13490. for (j = 0, group_found = 0; j <= (MAX_CIP_TYPES) && !busy && !group_found; j++) /* build groups with free applications only */
  13491. {
  13492. if (j == MAX_CIP_TYPES) /* all groups are in use but group still not found */
  13493. { /* the MAX_CIP_TYPES group enables all calls because of field overflow */
  13494. appl_number_group_type[i] = MAX_CIP_TYPES;
  13495. group_found = true;
  13496. dbug(1, dprintf("Field overflow appl 0x%x", i + 1));
  13497. }
  13498. else if ((info_mask_group[j] == a->CIP_Mask[i]) && (cip_mask_group[j] == a->Info_Mask[i]))
  13499. { /* is group already present ? */
  13500. appl_number_group_type[i] = j | 0x80; /* store the group number for each application */
  13501. group_found = true;
  13502. 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]));
  13503. }
  13504. else if (!info_mask_group[j])
  13505. { /* establish a new group */
  13506. appl_number_group_type[i] = j | 0x80; /* store the group number for each application */
  13507. info_mask_group[j] = a->CIP_Mask[i]; /* store the new CIP mask for the new group */
  13508. cip_mask_group[j] = a->Info_Mask[i]; /* store the new Info_Mask for this new group */
  13509. group_found = true;
  13510. 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]));
  13511. }
  13512. }
  13513. }
  13514. }
  13515. for (i = 0; i < max_appl; i++) /* Build group_optimization_mask_table */
  13516. {
  13517. if (appl_number_group_type[i]) /* application is free, has listens and is member of a group */
  13518. {
  13519. if (appl_number_group_type[i] == MAX_CIP_TYPES)
  13520. {
  13521. dbug(1, dprintf("OverflowGroup 0x%x, valid appl = 0x%x, call enabled", appl_number_group_type[i], i + 1));
  13522. }
  13523. else
  13524. {
  13525. dbug(1, dprintf("Group 0x%x, valid appl = 0x%x", appl_number_group_type[i], i + 1));
  13526. for (j = i + 1; j < max_appl; j++) /* search other group members and mark them as busy */
  13527. {
  13528. if (appl_number_group_type[i] == appl_number_group_type[j])
  13529. {
  13530. dbug(1, dprintf("Appl 0x%x is member of group 0x%x, no call", j + 1, appl_number_group_type[j]));
  13531. /* disable call on other group members */
  13532. __clear_bit(j, plci->group_optimization_mask_table);
  13533. appl_number_group_type[j] = 0; /* remove disabled group member from group list */
  13534. }
  13535. }
  13536. }
  13537. }
  13538. else /* application should not get a call */
  13539. {
  13540. __clear_bit(i, plci->group_optimization_mask_table);
  13541. }
  13542. }
  13543. }
  13544. /* OS notifies the driver about a application Capi_Register */
  13545. word CapiRegister(word id)
  13546. {
  13547. word i, j, appls_found;
  13548. PLCI *plci;
  13549. DIVA_CAPI_ADAPTER *a;
  13550. for (i = 0, appls_found = 0; i < max_appl; i++)
  13551. {
  13552. if (application[i].Id && (application[i].Id != id))
  13553. {
  13554. appls_found++; /* an application has been found */
  13555. }
  13556. }
  13557. if (appls_found) return true;
  13558. for (i = 0; i < max_adapter; i++) /* scan all adapters... */
  13559. {
  13560. a = &adapter[i];
  13561. if (a->request)
  13562. {
  13563. if (a->flag_dynamic_l1_down) /* remove adapter from L1 tristate (Huntgroup) */
  13564. {
  13565. if (!appls_found) /* first application does a capi register */
  13566. {
  13567. if ((j = get_plci(a))) /* activate L1 of all adapters */
  13568. {
  13569. plci = &a->plci[j - 1];
  13570. plci->command = 0;
  13571. add_p(plci, OAD, "\x01\xfd");
  13572. add_p(plci, CAI, "\x01\x80");
  13573. add_p(plci, UID, "\x06\x43\x61\x70\x69\x32\x30");
  13574. add_p(plci, SHIFT | 6, NULL);
  13575. add_p(plci, SIN, "\x02\x00\x00");
  13576. plci->internal_command = START_L1_SIG_ASSIGN_PEND;
  13577. sig_req(plci, ASSIGN, DSIG_ID);
  13578. add_p(plci, FTY, "\x02\xff\x07"); /* l1 start */
  13579. sig_req(plci, SIG_CTRL, 0);
  13580. send_req(plci);
  13581. }
  13582. }
  13583. }
  13584. }
  13585. }
  13586. return false;
  13587. }
  13588. /*------------------------------------------------------------------*/
  13589. /* Functions for virtual Switching e.g. Transfer by join, Conference */
  13590. static void VSwitchReqInd(PLCI *plci, dword Id, byte **parms)
  13591. {
  13592. word i;
  13593. /* Format of vswitch_t:
  13594. 0 byte length
  13595. 1 byte VSWITCHIE
  13596. 2 byte VSWITCH_REQ/VSWITCH_IND
  13597. 3 byte reserved
  13598. 4 word VSwitchcommand
  13599. 6 word returnerror
  13600. 8... Params
  13601. */
  13602. if (!plci ||
  13603. !plci->appl ||
  13604. !plci->State ||
  13605. plci->Sig.Ind == NCR_FACILITY
  13606. )
  13607. return;
  13608. for (i = 0; i < MAX_MULTI_IE; i++)
  13609. {
  13610. if (!parms[i][0]) continue;
  13611. if (parms[i][0] < 7)
  13612. {
  13613. parms[i][0] = 0; /* kill it */
  13614. continue;
  13615. }
  13616. dbug(1, dprintf("VSwitchReqInd(%d)", parms[i][4]));
  13617. switch (parms[i][4])
  13618. {
  13619. case VSJOIN:
  13620. if (!plci->relatedPTYPLCI ||
  13621. (plci->ptyState != S_ECT && plci->relatedPTYPLCI->ptyState != S_ECT))
  13622. { /* Error */
  13623. break;
  13624. }
  13625. /* remember all necessary informations */
  13626. if (parms[i][0] != 11 || parms[i][8] != 3) /* Length Test */
  13627. {
  13628. break;
  13629. }
  13630. if (parms[i][2] == VSWITCH_IND && parms[i][9] == 1)
  13631. { /* first indication after ECT-Request on Consultation Call */
  13632. plci->vswitchstate = parms[i][9];
  13633. parms[i][9] = 2; /* State */
  13634. /* now ask first Call to join */
  13635. }
  13636. else if (parms[i][2] == VSWITCH_REQ && parms[i][9] == 3)
  13637. { /* Answer of VSWITCH_REQ from first Call */
  13638. plci->vswitchstate = parms[i][9];
  13639. /* tell consultation call to join
  13640. and the protocol capabilities of the first call */
  13641. }
  13642. else
  13643. { /* Error */
  13644. break;
  13645. }
  13646. plci->vsprot = parms[i][10]; /* protocol */
  13647. plci->vsprotdialect = parms[i][11]; /* protocoldialect */
  13648. /* send join request to related PLCI */
  13649. parms[i][1] = VSWITCHIE;
  13650. parms[i][2] = VSWITCH_REQ;
  13651. plci->relatedPTYPLCI->command = 0;
  13652. plci->relatedPTYPLCI->internal_command = VSWITCH_REQ_PEND;
  13653. add_p(plci->relatedPTYPLCI, ESC, &parms[i][0]);
  13654. sig_req(plci->relatedPTYPLCI, VSWITCH_REQ, 0);
  13655. send_req(plci->relatedPTYPLCI);
  13656. break;
  13657. case VSTRANSPORT:
  13658. default:
  13659. if (plci->relatedPTYPLCI &&
  13660. plci->vswitchstate == 3 &&
  13661. plci->relatedPTYPLCI->vswitchstate == 3)
  13662. {
  13663. add_p(plci->relatedPTYPLCI, ESC, &parms[i][0]);
  13664. sig_req(plci->relatedPTYPLCI, VSWITCH_REQ, 0);
  13665. send_req(plci->relatedPTYPLCI);
  13666. }
  13667. break;
  13668. }
  13669. parms[i][0] = 0; /* kill it */
  13670. }
  13671. }
  13672. /*------------------------------------------------------------------*/
  13673. static int diva_get_dma_descriptor(PLCI *plci, dword *dma_magic) {
  13674. ENTITY e;
  13675. IDI_SYNC_REQ *pReq = (IDI_SYNC_REQ *)&e;
  13676. if (!(diva_xdi_extended_features & DIVA_CAPI_XDI_PROVIDES_RX_DMA)) {
  13677. return (-1);
  13678. }
  13679. pReq->xdi_dma_descriptor_operation.Req = 0;
  13680. pReq->xdi_dma_descriptor_operation.Rc = IDI_SYNC_REQ_DMA_DESCRIPTOR_OPERATION;
  13681. pReq->xdi_dma_descriptor_operation.info.operation = IDI_SYNC_REQ_DMA_DESCRIPTOR_ALLOC;
  13682. pReq->xdi_dma_descriptor_operation.info.descriptor_number = -1;
  13683. pReq->xdi_dma_descriptor_operation.info.descriptor_address = NULL;
  13684. pReq->xdi_dma_descriptor_operation.info.descriptor_magic = 0;
  13685. e.user[0] = plci->adapter->Id - 1;
  13686. plci->adapter->request((ENTITY *)pReq);
  13687. if (!pReq->xdi_dma_descriptor_operation.info.operation &&
  13688. (pReq->xdi_dma_descriptor_operation.info.descriptor_number >= 0) &&
  13689. pReq->xdi_dma_descriptor_operation.info.descriptor_magic) {
  13690. *dma_magic = pReq->xdi_dma_descriptor_operation.info.descriptor_magic;
  13691. dbug(3, dprintf("dma_alloc, a:%d (%d-%08x)",
  13692. plci->adapter->Id,
  13693. pReq->xdi_dma_descriptor_operation.info.descriptor_number,
  13694. *dma_magic));
  13695. return (pReq->xdi_dma_descriptor_operation.info.descriptor_number);
  13696. } else {
  13697. dbug(1, dprintf("dma_alloc failed"));
  13698. return (-1);
  13699. }
  13700. }
  13701. static void diva_free_dma_descriptor(PLCI *plci, int nr) {
  13702. ENTITY e;
  13703. IDI_SYNC_REQ *pReq = (IDI_SYNC_REQ *)&e;
  13704. if (nr < 0) {
  13705. return;
  13706. }
  13707. pReq->xdi_dma_descriptor_operation.Req = 0;
  13708. pReq->xdi_dma_descriptor_operation.Rc = IDI_SYNC_REQ_DMA_DESCRIPTOR_OPERATION;
  13709. pReq->xdi_dma_descriptor_operation.info.operation = IDI_SYNC_REQ_DMA_DESCRIPTOR_FREE;
  13710. pReq->xdi_dma_descriptor_operation.info.descriptor_number = nr;
  13711. pReq->xdi_dma_descriptor_operation.info.descriptor_address = NULL;
  13712. pReq->xdi_dma_descriptor_operation.info.descriptor_magic = 0;
  13713. e.user[0] = plci->adapter->Id - 1;
  13714. plci->adapter->request((ENTITY *)pReq);
  13715. if (!pReq->xdi_dma_descriptor_operation.info.operation) {
  13716. dbug(1, dprintf("dma_free(%d)", nr));
  13717. } else {
  13718. dbug(1, dprintf("dma_free failed (%d)", nr));
  13719. }
  13720. }
  13721. /*------------------------------------------------------------------*/