message.c 435 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686668766886689669066916692669366946695669666976698669967006701670267036704670567066707670867096710671167126713671467156716671767186719672067216722672367246725672667276728672967306731673267336734673567366737673867396740674167426743674467456746674767486749675067516752675367546755675667576758675967606761676267636764676567666767676867696770677167726773677467756776677767786779678067816782678367846785678667876788678967906791679267936794679567966797679867996800680168026803680468056806680768086809681068116812681368146815681668176818681968206821682268236824682568266827682868296830683168326833683468356836683768386839684068416842684368446845684668476848684968506851685268536854685568566857685868596860686168626863686468656866686768686869687068716872687368746875687668776878687968806881688268836884688568866887688868896890689168926893689468956896689768986899690069016902690369046905690669076908690969106911691269136914691569166917691869196920692169226923692469256926692769286929693069316932693369346935693669376938693969406941694269436944694569466947694869496950695169526953695469556956695769586959696069616962696369646965696669676968696969706971697269736974697569766977697869796980698169826983698469856986698769886989699069916992699369946995699669976998699970007001700270037004700570067007700870097010701170127013701470157016701770187019702070217022702370247025702670277028702970307031703270337034703570367037703870397040704170427043704470457046704770487049705070517052705370547055705670577058705970607061706270637064706570667067706870697070707170727073707470757076707770787079708070817082708370847085708670877088708970907091709270937094709570967097709870997100710171027103710471057106710771087109711071117112711371147115711671177118711971207121712271237124712571267127712871297130713171327133713471357136713771387139714071417142714371447145714671477148714971507151715271537154715571567157715871597160716171627163716471657166716771687169717071717172717371747175717671777178717971807181718271837184718571867187718871897190719171927193719471957196719771987199720072017202720372047205720672077208720972107211721272137214721572167217721872197220722172227223722472257226722772287229723072317232723372347235723672377238723972407241724272437244724572467247724872497250725172527253725472557256725772587259726072617262726372647265726672677268726972707271727272737274727572767277727872797280728172827283728472857286728772887289729072917292729372947295729672977298729973007301730273037304730573067307730873097310731173127313731473157316731773187319732073217322732373247325732673277328732973307331733273337334733573367337733873397340734173427343734473457346734773487349735073517352735373547355735673577358735973607361736273637364736573667367736873697370737173727373737473757376737773787379738073817382738373847385738673877388738973907391739273937394739573967397739873997400740174027403740474057406740774087409741074117412741374147415741674177418741974207421742274237424742574267427742874297430743174327433743474357436743774387439744074417442744374447445744674477448744974507451745274537454745574567457745874597460746174627463746474657466746774687469747074717472747374747475747674777478747974807481748274837484748574867487748874897490749174927493749474957496749774987499750075017502750375047505750675077508750975107511751275137514751575167517751875197520752175227523752475257526752775287529753075317532753375347535753675377538753975407541754275437544754575467547754875497550755175527553755475557556755775587559756075617562756375647565756675677568756975707571757275737574757575767577757875797580758175827583758475857586758775887589759075917592759375947595759675977598759976007601760276037604760576067607760876097610761176127613761476157616761776187619762076217622762376247625762676277628762976307631763276337634763576367637763876397640764176427643764476457646764776487649765076517652765376547655765676577658765976607661766276637664766576667667766876697670767176727673767476757676767776787679768076817682768376847685768676877688768976907691769276937694769576967697769876997700770177027703770477057706770777087709771077117712771377147715771677177718771977207721772277237724772577267727772877297730773177327733773477357736773777387739774077417742774377447745774677477748774977507751775277537754775577567757775877597760776177627763776477657766776777687769777077717772777377747775777677777778777977807781778277837784778577867787778877897790779177927793779477957796779777987799780078017802780378047805780678077808780978107811781278137814781578167817781878197820782178227823782478257826782778287829783078317832783378347835783678377838783978407841784278437844784578467847784878497850785178527853785478557856785778587859786078617862786378647865786678677868786978707871787278737874787578767877787878797880788178827883788478857886788778887889789078917892789378947895789678977898789979007901790279037904790579067907790879097910791179127913791479157916791779187919792079217922792379247925792679277928792979307931793279337934793579367937793879397940794179427943794479457946794779487949795079517952795379547955795679577958795979607961796279637964796579667967796879697970797179727973797479757976797779787979798079817982798379847985798679877988798979907991799279937994799579967997799879998000800180028003800480058006800780088009801080118012801380148015801680178018801980208021802280238024802580268027802880298030803180328033803480358036803780388039804080418042804380448045804680478048804980508051805280538054805580568057805880598060806180628063806480658066806780688069807080718072807380748075807680778078807980808081808280838084808580868087808880898090809180928093809480958096809780988099810081018102810381048105810681078108810981108111811281138114811581168117811881198120812181228123812481258126812781288129813081318132813381348135813681378138813981408141814281438144814581468147814881498150815181528153815481558156815781588159816081618162816381648165816681678168816981708171817281738174817581768177817881798180818181828183818481858186818781888189819081918192819381948195819681978198819982008201820282038204820582068207820882098210821182128213821482158216821782188219822082218222822382248225822682278228822982308231823282338234823582368237823882398240824182428243824482458246824782488249825082518252825382548255825682578258825982608261826282638264826582668267826882698270827182728273827482758276827782788279828082818282828382848285828682878288828982908291829282938294829582968297829882998300830183028303830483058306830783088309831083118312831383148315831683178318831983208321832283238324832583268327832883298330833183328333833483358336833783388339834083418342834383448345834683478348834983508351835283538354835583568357835883598360836183628363836483658366836783688369837083718372837383748375837683778378837983808381838283838384838583868387838883898390839183928393839483958396839783988399840084018402840384048405840684078408840984108411841284138414841584168417841884198420842184228423842484258426842784288429843084318432843384348435843684378438843984408441844284438444844584468447844884498450845184528453845484558456845784588459846084618462846384648465846684678468846984708471847284738474847584768477847884798480848184828483848484858486848784888489849084918492849384948495849684978498849985008501850285038504850585068507850885098510851185128513851485158516851785188519852085218522852385248525852685278528852985308531853285338534853585368537853885398540854185428543854485458546854785488549855085518552855385548555855685578558855985608561856285638564856585668567856885698570857185728573857485758576857785788579858085818582858385848585858685878588858985908591859285938594859585968597859885998600860186028603860486058606860786088609861086118612861386148615861686178618861986208621862286238624862586268627862886298630863186328633863486358636863786388639864086418642864386448645864686478648864986508651865286538654865586568657865886598660866186628663866486658666866786688669867086718672867386748675867686778678867986808681868286838684868586868687868886898690869186928693869486958696869786988699870087018702870387048705870687078708870987108711871287138714871587168717871887198720872187228723872487258726872787288729873087318732873387348735873687378738873987408741874287438744874587468747874887498750875187528753875487558756875787588759876087618762876387648765876687678768876987708771877287738774877587768777877887798780878187828783878487858786878787888789879087918792879387948795879687978798879988008801880288038804880588068807880888098810881188128813881488158816881788188819882088218822882388248825882688278828882988308831883288338834883588368837883888398840884188428843884488458846884788488849885088518852885388548855885688578858885988608861886288638864886588668867886888698870887188728873887488758876887788788879888088818882888388848885888688878888888988908891889288938894889588968897889888998900890189028903890489058906890789088909891089118912891389148915891689178918891989208921892289238924892589268927892889298930893189328933893489358936893789388939894089418942894389448945894689478948894989508951895289538954895589568957895889598960896189628963896489658966896789688969897089718972897389748975897689778978897989808981898289838984898589868987898889898990899189928993899489958996899789988999900090019002900390049005900690079008900990109011901290139014901590169017901890199020902190229023902490259026902790289029903090319032903390349035903690379038903990409041904290439044904590469047904890499050905190529053905490559056905790589059906090619062906390649065906690679068906990709071907290739074907590769077907890799080908190829083908490859086908790889089909090919092909390949095909690979098909991009101910291039104910591069107910891099110911191129113911491159116911791189119912091219122912391249125912691279128912991309131913291339134913591369137913891399140914191429143914491459146914791489149915091519152915391549155915691579158915991609161916291639164916591669167916891699170917191729173917491759176917791789179918091819182918391849185918691879188918991909191919291939194919591969197919891999200920192029203920492059206920792089209921092119212921392149215921692179218921992209221922292239224922592269227922892299230923192329233923492359236923792389239924092419242924392449245924692479248924992509251925292539254925592569257925892599260926192629263926492659266926792689269927092719272927392749275927692779278927992809281928292839284928592869287928892899290929192929293929492959296929792989299930093019302930393049305930693079308930993109311931293139314931593169317931893199320932193229323932493259326932793289329933093319332933393349335933693379338933993409341934293439344934593469347934893499350935193529353935493559356935793589359936093619362936393649365936693679368936993709371937293739374937593769377937893799380938193829383938493859386938793889389939093919392939393949395939693979398939994009401940294039404940594069407940894099410941194129413941494159416941794189419942094219422942394249425942694279428942994309431943294339434943594369437943894399440944194429443944494459446944794489449945094519452945394549455945694579458945994609461946294639464946594669467946894699470947194729473947494759476947794789479948094819482948394849485948694879488948994909491949294939494949594969497949894999500950195029503950495059506950795089509951095119512951395149515951695179518951995209521952295239524952595269527952895299530953195329533953495359536953795389539954095419542954395449545954695479548954995509551955295539554955595569557955895599560956195629563956495659566956795689569957095719572957395749575957695779578957995809581958295839584958595869587958895899590959195929593959495959596959795989599960096019602960396049605960696079608960996109611961296139614961596169617961896199620962196229623962496259626962796289629963096319632963396349635963696379638963996409641964296439644964596469647964896499650965196529653965496559656965796589659966096619662966396649665966696679668966996709671967296739674967596769677967896799680968196829683968496859686968796889689969096919692969396949695969696979698969997009701970297039704970597069707970897099710971197129713971497159716971797189719972097219722972397249725972697279728972997309731973297339734973597369737973897399740974197429743974497459746974797489749975097519752975397549755975697579758975997609761976297639764976597669767976897699770977197729773977497759776977797789779978097819782978397849785978697879788978997909791979297939794979597969797979897999800980198029803980498059806980798089809981098119812981398149815981698179818981998209821982298239824982598269827982898299830983198329833983498359836983798389839984098419842984398449845984698479848984998509851985298539854985598569857985898599860986198629863986498659866986798689869987098719872987398749875987698779878987998809881988298839884988598869887988898899890989198929893989498959896989798989899990099019902990399049905990699079908990999109911991299139914991599169917991899199920992199229923992499259926992799289929993099319932993399349935993699379938993999409941994299439944994599469947994899499950995199529953995499559956995799589959996099619962996399649965996699679968996999709971997299739974997599769977997899799980998199829983998499859986998799889989999099919992999399949995999699979998999910000100011000210003100041000510006100071000810009100101001110012100131001410015100161001710018100191002010021100221002310024100251002610027100281002910030100311003210033100341003510036100371003810039100401004110042100431004410045100461004710048100491005010051100521005310054100551005610057100581005910060100611006210063100641006510066100671006810069100701007110072100731007410075100761007710078100791008010081100821008310084100851008610087100881008910090100911009210093100941009510096100971009810099101001010110102101031010410105101061010710108101091011010111101121011310114101151011610117101181011910120101211012210123101241012510126101271012810129101301013110132101331013410135101361013710138101391014010141101421014310144101451014610147101481014910150101511015210153101541015510156101571015810159101601016110162101631016410165101661016710168101691017010171101721017310174101751017610177101781017910180101811018210183101841018510186101871018810189101901019110192101931019410195101961019710198101991020010201102021020310204102051020610207102081020910210102111021210213102141021510216102171021810219102201022110222102231022410225102261022710228102291023010231102321023310234102351023610237102381023910240102411024210243102441024510246102471024810249102501025110252102531025410255102561025710258102591026010261102621026310264102651026610267102681026910270102711027210273102741027510276102771027810279102801028110282102831028410285102861028710288102891029010291102921029310294102951029610297102981029910300103011030210303103041030510306103071030810309103101031110312103131031410315103161031710318103191032010321103221032310324103251032610327103281032910330103311033210333103341033510336103371033810339103401034110342103431034410345103461034710348103491035010351103521035310354103551035610357103581035910360103611036210363103641036510366103671036810369103701037110372103731037410375103761037710378103791038010381103821038310384103851038610387103881038910390103911039210393103941039510396103971039810399104001040110402104031040410405104061040710408104091041010411104121041310414104151041610417104181041910420104211042210423104241042510426104271042810429104301043110432104331043410435104361043710438104391044010441104421044310444104451044610447104481044910450104511045210453104541045510456104571045810459104601046110462104631046410465104661046710468104691047010471104721047310474104751047610477104781047910480104811048210483104841048510486104871048810489104901049110492104931049410495104961049710498104991050010501105021050310504105051050610507105081050910510105111051210513105141051510516105171051810519105201052110522105231052410525105261052710528105291053010531105321053310534105351053610537105381053910540105411054210543105441054510546105471054810549105501055110552105531055410555105561055710558105591056010561105621056310564105651056610567105681056910570105711057210573105741057510576105771057810579105801058110582105831058410585105861058710588105891059010591105921059310594105951059610597105981059910600106011060210603106041060510606106071060810609106101061110612106131061410615106161061710618106191062010621106221062310624106251062610627106281062910630106311063210633106341063510636106371063810639106401064110642106431064410645106461064710648106491065010651106521065310654106551065610657106581065910660106611066210663106641066510666106671066810669106701067110672106731067410675106761067710678106791068010681106821068310684106851068610687106881068910690106911069210693106941069510696106971069810699107001070110702107031070410705107061070710708107091071010711107121071310714107151071610717107181071910720107211072210723107241072510726107271072810729107301073110732107331073410735107361073710738107391074010741107421074310744107451074610747107481074910750107511075210753107541075510756107571075810759107601076110762107631076410765107661076710768107691077010771107721077310774107751077610777107781077910780107811078210783107841078510786107871078810789107901079110792107931079410795107961079710798107991080010801108021080310804108051080610807108081080910810108111081210813108141081510816108171081810819108201082110822108231082410825108261082710828108291083010831108321083310834108351083610837108381083910840108411084210843108441084510846108471084810849108501085110852108531085410855108561085710858108591086010861108621086310864108651086610867108681086910870108711087210873108741087510876108771087810879108801088110882108831088410885108861088710888108891089010891108921089310894108951089610897108981089910900109011090210903109041090510906109071090810909109101091110912109131091410915109161091710918109191092010921109221092310924109251092610927109281092910930109311093210933109341093510936109371093810939109401094110942109431094410945109461094710948109491095010951109521095310954109551095610957109581095910960109611096210963109641096510966109671096810969109701097110972109731097410975109761097710978109791098010981109821098310984109851098610987109881098910990109911099210993109941099510996109971099810999110001100111002110031100411005110061100711008110091101011011110121101311014110151101611017110181101911020110211102211023110241102511026110271102811029110301103111032110331103411035110361103711038110391104011041110421104311044110451104611047110481104911050110511105211053110541105511056110571105811059110601106111062110631106411065110661106711068110691107011071110721107311074110751107611077110781107911080110811108211083110841108511086110871108811089110901109111092110931109411095110961109711098110991110011101111021110311104111051110611107111081110911110111111111211113111141111511116111171111811119111201112111122111231112411125111261112711128111291113011131111321113311134111351113611137111381113911140111411114211143111441114511146111471114811149111501115111152111531115411155111561115711158111591116011161111621116311164111651116611167111681116911170111711117211173111741117511176111771117811179111801118111182111831118411185111861118711188111891119011191111921119311194111951119611197111981119911200112011120211203112041120511206112071120811209112101121111212112131121411215112161121711218112191122011221112221122311224112251122611227112281122911230112311123211233112341123511236112371123811239112401124111242112431124411245112461124711248112491125011251112521125311254112551125611257112581125911260112611126211263112641126511266112671126811269112701127111272112731127411275112761127711278112791128011281112821128311284112851128611287112881128911290112911129211293112941129511296112971129811299113001130111302113031130411305113061130711308113091131011311113121131311314113151131611317113181131911320113211132211323113241132511326113271132811329113301133111332113331133411335113361133711338113391134011341113421134311344113451134611347113481134911350113511135211353113541135511356113571135811359113601136111362113631136411365113661136711368113691137011371113721137311374113751137611377113781137911380113811138211383113841138511386113871138811389113901139111392113931139411395113961139711398113991140011401114021140311404114051140611407114081140911410114111141211413114141141511416114171141811419114201142111422114231142411425114261142711428114291143011431114321143311434114351143611437114381143911440114411144211443114441144511446114471144811449114501145111452114531145411455114561145711458114591146011461114621146311464114651146611467114681146911470114711147211473114741147511476114771147811479114801148111482114831148411485114861148711488114891149011491114921149311494114951149611497114981149911500115011150211503115041150511506115071150811509115101151111512115131151411515115161151711518115191152011521115221152311524115251152611527115281152911530115311153211533115341153511536115371153811539115401154111542115431154411545115461154711548115491155011551115521155311554115551155611557115581155911560115611156211563115641156511566115671156811569115701157111572115731157411575115761157711578115791158011581115821158311584115851158611587115881158911590115911159211593115941159511596115971159811599116001160111602116031160411605116061160711608116091161011611116121161311614116151161611617116181161911620116211162211623116241162511626116271162811629116301163111632116331163411635116361163711638116391164011641116421164311644116451164611647116481164911650116511165211653116541165511656116571165811659116601166111662116631166411665116661166711668116691167011671116721167311674116751167611677116781167911680116811168211683116841168511686116871168811689116901169111692116931169411695116961169711698116991170011701117021170311704117051170611707117081170911710117111171211713117141171511716117171171811719117201172111722117231172411725117261172711728117291173011731117321173311734117351173611737117381173911740117411174211743117441174511746117471174811749117501175111752117531175411755117561175711758117591176011761117621176311764117651176611767117681176911770117711177211773117741177511776117771177811779117801178111782117831178411785117861178711788117891179011791117921179311794117951179611797117981179911800118011180211803118041180511806118071180811809118101181111812118131181411815118161181711818118191182011821118221182311824118251182611827118281182911830118311183211833118341183511836118371183811839118401184111842118431184411845118461184711848118491185011851118521185311854118551185611857118581185911860118611186211863118641186511866118671186811869118701187111872118731187411875118761187711878118791188011881118821188311884118851188611887118881188911890118911189211893118941189511896118971189811899119001190111902119031190411905119061190711908119091191011911119121191311914119151191611917119181191911920119211192211923119241192511926119271192811929119301193111932119331193411935119361193711938119391194011941119421194311944119451194611947119481194911950119511195211953119541195511956119571195811959119601196111962119631196411965119661196711968119691197011971119721197311974119751197611977119781197911980119811198211983119841198511986119871198811989119901199111992119931199411995119961199711998119991200012001120021200312004120051200612007120081200912010120111201212013120141201512016120171201812019120201202112022120231202412025120261202712028120291203012031120321203312034120351203612037120381203912040120411204212043120441204512046120471204812049120501205112052120531205412055120561205712058120591206012061120621206312064120651206612067120681206912070120711207212073120741207512076120771207812079120801208112082120831208412085120861208712088120891209012091120921209312094120951209612097120981209912100121011210212103121041210512106121071210812109121101211112112121131211412115121161211712118121191212012121121221212312124121251212612127121281212912130121311213212133121341213512136121371213812139121401214112142121431214412145121461214712148121491215012151121521215312154121551215612157121581215912160121611216212163121641216512166121671216812169121701217112172121731217412175121761217712178121791218012181121821218312184121851218612187121881218912190121911219212193121941219512196121971219812199122001220112202122031220412205122061220712208122091221012211122121221312214122151221612217122181221912220122211222212223122241222512226122271222812229122301223112232122331223412235122361223712238122391224012241122421224312244122451224612247122481224912250122511225212253122541225512256122571225812259122601226112262122631226412265122661226712268122691227012271122721227312274122751227612277122781227912280122811228212283122841228512286122871228812289122901229112292122931229412295122961229712298122991230012301123021230312304123051230612307123081230912310123111231212313123141231512316123171231812319123201232112322123231232412325123261232712328123291233012331123321233312334123351233612337123381233912340123411234212343123441234512346123471234812349123501235112352123531235412355123561235712358123591236012361123621236312364123651236612367123681236912370123711237212373123741237512376123771237812379123801238112382123831238412385123861238712388123891239012391123921239312394123951239612397123981239912400124011240212403124041240512406124071240812409124101241112412124131241412415124161241712418124191242012421124221242312424124251242612427124281242912430124311243212433124341243512436124371243812439124401244112442124431244412445124461244712448124491245012451124521245312454124551245612457124581245912460124611246212463124641246512466124671246812469124701247112472124731247412475124761247712478124791248012481124821248312484124851248612487124881248912490124911249212493124941249512496124971249812499125001250112502125031250412505125061250712508125091251012511125121251312514125151251612517125181251912520125211252212523125241252512526125271252812529125301253112532125331253412535125361253712538125391254012541125421254312544125451254612547125481254912550125511255212553125541255512556125571255812559125601256112562125631256412565125661256712568125691257012571125721257312574125751257612577125781257912580125811258212583125841258512586125871258812589125901259112592125931259412595125961259712598125991260012601126021260312604126051260612607126081260912610126111261212613126141261512616126171261812619126201262112622126231262412625126261262712628126291263012631126321263312634126351263612637126381263912640126411264212643126441264512646126471264812649126501265112652126531265412655126561265712658126591266012661126621266312664126651266612667126681266912670126711267212673126741267512676126771267812679126801268112682126831268412685126861268712688126891269012691126921269312694126951269612697126981269912700127011270212703127041270512706127071270812709127101271112712127131271412715127161271712718127191272012721127221272312724127251272612727127281272912730127311273212733127341273512736127371273812739127401274112742127431274412745127461274712748127491275012751127521275312754127551275612757127581275912760127611276212763127641276512766127671276812769127701277112772127731277412775127761277712778127791278012781127821278312784127851278612787127881278912790127911279212793127941279512796127971279812799128001280112802128031280412805128061280712808128091281012811128121281312814128151281612817128181281912820128211282212823128241282512826128271282812829128301283112832128331283412835128361283712838128391284012841128421284312844128451284612847128481284912850128511285212853128541285512856128571285812859128601286112862128631286412865128661286712868128691287012871128721287312874128751287612877128781287912880128811288212883128841288512886128871288812889128901289112892128931289412895128961289712898128991290012901129021290312904129051290612907129081290912910129111291212913129141291512916129171291812919129201292112922129231292412925129261292712928129291293012931129321293312934129351293612937129381293912940129411294212943129441294512946129471294812949129501295112952129531295412955129561295712958129591296012961129621296312964129651296612967129681296912970129711297212973129741297512976129771297812979129801298112982129831298412985129861298712988129891299012991129921299312994129951299612997129981299913000130011300213003130041300513006130071300813009130101301113012130131301413015130161301713018130191302013021130221302313024130251302613027130281302913030130311303213033130341303513036130371303813039130401304113042130431304413045130461304713048130491305013051130521305313054130551305613057130581305913060130611306213063130641306513066130671306813069130701307113072130731307413075130761307713078130791308013081130821308313084130851308613087130881308913090130911309213093130941309513096130971309813099131001310113102131031310413105131061310713108131091311013111131121311313114131151311613117131181311913120131211312213123131241312513126131271312813129131301313113132131331313413135131361313713138131391314013141131421314313144131451314613147131481314913150131511315213153131541315513156131571315813159131601316113162131631316413165131661316713168131691317013171131721317313174131751317613177131781317913180131811318213183131841318513186131871318813189131901319113192131931319413195131961319713198131991320013201132021320313204132051320613207132081320913210132111321213213132141321513216132171321813219132201322113222132231322413225132261322713228132291323013231132321323313234132351323613237132381323913240132411324213243132441324513246132471324813249132501325113252132531325413255132561325713258132591326013261132621326313264132651326613267132681326913270132711327213273132741327513276132771327813279132801328113282132831328413285132861328713288132891329013291132921329313294132951329613297132981329913300133011330213303133041330513306133071330813309133101331113312133131331413315133161331713318133191332013321133221332313324133251332613327133281332913330133311333213333133341333513336133371333813339133401334113342133431334413345133461334713348133491335013351133521335313354133551335613357133581335913360133611336213363133641336513366133671336813369133701337113372133731337413375133761337713378133791338013381133821338313384133851338613387133881338913390133911339213393133941339513396133971339813399134001340113402134031340413405134061340713408134091341013411134121341313414134151341613417134181341913420134211342213423134241342513426134271342813429134301343113432134331343413435134361343713438134391344013441134421344313444134451344613447134481344913450134511345213453134541345513456134571345813459134601346113462134631346413465134661346713468134691347013471134721347313474134751347613477134781347913480134811348213483134841348513486134871348813489134901349113492134931349413495134961349713498134991350013501135021350313504135051350613507135081350913510135111351213513135141351513516135171351813519135201352113522135231352413525135261352713528135291353013531135321353313534135351353613537135381353913540135411354213543135441354513546135471354813549135501355113552135531355413555135561355713558135591356013561135621356313564135651356613567135681356913570135711357213573135741357513576135771357813579135801358113582135831358413585135861358713588135891359013591135921359313594135951359613597135981359913600136011360213603136041360513606136071360813609136101361113612136131361413615136161361713618136191362013621136221362313624136251362613627136281362913630136311363213633136341363513636136371363813639136401364113642136431364413645136461364713648136491365013651136521365313654136551365613657136581365913660136611366213663136641366513666136671366813669136701367113672136731367413675136761367713678136791368013681136821368313684136851368613687136881368913690136911369213693136941369513696136971369813699137001370113702137031370413705137061370713708137091371013711137121371313714137151371613717137181371913720137211372213723137241372513726137271372813729137301373113732137331373413735137361373713738137391374013741137421374313744137451374613747137481374913750137511375213753137541375513756137571375813759137601376113762137631376413765137661376713768137691377013771137721377313774137751377613777137781377913780137811378213783137841378513786137871378813789137901379113792137931379413795137961379713798137991380013801138021380313804138051380613807138081380913810138111381213813138141381513816138171381813819138201382113822138231382413825138261382713828138291383013831138321383313834138351383613837138381383913840138411384213843138441384513846138471384813849138501385113852138531385413855138561385713858138591386013861138621386313864138651386613867138681386913870138711387213873138741387513876138771387813879138801388113882138831388413885138861388713888138891389013891138921389313894138951389613897138981389913900139011390213903139041390513906139071390813909139101391113912139131391413915139161391713918139191392013921139221392313924139251392613927139281392913930139311393213933139341393513936139371393813939139401394113942139431394413945139461394713948139491395013951139521395313954139551395613957139581395913960139611396213963139641396513966139671396813969139701397113972139731397413975139761397713978139791398013981139821398313984139851398613987139881398913990139911399213993139941399513996139971399813999140001400114002140031400414005140061400714008140091401014011140121401314014140151401614017140181401914020140211402214023140241402514026140271402814029140301403114032140331403414035140361403714038140391404014041140421404314044140451404614047140481404914050140511405214053140541405514056140571405814059140601406114062140631406414065140661406714068140691407014071140721407314074140751407614077140781407914080140811408214083140841408514086140871408814089140901409114092140931409414095140961409714098140991410014101141021410314104141051410614107141081410914110141111411214113141141411514116141171411814119141201412114122141231412414125141261412714128141291413014131141321413314134141351413614137141381413914140141411414214143141441414514146141471414814149141501415114152141531415414155141561415714158141591416014161141621416314164141651416614167141681416914170141711417214173141741417514176141771417814179141801418114182141831418414185141861418714188141891419014191141921419314194141951419614197141981419914200142011420214203142041420514206142071420814209142101421114212142131421414215142161421714218142191422014221142221422314224142251422614227142281422914230142311423214233142341423514236142371423814239142401424114242142431424414245142461424714248142491425014251142521425314254142551425614257142581425914260142611426214263142641426514266142671426814269142701427114272142731427414275142761427714278142791428014281142821428314284142851428614287142881428914290142911429214293142941429514296142971429814299143001430114302143031430414305143061430714308143091431014311143121431314314143151431614317143181431914320143211432214323143241432514326143271432814329143301433114332143331433414335143361433714338143391434014341143421434314344143451434614347143481434914350143511435214353143541435514356143571435814359143601436114362143631436414365143661436714368143691437014371143721437314374143751437614377143781437914380143811438214383143841438514386143871438814389143901439114392143931439414395143961439714398143991440014401144021440314404144051440614407144081440914410144111441214413144141441514416144171441814419144201442114422144231442414425144261442714428144291443014431144321443314434144351443614437144381443914440144411444214443144441444514446144471444814449144501445114452144531445414455144561445714458144591446014461144621446314464144651446614467144681446914470144711447214473144741447514476144771447814479144801448114482144831448414485144861448714488144891449014491144921449314494144951449614497144981449914500145011450214503145041450514506145071450814509145101451114512145131451414515145161451714518145191452014521145221452314524145251452614527145281452914530145311453214533145341453514536145371453814539145401454114542145431454414545145461454714548145491455014551145521455314554145551455614557145581455914560145611456214563145641456514566145671456814569145701457114572145731457414575145761457714578145791458014581145821458314584145851458614587145881458914590145911459214593145941459514596145971459814599146001460114602146031460414605146061460714608146091461014611146121461314614146151461614617146181461914620146211462214623146241462514626146271462814629146301463114632146331463414635146361463714638146391464014641146421464314644146451464614647146481464914650146511465214653146541465514656146571465814659146601466114662146631466414665146661466714668146691467014671146721467314674146751467614677146781467914680146811468214683146841468514686146871468814689146901469114692146931469414695146961469714698146991470014701147021470314704147051470614707147081470914710147111471214713147141471514716147171471814719147201472114722147231472414725147261472714728147291473014731147321473314734147351473614737147381473914740147411474214743147441474514746147471474814749147501475114752147531475414755147561475714758147591476014761147621476314764147651476614767147681476914770147711477214773147741477514776147771477814779147801478114782147831478414785147861478714788147891479014791147921479314794147951479614797147981479914800148011480214803148041480514806148071480814809148101481114812148131481414815148161481714818148191482014821148221482314824148251482614827148281482914830148311483214833148341483514836148371483814839148401484114842148431484414845148461484714848148491485014851148521485314854148551485614857148581485914860148611486214863148641486514866148671486814869148701487114872148731487414875148761487714878148791488014881148821488314884148851488614887148881488914890148911489214893148941489514896148971489814899149001490114902149031490414905149061490714908149091491014911149121491314914149151491614917149181491914920149211492214923149241492514926149271492814929149301493114932149331493414935149361493714938149391494014941149421494314944149451494614947149481494914950149511495214953149541495514956149571495814959149601496114962149631496414965149661496714968149691497014971149721497314974149751497614977149781497914980149811498214983149841498514986149871498814989149901499114992149931499414995149961499714998149991500015001150021500315004150051500615007150081500915010150111501215013150141501515016150171501815019150201502115022150231502415025150261502715028150291503015031150321503315034150351503615037150381503915040150411504215043150441504515046
  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 *, const 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. word i, j, k;
  991. dword d;
  992. char *p;
  993. char buf[40];
  994. for (i = 0; i < C_IND_MASK_DWORDS; i += 4)
  995. {
  996. p = buf + 36;
  997. *p = '\0';
  998. for (j = 0; j < 4; j++)
  999. {
  1000. if (i + j < C_IND_MASK_DWORDS)
  1001. {
  1002. d = plci->c_ind_mask_table[i + j];
  1003. for (k = 0; k < 8; k++)
  1004. {
  1005. *(--p) = hex_asc_lo(d);
  1006. d >>= 4;
  1007. }
  1008. }
  1009. else if (i != 0)
  1010. {
  1011. for (k = 0; k < 8; k++)
  1012. *(--p) = ' ';
  1013. }
  1014. *(--p) = ' ';
  1015. }
  1016. dbug(1, dprintf("c_ind_mask =%s", (char *) p));
  1017. }
  1018. }
  1019. #define dump_plcis(a)
  1020. /*------------------------------------------------------------------*/
  1021. /* translation function for each message */
  1022. /*------------------------------------------------------------------*/
  1023. static byte connect_req(dword Id, word Number, DIVA_CAPI_ADAPTER *a,
  1024. PLCI *plci, APPL *appl, API_PARSE *parms)
  1025. {
  1026. word ch;
  1027. word i;
  1028. word Info;
  1029. byte LinkLayer;
  1030. API_PARSE *ai;
  1031. API_PARSE *bp;
  1032. API_PARSE ai_parms[5];
  1033. word channel = 0;
  1034. dword ch_mask;
  1035. byte m;
  1036. static byte esc_chi[35] = {0x02, 0x18, 0x01};
  1037. static byte lli[2] = {0x01, 0x00};
  1038. byte noCh = 0;
  1039. word dir = 0;
  1040. byte *p_chi = "";
  1041. for (i = 0; i < 5; i++) ai_parms[i].length = 0;
  1042. dbug(1, dprintf("connect_req(%d)", parms->length));
  1043. Info = _WRONG_IDENTIFIER;
  1044. if (a)
  1045. {
  1046. if (a->adapter_disabled)
  1047. {
  1048. dbug(1, dprintf("adapter disabled"));
  1049. Id = ((word)1 << 8) | a->Id;
  1050. sendf(appl, _CONNECT_R | CONFIRM, Id, Number, "w", 0);
  1051. sendf(appl, _DISCONNECT_I, Id, 0, "w", _L1_ERROR);
  1052. return false;
  1053. }
  1054. Info = _OUT_OF_PLCI;
  1055. if ((i = get_plci(a)))
  1056. {
  1057. Info = 0;
  1058. plci = &a->plci[i - 1];
  1059. plci->appl = appl;
  1060. plci->call_dir = CALL_DIR_OUT | CALL_DIR_ORIGINATE;
  1061. /* check 'external controller' bit for codec support */
  1062. if (Id & EXT_CONTROLLER)
  1063. {
  1064. if (AdvCodecSupport(a, plci, appl, 0))
  1065. {
  1066. plci->Id = 0;
  1067. sendf(appl, _CONNECT_R | CONFIRM, Id, Number, "w", _WRONG_IDENTIFIER);
  1068. return 2;
  1069. }
  1070. }
  1071. ai = &parms[9];
  1072. bp = &parms[5];
  1073. ch = 0;
  1074. if (bp->length)LinkLayer = bp->info[3];
  1075. else LinkLayer = 0;
  1076. if (ai->length)
  1077. {
  1078. ch = 0xffff;
  1079. if (!api_parse(&ai->info[1], (word)ai->length, "ssss", ai_parms))
  1080. {
  1081. ch = 0;
  1082. if (ai_parms[0].length)
  1083. {
  1084. ch = GET_WORD(ai_parms[0].info + 1);
  1085. if (ch > 4) ch = 0; /* safety -> ignore ChannelID */
  1086. if (ch == 4) /* explizit CHI in message */
  1087. {
  1088. /* check length of B-CH struct */
  1089. if ((ai_parms[0].info)[3] >= 1)
  1090. {
  1091. if ((ai_parms[0].info)[4] == CHI)
  1092. {
  1093. p_chi = &((ai_parms[0].info)[5]);
  1094. }
  1095. else
  1096. {
  1097. p_chi = &((ai_parms[0].info)[3]);
  1098. }
  1099. if (p_chi[0] > 35) /* check length of channel ID */
  1100. {
  1101. Info = _WRONG_MESSAGE_FORMAT;
  1102. }
  1103. }
  1104. else Info = _WRONG_MESSAGE_FORMAT;
  1105. }
  1106. if (ch == 3 && ai_parms[0].length >= 7 && ai_parms[0].length <= 36)
  1107. {
  1108. dir = GET_WORD(ai_parms[0].info + 3);
  1109. ch_mask = 0;
  1110. m = 0x3f;
  1111. for (i = 0; i + 5 <= ai_parms[0].length; i++)
  1112. {
  1113. if (ai_parms[0].info[i + 5] != 0)
  1114. {
  1115. if ((ai_parms[0].info[i + 5] | m) != 0xff)
  1116. Info = _WRONG_MESSAGE_FORMAT;
  1117. else
  1118. {
  1119. if (ch_mask == 0)
  1120. channel = i;
  1121. ch_mask |= 1L << i;
  1122. }
  1123. }
  1124. m = 0;
  1125. }
  1126. if (ch_mask == 0)
  1127. Info = _WRONG_MESSAGE_FORMAT;
  1128. if (!Info)
  1129. {
  1130. if ((ai_parms[0].length == 36) || (ch_mask != ((dword)(1L << channel))))
  1131. {
  1132. esc_chi[0] = (byte)(ai_parms[0].length - 2);
  1133. for (i = 0; i + 5 <= ai_parms[0].length; i++)
  1134. esc_chi[i + 3] = ai_parms[0].info[i + 5];
  1135. }
  1136. else
  1137. esc_chi[0] = 2;
  1138. esc_chi[2] = (byte)channel;
  1139. plci->b_channel = (byte)channel; /* not correct for ETSI ch 17..31 */
  1140. add_p(plci, LLI, lli);
  1141. add_p(plci, ESC, esc_chi);
  1142. plci->State = LOCAL_CONNECT;
  1143. if (!dir) plci->call_dir |= CALL_DIR_FORCE_OUTG_NL; /* dir 0=DTE, 1=DCE */
  1144. }
  1145. }
  1146. }
  1147. }
  1148. else Info = _WRONG_MESSAGE_FORMAT;
  1149. }
  1150. dbug(1, dprintf("ch=%x,dir=%x,p_ch=%d", ch, dir, channel));
  1151. plci->command = _CONNECT_R;
  1152. plci->number = Number;
  1153. /* x.31 or D-ch free SAPI in LinkLayer? */
  1154. if (ch == 1 && LinkLayer != 3 && LinkLayer != 12) noCh = true;
  1155. if ((ch == 0 || ch == 2 || noCh || ch == 3 || ch == 4) && !Info)
  1156. {
  1157. /* B-channel used for B3 connections (ch==0), or no B channel */
  1158. /* is used (ch==2) or perm. connection (3) is used do a CALL */
  1159. if (noCh) Info = add_b1(plci, &parms[5], 2, 0); /* no resource */
  1160. else Info = add_b1(plci, &parms[5], ch, 0);
  1161. add_s(plci, OAD, &parms[2]);
  1162. add_s(plci, OSA, &parms[4]);
  1163. add_s(plci, BC, &parms[6]);
  1164. add_s(plci, LLC, &parms[7]);
  1165. add_s(plci, HLC, &parms[8]);
  1166. if (a->Info_Mask[appl->Id - 1] & 0x200)
  1167. {
  1168. /* early B3 connect (CIP mask bit 9) no release after a disc */
  1169. add_p(plci, LLI, "\x01\x01");
  1170. }
  1171. if (GET_WORD(parms[0].info) < 29) {
  1172. add_p(plci, BC, cip_bc[GET_WORD(parms[0].info)][a->u_law]);
  1173. add_p(plci, HLC, cip_hlc[GET_WORD(parms[0].info)]);
  1174. }
  1175. add_p(plci, UID, "\x06\x43\x61\x70\x69\x32\x30");
  1176. sig_req(plci, ASSIGN, DSIG_ID);
  1177. }
  1178. else if (ch == 1) {
  1179. /* D-Channel used for B3 connections */
  1180. plci->Sig.Id = 0xff;
  1181. Info = 0;
  1182. }
  1183. if (!Info && ch != 2 && !noCh) {
  1184. Info = add_b23(plci, &parms[5]);
  1185. if (!Info) {
  1186. if (!(plci->tel && !plci->adv_nl))nl_req_ncci(plci, ASSIGN, 0);
  1187. }
  1188. }
  1189. if (!Info)
  1190. {
  1191. if (ch == 0 || ch == 2 || ch == 3 || noCh || ch == 4)
  1192. {
  1193. if (plci->spoofed_msg == SPOOFING_REQUIRED)
  1194. {
  1195. api_save_msg(parms, "wsssssssss", &plci->saved_msg);
  1196. plci->spoofed_msg = CALL_REQ;
  1197. plci->internal_command = BLOCK_PLCI;
  1198. plci->command = 0;
  1199. dbug(1, dprintf("Spoof"));
  1200. send_req(plci);
  1201. return false;
  1202. }
  1203. if (ch == 4)add_p(plci, CHI, p_chi);
  1204. add_s(plci, CPN, &parms[1]);
  1205. add_s(plci, DSA, &parms[3]);
  1206. if (noCh) add_p(plci, ESC, "\x02\x18\xfd"); /* D-channel, no B-L3 */
  1207. add_ai(plci, &parms[9]);
  1208. if (!dir)sig_req(plci, CALL_REQ, 0);
  1209. else
  1210. {
  1211. plci->command = PERM_LIST_REQ;
  1212. plci->appl = appl;
  1213. sig_req(plci, LISTEN_REQ, 0);
  1214. send_req(plci);
  1215. return false;
  1216. }
  1217. }
  1218. send_req(plci);
  1219. return false;
  1220. }
  1221. plci->Id = 0;
  1222. }
  1223. }
  1224. sendf(appl,
  1225. _CONNECT_R | CONFIRM,
  1226. Id,
  1227. Number,
  1228. "w", Info);
  1229. return 2;
  1230. }
  1231. static byte connect_res(dword Id, word Number, DIVA_CAPI_ADAPTER *a,
  1232. PLCI *plci, APPL *appl, API_PARSE *parms)
  1233. {
  1234. word i, Info;
  1235. word Reject;
  1236. static byte cau_t[] = {0, 0, 0x90, 0x91, 0xac, 0x9d, 0x86, 0xd8, 0x9b};
  1237. static byte esc_t[] = {0x03, 0x08, 0x00, 0x00};
  1238. API_PARSE *ai;
  1239. API_PARSE ai_parms[5];
  1240. word ch = 0;
  1241. if (!plci) {
  1242. dbug(1, dprintf("connect_res(no plci)"));
  1243. return 0; /* no plci, no send */
  1244. }
  1245. dbug(1, dprintf("connect_res(State=0x%x)", plci->State));
  1246. for (i = 0; i < 5; i++) ai_parms[i].length = 0;
  1247. ai = &parms[5];
  1248. dbug(1, dprintf("ai->length=%d", ai->length));
  1249. if (ai->length)
  1250. {
  1251. if (!api_parse(&ai->info[1], (word)ai->length, "ssss", ai_parms))
  1252. {
  1253. dbug(1, dprintf("ai_parms[0].length=%d/0x%x", ai_parms[0].length, GET_WORD(ai_parms[0].info + 1)));
  1254. ch = 0;
  1255. if (ai_parms[0].length)
  1256. {
  1257. ch = GET_WORD(ai_parms[0].info + 1);
  1258. dbug(1, dprintf("BCH-I=0x%x", ch));
  1259. }
  1260. }
  1261. }
  1262. if (plci->State == INC_CON_CONNECTED_ALERT)
  1263. {
  1264. dbug(1, dprintf("Connected Alert Call_Res"));
  1265. if (a->Info_Mask[appl->Id - 1] & 0x200)
  1266. {
  1267. /* early B3 connect (CIP mask bit 9) no release after a disc */
  1268. add_p(plci, LLI, "\x01\x01");
  1269. }
  1270. add_s(plci, CONN_NR, &parms[2]);
  1271. add_s(plci, LLC, &parms[4]);
  1272. add_ai(plci, &parms[5]);
  1273. plci->State = INC_CON_ACCEPT;
  1274. sig_req(plci, CALL_RES, 0);
  1275. return 1;
  1276. }
  1277. else if (plci->State == INC_CON_PENDING || plci->State == INC_CON_ALERT) {
  1278. clear_c_ind_mask_bit(plci, (word)(appl->Id - 1));
  1279. dump_c_ind_mask(plci);
  1280. Reject = GET_WORD(parms[0].info);
  1281. dbug(1, dprintf("Reject=0x%x", Reject));
  1282. if (Reject)
  1283. {
  1284. if (c_ind_mask_empty(plci))
  1285. {
  1286. if ((Reject & 0xff00) == 0x3400)
  1287. {
  1288. esc_t[2] = ((byte)(Reject & 0x00ff)) | 0x80;
  1289. add_p(plci, ESC, esc_t);
  1290. add_ai(plci, &parms[5]);
  1291. sig_req(plci, REJECT, 0);
  1292. }
  1293. else if (Reject == 1 || Reject >= 9)
  1294. {
  1295. add_ai(plci, &parms[5]);
  1296. sig_req(plci, HANGUP, 0);
  1297. }
  1298. else
  1299. {
  1300. esc_t[2] = cau_t[(Reject&0x000f)];
  1301. add_p(plci, ESC, esc_t);
  1302. add_ai(plci, &parms[5]);
  1303. sig_req(plci, REJECT, 0);
  1304. }
  1305. plci->appl = appl;
  1306. }
  1307. else
  1308. {
  1309. sendf(appl, _DISCONNECT_I, Id, 0, "w", _OTHER_APPL_CONNECTED);
  1310. }
  1311. }
  1312. else {
  1313. plci->appl = appl;
  1314. if (Id & EXT_CONTROLLER) {
  1315. if (AdvCodecSupport(a, plci, appl, 0)) {
  1316. dbug(1, dprintf("connect_res(error from AdvCodecSupport)"));
  1317. sig_req(plci, HANGUP, 0);
  1318. return 1;
  1319. }
  1320. if (plci->tel == ADV_VOICE && a->AdvCodecPLCI)
  1321. {
  1322. Info = add_b23(plci, &parms[1]);
  1323. if (Info)
  1324. {
  1325. dbug(1, dprintf("connect_res(error from add_b23)"));
  1326. sig_req(plci, HANGUP, 0);
  1327. return 1;
  1328. }
  1329. if (plci->adv_nl)
  1330. {
  1331. nl_req_ncci(plci, ASSIGN, 0);
  1332. }
  1333. }
  1334. }
  1335. else
  1336. {
  1337. plci->tel = 0;
  1338. if (ch != 2)
  1339. {
  1340. Info = add_b23(plci, &parms[1]);
  1341. if (Info)
  1342. {
  1343. dbug(1, dprintf("connect_res(error from add_b23 2)"));
  1344. sig_req(plci, HANGUP, 0);
  1345. return 1;
  1346. }
  1347. }
  1348. nl_req_ncci(plci, ASSIGN, 0);
  1349. }
  1350. if (plci->spoofed_msg == SPOOFING_REQUIRED)
  1351. {
  1352. api_save_msg(parms, "wsssss", &plci->saved_msg);
  1353. plci->spoofed_msg = CALL_RES;
  1354. plci->internal_command = BLOCK_PLCI;
  1355. plci->command = 0;
  1356. dbug(1, dprintf("Spoof"));
  1357. }
  1358. else
  1359. {
  1360. add_b1(plci, &parms[1], ch, plci->B1_facilities);
  1361. if (a->Info_Mask[appl->Id - 1] & 0x200)
  1362. {
  1363. /* early B3 connect (CIP mask bit 9) no release after a disc */
  1364. add_p(plci, LLI, "\x01\x01");
  1365. }
  1366. add_s(plci, CONN_NR, &parms[2]);
  1367. add_s(plci, LLC, &parms[4]);
  1368. add_ai(plci, &parms[5]);
  1369. plci->State = INC_CON_ACCEPT;
  1370. sig_req(plci, CALL_RES, 0);
  1371. }
  1372. for (i = 0; i < max_appl; i++) {
  1373. if (test_c_ind_mask_bit(plci, i)) {
  1374. sendf(&application[i], _DISCONNECT_I, Id, 0, "w", _OTHER_APPL_CONNECTED);
  1375. }
  1376. }
  1377. }
  1378. }
  1379. return 1;
  1380. }
  1381. static byte connect_a_res(dword Id, word Number, DIVA_CAPI_ADAPTER *a,
  1382. PLCI *plci, APPL *appl, API_PARSE *msg)
  1383. {
  1384. dbug(1, dprintf("connect_a_res"));
  1385. return false;
  1386. }
  1387. static byte disconnect_req(dword Id, word Number, DIVA_CAPI_ADAPTER *a,
  1388. PLCI *plci, APPL *appl, API_PARSE *msg)
  1389. {
  1390. word Info;
  1391. word i;
  1392. dbug(1, dprintf("disconnect_req"));
  1393. Info = _WRONG_IDENTIFIER;
  1394. if (plci)
  1395. {
  1396. if (plci->State == INC_CON_PENDING || plci->State == INC_CON_ALERT)
  1397. {
  1398. clear_c_ind_mask_bit(plci, (word)(appl->Id - 1));
  1399. plci->appl = appl;
  1400. for (i = 0; i < max_appl; i++)
  1401. {
  1402. if (test_c_ind_mask_bit(plci, i))
  1403. sendf(&application[i], _DISCONNECT_I, Id, 0, "w", 0);
  1404. }
  1405. plci->State = OUTG_DIS_PENDING;
  1406. }
  1407. if (plci->Sig.Id && plci->appl)
  1408. {
  1409. Info = 0;
  1410. if (plci->Sig.Id != 0xff)
  1411. {
  1412. if (plci->State != INC_DIS_PENDING)
  1413. {
  1414. add_ai(plci, &msg[0]);
  1415. sig_req(plci, HANGUP, 0);
  1416. plci->State = OUTG_DIS_PENDING;
  1417. return 1;
  1418. }
  1419. }
  1420. else
  1421. {
  1422. if (plci->NL.Id && !plci->nl_remove_id)
  1423. {
  1424. mixer_remove(plci);
  1425. nl_req_ncci(plci, REMOVE, 0);
  1426. sendf(appl, _DISCONNECT_R | CONFIRM, Id, Number, "w", 0);
  1427. sendf(appl, _DISCONNECT_I, Id, 0, "w", 0);
  1428. plci->State = INC_DIS_PENDING;
  1429. }
  1430. return 1;
  1431. }
  1432. }
  1433. }
  1434. if (!appl) return false;
  1435. sendf(appl, _DISCONNECT_R | CONFIRM, Id, Number, "w", Info);
  1436. return false;
  1437. }
  1438. static byte disconnect_res(dword Id, word Number, DIVA_CAPI_ADAPTER *a,
  1439. PLCI *plci, APPL *appl, API_PARSE *msg)
  1440. {
  1441. dbug(1, dprintf("disconnect_res"));
  1442. if (plci)
  1443. {
  1444. /* clear ind mask bit, just in case of collsion of */
  1445. /* DISCONNECT_IND and CONNECT_RES */
  1446. clear_c_ind_mask_bit(plci, (word)(appl->Id - 1));
  1447. ncci_free_receive_buffers(plci, 0);
  1448. if (plci_remove_check(plci))
  1449. {
  1450. return 0;
  1451. }
  1452. if (plci->State == INC_DIS_PENDING
  1453. || plci->State == SUSPENDING) {
  1454. if (c_ind_mask_empty(plci)) {
  1455. if (plci->State != SUSPENDING) plci->State = IDLE;
  1456. dbug(1, dprintf("chs=%d", plci->channels));
  1457. if (!plci->channels) {
  1458. plci_remove(plci);
  1459. }
  1460. }
  1461. }
  1462. }
  1463. return 0;
  1464. }
  1465. static byte listen_req(dword Id, word Number, DIVA_CAPI_ADAPTER *a,
  1466. PLCI *plci, APPL *appl, API_PARSE *parms)
  1467. {
  1468. word Info;
  1469. byte i;
  1470. dbug(1, dprintf("listen_req(Appl=0x%x)", appl->Id));
  1471. Info = _WRONG_IDENTIFIER;
  1472. if (a) {
  1473. Info = 0;
  1474. a->Info_Mask[appl->Id - 1] = GET_DWORD(parms[0].info);
  1475. a->CIP_Mask[appl->Id - 1] = GET_DWORD(parms[1].info);
  1476. dbug(1, dprintf("CIP_MASK=0x%lx", GET_DWORD(parms[1].info)));
  1477. if (a->Info_Mask[appl->Id - 1] & 0x200) { /* early B3 connect provides */
  1478. a->Info_Mask[appl->Id - 1] |= 0x10; /* call progression infos */
  1479. }
  1480. /* check if external controller listen and switch listen on or off*/
  1481. if (Id&EXT_CONTROLLER && GET_DWORD(parms[1].info)) {
  1482. if (a->profile.Global_Options & ON_BOARD_CODEC) {
  1483. dummy_plci.State = IDLE;
  1484. a->codec_listen[appl->Id - 1] = &dummy_plci;
  1485. a->TelOAD[0] = (byte)(parms[3].length);
  1486. for (i = 1; parms[3].length >= i && i < 22; i++) {
  1487. a->TelOAD[i] = parms[3].info[i];
  1488. }
  1489. a->TelOAD[i] = 0;
  1490. a->TelOSA[0] = (byte)(parms[4].length);
  1491. for (i = 1; parms[4].length >= i && i < 22; i++) {
  1492. a->TelOSA[i] = parms[4].info[i];
  1493. }
  1494. a->TelOSA[i] = 0;
  1495. }
  1496. else Info = 0x2002; /* wrong controller, codec not supported */
  1497. }
  1498. else{ /* clear listen */
  1499. a->codec_listen[appl->Id - 1] = (PLCI *)0;
  1500. }
  1501. }
  1502. sendf(appl,
  1503. _LISTEN_R | CONFIRM,
  1504. Id,
  1505. Number,
  1506. "w", Info);
  1507. if (a) listen_check(a);
  1508. return false;
  1509. }
  1510. static byte info_req(dword Id, word Number, DIVA_CAPI_ADAPTER *a,
  1511. PLCI *plci, APPL *appl, API_PARSE *msg)
  1512. {
  1513. word i;
  1514. API_PARSE *ai;
  1515. PLCI *rc_plci = NULL;
  1516. API_PARSE ai_parms[5];
  1517. word Info = 0;
  1518. dbug(1, dprintf("info_req"));
  1519. for (i = 0; i < 5; i++) ai_parms[i].length = 0;
  1520. ai = &msg[1];
  1521. if (ai->length)
  1522. {
  1523. if (api_parse(&ai->info[1], (word)ai->length, "ssss", ai_parms))
  1524. {
  1525. dbug(1, dprintf("AddInfo wrong"));
  1526. Info = _WRONG_MESSAGE_FORMAT;
  1527. }
  1528. }
  1529. if (!a) Info = _WRONG_STATE;
  1530. if (!Info && plci)
  1531. { /* no fac, with CPN, or KEY */
  1532. rc_plci = plci;
  1533. if (!ai_parms[3].length && plci->State && (msg[0].length || ai_parms[1].length))
  1534. {
  1535. /* overlap sending option */
  1536. dbug(1, dprintf("OvlSnd"));
  1537. add_s(plci, CPN, &msg[0]);
  1538. add_s(plci, KEY, &ai_parms[1]);
  1539. sig_req(plci, INFO_REQ, 0);
  1540. send_req(plci);
  1541. return false;
  1542. }
  1543. if (plci->State && ai_parms[2].length)
  1544. {
  1545. /* User_Info option */
  1546. dbug(1, dprintf("UUI"));
  1547. add_s(plci, UUI, &ai_parms[2]);
  1548. sig_req(plci, USER_DATA, 0);
  1549. }
  1550. else if (plci->State && ai_parms[3].length)
  1551. {
  1552. /* Facility option */
  1553. dbug(1, dprintf("FAC"));
  1554. add_s(plci, CPN, &msg[0]);
  1555. add_ai(plci, &msg[1]);
  1556. sig_req(plci, FACILITY_REQ, 0);
  1557. }
  1558. else
  1559. {
  1560. Info = _WRONG_STATE;
  1561. }
  1562. }
  1563. else if ((ai_parms[1].length || ai_parms[2].length || ai_parms[3].length) && !Info)
  1564. {
  1565. /* NCR_Facility option -> send UUI and Keypad too */
  1566. dbug(1, dprintf("NCR_FAC"));
  1567. if ((i = get_plci(a)))
  1568. {
  1569. rc_plci = &a->plci[i - 1];
  1570. appl->NullCREnable = true;
  1571. rc_plci->internal_command = C_NCR_FAC_REQ;
  1572. rc_plci->appl = appl;
  1573. add_p(rc_plci, CAI, "\x01\x80");
  1574. add_p(rc_plci, UID, "\x06\x43\x61\x70\x69\x32\x30");
  1575. sig_req(rc_plci, ASSIGN, DSIG_ID);
  1576. send_req(rc_plci);
  1577. }
  1578. else
  1579. {
  1580. Info = _OUT_OF_PLCI;
  1581. }
  1582. if (!Info)
  1583. {
  1584. add_s(rc_plci, CPN, &msg[0]);
  1585. add_ai(rc_plci, &msg[1]);
  1586. sig_req(rc_plci, NCR_FACILITY, 0);
  1587. send_req(rc_plci);
  1588. return false;
  1589. /* for application controlled supplementary services */
  1590. }
  1591. }
  1592. if (!rc_plci)
  1593. {
  1594. Info = _WRONG_MESSAGE_FORMAT;
  1595. }
  1596. if (!Info)
  1597. {
  1598. send_req(rc_plci);
  1599. }
  1600. else
  1601. { /* appl is not assigned to a PLCI or error condition */
  1602. dbug(1, dprintf("localInfoCon"));
  1603. sendf(appl,
  1604. _INFO_R | CONFIRM,
  1605. Id,
  1606. Number,
  1607. "w", Info);
  1608. }
  1609. return false;
  1610. }
  1611. static byte info_res(dword Id, word Number, DIVA_CAPI_ADAPTER *a,
  1612. PLCI *plci, APPL *appl, API_PARSE *msg)
  1613. {
  1614. dbug(1, dprintf("info_res"));
  1615. return false;
  1616. }
  1617. static byte alert_req(dword Id, word Number, DIVA_CAPI_ADAPTER *a,
  1618. PLCI *plci, APPL *appl, API_PARSE *msg)
  1619. {
  1620. word Info;
  1621. byte ret;
  1622. dbug(1, dprintf("alert_req"));
  1623. Info = _WRONG_IDENTIFIER;
  1624. ret = false;
  1625. if (plci) {
  1626. Info = _ALERT_IGNORED;
  1627. if (plci->State != INC_CON_ALERT) {
  1628. Info = _WRONG_STATE;
  1629. if (plci->State == INC_CON_PENDING) {
  1630. Info = 0;
  1631. plci->State = INC_CON_ALERT;
  1632. add_ai(plci, &msg[0]);
  1633. sig_req(plci, CALL_ALERT, 0);
  1634. ret = 1;
  1635. }
  1636. }
  1637. }
  1638. sendf(appl,
  1639. _ALERT_R | CONFIRM,
  1640. Id,
  1641. Number,
  1642. "w", Info);
  1643. return ret;
  1644. }
  1645. static byte facility_req(dword Id, word Number, DIVA_CAPI_ADAPTER *a,
  1646. PLCI *plci, APPL *appl, API_PARSE *msg)
  1647. {
  1648. word Info = 0;
  1649. word i = 0;
  1650. word selector;
  1651. word SSreq;
  1652. long relatedPLCIvalue;
  1653. DIVA_CAPI_ADAPTER *relatedadapter;
  1654. byte *SSparms = "";
  1655. byte RCparms[] = "\x05\x00\x00\x02\x00\x00";
  1656. byte SSstruct[] = "\x09\x00\x00\x06\x00\x00\x00\x00\x00\x00";
  1657. API_PARSE *parms;
  1658. API_PARSE ss_parms[11];
  1659. PLCI *rplci;
  1660. byte cai[15];
  1661. dword d;
  1662. API_PARSE dummy;
  1663. dbug(1, dprintf("facility_req"));
  1664. for (i = 0; i < 9; i++) ss_parms[i].length = 0;
  1665. parms = &msg[1];
  1666. if (!a)
  1667. {
  1668. dbug(1, dprintf("wrong Ctrl"));
  1669. Info = _WRONG_IDENTIFIER;
  1670. }
  1671. selector = GET_WORD(msg[0].info);
  1672. if (!Info)
  1673. {
  1674. switch (selector)
  1675. {
  1676. case SELECTOR_HANDSET:
  1677. Info = AdvCodecSupport(a, plci, appl, HOOK_SUPPORT);
  1678. break;
  1679. case SELECTOR_SU_SERV:
  1680. if (!msg[1].length)
  1681. {
  1682. Info = _WRONG_MESSAGE_FORMAT;
  1683. break;
  1684. }
  1685. SSreq = GET_WORD(&(msg[1].info[1]));
  1686. PUT_WORD(&RCparms[1], SSreq);
  1687. SSparms = RCparms;
  1688. switch (SSreq)
  1689. {
  1690. case S_GET_SUPPORTED_SERVICES:
  1691. if ((i = get_plci(a)))
  1692. {
  1693. rplci = &a->plci[i - 1];
  1694. rplci->appl = appl;
  1695. add_p(rplci, CAI, "\x01\x80");
  1696. add_p(rplci, UID, "\x06\x43\x61\x70\x69\x32\x30");
  1697. sig_req(rplci, ASSIGN, DSIG_ID);
  1698. send_req(rplci);
  1699. }
  1700. else
  1701. {
  1702. PUT_DWORD(&SSstruct[6], MASK_TERMINAL_PORTABILITY);
  1703. SSparms = (byte *)SSstruct;
  1704. break;
  1705. }
  1706. rplci->internal_command = GETSERV_REQ_PEND;
  1707. rplci->number = Number;
  1708. rplci->appl = appl;
  1709. sig_req(rplci, S_SUPPORTED, 0);
  1710. send_req(rplci);
  1711. return false;
  1712. break;
  1713. case S_LISTEN:
  1714. if (parms->length == 7)
  1715. {
  1716. if (api_parse(&parms->info[1], (word)parms->length, "wbd", ss_parms))
  1717. {
  1718. dbug(1, dprintf("format wrong"));
  1719. Info = _WRONG_MESSAGE_FORMAT;
  1720. break;
  1721. }
  1722. }
  1723. else
  1724. {
  1725. Info = _WRONG_MESSAGE_FORMAT;
  1726. break;
  1727. }
  1728. a->Notification_Mask[appl->Id - 1] = GET_DWORD(ss_parms[2].info);
  1729. if (a->Notification_Mask[appl->Id - 1] & SMASK_MWI) /* MWI active? */
  1730. {
  1731. if ((i = get_plci(a)))
  1732. {
  1733. rplci = &a->plci[i - 1];
  1734. rplci->appl = appl;
  1735. add_p(rplci, CAI, "\x01\x80");
  1736. add_p(rplci, UID, "\x06\x43\x61\x70\x69\x32\x30");
  1737. sig_req(rplci, ASSIGN, DSIG_ID);
  1738. send_req(rplci);
  1739. }
  1740. else
  1741. {
  1742. break;
  1743. }
  1744. rplci->internal_command = GET_MWI_STATE;
  1745. rplci->number = Number;
  1746. sig_req(rplci, MWI_POLL, 0);
  1747. send_req(rplci);
  1748. }
  1749. break;
  1750. case S_HOLD:
  1751. api_parse(&parms->info[1], (word)parms->length, "ws", ss_parms);
  1752. if (plci && plci->State && plci->SuppState == IDLE)
  1753. {
  1754. plci->SuppState = HOLD_REQUEST;
  1755. plci->command = C_HOLD_REQ;
  1756. add_s(plci, CAI, &ss_parms[1]);
  1757. sig_req(plci, CALL_HOLD, 0);
  1758. send_req(plci);
  1759. return false;
  1760. }
  1761. else Info = 0x3010; /* wrong state */
  1762. break;
  1763. case S_RETRIEVE:
  1764. if (plci && plci->State && plci->SuppState == CALL_HELD)
  1765. {
  1766. if (Id & EXT_CONTROLLER)
  1767. {
  1768. if (AdvCodecSupport(a, plci, appl, 0))
  1769. {
  1770. Info = 0x3010; /* wrong state */
  1771. break;
  1772. }
  1773. }
  1774. else plci->tel = 0;
  1775. plci->SuppState = RETRIEVE_REQUEST;
  1776. plci->command = C_RETRIEVE_REQ;
  1777. if (plci->spoofed_msg == SPOOFING_REQUIRED)
  1778. {
  1779. plci->spoofed_msg = CALL_RETRIEVE;
  1780. plci->internal_command = BLOCK_PLCI;
  1781. plci->command = 0;
  1782. dbug(1, dprintf("Spoof"));
  1783. return false;
  1784. }
  1785. else
  1786. {
  1787. sig_req(plci, CALL_RETRIEVE, 0);
  1788. send_req(plci);
  1789. return false;
  1790. }
  1791. }
  1792. else Info = 0x3010; /* wrong state */
  1793. break;
  1794. case S_SUSPEND:
  1795. if (parms->length)
  1796. {
  1797. if (api_parse(&parms->info[1], (word)parms->length, "wbs", ss_parms))
  1798. {
  1799. dbug(1, dprintf("format wrong"));
  1800. Info = _WRONG_MESSAGE_FORMAT;
  1801. break;
  1802. }
  1803. }
  1804. if (plci && plci->State)
  1805. {
  1806. add_s(plci, CAI, &ss_parms[2]);
  1807. plci->command = SUSPEND_REQ;
  1808. sig_req(plci, SUSPEND, 0);
  1809. plci->State = SUSPENDING;
  1810. send_req(plci);
  1811. }
  1812. else Info = 0x3010; /* wrong state */
  1813. break;
  1814. case S_RESUME:
  1815. if (!(i = get_plci(a)))
  1816. {
  1817. Info = _OUT_OF_PLCI;
  1818. break;
  1819. }
  1820. rplci = &a->plci[i - 1];
  1821. rplci->appl = appl;
  1822. rplci->number = Number;
  1823. rplci->tel = 0;
  1824. rplci->call_dir = CALL_DIR_OUT | CALL_DIR_ORIGINATE;
  1825. /* check 'external controller' bit for codec support */
  1826. if (Id & EXT_CONTROLLER)
  1827. {
  1828. if (AdvCodecSupport(a, rplci, appl, 0))
  1829. {
  1830. rplci->Id = 0;
  1831. Info = 0x300A;
  1832. break;
  1833. }
  1834. }
  1835. if (parms->length)
  1836. {
  1837. if (api_parse(&parms->info[1], (word)parms->length, "wbs", ss_parms))
  1838. {
  1839. dbug(1, dprintf("format wrong"));
  1840. rplci->Id = 0;
  1841. Info = _WRONG_MESSAGE_FORMAT;
  1842. break;
  1843. }
  1844. }
  1845. dummy.length = 0;
  1846. dummy.info = "\x00";
  1847. add_b1(rplci, &dummy, 0, 0);
  1848. if (a->Info_Mask[appl->Id - 1] & 0x200)
  1849. {
  1850. /* early B3 connect (CIP mask bit 9) no release after a disc */
  1851. add_p(rplci, LLI, "\x01\x01");
  1852. }
  1853. add_p(rplci, UID, "\x06\x43\x61\x70\x69\x32\x30");
  1854. sig_req(rplci, ASSIGN, DSIG_ID);
  1855. send_req(rplci);
  1856. add_s(rplci, CAI, &ss_parms[2]);
  1857. rplci->command = RESUME_REQ;
  1858. sig_req(rplci, RESUME, 0);
  1859. rplci->State = RESUMING;
  1860. send_req(rplci);
  1861. break;
  1862. case S_CONF_BEGIN: /* Request */
  1863. case S_CONF_DROP:
  1864. case S_CONF_ISOLATE:
  1865. case S_CONF_REATTACH:
  1866. if (api_parse(&parms->info[1], (word)parms->length, "wbd", ss_parms))
  1867. {
  1868. dbug(1, dprintf("format wrong"));
  1869. Info = _WRONG_MESSAGE_FORMAT;
  1870. break;
  1871. }
  1872. if (plci && plci->State && ((plci->SuppState == IDLE) || (plci->SuppState == CALL_HELD)))
  1873. {
  1874. d = GET_DWORD(ss_parms[2].info);
  1875. if (d >= 0x80)
  1876. {
  1877. dbug(1, dprintf("format wrong"));
  1878. Info = _WRONG_MESSAGE_FORMAT;
  1879. break;
  1880. }
  1881. plci->ptyState = (byte)SSreq;
  1882. plci->command = 0;
  1883. cai[0] = 2;
  1884. switch (SSreq)
  1885. {
  1886. case S_CONF_BEGIN:
  1887. cai[1] = CONF_BEGIN;
  1888. plci->internal_command = CONF_BEGIN_REQ_PEND;
  1889. break;
  1890. case S_CONF_DROP:
  1891. cai[1] = CONF_DROP;
  1892. plci->internal_command = CONF_DROP_REQ_PEND;
  1893. break;
  1894. case S_CONF_ISOLATE:
  1895. cai[1] = CONF_ISOLATE;
  1896. plci->internal_command = CONF_ISOLATE_REQ_PEND;
  1897. break;
  1898. case S_CONF_REATTACH:
  1899. cai[1] = CONF_REATTACH;
  1900. plci->internal_command = CONF_REATTACH_REQ_PEND;
  1901. break;
  1902. }
  1903. cai[2] = (byte)d; /* Conference Size resp. PartyId */
  1904. add_p(plci, CAI, cai);
  1905. sig_req(plci, S_SERVICE, 0);
  1906. send_req(plci);
  1907. return false;
  1908. }
  1909. else Info = 0x3010; /* wrong state */
  1910. break;
  1911. case S_ECT:
  1912. case S_3PTY_BEGIN:
  1913. case S_3PTY_END:
  1914. case S_CONF_ADD:
  1915. if (parms->length == 7)
  1916. {
  1917. if (api_parse(&parms->info[1], (word)parms->length, "wbd", ss_parms))
  1918. {
  1919. dbug(1, dprintf("format wrong"));
  1920. Info = _WRONG_MESSAGE_FORMAT;
  1921. break;
  1922. }
  1923. }
  1924. else if (parms->length == 8) /* workaround for the T-View-S */
  1925. {
  1926. if (api_parse(&parms->info[1], (word)parms->length, "wbdb", ss_parms))
  1927. {
  1928. dbug(1, dprintf("format wrong"));
  1929. Info = _WRONG_MESSAGE_FORMAT;
  1930. break;
  1931. }
  1932. }
  1933. else
  1934. {
  1935. Info = _WRONG_MESSAGE_FORMAT;
  1936. break;
  1937. }
  1938. if (!msg[1].length)
  1939. {
  1940. Info = _WRONG_MESSAGE_FORMAT;
  1941. break;
  1942. }
  1943. if (!plci)
  1944. {
  1945. Info = _WRONG_IDENTIFIER;
  1946. break;
  1947. }
  1948. relatedPLCIvalue = GET_DWORD(ss_parms[2].info);
  1949. relatedPLCIvalue &= 0x0000FFFF;
  1950. dbug(1, dprintf("PTY/ECT/addCONF,relPLCI=%lx", relatedPLCIvalue));
  1951. /* controller starts with 0 up to (max_adapter - 1) */
  1952. if (((relatedPLCIvalue & 0x7f) == 0)
  1953. || (MapController((byte)(relatedPLCIvalue & 0x7f)) == 0)
  1954. || (MapController((byte)(relatedPLCIvalue & 0x7f)) > max_adapter))
  1955. {
  1956. if (SSreq == S_3PTY_END)
  1957. {
  1958. dbug(1, dprintf("wrong Controller use 2nd PLCI=PLCI"));
  1959. rplci = plci;
  1960. }
  1961. else
  1962. {
  1963. Info = 0x3010; /* wrong state */
  1964. break;
  1965. }
  1966. }
  1967. else
  1968. {
  1969. relatedadapter = &adapter[MapController((byte)(relatedPLCIvalue & 0x7f)) - 1];
  1970. relatedPLCIvalue >>= 8;
  1971. /* find PLCI PTR*/
  1972. for (i = 0, rplci = NULL; i < relatedadapter->max_plci; i++)
  1973. {
  1974. if (relatedadapter->plci[i].Id == (byte)relatedPLCIvalue)
  1975. {
  1976. rplci = &relatedadapter->plci[i];
  1977. }
  1978. }
  1979. if (!rplci || !relatedPLCIvalue)
  1980. {
  1981. if (SSreq == S_3PTY_END)
  1982. {
  1983. dbug(1, dprintf("use 2nd PLCI=PLCI"));
  1984. rplci = plci;
  1985. }
  1986. else
  1987. {
  1988. Info = 0x3010; /* wrong state */
  1989. break;
  1990. }
  1991. }
  1992. }
  1993. /*
  1994. dbug(1, dprintf("rplci:%x", rplci));
  1995. dbug(1, dprintf("plci:%x", plci));
  1996. dbug(1, dprintf("rplci->ptyState:%x", rplci->ptyState));
  1997. dbug(1, dprintf("plci->ptyState:%x", plci->ptyState));
  1998. dbug(1, dprintf("SSreq:%x", SSreq));
  1999. dbug(1, dprintf("rplci->internal_command:%x", rplci->internal_command));
  2000. dbug(1, dprintf("rplci->appl:%x", rplci->appl));
  2001. dbug(1, dprintf("rplci->Id:%x", rplci->Id));
  2002. */
  2003. /* send PTY/ECT req, cannot check all states because of US stuff */
  2004. if (!rplci->internal_command && rplci->appl)
  2005. {
  2006. plci->command = 0;
  2007. rplci->relatedPTYPLCI = plci;
  2008. plci->relatedPTYPLCI = rplci;
  2009. rplci->ptyState = (byte)SSreq;
  2010. if (SSreq == S_ECT)
  2011. {
  2012. rplci->internal_command = ECT_REQ_PEND;
  2013. cai[1] = ECT_EXECUTE;
  2014. rplci->vswitchstate = 0;
  2015. rplci->vsprot = 0;
  2016. rplci->vsprotdialect = 0;
  2017. plci->vswitchstate = 0;
  2018. plci->vsprot = 0;
  2019. plci->vsprotdialect = 0;
  2020. }
  2021. else if (SSreq == S_CONF_ADD)
  2022. {
  2023. rplci->internal_command = CONF_ADD_REQ_PEND;
  2024. cai[1] = CONF_ADD;
  2025. }
  2026. else
  2027. {
  2028. rplci->internal_command = PTY_REQ_PEND;
  2029. cai[1] = (byte)(SSreq - 3);
  2030. }
  2031. rplci->number = Number;
  2032. if (plci != rplci) /* explicit invocation */
  2033. {
  2034. cai[0] = 2;
  2035. cai[2] = plci->Sig.Id;
  2036. dbug(1, dprintf("explicit invocation"));
  2037. }
  2038. else
  2039. {
  2040. dbug(1, dprintf("implicit invocation"));
  2041. cai[0] = 1;
  2042. }
  2043. add_p(rplci, CAI, cai);
  2044. sig_req(rplci, S_SERVICE, 0);
  2045. send_req(rplci);
  2046. return false;
  2047. }
  2048. else
  2049. {
  2050. dbug(0, dprintf("Wrong line"));
  2051. Info = 0x3010; /* wrong state */
  2052. break;
  2053. }
  2054. break;
  2055. case S_CALL_DEFLECTION:
  2056. if (api_parse(&parms->info[1], (word)parms->length, "wbwss", ss_parms))
  2057. {
  2058. dbug(1, dprintf("format wrong"));
  2059. Info = _WRONG_MESSAGE_FORMAT;
  2060. break;
  2061. }
  2062. if (!plci)
  2063. {
  2064. Info = _WRONG_IDENTIFIER;
  2065. break;
  2066. }
  2067. /* reuse unused screening indicator */
  2068. ss_parms[3].info[3] = (byte)GET_WORD(&(ss_parms[2].info[0]));
  2069. plci->command = 0;
  2070. plci->internal_command = CD_REQ_PEND;
  2071. appl->CDEnable = true;
  2072. cai[0] = 1;
  2073. cai[1] = CALL_DEFLECTION;
  2074. add_p(plci, CAI, cai);
  2075. add_p(plci, CPN, ss_parms[3].info);
  2076. sig_req(plci, S_SERVICE, 0);
  2077. send_req(plci);
  2078. return false;
  2079. break;
  2080. case S_CALL_FORWARDING_START:
  2081. if (api_parse(&parms->info[1], (word)parms->length, "wbdwwsss", ss_parms))
  2082. {
  2083. dbug(1, dprintf("format wrong"));
  2084. Info = _WRONG_MESSAGE_FORMAT;
  2085. break;
  2086. }
  2087. if ((i = get_plci(a)))
  2088. {
  2089. rplci = &a->plci[i - 1];
  2090. rplci->appl = appl;
  2091. add_p(rplci, CAI, "\x01\x80");
  2092. add_p(rplci, UID, "\x06\x43\x61\x70\x69\x32\x30");
  2093. sig_req(rplci, ASSIGN, DSIG_ID);
  2094. send_req(rplci);
  2095. }
  2096. else
  2097. {
  2098. Info = _OUT_OF_PLCI;
  2099. break;
  2100. }
  2101. /* reuse unused screening indicator */
  2102. rplci->internal_command = CF_START_PEND;
  2103. rplci->appl = appl;
  2104. rplci->number = Number;
  2105. appl->S_Handle = GET_DWORD(&(ss_parms[2].info[0]));
  2106. cai[0] = 2;
  2107. cai[1] = 0x70 | (byte)GET_WORD(&(ss_parms[3].info[0])); /* Function */
  2108. cai[2] = (byte)GET_WORD(&(ss_parms[4].info[0])); /* Basic Service */
  2109. add_p(rplci, CAI, cai);
  2110. add_p(rplci, OAD, ss_parms[5].info);
  2111. add_p(rplci, CPN, ss_parms[6].info);
  2112. sig_req(rplci, S_SERVICE, 0);
  2113. send_req(rplci);
  2114. return false;
  2115. break;
  2116. case S_INTERROGATE_DIVERSION:
  2117. case S_INTERROGATE_NUMBERS:
  2118. case S_CALL_FORWARDING_STOP:
  2119. case S_CCBS_REQUEST:
  2120. case S_CCBS_DEACTIVATE:
  2121. case S_CCBS_INTERROGATE:
  2122. switch (SSreq)
  2123. {
  2124. case S_INTERROGATE_NUMBERS:
  2125. if (api_parse(&parms->info[1], (word)parms->length, "wbd", ss_parms))
  2126. {
  2127. dbug(0, dprintf("format wrong"));
  2128. Info = _WRONG_MESSAGE_FORMAT;
  2129. }
  2130. break;
  2131. case S_CCBS_REQUEST:
  2132. case S_CCBS_DEACTIVATE:
  2133. if (api_parse(&parms->info[1], (word)parms->length, "wbdw", ss_parms))
  2134. {
  2135. dbug(0, dprintf("format wrong"));
  2136. Info = _WRONG_MESSAGE_FORMAT;
  2137. }
  2138. break;
  2139. case S_CCBS_INTERROGATE:
  2140. if (api_parse(&parms->info[1], (word)parms->length, "wbdws", ss_parms))
  2141. {
  2142. dbug(0, dprintf("format wrong"));
  2143. Info = _WRONG_MESSAGE_FORMAT;
  2144. }
  2145. break;
  2146. default:
  2147. if (api_parse(&parms->info[1], (word)parms->length, "wbdwws", ss_parms))
  2148. {
  2149. dbug(0, dprintf("format wrong"));
  2150. Info = _WRONG_MESSAGE_FORMAT;
  2151. break;
  2152. }
  2153. break;
  2154. }
  2155. if (Info) break;
  2156. if ((i = get_plci(a)))
  2157. {
  2158. rplci = &a->plci[i - 1];
  2159. switch (SSreq)
  2160. {
  2161. case S_INTERROGATE_DIVERSION: /* use cai with S_SERVICE below */
  2162. cai[1] = 0x60 | (byte)GET_WORD(&(ss_parms[3].info[0])); /* Function */
  2163. rplci->internal_command = INTERR_DIVERSION_REQ_PEND; /* move to rplci if assigned */
  2164. break;
  2165. case S_INTERROGATE_NUMBERS: /* use cai with S_SERVICE below */
  2166. cai[1] = DIVERSION_INTERROGATE_NUM; /* Function */
  2167. rplci->internal_command = INTERR_NUMBERS_REQ_PEND; /* move to rplci if assigned */
  2168. break;
  2169. case S_CALL_FORWARDING_STOP:
  2170. rplci->internal_command = CF_STOP_PEND;
  2171. cai[1] = 0x80 | (byte)GET_WORD(&(ss_parms[3].info[0])); /* Function */
  2172. break;
  2173. case S_CCBS_REQUEST:
  2174. cai[1] = CCBS_REQUEST;
  2175. rplci->internal_command = CCBS_REQUEST_REQ_PEND;
  2176. break;
  2177. case S_CCBS_DEACTIVATE:
  2178. cai[1] = CCBS_DEACTIVATE;
  2179. rplci->internal_command = CCBS_DEACTIVATE_REQ_PEND;
  2180. break;
  2181. case S_CCBS_INTERROGATE:
  2182. cai[1] = CCBS_INTERROGATE;
  2183. rplci->internal_command = CCBS_INTERROGATE_REQ_PEND;
  2184. break;
  2185. default:
  2186. cai[1] = 0;
  2187. break;
  2188. }
  2189. rplci->appl = appl;
  2190. rplci->number = Number;
  2191. add_p(rplci, CAI, "\x01\x80");
  2192. add_p(rplci, UID, "\x06\x43\x61\x70\x69\x32\x30");
  2193. sig_req(rplci, ASSIGN, DSIG_ID);
  2194. send_req(rplci);
  2195. }
  2196. else
  2197. {
  2198. Info = _OUT_OF_PLCI;
  2199. break;
  2200. }
  2201. appl->S_Handle = GET_DWORD(&(ss_parms[2].info[0]));
  2202. switch (SSreq)
  2203. {
  2204. case S_INTERROGATE_NUMBERS:
  2205. cai[0] = 1;
  2206. add_p(rplci, CAI, cai);
  2207. break;
  2208. case S_CCBS_REQUEST:
  2209. case S_CCBS_DEACTIVATE:
  2210. cai[0] = 3;
  2211. PUT_WORD(&cai[2], GET_WORD(&(ss_parms[3].info[0])));
  2212. add_p(rplci, CAI, cai);
  2213. break;
  2214. case S_CCBS_INTERROGATE:
  2215. cai[0] = 3;
  2216. PUT_WORD(&cai[2], GET_WORD(&(ss_parms[3].info[0])));
  2217. add_p(rplci, CAI, cai);
  2218. add_p(rplci, OAD, ss_parms[4].info);
  2219. break;
  2220. default:
  2221. cai[0] = 2;
  2222. cai[2] = (byte)GET_WORD(&(ss_parms[4].info[0])); /* Basic Service */
  2223. add_p(rplci, CAI, cai);
  2224. add_p(rplci, OAD, ss_parms[5].info);
  2225. break;
  2226. }
  2227. sig_req(rplci, S_SERVICE, 0);
  2228. send_req(rplci);
  2229. return false;
  2230. break;
  2231. case S_MWI_ACTIVATE:
  2232. if (api_parse(&parms->info[1], (word)parms->length, "wbwdwwwssss", ss_parms))
  2233. {
  2234. dbug(1, dprintf("format wrong"));
  2235. Info = _WRONG_MESSAGE_FORMAT;
  2236. break;
  2237. }
  2238. if (!plci)
  2239. {
  2240. if ((i = get_plci(a)))
  2241. {
  2242. rplci = &a->plci[i - 1];
  2243. rplci->appl = appl;
  2244. rplci->cr_enquiry = true;
  2245. add_p(rplci, CAI, "\x01\x80");
  2246. add_p(rplci, UID, "\x06\x43\x61\x70\x69\x32\x30");
  2247. sig_req(rplci, ASSIGN, DSIG_ID);
  2248. send_req(rplci);
  2249. }
  2250. else
  2251. {
  2252. Info = _OUT_OF_PLCI;
  2253. break;
  2254. }
  2255. }
  2256. else
  2257. {
  2258. rplci = plci;
  2259. rplci->cr_enquiry = false;
  2260. }
  2261. rplci->command = 0;
  2262. rplci->internal_command = MWI_ACTIVATE_REQ_PEND;
  2263. rplci->appl = appl;
  2264. rplci->number = Number;
  2265. cai[0] = 13;
  2266. cai[1] = ACTIVATION_MWI; /* Function */
  2267. PUT_WORD(&cai[2], GET_WORD(&(ss_parms[2].info[0]))); /* Basic Service */
  2268. PUT_DWORD(&cai[4], GET_DWORD(&(ss_parms[3].info[0]))); /* Number of Messages */
  2269. PUT_WORD(&cai[8], GET_WORD(&(ss_parms[4].info[0]))); /* Message Status */
  2270. PUT_WORD(&cai[10], GET_WORD(&(ss_parms[5].info[0]))); /* Message Reference */
  2271. PUT_WORD(&cai[12], GET_WORD(&(ss_parms[6].info[0]))); /* Invocation Mode */
  2272. add_p(rplci, CAI, cai);
  2273. add_p(rplci, CPN, ss_parms[7].info); /* Receiving User Number */
  2274. add_p(rplci, OAD, ss_parms[8].info); /* Controlling User Number */
  2275. add_p(rplci, OSA, ss_parms[9].info); /* Controlling User Provided Number */
  2276. add_p(rplci, UID, ss_parms[10].info); /* Time */
  2277. sig_req(rplci, S_SERVICE, 0);
  2278. send_req(rplci);
  2279. return false;
  2280. case S_MWI_DEACTIVATE:
  2281. if (api_parse(&parms->info[1], (word)parms->length, "wbwwss", ss_parms))
  2282. {
  2283. dbug(1, dprintf("format wrong"));
  2284. Info = _WRONG_MESSAGE_FORMAT;
  2285. break;
  2286. }
  2287. if (!plci)
  2288. {
  2289. if ((i = get_plci(a)))
  2290. {
  2291. rplci = &a->plci[i - 1];
  2292. rplci->appl = appl;
  2293. rplci->cr_enquiry = true;
  2294. add_p(rplci, CAI, "\x01\x80");
  2295. add_p(rplci, UID, "\x06\x43\x61\x70\x69\x32\x30");
  2296. sig_req(rplci, ASSIGN, DSIG_ID);
  2297. send_req(rplci);
  2298. }
  2299. else
  2300. {
  2301. Info = _OUT_OF_PLCI;
  2302. break;
  2303. }
  2304. }
  2305. else
  2306. {
  2307. rplci = plci;
  2308. rplci->cr_enquiry = false;
  2309. }
  2310. rplci->command = 0;
  2311. rplci->internal_command = MWI_DEACTIVATE_REQ_PEND;
  2312. rplci->appl = appl;
  2313. rplci->number = Number;
  2314. cai[0] = 5;
  2315. cai[1] = DEACTIVATION_MWI; /* Function */
  2316. PUT_WORD(&cai[2], GET_WORD(&(ss_parms[2].info[0]))); /* Basic Service */
  2317. PUT_WORD(&cai[4], GET_WORD(&(ss_parms[3].info[0]))); /* Invocation Mode */
  2318. add_p(rplci, CAI, cai);
  2319. add_p(rplci, CPN, ss_parms[4].info); /* Receiving User Number */
  2320. add_p(rplci, OAD, ss_parms[5].info); /* Controlling User Number */
  2321. sig_req(rplci, S_SERVICE, 0);
  2322. send_req(rplci);
  2323. return false;
  2324. default:
  2325. Info = 0x300E; /* not supported */
  2326. break;
  2327. }
  2328. break; /* case SELECTOR_SU_SERV: end */
  2329. case SELECTOR_DTMF:
  2330. return (dtmf_request(Id, Number, a, plci, appl, msg));
  2331. case SELECTOR_LINE_INTERCONNECT:
  2332. return (mixer_request(Id, Number, a, plci, appl, msg));
  2333. case PRIV_SELECTOR_ECHO_CANCELLER:
  2334. appl->appl_flags |= APPL_FLAG_PRIV_EC_SPEC;
  2335. return (ec_request(Id, Number, a, plci, appl, msg));
  2336. case SELECTOR_ECHO_CANCELLER:
  2337. appl->appl_flags &= ~APPL_FLAG_PRIV_EC_SPEC;
  2338. return (ec_request(Id, Number, a, plci, appl, msg));
  2339. case SELECTOR_V42BIS:
  2340. default:
  2341. Info = _FACILITY_NOT_SUPPORTED;
  2342. break;
  2343. } /* end of switch (selector) */
  2344. }
  2345. dbug(1, dprintf("SendFacRc"));
  2346. sendf(appl,
  2347. _FACILITY_R | CONFIRM,
  2348. Id,
  2349. Number,
  2350. "wws", Info, selector, SSparms);
  2351. return false;
  2352. }
  2353. static byte facility_res(dword Id, word Number, DIVA_CAPI_ADAPTER *a,
  2354. PLCI *plci, APPL *appl, API_PARSE *msg)
  2355. {
  2356. dbug(1, dprintf("facility_res"));
  2357. return false;
  2358. }
  2359. static byte connect_b3_req(dword Id, word Number, DIVA_CAPI_ADAPTER *a,
  2360. PLCI *plci, APPL *appl, API_PARSE *parms)
  2361. {
  2362. word Info = 0;
  2363. byte req;
  2364. byte len;
  2365. word w;
  2366. word fax_control_bits, fax_feature_bits, fax_info_change;
  2367. API_PARSE *ncpi;
  2368. byte pvc[2];
  2369. API_PARSE fax_parms[9];
  2370. word i;
  2371. dbug(1, dprintf("connect_b3_req"));
  2372. if (plci)
  2373. {
  2374. if ((plci->State == IDLE) || (plci->State == OUTG_DIS_PENDING)
  2375. || (plci->State == INC_DIS_PENDING) || (plci->SuppState != IDLE))
  2376. {
  2377. Info = _WRONG_STATE;
  2378. }
  2379. else
  2380. {
  2381. /* local reply if assign unsuccessful
  2382. or B3 protocol allows only one layer 3 connection
  2383. and already connected
  2384. or B2 protocol not any LAPD
  2385. and connect_b3_req contradicts originate/answer direction */
  2386. if (!plci->NL.Id
  2387. || (((plci->B3_prot != B3_T90NL) && (plci->B3_prot != B3_ISO8208) && (plci->B3_prot != B3_X25_DCE))
  2388. && ((plci->channels != 0)
  2389. || (((plci->B2_prot != B2_SDLC) && (plci->B2_prot != B2_LAPD) && (plci->B2_prot != B2_LAPD_FREE_SAPI_SEL))
  2390. && ((plci->call_dir & CALL_DIR_ANSWER) && !(plci->call_dir & CALL_DIR_FORCE_OUTG_NL))))))
  2391. {
  2392. dbug(1, dprintf("B3 already connected=%d or no NL.Id=0x%x, dir=%d sstate=0x%x",
  2393. plci->channels, plci->NL.Id, plci->call_dir, plci->SuppState));
  2394. Info = _WRONG_STATE;
  2395. sendf(appl,
  2396. _CONNECT_B3_R | CONFIRM,
  2397. Id,
  2398. Number,
  2399. "w", Info);
  2400. return false;
  2401. }
  2402. plci->requested_options_conn = 0;
  2403. req = N_CONNECT;
  2404. ncpi = &parms[0];
  2405. if (plci->B3_prot == 2 || plci->B3_prot == 3)
  2406. {
  2407. if (ncpi->length > 2)
  2408. {
  2409. /* check for PVC */
  2410. if (ncpi->info[2] || ncpi->info[3])
  2411. {
  2412. pvc[0] = ncpi->info[3];
  2413. pvc[1] = ncpi->info[2];
  2414. add_d(plci, 2, pvc);
  2415. req = N_RESET;
  2416. }
  2417. else
  2418. {
  2419. if (ncpi->info[1] & 1) req = N_CONNECT | N_D_BIT;
  2420. add_d(plci, (word)(ncpi->length - 3), &ncpi->info[4]);
  2421. }
  2422. }
  2423. }
  2424. else if (plci->B3_prot == 5)
  2425. {
  2426. if (plci->NL.Id && !plci->nl_remove_id)
  2427. {
  2428. fax_control_bits = GET_WORD(&((T30_INFO *)plci->fax_connect_info_buffer)->control_bits_low);
  2429. fax_feature_bits = GET_WORD(&((T30_INFO *)plci->fax_connect_info_buffer)->feature_bits_low);
  2430. if (!(fax_control_bits & T30_CONTROL_BIT_MORE_DOCUMENTS)
  2431. || (fax_feature_bits & T30_FEATURE_BIT_MORE_DOCUMENTS))
  2432. {
  2433. len = offsetof(T30_INFO, universal_6);
  2434. fax_info_change = false;
  2435. if (ncpi->length >= 4)
  2436. {
  2437. w = GET_WORD(&ncpi->info[3]);
  2438. if ((w & 0x0001) != ((word)(((T30_INFO *)(plci->fax_connect_info_buffer))->resolution & 0x0001)))
  2439. {
  2440. ((T30_INFO *)(plci->fax_connect_info_buffer))->resolution =
  2441. (byte)((((T30_INFO *)(plci->fax_connect_info_buffer))->resolution & ~T30_RESOLUTION_R8_0770_OR_200) |
  2442. ((w & 0x0001) ? T30_RESOLUTION_R8_0770_OR_200 : 0));
  2443. fax_info_change = true;
  2444. }
  2445. fax_control_bits &= ~(T30_CONTROL_BIT_REQUEST_POLLING | T30_CONTROL_BIT_MORE_DOCUMENTS);
  2446. if (w & 0x0002) /* Fax-polling request */
  2447. fax_control_bits |= T30_CONTROL_BIT_REQUEST_POLLING;
  2448. if ((w & 0x0004) /* Request to send / poll another document */
  2449. && (a->manufacturer_features & MANUFACTURER_FEATURE_FAX_MORE_DOCUMENTS))
  2450. {
  2451. fax_control_bits |= T30_CONTROL_BIT_MORE_DOCUMENTS;
  2452. }
  2453. if (ncpi->length >= 6)
  2454. {
  2455. w = GET_WORD(&ncpi->info[5]);
  2456. if (((byte) w) != ((T30_INFO *)(plci->fax_connect_info_buffer))->data_format)
  2457. {
  2458. ((T30_INFO *)(plci->fax_connect_info_buffer))->data_format = (byte) w;
  2459. fax_info_change = true;
  2460. }
  2461. if ((a->man_profile.private_options & (1L << PRIVATE_FAX_SUB_SEP_PWD))
  2462. && (GET_WORD(&ncpi->info[5]) & 0x8000)) /* Private SEP/SUB/PWD enable */
  2463. {
  2464. plci->requested_options_conn |= (1L << PRIVATE_FAX_SUB_SEP_PWD);
  2465. }
  2466. if ((a->man_profile.private_options & (1L << PRIVATE_FAX_NONSTANDARD))
  2467. && (GET_WORD(&ncpi->info[5]) & 0x4000)) /* Private non-standard facilities enable */
  2468. {
  2469. plci->requested_options_conn |= (1L << PRIVATE_FAX_NONSTANDARD);
  2470. }
  2471. fax_control_bits &= ~(T30_CONTROL_BIT_ACCEPT_SUBADDRESS | T30_CONTROL_BIT_ACCEPT_SEL_POLLING |
  2472. T30_CONTROL_BIT_ACCEPT_PASSWORD);
  2473. if ((plci->requested_options_conn | plci->requested_options | a->requested_options_table[appl->Id - 1])
  2474. & ((1L << PRIVATE_FAX_SUB_SEP_PWD) | (1L << PRIVATE_FAX_NONSTANDARD)))
  2475. {
  2476. if (api_parse(&ncpi->info[1], ncpi->length, "wwwwsss", fax_parms))
  2477. Info = _WRONG_MESSAGE_FORMAT;
  2478. else
  2479. {
  2480. if ((plci->requested_options_conn | plci->requested_options | a->requested_options_table[appl->Id - 1])
  2481. & (1L << PRIVATE_FAX_SUB_SEP_PWD))
  2482. {
  2483. fax_control_bits |= T30_CONTROL_BIT_ACCEPT_SUBADDRESS | T30_CONTROL_BIT_ACCEPT_PASSWORD;
  2484. if (fax_control_bits & T30_CONTROL_BIT_ACCEPT_POLLING)
  2485. fax_control_bits |= T30_CONTROL_BIT_ACCEPT_SEL_POLLING;
  2486. }
  2487. w = fax_parms[4].length;
  2488. if (w > 20)
  2489. w = 20;
  2490. ((T30_INFO *)(plci->fax_connect_info_buffer))->station_id_len = (byte) w;
  2491. for (i = 0; i < w; i++)
  2492. ((T30_INFO *)(plci->fax_connect_info_buffer))->station_id[i] = fax_parms[4].info[1 + i];
  2493. ((T30_INFO *)(plci->fax_connect_info_buffer))->head_line_len = 0;
  2494. len = offsetof(T30_INFO, station_id) + T30_MAX_STATION_ID_LENGTH;
  2495. w = fax_parms[5].length;
  2496. if (w > 20)
  2497. w = 20;
  2498. plci->fax_connect_info_buffer[len++] = (byte) w;
  2499. for (i = 0; i < w; i++)
  2500. plci->fax_connect_info_buffer[len++] = fax_parms[5].info[1 + i];
  2501. w = fax_parms[6].length;
  2502. if (w > 20)
  2503. w = 20;
  2504. plci->fax_connect_info_buffer[len++] = (byte) w;
  2505. for (i = 0; i < w; i++)
  2506. plci->fax_connect_info_buffer[len++] = fax_parms[6].info[1 + i];
  2507. if ((plci->requested_options_conn | plci->requested_options | a->requested_options_table[appl->Id - 1])
  2508. & (1L << PRIVATE_FAX_NONSTANDARD))
  2509. {
  2510. if (api_parse(&ncpi->info[1], ncpi->length, "wwwwssss", fax_parms))
  2511. {
  2512. dbug(1, dprintf("non-standard facilities info missing or wrong format"));
  2513. plci->fax_connect_info_buffer[len++] = 0;
  2514. }
  2515. else
  2516. {
  2517. if ((fax_parms[7].length >= 3) && (fax_parms[7].info[1] >= 2))
  2518. plci->nsf_control_bits = GET_WORD(&fax_parms[7].info[2]);
  2519. plci->fax_connect_info_buffer[len++] = (byte)(fax_parms[7].length);
  2520. for (i = 0; i < fax_parms[7].length; i++)
  2521. plci->fax_connect_info_buffer[len++] = fax_parms[7].info[1 + i];
  2522. }
  2523. }
  2524. }
  2525. }
  2526. else
  2527. {
  2528. len = offsetof(T30_INFO, universal_6);
  2529. }
  2530. fax_info_change = true;
  2531. }
  2532. if (fax_control_bits != GET_WORD(&((T30_INFO *)plci->fax_connect_info_buffer)->control_bits_low))
  2533. {
  2534. PUT_WORD(&((T30_INFO *)plci->fax_connect_info_buffer)->control_bits_low, fax_control_bits);
  2535. fax_info_change = true;
  2536. }
  2537. }
  2538. if (Info == GOOD)
  2539. {
  2540. plci->fax_connect_info_length = len;
  2541. if (fax_info_change)
  2542. {
  2543. if (fax_feature_bits & T30_FEATURE_BIT_MORE_DOCUMENTS)
  2544. {
  2545. start_internal_command(Id, plci, fax_connect_info_command);
  2546. return false;
  2547. }
  2548. else
  2549. {
  2550. start_internal_command(Id, plci, fax_adjust_b23_command);
  2551. return false;
  2552. }
  2553. }
  2554. }
  2555. }
  2556. else Info = _WRONG_STATE;
  2557. }
  2558. else Info = _WRONG_STATE;
  2559. }
  2560. else if (plci->B3_prot == B3_RTP)
  2561. {
  2562. plci->internal_req_buffer[0] = ncpi->length + 1;
  2563. plci->internal_req_buffer[1] = UDATA_REQUEST_RTP_RECONFIGURE;
  2564. for (w = 0; w < ncpi->length; w++)
  2565. plci->internal_req_buffer[2 + w] = ncpi->info[1 + w];
  2566. start_internal_command(Id, plci, rtp_connect_b3_req_command);
  2567. return false;
  2568. }
  2569. if (!Info)
  2570. {
  2571. nl_req_ncci(plci, req, 0);
  2572. return 1;
  2573. }
  2574. }
  2575. }
  2576. else Info = _WRONG_IDENTIFIER;
  2577. sendf(appl,
  2578. _CONNECT_B3_R | CONFIRM,
  2579. Id,
  2580. Number,
  2581. "w", Info);
  2582. return false;
  2583. }
  2584. static byte connect_b3_res(dword Id, word Number, DIVA_CAPI_ADAPTER *a,
  2585. PLCI *plci, APPL *appl, API_PARSE *parms)
  2586. {
  2587. word ncci;
  2588. API_PARSE *ncpi;
  2589. byte req;
  2590. word w;
  2591. API_PARSE fax_parms[9];
  2592. word i;
  2593. byte len;
  2594. dbug(1, dprintf("connect_b3_res"));
  2595. ncci = (word)(Id >> 16);
  2596. if (plci && ncci) {
  2597. if (a->ncci_state[ncci] == INC_CON_PENDING) {
  2598. if (GET_WORD(&parms[0].info[0]) != 0)
  2599. {
  2600. a->ncci_state[ncci] = OUTG_REJ_PENDING;
  2601. channel_request_xon(plci, a->ncci_ch[ncci]);
  2602. channel_xmit_xon(plci);
  2603. cleanup_ncci_data(plci, ncci);
  2604. nl_req_ncci(plci, N_DISC, (byte)ncci);
  2605. return 1;
  2606. }
  2607. a->ncci_state[ncci] = INC_ACT_PENDING;
  2608. req = N_CONNECT_ACK;
  2609. ncpi = &parms[1];
  2610. if ((plci->B3_prot == 4) || (plci->B3_prot == 5) || (plci->B3_prot == 7))
  2611. {
  2612. if ((plci->requested_options_conn | plci->requested_options | a->requested_options_table[plci->appl->Id - 1])
  2613. & (1L << PRIVATE_FAX_NONSTANDARD))
  2614. {
  2615. if (((plci->B3_prot == 4) || (plci->B3_prot == 5))
  2616. && (plci->nsf_control_bits & T30_NSF_CONTROL_BIT_ENABLE_NSF)
  2617. && (plci->nsf_control_bits & T30_NSF_CONTROL_BIT_NEGOTIATE_RESP))
  2618. {
  2619. len = offsetof(T30_INFO, station_id) + T30_MAX_STATION_ID_LENGTH;
  2620. if (plci->fax_connect_info_length < len)
  2621. {
  2622. ((T30_INFO *)(plci->fax_connect_info_buffer))->station_id_len = 0;
  2623. ((T30_INFO *)(plci->fax_connect_info_buffer))->head_line_len = 0;
  2624. }
  2625. if (api_parse(&ncpi->info[1], ncpi->length, "wwwwssss", fax_parms))
  2626. {
  2627. dbug(1, dprintf("non-standard facilities info missing or wrong format"));
  2628. }
  2629. else
  2630. {
  2631. if (plci->fax_connect_info_length <= len)
  2632. plci->fax_connect_info_buffer[len] = 0;
  2633. len += 1 + plci->fax_connect_info_buffer[len];
  2634. if (plci->fax_connect_info_length <= len)
  2635. plci->fax_connect_info_buffer[len] = 0;
  2636. len += 1 + plci->fax_connect_info_buffer[len];
  2637. if ((fax_parms[7].length >= 3) && (fax_parms[7].info[1] >= 2))
  2638. plci->nsf_control_bits = GET_WORD(&fax_parms[7].info[2]);
  2639. plci->fax_connect_info_buffer[len++] = (byte)(fax_parms[7].length);
  2640. for (i = 0; i < fax_parms[7].length; i++)
  2641. plci->fax_connect_info_buffer[len++] = fax_parms[7].info[1 + i];
  2642. }
  2643. plci->fax_connect_info_length = len;
  2644. ((T30_INFO *)(plci->fax_connect_info_buffer))->code = 0;
  2645. start_internal_command(Id, plci, fax_connect_ack_command);
  2646. return false;
  2647. }
  2648. }
  2649. nl_req_ncci(plci, req, (byte)ncci);
  2650. if ((plci->ncpi_state & NCPI_VALID_CONNECT_B3_ACT)
  2651. && !(plci->ncpi_state & NCPI_CONNECT_B3_ACT_SENT))
  2652. {
  2653. if (plci->B3_prot == 4)
  2654. sendf(appl, _CONNECT_B3_ACTIVE_I, Id, 0, "s", "");
  2655. else
  2656. sendf(appl, _CONNECT_B3_ACTIVE_I, Id, 0, "S", plci->ncpi_buffer);
  2657. plci->ncpi_state |= NCPI_CONNECT_B3_ACT_SENT;
  2658. }
  2659. }
  2660. else if (plci->B3_prot == B3_RTP)
  2661. {
  2662. plci->internal_req_buffer[0] = ncpi->length + 1;
  2663. plci->internal_req_buffer[1] = UDATA_REQUEST_RTP_RECONFIGURE;
  2664. for (w = 0; w < ncpi->length; w++)
  2665. plci->internal_req_buffer[2 + w] = ncpi->info[1+w];
  2666. start_internal_command(Id, plci, rtp_connect_b3_res_command);
  2667. return false;
  2668. }
  2669. else
  2670. {
  2671. if (ncpi->length > 2) {
  2672. if (ncpi->info[1] & 1) req = N_CONNECT_ACK | N_D_BIT;
  2673. add_d(plci, (word)(ncpi->length - 3), &ncpi->info[4]);
  2674. }
  2675. nl_req_ncci(plci, req, (byte)ncci);
  2676. sendf(appl, _CONNECT_B3_ACTIVE_I, Id, 0, "s", "");
  2677. if (plci->adjust_b_restore)
  2678. {
  2679. plci->adjust_b_restore = false;
  2680. start_internal_command(Id, plci, adjust_b_restore);
  2681. }
  2682. }
  2683. return 1;
  2684. }
  2685. }
  2686. return false;
  2687. }
  2688. static byte connect_b3_a_res(dword Id, word Number, DIVA_CAPI_ADAPTER *a,
  2689. PLCI *plci, APPL *appl, API_PARSE *parms)
  2690. {
  2691. word ncci;
  2692. ncci = (word)(Id >> 16);
  2693. dbug(1, dprintf("connect_b3_a_res(ncci=0x%x)", ncci));
  2694. if (plci && ncci && (plci->State != IDLE) && (plci->State != INC_DIS_PENDING)
  2695. && (plci->State != OUTG_DIS_PENDING))
  2696. {
  2697. if (a->ncci_state[ncci] == INC_ACT_PENDING) {
  2698. a->ncci_state[ncci] = CONNECTED;
  2699. if (plci->State != INC_CON_CONNECTED_ALERT) plci->State = CONNECTED;
  2700. channel_request_xon(plci, a->ncci_ch[ncci]);
  2701. channel_xmit_xon(plci);
  2702. }
  2703. }
  2704. return false;
  2705. }
  2706. static byte disconnect_b3_req(dword Id, word Number, DIVA_CAPI_ADAPTER *a,
  2707. PLCI *plci, APPL *appl, API_PARSE *parms)
  2708. {
  2709. word Info;
  2710. word ncci;
  2711. API_PARSE *ncpi;
  2712. dbug(1, dprintf("disconnect_b3_req"));
  2713. Info = _WRONG_IDENTIFIER;
  2714. ncci = (word)(Id >> 16);
  2715. if (plci && ncci)
  2716. {
  2717. Info = _WRONG_STATE;
  2718. if ((a->ncci_state[ncci] == CONNECTED)
  2719. || (a->ncci_state[ncci] == OUTG_CON_PENDING)
  2720. || (a->ncci_state[ncci] == INC_CON_PENDING)
  2721. || (a->ncci_state[ncci] == INC_ACT_PENDING))
  2722. {
  2723. a->ncci_state[ncci] = OUTG_DIS_PENDING;
  2724. channel_request_xon(plci, a->ncci_ch[ncci]);
  2725. channel_xmit_xon(plci);
  2726. if (a->ncci[ncci].data_pending
  2727. && ((plci->B3_prot == B3_TRANSPARENT)
  2728. || (plci->B3_prot == B3_T30)
  2729. || (plci->B3_prot == B3_T30_WITH_EXTENSIONS)))
  2730. {
  2731. plci->send_disc = (byte)ncci;
  2732. plci->command = 0;
  2733. return false;
  2734. }
  2735. else
  2736. {
  2737. cleanup_ncci_data(plci, ncci);
  2738. if (plci->B3_prot == 2 || plci->B3_prot == 3)
  2739. {
  2740. ncpi = &parms[0];
  2741. if (ncpi->length > 3)
  2742. {
  2743. add_d(plci, (word)(ncpi->length - 3), (byte *)&(ncpi->info[4]));
  2744. }
  2745. }
  2746. nl_req_ncci(plci, N_DISC, (byte)ncci);
  2747. }
  2748. return 1;
  2749. }
  2750. }
  2751. sendf(appl,
  2752. _DISCONNECT_B3_R | CONFIRM,
  2753. Id,
  2754. Number,
  2755. "w", Info);
  2756. return false;
  2757. }
  2758. static byte disconnect_b3_res(dword Id, word Number, DIVA_CAPI_ADAPTER *a,
  2759. PLCI *plci, APPL *appl, API_PARSE *parms)
  2760. {
  2761. word ncci;
  2762. word i;
  2763. ncci = (word)(Id >> 16);
  2764. dbug(1, dprintf("disconnect_b3_res(ncci=0x%x", ncci));
  2765. if (plci && ncci) {
  2766. plci->requested_options_conn = 0;
  2767. plci->fax_connect_info_length = 0;
  2768. plci->ncpi_state = 0x00;
  2769. if (((plci->B3_prot != B3_T90NL) && (plci->B3_prot != B3_ISO8208) && (plci->B3_prot != B3_X25_DCE))
  2770. && ((plci->B2_prot != B2_LAPD) && (plci->B2_prot != B2_LAPD_FREE_SAPI_SEL)))
  2771. {
  2772. plci->call_dir |= CALL_DIR_FORCE_OUTG_NL;
  2773. }
  2774. for (i = 0; i < MAX_CHANNELS_PER_PLCI && plci->inc_dis_ncci_table[i] != (byte)ncci; i++);
  2775. if (i < MAX_CHANNELS_PER_PLCI) {
  2776. if (plci->channels)plci->channels--;
  2777. for (; i < MAX_CHANNELS_PER_PLCI - 1; i++) plci->inc_dis_ncci_table[i] = plci->inc_dis_ncci_table[i + 1];
  2778. plci->inc_dis_ncci_table[MAX_CHANNELS_PER_PLCI - 1] = 0;
  2779. ncci_free_receive_buffers(plci, ncci);
  2780. if ((plci->State == IDLE || plci->State == SUSPENDING) && !plci->channels) {
  2781. if (plci->State == SUSPENDING) {
  2782. sendf(plci->appl,
  2783. _FACILITY_I,
  2784. Id & 0xffffL,
  2785. 0,
  2786. "ws", (word)3, "\x03\x04\x00\x00");
  2787. sendf(plci->appl, _DISCONNECT_I, Id & 0xffffL, 0, "w", 0);
  2788. }
  2789. plci_remove(plci);
  2790. plci->State = IDLE;
  2791. }
  2792. }
  2793. else
  2794. {
  2795. if ((a->manufacturer_features & MANUFACTURER_FEATURE_FAX_PAPER_FORMATS)
  2796. && ((plci->B3_prot == 4) || (plci->B3_prot == 5))
  2797. && (a->ncci_state[ncci] == INC_DIS_PENDING))
  2798. {
  2799. ncci_free_receive_buffers(plci, ncci);
  2800. nl_req_ncci(plci, N_EDATA, (byte)ncci);
  2801. plci->adapter->ncci_state[ncci] = IDLE;
  2802. start_internal_command(Id, plci, fax_disconnect_command);
  2803. return 1;
  2804. }
  2805. }
  2806. }
  2807. return false;
  2808. }
  2809. static byte data_b3_req(dword Id, word Number, DIVA_CAPI_ADAPTER *a,
  2810. PLCI *plci, APPL *appl, API_PARSE *parms)
  2811. {
  2812. NCCI *ncci_ptr;
  2813. DATA_B3_DESC *data;
  2814. word Info;
  2815. word ncci;
  2816. word i;
  2817. dbug(1, dprintf("data_b3_req"));
  2818. Info = _WRONG_IDENTIFIER;
  2819. ncci = (word)(Id >> 16);
  2820. dbug(1, dprintf("ncci=0x%x, plci=0x%x", ncci, plci));
  2821. if (plci && ncci)
  2822. {
  2823. Info = _WRONG_STATE;
  2824. if ((a->ncci_state[ncci] == CONNECTED)
  2825. || (a->ncci_state[ncci] == INC_ACT_PENDING))
  2826. {
  2827. /* queue data */
  2828. ncci_ptr = &(a->ncci[ncci]);
  2829. i = ncci_ptr->data_out + ncci_ptr->data_pending;
  2830. if (i >= MAX_DATA_B3)
  2831. i -= MAX_DATA_B3;
  2832. data = &(ncci_ptr->DBuffer[i]);
  2833. data->Number = Number;
  2834. if ((((byte *)(parms[0].info)) >= ((byte *)(plci->msg_in_queue)))
  2835. && (((byte *)(parms[0].info)) < ((byte *)(plci->msg_in_queue)) + sizeof(plci->msg_in_queue)))
  2836. {
  2837. data->P = (byte *)(long)(*((dword *)(parms[0].info)));
  2838. }
  2839. else
  2840. data->P = TransmitBufferSet(appl, *(dword *)parms[0].info);
  2841. data->Length = GET_WORD(parms[1].info);
  2842. data->Handle = GET_WORD(parms[2].info);
  2843. data->Flags = GET_WORD(parms[3].info);
  2844. (ncci_ptr->data_pending)++;
  2845. /* check for delivery confirmation */
  2846. if (data->Flags & 0x0004)
  2847. {
  2848. i = ncci_ptr->data_ack_out + ncci_ptr->data_ack_pending;
  2849. if (i >= MAX_DATA_ACK)
  2850. i -= MAX_DATA_ACK;
  2851. ncci_ptr->DataAck[i].Number = data->Number;
  2852. ncci_ptr->DataAck[i].Handle = data->Handle;
  2853. (ncci_ptr->data_ack_pending)++;
  2854. }
  2855. send_data(plci);
  2856. return false;
  2857. }
  2858. }
  2859. if (appl)
  2860. {
  2861. if (plci)
  2862. {
  2863. if ((((byte *)(parms[0].info)) >= ((byte *)(plci->msg_in_queue)))
  2864. && (((byte *)(parms[0].info)) < ((byte *)(plci->msg_in_queue)) + sizeof(plci->msg_in_queue)))
  2865. {
  2866. TransmitBufferFree(appl, (byte *)(long)(*((dword *)(parms[0].info))));
  2867. }
  2868. }
  2869. sendf(appl,
  2870. _DATA_B3_R | CONFIRM,
  2871. Id,
  2872. Number,
  2873. "ww", GET_WORD(parms[2].info), Info);
  2874. }
  2875. return false;
  2876. }
  2877. static byte data_b3_res(dword Id, word Number, DIVA_CAPI_ADAPTER *a,
  2878. PLCI *plci, APPL *appl, API_PARSE *parms)
  2879. {
  2880. word n;
  2881. word ncci;
  2882. word NCCIcode;
  2883. dbug(1, dprintf("data_b3_res"));
  2884. ncci = (word)(Id >> 16);
  2885. if (plci && ncci) {
  2886. n = GET_WORD(parms[0].info);
  2887. dbug(1, dprintf("free(%d)", n));
  2888. NCCIcode = ncci | (((word) a->Id) << 8);
  2889. if (n < appl->MaxBuffer &&
  2890. appl->DataNCCI[n] == NCCIcode &&
  2891. (byte)(appl->DataFlags[n] >> 8) == plci->Id) {
  2892. dbug(1, dprintf("found"));
  2893. appl->DataNCCI[n] = 0;
  2894. if (channel_can_xon(plci, a->ncci_ch[ncci])) {
  2895. channel_request_xon(plci, a->ncci_ch[ncci]);
  2896. }
  2897. channel_xmit_xon(plci);
  2898. if (appl->DataFlags[n] & 4) {
  2899. nl_req_ncci(plci, N_DATA_ACK, (byte)ncci);
  2900. return 1;
  2901. }
  2902. }
  2903. }
  2904. return false;
  2905. }
  2906. static byte reset_b3_req(dword Id, word Number, DIVA_CAPI_ADAPTER *a,
  2907. PLCI *plci, APPL *appl, API_PARSE *parms)
  2908. {
  2909. word Info;
  2910. word ncci;
  2911. dbug(1, dprintf("reset_b3_req"));
  2912. Info = _WRONG_IDENTIFIER;
  2913. ncci = (word)(Id >> 16);
  2914. if (plci && ncci)
  2915. {
  2916. Info = _WRONG_STATE;
  2917. switch (plci->B3_prot)
  2918. {
  2919. case B3_ISO8208:
  2920. case B3_X25_DCE:
  2921. if (a->ncci_state[ncci] == CONNECTED)
  2922. {
  2923. nl_req_ncci(plci, N_RESET, (byte)ncci);
  2924. send_req(plci);
  2925. Info = GOOD;
  2926. }
  2927. break;
  2928. case B3_TRANSPARENT:
  2929. if (a->ncci_state[ncci] == CONNECTED)
  2930. {
  2931. start_internal_command(Id, plci, reset_b3_command);
  2932. Info = GOOD;
  2933. }
  2934. break;
  2935. }
  2936. }
  2937. /* reset_b3 must result in a reset_b3_con & reset_b3_Ind */
  2938. sendf(appl,
  2939. _RESET_B3_R | CONFIRM,
  2940. Id,
  2941. Number,
  2942. "w", Info);
  2943. return false;
  2944. }
  2945. static byte reset_b3_res(dword Id, word Number, DIVA_CAPI_ADAPTER *a,
  2946. PLCI *plci, APPL *appl, API_PARSE *parms)
  2947. {
  2948. word ncci;
  2949. dbug(1, dprintf("reset_b3_res"));
  2950. ncci = (word)(Id >> 16);
  2951. if (plci && ncci) {
  2952. switch (plci->B3_prot)
  2953. {
  2954. case B3_ISO8208:
  2955. case B3_X25_DCE:
  2956. if (a->ncci_state[ncci] == INC_RES_PENDING)
  2957. {
  2958. a->ncci_state[ncci] = CONNECTED;
  2959. nl_req_ncci(plci, N_RESET_ACK, (byte)ncci);
  2960. return true;
  2961. }
  2962. break;
  2963. }
  2964. }
  2965. return false;
  2966. }
  2967. static byte connect_b3_t90_a_res(dword Id, word Number, DIVA_CAPI_ADAPTER *a,
  2968. PLCI *plci, APPL *appl, API_PARSE *parms)
  2969. {
  2970. word ncci;
  2971. API_PARSE *ncpi;
  2972. byte req;
  2973. dbug(1, dprintf("connect_b3_t90_a_res"));
  2974. ncci = (word)(Id >> 16);
  2975. if (plci && ncci) {
  2976. if (a->ncci_state[ncci] == INC_ACT_PENDING) {
  2977. a->ncci_state[ncci] = CONNECTED;
  2978. }
  2979. else if (a->ncci_state[ncci] == INC_CON_PENDING) {
  2980. a->ncci_state[ncci] = CONNECTED;
  2981. req = N_CONNECT_ACK;
  2982. /* parms[0]==0 for CAPI original message definition! */
  2983. if (parms[0].info) {
  2984. ncpi = &parms[1];
  2985. if (ncpi->length > 2) {
  2986. if (ncpi->info[1] & 1) req = N_CONNECT_ACK | N_D_BIT;
  2987. add_d(plci, (word)(ncpi->length - 3), &ncpi->info[4]);
  2988. }
  2989. }
  2990. nl_req_ncci(plci, req, (byte)ncci);
  2991. return 1;
  2992. }
  2993. }
  2994. return false;
  2995. }
  2996. static byte select_b_req(dword Id, word Number, DIVA_CAPI_ADAPTER *a,
  2997. PLCI *plci, APPL *appl, API_PARSE *msg)
  2998. {
  2999. word Info = 0;
  3000. word i;
  3001. byte tel;
  3002. API_PARSE bp_parms[7];
  3003. if (!plci || !msg)
  3004. {
  3005. Info = _WRONG_IDENTIFIER;
  3006. }
  3007. else
  3008. {
  3009. dbug(1, dprintf("select_b_req[%d],PLCI=0x%x,Tel=0x%x,NL=0x%x,appl=0x%x,sstate=0x%x",
  3010. msg->length, plci->Id, plci->tel, plci->NL.Id, plci->appl, plci->SuppState));
  3011. dbug(1, dprintf("PlciState=0x%x", plci->State));
  3012. for (i = 0; i < 7; i++) bp_parms[i].length = 0;
  3013. /* check if no channel is open, no B3 connected only */
  3014. if ((plci->State == IDLE) || (plci->State == OUTG_DIS_PENDING) || (plci->State == INC_DIS_PENDING)
  3015. || (plci->SuppState != IDLE) || plci->channels || plci->nl_remove_id)
  3016. {
  3017. Info = _WRONG_STATE;
  3018. }
  3019. /* check message format and fill bp_parms pointer */
  3020. else if (msg->length && api_parse(&msg->info[1], (word)msg->length, "wwwsss", bp_parms))
  3021. {
  3022. Info = _WRONG_MESSAGE_FORMAT;
  3023. }
  3024. else
  3025. {
  3026. if ((plci->State == INC_CON_PENDING) || (plci->State == INC_CON_ALERT)) /* send alert tone inband to the network, */
  3027. { /* e.g. Qsig or RBS or Cornet-N or xess PRI */
  3028. if (Id & EXT_CONTROLLER)
  3029. {
  3030. sendf(appl, _SELECT_B_REQ | CONFIRM, Id, Number, "w", 0x2002); /* wrong controller */
  3031. return 0;
  3032. }
  3033. plci->State = INC_CON_CONNECTED_ALERT;
  3034. plci->appl = appl;
  3035. clear_c_ind_mask_bit(plci, (word)(appl->Id - 1));
  3036. dump_c_ind_mask(plci);
  3037. for (i = 0; i < max_appl; i++) /* disconnect the other appls */
  3038. { /* its quasi a connect */
  3039. if (test_c_ind_mask_bit(plci, i))
  3040. sendf(&application[i], _DISCONNECT_I, Id, 0, "w", _OTHER_APPL_CONNECTED);
  3041. }
  3042. }
  3043. api_save_msg(msg, "s", &plci->saved_msg);
  3044. tel = plci->tel;
  3045. if (Id & EXT_CONTROLLER)
  3046. {
  3047. if (tel) /* external controller in use by this PLCI */
  3048. {
  3049. if (a->AdvSignalAppl && a->AdvSignalAppl != appl)
  3050. {
  3051. dbug(1, dprintf("Ext_Ctrl in use 1"));
  3052. Info = _WRONG_STATE;
  3053. }
  3054. }
  3055. else /* external controller NOT in use by this PLCI ? */
  3056. {
  3057. if (a->AdvSignalPLCI)
  3058. {
  3059. dbug(1, dprintf("Ext_Ctrl in use 2"));
  3060. Info = _WRONG_STATE;
  3061. }
  3062. else /* activate the codec */
  3063. {
  3064. dbug(1, dprintf("Ext_Ctrl start"));
  3065. if (AdvCodecSupport(a, plci, appl, 0))
  3066. {
  3067. dbug(1, dprintf("Error in codec procedures"));
  3068. Info = _WRONG_STATE;
  3069. }
  3070. else if (plci->spoofed_msg == SPOOFING_REQUIRED) /* wait until codec is active */
  3071. {
  3072. plci->spoofed_msg = AWAITING_SELECT_B;
  3073. plci->internal_command = BLOCK_PLCI; /* lock other commands */
  3074. plci->command = 0;
  3075. dbug(1, dprintf("continue if codec loaded"));
  3076. return false;
  3077. }
  3078. }
  3079. }
  3080. }
  3081. else /* external controller bit is OFF */
  3082. {
  3083. if (tel) /* external controller in use, need to switch off */
  3084. {
  3085. if (a->AdvSignalAppl == appl)
  3086. {
  3087. CodecIdCheck(a, plci);
  3088. plci->tel = 0;
  3089. plci->adv_nl = 0;
  3090. dbug(1, dprintf("Ext_Ctrl disable"));
  3091. }
  3092. else
  3093. {
  3094. dbug(1, dprintf("Ext_Ctrl not requested"));
  3095. }
  3096. }
  3097. }
  3098. if (!Info)
  3099. {
  3100. if (plci->call_dir & CALL_DIR_OUT)
  3101. plci->call_dir = CALL_DIR_OUT | CALL_DIR_ORIGINATE;
  3102. else if (plci->call_dir & CALL_DIR_IN)
  3103. plci->call_dir = CALL_DIR_IN | CALL_DIR_ANSWER;
  3104. start_internal_command(Id, plci, select_b_command);
  3105. return false;
  3106. }
  3107. }
  3108. }
  3109. sendf(appl, _SELECT_B_REQ | CONFIRM, Id, Number, "w", Info);
  3110. return false;
  3111. }
  3112. static byte manufacturer_req(dword Id, word Number, DIVA_CAPI_ADAPTER *a,
  3113. PLCI *plci, APPL *appl, API_PARSE *parms)
  3114. {
  3115. word command;
  3116. word i;
  3117. word ncci;
  3118. API_PARSE *m;
  3119. API_PARSE m_parms[5];
  3120. word codec;
  3121. byte req;
  3122. byte ch;
  3123. byte dir;
  3124. static byte chi[2] = {0x01, 0x00};
  3125. static byte lli[2] = {0x01, 0x00};
  3126. static byte codec_cai[2] = {0x01, 0x01};
  3127. static byte null_msg = {0};
  3128. static API_PARSE null_parms = { 0, &null_msg };
  3129. PLCI *v_plci;
  3130. word Info = 0;
  3131. dbug(1, dprintf("manufacturer_req"));
  3132. for (i = 0; i < 5; i++) m_parms[i].length = 0;
  3133. if (GET_DWORD(parms[0].info) != _DI_MANU_ID) {
  3134. Info = _WRONG_MESSAGE_FORMAT;
  3135. }
  3136. command = GET_WORD(parms[1].info);
  3137. m = &parms[2];
  3138. if (!Info)
  3139. {
  3140. switch (command) {
  3141. case _DI_ASSIGN_PLCI:
  3142. if (api_parse(&m->info[1], (word)m->length, "wbbs", m_parms)) {
  3143. Info = _WRONG_MESSAGE_FORMAT;
  3144. break;
  3145. }
  3146. codec = GET_WORD(m_parms[0].info);
  3147. ch = m_parms[1].info[0];
  3148. dir = m_parms[2].info[0];
  3149. if ((i = get_plci(a))) {
  3150. plci = &a->plci[i - 1];
  3151. plci->appl = appl;
  3152. plci->command = _MANUFACTURER_R;
  3153. plci->m_command = command;
  3154. plci->number = Number;
  3155. plci->State = LOCAL_CONNECT;
  3156. Id = (((word)plci->Id << 8) | plci->adapter->Id | 0x80);
  3157. dbug(1, dprintf("ManCMD,plci=0x%x", Id));
  3158. if ((ch == 1 || ch == 2) && (dir <= 2)) {
  3159. chi[1] = (byte)(0x80 | ch);
  3160. lli[1] = 0;
  3161. plci->call_dir = CALL_DIR_OUT | CALL_DIR_ORIGINATE;
  3162. switch (codec)
  3163. {
  3164. case 0:
  3165. Info = add_b1(plci, &m_parms[3], 0, 0);
  3166. break;
  3167. case 1:
  3168. add_p(plci, CAI, codec_cai);
  3169. break;
  3170. /* manual 'swich on' to the codec support without signalling */
  3171. /* first 'assign plci' with this function, then use */
  3172. case 2:
  3173. if (AdvCodecSupport(a, plci, appl, 0)) {
  3174. Info = _RESOURCE_ERROR;
  3175. }
  3176. else {
  3177. Info = add_b1(plci, &null_parms, 0, B1_FACILITY_LOCAL);
  3178. lli[1] = 0x10; /* local call codec stream */
  3179. }
  3180. break;
  3181. }
  3182. plci->State = LOCAL_CONNECT;
  3183. plci->manufacturer = true;
  3184. plci->command = _MANUFACTURER_R;
  3185. plci->m_command = command;
  3186. plci->number = Number;
  3187. if (!Info)
  3188. {
  3189. add_p(plci, LLI, lli);
  3190. add_p(plci, CHI, chi);
  3191. add_p(plci, UID, "\x06\x43\x61\x70\x69\x32\x30");
  3192. sig_req(plci, ASSIGN, DSIG_ID);
  3193. if (!codec)
  3194. {
  3195. Info = add_b23(plci, &m_parms[3]);
  3196. if (!Info)
  3197. {
  3198. nl_req_ncci(plci, ASSIGN, 0);
  3199. send_req(plci);
  3200. }
  3201. }
  3202. if (!Info)
  3203. {
  3204. dbug(1, dprintf("dir=0x%x,spoof=0x%x", dir, plci->spoofed_msg));
  3205. if (plci->spoofed_msg == SPOOFING_REQUIRED)
  3206. {
  3207. api_save_msg(m_parms, "wbbs", &plci->saved_msg);
  3208. plci->spoofed_msg = AWAITING_MANUF_CON;
  3209. plci->internal_command = BLOCK_PLCI; /* reject other req meanwhile */
  3210. plci->command = 0;
  3211. send_req(plci);
  3212. return false;
  3213. }
  3214. if (dir == 1) {
  3215. sig_req(plci, CALL_REQ, 0);
  3216. }
  3217. else if (!dir) {
  3218. sig_req(plci, LISTEN_REQ, 0);
  3219. }
  3220. send_req(plci);
  3221. }
  3222. else
  3223. {
  3224. sendf(appl,
  3225. _MANUFACTURER_R | CONFIRM,
  3226. Id,
  3227. Number,
  3228. "dww", _DI_MANU_ID, command, Info);
  3229. return 2;
  3230. }
  3231. }
  3232. }
  3233. }
  3234. else Info = _OUT_OF_PLCI;
  3235. break;
  3236. case _DI_IDI_CTRL:
  3237. if (!plci)
  3238. {
  3239. Info = _WRONG_IDENTIFIER;
  3240. break;
  3241. }
  3242. if (api_parse(&m->info[1], (word)m->length, "bs", m_parms)) {
  3243. Info = _WRONG_MESSAGE_FORMAT;
  3244. break;
  3245. }
  3246. req = m_parms[0].info[0];
  3247. plci->command = _MANUFACTURER_R;
  3248. plci->m_command = command;
  3249. plci->number = Number;
  3250. if (req == CALL_REQ)
  3251. {
  3252. plci->b_channel = getChannel(&m_parms[1]);
  3253. mixer_set_bchannel_id_esc(plci, plci->b_channel);
  3254. if (plci->spoofed_msg == SPOOFING_REQUIRED)
  3255. {
  3256. plci->spoofed_msg = CALL_REQ | AWAITING_MANUF_CON;
  3257. plci->internal_command = BLOCK_PLCI; /* reject other req meanwhile */
  3258. plci->command = 0;
  3259. break;
  3260. }
  3261. }
  3262. else if (req == LAW_REQ)
  3263. {
  3264. plci->cr_enquiry = true;
  3265. }
  3266. add_ss(plci, FTY, &m_parms[1]);
  3267. sig_req(plci, req, 0);
  3268. send_req(plci);
  3269. if (req == HANGUP)
  3270. {
  3271. if (plci->NL.Id && !plci->nl_remove_id)
  3272. {
  3273. if (plci->channels)
  3274. {
  3275. for (ncci = 1; ncci < MAX_NCCI + 1; ncci++)
  3276. {
  3277. if ((a->ncci_plci[ncci] == plci->Id) && (a->ncci_state[ncci] == CONNECTED))
  3278. {
  3279. a->ncci_state[ncci] = OUTG_DIS_PENDING;
  3280. cleanup_ncci_data(plci, ncci);
  3281. nl_req_ncci(plci, N_DISC, (byte)ncci);
  3282. }
  3283. }
  3284. }
  3285. mixer_remove(plci);
  3286. nl_req_ncci(plci, REMOVE, 0);
  3287. send_req(plci);
  3288. }
  3289. }
  3290. break;
  3291. case _DI_SIG_CTRL:
  3292. /* signalling control for loop activation B-channel */
  3293. if (!plci)
  3294. {
  3295. Info = _WRONG_IDENTIFIER;
  3296. break;
  3297. }
  3298. if (m->length) {
  3299. plci->command = _MANUFACTURER_R;
  3300. plci->number = Number;
  3301. add_ss(plci, FTY, m);
  3302. sig_req(plci, SIG_CTRL, 0);
  3303. send_req(plci);
  3304. }
  3305. else Info = _WRONG_MESSAGE_FORMAT;
  3306. break;
  3307. case _DI_RXT_CTRL:
  3308. /* activation control for receiver/transmitter B-channel */
  3309. if (!plci)
  3310. {
  3311. Info = _WRONG_IDENTIFIER;
  3312. break;
  3313. }
  3314. if (m->length) {
  3315. plci->command = _MANUFACTURER_R;
  3316. plci->number = Number;
  3317. add_ss(plci, FTY, m);
  3318. sig_req(plci, DSP_CTRL, 0);
  3319. send_req(plci);
  3320. }
  3321. else Info = _WRONG_MESSAGE_FORMAT;
  3322. break;
  3323. case _DI_ADV_CODEC:
  3324. case _DI_DSP_CTRL:
  3325. /* TEL_CTRL commands to support non standard adjustments: */
  3326. /* Ring on/off, Handset micro volume, external micro vol. */
  3327. /* handset+external speaker volume, receiver+transm. gain,*/
  3328. /* handsfree on (hookinfo off), set mixer command */
  3329. if (command == _DI_ADV_CODEC)
  3330. {
  3331. if (!a->AdvCodecPLCI) {
  3332. Info = _WRONG_STATE;
  3333. break;
  3334. }
  3335. v_plci = a->AdvCodecPLCI;
  3336. }
  3337. else
  3338. {
  3339. if (plci
  3340. && (m->length >= 3)
  3341. && (m->info[1] == 0x1c)
  3342. && (m->info[2] >= 1))
  3343. {
  3344. if (m->info[3] == DSP_CTRL_OLD_SET_MIXER_COEFFICIENTS)
  3345. {
  3346. if ((plci->tel != ADV_VOICE) || (plci != a->AdvSignalPLCI))
  3347. {
  3348. Info = _WRONG_STATE;
  3349. break;
  3350. }
  3351. a->adv_voice_coef_length = m->info[2] - 1;
  3352. if (a->adv_voice_coef_length > m->length - 3)
  3353. a->adv_voice_coef_length = (byte)(m->length - 3);
  3354. if (a->adv_voice_coef_length > ADV_VOICE_COEF_BUFFER_SIZE)
  3355. a->adv_voice_coef_length = ADV_VOICE_COEF_BUFFER_SIZE;
  3356. for (i = 0; i < a->adv_voice_coef_length; i++)
  3357. a->adv_voice_coef_buffer[i] = m->info[4 + i];
  3358. if (plci->B1_facilities & B1_FACILITY_VOICE)
  3359. adv_voice_write_coefs(plci, ADV_VOICE_WRITE_UPDATE);
  3360. break;
  3361. }
  3362. else if (m->info[3] == DSP_CTRL_SET_DTMF_PARAMETERS)
  3363. {
  3364. if (!(a->manufacturer_features & MANUFACTURER_FEATURE_DTMF_PARAMETERS))
  3365. {
  3366. Info = _FACILITY_NOT_SUPPORTED;
  3367. break;
  3368. }
  3369. plci->dtmf_parameter_length = m->info[2] - 1;
  3370. if (plci->dtmf_parameter_length > m->length - 3)
  3371. plci->dtmf_parameter_length = (byte)(m->length - 3);
  3372. if (plci->dtmf_parameter_length > DTMF_PARAMETER_BUFFER_SIZE)
  3373. plci->dtmf_parameter_length = DTMF_PARAMETER_BUFFER_SIZE;
  3374. for (i = 0; i < plci->dtmf_parameter_length; i++)
  3375. plci->dtmf_parameter_buffer[i] = m->info[4 + i];
  3376. if (plci->B1_facilities & B1_FACILITY_DTMFR)
  3377. dtmf_parameter_write(plci);
  3378. break;
  3379. }
  3380. }
  3381. v_plci = plci;
  3382. }
  3383. if (!v_plci)
  3384. {
  3385. Info = _WRONG_IDENTIFIER;
  3386. break;
  3387. }
  3388. if (m->length) {
  3389. add_ss(v_plci, FTY, m);
  3390. sig_req(v_plci, TEL_CTRL, 0);
  3391. send_req(v_plci);
  3392. }
  3393. else Info = _WRONG_MESSAGE_FORMAT;
  3394. break;
  3395. case _DI_OPTIONS_REQUEST:
  3396. if (api_parse(&m->info[1], (word)m->length, "d", m_parms)) {
  3397. Info = _WRONG_MESSAGE_FORMAT;
  3398. break;
  3399. }
  3400. if (GET_DWORD(m_parms[0].info) & ~a->man_profile.private_options)
  3401. {
  3402. Info = _FACILITY_NOT_SUPPORTED;
  3403. break;
  3404. }
  3405. a->requested_options_table[appl->Id - 1] = GET_DWORD(m_parms[0].info);
  3406. break;
  3407. default:
  3408. Info = _WRONG_MESSAGE_FORMAT;
  3409. break;
  3410. }
  3411. }
  3412. sendf(appl,
  3413. _MANUFACTURER_R | CONFIRM,
  3414. Id,
  3415. Number,
  3416. "dww", _DI_MANU_ID, command, Info);
  3417. return false;
  3418. }
  3419. static byte manufacturer_res(dword Id, word Number, DIVA_CAPI_ADAPTER *a,
  3420. PLCI *plci, APPL *appl, API_PARSE *msg)
  3421. {
  3422. word indication;
  3423. API_PARSE m_parms[3];
  3424. API_PARSE *ncpi;
  3425. API_PARSE fax_parms[9];
  3426. word i;
  3427. byte len;
  3428. dbug(1, dprintf("manufacturer_res"));
  3429. if ((msg[0].length == 0)
  3430. || (msg[1].length == 0)
  3431. || (GET_DWORD(msg[0].info) != _DI_MANU_ID))
  3432. {
  3433. return false;
  3434. }
  3435. indication = GET_WORD(msg[1].info);
  3436. switch (indication)
  3437. {
  3438. case _DI_NEGOTIATE_B3:
  3439. if (!plci)
  3440. break;
  3441. if (((plci->B3_prot != 4) && (plci->B3_prot != 5))
  3442. || !(plci->ncpi_state & NCPI_NEGOTIATE_B3_SENT))
  3443. {
  3444. dbug(1, dprintf("wrong state for NEGOTIATE_B3 parameters"));
  3445. break;
  3446. }
  3447. if (api_parse(&msg[2].info[1], msg[2].length, "ws", m_parms))
  3448. {
  3449. dbug(1, dprintf("wrong format in NEGOTIATE_B3 parameters"));
  3450. break;
  3451. }
  3452. ncpi = &m_parms[1];
  3453. len = offsetof(T30_INFO, station_id) + T30_MAX_STATION_ID_LENGTH;
  3454. if (plci->fax_connect_info_length < len)
  3455. {
  3456. ((T30_INFO *)(plci->fax_connect_info_buffer))->station_id_len = 0;
  3457. ((T30_INFO *)(plci->fax_connect_info_buffer))->head_line_len = 0;
  3458. }
  3459. if (api_parse(&ncpi->info[1], ncpi->length, "wwwwssss", fax_parms))
  3460. {
  3461. dbug(1, dprintf("non-standard facilities info missing or wrong format"));
  3462. }
  3463. else
  3464. {
  3465. if (plci->fax_connect_info_length <= len)
  3466. plci->fax_connect_info_buffer[len] = 0;
  3467. len += 1 + plci->fax_connect_info_buffer[len];
  3468. if (plci->fax_connect_info_length <= len)
  3469. plci->fax_connect_info_buffer[len] = 0;
  3470. len += 1 + plci->fax_connect_info_buffer[len];
  3471. if ((fax_parms[7].length >= 3) && (fax_parms[7].info[1] >= 2))
  3472. plci->nsf_control_bits = GET_WORD(&fax_parms[7].info[2]);
  3473. plci->fax_connect_info_buffer[len++] = (byte)(fax_parms[7].length);
  3474. for (i = 0; i < fax_parms[7].length; i++)
  3475. plci->fax_connect_info_buffer[len++] = fax_parms[7].info[1 + i];
  3476. }
  3477. plci->fax_connect_info_length = len;
  3478. plci->fax_edata_ack_length = plci->fax_connect_info_length;
  3479. start_internal_command(Id, plci, fax_edata_ack_command);
  3480. break;
  3481. }
  3482. return false;
  3483. }
  3484. /*------------------------------------------------------------------*/
  3485. /* IDI callback function */
  3486. /*------------------------------------------------------------------*/
  3487. void callback(ENTITY *e)
  3488. {
  3489. DIVA_CAPI_ADAPTER *a;
  3490. APPL *appl;
  3491. PLCI *plci;
  3492. CAPI_MSG *m;
  3493. word i, j;
  3494. byte rc;
  3495. byte ch;
  3496. byte req;
  3497. byte global_req;
  3498. int no_cancel_rc;
  3499. dbug(1, dprintf("%x:CB(%x:Req=%x,Rc=%x,Ind=%x)",
  3500. (e->user[0] + 1) & 0x7fff, e->Id, e->Req, e->Rc, e->Ind));
  3501. a = &(adapter[(byte)e->user[0]]);
  3502. plci = &(a->plci[e->user[1]]);
  3503. no_cancel_rc = DIVA_CAPI_SUPPORTS_NO_CANCEL(a);
  3504. /*
  3505. If new protocol code and new XDI is used then CAPI should work
  3506. fully in accordance with IDI cpec an look on callback field instead
  3507. of Rc field for return codes.
  3508. */
  3509. if (((e->complete == 0xff) && no_cancel_rc) ||
  3510. (e->Rc && !no_cancel_rc)) {
  3511. rc = e->Rc;
  3512. ch = e->RcCh;
  3513. req = e->Req;
  3514. e->Rc = 0;
  3515. if (e->user[0] & 0x8000)
  3516. {
  3517. /*
  3518. If REMOVE request was sent then we have to wait until
  3519. return code with Id set to zero arrives.
  3520. All other return codes should be ignored.
  3521. */
  3522. if (req == REMOVE)
  3523. {
  3524. if (e->Id)
  3525. {
  3526. dbug(1, dprintf("cancel RC in REMOVE state"));
  3527. return;
  3528. }
  3529. channel_flow_control_remove(plci);
  3530. for (i = 0; i < 256; i++)
  3531. {
  3532. if (a->FlowControlIdTable[i] == plci->nl_remove_id)
  3533. a->FlowControlIdTable[i] = 0;
  3534. }
  3535. plci->nl_remove_id = 0;
  3536. if (plci->rx_dma_descriptor > 0) {
  3537. diva_free_dma_descriptor(plci, plci->rx_dma_descriptor - 1);
  3538. plci->rx_dma_descriptor = 0;
  3539. }
  3540. }
  3541. if (rc == OK_FC)
  3542. {
  3543. a->FlowControlIdTable[ch] = e->Id;
  3544. a->FlowControlSkipTable[ch] = 0;
  3545. a->ch_flow_control[ch] |= N_OK_FC_PENDING;
  3546. a->ch_flow_plci[ch] = plci->Id;
  3547. plci->nl_req = 0;
  3548. }
  3549. else
  3550. {
  3551. /*
  3552. Cancel return codes self, if feature was requested
  3553. */
  3554. if (no_cancel_rc && (a->FlowControlIdTable[ch] == e->Id) && e->Id) {
  3555. a->FlowControlIdTable[ch] = 0;
  3556. if ((rc == OK) && a->FlowControlSkipTable[ch]) {
  3557. dbug(3, dprintf("XDI CAPI: RC cancelled Id:0x02, Ch:%02x", e->Id, ch));
  3558. return;
  3559. }
  3560. }
  3561. if (a->ch_flow_control[ch] & N_OK_FC_PENDING)
  3562. {
  3563. a->ch_flow_control[ch] &= ~N_OK_FC_PENDING;
  3564. if (ch == e->ReqCh)
  3565. plci->nl_req = 0;
  3566. }
  3567. else
  3568. plci->nl_req = 0;
  3569. }
  3570. if (plci->nl_req)
  3571. control_rc(plci, 0, rc, ch, 0, true);
  3572. else
  3573. {
  3574. if (req == N_XON)
  3575. {
  3576. channel_x_on(plci, ch);
  3577. if (plci->internal_command)
  3578. control_rc(plci, req, rc, ch, 0, true);
  3579. }
  3580. else
  3581. {
  3582. if (plci->nl_global_req)
  3583. {
  3584. global_req = plci->nl_global_req;
  3585. plci->nl_global_req = 0;
  3586. if (rc != ASSIGN_OK) {
  3587. e->Id = 0;
  3588. if (plci->rx_dma_descriptor > 0) {
  3589. diva_free_dma_descriptor(plci, plci->rx_dma_descriptor - 1);
  3590. plci->rx_dma_descriptor = 0;
  3591. }
  3592. }
  3593. channel_xmit_xon(plci);
  3594. control_rc(plci, 0, rc, ch, global_req, true);
  3595. }
  3596. else if (plci->data_sent)
  3597. {
  3598. channel_xmit_xon(plci);
  3599. plci->data_sent = false;
  3600. plci->NL.XNum = 1;
  3601. data_rc(plci, ch);
  3602. if (plci->internal_command)
  3603. control_rc(plci, req, rc, ch, 0, true);
  3604. }
  3605. else
  3606. {
  3607. channel_xmit_xon(plci);
  3608. control_rc(plci, req, rc, ch, 0, true);
  3609. }
  3610. }
  3611. }
  3612. }
  3613. else
  3614. {
  3615. /*
  3616. If REMOVE request was sent then we have to wait until
  3617. return code with Id set to zero arrives.
  3618. All other return codes should be ignored.
  3619. */
  3620. if (req == REMOVE)
  3621. {
  3622. if (e->Id)
  3623. {
  3624. dbug(1, dprintf("cancel RC in REMOVE state"));
  3625. return;
  3626. }
  3627. plci->sig_remove_id = 0;
  3628. }
  3629. plci->sig_req = 0;
  3630. if (plci->sig_global_req)
  3631. {
  3632. global_req = plci->sig_global_req;
  3633. plci->sig_global_req = 0;
  3634. if (rc != ASSIGN_OK)
  3635. e->Id = 0;
  3636. channel_xmit_xon(plci);
  3637. control_rc(plci, 0, rc, ch, global_req, false);
  3638. }
  3639. else
  3640. {
  3641. channel_xmit_xon(plci);
  3642. control_rc(plci, req, rc, ch, 0, false);
  3643. }
  3644. }
  3645. /*
  3646. Again: in accordance with IDI spec Rc and Ind can't be delivered in the
  3647. same callback. Also if new XDI and protocol code used then jump
  3648. direct to finish.
  3649. */
  3650. if (no_cancel_rc) {
  3651. channel_xmit_xon(plci);
  3652. goto capi_callback_suffix;
  3653. }
  3654. }
  3655. channel_xmit_xon(plci);
  3656. if (e->Ind) {
  3657. if (e->user[0] & 0x8000) {
  3658. byte Ind = e->Ind & 0x0f;
  3659. byte Ch = e->IndCh;
  3660. if (((Ind == N_DISC) || (Ind == N_DISC_ACK)) &&
  3661. (a->ch_flow_plci[Ch] == plci->Id)) {
  3662. if (a->ch_flow_control[Ch] & N_RX_FLOW_CONTROL_MASK) {
  3663. dbug(3, dprintf("XDI CAPI: I: pending N-XON Ch:%02x", Ch));
  3664. }
  3665. a->ch_flow_control[Ch] &= ~N_RX_FLOW_CONTROL_MASK;
  3666. }
  3667. nl_ind(plci);
  3668. if ((e->RNR != 1) &&
  3669. (a->ch_flow_plci[Ch] == plci->Id) &&
  3670. (a->ch_flow_control[Ch] & N_RX_FLOW_CONTROL_MASK)) {
  3671. a->ch_flow_control[Ch] &= ~N_RX_FLOW_CONTROL_MASK;
  3672. dbug(3, dprintf("XDI CAPI: I: remove faked N-XON Ch:%02x", Ch));
  3673. }
  3674. } else {
  3675. sig_ind(plci);
  3676. }
  3677. e->Ind = 0;
  3678. }
  3679. capi_callback_suffix:
  3680. while (!plci->req_in
  3681. && !plci->internal_command
  3682. && (plci->msg_in_write_pos != plci->msg_in_read_pos))
  3683. {
  3684. j = (plci->msg_in_read_pos == plci->msg_in_wrap_pos) ? 0 : plci->msg_in_read_pos;
  3685. i = (((CAPI_MSG *)(&((byte *)(plci->msg_in_queue))[j]))->header.length + 3) & 0xfffc;
  3686. m = (CAPI_MSG *)(&((byte *)(plci->msg_in_queue))[j]);
  3687. appl = *((APPL **)(&((byte *)(plci->msg_in_queue))[j + i]));
  3688. dbug(1, dprintf("dequeue msg(0x%04x) - write=%d read=%d wrap=%d",
  3689. m->header.command, plci->msg_in_write_pos, plci->msg_in_read_pos, plci->msg_in_wrap_pos));
  3690. if (plci->msg_in_read_pos == plci->msg_in_wrap_pos)
  3691. {
  3692. plci->msg_in_wrap_pos = MSG_IN_QUEUE_SIZE;
  3693. plci->msg_in_read_pos = i + MSG_IN_OVERHEAD;
  3694. }
  3695. else
  3696. {
  3697. plci->msg_in_read_pos = j + i + MSG_IN_OVERHEAD;
  3698. }
  3699. if (plci->msg_in_read_pos == plci->msg_in_write_pos)
  3700. {
  3701. plci->msg_in_write_pos = MSG_IN_QUEUE_SIZE;
  3702. plci->msg_in_read_pos = MSG_IN_QUEUE_SIZE;
  3703. }
  3704. else if (plci->msg_in_read_pos == plci->msg_in_wrap_pos)
  3705. {
  3706. plci->msg_in_read_pos = MSG_IN_QUEUE_SIZE;
  3707. plci->msg_in_wrap_pos = MSG_IN_QUEUE_SIZE;
  3708. }
  3709. i = api_put(appl, m);
  3710. if (i != 0)
  3711. {
  3712. if (m->header.command == _DATA_B3_R)
  3713. TransmitBufferFree(appl, (byte *)(long)(m->info.data_b3_req.Data));
  3714. dbug(1, dprintf("Error 0x%04x from msg(0x%04x)", i, m->header.command));
  3715. break;
  3716. }
  3717. if (plci->li_notify_update)
  3718. {
  3719. plci->li_notify_update = false;
  3720. mixer_notify_update(plci, false);
  3721. }
  3722. }
  3723. send_data(plci);
  3724. send_req(plci);
  3725. }
  3726. static void control_rc(PLCI *plci, byte req, byte rc, byte ch, byte global_req,
  3727. byte nl_rc)
  3728. {
  3729. dword Id;
  3730. dword rId;
  3731. word Number;
  3732. word Info = 0;
  3733. word i;
  3734. word ncci;
  3735. DIVA_CAPI_ADAPTER *a;
  3736. APPL *appl;
  3737. PLCI *rplci;
  3738. byte SSparms[] = "\x05\x00\x00\x02\x00\x00";
  3739. byte SSstruct[] = "\x09\x00\x00\x06\x00\x00\x00\x00\x00\x00";
  3740. if (!plci) {
  3741. dbug(0, dprintf("A: control_rc, no plci %02x:%02x:%02x:%02x:%02x", req, rc, ch, global_req, nl_rc));
  3742. return;
  3743. }
  3744. dbug(1, dprintf("req0_in/out=%d/%d", plci->req_in, plci->req_out));
  3745. if (plci->req_in != plci->req_out)
  3746. {
  3747. if (nl_rc || (global_req != ASSIGN) || (rc == ASSIGN_OK))
  3748. {
  3749. dbug(1, dprintf("req_1return"));
  3750. return;
  3751. }
  3752. /* cancel outstanding request on the PLCI after SIG ASSIGN failure */
  3753. }
  3754. plci->req_in = plci->req_in_start = plci->req_out = 0;
  3755. dbug(1, dprintf("control_rc"));
  3756. appl = plci->appl;
  3757. a = plci->adapter;
  3758. ncci = a->ch_ncci[ch];
  3759. if (appl)
  3760. {
  3761. Id = (((dword)(ncci ? ncci : ch)) << 16) | ((word)plci->Id << 8) | a->Id;
  3762. if (plci->tel && plci->SuppState != CALL_HELD) Id |= EXT_CONTROLLER;
  3763. Number = plci->number;
  3764. 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));
  3765. dbug(1, dprintf("channels=0x%x", plci->channels));
  3766. if (plci_remove_check(plci))
  3767. return;
  3768. if (req == REMOVE && rc == ASSIGN_OK)
  3769. {
  3770. sig_req(plci, HANGUP, 0);
  3771. sig_req(plci, REMOVE, 0);
  3772. send_req(plci);
  3773. }
  3774. if (plci->command)
  3775. {
  3776. switch (plci->command)
  3777. {
  3778. case C_HOLD_REQ:
  3779. dbug(1, dprintf("HoldRC=0x%x", rc));
  3780. SSparms[1] = (byte)S_HOLD;
  3781. if (rc != OK)
  3782. {
  3783. plci->SuppState = IDLE;
  3784. Info = 0x2001;
  3785. }
  3786. sendf(appl, _FACILITY_R | CONFIRM, Id, Number, "wws", Info, 3, SSparms);
  3787. break;
  3788. case C_RETRIEVE_REQ:
  3789. dbug(1, dprintf("RetrieveRC=0x%x", rc));
  3790. SSparms[1] = (byte)S_RETRIEVE;
  3791. if (rc != OK)
  3792. {
  3793. plci->SuppState = CALL_HELD;
  3794. Info = 0x2001;
  3795. }
  3796. sendf(appl, _FACILITY_R | CONFIRM, Id, Number, "wws", Info, 3, SSparms);
  3797. break;
  3798. case _INFO_R:
  3799. dbug(1, dprintf("InfoRC=0x%x", rc));
  3800. if (rc != OK) Info = _WRONG_STATE;
  3801. sendf(appl, _INFO_R | CONFIRM, Id, Number, "w", Info);
  3802. break;
  3803. case _CONNECT_R:
  3804. dbug(1, dprintf("Connect_R=0x%x/0x%x/0x%x/0x%x", req, rc, global_req, nl_rc));
  3805. if (plci->State == INC_DIS_PENDING)
  3806. break;
  3807. if (plci->Sig.Id != 0xff)
  3808. {
  3809. if (((global_req == ASSIGN) && (rc != ASSIGN_OK))
  3810. || (!nl_rc && (req == CALL_REQ) && (rc != OK)))
  3811. {
  3812. dbug(1, dprintf("No more IDs/Call_Req failed"));
  3813. sendf(appl, _CONNECT_R | CONFIRM, Id & 0xffL, Number, "w", _OUT_OF_PLCI);
  3814. plci_remove(plci);
  3815. plci->State = IDLE;
  3816. break;
  3817. }
  3818. if (plci->State != LOCAL_CONNECT) plci->State = OUTG_CON_PENDING;
  3819. sendf(appl, _CONNECT_R | CONFIRM, Id, Number, "w", 0);
  3820. }
  3821. else /* D-ch activation */
  3822. {
  3823. if (rc != ASSIGN_OK)
  3824. {
  3825. dbug(1, dprintf("No more IDs/X.25 Call_Req failed"));
  3826. sendf(appl, _CONNECT_R | CONFIRM, Id & 0xffL, Number, "w", _OUT_OF_PLCI);
  3827. plci_remove(plci);
  3828. plci->State = IDLE;
  3829. break;
  3830. }
  3831. sendf(appl, _CONNECT_R | CONFIRM, Id, Number, "w", 0);
  3832. sendf(plci->appl, _CONNECT_ACTIVE_I, Id, 0, "sss", "", "", "");
  3833. plci->State = INC_ACT_PENDING;
  3834. }
  3835. break;
  3836. case _CONNECT_I | RESPONSE:
  3837. if (plci->State != INC_DIS_PENDING)
  3838. plci->State = INC_CON_ACCEPT;
  3839. break;
  3840. case _DISCONNECT_R:
  3841. if (plci->State == INC_DIS_PENDING)
  3842. break;
  3843. if (plci->Sig.Id != 0xff)
  3844. {
  3845. plci->State = OUTG_DIS_PENDING;
  3846. sendf(appl, _DISCONNECT_R | CONFIRM, Id, Number, "w", 0);
  3847. }
  3848. break;
  3849. case SUSPEND_REQ:
  3850. break;
  3851. case RESUME_REQ:
  3852. break;
  3853. case _CONNECT_B3_R:
  3854. if (rc != OK)
  3855. {
  3856. sendf(appl, _CONNECT_B3_R | CONFIRM, Id, Number, "w", _WRONG_IDENTIFIER);
  3857. break;
  3858. }
  3859. ncci = get_ncci(plci, ch, 0);
  3860. Id = (Id & 0xffff) | (((dword) ncci) << 16);
  3861. plci->channels++;
  3862. if (req == N_RESET)
  3863. {
  3864. a->ncci_state[ncci] = INC_ACT_PENDING;
  3865. sendf(appl, _CONNECT_B3_R | CONFIRM, Id, Number, "w", 0);
  3866. sendf(appl, _CONNECT_B3_ACTIVE_I, Id, 0, "s", "");
  3867. }
  3868. else
  3869. {
  3870. a->ncci_state[ncci] = OUTG_CON_PENDING;
  3871. sendf(appl, _CONNECT_B3_R | CONFIRM, Id, Number, "w", 0);
  3872. }
  3873. break;
  3874. case _CONNECT_B3_I | RESPONSE:
  3875. break;
  3876. case _RESET_B3_R:
  3877. /* sendf(appl, _RESET_B3_R | CONFIRM, Id, Number, "w", 0);*/
  3878. break;
  3879. case _DISCONNECT_B3_R:
  3880. sendf(appl, _DISCONNECT_B3_R | CONFIRM, Id, Number, "w", 0);
  3881. break;
  3882. case _MANUFACTURER_R:
  3883. break;
  3884. case PERM_LIST_REQ:
  3885. if (rc != OK)
  3886. {
  3887. Info = _WRONG_IDENTIFIER;
  3888. sendf(plci->appl, _CONNECT_R | CONFIRM, Id, Number, "w", Info);
  3889. plci_remove(plci);
  3890. }
  3891. else
  3892. sendf(plci->appl, _CONNECT_R | CONFIRM, Id, Number, "w", Info);
  3893. break;
  3894. default:
  3895. break;
  3896. }
  3897. plci->command = 0;
  3898. }
  3899. else if (plci->internal_command)
  3900. {
  3901. switch (plci->internal_command)
  3902. {
  3903. case BLOCK_PLCI:
  3904. return;
  3905. case GET_MWI_STATE:
  3906. if (rc == OK) /* command supported, wait for indication */
  3907. {
  3908. return;
  3909. }
  3910. plci_remove(plci);
  3911. break;
  3912. /* Get Supported Services */
  3913. case GETSERV_REQ_PEND:
  3914. if (rc == OK) /* command supported, wait for indication */
  3915. {
  3916. break;
  3917. }
  3918. PUT_DWORD(&SSstruct[6], MASK_TERMINAL_PORTABILITY);
  3919. sendf(appl, _FACILITY_R | CONFIRM, Id, Number, "wws", 0, 3, SSstruct);
  3920. plci_remove(plci);
  3921. break;
  3922. case INTERR_DIVERSION_REQ_PEND: /* Interrogate Parameters */
  3923. case INTERR_NUMBERS_REQ_PEND:
  3924. case CF_START_PEND: /* Call Forwarding Start pending */
  3925. case CF_STOP_PEND: /* Call Forwarding Stop pending */
  3926. case CCBS_REQUEST_REQ_PEND:
  3927. case CCBS_DEACTIVATE_REQ_PEND:
  3928. case CCBS_INTERROGATE_REQ_PEND:
  3929. switch (plci->internal_command)
  3930. {
  3931. case INTERR_DIVERSION_REQ_PEND:
  3932. SSparms[1] = S_INTERROGATE_DIVERSION;
  3933. break;
  3934. case INTERR_NUMBERS_REQ_PEND:
  3935. SSparms[1] = S_INTERROGATE_NUMBERS;
  3936. break;
  3937. case CF_START_PEND:
  3938. SSparms[1] = S_CALL_FORWARDING_START;
  3939. break;
  3940. case CF_STOP_PEND:
  3941. SSparms[1] = S_CALL_FORWARDING_STOP;
  3942. break;
  3943. case CCBS_REQUEST_REQ_PEND:
  3944. SSparms[1] = S_CCBS_REQUEST;
  3945. break;
  3946. case CCBS_DEACTIVATE_REQ_PEND:
  3947. SSparms[1] = S_CCBS_DEACTIVATE;
  3948. break;
  3949. case CCBS_INTERROGATE_REQ_PEND:
  3950. SSparms[1] = S_CCBS_INTERROGATE;
  3951. break;
  3952. }
  3953. if (global_req == ASSIGN)
  3954. {
  3955. dbug(1, dprintf("AssignDiversion_RC=0x%x/0x%x", req, rc));
  3956. return;
  3957. }
  3958. if (!plci->appl) break;
  3959. if (rc == ISDN_GUARD_REJ)
  3960. {
  3961. Info = _CAPI_GUARD_ERROR;
  3962. }
  3963. else if (rc != OK)
  3964. {
  3965. Info = _SUPPLEMENTARY_SERVICE_NOT_SUPPORTED;
  3966. }
  3967. sendf(plci->appl, _FACILITY_R | CONFIRM, Id & 0x7,
  3968. plci->number, "wws", Info, (word)3, SSparms);
  3969. if (Info) plci_remove(plci);
  3970. break;
  3971. /* 3pty conference pending */
  3972. case PTY_REQ_PEND:
  3973. if (!plci->relatedPTYPLCI) break;
  3974. rplci = plci->relatedPTYPLCI;
  3975. SSparms[1] = plci->ptyState;
  3976. rId = ((word)rplci->Id << 8) | rplci->adapter->Id;
  3977. if (rplci->tel) rId |= EXT_CONTROLLER;
  3978. if (rc != OK)
  3979. {
  3980. Info = 0x300E; /* not supported */
  3981. plci->relatedPTYPLCI = NULL;
  3982. plci->ptyState = 0;
  3983. }
  3984. sendf(rplci->appl,
  3985. _FACILITY_R | CONFIRM,
  3986. rId,
  3987. plci->number,
  3988. "wws", Info, (word)3, SSparms);
  3989. break;
  3990. /* Explicit Call Transfer pending */
  3991. case ECT_REQ_PEND:
  3992. dbug(1, dprintf("ECT_RC=0x%x/0x%x", req, rc));
  3993. if (!plci->relatedPTYPLCI) break;
  3994. rplci = plci->relatedPTYPLCI;
  3995. SSparms[1] = S_ECT;
  3996. rId = ((word)rplci->Id << 8) | rplci->adapter->Id;
  3997. if (rplci->tel) rId |= EXT_CONTROLLER;
  3998. if (rc != OK)
  3999. {
  4000. Info = 0x300E; /* not supported */
  4001. plci->relatedPTYPLCI = NULL;
  4002. plci->ptyState = 0;
  4003. }
  4004. sendf(rplci->appl,
  4005. _FACILITY_R | CONFIRM,
  4006. rId,
  4007. plci->number,
  4008. "wws", Info, (word)3, SSparms);
  4009. break;
  4010. case _MANUFACTURER_R:
  4011. dbug(1, dprintf("_Manufacturer_R=0x%x/0x%x", req, rc));
  4012. if ((global_req == ASSIGN) && (rc != ASSIGN_OK))
  4013. {
  4014. dbug(1, dprintf("No more IDs"));
  4015. sendf(appl, _MANUFACTURER_R | CONFIRM, Id, Number, "dww", _DI_MANU_ID, _MANUFACTURER_R, _OUT_OF_PLCI);
  4016. plci_remove(plci); /* after codec init, internal codec commands pending */
  4017. }
  4018. break;
  4019. case _CONNECT_R:
  4020. dbug(1, dprintf("_Connect_R=0x%x/0x%x", req, rc));
  4021. if ((global_req == ASSIGN) && (rc != ASSIGN_OK))
  4022. {
  4023. dbug(1, dprintf("No more IDs"));
  4024. sendf(appl, _CONNECT_R | CONFIRM, Id & 0xffL, Number, "w", _OUT_OF_PLCI);
  4025. plci_remove(plci); /* after codec init, internal codec commands pending */
  4026. }
  4027. break;
  4028. case PERM_COD_HOOK: /* finished with Hook_Ind */
  4029. return;
  4030. case PERM_COD_CALL:
  4031. dbug(1, dprintf("***Codec Connect_Pending A, Rc = 0x%x", rc));
  4032. plci->internal_command = PERM_COD_CONN_PEND;
  4033. return;
  4034. case PERM_COD_ASSIGN:
  4035. dbug(1, dprintf("***Codec Assign A, Rc = 0x%x", rc));
  4036. if (rc != ASSIGN_OK) break;
  4037. sig_req(plci, CALL_REQ, 0);
  4038. send_req(plci);
  4039. plci->internal_command = PERM_COD_CALL;
  4040. return;
  4041. /* Null Call Reference Request pending */
  4042. case C_NCR_FAC_REQ:
  4043. dbug(1, dprintf("NCR_FAC=0x%x/0x%x", req, rc));
  4044. if (global_req == ASSIGN)
  4045. {
  4046. if (rc == ASSIGN_OK)
  4047. {
  4048. return;
  4049. }
  4050. else
  4051. {
  4052. sendf(appl, _INFO_R | CONFIRM, Id & 0xf, Number, "w", _WRONG_STATE);
  4053. appl->NullCREnable = false;
  4054. plci_remove(plci);
  4055. }
  4056. }
  4057. else if (req == NCR_FACILITY)
  4058. {
  4059. if (rc == OK)
  4060. {
  4061. sendf(appl, _INFO_R | CONFIRM, Id & 0xf, Number, "w", 0);
  4062. }
  4063. else
  4064. {
  4065. sendf(appl, _INFO_R | CONFIRM, Id & 0xf, Number, "w", _WRONG_STATE);
  4066. appl->NullCREnable = false;
  4067. }
  4068. plci_remove(plci);
  4069. }
  4070. break;
  4071. case HOOK_ON_REQ:
  4072. if (plci->channels)
  4073. {
  4074. if (a->ncci_state[ncci] == CONNECTED)
  4075. {
  4076. a->ncci_state[ncci] = OUTG_DIS_PENDING;
  4077. cleanup_ncci_data(plci, ncci);
  4078. nl_req_ncci(plci, N_DISC, (byte)ncci);
  4079. }
  4080. break;
  4081. }
  4082. break;
  4083. case HOOK_OFF_REQ:
  4084. if (plci->State == INC_DIS_PENDING)
  4085. break;
  4086. sig_req(plci, CALL_REQ, 0);
  4087. send_req(plci);
  4088. plci->State = OUTG_CON_PENDING;
  4089. break;
  4090. case MWI_ACTIVATE_REQ_PEND:
  4091. case MWI_DEACTIVATE_REQ_PEND:
  4092. if (global_req == ASSIGN && rc == ASSIGN_OK)
  4093. {
  4094. dbug(1, dprintf("MWI_REQ assigned"));
  4095. return;
  4096. }
  4097. else if (rc != OK)
  4098. {
  4099. if (rc == WRONG_IE)
  4100. {
  4101. Info = 0x2007; /* Illegal message parameter coding */
  4102. dbug(1, dprintf("MWI_REQ invalid parameter"));
  4103. }
  4104. else
  4105. {
  4106. Info = 0x300B; /* not supported */
  4107. dbug(1, dprintf("MWI_REQ not supported"));
  4108. }
  4109. /* 0x3010: Request not allowed in this state */
  4110. PUT_WORD(&SSparms[4], 0x300E); /* SS not supported */
  4111. }
  4112. if (plci->internal_command == MWI_ACTIVATE_REQ_PEND)
  4113. {
  4114. PUT_WORD(&SSparms[1], S_MWI_ACTIVATE);
  4115. }
  4116. else PUT_WORD(&SSparms[1], S_MWI_DEACTIVATE);
  4117. if (plci->cr_enquiry)
  4118. {
  4119. sendf(plci->appl,
  4120. _FACILITY_R | CONFIRM,
  4121. Id & 0xf,
  4122. plci->number,
  4123. "wws", Info, (word)3, SSparms);
  4124. if (rc != OK) plci_remove(plci);
  4125. }
  4126. else
  4127. {
  4128. sendf(plci->appl,
  4129. _FACILITY_R | CONFIRM,
  4130. Id,
  4131. plci->number,
  4132. "wws", Info, (word)3, SSparms);
  4133. }
  4134. break;
  4135. case CONF_BEGIN_REQ_PEND:
  4136. case CONF_ADD_REQ_PEND:
  4137. case CONF_SPLIT_REQ_PEND:
  4138. case CONF_DROP_REQ_PEND:
  4139. case CONF_ISOLATE_REQ_PEND:
  4140. case CONF_REATTACH_REQ_PEND:
  4141. dbug(1, dprintf("CONF_RC=0x%x/0x%x", req, rc));
  4142. if ((plci->internal_command == CONF_ADD_REQ_PEND) && (!plci->relatedPTYPLCI)) break;
  4143. rplci = plci;
  4144. rId = Id;
  4145. switch (plci->internal_command)
  4146. {
  4147. case CONF_BEGIN_REQ_PEND:
  4148. SSparms[1] = S_CONF_BEGIN;
  4149. break;
  4150. case CONF_ADD_REQ_PEND:
  4151. SSparms[1] = S_CONF_ADD;
  4152. rplci = plci->relatedPTYPLCI;
  4153. rId = ((word)rplci->Id << 8) | rplci->adapter->Id;
  4154. break;
  4155. case CONF_SPLIT_REQ_PEND:
  4156. SSparms[1] = S_CONF_SPLIT;
  4157. break;
  4158. case CONF_DROP_REQ_PEND:
  4159. SSparms[1] = S_CONF_DROP;
  4160. break;
  4161. case CONF_ISOLATE_REQ_PEND:
  4162. SSparms[1] = S_CONF_ISOLATE;
  4163. break;
  4164. case CONF_REATTACH_REQ_PEND:
  4165. SSparms[1] = S_CONF_REATTACH;
  4166. break;
  4167. }
  4168. if (rc != OK)
  4169. {
  4170. Info = 0x300E; /* not supported */
  4171. plci->relatedPTYPLCI = NULL;
  4172. plci->ptyState = 0;
  4173. }
  4174. sendf(rplci->appl,
  4175. _FACILITY_R | CONFIRM,
  4176. rId,
  4177. plci->number,
  4178. "wws", Info, (word)3, SSparms);
  4179. break;
  4180. case VSWITCH_REQ_PEND:
  4181. if (rc != OK)
  4182. {
  4183. if (plci->relatedPTYPLCI)
  4184. {
  4185. plci->relatedPTYPLCI->vswitchstate = 0;
  4186. plci->relatedPTYPLCI->vsprot = 0;
  4187. plci->relatedPTYPLCI->vsprotdialect = 0;
  4188. }
  4189. plci->vswitchstate = 0;
  4190. plci->vsprot = 0;
  4191. plci->vsprotdialect = 0;
  4192. }
  4193. else
  4194. {
  4195. if (plci->relatedPTYPLCI &&
  4196. plci->vswitchstate == 1 &&
  4197. plci->relatedPTYPLCI->vswitchstate == 3) /* join complete */
  4198. plci->vswitchstate = 3;
  4199. }
  4200. break;
  4201. /* Call Deflection Request pending (SSCT) */
  4202. case CD_REQ_PEND:
  4203. SSparms[1] = S_CALL_DEFLECTION;
  4204. if (rc != OK)
  4205. {
  4206. Info = 0x300E; /* not supported */
  4207. plci->appl->CDEnable = 0;
  4208. }
  4209. sendf(plci->appl, _FACILITY_R | CONFIRM, Id,
  4210. plci->number, "wws", Info, (word)3, SSparms);
  4211. break;
  4212. case RTP_CONNECT_B3_REQ_COMMAND_2:
  4213. if (rc == OK)
  4214. {
  4215. ncci = get_ncci(plci, ch, 0);
  4216. Id = (Id & 0xffff) | (((dword) ncci) << 16);
  4217. plci->channels++;
  4218. a->ncci_state[ncci] = OUTG_CON_PENDING;
  4219. }
  4220. default:
  4221. if (plci->internal_command_queue[0])
  4222. {
  4223. (*(plci->internal_command_queue[0]))(Id, plci, rc);
  4224. if (plci->internal_command)
  4225. return;
  4226. }
  4227. break;
  4228. }
  4229. next_internal_command(Id, plci);
  4230. }
  4231. }
  4232. else /* appl==0 */
  4233. {
  4234. Id = ((word)plci->Id << 8) | plci->adapter->Id;
  4235. if (plci->tel) Id |= EXT_CONTROLLER;
  4236. switch (plci->internal_command)
  4237. {
  4238. case BLOCK_PLCI:
  4239. return;
  4240. case START_L1_SIG_ASSIGN_PEND:
  4241. case REM_L1_SIG_ASSIGN_PEND:
  4242. if (global_req == ASSIGN)
  4243. {
  4244. break;
  4245. }
  4246. else
  4247. {
  4248. dbug(1, dprintf("***L1 Req rem PLCI"));
  4249. plci->internal_command = 0;
  4250. sig_req(plci, REMOVE, 0);
  4251. send_req(plci);
  4252. }
  4253. break;
  4254. /* Call Deflection Request pending, just no appl ptr assigned */
  4255. case CD_REQ_PEND:
  4256. SSparms[1] = S_CALL_DEFLECTION;
  4257. if (rc != OK)
  4258. {
  4259. Info = 0x300E; /* not supported */
  4260. }
  4261. for (i = 0; i < max_appl; i++)
  4262. {
  4263. if (application[i].CDEnable)
  4264. {
  4265. if (!application[i].Id) application[i].CDEnable = 0;
  4266. else
  4267. {
  4268. sendf(&application[i], _FACILITY_R | CONFIRM, Id,
  4269. plci->number, "wws", Info, (word)3, SSparms);
  4270. if (Info) application[i].CDEnable = 0;
  4271. }
  4272. }
  4273. }
  4274. plci->internal_command = 0;
  4275. break;
  4276. case PERM_COD_HOOK: /* finished with Hook_Ind */
  4277. return;
  4278. case PERM_COD_CALL:
  4279. plci->internal_command = PERM_COD_CONN_PEND;
  4280. dbug(1, dprintf("***Codec Connect_Pending, Rc = 0x%x", rc));
  4281. return;
  4282. case PERM_COD_ASSIGN:
  4283. dbug(1, dprintf("***Codec Assign, Rc = 0x%x", rc));
  4284. plci->internal_command = 0;
  4285. if (rc != ASSIGN_OK) break;
  4286. plci->internal_command = PERM_COD_CALL;
  4287. sig_req(plci, CALL_REQ, 0);
  4288. send_req(plci);
  4289. return;
  4290. case LISTEN_SIG_ASSIGN_PEND:
  4291. if (rc == ASSIGN_OK)
  4292. {
  4293. plci->internal_command = 0;
  4294. dbug(1, dprintf("ListenCheck, new SIG_ID = 0x%x", plci->Sig.Id));
  4295. add_p(plci, ESC, "\x02\x18\x00"); /* support call waiting */
  4296. sig_req(plci, INDICATE_REQ, 0);
  4297. send_req(plci);
  4298. }
  4299. else
  4300. {
  4301. dbug(1, dprintf("ListenCheck failed (assignRc=0x%x)", rc));
  4302. a->listen_active--;
  4303. plci_remove(plci);
  4304. plci->State = IDLE;
  4305. }
  4306. break;
  4307. case USELAW_REQ:
  4308. if (global_req == ASSIGN)
  4309. {
  4310. if (rc == ASSIGN_OK)
  4311. {
  4312. sig_req(plci, LAW_REQ, 0);
  4313. send_req(plci);
  4314. dbug(1, dprintf("Auto-Law assigned"));
  4315. }
  4316. else
  4317. {
  4318. dbug(1, dprintf("Auto-Law assign failed"));
  4319. a->automatic_law = 3;
  4320. plci->internal_command = 0;
  4321. a->automatic_lawPLCI = NULL;
  4322. }
  4323. break;
  4324. }
  4325. else if (req == LAW_REQ && rc == OK)
  4326. {
  4327. dbug(1, dprintf("Auto-Law initiated"));
  4328. a->automatic_law = 2;
  4329. plci->internal_command = 0;
  4330. }
  4331. else
  4332. {
  4333. dbug(1, dprintf("Auto-Law not supported"));
  4334. a->automatic_law = 3;
  4335. plci->internal_command = 0;
  4336. sig_req(plci, REMOVE, 0);
  4337. send_req(plci);
  4338. a->automatic_lawPLCI = NULL;
  4339. }
  4340. break;
  4341. }
  4342. plci_remove_check(plci);
  4343. }
  4344. }
  4345. static void data_rc(PLCI *plci, byte ch)
  4346. {
  4347. dword Id;
  4348. DIVA_CAPI_ADAPTER *a;
  4349. NCCI *ncci_ptr;
  4350. DATA_B3_DESC *data;
  4351. word ncci;
  4352. if (plci->appl)
  4353. {
  4354. TransmitBufferFree(plci->appl, plci->data_sent_ptr);
  4355. a = plci->adapter;
  4356. ncci = a->ch_ncci[ch];
  4357. if (ncci && (a->ncci_plci[ncci] == plci->Id))
  4358. {
  4359. ncci_ptr = &(a->ncci[ncci]);
  4360. dbug(1, dprintf("data_out=%d, data_pending=%d", ncci_ptr->data_out, ncci_ptr->data_pending));
  4361. if (ncci_ptr->data_pending)
  4362. {
  4363. data = &(ncci_ptr->DBuffer[ncci_ptr->data_out]);
  4364. if (!(data->Flags & 4) && a->ncci_state[ncci])
  4365. {
  4366. Id = (((dword)ncci) << 16) | ((word)plci->Id << 8) | a->Id;
  4367. if (plci->tel) Id |= EXT_CONTROLLER;
  4368. sendf(plci->appl, _DATA_B3_R | CONFIRM, Id, data->Number,
  4369. "ww", data->Handle, 0);
  4370. }
  4371. (ncci_ptr->data_out)++;
  4372. if (ncci_ptr->data_out == MAX_DATA_B3)
  4373. ncci_ptr->data_out = 0;
  4374. (ncci_ptr->data_pending)--;
  4375. }
  4376. }
  4377. }
  4378. }
  4379. static void data_ack(PLCI *plci, byte ch)
  4380. {
  4381. dword Id;
  4382. DIVA_CAPI_ADAPTER *a;
  4383. NCCI *ncci_ptr;
  4384. word ncci;
  4385. a = plci->adapter;
  4386. ncci = a->ch_ncci[ch];
  4387. ncci_ptr = &(a->ncci[ncci]);
  4388. if (ncci_ptr->data_ack_pending)
  4389. {
  4390. if (a->ncci_state[ncci] && (a->ncci_plci[ncci] == plci->Id))
  4391. {
  4392. Id = (((dword)ncci) << 16) | ((word)plci->Id << 8) | a->Id;
  4393. if (plci->tel) Id |= EXT_CONTROLLER;
  4394. sendf(plci->appl, _DATA_B3_R | CONFIRM, Id, ncci_ptr->DataAck[ncci_ptr->data_ack_out].Number,
  4395. "ww", ncci_ptr->DataAck[ncci_ptr->data_ack_out].Handle, 0);
  4396. }
  4397. (ncci_ptr->data_ack_out)++;
  4398. if (ncci_ptr->data_ack_out == MAX_DATA_ACK)
  4399. ncci_ptr->data_ack_out = 0;
  4400. (ncci_ptr->data_ack_pending)--;
  4401. }
  4402. }
  4403. static void sig_ind(PLCI *plci)
  4404. {
  4405. dword x_Id;
  4406. dword Id;
  4407. dword rId;
  4408. word i;
  4409. word cip;
  4410. dword cip_mask;
  4411. byte *ie;
  4412. DIVA_CAPI_ADAPTER *a;
  4413. API_PARSE saved_parms[MAX_MSG_PARMS + 1];
  4414. #define MAXPARMSIDS 31
  4415. byte *parms[MAXPARMSIDS];
  4416. byte *add_i[4];
  4417. byte *multi_fac_parms[MAX_MULTI_IE];
  4418. byte *multi_pi_parms[MAX_MULTI_IE];
  4419. byte *multi_ssext_parms[MAX_MULTI_IE];
  4420. byte *multi_CiPN_parms[MAX_MULTI_IE];
  4421. byte *multi_vswitch_parms[MAX_MULTI_IE];
  4422. byte ai_len;
  4423. byte *esc_chi = "";
  4424. byte *esc_law = "";
  4425. byte *pty_cai = "";
  4426. byte *esc_cr = "";
  4427. byte *esc_profile = "";
  4428. byte facility[256];
  4429. PLCI *tplci = NULL;
  4430. byte chi[] = "\x02\x18\x01";
  4431. byte voice_cai[] = "\x06\x14\x00\x00\x00\x00\x08";
  4432. byte resume_cau[] = "\x05\x05\x00\x02\x00\x00";
  4433. /* ESC_MSGTYPE must be the last but one message, a new IE has to be */
  4434. /* included before the ESC_MSGTYPE and MAXPARMSIDS has to be incremented */
  4435. /* SMSG is situated at the end because its 0 (for compatibility reasons */
  4436. /* (see Info_Mask Bit 4, first IE. then the message type) */
  4437. static const word parms_id[] =
  4438. {MAXPARMSIDS, CPN, 0xff, DSA, OSA, BC, LLC, HLC, ESC_CAUSE, DSP, DT, CHA,
  4439. UUI, CONG_RR, CONG_RNR, ESC_CHI, KEY, CHI, CAU, ESC_LAW,
  4440. RDN, RDX, CONN_NR, RIN, NI, CAI, ESC_CR,
  4441. CST, ESC_PROFILE, 0xff, ESC_MSGTYPE, SMSG};
  4442. /* 14 FTY repl by ESC_CHI */
  4443. /* 18 PI repl by ESC_LAW */
  4444. /* removed OAD changed to 0xff for future use, OAD is multiIE now */
  4445. static const word multi_fac_id[] = {1, FTY};
  4446. static const word multi_pi_id[] = {1, PI};
  4447. static const word multi_CiPN_id[] = {1, OAD};
  4448. static const word multi_ssext_id[] = {1, ESC_SSEXT};
  4449. static const word multi_vswitch_id[] = {1, ESC_VSWITCH};
  4450. byte *cau;
  4451. word ncci;
  4452. byte SS_Ind[] = "\x05\x02\x00\x02\x00\x00"; /* Hold_Ind struct*/
  4453. byte CF_Ind[] = "\x09\x02\x00\x06\x00\x00\x00\x00\x00\x00";
  4454. byte Interr_Err_Ind[] = "\x0a\x02\x00\x07\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00";
  4455. byte CONF_Ind[] = "\x09\x16\x00\x06\x00\x00\x00\x00\x00\x00";
  4456. byte force_mt_info = false;
  4457. byte dir;
  4458. dword d;
  4459. word w;
  4460. a = plci->adapter;
  4461. Id = ((word)plci->Id << 8) | a->Id;
  4462. PUT_WORD(&SS_Ind[4], 0x0000);
  4463. if (plci->sig_remove_id)
  4464. {
  4465. plci->Sig.RNR = 2; /* discard */
  4466. dbug(1, dprintf("SIG discard while remove pending"));
  4467. return;
  4468. }
  4469. if (plci->tel && plci->SuppState != CALL_HELD) Id |= EXT_CONTROLLER;
  4470. dbug(1, dprintf("SigInd-Id=%08lx,plci=%x,tel=%x,state=0x%x,channels=%d,Discflowcl=%d",
  4471. Id, plci->Id, plci->tel, plci->State, plci->channels, plci->hangup_flow_ctrl_timer));
  4472. if (plci->Sig.Ind == CALL_HOLD_ACK && plci->channels)
  4473. {
  4474. plci->Sig.RNR = 1;
  4475. return;
  4476. }
  4477. if (plci->Sig.Ind == HANGUP && plci->channels)
  4478. {
  4479. plci->Sig.RNR = 1;
  4480. plci->hangup_flow_ctrl_timer++;
  4481. /* recover the network layer after timeout */
  4482. if (plci->hangup_flow_ctrl_timer == 100)
  4483. {
  4484. dbug(1, dprintf("Exceptional disc"));
  4485. plci->Sig.RNR = 0;
  4486. plci->hangup_flow_ctrl_timer = 0;
  4487. for (ncci = 1; ncci < MAX_NCCI + 1; ncci++)
  4488. {
  4489. if (a->ncci_plci[ncci] == plci->Id)
  4490. {
  4491. cleanup_ncci_data(plci, ncci);
  4492. if (plci->channels)plci->channels--;
  4493. if (plci->appl)
  4494. sendf(plci->appl, _DISCONNECT_B3_I, (((dword) ncci) << 16) | Id, 0, "ws", 0, "");
  4495. }
  4496. }
  4497. if (plci->appl)
  4498. sendf(plci->appl, _DISCONNECT_I, Id, 0, "w", 0);
  4499. plci_remove(plci);
  4500. plci->State = IDLE;
  4501. }
  4502. return;
  4503. }
  4504. /* do first parse the info with no OAD in, because OAD will be converted */
  4505. /* first the multiple facility IE, then mult. progress ind. */
  4506. /* then the parameters for the info_ind + conn_ind */
  4507. IndParse(plci, multi_fac_id, multi_fac_parms, MAX_MULTI_IE);
  4508. IndParse(plci, multi_pi_id, multi_pi_parms, MAX_MULTI_IE);
  4509. IndParse(plci, multi_ssext_id, multi_ssext_parms, MAX_MULTI_IE);
  4510. IndParse(plci, multi_vswitch_id, multi_vswitch_parms, MAX_MULTI_IE);
  4511. IndParse(plci, parms_id, parms, 0);
  4512. IndParse(plci, multi_CiPN_id, multi_CiPN_parms, MAX_MULTI_IE);
  4513. esc_chi = parms[14];
  4514. esc_law = parms[18];
  4515. pty_cai = parms[24];
  4516. esc_cr = parms[25];
  4517. esc_profile = parms[27];
  4518. if (esc_cr[0] && plci)
  4519. {
  4520. if (plci->cr_enquiry && plci->appl)
  4521. {
  4522. plci->cr_enquiry = false;
  4523. /* d = MANU_ID */
  4524. /* w = m_command */
  4525. /* b = total length */
  4526. /* b = indication type */
  4527. /* b = length of all IEs */
  4528. /* b = IE1 */
  4529. /* S = IE1 length + cont. */
  4530. /* b = IE2 */
  4531. /* S = IE2 length + cont. */
  4532. sendf(plci->appl,
  4533. _MANUFACTURER_I,
  4534. Id,
  4535. 0,
  4536. "dwbbbbSbS", _DI_MANU_ID, plci->m_command,
  4537. 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);
  4538. }
  4539. }
  4540. /* create the additional info structure */
  4541. add_i[1] = parms[15]; /* KEY of additional info */
  4542. add_i[2] = parms[11]; /* UUI of additional info */
  4543. ai_len = AddInfo(add_i, multi_fac_parms, esc_chi, facility);
  4544. /* the ESC_LAW indicates if u-Law or a-Law is actually used by the card */
  4545. /* indication returns by the card if requested by the function */
  4546. /* AutomaticLaw() after driver init */
  4547. if (a->automatic_law < 4)
  4548. {
  4549. if (esc_law[0]) {
  4550. if (esc_law[2]) {
  4551. dbug(0, dprintf("u-Law selected"));
  4552. a->u_law = 1;
  4553. }
  4554. else {
  4555. dbug(0, dprintf("a-Law selected"));
  4556. a->u_law = 0;
  4557. }
  4558. a->automatic_law = 4;
  4559. if (plci == a->automatic_lawPLCI) {
  4560. plci->internal_command = 0;
  4561. sig_req(plci, REMOVE, 0);
  4562. send_req(plci);
  4563. a->automatic_lawPLCI = NULL;
  4564. }
  4565. }
  4566. if (esc_profile[0])
  4567. {
  4568. dbug(1, dprintf("[%06x] CardProfile: %lx %lx %lx %lx %lx",
  4569. UnMapController(a->Id), GET_DWORD(&esc_profile[6]),
  4570. GET_DWORD(&esc_profile[10]), GET_DWORD(&esc_profile[14]),
  4571. GET_DWORD(&esc_profile[18]), GET_DWORD(&esc_profile[46])));
  4572. a->profile.Global_Options &= 0x000000ffL;
  4573. a->profile.B1_Protocols &= 0x000003ffL;
  4574. a->profile.B2_Protocols &= 0x00001fdfL;
  4575. a->profile.B3_Protocols &= 0x000000b7L;
  4576. a->profile.Global_Options &= GET_DWORD(&esc_profile[6]) |
  4577. GL_BCHANNEL_OPERATION_SUPPORTED;
  4578. a->profile.B1_Protocols &= GET_DWORD(&esc_profile[10]);
  4579. a->profile.B2_Protocols &= GET_DWORD(&esc_profile[14]);
  4580. a->profile.B3_Protocols &= GET_DWORD(&esc_profile[18]);
  4581. a->manufacturer_features = GET_DWORD(&esc_profile[46]);
  4582. a->man_profile.private_options = 0;
  4583. if (a->manufacturer_features & MANUFACTURER_FEATURE_ECHO_CANCELLER)
  4584. {
  4585. a->man_profile.private_options |= 1L << PRIVATE_ECHO_CANCELLER;
  4586. a->profile.Global_Options |= GL_ECHO_CANCELLER_SUPPORTED;
  4587. }
  4588. if (a->manufacturer_features & MANUFACTURER_FEATURE_RTP)
  4589. a->man_profile.private_options |= 1L << PRIVATE_RTP;
  4590. a->man_profile.rtp_primary_payloads = GET_DWORD(&esc_profile[50]);
  4591. a->man_profile.rtp_additional_payloads = GET_DWORD(&esc_profile[54]);
  4592. if (a->manufacturer_features & MANUFACTURER_FEATURE_T38)
  4593. a->man_profile.private_options |= 1L << PRIVATE_T38;
  4594. if (a->manufacturer_features & MANUFACTURER_FEATURE_FAX_SUB_SEP_PWD)
  4595. a->man_profile.private_options |= 1L << PRIVATE_FAX_SUB_SEP_PWD;
  4596. if (a->manufacturer_features & MANUFACTURER_FEATURE_V18)
  4597. a->man_profile.private_options |= 1L << PRIVATE_V18;
  4598. if (a->manufacturer_features & MANUFACTURER_FEATURE_DTMF_TONE)
  4599. a->man_profile.private_options |= 1L << PRIVATE_DTMF_TONE;
  4600. if (a->manufacturer_features & MANUFACTURER_FEATURE_PIAFS)
  4601. a->man_profile.private_options |= 1L << PRIVATE_PIAFS;
  4602. if (a->manufacturer_features & MANUFACTURER_FEATURE_FAX_PAPER_FORMATS)
  4603. a->man_profile.private_options |= 1L << PRIVATE_FAX_PAPER_FORMATS;
  4604. if (a->manufacturer_features & MANUFACTURER_FEATURE_VOWN)
  4605. a->man_profile.private_options |= 1L << PRIVATE_VOWN;
  4606. if (a->manufacturer_features & MANUFACTURER_FEATURE_FAX_NONSTANDARD)
  4607. a->man_profile.private_options |= 1L << PRIVATE_FAX_NONSTANDARD;
  4608. }
  4609. else
  4610. {
  4611. a->profile.Global_Options &= 0x0000007fL;
  4612. a->profile.B1_Protocols &= 0x000003dfL;
  4613. a->profile.B2_Protocols &= 0x00001adfL;
  4614. a->profile.B3_Protocols &= 0x000000b7L;
  4615. a->manufacturer_features &= MANUFACTURER_FEATURE_HARDDTMF;
  4616. }
  4617. if (a->manufacturer_features & (MANUFACTURER_FEATURE_HARDDTMF |
  4618. MANUFACTURER_FEATURE_SOFTDTMF_SEND | MANUFACTURER_FEATURE_SOFTDTMF_RECEIVE))
  4619. {
  4620. a->profile.Global_Options |= GL_DTMF_SUPPORTED;
  4621. }
  4622. a->manufacturer_features &= ~MANUFACTURER_FEATURE_OOB_CHANNEL;
  4623. dbug(1, dprintf("[%06x] Profile: %lx %lx %lx %lx %lx",
  4624. UnMapController(a->Id), a->profile.Global_Options,
  4625. a->profile.B1_Protocols, a->profile.B2_Protocols,
  4626. a->profile.B3_Protocols, a->manufacturer_features));
  4627. }
  4628. /* codec plci for the handset/hook state support is just an internal id */
  4629. if (plci != a->AdvCodecPLCI)
  4630. {
  4631. force_mt_info = SendMultiIE(plci, Id, multi_fac_parms, FTY, 0x20, 0);
  4632. force_mt_info |= SendMultiIE(plci, Id, multi_pi_parms, PI, 0x210, 0);
  4633. SendSSExtInd(NULL, plci, Id, multi_ssext_parms);
  4634. SendInfo(plci, Id, parms, force_mt_info);
  4635. VSwitchReqInd(plci, Id, multi_vswitch_parms);
  4636. }
  4637. /* switch the codec to the b-channel */
  4638. if (esc_chi[0] && plci && !plci->SuppState) {
  4639. plci->b_channel = esc_chi[esc_chi[0]]&0x1f;
  4640. mixer_set_bchannel_id_esc(plci, plci->b_channel);
  4641. dbug(1, dprintf("storeChannel=0x%x", plci->b_channel));
  4642. if (plci->tel == ADV_VOICE && plci->appl) {
  4643. SetVoiceChannel(a->AdvCodecPLCI, esc_chi, a);
  4644. }
  4645. }
  4646. if (plci->appl) plci->appl->Number++;
  4647. switch (plci->Sig.Ind) {
  4648. /* Response to Get_Supported_Services request */
  4649. case S_SUPPORTED:
  4650. dbug(1, dprintf("S_Supported"));
  4651. if (!plci->appl) break;
  4652. if (pty_cai[0] == 4)
  4653. {
  4654. PUT_DWORD(&CF_Ind[6], GET_DWORD(&pty_cai[1]));
  4655. }
  4656. else
  4657. {
  4658. PUT_DWORD(&CF_Ind[6], MASK_TERMINAL_PORTABILITY | MASK_HOLD_RETRIEVE);
  4659. }
  4660. PUT_WORD(&CF_Ind[1], 0);
  4661. PUT_WORD(&CF_Ind[4], 0);
  4662. sendf(plci->appl, _FACILITY_R | CONFIRM, Id & 0x7, plci->number, "wws", 0, 3, CF_Ind);
  4663. plci_remove(plci);
  4664. break;
  4665. /* Supplementary Service rejected */
  4666. case S_SERVICE_REJ:
  4667. dbug(1, dprintf("S_Reject=0x%x", pty_cai[5]));
  4668. if (!pty_cai[0]) break;
  4669. switch (pty_cai[5])
  4670. {
  4671. case ECT_EXECUTE:
  4672. case THREE_PTY_END:
  4673. case THREE_PTY_BEGIN:
  4674. if (!plci->relatedPTYPLCI) break;
  4675. tplci = plci->relatedPTYPLCI;
  4676. rId = ((word)tplci->Id << 8) | tplci->adapter->Id;
  4677. if (tplci->tel) rId |= EXT_CONTROLLER;
  4678. if (pty_cai[5] == ECT_EXECUTE)
  4679. {
  4680. PUT_WORD(&SS_Ind[1], S_ECT);
  4681. plci->vswitchstate = 0;
  4682. plci->relatedPTYPLCI->vswitchstate = 0;
  4683. }
  4684. else
  4685. {
  4686. PUT_WORD(&SS_Ind[1], pty_cai[5] + 3);
  4687. }
  4688. if (pty_cai[2] != 0xff)
  4689. {
  4690. PUT_WORD(&SS_Ind[4], 0x3600 | (word)pty_cai[2]);
  4691. }
  4692. else
  4693. {
  4694. PUT_WORD(&SS_Ind[4], 0x300E);
  4695. }
  4696. plci->relatedPTYPLCI = NULL;
  4697. plci->ptyState = 0;
  4698. sendf(tplci->appl, _FACILITY_I, rId, 0, "ws", 3, SS_Ind);
  4699. break;
  4700. case CALL_DEFLECTION:
  4701. if (pty_cai[2] != 0xff)
  4702. {
  4703. PUT_WORD(&SS_Ind[4], 0x3600 | (word)pty_cai[2]);
  4704. }
  4705. else
  4706. {
  4707. PUT_WORD(&SS_Ind[4], 0x300E);
  4708. }
  4709. PUT_WORD(&SS_Ind[1], pty_cai[5]);
  4710. for (i = 0; i < max_appl; i++)
  4711. {
  4712. if (application[i].CDEnable)
  4713. {
  4714. if (application[i].Id) sendf(&application[i], _FACILITY_I, Id, 0, "ws", 3, SS_Ind);
  4715. application[i].CDEnable = false;
  4716. }
  4717. }
  4718. break;
  4719. case DEACTIVATION_DIVERSION:
  4720. case ACTIVATION_DIVERSION:
  4721. case DIVERSION_INTERROGATE_CFU:
  4722. case DIVERSION_INTERROGATE_CFB:
  4723. case DIVERSION_INTERROGATE_CFNR:
  4724. case DIVERSION_INTERROGATE_NUM:
  4725. case CCBS_REQUEST:
  4726. case CCBS_DEACTIVATE:
  4727. case CCBS_INTERROGATE:
  4728. if (!plci->appl) break;
  4729. if (pty_cai[2] != 0xff)
  4730. {
  4731. PUT_WORD(&Interr_Err_Ind[4], 0x3600 | (word)pty_cai[2]);
  4732. }
  4733. else
  4734. {
  4735. PUT_WORD(&Interr_Err_Ind[4], 0x300E);
  4736. }
  4737. switch (pty_cai[5])
  4738. {
  4739. case DEACTIVATION_DIVERSION:
  4740. dbug(1, dprintf("Deact_Div"));
  4741. Interr_Err_Ind[0] = 0x9;
  4742. Interr_Err_Ind[3] = 0x6;
  4743. PUT_WORD(&Interr_Err_Ind[1], S_CALL_FORWARDING_STOP);
  4744. break;
  4745. case ACTIVATION_DIVERSION:
  4746. dbug(1, dprintf("Act_Div"));
  4747. Interr_Err_Ind[0] = 0x9;
  4748. Interr_Err_Ind[3] = 0x6;
  4749. PUT_WORD(&Interr_Err_Ind[1], S_CALL_FORWARDING_START);
  4750. break;
  4751. case DIVERSION_INTERROGATE_CFU:
  4752. case DIVERSION_INTERROGATE_CFB:
  4753. case DIVERSION_INTERROGATE_CFNR:
  4754. dbug(1, dprintf("Interr_Div"));
  4755. Interr_Err_Ind[0] = 0xa;
  4756. Interr_Err_Ind[3] = 0x7;
  4757. PUT_WORD(&Interr_Err_Ind[1], S_INTERROGATE_DIVERSION);
  4758. break;
  4759. case DIVERSION_INTERROGATE_NUM:
  4760. dbug(1, dprintf("Interr_Num"));
  4761. Interr_Err_Ind[0] = 0xa;
  4762. Interr_Err_Ind[3] = 0x7;
  4763. PUT_WORD(&Interr_Err_Ind[1], S_INTERROGATE_NUMBERS);
  4764. break;
  4765. case CCBS_REQUEST:
  4766. dbug(1, dprintf("CCBS Request"));
  4767. Interr_Err_Ind[0] = 0xd;
  4768. Interr_Err_Ind[3] = 0xa;
  4769. PUT_WORD(&Interr_Err_Ind[1], S_CCBS_REQUEST);
  4770. break;
  4771. case CCBS_DEACTIVATE:
  4772. dbug(1, dprintf("CCBS Deactivate"));
  4773. Interr_Err_Ind[0] = 0x9;
  4774. Interr_Err_Ind[3] = 0x6;
  4775. PUT_WORD(&Interr_Err_Ind[1], S_CCBS_DEACTIVATE);
  4776. break;
  4777. case CCBS_INTERROGATE:
  4778. dbug(1, dprintf("CCBS Interrogate"));
  4779. Interr_Err_Ind[0] = 0xb;
  4780. Interr_Err_Ind[3] = 0x8;
  4781. PUT_WORD(&Interr_Err_Ind[1], S_CCBS_INTERROGATE);
  4782. break;
  4783. }
  4784. PUT_DWORD(&Interr_Err_Ind[6], plci->appl->S_Handle);
  4785. sendf(plci->appl, _FACILITY_I, Id & 0x7, 0, "ws", 3, Interr_Err_Ind);
  4786. plci_remove(plci);
  4787. break;
  4788. case ACTIVATION_MWI:
  4789. case DEACTIVATION_MWI:
  4790. if (pty_cai[5] == ACTIVATION_MWI)
  4791. {
  4792. PUT_WORD(&SS_Ind[1], S_MWI_ACTIVATE);
  4793. }
  4794. else PUT_WORD(&SS_Ind[1], S_MWI_DEACTIVATE);
  4795. if (pty_cai[2] != 0xff)
  4796. {
  4797. PUT_WORD(&SS_Ind[4], 0x3600 | (word)pty_cai[2]);
  4798. }
  4799. else
  4800. {
  4801. PUT_WORD(&SS_Ind[4], 0x300E);
  4802. }
  4803. if (plci->cr_enquiry)
  4804. {
  4805. sendf(plci->appl, _FACILITY_I, Id & 0xf, 0, "ws", 3, SS_Ind);
  4806. plci_remove(plci);
  4807. }
  4808. else
  4809. {
  4810. sendf(plci->appl, _FACILITY_I, Id, 0, "ws", 3, SS_Ind);
  4811. }
  4812. break;
  4813. case CONF_ADD: /* ERROR */
  4814. case CONF_BEGIN:
  4815. case CONF_DROP:
  4816. case CONF_ISOLATE:
  4817. case CONF_REATTACH:
  4818. CONF_Ind[0] = 9;
  4819. CONF_Ind[3] = 6;
  4820. switch (pty_cai[5])
  4821. {
  4822. case CONF_BEGIN:
  4823. PUT_WORD(&CONF_Ind[1], S_CONF_BEGIN);
  4824. plci->ptyState = 0;
  4825. break;
  4826. case CONF_DROP:
  4827. CONF_Ind[0] = 5;
  4828. CONF_Ind[3] = 2;
  4829. PUT_WORD(&CONF_Ind[1], S_CONF_DROP);
  4830. plci->ptyState = CONNECTED;
  4831. break;
  4832. case CONF_ISOLATE:
  4833. CONF_Ind[0] = 5;
  4834. CONF_Ind[3] = 2;
  4835. PUT_WORD(&CONF_Ind[1], S_CONF_ISOLATE);
  4836. plci->ptyState = CONNECTED;
  4837. break;
  4838. case CONF_REATTACH:
  4839. CONF_Ind[0] = 5;
  4840. CONF_Ind[3] = 2;
  4841. PUT_WORD(&CONF_Ind[1], S_CONF_REATTACH);
  4842. plci->ptyState = CONNECTED;
  4843. break;
  4844. case CONF_ADD:
  4845. PUT_WORD(&CONF_Ind[1], S_CONF_ADD);
  4846. plci->relatedPTYPLCI = NULL;
  4847. tplci = plci->relatedPTYPLCI;
  4848. if (tplci) tplci->ptyState = CONNECTED;
  4849. plci->ptyState = CONNECTED;
  4850. break;
  4851. }
  4852. if (pty_cai[2] != 0xff)
  4853. {
  4854. PUT_WORD(&CONF_Ind[4], 0x3600 | (word)pty_cai[2]);
  4855. }
  4856. else
  4857. {
  4858. PUT_WORD(&CONF_Ind[4], 0x3303); /* Time-out: network did not respond
  4859. within the required time */
  4860. }
  4861. PUT_DWORD(&CONF_Ind[6], 0x0);
  4862. sendf(plci->appl, _FACILITY_I, Id, 0, "ws", 3, CONF_Ind);
  4863. break;
  4864. }
  4865. break;
  4866. /* Supplementary Service indicates success */
  4867. case S_SERVICE:
  4868. dbug(1, dprintf("Service_Ind"));
  4869. PUT_WORD(&CF_Ind[4], 0);
  4870. switch (pty_cai[5])
  4871. {
  4872. case THREE_PTY_END:
  4873. case THREE_PTY_BEGIN:
  4874. case ECT_EXECUTE:
  4875. if (!plci->relatedPTYPLCI) break;
  4876. tplci = plci->relatedPTYPLCI;
  4877. rId = ((word)tplci->Id << 8) | tplci->adapter->Id;
  4878. if (tplci->tel) rId |= EXT_CONTROLLER;
  4879. if (pty_cai[5] == ECT_EXECUTE)
  4880. {
  4881. PUT_WORD(&SS_Ind[1], S_ECT);
  4882. if (plci->vswitchstate != 3)
  4883. {
  4884. plci->ptyState = IDLE;
  4885. plci->relatedPTYPLCI = NULL;
  4886. plci->ptyState = 0;
  4887. }
  4888. dbug(1, dprintf("ECT OK"));
  4889. sendf(tplci->appl, _FACILITY_I, rId, 0, "ws", 3, SS_Ind);
  4890. }
  4891. else
  4892. {
  4893. switch (plci->ptyState)
  4894. {
  4895. case S_3PTY_BEGIN:
  4896. plci->ptyState = CONNECTED;
  4897. dbug(1, dprintf("3PTY ON"));
  4898. break;
  4899. case S_3PTY_END:
  4900. plci->ptyState = IDLE;
  4901. plci->relatedPTYPLCI = NULL;
  4902. plci->ptyState = 0;
  4903. dbug(1, dprintf("3PTY OFF"));
  4904. break;
  4905. }
  4906. PUT_WORD(&SS_Ind[1], pty_cai[5] + 3);
  4907. sendf(tplci->appl, _FACILITY_I, rId, 0, "ws", 3, SS_Ind);
  4908. }
  4909. break;
  4910. case CALL_DEFLECTION:
  4911. PUT_WORD(&SS_Ind[1], pty_cai[5]);
  4912. for (i = 0; i < max_appl; i++)
  4913. {
  4914. if (application[i].CDEnable)
  4915. {
  4916. if (application[i].Id) sendf(&application[i], _FACILITY_I, Id, 0, "ws", 3, SS_Ind);
  4917. application[i].CDEnable = false;
  4918. }
  4919. }
  4920. break;
  4921. case DEACTIVATION_DIVERSION:
  4922. case ACTIVATION_DIVERSION:
  4923. if (!plci->appl) break;
  4924. PUT_WORD(&CF_Ind[1], pty_cai[5] + 2);
  4925. PUT_DWORD(&CF_Ind[6], plci->appl->S_Handle);
  4926. sendf(plci->appl, _FACILITY_I, Id & 0x7, 0, "ws", 3, CF_Ind);
  4927. plci_remove(plci);
  4928. break;
  4929. case DIVERSION_INTERROGATE_CFU:
  4930. case DIVERSION_INTERROGATE_CFB:
  4931. case DIVERSION_INTERROGATE_CFNR:
  4932. case DIVERSION_INTERROGATE_NUM:
  4933. case CCBS_REQUEST:
  4934. case CCBS_DEACTIVATE:
  4935. case CCBS_INTERROGATE:
  4936. if (!plci->appl) break;
  4937. switch (pty_cai[5])
  4938. {
  4939. case DIVERSION_INTERROGATE_CFU:
  4940. case DIVERSION_INTERROGATE_CFB:
  4941. case DIVERSION_INTERROGATE_CFNR:
  4942. dbug(1, dprintf("Interr_Div"));
  4943. PUT_WORD(&pty_cai[1], S_INTERROGATE_DIVERSION);
  4944. pty_cai[3] = pty_cai[0] - 3; /* Supplementary Service-specific parameter len */
  4945. break;
  4946. case DIVERSION_INTERROGATE_NUM:
  4947. dbug(1, dprintf("Interr_Num"));
  4948. PUT_WORD(&pty_cai[1], S_INTERROGATE_NUMBERS);
  4949. pty_cai[3] = pty_cai[0] - 3; /* Supplementary Service-specific parameter len */
  4950. break;
  4951. case CCBS_REQUEST:
  4952. dbug(1, dprintf("CCBS Request"));
  4953. PUT_WORD(&pty_cai[1], S_CCBS_REQUEST);
  4954. pty_cai[3] = pty_cai[0] - 3; /* Supplementary Service-specific parameter len */
  4955. break;
  4956. case CCBS_DEACTIVATE:
  4957. dbug(1, dprintf("CCBS Deactivate"));
  4958. PUT_WORD(&pty_cai[1], S_CCBS_DEACTIVATE);
  4959. pty_cai[3] = pty_cai[0] - 3; /* Supplementary Service-specific parameter len */
  4960. break;
  4961. case CCBS_INTERROGATE:
  4962. dbug(1, dprintf("CCBS Interrogate"));
  4963. PUT_WORD(&pty_cai[1], S_CCBS_INTERROGATE);
  4964. pty_cai[3] = pty_cai[0] - 3; /* Supplementary Service-specific parameter len */
  4965. break;
  4966. }
  4967. PUT_WORD(&pty_cai[4], 0); /* Supplementary Service Reason */
  4968. PUT_DWORD(&pty_cai[6], plci->appl->S_Handle);
  4969. sendf(plci->appl, _FACILITY_I, Id & 0x7, 0, "wS", 3, pty_cai);
  4970. plci_remove(plci);
  4971. break;
  4972. case ACTIVATION_MWI:
  4973. case DEACTIVATION_MWI:
  4974. if (pty_cai[5] == ACTIVATION_MWI)
  4975. {
  4976. PUT_WORD(&SS_Ind[1], S_MWI_ACTIVATE);
  4977. }
  4978. else PUT_WORD(&SS_Ind[1], S_MWI_DEACTIVATE);
  4979. if (plci->cr_enquiry)
  4980. {
  4981. sendf(plci->appl, _FACILITY_I, Id & 0xf, 0, "ws", 3, SS_Ind);
  4982. plci_remove(plci);
  4983. }
  4984. else
  4985. {
  4986. sendf(plci->appl, _FACILITY_I, Id, 0, "ws", 3, SS_Ind);
  4987. }
  4988. break;
  4989. case MWI_INDICATION:
  4990. if (pty_cai[0] >= 0x12)
  4991. {
  4992. PUT_WORD(&pty_cai[3], S_MWI_INDICATE);
  4993. pty_cai[2] = pty_cai[0] - 2; /* len Parameter */
  4994. pty_cai[5] = pty_cai[0] - 5; /* Supplementary Service-specific parameter len */
  4995. if (plci->appl && (a->Notification_Mask[plci->appl->Id - 1] & SMASK_MWI))
  4996. {
  4997. if (plci->internal_command == GET_MWI_STATE) /* result on Message Waiting Listen */
  4998. {
  4999. sendf(plci->appl, _FACILITY_I, Id & 0xf, 0, "wS", 3, &pty_cai[2]);
  5000. plci_remove(plci);
  5001. return;
  5002. }
  5003. else sendf(plci->appl, _FACILITY_I, Id, 0, "wS", 3, &pty_cai[2]);
  5004. pty_cai[0] = 0;
  5005. }
  5006. else
  5007. {
  5008. for (i = 0; i < max_appl; i++)
  5009. {
  5010. if (a->Notification_Mask[i]&SMASK_MWI)
  5011. {
  5012. sendf(&application[i], _FACILITY_I, Id & 0x7, 0, "wS", 3, &pty_cai[2]);
  5013. pty_cai[0] = 0;
  5014. }
  5015. }
  5016. }
  5017. if (!pty_cai[0])
  5018. { /* acknowledge */
  5019. facility[2] = 0; /* returncode */
  5020. }
  5021. else facility[2] = 0xff;
  5022. }
  5023. else
  5024. {
  5025. /* reject */
  5026. facility[2] = 0xff; /* returncode */
  5027. }
  5028. facility[0] = 2;
  5029. facility[1] = MWI_RESPONSE; /* Function */
  5030. add_p(plci, CAI, facility);
  5031. add_p(plci, ESC, multi_ssext_parms[0]); /* remembered parameter -> only one possible */
  5032. sig_req(plci, S_SERVICE, 0);
  5033. send_req(plci);
  5034. plci->command = 0;
  5035. next_internal_command(Id, plci);
  5036. break;
  5037. case CONF_ADD: /* OK */
  5038. case CONF_BEGIN:
  5039. case CONF_DROP:
  5040. case CONF_ISOLATE:
  5041. case CONF_REATTACH:
  5042. case CONF_PARTYDISC:
  5043. CONF_Ind[0] = 9;
  5044. CONF_Ind[3] = 6;
  5045. switch (pty_cai[5])
  5046. {
  5047. case CONF_BEGIN:
  5048. PUT_WORD(&CONF_Ind[1], S_CONF_BEGIN);
  5049. if (pty_cai[0] == 6)
  5050. {
  5051. d = pty_cai[6];
  5052. PUT_DWORD(&CONF_Ind[6], d); /* PartyID */
  5053. }
  5054. else
  5055. {
  5056. PUT_DWORD(&CONF_Ind[6], 0x0);
  5057. }
  5058. break;
  5059. case CONF_ISOLATE:
  5060. PUT_WORD(&CONF_Ind[1], S_CONF_ISOLATE);
  5061. CONF_Ind[0] = 5;
  5062. CONF_Ind[3] = 2;
  5063. break;
  5064. case CONF_REATTACH:
  5065. PUT_WORD(&CONF_Ind[1], S_CONF_REATTACH);
  5066. CONF_Ind[0] = 5;
  5067. CONF_Ind[3] = 2;
  5068. break;
  5069. case CONF_DROP:
  5070. PUT_WORD(&CONF_Ind[1], S_CONF_DROP);
  5071. CONF_Ind[0] = 5;
  5072. CONF_Ind[3] = 2;
  5073. break;
  5074. case CONF_ADD:
  5075. PUT_WORD(&CONF_Ind[1], S_CONF_ADD);
  5076. d = pty_cai[6];
  5077. PUT_DWORD(&CONF_Ind[6], d); /* PartyID */
  5078. tplci = plci->relatedPTYPLCI;
  5079. if (tplci) tplci->ptyState = CONNECTED;
  5080. break;
  5081. case CONF_PARTYDISC:
  5082. CONF_Ind[0] = 7;
  5083. CONF_Ind[3] = 4;
  5084. PUT_WORD(&CONF_Ind[1], S_CONF_PARTYDISC);
  5085. d = pty_cai[6];
  5086. PUT_DWORD(&CONF_Ind[4], d); /* PartyID */
  5087. break;
  5088. }
  5089. plci->ptyState = CONNECTED;
  5090. sendf(plci->appl, _FACILITY_I, Id, 0, "ws", 3, CONF_Ind);
  5091. break;
  5092. case CCBS_INFO_RETAIN:
  5093. case CCBS_ERASECALLLINKAGEID:
  5094. case CCBS_STOP_ALERTING:
  5095. CONF_Ind[0] = 5;
  5096. CONF_Ind[3] = 2;
  5097. switch (pty_cai[5])
  5098. {
  5099. case CCBS_INFO_RETAIN:
  5100. PUT_WORD(&CONF_Ind[1], S_CCBS_INFO_RETAIN);
  5101. break;
  5102. case CCBS_STOP_ALERTING:
  5103. PUT_WORD(&CONF_Ind[1], S_CCBS_STOP_ALERTING);
  5104. break;
  5105. case CCBS_ERASECALLLINKAGEID:
  5106. PUT_WORD(&CONF_Ind[1], S_CCBS_ERASECALLLINKAGEID);
  5107. CONF_Ind[0] = 7;
  5108. CONF_Ind[3] = 4;
  5109. CONF_Ind[6] = 0;
  5110. CONF_Ind[7] = 0;
  5111. break;
  5112. }
  5113. w = pty_cai[6];
  5114. PUT_WORD(&CONF_Ind[4], w); /* PartyID */
  5115. if (plci->appl && (a->Notification_Mask[plci->appl->Id - 1] & SMASK_CCBS))
  5116. {
  5117. sendf(plci->appl, _FACILITY_I, Id, 0, "ws", 3, CONF_Ind);
  5118. }
  5119. else
  5120. {
  5121. for (i = 0; i < max_appl; i++)
  5122. if (a->Notification_Mask[i] & SMASK_CCBS)
  5123. sendf(&application[i], _FACILITY_I, Id & 0x7, 0, "ws", 3, CONF_Ind);
  5124. }
  5125. break;
  5126. }
  5127. break;
  5128. case CALL_HOLD_REJ:
  5129. cau = parms[7];
  5130. if (cau)
  5131. {
  5132. i = _L3_CAUSE | cau[2];
  5133. if (cau[2] == 0) i = 0x3603;
  5134. }
  5135. else
  5136. {
  5137. i = 0x3603;
  5138. }
  5139. PUT_WORD(&SS_Ind[1], S_HOLD);
  5140. PUT_WORD(&SS_Ind[4], i);
  5141. if (plci->SuppState == HOLD_REQUEST)
  5142. {
  5143. plci->SuppState = IDLE;
  5144. sendf(plci->appl, _FACILITY_I, Id, 0, "ws", 3, SS_Ind);
  5145. }
  5146. break;
  5147. case CALL_HOLD_ACK:
  5148. if (plci->SuppState == HOLD_REQUEST)
  5149. {
  5150. plci->SuppState = CALL_HELD;
  5151. CodecIdCheck(a, plci);
  5152. start_internal_command(Id, plci, hold_save_command);
  5153. }
  5154. break;
  5155. case CALL_RETRIEVE_REJ:
  5156. cau = parms[7];
  5157. if (cau)
  5158. {
  5159. i = _L3_CAUSE | cau[2];
  5160. if (cau[2] == 0) i = 0x3603;
  5161. }
  5162. else
  5163. {
  5164. i = 0x3603;
  5165. }
  5166. PUT_WORD(&SS_Ind[1], S_RETRIEVE);
  5167. PUT_WORD(&SS_Ind[4], i);
  5168. if (plci->SuppState == RETRIEVE_REQUEST)
  5169. {
  5170. plci->SuppState = CALL_HELD;
  5171. CodecIdCheck(a, plci);
  5172. sendf(plci->appl, _FACILITY_I, Id, 0, "ws", 3, SS_Ind);
  5173. }
  5174. break;
  5175. case CALL_RETRIEVE_ACK:
  5176. PUT_WORD(&SS_Ind[1], S_RETRIEVE);
  5177. if (plci->SuppState == RETRIEVE_REQUEST)
  5178. {
  5179. plci->SuppState = IDLE;
  5180. plci->call_dir |= CALL_DIR_FORCE_OUTG_NL;
  5181. plci->b_channel = esc_chi[esc_chi[0]]&0x1f;
  5182. if (plci->tel)
  5183. {
  5184. mixer_set_bchannel_id_esc(plci, plci->b_channel);
  5185. dbug(1, dprintf("RetrChannel=0x%x", plci->b_channel));
  5186. SetVoiceChannel(a->AdvCodecPLCI, esc_chi, a);
  5187. if (plci->B2_prot == B2_TRANSPARENT && plci->B3_prot == B3_TRANSPARENT)
  5188. {
  5189. dbug(1, dprintf("Get B-ch"));
  5190. start_internal_command(Id, plci, retrieve_restore_command);
  5191. }
  5192. else
  5193. sendf(plci->appl, _FACILITY_I, Id, 0, "ws", 3, SS_Ind);
  5194. }
  5195. else
  5196. start_internal_command(Id, plci, retrieve_restore_command);
  5197. }
  5198. break;
  5199. case INDICATE_IND:
  5200. if (plci->State != LISTENING) {
  5201. sig_req(plci, HANGUP, 0);
  5202. send_req(plci);
  5203. break;
  5204. }
  5205. cip = find_cip(a, parms[4], parms[6]);
  5206. cip_mask = 1L << cip;
  5207. dbug(1, dprintf("cip=%d,cip_mask=%lx", cip, cip_mask));
  5208. clear_c_ind_mask(plci);
  5209. if (!remove_started && !a->adapter_disabled)
  5210. {
  5211. set_c_ind_mask_bit(plci, MAX_APPL);
  5212. group_optimization(a, plci);
  5213. for (i = 0; i < max_appl; i++) {
  5214. if (application[i].Id
  5215. && (a->CIP_Mask[i] & 1 || a->CIP_Mask[i] & cip_mask)
  5216. && CPN_filter_ok(parms[0], a, i)
  5217. && test_group_ind_mask_bit(plci, i)) {
  5218. dbug(1, dprintf("storedcip_mask[%d]=0x%lx", i, a->CIP_Mask[i]));
  5219. set_c_ind_mask_bit(plci, i);
  5220. dump_c_ind_mask(plci);
  5221. plci->State = INC_CON_PENDING;
  5222. plci->call_dir = (plci->call_dir & ~(CALL_DIR_OUT | CALL_DIR_ORIGINATE)) |
  5223. CALL_DIR_IN | CALL_DIR_ANSWER;
  5224. if (esc_chi[0]) {
  5225. plci->b_channel = esc_chi[esc_chi[0]] & 0x1f;
  5226. mixer_set_bchannel_id_esc(plci, plci->b_channel);
  5227. }
  5228. /* if a listen on the ext controller is done, check if hook states */
  5229. /* are supported or if just a on board codec must be activated */
  5230. if (a->codec_listen[i] && !a->AdvSignalPLCI) {
  5231. if (a->profile.Global_Options & HANDSET)
  5232. plci->tel = ADV_VOICE;
  5233. else if (a->profile.Global_Options & ON_BOARD_CODEC)
  5234. plci->tel = CODEC;
  5235. if (plci->tel) Id |= EXT_CONTROLLER;
  5236. a->codec_listen[i] = plci;
  5237. }
  5238. sendf(&application[i], _CONNECT_I, Id, 0,
  5239. "wSSSSSSSbSSSSS", cip, /* CIP */
  5240. parms[0], /* CalledPartyNumber */
  5241. multi_CiPN_parms[0], /* CallingPartyNumber */
  5242. parms[2], /* CalledPartySubad */
  5243. parms[3], /* CallingPartySubad */
  5244. parms[4], /* BearerCapability */
  5245. parms[5], /* LowLC */
  5246. parms[6], /* HighLC */
  5247. ai_len, /* nested struct add_i */
  5248. add_i[0], /* B channel info */
  5249. add_i[1], /* keypad facility */
  5250. add_i[2], /* user user data */
  5251. add_i[3], /* nested facility */
  5252. multi_CiPN_parms[1] /* second CiPN(SCR) */
  5253. );
  5254. SendSSExtInd(&application[i],
  5255. plci,
  5256. Id,
  5257. multi_ssext_parms);
  5258. SendSetupInfo(&application[i],
  5259. plci,
  5260. Id,
  5261. parms,
  5262. SendMultiIE(plci, Id, multi_pi_parms, PI, 0x210, true));
  5263. }
  5264. }
  5265. clear_c_ind_mask_bit(plci, MAX_APPL);
  5266. dump_c_ind_mask(plci);
  5267. }
  5268. if (c_ind_mask_empty(plci)) {
  5269. sig_req(plci, HANGUP, 0);
  5270. send_req(plci);
  5271. plci->State = IDLE;
  5272. }
  5273. plci->notifiedcall = 0;
  5274. a->listen_active--;
  5275. listen_check(a);
  5276. break;
  5277. case CALL_PEND_NOTIFY:
  5278. plci->notifiedcall = 1;
  5279. listen_check(a);
  5280. break;
  5281. case CALL_IND:
  5282. case CALL_CON:
  5283. if (plci->State == ADVANCED_VOICE_SIG || plci->State == ADVANCED_VOICE_NOSIG)
  5284. {
  5285. if (plci->internal_command == PERM_COD_CONN_PEND)
  5286. {
  5287. if (plci->State == ADVANCED_VOICE_NOSIG)
  5288. {
  5289. dbug(1, dprintf("***Codec OK"));
  5290. if (a->AdvSignalPLCI)
  5291. {
  5292. tplci = a->AdvSignalPLCI;
  5293. if (tplci->spoofed_msg)
  5294. {
  5295. dbug(1, dprintf("***Spoofed Msg(0x%x)", tplci->spoofed_msg));
  5296. tplci->command = 0;
  5297. tplci->internal_command = 0;
  5298. x_Id = ((word)tplci->Id << 8) | tplci->adapter->Id | 0x80;
  5299. switch (tplci->spoofed_msg)
  5300. {
  5301. case CALL_RES:
  5302. tplci->command = _CONNECT_I | RESPONSE;
  5303. api_load_msg(&tplci->saved_msg, saved_parms);
  5304. add_b1(tplci, &saved_parms[1], 0, tplci->B1_facilities);
  5305. if (tplci->adapter->Info_Mask[tplci->appl->Id - 1] & 0x200)
  5306. {
  5307. /* early B3 connect (CIP mask bit 9) no release after a disc */
  5308. add_p(tplci, LLI, "\x01\x01");
  5309. }
  5310. add_s(tplci, CONN_NR, &saved_parms[2]);
  5311. add_s(tplci, LLC, &saved_parms[4]);
  5312. add_ai(tplci, &saved_parms[5]);
  5313. tplci->State = INC_CON_ACCEPT;
  5314. sig_req(tplci, CALL_RES, 0);
  5315. send_req(tplci);
  5316. break;
  5317. case AWAITING_SELECT_B:
  5318. dbug(1, dprintf("Select_B continue"));
  5319. start_internal_command(x_Id, tplci, select_b_command);
  5320. break;
  5321. case AWAITING_MANUF_CON: /* Get_Plci per Manufacturer_Req to ext controller */
  5322. if (!tplci->Sig.Id)
  5323. {
  5324. dbug(1, dprintf("No SigID!"));
  5325. sendf(tplci->appl, _MANUFACTURER_R | CONFIRM, x_Id, tplci->number, "dww", _DI_MANU_ID, _MANUFACTURER_R, _OUT_OF_PLCI);
  5326. plci_remove(tplci);
  5327. break;
  5328. }
  5329. tplci->command = _MANUFACTURER_R;
  5330. api_load_msg(&tplci->saved_msg, saved_parms);
  5331. dir = saved_parms[2].info[0];
  5332. if (dir == 1) {
  5333. sig_req(tplci, CALL_REQ, 0);
  5334. }
  5335. else if (!dir) {
  5336. sig_req(tplci, LISTEN_REQ, 0);
  5337. }
  5338. send_req(tplci);
  5339. sendf(tplci->appl, _MANUFACTURER_R | CONFIRM, x_Id, tplci->number, "dww", _DI_MANU_ID, _MANUFACTURER_R, 0);
  5340. break;
  5341. case (CALL_REQ | AWAITING_MANUF_CON):
  5342. sig_req(tplci, CALL_REQ, 0);
  5343. send_req(tplci);
  5344. break;
  5345. case CALL_REQ:
  5346. if (!tplci->Sig.Id)
  5347. {
  5348. dbug(1, dprintf("No SigID!"));
  5349. sendf(tplci->appl, _CONNECT_R | CONFIRM, tplci->adapter->Id, 0, "w", _OUT_OF_PLCI);
  5350. plci_remove(tplci);
  5351. break;
  5352. }
  5353. tplci->command = _CONNECT_R;
  5354. api_load_msg(&tplci->saved_msg, saved_parms);
  5355. add_s(tplci, CPN, &saved_parms[1]);
  5356. add_s(tplci, DSA, &saved_parms[3]);
  5357. add_ai(tplci, &saved_parms[9]);
  5358. sig_req(tplci, CALL_REQ, 0);
  5359. send_req(tplci);
  5360. break;
  5361. case CALL_RETRIEVE:
  5362. tplci->command = C_RETRIEVE_REQ;
  5363. sig_req(tplci, CALL_RETRIEVE, 0);
  5364. send_req(tplci);
  5365. break;
  5366. }
  5367. tplci->spoofed_msg = 0;
  5368. if (tplci->internal_command == 0)
  5369. next_internal_command(x_Id, tplci);
  5370. }
  5371. }
  5372. next_internal_command(Id, plci);
  5373. break;
  5374. }
  5375. dbug(1, dprintf("***Codec Hook Init Req"));
  5376. plci->internal_command = PERM_COD_HOOK;
  5377. add_p(plci, FTY, "\x01\x09"); /* Get Hook State*/
  5378. sig_req(plci, TEL_CTRL, 0);
  5379. send_req(plci);
  5380. }
  5381. }
  5382. else if (plci->command != _MANUFACTURER_R /* old style permanent connect */
  5383. && plci->State != INC_ACT_PENDING)
  5384. {
  5385. mixer_set_bchannel_id_esc(plci, plci->b_channel);
  5386. if (plci->tel == ADV_VOICE && plci->SuppState == IDLE) /* with permanent codec switch on immediately */
  5387. {
  5388. chi[2] = plci->b_channel;
  5389. SetVoiceChannel(a->AdvCodecPLCI, chi, a);
  5390. }
  5391. sendf(plci->appl, _CONNECT_ACTIVE_I, Id, 0, "Sss", parms[21], "", "");
  5392. plci->State = INC_ACT_PENDING;
  5393. }
  5394. break;
  5395. case TEL_CTRL:
  5396. ie = multi_fac_parms[0]; /* inspect the facility hook indications */
  5397. if (plci->State == ADVANCED_VOICE_SIG && ie[0]) {
  5398. switch (ie[1] & 0x91) {
  5399. case 0x80: /* hook off */
  5400. case 0x81:
  5401. if (plci->internal_command == PERM_COD_HOOK)
  5402. {
  5403. dbug(1, dprintf("init:hook_off"));
  5404. plci->hook_state = ie[1];
  5405. next_internal_command(Id, plci);
  5406. break;
  5407. }
  5408. else /* ignore doubled hook indications */
  5409. {
  5410. if (((plci->hook_state) & 0xf0) == 0x80)
  5411. {
  5412. dbug(1, dprintf("ignore hook"));
  5413. break;
  5414. }
  5415. plci->hook_state = ie[1]&0x91;
  5416. }
  5417. /* check for incoming call pending */
  5418. /* and signal '+'.Appl must decide */
  5419. /* with connect_res if call must */
  5420. /* accepted or not */
  5421. for (i = 0, tplci = NULL; i < max_appl; i++) {
  5422. if (a->codec_listen[i]
  5423. && (a->codec_listen[i]->State == INC_CON_PENDING
  5424. || a->codec_listen[i]->State == INC_CON_ALERT)) {
  5425. tplci = a->codec_listen[i];
  5426. tplci->appl = &application[i];
  5427. }
  5428. }
  5429. /* no incoming call, do outgoing call */
  5430. /* and signal '+' if outg. setup */
  5431. if (!a->AdvSignalPLCI && !tplci) {
  5432. if ((i = get_plci(a))) {
  5433. a->AdvSignalPLCI = &a->plci[i - 1];
  5434. tplci = a->AdvSignalPLCI;
  5435. tplci->tel = ADV_VOICE;
  5436. PUT_WORD(&voice_cai[5], a->AdvSignalAppl->MaxDataLength);
  5437. if (a->Info_Mask[a->AdvSignalAppl->Id - 1] & 0x200) {
  5438. /* early B3 connect (CIP mask bit 9) no release after a disc */
  5439. add_p(tplci, LLI, "\x01\x01");
  5440. }
  5441. add_p(tplci, CAI, voice_cai);
  5442. add_p(tplci, OAD, a->TelOAD);
  5443. add_p(tplci, OSA, a->TelOSA);
  5444. add_p(tplci, SHIFT | 6, NULL);
  5445. add_p(tplci, SIN, "\x02\x01\x00");
  5446. add_p(tplci, UID, "\x06\x43\x61\x70\x69\x32\x30");
  5447. sig_req(tplci, ASSIGN, DSIG_ID);
  5448. a->AdvSignalPLCI->internal_command = HOOK_OFF_REQ;
  5449. a->AdvSignalPLCI->command = 0;
  5450. tplci->appl = a->AdvSignalAppl;
  5451. tplci->call_dir = CALL_DIR_OUT | CALL_DIR_ORIGINATE;
  5452. send_req(tplci);
  5453. }
  5454. }
  5455. if (!tplci) break;
  5456. Id = ((word)tplci->Id << 8) | a->Id;
  5457. Id |= EXT_CONTROLLER;
  5458. sendf(tplci->appl,
  5459. _FACILITY_I,
  5460. Id,
  5461. 0,
  5462. "ws", (word)0, "\x01+");
  5463. break;
  5464. case 0x90: /* hook on */
  5465. case 0x91:
  5466. if (plci->internal_command == PERM_COD_HOOK)
  5467. {
  5468. dbug(1, dprintf("init:hook_on"));
  5469. plci->hook_state = ie[1] & 0x91;
  5470. next_internal_command(Id, plci);
  5471. break;
  5472. }
  5473. else /* ignore doubled hook indications */
  5474. {
  5475. if (((plci->hook_state) & 0xf0) == 0x90) break;
  5476. plci->hook_state = ie[1] & 0x91;
  5477. }
  5478. /* hangup the adv. voice call and signal '-' to the appl */
  5479. if (a->AdvSignalPLCI) {
  5480. Id = ((word)a->AdvSignalPLCI->Id << 8) | a->Id;
  5481. if (plci->tel) Id |= EXT_CONTROLLER;
  5482. sendf(a->AdvSignalAppl,
  5483. _FACILITY_I,
  5484. Id,
  5485. 0,
  5486. "ws", (word)0, "\x01-");
  5487. a->AdvSignalPLCI->internal_command = HOOK_ON_REQ;
  5488. a->AdvSignalPLCI->command = 0;
  5489. sig_req(a->AdvSignalPLCI, HANGUP, 0);
  5490. send_req(a->AdvSignalPLCI);
  5491. }
  5492. break;
  5493. }
  5494. }
  5495. break;
  5496. case RESUME:
  5497. clear_c_ind_mask_bit(plci, (word)(plci->appl->Id - 1));
  5498. PUT_WORD(&resume_cau[4], GOOD);
  5499. sendf(plci->appl, _FACILITY_I, Id, 0, "ws", (word)3, resume_cau);
  5500. break;
  5501. case SUSPEND:
  5502. clear_c_ind_mask(plci);
  5503. if (plci->NL.Id && !plci->nl_remove_id) {
  5504. mixer_remove(plci);
  5505. nl_req_ncci(plci, REMOVE, 0);
  5506. }
  5507. if (!plci->sig_remove_id) {
  5508. plci->internal_command = 0;
  5509. sig_req(plci, REMOVE, 0);
  5510. }
  5511. send_req(plci);
  5512. if (!plci->channels) {
  5513. sendf(plci->appl, _FACILITY_I, Id, 0, "ws", (word)3, "\x05\x04\x00\x02\x00\x00");
  5514. sendf(plci->appl, _DISCONNECT_I, Id, 0, "w", 0);
  5515. }
  5516. break;
  5517. case SUSPEND_REJ:
  5518. break;
  5519. case HANGUP:
  5520. plci->hangup_flow_ctrl_timer = 0;
  5521. if (plci->manufacturer && plci->State == LOCAL_CONNECT) break;
  5522. cau = parms[7];
  5523. if (cau) {
  5524. i = _L3_CAUSE | cau[2];
  5525. if (cau[2] == 0) i = 0;
  5526. else if (cau[2] == 8) i = _L1_ERROR;
  5527. else if (cau[2] == 9 || cau[2] == 10) i = _L2_ERROR;
  5528. else if (cau[2] == 5) i = _CAPI_GUARD_ERROR;
  5529. }
  5530. else {
  5531. i = _L3_ERROR;
  5532. }
  5533. if (plci->State == INC_CON_PENDING || plci->State == INC_CON_ALERT)
  5534. {
  5535. for (i = 0; i < max_appl; i++)
  5536. {
  5537. if (test_c_ind_mask_bit(plci, i))
  5538. sendf(&application[i], _DISCONNECT_I, Id, 0, "w", 0);
  5539. }
  5540. }
  5541. else
  5542. {
  5543. clear_c_ind_mask(plci);
  5544. }
  5545. if (!plci->appl)
  5546. {
  5547. if (plci->State == LISTENING)
  5548. {
  5549. plci->notifiedcall = 0;
  5550. a->listen_active--;
  5551. }
  5552. plci->State = INC_DIS_PENDING;
  5553. if (c_ind_mask_empty(plci))
  5554. {
  5555. plci->State = IDLE;
  5556. if (plci->NL.Id && !plci->nl_remove_id)
  5557. {
  5558. mixer_remove(plci);
  5559. nl_req_ncci(plci, REMOVE, 0);
  5560. }
  5561. if (!plci->sig_remove_id)
  5562. {
  5563. plci->internal_command = 0;
  5564. sig_req(plci, REMOVE, 0);
  5565. }
  5566. send_req(plci);
  5567. }
  5568. }
  5569. else
  5570. {
  5571. /* collision of DISCONNECT or CONNECT_RES with HANGUP can */
  5572. /* result in a second HANGUP! Don't generate another */
  5573. /* DISCONNECT */
  5574. if (plci->State != IDLE && plci->State != INC_DIS_PENDING)
  5575. {
  5576. if (plci->State == RESUMING)
  5577. {
  5578. PUT_WORD(&resume_cau[4], i);
  5579. sendf(plci->appl, _FACILITY_I, Id, 0, "ws", (word)3, resume_cau);
  5580. }
  5581. plci->State = INC_DIS_PENDING;
  5582. sendf(plci->appl, _DISCONNECT_I, Id, 0, "w", i);
  5583. }
  5584. }
  5585. break;
  5586. case SSEXT_IND:
  5587. SendSSExtInd(NULL, plci, Id, multi_ssext_parms);
  5588. break;
  5589. case VSWITCH_REQ:
  5590. VSwitchReqInd(plci, Id, multi_vswitch_parms);
  5591. break;
  5592. case VSWITCH_IND:
  5593. if (plci->relatedPTYPLCI &&
  5594. plci->vswitchstate == 3 &&
  5595. plci->relatedPTYPLCI->vswitchstate == 3 &&
  5596. parms[MAXPARMSIDS - 1][0])
  5597. {
  5598. add_p(plci->relatedPTYPLCI, SMSG, parms[MAXPARMSIDS - 1]);
  5599. sig_req(plci->relatedPTYPLCI, VSWITCH_REQ, 0);
  5600. send_req(plci->relatedPTYPLCI);
  5601. }
  5602. else VSwitchReqInd(plci, Id, multi_vswitch_parms);
  5603. break;
  5604. }
  5605. }
  5606. static void SendSetupInfo(APPL *appl, PLCI *plci, dword Id, byte **parms, byte Info_Sent_Flag)
  5607. {
  5608. word i;
  5609. byte *ie;
  5610. word Info_Number;
  5611. byte *Info_Element;
  5612. word Info_Mask = 0;
  5613. dbug(1, dprintf("SetupInfo"));
  5614. for (i = 0; i < MAXPARMSIDS; i++) {
  5615. ie = parms[i];
  5616. Info_Number = 0;
  5617. Info_Element = ie;
  5618. if (ie[0]) {
  5619. switch (i) {
  5620. case 0:
  5621. dbug(1, dprintf("CPN "));
  5622. Info_Number = 0x0070;
  5623. Info_Mask = 0x80;
  5624. Info_Sent_Flag = true;
  5625. break;
  5626. case 8: /* display */
  5627. dbug(1, dprintf("display(%d)", i));
  5628. Info_Number = 0x0028;
  5629. Info_Mask = 0x04;
  5630. Info_Sent_Flag = true;
  5631. break;
  5632. case 16: /* Channel Id */
  5633. dbug(1, dprintf("CHI"));
  5634. Info_Number = 0x0018;
  5635. Info_Mask = 0x100;
  5636. Info_Sent_Flag = true;
  5637. mixer_set_bchannel_id(plci, Info_Element);
  5638. break;
  5639. case 19: /* Redirected Number */
  5640. dbug(1, dprintf("RDN"));
  5641. Info_Number = 0x0074;
  5642. Info_Mask = 0x400;
  5643. Info_Sent_Flag = true;
  5644. break;
  5645. case 20: /* Redirected Number extended */
  5646. dbug(1, dprintf("RDX"));
  5647. Info_Number = 0x0073;
  5648. Info_Mask = 0x400;
  5649. Info_Sent_Flag = true;
  5650. break;
  5651. case 22: /* Redirecing Number */
  5652. dbug(1, dprintf("RIN"));
  5653. Info_Number = 0x0076;
  5654. Info_Mask = 0x400;
  5655. Info_Sent_Flag = true;
  5656. break;
  5657. default:
  5658. Info_Number = 0;
  5659. break;
  5660. }
  5661. }
  5662. if (i == MAXPARMSIDS - 2) { /* to indicate the message type "Setup" */
  5663. Info_Number = 0x8000 | 5;
  5664. Info_Mask = 0x10;
  5665. Info_Element = "";
  5666. }
  5667. if (Info_Sent_Flag && Info_Number) {
  5668. if (plci->adapter->Info_Mask[appl->Id - 1] & Info_Mask) {
  5669. sendf(appl, _INFO_I, Id, 0, "wS", Info_Number, Info_Element);
  5670. }
  5671. }
  5672. }
  5673. }
  5674. static void SendInfo(PLCI *plci, dword Id, byte **parms, byte iesent)
  5675. {
  5676. word i;
  5677. word j;
  5678. word k;
  5679. byte *ie;
  5680. word Info_Number;
  5681. byte *Info_Element;
  5682. word Info_Mask = 0;
  5683. static byte charges[5] = {4, 0, 0, 0, 0};
  5684. static byte cause[] = {0x02, 0x80, 0x00};
  5685. APPL *appl;
  5686. dbug(1, dprintf("InfoParse "));
  5687. if (
  5688. !plci->appl
  5689. && !plci->State
  5690. && plci->Sig.Ind != NCR_FACILITY
  5691. )
  5692. {
  5693. dbug(1, dprintf("NoParse "));
  5694. return;
  5695. }
  5696. cause[2] = 0;
  5697. for (i = 0; i < MAXPARMSIDS; i++) {
  5698. ie = parms[i];
  5699. Info_Number = 0;
  5700. Info_Element = ie;
  5701. if (ie[0]) {
  5702. switch (i) {
  5703. case 0:
  5704. dbug(1, dprintf("CPN "));
  5705. Info_Number = 0x0070;
  5706. Info_Mask = 0x80;
  5707. break;
  5708. case 7: /* ESC_CAU */
  5709. dbug(1, dprintf("cau(0x%x)", ie[2]));
  5710. Info_Number = 0x0008;
  5711. Info_Mask = 0x00;
  5712. cause[2] = ie[2];
  5713. Info_Element = NULL;
  5714. break;
  5715. case 8: /* display */
  5716. dbug(1, dprintf("display(%d)", i));
  5717. Info_Number = 0x0028;
  5718. Info_Mask = 0x04;
  5719. break;
  5720. case 9: /* Date display */
  5721. dbug(1, dprintf("date(%d)", i));
  5722. Info_Number = 0x0029;
  5723. Info_Mask = 0x02;
  5724. break;
  5725. case 10: /* charges */
  5726. for (j = 0; j < 4; j++) charges[1 + j] = 0;
  5727. for (j = 0; j < ie[0] && !(ie[1 + j] & 0x80); j++);
  5728. for (k = 1, j++; j < ie[0] && k <= 4; j++, k++) charges[k] = ie[1 + j];
  5729. Info_Number = 0x4000;
  5730. Info_Mask = 0x40;
  5731. Info_Element = charges;
  5732. break;
  5733. case 11: /* user user info */
  5734. dbug(1, dprintf("uui"));
  5735. Info_Number = 0x007E;
  5736. Info_Mask = 0x08;
  5737. break;
  5738. case 12: /* congestion receiver ready */
  5739. dbug(1, dprintf("clRDY"));
  5740. Info_Number = 0x00B0;
  5741. Info_Mask = 0x08;
  5742. Info_Element = "";
  5743. break;
  5744. case 13: /* congestion receiver not ready */
  5745. dbug(1, dprintf("clNRDY"));
  5746. Info_Number = 0x00BF;
  5747. Info_Mask = 0x08;
  5748. Info_Element = "";
  5749. break;
  5750. case 15: /* Keypad Facility */
  5751. dbug(1, dprintf("KEY"));
  5752. Info_Number = 0x002C;
  5753. Info_Mask = 0x20;
  5754. break;
  5755. case 16: /* Channel Id */
  5756. dbug(1, dprintf("CHI"));
  5757. Info_Number = 0x0018;
  5758. Info_Mask = 0x100;
  5759. mixer_set_bchannel_id(plci, Info_Element);
  5760. break;
  5761. case 17: /* if no 1tr6 cause, send full cause, else esc_cause */
  5762. dbug(1, dprintf("q9cau(0x%x)", ie[2]));
  5763. if (!cause[2] || cause[2] < 0x80) break; /* eg. layer 1 error */
  5764. Info_Number = 0x0008;
  5765. Info_Mask = 0x01;
  5766. if (cause[2] != ie[2]) Info_Element = cause;
  5767. break;
  5768. case 19: /* Redirected Number */
  5769. dbug(1, dprintf("RDN"));
  5770. Info_Number = 0x0074;
  5771. Info_Mask = 0x400;
  5772. break;
  5773. case 22: /* Redirecing Number */
  5774. dbug(1, dprintf("RIN"));
  5775. Info_Number = 0x0076;
  5776. Info_Mask = 0x400;
  5777. break;
  5778. case 23: /* Notification Indicator */
  5779. dbug(1, dprintf("NI"));
  5780. Info_Number = (word)NI;
  5781. Info_Mask = 0x210;
  5782. break;
  5783. case 26: /* Call State */
  5784. dbug(1, dprintf("CST"));
  5785. Info_Number = (word)CST;
  5786. Info_Mask = 0x01; /* do with cause i.e. for now */
  5787. break;
  5788. case MAXPARMSIDS - 2: /* Escape Message Type, must be the last indication */
  5789. dbug(1, dprintf("ESC/MT[0x%x]", ie[3]));
  5790. Info_Number = 0x8000 | ie[3];
  5791. if (iesent) Info_Mask = 0xffff;
  5792. else Info_Mask = 0x10;
  5793. Info_Element = "";
  5794. break;
  5795. default:
  5796. Info_Number = 0;
  5797. Info_Mask = 0;
  5798. Info_Element = "";
  5799. break;
  5800. }
  5801. }
  5802. if (plci->Sig.Ind == NCR_FACILITY) /* check controller broadcast */
  5803. {
  5804. for (j = 0; j < max_appl; j++)
  5805. {
  5806. appl = &application[j];
  5807. if (Info_Number
  5808. && appl->Id
  5809. && plci->adapter->Info_Mask[appl->Id - 1] & Info_Mask)
  5810. {
  5811. dbug(1, dprintf("NCR_Ind"));
  5812. iesent = true;
  5813. sendf(&application[j], _INFO_I, Id & 0x0f, 0, "wS", Info_Number, Info_Element);
  5814. }
  5815. }
  5816. }
  5817. else if (!plci->appl)
  5818. { /* overlap receiving broadcast */
  5819. if (Info_Number == CPN
  5820. || Info_Number == KEY
  5821. || Info_Number == NI
  5822. || Info_Number == DSP
  5823. || Info_Number == UUI)
  5824. {
  5825. for (j = 0; j < max_appl; j++)
  5826. {
  5827. if (test_c_ind_mask_bit(plci, j))
  5828. {
  5829. dbug(1, dprintf("Ovl_Ind"));
  5830. iesent = true;
  5831. sendf(&application[j], _INFO_I, Id, 0, "wS", Info_Number, Info_Element);
  5832. }
  5833. }
  5834. }
  5835. } /* all other signalling states */
  5836. else if (Info_Number
  5837. && plci->adapter->Info_Mask[plci->appl->Id - 1] & Info_Mask)
  5838. {
  5839. dbug(1, dprintf("Std_Ind"));
  5840. iesent = true;
  5841. sendf(plci->appl, _INFO_I, Id, 0, "wS", Info_Number, Info_Element);
  5842. }
  5843. }
  5844. }
  5845. static byte SendMultiIE(PLCI *plci, dword Id, byte **parms, byte ie_type,
  5846. dword info_mask, byte setupParse)
  5847. {
  5848. word i;
  5849. word j;
  5850. byte *ie;
  5851. word Info_Number;
  5852. byte *Info_Element;
  5853. APPL *appl;
  5854. word Info_Mask = 0;
  5855. byte iesent = 0;
  5856. if (
  5857. !plci->appl
  5858. && !plci->State
  5859. && plci->Sig.Ind != NCR_FACILITY
  5860. && !setupParse
  5861. )
  5862. {
  5863. dbug(1, dprintf("NoM-IEParse "));
  5864. return 0;
  5865. }
  5866. dbug(1, dprintf("M-IEParse "));
  5867. for (i = 0; i < MAX_MULTI_IE; i++)
  5868. {
  5869. ie = parms[i];
  5870. Info_Number = 0;
  5871. Info_Element = ie;
  5872. if (ie[0])
  5873. {
  5874. dbug(1, dprintf("[Ind0x%x]:IE=0x%x", plci->Sig.Ind, ie_type));
  5875. Info_Number = (word)ie_type;
  5876. Info_Mask = (word)info_mask;
  5877. }
  5878. if (plci->Sig.Ind == NCR_FACILITY) /* check controller broadcast */
  5879. {
  5880. for (j = 0; j < max_appl; j++)
  5881. {
  5882. appl = &application[j];
  5883. if (Info_Number
  5884. && appl->Id
  5885. && plci->adapter->Info_Mask[appl->Id - 1] & Info_Mask)
  5886. {
  5887. iesent = true;
  5888. dbug(1, dprintf("Mlt_NCR_Ind"));
  5889. sendf(&application[j], _INFO_I, Id & 0x0f, 0, "wS", Info_Number, Info_Element);
  5890. }
  5891. }
  5892. }
  5893. else if (!plci->appl && Info_Number)
  5894. { /* overlap receiving broadcast */
  5895. for (j = 0; j < max_appl; j++)
  5896. {
  5897. if (test_c_ind_mask_bit(plci, j))
  5898. {
  5899. iesent = true;
  5900. dbug(1, dprintf("Mlt_Ovl_Ind"));
  5901. sendf(&application[j] , _INFO_I, Id, 0, "wS", Info_Number, Info_Element);
  5902. }
  5903. }
  5904. } /* all other signalling states */
  5905. else if (Info_Number
  5906. && plci->adapter->Info_Mask[plci->appl->Id - 1] & Info_Mask)
  5907. {
  5908. iesent = true;
  5909. dbug(1, dprintf("Mlt_Std_Ind"));
  5910. sendf(plci->appl, _INFO_I, Id, 0, "wS", Info_Number, Info_Element);
  5911. }
  5912. }
  5913. return iesent;
  5914. }
  5915. static void SendSSExtInd(APPL *appl, PLCI *plci, dword Id, byte **parms)
  5916. {
  5917. word i;
  5918. /* Format of multi_ssext_parms[i][]:
  5919. 0 byte length
  5920. 1 byte SSEXTIE
  5921. 2 byte SSEXT_REQ/SSEXT_IND
  5922. 3 byte length
  5923. 4 word SSExtCommand
  5924. 6... Params
  5925. */
  5926. if (
  5927. plci
  5928. && plci->State
  5929. && plci->Sig.Ind != NCR_FACILITY
  5930. )
  5931. for (i = 0; i < MAX_MULTI_IE; i++)
  5932. {
  5933. if (parms[i][0] < 6) continue;
  5934. if (parms[i][2] == SSEXT_REQ) continue;
  5935. if (appl)
  5936. {
  5937. parms[i][0] = 0; /* kill it */
  5938. sendf(appl, _MANUFACTURER_I,
  5939. Id,
  5940. 0,
  5941. "dwS",
  5942. _DI_MANU_ID,
  5943. _DI_SSEXT_CTRL,
  5944. &parms[i][3]);
  5945. }
  5946. else if (plci->appl)
  5947. {
  5948. parms[i][0] = 0; /* kill it */
  5949. sendf(plci->appl, _MANUFACTURER_I,
  5950. Id,
  5951. 0,
  5952. "dwS",
  5953. _DI_MANU_ID,
  5954. _DI_SSEXT_CTRL,
  5955. &parms[i][3]);
  5956. }
  5957. }
  5958. };
  5959. static void nl_ind(PLCI *plci)
  5960. {
  5961. byte ch;
  5962. word ncci;
  5963. dword Id;
  5964. DIVA_CAPI_ADAPTER *a;
  5965. word NCCIcode;
  5966. APPL *APPLptr;
  5967. word count;
  5968. word Num;
  5969. word i, ncpi_state;
  5970. byte len, ncci_state;
  5971. word msg;
  5972. word info = 0;
  5973. word fax_feature_bits;
  5974. byte fax_send_edata_ack;
  5975. static byte v120_header_buffer[2 + 3];
  5976. static word fax_info[] = {
  5977. 0, /* T30_SUCCESS */
  5978. _FAX_NO_CONNECTION, /* T30_ERR_NO_DIS_RECEIVED */
  5979. _FAX_PROTOCOL_ERROR, /* T30_ERR_TIMEOUT_NO_RESPONSE */
  5980. _FAX_PROTOCOL_ERROR, /* T30_ERR_RETRY_NO_RESPONSE */
  5981. _FAX_PROTOCOL_ERROR, /* T30_ERR_TOO_MANY_REPEATS */
  5982. _FAX_PROTOCOL_ERROR, /* T30_ERR_UNEXPECTED_MESSAGE */
  5983. _FAX_REMOTE_ABORT, /* T30_ERR_UNEXPECTED_DCN */
  5984. _FAX_LOCAL_ABORT, /* T30_ERR_DTC_UNSUPPORTED */
  5985. _FAX_TRAINING_ERROR, /* T30_ERR_ALL_RATES_FAILED */
  5986. _FAX_TRAINING_ERROR, /* T30_ERR_TOO_MANY_TRAINS */
  5987. _FAX_PARAMETER_ERROR, /* T30_ERR_RECEIVE_CORRUPTED */
  5988. _FAX_REMOTE_ABORT, /* T30_ERR_UNEXPECTED_DISC */
  5989. _FAX_LOCAL_ABORT, /* T30_ERR_APPLICATION_DISC */
  5990. _FAX_REMOTE_REJECT, /* T30_ERR_INCOMPATIBLE_DIS */
  5991. _FAX_LOCAL_ABORT, /* T30_ERR_INCOMPATIBLE_DCS */
  5992. _FAX_PROTOCOL_ERROR, /* T30_ERR_TIMEOUT_NO_COMMAND */
  5993. _FAX_PROTOCOL_ERROR, /* T30_ERR_RETRY_NO_COMMAND */
  5994. _FAX_PROTOCOL_ERROR, /* T30_ERR_TIMEOUT_COMMAND_TOO_LONG */
  5995. _FAX_PROTOCOL_ERROR, /* T30_ERR_TIMEOUT_RESPONSE_TOO_LONG */
  5996. _FAX_NO_CONNECTION, /* T30_ERR_NOT_IDENTIFIED */
  5997. _FAX_PROTOCOL_ERROR, /* T30_ERR_SUPERVISORY_TIMEOUT */
  5998. _FAX_PARAMETER_ERROR, /* T30_ERR_TOO_LONG_SCAN_LINE */
  5999. _FAX_PROTOCOL_ERROR, /* T30_ERR_RETRY_NO_PAGE_AFTER_MPS */
  6000. _FAX_PROTOCOL_ERROR, /* T30_ERR_RETRY_NO_PAGE_AFTER_CFR */
  6001. _FAX_PROTOCOL_ERROR, /* T30_ERR_RETRY_NO_DCS_AFTER_FTT */
  6002. _FAX_PROTOCOL_ERROR, /* T30_ERR_RETRY_NO_DCS_AFTER_EOM */
  6003. _FAX_PROTOCOL_ERROR, /* T30_ERR_RETRY_NO_DCS_AFTER_MPS */
  6004. _FAX_PROTOCOL_ERROR, /* T30_ERR_RETRY_NO_DCN_AFTER_MCF */
  6005. _FAX_PROTOCOL_ERROR, /* T30_ERR_RETRY_NO_DCN_AFTER_RTN */
  6006. _FAX_PROTOCOL_ERROR, /* T30_ERR_RETRY_NO_CFR */
  6007. _FAX_PROTOCOL_ERROR, /* T30_ERR_RETRY_NO_MCF_AFTER_EOP */
  6008. _FAX_PROTOCOL_ERROR, /* T30_ERR_RETRY_NO_MCF_AFTER_EOM */
  6009. _FAX_PROTOCOL_ERROR, /* T30_ERR_RETRY_NO_MCF_AFTER_MPS */
  6010. 0x331d, /* T30_ERR_SUB_SEP_UNSUPPORTED */
  6011. 0x331e, /* T30_ERR_PWD_UNSUPPORTED */
  6012. 0x331f, /* T30_ERR_SUB_SEP_PWD_UNSUPPORTED */
  6013. _FAX_PROTOCOL_ERROR, /* T30_ERR_INVALID_COMMAND_FRAME */
  6014. _FAX_PARAMETER_ERROR, /* T30_ERR_UNSUPPORTED_PAGE_CODING */
  6015. _FAX_PARAMETER_ERROR, /* T30_ERR_INVALID_PAGE_CODING */
  6016. _FAX_REMOTE_REJECT, /* T30_ERR_INCOMPATIBLE_PAGE_CONFIG */
  6017. _FAX_LOCAL_ABORT, /* T30_ERR_TIMEOUT_FROM_APPLICATION */
  6018. _FAX_PROTOCOL_ERROR, /* T30_ERR_V34FAX_NO_REACTION_ON_MARK */
  6019. _FAX_PROTOCOL_ERROR, /* T30_ERR_V34FAX_TRAINING_TIMEOUT */
  6020. _FAX_PROTOCOL_ERROR, /* T30_ERR_V34FAX_UNEXPECTED_V21 */
  6021. _FAX_PROTOCOL_ERROR, /* T30_ERR_V34FAX_PRIMARY_CTS_ON */
  6022. _FAX_LOCAL_ABORT, /* T30_ERR_V34FAX_TURNAROUND_POLLING */
  6023. _FAX_LOCAL_ABORT /* T30_ERR_V34FAX_V8_INCOMPATIBILITY */
  6024. };
  6025. byte dtmf_code_buffer[CAPIDTMF_RECV_DIGIT_BUFFER_SIZE + 1];
  6026. static word rtp_info[] = {
  6027. GOOD, /* RTP_SUCCESS */
  6028. 0x3600 /* RTP_ERR_SSRC_OR_PAYLOAD_CHANGE */
  6029. };
  6030. static dword udata_forwarding_table[0x100 / sizeof(dword)] =
  6031. {
  6032. 0x0020301e, 0x00000000, 0x00000000, 0x00000000,
  6033. 0x00000000, 0x00000000, 0x00000000, 0x00000000
  6034. };
  6035. ch = plci->NL.IndCh;
  6036. a = plci->adapter;
  6037. ncci = a->ch_ncci[ch];
  6038. Id = (((dword)(ncci ? ncci : ch)) << 16) | (((word) plci->Id) << 8) | a->Id;
  6039. if (plci->tel) Id |= EXT_CONTROLLER;
  6040. APPLptr = plci->appl;
  6041. 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",
  6042. plci->NL.Id, Id, plci->Id, plci->tel, plci->State, ch, plci->channels, plci->NL.Ind & 0x0f));
  6043. /* in the case if no connect_active_Ind was sent to the appl we wait for */
  6044. if (plci->nl_remove_id)
  6045. {
  6046. plci->NL.RNR = 2; /* discard */
  6047. dbug(1, dprintf("NL discard while remove pending"));
  6048. return;
  6049. }
  6050. if ((plci->NL.Ind & 0x0f) == N_CONNECT)
  6051. {
  6052. if (plci->State == INC_DIS_PENDING
  6053. || plci->State == OUTG_DIS_PENDING
  6054. || plci->State == IDLE)
  6055. {
  6056. plci->NL.RNR = 2; /* discard */
  6057. dbug(1, dprintf("discard n_connect"));
  6058. return;
  6059. }
  6060. if (plci->State < INC_ACT_PENDING)
  6061. {
  6062. plci->NL.RNR = 1; /* flow control */
  6063. channel_x_off(plci, ch, N_XON_CONNECT_IND);
  6064. return;
  6065. }
  6066. }
  6067. if (!APPLptr) /* no application or invalid data */
  6068. { /* while reloading the DSP */
  6069. dbug(1, dprintf("discard1"));
  6070. plci->NL.RNR = 2;
  6071. return;
  6072. }
  6073. if (((plci->NL.Ind & 0x0f) == N_UDATA)
  6074. && (((plci->B2_prot != B2_SDLC) && ((plci->B1_resource == 17) || (plci->B1_resource == 18)))
  6075. || (plci->B2_prot == 7)
  6076. || (plci->B3_prot == 7)))
  6077. {
  6078. plci->ncpi_buffer[0] = 0;
  6079. ncpi_state = plci->ncpi_state;
  6080. if (plci->NL.complete == 1)
  6081. {
  6082. byte *data = &plci->NL.RBuffer->P[0];
  6083. if ((plci->NL.RBuffer->length >= 12)
  6084. && ((*data == DSP_UDATA_INDICATION_DCD_ON)
  6085. || (*data == DSP_UDATA_INDICATION_CTS_ON)))
  6086. {
  6087. word conn_opt, ncpi_opt = 0x00;
  6088. /* HexDump ("MDM N_UDATA:", plci->NL.RBuffer->length, data); */
  6089. if (*data == DSP_UDATA_INDICATION_DCD_ON)
  6090. plci->ncpi_state |= NCPI_MDM_DCD_ON_RECEIVED;
  6091. if (*data == DSP_UDATA_INDICATION_CTS_ON)
  6092. plci->ncpi_state |= NCPI_MDM_CTS_ON_RECEIVED;
  6093. data++; /* indication code */
  6094. data += 2; /* timestamp */
  6095. if ((*data == DSP_CONNECTED_NORM_V18) || (*data == DSP_CONNECTED_NORM_VOWN))
  6096. ncpi_state &= ~(NCPI_MDM_DCD_ON_RECEIVED | NCPI_MDM_CTS_ON_RECEIVED);
  6097. data++; /* connected norm */
  6098. conn_opt = GET_WORD(data);
  6099. data += 2; /* connected options */
  6100. PUT_WORD(&(plci->ncpi_buffer[1]), (word)(GET_DWORD(data) & 0x0000FFFF));
  6101. if (conn_opt & DSP_CONNECTED_OPTION_MASK_V42)
  6102. {
  6103. ncpi_opt |= MDM_NCPI_ECM_V42;
  6104. }
  6105. else if (conn_opt & DSP_CONNECTED_OPTION_MASK_MNP)
  6106. {
  6107. ncpi_opt |= MDM_NCPI_ECM_MNP;
  6108. }
  6109. else
  6110. {
  6111. ncpi_opt |= MDM_NCPI_TRANSPARENT;
  6112. }
  6113. if (conn_opt & DSP_CONNECTED_OPTION_MASK_COMPRESSION)
  6114. {
  6115. ncpi_opt |= MDM_NCPI_COMPRESSED;
  6116. }
  6117. PUT_WORD(&(plci->ncpi_buffer[3]), ncpi_opt);
  6118. plci->ncpi_buffer[0] = 4;
  6119. plci->ncpi_state |= NCPI_VALID_CONNECT_B3_IND | NCPI_VALID_CONNECT_B3_ACT | NCPI_VALID_DISC_B3_IND;
  6120. }
  6121. }
  6122. if (plci->B3_prot == 7)
  6123. {
  6124. if (((a->ncci_state[ncci] == INC_ACT_PENDING) || (a->ncci_state[ncci] == OUTG_CON_PENDING))
  6125. && (plci->ncpi_state & NCPI_VALID_CONNECT_B3_ACT)
  6126. && !(plci->ncpi_state & NCPI_CONNECT_B3_ACT_SENT))
  6127. {
  6128. a->ncci_state[ncci] = INC_ACT_PENDING;
  6129. sendf(plci->appl, _CONNECT_B3_ACTIVE_I, Id, 0, "S", plci->ncpi_buffer);
  6130. plci->ncpi_state |= NCPI_CONNECT_B3_ACT_SENT;
  6131. }
  6132. }
  6133. if (!((plci->requested_options_conn | plci->requested_options | plci->adapter->requested_options_table[plci->appl->Id - 1])
  6134. & ((1L << PRIVATE_V18) | (1L << PRIVATE_VOWN)))
  6135. || !(ncpi_state & NCPI_MDM_DCD_ON_RECEIVED)
  6136. || !(ncpi_state & NCPI_MDM_CTS_ON_RECEIVED))
  6137. {
  6138. plci->NL.RNR = 2;
  6139. return;
  6140. }
  6141. }
  6142. if (plci->NL.complete == 2)
  6143. {
  6144. if (((plci->NL.Ind & 0x0f) == N_UDATA)
  6145. && !(udata_forwarding_table[plci->RData[0].P[0] >> 5] & (1L << (plci->RData[0].P[0] & 0x1f))))
  6146. {
  6147. switch (plci->RData[0].P[0])
  6148. {
  6149. case DTMF_UDATA_INDICATION_FAX_CALLING_TONE:
  6150. if (plci->dtmf_rec_active & DTMF_LISTEN_ACTIVE_FLAG)
  6151. sendf(plci->appl, _FACILITY_I, Id & 0xffffL, 0, "ws", SELECTOR_DTMF, "\x01X");
  6152. break;
  6153. case DTMF_UDATA_INDICATION_ANSWER_TONE:
  6154. if (plci->dtmf_rec_active & DTMF_LISTEN_ACTIVE_FLAG)
  6155. sendf(plci->appl, _FACILITY_I, Id & 0xffffL, 0, "ws", SELECTOR_DTMF, "\x01Y");
  6156. break;
  6157. case DTMF_UDATA_INDICATION_DIGITS_RECEIVED:
  6158. dtmf_indication(Id, plci, plci->RData[0].P, plci->RData[0].PLength);
  6159. break;
  6160. case DTMF_UDATA_INDICATION_DIGITS_SENT:
  6161. dtmf_confirmation(Id, plci);
  6162. break;
  6163. case UDATA_INDICATION_MIXER_TAP_DATA:
  6164. capidtmf_recv_process_block(&(plci->capidtmf_state), plci->RData[0].P + 1, (word)(plci->RData[0].PLength - 1));
  6165. i = capidtmf_indication(&(plci->capidtmf_state), dtmf_code_buffer + 1);
  6166. if (i != 0)
  6167. {
  6168. dtmf_code_buffer[0] = DTMF_UDATA_INDICATION_DIGITS_RECEIVED;
  6169. dtmf_indication(Id, plci, dtmf_code_buffer, (word)(i + 1));
  6170. }
  6171. break;
  6172. case UDATA_INDICATION_MIXER_COEFS_SET:
  6173. mixer_indication_coefs_set(Id, plci);
  6174. break;
  6175. case UDATA_INDICATION_XCONNECT_FROM:
  6176. mixer_indication_xconnect_from(Id, plci, plci->RData[0].P, plci->RData[0].PLength);
  6177. break;
  6178. case UDATA_INDICATION_XCONNECT_TO:
  6179. mixer_indication_xconnect_to(Id, plci, plci->RData[0].P, plci->RData[0].PLength);
  6180. break;
  6181. case LEC_UDATA_INDICATION_DISABLE_DETECT:
  6182. ec_indication(Id, plci, plci->RData[0].P, plci->RData[0].PLength);
  6183. break;
  6184. default:
  6185. break;
  6186. }
  6187. }
  6188. else
  6189. {
  6190. if ((plci->RData[0].PLength != 0)
  6191. && ((plci->B2_prot == B2_V120_ASYNC)
  6192. || (plci->B2_prot == B2_V120_ASYNC_V42BIS)
  6193. || (plci->B2_prot == B2_V120_BIT_TRANSPARENT)))
  6194. {
  6195. sendf(plci->appl, _DATA_B3_I, Id, 0,
  6196. "dwww",
  6197. plci->RData[1].P,
  6198. (plci->NL.RNum < 2) ? 0 : plci->RData[1].PLength,
  6199. plci->RNum,
  6200. plci->RFlags);
  6201. }
  6202. else
  6203. {
  6204. sendf(plci->appl, _DATA_B3_I, Id, 0,
  6205. "dwww",
  6206. plci->RData[0].P,
  6207. plci->RData[0].PLength,
  6208. plci->RNum,
  6209. plci->RFlags);
  6210. }
  6211. }
  6212. return;
  6213. }
  6214. fax_feature_bits = 0;
  6215. if ((plci->NL.Ind & 0x0f) == N_CONNECT ||
  6216. (plci->NL.Ind & 0x0f) == N_CONNECT_ACK ||
  6217. (plci->NL.Ind & 0x0f) == N_DISC ||
  6218. (plci->NL.Ind & 0x0f) == N_EDATA ||
  6219. (plci->NL.Ind & 0x0f) == N_DISC_ACK)
  6220. {
  6221. info = 0;
  6222. plci->ncpi_buffer[0] = 0;
  6223. switch (plci->B3_prot) {
  6224. case 0: /*XPARENT*/
  6225. case 1: /*T.90 NL*/
  6226. break; /* no network control protocol info - jfr */
  6227. case 2: /*ISO8202*/
  6228. case 3: /*X25 DCE*/
  6229. for (i = 0; i < plci->NL.RLength; i++) plci->ncpi_buffer[4 + i] = plci->NL.RBuffer->P[i];
  6230. plci->ncpi_buffer[0] = (byte)(i + 3);
  6231. plci->ncpi_buffer[1] = (byte)(plci->NL.Ind & N_D_BIT ? 1 : 0);
  6232. plci->ncpi_buffer[2] = 0;
  6233. plci->ncpi_buffer[3] = 0;
  6234. break;
  6235. case 4: /*T.30 - FAX*/
  6236. case 5: /*T.30 - FAX*/
  6237. if (plci->NL.RLength >= sizeof(T30_INFO))
  6238. {
  6239. dbug(1, dprintf("FaxStatus %04x", ((T30_INFO *)plci->NL.RBuffer->P)->code));
  6240. len = 9;
  6241. PUT_WORD(&(plci->ncpi_buffer[1]), ((T30_INFO *)plci->NL.RBuffer->P)->rate_div_2400 * 2400);
  6242. fax_feature_bits = GET_WORD(&((T30_INFO *)plci->NL.RBuffer->P)->feature_bits_low);
  6243. i = (((T30_INFO *)plci->NL.RBuffer->P)->resolution & T30_RESOLUTION_R8_0770_OR_200) ? 0x0001 : 0x0000;
  6244. if (plci->B3_prot == 5)
  6245. {
  6246. if (!(fax_feature_bits & T30_FEATURE_BIT_ECM))
  6247. i |= 0x8000; /* This is not an ECM connection */
  6248. if (fax_feature_bits & T30_FEATURE_BIT_T6_CODING)
  6249. i |= 0x4000; /* This is a connection with MMR compression */
  6250. if (fax_feature_bits & T30_FEATURE_BIT_2D_CODING)
  6251. i |= 0x2000; /* This is a connection with MR compression */
  6252. if (fax_feature_bits & T30_FEATURE_BIT_MORE_DOCUMENTS)
  6253. i |= 0x0004; /* More documents */
  6254. if (fax_feature_bits & T30_FEATURE_BIT_POLLING)
  6255. i |= 0x0002; /* Fax-polling indication */
  6256. }
  6257. dbug(1, dprintf("FAX Options %04x %04x", fax_feature_bits, i));
  6258. PUT_WORD(&(plci->ncpi_buffer[3]), i);
  6259. PUT_WORD(&(plci->ncpi_buffer[5]), ((T30_INFO *)plci->NL.RBuffer->P)->data_format);
  6260. plci->ncpi_buffer[7] = ((T30_INFO *)plci->NL.RBuffer->P)->pages_low;
  6261. plci->ncpi_buffer[8] = ((T30_INFO *)plci->NL.RBuffer->P)->pages_high;
  6262. plci->ncpi_buffer[len] = 0;
  6263. if (((T30_INFO *)plci->NL.RBuffer->P)->station_id_len)
  6264. {
  6265. plci->ncpi_buffer[len] = 20;
  6266. for (i = 0; i < T30_MAX_STATION_ID_LENGTH; i++)
  6267. plci->ncpi_buffer[++len] = ((T30_INFO *)plci->NL.RBuffer->P)->station_id[i];
  6268. }
  6269. if (((plci->NL.Ind & 0x0f) == N_DISC) || ((plci->NL.Ind & 0x0f) == N_DISC_ACK))
  6270. {
  6271. if (((T30_INFO *)plci->NL.RBuffer->P)->code < ARRAY_SIZE(fax_info))
  6272. info = fax_info[((T30_INFO *)plci->NL.RBuffer->P)->code];
  6273. else
  6274. info = _FAX_PROTOCOL_ERROR;
  6275. }
  6276. if ((plci->requested_options_conn | plci->requested_options | a->requested_options_table[plci->appl->Id - 1])
  6277. & ((1L << PRIVATE_FAX_SUB_SEP_PWD) | (1L << PRIVATE_FAX_NONSTANDARD)))
  6278. {
  6279. i = offsetof(T30_INFO, station_id) + T30_MAX_STATION_ID_LENGTH + ((T30_INFO *)plci->NL.RBuffer->P)->head_line_len;
  6280. while (i < plci->NL.RBuffer->length)
  6281. plci->ncpi_buffer[++len] = plci->NL.RBuffer->P[i++];
  6282. }
  6283. plci->ncpi_buffer[0] = len;
  6284. fax_feature_bits = GET_WORD(&((T30_INFO *)plci->NL.RBuffer->P)->feature_bits_low);
  6285. PUT_WORD(&((T30_INFO *)plci->fax_connect_info_buffer)->feature_bits_low, fax_feature_bits);
  6286. plci->ncpi_state |= NCPI_VALID_CONNECT_B3_IND;
  6287. if (((plci->NL.Ind & 0x0f) == N_CONNECT_ACK)
  6288. || (((plci->NL.Ind & 0x0f) == N_CONNECT)
  6289. && (fax_feature_bits & T30_FEATURE_BIT_POLLING))
  6290. || (((plci->NL.Ind & 0x0f) == N_EDATA)
  6291. && ((((T30_INFO *)plci->NL.RBuffer->P)->code == EDATA_T30_TRAIN_OK)
  6292. || (((T30_INFO *)plci->NL.RBuffer->P)->code == EDATA_T30_DIS)
  6293. || (((T30_INFO *)plci->NL.RBuffer->P)->code == EDATA_T30_DTC))))
  6294. {
  6295. plci->ncpi_state |= NCPI_VALID_CONNECT_B3_ACT;
  6296. }
  6297. if (((plci->NL.Ind & 0x0f) == N_DISC)
  6298. || ((plci->NL.Ind & 0x0f) == N_DISC_ACK)
  6299. || (((plci->NL.Ind & 0x0f) == N_EDATA)
  6300. && (((T30_INFO *)plci->NL.RBuffer->P)->code == EDATA_T30_EOP_CAPI)))
  6301. {
  6302. plci->ncpi_state |= NCPI_VALID_CONNECT_B3_ACT | NCPI_VALID_DISC_B3_IND;
  6303. }
  6304. }
  6305. break;
  6306. case B3_RTP:
  6307. if (((plci->NL.Ind & 0x0f) == N_DISC) || ((plci->NL.Ind & 0x0f) == N_DISC_ACK))
  6308. {
  6309. if (plci->NL.RLength != 0)
  6310. {
  6311. info = rtp_info[plci->NL.RBuffer->P[0]];
  6312. plci->ncpi_buffer[0] = plci->NL.RLength - 1;
  6313. for (i = 1; i < plci->NL.RLength; i++)
  6314. plci->ncpi_buffer[i] = plci->NL.RBuffer->P[i];
  6315. }
  6316. }
  6317. break;
  6318. }
  6319. plci->NL.RNR = 2;
  6320. }
  6321. switch (plci->NL.Ind & 0x0f) {
  6322. case N_EDATA:
  6323. if ((plci->B3_prot == 4) || (plci->B3_prot == 5))
  6324. {
  6325. dbug(1, dprintf("EDATA ncci=0x%x state=%d code=%02x", ncci, a->ncci_state[ncci],
  6326. ((T30_INFO *)plci->NL.RBuffer->P)->code));
  6327. fax_send_edata_ack = (((T30_INFO *)(plci->fax_connect_info_buffer))->operating_mode == T30_OPERATING_MODE_CAPI_NEG);
  6328. if ((plci->nsf_control_bits & T30_NSF_CONTROL_BIT_ENABLE_NSF)
  6329. && (plci->nsf_control_bits & (T30_NSF_CONTROL_BIT_NEGOTIATE_IND | T30_NSF_CONTROL_BIT_NEGOTIATE_RESP))
  6330. && (((T30_INFO *)plci->NL.RBuffer->P)->code == EDATA_T30_DIS)
  6331. && (a->ncci_state[ncci] == OUTG_CON_PENDING)
  6332. && (plci->ncpi_state & NCPI_VALID_CONNECT_B3_ACT)
  6333. && !(plci->ncpi_state & NCPI_NEGOTIATE_B3_SENT))
  6334. {
  6335. ((T30_INFO *)(plci->fax_connect_info_buffer))->code = ((T30_INFO *)plci->NL.RBuffer->P)->code;
  6336. sendf(plci->appl, _MANUFACTURER_I, Id, 0, "dwbS", _DI_MANU_ID, _DI_NEGOTIATE_B3,
  6337. (byte)(plci->ncpi_buffer[0] + 1), plci->ncpi_buffer);
  6338. plci->ncpi_state |= NCPI_NEGOTIATE_B3_SENT;
  6339. if (plci->nsf_control_bits & T30_NSF_CONTROL_BIT_NEGOTIATE_RESP)
  6340. fax_send_edata_ack = false;
  6341. }
  6342. if (a->manufacturer_features & MANUFACTURER_FEATURE_FAX_PAPER_FORMATS)
  6343. {
  6344. switch (((T30_INFO *)plci->NL.RBuffer->P)->code)
  6345. {
  6346. case EDATA_T30_DIS:
  6347. if ((a->ncci_state[ncci] == OUTG_CON_PENDING)
  6348. && !(GET_WORD(&((T30_INFO *)plci->fax_connect_info_buffer)->control_bits_low) & T30_CONTROL_BIT_REQUEST_POLLING)
  6349. && (plci->ncpi_state & NCPI_VALID_CONNECT_B3_ACT)
  6350. && !(plci->ncpi_state & NCPI_CONNECT_B3_ACT_SENT))
  6351. {
  6352. a->ncci_state[ncci] = INC_ACT_PENDING;
  6353. if (plci->B3_prot == 4)
  6354. sendf(plci->appl, _CONNECT_B3_ACTIVE_I, Id, 0, "s", "");
  6355. else
  6356. sendf(plci->appl, _CONNECT_B3_ACTIVE_I, Id, 0, "S", plci->ncpi_buffer);
  6357. plci->ncpi_state |= NCPI_CONNECT_B3_ACT_SENT;
  6358. }
  6359. break;
  6360. case EDATA_T30_TRAIN_OK:
  6361. if ((a->ncci_state[ncci] == INC_ACT_PENDING)
  6362. && (plci->ncpi_state & NCPI_VALID_CONNECT_B3_ACT)
  6363. && !(plci->ncpi_state & NCPI_CONNECT_B3_ACT_SENT))
  6364. {
  6365. if (plci->B3_prot == 4)
  6366. sendf(plci->appl, _CONNECT_B3_ACTIVE_I, Id, 0, "s", "");
  6367. else
  6368. sendf(plci->appl, _CONNECT_B3_ACTIVE_I, Id, 0, "S", plci->ncpi_buffer);
  6369. plci->ncpi_state |= NCPI_CONNECT_B3_ACT_SENT;
  6370. }
  6371. break;
  6372. case EDATA_T30_EOP_CAPI:
  6373. if (a->ncci_state[ncci] == CONNECTED)
  6374. {
  6375. sendf(plci->appl, _DISCONNECT_B3_I, Id, 0, "wS", GOOD, plci->ncpi_buffer);
  6376. a->ncci_state[ncci] = INC_DIS_PENDING;
  6377. plci->ncpi_state = 0;
  6378. fax_send_edata_ack = false;
  6379. }
  6380. break;
  6381. }
  6382. }
  6383. else
  6384. {
  6385. switch (((T30_INFO *)plci->NL.RBuffer->P)->code)
  6386. {
  6387. case EDATA_T30_TRAIN_OK:
  6388. if ((a->ncci_state[ncci] == INC_ACT_PENDING)
  6389. && (plci->ncpi_state & NCPI_VALID_CONNECT_B3_ACT)
  6390. && !(plci->ncpi_state & NCPI_CONNECT_B3_ACT_SENT))
  6391. {
  6392. if (plci->B3_prot == 4)
  6393. sendf(plci->appl, _CONNECT_B3_ACTIVE_I, Id, 0, "s", "");
  6394. else
  6395. sendf(plci->appl, _CONNECT_B3_ACTIVE_I, Id, 0, "S", plci->ncpi_buffer);
  6396. plci->ncpi_state |= NCPI_CONNECT_B3_ACT_SENT;
  6397. }
  6398. break;
  6399. }
  6400. }
  6401. if (fax_send_edata_ack)
  6402. {
  6403. ((T30_INFO *)(plci->fax_connect_info_buffer))->code = ((T30_INFO *)plci->NL.RBuffer->P)->code;
  6404. plci->fax_edata_ack_length = 1;
  6405. start_internal_command(Id, plci, fax_edata_ack_command);
  6406. }
  6407. }
  6408. else
  6409. {
  6410. dbug(1, dprintf("EDATA ncci=0x%x state=%d", ncci, a->ncci_state[ncci]));
  6411. }
  6412. break;
  6413. case N_CONNECT:
  6414. if (!a->ch_ncci[ch])
  6415. {
  6416. ncci = get_ncci(plci, ch, 0);
  6417. Id = (Id & 0xffff) | (((dword) ncci) << 16);
  6418. }
  6419. dbug(1, dprintf("N_CONNECT: ch=%d state=%d plci=%lx plci_Id=%lx plci_State=%d",
  6420. ch, a->ncci_state[ncci], a->ncci_plci[ncci], plci->Id, plci->State));
  6421. msg = _CONNECT_B3_I;
  6422. if (a->ncci_state[ncci] == IDLE)
  6423. plci->channels++;
  6424. else if (plci->B3_prot == 1)
  6425. msg = _CONNECT_B3_T90_ACTIVE_I;
  6426. a->ncci_state[ncci] = INC_CON_PENDING;
  6427. if (plci->B3_prot == 4)
  6428. sendf(plci->appl, msg, Id, 0, "s", "");
  6429. else
  6430. sendf(plci->appl, msg, Id, 0, "S", plci->ncpi_buffer);
  6431. break;
  6432. case N_CONNECT_ACK:
  6433. dbug(1, dprintf("N_connect_Ack"));
  6434. if (plci->internal_command_queue[0]
  6435. && ((plci->adjust_b_state == ADJUST_B_CONNECT_2)
  6436. || (plci->adjust_b_state == ADJUST_B_CONNECT_3)
  6437. || (plci->adjust_b_state == ADJUST_B_CONNECT_4)))
  6438. {
  6439. (*(plci->internal_command_queue[0]))(Id, plci, 0);
  6440. if (!plci->internal_command)
  6441. next_internal_command(Id, plci);
  6442. break;
  6443. }
  6444. msg = _CONNECT_B3_ACTIVE_I;
  6445. if (plci->B3_prot == 1)
  6446. {
  6447. if (a->ncci_state[ncci] != OUTG_CON_PENDING)
  6448. msg = _CONNECT_B3_T90_ACTIVE_I;
  6449. a->ncci_state[ncci] = INC_ACT_PENDING;
  6450. sendf(plci->appl, msg, Id, 0, "S", plci->ncpi_buffer);
  6451. }
  6452. else if ((plci->B3_prot == 4) || (plci->B3_prot == 5) || (plci->B3_prot == 7))
  6453. {
  6454. if ((a->ncci_state[ncci] == OUTG_CON_PENDING)
  6455. && (plci->ncpi_state & NCPI_VALID_CONNECT_B3_ACT)
  6456. && !(plci->ncpi_state & NCPI_CONNECT_B3_ACT_SENT))
  6457. {
  6458. a->ncci_state[ncci] = INC_ACT_PENDING;
  6459. if (plci->B3_prot == 4)
  6460. sendf(plci->appl, msg, Id, 0, "s", "");
  6461. else
  6462. sendf(plci->appl, msg, Id, 0, "S", plci->ncpi_buffer);
  6463. plci->ncpi_state |= NCPI_CONNECT_B3_ACT_SENT;
  6464. }
  6465. }
  6466. else
  6467. {
  6468. a->ncci_state[ncci] = INC_ACT_PENDING;
  6469. sendf(plci->appl, msg, Id, 0, "S", plci->ncpi_buffer);
  6470. }
  6471. if (plci->adjust_b_restore)
  6472. {
  6473. plci->adjust_b_restore = false;
  6474. start_internal_command(Id, plci, adjust_b_restore);
  6475. }
  6476. break;
  6477. case N_DISC:
  6478. case N_DISC_ACK:
  6479. if (plci->internal_command_queue[0]
  6480. && ((plci->internal_command == FAX_DISCONNECT_COMMAND_1)
  6481. || (plci->internal_command == FAX_DISCONNECT_COMMAND_2)
  6482. || (plci->internal_command == FAX_DISCONNECT_COMMAND_3)))
  6483. {
  6484. (*(plci->internal_command_queue[0]))(Id, plci, 0);
  6485. if (!plci->internal_command)
  6486. next_internal_command(Id, plci);
  6487. }
  6488. ncci_state = a->ncci_state[ncci];
  6489. ncci_remove(plci, ncci, false);
  6490. /* with N_DISC or N_DISC_ACK the IDI frees the respective */
  6491. /* channel, so we cannot store the state in ncci_state! The */
  6492. /* information which channel we received a N_DISC is thus */
  6493. /* stored in the inc_dis_ncci_table buffer. */
  6494. for (i = 0; plci->inc_dis_ncci_table[i]; i++);
  6495. plci->inc_dis_ncci_table[i] = (byte) ncci;
  6496. /* need a connect_b3_ind before a disconnect_b3_ind with FAX */
  6497. if (!plci->channels
  6498. && (plci->B1_resource == 16)
  6499. && (plci->State <= CONNECTED))
  6500. {
  6501. len = 9;
  6502. i = ((T30_INFO *)plci->fax_connect_info_buffer)->rate_div_2400 * 2400;
  6503. PUT_WORD(&plci->ncpi_buffer[1], i);
  6504. PUT_WORD(&plci->ncpi_buffer[3], 0);
  6505. i = ((T30_INFO *)plci->fax_connect_info_buffer)->data_format;
  6506. PUT_WORD(&plci->ncpi_buffer[5], i);
  6507. PUT_WORD(&plci->ncpi_buffer[7], 0);
  6508. plci->ncpi_buffer[len] = 0;
  6509. plci->ncpi_buffer[0] = len;
  6510. if (plci->B3_prot == 4)
  6511. sendf(plci->appl, _CONNECT_B3_I, Id, 0, "s", "");
  6512. else
  6513. {
  6514. if ((plci->requested_options_conn | plci->requested_options | a->requested_options_table[plci->appl->Id - 1])
  6515. & ((1L << PRIVATE_FAX_SUB_SEP_PWD) | (1L << PRIVATE_FAX_NONSTANDARD)))
  6516. {
  6517. plci->ncpi_buffer[++len] = 0;
  6518. plci->ncpi_buffer[++len] = 0;
  6519. plci->ncpi_buffer[++len] = 0;
  6520. plci->ncpi_buffer[0] = len;
  6521. }
  6522. sendf(plci->appl, _CONNECT_B3_I, Id, 0, "S", plci->ncpi_buffer);
  6523. }
  6524. sendf(plci->appl, _DISCONNECT_B3_I, Id, 0, "wS", info, plci->ncpi_buffer);
  6525. plci->ncpi_state = 0;
  6526. sig_req(plci, HANGUP, 0);
  6527. send_req(plci);
  6528. plci->State = OUTG_DIS_PENDING;
  6529. /* disc here */
  6530. }
  6531. else if ((a->manufacturer_features & MANUFACTURER_FEATURE_FAX_PAPER_FORMATS)
  6532. && ((plci->B3_prot == 4) || (plci->B3_prot == 5))
  6533. && ((ncci_state == INC_DIS_PENDING) || (ncci_state == IDLE)))
  6534. {
  6535. if (ncci_state == IDLE)
  6536. {
  6537. if (plci->channels)
  6538. plci->channels--;
  6539. if ((plci->State == IDLE || plci->State == SUSPENDING) && !plci->channels) {
  6540. if (plci->State == SUSPENDING) {
  6541. sendf(plci->appl,
  6542. _FACILITY_I,
  6543. Id & 0xffffL,
  6544. 0,
  6545. "ws", (word)3, "\x03\x04\x00\x00");
  6546. sendf(plci->appl, _DISCONNECT_I, Id & 0xffffL, 0, "w", 0);
  6547. }
  6548. plci_remove(plci);
  6549. plci->State = IDLE;
  6550. }
  6551. }
  6552. }
  6553. else if (plci->channels)
  6554. {
  6555. sendf(plci->appl, _DISCONNECT_B3_I, Id, 0, "wS", info, plci->ncpi_buffer);
  6556. plci->ncpi_state = 0;
  6557. if ((ncci_state == OUTG_REJ_PENDING)
  6558. && ((plci->B3_prot != B3_T90NL) && (plci->B3_prot != B3_ISO8208) && (plci->B3_prot != B3_X25_DCE)))
  6559. {
  6560. sig_req(plci, HANGUP, 0);
  6561. send_req(plci);
  6562. plci->State = OUTG_DIS_PENDING;
  6563. }
  6564. }
  6565. break;
  6566. case N_RESET:
  6567. a->ncci_state[ncci] = INC_RES_PENDING;
  6568. sendf(plci->appl, _RESET_B3_I, Id, 0, "S", plci->ncpi_buffer);
  6569. break;
  6570. case N_RESET_ACK:
  6571. a->ncci_state[ncci] = CONNECTED;
  6572. sendf(plci->appl, _RESET_B3_I, Id, 0, "S", plci->ncpi_buffer);
  6573. break;
  6574. case N_UDATA:
  6575. if (!(udata_forwarding_table[plci->NL.RBuffer->P[0] >> 5] & (1L << (plci->NL.RBuffer->P[0] & 0x1f))))
  6576. {
  6577. plci->RData[0].P = plci->internal_ind_buffer + (-((int)(long)(plci->internal_ind_buffer)) & 3);
  6578. plci->RData[0].PLength = INTERNAL_IND_BUFFER_SIZE;
  6579. plci->NL.R = plci->RData;
  6580. plci->NL.RNum = 1;
  6581. return;
  6582. }
  6583. case N_BDATA:
  6584. case N_DATA:
  6585. if (((a->ncci_state[ncci] != CONNECTED) && (plci->B2_prot == 1)) /* transparent */
  6586. || (a->ncci_state[ncci] == IDLE)
  6587. || (a->ncci_state[ncci] == INC_DIS_PENDING))
  6588. {
  6589. plci->NL.RNR = 2;
  6590. break;
  6591. }
  6592. if ((a->ncci_state[ncci] != CONNECTED)
  6593. && (a->ncci_state[ncci] != OUTG_DIS_PENDING)
  6594. && (a->ncci_state[ncci] != OUTG_REJ_PENDING))
  6595. {
  6596. dbug(1, dprintf("flow control"));
  6597. plci->NL.RNR = 1; /* flow control */
  6598. channel_x_off(plci, ch, 0);
  6599. break;
  6600. }
  6601. NCCIcode = ncci | (((word)a->Id) << 8);
  6602. /* count all buffers within the Application pool */
  6603. /* belonging to the same NCCI. If this is below the */
  6604. /* number of buffers available per NCCI we accept */
  6605. /* this packet, otherwise we reject it */
  6606. count = 0;
  6607. Num = 0xffff;
  6608. for (i = 0; i < APPLptr->MaxBuffer; i++) {
  6609. if (NCCIcode == APPLptr->DataNCCI[i]) count++;
  6610. if (!APPLptr->DataNCCI[i] && Num == 0xffff) Num = i;
  6611. }
  6612. if (count >= APPLptr->MaxNCCIData || Num == 0xffff)
  6613. {
  6614. dbug(3, dprintf("Flow-Control"));
  6615. plci->NL.RNR = 1;
  6616. if (++(APPLptr->NCCIDataFlowCtrlTimer) >=
  6617. (word)((a->manufacturer_features & MANUFACTURER_FEATURE_OOB_CHANNEL) ? 40 : 2000))
  6618. {
  6619. plci->NL.RNR = 2;
  6620. dbug(3, dprintf("DiscardData"));
  6621. } else {
  6622. channel_x_off(plci, ch, 0);
  6623. }
  6624. break;
  6625. }
  6626. else
  6627. {
  6628. APPLptr->NCCIDataFlowCtrlTimer = 0;
  6629. }
  6630. plci->RData[0].P = ReceiveBufferGet(APPLptr, Num);
  6631. if (!plci->RData[0].P) {
  6632. plci->NL.RNR = 1;
  6633. channel_x_off(plci, ch, 0);
  6634. break;
  6635. }
  6636. APPLptr->DataNCCI[Num] = NCCIcode;
  6637. APPLptr->DataFlags[Num] = (plci->Id << 8) | (plci->NL.Ind >> 4);
  6638. dbug(3, dprintf("Buffer(%d), Max = %d", Num, APPLptr->MaxBuffer));
  6639. plci->RNum = Num;
  6640. plci->RFlags = plci->NL.Ind >> 4;
  6641. plci->RData[0].PLength = APPLptr->MaxDataLength;
  6642. plci->NL.R = plci->RData;
  6643. if ((plci->NL.RLength != 0)
  6644. && ((plci->B2_prot == B2_V120_ASYNC)
  6645. || (plci->B2_prot == B2_V120_ASYNC_V42BIS)
  6646. || (plci->B2_prot == B2_V120_BIT_TRANSPARENT)))
  6647. {
  6648. plci->RData[1].P = plci->RData[0].P;
  6649. plci->RData[1].PLength = plci->RData[0].PLength;
  6650. plci->RData[0].P = v120_header_buffer + (-((unsigned long)v120_header_buffer) & 3);
  6651. if ((plci->NL.RBuffer->P[0] & V120_HEADER_EXTEND_BIT) || (plci->NL.RLength == 1))
  6652. plci->RData[0].PLength = 1;
  6653. else
  6654. plci->RData[0].PLength = 2;
  6655. if (plci->NL.RBuffer->P[0] & V120_HEADER_BREAK_BIT)
  6656. plci->RFlags |= 0x0010;
  6657. if (plci->NL.RBuffer->P[0] & (V120_HEADER_C1_BIT | V120_HEADER_C2_BIT))
  6658. plci->RFlags |= 0x8000;
  6659. plci->NL.RNum = 2;
  6660. }
  6661. else
  6662. {
  6663. if ((plci->NL.Ind & 0x0f) == N_UDATA)
  6664. plci->RFlags |= 0x0010;
  6665. else if ((plci->B3_prot == B3_RTP) && ((plci->NL.Ind & 0x0f) == N_BDATA))
  6666. plci->RFlags |= 0x0001;
  6667. plci->NL.RNum = 1;
  6668. }
  6669. break;
  6670. case N_DATA_ACK:
  6671. data_ack(plci, ch);
  6672. break;
  6673. default:
  6674. plci->NL.RNR = 2;
  6675. break;
  6676. }
  6677. }
  6678. /*------------------------------------------------------------------*/
  6679. /* find a free PLCI */
  6680. /*------------------------------------------------------------------*/
  6681. static word get_plci(DIVA_CAPI_ADAPTER *a)
  6682. {
  6683. word i, j;
  6684. PLCI *plci;
  6685. dump_plcis(a);
  6686. for (i = 0; i < a->max_plci && a->plci[i].Id; i++);
  6687. if (i == a->max_plci) {
  6688. dbug(1, dprintf("get_plci: out of PLCIs"));
  6689. return 0;
  6690. }
  6691. plci = &a->plci[i];
  6692. plci->Id = (byte)(i + 1);
  6693. plci->Sig.Id = 0;
  6694. plci->NL.Id = 0;
  6695. plci->sig_req = 0;
  6696. plci->nl_req = 0;
  6697. plci->appl = NULL;
  6698. plci->relatedPTYPLCI = NULL;
  6699. plci->State = IDLE;
  6700. plci->SuppState = IDLE;
  6701. plci->channels = 0;
  6702. plci->tel = 0;
  6703. plci->B1_resource = 0;
  6704. plci->B2_prot = 0;
  6705. plci->B3_prot = 0;
  6706. plci->command = 0;
  6707. plci->m_command = 0;
  6708. init_internal_command_queue(plci);
  6709. plci->number = 0;
  6710. plci->req_in_start = 0;
  6711. plci->req_in = 0;
  6712. plci->req_out = 0;
  6713. plci->msg_in_write_pos = MSG_IN_QUEUE_SIZE;
  6714. plci->msg_in_read_pos = MSG_IN_QUEUE_SIZE;
  6715. plci->msg_in_wrap_pos = MSG_IN_QUEUE_SIZE;
  6716. plci->data_sent = false;
  6717. plci->send_disc = 0;
  6718. plci->sig_global_req = 0;
  6719. plci->sig_remove_id = 0;
  6720. plci->nl_global_req = 0;
  6721. plci->nl_remove_id = 0;
  6722. plci->adv_nl = 0;
  6723. plci->manufacturer = false;
  6724. plci->call_dir = CALL_DIR_OUT | CALL_DIR_ORIGINATE;
  6725. plci->spoofed_msg = 0;
  6726. plci->ptyState = 0;
  6727. plci->cr_enquiry = false;
  6728. plci->hangup_flow_ctrl_timer = 0;
  6729. plci->ncci_ring_list = 0;
  6730. for (j = 0; j < MAX_CHANNELS_PER_PLCI; j++) plci->inc_dis_ncci_table[j] = 0;
  6731. clear_c_ind_mask(plci);
  6732. set_group_ind_mask(plci);
  6733. plci->fax_connect_info_length = 0;
  6734. plci->nsf_control_bits = 0;
  6735. plci->ncpi_state = 0x00;
  6736. plci->ncpi_buffer[0] = 0;
  6737. plci->requested_options_conn = 0;
  6738. plci->requested_options = 0;
  6739. plci->notifiedcall = 0;
  6740. plci->vswitchstate = 0;
  6741. plci->vsprot = 0;
  6742. plci->vsprotdialect = 0;
  6743. init_b1_config(plci);
  6744. dbug(1, dprintf("get_plci(%x)", plci->Id));
  6745. return i + 1;
  6746. }
  6747. /*------------------------------------------------------------------*/
  6748. /* put a parameter in the parameter buffer */
  6749. /*------------------------------------------------------------------*/
  6750. static void add_p(PLCI *plci, byte code, byte *p)
  6751. {
  6752. word p_length;
  6753. p_length = 0;
  6754. if (p) p_length = p[0];
  6755. add_ie(plci, code, p, p_length);
  6756. }
  6757. /*------------------------------------------------------------------*/
  6758. /* put a structure in the parameter buffer */
  6759. /*------------------------------------------------------------------*/
  6760. static void add_s(PLCI *plci, byte code, API_PARSE *p)
  6761. {
  6762. if (p) add_ie(plci, code, p->info, (word)p->length);
  6763. }
  6764. /*------------------------------------------------------------------*/
  6765. /* put multiple structures in the parameter buffer */
  6766. /*------------------------------------------------------------------*/
  6767. static void add_ss(PLCI *plci, byte code, API_PARSE *p)
  6768. {
  6769. byte i;
  6770. if (p) {
  6771. dbug(1, dprintf("add_ss(%x,len=%d)", code, p->length));
  6772. for (i = 2; i < (byte)p->length; i += p->info[i] + 2) {
  6773. dbug(1, dprintf("add_ss_ie(%x,len=%d)", p->info[i - 1], p->info[i]));
  6774. add_ie(plci, p->info[i - 1], (byte *)&(p->info[i]), (word)p->info[i]);
  6775. }
  6776. }
  6777. }
  6778. /*------------------------------------------------------------------*/
  6779. /* return the channel number sent by the application in a esc_chi */
  6780. /*------------------------------------------------------------------*/
  6781. static byte getChannel(API_PARSE *p)
  6782. {
  6783. byte i;
  6784. if (p) {
  6785. for (i = 2; i < (byte)p->length; i += p->info[i] + 2) {
  6786. if (p->info[i] == 2) {
  6787. if (p->info[i - 1] == ESC && p->info[i + 1] == CHI) return (p->info[i + 2]);
  6788. }
  6789. }
  6790. }
  6791. return 0;
  6792. }
  6793. /*------------------------------------------------------------------*/
  6794. /* put an information element in the parameter buffer */
  6795. /*------------------------------------------------------------------*/
  6796. static void add_ie(PLCI *plci, byte code, byte *p, word p_length)
  6797. {
  6798. word i;
  6799. if (!(code & 0x80) && !p_length) return;
  6800. if (plci->req_in == plci->req_in_start) {
  6801. plci->req_in += 2;
  6802. }
  6803. else {
  6804. plci->req_in--;
  6805. }
  6806. plci->RBuffer[plci->req_in++] = code;
  6807. if (p) {
  6808. plci->RBuffer[plci->req_in++] = (byte)p_length;
  6809. for (i = 0; i < p_length; i++) plci->RBuffer[plci->req_in++] = p[1 + i];
  6810. }
  6811. plci->RBuffer[plci->req_in++] = 0;
  6812. }
  6813. /*------------------------------------------------------------------*/
  6814. /* put a unstructured data into the buffer */
  6815. /*------------------------------------------------------------------*/
  6816. static void add_d(PLCI *plci, word length, byte *p)
  6817. {
  6818. word i;
  6819. if (plci->req_in == plci->req_in_start) {
  6820. plci->req_in += 2;
  6821. }
  6822. else {
  6823. plci->req_in--;
  6824. }
  6825. for (i = 0; i < length; i++) plci->RBuffer[plci->req_in++] = p[i];
  6826. }
  6827. /*------------------------------------------------------------------*/
  6828. /* put parameters from the Additional Info parameter in the */
  6829. /* parameter buffer */
  6830. /*------------------------------------------------------------------*/
  6831. static void add_ai(PLCI *plci, API_PARSE *ai)
  6832. {
  6833. word i;
  6834. API_PARSE ai_parms[5];
  6835. for (i = 0; i < 5; i++) ai_parms[i].length = 0;
  6836. if (!ai->length)
  6837. return;
  6838. if (api_parse(&ai->info[1], (word)ai->length, "ssss", ai_parms))
  6839. return;
  6840. add_s(plci, KEY, &ai_parms[1]);
  6841. add_s(plci, UUI, &ai_parms[2]);
  6842. add_ss(plci, FTY, &ai_parms[3]);
  6843. }
  6844. /*------------------------------------------------------------------*/
  6845. /* put parameter for b1 protocol in the parameter buffer */
  6846. /*------------------------------------------------------------------*/
  6847. static word add_b1(PLCI *plci, API_PARSE *bp, word b_channel_info,
  6848. word b1_facilities)
  6849. {
  6850. API_PARSE bp_parms[8];
  6851. API_PARSE mdm_cfg[9];
  6852. API_PARSE global_config[2];
  6853. byte cai[256];
  6854. byte resource[] = {5, 9, 13, 12, 16, 39, 9, 17, 17, 18};
  6855. byte voice_cai[] = "\x06\x14\x00\x00\x00\x00\x08";
  6856. word i;
  6857. API_PARSE mdm_cfg_v18[4];
  6858. word j, n, w;
  6859. dword d;
  6860. for (i = 0; i < 8; i++) bp_parms[i].length = 0;
  6861. for (i = 0; i < 2; i++) global_config[i].length = 0;
  6862. dbug(1, dprintf("add_b1"));
  6863. api_save_msg(bp, "s", &plci->B_protocol);
  6864. if (b_channel_info == 2) {
  6865. plci->B1_resource = 0;
  6866. adjust_b1_facilities(plci, plci->B1_resource, b1_facilities);
  6867. add_p(plci, CAI, "\x01\x00");
  6868. dbug(1, dprintf("Cai=1,0 (no resource)"));
  6869. return 0;
  6870. }
  6871. if (plci->tel == CODEC_PERMANENT) return 0;
  6872. else if (plci->tel == CODEC) {
  6873. plci->B1_resource = 1;
  6874. adjust_b1_facilities(plci, plci->B1_resource, b1_facilities);
  6875. add_p(plci, CAI, "\x01\x01");
  6876. dbug(1, dprintf("Cai=1,1 (Codec)"));
  6877. return 0;
  6878. }
  6879. else if (plci->tel == ADV_VOICE) {
  6880. plci->B1_resource = add_b1_facilities(plci, 9, (word)(b1_facilities | B1_FACILITY_VOICE));
  6881. adjust_b1_facilities(plci, plci->B1_resource, (word)(b1_facilities | B1_FACILITY_VOICE));
  6882. voice_cai[1] = plci->B1_resource;
  6883. PUT_WORD(&voice_cai[5], plci->appl->MaxDataLength);
  6884. add_p(plci, CAI, voice_cai);
  6885. dbug(1, dprintf("Cai=1,0x%x (AdvVoice)", voice_cai[1]));
  6886. return 0;
  6887. }
  6888. plci->call_dir &= ~(CALL_DIR_ORIGINATE | CALL_DIR_ANSWER);
  6889. if (plci->call_dir & CALL_DIR_OUT)
  6890. plci->call_dir |= CALL_DIR_ORIGINATE;
  6891. else if (plci->call_dir & CALL_DIR_IN)
  6892. plci->call_dir |= CALL_DIR_ANSWER;
  6893. if (!bp->length) {
  6894. plci->B1_resource = 0x5;
  6895. adjust_b1_facilities(plci, plci->B1_resource, b1_facilities);
  6896. add_p(plci, CAI, "\x01\x05");
  6897. return 0;
  6898. }
  6899. dbug(1, dprintf("b_prot_len=%d", (word)bp->length));
  6900. if (bp->length > 256) return _WRONG_MESSAGE_FORMAT;
  6901. if (api_parse(&bp->info[1], (word)bp->length, "wwwsssb", bp_parms))
  6902. {
  6903. bp_parms[6].length = 0;
  6904. if (api_parse(&bp->info[1], (word)bp->length, "wwwsss", bp_parms))
  6905. {
  6906. dbug(1, dprintf("b-form.!"));
  6907. return _WRONG_MESSAGE_FORMAT;
  6908. }
  6909. }
  6910. else if (api_parse(&bp->info[1], (word)bp->length, "wwwssss", bp_parms))
  6911. {
  6912. dbug(1, dprintf("b-form.!"));
  6913. return _WRONG_MESSAGE_FORMAT;
  6914. }
  6915. if (bp_parms[6].length)
  6916. {
  6917. if (api_parse(&bp_parms[6].info[1], (word)bp_parms[6].length, "w", global_config))
  6918. {
  6919. return _WRONG_MESSAGE_FORMAT;
  6920. }
  6921. switch (GET_WORD(global_config[0].info))
  6922. {
  6923. case 1:
  6924. plci->call_dir = (plci->call_dir & ~CALL_DIR_ANSWER) | CALL_DIR_ORIGINATE;
  6925. break;
  6926. case 2:
  6927. plci->call_dir = (plci->call_dir & ~CALL_DIR_ORIGINATE) | CALL_DIR_ANSWER;
  6928. break;
  6929. }
  6930. }
  6931. dbug(1, dprintf("call_dir=%04x", plci->call_dir));
  6932. if ((GET_WORD(bp_parms[0].info) == B1_RTP)
  6933. && (plci->adapter->man_profile.private_options & (1L << PRIVATE_RTP)))
  6934. {
  6935. plci->B1_resource = add_b1_facilities(plci, 31, (word)(b1_facilities & ~B1_FACILITY_VOICE));
  6936. adjust_b1_facilities(plci, plci->B1_resource, (word)(b1_facilities & ~B1_FACILITY_VOICE));
  6937. cai[1] = plci->B1_resource;
  6938. cai[2] = 0;
  6939. cai[3] = 0;
  6940. cai[4] = 0;
  6941. PUT_WORD(&cai[5], plci->appl->MaxDataLength);
  6942. for (i = 0; i < bp_parms[3].length; i++)
  6943. cai[7 + i] = bp_parms[3].info[1 + i];
  6944. cai[0] = 6 + bp_parms[3].length;
  6945. add_p(plci, CAI, cai);
  6946. return 0;
  6947. }
  6948. if ((GET_WORD(bp_parms[0].info) == B1_PIAFS)
  6949. && (plci->adapter->man_profile.private_options & (1L << PRIVATE_PIAFS)))
  6950. {
  6951. plci->B1_resource = add_b1_facilities(plci, 35/* PIAFS HARDWARE FACILITY */, (word)(b1_facilities & ~B1_FACILITY_VOICE));
  6952. adjust_b1_facilities(plci, plci->B1_resource, (word)(b1_facilities & ~B1_FACILITY_VOICE));
  6953. cai[1] = plci->B1_resource;
  6954. cai[2] = 0;
  6955. cai[3] = 0;
  6956. cai[4] = 0;
  6957. PUT_WORD(&cai[5], plci->appl->MaxDataLength);
  6958. cai[0] = 6;
  6959. add_p(plci, CAI, cai);
  6960. return 0;
  6961. }
  6962. if ((GET_WORD(bp_parms[0].info) >= 32)
  6963. || (!((1L << GET_WORD(bp_parms[0].info)) & plci->adapter->profile.B1_Protocols)
  6964. && ((GET_WORD(bp_parms[0].info) != 3)
  6965. || !((1L << B1_HDLC) & plci->adapter->profile.B1_Protocols)
  6966. || ((bp_parms[3].length != 0) && (GET_WORD(&bp_parms[3].info[1]) != 0) && (GET_WORD(&bp_parms[3].info[1]) != 56000)))))
  6967. {
  6968. return _B1_NOT_SUPPORTED;
  6969. }
  6970. plci->B1_resource = add_b1_facilities(plci, resource[GET_WORD(bp_parms[0].info)],
  6971. (word)(b1_facilities & ~B1_FACILITY_VOICE));
  6972. adjust_b1_facilities(plci, plci->B1_resource, (word)(b1_facilities & ~B1_FACILITY_VOICE));
  6973. cai[0] = 6;
  6974. cai[1] = plci->B1_resource;
  6975. for (i = 2; i < sizeof(cai); i++) cai[i] = 0;
  6976. if ((GET_WORD(bp_parms[0].info) == B1_MODEM_ALL_NEGOTIATE)
  6977. || (GET_WORD(bp_parms[0].info) == B1_MODEM_ASYNC)
  6978. || (GET_WORD(bp_parms[0].info) == B1_MODEM_SYNC_HDLC))
  6979. { /* B1 - modem */
  6980. for (i = 0; i < 7; i++) mdm_cfg[i].length = 0;
  6981. if (bp_parms[3].length)
  6982. {
  6983. if (api_parse(&bp_parms[3].info[1], (word)bp_parms[3].length, "wwwwww", mdm_cfg))
  6984. {
  6985. return (_WRONG_MESSAGE_FORMAT);
  6986. }
  6987. cai[2] = 0; /* Bit rate for adaptation */
  6988. dbug(1, dprintf("MDM Max Bit Rate:<%d>", GET_WORD(mdm_cfg[0].info)));
  6989. PUT_WORD(&cai[13], 0); /* Min Tx speed */
  6990. PUT_WORD(&cai[15], GET_WORD(mdm_cfg[0].info)); /* Max Tx speed */
  6991. PUT_WORD(&cai[17], 0); /* Min Rx speed */
  6992. PUT_WORD(&cai[19], GET_WORD(mdm_cfg[0].info)); /* Max Rx speed */
  6993. cai[3] = 0; /* Async framing parameters */
  6994. switch (GET_WORD(mdm_cfg[2].info))
  6995. { /* Parity */
  6996. case 1: /* odd parity */
  6997. cai[3] |= (DSP_CAI_ASYNC_PARITY_ENABLE | DSP_CAI_ASYNC_PARITY_ODD);
  6998. dbug(1, dprintf("MDM: odd parity"));
  6999. break;
  7000. case 2: /* even parity */
  7001. cai[3] |= (DSP_CAI_ASYNC_PARITY_ENABLE | DSP_CAI_ASYNC_PARITY_EVEN);
  7002. dbug(1, dprintf("MDM: even parity"));
  7003. break;
  7004. default:
  7005. dbug(1, dprintf("MDM: no parity"));
  7006. break;
  7007. }
  7008. switch (GET_WORD(mdm_cfg[3].info))
  7009. { /* stop bits */
  7010. case 1: /* 2 stop bits */
  7011. cai[3] |= DSP_CAI_ASYNC_TWO_STOP_BITS;
  7012. dbug(1, dprintf("MDM: 2 stop bits"));
  7013. break;
  7014. default:
  7015. dbug(1, dprintf("MDM: 1 stop bit"));
  7016. break;
  7017. }
  7018. switch (GET_WORD(mdm_cfg[1].info))
  7019. { /* char length */
  7020. case 5:
  7021. cai[3] |= DSP_CAI_ASYNC_CHAR_LENGTH_5;
  7022. dbug(1, dprintf("MDM: 5 bits"));
  7023. break;
  7024. case 6:
  7025. cai[3] |= DSP_CAI_ASYNC_CHAR_LENGTH_6;
  7026. dbug(1, dprintf("MDM: 6 bits"));
  7027. break;
  7028. case 7:
  7029. cai[3] |= DSP_CAI_ASYNC_CHAR_LENGTH_7;
  7030. dbug(1, dprintf("MDM: 7 bits"));
  7031. break;
  7032. default:
  7033. dbug(1, dprintf("MDM: 8 bits"));
  7034. break;
  7035. }
  7036. cai[7] = 0; /* Line taking options */
  7037. cai[8] = 0; /* Modulation negotiation options */
  7038. cai[9] = 0; /* Modulation options */
  7039. if (((plci->call_dir & CALL_DIR_ORIGINATE) != 0) ^ ((plci->call_dir & CALL_DIR_OUT) != 0))
  7040. {
  7041. cai[9] |= DSP_CAI_MODEM_REVERSE_DIRECTION;
  7042. dbug(1, dprintf("MDM: Reverse direction"));
  7043. }
  7044. if (GET_WORD(mdm_cfg[4].info) & MDM_CAPI_DISABLE_RETRAIN)
  7045. {
  7046. cai[9] |= DSP_CAI_MODEM_DISABLE_RETRAIN;
  7047. dbug(1, dprintf("MDM: Disable retrain"));
  7048. }
  7049. if (GET_WORD(mdm_cfg[4].info) & MDM_CAPI_DISABLE_RING_TONE)
  7050. {
  7051. cai[7] |= DSP_CAI_MODEM_DISABLE_CALLING_TONE | DSP_CAI_MODEM_DISABLE_ANSWER_TONE;
  7052. dbug(1, dprintf("MDM: Disable ring tone"));
  7053. }
  7054. if (GET_WORD(mdm_cfg[4].info) & MDM_CAPI_GUARD_1800)
  7055. {
  7056. cai[8] |= DSP_CAI_MODEM_GUARD_TONE_1800HZ;
  7057. dbug(1, dprintf("MDM: 1800 guard tone"));
  7058. }
  7059. else if (GET_WORD(mdm_cfg[4].info) & MDM_CAPI_GUARD_550)
  7060. {
  7061. cai[8] |= DSP_CAI_MODEM_GUARD_TONE_550HZ;
  7062. dbug(1, dprintf("MDM: 550 guard tone"));
  7063. }
  7064. if ((GET_WORD(mdm_cfg[5].info) & 0x00ff) == MDM_CAPI_NEG_V100)
  7065. {
  7066. cai[8] |= DSP_CAI_MODEM_NEGOTIATE_V100;
  7067. dbug(1, dprintf("MDM: V100"));
  7068. }
  7069. else if ((GET_WORD(mdm_cfg[5].info) & 0x00ff) == MDM_CAPI_NEG_MOD_CLASS)
  7070. {
  7071. cai[8] |= DSP_CAI_MODEM_NEGOTIATE_IN_CLASS;
  7072. dbug(1, dprintf("MDM: IN CLASS"));
  7073. }
  7074. else if ((GET_WORD(mdm_cfg[5].info) & 0x00ff) == MDM_CAPI_NEG_DISABLED)
  7075. {
  7076. cai[8] |= DSP_CAI_MODEM_NEGOTIATE_DISABLED;
  7077. dbug(1, dprintf("MDM: DISABLED"));
  7078. }
  7079. cai[0] = 20;
  7080. if ((plci->adapter->man_profile.private_options & (1L << PRIVATE_V18))
  7081. && (GET_WORD(mdm_cfg[5].info) & 0x8000)) /* Private V.18 enable */
  7082. {
  7083. plci->requested_options |= 1L << PRIVATE_V18;
  7084. }
  7085. if (GET_WORD(mdm_cfg[5].info) & 0x4000) /* Private VOWN enable */
  7086. plci->requested_options |= 1L << PRIVATE_VOWN;
  7087. if ((plci->requested_options_conn | plci->requested_options | plci->adapter->requested_options_table[plci->appl->Id - 1])
  7088. & ((1L << PRIVATE_V18) | (1L << PRIVATE_VOWN)))
  7089. {
  7090. if (!api_parse(&bp_parms[3].info[1], (word)bp_parms[3].length, "wwwwwws", mdm_cfg))
  7091. {
  7092. i = 27;
  7093. if (mdm_cfg[6].length >= 4)
  7094. {
  7095. d = GET_DWORD(&mdm_cfg[6].info[1]);
  7096. cai[7] |= (byte) d; /* line taking options */
  7097. cai[9] |= (byte)(d >> 8); /* modulation options */
  7098. cai[++i] = (byte)(d >> 16); /* vown modulation options */
  7099. cai[++i] = (byte)(d >> 24);
  7100. if (mdm_cfg[6].length >= 8)
  7101. {
  7102. d = GET_DWORD(&mdm_cfg[6].info[5]);
  7103. cai[10] |= (byte) d; /* disabled modulations mask */
  7104. cai[11] |= (byte)(d >> 8);
  7105. if (mdm_cfg[6].length >= 12)
  7106. {
  7107. d = GET_DWORD(&mdm_cfg[6].info[9]);
  7108. cai[12] = (byte) d; /* enabled modulations mask */
  7109. cai[++i] = (byte)(d >> 8); /* vown enabled modulations */
  7110. cai[++i] = (byte)(d >> 16);
  7111. cai[++i] = (byte)(d >> 24);
  7112. cai[++i] = 0;
  7113. if (mdm_cfg[6].length >= 14)
  7114. {
  7115. w = GET_WORD(&mdm_cfg[6].info[13]);
  7116. if (w != 0)
  7117. PUT_WORD(&cai[13], w); /* min tx speed */
  7118. if (mdm_cfg[6].length >= 16)
  7119. {
  7120. w = GET_WORD(&mdm_cfg[6].info[15]);
  7121. if (w != 0)
  7122. PUT_WORD(&cai[15], w); /* max tx speed */
  7123. if (mdm_cfg[6].length >= 18)
  7124. {
  7125. w = GET_WORD(&mdm_cfg[6].info[17]);
  7126. if (w != 0)
  7127. PUT_WORD(&cai[17], w); /* min rx speed */
  7128. if (mdm_cfg[6].length >= 20)
  7129. {
  7130. w = GET_WORD(&mdm_cfg[6].info[19]);
  7131. if (w != 0)
  7132. PUT_WORD(&cai[19], w); /* max rx speed */
  7133. if (mdm_cfg[6].length >= 22)
  7134. {
  7135. w = GET_WORD(&mdm_cfg[6].info[21]);
  7136. cai[23] = (byte)(-((short) w)); /* transmit level */
  7137. if (mdm_cfg[6].length >= 24)
  7138. {
  7139. w = GET_WORD(&mdm_cfg[6].info[23]);
  7140. cai[22] |= (byte) w; /* info options mask */
  7141. cai[21] |= (byte)(w >> 8); /* disabled symbol rates */
  7142. }
  7143. }
  7144. }
  7145. }
  7146. }
  7147. }
  7148. }
  7149. }
  7150. }
  7151. cai[27] = i - 27;
  7152. i++;
  7153. if (!api_parse(&bp_parms[3].info[1], (word)bp_parms[3].length, "wwwwwwss", mdm_cfg))
  7154. {
  7155. if (!api_parse(&mdm_cfg[7].info[1], (word)mdm_cfg[7].length, "sss", mdm_cfg_v18))
  7156. {
  7157. for (n = 0; n < 3; n++)
  7158. {
  7159. cai[i] = (byte)(mdm_cfg_v18[n].length);
  7160. for (j = 1; j < ((word)(cai[i] + 1)); j++)
  7161. cai[i + j] = mdm_cfg_v18[n].info[j];
  7162. i += cai[i] + 1;
  7163. }
  7164. }
  7165. }
  7166. cai[0] = (byte)(i - 1);
  7167. }
  7168. }
  7169. }
  7170. }
  7171. if (GET_WORD(bp_parms[0].info) == 2 || /* V.110 async */
  7172. GET_WORD(bp_parms[0].info) == 3) /* V.110 sync */
  7173. {
  7174. if (bp_parms[3].length) {
  7175. dbug(1, dprintf("V.110,%d", GET_WORD(&bp_parms[3].info[1])));
  7176. switch (GET_WORD(&bp_parms[3].info[1])) { /* Rate */
  7177. case 0:
  7178. case 56000:
  7179. if (GET_WORD(bp_parms[0].info) == 3) { /* V.110 sync 56k */
  7180. dbug(1, dprintf("56k sync HSCX"));
  7181. cai[1] = 8;
  7182. cai[2] = 0;
  7183. cai[3] = 0;
  7184. }
  7185. else if (GET_WORD(bp_parms[0].info) == 2) {
  7186. dbug(1, dprintf("56k async DSP"));
  7187. cai[2] = 9;
  7188. }
  7189. break;
  7190. case 50: cai[2] = 1; break;
  7191. case 75: cai[2] = 1; break;
  7192. case 110: cai[2] = 1; break;
  7193. case 150: cai[2] = 1; break;
  7194. case 200: cai[2] = 1; break;
  7195. case 300: cai[2] = 1; break;
  7196. case 600: cai[2] = 1; break;
  7197. case 1200: cai[2] = 2; break;
  7198. case 2400: cai[2] = 3; break;
  7199. case 4800: cai[2] = 4; break;
  7200. case 7200: cai[2] = 10; break;
  7201. case 9600: cai[2] = 5; break;
  7202. case 12000: cai[2] = 13; break;
  7203. case 24000: cai[2] = 0; break;
  7204. case 14400: cai[2] = 11; break;
  7205. case 19200: cai[2] = 6; break;
  7206. case 28800: cai[2] = 12; break;
  7207. case 38400: cai[2] = 7; break;
  7208. case 48000: cai[2] = 8; break;
  7209. case 76: cai[2] = 15; break; /* 75/1200 */
  7210. case 1201: cai[2] = 14; break; /* 1200/75 */
  7211. case 56001: cai[2] = 9; break; /* V.110 56000 */
  7212. default:
  7213. return _B1_PARM_NOT_SUPPORTED;
  7214. }
  7215. cai[3] = 0;
  7216. if (cai[1] == 13) /* v.110 async */
  7217. {
  7218. if (bp_parms[3].length >= 8)
  7219. {
  7220. switch (GET_WORD(&bp_parms[3].info[3]))
  7221. { /* char length */
  7222. case 5:
  7223. cai[3] |= DSP_CAI_ASYNC_CHAR_LENGTH_5;
  7224. break;
  7225. case 6:
  7226. cai[3] |= DSP_CAI_ASYNC_CHAR_LENGTH_6;
  7227. break;
  7228. case 7:
  7229. cai[3] |= DSP_CAI_ASYNC_CHAR_LENGTH_7;
  7230. break;
  7231. }
  7232. switch (GET_WORD(&bp_parms[3].info[5]))
  7233. { /* Parity */
  7234. case 1: /* odd parity */
  7235. cai[3] |= (DSP_CAI_ASYNC_PARITY_ENABLE | DSP_CAI_ASYNC_PARITY_ODD);
  7236. break;
  7237. case 2: /* even parity */
  7238. cai[3] |= (DSP_CAI_ASYNC_PARITY_ENABLE | DSP_CAI_ASYNC_PARITY_EVEN);
  7239. break;
  7240. }
  7241. switch (GET_WORD(&bp_parms[3].info[7]))
  7242. { /* stop bits */
  7243. case 1: /* 2 stop bits */
  7244. cai[3] |= DSP_CAI_ASYNC_TWO_STOP_BITS;
  7245. break;
  7246. }
  7247. }
  7248. }
  7249. }
  7250. else if (cai[1] == 8 || GET_WORD(bp_parms[0].info) == 3) {
  7251. dbug(1, dprintf("V.110 default 56k sync"));
  7252. cai[1] = 8;
  7253. cai[2] = 0;
  7254. cai[3] = 0;
  7255. }
  7256. else {
  7257. dbug(1, dprintf("V.110 default 9600 async"));
  7258. cai[2] = 5;
  7259. }
  7260. }
  7261. PUT_WORD(&cai[5], plci->appl->MaxDataLength);
  7262. 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]));
  7263. /* HexDump ("CAI", sizeof(cai), &cai[0]); */
  7264. add_p(plci, CAI, cai);
  7265. return 0;
  7266. }
  7267. /*------------------------------------------------------------------*/
  7268. /* put parameter for b2 and B3 protocol in the parameter buffer */
  7269. /*------------------------------------------------------------------*/
  7270. static word add_b23(PLCI *plci, API_PARSE *bp)
  7271. {
  7272. word i, fax_control_bits;
  7273. byte pos, len;
  7274. byte SAPI = 0x40; /* default SAPI 16 for x.31 */
  7275. API_PARSE bp_parms[8];
  7276. API_PARSE *b1_config;
  7277. API_PARSE *b2_config;
  7278. API_PARSE b2_config_parms[8];
  7279. API_PARSE *b3_config;
  7280. API_PARSE b3_config_parms[6];
  7281. API_PARSE global_config[2];
  7282. static byte llc[3] = {2,0,0};
  7283. static byte dlc[20] = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
  7284. static byte nlc[256];
  7285. static byte lli[12] = {1,1};
  7286. const byte llc2_out[] = {1,2,4,6,2,0,0,0, X75_V42BIS,V120_L2,V120_V42BIS,V120_L2,6};
  7287. const byte llc2_in[] = {1,3,4,6,3,0,0,0, X75_V42BIS,V120_L2,V120_V42BIS,V120_L2,6};
  7288. const byte llc3[] = {4,3,2,2,6,6,0};
  7289. const byte header[] = {0,2,3,3,0,0,0};
  7290. for (i = 0; i < 8; i++) bp_parms[i].length = 0;
  7291. for (i = 0; i < 6; i++) b2_config_parms[i].length = 0;
  7292. for (i = 0; i < 5; i++) b3_config_parms[i].length = 0;
  7293. lli[0] = 1;
  7294. lli[1] = 1;
  7295. if (plci->adapter->manufacturer_features & MANUFACTURER_FEATURE_XONOFF_FLOW_CONTROL)
  7296. lli[1] |= 2;
  7297. if (plci->adapter->manufacturer_features & MANUFACTURER_FEATURE_OOB_CHANNEL)
  7298. lli[1] |= 4;
  7299. if ((lli[1] & 0x02) && (diva_xdi_extended_features & DIVA_CAPI_USE_CMA)) {
  7300. lli[1] |= 0x10;
  7301. if (plci->rx_dma_descriptor <= 0) {
  7302. plci->rx_dma_descriptor = diva_get_dma_descriptor(plci, &plci->rx_dma_magic);
  7303. if (plci->rx_dma_descriptor >= 0)
  7304. plci->rx_dma_descriptor++;
  7305. }
  7306. if (plci->rx_dma_descriptor > 0) {
  7307. lli[0] = 6;
  7308. lli[1] |= 0x40;
  7309. lli[2] = (byte)(plci->rx_dma_descriptor - 1);
  7310. lli[3] = (byte)plci->rx_dma_magic;
  7311. lli[4] = (byte)(plci->rx_dma_magic >> 8);
  7312. lli[5] = (byte)(plci->rx_dma_magic >> 16);
  7313. lli[6] = (byte)(plci->rx_dma_magic >> 24);
  7314. }
  7315. }
  7316. if (DIVA_CAPI_SUPPORTS_NO_CANCEL(plci->adapter)) {
  7317. lli[1] |= 0x20;
  7318. }
  7319. dbug(1, dprintf("add_b23"));
  7320. api_save_msg(bp, "s", &plci->B_protocol);
  7321. if (!bp->length && plci->tel)
  7322. {
  7323. plci->adv_nl = true;
  7324. dbug(1, dprintf("Default adv.Nl"));
  7325. add_p(plci, LLI, lli);
  7326. plci->B2_prot = 1 /*XPARENT*/;
  7327. plci->B3_prot = 0 /*XPARENT*/;
  7328. llc[1] = 2;
  7329. llc[2] = 4;
  7330. add_p(plci, LLC, llc);
  7331. dlc[0] = 2;
  7332. PUT_WORD(&dlc[1], plci->appl->MaxDataLength);
  7333. add_p(plci, DLC, dlc);
  7334. return 0;
  7335. }
  7336. if (!bp->length) /*default*/
  7337. {
  7338. dbug(1, dprintf("ret default"));
  7339. add_p(plci, LLI, lli);
  7340. plci->B2_prot = 0 /*X.75 */;
  7341. plci->B3_prot = 0 /*XPARENT*/;
  7342. llc[1] = 1;
  7343. llc[2] = 4;
  7344. add_p(plci, LLC, llc);
  7345. dlc[0] = 2;
  7346. PUT_WORD(&dlc[1], plci->appl->MaxDataLength);
  7347. add_p(plci, DLC, dlc);
  7348. return 0;
  7349. }
  7350. dbug(1, dprintf("b_prot_len=%d", (word)bp->length));
  7351. if ((word)bp->length > 256) return _WRONG_MESSAGE_FORMAT;
  7352. if (api_parse(&bp->info[1], (word)bp->length, "wwwsssb", bp_parms))
  7353. {
  7354. bp_parms[6].length = 0;
  7355. if (api_parse(&bp->info[1], (word)bp->length, "wwwsss", bp_parms))
  7356. {
  7357. dbug(1, dprintf("b-form.!"));
  7358. return _WRONG_MESSAGE_FORMAT;
  7359. }
  7360. }
  7361. else if (api_parse(&bp->info[1], (word)bp->length, "wwwssss", bp_parms))
  7362. {
  7363. dbug(1, dprintf("b-form.!"));
  7364. return _WRONG_MESSAGE_FORMAT;
  7365. }
  7366. if (plci->tel == ADV_VOICE) /* transparent B on advanced voice */
  7367. {
  7368. if (GET_WORD(bp_parms[1].info) != 1
  7369. || GET_WORD(bp_parms[2].info) != 0) return _B2_NOT_SUPPORTED;
  7370. plci->adv_nl = true;
  7371. }
  7372. else if (plci->tel) return _B2_NOT_SUPPORTED;
  7373. if ((GET_WORD(bp_parms[1].info) == B2_RTP)
  7374. && (GET_WORD(bp_parms[2].info) == B3_RTP)
  7375. && (plci->adapter->man_profile.private_options & (1L << PRIVATE_RTP)))
  7376. {
  7377. add_p(plci, LLI, lli);
  7378. plci->B2_prot = (byte) GET_WORD(bp_parms[1].info);
  7379. plci->B3_prot = (byte) GET_WORD(bp_parms[2].info);
  7380. llc[1] = (plci->call_dir & (CALL_DIR_ORIGINATE | CALL_DIR_FORCE_OUTG_NL)) ? 14 : 13;
  7381. llc[2] = 4;
  7382. add_p(plci, LLC, llc);
  7383. dlc[0] = 2;
  7384. PUT_WORD(&dlc[1], plci->appl->MaxDataLength);
  7385. dlc[3] = 3; /* Addr A */
  7386. dlc[4] = 1; /* Addr B */
  7387. dlc[5] = 7; /* modulo mode */
  7388. dlc[6] = 7; /* window size */
  7389. dlc[7] = 0; /* XID len Lo */
  7390. dlc[8] = 0; /* XID len Hi */
  7391. for (i = 0; i < bp_parms[4].length; i++)
  7392. dlc[9 + i] = bp_parms[4].info[1 + i];
  7393. dlc[0] = (byte)(8 + bp_parms[4].length);
  7394. add_p(plci, DLC, dlc);
  7395. for (i = 0; i < bp_parms[5].length; i++)
  7396. nlc[1 + i] = bp_parms[5].info[1 + i];
  7397. nlc[0] = (byte)(bp_parms[5].length);
  7398. add_p(plci, NLC, nlc);
  7399. return 0;
  7400. }
  7401. if ((GET_WORD(bp_parms[1].info) >= 32)
  7402. || (!((1L << GET_WORD(bp_parms[1].info)) & plci->adapter->profile.B2_Protocols)
  7403. && ((GET_WORD(bp_parms[1].info) != B2_PIAFS)
  7404. || !(plci->adapter->man_profile.private_options & (1L << PRIVATE_PIAFS)))))
  7405. {
  7406. return _B2_NOT_SUPPORTED;
  7407. }
  7408. if ((GET_WORD(bp_parms[2].info) >= 32)
  7409. || !((1L << GET_WORD(bp_parms[2].info)) & plci->adapter->profile.B3_Protocols))
  7410. {
  7411. return _B3_NOT_SUPPORTED;
  7412. }
  7413. if ((GET_WORD(bp_parms[1].info) != B2_SDLC)
  7414. && ((GET_WORD(bp_parms[0].info) == B1_MODEM_ALL_NEGOTIATE)
  7415. || (GET_WORD(bp_parms[0].info) == B1_MODEM_ASYNC)
  7416. || (GET_WORD(bp_parms[0].info) == B1_MODEM_SYNC_HDLC)))
  7417. {
  7418. return (add_modem_b23(plci, bp_parms));
  7419. }
  7420. add_p(plci, LLI, lli);
  7421. plci->B2_prot = (byte)GET_WORD(bp_parms[1].info);
  7422. plci->B3_prot = (byte)GET_WORD(bp_parms[2].info);
  7423. if (plci->B2_prot == 12) SAPI = 0; /* default SAPI D-channel */
  7424. if (bp_parms[6].length)
  7425. {
  7426. if (api_parse(&bp_parms[6].info[1], (word)bp_parms[6].length, "w", global_config))
  7427. {
  7428. return _WRONG_MESSAGE_FORMAT;
  7429. }
  7430. switch (GET_WORD(global_config[0].info))
  7431. {
  7432. case 1:
  7433. plci->call_dir = (plci->call_dir & ~CALL_DIR_ANSWER) | CALL_DIR_ORIGINATE;
  7434. break;
  7435. case 2:
  7436. plci->call_dir = (plci->call_dir & ~CALL_DIR_ORIGINATE) | CALL_DIR_ANSWER;
  7437. break;
  7438. }
  7439. }
  7440. dbug(1, dprintf("call_dir=%04x", plci->call_dir));
  7441. if (plci->B2_prot == B2_PIAFS)
  7442. llc[1] = PIAFS_CRC;
  7443. else
  7444. /* IMPLEMENT_PIAFS */
  7445. {
  7446. llc[1] = (plci->call_dir & (CALL_DIR_ORIGINATE | CALL_DIR_FORCE_OUTG_NL)) ?
  7447. llc2_out[GET_WORD(bp_parms[1].info)] : llc2_in[GET_WORD(bp_parms[1].info)];
  7448. }
  7449. llc[2] = llc3[GET_WORD(bp_parms[2].info)];
  7450. add_p(plci, LLC, llc);
  7451. dlc[0] = 2;
  7452. PUT_WORD(&dlc[1], plci->appl->MaxDataLength +
  7453. header[GET_WORD(bp_parms[2].info)]);
  7454. b1_config = &bp_parms[3];
  7455. nlc[0] = 0;
  7456. if (plci->B3_prot == 4
  7457. || plci->B3_prot == 5)
  7458. {
  7459. for (i = 0; i < sizeof(T30_INFO); i++) nlc[i] = 0;
  7460. nlc[0] = sizeof(T30_INFO);
  7461. if (plci->adapter->manufacturer_features & MANUFACTURER_FEATURE_FAX_PAPER_FORMATS)
  7462. ((T30_INFO *)&nlc[1])->operating_mode = T30_OPERATING_MODE_CAPI;
  7463. ((T30_INFO *)&nlc[1])->rate_div_2400 = 0xff;
  7464. if (b1_config->length >= 2)
  7465. {
  7466. ((T30_INFO *)&nlc[1])->rate_div_2400 = (byte)(GET_WORD(&b1_config->info[1]) / 2400);
  7467. }
  7468. }
  7469. b2_config = &bp_parms[4];
  7470. if (llc[1] == PIAFS_CRC)
  7471. {
  7472. if (plci->B3_prot != B3_TRANSPARENT)
  7473. {
  7474. return _B_STACK_NOT_SUPPORTED;
  7475. }
  7476. if (b2_config->length && api_parse(&b2_config->info[1], (word)b2_config->length, "bwww", b2_config_parms)) {
  7477. return _WRONG_MESSAGE_FORMAT;
  7478. }
  7479. PUT_WORD(&dlc[1], plci->appl->MaxDataLength);
  7480. dlc[3] = 0; /* Addr A */
  7481. dlc[4] = 0; /* Addr B */
  7482. dlc[5] = 0; /* modulo mode */
  7483. dlc[6] = 0; /* window size */
  7484. if (b2_config->length >= 7) {
  7485. dlc[7] = 7;
  7486. dlc[8] = 0;
  7487. dlc[9] = b2_config_parms[0].info[0]; /* PIAFS protocol Speed configuration */
  7488. dlc[10] = b2_config_parms[1].info[0]; /* V.42bis P0 */
  7489. dlc[11] = b2_config_parms[1].info[1]; /* V.42bis P0 */
  7490. dlc[12] = b2_config_parms[2].info[0]; /* V.42bis P1 */
  7491. dlc[13] = b2_config_parms[2].info[1]; /* V.42bis P1 */
  7492. dlc[14] = b2_config_parms[3].info[0]; /* V.42bis P2 */
  7493. dlc[15] = b2_config_parms[3].info[1]; /* V.42bis P2 */
  7494. dlc[0] = 15;
  7495. if (b2_config->length >= 8) { /* PIAFS control abilities */
  7496. dlc[7] = 10;
  7497. dlc[16] = 2; /* Length of PIAFS extension */
  7498. dlc[17] = PIAFS_UDATA_ABILITIES; /* control (UDATA) ability */
  7499. dlc[18] = b2_config_parms[4].info[0]; /* value */
  7500. dlc[0] = 18;
  7501. }
  7502. }
  7503. else /* default values, 64K, variable, no compression */
  7504. {
  7505. dlc[7] = 7;
  7506. dlc[8] = 0;
  7507. dlc[9] = 0x03; /* PIAFS protocol Speed configuration */
  7508. dlc[10] = 0x03; /* V.42bis P0 */
  7509. dlc[11] = 0; /* V.42bis P0 */
  7510. dlc[12] = 0; /* V.42bis P1 */
  7511. dlc[13] = 0; /* V.42bis P1 */
  7512. dlc[14] = 0; /* V.42bis P2 */
  7513. dlc[15] = 0; /* V.42bis P2 */
  7514. dlc[0] = 15;
  7515. }
  7516. add_p(plci, DLC, dlc);
  7517. }
  7518. else
  7519. if ((llc[1] == V120_L2) || (llc[1] == V120_V42BIS))
  7520. {
  7521. if (plci->B3_prot != B3_TRANSPARENT)
  7522. return _B_STACK_NOT_SUPPORTED;
  7523. dlc[0] = 6;
  7524. PUT_WORD(&dlc[1], GET_WORD(&dlc[1]) + 2);
  7525. dlc[3] = 0x08;
  7526. dlc[4] = 0x01;
  7527. dlc[5] = 127;
  7528. dlc[6] = 7;
  7529. if (b2_config->length != 0)
  7530. {
  7531. if ((llc[1] == V120_V42BIS) && api_parse(&b2_config->info[1], (word)b2_config->length, "bbbbwww", b2_config_parms)) {
  7532. return _WRONG_MESSAGE_FORMAT;
  7533. }
  7534. dlc[3] = (byte)((b2_config->info[2] << 3) | ((b2_config->info[1] >> 5) & 0x04));
  7535. dlc[4] = (byte)((b2_config->info[1] << 1) | 0x01);
  7536. if (b2_config->info[3] != 128)
  7537. {
  7538. dbug(1, dprintf("1D-dlc= %x %x %x %x %x", dlc[0], dlc[1], dlc[2], dlc[3], dlc[4]));
  7539. return _B2_PARM_NOT_SUPPORTED;
  7540. }
  7541. dlc[5] = (byte)(b2_config->info[3] - 1);
  7542. dlc[6] = b2_config->info[4];
  7543. if (llc[1] == V120_V42BIS) {
  7544. if (b2_config->length >= 10) {
  7545. dlc[7] = 6;
  7546. dlc[8] = 0;
  7547. dlc[9] = b2_config_parms[4].info[0];
  7548. dlc[10] = b2_config_parms[4].info[1];
  7549. dlc[11] = b2_config_parms[5].info[0];
  7550. dlc[12] = b2_config_parms[5].info[1];
  7551. dlc[13] = b2_config_parms[6].info[0];
  7552. dlc[14] = b2_config_parms[6].info[1];
  7553. dlc[0] = 14;
  7554. dbug(1, dprintf("b2_config_parms[4].info[0] [1]: %x %x", b2_config_parms[4].info[0], b2_config_parms[4].info[1]));
  7555. dbug(1, dprintf("b2_config_parms[5].info[0] [1]: %x %x", b2_config_parms[5].info[0], b2_config_parms[5].info[1]));
  7556. dbug(1, dprintf("b2_config_parms[6].info[0] [1]: %x %x", b2_config_parms[6].info[0], b2_config_parms[6].info[1]));
  7557. }
  7558. else {
  7559. dlc[6] = 14;
  7560. }
  7561. }
  7562. }
  7563. }
  7564. else
  7565. {
  7566. if (b2_config->length)
  7567. {
  7568. dbug(1, dprintf("B2-Config"));
  7569. if (llc[1] == X75_V42BIS) {
  7570. if (api_parse(&b2_config->info[1], (word)b2_config->length, "bbbbwww", b2_config_parms))
  7571. {
  7572. return _WRONG_MESSAGE_FORMAT;
  7573. }
  7574. }
  7575. else {
  7576. if (api_parse(&b2_config->info[1], (word)b2_config->length, "bbbbs", b2_config_parms))
  7577. {
  7578. return _WRONG_MESSAGE_FORMAT;
  7579. }
  7580. }
  7581. /* if B2 Protocol is LAPD, b2_config structure is different */
  7582. if (llc[1] == 6)
  7583. {
  7584. dlc[0] = 4;
  7585. if (b2_config->length >= 1) dlc[2] = b2_config->info[1]; /* TEI */
  7586. else dlc[2] = 0x01;
  7587. if ((b2_config->length >= 2) && (plci->B2_prot == 12))
  7588. {
  7589. SAPI = b2_config->info[2]; /* SAPI */
  7590. }
  7591. dlc[1] = SAPI;
  7592. if ((b2_config->length >= 3) && (b2_config->info[3] == 128))
  7593. {
  7594. dlc[3] = 127; /* Mode */
  7595. }
  7596. else
  7597. {
  7598. dlc[3] = 7; /* Mode */
  7599. }
  7600. if (b2_config->length >= 4) dlc[4] = b2_config->info[4]; /* Window */
  7601. else dlc[4] = 1;
  7602. dbug(1, dprintf("D-dlc[%d]=%x,%x,%x,%x", dlc[0], dlc[1], dlc[2], dlc[3], dlc[4]));
  7603. if (b2_config->length > 5) return _B2_PARM_NOT_SUPPORTED;
  7604. }
  7605. else
  7606. {
  7607. dlc[0] = (byte)(b2_config_parms[4].length + 6);
  7608. dlc[3] = b2_config->info[1];
  7609. dlc[4] = b2_config->info[2];
  7610. if (b2_config->info[3] != 8 && b2_config->info[3] != 128) {
  7611. dbug(1, dprintf("1D-dlc= %x %x %x %x %x", dlc[0], dlc[1], dlc[2], dlc[3], dlc[4]));
  7612. return _B2_PARM_NOT_SUPPORTED;
  7613. }
  7614. dlc[5] = (byte)(b2_config->info[3] - 1);
  7615. dlc[6] = b2_config->info[4];
  7616. if (dlc[6] > dlc[5]) {
  7617. 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]));
  7618. return _B2_PARM_NOT_SUPPORTED;
  7619. }
  7620. if (llc[1] == X75_V42BIS) {
  7621. if (b2_config->length >= 10) {
  7622. dlc[7] = 6;
  7623. dlc[8] = 0;
  7624. dlc[9] = b2_config_parms[4].info[0];
  7625. dlc[10] = b2_config_parms[4].info[1];
  7626. dlc[11] = b2_config_parms[5].info[0];
  7627. dlc[12] = b2_config_parms[5].info[1];
  7628. dlc[13] = b2_config_parms[6].info[0];
  7629. dlc[14] = b2_config_parms[6].info[1];
  7630. dlc[0] = 14;
  7631. dbug(1, dprintf("b2_config_parms[4].info[0] [1]: %x %x", b2_config_parms[4].info[0], b2_config_parms[4].info[1]));
  7632. dbug(1, dprintf("b2_config_parms[5].info[0] [1]: %x %x", b2_config_parms[5].info[0], b2_config_parms[5].info[1]));
  7633. dbug(1, dprintf("b2_config_parms[6].info[0] [1]: %x %x", b2_config_parms[6].info[0], b2_config_parms[6].info[1]));
  7634. }
  7635. else {
  7636. dlc[6] = 14;
  7637. }
  7638. }
  7639. else {
  7640. PUT_WORD(&dlc[7], (word)b2_config_parms[4].length);
  7641. for (i = 0; i < b2_config_parms[4].length; i++)
  7642. dlc[11 + i] = b2_config_parms[4].info[1 + i];
  7643. }
  7644. }
  7645. }
  7646. }
  7647. add_p(plci, DLC, dlc);
  7648. b3_config = &bp_parms[5];
  7649. if (b3_config->length)
  7650. {
  7651. if (plci->B3_prot == 4
  7652. || plci->B3_prot == 5)
  7653. {
  7654. if (api_parse(&b3_config->info[1], (word)b3_config->length, "wwss", b3_config_parms))
  7655. {
  7656. return _WRONG_MESSAGE_FORMAT;
  7657. }
  7658. i = GET_WORD((byte *)(b3_config_parms[0].info));
  7659. ((T30_INFO *)&nlc[1])->resolution = (byte)(((i & 0x0001) ||
  7660. ((plci->B3_prot == 4) && (((byte)(GET_WORD((byte *)b3_config_parms[1].info))) != 5))) ? T30_RESOLUTION_R8_0770_OR_200 : 0);
  7661. ((T30_INFO *)&nlc[1])->data_format = (byte)(GET_WORD((byte *)b3_config_parms[1].info));
  7662. fax_control_bits = T30_CONTROL_BIT_ALL_FEATURES;
  7663. if ((((T30_INFO *)&nlc[1])->rate_div_2400 != 0) && (((T30_INFO *)&nlc[1])->rate_div_2400 <= 6))
  7664. fax_control_bits &= ~T30_CONTROL_BIT_ENABLE_V34FAX;
  7665. if (plci->adapter->manufacturer_features & MANUFACTURER_FEATURE_FAX_PAPER_FORMATS)
  7666. {
  7667. if ((plci->requested_options_conn | plci->requested_options | plci->adapter->requested_options_table[plci->appl->Id - 1])
  7668. & (1L << PRIVATE_FAX_PAPER_FORMATS))
  7669. {
  7670. ((T30_INFO *)&nlc[1])->resolution |= T30_RESOLUTION_R8_1540 |
  7671. T30_RESOLUTION_R16_1540_OR_400 | T30_RESOLUTION_300_300 |
  7672. T30_RESOLUTION_INCH_BASED | T30_RESOLUTION_METRIC_BASED;
  7673. }
  7674. ((T30_INFO *)&nlc[1])->recording_properties =
  7675. T30_RECORDING_WIDTH_ISO_A3 |
  7676. (T30_RECORDING_LENGTH_UNLIMITED << 2) |
  7677. (T30_MIN_SCANLINE_TIME_00_00_00 << 4);
  7678. }
  7679. if (plci->B3_prot == 5)
  7680. {
  7681. if (i & 0x0002) /* Accept incoming fax-polling requests */
  7682. fax_control_bits |= T30_CONTROL_BIT_ACCEPT_POLLING;
  7683. if (i & 0x2000) /* Do not use MR compression */
  7684. fax_control_bits &= ~T30_CONTROL_BIT_ENABLE_2D_CODING;
  7685. if (i & 0x4000) /* Do not use MMR compression */
  7686. fax_control_bits &= ~T30_CONTROL_BIT_ENABLE_T6_CODING;
  7687. if (i & 0x8000) /* Do not use ECM */
  7688. fax_control_bits &= ~T30_CONTROL_BIT_ENABLE_ECM;
  7689. if (plci->fax_connect_info_length != 0)
  7690. {
  7691. ((T30_INFO *)&nlc[1])->resolution = ((T30_INFO *)plci->fax_connect_info_buffer)->resolution;
  7692. ((T30_INFO *)&nlc[1])->data_format = ((T30_INFO *)plci->fax_connect_info_buffer)->data_format;
  7693. ((T30_INFO *)&nlc[1])->recording_properties = ((T30_INFO *)plci->fax_connect_info_buffer)->recording_properties;
  7694. fax_control_bits |= GET_WORD(&((T30_INFO *)plci->fax_connect_info_buffer)->control_bits_low) &
  7695. (T30_CONTROL_BIT_REQUEST_POLLING | T30_CONTROL_BIT_MORE_DOCUMENTS);
  7696. }
  7697. }
  7698. /* copy station id to NLC */
  7699. for (i = 0; i < T30_MAX_STATION_ID_LENGTH; i++)
  7700. {
  7701. if (i < b3_config_parms[2].length)
  7702. {
  7703. ((T30_INFO *)&nlc[1])->station_id[i] = ((byte *)b3_config_parms[2].info)[1 + i];
  7704. }
  7705. else
  7706. {
  7707. ((T30_INFO *)&nlc[1])->station_id[i] = ' ';
  7708. }
  7709. }
  7710. ((T30_INFO *)&nlc[1])->station_id_len = T30_MAX_STATION_ID_LENGTH;
  7711. /* copy head line to NLC */
  7712. if (b3_config_parms[3].length)
  7713. {
  7714. pos = (byte)(fax_head_line_time(&(((T30_INFO *)&nlc[1])->station_id[T30_MAX_STATION_ID_LENGTH])));
  7715. if (pos != 0)
  7716. {
  7717. if (CAPI_MAX_DATE_TIME_LENGTH + 2 + b3_config_parms[3].length > CAPI_MAX_HEAD_LINE_SPACE)
  7718. pos = 0;
  7719. else
  7720. {
  7721. nlc[1 + offsetof(T30_INFO, station_id) + T30_MAX_STATION_ID_LENGTH + pos++] = ' ';
  7722. nlc[1 + offsetof(T30_INFO, station_id) + T30_MAX_STATION_ID_LENGTH + pos++] = ' ';
  7723. len = (byte)b3_config_parms[2].length;
  7724. if (len > 20)
  7725. len = 20;
  7726. if (CAPI_MAX_DATE_TIME_LENGTH + 2 + len + 2 + b3_config_parms[3].length <= CAPI_MAX_HEAD_LINE_SPACE)
  7727. {
  7728. for (i = 0; i < len; i++)
  7729. nlc[1 + offsetof(T30_INFO, station_id) + T30_MAX_STATION_ID_LENGTH + pos++] = ((byte *)b3_config_parms[2].info)[1 + i];
  7730. nlc[1 + offsetof(T30_INFO, station_id) + T30_MAX_STATION_ID_LENGTH + pos++] = ' ';
  7731. nlc[1 + offsetof(T30_INFO, station_id) + T30_MAX_STATION_ID_LENGTH + pos++] = ' ';
  7732. }
  7733. }
  7734. }
  7735. len = (byte)b3_config_parms[3].length;
  7736. if (len > CAPI_MAX_HEAD_LINE_SPACE - pos)
  7737. len = (byte)(CAPI_MAX_HEAD_LINE_SPACE - pos);
  7738. ((T30_INFO *)&nlc[1])->head_line_len = (byte)(pos + len);
  7739. nlc[0] += (byte)(pos + len);
  7740. for (i = 0; i < len; i++)
  7741. nlc[1 + offsetof(T30_INFO, station_id) + T30_MAX_STATION_ID_LENGTH + pos++] = ((byte *)b3_config_parms[3].info)[1 + i];
  7742. } else
  7743. ((T30_INFO *)&nlc[1])->head_line_len = 0;
  7744. plci->nsf_control_bits = 0;
  7745. if (plci->B3_prot == 5)
  7746. {
  7747. if ((plci->adapter->man_profile.private_options & (1L << PRIVATE_FAX_SUB_SEP_PWD))
  7748. && (GET_WORD((byte *)b3_config_parms[1].info) & 0x8000)) /* Private SUB/SEP/PWD enable */
  7749. {
  7750. plci->requested_options |= 1L << PRIVATE_FAX_SUB_SEP_PWD;
  7751. }
  7752. if ((plci->adapter->man_profile.private_options & (1L << PRIVATE_FAX_NONSTANDARD))
  7753. && (GET_WORD((byte *)b3_config_parms[1].info) & 0x4000)) /* Private non-standard facilities enable */
  7754. {
  7755. plci->requested_options |= 1L << PRIVATE_FAX_NONSTANDARD;
  7756. }
  7757. if ((plci->requested_options_conn | plci->requested_options | plci->adapter->requested_options_table[plci->appl->Id - 1])
  7758. & ((1L << PRIVATE_FAX_SUB_SEP_PWD) | (1L << PRIVATE_FAX_NONSTANDARD)))
  7759. {
  7760. if ((plci->requested_options_conn | plci->requested_options | plci->adapter->requested_options_table[plci->appl->Id - 1])
  7761. & (1L << PRIVATE_FAX_SUB_SEP_PWD))
  7762. {
  7763. fax_control_bits |= T30_CONTROL_BIT_ACCEPT_SUBADDRESS | T30_CONTROL_BIT_ACCEPT_PASSWORD;
  7764. if (fax_control_bits & T30_CONTROL_BIT_ACCEPT_POLLING)
  7765. fax_control_bits |= T30_CONTROL_BIT_ACCEPT_SEL_POLLING;
  7766. }
  7767. len = nlc[0];
  7768. pos = offsetof(T30_INFO, station_id) + T30_MAX_STATION_ID_LENGTH;
  7769. if (pos < plci->fax_connect_info_length)
  7770. {
  7771. for (i = 1 + plci->fax_connect_info_buffer[pos]; i != 0; i--)
  7772. nlc[++len] = plci->fax_connect_info_buffer[pos++];
  7773. }
  7774. else
  7775. nlc[++len] = 0;
  7776. if (pos < plci->fax_connect_info_length)
  7777. {
  7778. for (i = 1 + plci->fax_connect_info_buffer[pos]; i != 0; i--)
  7779. nlc[++len] = plci->fax_connect_info_buffer[pos++];
  7780. }
  7781. else
  7782. nlc[++len] = 0;
  7783. if ((plci->requested_options_conn | plci->requested_options | plci->adapter->requested_options_table[plci->appl->Id - 1])
  7784. & (1L << PRIVATE_FAX_NONSTANDARD))
  7785. {
  7786. if ((pos < plci->fax_connect_info_length) && (plci->fax_connect_info_buffer[pos] != 0))
  7787. {
  7788. if ((plci->fax_connect_info_buffer[pos] >= 3) && (plci->fax_connect_info_buffer[pos + 1] >= 2))
  7789. plci->nsf_control_bits = GET_WORD(&plci->fax_connect_info_buffer[pos + 2]);
  7790. for (i = 1 + plci->fax_connect_info_buffer[pos]; i != 0; i--)
  7791. nlc[++len] = plci->fax_connect_info_buffer[pos++];
  7792. }
  7793. else
  7794. {
  7795. if (api_parse(&b3_config->info[1], (word)b3_config->length, "wwsss", b3_config_parms))
  7796. {
  7797. dbug(1, dprintf("non-standard facilities info missing or wrong format"));
  7798. nlc[++len] = 0;
  7799. }
  7800. else
  7801. {
  7802. if ((b3_config_parms[4].length >= 3) && (b3_config_parms[4].info[1] >= 2))
  7803. plci->nsf_control_bits = GET_WORD(&b3_config_parms[4].info[2]);
  7804. nlc[++len] = (byte)(b3_config_parms[4].length);
  7805. for (i = 0; i < b3_config_parms[4].length; i++)
  7806. nlc[++len] = b3_config_parms[4].info[1 + i];
  7807. }
  7808. }
  7809. }
  7810. nlc[0] = len;
  7811. if ((plci->nsf_control_bits & T30_NSF_CONTROL_BIT_ENABLE_NSF)
  7812. && (plci->nsf_control_bits & T30_NSF_CONTROL_BIT_NEGOTIATE_RESP))
  7813. {
  7814. ((T30_INFO *)&nlc[1])->operating_mode = T30_OPERATING_MODE_CAPI_NEG;
  7815. }
  7816. }
  7817. }
  7818. PUT_WORD(&(((T30_INFO *)&nlc[1])->control_bits_low), fax_control_bits);
  7819. len = offsetof(T30_INFO, station_id) + T30_MAX_STATION_ID_LENGTH;
  7820. for (i = 0; i < len; i++)
  7821. plci->fax_connect_info_buffer[i] = nlc[1 + i];
  7822. ((T30_INFO *) plci->fax_connect_info_buffer)->head_line_len = 0;
  7823. i += ((T30_INFO *)&nlc[1])->head_line_len;
  7824. while (i < nlc[0])
  7825. plci->fax_connect_info_buffer[len++] = nlc[++i];
  7826. plci->fax_connect_info_length = len;
  7827. }
  7828. else
  7829. {
  7830. nlc[0] = 14;
  7831. if (b3_config->length != 16)
  7832. return _B3_PARM_NOT_SUPPORTED;
  7833. for (i = 0; i < 12; i++) nlc[1 + i] = b3_config->info[1 + i];
  7834. if (GET_WORD(&b3_config->info[13]) != 8 && GET_WORD(&b3_config->info[13]) != 128)
  7835. return _B3_PARM_NOT_SUPPORTED;
  7836. nlc[13] = b3_config->info[13];
  7837. if (GET_WORD(&b3_config->info[15]) >= nlc[13])
  7838. return _B3_PARM_NOT_SUPPORTED;
  7839. nlc[14] = b3_config->info[15];
  7840. }
  7841. }
  7842. else
  7843. {
  7844. if (plci->B3_prot == 4
  7845. || plci->B3_prot == 5 /*T.30 - FAX*/) return _B3_PARM_NOT_SUPPORTED;
  7846. }
  7847. add_p(plci, NLC, nlc);
  7848. return 0;
  7849. }
  7850. /*----------------------------------------------------------------*/
  7851. /* make the same as add_b23, but only for the modem related */
  7852. /* L2 and L3 B-Chan protocol. */
  7853. /* */
  7854. /* Enabled L2 and L3 Configurations: */
  7855. /* If L1 == Modem all negotiation */
  7856. /* only L2 == Modem with full negotiation is allowed */
  7857. /* If L1 == Modem async or sync */
  7858. /* only L2 == Transparent is allowed */
  7859. /* L3 == Modem or L3 == Transparent are allowed */
  7860. /* B2 Configuration for modem: */
  7861. /* word : enable/disable compression, bitoptions */
  7862. /* B3 Configuration for modem: */
  7863. /* empty */
  7864. /*----------------------------------------------------------------*/
  7865. static word add_modem_b23(PLCI *plci, API_PARSE *bp_parms)
  7866. {
  7867. static byte lli[12] = {1,1};
  7868. static byte llc[3] = {2,0,0};
  7869. static byte dlc[16] = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
  7870. API_PARSE mdm_config[2];
  7871. word i;
  7872. word b2_config = 0;
  7873. for (i = 0; i < 2; i++) mdm_config[i].length = 0;
  7874. for (i = 0; i < sizeof(dlc); i++) dlc[i] = 0;
  7875. if (((GET_WORD(bp_parms[0].info) == B1_MODEM_ALL_NEGOTIATE)
  7876. && (GET_WORD(bp_parms[1].info) != B2_MODEM_EC_COMPRESSION))
  7877. || ((GET_WORD(bp_parms[0].info) != B1_MODEM_ALL_NEGOTIATE)
  7878. && (GET_WORD(bp_parms[1].info) != B2_TRANSPARENT)))
  7879. {
  7880. return (_B_STACK_NOT_SUPPORTED);
  7881. }
  7882. if ((GET_WORD(bp_parms[2].info) != B3_MODEM)
  7883. && (GET_WORD(bp_parms[2].info) != B3_TRANSPARENT))
  7884. {
  7885. return (_B_STACK_NOT_SUPPORTED);
  7886. }
  7887. plci->B2_prot = (byte) GET_WORD(bp_parms[1].info);
  7888. plci->B3_prot = (byte) GET_WORD(bp_parms[2].info);
  7889. if ((GET_WORD(bp_parms[1].info) == B2_MODEM_EC_COMPRESSION) && bp_parms[4].length)
  7890. {
  7891. if (api_parse(&bp_parms[4].info[1],
  7892. (word)bp_parms[4].length, "w",
  7893. mdm_config))
  7894. {
  7895. return (_WRONG_MESSAGE_FORMAT);
  7896. }
  7897. b2_config = GET_WORD(mdm_config[0].info);
  7898. }
  7899. /* OK, L2 is modem */
  7900. lli[0] = 1;
  7901. lli[1] = 1;
  7902. if (plci->adapter->manufacturer_features & MANUFACTURER_FEATURE_XONOFF_FLOW_CONTROL)
  7903. lli[1] |= 2;
  7904. if (plci->adapter->manufacturer_features & MANUFACTURER_FEATURE_OOB_CHANNEL)
  7905. lli[1] |= 4;
  7906. if ((lli[1] & 0x02) && (diva_xdi_extended_features & DIVA_CAPI_USE_CMA)) {
  7907. lli[1] |= 0x10;
  7908. if (plci->rx_dma_descriptor <= 0) {
  7909. plci->rx_dma_descriptor = diva_get_dma_descriptor(plci, &plci->rx_dma_magic);
  7910. if (plci->rx_dma_descriptor >= 0)
  7911. plci->rx_dma_descriptor++;
  7912. }
  7913. if (plci->rx_dma_descriptor > 0) {
  7914. lli[1] |= 0x40;
  7915. lli[0] = 6;
  7916. lli[2] = (byte)(plci->rx_dma_descriptor - 1);
  7917. lli[3] = (byte)plci->rx_dma_magic;
  7918. lli[4] = (byte)(plci->rx_dma_magic >> 8);
  7919. lli[5] = (byte)(plci->rx_dma_magic >> 16);
  7920. lli[6] = (byte)(plci->rx_dma_magic >> 24);
  7921. }
  7922. }
  7923. if (DIVA_CAPI_SUPPORTS_NO_CANCEL(plci->adapter)) {
  7924. lli[1] |= 0x20;
  7925. }
  7926. llc[1] = (plci->call_dir & (CALL_DIR_ORIGINATE | CALL_DIR_FORCE_OUTG_NL)) ?
  7927. /*V42*/ 10 : /*V42_IN*/ 9;
  7928. llc[2] = 4; /* pass L3 always transparent */
  7929. add_p(plci, LLI, lli);
  7930. add_p(plci, LLC, llc);
  7931. i = 1;
  7932. PUT_WORD(&dlc[i], plci->appl->MaxDataLength);
  7933. i += 2;
  7934. if (GET_WORD(bp_parms[1].info) == B2_MODEM_EC_COMPRESSION)
  7935. {
  7936. if (bp_parms[4].length)
  7937. {
  7938. dbug(1, dprintf("MDM b2_config=%02x", b2_config));
  7939. dlc[i++] = 3; /* Addr A */
  7940. dlc[i++] = 1; /* Addr B */
  7941. dlc[i++] = 7; /* modulo mode */
  7942. dlc[i++] = 7; /* window size */
  7943. dlc[i++] = 0; /* XID len Lo */
  7944. dlc[i++] = 0; /* XID len Hi */
  7945. if (b2_config & MDM_B2_DISABLE_V42bis)
  7946. {
  7947. dlc[i] |= DLC_MODEMPROT_DISABLE_V42_V42BIS;
  7948. }
  7949. if (b2_config & MDM_B2_DISABLE_MNP)
  7950. {
  7951. dlc[i] |= DLC_MODEMPROT_DISABLE_MNP_MNP5;
  7952. }
  7953. if (b2_config & MDM_B2_DISABLE_TRANS)
  7954. {
  7955. dlc[i] |= DLC_MODEMPROT_REQUIRE_PROTOCOL;
  7956. }
  7957. if (b2_config & MDM_B2_DISABLE_V42)
  7958. {
  7959. dlc[i] |= DLC_MODEMPROT_DISABLE_V42_DETECT;
  7960. }
  7961. if (b2_config & MDM_B2_DISABLE_COMP)
  7962. {
  7963. dlc[i] |= DLC_MODEMPROT_DISABLE_COMPRESSION;
  7964. }
  7965. i++;
  7966. }
  7967. }
  7968. else
  7969. {
  7970. dlc[i++] = 3; /* Addr A */
  7971. dlc[i++] = 1; /* Addr B */
  7972. dlc[i++] = 7; /* modulo mode */
  7973. dlc[i++] = 7; /* window size */
  7974. dlc[i++] = 0; /* XID len Lo */
  7975. dlc[i++] = 0; /* XID len Hi */
  7976. dlc[i++] = DLC_MODEMPROT_DISABLE_V42_V42BIS |
  7977. DLC_MODEMPROT_DISABLE_MNP_MNP5 |
  7978. DLC_MODEMPROT_DISABLE_V42_DETECT |
  7979. DLC_MODEMPROT_DISABLE_COMPRESSION;
  7980. }
  7981. dlc[0] = (byte)(i - 1);
  7982. /* HexDump ("DLC", sizeof(dlc), &dlc[0]); */
  7983. add_p(plci, DLC, dlc);
  7984. return (0);
  7985. }
  7986. /*------------------------------------------------------------------*/
  7987. /* send a request for the signaling entity */
  7988. /*------------------------------------------------------------------*/
  7989. static void sig_req(PLCI *plci, byte req, byte Id)
  7990. {
  7991. if (!plci) return;
  7992. if (plci->adapter->adapter_disabled) return;
  7993. dbug(1, dprintf("sig_req(%x)", req));
  7994. if (req == REMOVE)
  7995. plci->sig_remove_id = plci->Sig.Id;
  7996. if (plci->req_in == plci->req_in_start) {
  7997. plci->req_in += 2;
  7998. plci->RBuffer[plci->req_in++] = 0;
  7999. }
  8000. PUT_WORD(&plci->RBuffer[plci->req_in_start], plci->req_in-plci->req_in_start - 2);
  8001. plci->RBuffer[plci->req_in++] = Id; /* sig/nl flag */
  8002. plci->RBuffer[plci->req_in++] = req; /* request */
  8003. plci->RBuffer[plci->req_in++] = 0; /* channel */
  8004. plci->req_in_start = plci->req_in;
  8005. }
  8006. /*------------------------------------------------------------------*/
  8007. /* send a request for the network layer entity */
  8008. /*------------------------------------------------------------------*/
  8009. static void nl_req_ncci(PLCI *plci, byte req, byte ncci)
  8010. {
  8011. if (!plci) return;
  8012. if (plci->adapter->adapter_disabled) return;
  8013. dbug(1, dprintf("nl_req %02x %02x %02x", plci->Id, req, ncci));
  8014. if (req == REMOVE)
  8015. {
  8016. plci->nl_remove_id = plci->NL.Id;
  8017. ncci_remove(plci, 0, (byte)(ncci != 0));
  8018. ncci = 0;
  8019. }
  8020. if (plci->req_in == plci->req_in_start) {
  8021. plci->req_in += 2;
  8022. plci->RBuffer[plci->req_in++] = 0;
  8023. }
  8024. PUT_WORD(&plci->RBuffer[plci->req_in_start], plci->req_in-plci->req_in_start - 2);
  8025. plci->RBuffer[plci->req_in++] = 1; /* sig/nl flag */
  8026. plci->RBuffer[plci->req_in++] = req; /* request */
  8027. plci->RBuffer[plci->req_in++] = plci->adapter->ncci_ch[ncci]; /* channel */
  8028. plci->req_in_start = plci->req_in;
  8029. }
  8030. static void send_req(PLCI *plci)
  8031. {
  8032. ENTITY *e;
  8033. word l;
  8034. /* word i; */
  8035. if (!plci) return;
  8036. if (plci->adapter->adapter_disabled) return;
  8037. channel_xmit_xon(plci);
  8038. /* if nothing to do, return */
  8039. if (plci->req_in == plci->req_out) return;
  8040. dbug(1, dprintf("send_req(in=%d,out=%d)", plci->req_in, plci->req_out));
  8041. if (plci->nl_req || plci->sig_req) return;
  8042. l = GET_WORD(&plci->RBuffer[plci->req_out]);
  8043. plci->req_out += 2;
  8044. plci->XData[0].P = &plci->RBuffer[plci->req_out];
  8045. plci->req_out += l;
  8046. if (plci->RBuffer[plci->req_out] == 1)
  8047. {
  8048. e = &plci->NL;
  8049. plci->req_out++;
  8050. e->Req = plci->nl_req = plci->RBuffer[plci->req_out++];
  8051. e->ReqCh = plci->RBuffer[plci->req_out++];
  8052. if (!(e->Id & 0x1f))
  8053. {
  8054. e->Id = NL_ID;
  8055. plci->RBuffer[plci->req_out - 4] = CAI;
  8056. plci->RBuffer[plci->req_out - 3] = 1;
  8057. plci->RBuffer[plci->req_out - 2] = (plci->Sig.Id == 0xff) ? 0 : plci->Sig.Id;
  8058. plci->RBuffer[plci->req_out - 1] = 0;
  8059. l += 3;
  8060. plci->nl_global_req = plci->nl_req;
  8061. }
  8062. dbug(1, dprintf("%x:NLREQ(%x:%x:%x)", plci->adapter->Id, e->Id, e->Req, e->ReqCh));
  8063. }
  8064. else
  8065. {
  8066. e = &plci->Sig;
  8067. if (plci->RBuffer[plci->req_out])
  8068. e->Id = plci->RBuffer[plci->req_out];
  8069. plci->req_out++;
  8070. e->Req = plci->sig_req = plci->RBuffer[plci->req_out++];
  8071. e->ReqCh = plci->RBuffer[plci->req_out++];
  8072. if (!(e->Id & 0x1f))
  8073. plci->sig_global_req = plci->sig_req;
  8074. dbug(1, dprintf("%x:SIGREQ(%x:%x:%x)", plci->adapter->Id, e->Id, e->Req, e->ReqCh));
  8075. }
  8076. plci->XData[0].PLength = l;
  8077. e->X = plci->XData;
  8078. plci->adapter->request(e);
  8079. dbug(1, dprintf("send_ok"));
  8080. }
  8081. static void send_data(PLCI *plci)
  8082. {
  8083. DIVA_CAPI_ADAPTER *a;
  8084. DATA_B3_DESC *data;
  8085. NCCI *ncci_ptr;
  8086. word ncci;
  8087. if (!plci->nl_req && plci->ncci_ring_list)
  8088. {
  8089. a = plci->adapter;
  8090. ncci = plci->ncci_ring_list;
  8091. do
  8092. {
  8093. ncci = a->ncci_next[ncci];
  8094. ncci_ptr = &(a->ncci[ncci]);
  8095. if (!(a->ncci_ch[ncci]
  8096. && (a->ch_flow_control[a->ncci_ch[ncci]] & N_OK_FC_PENDING)))
  8097. {
  8098. if (ncci_ptr->data_pending)
  8099. {
  8100. if ((a->ncci_state[ncci] == CONNECTED)
  8101. || (a->ncci_state[ncci] == INC_ACT_PENDING)
  8102. || (plci->send_disc == ncci))
  8103. {
  8104. data = &(ncci_ptr->DBuffer[ncci_ptr->data_out]);
  8105. if ((plci->B2_prot == B2_V120_ASYNC)
  8106. || (plci->B2_prot == B2_V120_ASYNC_V42BIS)
  8107. || (plci->B2_prot == B2_V120_BIT_TRANSPARENT))
  8108. {
  8109. plci->NData[1].P = TransmitBufferGet(plci->appl, data->P);
  8110. plci->NData[1].PLength = data->Length;
  8111. if (data->Flags & 0x10)
  8112. plci->NData[0].P = v120_break_header;
  8113. else
  8114. plci->NData[0].P = v120_default_header;
  8115. plci->NData[0].PLength = 1;
  8116. plci->NL.XNum = 2;
  8117. plci->NL.Req = plci->nl_req = (byte)((data->Flags & 0x07) << 4 | N_DATA);
  8118. }
  8119. else
  8120. {
  8121. plci->NData[0].P = TransmitBufferGet(plci->appl, data->P);
  8122. plci->NData[0].PLength = data->Length;
  8123. if (data->Flags & 0x10)
  8124. plci->NL.Req = plci->nl_req = (byte)N_UDATA;
  8125. else if ((plci->B3_prot == B3_RTP) && (data->Flags & 0x01))
  8126. plci->NL.Req = plci->nl_req = (byte)N_BDATA;
  8127. else
  8128. plci->NL.Req = plci->nl_req = (byte)((data->Flags & 0x07) << 4 | N_DATA);
  8129. }
  8130. plci->NL.X = plci->NData;
  8131. plci->NL.ReqCh = a->ncci_ch[ncci];
  8132. dbug(1, dprintf("%x:DREQ(%x:%x)", a->Id, plci->NL.Id, plci->NL.Req));
  8133. plci->data_sent = true;
  8134. plci->data_sent_ptr = data->P;
  8135. a->request(&plci->NL);
  8136. }
  8137. else {
  8138. cleanup_ncci_data(plci, ncci);
  8139. }
  8140. }
  8141. else if (plci->send_disc == ncci)
  8142. {
  8143. /* dprintf("N_DISC"); */
  8144. plci->NData[0].PLength = 0;
  8145. plci->NL.ReqCh = a->ncci_ch[ncci];
  8146. plci->NL.Req = plci->nl_req = N_DISC;
  8147. a->request(&plci->NL);
  8148. plci->command = _DISCONNECT_B3_R;
  8149. plci->send_disc = 0;
  8150. }
  8151. }
  8152. } while (!plci->nl_req && (ncci != plci->ncci_ring_list));
  8153. plci->ncci_ring_list = ncci;
  8154. }
  8155. }
  8156. static void listen_check(DIVA_CAPI_ADAPTER *a)
  8157. {
  8158. word i, j;
  8159. PLCI *plci;
  8160. byte activnotifiedcalls = 0;
  8161. dbug(1, dprintf("listen_check(%d,%d)", a->listen_active, a->max_listen));
  8162. if (!remove_started && !a->adapter_disabled)
  8163. {
  8164. for (i = 0; i < a->max_plci; i++)
  8165. {
  8166. plci = &(a->plci[i]);
  8167. if (plci->notifiedcall) activnotifiedcalls++;
  8168. }
  8169. dbug(1, dprintf("listen_check(%d)", activnotifiedcalls));
  8170. for (i = a->listen_active; i < ((word)(a->max_listen + activnotifiedcalls)); i++) {
  8171. if ((j = get_plci(a))) {
  8172. a->listen_active++;
  8173. plci = &a->plci[j - 1];
  8174. plci->State = LISTENING;
  8175. add_p(plci, OAD, "\x01\xfd");
  8176. add_p(plci, KEY, "\x04\x43\x41\x32\x30");
  8177. add_p(plci, CAI, "\x01\xc0");
  8178. add_p(plci, UID, "\x06\x43\x61\x70\x69\x32\x30");
  8179. add_p(plci, LLI, "\x01\xc4"); /* support Dummy CR FAC + MWI + SpoofNotify */
  8180. add_p(plci, SHIFT | 6, NULL);
  8181. add_p(plci, SIN, "\x02\x00\x00");
  8182. plci->internal_command = LISTEN_SIG_ASSIGN_PEND; /* do indicate_req if OK */
  8183. sig_req(plci, ASSIGN, DSIG_ID);
  8184. send_req(plci);
  8185. }
  8186. }
  8187. }
  8188. }
  8189. /*------------------------------------------------------------------*/
  8190. /* functions for all parameters sent in INDs */
  8191. /*------------------------------------------------------------------*/
  8192. static void IndParse(PLCI *plci, const word *parms_id, byte **parms, byte multiIEsize)
  8193. {
  8194. word ploc; /* points to current location within packet */
  8195. byte w;
  8196. byte wlen;
  8197. byte codeset, lock;
  8198. byte *in;
  8199. word i;
  8200. word code;
  8201. word mIEindex = 0;
  8202. ploc = 0;
  8203. codeset = 0;
  8204. lock = 0;
  8205. in = plci->Sig.RBuffer->P;
  8206. for (i = 0; i < parms_id[0]; i++) /* multiIE parms_id contains just the 1st */
  8207. { /* element but parms array is larger */
  8208. parms[i] = (byte *)"";
  8209. }
  8210. for (i = 0; i < multiIEsize; i++)
  8211. {
  8212. parms[i] = (byte *)"";
  8213. }
  8214. while (ploc < plci->Sig.RBuffer->length - 1) {
  8215. /* read information element id and length */
  8216. w = in[ploc];
  8217. if (w & 0x80) {
  8218. /* w &=0xf0; removed, cannot detect congestion levels */
  8219. /* upper 4 bit masked with w==SHIFT now */
  8220. wlen = 0;
  8221. }
  8222. else {
  8223. wlen = (byte)(in[ploc + 1] + 1);
  8224. }
  8225. /* check if length valid (not exceeding end of packet) */
  8226. if ((ploc + wlen) > 270) return;
  8227. if (lock & 0x80) lock &= 0x7f;
  8228. else codeset = lock;
  8229. if ((w & 0xf0) == SHIFT) {
  8230. codeset = in[ploc];
  8231. if (!(codeset & 0x08)) lock = (byte)(codeset & 7);
  8232. codeset &= 7;
  8233. lock |= 0x80;
  8234. }
  8235. else {
  8236. if (w == ESC && wlen >= 3) code = in[ploc + 2] | 0x800;
  8237. else code = w;
  8238. code |= (codeset << 8);
  8239. for (i = 1; i < parms_id[0] + 1 && parms_id[i] != code; i++);
  8240. if (i < parms_id[0] + 1) {
  8241. if (!multiIEsize) { /* with multiIEs use next field index, */
  8242. mIEindex = i - 1; /* with normal IEs use same index like parms_id */
  8243. }
  8244. parms[mIEindex] = &in[ploc + 1];
  8245. dbug(1, dprintf("mIE[%d]=0x%x", *parms[mIEindex], in[ploc]));
  8246. if (parms_id[i] == OAD
  8247. || parms_id[i] == CONN_NR
  8248. || parms_id[i] == CAD) {
  8249. if (in[ploc + 2] & 0x80) {
  8250. in[ploc + 0] = (byte)(in[ploc + 1] + 1);
  8251. in[ploc + 1] = (byte)(in[ploc + 2] & 0x7f);
  8252. in[ploc + 2] = 0x80;
  8253. parms[mIEindex] = &in[ploc];
  8254. }
  8255. }
  8256. mIEindex++; /* effects multiIEs only */
  8257. }
  8258. }
  8259. ploc += (wlen + 1);
  8260. }
  8261. return;
  8262. }
  8263. /*------------------------------------------------------------------*/
  8264. /* try to match a cip from received BC and HLC */
  8265. /*------------------------------------------------------------------*/
  8266. static byte ie_compare(byte *ie1, byte *ie2)
  8267. {
  8268. word i;
  8269. if (!ie1 || !ie2) return false;
  8270. if (!ie1[0]) return false;
  8271. for (i = 0; i < (word)(ie1[0] + 1); i++) if (ie1[i] != ie2[i]) return false;
  8272. return true;
  8273. }
  8274. static word find_cip(DIVA_CAPI_ADAPTER *a, byte *bc, byte *hlc)
  8275. {
  8276. word i;
  8277. word j;
  8278. for (i = 9; i && !ie_compare(bc, cip_bc[i][a->u_law]); i--);
  8279. for (j = 16; j < 29 &&
  8280. (!ie_compare(bc, cip_bc[j][a->u_law]) || !ie_compare(hlc, cip_hlc[j])); j++);
  8281. if (j == 29) return i;
  8282. return j;
  8283. }
  8284. static byte AddInfo(byte **add_i,
  8285. byte **fty_i,
  8286. byte *esc_chi,
  8287. byte *facility)
  8288. {
  8289. byte i;
  8290. byte j;
  8291. byte k;
  8292. byte flen;
  8293. byte len = 0;
  8294. /* facility is a nested structure */
  8295. /* FTY can be more than once */
  8296. if (esc_chi[0] && !(esc_chi[esc_chi[0]] & 0x7f))
  8297. {
  8298. add_i[0] = (byte *)"\x02\x02\x00"; /* use neither b nor d channel */
  8299. }
  8300. else
  8301. {
  8302. add_i[0] = (byte *)"";
  8303. }
  8304. if (!fty_i[0][0])
  8305. {
  8306. add_i[3] = (byte *)"";
  8307. }
  8308. else
  8309. { /* facility array found */
  8310. for (i = 0, j = 1; i < MAX_MULTI_IE && fty_i[i][0]; i++)
  8311. {
  8312. dbug(1, dprintf("AddIFac[%d]", fty_i[i][0]));
  8313. len += fty_i[i][0];
  8314. len += 2;
  8315. flen = fty_i[i][0];
  8316. facility[j++] = 0x1c; /* copy fac IE */
  8317. for (k = 0; k <= flen; k++, j++)
  8318. {
  8319. facility[j] = fty_i[i][k];
  8320. /* dbug(1, dprintf("%x ",facility[j])); */
  8321. }
  8322. }
  8323. facility[0] = len;
  8324. add_i[3] = facility;
  8325. }
  8326. /* dbug(1, dprintf("FacArrLen=%d ",len)); */
  8327. len = add_i[0][0] + add_i[1][0] + add_i[2][0] + add_i[3][0];
  8328. len += 4; /* calculate length of all */
  8329. return (len);
  8330. }
  8331. /*------------------------------------------------------------------*/
  8332. /* voice and codec features */
  8333. /*------------------------------------------------------------------*/
  8334. static void SetVoiceChannel(PLCI *plci, byte *chi, DIVA_CAPI_ADAPTER *a)
  8335. {
  8336. byte voice_chi[] = "\x02\x18\x01";
  8337. byte channel;
  8338. channel = chi[chi[0]] & 0x3;
  8339. dbug(1, dprintf("ExtDevON(Ch=0x%x)", channel));
  8340. voice_chi[2] = (channel) ? channel : 1;
  8341. add_p(plci, FTY, "\x02\x01\x07"); /* B On, default on 1 */
  8342. add_p(plci, ESC, voice_chi); /* Channel */
  8343. sig_req(plci, TEL_CTRL, 0);
  8344. send_req(plci);
  8345. if (a->AdvSignalPLCI)
  8346. {
  8347. adv_voice_write_coefs(a->AdvSignalPLCI, ADV_VOICE_WRITE_ACTIVATION);
  8348. }
  8349. }
  8350. static void VoiceChannelOff(PLCI *plci)
  8351. {
  8352. dbug(1, dprintf("ExtDevOFF"));
  8353. add_p(plci, FTY, "\x02\x01\x08"); /* B Off */
  8354. sig_req(plci, TEL_CTRL, 0);
  8355. send_req(plci);
  8356. if (plci->adapter->AdvSignalPLCI)
  8357. {
  8358. adv_voice_clear_config(plci->adapter->AdvSignalPLCI);
  8359. }
  8360. }
  8361. static word AdvCodecSupport(DIVA_CAPI_ADAPTER *a, PLCI *plci, APPL *appl,
  8362. byte hook_listen)
  8363. {
  8364. word j;
  8365. PLCI *splci;
  8366. /* check if hardware supports handset with hook states (adv.codec) */
  8367. /* or if just a on board codec is supported */
  8368. /* the advanced codec plci is just for internal use */
  8369. /* diva Pro with on-board codec: */
  8370. if (a->profile.Global_Options & HANDSET)
  8371. {
  8372. /* new call, but hook states are already signalled */
  8373. if (a->AdvCodecFLAG)
  8374. {
  8375. if (a->AdvSignalAppl != appl || a->AdvSignalPLCI)
  8376. {
  8377. dbug(1, dprintf("AdvSigPlci=0x%x", a->AdvSignalPLCI));
  8378. return 0x2001; /* codec in use by another application */
  8379. }
  8380. if (plci != NULL)
  8381. {
  8382. a->AdvSignalPLCI = plci;
  8383. plci->tel = ADV_VOICE;
  8384. }
  8385. return 0; /* adv codec still used */
  8386. }
  8387. if ((j = get_plci(a)))
  8388. {
  8389. splci = &a->plci[j - 1];
  8390. splci->tel = CODEC_PERMANENT;
  8391. /* hook_listen indicates if a facility_req with handset/hook support */
  8392. /* was sent. Otherwise if just a call on an external device was made */
  8393. /* the codec will be used but the hook info will be discarded (just */
  8394. /* the external controller is in use */
  8395. if (hook_listen) splci->State = ADVANCED_VOICE_SIG;
  8396. else
  8397. {
  8398. splci->State = ADVANCED_VOICE_NOSIG;
  8399. if (plci)
  8400. {
  8401. plci->spoofed_msg = SPOOFING_REQUIRED;
  8402. }
  8403. /* indicate D-ch connect if */
  8404. } /* codec is connected OK */
  8405. if (plci != NULL)
  8406. {
  8407. a->AdvSignalPLCI = plci;
  8408. plci->tel = ADV_VOICE;
  8409. }
  8410. a->AdvSignalAppl = appl;
  8411. a->AdvCodecFLAG = true;
  8412. a->AdvCodecPLCI = splci;
  8413. add_p(splci, CAI, "\x01\x15");
  8414. add_p(splci, LLI, "\x01\x00");
  8415. add_p(splci, ESC, "\x02\x18\x00");
  8416. add_p(splci, UID, "\x06\x43\x61\x70\x69\x32\x30");
  8417. splci->internal_command = PERM_COD_ASSIGN;
  8418. dbug(1, dprintf("Codec Assign"));
  8419. sig_req(splci, ASSIGN, DSIG_ID);
  8420. send_req(splci);
  8421. }
  8422. else
  8423. {
  8424. return 0x2001; /* wrong state, no more plcis */
  8425. }
  8426. }
  8427. else if (a->profile.Global_Options & ON_BOARD_CODEC)
  8428. {
  8429. if (hook_listen) return 0x300B; /* Facility not supported */
  8430. /* no hook with SCOM */
  8431. if (plci != NULL) plci->tel = CODEC;
  8432. dbug(1, dprintf("S/SCOM codec"));
  8433. /* first time we use the scom-s codec we must shut down the internal */
  8434. /* handset application of the card. This can be done by an assign with */
  8435. /* a cai with the 0x80 bit set. Assign return code is 'out of resource'*/
  8436. if (!a->scom_appl_disable) {
  8437. if ((j = get_plci(a))) {
  8438. splci = &a->plci[j - 1];
  8439. add_p(splci, CAI, "\x01\x80");
  8440. add_p(splci, UID, "\x06\x43\x61\x70\x69\x32\x30");
  8441. sig_req(splci, ASSIGN, 0xC0); /* 0xc0 is the TEL_ID */
  8442. send_req(splci);
  8443. a->scom_appl_disable = true;
  8444. }
  8445. else{
  8446. return 0x2001; /* wrong state, no more plcis */
  8447. }
  8448. }
  8449. }
  8450. else return 0x300B; /* Facility not supported */
  8451. return 0;
  8452. }
  8453. static void CodecIdCheck(DIVA_CAPI_ADAPTER *a, PLCI *plci)
  8454. {
  8455. dbug(1, dprintf("CodecIdCheck"));
  8456. if (a->AdvSignalPLCI == plci)
  8457. {
  8458. dbug(1, dprintf("PLCI owns codec"));
  8459. VoiceChannelOff(a->AdvCodecPLCI);
  8460. if (a->AdvCodecPLCI->State == ADVANCED_VOICE_NOSIG)
  8461. {
  8462. dbug(1, dprintf("remove temp codec PLCI"));
  8463. plci_remove(a->AdvCodecPLCI);
  8464. a->AdvCodecFLAG = 0;
  8465. a->AdvCodecPLCI = NULL;
  8466. a->AdvSignalAppl = NULL;
  8467. }
  8468. a->AdvSignalPLCI = NULL;
  8469. }
  8470. }
  8471. /* -------------------------------------------------------------------
  8472. Ask for physical address of card on PCI bus
  8473. ------------------------------------------------------------------- */
  8474. static void diva_ask_for_xdi_sdram_bar(DIVA_CAPI_ADAPTER *a,
  8475. IDI_SYNC_REQ *preq) {
  8476. a->sdram_bar = 0;
  8477. if (diva_xdi_extended_features & DIVA_CAPI_XDI_PROVIDES_SDRAM_BAR) {
  8478. ENTITY *e = (ENTITY *)preq;
  8479. e->user[0] = a->Id - 1;
  8480. preq->xdi_sdram_bar.info.bar = 0;
  8481. preq->xdi_sdram_bar.Req = 0;
  8482. preq->xdi_sdram_bar.Rc = IDI_SYNC_REQ_XDI_GET_ADAPTER_SDRAM_BAR;
  8483. (*(a->request))(e);
  8484. a->sdram_bar = preq->xdi_sdram_bar.info.bar;
  8485. dbug(3, dprintf("A(%d) SDRAM BAR = %08x", a->Id, a->sdram_bar));
  8486. }
  8487. }
  8488. /* -------------------------------------------------------------------
  8489. Ask XDI about extended features
  8490. ------------------------------------------------------------------- */
  8491. static void diva_get_extended_adapter_features(DIVA_CAPI_ADAPTER *a) {
  8492. IDI_SYNC_REQ *preq;
  8493. char buffer[((sizeof(preq->xdi_extended_features) + 4) > sizeof(ENTITY)) ? (sizeof(preq->xdi_extended_features) + 4) : sizeof(ENTITY)];
  8494. char features[4];
  8495. preq = (IDI_SYNC_REQ *)&buffer[0];
  8496. if (!diva_xdi_extended_features) {
  8497. ENTITY *e = (ENTITY *)preq;
  8498. diva_xdi_extended_features |= 0x80000000;
  8499. e->user[0] = a->Id - 1;
  8500. preq->xdi_extended_features.Req = 0;
  8501. preq->xdi_extended_features.Rc = IDI_SYNC_REQ_XDI_GET_EXTENDED_FEATURES;
  8502. preq->xdi_extended_features.info.buffer_length_in_bytes = sizeof(features);
  8503. preq->xdi_extended_features.info.features = &features[0];
  8504. (*(a->request))(e);
  8505. if (features[0] & DIVA_XDI_EXTENDED_FEATURES_VALID) {
  8506. /*
  8507. Check features located in the byte '0'
  8508. */
  8509. if (features[0] & DIVA_XDI_EXTENDED_FEATURE_CMA) {
  8510. diva_xdi_extended_features |= DIVA_CAPI_USE_CMA;
  8511. }
  8512. if (features[0] & DIVA_XDI_EXTENDED_FEATURE_RX_DMA) {
  8513. diva_xdi_extended_features |= DIVA_CAPI_XDI_PROVIDES_RX_DMA;
  8514. dbug(1, dprintf("XDI provides RxDMA"));
  8515. }
  8516. if (features[0] & DIVA_XDI_EXTENDED_FEATURE_SDRAM_BAR) {
  8517. diva_xdi_extended_features |= DIVA_CAPI_XDI_PROVIDES_SDRAM_BAR;
  8518. }
  8519. if (features[0] & DIVA_XDI_EXTENDED_FEATURE_NO_CANCEL_RC) {
  8520. diva_xdi_extended_features |= DIVA_CAPI_XDI_PROVIDES_NO_CANCEL;
  8521. dbug(3, dprintf("XDI provides NO_CANCEL_RC feature"));
  8522. }
  8523. }
  8524. }
  8525. diva_ask_for_xdi_sdram_bar(a, preq);
  8526. }
  8527. /*------------------------------------------------------------------*/
  8528. /* automatic law */
  8529. /*------------------------------------------------------------------*/
  8530. /* called from OS specific part after init time to get the Law */
  8531. /* a-law (Euro) and u-law (us,japan) use different BCs in the Setup message */
  8532. void AutomaticLaw(DIVA_CAPI_ADAPTER *a)
  8533. {
  8534. word j;
  8535. PLCI *splci;
  8536. if (a->automatic_law) {
  8537. return;
  8538. }
  8539. if ((j = get_plci(a))) {
  8540. diva_get_extended_adapter_features(a);
  8541. splci = &a->plci[j - 1];
  8542. a->automatic_lawPLCI = splci;
  8543. a->automatic_law = 1;
  8544. add_p(splci, CAI, "\x01\x80");
  8545. add_p(splci, UID, "\x06\x43\x61\x70\x69\x32\x30");
  8546. splci->internal_command = USELAW_REQ;
  8547. splci->command = 0;
  8548. splci->number = 0;
  8549. sig_req(splci, ASSIGN, DSIG_ID);
  8550. send_req(splci);
  8551. }
  8552. }
  8553. /* called from OS specific part if an application sends an Capi20Release */
  8554. word CapiRelease(word Id)
  8555. {
  8556. word i, j, appls_found;
  8557. PLCI *plci;
  8558. APPL *this;
  8559. DIVA_CAPI_ADAPTER *a;
  8560. if (!Id)
  8561. {
  8562. dbug(0, dprintf("A: CapiRelease(Id==0)"));
  8563. return (_WRONG_APPL_ID);
  8564. }
  8565. this = &application[Id - 1]; /* get application pointer */
  8566. for (i = 0, appls_found = 0; i < max_appl; i++)
  8567. {
  8568. if (application[i].Id) /* an application has been found */
  8569. {
  8570. appls_found++;
  8571. }
  8572. }
  8573. for (i = 0; i < max_adapter; i++) /* scan all adapters... */
  8574. {
  8575. a = &adapter[i];
  8576. if (a->request)
  8577. {
  8578. a->Info_Mask[Id - 1] = 0;
  8579. a->CIP_Mask[Id - 1] = 0;
  8580. a->Notification_Mask[Id - 1] = 0;
  8581. a->codec_listen[Id - 1] = NULL;
  8582. a->requested_options_table[Id - 1] = 0;
  8583. for (j = 0; j < a->max_plci; j++) /* and all PLCIs connected */
  8584. { /* with this application */
  8585. plci = &a->plci[j];
  8586. if (plci->Id) /* if plci owns no application */
  8587. { /* it may be not jet connected */
  8588. if (plci->State == INC_CON_PENDING
  8589. || plci->State == INC_CON_ALERT)
  8590. {
  8591. if (test_c_ind_mask_bit(plci, (word)(Id - 1)))
  8592. {
  8593. clear_c_ind_mask_bit(plci, (word)(Id - 1));
  8594. if (c_ind_mask_empty(plci))
  8595. {
  8596. sig_req(plci, HANGUP, 0);
  8597. send_req(plci);
  8598. plci->State = OUTG_DIS_PENDING;
  8599. }
  8600. }
  8601. }
  8602. if (test_c_ind_mask_bit(plci, (word)(Id - 1)))
  8603. {
  8604. clear_c_ind_mask_bit(plci, (word)(Id - 1));
  8605. if (c_ind_mask_empty(plci))
  8606. {
  8607. if (!plci->appl)
  8608. {
  8609. plci_remove(plci);
  8610. plci->State = IDLE;
  8611. }
  8612. }
  8613. }
  8614. if (plci->appl == this)
  8615. {
  8616. plci->appl = NULL;
  8617. plci_remove(plci);
  8618. plci->State = IDLE;
  8619. }
  8620. }
  8621. }
  8622. listen_check(a);
  8623. if (a->flag_dynamic_l1_down)
  8624. {
  8625. if (appls_found == 1) /* last application does a capi release */
  8626. {
  8627. if ((j = get_plci(a)))
  8628. {
  8629. plci = &a->plci[j - 1];
  8630. plci->command = 0;
  8631. add_p(plci, OAD, "\x01\xfd");
  8632. add_p(plci, CAI, "\x01\x80");
  8633. add_p(plci, UID, "\x06\x43\x61\x70\x69\x32\x30");
  8634. add_p(plci, SHIFT | 6, NULL);
  8635. add_p(plci, SIN, "\x02\x00\x00");
  8636. plci->internal_command = REM_L1_SIG_ASSIGN_PEND;
  8637. sig_req(plci, ASSIGN, DSIG_ID);
  8638. add_p(plci, FTY, "\x02\xff\x06"); /* l1 down */
  8639. sig_req(plci, SIG_CTRL, 0);
  8640. send_req(plci);
  8641. }
  8642. }
  8643. }
  8644. if (a->AdvSignalAppl == this)
  8645. {
  8646. this->NullCREnable = false;
  8647. if (a->AdvCodecPLCI)
  8648. {
  8649. plci_remove(a->AdvCodecPLCI);
  8650. a->AdvCodecPLCI->tel = 0;
  8651. a->AdvCodecPLCI->adv_nl = 0;
  8652. }
  8653. a->AdvSignalAppl = NULL;
  8654. a->AdvSignalPLCI = NULL;
  8655. a->AdvCodecFLAG = 0;
  8656. a->AdvCodecPLCI = NULL;
  8657. }
  8658. }
  8659. }
  8660. this->Id = 0;
  8661. return GOOD;
  8662. }
  8663. static word plci_remove_check(PLCI *plci)
  8664. {
  8665. if (!plci) return true;
  8666. if (!plci->NL.Id && c_ind_mask_empty(plci))
  8667. {
  8668. if (plci->Sig.Id == 0xff)
  8669. plci->Sig.Id = 0;
  8670. if (!plci->Sig.Id)
  8671. {
  8672. dbug(1, dprintf("plci_remove_complete(%x)", plci->Id));
  8673. dbug(1, dprintf("tel=0x%x,Sig=0x%x", plci->tel, plci->Sig.Id));
  8674. if (plci->Id)
  8675. {
  8676. CodecIdCheck(plci->adapter, plci);
  8677. clear_b1_config(plci);
  8678. ncci_remove(plci, 0, false);
  8679. plci_free_msg_in_queue(plci);
  8680. channel_flow_control_remove(plci);
  8681. plci->Id = 0;
  8682. plci->State = IDLE;
  8683. plci->channels = 0;
  8684. plci->appl = NULL;
  8685. plci->notifiedcall = 0;
  8686. }
  8687. listen_check(plci->adapter);
  8688. return true;
  8689. }
  8690. }
  8691. return false;
  8692. }
  8693. /*------------------------------------------------------------------*/
  8694. static byte plci_nl_busy(PLCI *plci)
  8695. {
  8696. /* only applicable for non-multiplexed protocols */
  8697. return (plci->nl_req
  8698. || (plci->ncci_ring_list
  8699. && plci->adapter->ncci_ch[plci->ncci_ring_list]
  8700. && (plci->adapter->ch_flow_control[plci->adapter->ncci_ch[plci->ncci_ring_list]] & N_OK_FC_PENDING)));
  8701. }
  8702. /*------------------------------------------------------------------*/
  8703. /* DTMF facilities */
  8704. /*------------------------------------------------------------------*/
  8705. static struct
  8706. {
  8707. byte send_mask;
  8708. byte listen_mask;
  8709. byte character;
  8710. byte code;
  8711. } dtmf_digit_map[] =
  8712. {
  8713. { 0x01, 0x01, 0x23, DTMF_DIGIT_TONE_CODE_HASHMARK },
  8714. { 0x01, 0x01, 0x2a, DTMF_DIGIT_TONE_CODE_STAR },
  8715. { 0x01, 0x01, 0x30, DTMF_DIGIT_TONE_CODE_0 },
  8716. { 0x01, 0x01, 0x31, DTMF_DIGIT_TONE_CODE_1 },
  8717. { 0x01, 0x01, 0x32, DTMF_DIGIT_TONE_CODE_2 },
  8718. { 0x01, 0x01, 0x33, DTMF_DIGIT_TONE_CODE_3 },
  8719. { 0x01, 0x01, 0x34, DTMF_DIGIT_TONE_CODE_4 },
  8720. { 0x01, 0x01, 0x35, DTMF_DIGIT_TONE_CODE_5 },
  8721. { 0x01, 0x01, 0x36, DTMF_DIGIT_TONE_CODE_6 },
  8722. { 0x01, 0x01, 0x37, DTMF_DIGIT_TONE_CODE_7 },
  8723. { 0x01, 0x01, 0x38, DTMF_DIGIT_TONE_CODE_8 },
  8724. { 0x01, 0x01, 0x39, DTMF_DIGIT_TONE_CODE_9 },
  8725. { 0x01, 0x01, 0x41, DTMF_DIGIT_TONE_CODE_A },
  8726. { 0x01, 0x01, 0x42, DTMF_DIGIT_TONE_CODE_B },
  8727. { 0x01, 0x01, 0x43, DTMF_DIGIT_TONE_CODE_C },
  8728. { 0x01, 0x01, 0x44, DTMF_DIGIT_TONE_CODE_D },
  8729. { 0x01, 0x00, 0x61, DTMF_DIGIT_TONE_CODE_A },
  8730. { 0x01, 0x00, 0x62, DTMF_DIGIT_TONE_CODE_B },
  8731. { 0x01, 0x00, 0x63, DTMF_DIGIT_TONE_CODE_C },
  8732. { 0x01, 0x00, 0x64, DTMF_DIGIT_TONE_CODE_D },
  8733. { 0x04, 0x04, 0x80, DTMF_SIGNAL_NO_TONE },
  8734. { 0x00, 0x04, 0x81, DTMF_SIGNAL_UNIDENTIFIED_TONE },
  8735. { 0x04, 0x04, 0x82, DTMF_SIGNAL_DIAL_TONE },
  8736. { 0x04, 0x04, 0x83, DTMF_SIGNAL_PABX_INTERNAL_DIAL_TONE },
  8737. { 0x04, 0x04, 0x84, DTMF_SIGNAL_SPECIAL_DIAL_TONE },
  8738. { 0x04, 0x04, 0x85, DTMF_SIGNAL_SECOND_DIAL_TONE },
  8739. { 0x04, 0x04, 0x86, DTMF_SIGNAL_RINGING_TONE },
  8740. { 0x04, 0x04, 0x87, DTMF_SIGNAL_SPECIAL_RINGING_TONE },
  8741. { 0x04, 0x04, 0x88, DTMF_SIGNAL_BUSY_TONE },
  8742. { 0x04, 0x04, 0x89, DTMF_SIGNAL_CONGESTION_TONE },
  8743. { 0x04, 0x04, 0x8a, DTMF_SIGNAL_SPECIAL_INFORMATION_TONE },
  8744. { 0x04, 0x04, 0x8b, DTMF_SIGNAL_COMFORT_TONE },
  8745. { 0x04, 0x04, 0x8c, DTMF_SIGNAL_HOLD_TONE },
  8746. { 0x04, 0x04, 0x8d, DTMF_SIGNAL_RECORD_TONE },
  8747. { 0x04, 0x04, 0x8e, DTMF_SIGNAL_CALLER_WAITING_TONE },
  8748. { 0x04, 0x04, 0x8f, DTMF_SIGNAL_CALL_WAITING_TONE },
  8749. { 0x04, 0x04, 0x90, DTMF_SIGNAL_PAY_TONE },
  8750. { 0x04, 0x04, 0x91, DTMF_SIGNAL_POSITIVE_INDICATION_TONE },
  8751. { 0x04, 0x04, 0x92, DTMF_SIGNAL_NEGATIVE_INDICATION_TONE },
  8752. { 0x04, 0x04, 0x93, DTMF_SIGNAL_WARNING_TONE },
  8753. { 0x04, 0x04, 0x94, DTMF_SIGNAL_INTRUSION_TONE },
  8754. { 0x04, 0x04, 0x95, DTMF_SIGNAL_CALLING_CARD_SERVICE_TONE },
  8755. { 0x04, 0x04, 0x96, DTMF_SIGNAL_PAYPHONE_RECOGNITION_TONE },
  8756. { 0x04, 0x04, 0x97, DTMF_SIGNAL_CPE_ALERTING_SIGNAL },
  8757. { 0x04, 0x04, 0x98, DTMF_SIGNAL_OFF_HOOK_WARNING_TONE },
  8758. { 0x04, 0x04, 0xbf, DTMF_SIGNAL_INTERCEPT_TONE },
  8759. { 0x04, 0x04, 0xc0, DTMF_SIGNAL_MODEM_CALLING_TONE },
  8760. { 0x04, 0x04, 0xc1, DTMF_SIGNAL_FAX_CALLING_TONE },
  8761. { 0x04, 0x04, 0xc2, DTMF_SIGNAL_ANSWER_TONE },
  8762. { 0x04, 0x04, 0xc3, DTMF_SIGNAL_REVERSED_ANSWER_TONE },
  8763. { 0x04, 0x04, 0xc4, DTMF_SIGNAL_ANSAM_TONE },
  8764. { 0x04, 0x04, 0xc5, DTMF_SIGNAL_REVERSED_ANSAM_TONE },
  8765. { 0x04, 0x04, 0xc6, DTMF_SIGNAL_BELL103_ANSWER_TONE },
  8766. { 0x04, 0x04, 0xc7, DTMF_SIGNAL_FAX_FLAGS },
  8767. { 0x04, 0x04, 0xc8, DTMF_SIGNAL_G2_FAX_GROUP_ID },
  8768. { 0x00, 0x04, 0xc9, DTMF_SIGNAL_HUMAN_SPEECH },
  8769. { 0x04, 0x04, 0xca, DTMF_SIGNAL_ANSWERING_MACHINE_390 },
  8770. { 0x02, 0x02, 0xf1, DTMF_MF_DIGIT_TONE_CODE_1 },
  8771. { 0x02, 0x02, 0xf2, DTMF_MF_DIGIT_TONE_CODE_2 },
  8772. { 0x02, 0x02, 0xf3, DTMF_MF_DIGIT_TONE_CODE_3 },
  8773. { 0x02, 0x02, 0xf4, DTMF_MF_DIGIT_TONE_CODE_4 },
  8774. { 0x02, 0x02, 0xf5, DTMF_MF_DIGIT_TONE_CODE_5 },
  8775. { 0x02, 0x02, 0xf6, DTMF_MF_DIGIT_TONE_CODE_6 },
  8776. { 0x02, 0x02, 0xf7, DTMF_MF_DIGIT_TONE_CODE_7 },
  8777. { 0x02, 0x02, 0xf8, DTMF_MF_DIGIT_TONE_CODE_8 },
  8778. { 0x02, 0x02, 0xf9, DTMF_MF_DIGIT_TONE_CODE_9 },
  8779. { 0x02, 0x02, 0xfa, DTMF_MF_DIGIT_TONE_CODE_0 },
  8780. { 0x02, 0x02, 0xfb, DTMF_MF_DIGIT_TONE_CODE_K1 },
  8781. { 0x02, 0x02, 0xfc, DTMF_MF_DIGIT_TONE_CODE_K2 },
  8782. { 0x02, 0x02, 0xfd, DTMF_MF_DIGIT_TONE_CODE_KP },
  8783. { 0x02, 0x02, 0xfe, DTMF_MF_DIGIT_TONE_CODE_S1 },
  8784. { 0x02, 0x02, 0xff, DTMF_MF_DIGIT_TONE_CODE_ST },
  8785. };
  8786. #define DTMF_DIGIT_MAP_ENTRIES ARRAY_SIZE(dtmf_digit_map)
  8787. static void dtmf_enable_receiver(PLCI *plci, byte enable_mask)
  8788. {
  8789. word min_digit_duration, min_gap_duration;
  8790. dbug(1, dprintf("[%06lx] %s,%d: dtmf_enable_receiver %02x",
  8791. (dword)((plci->Id << 8) | UnMapController(plci->adapter->Id)),
  8792. (char *)(FILE_), __LINE__, enable_mask));
  8793. if (enable_mask != 0)
  8794. {
  8795. min_digit_duration = (plci->dtmf_rec_pulse_ms == 0) ? 40 : plci->dtmf_rec_pulse_ms;
  8796. min_gap_duration = (plci->dtmf_rec_pause_ms == 0) ? 40 : plci->dtmf_rec_pause_ms;
  8797. plci->internal_req_buffer[0] = DTMF_UDATA_REQUEST_ENABLE_RECEIVER;
  8798. PUT_WORD(&plci->internal_req_buffer[1], min_digit_duration);
  8799. PUT_WORD(&plci->internal_req_buffer[3], min_gap_duration);
  8800. plci->NData[0].PLength = 5;
  8801. PUT_WORD(&plci->internal_req_buffer[5], INTERNAL_IND_BUFFER_SIZE);
  8802. plci->NData[0].PLength += 2;
  8803. capidtmf_recv_enable(&(plci->capidtmf_state), min_digit_duration, min_gap_duration);
  8804. }
  8805. else
  8806. {
  8807. plci->internal_req_buffer[0] = DTMF_UDATA_REQUEST_DISABLE_RECEIVER;
  8808. plci->NData[0].PLength = 1;
  8809. capidtmf_recv_disable(&(plci->capidtmf_state));
  8810. }
  8811. plci->NData[0].P = plci->internal_req_buffer;
  8812. plci->NL.X = plci->NData;
  8813. plci->NL.ReqCh = 0;
  8814. plci->NL.Req = plci->nl_req = (byte) N_UDATA;
  8815. plci->adapter->request(&plci->NL);
  8816. }
  8817. static void dtmf_send_digits(PLCI *plci, byte *digit_buffer, word digit_count)
  8818. {
  8819. word w, i;
  8820. dbug(1, dprintf("[%06lx] %s,%d: dtmf_send_digits %d",
  8821. (dword)((plci->Id << 8) | UnMapController(plci->adapter->Id)),
  8822. (char *)(FILE_), __LINE__, digit_count));
  8823. plci->internal_req_buffer[0] = DTMF_UDATA_REQUEST_SEND_DIGITS;
  8824. w = (plci->dtmf_send_pulse_ms == 0) ? 40 : plci->dtmf_send_pulse_ms;
  8825. PUT_WORD(&plci->internal_req_buffer[1], w);
  8826. w = (plci->dtmf_send_pause_ms == 0) ? 40 : plci->dtmf_send_pause_ms;
  8827. PUT_WORD(&plci->internal_req_buffer[3], w);
  8828. for (i = 0; i < digit_count; i++)
  8829. {
  8830. w = 0;
  8831. while ((w < DTMF_DIGIT_MAP_ENTRIES)
  8832. && (digit_buffer[i] != dtmf_digit_map[w].character))
  8833. {
  8834. w++;
  8835. }
  8836. plci->internal_req_buffer[5 + i] = (w < DTMF_DIGIT_MAP_ENTRIES) ?
  8837. dtmf_digit_map[w].code : DTMF_DIGIT_TONE_CODE_STAR;
  8838. }
  8839. plci->NData[0].PLength = 5 + digit_count;
  8840. plci->NData[0].P = plci->internal_req_buffer;
  8841. plci->NL.X = plci->NData;
  8842. plci->NL.ReqCh = 0;
  8843. plci->NL.Req = plci->nl_req = (byte) N_UDATA;
  8844. plci->adapter->request(&plci->NL);
  8845. }
  8846. static void dtmf_rec_clear_config(PLCI *plci)
  8847. {
  8848. dbug(1, dprintf("[%06lx] %s,%d: dtmf_rec_clear_config",
  8849. (dword)((plci->Id << 8) | UnMapController(plci->adapter->Id)),
  8850. (char *)(FILE_), __LINE__));
  8851. plci->dtmf_rec_active = 0;
  8852. plci->dtmf_rec_pulse_ms = 0;
  8853. plci->dtmf_rec_pause_ms = 0;
  8854. capidtmf_init(&(plci->capidtmf_state), plci->adapter->u_law);
  8855. }
  8856. static void dtmf_send_clear_config(PLCI *plci)
  8857. {
  8858. dbug(1, dprintf("[%06lx] %s,%d: dtmf_send_clear_config",
  8859. (dword)((plci->Id << 8) | UnMapController(plci->adapter->Id)),
  8860. (char *)(FILE_), __LINE__));
  8861. plci->dtmf_send_requests = 0;
  8862. plci->dtmf_send_pulse_ms = 0;
  8863. plci->dtmf_send_pause_ms = 0;
  8864. }
  8865. static void dtmf_prepare_switch(dword Id, PLCI *plci)
  8866. {
  8867. dbug(1, dprintf("[%06lx] %s,%d: dtmf_prepare_switch",
  8868. UnMapId(Id), (char *)(FILE_), __LINE__));
  8869. while (plci->dtmf_send_requests != 0)
  8870. dtmf_confirmation(Id, plci);
  8871. }
  8872. static word dtmf_save_config(dword Id, PLCI *plci, byte Rc)
  8873. {
  8874. dbug(1, dprintf("[%06lx] %s,%d: dtmf_save_config %02x %d",
  8875. UnMapId(Id), (char *)(FILE_), __LINE__, Rc, plci->adjust_b_state));
  8876. return (GOOD);
  8877. }
  8878. static word dtmf_restore_config(dword Id, PLCI *plci, byte Rc)
  8879. {
  8880. word Info;
  8881. dbug(1, dprintf("[%06lx] %s,%d: dtmf_restore_config %02x %d",
  8882. UnMapId(Id), (char *)(FILE_), __LINE__, Rc, plci->adjust_b_state));
  8883. Info = GOOD;
  8884. if (plci->B1_facilities & B1_FACILITY_DTMFR)
  8885. {
  8886. switch (plci->adjust_b_state)
  8887. {
  8888. case ADJUST_B_RESTORE_DTMF_1:
  8889. plci->internal_command = plci->adjust_b_command;
  8890. if (plci_nl_busy(plci))
  8891. {
  8892. plci->adjust_b_state = ADJUST_B_RESTORE_DTMF_1;
  8893. break;
  8894. }
  8895. dtmf_enable_receiver(plci, plci->dtmf_rec_active);
  8896. plci->adjust_b_state = ADJUST_B_RESTORE_DTMF_2;
  8897. break;
  8898. case ADJUST_B_RESTORE_DTMF_2:
  8899. if ((Rc != OK) && (Rc != OK_FC))
  8900. {
  8901. dbug(1, dprintf("[%06lx] %s,%d: Reenable DTMF receiver failed %02x",
  8902. UnMapId(Id), (char *)(FILE_), __LINE__, Rc));
  8903. Info = _WRONG_STATE;
  8904. break;
  8905. }
  8906. break;
  8907. }
  8908. }
  8909. return (Info);
  8910. }
  8911. static void dtmf_command(dword Id, PLCI *plci, byte Rc)
  8912. {
  8913. word internal_command, Info;
  8914. byte mask;
  8915. byte result[4];
  8916. dbug(1, dprintf("[%06lx] %s,%d: dtmf_command %02x %04x %04x %d %d %d %d",
  8917. UnMapId(Id), (char *)(FILE_), __LINE__, Rc, plci->internal_command,
  8918. plci->dtmf_cmd, plci->dtmf_rec_pulse_ms, plci->dtmf_rec_pause_ms,
  8919. plci->dtmf_send_pulse_ms, plci->dtmf_send_pause_ms));
  8920. Info = GOOD;
  8921. result[0] = 2;
  8922. PUT_WORD(&result[1], DTMF_SUCCESS);
  8923. internal_command = plci->internal_command;
  8924. plci->internal_command = 0;
  8925. mask = 0x01;
  8926. switch (plci->dtmf_cmd)
  8927. {
  8928. case DTMF_LISTEN_TONE_START:
  8929. mask <<= 1;
  8930. case DTMF_LISTEN_MF_START:
  8931. mask <<= 1;
  8932. case DTMF_LISTEN_START:
  8933. switch (internal_command)
  8934. {
  8935. default:
  8936. adjust_b1_resource(Id, plci, NULL, (word)(plci->B1_facilities |
  8937. B1_FACILITY_DTMFR), DTMF_COMMAND_1);
  8938. case DTMF_COMMAND_1:
  8939. if (adjust_b_process(Id, plci, Rc) != GOOD)
  8940. {
  8941. dbug(1, dprintf("[%06lx] %s,%d: Load DTMF failed",
  8942. UnMapId(Id), (char *)(FILE_), __LINE__));
  8943. Info = _FACILITY_NOT_SUPPORTED;
  8944. break;
  8945. }
  8946. if (plci->internal_command)
  8947. return;
  8948. case DTMF_COMMAND_2:
  8949. if (plci_nl_busy(plci))
  8950. {
  8951. plci->internal_command = DTMF_COMMAND_2;
  8952. return;
  8953. }
  8954. plci->internal_command = DTMF_COMMAND_3;
  8955. dtmf_enable_receiver(plci, (byte)(plci->dtmf_rec_active | mask));
  8956. return;
  8957. case DTMF_COMMAND_3:
  8958. if ((Rc != OK) && (Rc != OK_FC))
  8959. {
  8960. dbug(1, dprintf("[%06lx] %s,%d: Enable DTMF receiver failed %02x",
  8961. UnMapId(Id), (char *)(FILE_), __LINE__, Rc));
  8962. Info = _FACILITY_NOT_SUPPORTED;
  8963. break;
  8964. }
  8965. plci->tone_last_indication_code = DTMF_SIGNAL_NO_TONE;
  8966. plci->dtmf_rec_active |= mask;
  8967. break;
  8968. }
  8969. break;
  8970. case DTMF_LISTEN_TONE_STOP:
  8971. mask <<= 1;
  8972. case DTMF_LISTEN_MF_STOP:
  8973. mask <<= 1;
  8974. case DTMF_LISTEN_STOP:
  8975. switch (internal_command)
  8976. {
  8977. default:
  8978. plci->dtmf_rec_active &= ~mask;
  8979. if (plci->dtmf_rec_active)
  8980. break;
  8981. /*
  8982. case DTMF_COMMAND_1:
  8983. if (plci->dtmf_rec_active)
  8984. {
  8985. if (plci_nl_busy (plci))
  8986. {
  8987. plci->internal_command = DTMF_COMMAND_1;
  8988. return;
  8989. }
  8990. plci->dtmf_rec_active &= ~mask;
  8991. plci->internal_command = DTMF_COMMAND_2;
  8992. dtmf_enable_receiver (plci, false);
  8993. return;
  8994. }
  8995. Rc = OK;
  8996. case DTMF_COMMAND_2:
  8997. if ((Rc != OK) && (Rc != OK_FC))
  8998. {
  8999. dbug (1, dprintf("[%06lx] %s,%d: Disable DTMF receiver failed %02x",
  9000. UnMapId (Id), (char far *)(FILE_), __LINE__, Rc));
  9001. Info = _FACILITY_NOT_SUPPORTED;
  9002. break;
  9003. }
  9004. */
  9005. adjust_b1_resource(Id, plci, NULL, (word)(plci->B1_facilities &
  9006. ~(B1_FACILITY_DTMFX | B1_FACILITY_DTMFR)), DTMF_COMMAND_3);
  9007. case DTMF_COMMAND_3:
  9008. if (adjust_b_process(Id, plci, Rc) != GOOD)
  9009. {
  9010. dbug(1, dprintf("[%06lx] %s,%d: Unload DTMF failed",
  9011. UnMapId(Id), (char *)(FILE_), __LINE__));
  9012. Info = _FACILITY_NOT_SUPPORTED;
  9013. break;
  9014. }
  9015. if (plci->internal_command)
  9016. return;
  9017. break;
  9018. }
  9019. break;
  9020. case DTMF_SEND_TONE:
  9021. mask <<= 1;
  9022. case DTMF_SEND_MF:
  9023. mask <<= 1;
  9024. case DTMF_DIGITS_SEND:
  9025. switch (internal_command)
  9026. {
  9027. default:
  9028. adjust_b1_resource(Id, plci, NULL, (word)(plci->B1_facilities |
  9029. ((plci->dtmf_parameter_length != 0) ? B1_FACILITY_DTMFX | B1_FACILITY_DTMFR : B1_FACILITY_DTMFX)),
  9030. DTMF_COMMAND_1);
  9031. case DTMF_COMMAND_1:
  9032. if (adjust_b_process(Id, plci, Rc) != GOOD)
  9033. {
  9034. dbug(1, dprintf("[%06lx] %s,%d: Load DTMF failed",
  9035. UnMapId(Id), (char *)(FILE_), __LINE__));
  9036. Info = _FACILITY_NOT_SUPPORTED;
  9037. break;
  9038. }
  9039. if (plci->internal_command)
  9040. return;
  9041. case DTMF_COMMAND_2:
  9042. if (plci_nl_busy(plci))
  9043. {
  9044. plci->internal_command = DTMF_COMMAND_2;
  9045. return;
  9046. }
  9047. plci->dtmf_msg_number_queue[(plci->dtmf_send_requests)++] = plci->number;
  9048. plci->internal_command = DTMF_COMMAND_3;
  9049. dtmf_send_digits(plci, &plci->saved_msg.parms[3].info[1], plci->saved_msg.parms[3].length);
  9050. return;
  9051. case DTMF_COMMAND_3:
  9052. if ((Rc != OK) && (Rc != OK_FC))
  9053. {
  9054. dbug(1, dprintf("[%06lx] %s,%d: Send DTMF digits failed %02x",
  9055. UnMapId(Id), (char *)(FILE_), __LINE__, Rc));
  9056. if (plci->dtmf_send_requests != 0)
  9057. (plci->dtmf_send_requests)--;
  9058. Info = _FACILITY_NOT_SUPPORTED;
  9059. break;
  9060. }
  9061. return;
  9062. }
  9063. break;
  9064. }
  9065. sendf(plci->appl, _FACILITY_R | CONFIRM, Id & 0xffffL, plci->number,
  9066. "wws", Info, SELECTOR_DTMF, result);
  9067. }
  9068. static byte dtmf_request(dword Id, word Number, DIVA_CAPI_ADAPTER *a, PLCI *plci, APPL *appl, API_PARSE *msg)
  9069. {
  9070. word Info;
  9071. word i, j;
  9072. byte mask;
  9073. API_PARSE dtmf_parms[5];
  9074. byte result[40];
  9075. dbug(1, dprintf("[%06lx] %s,%d: dtmf_request",
  9076. UnMapId(Id), (char *)(FILE_), __LINE__));
  9077. Info = GOOD;
  9078. result[0] = 2;
  9079. PUT_WORD(&result[1], DTMF_SUCCESS);
  9080. if (!(a->profile.Global_Options & GL_DTMF_SUPPORTED))
  9081. {
  9082. dbug(1, dprintf("[%06lx] %s,%d: Facility not supported",
  9083. UnMapId(Id), (char *)(FILE_), __LINE__));
  9084. Info = _FACILITY_NOT_SUPPORTED;
  9085. }
  9086. else if (api_parse(&msg[1].info[1], msg[1].length, "w", dtmf_parms))
  9087. {
  9088. dbug(1, dprintf("[%06lx] %s,%d: Wrong message format",
  9089. UnMapId(Id), (char *)(FILE_), __LINE__));
  9090. Info = _WRONG_MESSAGE_FORMAT;
  9091. }
  9092. else if ((GET_WORD(dtmf_parms[0].info) == DTMF_GET_SUPPORTED_DETECT_CODES)
  9093. || (GET_WORD(dtmf_parms[0].info) == DTMF_GET_SUPPORTED_SEND_CODES))
  9094. {
  9095. if (!((a->requested_options_table[appl->Id - 1])
  9096. & (1L << PRIVATE_DTMF_TONE)))
  9097. {
  9098. dbug(1, dprintf("[%06lx] %s,%d: DTMF unknown request %04x",
  9099. UnMapId(Id), (char *)(FILE_), __LINE__, GET_WORD(dtmf_parms[0].info)));
  9100. PUT_WORD(&result[1], DTMF_UNKNOWN_REQUEST);
  9101. }
  9102. else
  9103. {
  9104. for (i = 0; i < 32; i++)
  9105. result[4 + i] = 0;
  9106. if (GET_WORD(dtmf_parms[0].info) == DTMF_GET_SUPPORTED_DETECT_CODES)
  9107. {
  9108. for (i = 0; i < DTMF_DIGIT_MAP_ENTRIES; i++)
  9109. {
  9110. if (dtmf_digit_map[i].listen_mask != 0)
  9111. result[4 + (dtmf_digit_map[i].character >> 3)] |= (1 << (dtmf_digit_map[i].character & 0x7));
  9112. }
  9113. }
  9114. else
  9115. {
  9116. for (i = 0; i < DTMF_DIGIT_MAP_ENTRIES; i++)
  9117. {
  9118. if (dtmf_digit_map[i].send_mask != 0)
  9119. result[4 + (dtmf_digit_map[i].character >> 3)] |= (1 << (dtmf_digit_map[i].character & 0x7));
  9120. }
  9121. }
  9122. result[0] = 3 + 32;
  9123. result[3] = 32;
  9124. }
  9125. }
  9126. else if (plci == NULL)
  9127. {
  9128. dbug(1, dprintf("[%06lx] %s,%d: Wrong PLCI",
  9129. UnMapId(Id), (char *)(FILE_), __LINE__));
  9130. Info = _WRONG_IDENTIFIER;
  9131. }
  9132. else
  9133. {
  9134. if (!plci->State
  9135. || !plci->NL.Id || plci->nl_remove_id)
  9136. {
  9137. dbug(1, dprintf("[%06lx] %s,%d: Wrong state",
  9138. UnMapId(Id), (char *)(FILE_), __LINE__));
  9139. Info = _WRONG_STATE;
  9140. }
  9141. else
  9142. {
  9143. plci->command = 0;
  9144. plci->dtmf_cmd = GET_WORD(dtmf_parms[0].info);
  9145. mask = 0x01;
  9146. switch (plci->dtmf_cmd)
  9147. {
  9148. case DTMF_LISTEN_TONE_START:
  9149. case DTMF_LISTEN_TONE_STOP:
  9150. mask <<= 1;
  9151. case DTMF_LISTEN_MF_START:
  9152. case DTMF_LISTEN_MF_STOP:
  9153. mask <<= 1;
  9154. if (!((plci->requested_options_conn | plci->requested_options | plci->adapter->requested_options_table[appl->Id - 1])
  9155. & (1L << PRIVATE_DTMF_TONE)))
  9156. {
  9157. dbug(1, dprintf("[%06lx] %s,%d: DTMF unknown request %04x",
  9158. UnMapId(Id), (char *)(FILE_), __LINE__, GET_WORD(dtmf_parms[0].info)));
  9159. PUT_WORD(&result[1], DTMF_UNKNOWN_REQUEST);
  9160. break;
  9161. }
  9162. case DTMF_LISTEN_START:
  9163. case DTMF_LISTEN_STOP:
  9164. if (!(a->manufacturer_features & MANUFACTURER_FEATURE_HARDDTMF)
  9165. && !(a->manufacturer_features & MANUFACTURER_FEATURE_SOFTDTMF_RECEIVE))
  9166. {
  9167. dbug(1, dprintf("[%06lx] %s,%d: Facility not supported",
  9168. UnMapId(Id), (char *)(FILE_), __LINE__));
  9169. Info = _FACILITY_NOT_SUPPORTED;
  9170. break;
  9171. }
  9172. if (mask & DTMF_LISTEN_ACTIVE_FLAG)
  9173. {
  9174. if (api_parse(&msg[1].info[1], msg[1].length, "wwws", dtmf_parms))
  9175. {
  9176. plci->dtmf_rec_pulse_ms = 0;
  9177. plci->dtmf_rec_pause_ms = 0;
  9178. }
  9179. else
  9180. {
  9181. plci->dtmf_rec_pulse_ms = GET_WORD(dtmf_parms[1].info);
  9182. plci->dtmf_rec_pause_ms = GET_WORD(dtmf_parms[2].info);
  9183. }
  9184. }
  9185. start_internal_command(Id, plci, dtmf_command);
  9186. return (false);
  9187. case DTMF_SEND_TONE:
  9188. mask <<= 1;
  9189. case DTMF_SEND_MF:
  9190. mask <<= 1;
  9191. if (!((plci->requested_options_conn | plci->requested_options | plci->adapter->requested_options_table[appl->Id - 1])
  9192. & (1L << PRIVATE_DTMF_TONE)))
  9193. {
  9194. dbug(1, dprintf("[%06lx] %s,%d: DTMF unknown request %04x",
  9195. UnMapId(Id), (char *)(FILE_), __LINE__, GET_WORD(dtmf_parms[0].info)));
  9196. PUT_WORD(&result[1], DTMF_UNKNOWN_REQUEST);
  9197. break;
  9198. }
  9199. case DTMF_DIGITS_SEND:
  9200. if (api_parse(&msg[1].info[1], msg[1].length, "wwws", dtmf_parms))
  9201. {
  9202. dbug(1, dprintf("[%06lx] %s,%d: Wrong message format",
  9203. UnMapId(Id), (char *)(FILE_), __LINE__));
  9204. Info = _WRONG_MESSAGE_FORMAT;
  9205. break;
  9206. }
  9207. if (mask & DTMF_LISTEN_ACTIVE_FLAG)
  9208. {
  9209. plci->dtmf_send_pulse_ms = GET_WORD(dtmf_parms[1].info);
  9210. plci->dtmf_send_pause_ms = GET_WORD(dtmf_parms[2].info);
  9211. }
  9212. i = 0;
  9213. j = 0;
  9214. while ((i < dtmf_parms[3].length) && (j < DTMF_DIGIT_MAP_ENTRIES))
  9215. {
  9216. j = 0;
  9217. while ((j < DTMF_DIGIT_MAP_ENTRIES)
  9218. && ((dtmf_parms[3].info[i + 1] != dtmf_digit_map[j].character)
  9219. || ((dtmf_digit_map[j].send_mask & mask) == 0)))
  9220. {
  9221. j++;
  9222. }
  9223. i++;
  9224. }
  9225. if (j == DTMF_DIGIT_MAP_ENTRIES)
  9226. {
  9227. dbug(1, dprintf("[%06lx] %s,%d: Incorrect DTMF digit %02x",
  9228. UnMapId(Id), (char *)(FILE_), __LINE__, dtmf_parms[3].info[i]));
  9229. PUT_WORD(&result[1], DTMF_INCORRECT_DIGIT);
  9230. break;
  9231. }
  9232. if (plci->dtmf_send_requests >= ARRAY_SIZE(plci->dtmf_msg_number_queue))
  9233. {
  9234. dbug(1, dprintf("[%06lx] %s,%d: DTMF request overrun",
  9235. UnMapId(Id), (char *)(FILE_), __LINE__));
  9236. Info = _WRONG_STATE;
  9237. break;
  9238. }
  9239. api_save_msg(dtmf_parms, "wwws", &plci->saved_msg);
  9240. start_internal_command(Id, plci, dtmf_command);
  9241. return (false);
  9242. default:
  9243. dbug(1, dprintf("[%06lx] %s,%d: DTMF unknown request %04x",
  9244. UnMapId(Id), (char *)(FILE_), __LINE__, plci->dtmf_cmd));
  9245. PUT_WORD(&result[1], DTMF_UNKNOWN_REQUEST);
  9246. }
  9247. }
  9248. }
  9249. sendf(appl, _FACILITY_R | CONFIRM, Id & 0xffffL, Number,
  9250. "wws", Info, SELECTOR_DTMF, result);
  9251. return (false);
  9252. }
  9253. static void dtmf_confirmation(dword Id, PLCI *plci)
  9254. {
  9255. word i;
  9256. byte result[4];
  9257. dbug(1, dprintf("[%06lx] %s,%d: dtmf_confirmation",
  9258. UnMapId(Id), (char *)(FILE_), __LINE__));
  9259. result[0] = 2;
  9260. PUT_WORD(&result[1], DTMF_SUCCESS);
  9261. if (plci->dtmf_send_requests != 0)
  9262. {
  9263. sendf(plci->appl, _FACILITY_R | CONFIRM, Id & 0xffffL, plci->dtmf_msg_number_queue[0],
  9264. "wws", GOOD, SELECTOR_DTMF, result);
  9265. (plci->dtmf_send_requests)--;
  9266. for (i = 0; i < plci->dtmf_send_requests; i++)
  9267. plci->dtmf_msg_number_queue[i] = plci->dtmf_msg_number_queue[i + 1];
  9268. }
  9269. }
  9270. static void dtmf_indication(dword Id, PLCI *plci, byte *msg, word length)
  9271. {
  9272. word i, j, n;
  9273. dbug(1, dprintf("[%06lx] %s,%d: dtmf_indication",
  9274. UnMapId(Id), (char *)(FILE_), __LINE__));
  9275. n = 0;
  9276. for (i = 1; i < length; i++)
  9277. {
  9278. j = 0;
  9279. while ((j < DTMF_DIGIT_MAP_ENTRIES)
  9280. && ((msg[i] != dtmf_digit_map[j].code)
  9281. || ((dtmf_digit_map[j].listen_mask & plci->dtmf_rec_active) == 0)))
  9282. {
  9283. j++;
  9284. }
  9285. if (j < DTMF_DIGIT_MAP_ENTRIES)
  9286. {
  9287. if ((dtmf_digit_map[j].listen_mask & DTMF_TONE_LISTEN_ACTIVE_FLAG)
  9288. && (plci->tone_last_indication_code == DTMF_SIGNAL_NO_TONE)
  9289. && (dtmf_digit_map[j].character != DTMF_SIGNAL_UNIDENTIFIED_TONE))
  9290. {
  9291. if (n + 1 == i)
  9292. {
  9293. for (i = length; i > n + 1; i--)
  9294. msg[i] = msg[i - 1];
  9295. length++;
  9296. i++;
  9297. }
  9298. msg[++n] = DTMF_SIGNAL_UNIDENTIFIED_TONE;
  9299. }
  9300. plci->tone_last_indication_code = dtmf_digit_map[j].character;
  9301. msg[++n] = dtmf_digit_map[j].character;
  9302. }
  9303. }
  9304. if (n != 0)
  9305. {
  9306. msg[0] = (byte) n;
  9307. sendf(plci->appl, _FACILITY_I, Id & 0xffffL, 0, "wS", SELECTOR_DTMF, msg);
  9308. }
  9309. }
  9310. /*------------------------------------------------------------------*/
  9311. /* DTMF parameters */
  9312. /*------------------------------------------------------------------*/
  9313. static void dtmf_parameter_write(PLCI *plci)
  9314. {
  9315. word i;
  9316. byte parameter_buffer[DTMF_PARAMETER_BUFFER_SIZE + 2];
  9317. dbug(1, dprintf("[%06lx] %s,%d: dtmf_parameter_write",
  9318. (dword)((plci->Id << 8) | UnMapController(plci->adapter->Id)),
  9319. (char *)(FILE_), __LINE__));
  9320. parameter_buffer[0] = plci->dtmf_parameter_length + 1;
  9321. parameter_buffer[1] = DSP_CTRL_SET_DTMF_PARAMETERS;
  9322. for (i = 0; i < plci->dtmf_parameter_length; i++)
  9323. parameter_buffer[2 + i] = plci->dtmf_parameter_buffer[i];
  9324. add_p(plci, FTY, parameter_buffer);
  9325. sig_req(plci, TEL_CTRL, 0);
  9326. send_req(plci);
  9327. }
  9328. static void dtmf_parameter_clear_config(PLCI *plci)
  9329. {
  9330. dbug(1, dprintf("[%06lx] %s,%d: dtmf_parameter_clear_config",
  9331. (dword)((plci->Id << 8) | UnMapController(plci->adapter->Id)),
  9332. (char *)(FILE_), __LINE__));
  9333. plci->dtmf_parameter_length = 0;
  9334. }
  9335. static void dtmf_parameter_prepare_switch(dword Id, PLCI *plci)
  9336. {
  9337. dbug(1, dprintf("[%06lx] %s,%d: dtmf_parameter_prepare_switch",
  9338. UnMapId(Id), (char *)(FILE_), __LINE__));
  9339. }
  9340. static word dtmf_parameter_save_config(dword Id, PLCI *plci, byte Rc)
  9341. {
  9342. dbug(1, dprintf("[%06lx] %s,%d: dtmf_parameter_save_config %02x %d",
  9343. UnMapId(Id), (char *)(FILE_), __LINE__, Rc, plci->adjust_b_state));
  9344. return (GOOD);
  9345. }
  9346. static word dtmf_parameter_restore_config(dword Id, PLCI *plci, byte Rc)
  9347. {
  9348. word Info;
  9349. dbug(1, dprintf("[%06lx] %s,%d: dtmf_parameter_restore_config %02x %d",
  9350. UnMapId(Id), (char *)(FILE_), __LINE__, Rc, plci->adjust_b_state));
  9351. Info = GOOD;
  9352. if ((plci->B1_facilities & B1_FACILITY_DTMFR)
  9353. && (plci->dtmf_parameter_length != 0))
  9354. {
  9355. switch (plci->adjust_b_state)
  9356. {
  9357. case ADJUST_B_RESTORE_DTMF_PARAMETER_1:
  9358. plci->internal_command = plci->adjust_b_command;
  9359. if (plci->sig_req)
  9360. {
  9361. plci->adjust_b_state = ADJUST_B_RESTORE_DTMF_PARAMETER_1;
  9362. break;
  9363. }
  9364. dtmf_parameter_write(plci);
  9365. plci->adjust_b_state = ADJUST_B_RESTORE_DTMF_PARAMETER_2;
  9366. break;
  9367. case ADJUST_B_RESTORE_DTMF_PARAMETER_2:
  9368. if ((Rc != OK) && (Rc != OK_FC))
  9369. {
  9370. dbug(1, dprintf("[%06lx] %s,%d: Restore DTMF parameters failed %02x",
  9371. UnMapId(Id), (char *)(FILE_), __LINE__, Rc));
  9372. Info = _WRONG_STATE;
  9373. break;
  9374. }
  9375. break;
  9376. }
  9377. }
  9378. return (Info);
  9379. }
  9380. /*------------------------------------------------------------------*/
  9381. /* Line interconnect facilities */
  9382. /*------------------------------------------------------------------*/
  9383. LI_CONFIG *li_config_table;
  9384. word li_total_channels;
  9385. /*------------------------------------------------------------------*/
  9386. /* translate a CHI information element to a channel number */
  9387. /* returns 0xff - any channel */
  9388. /* 0xfe - chi wrong coding */
  9389. /* 0xfd - D-channel */
  9390. /* 0x00 - no channel */
  9391. /* else channel number / PRI: timeslot */
  9392. /* if channels is provided we accept more than one channel. */
  9393. /*------------------------------------------------------------------*/
  9394. static byte chi_to_channel(byte *chi, dword *pchannelmap)
  9395. {
  9396. int p;
  9397. int i;
  9398. dword map;
  9399. byte excl;
  9400. byte ofs;
  9401. byte ch;
  9402. if (pchannelmap) *pchannelmap = 0;
  9403. if (!chi[0]) return 0xff;
  9404. excl = 0;
  9405. if (chi[1] & 0x20) {
  9406. if (chi[0] == 1 && chi[1] == 0xac) return 0xfd; /* exclusive d-channel */
  9407. for (i = 1; i < chi[0] && !(chi[i] & 0x80); i++);
  9408. if (i == chi[0] || !(chi[i] & 0x80)) return 0xfe;
  9409. if ((chi[1] | 0xc8) != 0xe9) return 0xfe;
  9410. if (chi[1] & 0x08) excl = 0x40;
  9411. /* int. id present */
  9412. if (chi[1] & 0x40) {
  9413. p = i + 1;
  9414. for (i = p; i < chi[0] && !(chi[i] & 0x80); i++);
  9415. if (i == chi[0] || !(chi[i] & 0x80)) return 0xfe;
  9416. }
  9417. /* coding standard, Number/Map, Channel Type */
  9418. p = i + 1;
  9419. for (i = p; i < chi[0] && !(chi[i] & 0x80); i++);
  9420. if (i == chi[0] || !(chi[i] & 0x80)) return 0xfe;
  9421. if ((chi[p] | 0xd0) != 0xd3) return 0xfe;
  9422. /* Number/Map */
  9423. if (chi[p] & 0x10) {
  9424. /* map */
  9425. if ((chi[0] - p) == 4) ofs = 0;
  9426. else if ((chi[0] - p) == 3) ofs = 1;
  9427. else return 0xfe;
  9428. ch = 0;
  9429. map = 0;
  9430. for (i = 0; i < 4 && p < chi[0]; i++) {
  9431. p++;
  9432. ch += 8;
  9433. map <<= 8;
  9434. if (chi[p]) {
  9435. for (ch = 0; !(chi[p] & (1 << ch)); ch++);
  9436. map |= chi[p];
  9437. }
  9438. }
  9439. ch += ofs;
  9440. map <<= ofs;
  9441. }
  9442. else {
  9443. /* number */
  9444. p = i + 1;
  9445. ch = chi[p] & 0x3f;
  9446. if (pchannelmap) {
  9447. if ((byte)(chi[0] - p) > 30) return 0xfe;
  9448. map = 0;
  9449. for (i = p; i <= chi[0]; i++) {
  9450. if ((chi[i] & 0x7f) > 31) return 0xfe;
  9451. map |= (1L << (chi[i] & 0x7f));
  9452. }
  9453. }
  9454. else {
  9455. if (p != chi[0]) return 0xfe;
  9456. if (ch > 31) return 0xfe;
  9457. map = (1L << ch);
  9458. }
  9459. if (chi[p] & 0x40) return 0xfe;
  9460. }
  9461. if (pchannelmap) *pchannelmap = map;
  9462. else if (map != ((dword)(1L << ch))) return 0xfe;
  9463. return (byte)(excl | ch);
  9464. }
  9465. else { /* not PRI */
  9466. for (i = 1; i < chi[0] && !(chi[i] & 0x80); i++);
  9467. if (i != chi[0] || !(chi[i] & 0x80)) return 0xfe;
  9468. if (chi[1] & 0x08) excl = 0x40;
  9469. switch (chi[1] | 0x98) {
  9470. case 0x98: return 0;
  9471. case 0x99:
  9472. if (pchannelmap) *pchannelmap = 2;
  9473. return excl | 1;
  9474. case 0x9a:
  9475. if (pchannelmap) *pchannelmap = 4;
  9476. return excl | 2;
  9477. case 0x9b: return 0xff;
  9478. case 0x9c: return 0xfd; /* d-ch */
  9479. default: return 0xfe;
  9480. }
  9481. }
  9482. }
  9483. static void mixer_set_bchannel_id_esc(PLCI *plci, byte bchannel_id)
  9484. {
  9485. DIVA_CAPI_ADAPTER *a;
  9486. PLCI *splci;
  9487. byte old_id;
  9488. a = plci->adapter;
  9489. old_id = plci->li_bchannel_id;
  9490. if (a->li_pri)
  9491. {
  9492. if ((old_id != 0) && (li_config_table[a->li_base + (old_id - 1)].plci == plci))
  9493. li_config_table[a->li_base + (old_id - 1)].plci = NULL;
  9494. plci->li_bchannel_id = (bchannel_id & 0x1f) + 1;
  9495. if (li_config_table[a->li_base + (plci->li_bchannel_id - 1)].plci == NULL)
  9496. li_config_table[a->li_base + (plci->li_bchannel_id - 1)].plci = plci;
  9497. }
  9498. else
  9499. {
  9500. if (((bchannel_id & 0x03) == 1) || ((bchannel_id & 0x03) == 2))
  9501. {
  9502. if ((old_id != 0) && (li_config_table[a->li_base + (old_id - 1)].plci == plci))
  9503. li_config_table[a->li_base + (old_id - 1)].plci = NULL;
  9504. plci->li_bchannel_id = bchannel_id & 0x03;
  9505. if ((a->AdvSignalPLCI != NULL) && (a->AdvSignalPLCI != plci) && (a->AdvSignalPLCI->tel == ADV_VOICE))
  9506. {
  9507. splci = a->AdvSignalPLCI;
  9508. if (li_config_table[a->li_base + (2 - plci->li_bchannel_id)].plci == NULL)
  9509. {
  9510. if ((splci->li_bchannel_id != 0)
  9511. && (li_config_table[a->li_base + (splci->li_bchannel_id - 1)].plci == splci))
  9512. {
  9513. li_config_table[a->li_base + (splci->li_bchannel_id - 1)].plci = NULL;
  9514. }
  9515. splci->li_bchannel_id = 3 - plci->li_bchannel_id;
  9516. li_config_table[a->li_base + (2 - plci->li_bchannel_id)].plci = splci;
  9517. dbug(1, dprintf("[%06lx] %s,%d: adv_voice_set_bchannel_id_esc %d",
  9518. (dword)((splci->Id << 8) | UnMapController(splci->adapter->Id)),
  9519. (char *)(FILE_), __LINE__, splci->li_bchannel_id));
  9520. }
  9521. }
  9522. if (li_config_table[a->li_base + (plci->li_bchannel_id - 1)].plci == NULL)
  9523. li_config_table[a->li_base + (plci->li_bchannel_id - 1)].plci = plci;
  9524. }
  9525. }
  9526. if ((old_id == 0) && (plci->li_bchannel_id != 0)
  9527. && (li_config_table[a->li_base + (plci->li_bchannel_id - 1)].plci == plci))
  9528. {
  9529. mixer_clear_config(plci);
  9530. }
  9531. dbug(1, dprintf("[%06lx] %s,%d: mixer_set_bchannel_id_esc %d %d",
  9532. (dword)((plci->Id << 8) | UnMapController(plci->adapter->Id)),
  9533. (char *)(FILE_), __LINE__, bchannel_id, plci->li_bchannel_id));
  9534. }
  9535. static void mixer_set_bchannel_id(PLCI *plci, byte *chi)
  9536. {
  9537. DIVA_CAPI_ADAPTER *a;
  9538. PLCI *splci;
  9539. byte ch, old_id;
  9540. a = plci->adapter;
  9541. old_id = plci->li_bchannel_id;
  9542. ch = chi_to_channel(chi, NULL);
  9543. if (!(ch & 0x80))
  9544. {
  9545. if (a->li_pri)
  9546. {
  9547. if ((old_id != 0) && (li_config_table[a->li_base + (old_id - 1)].plci == plci))
  9548. li_config_table[a->li_base + (old_id - 1)].plci = NULL;
  9549. plci->li_bchannel_id = (ch & 0x1f) + 1;
  9550. if (li_config_table[a->li_base + (plci->li_bchannel_id - 1)].plci == NULL)
  9551. li_config_table[a->li_base + (plci->li_bchannel_id - 1)].plci = plci;
  9552. }
  9553. else
  9554. {
  9555. if (((ch & 0x1f) == 1) || ((ch & 0x1f) == 2))
  9556. {
  9557. if ((old_id != 0) && (li_config_table[a->li_base + (old_id - 1)].plci == plci))
  9558. li_config_table[a->li_base + (old_id - 1)].plci = NULL;
  9559. plci->li_bchannel_id = ch & 0x1f;
  9560. if ((a->AdvSignalPLCI != NULL) && (a->AdvSignalPLCI != plci) && (a->AdvSignalPLCI->tel == ADV_VOICE))
  9561. {
  9562. splci = a->AdvSignalPLCI;
  9563. if (li_config_table[a->li_base + (2 - plci->li_bchannel_id)].plci == NULL)
  9564. {
  9565. if ((splci->li_bchannel_id != 0)
  9566. && (li_config_table[a->li_base + (splci->li_bchannel_id - 1)].plci == splci))
  9567. {
  9568. li_config_table[a->li_base + (splci->li_bchannel_id - 1)].plci = NULL;
  9569. }
  9570. splci->li_bchannel_id = 3 - plci->li_bchannel_id;
  9571. li_config_table[a->li_base + (2 - plci->li_bchannel_id)].plci = splci;
  9572. dbug(1, dprintf("[%06lx] %s,%d: adv_voice_set_bchannel_id %d",
  9573. (dword)((splci->Id << 8) | UnMapController(splci->adapter->Id)),
  9574. (char *)(FILE_), __LINE__, splci->li_bchannel_id));
  9575. }
  9576. }
  9577. if (li_config_table[a->li_base + (plci->li_bchannel_id - 1)].plci == NULL)
  9578. li_config_table[a->li_base + (plci->li_bchannel_id - 1)].plci = plci;
  9579. }
  9580. }
  9581. }
  9582. if ((old_id == 0) && (plci->li_bchannel_id != 0)
  9583. && (li_config_table[a->li_base + (plci->li_bchannel_id - 1)].plci == plci))
  9584. {
  9585. mixer_clear_config(plci);
  9586. }
  9587. dbug(1, dprintf("[%06lx] %s,%d: mixer_set_bchannel_id %02x %d",
  9588. (dword)((plci->Id << 8) | UnMapController(plci->adapter->Id)),
  9589. (char *)(FILE_), __LINE__, ch, plci->li_bchannel_id));
  9590. }
  9591. #define MIXER_MAX_DUMP_CHANNELS 34
  9592. static void mixer_calculate_coefs(DIVA_CAPI_ADAPTER *a)
  9593. {
  9594. word n, i, j;
  9595. char *p;
  9596. char hex_line[2 * MIXER_MAX_DUMP_CHANNELS + MIXER_MAX_DUMP_CHANNELS / 8 + 4];
  9597. dbug(1, dprintf("[%06lx] %s,%d: mixer_calculate_coefs",
  9598. (dword)(UnMapController(a->Id)), (char *)(FILE_), __LINE__));
  9599. for (i = 0; i < li_total_channels; i++)
  9600. {
  9601. li_config_table[i].channel &= LI_CHANNEL_ADDRESSES_SET;
  9602. if (li_config_table[i].chflags != 0)
  9603. li_config_table[i].channel |= LI_CHANNEL_INVOLVED;
  9604. else
  9605. {
  9606. for (j = 0; j < li_total_channels; j++)
  9607. {
  9608. if (((li_config_table[i].flag_table[j]) != 0)
  9609. || ((li_config_table[j].flag_table[i]) != 0))
  9610. {
  9611. li_config_table[i].channel |= LI_CHANNEL_INVOLVED;
  9612. }
  9613. if (((li_config_table[i].flag_table[j] & LI_FLAG_CONFERENCE) != 0)
  9614. || ((li_config_table[j].flag_table[i] & LI_FLAG_CONFERENCE) != 0))
  9615. {
  9616. li_config_table[i].channel |= LI_CHANNEL_CONFERENCE;
  9617. }
  9618. }
  9619. }
  9620. }
  9621. for (i = 0; i < li_total_channels; i++)
  9622. {
  9623. for (j = 0; j < li_total_channels; j++)
  9624. {
  9625. li_config_table[i].coef_table[j] &= ~(LI_COEF_CH_CH | LI_COEF_CH_PC | LI_COEF_PC_CH | LI_COEF_PC_PC);
  9626. if (li_config_table[i].flag_table[j] & LI_FLAG_CONFERENCE)
  9627. li_config_table[i].coef_table[j] |= LI_COEF_CH_CH;
  9628. }
  9629. }
  9630. for (n = 0; n < li_total_channels; n++)
  9631. {
  9632. if (li_config_table[n].channel & LI_CHANNEL_CONFERENCE)
  9633. {
  9634. for (i = 0; i < li_total_channels; i++)
  9635. {
  9636. if (li_config_table[i].channel & LI_CHANNEL_CONFERENCE)
  9637. {
  9638. for (j = 0; j < li_total_channels; j++)
  9639. {
  9640. li_config_table[i].coef_table[j] |=
  9641. li_config_table[i].coef_table[n] & li_config_table[n].coef_table[j];
  9642. }
  9643. }
  9644. }
  9645. }
  9646. }
  9647. for (i = 0; i < li_total_channels; i++)
  9648. {
  9649. if (li_config_table[i].channel & LI_CHANNEL_INVOLVED)
  9650. {
  9651. li_config_table[i].coef_table[i] &= ~LI_COEF_CH_CH;
  9652. for (j = 0; j < li_total_channels; j++)
  9653. {
  9654. if (li_config_table[i].coef_table[j] & LI_COEF_CH_CH)
  9655. li_config_table[i].flag_table[j] |= LI_FLAG_CONFERENCE;
  9656. }
  9657. if (li_config_table[i].flag_table[i] & LI_FLAG_CONFERENCE)
  9658. li_config_table[i].coef_table[i] |= LI_COEF_CH_CH;
  9659. }
  9660. }
  9661. for (i = 0; i < li_total_channels; i++)
  9662. {
  9663. if (li_config_table[i].channel & LI_CHANNEL_INVOLVED)
  9664. {
  9665. for (j = 0; j < li_total_channels; j++)
  9666. {
  9667. if (li_config_table[i].flag_table[j] & LI_FLAG_INTERCONNECT)
  9668. li_config_table[i].coef_table[j] |= LI_COEF_CH_CH;
  9669. if (li_config_table[i].flag_table[j] & LI_FLAG_MONITOR)
  9670. li_config_table[i].coef_table[j] |= LI_COEF_CH_PC;
  9671. if (li_config_table[i].flag_table[j] & LI_FLAG_MIX)
  9672. li_config_table[i].coef_table[j] |= LI_COEF_PC_CH;
  9673. if (li_config_table[i].flag_table[j] & LI_FLAG_PCCONNECT)
  9674. li_config_table[i].coef_table[j] |= LI_COEF_PC_PC;
  9675. }
  9676. if (li_config_table[i].chflags & LI_CHFLAG_MONITOR)
  9677. {
  9678. for (j = 0; j < li_total_channels; j++)
  9679. {
  9680. if (li_config_table[i].flag_table[j] & LI_FLAG_INTERCONNECT)
  9681. {
  9682. li_config_table[i].coef_table[j] |= LI_COEF_CH_PC;
  9683. if (li_config_table[j].chflags & LI_CHFLAG_MIX)
  9684. li_config_table[i].coef_table[j] |= LI_COEF_PC_CH | LI_COEF_PC_PC;
  9685. }
  9686. }
  9687. }
  9688. if (li_config_table[i].chflags & LI_CHFLAG_MIX)
  9689. {
  9690. for (j = 0; j < li_total_channels; j++)
  9691. {
  9692. if (li_config_table[j].flag_table[i] & LI_FLAG_INTERCONNECT)
  9693. li_config_table[j].coef_table[i] |= LI_COEF_PC_CH;
  9694. }
  9695. }
  9696. if (li_config_table[i].chflags & LI_CHFLAG_LOOP)
  9697. {
  9698. for (j = 0; j < li_total_channels; j++)
  9699. {
  9700. if (li_config_table[i].flag_table[j] & LI_FLAG_INTERCONNECT)
  9701. {
  9702. for (n = 0; n < li_total_channels; n++)
  9703. {
  9704. if (li_config_table[n].flag_table[i] & LI_FLAG_INTERCONNECT)
  9705. {
  9706. li_config_table[n].coef_table[j] |= LI_COEF_CH_CH;
  9707. if (li_config_table[j].chflags & LI_CHFLAG_MIX)
  9708. {
  9709. li_config_table[n].coef_table[j] |= LI_COEF_PC_CH;
  9710. if (li_config_table[n].chflags & LI_CHFLAG_MONITOR)
  9711. li_config_table[n].coef_table[j] |= LI_COEF_CH_PC | LI_COEF_PC_PC;
  9712. }
  9713. else if (li_config_table[n].chflags & LI_CHFLAG_MONITOR)
  9714. li_config_table[n].coef_table[j] |= LI_COEF_CH_PC;
  9715. }
  9716. }
  9717. }
  9718. }
  9719. }
  9720. }
  9721. }
  9722. for (i = 0; i < li_total_channels; i++)
  9723. {
  9724. if (li_config_table[i].channel & LI_CHANNEL_INVOLVED)
  9725. {
  9726. if (li_config_table[i].chflags & (LI_CHFLAG_MONITOR | LI_CHFLAG_MIX | LI_CHFLAG_LOOP))
  9727. li_config_table[i].channel |= LI_CHANNEL_ACTIVE;
  9728. if (li_config_table[i].chflags & LI_CHFLAG_MONITOR)
  9729. li_config_table[i].channel |= LI_CHANNEL_RX_DATA;
  9730. if (li_config_table[i].chflags & LI_CHFLAG_MIX)
  9731. li_config_table[i].channel |= LI_CHANNEL_TX_DATA;
  9732. for (j = 0; j < li_total_channels; j++)
  9733. {
  9734. if ((li_config_table[i].flag_table[j] &
  9735. (LI_FLAG_INTERCONNECT | LI_FLAG_PCCONNECT | LI_FLAG_CONFERENCE | LI_FLAG_MONITOR))
  9736. || (li_config_table[j].flag_table[i] &
  9737. (LI_FLAG_INTERCONNECT | LI_FLAG_PCCONNECT | LI_FLAG_CONFERENCE | LI_FLAG_ANNOUNCEMENT | LI_FLAG_MIX)))
  9738. {
  9739. li_config_table[i].channel |= LI_CHANNEL_ACTIVE;
  9740. }
  9741. if (li_config_table[i].flag_table[j] & (LI_FLAG_PCCONNECT | LI_FLAG_MONITOR))
  9742. li_config_table[i].channel |= LI_CHANNEL_RX_DATA;
  9743. if (li_config_table[j].flag_table[i] & (LI_FLAG_PCCONNECT | LI_FLAG_ANNOUNCEMENT | LI_FLAG_MIX))
  9744. li_config_table[i].channel |= LI_CHANNEL_TX_DATA;
  9745. }
  9746. if (!(li_config_table[i].channel & LI_CHANNEL_ACTIVE))
  9747. {
  9748. li_config_table[i].coef_table[i] |= LI_COEF_PC_CH | LI_COEF_CH_PC;
  9749. li_config_table[i].channel |= LI_CHANNEL_TX_DATA | LI_CHANNEL_RX_DATA;
  9750. }
  9751. }
  9752. }
  9753. for (i = 0; i < li_total_channels; i++)
  9754. {
  9755. if (li_config_table[i].channel & LI_CHANNEL_INVOLVED)
  9756. {
  9757. j = 0;
  9758. while ((j < li_total_channels) && !(li_config_table[i].flag_table[j] & LI_FLAG_ANNOUNCEMENT))
  9759. j++;
  9760. if (j < li_total_channels)
  9761. {
  9762. for (j = 0; j < li_total_channels; j++)
  9763. {
  9764. li_config_table[i].coef_table[j] &= ~(LI_COEF_CH_CH | LI_COEF_PC_CH);
  9765. if (li_config_table[i].flag_table[j] & LI_FLAG_ANNOUNCEMENT)
  9766. li_config_table[i].coef_table[j] |= LI_COEF_PC_CH;
  9767. }
  9768. }
  9769. }
  9770. }
  9771. n = li_total_channels;
  9772. if (n > MIXER_MAX_DUMP_CHANNELS)
  9773. n = MIXER_MAX_DUMP_CHANNELS;
  9774. p = hex_line;
  9775. for (j = 0; j < n; j++)
  9776. {
  9777. if ((j & 0x7) == 0)
  9778. *(p++) = ' ';
  9779. p = hex_byte_pack(p, li_config_table[j].curchnl);
  9780. }
  9781. *p = '\0';
  9782. dbug(1, dprintf("[%06lx] CURRENT %s",
  9783. (dword)(UnMapController(a->Id)), (char *)hex_line));
  9784. p = hex_line;
  9785. for (j = 0; j < n; j++)
  9786. {
  9787. if ((j & 0x7) == 0)
  9788. *(p++) = ' ';
  9789. p = hex_byte_pack(p, li_config_table[j].channel);
  9790. }
  9791. *p = '\0';
  9792. dbug(1, dprintf("[%06lx] CHANNEL %s",
  9793. (dword)(UnMapController(a->Id)), (char *)hex_line));
  9794. p = hex_line;
  9795. for (j = 0; j < n; j++)
  9796. {
  9797. if ((j & 0x7) == 0)
  9798. *(p++) = ' ';
  9799. p = hex_byte_pack(p, li_config_table[j].chflags);
  9800. }
  9801. *p = '\0';
  9802. dbug(1, dprintf("[%06lx] CHFLAG %s",
  9803. (dword)(UnMapController(a->Id)), (char *)hex_line));
  9804. for (i = 0; i < n; i++)
  9805. {
  9806. p = hex_line;
  9807. for (j = 0; j < n; j++)
  9808. {
  9809. if ((j & 0x7) == 0)
  9810. *(p++) = ' ';
  9811. p = hex_byte_pack(p, li_config_table[i].flag_table[j]);
  9812. }
  9813. *p = '\0';
  9814. dbug(1, dprintf("[%06lx] FLAG[%02x]%s",
  9815. (dword)(UnMapController(a->Id)), i, (char *)hex_line));
  9816. }
  9817. for (i = 0; i < n; i++)
  9818. {
  9819. p = hex_line;
  9820. for (j = 0; j < n; j++)
  9821. {
  9822. if ((j & 0x7) == 0)
  9823. *(p++) = ' ';
  9824. p = hex_byte_pack(p, li_config_table[i].coef_table[j]);
  9825. }
  9826. *p = '\0';
  9827. dbug(1, dprintf("[%06lx] COEF[%02x]%s",
  9828. (dword)(UnMapController(a->Id)), i, (char *)hex_line));
  9829. }
  9830. }
  9831. static struct
  9832. {
  9833. byte mask;
  9834. byte line_flags;
  9835. } mixer_write_prog_pri[] =
  9836. {
  9837. { LI_COEF_CH_CH, 0 },
  9838. { LI_COEF_CH_PC, MIXER_COEF_LINE_TO_PC_FLAG },
  9839. { LI_COEF_PC_CH, MIXER_COEF_LINE_FROM_PC_FLAG },
  9840. { LI_COEF_PC_PC, MIXER_COEF_LINE_TO_PC_FLAG | MIXER_COEF_LINE_FROM_PC_FLAG }
  9841. };
  9842. static struct
  9843. {
  9844. byte from_ch;
  9845. byte to_ch;
  9846. byte mask;
  9847. byte xconnect_override;
  9848. } mixer_write_prog_bri[] =
  9849. {
  9850. { 0, 0, LI_COEF_CH_CH, 0x01 }, /* B to B */
  9851. { 1, 0, LI_COEF_CH_CH, 0x01 }, /* Alt B to B */
  9852. { 0, 0, LI_COEF_PC_CH, 0x80 }, /* PC to B */
  9853. { 1, 0, LI_COEF_PC_CH, 0x01 }, /* Alt PC to B */
  9854. { 2, 0, LI_COEF_CH_CH, 0x00 }, /* IC to B */
  9855. { 3, 0, LI_COEF_CH_CH, 0x00 }, /* Alt IC to B */
  9856. { 0, 0, LI_COEF_CH_PC, 0x80 }, /* B to PC */
  9857. { 1, 0, LI_COEF_CH_PC, 0x01 }, /* Alt B to PC */
  9858. { 0, 0, LI_COEF_PC_PC, 0x01 }, /* PC to PC */
  9859. { 1, 0, LI_COEF_PC_PC, 0x01 }, /* Alt PC to PC */
  9860. { 2, 0, LI_COEF_CH_PC, 0x00 }, /* IC to PC */
  9861. { 3, 0, LI_COEF_CH_PC, 0x00 }, /* Alt IC to PC */
  9862. { 0, 2, LI_COEF_CH_CH, 0x00 }, /* B to IC */
  9863. { 1, 2, LI_COEF_CH_CH, 0x00 }, /* Alt B to IC */
  9864. { 0, 2, LI_COEF_PC_CH, 0x00 }, /* PC to IC */
  9865. { 1, 2, LI_COEF_PC_CH, 0x00 }, /* Alt PC to IC */
  9866. { 2, 2, LI_COEF_CH_CH, 0x00 }, /* IC to IC */
  9867. { 3, 2, LI_COEF_CH_CH, 0x00 }, /* Alt IC to IC */
  9868. { 1, 1, LI_COEF_CH_CH, 0x01 }, /* Alt B to Alt B */
  9869. { 0, 1, LI_COEF_CH_CH, 0x01 }, /* B to Alt B */
  9870. { 1, 1, LI_COEF_PC_CH, 0x80 }, /* Alt PC to Alt B */
  9871. { 0, 1, LI_COEF_PC_CH, 0x01 }, /* PC to Alt B */
  9872. { 3, 1, LI_COEF_CH_CH, 0x00 }, /* Alt IC to Alt B */
  9873. { 2, 1, LI_COEF_CH_CH, 0x00 }, /* IC to Alt B */
  9874. { 1, 1, LI_COEF_CH_PC, 0x80 }, /* Alt B to Alt PC */
  9875. { 0, 1, LI_COEF_CH_PC, 0x01 }, /* B to Alt PC */
  9876. { 1, 1, LI_COEF_PC_PC, 0x01 }, /* Alt PC to Alt PC */
  9877. { 0, 1, LI_COEF_PC_PC, 0x01 }, /* PC to Alt PC */
  9878. { 3, 1, LI_COEF_CH_PC, 0x00 }, /* Alt IC to Alt PC */
  9879. { 2, 1, LI_COEF_CH_PC, 0x00 }, /* IC to Alt PC */
  9880. { 1, 3, LI_COEF_CH_CH, 0x00 }, /* Alt B to Alt IC */
  9881. { 0, 3, LI_COEF_CH_CH, 0x00 }, /* B to Alt IC */
  9882. { 1, 3, LI_COEF_PC_CH, 0x00 }, /* Alt PC to Alt IC */
  9883. { 0, 3, LI_COEF_PC_CH, 0x00 }, /* PC to Alt IC */
  9884. { 3, 3, LI_COEF_CH_CH, 0x00 }, /* Alt IC to Alt IC */
  9885. { 2, 3, LI_COEF_CH_CH, 0x00 } /* IC to Alt IC */
  9886. };
  9887. static byte mixer_swapped_index_bri[] =
  9888. {
  9889. 18, /* B to B */
  9890. 19, /* Alt B to B */
  9891. 20, /* PC to B */
  9892. 21, /* Alt PC to B */
  9893. 22, /* IC to B */
  9894. 23, /* Alt IC to B */
  9895. 24, /* B to PC */
  9896. 25, /* Alt B to PC */
  9897. 26, /* PC to PC */
  9898. 27, /* Alt PC to PC */
  9899. 28, /* IC to PC */
  9900. 29, /* Alt IC to PC */
  9901. 30, /* B to IC */
  9902. 31, /* Alt B to IC */
  9903. 32, /* PC to IC */
  9904. 33, /* Alt PC to IC */
  9905. 34, /* IC to IC */
  9906. 35, /* Alt IC to IC */
  9907. 0, /* Alt B to Alt B */
  9908. 1, /* B to Alt B */
  9909. 2, /* Alt PC to Alt B */
  9910. 3, /* PC to Alt B */
  9911. 4, /* Alt IC to Alt B */
  9912. 5, /* IC to Alt B */
  9913. 6, /* Alt B to Alt PC */
  9914. 7, /* B to Alt PC */
  9915. 8, /* Alt PC to Alt PC */
  9916. 9, /* PC to Alt PC */
  9917. 10, /* Alt IC to Alt PC */
  9918. 11, /* IC to Alt PC */
  9919. 12, /* Alt B to Alt IC */
  9920. 13, /* B to Alt IC */
  9921. 14, /* Alt PC to Alt IC */
  9922. 15, /* PC to Alt IC */
  9923. 16, /* Alt IC to Alt IC */
  9924. 17 /* IC to Alt IC */
  9925. };
  9926. static struct
  9927. {
  9928. byte mask;
  9929. byte from_pc;
  9930. byte to_pc;
  9931. } xconnect_write_prog[] =
  9932. {
  9933. { LI_COEF_CH_CH, false, false },
  9934. { LI_COEF_CH_PC, false, true },
  9935. { LI_COEF_PC_CH, true, false },
  9936. { LI_COEF_PC_PC, true, true }
  9937. };
  9938. static void xconnect_query_addresses(PLCI *plci)
  9939. {
  9940. DIVA_CAPI_ADAPTER *a;
  9941. word w, ch;
  9942. byte *p;
  9943. dbug(1, dprintf("[%06lx] %s,%d: xconnect_query_addresses",
  9944. (dword)((plci->Id << 8) | UnMapController(plci->adapter->Id)),
  9945. (char *)(FILE_), __LINE__));
  9946. a = plci->adapter;
  9947. if (a->li_pri && ((plci->li_bchannel_id == 0)
  9948. || (li_config_table[a->li_base + (plci->li_bchannel_id - 1)].plci != plci)))
  9949. {
  9950. dbug(1, dprintf("[%06x] %s,%d: Channel id wiped out",
  9951. (dword)((plci->Id << 8) | UnMapController(plci->adapter->Id)),
  9952. (char *)(FILE_), __LINE__));
  9953. return;
  9954. }
  9955. p = plci->internal_req_buffer;
  9956. ch = (a->li_pri) ? plci->li_bchannel_id - 1 : 0;
  9957. *(p++) = UDATA_REQUEST_XCONNECT_FROM;
  9958. w = ch;
  9959. *(p++) = (byte) w;
  9960. *(p++) = (byte)(w >> 8);
  9961. w = ch | XCONNECT_CHANNEL_PORT_PC;
  9962. *(p++) = (byte) w;
  9963. *(p++) = (byte)(w >> 8);
  9964. plci->NData[0].P = plci->internal_req_buffer;
  9965. plci->NData[0].PLength = p - plci->internal_req_buffer;
  9966. plci->NL.X = plci->NData;
  9967. plci->NL.ReqCh = 0;
  9968. plci->NL.Req = plci->nl_req = (byte) N_UDATA;
  9969. plci->adapter->request(&plci->NL);
  9970. }
  9971. static void xconnect_write_coefs(PLCI *plci, word internal_command)
  9972. {
  9973. dbug(1, dprintf("[%06lx] %s,%d: xconnect_write_coefs %04x",
  9974. (dword)((plci->Id << 8) | UnMapController(plci->adapter->Id)),
  9975. (char *)(FILE_), __LINE__, internal_command));
  9976. plci->li_write_command = internal_command;
  9977. plci->li_write_channel = 0;
  9978. }
  9979. static byte xconnect_write_coefs_process(dword Id, PLCI *plci, byte Rc)
  9980. {
  9981. DIVA_CAPI_ADAPTER *a;
  9982. word w, n, i, j, r, s, to_ch;
  9983. dword d;
  9984. byte *p;
  9985. struct xconnect_transfer_address_s *transfer_address;
  9986. byte ch_map[MIXER_CHANNELS_BRI];
  9987. dbug(1, dprintf("[%06x] %s,%d: xconnect_write_coefs_process %02x %d",
  9988. UnMapId(Id), (char *)(FILE_), __LINE__, Rc, plci->li_write_channel));
  9989. a = plci->adapter;
  9990. if ((plci->li_bchannel_id == 0)
  9991. || (li_config_table[a->li_base + (plci->li_bchannel_id - 1)].plci != plci))
  9992. {
  9993. dbug(1, dprintf("[%06x] %s,%d: Channel id wiped out",
  9994. UnMapId(Id), (char *)(FILE_), __LINE__));
  9995. return (true);
  9996. }
  9997. i = a->li_base + (plci->li_bchannel_id - 1);
  9998. j = plci->li_write_channel;
  9999. p = plci->internal_req_buffer;
  10000. if (j != 0)
  10001. {
  10002. if ((Rc != OK) && (Rc != OK_FC))
  10003. {
  10004. dbug(1, dprintf("[%06lx] %s,%d: LI write coefs failed %02x",
  10005. UnMapId(Id), (char *)(FILE_), __LINE__, Rc));
  10006. return (false);
  10007. }
  10008. }
  10009. if (li_config_table[i].adapter->manufacturer_features & MANUFACTURER_FEATURE_XCONNECT)
  10010. {
  10011. r = 0;
  10012. s = 0;
  10013. if (j < li_total_channels)
  10014. {
  10015. if (li_config_table[i].channel & LI_CHANNEL_ADDRESSES_SET)
  10016. {
  10017. s = ((li_config_table[i].send_b.card_address.low | li_config_table[i].send_b.card_address.high) ?
  10018. (LI_COEF_CH_CH | LI_COEF_CH_PC | LI_COEF_PC_CH | LI_COEF_PC_PC) : (LI_COEF_CH_PC | LI_COEF_PC_PC)) &
  10019. ((li_config_table[i].send_pc.card_address.low | li_config_table[i].send_pc.card_address.high) ?
  10020. (LI_COEF_CH_CH | LI_COEF_CH_PC | LI_COEF_PC_CH | LI_COEF_PC_PC) : (LI_COEF_CH_CH | LI_COEF_PC_CH));
  10021. }
  10022. r = ((li_config_table[i].coef_table[j] & 0xf) ^ (li_config_table[i].coef_table[j] >> 4));
  10023. while ((j < li_total_channels)
  10024. && ((r == 0)
  10025. || (!(li_config_table[j].channel & LI_CHANNEL_ADDRESSES_SET))
  10026. || (!li_config_table[j].adapter->li_pri
  10027. && (j >= li_config_table[j].adapter->li_base + MIXER_BCHANNELS_BRI))
  10028. || (((li_config_table[j].send_b.card_address.low != li_config_table[i].send_b.card_address.low)
  10029. || (li_config_table[j].send_b.card_address.high != li_config_table[i].send_b.card_address.high))
  10030. && (!(a->manufacturer_features & MANUFACTURER_FEATURE_DMACONNECT)
  10031. || !(li_config_table[j].adapter->manufacturer_features & MANUFACTURER_FEATURE_DMACONNECT)))
  10032. || ((li_config_table[j].adapter->li_base != a->li_base)
  10033. && !(r & s &
  10034. ((li_config_table[j].send_b.card_address.low | li_config_table[j].send_b.card_address.high) ?
  10035. (LI_COEF_CH_CH | LI_COEF_CH_PC | LI_COEF_PC_CH | LI_COEF_PC_PC) : (LI_COEF_PC_CH | LI_COEF_PC_PC)) &
  10036. ((li_config_table[j].send_pc.card_address.low | li_config_table[j].send_pc.card_address.high) ?
  10037. (LI_COEF_CH_CH | LI_COEF_CH_PC | LI_COEF_PC_CH | LI_COEF_PC_PC) : (LI_COEF_CH_CH | LI_COEF_CH_PC))))))
  10038. {
  10039. j++;
  10040. if (j < li_total_channels)
  10041. r = ((li_config_table[i].coef_table[j] & 0xf) ^ (li_config_table[i].coef_table[j] >> 4));
  10042. }
  10043. }
  10044. if (j < li_total_channels)
  10045. {
  10046. plci->internal_command = plci->li_write_command;
  10047. if (plci_nl_busy(plci))
  10048. return (true);
  10049. to_ch = (a->li_pri) ? plci->li_bchannel_id - 1 : 0;
  10050. *(p++) = UDATA_REQUEST_XCONNECT_TO;
  10051. do
  10052. {
  10053. if (li_config_table[j].adapter->li_base != a->li_base)
  10054. {
  10055. r &= s &
  10056. ((li_config_table[j].send_b.card_address.low | li_config_table[j].send_b.card_address.high) ?
  10057. (LI_COEF_CH_CH | LI_COEF_CH_PC | LI_COEF_PC_CH | LI_COEF_PC_PC) : (LI_COEF_PC_CH | LI_COEF_PC_PC)) &
  10058. ((li_config_table[j].send_pc.card_address.low | li_config_table[j].send_pc.card_address.high) ?
  10059. (LI_COEF_CH_CH | LI_COEF_CH_PC | LI_COEF_PC_CH | LI_COEF_PC_PC) : (LI_COEF_CH_CH | LI_COEF_CH_PC));
  10060. }
  10061. n = 0;
  10062. do
  10063. {
  10064. if (r & xconnect_write_prog[n].mask)
  10065. {
  10066. if (xconnect_write_prog[n].from_pc)
  10067. transfer_address = &(li_config_table[j].send_pc);
  10068. else
  10069. transfer_address = &(li_config_table[j].send_b);
  10070. d = transfer_address->card_address.low;
  10071. *(p++) = (byte) d;
  10072. *(p++) = (byte)(d >> 8);
  10073. *(p++) = (byte)(d >> 16);
  10074. *(p++) = (byte)(d >> 24);
  10075. d = transfer_address->card_address.high;
  10076. *(p++) = (byte) d;
  10077. *(p++) = (byte)(d >> 8);
  10078. *(p++) = (byte)(d >> 16);
  10079. *(p++) = (byte)(d >> 24);
  10080. d = transfer_address->offset;
  10081. *(p++) = (byte) d;
  10082. *(p++) = (byte)(d >> 8);
  10083. *(p++) = (byte)(d >> 16);
  10084. *(p++) = (byte)(d >> 24);
  10085. w = xconnect_write_prog[n].to_pc ? to_ch | XCONNECT_CHANNEL_PORT_PC : to_ch;
  10086. *(p++) = (byte) w;
  10087. *(p++) = (byte)(w >> 8);
  10088. w = ((li_config_table[i].coef_table[j] & xconnect_write_prog[n].mask) == 0) ? 0x01 :
  10089. (li_config_table[i].adapter->u_law ?
  10090. (li_config_table[j].adapter->u_law ? 0x80 : 0x86) :
  10091. (li_config_table[j].adapter->u_law ? 0x7a : 0x80));
  10092. *(p++) = (byte) w;
  10093. *(p++) = (byte) 0;
  10094. li_config_table[i].coef_table[j] ^= xconnect_write_prog[n].mask << 4;
  10095. }
  10096. n++;
  10097. } while ((n < ARRAY_SIZE(xconnect_write_prog))
  10098. && ((p - plci->internal_req_buffer) + 16 < INTERNAL_REQ_BUFFER_SIZE));
  10099. if (n == ARRAY_SIZE(xconnect_write_prog))
  10100. {
  10101. do
  10102. {
  10103. j++;
  10104. if (j < li_total_channels)
  10105. r = ((li_config_table[i].coef_table[j] & 0xf) ^ (li_config_table[i].coef_table[j] >> 4));
  10106. } while ((j < li_total_channels)
  10107. && ((r == 0)
  10108. || (!(li_config_table[j].channel & LI_CHANNEL_ADDRESSES_SET))
  10109. || (!li_config_table[j].adapter->li_pri
  10110. && (j >= li_config_table[j].adapter->li_base + MIXER_BCHANNELS_BRI))
  10111. || (((li_config_table[j].send_b.card_address.low != li_config_table[i].send_b.card_address.low)
  10112. || (li_config_table[j].send_b.card_address.high != li_config_table[i].send_b.card_address.high))
  10113. && (!(a->manufacturer_features & MANUFACTURER_FEATURE_DMACONNECT)
  10114. || !(li_config_table[j].adapter->manufacturer_features & MANUFACTURER_FEATURE_DMACONNECT)))
  10115. || ((li_config_table[j].adapter->li_base != a->li_base)
  10116. && !(r & s &
  10117. ((li_config_table[j].send_b.card_address.low | li_config_table[j].send_b.card_address.high) ?
  10118. (LI_COEF_CH_CH | LI_COEF_CH_PC | LI_COEF_PC_CH | LI_COEF_PC_PC) : (LI_COEF_PC_CH | LI_COEF_PC_PC)) &
  10119. ((li_config_table[j].send_pc.card_address.low | li_config_table[j].send_pc.card_address.high) ?
  10120. (LI_COEF_CH_CH | LI_COEF_CH_PC | LI_COEF_PC_CH | LI_COEF_PC_PC) : (LI_COEF_CH_CH | LI_COEF_CH_PC))))));
  10121. }
  10122. } while ((j < li_total_channels)
  10123. && ((p - plci->internal_req_buffer) + 16 < INTERNAL_REQ_BUFFER_SIZE));
  10124. }
  10125. else if (j == li_total_channels)
  10126. {
  10127. plci->internal_command = plci->li_write_command;
  10128. if (plci_nl_busy(plci))
  10129. return (true);
  10130. if (a->li_pri)
  10131. {
  10132. *(p++) = UDATA_REQUEST_SET_MIXER_COEFS_PRI_SYNC;
  10133. w = 0;
  10134. if (li_config_table[i].channel & LI_CHANNEL_TX_DATA)
  10135. w |= MIXER_FEATURE_ENABLE_TX_DATA;
  10136. if (li_config_table[i].channel & LI_CHANNEL_RX_DATA)
  10137. w |= MIXER_FEATURE_ENABLE_RX_DATA;
  10138. *(p++) = (byte) w;
  10139. *(p++) = (byte)(w >> 8);
  10140. }
  10141. else
  10142. {
  10143. *(p++) = UDATA_REQUEST_SET_MIXER_COEFS_BRI;
  10144. w = 0;
  10145. if ((plci->tel == ADV_VOICE) && (plci == a->AdvSignalPLCI)
  10146. && (ADV_VOICE_NEW_COEF_BASE + sizeof(word) <= a->adv_voice_coef_length))
  10147. {
  10148. w = GET_WORD(a->adv_voice_coef_buffer + ADV_VOICE_NEW_COEF_BASE);
  10149. }
  10150. if (li_config_table[i].channel & LI_CHANNEL_TX_DATA)
  10151. w |= MIXER_FEATURE_ENABLE_TX_DATA;
  10152. if (li_config_table[i].channel & LI_CHANNEL_RX_DATA)
  10153. w |= MIXER_FEATURE_ENABLE_RX_DATA;
  10154. *(p++) = (byte) w;
  10155. *(p++) = (byte)(w >> 8);
  10156. for (j = 0; j < sizeof(ch_map); j += 2)
  10157. {
  10158. if (plci->li_bchannel_id == 2)
  10159. {
  10160. ch_map[j] = (byte)(j + 1);
  10161. ch_map[j + 1] = (byte) j;
  10162. }
  10163. else
  10164. {
  10165. ch_map[j] = (byte) j;
  10166. ch_map[j + 1] = (byte)(j + 1);
  10167. }
  10168. }
  10169. for (n = 0; n < ARRAY_SIZE(mixer_write_prog_bri); n++)
  10170. {
  10171. i = a->li_base + ch_map[mixer_write_prog_bri[n].to_ch];
  10172. j = a->li_base + ch_map[mixer_write_prog_bri[n].from_ch];
  10173. if (li_config_table[i].channel & li_config_table[j].channel & LI_CHANNEL_INVOLVED)
  10174. {
  10175. *p = (mixer_write_prog_bri[n].xconnect_override != 0) ?
  10176. mixer_write_prog_bri[n].xconnect_override :
  10177. ((li_config_table[i].coef_table[j] & mixer_write_prog_bri[n].mask) ? 0x80 : 0x01);
  10178. if ((i >= a->li_base + MIXER_BCHANNELS_BRI) || (j >= a->li_base + MIXER_BCHANNELS_BRI))
  10179. {
  10180. w = ((li_config_table[i].coef_table[j] & 0xf) ^ (li_config_table[i].coef_table[j] >> 4));
  10181. li_config_table[i].coef_table[j] ^= (w & mixer_write_prog_bri[n].mask) << 4;
  10182. }
  10183. }
  10184. else
  10185. {
  10186. *p = 0x00;
  10187. if ((a->AdvSignalPLCI != NULL) && (a->AdvSignalPLCI->tel == ADV_VOICE))
  10188. {
  10189. w = (plci == a->AdvSignalPLCI) ? n : mixer_swapped_index_bri[n];
  10190. if (ADV_VOICE_NEW_COEF_BASE + sizeof(word) + w < a->adv_voice_coef_length)
  10191. *p = a->adv_voice_coef_buffer[ADV_VOICE_NEW_COEF_BASE + sizeof(word) + w];
  10192. }
  10193. }
  10194. p++;
  10195. }
  10196. }
  10197. j = li_total_channels + 1;
  10198. }
  10199. }
  10200. else
  10201. {
  10202. if (j <= li_total_channels)
  10203. {
  10204. plci->internal_command = plci->li_write_command;
  10205. if (plci_nl_busy(plci))
  10206. return (true);
  10207. if (j < a->li_base)
  10208. j = a->li_base;
  10209. if (a->li_pri)
  10210. {
  10211. *(p++) = UDATA_REQUEST_SET_MIXER_COEFS_PRI_SYNC;
  10212. w = 0;
  10213. if (li_config_table[i].channel & LI_CHANNEL_TX_DATA)
  10214. w |= MIXER_FEATURE_ENABLE_TX_DATA;
  10215. if (li_config_table[i].channel & LI_CHANNEL_RX_DATA)
  10216. w |= MIXER_FEATURE_ENABLE_RX_DATA;
  10217. *(p++) = (byte) w;
  10218. *(p++) = (byte)(w >> 8);
  10219. for (n = 0; n < ARRAY_SIZE(mixer_write_prog_pri); n++)
  10220. {
  10221. *(p++) = (byte)((plci->li_bchannel_id - 1) | mixer_write_prog_pri[n].line_flags);
  10222. for (j = a->li_base; j < a->li_base + MIXER_CHANNELS_PRI; j++)
  10223. {
  10224. w = ((li_config_table[i].coef_table[j] & 0xf) ^ (li_config_table[i].coef_table[j] >> 4));
  10225. if (w & mixer_write_prog_pri[n].mask)
  10226. {
  10227. *(p++) = (li_config_table[i].coef_table[j] & mixer_write_prog_pri[n].mask) ? 0x80 : 0x01;
  10228. li_config_table[i].coef_table[j] ^= mixer_write_prog_pri[n].mask << 4;
  10229. }
  10230. else
  10231. *(p++) = 0x00;
  10232. }
  10233. *(p++) = (byte)((plci->li_bchannel_id - 1) | MIXER_COEF_LINE_ROW_FLAG | mixer_write_prog_pri[n].line_flags);
  10234. for (j = a->li_base; j < a->li_base + MIXER_CHANNELS_PRI; j++)
  10235. {
  10236. w = ((li_config_table[j].coef_table[i] & 0xf) ^ (li_config_table[j].coef_table[i] >> 4));
  10237. if (w & mixer_write_prog_pri[n].mask)
  10238. {
  10239. *(p++) = (li_config_table[j].coef_table[i] & mixer_write_prog_pri[n].mask) ? 0x80 : 0x01;
  10240. li_config_table[j].coef_table[i] ^= mixer_write_prog_pri[n].mask << 4;
  10241. }
  10242. else
  10243. *(p++) = 0x00;
  10244. }
  10245. }
  10246. }
  10247. else
  10248. {
  10249. *(p++) = UDATA_REQUEST_SET_MIXER_COEFS_BRI;
  10250. w = 0;
  10251. if ((plci->tel == ADV_VOICE) && (plci == a->AdvSignalPLCI)
  10252. && (ADV_VOICE_NEW_COEF_BASE + sizeof(word) <= a->adv_voice_coef_length))
  10253. {
  10254. w = GET_WORD(a->adv_voice_coef_buffer + ADV_VOICE_NEW_COEF_BASE);
  10255. }
  10256. if (li_config_table[i].channel & LI_CHANNEL_TX_DATA)
  10257. w |= MIXER_FEATURE_ENABLE_TX_DATA;
  10258. if (li_config_table[i].channel & LI_CHANNEL_RX_DATA)
  10259. w |= MIXER_FEATURE_ENABLE_RX_DATA;
  10260. *(p++) = (byte) w;
  10261. *(p++) = (byte)(w >> 8);
  10262. for (j = 0; j < sizeof(ch_map); j += 2)
  10263. {
  10264. if (plci->li_bchannel_id == 2)
  10265. {
  10266. ch_map[j] = (byte)(j + 1);
  10267. ch_map[j + 1] = (byte) j;
  10268. }
  10269. else
  10270. {
  10271. ch_map[j] = (byte) j;
  10272. ch_map[j + 1] = (byte)(j + 1);
  10273. }
  10274. }
  10275. for (n = 0; n < ARRAY_SIZE(mixer_write_prog_bri); n++)
  10276. {
  10277. i = a->li_base + ch_map[mixer_write_prog_bri[n].to_ch];
  10278. j = a->li_base + ch_map[mixer_write_prog_bri[n].from_ch];
  10279. if (li_config_table[i].channel & li_config_table[j].channel & LI_CHANNEL_INVOLVED)
  10280. {
  10281. *p = ((li_config_table[i].coef_table[j] & mixer_write_prog_bri[n].mask) ? 0x80 : 0x01);
  10282. w = ((li_config_table[i].coef_table[j] & 0xf) ^ (li_config_table[i].coef_table[j] >> 4));
  10283. li_config_table[i].coef_table[j] ^= (w & mixer_write_prog_bri[n].mask) << 4;
  10284. }
  10285. else
  10286. {
  10287. *p = 0x00;
  10288. if ((a->AdvSignalPLCI != NULL) && (a->AdvSignalPLCI->tel == ADV_VOICE))
  10289. {
  10290. w = (plci == a->AdvSignalPLCI) ? n : mixer_swapped_index_bri[n];
  10291. if (ADV_VOICE_NEW_COEF_BASE + sizeof(word) + w < a->adv_voice_coef_length)
  10292. *p = a->adv_voice_coef_buffer[ADV_VOICE_NEW_COEF_BASE + sizeof(word) + w];
  10293. }
  10294. }
  10295. p++;
  10296. }
  10297. }
  10298. j = li_total_channels + 1;
  10299. }
  10300. }
  10301. plci->li_write_channel = j;
  10302. if (p != plci->internal_req_buffer)
  10303. {
  10304. plci->NData[0].P = plci->internal_req_buffer;
  10305. plci->NData[0].PLength = p - plci->internal_req_buffer;
  10306. plci->NL.X = plci->NData;
  10307. plci->NL.ReqCh = 0;
  10308. plci->NL.Req = plci->nl_req = (byte) N_UDATA;
  10309. plci->adapter->request(&plci->NL);
  10310. }
  10311. return (true);
  10312. }
  10313. static void mixer_notify_update(PLCI *plci, byte others)
  10314. {
  10315. DIVA_CAPI_ADAPTER *a;
  10316. word i, w;
  10317. PLCI *notify_plci;
  10318. byte msg[sizeof(CAPI_MSG_HEADER) + 6];
  10319. dbug(1, dprintf("[%06lx] %s,%d: mixer_notify_update %d",
  10320. (dword)((plci->Id << 8) | UnMapController(plci->adapter->Id)),
  10321. (char *)(FILE_), __LINE__, others));
  10322. a = plci->adapter;
  10323. if (a->profile.Global_Options & GL_LINE_INTERCONNECT_SUPPORTED)
  10324. {
  10325. if (others)
  10326. plci->li_notify_update = true;
  10327. i = 0;
  10328. do
  10329. {
  10330. notify_plci = NULL;
  10331. if (others)
  10332. {
  10333. while ((i < li_total_channels) && (li_config_table[i].plci == NULL))
  10334. i++;
  10335. if (i < li_total_channels)
  10336. notify_plci = li_config_table[i++].plci;
  10337. }
  10338. else
  10339. {
  10340. if ((plci->li_bchannel_id != 0)
  10341. && (li_config_table[a->li_base + (plci->li_bchannel_id - 1)].plci == plci))
  10342. {
  10343. notify_plci = plci;
  10344. }
  10345. }
  10346. if ((notify_plci != NULL)
  10347. && !notify_plci->li_notify_update
  10348. && (notify_plci->appl != NULL)
  10349. && (notify_plci->State)
  10350. && notify_plci->NL.Id && !notify_plci->nl_remove_id)
  10351. {
  10352. notify_plci->li_notify_update = true;
  10353. ((CAPI_MSG *) msg)->header.length = 18;
  10354. ((CAPI_MSG *) msg)->header.appl_id = notify_plci->appl->Id;
  10355. ((CAPI_MSG *) msg)->header.command = _FACILITY_R;
  10356. ((CAPI_MSG *) msg)->header.number = 0;
  10357. ((CAPI_MSG *) msg)->header.controller = notify_plci->adapter->Id;
  10358. ((CAPI_MSG *) msg)->header.plci = notify_plci->Id;
  10359. ((CAPI_MSG *) msg)->header.ncci = 0;
  10360. ((CAPI_MSG *) msg)->info.facility_req.Selector = SELECTOR_LINE_INTERCONNECT;
  10361. ((CAPI_MSG *) msg)->info.facility_req.structs[0] = 3;
  10362. ((CAPI_MSG *) msg)->info.facility_req.structs[1] = LI_REQ_SILENT_UPDATE & 0xff;
  10363. ((CAPI_MSG *) msg)->info.facility_req.structs[2] = LI_REQ_SILENT_UPDATE >> 8;
  10364. ((CAPI_MSG *) msg)->info.facility_req.structs[3] = 0;
  10365. w = api_put(notify_plci->appl, (CAPI_MSG *) msg);
  10366. if (w != _QUEUE_FULL)
  10367. {
  10368. if (w != 0)
  10369. {
  10370. dbug(1, dprintf("[%06lx] %s,%d: Interconnect notify failed %06x %d",
  10371. (dword)((plci->Id << 8) | UnMapController(plci->adapter->Id)),
  10372. (char *)(FILE_), __LINE__,
  10373. (dword)((notify_plci->Id << 8) | UnMapController(notify_plci->adapter->Id)), w));
  10374. }
  10375. notify_plci->li_notify_update = false;
  10376. }
  10377. }
  10378. } while (others && (notify_plci != NULL));
  10379. if (others)
  10380. plci->li_notify_update = false;
  10381. }
  10382. }
  10383. static void mixer_clear_config(PLCI *plci)
  10384. {
  10385. DIVA_CAPI_ADAPTER *a;
  10386. word i, j;
  10387. dbug(1, dprintf("[%06lx] %s,%d: mixer_clear_config",
  10388. (dword)((plci->Id << 8) | UnMapController(plci->adapter->Id)),
  10389. (char *)(FILE_), __LINE__));
  10390. plci->li_notify_update = false;
  10391. plci->li_plci_b_write_pos = 0;
  10392. plci->li_plci_b_read_pos = 0;
  10393. plci->li_plci_b_req_pos = 0;
  10394. a = plci->adapter;
  10395. if ((plci->li_bchannel_id != 0)
  10396. && (li_config_table[a->li_base + (plci->li_bchannel_id - 1)].plci == plci))
  10397. {
  10398. i = a->li_base + (plci->li_bchannel_id - 1);
  10399. li_config_table[i].curchnl = 0;
  10400. li_config_table[i].channel = 0;
  10401. li_config_table[i].chflags = 0;
  10402. for (j = 0; j < li_total_channels; j++)
  10403. {
  10404. li_config_table[j].flag_table[i] = 0;
  10405. li_config_table[i].flag_table[j] = 0;
  10406. li_config_table[i].coef_table[j] = 0;
  10407. li_config_table[j].coef_table[i] = 0;
  10408. }
  10409. if (!a->li_pri)
  10410. {
  10411. li_config_table[i].coef_table[i] |= LI_COEF_CH_PC_SET | LI_COEF_PC_CH_SET;
  10412. if ((plci->tel == ADV_VOICE) && (plci == a->AdvSignalPLCI))
  10413. {
  10414. i = a->li_base + MIXER_IC_CHANNEL_BASE + (plci->li_bchannel_id - 1);
  10415. li_config_table[i].curchnl = 0;
  10416. li_config_table[i].channel = 0;
  10417. li_config_table[i].chflags = 0;
  10418. for (j = 0; j < li_total_channels; j++)
  10419. {
  10420. li_config_table[i].flag_table[j] = 0;
  10421. li_config_table[j].flag_table[i] = 0;
  10422. li_config_table[i].coef_table[j] = 0;
  10423. li_config_table[j].coef_table[i] = 0;
  10424. }
  10425. if (a->manufacturer_features & MANUFACTURER_FEATURE_SLAVE_CODEC)
  10426. {
  10427. i = a->li_base + MIXER_IC_CHANNEL_BASE + (2 - plci->li_bchannel_id);
  10428. li_config_table[i].curchnl = 0;
  10429. li_config_table[i].channel = 0;
  10430. li_config_table[i].chflags = 0;
  10431. for (j = 0; j < li_total_channels; j++)
  10432. {
  10433. li_config_table[i].flag_table[j] = 0;
  10434. li_config_table[j].flag_table[i] = 0;
  10435. li_config_table[i].coef_table[j] = 0;
  10436. li_config_table[j].coef_table[i] = 0;
  10437. }
  10438. }
  10439. }
  10440. }
  10441. }
  10442. }
  10443. static void mixer_prepare_switch(dword Id, PLCI *plci)
  10444. {
  10445. dbug(1, dprintf("[%06lx] %s,%d: mixer_prepare_switch",
  10446. UnMapId(Id), (char *)(FILE_), __LINE__));
  10447. do
  10448. {
  10449. mixer_indication_coefs_set(Id, plci);
  10450. } while (plci->li_plci_b_read_pos != plci->li_plci_b_req_pos);
  10451. }
  10452. static word mixer_save_config(dword Id, PLCI *plci, byte Rc)
  10453. {
  10454. DIVA_CAPI_ADAPTER *a;
  10455. word i, j;
  10456. dbug(1, dprintf("[%06lx] %s,%d: mixer_save_config %02x %d",
  10457. UnMapId(Id), (char *)(FILE_), __LINE__, Rc, plci->adjust_b_state));
  10458. a = plci->adapter;
  10459. if ((plci->li_bchannel_id != 0)
  10460. && (li_config_table[a->li_base + (plci->li_bchannel_id - 1)].plci == plci))
  10461. {
  10462. i = a->li_base + (plci->li_bchannel_id - 1);
  10463. for (j = 0; j < li_total_channels; j++)
  10464. {
  10465. li_config_table[i].coef_table[j] &= 0xf;
  10466. li_config_table[j].coef_table[i] &= 0xf;
  10467. }
  10468. if (!a->li_pri)
  10469. li_config_table[i].coef_table[i] |= LI_COEF_CH_PC_SET | LI_COEF_PC_CH_SET;
  10470. }
  10471. return (GOOD);
  10472. }
  10473. static word mixer_restore_config(dword Id, PLCI *plci, byte Rc)
  10474. {
  10475. DIVA_CAPI_ADAPTER *a;
  10476. word Info;
  10477. dbug(1, dprintf("[%06lx] %s,%d: mixer_restore_config %02x %d",
  10478. UnMapId(Id), (char *)(FILE_), __LINE__, Rc, plci->adjust_b_state));
  10479. Info = GOOD;
  10480. a = plci->adapter;
  10481. if ((plci->B1_facilities & B1_FACILITY_MIXER)
  10482. && (plci->li_bchannel_id != 0)
  10483. && (li_config_table[a->li_base + (plci->li_bchannel_id - 1)].plci == plci))
  10484. {
  10485. switch (plci->adjust_b_state)
  10486. {
  10487. case ADJUST_B_RESTORE_MIXER_1:
  10488. if (a->manufacturer_features & MANUFACTURER_FEATURE_XCONNECT)
  10489. {
  10490. plci->internal_command = plci->adjust_b_command;
  10491. if (plci_nl_busy(plci))
  10492. {
  10493. plci->adjust_b_state = ADJUST_B_RESTORE_MIXER_1;
  10494. break;
  10495. }
  10496. xconnect_query_addresses(plci);
  10497. plci->adjust_b_state = ADJUST_B_RESTORE_MIXER_2;
  10498. break;
  10499. }
  10500. plci->adjust_b_state = ADJUST_B_RESTORE_MIXER_5;
  10501. Rc = OK;
  10502. case ADJUST_B_RESTORE_MIXER_2:
  10503. case ADJUST_B_RESTORE_MIXER_3:
  10504. case ADJUST_B_RESTORE_MIXER_4:
  10505. if ((Rc != OK) && (Rc != OK_FC) && (Rc != 0))
  10506. {
  10507. dbug(1, dprintf("[%06lx] %s,%d: Adjust B query addresses failed %02x",
  10508. UnMapId(Id), (char *)(FILE_), __LINE__, Rc));
  10509. Info = _WRONG_STATE;
  10510. break;
  10511. }
  10512. if (Rc == OK)
  10513. {
  10514. if (plci->adjust_b_state == ADJUST_B_RESTORE_MIXER_2)
  10515. plci->adjust_b_state = ADJUST_B_RESTORE_MIXER_3;
  10516. else if (plci->adjust_b_state == ADJUST_B_RESTORE_MIXER_4)
  10517. plci->adjust_b_state = ADJUST_B_RESTORE_MIXER_5;
  10518. }
  10519. else if (Rc == 0)
  10520. {
  10521. if (plci->adjust_b_state == ADJUST_B_RESTORE_MIXER_2)
  10522. plci->adjust_b_state = ADJUST_B_RESTORE_MIXER_4;
  10523. else if (plci->adjust_b_state == ADJUST_B_RESTORE_MIXER_3)
  10524. plci->adjust_b_state = ADJUST_B_RESTORE_MIXER_5;
  10525. }
  10526. if (plci->adjust_b_state != ADJUST_B_RESTORE_MIXER_5)
  10527. {
  10528. plci->internal_command = plci->adjust_b_command;
  10529. break;
  10530. }
  10531. case ADJUST_B_RESTORE_MIXER_5:
  10532. xconnect_write_coefs(plci, plci->adjust_b_command);
  10533. plci->adjust_b_state = ADJUST_B_RESTORE_MIXER_6;
  10534. Rc = OK;
  10535. case ADJUST_B_RESTORE_MIXER_6:
  10536. if (!xconnect_write_coefs_process(Id, plci, Rc))
  10537. {
  10538. dbug(1, dprintf("[%06lx] %s,%d: Write mixer coefs failed",
  10539. UnMapId(Id), (char *)(FILE_), __LINE__));
  10540. Info = _FACILITY_NOT_SUPPORTED;
  10541. break;
  10542. }
  10543. if (plci->internal_command)
  10544. break;
  10545. plci->adjust_b_state = ADJUST_B_RESTORE_MIXER_7;
  10546. case ADJUST_B_RESTORE_MIXER_7:
  10547. break;
  10548. }
  10549. }
  10550. return (Info);
  10551. }
  10552. static void mixer_command(dword Id, PLCI *plci, byte Rc)
  10553. {
  10554. DIVA_CAPI_ADAPTER *a;
  10555. word i, internal_command;
  10556. dbug(1, dprintf("[%06lx] %s,%d: mixer_command %02x %04x %04x",
  10557. UnMapId(Id), (char *)(FILE_), __LINE__, Rc, plci->internal_command,
  10558. plci->li_cmd));
  10559. a = plci->adapter;
  10560. internal_command = plci->internal_command;
  10561. plci->internal_command = 0;
  10562. switch (plci->li_cmd)
  10563. {
  10564. case LI_REQ_CONNECT:
  10565. case LI_REQ_DISCONNECT:
  10566. case LI_REQ_SILENT_UPDATE:
  10567. switch (internal_command)
  10568. {
  10569. default:
  10570. if (plci->li_channel_bits & LI_CHANNEL_INVOLVED)
  10571. {
  10572. adjust_b1_resource(Id, plci, NULL, (word)(plci->B1_facilities |
  10573. B1_FACILITY_MIXER), MIXER_COMMAND_1);
  10574. }
  10575. case MIXER_COMMAND_1:
  10576. if (plci->li_channel_bits & LI_CHANNEL_INVOLVED)
  10577. {
  10578. if (adjust_b_process(Id, plci, Rc) != GOOD)
  10579. {
  10580. dbug(1, dprintf("[%06lx] %s,%d: Load mixer failed",
  10581. UnMapId(Id), (char *)(FILE_), __LINE__));
  10582. break;
  10583. }
  10584. if (plci->internal_command)
  10585. return;
  10586. }
  10587. plci->li_plci_b_req_pos = plci->li_plci_b_write_pos;
  10588. if ((plci->li_channel_bits & LI_CHANNEL_INVOLVED)
  10589. || ((get_b1_facilities(plci, plci->B1_resource) & B1_FACILITY_MIXER)
  10590. && (add_b1_facilities(plci, plci->B1_resource, (word)(plci->B1_facilities &
  10591. ~B1_FACILITY_MIXER)) == plci->B1_resource)))
  10592. {
  10593. xconnect_write_coefs(plci, MIXER_COMMAND_2);
  10594. }
  10595. else
  10596. {
  10597. do
  10598. {
  10599. mixer_indication_coefs_set(Id, plci);
  10600. } while (plci->li_plci_b_read_pos != plci->li_plci_b_req_pos);
  10601. }
  10602. case MIXER_COMMAND_2:
  10603. if ((plci->li_channel_bits & LI_CHANNEL_INVOLVED)
  10604. || ((get_b1_facilities(plci, plci->B1_resource) & B1_FACILITY_MIXER)
  10605. && (add_b1_facilities(plci, plci->B1_resource, (word)(plci->B1_facilities &
  10606. ~B1_FACILITY_MIXER)) == plci->B1_resource)))
  10607. {
  10608. if (!xconnect_write_coefs_process(Id, plci, Rc))
  10609. {
  10610. dbug(1, dprintf("[%06lx] %s,%d: Write mixer coefs failed",
  10611. UnMapId(Id), (char *)(FILE_), __LINE__));
  10612. if (plci->li_plci_b_write_pos != plci->li_plci_b_req_pos)
  10613. {
  10614. do
  10615. {
  10616. plci->li_plci_b_write_pos = (plci->li_plci_b_write_pos == 0) ?
  10617. LI_PLCI_B_QUEUE_ENTRIES - 1 : plci->li_plci_b_write_pos - 1;
  10618. i = (plci->li_plci_b_write_pos == 0) ?
  10619. LI_PLCI_B_QUEUE_ENTRIES - 1 : plci->li_plci_b_write_pos - 1;
  10620. } while ((plci->li_plci_b_write_pos != plci->li_plci_b_req_pos)
  10621. && !(plci->li_plci_b_queue[i] & LI_PLCI_B_LAST_FLAG));
  10622. }
  10623. break;
  10624. }
  10625. if (plci->internal_command)
  10626. return;
  10627. }
  10628. if (!(plci->li_channel_bits & LI_CHANNEL_INVOLVED))
  10629. {
  10630. adjust_b1_resource(Id, plci, NULL, (word)(plci->B1_facilities &
  10631. ~B1_FACILITY_MIXER), MIXER_COMMAND_3);
  10632. }
  10633. case MIXER_COMMAND_3:
  10634. if (!(plci->li_channel_bits & LI_CHANNEL_INVOLVED))
  10635. {
  10636. if (adjust_b_process(Id, plci, Rc) != GOOD)
  10637. {
  10638. dbug(1, dprintf("[%06lx] %s,%d: Unload mixer failed",
  10639. UnMapId(Id), (char *)(FILE_), __LINE__));
  10640. break;
  10641. }
  10642. if (plci->internal_command)
  10643. return;
  10644. }
  10645. break;
  10646. }
  10647. break;
  10648. }
  10649. if ((plci->li_bchannel_id == 0)
  10650. || (li_config_table[a->li_base + (plci->li_bchannel_id - 1)].plci != plci))
  10651. {
  10652. dbug(1, dprintf("[%06x] %s,%d: Channel id wiped out %d",
  10653. UnMapId(Id), (char *)(FILE_), __LINE__, (int)(plci->li_bchannel_id)));
  10654. }
  10655. else
  10656. {
  10657. i = a->li_base + (plci->li_bchannel_id - 1);
  10658. li_config_table[i].curchnl = plci->li_channel_bits;
  10659. if (!a->li_pri && (plci->tel == ADV_VOICE) && (plci == a->AdvSignalPLCI))
  10660. {
  10661. i = a->li_base + MIXER_IC_CHANNEL_BASE + (plci->li_bchannel_id - 1);
  10662. li_config_table[i].curchnl = plci->li_channel_bits;
  10663. if (a->manufacturer_features & MANUFACTURER_FEATURE_SLAVE_CODEC)
  10664. {
  10665. i = a->li_base + MIXER_IC_CHANNEL_BASE + (2 - plci->li_bchannel_id);
  10666. li_config_table[i].curchnl = plci->li_channel_bits;
  10667. }
  10668. }
  10669. }
  10670. }
  10671. static void li_update_connect(dword Id, DIVA_CAPI_ADAPTER *a, PLCI *plci,
  10672. dword plci_b_id, byte connect, dword li_flags)
  10673. {
  10674. word i, ch_a, ch_a_v, ch_a_s, ch_b, ch_b_v, ch_b_s;
  10675. PLCI *plci_b;
  10676. DIVA_CAPI_ADAPTER *a_b;
  10677. a_b = &(adapter[MapController((byte)(plci_b_id & 0x7f)) - 1]);
  10678. plci_b = &(a_b->plci[((plci_b_id >> 8) & 0xff) - 1]);
  10679. ch_a = a->li_base + (plci->li_bchannel_id - 1);
  10680. if (!a->li_pri && (plci->tel == ADV_VOICE)
  10681. && (plci == a->AdvSignalPLCI) && (Id & EXT_CONTROLLER))
  10682. {
  10683. ch_a_v = ch_a + MIXER_IC_CHANNEL_BASE;
  10684. ch_a_s = (a->manufacturer_features & MANUFACTURER_FEATURE_SLAVE_CODEC) ?
  10685. a->li_base + MIXER_IC_CHANNEL_BASE + (2 - plci->li_bchannel_id) : ch_a_v;
  10686. }
  10687. else
  10688. {
  10689. ch_a_v = ch_a;
  10690. ch_a_s = ch_a;
  10691. }
  10692. ch_b = a_b->li_base + (plci_b->li_bchannel_id - 1);
  10693. if (!a_b->li_pri && (plci_b->tel == ADV_VOICE)
  10694. && (plci_b == a_b->AdvSignalPLCI) && (plci_b_id & EXT_CONTROLLER))
  10695. {
  10696. ch_b_v = ch_b + MIXER_IC_CHANNEL_BASE;
  10697. ch_b_s = (a_b->manufacturer_features & MANUFACTURER_FEATURE_SLAVE_CODEC) ?
  10698. a_b->li_base + MIXER_IC_CHANNEL_BASE + (2 - plci_b->li_bchannel_id) : ch_b_v;
  10699. }
  10700. else
  10701. {
  10702. ch_b_v = ch_b;
  10703. ch_b_s = ch_b;
  10704. }
  10705. if (connect)
  10706. {
  10707. li_config_table[ch_a].flag_table[ch_a_v] &= ~LI_FLAG_MONITOR;
  10708. li_config_table[ch_a].flag_table[ch_a_s] &= ~LI_FLAG_MONITOR;
  10709. li_config_table[ch_a_v].flag_table[ch_a] &= ~(LI_FLAG_ANNOUNCEMENT | LI_FLAG_MIX);
  10710. li_config_table[ch_a_s].flag_table[ch_a] &= ~(LI_FLAG_ANNOUNCEMENT | LI_FLAG_MIX);
  10711. }
  10712. li_config_table[ch_a].flag_table[ch_b_v] &= ~LI_FLAG_MONITOR;
  10713. li_config_table[ch_a].flag_table[ch_b_s] &= ~LI_FLAG_MONITOR;
  10714. li_config_table[ch_b_v].flag_table[ch_a] &= ~(LI_FLAG_ANNOUNCEMENT | LI_FLAG_MIX);
  10715. li_config_table[ch_b_s].flag_table[ch_a] &= ~(LI_FLAG_ANNOUNCEMENT | LI_FLAG_MIX);
  10716. if (ch_a_v == ch_b_v)
  10717. {
  10718. li_config_table[ch_a_v].flag_table[ch_b_v] &= ~LI_FLAG_CONFERENCE;
  10719. li_config_table[ch_a_s].flag_table[ch_b_s] &= ~LI_FLAG_CONFERENCE;
  10720. }
  10721. else
  10722. {
  10723. if (li_config_table[ch_a_v].flag_table[ch_b_v] & LI_FLAG_CONFERENCE)
  10724. {
  10725. for (i = 0; i < li_total_channels; i++)
  10726. {
  10727. if (i != ch_a_v)
  10728. li_config_table[ch_a_v].flag_table[i] &= ~LI_FLAG_CONFERENCE;
  10729. }
  10730. }
  10731. if (li_config_table[ch_a_s].flag_table[ch_b_v] & LI_FLAG_CONFERENCE)
  10732. {
  10733. for (i = 0; i < li_total_channels; i++)
  10734. {
  10735. if (i != ch_a_s)
  10736. li_config_table[ch_a_s].flag_table[i] &= ~LI_FLAG_CONFERENCE;
  10737. }
  10738. }
  10739. if (li_config_table[ch_b_v].flag_table[ch_a_v] & LI_FLAG_CONFERENCE)
  10740. {
  10741. for (i = 0; i < li_total_channels; i++)
  10742. {
  10743. if (i != ch_a_v)
  10744. li_config_table[i].flag_table[ch_a_v] &= ~LI_FLAG_CONFERENCE;
  10745. }
  10746. }
  10747. if (li_config_table[ch_b_v].flag_table[ch_a_s] & LI_FLAG_CONFERENCE)
  10748. {
  10749. for (i = 0; i < li_total_channels; i++)
  10750. {
  10751. if (i != ch_a_s)
  10752. li_config_table[i].flag_table[ch_a_s] &= ~LI_FLAG_CONFERENCE;
  10753. }
  10754. }
  10755. }
  10756. if (li_flags & LI_FLAG_CONFERENCE_A_B)
  10757. {
  10758. li_config_table[ch_b_v].flag_table[ch_a_v] |= LI_FLAG_CONFERENCE;
  10759. li_config_table[ch_b_s].flag_table[ch_a_v] |= LI_FLAG_CONFERENCE;
  10760. li_config_table[ch_b_v].flag_table[ch_a_s] |= LI_FLAG_CONFERENCE;
  10761. li_config_table[ch_b_s].flag_table[ch_a_s] |= LI_FLAG_CONFERENCE;
  10762. }
  10763. if (li_flags & LI_FLAG_CONFERENCE_B_A)
  10764. {
  10765. li_config_table[ch_a_v].flag_table[ch_b_v] |= LI_FLAG_CONFERENCE;
  10766. li_config_table[ch_a_v].flag_table[ch_b_s] |= LI_FLAG_CONFERENCE;
  10767. li_config_table[ch_a_s].flag_table[ch_b_v] |= LI_FLAG_CONFERENCE;
  10768. li_config_table[ch_a_s].flag_table[ch_b_s] |= LI_FLAG_CONFERENCE;
  10769. }
  10770. if (li_flags & LI_FLAG_MONITOR_A)
  10771. {
  10772. li_config_table[ch_a].flag_table[ch_a_v] |= LI_FLAG_MONITOR;
  10773. li_config_table[ch_a].flag_table[ch_a_s] |= LI_FLAG_MONITOR;
  10774. }
  10775. if (li_flags & LI_FLAG_MONITOR_B)
  10776. {
  10777. li_config_table[ch_a].flag_table[ch_b_v] |= LI_FLAG_MONITOR;
  10778. li_config_table[ch_a].flag_table[ch_b_s] |= LI_FLAG_MONITOR;
  10779. }
  10780. if (li_flags & LI_FLAG_ANNOUNCEMENT_A)
  10781. {
  10782. li_config_table[ch_a_v].flag_table[ch_a] |= LI_FLAG_ANNOUNCEMENT;
  10783. li_config_table[ch_a_s].flag_table[ch_a] |= LI_FLAG_ANNOUNCEMENT;
  10784. }
  10785. if (li_flags & LI_FLAG_ANNOUNCEMENT_B)
  10786. {
  10787. li_config_table[ch_b_v].flag_table[ch_a] |= LI_FLAG_ANNOUNCEMENT;
  10788. li_config_table[ch_b_s].flag_table[ch_a] |= LI_FLAG_ANNOUNCEMENT;
  10789. }
  10790. if (li_flags & LI_FLAG_MIX_A)
  10791. {
  10792. li_config_table[ch_a_v].flag_table[ch_a] |= LI_FLAG_MIX;
  10793. li_config_table[ch_a_s].flag_table[ch_a] |= LI_FLAG_MIX;
  10794. }
  10795. if (li_flags & LI_FLAG_MIX_B)
  10796. {
  10797. li_config_table[ch_b_v].flag_table[ch_a] |= LI_FLAG_MIX;
  10798. li_config_table[ch_b_s].flag_table[ch_a] |= LI_FLAG_MIX;
  10799. }
  10800. if (ch_a_v != ch_a_s)
  10801. {
  10802. li_config_table[ch_a_v].flag_table[ch_a_s] |= LI_FLAG_CONFERENCE;
  10803. li_config_table[ch_a_s].flag_table[ch_a_v] |= LI_FLAG_CONFERENCE;
  10804. }
  10805. if (ch_b_v != ch_b_s)
  10806. {
  10807. li_config_table[ch_b_v].flag_table[ch_b_s] |= LI_FLAG_CONFERENCE;
  10808. li_config_table[ch_b_s].flag_table[ch_b_v] |= LI_FLAG_CONFERENCE;
  10809. }
  10810. }
  10811. static void li2_update_connect(dword Id, DIVA_CAPI_ADAPTER *a, PLCI *plci,
  10812. dword plci_b_id, byte connect, dword li_flags)
  10813. {
  10814. word ch_a, ch_a_v, ch_a_s, ch_b, ch_b_v, ch_b_s;
  10815. PLCI *plci_b;
  10816. DIVA_CAPI_ADAPTER *a_b;
  10817. a_b = &(adapter[MapController((byte)(plci_b_id & 0x7f)) - 1]);
  10818. plci_b = &(a_b->plci[((plci_b_id >> 8) & 0xff) - 1]);
  10819. ch_a = a->li_base + (plci->li_bchannel_id - 1);
  10820. if (!a->li_pri && (plci->tel == ADV_VOICE)
  10821. && (plci == a->AdvSignalPLCI) && (Id & EXT_CONTROLLER))
  10822. {
  10823. ch_a_v = ch_a + MIXER_IC_CHANNEL_BASE;
  10824. ch_a_s = (a->manufacturer_features & MANUFACTURER_FEATURE_SLAVE_CODEC) ?
  10825. a->li_base + MIXER_IC_CHANNEL_BASE + (2 - plci->li_bchannel_id) : ch_a_v;
  10826. }
  10827. else
  10828. {
  10829. ch_a_v = ch_a;
  10830. ch_a_s = ch_a;
  10831. }
  10832. ch_b = a_b->li_base + (plci_b->li_bchannel_id - 1);
  10833. if (!a_b->li_pri && (plci_b->tel == ADV_VOICE)
  10834. && (plci_b == a_b->AdvSignalPLCI) && (plci_b_id & EXT_CONTROLLER))
  10835. {
  10836. ch_b_v = ch_b + MIXER_IC_CHANNEL_BASE;
  10837. ch_b_s = (a_b->manufacturer_features & MANUFACTURER_FEATURE_SLAVE_CODEC) ?
  10838. a_b->li_base + MIXER_IC_CHANNEL_BASE + (2 - plci_b->li_bchannel_id) : ch_b_v;
  10839. }
  10840. else
  10841. {
  10842. ch_b_v = ch_b;
  10843. ch_b_s = ch_b;
  10844. }
  10845. if (connect)
  10846. {
  10847. li_config_table[ch_b].flag_table[ch_b_v] &= ~LI_FLAG_MONITOR;
  10848. li_config_table[ch_b].flag_table[ch_b_s] &= ~LI_FLAG_MONITOR;
  10849. li_config_table[ch_b_v].flag_table[ch_b] &= ~LI_FLAG_MIX;
  10850. li_config_table[ch_b_s].flag_table[ch_b] &= ~LI_FLAG_MIX;
  10851. li_config_table[ch_b].flag_table[ch_b] &= ~LI_FLAG_PCCONNECT;
  10852. li_config_table[ch_b].chflags &= ~(LI_CHFLAG_MONITOR | LI_CHFLAG_MIX | LI_CHFLAG_LOOP);
  10853. }
  10854. li_config_table[ch_b_v].flag_table[ch_a_v] &= ~(LI_FLAG_INTERCONNECT | LI_FLAG_CONFERENCE);
  10855. li_config_table[ch_b_s].flag_table[ch_a_v] &= ~(LI_FLAG_INTERCONNECT | LI_FLAG_CONFERENCE);
  10856. li_config_table[ch_b_v].flag_table[ch_a_s] &= ~(LI_FLAG_INTERCONNECT | LI_FLAG_CONFERENCE);
  10857. li_config_table[ch_b_s].flag_table[ch_a_s] &= ~(LI_FLAG_INTERCONNECT | LI_FLAG_CONFERENCE);
  10858. li_config_table[ch_a_v].flag_table[ch_b_v] &= ~(LI_FLAG_INTERCONNECT | LI_FLAG_CONFERENCE);
  10859. li_config_table[ch_a_v].flag_table[ch_b_s] &= ~(LI_FLAG_INTERCONNECT | LI_FLAG_CONFERENCE);
  10860. li_config_table[ch_a_s].flag_table[ch_b_v] &= ~(LI_FLAG_INTERCONNECT | LI_FLAG_CONFERENCE);
  10861. li_config_table[ch_a_s].flag_table[ch_b_s] &= ~(LI_FLAG_INTERCONNECT | LI_FLAG_CONFERENCE);
  10862. if (li_flags & LI2_FLAG_INTERCONNECT_A_B)
  10863. {
  10864. li_config_table[ch_b_v].flag_table[ch_a_v] |= LI_FLAG_INTERCONNECT;
  10865. li_config_table[ch_b_s].flag_table[ch_a_v] |= LI_FLAG_INTERCONNECT;
  10866. li_config_table[ch_b_v].flag_table[ch_a_s] |= LI_FLAG_INTERCONNECT;
  10867. li_config_table[ch_b_s].flag_table[ch_a_s] |= LI_FLAG_INTERCONNECT;
  10868. }
  10869. if (li_flags & LI2_FLAG_INTERCONNECT_B_A)
  10870. {
  10871. li_config_table[ch_a_v].flag_table[ch_b_v] |= LI_FLAG_INTERCONNECT;
  10872. li_config_table[ch_a_v].flag_table[ch_b_s] |= LI_FLAG_INTERCONNECT;
  10873. li_config_table[ch_a_s].flag_table[ch_b_v] |= LI_FLAG_INTERCONNECT;
  10874. li_config_table[ch_a_s].flag_table[ch_b_s] |= LI_FLAG_INTERCONNECT;
  10875. }
  10876. if (li_flags & LI2_FLAG_MONITOR_B)
  10877. {
  10878. li_config_table[ch_b].flag_table[ch_b_v] |= LI_FLAG_MONITOR;
  10879. li_config_table[ch_b].flag_table[ch_b_s] |= LI_FLAG_MONITOR;
  10880. }
  10881. if (li_flags & LI2_FLAG_MIX_B)
  10882. {
  10883. li_config_table[ch_b_v].flag_table[ch_b] |= LI_FLAG_MIX;
  10884. li_config_table[ch_b_s].flag_table[ch_b] |= LI_FLAG_MIX;
  10885. }
  10886. if (li_flags & LI2_FLAG_MONITOR_X)
  10887. li_config_table[ch_b].chflags |= LI_CHFLAG_MONITOR;
  10888. if (li_flags & LI2_FLAG_MIX_X)
  10889. li_config_table[ch_b].chflags |= LI_CHFLAG_MIX;
  10890. if (li_flags & LI2_FLAG_LOOP_B)
  10891. {
  10892. li_config_table[ch_b_v].flag_table[ch_b_v] |= LI_FLAG_INTERCONNECT;
  10893. li_config_table[ch_b_s].flag_table[ch_b_v] |= LI_FLAG_INTERCONNECT;
  10894. li_config_table[ch_b_v].flag_table[ch_b_s] |= LI_FLAG_INTERCONNECT;
  10895. li_config_table[ch_b_s].flag_table[ch_b_s] |= LI_FLAG_INTERCONNECT;
  10896. }
  10897. if (li_flags & LI2_FLAG_LOOP_PC)
  10898. li_config_table[ch_b].flag_table[ch_b] |= LI_FLAG_PCCONNECT;
  10899. if (li_flags & LI2_FLAG_LOOP_X)
  10900. li_config_table[ch_b].chflags |= LI_CHFLAG_LOOP;
  10901. if (li_flags & LI2_FLAG_PCCONNECT_A_B)
  10902. li_config_table[ch_b_s].flag_table[ch_a_s] |= LI_FLAG_PCCONNECT;
  10903. if (li_flags & LI2_FLAG_PCCONNECT_B_A)
  10904. li_config_table[ch_a_s].flag_table[ch_b_s] |= LI_FLAG_PCCONNECT;
  10905. if (ch_a_v != ch_a_s)
  10906. {
  10907. li_config_table[ch_a_v].flag_table[ch_a_s] |= LI_FLAG_CONFERENCE;
  10908. li_config_table[ch_a_s].flag_table[ch_a_v] |= LI_FLAG_CONFERENCE;
  10909. }
  10910. if (ch_b_v != ch_b_s)
  10911. {
  10912. li_config_table[ch_b_v].flag_table[ch_b_s] |= LI_FLAG_CONFERENCE;
  10913. li_config_table[ch_b_s].flag_table[ch_b_v] |= LI_FLAG_CONFERENCE;
  10914. }
  10915. }
  10916. static word li_check_main_plci(dword Id, PLCI *plci)
  10917. {
  10918. if (plci == NULL)
  10919. {
  10920. dbug(1, dprintf("[%06lx] %s,%d: Wrong PLCI",
  10921. UnMapId(Id), (char *)(FILE_), __LINE__));
  10922. return (_WRONG_IDENTIFIER);
  10923. }
  10924. if (!plci->State
  10925. || !plci->NL.Id || plci->nl_remove_id
  10926. || (plci->li_bchannel_id == 0))
  10927. {
  10928. dbug(1, dprintf("[%06lx] %s,%d: Wrong state",
  10929. UnMapId(Id), (char *)(FILE_), __LINE__));
  10930. return (_WRONG_STATE);
  10931. }
  10932. li_config_table[plci->adapter->li_base + (plci->li_bchannel_id - 1)].plci = plci;
  10933. return (GOOD);
  10934. }
  10935. static PLCI *li_check_plci_b(dword Id, PLCI *plci,
  10936. dword plci_b_id, word plci_b_write_pos, byte *p_result)
  10937. {
  10938. byte ctlr_b;
  10939. PLCI *plci_b;
  10940. if (((plci->li_plci_b_read_pos > plci_b_write_pos) ? plci->li_plci_b_read_pos :
  10941. LI_PLCI_B_QUEUE_ENTRIES + plci->li_plci_b_read_pos) - plci_b_write_pos - 1 < 2)
  10942. {
  10943. dbug(1, dprintf("[%06lx] %s,%d: LI request overrun",
  10944. UnMapId(Id), (char *)(FILE_), __LINE__));
  10945. PUT_WORD(p_result, _REQUEST_NOT_ALLOWED_IN_THIS_STATE);
  10946. return (NULL);
  10947. }
  10948. ctlr_b = 0;
  10949. if ((plci_b_id & 0x7f) != 0)
  10950. {
  10951. ctlr_b = MapController((byte)(plci_b_id & 0x7f));
  10952. if ((ctlr_b > max_adapter) || ((ctlr_b != 0) && (adapter[ctlr_b - 1].request == NULL)))
  10953. ctlr_b = 0;
  10954. }
  10955. if ((ctlr_b == 0)
  10956. || (((plci_b_id >> 8) & 0xff) == 0)
  10957. || (((plci_b_id >> 8) & 0xff) > adapter[ctlr_b - 1].max_plci))
  10958. {
  10959. dbug(1, dprintf("[%06lx] %s,%d: LI invalid second PLCI %08lx",
  10960. UnMapId(Id), (char *)(FILE_), __LINE__, plci_b_id));
  10961. PUT_WORD(p_result, _WRONG_IDENTIFIER);
  10962. return (NULL);
  10963. }
  10964. plci_b = &(adapter[ctlr_b - 1].plci[((plci_b_id >> 8) & 0xff) - 1]);
  10965. if (!plci_b->State
  10966. || !plci_b->NL.Id || plci_b->nl_remove_id
  10967. || (plci_b->li_bchannel_id == 0))
  10968. {
  10969. dbug(1, dprintf("[%06lx] %s,%d: LI peer in wrong state %08lx",
  10970. UnMapId(Id), (char *)(FILE_), __LINE__, plci_b_id));
  10971. PUT_WORD(p_result, _REQUEST_NOT_ALLOWED_IN_THIS_STATE);
  10972. return (NULL);
  10973. }
  10974. li_config_table[plci_b->adapter->li_base + (plci_b->li_bchannel_id - 1)].plci = plci_b;
  10975. if (((byte)(plci_b_id & ~EXT_CONTROLLER)) !=
  10976. ((byte)(UnMapController(plci->adapter->Id) & ~EXT_CONTROLLER))
  10977. && (!(plci->adapter->manufacturer_features & MANUFACTURER_FEATURE_XCONNECT)
  10978. || !(plci_b->adapter->manufacturer_features & MANUFACTURER_FEATURE_XCONNECT)))
  10979. {
  10980. dbug(1, dprintf("[%06lx] %s,%d: LI not on same ctrl %08lx",
  10981. UnMapId(Id), (char *)(FILE_), __LINE__, plci_b_id));
  10982. PUT_WORD(p_result, _WRONG_IDENTIFIER);
  10983. return (NULL);
  10984. }
  10985. if (!(get_b1_facilities(plci_b, add_b1_facilities(plci_b, plci_b->B1_resource,
  10986. (word)(plci_b->B1_facilities | B1_FACILITY_MIXER))) & B1_FACILITY_MIXER))
  10987. {
  10988. dbug(1, dprintf("[%06lx] %s,%d: Interconnect peer cannot mix %d",
  10989. UnMapId(Id), (char *)(FILE_), __LINE__, plci_b->B1_resource));
  10990. PUT_WORD(p_result, _REQUEST_NOT_ALLOWED_IN_THIS_STATE);
  10991. return (NULL);
  10992. }
  10993. return (plci_b);
  10994. }
  10995. static PLCI *li2_check_plci_b(dword Id, PLCI *plci,
  10996. dword plci_b_id, word plci_b_write_pos, byte *p_result)
  10997. {
  10998. byte ctlr_b;
  10999. PLCI *plci_b;
  11000. if (((plci->li_plci_b_read_pos > plci_b_write_pos) ? plci->li_plci_b_read_pos :
  11001. LI_PLCI_B_QUEUE_ENTRIES + plci->li_plci_b_read_pos) - plci_b_write_pos - 1 < 2)
  11002. {
  11003. dbug(1, dprintf("[%06lx] %s,%d: LI request overrun",
  11004. UnMapId(Id), (char *)(FILE_), __LINE__));
  11005. PUT_WORD(p_result, _WRONG_STATE);
  11006. return (NULL);
  11007. }
  11008. ctlr_b = 0;
  11009. if ((plci_b_id & 0x7f) != 0)
  11010. {
  11011. ctlr_b = MapController((byte)(plci_b_id & 0x7f));
  11012. if ((ctlr_b > max_adapter) || ((ctlr_b != 0) && (adapter[ctlr_b - 1].request == NULL)))
  11013. ctlr_b = 0;
  11014. }
  11015. if ((ctlr_b == 0)
  11016. || (((plci_b_id >> 8) & 0xff) == 0)
  11017. || (((plci_b_id >> 8) & 0xff) > adapter[ctlr_b - 1].max_plci))
  11018. {
  11019. dbug(1, dprintf("[%06lx] %s,%d: LI invalid second PLCI %08lx",
  11020. UnMapId(Id), (char *)(FILE_), __LINE__, plci_b_id));
  11021. PUT_WORD(p_result, _WRONG_IDENTIFIER);
  11022. return (NULL);
  11023. }
  11024. plci_b = &(adapter[ctlr_b - 1].plci[((plci_b_id >> 8) & 0xff) - 1]);
  11025. if (!plci_b->State
  11026. || !plci_b->NL.Id || plci_b->nl_remove_id
  11027. || (plci_b->li_bchannel_id == 0)
  11028. || (li_config_table[plci_b->adapter->li_base + (plci_b->li_bchannel_id - 1)].plci != plci_b))
  11029. {
  11030. dbug(1, dprintf("[%06lx] %s,%d: LI peer in wrong state %08lx",
  11031. UnMapId(Id), (char *)(FILE_), __LINE__, plci_b_id));
  11032. PUT_WORD(p_result, _WRONG_STATE);
  11033. return (NULL);
  11034. }
  11035. if (((byte)(plci_b_id & ~EXT_CONTROLLER)) !=
  11036. ((byte)(UnMapController(plci->adapter->Id) & ~EXT_CONTROLLER))
  11037. && (!(plci->adapter->manufacturer_features & MANUFACTURER_FEATURE_XCONNECT)
  11038. || !(plci_b->adapter->manufacturer_features & MANUFACTURER_FEATURE_XCONNECT)))
  11039. {
  11040. dbug(1, dprintf("[%06lx] %s,%d: LI not on same ctrl %08lx",
  11041. UnMapId(Id), (char *)(FILE_), __LINE__, plci_b_id));
  11042. PUT_WORD(p_result, _WRONG_IDENTIFIER);
  11043. return (NULL);
  11044. }
  11045. if (!(get_b1_facilities(plci_b, add_b1_facilities(plci_b, plci_b->B1_resource,
  11046. (word)(plci_b->B1_facilities | B1_FACILITY_MIXER))) & B1_FACILITY_MIXER))
  11047. {
  11048. dbug(1, dprintf("[%06lx] %s,%d: Interconnect peer cannot mix %d",
  11049. UnMapId(Id), (char *)(FILE_), __LINE__, plci_b->B1_resource));
  11050. PUT_WORD(p_result, _WRONG_STATE);
  11051. return (NULL);
  11052. }
  11053. return (plci_b);
  11054. }
  11055. static byte mixer_request(dword Id, word Number, DIVA_CAPI_ADAPTER *a, PLCI *plci, APPL *appl, API_PARSE *msg)
  11056. {
  11057. word Info;
  11058. word i;
  11059. dword d, li_flags, plci_b_id;
  11060. PLCI *plci_b;
  11061. API_PARSE li_parms[3];
  11062. API_PARSE li_req_parms[3];
  11063. API_PARSE li_participant_struct[2];
  11064. API_PARSE li_participant_parms[3];
  11065. word participant_parms_pos;
  11066. byte result_buffer[32];
  11067. byte *result;
  11068. word result_pos;
  11069. word plci_b_write_pos;
  11070. dbug(1, dprintf("[%06lx] %s,%d: mixer_request",
  11071. UnMapId(Id), (char *)(FILE_), __LINE__));
  11072. Info = GOOD;
  11073. result = result_buffer;
  11074. result_buffer[0] = 0;
  11075. if (!(a->profile.Global_Options & GL_LINE_INTERCONNECT_SUPPORTED))
  11076. {
  11077. dbug(1, dprintf("[%06lx] %s,%d: Facility not supported",
  11078. UnMapId(Id), (char *)(FILE_), __LINE__));
  11079. Info = _FACILITY_NOT_SUPPORTED;
  11080. }
  11081. else if (api_parse(&msg[1].info[1], msg[1].length, "ws", li_parms))
  11082. {
  11083. dbug(1, dprintf("[%06lx] %s,%d: Wrong message format",
  11084. UnMapId(Id), (char *)(FILE_), __LINE__));
  11085. Info = _WRONG_MESSAGE_FORMAT;
  11086. }
  11087. else
  11088. {
  11089. result_buffer[0] = 3;
  11090. PUT_WORD(&result_buffer[1], GET_WORD(li_parms[0].info));
  11091. result_buffer[3] = 0;
  11092. switch (GET_WORD(li_parms[0].info))
  11093. {
  11094. case LI_GET_SUPPORTED_SERVICES:
  11095. if (appl->appl_flags & APPL_FLAG_OLD_LI_SPEC)
  11096. {
  11097. result_buffer[0] = 17;
  11098. result_buffer[3] = 14;
  11099. PUT_WORD(&result_buffer[4], GOOD);
  11100. d = 0;
  11101. if (a->manufacturer_features & MANUFACTURER_FEATURE_MIXER_CH_CH)
  11102. d |= LI_CONFERENCING_SUPPORTED;
  11103. if (a->manufacturer_features & MANUFACTURER_FEATURE_MIXER_CH_PC)
  11104. d |= LI_MONITORING_SUPPORTED;
  11105. if (a->manufacturer_features & MANUFACTURER_FEATURE_MIXER_PC_CH)
  11106. d |= LI_ANNOUNCEMENTS_SUPPORTED | LI_MIXING_SUPPORTED;
  11107. if (a->manufacturer_features & MANUFACTURER_FEATURE_XCONNECT)
  11108. d |= LI_CROSS_CONTROLLER_SUPPORTED;
  11109. PUT_DWORD(&result_buffer[6], d);
  11110. if (a->manufacturer_features & MANUFACTURER_FEATURE_XCONNECT)
  11111. {
  11112. d = 0;
  11113. for (i = 0; i < li_total_channels; i++)
  11114. {
  11115. if ((li_config_table[i].adapter->manufacturer_features & MANUFACTURER_FEATURE_XCONNECT)
  11116. && (li_config_table[i].adapter->li_pri
  11117. || (i < li_config_table[i].adapter->li_base + MIXER_BCHANNELS_BRI)))
  11118. {
  11119. d++;
  11120. }
  11121. }
  11122. }
  11123. else
  11124. {
  11125. d = a->li_pri ? a->li_channels : MIXER_BCHANNELS_BRI;
  11126. }
  11127. PUT_DWORD(&result_buffer[10], d / 2);
  11128. PUT_DWORD(&result_buffer[14], d);
  11129. }
  11130. else
  11131. {
  11132. result_buffer[0] = 25;
  11133. result_buffer[3] = 22;
  11134. PUT_WORD(&result_buffer[4], GOOD);
  11135. d = LI2_ASYMMETRIC_SUPPORTED | LI2_B_LOOPING_SUPPORTED | LI2_X_LOOPING_SUPPORTED;
  11136. if (a->manufacturer_features & MANUFACTURER_FEATURE_MIXER_CH_PC)
  11137. d |= LI2_MONITORING_SUPPORTED | LI2_REMOTE_MONITORING_SUPPORTED;
  11138. if (a->manufacturer_features & MANUFACTURER_FEATURE_MIXER_PC_CH)
  11139. d |= LI2_MIXING_SUPPORTED | LI2_REMOTE_MIXING_SUPPORTED;
  11140. if (a->manufacturer_features & MANUFACTURER_FEATURE_MIXER_PC_PC)
  11141. d |= LI2_PC_LOOPING_SUPPORTED;
  11142. if (a->manufacturer_features & MANUFACTURER_FEATURE_XCONNECT)
  11143. d |= LI2_CROSS_CONTROLLER_SUPPORTED;
  11144. PUT_DWORD(&result_buffer[6], d);
  11145. d = a->li_pri ? a->li_channels : MIXER_BCHANNELS_BRI;
  11146. PUT_DWORD(&result_buffer[10], d / 2);
  11147. PUT_DWORD(&result_buffer[14], d - 1);
  11148. if (a->manufacturer_features & MANUFACTURER_FEATURE_XCONNECT)
  11149. {
  11150. d = 0;
  11151. for (i = 0; i < li_total_channels; i++)
  11152. {
  11153. if ((li_config_table[i].adapter->manufacturer_features & MANUFACTURER_FEATURE_XCONNECT)
  11154. && (li_config_table[i].adapter->li_pri
  11155. || (i < li_config_table[i].adapter->li_base + MIXER_BCHANNELS_BRI)))
  11156. {
  11157. d++;
  11158. }
  11159. }
  11160. }
  11161. PUT_DWORD(&result_buffer[18], d / 2);
  11162. PUT_DWORD(&result_buffer[22], d - 1);
  11163. }
  11164. break;
  11165. case LI_REQ_CONNECT:
  11166. if (li_parms[1].length == 8)
  11167. {
  11168. appl->appl_flags |= APPL_FLAG_OLD_LI_SPEC;
  11169. if (api_parse(&li_parms[1].info[1], li_parms[1].length, "dd", li_req_parms))
  11170. {
  11171. dbug(1, dprintf("[%06lx] %s,%d: Wrong message format",
  11172. UnMapId(Id), (char *)(FILE_), __LINE__));
  11173. Info = _WRONG_MESSAGE_FORMAT;
  11174. break;
  11175. }
  11176. plci_b_id = GET_DWORD(li_req_parms[0].info) & 0xffff;
  11177. li_flags = GET_DWORD(li_req_parms[1].info);
  11178. Info = li_check_main_plci(Id, plci);
  11179. result_buffer[0] = 9;
  11180. result_buffer[3] = 6;
  11181. PUT_DWORD(&result_buffer[4], plci_b_id);
  11182. PUT_WORD(&result_buffer[8], GOOD);
  11183. if (Info != GOOD)
  11184. break;
  11185. result = plci->saved_msg.info;
  11186. for (i = 0; i <= result_buffer[0]; i++)
  11187. result[i] = result_buffer[i];
  11188. plci_b_write_pos = plci->li_plci_b_write_pos;
  11189. plci_b = li_check_plci_b(Id, plci, plci_b_id, plci_b_write_pos, &result[8]);
  11190. if (plci_b == NULL)
  11191. break;
  11192. li_update_connect(Id, a, plci, plci_b_id, true, li_flags);
  11193. plci->li_plci_b_queue[plci_b_write_pos] = plci_b_id | LI_PLCI_B_LAST_FLAG;
  11194. plci_b_write_pos = (plci_b_write_pos == LI_PLCI_B_QUEUE_ENTRIES - 1) ? 0 : plci_b_write_pos + 1;
  11195. plci->li_plci_b_write_pos = plci_b_write_pos;
  11196. }
  11197. else
  11198. {
  11199. appl->appl_flags &= ~APPL_FLAG_OLD_LI_SPEC;
  11200. if (api_parse(&li_parms[1].info[1], li_parms[1].length, "ds", li_req_parms))
  11201. {
  11202. dbug(1, dprintf("[%06lx] %s,%d: Wrong message format",
  11203. UnMapId(Id), (char *)(FILE_), __LINE__));
  11204. Info = _WRONG_MESSAGE_FORMAT;
  11205. break;
  11206. }
  11207. li_flags = GET_DWORD(li_req_parms[0].info) & ~(LI2_FLAG_INTERCONNECT_A_B | LI2_FLAG_INTERCONNECT_B_A);
  11208. Info = li_check_main_plci(Id, plci);
  11209. result_buffer[0] = 7;
  11210. result_buffer[3] = 4;
  11211. PUT_WORD(&result_buffer[4], Info);
  11212. result_buffer[6] = 0;
  11213. if (Info != GOOD)
  11214. break;
  11215. result = plci->saved_msg.info;
  11216. for (i = 0; i <= result_buffer[0]; i++)
  11217. result[i] = result_buffer[i];
  11218. plci_b_write_pos = plci->li_plci_b_write_pos;
  11219. participant_parms_pos = 0;
  11220. result_pos = 7;
  11221. li2_update_connect(Id, a, plci, UnMapId(Id), true, li_flags);
  11222. while (participant_parms_pos < li_req_parms[1].length)
  11223. {
  11224. result[result_pos] = 6;
  11225. result_pos += 7;
  11226. PUT_DWORD(&result[result_pos - 6], 0);
  11227. PUT_WORD(&result[result_pos - 2], GOOD);
  11228. if (api_parse(&li_req_parms[1].info[1 + participant_parms_pos],
  11229. (word)(li_parms[1].length - participant_parms_pos), "s", li_participant_struct))
  11230. {
  11231. dbug(1, dprintf("[%06lx] %s,%d: Wrong message format",
  11232. UnMapId(Id), (char *)(FILE_), __LINE__));
  11233. PUT_WORD(&result[result_pos - 2], _WRONG_MESSAGE_FORMAT);
  11234. break;
  11235. }
  11236. if (api_parse(&li_participant_struct[0].info[1],
  11237. li_participant_struct[0].length, "dd", li_participant_parms))
  11238. {
  11239. dbug(1, dprintf("[%06lx] %s,%d: Wrong message format",
  11240. UnMapId(Id), (char *)(FILE_), __LINE__));
  11241. PUT_WORD(&result[result_pos - 2], _WRONG_MESSAGE_FORMAT);
  11242. break;
  11243. }
  11244. plci_b_id = GET_DWORD(li_participant_parms[0].info) & 0xffff;
  11245. li_flags = GET_DWORD(li_participant_parms[1].info);
  11246. PUT_DWORD(&result[result_pos - 6], plci_b_id);
  11247. if (sizeof(result) - result_pos < 7)
  11248. {
  11249. dbug(1, dprintf("[%06lx] %s,%d: LI result overrun",
  11250. UnMapId(Id), (char *)(FILE_), __LINE__));
  11251. PUT_WORD(&result[result_pos - 2], _WRONG_STATE);
  11252. break;
  11253. }
  11254. plci_b = li2_check_plci_b(Id, plci, plci_b_id, plci_b_write_pos, &result[result_pos - 2]);
  11255. if (plci_b != NULL)
  11256. {
  11257. li2_update_connect(Id, a, plci, plci_b_id, true, li_flags);
  11258. plci->li_plci_b_queue[plci_b_write_pos] = plci_b_id |
  11259. ((li_flags & (LI2_FLAG_INTERCONNECT_A_B | LI2_FLAG_INTERCONNECT_B_A |
  11260. LI2_FLAG_PCCONNECT_A_B | LI2_FLAG_PCCONNECT_B_A)) ? 0 : LI_PLCI_B_DISC_FLAG);
  11261. plci_b_write_pos = (plci_b_write_pos == LI_PLCI_B_QUEUE_ENTRIES - 1) ? 0 : plci_b_write_pos + 1;
  11262. }
  11263. participant_parms_pos = (word)((&li_participant_struct[0].info[1 + li_participant_struct[0].length]) -
  11264. (&li_req_parms[1].info[1]));
  11265. }
  11266. result[0] = (byte)(result_pos - 1);
  11267. result[3] = (byte)(result_pos - 4);
  11268. result[6] = (byte)(result_pos - 7);
  11269. i = (plci_b_write_pos == 0) ? LI_PLCI_B_QUEUE_ENTRIES - 1 : plci_b_write_pos - 1;
  11270. if ((plci_b_write_pos == plci->li_plci_b_read_pos)
  11271. || (plci->li_plci_b_queue[i] & LI_PLCI_B_LAST_FLAG))
  11272. {
  11273. plci->li_plci_b_queue[plci_b_write_pos] = LI_PLCI_B_SKIP_FLAG | LI_PLCI_B_LAST_FLAG;
  11274. plci_b_write_pos = (plci_b_write_pos == LI_PLCI_B_QUEUE_ENTRIES - 1) ? 0 : plci_b_write_pos + 1;
  11275. }
  11276. else
  11277. plci->li_plci_b_queue[i] |= LI_PLCI_B_LAST_FLAG;
  11278. plci->li_plci_b_write_pos = plci_b_write_pos;
  11279. }
  11280. mixer_calculate_coefs(a);
  11281. plci->li_channel_bits = li_config_table[a->li_base + (plci->li_bchannel_id - 1)].channel;
  11282. mixer_notify_update(plci, true);
  11283. sendf(appl, _FACILITY_R | CONFIRM, Id & 0xffffL, Number,
  11284. "wwS", Info, SELECTOR_LINE_INTERCONNECT, result);
  11285. plci->command = 0;
  11286. plci->li_cmd = GET_WORD(li_parms[0].info);
  11287. start_internal_command(Id, plci, mixer_command);
  11288. return (false);
  11289. case LI_REQ_DISCONNECT:
  11290. if (li_parms[1].length == 4)
  11291. {
  11292. appl->appl_flags |= APPL_FLAG_OLD_LI_SPEC;
  11293. if (api_parse(&li_parms[1].info[1], li_parms[1].length, "d", li_req_parms))
  11294. {
  11295. dbug(1, dprintf("[%06lx] %s,%d: Wrong message format",
  11296. UnMapId(Id), (char *)(FILE_), __LINE__));
  11297. Info = _WRONG_MESSAGE_FORMAT;
  11298. break;
  11299. }
  11300. plci_b_id = GET_DWORD(li_req_parms[0].info) & 0xffff;
  11301. Info = li_check_main_plci(Id, plci);
  11302. result_buffer[0] = 9;
  11303. result_buffer[3] = 6;
  11304. PUT_DWORD(&result_buffer[4], GET_DWORD(li_req_parms[0].info));
  11305. PUT_WORD(&result_buffer[8], GOOD);
  11306. if (Info != GOOD)
  11307. break;
  11308. result = plci->saved_msg.info;
  11309. for (i = 0; i <= result_buffer[0]; i++)
  11310. result[i] = result_buffer[i];
  11311. plci_b_write_pos = plci->li_plci_b_write_pos;
  11312. plci_b = li_check_plci_b(Id, plci, plci_b_id, plci_b_write_pos, &result[8]);
  11313. if (plci_b == NULL)
  11314. break;
  11315. li_update_connect(Id, a, plci, plci_b_id, false, 0);
  11316. plci->li_plci_b_queue[plci_b_write_pos] = plci_b_id | LI_PLCI_B_DISC_FLAG | LI_PLCI_B_LAST_FLAG;
  11317. plci_b_write_pos = (plci_b_write_pos == LI_PLCI_B_QUEUE_ENTRIES - 1) ? 0 : plci_b_write_pos + 1;
  11318. plci->li_plci_b_write_pos = plci_b_write_pos;
  11319. }
  11320. else
  11321. {
  11322. appl->appl_flags &= ~APPL_FLAG_OLD_LI_SPEC;
  11323. if (api_parse(&li_parms[1].info[1], li_parms[1].length, "s", li_req_parms))
  11324. {
  11325. dbug(1, dprintf("[%06lx] %s,%d: Wrong message format",
  11326. UnMapId(Id), (char *)(FILE_), __LINE__));
  11327. Info = _WRONG_MESSAGE_FORMAT;
  11328. break;
  11329. }
  11330. Info = li_check_main_plci(Id, plci);
  11331. result_buffer[0] = 7;
  11332. result_buffer[3] = 4;
  11333. PUT_WORD(&result_buffer[4], Info);
  11334. result_buffer[6] = 0;
  11335. if (Info != GOOD)
  11336. break;
  11337. result = plci->saved_msg.info;
  11338. for (i = 0; i <= result_buffer[0]; i++)
  11339. result[i] = result_buffer[i];
  11340. plci_b_write_pos = plci->li_plci_b_write_pos;
  11341. participant_parms_pos = 0;
  11342. result_pos = 7;
  11343. while (participant_parms_pos < li_req_parms[0].length)
  11344. {
  11345. result[result_pos] = 6;
  11346. result_pos += 7;
  11347. PUT_DWORD(&result[result_pos - 6], 0);
  11348. PUT_WORD(&result[result_pos - 2], GOOD);
  11349. if (api_parse(&li_req_parms[0].info[1 + participant_parms_pos],
  11350. (word)(li_parms[1].length - participant_parms_pos), "s", li_participant_struct))
  11351. {
  11352. dbug(1, dprintf("[%06lx] %s,%d: Wrong message format",
  11353. UnMapId(Id), (char *)(FILE_), __LINE__));
  11354. PUT_WORD(&result[result_pos - 2], _WRONG_MESSAGE_FORMAT);
  11355. break;
  11356. }
  11357. if (api_parse(&li_participant_struct[0].info[1],
  11358. li_participant_struct[0].length, "d", li_participant_parms))
  11359. {
  11360. dbug(1, dprintf("[%06lx] %s,%d: Wrong message format",
  11361. UnMapId(Id), (char *)(FILE_), __LINE__));
  11362. PUT_WORD(&result[result_pos - 2], _WRONG_MESSAGE_FORMAT);
  11363. break;
  11364. }
  11365. plci_b_id = GET_DWORD(li_participant_parms[0].info) & 0xffff;
  11366. PUT_DWORD(&result[result_pos - 6], plci_b_id);
  11367. if (sizeof(result) - result_pos < 7)
  11368. {
  11369. dbug(1, dprintf("[%06lx] %s,%d: LI result overrun",
  11370. UnMapId(Id), (char *)(FILE_), __LINE__));
  11371. PUT_WORD(&result[result_pos - 2], _WRONG_STATE);
  11372. break;
  11373. }
  11374. plci_b = li2_check_plci_b(Id, plci, plci_b_id, plci_b_write_pos, &result[result_pos - 2]);
  11375. if (plci_b != NULL)
  11376. {
  11377. li2_update_connect(Id, a, plci, plci_b_id, false, 0);
  11378. plci->li_plci_b_queue[plci_b_write_pos] = plci_b_id | LI_PLCI_B_DISC_FLAG;
  11379. plci_b_write_pos = (plci_b_write_pos == LI_PLCI_B_QUEUE_ENTRIES - 1) ? 0 : plci_b_write_pos + 1;
  11380. }
  11381. participant_parms_pos = (word)((&li_participant_struct[0].info[1 + li_participant_struct[0].length]) -
  11382. (&li_req_parms[0].info[1]));
  11383. }
  11384. result[0] = (byte)(result_pos - 1);
  11385. result[3] = (byte)(result_pos - 4);
  11386. result[6] = (byte)(result_pos - 7);
  11387. i = (plci_b_write_pos == 0) ? LI_PLCI_B_QUEUE_ENTRIES - 1 : plci_b_write_pos - 1;
  11388. if ((plci_b_write_pos == plci->li_plci_b_read_pos)
  11389. || (plci->li_plci_b_queue[i] & LI_PLCI_B_LAST_FLAG))
  11390. {
  11391. plci->li_plci_b_queue[plci_b_write_pos] = LI_PLCI_B_SKIP_FLAG | LI_PLCI_B_LAST_FLAG;
  11392. plci_b_write_pos = (plci_b_write_pos == LI_PLCI_B_QUEUE_ENTRIES - 1) ? 0 : plci_b_write_pos + 1;
  11393. }
  11394. else
  11395. plci->li_plci_b_queue[i] |= LI_PLCI_B_LAST_FLAG;
  11396. plci->li_plci_b_write_pos = plci_b_write_pos;
  11397. }
  11398. mixer_calculate_coefs(a);
  11399. plci->li_channel_bits = li_config_table[a->li_base + (plci->li_bchannel_id - 1)].channel;
  11400. mixer_notify_update(plci, true);
  11401. sendf(appl, _FACILITY_R | CONFIRM, Id & 0xffffL, Number,
  11402. "wwS", Info, SELECTOR_LINE_INTERCONNECT, result);
  11403. plci->command = 0;
  11404. plci->li_cmd = GET_WORD(li_parms[0].info);
  11405. start_internal_command(Id, plci, mixer_command);
  11406. return (false);
  11407. case LI_REQ_SILENT_UPDATE:
  11408. if (!plci || !plci->State
  11409. || !plci->NL.Id || plci->nl_remove_id
  11410. || (plci->li_bchannel_id == 0)
  11411. || (li_config_table[plci->adapter->li_base + (plci->li_bchannel_id - 1)].plci != plci))
  11412. {
  11413. dbug(1, dprintf("[%06lx] %s,%d: Wrong state",
  11414. UnMapId(Id), (char *)(FILE_), __LINE__));
  11415. return (false);
  11416. }
  11417. plci_b_write_pos = plci->li_plci_b_write_pos;
  11418. if (((plci->li_plci_b_read_pos > plci_b_write_pos) ? plci->li_plci_b_read_pos :
  11419. LI_PLCI_B_QUEUE_ENTRIES + plci->li_plci_b_read_pos) - plci_b_write_pos - 1 < 2)
  11420. {
  11421. dbug(1, dprintf("[%06lx] %s,%d: LI request overrun",
  11422. UnMapId(Id), (char *)(FILE_), __LINE__));
  11423. return (false);
  11424. }
  11425. i = (plci_b_write_pos == 0) ? LI_PLCI_B_QUEUE_ENTRIES - 1 : plci_b_write_pos - 1;
  11426. if ((plci_b_write_pos == plci->li_plci_b_read_pos)
  11427. || (plci->li_plci_b_queue[i] & LI_PLCI_B_LAST_FLAG))
  11428. {
  11429. plci->li_plci_b_queue[plci_b_write_pos] = LI_PLCI_B_SKIP_FLAG | LI_PLCI_B_LAST_FLAG;
  11430. plci_b_write_pos = (plci_b_write_pos == LI_PLCI_B_QUEUE_ENTRIES - 1) ? 0 : plci_b_write_pos + 1;
  11431. }
  11432. else
  11433. plci->li_plci_b_queue[i] |= LI_PLCI_B_LAST_FLAG;
  11434. plci->li_plci_b_write_pos = plci_b_write_pos;
  11435. plci->li_channel_bits = li_config_table[a->li_base + (plci->li_bchannel_id - 1)].channel;
  11436. plci->command = 0;
  11437. plci->li_cmd = GET_WORD(li_parms[0].info);
  11438. start_internal_command(Id, plci, mixer_command);
  11439. return (false);
  11440. default:
  11441. dbug(1, dprintf("[%06lx] %s,%d: LI unknown request %04x",
  11442. UnMapId(Id), (char *)(FILE_), __LINE__, GET_WORD(li_parms[0].info)));
  11443. Info = _FACILITY_NOT_SUPPORTED;
  11444. }
  11445. }
  11446. sendf(appl, _FACILITY_R | CONFIRM, Id & 0xffffL, Number,
  11447. "wwS", Info, SELECTOR_LINE_INTERCONNECT, result);
  11448. return (false);
  11449. }
  11450. static void mixer_indication_coefs_set(dword Id, PLCI *plci)
  11451. {
  11452. dword d;
  11453. byte result[12];
  11454. dbug(1, dprintf("[%06lx] %s,%d: mixer_indication_coefs_set",
  11455. UnMapId(Id), (char *)(FILE_), __LINE__));
  11456. if (plci->li_plci_b_read_pos != plci->li_plci_b_req_pos)
  11457. {
  11458. do
  11459. {
  11460. d = plci->li_plci_b_queue[plci->li_plci_b_read_pos];
  11461. if (!(d & LI_PLCI_B_SKIP_FLAG))
  11462. {
  11463. if (plci->appl->appl_flags & APPL_FLAG_OLD_LI_SPEC)
  11464. {
  11465. if (d & LI_PLCI_B_DISC_FLAG)
  11466. {
  11467. result[0] = 5;
  11468. PUT_WORD(&result[1], LI_IND_DISCONNECT);
  11469. result[3] = 2;
  11470. PUT_WORD(&result[4], _LI_USER_INITIATED);
  11471. }
  11472. else
  11473. {
  11474. result[0] = 7;
  11475. PUT_WORD(&result[1], LI_IND_CONNECT_ACTIVE);
  11476. result[3] = 4;
  11477. PUT_DWORD(&result[4], d & ~LI_PLCI_B_FLAG_MASK);
  11478. }
  11479. }
  11480. else
  11481. {
  11482. if (d & LI_PLCI_B_DISC_FLAG)
  11483. {
  11484. result[0] = 9;
  11485. PUT_WORD(&result[1], LI_IND_DISCONNECT);
  11486. result[3] = 6;
  11487. PUT_DWORD(&result[4], d & ~LI_PLCI_B_FLAG_MASK);
  11488. PUT_WORD(&result[8], _LI_USER_INITIATED);
  11489. }
  11490. else
  11491. {
  11492. result[0] = 7;
  11493. PUT_WORD(&result[1], LI_IND_CONNECT_ACTIVE);
  11494. result[3] = 4;
  11495. PUT_DWORD(&result[4], d & ~LI_PLCI_B_FLAG_MASK);
  11496. }
  11497. }
  11498. sendf(plci->appl, _FACILITY_I, Id & 0xffffL, 0,
  11499. "ws", SELECTOR_LINE_INTERCONNECT, result);
  11500. }
  11501. plci->li_plci_b_read_pos = (plci->li_plci_b_read_pos == LI_PLCI_B_QUEUE_ENTRIES - 1) ?
  11502. 0 : plci->li_plci_b_read_pos + 1;
  11503. } while (!(d & LI_PLCI_B_LAST_FLAG) && (plci->li_plci_b_read_pos != plci->li_plci_b_req_pos));
  11504. }
  11505. }
  11506. static void mixer_indication_xconnect_from(dword Id, PLCI *plci, byte *msg, word length)
  11507. {
  11508. word i, j, ch;
  11509. struct xconnect_transfer_address_s s, *p;
  11510. DIVA_CAPI_ADAPTER *a;
  11511. dbug(1, dprintf("[%06lx] %s,%d: mixer_indication_xconnect_from %d",
  11512. UnMapId(Id), (char *)(FILE_), __LINE__, (int)length));
  11513. a = plci->adapter;
  11514. i = 1;
  11515. for (i = 1; i < length; i += 16)
  11516. {
  11517. s.card_address.low = msg[i] | (msg[i + 1] << 8) | (((dword)(msg[i + 2])) << 16) | (((dword)(msg[i + 3])) << 24);
  11518. s.card_address.high = msg[i + 4] | (msg[i + 5] << 8) | (((dword)(msg[i + 6])) << 16) | (((dword)(msg[i + 7])) << 24);
  11519. s.offset = msg[i + 8] | (msg[i + 9] << 8) | (((dword)(msg[i + 10])) << 16) | (((dword)(msg[i + 11])) << 24);
  11520. ch = msg[i + 12] | (msg[i + 13] << 8);
  11521. j = ch & XCONNECT_CHANNEL_NUMBER_MASK;
  11522. if (!a->li_pri && (plci->li_bchannel_id == 2))
  11523. j = 1 - j;
  11524. j += a->li_base;
  11525. if (ch & XCONNECT_CHANNEL_PORT_PC)
  11526. p = &(li_config_table[j].send_pc);
  11527. else
  11528. p = &(li_config_table[j].send_b);
  11529. p->card_address.low = s.card_address.low;
  11530. p->card_address.high = s.card_address.high;
  11531. p->offset = s.offset;
  11532. li_config_table[j].channel |= LI_CHANNEL_ADDRESSES_SET;
  11533. }
  11534. if (plci->internal_command_queue[0]
  11535. && ((plci->adjust_b_state == ADJUST_B_RESTORE_MIXER_2)
  11536. || (plci->adjust_b_state == ADJUST_B_RESTORE_MIXER_3)
  11537. || (plci->adjust_b_state == ADJUST_B_RESTORE_MIXER_4)))
  11538. {
  11539. (*(plci->internal_command_queue[0]))(Id, plci, 0);
  11540. if (!plci->internal_command)
  11541. next_internal_command(Id, plci);
  11542. }
  11543. mixer_notify_update(plci, true);
  11544. }
  11545. static void mixer_indication_xconnect_to(dword Id, PLCI *plci, byte *msg, word length)
  11546. {
  11547. dbug(1, dprintf("[%06lx] %s,%d: mixer_indication_xconnect_to %d",
  11548. UnMapId(Id), (char *)(FILE_), __LINE__, (int) length));
  11549. }
  11550. static byte mixer_notify_source_removed(PLCI *plci, dword plci_b_id)
  11551. {
  11552. word plci_b_write_pos;
  11553. plci_b_write_pos = plci->li_plci_b_write_pos;
  11554. if (((plci->li_plci_b_read_pos > plci_b_write_pos) ? plci->li_plci_b_read_pos :
  11555. LI_PLCI_B_QUEUE_ENTRIES + plci->li_plci_b_read_pos) - plci_b_write_pos - 1 < 1)
  11556. {
  11557. dbug(1, dprintf("[%06lx] %s,%d: LI request overrun",
  11558. (dword)((plci->Id << 8) | UnMapController(plci->adapter->Id)),
  11559. (char *)(FILE_), __LINE__));
  11560. return (false);
  11561. }
  11562. plci->li_plci_b_queue[plci_b_write_pos] = plci_b_id | LI_PLCI_B_DISC_FLAG;
  11563. plci_b_write_pos = (plci_b_write_pos == LI_PLCI_B_QUEUE_ENTRIES - 1) ? 0 : plci_b_write_pos + 1;
  11564. plci->li_plci_b_write_pos = plci_b_write_pos;
  11565. return (true);
  11566. }
  11567. static void mixer_remove(PLCI *plci)
  11568. {
  11569. DIVA_CAPI_ADAPTER *a;
  11570. PLCI *notify_plci;
  11571. dword plci_b_id;
  11572. word i, j;
  11573. dbug(1, dprintf("[%06lx] %s,%d: mixer_remove",
  11574. (dword)((plci->Id << 8) | UnMapController(plci->adapter->Id)),
  11575. (char *)(FILE_), __LINE__));
  11576. a = plci->adapter;
  11577. plci_b_id = (plci->Id << 8) | UnMapController(plci->adapter->Id);
  11578. if (a->profile.Global_Options & GL_LINE_INTERCONNECT_SUPPORTED)
  11579. {
  11580. if ((plci->li_bchannel_id != 0)
  11581. && (li_config_table[a->li_base + (plci->li_bchannel_id - 1)].plci == plci))
  11582. {
  11583. i = a->li_base + (plci->li_bchannel_id - 1);
  11584. if ((li_config_table[i].curchnl | li_config_table[i].channel) & LI_CHANNEL_INVOLVED)
  11585. {
  11586. for (j = 0; j < li_total_channels; j++)
  11587. {
  11588. if ((li_config_table[i].flag_table[j] & LI_FLAG_INTERCONNECT)
  11589. || (li_config_table[j].flag_table[i] & LI_FLAG_INTERCONNECT))
  11590. {
  11591. notify_plci = li_config_table[j].plci;
  11592. if ((notify_plci != NULL)
  11593. && (notify_plci != plci)
  11594. && (notify_plci->appl != NULL)
  11595. && !(notify_plci->appl->appl_flags & APPL_FLAG_OLD_LI_SPEC)
  11596. && (notify_plci->State)
  11597. && notify_plci->NL.Id && !notify_plci->nl_remove_id)
  11598. {
  11599. mixer_notify_source_removed(notify_plci, plci_b_id);
  11600. }
  11601. }
  11602. }
  11603. mixer_clear_config(plci);
  11604. mixer_calculate_coefs(a);
  11605. mixer_notify_update(plci, true);
  11606. }
  11607. li_config_table[i].plci = NULL;
  11608. plci->li_bchannel_id = 0;
  11609. }
  11610. }
  11611. }
  11612. /*------------------------------------------------------------------*/
  11613. /* Echo canceller facilities */
  11614. /*------------------------------------------------------------------*/
  11615. static void ec_write_parameters(PLCI *plci)
  11616. {
  11617. word w;
  11618. byte parameter_buffer[6];
  11619. dbug(1, dprintf("[%06lx] %s,%d: ec_write_parameters",
  11620. (dword)((plci->Id << 8) | UnMapController(plci->adapter->Id)),
  11621. (char *)(FILE_), __LINE__));
  11622. parameter_buffer[0] = 5;
  11623. parameter_buffer[1] = DSP_CTRL_SET_LEC_PARAMETERS;
  11624. PUT_WORD(&parameter_buffer[2], plci->ec_idi_options);
  11625. plci->ec_idi_options &= ~LEC_RESET_COEFFICIENTS;
  11626. w = (plci->ec_tail_length == 0) ? 128 : plci->ec_tail_length;
  11627. PUT_WORD(&parameter_buffer[4], w);
  11628. add_p(plci, FTY, parameter_buffer);
  11629. sig_req(plci, TEL_CTRL, 0);
  11630. send_req(plci);
  11631. }
  11632. static void ec_clear_config(PLCI *plci)
  11633. {
  11634. dbug(1, dprintf("[%06lx] %s,%d: ec_clear_config",
  11635. (dword)((plci->Id << 8) | UnMapController(plci->adapter->Id)),
  11636. (char *)(FILE_), __LINE__));
  11637. plci->ec_idi_options = LEC_ENABLE_ECHO_CANCELLER |
  11638. LEC_MANUAL_DISABLE | LEC_ENABLE_NONLINEAR_PROCESSING;
  11639. plci->ec_tail_length = 0;
  11640. }
  11641. static void ec_prepare_switch(dword Id, PLCI *plci)
  11642. {
  11643. dbug(1, dprintf("[%06lx] %s,%d: ec_prepare_switch",
  11644. UnMapId(Id), (char *)(FILE_), __LINE__));
  11645. }
  11646. static word ec_save_config(dword Id, PLCI *plci, byte Rc)
  11647. {
  11648. dbug(1, dprintf("[%06lx] %s,%d: ec_save_config %02x %d",
  11649. UnMapId(Id), (char *)(FILE_), __LINE__, Rc, plci->adjust_b_state));
  11650. return (GOOD);
  11651. }
  11652. static word ec_restore_config(dword Id, PLCI *plci, byte Rc)
  11653. {
  11654. word Info;
  11655. dbug(1, dprintf("[%06lx] %s,%d: ec_restore_config %02x %d",
  11656. UnMapId(Id), (char *)(FILE_), __LINE__, Rc, plci->adjust_b_state));
  11657. Info = GOOD;
  11658. if (plci->B1_facilities & B1_FACILITY_EC)
  11659. {
  11660. switch (plci->adjust_b_state)
  11661. {
  11662. case ADJUST_B_RESTORE_EC_1:
  11663. plci->internal_command = plci->adjust_b_command;
  11664. if (plci->sig_req)
  11665. {
  11666. plci->adjust_b_state = ADJUST_B_RESTORE_EC_1;
  11667. break;
  11668. }
  11669. ec_write_parameters(plci);
  11670. plci->adjust_b_state = ADJUST_B_RESTORE_EC_2;
  11671. break;
  11672. case ADJUST_B_RESTORE_EC_2:
  11673. if ((Rc != OK) && (Rc != OK_FC))
  11674. {
  11675. dbug(1, dprintf("[%06lx] %s,%d: Restore EC failed %02x",
  11676. UnMapId(Id), (char *)(FILE_), __LINE__, Rc));
  11677. Info = _WRONG_STATE;
  11678. break;
  11679. }
  11680. break;
  11681. }
  11682. }
  11683. return (Info);
  11684. }
  11685. static void ec_command(dword Id, PLCI *plci, byte Rc)
  11686. {
  11687. word internal_command, Info;
  11688. byte result[8];
  11689. dbug(1, dprintf("[%06lx] %s,%d: ec_command %02x %04x %04x %04x %d",
  11690. UnMapId(Id), (char *)(FILE_), __LINE__, Rc, plci->internal_command,
  11691. plci->ec_cmd, plci->ec_idi_options, plci->ec_tail_length));
  11692. Info = GOOD;
  11693. if (plci->appl->appl_flags & APPL_FLAG_PRIV_EC_SPEC)
  11694. {
  11695. result[0] = 2;
  11696. PUT_WORD(&result[1], EC_SUCCESS);
  11697. }
  11698. else
  11699. {
  11700. result[0] = 5;
  11701. PUT_WORD(&result[1], plci->ec_cmd);
  11702. result[3] = 2;
  11703. PUT_WORD(&result[4], GOOD);
  11704. }
  11705. internal_command = plci->internal_command;
  11706. plci->internal_command = 0;
  11707. switch (plci->ec_cmd)
  11708. {
  11709. case EC_ENABLE_OPERATION:
  11710. case EC_FREEZE_COEFFICIENTS:
  11711. case EC_RESUME_COEFFICIENT_UPDATE:
  11712. case EC_RESET_COEFFICIENTS:
  11713. switch (internal_command)
  11714. {
  11715. default:
  11716. adjust_b1_resource(Id, plci, NULL, (word)(plci->B1_facilities |
  11717. B1_FACILITY_EC), EC_COMMAND_1);
  11718. case EC_COMMAND_1:
  11719. if (adjust_b_process(Id, plci, Rc) != GOOD)
  11720. {
  11721. dbug(1, dprintf("[%06lx] %s,%d: Load EC failed",
  11722. UnMapId(Id), (char *)(FILE_), __LINE__));
  11723. Info = _FACILITY_NOT_SUPPORTED;
  11724. break;
  11725. }
  11726. if (plci->internal_command)
  11727. return;
  11728. case EC_COMMAND_2:
  11729. if (plci->sig_req)
  11730. {
  11731. plci->internal_command = EC_COMMAND_2;
  11732. return;
  11733. }
  11734. plci->internal_command = EC_COMMAND_3;
  11735. ec_write_parameters(plci);
  11736. return;
  11737. case EC_COMMAND_3:
  11738. if ((Rc != OK) && (Rc != OK_FC))
  11739. {
  11740. dbug(1, dprintf("[%06lx] %s,%d: Enable EC failed %02x",
  11741. UnMapId(Id), (char *)(FILE_), __LINE__, Rc));
  11742. Info = _FACILITY_NOT_SUPPORTED;
  11743. break;
  11744. }
  11745. break;
  11746. }
  11747. break;
  11748. case EC_DISABLE_OPERATION:
  11749. switch (internal_command)
  11750. {
  11751. default:
  11752. case EC_COMMAND_1:
  11753. if (plci->B1_facilities & B1_FACILITY_EC)
  11754. {
  11755. if (plci->sig_req)
  11756. {
  11757. plci->internal_command = EC_COMMAND_1;
  11758. return;
  11759. }
  11760. plci->internal_command = EC_COMMAND_2;
  11761. ec_write_parameters(plci);
  11762. return;
  11763. }
  11764. Rc = OK;
  11765. case EC_COMMAND_2:
  11766. if ((Rc != OK) && (Rc != OK_FC))
  11767. {
  11768. dbug(1, dprintf("[%06lx] %s,%d: Disable EC failed %02x",
  11769. UnMapId(Id), (char *)(FILE_), __LINE__, Rc));
  11770. Info = _FACILITY_NOT_SUPPORTED;
  11771. break;
  11772. }
  11773. adjust_b1_resource(Id, plci, NULL, (word)(plci->B1_facilities &
  11774. ~B1_FACILITY_EC), EC_COMMAND_3);
  11775. case EC_COMMAND_3:
  11776. if (adjust_b_process(Id, plci, Rc) != GOOD)
  11777. {
  11778. dbug(1, dprintf("[%06lx] %s,%d: Unload EC failed",
  11779. UnMapId(Id), (char *)(FILE_), __LINE__));
  11780. Info = _FACILITY_NOT_SUPPORTED;
  11781. break;
  11782. }
  11783. if (plci->internal_command)
  11784. return;
  11785. break;
  11786. }
  11787. break;
  11788. }
  11789. sendf(plci->appl, _FACILITY_R | CONFIRM, Id & 0xffffL, plci->number,
  11790. "wws", Info, (plci->appl->appl_flags & APPL_FLAG_PRIV_EC_SPEC) ?
  11791. PRIV_SELECTOR_ECHO_CANCELLER : SELECTOR_ECHO_CANCELLER, result);
  11792. }
  11793. static byte ec_request(dword Id, word Number, DIVA_CAPI_ADAPTER *a, PLCI *plci, APPL *appl, API_PARSE *msg)
  11794. {
  11795. word Info;
  11796. word opt;
  11797. API_PARSE ec_parms[3];
  11798. byte result[16];
  11799. dbug(1, dprintf("[%06lx] %s,%d: ec_request",
  11800. UnMapId(Id), (char *)(FILE_), __LINE__));
  11801. Info = GOOD;
  11802. result[0] = 0;
  11803. if (!(a->man_profile.private_options & (1L << PRIVATE_ECHO_CANCELLER)))
  11804. {
  11805. dbug(1, dprintf("[%06lx] %s,%d: Facility not supported",
  11806. UnMapId(Id), (char *)(FILE_), __LINE__));
  11807. Info = _FACILITY_NOT_SUPPORTED;
  11808. }
  11809. else
  11810. {
  11811. if (appl->appl_flags & APPL_FLAG_PRIV_EC_SPEC)
  11812. {
  11813. if (api_parse(&msg[1].info[1], msg[1].length, "w", ec_parms))
  11814. {
  11815. dbug(1, dprintf("[%06lx] %s,%d: Wrong message format",
  11816. UnMapId(Id), (char *)(FILE_), __LINE__));
  11817. Info = _WRONG_MESSAGE_FORMAT;
  11818. }
  11819. else
  11820. {
  11821. if (plci == NULL)
  11822. {
  11823. dbug(1, dprintf("[%06lx] %s,%d: Wrong PLCI",
  11824. UnMapId(Id), (char *)(FILE_), __LINE__));
  11825. Info = _WRONG_IDENTIFIER;
  11826. }
  11827. else if (!plci->State || !plci->NL.Id || plci->nl_remove_id)
  11828. {
  11829. dbug(1, dprintf("[%06lx] %s,%d: Wrong state",
  11830. UnMapId(Id), (char *)(FILE_), __LINE__));
  11831. Info = _WRONG_STATE;
  11832. }
  11833. else
  11834. {
  11835. plci->command = 0;
  11836. plci->ec_cmd = GET_WORD(ec_parms[0].info);
  11837. plci->ec_idi_options &= ~(LEC_MANUAL_DISABLE | LEC_RESET_COEFFICIENTS);
  11838. result[0] = 2;
  11839. PUT_WORD(&result[1], EC_SUCCESS);
  11840. if (msg[1].length >= 4)
  11841. {
  11842. opt = GET_WORD(&ec_parms[0].info[2]);
  11843. plci->ec_idi_options &= ~(LEC_ENABLE_NONLINEAR_PROCESSING |
  11844. LEC_ENABLE_2100HZ_DETECTOR | LEC_REQUIRE_2100HZ_REVERSALS);
  11845. if (!(opt & EC_DISABLE_NON_LINEAR_PROCESSING))
  11846. plci->ec_idi_options |= LEC_ENABLE_NONLINEAR_PROCESSING;
  11847. if (opt & EC_DETECT_DISABLE_TONE)
  11848. plci->ec_idi_options |= LEC_ENABLE_2100HZ_DETECTOR;
  11849. if (!(opt & EC_DO_NOT_REQUIRE_REVERSALS))
  11850. plci->ec_idi_options |= LEC_REQUIRE_2100HZ_REVERSALS;
  11851. if (msg[1].length >= 6)
  11852. {
  11853. plci->ec_tail_length = GET_WORD(&ec_parms[0].info[4]);
  11854. }
  11855. }
  11856. switch (plci->ec_cmd)
  11857. {
  11858. case EC_ENABLE_OPERATION:
  11859. plci->ec_idi_options &= ~LEC_FREEZE_COEFFICIENTS;
  11860. start_internal_command(Id, plci, ec_command);
  11861. return (false);
  11862. case EC_DISABLE_OPERATION:
  11863. plci->ec_idi_options = LEC_ENABLE_ECHO_CANCELLER |
  11864. LEC_MANUAL_DISABLE | LEC_ENABLE_NONLINEAR_PROCESSING |
  11865. LEC_RESET_COEFFICIENTS;
  11866. start_internal_command(Id, plci, ec_command);
  11867. return (false);
  11868. case EC_FREEZE_COEFFICIENTS:
  11869. plci->ec_idi_options |= LEC_FREEZE_COEFFICIENTS;
  11870. start_internal_command(Id, plci, ec_command);
  11871. return (false);
  11872. case EC_RESUME_COEFFICIENT_UPDATE:
  11873. plci->ec_idi_options &= ~LEC_FREEZE_COEFFICIENTS;
  11874. start_internal_command(Id, plci, ec_command);
  11875. return (false);
  11876. case EC_RESET_COEFFICIENTS:
  11877. plci->ec_idi_options |= LEC_RESET_COEFFICIENTS;
  11878. start_internal_command(Id, plci, ec_command);
  11879. return (false);
  11880. default:
  11881. dbug(1, dprintf("[%06lx] %s,%d: EC unknown request %04x",
  11882. UnMapId(Id), (char *)(FILE_), __LINE__, plci->ec_cmd));
  11883. PUT_WORD(&result[1], EC_UNSUPPORTED_OPERATION);
  11884. }
  11885. }
  11886. }
  11887. }
  11888. else
  11889. {
  11890. if (api_parse(&msg[1].info[1], msg[1].length, "ws", ec_parms))
  11891. {
  11892. dbug(1, dprintf("[%06lx] %s,%d: Wrong message format",
  11893. UnMapId(Id), (char *)(FILE_), __LINE__));
  11894. Info = _WRONG_MESSAGE_FORMAT;
  11895. }
  11896. else
  11897. {
  11898. if (GET_WORD(ec_parms[0].info) == EC_GET_SUPPORTED_SERVICES)
  11899. {
  11900. result[0] = 11;
  11901. PUT_WORD(&result[1], EC_GET_SUPPORTED_SERVICES);
  11902. result[3] = 8;
  11903. PUT_WORD(&result[4], GOOD);
  11904. PUT_WORD(&result[6], 0x0007);
  11905. PUT_WORD(&result[8], LEC_MAX_SUPPORTED_TAIL_LENGTH);
  11906. PUT_WORD(&result[10], 0);
  11907. }
  11908. else if (plci == NULL)
  11909. {
  11910. dbug(1, dprintf("[%06lx] %s,%d: Wrong PLCI",
  11911. UnMapId(Id), (char *)(FILE_), __LINE__));
  11912. Info = _WRONG_IDENTIFIER;
  11913. }
  11914. else if (!plci->State || !plci->NL.Id || plci->nl_remove_id)
  11915. {
  11916. dbug(1, dprintf("[%06lx] %s,%d: Wrong state",
  11917. UnMapId(Id), (char *)(FILE_), __LINE__));
  11918. Info = _WRONG_STATE;
  11919. }
  11920. else
  11921. {
  11922. plci->command = 0;
  11923. plci->ec_cmd = GET_WORD(ec_parms[0].info);
  11924. plci->ec_idi_options &= ~(LEC_MANUAL_DISABLE | LEC_RESET_COEFFICIENTS);
  11925. result[0] = 5;
  11926. PUT_WORD(&result[1], plci->ec_cmd);
  11927. result[3] = 2;
  11928. PUT_WORD(&result[4], GOOD);
  11929. plci->ec_idi_options &= ~(LEC_ENABLE_NONLINEAR_PROCESSING |
  11930. LEC_ENABLE_2100HZ_DETECTOR | LEC_REQUIRE_2100HZ_REVERSALS);
  11931. plci->ec_tail_length = 0;
  11932. if (ec_parms[1].length >= 2)
  11933. {
  11934. opt = GET_WORD(&ec_parms[1].info[1]);
  11935. if (opt & EC_ENABLE_NON_LINEAR_PROCESSING)
  11936. plci->ec_idi_options |= LEC_ENABLE_NONLINEAR_PROCESSING;
  11937. if (opt & EC_DETECT_DISABLE_TONE)
  11938. plci->ec_idi_options |= LEC_ENABLE_2100HZ_DETECTOR;
  11939. if (!(opt & EC_DO_NOT_REQUIRE_REVERSALS))
  11940. plci->ec_idi_options |= LEC_REQUIRE_2100HZ_REVERSALS;
  11941. if (ec_parms[1].length >= 4)
  11942. {
  11943. plci->ec_tail_length = GET_WORD(&ec_parms[1].info[3]);
  11944. }
  11945. }
  11946. switch (plci->ec_cmd)
  11947. {
  11948. case EC_ENABLE_OPERATION:
  11949. plci->ec_idi_options &= ~LEC_FREEZE_COEFFICIENTS;
  11950. start_internal_command(Id, plci, ec_command);
  11951. return (false);
  11952. case EC_DISABLE_OPERATION:
  11953. plci->ec_idi_options = LEC_ENABLE_ECHO_CANCELLER |
  11954. LEC_MANUAL_DISABLE | LEC_ENABLE_NONLINEAR_PROCESSING |
  11955. LEC_RESET_COEFFICIENTS;
  11956. start_internal_command(Id, plci, ec_command);
  11957. return (false);
  11958. default:
  11959. dbug(1, dprintf("[%06lx] %s,%d: EC unknown request %04x",
  11960. UnMapId(Id), (char *)(FILE_), __LINE__, plci->ec_cmd));
  11961. PUT_WORD(&result[4], _FACILITY_SPECIFIC_FUNCTION_NOT_SUPP);
  11962. }
  11963. }
  11964. }
  11965. }
  11966. }
  11967. sendf(appl, _FACILITY_R | CONFIRM, Id & 0xffffL, Number,
  11968. "wws", Info, (appl->appl_flags & APPL_FLAG_PRIV_EC_SPEC) ?
  11969. PRIV_SELECTOR_ECHO_CANCELLER : SELECTOR_ECHO_CANCELLER, result);
  11970. return (false);
  11971. }
  11972. static void ec_indication(dword Id, PLCI *plci, byte *msg, word length)
  11973. {
  11974. byte result[8];
  11975. dbug(1, dprintf("[%06lx] %s,%d: ec_indication",
  11976. UnMapId(Id), (char *)(FILE_), __LINE__));
  11977. if (!(plci->ec_idi_options & LEC_MANUAL_DISABLE))
  11978. {
  11979. if (plci->appl->appl_flags & APPL_FLAG_PRIV_EC_SPEC)
  11980. {
  11981. result[0] = 2;
  11982. PUT_WORD(&result[1], 0);
  11983. switch (msg[1])
  11984. {
  11985. case LEC_DISABLE_TYPE_CONTIGNUOUS_2100HZ:
  11986. PUT_WORD(&result[1], EC_BYPASS_DUE_TO_CONTINUOUS_2100HZ);
  11987. break;
  11988. case LEC_DISABLE_TYPE_REVERSED_2100HZ:
  11989. PUT_WORD(&result[1], EC_BYPASS_DUE_TO_REVERSED_2100HZ);
  11990. break;
  11991. case LEC_DISABLE_RELEASED:
  11992. PUT_WORD(&result[1], EC_BYPASS_RELEASED);
  11993. break;
  11994. }
  11995. }
  11996. else
  11997. {
  11998. result[0] = 5;
  11999. PUT_WORD(&result[1], EC_BYPASS_INDICATION);
  12000. result[3] = 2;
  12001. PUT_WORD(&result[4], 0);
  12002. switch (msg[1])
  12003. {
  12004. case LEC_DISABLE_TYPE_CONTIGNUOUS_2100HZ:
  12005. PUT_WORD(&result[4], EC_BYPASS_DUE_TO_CONTINUOUS_2100HZ);
  12006. break;
  12007. case LEC_DISABLE_TYPE_REVERSED_2100HZ:
  12008. PUT_WORD(&result[4], EC_BYPASS_DUE_TO_REVERSED_2100HZ);
  12009. break;
  12010. case LEC_DISABLE_RELEASED:
  12011. PUT_WORD(&result[4], EC_BYPASS_RELEASED);
  12012. break;
  12013. }
  12014. }
  12015. sendf(plci->appl, _FACILITY_I, Id & 0xffffL, 0, "ws", (plci->appl->appl_flags & APPL_FLAG_PRIV_EC_SPEC) ?
  12016. PRIV_SELECTOR_ECHO_CANCELLER : SELECTOR_ECHO_CANCELLER, result);
  12017. }
  12018. }
  12019. /*------------------------------------------------------------------*/
  12020. /* Advanced voice */
  12021. /*------------------------------------------------------------------*/
  12022. static void adv_voice_write_coefs(PLCI *plci, word write_command)
  12023. {
  12024. DIVA_CAPI_ADAPTER *a;
  12025. word i;
  12026. byte *p;
  12027. word w, n, j, k;
  12028. byte ch_map[MIXER_CHANNELS_BRI];
  12029. byte coef_buffer[ADV_VOICE_COEF_BUFFER_SIZE + 2];
  12030. dbug(1, dprintf("[%06lx] %s,%d: adv_voice_write_coefs %d",
  12031. (dword)((plci->Id << 8) | UnMapController(plci->adapter->Id)),
  12032. (char *)(FILE_), __LINE__, write_command));
  12033. a = plci->adapter;
  12034. p = coef_buffer + 1;
  12035. *(p++) = DSP_CTRL_OLD_SET_MIXER_COEFFICIENTS;
  12036. i = 0;
  12037. while (i + sizeof(word) <= a->adv_voice_coef_length)
  12038. {
  12039. PUT_WORD(p, GET_WORD(a->adv_voice_coef_buffer + i));
  12040. p += 2;
  12041. i += 2;
  12042. }
  12043. while (i < ADV_VOICE_OLD_COEF_COUNT * sizeof(word))
  12044. {
  12045. PUT_WORD(p, 0x8000);
  12046. p += 2;
  12047. i += 2;
  12048. }
  12049. if (!a->li_pri && (plci->li_bchannel_id == 0))
  12050. {
  12051. if ((li_config_table[a->li_base].plci == NULL) && (li_config_table[a->li_base + 1].plci != NULL))
  12052. {
  12053. plci->li_bchannel_id = 1;
  12054. li_config_table[a->li_base].plci = plci;
  12055. dbug(1, dprintf("[%06lx] %s,%d: adv_voice_set_bchannel_id %d",
  12056. (dword)((plci->Id << 8) | UnMapController(plci->adapter->Id)),
  12057. (char *)(FILE_), __LINE__, plci->li_bchannel_id));
  12058. }
  12059. else if ((li_config_table[a->li_base].plci != NULL) && (li_config_table[a->li_base + 1].plci == NULL))
  12060. {
  12061. plci->li_bchannel_id = 2;
  12062. li_config_table[a->li_base + 1].plci = plci;
  12063. dbug(1, dprintf("[%06lx] %s,%d: adv_voice_set_bchannel_id %d",
  12064. (dword)((plci->Id << 8) | UnMapController(plci->adapter->Id)),
  12065. (char *)(FILE_), __LINE__, plci->li_bchannel_id));
  12066. }
  12067. }
  12068. if (!a->li_pri && (plci->li_bchannel_id != 0)
  12069. && (li_config_table[a->li_base + (plci->li_bchannel_id - 1)].plci == plci))
  12070. {
  12071. i = a->li_base + (plci->li_bchannel_id - 1);
  12072. switch (write_command)
  12073. {
  12074. case ADV_VOICE_WRITE_ACTIVATION:
  12075. j = a->li_base + MIXER_IC_CHANNEL_BASE + (plci->li_bchannel_id - 1);
  12076. k = a->li_base + MIXER_IC_CHANNEL_BASE + (2 - plci->li_bchannel_id);
  12077. if (!(plci->B1_facilities & B1_FACILITY_MIXER))
  12078. {
  12079. li_config_table[j].flag_table[i] |= LI_FLAG_CONFERENCE | LI_FLAG_MIX;
  12080. li_config_table[i].flag_table[j] |= LI_FLAG_CONFERENCE | LI_FLAG_MONITOR;
  12081. }
  12082. if (a->manufacturer_features & MANUFACTURER_FEATURE_SLAVE_CODEC)
  12083. {
  12084. li_config_table[k].flag_table[i] |= LI_FLAG_CONFERENCE | LI_FLAG_MIX;
  12085. li_config_table[i].flag_table[k] |= LI_FLAG_CONFERENCE | LI_FLAG_MONITOR;
  12086. li_config_table[k].flag_table[j] |= LI_FLAG_CONFERENCE;
  12087. li_config_table[j].flag_table[k] |= LI_FLAG_CONFERENCE;
  12088. }
  12089. mixer_calculate_coefs(a);
  12090. li_config_table[i].curchnl = li_config_table[i].channel;
  12091. li_config_table[j].curchnl = li_config_table[j].channel;
  12092. if (a->manufacturer_features & MANUFACTURER_FEATURE_SLAVE_CODEC)
  12093. li_config_table[k].curchnl = li_config_table[k].channel;
  12094. break;
  12095. case ADV_VOICE_WRITE_DEACTIVATION:
  12096. for (j = 0; j < li_total_channels; j++)
  12097. {
  12098. li_config_table[i].flag_table[j] = 0;
  12099. li_config_table[j].flag_table[i] = 0;
  12100. }
  12101. k = a->li_base + MIXER_IC_CHANNEL_BASE + (plci->li_bchannel_id - 1);
  12102. for (j = 0; j < li_total_channels; j++)
  12103. {
  12104. li_config_table[k].flag_table[j] = 0;
  12105. li_config_table[j].flag_table[k] = 0;
  12106. }
  12107. if (a->manufacturer_features & MANUFACTURER_FEATURE_SLAVE_CODEC)
  12108. {
  12109. k = a->li_base + MIXER_IC_CHANNEL_BASE + (2 - plci->li_bchannel_id);
  12110. for (j = 0; j < li_total_channels; j++)
  12111. {
  12112. li_config_table[k].flag_table[j] = 0;
  12113. li_config_table[j].flag_table[k] = 0;
  12114. }
  12115. }
  12116. mixer_calculate_coefs(a);
  12117. break;
  12118. }
  12119. if (plci->B1_facilities & B1_FACILITY_MIXER)
  12120. {
  12121. w = 0;
  12122. if (ADV_VOICE_NEW_COEF_BASE + sizeof(word) <= a->adv_voice_coef_length)
  12123. w = GET_WORD(a->adv_voice_coef_buffer + ADV_VOICE_NEW_COEF_BASE);
  12124. if (li_config_table[i].channel & LI_CHANNEL_TX_DATA)
  12125. w |= MIXER_FEATURE_ENABLE_TX_DATA;
  12126. if (li_config_table[i].channel & LI_CHANNEL_RX_DATA)
  12127. w |= MIXER_FEATURE_ENABLE_RX_DATA;
  12128. *(p++) = (byte) w;
  12129. *(p++) = (byte)(w >> 8);
  12130. for (j = 0; j < sizeof(ch_map); j += 2)
  12131. {
  12132. ch_map[j] = (byte)(j + (plci->li_bchannel_id - 1));
  12133. ch_map[j + 1] = (byte)(j + (2 - plci->li_bchannel_id));
  12134. }
  12135. for (n = 0; n < ARRAY_SIZE(mixer_write_prog_bri); n++)
  12136. {
  12137. i = a->li_base + ch_map[mixer_write_prog_bri[n].to_ch];
  12138. j = a->li_base + ch_map[mixer_write_prog_bri[n].from_ch];
  12139. if (li_config_table[i].channel & li_config_table[j].channel & LI_CHANNEL_INVOLVED)
  12140. {
  12141. *(p++) = ((li_config_table[i].coef_table[j] & mixer_write_prog_bri[n].mask) ? 0x80 : 0x01);
  12142. w = ((li_config_table[i].coef_table[j] & 0xf) ^ (li_config_table[i].coef_table[j] >> 4));
  12143. li_config_table[i].coef_table[j] ^= (w & mixer_write_prog_bri[n].mask) << 4;
  12144. }
  12145. else
  12146. {
  12147. *(p++) = (ADV_VOICE_NEW_COEF_BASE + sizeof(word) + n < a->adv_voice_coef_length) ?
  12148. a->adv_voice_coef_buffer[ADV_VOICE_NEW_COEF_BASE + sizeof(word) + n] : 0x00;
  12149. }
  12150. }
  12151. }
  12152. else
  12153. {
  12154. for (i = ADV_VOICE_NEW_COEF_BASE; i < a->adv_voice_coef_length; i++)
  12155. *(p++) = a->adv_voice_coef_buffer[i];
  12156. }
  12157. }
  12158. else
  12159. {
  12160. for (i = ADV_VOICE_NEW_COEF_BASE; i < a->adv_voice_coef_length; i++)
  12161. *(p++) = a->adv_voice_coef_buffer[i];
  12162. }
  12163. coef_buffer[0] = (p - coef_buffer) - 1;
  12164. add_p(plci, FTY, coef_buffer);
  12165. sig_req(plci, TEL_CTRL, 0);
  12166. send_req(plci);
  12167. }
  12168. static void adv_voice_clear_config(PLCI *plci)
  12169. {
  12170. DIVA_CAPI_ADAPTER *a;
  12171. word i, j;
  12172. dbug(1, dprintf("[%06lx] %s,%d: adv_voice_clear_config",
  12173. (dword)((plci->Id << 8) | UnMapController(plci->adapter->Id)),
  12174. (char *)(FILE_), __LINE__));
  12175. a = plci->adapter;
  12176. if ((plci->tel == ADV_VOICE) && (plci == a->AdvSignalPLCI))
  12177. {
  12178. a->adv_voice_coef_length = 0;
  12179. if (!a->li_pri && (plci->li_bchannel_id != 0)
  12180. && (li_config_table[a->li_base + (plci->li_bchannel_id - 1)].plci == plci))
  12181. {
  12182. i = a->li_base + (plci->li_bchannel_id - 1);
  12183. li_config_table[i].curchnl = 0;
  12184. li_config_table[i].channel = 0;
  12185. li_config_table[i].chflags = 0;
  12186. for (j = 0; j < li_total_channels; j++)
  12187. {
  12188. li_config_table[i].flag_table[j] = 0;
  12189. li_config_table[j].flag_table[i] = 0;
  12190. li_config_table[i].coef_table[j] = 0;
  12191. li_config_table[j].coef_table[i] = 0;
  12192. }
  12193. li_config_table[i].coef_table[i] |= LI_COEF_CH_PC_SET | LI_COEF_PC_CH_SET;
  12194. i = a->li_base + MIXER_IC_CHANNEL_BASE + (plci->li_bchannel_id - 1);
  12195. li_config_table[i].curchnl = 0;
  12196. li_config_table[i].channel = 0;
  12197. li_config_table[i].chflags = 0;
  12198. for (j = 0; j < li_total_channels; j++)
  12199. {
  12200. li_config_table[i].flag_table[j] = 0;
  12201. li_config_table[j].flag_table[i] = 0;
  12202. li_config_table[i].coef_table[j] = 0;
  12203. li_config_table[j].coef_table[i] = 0;
  12204. }
  12205. if (a->manufacturer_features & MANUFACTURER_FEATURE_SLAVE_CODEC)
  12206. {
  12207. i = a->li_base + MIXER_IC_CHANNEL_BASE + (2 - plci->li_bchannel_id);
  12208. li_config_table[i].curchnl = 0;
  12209. li_config_table[i].channel = 0;
  12210. li_config_table[i].chflags = 0;
  12211. for (j = 0; j < li_total_channels; j++)
  12212. {
  12213. li_config_table[i].flag_table[j] = 0;
  12214. li_config_table[j].flag_table[i] = 0;
  12215. li_config_table[i].coef_table[j] = 0;
  12216. li_config_table[j].coef_table[i] = 0;
  12217. }
  12218. }
  12219. }
  12220. }
  12221. }
  12222. static void adv_voice_prepare_switch(dword Id, PLCI *plci)
  12223. {
  12224. dbug(1, dprintf("[%06lx] %s,%d: adv_voice_prepare_switch",
  12225. UnMapId(Id), (char *)(FILE_), __LINE__));
  12226. }
  12227. static word adv_voice_save_config(dword Id, PLCI *plci, byte Rc)
  12228. {
  12229. dbug(1, dprintf("[%06lx] %s,%d: adv_voice_save_config %02x %d",
  12230. UnMapId(Id), (char *)(FILE_), __LINE__, Rc, plci->adjust_b_state));
  12231. return (GOOD);
  12232. }
  12233. static word adv_voice_restore_config(dword Id, PLCI *plci, byte Rc)
  12234. {
  12235. DIVA_CAPI_ADAPTER *a;
  12236. word Info;
  12237. dbug(1, dprintf("[%06lx] %s,%d: adv_voice_restore_config %02x %d",
  12238. UnMapId(Id), (char *)(FILE_), __LINE__, Rc, plci->adjust_b_state));
  12239. Info = GOOD;
  12240. a = plci->adapter;
  12241. if ((plci->B1_facilities & B1_FACILITY_VOICE)
  12242. && (plci->tel == ADV_VOICE) && (plci == a->AdvSignalPLCI))
  12243. {
  12244. switch (plci->adjust_b_state)
  12245. {
  12246. case ADJUST_B_RESTORE_VOICE_1:
  12247. plci->internal_command = plci->adjust_b_command;
  12248. if (plci->sig_req)
  12249. {
  12250. plci->adjust_b_state = ADJUST_B_RESTORE_VOICE_1;
  12251. break;
  12252. }
  12253. adv_voice_write_coefs(plci, ADV_VOICE_WRITE_UPDATE);
  12254. plci->adjust_b_state = ADJUST_B_RESTORE_VOICE_2;
  12255. break;
  12256. case ADJUST_B_RESTORE_VOICE_2:
  12257. if ((Rc != OK) && (Rc != OK_FC))
  12258. {
  12259. dbug(1, dprintf("[%06lx] %s,%d: Restore voice config failed %02x",
  12260. UnMapId(Id), (char *)(FILE_), __LINE__, Rc));
  12261. Info = _WRONG_STATE;
  12262. break;
  12263. }
  12264. break;
  12265. }
  12266. }
  12267. return (Info);
  12268. }
  12269. /*------------------------------------------------------------------*/
  12270. /* B1 resource switching */
  12271. /*------------------------------------------------------------------*/
  12272. static byte b1_facilities_table[] =
  12273. {
  12274. 0x00, /* 0 No bchannel resources */
  12275. 0x00, /* 1 Codec (automatic law) */
  12276. 0x00, /* 2 Codec (A-law) */
  12277. 0x00, /* 3 Codec (y-law) */
  12278. 0x00, /* 4 HDLC for X.21 */
  12279. 0x00, /* 5 HDLC */
  12280. 0x00, /* 6 External Device 0 */
  12281. 0x00, /* 7 External Device 1 */
  12282. 0x00, /* 8 HDLC 56k */
  12283. 0x00, /* 9 Transparent */
  12284. 0x00, /* 10 Loopback to network */
  12285. 0x00, /* 11 Test pattern to net */
  12286. 0x00, /* 12 Rate adaptation sync */
  12287. 0x00, /* 13 Rate adaptation async */
  12288. 0x00, /* 14 R-Interface */
  12289. 0x00, /* 15 HDLC 128k leased line */
  12290. 0x00, /* 16 FAX */
  12291. 0x00, /* 17 Modem async */
  12292. 0x00, /* 18 Modem sync HDLC */
  12293. 0x00, /* 19 V.110 async HDLC */
  12294. 0x12, /* 20 Adv voice (Trans,mixer) */
  12295. 0x00, /* 21 Codec connected to IC */
  12296. 0x0c, /* 22 Trans,DTMF */
  12297. 0x1e, /* 23 Trans,DTMF+mixer */
  12298. 0x1f, /* 24 Trans,DTMF+mixer+local */
  12299. 0x13, /* 25 Trans,mixer+local */
  12300. 0x12, /* 26 HDLC,mixer */
  12301. 0x12, /* 27 HDLC 56k,mixer */
  12302. 0x2c, /* 28 Trans,LEC+DTMF */
  12303. 0x3e, /* 29 Trans,LEC+DTMF+mixer */
  12304. 0x3f, /* 30 Trans,LEC+DTMF+mixer+local */
  12305. 0x2c, /* 31 RTP,LEC+DTMF */
  12306. 0x3e, /* 32 RTP,LEC+DTMF+mixer */
  12307. 0x3f, /* 33 RTP,LEC+DTMF+mixer+local */
  12308. 0x00, /* 34 Signaling task */
  12309. 0x00, /* 35 PIAFS */
  12310. 0x0c, /* 36 Trans,DTMF+TONE */
  12311. 0x1e, /* 37 Trans,DTMF+TONE+mixer */
  12312. 0x1f /* 38 Trans,DTMF+TONE+mixer+local*/
  12313. };
  12314. static word get_b1_facilities(PLCI *plci, byte b1_resource)
  12315. {
  12316. word b1_facilities;
  12317. b1_facilities = b1_facilities_table[b1_resource];
  12318. if ((b1_resource == 9) || (b1_resource == 20) || (b1_resource == 25))
  12319. {
  12320. if (!(((plci->requested_options_conn | plci->requested_options) & (1L << PRIVATE_DTMF_TONE))
  12321. || (plci->appl && (plci->adapter->requested_options_table[plci->appl->Id - 1] & (1L << PRIVATE_DTMF_TONE)))))
  12322. {
  12323. if (plci->adapter->manufacturer_features & MANUFACTURER_FEATURE_SOFTDTMF_SEND)
  12324. b1_facilities |= B1_FACILITY_DTMFX;
  12325. if (plci->adapter->manufacturer_features & MANUFACTURER_FEATURE_SOFTDTMF_RECEIVE)
  12326. b1_facilities |= B1_FACILITY_DTMFR;
  12327. }
  12328. }
  12329. if ((b1_resource == 17) || (b1_resource == 18))
  12330. {
  12331. if (plci->adapter->manufacturer_features & (MANUFACTURER_FEATURE_V18 | MANUFACTURER_FEATURE_VOWN))
  12332. b1_facilities |= B1_FACILITY_DTMFX | B1_FACILITY_DTMFR;
  12333. }
  12334. /*
  12335. dbug (1, dprintf("[%06lx] %s,%d: get_b1_facilities %d %04x",
  12336. (dword)((plci->Id << 8) | UnMapController(plci->adapter->Id)),
  12337. (char far *)(FILE_), __LINE__, b1_resource, b1_facilites));
  12338. */
  12339. return (b1_facilities);
  12340. }
  12341. static byte add_b1_facilities(PLCI *plci, byte b1_resource, word b1_facilities)
  12342. {
  12343. byte b;
  12344. switch (b1_resource)
  12345. {
  12346. case 5:
  12347. case 26:
  12348. if (b1_facilities & (B1_FACILITY_MIXER | B1_FACILITY_VOICE))
  12349. b = 26;
  12350. else
  12351. b = 5;
  12352. break;
  12353. case 8:
  12354. case 27:
  12355. if (b1_facilities & (B1_FACILITY_MIXER | B1_FACILITY_VOICE))
  12356. b = 27;
  12357. else
  12358. b = 8;
  12359. break;
  12360. case 9:
  12361. case 20:
  12362. case 22:
  12363. case 23:
  12364. case 24:
  12365. case 25:
  12366. case 28:
  12367. case 29:
  12368. case 30:
  12369. case 36:
  12370. case 37:
  12371. case 38:
  12372. if (b1_facilities & B1_FACILITY_EC)
  12373. {
  12374. if (b1_facilities & B1_FACILITY_LOCAL)
  12375. b = 30;
  12376. else if (b1_facilities & (B1_FACILITY_MIXER | B1_FACILITY_VOICE))
  12377. b = 29;
  12378. else
  12379. b = 28;
  12380. }
  12381. else if ((b1_facilities & (B1_FACILITY_DTMFX | B1_FACILITY_DTMFR | B1_FACILITY_MIXER))
  12382. && (((plci->requested_options_conn | plci->requested_options) & (1L << PRIVATE_DTMF_TONE))
  12383. || (plci->appl && (plci->adapter->requested_options_table[plci->appl->Id - 1] & (1L << PRIVATE_DTMF_TONE)))))
  12384. {
  12385. if (b1_facilities & B1_FACILITY_LOCAL)
  12386. b = 38;
  12387. else if (b1_facilities & (B1_FACILITY_MIXER | B1_FACILITY_VOICE))
  12388. b = 37;
  12389. else
  12390. b = 36;
  12391. }
  12392. else if (((plci->adapter->manufacturer_features & MANUFACTURER_FEATURE_HARDDTMF)
  12393. && !(plci->adapter->manufacturer_features & MANUFACTURER_FEATURE_SOFTDTMF_RECEIVE))
  12394. || ((b1_facilities & B1_FACILITY_DTMFR)
  12395. && ((b1_facilities & B1_FACILITY_MIXER)
  12396. || !(plci->adapter->manufacturer_features & MANUFACTURER_FEATURE_SOFTDTMF_RECEIVE)))
  12397. || ((b1_facilities & B1_FACILITY_DTMFX)
  12398. && ((b1_facilities & B1_FACILITY_MIXER)
  12399. || !(plci->adapter->manufacturer_features & MANUFACTURER_FEATURE_SOFTDTMF_SEND))))
  12400. {
  12401. if (b1_facilities & B1_FACILITY_LOCAL)
  12402. b = 24;
  12403. else if (b1_facilities & (B1_FACILITY_MIXER | B1_FACILITY_VOICE))
  12404. b = 23;
  12405. else
  12406. b = 22;
  12407. }
  12408. else
  12409. {
  12410. if (b1_facilities & B1_FACILITY_LOCAL)
  12411. b = 25;
  12412. else if (b1_facilities & (B1_FACILITY_MIXER | B1_FACILITY_VOICE))
  12413. b = 20;
  12414. else
  12415. b = 9;
  12416. }
  12417. break;
  12418. case 31:
  12419. case 32:
  12420. case 33:
  12421. if (b1_facilities & B1_FACILITY_LOCAL)
  12422. b = 33;
  12423. else if (b1_facilities & (B1_FACILITY_MIXER | B1_FACILITY_VOICE))
  12424. b = 32;
  12425. else
  12426. b = 31;
  12427. break;
  12428. default:
  12429. b = b1_resource;
  12430. }
  12431. dbug(1, dprintf("[%06lx] %s,%d: add_b1_facilities %d %04x %d %04x",
  12432. (dword)((plci->Id << 8) | UnMapController(plci->adapter->Id)),
  12433. (char *)(FILE_), __LINE__,
  12434. b1_resource, b1_facilities, b, get_b1_facilities(plci, b)));
  12435. return (b);
  12436. }
  12437. static void adjust_b1_facilities(PLCI *plci, byte new_b1_resource, word new_b1_facilities)
  12438. {
  12439. word removed_facilities;
  12440. dbug(1, dprintf("[%06lx] %s,%d: adjust_b1_facilities %d %04x %04x",
  12441. (dword)((plci->Id << 8) | UnMapController(plci->adapter->Id)),
  12442. (char *)(FILE_), __LINE__, new_b1_resource, new_b1_facilities,
  12443. new_b1_facilities & get_b1_facilities(plci, new_b1_resource)));
  12444. new_b1_facilities &= get_b1_facilities(plci, new_b1_resource);
  12445. removed_facilities = plci->B1_facilities & ~new_b1_facilities;
  12446. if (removed_facilities & B1_FACILITY_EC)
  12447. ec_clear_config(plci);
  12448. if (removed_facilities & B1_FACILITY_DTMFR)
  12449. {
  12450. dtmf_rec_clear_config(plci);
  12451. dtmf_parameter_clear_config(plci);
  12452. }
  12453. if (removed_facilities & B1_FACILITY_DTMFX)
  12454. dtmf_send_clear_config(plci);
  12455. if (removed_facilities & B1_FACILITY_MIXER)
  12456. mixer_clear_config(plci);
  12457. if (removed_facilities & B1_FACILITY_VOICE)
  12458. adv_voice_clear_config(plci);
  12459. plci->B1_facilities = new_b1_facilities;
  12460. }
  12461. static void adjust_b_clear(PLCI *plci)
  12462. {
  12463. dbug(1, dprintf("[%06lx] %s,%d: adjust_b_clear",
  12464. (dword)((plci->Id << 8) | UnMapController(plci->adapter->Id)),
  12465. (char *)(FILE_), __LINE__));
  12466. plci->adjust_b_restore = false;
  12467. }
  12468. static word adjust_b_process(dword Id, PLCI *plci, byte Rc)
  12469. {
  12470. word Info;
  12471. byte b1_resource;
  12472. NCCI *ncci_ptr;
  12473. API_PARSE bp[2];
  12474. dbug(1, dprintf("[%06lx] %s,%d: adjust_b_process %02x %d",
  12475. UnMapId(Id), (char *)(FILE_), __LINE__, Rc, plci->adjust_b_state));
  12476. Info = GOOD;
  12477. switch (plci->adjust_b_state)
  12478. {
  12479. case ADJUST_B_START:
  12480. if ((plci->adjust_b_parms_msg == NULL)
  12481. && (plci->adjust_b_mode & ADJUST_B_MODE_SWITCH_L1)
  12482. && ((plci->adjust_b_mode & ~(ADJUST_B_MODE_SAVE | ADJUST_B_MODE_SWITCH_L1 |
  12483. ADJUST_B_MODE_NO_RESOURCE | ADJUST_B_MODE_RESTORE)) == 0))
  12484. {
  12485. b1_resource = (plci->adjust_b_mode == ADJUST_B_MODE_NO_RESOURCE) ?
  12486. 0 : add_b1_facilities(plci, plci->B1_resource, plci->adjust_b_facilities);
  12487. if (b1_resource == plci->B1_resource)
  12488. {
  12489. adjust_b1_facilities(plci, b1_resource, plci->adjust_b_facilities);
  12490. break;
  12491. }
  12492. if (plci->adjust_b_facilities & ~get_b1_facilities(plci, b1_resource))
  12493. {
  12494. dbug(1, dprintf("[%06lx] %s,%d: Adjust B nonsupported facilities %d %d %04x",
  12495. UnMapId(Id), (char *)(FILE_), __LINE__,
  12496. plci->B1_resource, b1_resource, plci->adjust_b_facilities));
  12497. Info = _WRONG_STATE;
  12498. break;
  12499. }
  12500. }
  12501. if (plci->adjust_b_mode & ADJUST_B_MODE_SAVE)
  12502. {
  12503. mixer_prepare_switch(Id, plci);
  12504. dtmf_prepare_switch(Id, plci);
  12505. dtmf_parameter_prepare_switch(Id, plci);
  12506. ec_prepare_switch(Id, plci);
  12507. adv_voice_prepare_switch(Id, plci);
  12508. }
  12509. plci->adjust_b_state = ADJUST_B_SAVE_MIXER_1;
  12510. Rc = OK;
  12511. case ADJUST_B_SAVE_MIXER_1:
  12512. if (plci->adjust_b_mode & ADJUST_B_MODE_SAVE)
  12513. {
  12514. Info = mixer_save_config(Id, plci, Rc);
  12515. if ((Info != GOOD) || plci->internal_command)
  12516. break;
  12517. }
  12518. plci->adjust_b_state = ADJUST_B_SAVE_DTMF_1;
  12519. Rc = OK;
  12520. case ADJUST_B_SAVE_DTMF_1:
  12521. if (plci->adjust_b_mode & ADJUST_B_MODE_SAVE)
  12522. {
  12523. Info = dtmf_save_config(Id, plci, Rc);
  12524. if ((Info != GOOD) || plci->internal_command)
  12525. break;
  12526. }
  12527. plci->adjust_b_state = ADJUST_B_REMOVE_L23_1;
  12528. case ADJUST_B_REMOVE_L23_1:
  12529. if ((plci->adjust_b_mode & ADJUST_B_MODE_REMOVE_L23)
  12530. && plci->NL.Id && !plci->nl_remove_id)
  12531. {
  12532. plci->internal_command = plci->adjust_b_command;
  12533. if (plci->adjust_b_ncci != 0)
  12534. {
  12535. ncci_ptr = &(plci->adapter->ncci[plci->adjust_b_ncci]);
  12536. while (ncci_ptr->data_pending)
  12537. {
  12538. plci->data_sent_ptr = ncci_ptr->DBuffer[ncci_ptr->data_out].P;
  12539. data_rc(plci, plci->adapter->ncci_ch[plci->adjust_b_ncci]);
  12540. }
  12541. while (ncci_ptr->data_ack_pending)
  12542. data_ack(plci, plci->adapter->ncci_ch[plci->adjust_b_ncci]);
  12543. }
  12544. nl_req_ncci(plci, REMOVE,
  12545. (byte)((plci->adjust_b_mode & ADJUST_B_MODE_CONNECT) ? plci->adjust_b_ncci : 0));
  12546. send_req(plci);
  12547. plci->adjust_b_state = ADJUST_B_REMOVE_L23_2;
  12548. break;
  12549. }
  12550. plci->adjust_b_state = ADJUST_B_REMOVE_L23_2;
  12551. Rc = OK;
  12552. case ADJUST_B_REMOVE_L23_2:
  12553. if ((Rc != OK) && (Rc != OK_FC))
  12554. {
  12555. dbug(1, dprintf("[%06lx] %s,%d: Adjust B remove failed %02x",
  12556. UnMapId(Id), (char *)(FILE_), __LINE__, Rc));
  12557. Info = _WRONG_STATE;
  12558. break;
  12559. }
  12560. if (plci->adjust_b_mode & ADJUST_B_MODE_REMOVE_L23)
  12561. {
  12562. if (plci_nl_busy(plci))
  12563. {
  12564. plci->internal_command = plci->adjust_b_command;
  12565. break;
  12566. }
  12567. }
  12568. plci->adjust_b_state = ADJUST_B_SAVE_EC_1;
  12569. Rc = OK;
  12570. case ADJUST_B_SAVE_EC_1:
  12571. if (plci->adjust_b_mode & ADJUST_B_MODE_SAVE)
  12572. {
  12573. Info = ec_save_config(Id, plci, Rc);
  12574. if ((Info != GOOD) || plci->internal_command)
  12575. break;
  12576. }
  12577. plci->adjust_b_state = ADJUST_B_SAVE_DTMF_PARAMETER_1;
  12578. Rc = OK;
  12579. case ADJUST_B_SAVE_DTMF_PARAMETER_1:
  12580. if (plci->adjust_b_mode & ADJUST_B_MODE_SAVE)
  12581. {
  12582. Info = dtmf_parameter_save_config(Id, plci, Rc);
  12583. if ((Info != GOOD) || plci->internal_command)
  12584. break;
  12585. }
  12586. plci->adjust_b_state = ADJUST_B_SAVE_VOICE_1;
  12587. Rc = OK;
  12588. case ADJUST_B_SAVE_VOICE_1:
  12589. if (plci->adjust_b_mode & ADJUST_B_MODE_SAVE)
  12590. {
  12591. Info = adv_voice_save_config(Id, plci, Rc);
  12592. if ((Info != GOOD) || plci->internal_command)
  12593. break;
  12594. }
  12595. plci->adjust_b_state = ADJUST_B_SWITCH_L1_1;
  12596. case ADJUST_B_SWITCH_L1_1:
  12597. if (plci->adjust_b_mode & ADJUST_B_MODE_SWITCH_L1)
  12598. {
  12599. if (plci->sig_req)
  12600. {
  12601. plci->internal_command = plci->adjust_b_command;
  12602. break;
  12603. }
  12604. if (plci->adjust_b_parms_msg != NULL)
  12605. api_load_msg(plci->adjust_b_parms_msg, bp);
  12606. else
  12607. api_load_msg(&plci->B_protocol, bp);
  12608. Info = add_b1(plci, bp,
  12609. (word)((plci->adjust_b_mode & ADJUST_B_MODE_NO_RESOURCE) ? 2 : 0),
  12610. plci->adjust_b_facilities);
  12611. if (Info != GOOD)
  12612. {
  12613. dbug(1, dprintf("[%06lx] %s,%d: Adjust B invalid L1 parameters %d %04x",
  12614. UnMapId(Id), (char *)(FILE_), __LINE__,
  12615. plci->B1_resource, plci->adjust_b_facilities));
  12616. break;
  12617. }
  12618. plci->internal_command = plci->adjust_b_command;
  12619. sig_req(plci, RESOURCES, 0);
  12620. send_req(plci);
  12621. plci->adjust_b_state = ADJUST_B_SWITCH_L1_2;
  12622. break;
  12623. }
  12624. plci->adjust_b_state = ADJUST_B_SWITCH_L1_2;
  12625. Rc = OK;
  12626. case ADJUST_B_SWITCH_L1_2:
  12627. if ((Rc != OK) && (Rc != OK_FC))
  12628. {
  12629. dbug(1, dprintf("[%06lx] %s,%d: Adjust B switch failed %02x %d %04x",
  12630. UnMapId(Id), (char *)(FILE_), __LINE__,
  12631. Rc, plci->B1_resource, plci->adjust_b_facilities));
  12632. Info = _WRONG_STATE;
  12633. break;
  12634. }
  12635. plci->adjust_b_state = ADJUST_B_RESTORE_VOICE_1;
  12636. Rc = OK;
  12637. case ADJUST_B_RESTORE_VOICE_1:
  12638. case ADJUST_B_RESTORE_VOICE_2:
  12639. if (plci->adjust_b_mode & ADJUST_B_MODE_RESTORE)
  12640. {
  12641. Info = adv_voice_restore_config(Id, plci, Rc);
  12642. if ((Info != GOOD) || plci->internal_command)
  12643. break;
  12644. }
  12645. plci->adjust_b_state = ADJUST_B_RESTORE_DTMF_PARAMETER_1;
  12646. Rc = OK;
  12647. case ADJUST_B_RESTORE_DTMF_PARAMETER_1:
  12648. case ADJUST_B_RESTORE_DTMF_PARAMETER_2:
  12649. if (plci->adjust_b_mode & ADJUST_B_MODE_RESTORE)
  12650. {
  12651. Info = dtmf_parameter_restore_config(Id, plci, Rc);
  12652. if ((Info != GOOD) || plci->internal_command)
  12653. break;
  12654. }
  12655. plci->adjust_b_state = ADJUST_B_RESTORE_EC_1;
  12656. Rc = OK;
  12657. case ADJUST_B_RESTORE_EC_1:
  12658. case ADJUST_B_RESTORE_EC_2:
  12659. if (plci->adjust_b_mode & ADJUST_B_MODE_RESTORE)
  12660. {
  12661. Info = ec_restore_config(Id, plci, Rc);
  12662. if ((Info != GOOD) || plci->internal_command)
  12663. break;
  12664. }
  12665. plci->adjust_b_state = ADJUST_B_ASSIGN_L23_1;
  12666. case ADJUST_B_ASSIGN_L23_1:
  12667. if (plci->adjust_b_mode & ADJUST_B_MODE_ASSIGN_L23)
  12668. {
  12669. if (plci_nl_busy(plci))
  12670. {
  12671. plci->internal_command = plci->adjust_b_command;
  12672. break;
  12673. }
  12674. if (plci->adjust_b_mode & ADJUST_B_MODE_CONNECT)
  12675. plci->call_dir |= CALL_DIR_FORCE_OUTG_NL;
  12676. if (plci->adjust_b_parms_msg != NULL)
  12677. api_load_msg(plci->adjust_b_parms_msg, bp);
  12678. else
  12679. api_load_msg(&plci->B_protocol, bp);
  12680. Info = add_b23(plci, bp);
  12681. if (Info != GOOD)
  12682. {
  12683. dbug(1, dprintf("[%06lx] %s,%d: Adjust B invalid L23 parameters %04x",
  12684. UnMapId(Id), (char *)(FILE_), __LINE__, Info));
  12685. break;
  12686. }
  12687. plci->internal_command = plci->adjust_b_command;
  12688. nl_req_ncci(plci, ASSIGN, 0);
  12689. send_req(plci);
  12690. plci->adjust_b_state = ADJUST_B_ASSIGN_L23_2;
  12691. break;
  12692. }
  12693. plci->adjust_b_state = ADJUST_B_ASSIGN_L23_2;
  12694. Rc = ASSIGN_OK;
  12695. case ADJUST_B_ASSIGN_L23_2:
  12696. if ((Rc != OK) && (Rc != OK_FC) && (Rc != ASSIGN_OK))
  12697. {
  12698. dbug(1, dprintf("[%06lx] %s,%d: Adjust B assign failed %02x",
  12699. UnMapId(Id), (char *)(FILE_), __LINE__, Rc));
  12700. Info = _WRONG_STATE;
  12701. break;
  12702. }
  12703. if (plci->adjust_b_mode & ADJUST_B_MODE_ASSIGN_L23)
  12704. {
  12705. if (Rc != ASSIGN_OK)
  12706. {
  12707. plci->internal_command = plci->adjust_b_command;
  12708. break;
  12709. }
  12710. }
  12711. if (plci->adjust_b_mode & ADJUST_B_MODE_USER_CONNECT)
  12712. {
  12713. plci->adjust_b_restore = true;
  12714. break;
  12715. }
  12716. plci->adjust_b_state = ADJUST_B_CONNECT_1;
  12717. case ADJUST_B_CONNECT_1:
  12718. if (plci->adjust_b_mode & ADJUST_B_MODE_CONNECT)
  12719. {
  12720. plci->internal_command = plci->adjust_b_command;
  12721. if (plci_nl_busy(plci))
  12722. break;
  12723. nl_req_ncci(plci, N_CONNECT, 0);
  12724. send_req(plci);
  12725. plci->adjust_b_state = ADJUST_B_CONNECT_2;
  12726. break;
  12727. }
  12728. plci->adjust_b_state = ADJUST_B_RESTORE_DTMF_1;
  12729. Rc = OK;
  12730. case ADJUST_B_CONNECT_2:
  12731. case ADJUST_B_CONNECT_3:
  12732. case ADJUST_B_CONNECT_4:
  12733. if ((Rc != OK) && (Rc != OK_FC) && (Rc != 0))
  12734. {
  12735. dbug(1, dprintf("[%06lx] %s,%d: Adjust B connect failed %02x",
  12736. UnMapId(Id), (char *)(FILE_), __LINE__, Rc));
  12737. Info = _WRONG_STATE;
  12738. break;
  12739. }
  12740. if (Rc == OK)
  12741. {
  12742. if (plci->adjust_b_mode & ADJUST_B_MODE_CONNECT)
  12743. {
  12744. get_ncci(plci, (byte)(Id >> 16), plci->adjust_b_ncci);
  12745. Id = (Id & 0xffff) | (((dword)(plci->adjust_b_ncci)) << 16);
  12746. }
  12747. if (plci->adjust_b_state == ADJUST_B_CONNECT_2)
  12748. plci->adjust_b_state = ADJUST_B_CONNECT_3;
  12749. else if (plci->adjust_b_state == ADJUST_B_CONNECT_4)
  12750. plci->adjust_b_state = ADJUST_B_RESTORE_DTMF_1;
  12751. }
  12752. else if (Rc == 0)
  12753. {
  12754. if (plci->adjust_b_state == ADJUST_B_CONNECT_2)
  12755. plci->adjust_b_state = ADJUST_B_CONNECT_4;
  12756. else if (plci->adjust_b_state == ADJUST_B_CONNECT_3)
  12757. plci->adjust_b_state = ADJUST_B_RESTORE_DTMF_1;
  12758. }
  12759. if (plci->adjust_b_state != ADJUST_B_RESTORE_DTMF_1)
  12760. {
  12761. plci->internal_command = plci->adjust_b_command;
  12762. break;
  12763. }
  12764. Rc = OK;
  12765. case ADJUST_B_RESTORE_DTMF_1:
  12766. case ADJUST_B_RESTORE_DTMF_2:
  12767. if (plci->adjust_b_mode & ADJUST_B_MODE_RESTORE)
  12768. {
  12769. Info = dtmf_restore_config(Id, plci, Rc);
  12770. if ((Info != GOOD) || plci->internal_command)
  12771. break;
  12772. }
  12773. plci->adjust_b_state = ADJUST_B_RESTORE_MIXER_1;
  12774. Rc = OK;
  12775. case ADJUST_B_RESTORE_MIXER_1:
  12776. case ADJUST_B_RESTORE_MIXER_2:
  12777. case ADJUST_B_RESTORE_MIXER_3:
  12778. case ADJUST_B_RESTORE_MIXER_4:
  12779. case ADJUST_B_RESTORE_MIXER_5:
  12780. case ADJUST_B_RESTORE_MIXER_6:
  12781. case ADJUST_B_RESTORE_MIXER_7:
  12782. if (plci->adjust_b_mode & ADJUST_B_MODE_RESTORE)
  12783. {
  12784. Info = mixer_restore_config(Id, plci, Rc);
  12785. if ((Info != GOOD) || plci->internal_command)
  12786. break;
  12787. }
  12788. plci->adjust_b_state = ADJUST_B_END;
  12789. case ADJUST_B_END:
  12790. break;
  12791. }
  12792. return (Info);
  12793. }
  12794. static void adjust_b1_resource(dword Id, PLCI *plci, API_SAVE *bp_msg, word b1_facilities, word internal_command)
  12795. {
  12796. dbug(1, dprintf("[%06lx] %s,%d: adjust_b1_resource %d %04x",
  12797. UnMapId(Id), (char *)(FILE_), __LINE__,
  12798. plci->B1_resource, b1_facilities));
  12799. plci->adjust_b_parms_msg = bp_msg;
  12800. plci->adjust_b_facilities = b1_facilities;
  12801. plci->adjust_b_command = internal_command;
  12802. plci->adjust_b_ncci = (word)(Id >> 16);
  12803. if ((bp_msg == NULL) && (plci->B1_resource == 0))
  12804. plci->adjust_b_mode = ADJUST_B_MODE_SAVE | ADJUST_B_MODE_NO_RESOURCE | ADJUST_B_MODE_SWITCH_L1;
  12805. else
  12806. plci->adjust_b_mode = ADJUST_B_MODE_SAVE | ADJUST_B_MODE_SWITCH_L1 | ADJUST_B_MODE_RESTORE;
  12807. plci->adjust_b_state = ADJUST_B_START;
  12808. dbug(1, dprintf("[%06lx] %s,%d: Adjust B1 resource %d %04x...",
  12809. UnMapId(Id), (char *)(FILE_), __LINE__,
  12810. plci->B1_resource, b1_facilities));
  12811. }
  12812. static void adjust_b_restore(dword Id, PLCI *plci, byte Rc)
  12813. {
  12814. word internal_command;
  12815. dbug(1, dprintf("[%06lx] %s,%d: adjust_b_restore %02x %04x",
  12816. UnMapId(Id), (char *)(FILE_), __LINE__, Rc, plci->internal_command));
  12817. internal_command = plci->internal_command;
  12818. plci->internal_command = 0;
  12819. switch (internal_command)
  12820. {
  12821. default:
  12822. plci->command = 0;
  12823. if (plci->req_in != 0)
  12824. {
  12825. plci->internal_command = ADJUST_B_RESTORE_1;
  12826. break;
  12827. }
  12828. Rc = OK;
  12829. case ADJUST_B_RESTORE_1:
  12830. if ((Rc != OK) && (Rc != OK_FC))
  12831. {
  12832. dbug(1, dprintf("[%06lx] %s,%d: Adjust B enqueued failed %02x",
  12833. UnMapId(Id), (char *)(FILE_), __LINE__, Rc));
  12834. }
  12835. plci->adjust_b_parms_msg = NULL;
  12836. plci->adjust_b_facilities = plci->B1_facilities;
  12837. plci->adjust_b_command = ADJUST_B_RESTORE_2;
  12838. plci->adjust_b_ncci = (word)(Id >> 16);
  12839. plci->adjust_b_mode = ADJUST_B_MODE_RESTORE;
  12840. plci->adjust_b_state = ADJUST_B_START;
  12841. dbug(1, dprintf("[%06lx] %s,%d: Adjust B restore...",
  12842. UnMapId(Id), (char *)(FILE_), __LINE__));
  12843. case ADJUST_B_RESTORE_2:
  12844. if (adjust_b_process(Id, plci, Rc) != GOOD)
  12845. {
  12846. dbug(1, dprintf("[%06lx] %s,%d: Adjust B restore failed",
  12847. UnMapId(Id), (char *)(FILE_), __LINE__));
  12848. }
  12849. if (plci->internal_command)
  12850. break;
  12851. break;
  12852. }
  12853. }
  12854. static void reset_b3_command(dword Id, PLCI *plci, byte Rc)
  12855. {
  12856. word Info;
  12857. word internal_command;
  12858. dbug(1, dprintf("[%06lx] %s,%d: reset_b3_command %02x %04x",
  12859. UnMapId(Id), (char *)(FILE_), __LINE__, Rc, plci->internal_command));
  12860. Info = GOOD;
  12861. internal_command = plci->internal_command;
  12862. plci->internal_command = 0;
  12863. switch (internal_command)
  12864. {
  12865. default:
  12866. plci->command = 0;
  12867. plci->adjust_b_parms_msg = NULL;
  12868. plci->adjust_b_facilities = plci->B1_facilities;
  12869. plci->adjust_b_command = RESET_B3_COMMAND_1;
  12870. plci->adjust_b_ncci = (word)(Id >> 16);
  12871. plci->adjust_b_mode = ADJUST_B_MODE_REMOVE_L23 | ADJUST_B_MODE_ASSIGN_L23 | ADJUST_B_MODE_CONNECT;
  12872. plci->adjust_b_state = ADJUST_B_START;
  12873. dbug(1, dprintf("[%06lx] %s,%d: Reset B3...",
  12874. UnMapId(Id), (char *)(FILE_), __LINE__));
  12875. case RESET_B3_COMMAND_1:
  12876. Info = adjust_b_process(Id, plci, Rc);
  12877. if (Info != GOOD)
  12878. {
  12879. dbug(1, dprintf("[%06lx] %s,%d: Reset failed",
  12880. UnMapId(Id), (char *)(FILE_), __LINE__));
  12881. break;
  12882. }
  12883. if (plci->internal_command)
  12884. return;
  12885. break;
  12886. }
  12887. /* sendf (plci->appl, _RESET_B3_R | CONFIRM, Id, plci->number, "w", Info);*/
  12888. sendf(plci->appl, _RESET_B3_I, Id, 0, "s", "");
  12889. }
  12890. static void select_b_command(dword Id, PLCI *plci, byte Rc)
  12891. {
  12892. word Info;
  12893. word internal_command;
  12894. byte esc_chi[3];
  12895. dbug(1, dprintf("[%06lx] %s,%d: select_b_command %02x %04x",
  12896. UnMapId(Id), (char *)(FILE_), __LINE__, Rc, plci->internal_command));
  12897. Info = GOOD;
  12898. internal_command = plci->internal_command;
  12899. plci->internal_command = 0;
  12900. switch (internal_command)
  12901. {
  12902. default:
  12903. plci->command = 0;
  12904. plci->adjust_b_parms_msg = &plci->saved_msg;
  12905. if ((plci->tel == ADV_VOICE) && (plci == plci->adapter->AdvSignalPLCI))
  12906. plci->adjust_b_facilities = plci->B1_facilities | B1_FACILITY_VOICE;
  12907. else
  12908. plci->adjust_b_facilities = plci->B1_facilities & ~B1_FACILITY_VOICE;
  12909. plci->adjust_b_command = SELECT_B_COMMAND_1;
  12910. plci->adjust_b_ncci = (word)(Id >> 16);
  12911. if (plci->saved_msg.parms[0].length == 0)
  12912. {
  12913. plci->adjust_b_mode = ADJUST_B_MODE_SAVE | ADJUST_B_MODE_REMOVE_L23 | ADJUST_B_MODE_SWITCH_L1 |
  12914. ADJUST_B_MODE_NO_RESOURCE;
  12915. }
  12916. else
  12917. {
  12918. plci->adjust_b_mode = ADJUST_B_MODE_SAVE | ADJUST_B_MODE_REMOVE_L23 | ADJUST_B_MODE_SWITCH_L1 |
  12919. ADJUST_B_MODE_ASSIGN_L23 | ADJUST_B_MODE_USER_CONNECT | ADJUST_B_MODE_RESTORE;
  12920. }
  12921. plci->adjust_b_state = ADJUST_B_START;
  12922. dbug(1, dprintf("[%06lx] %s,%d: Select B protocol...",
  12923. UnMapId(Id), (char *)(FILE_), __LINE__));
  12924. case SELECT_B_COMMAND_1:
  12925. Info = adjust_b_process(Id, plci, Rc);
  12926. if (Info != GOOD)
  12927. {
  12928. dbug(1, dprintf("[%06lx] %s,%d: Select B protocol failed",
  12929. UnMapId(Id), (char *)(FILE_), __LINE__));
  12930. break;
  12931. }
  12932. if (plci->internal_command)
  12933. return;
  12934. if (plci->tel == ADV_VOICE)
  12935. {
  12936. esc_chi[0] = 0x02;
  12937. esc_chi[1] = 0x18;
  12938. esc_chi[2] = plci->b_channel;
  12939. SetVoiceChannel(plci->adapter->AdvCodecPLCI, esc_chi, plci->adapter);
  12940. }
  12941. break;
  12942. }
  12943. sendf(plci->appl, _SELECT_B_REQ | CONFIRM, Id, plci->number, "w", Info);
  12944. }
  12945. static void fax_connect_ack_command(dword Id, PLCI *plci, byte Rc)
  12946. {
  12947. word internal_command;
  12948. dbug(1, dprintf("[%06lx] %s,%d: fax_connect_ack_command %02x %04x",
  12949. UnMapId(Id), (char *)(FILE_), __LINE__, Rc, plci->internal_command));
  12950. internal_command = plci->internal_command;
  12951. plci->internal_command = 0;
  12952. switch (internal_command)
  12953. {
  12954. default:
  12955. plci->command = 0;
  12956. case FAX_CONNECT_ACK_COMMAND_1:
  12957. if (plci_nl_busy(plci))
  12958. {
  12959. plci->internal_command = FAX_CONNECT_ACK_COMMAND_1;
  12960. return;
  12961. }
  12962. plci->internal_command = FAX_CONNECT_ACK_COMMAND_2;
  12963. plci->NData[0].P = plci->fax_connect_info_buffer;
  12964. plci->NData[0].PLength = plci->fax_connect_info_length;
  12965. plci->NL.X = plci->NData;
  12966. plci->NL.ReqCh = 0;
  12967. plci->NL.Req = plci->nl_req = (byte) N_CONNECT_ACK;
  12968. plci->adapter->request(&plci->NL);
  12969. return;
  12970. case FAX_CONNECT_ACK_COMMAND_2:
  12971. if ((Rc != OK) && (Rc != OK_FC))
  12972. {
  12973. dbug(1, dprintf("[%06lx] %s,%d: FAX issue CONNECT ACK failed %02x",
  12974. UnMapId(Id), (char *)(FILE_), __LINE__, Rc));
  12975. break;
  12976. }
  12977. }
  12978. if ((plci->ncpi_state & NCPI_VALID_CONNECT_B3_ACT)
  12979. && !(plci->ncpi_state & NCPI_CONNECT_B3_ACT_SENT))
  12980. {
  12981. if (plci->B3_prot == 4)
  12982. sendf(plci->appl, _CONNECT_B3_ACTIVE_I, Id, 0, "s", "");
  12983. else
  12984. sendf(plci->appl, _CONNECT_B3_ACTIVE_I, Id, 0, "S", plci->ncpi_buffer);
  12985. plci->ncpi_state |= NCPI_CONNECT_B3_ACT_SENT;
  12986. }
  12987. }
  12988. static void fax_edata_ack_command(dword Id, PLCI *plci, byte Rc)
  12989. {
  12990. word internal_command;
  12991. dbug(1, dprintf("[%06lx] %s,%d: fax_edata_ack_command %02x %04x",
  12992. UnMapId(Id), (char *)(FILE_), __LINE__, Rc, plci->internal_command));
  12993. internal_command = plci->internal_command;
  12994. plci->internal_command = 0;
  12995. switch (internal_command)
  12996. {
  12997. default:
  12998. plci->command = 0;
  12999. case FAX_EDATA_ACK_COMMAND_1:
  13000. if (plci_nl_busy(plci))
  13001. {
  13002. plci->internal_command = FAX_EDATA_ACK_COMMAND_1;
  13003. return;
  13004. }
  13005. plci->internal_command = FAX_EDATA_ACK_COMMAND_2;
  13006. plci->NData[0].P = plci->fax_connect_info_buffer;
  13007. plci->NData[0].PLength = plci->fax_edata_ack_length;
  13008. plci->NL.X = plci->NData;
  13009. plci->NL.ReqCh = 0;
  13010. plci->NL.Req = plci->nl_req = (byte) N_EDATA;
  13011. plci->adapter->request(&plci->NL);
  13012. return;
  13013. case FAX_EDATA_ACK_COMMAND_2:
  13014. if ((Rc != OK) && (Rc != OK_FC))
  13015. {
  13016. dbug(1, dprintf("[%06lx] %s,%d: FAX issue EDATA ACK failed %02x",
  13017. UnMapId(Id), (char *)(FILE_), __LINE__, Rc));
  13018. break;
  13019. }
  13020. }
  13021. }
  13022. static void fax_connect_info_command(dword Id, PLCI *plci, byte Rc)
  13023. {
  13024. word Info;
  13025. word internal_command;
  13026. dbug(1, dprintf("[%06lx] %s,%d: fax_connect_info_command %02x %04x",
  13027. UnMapId(Id), (char *)(FILE_), __LINE__, Rc, plci->internal_command));
  13028. Info = GOOD;
  13029. internal_command = plci->internal_command;
  13030. plci->internal_command = 0;
  13031. switch (internal_command)
  13032. {
  13033. default:
  13034. plci->command = 0;
  13035. case FAX_CONNECT_INFO_COMMAND_1:
  13036. if (plci_nl_busy(plci))
  13037. {
  13038. plci->internal_command = FAX_CONNECT_INFO_COMMAND_1;
  13039. return;
  13040. }
  13041. plci->internal_command = FAX_CONNECT_INFO_COMMAND_2;
  13042. plci->NData[0].P = plci->fax_connect_info_buffer;
  13043. plci->NData[0].PLength = plci->fax_connect_info_length;
  13044. plci->NL.X = plci->NData;
  13045. plci->NL.ReqCh = 0;
  13046. plci->NL.Req = plci->nl_req = (byte) N_EDATA;
  13047. plci->adapter->request(&plci->NL);
  13048. return;
  13049. case FAX_CONNECT_INFO_COMMAND_2:
  13050. if ((Rc != OK) && (Rc != OK_FC))
  13051. {
  13052. dbug(1, dprintf("[%06lx] %s,%d: FAX setting connect info failed %02x",
  13053. UnMapId(Id), (char *)(FILE_), __LINE__, Rc));
  13054. Info = _WRONG_STATE;
  13055. break;
  13056. }
  13057. if (plci_nl_busy(plci))
  13058. {
  13059. plci->internal_command = FAX_CONNECT_INFO_COMMAND_2;
  13060. return;
  13061. }
  13062. plci->command = _CONNECT_B3_R;
  13063. nl_req_ncci(plci, N_CONNECT, 0);
  13064. send_req(plci);
  13065. return;
  13066. }
  13067. sendf(plci->appl, _CONNECT_B3_R | CONFIRM, Id, plci->number, "w", Info);
  13068. }
  13069. static void fax_adjust_b23_command(dword Id, PLCI *plci, byte Rc)
  13070. {
  13071. word Info;
  13072. word internal_command;
  13073. dbug(1, dprintf("[%06lx] %s,%d: fax_adjust_b23_command %02x %04x",
  13074. UnMapId(Id), (char *)(FILE_), __LINE__, Rc, plci->internal_command));
  13075. Info = GOOD;
  13076. internal_command = plci->internal_command;
  13077. plci->internal_command = 0;
  13078. switch (internal_command)
  13079. {
  13080. default:
  13081. plci->command = 0;
  13082. plci->adjust_b_parms_msg = NULL;
  13083. plci->adjust_b_facilities = plci->B1_facilities;
  13084. plci->adjust_b_command = FAX_ADJUST_B23_COMMAND_1;
  13085. plci->adjust_b_ncci = (word)(Id >> 16);
  13086. plci->adjust_b_mode = ADJUST_B_MODE_REMOVE_L23 | ADJUST_B_MODE_ASSIGN_L23;
  13087. plci->adjust_b_state = ADJUST_B_START;
  13088. dbug(1, dprintf("[%06lx] %s,%d: FAX adjust B23...",
  13089. UnMapId(Id), (char *)(FILE_), __LINE__));
  13090. case FAX_ADJUST_B23_COMMAND_1:
  13091. Info = adjust_b_process(Id, plci, Rc);
  13092. if (Info != GOOD)
  13093. {
  13094. dbug(1, dprintf("[%06lx] %s,%d: FAX adjust failed",
  13095. UnMapId(Id), (char *)(FILE_), __LINE__));
  13096. break;
  13097. }
  13098. if (plci->internal_command)
  13099. return;
  13100. case FAX_ADJUST_B23_COMMAND_2:
  13101. if (plci_nl_busy(plci))
  13102. {
  13103. plci->internal_command = FAX_ADJUST_B23_COMMAND_2;
  13104. return;
  13105. }
  13106. plci->command = _CONNECT_B3_R;
  13107. nl_req_ncci(plci, N_CONNECT, 0);
  13108. send_req(plci);
  13109. return;
  13110. }
  13111. sendf(plci->appl, _CONNECT_B3_R | CONFIRM, Id, plci->number, "w", Info);
  13112. }
  13113. static void fax_disconnect_command(dword Id, PLCI *plci, byte Rc)
  13114. {
  13115. word internal_command;
  13116. dbug(1, dprintf("[%06lx] %s,%d: fax_disconnect_command %02x %04x",
  13117. UnMapId(Id), (char *)(FILE_), __LINE__, Rc, plci->internal_command));
  13118. internal_command = plci->internal_command;
  13119. plci->internal_command = 0;
  13120. switch (internal_command)
  13121. {
  13122. default:
  13123. plci->command = 0;
  13124. plci->internal_command = FAX_DISCONNECT_COMMAND_1;
  13125. return;
  13126. case FAX_DISCONNECT_COMMAND_1:
  13127. case FAX_DISCONNECT_COMMAND_2:
  13128. case FAX_DISCONNECT_COMMAND_3:
  13129. if ((Rc != OK) && (Rc != OK_FC) && (Rc != 0))
  13130. {
  13131. dbug(1, dprintf("[%06lx] %s,%d: FAX disconnect EDATA failed %02x",
  13132. UnMapId(Id), (char *)(FILE_), __LINE__, Rc));
  13133. break;
  13134. }
  13135. if (Rc == OK)
  13136. {
  13137. if ((internal_command == FAX_DISCONNECT_COMMAND_1)
  13138. || (internal_command == FAX_DISCONNECT_COMMAND_2))
  13139. {
  13140. plci->internal_command = FAX_DISCONNECT_COMMAND_2;
  13141. }
  13142. }
  13143. else if (Rc == 0)
  13144. {
  13145. if (internal_command == FAX_DISCONNECT_COMMAND_1)
  13146. plci->internal_command = FAX_DISCONNECT_COMMAND_3;
  13147. }
  13148. return;
  13149. }
  13150. }
  13151. static void rtp_connect_b3_req_command(dword Id, PLCI *plci, byte Rc)
  13152. {
  13153. word Info;
  13154. word internal_command;
  13155. dbug(1, dprintf("[%06lx] %s,%d: rtp_connect_b3_req_command %02x %04x",
  13156. UnMapId(Id), (char *)(FILE_), __LINE__, Rc, plci->internal_command));
  13157. Info = GOOD;
  13158. internal_command = plci->internal_command;
  13159. plci->internal_command = 0;
  13160. switch (internal_command)
  13161. {
  13162. default:
  13163. plci->command = 0;
  13164. case RTP_CONNECT_B3_REQ_COMMAND_1:
  13165. if (plci_nl_busy(plci))
  13166. {
  13167. plci->internal_command = RTP_CONNECT_B3_REQ_COMMAND_1;
  13168. return;
  13169. }
  13170. plci->internal_command = RTP_CONNECT_B3_REQ_COMMAND_2;
  13171. nl_req_ncci(plci, N_CONNECT, 0);
  13172. send_req(plci);
  13173. return;
  13174. case RTP_CONNECT_B3_REQ_COMMAND_2:
  13175. if ((Rc != OK) && (Rc != OK_FC))
  13176. {
  13177. dbug(1, dprintf("[%06lx] %s,%d: RTP setting connect info failed %02x",
  13178. UnMapId(Id), (char *)(FILE_), __LINE__, Rc));
  13179. Info = _WRONG_STATE;
  13180. break;
  13181. }
  13182. if (plci_nl_busy(plci))
  13183. {
  13184. plci->internal_command = RTP_CONNECT_B3_REQ_COMMAND_2;
  13185. return;
  13186. }
  13187. plci->internal_command = RTP_CONNECT_B3_REQ_COMMAND_3;
  13188. plci->NData[0].PLength = plci->internal_req_buffer[0];
  13189. plci->NData[0].P = plci->internal_req_buffer + 1;
  13190. plci->NL.X = plci->NData;
  13191. plci->NL.ReqCh = 0;
  13192. plci->NL.Req = plci->nl_req = (byte) N_UDATA;
  13193. plci->adapter->request(&plci->NL);
  13194. break;
  13195. case RTP_CONNECT_B3_REQ_COMMAND_3:
  13196. return;
  13197. }
  13198. sendf(plci->appl, _CONNECT_B3_R | CONFIRM, Id, plci->number, "w", Info);
  13199. }
  13200. static void rtp_connect_b3_res_command(dword Id, PLCI *plci, byte Rc)
  13201. {
  13202. word internal_command;
  13203. dbug(1, dprintf("[%06lx] %s,%d: rtp_connect_b3_res_command %02x %04x",
  13204. UnMapId(Id), (char *)(FILE_), __LINE__, Rc, plci->internal_command));
  13205. internal_command = plci->internal_command;
  13206. plci->internal_command = 0;
  13207. switch (internal_command)
  13208. {
  13209. default:
  13210. plci->command = 0;
  13211. case RTP_CONNECT_B3_RES_COMMAND_1:
  13212. if (plci_nl_busy(plci))
  13213. {
  13214. plci->internal_command = RTP_CONNECT_B3_RES_COMMAND_1;
  13215. return;
  13216. }
  13217. plci->internal_command = RTP_CONNECT_B3_RES_COMMAND_2;
  13218. nl_req_ncci(plci, N_CONNECT_ACK, (byte)(Id >> 16));
  13219. send_req(plci);
  13220. return;
  13221. case RTP_CONNECT_B3_RES_COMMAND_2:
  13222. if ((Rc != OK) && (Rc != OK_FC))
  13223. {
  13224. dbug(1, dprintf("[%06lx] %s,%d: RTP setting connect resp info failed %02x",
  13225. UnMapId(Id), (char *)(FILE_), __LINE__, Rc));
  13226. break;
  13227. }
  13228. if (plci_nl_busy(plci))
  13229. {
  13230. plci->internal_command = RTP_CONNECT_B3_RES_COMMAND_2;
  13231. return;
  13232. }
  13233. sendf(plci->appl, _CONNECT_B3_ACTIVE_I, Id, 0, "s", "");
  13234. plci->internal_command = RTP_CONNECT_B3_RES_COMMAND_3;
  13235. plci->NData[0].PLength = plci->internal_req_buffer[0];
  13236. plci->NData[0].P = plci->internal_req_buffer + 1;
  13237. plci->NL.X = plci->NData;
  13238. plci->NL.ReqCh = 0;
  13239. plci->NL.Req = plci->nl_req = (byte) N_UDATA;
  13240. plci->adapter->request(&plci->NL);
  13241. return;
  13242. case RTP_CONNECT_B3_RES_COMMAND_3:
  13243. return;
  13244. }
  13245. }
  13246. static void hold_save_command(dword Id, PLCI *plci, byte Rc)
  13247. {
  13248. byte SS_Ind[] = "\x05\x02\x00\x02\x00\x00"; /* Hold_Ind struct*/
  13249. word Info;
  13250. word internal_command;
  13251. dbug(1, dprintf("[%06lx] %s,%d: hold_save_command %02x %04x",
  13252. UnMapId(Id), (char *)(FILE_), __LINE__, Rc, plci->internal_command));
  13253. Info = GOOD;
  13254. internal_command = plci->internal_command;
  13255. plci->internal_command = 0;
  13256. switch (internal_command)
  13257. {
  13258. default:
  13259. if (!plci->NL.Id)
  13260. break;
  13261. plci->command = 0;
  13262. plci->adjust_b_parms_msg = NULL;
  13263. plci->adjust_b_facilities = plci->B1_facilities;
  13264. plci->adjust_b_command = HOLD_SAVE_COMMAND_1;
  13265. plci->adjust_b_ncci = (word)(Id >> 16);
  13266. plci->adjust_b_mode = ADJUST_B_MODE_SAVE | ADJUST_B_MODE_REMOVE_L23;
  13267. plci->adjust_b_state = ADJUST_B_START;
  13268. dbug(1, dprintf("[%06lx] %s,%d: HOLD save...",
  13269. UnMapId(Id), (char *)(FILE_), __LINE__));
  13270. case HOLD_SAVE_COMMAND_1:
  13271. Info = adjust_b_process(Id, plci, Rc);
  13272. if (Info != GOOD)
  13273. {
  13274. dbug(1, dprintf("[%06lx] %s,%d: HOLD save failed",
  13275. UnMapId(Id), (char *)(FILE_), __LINE__));
  13276. break;
  13277. }
  13278. if (plci->internal_command)
  13279. return;
  13280. }
  13281. sendf(plci->appl, _FACILITY_I, Id & 0xffffL, 0, "ws", 3, SS_Ind);
  13282. }
  13283. static void retrieve_restore_command(dword Id, PLCI *plci, byte Rc)
  13284. {
  13285. byte SS_Ind[] = "\x05\x03\x00\x02\x00\x00"; /* Retrieve_Ind struct*/
  13286. word Info;
  13287. word internal_command;
  13288. dbug(1, dprintf("[%06lx] %s,%d: retrieve_restore_command %02x %04x",
  13289. UnMapId(Id), (char *)(FILE_), __LINE__, Rc, plci->internal_command));
  13290. Info = GOOD;
  13291. internal_command = plci->internal_command;
  13292. plci->internal_command = 0;
  13293. switch (internal_command)
  13294. {
  13295. default:
  13296. plci->command = 0;
  13297. plci->adjust_b_parms_msg = NULL;
  13298. plci->adjust_b_facilities = plci->B1_facilities;
  13299. plci->adjust_b_command = RETRIEVE_RESTORE_COMMAND_1;
  13300. plci->adjust_b_ncci = (word)(Id >> 16);
  13301. plci->adjust_b_mode = ADJUST_B_MODE_ASSIGN_L23 | ADJUST_B_MODE_USER_CONNECT | ADJUST_B_MODE_RESTORE;
  13302. plci->adjust_b_state = ADJUST_B_START;
  13303. dbug(1, dprintf("[%06lx] %s,%d: RETRIEVE restore...",
  13304. UnMapId(Id), (char *)(FILE_), __LINE__));
  13305. case RETRIEVE_RESTORE_COMMAND_1:
  13306. Info = adjust_b_process(Id, plci, Rc);
  13307. if (Info != GOOD)
  13308. {
  13309. dbug(1, dprintf("[%06lx] %s,%d: RETRIEVE restore failed",
  13310. UnMapId(Id), (char *)(FILE_), __LINE__));
  13311. break;
  13312. }
  13313. if (plci->internal_command)
  13314. return;
  13315. }
  13316. sendf(plci->appl, _FACILITY_I, Id & 0xffffL, 0, "ws", 3, SS_Ind);
  13317. }
  13318. static void init_b1_config(PLCI *plci)
  13319. {
  13320. dbug(1, dprintf("[%06lx] %s,%d: init_b1_config",
  13321. (dword)((plci->Id << 8) | UnMapController(plci->adapter->Id)),
  13322. (char *)(FILE_), __LINE__));
  13323. plci->B1_resource = 0;
  13324. plci->B1_facilities = 0;
  13325. plci->li_bchannel_id = 0;
  13326. mixer_clear_config(plci);
  13327. ec_clear_config(plci);
  13328. dtmf_rec_clear_config(plci);
  13329. dtmf_send_clear_config(plci);
  13330. dtmf_parameter_clear_config(plci);
  13331. adv_voice_clear_config(plci);
  13332. adjust_b_clear(plci);
  13333. }
  13334. static void clear_b1_config(PLCI *plci)
  13335. {
  13336. dbug(1, dprintf("[%06lx] %s,%d: clear_b1_config",
  13337. (dword)((plci->Id << 8) | UnMapController(plci->adapter->Id)),
  13338. (char *)(FILE_), __LINE__));
  13339. adv_voice_clear_config(plci);
  13340. adjust_b_clear(plci);
  13341. ec_clear_config(plci);
  13342. dtmf_rec_clear_config(plci);
  13343. dtmf_send_clear_config(plci);
  13344. dtmf_parameter_clear_config(plci);
  13345. if ((plci->li_bchannel_id != 0)
  13346. && (li_config_table[plci->adapter->li_base + (plci->li_bchannel_id - 1)].plci == plci))
  13347. {
  13348. mixer_clear_config(plci);
  13349. li_config_table[plci->adapter->li_base + (plci->li_bchannel_id - 1)].plci = NULL;
  13350. plci->li_bchannel_id = 0;
  13351. }
  13352. plci->B1_resource = 0;
  13353. plci->B1_facilities = 0;
  13354. }
  13355. /* -----------------------------------------------------------------
  13356. XON protocol local helpers
  13357. ----------------------------------------------------------------- */
  13358. static void channel_flow_control_remove(PLCI *plci) {
  13359. DIVA_CAPI_ADAPTER *a = plci->adapter;
  13360. word i;
  13361. for (i = 1; i < MAX_NL_CHANNEL + 1; i++) {
  13362. if (a->ch_flow_plci[i] == plci->Id) {
  13363. a->ch_flow_plci[i] = 0;
  13364. a->ch_flow_control[i] = 0;
  13365. }
  13366. }
  13367. }
  13368. static void channel_x_on(PLCI *plci, byte ch) {
  13369. DIVA_CAPI_ADAPTER *a = plci->adapter;
  13370. if (a->ch_flow_control[ch] & N_XON_SENT) {
  13371. a->ch_flow_control[ch] &= ~N_XON_SENT;
  13372. }
  13373. }
  13374. static void channel_x_off(PLCI *plci, byte ch, byte flag) {
  13375. DIVA_CAPI_ADAPTER *a = plci->adapter;
  13376. if ((a->ch_flow_control[ch] & N_RX_FLOW_CONTROL_MASK) == 0) {
  13377. a->ch_flow_control[ch] |= (N_CH_XOFF | flag);
  13378. a->ch_flow_plci[ch] = plci->Id;
  13379. a->ch_flow_control_pending++;
  13380. }
  13381. }
  13382. static void channel_request_xon(PLCI *plci, byte ch) {
  13383. DIVA_CAPI_ADAPTER *a = plci->adapter;
  13384. if (a->ch_flow_control[ch] & N_CH_XOFF) {
  13385. a->ch_flow_control[ch] |= N_XON_REQ;
  13386. a->ch_flow_control[ch] &= ~N_CH_XOFF;
  13387. a->ch_flow_control[ch] &= ~N_XON_CONNECT_IND;
  13388. }
  13389. }
  13390. static void channel_xmit_extended_xon(PLCI *plci) {
  13391. DIVA_CAPI_ADAPTER *a;
  13392. int max_ch = ARRAY_SIZE(a->ch_flow_control);
  13393. int i, one_requested = 0;
  13394. if ((!plci) || (!plci->Id) || ((a = plci->adapter) == NULL)) {
  13395. return;
  13396. }
  13397. for (i = 0; i < max_ch; i++) {
  13398. if ((a->ch_flow_control[i] & N_CH_XOFF) &&
  13399. (a->ch_flow_control[i] & N_XON_CONNECT_IND) &&
  13400. (plci->Id == a->ch_flow_plci[i])) {
  13401. channel_request_xon(plci, (byte)i);
  13402. one_requested = 1;
  13403. }
  13404. }
  13405. if (one_requested) {
  13406. channel_xmit_xon(plci);
  13407. }
  13408. }
  13409. /*
  13410. Try to xmit next X_ON
  13411. */
  13412. static int find_channel_with_pending_x_on(DIVA_CAPI_ADAPTER *a, PLCI *plci) {
  13413. int max_ch = ARRAY_SIZE(a->ch_flow_control);
  13414. int i;
  13415. if (!(plci->adapter->manufacturer_features & MANUFACTURER_FEATURE_XONOFF_FLOW_CONTROL)) {
  13416. return (0);
  13417. }
  13418. if (a->last_flow_control_ch >= max_ch) {
  13419. a->last_flow_control_ch = 1;
  13420. }
  13421. for (i = a->last_flow_control_ch; i < max_ch; i++) {
  13422. if ((a->ch_flow_control[i] & N_XON_REQ) &&
  13423. (plci->Id == a->ch_flow_plci[i])) {
  13424. a->last_flow_control_ch = i + 1;
  13425. return (i);
  13426. }
  13427. }
  13428. for (i = 1; i < a->last_flow_control_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. return (0);
  13436. }
  13437. static void channel_xmit_xon(PLCI *plci) {
  13438. DIVA_CAPI_ADAPTER *a = plci->adapter;
  13439. byte ch;
  13440. if (plci->nl_req || !plci->NL.Id || plci->nl_remove_id) {
  13441. return;
  13442. }
  13443. if ((ch = (byte)find_channel_with_pending_x_on(a, plci)) == 0) {
  13444. return;
  13445. }
  13446. a->ch_flow_control[ch] &= ~N_XON_REQ;
  13447. a->ch_flow_control[ch] |= N_XON_SENT;
  13448. plci->NL.Req = plci->nl_req = (byte)N_XON;
  13449. plci->NL.ReqCh = ch;
  13450. plci->NL.X = plci->NData;
  13451. plci->NL.XNum = 1;
  13452. plci->NData[0].P = &plci->RBuffer[0];
  13453. plci->NData[0].PLength = 0;
  13454. plci->adapter->request(&plci->NL);
  13455. }
  13456. static int channel_can_xon(PLCI *plci, byte ch) {
  13457. APPL *APPLptr;
  13458. DIVA_CAPI_ADAPTER *a;
  13459. word NCCIcode;
  13460. dword count;
  13461. word Num;
  13462. word i;
  13463. APPLptr = plci->appl;
  13464. a = plci->adapter;
  13465. if (!APPLptr)
  13466. return (0);
  13467. NCCIcode = a->ch_ncci[ch] | (((word) a->Id) << 8);
  13468. /* count all buffers within the Application pool */
  13469. /* belonging to the same NCCI. XON if a first is */
  13470. /* used. */
  13471. count = 0;
  13472. Num = 0xffff;
  13473. for (i = 0; i < APPLptr->MaxBuffer; i++) {
  13474. if (NCCIcode == APPLptr->DataNCCI[i]) count++;
  13475. if (!APPLptr->DataNCCI[i] && Num == 0xffff) Num = i;
  13476. }
  13477. if ((count > 2) || (Num == 0xffff)) {
  13478. return (0);
  13479. }
  13480. return (1);
  13481. }
  13482. /*------------------------------------------------------------------*/
  13483. static word CPN_filter_ok(byte *cpn, DIVA_CAPI_ADAPTER *a, word offset)
  13484. {
  13485. return 1;
  13486. }
  13487. /**********************************************************************************/
  13488. /* function groups the listening applications according to the CIP mask and the */
  13489. /* Info_Mask. Each group gets just one Connect_Ind. Some application manufacturer */
  13490. /* are not multi-instance capable, so they start e.g. 30 applications what causes */
  13491. /* big problems on application level (one call, 30 Connect_Ind, ect). The */
  13492. /* function must be enabled by setting "a->group_optimization_enabled" from the */
  13493. /* OS specific part (per adapter). */
  13494. /**********************************************************************************/
  13495. static void group_optimization(DIVA_CAPI_ADAPTER *a, PLCI *plci)
  13496. {
  13497. word i, j, k, busy, group_found;
  13498. dword info_mask_group[MAX_CIP_TYPES];
  13499. dword cip_mask_group[MAX_CIP_TYPES];
  13500. word appl_number_group_type[MAX_APPL];
  13501. PLCI *auxplci;
  13502. set_group_ind_mask(plci); /* all APPLs within this inc. call are allowed to dial in */
  13503. if (!a->group_optimization_enabled)
  13504. {
  13505. dbug(1, dprintf("No group optimization"));
  13506. return;
  13507. }
  13508. dbug(1, dprintf("Group optimization = 0x%x...", a->group_optimization_enabled));
  13509. for (i = 0; i < MAX_CIP_TYPES; i++)
  13510. {
  13511. info_mask_group[i] = 0;
  13512. cip_mask_group[i] = 0;
  13513. }
  13514. for (i = 0; i < MAX_APPL; i++)
  13515. {
  13516. appl_number_group_type[i] = 0;
  13517. }
  13518. for (i = 0; i < max_appl; i++) /* check if any multi instance capable application is present */
  13519. { /* group_optimization set to 1 means not to optimize multi-instance capable applications (default) */
  13520. if (application[i].Id && (application[i].MaxNCCI) > 1 && (a->CIP_Mask[i]) && (a->group_optimization_enabled == 1))
  13521. {
  13522. dbug(1, dprintf("Multi-Instance capable, no optimization required"));
  13523. return; /* allow good application unfiltered access */
  13524. }
  13525. }
  13526. for (i = 0; i < max_appl; i++) /* Build CIP Groups */
  13527. {
  13528. if (application[i].Id && a->CIP_Mask[i])
  13529. {
  13530. for (k = 0, busy = false; k < a->max_plci; k++)
  13531. {
  13532. if (a->plci[k].Id)
  13533. {
  13534. auxplci = &a->plci[k];
  13535. if (auxplci->appl == &application[i]) /* application has a busy PLCI */
  13536. {
  13537. busy = true;
  13538. dbug(1, dprintf("Appl 0x%x is busy", i + 1));
  13539. }
  13540. else if (test_c_ind_mask_bit(auxplci, i)) /* application has an incoming call pending */
  13541. {
  13542. busy = true;
  13543. dbug(1, dprintf("Appl 0x%x has inc. call pending", i + 1));
  13544. }
  13545. }
  13546. }
  13547. for (j = 0, group_found = 0; j <= (MAX_CIP_TYPES) && !busy && !group_found; j++) /* build groups with free applications only */
  13548. {
  13549. if (j == MAX_CIP_TYPES) /* all groups are in use but group still not found */
  13550. { /* the MAX_CIP_TYPES group enables all calls because of field overflow */
  13551. appl_number_group_type[i] = MAX_CIP_TYPES;
  13552. group_found = true;
  13553. dbug(1, dprintf("Field overflow appl 0x%x", i + 1));
  13554. }
  13555. else if ((info_mask_group[j] == a->CIP_Mask[i]) && (cip_mask_group[j] == a->Info_Mask[i]))
  13556. { /* is group already present ? */
  13557. appl_number_group_type[i] = j | 0x80; /* store the group number for each application */
  13558. group_found = true;
  13559. 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]));
  13560. }
  13561. else if (!info_mask_group[j])
  13562. { /* establish a new group */
  13563. appl_number_group_type[i] = j | 0x80; /* store the group number for each application */
  13564. info_mask_group[j] = a->CIP_Mask[i]; /* store the new CIP mask for the new group */
  13565. cip_mask_group[j] = a->Info_Mask[i]; /* store the new Info_Mask for this new group */
  13566. group_found = true;
  13567. 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]));
  13568. }
  13569. }
  13570. }
  13571. }
  13572. for (i = 0; i < max_appl; i++) /* Build group_optimization_mask_table */
  13573. {
  13574. if (appl_number_group_type[i]) /* application is free, has listens and is member of a group */
  13575. {
  13576. if (appl_number_group_type[i] == MAX_CIP_TYPES)
  13577. {
  13578. dbug(1, dprintf("OverflowGroup 0x%x, valid appl = 0x%x, call enabled", appl_number_group_type[i], i + 1));
  13579. }
  13580. else
  13581. {
  13582. dbug(1, dprintf("Group 0x%x, valid appl = 0x%x", appl_number_group_type[i], i + 1));
  13583. for (j = i + 1; j < max_appl; j++) /* search other group members and mark them as busy */
  13584. {
  13585. if (appl_number_group_type[i] == appl_number_group_type[j])
  13586. {
  13587. dbug(1, dprintf("Appl 0x%x is member of group 0x%x, no call", j + 1, appl_number_group_type[j]));
  13588. clear_group_ind_mask_bit(plci, j); /* disable call on other group members */
  13589. appl_number_group_type[j] = 0; /* remove disabled group member from group list */
  13590. }
  13591. }
  13592. }
  13593. }
  13594. else /* application should not get a call */
  13595. {
  13596. clear_group_ind_mask_bit(plci, i);
  13597. }
  13598. }
  13599. }
  13600. /* OS notifies the driver about a application Capi_Register */
  13601. word CapiRegister(word id)
  13602. {
  13603. word i, j, appls_found;
  13604. PLCI *plci;
  13605. DIVA_CAPI_ADAPTER *a;
  13606. for (i = 0, appls_found = 0; i < max_appl; i++)
  13607. {
  13608. if (application[i].Id && (application[i].Id != id))
  13609. {
  13610. appls_found++; /* an application has been found */
  13611. }
  13612. }
  13613. if (appls_found) return true;
  13614. for (i = 0; i < max_adapter; i++) /* scan all adapters... */
  13615. {
  13616. a = &adapter[i];
  13617. if (a->request)
  13618. {
  13619. if (a->flag_dynamic_l1_down) /* remove adapter from L1 tristate (Huntgroup) */
  13620. {
  13621. if (!appls_found) /* first application does a capi register */
  13622. {
  13623. if ((j = get_plci(a))) /* activate L1 of all adapters */
  13624. {
  13625. plci = &a->plci[j - 1];
  13626. plci->command = 0;
  13627. add_p(plci, OAD, "\x01\xfd");
  13628. add_p(plci, CAI, "\x01\x80");
  13629. add_p(plci, UID, "\x06\x43\x61\x70\x69\x32\x30");
  13630. add_p(plci, SHIFT | 6, NULL);
  13631. add_p(plci, SIN, "\x02\x00\x00");
  13632. plci->internal_command = START_L1_SIG_ASSIGN_PEND;
  13633. sig_req(plci, ASSIGN, DSIG_ID);
  13634. add_p(plci, FTY, "\x02\xff\x07"); /* l1 start */
  13635. sig_req(plci, SIG_CTRL, 0);
  13636. send_req(plci);
  13637. }
  13638. }
  13639. }
  13640. }
  13641. }
  13642. return false;
  13643. }
  13644. /*------------------------------------------------------------------*/
  13645. /* Functions for virtual Switching e.g. Transfer by join, Conference */
  13646. static void VSwitchReqInd(PLCI *plci, dword Id, byte **parms)
  13647. {
  13648. word i;
  13649. /* Format of vswitch_t:
  13650. 0 byte length
  13651. 1 byte VSWITCHIE
  13652. 2 byte VSWITCH_REQ/VSWITCH_IND
  13653. 3 byte reserved
  13654. 4 word VSwitchcommand
  13655. 6 word returnerror
  13656. 8... Params
  13657. */
  13658. if (!plci ||
  13659. !plci->appl ||
  13660. !plci->State ||
  13661. plci->Sig.Ind == NCR_FACILITY
  13662. )
  13663. return;
  13664. for (i = 0; i < MAX_MULTI_IE; i++)
  13665. {
  13666. if (!parms[i][0]) continue;
  13667. if (parms[i][0] < 7)
  13668. {
  13669. parms[i][0] = 0; /* kill it */
  13670. continue;
  13671. }
  13672. dbug(1, dprintf("VSwitchReqInd(%d)", parms[i][4]));
  13673. switch (parms[i][4])
  13674. {
  13675. case VSJOIN:
  13676. if (!plci->relatedPTYPLCI ||
  13677. (plci->ptyState != S_ECT && plci->relatedPTYPLCI->ptyState != S_ECT))
  13678. { /* Error */
  13679. break;
  13680. }
  13681. /* remember all necessary informations */
  13682. if (parms[i][0] != 11 || parms[i][8] != 3) /* Length Test */
  13683. {
  13684. break;
  13685. }
  13686. if (parms[i][2] == VSWITCH_IND && parms[i][9] == 1)
  13687. { /* first indication after ECT-Request on Consultation Call */
  13688. plci->vswitchstate = parms[i][9];
  13689. parms[i][9] = 2; /* State */
  13690. /* now ask first Call to join */
  13691. }
  13692. else if (parms[i][2] == VSWITCH_REQ && parms[i][9] == 3)
  13693. { /* Answer of VSWITCH_REQ from first Call */
  13694. plci->vswitchstate = parms[i][9];
  13695. /* tell consultation call to join
  13696. and the protocol capabilities of the first call */
  13697. }
  13698. else
  13699. { /* Error */
  13700. break;
  13701. }
  13702. plci->vsprot = parms[i][10]; /* protocol */
  13703. plci->vsprotdialect = parms[i][11]; /* protocoldialect */
  13704. /* send join request to related PLCI */
  13705. parms[i][1] = VSWITCHIE;
  13706. parms[i][2] = VSWITCH_REQ;
  13707. plci->relatedPTYPLCI->command = 0;
  13708. plci->relatedPTYPLCI->internal_command = VSWITCH_REQ_PEND;
  13709. add_p(plci->relatedPTYPLCI, ESC, &parms[i][0]);
  13710. sig_req(plci->relatedPTYPLCI, VSWITCH_REQ, 0);
  13711. send_req(plci->relatedPTYPLCI);
  13712. break;
  13713. case VSTRANSPORT:
  13714. default:
  13715. if (plci->relatedPTYPLCI &&
  13716. plci->vswitchstate == 3 &&
  13717. plci->relatedPTYPLCI->vswitchstate == 3)
  13718. {
  13719. add_p(plci->relatedPTYPLCI, ESC, &parms[i][0]);
  13720. sig_req(plci->relatedPTYPLCI, VSWITCH_REQ, 0);
  13721. send_req(plci->relatedPTYPLCI);
  13722. }
  13723. break;
  13724. }
  13725. parms[i][0] = 0; /* kill it */
  13726. }
  13727. }
  13728. /*------------------------------------------------------------------*/
  13729. static int diva_get_dma_descriptor(PLCI *plci, dword *dma_magic) {
  13730. ENTITY e;
  13731. IDI_SYNC_REQ *pReq = (IDI_SYNC_REQ *)&e;
  13732. if (!(diva_xdi_extended_features & DIVA_CAPI_XDI_PROVIDES_RX_DMA)) {
  13733. return (-1);
  13734. }
  13735. pReq->xdi_dma_descriptor_operation.Req = 0;
  13736. pReq->xdi_dma_descriptor_operation.Rc = IDI_SYNC_REQ_DMA_DESCRIPTOR_OPERATION;
  13737. pReq->xdi_dma_descriptor_operation.info.operation = IDI_SYNC_REQ_DMA_DESCRIPTOR_ALLOC;
  13738. pReq->xdi_dma_descriptor_operation.info.descriptor_number = -1;
  13739. pReq->xdi_dma_descriptor_operation.info.descriptor_address = NULL;
  13740. pReq->xdi_dma_descriptor_operation.info.descriptor_magic = 0;
  13741. e.user[0] = plci->adapter->Id - 1;
  13742. plci->adapter->request((ENTITY *)pReq);
  13743. if (!pReq->xdi_dma_descriptor_operation.info.operation &&
  13744. (pReq->xdi_dma_descriptor_operation.info.descriptor_number >= 0) &&
  13745. pReq->xdi_dma_descriptor_operation.info.descriptor_magic) {
  13746. *dma_magic = pReq->xdi_dma_descriptor_operation.info.descriptor_magic;
  13747. dbug(3, dprintf("dma_alloc, a:%d (%d-%08x)",
  13748. plci->adapter->Id,
  13749. pReq->xdi_dma_descriptor_operation.info.descriptor_number,
  13750. *dma_magic));
  13751. return (pReq->xdi_dma_descriptor_operation.info.descriptor_number);
  13752. } else {
  13753. dbug(1, dprintf("dma_alloc failed"));
  13754. return (-1);
  13755. }
  13756. }
  13757. static void diva_free_dma_descriptor(PLCI *plci, int nr) {
  13758. ENTITY e;
  13759. IDI_SYNC_REQ *pReq = (IDI_SYNC_REQ *)&e;
  13760. if (nr < 0) {
  13761. return;
  13762. }
  13763. pReq->xdi_dma_descriptor_operation.Req = 0;
  13764. pReq->xdi_dma_descriptor_operation.Rc = IDI_SYNC_REQ_DMA_DESCRIPTOR_OPERATION;
  13765. pReq->xdi_dma_descriptor_operation.info.operation = IDI_SYNC_REQ_DMA_DESCRIPTOR_FREE;
  13766. pReq->xdi_dma_descriptor_operation.info.descriptor_number = nr;
  13767. pReq->xdi_dma_descriptor_operation.info.descriptor_address = NULL;
  13768. pReq->xdi_dma_descriptor_operation.info.descriptor_magic = 0;
  13769. e.user[0] = plci->adapter->Id - 1;
  13770. plci->adapter->request((ENTITY *)pReq);
  13771. if (!pReq->xdi_dma_descriptor_operation.info.operation) {
  13772. dbug(1, dprintf("dma_free(%d)", nr));
  13773. } else {
  13774. dbug(1, dprintf("dma_free failed (%d)", nr));
  13775. }
  13776. }
  13777. /*------------------------------------------------------------------*/