message.c 435 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521752275237524752575267527752875297530753175327533753475357536753775387539754075417542754375447545754675477548754975507551755275537554755575567557755875597560756175627563756475657566756775687569757075717572757375747575757675777578757975807581758275837584758575867587758875897590759175927593759475957596759775987599760076017602760376047605760676077608760976107611761276137614761576167617761876197620762176227623762476257626762776287629763076317632763376347635763676377638763976407641764276437644764576467647764876497650765176527653765476557656765776587659766076617662766376647665766676677668766976707671767276737674767576767677767876797680768176827683768476857686768776887689769076917692769376947695769676977698769977007701770277037704770577067707770877097710771177127713771477157716771777187719772077217722772377247725772677277728772977307731773277337734773577367737773877397740774177427743774477457746774777487749775077517752775377547755775677577758775977607761776277637764776577667767776877697770777177727773777477757776777777787779778077817782778377847785778677877788778977907791779277937794779577967797779877997800780178027803780478057806780778087809781078117812781378147815781678177818781978207821782278237824782578267827782878297830783178327833783478357836783778387839784078417842784378447845784678477848784978507851785278537854785578567857785878597860786178627863786478657866786778687869787078717872787378747875787678777878787978807881788278837884788578867887788878897890789178927893789478957896789778987899790079017902790379047905790679077908790979107911791279137914791579167917791879197920792179227923792479257926792779287929793079317932793379347935793679377938793979407941794279437944794579467947794879497950795179527953795479557956795779587959796079617962796379647965796679677968796979707971797279737974797579767977797879797980798179827983798479857986798779887989799079917992799379947995799679977998799980008001800280038004800580068007800880098010801180128013801480158016801780188019802080218022802380248025802680278028802980308031803280338034803580368037803880398040804180428043804480458046804780488049805080518052805380548055805680578058805980608061806280638064806580668067806880698070807180728073807480758076807780788079808080818082808380848085808680878088808980908091809280938094809580968097809880998100810181028103810481058106810781088109811081118112811381148115811681178118811981208121812281238124812581268127812881298130813181328133813481358136813781388139814081418142814381448145814681478148814981508151815281538154815581568157815881598160816181628163816481658166816781688169817081718172817381748175817681778178817981808181818281838184818581868187818881898190819181928193819481958196819781988199820082018202820382048205820682078208820982108211821282138214821582168217821882198220822182228223822482258226822782288229823082318232823382348235823682378238823982408241824282438244824582468247824882498250825182528253825482558256825782588259826082618262826382648265826682678268826982708271827282738274827582768277827882798280828182828283828482858286828782888289829082918292829382948295829682978298829983008301830283038304830583068307830883098310831183128313831483158316831783188319832083218322832383248325832683278328832983308331833283338334833583368337833883398340834183428343834483458346834783488349835083518352835383548355835683578358835983608361836283638364836583668367836883698370837183728373837483758376837783788379838083818382838383848385838683878388838983908391839283938394839583968397839883998400840184028403840484058406840784088409841084118412841384148415841684178418841984208421842284238424842584268427842884298430843184328433843484358436843784388439844084418442844384448445844684478448844984508451845284538454845584568457845884598460846184628463846484658466846784688469847084718472847384748475847684778478847984808481848284838484848584868487848884898490849184928493849484958496849784988499850085018502850385048505850685078508850985108511851285138514851585168517851885198520852185228523852485258526852785288529853085318532853385348535853685378538853985408541854285438544854585468547854885498550855185528553855485558556855785588559856085618562856385648565856685678568856985708571857285738574857585768577857885798580858185828583858485858586858785888589859085918592859385948595859685978598859986008601860286038604860586068607860886098610861186128613861486158616861786188619862086218622862386248625862686278628862986308631863286338634863586368637863886398640864186428643864486458646864786488649865086518652865386548655865686578658865986608661866286638664866586668667866886698670867186728673867486758676867786788679868086818682868386848685868686878688868986908691869286938694869586968697869886998700870187028703870487058706870787088709871087118712871387148715871687178718871987208721872287238724872587268727872887298730873187328733873487358736873787388739874087418742874387448745874687478748874987508751875287538754875587568757875887598760876187628763876487658766876787688769877087718772877387748775877687778778877987808781878287838784878587868787878887898790879187928793879487958796879787988799880088018802880388048805880688078808880988108811881288138814881588168817881888198820882188228823882488258826882788288829883088318832883388348835883688378838883988408841884288438844884588468847884888498850885188528853885488558856885788588859886088618862886388648865886688678868886988708871887288738874887588768877887888798880888188828883888488858886888788888889889088918892889388948895889688978898889989008901890289038904890589068907890889098910891189128913891489158916891789188919892089218922892389248925892689278928892989308931893289338934893589368937893889398940894189428943894489458946894789488949895089518952895389548955895689578958895989608961896289638964896589668967896889698970897189728973897489758976897789788979898089818982898389848985898689878988898989908991899289938994899589968997899889999000900190029003900490059006900790089009901090119012901390149015901690179018901990209021902290239024902590269027902890299030903190329033903490359036903790389039904090419042904390449045904690479048904990509051905290539054905590569057905890599060906190629063906490659066906790689069907090719072907390749075907690779078907990809081908290839084908590869087908890899090909190929093909490959096909790989099910091019102910391049105910691079108910991109111911291139114911591169117911891199120912191229123912491259126912791289129913091319132913391349135913691379138913991409141914291439144914591469147914891499150915191529153915491559156915791589159916091619162916391649165916691679168916991709171917291739174917591769177917891799180918191829183918491859186918791889189919091919192919391949195919691979198919992009201920292039204920592069207920892099210921192129213921492159216921792189219922092219222922392249225922692279228922992309231923292339234923592369237923892399240924192429243924492459246924792489249925092519252925392549255925692579258925992609261926292639264926592669267926892699270927192729273927492759276927792789279928092819282928392849285928692879288928992909291929292939294929592969297929892999300930193029303930493059306930793089309931093119312931393149315931693179318931993209321932293239324932593269327932893299330933193329333933493359336933793389339934093419342934393449345934693479348934993509351935293539354935593569357935893599360936193629363936493659366936793689369937093719372937393749375937693779378937993809381938293839384938593869387938893899390939193929393939493959396939793989399940094019402940394049405940694079408940994109411941294139414941594169417941894199420942194229423942494259426942794289429943094319432943394349435943694379438943994409441944294439444944594469447944894499450945194529453945494559456945794589459946094619462946394649465946694679468946994709471947294739474947594769477947894799480948194829483948494859486948794889489949094919492949394949495949694979498949995009501950295039504950595069507950895099510951195129513951495159516951795189519952095219522952395249525952695279528952995309531953295339534953595369537953895399540954195429543954495459546954795489549955095519552955395549555955695579558955995609561956295639564956595669567956895699570957195729573957495759576957795789579958095819582958395849585958695879588958995909591959295939594959595969597959895999600960196029603960496059606960796089609961096119612961396149615961696179618961996209621962296239624962596269627962896299630963196329633963496359636963796389639964096419642964396449645964696479648964996509651965296539654965596569657965896599660966196629663966496659666966796689669967096719672967396749675967696779678967996809681968296839684968596869687968896899690969196929693969496959696969796989699970097019702970397049705970697079708970997109711971297139714971597169717971897199720972197229723972497259726972797289729973097319732973397349735973697379738973997409741974297439744974597469747974897499750975197529753975497559756975797589759976097619762976397649765976697679768976997709771977297739774977597769777977897799780978197829783978497859786978797889789979097919792979397949795979697979798979998009801980298039804980598069807980898099810981198129813981498159816981798189819982098219822982398249825982698279828982998309831983298339834983598369837983898399840984198429843984498459846984798489849985098519852985398549855985698579858985998609861986298639864986598669867986898699870987198729873987498759876987798789879988098819882988398849885988698879888988998909891989298939894989598969897989898999900990199029903990499059906990799089909991099119912991399149915991699179918991999209921992299239924992599269927992899299930993199329933993499359936993799389939994099419942994399449945994699479948994999509951995299539954995599569957995899599960996199629963996499659966996799689969997099719972997399749975997699779978997999809981998299839984998599869987998899899990999199929993999499959996999799989999100001000110002100031000410005100061000710008100091001010011100121001310014100151001610017100181001910020100211002210023100241002510026100271002810029100301003110032100331003410035100361003710038100391004010041100421004310044100451004610047100481004910050100511005210053100541005510056100571005810059100601006110062100631006410065100661006710068100691007010071100721007310074100751007610077100781007910080100811008210083100841008510086100871008810089100901009110092100931009410095100961009710098100991010010101101021010310104101051010610107101081010910110101111011210113101141011510116101171011810119101201012110122101231012410125101261012710128101291013010131101321013310134101351013610137101381013910140101411014210143101441014510146101471014810149101501015110152101531015410155101561015710158101591016010161101621016310164101651016610167101681016910170101711017210173101741017510176101771017810179101801018110182101831018410185101861018710188101891019010191101921019310194101951019610197101981019910200102011020210203102041020510206102071020810209102101021110212102131021410215102161021710218102191022010221102221022310224102251022610227102281022910230102311023210233102341023510236102371023810239102401024110242102431024410245102461024710248102491025010251102521025310254102551025610257102581025910260102611026210263102641026510266102671026810269102701027110272102731027410275102761027710278102791028010281102821028310284102851028610287102881028910290102911029210293102941029510296102971029810299103001030110302103031030410305103061030710308103091031010311103121031310314103151031610317103181031910320103211032210323103241032510326103271032810329103301033110332103331033410335103361033710338103391034010341103421034310344103451034610347103481034910350103511035210353103541035510356103571035810359103601036110362103631036410365103661036710368103691037010371103721037310374103751037610377103781037910380103811038210383103841038510386103871038810389103901039110392103931039410395103961039710398103991040010401104021040310404104051040610407104081040910410104111041210413104141041510416104171041810419104201042110422104231042410425104261042710428104291043010431104321043310434104351043610437104381043910440104411044210443104441044510446104471044810449104501045110452104531045410455104561045710458104591046010461104621046310464104651046610467104681046910470104711047210473104741047510476104771047810479104801048110482104831048410485104861048710488104891049010491104921049310494104951049610497104981049910500105011050210503105041050510506105071050810509105101051110512105131051410515105161051710518105191052010521105221052310524105251052610527105281052910530105311053210533105341053510536105371053810539105401054110542105431054410545105461054710548105491055010551105521055310554105551055610557105581055910560105611056210563105641056510566105671056810569105701057110572105731057410575105761057710578105791058010581105821058310584105851058610587105881058910590105911059210593105941059510596105971059810599106001060110602106031060410605106061060710608106091061010611106121061310614106151061610617106181061910620106211062210623106241062510626106271062810629106301063110632106331063410635106361063710638106391064010641106421064310644106451064610647106481064910650106511065210653106541065510656106571065810659106601066110662106631066410665106661066710668106691067010671106721067310674106751067610677106781067910680106811068210683106841068510686106871068810689106901069110692106931069410695106961069710698106991070010701107021070310704107051070610707107081070910710107111071210713107141071510716107171071810719107201072110722107231072410725107261072710728107291073010731107321073310734107351073610737107381073910740107411074210743107441074510746107471074810749107501075110752107531075410755107561075710758107591076010761107621076310764107651076610767107681076910770107711077210773107741077510776107771077810779107801078110782107831078410785107861078710788107891079010791107921079310794107951079610797107981079910800108011080210803108041080510806108071080810809108101081110812108131081410815108161081710818108191082010821108221082310824108251082610827108281082910830108311083210833108341083510836108371083810839108401084110842108431084410845108461084710848108491085010851108521085310854108551085610857108581085910860108611086210863108641086510866108671086810869108701087110872108731087410875108761087710878108791088010881108821088310884108851088610887108881088910890108911089210893108941089510896108971089810899109001090110902109031090410905109061090710908109091091010911109121091310914109151091610917109181091910920109211092210923109241092510926109271092810929109301093110932109331093410935109361093710938109391094010941109421094310944109451094610947109481094910950109511095210953109541095510956109571095810959109601096110962109631096410965109661096710968109691097010971109721097310974109751097610977109781097910980109811098210983109841098510986109871098810989109901099110992109931099410995109961099710998109991100011001110021100311004110051100611007110081100911010110111101211013110141101511016110171101811019110201102111022110231102411025110261102711028110291103011031110321103311034110351103611037110381103911040110411104211043110441104511046110471104811049110501105111052110531105411055110561105711058110591106011061110621106311064110651106611067110681106911070110711107211073110741107511076110771107811079110801108111082110831108411085110861108711088110891109011091110921109311094110951109611097110981109911100111011110211103111041110511106111071110811109111101111111112111131111411115111161111711118111191112011121111221112311124111251112611127111281112911130111311113211133111341113511136111371113811139111401114111142111431114411145111461114711148111491115011151111521115311154111551115611157111581115911160111611116211163111641116511166111671116811169111701117111172111731117411175111761117711178111791118011181111821118311184111851118611187111881118911190111911119211193111941119511196111971119811199112001120111202112031120411205112061120711208112091121011211112121121311214112151121611217112181121911220112211122211223112241122511226112271122811229112301123111232112331123411235112361123711238112391124011241112421124311244112451124611247112481124911250112511125211253112541125511256112571125811259112601126111262112631126411265112661126711268112691127011271112721127311274112751127611277112781127911280112811128211283112841128511286112871128811289112901129111292112931129411295112961129711298112991130011301113021130311304113051130611307113081130911310113111131211313113141131511316113171131811319113201132111322113231132411325113261132711328113291133011331113321133311334113351133611337113381133911340113411134211343113441134511346113471134811349113501135111352113531135411355113561135711358113591136011361113621136311364113651136611367113681136911370113711137211373113741137511376113771137811379113801138111382113831138411385113861138711388113891139011391113921139311394113951139611397113981139911400114011140211403114041140511406114071140811409114101141111412114131141411415114161141711418114191142011421114221142311424114251142611427114281142911430114311143211433114341143511436114371143811439114401144111442114431144411445114461144711448114491145011451114521145311454114551145611457114581145911460114611146211463114641146511466114671146811469114701147111472114731147411475114761147711478114791148011481114821148311484114851148611487114881148911490114911149211493114941149511496114971149811499115001150111502115031150411505115061150711508115091151011511115121151311514115151151611517115181151911520115211152211523115241152511526115271152811529115301153111532115331153411535115361153711538115391154011541115421154311544115451154611547115481154911550115511155211553115541155511556115571155811559115601156111562115631156411565115661156711568115691157011571115721157311574115751157611577115781157911580115811158211583115841158511586115871158811589115901159111592115931159411595115961159711598115991160011601116021160311604116051160611607116081160911610116111161211613116141161511616116171161811619116201162111622116231162411625116261162711628116291163011631116321163311634116351163611637116381163911640116411164211643116441164511646116471164811649116501165111652116531165411655116561165711658116591166011661116621166311664116651166611667116681166911670116711167211673116741167511676116771167811679116801168111682116831168411685116861168711688116891169011691116921169311694116951169611697116981169911700117011170211703117041170511706117071170811709117101171111712117131171411715117161171711718117191172011721117221172311724117251172611727117281172911730117311173211733117341173511736117371173811739117401174111742117431174411745117461174711748117491175011751117521175311754117551175611757117581175911760117611176211763117641176511766117671176811769117701177111772117731177411775117761177711778117791178011781117821178311784117851178611787117881178911790117911179211793117941179511796117971179811799118001180111802118031180411805118061180711808118091181011811118121181311814118151181611817118181181911820118211182211823118241182511826118271182811829118301183111832118331183411835118361183711838118391184011841118421184311844118451184611847118481184911850118511185211853118541185511856118571185811859118601186111862118631186411865118661186711868118691187011871118721187311874118751187611877118781187911880118811188211883118841188511886118871188811889118901189111892118931189411895118961189711898118991190011901119021190311904119051190611907119081190911910119111191211913119141191511916119171191811919119201192111922119231192411925119261192711928119291193011931119321193311934119351193611937119381193911940119411194211943119441194511946119471194811949119501195111952119531195411955119561195711958119591196011961119621196311964119651196611967119681196911970119711197211973119741197511976119771197811979119801198111982119831198411985119861198711988119891199011991119921199311994119951199611997119981199912000120011200212003120041200512006120071200812009120101201112012120131201412015120161201712018120191202012021120221202312024120251202612027120281202912030120311203212033120341203512036120371203812039120401204112042120431204412045120461204712048120491205012051120521205312054120551205612057120581205912060120611206212063120641206512066120671206812069120701207112072120731207412075120761207712078120791208012081120821208312084120851208612087120881208912090120911209212093120941209512096120971209812099121001210112102121031210412105121061210712108121091211012111121121211312114121151211612117121181211912120121211212212123121241212512126121271212812129121301213112132121331213412135121361213712138121391214012141121421214312144121451214612147121481214912150121511215212153121541215512156121571215812159121601216112162121631216412165121661216712168121691217012171121721217312174121751217612177121781217912180121811218212183121841218512186121871218812189121901219112192121931219412195121961219712198121991220012201122021220312204122051220612207122081220912210122111221212213122141221512216122171221812219122201222112222122231222412225122261222712228122291223012231122321223312234122351223612237122381223912240122411224212243122441224512246122471224812249122501225112252122531225412255122561225712258122591226012261122621226312264122651226612267122681226912270122711227212273122741227512276122771227812279122801228112282122831228412285122861228712288122891229012291122921229312294122951229612297122981229912300123011230212303123041230512306123071230812309123101231112312123131231412315123161231712318123191232012321123221232312324123251232612327123281232912330123311233212333123341233512336123371233812339123401234112342123431234412345123461234712348123491235012351123521235312354123551235612357123581235912360123611236212363123641236512366123671236812369123701237112372123731237412375123761237712378123791238012381123821238312384123851238612387123881238912390123911239212393123941239512396123971239812399124001240112402124031240412405124061240712408124091241012411124121241312414124151241612417124181241912420124211242212423124241242512426124271242812429124301243112432124331243412435124361243712438124391244012441124421244312444124451244612447124481244912450124511245212453124541245512456124571245812459124601246112462124631246412465124661246712468124691247012471124721247312474124751247612477124781247912480124811248212483124841248512486124871248812489124901249112492124931249412495124961249712498124991250012501125021250312504125051250612507125081250912510125111251212513125141251512516125171251812519125201252112522125231252412525125261252712528125291253012531125321253312534125351253612537125381253912540125411254212543125441254512546125471254812549125501255112552125531255412555125561255712558125591256012561125621256312564125651256612567125681256912570125711257212573125741257512576125771257812579125801258112582125831258412585125861258712588125891259012591125921259312594125951259612597125981259912600126011260212603126041260512606126071260812609126101261112612126131261412615126161261712618126191262012621126221262312624126251262612627126281262912630126311263212633126341263512636126371263812639126401264112642126431264412645126461264712648126491265012651126521265312654126551265612657126581265912660126611266212663126641266512666126671266812669126701267112672126731267412675126761267712678126791268012681126821268312684126851268612687126881268912690126911269212693126941269512696126971269812699127001270112702127031270412705127061270712708127091271012711127121271312714127151271612717127181271912720127211272212723127241272512726127271272812729127301273112732127331273412735127361273712738127391274012741127421274312744127451274612747127481274912750127511275212753127541275512756127571275812759127601276112762127631276412765127661276712768127691277012771127721277312774127751277612777127781277912780127811278212783127841278512786127871278812789127901279112792127931279412795127961279712798127991280012801128021280312804128051280612807128081280912810128111281212813128141281512816128171281812819128201282112822128231282412825128261282712828128291283012831128321283312834128351283612837128381283912840128411284212843128441284512846128471284812849128501285112852128531285412855128561285712858128591286012861128621286312864128651286612867128681286912870128711287212873128741287512876128771287812879128801288112882128831288412885128861288712888128891289012891128921289312894128951289612897128981289912900129011290212903129041290512906129071290812909129101291112912129131291412915129161291712918129191292012921129221292312924129251292612927129281292912930129311293212933129341293512936129371293812939129401294112942129431294412945129461294712948129491295012951129521295312954129551295612957129581295912960129611296212963129641296512966129671296812969129701297112972129731297412975129761297712978129791298012981129821298312984129851298612987129881298912990129911299212993129941299512996129971299812999130001300113002130031300413005130061300713008130091301013011130121301313014130151301613017130181301913020130211302213023130241302513026130271302813029130301303113032130331303413035130361303713038130391304013041130421304313044130451304613047130481304913050130511305213053130541305513056130571305813059130601306113062130631306413065130661306713068130691307013071130721307313074130751307613077130781307913080130811308213083130841308513086130871308813089130901309113092130931309413095130961309713098130991310013101131021310313104131051310613107131081310913110131111311213113131141311513116131171311813119131201312113122131231312413125131261312713128131291313013131131321313313134131351313613137131381313913140131411314213143131441314513146131471314813149131501315113152131531315413155131561315713158131591316013161131621316313164131651316613167131681316913170131711317213173131741317513176131771317813179131801318113182131831318413185131861318713188131891319013191131921319313194131951319613197131981319913200132011320213203132041320513206132071320813209132101321113212132131321413215132161321713218132191322013221132221322313224132251322613227132281322913230132311323213233132341323513236132371323813239132401324113242132431324413245132461324713248132491325013251132521325313254132551325613257132581325913260132611326213263132641326513266132671326813269132701327113272132731327413275132761327713278132791328013281132821328313284132851328613287132881328913290132911329213293132941329513296132971329813299133001330113302133031330413305133061330713308133091331013311133121331313314133151331613317133181331913320133211332213323133241332513326133271332813329133301333113332133331333413335133361333713338133391334013341133421334313344133451334613347133481334913350133511335213353133541335513356133571335813359133601336113362133631336413365133661336713368133691337013371133721337313374133751337613377133781337913380133811338213383133841338513386133871338813389133901339113392133931339413395133961339713398133991340013401134021340313404134051340613407134081340913410134111341213413134141341513416134171341813419134201342113422134231342413425134261342713428134291343013431134321343313434134351343613437134381343913440134411344213443134441344513446134471344813449134501345113452134531345413455134561345713458134591346013461134621346313464134651346613467134681346913470134711347213473134741347513476134771347813479134801348113482134831348413485134861348713488134891349013491134921349313494134951349613497134981349913500135011350213503135041350513506135071350813509135101351113512135131351413515135161351713518135191352013521135221352313524135251352613527135281352913530135311353213533135341353513536135371353813539135401354113542135431354413545135461354713548135491355013551135521355313554135551355613557135581355913560135611356213563135641356513566135671356813569135701357113572135731357413575135761357713578135791358013581135821358313584135851358613587135881358913590135911359213593135941359513596135971359813599136001360113602136031360413605136061360713608136091361013611136121361313614136151361613617136181361913620136211362213623136241362513626136271362813629136301363113632136331363413635136361363713638136391364013641136421364313644136451364613647136481364913650136511365213653136541365513656136571365813659136601366113662136631366413665136661366713668136691367013671136721367313674136751367613677136781367913680136811368213683136841368513686136871368813689136901369113692136931369413695136961369713698136991370013701137021370313704137051370613707137081370913710137111371213713137141371513716137171371813719137201372113722137231372413725137261372713728137291373013731137321373313734137351373613737137381373913740137411374213743137441374513746137471374813749137501375113752137531375413755137561375713758137591376013761137621376313764137651376613767137681376913770137711377213773137741377513776137771377813779137801378113782137831378413785137861378713788137891379013791137921379313794137951379613797137981379913800138011380213803138041380513806138071380813809138101381113812138131381413815138161381713818138191382013821138221382313824138251382613827138281382913830138311383213833138341383513836138371383813839138401384113842138431384413845138461384713848138491385013851138521385313854138551385613857138581385913860138611386213863138641386513866138671386813869138701387113872138731387413875138761387713878138791388013881138821388313884138851388613887138881388913890138911389213893138941389513896138971389813899139001390113902139031390413905139061390713908139091391013911139121391313914139151391613917139181391913920139211392213923139241392513926139271392813929139301393113932139331393413935139361393713938139391394013941139421394313944139451394613947139481394913950139511395213953139541395513956139571395813959139601396113962139631396413965139661396713968139691397013971139721397313974139751397613977139781397913980139811398213983139841398513986139871398813989139901399113992139931399413995139961399713998139991400014001140021400314004140051400614007140081400914010140111401214013140141401514016140171401814019140201402114022140231402414025140261402714028140291403014031140321403314034140351403614037140381403914040140411404214043140441404514046140471404814049140501405114052140531405414055140561405714058140591406014061140621406314064140651406614067140681406914070140711407214073140741407514076140771407814079140801408114082140831408414085140861408714088140891409014091140921409314094140951409614097140981409914100141011410214103141041410514106141071410814109141101411114112141131411414115141161411714118141191412014121141221412314124141251412614127141281412914130141311413214133141341413514136141371413814139141401414114142141431414414145141461414714148141491415014151141521415314154141551415614157141581415914160141611416214163141641416514166141671416814169141701417114172141731417414175141761417714178141791418014181141821418314184141851418614187141881418914190141911419214193141941419514196141971419814199142001420114202142031420414205142061420714208142091421014211142121421314214142151421614217142181421914220142211422214223142241422514226142271422814229142301423114232142331423414235142361423714238142391424014241142421424314244142451424614247142481424914250142511425214253142541425514256142571425814259142601426114262142631426414265142661426714268142691427014271142721427314274142751427614277142781427914280142811428214283142841428514286142871428814289142901429114292142931429414295142961429714298142991430014301143021430314304143051430614307143081430914310143111431214313143141431514316143171431814319143201432114322143231432414325143261432714328143291433014331143321433314334143351433614337143381433914340143411434214343143441434514346143471434814349143501435114352143531435414355143561435714358143591436014361143621436314364143651436614367143681436914370143711437214373143741437514376143771437814379143801438114382143831438414385143861438714388143891439014391143921439314394143951439614397143981439914400144011440214403144041440514406144071440814409144101441114412144131441414415144161441714418144191442014421144221442314424144251442614427144281442914430144311443214433144341443514436144371443814439144401444114442144431444414445144461444714448144491445014451144521445314454144551445614457144581445914460144611446214463144641446514466144671446814469144701447114472144731447414475144761447714478144791448014481144821448314484144851448614487144881448914490144911449214493144941449514496144971449814499145001450114502145031450414505145061450714508145091451014511145121451314514145151451614517145181451914520145211452214523145241452514526145271452814529145301453114532145331453414535145361453714538145391454014541145421454314544145451454614547145481454914550145511455214553145541455514556145571455814559145601456114562145631456414565145661456714568145691457014571145721457314574145751457614577145781457914580145811458214583145841458514586145871458814589145901459114592145931459414595145961459714598145991460014601146021460314604146051460614607146081460914610146111461214613146141461514616146171461814619146201462114622146231462414625146261462714628146291463014631146321463314634146351463614637146381463914640146411464214643146441464514646146471464814649146501465114652146531465414655146561465714658146591466014661146621466314664146651466614667146681466914670146711467214673146741467514676146771467814679146801468114682146831468414685146861468714688146891469014691146921469314694146951469614697146981469914700147011470214703147041470514706147071470814709147101471114712147131471414715147161471714718147191472014721147221472314724147251472614727147281472914730147311473214733147341473514736147371473814739147401474114742147431474414745147461474714748147491475014751147521475314754147551475614757147581475914760147611476214763147641476514766147671476814769147701477114772147731477414775147761477714778147791478014781147821478314784147851478614787147881478914790147911479214793147941479514796147971479814799148001480114802148031480414805148061480714808148091481014811148121481314814148151481614817148181481914820148211482214823148241482514826148271482814829148301483114832148331483414835148361483714838148391484014841148421484314844148451484614847148481484914850148511485214853148541485514856148571485814859148601486114862148631486414865148661486714868148691487014871148721487314874148751487614877148781487914880148811488214883148841488514886148871488814889148901489114892148931489414895148961489714898148991490014901149021490314904149051490614907149081490914910149111491214913149141491514916149171491814919149201492114922149231492414925149261492714928149291493014931149321493314934149351493614937149381493914940149411494214943149441494514946149471494814949149501495114952149531495414955149561495714958149591496014961149621496314964149651496614967149681496914970149711497214973149741497514976149771497814979149801498114982149831498414985149861498714988149891499014991149921499314994149951499614997149981499915000150011500215003150041500515006150071500815009150101501115012150131501415015150161501715018150191502015021150221502315024150251502615027150281502915030150311503215033150341503515036150371503815039150401504115042150431504415045
  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. /*------------------------------------------------------------------*/