message.c 436 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686668766886689669066916692669366946695669666976698669967006701670267036704670567066707670867096710671167126713671467156716671767186719672067216722672367246725672667276728672967306731673267336734673567366737673867396740674167426743674467456746674767486749675067516752675367546755675667576758675967606761676267636764676567666767676867696770677167726773677467756776677767786779678067816782678367846785678667876788678967906791679267936794679567966797679867996800680168026803680468056806680768086809681068116812681368146815681668176818681968206821682268236824682568266827682868296830683168326833683468356836683768386839684068416842684368446845684668476848684968506851685268536854685568566857685868596860686168626863686468656866686768686869687068716872687368746875687668776878687968806881688268836884688568866887688868896890689168926893689468956896689768986899690069016902690369046905690669076908690969106911691269136914691569166917691869196920692169226923692469256926692769286929693069316932693369346935693669376938693969406941694269436944694569466947694869496950695169526953695469556956695769586959696069616962696369646965696669676968696969706971697269736974697569766977697869796980698169826983698469856986698769886989699069916992699369946995699669976998699970007001700270037004700570067007700870097010701170127013701470157016701770187019702070217022702370247025702670277028702970307031703270337034703570367037703870397040704170427043704470457046704770487049705070517052705370547055705670577058705970607061706270637064706570667067706870697070707170727073707470757076707770787079708070817082708370847085708670877088708970907091709270937094709570967097709870997100710171027103710471057106710771087109711071117112711371147115711671177118711971207121712271237124712571267127712871297130713171327133713471357136713771387139714071417142714371447145714671477148714971507151715271537154715571567157715871597160716171627163716471657166716771687169717071717172717371747175717671777178717971807181718271837184718571867187718871897190719171927193719471957196719771987199720072017202720372047205720672077208720972107211721272137214721572167217721872197220722172227223722472257226722772287229723072317232723372347235723672377238723972407241724272437244724572467247724872497250725172527253725472557256725772587259726072617262726372647265726672677268726972707271727272737274727572767277727872797280728172827283728472857286728772887289729072917292729372947295729672977298729973007301730273037304730573067307730873097310731173127313731473157316731773187319732073217322732373247325732673277328732973307331733273337334733573367337733873397340734173427343734473457346734773487349735073517352735373547355735673577358735973607361736273637364736573667367736873697370737173727373737473757376737773787379738073817382738373847385738673877388738973907391739273937394739573967397739873997400740174027403740474057406740774087409741074117412741374147415741674177418741974207421742274237424742574267427742874297430743174327433743474357436743774387439744074417442744374447445744674477448744974507451745274537454745574567457745874597460746174627463746474657466746774687469747074717472747374747475747674777478747974807481748274837484748574867487748874897490749174927493749474957496749774987499750075017502750375047505750675077508750975107511751275137514751575167517751875197520752175227523752475257526752775287529753075317532753375347535753675377538753975407541754275437544754575467547754875497550755175527553755475557556755775587559756075617562756375647565756675677568756975707571757275737574757575767577757875797580758175827583758475857586758775887589759075917592759375947595759675977598759976007601760276037604760576067607760876097610761176127613761476157616761776187619762076217622762376247625762676277628762976307631763276337634763576367637763876397640764176427643764476457646764776487649765076517652765376547655765676577658765976607661766276637664766576667667766876697670767176727673767476757676767776787679768076817682768376847685768676877688768976907691769276937694769576967697769876997700770177027703770477057706770777087709771077117712771377147715771677177718771977207721772277237724772577267727772877297730773177327733773477357736773777387739774077417742774377447745774677477748774977507751775277537754775577567757775877597760776177627763776477657766776777687769777077717772777377747775777677777778777977807781778277837784778577867787778877897790779177927793779477957796779777987799780078017802780378047805780678077808780978107811781278137814781578167817781878197820782178227823782478257826782778287829783078317832783378347835783678377838783978407841784278437844784578467847784878497850785178527853785478557856785778587859786078617862786378647865786678677868786978707871787278737874787578767877787878797880788178827883788478857886788778887889789078917892789378947895789678977898789979007901790279037904790579067907790879097910791179127913791479157916791779187919792079217922792379247925792679277928792979307931793279337934793579367937793879397940794179427943794479457946794779487949795079517952795379547955795679577958795979607961796279637964796579667967796879697970797179727973797479757976797779787979798079817982798379847985798679877988798979907991799279937994799579967997799879998000800180028003800480058006800780088009801080118012801380148015801680178018801980208021802280238024802580268027802880298030803180328033803480358036803780388039804080418042804380448045804680478048804980508051805280538054805580568057805880598060806180628063806480658066806780688069807080718072807380748075807680778078807980808081808280838084808580868087808880898090809180928093809480958096809780988099810081018102810381048105810681078108810981108111811281138114811581168117811881198120812181228123812481258126812781288129813081318132813381348135813681378138813981408141814281438144814581468147814881498150815181528153815481558156815781588159816081618162816381648165816681678168816981708171817281738174817581768177817881798180818181828183818481858186818781888189819081918192819381948195819681978198819982008201820282038204820582068207820882098210821182128213821482158216821782188219822082218222822382248225822682278228822982308231823282338234823582368237823882398240824182428243824482458246824782488249825082518252825382548255825682578258825982608261826282638264826582668267826882698270827182728273827482758276827782788279828082818282828382848285828682878288828982908291829282938294829582968297829882998300830183028303830483058306830783088309831083118312831383148315831683178318831983208321832283238324832583268327832883298330833183328333833483358336833783388339834083418342834383448345834683478348834983508351835283538354835583568357835883598360836183628363836483658366836783688369837083718372837383748375837683778378837983808381838283838384838583868387838883898390839183928393839483958396839783988399840084018402840384048405840684078408840984108411841284138414841584168417841884198420842184228423842484258426842784288429843084318432843384348435843684378438843984408441844284438444844584468447844884498450845184528453845484558456845784588459846084618462846384648465846684678468846984708471847284738474847584768477847884798480848184828483848484858486848784888489849084918492849384948495849684978498849985008501850285038504850585068507850885098510851185128513851485158516851785188519852085218522852385248525852685278528852985308531853285338534853585368537853885398540854185428543854485458546854785488549855085518552855385548555855685578558855985608561856285638564856585668567856885698570857185728573857485758576857785788579858085818582858385848585858685878588858985908591859285938594859585968597859885998600860186028603860486058606860786088609861086118612861386148615861686178618861986208621862286238624862586268627862886298630863186328633863486358636863786388639864086418642864386448645864686478648864986508651865286538654865586568657865886598660866186628663866486658666866786688669867086718672867386748675867686778678867986808681868286838684868586868687868886898690869186928693869486958696869786988699870087018702870387048705870687078708870987108711871287138714871587168717871887198720872187228723872487258726872787288729873087318732873387348735873687378738873987408741874287438744874587468747874887498750875187528753875487558756875787588759876087618762876387648765876687678768876987708771877287738774877587768777877887798780878187828783878487858786878787888789879087918792879387948795879687978798879988008801880288038804880588068807880888098810881188128813881488158816881788188819882088218822882388248825882688278828882988308831883288338834883588368837883888398840884188428843884488458846884788488849885088518852885388548855885688578858885988608861886288638864886588668867886888698870887188728873887488758876887788788879888088818882888388848885888688878888888988908891889288938894889588968897889888998900890189028903890489058906890789088909891089118912891389148915891689178918891989208921892289238924892589268927892889298930893189328933893489358936893789388939894089418942894389448945894689478948894989508951895289538954895589568957895889598960896189628963896489658966896789688969897089718972897389748975897689778978897989808981898289838984898589868987898889898990899189928993899489958996899789988999900090019002900390049005900690079008900990109011901290139014901590169017901890199020902190229023902490259026902790289029903090319032903390349035903690379038903990409041904290439044904590469047904890499050905190529053905490559056905790589059906090619062906390649065906690679068906990709071907290739074907590769077907890799080908190829083908490859086908790889089909090919092909390949095909690979098909991009101910291039104910591069107910891099110911191129113911491159116911791189119912091219122912391249125912691279128912991309131913291339134913591369137913891399140914191429143914491459146914791489149915091519152915391549155915691579158915991609161916291639164916591669167916891699170917191729173917491759176917791789179918091819182918391849185918691879188918991909191919291939194919591969197919891999200920192029203920492059206920792089209921092119212921392149215921692179218921992209221922292239224922592269227922892299230923192329233923492359236923792389239924092419242924392449245924692479248924992509251925292539254925592569257925892599260926192629263926492659266926792689269927092719272927392749275927692779278927992809281928292839284928592869287928892899290929192929293929492959296929792989299930093019302930393049305930693079308930993109311931293139314931593169317931893199320932193229323932493259326932793289329933093319332933393349335933693379338933993409341934293439344934593469347934893499350935193529353935493559356935793589359936093619362936393649365936693679368936993709371937293739374937593769377937893799380938193829383938493859386938793889389939093919392939393949395939693979398939994009401940294039404940594069407940894099410941194129413941494159416941794189419942094219422942394249425942694279428942994309431943294339434943594369437943894399440944194429443944494459446944794489449945094519452945394549455945694579458945994609461946294639464946594669467946894699470947194729473947494759476947794789479948094819482948394849485948694879488948994909491949294939494949594969497949894999500950195029503950495059506950795089509951095119512951395149515951695179518951995209521952295239524952595269527952895299530953195329533953495359536953795389539954095419542954395449545954695479548954995509551955295539554955595569557955895599560956195629563956495659566956795689569957095719572957395749575957695779578957995809581958295839584958595869587958895899590959195929593959495959596959795989599960096019602960396049605960696079608960996109611961296139614961596169617961896199620962196229623962496259626962796289629963096319632963396349635963696379638963996409641964296439644964596469647964896499650965196529653965496559656965796589659966096619662966396649665966696679668966996709671967296739674967596769677967896799680968196829683968496859686968796889689969096919692969396949695969696979698969997009701970297039704970597069707970897099710971197129713971497159716971797189719972097219722972397249725972697279728972997309731973297339734973597369737973897399740974197429743974497459746974797489749975097519752975397549755975697579758975997609761976297639764976597669767976897699770977197729773977497759776977797789779978097819782978397849785978697879788978997909791979297939794979597969797979897999800980198029803980498059806980798089809981098119812981398149815981698179818981998209821982298239824982598269827982898299830983198329833983498359836983798389839984098419842984398449845984698479848984998509851985298539854985598569857985898599860986198629863986498659866986798689869987098719872987398749875987698779878987998809881988298839884988598869887988898899890989198929893989498959896989798989899990099019902990399049905990699079908990999109911991299139914991599169917991899199920992199229923992499259926992799289929993099319932993399349935993699379938993999409941994299439944994599469947994899499950995199529953995499559956995799589959996099619962996399649965996699679968996999709971997299739974997599769977997899799980998199829983998499859986998799889989999099919992999399949995999699979998999910000100011000210003100041000510006100071000810009100101001110012100131001410015100161001710018100191002010021100221002310024100251002610027100281002910030100311003210033100341003510036100371003810039100401004110042100431004410045100461004710048100491005010051100521005310054100551005610057100581005910060100611006210063100641006510066100671006810069100701007110072100731007410075100761007710078100791008010081100821008310084100851008610087100881008910090100911009210093100941009510096100971009810099101001010110102101031010410105101061010710108101091011010111101121011310114101151011610117101181011910120101211012210123101241012510126101271012810129101301013110132101331013410135101361013710138101391014010141101421014310144101451014610147101481014910150101511015210153101541015510156101571015810159101601016110162101631016410165101661016710168101691017010171101721017310174101751017610177101781017910180101811018210183101841018510186101871018810189101901019110192101931019410195101961019710198101991020010201102021020310204102051020610207102081020910210102111021210213102141021510216102171021810219102201022110222102231022410225102261022710228102291023010231102321023310234102351023610237102381023910240102411024210243102441024510246102471024810249102501025110252102531025410255102561025710258102591026010261102621026310264102651026610267102681026910270102711027210273102741027510276102771027810279102801028110282102831028410285102861028710288102891029010291102921029310294102951029610297102981029910300103011030210303103041030510306103071030810309103101031110312103131031410315103161031710318103191032010321103221032310324103251032610327103281032910330103311033210333103341033510336103371033810339103401034110342103431034410345103461034710348103491035010351103521035310354103551035610357103581035910360103611036210363103641036510366103671036810369103701037110372103731037410375103761037710378103791038010381103821038310384103851038610387103881038910390103911039210393103941039510396103971039810399104001040110402104031040410405104061040710408104091041010411104121041310414104151041610417104181041910420104211042210423104241042510426104271042810429104301043110432104331043410435104361043710438104391044010441104421044310444104451044610447104481044910450104511045210453104541045510456104571045810459104601046110462104631046410465104661046710468104691047010471104721047310474104751047610477104781047910480104811048210483104841048510486104871048810489104901049110492104931049410495104961049710498104991050010501105021050310504105051050610507105081050910510105111051210513105141051510516105171051810519105201052110522105231052410525105261052710528105291053010531105321053310534105351053610537105381053910540105411054210543105441054510546105471054810549105501055110552105531055410555105561055710558105591056010561105621056310564105651056610567105681056910570105711057210573105741057510576105771057810579105801058110582105831058410585105861058710588105891059010591105921059310594105951059610597105981059910600106011060210603106041060510606106071060810609106101061110612106131061410615106161061710618106191062010621106221062310624106251062610627106281062910630106311063210633106341063510636106371063810639106401064110642106431064410645106461064710648106491065010651106521065310654106551065610657106581065910660106611066210663106641066510666106671066810669106701067110672106731067410675106761067710678106791068010681106821068310684106851068610687106881068910690106911069210693106941069510696106971069810699107001070110702107031070410705107061070710708107091071010711107121071310714107151071610717107181071910720107211072210723107241072510726107271072810729107301073110732107331073410735107361073710738107391074010741107421074310744107451074610747107481074910750107511075210753107541075510756107571075810759107601076110762107631076410765107661076710768107691077010771107721077310774107751077610777107781077910780107811078210783107841078510786107871078810789107901079110792107931079410795107961079710798107991080010801108021080310804108051080610807108081080910810108111081210813108141081510816108171081810819108201082110822108231082410825108261082710828108291083010831108321083310834108351083610837108381083910840108411084210843108441084510846108471084810849108501085110852108531085410855108561085710858108591086010861108621086310864108651086610867108681086910870108711087210873108741087510876108771087810879108801088110882108831088410885108861088710888108891089010891108921089310894108951089610897108981089910900109011090210903109041090510906109071090810909109101091110912109131091410915109161091710918109191092010921109221092310924109251092610927109281092910930109311093210933109341093510936109371093810939109401094110942109431094410945109461094710948109491095010951109521095310954109551095610957109581095910960109611096210963109641096510966109671096810969109701097110972109731097410975109761097710978109791098010981109821098310984109851098610987109881098910990109911099210993109941099510996109971099810999110001100111002110031100411005110061100711008110091101011011110121101311014110151101611017110181101911020110211102211023110241102511026110271102811029110301103111032110331103411035110361103711038110391104011041110421104311044110451104611047110481104911050110511105211053110541105511056110571105811059110601106111062110631106411065110661106711068110691107011071110721107311074110751107611077110781107911080110811108211083110841108511086110871108811089110901109111092110931109411095110961109711098110991110011101111021110311104111051110611107111081110911110111111111211113111141111511116111171111811119111201112111122111231112411125111261112711128111291113011131111321113311134111351113611137111381113911140111411114211143111441114511146111471114811149111501115111152111531115411155111561115711158111591116011161111621116311164111651116611167111681116911170111711117211173111741117511176111771117811179111801118111182111831118411185111861118711188111891119011191111921119311194111951119611197111981119911200112011120211203112041120511206112071120811209112101121111212112131121411215112161121711218112191122011221112221122311224112251122611227112281122911230112311123211233112341123511236112371123811239112401124111242112431124411245112461124711248112491125011251112521125311254112551125611257112581125911260112611126211263112641126511266112671126811269112701127111272112731127411275112761127711278112791128011281112821128311284112851128611287112881128911290112911129211293112941129511296112971129811299113001130111302113031130411305113061130711308113091131011311113121131311314113151131611317113181131911320113211132211323113241132511326113271132811329113301133111332113331133411335113361133711338113391134011341113421134311344113451134611347113481134911350113511135211353113541135511356113571135811359113601136111362113631136411365113661136711368113691137011371113721137311374113751137611377113781137911380113811138211383113841138511386113871138811389113901139111392113931139411395113961139711398113991140011401114021140311404114051140611407114081140911410114111141211413114141141511416114171141811419114201142111422114231142411425114261142711428114291143011431114321143311434114351143611437114381143911440114411144211443114441144511446114471144811449114501145111452114531145411455114561145711458114591146011461114621146311464114651146611467114681146911470114711147211473114741147511476114771147811479114801148111482114831148411485114861148711488114891149011491114921149311494114951149611497114981149911500115011150211503115041150511506115071150811509115101151111512115131151411515115161151711518115191152011521115221152311524115251152611527115281152911530115311153211533115341153511536115371153811539115401154111542115431154411545115461154711548115491155011551115521155311554115551155611557115581155911560115611156211563115641156511566115671156811569115701157111572115731157411575115761157711578115791158011581115821158311584115851158611587115881158911590115911159211593115941159511596115971159811599116001160111602116031160411605116061160711608116091161011611116121161311614116151161611617116181161911620116211162211623116241162511626116271162811629116301163111632116331163411635116361163711638116391164011641116421164311644116451164611647116481164911650116511165211653116541165511656116571165811659116601166111662116631166411665116661166711668116691167011671116721167311674116751167611677116781167911680116811168211683116841168511686116871168811689116901169111692116931169411695116961169711698116991170011701117021170311704117051170611707117081170911710117111171211713117141171511716117171171811719117201172111722117231172411725117261172711728117291173011731117321173311734117351173611737117381173911740117411174211743117441174511746117471174811749117501175111752117531175411755117561175711758117591176011761117621176311764117651176611767117681176911770117711177211773117741177511776117771177811779117801178111782117831178411785117861178711788117891179011791117921179311794117951179611797117981179911800118011180211803118041180511806118071180811809118101181111812118131181411815118161181711818118191182011821118221182311824118251182611827118281182911830118311183211833118341183511836118371183811839118401184111842118431184411845118461184711848118491185011851118521185311854118551185611857118581185911860118611186211863118641186511866118671186811869118701187111872118731187411875118761187711878118791188011881118821188311884118851188611887118881188911890118911189211893118941189511896118971189811899119001190111902119031190411905119061190711908119091191011911119121191311914119151191611917119181191911920119211192211923119241192511926119271192811929119301193111932119331193411935119361193711938119391194011941119421194311944119451194611947119481194911950119511195211953119541195511956119571195811959119601196111962119631196411965119661196711968119691197011971119721197311974119751197611977119781197911980119811198211983119841198511986119871198811989119901199111992119931199411995119961199711998119991200012001120021200312004120051200612007120081200912010120111201212013120141201512016120171201812019120201202112022120231202412025120261202712028120291203012031120321203312034120351203612037120381203912040120411204212043120441204512046120471204812049120501205112052120531205412055120561205712058120591206012061120621206312064120651206612067120681206912070120711207212073120741207512076120771207812079120801208112082120831208412085120861208712088120891209012091120921209312094120951209612097120981209912100121011210212103121041210512106121071210812109121101211112112121131211412115121161211712118121191212012121121221212312124121251212612127121281212912130121311213212133121341213512136121371213812139121401214112142121431214412145121461214712148121491215012151121521215312154121551215612157121581215912160121611216212163121641216512166121671216812169121701217112172121731217412175121761217712178121791218012181121821218312184121851218612187121881218912190121911219212193121941219512196121971219812199122001220112202122031220412205122061220712208122091221012211122121221312214122151221612217122181221912220122211222212223122241222512226122271222812229122301223112232122331223412235122361223712238122391224012241122421224312244122451224612247122481224912250122511225212253122541225512256122571225812259122601226112262122631226412265122661226712268122691227012271122721227312274122751227612277122781227912280122811228212283122841228512286122871228812289122901229112292122931229412295122961229712298122991230012301123021230312304123051230612307123081230912310123111231212313123141231512316123171231812319123201232112322123231232412325123261232712328123291233012331123321233312334123351233612337123381233912340123411234212343123441234512346123471234812349123501235112352123531235412355123561235712358123591236012361123621236312364123651236612367123681236912370123711237212373123741237512376123771237812379123801238112382123831238412385123861238712388123891239012391123921239312394123951239612397123981239912400124011240212403124041240512406124071240812409124101241112412124131241412415124161241712418124191242012421124221242312424124251242612427124281242912430124311243212433124341243512436124371243812439124401244112442124431244412445124461244712448124491245012451124521245312454124551245612457124581245912460124611246212463124641246512466124671246812469124701247112472124731247412475124761247712478124791248012481124821248312484124851248612487124881248912490124911249212493124941249512496124971249812499125001250112502125031250412505125061250712508125091251012511125121251312514125151251612517125181251912520125211252212523125241252512526125271252812529125301253112532125331253412535125361253712538125391254012541125421254312544125451254612547125481254912550125511255212553125541255512556125571255812559125601256112562125631256412565125661256712568125691257012571125721257312574125751257612577125781257912580125811258212583125841258512586125871258812589125901259112592125931259412595125961259712598125991260012601126021260312604126051260612607126081260912610126111261212613126141261512616126171261812619126201262112622126231262412625126261262712628126291263012631126321263312634126351263612637126381263912640126411264212643126441264512646126471264812649126501265112652126531265412655126561265712658126591266012661126621266312664126651266612667126681266912670126711267212673126741267512676126771267812679126801268112682126831268412685126861268712688126891269012691126921269312694126951269612697126981269912700127011270212703127041270512706127071270812709127101271112712127131271412715127161271712718127191272012721127221272312724127251272612727127281272912730127311273212733127341273512736127371273812739127401274112742127431274412745127461274712748127491275012751127521275312754127551275612757127581275912760127611276212763127641276512766127671276812769127701277112772127731277412775127761277712778127791278012781127821278312784127851278612787127881278912790127911279212793127941279512796127971279812799128001280112802128031280412805128061280712808128091281012811128121281312814128151281612817128181281912820128211282212823128241282512826128271282812829128301283112832128331283412835128361283712838128391284012841128421284312844128451284612847128481284912850128511285212853128541285512856128571285812859128601286112862128631286412865128661286712868128691287012871128721287312874128751287612877128781287912880128811288212883128841288512886128871288812889128901289112892128931289412895128961289712898128991290012901129021290312904129051290612907129081290912910129111291212913129141291512916129171291812919129201292112922129231292412925129261292712928129291293012931129321293312934129351293612937129381293912940129411294212943129441294512946129471294812949129501295112952129531295412955129561295712958129591296012961129621296312964129651296612967129681296912970129711297212973129741297512976129771297812979129801298112982129831298412985129861298712988129891299012991129921299312994129951299612997129981299913000130011300213003130041300513006130071300813009130101301113012130131301413015130161301713018130191302013021130221302313024130251302613027130281302913030130311303213033130341303513036130371303813039130401304113042130431304413045130461304713048130491305013051130521305313054130551305613057130581305913060130611306213063130641306513066130671306813069130701307113072130731307413075130761307713078130791308013081130821308313084130851308613087130881308913090130911309213093130941309513096130971309813099131001310113102131031310413105131061310713108131091311013111131121311313114131151311613117131181311913120131211312213123131241312513126131271312813129131301313113132131331313413135131361313713138131391314013141131421314313144131451314613147131481314913150131511315213153131541315513156131571315813159131601316113162131631316413165131661316713168131691317013171131721317313174131751317613177131781317913180131811318213183131841318513186131871318813189131901319113192131931319413195131961319713198131991320013201132021320313204132051320613207132081320913210132111321213213132141321513216132171321813219132201322113222132231322413225132261322713228132291323013231132321323313234132351323613237132381323913240132411324213243132441324513246132471324813249132501325113252132531325413255132561325713258132591326013261132621326313264132651326613267132681326913270132711327213273132741327513276132771327813279132801328113282132831328413285132861328713288132891329013291132921329313294132951329613297132981329913300133011330213303133041330513306133071330813309133101331113312133131331413315133161331713318133191332013321133221332313324133251332613327133281332913330133311333213333133341333513336133371333813339133401334113342133431334413345133461334713348133491335013351133521335313354133551335613357133581335913360133611336213363133641336513366133671336813369133701337113372133731337413375133761337713378133791338013381133821338313384133851338613387133881338913390133911339213393133941339513396133971339813399134001340113402134031340413405134061340713408134091341013411134121341313414134151341613417134181341913420134211342213423134241342513426134271342813429134301343113432134331343413435134361343713438134391344013441134421344313444134451344613447134481344913450134511345213453134541345513456134571345813459134601346113462134631346413465134661346713468134691347013471134721347313474134751347613477134781347913480134811348213483134841348513486134871348813489134901349113492134931349413495134961349713498134991350013501135021350313504135051350613507135081350913510135111351213513135141351513516135171351813519135201352113522135231352413525135261352713528135291353013531135321353313534135351353613537135381353913540135411354213543135441354513546135471354813549135501355113552135531355413555135561355713558135591356013561135621356313564135651356613567135681356913570135711357213573135741357513576135771357813579135801358113582135831358413585135861358713588135891359013591135921359313594135951359613597135981359913600136011360213603136041360513606136071360813609136101361113612136131361413615136161361713618136191362013621136221362313624136251362613627136281362913630136311363213633136341363513636136371363813639136401364113642136431364413645136461364713648136491365013651136521365313654136551365613657136581365913660136611366213663136641366513666136671366813669136701367113672136731367413675136761367713678136791368013681136821368313684136851368613687136881368913690136911369213693136941369513696136971369813699137001370113702137031370413705137061370713708137091371013711137121371313714137151371613717137181371913720137211372213723137241372513726137271372813729137301373113732137331373413735137361373713738137391374013741137421374313744137451374613747137481374913750137511375213753137541375513756137571375813759137601376113762137631376413765137661376713768137691377013771137721377313774137751377613777137781377913780137811378213783137841378513786137871378813789137901379113792137931379413795137961379713798137991380013801138021380313804138051380613807138081380913810138111381213813138141381513816138171381813819138201382113822138231382413825138261382713828138291383013831138321383313834138351383613837138381383913840138411384213843138441384513846138471384813849138501385113852138531385413855138561385713858138591386013861138621386313864138651386613867138681386913870138711387213873138741387513876138771387813879138801388113882138831388413885138861388713888138891389013891138921389313894138951389613897138981389913900139011390213903139041390513906139071390813909139101391113912139131391413915139161391713918139191392013921139221392313924139251392613927139281392913930139311393213933139341393513936139371393813939139401394113942139431394413945139461394713948139491395013951139521395313954139551395613957139581395913960139611396213963139641396513966139671396813969139701397113972139731397413975139761397713978139791398013981139821398313984139851398613987139881398913990139911399213993139941399513996139971399813999140001400114002140031400414005140061400714008140091401014011140121401314014140151401614017140181401914020140211402214023140241402514026140271402814029140301403114032140331403414035140361403714038140391404014041140421404314044140451404614047140481404914050140511405214053140541405514056140571405814059140601406114062140631406414065140661406714068140691407014071140721407314074140751407614077140781407914080140811408214083140841408514086140871408814089140901409114092140931409414095140961409714098140991410014101141021410314104141051410614107141081410914110141111411214113141141411514116141171411814119141201412114122141231412414125141261412714128141291413014131141321413314134141351413614137141381413914140141411414214143141441414514146141471414814149141501415114152141531415414155141561415714158141591416014161141621416314164141651416614167141681416914170141711417214173141741417514176141771417814179141801418114182141831418414185141861418714188141891419014191141921419314194141951419614197141981419914200142011420214203142041420514206142071420814209142101421114212142131421414215142161421714218142191422014221142221422314224142251422614227142281422914230142311423214233142341423514236142371423814239142401424114242142431424414245142461424714248142491425014251142521425314254142551425614257142581425914260142611426214263142641426514266142671426814269142701427114272142731427414275142761427714278142791428014281142821428314284142851428614287142881428914290142911429214293142941429514296142971429814299143001430114302143031430414305143061430714308143091431014311143121431314314143151431614317143181431914320143211432214323143241432514326143271432814329143301433114332143331433414335143361433714338143391434014341143421434314344143451434614347143481434914350143511435214353143541435514356143571435814359143601436114362143631436414365143661436714368143691437014371143721437314374143751437614377143781437914380143811438214383143841438514386143871438814389143901439114392143931439414395143961439714398143991440014401144021440314404144051440614407144081440914410144111441214413144141441514416144171441814419144201442114422144231442414425144261442714428144291443014431144321443314434144351443614437144381443914440144411444214443144441444514446144471444814449144501445114452144531445414455144561445714458144591446014461144621446314464144651446614467144681446914470144711447214473144741447514476144771447814479144801448114482144831448414485144861448714488144891449014491144921449314494144951449614497144981449914500145011450214503145041450514506145071450814509145101451114512145131451414515145161451714518145191452014521145221452314524145251452614527145281452914530145311453214533145341453514536145371453814539145401454114542145431454414545145461454714548145491455014551145521455314554145551455614557145581455914560145611456214563145641456514566145671456814569145701457114572145731457414575145761457714578145791458014581145821458314584145851458614587145881458914590145911459214593145941459514596145971459814599146001460114602146031460414605146061460714608146091461014611146121461314614146151461614617146181461914620146211462214623146241462514626146271462814629146301463114632146331463414635146361463714638146391464014641146421464314644146451464614647146481464914650146511465214653146541465514656146571465814659146601466114662146631466414665146661466714668146691467014671146721467314674146751467614677146781467914680146811468214683146841468514686146871468814689146901469114692146931469414695146961469714698146991470014701147021470314704147051470614707147081470914710147111471214713147141471514716147171471814719147201472114722147231472414725147261472714728147291473014731147321473314734147351473614737147381473914740147411474214743147441474514746147471474814749147501475114752147531475414755147561475714758147591476014761147621476314764147651476614767147681476914770147711477214773147741477514776147771477814779147801478114782147831478414785147861478714788147891479014791147921479314794147951479614797147981479914800148011480214803148041480514806148071480814809148101481114812148131481414815148161481714818148191482014821148221482314824148251482614827148281482914830148311483214833148341483514836148371483814839148401484114842148431484414845148461484714848148491485014851148521485314854148551485614857148581485914860148611486214863148641486514866148671486814869148701487114872148731487414875148761487714878148791488014881148821488314884148851488614887148881488914890148911489214893148941489514896148971489814899149001490114902149031490414905149061490714908149091491014911149121491314914149151491614917149181491914920149211492214923149241492514926149271492814929149301493114932149331493414935149361493714938149391494014941149421494314944149451494614947149481494914950149511495214953149541495514956149571495814959149601496114962149631496414965149661496714968149691497014971149721497314974149751497614977149781497914980149811498214983149841498514986149871498814989149901499114992149931499414995149961499714998149991500015001150021500315004150051500615007150081500915010150111501215013150141501515016150171501815019150201502115022150231502415025150261502715028150291503015031150321503315034150351503615037150381503915040150411504215043150441504515046150471504815049150501505115052
  1. /*
  2. *
  3. Copyright (c) Eicon Networks, 2002.
  4. *
  5. This source file is supplied for the use with
  6. Eicon Networks range of DIVA Server Adapters.
  7. *
  8. Eicon File Revision : 2.1
  9. *
  10. This program is free software; you can redistribute it and/or modify
  11. it under the terms of the GNU General Public License as published by
  12. the Free Software Foundation; either version 2, or (at your option)
  13. any later version.
  14. *
  15. This program is distributed in the hope that it will be useful,
  16. but WITHOUT ANY WARRANTY OF ANY KIND WHATSOEVER INCLUDING ANY
  17. implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  18. See the GNU General Public License for more details.
  19. *
  20. You should have received a copy of the GNU General Public License
  21. along with this program; if not, write to the Free Software
  22. Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  23. *
  24. */
  25. #include "platform.h"
  26. #include "di_defs.h"
  27. #include "pc.h"
  28. #include "capi20.h"
  29. #include "divacapi.h"
  30. #include "mdm_msg.h"
  31. #include "divasync.h"
  32. #define FILE_ "MESSAGE.C"
  33. #define dprintf
  34. /*------------------------------------------------------------------*/
  35. /* This is options supported for all adapters that are server by */
  36. /* XDI driver. Allo it is not necessary to ask it from every adapter*/
  37. /* and it is not necessary to save it separate for every adapter */
  38. /* Macrose defined here have only local meaning */
  39. /*------------------------------------------------------------------*/
  40. static dword diva_xdi_extended_features = 0;
  41. #define DIVA_CAPI_USE_CMA 0x00000001
  42. #define DIVA_CAPI_XDI_PROVIDES_SDRAM_BAR 0x00000002
  43. #define DIVA_CAPI_XDI_PROVIDES_NO_CANCEL 0x00000004
  44. #define DIVA_CAPI_XDI_PROVIDES_RX_DMA 0x00000008
  45. /*
  46. CAPI can request to process all return codes self only if:
  47. protocol code supports this && xdi supports this
  48. */
  49. #define DIVA_CAPI_SUPPORTS_NO_CANCEL(__a__) (((__a__)->manufacturer_features & MANUFACTURER_FEATURE_XONOFF_FLOW_CONTROL) && ((__a__)->manufacturer_features & MANUFACTURER_FEATURE_OK_FC_LABEL) && (diva_xdi_extended_features & DIVA_CAPI_XDI_PROVIDES_NO_CANCEL))
  50. /*------------------------------------------------------------------*/
  51. /* local function prototypes */
  52. /*------------------------------------------------------------------*/
  53. static void group_optimization(DIVA_CAPI_ADAPTER *a, PLCI *plci);
  54. static void set_group_ind_mask(PLCI *plci);
  55. static void clear_group_ind_mask_bit(PLCI *plci, word b);
  56. static byte test_group_ind_mask_bit(PLCI *plci, word b);
  57. void AutomaticLaw(DIVA_CAPI_ADAPTER *);
  58. word CapiRelease(word);
  59. word CapiRegister(word);
  60. word api_put(APPL *, CAPI_MSG *);
  61. static word api_parse(byte *, word, byte *, API_PARSE *);
  62. static void api_save_msg(API_PARSE *in, byte *format, API_SAVE *out);
  63. static void api_load_msg(API_SAVE *in, API_PARSE *out);
  64. word api_remove_start(void);
  65. void api_remove_complete(void);
  66. static void plci_remove(PLCI *);
  67. static void diva_get_extended_adapter_features(DIVA_CAPI_ADAPTER *a);
  68. static void diva_ask_for_xdi_sdram_bar(DIVA_CAPI_ADAPTER *, IDI_SYNC_REQ *);
  69. void callback(ENTITY *);
  70. static void control_rc(PLCI *, byte, byte, byte, byte, byte);
  71. static void data_rc(PLCI *, byte);
  72. static void data_ack(PLCI *, byte);
  73. static void sig_ind(PLCI *);
  74. static void SendInfo(PLCI *, dword, byte **, byte);
  75. static void SendSetupInfo(APPL *, PLCI *, dword, byte **, byte);
  76. static void SendSSExtInd(APPL *, PLCI *plci, dword Id, byte **parms);
  77. static void VSwitchReqInd(PLCI *plci, dword Id, byte **parms);
  78. static void nl_ind(PLCI *);
  79. static byte connect_req(dword, word, DIVA_CAPI_ADAPTER *, PLCI *, APPL *, API_PARSE *);
  80. static byte connect_res(dword, word, DIVA_CAPI_ADAPTER *, PLCI *, APPL *, API_PARSE *);
  81. static byte connect_a_res(dword, word, DIVA_CAPI_ADAPTER *, PLCI *, APPL *, API_PARSE *);
  82. static byte disconnect_req(dword, word, DIVA_CAPI_ADAPTER *, PLCI *, APPL *, API_PARSE *);
  83. static byte disconnect_res(dword, word, DIVA_CAPI_ADAPTER *, PLCI *, APPL *, API_PARSE *);
  84. static byte listen_req(dword, word, DIVA_CAPI_ADAPTER *, PLCI *, APPL *, API_PARSE *);
  85. static byte info_req(dword, word, DIVA_CAPI_ADAPTER *, PLCI *, APPL *, API_PARSE *);
  86. static byte info_res(dword, word, DIVA_CAPI_ADAPTER *, PLCI *, APPL *, API_PARSE *);
  87. static byte alert_req(dword, word, DIVA_CAPI_ADAPTER *, PLCI *, APPL *, API_PARSE *);
  88. static byte facility_req(dword, word, DIVA_CAPI_ADAPTER *, PLCI *, APPL *, API_PARSE *);
  89. static byte facility_res(dword, word, DIVA_CAPI_ADAPTER *, PLCI *, APPL *, API_PARSE *);
  90. static byte connect_b3_req(dword, word, DIVA_CAPI_ADAPTER *, PLCI *, APPL *, API_PARSE *);
  91. static byte connect_b3_res(dword, word, DIVA_CAPI_ADAPTER *, PLCI *, APPL *, API_PARSE *);
  92. static byte connect_b3_a_res(dword, word, DIVA_CAPI_ADAPTER *, PLCI *, APPL *, API_PARSE *);
  93. static byte disconnect_b3_req(dword, word, DIVA_CAPI_ADAPTER *, PLCI *, APPL *, API_PARSE *);
  94. static byte disconnect_b3_res(dword, word, DIVA_CAPI_ADAPTER *, PLCI *, APPL *, API_PARSE *);
  95. static byte data_b3_req(dword, word, DIVA_CAPI_ADAPTER *, PLCI *, APPL *, API_PARSE *);
  96. static byte data_b3_res(dword, word, DIVA_CAPI_ADAPTER *, PLCI *, APPL *, API_PARSE *);
  97. static byte reset_b3_req(dword, word, DIVA_CAPI_ADAPTER *, PLCI *, APPL *, API_PARSE *);
  98. static byte reset_b3_res(dword, word, DIVA_CAPI_ADAPTER *, PLCI *, APPL *, API_PARSE *);
  99. static byte connect_b3_t90_a_res(dword, word, DIVA_CAPI_ADAPTER *, PLCI *, APPL *, API_PARSE *);
  100. static byte select_b_req(dword, word, DIVA_CAPI_ADAPTER *, PLCI *, APPL *, API_PARSE *);
  101. static byte manufacturer_req(dword, word, DIVA_CAPI_ADAPTER *, PLCI *, APPL *, API_PARSE *);
  102. static byte manufacturer_res(dword, word, DIVA_CAPI_ADAPTER *, PLCI *, APPL *, API_PARSE *);
  103. static word get_plci(DIVA_CAPI_ADAPTER *);
  104. static void add_p(PLCI *, byte, byte *);
  105. static void add_s(PLCI *plci, byte code, API_PARSE *p);
  106. static void add_ss(PLCI *plci, byte code, API_PARSE *p);
  107. static void add_ie(PLCI *plci, byte code, byte *p, word p_length);
  108. static void add_d(PLCI *, word, byte *);
  109. static void add_ai(PLCI *, API_PARSE *);
  110. static word add_b1(PLCI *, API_PARSE *, word, word);
  111. static word add_b23(PLCI *, API_PARSE *);
  112. static word add_modem_b23(PLCI *plci, API_PARSE *bp_parms);
  113. static void sig_req(PLCI *, byte, byte);
  114. static void nl_req_ncci(PLCI *, byte, byte);
  115. static void send_req(PLCI *);
  116. static void send_data(PLCI *);
  117. static word plci_remove_check(PLCI *);
  118. static void listen_check(DIVA_CAPI_ADAPTER *);
  119. static byte AddInfo(byte **, byte **, byte *, byte *);
  120. static byte getChannel(API_PARSE *);
  121. static void IndParse(PLCI *, word *, byte **, byte);
  122. static byte ie_compare(byte *, byte *);
  123. static word find_cip(DIVA_CAPI_ADAPTER *, byte *, byte *);
  124. static word CPN_filter_ok(byte *cpn, DIVA_CAPI_ADAPTER *, word);
  125. /*
  126. XON protocol helpers
  127. */
  128. static void channel_flow_control_remove(PLCI *plci);
  129. static void channel_x_off(PLCI *plci, byte ch, byte flag);
  130. static void channel_x_on(PLCI *plci, byte ch);
  131. static void channel_request_xon(PLCI *plci, byte ch);
  132. static void channel_xmit_xon(PLCI *plci);
  133. static int channel_can_xon(PLCI *plci, byte ch);
  134. static void channel_xmit_extended_xon(PLCI *plci);
  135. static byte SendMultiIE(PLCI *plci, dword Id, byte **parms, byte ie_type, dword info_mask, byte setupParse);
  136. static word AdvCodecSupport(DIVA_CAPI_ADAPTER *, PLCI *, APPL *, byte);
  137. static void CodecIdCheck(DIVA_CAPI_ADAPTER *, PLCI *);
  138. static void SetVoiceChannel(PLCI *, byte *, DIVA_CAPI_ADAPTER *);
  139. static void VoiceChannelOff(PLCI *plci);
  140. static void adv_voice_write_coefs(PLCI *plci, word write_command);
  141. static void adv_voice_clear_config(PLCI *plci);
  142. static word get_b1_facilities(PLCI *plci, byte b1_resource);
  143. static byte add_b1_facilities(PLCI *plci, byte b1_resource, word b1_facilities);
  144. static void adjust_b1_facilities(PLCI *plci, byte new_b1_resource, word new_b1_facilities);
  145. static word adjust_b_process(dword Id, PLCI *plci, byte Rc);
  146. static void adjust_b1_resource(dword Id, PLCI *plci, API_SAVE *bp_msg, word b1_facilities, word internal_command);
  147. static void adjust_b_restore(dword Id, PLCI *plci, byte Rc);
  148. static void reset_b3_command(dword Id, PLCI *plci, byte Rc);
  149. static void select_b_command(dword Id, PLCI *plci, byte Rc);
  150. static void fax_connect_ack_command(dword Id, PLCI *plci, byte Rc);
  151. static void fax_edata_ack_command(dword Id, PLCI *plci, byte Rc);
  152. static void fax_connect_info_command(dword Id, PLCI *plci, byte Rc);
  153. static void fax_adjust_b23_command(dword Id, PLCI *plci, byte Rc);
  154. static void fax_disconnect_command(dword Id, PLCI *plci, byte Rc);
  155. static void hold_save_command(dword Id, PLCI *plci, byte Rc);
  156. static void retrieve_restore_command(dword Id, PLCI *plci, byte Rc);
  157. static void init_b1_config(PLCI *plci);
  158. static void clear_b1_config(PLCI *plci);
  159. static void dtmf_command(dword Id, PLCI *plci, byte Rc);
  160. static byte dtmf_request(dword Id, word Number, DIVA_CAPI_ADAPTER *a, PLCI *plci, APPL *appl, API_PARSE *msg);
  161. static void dtmf_confirmation(dword Id, PLCI *plci);
  162. static void dtmf_indication(dword Id, PLCI *plci, byte *msg, word length);
  163. static void dtmf_parameter_write(PLCI *plci);
  164. static void mixer_set_bchannel_id_esc(PLCI *plci, byte bchannel_id);
  165. static void mixer_set_bchannel_id(PLCI *plci, byte *chi);
  166. static void mixer_clear_config(PLCI *plci);
  167. static void mixer_notify_update(PLCI *plci, byte others);
  168. static void mixer_command(dword Id, PLCI *plci, byte Rc);
  169. static byte mixer_request(dword Id, word Number, DIVA_CAPI_ADAPTER *a, PLCI *plci, APPL *appl, API_PARSE *msg);
  170. static void mixer_indication_coefs_set(dword Id, PLCI *plci);
  171. static void mixer_indication_xconnect_from(dword Id, PLCI *plci, byte *msg, word length);
  172. static void mixer_indication_xconnect_to(dword Id, PLCI *plci, byte *msg, word length);
  173. static void mixer_remove(PLCI *plci);
  174. static void ec_command(dword Id, PLCI *plci, byte Rc);
  175. static byte ec_request(dword Id, word Number, DIVA_CAPI_ADAPTER *a, PLCI *plci, APPL *appl, API_PARSE *msg);
  176. static void ec_indication(dword Id, PLCI *plci, byte *msg, word length);
  177. static void rtp_connect_b3_req_command(dword Id, PLCI *plci, byte Rc);
  178. static void rtp_connect_b3_res_command(dword Id, PLCI *plci, byte Rc);
  179. static int diva_get_dma_descriptor(PLCI *plci, dword *dma_magic);
  180. static void diva_free_dma_descriptor(PLCI *plci, int nr);
  181. /*------------------------------------------------------------------*/
  182. /* external function prototypes */
  183. /*------------------------------------------------------------------*/
  184. extern byte MapController(byte);
  185. extern byte UnMapController(byte);
  186. #define MapId(Id)(((Id) & 0xffffff00L) | MapController((byte)(Id)))
  187. #define UnMapId(Id)(((Id) & 0xffffff00L) | UnMapController((byte)(Id)))
  188. void sendf(APPL *, word, dword, word, byte *, ...);
  189. void *TransmitBufferSet(APPL *appl, dword ref);
  190. void *TransmitBufferGet(APPL *appl, void *p);
  191. void TransmitBufferFree(APPL *appl, void *p);
  192. void *ReceiveBufferGet(APPL *appl, int Num);
  193. int fax_head_line_time(char *buffer);
  194. /*------------------------------------------------------------------*/
  195. /* Global data definitions */
  196. /*------------------------------------------------------------------*/
  197. extern byte max_adapter;
  198. extern byte max_appl;
  199. extern DIVA_CAPI_ADAPTER *adapter;
  200. extern APPL *application;
  201. static byte remove_started = false;
  202. static PLCI dummy_plci;
  203. static struct _ftable {
  204. word command;
  205. byte *format;
  206. byte (*function)(dword, word, DIVA_CAPI_ADAPTER *, PLCI *, APPL *, API_PARSE *);
  207. } ftable[] = {
  208. {_DATA_B3_R, "dwww", data_b3_req},
  209. {_DATA_B3_I | RESPONSE, "w", data_b3_res},
  210. {_INFO_R, "ss", info_req},
  211. {_INFO_I | RESPONSE, "", info_res},
  212. {_CONNECT_R, "wsssssssss", connect_req},
  213. {_CONNECT_I | RESPONSE, "wsssss", connect_res},
  214. {_CONNECT_ACTIVE_I | RESPONSE, "", connect_a_res},
  215. {_DISCONNECT_R, "s", disconnect_req},
  216. {_DISCONNECT_I | RESPONSE, "", disconnect_res},
  217. {_LISTEN_R, "dddss", listen_req},
  218. {_ALERT_R, "s", alert_req},
  219. {_FACILITY_R, "ws", facility_req},
  220. {_FACILITY_I | RESPONSE, "ws", facility_res},
  221. {_CONNECT_B3_R, "s", connect_b3_req},
  222. {_CONNECT_B3_I | RESPONSE, "ws", connect_b3_res},
  223. {_CONNECT_B3_ACTIVE_I | RESPONSE, "", connect_b3_a_res},
  224. {_DISCONNECT_B3_R, "s", disconnect_b3_req},
  225. {_DISCONNECT_B3_I | RESPONSE, "", disconnect_b3_res},
  226. {_RESET_B3_R, "s", reset_b3_req},
  227. {_RESET_B3_I | RESPONSE, "", reset_b3_res},
  228. {_CONNECT_B3_T90_ACTIVE_I | RESPONSE, "ws", connect_b3_t90_a_res},
  229. {_CONNECT_B3_T90_ACTIVE_I | RESPONSE, "", connect_b3_t90_a_res},
  230. {_SELECT_B_REQ, "s", select_b_req},
  231. {_MANUFACTURER_R, "dws", manufacturer_req},
  232. {_MANUFACTURER_I | RESPONSE, "dws", manufacturer_res},
  233. {_MANUFACTURER_I | RESPONSE, "", manufacturer_res}
  234. };
  235. static byte *cip_bc[29][2] = {
  236. { "", "" }, /* 0 */
  237. { "\x03\x80\x90\xa3", "\x03\x80\x90\xa2" }, /* 1 */
  238. { "\x02\x88\x90", "\x02\x88\x90" }, /* 2 */
  239. { "\x02\x89\x90", "\x02\x89\x90" }, /* 3 */
  240. { "\x03\x90\x90\xa3", "\x03\x90\x90\xa2" }, /* 4 */
  241. { "\x03\x91\x90\xa5", "\x03\x91\x90\xa5" }, /* 5 */
  242. { "\x02\x98\x90", "\x02\x98\x90" }, /* 6 */
  243. { "\x04\x88\xc0\xc6\xe6", "\x04\x88\xc0\xc6\xe6" }, /* 7 */
  244. { "\x04\x88\x90\x21\x8f", "\x04\x88\x90\x21\x8f" }, /* 8 */
  245. { "\x03\x91\x90\xa5", "\x03\x91\x90\xa5" }, /* 9 */
  246. { "", "" }, /* 10 */
  247. { "", "" }, /* 11 */
  248. { "", "" }, /* 12 */
  249. { "", "" }, /* 13 */
  250. { "", "" }, /* 14 */
  251. { "", "" }, /* 15 */
  252. { "\x03\x80\x90\xa3", "\x03\x80\x90\xa2" }, /* 16 */
  253. { "\x03\x90\x90\xa3", "\x03\x90\x90\xa2" }, /* 17 */
  254. { "\x02\x88\x90", "\x02\x88\x90" }, /* 18 */
  255. { "\x02\x88\x90", "\x02\x88\x90" }, /* 19 */
  256. { "\x02\x88\x90", "\x02\x88\x90" }, /* 20 */
  257. { "\x02\x88\x90", "\x02\x88\x90" }, /* 21 */
  258. { "\x02\x88\x90", "\x02\x88\x90" }, /* 22 */
  259. { "\x02\x88\x90", "\x02\x88\x90" }, /* 23 */
  260. { "\x02\x88\x90", "\x02\x88\x90" }, /* 24 */
  261. { "\x02\x88\x90", "\x02\x88\x90" }, /* 25 */
  262. { "\x03\x91\x90\xa5", "\x03\x91\x90\xa5" }, /* 26 */
  263. { "\x03\x91\x90\xa5", "\x03\x91\x90\xa5" }, /* 27 */
  264. { "\x02\x88\x90", "\x02\x88\x90" } /* 28 */
  265. };
  266. static byte *cip_hlc[29] = {
  267. "", /* 0 */
  268. "", /* 1 */
  269. "", /* 2 */
  270. "", /* 3 */
  271. "", /* 4 */
  272. "", /* 5 */
  273. "", /* 6 */
  274. "", /* 7 */
  275. "", /* 8 */
  276. "", /* 9 */
  277. "", /* 10 */
  278. "", /* 11 */
  279. "", /* 12 */
  280. "", /* 13 */
  281. "", /* 14 */
  282. "", /* 15 */
  283. "\x02\x91\x81", /* 16 */
  284. "\x02\x91\x84", /* 17 */
  285. "\x02\x91\xa1", /* 18 */
  286. "\x02\x91\xa4", /* 19 */
  287. "\x02\x91\xa8", /* 20 */
  288. "\x02\x91\xb1", /* 21 */
  289. "\x02\x91\xb2", /* 22 */
  290. "\x02\x91\xb5", /* 23 */
  291. "\x02\x91\xb8", /* 24 */
  292. "\x02\x91\xc1", /* 25 */
  293. "\x02\x91\x81", /* 26 */
  294. "\x03\x91\xe0\x01", /* 27 */
  295. "\x03\x91\xe0\x02" /* 28 */
  296. };
  297. /*------------------------------------------------------------------*/
  298. #define V120_HEADER_LENGTH 1
  299. #define V120_HEADER_EXTEND_BIT 0x80
  300. #define V120_HEADER_BREAK_BIT 0x40
  301. #define V120_HEADER_C1_BIT 0x04
  302. #define V120_HEADER_C2_BIT 0x08
  303. #define V120_HEADER_FLUSH_COND (V120_HEADER_BREAK_BIT | V120_HEADER_C1_BIT | V120_HEADER_C2_BIT)
  304. static byte v120_default_header[] =
  305. {
  306. 0x83 /* Ext, BR , res, res, C2 , C1 , B , F */
  307. };
  308. static byte v120_break_header[] =
  309. {
  310. 0xc3 | V120_HEADER_BREAK_BIT /* Ext, BR , res, res, C2 , C1 , B , F */
  311. };
  312. /*------------------------------------------------------------------*/
  313. /* API_PUT function */
  314. /*------------------------------------------------------------------*/
  315. word api_put(APPL *appl, CAPI_MSG *msg)
  316. {
  317. word i, j, k, l, n;
  318. word ret;
  319. byte c;
  320. byte controller;
  321. DIVA_CAPI_ADAPTER *a;
  322. PLCI *plci;
  323. NCCI *ncci_ptr;
  324. word ncci;
  325. CAPI_MSG *m;
  326. API_PARSE msg_parms[MAX_MSG_PARMS + 1];
  327. if (msg->header.length < sizeof(msg->header) ||
  328. msg->header.length > MAX_MSG_SIZE) {
  329. dbug(1, dprintf("bad len"));
  330. return _BAD_MSG;
  331. }
  332. controller = (byte)((msg->header.controller & 0x7f) - 1);
  333. /* controller starts with 0 up to (max_adapter - 1) */
  334. if (controller >= max_adapter)
  335. {
  336. dbug(1, dprintf("invalid ctrl"));
  337. return _BAD_MSG;
  338. }
  339. a = &adapter[controller];
  340. plci = NULL;
  341. if ((msg->header.plci != 0) && (msg->header.plci <= a->max_plci) && !a->adapter_disabled)
  342. {
  343. dbug(1, dprintf("plci=%x", msg->header.plci));
  344. plci = &a->plci[msg->header.plci - 1];
  345. ncci = GET_WORD(&msg->header.ncci);
  346. if (plci->Id
  347. && (plci->appl
  348. || (plci->State == INC_CON_PENDING)
  349. || (plci->State == INC_CON_ALERT)
  350. || (msg->header.command == (_DISCONNECT_I | RESPONSE)))
  351. && ((ncci == 0)
  352. || (msg->header.command == (_DISCONNECT_B3_I | RESPONSE))
  353. || ((ncci < MAX_NCCI + 1) && (a->ncci_plci[ncci] == plci->Id))))
  354. {
  355. i = plci->msg_in_read_pos;
  356. j = plci->msg_in_write_pos;
  357. if (j >= i)
  358. {
  359. if (j + msg->header.length + MSG_IN_OVERHEAD <= MSG_IN_QUEUE_SIZE)
  360. i += MSG_IN_QUEUE_SIZE - j;
  361. else
  362. j = 0;
  363. }
  364. else
  365. {
  366. n = (((CAPI_MSG *)(plci->msg_in_queue))->header.length + MSG_IN_OVERHEAD + 3) & 0xfffc;
  367. if (i > MSG_IN_QUEUE_SIZE - n)
  368. i = MSG_IN_QUEUE_SIZE - n + 1;
  369. i -= j;
  370. }
  371. if (i <= ((msg->header.length + MSG_IN_OVERHEAD + 3) & 0xfffc))
  372. {
  373. dbug(0, dprintf("Q-FULL1(msg) - len=%d write=%d read=%d wrap=%d free=%d",
  374. msg->header.length, plci->msg_in_write_pos,
  375. plci->msg_in_read_pos, plci->msg_in_wrap_pos, i));
  376. return _QUEUE_FULL;
  377. }
  378. c = false;
  379. if ((((byte *) msg) < ((byte *)(plci->msg_in_queue)))
  380. || (((byte *) msg) >= ((byte *)(plci->msg_in_queue)) + sizeof(plci->msg_in_queue)))
  381. {
  382. if (plci->msg_in_write_pos != plci->msg_in_read_pos)
  383. c = true;
  384. }
  385. if (msg->header.command == _DATA_B3_R)
  386. {
  387. if (msg->header.length < 20)
  388. {
  389. dbug(1, dprintf("DATA_B3 REQ wrong length %d", msg->header.length));
  390. return _BAD_MSG;
  391. }
  392. ncci_ptr = &(a->ncci[ncci]);
  393. n = ncci_ptr->data_pending;
  394. l = ncci_ptr->data_ack_pending;
  395. k = plci->msg_in_read_pos;
  396. while (k != plci->msg_in_write_pos)
  397. {
  398. if (k == plci->msg_in_wrap_pos)
  399. k = 0;
  400. if ((((CAPI_MSG *)(&((byte *)(plci->msg_in_queue))[k]))->header.command == _DATA_B3_R)
  401. && (((CAPI_MSG *)(&((byte *)(plci->msg_in_queue))[k]))->header.ncci == ncci))
  402. {
  403. n++;
  404. if (((CAPI_MSG *)(&((byte *)(plci->msg_in_queue))[k]))->info.data_b3_req.Flags & 0x0004)
  405. l++;
  406. }
  407. k += (((CAPI_MSG *)(&((byte *)(plci->msg_in_queue))[k]))->header.length +
  408. MSG_IN_OVERHEAD + 3) & 0xfffc;
  409. }
  410. if ((n >= MAX_DATA_B3) || (l >= MAX_DATA_ACK))
  411. {
  412. dbug(0, dprintf("Q-FULL2(data) - pending=%d/%d ack_pending=%d/%d",
  413. ncci_ptr->data_pending, n, ncci_ptr->data_ack_pending, l));
  414. return _QUEUE_FULL;
  415. }
  416. if (plci->req_in || plci->internal_command)
  417. {
  418. if ((((byte *) msg) >= ((byte *)(plci->msg_in_queue)))
  419. && (((byte *) msg) < ((byte *)(plci->msg_in_queue)) + sizeof(plci->msg_in_queue)))
  420. {
  421. dbug(0, dprintf("Q-FULL3(requeue)"));
  422. return _QUEUE_FULL;
  423. }
  424. c = true;
  425. }
  426. }
  427. else
  428. {
  429. if (plci->req_in || plci->internal_command)
  430. c = true;
  431. else
  432. {
  433. plci->command = msg->header.command;
  434. plci->number = msg->header.number;
  435. }
  436. }
  437. if (c)
  438. {
  439. dbug(1, dprintf("enqueue msg(0x%04x,0x%x,0x%x) - len=%d write=%d read=%d wrap=%d free=%d",
  440. msg->header.command, plci->req_in, plci->internal_command,
  441. msg->header.length, plci->msg_in_write_pos,
  442. plci->msg_in_read_pos, plci->msg_in_wrap_pos, i));
  443. if (j == 0)
  444. plci->msg_in_wrap_pos = plci->msg_in_write_pos;
  445. m = (CAPI_MSG *)(&((byte *)(plci->msg_in_queue))[j]);
  446. for (i = 0; i < msg->header.length; i++)
  447. ((byte *)(plci->msg_in_queue))[j++] = ((byte *) msg)[i];
  448. if (m->header.command == _DATA_B3_R)
  449. {
  450. m->info.data_b3_req.Data = (dword)(long)(TransmitBufferSet(appl, m->info.data_b3_req.Data));
  451. }
  452. j = (j + 3) & 0xfffc;
  453. *((APPL **)(&((byte *)(plci->msg_in_queue))[j])) = appl;
  454. plci->msg_in_write_pos = j + MSG_IN_OVERHEAD;
  455. return 0;
  456. }
  457. }
  458. else
  459. {
  460. plci = NULL;
  461. }
  462. }
  463. dbug(1, dprintf("com=%x", msg->header.command));
  464. for (j = 0; j < MAX_MSG_PARMS + 1; j++) msg_parms[j].length = 0;
  465. for (i = 0, ret = _BAD_MSG; i < ARRAY_SIZE(ftable); i++) {
  466. if (ftable[i].command == msg->header.command) {
  467. /* break loop if the message is correct, otherwise continue scan */
  468. /* (for example: CONNECT_B3_T90_ACT_RES has two specifications) */
  469. if (!api_parse(msg->info.b, (word)(msg->header.length - 12), ftable[i].format, msg_parms)) {
  470. ret = 0;
  471. break;
  472. }
  473. for (j = 0; j < MAX_MSG_PARMS + 1; j++) msg_parms[j].length = 0;
  474. }
  475. }
  476. if (ret) {
  477. dbug(1, dprintf("BAD_MSG"));
  478. if (plci) plci->command = 0;
  479. return ret;
  480. }
  481. c = ftable[i].function(GET_DWORD(&msg->header.controller),
  482. msg->header.number,
  483. a,
  484. plci,
  485. appl,
  486. msg_parms);
  487. channel_xmit_extended_xon(plci);
  488. if (c == 1) send_req(plci);
  489. if (c == 2 && plci) plci->req_in = plci->req_in_start = plci->req_out = 0;
  490. if (plci && !plci->req_in) plci->command = 0;
  491. return 0;
  492. }
  493. /*------------------------------------------------------------------*/
  494. /* api_parse function, check the format of api messages */
  495. /*------------------------------------------------------------------*/
  496. static word api_parse(byte *msg, word length, byte *format, API_PARSE *parms)
  497. {
  498. word i;
  499. word p;
  500. for (i = 0, p = 0; format[i]; i++) {
  501. if (parms)
  502. {
  503. parms[i].info = &msg[p];
  504. }
  505. switch (format[i]) {
  506. case 'b':
  507. p += 1;
  508. break;
  509. case 'w':
  510. p += 2;
  511. break;
  512. case 'd':
  513. p += 4;
  514. break;
  515. case 's':
  516. if (msg[p] == 0xff) {
  517. parms[i].info += 2;
  518. parms[i].length = msg[p + 1] + (msg[p + 2] << 8);
  519. p += (parms[i].length + 3);
  520. }
  521. else {
  522. parms[i].length = msg[p];
  523. p += (parms[i].length + 1);
  524. }
  525. break;
  526. }
  527. if (p > length) return true;
  528. }
  529. if (parms) parms[i].info = NULL;
  530. return false;
  531. }
  532. static void api_save_msg(API_PARSE *in, byte *format, API_SAVE *out)
  533. {
  534. word i, j, n = 0;
  535. byte *p;
  536. p = out->info;
  537. for (i = 0; format[i] != '\0'; i++)
  538. {
  539. out->parms[i].info = p;
  540. out->parms[i].length = in[i].length;
  541. switch (format[i])
  542. {
  543. case 'b':
  544. n = 1;
  545. break;
  546. case 'w':
  547. n = 2;
  548. break;
  549. case 'd':
  550. n = 4;
  551. break;
  552. case 's':
  553. n = in[i].length + 1;
  554. break;
  555. }
  556. for (j = 0; j < n; j++)
  557. *(p++) = in[i].info[j];
  558. }
  559. out->parms[i].info = NULL;
  560. out->parms[i].length = 0;
  561. }
  562. static void api_load_msg(API_SAVE *in, API_PARSE *out)
  563. {
  564. word i;
  565. i = 0;
  566. do
  567. {
  568. out[i].info = in->parms[i].info;
  569. out[i].length = in->parms[i].length;
  570. } while (in->parms[i++].info);
  571. }
  572. /*------------------------------------------------------------------*/
  573. /* CAPI remove function */
  574. /*------------------------------------------------------------------*/
  575. word api_remove_start(void)
  576. {
  577. word i;
  578. word j;
  579. if (!remove_started) {
  580. remove_started = true;
  581. for (i = 0; i < max_adapter; i++) {
  582. if (adapter[i].request) {
  583. for (j = 0; j < adapter[i].max_plci; j++) {
  584. if (adapter[i].plci[j].Sig.Id) plci_remove(&adapter[i].plci[j]);
  585. }
  586. }
  587. }
  588. return 1;
  589. }
  590. else {
  591. for (i = 0; i < max_adapter; i++) {
  592. if (adapter[i].request) {
  593. for (j = 0; j < adapter[i].max_plci; j++) {
  594. if (adapter[i].plci[j].Sig.Id) return 1;
  595. }
  596. }
  597. }
  598. }
  599. api_remove_complete();
  600. return 0;
  601. }
  602. /*------------------------------------------------------------------*/
  603. /* internal command queue */
  604. /*------------------------------------------------------------------*/
  605. static void init_internal_command_queue(PLCI *plci)
  606. {
  607. word i;
  608. dbug(1, dprintf("%s,%d: init_internal_command_queue",
  609. (char *)(FILE_), __LINE__));
  610. plci->internal_command = 0;
  611. for (i = 0; i < MAX_INTERNAL_COMMAND_LEVELS; i++)
  612. plci->internal_command_queue[i] = NULL;
  613. }
  614. static void start_internal_command(dword Id, PLCI *plci, t_std_internal_command command_function)
  615. {
  616. word i;
  617. dbug(1, dprintf("[%06lx] %s,%d: start_internal_command",
  618. UnMapId(Id), (char *)(FILE_), __LINE__));
  619. if (plci->internal_command == 0)
  620. {
  621. plci->internal_command_queue[0] = command_function;
  622. (*command_function)(Id, plci, OK);
  623. }
  624. else
  625. {
  626. i = 1;
  627. while (plci->internal_command_queue[i] != NULL)
  628. i++;
  629. plci->internal_command_queue[i] = command_function;
  630. }
  631. }
  632. static void next_internal_command(dword Id, PLCI *plci)
  633. {
  634. word i;
  635. dbug(1, dprintf("[%06lx] %s,%d: next_internal_command",
  636. UnMapId(Id), (char *)(FILE_), __LINE__));
  637. plci->internal_command = 0;
  638. plci->internal_command_queue[0] = NULL;
  639. while (plci->internal_command_queue[1] != NULL)
  640. {
  641. for (i = 0; i < MAX_INTERNAL_COMMAND_LEVELS - 1; i++)
  642. plci->internal_command_queue[i] = plci->internal_command_queue[i + 1];
  643. plci->internal_command_queue[MAX_INTERNAL_COMMAND_LEVELS - 1] = NULL;
  644. (*(plci->internal_command_queue[0]))(Id, plci, OK);
  645. if (plci->internal_command != 0)
  646. return;
  647. plci->internal_command_queue[0] = NULL;
  648. }
  649. }
  650. /*------------------------------------------------------------------*/
  651. /* NCCI allocate/remove function */
  652. /*------------------------------------------------------------------*/
  653. static dword ncci_mapping_bug = 0;
  654. static word get_ncci(PLCI *plci, byte ch, word force_ncci)
  655. {
  656. DIVA_CAPI_ADAPTER *a;
  657. word ncci, i, j, k;
  658. a = plci->adapter;
  659. if (!ch || a->ch_ncci[ch])
  660. {
  661. ncci_mapping_bug++;
  662. dbug(1, dprintf("NCCI mapping exists %ld %02x %02x %02x-%02x",
  663. ncci_mapping_bug, ch, force_ncci, a->ncci_ch[a->ch_ncci[ch]], a->ch_ncci[ch]));
  664. ncci = ch;
  665. }
  666. else
  667. {
  668. if (force_ncci)
  669. ncci = force_ncci;
  670. else
  671. {
  672. if ((ch < MAX_NCCI + 1) && !a->ncci_ch[ch])
  673. ncci = ch;
  674. else
  675. {
  676. ncci = 1;
  677. while ((ncci < MAX_NCCI + 1) && a->ncci_ch[ncci])
  678. ncci++;
  679. if (ncci == MAX_NCCI + 1)
  680. {
  681. ncci_mapping_bug++;
  682. i = 1;
  683. do
  684. {
  685. j = 1;
  686. while ((j < MAX_NCCI + 1) && (a->ncci_ch[j] != i))
  687. j++;
  688. k = j;
  689. if (j < MAX_NCCI + 1)
  690. {
  691. do
  692. {
  693. j++;
  694. } while ((j < MAX_NCCI + 1) && (a->ncci_ch[j] != i));
  695. }
  696. } while ((i < MAX_NL_CHANNEL + 1) && (j < MAX_NCCI + 1));
  697. if (i < MAX_NL_CHANNEL + 1)
  698. {
  699. dbug(1, dprintf("NCCI mapping overflow %ld %02x %02x %02x-%02x-%02x",
  700. ncci_mapping_bug, ch, force_ncci, i, k, j));
  701. }
  702. else
  703. {
  704. dbug(1, dprintf("NCCI mapping overflow %ld %02x %02x",
  705. ncci_mapping_bug, ch, force_ncci));
  706. }
  707. ncci = ch;
  708. }
  709. }
  710. a->ncci_plci[ncci] = plci->Id;
  711. a->ncci_state[ncci] = IDLE;
  712. if (!plci->ncci_ring_list)
  713. plci->ncci_ring_list = ncci;
  714. else
  715. a->ncci_next[ncci] = a->ncci_next[plci->ncci_ring_list];
  716. a->ncci_next[plci->ncci_ring_list] = (byte) ncci;
  717. }
  718. a->ncci_ch[ncci] = ch;
  719. a->ch_ncci[ch] = (byte) ncci;
  720. dbug(1, dprintf("NCCI mapping established %ld %02x %02x %02x-%02x",
  721. ncci_mapping_bug, ch, force_ncci, ch, ncci));
  722. }
  723. return (ncci);
  724. }
  725. static void ncci_free_receive_buffers(PLCI *plci, word ncci)
  726. {
  727. DIVA_CAPI_ADAPTER *a;
  728. APPL *appl;
  729. word i, ncci_code;
  730. dword Id;
  731. a = plci->adapter;
  732. Id = (((dword) ncci) << 16) | (((word)(plci->Id)) << 8) | a->Id;
  733. if (ncci)
  734. {
  735. if (a->ncci_plci[ncci] == plci->Id)
  736. {
  737. if (!plci->appl)
  738. {
  739. ncci_mapping_bug++;
  740. dbug(1, dprintf("NCCI mapping appl expected %ld %08lx",
  741. ncci_mapping_bug, Id));
  742. }
  743. else
  744. {
  745. appl = plci->appl;
  746. ncci_code = ncci | (((word) a->Id) << 8);
  747. for (i = 0; i < appl->MaxBuffer; i++)
  748. {
  749. if ((appl->DataNCCI[i] == ncci_code)
  750. && (((byte)(appl->DataFlags[i] >> 8)) == plci->Id))
  751. {
  752. appl->DataNCCI[i] = 0;
  753. }
  754. }
  755. }
  756. }
  757. }
  758. else
  759. {
  760. for (ncci = 1; ncci < MAX_NCCI + 1; ncci++)
  761. {
  762. if (a->ncci_plci[ncci] == plci->Id)
  763. {
  764. if (!plci->appl)
  765. {
  766. ncci_mapping_bug++;
  767. dbug(1, dprintf("NCCI mapping no appl %ld %08lx",
  768. ncci_mapping_bug, Id));
  769. }
  770. else
  771. {
  772. appl = plci->appl;
  773. ncci_code = ncci | (((word) a->Id) << 8);
  774. for (i = 0; i < appl->MaxBuffer; i++)
  775. {
  776. if ((appl->DataNCCI[i] == ncci_code)
  777. && (((byte)(appl->DataFlags[i] >> 8)) == plci->Id))
  778. {
  779. appl->DataNCCI[i] = 0;
  780. }
  781. }
  782. }
  783. }
  784. }
  785. }
  786. }
  787. static void cleanup_ncci_data(PLCI *plci, word ncci)
  788. {
  789. NCCI *ncci_ptr;
  790. if (ncci && (plci->adapter->ncci_plci[ncci] == plci->Id))
  791. {
  792. ncci_ptr = &(plci->adapter->ncci[ncci]);
  793. if (plci->appl)
  794. {
  795. while (ncci_ptr->data_pending != 0)
  796. {
  797. if (!plci->data_sent || (ncci_ptr->DBuffer[ncci_ptr->data_out].P != plci->data_sent_ptr))
  798. TransmitBufferFree(plci->appl, ncci_ptr->DBuffer[ncci_ptr->data_out].P);
  799. (ncci_ptr->data_out)++;
  800. if (ncci_ptr->data_out == MAX_DATA_B3)
  801. ncci_ptr->data_out = 0;
  802. (ncci_ptr->data_pending)--;
  803. }
  804. }
  805. ncci_ptr->data_out = 0;
  806. ncci_ptr->data_pending = 0;
  807. ncci_ptr->data_ack_out = 0;
  808. ncci_ptr->data_ack_pending = 0;
  809. }
  810. }
  811. static void ncci_remove(PLCI *plci, word ncci, byte preserve_ncci)
  812. {
  813. DIVA_CAPI_ADAPTER *a;
  814. dword Id;
  815. word i;
  816. a = plci->adapter;
  817. Id = (((dword) ncci) << 16) | (((word)(plci->Id)) << 8) | a->Id;
  818. if (!preserve_ncci)
  819. ncci_free_receive_buffers(plci, ncci);
  820. if (ncci)
  821. {
  822. if (a->ncci_plci[ncci] != plci->Id)
  823. {
  824. ncci_mapping_bug++;
  825. dbug(1, dprintf("NCCI mapping doesn't exist %ld %08lx %02x",
  826. ncci_mapping_bug, Id, preserve_ncci));
  827. }
  828. else
  829. {
  830. cleanup_ncci_data(plci, ncci);
  831. dbug(1, dprintf("NCCI mapping released %ld %08lx %02x %02x-%02x",
  832. ncci_mapping_bug, Id, preserve_ncci, a->ncci_ch[ncci], ncci));
  833. a->ch_ncci[a->ncci_ch[ncci]] = 0;
  834. if (!preserve_ncci)
  835. {
  836. a->ncci_ch[ncci] = 0;
  837. a->ncci_plci[ncci] = 0;
  838. a->ncci_state[ncci] = IDLE;
  839. i = plci->ncci_ring_list;
  840. while ((i != 0) && (a->ncci_next[i] != plci->ncci_ring_list) && (a->ncci_next[i] != ncci))
  841. i = a->ncci_next[i];
  842. if ((i != 0) && (a->ncci_next[i] == ncci))
  843. {
  844. if (i == ncci)
  845. plci->ncci_ring_list = 0;
  846. else if (plci->ncci_ring_list == ncci)
  847. plci->ncci_ring_list = i;
  848. a->ncci_next[i] = a->ncci_next[ncci];
  849. }
  850. a->ncci_next[ncci] = 0;
  851. }
  852. }
  853. }
  854. else
  855. {
  856. for (ncci = 1; ncci < MAX_NCCI + 1; ncci++)
  857. {
  858. if (a->ncci_plci[ncci] == plci->Id)
  859. {
  860. cleanup_ncci_data(plci, ncci);
  861. dbug(1, dprintf("NCCI mapping released %ld %08lx %02x %02x-%02x",
  862. ncci_mapping_bug, Id, preserve_ncci, a->ncci_ch[ncci], ncci));
  863. a->ch_ncci[a->ncci_ch[ncci]] = 0;
  864. if (!preserve_ncci)
  865. {
  866. a->ncci_ch[ncci] = 0;
  867. a->ncci_plci[ncci] = 0;
  868. a->ncci_state[ncci] = IDLE;
  869. a->ncci_next[ncci] = 0;
  870. }
  871. }
  872. }
  873. if (!preserve_ncci)
  874. plci->ncci_ring_list = 0;
  875. }
  876. }
  877. /*------------------------------------------------------------------*/
  878. /* PLCI remove function */
  879. /*------------------------------------------------------------------*/
  880. static void plci_free_msg_in_queue(PLCI *plci)
  881. {
  882. word i;
  883. if (plci->appl)
  884. {
  885. i = plci->msg_in_read_pos;
  886. while (i != plci->msg_in_write_pos)
  887. {
  888. if (i == plci->msg_in_wrap_pos)
  889. i = 0;
  890. if (((CAPI_MSG *)(&((byte *)(plci->msg_in_queue))[i]))->header.command == _DATA_B3_R)
  891. {
  892. TransmitBufferFree(plci->appl,
  893. (byte *)(long)(((CAPI_MSG *)(&((byte *)(plci->msg_in_queue))[i]))->info.data_b3_req.Data));
  894. }
  895. i += (((CAPI_MSG *)(&((byte *)(plci->msg_in_queue))[i]))->header.length +
  896. MSG_IN_OVERHEAD + 3) & 0xfffc;
  897. }
  898. }
  899. plci->msg_in_write_pos = MSG_IN_QUEUE_SIZE;
  900. plci->msg_in_read_pos = MSG_IN_QUEUE_SIZE;
  901. plci->msg_in_wrap_pos = MSG_IN_QUEUE_SIZE;
  902. }
  903. static void plci_remove(PLCI *plci)
  904. {
  905. if (!plci) {
  906. dbug(1, dprintf("plci_remove(no plci)"));
  907. return;
  908. }
  909. init_internal_command_queue(plci);
  910. dbug(1, dprintf("plci_remove(%x,tel=%x)", plci->Id, plci->tel));
  911. if (plci_remove_check(plci))
  912. {
  913. return;
  914. }
  915. if (plci->Sig.Id == 0xff)
  916. {
  917. dbug(1, dprintf("D-channel X.25 plci->NL.Id:%0x", plci->NL.Id));
  918. if (plci->NL.Id && !plci->nl_remove_id)
  919. {
  920. nl_req_ncci(plci, REMOVE, 0);
  921. send_req(plci);
  922. }
  923. }
  924. else
  925. {
  926. if (!plci->sig_remove_id
  927. && (plci->Sig.Id
  928. || (plci->req_in != plci->req_out)
  929. || (plci->nl_req || plci->sig_req)))
  930. {
  931. sig_req(plci, HANGUP, 0);
  932. send_req(plci);
  933. }
  934. }
  935. ncci_remove(plci, 0, false);
  936. plci_free_msg_in_queue(plci);
  937. plci->channels = 0;
  938. plci->appl = NULL;
  939. if ((plci->State == INC_CON_PENDING) || (plci->State == INC_CON_ALERT))
  940. plci->State = OUTG_DIS_PENDING;
  941. }
  942. /*------------------------------------------------------------------*/
  943. /* Application Group function helpers */
  944. /*------------------------------------------------------------------*/
  945. static void set_group_ind_mask(PLCI *plci)
  946. {
  947. word i;
  948. for (i = 0; i < C_IND_MASK_DWORDS; i++)
  949. plci->group_optimization_mask_table[i] = 0xffffffffL;
  950. }
  951. static void clear_group_ind_mask_bit(PLCI *plci, word b)
  952. {
  953. plci->group_optimization_mask_table[b >> 5] &= ~(1L << (b & 0x1f));
  954. }
  955. static byte test_group_ind_mask_bit(PLCI *plci, word b)
  956. {
  957. return ((plci->group_optimization_mask_table[b >> 5] & (1L << (b & 0x1f))) != 0);
  958. }
  959. /*------------------------------------------------------------------*/
  960. /* c_ind_mask operations for arbitrary MAX_APPL */
  961. /*------------------------------------------------------------------*/
  962. static void clear_c_ind_mask(PLCI *plci)
  963. {
  964. word i;
  965. for (i = 0; i < C_IND_MASK_DWORDS; i++)
  966. plci->c_ind_mask_table[i] = 0;
  967. }
  968. static byte c_ind_mask_empty(PLCI *plci)
  969. {
  970. word i;
  971. i = 0;
  972. while ((i < C_IND_MASK_DWORDS) && (plci->c_ind_mask_table[i] == 0))
  973. i++;
  974. return (i == C_IND_MASK_DWORDS);
  975. }
  976. static void set_c_ind_mask_bit(PLCI *plci, word b)
  977. {
  978. plci->c_ind_mask_table[b >> 5] |= (1L << (b & 0x1f));
  979. }
  980. static void clear_c_ind_mask_bit(PLCI *plci, word b)
  981. {
  982. plci->c_ind_mask_table[b >> 5] &= ~(1L << (b & 0x1f));
  983. }
  984. static byte test_c_ind_mask_bit(PLCI *plci, word b)
  985. {
  986. return ((plci->c_ind_mask_table[b >> 5] & (1L << (b & 0x1f))) != 0);
  987. }
  988. static void dump_c_ind_mask(PLCI *plci)
  989. {
  990. static char hex_digit_table[0x10] =
  991. {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f'};
  992. word i, j, k;
  993. dword d;
  994. char *p;
  995. char buf[40];
  996. for (i = 0; i < C_IND_MASK_DWORDS; i += 4)
  997. {
  998. p = buf + 36;
  999. *p = '\0';
  1000. for (j = 0; j < 4; j++)
  1001. {
  1002. if (i + j < C_IND_MASK_DWORDS)
  1003. {
  1004. d = plci->c_ind_mask_table[i + j];
  1005. for (k = 0; k < 8; k++)
  1006. {
  1007. *(--p) = hex_digit_table[d & 0xf];
  1008. d >>= 4;
  1009. }
  1010. }
  1011. else if (i != 0)
  1012. {
  1013. for (k = 0; k < 8; k++)
  1014. *(--p) = ' ';
  1015. }
  1016. *(--p) = ' ';
  1017. }
  1018. dbug(1, dprintf("c_ind_mask =%s", (char *) p));
  1019. }
  1020. }
  1021. #define dump_plcis(a)
  1022. /*------------------------------------------------------------------*/
  1023. /* translation function for each message */
  1024. /*------------------------------------------------------------------*/
  1025. static byte connect_req(dword Id, word Number, DIVA_CAPI_ADAPTER *a,
  1026. PLCI *plci, APPL *appl, API_PARSE *parms)
  1027. {
  1028. word ch;
  1029. word i;
  1030. word Info;
  1031. byte LinkLayer;
  1032. API_PARSE *ai;
  1033. API_PARSE *bp;
  1034. API_PARSE ai_parms[5];
  1035. word channel = 0;
  1036. dword ch_mask;
  1037. byte m;
  1038. static byte esc_chi[35] = {0x02, 0x18, 0x01};
  1039. static byte lli[2] = {0x01, 0x00};
  1040. byte noCh = 0;
  1041. word dir = 0;
  1042. byte *p_chi = "";
  1043. for (i = 0; i < 5; i++) ai_parms[i].length = 0;
  1044. dbug(1, dprintf("connect_req(%d)", parms->length));
  1045. Info = _WRONG_IDENTIFIER;
  1046. if (a)
  1047. {
  1048. if (a->adapter_disabled)
  1049. {
  1050. dbug(1, dprintf("adapter disabled"));
  1051. Id = ((word)1 << 8) | a->Id;
  1052. sendf(appl, _CONNECT_R | CONFIRM, Id, Number, "w", 0);
  1053. sendf(appl, _DISCONNECT_I, Id, 0, "w", _L1_ERROR);
  1054. return false;
  1055. }
  1056. Info = _OUT_OF_PLCI;
  1057. if ((i = get_plci(a)))
  1058. {
  1059. Info = 0;
  1060. plci = &a->plci[i - 1];
  1061. plci->appl = appl;
  1062. plci->call_dir = CALL_DIR_OUT | CALL_DIR_ORIGINATE;
  1063. /* check 'external controller' bit for codec support */
  1064. if (Id & EXT_CONTROLLER)
  1065. {
  1066. if (AdvCodecSupport(a, plci, appl, 0))
  1067. {
  1068. plci->Id = 0;
  1069. sendf(appl, _CONNECT_R | CONFIRM, Id, Number, "w", _WRONG_IDENTIFIER);
  1070. return 2;
  1071. }
  1072. }
  1073. ai = &parms[9];
  1074. bp = &parms[5];
  1075. ch = 0;
  1076. if (bp->length)LinkLayer = bp->info[3];
  1077. else LinkLayer = 0;
  1078. if (ai->length)
  1079. {
  1080. ch = 0xffff;
  1081. if (!api_parse(&ai->info[1], (word)ai->length, "ssss", ai_parms))
  1082. {
  1083. ch = 0;
  1084. if (ai_parms[0].length)
  1085. {
  1086. ch = GET_WORD(ai_parms[0].info + 1);
  1087. if (ch > 4) ch = 0; /* safety -> ignore ChannelID */
  1088. if (ch == 4) /* explizit CHI in message */
  1089. {
  1090. /* check length of B-CH struct */
  1091. if ((ai_parms[0].info)[3] >= 1)
  1092. {
  1093. if ((ai_parms[0].info)[4] == CHI)
  1094. {
  1095. p_chi = &((ai_parms[0].info)[5]);
  1096. }
  1097. else
  1098. {
  1099. p_chi = &((ai_parms[0].info)[3]);
  1100. }
  1101. if (p_chi[0] > 35) /* check length of channel ID */
  1102. {
  1103. Info = _WRONG_MESSAGE_FORMAT;
  1104. }
  1105. }
  1106. else Info = _WRONG_MESSAGE_FORMAT;
  1107. }
  1108. if (ch == 3 && ai_parms[0].length >= 7 && ai_parms[0].length <= 36)
  1109. {
  1110. dir = GET_WORD(ai_parms[0].info + 3);
  1111. ch_mask = 0;
  1112. m = 0x3f;
  1113. for (i = 0; i + 5 <= ai_parms[0].length; i++)
  1114. {
  1115. if (ai_parms[0].info[i + 5] != 0)
  1116. {
  1117. if ((ai_parms[0].info[i + 5] | m) != 0xff)
  1118. Info = _WRONG_MESSAGE_FORMAT;
  1119. else
  1120. {
  1121. if (ch_mask == 0)
  1122. channel = i;
  1123. ch_mask |= 1L << i;
  1124. }
  1125. }
  1126. m = 0;
  1127. }
  1128. if (ch_mask == 0)
  1129. Info = _WRONG_MESSAGE_FORMAT;
  1130. if (!Info)
  1131. {
  1132. if ((ai_parms[0].length == 36) || (ch_mask != ((dword)(1L << channel))))
  1133. {
  1134. esc_chi[0] = (byte)(ai_parms[0].length - 2);
  1135. for (i = 0; i + 5 <= ai_parms[0].length; i++)
  1136. esc_chi[i + 3] = ai_parms[0].info[i + 5];
  1137. }
  1138. else
  1139. esc_chi[0] = 2;
  1140. esc_chi[2] = (byte)channel;
  1141. plci->b_channel = (byte)channel; /* not correct for ETSI ch 17..31 */
  1142. add_p(plci, LLI, lli);
  1143. add_p(plci, ESC, esc_chi);
  1144. plci->State = LOCAL_CONNECT;
  1145. if (!dir) plci->call_dir |= CALL_DIR_FORCE_OUTG_NL; /* dir 0=DTE, 1=DCE */
  1146. }
  1147. }
  1148. }
  1149. }
  1150. else Info = _WRONG_MESSAGE_FORMAT;
  1151. }
  1152. dbug(1, dprintf("ch=%x,dir=%x,p_ch=%d", ch, dir, channel));
  1153. plci->command = _CONNECT_R;
  1154. plci->number = Number;
  1155. /* x.31 or D-ch free SAPI in LinkLayer? */
  1156. if (ch == 1 && LinkLayer != 3 && LinkLayer != 12) noCh = true;
  1157. if ((ch == 0 || ch == 2 || noCh || ch == 3 || ch == 4) && !Info)
  1158. {
  1159. /* B-channel used for B3 connections (ch==0), or no B channel */
  1160. /* is used (ch==2) or perm. connection (3) is used do a CALL */
  1161. if (noCh) Info = add_b1(plci, &parms[5], 2, 0); /* no resource */
  1162. else Info = add_b1(plci, &parms[5], ch, 0);
  1163. add_s(plci, OAD, &parms[2]);
  1164. add_s(plci, OSA, &parms[4]);
  1165. add_s(plci, BC, &parms[6]);
  1166. add_s(plci, LLC, &parms[7]);
  1167. add_s(plci, HLC, &parms[8]);
  1168. if (a->Info_Mask[appl->Id - 1] & 0x200)
  1169. {
  1170. /* early B3 connect (CIP mask bit 9) no release after a disc */
  1171. add_p(plci, LLI, "\x01\x01");
  1172. }
  1173. if (GET_WORD(parms[0].info) < 29) {
  1174. add_p(plci, BC, cip_bc[GET_WORD(parms[0].info)][a->u_law]);
  1175. add_p(plci, HLC, cip_hlc[GET_WORD(parms[0].info)]);
  1176. }
  1177. add_p(plci, UID, "\x06\x43\x61\x70\x69\x32\x30");
  1178. sig_req(plci, ASSIGN, DSIG_ID);
  1179. }
  1180. else if (ch == 1) {
  1181. /* D-Channel used for B3 connections */
  1182. plci->Sig.Id = 0xff;
  1183. Info = 0;
  1184. }
  1185. if (!Info && ch != 2 && !noCh) {
  1186. Info = add_b23(plci, &parms[5]);
  1187. if (!Info) {
  1188. if (!(plci->tel && !plci->adv_nl))nl_req_ncci(plci, ASSIGN, 0);
  1189. }
  1190. }
  1191. if (!Info)
  1192. {
  1193. if (ch == 0 || ch == 2 || ch == 3 || noCh || ch == 4)
  1194. {
  1195. if (plci->spoofed_msg == SPOOFING_REQUIRED)
  1196. {
  1197. api_save_msg(parms, "wsssssssss", &plci->saved_msg);
  1198. plci->spoofed_msg = CALL_REQ;
  1199. plci->internal_command = BLOCK_PLCI;
  1200. plci->command = 0;
  1201. dbug(1, dprintf("Spoof"));
  1202. send_req(plci);
  1203. return false;
  1204. }
  1205. if (ch == 4)add_p(plci, CHI, p_chi);
  1206. add_s(plci, CPN, &parms[1]);
  1207. add_s(plci, DSA, &parms[3]);
  1208. if (noCh) add_p(plci, ESC, "\x02\x18\xfd"); /* D-channel, no B-L3 */
  1209. add_ai(plci, &parms[9]);
  1210. if (!dir)sig_req(plci, CALL_REQ, 0);
  1211. else
  1212. {
  1213. plci->command = PERM_LIST_REQ;
  1214. plci->appl = appl;
  1215. sig_req(plci, LISTEN_REQ, 0);
  1216. send_req(plci);
  1217. return false;
  1218. }
  1219. }
  1220. send_req(plci);
  1221. return false;
  1222. }
  1223. plci->Id = 0;
  1224. }
  1225. }
  1226. sendf(appl,
  1227. _CONNECT_R | CONFIRM,
  1228. Id,
  1229. Number,
  1230. "w", Info);
  1231. return 2;
  1232. }
  1233. static byte connect_res(dword Id, word Number, DIVA_CAPI_ADAPTER *a,
  1234. PLCI *plci, APPL *appl, API_PARSE *parms)
  1235. {
  1236. word i, Info;
  1237. word Reject;
  1238. static byte cau_t[] = {0, 0, 0x90, 0x91, 0xac, 0x9d, 0x86, 0xd8, 0x9b};
  1239. static byte esc_t[] = {0x03, 0x08, 0x00, 0x00};
  1240. API_PARSE *ai;
  1241. API_PARSE ai_parms[5];
  1242. word ch = 0;
  1243. if (!plci) {
  1244. dbug(1, dprintf("connect_res(no plci)"));
  1245. return 0; /* no plci, no send */
  1246. }
  1247. dbug(1, dprintf("connect_res(State=0x%x)", plci->State));
  1248. for (i = 0; i < 5; i++) ai_parms[i].length = 0;
  1249. ai = &parms[5];
  1250. dbug(1, dprintf("ai->length=%d", ai->length));
  1251. if (ai->length)
  1252. {
  1253. if (!api_parse(&ai->info[1], (word)ai->length, "ssss", ai_parms))
  1254. {
  1255. dbug(1, dprintf("ai_parms[0].length=%d/0x%x", ai_parms[0].length, GET_WORD(ai_parms[0].info + 1)));
  1256. ch = 0;
  1257. if (ai_parms[0].length)
  1258. {
  1259. ch = GET_WORD(ai_parms[0].info + 1);
  1260. dbug(1, dprintf("BCH-I=0x%x", ch));
  1261. }
  1262. }
  1263. }
  1264. if (plci->State == INC_CON_CONNECTED_ALERT)
  1265. {
  1266. dbug(1, dprintf("Connected Alert Call_Res"));
  1267. if (a->Info_Mask[appl->Id - 1] & 0x200)
  1268. {
  1269. /* early B3 connect (CIP mask bit 9) no release after a disc */
  1270. add_p(plci, LLI, "\x01\x01");
  1271. }
  1272. add_s(plci, CONN_NR, &parms[2]);
  1273. add_s(plci, LLC, &parms[4]);
  1274. add_ai(plci, &parms[5]);
  1275. plci->State = INC_CON_ACCEPT;
  1276. sig_req(plci, CALL_RES, 0);
  1277. return 1;
  1278. }
  1279. else if (plci->State == INC_CON_PENDING || plci->State == INC_CON_ALERT) {
  1280. clear_c_ind_mask_bit(plci, (word)(appl->Id - 1));
  1281. dump_c_ind_mask(plci);
  1282. Reject = GET_WORD(parms[0].info);
  1283. dbug(1, dprintf("Reject=0x%x", Reject));
  1284. if (Reject)
  1285. {
  1286. if (c_ind_mask_empty(plci))
  1287. {
  1288. if ((Reject & 0xff00) == 0x3400)
  1289. {
  1290. esc_t[2] = ((byte)(Reject & 0x00ff)) | 0x80;
  1291. add_p(plci, ESC, esc_t);
  1292. add_ai(plci, &parms[5]);
  1293. sig_req(plci, REJECT, 0);
  1294. }
  1295. else if (Reject == 1 || Reject > 9)
  1296. {
  1297. add_ai(plci, &parms[5]);
  1298. sig_req(plci, HANGUP, 0);
  1299. }
  1300. else
  1301. {
  1302. esc_t[2] = cau_t[(Reject&0x000f)];
  1303. add_p(plci, ESC, esc_t);
  1304. add_ai(plci, &parms[5]);
  1305. sig_req(plci, REJECT, 0);
  1306. }
  1307. plci->appl = appl;
  1308. }
  1309. else
  1310. {
  1311. sendf(appl, _DISCONNECT_I, Id, 0, "w", _OTHER_APPL_CONNECTED);
  1312. }
  1313. }
  1314. else {
  1315. plci->appl = appl;
  1316. if (Id & EXT_CONTROLLER) {
  1317. if (AdvCodecSupport(a, plci, appl, 0)) {
  1318. dbug(1, dprintf("connect_res(error from AdvCodecSupport)"));
  1319. sig_req(plci, HANGUP, 0);
  1320. return 1;
  1321. }
  1322. if (plci->tel == ADV_VOICE && a->AdvCodecPLCI)
  1323. {
  1324. Info = add_b23(plci, &parms[1]);
  1325. if (Info)
  1326. {
  1327. dbug(1, dprintf("connect_res(error from add_b23)"));
  1328. sig_req(plci, HANGUP, 0);
  1329. return 1;
  1330. }
  1331. if (plci->adv_nl)
  1332. {
  1333. nl_req_ncci(plci, ASSIGN, 0);
  1334. }
  1335. }
  1336. }
  1337. else
  1338. {
  1339. plci->tel = 0;
  1340. if (ch != 2)
  1341. {
  1342. Info = add_b23(plci, &parms[1]);
  1343. if (Info)
  1344. {
  1345. dbug(1, dprintf("connect_res(error from add_b23 2)"));
  1346. sig_req(plci, HANGUP, 0);
  1347. return 1;
  1348. }
  1349. }
  1350. nl_req_ncci(plci, ASSIGN, 0);
  1351. }
  1352. if (plci->spoofed_msg == SPOOFING_REQUIRED)
  1353. {
  1354. api_save_msg(parms, "wsssss", &plci->saved_msg);
  1355. plci->spoofed_msg = CALL_RES;
  1356. plci->internal_command = BLOCK_PLCI;
  1357. plci->command = 0;
  1358. dbug(1, dprintf("Spoof"));
  1359. }
  1360. else
  1361. {
  1362. add_b1(plci, &parms[1], ch, plci->B1_facilities);
  1363. if (a->Info_Mask[appl->Id - 1] & 0x200)
  1364. {
  1365. /* early B3 connect (CIP mask bit 9) no release after a disc */
  1366. add_p(plci, LLI, "\x01\x01");
  1367. }
  1368. add_s(plci, CONN_NR, &parms[2]);
  1369. add_s(plci, LLC, &parms[4]);
  1370. add_ai(plci, &parms[5]);
  1371. plci->State = INC_CON_ACCEPT;
  1372. sig_req(plci, CALL_RES, 0);
  1373. }
  1374. for (i = 0; i < max_appl; i++) {
  1375. if (test_c_ind_mask_bit(plci, i)) {
  1376. sendf(&application[i], _DISCONNECT_I, Id, 0, "w", _OTHER_APPL_CONNECTED);
  1377. }
  1378. }
  1379. }
  1380. }
  1381. return 1;
  1382. }
  1383. static byte connect_a_res(dword Id, word Number, DIVA_CAPI_ADAPTER *a,
  1384. PLCI *plci, APPL *appl, API_PARSE *msg)
  1385. {
  1386. dbug(1, dprintf("connect_a_res"));
  1387. return false;
  1388. }
  1389. static byte disconnect_req(dword Id, word Number, DIVA_CAPI_ADAPTER *a,
  1390. PLCI *plci, APPL *appl, API_PARSE *msg)
  1391. {
  1392. word Info;
  1393. word i;
  1394. dbug(1, dprintf("disconnect_req"));
  1395. Info = _WRONG_IDENTIFIER;
  1396. if (plci)
  1397. {
  1398. if (plci->State == INC_CON_PENDING || plci->State == INC_CON_ALERT)
  1399. {
  1400. clear_c_ind_mask_bit(plci, (word)(appl->Id - 1));
  1401. plci->appl = appl;
  1402. for (i = 0; i < max_appl; i++)
  1403. {
  1404. if (test_c_ind_mask_bit(plci, i))
  1405. sendf(&application[i], _DISCONNECT_I, Id, 0, "w", 0);
  1406. }
  1407. plci->State = OUTG_DIS_PENDING;
  1408. }
  1409. if (plci->Sig.Id && plci->appl)
  1410. {
  1411. Info = 0;
  1412. if (plci->Sig.Id != 0xff)
  1413. {
  1414. if (plci->State != INC_DIS_PENDING)
  1415. {
  1416. add_ai(plci, &msg[0]);
  1417. sig_req(plci, HANGUP, 0);
  1418. plci->State = OUTG_DIS_PENDING;
  1419. return 1;
  1420. }
  1421. }
  1422. else
  1423. {
  1424. if (plci->NL.Id && !plci->nl_remove_id)
  1425. {
  1426. mixer_remove(plci);
  1427. nl_req_ncci(plci, REMOVE, 0);
  1428. sendf(appl, _DISCONNECT_R | CONFIRM, Id, Number, "w", 0);
  1429. sendf(appl, _DISCONNECT_I, Id, 0, "w", 0);
  1430. plci->State = INC_DIS_PENDING;
  1431. }
  1432. return 1;
  1433. }
  1434. }
  1435. }
  1436. if (!appl) return false;
  1437. sendf(appl, _DISCONNECT_R | CONFIRM, Id, Number, "w", Info);
  1438. return false;
  1439. }
  1440. static byte disconnect_res(dword Id, word Number, DIVA_CAPI_ADAPTER *a,
  1441. PLCI *plci, APPL *appl, API_PARSE *msg)
  1442. {
  1443. dbug(1, dprintf("disconnect_res"));
  1444. if (plci)
  1445. {
  1446. /* clear ind mask bit, just in case of collsion of */
  1447. /* DISCONNECT_IND and CONNECT_RES */
  1448. clear_c_ind_mask_bit(plci, (word)(appl->Id - 1));
  1449. ncci_free_receive_buffers(plci, 0);
  1450. if (plci_remove_check(plci))
  1451. {
  1452. return 0;
  1453. }
  1454. if (plci->State == INC_DIS_PENDING
  1455. || plci->State == SUSPENDING) {
  1456. if (c_ind_mask_empty(plci)) {
  1457. if (plci->State != SUSPENDING) plci->State = IDLE;
  1458. dbug(1, dprintf("chs=%d", plci->channels));
  1459. if (!plci->channels) {
  1460. plci_remove(plci);
  1461. }
  1462. }
  1463. }
  1464. }
  1465. return 0;
  1466. }
  1467. static byte listen_req(dword Id, word Number, DIVA_CAPI_ADAPTER *a,
  1468. PLCI *plci, APPL *appl, API_PARSE *parms)
  1469. {
  1470. word Info;
  1471. byte i;
  1472. dbug(1, dprintf("listen_req(Appl=0x%x)", appl->Id));
  1473. Info = _WRONG_IDENTIFIER;
  1474. if (a) {
  1475. Info = 0;
  1476. a->Info_Mask[appl->Id - 1] = GET_DWORD(parms[0].info);
  1477. a->CIP_Mask[appl->Id - 1] = GET_DWORD(parms[1].info);
  1478. dbug(1, dprintf("CIP_MASK=0x%lx", GET_DWORD(parms[1].info)));
  1479. if (a->Info_Mask[appl->Id - 1] & 0x200) { /* early B3 connect provides */
  1480. a->Info_Mask[appl->Id - 1] |= 0x10; /* call progression infos */
  1481. }
  1482. /* check if external controller listen and switch listen on or off*/
  1483. if (Id&EXT_CONTROLLER && GET_DWORD(parms[1].info)) {
  1484. if (a->profile.Global_Options & ON_BOARD_CODEC) {
  1485. dummy_plci.State = IDLE;
  1486. a->codec_listen[appl->Id - 1] = &dummy_plci;
  1487. a->TelOAD[0] = (byte)(parms[3].length);
  1488. for (i = 1; parms[3].length >= i && i < 22; i++) {
  1489. a->TelOAD[i] = parms[3].info[i];
  1490. }
  1491. a->TelOAD[i] = 0;
  1492. a->TelOSA[0] = (byte)(parms[4].length);
  1493. for (i = 1; parms[4].length >= i && i < 22; i++) {
  1494. a->TelOSA[i] = parms[4].info[i];
  1495. }
  1496. a->TelOSA[i] = 0;
  1497. }
  1498. else Info = 0x2002; /* wrong controller, codec not supported */
  1499. }
  1500. else{ /* clear listen */
  1501. a->codec_listen[appl->Id - 1] = (PLCI *)0;
  1502. }
  1503. }
  1504. sendf(appl,
  1505. _LISTEN_R | CONFIRM,
  1506. Id,
  1507. Number,
  1508. "w", Info);
  1509. if (a) listen_check(a);
  1510. return false;
  1511. }
  1512. static byte info_req(dword Id, word Number, DIVA_CAPI_ADAPTER *a,
  1513. PLCI *plci, APPL *appl, API_PARSE *msg)
  1514. {
  1515. word i;
  1516. API_PARSE *ai;
  1517. PLCI *rc_plci = NULL;
  1518. API_PARSE ai_parms[5];
  1519. word Info = 0;
  1520. dbug(1, dprintf("info_req"));
  1521. for (i = 0; i < 5; i++) ai_parms[i].length = 0;
  1522. ai = &msg[1];
  1523. if (ai->length)
  1524. {
  1525. if (api_parse(&ai->info[1], (word)ai->length, "ssss", ai_parms))
  1526. {
  1527. dbug(1, dprintf("AddInfo wrong"));
  1528. Info = _WRONG_MESSAGE_FORMAT;
  1529. }
  1530. }
  1531. if (!a) Info = _WRONG_STATE;
  1532. if (!Info && plci)
  1533. { /* no fac, with CPN, or KEY */
  1534. rc_plci = plci;
  1535. if (!ai_parms[3].length && plci->State && (msg[0].length || ai_parms[1].length))
  1536. {
  1537. /* overlap sending option */
  1538. dbug(1, dprintf("OvlSnd"));
  1539. add_s(plci, CPN, &msg[0]);
  1540. add_s(plci, KEY, &ai_parms[1]);
  1541. sig_req(plci, INFO_REQ, 0);
  1542. send_req(plci);
  1543. return false;
  1544. }
  1545. if (plci->State && ai_parms[2].length)
  1546. {
  1547. /* User_Info option */
  1548. dbug(1, dprintf("UUI"));
  1549. add_s(plci, UUI, &ai_parms[2]);
  1550. sig_req(plci, USER_DATA, 0);
  1551. }
  1552. else if (plci->State && ai_parms[3].length)
  1553. {
  1554. /* Facility option */
  1555. dbug(1, dprintf("FAC"));
  1556. add_s(plci, CPN, &msg[0]);
  1557. add_ai(plci, &msg[1]);
  1558. sig_req(plci, FACILITY_REQ, 0);
  1559. }
  1560. else
  1561. {
  1562. Info = _WRONG_STATE;
  1563. }
  1564. }
  1565. else if ((ai_parms[1].length || ai_parms[2].length || ai_parms[3].length) && !Info)
  1566. {
  1567. /* NCR_Facility option -> send UUI and Keypad too */
  1568. dbug(1, dprintf("NCR_FAC"));
  1569. if ((i = get_plci(a)))
  1570. {
  1571. rc_plci = &a->plci[i - 1];
  1572. appl->NullCREnable = true;
  1573. rc_plci->internal_command = C_NCR_FAC_REQ;
  1574. rc_plci->appl = appl;
  1575. add_p(rc_plci, CAI, "\x01\x80");
  1576. add_p(rc_plci, UID, "\x06\x43\x61\x70\x69\x32\x30");
  1577. sig_req(rc_plci, ASSIGN, DSIG_ID);
  1578. send_req(rc_plci);
  1579. }
  1580. else
  1581. {
  1582. Info = _OUT_OF_PLCI;
  1583. }
  1584. if (!Info)
  1585. {
  1586. add_s(rc_plci, CPN, &msg[0]);
  1587. add_ai(rc_plci, &msg[1]);
  1588. sig_req(rc_plci, NCR_FACILITY, 0);
  1589. send_req(rc_plci);
  1590. return false;
  1591. /* for application controlled supplementary services */
  1592. }
  1593. }
  1594. if (!rc_plci)
  1595. {
  1596. Info = _WRONG_MESSAGE_FORMAT;
  1597. }
  1598. if (!Info)
  1599. {
  1600. send_req(rc_plci);
  1601. }
  1602. else
  1603. { /* appl is not assigned to a PLCI or error condition */
  1604. dbug(1, dprintf("localInfoCon"));
  1605. sendf(appl,
  1606. _INFO_R | CONFIRM,
  1607. Id,
  1608. Number,
  1609. "w", Info);
  1610. }
  1611. return false;
  1612. }
  1613. static byte info_res(dword Id, word Number, DIVA_CAPI_ADAPTER *a,
  1614. PLCI *plci, APPL *appl, API_PARSE *msg)
  1615. {
  1616. dbug(1, dprintf("info_res"));
  1617. return false;
  1618. }
  1619. static byte alert_req(dword Id, word Number, DIVA_CAPI_ADAPTER *a,
  1620. PLCI *plci, APPL *appl, API_PARSE *msg)
  1621. {
  1622. word Info;
  1623. byte ret;
  1624. dbug(1, dprintf("alert_req"));
  1625. Info = _WRONG_IDENTIFIER;
  1626. ret = false;
  1627. if (plci) {
  1628. Info = _ALERT_IGNORED;
  1629. if (plci->State != INC_CON_ALERT) {
  1630. Info = _WRONG_STATE;
  1631. if (plci->State == INC_CON_PENDING) {
  1632. Info = 0;
  1633. plci->State = INC_CON_ALERT;
  1634. add_ai(plci, &msg[0]);
  1635. sig_req(plci, CALL_ALERT, 0);
  1636. ret = 1;
  1637. }
  1638. }
  1639. }
  1640. sendf(appl,
  1641. _ALERT_R | CONFIRM,
  1642. Id,
  1643. Number,
  1644. "w", Info);
  1645. return ret;
  1646. }
  1647. static byte facility_req(dword Id, word Number, DIVA_CAPI_ADAPTER *a,
  1648. PLCI *plci, APPL *appl, API_PARSE *msg)
  1649. {
  1650. word Info = 0;
  1651. word i = 0;
  1652. word selector;
  1653. word SSreq;
  1654. long relatedPLCIvalue;
  1655. DIVA_CAPI_ADAPTER *relatedadapter;
  1656. byte *SSparms = "";
  1657. byte RCparms[] = "\x05\x00\x00\x02\x00\x00";
  1658. byte SSstruct[] = "\x09\x00\x00\x06\x00\x00\x00\x00\x00\x00";
  1659. API_PARSE *parms;
  1660. API_PARSE ss_parms[11];
  1661. PLCI *rplci;
  1662. byte cai[15];
  1663. dword d;
  1664. API_PARSE dummy;
  1665. dbug(1, dprintf("facility_req"));
  1666. for (i = 0; i < 9; i++) ss_parms[i].length = 0;
  1667. parms = &msg[1];
  1668. if (!a)
  1669. {
  1670. dbug(1, dprintf("wrong Ctrl"));
  1671. Info = _WRONG_IDENTIFIER;
  1672. }
  1673. selector = GET_WORD(msg[0].info);
  1674. if (!Info)
  1675. {
  1676. switch (selector)
  1677. {
  1678. case SELECTOR_HANDSET:
  1679. Info = AdvCodecSupport(a, plci, appl, HOOK_SUPPORT);
  1680. break;
  1681. case SELECTOR_SU_SERV:
  1682. if (!msg[1].length)
  1683. {
  1684. Info = _WRONG_MESSAGE_FORMAT;
  1685. break;
  1686. }
  1687. SSreq = GET_WORD(&(msg[1].info[1]));
  1688. PUT_WORD(&RCparms[1], SSreq);
  1689. SSparms = RCparms;
  1690. switch (SSreq)
  1691. {
  1692. case S_GET_SUPPORTED_SERVICES:
  1693. if ((i = get_plci(a)))
  1694. {
  1695. rplci = &a->plci[i - 1];
  1696. rplci->appl = appl;
  1697. add_p(rplci, CAI, "\x01\x80");
  1698. add_p(rplci, UID, "\x06\x43\x61\x70\x69\x32\x30");
  1699. sig_req(rplci, ASSIGN, DSIG_ID);
  1700. send_req(rplci);
  1701. }
  1702. else
  1703. {
  1704. PUT_DWORD(&SSstruct[6], MASK_TERMINAL_PORTABILITY);
  1705. SSparms = (byte *)SSstruct;
  1706. break;
  1707. }
  1708. rplci->internal_command = GETSERV_REQ_PEND;
  1709. rplci->number = Number;
  1710. rplci->appl = appl;
  1711. sig_req(rplci, S_SUPPORTED, 0);
  1712. send_req(rplci);
  1713. return false;
  1714. break;
  1715. case S_LISTEN:
  1716. if (parms->length == 7)
  1717. {
  1718. if (api_parse(&parms->info[1], (word)parms->length, "wbd", ss_parms))
  1719. {
  1720. dbug(1, dprintf("format wrong"));
  1721. Info = _WRONG_MESSAGE_FORMAT;
  1722. break;
  1723. }
  1724. }
  1725. else
  1726. {
  1727. Info = _WRONG_MESSAGE_FORMAT;
  1728. break;
  1729. }
  1730. a->Notification_Mask[appl->Id - 1] = GET_DWORD(ss_parms[2].info);
  1731. if (a->Notification_Mask[appl->Id - 1] & SMASK_MWI) /* MWI active? */
  1732. {
  1733. if ((i = get_plci(a)))
  1734. {
  1735. rplci = &a->plci[i - 1];
  1736. rplci->appl = appl;
  1737. add_p(rplci, CAI, "\x01\x80");
  1738. add_p(rplci, UID, "\x06\x43\x61\x70\x69\x32\x30");
  1739. sig_req(rplci, ASSIGN, DSIG_ID);
  1740. send_req(rplci);
  1741. }
  1742. else
  1743. {
  1744. break;
  1745. }
  1746. rplci->internal_command = GET_MWI_STATE;
  1747. rplci->number = Number;
  1748. sig_req(rplci, MWI_POLL, 0);
  1749. send_req(rplci);
  1750. }
  1751. break;
  1752. case S_HOLD:
  1753. api_parse(&parms->info[1], (word)parms->length, "ws", ss_parms);
  1754. if (plci && plci->State && plci->SuppState == IDLE)
  1755. {
  1756. plci->SuppState = HOLD_REQUEST;
  1757. plci->command = C_HOLD_REQ;
  1758. add_s(plci, CAI, &ss_parms[1]);
  1759. sig_req(plci, CALL_HOLD, 0);
  1760. send_req(plci);
  1761. return false;
  1762. }
  1763. else Info = 0x3010; /* wrong state */
  1764. break;
  1765. case S_RETRIEVE:
  1766. if (plci && plci->State && plci->SuppState == CALL_HELD)
  1767. {
  1768. if (Id & EXT_CONTROLLER)
  1769. {
  1770. if (AdvCodecSupport(a, plci, appl, 0))
  1771. {
  1772. Info = 0x3010; /* wrong state */
  1773. break;
  1774. }
  1775. }
  1776. else plci->tel = 0;
  1777. plci->SuppState = RETRIEVE_REQUEST;
  1778. plci->command = C_RETRIEVE_REQ;
  1779. if (plci->spoofed_msg == SPOOFING_REQUIRED)
  1780. {
  1781. plci->spoofed_msg = CALL_RETRIEVE;
  1782. plci->internal_command = BLOCK_PLCI;
  1783. plci->command = 0;
  1784. dbug(1, dprintf("Spoof"));
  1785. return false;
  1786. }
  1787. else
  1788. {
  1789. sig_req(plci, CALL_RETRIEVE, 0);
  1790. send_req(plci);
  1791. return false;
  1792. }
  1793. }
  1794. else Info = 0x3010; /* wrong state */
  1795. break;
  1796. case S_SUSPEND:
  1797. if (parms->length)
  1798. {
  1799. if (api_parse(&parms->info[1], (word)parms->length, "wbs", ss_parms))
  1800. {
  1801. dbug(1, dprintf("format wrong"));
  1802. Info = _WRONG_MESSAGE_FORMAT;
  1803. break;
  1804. }
  1805. }
  1806. if (plci && plci->State)
  1807. {
  1808. add_s(plci, CAI, &ss_parms[2]);
  1809. plci->command = SUSPEND_REQ;
  1810. sig_req(plci, SUSPEND, 0);
  1811. plci->State = SUSPENDING;
  1812. send_req(plci);
  1813. }
  1814. else Info = 0x3010; /* wrong state */
  1815. break;
  1816. case S_RESUME:
  1817. if (!(i = get_plci(a)))
  1818. {
  1819. Info = _OUT_OF_PLCI;
  1820. break;
  1821. }
  1822. rplci = &a->plci[i - 1];
  1823. rplci->appl = appl;
  1824. rplci->number = Number;
  1825. rplci->tel = 0;
  1826. rplci->call_dir = CALL_DIR_OUT | CALL_DIR_ORIGINATE;
  1827. /* check 'external controller' bit for codec support */
  1828. if (Id & EXT_CONTROLLER)
  1829. {
  1830. if (AdvCodecSupport(a, rplci, appl, 0))
  1831. {
  1832. rplci->Id = 0;
  1833. Info = 0x300A;
  1834. break;
  1835. }
  1836. }
  1837. if (parms->length)
  1838. {
  1839. if (api_parse(&parms->info[1], (word)parms->length, "wbs", ss_parms))
  1840. {
  1841. dbug(1, dprintf("format wrong"));
  1842. rplci->Id = 0;
  1843. Info = _WRONG_MESSAGE_FORMAT;
  1844. break;
  1845. }
  1846. }
  1847. dummy.length = 0;
  1848. dummy.info = "\x00";
  1849. add_b1(rplci, &dummy, 0, 0);
  1850. if (a->Info_Mask[appl->Id - 1] & 0x200)
  1851. {
  1852. /* early B3 connect (CIP mask bit 9) no release after a disc */
  1853. add_p(rplci, LLI, "\x01\x01");
  1854. }
  1855. add_p(rplci, UID, "\x06\x43\x61\x70\x69\x32\x30");
  1856. sig_req(rplci, ASSIGN, DSIG_ID);
  1857. send_req(rplci);
  1858. add_s(rplci, CAI, &ss_parms[2]);
  1859. rplci->command = RESUME_REQ;
  1860. sig_req(rplci, RESUME, 0);
  1861. rplci->State = RESUMING;
  1862. send_req(rplci);
  1863. break;
  1864. case S_CONF_BEGIN: /* Request */
  1865. case S_CONF_DROP:
  1866. case S_CONF_ISOLATE:
  1867. case S_CONF_REATTACH:
  1868. if (api_parse(&parms->info[1], (word)parms->length, "wbd", ss_parms))
  1869. {
  1870. dbug(1, dprintf("format wrong"));
  1871. Info = _WRONG_MESSAGE_FORMAT;
  1872. break;
  1873. }
  1874. if (plci && plci->State && ((plci->SuppState == IDLE) || (plci->SuppState == CALL_HELD)))
  1875. {
  1876. d = GET_DWORD(ss_parms[2].info);
  1877. if (d >= 0x80)
  1878. {
  1879. dbug(1, dprintf("format wrong"));
  1880. Info = _WRONG_MESSAGE_FORMAT;
  1881. break;
  1882. }
  1883. plci->ptyState = (byte)SSreq;
  1884. plci->command = 0;
  1885. cai[0] = 2;
  1886. switch (SSreq)
  1887. {
  1888. case S_CONF_BEGIN:
  1889. cai[1] = CONF_BEGIN;
  1890. plci->internal_command = CONF_BEGIN_REQ_PEND;
  1891. break;
  1892. case S_CONF_DROP:
  1893. cai[1] = CONF_DROP;
  1894. plci->internal_command = CONF_DROP_REQ_PEND;
  1895. break;
  1896. case S_CONF_ISOLATE:
  1897. cai[1] = CONF_ISOLATE;
  1898. plci->internal_command = CONF_ISOLATE_REQ_PEND;
  1899. break;
  1900. case S_CONF_REATTACH:
  1901. cai[1] = CONF_REATTACH;
  1902. plci->internal_command = CONF_REATTACH_REQ_PEND;
  1903. break;
  1904. }
  1905. cai[2] = (byte)d; /* Conference Size resp. PartyId */
  1906. add_p(plci, CAI, cai);
  1907. sig_req(plci, S_SERVICE, 0);
  1908. send_req(plci);
  1909. return false;
  1910. }
  1911. else Info = 0x3010; /* wrong state */
  1912. break;
  1913. case S_ECT:
  1914. case S_3PTY_BEGIN:
  1915. case S_3PTY_END:
  1916. case S_CONF_ADD:
  1917. if (parms->length == 7)
  1918. {
  1919. if (api_parse(&parms->info[1], (word)parms->length, "wbd", ss_parms))
  1920. {
  1921. dbug(1, dprintf("format wrong"));
  1922. Info = _WRONG_MESSAGE_FORMAT;
  1923. break;
  1924. }
  1925. }
  1926. else if (parms->length == 8) /* workaround for the T-View-S */
  1927. {
  1928. if (api_parse(&parms->info[1], (word)parms->length, "wbdb", ss_parms))
  1929. {
  1930. dbug(1, dprintf("format wrong"));
  1931. Info = _WRONG_MESSAGE_FORMAT;
  1932. break;
  1933. }
  1934. }
  1935. else
  1936. {
  1937. Info = _WRONG_MESSAGE_FORMAT;
  1938. break;
  1939. }
  1940. if (!msg[1].length)
  1941. {
  1942. Info = _WRONG_MESSAGE_FORMAT;
  1943. break;
  1944. }
  1945. if (!plci)
  1946. {
  1947. Info = _WRONG_IDENTIFIER;
  1948. break;
  1949. }
  1950. relatedPLCIvalue = GET_DWORD(ss_parms[2].info);
  1951. relatedPLCIvalue &= 0x0000FFFF;
  1952. dbug(1, dprintf("PTY/ECT/addCONF,relPLCI=%lx", relatedPLCIvalue));
  1953. /* controller starts with 0 up to (max_adapter - 1) */
  1954. if (((relatedPLCIvalue & 0x7f) == 0)
  1955. || (MapController((byte)(relatedPLCIvalue & 0x7f)) == 0)
  1956. || (MapController((byte)(relatedPLCIvalue & 0x7f)) > max_adapter))
  1957. {
  1958. if (SSreq == S_3PTY_END)
  1959. {
  1960. dbug(1, dprintf("wrong Controller use 2nd PLCI=PLCI"));
  1961. rplci = plci;
  1962. }
  1963. else
  1964. {
  1965. Info = 0x3010; /* wrong state */
  1966. break;
  1967. }
  1968. }
  1969. else
  1970. {
  1971. relatedadapter = &adapter[MapController((byte)(relatedPLCIvalue & 0x7f)) - 1];
  1972. relatedPLCIvalue >>= 8;
  1973. /* find PLCI PTR*/
  1974. for (i = 0, rplci = NULL; i < relatedadapter->max_plci; i++)
  1975. {
  1976. if (relatedadapter->plci[i].Id == (byte)relatedPLCIvalue)
  1977. {
  1978. rplci = &relatedadapter->plci[i];
  1979. }
  1980. }
  1981. if (!rplci || !relatedPLCIvalue)
  1982. {
  1983. if (SSreq == S_3PTY_END)
  1984. {
  1985. dbug(1, dprintf("use 2nd PLCI=PLCI"));
  1986. rplci = plci;
  1987. }
  1988. else
  1989. {
  1990. Info = 0x3010; /* wrong state */
  1991. break;
  1992. }
  1993. }
  1994. }
  1995. /*
  1996. dbug(1, dprintf("rplci:%x", rplci));
  1997. dbug(1, dprintf("plci:%x", plci));
  1998. dbug(1, dprintf("rplci->ptyState:%x", rplci->ptyState));
  1999. dbug(1, dprintf("plci->ptyState:%x", plci->ptyState));
  2000. dbug(1, dprintf("SSreq:%x", SSreq));
  2001. dbug(1, dprintf("rplci->internal_command:%x", rplci->internal_command));
  2002. dbug(1, dprintf("rplci->appl:%x", rplci->appl));
  2003. dbug(1, dprintf("rplci->Id:%x", rplci->Id));
  2004. */
  2005. /* send PTY/ECT req, cannot check all states because of US stuff */
  2006. if (!rplci->internal_command && rplci->appl)
  2007. {
  2008. plci->command = 0;
  2009. rplci->relatedPTYPLCI = plci;
  2010. plci->relatedPTYPLCI = rplci;
  2011. rplci->ptyState = (byte)SSreq;
  2012. if (SSreq == S_ECT)
  2013. {
  2014. rplci->internal_command = ECT_REQ_PEND;
  2015. cai[1] = ECT_EXECUTE;
  2016. rplci->vswitchstate = 0;
  2017. rplci->vsprot = 0;
  2018. rplci->vsprotdialect = 0;
  2019. plci->vswitchstate = 0;
  2020. plci->vsprot = 0;
  2021. plci->vsprotdialect = 0;
  2022. }
  2023. else if (SSreq == S_CONF_ADD)
  2024. {
  2025. rplci->internal_command = CONF_ADD_REQ_PEND;
  2026. cai[1] = CONF_ADD;
  2027. }
  2028. else
  2029. {
  2030. rplci->internal_command = PTY_REQ_PEND;
  2031. cai[1] = (byte)(SSreq - 3);
  2032. }
  2033. rplci->number = Number;
  2034. if (plci != rplci) /* explicit invocation */
  2035. {
  2036. cai[0] = 2;
  2037. cai[2] = plci->Sig.Id;
  2038. dbug(1, dprintf("explicit invocation"));
  2039. }
  2040. else
  2041. {
  2042. dbug(1, dprintf("implicit invocation"));
  2043. cai[0] = 1;
  2044. }
  2045. add_p(rplci, CAI, cai);
  2046. sig_req(rplci, S_SERVICE, 0);
  2047. send_req(rplci);
  2048. return false;
  2049. }
  2050. else
  2051. {
  2052. dbug(0, dprintf("Wrong line"));
  2053. Info = 0x3010; /* wrong state */
  2054. break;
  2055. }
  2056. break;
  2057. case S_CALL_DEFLECTION:
  2058. if (api_parse(&parms->info[1], (word)parms->length, "wbwss", ss_parms))
  2059. {
  2060. dbug(1, dprintf("format wrong"));
  2061. Info = _WRONG_MESSAGE_FORMAT;
  2062. break;
  2063. }
  2064. if (!plci)
  2065. {
  2066. Info = _WRONG_IDENTIFIER;
  2067. break;
  2068. }
  2069. /* reuse unused screening indicator */
  2070. ss_parms[3].info[3] = (byte)GET_WORD(&(ss_parms[2].info[0]));
  2071. plci->command = 0;
  2072. plci->internal_command = CD_REQ_PEND;
  2073. appl->CDEnable = true;
  2074. cai[0] = 1;
  2075. cai[1] = CALL_DEFLECTION;
  2076. add_p(plci, CAI, cai);
  2077. add_p(plci, CPN, ss_parms[3].info);
  2078. sig_req(plci, S_SERVICE, 0);
  2079. send_req(plci);
  2080. return false;
  2081. break;
  2082. case S_CALL_FORWARDING_START:
  2083. if (api_parse(&parms->info[1], (word)parms->length, "wbdwwsss", ss_parms))
  2084. {
  2085. dbug(1, dprintf("format wrong"));
  2086. Info = _WRONG_MESSAGE_FORMAT;
  2087. break;
  2088. }
  2089. if ((i = get_plci(a)))
  2090. {
  2091. rplci = &a->plci[i - 1];
  2092. rplci->appl = appl;
  2093. add_p(rplci, CAI, "\x01\x80");
  2094. add_p(rplci, UID, "\x06\x43\x61\x70\x69\x32\x30");
  2095. sig_req(rplci, ASSIGN, DSIG_ID);
  2096. send_req(rplci);
  2097. }
  2098. else
  2099. {
  2100. Info = _OUT_OF_PLCI;
  2101. break;
  2102. }
  2103. /* reuse unused screening indicator */
  2104. rplci->internal_command = CF_START_PEND;
  2105. rplci->appl = appl;
  2106. rplci->number = Number;
  2107. appl->S_Handle = GET_DWORD(&(ss_parms[2].info[0]));
  2108. cai[0] = 2;
  2109. cai[1] = 0x70 | (byte)GET_WORD(&(ss_parms[3].info[0])); /* Function */
  2110. cai[2] = (byte)GET_WORD(&(ss_parms[4].info[0])); /* Basic Service */
  2111. add_p(rplci, CAI, cai);
  2112. add_p(rplci, OAD, ss_parms[5].info);
  2113. add_p(rplci, CPN, ss_parms[6].info);
  2114. sig_req(rplci, S_SERVICE, 0);
  2115. send_req(rplci);
  2116. return false;
  2117. break;
  2118. case S_INTERROGATE_DIVERSION:
  2119. case S_INTERROGATE_NUMBERS:
  2120. case S_CALL_FORWARDING_STOP:
  2121. case S_CCBS_REQUEST:
  2122. case S_CCBS_DEACTIVATE:
  2123. case S_CCBS_INTERROGATE:
  2124. switch (SSreq)
  2125. {
  2126. case S_INTERROGATE_NUMBERS:
  2127. if (api_parse(&parms->info[1], (word)parms->length, "wbd", ss_parms))
  2128. {
  2129. dbug(0, dprintf("format wrong"));
  2130. Info = _WRONG_MESSAGE_FORMAT;
  2131. }
  2132. break;
  2133. case S_CCBS_REQUEST:
  2134. case S_CCBS_DEACTIVATE:
  2135. if (api_parse(&parms->info[1], (word)parms->length, "wbdw", ss_parms))
  2136. {
  2137. dbug(0, dprintf("format wrong"));
  2138. Info = _WRONG_MESSAGE_FORMAT;
  2139. }
  2140. break;
  2141. case S_CCBS_INTERROGATE:
  2142. if (api_parse(&parms->info[1], (word)parms->length, "wbdws", ss_parms))
  2143. {
  2144. dbug(0, dprintf("format wrong"));
  2145. Info = _WRONG_MESSAGE_FORMAT;
  2146. }
  2147. break;
  2148. default:
  2149. if (api_parse(&parms->info[1], (word)parms->length, "wbdwws", ss_parms))
  2150. {
  2151. dbug(0, dprintf("format wrong"));
  2152. Info = _WRONG_MESSAGE_FORMAT;
  2153. break;
  2154. }
  2155. break;
  2156. }
  2157. if (Info) break;
  2158. if ((i = get_plci(a)))
  2159. {
  2160. rplci = &a->plci[i - 1];
  2161. switch (SSreq)
  2162. {
  2163. case S_INTERROGATE_DIVERSION: /* use cai with S_SERVICE below */
  2164. cai[1] = 0x60 | (byte)GET_WORD(&(ss_parms[3].info[0])); /* Function */
  2165. rplci->internal_command = INTERR_DIVERSION_REQ_PEND; /* move to rplci if assigned */
  2166. break;
  2167. case S_INTERROGATE_NUMBERS: /* use cai with S_SERVICE below */
  2168. cai[1] = DIVERSION_INTERROGATE_NUM; /* Function */
  2169. rplci->internal_command = INTERR_NUMBERS_REQ_PEND; /* move to rplci if assigned */
  2170. break;
  2171. case S_CALL_FORWARDING_STOP:
  2172. rplci->internal_command = CF_STOP_PEND;
  2173. cai[1] = 0x80 | (byte)GET_WORD(&(ss_parms[3].info[0])); /* Function */
  2174. break;
  2175. case S_CCBS_REQUEST:
  2176. cai[1] = CCBS_REQUEST;
  2177. rplci->internal_command = CCBS_REQUEST_REQ_PEND;
  2178. break;
  2179. case S_CCBS_DEACTIVATE:
  2180. cai[1] = CCBS_DEACTIVATE;
  2181. rplci->internal_command = CCBS_DEACTIVATE_REQ_PEND;
  2182. break;
  2183. case S_CCBS_INTERROGATE:
  2184. cai[1] = CCBS_INTERROGATE;
  2185. rplci->internal_command = CCBS_INTERROGATE_REQ_PEND;
  2186. break;
  2187. default:
  2188. cai[1] = 0;
  2189. break;
  2190. }
  2191. rplci->appl = appl;
  2192. rplci->number = Number;
  2193. add_p(rplci, CAI, "\x01\x80");
  2194. add_p(rplci, UID, "\x06\x43\x61\x70\x69\x32\x30");
  2195. sig_req(rplci, ASSIGN, DSIG_ID);
  2196. send_req(rplci);
  2197. }
  2198. else
  2199. {
  2200. Info = _OUT_OF_PLCI;
  2201. break;
  2202. }
  2203. appl->S_Handle = GET_DWORD(&(ss_parms[2].info[0]));
  2204. switch (SSreq)
  2205. {
  2206. case S_INTERROGATE_NUMBERS:
  2207. cai[0] = 1;
  2208. add_p(rplci, CAI, cai);
  2209. break;
  2210. case S_CCBS_REQUEST:
  2211. case S_CCBS_DEACTIVATE:
  2212. cai[0] = 3;
  2213. PUT_WORD(&cai[2], GET_WORD(&(ss_parms[3].info[0])));
  2214. add_p(rplci, CAI, cai);
  2215. break;
  2216. case S_CCBS_INTERROGATE:
  2217. cai[0] = 3;
  2218. PUT_WORD(&cai[2], GET_WORD(&(ss_parms[3].info[0])));
  2219. add_p(rplci, CAI, cai);
  2220. add_p(rplci, OAD, ss_parms[4].info);
  2221. break;
  2222. default:
  2223. cai[0] = 2;
  2224. cai[2] = (byte)GET_WORD(&(ss_parms[4].info[0])); /* Basic Service */
  2225. add_p(rplci, CAI, cai);
  2226. add_p(rplci, OAD, ss_parms[5].info);
  2227. break;
  2228. }
  2229. sig_req(rplci, S_SERVICE, 0);
  2230. send_req(rplci);
  2231. return false;
  2232. break;
  2233. case S_MWI_ACTIVATE:
  2234. if (api_parse(&parms->info[1], (word)parms->length, "wbwdwwwssss", ss_parms))
  2235. {
  2236. dbug(1, dprintf("format wrong"));
  2237. Info = _WRONG_MESSAGE_FORMAT;
  2238. break;
  2239. }
  2240. if (!plci)
  2241. {
  2242. if ((i = get_plci(a)))
  2243. {
  2244. rplci = &a->plci[i - 1];
  2245. rplci->appl = appl;
  2246. rplci->cr_enquiry = true;
  2247. add_p(rplci, CAI, "\x01\x80");
  2248. add_p(rplci, UID, "\x06\x43\x61\x70\x69\x32\x30");
  2249. sig_req(rplci, ASSIGN, DSIG_ID);
  2250. send_req(rplci);
  2251. }
  2252. else
  2253. {
  2254. Info = _OUT_OF_PLCI;
  2255. break;
  2256. }
  2257. }
  2258. else
  2259. {
  2260. rplci = plci;
  2261. rplci->cr_enquiry = false;
  2262. }
  2263. rplci->command = 0;
  2264. rplci->internal_command = MWI_ACTIVATE_REQ_PEND;
  2265. rplci->appl = appl;
  2266. rplci->number = Number;
  2267. cai[0] = 13;
  2268. cai[1] = ACTIVATION_MWI; /* Function */
  2269. PUT_WORD(&cai[2], GET_WORD(&(ss_parms[2].info[0]))); /* Basic Service */
  2270. PUT_DWORD(&cai[4], GET_DWORD(&(ss_parms[3].info[0]))); /* Number of Messages */
  2271. PUT_WORD(&cai[8], GET_WORD(&(ss_parms[4].info[0]))); /* Message Status */
  2272. PUT_WORD(&cai[10], GET_WORD(&(ss_parms[5].info[0]))); /* Message Reference */
  2273. PUT_WORD(&cai[12], GET_WORD(&(ss_parms[6].info[0]))); /* Invocation Mode */
  2274. add_p(rplci, CAI, cai);
  2275. add_p(rplci, CPN, ss_parms[7].info); /* Receiving User Number */
  2276. add_p(rplci, OAD, ss_parms[8].info); /* Controlling User Number */
  2277. add_p(rplci, OSA, ss_parms[9].info); /* Controlling User Provided Number */
  2278. add_p(rplci, UID, ss_parms[10].info); /* Time */
  2279. sig_req(rplci, S_SERVICE, 0);
  2280. send_req(rplci);
  2281. return false;
  2282. case S_MWI_DEACTIVATE:
  2283. if (api_parse(&parms->info[1], (word)parms->length, "wbwwss", ss_parms))
  2284. {
  2285. dbug(1, dprintf("format wrong"));
  2286. Info = _WRONG_MESSAGE_FORMAT;
  2287. break;
  2288. }
  2289. if (!plci)
  2290. {
  2291. if ((i = get_plci(a)))
  2292. {
  2293. rplci = &a->plci[i - 1];
  2294. rplci->appl = appl;
  2295. rplci->cr_enquiry = true;
  2296. add_p(rplci, CAI, "\x01\x80");
  2297. add_p(rplci, UID, "\x06\x43\x61\x70\x69\x32\x30");
  2298. sig_req(rplci, ASSIGN, DSIG_ID);
  2299. send_req(rplci);
  2300. }
  2301. else
  2302. {
  2303. Info = _OUT_OF_PLCI;
  2304. break;
  2305. }
  2306. }
  2307. else
  2308. {
  2309. rplci = plci;
  2310. rplci->cr_enquiry = false;
  2311. }
  2312. rplci->command = 0;
  2313. rplci->internal_command = MWI_DEACTIVATE_REQ_PEND;
  2314. rplci->appl = appl;
  2315. rplci->number = Number;
  2316. cai[0] = 5;
  2317. cai[1] = DEACTIVATION_MWI; /* Function */
  2318. PUT_WORD(&cai[2], GET_WORD(&(ss_parms[2].info[0]))); /* Basic Service */
  2319. PUT_WORD(&cai[4], GET_WORD(&(ss_parms[3].info[0]))); /* Invocation Mode */
  2320. add_p(rplci, CAI, cai);
  2321. add_p(rplci, CPN, ss_parms[4].info); /* Receiving User Number */
  2322. add_p(rplci, OAD, ss_parms[5].info); /* Controlling User Number */
  2323. sig_req(rplci, S_SERVICE, 0);
  2324. send_req(rplci);
  2325. return false;
  2326. default:
  2327. Info = 0x300E; /* not supported */
  2328. break;
  2329. }
  2330. break; /* case SELECTOR_SU_SERV: end */
  2331. case SELECTOR_DTMF:
  2332. return (dtmf_request(Id, Number, a, plci, appl, msg));
  2333. case SELECTOR_LINE_INTERCONNECT:
  2334. return (mixer_request(Id, Number, a, plci, appl, msg));
  2335. case PRIV_SELECTOR_ECHO_CANCELLER:
  2336. appl->appl_flags |= APPL_FLAG_PRIV_EC_SPEC;
  2337. return (ec_request(Id, Number, a, plci, appl, msg));
  2338. case SELECTOR_ECHO_CANCELLER:
  2339. appl->appl_flags &= ~APPL_FLAG_PRIV_EC_SPEC;
  2340. return (ec_request(Id, Number, a, plci, appl, msg));
  2341. case SELECTOR_V42BIS:
  2342. default:
  2343. Info = _FACILITY_NOT_SUPPORTED;
  2344. break;
  2345. } /* end of switch (selector) */
  2346. }
  2347. dbug(1, dprintf("SendFacRc"));
  2348. sendf(appl,
  2349. _FACILITY_R | CONFIRM,
  2350. Id,
  2351. Number,
  2352. "wws", Info, selector, SSparms);
  2353. return false;
  2354. }
  2355. static byte facility_res(dword Id, word Number, DIVA_CAPI_ADAPTER *a,
  2356. PLCI *plci, APPL *appl, API_PARSE *msg)
  2357. {
  2358. dbug(1, dprintf("facility_res"));
  2359. return false;
  2360. }
  2361. static byte connect_b3_req(dword Id, word Number, DIVA_CAPI_ADAPTER *a,
  2362. PLCI *plci, APPL *appl, API_PARSE *parms)
  2363. {
  2364. word Info = 0;
  2365. byte req;
  2366. byte len;
  2367. word w;
  2368. word fax_control_bits, fax_feature_bits, fax_info_change;
  2369. API_PARSE *ncpi;
  2370. byte pvc[2];
  2371. API_PARSE fax_parms[9];
  2372. word i;
  2373. dbug(1, dprintf("connect_b3_req"));
  2374. if (plci)
  2375. {
  2376. if ((plci->State == IDLE) || (plci->State == OUTG_DIS_PENDING)
  2377. || (plci->State == INC_DIS_PENDING) || (plci->SuppState != IDLE))
  2378. {
  2379. Info = _WRONG_STATE;
  2380. }
  2381. else
  2382. {
  2383. /* local reply if assign unsuccessful
  2384. or B3 protocol allows only one layer 3 connection
  2385. and already connected
  2386. or B2 protocol not any LAPD
  2387. and connect_b3_req contradicts originate/answer direction */
  2388. if (!plci->NL.Id
  2389. || (((plci->B3_prot != B3_T90NL) && (plci->B3_prot != B3_ISO8208) && (plci->B3_prot != B3_X25_DCE))
  2390. && ((plci->channels != 0)
  2391. || (((plci->B2_prot != B2_SDLC) && (plci->B2_prot != B2_LAPD) && (plci->B2_prot != B2_LAPD_FREE_SAPI_SEL))
  2392. && ((plci->call_dir & CALL_DIR_ANSWER) && !(plci->call_dir & CALL_DIR_FORCE_OUTG_NL))))))
  2393. {
  2394. dbug(1, dprintf("B3 already connected=%d or no NL.Id=0x%x, dir=%d sstate=0x%x",
  2395. plci->channels, plci->NL.Id, plci->call_dir, plci->SuppState));
  2396. Info = _WRONG_STATE;
  2397. sendf(appl,
  2398. _CONNECT_B3_R | CONFIRM,
  2399. Id,
  2400. Number,
  2401. "w", Info);
  2402. return false;
  2403. }
  2404. plci->requested_options_conn = 0;
  2405. req = N_CONNECT;
  2406. ncpi = &parms[0];
  2407. if (plci->B3_prot == 2 || plci->B3_prot == 3)
  2408. {
  2409. if (ncpi->length > 2)
  2410. {
  2411. /* check for PVC */
  2412. if (ncpi->info[2] || ncpi->info[3])
  2413. {
  2414. pvc[0] = ncpi->info[3];
  2415. pvc[1] = ncpi->info[2];
  2416. add_d(plci, 2, pvc);
  2417. req = N_RESET;
  2418. }
  2419. else
  2420. {
  2421. if (ncpi->info[1] & 1) req = N_CONNECT | N_D_BIT;
  2422. add_d(plci, (word)(ncpi->length - 3), &ncpi->info[4]);
  2423. }
  2424. }
  2425. }
  2426. else if (plci->B3_prot == 5)
  2427. {
  2428. if (plci->NL.Id && !plci->nl_remove_id)
  2429. {
  2430. fax_control_bits = GET_WORD(&((T30_INFO *)plci->fax_connect_info_buffer)->control_bits_low);
  2431. fax_feature_bits = GET_WORD(&((T30_INFO *)plci->fax_connect_info_buffer)->feature_bits_low);
  2432. if (!(fax_control_bits & T30_CONTROL_BIT_MORE_DOCUMENTS)
  2433. || (fax_feature_bits & T30_FEATURE_BIT_MORE_DOCUMENTS))
  2434. {
  2435. len = offsetof(T30_INFO, universal_6);
  2436. fax_info_change = false;
  2437. if (ncpi->length >= 4)
  2438. {
  2439. w = GET_WORD(&ncpi->info[3]);
  2440. if ((w & 0x0001) != ((word)(((T30_INFO *)(plci->fax_connect_info_buffer))->resolution & 0x0001)))
  2441. {
  2442. ((T30_INFO *)(plci->fax_connect_info_buffer))->resolution =
  2443. (byte)((((T30_INFO *)(plci->fax_connect_info_buffer))->resolution & ~T30_RESOLUTION_R8_0770_OR_200) |
  2444. ((w & 0x0001) ? T30_RESOLUTION_R8_0770_OR_200 : 0));
  2445. fax_info_change = true;
  2446. }
  2447. fax_control_bits &= ~(T30_CONTROL_BIT_REQUEST_POLLING | T30_CONTROL_BIT_MORE_DOCUMENTS);
  2448. if (w & 0x0002) /* Fax-polling request */
  2449. fax_control_bits |= T30_CONTROL_BIT_REQUEST_POLLING;
  2450. if ((w & 0x0004) /* Request to send / poll another document */
  2451. && (a->manufacturer_features & MANUFACTURER_FEATURE_FAX_MORE_DOCUMENTS))
  2452. {
  2453. fax_control_bits |= T30_CONTROL_BIT_MORE_DOCUMENTS;
  2454. }
  2455. if (ncpi->length >= 6)
  2456. {
  2457. w = GET_WORD(&ncpi->info[5]);
  2458. if (((byte) w) != ((T30_INFO *)(plci->fax_connect_info_buffer))->data_format)
  2459. {
  2460. ((T30_INFO *)(plci->fax_connect_info_buffer))->data_format = (byte) w;
  2461. fax_info_change = true;
  2462. }
  2463. if ((a->man_profile.private_options & (1L << PRIVATE_FAX_SUB_SEP_PWD))
  2464. && (GET_WORD(&ncpi->info[5]) & 0x8000)) /* Private SEP/SUB/PWD enable */
  2465. {
  2466. plci->requested_options_conn |= (1L << PRIVATE_FAX_SUB_SEP_PWD);
  2467. }
  2468. if ((a->man_profile.private_options & (1L << PRIVATE_FAX_NONSTANDARD))
  2469. && (GET_WORD(&ncpi->info[5]) & 0x4000)) /* Private non-standard facilities enable */
  2470. {
  2471. plci->requested_options_conn |= (1L << PRIVATE_FAX_NONSTANDARD);
  2472. }
  2473. fax_control_bits &= ~(T30_CONTROL_BIT_ACCEPT_SUBADDRESS | T30_CONTROL_BIT_ACCEPT_SEL_POLLING |
  2474. T30_CONTROL_BIT_ACCEPT_PASSWORD);
  2475. if ((plci->requested_options_conn | plci->requested_options | a->requested_options_table[appl->Id - 1])
  2476. & ((1L << PRIVATE_FAX_SUB_SEP_PWD) | (1L << PRIVATE_FAX_NONSTANDARD)))
  2477. {
  2478. if (api_parse(&ncpi->info[1], ncpi->length, "wwwwsss", fax_parms))
  2479. Info = _WRONG_MESSAGE_FORMAT;
  2480. else
  2481. {
  2482. if ((plci->requested_options_conn | plci->requested_options | a->requested_options_table[appl->Id - 1])
  2483. & (1L << PRIVATE_FAX_SUB_SEP_PWD))
  2484. {
  2485. fax_control_bits |= T30_CONTROL_BIT_ACCEPT_SUBADDRESS | T30_CONTROL_BIT_ACCEPT_PASSWORD;
  2486. if (fax_control_bits & T30_CONTROL_BIT_ACCEPT_POLLING)
  2487. fax_control_bits |= T30_CONTROL_BIT_ACCEPT_SEL_POLLING;
  2488. }
  2489. w = fax_parms[4].length;
  2490. if (w > 20)
  2491. w = 20;
  2492. ((T30_INFO *)(plci->fax_connect_info_buffer))->station_id_len = (byte) w;
  2493. for (i = 0; i < w; i++)
  2494. ((T30_INFO *)(plci->fax_connect_info_buffer))->station_id[i] = fax_parms[4].info[1 + i];
  2495. ((T30_INFO *)(plci->fax_connect_info_buffer))->head_line_len = 0;
  2496. len = offsetof(T30_INFO, station_id) + T30_MAX_STATION_ID_LENGTH;
  2497. w = fax_parms[5].length;
  2498. if (w > 20)
  2499. w = 20;
  2500. plci->fax_connect_info_buffer[len++] = (byte) w;
  2501. for (i = 0; i < w; i++)
  2502. plci->fax_connect_info_buffer[len++] = fax_parms[5].info[1 + i];
  2503. w = fax_parms[6].length;
  2504. if (w > 20)
  2505. w = 20;
  2506. plci->fax_connect_info_buffer[len++] = (byte) w;
  2507. for (i = 0; i < w; i++)
  2508. plci->fax_connect_info_buffer[len++] = fax_parms[6].info[1 + i];
  2509. if ((plci->requested_options_conn | plci->requested_options | a->requested_options_table[appl->Id - 1])
  2510. & (1L << PRIVATE_FAX_NONSTANDARD))
  2511. {
  2512. if (api_parse(&ncpi->info[1], ncpi->length, "wwwwssss", fax_parms))
  2513. {
  2514. dbug(1, dprintf("non-standard facilities info missing or wrong format"));
  2515. plci->fax_connect_info_buffer[len++] = 0;
  2516. }
  2517. else
  2518. {
  2519. if ((fax_parms[7].length >= 3) && (fax_parms[7].info[1] >= 2))
  2520. plci->nsf_control_bits = GET_WORD(&fax_parms[7].info[2]);
  2521. plci->fax_connect_info_buffer[len++] = (byte)(fax_parms[7].length);
  2522. for (i = 0; i < fax_parms[7].length; i++)
  2523. plci->fax_connect_info_buffer[len++] = fax_parms[7].info[1 + i];
  2524. }
  2525. }
  2526. }
  2527. }
  2528. else
  2529. {
  2530. len = offsetof(T30_INFO, universal_6);
  2531. }
  2532. fax_info_change = true;
  2533. }
  2534. if (fax_control_bits != GET_WORD(&((T30_INFO *)plci->fax_connect_info_buffer)->control_bits_low))
  2535. {
  2536. PUT_WORD(&((T30_INFO *)plci->fax_connect_info_buffer)->control_bits_low, fax_control_bits);
  2537. fax_info_change = true;
  2538. }
  2539. }
  2540. if (Info == GOOD)
  2541. {
  2542. plci->fax_connect_info_length = len;
  2543. if (fax_info_change)
  2544. {
  2545. if (fax_feature_bits & T30_FEATURE_BIT_MORE_DOCUMENTS)
  2546. {
  2547. start_internal_command(Id, plci, fax_connect_info_command);
  2548. return false;
  2549. }
  2550. else
  2551. {
  2552. start_internal_command(Id, plci, fax_adjust_b23_command);
  2553. return false;
  2554. }
  2555. }
  2556. }
  2557. }
  2558. else Info = _WRONG_STATE;
  2559. }
  2560. else Info = _WRONG_STATE;
  2561. }
  2562. else if (plci->B3_prot == B3_RTP)
  2563. {
  2564. plci->internal_req_buffer[0] = ncpi->length + 1;
  2565. plci->internal_req_buffer[1] = UDATA_REQUEST_RTP_RECONFIGURE;
  2566. for (w = 0; w < ncpi->length; w++)
  2567. plci->internal_req_buffer[2 + w] = ncpi->info[1 + w];
  2568. start_internal_command(Id, plci, rtp_connect_b3_req_command);
  2569. return false;
  2570. }
  2571. if (!Info)
  2572. {
  2573. nl_req_ncci(plci, req, 0);
  2574. return 1;
  2575. }
  2576. }
  2577. }
  2578. else Info = _WRONG_IDENTIFIER;
  2579. sendf(appl,
  2580. _CONNECT_B3_R | CONFIRM,
  2581. Id,
  2582. Number,
  2583. "w", Info);
  2584. return false;
  2585. }
  2586. static byte connect_b3_res(dword Id, word Number, DIVA_CAPI_ADAPTER *a,
  2587. PLCI *plci, APPL *appl, API_PARSE *parms)
  2588. {
  2589. word ncci;
  2590. API_PARSE *ncpi;
  2591. byte req;
  2592. word w;
  2593. API_PARSE fax_parms[9];
  2594. word i;
  2595. byte len;
  2596. dbug(1, dprintf("connect_b3_res"));
  2597. ncci = (word)(Id >> 16);
  2598. if (plci && ncci) {
  2599. if (a->ncci_state[ncci] == INC_CON_PENDING) {
  2600. if (GET_WORD(&parms[0].info[0]) != 0)
  2601. {
  2602. a->ncci_state[ncci] = OUTG_REJ_PENDING;
  2603. channel_request_xon(plci, a->ncci_ch[ncci]);
  2604. channel_xmit_xon(plci);
  2605. cleanup_ncci_data(plci, ncci);
  2606. nl_req_ncci(plci, N_DISC, (byte)ncci);
  2607. return 1;
  2608. }
  2609. a->ncci_state[ncci] = INC_ACT_PENDING;
  2610. req = N_CONNECT_ACK;
  2611. ncpi = &parms[1];
  2612. if ((plci->B3_prot == 4) || (plci->B3_prot == 5) || (plci->B3_prot == 7))
  2613. {
  2614. if ((plci->requested_options_conn | plci->requested_options | a->requested_options_table[plci->appl->Id - 1])
  2615. & (1L << PRIVATE_FAX_NONSTANDARD))
  2616. {
  2617. if (((plci->B3_prot == 4) || (plci->B3_prot == 5))
  2618. && (plci->nsf_control_bits & T30_NSF_CONTROL_BIT_ENABLE_NSF)
  2619. && (plci->nsf_control_bits & T30_NSF_CONTROL_BIT_NEGOTIATE_RESP))
  2620. {
  2621. len = offsetof(T30_INFO, station_id) + T30_MAX_STATION_ID_LENGTH;
  2622. if (plci->fax_connect_info_length < len)
  2623. {
  2624. ((T30_INFO *)(plci->fax_connect_info_buffer))->station_id_len = 0;
  2625. ((T30_INFO *)(plci->fax_connect_info_buffer))->head_line_len = 0;
  2626. }
  2627. if (api_parse(&ncpi->info[1], ncpi->length, "wwwwssss", fax_parms))
  2628. {
  2629. dbug(1, dprintf("non-standard facilities info missing or wrong format"));
  2630. }
  2631. else
  2632. {
  2633. if (plci->fax_connect_info_length <= len)
  2634. plci->fax_connect_info_buffer[len] = 0;
  2635. len += 1 + plci->fax_connect_info_buffer[len];
  2636. if (plci->fax_connect_info_length <= len)
  2637. plci->fax_connect_info_buffer[len] = 0;
  2638. len += 1 + plci->fax_connect_info_buffer[len];
  2639. if ((fax_parms[7].length >= 3) && (fax_parms[7].info[1] >= 2))
  2640. plci->nsf_control_bits = GET_WORD(&fax_parms[7].info[2]);
  2641. plci->fax_connect_info_buffer[len++] = (byte)(fax_parms[7].length);
  2642. for (i = 0; i < fax_parms[7].length; i++)
  2643. plci->fax_connect_info_buffer[len++] = fax_parms[7].info[1 + i];
  2644. }
  2645. plci->fax_connect_info_length = len;
  2646. ((T30_INFO *)(plci->fax_connect_info_buffer))->code = 0;
  2647. start_internal_command(Id, plci, fax_connect_ack_command);
  2648. return false;
  2649. }
  2650. }
  2651. nl_req_ncci(plci, req, (byte)ncci);
  2652. if ((plci->ncpi_state & NCPI_VALID_CONNECT_B3_ACT)
  2653. && !(plci->ncpi_state & NCPI_CONNECT_B3_ACT_SENT))
  2654. {
  2655. if (plci->B3_prot == 4)
  2656. sendf(appl, _CONNECT_B3_ACTIVE_I, Id, 0, "s", "");
  2657. else
  2658. sendf(appl, _CONNECT_B3_ACTIVE_I, Id, 0, "S", plci->ncpi_buffer);
  2659. plci->ncpi_state |= NCPI_CONNECT_B3_ACT_SENT;
  2660. }
  2661. }
  2662. else if (plci->B3_prot == B3_RTP)
  2663. {
  2664. plci->internal_req_buffer[0] = ncpi->length + 1;
  2665. plci->internal_req_buffer[1] = UDATA_REQUEST_RTP_RECONFIGURE;
  2666. for (w = 0; w < ncpi->length; w++)
  2667. plci->internal_req_buffer[2 + w] = ncpi->info[1+w];
  2668. start_internal_command(Id, plci, rtp_connect_b3_res_command);
  2669. return false;
  2670. }
  2671. else
  2672. {
  2673. if (ncpi->length > 2) {
  2674. if (ncpi->info[1] & 1) req = N_CONNECT_ACK | N_D_BIT;
  2675. add_d(plci, (word)(ncpi->length - 3), &ncpi->info[4]);
  2676. }
  2677. nl_req_ncci(plci, req, (byte)ncci);
  2678. sendf(appl, _CONNECT_B3_ACTIVE_I, Id, 0, "s", "");
  2679. if (plci->adjust_b_restore)
  2680. {
  2681. plci->adjust_b_restore = false;
  2682. start_internal_command(Id, plci, adjust_b_restore);
  2683. }
  2684. }
  2685. return 1;
  2686. }
  2687. }
  2688. return false;
  2689. }
  2690. static byte connect_b3_a_res(dword Id, word Number, DIVA_CAPI_ADAPTER *a,
  2691. PLCI *plci, APPL *appl, API_PARSE *parms)
  2692. {
  2693. word ncci;
  2694. ncci = (word)(Id >> 16);
  2695. dbug(1, dprintf("connect_b3_a_res(ncci=0x%x)", ncci));
  2696. if (plci && ncci && (plci->State != IDLE) && (plci->State != INC_DIS_PENDING)
  2697. && (plci->State != OUTG_DIS_PENDING))
  2698. {
  2699. if (a->ncci_state[ncci] == INC_ACT_PENDING) {
  2700. a->ncci_state[ncci] = CONNECTED;
  2701. if (plci->State != INC_CON_CONNECTED_ALERT) plci->State = CONNECTED;
  2702. channel_request_xon(plci, a->ncci_ch[ncci]);
  2703. channel_xmit_xon(plci);
  2704. }
  2705. }
  2706. return false;
  2707. }
  2708. static byte disconnect_b3_req(dword Id, word Number, DIVA_CAPI_ADAPTER *a,
  2709. PLCI *plci, APPL *appl, API_PARSE *parms)
  2710. {
  2711. word Info;
  2712. word ncci;
  2713. API_PARSE *ncpi;
  2714. dbug(1, dprintf("disconnect_b3_req"));
  2715. Info = _WRONG_IDENTIFIER;
  2716. ncci = (word)(Id >> 16);
  2717. if (plci && ncci)
  2718. {
  2719. Info = _WRONG_STATE;
  2720. if ((a->ncci_state[ncci] == CONNECTED)
  2721. || (a->ncci_state[ncci] == OUTG_CON_PENDING)
  2722. || (a->ncci_state[ncci] == INC_CON_PENDING)
  2723. || (a->ncci_state[ncci] == INC_ACT_PENDING))
  2724. {
  2725. a->ncci_state[ncci] = OUTG_DIS_PENDING;
  2726. channel_request_xon(plci, a->ncci_ch[ncci]);
  2727. channel_xmit_xon(plci);
  2728. if (a->ncci[ncci].data_pending
  2729. && ((plci->B3_prot == B3_TRANSPARENT)
  2730. || (plci->B3_prot == B3_T30)
  2731. || (plci->B3_prot == B3_T30_WITH_EXTENSIONS)))
  2732. {
  2733. plci->send_disc = (byte)ncci;
  2734. plci->command = 0;
  2735. return false;
  2736. }
  2737. else
  2738. {
  2739. cleanup_ncci_data(plci, ncci);
  2740. if (plci->B3_prot == 2 || plci->B3_prot == 3)
  2741. {
  2742. ncpi = &parms[0];
  2743. if (ncpi->length > 3)
  2744. {
  2745. add_d(plci, (word)(ncpi->length - 3), (byte *)&(ncpi->info[4]));
  2746. }
  2747. }
  2748. nl_req_ncci(plci, N_DISC, (byte)ncci);
  2749. }
  2750. return 1;
  2751. }
  2752. }
  2753. sendf(appl,
  2754. _DISCONNECT_B3_R | CONFIRM,
  2755. Id,
  2756. Number,
  2757. "w", Info);
  2758. return false;
  2759. }
  2760. static byte disconnect_b3_res(dword Id, word Number, DIVA_CAPI_ADAPTER *a,
  2761. PLCI *plci, APPL *appl, API_PARSE *parms)
  2762. {
  2763. word ncci;
  2764. word i;
  2765. ncci = (word)(Id >> 16);
  2766. dbug(1, dprintf("disconnect_b3_res(ncci=0x%x", ncci));
  2767. if (plci && ncci) {
  2768. plci->requested_options_conn = 0;
  2769. plci->fax_connect_info_length = 0;
  2770. plci->ncpi_state = 0x00;
  2771. if (((plci->B3_prot != B3_T90NL) && (plci->B3_prot != B3_ISO8208) && (plci->B3_prot != B3_X25_DCE))
  2772. && ((plci->B2_prot != B2_LAPD) && (plci->B2_prot != B2_LAPD_FREE_SAPI_SEL)))
  2773. {
  2774. plci->call_dir |= CALL_DIR_FORCE_OUTG_NL;
  2775. }
  2776. for (i = 0; i < MAX_CHANNELS_PER_PLCI && plci->inc_dis_ncci_table[i] != (byte)ncci; i++);
  2777. if (i < MAX_CHANNELS_PER_PLCI) {
  2778. if (plci->channels)plci->channels--;
  2779. for (; i < MAX_CHANNELS_PER_PLCI - 1; i++) plci->inc_dis_ncci_table[i] = plci->inc_dis_ncci_table[i + 1];
  2780. plci->inc_dis_ncci_table[MAX_CHANNELS_PER_PLCI - 1] = 0;
  2781. ncci_free_receive_buffers(plci, ncci);
  2782. if ((plci->State == IDLE || plci->State == SUSPENDING) && !plci->channels) {
  2783. if (plci->State == SUSPENDING) {
  2784. sendf(plci->appl,
  2785. _FACILITY_I,
  2786. Id & 0xffffL,
  2787. 0,
  2788. "ws", (word)3, "\x03\x04\x00\x00");
  2789. sendf(plci->appl, _DISCONNECT_I, Id & 0xffffL, 0, "w", 0);
  2790. }
  2791. plci_remove(plci);
  2792. plci->State = IDLE;
  2793. }
  2794. }
  2795. else
  2796. {
  2797. if ((a->manufacturer_features & MANUFACTURER_FEATURE_FAX_PAPER_FORMATS)
  2798. && ((plci->B3_prot == 4) || (plci->B3_prot == 5))
  2799. && (a->ncci_state[ncci] == INC_DIS_PENDING))
  2800. {
  2801. ncci_free_receive_buffers(plci, ncci);
  2802. nl_req_ncci(plci, N_EDATA, (byte)ncci);
  2803. plci->adapter->ncci_state[ncci] = IDLE;
  2804. start_internal_command(Id, plci, fax_disconnect_command);
  2805. return 1;
  2806. }
  2807. }
  2808. }
  2809. return false;
  2810. }
  2811. static byte data_b3_req(dword Id, word Number, DIVA_CAPI_ADAPTER *a,
  2812. PLCI *plci, APPL *appl, API_PARSE *parms)
  2813. {
  2814. NCCI *ncci_ptr;
  2815. DATA_B3_DESC *data;
  2816. word Info;
  2817. word ncci;
  2818. word i;
  2819. dbug(1, dprintf("data_b3_req"));
  2820. Info = _WRONG_IDENTIFIER;
  2821. ncci = (word)(Id >> 16);
  2822. dbug(1, dprintf("ncci=0x%x, plci=0x%x", ncci, plci));
  2823. if (plci && ncci)
  2824. {
  2825. Info = _WRONG_STATE;
  2826. if ((a->ncci_state[ncci] == CONNECTED)
  2827. || (a->ncci_state[ncci] == INC_ACT_PENDING))
  2828. {
  2829. /* queue data */
  2830. ncci_ptr = &(a->ncci[ncci]);
  2831. i = ncci_ptr->data_out + ncci_ptr->data_pending;
  2832. if (i >= MAX_DATA_B3)
  2833. i -= MAX_DATA_B3;
  2834. data = &(ncci_ptr->DBuffer[i]);
  2835. data->Number = Number;
  2836. if ((((byte *)(parms[0].info)) >= ((byte *)(plci->msg_in_queue)))
  2837. && (((byte *)(parms[0].info)) < ((byte *)(plci->msg_in_queue)) + sizeof(plci->msg_in_queue)))
  2838. {
  2839. data->P = (byte *)(long)(*((dword *)(parms[0].info)));
  2840. }
  2841. else
  2842. data->P = TransmitBufferSet(appl, *(dword *)parms[0].info);
  2843. data->Length = GET_WORD(parms[1].info);
  2844. data->Handle = GET_WORD(parms[2].info);
  2845. data->Flags = GET_WORD(parms[3].info);
  2846. (ncci_ptr->data_pending)++;
  2847. /* check for delivery confirmation */
  2848. if (data->Flags & 0x0004)
  2849. {
  2850. i = ncci_ptr->data_ack_out + ncci_ptr->data_ack_pending;
  2851. if (i >= MAX_DATA_ACK)
  2852. i -= MAX_DATA_ACK;
  2853. ncci_ptr->DataAck[i].Number = data->Number;
  2854. ncci_ptr->DataAck[i].Handle = data->Handle;
  2855. (ncci_ptr->data_ack_pending)++;
  2856. }
  2857. send_data(plci);
  2858. return false;
  2859. }
  2860. }
  2861. if (appl)
  2862. {
  2863. if (plci)
  2864. {
  2865. if ((((byte *)(parms[0].info)) >= ((byte *)(plci->msg_in_queue)))
  2866. && (((byte *)(parms[0].info)) < ((byte *)(plci->msg_in_queue)) + sizeof(plci->msg_in_queue)))
  2867. {
  2868. TransmitBufferFree(appl, (byte *)(long)(*((dword *)(parms[0].info))));
  2869. }
  2870. }
  2871. sendf(appl,
  2872. _DATA_B3_R | CONFIRM,
  2873. Id,
  2874. Number,
  2875. "ww", GET_WORD(parms[2].info), Info);
  2876. }
  2877. return false;
  2878. }
  2879. static byte data_b3_res(dword Id, word Number, DIVA_CAPI_ADAPTER *a,
  2880. PLCI *plci, APPL *appl, API_PARSE *parms)
  2881. {
  2882. word n;
  2883. word ncci;
  2884. word NCCIcode;
  2885. dbug(1, dprintf("data_b3_res"));
  2886. ncci = (word)(Id >> 16);
  2887. if (plci && ncci) {
  2888. n = GET_WORD(parms[0].info);
  2889. dbug(1, dprintf("free(%d)", n));
  2890. NCCIcode = ncci | (((word) a->Id) << 8);
  2891. if (n < appl->MaxBuffer &&
  2892. appl->DataNCCI[n] == NCCIcode &&
  2893. (byte)(appl->DataFlags[n] >> 8) == plci->Id) {
  2894. dbug(1, dprintf("found"));
  2895. appl->DataNCCI[n] = 0;
  2896. if (channel_can_xon(plci, a->ncci_ch[ncci])) {
  2897. channel_request_xon(plci, a->ncci_ch[ncci]);
  2898. }
  2899. channel_xmit_xon(plci);
  2900. if (appl->DataFlags[n] & 4) {
  2901. nl_req_ncci(plci, N_DATA_ACK, (byte)ncci);
  2902. return 1;
  2903. }
  2904. }
  2905. }
  2906. return false;
  2907. }
  2908. static byte reset_b3_req(dword Id, word Number, DIVA_CAPI_ADAPTER *a,
  2909. PLCI *plci, APPL *appl, API_PARSE *parms)
  2910. {
  2911. word Info;
  2912. word ncci;
  2913. dbug(1, dprintf("reset_b3_req"));
  2914. Info = _WRONG_IDENTIFIER;
  2915. ncci = (word)(Id >> 16);
  2916. if (plci && ncci)
  2917. {
  2918. Info = _WRONG_STATE;
  2919. switch (plci->B3_prot)
  2920. {
  2921. case B3_ISO8208:
  2922. case B3_X25_DCE:
  2923. if (a->ncci_state[ncci] == CONNECTED)
  2924. {
  2925. nl_req_ncci(plci, N_RESET, (byte)ncci);
  2926. send_req(plci);
  2927. Info = GOOD;
  2928. }
  2929. break;
  2930. case B3_TRANSPARENT:
  2931. if (a->ncci_state[ncci] == CONNECTED)
  2932. {
  2933. start_internal_command(Id, plci, reset_b3_command);
  2934. Info = GOOD;
  2935. }
  2936. break;
  2937. }
  2938. }
  2939. /* reset_b3 must result in a reset_b3_con & reset_b3_Ind */
  2940. sendf(appl,
  2941. _RESET_B3_R | CONFIRM,
  2942. Id,
  2943. Number,
  2944. "w", Info);
  2945. return false;
  2946. }
  2947. static byte reset_b3_res(dword Id, word Number, DIVA_CAPI_ADAPTER *a,
  2948. PLCI *plci, APPL *appl, API_PARSE *parms)
  2949. {
  2950. word ncci;
  2951. dbug(1, dprintf("reset_b3_res"));
  2952. ncci = (word)(Id >> 16);
  2953. if (plci && ncci) {
  2954. switch (plci->B3_prot)
  2955. {
  2956. case B3_ISO8208:
  2957. case B3_X25_DCE:
  2958. if (a->ncci_state[ncci] == INC_RES_PENDING)
  2959. {
  2960. a->ncci_state[ncci] = CONNECTED;
  2961. nl_req_ncci(plci, N_RESET_ACK, (byte)ncci);
  2962. return true;
  2963. }
  2964. break;
  2965. }
  2966. }
  2967. return false;
  2968. }
  2969. static byte connect_b3_t90_a_res(dword Id, word Number, DIVA_CAPI_ADAPTER *a,
  2970. PLCI *plci, APPL *appl, API_PARSE *parms)
  2971. {
  2972. word ncci;
  2973. API_PARSE *ncpi;
  2974. byte req;
  2975. dbug(1, dprintf("connect_b3_t90_a_res"));
  2976. ncci = (word)(Id >> 16);
  2977. if (plci && ncci) {
  2978. if (a->ncci_state[ncci] == INC_ACT_PENDING) {
  2979. a->ncci_state[ncci] = CONNECTED;
  2980. }
  2981. else if (a->ncci_state[ncci] == INC_CON_PENDING) {
  2982. a->ncci_state[ncci] = CONNECTED;
  2983. req = N_CONNECT_ACK;
  2984. /* parms[0]==0 for CAPI original message definition! */
  2985. if (parms[0].info) {
  2986. ncpi = &parms[1];
  2987. if (ncpi->length > 2) {
  2988. if (ncpi->info[1] & 1) req = N_CONNECT_ACK | N_D_BIT;
  2989. add_d(plci, (word)(ncpi->length - 3), &ncpi->info[4]);
  2990. }
  2991. }
  2992. nl_req_ncci(plci, req, (byte)ncci);
  2993. return 1;
  2994. }
  2995. }
  2996. return false;
  2997. }
  2998. static byte select_b_req(dword Id, word Number, DIVA_CAPI_ADAPTER *a,
  2999. PLCI *plci, APPL *appl, API_PARSE *msg)
  3000. {
  3001. word Info = 0;
  3002. word i;
  3003. byte tel;
  3004. API_PARSE bp_parms[7];
  3005. if (!plci || !msg)
  3006. {
  3007. Info = _WRONG_IDENTIFIER;
  3008. }
  3009. else
  3010. {
  3011. dbug(1, dprintf("select_b_req[%d],PLCI=0x%x,Tel=0x%x,NL=0x%x,appl=0x%x,sstate=0x%x",
  3012. msg->length, plci->Id, plci->tel, plci->NL.Id, plci->appl, plci->SuppState));
  3013. dbug(1, dprintf("PlciState=0x%x", plci->State));
  3014. for (i = 0; i < 7; i++) bp_parms[i].length = 0;
  3015. /* check if no channel is open, no B3 connected only */
  3016. if ((plci->State == IDLE) || (plci->State == OUTG_DIS_PENDING) || (plci->State == INC_DIS_PENDING)
  3017. || (plci->SuppState != IDLE) || plci->channels || plci->nl_remove_id)
  3018. {
  3019. Info = _WRONG_STATE;
  3020. }
  3021. /* check message format and fill bp_parms pointer */
  3022. else if (msg->length && api_parse(&msg->info[1], (word)msg->length, "wwwsss", bp_parms))
  3023. {
  3024. Info = _WRONG_MESSAGE_FORMAT;
  3025. }
  3026. else
  3027. {
  3028. if ((plci->State == INC_CON_PENDING) || (plci->State == INC_CON_ALERT)) /* send alert tone inband to the network, */
  3029. { /* e.g. Qsig or RBS or Cornet-N or xess PRI */
  3030. if (Id & EXT_CONTROLLER)
  3031. {
  3032. sendf(appl, _SELECT_B_REQ | CONFIRM, Id, Number, "w", 0x2002); /* wrong controller */
  3033. return 0;
  3034. }
  3035. plci->State = INC_CON_CONNECTED_ALERT;
  3036. plci->appl = appl;
  3037. clear_c_ind_mask_bit(plci, (word)(appl->Id - 1));
  3038. dump_c_ind_mask(plci);
  3039. for (i = 0; i < max_appl; i++) /* disconnect the other appls */
  3040. { /* its quasi a connect */
  3041. if (test_c_ind_mask_bit(plci, i))
  3042. sendf(&application[i], _DISCONNECT_I, Id, 0, "w", _OTHER_APPL_CONNECTED);
  3043. }
  3044. }
  3045. api_save_msg(msg, "s", &plci->saved_msg);
  3046. tel = plci->tel;
  3047. if (Id & EXT_CONTROLLER)
  3048. {
  3049. if (tel) /* external controller in use by this PLCI */
  3050. {
  3051. if (a->AdvSignalAppl && a->AdvSignalAppl != appl)
  3052. {
  3053. dbug(1, dprintf("Ext_Ctrl in use 1"));
  3054. Info = _WRONG_STATE;
  3055. }
  3056. }
  3057. else /* external controller NOT in use by this PLCI ? */
  3058. {
  3059. if (a->AdvSignalPLCI)
  3060. {
  3061. dbug(1, dprintf("Ext_Ctrl in use 2"));
  3062. Info = _WRONG_STATE;
  3063. }
  3064. else /* activate the codec */
  3065. {
  3066. dbug(1, dprintf("Ext_Ctrl start"));
  3067. if (AdvCodecSupport(a, plci, appl, 0))
  3068. {
  3069. dbug(1, dprintf("Error in codec procedures"));
  3070. Info = _WRONG_STATE;
  3071. }
  3072. else if (plci->spoofed_msg == SPOOFING_REQUIRED) /* wait until codec is active */
  3073. {
  3074. plci->spoofed_msg = AWAITING_SELECT_B;
  3075. plci->internal_command = BLOCK_PLCI; /* lock other commands */
  3076. plci->command = 0;
  3077. dbug(1, dprintf("continue if codec loaded"));
  3078. return false;
  3079. }
  3080. }
  3081. }
  3082. }
  3083. else /* external controller bit is OFF */
  3084. {
  3085. if (tel) /* external controller in use, need to switch off */
  3086. {
  3087. if (a->AdvSignalAppl == appl)
  3088. {
  3089. CodecIdCheck(a, plci);
  3090. plci->tel = 0;
  3091. plci->adv_nl = 0;
  3092. dbug(1, dprintf("Ext_Ctrl disable"));
  3093. }
  3094. else
  3095. {
  3096. dbug(1, dprintf("Ext_Ctrl not requested"));
  3097. }
  3098. }
  3099. }
  3100. if (!Info)
  3101. {
  3102. if (plci->call_dir & CALL_DIR_OUT)
  3103. plci->call_dir = CALL_DIR_OUT | CALL_DIR_ORIGINATE;
  3104. else if (plci->call_dir & CALL_DIR_IN)
  3105. plci->call_dir = CALL_DIR_IN | CALL_DIR_ANSWER;
  3106. start_internal_command(Id, plci, select_b_command);
  3107. return false;
  3108. }
  3109. }
  3110. }
  3111. sendf(appl, _SELECT_B_REQ | CONFIRM, Id, Number, "w", Info);
  3112. return false;
  3113. }
  3114. static byte manufacturer_req(dword Id, word Number, DIVA_CAPI_ADAPTER *a,
  3115. PLCI *plci, APPL *appl, API_PARSE *parms)
  3116. {
  3117. word command;
  3118. word i;
  3119. word ncci;
  3120. API_PARSE *m;
  3121. API_PARSE m_parms[5];
  3122. word codec;
  3123. byte req;
  3124. byte ch;
  3125. byte dir;
  3126. static byte chi[2] = {0x01, 0x00};
  3127. static byte lli[2] = {0x01, 0x00};
  3128. static byte codec_cai[2] = {0x01, 0x01};
  3129. static byte null_msg = {0};
  3130. static API_PARSE null_parms = { 0, &null_msg };
  3131. PLCI *v_plci;
  3132. word Info = 0;
  3133. dbug(1, dprintf("manufacturer_req"));
  3134. for (i = 0; i < 5; i++) m_parms[i].length = 0;
  3135. if (GET_DWORD(parms[0].info) != _DI_MANU_ID) {
  3136. Info = _WRONG_MESSAGE_FORMAT;
  3137. }
  3138. command = GET_WORD(parms[1].info);
  3139. m = &parms[2];
  3140. if (!Info)
  3141. {
  3142. switch (command) {
  3143. case _DI_ASSIGN_PLCI:
  3144. if (api_parse(&m->info[1], (word)m->length, "wbbs", m_parms)) {
  3145. Info = _WRONG_MESSAGE_FORMAT;
  3146. break;
  3147. }
  3148. codec = GET_WORD(m_parms[0].info);
  3149. ch = m_parms[1].info[0];
  3150. dir = m_parms[2].info[0];
  3151. if ((i = get_plci(a))) {
  3152. plci = &a->plci[i - 1];
  3153. plci->appl = appl;
  3154. plci->command = _MANUFACTURER_R;
  3155. plci->m_command = command;
  3156. plci->number = Number;
  3157. plci->State = LOCAL_CONNECT;
  3158. Id = (((word)plci->Id << 8) | plci->adapter->Id | 0x80);
  3159. dbug(1, dprintf("ManCMD,plci=0x%x", Id));
  3160. if ((ch == 1 || ch == 2) && (dir <= 2)) {
  3161. chi[1] = (byte)(0x80 | ch);
  3162. lli[1] = 0;
  3163. plci->call_dir = CALL_DIR_OUT | CALL_DIR_ORIGINATE;
  3164. switch (codec)
  3165. {
  3166. case 0:
  3167. Info = add_b1(plci, &m_parms[3], 0, 0);
  3168. break;
  3169. case 1:
  3170. add_p(plci, CAI, codec_cai);
  3171. break;
  3172. /* manual 'swich on' to the codec support without signalling */
  3173. /* first 'assign plci' with this function, then use */
  3174. case 2:
  3175. if (AdvCodecSupport(a, plci, appl, 0)) {
  3176. Info = _RESOURCE_ERROR;
  3177. }
  3178. else {
  3179. Info = add_b1(plci, &null_parms, 0, B1_FACILITY_LOCAL);
  3180. lli[1] = 0x10; /* local call codec stream */
  3181. }
  3182. break;
  3183. }
  3184. plci->State = LOCAL_CONNECT;
  3185. plci->manufacturer = true;
  3186. plci->command = _MANUFACTURER_R;
  3187. plci->m_command = command;
  3188. plci->number = Number;
  3189. if (!Info)
  3190. {
  3191. add_p(plci, LLI, lli);
  3192. add_p(plci, CHI, chi);
  3193. add_p(plci, UID, "\x06\x43\x61\x70\x69\x32\x30");
  3194. sig_req(plci, ASSIGN, DSIG_ID);
  3195. if (!codec)
  3196. {
  3197. Info = add_b23(plci, &m_parms[3]);
  3198. if (!Info)
  3199. {
  3200. nl_req_ncci(plci, ASSIGN, 0);
  3201. send_req(plci);
  3202. }
  3203. }
  3204. if (!Info)
  3205. {
  3206. dbug(1, dprintf("dir=0x%x,spoof=0x%x", dir, plci->spoofed_msg));
  3207. if (plci->spoofed_msg == SPOOFING_REQUIRED)
  3208. {
  3209. api_save_msg(m_parms, "wbbs", &plci->saved_msg);
  3210. plci->spoofed_msg = AWAITING_MANUF_CON;
  3211. plci->internal_command = BLOCK_PLCI; /* reject other req meanwhile */
  3212. plci->command = 0;
  3213. send_req(plci);
  3214. return false;
  3215. }
  3216. if (dir == 1) {
  3217. sig_req(plci, CALL_REQ, 0);
  3218. }
  3219. else if (!dir) {
  3220. sig_req(plci, LISTEN_REQ, 0);
  3221. }
  3222. send_req(plci);
  3223. }
  3224. else
  3225. {
  3226. sendf(appl,
  3227. _MANUFACTURER_R | CONFIRM,
  3228. Id,
  3229. Number,
  3230. "dww", _DI_MANU_ID, command, Info);
  3231. return 2;
  3232. }
  3233. }
  3234. }
  3235. }
  3236. else Info = _OUT_OF_PLCI;
  3237. break;
  3238. case _DI_IDI_CTRL:
  3239. if (!plci)
  3240. {
  3241. Info = _WRONG_IDENTIFIER;
  3242. break;
  3243. }
  3244. if (api_parse(&m->info[1], (word)m->length, "bs", m_parms)) {
  3245. Info = _WRONG_MESSAGE_FORMAT;
  3246. break;
  3247. }
  3248. req = m_parms[0].info[0];
  3249. plci->command = _MANUFACTURER_R;
  3250. plci->m_command = command;
  3251. plci->number = Number;
  3252. if (req == CALL_REQ)
  3253. {
  3254. plci->b_channel = getChannel(&m_parms[1]);
  3255. mixer_set_bchannel_id_esc(plci, plci->b_channel);
  3256. if (plci->spoofed_msg == SPOOFING_REQUIRED)
  3257. {
  3258. plci->spoofed_msg = CALL_REQ | AWAITING_MANUF_CON;
  3259. plci->internal_command = BLOCK_PLCI; /* reject other req meanwhile */
  3260. plci->command = 0;
  3261. break;
  3262. }
  3263. }
  3264. else if (req == LAW_REQ)
  3265. {
  3266. plci->cr_enquiry = true;
  3267. }
  3268. add_ss(plci, FTY, &m_parms[1]);
  3269. sig_req(plci, req, 0);
  3270. send_req(plci);
  3271. if (req == HANGUP)
  3272. {
  3273. if (plci->NL.Id && !plci->nl_remove_id)
  3274. {
  3275. if (plci->channels)
  3276. {
  3277. for (ncci = 1; ncci < MAX_NCCI + 1; ncci++)
  3278. {
  3279. if ((a->ncci_plci[ncci] == plci->Id) && (a->ncci_state[ncci] == CONNECTED))
  3280. {
  3281. a->ncci_state[ncci] = OUTG_DIS_PENDING;
  3282. cleanup_ncci_data(plci, ncci);
  3283. nl_req_ncci(plci, N_DISC, (byte)ncci);
  3284. }
  3285. }
  3286. }
  3287. mixer_remove(plci);
  3288. nl_req_ncci(plci, REMOVE, 0);
  3289. send_req(plci);
  3290. }
  3291. }
  3292. break;
  3293. case _DI_SIG_CTRL:
  3294. /* signalling control for loop activation B-channel */
  3295. if (!plci)
  3296. {
  3297. Info = _WRONG_IDENTIFIER;
  3298. break;
  3299. }
  3300. if (m->length) {
  3301. plci->command = _MANUFACTURER_R;
  3302. plci->number = Number;
  3303. add_ss(plci, FTY, m);
  3304. sig_req(plci, SIG_CTRL, 0);
  3305. send_req(plci);
  3306. }
  3307. else Info = _WRONG_MESSAGE_FORMAT;
  3308. break;
  3309. case _DI_RXT_CTRL:
  3310. /* activation control for receiver/transmitter B-channel */
  3311. if (!plci)
  3312. {
  3313. Info = _WRONG_IDENTIFIER;
  3314. break;
  3315. }
  3316. if (m->length) {
  3317. plci->command = _MANUFACTURER_R;
  3318. plci->number = Number;
  3319. add_ss(plci, FTY, m);
  3320. sig_req(plci, DSP_CTRL, 0);
  3321. send_req(plci);
  3322. }
  3323. else Info = _WRONG_MESSAGE_FORMAT;
  3324. break;
  3325. case _DI_ADV_CODEC:
  3326. case _DI_DSP_CTRL:
  3327. /* TEL_CTRL commands to support non standard adjustments: */
  3328. /* Ring on/off, Handset micro volume, external micro vol. */
  3329. /* handset+external speaker volume, receiver+transm. gain,*/
  3330. /* handsfree on (hookinfo off), set mixer command */
  3331. if (command == _DI_ADV_CODEC)
  3332. {
  3333. if (!a->AdvCodecPLCI) {
  3334. Info = _WRONG_STATE;
  3335. break;
  3336. }
  3337. v_plci = a->AdvCodecPLCI;
  3338. }
  3339. else
  3340. {
  3341. if (plci
  3342. && (m->length >= 3)
  3343. && (m->info[1] == 0x1c)
  3344. && (m->info[2] >= 1))
  3345. {
  3346. if (m->info[3] == DSP_CTRL_OLD_SET_MIXER_COEFFICIENTS)
  3347. {
  3348. if ((plci->tel != ADV_VOICE) || (plci != a->AdvSignalPLCI))
  3349. {
  3350. Info = _WRONG_STATE;
  3351. break;
  3352. }
  3353. a->adv_voice_coef_length = m->info[2] - 1;
  3354. if (a->adv_voice_coef_length > m->length - 3)
  3355. a->adv_voice_coef_length = (byte)(m->length - 3);
  3356. if (a->adv_voice_coef_length > ADV_VOICE_COEF_BUFFER_SIZE)
  3357. a->adv_voice_coef_length = ADV_VOICE_COEF_BUFFER_SIZE;
  3358. for (i = 0; i < a->adv_voice_coef_length; i++)
  3359. a->adv_voice_coef_buffer[i] = m->info[4 + i];
  3360. if (plci->B1_facilities & B1_FACILITY_VOICE)
  3361. adv_voice_write_coefs(plci, ADV_VOICE_WRITE_UPDATE);
  3362. break;
  3363. }
  3364. else if (m->info[3] == DSP_CTRL_SET_DTMF_PARAMETERS)
  3365. {
  3366. if (!(a->manufacturer_features & MANUFACTURER_FEATURE_DTMF_PARAMETERS))
  3367. {
  3368. Info = _FACILITY_NOT_SUPPORTED;
  3369. break;
  3370. }
  3371. plci->dtmf_parameter_length = m->info[2] - 1;
  3372. if (plci->dtmf_parameter_length > m->length - 3)
  3373. plci->dtmf_parameter_length = (byte)(m->length - 3);
  3374. if (plci->dtmf_parameter_length > DTMF_PARAMETER_BUFFER_SIZE)
  3375. plci->dtmf_parameter_length = DTMF_PARAMETER_BUFFER_SIZE;
  3376. for (i = 0; i < plci->dtmf_parameter_length; i++)
  3377. plci->dtmf_parameter_buffer[i] = m->info[4 + i];
  3378. if (plci->B1_facilities & B1_FACILITY_DTMFR)
  3379. dtmf_parameter_write(plci);
  3380. break;
  3381. }
  3382. }
  3383. v_plci = plci;
  3384. }
  3385. if (!v_plci)
  3386. {
  3387. Info = _WRONG_IDENTIFIER;
  3388. break;
  3389. }
  3390. if (m->length) {
  3391. add_ss(v_plci, FTY, m);
  3392. sig_req(v_plci, TEL_CTRL, 0);
  3393. send_req(v_plci);
  3394. }
  3395. else Info = _WRONG_MESSAGE_FORMAT;
  3396. break;
  3397. case _DI_OPTIONS_REQUEST:
  3398. if (api_parse(&m->info[1], (word)m->length, "d", m_parms)) {
  3399. Info = _WRONG_MESSAGE_FORMAT;
  3400. break;
  3401. }
  3402. if (GET_DWORD(m_parms[0].info) & ~a->man_profile.private_options)
  3403. {
  3404. Info = _FACILITY_NOT_SUPPORTED;
  3405. break;
  3406. }
  3407. a->requested_options_table[appl->Id - 1] = GET_DWORD(m_parms[0].info);
  3408. break;
  3409. default:
  3410. Info = _WRONG_MESSAGE_FORMAT;
  3411. break;
  3412. }
  3413. }
  3414. sendf(appl,
  3415. _MANUFACTURER_R | CONFIRM,
  3416. Id,
  3417. Number,
  3418. "dww", _DI_MANU_ID, command, Info);
  3419. return false;
  3420. }
  3421. static byte manufacturer_res(dword Id, word Number, DIVA_CAPI_ADAPTER *a,
  3422. PLCI *plci, APPL *appl, API_PARSE *msg)
  3423. {
  3424. word indication;
  3425. API_PARSE m_parms[3];
  3426. API_PARSE *ncpi;
  3427. API_PARSE fax_parms[9];
  3428. word i;
  3429. byte len;
  3430. dbug(1, dprintf("manufacturer_res"));
  3431. if ((msg[0].length == 0)
  3432. || (msg[1].length == 0)
  3433. || (GET_DWORD(msg[0].info) != _DI_MANU_ID))
  3434. {
  3435. return false;
  3436. }
  3437. indication = GET_WORD(msg[1].info);
  3438. switch (indication)
  3439. {
  3440. case _DI_NEGOTIATE_B3:
  3441. if (!plci)
  3442. break;
  3443. if (((plci->B3_prot != 4) && (plci->B3_prot != 5))
  3444. || !(plci->ncpi_state & NCPI_NEGOTIATE_B3_SENT))
  3445. {
  3446. dbug(1, dprintf("wrong state for NEGOTIATE_B3 parameters"));
  3447. break;
  3448. }
  3449. if (api_parse(&msg[2].info[1], msg[2].length, "ws", m_parms))
  3450. {
  3451. dbug(1, dprintf("wrong format in NEGOTIATE_B3 parameters"));
  3452. break;
  3453. }
  3454. ncpi = &m_parms[1];
  3455. len = offsetof(T30_INFO, station_id) + T30_MAX_STATION_ID_LENGTH;
  3456. if (plci->fax_connect_info_length < len)
  3457. {
  3458. ((T30_INFO *)(plci->fax_connect_info_buffer))->station_id_len = 0;
  3459. ((T30_INFO *)(plci->fax_connect_info_buffer))->head_line_len = 0;
  3460. }
  3461. if (api_parse(&ncpi->info[1], ncpi->length, "wwwwssss", fax_parms))
  3462. {
  3463. dbug(1, dprintf("non-standard facilities info missing or wrong format"));
  3464. }
  3465. else
  3466. {
  3467. if (plci->fax_connect_info_length <= len)
  3468. plci->fax_connect_info_buffer[len] = 0;
  3469. len += 1 + plci->fax_connect_info_buffer[len];
  3470. if (plci->fax_connect_info_length <= len)
  3471. plci->fax_connect_info_buffer[len] = 0;
  3472. len += 1 + plci->fax_connect_info_buffer[len];
  3473. if ((fax_parms[7].length >= 3) && (fax_parms[7].info[1] >= 2))
  3474. plci->nsf_control_bits = GET_WORD(&fax_parms[7].info[2]);
  3475. plci->fax_connect_info_buffer[len++] = (byte)(fax_parms[7].length);
  3476. for (i = 0; i < fax_parms[7].length; i++)
  3477. plci->fax_connect_info_buffer[len++] = fax_parms[7].info[1 + i];
  3478. }
  3479. plci->fax_connect_info_length = len;
  3480. plci->fax_edata_ack_length = plci->fax_connect_info_length;
  3481. start_internal_command(Id, plci, fax_edata_ack_command);
  3482. break;
  3483. }
  3484. return false;
  3485. }
  3486. /*------------------------------------------------------------------*/
  3487. /* IDI callback function */
  3488. /*------------------------------------------------------------------*/
  3489. void callback(ENTITY *e)
  3490. {
  3491. DIVA_CAPI_ADAPTER *a;
  3492. APPL *appl;
  3493. PLCI *plci;
  3494. CAPI_MSG *m;
  3495. word i, j;
  3496. byte rc;
  3497. byte ch;
  3498. byte req;
  3499. byte global_req;
  3500. int no_cancel_rc;
  3501. dbug(1, dprintf("%x:CB(%x:Req=%x,Rc=%x,Ind=%x)",
  3502. (e->user[0] + 1) & 0x7fff, e->Id, e->Req, e->Rc, e->Ind));
  3503. a = &(adapter[(byte)e->user[0]]);
  3504. plci = &(a->plci[e->user[1]]);
  3505. no_cancel_rc = DIVA_CAPI_SUPPORTS_NO_CANCEL(a);
  3506. /*
  3507. If new protocol code and new XDI is used then CAPI should work
  3508. fully in accordance with IDI cpec an look on callback field instead
  3509. of Rc field for return codes.
  3510. */
  3511. if (((e->complete == 0xff) && no_cancel_rc) ||
  3512. (e->Rc && !no_cancel_rc)) {
  3513. rc = e->Rc;
  3514. ch = e->RcCh;
  3515. req = e->Req;
  3516. e->Rc = 0;
  3517. if (e->user[0] & 0x8000)
  3518. {
  3519. /*
  3520. If REMOVE request was sent then we have to wait until
  3521. return code with Id set to zero arrives.
  3522. All other return codes should be ignored.
  3523. */
  3524. if (req == REMOVE)
  3525. {
  3526. if (e->Id)
  3527. {
  3528. dbug(1, dprintf("cancel RC in REMOVE state"));
  3529. return;
  3530. }
  3531. channel_flow_control_remove(plci);
  3532. for (i = 0; i < 256; i++)
  3533. {
  3534. if (a->FlowControlIdTable[i] == plci->nl_remove_id)
  3535. a->FlowControlIdTable[i] = 0;
  3536. }
  3537. plci->nl_remove_id = 0;
  3538. if (plci->rx_dma_descriptor > 0) {
  3539. diva_free_dma_descriptor(plci, plci->rx_dma_descriptor - 1);
  3540. plci->rx_dma_descriptor = 0;
  3541. }
  3542. }
  3543. if (rc == OK_FC)
  3544. {
  3545. a->FlowControlIdTable[ch] = e->Id;
  3546. a->FlowControlSkipTable[ch] = 0;
  3547. a->ch_flow_control[ch] |= N_OK_FC_PENDING;
  3548. a->ch_flow_plci[ch] = plci->Id;
  3549. plci->nl_req = 0;
  3550. }
  3551. else
  3552. {
  3553. /*
  3554. Cancel return codes self, if feature was requested
  3555. */
  3556. if (no_cancel_rc && (a->FlowControlIdTable[ch] == e->Id) && e->Id) {
  3557. a->FlowControlIdTable[ch] = 0;
  3558. if ((rc == OK) && a->FlowControlSkipTable[ch]) {
  3559. dbug(3, dprintf("XDI CAPI: RC cancelled Id:0x02, Ch:%02x", e->Id, ch));
  3560. return;
  3561. }
  3562. }
  3563. if (a->ch_flow_control[ch] & N_OK_FC_PENDING)
  3564. {
  3565. a->ch_flow_control[ch] &= ~N_OK_FC_PENDING;
  3566. if (ch == e->ReqCh)
  3567. plci->nl_req = 0;
  3568. }
  3569. else
  3570. plci->nl_req = 0;
  3571. }
  3572. if (plci->nl_req)
  3573. control_rc(plci, 0, rc, ch, 0, true);
  3574. else
  3575. {
  3576. if (req == N_XON)
  3577. {
  3578. channel_x_on(plci, ch);
  3579. if (plci->internal_command)
  3580. control_rc(plci, req, rc, ch, 0, true);
  3581. }
  3582. else
  3583. {
  3584. if (plci->nl_global_req)
  3585. {
  3586. global_req = plci->nl_global_req;
  3587. plci->nl_global_req = 0;
  3588. if (rc != ASSIGN_OK) {
  3589. e->Id = 0;
  3590. if (plci->rx_dma_descriptor > 0) {
  3591. diva_free_dma_descriptor(plci, plci->rx_dma_descriptor - 1);
  3592. plci->rx_dma_descriptor = 0;
  3593. }
  3594. }
  3595. channel_xmit_xon(plci);
  3596. control_rc(plci, 0, rc, ch, global_req, true);
  3597. }
  3598. else if (plci->data_sent)
  3599. {
  3600. channel_xmit_xon(plci);
  3601. plci->data_sent = false;
  3602. plci->NL.XNum = 1;
  3603. data_rc(plci, ch);
  3604. if (plci->internal_command)
  3605. control_rc(plci, req, rc, ch, 0, true);
  3606. }
  3607. else
  3608. {
  3609. channel_xmit_xon(plci);
  3610. control_rc(plci, req, rc, ch, 0, true);
  3611. }
  3612. }
  3613. }
  3614. }
  3615. else
  3616. {
  3617. /*
  3618. If REMOVE request was sent then we have to wait until
  3619. return code with Id set to zero arrives.
  3620. All other return codes should be ignored.
  3621. */
  3622. if (req == REMOVE)
  3623. {
  3624. if (e->Id)
  3625. {
  3626. dbug(1, dprintf("cancel RC in REMOVE state"));
  3627. return;
  3628. }
  3629. plci->sig_remove_id = 0;
  3630. }
  3631. plci->sig_req = 0;
  3632. if (plci->sig_global_req)
  3633. {
  3634. global_req = plci->sig_global_req;
  3635. plci->sig_global_req = 0;
  3636. if (rc != ASSIGN_OK)
  3637. e->Id = 0;
  3638. channel_xmit_xon(plci);
  3639. control_rc(plci, 0, rc, ch, global_req, false);
  3640. }
  3641. else
  3642. {
  3643. channel_xmit_xon(plci);
  3644. control_rc(plci, req, rc, ch, 0, false);
  3645. }
  3646. }
  3647. /*
  3648. Again: in accordance with IDI spec Rc and Ind can't be delivered in the
  3649. same callback. Also if new XDI and protocol code used then jump
  3650. direct to finish.
  3651. */
  3652. if (no_cancel_rc) {
  3653. channel_xmit_xon(plci);
  3654. goto capi_callback_suffix;
  3655. }
  3656. }
  3657. channel_xmit_xon(plci);
  3658. if (e->Ind) {
  3659. if (e->user[0] & 0x8000) {
  3660. byte Ind = e->Ind & 0x0f;
  3661. byte Ch = e->IndCh;
  3662. if (((Ind == N_DISC) || (Ind == N_DISC_ACK)) &&
  3663. (a->ch_flow_plci[Ch] == plci->Id)) {
  3664. if (a->ch_flow_control[Ch] & N_RX_FLOW_CONTROL_MASK) {
  3665. dbug(3, dprintf("XDI CAPI: I: pending N-XON Ch:%02x", Ch));
  3666. }
  3667. a->ch_flow_control[Ch] &= ~N_RX_FLOW_CONTROL_MASK;
  3668. }
  3669. nl_ind(plci);
  3670. if ((e->RNR != 1) &&
  3671. (a->ch_flow_plci[Ch] == plci->Id) &&
  3672. (a->ch_flow_control[Ch] & N_RX_FLOW_CONTROL_MASK)) {
  3673. a->ch_flow_control[Ch] &= ~N_RX_FLOW_CONTROL_MASK;
  3674. dbug(3, dprintf("XDI CAPI: I: remove faked N-XON Ch:%02x", Ch));
  3675. }
  3676. } else {
  3677. sig_ind(plci);
  3678. }
  3679. e->Ind = 0;
  3680. }
  3681. capi_callback_suffix:
  3682. while (!plci->req_in
  3683. && !plci->internal_command
  3684. && (plci->msg_in_write_pos != plci->msg_in_read_pos))
  3685. {
  3686. j = (plci->msg_in_read_pos == plci->msg_in_wrap_pos) ? 0 : plci->msg_in_read_pos;
  3687. i = (((CAPI_MSG *)(&((byte *)(plci->msg_in_queue))[j]))->header.length + 3) & 0xfffc;
  3688. m = (CAPI_MSG *)(&((byte *)(plci->msg_in_queue))[j]);
  3689. appl = *((APPL **)(&((byte *)(plci->msg_in_queue))[j + i]));
  3690. dbug(1, dprintf("dequeue msg(0x%04x) - write=%d read=%d wrap=%d",
  3691. m->header.command, plci->msg_in_write_pos, plci->msg_in_read_pos, plci->msg_in_wrap_pos));
  3692. if (plci->msg_in_read_pos == plci->msg_in_wrap_pos)
  3693. {
  3694. plci->msg_in_wrap_pos = MSG_IN_QUEUE_SIZE;
  3695. plci->msg_in_read_pos = i + MSG_IN_OVERHEAD;
  3696. }
  3697. else
  3698. {
  3699. plci->msg_in_read_pos = j + i + MSG_IN_OVERHEAD;
  3700. }
  3701. if (plci->msg_in_read_pos == plci->msg_in_write_pos)
  3702. {
  3703. plci->msg_in_write_pos = MSG_IN_QUEUE_SIZE;
  3704. plci->msg_in_read_pos = MSG_IN_QUEUE_SIZE;
  3705. }
  3706. else if (plci->msg_in_read_pos == plci->msg_in_wrap_pos)
  3707. {
  3708. plci->msg_in_read_pos = MSG_IN_QUEUE_SIZE;
  3709. plci->msg_in_wrap_pos = MSG_IN_QUEUE_SIZE;
  3710. }
  3711. i = api_put(appl, m);
  3712. if (i != 0)
  3713. {
  3714. if (m->header.command == _DATA_B3_R)
  3715. TransmitBufferFree(appl, (byte *)(long)(m->info.data_b3_req.Data));
  3716. dbug(1, dprintf("Error 0x%04x from msg(0x%04x)", i, m->header.command));
  3717. break;
  3718. }
  3719. if (plci->li_notify_update)
  3720. {
  3721. plci->li_notify_update = false;
  3722. mixer_notify_update(plci, false);
  3723. }
  3724. }
  3725. send_data(plci);
  3726. send_req(plci);
  3727. }
  3728. static void control_rc(PLCI *plci, byte req, byte rc, byte ch, byte global_req,
  3729. byte nl_rc)
  3730. {
  3731. dword Id;
  3732. dword rId;
  3733. word Number;
  3734. word Info = 0;
  3735. word i;
  3736. word ncci;
  3737. DIVA_CAPI_ADAPTER *a;
  3738. APPL *appl;
  3739. PLCI *rplci;
  3740. byte SSparms[] = "\x05\x00\x00\x02\x00\x00";
  3741. byte SSstruct[] = "\x09\x00\x00\x06\x00\x00\x00\x00\x00\x00";
  3742. if (!plci) {
  3743. dbug(0, dprintf("A: control_rc, no plci %02x:%02x:%02x:%02x:%02x", req, rc, ch, global_req, nl_rc));
  3744. return;
  3745. }
  3746. dbug(1, dprintf("req0_in/out=%d/%d", plci->req_in, plci->req_out));
  3747. if (plci->req_in != plci->req_out)
  3748. {
  3749. if (nl_rc || (global_req != ASSIGN) || (rc == ASSIGN_OK))
  3750. {
  3751. dbug(1, dprintf("req_1return"));
  3752. return;
  3753. }
  3754. /* cancel outstanding request on the PLCI after SIG ASSIGN failure */
  3755. }
  3756. plci->req_in = plci->req_in_start = plci->req_out = 0;
  3757. dbug(1, dprintf("control_rc"));
  3758. appl = plci->appl;
  3759. a = plci->adapter;
  3760. ncci = a->ch_ncci[ch];
  3761. if (appl)
  3762. {
  3763. Id = (((dword)(ncci ? ncci : ch)) << 16) | ((word)plci->Id << 8) | a->Id;
  3764. if (plci->tel && plci->SuppState != CALL_HELD) Id |= EXT_CONTROLLER;
  3765. Number = plci->number;
  3766. 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));
  3767. dbug(1, dprintf("channels=0x%x", plci->channels));
  3768. if (plci_remove_check(plci))
  3769. return;
  3770. if (req == REMOVE && rc == ASSIGN_OK)
  3771. {
  3772. sig_req(plci, HANGUP, 0);
  3773. sig_req(plci, REMOVE, 0);
  3774. send_req(plci);
  3775. }
  3776. if (plci->command)
  3777. {
  3778. switch (plci->command)
  3779. {
  3780. case C_HOLD_REQ:
  3781. dbug(1, dprintf("HoldRC=0x%x", rc));
  3782. SSparms[1] = (byte)S_HOLD;
  3783. if (rc != OK)
  3784. {
  3785. plci->SuppState = IDLE;
  3786. Info = 0x2001;
  3787. }
  3788. sendf(appl, _FACILITY_R | CONFIRM, Id, Number, "wws", Info, 3, SSparms);
  3789. break;
  3790. case C_RETRIEVE_REQ:
  3791. dbug(1, dprintf("RetrieveRC=0x%x", rc));
  3792. SSparms[1] = (byte)S_RETRIEVE;
  3793. if (rc != OK)
  3794. {
  3795. plci->SuppState = CALL_HELD;
  3796. Info = 0x2001;
  3797. }
  3798. sendf(appl, _FACILITY_R | CONFIRM, Id, Number, "wws", Info, 3, SSparms);
  3799. break;
  3800. case _INFO_R:
  3801. dbug(1, dprintf("InfoRC=0x%x", rc));
  3802. if (rc != OK) Info = _WRONG_STATE;
  3803. sendf(appl, _INFO_R | CONFIRM, Id, Number, "w", Info);
  3804. break;
  3805. case _CONNECT_R:
  3806. dbug(1, dprintf("Connect_R=0x%x/0x%x/0x%x/0x%x", req, rc, global_req, nl_rc));
  3807. if (plci->State == INC_DIS_PENDING)
  3808. break;
  3809. if (plci->Sig.Id != 0xff)
  3810. {
  3811. if (((global_req == ASSIGN) && (rc != ASSIGN_OK))
  3812. || (!nl_rc && (req == CALL_REQ) && (rc != OK)))
  3813. {
  3814. dbug(1, dprintf("No more IDs/Call_Req failed"));
  3815. sendf(appl, _CONNECT_R | CONFIRM, Id & 0xffL, Number, "w", _OUT_OF_PLCI);
  3816. plci_remove(plci);
  3817. plci->State = IDLE;
  3818. break;
  3819. }
  3820. if (plci->State != LOCAL_CONNECT) plci->State = OUTG_CON_PENDING;
  3821. sendf(appl, _CONNECT_R | CONFIRM, Id, Number, "w", 0);
  3822. }
  3823. else /* D-ch activation */
  3824. {
  3825. if (rc != ASSIGN_OK)
  3826. {
  3827. dbug(1, dprintf("No more IDs/X.25 Call_Req failed"));
  3828. sendf(appl, _CONNECT_R | CONFIRM, Id & 0xffL, Number, "w", _OUT_OF_PLCI);
  3829. plci_remove(plci);
  3830. plci->State = IDLE;
  3831. break;
  3832. }
  3833. sendf(appl, _CONNECT_R | CONFIRM, Id, Number, "w", 0);
  3834. sendf(plci->appl, _CONNECT_ACTIVE_I, Id, 0, "sss", "", "", "");
  3835. plci->State = INC_ACT_PENDING;
  3836. }
  3837. break;
  3838. case _CONNECT_I | RESPONSE:
  3839. if (plci->State != INC_DIS_PENDING)
  3840. plci->State = INC_CON_ACCEPT;
  3841. break;
  3842. case _DISCONNECT_R:
  3843. if (plci->State == INC_DIS_PENDING)
  3844. break;
  3845. if (plci->Sig.Id != 0xff)
  3846. {
  3847. plci->State = OUTG_DIS_PENDING;
  3848. sendf(appl, _DISCONNECT_R | CONFIRM, Id, Number, "w", 0);
  3849. }
  3850. break;
  3851. case SUSPEND_REQ:
  3852. break;
  3853. case RESUME_REQ:
  3854. break;
  3855. case _CONNECT_B3_R:
  3856. if (rc != OK)
  3857. {
  3858. sendf(appl, _CONNECT_B3_R | CONFIRM, Id, Number, "w", _WRONG_IDENTIFIER);
  3859. break;
  3860. }
  3861. ncci = get_ncci(plci, ch, 0);
  3862. Id = (Id & 0xffff) | (((dword) ncci) << 16);
  3863. plci->channels++;
  3864. if (req == N_RESET)
  3865. {
  3866. a->ncci_state[ncci] = INC_ACT_PENDING;
  3867. sendf(appl, _CONNECT_B3_R | CONFIRM, Id, Number, "w", 0);
  3868. sendf(appl, _CONNECT_B3_ACTIVE_I, Id, 0, "s", "");
  3869. }
  3870. else
  3871. {
  3872. a->ncci_state[ncci] = OUTG_CON_PENDING;
  3873. sendf(appl, _CONNECT_B3_R | CONFIRM, Id, Number, "w", 0);
  3874. }
  3875. break;
  3876. case _CONNECT_B3_I | RESPONSE:
  3877. break;
  3878. case _RESET_B3_R:
  3879. /* sendf(appl, _RESET_B3_R | CONFIRM, Id, Number, "w", 0);*/
  3880. break;
  3881. case _DISCONNECT_B3_R:
  3882. sendf(appl, _DISCONNECT_B3_R | CONFIRM, Id, Number, "w", 0);
  3883. break;
  3884. case _MANUFACTURER_R:
  3885. break;
  3886. case PERM_LIST_REQ:
  3887. if (rc != OK)
  3888. {
  3889. Info = _WRONG_IDENTIFIER;
  3890. sendf(plci->appl, _CONNECT_R | CONFIRM, Id, Number, "w", Info);
  3891. plci_remove(plci);
  3892. }
  3893. else
  3894. sendf(plci->appl, _CONNECT_R | CONFIRM, Id, Number, "w", Info);
  3895. break;
  3896. default:
  3897. break;
  3898. }
  3899. plci->command = 0;
  3900. }
  3901. else if (plci->internal_command)
  3902. {
  3903. switch (plci->internal_command)
  3904. {
  3905. case BLOCK_PLCI:
  3906. return;
  3907. case GET_MWI_STATE:
  3908. if (rc == OK) /* command supported, wait for indication */
  3909. {
  3910. return;
  3911. }
  3912. plci_remove(plci);
  3913. break;
  3914. /* Get Supported Services */
  3915. case GETSERV_REQ_PEND:
  3916. if (rc == OK) /* command supported, wait for indication */
  3917. {
  3918. break;
  3919. }
  3920. PUT_DWORD(&SSstruct[6], MASK_TERMINAL_PORTABILITY);
  3921. sendf(appl, _FACILITY_R | CONFIRM, Id, Number, "wws", 0, 3, SSstruct);
  3922. plci_remove(plci);
  3923. break;
  3924. case INTERR_DIVERSION_REQ_PEND: /* Interrogate Parameters */
  3925. case INTERR_NUMBERS_REQ_PEND:
  3926. case CF_START_PEND: /* Call Forwarding Start pending */
  3927. case CF_STOP_PEND: /* Call Forwarding Stop pending */
  3928. case CCBS_REQUEST_REQ_PEND:
  3929. case CCBS_DEACTIVATE_REQ_PEND:
  3930. case CCBS_INTERROGATE_REQ_PEND:
  3931. switch (plci->internal_command)
  3932. {
  3933. case INTERR_DIVERSION_REQ_PEND:
  3934. SSparms[1] = S_INTERROGATE_DIVERSION;
  3935. break;
  3936. case INTERR_NUMBERS_REQ_PEND:
  3937. SSparms[1] = S_INTERROGATE_NUMBERS;
  3938. break;
  3939. case CF_START_PEND:
  3940. SSparms[1] = S_CALL_FORWARDING_START;
  3941. break;
  3942. case CF_STOP_PEND:
  3943. SSparms[1] = S_CALL_FORWARDING_STOP;
  3944. break;
  3945. case CCBS_REQUEST_REQ_PEND:
  3946. SSparms[1] = S_CCBS_REQUEST;
  3947. break;
  3948. case CCBS_DEACTIVATE_REQ_PEND:
  3949. SSparms[1] = S_CCBS_DEACTIVATE;
  3950. break;
  3951. case CCBS_INTERROGATE_REQ_PEND:
  3952. SSparms[1] = S_CCBS_INTERROGATE;
  3953. break;
  3954. }
  3955. if (global_req == ASSIGN)
  3956. {
  3957. dbug(1, dprintf("AssignDiversion_RC=0x%x/0x%x", req, rc));
  3958. return;
  3959. }
  3960. if (!plci->appl) break;
  3961. if (rc == ISDN_GUARD_REJ)
  3962. {
  3963. Info = _CAPI_GUARD_ERROR;
  3964. }
  3965. else if (rc != OK)
  3966. {
  3967. Info = _SUPPLEMENTARY_SERVICE_NOT_SUPPORTED;
  3968. }
  3969. sendf(plci->appl, _FACILITY_R | CONFIRM, Id & 0x7,
  3970. plci->number, "wws", Info, (word)3, SSparms);
  3971. if (Info) plci_remove(plci);
  3972. break;
  3973. /* 3pty conference pending */
  3974. case PTY_REQ_PEND:
  3975. if (!plci->relatedPTYPLCI) break;
  3976. rplci = plci->relatedPTYPLCI;
  3977. SSparms[1] = plci->ptyState;
  3978. rId = ((word)rplci->Id << 8) | rplci->adapter->Id;
  3979. if (rplci->tel) rId |= EXT_CONTROLLER;
  3980. if (rc != OK)
  3981. {
  3982. Info = 0x300E; /* not supported */
  3983. plci->relatedPTYPLCI = NULL;
  3984. plci->ptyState = 0;
  3985. }
  3986. sendf(rplci->appl,
  3987. _FACILITY_R | CONFIRM,
  3988. rId,
  3989. plci->number,
  3990. "wws", Info, (word)3, SSparms);
  3991. break;
  3992. /* Explicit Call Transfer pending */
  3993. case ECT_REQ_PEND:
  3994. dbug(1, dprintf("ECT_RC=0x%x/0x%x", req, rc));
  3995. if (!plci->relatedPTYPLCI) break;
  3996. rplci = plci->relatedPTYPLCI;
  3997. SSparms[1] = S_ECT;
  3998. rId = ((word)rplci->Id << 8) | rplci->adapter->Id;
  3999. if (rplci->tel) rId |= EXT_CONTROLLER;
  4000. if (rc != OK)
  4001. {
  4002. Info = 0x300E; /* not supported */
  4003. plci->relatedPTYPLCI = NULL;
  4004. plci->ptyState = 0;
  4005. }
  4006. sendf(rplci->appl,
  4007. _FACILITY_R | CONFIRM,
  4008. rId,
  4009. plci->number,
  4010. "wws", Info, (word)3, SSparms);
  4011. break;
  4012. case _MANUFACTURER_R:
  4013. dbug(1, dprintf("_Manufacturer_R=0x%x/0x%x", req, rc));
  4014. if ((global_req == ASSIGN) && (rc != ASSIGN_OK))
  4015. {
  4016. dbug(1, dprintf("No more IDs"));
  4017. sendf(appl, _MANUFACTURER_R | CONFIRM, Id, Number, "dww", _DI_MANU_ID, _MANUFACTURER_R, _OUT_OF_PLCI);
  4018. plci_remove(plci); /* after codec init, internal codec commands pending */
  4019. }
  4020. break;
  4021. case _CONNECT_R:
  4022. dbug(1, dprintf("_Connect_R=0x%x/0x%x", req, rc));
  4023. if ((global_req == ASSIGN) && (rc != ASSIGN_OK))
  4024. {
  4025. dbug(1, dprintf("No more IDs"));
  4026. sendf(appl, _CONNECT_R | CONFIRM, Id & 0xffL, Number, "w", _OUT_OF_PLCI);
  4027. plci_remove(plci); /* after codec init, internal codec commands pending */
  4028. }
  4029. break;
  4030. case PERM_COD_HOOK: /* finished with Hook_Ind */
  4031. return;
  4032. case PERM_COD_CALL:
  4033. dbug(1, dprintf("***Codec Connect_Pending A, Rc = 0x%x", rc));
  4034. plci->internal_command = PERM_COD_CONN_PEND;
  4035. return;
  4036. case PERM_COD_ASSIGN:
  4037. dbug(1, dprintf("***Codec Assign A, Rc = 0x%x", rc));
  4038. if (rc != ASSIGN_OK) break;
  4039. sig_req(plci, CALL_REQ, 0);
  4040. send_req(plci);
  4041. plci->internal_command = PERM_COD_CALL;
  4042. return;
  4043. /* Null Call Reference Request pending */
  4044. case C_NCR_FAC_REQ:
  4045. dbug(1, dprintf("NCR_FAC=0x%x/0x%x", req, rc));
  4046. if (global_req == ASSIGN)
  4047. {
  4048. if (rc == ASSIGN_OK)
  4049. {
  4050. return;
  4051. }
  4052. else
  4053. {
  4054. sendf(appl, _INFO_R | CONFIRM, Id & 0xf, Number, "w", _WRONG_STATE);
  4055. appl->NullCREnable = false;
  4056. plci_remove(plci);
  4057. }
  4058. }
  4059. else if (req == NCR_FACILITY)
  4060. {
  4061. if (rc == OK)
  4062. {
  4063. sendf(appl, _INFO_R | CONFIRM, Id & 0xf, Number, "w", 0);
  4064. }
  4065. else
  4066. {
  4067. sendf(appl, _INFO_R | CONFIRM, Id & 0xf, Number, "w", _WRONG_STATE);
  4068. appl->NullCREnable = false;
  4069. }
  4070. plci_remove(plci);
  4071. }
  4072. break;
  4073. case HOOK_ON_REQ:
  4074. if (plci->channels)
  4075. {
  4076. if (a->ncci_state[ncci] == CONNECTED)
  4077. {
  4078. a->ncci_state[ncci] = OUTG_DIS_PENDING;
  4079. cleanup_ncci_data(plci, ncci);
  4080. nl_req_ncci(plci, N_DISC, (byte)ncci);
  4081. }
  4082. break;
  4083. }
  4084. break;
  4085. case HOOK_OFF_REQ:
  4086. if (plci->State == INC_DIS_PENDING)
  4087. break;
  4088. sig_req(plci, CALL_REQ, 0);
  4089. send_req(plci);
  4090. plci->State = OUTG_CON_PENDING;
  4091. break;
  4092. case MWI_ACTIVATE_REQ_PEND:
  4093. case MWI_DEACTIVATE_REQ_PEND:
  4094. if (global_req == ASSIGN && rc == ASSIGN_OK)
  4095. {
  4096. dbug(1, dprintf("MWI_REQ assigned"));
  4097. return;
  4098. }
  4099. else if (rc != OK)
  4100. {
  4101. if (rc == WRONG_IE)
  4102. {
  4103. Info = 0x2007; /* Illegal message parameter coding */
  4104. dbug(1, dprintf("MWI_REQ invalid parameter"));
  4105. }
  4106. else
  4107. {
  4108. Info = 0x300B; /* not supported */
  4109. dbug(1, dprintf("MWI_REQ not supported"));
  4110. }
  4111. /* 0x3010: Request not allowed in this state */
  4112. PUT_WORD(&SSparms[4], 0x300E); /* SS not supported */
  4113. }
  4114. if (plci->internal_command == MWI_ACTIVATE_REQ_PEND)
  4115. {
  4116. PUT_WORD(&SSparms[1], S_MWI_ACTIVATE);
  4117. }
  4118. else PUT_WORD(&SSparms[1], S_MWI_DEACTIVATE);
  4119. if (plci->cr_enquiry)
  4120. {
  4121. sendf(plci->appl,
  4122. _FACILITY_R | CONFIRM,
  4123. Id & 0xf,
  4124. plci->number,
  4125. "wws", Info, (word)3, SSparms);
  4126. if (rc != OK) plci_remove(plci);
  4127. }
  4128. else
  4129. {
  4130. sendf(plci->appl,
  4131. _FACILITY_R | CONFIRM,
  4132. Id,
  4133. plci->number,
  4134. "wws", Info, (word)3, SSparms);
  4135. }
  4136. break;
  4137. case CONF_BEGIN_REQ_PEND:
  4138. case CONF_ADD_REQ_PEND:
  4139. case CONF_SPLIT_REQ_PEND:
  4140. case CONF_DROP_REQ_PEND:
  4141. case CONF_ISOLATE_REQ_PEND:
  4142. case CONF_REATTACH_REQ_PEND:
  4143. dbug(1, dprintf("CONF_RC=0x%x/0x%x", req, rc));
  4144. if ((plci->internal_command == CONF_ADD_REQ_PEND) && (!plci->relatedPTYPLCI)) break;
  4145. rplci = plci;
  4146. rId = Id;
  4147. switch (plci->internal_command)
  4148. {
  4149. case CONF_BEGIN_REQ_PEND:
  4150. SSparms[1] = S_CONF_BEGIN;
  4151. break;
  4152. case CONF_ADD_REQ_PEND:
  4153. SSparms[1] = S_CONF_ADD;
  4154. rplci = plci->relatedPTYPLCI;
  4155. rId = ((word)rplci->Id << 8) | rplci->adapter->Id;
  4156. break;
  4157. case CONF_SPLIT_REQ_PEND:
  4158. SSparms[1] = S_CONF_SPLIT;
  4159. break;
  4160. case CONF_DROP_REQ_PEND:
  4161. SSparms[1] = S_CONF_DROP;
  4162. break;
  4163. case CONF_ISOLATE_REQ_PEND:
  4164. SSparms[1] = S_CONF_ISOLATE;
  4165. break;
  4166. case CONF_REATTACH_REQ_PEND:
  4167. SSparms[1] = S_CONF_REATTACH;
  4168. break;
  4169. }
  4170. if (rc != OK)
  4171. {
  4172. Info = 0x300E; /* not supported */
  4173. plci->relatedPTYPLCI = NULL;
  4174. plci->ptyState = 0;
  4175. }
  4176. sendf(rplci->appl,
  4177. _FACILITY_R | CONFIRM,
  4178. rId,
  4179. plci->number,
  4180. "wws", Info, (word)3, SSparms);
  4181. break;
  4182. case VSWITCH_REQ_PEND:
  4183. if (rc != OK)
  4184. {
  4185. if (plci->relatedPTYPLCI)
  4186. {
  4187. plci->relatedPTYPLCI->vswitchstate = 0;
  4188. plci->relatedPTYPLCI->vsprot = 0;
  4189. plci->relatedPTYPLCI->vsprotdialect = 0;
  4190. }
  4191. plci->vswitchstate = 0;
  4192. plci->vsprot = 0;
  4193. plci->vsprotdialect = 0;
  4194. }
  4195. else
  4196. {
  4197. if (plci->relatedPTYPLCI &&
  4198. plci->vswitchstate == 1 &&
  4199. plci->relatedPTYPLCI->vswitchstate == 3) /* join complete */
  4200. plci->vswitchstate = 3;
  4201. }
  4202. break;
  4203. /* Call Deflection Request pending (SSCT) */
  4204. case CD_REQ_PEND:
  4205. SSparms[1] = S_CALL_DEFLECTION;
  4206. if (rc != OK)
  4207. {
  4208. Info = 0x300E; /* not supported */
  4209. plci->appl->CDEnable = 0;
  4210. }
  4211. sendf(plci->appl, _FACILITY_R | CONFIRM, Id,
  4212. plci->number, "wws", Info, (word)3, SSparms);
  4213. break;
  4214. case RTP_CONNECT_B3_REQ_COMMAND_2:
  4215. if (rc == OK)
  4216. {
  4217. ncci = get_ncci(plci, ch, 0);
  4218. Id = (Id & 0xffff) | (((dword) ncci) << 16);
  4219. plci->channels++;
  4220. a->ncci_state[ncci] = OUTG_CON_PENDING;
  4221. }
  4222. default:
  4223. if (plci->internal_command_queue[0])
  4224. {
  4225. (*(plci->internal_command_queue[0]))(Id, plci, rc);
  4226. if (plci->internal_command)
  4227. return;
  4228. }
  4229. break;
  4230. }
  4231. next_internal_command(Id, plci);
  4232. }
  4233. }
  4234. else /* appl==0 */
  4235. {
  4236. Id = ((word)plci->Id << 8) | plci->adapter->Id;
  4237. if (plci->tel) Id |= EXT_CONTROLLER;
  4238. switch (plci->internal_command)
  4239. {
  4240. case BLOCK_PLCI:
  4241. return;
  4242. case START_L1_SIG_ASSIGN_PEND:
  4243. case REM_L1_SIG_ASSIGN_PEND:
  4244. if (global_req == ASSIGN)
  4245. {
  4246. break;
  4247. }
  4248. else
  4249. {
  4250. dbug(1, dprintf("***L1 Req rem PLCI"));
  4251. plci->internal_command = 0;
  4252. sig_req(plci, REMOVE, 0);
  4253. send_req(plci);
  4254. }
  4255. break;
  4256. /* Call Deflection Request pending, just no appl ptr assigned */
  4257. case CD_REQ_PEND:
  4258. SSparms[1] = S_CALL_DEFLECTION;
  4259. if (rc != OK)
  4260. {
  4261. Info = 0x300E; /* not supported */
  4262. }
  4263. for (i = 0; i < max_appl; i++)
  4264. {
  4265. if (application[i].CDEnable)
  4266. {
  4267. if (!application[i].Id) application[i].CDEnable = 0;
  4268. else
  4269. {
  4270. sendf(&application[i], _FACILITY_R | CONFIRM, Id,
  4271. plci->number, "wws", Info, (word)3, SSparms);
  4272. if (Info) application[i].CDEnable = 0;
  4273. }
  4274. }
  4275. }
  4276. plci->internal_command = 0;
  4277. break;
  4278. case PERM_COD_HOOK: /* finished with Hook_Ind */
  4279. return;
  4280. case PERM_COD_CALL:
  4281. plci->internal_command = PERM_COD_CONN_PEND;
  4282. dbug(1, dprintf("***Codec Connect_Pending, Rc = 0x%x", rc));
  4283. return;
  4284. case PERM_COD_ASSIGN:
  4285. dbug(1, dprintf("***Codec Assign, Rc = 0x%x", rc));
  4286. plci->internal_command = 0;
  4287. if (rc != ASSIGN_OK) break;
  4288. plci->internal_command = PERM_COD_CALL;
  4289. sig_req(plci, CALL_REQ, 0);
  4290. send_req(plci);
  4291. return;
  4292. case LISTEN_SIG_ASSIGN_PEND:
  4293. if (rc == ASSIGN_OK)
  4294. {
  4295. plci->internal_command = 0;
  4296. dbug(1, dprintf("ListenCheck, new SIG_ID = 0x%x", plci->Sig.Id));
  4297. add_p(plci, ESC, "\x02\x18\x00"); /* support call waiting */
  4298. sig_req(plci, INDICATE_REQ, 0);
  4299. send_req(plci);
  4300. }
  4301. else
  4302. {
  4303. dbug(1, dprintf("ListenCheck failed (assignRc=0x%x)", rc));
  4304. a->listen_active--;
  4305. plci_remove(plci);
  4306. plci->State = IDLE;
  4307. }
  4308. break;
  4309. case USELAW_REQ:
  4310. if (global_req == ASSIGN)
  4311. {
  4312. if (rc == ASSIGN_OK)
  4313. {
  4314. sig_req(plci, LAW_REQ, 0);
  4315. send_req(plci);
  4316. dbug(1, dprintf("Auto-Law assigned"));
  4317. }
  4318. else
  4319. {
  4320. dbug(1, dprintf("Auto-Law assign failed"));
  4321. a->automatic_law = 3;
  4322. plci->internal_command = 0;
  4323. a->automatic_lawPLCI = NULL;
  4324. }
  4325. break;
  4326. }
  4327. else if (req == LAW_REQ && rc == OK)
  4328. {
  4329. dbug(1, dprintf("Auto-Law initiated"));
  4330. a->automatic_law = 2;
  4331. plci->internal_command = 0;
  4332. }
  4333. else
  4334. {
  4335. dbug(1, dprintf("Auto-Law not supported"));
  4336. a->automatic_law = 3;
  4337. plci->internal_command = 0;
  4338. sig_req(plci, REMOVE, 0);
  4339. send_req(plci);
  4340. a->automatic_lawPLCI = NULL;
  4341. }
  4342. break;
  4343. }
  4344. plci_remove_check(plci);
  4345. }
  4346. }
  4347. static void data_rc(PLCI *plci, byte ch)
  4348. {
  4349. dword Id;
  4350. DIVA_CAPI_ADAPTER *a;
  4351. NCCI *ncci_ptr;
  4352. DATA_B3_DESC *data;
  4353. word ncci;
  4354. if (plci->appl)
  4355. {
  4356. TransmitBufferFree(plci->appl, plci->data_sent_ptr);
  4357. a = plci->adapter;
  4358. ncci = a->ch_ncci[ch];
  4359. if (ncci && (a->ncci_plci[ncci] == plci->Id))
  4360. {
  4361. ncci_ptr = &(a->ncci[ncci]);
  4362. dbug(1, dprintf("data_out=%d, data_pending=%d", ncci_ptr->data_out, ncci_ptr->data_pending));
  4363. if (ncci_ptr->data_pending)
  4364. {
  4365. data = &(ncci_ptr->DBuffer[ncci_ptr->data_out]);
  4366. if (!(data->Flags & 4) && a->ncci_state[ncci])
  4367. {
  4368. Id = (((dword)ncci) << 16) | ((word)plci->Id << 8) | a->Id;
  4369. if (plci->tel) Id |= EXT_CONTROLLER;
  4370. sendf(plci->appl, _DATA_B3_R | CONFIRM, Id, data->Number,
  4371. "ww", data->Handle, 0);
  4372. }
  4373. (ncci_ptr->data_out)++;
  4374. if (ncci_ptr->data_out == MAX_DATA_B3)
  4375. ncci_ptr->data_out = 0;
  4376. (ncci_ptr->data_pending)--;
  4377. }
  4378. }
  4379. }
  4380. }
  4381. static void data_ack(PLCI *plci, byte ch)
  4382. {
  4383. dword Id;
  4384. DIVA_CAPI_ADAPTER *a;
  4385. NCCI *ncci_ptr;
  4386. word ncci;
  4387. a = plci->adapter;
  4388. ncci = a->ch_ncci[ch];
  4389. ncci_ptr = &(a->ncci[ncci]);
  4390. if (ncci_ptr->data_ack_pending)
  4391. {
  4392. if (a->ncci_state[ncci] && (a->ncci_plci[ncci] == plci->Id))
  4393. {
  4394. Id = (((dword)ncci) << 16) | ((word)plci->Id << 8) | a->Id;
  4395. if (plci->tel) Id |= EXT_CONTROLLER;
  4396. sendf(plci->appl, _DATA_B3_R | CONFIRM, Id, ncci_ptr->DataAck[ncci_ptr->data_ack_out].Number,
  4397. "ww", ncci_ptr->DataAck[ncci_ptr->data_ack_out].Handle, 0);
  4398. }
  4399. (ncci_ptr->data_ack_out)++;
  4400. if (ncci_ptr->data_ack_out == MAX_DATA_ACK)
  4401. ncci_ptr->data_ack_out = 0;
  4402. (ncci_ptr->data_ack_pending)--;
  4403. }
  4404. }
  4405. static void sig_ind(PLCI *plci)
  4406. {
  4407. dword x_Id;
  4408. dword Id;
  4409. dword rId;
  4410. word i;
  4411. word cip;
  4412. dword cip_mask;
  4413. byte *ie;
  4414. DIVA_CAPI_ADAPTER *a;
  4415. API_PARSE saved_parms[MAX_MSG_PARMS + 1];
  4416. #define MAXPARMSIDS 31
  4417. byte *parms[MAXPARMSIDS];
  4418. byte *add_i[4];
  4419. byte *multi_fac_parms[MAX_MULTI_IE];
  4420. byte *multi_pi_parms[MAX_MULTI_IE];
  4421. byte *multi_ssext_parms[MAX_MULTI_IE];
  4422. byte *multi_CiPN_parms[MAX_MULTI_IE];
  4423. byte *multi_vswitch_parms[MAX_MULTI_IE];
  4424. byte ai_len;
  4425. byte *esc_chi = "";
  4426. byte *esc_law = "";
  4427. byte *pty_cai = "";
  4428. byte *esc_cr = "";
  4429. byte *esc_profile = "";
  4430. byte facility[256];
  4431. PLCI *tplci = NULL;
  4432. byte chi[] = "\x02\x18\x01";
  4433. byte voice_cai[] = "\x06\x14\x00\x00\x00\x00\x08";
  4434. byte resume_cau[] = "\x05\x05\x00\x02\x00\x00";
  4435. /* ESC_MSGTYPE must be the last but one message, a new IE has to be */
  4436. /* included before the ESC_MSGTYPE and MAXPARMSIDS has to be incremented */
  4437. /* SMSG is situated at the end because its 0 (for compatibility reasons */
  4438. /* (see Info_Mask Bit 4, first IE. then the message type) */
  4439. word parms_id[] =
  4440. {MAXPARMSIDS, CPN, 0xff, DSA, OSA, BC, LLC, HLC, ESC_CAUSE, DSP, DT, CHA,
  4441. UUI, CONG_RR, CONG_RNR, ESC_CHI, KEY, CHI, CAU, ESC_LAW,
  4442. RDN, RDX, CONN_NR, RIN, NI, CAI, ESC_CR,
  4443. CST, ESC_PROFILE, 0xff, ESC_MSGTYPE, SMSG};
  4444. /* 14 FTY repl by ESC_CHI */
  4445. /* 18 PI repl by ESC_LAW */
  4446. /* removed OAD changed to 0xff for future use, OAD is multiIE now */
  4447. word multi_fac_id[] = {1, FTY};
  4448. word multi_pi_id[] = {1, PI};
  4449. word multi_CiPN_id[] = {1, OAD};
  4450. word multi_ssext_id[] = {1, ESC_SSEXT};
  4451. word multi_vswitch_id[] = {1, ESC_VSWITCH};
  4452. byte *cau;
  4453. word ncci;
  4454. byte SS_Ind[] = "\x05\x02\x00\x02\x00\x00"; /* Hold_Ind struct*/
  4455. byte CF_Ind[] = "\x09\x02\x00\x06\x00\x00\x00\x00\x00\x00";
  4456. byte Interr_Err_Ind[] = "\x0a\x02\x00\x07\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00";
  4457. byte CONF_Ind[] = "\x09\x16\x00\x06\x00\x00\0x00\0x00\0x00\0x00";
  4458. byte force_mt_info = false;
  4459. byte dir;
  4460. dword d;
  4461. word w;
  4462. a = plci->adapter;
  4463. Id = ((word)plci->Id << 8) | a->Id;
  4464. PUT_WORD(&SS_Ind[4], 0x0000);
  4465. if (plci->sig_remove_id)
  4466. {
  4467. plci->Sig.RNR = 2; /* discard */
  4468. dbug(1, dprintf("SIG discard while remove pending"));
  4469. return;
  4470. }
  4471. if (plci->tel && plci->SuppState != CALL_HELD) Id |= EXT_CONTROLLER;
  4472. dbug(1, dprintf("SigInd-Id=%08lx,plci=%x,tel=%x,state=0x%x,channels=%d,Discflowcl=%d",
  4473. Id, plci->Id, plci->tel, plci->State, plci->channels, plci->hangup_flow_ctrl_timer));
  4474. if (plci->Sig.Ind == CALL_HOLD_ACK && plci->channels)
  4475. {
  4476. plci->Sig.RNR = 1;
  4477. return;
  4478. }
  4479. if (plci->Sig.Ind == HANGUP && plci->channels)
  4480. {
  4481. plci->Sig.RNR = 1;
  4482. plci->hangup_flow_ctrl_timer++;
  4483. /* recover the network layer after timeout */
  4484. if (plci->hangup_flow_ctrl_timer == 100)
  4485. {
  4486. dbug(1, dprintf("Exceptional disc"));
  4487. plci->Sig.RNR = 0;
  4488. plci->hangup_flow_ctrl_timer = 0;
  4489. for (ncci = 1; ncci < MAX_NCCI + 1; ncci++)
  4490. {
  4491. if (a->ncci_plci[ncci] == plci->Id)
  4492. {
  4493. cleanup_ncci_data(plci, ncci);
  4494. if (plci->channels)plci->channels--;
  4495. if (plci->appl)
  4496. sendf(plci->appl, _DISCONNECT_B3_I, (((dword) ncci) << 16) | Id, 0, "ws", 0, "");
  4497. }
  4498. }
  4499. if (plci->appl)
  4500. sendf(plci->appl, _DISCONNECT_I, Id, 0, "w", 0);
  4501. plci_remove(plci);
  4502. plci->State = IDLE;
  4503. }
  4504. return;
  4505. }
  4506. /* do first parse the info with no OAD in, because OAD will be converted */
  4507. /* first the multiple facility IE, then mult. progress ind. */
  4508. /* then the parameters for the info_ind + conn_ind */
  4509. IndParse(plci, multi_fac_id, multi_fac_parms, MAX_MULTI_IE);
  4510. IndParse(plci, multi_pi_id, multi_pi_parms, MAX_MULTI_IE);
  4511. IndParse(plci, multi_ssext_id, multi_ssext_parms, MAX_MULTI_IE);
  4512. IndParse(plci, multi_vswitch_id, multi_vswitch_parms, MAX_MULTI_IE);
  4513. IndParse(plci, parms_id, parms, 0);
  4514. IndParse(plci, multi_CiPN_id, multi_CiPN_parms, MAX_MULTI_IE);
  4515. esc_chi = parms[14];
  4516. esc_law = parms[18];
  4517. pty_cai = parms[24];
  4518. esc_cr = parms[25];
  4519. esc_profile = parms[27];
  4520. if (esc_cr[0] && plci)
  4521. {
  4522. if (plci->cr_enquiry && plci->appl)
  4523. {
  4524. plci->cr_enquiry = false;
  4525. /* d = MANU_ID */
  4526. /* w = m_command */
  4527. /* b = total length */
  4528. /* b = indication type */
  4529. /* b = length of all IEs */
  4530. /* b = IE1 */
  4531. /* S = IE1 length + cont. */
  4532. /* b = IE2 */
  4533. /* S = IE2 length + cont. */
  4534. sendf(plci->appl,
  4535. _MANUFACTURER_I,
  4536. Id,
  4537. 0,
  4538. "dwbbbbSbS", _DI_MANU_ID, plci->m_command,
  4539. 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);
  4540. }
  4541. }
  4542. /* create the additional info structure */
  4543. add_i[1] = parms[15]; /* KEY of additional info */
  4544. add_i[2] = parms[11]; /* UUI of additional info */
  4545. ai_len = AddInfo(add_i, multi_fac_parms, esc_chi, facility);
  4546. /* the ESC_LAW indicates if u-Law or a-Law is actually used by the card */
  4547. /* indication returns by the card if requested by the function */
  4548. /* AutomaticLaw() after driver init */
  4549. if (a->automatic_law < 4)
  4550. {
  4551. if (esc_law[0]) {
  4552. if (esc_law[2]) {
  4553. dbug(0, dprintf("u-Law selected"));
  4554. a->u_law = 1;
  4555. }
  4556. else {
  4557. dbug(0, dprintf("a-Law selected"));
  4558. a->u_law = 0;
  4559. }
  4560. a->automatic_law = 4;
  4561. if (plci == a->automatic_lawPLCI) {
  4562. plci->internal_command = 0;
  4563. sig_req(plci, REMOVE, 0);
  4564. send_req(plci);
  4565. a->automatic_lawPLCI = NULL;
  4566. }
  4567. }
  4568. if (esc_profile[0])
  4569. {
  4570. dbug(1, dprintf("[%06x] CardProfile: %lx %lx %lx %lx %lx",
  4571. UnMapController(a->Id), GET_DWORD(&esc_profile[6]),
  4572. GET_DWORD(&esc_profile[10]), GET_DWORD(&esc_profile[14]),
  4573. GET_DWORD(&esc_profile[18]), GET_DWORD(&esc_profile[46])));
  4574. a->profile.Global_Options &= 0x000000ffL;
  4575. a->profile.B1_Protocols &= 0x000003ffL;
  4576. a->profile.B2_Protocols &= 0x00001fdfL;
  4577. a->profile.B3_Protocols &= 0x000000b7L;
  4578. a->profile.Global_Options &= GET_DWORD(&esc_profile[6]) |
  4579. GL_BCHANNEL_OPERATION_SUPPORTED;
  4580. a->profile.B1_Protocols &= GET_DWORD(&esc_profile[10]);
  4581. a->profile.B2_Protocols &= GET_DWORD(&esc_profile[14]);
  4582. a->profile.B3_Protocols &= GET_DWORD(&esc_profile[18]);
  4583. a->manufacturer_features = GET_DWORD(&esc_profile[46]);
  4584. a->man_profile.private_options = 0;
  4585. if (a->manufacturer_features & MANUFACTURER_FEATURE_ECHO_CANCELLER)
  4586. {
  4587. a->man_profile.private_options |= 1L << PRIVATE_ECHO_CANCELLER;
  4588. a->profile.Global_Options |= GL_ECHO_CANCELLER_SUPPORTED;
  4589. }
  4590. if (a->manufacturer_features & MANUFACTURER_FEATURE_RTP)
  4591. a->man_profile.private_options |= 1L << PRIVATE_RTP;
  4592. a->man_profile.rtp_primary_payloads = GET_DWORD(&esc_profile[50]);
  4593. a->man_profile.rtp_additional_payloads = GET_DWORD(&esc_profile[54]);
  4594. if (a->manufacturer_features & MANUFACTURER_FEATURE_T38)
  4595. a->man_profile.private_options |= 1L << PRIVATE_T38;
  4596. if (a->manufacturer_features & MANUFACTURER_FEATURE_FAX_SUB_SEP_PWD)
  4597. a->man_profile.private_options |= 1L << PRIVATE_FAX_SUB_SEP_PWD;
  4598. if (a->manufacturer_features & MANUFACTURER_FEATURE_V18)
  4599. a->man_profile.private_options |= 1L << PRIVATE_V18;
  4600. if (a->manufacturer_features & MANUFACTURER_FEATURE_DTMF_TONE)
  4601. a->man_profile.private_options |= 1L << PRIVATE_DTMF_TONE;
  4602. if (a->manufacturer_features & MANUFACTURER_FEATURE_PIAFS)
  4603. a->man_profile.private_options |= 1L << PRIVATE_PIAFS;
  4604. if (a->manufacturer_features & MANUFACTURER_FEATURE_FAX_PAPER_FORMATS)
  4605. a->man_profile.private_options |= 1L << PRIVATE_FAX_PAPER_FORMATS;
  4606. if (a->manufacturer_features & MANUFACTURER_FEATURE_VOWN)
  4607. a->man_profile.private_options |= 1L << PRIVATE_VOWN;
  4608. if (a->manufacturer_features & MANUFACTURER_FEATURE_FAX_NONSTANDARD)
  4609. a->man_profile.private_options |= 1L << PRIVATE_FAX_NONSTANDARD;
  4610. }
  4611. else
  4612. {
  4613. a->profile.Global_Options &= 0x0000007fL;
  4614. a->profile.B1_Protocols &= 0x000003dfL;
  4615. a->profile.B2_Protocols &= 0x00001adfL;
  4616. a->profile.B3_Protocols &= 0x000000b7L;
  4617. a->manufacturer_features &= MANUFACTURER_FEATURE_HARDDTMF;
  4618. }
  4619. if (a->manufacturer_features & (MANUFACTURER_FEATURE_HARDDTMF |
  4620. MANUFACTURER_FEATURE_SOFTDTMF_SEND | MANUFACTURER_FEATURE_SOFTDTMF_RECEIVE))
  4621. {
  4622. a->profile.Global_Options |= GL_DTMF_SUPPORTED;
  4623. }
  4624. a->manufacturer_features &= ~MANUFACTURER_FEATURE_OOB_CHANNEL;
  4625. dbug(1, dprintf("[%06x] Profile: %lx %lx %lx %lx %lx",
  4626. UnMapController(a->Id), a->profile.Global_Options,
  4627. a->profile.B1_Protocols, a->profile.B2_Protocols,
  4628. a->profile.B3_Protocols, a->manufacturer_features));
  4629. }
  4630. /* codec plci for the handset/hook state support is just an internal id */
  4631. if (plci != a->AdvCodecPLCI)
  4632. {
  4633. force_mt_info = SendMultiIE(plci, Id, multi_fac_parms, FTY, 0x20, 0);
  4634. force_mt_info |= SendMultiIE(plci, Id, multi_pi_parms, PI, 0x210, 0);
  4635. SendSSExtInd(NULL, plci, Id, multi_ssext_parms);
  4636. SendInfo(plci, Id, parms, force_mt_info);
  4637. VSwitchReqInd(plci, Id, multi_vswitch_parms);
  4638. }
  4639. /* switch the codec to the b-channel */
  4640. if (esc_chi[0] && plci && !plci->SuppState) {
  4641. plci->b_channel = esc_chi[esc_chi[0]]&0x1f;
  4642. mixer_set_bchannel_id_esc(plci, plci->b_channel);
  4643. dbug(1, dprintf("storeChannel=0x%x", plci->b_channel));
  4644. if (plci->tel == ADV_VOICE && plci->appl) {
  4645. SetVoiceChannel(a->AdvCodecPLCI, esc_chi, a);
  4646. }
  4647. }
  4648. if (plci->appl) plci->appl->Number++;
  4649. switch (plci->Sig.Ind) {
  4650. /* Response to Get_Supported_Services request */
  4651. case S_SUPPORTED:
  4652. dbug(1, dprintf("S_Supported"));
  4653. if (!plci->appl) break;
  4654. if (pty_cai[0] == 4)
  4655. {
  4656. PUT_DWORD(&CF_Ind[6], GET_DWORD(&pty_cai[1]));
  4657. }
  4658. else
  4659. {
  4660. PUT_DWORD(&CF_Ind[6], MASK_TERMINAL_PORTABILITY | MASK_HOLD_RETRIEVE);
  4661. }
  4662. PUT_WORD(&CF_Ind[1], 0);
  4663. PUT_WORD(&CF_Ind[4], 0);
  4664. sendf(plci->appl, _FACILITY_R | CONFIRM, Id & 0x7, plci->number, "wws", 0, 3, CF_Ind);
  4665. plci_remove(plci);
  4666. break;
  4667. /* Supplementary Service rejected */
  4668. case S_SERVICE_REJ:
  4669. dbug(1, dprintf("S_Reject=0x%x", pty_cai[5]));
  4670. if (!pty_cai[0]) break;
  4671. switch (pty_cai[5])
  4672. {
  4673. case ECT_EXECUTE:
  4674. case THREE_PTY_END:
  4675. case THREE_PTY_BEGIN:
  4676. if (!plci->relatedPTYPLCI) break;
  4677. tplci = plci->relatedPTYPLCI;
  4678. rId = ((word)tplci->Id << 8) | tplci->adapter->Id;
  4679. if (tplci->tel) rId |= EXT_CONTROLLER;
  4680. if (pty_cai[5] == ECT_EXECUTE)
  4681. {
  4682. PUT_WORD(&SS_Ind[1], S_ECT);
  4683. plci->vswitchstate = 0;
  4684. plci->relatedPTYPLCI->vswitchstate = 0;
  4685. }
  4686. else
  4687. {
  4688. PUT_WORD(&SS_Ind[1], pty_cai[5] + 3);
  4689. }
  4690. if (pty_cai[2] != 0xff)
  4691. {
  4692. PUT_WORD(&SS_Ind[4], 0x3600 | (word)pty_cai[2]);
  4693. }
  4694. else
  4695. {
  4696. PUT_WORD(&SS_Ind[4], 0x300E);
  4697. }
  4698. plci->relatedPTYPLCI = NULL;
  4699. plci->ptyState = 0;
  4700. sendf(tplci->appl, _FACILITY_I, rId, 0, "ws", 3, SS_Ind);
  4701. break;
  4702. case CALL_DEFLECTION:
  4703. if (pty_cai[2] != 0xff)
  4704. {
  4705. PUT_WORD(&SS_Ind[4], 0x3600 | (word)pty_cai[2]);
  4706. }
  4707. else
  4708. {
  4709. PUT_WORD(&SS_Ind[4], 0x300E);
  4710. }
  4711. PUT_WORD(&SS_Ind[1], pty_cai[5]);
  4712. for (i = 0; i < max_appl; i++)
  4713. {
  4714. if (application[i].CDEnable)
  4715. {
  4716. if (application[i].Id) sendf(&application[i], _FACILITY_I, Id, 0, "ws", 3, SS_Ind);
  4717. application[i].CDEnable = false;
  4718. }
  4719. }
  4720. break;
  4721. case DEACTIVATION_DIVERSION:
  4722. case ACTIVATION_DIVERSION:
  4723. case DIVERSION_INTERROGATE_CFU:
  4724. case DIVERSION_INTERROGATE_CFB:
  4725. case DIVERSION_INTERROGATE_CFNR:
  4726. case DIVERSION_INTERROGATE_NUM:
  4727. case CCBS_REQUEST:
  4728. case CCBS_DEACTIVATE:
  4729. case CCBS_INTERROGATE:
  4730. if (!plci->appl) break;
  4731. if (pty_cai[2] != 0xff)
  4732. {
  4733. PUT_WORD(&Interr_Err_Ind[4], 0x3600 | (word)pty_cai[2]);
  4734. }
  4735. else
  4736. {
  4737. PUT_WORD(&Interr_Err_Ind[4], 0x300E);
  4738. }
  4739. switch (pty_cai[5])
  4740. {
  4741. case DEACTIVATION_DIVERSION:
  4742. dbug(1, dprintf("Deact_Div"));
  4743. Interr_Err_Ind[0] = 0x9;
  4744. Interr_Err_Ind[3] = 0x6;
  4745. PUT_WORD(&Interr_Err_Ind[1], S_CALL_FORWARDING_STOP);
  4746. break;
  4747. case ACTIVATION_DIVERSION:
  4748. dbug(1, dprintf("Act_Div"));
  4749. Interr_Err_Ind[0] = 0x9;
  4750. Interr_Err_Ind[3] = 0x6;
  4751. PUT_WORD(&Interr_Err_Ind[1], S_CALL_FORWARDING_START);
  4752. break;
  4753. case DIVERSION_INTERROGATE_CFU:
  4754. case DIVERSION_INTERROGATE_CFB:
  4755. case DIVERSION_INTERROGATE_CFNR:
  4756. dbug(1, dprintf("Interr_Div"));
  4757. Interr_Err_Ind[0] = 0xa;
  4758. Interr_Err_Ind[3] = 0x7;
  4759. PUT_WORD(&Interr_Err_Ind[1], S_INTERROGATE_DIVERSION);
  4760. break;
  4761. case DIVERSION_INTERROGATE_NUM:
  4762. dbug(1, dprintf("Interr_Num"));
  4763. Interr_Err_Ind[0] = 0xa;
  4764. Interr_Err_Ind[3] = 0x7;
  4765. PUT_WORD(&Interr_Err_Ind[1], S_INTERROGATE_NUMBERS);
  4766. break;
  4767. case CCBS_REQUEST:
  4768. dbug(1, dprintf("CCBS Request"));
  4769. Interr_Err_Ind[0] = 0xd;
  4770. Interr_Err_Ind[3] = 0xa;
  4771. PUT_WORD(&Interr_Err_Ind[1], S_CCBS_REQUEST);
  4772. break;
  4773. case CCBS_DEACTIVATE:
  4774. dbug(1, dprintf("CCBS Deactivate"));
  4775. Interr_Err_Ind[0] = 0x9;
  4776. Interr_Err_Ind[3] = 0x6;
  4777. PUT_WORD(&Interr_Err_Ind[1], S_CCBS_DEACTIVATE);
  4778. break;
  4779. case CCBS_INTERROGATE:
  4780. dbug(1, dprintf("CCBS Interrogate"));
  4781. Interr_Err_Ind[0] = 0xb;
  4782. Interr_Err_Ind[3] = 0x8;
  4783. PUT_WORD(&Interr_Err_Ind[1], S_CCBS_INTERROGATE);
  4784. break;
  4785. }
  4786. PUT_DWORD(&Interr_Err_Ind[6], plci->appl->S_Handle);
  4787. sendf(plci->appl, _FACILITY_I, Id & 0x7, 0, "ws", 3, Interr_Err_Ind);
  4788. plci_remove(plci);
  4789. break;
  4790. case ACTIVATION_MWI:
  4791. case DEACTIVATION_MWI:
  4792. if (pty_cai[5] == ACTIVATION_MWI)
  4793. {
  4794. PUT_WORD(&SS_Ind[1], S_MWI_ACTIVATE);
  4795. }
  4796. else PUT_WORD(&SS_Ind[1], S_MWI_DEACTIVATE);
  4797. if (pty_cai[2] != 0xff)
  4798. {
  4799. PUT_WORD(&SS_Ind[4], 0x3600 | (word)pty_cai[2]);
  4800. }
  4801. else
  4802. {
  4803. PUT_WORD(&SS_Ind[4], 0x300E);
  4804. }
  4805. if (plci->cr_enquiry)
  4806. {
  4807. sendf(plci->appl, _FACILITY_I, Id & 0xf, 0, "ws", 3, SS_Ind);
  4808. plci_remove(plci);
  4809. }
  4810. else
  4811. {
  4812. sendf(plci->appl, _FACILITY_I, Id, 0, "ws", 3, SS_Ind);
  4813. }
  4814. break;
  4815. case CONF_ADD: /* ERROR */
  4816. case CONF_BEGIN:
  4817. case CONF_DROP:
  4818. case CONF_ISOLATE:
  4819. case CONF_REATTACH:
  4820. CONF_Ind[0] = 9;
  4821. CONF_Ind[3] = 6;
  4822. switch (pty_cai[5])
  4823. {
  4824. case CONF_BEGIN:
  4825. PUT_WORD(&CONF_Ind[1], S_CONF_BEGIN);
  4826. plci->ptyState = 0;
  4827. break;
  4828. case CONF_DROP:
  4829. CONF_Ind[0] = 5;
  4830. CONF_Ind[3] = 2;
  4831. PUT_WORD(&CONF_Ind[1], S_CONF_DROP);
  4832. plci->ptyState = CONNECTED;
  4833. break;
  4834. case CONF_ISOLATE:
  4835. CONF_Ind[0] = 5;
  4836. CONF_Ind[3] = 2;
  4837. PUT_WORD(&CONF_Ind[1], S_CONF_ISOLATE);
  4838. plci->ptyState = CONNECTED;
  4839. break;
  4840. case CONF_REATTACH:
  4841. CONF_Ind[0] = 5;
  4842. CONF_Ind[3] = 2;
  4843. PUT_WORD(&CONF_Ind[1], S_CONF_REATTACH);
  4844. plci->ptyState = CONNECTED;
  4845. break;
  4846. case CONF_ADD:
  4847. PUT_WORD(&CONF_Ind[1], S_CONF_ADD);
  4848. plci->relatedPTYPLCI = NULL;
  4849. tplci = plci->relatedPTYPLCI;
  4850. if (tplci) tplci->ptyState = CONNECTED;
  4851. plci->ptyState = CONNECTED;
  4852. break;
  4853. }
  4854. if (pty_cai[2] != 0xff)
  4855. {
  4856. PUT_WORD(&CONF_Ind[4], 0x3600 | (word)pty_cai[2]);
  4857. }
  4858. else
  4859. {
  4860. PUT_WORD(&CONF_Ind[4], 0x3303); /* Time-out: network did not respond
  4861. within the required time */
  4862. }
  4863. PUT_DWORD(&CONF_Ind[6], 0x0);
  4864. sendf(plci->appl, _FACILITY_I, Id, 0, "ws", 3, CONF_Ind);
  4865. break;
  4866. }
  4867. break;
  4868. /* Supplementary Service indicates success */
  4869. case S_SERVICE:
  4870. dbug(1, dprintf("Service_Ind"));
  4871. PUT_WORD(&CF_Ind[4], 0);
  4872. switch (pty_cai[5])
  4873. {
  4874. case THREE_PTY_END:
  4875. case THREE_PTY_BEGIN:
  4876. case ECT_EXECUTE:
  4877. if (!plci->relatedPTYPLCI) break;
  4878. tplci = plci->relatedPTYPLCI;
  4879. rId = ((word)tplci->Id << 8) | tplci->adapter->Id;
  4880. if (tplci->tel) rId |= EXT_CONTROLLER;
  4881. if (pty_cai[5] == ECT_EXECUTE)
  4882. {
  4883. PUT_WORD(&SS_Ind[1], S_ECT);
  4884. if (plci->vswitchstate != 3)
  4885. {
  4886. plci->ptyState = IDLE;
  4887. plci->relatedPTYPLCI = NULL;
  4888. plci->ptyState = 0;
  4889. }
  4890. dbug(1, dprintf("ECT OK"));
  4891. sendf(tplci->appl, _FACILITY_I, rId, 0, "ws", 3, SS_Ind);
  4892. }
  4893. else
  4894. {
  4895. switch (plci->ptyState)
  4896. {
  4897. case S_3PTY_BEGIN:
  4898. plci->ptyState = CONNECTED;
  4899. dbug(1, dprintf("3PTY ON"));
  4900. break;
  4901. case S_3PTY_END:
  4902. plci->ptyState = IDLE;
  4903. plci->relatedPTYPLCI = NULL;
  4904. plci->ptyState = 0;
  4905. dbug(1, dprintf("3PTY OFF"));
  4906. break;
  4907. }
  4908. PUT_WORD(&SS_Ind[1], pty_cai[5] + 3);
  4909. sendf(tplci->appl, _FACILITY_I, rId, 0, "ws", 3, SS_Ind);
  4910. }
  4911. break;
  4912. case CALL_DEFLECTION:
  4913. PUT_WORD(&SS_Ind[1], pty_cai[5]);
  4914. for (i = 0; i < max_appl; i++)
  4915. {
  4916. if (application[i].CDEnable)
  4917. {
  4918. if (application[i].Id) sendf(&application[i], _FACILITY_I, Id, 0, "ws", 3, SS_Ind);
  4919. application[i].CDEnable = false;
  4920. }
  4921. }
  4922. break;
  4923. case DEACTIVATION_DIVERSION:
  4924. case ACTIVATION_DIVERSION:
  4925. if (!plci->appl) break;
  4926. PUT_WORD(&CF_Ind[1], pty_cai[5] + 2);
  4927. PUT_DWORD(&CF_Ind[6], plci->appl->S_Handle);
  4928. sendf(plci->appl, _FACILITY_I, Id & 0x7, 0, "ws", 3, CF_Ind);
  4929. plci_remove(plci);
  4930. break;
  4931. case DIVERSION_INTERROGATE_CFU:
  4932. case DIVERSION_INTERROGATE_CFB:
  4933. case DIVERSION_INTERROGATE_CFNR:
  4934. case DIVERSION_INTERROGATE_NUM:
  4935. case CCBS_REQUEST:
  4936. case CCBS_DEACTIVATE:
  4937. case CCBS_INTERROGATE:
  4938. if (!plci->appl) break;
  4939. switch (pty_cai[5])
  4940. {
  4941. case DIVERSION_INTERROGATE_CFU:
  4942. case DIVERSION_INTERROGATE_CFB:
  4943. case DIVERSION_INTERROGATE_CFNR:
  4944. dbug(1, dprintf("Interr_Div"));
  4945. PUT_WORD(&pty_cai[1], S_INTERROGATE_DIVERSION);
  4946. pty_cai[3] = pty_cai[0] - 3; /* Supplementary Service-specific parameter len */
  4947. break;
  4948. case DIVERSION_INTERROGATE_NUM:
  4949. dbug(1, dprintf("Interr_Num"));
  4950. PUT_WORD(&pty_cai[1], S_INTERROGATE_NUMBERS);
  4951. pty_cai[3] = pty_cai[0] - 3; /* Supplementary Service-specific parameter len */
  4952. break;
  4953. case CCBS_REQUEST:
  4954. dbug(1, dprintf("CCBS Request"));
  4955. PUT_WORD(&pty_cai[1], S_CCBS_REQUEST);
  4956. pty_cai[3] = pty_cai[0] - 3; /* Supplementary Service-specific parameter len */
  4957. break;
  4958. case CCBS_DEACTIVATE:
  4959. dbug(1, dprintf("CCBS Deactivate"));
  4960. PUT_WORD(&pty_cai[1], S_CCBS_DEACTIVATE);
  4961. pty_cai[3] = pty_cai[0] - 3; /* Supplementary Service-specific parameter len */
  4962. break;
  4963. case CCBS_INTERROGATE:
  4964. dbug(1, dprintf("CCBS Interrogate"));
  4965. PUT_WORD(&pty_cai[1], S_CCBS_INTERROGATE);
  4966. pty_cai[3] = pty_cai[0] - 3; /* Supplementary Service-specific parameter len */
  4967. break;
  4968. }
  4969. PUT_WORD(&pty_cai[4], 0); /* Supplementary Service Reason */
  4970. PUT_DWORD(&pty_cai[6], plci->appl->S_Handle);
  4971. sendf(plci->appl, _FACILITY_I, Id & 0x7, 0, "wS", 3, pty_cai);
  4972. plci_remove(plci);
  4973. break;
  4974. case ACTIVATION_MWI:
  4975. case DEACTIVATION_MWI:
  4976. if (pty_cai[5] == ACTIVATION_MWI)
  4977. {
  4978. PUT_WORD(&SS_Ind[1], S_MWI_ACTIVATE);
  4979. }
  4980. else PUT_WORD(&SS_Ind[1], S_MWI_DEACTIVATE);
  4981. if (plci->cr_enquiry)
  4982. {
  4983. sendf(plci->appl, _FACILITY_I, Id & 0xf, 0, "ws", 3, SS_Ind);
  4984. plci_remove(plci);
  4985. }
  4986. else
  4987. {
  4988. sendf(plci->appl, _FACILITY_I, Id, 0, "ws", 3, SS_Ind);
  4989. }
  4990. break;
  4991. case MWI_INDICATION:
  4992. if (pty_cai[0] >= 0x12)
  4993. {
  4994. PUT_WORD(&pty_cai[3], S_MWI_INDICATE);
  4995. pty_cai[2] = pty_cai[0] - 2; /* len Parameter */
  4996. pty_cai[5] = pty_cai[0] - 5; /* Supplementary Service-specific parameter len */
  4997. if (plci->appl && (a->Notification_Mask[plci->appl->Id - 1] & SMASK_MWI))
  4998. {
  4999. if (plci->internal_command == GET_MWI_STATE) /* result on Message Waiting Listen */
  5000. {
  5001. sendf(plci->appl, _FACILITY_I, Id & 0xf, 0, "wS", 3, &pty_cai[2]);
  5002. plci_remove(plci);
  5003. return;
  5004. }
  5005. else sendf(plci->appl, _FACILITY_I, Id, 0, "wS", 3, &pty_cai[2]);
  5006. pty_cai[0] = 0;
  5007. }
  5008. else
  5009. {
  5010. for (i = 0; i < max_appl; i++)
  5011. {
  5012. if (a->Notification_Mask[i]&SMASK_MWI)
  5013. {
  5014. sendf(&application[i], _FACILITY_I, Id & 0x7, 0, "wS", 3, &pty_cai[2]);
  5015. pty_cai[0] = 0;
  5016. }
  5017. }
  5018. }
  5019. if (!pty_cai[0])
  5020. { /* acknowledge */
  5021. facility[2] = 0; /* returncode */
  5022. }
  5023. else facility[2] = 0xff;
  5024. }
  5025. else
  5026. {
  5027. /* reject */
  5028. facility[2] = 0xff; /* returncode */
  5029. }
  5030. facility[0] = 2;
  5031. facility[1] = MWI_RESPONSE; /* Function */
  5032. add_p(plci, CAI, facility);
  5033. add_p(plci, ESC, multi_ssext_parms[0]); /* remembered parameter -> only one possible */
  5034. sig_req(plci, S_SERVICE, 0);
  5035. send_req(plci);
  5036. plci->command = 0;
  5037. next_internal_command(Id, plci);
  5038. break;
  5039. case CONF_ADD: /* OK */
  5040. case CONF_BEGIN:
  5041. case CONF_DROP:
  5042. case CONF_ISOLATE:
  5043. case CONF_REATTACH:
  5044. case CONF_PARTYDISC:
  5045. CONF_Ind[0] = 9;
  5046. CONF_Ind[3] = 6;
  5047. switch (pty_cai[5])
  5048. {
  5049. case CONF_BEGIN:
  5050. PUT_WORD(&CONF_Ind[1], S_CONF_BEGIN);
  5051. if (pty_cai[0] == 6)
  5052. {
  5053. d = pty_cai[6];
  5054. PUT_DWORD(&CONF_Ind[6], d); /* PartyID */
  5055. }
  5056. else
  5057. {
  5058. PUT_DWORD(&CONF_Ind[6], 0x0);
  5059. }
  5060. break;
  5061. case CONF_ISOLATE:
  5062. PUT_WORD(&CONF_Ind[1], S_CONF_ISOLATE);
  5063. CONF_Ind[0] = 5;
  5064. CONF_Ind[3] = 2;
  5065. break;
  5066. case CONF_REATTACH:
  5067. PUT_WORD(&CONF_Ind[1], S_CONF_REATTACH);
  5068. CONF_Ind[0] = 5;
  5069. CONF_Ind[3] = 2;
  5070. break;
  5071. case CONF_DROP:
  5072. PUT_WORD(&CONF_Ind[1], S_CONF_DROP);
  5073. CONF_Ind[0] = 5;
  5074. CONF_Ind[3] = 2;
  5075. break;
  5076. case CONF_ADD:
  5077. PUT_WORD(&CONF_Ind[1], S_CONF_ADD);
  5078. d = pty_cai[6];
  5079. PUT_DWORD(&CONF_Ind[6], d); /* PartyID */
  5080. tplci = plci->relatedPTYPLCI;
  5081. if (tplci) tplci->ptyState = CONNECTED;
  5082. break;
  5083. case CONF_PARTYDISC:
  5084. CONF_Ind[0] = 7;
  5085. CONF_Ind[3] = 4;
  5086. PUT_WORD(&CONF_Ind[1], S_CONF_PARTYDISC);
  5087. d = pty_cai[6];
  5088. PUT_DWORD(&CONF_Ind[4], d); /* PartyID */
  5089. break;
  5090. }
  5091. plci->ptyState = CONNECTED;
  5092. sendf(plci->appl, _FACILITY_I, Id, 0, "ws", 3, CONF_Ind);
  5093. break;
  5094. case CCBS_INFO_RETAIN:
  5095. case CCBS_ERASECALLLINKAGEID:
  5096. case CCBS_STOP_ALERTING:
  5097. CONF_Ind[0] = 5;
  5098. CONF_Ind[3] = 2;
  5099. switch (pty_cai[5])
  5100. {
  5101. case CCBS_INFO_RETAIN:
  5102. PUT_WORD(&CONF_Ind[1], S_CCBS_INFO_RETAIN);
  5103. break;
  5104. case CCBS_STOP_ALERTING:
  5105. PUT_WORD(&CONF_Ind[1], S_CCBS_STOP_ALERTING);
  5106. break;
  5107. case CCBS_ERASECALLLINKAGEID:
  5108. PUT_WORD(&CONF_Ind[1], S_CCBS_ERASECALLLINKAGEID);
  5109. CONF_Ind[0] = 7;
  5110. CONF_Ind[3] = 4;
  5111. CONF_Ind[6] = 0;
  5112. CONF_Ind[7] = 0;
  5113. break;
  5114. }
  5115. w = pty_cai[6];
  5116. PUT_WORD(&CONF_Ind[4], w); /* PartyID */
  5117. if (plci->appl && (a->Notification_Mask[plci->appl->Id - 1] & SMASK_CCBS))
  5118. {
  5119. sendf(plci->appl, _FACILITY_I, Id, 0, "ws", 3, CONF_Ind);
  5120. }
  5121. else
  5122. {
  5123. for (i = 0; i < max_appl; i++)
  5124. if (a->Notification_Mask[i] & SMASK_CCBS)
  5125. sendf(&application[i], _FACILITY_I, Id & 0x7, 0, "ws", 3, CONF_Ind);
  5126. }
  5127. break;
  5128. }
  5129. break;
  5130. case CALL_HOLD_REJ:
  5131. cau = parms[7];
  5132. if (cau)
  5133. {
  5134. i = _L3_CAUSE | cau[2];
  5135. if (cau[2] == 0) i = 0x3603;
  5136. }
  5137. else
  5138. {
  5139. i = 0x3603;
  5140. }
  5141. PUT_WORD(&SS_Ind[1], S_HOLD);
  5142. PUT_WORD(&SS_Ind[4], i);
  5143. if (plci->SuppState == HOLD_REQUEST)
  5144. {
  5145. plci->SuppState = IDLE;
  5146. sendf(plci->appl, _FACILITY_I, Id, 0, "ws", 3, SS_Ind);
  5147. }
  5148. break;
  5149. case CALL_HOLD_ACK:
  5150. if (plci->SuppState == HOLD_REQUEST)
  5151. {
  5152. plci->SuppState = CALL_HELD;
  5153. CodecIdCheck(a, plci);
  5154. start_internal_command(Id, plci, hold_save_command);
  5155. }
  5156. break;
  5157. case CALL_RETRIEVE_REJ:
  5158. cau = parms[7];
  5159. if (cau)
  5160. {
  5161. i = _L3_CAUSE | cau[2];
  5162. if (cau[2] == 0) i = 0x3603;
  5163. }
  5164. else
  5165. {
  5166. i = 0x3603;
  5167. }
  5168. PUT_WORD(&SS_Ind[1], S_RETRIEVE);
  5169. PUT_WORD(&SS_Ind[4], i);
  5170. if (plci->SuppState == RETRIEVE_REQUEST)
  5171. {
  5172. plci->SuppState = CALL_HELD;
  5173. CodecIdCheck(a, plci);
  5174. sendf(plci->appl, _FACILITY_I, Id, 0, "ws", 3, SS_Ind);
  5175. }
  5176. break;
  5177. case CALL_RETRIEVE_ACK:
  5178. PUT_WORD(&SS_Ind[1], S_RETRIEVE);
  5179. if (plci->SuppState == RETRIEVE_REQUEST)
  5180. {
  5181. plci->SuppState = IDLE;
  5182. plci->call_dir |= CALL_DIR_FORCE_OUTG_NL;
  5183. plci->b_channel = esc_chi[esc_chi[0]]&0x1f;
  5184. if (plci->tel)
  5185. {
  5186. mixer_set_bchannel_id_esc(plci, plci->b_channel);
  5187. dbug(1, dprintf("RetrChannel=0x%x", plci->b_channel));
  5188. SetVoiceChannel(a->AdvCodecPLCI, esc_chi, a);
  5189. if (plci->B2_prot == B2_TRANSPARENT && plci->B3_prot == B3_TRANSPARENT)
  5190. {
  5191. dbug(1, dprintf("Get B-ch"));
  5192. start_internal_command(Id, plci, retrieve_restore_command);
  5193. }
  5194. else
  5195. sendf(plci->appl, _FACILITY_I, Id, 0, "ws", 3, SS_Ind);
  5196. }
  5197. else
  5198. start_internal_command(Id, plci, retrieve_restore_command);
  5199. }
  5200. break;
  5201. case INDICATE_IND:
  5202. if (plci->State != LISTENING) {
  5203. sig_req(plci, HANGUP, 0);
  5204. send_req(plci);
  5205. break;
  5206. }
  5207. cip = find_cip(a, parms[4], parms[6]);
  5208. cip_mask = 1L << cip;
  5209. dbug(1, dprintf("cip=%d,cip_mask=%lx", cip, cip_mask));
  5210. clear_c_ind_mask(plci);
  5211. if (!remove_started && !a->adapter_disabled)
  5212. {
  5213. set_c_ind_mask_bit(plci, MAX_APPL);
  5214. group_optimization(a, plci);
  5215. for (i = 0; i < max_appl; i++) {
  5216. if (application[i].Id
  5217. && (a->CIP_Mask[i] & 1 || a->CIP_Mask[i] & cip_mask)
  5218. && CPN_filter_ok(parms[0], a, i)
  5219. && test_group_ind_mask_bit(plci, i)) {
  5220. dbug(1, dprintf("storedcip_mask[%d]=0x%lx", i, a->CIP_Mask[i]));
  5221. set_c_ind_mask_bit(plci, i);
  5222. dump_c_ind_mask(plci);
  5223. plci->State = INC_CON_PENDING;
  5224. plci->call_dir = (plci->call_dir & ~(CALL_DIR_OUT | CALL_DIR_ORIGINATE)) |
  5225. CALL_DIR_IN | CALL_DIR_ANSWER;
  5226. if (esc_chi[0]) {
  5227. plci->b_channel = esc_chi[esc_chi[0]] & 0x1f;
  5228. mixer_set_bchannel_id_esc(plci, plci->b_channel);
  5229. }
  5230. /* if a listen on the ext controller is done, check if hook states */
  5231. /* are supported or if just a on board codec must be activated */
  5232. if (a->codec_listen[i] && !a->AdvSignalPLCI) {
  5233. if (a->profile.Global_Options & HANDSET)
  5234. plci->tel = ADV_VOICE;
  5235. else if (a->profile.Global_Options & ON_BOARD_CODEC)
  5236. plci->tel = CODEC;
  5237. if (plci->tel) Id |= EXT_CONTROLLER;
  5238. a->codec_listen[i] = plci;
  5239. }
  5240. sendf(&application[i], _CONNECT_I, Id, 0,
  5241. "wSSSSSSSbSSSSS", cip, /* CIP */
  5242. parms[0], /* CalledPartyNumber */
  5243. multi_CiPN_parms[0], /* CallingPartyNumber */
  5244. parms[2], /* CalledPartySubad */
  5245. parms[3], /* CallingPartySubad */
  5246. parms[4], /* BearerCapability */
  5247. parms[5], /* LowLC */
  5248. parms[6], /* HighLC */
  5249. ai_len, /* nested struct add_i */
  5250. add_i[0], /* B channel info */
  5251. add_i[1], /* keypad facility */
  5252. add_i[2], /* user user data */
  5253. add_i[3], /* nested facility */
  5254. multi_CiPN_parms[1] /* second CiPN(SCR) */
  5255. );
  5256. SendSSExtInd(&application[i],
  5257. plci,
  5258. Id,
  5259. multi_ssext_parms);
  5260. SendSetupInfo(&application[i],
  5261. plci,
  5262. Id,
  5263. parms,
  5264. SendMultiIE(plci, Id, multi_pi_parms, PI, 0x210, true));
  5265. }
  5266. }
  5267. clear_c_ind_mask_bit(plci, MAX_APPL);
  5268. dump_c_ind_mask(plci);
  5269. }
  5270. if (c_ind_mask_empty(plci)) {
  5271. sig_req(plci, HANGUP, 0);
  5272. send_req(plci);
  5273. plci->State = IDLE;
  5274. }
  5275. plci->notifiedcall = 0;
  5276. a->listen_active--;
  5277. listen_check(a);
  5278. break;
  5279. case CALL_PEND_NOTIFY:
  5280. plci->notifiedcall = 1;
  5281. listen_check(a);
  5282. break;
  5283. case CALL_IND:
  5284. case CALL_CON:
  5285. if (plci->State == ADVANCED_VOICE_SIG || plci->State == ADVANCED_VOICE_NOSIG)
  5286. {
  5287. if (plci->internal_command == PERM_COD_CONN_PEND)
  5288. {
  5289. if (plci->State == ADVANCED_VOICE_NOSIG)
  5290. {
  5291. dbug(1, dprintf("***Codec OK"));
  5292. if (a->AdvSignalPLCI)
  5293. {
  5294. tplci = a->AdvSignalPLCI;
  5295. if (tplci->spoofed_msg)
  5296. {
  5297. dbug(1, dprintf("***Spoofed Msg(0x%x)", tplci->spoofed_msg));
  5298. tplci->command = 0;
  5299. tplci->internal_command = 0;
  5300. x_Id = ((word)tplci->Id << 8) | tplci->adapter->Id | 0x80;
  5301. switch (tplci->spoofed_msg)
  5302. {
  5303. case CALL_RES:
  5304. tplci->command = _CONNECT_I | RESPONSE;
  5305. api_load_msg(&tplci->saved_msg, saved_parms);
  5306. add_b1(tplci, &saved_parms[1], 0, tplci->B1_facilities);
  5307. if (tplci->adapter->Info_Mask[tplci->appl->Id - 1] & 0x200)
  5308. {
  5309. /* early B3 connect (CIP mask bit 9) no release after a disc */
  5310. add_p(tplci, LLI, "\x01\x01");
  5311. }
  5312. add_s(tplci, CONN_NR, &saved_parms[2]);
  5313. add_s(tplci, LLC, &saved_parms[4]);
  5314. add_ai(tplci, &saved_parms[5]);
  5315. tplci->State = INC_CON_ACCEPT;
  5316. sig_req(tplci, CALL_RES, 0);
  5317. send_req(tplci);
  5318. break;
  5319. case AWAITING_SELECT_B:
  5320. dbug(1, dprintf("Select_B continue"));
  5321. start_internal_command(x_Id, tplci, select_b_command);
  5322. break;
  5323. case AWAITING_MANUF_CON: /* Get_Plci per Manufacturer_Req to ext controller */
  5324. if (!tplci->Sig.Id)
  5325. {
  5326. dbug(1, dprintf("No SigID!"));
  5327. sendf(tplci->appl, _MANUFACTURER_R | CONFIRM, x_Id, tplci->number, "dww", _DI_MANU_ID, _MANUFACTURER_R, _OUT_OF_PLCI);
  5328. plci_remove(tplci);
  5329. break;
  5330. }
  5331. tplci->command = _MANUFACTURER_R;
  5332. api_load_msg(&tplci->saved_msg, saved_parms);
  5333. dir = saved_parms[2].info[0];
  5334. if (dir == 1) {
  5335. sig_req(tplci, CALL_REQ, 0);
  5336. }
  5337. else if (!dir) {
  5338. sig_req(tplci, LISTEN_REQ, 0);
  5339. }
  5340. send_req(tplci);
  5341. sendf(tplci->appl, _MANUFACTURER_R | CONFIRM, x_Id, tplci->number, "dww", _DI_MANU_ID, _MANUFACTURER_R, 0);
  5342. break;
  5343. case (CALL_REQ | AWAITING_MANUF_CON):
  5344. sig_req(tplci, CALL_REQ, 0);
  5345. send_req(tplci);
  5346. break;
  5347. case CALL_REQ:
  5348. if (!tplci->Sig.Id)
  5349. {
  5350. dbug(1, dprintf("No SigID!"));
  5351. sendf(tplci->appl, _CONNECT_R | CONFIRM, tplci->adapter->Id, 0, "w", _OUT_OF_PLCI);
  5352. plci_remove(tplci);
  5353. break;
  5354. }
  5355. tplci->command = _CONNECT_R;
  5356. api_load_msg(&tplci->saved_msg, saved_parms);
  5357. add_s(tplci, CPN, &saved_parms[1]);
  5358. add_s(tplci, DSA, &saved_parms[3]);
  5359. add_ai(tplci, &saved_parms[9]);
  5360. sig_req(tplci, CALL_REQ, 0);
  5361. send_req(tplci);
  5362. break;
  5363. case CALL_RETRIEVE:
  5364. tplci->command = C_RETRIEVE_REQ;
  5365. sig_req(tplci, CALL_RETRIEVE, 0);
  5366. send_req(tplci);
  5367. break;
  5368. }
  5369. tplci->spoofed_msg = 0;
  5370. if (tplci->internal_command == 0)
  5371. next_internal_command(x_Id, tplci);
  5372. }
  5373. }
  5374. next_internal_command(Id, plci);
  5375. break;
  5376. }
  5377. dbug(1, dprintf("***Codec Hook Init Req"));
  5378. plci->internal_command = PERM_COD_HOOK;
  5379. add_p(plci, FTY, "\x01\x09"); /* Get Hook State*/
  5380. sig_req(plci, TEL_CTRL, 0);
  5381. send_req(plci);
  5382. }
  5383. }
  5384. else if (plci->command != _MANUFACTURER_R /* old style permanent connect */
  5385. && plci->State != INC_ACT_PENDING)
  5386. {
  5387. mixer_set_bchannel_id_esc(plci, plci->b_channel);
  5388. if (plci->tel == ADV_VOICE && plci->SuppState == IDLE) /* with permanent codec switch on immediately */
  5389. {
  5390. chi[2] = plci->b_channel;
  5391. SetVoiceChannel(a->AdvCodecPLCI, chi, a);
  5392. }
  5393. sendf(plci->appl, _CONNECT_ACTIVE_I, Id, 0, "Sss", parms[21], "", "");
  5394. plci->State = INC_ACT_PENDING;
  5395. }
  5396. break;
  5397. case TEL_CTRL:
  5398. ie = multi_fac_parms[0]; /* inspect the facility hook indications */
  5399. if (plci->State == ADVANCED_VOICE_SIG && ie[0]) {
  5400. switch (ie[1] & 0x91) {
  5401. case 0x80: /* hook off */
  5402. case 0x81:
  5403. if (plci->internal_command == PERM_COD_HOOK)
  5404. {
  5405. dbug(1, dprintf("init:hook_off"));
  5406. plci->hook_state = ie[1];
  5407. next_internal_command(Id, plci);
  5408. break;
  5409. }
  5410. else /* ignore doubled hook indications */
  5411. {
  5412. if (((plci->hook_state) & 0xf0) == 0x80)
  5413. {
  5414. dbug(1, dprintf("ignore hook"));
  5415. break;
  5416. }
  5417. plci->hook_state = ie[1]&0x91;
  5418. }
  5419. /* check for incoming call pending */
  5420. /* and signal '+'.Appl must decide */
  5421. /* with connect_res if call must */
  5422. /* accepted or not */
  5423. for (i = 0, tplci = NULL; i < max_appl; i++) {
  5424. if (a->codec_listen[i]
  5425. && (a->codec_listen[i]->State == INC_CON_PENDING
  5426. || a->codec_listen[i]->State == INC_CON_ALERT)) {
  5427. tplci = a->codec_listen[i];
  5428. tplci->appl = &application[i];
  5429. }
  5430. }
  5431. /* no incoming call, do outgoing call */
  5432. /* and signal '+' if outg. setup */
  5433. if (!a->AdvSignalPLCI && !tplci) {
  5434. if ((i = get_plci(a))) {
  5435. a->AdvSignalPLCI = &a->plci[i - 1];
  5436. tplci = a->AdvSignalPLCI;
  5437. tplci->tel = ADV_VOICE;
  5438. PUT_WORD(&voice_cai[5], a->AdvSignalAppl->MaxDataLength);
  5439. if (a->Info_Mask[a->AdvSignalAppl->Id - 1] & 0x200) {
  5440. /* early B3 connect (CIP mask bit 9) no release after a disc */
  5441. add_p(tplci, LLI, "\x01\x01");
  5442. }
  5443. add_p(tplci, CAI, voice_cai);
  5444. add_p(tplci, OAD, a->TelOAD);
  5445. add_p(tplci, OSA, a->TelOSA);
  5446. add_p(tplci, SHIFT | 6, NULL);
  5447. add_p(tplci, SIN, "\x02\x01\x00");
  5448. add_p(tplci, UID, "\x06\x43\x61\x70\x69\x32\x30");
  5449. sig_req(tplci, ASSIGN, DSIG_ID);
  5450. a->AdvSignalPLCI->internal_command = HOOK_OFF_REQ;
  5451. a->AdvSignalPLCI->command = 0;
  5452. tplci->appl = a->AdvSignalAppl;
  5453. tplci->call_dir = CALL_DIR_OUT | CALL_DIR_ORIGINATE;
  5454. send_req(tplci);
  5455. }
  5456. }
  5457. if (!tplci) break;
  5458. Id = ((word)tplci->Id << 8) | a->Id;
  5459. Id |= EXT_CONTROLLER;
  5460. sendf(tplci->appl,
  5461. _FACILITY_I,
  5462. Id,
  5463. 0,
  5464. "ws", (word)0, "\x01+");
  5465. break;
  5466. case 0x90: /* hook on */
  5467. case 0x91:
  5468. if (plci->internal_command == PERM_COD_HOOK)
  5469. {
  5470. dbug(1, dprintf("init:hook_on"));
  5471. plci->hook_state = ie[1] & 0x91;
  5472. next_internal_command(Id, plci);
  5473. break;
  5474. }
  5475. else /* ignore doubled hook indications */
  5476. {
  5477. if (((plci->hook_state) & 0xf0) == 0x90) break;
  5478. plci->hook_state = ie[1] & 0x91;
  5479. }
  5480. /* hangup the adv. voice call and signal '-' to the appl */
  5481. if (a->AdvSignalPLCI) {
  5482. Id = ((word)a->AdvSignalPLCI->Id << 8) | a->Id;
  5483. if (plci->tel) Id |= EXT_CONTROLLER;
  5484. sendf(a->AdvSignalAppl,
  5485. _FACILITY_I,
  5486. Id,
  5487. 0,
  5488. "ws", (word)0, "\x01-");
  5489. a->AdvSignalPLCI->internal_command = HOOK_ON_REQ;
  5490. a->AdvSignalPLCI->command = 0;
  5491. sig_req(a->AdvSignalPLCI, HANGUP, 0);
  5492. send_req(a->AdvSignalPLCI);
  5493. }
  5494. break;
  5495. }
  5496. }
  5497. break;
  5498. case RESUME:
  5499. clear_c_ind_mask_bit(plci, (word)(plci->appl->Id - 1));
  5500. PUT_WORD(&resume_cau[4], GOOD);
  5501. sendf(plci->appl, _FACILITY_I, Id, 0, "ws", (word)3, resume_cau);
  5502. break;
  5503. case SUSPEND:
  5504. clear_c_ind_mask(plci);
  5505. if (plci->NL.Id && !plci->nl_remove_id) {
  5506. mixer_remove(plci);
  5507. nl_req_ncci(plci, REMOVE, 0);
  5508. }
  5509. if (!plci->sig_remove_id) {
  5510. plci->internal_command = 0;
  5511. sig_req(plci, REMOVE, 0);
  5512. }
  5513. send_req(plci);
  5514. if (!plci->channels) {
  5515. sendf(plci->appl, _FACILITY_I, Id, 0, "ws", (word)3, "\x05\x04\x00\x02\x00\x00");
  5516. sendf(plci->appl, _DISCONNECT_I, Id, 0, "w", 0);
  5517. }
  5518. break;
  5519. case SUSPEND_REJ:
  5520. break;
  5521. case HANGUP:
  5522. plci->hangup_flow_ctrl_timer = 0;
  5523. if (plci->manufacturer && plci->State == LOCAL_CONNECT) break;
  5524. cau = parms[7];
  5525. if (cau) {
  5526. i = _L3_CAUSE | cau[2];
  5527. if (cau[2] == 0) i = 0;
  5528. else if (cau[2] == 8) i = _L1_ERROR;
  5529. else if (cau[2] == 9 || cau[2] == 10) i = _L2_ERROR;
  5530. else if (cau[2] == 5) i = _CAPI_GUARD_ERROR;
  5531. }
  5532. else {
  5533. i = _L3_ERROR;
  5534. }
  5535. if (plci->State == INC_CON_PENDING || plci->State == INC_CON_ALERT)
  5536. {
  5537. for (i = 0; i < max_appl; i++)
  5538. {
  5539. if (test_c_ind_mask_bit(plci, i))
  5540. sendf(&application[i], _DISCONNECT_I, Id, 0, "w", 0);
  5541. }
  5542. }
  5543. else
  5544. {
  5545. clear_c_ind_mask(plci);
  5546. }
  5547. if (!plci->appl)
  5548. {
  5549. if (plci->State == LISTENING)
  5550. {
  5551. plci->notifiedcall = 0;
  5552. a->listen_active--;
  5553. }
  5554. plci->State = INC_DIS_PENDING;
  5555. if (c_ind_mask_empty(plci))
  5556. {
  5557. plci->State = IDLE;
  5558. if (plci->NL.Id && !plci->nl_remove_id)
  5559. {
  5560. mixer_remove(plci);
  5561. nl_req_ncci(plci, REMOVE, 0);
  5562. }
  5563. if (!plci->sig_remove_id)
  5564. {
  5565. plci->internal_command = 0;
  5566. sig_req(plci, REMOVE, 0);
  5567. }
  5568. send_req(plci);
  5569. }
  5570. }
  5571. else
  5572. {
  5573. /* collision of DISCONNECT or CONNECT_RES with HANGUP can */
  5574. /* result in a second HANGUP! Don't generate another */
  5575. /* DISCONNECT */
  5576. if (plci->State != IDLE && plci->State != INC_DIS_PENDING)
  5577. {
  5578. if (plci->State == RESUMING)
  5579. {
  5580. PUT_WORD(&resume_cau[4], i);
  5581. sendf(plci->appl, _FACILITY_I, Id, 0, "ws", (word)3, resume_cau);
  5582. }
  5583. plci->State = INC_DIS_PENDING;
  5584. sendf(plci->appl, _DISCONNECT_I, Id, 0, "w", i);
  5585. }
  5586. }
  5587. break;
  5588. case SSEXT_IND:
  5589. SendSSExtInd(NULL, plci, Id, multi_ssext_parms);
  5590. break;
  5591. case VSWITCH_REQ:
  5592. VSwitchReqInd(plci, Id, multi_vswitch_parms);
  5593. break;
  5594. case VSWITCH_IND:
  5595. if (plci->relatedPTYPLCI &&
  5596. plci->vswitchstate == 3 &&
  5597. plci->relatedPTYPLCI->vswitchstate == 3 &&
  5598. parms[MAXPARMSIDS - 1][0])
  5599. {
  5600. add_p(plci->relatedPTYPLCI, SMSG, parms[MAXPARMSIDS - 1]);
  5601. sig_req(plci->relatedPTYPLCI, VSWITCH_REQ, 0);
  5602. send_req(plci->relatedPTYPLCI);
  5603. }
  5604. else VSwitchReqInd(plci, Id, multi_vswitch_parms);
  5605. break;
  5606. }
  5607. }
  5608. static void SendSetupInfo(APPL *appl, PLCI *plci, dword Id, byte **parms, byte Info_Sent_Flag)
  5609. {
  5610. word i;
  5611. byte *ie;
  5612. word Info_Number;
  5613. byte *Info_Element;
  5614. word Info_Mask = 0;
  5615. dbug(1, dprintf("SetupInfo"));
  5616. for (i = 0; i < MAXPARMSIDS; i++) {
  5617. ie = parms[i];
  5618. Info_Number = 0;
  5619. Info_Element = ie;
  5620. if (ie[0]) {
  5621. switch (i) {
  5622. case 0:
  5623. dbug(1, dprintf("CPN "));
  5624. Info_Number = 0x0070;
  5625. Info_Mask = 0x80;
  5626. Info_Sent_Flag = true;
  5627. break;
  5628. case 8: /* display */
  5629. dbug(1, dprintf("display(%d)", i));
  5630. Info_Number = 0x0028;
  5631. Info_Mask = 0x04;
  5632. Info_Sent_Flag = true;
  5633. break;
  5634. case 16: /* Channel Id */
  5635. dbug(1, dprintf("CHI"));
  5636. Info_Number = 0x0018;
  5637. Info_Mask = 0x100;
  5638. Info_Sent_Flag = true;
  5639. mixer_set_bchannel_id(plci, Info_Element);
  5640. break;
  5641. case 19: /* Redirected Number */
  5642. dbug(1, dprintf("RDN"));
  5643. Info_Number = 0x0074;
  5644. Info_Mask = 0x400;
  5645. Info_Sent_Flag = true;
  5646. break;
  5647. case 20: /* Redirected Number extended */
  5648. dbug(1, dprintf("RDX"));
  5649. Info_Number = 0x0073;
  5650. Info_Mask = 0x400;
  5651. Info_Sent_Flag = true;
  5652. break;
  5653. case 22: /* Redirecing Number */
  5654. dbug(1, dprintf("RIN"));
  5655. Info_Number = 0x0076;
  5656. Info_Mask = 0x400;
  5657. Info_Sent_Flag = true;
  5658. break;
  5659. default:
  5660. Info_Number = 0;
  5661. break;
  5662. }
  5663. }
  5664. if (i == MAXPARMSIDS - 2) { /* to indicate the message type "Setup" */
  5665. Info_Number = 0x8000 | 5;
  5666. Info_Mask = 0x10;
  5667. Info_Element = "";
  5668. }
  5669. if (Info_Sent_Flag && Info_Number) {
  5670. if (plci->adapter->Info_Mask[appl->Id - 1] & Info_Mask) {
  5671. sendf(appl, _INFO_I, Id, 0, "wS", Info_Number, Info_Element);
  5672. }
  5673. }
  5674. }
  5675. }
  5676. static void SendInfo(PLCI *plci, dword Id, byte **parms, byte iesent)
  5677. {
  5678. word i;
  5679. word j;
  5680. word k;
  5681. byte *ie;
  5682. word Info_Number;
  5683. byte *Info_Element;
  5684. word Info_Mask = 0;
  5685. static byte charges[5] = {4, 0, 0, 0, 0};
  5686. static byte cause[] = {0x02, 0x80, 0x00};
  5687. APPL *appl;
  5688. dbug(1, dprintf("InfoParse "));
  5689. if (
  5690. !plci->appl
  5691. && !plci->State
  5692. && plci->Sig.Ind != NCR_FACILITY
  5693. )
  5694. {
  5695. dbug(1, dprintf("NoParse "));
  5696. return;
  5697. }
  5698. cause[2] = 0;
  5699. for (i = 0; i < MAXPARMSIDS; i++) {
  5700. ie = parms[i];
  5701. Info_Number = 0;
  5702. Info_Element = ie;
  5703. if (ie[0]) {
  5704. switch (i) {
  5705. case 0:
  5706. dbug(1, dprintf("CPN "));
  5707. Info_Number = 0x0070;
  5708. Info_Mask = 0x80;
  5709. break;
  5710. case 7: /* ESC_CAU */
  5711. dbug(1, dprintf("cau(0x%x)", ie[2]));
  5712. Info_Number = 0x0008;
  5713. Info_Mask = 0x00;
  5714. cause[2] = ie[2];
  5715. Info_Element = NULL;
  5716. break;
  5717. case 8: /* display */
  5718. dbug(1, dprintf("display(%d)", i));
  5719. Info_Number = 0x0028;
  5720. Info_Mask = 0x04;
  5721. break;
  5722. case 9: /* Date display */
  5723. dbug(1, dprintf("date(%d)", i));
  5724. Info_Number = 0x0029;
  5725. Info_Mask = 0x02;
  5726. break;
  5727. case 10: /* charges */
  5728. for (j = 0; j < 4; j++) charges[1 + j] = 0;
  5729. for (j = 0; j < ie[0] && !(ie[1 + j] & 0x80); j++);
  5730. for (k = 1, j++; j < ie[0] && k <= 4; j++, k++) charges[k] = ie[1 + j];
  5731. Info_Number = 0x4000;
  5732. Info_Mask = 0x40;
  5733. Info_Element = charges;
  5734. break;
  5735. case 11: /* user user info */
  5736. dbug(1, dprintf("uui"));
  5737. Info_Number = 0x007E;
  5738. Info_Mask = 0x08;
  5739. break;
  5740. case 12: /* congestion receiver ready */
  5741. dbug(1, dprintf("clRDY"));
  5742. Info_Number = 0x00B0;
  5743. Info_Mask = 0x08;
  5744. Info_Element = "";
  5745. break;
  5746. case 13: /* congestion receiver not ready */
  5747. dbug(1, dprintf("clNRDY"));
  5748. Info_Number = 0x00BF;
  5749. Info_Mask = 0x08;
  5750. Info_Element = "";
  5751. break;
  5752. case 15: /* Keypad Facility */
  5753. dbug(1, dprintf("KEY"));
  5754. Info_Number = 0x002C;
  5755. Info_Mask = 0x20;
  5756. break;
  5757. case 16: /* Channel Id */
  5758. dbug(1, dprintf("CHI"));
  5759. Info_Number = 0x0018;
  5760. Info_Mask = 0x100;
  5761. mixer_set_bchannel_id(plci, Info_Element);
  5762. break;
  5763. case 17: /* if no 1tr6 cause, send full cause, else esc_cause */
  5764. dbug(1, dprintf("q9cau(0x%x)", ie[2]));
  5765. if (!cause[2] || cause[2] < 0x80) break; /* eg. layer 1 error */
  5766. Info_Number = 0x0008;
  5767. Info_Mask = 0x01;
  5768. if (cause[2] != ie[2]) Info_Element = cause;
  5769. break;
  5770. case 19: /* Redirected Number */
  5771. dbug(1, dprintf("RDN"));
  5772. Info_Number = 0x0074;
  5773. Info_Mask = 0x400;
  5774. break;
  5775. case 22: /* Redirecing Number */
  5776. dbug(1, dprintf("RIN"));
  5777. Info_Number = 0x0076;
  5778. Info_Mask = 0x400;
  5779. break;
  5780. case 23: /* Notification Indicator */
  5781. dbug(1, dprintf("NI"));
  5782. Info_Number = (word)NI;
  5783. Info_Mask = 0x210;
  5784. break;
  5785. case 26: /* Call State */
  5786. dbug(1, dprintf("CST"));
  5787. Info_Number = (word)CST;
  5788. Info_Mask = 0x01; /* do with cause i.e. for now */
  5789. break;
  5790. case MAXPARMSIDS - 2: /* Escape Message Type, must be the last indication */
  5791. dbug(1, dprintf("ESC/MT[0x%x]", ie[3]));
  5792. Info_Number = 0x8000 | ie[3];
  5793. if (iesent) Info_Mask = 0xffff;
  5794. else Info_Mask = 0x10;
  5795. Info_Element = "";
  5796. break;
  5797. default:
  5798. Info_Number = 0;
  5799. Info_Mask = 0;
  5800. Info_Element = "";
  5801. break;
  5802. }
  5803. }
  5804. if (plci->Sig.Ind == NCR_FACILITY) /* check controller broadcast */
  5805. {
  5806. for (j = 0; j < max_appl; j++)
  5807. {
  5808. appl = &application[j];
  5809. if (Info_Number
  5810. && appl->Id
  5811. && plci->adapter->Info_Mask[appl->Id - 1] & Info_Mask)
  5812. {
  5813. dbug(1, dprintf("NCR_Ind"));
  5814. iesent = true;
  5815. sendf(&application[j], _INFO_I, Id & 0x0f, 0, "wS", Info_Number, Info_Element);
  5816. }
  5817. }
  5818. }
  5819. else if (!plci->appl)
  5820. { /* overlap receiving broadcast */
  5821. if (Info_Number == CPN
  5822. || Info_Number == KEY
  5823. || Info_Number == NI
  5824. || Info_Number == DSP
  5825. || Info_Number == UUI)
  5826. {
  5827. for (j = 0; j < max_appl; j++)
  5828. {
  5829. if (test_c_ind_mask_bit(plci, j))
  5830. {
  5831. dbug(1, dprintf("Ovl_Ind"));
  5832. iesent = true;
  5833. sendf(&application[j], _INFO_I, Id, 0, "wS", Info_Number, Info_Element);
  5834. }
  5835. }
  5836. }
  5837. } /* all other signalling states */
  5838. else if (Info_Number
  5839. && plci->adapter->Info_Mask[plci->appl->Id - 1] & Info_Mask)
  5840. {
  5841. dbug(1, dprintf("Std_Ind"));
  5842. iesent = true;
  5843. sendf(plci->appl, _INFO_I, Id, 0, "wS", Info_Number, Info_Element);
  5844. }
  5845. }
  5846. }
  5847. static byte SendMultiIE(PLCI *plci, dword Id, byte **parms, byte ie_type,
  5848. dword info_mask, byte setupParse)
  5849. {
  5850. word i;
  5851. word j;
  5852. byte *ie;
  5853. word Info_Number;
  5854. byte *Info_Element;
  5855. APPL *appl;
  5856. word Info_Mask = 0;
  5857. byte iesent = 0;
  5858. if (
  5859. !plci->appl
  5860. && !plci->State
  5861. && plci->Sig.Ind != NCR_FACILITY
  5862. && !setupParse
  5863. )
  5864. {
  5865. dbug(1, dprintf("NoM-IEParse "));
  5866. return 0;
  5867. }
  5868. dbug(1, dprintf("M-IEParse "));
  5869. for (i = 0; i < MAX_MULTI_IE; i++)
  5870. {
  5871. ie = parms[i];
  5872. Info_Number = 0;
  5873. Info_Element = ie;
  5874. if (ie[0])
  5875. {
  5876. dbug(1, dprintf("[Ind0x%x]:IE=0x%x", plci->Sig.Ind, ie_type));
  5877. Info_Number = (word)ie_type;
  5878. Info_Mask = (word)info_mask;
  5879. }
  5880. if (plci->Sig.Ind == NCR_FACILITY) /* check controller broadcast */
  5881. {
  5882. for (j = 0; j < max_appl; j++)
  5883. {
  5884. appl = &application[j];
  5885. if (Info_Number
  5886. && appl->Id
  5887. && plci->adapter->Info_Mask[appl->Id - 1] & Info_Mask)
  5888. {
  5889. iesent = true;
  5890. dbug(1, dprintf("Mlt_NCR_Ind"));
  5891. sendf(&application[j], _INFO_I, Id & 0x0f, 0, "wS", Info_Number, Info_Element);
  5892. }
  5893. }
  5894. }
  5895. else if (!plci->appl && Info_Number)
  5896. { /* overlap receiving broadcast */
  5897. for (j = 0; j < max_appl; j++)
  5898. {
  5899. if (test_c_ind_mask_bit(plci, j))
  5900. {
  5901. iesent = true;
  5902. dbug(1, dprintf("Mlt_Ovl_Ind"));
  5903. sendf(&application[j] , _INFO_I, Id, 0, "wS", Info_Number, Info_Element);
  5904. }
  5905. }
  5906. } /* all other signalling states */
  5907. else if (Info_Number
  5908. && plci->adapter->Info_Mask[plci->appl->Id - 1] & Info_Mask)
  5909. {
  5910. iesent = true;
  5911. dbug(1, dprintf("Mlt_Std_Ind"));
  5912. sendf(plci->appl, _INFO_I, Id, 0, "wS", Info_Number, Info_Element);
  5913. }
  5914. }
  5915. return iesent;
  5916. }
  5917. static void SendSSExtInd(APPL *appl, PLCI *plci, dword Id, byte **parms)
  5918. {
  5919. word i;
  5920. /* Format of multi_ssext_parms[i][]:
  5921. 0 byte length
  5922. 1 byte SSEXTIE
  5923. 2 byte SSEXT_REQ/SSEXT_IND
  5924. 3 byte length
  5925. 4 word SSExtCommand
  5926. 6... Params
  5927. */
  5928. if (
  5929. plci
  5930. && plci->State
  5931. && plci->Sig.Ind != NCR_FACILITY
  5932. )
  5933. for (i = 0; i < MAX_MULTI_IE; i++)
  5934. {
  5935. if (parms[i][0] < 6) continue;
  5936. if (parms[i][2] == SSEXT_REQ) continue;
  5937. if (appl)
  5938. {
  5939. parms[i][0] = 0; /* kill it */
  5940. sendf(appl, _MANUFACTURER_I,
  5941. Id,
  5942. 0,
  5943. "dwS",
  5944. _DI_MANU_ID,
  5945. _DI_SSEXT_CTRL,
  5946. &parms[i][3]);
  5947. }
  5948. else if (plci->appl)
  5949. {
  5950. parms[i][0] = 0; /* kill it */
  5951. sendf(plci->appl, _MANUFACTURER_I,
  5952. Id,
  5953. 0,
  5954. "dwS",
  5955. _DI_MANU_ID,
  5956. _DI_SSEXT_CTRL,
  5957. &parms[i][3]);
  5958. }
  5959. }
  5960. };
  5961. static void nl_ind(PLCI *plci)
  5962. {
  5963. byte ch;
  5964. word ncci;
  5965. dword Id;
  5966. DIVA_CAPI_ADAPTER *a;
  5967. word NCCIcode;
  5968. APPL *APPLptr;
  5969. word count;
  5970. word Num;
  5971. word i, ncpi_state;
  5972. byte len, ncci_state;
  5973. word msg;
  5974. word info = 0;
  5975. word fax_feature_bits;
  5976. byte fax_send_edata_ack;
  5977. static byte v120_header_buffer[2 + 3];
  5978. static word fax_info[] = {
  5979. 0, /* T30_SUCCESS */
  5980. _FAX_NO_CONNECTION, /* T30_ERR_NO_DIS_RECEIVED */
  5981. _FAX_PROTOCOL_ERROR, /* T30_ERR_TIMEOUT_NO_RESPONSE */
  5982. _FAX_PROTOCOL_ERROR, /* T30_ERR_RETRY_NO_RESPONSE */
  5983. _FAX_PROTOCOL_ERROR, /* T30_ERR_TOO_MANY_REPEATS */
  5984. _FAX_PROTOCOL_ERROR, /* T30_ERR_UNEXPECTED_MESSAGE */
  5985. _FAX_REMOTE_ABORT, /* T30_ERR_UNEXPECTED_DCN */
  5986. _FAX_LOCAL_ABORT, /* T30_ERR_DTC_UNSUPPORTED */
  5987. _FAX_TRAINING_ERROR, /* T30_ERR_ALL_RATES_FAILED */
  5988. _FAX_TRAINING_ERROR, /* T30_ERR_TOO_MANY_TRAINS */
  5989. _FAX_PARAMETER_ERROR, /* T30_ERR_RECEIVE_CORRUPTED */
  5990. _FAX_REMOTE_ABORT, /* T30_ERR_UNEXPECTED_DISC */
  5991. _FAX_LOCAL_ABORT, /* T30_ERR_APPLICATION_DISC */
  5992. _FAX_REMOTE_REJECT, /* T30_ERR_INCOMPATIBLE_DIS */
  5993. _FAX_LOCAL_ABORT, /* T30_ERR_INCOMPATIBLE_DCS */
  5994. _FAX_PROTOCOL_ERROR, /* T30_ERR_TIMEOUT_NO_COMMAND */
  5995. _FAX_PROTOCOL_ERROR, /* T30_ERR_RETRY_NO_COMMAND */
  5996. _FAX_PROTOCOL_ERROR, /* T30_ERR_TIMEOUT_COMMAND_TOO_LONG */
  5997. _FAX_PROTOCOL_ERROR, /* T30_ERR_TIMEOUT_RESPONSE_TOO_LONG */
  5998. _FAX_NO_CONNECTION, /* T30_ERR_NOT_IDENTIFIED */
  5999. _FAX_PROTOCOL_ERROR, /* T30_ERR_SUPERVISORY_TIMEOUT */
  6000. _FAX_PARAMETER_ERROR, /* T30_ERR_TOO_LONG_SCAN_LINE */
  6001. _FAX_PROTOCOL_ERROR, /* T30_ERR_RETRY_NO_PAGE_AFTER_MPS */
  6002. _FAX_PROTOCOL_ERROR, /* T30_ERR_RETRY_NO_PAGE_AFTER_CFR */
  6003. _FAX_PROTOCOL_ERROR, /* T30_ERR_RETRY_NO_DCS_AFTER_FTT */
  6004. _FAX_PROTOCOL_ERROR, /* T30_ERR_RETRY_NO_DCS_AFTER_EOM */
  6005. _FAX_PROTOCOL_ERROR, /* T30_ERR_RETRY_NO_DCS_AFTER_MPS */
  6006. _FAX_PROTOCOL_ERROR, /* T30_ERR_RETRY_NO_DCN_AFTER_MCF */
  6007. _FAX_PROTOCOL_ERROR, /* T30_ERR_RETRY_NO_DCN_AFTER_RTN */
  6008. _FAX_PROTOCOL_ERROR, /* T30_ERR_RETRY_NO_CFR */
  6009. _FAX_PROTOCOL_ERROR, /* T30_ERR_RETRY_NO_MCF_AFTER_EOP */
  6010. _FAX_PROTOCOL_ERROR, /* T30_ERR_RETRY_NO_MCF_AFTER_EOM */
  6011. _FAX_PROTOCOL_ERROR, /* T30_ERR_RETRY_NO_MCF_AFTER_MPS */
  6012. 0x331d, /* T30_ERR_SUB_SEP_UNSUPPORTED */
  6013. 0x331e, /* T30_ERR_PWD_UNSUPPORTED */
  6014. 0x331f, /* T30_ERR_SUB_SEP_PWD_UNSUPPORTED */
  6015. _FAX_PROTOCOL_ERROR, /* T30_ERR_INVALID_COMMAND_FRAME */
  6016. _FAX_PARAMETER_ERROR, /* T30_ERR_UNSUPPORTED_PAGE_CODING */
  6017. _FAX_PARAMETER_ERROR, /* T30_ERR_INVALID_PAGE_CODING */
  6018. _FAX_REMOTE_REJECT, /* T30_ERR_INCOMPATIBLE_PAGE_CONFIG */
  6019. _FAX_LOCAL_ABORT, /* T30_ERR_TIMEOUT_FROM_APPLICATION */
  6020. _FAX_PROTOCOL_ERROR, /* T30_ERR_V34FAX_NO_REACTION_ON_MARK */
  6021. _FAX_PROTOCOL_ERROR, /* T30_ERR_V34FAX_TRAINING_TIMEOUT */
  6022. _FAX_PROTOCOL_ERROR, /* T30_ERR_V34FAX_UNEXPECTED_V21 */
  6023. _FAX_PROTOCOL_ERROR, /* T30_ERR_V34FAX_PRIMARY_CTS_ON */
  6024. _FAX_LOCAL_ABORT, /* T30_ERR_V34FAX_TURNAROUND_POLLING */
  6025. _FAX_LOCAL_ABORT /* T30_ERR_V34FAX_V8_INCOMPATIBILITY */
  6026. };
  6027. byte dtmf_code_buffer[CAPIDTMF_RECV_DIGIT_BUFFER_SIZE + 1];
  6028. static word rtp_info[] = {
  6029. GOOD, /* RTP_SUCCESS */
  6030. 0x3600 /* RTP_ERR_SSRC_OR_PAYLOAD_CHANGE */
  6031. };
  6032. static dword udata_forwarding_table[0x100 / sizeof(dword)] =
  6033. {
  6034. 0x0020301e, 0x00000000, 0x00000000, 0x00000000,
  6035. 0x00000000, 0x00000000, 0x00000000, 0x00000000
  6036. };
  6037. ch = plci->NL.IndCh;
  6038. a = plci->adapter;
  6039. ncci = a->ch_ncci[ch];
  6040. Id = (((dword)(ncci ? ncci : ch)) << 16) | (((word) plci->Id) << 8) | a->Id;
  6041. if (plci->tel) Id |= EXT_CONTROLLER;
  6042. APPLptr = plci->appl;
  6043. 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",
  6044. plci->NL.Id, Id, plci->Id, plci->tel, plci->State, ch, plci->channels, plci->NL.Ind & 0x0f));
  6045. /* in the case if no connect_active_Ind was sent to the appl we wait for */
  6046. if (plci->nl_remove_id)
  6047. {
  6048. plci->NL.RNR = 2; /* discard */
  6049. dbug(1, dprintf("NL discard while remove pending"));
  6050. return;
  6051. }
  6052. if ((plci->NL.Ind & 0x0f) == N_CONNECT)
  6053. {
  6054. if (plci->State == INC_DIS_PENDING
  6055. || plci->State == OUTG_DIS_PENDING
  6056. || plci->State == IDLE)
  6057. {
  6058. plci->NL.RNR = 2; /* discard */
  6059. dbug(1, dprintf("discard n_connect"));
  6060. return;
  6061. }
  6062. if (plci->State < INC_ACT_PENDING)
  6063. {
  6064. plci->NL.RNR = 1; /* flow control */
  6065. channel_x_off(plci, ch, N_XON_CONNECT_IND);
  6066. return;
  6067. }
  6068. }
  6069. if (!APPLptr) /* no application or invalid data */
  6070. { /* while reloading the DSP */
  6071. dbug(1, dprintf("discard1"));
  6072. plci->NL.RNR = 2;
  6073. return;
  6074. }
  6075. if (((plci->NL.Ind & 0x0f) == N_UDATA)
  6076. && (((plci->B2_prot != B2_SDLC) && ((plci->B1_resource == 17) || (plci->B1_resource == 18)))
  6077. || (plci->B2_prot == 7)
  6078. || (plci->B3_prot == 7)))
  6079. {
  6080. plci->ncpi_buffer[0] = 0;
  6081. ncpi_state = plci->ncpi_state;
  6082. if (plci->NL.complete == 1)
  6083. {
  6084. byte *data = &plci->NL.RBuffer->P[0];
  6085. if ((plci->NL.RBuffer->length >= 12)
  6086. && ((*data == DSP_UDATA_INDICATION_DCD_ON)
  6087. || (*data == DSP_UDATA_INDICATION_CTS_ON)))
  6088. {
  6089. word conn_opt, ncpi_opt = 0x00;
  6090. /* HexDump ("MDM N_UDATA:", plci->NL.RBuffer->length, data); */
  6091. if (*data == DSP_UDATA_INDICATION_DCD_ON)
  6092. plci->ncpi_state |= NCPI_MDM_DCD_ON_RECEIVED;
  6093. if (*data == DSP_UDATA_INDICATION_CTS_ON)
  6094. plci->ncpi_state |= NCPI_MDM_CTS_ON_RECEIVED;
  6095. data++; /* indication code */
  6096. data += 2; /* timestamp */
  6097. if ((*data == DSP_CONNECTED_NORM_V18) || (*data == DSP_CONNECTED_NORM_VOWN))
  6098. ncpi_state &= ~(NCPI_MDM_DCD_ON_RECEIVED | NCPI_MDM_CTS_ON_RECEIVED);
  6099. data++; /* connected norm */
  6100. conn_opt = GET_WORD(data);
  6101. data += 2; /* connected options */
  6102. PUT_WORD(&(plci->ncpi_buffer[1]), (word)(GET_DWORD(data) & 0x0000FFFF));
  6103. if (conn_opt & DSP_CONNECTED_OPTION_MASK_V42)
  6104. {
  6105. ncpi_opt |= MDM_NCPI_ECM_V42;
  6106. }
  6107. else if (conn_opt & DSP_CONNECTED_OPTION_MASK_MNP)
  6108. {
  6109. ncpi_opt |= MDM_NCPI_ECM_MNP;
  6110. }
  6111. else
  6112. {
  6113. ncpi_opt |= MDM_NCPI_TRANSPARENT;
  6114. }
  6115. if (conn_opt & DSP_CONNECTED_OPTION_MASK_COMPRESSION)
  6116. {
  6117. ncpi_opt |= MDM_NCPI_COMPRESSED;
  6118. }
  6119. PUT_WORD(&(plci->ncpi_buffer[3]), ncpi_opt);
  6120. plci->ncpi_buffer[0] = 4;
  6121. plci->ncpi_state |= NCPI_VALID_CONNECT_B3_IND | NCPI_VALID_CONNECT_B3_ACT | NCPI_VALID_DISC_B3_IND;
  6122. }
  6123. }
  6124. if (plci->B3_prot == 7)
  6125. {
  6126. if (((a->ncci_state[ncci] == INC_ACT_PENDING) || (a->ncci_state[ncci] == OUTG_CON_PENDING))
  6127. && (plci->ncpi_state & NCPI_VALID_CONNECT_B3_ACT)
  6128. && !(plci->ncpi_state & NCPI_CONNECT_B3_ACT_SENT))
  6129. {
  6130. a->ncci_state[ncci] = INC_ACT_PENDING;
  6131. sendf(plci->appl, _CONNECT_B3_ACTIVE_I, Id, 0, "S", plci->ncpi_buffer);
  6132. plci->ncpi_state |= NCPI_CONNECT_B3_ACT_SENT;
  6133. }
  6134. }
  6135. if (!((plci->requested_options_conn | plci->requested_options | plci->adapter->requested_options_table[plci->appl->Id - 1])
  6136. & ((1L << PRIVATE_V18) | (1L << PRIVATE_VOWN)))
  6137. || !(ncpi_state & NCPI_MDM_DCD_ON_RECEIVED)
  6138. || !(ncpi_state & NCPI_MDM_CTS_ON_RECEIVED))
  6139. {
  6140. plci->NL.RNR = 2;
  6141. return;
  6142. }
  6143. }
  6144. if (plci->NL.complete == 2)
  6145. {
  6146. if (((plci->NL.Ind & 0x0f) == N_UDATA)
  6147. && !(udata_forwarding_table[plci->RData[0].P[0] >> 5] & (1L << (plci->RData[0].P[0] & 0x1f))))
  6148. {
  6149. switch (plci->RData[0].P[0])
  6150. {
  6151. case DTMF_UDATA_INDICATION_FAX_CALLING_TONE:
  6152. if (plci->dtmf_rec_active & DTMF_LISTEN_ACTIVE_FLAG)
  6153. sendf(plci->appl, _FACILITY_I, Id & 0xffffL, 0, "ws", SELECTOR_DTMF, "\x01X");
  6154. break;
  6155. case DTMF_UDATA_INDICATION_ANSWER_TONE:
  6156. if (plci->dtmf_rec_active & DTMF_LISTEN_ACTIVE_FLAG)
  6157. sendf(plci->appl, _FACILITY_I, Id & 0xffffL, 0, "ws", SELECTOR_DTMF, "\x01Y");
  6158. break;
  6159. case DTMF_UDATA_INDICATION_DIGITS_RECEIVED:
  6160. dtmf_indication(Id, plci, plci->RData[0].P, plci->RData[0].PLength);
  6161. break;
  6162. case DTMF_UDATA_INDICATION_DIGITS_SENT:
  6163. dtmf_confirmation(Id, plci);
  6164. break;
  6165. case UDATA_INDICATION_MIXER_TAP_DATA:
  6166. capidtmf_recv_process_block(&(plci->capidtmf_state), plci->RData[0].P + 1, (word)(plci->RData[0].PLength - 1));
  6167. i = capidtmf_indication(&(plci->capidtmf_state), dtmf_code_buffer + 1);
  6168. if (i != 0)
  6169. {
  6170. dtmf_code_buffer[0] = DTMF_UDATA_INDICATION_DIGITS_RECEIVED;
  6171. dtmf_indication(Id, plci, dtmf_code_buffer, (word)(i + 1));
  6172. }
  6173. break;
  6174. case UDATA_INDICATION_MIXER_COEFS_SET:
  6175. mixer_indication_coefs_set(Id, plci);
  6176. break;
  6177. case UDATA_INDICATION_XCONNECT_FROM:
  6178. mixer_indication_xconnect_from(Id, plci, plci->RData[0].P, plci->RData[0].PLength);
  6179. break;
  6180. case UDATA_INDICATION_XCONNECT_TO:
  6181. mixer_indication_xconnect_to(Id, plci, plci->RData[0].P, plci->RData[0].PLength);
  6182. break;
  6183. case LEC_UDATA_INDICATION_DISABLE_DETECT:
  6184. ec_indication(Id, plci, plci->RData[0].P, plci->RData[0].PLength);
  6185. break;
  6186. default:
  6187. break;
  6188. }
  6189. }
  6190. else
  6191. {
  6192. if ((plci->RData[0].PLength != 0)
  6193. && ((plci->B2_prot == B2_V120_ASYNC)
  6194. || (plci->B2_prot == B2_V120_ASYNC_V42BIS)
  6195. || (plci->B2_prot == B2_V120_BIT_TRANSPARENT)))
  6196. {
  6197. sendf(plci->appl, _DATA_B3_I, Id, 0,
  6198. "dwww",
  6199. plci->RData[1].P,
  6200. (plci->NL.RNum < 2) ? 0 : plci->RData[1].PLength,
  6201. plci->RNum,
  6202. plci->RFlags);
  6203. }
  6204. else
  6205. {
  6206. sendf(plci->appl, _DATA_B3_I, Id, 0,
  6207. "dwww",
  6208. plci->RData[0].P,
  6209. plci->RData[0].PLength,
  6210. plci->RNum,
  6211. plci->RFlags);
  6212. }
  6213. }
  6214. return;
  6215. }
  6216. fax_feature_bits = 0;
  6217. if ((plci->NL.Ind & 0x0f) == N_CONNECT ||
  6218. (plci->NL.Ind & 0x0f) == N_CONNECT_ACK ||
  6219. (plci->NL.Ind & 0x0f) == N_DISC ||
  6220. (plci->NL.Ind & 0x0f) == N_EDATA ||
  6221. (plci->NL.Ind & 0x0f) == N_DISC_ACK)
  6222. {
  6223. info = 0;
  6224. plci->ncpi_buffer[0] = 0;
  6225. switch (plci->B3_prot) {
  6226. case 0: /*XPARENT*/
  6227. case 1: /*T.90 NL*/
  6228. break; /* no network control protocol info - jfr */
  6229. case 2: /*ISO8202*/
  6230. case 3: /*X25 DCE*/
  6231. for (i = 0; i < plci->NL.RLength; i++) plci->ncpi_buffer[4 + i] = plci->NL.RBuffer->P[i];
  6232. plci->ncpi_buffer[0] = (byte)(i + 3);
  6233. plci->ncpi_buffer[1] = (byte)(plci->NL.Ind & N_D_BIT ? 1 : 0);
  6234. plci->ncpi_buffer[2] = 0;
  6235. plci->ncpi_buffer[3] = 0;
  6236. break;
  6237. case 4: /*T.30 - FAX*/
  6238. case 5: /*T.30 - FAX*/
  6239. if (plci->NL.RLength >= sizeof(T30_INFO))
  6240. {
  6241. dbug(1, dprintf("FaxStatus %04x", ((T30_INFO *)plci->NL.RBuffer->P)->code));
  6242. len = 9;
  6243. PUT_WORD(&(plci->ncpi_buffer[1]), ((T30_INFO *)plci->NL.RBuffer->P)->rate_div_2400 * 2400);
  6244. fax_feature_bits = GET_WORD(&((T30_INFO *)plci->NL.RBuffer->P)->feature_bits_low);
  6245. i = (((T30_INFO *)plci->NL.RBuffer->P)->resolution & T30_RESOLUTION_R8_0770_OR_200) ? 0x0001 : 0x0000;
  6246. if (plci->B3_prot == 5)
  6247. {
  6248. if (!(fax_feature_bits & T30_FEATURE_BIT_ECM))
  6249. i |= 0x8000; /* This is not an ECM connection */
  6250. if (fax_feature_bits & T30_FEATURE_BIT_T6_CODING)
  6251. i |= 0x4000; /* This is a connection with MMR compression */
  6252. if (fax_feature_bits & T30_FEATURE_BIT_2D_CODING)
  6253. i |= 0x2000; /* This is a connection with MR compression */
  6254. if (fax_feature_bits & T30_FEATURE_BIT_MORE_DOCUMENTS)
  6255. i |= 0x0004; /* More documents */
  6256. if (fax_feature_bits & T30_FEATURE_BIT_POLLING)
  6257. i |= 0x0002; /* Fax-polling indication */
  6258. }
  6259. dbug(1, dprintf("FAX Options %04x %04x", fax_feature_bits, i));
  6260. PUT_WORD(&(plci->ncpi_buffer[3]), i);
  6261. PUT_WORD(&(plci->ncpi_buffer[5]), ((T30_INFO *)plci->NL.RBuffer->P)->data_format);
  6262. plci->ncpi_buffer[7] = ((T30_INFO *)plci->NL.RBuffer->P)->pages_low;
  6263. plci->ncpi_buffer[8] = ((T30_INFO *)plci->NL.RBuffer->P)->pages_high;
  6264. plci->ncpi_buffer[len] = 0;
  6265. if (((T30_INFO *)plci->NL.RBuffer->P)->station_id_len)
  6266. {
  6267. plci->ncpi_buffer[len] = 20;
  6268. for (i = 0; i < T30_MAX_STATION_ID_LENGTH; i++)
  6269. plci->ncpi_buffer[++len] = ((T30_INFO *)plci->NL.RBuffer->P)->station_id[i];
  6270. }
  6271. if (((plci->NL.Ind & 0x0f) == N_DISC) || ((plci->NL.Ind & 0x0f) == N_DISC_ACK))
  6272. {
  6273. if (((T30_INFO *)plci->NL.RBuffer->P)->code < ARRAY_SIZE(fax_info))
  6274. info = fax_info[((T30_INFO *)plci->NL.RBuffer->P)->code];
  6275. else
  6276. info = _FAX_PROTOCOL_ERROR;
  6277. }
  6278. if ((plci->requested_options_conn | plci->requested_options | a->requested_options_table[plci->appl->Id - 1])
  6279. & ((1L << PRIVATE_FAX_SUB_SEP_PWD) | (1L << PRIVATE_FAX_NONSTANDARD)))
  6280. {
  6281. i = offsetof(T30_INFO, station_id) + T30_MAX_STATION_ID_LENGTH + ((T30_INFO *)plci->NL.RBuffer->P)->head_line_len;
  6282. while (i < plci->NL.RBuffer->length)
  6283. plci->ncpi_buffer[++len] = plci->NL.RBuffer->P[i++];
  6284. }
  6285. plci->ncpi_buffer[0] = len;
  6286. fax_feature_bits = GET_WORD(&((T30_INFO *)plci->NL.RBuffer->P)->feature_bits_low);
  6287. PUT_WORD(&((T30_INFO *)plci->fax_connect_info_buffer)->feature_bits_low, fax_feature_bits);
  6288. plci->ncpi_state |= NCPI_VALID_CONNECT_B3_IND;
  6289. if (((plci->NL.Ind & 0x0f) == N_CONNECT_ACK)
  6290. || (((plci->NL.Ind & 0x0f) == N_CONNECT)
  6291. && (fax_feature_bits & T30_FEATURE_BIT_POLLING))
  6292. || (((plci->NL.Ind & 0x0f) == N_EDATA)
  6293. && ((((T30_INFO *)plci->NL.RBuffer->P)->code == EDATA_T30_TRAIN_OK)
  6294. || (((T30_INFO *)plci->NL.RBuffer->P)->code == EDATA_T30_DIS)
  6295. || (((T30_INFO *)plci->NL.RBuffer->P)->code == EDATA_T30_DTC))))
  6296. {
  6297. plci->ncpi_state |= NCPI_VALID_CONNECT_B3_ACT;
  6298. }
  6299. if (((plci->NL.Ind & 0x0f) == N_DISC)
  6300. || ((plci->NL.Ind & 0x0f) == N_DISC_ACK)
  6301. || (((plci->NL.Ind & 0x0f) == N_EDATA)
  6302. && (((T30_INFO *)plci->NL.RBuffer->P)->code == EDATA_T30_EOP_CAPI)))
  6303. {
  6304. plci->ncpi_state |= NCPI_VALID_CONNECT_B3_ACT | NCPI_VALID_DISC_B3_IND;
  6305. }
  6306. }
  6307. break;
  6308. case B3_RTP:
  6309. if (((plci->NL.Ind & 0x0f) == N_DISC) || ((plci->NL.Ind & 0x0f) == N_DISC_ACK))
  6310. {
  6311. if (plci->NL.RLength != 0)
  6312. {
  6313. info = rtp_info[plci->NL.RBuffer->P[0]];
  6314. plci->ncpi_buffer[0] = plci->NL.RLength - 1;
  6315. for (i = 1; i < plci->NL.RLength; i++)
  6316. plci->ncpi_buffer[i] = plci->NL.RBuffer->P[i];
  6317. }
  6318. }
  6319. break;
  6320. }
  6321. plci->NL.RNR = 2;
  6322. }
  6323. switch (plci->NL.Ind & 0x0f) {
  6324. case N_EDATA:
  6325. if ((plci->B3_prot == 4) || (plci->B3_prot == 5))
  6326. {
  6327. dbug(1, dprintf("EDATA ncci=0x%x state=%d code=%02x", ncci, a->ncci_state[ncci],
  6328. ((T30_INFO *)plci->NL.RBuffer->P)->code));
  6329. fax_send_edata_ack = (((T30_INFO *)(plci->fax_connect_info_buffer))->operating_mode == T30_OPERATING_MODE_CAPI_NEG);
  6330. if ((plci->nsf_control_bits & T30_NSF_CONTROL_BIT_ENABLE_NSF)
  6331. && (plci->nsf_control_bits & (T30_NSF_CONTROL_BIT_NEGOTIATE_IND | T30_NSF_CONTROL_BIT_NEGOTIATE_RESP))
  6332. && (((T30_INFO *)plci->NL.RBuffer->P)->code == EDATA_T30_DIS)
  6333. && (a->ncci_state[ncci] == OUTG_CON_PENDING)
  6334. && (plci->ncpi_state & NCPI_VALID_CONNECT_B3_ACT)
  6335. && !(plci->ncpi_state & NCPI_NEGOTIATE_B3_SENT))
  6336. {
  6337. ((T30_INFO *)(plci->fax_connect_info_buffer))->code = ((T30_INFO *)plci->NL.RBuffer->P)->code;
  6338. sendf(plci->appl, _MANUFACTURER_I, Id, 0, "dwbS", _DI_MANU_ID, _DI_NEGOTIATE_B3,
  6339. (byte)(plci->ncpi_buffer[0] + 1), plci->ncpi_buffer);
  6340. plci->ncpi_state |= NCPI_NEGOTIATE_B3_SENT;
  6341. if (plci->nsf_control_bits & T30_NSF_CONTROL_BIT_NEGOTIATE_RESP)
  6342. fax_send_edata_ack = false;
  6343. }
  6344. if (a->manufacturer_features & MANUFACTURER_FEATURE_FAX_PAPER_FORMATS)
  6345. {
  6346. switch (((T30_INFO *)plci->NL.RBuffer->P)->code)
  6347. {
  6348. case EDATA_T30_DIS:
  6349. if ((a->ncci_state[ncci] == OUTG_CON_PENDING)
  6350. && !(GET_WORD(&((T30_INFO *)plci->fax_connect_info_buffer)->control_bits_low) & T30_CONTROL_BIT_REQUEST_POLLING)
  6351. && (plci->ncpi_state & NCPI_VALID_CONNECT_B3_ACT)
  6352. && !(plci->ncpi_state & NCPI_CONNECT_B3_ACT_SENT))
  6353. {
  6354. a->ncci_state[ncci] = INC_ACT_PENDING;
  6355. if (plci->B3_prot == 4)
  6356. sendf(plci->appl, _CONNECT_B3_ACTIVE_I, Id, 0, "s", "");
  6357. else
  6358. sendf(plci->appl, _CONNECT_B3_ACTIVE_I, Id, 0, "S", plci->ncpi_buffer);
  6359. plci->ncpi_state |= NCPI_CONNECT_B3_ACT_SENT;
  6360. }
  6361. break;
  6362. case EDATA_T30_TRAIN_OK:
  6363. if ((a->ncci_state[ncci] == INC_ACT_PENDING)
  6364. && (plci->ncpi_state & NCPI_VALID_CONNECT_B3_ACT)
  6365. && !(plci->ncpi_state & NCPI_CONNECT_B3_ACT_SENT))
  6366. {
  6367. if (plci->B3_prot == 4)
  6368. sendf(plci->appl, _CONNECT_B3_ACTIVE_I, Id, 0, "s", "");
  6369. else
  6370. sendf(plci->appl, _CONNECT_B3_ACTIVE_I, Id, 0, "S", plci->ncpi_buffer);
  6371. plci->ncpi_state |= NCPI_CONNECT_B3_ACT_SENT;
  6372. }
  6373. break;
  6374. case EDATA_T30_EOP_CAPI:
  6375. if (a->ncci_state[ncci] == CONNECTED)
  6376. {
  6377. sendf(plci->appl, _DISCONNECT_B3_I, Id, 0, "wS", GOOD, plci->ncpi_buffer);
  6378. a->ncci_state[ncci] = INC_DIS_PENDING;
  6379. plci->ncpi_state = 0;
  6380. fax_send_edata_ack = false;
  6381. }
  6382. break;
  6383. }
  6384. }
  6385. else
  6386. {
  6387. switch (((T30_INFO *)plci->NL.RBuffer->P)->code)
  6388. {
  6389. case EDATA_T30_TRAIN_OK:
  6390. if ((a->ncci_state[ncci] == INC_ACT_PENDING)
  6391. && (plci->ncpi_state & NCPI_VALID_CONNECT_B3_ACT)
  6392. && !(plci->ncpi_state & NCPI_CONNECT_B3_ACT_SENT))
  6393. {
  6394. if (plci->B3_prot == 4)
  6395. sendf(plci->appl, _CONNECT_B3_ACTIVE_I, Id, 0, "s", "");
  6396. else
  6397. sendf(plci->appl, _CONNECT_B3_ACTIVE_I, Id, 0, "S", plci->ncpi_buffer);
  6398. plci->ncpi_state |= NCPI_CONNECT_B3_ACT_SENT;
  6399. }
  6400. break;
  6401. }
  6402. }
  6403. if (fax_send_edata_ack)
  6404. {
  6405. ((T30_INFO *)(plci->fax_connect_info_buffer))->code = ((T30_INFO *)plci->NL.RBuffer->P)->code;
  6406. plci->fax_edata_ack_length = 1;
  6407. start_internal_command(Id, plci, fax_edata_ack_command);
  6408. }
  6409. }
  6410. else
  6411. {
  6412. dbug(1, dprintf("EDATA ncci=0x%x state=%d", ncci, a->ncci_state[ncci]));
  6413. }
  6414. break;
  6415. case N_CONNECT:
  6416. if (!a->ch_ncci[ch])
  6417. {
  6418. ncci = get_ncci(plci, ch, 0);
  6419. Id = (Id & 0xffff) | (((dword) ncci) << 16);
  6420. }
  6421. dbug(1, dprintf("N_CONNECT: ch=%d state=%d plci=%lx plci_Id=%lx plci_State=%d",
  6422. ch, a->ncci_state[ncci], a->ncci_plci[ncci], plci->Id, plci->State));
  6423. msg = _CONNECT_B3_I;
  6424. if (a->ncci_state[ncci] == IDLE)
  6425. plci->channels++;
  6426. else if (plci->B3_prot == 1)
  6427. msg = _CONNECT_B3_T90_ACTIVE_I;
  6428. a->ncci_state[ncci] = INC_CON_PENDING;
  6429. if (plci->B3_prot == 4)
  6430. sendf(plci->appl, msg, Id, 0, "s", "");
  6431. else
  6432. sendf(plci->appl, msg, Id, 0, "S", plci->ncpi_buffer);
  6433. break;
  6434. case N_CONNECT_ACK:
  6435. dbug(1, dprintf("N_connect_Ack"));
  6436. if (plci->internal_command_queue[0]
  6437. && ((plci->adjust_b_state == ADJUST_B_CONNECT_2)
  6438. || (plci->adjust_b_state == ADJUST_B_CONNECT_3)
  6439. || (plci->adjust_b_state == ADJUST_B_CONNECT_4)))
  6440. {
  6441. (*(plci->internal_command_queue[0]))(Id, plci, 0);
  6442. if (!plci->internal_command)
  6443. next_internal_command(Id, plci);
  6444. break;
  6445. }
  6446. msg = _CONNECT_B3_ACTIVE_I;
  6447. if (plci->B3_prot == 1)
  6448. {
  6449. if (a->ncci_state[ncci] != OUTG_CON_PENDING)
  6450. msg = _CONNECT_B3_T90_ACTIVE_I;
  6451. a->ncci_state[ncci] = INC_ACT_PENDING;
  6452. sendf(plci->appl, msg, Id, 0, "S", plci->ncpi_buffer);
  6453. }
  6454. else if ((plci->B3_prot == 4) || (plci->B3_prot == 5) || (plci->B3_prot == 7))
  6455. {
  6456. if ((a->ncci_state[ncci] == OUTG_CON_PENDING)
  6457. && (plci->ncpi_state & NCPI_VALID_CONNECT_B3_ACT)
  6458. && !(plci->ncpi_state & NCPI_CONNECT_B3_ACT_SENT))
  6459. {
  6460. a->ncci_state[ncci] = INC_ACT_PENDING;
  6461. if (plci->B3_prot == 4)
  6462. sendf(plci->appl, msg, Id, 0, "s", "");
  6463. else
  6464. sendf(plci->appl, msg, Id, 0, "S", plci->ncpi_buffer);
  6465. plci->ncpi_state |= NCPI_CONNECT_B3_ACT_SENT;
  6466. }
  6467. }
  6468. else
  6469. {
  6470. a->ncci_state[ncci] = INC_ACT_PENDING;
  6471. sendf(plci->appl, msg, Id, 0, "S", plci->ncpi_buffer);
  6472. }
  6473. if (plci->adjust_b_restore)
  6474. {
  6475. plci->adjust_b_restore = false;
  6476. start_internal_command(Id, plci, adjust_b_restore);
  6477. }
  6478. break;
  6479. case N_DISC:
  6480. case N_DISC_ACK:
  6481. if (plci->internal_command_queue[0]
  6482. && ((plci->internal_command == FAX_DISCONNECT_COMMAND_1)
  6483. || (plci->internal_command == FAX_DISCONNECT_COMMAND_2)
  6484. || (plci->internal_command == FAX_DISCONNECT_COMMAND_3)))
  6485. {
  6486. (*(plci->internal_command_queue[0]))(Id, plci, 0);
  6487. if (!plci->internal_command)
  6488. next_internal_command(Id, plci);
  6489. }
  6490. ncci_state = a->ncci_state[ncci];
  6491. ncci_remove(plci, ncci, false);
  6492. /* with N_DISC or N_DISC_ACK the IDI frees the respective */
  6493. /* channel, so we cannot store the state in ncci_state! The */
  6494. /* information which channel we received a N_DISC is thus */
  6495. /* stored in the inc_dis_ncci_table buffer. */
  6496. for (i = 0; plci->inc_dis_ncci_table[i]; i++);
  6497. plci->inc_dis_ncci_table[i] = (byte) ncci;
  6498. /* need a connect_b3_ind before a disconnect_b3_ind with FAX */
  6499. if (!plci->channels
  6500. && (plci->B1_resource == 16)
  6501. && (plci->State <= CONNECTED))
  6502. {
  6503. len = 9;
  6504. i = ((T30_INFO *)plci->fax_connect_info_buffer)->rate_div_2400 * 2400;
  6505. PUT_WORD(&plci->ncpi_buffer[1], i);
  6506. PUT_WORD(&plci->ncpi_buffer[3], 0);
  6507. i = ((T30_INFO *)plci->fax_connect_info_buffer)->data_format;
  6508. PUT_WORD(&plci->ncpi_buffer[5], i);
  6509. PUT_WORD(&plci->ncpi_buffer[7], 0);
  6510. plci->ncpi_buffer[len] = 0;
  6511. plci->ncpi_buffer[0] = len;
  6512. if (plci->B3_prot == 4)
  6513. sendf(plci->appl, _CONNECT_B3_I, Id, 0, "s", "");
  6514. else
  6515. {
  6516. if ((plci->requested_options_conn | plci->requested_options | a->requested_options_table[plci->appl->Id - 1])
  6517. & ((1L << PRIVATE_FAX_SUB_SEP_PWD) | (1L << PRIVATE_FAX_NONSTANDARD)))
  6518. {
  6519. plci->ncpi_buffer[++len] = 0;
  6520. plci->ncpi_buffer[++len] = 0;
  6521. plci->ncpi_buffer[++len] = 0;
  6522. plci->ncpi_buffer[0] = len;
  6523. }
  6524. sendf(plci->appl, _CONNECT_B3_I, Id, 0, "S", plci->ncpi_buffer);
  6525. }
  6526. sendf(plci->appl, _DISCONNECT_B3_I, Id, 0, "wS", info, plci->ncpi_buffer);
  6527. plci->ncpi_state = 0;
  6528. sig_req(plci, HANGUP, 0);
  6529. send_req(plci);
  6530. plci->State = OUTG_DIS_PENDING;
  6531. /* disc here */
  6532. }
  6533. else if ((a->manufacturer_features & MANUFACTURER_FEATURE_FAX_PAPER_FORMATS)
  6534. && ((plci->B3_prot == 4) || (plci->B3_prot == 5))
  6535. && ((ncci_state == INC_DIS_PENDING) || (ncci_state == IDLE)))
  6536. {
  6537. if (ncci_state == IDLE)
  6538. {
  6539. if (plci->channels)
  6540. plci->channels--;
  6541. if ((plci->State == IDLE || plci->State == SUSPENDING) && !plci->channels) {
  6542. if (plci->State == SUSPENDING) {
  6543. sendf(plci->appl,
  6544. _FACILITY_I,
  6545. Id & 0xffffL,
  6546. 0,
  6547. "ws", (word)3, "\x03\x04\x00\x00");
  6548. sendf(plci->appl, _DISCONNECT_I, Id & 0xffffL, 0, "w", 0);
  6549. }
  6550. plci_remove(plci);
  6551. plci->State = IDLE;
  6552. }
  6553. }
  6554. }
  6555. else if (plci->channels)
  6556. {
  6557. sendf(plci->appl, _DISCONNECT_B3_I, Id, 0, "wS", info, plci->ncpi_buffer);
  6558. plci->ncpi_state = 0;
  6559. if ((ncci_state == OUTG_REJ_PENDING)
  6560. && ((plci->B3_prot != B3_T90NL) && (plci->B3_prot != B3_ISO8208) && (plci->B3_prot != B3_X25_DCE)))
  6561. {
  6562. sig_req(plci, HANGUP, 0);
  6563. send_req(plci);
  6564. plci->State = OUTG_DIS_PENDING;
  6565. }
  6566. }
  6567. break;
  6568. case N_RESET:
  6569. a->ncci_state[ncci] = INC_RES_PENDING;
  6570. sendf(plci->appl, _RESET_B3_I, Id, 0, "S", plci->ncpi_buffer);
  6571. break;
  6572. case N_RESET_ACK:
  6573. a->ncci_state[ncci] = CONNECTED;
  6574. sendf(plci->appl, _RESET_B3_I, Id, 0, "S", plci->ncpi_buffer);
  6575. break;
  6576. case N_UDATA:
  6577. if (!(udata_forwarding_table[plci->NL.RBuffer->P[0] >> 5] & (1L << (plci->NL.RBuffer->P[0] & 0x1f))))
  6578. {
  6579. plci->RData[0].P = plci->internal_ind_buffer + (-((int)(long)(plci->internal_ind_buffer)) & 3);
  6580. plci->RData[0].PLength = INTERNAL_IND_BUFFER_SIZE;
  6581. plci->NL.R = plci->RData;
  6582. plci->NL.RNum = 1;
  6583. return;
  6584. }
  6585. case N_BDATA:
  6586. case N_DATA:
  6587. if (((a->ncci_state[ncci] != CONNECTED) && (plci->B2_prot == 1)) /* transparent */
  6588. || (a->ncci_state[ncci] == IDLE)
  6589. || (a->ncci_state[ncci] == INC_DIS_PENDING))
  6590. {
  6591. plci->NL.RNR = 2;
  6592. break;
  6593. }
  6594. if ((a->ncci_state[ncci] != CONNECTED)
  6595. && (a->ncci_state[ncci] != OUTG_DIS_PENDING)
  6596. && (a->ncci_state[ncci] != OUTG_REJ_PENDING))
  6597. {
  6598. dbug(1, dprintf("flow control"));
  6599. plci->NL.RNR = 1; /* flow control */
  6600. channel_x_off(plci, ch, 0);
  6601. break;
  6602. }
  6603. NCCIcode = ncci | (((word)a->Id) << 8);
  6604. /* count all buffers within the Application pool */
  6605. /* belonging to the same NCCI. If this is below the */
  6606. /* number of buffers available per NCCI we accept */
  6607. /* this packet, otherwise we reject it */
  6608. count = 0;
  6609. Num = 0xffff;
  6610. for (i = 0; i < APPLptr->MaxBuffer; i++) {
  6611. if (NCCIcode == APPLptr->DataNCCI[i]) count++;
  6612. if (!APPLptr->DataNCCI[i] && Num == 0xffff) Num = i;
  6613. }
  6614. if (count >= APPLptr->MaxNCCIData || Num == 0xffff)
  6615. {
  6616. dbug(3, dprintf("Flow-Control"));
  6617. plci->NL.RNR = 1;
  6618. if (++(APPLptr->NCCIDataFlowCtrlTimer) >=
  6619. (word)((a->manufacturer_features & MANUFACTURER_FEATURE_OOB_CHANNEL) ? 40 : 2000))
  6620. {
  6621. plci->NL.RNR = 2;
  6622. dbug(3, dprintf("DiscardData"));
  6623. } else {
  6624. channel_x_off(plci, ch, 0);
  6625. }
  6626. break;
  6627. }
  6628. else
  6629. {
  6630. APPLptr->NCCIDataFlowCtrlTimer = 0;
  6631. }
  6632. plci->RData[0].P = ReceiveBufferGet(APPLptr, Num);
  6633. if (!plci->RData[0].P) {
  6634. plci->NL.RNR = 1;
  6635. channel_x_off(plci, ch, 0);
  6636. break;
  6637. }
  6638. APPLptr->DataNCCI[Num] = NCCIcode;
  6639. APPLptr->DataFlags[Num] = (plci->Id << 8) | (plci->NL.Ind >> 4);
  6640. dbug(3, dprintf("Buffer(%d), Max = %d", Num, APPLptr->MaxBuffer));
  6641. plci->RNum = Num;
  6642. plci->RFlags = plci->NL.Ind >> 4;
  6643. plci->RData[0].PLength = APPLptr->MaxDataLength;
  6644. plci->NL.R = plci->RData;
  6645. if ((plci->NL.RLength != 0)
  6646. && ((plci->B2_prot == B2_V120_ASYNC)
  6647. || (plci->B2_prot == B2_V120_ASYNC_V42BIS)
  6648. || (plci->B2_prot == B2_V120_BIT_TRANSPARENT)))
  6649. {
  6650. plci->RData[1].P = plci->RData[0].P;
  6651. plci->RData[1].PLength = plci->RData[0].PLength;
  6652. plci->RData[0].P = v120_header_buffer + (-((unsigned long)v120_header_buffer) & 3);
  6653. if ((plci->NL.RBuffer->P[0] & V120_HEADER_EXTEND_BIT) || (plci->NL.RLength == 1))
  6654. plci->RData[0].PLength = 1;
  6655. else
  6656. plci->RData[0].PLength = 2;
  6657. if (plci->NL.RBuffer->P[0] & V120_HEADER_BREAK_BIT)
  6658. plci->RFlags |= 0x0010;
  6659. if (plci->NL.RBuffer->P[0] & (V120_HEADER_C1_BIT | V120_HEADER_C2_BIT))
  6660. plci->RFlags |= 0x8000;
  6661. plci->NL.RNum = 2;
  6662. }
  6663. else
  6664. {
  6665. if ((plci->NL.Ind & 0x0f) == N_UDATA)
  6666. plci->RFlags |= 0x0010;
  6667. else if ((plci->B3_prot == B3_RTP) && ((plci->NL.Ind & 0x0f) == N_BDATA))
  6668. plci->RFlags |= 0x0001;
  6669. plci->NL.RNum = 1;
  6670. }
  6671. break;
  6672. case N_DATA_ACK:
  6673. data_ack(plci, ch);
  6674. break;
  6675. default:
  6676. plci->NL.RNR = 2;
  6677. break;
  6678. }
  6679. }
  6680. /*------------------------------------------------------------------*/
  6681. /* find a free PLCI */
  6682. /*------------------------------------------------------------------*/
  6683. static word get_plci(DIVA_CAPI_ADAPTER *a)
  6684. {
  6685. word i, j;
  6686. PLCI *plci;
  6687. dump_plcis(a);
  6688. for (i = 0; i < a->max_plci && a->plci[i].Id; i++);
  6689. if (i == a->max_plci) {
  6690. dbug(1, dprintf("get_plci: out of PLCIs"));
  6691. return 0;
  6692. }
  6693. plci = &a->plci[i];
  6694. plci->Id = (byte)(i + 1);
  6695. plci->Sig.Id = 0;
  6696. plci->NL.Id = 0;
  6697. plci->sig_req = 0;
  6698. plci->nl_req = 0;
  6699. plci->appl = NULL;
  6700. plci->relatedPTYPLCI = NULL;
  6701. plci->State = IDLE;
  6702. plci->SuppState = IDLE;
  6703. plci->channels = 0;
  6704. plci->tel = 0;
  6705. plci->B1_resource = 0;
  6706. plci->B2_prot = 0;
  6707. plci->B3_prot = 0;
  6708. plci->command = 0;
  6709. plci->m_command = 0;
  6710. init_internal_command_queue(plci);
  6711. plci->number = 0;
  6712. plci->req_in_start = 0;
  6713. plci->req_in = 0;
  6714. plci->req_out = 0;
  6715. plci->msg_in_write_pos = MSG_IN_QUEUE_SIZE;
  6716. plci->msg_in_read_pos = MSG_IN_QUEUE_SIZE;
  6717. plci->msg_in_wrap_pos = MSG_IN_QUEUE_SIZE;
  6718. plci->data_sent = false;
  6719. plci->send_disc = 0;
  6720. plci->sig_global_req = 0;
  6721. plci->sig_remove_id = 0;
  6722. plci->nl_global_req = 0;
  6723. plci->nl_remove_id = 0;
  6724. plci->adv_nl = 0;
  6725. plci->manufacturer = false;
  6726. plci->call_dir = CALL_DIR_OUT | CALL_DIR_ORIGINATE;
  6727. plci->spoofed_msg = 0;
  6728. plci->ptyState = 0;
  6729. plci->cr_enquiry = false;
  6730. plci->hangup_flow_ctrl_timer = 0;
  6731. plci->ncci_ring_list = 0;
  6732. for (j = 0; j < MAX_CHANNELS_PER_PLCI; j++) plci->inc_dis_ncci_table[j] = 0;
  6733. clear_c_ind_mask(plci);
  6734. set_group_ind_mask(plci);
  6735. plci->fax_connect_info_length = 0;
  6736. plci->nsf_control_bits = 0;
  6737. plci->ncpi_state = 0x00;
  6738. plci->ncpi_buffer[0] = 0;
  6739. plci->requested_options_conn = 0;
  6740. plci->requested_options = 0;
  6741. plci->notifiedcall = 0;
  6742. plci->vswitchstate = 0;
  6743. plci->vsprot = 0;
  6744. plci->vsprotdialect = 0;
  6745. init_b1_config(plci);
  6746. dbug(1, dprintf("get_plci(%x)", plci->Id));
  6747. return i + 1;
  6748. }
  6749. /*------------------------------------------------------------------*/
  6750. /* put a parameter in the parameter buffer */
  6751. /*------------------------------------------------------------------*/
  6752. static void add_p(PLCI *plci, byte code, byte *p)
  6753. {
  6754. word p_length;
  6755. p_length = 0;
  6756. if (p) p_length = p[0];
  6757. add_ie(plci, code, p, p_length);
  6758. }
  6759. /*------------------------------------------------------------------*/
  6760. /* put a structure in the parameter buffer */
  6761. /*------------------------------------------------------------------*/
  6762. static void add_s(PLCI *plci, byte code, API_PARSE *p)
  6763. {
  6764. if (p) add_ie(plci, code, p->info, (word)p->length);
  6765. }
  6766. /*------------------------------------------------------------------*/
  6767. /* put multiple structures in the parameter buffer */
  6768. /*------------------------------------------------------------------*/
  6769. static void add_ss(PLCI *plci, byte code, API_PARSE *p)
  6770. {
  6771. byte i;
  6772. if (p) {
  6773. dbug(1, dprintf("add_ss(%x,len=%d)", code, p->length));
  6774. for (i = 2; i < (byte)p->length; i += p->info[i] + 2) {
  6775. dbug(1, dprintf("add_ss_ie(%x,len=%d)", p->info[i - 1], p->info[i]));
  6776. add_ie(plci, p->info[i - 1], (byte *)&(p->info[i]), (word)p->info[i]);
  6777. }
  6778. }
  6779. }
  6780. /*------------------------------------------------------------------*/
  6781. /* return the channel number sent by the application in a esc_chi */
  6782. /*------------------------------------------------------------------*/
  6783. static byte getChannel(API_PARSE *p)
  6784. {
  6785. byte i;
  6786. if (p) {
  6787. for (i = 2; i < (byte)p->length; i += p->info[i] + 2) {
  6788. if (p->info[i] == 2) {
  6789. if (p->info[i - 1] == ESC && p->info[i + 1] == CHI) return (p->info[i + 2]);
  6790. }
  6791. }
  6792. }
  6793. return 0;
  6794. }
  6795. /*------------------------------------------------------------------*/
  6796. /* put an information element in the parameter buffer */
  6797. /*------------------------------------------------------------------*/
  6798. static void add_ie(PLCI *plci, byte code, byte *p, word p_length)
  6799. {
  6800. word i;
  6801. if (!(code & 0x80) && !p_length) return;
  6802. if (plci->req_in == plci->req_in_start) {
  6803. plci->req_in += 2;
  6804. }
  6805. else {
  6806. plci->req_in--;
  6807. }
  6808. plci->RBuffer[plci->req_in++] = code;
  6809. if (p) {
  6810. plci->RBuffer[plci->req_in++] = (byte)p_length;
  6811. for (i = 0; i < p_length; i++) plci->RBuffer[plci->req_in++] = p[1 + i];
  6812. }
  6813. plci->RBuffer[plci->req_in++] = 0;
  6814. }
  6815. /*------------------------------------------------------------------*/
  6816. /* put a unstructured data into the buffer */
  6817. /*------------------------------------------------------------------*/
  6818. static void add_d(PLCI *plci, word length, byte *p)
  6819. {
  6820. word i;
  6821. if (plci->req_in == plci->req_in_start) {
  6822. plci->req_in += 2;
  6823. }
  6824. else {
  6825. plci->req_in--;
  6826. }
  6827. for (i = 0; i < length; i++) plci->RBuffer[plci->req_in++] = p[i];
  6828. }
  6829. /*------------------------------------------------------------------*/
  6830. /* put parameters from the Additional Info parameter in the */
  6831. /* parameter buffer */
  6832. /*------------------------------------------------------------------*/
  6833. static void add_ai(PLCI *plci, API_PARSE *ai)
  6834. {
  6835. word i;
  6836. API_PARSE ai_parms[5];
  6837. for (i = 0; i < 5; i++) ai_parms[i].length = 0;
  6838. if (!ai->length)
  6839. return;
  6840. if (api_parse(&ai->info[1], (word)ai->length, "ssss", ai_parms))
  6841. return;
  6842. add_s(plci, KEY, &ai_parms[1]);
  6843. add_s(plci, UUI, &ai_parms[2]);
  6844. add_ss(plci, FTY, &ai_parms[3]);
  6845. }
  6846. /*------------------------------------------------------------------*/
  6847. /* put parameter for b1 protocol in the parameter buffer */
  6848. /*------------------------------------------------------------------*/
  6849. static word add_b1(PLCI *plci, API_PARSE *bp, word b_channel_info,
  6850. word b1_facilities)
  6851. {
  6852. API_PARSE bp_parms[8];
  6853. API_PARSE mdm_cfg[9];
  6854. API_PARSE global_config[2];
  6855. byte cai[256];
  6856. byte resource[] = {5, 9, 13, 12, 16, 39, 9, 17, 17, 18};
  6857. byte voice_cai[] = "\x06\x14\x00\x00\x00\x00\x08";
  6858. word i;
  6859. API_PARSE mdm_cfg_v18[4];
  6860. word j, n, w;
  6861. dword d;
  6862. for (i = 0; i < 8; i++) bp_parms[i].length = 0;
  6863. for (i = 0; i < 2; i++) global_config[i].length = 0;
  6864. dbug(1, dprintf("add_b1"));
  6865. api_save_msg(bp, "s", &plci->B_protocol);
  6866. if (b_channel_info == 2) {
  6867. plci->B1_resource = 0;
  6868. adjust_b1_facilities(plci, plci->B1_resource, b1_facilities);
  6869. add_p(plci, CAI, "\x01\x00");
  6870. dbug(1, dprintf("Cai=1,0 (no resource)"));
  6871. return 0;
  6872. }
  6873. if (plci->tel == CODEC_PERMANENT) return 0;
  6874. else if (plci->tel == CODEC) {
  6875. plci->B1_resource = 1;
  6876. adjust_b1_facilities(plci, plci->B1_resource, b1_facilities);
  6877. add_p(plci, CAI, "\x01\x01");
  6878. dbug(1, dprintf("Cai=1,1 (Codec)"));
  6879. return 0;
  6880. }
  6881. else if (plci->tel == ADV_VOICE) {
  6882. plci->B1_resource = add_b1_facilities(plci, 9, (word)(b1_facilities | B1_FACILITY_VOICE));
  6883. adjust_b1_facilities(plci, plci->B1_resource, (word)(b1_facilities | B1_FACILITY_VOICE));
  6884. voice_cai[1] = plci->B1_resource;
  6885. PUT_WORD(&voice_cai[5], plci->appl->MaxDataLength);
  6886. add_p(plci, CAI, voice_cai);
  6887. dbug(1, dprintf("Cai=1,0x%x (AdvVoice)", voice_cai[1]));
  6888. return 0;
  6889. }
  6890. plci->call_dir &= ~(CALL_DIR_ORIGINATE | CALL_DIR_ANSWER);
  6891. if (plci->call_dir & CALL_DIR_OUT)
  6892. plci->call_dir |= CALL_DIR_ORIGINATE;
  6893. else if (plci->call_dir & CALL_DIR_IN)
  6894. plci->call_dir |= CALL_DIR_ANSWER;
  6895. if (!bp->length) {
  6896. plci->B1_resource = 0x5;
  6897. adjust_b1_facilities(plci, plci->B1_resource, b1_facilities);
  6898. add_p(plci, CAI, "\x01\x05");
  6899. return 0;
  6900. }
  6901. dbug(1, dprintf("b_prot_len=%d", (word)bp->length));
  6902. if (bp->length > 256) return _WRONG_MESSAGE_FORMAT;
  6903. if (api_parse(&bp->info[1], (word)bp->length, "wwwsssb", bp_parms))
  6904. {
  6905. bp_parms[6].length = 0;
  6906. if (api_parse(&bp->info[1], (word)bp->length, "wwwsss", bp_parms))
  6907. {
  6908. dbug(1, dprintf("b-form.!"));
  6909. return _WRONG_MESSAGE_FORMAT;
  6910. }
  6911. }
  6912. else if (api_parse(&bp->info[1], (word)bp->length, "wwwssss", bp_parms))
  6913. {
  6914. dbug(1, dprintf("b-form.!"));
  6915. return _WRONG_MESSAGE_FORMAT;
  6916. }
  6917. if (bp_parms[6].length)
  6918. {
  6919. if (api_parse(&bp_parms[6].info[1], (word)bp_parms[6].length, "w", global_config))
  6920. {
  6921. return _WRONG_MESSAGE_FORMAT;
  6922. }
  6923. switch (GET_WORD(global_config[0].info))
  6924. {
  6925. case 1:
  6926. plci->call_dir = (plci->call_dir & ~CALL_DIR_ANSWER) | CALL_DIR_ORIGINATE;
  6927. break;
  6928. case 2:
  6929. plci->call_dir = (plci->call_dir & ~CALL_DIR_ORIGINATE) | CALL_DIR_ANSWER;
  6930. break;
  6931. }
  6932. }
  6933. dbug(1, dprintf("call_dir=%04x", plci->call_dir));
  6934. if ((GET_WORD(bp_parms[0].info) == B1_RTP)
  6935. && (plci->adapter->man_profile.private_options & (1L << PRIVATE_RTP)))
  6936. {
  6937. plci->B1_resource = add_b1_facilities(plci, 31, (word)(b1_facilities & ~B1_FACILITY_VOICE));
  6938. adjust_b1_facilities(plci, plci->B1_resource, (word)(b1_facilities & ~B1_FACILITY_VOICE));
  6939. cai[1] = plci->B1_resource;
  6940. cai[2] = 0;
  6941. cai[3] = 0;
  6942. cai[4] = 0;
  6943. PUT_WORD(&cai[5], plci->appl->MaxDataLength);
  6944. for (i = 0; i < bp_parms[3].length; i++)
  6945. cai[7 + i] = bp_parms[3].info[1 + i];
  6946. cai[0] = 6 + bp_parms[3].length;
  6947. add_p(plci, CAI, cai);
  6948. return 0;
  6949. }
  6950. if ((GET_WORD(bp_parms[0].info) == B1_PIAFS)
  6951. && (plci->adapter->man_profile.private_options & (1L << PRIVATE_PIAFS)))
  6952. {
  6953. plci->B1_resource = add_b1_facilities(plci, 35/* PIAFS HARDWARE FACILITY */, (word)(b1_facilities & ~B1_FACILITY_VOICE));
  6954. adjust_b1_facilities(plci, plci->B1_resource, (word)(b1_facilities & ~B1_FACILITY_VOICE));
  6955. cai[1] = plci->B1_resource;
  6956. cai[2] = 0;
  6957. cai[3] = 0;
  6958. cai[4] = 0;
  6959. PUT_WORD(&cai[5], plci->appl->MaxDataLength);
  6960. cai[0] = 6;
  6961. add_p(plci, CAI, cai);
  6962. return 0;
  6963. }
  6964. if ((GET_WORD(bp_parms[0].info) >= 32)
  6965. || (!((1L << GET_WORD(bp_parms[0].info)) & plci->adapter->profile.B1_Protocols)
  6966. && ((GET_WORD(bp_parms[0].info) != 3)
  6967. || !((1L << B1_HDLC) & plci->adapter->profile.B1_Protocols)
  6968. || ((bp_parms[3].length != 0) && (GET_WORD(&bp_parms[3].info[1]) != 0) && (GET_WORD(&bp_parms[3].info[1]) != 56000)))))
  6969. {
  6970. return _B1_NOT_SUPPORTED;
  6971. }
  6972. plci->B1_resource = add_b1_facilities(plci, resource[GET_WORD(bp_parms[0].info)],
  6973. (word)(b1_facilities & ~B1_FACILITY_VOICE));
  6974. adjust_b1_facilities(plci, plci->B1_resource, (word)(b1_facilities & ~B1_FACILITY_VOICE));
  6975. cai[0] = 6;
  6976. cai[1] = plci->B1_resource;
  6977. for (i = 2; i < sizeof(cai); i++) cai[i] = 0;
  6978. if ((GET_WORD(bp_parms[0].info) == B1_MODEM_ALL_NEGOTIATE)
  6979. || (GET_WORD(bp_parms[0].info) == B1_MODEM_ASYNC)
  6980. || (GET_WORD(bp_parms[0].info) == B1_MODEM_SYNC_HDLC))
  6981. { /* B1 - modem */
  6982. for (i = 0; i < 7; i++) mdm_cfg[i].length = 0;
  6983. if (bp_parms[3].length)
  6984. {
  6985. if (api_parse(&bp_parms[3].info[1], (word)bp_parms[3].length, "wwwwww", mdm_cfg))
  6986. {
  6987. return (_WRONG_MESSAGE_FORMAT);
  6988. }
  6989. cai[2] = 0; /* Bit rate for adaptation */
  6990. dbug(1, dprintf("MDM Max Bit Rate:<%d>", GET_WORD(mdm_cfg[0].info)));
  6991. PUT_WORD(&cai[13], 0); /* Min Tx speed */
  6992. PUT_WORD(&cai[15], GET_WORD(mdm_cfg[0].info)); /* Max Tx speed */
  6993. PUT_WORD(&cai[17], 0); /* Min Rx speed */
  6994. PUT_WORD(&cai[19], GET_WORD(mdm_cfg[0].info)); /* Max Rx speed */
  6995. cai[3] = 0; /* Async framing parameters */
  6996. switch (GET_WORD(mdm_cfg[2].info))
  6997. { /* Parity */
  6998. case 1: /* odd parity */
  6999. cai[3] |= (DSP_CAI_ASYNC_PARITY_ENABLE | DSP_CAI_ASYNC_PARITY_ODD);
  7000. dbug(1, dprintf("MDM: odd parity"));
  7001. break;
  7002. case 2: /* even parity */
  7003. cai[3] |= (DSP_CAI_ASYNC_PARITY_ENABLE | DSP_CAI_ASYNC_PARITY_EVEN);
  7004. dbug(1, dprintf("MDM: even parity"));
  7005. break;
  7006. default:
  7007. dbug(1, dprintf("MDM: no parity"));
  7008. break;
  7009. }
  7010. switch (GET_WORD(mdm_cfg[3].info))
  7011. { /* stop bits */
  7012. case 1: /* 2 stop bits */
  7013. cai[3] |= DSP_CAI_ASYNC_TWO_STOP_BITS;
  7014. dbug(1, dprintf("MDM: 2 stop bits"));
  7015. break;
  7016. default:
  7017. dbug(1, dprintf("MDM: 1 stop bit"));
  7018. break;
  7019. }
  7020. switch (GET_WORD(mdm_cfg[1].info))
  7021. { /* char length */
  7022. case 5:
  7023. cai[3] |= DSP_CAI_ASYNC_CHAR_LENGTH_5;
  7024. dbug(1, dprintf("MDM: 5 bits"));
  7025. break;
  7026. case 6:
  7027. cai[3] |= DSP_CAI_ASYNC_CHAR_LENGTH_6;
  7028. dbug(1, dprintf("MDM: 6 bits"));
  7029. break;
  7030. case 7:
  7031. cai[3] |= DSP_CAI_ASYNC_CHAR_LENGTH_7;
  7032. dbug(1, dprintf("MDM: 7 bits"));
  7033. break;
  7034. default:
  7035. dbug(1, dprintf("MDM: 8 bits"));
  7036. break;
  7037. }
  7038. cai[7] = 0; /* Line taking options */
  7039. cai[8] = 0; /* Modulation negotiation options */
  7040. cai[9] = 0; /* Modulation options */
  7041. if (((plci->call_dir & CALL_DIR_ORIGINATE) != 0) ^ ((plci->call_dir & CALL_DIR_OUT) != 0))
  7042. {
  7043. cai[9] |= DSP_CAI_MODEM_REVERSE_DIRECTION;
  7044. dbug(1, dprintf("MDM: Reverse direction"));
  7045. }
  7046. if (GET_WORD(mdm_cfg[4].info) & MDM_CAPI_DISABLE_RETRAIN)
  7047. {
  7048. cai[9] |= DSP_CAI_MODEM_DISABLE_RETRAIN;
  7049. dbug(1, dprintf("MDM: Disable retrain"));
  7050. }
  7051. if (GET_WORD(mdm_cfg[4].info) & MDM_CAPI_DISABLE_RING_TONE)
  7052. {
  7053. cai[7] |= DSP_CAI_MODEM_DISABLE_CALLING_TONE | DSP_CAI_MODEM_DISABLE_ANSWER_TONE;
  7054. dbug(1, dprintf("MDM: Disable ring tone"));
  7055. }
  7056. if (GET_WORD(mdm_cfg[4].info) & MDM_CAPI_GUARD_1800)
  7057. {
  7058. cai[8] |= DSP_CAI_MODEM_GUARD_TONE_1800HZ;
  7059. dbug(1, dprintf("MDM: 1800 guard tone"));
  7060. }
  7061. else if (GET_WORD(mdm_cfg[4].info) & MDM_CAPI_GUARD_550)
  7062. {
  7063. cai[8] |= DSP_CAI_MODEM_GUARD_TONE_550HZ;
  7064. dbug(1, dprintf("MDM: 550 guard tone"));
  7065. }
  7066. if ((GET_WORD(mdm_cfg[5].info) & 0x00ff) == MDM_CAPI_NEG_V100)
  7067. {
  7068. cai[8] |= DSP_CAI_MODEM_NEGOTIATE_V100;
  7069. dbug(1, dprintf("MDM: V100"));
  7070. }
  7071. else if ((GET_WORD(mdm_cfg[5].info) & 0x00ff) == MDM_CAPI_NEG_MOD_CLASS)
  7072. {
  7073. cai[8] |= DSP_CAI_MODEM_NEGOTIATE_IN_CLASS;
  7074. dbug(1, dprintf("MDM: IN CLASS"));
  7075. }
  7076. else if ((GET_WORD(mdm_cfg[5].info) & 0x00ff) == MDM_CAPI_NEG_DISABLED)
  7077. {
  7078. cai[8] |= DSP_CAI_MODEM_NEGOTIATE_DISABLED;
  7079. dbug(1, dprintf("MDM: DISABLED"));
  7080. }
  7081. cai[0] = 20;
  7082. if ((plci->adapter->man_profile.private_options & (1L << PRIVATE_V18))
  7083. && (GET_WORD(mdm_cfg[5].info) & 0x8000)) /* Private V.18 enable */
  7084. {
  7085. plci->requested_options |= 1L << PRIVATE_V18;
  7086. }
  7087. if (GET_WORD(mdm_cfg[5].info) & 0x4000) /* Private VOWN enable */
  7088. plci->requested_options |= 1L << PRIVATE_VOWN;
  7089. if ((plci->requested_options_conn | plci->requested_options | plci->adapter->requested_options_table[plci->appl->Id - 1])
  7090. & ((1L << PRIVATE_V18) | (1L << PRIVATE_VOWN)))
  7091. {
  7092. if (!api_parse(&bp_parms[3].info[1], (word)bp_parms[3].length, "wwwwwws", mdm_cfg))
  7093. {
  7094. i = 27;
  7095. if (mdm_cfg[6].length >= 4)
  7096. {
  7097. d = GET_DWORD(&mdm_cfg[6].info[1]);
  7098. cai[7] |= (byte) d; /* line taking options */
  7099. cai[9] |= (byte)(d >> 8); /* modulation options */
  7100. cai[++i] = (byte)(d >> 16); /* vown modulation options */
  7101. cai[++i] = (byte)(d >> 24);
  7102. if (mdm_cfg[6].length >= 8)
  7103. {
  7104. d = GET_DWORD(&mdm_cfg[6].info[5]);
  7105. cai[10] |= (byte) d; /* disabled modulations mask */
  7106. cai[11] |= (byte)(d >> 8);
  7107. if (mdm_cfg[6].length >= 12)
  7108. {
  7109. d = GET_DWORD(&mdm_cfg[6].info[9]);
  7110. cai[12] = (byte) d; /* enabled modulations mask */
  7111. cai[++i] = (byte)(d >> 8); /* vown enabled modulations */
  7112. cai[++i] = (byte)(d >> 16);
  7113. cai[++i] = (byte)(d >> 24);
  7114. cai[++i] = 0;
  7115. if (mdm_cfg[6].length >= 14)
  7116. {
  7117. w = GET_WORD(&mdm_cfg[6].info[13]);
  7118. if (w != 0)
  7119. PUT_WORD(&cai[13], w); /* min tx speed */
  7120. if (mdm_cfg[6].length >= 16)
  7121. {
  7122. w = GET_WORD(&mdm_cfg[6].info[15]);
  7123. if (w != 0)
  7124. PUT_WORD(&cai[15], w); /* max tx speed */
  7125. if (mdm_cfg[6].length >= 18)
  7126. {
  7127. w = GET_WORD(&mdm_cfg[6].info[17]);
  7128. if (w != 0)
  7129. PUT_WORD(&cai[17], w); /* min rx speed */
  7130. if (mdm_cfg[6].length >= 20)
  7131. {
  7132. w = GET_WORD(&mdm_cfg[6].info[19]);
  7133. if (w != 0)
  7134. PUT_WORD(&cai[19], w); /* max rx speed */
  7135. if (mdm_cfg[6].length >= 22)
  7136. {
  7137. w = GET_WORD(&mdm_cfg[6].info[21]);
  7138. cai[23] = (byte)(-((short) w)); /* transmit level */
  7139. if (mdm_cfg[6].length >= 24)
  7140. {
  7141. w = GET_WORD(&mdm_cfg[6].info[23]);
  7142. cai[22] |= (byte) w; /* info options mask */
  7143. cai[21] |= (byte)(w >> 8); /* disabled symbol rates */
  7144. }
  7145. }
  7146. }
  7147. }
  7148. }
  7149. }
  7150. }
  7151. }
  7152. }
  7153. cai[27] = i - 27;
  7154. i++;
  7155. if (!api_parse(&bp_parms[3].info[1], (word)bp_parms[3].length, "wwwwwwss", mdm_cfg))
  7156. {
  7157. if (!api_parse(&mdm_cfg[7].info[1], (word)mdm_cfg[7].length, "sss", mdm_cfg_v18))
  7158. {
  7159. for (n = 0; n < 3; n++)
  7160. {
  7161. cai[i] = (byte)(mdm_cfg_v18[n].length);
  7162. for (j = 1; j < ((word)(cai[i] + 1)); j++)
  7163. cai[i + j] = mdm_cfg_v18[n].info[j];
  7164. i += cai[i] + 1;
  7165. }
  7166. }
  7167. }
  7168. cai[0] = (byte)(i - 1);
  7169. }
  7170. }
  7171. }
  7172. }
  7173. if (GET_WORD(bp_parms[0].info) == 2 || /* V.110 async */
  7174. GET_WORD(bp_parms[0].info) == 3) /* V.110 sync */
  7175. {
  7176. if (bp_parms[3].length) {
  7177. dbug(1, dprintf("V.110,%d", GET_WORD(&bp_parms[3].info[1])));
  7178. switch (GET_WORD(&bp_parms[3].info[1])) { /* Rate */
  7179. case 0:
  7180. case 56000:
  7181. if (GET_WORD(bp_parms[0].info) == 3) { /* V.110 sync 56k */
  7182. dbug(1, dprintf("56k sync HSCX"));
  7183. cai[1] = 8;
  7184. cai[2] = 0;
  7185. cai[3] = 0;
  7186. }
  7187. else if (GET_WORD(bp_parms[0].info) == 2) {
  7188. dbug(1, dprintf("56k async DSP"));
  7189. cai[2] = 9;
  7190. }
  7191. break;
  7192. case 50: cai[2] = 1; break;
  7193. case 75: cai[2] = 1; break;
  7194. case 110: cai[2] = 1; break;
  7195. case 150: cai[2] = 1; break;
  7196. case 200: cai[2] = 1; break;
  7197. case 300: cai[2] = 1; break;
  7198. case 600: cai[2] = 1; break;
  7199. case 1200: cai[2] = 2; break;
  7200. case 2400: cai[2] = 3; break;
  7201. case 4800: cai[2] = 4; break;
  7202. case 7200: cai[2] = 10; break;
  7203. case 9600: cai[2] = 5; break;
  7204. case 12000: cai[2] = 13; break;
  7205. case 24000: cai[2] = 0; break;
  7206. case 14400: cai[2] = 11; break;
  7207. case 19200: cai[2] = 6; break;
  7208. case 28800: cai[2] = 12; break;
  7209. case 38400: cai[2] = 7; break;
  7210. case 48000: cai[2] = 8; break;
  7211. case 76: cai[2] = 15; break; /* 75/1200 */
  7212. case 1201: cai[2] = 14; break; /* 1200/75 */
  7213. case 56001: cai[2] = 9; break; /* V.110 56000 */
  7214. default:
  7215. return _B1_PARM_NOT_SUPPORTED;
  7216. }
  7217. cai[3] = 0;
  7218. if (cai[1] == 13) /* v.110 async */
  7219. {
  7220. if (bp_parms[3].length >= 8)
  7221. {
  7222. switch (GET_WORD(&bp_parms[3].info[3]))
  7223. { /* char length */
  7224. case 5:
  7225. cai[3] |= DSP_CAI_ASYNC_CHAR_LENGTH_5;
  7226. break;
  7227. case 6:
  7228. cai[3] |= DSP_CAI_ASYNC_CHAR_LENGTH_6;
  7229. break;
  7230. case 7:
  7231. cai[3] |= DSP_CAI_ASYNC_CHAR_LENGTH_7;
  7232. break;
  7233. }
  7234. switch (GET_WORD(&bp_parms[3].info[5]))
  7235. { /* Parity */
  7236. case 1: /* odd parity */
  7237. cai[3] |= (DSP_CAI_ASYNC_PARITY_ENABLE | DSP_CAI_ASYNC_PARITY_ODD);
  7238. break;
  7239. case 2: /* even parity */
  7240. cai[3] |= (DSP_CAI_ASYNC_PARITY_ENABLE | DSP_CAI_ASYNC_PARITY_EVEN);
  7241. break;
  7242. }
  7243. switch (GET_WORD(&bp_parms[3].info[7]))
  7244. { /* stop bits */
  7245. case 1: /* 2 stop bits */
  7246. cai[3] |= DSP_CAI_ASYNC_TWO_STOP_BITS;
  7247. break;
  7248. }
  7249. }
  7250. }
  7251. }
  7252. else if (cai[1] == 8 || GET_WORD(bp_parms[0].info) == 3) {
  7253. dbug(1, dprintf("V.110 default 56k sync"));
  7254. cai[1] = 8;
  7255. cai[2] = 0;
  7256. cai[3] = 0;
  7257. }
  7258. else {
  7259. dbug(1, dprintf("V.110 default 9600 async"));
  7260. cai[2] = 5;
  7261. }
  7262. }
  7263. PUT_WORD(&cai[5], plci->appl->MaxDataLength);
  7264. 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]));
  7265. /* HexDump ("CAI", sizeof(cai), &cai[0]); */
  7266. add_p(plci, CAI, cai);
  7267. return 0;
  7268. }
  7269. /*------------------------------------------------------------------*/
  7270. /* put parameter for b2 and B3 protocol in the parameter buffer */
  7271. /*------------------------------------------------------------------*/
  7272. static word add_b23(PLCI *plci, API_PARSE *bp)
  7273. {
  7274. word i, fax_control_bits;
  7275. byte pos, len;
  7276. byte SAPI = 0x40; /* default SAPI 16 for x.31 */
  7277. API_PARSE bp_parms[8];
  7278. API_PARSE *b1_config;
  7279. API_PARSE *b2_config;
  7280. API_PARSE b2_config_parms[8];
  7281. API_PARSE *b3_config;
  7282. API_PARSE b3_config_parms[6];
  7283. API_PARSE global_config[2];
  7284. static byte llc[3] = {2,0,0};
  7285. static byte dlc[20] = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
  7286. static byte nlc[256];
  7287. static byte lli[12] = {1,1};
  7288. const byte llc2_out[] = {1,2,4,6,2,0,0,0, X75_V42BIS,V120_L2,V120_V42BIS,V120_L2,6};
  7289. const byte llc2_in[] = {1,3,4,6,3,0,0,0, X75_V42BIS,V120_L2,V120_V42BIS,V120_L2,6};
  7290. const byte llc3[] = {4,3,2,2,6,6,0};
  7291. const byte header[] = {0,2,3,3,0,0,0};
  7292. for (i = 0; i < 8; i++) bp_parms[i].length = 0;
  7293. for (i = 0; i < 6; i++) b2_config_parms[i].length = 0;
  7294. for (i = 0; i < 5; i++) b3_config_parms[i].length = 0;
  7295. lli[0] = 1;
  7296. lli[1] = 1;
  7297. if (plci->adapter->manufacturer_features & MANUFACTURER_FEATURE_XONOFF_FLOW_CONTROL)
  7298. lli[1] |= 2;
  7299. if (plci->adapter->manufacturer_features & MANUFACTURER_FEATURE_OOB_CHANNEL)
  7300. lli[1] |= 4;
  7301. if ((lli[1] & 0x02) && (diva_xdi_extended_features & DIVA_CAPI_USE_CMA)) {
  7302. lli[1] |= 0x10;
  7303. if (plci->rx_dma_descriptor <= 0) {
  7304. plci->rx_dma_descriptor = diva_get_dma_descriptor(plci, &plci->rx_dma_magic);
  7305. if (plci->rx_dma_descriptor >= 0)
  7306. plci->rx_dma_descriptor++;
  7307. }
  7308. if (plci->rx_dma_descriptor > 0) {
  7309. lli[0] = 6;
  7310. lli[1] |= 0x40;
  7311. lli[2] = (byte)(plci->rx_dma_descriptor - 1);
  7312. lli[3] = (byte)plci->rx_dma_magic;
  7313. lli[4] = (byte)(plci->rx_dma_magic >> 8);
  7314. lli[5] = (byte)(plci->rx_dma_magic >> 16);
  7315. lli[6] = (byte)(plci->rx_dma_magic >> 24);
  7316. }
  7317. }
  7318. if (DIVA_CAPI_SUPPORTS_NO_CANCEL(plci->adapter)) {
  7319. lli[1] |= 0x20;
  7320. }
  7321. dbug(1, dprintf("add_b23"));
  7322. api_save_msg(bp, "s", &plci->B_protocol);
  7323. if (!bp->length && plci->tel)
  7324. {
  7325. plci->adv_nl = true;
  7326. dbug(1, dprintf("Default adv.Nl"));
  7327. add_p(plci, LLI, lli);
  7328. plci->B2_prot = 1 /*XPARENT*/;
  7329. plci->B3_prot = 0 /*XPARENT*/;
  7330. llc[1] = 2;
  7331. llc[2] = 4;
  7332. add_p(plci, LLC, llc);
  7333. dlc[0] = 2;
  7334. PUT_WORD(&dlc[1], plci->appl->MaxDataLength);
  7335. add_p(plci, DLC, dlc);
  7336. return 0;
  7337. }
  7338. if (!bp->length) /*default*/
  7339. {
  7340. dbug(1, dprintf("ret default"));
  7341. add_p(plci, LLI, lli);
  7342. plci->B2_prot = 0 /*X.75 */;
  7343. plci->B3_prot = 0 /*XPARENT*/;
  7344. llc[1] = 1;
  7345. llc[2] = 4;
  7346. add_p(plci, LLC, llc);
  7347. dlc[0] = 2;
  7348. PUT_WORD(&dlc[1], plci->appl->MaxDataLength);
  7349. add_p(plci, DLC, dlc);
  7350. return 0;
  7351. }
  7352. dbug(1, dprintf("b_prot_len=%d", (word)bp->length));
  7353. if ((word)bp->length > 256) return _WRONG_MESSAGE_FORMAT;
  7354. if (api_parse(&bp->info[1], (word)bp->length, "wwwsssb", bp_parms))
  7355. {
  7356. bp_parms[6].length = 0;
  7357. if (api_parse(&bp->info[1], (word)bp->length, "wwwsss", bp_parms))
  7358. {
  7359. dbug(1, dprintf("b-form.!"));
  7360. return _WRONG_MESSAGE_FORMAT;
  7361. }
  7362. }
  7363. else if (api_parse(&bp->info[1], (word)bp->length, "wwwssss", bp_parms))
  7364. {
  7365. dbug(1, dprintf("b-form.!"));
  7366. return _WRONG_MESSAGE_FORMAT;
  7367. }
  7368. if (plci->tel == ADV_VOICE) /* transparent B on advanced voice */
  7369. {
  7370. if (GET_WORD(bp_parms[1].info) != 1
  7371. || GET_WORD(bp_parms[2].info) != 0) return _B2_NOT_SUPPORTED;
  7372. plci->adv_nl = true;
  7373. }
  7374. else if (plci->tel) return _B2_NOT_SUPPORTED;
  7375. if ((GET_WORD(bp_parms[1].info) == B2_RTP)
  7376. && (GET_WORD(bp_parms[2].info) == B3_RTP)
  7377. && (plci->adapter->man_profile.private_options & (1L << PRIVATE_RTP)))
  7378. {
  7379. add_p(plci, LLI, lli);
  7380. plci->B2_prot = (byte) GET_WORD(bp_parms[1].info);
  7381. plci->B3_prot = (byte) GET_WORD(bp_parms[2].info);
  7382. llc[1] = (plci->call_dir & (CALL_DIR_ORIGINATE | CALL_DIR_FORCE_OUTG_NL)) ? 14 : 13;
  7383. llc[2] = 4;
  7384. add_p(plci, LLC, llc);
  7385. dlc[0] = 2;
  7386. PUT_WORD(&dlc[1], plci->appl->MaxDataLength);
  7387. dlc[3] = 3; /* Addr A */
  7388. dlc[4] = 1; /* Addr B */
  7389. dlc[5] = 7; /* modulo mode */
  7390. dlc[6] = 7; /* window size */
  7391. dlc[7] = 0; /* XID len Lo */
  7392. dlc[8] = 0; /* XID len Hi */
  7393. for (i = 0; i < bp_parms[4].length; i++)
  7394. dlc[9 + i] = bp_parms[4].info[1 + i];
  7395. dlc[0] = (byte)(8 + bp_parms[4].length);
  7396. add_p(plci, DLC, dlc);
  7397. for (i = 0; i < bp_parms[5].length; i++)
  7398. nlc[1 + i] = bp_parms[5].info[1 + i];
  7399. nlc[0] = (byte)(bp_parms[5].length);
  7400. add_p(plci, NLC, nlc);
  7401. return 0;
  7402. }
  7403. if ((GET_WORD(bp_parms[1].info) >= 32)
  7404. || (!((1L << GET_WORD(bp_parms[1].info)) & plci->adapter->profile.B2_Protocols)
  7405. && ((GET_WORD(bp_parms[1].info) != B2_PIAFS)
  7406. || !(plci->adapter->man_profile.private_options & (1L << PRIVATE_PIAFS)))))
  7407. {
  7408. return _B2_NOT_SUPPORTED;
  7409. }
  7410. if ((GET_WORD(bp_parms[2].info) >= 32)
  7411. || !((1L << GET_WORD(bp_parms[2].info)) & plci->adapter->profile.B3_Protocols))
  7412. {
  7413. return _B3_NOT_SUPPORTED;
  7414. }
  7415. if ((GET_WORD(bp_parms[1].info) != B2_SDLC)
  7416. && ((GET_WORD(bp_parms[0].info) == B1_MODEM_ALL_NEGOTIATE)
  7417. || (GET_WORD(bp_parms[0].info) == B1_MODEM_ASYNC)
  7418. || (GET_WORD(bp_parms[0].info) == B1_MODEM_SYNC_HDLC)))
  7419. {
  7420. return (add_modem_b23(plci, bp_parms));
  7421. }
  7422. add_p(plci, LLI, lli);
  7423. plci->B2_prot = (byte)GET_WORD(bp_parms[1].info);
  7424. plci->B3_prot = (byte)GET_WORD(bp_parms[2].info);
  7425. if (plci->B2_prot == 12) SAPI = 0; /* default SAPI D-channel */
  7426. if (bp_parms[6].length)
  7427. {
  7428. if (api_parse(&bp_parms[6].info[1], (word)bp_parms[6].length, "w", global_config))
  7429. {
  7430. return _WRONG_MESSAGE_FORMAT;
  7431. }
  7432. switch (GET_WORD(global_config[0].info))
  7433. {
  7434. case 1:
  7435. plci->call_dir = (plci->call_dir & ~CALL_DIR_ANSWER) | CALL_DIR_ORIGINATE;
  7436. break;
  7437. case 2:
  7438. plci->call_dir = (plci->call_dir & ~CALL_DIR_ORIGINATE) | CALL_DIR_ANSWER;
  7439. break;
  7440. }
  7441. }
  7442. dbug(1, dprintf("call_dir=%04x", plci->call_dir));
  7443. if (plci->B2_prot == B2_PIAFS)
  7444. llc[1] = PIAFS_CRC;
  7445. else
  7446. /* IMPLEMENT_PIAFS */
  7447. {
  7448. llc[1] = (plci->call_dir & (CALL_DIR_ORIGINATE | CALL_DIR_FORCE_OUTG_NL)) ?
  7449. llc2_out[GET_WORD(bp_parms[1].info)] : llc2_in[GET_WORD(bp_parms[1].info)];
  7450. }
  7451. llc[2] = llc3[GET_WORD(bp_parms[2].info)];
  7452. add_p(plci, LLC, llc);
  7453. dlc[0] = 2;
  7454. PUT_WORD(&dlc[1], plci->appl->MaxDataLength +
  7455. header[GET_WORD(bp_parms[2].info)]);
  7456. b1_config = &bp_parms[3];
  7457. nlc[0] = 0;
  7458. if (plci->B3_prot == 4
  7459. || plci->B3_prot == 5)
  7460. {
  7461. for (i = 0; i < sizeof(T30_INFO); i++) nlc[i] = 0;
  7462. nlc[0] = sizeof(T30_INFO);
  7463. if (plci->adapter->manufacturer_features & MANUFACTURER_FEATURE_FAX_PAPER_FORMATS)
  7464. ((T30_INFO *)&nlc[1])->operating_mode = T30_OPERATING_MODE_CAPI;
  7465. ((T30_INFO *)&nlc[1])->rate_div_2400 = 0xff;
  7466. if (b1_config->length >= 2)
  7467. {
  7468. ((T30_INFO *)&nlc[1])->rate_div_2400 = (byte)(GET_WORD(&b1_config->info[1]) / 2400);
  7469. }
  7470. }
  7471. b2_config = &bp_parms[4];
  7472. if (llc[1] == PIAFS_CRC)
  7473. {
  7474. if (plci->B3_prot != B3_TRANSPARENT)
  7475. {
  7476. return _B_STACK_NOT_SUPPORTED;
  7477. }
  7478. if (b2_config->length && api_parse(&b2_config->info[1], (word)b2_config->length, "bwww", b2_config_parms)) {
  7479. return _WRONG_MESSAGE_FORMAT;
  7480. }
  7481. PUT_WORD(&dlc[1], plci->appl->MaxDataLength);
  7482. dlc[3] = 0; /* Addr A */
  7483. dlc[4] = 0; /* Addr B */
  7484. dlc[5] = 0; /* modulo mode */
  7485. dlc[6] = 0; /* window size */
  7486. if (b2_config->length >= 7) {
  7487. dlc[7] = 7;
  7488. dlc[8] = 0;
  7489. dlc[9] = b2_config_parms[0].info[0]; /* PIAFS protocol Speed configuration */
  7490. dlc[10] = b2_config_parms[1].info[0]; /* V.42bis P0 */
  7491. dlc[11] = b2_config_parms[1].info[1]; /* V.42bis P0 */
  7492. dlc[12] = b2_config_parms[2].info[0]; /* V.42bis P1 */
  7493. dlc[13] = b2_config_parms[2].info[1]; /* V.42bis P1 */
  7494. dlc[14] = b2_config_parms[3].info[0]; /* V.42bis P2 */
  7495. dlc[15] = b2_config_parms[3].info[1]; /* V.42bis P2 */
  7496. dlc[0] = 15;
  7497. if (b2_config->length >= 8) { /* PIAFS control abilities */
  7498. dlc[7] = 10;
  7499. dlc[16] = 2; /* Length of PIAFS extension */
  7500. dlc[17] = PIAFS_UDATA_ABILITIES; /* control (UDATA) ability */
  7501. dlc[18] = b2_config_parms[4].info[0]; /* value */
  7502. dlc[0] = 18;
  7503. }
  7504. }
  7505. else /* default values, 64K, variable, no compression */
  7506. {
  7507. dlc[7] = 7;
  7508. dlc[8] = 0;
  7509. dlc[9] = 0x03; /* PIAFS protocol Speed configuration */
  7510. dlc[10] = 0x03; /* V.42bis P0 */
  7511. dlc[11] = 0; /* V.42bis P0 */
  7512. dlc[12] = 0; /* V.42bis P1 */
  7513. dlc[13] = 0; /* V.42bis P1 */
  7514. dlc[14] = 0; /* V.42bis P2 */
  7515. dlc[15] = 0; /* V.42bis P2 */
  7516. dlc[0] = 15;
  7517. }
  7518. add_p(plci, DLC, dlc);
  7519. }
  7520. else
  7521. if ((llc[1] == V120_L2) || (llc[1] == V120_V42BIS))
  7522. {
  7523. if (plci->B3_prot != B3_TRANSPARENT)
  7524. return _B_STACK_NOT_SUPPORTED;
  7525. dlc[0] = 6;
  7526. PUT_WORD(&dlc[1], GET_WORD(&dlc[1]) + 2);
  7527. dlc[3] = 0x08;
  7528. dlc[4] = 0x01;
  7529. dlc[5] = 127;
  7530. dlc[6] = 7;
  7531. if (b2_config->length != 0)
  7532. {
  7533. if ((llc[1] == V120_V42BIS) && api_parse(&b2_config->info[1], (word)b2_config->length, "bbbbwww", b2_config_parms)) {
  7534. return _WRONG_MESSAGE_FORMAT;
  7535. }
  7536. dlc[3] = (byte)((b2_config->info[2] << 3) | ((b2_config->info[1] >> 5) & 0x04));
  7537. dlc[4] = (byte)((b2_config->info[1] << 1) | 0x01);
  7538. if (b2_config->info[3] != 128)
  7539. {
  7540. dbug(1, dprintf("1D-dlc= %x %x %x %x %x", dlc[0], dlc[1], dlc[2], dlc[3], dlc[4]));
  7541. return _B2_PARM_NOT_SUPPORTED;
  7542. }
  7543. dlc[5] = (byte)(b2_config->info[3] - 1);
  7544. dlc[6] = b2_config->info[4];
  7545. if (llc[1] == V120_V42BIS) {
  7546. if (b2_config->length >= 10) {
  7547. dlc[7] = 6;
  7548. dlc[8] = 0;
  7549. dlc[9] = b2_config_parms[4].info[0];
  7550. dlc[10] = b2_config_parms[4].info[1];
  7551. dlc[11] = b2_config_parms[5].info[0];
  7552. dlc[12] = b2_config_parms[5].info[1];
  7553. dlc[13] = b2_config_parms[6].info[0];
  7554. dlc[14] = b2_config_parms[6].info[1];
  7555. dlc[0] = 14;
  7556. dbug(1, dprintf("b2_config_parms[4].info[0] [1]: %x %x", b2_config_parms[4].info[0], b2_config_parms[4].info[1]));
  7557. dbug(1, dprintf("b2_config_parms[5].info[0] [1]: %x %x", b2_config_parms[5].info[0], b2_config_parms[5].info[1]));
  7558. dbug(1, dprintf("b2_config_parms[6].info[0] [1]: %x %x", b2_config_parms[6].info[0], b2_config_parms[6].info[1]));
  7559. }
  7560. else {
  7561. dlc[6] = 14;
  7562. }
  7563. }
  7564. }
  7565. }
  7566. else
  7567. {
  7568. if (b2_config->length)
  7569. {
  7570. dbug(1, dprintf("B2-Config"));
  7571. if (llc[1] == X75_V42BIS) {
  7572. if (api_parse(&b2_config->info[1], (word)b2_config->length, "bbbbwww", b2_config_parms))
  7573. {
  7574. return _WRONG_MESSAGE_FORMAT;
  7575. }
  7576. }
  7577. else {
  7578. if (api_parse(&b2_config->info[1], (word)b2_config->length, "bbbbs", b2_config_parms))
  7579. {
  7580. return _WRONG_MESSAGE_FORMAT;
  7581. }
  7582. }
  7583. /* if B2 Protocol is LAPD, b2_config structure is different */
  7584. if (llc[1] == 6)
  7585. {
  7586. dlc[0] = 4;
  7587. if (b2_config->length >= 1) dlc[2] = b2_config->info[1]; /* TEI */
  7588. else dlc[2] = 0x01;
  7589. if ((b2_config->length >= 2) && (plci->B2_prot == 12))
  7590. {
  7591. SAPI = b2_config->info[2]; /* SAPI */
  7592. }
  7593. dlc[1] = SAPI;
  7594. if ((b2_config->length >= 3) && (b2_config->info[3] == 128))
  7595. {
  7596. dlc[3] = 127; /* Mode */
  7597. }
  7598. else
  7599. {
  7600. dlc[3] = 7; /* Mode */
  7601. }
  7602. if (b2_config->length >= 4) dlc[4] = b2_config->info[4]; /* Window */
  7603. else dlc[4] = 1;
  7604. dbug(1, dprintf("D-dlc[%d]=%x,%x,%x,%x", dlc[0], dlc[1], dlc[2], dlc[3], dlc[4]));
  7605. if (b2_config->length > 5) return _B2_PARM_NOT_SUPPORTED;
  7606. }
  7607. else
  7608. {
  7609. dlc[0] = (byte)(b2_config_parms[4].length + 6);
  7610. dlc[3] = b2_config->info[1];
  7611. dlc[4] = b2_config->info[2];
  7612. if (b2_config->info[3] != 8 && b2_config->info[3] != 128) {
  7613. dbug(1, dprintf("1D-dlc= %x %x %x %x %x", dlc[0], dlc[1], dlc[2], dlc[3], dlc[4]));
  7614. return _B2_PARM_NOT_SUPPORTED;
  7615. }
  7616. dlc[5] = (byte)(b2_config->info[3] - 1);
  7617. dlc[6] = b2_config->info[4];
  7618. if (dlc[6] > dlc[5]) {
  7619. 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]));
  7620. return _B2_PARM_NOT_SUPPORTED;
  7621. }
  7622. if (llc[1] == X75_V42BIS) {
  7623. if (b2_config->length >= 10) {
  7624. dlc[7] = 6;
  7625. dlc[8] = 0;
  7626. dlc[9] = b2_config_parms[4].info[0];
  7627. dlc[10] = b2_config_parms[4].info[1];
  7628. dlc[11] = b2_config_parms[5].info[0];
  7629. dlc[12] = b2_config_parms[5].info[1];
  7630. dlc[13] = b2_config_parms[6].info[0];
  7631. dlc[14] = b2_config_parms[6].info[1];
  7632. dlc[0] = 14;
  7633. dbug(1, dprintf("b2_config_parms[4].info[0] [1]: %x %x", b2_config_parms[4].info[0], b2_config_parms[4].info[1]));
  7634. dbug(1, dprintf("b2_config_parms[5].info[0] [1]: %x %x", b2_config_parms[5].info[0], b2_config_parms[5].info[1]));
  7635. dbug(1, dprintf("b2_config_parms[6].info[0] [1]: %x %x", b2_config_parms[6].info[0], b2_config_parms[6].info[1]));
  7636. }
  7637. else {
  7638. dlc[6] = 14;
  7639. }
  7640. }
  7641. else {
  7642. PUT_WORD(&dlc[7], (word)b2_config_parms[4].length);
  7643. for (i = 0; i < b2_config_parms[4].length; i++)
  7644. dlc[11 + i] = b2_config_parms[4].info[1 + i];
  7645. }
  7646. }
  7647. }
  7648. }
  7649. add_p(plci, DLC, dlc);
  7650. b3_config = &bp_parms[5];
  7651. if (b3_config->length)
  7652. {
  7653. if (plci->B3_prot == 4
  7654. || plci->B3_prot == 5)
  7655. {
  7656. if (api_parse(&b3_config->info[1], (word)b3_config->length, "wwss", b3_config_parms))
  7657. {
  7658. return _WRONG_MESSAGE_FORMAT;
  7659. }
  7660. i = GET_WORD((byte *)(b3_config_parms[0].info));
  7661. ((T30_INFO *)&nlc[1])->resolution = (byte)(((i & 0x0001) ||
  7662. ((plci->B3_prot == 4) && (((byte)(GET_WORD((byte *)b3_config_parms[1].info))) != 5))) ? T30_RESOLUTION_R8_0770_OR_200 : 0);
  7663. ((T30_INFO *)&nlc[1])->data_format = (byte)(GET_WORD((byte *)b3_config_parms[1].info));
  7664. fax_control_bits = T30_CONTROL_BIT_ALL_FEATURES;
  7665. if ((((T30_INFO *)&nlc[1])->rate_div_2400 != 0) && (((T30_INFO *)&nlc[1])->rate_div_2400 <= 6))
  7666. fax_control_bits &= ~T30_CONTROL_BIT_ENABLE_V34FAX;
  7667. if (plci->adapter->manufacturer_features & MANUFACTURER_FEATURE_FAX_PAPER_FORMATS)
  7668. {
  7669. if ((plci->requested_options_conn | plci->requested_options | plci->adapter->requested_options_table[plci->appl->Id - 1])
  7670. & (1L << PRIVATE_FAX_PAPER_FORMATS))
  7671. {
  7672. ((T30_INFO *)&nlc[1])->resolution |= T30_RESOLUTION_R8_1540 |
  7673. T30_RESOLUTION_R16_1540_OR_400 | T30_RESOLUTION_300_300 |
  7674. T30_RESOLUTION_INCH_BASED | T30_RESOLUTION_METRIC_BASED;
  7675. }
  7676. ((T30_INFO *)&nlc[1])->recording_properties =
  7677. T30_RECORDING_WIDTH_ISO_A3 |
  7678. (T30_RECORDING_LENGTH_UNLIMITED << 2) |
  7679. (T30_MIN_SCANLINE_TIME_00_00_00 << 4);
  7680. }
  7681. if (plci->B3_prot == 5)
  7682. {
  7683. if (i & 0x0002) /* Accept incoming fax-polling requests */
  7684. fax_control_bits |= T30_CONTROL_BIT_ACCEPT_POLLING;
  7685. if (i & 0x2000) /* Do not use MR compression */
  7686. fax_control_bits &= ~T30_CONTROL_BIT_ENABLE_2D_CODING;
  7687. if (i & 0x4000) /* Do not use MMR compression */
  7688. fax_control_bits &= ~T30_CONTROL_BIT_ENABLE_T6_CODING;
  7689. if (i & 0x8000) /* Do not use ECM */
  7690. fax_control_bits &= ~T30_CONTROL_BIT_ENABLE_ECM;
  7691. if (plci->fax_connect_info_length != 0)
  7692. {
  7693. ((T30_INFO *)&nlc[1])->resolution = ((T30_INFO *)plci->fax_connect_info_buffer)->resolution;
  7694. ((T30_INFO *)&nlc[1])->data_format = ((T30_INFO *)plci->fax_connect_info_buffer)->data_format;
  7695. ((T30_INFO *)&nlc[1])->recording_properties = ((T30_INFO *)plci->fax_connect_info_buffer)->recording_properties;
  7696. fax_control_bits |= GET_WORD(&((T30_INFO *)plci->fax_connect_info_buffer)->control_bits_low) &
  7697. (T30_CONTROL_BIT_REQUEST_POLLING | T30_CONTROL_BIT_MORE_DOCUMENTS);
  7698. }
  7699. }
  7700. /* copy station id to NLC */
  7701. for (i = 0; i < T30_MAX_STATION_ID_LENGTH; i++)
  7702. {
  7703. if (i < b3_config_parms[2].length)
  7704. {
  7705. ((T30_INFO *)&nlc[1])->station_id[i] = ((byte *)b3_config_parms[2].info)[1 + i];
  7706. }
  7707. else
  7708. {
  7709. ((T30_INFO *)&nlc[1])->station_id[i] = ' ';
  7710. }
  7711. }
  7712. ((T30_INFO *)&nlc[1])->station_id_len = T30_MAX_STATION_ID_LENGTH;
  7713. /* copy head line to NLC */
  7714. if (b3_config_parms[3].length)
  7715. {
  7716. pos = (byte)(fax_head_line_time(&(((T30_INFO *)&nlc[1])->station_id[T30_MAX_STATION_ID_LENGTH])));
  7717. if (pos != 0)
  7718. {
  7719. if (CAPI_MAX_DATE_TIME_LENGTH + 2 + b3_config_parms[3].length > CAPI_MAX_HEAD_LINE_SPACE)
  7720. pos = 0;
  7721. else
  7722. {
  7723. nlc[1 + offsetof(T30_INFO, station_id) + T30_MAX_STATION_ID_LENGTH + pos++] = ' ';
  7724. nlc[1 + offsetof(T30_INFO, station_id) + T30_MAX_STATION_ID_LENGTH + pos++] = ' ';
  7725. len = (byte)b3_config_parms[2].length;
  7726. if (len > 20)
  7727. len = 20;
  7728. if (CAPI_MAX_DATE_TIME_LENGTH + 2 + len + 2 + b3_config_parms[3].length <= CAPI_MAX_HEAD_LINE_SPACE)
  7729. {
  7730. for (i = 0; i < len; i++)
  7731. nlc[1 + offsetof(T30_INFO, station_id) + T30_MAX_STATION_ID_LENGTH + pos++] = ((byte *)b3_config_parms[2].info)[1 + i];
  7732. nlc[1 + offsetof(T30_INFO, station_id) + T30_MAX_STATION_ID_LENGTH + pos++] = ' ';
  7733. nlc[1 + offsetof(T30_INFO, station_id) + T30_MAX_STATION_ID_LENGTH + pos++] = ' ';
  7734. }
  7735. }
  7736. }
  7737. len = (byte)b3_config_parms[3].length;
  7738. if (len > CAPI_MAX_HEAD_LINE_SPACE - pos)
  7739. len = (byte)(CAPI_MAX_HEAD_LINE_SPACE - pos);
  7740. ((T30_INFO *)&nlc[1])->head_line_len = (byte)(pos + len);
  7741. nlc[0] += (byte)(pos + len);
  7742. for (i = 0; i < len; i++)
  7743. nlc[1 + offsetof(T30_INFO, station_id) + T30_MAX_STATION_ID_LENGTH + pos++] = ((byte *)b3_config_parms[3].info)[1 + i];
  7744. } else
  7745. ((T30_INFO *)&nlc[1])->head_line_len = 0;
  7746. plci->nsf_control_bits = 0;
  7747. if (plci->B3_prot == 5)
  7748. {
  7749. if ((plci->adapter->man_profile.private_options & (1L << PRIVATE_FAX_SUB_SEP_PWD))
  7750. && (GET_WORD((byte *)b3_config_parms[1].info) & 0x8000)) /* Private SUB/SEP/PWD enable */
  7751. {
  7752. plci->requested_options |= 1L << PRIVATE_FAX_SUB_SEP_PWD;
  7753. }
  7754. if ((plci->adapter->man_profile.private_options & (1L << PRIVATE_FAX_NONSTANDARD))
  7755. && (GET_WORD((byte *)b3_config_parms[1].info) & 0x4000)) /* Private non-standard facilities enable */
  7756. {
  7757. plci->requested_options |= 1L << PRIVATE_FAX_NONSTANDARD;
  7758. }
  7759. if ((plci->requested_options_conn | plci->requested_options | plci->adapter->requested_options_table[plci->appl->Id - 1])
  7760. & ((1L << PRIVATE_FAX_SUB_SEP_PWD) | (1L << PRIVATE_FAX_NONSTANDARD)))
  7761. {
  7762. if ((plci->requested_options_conn | plci->requested_options | plci->adapter->requested_options_table[plci->appl->Id - 1])
  7763. & (1L << PRIVATE_FAX_SUB_SEP_PWD))
  7764. {
  7765. fax_control_bits |= T30_CONTROL_BIT_ACCEPT_SUBADDRESS | T30_CONTROL_BIT_ACCEPT_PASSWORD;
  7766. if (fax_control_bits & T30_CONTROL_BIT_ACCEPT_POLLING)
  7767. fax_control_bits |= T30_CONTROL_BIT_ACCEPT_SEL_POLLING;
  7768. }
  7769. len = nlc[0];
  7770. pos = offsetof(T30_INFO, station_id) + T30_MAX_STATION_ID_LENGTH;
  7771. if (pos < plci->fax_connect_info_length)
  7772. {
  7773. for (i = 1 + plci->fax_connect_info_buffer[pos]; i != 0; i--)
  7774. nlc[++len] = plci->fax_connect_info_buffer[pos++];
  7775. }
  7776. else
  7777. nlc[++len] = 0;
  7778. if (pos < plci->fax_connect_info_length)
  7779. {
  7780. for (i = 1 + plci->fax_connect_info_buffer[pos]; i != 0; i--)
  7781. nlc[++len] = plci->fax_connect_info_buffer[pos++];
  7782. }
  7783. else
  7784. nlc[++len] = 0;
  7785. if ((plci->requested_options_conn | plci->requested_options | plci->adapter->requested_options_table[plci->appl->Id - 1])
  7786. & (1L << PRIVATE_FAX_NONSTANDARD))
  7787. {
  7788. if ((pos < plci->fax_connect_info_length) && (plci->fax_connect_info_buffer[pos] != 0))
  7789. {
  7790. if ((plci->fax_connect_info_buffer[pos] >= 3) && (plci->fax_connect_info_buffer[pos + 1] >= 2))
  7791. plci->nsf_control_bits = GET_WORD(&plci->fax_connect_info_buffer[pos + 2]);
  7792. for (i = 1 + plci->fax_connect_info_buffer[pos]; i != 0; i--)
  7793. nlc[++len] = plci->fax_connect_info_buffer[pos++];
  7794. }
  7795. else
  7796. {
  7797. if (api_parse(&b3_config->info[1], (word)b3_config->length, "wwsss", b3_config_parms))
  7798. {
  7799. dbug(1, dprintf("non-standard facilities info missing or wrong format"));
  7800. nlc[++len] = 0;
  7801. }
  7802. else
  7803. {
  7804. if ((b3_config_parms[4].length >= 3) && (b3_config_parms[4].info[1] >= 2))
  7805. plci->nsf_control_bits = GET_WORD(&b3_config_parms[4].info[2]);
  7806. nlc[++len] = (byte)(b3_config_parms[4].length);
  7807. for (i = 0; i < b3_config_parms[4].length; i++)
  7808. nlc[++len] = b3_config_parms[4].info[1 + i];
  7809. }
  7810. }
  7811. }
  7812. nlc[0] = len;
  7813. if ((plci->nsf_control_bits & T30_NSF_CONTROL_BIT_ENABLE_NSF)
  7814. && (plci->nsf_control_bits & T30_NSF_CONTROL_BIT_NEGOTIATE_RESP))
  7815. {
  7816. ((T30_INFO *)&nlc[1])->operating_mode = T30_OPERATING_MODE_CAPI_NEG;
  7817. }
  7818. }
  7819. }
  7820. PUT_WORD(&(((T30_INFO *)&nlc[1])->control_bits_low), fax_control_bits);
  7821. len = offsetof(T30_INFO, station_id) + T30_MAX_STATION_ID_LENGTH;
  7822. for (i = 0; i < len; i++)
  7823. plci->fax_connect_info_buffer[i] = nlc[1 + i];
  7824. ((T30_INFO *) plci->fax_connect_info_buffer)->head_line_len = 0;
  7825. i += ((T30_INFO *)&nlc[1])->head_line_len;
  7826. while (i < nlc[0])
  7827. plci->fax_connect_info_buffer[len++] = nlc[++i];
  7828. plci->fax_connect_info_length = len;
  7829. }
  7830. else
  7831. {
  7832. nlc[0] = 14;
  7833. if (b3_config->length != 16)
  7834. return _B3_PARM_NOT_SUPPORTED;
  7835. for (i = 0; i < 12; i++) nlc[1 + i] = b3_config->info[1 + i];
  7836. if (GET_WORD(&b3_config->info[13]) != 8 && GET_WORD(&b3_config->info[13]) != 128)
  7837. return _B3_PARM_NOT_SUPPORTED;
  7838. nlc[13] = b3_config->info[13];
  7839. if (GET_WORD(&b3_config->info[15]) >= nlc[13])
  7840. return _B3_PARM_NOT_SUPPORTED;
  7841. nlc[14] = b3_config->info[15];
  7842. }
  7843. }
  7844. else
  7845. {
  7846. if (plci->B3_prot == 4
  7847. || plci->B3_prot == 5 /*T.30 - FAX*/) return _B3_PARM_NOT_SUPPORTED;
  7848. }
  7849. add_p(plci, NLC, nlc);
  7850. return 0;
  7851. }
  7852. /*----------------------------------------------------------------*/
  7853. /* make the same as add_b23, but only for the modem related */
  7854. /* L2 and L3 B-Chan protocol. */
  7855. /* */
  7856. /* Enabled L2 and L3 Configurations: */
  7857. /* If L1 == Modem all negotiation */
  7858. /* only L2 == Modem with full negotiation is allowed */
  7859. /* If L1 == Modem async or sync */
  7860. /* only L2 == Transparent is allowed */
  7861. /* L3 == Modem or L3 == Transparent are allowed */
  7862. /* B2 Configuration for modem: */
  7863. /* word : enable/disable compression, bitoptions */
  7864. /* B3 Configuration for modem: */
  7865. /* empty */
  7866. /*----------------------------------------------------------------*/
  7867. static word add_modem_b23(PLCI *plci, API_PARSE *bp_parms)
  7868. {
  7869. static byte lli[12] = {1,1};
  7870. static byte llc[3] = {2,0,0};
  7871. static byte dlc[16] = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
  7872. API_PARSE mdm_config[2];
  7873. word i;
  7874. word b2_config = 0;
  7875. for (i = 0; i < 2; i++) mdm_config[i].length = 0;
  7876. for (i = 0; i < sizeof(dlc); i++) dlc[i] = 0;
  7877. if (((GET_WORD(bp_parms[0].info) == B1_MODEM_ALL_NEGOTIATE)
  7878. && (GET_WORD(bp_parms[1].info) != B2_MODEM_EC_COMPRESSION))
  7879. || ((GET_WORD(bp_parms[0].info) != B1_MODEM_ALL_NEGOTIATE)
  7880. && (GET_WORD(bp_parms[1].info) != B2_TRANSPARENT)))
  7881. {
  7882. return (_B_STACK_NOT_SUPPORTED);
  7883. }
  7884. if ((GET_WORD(bp_parms[2].info) != B3_MODEM)
  7885. && (GET_WORD(bp_parms[2].info) != B3_TRANSPARENT))
  7886. {
  7887. return (_B_STACK_NOT_SUPPORTED);
  7888. }
  7889. plci->B2_prot = (byte) GET_WORD(bp_parms[1].info);
  7890. plci->B3_prot = (byte) GET_WORD(bp_parms[2].info);
  7891. if ((GET_WORD(bp_parms[1].info) == B2_MODEM_EC_COMPRESSION) && bp_parms[4].length)
  7892. {
  7893. if (api_parse(&bp_parms[4].info[1],
  7894. (word)bp_parms[4].length, "w",
  7895. mdm_config))
  7896. {
  7897. return (_WRONG_MESSAGE_FORMAT);
  7898. }
  7899. b2_config = GET_WORD(mdm_config[0].info);
  7900. }
  7901. /* OK, L2 is modem */
  7902. lli[0] = 1;
  7903. lli[1] = 1;
  7904. if (plci->adapter->manufacturer_features & MANUFACTURER_FEATURE_XONOFF_FLOW_CONTROL)
  7905. lli[1] |= 2;
  7906. if (plci->adapter->manufacturer_features & MANUFACTURER_FEATURE_OOB_CHANNEL)
  7907. lli[1] |= 4;
  7908. if ((lli[1] & 0x02) && (diva_xdi_extended_features & DIVA_CAPI_USE_CMA)) {
  7909. lli[1] |= 0x10;
  7910. if (plci->rx_dma_descriptor <= 0) {
  7911. plci->rx_dma_descriptor = diva_get_dma_descriptor(plci, &plci->rx_dma_magic);
  7912. if (plci->rx_dma_descriptor >= 0)
  7913. plci->rx_dma_descriptor++;
  7914. }
  7915. if (plci->rx_dma_descriptor > 0) {
  7916. lli[1] |= 0x40;
  7917. lli[0] = 6;
  7918. lli[2] = (byte)(plci->rx_dma_descriptor - 1);
  7919. lli[3] = (byte)plci->rx_dma_magic;
  7920. lli[4] = (byte)(plci->rx_dma_magic >> 8);
  7921. lli[5] = (byte)(plci->rx_dma_magic >> 16);
  7922. lli[6] = (byte)(plci->rx_dma_magic >> 24);
  7923. }
  7924. }
  7925. if (DIVA_CAPI_SUPPORTS_NO_CANCEL(plci->adapter)) {
  7926. lli[1] |= 0x20;
  7927. }
  7928. llc[1] = (plci->call_dir & (CALL_DIR_ORIGINATE | CALL_DIR_FORCE_OUTG_NL)) ?
  7929. /*V42*/ 10 : /*V42_IN*/ 9;
  7930. llc[2] = 4; /* pass L3 always transparent */
  7931. add_p(plci, LLI, lli);
  7932. add_p(plci, LLC, llc);
  7933. i = 1;
  7934. PUT_WORD(&dlc[i], plci->appl->MaxDataLength);
  7935. i += 2;
  7936. if (GET_WORD(bp_parms[1].info) == B2_MODEM_EC_COMPRESSION)
  7937. {
  7938. if (bp_parms[4].length)
  7939. {
  7940. dbug(1, dprintf("MDM b2_config=%02x", b2_config));
  7941. dlc[i++] = 3; /* Addr A */
  7942. dlc[i++] = 1; /* Addr B */
  7943. dlc[i++] = 7; /* modulo mode */
  7944. dlc[i++] = 7; /* window size */
  7945. dlc[i++] = 0; /* XID len Lo */
  7946. dlc[i++] = 0; /* XID len Hi */
  7947. if (b2_config & MDM_B2_DISABLE_V42bis)
  7948. {
  7949. dlc[i] |= DLC_MODEMPROT_DISABLE_V42_V42BIS;
  7950. }
  7951. if (b2_config & MDM_B2_DISABLE_MNP)
  7952. {
  7953. dlc[i] |= DLC_MODEMPROT_DISABLE_MNP_MNP5;
  7954. }
  7955. if (b2_config & MDM_B2_DISABLE_TRANS)
  7956. {
  7957. dlc[i] |= DLC_MODEMPROT_REQUIRE_PROTOCOL;
  7958. }
  7959. if (b2_config & MDM_B2_DISABLE_V42)
  7960. {
  7961. dlc[i] |= DLC_MODEMPROT_DISABLE_V42_DETECT;
  7962. }
  7963. if (b2_config & MDM_B2_DISABLE_COMP)
  7964. {
  7965. dlc[i] |= DLC_MODEMPROT_DISABLE_COMPRESSION;
  7966. }
  7967. i++;
  7968. }
  7969. }
  7970. else
  7971. {
  7972. dlc[i++] = 3; /* Addr A */
  7973. dlc[i++] = 1; /* Addr B */
  7974. dlc[i++] = 7; /* modulo mode */
  7975. dlc[i++] = 7; /* window size */
  7976. dlc[i++] = 0; /* XID len Lo */
  7977. dlc[i++] = 0; /* XID len Hi */
  7978. dlc[i++] = DLC_MODEMPROT_DISABLE_V42_V42BIS |
  7979. DLC_MODEMPROT_DISABLE_MNP_MNP5 |
  7980. DLC_MODEMPROT_DISABLE_V42_DETECT |
  7981. DLC_MODEMPROT_DISABLE_COMPRESSION;
  7982. }
  7983. dlc[0] = (byte)(i - 1);
  7984. /* HexDump ("DLC", sizeof(dlc), &dlc[0]); */
  7985. add_p(plci, DLC, dlc);
  7986. return (0);
  7987. }
  7988. /*------------------------------------------------------------------*/
  7989. /* send a request for the signaling entity */
  7990. /*------------------------------------------------------------------*/
  7991. static void sig_req(PLCI *plci, byte req, byte Id)
  7992. {
  7993. if (!plci) return;
  7994. if (plci->adapter->adapter_disabled) return;
  7995. dbug(1, dprintf("sig_req(%x)", req));
  7996. if (req == REMOVE)
  7997. plci->sig_remove_id = plci->Sig.Id;
  7998. if (plci->req_in == plci->req_in_start) {
  7999. plci->req_in += 2;
  8000. plci->RBuffer[plci->req_in++] = 0;
  8001. }
  8002. PUT_WORD(&plci->RBuffer[plci->req_in_start], plci->req_in-plci->req_in_start - 2);
  8003. plci->RBuffer[plci->req_in++] = Id; /* sig/nl flag */
  8004. plci->RBuffer[plci->req_in++] = req; /* request */
  8005. plci->RBuffer[plci->req_in++] = 0; /* channel */
  8006. plci->req_in_start = plci->req_in;
  8007. }
  8008. /*------------------------------------------------------------------*/
  8009. /* send a request for the network layer entity */
  8010. /*------------------------------------------------------------------*/
  8011. static void nl_req_ncci(PLCI *plci, byte req, byte ncci)
  8012. {
  8013. if (!plci) return;
  8014. if (plci->adapter->adapter_disabled) return;
  8015. dbug(1, dprintf("nl_req %02x %02x %02x", plci->Id, req, ncci));
  8016. if (req == REMOVE)
  8017. {
  8018. plci->nl_remove_id = plci->NL.Id;
  8019. ncci_remove(plci, 0, (byte)(ncci != 0));
  8020. ncci = 0;
  8021. }
  8022. if (plci->req_in == plci->req_in_start) {
  8023. plci->req_in += 2;
  8024. plci->RBuffer[plci->req_in++] = 0;
  8025. }
  8026. PUT_WORD(&plci->RBuffer[plci->req_in_start], plci->req_in-plci->req_in_start - 2);
  8027. plci->RBuffer[plci->req_in++] = 1; /* sig/nl flag */
  8028. plci->RBuffer[plci->req_in++] = req; /* request */
  8029. plci->RBuffer[plci->req_in++] = plci->adapter->ncci_ch[ncci]; /* channel */
  8030. plci->req_in_start = plci->req_in;
  8031. }
  8032. static void send_req(PLCI *plci)
  8033. {
  8034. ENTITY *e;
  8035. word l;
  8036. /* word i; */
  8037. if (!plci) return;
  8038. if (plci->adapter->adapter_disabled) return;
  8039. channel_xmit_xon(plci);
  8040. /* if nothing to do, return */
  8041. if (plci->req_in == plci->req_out) return;
  8042. dbug(1, dprintf("send_req(in=%d,out=%d)", plci->req_in, plci->req_out));
  8043. if (plci->nl_req || plci->sig_req) return;
  8044. l = GET_WORD(&plci->RBuffer[plci->req_out]);
  8045. plci->req_out += 2;
  8046. plci->XData[0].P = &plci->RBuffer[plci->req_out];
  8047. plci->req_out += l;
  8048. if (plci->RBuffer[plci->req_out] == 1)
  8049. {
  8050. e = &plci->NL;
  8051. plci->req_out++;
  8052. e->Req = plci->nl_req = plci->RBuffer[plci->req_out++];
  8053. e->ReqCh = plci->RBuffer[plci->req_out++];
  8054. if (!(e->Id & 0x1f))
  8055. {
  8056. e->Id = NL_ID;
  8057. plci->RBuffer[plci->req_out - 4] = CAI;
  8058. plci->RBuffer[plci->req_out - 3] = 1;
  8059. plci->RBuffer[plci->req_out - 2] = (plci->Sig.Id == 0xff) ? 0 : plci->Sig.Id;
  8060. plci->RBuffer[plci->req_out - 1] = 0;
  8061. l += 3;
  8062. plci->nl_global_req = plci->nl_req;
  8063. }
  8064. dbug(1, dprintf("%x:NLREQ(%x:%x:%x)", plci->adapter->Id, e->Id, e->Req, e->ReqCh));
  8065. }
  8066. else
  8067. {
  8068. e = &plci->Sig;
  8069. if (plci->RBuffer[plci->req_out])
  8070. e->Id = plci->RBuffer[plci->req_out];
  8071. plci->req_out++;
  8072. e->Req = plci->sig_req = plci->RBuffer[plci->req_out++];
  8073. e->ReqCh = plci->RBuffer[plci->req_out++];
  8074. if (!(e->Id & 0x1f))
  8075. plci->sig_global_req = plci->sig_req;
  8076. dbug(1, dprintf("%x:SIGREQ(%x:%x:%x)", plci->adapter->Id, e->Id, e->Req, e->ReqCh));
  8077. }
  8078. plci->XData[0].PLength = l;
  8079. e->X = plci->XData;
  8080. plci->adapter->request(e);
  8081. dbug(1, dprintf("send_ok"));
  8082. }
  8083. static void send_data(PLCI *plci)
  8084. {
  8085. DIVA_CAPI_ADAPTER *a;
  8086. DATA_B3_DESC *data;
  8087. NCCI *ncci_ptr;
  8088. word ncci;
  8089. if (!plci->nl_req && plci->ncci_ring_list)
  8090. {
  8091. a = plci->adapter;
  8092. ncci = plci->ncci_ring_list;
  8093. do
  8094. {
  8095. ncci = a->ncci_next[ncci];
  8096. ncci_ptr = &(a->ncci[ncci]);
  8097. if (!(a->ncci_ch[ncci]
  8098. && (a->ch_flow_control[a->ncci_ch[ncci]] & N_OK_FC_PENDING)))
  8099. {
  8100. if (ncci_ptr->data_pending)
  8101. {
  8102. if ((a->ncci_state[ncci] == CONNECTED)
  8103. || (a->ncci_state[ncci] == INC_ACT_PENDING)
  8104. || (plci->send_disc == ncci))
  8105. {
  8106. data = &(ncci_ptr->DBuffer[ncci_ptr->data_out]);
  8107. if ((plci->B2_prot == B2_V120_ASYNC)
  8108. || (plci->B2_prot == B2_V120_ASYNC_V42BIS)
  8109. || (plci->B2_prot == B2_V120_BIT_TRANSPARENT))
  8110. {
  8111. plci->NData[1].P = TransmitBufferGet(plci->appl, data->P);
  8112. plci->NData[1].PLength = data->Length;
  8113. if (data->Flags & 0x10)
  8114. plci->NData[0].P = v120_break_header;
  8115. else
  8116. plci->NData[0].P = v120_default_header;
  8117. plci->NData[0].PLength = 1;
  8118. plci->NL.XNum = 2;
  8119. plci->NL.Req = plci->nl_req = (byte)((data->Flags & 0x07) << 4 | N_DATA);
  8120. }
  8121. else
  8122. {
  8123. plci->NData[0].P = TransmitBufferGet(plci->appl, data->P);
  8124. plci->NData[0].PLength = data->Length;
  8125. if (data->Flags & 0x10)
  8126. plci->NL.Req = plci->nl_req = (byte)N_UDATA;
  8127. else if ((plci->B3_prot == B3_RTP) && (data->Flags & 0x01))
  8128. plci->NL.Req = plci->nl_req = (byte)N_BDATA;
  8129. else
  8130. plci->NL.Req = plci->nl_req = (byte)((data->Flags & 0x07) << 4 | N_DATA);
  8131. }
  8132. plci->NL.X = plci->NData;
  8133. plci->NL.ReqCh = a->ncci_ch[ncci];
  8134. dbug(1, dprintf("%x:DREQ(%x:%x)", a->Id, plci->NL.Id, plci->NL.Req));
  8135. plci->data_sent = true;
  8136. plci->data_sent_ptr = data->P;
  8137. a->request(&plci->NL);
  8138. }
  8139. else {
  8140. cleanup_ncci_data(plci, ncci);
  8141. }
  8142. }
  8143. else if (plci->send_disc == ncci)
  8144. {
  8145. /* dprintf("N_DISC"); */
  8146. plci->NData[0].PLength = 0;
  8147. plci->NL.ReqCh = a->ncci_ch[ncci];
  8148. plci->NL.Req = plci->nl_req = N_DISC;
  8149. a->request(&plci->NL);
  8150. plci->command = _DISCONNECT_B3_R;
  8151. plci->send_disc = 0;
  8152. }
  8153. }
  8154. } while (!plci->nl_req && (ncci != plci->ncci_ring_list));
  8155. plci->ncci_ring_list = ncci;
  8156. }
  8157. }
  8158. static void listen_check(DIVA_CAPI_ADAPTER *a)
  8159. {
  8160. word i, j;
  8161. PLCI *plci;
  8162. byte activnotifiedcalls = 0;
  8163. dbug(1, dprintf("listen_check(%d,%d)", a->listen_active, a->max_listen));
  8164. if (!remove_started && !a->adapter_disabled)
  8165. {
  8166. for (i = 0; i < a->max_plci; i++)
  8167. {
  8168. plci = &(a->plci[i]);
  8169. if (plci->notifiedcall) activnotifiedcalls++;
  8170. }
  8171. dbug(1, dprintf("listen_check(%d)", activnotifiedcalls));
  8172. for (i = a->listen_active; i < ((word)(a->max_listen + activnotifiedcalls)); i++) {
  8173. if ((j = get_plci(a))) {
  8174. a->listen_active++;
  8175. plci = &a->plci[j - 1];
  8176. plci->State = LISTENING;
  8177. add_p(plci, OAD, "\x01\xfd");
  8178. add_p(plci, KEY, "\x04\x43\x41\x32\x30");
  8179. add_p(plci, CAI, "\x01\xc0");
  8180. add_p(plci, UID, "\x06\x43\x61\x70\x69\x32\x30");
  8181. add_p(plci, LLI, "\x01\xc4"); /* support Dummy CR FAC + MWI + SpoofNotify */
  8182. add_p(plci, SHIFT | 6, NULL);
  8183. add_p(plci, SIN, "\x02\x00\x00");
  8184. plci->internal_command = LISTEN_SIG_ASSIGN_PEND; /* do indicate_req if OK */
  8185. sig_req(plci, ASSIGN, DSIG_ID);
  8186. send_req(plci);
  8187. }
  8188. }
  8189. }
  8190. }
  8191. /*------------------------------------------------------------------*/
  8192. /* functions for all parameters sent in INDs */
  8193. /*------------------------------------------------------------------*/
  8194. static void IndParse(PLCI *plci, word *parms_id, byte **parms, byte multiIEsize)
  8195. {
  8196. word ploc; /* points to current location within packet */
  8197. byte w;
  8198. byte wlen;
  8199. byte codeset, lock;
  8200. byte *in;
  8201. word i;
  8202. word code;
  8203. word mIEindex = 0;
  8204. ploc = 0;
  8205. codeset = 0;
  8206. lock = 0;
  8207. in = plci->Sig.RBuffer->P;
  8208. for (i = 0; i < parms_id[0]; i++) /* multiIE parms_id contains just the 1st */
  8209. { /* element but parms array is larger */
  8210. parms[i] = (byte *)"";
  8211. }
  8212. for (i = 0; i < multiIEsize; i++)
  8213. {
  8214. parms[i] = (byte *)"";
  8215. }
  8216. while (ploc < plci->Sig.RBuffer->length - 1) {
  8217. /* read information element id and length */
  8218. w = in[ploc];
  8219. if (w & 0x80) {
  8220. /* w &=0xf0; removed, cannot detect congestion levels */
  8221. /* upper 4 bit masked with w==SHIFT now */
  8222. wlen = 0;
  8223. }
  8224. else {
  8225. wlen = (byte)(in[ploc + 1] + 1);
  8226. }
  8227. /* check if length valid (not exceeding end of packet) */
  8228. if ((ploc + wlen) > 270) return;
  8229. if (lock & 0x80) lock &= 0x7f;
  8230. else codeset = lock;
  8231. if ((w & 0xf0) == SHIFT) {
  8232. codeset = in[ploc];
  8233. if (!(codeset & 0x08)) lock = (byte)(codeset & 7);
  8234. codeset &= 7;
  8235. lock |= 0x80;
  8236. }
  8237. else {
  8238. if (w == ESC && wlen >= 3) code = in[ploc + 2] | 0x800;
  8239. else code = w;
  8240. code |= (codeset << 8);
  8241. for (i = 1; i < parms_id[0] + 1 && parms_id[i] != code; i++);
  8242. if (i < parms_id[0] + 1) {
  8243. if (!multiIEsize) { /* with multiIEs use next field index, */
  8244. mIEindex = i - 1; /* with normal IEs use same index like parms_id */
  8245. }
  8246. parms[mIEindex] = &in[ploc + 1];
  8247. dbug(1, dprintf("mIE[%d]=0x%x", *parms[mIEindex], in[ploc]));
  8248. if (parms_id[i] == OAD
  8249. || parms_id[i] == CONN_NR
  8250. || parms_id[i] == CAD) {
  8251. if (in[ploc + 2] & 0x80) {
  8252. in[ploc + 0] = (byte)(in[ploc + 1] + 1);
  8253. in[ploc + 1] = (byte)(in[ploc + 2] & 0x7f);
  8254. in[ploc + 2] = 0x80;
  8255. parms[mIEindex] = &in[ploc];
  8256. }
  8257. }
  8258. mIEindex++; /* effects multiIEs only */
  8259. }
  8260. }
  8261. ploc += (wlen + 1);
  8262. }
  8263. return;
  8264. }
  8265. /*------------------------------------------------------------------*/
  8266. /* try to match a cip from received BC and HLC */
  8267. /*------------------------------------------------------------------*/
  8268. static byte ie_compare(byte *ie1, byte *ie2)
  8269. {
  8270. word i;
  8271. if (!ie1 || !ie2) return false;
  8272. if (!ie1[0]) return false;
  8273. for (i = 0; i < (word)(ie1[0] + 1); i++) if (ie1[i] != ie2[i]) return false;
  8274. return true;
  8275. }
  8276. static word find_cip(DIVA_CAPI_ADAPTER *a, byte *bc, byte *hlc)
  8277. {
  8278. word i;
  8279. word j;
  8280. for (i = 9; i && !ie_compare(bc, cip_bc[i][a->u_law]); i--);
  8281. for (j = 16; j < 29 &&
  8282. (!ie_compare(bc, cip_bc[j][a->u_law]) || !ie_compare(hlc, cip_hlc[j])); j++);
  8283. if (j == 29) return i;
  8284. return j;
  8285. }
  8286. static byte AddInfo(byte **add_i,
  8287. byte **fty_i,
  8288. byte *esc_chi,
  8289. byte *facility)
  8290. {
  8291. byte i;
  8292. byte j;
  8293. byte k;
  8294. byte flen;
  8295. byte len = 0;
  8296. /* facility is a nested structure */
  8297. /* FTY can be more than once */
  8298. if (esc_chi[0] && !(esc_chi[esc_chi[0]] & 0x7f))
  8299. {
  8300. add_i[0] = (byte *)"\x02\x02\x00"; /* use neither b nor d channel */
  8301. }
  8302. else
  8303. {
  8304. add_i[0] = (byte *)"";
  8305. }
  8306. if (!fty_i[0][0])
  8307. {
  8308. add_i[3] = (byte *)"";
  8309. }
  8310. else
  8311. { /* facility array found */
  8312. for (i = 0, j = 1; i < MAX_MULTI_IE && fty_i[i][0]; i++)
  8313. {
  8314. dbug(1, dprintf("AddIFac[%d]", fty_i[i][0]));
  8315. len += fty_i[i][0];
  8316. len += 2;
  8317. flen = fty_i[i][0];
  8318. facility[j++] = 0x1c; /* copy fac IE */
  8319. for (k = 0; k <= flen; k++, j++)
  8320. {
  8321. facility[j] = fty_i[i][k];
  8322. /* dbug(1, dprintf("%x ",facility[j])); */
  8323. }
  8324. }
  8325. facility[0] = len;
  8326. add_i[3] = facility;
  8327. }
  8328. /* dbug(1, dprintf("FacArrLen=%d ",len)); */
  8329. len = add_i[0][0] + add_i[1][0] + add_i[2][0] + add_i[3][0];
  8330. len += 4; /* calculate length of all */
  8331. return (len);
  8332. }
  8333. /*------------------------------------------------------------------*/
  8334. /* voice and codec features */
  8335. /*------------------------------------------------------------------*/
  8336. static void SetVoiceChannel(PLCI *plci, byte *chi, DIVA_CAPI_ADAPTER *a)
  8337. {
  8338. byte voice_chi[] = "\x02\x18\x01";
  8339. byte channel;
  8340. channel = chi[chi[0]] & 0x3;
  8341. dbug(1, dprintf("ExtDevON(Ch=0x%x)", channel));
  8342. voice_chi[2] = (channel) ? channel : 1;
  8343. add_p(plci, FTY, "\x02\x01\x07"); /* B On, default on 1 */
  8344. add_p(plci, ESC, voice_chi); /* Channel */
  8345. sig_req(plci, TEL_CTRL, 0);
  8346. send_req(plci);
  8347. if (a->AdvSignalPLCI)
  8348. {
  8349. adv_voice_write_coefs(a->AdvSignalPLCI, ADV_VOICE_WRITE_ACTIVATION);
  8350. }
  8351. }
  8352. static void VoiceChannelOff(PLCI *plci)
  8353. {
  8354. dbug(1, dprintf("ExtDevOFF"));
  8355. add_p(plci, FTY, "\x02\x01\x08"); /* B Off */
  8356. sig_req(plci, TEL_CTRL, 0);
  8357. send_req(plci);
  8358. if (plci->adapter->AdvSignalPLCI)
  8359. {
  8360. adv_voice_clear_config(plci->adapter->AdvSignalPLCI);
  8361. }
  8362. }
  8363. static word AdvCodecSupport(DIVA_CAPI_ADAPTER *a, PLCI *plci, APPL *appl,
  8364. byte hook_listen)
  8365. {
  8366. word j;
  8367. PLCI *splci;
  8368. /* check if hardware supports handset with hook states (adv.codec) */
  8369. /* or if just a on board codec is supported */
  8370. /* the advanced codec plci is just for internal use */
  8371. /* diva Pro with on-board codec: */
  8372. if (a->profile.Global_Options & HANDSET)
  8373. {
  8374. /* new call, but hook states are already signalled */
  8375. if (a->AdvCodecFLAG)
  8376. {
  8377. if (a->AdvSignalAppl != appl || a->AdvSignalPLCI)
  8378. {
  8379. dbug(1, dprintf("AdvSigPlci=0x%x", a->AdvSignalPLCI));
  8380. return 0x2001; /* codec in use by another application */
  8381. }
  8382. if (plci != NULL)
  8383. {
  8384. a->AdvSignalPLCI = plci;
  8385. plci->tel = ADV_VOICE;
  8386. }
  8387. return 0; /* adv codec still used */
  8388. }
  8389. if ((j = get_plci(a)))
  8390. {
  8391. splci = &a->plci[j - 1];
  8392. splci->tel = CODEC_PERMANENT;
  8393. /* hook_listen indicates if a facility_req with handset/hook support */
  8394. /* was sent. Otherwise if just a call on an external device was made */
  8395. /* the codec will be used but the hook info will be discarded (just */
  8396. /* the external controller is in use */
  8397. if (hook_listen) splci->State = ADVANCED_VOICE_SIG;
  8398. else
  8399. {
  8400. splci->State = ADVANCED_VOICE_NOSIG;
  8401. if (plci)
  8402. {
  8403. plci->spoofed_msg = SPOOFING_REQUIRED;
  8404. }
  8405. /* indicate D-ch connect if */
  8406. } /* codec is connected OK */
  8407. if (plci != NULL)
  8408. {
  8409. a->AdvSignalPLCI = plci;
  8410. plci->tel = ADV_VOICE;
  8411. }
  8412. a->AdvSignalAppl = appl;
  8413. a->AdvCodecFLAG = true;
  8414. a->AdvCodecPLCI = splci;
  8415. add_p(splci, CAI, "\x01\x15");
  8416. add_p(splci, LLI, "\x01\x00");
  8417. add_p(splci, ESC, "\x02\x18\x00");
  8418. add_p(splci, UID, "\x06\x43\x61\x70\x69\x32\x30");
  8419. splci->internal_command = PERM_COD_ASSIGN;
  8420. dbug(1, dprintf("Codec Assign"));
  8421. sig_req(splci, ASSIGN, DSIG_ID);
  8422. send_req(splci);
  8423. }
  8424. else
  8425. {
  8426. return 0x2001; /* wrong state, no more plcis */
  8427. }
  8428. }
  8429. else if (a->profile.Global_Options & ON_BOARD_CODEC)
  8430. {
  8431. if (hook_listen) return 0x300B; /* Facility not supported */
  8432. /* no hook with SCOM */
  8433. if (plci != NULL) plci->tel = CODEC;
  8434. dbug(1, dprintf("S/SCOM codec"));
  8435. /* first time we use the scom-s codec we must shut down the internal */
  8436. /* handset application of the card. This can be done by an assign with */
  8437. /* a cai with the 0x80 bit set. Assign return code is 'out of resource'*/
  8438. if (!a->scom_appl_disable) {
  8439. if ((j = get_plci(a))) {
  8440. splci = &a->plci[j - 1];
  8441. add_p(splci, CAI, "\x01\x80");
  8442. add_p(splci, UID, "\x06\x43\x61\x70\x69\x32\x30");
  8443. sig_req(splci, ASSIGN, 0xC0); /* 0xc0 is the TEL_ID */
  8444. send_req(splci);
  8445. a->scom_appl_disable = true;
  8446. }
  8447. else{
  8448. return 0x2001; /* wrong state, no more plcis */
  8449. }
  8450. }
  8451. }
  8452. else return 0x300B; /* Facility not supported */
  8453. return 0;
  8454. }
  8455. static void CodecIdCheck(DIVA_CAPI_ADAPTER *a, PLCI *plci)
  8456. {
  8457. dbug(1, dprintf("CodecIdCheck"));
  8458. if (a->AdvSignalPLCI == plci)
  8459. {
  8460. dbug(1, dprintf("PLCI owns codec"));
  8461. VoiceChannelOff(a->AdvCodecPLCI);
  8462. if (a->AdvCodecPLCI->State == ADVANCED_VOICE_NOSIG)
  8463. {
  8464. dbug(1, dprintf("remove temp codec PLCI"));
  8465. plci_remove(a->AdvCodecPLCI);
  8466. a->AdvCodecFLAG = 0;
  8467. a->AdvCodecPLCI = NULL;
  8468. a->AdvSignalAppl = NULL;
  8469. }
  8470. a->AdvSignalPLCI = NULL;
  8471. }
  8472. }
  8473. /* -------------------------------------------------------------------
  8474. Ask for physical address of card on PCI bus
  8475. ------------------------------------------------------------------- */
  8476. static void diva_ask_for_xdi_sdram_bar(DIVA_CAPI_ADAPTER *a,
  8477. IDI_SYNC_REQ *preq) {
  8478. a->sdram_bar = 0;
  8479. if (diva_xdi_extended_features & DIVA_CAPI_XDI_PROVIDES_SDRAM_BAR) {
  8480. ENTITY *e = (ENTITY *)preq;
  8481. e->user[0] = a->Id - 1;
  8482. preq->xdi_sdram_bar.info.bar = 0;
  8483. preq->xdi_sdram_bar.Req = 0;
  8484. preq->xdi_sdram_bar.Rc = IDI_SYNC_REQ_XDI_GET_ADAPTER_SDRAM_BAR;
  8485. (*(a->request))(e);
  8486. a->sdram_bar = preq->xdi_sdram_bar.info.bar;
  8487. dbug(3, dprintf("A(%d) SDRAM BAR = %08x", a->Id, a->sdram_bar));
  8488. }
  8489. }
  8490. /* -------------------------------------------------------------------
  8491. Ask XDI about extended features
  8492. ------------------------------------------------------------------- */
  8493. static void diva_get_extended_adapter_features(DIVA_CAPI_ADAPTER *a) {
  8494. IDI_SYNC_REQ *preq;
  8495. char buffer[((sizeof(preq->xdi_extended_features) + 4) > sizeof(ENTITY)) ? (sizeof(preq->xdi_extended_features) + 4) : sizeof(ENTITY)];
  8496. char features[4];
  8497. preq = (IDI_SYNC_REQ *)&buffer[0];
  8498. if (!diva_xdi_extended_features) {
  8499. ENTITY *e = (ENTITY *)preq;
  8500. diva_xdi_extended_features |= 0x80000000;
  8501. e->user[0] = a->Id - 1;
  8502. preq->xdi_extended_features.Req = 0;
  8503. preq->xdi_extended_features.Rc = IDI_SYNC_REQ_XDI_GET_EXTENDED_FEATURES;
  8504. preq->xdi_extended_features.info.buffer_length_in_bytes = sizeof(features);
  8505. preq->xdi_extended_features.info.features = &features[0];
  8506. (*(a->request))(e);
  8507. if (features[0] & DIVA_XDI_EXTENDED_FEATURES_VALID) {
  8508. /*
  8509. Check features located in the byte '0'
  8510. */
  8511. if (features[0] & DIVA_XDI_EXTENDED_FEATURE_CMA) {
  8512. diva_xdi_extended_features |= DIVA_CAPI_USE_CMA;
  8513. }
  8514. if (features[0] & DIVA_XDI_EXTENDED_FEATURE_RX_DMA) {
  8515. diva_xdi_extended_features |= DIVA_CAPI_XDI_PROVIDES_RX_DMA;
  8516. dbug(1, dprintf("XDI provides RxDMA"));
  8517. }
  8518. if (features[0] & DIVA_XDI_EXTENDED_FEATURE_SDRAM_BAR) {
  8519. diva_xdi_extended_features |= DIVA_CAPI_XDI_PROVIDES_SDRAM_BAR;
  8520. }
  8521. if (features[0] & DIVA_XDI_EXTENDED_FEATURE_NO_CANCEL_RC) {
  8522. diva_xdi_extended_features |= DIVA_CAPI_XDI_PROVIDES_NO_CANCEL;
  8523. dbug(3, dprintf("XDI provides NO_CANCEL_RC feature"));
  8524. }
  8525. }
  8526. }
  8527. diva_ask_for_xdi_sdram_bar(a, preq);
  8528. }
  8529. /*------------------------------------------------------------------*/
  8530. /* automatic law */
  8531. /*------------------------------------------------------------------*/
  8532. /* called from OS specific part after init time to get the Law */
  8533. /* a-law (Euro) and u-law (us,japan) use different BCs in the Setup message */
  8534. void AutomaticLaw(DIVA_CAPI_ADAPTER *a)
  8535. {
  8536. word j;
  8537. PLCI *splci;
  8538. if (a->automatic_law) {
  8539. return;
  8540. }
  8541. if ((j = get_plci(a))) {
  8542. diva_get_extended_adapter_features(a);
  8543. splci = &a->plci[j - 1];
  8544. a->automatic_lawPLCI = splci;
  8545. a->automatic_law = 1;
  8546. add_p(splci, CAI, "\x01\x80");
  8547. add_p(splci, UID, "\x06\x43\x61\x70\x69\x32\x30");
  8548. splci->internal_command = USELAW_REQ;
  8549. splci->command = 0;
  8550. splci->number = 0;
  8551. sig_req(splci, ASSIGN, DSIG_ID);
  8552. send_req(splci);
  8553. }
  8554. }
  8555. /* called from OS specific part if an application sends an Capi20Release */
  8556. word CapiRelease(word Id)
  8557. {
  8558. word i, j, appls_found;
  8559. PLCI *plci;
  8560. APPL *this;
  8561. DIVA_CAPI_ADAPTER *a;
  8562. if (!Id)
  8563. {
  8564. dbug(0, dprintf("A: CapiRelease(Id==0)"));
  8565. return (_WRONG_APPL_ID);
  8566. }
  8567. this = &application[Id - 1]; /* get application pointer */
  8568. for (i = 0, appls_found = 0; i < max_appl; i++)
  8569. {
  8570. if (application[i].Id) /* an application has been found */
  8571. {
  8572. appls_found++;
  8573. }
  8574. }
  8575. for (i = 0; i < max_adapter; i++) /* scan all adapters... */
  8576. {
  8577. a = &adapter[i];
  8578. if (a->request)
  8579. {
  8580. a->Info_Mask[Id - 1] = 0;
  8581. a->CIP_Mask[Id - 1] = 0;
  8582. a->Notification_Mask[Id - 1] = 0;
  8583. a->codec_listen[Id - 1] = NULL;
  8584. a->requested_options_table[Id - 1] = 0;
  8585. for (j = 0; j < a->max_plci; j++) /* and all PLCIs connected */
  8586. { /* with this application */
  8587. plci = &a->plci[j];
  8588. if (plci->Id) /* if plci owns no application */
  8589. { /* it may be not jet connected */
  8590. if (plci->State == INC_CON_PENDING
  8591. || plci->State == INC_CON_ALERT)
  8592. {
  8593. if (test_c_ind_mask_bit(plci, (word)(Id - 1)))
  8594. {
  8595. clear_c_ind_mask_bit(plci, (word)(Id - 1));
  8596. if (c_ind_mask_empty(plci))
  8597. {
  8598. sig_req(plci, HANGUP, 0);
  8599. send_req(plci);
  8600. plci->State = OUTG_DIS_PENDING;
  8601. }
  8602. }
  8603. }
  8604. if (test_c_ind_mask_bit(plci, (word)(Id - 1)))
  8605. {
  8606. clear_c_ind_mask_bit(plci, (word)(Id - 1));
  8607. if (c_ind_mask_empty(plci))
  8608. {
  8609. if (!plci->appl)
  8610. {
  8611. plci_remove(plci);
  8612. plci->State = IDLE;
  8613. }
  8614. }
  8615. }
  8616. if (plci->appl == this)
  8617. {
  8618. plci->appl = NULL;
  8619. plci_remove(plci);
  8620. plci->State = IDLE;
  8621. }
  8622. }
  8623. }
  8624. listen_check(a);
  8625. if (a->flag_dynamic_l1_down)
  8626. {
  8627. if (appls_found == 1) /* last application does a capi release */
  8628. {
  8629. if ((j = get_plci(a)))
  8630. {
  8631. plci = &a->plci[j - 1];
  8632. plci->command = 0;
  8633. add_p(plci, OAD, "\x01\xfd");
  8634. add_p(plci, CAI, "\x01\x80");
  8635. add_p(plci, UID, "\x06\x43\x61\x70\x69\x32\x30");
  8636. add_p(plci, SHIFT | 6, NULL);
  8637. add_p(plci, SIN, "\x02\x00\x00");
  8638. plci->internal_command = REM_L1_SIG_ASSIGN_PEND;
  8639. sig_req(plci, ASSIGN, DSIG_ID);
  8640. add_p(plci, FTY, "\x02\xff\x06"); /* l1 down */
  8641. sig_req(plci, SIG_CTRL, 0);
  8642. send_req(plci);
  8643. }
  8644. }
  8645. }
  8646. if (a->AdvSignalAppl == this)
  8647. {
  8648. this->NullCREnable = false;
  8649. if (a->AdvCodecPLCI)
  8650. {
  8651. plci_remove(a->AdvCodecPLCI);
  8652. a->AdvCodecPLCI->tel = 0;
  8653. a->AdvCodecPLCI->adv_nl = 0;
  8654. }
  8655. a->AdvSignalAppl = NULL;
  8656. a->AdvSignalPLCI = NULL;
  8657. a->AdvCodecFLAG = 0;
  8658. a->AdvCodecPLCI = NULL;
  8659. }
  8660. }
  8661. }
  8662. this->Id = 0;
  8663. return GOOD;
  8664. }
  8665. static word plci_remove_check(PLCI *plci)
  8666. {
  8667. if (!plci) return true;
  8668. if (!plci->NL.Id && c_ind_mask_empty(plci))
  8669. {
  8670. if (plci->Sig.Id == 0xff)
  8671. plci->Sig.Id = 0;
  8672. if (!plci->Sig.Id)
  8673. {
  8674. dbug(1, dprintf("plci_remove_complete(%x)", plci->Id));
  8675. dbug(1, dprintf("tel=0x%x,Sig=0x%x", plci->tel, plci->Sig.Id));
  8676. if (plci->Id)
  8677. {
  8678. CodecIdCheck(plci->adapter, plci);
  8679. clear_b1_config(plci);
  8680. ncci_remove(plci, 0, false);
  8681. plci_free_msg_in_queue(plci);
  8682. channel_flow_control_remove(plci);
  8683. plci->Id = 0;
  8684. plci->State = IDLE;
  8685. plci->channels = 0;
  8686. plci->appl = NULL;
  8687. plci->notifiedcall = 0;
  8688. }
  8689. listen_check(plci->adapter);
  8690. return true;
  8691. }
  8692. }
  8693. return false;
  8694. }
  8695. /*------------------------------------------------------------------*/
  8696. static byte plci_nl_busy(PLCI *plci)
  8697. {
  8698. /* only applicable for non-multiplexed protocols */
  8699. return (plci->nl_req
  8700. || (plci->ncci_ring_list
  8701. && plci->adapter->ncci_ch[plci->ncci_ring_list]
  8702. && (plci->adapter->ch_flow_control[plci->adapter->ncci_ch[plci->ncci_ring_list]] & N_OK_FC_PENDING)));
  8703. }
  8704. /*------------------------------------------------------------------*/
  8705. /* DTMF facilities */
  8706. /*------------------------------------------------------------------*/
  8707. static struct
  8708. {
  8709. byte send_mask;
  8710. byte listen_mask;
  8711. byte character;
  8712. byte code;
  8713. } dtmf_digit_map[] =
  8714. {
  8715. { 0x01, 0x01, 0x23, DTMF_DIGIT_TONE_CODE_HASHMARK },
  8716. { 0x01, 0x01, 0x2a, DTMF_DIGIT_TONE_CODE_STAR },
  8717. { 0x01, 0x01, 0x30, DTMF_DIGIT_TONE_CODE_0 },
  8718. { 0x01, 0x01, 0x31, DTMF_DIGIT_TONE_CODE_1 },
  8719. { 0x01, 0x01, 0x32, DTMF_DIGIT_TONE_CODE_2 },
  8720. { 0x01, 0x01, 0x33, DTMF_DIGIT_TONE_CODE_3 },
  8721. { 0x01, 0x01, 0x34, DTMF_DIGIT_TONE_CODE_4 },
  8722. { 0x01, 0x01, 0x35, DTMF_DIGIT_TONE_CODE_5 },
  8723. { 0x01, 0x01, 0x36, DTMF_DIGIT_TONE_CODE_6 },
  8724. { 0x01, 0x01, 0x37, DTMF_DIGIT_TONE_CODE_7 },
  8725. { 0x01, 0x01, 0x38, DTMF_DIGIT_TONE_CODE_8 },
  8726. { 0x01, 0x01, 0x39, DTMF_DIGIT_TONE_CODE_9 },
  8727. { 0x01, 0x01, 0x41, DTMF_DIGIT_TONE_CODE_A },
  8728. { 0x01, 0x01, 0x42, DTMF_DIGIT_TONE_CODE_B },
  8729. { 0x01, 0x01, 0x43, DTMF_DIGIT_TONE_CODE_C },
  8730. { 0x01, 0x01, 0x44, DTMF_DIGIT_TONE_CODE_D },
  8731. { 0x01, 0x00, 0x61, DTMF_DIGIT_TONE_CODE_A },
  8732. { 0x01, 0x00, 0x62, DTMF_DIGIT_TONE_CODE_B },
  8733. { 0x01, 0x00, 0x63, DTMF_DIGIT_TONE_CODE_C },
  8734. { 0x01, 0x00, 0x64, DTMF_DIGIT_TONE_CODE_D },
  8735. { 0x04, 0x04, 0x80, DTMF_SIGNAL_NO_TONE },
  8736. { 0x00, 0x04, 0x81, DTMF_SIGNAL_UNIDENTIFIED_TONE },
  8737. { 0x04, 0x04, 0x82, DTMF_SIGNAL_DIAL_TONE },
  8738. { 0x04, 0x04, 0x83, DTMF_SIGNAL_PABX_INTERNAL_DIAL_TONE },
  8739. { 0x04, 0x04, 0x84, DTMF_SIGNAL_SPECIAL_DIAL_TONE },
  8740. { 0x04, 0x04, 0x85, DTMF_SIGNAL_SECOND_DIAL_TONE },
  8741. { 0x04, 0x04, 0x86, DTMF_SIGNAL_RINGING_TONE },
  8742. { 0x04, 0x04, 0x87, DTMF_SIGNAL_SPECIAL_RINGING_TONE },
  8743. { 0x04, 0x04, 0x88, DTMF_SIGNAL_BUSY_TONE },
  8744. { 0x04, 0x04, 0x89, DTMF_SIGNAL_CONGESTION_TONE },
  8745. { 0x04, 0x04, 0x8a, DTMF_SIGNAL_SPECIAL_INFORMATION_TONE },
  8746. { 0x04, 0x04, 0x8b, DTMF_SIGNAL_COMFORT_TONE },
  8747. { 0x04, 0x04, 0x8c, DTMF_SIGNAL_HOLD_TONE },
  8748. { 0x04, 0x04, 0x8d, DTMF_SIGNAL_RECORD_TONE },
  8749. { 0x04, 0x04, 0x8e, DTMF_SIGNAL_CALLER_WAITING_TONE },
  8750. { 0x04, 0x04, 0x8f, DTMF_SIGNAL_CALL_WAITING_TONE },
  8751. { 0x04, 0x04, 0x90, DTMF_SIGNAL_PAY_TONE },
  8752. { 0x04, 0x04, 0x91, DTMF_SIGNAL_POSITIVE_INDICATION_TONE },
  8753. { 0x04, 0x04, 0x92, DTMF_SIGNAL_NEGATIVE_INDICATION_TONE },
  8754. { 0x04, 0x04, 0x93, DTMF_SIGNAL_WARNING_TONE },
  8755. { 0x04, 0x04, 0x94, DTMF_SIGNAL_INTRUSION_TONE },
  8756. { 0x04, 0x04, 0x95, DTMF_SIGNAL_CALLING_CARD_SERVICE_TONE },
  8757. { 0x04, 0x04, 0x96, DTMF_SIGNAL_PAYPHONE_RECOGNITION_TONE },
  8758. { 0x04, 0x04, 0x97, DTMF_SIGNAL_CPE_ALERTING_SIGNAL },
  8759. { 0x04, 0x04, 0x98, DTMF_SIGNAL_OFF_HOOK_WARNING_TONE },
  8760. { 0x04, 0x04, 0xbf, DTMF_SIGNAL_INTERCEPT_TONE },
  8761. { 0x04, 0x04, 0xc0, DTMF_SIGNAL_MODEM_CALLING_TONE },
  8762. { 0x04, 0x04, 0xc1, DTMF_SIGNAL_FAX_CALLING_TONE },
  8763. { 0x04, 0x04, 0xc2, DTMF_SIGNAL_ANSWER_TONE },
  8764. { 0x04, 0x04, 0xc3, DTMF_SIGNAL_REVERSED_ANSWER_TONE },
  8765. { 0x04, 0x04, 0xc4, DTMF_SIGNAL_ANSAM_TONE },
  8766. { 0x04, 0x04, 0xc5, DTMF_SIGNAL_REVERSED_ANSAM_TONE },
  8767. { 0x04, 0x04, 0xc6, DTMF_SIGNAL_BELL103_ANSWER_TONE },
  8768. { 0x04, 0x04, 0xc7, DTMF_SIGNAL_FAX_FLAGS },
  8769. { 0x04, 0x04, 0xc8, DTMF_SIGNAL_G2_FAX_GROUP_ID },
  8770. { 0x00, 0x04, 0xc9, DTMF_SIGNAL_HUMAN_SPEECH },
  8771. { 0x04, 0x04, 0xca, DTMF_SIGNAL_ANSWERING_MACHINE_390 },
  8772. { 0x02, 0x02, 0xf1, DTMF_MF_DIGIT_TONE_CODE_1 },
  8773. { 0x02, 0x02, 0xf2, DTMF_MF_DIGIT_TONE_CODE_2 },
  8774. { 0x02, 0x02, 0xf3, DTMF_MF_DIGIT_TONE_CODE_3 },
  8775. { 0x02, 0x02, 0xf4, DTMF_MF_DIGIT_TONE_CODE_4 },
  8776. { 0x02, 0x02, 0xf5, DTMF_MF_DIGIT_TONE_CODE_5 },
  8777. { 0x02, 0x02, 0xf6, DTMF_MF_DIGIT_TONE_CODE_6 },
  8778. { 0x02, 0x02, 0xf7, DTMF_MF_DIGIT_TONE_CODE_7 },
  8779. { 0x02, 0x02, 0xf8, DTMF_MF_DIGIT_TONE_CODE_8 },
  8780. { 0x02, 0x02, 0xf9, DTMF_MF_DIGIT_TONE_CODE_9 },
  8781. { 0x02, 0x02, 0xfa, DTMF_MF_DIGIT_TONE_CODE_0 },
  8782. { 0x02, 0x02, 0xfb, DTMF_MF_DIGIT_TONE_CODE_K1 },
  8783. { 0x02, 0x02, 0xfc, DTMF_MF_DIGIT_TONE_CODE_K2 },
  8784. { 0x02, 0x02, 0xfd, DTMF_MF_DIGIT_TONE_CODE_KP },
  8785. { 0x02, 0x02, 0xfe, DTMF_MF_DIGIT_TONE_CODE_S1 },
  8786. { 0x02, 0x02, 0xff, DTMF_MF_DIGIT_TONE_CODE_ST },
  8787. };
  8788. #define DTMF_DIGIT_MAP_ENTRIES ARRAY_SIZE(dtmf_digit_map)
  8789. static void dtmf_enable_receiver(PLCI *plci, byte enable_mask)
  8790. {
  8791. word min_digit_duration, min_gap_duration;
  8792. dbug(1, dprintf("[%06lx] %s,%d: dtmf_enable_receiver %02x",
  8793. (dword)((plci->Id << 8) | UnMapController(plci->adapter->Id)),
  8794. (char *)(FILE_), __LINE__, enable_mask));
  8795. if (enable_mask != 0)
  8796. {
  8797. min_digit_duration = (plci->dtmf_rec_pulse_ms == 0) ? 40 : plci->dtmf_rec_pulse_ms;
  8798. min_gap_duration = (plci->dtmf_rec_pause_ms == 0) ? 40 : plci->dtmf_rec_pause_ms;
  8799. plci->internal_req_buffer[0] = DTMF_UDATA_REQUEST_ENABLE_RECEIVER;
  8800. PUT_WORD(&plci->internal_req_buffer[1], min_digit_duration);
  8801. PUT_WORD(&plci->internal_req_buffer[3], min_gap_duration);
  8802. plci->NData[0].PLength = 5;
  8803. PUT_WORD(&plci->internal_req_buffer[5], INTERNAL_IND_BUFFER_SIZE);
  8804. plci->NData[0].PLength += 2;
  8805. capidtmf_recv_enable(&(plci->capidtmf_state), min_digit_duration, min_gap_duration);
  8806. }
  8807. else
  8808. {
  8809. plci->internal_req_buffer[0] = DTMF_UDATA_REQUEST_DISABLE_RECEIVER;
  8810. plci->NData[0].PLength = 1;
  8811. capidtmf_recv_disable(&(plci->capidtmf_state));
  8812. }
  8813. plci->NData[0].P = plci->internal_req_buffer;
  8814. plci->NL.X = plci->NData;
  8815. plci->NL.ReqCh = 0;
  8816. plci->NL.Req = plci->nl_req = (byte) N_UDATA;
  8817. plci->adapter->request(&plci->NL);
  8818. }
  8819. static void dtmf_send_digits(PLCI *plci, byte *digit_buffer, word digit_count)
  8820. {
  8821. word w, i;
  8822. dbug(1, dprintf("[%06lx] %s,%d: dtmf_send_digits %d",
  8823. (dword)((plci->Id << 8) | UnMapController(plci->adapter->Id)),
  8824. (char *)(FILE_), __LINE__, digit_count));
  8825. plci->internal_req_buffer[0] = DTMF_UDATA_REQUEST_SEND_DIGITS;
  8826. w = (plci->dtmf_send_pulse_ms == 0) ? 40 : plci->dtmf_send_pulse_ms;
  8827. PUT_WORD(&plci->internal_req_buffer[1], w);
  8828. w = (plci->dtmf_send_pause_ms == 0) ? 40 : plci->dtmf_send_pause_ms;
  8829. PUT_WORD(&plci->internal_req_buffer[3], w);
  8830. for (i = 0; i < digit_count; i++)
  8831. {
  8832. w = 0;
  8833. while ((w < DTMF_DIGIT_MAP_ENTRIES)
  8834. && (digit_buffer[i] != dtmf_digit_map[w].character))
  8835. {
  8836. w++;
  8837. }
  8838. plci->internal_req_buffer[5 + i] = (w < DTMF_DIGIT_MAP_ENTRIES) ?
  8839. dtmf_digit_map[w].code : DTMF_DIGIT_TONE_CODE_STAR;
  8840. }
  8841. plci->NData[0].PLength = 5 + digit_count;
  8842. plci->NData[0].P = plci->internal_req_buffer;
  8843. plci->NL.X = plci->NData;
  8844. plci->NL.ReqCh = 0;
  8845. plci->NL.Req = plci->nl_req = (byte) N_UDATA;
  8846. plci->adapter->request(&plci->NL);
  8847. }
  8848. static void dtmf_rec_clear_config(PLCI *plci)
  8849. {
  8850. dbug(1, dprintf("[%06lx] %s,%d: dtmf_rec_clear_config",
  8851. (dword)((plci->Id << 8) | UnMapController(plci->adapter->Id)),
  8852. (char *)(FILE_), __LINE__));
  8853. plci->dtmf_rec_active = 0;
  8854. plci->dtmf_rec_pulse_ms = 0;
  8855. plci->dtmf_rec_pause_ms = 0;
  8856. capidtmf_init(&(plci->capidtmf_state), plci->adapter->u_law);
  8857. }
  8858. static void dtmf_send_clear_config(PLCI *plci)
  8859. {
  8860. dbug(1, dprintf("[%06lx] %s,%d: dtmf_send_clear_config",
  8861. (dword)((plci->Id << 8) | UnMapController(plci->adapter->Id)),
  8862. (char *)(FILE_), __LINE__));
  8863. plci->dtmf_send_requests = 0;
  8864. plci->dtmf_send_pulse_ms = 0;
  8865. plci->dtmf_send_pause_ms = 0;
  8866. }
  8867. static void dtmf_prepare_switch(dword Id, PLCI *plci)
  8868. {
  8869. dbug(1, dprintf("[%06lx] %s,%d: dtmf_prepare_switch",
  8870. UnMapId(Id), (char *)(FILE_), __LINE__));
  8871. while (plci->dtmf_send_requests != 0)
  8872. dtmf_confirmation(Id, plci);
  8873. }
  8874. static word dtmf_save_config(dword Id, PLCI *plci, byte Rc)
  8875. {
  8876. dbug(1, dprintf("[%06lx] %s,%d: dtmf_save_config %02x %d",
  8877. UnMapId(Id), (char *)(FILE_), __LINE__, Rc, plci->adjust_b_state));
  8878. return (GOOD);
  8879. }
  8880. static word dtmf_restore_config(dword Id, PLCI *plci, byte Rc)
  8881. {
  8882. word Info;
  8883. dbug(1, dprintf("[%06lx] %s,%d: dtmf_restore_config %02x %d",
  8884. UnMapId(Id), (char *)(FILE_), __LINE__, Rc, plci->adjust_b_state));
  8885. Info = GOOD;
  8886. if (plci->B1_facilities & B1_FACILITY_DTMFR)
  8887. {
  8888. switch (plci->adjust_b_state)
  8889. {
  8890. case ADJUST_B_RESTORE_DTMF_1:
  8891. plci->internal_command = plci->adjust_b_command;
  8892. if (plci_nl_busy(plci))
  8893. {
  8894. plci->adjust_b_state = ADJUST_B_RESTORE_DTMF_1;
  8895. break;
  8896. }
  8897. dtmf_enable_receiver(plci, plci->dtmf_rec_active);
  8898. plci->adjust_b_state = ADJUST_B_RESTORE_DTMF_2;
  8899. break;
  8900. case ADJUST_B_RESTORE_DTMF_2:
  8901. if ((Rc != OK) && (Rc != OK_FC))
  8902. {
  8903. dbug(1, dprintf("[%06lx] %s,%d: Reenable DTMF receiver failed %02x",
  8904. UnMapId(Id), (char *)(FILE_), __LINE__, Rc));
  8905. Info = _WRONG_STATE;
  8906. break;
  8907. }
  8908. break;
  8909. }
  8910. }
  8911. return (Info);
  8912. }
  8913. static void dtmf_command(dword Id, PLCI *plci, byte Rc)
  8914. {
  8915. word internal_command, Info;
  8916. byte mask;
  8917. byte result[4];
  8918. dbug(1, dprintf("[%06lx] %s,%d: dtmf_command %02x %04x %04x %d %d %d %d",
  8919. UnMapId(Id), (char *)(FILE_), __LINE__, Rc, plci->internal_command,
  8920. plci->dtmf_cmd, plci->dtmf_rec_pulse_ms, plci->dtmf_rec_pause_ms,
  8921. plci->dtmf_send_pulse_ms, plci->dtmf_send_pause_ms));
  8922. Info = GOOD;
  8923. result[0] = 2;
  8924. PUT_WORD(&result[1], DTMF_SUCCESS);
  8925. internal_command = plci->internal_command;
  8926. plci->internal_command = 0;
  8927. mask = 0x01;
  8928. switch (plci->dtmf_cmd)
  8929. {
  8930. case DTMF_LISTEN_TONE_START:
  8931. mask <<= 1;
  8932. case DTMF_LISTEN_MF_START:
  8933. mask <<= 1;
  8934. case DTMF_LISTEN_START:
  8935. switch (internal_command)
  8936. {
  8937. default:
  8938. adjust_b1_resource(Id, plci, NULL, (word)(plci->B1_facilities |
  8939. B1_FACILITY_DTMFR), DTMF_COMMAND_1);
  8940. case DTMF_COMMAND_1:
  8941. if (adjust_b_process(Id, plci, Rc) != GOOD)
  8942. {
  8943. dbug(1, dprintf("[%06lx] %s,%d: Load DTMF failed",
  8944. UnMapId(Id), (char *)(FILE_), __LINE__));
  8945. Info = _FACILITY_NOT_SUPPORTED;
  8946. break;
  8947. }
  8948. if (plci->internal_command)
  8949. return;
  8950. case DTMF_COMMAND_2:
  8951. if (plci_nl_busy(plci))
  8952. {
  8953. plci->internal_command = DTMF_COMMAND_2;
  8954. return;
  8955. }
  8956. plci->internal_command = DTMF_COMMAND_3;
  8957. dtmf_enable_receiver(plci, (byte)(plci->dtmf_rec_active | mask));
  8958. return;
  8959. case DTMF_COMMAND_3:
  8960. if ((Rc != OK) && (Rc != OK_FC))
  8961. {
  8962. dbug(1, dprintf("[%06lx] %s,%d: Enable DTMF receiver failed %02x",
  8963. UnMapId(Id), (char *)(FILE_), __LINE__, Rc));
  8964. Info = _FACILITY_NOT_SUPPORTED;
  8965. break;
  8966. }
  8967. plci->tone_last_indication_code = DTMF_SIGNAL_NO_TONE;
  8968. plci->dtmf_rec_active |= mask;
  8969. break;
  8970. }
  8971. break;
  8972. case DTMF_LISTEN_TONE_STOP:
  8973. mask <<= 1;
  8974. case DTMF_LISTEN_MF_STOP:
  8975. mask <<= 1;
  8976. case DTMF_LISTEN_STOP:
  8977. switch (internal_command)
  8978. {
  8979. default:
  8980. plci->dtmf_rec_active &= ~mask;
  8981. if (plci->dtmf_rec_active)
  8982. break;
  8983. /*
  8984. case DTMF_COMMAND_1:
  8985. if (plci->dtmf_rec_active)
  8986. {
  8987. if (plci_nl_busy (plci))
  8988. {
  8989. plci->internal_command = DTMF_COMMAND_1;
  8990. return;
  8991. }
  8992. plci->dtmf_rec_active &= ~mask;
  8993. plci->internal_command = DTMF_COMMAND_2;
  8994. dtmf_enable_receiver (plci, false);
  8995. return;
  8996. }
  8997. Rc = OK;
  8998. case DTMF_COMMAND_2:
  8999. if ((Rc != OK) && (Rc != OK_FC))
  9000. {
  9001. dbug (1, dprintf("[%06lx] %s,%d: Disable DTMF receiver failed %02x",
  9002. UnMapId (Id), (char far *)(FILE_), __LINE__, Rc));
  9003. Info = _FACILITY_NOT_SUPPORTED;
  9004. break;
  9005. }
  9006. */
  9007. adjust_b1_resource(Id, plci, NULL, (word)(plci->B1_facilities &
  9008. ~(B1_FACILITY_DTMFX | B1_FACILITY_DTMFR)), DTMF_COMMAND_3);
  9009. case DTMF_COMMAND_3:
  9010. if (adjust_b_process(Id, plci, Rc) != GOOD)
  9011. {
  9012. dbug(1, dprintf("[%06lx] %s,%d: Unload DTMF failed",
  9013. UnMapId(Id), (char *)(FILE_), __LINE__));
  9014. Info = _FACILITY_NOT_SUPPORTED;
  9015. break;
  9016. }
  9017. if (plci->internal_command)
  9018. return;
  9019. break;
  9020. }
  9021. break;
  9022. case DTMF_SEND_TONE:
  9023. mask <<= 1;
  9024. case DTMF_SEND_MF:
  9025. mask <<= 1;
  9026. case DTMF_DIGITS_SEND:
  9027. switch (internal_command)
  9028. {
  9029. default:
  9030. adjust_b1_resource(Id, plci, NULL, (word)(plci->B1_facilities |
  9031. ((plci->dtmf_parameter_length != 0) ? B1_FACILITY_DTMFX | B1_FACILITY_DTMFR : B1_FACILITY_DTMFX)),
  9032. DTMF_COMMAND_1);
  9033. case DTMF_COMMAND_1:
  9034. if (adjust_b_process(Id, plci, Rc) != GOOD)
  9035. {
  9036. dbug(1, dprintf("[%06lx] %s,%d: Load DTMF failed",
  9037. UnMapId(Id), (char *)(FILE_), __LINE__));
  9038. Info = _FACILITY_NOT_SUPPORTED;
  9039. break;
  9040. }
  9041. if (plci->internal_command)
  9042. return;
  9043. case DTMF_COMMAND_2:
  9044. if (plci_nl_busy(plci))
  9045. {
  9046. plci->internal_command = DTMF_COMMAND_2;
  9047. return;
  9048. }
  9049. plci->dtmf_msg_number_queue[(plci->dtmf_send_requests)++] = plci->number;
  9050. plci->internal_command = DTMF_COMMAND_3;
  9051. dtmf_send_digits(plci, &plci->saved_msg.parms[3].info[1], plci->saved_msg.parms[3].length);
  9052. return;
  9053. case DTMF_COMMAND_3:
  9054. if ((Rc != OK) && (Rc != OK_FC))
  9055. {
  9056. dbug(1, dprintf("[%06lx] %s,%d: Send DTMF digits failed %02x",
  9057. UnMapId(Id), (char *)(FILE_), __LINE__, Rc));
  9058. if (plci->dtmf_send_requests != 0)
  9059. (plci->dtmf_send_requests)--;
  9060. Info = _FACILITY_NOT_SUPPORTED;
  9061. break;
  9062. }
  9063. return;
  9064. }
  9065. break;
  9066. }
  9067. sendf(plci->appl, _FACILITY_R | CONFIRM, Id & 0xffffL, plci->number,
  9068. "wws", Info, SELECTOR_DTMF, result);
  9069. }
  9070. static byte dtmf_request(dword Id, word Number, DIVA_CAPI_ADAPTER *a, PLCI *plci, APPL *appl, API_PARSE *msg)
  9071. {
  9072. word Info;
  9073. word i, j;
  9074. byte mask;
  9075. API_PARSE dtmf_parms[5];
  9076. byte result[40];
  9077. dbug(1, dprintf("[%06lx] %s,%d: dtmf_request",
  9078. UnMapId(Id), (char *)(FILE_), __LINE__));
  9079. Info = GOOD;
  9080. result[0] = 2;
  9081. PUT_WORD(&result[1], DTMF_SUCCESS);
  9082. if (!(a->profile.Global_Options & GL_DTMF_SUPPORTED))
  9083. {
  9084. dbug(1, dprintf("[%06lx] %s,%d: Facility not supported",
  9085. UnMapId(Id), (char *)(FILE_), __LINE__));
  9086. Info = _FACILITY_NOT_SUPPORTED;
  9087. }
  9088. else if (api_parse(&msg[1].info[1], msg[1].length, "w", dtmf_parms))
  9089. {
  9090. dbug(1, dprintf("[%06lx] %s,%d: Wrong message format",
  9091. UnMapId(Id), (char *)(FILE_), __LINE__));
  9092. Info = _WRONG_MESSAGE_FORMAT;
  9093. }
  9094. else if ((GET_WORD(dtmf_parms[0].info) == DTMF_GET_SUPPORTED_DETECT_CODES)
  9095. || (GET_WORD(dtmf_parms[0].info) == DTMF_GET_SUPPORTED_SEND_CODES))
  9096. {
  9097. if (!((a->requested_options_table[appl->Id - 1])
  9098. & (1L << PRIVATE_DTMF_TONE)))
  9099. {
  9100. dbug(1, dprintf("[%06lx] %s,%d: DTMF unknown request %04x",
  9101. UnMapId(Id), (char *)(FILE_), __LINE__, GET_WORD(dtmf_parms[0].info)));
  9102. PUT_WORD(&result[1], DTMF_UNKNOWN_REQUEST);
  9103. }
  9104. else
  9105. {
  9106. for (i = 0; i < 32; i++)
  9107. result[4 + i] = 0;
  9108. if (GET_WORD(dtmf_parms[0].info) == DTMF_GET_SUPPORTED_DETECT_CODES)
  9109. {
  9110. for (i = 0; i < DTMF_DIGIT_MAP_ENTRIES; i++)
  9111. {
  9112. if (dtmf_digit_map[i].listen_mask != 0)
  9113. result[4 + (dtmf_digit_map[i].character >> 3)] |= (1 << (dtmf_digit_map[i].character & 0x7));
  9114. }
  9115. }
  9116. else
  9117. {
  9118. for (i = 0; i < DTMF_DIGIT_MAP_ENTRIES; i++)
  9119. {
  9120. if (dtmf_digit_map[i].send_mask != 0)
  9121. result[4 + (dtmf_digit_map[i].character >> 3)] |= (1 << (dtmf_digit_map[i].character & 0x7));
  9122. }
  9123. }
  9124. result[0] = 3 + 32;
  9125. result[3] = 32;
  9126. }
  9127. }
  9128. else if (plci == NULL)
  9129. {
  9130. dbug(1, dprintf("[%06lx] %s,%d: Wrong PLCI",
  9131. UnMapId(Id), (char *)(FILE_), __LINE__));
  9132. Info = _WRONG_IDENTIFIER;
  9133. }
  9134. else
  9135. {
  9136. if (!plci->State
  9137. || !plci->NL.Id || plci->nl_remove_id)
  9138. {
  9139. dbug(1, dprintf("[%06lx] %s,%d: Wrong state",
  9140. UnMapId(Id), (char *)(FILE_), __LINE__));
  9141. Info = _WRONG_STATE;
  9142. }
  9143. else
  9144. {
  9145. plci->command = 0;
  9146. plci->dtmf_cmd = GET_WORD(dtmf_parms[0].info);
  9147. mask = 0x01;
  9148. switch (plci->dtmf_cmd)
  9149. {
  9150. case DTMF_LISTEN_TONE_START:
  9151. case DTMF_LISTEN_TONE_STOP:
  9152. mask <<= 1;
  9153. case DTMF_LISTEN_MF_START:
  9154. case DTMF_LISTEN_MF_STOP:
  9155. mask <<= 1;
  9156. if (!((plci->requested_options_conn | plci->requested_options | plci->adapter->requested_options_table[appl->Id - 1])
  9157. & (1L << PRIVATE_DTMF_TONE)))
  9158. {
  9159. dbug(1, dprintf("[%06lx] %s,%d: DTMF unknown request %04x",
  9160. UnMapId(Id), (char *)(FILE_), __LINE__, GET_WORD(dtmf_parms[0].info)));
  9161. PUT_WORD(&result[1], DTMF_UNKNOWN_REQUEST);
  9162. break;
  9163. }
  9164. case DTMF_LISTEN_START:
  9165. case DTMF_LISTEN_STOP:
  9166. if (!(a->manufacturer_features & MANUFACTURER_FEATURE_HARDDTMF)
  9167. && !(a->manufacturer_features & MANUFACTURER_FEATURE_SOFTDTMF_RECEIVE))
  9168. {
  9169. dbug(1, dprintf("[%06lx] %s,%d: Facility not supported",
  9170. UnMapId(Id), (char *)(FILE_), __LINE__));
  9171. Info = _FACILITY_NOT_SUPPORTED;
  9172. break;
  9173. }
  9174. if (mask & DTMF_LISTEN_ACTIVE_FLAG)
  9175. {
  9176. if (api_parse(&msg[1].info[1], msg[1].length, "wwws", dtmf_parms))
  9177. {
  9178. plci->dtmf_rec_pulse_ms = 0;
  9179. plci->dtmf_rec_pause_ms = 0;
  9180. }
  9181. else
  9182. {
  9183. plci->dtmf_rec_pulse_ms = GET_WORD(dtmf_parms[1].info);
  9184. plci->dtmf_rec_pause_ms = GET_WORD(dtmf_parms[2].info);
  9185. }
  9186. }
  9187. start_internal_command(Id, plci, dtmf_command);
  9188. return (false);
  9189. case DTMF_SEND_TONE:
  9190. mask <<= 1;
  9191. case DTMF_SEND_MF:
  9192. mask <<= 1;
  9193. if (!((plci->requested_options_conn | plci->requested_options | plci->adapter->requested_options_table[appl->Id - 1])
  9194. & (1L << PRIVATE_DTMF_TONE)))
  9195. {
  9196. dbug(1, dprintf("[%06lx] %s,%d: DTMF unknown request %04x",
  9197. UnMapId(Id), (char *)(FILE_), __LINE__, GET_WORD(dtmf_parms[0].info)));
  9198. PUT_WORD(&result[1], DTMF_UNKNOWN_REQUEST);
  9199. break;
  9200. }
  9201. case DTMF_DIGITS_SEND:
  9202. if (api_parse(&msg[1].info[1], msg[1].length, "wwws", dtmf_parms))
  9203. {
  9204. dbug(1, dprintf("[%06lx] %s,%d: Wrong message format",
  9205. UnMapId(Id), (char *)(FILE_), __LINE__));
  9206. Info = _WRONG_MESSAGE_FORMAT;
  9207. break;
  9208. }
  9209. if (mask & DTMF_LISTEN_ACTIVE_FLAG)
  9210. {
  9211. plci->dtmf_send_pulse_ms = GET_WORD(dtmf_parms[1].info);
  9212. plci->dtmf_send_pause_ms = GET_WORD(dtmf_parms[2].info);
  9213. }
  9214. i = 0;
  9215. j = 0;
  9216. while ((i < dtmf_parms[3].length) && (j < DTMF_DIGIT_MAP_ENTRIES))
  9217. {
  9218. j = 0;
  9219. while ((j < DTMF_DIGIT_MAP_ENTRIES)
  9220. && ((dtmf_parms[3].info[i + 1] != dtmf_digit_map[j].character)
  9221. || ((dtmf_digit_map[j].send_mask & mask) == 0)))
  9222. {
  9223. j++;
  9224. }
  9225. i++;
  9226. }
  9227. if (j == DTMF_DIGIT_MAP_ENTRIES)
  9228. {
  9229. dbug(1, dprintf("[%06lx] %s,%d: Incorrect DTMF digit %02x",
  9230. UnMapId(Id), (char *)(FILE_), __LINE__, dtmf_parms[3].info[i]));
  9231. PUT_WORD(&result[1], DTMF_INCORRECT_DIGIT);
  9232. break;
  9233. }
  9234. if (plci->dtmf_send_requests >= ARRAY_SIZE(plci->dtmf_msg_number_queue))
  9235. {
  9236. dbug(1, dprintf("[%06lx] %s,%d: DTMF request overrun",
  9237. UnMapId(Id), (char *)(FILE_), __LINE__));
  9238. Info = _WRONG_STATE;
  9239. break;
  9240. }
  9241. api_save_msg(dtmf_parms, "wwws", &plci->saved_msg);
  9242. start_internal_command(Id, plci, dtmf_command);
  9243. return (false);
  9244. default:
  9245. dbug(1, dprintf("[%06lx] %s,%d: DTMF unknown request %04x",
  9246. UnMapId(Id), (char *)(FILE_), __LINE__, plci->dtmf_cmd));
  9247. PUT_WORD(&result[1], DTMF_UNKNOWN_REQUEST);
  9248. }
  9249. }
  9250. }
  9251. sendf(appl, _FACILITY_R | CONFIRM, Id & 0xffffL, Number,
  9252. "wws", Info, SELECTOR_DTMF, result);
  9253. return (false);
  9254. }
  9255. static void dtmf_confirmation(dword Id, PLCI *plci)
  9256. {
  9257. word i;
  9258. byte result[4];
  9259. dbug(1, dprintf("[%06lx] %s,%d: dtmf_confirmation",
  9260. UnMapId(Id), (char *)(FILE_), __LINE__));
  9261. result[0] = 2;
  9262. PUT_WORD(&result[1], DTMF_SUCCESS);
  9263. if (plci->dtmf_send_requests != 0)
  9264. {
  9265. sendf(plci->appl, _FACILITY_R | CONFIRM, Id & 0xffffL, plci->dtmf_msg_number_queue[0],
  9266. "wws", GOOD, SELECTOR_DTMF, result);
  9267. (plci->dtmf_send_requests)--;
  9268. for (i = 0; i < plci->dtmf_send_requests; i++)
  9269. plci->dtmf_msg_number_queue[i] = plci->dtmf_msg_number_queue[i + 1];
  9270. }
  9271. }
  9272. static void dtmf_indication(dword Id, PLCI *plci, byte *msg, word length)
  9273. {
  9274. word i, j, n;
  9275. dbug(1, dprintf("[%06lx] %s,%d: dtmf_indication",
  9276. UnMapId(Id), (char *)(FILE_), __LINE__));
  9277. n = 0;
  9278. for (i = 1; i < length; i++)
  9279. {
  9280. j = 0;
  9281. while ((j < DTMF_DIGIT_MAP_ENTRIES)
  9282. && ((msg[i] != dtmf_digit_map[j].code)
  9283. || ((dtmf_digit_map[j].listen_mask & plci->dtmf_rec_active) == 0)))
  9284. {
  9285. j++;
  9286. }
  9287. if (j < DTMF_DIGIT_MAP_ENTRIES)
  9288. {
  9289. if ((dtmf_digit_map[j].listen_mask & DTMF_TONE_LISTEN_ACTIVE_FLAG)
  9290. && (plci->tone_last_indication_code == DTMF_SIGNAL_NO_TONE)
  9291. && (dtmf_digit_map[j].character != DTMF_SIGNAL_UNIDENTIFIED_TONE))
  9292. {
  9293. if (n + 1 == i)
  9294. {
  9295. for (i = length; i > n + 1; i--)
  9296. msg[i] = msg[i - 1];
  9297. length++;
  9298. i++;
  9299. }
  9300. msg[++n] = DTMF_SIGNAL_UNIDENTIFIED_TONE;
  9301. }
  9302. plci->tone_last_indication_code = dtmf_digit_map[j].character;
  9303. msg[++n] = dtmf_digit_map[j].character;
  9304. }
  9305. }
  9306. if (n != 0)
  9307. {
  9308. msg[0] = (byte) n;
  9309. sendf(plci->appl, _FACILITY_I, Id & 0xffffL, 0, "wS", SELECTOR_DTMF, msg);
  9310. }
  9311. }
  9312. /*------------------------------------------------------------------*/
  9313. /* DTMF parameters */
  9314. /*------------------------------------------------------------------*/
  9315. static void dtmf_parameter_write(PLCI *plci)
  9316. {
  9317. word i;
  9318. byte parameter_buffer[DTMF_PARAMETER_BUFFER_SIZE + 2];
  9319. dbug(1, dprintf("[%06lx] %s,%d: dtmf_parameter_write",
  9320. (dword)((plci->Id << 8) | UnMapController(plci->adapter->Id)),
  9321. (char *)(FILE_), __LINE__));
  9322. parameter_buffer[0] = plci->dtmf_parameter_length + 1;
  9323. parameter_buffer[1] = DSP_CTRL_SET_DTMF_PARAMETERS;
  9324. for (i = 0; i < plci->dtmf_parameter_length; i++)
  9325. parameter_buffer[2 + i] = plci->dtmf_parameter_buffer[i];
  9326. add_p(plci, FTY, parameter_buffer);
  9327. sig_req(plci, TEL_CTRL, 0);
  9328. send_req(plci);
  9329. }
  9330. static void dtmf_parameter_clear_config(PLCI *plci)
  9331. {
  9332. dbug(1, dprintf("[%06lx] %s,%d: dtmf_parameter_clear_config",
  9333. (dword)((plci->Id << 8) | UnMapController(plci->adapter->Id)),
  9334. (char *)(FILE_), __LINE__));
  9335. plci->dtmf_parameter_length = 0;
  9336. }
  9337. static void dtmf_parameter_prepare_switch(dword Id, PLCI *plci)
  9338. {
  9339. dbug(1, dprintf("[%06lx] %s,%d: dtmf_parameter_prepare_switch",
  9340. UnMapId(Id), (char *)(FILE_), __LINE__));
  9341. }
  9342. static word dtmf_parameter_save_config(dword Id, PLCI *plci, byte Rc)
  9343. {
  9344. dbug(1, dprintf("[%06lx] %s,%d: dtmf_parameter_save_config %02x %d",
  9345. UnMapId(Id), (char *)(FILE_), __LINE__, Rc, plci->adjust_b_state));
  9346. return (GOOD);
  9347. }
  9348. static word dtmf_parameter_restore_config(dword Id, PLCI *plci, byte Rc)
  9349. {
  9350. word Info;
  9351. dbug(1, dprintf("[%06lx] %s,%d: dtmf_parameter_restore_config %02x %d",
  9352. UnMapId(Id), (char *)(FILE_), __LINE__, Rc, plci->adjust_b_state));
  9353. Info = GOOD;
  9354. if ((plci->B1_facilities & B1_FACILITY_DTMFR)
  9355. && (plci->dtmf_parameter_length != 0))
  9356. {
  9357. switch (plci->adjust_b_state)
  9358. {
  9359. case ADJUST_B_RESTORE_DTMF_PARAMETER_1:
  9360. plci->internal_command = plci->adjust_b_command;
  9361. if (plci->sig_req)
  9362. {
  9363. plci->adjust_b_state = ADJUST_B_RESTORE_DTMF_PARAMETER_1;
  9364. break;
  9365. }
  9366. dtmf_parameter_write(plci);
  9367. plci->adjust_b_state = ADJUST_B_RESTORE_DTMF_PARAMETER_2;
  9368. break;
  9369. case ADJUST_B_RESTORE_DTMF_PARAMETER_2:
  9370. if ((Rc != OK) && (Rc != OK_FC))
  9371. {
  9372. dbug(1, dprintf("[%06lx] %s,%d: Restore DTMF parameters failed %02x",
  9373. UnMapId(Id), (char *)(FILE_), __LINE__, Rc));
  9374. Info = _WRONG_STATE;
  9375. break;
  9376. }
  9377. break;
  9378. }
  9379. }
  9380. return (Info);
  9381. }
  9382. /*------------------------------------------------------------------*/
  9383. /* Line interconnect facilities */
  9384. /*------------------------------------------------------------------*/
  9385. LI_CONFIG *li_config_table;
  9386. word li_total_channels;
  9387. /*------------------------------------------------------------------*/
  9388. /* translate a CHI information element to a channel number */
  9389. /* returns 0xff - any channel */
  9390. /* 0xfe - chi wrong coding */
  9391. /* 0xfd - D-channel */
  9392. /* 0x00 - no channel */
  9393. /* else channel number / PRI: timeslot */
  9394. /* if channels is provided we accept more than one channel. */
  9395. /*------------------------------------------------------------------*/
  9396. static byte chi_to_channel(byte *chi, dword *pchannelmap)
  9397. {
  9398. int p;
  9399. int i;
  9400. dword map;
  9401. byte excl;
  9402. byte ofs;
  9403. byte ch;
  9404. if (pchannelmap) *pchannelmap = 0;
  9405. if (!chi[0]) return 0xff;
  9406. excl = 0;
  9407. if (chi[1] & 0x20) {
  9408. if (chi[0] == 1 && chi[1] == 0xac) return 0xfd; /* exclusive d-channel */
  9409. for (i = 1; i < chi[0] && !(chi[i] & 0x80); i++);
  9410. if (i == chi[0] || !(chi[i] & 0x80)) return 0xfe;
  9411. if ((chi[1] | 0xc8) != 0xe9) return 0xfe;
  9412. if (chi[1] & 0x08) excl = 0x40;
  9413. /* int. id present */
  9414. if (chi[1] & 0x40) {
  9415. p = i + 1;
  9416. for (i = p; i < chi[0] && !(chi[i] & 0x80); i++);
  9417. if (i == chi[0] || !(chi[i] & 0x80)) return 0xfe;
  9418. }
  9419. /* coding standard, Number/Map, Channel Type */
  9420. p = i + 1;
  9421. for (i = p; i < chi[0] && !(chi[i] & 0x80); i++);
  9422. if (i == chi[0] || !(chi[i] & 0x80)) return 0xfe;
  9423. if ((chi[p] | 0xd0) != 0xd3) return 0xfe;
  9424. /* Number/Map */
  9425. if (chi[p] & 0x10) {
  9426. /* map */
  9427. if ((chi[0] - p) == 4) ofs = 0;
  9428. else if ((chi[0] - p) == 3) ofs = 1;
  9429. else return 0xfe;
  9430. ch = 0;
  9431. map = 0;
  9432. for (i = 0; i < 4 && p < chi[0]; i++) {
  9433. p++;
  9434. ch += 8;
  9435. map <<= 8;
  9436. if (chi[p]) {
  9437. for (ch = 0; !(chi[p] & (1 << ch)); ch++);
  9438. map |= chi[p];
  9439. }
  9440. }
  9441. ch += ofs;
  9442. map <<= ofs;
  9443. }
  9444. else {
  9445. /* number */
  9446. p = i + 1;
  9447. ch = chi[p] & 0x3f;
  9448. if (pchannelmap) {
  9449. if ((byte)(chi[0] - p) > 30) return 0xfe;
  9450. map = 0;
  9451. for (i = p; i <= chi[0]; i++) {
  9452. if ((chi[i] & 0x7f) > 31) return 0xfe;
  9453. map |= (1L << (chi[i] & 0x7f));
  9454. }
  9455. }
  9456. else {
  9457. if (p != chi[0]) return 0xfe;
  9458. if (ch > 31) return 0xfe;
  9459. map = (1L << ch);
  9460. }
  9461. if (chi[p] & 0x40) return 0xfe;
  9462. }
  9463. if (pchannelmap) *pchannelmap = map;
  9464. else if (map != ((dword)(1L << ch))) return 0xfe;
  9465. return (byte)(excl | ch);
  9466. }
  9467. else { /* not PRI */
  9468. for (i = 1; i < chi[0] && !(chi[i] & 0x80); i++);
  9469. if (i != chi[0] || !(chi[i] & 0x80)) return 0xfe;
  9470. if (chi[1] & 0x08) excl = 0x40;
  9471. switch (chi[1] | 0x98) {
  9472. case 0x98: return 0;
  9473. case 0x99:
  9474. if (pchannelmap) *pchannelmap = 2;
  9475. return excl | 1;
  9476. case 0x9a:
  9477. if (pchannelmap) *pchannelmap = 4;
  9478. return excl | 2;
  9479. case 0x9b: return 0xff;
  9480. case 0x9c: return 0xfd; /* d-ch */
  9481. default: return 0xfe;
  9482. }
  9483. }
  9484. }
  9485. static void mixer_set_bchannel_id_esc(PLCI *plci, byte bchannel_id)
  9486. {
  9487. DIVA_CAPI_ADAPTER *a;
  9488. PLCI *splci;
  9489. byte old_id;
  9490. a = plci->adapter;
  9491. old_id = plci->li_bchannel_id;
  9492. if (a->li_pri)
  9493. {
  9494. if ((old_id != 0) && (li_config_table[a->li_base + (old_id - 1)].plci == plci))
  9495. li_config_table[a->li_base + (old_id - 1)].plci = NULL;
  9496. plci->li_bchannel_id = (bchannel_id & 0x1f) + 1;
  9497. if (li_config_table[a->li_base + (plci->li_bchannel_id - 1)].plci == NULL)
  9498. li_config_table[a->li_base + (plci->li_bchannel_id - 1)].plci = plci;
  9499. }
  9500. else
  9501. {
  9502. if (((bchannel_id & 0x03) == 1) || ((bchannel_id & 0x03) == 2))
  9503. {
  9504. if ((old_id != 0) && (li_config_table[a->li_base + (old_id - 1)].plci == plci))
  9505. li_config_table[a->li_base + (old_id - 1)].plci = NULL;
  9506. plci->li_bchannel_id = bchannel_id & 0x03;
  9507. if ((a->AdvSignalPLCI != NULL) && (a->AdvSignalPLCI != plci) && (a->AdvSignalPLCI->tel == ADV_VOICE))
  9508. {
  9509. splci = a->AdvSignalPLCI;
  9510. if (li_config_table[a->li_base + (2 - plci->li_bchannel_id)].plci == NULL)
  9511. {
  9512. if ((splci->li_bchannel_id != 0)
  9513. && (li_config_table[a->li_base + (splci->li_bchannel_id - 1)].plci == splci))
  9514. {
  9515. li_config_table[a->li_base + (splci->li_bchannel_id - 1)].plci = NULL;
  9516. }
  9517. splci->li_bchannel_id = 3 - plci->li_bchannel_id;
  9518. li_config_table[a->li_base + (2 - plci->li_bchannel_id)].plci = splci;
  9519. dbug(1, dprintf("[%06lx] %s,%d: adv_voice_set_bchannel_id_esc %d",
  9520. (dword)((splci->Id << 8) | UnMapController(splci->adapter->Id)),
  9521. (char *)(FILE_), __LINE__, splci->li_bchannel_id));
  9522. }
  9523. }
  9524. if (li_config_table[a->li_base + (plci->li_bchannel_id - 1)].plci == NULL)
  9525. li_config_table[a->li_base + (plci->li_bchannel_id - 1)].plci = plci;
  9526. }
  9527. }
  9528. if ((old_id == 0) && (plci->li_bchannel_id != 0)
  9529. && (li_config_table[a->li_base + (plci->li_bchannel_id - 1)].plci == plci))
  9530. {
  9531. mixer_clear_config(plci);
  9532. }
  9533. dbug(1, dprintf("[%06lx] %s,%d: mixer_set_bchannel_id_esc %d %d",
  9534. (dword)((plci->Id << 8) | UnMapController(plci->adapter->Id)),
  9535. (char *)(FILE_), __LINE__, bchannel_id, plci->li_bchannel_id));
  9536. }
  9537. static void mixer_set_bchannel_id(PLCI *plci, byte *chi)
  9538. {
  9539. DIVA_CAPI_ADAPTER *a;
  9540. PLCI *splci;
  9541. byte ch, old_id;
  9542. a = plci->adapter;
  9543. old_id = plci->li_bchannel_id;
  9544. ch = chi_to_channel(chi, NULL);
  9545. if (!(ch & 0x80))
  9546. {
  9547. if (a->li_pri)
  9548. {
  9549. if ((old_id != 0) && (li_config_table[a->li_base + (old_id - 1)].plci == plci))
  9550. li_config_table[a->li_base + (old_id - 1)].plci = NULL;
  9551. plci->li_bchannel_id = (ch & 0x1f) + 1;
  9552. if (li_config_table[a->li_base + (plci->li_bchannel_id - 1)].plci == NULL)
  9553. li_config_table[a->li_base + (plci->li_bchannel_id - 1)].plci = plci;
  9554. }
  9555. else
  9556. {
  9557. if (((ch & 0x1f) == 1) || ((ch & 0x1f) == 2))
  9558. {
  9559. if ((old_id != 0) && (li_config_table[a->li_base + (old_id - 1)].plci == plci))
  9560. li_config_table[a->li_base + (old_id - 1)].plci = NULL;
  9561. plci->li_bchannel_id = ch & 0x1f;
  9562. if ((a->AdvSignalPLCI != NULL) && (a->AdvSignalPLCI != plci) && (a->AdvSignalPLCI->tel == ADV_VOICE))
  9563. {
  9564. splci = a->AdvSignalPLCI;
  9565. if (li_config_table[a->li_base + (2 - plci->li_bchannel_id)].plci == NULL)
  9566. {
  9567. if ((splci->li_bchannel_id != 0)
  9568. && (li_config_table[a->li_base + (splci->li_bchannel_id - 1)].plci == splci))
  9569. {
  9570. li_config_table[a->li_base + (splci->li_bchannel_id - 1)].plci = NULL;
  9571. }
  9572. splci->li_bchannel_id = 3 - plci->li_bchannel_id;
  9573. li_config_table[a->li_base + (2 - plci->li_bchannel_id)].plci = splci;
  9574. dbug(1, dprintf("[%06lx] %s,%d: adv_voice_set_bchannel_id %d",
  9575. (dword)((splci->Id << 8) | UnMapController(splci->adapter->Id)),
  9576. (char *)(FILE_), __LINE__, splci->li_bchannel_id));
  9577. }
  9578. }
  9579. if (li_config_table[a->li_base + (plci->li_bchannel_id - 1)].plci == NULL)
  9580. li_config_table[a->li_base + (plci->li_bchannel_id - 1)].plci = plci;
  9581. }
  9582. }
  9583. }
  9584. if ((old_id == 0) && (plci->li_bchannel_id != 0)
  9585. && (li_config_table[a->li_base + (plci->li_bchannel_id - 1)].plci == plci))
  9586. {
  9587. mixer_clear_config(plci);
  9588. }
  9589. dbug(1, dprintf("[%06lx] %s,%d: mixer_set_bchannel_id %02x %d",
  9590. (dword)((plci->Id << 8) | UnMapController(plci->adapter->Id)),
  9591. (char *)(FILE_), __LINE__, ch, plci->li_bchannel_id));
  9592. }
  9593. #define MIXER_MAX_DUMP_CHANNELS 34
  9594. static void mixer_calculate_coefs(DIVA_CAPI_ADAPTER *a)
  9595. {
  9596. static char hex_digit_table[0x10] = {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f'};
  9597. word n, i, j;
  9598. char *p;
  9599. char hex_line[2 * MIXER_MAX_DUMP_CHANNELS + MIXER_MAX_DUMP_CHANNELS / 8 + 4];
  9600. dbug(1, dprintf("[%06lx] %s,%d: mixer_calculate_coefs",
  9601. (dword)(UnMapController(a->Id)), (char *)(FILE_), __LINE__));
  9602. for (i = 0; i < li_total_channels; i++)
  9603. {
  9604. li_config_table[i].channel &= LI_CHANNEL_ADDRESSES_SET;
  9605. if (li_config_table[i].chflags != 0)
  9606. li_config_table[i].channel |= LI_CHANNEL_INVOLVED;
  9607. else
  9608. {
  9609. for (j = 0; j < li_total_channels; j++)
  9610. {
  9611. if (((li_config_table[i].flag_table[j]) != 0)
  9612. || ((li_config_table[j].flag_table[i]) != 0))
  9613. {
  9614. li_config_table[i].channel |= LI_CHANNEL_INVOLVED;
  9615. }
  9616. if (((li_config_table[i].flag_table[j] & LI_FLAG_CONFERENCE) != 0)
  9617. || ((li_config_table[j].flag_table[i] & LI_FLAG_CONFERENCE) != 0))
  9618. {
  9619. li_config_table[i].channel |= LI_CHANNEL_CONFERENCE;
  9620. }
  9621. }
  9622. }
  9623. }
  9624. for (i = 0; i < li_total_channels; i++)
  9625. {
  9626. for (j = 0; j < li_total_channels; j++)
  9627. {
  9628. li_config_table[i].coef_table[j] &= ~(LI_COEF_CH_CH | LI_COEF_CH_PC | LI_COEF_PC_CH | LI_COEF_PC_PC);
  9629. if (li_config_table[i].flag_table[j] & LI_FLAG_CONFERENCE)
  9630. li_config_table[i].coef_table[j] |= LI_COEF_CH_CH;
  9631. }
  9632. }
  9633. for (n = 0; n < li_total_channels; n++)
  9634. {
  9635. if (li_config_table[n].channel & LI_CHANNEL_CONFERENCE)
  9636. {
  9637. for (i = 0; i < li_total_channels; i++)
  9638. {
  9639. if (li_config_table[i].channel & LI_CHANNEL_CONFERENCE)
  9640. {
  9641. for (j = 0; j < li_total_channels; j++)
  9642. {
  9643. li_config_table[i].coef_table[j] |=
  9644. li_config_table[i].coef_table[n] & li_config_table[n].coef_table[j];
  9645. }
  9646. }
  9647. }
  9648. }
  9649. }
  9650. for (i = 0; i < li_total_channels; i++)
  9651. {
  9652. if (li_config_table[i].channel & LI_CHANNEL_INVOLVED)
  9653. {
  9654. li_config_table[i].coef_table[i] &= ~LI_COEF_CH_CH;
  9655. for (j = 0; j < li_total_channels; j++)
  9656. {
  9657. if (li_config_table[i].coef_table[j] & LI_COEF_CH_CH)
  9658. li_config_table[i].flag_table[j] |= LI_FLAG_CONFERENCE;
  9659. }
  9660. if (li_config_table[i].flag_table[i] & LI_FLAG_CONFERENCE)
  9661. li_config_table[i].coef_table[i] |= LI_COEF_CH_CH;
  9662. }
  9663. }
  9664. for (i = 0; i < li_total_channels; i++)
  9665. {
  9666. if (li_config_table[i].channel & LI_CHANNEL_INVOLVED)
  9667. {
  9668. for (j = 0; j < li_total_channels; j++)
  9669. {
  9670. if (li_config_table[i].flag_table[j] & LI_FLAG_INTERCONNECT)
  9671. li_config_table[i].coef_table[j] |= LI_COEF_CH_CH;
  9672. if (li_config_table[i].flag_table[j] & LI_FLAG_MONITOR)
  9673. li_config_table[i].coef_table[j] |= LI_COEF_CH_PC;
  9674. if (li_config_table[i].flag_table[j] & LI_FLAG_MIX)
  9675. li_config_table[i].coef_table[j] |= LI_COEF_PC_CH;
  9676. if (li_config_table[i].flag_table[j] & LI_FLAG_PCCONNECT)
  9677. li_config_table[i].coef_table[j] |= LI_COEF_PC_PC;
  9678. }
  9679. if (li_config_table[i].chflags & LI_CHFLAG_MONITOR)
  9680. {
  9681. for (j = 0; j < li_total_channels; j++)
  9682. {
  9683. if (li_config_table[i].flag_table[j] & LI_FLAG_INTERCONNECT)
  9684. {
  9685. li_config_table[i].coef_table[j] |= LI_COEF_CH_PC;
  9686. if (li_config_table[j].chflags & LI_CHFLAG_MIX)
  9687. li_config_table[i].coef_table[j] |= LI_COEF_PC_CH | LI_COEF_PC_PC;
  9688. }
  9689. }
  9690. }
  9691. if (li_config_table[i].chflags & LI_CHFLAG_MIX)
  9692. {
  9693. for (j = 0; j < li_total_channels; j++)
  9694. {
  9695. if (li_config_table[j].flag_table[i] & LI_FLAG_INTERCONNECT)
  9696. li_config_table[j].coef_table[i] |= LI_COEF_PC_CH;
  9697. }
  9698. }
  9699. if (li_config_table[i].chflags & LI_CHFLAG_LOOP)
  9700. {
  9701. for (j = 0; j < li_total_channels; j++)
  9702. {
  9703. if (li_config_table[i].flag_table[j] & LI_FLAG_INTERCONNECT)
  9704. {
  9705. for (n = 0; n < li_total_channels; n++)
  9706. {
  9707. if (li_config_table[n].flag_table[i] & LI_FLAG_INTERCONNECT)
  9708. {
  9709. li_config_table[n].coef_table[j] |= LI_COEF_CH_CH;
  9710. if (li_config_table[j].chflags & LI_CHFLAG_MIX)
  9711. {
  9712. li_config_table[n].coef_table[j] |= LI_COEF_PC_CH;
  9713. if (li_config_table[n].chflags & LI_CHFLAG_MONITOR)
  9714. li_config_table[n].coef_table[j] |= LI_COEF_CH_PC | LI_COEF_PC_PC;
  9715. }
  9716. else if (li_config_table[n].chflags & LI_CHFLAG_MONITOR)
  9717. li_config_table[n].coef_table[j] |= LI_COEF_CH_PC;
  9718. }
  9719. }
  9720. }
  9721. }
  9722. }
  9723. }
  9724. }
  9725. for (i = 0; i < li_total_channels; i++)
  9726. {
  9727. if (li_config_table[i].channel & LI_CHANNEL_INVOLVED)
  9728. {
  9729. if (li_config_table[i].chflags & (LI_CHFLAG_MONITOR | LI_CHFLAG_MIX | LI_CHFLAG_LOOP))
  9730. li_config_table[i].channel |= LI_CHANNEL_ACTIVE;
  9731. if (li_config_table[i].chflags & LI_CHFLAG_MONITOR)
  9732. li_config_table[i].channel |= LI_CHANNEL_RX_DATA;
  9733. if (li_config_table[i].chflags & LI_CHFLAG_MIX)
  9734. li_config_table[i].channel |= LI_CHANNEL_TX_DATA;
  9735. for (j = 0; j < li_total_channels; j++)
  9736. {
  9737. if ((li_config_table[i].flag_table[j] &
  9738. (LI_FLAG_INTERCONNECT | LI_FLAG_PCCONNECT | LI_FLAG_CONFERENCE | LI_FLAG_MONITOR))
  9739. || (li_config_table[j].flag_table[i] &
  9740. (LI_FLAG_INTERCONNECT | LI_FLAG_PCCONNECT | LI_FLAG_CONFERENCE | LI_FLAG_ANNOUNCEMENT | LI_FLAG_MIX)))
  9741. {
  9742. li_config_table[i].channel |= LI_CHANNEL_ACTIVE;
  9743. }
  9744. if (li_config_table[i].flag_table[j] & (LI_FLAG_PCCONNECT | LI_FLAG_MONITOR))
  9745. li_config_table[i].channel |= LI_CHANNEL_RX_DATA;
  9746. if (li_config_table[j].flag_table[i] & (LI_FLAG_PCCONNECT | LI_FLAG_ANNOUNCEMENT | LI_FLAG_MIX))
  9747. li_config_table[i].channel |= LI_CHANNEL_TX_DATA;
  9748. }
  9749. if (!(li_config_table[i].channel & LI_CHANNEL_ACTIVE))
  9750. {
  9751. li_config_table[i].coef_table[i] |= LI_COEF_PC_CH | LI_COEF_CH_PC;
  9752. li_config_table[i].channel |= LI_CHANNEL_TX_DATA | LI_CHANNEL_RX_DATA;
  9753. }
  9754. }
  9755. }
  9756. for (i = 0; i < li_total_channels; i++)
  9757. {
  9758. if (li_config_table[i].channel & LI_CHANNEL_INVOLVED)
  9759. {
  9760. j = 0;
  9761. while ((j < li_total_channels) && !(li_config_table[i].flag_table[j] & LI_FLAG_ANNOUNCEMENT))
  9762. j++;
  9763. if (j < li_total_channels)
  9764. {
  9765. for (j = 0; j < li_total_channels; j++)
  9766. {
  9767. li_config_table[i].coef_table[j] &= ~(LI_COEF_CH_CH | LI_COEF_PC_CH);
  9768. if (li_config_table[i].flag_table[j] & LI_FLAG_ANNOUNCEMENT)
  9769. li_config_table[i].coef_table[j] |= LI_COEF_PC_CH;
  9770. }
  9771. }
  9772. }
  9773. }
  9774. n = li_total_channels;
  9775. if (n > MIXER_MAX_DUMP_CHANNELS)
  9776. n = MIXER_MAX_DUMP_CHANNELS;
  9777. p = hex_line;
  9778. for (j = 0; j < n; j++)
  9779. {
  9780. if ((j & 0x7) == 0)
  9781. *(p++) = ' ';
  9782. *(p++) = hex_digit_table[li_config_table[j].curchnl >> 4];
  9783. *(p++) = hex_digit_table[li_config_table[j].curchnl & 0xf];
  9784. }
  9785. *p = '\0';
  9786. dbug(1, dprintf("[%06lx] CURRENT %s",
  9787. (dword)(UnMapController(a->Id)), (char *)hex_line));
  9788. p = hex_line;
  9789. for (j = 0; j < n; j++)
  9790. {
  9791. if ((j & 0x7) == 0)
  9792. *(p++) = ' ';
  9793. *(p++) = hex_digit_table[li_config_table[j].channel >> 4];
  9794. *(p++) = hex_digit_table[li_config_table[j].channel & 0xf];
  9795. }
  9796. *p = '\0';
  9797. dbug(1, dprintf("[%06lx] CHANNEL %s",
  9798. (dword)(UnMapController(a->Id)), (char *)hex_line));
  9799. p = hex_line;
  9800. for (j = 0; j < n; j++)
  9801. {
  9802. if ((j & 0x7) == 0)
  9803. *(p++) = ' ';
  9804. *(p++) = hex_digit_table[li_config_table[j].chflags >> 4];
  9805. *(p++) = hex_digit_table[li_config_table[j].chflags & 0xf];
  9806. }
  9807. *p = '\0';
  9808. dbug(1, dprintf("[%06lx] CHFLAG %s",
  9809. (dword)(UnMapController(a->Id)), (char *)hex_line));
  9810. for (i = 0; i < n; i++)
  9811. {
  9812. p = hex_line;
  9813. for (j = 0; j < n; j++)
  9814. {
  9815. if ((j & 0x7) == 0)
  9816. *(p++) = ' ';
  9817. *(p++) = hex_digit_table[li_config_table[i].flag_table[j] >> 4];
  9818. *(p++) = hex_digit_table[li_config_table[i].flag_table[j] & 0xf];
  9819. }
  9820. *p = '\0';
  9821. dbug(1, dprintf("[%06lx] FLAG[%02x]%s",
  9822. (dword)(UnMapController(a->Id)), i, (char *)hex_line));
  9823. }
  9824. for (i = 0; i < n; i++)
  9825. {
  9826. p = hex_line;
  9827. for (j = 0; j < n; j++)
  9828. {
  9829. if ((j & 0x7) == 0)
  9830. *(p++) = ' ';
  9831. *(p++) = hex_digit_table[li_config_table[i].coef_table[j] >> 4];
  9832. *(p++) = hex_digit_table[li_config_table[i].coef_table[j] & 0xf];
  9833. }
  9834. *p = '\0';
  9835. dbug(1, dprintf("[%06lx] COEF[%02x]%s",
  9836. (dword)(UnMapController(a->Id)), i, (char *)hex_line));
  9837. }
  9838. }
  9839. static struct
  9840. {
  9841. byte mask;
  9842. byte line_flags;
  9843. } mixer_write_prog_pri[] =
  9844. {
  9845. { LI_COEF_CH_CH, 0 },
  9846. { LI_COEF_CH_PC, MIXER_COEF_LINE_TO_PC_FLAG },
  9847. { LI_COEF_PC_CH, MIXER_COEF_LINE_FROM_PC_FLAG },
  9848. { LI_COEF_PC_PC, MIXER_COEF_LINE_TO_PC_FLAG | MIXER_COEF_LINE_FROM_PC_FLAG }
  9849. };
  9850. static struct
  9851. {
  9852. byte from_ch;
  9853. byte to_ch;
  9854. byte mask;
  9855. byte xconnect_override;
  9856. } mixer_write_prog_bri[] =
  9857. {
  9858. { 0, 0, LI_COEF_CH_CH, 0x01 }, /* B to B */
  9859. { 1, 0, LI_COEF_CH_CH, 0x01 }, /* Alt B to B */
  9860. { 0, 0, LI_COEF_PC_CH, 0x80 }, /* PC to B */
  9861. { 1, 0, LI_COEF_PC_CH, 0x01 }, /* Alt PC to B */
  9862. { 2, 0, LI_COEF_CH_CH, 0x00 }, /* IC to B */
  9863. { 3, 0, LI_COEF_CH_CH, 0x00 }, /* Alt IC to B */
  9864. { 0, 0, LI_COEF_CH_PC, 0x80 }, /* B to PC */
  9865. { 1, 0, LI_COEF_CH_PC, 0x01 }, /* Alt B to PC */
  9866. { 0, 0, LI_COEF_PC_PC, 0x01 }, /* PC to PC */
  9867. { 1, 0, LI_COEF_PC_PC, 0x01 }, /* Alt PC to PC */
  9868. { 2, 0, LI_COEF_CH_PC, 0x00 }, /* IC to PC */
  9869. { 3, 0, LI_COEF_CH_PC, 0x00 }, /* Alt IC to PC */
  9870. { 0, 2, LI_COEF_CH_CH, 0x00 }, /* B to IC */
  9871. { 1, 2, LI_COEF_CH_CH, 0x00 }, /* Alt B to IC */
  9872. { 0, 2, LI_COEF_PC_CH, 0x00 }, /* PC to IC */
  9873. { 1, 2, LI_COEF_PC_CH, 0x00 }, /* Alt PC to IC */
  9874. { 2, 2, LI_COEF_CH_CH, 0x00 }, /* IC to IC */
  9875. { 3, 2, LI_COEF_CH_CH, 0x00 }, /* Alt IC to IC */
  9876. { 1, 1, LI_COEF_CH_CH, 0x01 }, /* Alt B to Alt B */
  9877. { 0, 1, LI_COEF_CH_CH, 0x01 }, /* B to Alt B */
  9878. { 1, 1, LI_COEF_PC_CH, 0x80 }, /* Alt PC to Alt B */
  9879. { 0, 1, LI_COEF_PC_CH, 0x01 }, /* PC to Alt B */
  9880. { 3, 1, LI_COEF_CH_CH, 0x00 }, /* Alt IC to Alt B */
  9881. { 2, 1, LI_COEF_CH_CH, 0x00 }, /* IC to Alt B */
  9882. { 1, 1, LI_COEF_CH_PC, 0x80 }, /* Alt B to Alt PC */
  9883. { 0, 1, LI_COEF_CH_PC, 0x01 }, /* B to Alt PC */
  9884. { 1, 1, LI_COEF_PC_PC, 0x01 }, /* Alt PC to Alt PC */
  9885. { 0, 1, LI_COEF_PC_PC, 0x01 }, /* PC to Alt PC */
  9886. { 3, 1, LI_COEF_CH_PC, 0x00 }, /* Alt IC to Alt PC */
  9887. { 2, 1, LI_COEF_CH_PC, 0x00 }, /* IC to Alt PC */
  9888. { 1, 3, LI_COEF_CH_CH, 0x00 }, /* Alt B to Alt IC */
  9889. { 0, 3, LI_COEF_CH_CH, 0x00 }, /* B to Alt IC */
  9890. { 1, 3, LI_COEF_PC_CH, 0x00 }, /* Alt PC to Alt IC */
  9891. { 0, 3, LI_COEF_PC_CH, 0x00 }, /* PC to Alt IC */
  9892. { 3, 3, LI_COEF_CH_CH, 0x00 }, /* Alt IC to Alt IC */
  9893. { 2, 3, LI_COEF_CH_CH, 0x00 } /* IC to Alt IC */
  9894. };
  9895. static byte mixer_swapped_index_bri[] =
  9896. {
  9897. 18, /* B to B */
  9898. 19, /* Alt B to B */
  9899. 20, /* PC to B */
  9900. 21, /* Alt PC to B */
  9901. 22, /* IC to B */
  9902. 23, /* Alt IC to B */
  9903. 24, /* B to PC */
  9904. 25, /* Alt B to PC */
  9905. 26, /* PC to PC */
  9906. 27, /* Alt PC to PC */
  9907. 28, /* IC to PC */
  9908. 29, /* Alt IC to PC */
  9909. 30, /* B to IC */
  9910. 31, /* Alt B to IC */
  9911. 32, /* PC to IC */
  9912. 33, /* Alt PC to IC */
  9913. 34, /* IC to IC */
  9914. 35, /* Alt IC to IC */
  9915. 0, /* Alt B to Alt B */
  9916. 1, /* B to Alt B */
  9917. 2, /* Alt PC to Alt B */
  9918. 3, /* PC to Alt B */
  9919. 4, /* Alt IC to Alt B */
  9920. 5, /* IC to Alt B */
  9921. 6, /* Alt B to Alt PC */
  9922. 7, /* B to Alt PC */
  9923. 8, /* Alt PC to Alt PC */
  9924. 9, /* PC to Alt PC */
  9925. 10, /* Alt IC to Alt PC */
  9926. 11, /* IC to Alt PC */
  9927. 12, /* Alt B to Alt IC */
  9928. 13, /* B to Alt IC */
  9929. 14, /* Alt PC to Alt IC */
  9930. 15, /* PC to Alt IC */
  9931. 16, /* Alt IC to Alt IC */
  9932. 17 /* IC to Alt IC */
  9933. };
  9934. static struct
  9935. {
  9936. byte mask;
  9937. byte from_pc;
  9938. byte to_pc;
  9939. } xconnect_write_prog[] =
  9940. {
  9941. { LI_COEF_CH_CH, false, false },
  9942. { LI_COEF_CH_PC, false, true },
  9943. { LI_COEF_PC_CH, true, false },
  9944. { LI_COEF_PC_PC, true, true }
  9945. };
  9946. static void xconnect_query_addresses(PLCI *plci)
  9947. {
  9948. DIVA_CAPI_ADAPTER *a;
  9949. word w, ch;
  9950. byte *p;
  9951. dbug(1, dprintf("[%06lx] %s,%d: xconnect_query_addresses",
  9952. (dword)((plci->Id << 8) | UnMapController(plci->adapter->Id)),
  9953. (char *)(FILE_), __LINE__));
  9954. a = plci->adapter;
  9955. if (a->li_pri && ((plci->li_bchannel_id == 0)
  9956. || (li_config_table[a->li_base + (plci->li_bchannel_id - 1)].plci != plci)))
  9957. {
  9958. dbug(1, dprintf("[%06x] %s,%d: Channel id wiped out",
  9959. (dword)((plci->Id << 8) | UnMapController(plci->adapter->Id)),
  9960. (char *)(FILE_), __LINE__));
  9961. return;
  9962. }
  9963. p = plci->internal_req_buffer;
  9964. ch = (a->li_pri) ? plci->li_bchannel_id - 1 : 0;
  9965. *(p++) = UDATA_REQUEST_XCONNECT_FROM;
  9966. w = ch;
  9967. *(p++) = (byte) w;
  9968. *(p++) = (byte)(w >> 8);
  9969. w = ch | XCONNECT_CHANNEL_PORT_PC;
  9970. *(p++) = (byte) w;
  9971. *(p++) = (byte)(w >> 8);
  9972. plci->NData[0].P = plci->internal_req_buffer;
  9973. plci->NData[0].PLength = p - plci->internal_req_buffer;
  9974. plci->NL.X = plci->NData;
  9975. plci->NL.ReqCh = 0;
  9976. plci->NL.Req = plci->nl_req = (byte) N_UDATA;
  9977. plci->adapter->request(&plci->NL);
  9978. }
  9979. static void xconnect_write_coefs(PLCI *plci, word internal_command)
  9980. {
  9981. dbug(1, dprintf("[%06lx] %s,%d: xconnect_write_coefs %04x",
  9982. (dword)((plci->Id << 8) | UnMapController(plci->adapter->Id)),
  9983. (char *)(FILE_), __LINE__, internal_command));
  9984. plci->li_write_command = internal_command;
  9985. plci->li_write_channel = 0;
  9986. }
  9987. static byte xconnect_write_coefs_process(dword Id, PLCI *plci, byte Rc)
  9988. {
  9989. DIVA_CAPI_ADAPTER *a;
  9990. word w, n, i, j, r, s, to_ch;
  9991. dword d;
  9992. byte *p;
  9993. struct xconnect_transfer_address_s *transfer_address;
  9994. byte ch_map[MIXER_CHANNELS_BRI];
  9995. dbug(1, dprintf("[%06x] %s,%d: xconnect_write_coefs_process %02x %d",
  9996. UnMapId(Id), (char *)(FILE_), __LINE__, Rc, plci->li_write_channel));
  9997. a = plci->adapter;
  9998. if ((plci->li_bchannel_id == 0)
  9999. || (li_config_table[a->li_base + (plci->li_bchannel_id - 1)].plci != plci))
  10000. {
  10001. dbug(1, dprintf("[%06x] %s,%d: Channel id wiped out",
  10002. UnMapId(Id), (char *)(FILE_), __LINE__));
  10003. return (true);
  10004. }
  10005. i = a->li_base + (plci->li_bchannel_id - 1);
  10006. j = plci->li_write_channel;
  10007. p = plci->internal_req_buffer;
  10008. if (j != 0)
  10009. {
  10010. if ((Rc != OK) && (Rc != OK_FC))
  10011. {
  10012. dbug(1, dprintf("[%06lx] %s,%d: LI write coefs failed %02x",
  10013. UnMapId(Id), (char *)(FILE_), __LINE__, Rc));
  10014. return (false);
  10015. }
  10016. }
  10017. if (li_config_table[i].adapter->manufacturer_features & MANUFACTURER_FEATURE_XCONNECT)
  10018. {
  10019. r = 0;
  10020. s = 0;
  10021. if (j < li_total_channels)
  10022. {
  10023. if (li_config_table[i].channel & LI_CHANNEL_ADDRESSES_SET)
  10024. {
  10025. s = ((li_config_table[i].send_b.card_address.low | li_config_table[i].send_b.card_address.high) ?
  10026. (LI_COEF_CH_CH | LI_COEF_CH_PC | LI_COEF_PC_CH | LI_COEF_PC_PC) : (LI_COEF_CH_PC | LI_COEF_PC_PC)) &
  10027. ((li_config_table[i].send_pc.card_address.low | li_config_table[i].send_pc.card_address.high) ?
  10028. (LI_COEF_CH_CH | LI_COEF_CH_PC | LI_COEF_PC_CH | LI_COEF_PC_PC) : (LI_COEF_CH_CH | LI_COEF_PC_CH));
  10029. }
  10030. r = ((li_config_table[i].coef_table[j] & 0xf) ^ (li_config_table[i].coef_table[j] >> 4));
  10031. while ((j < li_total_channels)
  10032. && ((r == 0)
  10033. || (!(li_config_table[j].channel & LI_CHANNEL_ADDRESSES_SET))
  10034. || (!li_config_table[j].adapter->li_pri
  10035. && (j >= li_config_table[j].adapter->li_base + MIXER_BCHANNELS_BRI))
  10036. || (((li_config_table[j].send_b.card_address.low != li_config_table[i].send_b.card_address.low)
  10037. || (li_config_table[j].send_b.card_address.high != li_config_table[i].send_b.card_address.high))
  10038. && (!(a->manufacturer_features & MANUFACTURER_FEATURE_DMACONNECT)
  10039. || !(li_config_table[j].adapter->manufacturer_features & MANUFACTURER_FEATURE_DMACONNECT)))
  10040. || ((li_config_table[j].adapter->li_base != a->li_base)
  10041. && !(r & s &
  10042. ((li_config_table[j].send_b.card_address.low | li_config_table[j].send_b.card_address.high) ?
  10043. (LI_COEF_CH_CH | LI_COEF_CH_PC | LI_COEF_PC_CH | LI_COEF_PC_PC) : (LI_COEF_PC_CH | LI_COEF_PC_PC)) &
  10044. ((li_config_table[j].send_pc.card_address.low | li_config_table[j].send_pc.card_address.high) ?
  10045. (LI_COEF_CH_CH | LI_COEF_CH_PC | LI_COEF_PC_CH | LI_COEF_PC_PC) : (LI_COEF_CH_CH | LI_COEF_CH_PC))))))
  10046. {
  10047. j++;
  10048. if (j < li_total_channels)
  10049. r = ((li_config_table[i].coef_table[j] & 0xf) ^ (li_config_table[i].coef_table[j] >> 4));
  10050. }
  10051. }
  10052. if (j < li_total_channels)
  10053. {
  10054. plci->internal_command = plci->li_write_command;
  10055. if (plci_nl_busy(plci))
  10056. return (true);
  10057. to_ch = (a->li_pri) ? plci->li_bchannel_id - 1 : 0;
  10058. *(p++) = UDATA_REQUEST_XCONNECT_TO;
  10059. do
  10060. {
  10061. if (li_config_table[j].adapter->li_base != a->li_base)
  10062. {
  10063. r &= s &
  10064. ((li_config_table[j].send_b.card_address.low | li_config_table[j].send_b.card_address.high) ?
  10065. (LI_COEF_CH_CH | LI_COEF_CH_PC | LI_COEF_PC_CH | LI_COEF_PC_PC) : (LI_COEF_PC_CH | LI_COEF_PC_PC)) &
  10066. ((li_config_table[j].send_pc.card_address.low | li_config_table[j].send_pc.card_address.high) ?
  10067. (LI_COEF_CH_CH | LI_COEF_CH_PC | LI_COEF_PC_CH | LI_COEF_PC_PC) : (LI_COEF_CH_CH | LI_COEF_CH_PC));
  10068. }
  10069. n = 0;
  10070. do
  10071. {
  10072. if (r & xconnect_write_prog[n].mask)
  10073. {
  10074. if (xconnect_write_prog[n].from_pc)
  10075. transfer_address = &(li_config_table[j].send_pc);
  10076. else
  10077. transfer_address = &(li_config_table[j].send_b);
  10078. d = transfer_address->card_address.low;
  10079. *(p++) = (byte) d;
  10080. *(p++) = (byte)(d >> 8);
  10081. *(p++) = (byte)(d >> 16);
  10082. *(p++) = (byte)(d >> 24);
  10083. d = transfer_address->card_address.high;
  10084. *(p++) = (byte) d;
  10085. *(p++) = (byte)(d >> 8);
  10086. *(p++) = (byte)(d >> 16);
  10087. *(p++) = (byte)(d >> 24);
  10088. d = transfer_address->offset;
  10089. *(p++) = (byte) d;
  10090. *(p++) = (byte)(d >> 8);
  10091. *(p++) = (byte)(d >> 16);
  10092. *(p++) = (byte)(d >> 24);
  10093. w = xconnect_write_prog[n].to_pc ? to_ch | XCONNECT_CHANNEL_PORT_PC : to_ch;
  10094. *(p++) = (byte) w;
  10095. *(p++) = (byte)(w >> 8);
  10096. w = ((li_config_table[i].coef_table[j] & xconnect_write_prog[n].mask) == 0) ? 0x01 :
  10097. (li_config_table[i].adapter->u_law ?
  10098. (li_config_table[j].adapter->u_law ? 0x80 : 0x86) :
  10099. (li_config_table[j].adapter->u_law ? 0x7a : 0x80));
  10100. *(p++) = (byte) w;
  10101. *(p++) = (byte) 0;
  10102. li_config_table[i].coef_table[j] ^= xconnect_write_prog[n].mask << 4;
  10103. }
  10104. n++;
  10105. } while ((n < ARRAY_SIZE(xconnect_write_prog))
  10106. && ((p - plci->internal_req_buffer) + 16 < INTERNAL_REQ_BUFFER_SIZE));
  10107. if (n == ARRAY_SIZE(xconnect_write_prog))
  10108. {
  10109. do
  10110. {
  10111. j++;
  10112. if (j < li_total_channels)
  10113. r = ((li_config_table[i].coef_table[j] & 0xf) ^ (li_config_table[i].coef_table[j] >> 4));
  10114. } while ((j < li_total_channels)
  10115. && ((r == 0)
  10116. || (!(li_config_table[j].channel & LI_CHANNEL_ADDRESSES_SET))
  10117. || (!li_config_table[j].adapter->li_pri
  10118. && (j >= li_config_table[j].adapter->li_base + MIXER_BCHANNELS_BRI))
  10119. || (((li_config_table[j].send_b.card_address.low != li_config_table[i].send_b.card_address.low)
  10120. || (li_config_table[j].send_b.card_address.high != li_config_table[i].send_b.card_address.high))
  10121. && (!(a->manufacturer_features & MANUFACTURER_FEATURE_DMACONNECT)
  10122. || !(li_config_table[j].adapter->manufacturer_features & MANUFACTURER_FEATURE_DMACONNECT)))
  10123. || ((li_config_table[j].adapter->li_base != a->li_base)
  10124. && !(r & s &
  10125. ((li_config_table[j].send_b.card_address.low | li_config_table[j].send_b.card_address.high) ?
  10126. (LI_COEF_CH_CH | LI_COEF_CH_PC | LI_COEF_PC_CH | LI_COEF_PC_PC) : (LI_COEF_PC_CH | LI_COEF_PC_PC)) &
  10127. ((li_config_table[j].send_pc.card_address.low | li_config_table[j].send_pc.card_address.high) ?
  10128. (LI_COEF_CH_CH | LI_COEF_CH_PC | LI_COEF_PC_CH | LI_COEF_PC_PC) : (LI_COEF_CH_CH | LI_COEF_CH_PC))))));
  10129. }
  10130. } while ((j < li_total_channels)
  10131. && ((p - plci->internal_req_buffer) + 16 < INTERNAL_REQ_BUFFER_SIZE));
  10132. }
  10133. else if (j == li_total_channels)
  10134. {
  10135. plci->internal_command = plci->li_write_command;
  10136. if (plci_nl_busy(plci))
  10137. return (true);
  10138. if (a->li_pri)
  10139. {
  10140. *(p++) = UDATA_REQUEST_SET_MIXER_COEFS_PRI_SYNC;
  10141. w = 0;
  10142. if (li_config_table[i].channel & LI_CHANNEL_TX_DATA)
  10143. w |= MIXER_FEATURE_ENABLE_TX_DATA;
  10144. if (li_config_table[i].channel & LI_CHANNEL_RX_DATA)
  10145. w |= MIXER_FEATURE_ENABLE_RX_DATA;
  10146. *(p++) = (byte) w;
  10147. *(p++) = (byte)(w >> 8);
  10148. }
  10149. else
  10150. {
  10151. *(p++) = UDATA_REQUEST_SET_MIXER_COEFS_BRI;
  10152. w = 0;
  10153. if ((plci->tel == ADV_VOICE) && (plci == a->AdvSignalPLCI)
  10154. && (ADV_VOICE_NEW_COEF_BASE + sizeof(word) <= a->adv_voice_coef_length))
  10155. {
  10156. w = GET_WORD(a->adv_voice_coef_buffer + ADV_VOICE_NEW_COEF_BASE);
  10157. }
  10158. if (li_config_table[i].channel & LI_CHANNEL_TX_DATA)
  10159. w |= MIXER_FEATURE_ENABLE_TX_DATA;
  10160. if (li_config_table[i].channel & LI_CHANNEL_RX_DATA)
  10161. w |= MIXER_FEATURE_ENABLE_RX_DATA;
  10162. *(p++) = (byte) w;
  10163. *(p++) = (byte)(w >> 8);
  10164. for (j = 0; j < sizeof(ch_map); j += 2)
  10165. {
  10166. if (plci->li_bchannel_id == 2)
  10167. {
  10168. ch_map[j] = (byte)(j + 1);
  10169. ch_map[j + 1] = (byte) j;
  10170. }
  10171. else
  10172. {
  10173. ch_map[j] = (byte) j;
  10174. ch_map[j + 1] = (byte)(j + 1);
  10175. }
  10176. }
  10177. for (n = 0; n < ARRAY_SIZE(mixer_write_prog_bri); n++)
  10178. {
  10179. i = a->li_base + ch_map[mixer_write_prog_bri[n].to_ch];
  10180. j = a->li_base + ch_map[mixer_write_prog_bri[n].from_ch];
  10181. if (li_config_table[i].channel & li_config_table[j].channel & LI_CHANNEL_INVOLVED)
  10182. {
  10183. *p = (mixer_write_prog_bri[n].xconnect_override != 0) ?
  10184. mixer_write_prog_bri[n].xconnect_override :
  10185. ((li_config_table[i].coef_table[j] & mixer_write_prog_bri[n].mask) ? 0x80 : 0x01);
  10186. if ((i >= a->li_base + MIXER_BCHANNELS_BRI) || (j >= a->li_base + MIXER_BCHANNELS_BRI))
  10187. {
  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. }
  10192. else
  10193. {
  10194. *p = 0x00;
  10195. if ((a->AdvSignalPLCI != NULL) && (a->AdvSignalPLCI->tel == ADV_VOICE))
  10196. {
  10197. w = (plci == a->AdvSignalPLCI) ? n : mixer_swapped_index_bri[n];
  10198. if (ADV_VOICE_NEW_COEF_BASE + sizeof(word) + w < a->adv_voice_coef_length)
  10199. *p = a->adv_voice_coef_buffer[ADV_VOICE_NEW_COEF_BASE + sizeof(word) + w];
  10200. }
  10201. }
  10202. p++;
  10203. }
  10204. }
  10205. j = li_total_channels + 1;
  10206. }
  10207. }
  10208. else
  10209. {
  10210. if (j <= li_total_channels)
  10211. {
  10212. plci->internal_command = plci->li_write_command;
  10213. if (plci_nl_busy(plci))
  10214. return (true);
  10215. if (j < a->li_base)
  10216. j = a->li_base;
  10217. if (a->li_pri)
  10218. {
  10219. *(p++) = UDATA_REQUEST_SET_MIXER_COEFS_PRI_SYNC;
  10220. w = 0;
  10221. if (li_config_table[i].channel & LI_CHANNEL_TX_DATA)
  10222. w |= MIXER_FEATURE_ENABLE_TX_DATA;
  10223. if (li_config_table[i].channel & LI_CHANNEL_RX_DATA)
  10224. w |= MIXER_FEATURE_ENABLE_RX_DATA;
  10225. *(p++) = (byte) w;
  10226. *(p++) = (byte)(w >> 8);
  10227. for (n = 0; n < ARRAY_SIZE(mixer_write_prog_pri); n++)
  10228. {
  10229. *(p++) = (byte)((plci->li_bchannel_id - 1) | mixer_write_prog_pri[n].line_flags);
  10230. for (j = a->li_base; j < a->li_base + MIXER_CHANNELS_PRI; j++)
  10231. {
  10232. w = ((li_config_table[i].coef_table[j] & 0xf) ^ (li_config_table[i].coef_table[j] >> 4));
  10233. if (w & mixer_write_prog_pri[n].mask)
  10234. {
  10235. *(p++) = (li_config_table[i].coef_table[j] & mixer_write_prog_pri[n].mask) ? 0x80 : 0x01;
  10236. li_config_table[i].coef_table[j] ^= mixer_write_prog_pri[n].mask << 4;
  10237. }
  10238. else
  10239. *(p++) = 0x00;
  10240. }
  10241. *(p++) = (byte)((plci->li_bchannel_id - 1) | MIXER_COEF_LINE_ROW_FLAG | mixer_write_prog_pri[n].line_flags);
  10242. for (j = a->li_base; j < a->li_base + MIXER_CHANNELS_PRI; j++)
  10243. {
  10244. w = ((li_config_table[j].coef_table[i] & 0xf) ^ (li_config_table[j].coef_table[i] >> 4));
  10245. if (w & mixer_write_prog_pri[n].mask)
  10246. {
  10247. *(p++) = (li_config_table[j].coef_table[i] & mixer_write_prog_pri[n].mask) ? 0x80 : 0x01;
  10248. li_config_table[j].coef_table[i] ^= mixer_write_prog_pri[n].mask << 4;
  10249. }
  10250. else
  10251. *(p++) = 0x00;
  10252. }
  10253. }
  10254. }
  10255. else
  10256. {
  10257. *(p++) = UDATA_REQUEST_SET_MIXER_COEFS_BRI;
  10258. w = 0;
  10259. if ((plci->tel == ADV_VOICE) && (plci == a->AdvSignalPLCI)
  10260. && (ADV_VOICE_NEW_COEF_BASE + sizeof(word) <= a->adv_voice_coef_length))
  10261. {
  10262. w = GET_WORD(a->adv_voice_coef_buffer + ADV_VOICE_NEW_COEF_BASE);
  10263. }
  10264. if (li_config_table[i].channel & LI_CHANNEL_TX_DATA)
  10265. w |= MIXER_FEATURE_ENABLE_TX_DATA;
  10266. if (li_config_table[i].channel & LI_CHANNEL_RX_DATA)
  10267. w |= MIXER_FEATURE_ENABLE_RX_DATA;
  10268. *(p++) = (byte) w;
  10269. *(p++) = (byte)(w >> 8);
  10270. for (j = 0; j < sizeof(ch_map); j += 2)
  10271. {
  10272. if (plci->li_bchannel_id == 2)
  10273. {
  10274. ch_map[j] = (byte)(j + 1);
  10275. ch_map[j + 1] = (byte) j;
  10276. }
  10277. else
  10278. {
  10279. ch_map[j] = (byte) j;
  10280. ch_map[j + 1] = (byte)(j + 1);
  10281. }
  10282. }
  10283. for (n = 0; n < ARRAY_SIZE(mixer_write_prog_bri); n++)
  10284. {
  10285. i = a->li_base + ch_map[mixer_write_prog_bri[n].to_ch];
  10286. j = a->li_base + ch_map[mixer_write_prog_bri[n].from_ch];
  10287. if (li_config_table[i].channel & li_config_table[j].channel & LI_CHANNEL_INVOLVED)
  10288. {
  10289. *p = ((li_config_table[i].coef_table[j] & mixer_write_prog_bri[n].mask) ? 0x80 : 0x01);
  10290. w = ((li_config_table[i].coef_table[j] & 0xf) ^ (li_config_table[i].coef_table[j] >> 4));
  10291. li_config_table[i].coef_table[j] ^= (w & mixer_write_prog_bri[n].mask) << 4;
  10292. }
  10293. else
  10294. {
  10295. *p = 0x00;
  10296. if ((a->AdvSignalPLCI != NULL) && (a->AdvSignalPLCI->tel == ADV_VOICE))
  10297. {
  10298. w = (plci == a->AdvSignalPLCI) ? n : mixer_swapped_index_bri[n];
  10299. if (ADV_VOICE_NEW_COEF_BASE + sizeof(word) + w < a->adv_voice_coef_length)
  10300. *p = a->adv_voice_coef_buffer[ADV_VOICE_NEW_COEF_BASE + sizeof(word) + w];
  10301. }
  10302. }
  10303. p++;
  10304. }
  10305. }
  10306. j = li_total_channels + 1;
  10307. }
  10308. }
  10309. plci->li_write_channel = j;
  10310. if (p != plci->internal_req_buffer)
  10311. {
  10312. plci->NData[0].P = plci->internal_req_buffer;
  10313. plci->NData[0].PLength = p - plci->internal_req_buffer;
  10314. plci->NL.X = plci->NData;
  10315. plci->NL.ReqCh = 0;
  10316. plci->NL.Req = plci->nl_req = (byte) N_UDATA;
  10317. plci->adapter->request(&plci->NL);
  10318. }
  10319. return (true);
  10320. }
  10321. static void mixer_notify_update(PLCI *plci, byte others)
  10322. {
  10323. DIVA_CAPI_ADAPTER *a;
  10324. word i, w;
  10325. PLCI *notify_plci;
  10326. byte msg[sizeof(CAPI_MSG_HEADER) + 6];
  10327. dbug(1, dprintf("[%06lx] %s,%d: mixer_notify_update %d",
  10328. (dword)((plci->Id << 8) | UnMapController(plci->adapter->Id)),
  10329. (char *)(FILE_), __LINE__, others));
  10330. a = plci->adapter;
  10331. if (a->profile.Global_Options & GL_LINE_INTERCONNECT_SUPPORTED)
  10332. {
  10333. if (others)
  10334. plci->li_notify_update = true;
  10335. i = 0;
  10336. do
  10337. {
  10338. notify_plci = NULL;
  10339. if (others)
  10340. {
  10341. while ((i < li_total_channels) && (li_config_table[i].plci == NULL))
  10342. i++;
  10343. if (i < li_total_channels)
  10344. notify_plci = li_config_table[i++].plci;
  10345. }
  10346. else
  10347. {
  10348. if ((plci->li_bchannel_id != 0)
  10349. && (li_config_table[a->li_base + (plci->li_bchannel_id - 1)].plci == plci))
  10350. {
  10351. notify_plci = plci;
  10352. }
  10353. }
  10354. if ((notify_plci != NULL)
  10355. && !notify_plci->li_notify_update
  10356. && (notify_plci->appl != NULL)
  10357. && (notify_plci->State)
  10358. && notify_plci->NL.Id && !notify_plci->nl_remove_id)
  10359. {
  10360. notify_plci->li_notify_update = true;
  10361. ((CAPI_MSG *) msg)->header.length = 18;
  10362. ((CAPI_MSG *) msg)->header.appl_id = notify_plci->appl->Id;
  10363. ((CAPI_MSG *) msg)->header.command = _FACILITY_R;
  10364. ((CAPI_MSG *) msg)->header.number = 0;
  10365. ((CAPI_MSG *) msg)->header.controller = notify_plci->adapter->Id;
  10366. ((CAPI_MSG *) msg)->header.plci = notify_plci->Id;
  10367. ((CAPI_MSG *) msg)->header.ncci = 0;
  10368. ((CAPI_MSG *) msg)->info.facility_req.Selector = SELECTOR_LINE_INTERCONNECT;
  10369. ((CAPI_MSG *) msg)->info.facility_req.structs[0] = 3;
  10370. PUT_WORD(&(((CAPI_MSG *) msg)->info.facility_req.structs[1]), LI_REQ_SILENT_UPDATE);
  10371. ((CAPI_MSG *) msg)->info.facility_req.structs[3] = 0;
  10372. w = api_put(notify_plci->appl, (CAPI_MSG *) msg);
  10373. if (w != _QUEUE_FULL)
  10374. {
  10375. if (w != 0)
  10376. {
  10377. dbug(1, dprintf("[%06lx] %s,%d: Interconnect notify failed %06x %d",
  10378. (dword)((plci->Id << 8) | UnMapController(plci->adapter->Id)),
  10379. (char *)(FILE_), __LINE__,
  10380. (dword)((notify_plci->Id << 8) | UnMapController(notify_plci->adapter->Id)), w));
  10381. }
  10382. notify_plci->li_notify_update = false;
  10383. }
  10384. }
  10385. } while (others && (notify_plci != NULL));
  10386. if (others)
  10387. plci->li_notify_update = false;
  10388. }
  10389. }
  10390. static void mixer_clear_config(PLCI *plci)
  10391. {
  10392. DIVA_CAPI_ADAPTER *a;
  10393. word i, j;
  10394. dbug(1, dprintf("[%06lx] %s,%d: mixer_clear_config",
  10395. (dword)((plci->Id << 8) | UnMapController(plci->adapter->Id)),
  10396. (char *)(FILE_), __LINE__));
  10397. plci->li_notify_update = false;
  10398. plci->li_plci_b_write_pos = 0;
  10399. plci->li_plci_b_read_pos = 0;
  10400. plci->li_plci_b_req_pos = 0;
  10401. a = plci->adapter;
  10402. if ((plci->li_bchannel_id != 0)
  10403. && (li_config_table[a->li_base + (plci->li_bchannel_id - 1)].plci == plci))
  10404. {
  10405. i = a->li_base + (plci->li_bchannel_id - 1);
  10406. li_config_table[i].curchnl = 0;
  10407. li_config_table[i].channel = 0;
  10408. li_config_table[i].chflags = 0;
  10409. for (j = 0; j < li_total_channels; j++)
  10410. {
  10411. li_config_table[j].flag_table[i] = 0;
  10412. li_config_table[i].flag_table[j] = 0;
  10413. li_config_table[i].coef_table[j] = 0;
  10414. li_config_table[j].coef_table[i] = 0;
  10415. }
  10416. if (!a->li_pri)
  10417. {
  10418. li_config_table[i].coef_table[i] |= LI_COEF_CH_PC_SET | LI_COEF_PC_CH_SET;
  10419. if ((plci->tel == ADV_VOICE) && (plci == a->AdvSignalPLCI))
  10420. {
  10421. i = a->li_base + MIXER_IC_CHANNEL_BASE + (plci->li_bchannel_id - 1);
  10422. li_config_table[i].curchnl = 0;
  10423. li_config_table[i].channel = 0;
  10424. li_config_table[i].chflags = 0;
  10425. for (j = 0; j < li_total_channels; j++)
  10426. {
  10427. li_config_table[i].flag_table[j] = 0;
  10428. li_config_table[j].flag_table[i] = 0;
  10429. li_config_table[i].coef_table[j] = 0;
  10430. li_config_table[j].coef_table[i] = 0;
  10431. }
  10432. if (a->manufacturer_features & MANUFACTURER_FEATURE_SLAVE_CODEC)
  10433. {
  10434. i = a->li_base + MIXER_IC_CHANNEL_BASE + (2 - plci->li_bchannel_id);
  10435. li_config_table[i].curchnl = 0;
  10436. li_config_table[i].channel = 0;
  10437. li_config_table[i].chflags = 0;
  10438. for (j = 0; j < li_total_channels; j++)
  10439. {
  10440. li_config_table[i].flag_table[j] = 0;
  10441. li_config_table[j].flag_table[i] = 0;
  10442. li_config_table[i].coef_table[j] = 0;
  10443. li_config_table[j].coef_table[i] = 0;
  10444. }
  10445. }
  10446. }
  10447. }
  10448. }
  10449. }
  10450. static void mixer_prepare_switch(dword Id, PLCI *plci)
  10451. {
  10452. dbug(1, dprintf("[%06lx] %s,%d: mixer_prepare_switch",
  10453. UnMapId(Id), (char *)(FILE_), __LINE__));
  10454. do
  10455. {
  10456. mixer_indication_coefs_set(Id, plci);
  10457. } while (plci->li_plci_b_read_pos != plci->li_plci_b_req_pos);
  10458. }
  10459. static word mixer_save_config(dword Id, PLCI *plci, byte Rc)
  10460. {
  10461. DIVA_CAPI_ADAPTER *a;
  10462. word i, j;
  10463. dbug(1, dprintf("[%06lx] %s,%d: mixer_save_config %02x %d",
  10464. UnMapId(Id), (char *)(FILE_), __LINE__, Rc, plci->adjust_b_state));
  10465. a = plci->adapter;
  10466. if ((plci->li_bchannel_id != 0)
  10467. && (li_config_table[a->li_base + (plci->li_bchannel_id - 1)].plci == plci))
  10468. {
  10469. i = a->li_base + (plci->li_bchannel_id - 1);
  10470. for (j = 0; j < li_total_channels; j++)
  10471. {
  10472. li_config_table[i].coef_table[j] &= 0xf;
  10473. li_config_table[j].coef_table[i] &= 0xf;
  10474. }
  10475. if (!a->li_pri)
  10476. li_config_table[i].coef_table[i] |= LI_COEF_CH_PC_SET | LI_COEF_PC_CH_SET;
  10477. }
  10478. return (GOOD);
  10479. }
  10480. static word mixer_restore_config(dword Id, PLCI *plci, byte Rc)
  10481. {
  10482. DIVA_CAPI_ADAPTER *a;
  10483. word Info;
  10484. dbug(1, dprintf("[%06lx] %s,%d: mixer_restore_config %02x %d",
  10485. UnMapId(Id), (char *)(FILE_), __LINE__, Rc, plci->adjust_b_state));
  10486. Info = GOOD;
  10487. a = plci->adapter;
  10488. if ((plci->B1_facilities & B1_FACILITY_MIXER)
  10489. && (plci->li_bchannel_id != 0)
  10490. && (li_config_table[a->li_base + (plci->li_bchannel_id - 1)].plci == plci))
  10491. {
  10492. switch (plci->adjust_b_state)
  10493. {
  10494. case ADJUST_B_RESTORE_MIXER_1:
  10495. if (a->manufacturer_features & MANUFACTURER_FEATURE_XCONNECT)
  10496. {
  10497. plci->internal_command = plci->adjust_b_command;
  10498. if (plci_nl_busy(plci))
  10499. {
  10500. plci->adjust_b_state = ADJUST_B_RESTORE_MIXER_1;
  10501. break;
  10502. }
  10503. xconnect_query_addresses(plci);
  10504. plci->adjust_b_state = ADJUST_B_RESTORE_MIXER_2;
  10505. break;
  10506. }
  10507. plci->adjust_b_state = ADJUST_B_RESTORE_MIXER_5;
  10508. Rc = OK;
  10509. case ADJUST_B_RESTORE_MIXER_2:
  10510. case ADJUST_B_RESTORE_MIXER_3:
  10511. case ADJUST_B_RESTORE_MIXER_4:
  10512. if ((Rc != OK) && (Rc != OK_FC) && (Rc != 0))
  10513. {
  10514. dbug(1, dprintf("[%06lx] %s,%d: Adjust B query addresses failed %02x",
  10515. UnMapId(Id), (char *)(FILE_), __LINE__, Rc));
  10516. Info = _WRONG_STATE;
  10517. break;
  10518. }
  10519. if (Rc == OK)
  10520. {
  10521. if (plci->adjust_b_state == ADJUST_B_RESTORE_MIXER_2)
  10522. plci->adjust_b_state = ADJUST_B_RESTORE_MIXER_3;
  10523. else if (plci->adjust_b_state == ADJUST_B_RESTORE_MIXER_4)
  10524. plci->adjust_b_state = ADJUST_B_RESTORE_MIXER_5;
  10525. }
  10526. else if (Rc == 0)
  10527. {
  10528. if (plci->adjust_b_state == ADJUST_B_RESTORE_MIXER_2)
  10529. plci->adjust_b_state = ADJUST_B_RESTORE_MIXER_4;
  10530. else if (plci->adjust_b_state == ADJUST_B_RESTORE_MIXER_3)
  10531. plci->adjust_b_state = ADJUST_B_RESTORE_MIXER_5;
  10532. }
  10533. if (plci->adjust_b_state != ADJUST_B_RESTORE_MIXER_5)
  10534. {
  10535. plci->internal_command = plci->adjust_b_command;
  10536. break;
  10537. }
  10538. case ADJUST_B_RESTORE_MIXER_5:
  10539. xconnect_write_coefs(plci, plci->adjust_b_command);
  10540. plci->adjust_b_state = ADJUST_B_RESTORE_MIXER_6;
  10541. Rc = OK;
  10542. case ADJUST_B_RESTORE_MIXER_6:
  10543. if (!xconnect_write_coefs_process(Id, plci, Rc))
  10544. {
  10545. dbug(1, dprintf("[%06lx] %s,%d: Write mixer coefs failed",
  10546. UnMapId(Id), (char *)(FILE_), __LINE__));
  10547. Info = _FACILITY_NOT_SUPPORTED;
  10548. break;
  10549. }
  10550. if (plci->internal_command)
  10551. break;
  10552. plci->adjust_b_state = ADJUST_B_RESTORE_MIXER_7;
  10553. case ADJUST_B_RESTORE_MIXER_7:
  10554. break;
  10555. }
  10556. }
  10557. return (Info);
  10558. }
  10559. static void mixer_command(dword Id, PLCI *plci, byte Rc)
  10560. {
  10561. DIVA_CAPI_ADAPTER *a;
  10562. word i, internal_command;
  10563. dbug(1, dprintf("[%06lx] %s,%d: mixer_command %02x %04x %04x",
  10564. UnMapId(Id), (char *)(FILE_), __LINE__, Rc, plci->internal_command,
  10565. plci->li_cmd));
  10566. a = plci->adapter;
  10567. internal_command = plci->internal_command;
  10568. plci->internal_command = 0;
  10569. switch (plci->li_cmd)
  10570. {
  10571. case LI_REQ_CONNECT:
  10572. case LI_REQ_DISCONNECT:
  10573. case LI_REQ_SILENT_UPDATE:
  10574. switch (internal_command)
  10575. {
  10576. default:
  10577. if (plci->li_channel_bits & LI_CHANNEL_INVOLVED)
  10578. {
  10579. adjust_b1_resource(Id, plci, NULL, (word)(plci->B1_facilities |
  10580. B1_FACILITY_MIXER), MIXER_COMMAND_1);
  10581. }
  10582. case MIXER_COMMAND_1:
  10583. if (plci->li_channel_bits & LI_CHANNEL_INVOLVED)
  10584. {
  10585. if (adjust_b_process(Id, plci, Rc) != GOOD)
  10586. {
  10587. dbug(1, dprintf("[%06lx] %s,%d: Load mixer failed",
  10588. UnMapId(Id), (char *)(FILE_), __LINE__));
  10589. break;
  10590. }
  10591. if (plci->internal_command)
  10592. return;
  10593. }
  10594. plci->li_plci_b_req_pos = plci->li_plci_b_write_pos;
  10595. if ((plci->li_channel_bits & LI_CHANNEL_INVOLVED)
  10596. || ((get_b1_facilities(plci, plci->B1_resource) & B1_FACILITY_MIXER)
  10597. && (add_b1_facilities(plci, plci->B1_resource, (word)(plci->B1_facilities &
  10598. ~B1_FACILITY_MIXER)) == plci->B1_resource)))
  10599. {
  10600. xconnect_write_coefs(plci, MIXER_COMMAND_2);
  10601. }
  10602. else
  10603. {
  10604. do
  10605. {
  10606. mixer_indication_coefs_set(Id, plci);
  10607. } while (plci->li_plci_b_read_pos != plci->li_plci_b_req_pos);
  10608. }
  10609. case MIXER_COMMAND_2:
  10610. if ((plci->li_channel_bits & LI_CHANNEL_INVOLVED)
  10611. || ((get_b1_facilities(plci, plci->B1_resource) & B1_FACILITY_MIXER)
  10612. && (add_b1_facilities(plci, plci->B1_resource, (word)(plci->B1_facilities &
  10613. ~B1_FACILITY_MIXER)) == plci->B1_resource)))
  10614. {
  10615. if (!xconnect_write_coefs_process(Id, plci, Rc))
  10616. {
  10617. dbug(1, dprintf("[%06lx] %s,%d: Write mixer coefs failed",
  10618. UnMapId(Id), (char *)(FILE_), __LINE__));
  10619. if (plci->li_plci_b_write_pos != plci->li_plci_b_req_pos)
  10620. {
  10621. do
  10622. {
  10623. plci->li_plci_b_write_pos = (plci->li_plci_b_write_pos == 0) ?
  10624. LI_PLCI_B_QUEUE_ENTRIES - 1 : plci->li_plci_b_write_pos - 1;
  10625. i = (plci->li_plci_b_write_pos == 0) ?
  10626. LI_PLCI_B_QUEUE_ENTRIES - 1 : plci->li_plci_b_write_pos - 1;
  10627. } while ((plci->li_plci_b_write_pos != plci->li_plci_b_req_pos)
  10628. && !(plci->li_plci_b_queue[i] & LI_PLCI_B_LAST_FLAG));
  10629. }
  10630. break;
  10631. }
  10632. if (plci->internal_command)
  10633. return;
  10634. }
  10635. if (!(plci->li_channel_bits & LI_CHANNEL_INVOLVED))
  10636. {
  10637. adjust_b1_resource(Id, plci, NULL, (word)(plci->B1_facilities &
  10638. ~B1_FACILITY_MIXER), MIXER_COMMAND_3);
  10639. }
  10640. case MIXER_COMMAND_3:
  10641. if (!(plci->li_channel_bits & LI_CHANNEL_INVOLVED))
  10642. {
  10643. if (adjust_b_process(Id, plci, Rc) != GOOD)
  10644. {
  10645. dbug(1, dprintf("[%06lx] %s,%d: Unload mixer failed",
  10646. UnMapId(Id), (char *)(FILE_), __LINE__));
  10647. break;
  10648. }
  10649. if (plci->internal_command)
  10650. return;
  10651. }
  10652. break;
  10653. }
  10654. break;
  10655. }
  10656. if ((plci->li_bchannel_id == 0)
  10657. || (li_config_table[a->li_base + (plci->li_bchannel_id - 1)].plci != plci))
  10658. {
  10659. dbug(1, dprintf("[%06x] %s,%d: Channel id wiped out %d",
  10660. UnMapId(Id), (char *)(FILE_), __LINE__, (int)(plci->li_bchannel_id)));
  10661. }
  10662. else
  10663. {
  10664. i = a->li_base + (plci->li_bchannel_id - 1);
  10665. li_config_table[i].curchnl = plci->li_channel_bits;
  10666. if (!a->li_pri && (plci->tel == ADV_VOICE) && (plci == a->AdvSignalPLCI))
  10667. {
  10668. i = a->li_base + MIXER_IC_CHANNEL_BASE + (plci->li_bchannel_id - 1);
  10669. li_config_table[i].curchnl = plci->li_channel_bits;
  10670. if (a->manufacturer_features & MANUFACTURER_FEATURE_SLAVE_CODEC)
  10671. {
  10672. i = a->li_base + MIXER_IC_CHANNEL_BASE + (2 - plci->li_bchannel_id);
  10673. li_config_table[i].curchnl = plci->li_channel_bits;
  10674. }
  10675. }
  10676. }
  10677. }
  10678. static void li_update_connect(dword Id, DIVA_CAPI_ADAPTER *a, PLCI *plci,
  10679. dword plci_b_id, byte connect, dword li_flags)
  10680. {
  10681. word i, ch_a, ch_a_v, ch_a_s, ch_b, ch_b_v, ch_b_s;
  10682. PLCI *plci_b;
  10683. DIVA_CAPI_ADAPTER *a_b;
  10684. a_b = &(adapter[MapController((byte)(plci_b_id & 0x7f)) - 1]);
  10685. plci_b = &(a_b->plci[((plci_b_id >> 8) & 0xff) - 1]);
  10686. ch_a = a->li_base + (plci->li_bchannel_id - 1);
  10687. if (!a->li_pri && (plci->tel == ADV_VOICE)
  10688. && (plci == a->AdvSignalPLCI) && (Id & EXT_CONTROLLER))
  10689. {
  10690. ch_a_v = ch_a + MIXER_IC_CHANNEL_BASE;
  10691. ch_a_s = (a->manufacturer_features & MANUFACTURER_FEATURE_SLAVE_CODEC) ?
  10692. a->li_base + MIXER_IC_CHANNEL_BASE + (2 - plci->li_bchannel_id) : ch_a_v;
  10693. }
  10694. else
  10695. {
  10696. ch_a_v = ch_a;
  10697. ch_a_s = ch_a;
  10698. }
  10699. ch_b = a_b->li_base + (plci_b->li_bchannel_id - 1);
  10700. if (!a_b->li_pri && (plci_b->tel == ADV_VOICE)
  10701. && (plci_b == a_b->AdvSignalPLCI) && (plci_b_id & EXT_CONTROLLER))
  10702. {
  10703. ch_b_v = ch_b + MIXER_IC_CHANNEL_BASE;
  10704. ch_b_s = (a_b->manufacturer_features & MANUFACTURER_FEATURE_SLAVE_CODEC) ?
  10705. a_b->li_base + MIXER_IC_CHANNEL_BASE + (2 - plci_b->li_bchannel_id) : ch_b_v;
  10706. }
  10707. else
  10708. {
  10709. ch_b_v = ch_b;
  10710. ch_b_s = ch_b;
  10711. }
  10712. if (connect)
  10713. {
  10714. li_config_table[ch_a].flag_table[ch_a_v] &= ~LI_FLAG_MONITOR;
  10715. li_config_table[ch_a].flag_table[ch_a_s] &= ~LI_FLAG_MONITOR;
  10716. li_config_table[ch_a_v].flag_table[ch_a] &= ~(LI_FLAG_ANNOUNCEMENT | LI_FLAG_MIX);
  10717. li_config_table[ch_a_s].flag_table[ch_a] &= ~(LI_FLAG_ANNOUNCEMENT | LI_FLAG_MIX);
  10718. }
  10719. li_config_table[ch_a].flag_table[ch_b_v] &= ~LI_FLAG_MONITOR;
  10720. li_config_table[ch_a].flag_table[ch_b_s] &= ~LI_FLAG_MONITOR;
  10721. li_config_table[ch_b_v].flag_table[ch_a] &= ~(LI_FLAG_ANNOUNCEMENT | LI_FLAG_MIX);
  10722. li_config_table[ch_b_s].flag_table[ch_a] &= ~(LI_FLAG_ANNOUNCEMENT | LI_FLAG_MIX);
  10723. if (ch_a_v == ch_b_v)
  10724. {
  10725. li_config_table[ch_a_v].flag_table[ch_b_v] &= ~LI_FLAG_CONFERENCE;
  10726. li_config_table[ch_a_s].flag_table[ch_b_s] &= ~LI_FLAG_CONFERENCE;
  10727. }
  10728. else
  10729. {
  10730. if (li_config_table[ch_a_v].flag_table[ch_b_v] & LI_FLAG_CONFERENCE)
  10731. {
  10732. for (i = 0; i < li_total_channels; i++)
  10733. {
  10734. if (i != ch_a_v)
  10735. li_config_table[ch_a_v].flag_table[i] &= ~LI_FLAG_CONFERENCE;
  10736. }
  10737. }
  10738. if (li_config_table[ch_a_s].flag_table[ch_b_v] & LI_FLAG_CONFERENCE)
  10739. {
  10740. for (i = 0; i < li_total_channels; i++)
  10741. {
  10742. if (i != ch_a_s)
  10743. li_config_table[ch_a_s].flag_table[i] &= ~LI_FLAG_CONFERENCE;
  10744. }
  10745. }
  10746. if (li_config_table[ch_b_v].flag_table[ch_a_v] & LI_FLAG_CONFERENCE)
  10747. {
  10748. for (i = 0; i < li_total_channels; i++)
  10749. {
  10750. if (i != ch_a_v)
  10751. li_config_table[i].flag_table[ch_a_v] &= ~LI_FLAG_CONFERENCE;
  10752. }
  10753. }
  10754. if (li_config_table[ch_b_v].flag_table[ch_a_s] & LI_FLAG_CONFERENCE)
  10755. {
  10756. for (i = 0; i < li_total_channels; i++)
  10757. {
  10758. if (i != ch_a_s)
  10759. li_config_table[i].flag_table[ch_a_s] &= ~LI_FLAG_CONFERENCE;
  10760. }
  10761. }
  10762. }
  10763. if (li_flags & LI_FLAG_CONFERENCE_A_B)
  10764. {
  10765. li_config_table[ch_b_v].flag_table[ch_a_v] |= LI_FLAG_CONFERENCE;
  10766. li_config_table[ch_b_s].flag_table[ch_a_v] |= LI_FLAG_CONFERENCE;
  10767. li_config_table[ch_b_v].flag_table[ch_a_s] |= LI_FLAG_CONFERENCE;
  10768. li_config_table[ch_b_s].flag_table[ch_a_s] |= LI_FLAG_CONFERENCE;
  10769. }
  10770. if (li_flags & LI_FLAG_CONFERENCE_B_A)
  10771. {
  10772. li_config_table[ch_a_v].flag_table[ch_b_v] |= LI_FLAG_CONFERENCE;
  10773. li_config_table[ch_a_v].flag_table[ch_b_s] |= LI_FLAG_CONFERENCE;
  10774. li_config_table[ch_a_s].flag_table[ch_b_v] |= LI_FLAG_CONFERENCE;
  10775. li_config_table[ch_a_s].flag_table[ch_b_s] |= LI_FLAG_CONFERENCE;
  10776. }
  10777. if (li_flags & LI_FLAG_MONITOR_A)
  10778. {
  10779. li_config_table[ch_a].flag_table[ch_a_v] |= LI_FLAG_MONITOR;
  10780. li_config_table[ch_a].flag_table[ch_a_s] |= LI_FLAG_MONITOR;
  10781. }
  10782. if (li_flags & LI_FLAG_MONITOR_B)
  10783. {
  10784. li_config_table[ch_a].flag_table[ch_b_v] |= LI_FLAG_MONITOR;
  10785. li_config_table[ch_a].flag_table[ch_b_s] |= LI_FLAG_MONITOR;
  10786. }
  10787. if (li_flags & LI_FLAG_ANNOUNCEMENT_A)
  10788. {
  10789. li_config_table[ch_a_v].flag_table[ch_a] |= LI_FLAG_ANNOUNCEMENT;
  10790. li_config_table[ch_a_s].flag_table[ch_a] |= LI_FLAG_ANNOUNCEMENT;
  10791. }
  10792. if (li_flags & LI_FLAG_ANNOUNCEMENT_B)
  10793. {
  10794. li_config_table[ch_b_v].flag_table[ch_a] |= LI_FLAG_ANNOUNCEMENT;
  10795. li_config_table[ch_b_s].flag_table[ch_a] |= LI_FLAG_ANNOUNCEMENT;
  10796. }
  10797. if (li_flags & LI_FLAG_MIX_A)
  10798. {
  10799. li_config_table[ch_a_v].flag_table[ch_a] |= LI_FLAG_MIX;
  10800. li_config_table[ch_a_s].flag_table[ch_a] |= LI_FLAG_MIX;
  10801. }
  10802. if (li_flags & LI_FLAG_MIX_B)
  10803. {
  10804. li_config_table[ch_b_v].flag_table[ch_a] |= LI_FLAG_MIX;
  10805. li_config_table[ch_b_s].flag_table[ch_a] |= LI_FLAG_MIX;
  10806. }
  10807. if (ch_a_v != ch_a_s)
  10808. {
  10809. li_config_table[ch_a_v].flag_table[ch_a_s] |= LI_FLAG_CONFERENCE;
  10810. li_config_table[ch_a_s].flag_table[ch_a_v] |= LI_FLAG_CONFERENCE;
  10811. }
  10812. if (ch_b_v != ch_b_s)
  10813. {
  10814. li_config_table[ch_b_v].flag_table[ch_b_s] |= LI_FLAG_CONFERENCE;
  10815. li_config_table[ch_b_s].flag_table[ch_b_v] |= LI_FLAG_CONFERENCE;
  10816. }
  10817. }
  10818. static void li2_update_connect(dword Id, DIVA_CAPI_ADAPTER *a, PLCI *plci,
  10819. dword plci_b_id, byte connect, dword li_flags)
  10820. {
  10821. word ch_a, ch_a_v, ch_a_s, ch_b, ch_b_v, ch_b_s;
  10822. PLCI *plci_b;
  10823. DIVA_CAPI_ADAPTER *a_b;
  10824. a_b = &(adapter[MapController((byte)(plci_b_id & 0x7f)) - 1]);
  10825. plci_b = &(a_b->plci[((plci_b_id >> 8) & 0xff) - 1]);
  10826. ch_a = a->li_base + (plci->li_bchannel_id - 1);
  10827. if (!a->li_pri && (plci->tel == ADV_VOICE)
  10828. && (plci == a->AdvSignalPLCI) && (Id & EXT_CONTROLLER))
  10829. {
  10830. ch_a_v = ch_a + MIXER_IC_CHANNEL_BASE;
  10831. ch_a_s = (a->manufacturer_features & MANUFACTURER_FEATURE_SLAVE_CODEC) ?
  10832. a->li_base + MIXER_IC_CHANNEL_BASE + (2 - plci->li_bchannel_id) : ch_a_v;
  10833. }
  10834. else
  10835. {
  10836. ch_a_v = ch_a;
  10837. ch_a_s = ch_a;
  10838. }
  10839. ch_b = a_b->li_base + (plci_b->li_bchannel_id - 1);
  10840. if (!a_b->li_pri && (plci_b->tel == ADV_VOICE)
  10841. && (plci_b == a_b->AdvSignalPLCI) && (plci_b_id & EXT_CONTROLLER))
  10842. {
  10843. ch_b_v = ch_b + MIXER_IC_CHANNEL_BASE;
  10844. ch_b_s = (a_b->manufacturer_features & MANUFACTURER_FEATURE_SLAVE_CODEC) ?
  10845. a_b->li_base + MIXER_IC_CHANNEL_BASE + (2 - plci_b->li_bchannel_id) : ch_b_v;
  10846. }
  10847. else
  10848. {
  10849. ch_b_v = ch_b;
  10850. ch_b_s = ch_b;
  10851. }
  10852. if (connect)
  10853. {
  10854. li_config_table[ch_b].flag_table[ch_b_v] &= ~LI_FLAG_MONITOR;
  10855. li_config_table[ch_b].flag_table[ch_b_s] &= ~LI_FLAG_MONITOR;
  10856. li_config_table[ch_b_v].flag_table[ch_b] &= ~LI_FLAG_MIX;
  10857. li_config_table[ch_b_s].flag_table[ch_b] &= ~LI_FLAG_MIX;
  10858. li_config_table[ch_b].flag_table[ch_b] &= ~LI_FLAG_PCCONNECT;
  10859. li_config_table[ch_b].chflags &= ~(LI_CHFLAG_MONITOR | LI_CHFLAG_MIX | LI_CHFLAG_LOOP);
  10860. }
  10861. li_config_table[ch_b_v].flag_table[ch_a_v] &= ~(LI_FLAG_INTERCONNECT | LI_FLAG_CONFERENCE);
  10862. li_config_table[ch_b_s].flag_table[ch_a_v] &= ~(LI_FLAG_INTERCONNECT | LI_FLAG_CONFERENCE);
  10863. li_config_table[ch_b_v].flag_table[ch_a_s] &= ~(LI_FLAG_INTERCONNECT | LI_FLAG_CONFERENCE);
  10864. li_config_table[ch_b_s].flag_table[ch_a_s] &= ~(LI_FLAG_INTERCONNECT | LI_FLAG_CONFERENCE);
  10865. li_config_table[ch_a_v].flag_table[ch_b_v] &= ~(LI_FLAG_INTERCONNECT | LI_FLAG_CONFERENCE);
  10866. li_config_table[ch_a_v].flag_table[ch_b_s] &= ~(LI_FLAG_INTERCONNECT | LI_FLAG_CONFERENCE);
  10867. li_config_table[ch_a_s].flag_table[ch_b_v] &= ~(LI_FLAG_INTERCONNECT | LI_FLAG_CONFERENCE);
  10868. li_config_table[ch_a_s].flag_table[ch_b_s] &= ~(LI_FLAG_INTERCONNECT | LI_FLAG_CONFERENCE);
  10869. if (li_flags & LI2_FLAG_INTERCONNECT_A_B)
  10870. {
  10871. li_config_table[ch_b_v].flag_table[ch_a_v] |= LI_FLAG_INTERCONNECT;
  10872. li_config_table[ch_b_s].flag_table[ch_a_v] |= LI_FLAG_INTERCONNECT;
  10873. li_config_table[ch_b_v].flag_table[ch_a_s] |= LI_FLAG_INTERCONNECT;
  10874. li_config_table[ch_b_s].flag_table[ch_a_s] |= LI_FLAG_INTERCONNECT;
  10875. }
  10876. if (li_flags & LI2_FLAG_INTERCONNECT_B_A)
  10877. {
  10878. li_config_table[ch_a_v].flag_table[ch_b_v] |= LI_FLAG_INTERCONNECT;
  10879. li_config_table[ch_a_v].flag_table[ch_b_s] |= LI_FLAG_INTERCONNECT;
  10880. li_config_table[ch_a_s].flag_table[ch_b_v] |= LI_FLAG_INTERCONNECT;
  10881. li_config_table[ch_a_s].flag_table[ch_b_s] |= LI_FLAG_INTERCONNECT;
  10882. }
  10883. if (li_flags & LI2_FLAG_MONITOR_B)
  10884. {
  10885. li_config_table[ch_b].flag_table[ch_b_v] |= LI_FLAG_MONITOR;
  10886. li_config_table[ch_b].flag_table[ch_b_s] |= LI_FLAG_MONITOR;
  10887. }
  10888. if (li_flags & LI2_FLAG_MIX_B)
  10889. {
  10890. li_config_table[ch_b_v].flag_table[ch_b] |= LI_FLAG_MIX;
  10891. li_config_table[ch_b_s].flag_table[ch_b] |= LI_FLAG_MIX;
  10892. }
  10893. if (li_flags & LI2_FLAG_MONITOR_X)
  10894. li_config_table[ch_b].chflags |= LI_CHFLAG_MONITOR;
  10895. if (li_flags & LI2_FLAG_MIX_X)
  10896. li_config_table[ch_b].chflags |= LI_CHFLAG_MIX;
  10897. if (li_flags & LI2_FLAG_LOOP_B)
  10898. {
  10899. li_config_table[ch_b_v].flag_table[ch_b_v] |= LI_FLAG_INTERCONNECT;
  10900. li_config_table[ch_b_s].flag_table[ch_b_v] |= LI_FLAG_INTERCONNECT;
  10901. li_config_table[ch_b_v].flag_table[ch_b_s] |= LI_FLAG_INTERCONNECT;
  10902. li_config_table[ch_b_s].flag_table[ch_b_s] |= LI_FLAG_INTERCONNECT;
  10903. }
  10904. if (li_flags & LI2_FLAG_LOOP_PC)
  10905. li_config_table[ch_b].flag_table[ch_b] |= LI_FLAG_PCCONNECT;
  10906. if (li_flags & LI2_FLAG_LOOP_X)
  10907. li_config_table[ch_b].chflags |= LI_CHFLAG_LOOP;
  10908. if (li_flags & LI2_FLAG_PCCONNECT_A_B)
  10909. li_config_table[ch_b_s].flag_table[ch_a_s] |= LI_FLAG_PCCONNECT;
  10910. if (li_flags & LI2_FLAG_PCCONNECT_B_A)
  10911. li_config_table[ch_a_s].flag_table[ch_b_s] |= LI_FLAG_PCCONNECT;
  10912. if (ch_a_v != ch_a_s)
  10913. {
  10914. li_config_table[ch_a_v].flag_table[ch_a_s] |= LI_FLAG_CONFERENCE;
  10915. li_config_table[ch_a_s].flag_table[ch_a_v] |= LI_FLAG_CONFERENCE;
  10916. }
  10917. if (ch_b_v != ch_b_s)
  10918. {
  10919. li_config_table[ch_b_v].flag_table[ch_b_s] |= LI_FLAG_CONFERENCE;
  10920. li_config_table[ch_b_s].flag_table[ch_b_v] |= LI_FLAG_CONFERENCE;
  10921. }
  10922. }
  10923. static word li_check_main_plci(dword Id, PLCI *plci)
  10924. {
  10925. if (plci == NULL)
  10926. {
  10927. dbug(1, dprintf("[%06lx] %s,%d: Wrong PLCI",
  10928. UnMapId(Id), (char *)(FILE_), __LINE__));
  10929. return (_WRONG_IDENTIFIER);
  10930. }
  10931. if (!plci->State
  10932. || !plci->NL.Id || plci->nl_remove_id
  10933. || (plci->li_bchannel_id == 0))
  10934. {
  10935. dbug(1, dprintf("[%06lx] %s,%d: Wrong state",
  10936. UnMapId(Id), (char *)(FILE_), __LINE__));
  10937. return (_WRONG_STATE);
  10938. }
  10939. li_config_table[plci->adapter->li_base + (plci->li_bchannel_id - 1)].plci = plci;
  10940. return (GOOD);
  10941. }
  10942. static PLCI *li_check_plci_b(dword Id, PLCI *plci,
  10943. dword plci_b_id, word plci_b_write_pos, byte *p_result)
  10944. {
  10945. byte ctlr_b;
  10946. PLCI *plci_b;
  10947. if (((plci->li_plci_b_read_pos > plci_b_write_pos) ? plci->li_plci_b_read_pos :
  10948. LI_PLCI_B_QUEUE_ENTRIES + plci->li_plci_b_read_pos) - plci_b_write_pos - 1 < 2)
  10949. {
  10950. dbug(1, dprintf("[%06lx] %s,%d: LI request overrun",
  10951. UnMapId(Id), (char *)(FILE_), __LINE__));
  10952. PUT_WORD(p_result, _REQUEST_NOT_ALLOWED_IN_THIS_STATE);
  10953. return (NULL);
  10954. }
  10955. ctlr_b = 0;
  10956. if ((plci_b_id & 0x7f) != 0)
  10957. {
  10958. ctlr_b = MapController((byte)(plci_b_id & 0x7f));
  10959. if ((ctlr_b > max_adapter) || ((ctlr_b != 0) && (adapter[ctlr_b - 1].request == NULL)))
  10960. ctlr_b = 0;
  10961. }
  10962. if ((ctlr_b == 0)
  10963. || (((plci_b_id >> 8) & 0xff) == 0)
  10964. || (((plci_b_id >> 8) & 0xff) > adapter[ctlr_b - 1].max_plci))
  10965. {
  10966. dbug(1, dprintf("[%06lx] %s,%d: LI invalid second PLCI %08lx",
  10967. UnMapId(Id), (char *)(FILE_), __LINE__, plci_b_id));
  10968. PUT_WORD(p_result, _WRONG_IDENTIFIER);
  10969. return (NULL);
  10970. }
  10971. plci_b = &(adapter[ctlr_b - 1].plci[((plci_b_id >> 8) & 0xff) - 1]);
  10972. if (!plci_b->State
  10973. || !plci_b->NL.Id || plci_b->nl_remove_id
  10974. || (plci_b->li_bchannel_id == 0))
  10975. {
  10976. dbug(1, dprintf("[%06lx] %s,%d: LI peer in wrong state %08lx",
  10977. UnMapId(Id), (char *)(FILE_), __LINE__, plci_b_id));
  10978. PUT_WORD(p_result, _REQUEST_NOT_ALLOWED_IN_THIS_STATE);
  10979. return (NULL);
  10980. }
  10981. li_config_table[plci_b->adapter->li_base + (plci_b->li_bchannel_id - 1)].plci = plci_b;
  10982. if (((byte)(plci_b_id & ~EXT_CONTROLLER)) !=
  10983. ((byte)(UnMapController(plci->adapter->Id) & ~EXT_CONTROLLER))
  10984. && (!(plci->adapter->manufacturer_features & MANUFACTURER_FEATURE_XCONNECT)
  10985. || !(plci_b->adapter->manufacturer_features & MANUFACTURER_FEATURE_XCONNECT)))
  10986. {
  10987. dbug(1, dprintf("[%06lx] %s,%d: LI not on same ctrl %08lx",
  10988. UnMapId(Id), (char *)(FILE_), __LINE__, plci_b_id));
  10989. PUT_WORD(p_result, _WRONG_IDENTIFIER);
  10990. return (NULL);
  10991. }
  10992. if (!(get_b1_facilities(plci_b, add_b1_facilities(plci_b, plci_b->B1_resource,
  10993. (word)(plci_b->B1_facilities | B1_FACILITY_MIXER))) & B1_FACILITY_MIXER))
  10994. {
  10995. dbug(1, dprintf("[%06lx] %s,%d: Interconnect peer cannot mix %d",
  10996. UnMapId(Id), (char *)(FILE_), __LINE__, plci_b->B1_resource));
  10997. PUT_WORD(p_result, _REQUEST_NOT_ALLOWED_IN_THIS_STATE);
  10998. return (NULL);
  10999. }
  11000. return (plci_b);
  11001. }
  11002. static PLCI *li2_check_plci_b(dword Id, PLCI *plci,
  11003. dword plci_b_id, word plci_b_write_pos, byte *p_result)
  11004. {
  11005. byte ctlr_b;
  11006. PLCI *plci_b;
  11007. if (((plci->li_plci_b_read_pos > plci_b_write_pos) ? plci->li_plci_b_read_pos :
  11008. LI_PLCI_B_QUEUE_ENTRIES + plci->li_plci_b_read_pos) - plci_b_write_pos - 1 < 2)
  11009. {
  11010. dbug(1, dprintf("[%06lx] %s,%d: LI request overrun",
  11011. UnMapId(Id), (char *)(FILE_), __LINE__));
  11012. PUT_WORD(p_result, _WRONG_STATE);
  11013. return (NULL);
  11014. }
  11015. ctlr_b = 0;
  11016. if ((plci_b_id & 0x7f) != 0)
  11017. {
  11018. ctlr_b = MapController((byte)(plci_b_id & 0x7f));
  11019. if ((ctlr_b > max_adapter) || ((ctlr_b != 0) && (adapter[ctlr_b - 1].request == NULL)))
  11020. ctlr_b = 0;
  11021. }
  11022. if ((ctlr_b == 0)
  11023. || (((plci_b_id >> 8) & 0xff) == 0)
  11024. || (((plci_b_id >> 8) & 0xff) > adapter[ctlr_b - 1].max_plci))
  11025. {
  11026. dbug(1, dprintf("[%06lx] %s,%d: LI invalid second PLCI %08lx",
  11027. UnMapId(Id), (char *)(FILE_), __LINE__, plci_b_id));
  11028. PUT_WORD(p_result, _WRONG_IDENTIFIER);
  11029. return (NULL);
  11030. }
  11031. plci_b = &(adapter[ctlr_b - 1].plci[((plci_b_id >> 8) & 0xff) - 1]);
  11032. if (!plci_b->State
  11033. || !plci_b->NL.Id || plci_b->nl_remove_id
  11034. || (plci_b->li_bchannel_id == 0)
  11035. || (li_config_table[plci_b->adapter->li_base + (plci_b->li_bchannel_id - 1)].plci != plci_b))
  11036. {
  11037. dbug(1, dprintf("[%06lx] %s,%d: LI peer in wrong state %08lx",
  11038. UnMapId(Id), (char *)(FILE_), __LINE__, plci_b_id));
  11039. PUT_WORD(p_result, _WRONG_STATE);
  11040. return (NULL);
  11041. }
  11042. if (((byte)(plci_b_id & ~EXT_CONTROLLER)) !=
  11043. ((byte)(UnMapController(plci->adapter->Id) & ~EXT_CONTROLLER))
  11044. && (!(plci->adapter->manufacturer_features & MANUFACTURER_FEATURE_XCONNECT)
  11045. || !(plci_b->adapter->manufacturer_features & MANUFACTURER_FEATURE_XCONNECT)))
  11046. {
  11047. dbug(1, dprintf("[%06lx] %s,%d: LI not on same ctrl %08lx",
  11048. UnMapId(Id), (char *)(FILE_), __LINE__, plci_b_id));
  11049. PUT_WORD(p_result, _WRONG_IDENTIFIER);
  11050. return (NULL);
  11051. }
  11052. if (!(get_b1_facilities(plci_b, add_b1_facilities(plci_b, plci_b->B1_resource,
  11053. (word)(plci_b->B1_facilities | B1_FACILITY_MIXER))) & B1_FACILITY_MIXER))
  11054. {
  11055. dbug(1, dprintf("[%06lx] %s,%d: Interconnect peer cannot mix %d",
  11056. UnMapId(Id), (char *)(FILE_), __LINE__, plci_b->B1_resource));
  11057. PUT_WORD(p_result, _WRONG_STATE);
  11058. return (NULL);
  11059. }
  11060. return (plci_b);
  11061. }
  11062. static byte mixer_request(dword Id, word Number, DIVA_CAPI_ADAPTER *a, PLCI *plci, APPL *appl, API_PARSE *msg)
  11063. {
  11064. word Info;
  11065. word i;
  11066. dword d, li_flags, plci_b_id;
  11067. PLCI *plci_b;
  11068. API_PARSE li_parms[3];
  11069. API_PARSE li_req_parms[3];
  11070. API_PARSE li_participant_struct[2];
  11071. API_PARSE li_participant_parms[3];
  11072. word participant_parms_pos;
  11073. byte result_buffer[32];
  11074. byte *result;
  11075. word result_pos;
  11076. word plci_b_write_pos;
  11077. dbug(1, dprintf("[%06lx] %s,%d: mixer_request",
  11078. UnMapId(Id), (char *)(FILE_), __LINE__));
  11079. Info = GOOD;
  11080. result = result_buffer;
  11081. result_buffer[0] = 0;
  11082. if (!(a->profile.Global_Options & GL_LINE_INTERCONNECT_SUPPORTED))
  11083. {
  11084. dbug(1, dprintf("[%06lx] %s,%d: Facility not supported",
  11085. UnMapId(Id), (char *)(FILE_), __LINE__));
  11086. Info = _FACILITY_NOT_SUPPORTED;
  11087. }
  11088. else if (api_parse(&msg[1].info[1], msg[1].length, "ws", li_parms))
  11089. {
  11090. dbug(1, dprintf("[%06lx] %s,%d: Wrong message format",
  11091. UnMapId(Id), (char *)(FILE_), __LINE__));
  11092. Info = _WRONG_MESSAGE_FORMAT;
  11093. }
  11094. else
  11095. {
  11096. result_buffer[0] = 3;
  11097. PUT_WORD(&result_buffer[1], GET_WORD(li_parms[0].info));
  11098. result_buffer[3] = 0;
  11099. switch (GET_WORD(li_parms[0].info))
  11100. {
  11101. case LI_GET_SUPPORTED_SERVICES:
  11102. if (appl->appl_flags & APPL_FLAG_OLD_LI_SPEC)
  11103. {
  11104. result_buffer[0] = 17;
  11105. result_buffer[3] = 14;
  11106. PUT_WORD(&result_buffer[4], GOOD);
  11107. d = 0;
  11108. if (a->manufacturer_features & MANUFACTURER_FEATURE_MIXER_CH_CH)
  11109. d |= LI_CONFERENCING_SUPPORTED;
  11110. if (a->manufacturer_features & MANUFACTURER_FEATURE_MIXER_CH_PC)
  11111. d |= LI_MONITORING_SUPPORTED;
  11112. if (a->manufacturer_features & MANUFACTURER_FEATURE_MIXER_PC_CH)
  11113. d |= LI_ANNOUNCEMENTS_SUPPORTED | LI_MIXING_SUPPORTED;
  11114. if (a->manufacturer_features & MANUFACTURER_FEATURE_XCONNECT)
  11115. d |= LI_CROSS_CONTROLLER_SUPPORTED;
  11116. PUT_DWORD(&result_buffer[6], d);
  11117. if (a->manufacturer_features & MANUFACTURER_FEATURE_XCONNECT)
  11118. {
  11119. d = 0;
  11120. for (i = 0; i < li_total_channels; i++)
  11121. {
  11122. if ((li_config_table[i].adapter->manufacturer_features & MANUFACTURER_FEATURE_XCONNECT)
  11123. && (li_config_table[i].adapter->li_pri
  11124. || (i < li_config_table[i].adapter->li_base + MIXER_BCHANNELS_BRI)))
  11125. {
  11126. d++;
  11127. }
  11128. }
  11129. }
  11130. else
  11131. {
  11132. d = a->li_pri ? a->li_channels : MIXER_BCHANNELS_BRI;
  11133. }
  11134. PUT_DWORD(&result_buffer[10], d / 2);
  11135. PUT_DWORD(&result_buffer[14], d);
  11136. }
  11137. else
  11138. {
  11139. result_buffer[0] = 25;
  11140. result_buffer[3] = 22;
  11141. PUT_WORD(&result_buffer[4], GOOD);
  11142. d = LI2_ASYMMETRIC_SUPPORTED | LI2_B_LOOPING_SUPPORTED | LI2_X_LOOPING_SUPPORTED;
  11143. if (a->manufacturer_features & MANUFACTURER_FEATURE_MIXER_CH_PC)
  11144. d |= LI2_MONITORING_SUPPORTED | LI2_REMOTE_MONITORING_SUPPORTED;
  11145. if (a->manufacturer_features & MANUFACTURER_FEATURE_MIXER_PC_CH)
  11146. d |= LI2_MIXING_SUPPORTED | LI2_REMOTE_MIXING_SUPPORTED;
  11147. if (a->manufacturer_features & MANUFACTURER_FEATURE_MIXER_PC_PC)
  11148. d |= LI2_PC_LOOPING_SUPPORTED;
  11149. if (a->manufacturer_features & MANUFACTURER_FEATURE_XCONNECT)
  11150. d |= LI2_CROSS_CONTROLLER_SUPPORTED;
  11151. PUT_DWORD(&result_buffer[6], d);
  11152. d = a->li_pri ? a->li_channels : MIXER_BCHANNELS_BRI;
  11153. PUT_DWORD(&result_buffer[10], d / 2);
  11154. PUT_DWORD(&result_buffer[14], d - 1);
  11155. if (a->manufacturer_features & MANUFACTURER_FEATURE_XCONNECT)
  11156. {
  11157. d = 0;
  11158. for (i = 0; i < li_total_channels; i++)
  11159. {
  11160. if ((li_config_table[i].adapter->manufacturer_features & MANUFACTURER_FEATURE_XCONNECT)
  11161. && (li_config_table[i].adapter->li_pri
  11162. || (i < li_config_table[i].adapter->li_base + MIXER_BCHANNELS_BRI)))
  11163. {
  11164. d++;
  11165. }
  11166. }
  11167. }
  11168. PUT_DWORD(&result_buffer[18], d / 2);
  11169. PUT_DWORD(&result_buffer[22], d - 1);
  11170. }
  11171. break;
  11172. case LI_REQ_CONNECT:
  11173. if (li_parms[1].length == 8)
  11174. {
  11175. appl->appl_flags |= APPL_FLAG_OLD_LI_SPEC;
  11176. if (api_parse(&li_parms[1].info[1], li_parms[1].length, "dd", li_req_parms))
  11177. {
  11178. dbug(1, dprintf("[%06lx] %s,%d: Wrong message format",
  11179. UnMapId(Id), (char *)(FILE_), __LINE__));
  11180. Info = _WRONG_MESSAGE_FORMAT;
  11181. break;
  11182. }
  11183. plci_b_id = GET_DWORD(li_req_parms[0].info) & 0xffff;
  11184. li_flags = GET_DWORD(li_req_parms[1].info);
  11185. Info = li_check_main_plci(Id, plci);
  11186. result_buffer[0] = 9;
  11187. result_buffer[3] = 6;
  11188. PUT_DWORD(&result_buffer[4], plci_b_id);
  11189. PUT_WORD(&result_buffer[8], GOOD);
  11190. if (Info != GOOD)
  11191. break;
  11192. result = plci->saved_msg.info;
  11193. for (i = 0; i <= result_buffer[0]; i++)
  11194. result[i] = result_buffer[i];
  11195. plci_b_write_pos = plci->li_plci_b_write_pos;
  11196. plci_b = li_check_plci_b(Id, plci, plci_b_id, plci_b_write_pos, &result[8]);
  11197. if (plci_b == NULL)
  11198. break;
  11199. li_update_connect(Id, a, plci, plci_b_id, true, li_flags);
  11200. plci->li_plci_b_queue[plci_b_write_pos] = plci_b_id | LI_PLCI_B_LAST_FLAG;
  11201. plci_b_write_pos = (plci_b_write_pos == LI_PLCI_B_QUEUE_ENTRIES - 1) ? 0 : plci_b_write_pos + 1;
  11202. plci->li_plci_b_write_pos = plci_b_write_pos;
  11203. }
  11204. else
  11205. {
  11206. appl->appl_flags &= ~APPL_FLAG_OLD_LI_SPEC;
  11207. if (api_parse(&li_parms[1].info[1], li_parms[1].length, "ds", li_req_parms))
  11208. {
  11209. dbug(1, dprintf("[%06lx] %s,%d: Wrong message format",
  11210. UnMapId(Id), (char *)(FILE_), __LINE__));
  11211. Info = _WRONG_MESSAGE_FORMAT;
  11212. break;
  11213. }
  11214. li_flags = GET_DWORD(li_req_parms[0].info) & ~(LI2_FLAG_INTERCONNECT_A_B | LI2_FLAG_INTERCONNECT_B_A);
  11215. Info = li_check_main_plci(Id, plci);
  11216. result_buffer[0] = 7;
  11217. result_buffer[3] = 4;
  11218. PUT_WORD(&result_buffer[4], Info);
  11219. result_buffer[6] = 0;
  11220. if (Info != GOOD)
  11221. break;
  11222. result = plci->saved_msg.info;
  11223. for (i = 0; i <= result_buffer[0]; i++)
  11224. result[i] = result_buffer[i];
  11225. plci_b_write_pos = plci->li_plci_b_write_pos;
  11226. participant_parms_pos = 0;
  11227. result_pos = 7;
  11228. li2_update_connect(Id, a, plci, UnMapId(Id), true, li_flags);
  11229. while (participant_parms_pos < li_req_parms[1].length)
  11230. {
  11231. result[result_pos] = 6;
  11232. result_pos += 7;
  11233. PUT_DWORD(&result[result_pos - 6], 0);
  11234. PUT_WORD(&result[result_pos - 2], GOOD);
  11235. if (api_parse(&li_req_parms[1].info[1 + participant_parms_pos],
  11236. (word)(li_parms[1].length - participant_parms_pos), "s", li_participant_struct))
  11237. {
  11238. dbug(1, dprintf("[%06lx] %s,%d: Wrong message format",
  11239. UnMapId(Id), (char *)(FILE_), __LINE__));
  11240. PUT_WORD(&result[result_pos - 2], _WRONG_MESSAGE_FORMAT);
  11241. break;
  11242. }
  11243. if (api_parse(&li_participant_struct[0].info[1],
  11244. li_participant_struct[0].length, "dd", li_participant_parms))
  11245. {
  11246. dbug(1, dprintf("[%06lx] %s,%d: Wrong message format",
  11247. UnMapId(Id), (char *)(FILE_), __LINE__));
  11248. PUT_WORD(&result[result_pos - 2], _WRONG_MESSAGE_FORMAT);
  11249. break;
  11250. }
  11251. plci_b_id = GET_DWORD(li_participant_parms[0].info) & 0xffff;
  11252. li_flags = GET_DWORD(li_participant_parms[1].info);
  11253. PUT_DWORD(&result[result_pos - 6], plci_b_id);
  11254. if (sizeof(result) - result_pos < 7)
  11255. {
  11256. dbug(1, dprintf("[%06lx] %s,%d: LI result overrun",
  11257. UnMapId(Id), (char *)(FILE_), __LINE__));
  11258. PUT_WORD(&result[result_pos - 2], _WRONG_STATE);
  11259. break;
  11260. }
  11261. plci_b = li2_check_plci_b(Id, plci, plci_b_id, plci_b_write_pos, &result[result_pos - 2]);
  11262. if (plci_b != NULL)
  11263. {
  11264. li2_update_connect(Id, a, plci, plci_b_id, true, li_flags);
  11265. plci->li_plci_b_queue[plci_b_write_pos] = plci_b_id |
  11266. ((li_flags & (LI2_FLAG_INTERCONNECT_A_B | LI2_FLAG_INTERCONNECT_B_A |
  11267. LI2_FLAG_PCCONNECT_A_B | LI2_FLAG_PCCONNECT_B_A)) ? 0 : LI_PLCI_B_DISC_FLAG);
  11268. plci_b_write_pos = (plci_b_write_pos == LI_PLCI_B_QUEUE_ENTRIES - 1) ? 0 : plci_b_write_pos + 1;
  11269. }
  11270. participant_parms_pos = (word)((&li_participant_struct[0].info[1 + li_participant_struct[0].length]) -
  11271. (&li_req_parms[1].info[1]));
  11272. }
  11273. result[0] = (byte)(result_pos - 1);
  11274. result[3] = (byte)(result_pos - 4);
  11275. result[6] = (byte)(result_pos - 7);
  11276. i = (plci_b_write_pos == 0) ? LI_PLCI_B_QUEUE_ENTRIES - 1 : plci_b_write_pos - 1;
  11277. if ((plci_b_write_pos == plci->li_plci_b_read_pos)
  11278. || (plci->li_plci_b_queue[i] & LI_PLCI_B_LAST_FLAG))
  11279. {
  11280. plci->li_plci_b_queue[plci_b_write_pos] = LI_PLCI_B_SKIP_FLAG | LI_PLCI_B_LAST_FLAG;
  11281. plci_b_write_pos = (plci_b_write_pos == LI_PLCI_B_QUEUE_ENTRIES - 1) ? 0 : plci_b_write_pos + 1;
  11282. }
  11283. else
  11284. plci->li_plci_b_queue[i] |= LI_PLCI_B_LAST_FLAG;
  11285. plci->li_plci_b_write_pos = plci_b_write_pos;
  11286. }
  11287. mixer_calculate_coefs(a);
  11288. plci->li_channel_bits = li_config_table[a->li_base + (plci->li_bchannel_id - 1)].channel;
  11289. mixer_notify_update(plci, true);
  11290. sendf(appl, _FACILITY_R | CONFIRM, Id & 0xffffL, Number,
  11291. "wwS", Info, SELECTOR_LINE_INTERCONNECT, result);
  11292. plci->command = 0;
  11293. plci->li_cmd = GET_WORD(li_parms[0].info);
  11294. start_internal_command(Id, plci, mixer_command);
  11295. return (false);
  11296. case LI_REQ_DISCONNECT:
  11297. if (li_parms[1].length == 4)
  11298. {
  11299. appl->appl_flags |= APPL_FLAG_OLD_LI_SPEC;
  11300. if (api_parse(&li_parms[1].info[1], li_parms[1].length, "d", li_req_parms))
  11301. {
  11302. dbug(1, dprintf("[%06lx] %s,%d: Wrong message format",
  11303. UnMapId(Id), (char *)(FILE_), __LINE__));
  11304. Info = _WRONG_MESSAGE_FORMAT;
  11305. break;
  11306. }
  11307. plci_b_id = GET_DWORD(li_req_parms[0].info) & 0xffff;
  11308. Info = li_check_main_plci(Id, plci);
  11309. result_buffer[0] = 9;
  11310. result_buffer[3] = 6;
  11311. PUT_DWORD(&result_buffer[4], GET_DWORD(li_req_parms[0].info));
  11312. PUT_WORD(&result_buffer[8], GOOD);
  11313. if (Info != GOOD)
  11314. break;
  11315. result = plci->saved_msg.info;
  11316. for (i = 0; i <= result_buffer[0]; i++)
  11317. result[i] = result_buffer[i];
  11318. plci_b_write_pos = plci->li_plci_b_write_pos;
  11319. plci_b = li_check_plci_b(Id, plci, plci_b_id, plci_b_write_pos, &result[8]);
  11320. if (plci_b == NULL)
  11321. break;
  11322. li_update_connect(Id, a, plci, plci_b_id, false, 0);
  11323. plci->li_plci_b_queue[plci_b_write_pos] = plci_b_id | LI_PLCI_B_DISC_FLAG | LI_PLCI_B_LAST_FLAG;
  11324. plci_b_write_pos = (plci_b_write_pos == LI_PLCI_B_QUEUE_ENTRIES - 1) ? 0 : plci_b_write_pos + 1;
  11325. plci->li_plci_b_write_pos = plci_b_write_pos;
  11326. }
  11327. else
  11328. {
  11329. appl->appl_flags &= ~APPL_FLAG_OLD_LI_SPEC;
  11330. if (api_parse(&li_parms[1].info[1], li_parms[1].length, "s", li_req_parms))
  11331. {
  11332. dbug(1, dprintf("[%06lx] %s,%d: Wrong message format",
  11333. UnMapId(Id), (char *)(FILE_), __LINE__));
  11334. Info = _WRONG_MESSAGE_FORMAT;
  11335. break;
  11336. }
  11337. Info = li_check_main_plci(Id, plci);
  11338. result_buffer[0] = 7;
  11339. result_buffer[3] = 4;
  11340. PUT_WORD(&result_buffer[4], Info);
  11341. result_buffer[6] = 0;
  11342. if (Info != GOOD)
  11343. break;
  11344. result = plci->saved_msg.info;
  11345. for (i = 0; i <= result_buffer[0]; i++)
  11346. result[i] = result_buffer[i];
  11347. plci_b_write_pos = plci->li_plci_b_write_pos;
  11348. participant_parms_pos = 0;
  11349. result_pos = 7;
  11350. while (participant_parms_pos < li_req_parms[0].length)
  11351. {
  11352. result[result_pos] = 6;
  11353. result_pos += 7;
  11354. PUT_DWORD(&result[result_pos - 6], 0);
  11355. PUT_WORD(&result[result_pos - 2], GOOD);
  11356. if (api_parse(&li_req_parms[0].info[1 + participant_parms_pos],
  11357. (word)(li_parms[1].length - participant_parms_pos), "s", li_participant_struct))
  11358. {
  11359. dbug(1, dprintf("[%06lx] %s,%d: Wrong message format",
  11360. UnMapId(Id), (char *)(FILE_), __LINE__));
  11361. PUT_WORD(&result[result_pos - 2], _WRONG_MESSAGE_FORMAT);
  11362. break;
  11363. }
  11364. if (api_parse(&li_participant_struct[0].info[1],
  11365. li_participant_struct[0].length, "d", li_participant_parms))
  11366. {
  11367. dbug(1, dprintf("[%06lx] %s,%d: Wrong message format",
  11368. UnMapId(Id), (char *)(FILE_), __LINE__));
  11369. PUT_WORD(&result[result_pos - 2], _WRONG_MESSAGE_FORMAT);
  11370. break;
  11371. }
  11372. plci_b_id = GET_DWORD(li_participant_parms[0].info) & 0xffff;
  11373. PUT_DWORD(&result[result_pos - 6], plci_b_id);
  11374. if (sizeof(result) - result_pos < 7)
  11375. {
  11376. dbug(1, dprintf("[%06lx] %s,%d: LI result overrun",
  11377. UnMapId(Id), (char *)(FILE_), __LINE__));
  11378. PUT_WORD(&result[result_pos - 2], _WRONG_STATE);
  11379. break;
  11380. }
  11381. plci_b = li2_check_plci_b(Id, plci, plci_b_id, plci_b_write_pos, &result[result_pos - 2]);
  11382. if (plci_b != NULL)
  11383. {
  11384. li2_update_connect(Id, a, plci, plci_b_id, false, 0);
  11385. plci->li_plci_b_queue[plci_b_write_pos] = plci_b_id | LI_PLCI_B_DISC_FLAG;
  11386. plci_b_write_pos = (plci_b_write_pos == LI_PLCI_B_QUEUE_ENTRIES - 1) ? 0 : plci_b_write_pos + 1;
  11387. }
  11388. participant_parms_pos = (word)((&li_participant_struct[0].info[1 + li_participant_struct[0].length]) -
  11389. (&li_req_parms[0].info[1]));
  11390. }
  11391. result[0] = (byte)(result_pos - 1);
  11392. result[3] = (byte)(result_pos - 4);
  11393. result[6] = (byte)(result_pos - 7);
  11394. i = (plci_b_write_pos == 0) ? LI_PLCI_B_QUEUE_ENTRIES - 1 : plci_b_write_pos - 1;
  11395. if ((plci_b_write_pos == plci->li_plci_b_read_pos)
  11396. || (plci->li_plci_b_queue[i] & LI_PLCI_B_LAST_FLAG))
  11397. {
  11398. plci->li_plci_b_queue[plci_b_write_pos] = LI_PLCI_B_SKIP_FLAG | LI_PLCI_B_LAST_FLAG;
  11399. plci_b_write_pos = (plci_b_write_pos == LI_PLCI_B_QUEUE_ENTRIES - 1) ? 0 : plci_b_write_pos + 1;
  11400. }
  11401. else
  11402. plci->li_plci_b_queue[i] |= LI_PLCI_B_LAST_FLAG;
  11403. plci->li_plci_b_write_pos = plci_b_write_pos;
  11404. }
  11405. mixer_calculate_coefs(a);
  11406. plci->li_channel_bits = li_config_table[a->li_base + (plci->li_bchannel_id - 1)].channel;
  11407. mixer_notify_update(plci, true);
  11408. sendf(appl, _FACILITY_R | CONFIRM, Id & 0xffffL, Number,
  11409. "wwS", Info, SELECTOR_LINE_INTERCONNECT, result);
  11410. plci->command = 0;
  11411. plci->li_cmd = GET_WORD(li_parms[0].info);
  11412. start_internal_command(Id, plci, mixer_command);
  11413. return (false);
  11414. case LI_REQ_SILENT_UPDATE:
  11415. if (!plci || !plci->State
  11416. || !plci->NL.Id || plci->nl_remove_id
  11417. || (plci->li_bchannel_id == 0)
  11418. || (li_config_table[plci->adapter->li_base + (plci->li_bchannel_id - 1)].plci != plci))
  11419. {
  11420. dbug(1, dprintf("[%06lx] %s,%d: Wrong state",
  11421. UnMapId(Id), (char *)(FILE_), __LINE__));
  11422. return (false);
  11423. }
  11424. plci_b_write_pos = plci->li_plci_b_write_pos;
  11425. if (((plci->li_plci_b_read_pos > plci_b_write_pos) ? plci->li_plci_b_read_pos :
  11426. LI_PLCI_B_QUEUE_ENTRIES + plci->li_plci_b_read_pos) - plci_b_write_pos - 1 < 2)
  11427. {
  11428. dbug(1, dprintf("[%06lx] %s,%d: LI request overrun",
  11429. UnMapId(Id), (char *)(FILE_), __LINE__));
  11430. return (false);
  11431. }
  11432. i = (plci_b_write_pos == 0) ? LI_PLCI_B_QUEUE_ENTRIES - 1 : plci_b_write_pos - 1;
  11433. if ((plci_b_write_pos == plci->li_plci_b_read_pos)
  11434. || (plci->li_plci_b_queue[i] & LI_PLCI_B_LAST_FLAG))
  11435. {
  11436. plci->li_plci_b_queue[plci_b_write_pos] = LI_PLCI_B_SKIP_FLAG | LI_PLCI_B_LAST_FLAG;
  11437. plci_b_write_pos = (plci_b_write_pos == LI_PLCI_B_QUEUE_ENTRIES - 1) ? 0 : plci_b_write_pos + 1;
  11438. }
  11439. else
  11440. plci->li_plci_b_queue[i] |= LI_PLCI_B_LAST_FLAG;
  11441. plci->li_plci_b_write_pos = plci_b_write_pos;
  11442. plci->li_channel_bits = li_config_table[a->li_base + (plci->li_bchannel_id - 1)].channel;
  11443. plci->command = 0;
  11444. plci->li_cmd = GET_WORD(li_parms[0].info);
  11445. start_internal_command(Id, plci, mixer_command);
  11446. return (false);
  11447. default:
  11448. dbug(1, dprintf("[%06lx] %s,%d: LI unknown request %04x",
  11449. UnMapId(Id), (char *)(FILE_), __LINE__, GET_WORD(li_parms[0].info)));
  11450. Info = _FACILITY_NOT_SUPPORTED;
  11451. }
  11452. }
  11453. sendf(appl, _FACILITY_R | CONFIRM, Id & 0xffffL, Number,
  11454. "wwS", Info, SELECTOR_LINE_INTERCONNECT, result);
  11455. return (false);
  11456. }
  11457. static void mixer_indication_coefs_set(dword Id, PLCI *plci)
  11458. {
  11459. dword d;
  11460. byte result[12];
  11461. dbug(1, dprintf("[%06lx] %s,%d: mixer_indication_coefs_set",
  11462. UnMapId(Id), (char *)(FILE_), __LINE__));
  11463. if (plci->li_plci_b_read_pos != plci->li_plci_b_req_pos)
  11464. {
  11465. do
  11466. {
  11467. d = plci->li_plci_b_queue[plci->li_plci_b_read_pos];
  11468. if (!(d & LI_PLCI_B_SKIP_FLAG))
  11469. {
  11470. if (plci->appl->appl_flags & APPL_FLAG_OLD_LI_SPEC)
  11471. {
  11472. if (d & LI_PLCI_B_DISC_FLAG)
  11473. {
  11474. result[0] = 5;
  11475. PUT_WORD(&result[1], LI_IND_DISCONNECT);
  11476. result[3] = 2;
  11477. PUT_WORD(&result[4], _LI_USER_INITIATED);
  11478. }
  11479. else
  11480. {
  11481. result[0] = 7;
  11482. PUT_WORD(&result[1], LI_IND_CONNECT_ACTIVE);
  11483. result[3] = 4;
  11484. PUT_DWORD(&result[4], d & ~LI_PLCI_B_FLAG_MASK);
  11485. }
  11486. }
  11487. else
  11488. {
  11489. if (d & LI_PLCI_B_DISC_FLAG)
  11490. {
  11491. result[0] = 9;
  11492. PUT_WORD(&result[1], LI_IND_DISCONNECT);
  11493. result[3] = 6;
  11494. PUT_DWORD(&result[4], d & ~LI_PLCI_B_FLAG_MASK);
  11495. PUT_WORD(&result[8], _LI_USER_INITIATED);
  11496. }
  11497. else
  11498. {
  11499. result[0] = 7;
  11500. PUT_WORD(&result[1], LI_IND_CONNECT_ACTIVE);
  11501. result[3] = 4;
  11502. PUT_DWORD(&result[4], d & ~LI_PLCI_B_FLAG_MASK);
  11503. }
  11504. }
  11505. sendf(plci->appl, _FACILITY_I, Id & 0xffffL, 0,
  11506. "ws", SELECTOR_LINE_INTERCONNECT, result);
  11507. }
  11508. plci->li_plci_b_read_pos = (plci->li_plci_b_read_pos == LI_PLCI_B_QUEUE_ENTRIES - 1) ?
  11509. 0 : plci->li_plci_b_read_pos + 1;
  11510. } while (!(d & LI_PLCI_B_LAST_FLAG) && (plci->li_plci_b_read_pos != plci->li_plci_b_req_pos));
  11511. }
  11512. }
  11513. static void mixer_indication_xconnect_from(dword Id, PLCI *plci, byte *msg, word length)
  11514. {
  11515. word i, j, ch;
  11516. struct xconnect_transfer_address_s s, *p;
  11517. DIVA_CAPI_ADAPTER *a;
  11518. dbug(1, dprintf("[%06lx] %s,%d: mixer_indication_xconnect_from %d",
  11519. UnMapId(Id), (char *)(FILE_), __LINE__, (int)length));
  11520. a = plci->adapter;
  11521. i = 1;
  11522. for (i = 1; i < length; i += 16)
  11523. {
  11524. s.card_address.low = msg[i] | (msg[i + 1] << 8) | (((dword)(msg[i + 2])) << 16) | (((dword)(msg[i + 3])) << 24);
  11525. s.card_address.high = msg[i + 4] | (msg[i + 5] << 8) | (((dword)(msg[i + 6])) << 16) | (((dword)(msg[i + 7])) << 24);
  11526. s.offset = msg[i + 8] | (msg[i + 9] << 8) | (((dword)(msg[i + 10])) << 16) | (((dword)(msg[i + 11])) << 24);
  11527. ch = msg[i + 12] | (msg[i + 13] << 8);
  11528. j = ch & XCONNECT_CHANNEL_NUMBER_MASK;
  11529. if (!a->li_pri && (plci->li_bchannel_id == 2))
  11530. j = 1 - j;
  11531. j += a->li_base;
  11532. if (ch & XCONNECT_CHANNEL_PORT_PC)
  11533. p = &(li_config_table[j].send_pc);
  11534. else
  11535. p = &(li_config_table[j].send_b);
  11536. p->card_address.low = s.card_address.low;
  11537. p->card_address.high = s.card_address.high;
  11538. p->offset = s.offset;
  11539. li_config_table[j].channel |= LI_CHANNEL_ADDRESSES_SET;
  11540. }
  11541. if (plci->internal_command_queue[0]
  11542. && ((plci->adjust_b_state == ADJUST_B_RESTORE_MIXER_2)
  11543. || (plci->adjust_b_state == ADJUST_B_RESTORE_MIXER_3)
  11544. || (plci->adjust_b_state == ADJUST_B_RESTORE_MIXER_4)))
  11545. {
  11546. (*(plci->internal_command_queue[0]))(Id, plci, 0);
  11547. if (!plci->internal_command)
  11548. next_internal_command(Id, plci);
  11549. }
  11550. mixer_notify_update(plci, true);
  11551. }
  11552. static void mixer_indication_xconnect_to(dword Id, PLCI *plci, byte *msg, word length)
  11553. {
  11554. dbug(1, dprintf("[%06lx] %s,%d: mixer_indication_xconnect_to %d",
  11555. UnMapId(Id), (char *)(FILE_), __LINE__, (int) length));
  11556. }
  11557. static byte mixer_notify_source_removed(PLCI *plci, dword plci_b_id)
  11558. {
  11559. word plci_b_write_pos;
  11560. plci_b_write_pos = plci->li_plci_b_write_pos;
  11561. if (((plci->li_plci_b_read_pos > plci_b_write_pos) ? plci->li_plci_b_read_pos :
  11562. LI_PLCI_B_QUEUE_ENTRIES + plci->li_plci_b_read_pos) - plci_b_write_pos - 1 < 1)
  11563. {
  11564. dbug(1, dprintf("[%06lx] %s,%d: LI request overrun",
  11565. (dword)((plci->Id << 8) | UnMapController(plci->adapter->Id)),
  11566. (char *)(FILE_), __LINE__));
  11567. return (false);
  11568. }
  11569. plci->li_plci_b_queue[plci_b_write_pos] = plci_b_id | LI_PLCI_B_DISC_FLAG;
  11570. plci_b_write_pos = (plci_b_write_pos == LI_PLCI_B_QUEUE_ENTRIES - 1) ? 0 : plci_b_write_pos + 1;
  11571. plci->li_plci_b_write_pos = plci_b_write_pos;
  11572. return (true);
  11573. }
  11574. static void mixer_remove(PLCI *plci)
  11575. {
  11576. DIVA_CAPI_ADAPTER *a;
  11577. PLCI *notify_plci;
  11578. dword plci_b_id;
  11579. word i, j;
  11580. dbug(1, dprintf("[%06lx] %s,%d: mixer_remove",
  11581. (dword)((plci->Id << 8) | UnMapController(plci->adapter->Id)),
  11582. (char *)(FILE_), __LINE__));
  11583. a = plci->adapter;
  11584. plci_b_id = (plci->Id << 8) | UnMapController(plci->adapter->Id);
  11585. if (a->profile.Global_Options & GL_LINE_INTERCONNECT_SUPPORTED)
  11586. {
  11587. if ((plci->li_bchannel_id != 0)
  11588. && (li_config_table[a->li_base + (plci->li_bchannel_id - 1)].plci == plci))
  11589. {
  11590. i = a->li_base + (plci->li_bchannel_id - 1);
  11591. if ((li_config_table[i].curchnl | li_config_table[i].channel) & LI_CHANNEL_INVOLVED)
  11592. {
  11593. for (j = 0; j < li_total_channels; j++)
  11594. {
  11595. if ((li_config_table[i].flag_table[j] & LI_FLAG_INTERCONNECT)
  11596. || (li_config_table[j].flag_table[i] & LI_FLAG_INTERCONNECT))
  11597. {
  11598. notify_plci = li_config_table[j].plci;
  11599. if ((notify_plci != NULL)
  11600. && (notify_plci != plci)
  11601. && (notify_plci->appl != NULL)
  11602. && !(notify_plci->appl->appl_flags & APPL_FLAG_OLD_LI_SPEC)
  11603. && (notify_plci->State)
  11604. && notify_plci->NL.Id && !notify_plci->nl_remove_id)
  11605. {
  11606. mixer_notify_source_removed(notify_plci, plci_b_id);
  11607. }
  11608. }
  11609. }
  11610. mixer_clear_config(plci);
  11611. mixer_calculate_coefs(a);
  11612. mixer_notify_update(plci, true);
  11613. }
  11614. li_config_table[i].plci = NULL;
  11615. plci->li_bchannel_id = 0;
  11616. }
  11617. }
  11618. }
  11619. /*------------------------------------------------------------------*/
  11620. /* Echo canceller facilities */
  11621. /*------------------------------------------------------------------*/
  11622. static void ec_write_parameters(PLCI *plci)
  11623. {
  11624. word w;
  11625. byte parameter_buffer[6];
  11626. dbug(1, dprintf("[%06lx] %s,%d: ec_write_parameters",
  11627. (dword)((plci->Id << 8) | UnMapController(plci->adapter->Id)),
  11628. (char *)(FILE_), __LINE__));
  11629. parameter_buffer[0] = 5;
  11630. parameter_buffer[1] = DSP_CTRL_SET_LEC_PARAMETERS;
  11631. PUT_WORD(&parameter_buffer[2], plci->ec_idi_options);
  11632. plci->ec_idi_options &= ~LEC_RESET_COEFFICIENTS;
  11633. w = (plci->ec_tail_length == 0) ? 128 : plci->ec_tail_length;
  11634. PUT_WORD(&parameter_buffer[4], w);
  11635. add_p(plci, FTY, parameter_buffer);
  11636. sig_req(plci, TEL_CTRL, 0);
  11637. send_req(plci);
  11638. }
  11639. static void ec_clear_config(PLCI *plci)
  11640. {
  11641. dbug(1, dprintf("[%06lx] %s,%d: ec_clear_config",
  11642. (dword)((plci->Id << 8) | UnMapController(plci->adapter->Id)),
  11643. (char *)(FILE_), __LINE__));
  11644. plci->ec_idi_options = LEC_ENABLE_ECHO_CANCELLER |
  11645. LEC_MANUAL_DISABLE | LEC_ENABLE_NONLINEAR_PROCESSING;
  11646. plci->ec_tail_length = 0;
  11647. }
  11648. static void ec_prepare_switch(dword Id, PLCI *plci)
  11649. {
  11650. dbug(1, dprintf("[%06lx] %s,%d: ec_prepare_switch",
  11651. UnMapId(Id), (char *)(FILE_), __LINE__));
  11652. }
  11653. static word ec_save_config(dword Id, PLCI *plci, byte Rc)
  11654. {
  11655. dbug(1, dprintf("[%06lx] %s,%d: ec_save_config %02x %d",
  11656. UnMapId(Id), (char *)(FILE_), __LINE__, Rc, plci->adjust_b_state));
  11657. return (GOOD);
  11658. }
  11659. static word ec_restore_config(dword Id, PLCI *plci, byte Rc)
  11660. {
  11661. word Info;
  11662. dbug(1, dprintf("[%06lx] %s,%d: ec_restore_config %02x %d",
  11663. UnMapId(Id), (char *)(FILE_), __LINE__, Rc, plci->adjust_b_state));
  11664. Info = GOOD;
  11665. if (plci->B1_facilities & B1_FACILITY_EC)
  11666. {
  11667. switch (plci->adjust_b_state)
  11668. {
  11669. case ADJUST_B_RESTORE_EC_1:
  11670. plci->internal_command = plci->adjust_b_command;
  11671. if (plci->sig_req)
  11672. {
  11673. plci->adjust_b_state = ADJUST_B_RESTORE_EC_1;
  11674. break;
  11675. }
  11676. ec_write_parameters(plci);
  11677. plci->adjust_b_state = ADJUST_B_RESTORE_EC_2;
  11678. break;
  11679. case ADJUST_B_RESTORE_EC_2:
  11680. if ((Rc != OK) && (Rc != OK_FC))
  11681. {
  11682. dbug(1, dprintf("[%06lx] %s,%d: Restore EC failed %02x",
  11683. UnMapId(Id), (char *)(FILE_), __LINE__, Rc));
  11684. Info = _WRONG_STATE;
  11685. break;
  11686. }
  11687. break;
  11688. }
  11689. }
  11690. return (Info);
  11691. }
  11692. static void ec_command(dword Id, PLCI *plci, byte Rc)
  11693. {
  11694. word internal_command, Info;
  11695. byte result[8];
  11696. dbug(1, dprintf("[%06lx] %s,%d: ec_command %02x %04x %04x %04x %d",
  11697. UnMapId(Id), (char *)(FILE_), __LINE__, Rc, plci->internal_command,
  11698. plci->ec_cmd, plci->ec_idi_options, plci->ec_tail_length));
  11699. Info = GOOD;
  11700. if (plci->appl->appl_flags & APPL_FLAG_PRIV_EC_SPEC)
  11701. {
  11702. result[0] = 2;
  11703. PUT_WORD(&result[1], EC_SUCCESS);
  11704. }
  11705. else
  11706. {
  11707. result[0] = 5;
  11708. PUT_WORD(&result[1], plci->ec_cmd);
  11709. result[3] = 2;
  11710. PUT_WORD(&result[4], GOOD);
  11711. }
  11712. internal_command = plci->internal_command;
  11713. plci->internal_command = 0;
  11714. switch (plci->ec_cmd)
  11715. {
  11716. case EC_ENABLE_OPERATION:
  11717. case EC_FREEZE_COEFFICIENTS:
  11718. case EC_RESUME_COEFFICIENT_UPDATE:
  11719. case EC_RESET_COEFFICIENTS:
  11720. switch (internal_command)
  11721. {
  11722. default:
  11723. adjust_b1_resource(Id, plci, NULL, (word)(plci->B1_facilities |
  11724. B1_FACILITY_EC), EC_COMMAND_1);
  11725. case EC_COMMAND_1:
  11726. if (adjust_b_process(Id, plci, Rc) != GOOD)
  11727. {
  11728. dbug(1, dprintf("[%06lx] %s,%d: Load EC failed",
  11729. UnMapId(Id), (char *)(FILE_), __LINE__));
  11730. Info = _FACILITY_NOT_SUPPORTED;
  11731. break;
  11732. }
  11733. if (plci->internal_command)
  11734. return;
  11735. case EC_COMMAND_2:
  11736. if (plci->sig_req)
  11737. {
  11738. plci->internal_command = EC_COMMAND_2;
  11739. return;
  11740. }
  11741. plci->internal_command = EC_COMMAND_3;
  11742. ec_write_parameters(plci);
  11743. return;
  11744. case EC_COMMAND_3:
  11745. if ((Rc != OK) && (Rc != OK_FC))
  11746. {
  11747. dbug(1, dprintf("[%06lx] %s,%d: Enable EC failed %02x",
  11748. UnMapId(Id), (char *)(FILE_), __LINE__, Rc));
  11749. Info = _FACILITY_NOT_SUPPORTED;
  11750. break;
  11751. }
  11752. break;
  11753. }
  11754. break;
  11755. case EC_DISABLE_OPERATION:
  11756. switch (internal_command)
  11757. {
  11758. default:
  11759. case EC_COMMAND_1:
  11760. if (plci->B1_facilities & B1_FACILITY_EC)
  11761. {
  11762. if (plci->sig_req)
  11763. {
  11764. plci->internal_command = EC_COMMAND_1;
  11765. return;
  11766. }
  11767. plci->internal_command = EC_COMMAND_2;
  11768. ec_write_parameters(plci);
  11769. return;
  11770. }
  11771. Rc = OK;
  11772. case EC_COMMAND_2:
  11773. if ((Rc != OK) && (Rc != OK_FC))
  11774. {
  11775. dbug(1, dprintf("[%06lx] %s,%d: Disable EC failed %02x",
  11776. UnMapId(Id), (char *)(FILE_), __LINE__, Rc));
  11777. Info = _FACILITY_NOT_SUPPORTED;
  11778. break;
  11779. }
  11780. adjust_b1_resource(Id, plci, NULL, (word)(plci->B1_facilities &
  11781. ~B1_FACILITY_EC), EC_COMMAND_3);
  11782. case EC_COMMAND_3:
  11783. if (adjust_b_process(Id, plci, Rc) != GOOD)
  11784. {
  11785. dbug(1, dprintf("[%06lx] %s,%d: Unload EC failed",
  11786. UnMapId(Id), (char *)(FILE_), __LINE__));
  11787. Info = _FACILITY_NOT_SUPPORTED;
  11788. break;
  11789. }
  11790. if (plci->internal_command)
  11791. return;
  11792. break;
  11793. }
  11794. break;
  11795. }
  11796. sendf(plci->appl, _FACILITY_R | CONFIRM, Id & 0xffffL, plci->number,
  11797. "wws", Info, (plci->appl->appl_flags & APPL_FLAG_PRIV_EC_SPEC) ?
  11798. PRIV_SELECTOR_ECHO_CANCELLER : SELECTOR_ECHO_CANCELLER, result);
  11799. }
  11800. static byte ec_request(dword Id, word Number, DIVA_CAPI_ADAPTER *a, PLCI *plci, APPL *appl, API_PARSE *msg)
  11801. {
  11802. word Info;
  11803. word opt;
  11804. API_PARSE ec_parms[3];
  11805. byte result[16];
  11806. dbug(1, dprintf("[%06lx] %s,%d: ec_request",
  11807. UnMapId(Id), (char *)(FILE_), __LINE__));
  11808. Info = GOOD;
  11809. result[0] = 0;
  11810. if (!(a->man_profile.private_options & (1L << PRIVATE_ECHO_CANCELLER)))
  11811. {
  11812. dbug(1, dprintf("[%06lx] %s,%d: Facility not supported",
  11813. UnMapId(Id), (char *)(FILE_), __LINE__));
  11814. Info = _FACILITY_NOT_SUPPORTED;
  11815. }
  11816. else
  11817. {
  11818. if (appl->appl_flags & APPL_FLAG_PRIV_EC_SPEC)
  11819. {
  11820. if (api_parse(&msg[1].info[1], msg[1].length, "w", ec_parms))
  11821. {
  11822. dbug(1, dprintf("[%06lx] %s,%d: Wrong message format",
  11823. UnMapId(Id), (char *)(FILE_), __LINE__));
  11824. Info = _WRONG_MESSAGE_FORMAT;
  11825. }
  11826. else
  11827. {
  11828. if (plci == NULL)
  11829. {
  11830. dbug(1, dprintf("[%06lx] %s,%d: Wrong PLCI",
  11831. UnMapId(Id), (char *)(FILE_), __LINE__));
  11832. Info = _WRONG_IDENTIFIER;
  11833. }
  11834. else if (!plci->State || !plci->NL.Id || plci->nl_remove_id)
  11835. {
  11836. dbug(1, dprintf("[%06lx] %s,%d: Wrong state",
  11837. UnMapId(Id), (char *)(FILE_), __LINE__));
  11838. Info = _WRONG_STATE;
  11839. }
  11840. else
  11841. {
  11842. plci->command = 0;
  11843. plci->ec_cmd = GET_WORD(ec_parms[0].info);
  11844. plci->ec_idi_options &= ~(LEC_MANUAL_DISABLE | LEC_RESET_COEFFICIENTS);
  11845. result[0] = 2;
  11846. PUT_WORD(&result[1], EC_SUCCESS);
  11847. if (msg[1].length >= 4)
  11848. {
  11849. opt = GET_WORD(&ec_parms[0].info[2]);
  11850. plci->ec_idi_options &= ~(LEC_ENABLE_NONLINEAR_PROCESSING |
  11851. LEC_ENABLE_2100HZ_DETECTOR | LEC_REQUIRE_2100HZ_REVERSALS);
  11852. if (!(opt & EC_DISABLE_NON_LINEAR_PROCESSING))
  11853. plci->ec_idi_options |= LEC_ENABLE_NONLINEAR_PROCESSING;
  11854. if (opt & EC_DETECT_DISABLE_TONE)
  11855. plci->ec_idi_options |= LEC_ENABLE_2100HZ_DETECTOR;
  11856. if (!(opt & EC_DO_NOT_REQUIRE_REVERSALS))
  11857. plci->ec_idi_options |= LEC_REQUIRE_2100HZ_REVERSALS;
  11858. if (msg[1].length >= 6)
  11859. {
  11860. plci->ec_tail_length = GET_WORD(&ec_parms[0].info[4]);
  11861. }
  11862. }
  11863. switch (plci->ec_cmd)
  11864. {
  11865. case EC_ENABLE_OPERATION:
  11866. plci->ec_idi_options &= ~LEC_FREEZE_COEFFICIENTS;
  11867. start_internal_command(Id, plci, ec_command);
  11868. return (false);
  11869. case EC_DISABLE_OPERATION:
  11870. plci->ec_idi_options = LEC_ENABLE_ECHO_CANCELLER |
  11871. LEC_MANUAL_DISABLE | LEC_ENABLE_NONLINEAR_PROCESSING |
  11872. LEC_RESET_COEFFICIENTS;
  11873. start_internal_command(Id, plci, ec_command);
  11874. return (false);
  11875. case EC_FREEZE_COEFFICIENTS:
  11876. plci->ec_idi_options |= LEC_FREEZE_COEFFICIENTS;
  11877. start_internal_command(Id, plci, ec_command);
  11878. return (false);
  11879. case EC_RESUME_COEFFICIENT_UPDATE:
  11880. plci->ec_idi_options &= ~LEC_FREEZE_COEFFICIENTS;
  11881. start_internal_command(Id, plci, ec_command);
  11882. return (false);
  11883. case EC_RESET_COEFFICIENTS:
  11884. plci->ec_idi_options |= LEC_RESET_COEFFICIENTS;
  11885. start_internal_command(Id, plci, ec_command);
  11886. return (false);
  11887. default:
  11888. dbug(1, dprintf("[%06lx] %s,%d: EC unknown request %04x",
  11889. UnMapId(Id), (char *)(FILE_), __LINE__, plci->ec_cmd));
  11890. PUT_WORD(&result[1], EC_UNSUPPORTED_OPERATION);
  11891. }
  11892. }
  11893. }
  11894. }
  11895. else
  11896. {
  11897. if (api_parse(&msg[1].info[1], msg[1].length, "ws", ec_parms))
  11898. {
  11899. dbug(1, dprintf("[%06lx] %s,%d: Wrong message format",
  11900. UnMapId(Id), (char *)(FILE_), __LINE__));
  11901. Info = _WRONG_MESSAGE_FORMAT;
  11902. }
  11903. else
  11904. {
  11905. if (GET_WORD(ec_parms[0].info) == EC_GET_SUPPORTED_SERVICES)
  11906. {
  11907. result[0] = 11;
  11908. PUT_WORD(&result[1], EC_GET_SUPPORTED_SERVICES);
  11909. result[3] = 8;
  11910. PUT_WORD(&result[4], GOOD);
  11911. PUT_WORD(&result[6], 0x0007);
  11912. PUT_WORD(&result[8], LEC_MAX_SUPPORTED_TAIL_LENGTH);
  11913. PUT_WORD(&result[10], 0);
  11914. }
  11915. else if (plci == NULL)
  11916. {
  11917. dbug(1, dprintf("[%06lx] %s,%d: Wrong PLCI",
  11918. UnMapId(Id), (char *)(FILE_), __LINE__));
  11919. Info = _WRONG_IDENTIFIER;
  11920. }
  11921. else if (!plci->State || !plci->NL.Id || plci->nl_remove_id)
  11922. {
  11923. dbug(1, dprintf("[%06lx] %s,%d: Wrong state",
  11924. UnMapId(Id), (char *)(FILE_), __LINE__));
  11925. Info = _WRONG_STATE;
  11926. }
  11927. else
  11928. {
  11929. plci->command = 0;
  11930. plci->ec_cmd = GET_WORD(ec_parms[0].info);
  11931. plci->ec_idi_options &= ~(LEC_MANUAL_DISABLE | LEC_RESET_COEFFICIENTS);
  11932. result[0] = 5;
  11933. PUT_WORD(&result[1], plci->ec_cmd);
  11934. result[3] = 2;
  11935. PUT_WORD(&result[4], GOOD);
  11936. plci->ec_idi_options &= ~(LEC_ENABLE_NONLINEAR_PROCESSING |
  11937. LEC_ENABLE_2100HZ_DETECTOR | LEC_REQUIRE_2100HZ_REVERSALS);
  11938. plci->ec_tail_length = 0;
  11939. if (ec_parms[1].length >= 2)
  11940. {
  11941. opt = GET_WORD(&ec_parms[1].info[1]);
  11942. if (opt & EC_ENABLE_NON_LINEAR_PROCESSING)
  11943. plci->ec_idi_options |= LEC_ENABLE_NONLINEAR_PROCESSING;
  11944. if (opt & EC_DETECT_DISABLE_TONE)
  11945. plci->ec_idi_options |= LEC_ENABLE_2100HZ_DETECTOR;
  11946. if (!(opt & EC_DO_NOT_REQUIRE_REVERSALS))
  11947. plci->ec_idi_options |= LEC_REQUIRE_2100HZ_REVERSALS;
  11948. if (ec_parms[1].length >= 4)
  11949. {
  11950. plci->ec_tail_length = GET_WORD(&ec_parms[1].info[3]);
  11951. }
  11952. }
  11953. switch (plci->ec_cmd)
  11954. {
  11955. case EC_ENABLE_OPERATION:
  11956. plci->ec_idi_options &= ~LEC_FREEZE_COEFFICIENTS;
  11957. start_internal_command(Id, plci, ec_command);
  11958. return (false);
  11959. case EC_DISABLE_OPERATION:
  11960. plci->ec_idi_options = LEC_ENABLE_ECHO_CANCELLER |
  11961. LEC_MANUAL_DISABLE | LEC_ENABLE_NONLINEAR_PROCESSING |
  11962. LEC_RESET_COEFFICIENTS;
  11963. start_internal_command(Id, plci, ec_command);
  11964. return (false);
  11965. default:
  11966. dbug(1, dprintf("[%06lx] %s,%d: EC unknown request %04x",
  11967. UnMapId(Id), (char *)(FILE_), __LINE__, plci->ec_cmd));
  11968. PUT_WORD(&result[4], _FACILITY_SPECIFIC_FUNCTION_NOT_SUPP);
  11969. }
  11970. }
  11971. }
  11972. }
  11973. }
  11974. sendf(appl, _FACILITY_R | CONFIRM, Id & 0xffffL, Number,
  11975. "wws", Info, (appl->appl_flags & APPL_FLAG_PRIV_EC_SPEC) ?
  11976. PRIV_SELECTOR_ECHO_CANCELLER : SELECTOR_ECHO_CANCELLER, result);
  11977. return (false);
  11978. }
  11979. static void ec_indication(dword Id, PLCI *plci, byte *msg, word length)
  11980. {
  11981. byte result[8];
  11982. dbug(1, dprintf("[%06lx] %s,%d: ec_indication",
  11983. UnMapId(Id), (char *)(FILE_), __LINE__));
  11984. if (!(plci->ec_idi_options & LEC_MANUAL_DISABLE))
  11985. {
  11986. if (plci->appl->appl_flags & APPL_FLAG_PRIV_EC_SPEC)
  11987. {
  11988. result[0] = 2;
  11989. PUT_WORD(&result[1], 0);
  11990. switch (msg[1])
  11991. {
  11992. case LEC_DISABLE_TYPE_CONTIGNUOUS_2100HZ:
  11993. PUT_WORD(&result[1], EC_BYPASS_DUE_TO_CONTINUOUS_2100HZ);
  11994. break;
  11995. case LEC_DISABLE_TYPE_REVERSED_2100HZ:
  11996. PUT_WORD(&result[1], EC_BYPASS_DUE_TO_REVERSED_2100HZ);
  11997. break;
  11998. case LEC_DISABLE_RELEASED:
  11999. PUT_WORD(&result[1], EC_BYPASS_RELEASED);
  12000. break;
  12001. }
  12002. }
  12003. else
  12004. {
  12005. result[0] = 5;
  12006. PUT_WORD(&result[1], EC_BYPASS_INDICATION);
  12007. result[3] = 2;
  12008. PUT_WORD(&result[4], 0);
  12009. switch (msg[1])
  12010. {
  12011. case LEC_DISABLE_TYPE_CONTIGNUOUS_2100HZ:
  12012. PUT_WORD(&result[4], EC_BYPASS_DUE_TO_CONTINUOUS_2100HZ);
  12013. break;
  12014. case LEC_DISABLE_TYPE_REVERSED_2100HZ:
  12015. PUT_WORD(&result[4], EC_BYPASS_DUE_TO_REVERSED_2100HZ);
  12016. break;
  12017. case LEC_DISABLE_RELEASED:
  12018. PUT_WORD(&result[4], EC_BYPASS_RELEASED);
  12019. break;
  12020. }
  12021. }
  12022. sendf(plci->appl, _FACILITY_I, Id & 0xffffL, 0, "ws", (plci->appl->appl_flags & APPL_FLAG_PRIV_EC_SPEC) ?
  12023. PRIV_SELECTOR_ECHO_CANCELLER : SELECTOR_ECHO_CANCELLER, result);
  12024. }
  12025. }
  12026. /*------------------------------------------------------------------*/
  12027. /* Advanced voice */
  12028. /*------------------------------------------------------------------*/
  12029. static void adv_voice_write_coefs(PLCI *plci, word write_command)
  12030. {
  12031. DIVA_CAPI_ADAPTER *a;
  12032. word i;
  12033. byte *p;
  12034. word w, n, j, k;
  12035. byte ch_map[MIXER_CHANNELS_BRI];
  12036. byte coef_buffer[ADV_VOICE_COEF_BUFFER_SIZE + 2];
  12037. dbug(1, dprintf("[%06lx] %s,%d: adv_voice_write_coefs %d",
  12038. (dword)((plci->Id << 8) | UnMapController(plci->adapter->Id)),
  12039. (char *)(FILE_), __LINE__, write_command));
  12040. a = plci->adapter;
  12041. p = coef_buffer + 1;
  12042. *(p++) = DSP_CTRL_OLD_SET_MIXER_COEFFICIENTS;
  12043. i = 0;
  12044. while (i + sizeof(word) <= a->adv_voice_coef_length)
  12045. {
  12046. PUT_WORD(p, GET_WORD(a->adv_voice_coef_buffer + i));
  12047. p += 2;
  12048. i += 2;
  12049. }
  12050. while (i < ADV_VOICE_OLD_COEF_COUNT * sizeof(word))
  12051. {
  12052. PUT_WORD(p, 0x8000);
  12053. p += 2;
  12054. i += 2;
  12055. }
  12056. if (!a->li_pri && (plci->li_bchannel_id == 0))
  12057. {
  12058. if ((li_config_table[a->li_base].plci == NULL) && (li_config_table[a->li_base + 1].plci != NULL))
  12059. {
  12060. plci->li_bchannel_id = 1;
  12061. li_config_table[a->li_base].plci = plci;
  12062. dbug(1, dprintf("[%06lx] %s,%d: adv_voice_set_bchannel_id %d",
  12063. (dword)((plci->Id << 8) | UnMapController(plci->adapter->Id)),
  12064. (char *)(FILE_), __LINE__, plci->li_bchannel_id));
  12065. }
  12066. else if ((li_config_table[a->li_base].plci != NULL) && (li_config_table[a->li_base + 1].plci == NULL))
  12067. {
  12068. plci->li_bchannel_id = 2;
  12069. li_config_table[a->li_base + 1].plci = plci;
  12070. dbug(1, dprintf("[%06lx] %s,%d: adv_voice_set_bchannel_id %d",
  12071. (dword)((plci->Id << 8) | UnMapController(plci->adapter->Id)),
  12072. (char *)(FILE_), __LINE__, plci->li_bchannel_id));
  12073. }
  12074. }
  12075. if (!a->li_pri && (plci->li_bchannel_id != 0)
  12076. && (li_config_table[a->li_base + (plci->li_bchannel_id - 1)].plci == plci))
  12077. {
  12078. i = a->li_base + (plci->li_bchannel_id - 1);
  12079. switch (write_command)
  12080. {
  12081. case ADV_VOICE_WRITE_ACTIVATION:
  12082. j = a->li_base + MIXER_IC_CHANNEL_BASE + (plci->li_bchannel_id - 1);
  12083. k = a->li_base + MIXER_IC_CHANNEL_BASE + (2 - plci->li_bchannel_id);
  12084. if (!(plci->B1_facilities & B1_FACILITY_MIXER))
  12085. {
  12086. li_config_table[j].flag_table[i] |= LI_FLAG_CONFERENCE | LI_FLAG_MIX;
  12087. li_config_table[i].flag_table[j] |= LI_FLAG_CONFERENCE | LI_FLAG_MONITOR;
  12088. }
  12089. if (a->manufacturer_features & MANUFACTURER_FEATURE_SLAVE_CODEC)
  12090. {
  12091. li_config_table[k].flag_table[i] |= LI_FLAG_CONFERENCE | LI_FLAG_MIX;
  12092. li_config_table[i].flag_table[k] |= LI_FLAG_CONFERENCE | LI_FLAG_MONITOR;
  12093. li_config_table[k].flag_table[j] |= LI_FLAG_CONFERENCE;
  12094. li_config_table[j].flag_table[k] |= LI_FLAG_CONFERENCE;
  12095. }
  12096. mixer_calculate_coefs(a);
  12097. li_config_table[i].curchnl = li_config_table[i].channel;
  12098. li_config_table[j].curchnl = li_config_table[j].channel;
  12099. if (a->manufacturer_features & MANUFACTURER_FEATURE_SLAVE_CODEC)
  12100. li_config_table[k].curchnl = li_config_table[k].channel;
  12101. break;
  12102. case ADV_VOICE_WRITE_DEACTIVATION:
  12103. for (j = 0; j < li_total_channels; j++)
  12104. {
  12105. li_config_table[i].flag_table[j] = 0;
  12106. li_config_table[j].flag_table[i] = 0;
  12107. }
  12108. k = a->li_base + MIXER_IC_CHANNEL_BASE + (plci->li_bchannel_id - 1);
  12109. for (j = 0; j < li_total_channels; j++)
  12110. {
  12111. li_config_table[k].flag_table[j] = 0;
  12112. li_config_table[j].flag_table[k] = 0;
  12113. }
  12114. if (a->manufacturer_features & MANUFACTURER_FEATURE_SLAVE_CODEC)
  12115. {
  12116. k = a->li_base + MIXER_IC_CHANNEL_BASE + (2 - plci->li_bchannel_id);
  12117. for (j = 0; j < li_total_channels; j++)
  12118. {
  12119. li_config_table[k].flag_table[j] = 0;
  12120. li_config_table[j].flag_table[k] = 0;
  12121. }
  12122. }
  12123. mixer_calculate_coefs(a);
  12124. break;
  12125. }
  12126. if (plci->B1_facilities & B1_FACILITY_MIXER)
  12127. {
  12128. w = 0;
  12129. if (ADV_VOICE_NEW_COEF_BASE + sizeof(word) <= a->adv_voice_coef_length)
  12130. w = GET_WORD(a->adv_voice_coef_buffer + ADV_VOICE_NEW_COEF_BASE);
  12131. if (li_config_table[i].channel & LI_CHANNEL_TX_DATA)
  12132. w |= MIXER_FEATURE_ENABLE_TX_DATA;
  12133. if (li_config_table[i].channel & LI_CHANNEL_RX_DATA)
  12134. w |= MIXER_FEATURE_ENABLE_RX_DATA;
  12135. *(p++) = (byte) w;
  12136. *(p++) = (byte)(w >> 8);
  12137. for (j = 0; j < sizeof(ch_map); j += 2)
  12138. {
  12139. ch_map[j] = (byte)(j + (plci->li_bchannel_id - 1));
  12140. ch_map[j + 1] = (byte)(j + (2 - plci->li_bchannel_id));
  12141. }
  12142. for (n = 0; n < ARRAY_SIZE(mixer_write_prog_bri); n++)
  12143. {
  12144. i = a->li_base + ch_map[mixer_write_prog_bri[n].to_ch];
  12145. j = a->li_base + ch_map[mixer_write_prog_bri[n].from_ch];
  12146. if (li_config_table[i].channel & li_config_table[j].channel & LI_CHANNEL_INVOLVED)
  12147. {
  12148. *(p++) = ((li_config_table[i].coef_table[j] & mixer_write_prog_bri[n].mask) ? 0x80 : 0x01);
  12149. w = ((li_config_table[i].coef_table[j] & 0xf) ^ (li_config_table[i].coef_table[j] >> 4));
  12150. li_config_table[i].coef_table[j] ^= (w & mixer_write_prog_bri[n].mask) << 4;
  12151. }
  12152. else
  12153. {
  12154. *(p++) = (ADV_VOICE_NEW_COEF_BASE + sizeof(word) + n < a->adv_voice_coef_length) ?
  12155. a->adv_voice_coef_buffer[ADV_VOICE_NEW_COEF_BASE + sizeof(word) + n] : 0x00;
  12156. }
  12157. }
  12158. }
  12159. else
  12160. {
  12161. for (i = ADV_VOICE_NEW_COEF_BASE; i < a->adv_voice_coef_length; i++)
  12162. *(p++) = a->adv_voice_coef_buffer[i];
  12163. }
  12164. }
  12165. else
  12166. {
  12167. for (i = ADV_VOICE_NEW_COEF_BASE; i < a->adv_voice_coef_length; i++)
  12168. *(p++) = a->adv_voice_coef_buffer[i];
  12169. }
  12170. coef_buffer[0] = (p - coef_buffer) - 1;
  12171. add_p(plci, FTY, coef_buffer);
  12172. sig_req(plci, TEL_CTRL, 0);
  12173. send_req(plci);
  12174. }
  12175. static void adv_voice_clear_config(PLCI *plci)
  12176. {
  12177. DIVA_CAPI_ADAPTER *a;
  12178. word i, j;
  12179. dbug(1, dprintf("[%06lx] %s,%d: adv_voice_clear_config",
  12180. (dword)((plci->Id << 8) | UnMapController(plci->adapter->Id)),
  12181. (char *)(FILE_), __LINE__));
  12182. a = plci->adapter;
  12183. if ((plci->tel == ADV_VOICE) && (plci == a->AdvSignalPLCI))
  12184. {
  12185. a->adv_voice_coef_length = 0;
  12186. if (!a->li_pri && (plci->li_bchannel_id != 0)
  12187. && (li_config_table[a->li_base + (plci->li_bchannel_id - 1)].plci == plci))
  12188. {
  12189. i = a->li_base + (plci->li_bchannel_id - 1);
  12190. li_config_table[i].curchnl = 0;
  12191. li_config_table[i].channel = 0;
  12192. li_config_table[i].chflags = 0;
  12193. for (j = 0; j < li_total_channels; j++)
  12194. {
  12195. li_config_table[i].flag_table[j] = 0;
  12196. li_config_table[j].flag_table[i] = 0;
  12197. li_config_table[i].coef_table[j] = 0;
  12198. li_config_table[j].coef_table[i] = 0;
  12199. }
  12200. li_config_table[i].coef_table[i] |= LI_COEF_CH_PC_SET | LI_COEF_PC_CH_SET;
  12201. i = a->li_base + MIXER_IC_CHANNEL_BASE + (plci->li_bchannel_id - 1);
  12202. li_config_table[i].curchnl = 0;
  12203. li_config_table[i].channel = 0;
  12204. li_config_table[i].chflags = 0;
  12205. for (j = 0; j < li_total_channels; j++)
  12206. {
  12207. li_config_table[i].flag_table[j] = 0;
  12208. li_config_table[j].flag_table[i] = 0;
  12209. li_config_table[i].coef_table[j] = 0;
  12210. li_config_table[j].coef_table[i] = 0;
  12211. }
  12212. if (a->manufacturer_features & MANUFACTURER_FEATURE_SLAVE_CODEC)
  12213. {
  12214. i = a->li_base + MIXER_IC_CHANNEL_BASE + (2 - plci->li_bchannel_id);
  12215. li_config_table[i].curchnl = 0;
  12216. li_config_table[i].channel = 0;
  12217. li_config_table[i].chflags = 0;
  12218. for (j = 0; j < li_total_channels; j++)
  12219. {
  12220. li_config_table[i].flag_table[j] = 0;
  12221. li_config_table[j].flag_table[i] = 0;
  12222. li_config_table[i].coef_table[j] = 0;
  12223. li_config_table[j].coef_table[i] = 0;
  12224. }
  12225. }
  12226. }
  12227. }
  12228. }
  12229. static void adv_voice_prepare_switch(dword Id, PLCI *plci)
  12230. {
  12231. dbug(1, dprintf("[%06lx] %s,%d: adv_voice_prepare_switch",
  12232. UnMapId(Id), (char *)(FILE_), __LINE__));
  12233. }
  12234. static word adv_voice_save_config(dword Id, PLCI *plci, byte Rc)
  12235. {
  12236. dbug(1, dprintf("[%06lx] %s,%d: adv_voice_save_config %02x %d",
  12237. UnMapId(Id), (char *)(FILE_), __LINE__, Rc, plci->adjust_b_state));
  12238. return (GOOD);
  12239. }
  12240. static word adv_voice_restore_config(dword Id, PLCI *plci, byte Rc)
  12241. {
  12242. DIVA_CAPI_ADAPTER *a;
  12243. word Info;
  12244. dbug(1, dprintf("[%06lx] %s,%d: adv_voice_restore_config %02x %d",
  12245. UnMapId(Id), (char *)(FILE_), __LINE__, Rc, plci->adjust_b_state));
  12246. Info = GOOD;
  12247. a = plci->adapter;
  12248. if ((plci->B1_facilities & B1_FACILITY_VOICE)
  12249. && (plci->tel == ADV_VOICE) && (plci == a->AdvSignalPLCI))
  12250. {
  12251. switch (plci->adjust_b_state)
  12252. {
  12253. case ADJUST_B_RESTORE_VOICE_1:
  12254. plci->internal_command = plci->adjust_b_command;
  12255. if (plci->sig_req)
  12256. {
  12257. plci->adjust_b_state = ADJUST_B_RESTORE_VOICE_1;
  12258. break;
  12259. }
  12260. adv_voice_write_coefs(plci, ADV_VOICE_WRITE_UPDATE);
  12261. plci->adjust_b_state = ADJUST_B_RESTORE_VOICE_2;
  12262. break;
  12263. case ADJUST_B_RESTORE_VOICE_2:
  12264. if ((Rc != OK) && (Rc != OK_FC))
  12265. {
  12266. dbug(1, dprintf("[%06lx] %s,%d: Restore voice config failed %02x",
  12267. UnMapId(Id), (char *)(FILE_), __LINE__, Rc));
  12268. Info = _WRONG_STATE;
  12269. break;
  12270. }
  12271. break;
  12272. }
  12273. }
  12274. return (Info);
  12275. }
  12276. /*------------------------------------------------------------------*/
  12277. /* B1 resource switching */
  12278. /*------------------------------------------------------------------*/
  12279. static byte b1_facilities_table[] =
  12280. {
  12281. 0x00, /* 0 No bchannel resources */
  12282. 0x00, /* 1 Codec (automatic law) */
  12283. 0x00, /* 2 Codec (A-law) */
  12284. 0x00, /* 3 Codec (y-law) */
  12285. 0x00, /* 4 HDLC for X.21 */
  12286. 0x00, /* 5 HDLC */
  12287. 0x00, /* 6 External Device 0 */
  12288. 0x00, /* 7 External Device 1 */
  12289. 0x00, /* 8 HDLC 56k */
  12290. 0x00, /* 9 Transparent */
  12291. 0x00, /* 10 Loopback to network */
  12292. 0x00, /* 11 Test pattern to net */
  12293. 0x00, /* 12 Rate adaptation sync */
  12294. 0x00, /* 13 Rate adaptation async */
  12295. 0x00, /* 14 R-Interface */
  12296. 0x00, /* 15 HDLC 128k leased line */
  12297. 0x00, /* 16 FAX */
  12298. 0x00, /* 17 Modem async */
  12299. 0x00, /* 18 Modem sync HDLC */
  12300. 0x00, /* 19 V.110 async HDLC */
  12301. 0x12, /* 20 Adv voice (Trans,mixer) */
  12302. 0x00, /* 21 Codec connected to IC */
  12303. 0x0c, /* 22 Trans,DTMF */
  12304. 0x1e, /* 23 Trans,DTMF+mixer */
  12305. 0x1f, /* 24 Trans,DTMF+mixer+local */
  12306. 0x13, /* 25 Trans,mixer+local */
  12307. 0x12, /* 26 HDLC,mixer */
  12308. 0x12, /* 27 HDLC 56k,mixer */
  12309. 0x2c, /* 28 Trans,LEC+DTMF */
  12310. 0x3e, /* 29 Trans,LEC+DTMF+mixer */
  12311. 0x3f, /* 30 Trans,LEC+DTMF+mixer+local */
  12312. 0x2c, /* 31 RTP,LEC+DTMF */
  12313. 0x3e, /* 32 RTP,LEC+DTMF+mixer */
  12314. 0x3f, /* 33 RTP,LEC+DTMF+mixer+local */
  12315. 0x00, /* 34 Signaling task */
  12316. 0x00, /* 35 PIAFS */
  12317. 0x0c, /* 36 Trans,DTMF+TONE */
  12318. 0x1e, /* 37 Trans,DTMF+TONE+mixer */
  12319. 0x1f /* 38 Trans,DTMF+TONE+mixer+local*/
  12320. };
  12321. static word get_b1_facilities(PLCI *plci, byte b1_resource)
  12322. {
  12323. word b1_facilities;
  12324. b1_facilities = b1_facilities_table[b1_resource];
  12325. if ((b1_resource == 9) || (b1_resource == 20) || (b1_resource == 25))
  12326. {
  12327. if (!(((plci->requested_options_conn | plci->requested_options) & (1L << PRIVATE_DTMF_TONE))
  12328. || (plci->appl && (plci->adapter->requested_options_table[plci->appl->Id - 1] & (1L << PRIVATE_DTMF_TONE)))))
  12329. {
  12330. if (plci->adapter->manufacturer_features & MANUFACTURER_FEATURE_SOFTDTMF_SEND)
  12331. b1_facilities |= B1_FACILITY_DTMFX;
  12332. if (plci->adapter->manufacturer_features & MANUFACTURER_FEATURE_SOFTDTMF_RECEIVE)
  12333. b1_facilities |= B1_FACILITY_DTMFR;
  12334. }
  12335. }
  12336. if ((b1_resource == 17) || (b1_resource == 18))
  12337. {
  12338. if (plci->adapter->manufacturer_features & (MANUFACTURER_FEATURE_V18 | MANUFACTURER_FEATURE_VOWN))
  12339. b1_facilities |= B1_FACILITY_DTMFX | B1_FACILITY_DTMFR;
  12340. }
  12341. /*
  12342. dbug (1, dprintf("[%06lx] %s,%d: get_b1_facilities %d %04x",
  12343. (dword)((plci->Id << 8) | UnMapController(plci->adapter->Id)),
  12344. (char far *)(FILE_), __LINE__, b1_resource, b1_facilites));
  12345. */
  12346. return (b1_facilities);
  12347. }
  12348. static byte add_b1_facilities(PLCI *plci, byte b1_resource, word b1_facilities)
  12349. {
  12350. byte b;
  12351. switch (b1_resource)
  12352. {
  12353. case 5:
  12354. case 26:
  12355. if (b1_facilities & (B1_FACILITY_MIXER | B1_FACILITY_VOICE))
  12356. b = 26;
  12357. else
  12358. b = 5;
  12359. break;
  12360. case 8:
  12361. case 27:
  12362. if (b1_facilities & (B1_FACILITY_MIXER | B1_FACILITY_VOICE))
  12363. b = 27;
  12364. else
  12365. b = 8;
  12366. break;
  12367. case 9:
  12368. case 20:
  12369. case 22:
  12370. case 23:
  12371. case 24:
  12372. case 25:
  12373. case 28:
  12374. case 29:
  12375. case 30:
  12376. case 36:
  12377. case 37:
  12378. case 38:
  12379. if (b1_facilities & B1_FACILITY_EC)
  12380. {
  12381. if (b1_facilities & B1_FACILITY_LOCAL)
  12382. b = 30;
  12383. else if (b1_facilities & (B1_FACILITY_MIXER | B1_FACILITY_VOICE))
  12384. b = 29;
  12385. else
  12386. b = 28;
  12387. }
  12388. else if ((b1_facilities & (B1_FACILITY_DTMFX | B1_FACILITY_DTMFR | B1_FACILITY_MIXER))
  12389. && (((plci->requested_options_conn | plci->requested_options) & (1L << PRIVATE_DTMF_TONE))
  12390. || (plci->appl && (plci->adapter->requested_options_table[plci->appl->Id - 1] & (1L << PRIVATE_DTMF_TONE)))))
  12391. {
  12392. if (b1_facilities & B1_FACILITY_LOCAL)
  12393. b = 38;
  12394. else if (b1_facilities & (B1_FACILITY_MIXER | B1_FACILITY_VOICE))
  12395. b = 37;
  12396. else
  12397. b = 36;
  12398. }
  12399. else if (((plci->adapter->manufacturer_features & MANUFACTURER_FEATURE_HARDDTMF)
  12400. && !(plci->adapter->manufacturer_features & MANUFACTURER_FEATURE_SOFTDTMF_RECEIVE))
  12401. || ((b1_facilities & B1_FACILITY_DTMFR)
  12402. && ((b1_facilities & B1_FACILITY_MIXER)
  12403. || !(plci->adapter->manufacturer_features & MANUFACTURER_FEATURE_SOFTDTMF_RECEIVE)))
  12404. || ((b1_facilities & B1_FACILITY_DTMFX)
  12405. && ((b1_facilities & B1_FACILITY_MIXER)
  12406. || !(plci->adapter->manufacturer_features & MANUFACTURER_FEATURE_SOFTDTMF_SEND))))
  12407. {
  12408. if (b1_facilities & B1_FACILITY_LOCAL)
  12409. b = 24;
  12410. else if (b1_facilities & (B1_FACILITY_MIXER | B1_FACILITY_VOICE))
  12411. b = 23;
  12412. else
  12413. b = 22;
  12414. }
  12415. else
  12416. {
  12417. if (b1_facilities & B1_FACILITY_LOCAL)
  12418. b = 25;
  12419. else if (b1_facilities & (B1_FACILITY_MIXER | B1_FACILITY_VOICE))
  12420. b = 20;
  12421. else
  12422. b = 9;
  12423. }
  12424. break;
  12425. case 31:
  12426. case 32:
  12427. case 33:
  12428. if (b1_facilities & B1_FACILITY_LOCAL)
  12429. b = 33;
  12430. else if (b1_facilities & (B1_FACILITY_MIXER | B1_FACILITY_VOICE))
  12431. b = 32;
  12432. else
  12433. b = 31;
  12434. break;
  12435. default:
  12436. b = b1_resource;
  12437. }
  12438. dbug(1, dprintf("[%06lx] %s,%d: add_b1_facilities %d %04x %d %04x",
  12439. (dword)((plci->Id << 8) | UnMapController(plci->adapter->Id)),
  12440. (char *)(FILE_), __LINE__,
  12441. b1_resource, b1_facilities, b, get_b1_facilities(plci, b)));
  12442. return (b);
  12443. }
  12444. static void adjust_b1_facilities(PLCI *plci, byte new_b1_resource, word new_b1_facilities)
  12445. {
  12446. word removed_facilities;
  12447. dbug(1, dprintf("[%06lx] %s,%d: adjust_b1_facilities %d %04x %04x",
  12448. (dword)((plci->Id << 8) | UnMapController(plci->adapter->Id)),
  12449. (char *)(FILE_), __LINE__, new_b1_resource, new_b1_facilities,
  12450. new_b1_facilities & get_b1_facilities(plci, new_b1_resource)));
  12451. new_b1_facilities &= get_b1_facilities(plci, new_b1_resource);
  12452. removed_facilities = plci->B1_facilities & ~new_b1_facilities;
  12453. if (removed_facilities & B1_FACILITY_EC)
  12454. ec_clear_config(plci);
  12455. if (removed_facilities & B1_FACILITY_DTMFR)
  12456. {
  12457. dtmf_rec_clear_config(plci);
  12458. dtmf_parameter_clear_config(plci);
  12459. }
  12460. if (removed_facilities & B1_FACILITY_DTMFX)
  12461. dtmf_send_clear_config(plci);
  12462. if (removed_facilities & B1_FACILITY_MIXER)
  12463. mixer_clear_config(plci);
  12464. if (removed_facilities & B1_FACILITY_VOICE)
  12465. adv_voice_clear_config(plci);
  12466. plci->B1_facilities = new_b1_facilities;
  12467. }
  12468. static void adjust_b_clear(PLCI *plci)
  12469. {
  12470. dbug(1, dprintf("[%06lx] %s,%d: adjust_b_clear",
  12471. (dword)((plci->Id << 8) | UnMapController(plci->adapter->Id)),
  12472. (char *)(FILE_), __LINE__));
  12473. plci->adjust_b_restore = false;
  12474. }
  12475. static word adjust_b_process(dword Id, PLCI *plci, byte Rc)
  12476. {
  12477. word Info;
  12478. byte b1_resource;
  12479. NCCI *ncci_ptr;
  12480. API_PARSE bp[2];
  12481. dbug(1, dprintf("[%06lx] %s,%d: adjust_b_process %02x %d",
  12482. UnMapId(Id), (char *)(FILE_), __LINE__, Rc, plci->adjust_b_state));
  12483. Info = GOOD;
  12484. switch (plci->adjust_b_state)
  12485. {
  12486. case ADJUST_B_START:
  12487. if ((plci->adjust_b_parms_msg == NULL)
  12488. && (plci->adjust_b_mode & ADJUST_B_MODE_SWITCH_L1)
  12489. && ((plci->adjust_b_mode & ~(ADJUST_B_MODE_SAVE | ADJUST_B_MODE_SWITCH_L1 |
  12490. ADJUST_B_MODE_NO_RESOURCE | ADJUST_B_MODE_RESTORE)) == 0))
  12491. {
  12492. b1_resource = (plci->adjust_b_mode == ADJUST_B_MODE_NO_RESOURCE) ?
  12493. 0 : add_b1_facilities(plci, plci->B1_resource, plci->adjust_b_facilities);
  12494. if (b1_resource == plci->B1_resource)
  12495. {
  12496. adjust_b1_facilities(plci, b1_resource, plci->adjust_b_facilities);
  12497. break;
  12498. }
  12499. if (plci->adjust_b_facilities & ~get_b1_facilities(plci, b1_resource))
  12500. {
  12501. dbug(1, dprintf("[%06lx] %s,%d: Adjust B nonsupported facilities %d %d %04x",
  12502. UnMapId(Id), (char *)(FILE_), __LINE__,
  12503. plci->B1_resource, b1_resource, plci->adjust_b_facilities));
  12504. Info = _WRONG_STATE;
  12505. break;
  12506. }
  12507. }
  12508. if (plci->adjust_b_mode & ADJUST_B_MODE_SAVE)
  12509. {
  12510. mixer_prepare_switch(Id, plci);
  12511. dtmf_prepare_switch(Id, plci);
  12512. dtmf_parameter_prepare_switch(Id, plci);
  12513. ec_prepare_switch(Id, plci);
  12514. adv_voice_prepare_switch(Id, plci);
  12515. }
  12516. plci->adjust_b_state = ADJUST_B_SAVE_MIXER_1;
  12517. Rc = OK;
  12518. case ADJUST_B_SAVE_MIXER_1:
  12519. if (plci->adjust_b_mode & ADJUST_B_MODE_SAVE)
  12520. {
  12521. Info = mixer_save_config(Id, plci, Rc);
  12522. if ((Info != GOOD) || plci->internal_command)
  12523. break;
  12524. }
  12525. plci->adjust_b_state = ADJUST_B_SAVE_DTMF_1;
  12526. Rc = OK;
  12527. case ADJUST_B_SAVE_DTMF_1:
  12528. if (plci->adjust_b_mode & ADJUST_B_MODE_SAVE)
  12529. {
  12530. Info = dtmf_save_config(Id, plci, Rc);
  12531. if ((Info != GOOD) || plci->internal_command)
  12532. break;
  12533. }
  12534. plci->adjust_b_state = ADJUST_B_REMOVE_L23_1;
  12535. case ADJUST_B_REMOVE_L23_1:
  12536. if ((plci->adjust_b_mode & ADJUST_B_MODE_REMOVE_L23)
  12537. && plci->NL.Id && !plci->nl_remove_id)
  12538. {
  12539. plci->internal_command = plci->adjust_b_command;
  12540. if (plci->adjust_b_ncci != 0)
  12541. {
  12542. ncci_ptr = &(plci->adapter->ncci[plci->adjust_b_ncci]);
  12543. while (ncci_ptr->data_pending)
  12544. {
  12545. plci->data_sent_ptr = ncci_ptr->DBuffer[ncci_ptr->data_out].P;
  12546. data_rc(plci, plci->adapter->ncci_ch[plci->adjust_b_ncci]);
  12547. }
  12548. while (ncci_ptr->data_ack_pending)
  12549. data_ack(plci, plci->adapter->ncci_ch[plci->adjust_b_ncci]);
  12550. }
  12551. nl_req_ncci(plci, REMOVE,
  12552. (byte)((plci->adjust_b_mode & ADJUST_B_MODE_CONNECT) ? plci->adjust_b_ncci : 0));
  12553. send_req(plci);
  12554. plci->adjust_b_state = ADJUST_B_REMOVE_L23_2;
  12555. break;
  12556. }
  12557. plci->adjust_b_state = ADJUST_B_REMOVE_L23_2;
  12558. Rc = OK;
  12559. case ADJUST_B_REMOVE_L23_2:
  12560. if ((Rc != OK) && (Rc != OK_FC))
  12561. {
  12562. dbug(1, dprintf("[%06lx] %s,%d: Adjust B remove failed %02x",
  12563. UnMapId(Id), (char *)(FILE_), __LINE__, Rc));
  12564. Info = _WRONG_STATE;
  12565. break;
  12566. }
  12567. if (plci->adjust_b_mode & ADJUST_B_MODE_REMOVE_L23)
  12568. {
  12569. if (plci_nl_busy(plci))
  12570. {
  12571. plci->internal_command = plci->adjust_b_command;
  12572. break;
  12573. }
  12574. }
  12575. plci->adjust_b_state = ADJUST_B_SAVE_EC_1;
  12576. Rc = OK;
  12577. case ADJUST_B_SAVE_EC_1:
  12578. if (plci->adjust_b_mode & ADJUST_B_MODE_SAVE)
  12579. {
  12580. Info = ec_save_config(Id, plci, Rc);
  12581. if ((Info != GOOD) || plci->internal_command)
  12582. break;
  12583. }
  12584. plci->adjust_b_state = ADJUST_B_SAVE_DTMF_PARAMETER_1;
  12585. Rc = OK;
  12586. case ADJUST_B_SAVE_DTMF_PARAMETER_1:
  12587. if (plci->adjust_b_mode & ADJUST_B_MODE_SAVE)
  12588. {
  12589. Info = dtmf_parameter_save_config(Id, plci, Rc);
  12590. if ((Info != GOOD) || plci->internal_command)
  12591. break;
  12592. }
  12593. plci->adjust_b_state = ADJUST_B_SAVE_VOICE_1;
  12594. Rc = OK;
  12595. case ADJUST_B_SAVE_VOICE_1:
  12596. if (plci->adjust_b_mode & ADJUST_B_MODE_SAVE)
  12597. {
  12598. Info = adv_voice_save_config(Id, plci, Rc);
  12599. if ((Info != GOOD) || plci->internal_command)
  12600. break;
  12601. }
  12602. plci->adjust_b_state = ADJUST_B_SWITCH_L1_1;
  12603. case ADJUST_B_SWITCH_L1_1:
  12604. if (plci->adjust_b_mode & ADJUST_B_MODE_SWITCH_L1)
  12605. {
  12606. if (plci->sig_req)
  12607. {
  12608. plci->internal_command = plci->adjust_b_command;
  12609. break;
  12610. }
  12611. if (plci->adjust_b_parms_msg != NULL)
  12612. api_load_msg(plci->adjust_b_parms_msg, bp);
  12613. else
  12614. api_load_msg(&plci->B_protocol, bp);
  12615. Info = add_b1(plci, bp,
  12616. (word)((plci->adjust_b_mode & ADJUST_B_MODE_NO_RESOURCE) ? 2 : 0),
  12617. plci->adjust_b_facilities);
  12618. if (Info != GOOD)
  12619. {
  12620. dbug(1, dprintf("[%06lx] %s,%d: Adjust B invalid L1 parameters %d %04x",
  12621. UnMapId(Id), (char *)(FILE_), __LINE__,
  12622. plci->B1_resource, plci->adjust_b_facilities));
  12623. break;
  12624. }
  12625. plci->internal_command = plci->adjust_b_command;
  12626. sig_req(plci, RESOURCES, 0);
  12627. send_req(plci);
  12628. plci->adjust_b_state = ADJUST_B_SWITCH_L1_2;
  12629. break;
  12630. }
  12631. plci->adjust_b_state = ADJUST_B_SWITCH_L1_2;
  12632. Rc = OK;
  12633. case ADJUST_B_SWITCH_L1_2:
  12634. if ((Rc != OK) && (Rc != OK_FC))
  12635. {
  12636. dbug(1, dprintf("[%06lx] %s,%d: Adjust B switch failed %02x %d %04x",
  12637. UnMapId(Id), (char *)(FILE_), __LINE__,
  12638. Rc, plci->B1_resource, plci->adjust_b_facilities));
  12639. Info = _WRONG_STATE;
  12640. break;
  12641. }
  12642. plci->adjust_b_state = ADJUST_B_RESTORE_VOICE_1;
  12643. Rc = OK;
  12644. case ADJUST_B_RESTORE_VOICE_1:
  12645. case ADJUST_B_RESTORE_VOICE_2:
  12646. if (plci->adjust_b_mode & ADJUST_B_MODE_RESTORE)
  12647. {
  12648. Info = adv_voice_restore_config(Id, plci, Rc);
  12649. if ((Info != GOOD) || plci->internal_command)
  12650. break;
  12651. }
  12652. plci->adjust_b_state = ADJUST_B_RESTORE_DTMF_PARAMETER_1;
  12653. Rc = OK;
  12654. case ADJUST_B_RESTORE_DTMF_PARAMETER_1:
  12655. case ADJUST_B_RESTORE_DTMF_PARAMETER_2:
  12656. if (plci->adjust_b_mode & ADJUST_B_MODE_RESTORE)
  12657. {
  12658. Info = dtmf_parameter_restore_config(Id, plci, Rc);
  12659. if ((Info != GOOD) || plci->internal_command)
  12660. break;
  12661. }
  12662. plci->adjust_b_state = ADJUST_B_RESTORE_EC_1;
  12663. Rc = OK;
  12664. case ADJUST_B_RESTORE_EC_1:
  12665. case ADJUST_B_RESTORE_EC_2:
  12666. if (plci->adjust_b_mode & ADJUST_B_MODE_RESTORE)
  12667. {
  12668. Info = ec_restore_config(Id, plci, Rc);
  12669. if ((Info != GOOD) || plci->internal_command)
  12670. break;
  12671. }
  12672. plci->adjust_b_state = ADJUST_B_ASSIGN_L23_1;
  12673. case ADJUST_B_ASSIGN_L23_1:
  12674. if (plci->adjust_b_mode & ADJUST_B_MODE_ASSIGN_L23)
  12675. {
  12676. if (plci_nl_busy(plci))
  12677. {
  12678. plci->internal_command = plci->adjust_b_command;
  12679. break;
  12680. }
  12681. if (plci->adjust_b_mode & ADJUST_B_MODE_CONNECT)
  12682. plci->call_dir |= CALL_DIR_FORCE_OUTG_NL;
  12683. if (plci->adjust_b_parms_msg != NULL)
  12684. api_load_msg(plci->adjust_b_parms_msg, bp);
  12685. else
  12686. api_load_msg(&plci->B_protocol, bp);
  12687. Info = add_b23(plci, bp);
  12688. if (Info != GOOD)
  12689. {
  12690. dbug(1, dprintf("[%06lx] %s,%d: Adjust B invalid L23 parameters %04x",
  12691. UnMapId(Id), (char *)(FILE_), __LINE__, Info));
  12692. break;
  12693. }
  12694. plci->internal_command = plci->adjust_b_command;
  12695. nl_req_ncci(plci, ASSIGN, 0);
  12696. send_req(plci);
  12697. plci->adjust_b_state = ADJUST_B_ASSIGN_L23_2;
  12698. break;
  12699. }
  12700. plci->adjust_b_state = ADJUST_B_ASSIGN_L23_2;
  12701. Rc = ASSIGN_OK;
  12702. case ADJUST_B_ASSIGN_L23_2:
  12703. if ((Rc != OK) && (Rc != OK_FC) && (Rc != ASSIGN_OK))
  12704. {
  12705. dbug(1, dprintf("[%06lx] %s,%d: Adjust B assign failed %02x",
  12706. UnMapId(Id), (char *)(FILE_), __LINE__, Rc));
  12707. Info = _WRONG_STATE;
  12708. break;
  12709. }
  12710. if (plci->adjust_b_mode & ADJUST_B_MODE_ASSIGN_L23)
  12711. {
  12712. if (Rc != ASSIGN_OK)
  12713. {
  12714. plci->internal_command = plci->adjust_b_command;
  12715. break;
  12716. }
  12717. }
  12718. if (plci->adjust_b_mode & ADJUST_B_MODE_USER_CONNECT)
  12719. {
  12720. plci->adjust_b_restore = true;
  12721. break;
  12722. }
  12723. plci->adjust_b_state = ADJUST_B_CONNECT_1;
  12724. case ADJUST_B_CONNECT_1:
  12725. if (plci->adjust_b_mode & ADJUST_B_MODE_CONNECT)
  12726. {
  12727. plci->internal_command = plci->adjust_b_command;
  12728. if (plci_nl_busy(plci))
  12729. break;
  12730. nl_req_ncci(plci, N_CONNECT, 0);
  12731. send_req(plci);
  12732. plci->adjust_b_state = ADJUST_B_CONNECT_2;
  12733. break;
  12734. }
  12735. plci->adjust_b_state = ADJUST_B_RESTORE_DTMF_1;
  12736. Rc = OK;
  12737. case ADJUST_B_CONNECT_2:
  12738. case ADJUST_B_CONNECT_3:
  12739. case ADJUST_B_CONNECT_4:
  12740. if ((Rc != OK) && (Rc != OK_FC) && (Rc != 0))
  12741. {
  12742. dbug(1, dprintf("[%06lx] %s,%d: Adjust B connect failed %02x",
  12743. UnMapId(Id), (char *)(FILE_), __LINE__, Rc));
  12744. Info = _WRONG_STATE;
  12745. break;
  12746. }
  12747. if (Rc == OK)
  12748. {
  12749. if (plci->adjust_b_mode & ADJUST_B_MODE_CONNECT)
  12750. {
  12751. get_ncci(plci, (byte)(Id >> 16), plci->adjust_b_ncci);
  12752. Id = (Id & 0xffff) | (((dword)(plci->adjust_b_ncci)) << 16);
  12753. }
  12754. if (plci->adjust_b_state == ADJUST_B_CONNECT_2)
  12755. plci->adjust_b_state = ADJUST_B_CONNECT_3;
  12756. else if (plci->adjust_b_state == ADJUST_B_CONNECT_4)
  12757. plci->adjust_b_state = ADJUST_B_RESTORE_DTMF_1;
  12758. }
  12759. else if (Rc == 0)
  12760. {
  12761. if (plci->adjust_b_state == ADJUST_B_CONNECT_2)
  12762. plci->adjust_b_state = ADJUST_B_CONNECT_4;
  12763. else if (plci->adjust_b_state == ADJUST_B_CONNECT_3)
  12764. plci->adjust_b_state = ADJUST_B_RESTORE_DTMF_1;
  12765. }
  12766. if (plci->adjust_b_state != ADJUST_B_RESTORE_DTMF_1)
  12767. {
  12768. plci->internal_command = plci->adjust_b_command;
  12769. break;
  12770. }
  12771. Rc = OK;
  12772. case ADJUST_B_RESTORE_DTMF_1:
  12773. case ADJUST_B_RESTORE_DTMF_2:
  12774. if (plci->adjust_b_mode & ADJUST_B_MODE_RESTORE)
  12775. {
  12776. Info = dtmf_restore_config(Id, plci, Rc);
  12777. if ((Info != GOOD) || plci->internal_command)
  12778. break;
  12779. }
  12780. plci->adjust_b_state = ADJUST_B_RESTORE_MIXER_1;
  12781. Rc = OK;
  12782. case ADJUST_B_RESTORE_MIXER_1:
  12783. case ADJUST_B_RESTORE_MIXER_2:
  12784. case ADJUST_B_RESTORE_MIXER_3:
  12785. case ADJUST_B_RESTORE_MIXER_4:
  12786. case ADJUST_B_RESTORE_MIXER_5:
  12787. case ADJUST_B_RESTORE_MIXER_6:
  12788. case ADJUST_B_RESTORE_MIXER_7:
  12789. if (plci->adjust_b_mode & ADJUST_B_MODE_RESTORE)
  12790. {
  12791. Info = mixer_restore_config(Id, plci, Rc);
  12792. if ((Info != GOOD) || plci->internal_command)
  12793. break;
  12794. }
  12795. plci->adjust_b_state = ADJUST_B_END;
  12796. case ADJUST_B_END:
  12797. break;
  12798. }
  12799. return (Info);
  12800. }
  12801. static void adjust_b1_resource(dword Id, PLCI *plci, API_SAVE *bp_msg, word b1_facilities, word internal_command)
  12802. {
  12803. dbug(1, dprintf("[%06lx] %s,%d: adjust_b1_resource %d %04x",
  12804. UnMapId(Id), (char *)(FILE_), __LINE__,
  12805. plci->B1_resource, b1_facilities));
  12806. plci->adjust_b_parms_msg = bp_msg;
  12807. plci->adjust_b_facilities = b1_facilities;
  12808. plci->adjust_b_command = internal_command;
  12809. plci->adjust_b_ncci = (word)(Id >> 16);
  12810. if ((bp_msg == NULL) && (plci->B1_resource == 0))
  12811. plci->adjust_b_mode = ADJUST_B_MODE_SAVE | ADJUST_B_MODE_NO_RESOURCE | ADJUST_B_MODE_SWITCH_L1;
  12812. else
  12813. plci->adjust_b_mode = ADJUST_B_MODE_SAVE | ADJUST_B_MODE_SWITCH_L1 | ADJUST_B_MODE_RESTORE;
  12814. plci->adjust_b_state = ADJUST_B_START;
  12815. dbug(1, dprintf("[%06lx] %s,%d: Adjust B1 resource %d %04x...",
  12816. UnMapId(Id), (char *)(FILE_), __LINE__,
  12817. plci->B1_resource, b1_facilities));
  12818. }
  12819. static void adjust_b_restore(dword Id, PLCI *plci, byte Rc)
  12820. {
  12821. word internal_command;
  12822. dbug(1, dprintf("[%06lx] %s,%d: adjust_b_restore %02x %04x",
  12823. UnMapId(Id), (char *)(FILE_), __LINE__, Rc, plci->internal_command));
  12824. internal_command = plci->internal_command;
  12825. plci->internal_command = 0;
  12826. switch (internal_command)
  12827. {
  12828. default:
  12829. plci->command = 0;
  12830. if (plci->req_in != 0)
  12831. {
  12832. plci->internal_command = ADJUST_B_RESTORE_1;
  12833. break;
  12834. }
  12835. Rc = OK;
  12836. case ADJUST_B_RESTORE_1:
  12837. if ((Rc != OK) && (Rc != OK_FC))
  12838. {
  12839. dbug(1, dprintf("[%06lx] %s,%d: Adjust B enqueued failed %02x",
  12840. UnMapId(Id), (char *)(FILE_), __LINE__, Rc));
  12841. }
  12842. plci->adjust_b_parms_msg = NULL;
  12843. plci->adjust_b_facilities = plci->B1_facilities;
  12844. plci->adjust_b_command = ADJUST_B_RESTORE_2;
  12845. plci->adjust_b_ncci = (word)(Id >> 16);
  12846. plci->adjust_b_mode = ADJUST_B_MODE_RESTORE;
  12847. plci->adjust_b_state = ADJUST_B_START;
  12848. dbug(1, dprintf("[%06lx] %s,%d: Adjust B restore...",
  12849. UnMapId(Id), (char *)(FILE_), __LINE__));
  12850. case ADJUST_B_RESTORE_2:
  12851. if (adjust_b_process(Id, plci, Rc) != GOOD)
  12852. {
  12853. dbug(1, dprintf("[%06lx] %s,%d: Adjust B restore failed",
  12854. UnMapId(Id), (char *)(FILE_), __LINE__));
  12855. }
  12856. if (plci->internal_command)
  12857. break;
  12858. break;
  12859. }
  12860. }
  12861. static void reset_b3_command(dword Id, PLCI *plci, byte Rc)
  12862. {
  12863. word Info;
  12864. word internal_command;
  12865. dbug(1, dprintf("[%06lx] %s,%d: reset_b3_command %02x %04x",
  12866. UnMapId(Id), (char *)(FILE_), __LINE__, Rc, plci->internal_command));
  12867. Info = GOOD;
  12868. internal_command = plci->internal_command;
  12869. plci->internal_command = 0;
  12870. switch (internal_command)
  12871. {
  12872. default:
  12873. plci->command = 0;
  12874. plci->adjust_b_parms_msg = NULL;
  12875. plci->adjust_b_facilities = plci->B1_facilities;
  12876. plci->adjust_b_command = RESET_B3_COMMAND_1;
  12877. plci->adjust_b_ncci = (word)(Id >> 16);
  12878. plci->adjust_b_mode = ADJUST_B_MODE_REMOVE_L23 | ADJUST_B_MODE_ASSIGN_L23 | ADJUST_B_MODE_CONNECT;
  12879. plci->adjust_b_state = ADJUST_B_START;
  12880. dbug(1, dprintf("[%06lx] %s,%d: Reset B3...",
  12881. UnMapId(Id), (char *)(FILE_), __LINE__));
  12882. case RESET_B3_COMMAND_1:
  12883. Info = adjust_b_process(Id, plci, Rc);
  12884. if (Info != GOOD)
  12885. {
  12886. dbug(1, dprintf("[%06lx] %s,%d: Reset failed",
  12887. UnMapId(Id), (char *)(FILE_), __LINE__));
  12888. break;
  12889. }
  12890. if (plci->internal_command)
  12891. return;
  12892. break;
  12893. }
  12894. /* sendf (plci->appl, _RESET_B3_R | CONFIRM, Id, plci->number, "w", Info);*/
  12895. sendf(plci->appl, _RESET_B3_I, Id, 0, "s", "");
  12896. }
  12897. static void select_b_command(dword Id, PLCI *plci, byte Rc)
  12898. {
  12899. word Info;
  12900. word internal_command;
  12901. byte esc_chi[3];
  12902. dbug(1, dprintf("[%06lx] %s,%d: select_b_command %02x %04x",
  12903. UnMapId(Id), (char *)(FILE_), __LINE__, Rc, plci->internal_command));
  12904. Info = GOOD;
  12905. internal_command = plci->internal_command;
  12906. plci->internal_command = 0;
  12907. switch (internal_command)
  12908. {
  12909. default:
  12910. plci->command = 0;
  12911. plci->adjust_b_parms_msg = &plci->saved_msg;
  12912. if ((plci->tel == ADV_VOICE) && (plci == plci->adapter->AdvSignalPLCI))
  12913. plci->adjust_b_facilities = plci->B1_facilities | B1_FACILITY_VOICE;
  12914. else
  12915. plci->adjust_b_facilities = plci->B1_facilities & ~B1_FACILITY_VOICE;
  12916. plci->adjust_b_command = SELECT_B_COMMAND_1;
  12917. plci->adjust_b_ncci = (word)(Id >> 16);
  12918. if (plci->saved_msg.parms[0].length == 0)
  12919. {
  12920. plci->adjust_b_mode = ADJUST_B_MODE_SAVE | ADJUST_B_MODE_REMOVE_L23 | ADJUST_B_MODE_SWITCH_L1 |
  12921. ADJUST_B_MODE_NO_RESOURCE;
  12922. }
  12923. else
  12924. {
  12925. plci->adjust_b_mode = ADJUST_B_MODE_SAVE | ADJUST_B_MODE_REMOVE_L23 | ADJUST_B_MODE_SWITCH_L1 |
  12926. ADJUST_B_MODE_ASSIGN_L23 | ADJUST_B_MODE_USER_CONNECT | ADJUST_B_MODE_RESTORE;
  12927. }
  12928. plci->adjust_b_state = ADJUST_B_START;
  12929. dbug(1, dprintf("[%06lx] %s,%d: Select B protocol...",
  12930. UnMapId(Id), (char *)(FILE_), __LINE__));
  12931. case SELECT_B_COMMAND_1:
  12932. Info = adjust_b_process(Id, plci, Rc);
  12933. if (Info != GOOD)
  12934. {
  12935. dbug(1, dprintf("[%06lx] %s,%d: Select B protocol failed",
  12936. UnMapId(Id), (char *)(FILE_), __LINE__));
  12937. break;
  12938. }
  12939. if (plci->internal_command)
  12940. return;
  12941. if (plci->tel == ADV_VOICE)
  12942. {
  12943. esc_chi[0] = 0x02;
  12944. esc_chi[1] = 0x18;
  12945. esc_chi[2] = plci->b_channel;
  12946. SetVoiceChannel(plci->adapter->AdvCodecPLCI, esc_chi, plci->adapter);
  12947. }
  12948. break;
  12949. }
  12950. sendf(plci->appl, _SELECT_B_REQ | CONFIRM, Id, plci->number, "w", Info);
  12951. }
  12952. static void fax_connect_ack_command(dword Id, PLCI *plci, byte Rc)
  12953. {
  12954. word internal_command;
  12955. dbug(1, dprintf("[%06lx] %s,%d: fax_connect_ack_command %02x %04x",
  12956. UnMapId(Id), (char *)(FILE_), __LINE__, Rc, plci->internal_command));
  12957. internal_command = plci->internal_command;
  12958. plci->internal_command = 0;
  12959. switch (internal_command)
  12960. {
  12961. default:
  12962. plci->command = 0;
  12963. case FAX_CONNECT_ACK_COMMAND_1:
  12964. if (plci_nl_busy(plci))
  12965. {
  12966. plci->internal_command = FAX_CONNECT_ACK_COMMAND_1;
  12967. return;
  12968. }
  12969. plci->internal_command = FAX_CONNECT_ACK_COMMAND_2;
  12970. plci->NData[0].P = plci->fax_connect_info_buffer;
  12971. plci->NData[0].PLength = plci->fax_connect_info_length;
  12972. plci->NL.X = plci->NData;
  12973. plci->NL.ReqCh = 0;
  12974. plci->NL.Req = plci->nl_req = (byte) N_CONNECT_ACK;
  12975. plci->adapter->request(&plci->NL);
  12976. return;
  12977. case FAX_CONNECT_ACK_COMMAND_2:
  12978. if ((Rc != OK) && (Rc != OK_FC))
  12979. {
  12980. dbug(1, dprintf("[%06lx] %s,%d: FAX issue CONNECT ACK failed %02x",
  12981. UnMapId(Id), (char *)(FILE_), __LINE__, Rc));
  12982. break;
  12983. }
  12984. }
  12985. if ((plci->ncpi_state & NCPI_VALID_CONNECT_B3_ACT)
  12986. && !(plci->ncpi_state & NCPI_CONNECT_B3_ACT_SENT))
  12987. {
  12988. if (plci->B3_prot == 4)
  12989. sendf(plci->appl, _CONNECT_B3_ACTIVE_I, Id, 0, "s", "");
  12990. else
  12991. sendf(plci->appl, _CONNECT_B3_ACTIVE_I, Id, 0, "S", plci->ncpi_buffer);
  12992. plci->ncpi_state |= NCPI_CONNECT_B3_ACT_SENT;
  12993. }
  12994. }
  12995. static void fax_edata_ack_command(dword Id, PLCI *plci, byte Rc)
  12996. {
  12997. word internal_command;
  12998. dbug(1, dprintf("[%06lx] %s,%d: fax_edata_ack_command %02x %04x",
  12999. UnMapId(Id), (char *)(FILE_), __LINE__, Rc, plci->internal_command));
  13000. internal_command = plci->internal_command;
  13001. plci->internal_command = 0;
  13002. switch (internal_command)
  13003. {
  13004. default:
  13005. plci->command = 0;
  13006. case FAX_EDATA_ACK_COMMAND_1:
  13007. if (plci_nl_busy(plci))
  13008. {
  13009. plci->internal_command = FAX_EDATA_ACK_COMMAND_1;
  13010. return;
  13011. }
  13012. plci->internal_command = FAX_EDATA_ACK_COMMAND_2;
  13013. plci->NData[0].P = plci->fax_connect_info_buffer;
  13014. plci->NData[0].PLength = plci->fax_edata_ack_length;
  13015. plci->NL.X = plci->NData;
  13016. plci->NL.ReqCh = 0;
  13017. plci->NL.Req = plci->nl_req = (byte) N_EDATA;
  13018. plci->adapter->request(&plci->NL);
  13019. return;
  13020. case FAX_EDATA_ACK_COMMAND_2:
  13021. if ((Rc != OK) && (Rc != OK_FC))
  13022. {
  13023. dbug(1, dprintf("[%06lx] %s,%d: FAX issue EDATA ACK failed %02x",
  13024. UnMapId(Id), (char *)(FILE_), __LINE__, Rc));
  13025. break;
  13026. }
  13027. }
  13028. }
  13029. static void fax_connect_info_command(dword Id, PLCI *plci, byte Rc)
  13030. {
  13031. word Info;
  13032. word internal_command;
  13033. dbug(1, dprintf("[%06lx] %s,%d: fax_connect_info_command %02x %04x",
  13034. UnMapId(Id), (char *)(FILE_), __LINE__, Rc, plci->internal_command));
  13035. Info = GOOD;
  13036. internal_command = plci->internal_command;
  13037. plci->internal_command = 0;
  13038. switch (internal_command)
  13039. {
  13040. default:
  13041. plci->command = 0;
  13042. case FAX_CONNECT_INFO_COMMAND_1:
  13043. if (plci_nl_busy(plci))
  13044. {
  13045. plci->internal_command = FAX_CONNECT_INFO_COMMAND_1;
  13046. return;
  13047. }
  13048. plci->internal_command = FAX_CONNECT_INFO_COMMAND_2;
  13049. plci->NData[0].P = plci->fax_connect_info_buffer;
  13050. plci->NData[0].PLength = plci->fax_connect_info_length;
  13051. plci->NL.X = plci->NData;
  13052. plci->NL.ReqCh = 0;
  13053. plci->NL.Req = plci->nl_req = (byte) N_EDATA;
  13054. plci->adapter->request(&plci->NL);
  13055. return;
  13056. case FAX_CONNECT_INFO_COMMAND_2:
  13057. if ((Rc != OK) && (Rc != OK_FC))
  13058. {
  13059. dbug(1, dprintf("[%06lx] %s,%d: FAX setting connect info failed %02x",
  13060. UnMapId(Id), (char *)(FILE_), __LINE__, Rc));
  13061. Info = _WRONG_STATE;
  13062. break;
  13063. }
  13064. if (plci_nl_busy(plci))
  13065. {
  13066. plci->internal_command = FAX_CONNECT_INFO_COMMAND_2;
  13067. return;
  13068. }
  13069. plci->command = _CONNECT_B3_R;
  13070. nl_req_ncci(plci, N_CONNECT, 0);
  13071. send_req(plci);
  13072. return;
  13073. }
  13074. sendf(plci->appl, _CONNECT_B3_R | CONFIRM, Id, plci->number, "w", Info);
  13075. }
  13076. static void fax_adjust_b23_command(dword Id, PLCI *plci, byte Rc)
  13077. {
  13078. word Info;
  13079. word internal_command;
  13080. dbug(1, dprintf("[%06lx] %s,%d: fax_adjust_b23_command %02x %04x",
  13081. UnMapId(Id), (char *)(FILE_), __LINE__, Rc, plci->internal_command));
  13082. Info = GOOD;
  13083. internal_command = plci->internal_command;
  13084. plci->internal_command = 0;
  13085. switch (internal_command)
  13086. {
  13087. default:
  13088. plci->command = 0;
  13089. plci->adjust_b_parms_msg = NULL;
  13090. plci->adjust_b_facilities = plci->B1_facilities;
  13091. plci->adjust_b_command = FAX_ADJUST_B23_COMMAND_1;
  13092. plci->adjust_b_ncci = (word)(Id >> 16);
  13093. plci->adjust_b_mode = ADJUST_B_MODE_REMOVE_L23 | ADJUST_B_MODE_ASSIGN_L23;
  13094. plci->adjust_b_state = ADJUST_B_START;
  13095. dbug(1, dprintf("[%06lx] %s,%d: FAX adjust B23...",
  13096. UnMapId(Id), (char *)(FILE_), __LINE__));
  13097. case FAX_ADJUST_B23_COMMAND_1:
  13098. Info = adjust_b_process(Id, plci, Rc);
  13099. if (Info != GOOD)
  13100. {
  13101. dbug(1, dprintf("[%06lx] %s,%d: FAX adjust failed",
  13102. UnMapId(Id), (char *)(FILE_), __LINE__));
  13103. break;
  13104. }
  13105. if (plci->internal_command)
  13106. return;
  13107. case FAX_ADJUST_B23_COMMAND_2:
  13108. if (plci_nl_busy(plci))
  13109. {
  13110. plci->internal_command = FAX_ADJUST_B23_COMMAND_2;
  13111. return;
  13112. }
  13113. plci->command = _CONNECT_B3_R;
  13114. nl_req_ncci(plci, N_CONNECT, 0);
  13115. send_req(plci);
  13116. return;
  13117. }
  13118. sendf(plci->appl, _CONNECT_B3_R | CONFIRM, Id, plci->number, "w", Info);
  13119. }
  13120. static void fax_disconnect_command(dword Id, PLCI *plci, byte Rc)
  13121. {
  13122. word internal_command;
  13123. dbug(1, dprintf("[%06lx] %s,%d: fax_disconnect_command %02x %04x",
  13124. UnMapId(Id), (char *)(FILE_), __LINE__, Rc, plci->internal_command));
  13125. internal_command = plci->internal_command;
  13126. plci->internal_command = 0;
  13127. switch (internal_command)
  13128. {
  13129. default:
  13130. plci->command = 0;
  13131. plci->internal_command = FAX_DISCONNECT_COMMAND_1;
  13132. return;
  13133. case FAX_DISCONNECT_COMMAND_1:
  13134. case FAX_DISCONNECT_COMMAND_2:
  13135. case FAX_DISCONNECT_COMMAND_3:
  13136. if ((Rc != OK) && (Rc != OK_FC) && (Rc != 0))
  13137. {
  13138. dbug(1, dprintf("[%06lx] %s,%d: FAX disconnect EDATA failed %02x",
  13139. UnMapId(Id), (char *)(FILE_), __LINE__, Rc));
  13140. break;
  13141. }
  13142. if (Rc == OK)
  13143. {
  13144. if ((internal_command == FAX_DISCONNECT_COMMAND_1)
  13145. || (internal_command == FAX_DISCONNECT_COMMAND_2))
  13146. {
  13147. plci->internal_command = FAX_DISCONNECT_COMMAND_2;
  13148. }
  13149. }
  13150. else if (Rc == 0)
  13151. {
  13152. if (internal_command == FAX_DISCONNECT_COMMAND_1)
  13153. plci->internal_command = FAX_DISCONNECT_COMMAND_3;
  13154. }
  13155. return;
  13156. }
  13157. }
  13158. static void rtp_connect_b3_req_command(dword Id, PLCI *plci, byte Rc)
  13159. {
  13160. word Info;
  13161. word internal_command;
  13162. dbug(1, dprintf("[%06lx] %s,%d: rtp_connect_b3_req_command %02x %04x",
  13163. UnMapId(Id), (char *)(FILE_), __LINE__, Rc, plci->internal_command));
  13164. Info = GOOD;
  13165. internal_command = plci->internal_command;
  13166. plci->internal_command = 0;
  13167. switch (internal_command)
  13168. {
  13169. default:
  13170. plci->command = 0;
  13171. case RTP_CONNECT_B3_REQ_COMMAND_1:
  13172. if (plci_nl_busy(plci))
  13173. {
  13174. plci->internal_command = RTP_CONNECT_B3_REQ_COMMAND_1;
  13175. return;
  13176. }
  13177. plci->internal_command = RTP_CONNECT_B3_REQ_COMMAND_2;
  13178. nl_req_ncci(plci, N_CONNECT, 0);
  13179. send_req(plci);
  13180. return;
  13181. case RTP_CONNECT_B3_REQ_COMMAND_2:
  13182. if ((Rc != OK) && (Rc != OK_FC))
  13183. {
  13184. dbug(1, dprintf("[%06lx] %s,%d: RTP setting connect info failed %02x",
  13185. UnMapId(Id), (char *)(FILE_), __LINE__, Rc));
  13186. Info = _WRONG_STATE;
  13187. break;
  13188. }
  13189. if (plci_nl_busy(plci))
  13190. {
  13191. plci->internal_command = RTP_CONNECT_B3_REQ_COMMAND_2;
  13192. return;
  13193. }
  13194. plci->internal_command = RTP_CONNECT_B3_REQ_COMMAND_3;
  13195. plci->NData[0].PLength = plci->internal_req_buffer[0];
  13196. plci->NData[0].P = plci->internal_req_buffer + 1;
  13197. plci->NL.X = plci->NData;
  13198. plci->NL.ReqCh = 0;
  13199. plci->NL.Req = plci->nl_req = (byte) N_UDATA;
  13200. plci->adapter->request(&plci->NL);
  13201. break;
  13202. case RTP_CONNECT_B3_REQ_COMMAND_3:
  13203. return;
  13204. }
  13205. sendf(plci->appl, _CONNECT_B3_R | CONFIRM, Id, plci->number, "w", Info);
  13206. }
  13207. static void rtp_connect_b3_res_command(dword Id, PLCI *plci, byte Rc)
  13208. {
  13209. word internal_command;
  13210. dbug(1, dprintf("[%06lx] %s,%d: rtp_connect_b3_res_command %02x %04x",
  13211. UnMapId(Id), (char *)(FILE_), __LINE__, Rc, plci->internal_command));
  13212. internal_command = plci->internal_command;
  13213. plci->internal_command = 0;
  13214. switch (internal_command)
  13215. {
  13216. default:
  13217. plci->command = 0;
  13218. case RTP_CONNECT_B3_RES_COMMAND_1:
  13219. if (plci_nl_busy(plci))
  13220. {
  13221. plci->internal_command = RTP_CONNECT_B3_RES_COMMAND_1;
  13222. return;
  13223. }
  13224. plci->internal_command = RTP_CONNECT_B3_RES_COMMAND_2;
  13225. nl_req_ncci(plci, N_CONNECT_ACK, (byte)(Id >> 16));
  13226. send_req(plci);
  13227. return;
  13228. case RTP_CONNECT_B3_RES_COMMAND_2:
  13229. if ((Rc != OK) && (Rc != OK_FC))
  13230. {
  13231. dbug(1, dprintf("[%06lx] %s,%d: RTP setting connect resp info failed %02x",
  13232. UnMapId(Id), (char *)(FILE_), __LINE__, Rc));
  13233. break;
  13234. }
  13235. if (plci_nl_busy(plci))
  13236. {
  13237. plci->internal_command = RTP_CONNECT_B3_RES_COMMAND_2;
  13238. return;
  13239. }
  13240. sendf(plci->appl, _CONNECT_B3_ACTIVE_I, Id, 0, "s", "");
  13241. plci->internal_command = RTP_CONNECT_B3_RES_COMMAND_3;
  13242. plci->NData[0].PLength = plci->internal_req_buffer[0];
  13243. plci->NData[0].P = plci->internal_req_buffer + 1;
  13244. plci->NL.X = plci->NData;
  13245. plci->NL.ReqCh = 0;
  13246. plci->NL.Req = plci->nl_req = (byte) N_UDATA;
  13247. plci->adapter->request(&plci->NL);
  13248. return;
  13249. case RTP_CONNECT_B3_RES_COMMAND_3:
  13250. return;
  13251. }
  13252. }
  13253. static void hold_save_command(dword Id, PLCI *plci, byte Rc)
  13254. {
  13255. byte SS_Ind[] = "\x05\x02\x00\x02\x00\x00"; /* Hold_Ind struct*/
  13256. word Info;
  13257. word internal_command;
  13258. dbug(1, dprintf("[%06lx] %s,%d: hold_save_command %02x %04x",
  13259. UnMapId(Id), (char *)(FILE_), __LINE__, Rc, plci->internal_command));
  13260. Info = GOOD;
  13261. internal_command = plci->internal_command;
  13262. plci->internal_command = 0;
  13263. switch (internal_command)
  13264. {
  13265. default:
  13266. if (!plci->NL.Id)
  13267. break;
  13268. plci->command = 0;
  13269. plci->adjust_b_parms_msg = NULL;
  13270. plci->adjust_b_facilities = plci->B1_facilities;
  13271. plci->adjust_b_command = HOLD_SAVE_COMMAND_1;
  13272. plci->adjust_b_ncci = (word)(Id >> 16);
  13273. plci->adjust_b_mode = ADJUST_B_MODE_SAVE | ADJUST_B_MODE_REMOVE_L23;
  13274. plci->adjust_b_state = ADJUST_B_START;
  13275. dbug(1, dprintf("[%06lx] %s,%d: HOLD save...",
  13276. UnMapId(Id), (char *)(FILE_), __LINE__));
  13277. case HOLD_SAVE_COMMAND_1:
  13278. Info = adjust_b_process(Id, plci, Rc);
  13279. if (Info != GOOD)
  13280. {
  13281. dbug(1, dprintf("[%06lx] %s,%d: HOLD save failed",
  13282. UnMapId(Id), (char *)(FILE_), __LINE__));
  13283. break;
  13284. }
  13285. if (plci->internal_command)
  13286. return;
  13287. }
  13288. sendf(plci->appl, _FACILITY_I, Id & 0xffffL, 0, "ws", 3, SS_Ind);
  13289. }
  13290. static void retrieve_restore_command(dword Id, PLCI *plci, byte Rc)
  13291. {
  13292. byte SS_Ind[] = "\x05\x03\x00\x02\x00\x00"; /* Retrieve_Ind struct*/
  13293. word Info;
  13294. word internal_command;
  13295. dbug(1, dprintf("[%06lx] %s,%d: retrieve_restore_command %02x %04x",
  13296. UnMapId(Id), (char *)(FILE_), __LINE__, Rc, plci->internal_command));
  13297. Info = GOOD;
  13298. internal_command = plci->internal_command;
  13299. plci->internal_command = 0;
  13300. switch (internal_command)
  13301. {
  13302. default:
  13303. plci->command = 0;
  13304. plci->adjust_b_parms_msg = NULL;
  13305. plci->adjust_b_facilities = plci->B1_facilities;
  13306. plci->adjust_b_command = RETRIEVE_RESTORE_COMMAND_1;
  13307. plci->adjust_b_ncci = (word)(Id >> 16);
  13308. plci->adjust_b_mode = ADJUST_B_MODE_ASSIGN_L23 | ADJUST_B_MODE_USER_CONNECT | ADJUST_B_MODE_RESTORE;
  13309. plci->adjust_b_state = ADJUST_B_START;
  13310. dbug(1, dprintf("[%06lx] %s,%d: RETRIEVE restore...",
  13311. UnMapId(Id), (char *)(FILE_), __LINE__));
  13312. case RETRIEVE_RESTORE_COMMAND_1:
  13313. Info = adjust_b_process(Id, plci, Rc);
  13314. if (Info != GOOD)
  13315. {
  13316. dbug(1, dprintf("[%06lx] %s,%d: RETRIEVE restore failed",
  13317. UnMapId(Id), (char *)(FILE_), __LINE__));
  13318. break;
  13319. }
  13320. if (plci->internal_command)
  13321. return;
  13322. }
  13323. sendf(plci->appl, _FACILITY_I, Id & 0xffffL, 0, "ws", 3, SS_Ind);
  13324. }
  13325. static void init_b1_config(PLCI *plci)
  13326. {
  13327. dbug(1, dprintf("[%06lx] %s,%d: init_b1_config",
  13328. (dword)((plci->Id << 8) | UnMapController(plci->adapter->Id)),
  13329. (char *)(FILE_), __LINE__));
  13330. plci->B1_resource = 0;
  13331. plci->B1_facilities = 0;
  13332. plci->li_bchannel_id = 0;
  13333. mixer_clear_config(plci);
  13334. ec_clear_config(plci);
  13335. dtmf_rec_clear_config(plci);
  13336. dtmf_send_clear_config(plci);
  13337. dtmf_parameter_clear_config(plci);
  13338. adv_voice_clear_config(plci);
  13339. adjust_b_clear(plci);
  13340. }
  13341. static void clear_b1_config(PLCI *plci)
  13342. {
  13343. dbug(1, dprintf("[%06lx] %s,%d: clear_b1_config",
  13344. (dword)((plci->Id << 8) | UnMapController(plci->adapter->Id)),
  13345. (char *)(FILE_), __LINE__));
  13346. adv_voice_clear_config(plci);
  13347. adjust_b_clear(plci);
  13348. ec_clear_config(plci);
  13349. dtmf_rec_clear_config(plci);
  13350. dtmf_send_clear_config(plci);
  13351. dtmf_parameter_clear_config(plci);
  13352. if ((plci->li_bchannel_id != 0)
  13353. && (li_config_table[plci->adapter->li_base + (plci->li_bchannel_id - 1)].plci == plci))
  13354. {
  13355. mixer_clear_config(plci);
  13356. li_config_table[plci->adapter->li_base + (plci->li_bchannel_id - 1)].plci = NULL;
  13357. plci->li_bchannel_id = 0;
  13358. }
  13359. plci->B1_resource = 0;
  13360. plci->B1_facilities = 0;
  13361. }
  13362. /* -----------------------------------------------------------------
  13363. XON protocol local helpers
  13364. ----------------------------------------------------------------- */
  13365. static void channel_flow_control_remove(PLCI *plci) {
  13366. DIVA_CAPI_ADAPTER *a = plci->adapter;
  13367. word i;
  13368. for (i = 1; i < MAX_NL_CHANNEL + 1; i++) {
  13369. if (a->ch_flow_plci[i] == plci->Id) {
  13370. a->ch_flow_plci[i] = 0;
  13371. a->ch_flow_control[i] = 0;
  13372. }
  13373. }
  13374. }
  13375. static void channel_x_on(PLCI *plci, byte ch) {
  13376. DIVA_CAPI_ADAPTER *a = plci->adapter;
  13377. if (a->ch_flow_control[ch] & N_XON_SENT) {
  13378. a->ch_flow_control[ch] &= ~N_XON_SENT;
  13379. }
  13380. }
  13381. static void channel_x_off(PLCI *plci, byte ch, byte flag) {
  13382. DIVA_CAPI_ADAPTER *a = plci->adapter;
  13383. if ((a->ch_flow_control[ch] & N_RX_FLOW_CONTROL_MASK) == 0) {
  13384. a->ch_flow_control[ch] |= (N_CH_XOFF | flag);
  13385. a->ch_flow_plci[ch] = plci->Id;
  13386. a->ch_flow_control_pending++;
  13387. }
  13388. }
  13389. static void channel_request_xon(PLCI *plci, byte ch) {
  13390. DIVA_CAPI_ADAPTER *a = plci->adapter;
  13391. if (a->ch_flow_control[ch] & N_CH_XOFF) {
  13392. a->ch_flow_control[ch] |= N_XON_REQ;
  13393. a->ch_flow_control[ch] &= ~N_CH_XOFF;
  13394. a->ch_flow_control[ch] &= ~N_XON_CONNECT_IND;
  13395. }
  13396. }
  13397. static void channel_xmit_extended_xon(PLCI *plci) {
  13398. DIVA_CAPI_ADAPTER *a;
  13399. int max_ch = ARRAY_SIZE(a->ch_flow_control);
  13400. int i, one_requested = 0;
  13401. if ((!plci) || (!plci->Id) || ((a = plci->adapter) == NULL)) {
  13402. return;
  13403. }
  13404. for (i = 0; i < max_ch; i++) {
  13405. if ((a->ch_flow_control[i] & N_CH_XOFF) &&
  13406. (a->ch_flow_control[i] & N_XON_CONNECT_IND) &&
  13407. (plci->Id == a->ch_flow_plci[i])) {
  13408. channel_request_xon(plci, (byte)i);
  13409. one_requested = 1;
  13410. }
  13411. }
  13412. if (one_requested) {
  13413. channel_xmit_xon(plci);
  13414. }
  13415. }
  13416. /*
  13417. Try to xmit next X_ON
  13418. */
  13419. static int find_channel_with_pending_x_on(DIVA_CAPI_ADAPTER *a, PLCI *plci) {
  13420. int max_ch = ARRAY_SIZE(a->ch_flow_control);
  13421. int i;
  13422. if (!(plci->adapter->manufacturer_features & MANUFACTURER_FEATURE_XONOFF_FLOW_CONTROL)) {
  13423. return (0);
  13424. }
  13425. if (a->last_flow_control_ch >= max_ch) {
  13426. a->last_flow_control_ch = 1;
  13427. }
  13428. for (i = a->last_flow_control_ch; i < max_ch; i++) {
  13429. if ((a->ch_flow_control[i] & N_XON_REQ) &&
  13430. (plci->Id == a->ch_flow_plci[i])) {
  13431. a->last_flow_control_ch = i + 1;
  13432. return (i);
  13433. }
  13434. }
  13435. for (i = 1; i < a->last_flow_control_ch; i++) {
  13436. if ((a->ch_flow_control[i] & N_XON_REQ) &&
  13437. (plci->Id == a->ch_flow_plci[i])) {
  13438. a->last_flow_control_ch = i + 1;
  13439. return (i);
  13440. }
  13441. }
  13442. return (0);
  13443. }
  13444. static void channel_xmit_xon(PLCI *plci) {
  13445. DIVA_CAPI_ADAPTER *a = plci->adapter;
  13446. byte ch;
  13447. if (plci->nl_req || !plci->NL.Id || plci->nl_remove_id) {
  13448. return;
  13449. }
  13450. if ((ch = (byte)find_channel_with_pending_x_on(a, plci)) == 0) {
  13451. return;
  13452. }
  13453. a->ch_flow_control[ch] &= ~N_XON_REQ;
  13454. a->ch_flow_control[ch] |= N_XON_SENT;
  13455. plci->NL.Req = plci->nl_req = (byte)N_XON;
  13456. plci->NL.ReqCh = ch;
  13457. plci->NL.X = plci->NData;
  13458. plci->NL.XNum = 1;
  13459. plci->NData[0].P = &plci->RBuffer[0];
  13460. plci->NData[0].PLength = 0;
  13461. plci->adapter->request(&plci->NL);
  13462. }
  13463. static int channel_can_xon(PLCI *plci, byte ch) {
  13464. APPL *APPLptr;
  13465. DIVA_CAPI_ADAPTER *a;
  13466. word NCCIcode;
  13467. dword count;
  13468. word Num;
  13469. word i;
  13470. APPLptr = plci->appl;
  13471. a = plci->adapter;
  13472. if (!APPLptr)
  13473. return (0);
  13474. NCCIcode = a->ch_ncci[ch] | (((word) a->Id) << 8);
  13475. /* count all buffers within the Application pool */
  13476. /* belonging to the same NCCI. XON if a first is */
  13477. /* used. */
  13478. count = 0;
  13479. Num = 0xffff;
  13480. for (i = 0; i < APPLptr->MaxBuffer; i++) {
  13481. if (NCCIcode == APPLptr->DataNCCI[i]) count++;
  13482. if (!APPLptr->DataNCCI[i] && Num == 0xffff) Num = i;
  13483. }
  13484. if ((count > 2) || (Num == 0xffff)) {
  13485. return (0);
  13486. }
  13487. return (1);
  13488. }
  13489. /*------------------------------------------------------------------*/
  13490. static word CPN_filter_ok(byte *cpn, DIVA_CAPI_ADAPTER *a, word offset)
  13491. {
  13492. return 1;
  13493. }
  13494. /**********************************************************************************/
  13495. /* function groups the listening applications according to the CIP mask and the */
  13496. /* Info_Mask. Each group gets just one Connect_Ind. Some application manufacturer */
  13497. /* are not multi-instance capable, so they start e.g. 30 applications what causes */
  13498. /* big problems on application level (one call, 30 Connect_Ind, ect). The */
  13499. /* function must be enabled by setting "a->group_optimization_enabled" from the */
  13500. /* OS specific part (per adapter). */
  13501. /**********************************************************************************/
  13502. static void group_optimization(DIVA_CAPI_ADAPTER *a, PLCI *plci)
  13503. {
  13504. word i, j, k, busy, group_found;
  13505. dword info_mask_group[MAX_CIP_TYPES];
  13506. dword cip_mask_group[MAX_CIP_TYPES];
  13507. word appl_number_group_type[MAX_APPL];
  13508. PLCI *auxplci;
  13509. set_group_ind_mask(plci); /* all APPLs within this inc. call are allowed to dial in */
  13510. if (!a->group_optimization_enabled)
  13511. {
  13512. dbug(1, dprintf("No group optimization"));
  13513. return;
  13514. }
  13515. dbug(1, dprintf("Group optimization = 0x%x...", a->group_optimization_enabled));
  13516. for (i = 0; i < MAX_CIP_TYPES; i++)
  13517. {
  13518. info_mask_group[i] = 0;
  13519. cip_mask_group[i] = 0;
  13520. }
  13521. for (i = 0; i < MAX_APPL; i++)
  13522. {
  13523. appl_number_group_type[i] = 0;
  13524. }
  13525. for (i = 0; i < max_appl; i++) /* check if any multi instance capable application is present */
  13526. { /* group_optimization set to 1 means not to optimize multi-instance capable applications (default) */
  13527. if (application[i].Id && (application[i].MaxNCCI) > 1 && (a->CIP_Mask[i]) && (a->group_optimization_enabled == 1))
  13528. {
  13529. dbug(1, dprintf("Multi-Instance capable, no optimization required"));
  13530. return; /* allow good application unfiltered access */
  13531. }
  13532. }
  13533. for (i = 0; i < max_appl; i++) /* Build CIP Groups */
  13534. {
  13535. if (application[i].Id && a->CIP_Mask[i])
  13536. {
  13537. for (k = 0, busy = false; k < a->max_plci; k++)
  13538. {
  13539. if (a->plci[k].Id)
  13540. {
  13541. auxplci = &a->plci[k];
  13542. if (auxplci->appl == &application[i]) /* application has a busy PLCI */
  13543. {
  13544. busy = true;
  13545. dbug(1, dprintf("Appl 0x%x is busy", i + 1));
  13546. }
  13547. else if (test_c_ind_mask_bit(auxplci, i)) /* application has an incoming call pending */
  13548. {
  13549. busy = true;
  13550. dbug(1, dprintf("Appl 0x%x has inc. call pending", i + 1));
  13551. }
  13552. }
  13553. }
  13554. for (j = 0, group_found = 0; j <= (MAX_CIP_TYPES) && !busy && !group_found; j++) /* build groups with free applications only */
  13555. {
  13556. if (j == MAX_CIP_TYPES) /* all groups are in use but group still not found */
  13557. { /* the MAX_CIP_TYPES group enables all calls because of field overflow */
  13558. appl_number_group_type[i] = MAX_CIP_TYPES;
  13559. group_found = true;
  13560. dbug(1, dprintf("Field overflow appl 0x%x", i + 1));
  13561. }
  13562. else if ((info_mask_group[j] == a->CIP_Mask[i]) && (cip_mask_group[j] == a->Info_Mask[i]))
  13563. { /* is group already present ? */
  13564. appl_number_group_type[i] = j | 0x80; /* store the group number for each application */
  13565. group_found = true;
  13566. dbug(1, dprintf("Group 0x%x found with appl 0x%x, CIP=0x%lx", appl_number_group_type[i], i + 1, info_mask_group[j]));
  13567. }
  13568. else if (!info_mask_group[j])
  13569. { /* establish a new group */
  13570. appl_number_group_type[i] = j | 0x80; /* store the group number for each application */
  13571. info_mask_group[j] = a->CIP_Mask[i]; /* store the new CIP mask for the new group */
  13572. cip_mask_group[j] = a->Info_Mask[i]; /* store the new Info_Mask for this new group */
  13573. group_found = true;
  13574. dbug(1, dprintf("New Group 0x%x established with appl 0x%x, CIP=0x%lx", appl_number_group_type[i], i + 1, info_mask_group[j]));
  13575. }
  13576. }
  13577. }
  13578. }
  13579. for (i = 0; i < max_appl; i++) /* Build group_optimization_mask_table */
  13580. {
  13581. if (appl_number_group_type[i]) /* application is free, has listens and is member of a group */
  13582. {
  13583. if (appl_number_group_type[i] == MAX_CIP_TYPES)
  13584. {
  13585. dbug(1, dprintf("OverflowGroup 0x%x, valid appl = 0x%x, call enabled", appl_number_group_type[i], i + 1));
  13586. }
  13587. else
  13588. {
  13589. dbug(1, dprintf("Group 0x%x, valid appl = 0x%x", appl_number_group_type[i], i + 1));
  13590. for (j = i + 1; j < max_appl; j++) /* search other group members and mark them as busy */
  13591. {
  13592. if (appl_number_group_type[i] == appl_number_group_type[j])
  13593. {
  13594. dbug(1, dprintf("Appl 0x%x is member of group 0x%x, no call", j + 1, appl_number_group_type[j]));
  13595. clear_group_ind_mask_bit(plci, j); /* disable call on other group members */
  13596. appl_number_group_type[j] = 0; /* remove disabled group member from group list */
  13597. }
  13598. }
  13599. }
  13600. }
  13601. else /* application should not get a call */
  13602. {
  13603. clear_group_ind_mask_bit(plci, i);
  13604. }
  13605. }
  13606. }
  13607. /* OS notifies the driver about a application Capi_Register */
  13608. word CapiRegister(word id)
  13609. {
  13610. word i, j, appls_found;
  13611. PLCI *plci;
  13612. DIVA_CAPI_ADAPTER *a;
  13613. for (i = 0, appls_found = 0; i < max_appl; i++)
  13614. {
  13615. if (application[i].Id && (application[i].Id != id))
  13616. {
  13617. appls_found++; /* an application has been found */
  13618. }
  13619. }
  13620. if (appls_found) return true;
  13621. for (i = 0; i < max_adapter; i++) /* scan all adapters... */
  13622. {
  13623. a = &adapter[i];
  13624. if (a->request)
  13625. {
  13626. if (a->flag_dynamic_l1_down) /* remove adapter from L1 tristate (Huntgroup) */
  13627. {
  13628. if (!appls_found) /* first application does a capi register */
  13629. {
  13630. if ((j = get_plci(a))) /* activate L1 of all adapters */
  13631. {
  13632. plci = &a->plci[j - 1];
  13633. plci->command = 0;
  13634. add_p(plci, OAD, "\x01\xfd");
  13635. add_p(plci, CAI, "\x01\x80");
  13636. add_p(plci, UID, "\x06\x43\x61\x70\x69\x32\x30");
  13637. add_p(plci, SHIFT | 6, NULL);
  13638. add_p(plci, SIN, "\x02\x00\x00");
  13639. plci->internal_command = START_L1_SIG_ASSIGN_PEND;
  13640. sig_req(plci, ASSIGN, DSIG_ID);
  13641. add_p(plci, FTY, "\x02\xff\x07"); /* l1 start */
  13642. sig_req(plci, SIG_CTRL, 0);
  13643. send_req(plci);
  13644. }
  13645. }
  13646. }
  13647. }
  13648. }
  13649. return false;
  13650. }
  13651. /*------------------------------------------------------------------*/
  13652. /* Functions for virtual Switching e.g. Transfer by join, Conference */
  13653. static void VSwitchReqInd(PLCI *plci, dword Id, byte **parms)
  13654. {
  13655. word i;
  13656. /* Format of vswitch_t:
  13657. 0 byte length
  13658. 1 byte VSWITCHIE
  13659. 2 byte VSWITCH_REQ/VSWITCH_IND
  13660. 3 byte reserved
  13661. 4 word VSwitchcommand
  13662. 6 word returnerror
  13663. 8... Params
  13664. */
  13665. if (!plci ||
  13666. !plci->appl ||
  13667. !plci->State ||
  13668. plci->Sig.Ind == NCR_FACILITY
  13669. )
  13670. return;
  13671. for (i = 0; i < MAX_MULTI_IE; i++)
  13672. {
  13673. if (!parms[i][0]) continue;
  13674. if (parms[i][0] < 7)
  13675. {
  13676. parms[i][0] = 0; /* kill it */
  13677. continue;
  13678. }
  13679. dbug(1, dprintf("VSwitchReqInd(%d)", parms[i][4]));
  13680. switch (parms[i][4])
  13681. {
  13682. case VSJOIN:
  13683. if (!plci->relatedPTYPLCI ||
  13684. (plci->ptyState != S_ECT && plci->relatedPTYPLCI->ptyState != S_ECT))
  13685. { /* Error */
  13686. break;
  13687. }
  13688. /* remember all necessary informations */
  13689. if (parms[i][0] != 11 || parms[i][8] != 3) /* Length Test */
  13690. {
  13691. break;
  13692. }
  13693. if (parms[i][2] == VSWITCH_IND && parms[i][9] == 1)
  13694. { /* first indication after ECT-Request on Consultation Call */
  13695. plci->vswitchstate = parms[i][9];
  13696. parms[i][9] = 2; /* State */
  13697. /* now ask first Call to join */
  13698. }
  13699. else if (parms[i][2] == VSWITCH_REQ && parms[i][9] == 3)
  13700. { /* Answer of VSWITCH_REQ from first Call */
  13701. plci->vswitchstate = parms[i][9];
  13702. /* tell consultation call to join
  13703. and the protocol capabilities of the first call */
  13704. }
  13705. else
  13706. { /* Error */
  13707. break;
  13708. }
  13709. plci->vsprot = parms[i][10]; /* protocol */
  13710. plci->vsprotdialect = parms[i][11]; /* protocoldialect */
  13711. /* send join request to related PLCI */
  13712. parms[i][1] = VSWITCHIE;
  13713. parms[i][2] = VSWITCH_REQ;
  13714. plci->relatedPTYPLCI->command = 0;
  13715. plci->relatedPTYPLCI->internal_command = VSWITCH_REQ_PEND;
  13716. add_p(plci->relatedPTYPLCI, ESC, &parms[i][0]);
  13717. sig_req(plci->relatedPTYPLCI, VSWITCH_REQ, 0);
  13718. send_req(plci->relatedPTYPLCI);
  13719. break;
  13720. case VSTRANSPORT:
  13721. default:
  13722. if (plci->relatedPTYPLCI &&
  13723. plci->vswitchstate == 3 &&
  13724. plci->relatedPTYPLCI->vswitchstate == 3)
  13725. {
  13726. add_p(plci->relatedPTYPLCI, ESC, &parms[i][0]);
  13727. sig_req(plci->relatedPTYPLCI, VSWITCH_REQ, 0);
  13728. send_req(plci->relatedPTYPLCI);
  13729. }
  13730. break;
  13731. }
  13732. parms[i][0] = 0; /* kill it */
  13733. }
  13734. }
  13735. /*------------------------------------------------------------------*/
  13736. static int diva_get_dma_descriptor(PLCI *plci, dword *dma_magic) {
  13737. ENTITY e;
  13738. IDI_SYNC_REQ *pReq = (IDI_SYNC_REQ *)&e;
  13739. if (!(diva_xdi_extended_features & DIVA_CAPI_XDI_PROVIDES_RX_DMA)) {
  13740. return (-1);
  13741. }
  13742. pReq->xdi_dma_descriptor_operation.Req = 0;
  13743. pReq->xdi_dma_descriptor_operation.Rc = IDI_SYNC_REQ_DMA_DESCRIPTOR_OPERATION;
  13744. pReq->xdi_dma_descriptor_operation.info.operation = IDI_SYNC_REQ_DMA_DESCRIPTOR_ALLOC;
  13745. pReq->xdi_dma_descriptor_operation.info.descriptor_number = -1;
  13746. pReq->xdi_dma_descriptor_operation.info.descriptor_address = NULL;
  13747. pReq->xdi_dma_descriptor_operation.info.descriptor_magic = 0;
  13748. e.user[0] = plci->adapter->Id - 1;
  13749. plci->adapter->request((ENTITY *)pReq);
  13750. if (!pReq->xdi_dma_descriptor_operation.info.operation &&
  13751. (pReq->xdi_dma_descriptor_operation.info.descriptor_number >= 0) &&
  13752. pReq->xdi_dma_descriptor_operation.info.descriptor_magic) {
  13753. *dma_magic = pReq->xdi_dma_descriptor_operation.info.descriptor_magic;
  13754. dbug(3, dprintf("dma_alloc, a:%d (%d-%08x)",
  13755. plci->adapter->Id,
  13756. pReq->xdi_dma_descriptor_operation.info.descriptor_number,
  13757. *dma_magic));
  13758. return (pReq->xdi_dma_descriptor_operation.info.descriptor_number);
  13759. } else {
  13760. dbug(1, dprintf("dma_alloc failed"));
  13761. return (-1);
  13762. }
  13763. }
  13764. static void diva_free_dma_descriptor(PLCI *plci, int nr) {
  13765. ENTITY e;
  13766. IDI_SYNC_REQ *pReq = (IDI_SYNC_REQ *)&e;
  13767. if (nr < 0) {
  13768. return;
  13769. }
  13770. pReq->xdi_dma_descriptor_operation.Req = 0;
  13771. pReq->xdi_dma_descriptor_operation.Rc = IDI_SYNC_REQ_DMA_DESCRIPTOR_OPERATION;
  13772. pReq->xdi_dma_descriptor_operation.info.operation = IDI_SYNC_REQ_DMA_DESCRIPTOR_FREE;
  13773. pReq->xdi_dma_descriptor_operation.info.descriptor_number = nr;
  13774. pReq->xdi_dma_descriptor_operation.info.descriptor_address = NULL;
  13775. pReq->xdi_dma_descriptor_operation.info.descriptor_magic = 0;
  13776. e.user[0] = plci->adapter->Id - 1;
  13777. plci->adapter->request((ENTITY *)pReq);
  13778. if (!pReq->xdi_dma_descriptor_operation.info.operation) {
  13779. dbug(1, dprintf("dma_free(%d)", nr));
  13780. } else {
  13781. dbug(1, dprintf("dma_free failed (%d)", nr));
  13782. }
  13783. }
  13784. /*------------------------------------------------------------------*/