message.c 476 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686668766886689669066916692669366946695669666976698669967006701670267036704670567066707670867096710671167126713671467156716671767186719672067216722672367246725672667276728672967306731673267336734673567366737673867396740674167426743674467456746674767486749675067516752675367546755675667576758675967606761676267636764676567666767676867696770677167726773677467756776677767786779678067816782678367846785678667876788678967906791679267936794679567966797679867996800680168026803680468056806680768086809681068116812681368146815681668176818681968206821682268236824682568266827682868296830683168326833683468356836683768386839684068416842684368446845684668476848684968506851685268536854685568566857685868596860686168626863686468656866686768686869687068716872687368746875687668776878687968806881688268836884688568866887688868896890689168926893689468956896689768986899690069016902690369046905690669076908690969106911691269136914691569166917691869196920692169226923692469256926692769286929693069316932693369346935693669376938693969406941694269436944694569466947694869496950695169526953695469556956695769586959696069616962696369646965696669676968696969706971697269736974697569766977697869796980698169826983698469856986698769886989699069916992699369946995699669976998699970007001700270037004700570067007700870097010701170127013701470157016701770187019702070217022702370247025702670277028702970307031703270337034703570367037703870397040704170427043704470457046704770487049705070517052705370547055705670577058705970607061706270637064706570667067706870697070707170727073707470757076707770787079708070817082708370847085708670877088708970907091709270937094709570967097709870997100710171027103710471057106710771087109711071117112711371147115711671177118711971207121712271237124712571267127712871297130713171327133713471357136713771387139714071417142714371447145714671477148714971507151715271537154715571567157715871597160716171627163716471657166716771687169717071717172717371747175717671777178717971807181718271837184718571867187718871897190719171927193719471957196719771987199720072017202720372047205720672077208720972107211721272137214721572167217721872197220722172227223722472257226722772287229723072317232723372347235723672377238723972407241724272437244724572467247724872497250725172527253725472557256725772587259726072617262726372647265726672677268726972707271727272737274727572767277727872797280728172827283728472857286728772887289729072917292729372947295729672977298729973007301730273037304730573067307730873097310731173127313731473157316731773187319732073217322732373247325732673277328732973307331733273337334733573367337733873397340734173427343734473457346734773487349735073517352735373547355735673577358735973607361736273637364736573667367736873697370737173727373737473757376737773787379738073817382738373847385738673877388738973907391739273937394739573967397739873997400740174027403740474057406740774087409741074117412741374147415741674177418741974207421742274237424742574267427742874297430743174327433743474357436743774387439744074417442744374447445744674477448744974507451745274537454745574567457745874597460746174627463746474657466746774687469747074717472747374747475747674777478747974807481748274837484748574867487748874897490749174927493749474957496749774987499750075017502750375047505750675077508750975107511751275137514751575167517751875197520752175227523752475257526752775287529753075317532753375347535753675377538753975407541754275437544754575467547754875497550755175527553755475557556755775587559756075617562756375647565756675677568756975707571757275737574757575767577757875797580758175827583758475857586758775887589759075917592759375947595759675977598759976007601760276037604760576067607760876097610761176127613761476157616761776187619762076217622762376247625762676277628762976307631763276337634763576367637763876397640764176427643764476457646764776487649765076517652765376547655765676577658765976607661766276637664766576667667766876697670767176727673767476757676767776787679768076817682768376847685768676877688768976907691769276937694769576967697769876997700770177027703770477057706770777087709771077117712771377147715771677177718771977207721772277237724772577267727772877297730773177327733773477357736773777387739774077417742774377447745774677477748774977507751775277537754775577567757775877597760776177627763776477657766776777687769777077717772777377747775777677777778777977807781778277837784778577867787778877897790779177927793779477957796779777987799780078017802780378047805780678077808780978107811781278137814781578167817781878197820782178227823782478257826782778287829783078317832783378347835783678377838783978407841784278437844784578467847784878497850785178527853785478557856785778587859786078617862786378647865786678677868786978707871787278737874787578767877787878797880788178827883788478857886788778887889789078917892789378947895789678977898789979007901790279037904790579067907790879097910791179127913791479157916791779187919792079217922792379247925792679277928792979307931793279337934793579367937793879397940794179427943794479457946794779487949795079517952795379547955795679577958795979607961796279637964796579667967796879697970797179727973797479757976797779787979798079817982798379847985798679877988798979907991799279937994799579967997799879998000800180028003800480058006800780088009801080118012801380148015801680178018801980208021802280238024802580268027802880298030803180328033803480358036803780388039804080418042804380448045804680478048804980508051805280538054805580568057805880598060806180628063806480658066806780688069807080718072807380748075807680778078807980808081808280838084808580868087808880898090809180928093809480958096809780988099810081018102810381048105810681078108810981108111811281138114811581168117811881198120812181228123812481258126812781288129813081318132813381348135813681378138813981408141814281438144814581468147814881498150815181528153815481558156815781588159816081618162816381648165816681678168816981708171817281738174817581768177817881798180818181828183818481858186818781888189819081918192819381948195819681978198819982008201820282038204820582068207820882098210821182128213821482158216821782188219822082218222822382248225822682278228822982308231823282338234823582368237823882398240824182428243824482458246824782488249825082518252825382548255825682578258825982608261826282638264826582668267826882698270827182728273827482758276827782788279828082818282828382848285828682878288828982908291829282938294829582968297829882998300830183028303830483058306830783088309831083118312831383148315831683178318831983208321832283238324832583268327832883298330833183328333833483358336833783388339834083418342834383448345834683478348834983508351835283538354835583568357835883598360836183628363836483658366836783688369837083718372837383748375837683778378837983808381838283838384838583868387838883898390839183928393839483958396839783988399840084018402840384048405840684078408840984108411841284138414841584168417841884198420842184228423842484258426842784288429843084318432843384348435843684378438843984408441844284438444844584468447844884498450845184528453845484558456845784588459846084618462846384648465846684678468846984708471847284738474847584768477847884798480848184828483848484858486848784888489849084918492849384948495849684978498849985008501850285038504850585068507850885098510851185128513851485158516851785188519852085218522852385248525852685278528852985308531853285338534853585368537853885398540854185428543854485458546854785488549855085518552855385548555855685578558855985608561856285638564856585668567856885698570857185728573857485758576857785788579858085818582858385848585858685878588858985908591859285938594859585968597859885998600860186028603860486058606860786088609861086118612861386148615861686178618861986208621862286238624862586268627862886298630863186328633863486358636863786388639864086418642864386448645864686478648864986508651865286538654865586568657865886598660866186628663866486658666866786688669867086718672867386748675867686778678867986808681868286838684868586868687868886898690869186928693869486958696869786988699870087018702870387048705870687078708870987108711871287138714871587168717871887198720872187228723872487258726872787288729873087318732873387348735873687378738873987408741874287438744874587468747874887498750875187528753875487558756875787588759876087618762876387648765876687678768876987708771877287738774877587768777877887798780878187828783878487858786878787888789879087918792879387948795879687978798879988008801880288038804880588068807880888098810881188128813881488158816881788188819882088218822882388248825882688278828882988308831883288338834883588368837883888398840884188428843884488458846884788488849885088518852885388548855885688578858885988608861886288638864886588668867886888698870887188728873887488758876887788788879888088818882888388848885888688878888888988908891889288938894889588968897889888998900890189028903890489058906890789088909891089118912891389148915891689178918891989208921892289238924892589268927892889298930893189328933893489358936893789388939894089418942894389448945894689478948894989508951895289538954895589568957895889598960896189628963896489658966896789688969897089718972897389748975897689778978897989808981898289838984898589868987898889898990899189928993899489958996899789988999900090019002900390049005900690079008900990109011901290139014901590169017901890199020902190229023902490259026902790289029903090319032903390349035903690379038903990409041904290439044904590469047904890499050905190529053905490559056905790589059906090619062906390649065906690679068906990709071907290739074907590769077907890799080908190829083908490859086908790889089909090919092909390949095909690979098909991009101910291039104910591069107910891099110911191129113911491159116911791189119912091219122912391249125912691279128912991309131913291339134913591369137913891399140914191429143914491459146914791489149915091519152915391549155915691579158915991609161916291639164916591669167916891699170917191729173917491759176917791789179918091819182918391849185918691879188918991909191919291939194919591969197919891999200920192029203920492059206920792089209921092119212921392149215921692179218921992209221922292239224922592269227922892299230923192329233923492359236923792389239924092419242924392449245924692479248924992509251925292539254925592569257925892599260926192629263926492659266926792689269927092719272927392749275927692779278927992809281928292839284928592869287928892899290929192929293929492959296929792989299930093019302930393049305930693079308930993109311931293139314931593169317931893199320932193229323932493259326932793289329933093319332933393349335933693379338933993409341934293439344934593469347934893499350935193529353935493559356935793589359936093619362936393649365936693679368936993709371937293739374937593769377937893799380938193829383938493859386938793889389939093919392939393949395939693979398939994009401940294039404940594069407940894099410941194129413941494159416941794189419942094219422942394249425942694279428942994309431943294339434943594369437943894399440944194429443944494459446944794489449945094519452945394549455945694579458945994609461946294639464946594669467946894699470947194729473947494759476947794789479948094819482948394849485948694879488948994909491949294939494949594969497949894999500950195029503950495059506950795089509951095119512951395149515951695179518951995209521952295239524952595269527952895299530953195329533953495359536953795389539954095419542954395449545954695479548954995509551955295539554955595569557955895599560956195629563956495659566956795689569957095719572957395749575957695779578957995809581958295839584958595869587958895899590959195929593959495959596959795989599960096019602960396049605960696079608960996109611961296139614961596169617961896199620962196229623962496259626962796289629963096319632963396349635963696379638963996409641964296439644964596469647964896499650965196529653965496559656965796589659966096619662966396649665966696679668966996709671967296739674967596769677967896799680968196829683968496859686968796889689969096919692969396949695969696979698969997009701970297039704970597069707970897099710971197129713971497159716971797189719972097219722972397249725972697279728972997309731973297339734973597369737973897399740974197429743974497459746974797489749975097519752975397549755975697579758975997609761976297639764976597669767976897699770977197729773977497759776977797789779978097819782978397849785978697879788978997909791979297939794979597969797979897999800980198029803980498059806980798089809981098119812981398149815981698179818981998209821982298239824982598269827982898299830983198329833983498359836983798389839984098419842984398449845984698479848984998509851985298539854985598569857985898599860986198629863986498659866986798689869987098719872987398749875987698779878987998809881988298839884988598869887988898899890989198929893989498959896989798989899990099019902990399049905990699079908990999109911991299139914991599169917991899199920992199229923992499259926992799289929993099319932993399349935993699379938993999409941994299439944994599469947994899499950995199529953995499559956995799589959996099619962996399649965996699679968996999709971997299739974997599769977997899799980998199829983998499859986998799889989999099919992999399949995999699979998999910000100011000210003100041000510006100071000810009100101001110012100131001410015100161001710018100191002010021100221002310024100251002610027100281002910030100311003210033100341003510036100371003810039100401004110042100431004410045100461004710048100491005010051100521005310054100551005610057100581005910060100611006210063100641006510066100671006810069100701007110072100731007410075100761007710078100791008010081100821008310084100851008610087100881008910090100911009210093100941009510096100971009810099101001010110102101031010410105101061010710108101091011010111101121011310114101151011610117101181011910120101211012210123101241012510126101271012810129101301013110132101331013410135101361013710138101391014010141101421014310144101451014610147101481014910150101511015210153101541015510156101571015810159101601016110162101631016410165101661016710168101691017010171101721017310174101751017610177101781017910180101811018210183101841018510186101871018810189101901019110192101931019410195101961019710198101991020010201102021020310204102051020610207102081020910210102111021210213102141021510216102171021810219102201022110222102231022410225102261022710228102291023010231102321023310234102351023610237102381023910240102411024210243102441024510246102471024810249102501025110252102531025410255102561025710258102591026010261102621026310264102651026610267102681026910270102711027210273102741027510276102771027810279102801028110282102831028410285102861028710288102891029010291102921029310294102951029610297102981029910300103011030210303103041030510306103071030810309103101031110312103131031410315103161031710318103191032010321103221032310324103251032610327103281032910330103311033210333103341033510336103371033810339103401034110342103431034410345103461034710348103491035010351103521035310354103551035610357103581035910360103611036210363103641036510366103671036810369103701037110372103731037410375103761037710378103791038010381103821038310384103851038610387103881038910390103911039210393103941039510396103971039810399104001040110402104031040410405104061040710408104091041010411104121041310414104151041610417104181041910420104211042210423104241042510426104271042810429104301043110432104331043410435104361043710438104391044010441104421044310444104451044610447104481044910450104511045210453104541045510456104571045810459104601046110462104631046410465104661046710468104691047010471104721047310474104751047610477104781047910480104811048210483104841048510486104871048810489104901049110492104931049410495104961049710498104991050010501105021050310504105051050610507105081050910510105111051210513105141051510516105171051810519105201052110522105231052410525105261052710528105291053010531105321053310534105351053610537105381053910540105411054210543105441054510546105471054810549105501055110552105531055410555105561055710558105591056010561105621056310564105651056610567105681056910570105711057210573105741057510576105771057810579105801058110582105831058410585105861058710588105891059010591105921059310594105951059610597105981059910600106011060210603106041060510606106071060810609106101061110612106131061410615106161061710618106191062010621106221062310624106251062610627106281062910630106311063210633106341063510636106371063810639106401064110642106431064410645106461064710648106491065010651106521065310654106551065610657106581065910660106611066210663106641066510666106671066810669106701067110672106731067410675106761067710678106791068010681106821068310684106851068610687106881068910690106911069210693106941069510696106971069810699107001070110702107031070410705107061070710708107091071010711107121071310714107151071610717107181071910720107211072210723107241072510726107271072810729107301073110732107331073410735107361073710738107391074010741107421074310744107451074610747107481074910750107511075210753107541075510756107571075810759107601076110762107631076410765107661076710768107691077010771107721077310774107751077610777107781077910780107811078210783107841078510786107871078810789107901079110792107931079410795107961079710798107991080010801108021080310804108051080610807108081080910810108111081210813108141081510816108171081810819108201082110822108231082410825108261082710828108291083010831108321083310834108351083610837108381083910840108411084210843108441084510846108471084810849108501085110852108531085410855108561085710858108591086010861108621086310864108651086610867108681086910870108711087210873108741087510876108771087810879108801088110882108831088410885108861088710888108891089010891108921089310894108951089610897108981089910900109011090210903109041090510906109071090810909109101091110912109131091410915109161091710918109191092010921109221092310924109251092610927109281092910930109311093210933109341093510936109371093810939109401094110942109431094410945109461094710948109491095010951109521095310954109551095610957109581095910960109611096210963109641096510966109671096810969109701097110972109731097410975109761097710978109791098010981109821098310984109851098610987109881098910990109911099210993109941099510996109971099810999110001100111002110031100411005110061100711008110091101011011110121101311014110151101611017110181101911020110211102211023110241102511026110271102811029110301103111032110331103411035110361103711038110391104011041110421104311044110451104611047110481104911050110511105211053110541105511056110571105811059110601106111062110631106411065110661106711068110691107011071110721107311074110751107611077110781107911080110811108211083110841108511086110871108811089110901109111092110931109411095110961109711098110991110011101111021110311104111051110611107111081110911110111111111211113111141111511116111171111811119111201112111122111231112411125111261112711128111291113011131111321113311134111351113611137111381113911140111411114211143111441114511146111471114811149111501115111152111531115411155111561115711158111591116011161111621116311164111651116611167111681116911170111711117211173111741117511176111771117811179111801118111182111831118411185111861118711188111891119011191111921119311194111951119611197111981119911200112011120211203112041120511206112071120811209112101121111212112131121411215112161121711218112191122011221112221122311224112251122611227112281122911230112311123211233112341123511236112371123811239112401124111242112431124411245112461124711248112491125011251112521125311254112551125611257112581125911260112611126211263112641126511266112671126811269112701127111272112731127411275112761127711278112791128011281112821128311284112851128611287112881128911290112911129211293112941129511296112971129811299113001130111302113031130411305113061130711308113091131011311113121131311314113151131611317113181131911320113211132211323113241132511326113271132811329113301133111332113331133411335113361133711338113391134011341113421134311344113451134611347113481134911350113511135211353113541135511356113571135811359113601136111362113631136411365113661136711368113691137011371113721137311374113751137611377113781137911380113811138211383113841138511386113871138811389113901139111392113931139411395113961139711398113991140011401114021140311404114051140611407114081140911410114111141211413114141141511416114171141811419114201142111422114231142411425114261142711428114291143011431114321143311434114351143611437114381143911440114411144211443114441144511446114471144811449114501145111452114531145411455114561145711458114591146011461114621146311464114651146611467114681146911470114711147211473114741147511476114771147811479114801148111482114831148411485114861148711488114891149011491114921149311494114951149611497114981149911500115011150211503115041150511506115071150811509115101151111512115131151411515115161151711518115191152011521115221152311524115251152611527115281152911530115311153211533115341153511536115371153811539115401154111542115431154411545115461154711548115491155011551115521155311554115551155611557115581155911560115611156211563115641156511566115671156811569115701157111572115731157411575115761157711578115791158011581115821158311584115851158611587115881158911590115911159211593115941159511596115971159811599116001160111602116031160411605116061160711608116091161011611116121161311614116151161611617116181161911620116211162211623116241162511626116271162811629116301163111632116331163411635116361163711638116391164011641116421164311644116451164611647116481164911650116511165211653116541165511656116571165811659116601166111662116631166411665116661166711668116691167011671116721167311674116751167611677116781167911680116811168211683116841168511686116871168811689116901169111692116931169411695116961169711698116991170011701117021170311704117051170611707117081170911710117111171211713117141171511716117171171811719117201172111722117231172411725117261172711728117291173011731117321173311734117351173611737117381173911740117411174211743117441174511746117471174811749117501175111752117531175411755117561175711758117591176011761117621176311764117651176611767117681176911770117711177211773117741177511776117771177811779117801178111782117831178411785117861178711788117891179011791117921179311794117951179611797117981179911800118011180211803118041180511806118071180811809118101181111812118131181411815118161181711818118191182011821118221182311824118251182611827118281182911830118311183211833118341183511836118371183811839118401184111842118431184411845118461184711848118491185011851118521185311854118551185611857118581185911860118611186211863118641186511866118671186811869118701187111872118731187411875118761187711878118791188011881118821188311884118851188611887118881188911890118911189211893118941189511896118971189811899119001190111902119031190411905119061190711908119091191011911119121191311914119151191611917119181191911920119211192211923119241192511926119271192811929119301193111932119331193411935119361193711938119391194011941119421194311944119451194611947119481194911950119511195211953119541195511956119571195811959119601196111962119631196411965119661196711968119691197011971119721197311974119751197611977119781197911980119811198211983119841198511986119871198811989119901199111992119931199411995119961199711998119991200012001120021200312004120051200612007120081200912010120111201212013120141201512016120171201812019120201202112022120231202412025120261202712028120291203012031120321203312034120351203612037120381203912040120411204212043120441204512046120471204812049120501205112052120531205412055120561205712058120591206012061120621206312064120651206612067120681206912070120711207212073120741207512076120771207812079120801208112082120831208412085120861208712088120891209012091120921209312094120951209612097120981209912100121011210212103121041210512106121071210812109121101211112112121131211412115121161211712118121191212012121121221212312124121251212612127121281212912130121311213212133121341213512136121371213812139121401214112142121431214412145121461214712148121491215012151121521215312154121551215612157121581215912160121611216212163121641216512166121671216812169121701217112172121731217412175121761217712178121791218012181121821218312184121851218612187121881218912190121911219212193121941219512196121971219812199122001220112202122031220412205122061220712208122091221012211122121221312214122151221612217122181221912220122211222212223122241222512226122271222812229122301223112232122331223412235122361223712238122391224012241122421224312244122451224612247122481224912250122511225212253122541225512256122571225812259122601226112262122631226412265122661226712268122691227012271122721227312274122751227612277122781227912280122811228212283122841228512286122871228812289122901229112292122931229412295122961229712298122991230012301123021230312304123051230612307123081230912310123111231212313123141231512316123171231812319123201232112322123231232412325123261232712328123291233012331123321233312334123351233612337123381233912340123411234212343123441234512346123471234812349123501235112352123531235412355123561235712358123591236012361123621236312364123651236612367123681236912370123711237212373123741237512376123771237812379123801238112382123831238412385123861238712388123891239012391123921239312394123951239612397123981239912400124011240212403124041240512406124071240812409124101241112412124131241412415124161241712418124191242012421124221242312424124251242612427124281242912430124311243212433124341243512436124371243812439124401244112442124431244412445124461244712448124491245012451124521245312454124551245612457124581245912460124611246212463124641246512466124671246812469124701247112472124731247412475124761247712478124791248012481124821248312484124851248612487124881248912490124911249212493124941249512496124971249812499125001250112502125031250412505125061250712508125091251012511125121251312514125151251612517125181251912520125211252212523125241252512526125271252812529125301253112532125331253412535125361253712538125391254012541125421254312544125451254612547125481254912550125511255212553125541255512556125571255812559125601256112562125631256412565125661256712568125691257012571125721257312574125751257612577125781257912580125811258212583125841258512586125871258812589125901259112592125931259412595125961259712598125991260012601126021260312604126051260612607126081260912610126111261212613126141261512616126171261812619126201262112622126231262412625126261262712628126291263012631126321263312634126351263612637126381263912640126411264212643126441264512646126471264812649126501265112652126531265412655126561265712658126591266012661126621266312664126651266612667126681266912670126711267212673126741267512676126771267812679126801268112682126831268412685126861268712688126891269012691126921269312694126951269612697126981269912700127011270212703127041270512706127071270812709127101271112712127131271412715127161271712718127191272012721127221272312724127251272612727127281272912730127311273212733127341273512736127371273812739127401274112742127431274412745127461274712748127491275012751127521275312754127551275612757127581275912760127611276212763127641276512766127671276812769127701277112772127731277412775127761277712778127791278012781127821278312784127851278612787127881278912790127911279212793127941279512796127971279812799128001280112802128031280412805128061280712808128091281012811128121281312814128151281612817128181281912820128211282212823128241282512826128271282812829128301283112832128331283412835128361283712838128391284012841128421284312844128451284612847128481284912850128511285212853128541285512856128571285812859128601286112862128631286412865128661286712868128691287012871128721287312874128751287612877128781287912880128811288212883128841288512886128871288812889128901289112892128931289412895128961289712898128991290012901129021290312904129051290612907129081290912910129111291212913129141291512916129171291812919129201292112922129231292412925129261292712928129291293012931129321293312934129351293612937129381293912940129411294212943129441294512946129471294812949129501295112952129531295412955129561295712958129591296012961129621296312964129651296612967129681296912970129711297212973129741297512976129771297812979129801298112982129831298412985129861298712988129891299012991129921299312994129951299612997129981299913000130011300213003130041300513006130071300813009130101301113012130131301413015130161301713018130191302013021130221302313024130251302613027130281302913030130311303213033130341303513036130371303813039130401304113042130431304413045130461304713048130491305013051130521305313054130551305613057130581305913060130611306213063130641306513066130671306813069130701307113072130731307413075130761307713078130791308013081130821308313084130851308613087130881308913090130911309213093130941309513096130971309813099131001310113102131031310413105131061310713108131091311013111131121311313114131151311613117131181311913120131211312213123131241312513126131271312813129131301313113132131331313413135131361313713138131391314013141131421314313144131451314613147131481314913150131511315213153131541315513156131571315813159131601316113162131631316413165131661316713168131691317013171131721317313174131751317613177131781317913180131811318213183131841318513186131871318813189131901319113192131931319413195131961319713198131991320013201132021320313204132051320613207132081320913210132111321213213132141321513216132171321813219132201322113222132231322413225132261322713228132291323013231132321323313234132351323613237132381323913240132411324213243132441324513246132471324813249132501325113252132531325413255132561325713258132591326013261132621326313264132651326613267132681326913270132711327213273132741327513276132771327813279132801328113282132831328413285132861328713288132891329013291132921329313294132951329613297132981329913300133011330213303133041330513306133071330813309133101331113312133131331413315133161331713318133191332013321133221332313324133251332613327133281332913330133311333213333133341333513336133371333813339133401334113342133431334413345133461334713348133491335013351133521335313354133551335613357133581335913360133611336213363133641336513366133671336813369133701337113372133731337413375133761337713378133791338013381133821338313384133851338613387133881338913390133911339213393133941339513396133971339813399134001340113402134031340413405134061340713408134091341013411134121341313414134151341613417134181341913420134211342213423134241342513426134271342813429134301343113432134331343413435134361343713438134391344013441134421344313444134451344613447134481344913450134511345213453134541345513456134571345813459134601346113462134631346413465134661346713468134691347013471134721347313474134751347613477134781347913480134811348213483134841348513486134871348813489134901349113492134931349413495134961349713498134991350013501135021350313504135051350613507135081350913510135111351213513135141351513516135171351813519135201352113522135231352413525135261352713528135291353013531135321353313534135351353613537135381353913540135411354213543135441354513546135471354813549135501355113552135531355413555135561355713558135591356013561135621356313564135651356613567135681356913570135711357213573135741357513576135771357813579135801358113582135831358413585135861358713588135891359013591135921359313594135951359613597135981359913600136011360213603136041360513606136071360813609136101361113612136131361413615136161361713618136191362013621136221362313624136251362613627136281362913630136311363213633136341363513636136371363813639136401364113642136431364413645136461364713648136491365013651136521365313654136551365613657136581365913660136611366213663136641366513666136671366813669136701367113672136731367413675136761367713678136791368013681136821368313684136851368613687136881368913690136911369213693136941369513696136971369813699137001370113702137031370413705137061370713708137091371013711137121371313714137151371613717137181371913720137211372213723137241372513726137271372813729137301373113732137331373413735137361373713738137391374013741137421374313744137451374613747137481374913750137511375213753137541375513756137571375813759137601376113762137631376413765137661376713768137691377013771137721377313774137751377613777137781377913780137811378213783137841378513786137871378813789137901379113792137931379413795137961379713798137991380013801138021380313804138051380613807138081380913810138111381213813138141381513816138171381813819138201382113822138231382413825138261382713828138291383013831138321383313834138351383613837138381383913840138411384213843138441384513846138471384813849138501385113852138531385413855138561385713858138591386013861138621386313864138651386613867138681386913870138711387213873138741387513876138771387813879138801388113882138831388413885138861388713888138891389013891138921389313894138951389613897138981389913900139011390213903139041390513906139071390813909139101391113912139131391413915139161391713918139191392013921139221392313924139251392613927139281392913930139311393213933139341393513936139371393813939139401394113942139431394413945139461394713948139491395013951139521395313954139551395613957139581395913960139611396213963139641396513966139671396813969139701397113972139731397413975139761397713978139791398013981139821398313984139851398613987139881398913990139911399213993139941399513996139971399813999140001400114002140031400414005140061400714008140091401014011140121401314014140151401614017140181401914020140211402214023140241402514026140271402814029140301403114032140331403414035140361403714038140391404014041140421404314044140451404614047140481404914050140511405214053140541405514056140571405814059140601406114062140631406414065140661406714068140691407014071140721407314074140751407614077140781407914080140811408214083140841408514086140871408814089140901409114092140931409414095140961409714098140991410014101141021410314104141051410614107141081410914110141111411214113141141411514116141171411814119141201412114122141231412414125141261412714128141291413014131141321413314134141351413614137141381413914140141411414214143141441414514146141471414814149141501415114152141531415414155141561415714158141591416014161141621416314164141651416614167141681416914170141711417214173141741417514176141771417814179141801418114182141831418414185141861418714188141891419014191141921419314194141951419614197141981419914200142011420214203142041420514206142071420814209142101421114212142131421414215142161421714218142191422014221142221422314224142251422614227142281422914230142311423214233142341423514236142371423814239142401424114242142431424414245142461424714248142491425014251142521425314254142551425614257142581425914260142611426214263142641426514266142671426814269142701427114272142731427414275142761427714278142791428014281142821428314284142851428614287142881428914290142911429214293142941429514296142971429814299143001430114302143031430414305143061430714308143091431014311143121431314314143151431614317143181431914320143211432214323143241432514326143271432814329143301433114332143331433414335143361433714338143391434014341143421434314344143451434614347143481434914350143511435214353143541435514356143571435814359143601436114362143631436414365143661436714368143691437014371143721437314374143751437614377143781437914380143811438214383143841438514386143871438814389143901439114392143931439414395143961439714398143991440014401144021440314404144051440614407144081440914410144111441214413144141441514416144171441814419144201442114422144231442414425144261442714428144291443014431144321443314434144351443614437144381443914440144411444214443144441444514446144471444814449144501445114452144531445414455144561445714458144591446014461144621446314464144651446614467144681446914470144711447214473144741447514476144771447814479144801448114482144831448414485144861448714488144891449014491144921449314494144951449614497144981449914500145011450214503145041450514506145071450814509145101451114512145131451414515145161451714518145191452014521145221452314524145251452614527145281452914530145311453214533145341453514536145371453814539145401454114542145431454414545145461454714548145491455014551145521455314554145551455614557145581455914560145611456214563145641456514566145671456814569145701457114572145731457414575145761457714578145791458014581145821458314584145851458614587145881458914590145911459214593145941459514596145971459814599146001460114602146031460414605146061460714608146091461014611146121461314614146151461614617146181461914620146211462214623146241462514626146271462814629146301463114632146331463414635146361463714638146391464014641146421464314644146451464614647146481464914650146511465214653146541465514656146571465814659146601466114662146631466414665146661466714668146691467014671146721467314674146751467614677146781467914680146811468214683146841468514686146871468814689146901469114692146931469414695146961469714698146991470014701147021470314704147051470614707147081470914710147111471214713147141471514716147171471814719147201472114722147231472414725147261472714728147291473014731147321473314734147351473614737147381473914740147411474214743147441474514746147471474814749147501475114752147531475414755147561475714758147591476014761147621476314764147651476614767147681476914770147711477214773147741477514776147771477814779147801478114782147831478414785147861478714788147891479014791147921479314794147951479614797147981479914800148011480214803148041480514806148071480814809148101481114812148131481414815148161481714818148191482014821148221482314824148251482614827148281482914830148311483214833148341483514836148371483814839148401484114842148431484414845148461484714848148491485014851148521485314854148551485614857148581485914860148611486214863148641486514866148671486814869148701487114872148731487414875148761487714878148791488014881148821488314884148851488614887148881488914890148911489214893148941489514896148971489814899149001490114902149031490414905149061490714908149091491014911149121491314914149151491614917149181491914920149211492214923149241492514926149271492814929149301493114932149331493414935149361493714938149391494014941149421494314944149451494614947149481494914950149511495214953149541495514956149571495814959149601496114962149631496414965149661496714968149691497014971149721497314974149751497614977149781497914980149811498214983149841498514986149871498814989149901499114992149931499414995149961499714998149991500015001150021500315004150051500615007150081500915010150111501215013150141501515016150171501815019150201502115022150231502415025150261502715028150291503015031150321503315034150351503615037150381503915040150411504215043150441504515046150471504815049150501505115052150531505415055150561505715058150591506015061150621506315064150651506615067150681506915070150711507215073
  1. /*
  2. *
  3. Copyright (c) Eicon Networks, 2002.
  4. *
  5. This source file is supplied for the use with
  6. Eicon Networks range of DIVA Server Adapters.
  7. *
  8. Eicon File Revision : 2.1
  9. *
  10. This program is free software; you can redistribute it and/or modify
  11. it under the terms of the GNU General Public License as published by
  12. the Free Software Foundation; either version 2, or (at your option)
  13. any later version.
  14. *
  15. This program is distributed in the hope that it will be useful,
  16. but WITHOUT ANY WARRANTY OF ANY KIND WHATSOEVER INCLUDING ANY
  17. implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  18. See the GNU General Public License for more details.
  19. *
  20. You should have received a copy of the GNU General Public License
  21. along with this program; if not, write to the Free Software
  22. Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  23. *
  24. */
  25. #include "platform.h"
  26. #include "di_defs.h"
  27. #include "pc.h"
  28. #include "capi20.h"
  29. #include "divacapi.h"
  30. #include "mdm_msg.h"
  31. #include "divasync.h"
  32. #define FILE_ "MESSAGE.C"
  33. #define dprintf
  34. /*------------------------------------------------------------------*/
  35. /* This is options supported for all adapters that are server by */
  36. /* XDI driver. Allo it is not necessary to ask it from every adapter*/
  37. /* and it is not necessary to save it separate for every adapter */
  38. /* Macrose defined here have only local meaning */
  39. /*------------------------------------------------------------------*/
  40. static dword diva_xdi_extended_features = 0;
  41. #define DIVA_CAPI_USE_CMA 0x00000001
  42. #define DIVA_CAPI_XDI_PROVIDES_SDRAM_BAR 0x00000002
  43. #define DIVA_CAPI_XDI_PROVIDES_NO_CANCEL 0x00000004
  44. #define DIVA_CAPI_XDI_PROVIDES_RX_DMA 0x00000008
  45. /*
  46. CAPI can request to process all return codes self only if:
  47. protocol code supports this && xdi supports this
  48. */
  49. #define DIVA_CAPI_SUPPORTS_NO_CANCEL(__a__) (((__a__)->manufacturer_features&MANUFACTURER_FEATURE_XONOFF_FLOW_CONTROL)&& ((__a__)->manufacturer_features & MANUFACTURER_FEATURE_OK_FC_LABEL) && (diva_xdi_extended_features & DIVA_CAPI_XDI_PROVIDES_NO_CANCEL))
  50. /*------------------------------------------------------------------*/
  51. /* local function prototypes */
  52. /*------------------------------------------------------------------*/
  53. static void group_optimization(DIVA_CAPI_ADAPTER * a, PLCI * plci);
  54. static void set_group_ind_mask (PLCI *plci);
  55. static void clear_group_ind_mask_bit (PLCI *plci, word b);
  56. static byte test_group_ind_mask_bit (PLCI *plci, word b);
  57. void AutomaticLaw(DIVA_CAPI_ADAPTER *);
  58. word CapiRelease(word);
  59. word CapiRegister(word);
  60. word api_put(APPL *, CAPI_MSG *);
  61. static word api_parse(byte *, word, byte *, API_PARSE *);
  62. static void api_save_msg(API_PARSE *in, byte *format, API_SAVE *out);
  63. static void api_load_msg(API_SAVE *in, API_PARSE *out);
  64. word api_remove_start(void);
  65. void api_remove_complete(void);
  66. static void plci_remove(PLCI *);
  67. static void diva_get_extended_adapter_features (DIVA_CAPI_ADAPTER * a);
  68. static void diva_ask_for_xdi_sdram_bar (DIVA_CAPI_ADAPTER *, IDI_SYNC_REQ *);
  69. void callback(ENTITY *);
  70. static void control_rc(PLCI *, byte, byte, byte, byte, byte);
  71. static void data_rc(PLCI *, byte);
  72. static void data_ack(PLCI *, byte);
  73. static void sig_ind(PLCI *);
  74. static void SendInfo(PLCI *, dword, byte * *, byte);
  75. static void SendSetupInfo(APPL *, PLCI *, dword, byte * *, byte);
  76. static void SendSSExtInd(APPL *, PLCI * plci, dword Id, byte * * parms);
  77. static void VSwitchReqInd(PLCI *plci, dword Id, byte **parms);
  78. static void nl_ind(PLCI *);
  79. static byte connect_req(dword, word, DIVA_CAPI_ADAPTER *, PLCI *, APPL *, API_PARSE *);
  80. static byte connect_res(dword, word, DIVA_CAPI_ADAPTER *, PLCI *, APPL *, API_PARSE *);
  81. static byte connect_a_res(dword,word, DIVA_CAPI_ADAPTER *, PLCI *, APPL *, API_PARSE *);
  82. static byte disconnect_req(dword, word, DIVA_CAPI_ADAPTER *, PLCI *, APPL *, API_PARSE *);
  83. static byte disconnect_res(dword, word, DIVA_CAPI_ADAPTER *, PLCI *, APPL *, API_PARSE *);
  84. static byte listen_req(dword, word, DIVA_CAPI_ADAPTER *, PLCI *, APPL *, API_PARSE *);
  85. static byte info_req(dword, word, DIVA_CAPI_ADAPTER *, PLCI *, APPL *, API_PARSE *);
  86. static byte info_res(dword, word, DIVA_CAPI_ADAPTER *, PLCI *, APPL *, API_PARSE *);
  87. static byte alert_req(dword, word, DIVA_CAPI_ADAPTER *, PLCI *, APPL *, API_PARSE *);
  88. static byte facility_req(dword, word, DIVA_CAPI_ADAPTER *, PLCI *, APPL *, API_PARSE *);
  89. static byte facility_res(dword, word, DIVA_CAPI_ADAPTER *, PLCI *, APPL *, API_PARSE *);
  90. static byte connect_b3_req(dword, word, DIVA_CAPI_ADAPTER *, PLCI *, APPL *, API_PARSE *);
  91. static byte connect_b3_res(dword, word, DIVA_CAPI_ADAPTER *, PLCI *, APPL *, API_PARSE *);
  92. static byte connect_b3_a_res(dword, word, DIVA_CAPI_ADAPTER *, PLCI *, APPL *, API_PARSE *);
  93. static byte disconnect_b3_req(dword, word, DIVA_CAPI_ADAPTER *, PLCI *, APPL *, API_PARSE *);
  94. static byte disconnect_b3_res(dword, word, DIVA_CAPI_ADAPTER *, PLCI *, APPL *, API_PARSE *);
  95. static byte data_b3_req(dword, word, DIVA_CAPI_ADAPTER *, PLCI *, APPL *, API_PARSE *);
  96. static byte data_b3_res(dword, word, DIVA_CAPI_ADAPTER *, PLCI *, APPL *, API_PARSE *);
  97. static byte reset_b3_req(dword, word, DIVA_CAPI_ADAPTER *, PLCI *, APPL *, API_PARSE *);
  98. static byte reset_b3_res(dword, word, DIVA_CAPI_ADAPTER *, PLCI *, APPL *, API_PARSE *);
  99. static byte connect_b3_t90_a_res(dword, word, DIVA_CAPI_ADAPTER *, PLCI *, APPL *, API_PARSE *);
  100. static byte select_b_req(dword, word, DIVA_CAPI_ADAPTER *, PLCI *, APPL *, API_PARSE *);
  101. static byte manufacturer_req(dword, word, DIVA_CAPI_ADAPTER *, PLCI *, APPL *, API_PARSE *);
  102. static byte manufacturer_res(dword, word, DIVA_CAPI_ADAPTER *, PLCI *, APPL *, API_PARSE *);
  103. static word get_plci(DIVA_CAPI_ADAPTER *);
  104. static void add_p(PLCI *, byte, byte *);
  105. static void add_s(PLCI * plci, byte code, API_PARSE * p);
  106. static void add_ss(PLCI * plci, byte code, API_PARSE * p);
  107. static void add_ie(PLCI * plci, byte code, byte * p, word p_length);
  108. static void add_d(PLCI *, word, byte *);
  109. static void add_ai(PLCI *, API_PARSE *);
  110. static word add_b1(PLCI *, API_PARSE *, word, word);
  111. static word add_b23(PLCI *, API_PARSE *);
  112. static word add_modem_b23 (PLCI * plci, API_PARSE* bp_parms);
  113. static void sig_req(PLCI *, byte, byte);
  114. static void nl_req_ncci(PLCI *, byte, byte);
  115. static void send_req(PLCI *);
  116. static void send_data(PLCI *);
  117. static word plci_remove_check(PLCI *);
  118. static void listen_check(DIVA_CAPI_ADAPTER *);
  119. static byte AddInfo(byte **, byte **, byte *, byte *);
  120. static byte getChannel(API_PARSE *);
  121. static void IndParse(PLCI *, word *, byte **, byte);
  122. static byte ie_compare(byte *, byte *);
  123. static word find_cip(DIVA_CAPI_ADAPTER *, byte *, byte *);
  124. static word CPN_filter_ok(byte *cpn,DIVA_CAPI_ADAPTER *,word);
  125. /*
  126. XON protocol helpers
  127. */
  128. static void channel_flow_control_remove (PLCI * plci);
  129. static void channel_x_off (PLCI * plci, byte ch, byte flag);
  130. static void channel_x_on (PLCI * plci, byte ch);
  131. static void channel_request_xon (PLCI * plci, byte ch);
  132. static void channel_xmit_xon (PLCI * plci);
  133. static int channel_can_xon (PLCI * plci, byte ch);
  134. static void channel_xmit_extended_xon (PLCI * plci);
  135. static byte SendMultiIE(PLCI * plci, dword Id, byte * * parms, byte ie_type, dword info_mask, byte setupParse);
  136. static word AdvCodecSupport(DIVA_CAPI_ADAPTER *, PLCI *, APPL *, byte);
  137. static void CodecIdCheck(DIVA_CAPI_ADAPTER *, PLCI *);
  138. static void SetVoiceChannel(PLCI *, byte *, DIVA_CAPI_ADAPTER * );
  139. static void VoiceChannelOff(PLCI *plci);
  140. static void adv_voice_write_coefs (PLCI *plci, word write_command);
  141. static void adv_voice_clear_config (PLCI *plci);
  142. static word get_b1_facilities (PLCI * plci, byte b1_resource);
  143. static byte add_b1_facilities (PLCI * plci, byte b1_resource, word b1_facilities);
  144. static void adjust_b1_facilities (PLCI *plci, byte new_b1_resource, word new_b1_facilities);
  145. static word adjust_b_process (dword Id, PLCI *plci, byte Rc);
  146. static void adjust_b1_resource (dword Id, PLCI *plci, API_SAVE *bp_msg, word b1_facilities, word internal_command);
  147. static void adjust_b_restore (dword Id, PLCI *plci, byte Rc);
  148. static void reset_b3_command (dword Id, PLCI *plci, byte Rc);
  149. static void select_b_command (dword Id, PLCI *plci, byte Rc);
  150. static void fax_connect_ack_command (dword Id, PLCI *plci, byte Rc);
  151. static void fax_edata_ack_command (dword Id, PLCI *plci, byte Rc);
  152. static void fax_connect_info_command (dword Id, PLCI *plci, byte Rc);
  153. static void fax_adjust_b23_command (dword Id, PLCI *plci, byte Rc);
  154. static void fax_disconnect_command (dword Id, PLCI *plci, byte Rc);
  155. static void hold_save_command (dword Id, PLCI *plci, byte Rc);
  156. static void retrieve_restore_command (dword Id, PLCI *plci, byte Rc);
  157. static void init_b1_config (PLCI *plci);
  158. static void clear_b1_config (PLCI *plci);
  159. static void dtmf_command (dword Id, PLCI *plci, byte Rc);
  160. static byte dtmf_request (dword Id, word Number, DIVA_CAPI_ADAPTER *a, PLCI *plci, APPL *appl, API_PARSE *msg);
  161. static void dtmf_confirmation (dword Id, PLCI *plci);
  162. static void dtmf_indication (dword Id, PLCI *plci, byte *msg, word length);
  163. static void dtmf_parameter_write (PLCI *plci);
  164. static void mixer_set_bchannel_id_esc (PLCI *plci, byte bchannel_id);
  165. static void mixer_set_bchannel_id (PLCI *plci, byte *chi);
  166. static void mixer_clear_config (PLCI *plci);
  167. static void mixer_notify_update (PLCI *plci, byte others);
  168. static void mixer_command (dword Id, PLCI *plci, byte Rc);
  169. static byte mixer_request (dword Id, word Number, DIVA_CAPI_ADAPTER *a, PLCI *plci, APPL *appl, API_PARSE *msg);
  170. static void mixer_indication_coefs_set (dword Id, PLCI *plci);
  171. static void mixer_indication_xconnect_from (dword Id, PLCI *plci, byte *msg, word length);
  172. static void mixer_indication_xconnect_to (dword Id, PLCI *plci, byte *msg, word length);
  173. static void mixer_remove (PLCI *plci);
  174. static void ec_command (dword Id, PLCI *plci, byte Rc);
  175. static byte ec_request (dword Id, word Number, DIVA_CAPI_ADAPTER *a, PLCI *plci, APPL *appl, API_PARSE *msg);
  176. static void ec_indication (dword Id, PLCI *plci, byte *msg, word length);
  177. static void rtp_connect_b3_req_command (dword Id, PLCI *plci, byte Rc);
  178. static void rtp_connect_b3_res_command (dword Id, PLCI *plci, byte Rc);
  179. static int diva_get_dma_descriptor (PLCI *plci, dword *dma_magic);
  180. static void diva_free_dma_descriptor (PLCI *plci, int nr);
  181. /*------------------------------------------------------------------*/
  182. /* external function prototypes */
  183. /*------------------------------------------------------------------*/
  184. extern byte MapController (byte);
  185. extern byte UnMapController (byte);
  186. #define MapId(Id) (((Id) & 0xffffff00L) | MapController ((byte)(Id)))
  187. #define UnMapId(Id) (((Id) & 0xffffff00L) | UnMapController ((byte)(Id)))
  188. void sendf(APPL *, word, dword, word, byte *, ...);
  189. void * TransmitBufferSet(APPL * appl, dword ref);
  190. void * TransmitBufferGet(APPL * appl, void * p);
  191. void TransmitBufferFree(APPL * appl, void * p);
  192. void * ReceiveBufferGet(APPL * appl, int Num);
  193. int fax_head_line_time (char *buffer);
  194. /*------------------------------------------------------------------*/
  195. /* Global data definitions */
  196. /*------------------------------------------------------------------*/
  197. extern byte max_adapter;
  198. extern byte max_appl;
  199. extern DIVA_CAPI_ADAPTER * adapter;
  200. extern APPL * application;
  201. static byte remove_started = false;
  202. static PLCI dummy_plci;
  203. static struct _ftable {
  204. word command;
  205. byte * format;
  206. byte (* function)(dword, word, DIVA_CAPI_ADAPTER *, PLCI *, APPL *, API_PARSE *);
  207. } ftable[] = {
  208. {_DATA_B3_R, "dwww", data_b3_req},
  209. {_DATA_B3_I|RESPONSE, "w", data_b3_res},
  210. {_INFO_R, "ss", info_req},
  211. {_INFO_I|RESPONSE, "", info_res},
  212. {_CONNECT_R, "wsssssssss", connect_req},
  213. {_CONNECT_I|RESPONSE, "wsssss", connect_res},
  214. {_CONNECT_ACTIVE_I|RESPONSE, "", connect_a_res},
  215. {_DISCONNECT_R, "s", disconnect_req},
  216. {_DISCONNECT_I|RESPONSE, "", disconnect_res},
  217. {_LISTEN_R, "dddss", listen_req},
  218. {_ALERT_R, "s", alert_req},
  219. {_FACILITY_R, "ws", facility_req},
  220. {_FACILITY_I|RESPONSE, "ws", facility_res},
  221. {_CONNECT_B3_R, "s", connect_b3_req},
  222. {_CONNECT_B3_I|RESPONSE, "ws", connect_b3_res},
  223. {_CONNECT_B3_ACTIVE_I|RESPONSE, "", connect_b3_a_res},
  224. {_DISCONNECT_B3_R, "s", disconnect_b3_req},
  225. {_DISCONNECT_B3_I|RESPONSE, "", disconnect_b3_res},
  226. {_RESET_B3_R, "s", reset_b3_req},
  227. {_RESET_B3_I|RESPONSE, "", reset_b3_res},
  228. {_CONNECT_B3_T90_ACTIVE_I|RESPONSE, "ws", connect_b3_t90_a_res},
  229. {_CONNECT_B3_T90_ACTIVE_I|RESPONSE, "", connect_b3_t90_a_res},
  230. {_SELECT_B_REQ, "s", select_b_req},
  231. {_MANUFACTURER_R, "dws", manufacturer_req},
  232. {_MANUFACTURER_I|RESPONSE, "dws", manufacturer_res},
  233. {_MANUFACTURER_I|RESPONSE, "", manufacturer_res}
  234. };
  235. static byte * cip_bc[29][2] = {
  236. { "", "" }, /* 0 */
  237. { "\x03\x80\x90\xa3", "\x03\x80\x90\xa2" }, /* 1 */
  238. { "\x02\x88\x90", "\x02\x88\x90" }, /* 2 */
  239. { "\x02\x89\x90", "\x02\x89\x90" }, /* 3 */
  240. { "\x03\x90\x90\xa3", "\x03\x90\x90\xa2" }, /* 4 */
  241. { "\x03\x91\x90\xa5", "\x03\x91\x90\xa5" }, /* 5 */
  242. { "\x02\x98\x90", "\x02\x98\x90" }, /* 6 */
  243. { "\x04\x88\xc0\xc6\xe6", "\x04\x88\xc0\xc6\xe6" }, /* 7 */
  244. { "\x04\x88\x90\x21\x8f", "\x04\x88\x90\x21\x8f" }, /* 8 */
  245. { "\x03\x91\x90\xa5", "\x03\x91\x90\xa5" }, /* 9 */
  246. { "", "" }, /* 10 */
  247. { "", "" }, /* 11 */
  248. { "", "" }, /* 12 */
  249. { "", "" }, /* 13 */
  250. { "", "" }, /* 14 */
  251. { "", "" }, /* 15 */
  252. { "\x03\x80\x90\xa3", "\x03\x80\x90\xa2" }, /* 16 */
  253. { "\x03\x90\x90\xa3", "\x03\x90\x90\xa2" }, /* 17 */
  254. { "\x02\x88\x90", "\x02\x88\x90" }, /* 18 */
  255. { "\x02\x88\x90", "\x02\x88\x90" }, /* 19 */
  256. { "\x02\x88\x90", "\x02\x88\x90" }, /* 20 */
  257. { "\x02\x88\x90", "\x02\x88\x90" }, /* 21 */
  258. { "\x02\x88\x90", "\x02\x88\x90" }, /* 22 */
  259. { "\x02\x88\x90", "\x02\x88\x90" }, /* 23 */
  260. { "\x02\x88\x90", "\x02\x88\x90" }, /* 24 */
  261. { "\x02\x88\x90", "\x02\x88\x90" }, /* 25 */
  262. { "\x03\x91\x90\xa5", "\x03\x91\x90\xa5" }, /* 26 */
  263. { "\x03\x91\x90\xa5", "\x03\x91\x90\xa5" }, /* 27 */
  264. { "\x02\x88\x90", "\x02\x88\x90" } /* 28 */
  265. };
  266. static byte * cip_hlc[29] = {
  267. "", /* 0 */
  268. "", /* 1 */
  269. "", /* 2 */
  270. "", /* 3 */
  271. "", /* 4 */
  272. "", /* 5 */
  273. "", /* 6 */
  274. "", /* 7 */
  275. "", /* 8 */
  276. "", /* 9 */
  277. "", /* 10 */
  278. "", /* 11 */
  279. "", /* 12 */
  280. "", /* 13 */
  281. "", /* 14 */
  282. "", /* 15 */
  283. "\x02\x91\x81", /* 16 */
  284. "\x02\x91\x84", /* 17 */
  285. "\x02\x91\xa1", /* 18 */
  286. "\x02\x91\xa4", /* 19 */
  287. "\x02\x91\xa8", /* 20 */
  288. "\x02\x91\xb1", /* 21 */
  289. "\x02\x91\xb2", /* 22 */
  290. "\x02\x91\xb5", /* 23 */
  291. "\x02\x91\xb8", /* 24 */
  292. "\x02\x91\xc1", /* 25 */
  293. "\x02\x91\x81", /* 26 */
  294. "\x03\x91\xe0\x01", /* 27 */
  295. "\x03\x91\xe0\x02" /* 28 */
  296. };
  297. /*------------------------------------------------------------------*/
  298. #define V120_HEADER_LENGTH 1
  299. #define V120_HEADER_EXTEND_BIT 0x80
  300. #define V120_HEADER_BREAK_BIT 0x40
  301. #define V120_HEADER_C1_BIT 0x04
  302. #define V120_HEADER_C2_BIT 0x08
  303. #define V120_HEADER_FLUSH_COND (V120_HEADER_BREAK_BIT | V120_HEADER_C1_BIT | V120_HEADER_C2_BIT)
  304. static byte v120_default_header[] =
  305. {
  306. 0x83 /* Ext, BR , res, res, C2 , C1 , B , F */
  307. };
  308. static byte v120_break_header[] =
  309. {
  310. 0xc3 | V120_HEADER_BREAK_BIT /* Ext, BR , res, res, C2 , C1 , B , F */
  311. };
  312. /*------------------------------------------------------------------*/
  313. /* API_PUT function */
  314. /*------------------------------------------------------------------*/
  315. word api_put(APPL * appl, CAPI_MSG * msg)
  316. {
  317. word i, j, k, l, n;
  318. word ret;
  319. byte c;
  320. byte controller;
  321. DIVA_CAPI_ADAPTER * a;
  322. PLCI * plci;
  323. NCCI * ncci_ptr;
  324. word ncci;
  325. CAPI_MSG *m;
  326. API_PARSE msg_parms[MAX_MSG_PARMS+1];
  327. if (msg->header.length < sizeof (msg->header) ||
  328. msg->header.length > MAX_MSG_SIZE) {
  329. dbug(1,dprintf("bad len"));
  330. return _BAD_MSG;
  331. }
  332. controller = (byte)((msg->header.controller &0x7f)-1);
  333. /* controller starts with 0 up to (max_adapter - 1) */
  334. if ( controller >= max_adapter )
  335. {
  336. dbug(1,dprintf("invalid ctrl"));
  337. return _BAD_MSG;
  338. }
  339. a = &adapter[controller];
  340. plci = NULL;
  341. if ((msg->header.plci != 0) && (msg->header.plci <= a->max_plci) && !a->adapter_disabled)
  342. {
  343. dbug(1,dprintf("plci=%x",msg->header.plci));
  344. plci = &a->plci[msg->header.plci-1];
  345. ncci = GET_WORD(&msg->header.ncci);
  346. if (plci->Id
  347. && (plci->appl
  348. || (plci->State == INC_CON_PENDING)
  349. || (plci->State == INC_CON_ALERT)
  350. || (msg->header.command == (_DISCONNECT_I|RESPONSE)))
  351. && ((ncci == 0)
  352. || (msg->header.command == (_DISCONNECT_B3_I|RESPONSE))
  353. || ((ncci < MAX_NCCI+1) && (a->ncci_plci[ncci] == plci->Id))))
  354. {
  355. i = plci->msg_in_read_pos;
  356. j = plci->msg_in_write_pos;
  357. if (j >= i)
  358. {
  359. if (j + msg->header.length + MSG_IN_OVERHEAD <= MSG_IN_QUEUE_SIZE)
  360. i += MSG_IN_QUEUE_SIZE - j;
  361. else
  362. j = 0;
  363. }
  364. else
  365. {
  366. n = (((CAPI_MSG *)(plci->msg_in_queue))->header.length + MSG_IN_OVERHEAD + 3) & 0xfffc;
  367. if (i > MSG_IN_QUEUE_SIZE - n)
  368. i = MSG_IN_QUEUE_SIZE - n + 1;
  369. i -= j;
  370. }
  371. if (i <= ((msg->header.length + MSG_IN_OVERHEAD + 3) & 0xfffc))
  372. {
  373. dbug(0,dprintf("Q-FULL1(msg) - len=%d write=%d read=%d wrap=%d free=%d",
  374. msg->header.length, plci->msg_in_write_pos,
  375. plci->msg_in_read_pos, plci->msg_in_wrap_pos, i));
  376. return _QUEUE_FULL;
  377. }
  378. c = false;
  379. if ((((byte *) msg) < ((byte *)(plci->msg_in_queue)))
  380. || (((byte *) msg) >= ((byte *)(plci->msg_in_queue)) + sizeof(plci->msg_in_queue)))
  381. {
  382. if (plci->msg_in_write_pos != plci->msg_in_read_pos)
  383. c = true;
  384. }
  385. if (msg->header.command == _DATA_B3_R)
  386. {
  387. if (msg->header.length < 20)
  388. {
  389. dbug(1,dprintf("DATA_B3 REQ wrong length %d", msg->header.length));
  390. return _BAD_MSG;
  391. }
  392. ncci_ptr = &(a->ncci[ncci]);
  393. n = ncci_ptr->data_pending;
  394. l = ncci_ptr->data_ack_pending;
  395. k = plci->msg_in_read_pos;
  396. while (k != plci->msg_in_write_pos)
  397. {
  398. if (k == plci->msg_in_wrap_pos)
  399. k = 0;
  400. if ((((CAPI_MSG *)(&((byte *)(plci->msg_in_queue))[k]))->header.command == _DATA_B3_R)
  401. && (((CAPI_MSG *)(&((byte *)(plci->msg_in_queue))[k]))->header.ncci == ncci))
  402. {
  403. n++;
  404. if (((CAPI_MSG *)(&((byte *)(plci->msg_in_queue))[k]))->info.data_b3_req.Flags & 0x0004)
  405. l++;
  406. }
  407. k += (((CAPI_MSG *)(&((byte *)(plci->msg_in_queue))[k]))->header.length +
  408. MSG_IN_OVERHEAD + 3) & 0xfffc;
  409. }
  410. if ((n >= MAX_DATA_B3) || (l >= MAX_DATA_ACK))
  411. {
  412. dbug(0,dprintf("Q-FULL2(data) - pending=%d/%d ack_pending=%d/%d",
  413. ncci_ptr->data_pending, n, ncci_ptr->data_ack_pending, l));
  414. return _QUEUE_FULL;
  415. }
  416. if (plci->req_in || plci->internal_command)
  417. {
  418. if ((((byte *) msg) >= ((byte *)(plci->msg_in_queue)))
  419. && (((byte *) msg) < ((byte *)(plci->msg_in_queue)) + sizeof(plci->msg_in_queue)))
  420. {
  421. dbug(0,dprintf("Q-FULL3(requeue)"));
  422. return _QUEUE_FULL;
  423. }
  424. c = true;
  425. }
  426. }
  427. else
  428. {
  429. if (plci->req_in || plci->internal_command)
  430. c = true;
  431. else
  432. {
  433. plci->command = msg->header.command;
  434. plci->number = msg->header.number;
  435. }
  436. }
  437. if (c)
  438. {
  439. dbug(1,dprintf("enqueue msg(0x%04x,0x%x,0x%x) - len=%d write=%d read=%d wrap=%d free=%d",
  440. msg->header.command, plci->req_in, plci->internal_command,
  441. msg->header.length, plci->msg_in_write_pos,
  442. plci->msg_in_read_pos, plci->msg_in_wrap_pos, i));
  443. if (j == 0)
  444. plci->msg_in_wrap_pos = plci->msg_in_write_pos;
  445. m = (CAPI_MSG *)(&((byte *)(plci->msg_in_queue))[j]);
  446. for (i = 0; i < msg->header.length; i++)
  447. ((byte *)(plci->msg_in_queue))[j++] = ((byte *) msg)[i];
  448. if (m->header.command == _DATA_B3_R)
  449. {
  450. m->info.data_b3_req.Data = (dword)(long)(TransmitBufferSet (appl, m->info.data_b3_req.Data));
  451. }
  452. j = (j + 3) & 0xfffc;
  453. *((APPL * *)(&((byte *)(plci->msg_in_queue))[j])) = appl;
  454. plci->msg_in_write_pos = j + MSG_IN_OVERHEAD;
  455. return 0;
  456. }
  457. }
  458. else
  459. {
  460. plci = NULL;
  461. }
  462. }
  463. dbug(1,dprintf("com=%x",msg->header.command));
  464. for(j=0;j<MAX_MSG_PARMS+1;j++) msg_parms[j].length = 0;
  465. for(i=0, ret = _BAD_MSG;
  466. i<(sizeof(ftable)/sizeof(struct _ftable));
  467. i++) {
  468. if(ftable[i].command==msg->header.command) {
  469. /* break loop if the message is correct, otherwise continue scan */
  470. /* (for example: CONNECT_B3_T90_ACT_RES has two specifications) */
  471. if(!api_parse(msg->info.b,(word)(msg->header.length-12),ftable[i].format,msg_parms)) {
  472. ret = 0;
  473. break;
  474. }
  475. for(j=0;j<MAX_MSG_PARMS+1;j++) msg_parms[j].length = 0;
  476. }
  477. }
  478. if(ret) {
  479. dbug(1,dprintf("BAD_MSG"));
  480. if(plci) plci->command = 0;
  481. return ret;
  482. }
  483. c = ftable[i].function(GET_DWORD(&msg->header.controller),
  484. msg->header.number,
  485. a,
  486. plci,
  487. appl,
  488. msg_parms);
  489. channel_xmit_extended_xon (plci);
  490. if(c==1) send_req(plci);
  491. if(c==2 && plci) plci->req_in = plci->req_in_start = plci->req_out = 0;
  492. if(plci && !plci->req_in) plci->command = 0;
  493. return 0;
  494. }
  495. /*------------------------------------------------------------------*/
  496. /* api_parse function, check the format of api messages */
  497. /*------------------------------------------------------------------*/
  498. static word api_parse(byte *msg, word length, byte *format, API_PARSE *parms)
  499. {
  500. word i;
  501. word p;
  502. for(i=0,p=0; format[i]; i++) {
  503. if(parms)
  504. {
  505. parms[i].info = &msg[p];
  506. }
  507. switch(format[i]) {
  508. case 'b':
  509. p +=1;
  510. break;
  511. case 'w':
  512. p +=2;
  513. break;
  514. case 'd':
  515. p +=4;
  516. break;
  517. case 's':
  518. if(msg[p]==0xff) {
  519. parms[i].info +=2;
  520. parms[i].length = msg[p+1] + (msg[p+2]<<8);
  521. p +=(parms[i].length +3);
  522. }
  523. else {
  524. parms[i].length = msg[p];
  525. p +=(parms[i].length +1);
  526. }
  527. break;
  528. }
  529. if(p>length) return true;
  530. }
  531. if(parms) parms[i].info = NULL;
  532. return false;
  533. }
  534. static void api_save_msg(API_PARSE *in, byte *format, API_SAVE *out)
  535. {
  536. word i, j, n = 0;
  537. byte *p;
  538. p = out->info;
  539. for (i = 0; format[i] != '\0'; i++)
  540. {
  541. out->parms[i].info = p;
  542. out->parms[i].length = in[i].length;
  543. switch (format[i])
  544. {
  545. case 'b':
  546. n = 1;
  547. break;
  548. case 'w':
  549. n = 2;
  550. break;
  551. case 'd':
  552. n = 4;
  553. break;
  554. case 's':
  555. n = in[i].length + 1;
  556. break;
  557. }
  558. for (j = 0; j < n; j++)
  559. *(p++) = in[i].info[j];
  560. }
  561. out->parms[i].info = NULL;
  562. out->parms[i].length = 0;
  563. }
  564. static void api_load_msg(API_SAVE *in, API_PARSE *out)
  565. {
  566. word i;
  567. i = 0;
  568. do
  569. {
  570. out[i].info = in->parms[i].info;
  571. out[i].length = in->parms[i].length;
  572. } while (in->parms[i++].info);
  573. }
  574. /*------------------------------------------------------------------*/
  575. /* CAPI remove function */
  576. /*------------------------------------------------------------------*/
  577. word api_remove_start(void)
  578. {
  579. word i;
  580. word j;
  581. if(!remove_started) {
  582. remove_started = true;
  583. for(i=0;i<max_adapter;i++) {
  584. if(adapter[i].request) {
  585. for(j=0;j<adapter[i].max_plci;j++) {
  586. if(adapter[i].plci[j].Sig.Id) plci_remove(&adapter[i].plci[j]);
  587. }
  588. }
  589. }
  590. return 1;
  591. }
  592. else {
  593. for(i=0;i<max_adapter;i++) {
  594. if(adapter[i].request) {
  595. for(j=0;j<adapter[i].max_plci;j++) {
  596. if(adapter[i].plci[j].Sig.Id) return 1;
  597. }
  598. }
  599. }
  600. }
  601. api_remove_complete();
  602. return 0;
  603. }
  604. /*------------------------------------------------------------------*/
  605. /* internal command queue */
  606. /*------------------------------------------------------------------*/
  607. static void init_internal_command_queue (PLCI *plci)
  608. {
  609. word i;
  610. dbug (1, dprintf ("%s,%d: init_internal_command_queue",
  611. (char *)(FILE_), __LINE__));
  612. plci->internal_command = 0;
  613. for (i = 0; i < MAX_INTERNAL_COMMAND_LEVELS; i++)
  614. plci->internal_command_queue[i] = NULL;
  615. }
  616. static void start_internal_command (dword Id, PLCI *plci, t_std_internal_command command_function)
  617. {
  618. word i;
  619. dbug (1, dprintf ("[%06lx] %s,%d: start_internal_command",
  620. UnMapId (Id), (char *)(FILE_), __LINE__));
  621. if (plci->internal_command == 0)
  622. {
  623. plci->internal_command_queue[0] = command_function;
  624. (* command_function)(Id, plci, OK);
  625. }
  626. else
  627. {
  628. i = 1;
  629. while (plci->internal_command_queue[i] != NULL)
  630. i++;
  631. plci->internal_command_queue[i] = command_function;
  632. }
  633. }
  634. static void next_internal_command (dword Id, PLCI *plci)
  635. {
  636. word i;
  637. dbug (1, dprintf ("[%06lx] %s,%d: next_internal_command",
  638. UnMapId (Id), (char *)(FILE_), __LINE__));
  639. plci->internal_command = 0;
  640. plci->internal_command_queue[0] = NULL;
  641. while (plci->internal_command_queue[1] != NULL)
  642. {
  643. for (i = 0; i < MAX_INTERNAL_COMMAND_LEVELS - 1; i++)
  644. plci->internal_command_queue[i] = plci->internal_command_queue[i+1];
  645. plci->internal_command_queue[MAX_INTERNAL_COMMAND_LEVELS - 1] = NULL;
  646. (*(plci->internal_command_queue[0]))(Id, plci, OK);
  647. if (plci->internal_command != 0)
  648. return;
  649. plci->internal_command_queue[0] = NULL;
  650. }
  651. }
  652. /*------------------------------------------------------------------*/
  653. /* NCCI allocate/remove function */
  654. /*------------------------------------------------------------------*/
  655. static dword ncci_mapping_bug = 0;
  656. static word get_ncci (PLCI *plci, byte ch, word force_ncci)
  657. {
  658. DIVA_CAPI_ADAPTER *a;
  659. word ncci, i, j, k;
  660. a = plci->adapter;
  661. if (!ch || a->ch_ncci[ch])
  662. {
  663. ncci_mapping_bug++;
  664. dbug(1,dprintf("NCCI mapping exists %ld %02x %02x %02x-%02x",
  665. ncci_mapping_bug, ch, force_ncci, a->ncci_ch[a->ch_ncci[ch]], a->ch_ncci[ch]));
  666. ncci = ch;
  667. }
  668. else
  669. {
  670. if (force_ncci)
  671. ncci = force_ncci;
  672. else
  673. {
  674. if ((ch < MAX_NCCI+1) && !a->ncci_ch[ch])
  675. ncci = ch;
  676. else
  677. {
  678. ncci = 1;
  679. while ((ncci < MAX_NCCI+1) && a->ncci_ch[ncci])
  680. ncci++;
  681. if (ncci == MAX_NCCI+1)
  682. {
  683. ncci_mapping_bug++;
  684. i = 1;
  685. do
  686. {
  687. j = 1;
  688. while ((j < MAX_NCCI+1) && (a->ncci_ch[j] != i))
  689. j++;
  690. k = j;
  691. if (j < MAX_NCCI+1)
  692. {
  693. do
  694. {
  695. j++;
  696. } while ((j < MAX_NCCI+1) && (a->ncci_ch[j] != i));
  697. }
  698. } while ((i < MAX_NL_CHANNEL+1) && (j < MAX_NCCI+1));
  699. if (i < MAX_NL_CHANNEL+1)
  700. {
  701. dbug(1,dprintf("NCCI mapping overflow %ld %02x %02x %02x-%02x-%02x",
  702. ncci_mapping_bug, ch, force_ncci, i, k, j));
  703. }
  704. else
  705. {
  706. dbug(1,dprintf("NCCI mapping overflow %ld %02x %02x",
  707. ncci_mapping_bug, ch, force_ncci));
  708. }
  709. ncci = ch;
  710. }
  711. }
  712. a->ncci_plci[ncci] = plci->Id;
  713. a->ncci_state[ncci] = IDLE;
  714. if (!plci->ncci_ring_list)
  715. plci->ncci_ring_list = ncci;
  716. else
  717. a->ncci_next[ncci] = a->ncci_next[plci->ncci_ring_list];
  718. a->ncci_next[plci->ncci_ring_list] = (byte) ncci;
  719. }
  720. a->ncci_ch[ncci] = ch;
  721. a->ch_ncci[ch] = (byte) ncci;
  722. dbug(1,dprintf("NCCI mapping established %ld %02x %02x %02x-%02x",
  723. ncci_mapping_bug, ch, force_ncci, ch, ncci));
  724. }
  725. return (ncci);
  726. }
  727. static void ncci_free_receive_buffers (PLCI *plci, word ncci)
  728. {
  729. DIVA_CAPI_ADAPTER *a;
  730. APPL *appl;
  731. word i, ncci_code;
  732. dword Id;
  733. a = plci->adapter;
  734. Id = (((dword) ncci) << 16) | (((word)(plci->Id)) << 8) | a->Id;
  735. if (ncci)
  736. {
  737. if (a->ncci_plci[ncci] == plci->Id)
  738. {
  739. if (!plci->appl)
  740. {
  741. ncci_mapping_bug++;
  742. dbug(1,dprintf("NCCI mapping appl expected %ld %08lx",
  743. ncci_mapping_bug, Id));
  744. }
  745. else
  746. {
  747. appl = plci->appl;
  748. ncci_code = ncci | (((word) a->Id) << 8);
  749. for (i = 0; i < appl->MaxBuffer; i++)
  750. {
  751. if ((appl->DataNCCI[i] == ncci_code)
  752. && (((byte)(appl->DataFlags[i] >> 8)) == plci->Id))
  753. {
  754. appl->DataNCCI[i] = 0;
  755. }
  756. }
  757. }
  758. }
  759. }
  760. else
  761. {
  762. for (ncci = 1; ncci < MAX_NCCI+1; ncci++)
  763. {
  764. if (a->ncci_plci[ncci] == plci->Id)
  765. {
  766. if (!plci->appl)
  767. {
  768. ncci_mapping_bug++;
  769. dbug(1,dprintf("NCCI mapping no appl %ld %08lx",
  770. ncci_mapping_bug, Id));
  771. }
  772. else
  773. {
  774. appl = plci->appl;
  775. ncci_code = ncci | (((word) a->Id) << 8);
  776. for (i = 0; i < appl->MaxBuffer; i++)
  777. {
  778. if ((appl->DataNCCI[i] == ncci_code)
  779. && (((byte)(appl->DataFlags[i] >> 8)) == plci->Id))
  780. {
  781. appl->DataNCCI[i] = 0;
  782. }
  783. }
  784. }
  785. }
  786. }
  787. }
  788. }
  789. static void cleanup_ncci_data (PLCI *plci, word ncci)
  790. {
  791. NCCI *ncci_ptr;
  792. if (ncci && (plci->adapter->ncci_plci[ncci] == plci->Id))
  793. {
  794. ncci_ptr = &(plci->adapter->ncci[ncci]);
  795. if (plci->appl)
  796. {
  797. while (ncci_ptr->data_pending != 0)
  798. {
  799. if (!plci->data_sent || (ncci_ptr->DBuffer[ncci_ptr->data_out].P != plci->data_sent_ptr))
  800. TransmitBufferFree (plci->appl, ncci_ptr->DBuffer[ncci_ptr->data_out].P);
  801. (ncci_ptr->data_out)++;
  802. if (ncci_ptr->data_out == MAX_DATA_B3)
  803. ncci_ptr->data_out = 0;
  804. (ncci_ptr->data_pending)--;
  805. }
  806. }
  807. ncci_ptr->data_out = 0;
  808. ncci_ptr->data_pending = 0;
  809. ncci_ptr->data_ack_out = 0;
  810. ncci_ptr->data_ack_pending = 0;
  811. }
  812. }
  813. static void ncci_remove (PLCI *plci, word ncci, byte preserve_ncci)
  814. {
  815. DIVA_CAPI_ADAPTER *a;
  816. dword Id;
  817. word i;
  818. a = plci->adapter;
  819. Id = (((dword) ncci) << 16) | (((word)(plci->Id)) << 8) | a->Id;
  820. if (!preserve_ncci)
  821. ncci_free_receive_buffers (plci, ncci);
  822. if (ncci)
  823. {
  824. if (a->ncci_plci[ncci] != plci->Id)
  825. {
  826. ncci_mapping_bug++;
  827. dbug(1,dprintf("NCCI mapping doesn't exist %ld %08lx %02x",
  828. ncci_mapping_bug, Id, preserve_ncci));
  829. }
  830. else
  831. {
  832. cleanup_ncci_data (plci, ncci);
  833. dbug(1,dprintf("NCCI mapping released %ld %08lx %02x %02x-%02x",
  834. ncci_mapping_bug, Id, preserve_ncci, a->ncci_ch[ncci], ncci));
  835. a->ch_ncci[a->ncci_ch[ncci]] = 0;
  836. if (!preserve_ncci)
  837. {
  838. a->ncci_ch[ncci] = 0;
  839. a->ncci_plci[ncci] = 0;
  840. a->ncci_state[ncci] = IDLE;
  841. i = plci->ncci_ring_list;
  842. while ((i != 0) && (a->ncci_next[i] != plci->ncci_ring_list) && (a->ncci_next[i] != ncci))
  843. i = a->ncci_next[i];
  844. if ((i != 0) && (a->ncci_next[i] == ncci))
  845. {
  846. if (i == ncci)
  847. plci->ncci_ring_list = 0;
  848. else if (plci->ncci_ring_list == ncci)
  849. plci->ncci_ring_list = i;
  850. a->ncci_next[i] = a->ncci_next[ncci];
  851. }
  852. a->ncci_next[ncci] = 0;
  853. }
  854. }
  855. }
  856. else
  857. {
  858. for (ncci = 1; ncci < MAX_NCCI+1; ncci++)
  859. {
  860. if (a->ncci_plci[ncci] == plci->Id)
  861. {
  862. cleanup_ncci_data (plci, ncci);
  863. dbug(1,dprintf("NCCI mapping released %ld %08lx %02x %02x-%02x",
  864. ncci_mapping_bug, Id, preserve_ncci, a->ncci_ch[ncci], ncci));
  865. a->ch_ncci[a->ncci_ch[ncci]] = 0;
  866. if (!preserve_ncci)
  867. {
  868. a->ncci_ch[ncci] = 0;
  869. a->ncci_plci[ncci] = 0;
  870. a->ncci_state[ncci] = IDLE;
  871. a->ncci_next[ncci] = 0;
  872. }
  873. }
  874. }
  875. if (!preserve_ncci)
  876. plci->ncci_ring_list = 0;
  877. }
  878. }
  879. /*------------------------------------------------------------------*/
  880. /* PLCI remove function */
  881. /*------------------------------------------------------------------*/
  882. static void plci_free_msg_in_queue (PLCI *plci)
  883. {
  884. word i;
  885. if (plci->appl)
  886. {
  887. i = plci->msg_in_read_pos;
  888. while (i != plci->msg_in_write_pos)
  889. {
  890. if (i == plci->msg_in_wrap_pos)
  891. i = 0;
  892. if (((CAPI_MSG *)(&((byte *)(plci->msg_in_queue))[i]))->header.command == _DATA_B3_R)
  893. {
  894. TransmitBufferFree (plci->appl,
  895. (byte *)(long)(((CAPI_MSG *)(&((byte *)(plci->msg_in_queue))[i]))->info.data_b3_req.Data));
  896. }
  897. i += (((CAPI_MSG *)(&((byte *)(plci->msg_in_queue))[i]))->header.length +
  898. MSG_IN_OVERHEAD + 3) & 0xfffc;
  899. }
  900. }
  901. plci->msg_in_write_pos = MSG_IN_QUEUE_SIZE;
  902. plci->msg_in_read_pos = MSG_IN_QUEUE_SIZE;
  903. plci->msg_in_wrap_pos = MSG_IN_QUEUE_SIZE;
  904. }
  905. static void plci_remove(PLCI * plci)
  906. {
  907. if(!plci) {
  908. dbug(1,dprintf("plci_remove(no plci)"));
  909. return;
  910. }
  911. init_internal_command_queue (plci);
  912. dbug(1,dprintf("plci_remove(%x,tel=%x)",plci->Id,plci->tel));
  913. if(plci_remove_check(plci))
  914. {
  915. return;
  916. }
  917. if (plci->Sig.Id == 0xff)
  918. {
  919. dbug(1,dprintf("D-channel X.25 plci->NL.Id:%0x", plci->NL.Id));
  920. if (plci->NL.Id && !plci->nl_remove_id)
  921. {
  922. nl_req_ncci(plci,REMOVE,0);
  923. send_req(plci);
  924. }
  925. }
  926. else
  927. {
  928. if (!plci->sig_remove_id
  929. && (plci->Sig.Id
  930. || (plci->req_in!=plci->req_out)
  931. || (plci->nl_req || plci->sig_req)))
  932. {
  933. sig_req(plci,HANGUP,0);
  934. send_req(plci);
  935. }
  936. }
  937. ncci_remove (plci, 0, false);
  938. plci_free_msg_in_queue (plci);
  939. plci->channels = 0;
  940. plci->appl = NULL;
  941. if ((plci->State == INC_CON_PENDING) || (plci->State == INC_CON_ALERT))
  942. plci->State = OUTG_DIS_PENDING;
  943. }
  944. /*------------------------------------------------------------------*/
  945. /* Application Group function helpers */
  946. /*------------------------------------------------------------------*/
  947. static void set_group_ind_mask (PLCI *plci)
  948. {
  949. word i;
  950. for (i = 0; i < C_IND_MASK_DWORDS; i++)
  951. plci->group_optimization_mask_table[i] = 0xffffffffL;
  952. }
  953. static void clear_group_ind_mask_bit (PLCI *plci, word b)
  954. {
  955. plci->group_optimization_mask_table[b >> 5] &= ~(1L << (b & 0x1f));
  956. }
  957. static byte test_group_ind_mask_bit (PLCI *plci, word b)
  958. {
  959. return ((plci->group_optimization_mask_table[b >> 5] & (1L << (b & 0x1f))) != 0);
  960. }
  961. /*------------------------------------------------------------------*/
  962. /* c_ind_mask operations for arbitrary MAX_APPL */
  963. /*------------------------------------------------------------------*/
  964. static void clear_c_ind_mask (PLCI *plci)
  965. {
  966. word i;
  967. for (i = 0; i < C_IND_MASK_DWORDS; i++)
  968. plci->c_ind_mask_table[i] = 0;
  969. }
  970. static byte c_ind_mask_empty (PLCI *plci)
  971. {
  972. word i;
  973. i = 0;
  974. while ((i < C_IND_MASK_DWORDS) && (plci->c_ind_mask_table[i] == 0))
  975. i++;
  976. return (i == C_IND_MASK_DWORDS);
  977. }
  978. static void set_c_ind_mask_bit (PLCI *plci, word b)
  979. {
  980. plci->c_ind_mask_table[b >> 5] |= (1L << (b & 0x1f));
  981. }
  982. static void clear_c_ind_mask_bit (PLCI *plci, word b)
  983. {
  984. plci->c_ind_mask_table[b >> 5] &= ~(1L << (b & 0x1f));
  985. }
  986. static byte test_c_ind_mask_bit (PLCI *plci, word b)
  987. {
  988. return ((plci->c_ind_mask_table[b >> 5] & (1L << (b & 0x1f))) != 0);
  989. }
  990. static void dump_c_ind_mask (PLCI *plci)
  991. {
  992. static char hex_digit_table[0x10] =
  993. {'0','1','2','3','4','5','6','7','8','9','a','b','c','d','e','f'};
  994. word i, j, k;
  995. dword d;
  996. char *p;
  997. char buf[40];
  998. for (i = 0; i < C_IND_MASK_DWORDS; i += 4)
  999. {
  1000. p = buf + 36;
  1001. *p = '\0';
  1002. for (j = 0; j < 4; j++)
  1003. {
  1004. if (i+j < C_IND_MASK_DWORDS)
  1005. {
  1006. d = plci->c_ind_mask_table[i+j];
  1007. for (k = 0; k < 8; k++)
  1008. {
  1009. *(--p) = hex_digit_table[d & 0xf];
  1010. d >>= 4;
  1011. }
  1012. }
  1013. else if (i != 0)
  1014. {
  1015. for (k = 0; k < 8; k++)
  1016. *(--p) = ' ';
  1017. }
  1018. *(--p) = ' ';
  1019. }
  1020. dbug(1,dprintf ("c_ind_mask =%s", (char *) p));
  1021. }
  1022. }
  1023. #define dump_plcis(a)
  1024. /*------------------------------------------------------------------*/
  1025. /* translation function for each message */
  1026. /*------------------------------------------------------------------*/
  1027. static byte connect_req(dword Id, word Number, DIVA_CAPI_ADAPTER *a,
  1028. PLCI *plci, APPL *appl, API_PARSE *parms)
  1029. {
  1030. word ch;
  1031. word i;
  1032. word Info;
  1033. word CIP;
  1034. byte LinkLayer;
  1035. API_PARSE * ai;
  1036. API_PARSE * bp;
  1037. API_PARSE ai_parms[5];
  1038. word channel = 0;
  1039. dword ch_mask;
  1040. byte m;
  1041. static byte esc_chi[35] = {0x02,0x18,0x01};
  1042. static byte lli[2] = {0x01,0x00};
  1043. byte noCh = 0;
  1044. word dir = 0;
  1045. byte *p_chi = "";
  1046. for(i=0;i<5;i++) ai_parms[i].length = 0;
  1047. dbug(1,dprintf("connect_req(%d)",parms->length));
  1048. Info = _WRONG_IDENTIFIER;
  1049. if(a)
  1050. {
  1051. if(a->adapter_disabled)
  1052. {
  1053. dbug(1,dprintf("adapter disabled"));
  1054. Id = ((word)1<<8)|a->Id;
  1055. sendf(appl,_CONNECT_R|CONFIRM,Id,Number,"w",0);
  1056. sendf(appl, _DISCONNECT_I, Id, 0, "w", _L1_ERROR);
  1057. return false;
  1058. }
  1059. Info = _OUT_OF_PLCI;
  1060. if((i=get_plci(a)))
  1061. {
  1062. Info = 0;
  1063. plci = &a->plci[i-1];
  1064. plci->appl = appl;
  1065. plci->call_dir = CALL_DIR_OUT | CALL_DIR_ORIGINATE;
  1066. /* check 'external controller' bit for codec support */
  1067. if(Id & EXT_CONTROLLER)
  1068. {
  1069. if(AdvCodecSupport(a, plci, appl, 0) )
  1070. {
  1071. plci->Id = 0;
  1072. sendf(appl, _CONNECT_R|CONFIRM, Id, Number, "w", _WRONG_IDENTIFIER);
  1073. return 2;
  1074. }
  1075. }
  1076. ai = &parms[9];
  1077. bp = &parms[5];
  1078. ch = 0;
  1079. if(bp->length)LinkLayer = bp->info[3];
  1080. else LinkLayer = 0;
  1081. if(ai->length)
  1082. {
  1083. ch=0xffff;
  1084. if(!api_parse(&ai->info[1],(word)ai->length,"ssss",ai_parms))
  1085. {
  1086. ch = 0;
  1087. if(ai_parms[0].length)
  1088. {
  1089. ch = GET_WORD(ai_parms[0].info+1);
  1090. if(ch>4) ch=0; /* safety -> ignore ChannelID */
  1091. if(ch==4) /* explizit CHI in message */
  1092. {
  1093. /* check length of B-CH struct */
  1094. if((ai_parms[0].info)[3]>=1)
  1095. {
  1096. if((ai_parms[0].info)[4]==CHI)
  1097. {
  1098. p_chi = &((ai_parms[0].info)[5]);
  1099. }
  1100. else
  1101. {
  1102. p_chi = &((ai_parms[0].info)[3]);
  1103. }
  1104. if(p_chi[0]>35) /* check length of channel ID */
  1105. {
  1106. Info = _WRONG_MESSAGE_FORMAT;
  1107. }
  1108. }
  1109. else Info = _WRONG_MESSAGE_FORMAT;
  1110. }
  1111. if(ch==3 && ai_parms[0].length>=7 && ai_parms[0].length<=36)
  1112. {
  1113. dir = GET_WORD(ai_parms[0].info+3);
  1114. ch_mask = 0;
  1115. m = 0x3f;
  1116. for(i=0; i+5<=ai_parms[0].length; i++)
  1117. {
  1118. if(ai_parms[0].info[i+5]!=0)
  1119. {
  1120. if((ai_parms[0].info[i+5] | m) != 0xff)
  1121. Info = _WRONG_MESSAGE_FORMAT;
  1122. else
  1123. {
  1124. if (ch_mask == 0)
  1125. channel = i;
  1126. ch_mask |= 1L << i;
  1127. }
  1128. }
  1129. m = 0;
  1130. }
  1131. if (ch_mask == 0)
  1132. Info = _WRONG_MESSAGE_FORMAT;
  1133. if (!Info)
  1134. {
  1135. if ((ai_parms[0].length == 36) || (ch_mask != ((dword)(1L << channel))))
  1136. {
  1137. esc_chi[0] = (byte)(ai_parms[0].length - 2);
  1138. for(i=0; i+5<=ai_parms[0].length; i++)
  1139. esc_chi[i+3] = ai_parms[0].info[i+5];
  1140. }
  1141. else
  1142. esc_chi[0] = 2;
  1143. esc_chi[2] = (byte)channel;
  1144. plci->b_channel = (byte)channel; /* not correct for ETSI ch 17..31 */
  1145. add_p(plci,LLI,lli);
  1146. add_p(plci,ESC,esc_chi);
  1147. plci->State = LOCAL_CONNECT;
  1148. if(!dir) plci->call_dir |= CALL_DIR_FORCE_OUTG_NL; /* dir 0=DTE, 1=DCE */
  1149. }
  1150. }
  1151. }
  1152. }
  1153. else Info = _WRONG_MESSAGE_FORMAT;
  1154. }
  1155. dbug(1,dprintf("ch=%x,dir=%x,p_ch=%d",ch,dir,channel));
  1156. plci->command = _CONNECT_R;
  1157. plci->number = Number;
  1158. /* x.31 or D-ch free SAPI in LinkLayer? */
  1159. if(ch==1 && LinkLayer!=3 && LinkLayer!=12) noCh = true;
  1160. if((ch==0 || ch==2 || noCh || ch==3 || ch==4) && !Info)
  1161. {
  1162. /* B-channel used for B3 connections (ch==0), or no B channel */
  1163. /* is used (ch==2) or perm. connection (3) is used do a CALL */
  1164. if(noCh) Info = add_b1(plci,&parms[5],2,0); /* no resource */
  1165. else Info = add_b1(plci,&parms[5],ch,0);
  1166. add_s(plci,OAD,&parms[2]);
  1167. add_s(plci,OSA,&parms[4]);
  1168. add_s(plci,BC,&parms[6]);
  1169. add_s(plci,LLC,&parms[7]);
  1170. add_s(plci,HLC,&parms[8]);
  1171. CIP = GET_WORD(parms[0].info);
  1172. if (a->Info_Mask[appl->Id-1] & 0x200)
  1173. {
  1174. /* early B3 connect (CIP mask bit 9) no release after a disc */
  1175. add_p(plci,LLI,"\x01\x01");
  1176. }
  1177. if(GET_WORD(parms[0].info)<29) {
  1178. add_p(plci,BC,cip_bc[GET_WORD(parms[0].info)][a->u_law]);
  1179. add_p(plci,HLC,cip_hlc[GET_WORD(parms[0].info)]);
  1180. }
  1181. add_p(plci,UID,"\x06\x43\x61\x70\x69\x32\x30");
  1182. sig_req(plci,ASSIGN,DSIG_ID);
  1183. }
  1184. else if(ch==1) {
  1185. /* D-Channel used for B3 connections */
  1186. plci->Sig.Id = 0xff;
  1187. Info = 0;
  1188. }
  1189. if(!Info && ch!=2 && !noCh ) {
  1190. Info = add_b23(plci,&parms[5]);
  1191. if(!Info) {
  1192. if(!(plci->tel && !plci->adv_nl))nl_req_ncci(plci,ASSIGN,0);
  1193. }
  1194. }
  1195. if(!Info)
  1196. {
  1197. if(ch==0 || ch==2 || ch==3 || noCh || ch==4)
  1198. {
  1199. if(plci->spoofed_msg==SPOOFING_REQUIRED)
  1200. {
  1201. api_save_msg(parms, "wsssssssss", &plci->saved_msg);
  1202. plci->spoofed_msg = CALL_REQ;
  1203. plci->internal_command = BLOCK_PLCI;
  1204. plci->command = 0;
  1205. dbug(1,dprintf("Spoof"));
  1206. send_req(plci);
  1207. return false;
  1208. }
  1209. if(ch==4)add_p(plci,CHI,p_chi);
  1210. add_s(plci,CPN,&parms[1]);
  1211. add_s(plci,DSA,&parms[3]);
  1212. if(noCh) add_p(plci,ESC,"\x02\x18\xfd"); /* D-channel, no B-L3 */
  1213. add_ai(plci,&parms[9]);
  1214. if(!dir)sig_req(plci,CALL_REQ,0);
  1215. else
  1216. {
  1217. plci->command = PERM_LIST_REQ;
  1218. plci->appl = appl;
  1219. sig_req(plci,LISTEN_REQ,0);
  1220. send_req(plci);
  1221. return false;
  1222. }
  1223. }
  1224. send_req(plci);
  1225. return false;
  1226. }
  1227. plci->Id = 0;
  1228. }
  1229. }
  1230. sendf(appl,
  1231. _CONNECT_R|CONFIRM,
  1232. Id,
  1233. Number,
  1234. "w",Info);
  1235. return 2;
  1236. }
  1237. static byte connect_res(dword Id, word Number, DIVA_CAPI_ADAPTER *a,
  1238. PLCI *plci, APPL *appl, API_PARSE *parms)
  1239. {
  1240. word i, Info;
  1241. word Reject;
  1242. static byte cau_t[] = {0,0,0x90,0x91,0xac,0x9d,0x86,0xd8,0x9b};
  1243. static byte esc_t[] = {0x03,0x08,0x00,0x00};
  1244. API_PARSE * ai;
  1245. API_PARSE ai_parms[5];
  1246. word ch=0;
  1247. if(!plci) {
  1248. dbug(1,dprintf("connect_res(no plci)"));
  1249. return 0; /* no plci, no send */
  1250. }
  1251. dbug(1,dprintf("connect_res(State=0x%x)",plci->State));
  1252. for(i=0;i<5;i++) ai_parms[i].length = 0;
  1253. ai = &parms[5];
  1254. dbug(1,dprintf("ai->length=%d",ai->length));
  1255. if(ai->length)
  1256. {
  1257. if(!api_parse(&ai->info[1],(word)ai->length,"ssss",ai_parms))
  1258. {
  1259. dbug(1,dprintf("ai_parms[0].length=%d/0x%x",ai_parms[0].length,GET_WORD(ai_parms[0].info+1)));
  1260. ch = 0;
  1261. if(ai_parms[0].length)
  1262. {
  1263. ch = GET_WORD(ai_parms[0].info+1);
  1264. dbug(1,dprintf("BCH-I=0x%x",ch));
  1265. }
  1266. }
  1267. }
  1268. if(plci->State==INC_CON_CONNECTED_ALERT)
  1269. {
  1270. dbug(1,dprintf("Connected Alert Call_Res"));
  1271. if (a->Info_Mask[appl->Id-1] & 0x200)
  1272. {
  1273. /* early B3 connect (CIP mask bit 9) no release after a disc */
  1274. add_p(plci,LLI,"\x01\x01");
  1275. }
  1276. add_s(plci, CONN_NR, &parms[2]);
  1277. add_s(plci, LLC, &parms[4]);
  1278. add_ai(plci, &parms[5]);
  1279. plci->State = INC_CON_ACCEPT;
  1280. sig_req(plci, CALL_RES,0);
  1281. return 1;
  1282. }
  1283. else if(plci->State==INC_CON_PENDING || plci->State==INC_CON_ALERT) {
  1284. clear_c_ind_mask_bit (plci, (word)(appl->Id-1));
  1285. dump_c_ind_mask (plci);
  1286. Reject = GET_WORD(parms[0].info);
  1287. dbug(1,dprintf("Reject=0x%x",Reject));
  1288. if(Reject)
  1289. {
  1290. if(c_ind_mask_empty (plci))
  1291. {
  1292. if((Reject&0xff00)==0x3400)
  1293. {
  1294. esc_t[2] = ((byte)(Reject&0x00ff)) | 0x80;
  1295. add_p(plci,ESC,esc_t);
  1296. add_ai(plci, &parms[5]);
  1297. sig_req(plci,REJECT,0);
  1298. }
  1299. else if(Reject==1 || Reject>9)
  1300. {
  1301. add_ai(plci, &parms[5]);
  1302. sig_req(plci,HANGUP,0);
  1303. }
  1304. else
  1305. {
  1306. esc_t[2] = cau_t[(Reject&0x000f)];
  1307. add_p(plci,ESC,esc_t);
  1308. add_ai(plci, &parms[5]);
  1309. sig_req(plci,REJECT,0);
  1310. }
  1311. plci->appl = appl;
  1312. }
  1313. else
  1314. {
  1315. sendf(appl, _DISCONNECT_I, Id, 0, "w", _OTHER_APPL_CONNECTED);
  1316. }
  1317. }
  1318. else {
  1319. plci->appl = appl;
  1320. if(Id & EXT_CONTROLLER){
  1321. if(AdvCodecSupport(a, plci, appl, 0)){
  1322. dbug(1,dprintf("connect_res(error from AdvCodecSupport)"));
  1323. sig_req(plci,HANGUP,0);
  1324. return 1;
  1325. }
  1326. if(plci->tel == ADV_VOICE && a->AdvCodecPLCI)
  1327. {
  1328. Info = add_b23(plci, &parms[1]);
  1329. if (Info)
  1330. {
  1331. dbug(1,dprintf("connect_res(error from add_b23)"));
  1332. sig_req(plci,HANGUP,0);
  1333. return 1;
  1334. }
  1335. if(plci->adv_nl)
  1336. {
  1337. nl_req_ncci(plci, ASSIGN, 0);
  1338. }
  1339. }
  1340. }
  1341. else
  1342. {
  1343. plci->tel = 0;
  1344. if(ch!=2)
  1345. {
  1346. Info = add_b23(plci, &parms[1]);
  1347. if (Info)
  1348. {
  1349. dbug(1,dprintf("connect_res(error from add_b23 2)"));
  1350. sig_req(plci,HANGUP,0);
  1351. return 1;
  1352. }
  1353. }
  1354. nl_req_ncci(plci, ASSIGN, 0);
  1355. }
  1356. if(plci->spoofed_msg==SPOOFING_REQUIRED)
  1357. {
  1358. api_save_msg(parms, "wsssss", &plci->saved_msg);
  1359. plci->spoofed_msg = CALL_RES;
  1360. plci->internal_command = BLOCK_PLCI;
  1361. plci->command = 0;
  1362. dbug(1,dprintf("Spoof"));
  1363. }
  1364. else
  1365. {
  1366. add_b1 (plci, &parms[1], ch, plci->B1_facilities);
  1367. if (a->Info_Mask[appl->Id-1] & 0x200)
  1368. {
  1369. /* early B3 connect (CIP mask bit 9) no release after a disc */
  1370. add_p(plci,LLI,"\x01\x01");
  1371. }
  1372. add_s(plci, CONN_NR, &parms[2]);
  1373. add_s(plci, LLC, &parms[4]);
  1374. add_ai(plci, &parms[5]);
  1375. plci->State = INC_CON_ACCEPT;
  1376. sig_req(plci, CALL_RES,0);
  1377. }
  1378. for(i=0; i<max_appl; i++) {
  1379. if(test_c_ind_mask_bit (plci, i)) {
  1380. sendf(&application[i], _DISCONNECT_I, Id, 0, "w", _OTHER_APPL_CONNECTED);
  1381. }
  1382. }
  1383. }
  1384. }
  1385. return 1;
  1386. }
  1387. static byte connect_a_res(dword Id, word Number, DIVA_CAPI_ADAPTER *a,
  1388. PLCI *plci, APPL *appl, API_PARSE *msg)
  1389. {
  1390. dbug(1,dprintf("connect_a_res"));
  1391. return false;
  1392. }
  1393. static byte disconnect_req(dword Id, word Number, DIVA_CAPI_ADAPTER *a,
  1394. PLCI *plci, APPL *appl, API_PARSE *msg)
  1395. {
  1396. word Info;
  1397. word i;
  1398. dbug(1,dprintf("disconnect_req"));
  1399. Info = _WRONG_IDENTIFIER;
  1400. if(plci)
  1401. {
  1402. if(plci->State==INC_CON_PENDING || plci->State==INC_CON_ALERT)
  1403. {
  1404. clear_c_ind_mask_bit (plci, (word)(appl->Id-1));
  1405. plci->appl = appl;
  1406. for(i=0; i<max_appl; i++)
  1407. {
  1408. if(test_c_ind_mask_bit (plci, i))
  1409. sendf(&application[i], _DISCONNECT_I, Id, 0, "w", 0);
  1410. }
  1411. plci->State = OUTG_DIS_PENDING;
  1412. }
  1413. if(plci->Sig.Id && plci->appl)
  1414. {
  1415. Info = 0;
  1416. if(plci->Sig.Id!=0xff)
  1417. {
  1418. if(plci->State!=INC_DIS_PENDING)
  1419. {
  1420. add_ai(plci, &msg[0]);
  1421. sig_req(plci,HANGUP,0);
  1422. plci->State = OUTG_DIS_PENDING;
  1423. return 1;
  1424. }
  1425. }
  1426. else
  1427. {
  1428. if (plci->NL.Id && !plci->nl_remove_id)
  1429. {
  1430. mixer_remove (plci);
  1431. nl_req_ncci(plci,REMOVE,0);
  1432. sendf(appl,_DISCONNECT_R|CONFIRM,Id,Number,"w",0);
  1433. sendf(appl, _DISCONNECT_I, Id, 0, "w", 0);
  1434. plci->State = INC_DIS_PENDING;
  1435. }
  1436. return 1;
  1437. }
  1438. }
  1439. }
  1440. if(!appl) return false;
  1441. sendf(appl, _DISCONNECT_R|CONFIRM, Id, Number, "w",Info);
  1442. return false;
  1443. }
  1444. static byte disconnect_res(dword Id, word Number, DIVA_CAPI_ADAPTER *a,
  1445. PLCI *plci, APPL *appl, API_PARSE *msg)
  1446. {
  1447. dbug(1,dprintf("disconnect_res"));
  1448. if(plci)
  1449. {
  1450. /* clear ind mask bit, just in case of collsion of */
  1451. /* DISCONNECT_IND and CONNECT_RES */
  1452. clear_c_ind_mask_bit (plci, (word)(appl->Id-1));
  1453. ncci_free_receive_buffers (plci, 0);
  1454. if(plci_remove_check(plci))
  1455. {
  1456. return 0;
  1457. }
  1458. if(plci->State==INC_DIS_PENDING
  1459. || plci->State==SUSPENDING) {
  1460. if(c_ind_mask_empty (plci)) {
  1461. if(plci->State!=SUSPENDING)plci->State = IDLE;
  1462. dbug(1,dprintf("chs=%d",plci->channels));
  1463. if(!plci->channels) {
  1464. plci_remove(plci);
  1465. }
  1466. }
  1467. }
  1468. }
  1469. return 0;
  1470. }
  1471. static byte listen_req(dword Id, word Number, DIVA_CAPI_ADAPTER *a,
  1472. PLCI *plci, APPL *appl, API_PARSE *parms)
  1473. {
  1474. word Info;
  1475. byte i;
  1476. dbug(1,dprintf("listen_req(Appl=0x%x)",appl->Id));
  1477. Info = _WRONG_IDENTIFIER;
  1478. if(a) {
  1479. Info = 0;
  1480. a->Info_Mask[appl->Id-1] = GET_DWORD(parms[0].info);
  1481. a->CIP_Mask[appl->Id-1] = GET_DWORD(parms[1].info);
  1482. dbug(1,dprintf("CIP_MASK=0x%lx",GET_DWORD(parms[1].info)));
  1483. if (a->Info_Mask[appl->Id-1] & 0x200){ /* early B3 connect provides */
  1484. a->Info_Mask[appl->Id-1] |= 0x10; /* call progression infos */
  1485. }
  1486. /* check if external controller listen and switch listen on or off*/
  1487. if(Id&EXT_CONTROLLER && GET_DWORD(parms[1].info)){
  1488. if(a->profile.Global_Options & ON_BOARD_CODEC) {
  1489. dummy_plci.State = IDLE;
  1490. a->codec_listen[appl->Id-1] = &dummy_plci;
  1491. a->TelOAD[0] = (byte)(parms[3].length);
  1492. for(i=1;parms[3].length>=i && i<22;i++) {
  1493. a->TelOAD[i] = parms[3].info[i];
  1494. }
  1495. a->TelOAD[i] = 0;
  1496. a->TelOSA[0] = (byte)(parms[4].length);
  1497. for(i=1;parms[4].length>=i && i<22;i++) {
  1498. a->TelOSA[i] = parms[4].info[i];
  1499. }
  1500. a->TelOSA[i] = 0;
  1501. }
  1502. else Info = 0x2002; /* wrong controller, codec not supported */
  1503. }
  1504. else{ /* clear listen */
  1505. a->codec_listen[appl->Id-1] = (PLCI *)0;
  1506. }
  1507. }
  1508. sendf(appl,
  1509. _LISTEN_R|CONFIRM,
  1510. Id,
  1511. Number,
  1512. "w",Info);
  1513. if (a) listen_check(a);
  1514. return false;
  1515. }
  1516. static byte info_req(dword Id, word Number, DIVA_CAPI_ADAPTER *a,
  1517. PLCI *plci, APPL *appl, API_PARSE *msg)
  1518. {
  1519. word i;
  1520. API_PARSE * ai;
  1521. PLCI * rc_plci = NULL;
  1522. API_PARSE ai_parms[5];
  1523. word Info = 0;
  1524. dbug(1,dprintf("info_req"));
  1525. for(i=0;i<5;i++) ai_parms[i].length = 0;
  1526. ai = &msg[1];
  1527. if(ai->length)
  1528. {
  1529. if(api_parse(&ai->info[1],(word)ai->length,"ssss",ai_parms))
  1530. {
  1531. dbug(1,dprintf("AddInfo wrong"));
  1532. Info = _WRONG_MESSAGE_FORMAT;
  1533. }
  1534. }
  1535. if(!a) Info = _WRONG_STATE;
  1536. if(!Info && plci)
  1537. { /* no fac, with CPN, or KEY */
  1538. rc_plci = plci;
  1539. if(!ai_parms[3].length && plci->State && (msg[0].length || ai_parms[1].length) )
  1540. {
  1541. /* overlap sending option */
  1542. dbug(1,dprintf("OvlSnd"));
  1543. add_s(plci,CPN,&msg[0]);
  1544. add_s(plci,KEY,&ai_parms[1]);
  1545. sig_req(plci,INFO_REQ,0);
  1546. send_req(plci);
  1547. return false;
  1548. }
  1549. if(plci->State && ai_parms[2].length)
  1550. {
  1551. /* User_Info option */
  1552. dbug(1,dprintf("UUI"));
  1553. add_s(plci,UUI,&ai_parms[2]);
  1554. sig_req(plci,USER_DATA,0);
  1555. }
  1556. else if(plci->State && ai_parms[3].length)
  1557. {
  1558. /* Facility option */
  1559. dbug(1,dprintf("FAC"));
  1560. add_s(plci,CPN,&msg[0]);
  1561. add_ai(plci, &msg[1]);
  1562. sig_req(plci,FACILITY_REQ,0);
  1563. }
  1564. else
  1565. {
  1566. Info = _WRONG_STATE;
  1567. }
  1568. }
  1569. else if((ai_parms[1].length || ai_parms[2].length || ai_parms[3].length) && !Info)
  1570. {
  1571. /* NCR_Facility option -> send UUI and Keypad too */
  1572. dbug(1,dprintf("NCR_FAC"));
  1573. if((i=get_plci(a)))
  1574. {
  1575. rc_plci = &a->plci[i-1];
  1576. appl->NullCREnable = true;
  1577. rc_plci->internal_command = C_NCR_FAC_REQ;
  1578. rc_plci->appl = appl;
  1579. add_p(rc_plci,CAI,"\x01\x80");
  1580. add_p(rc_plci,UID,"\x06\x43\x61\x70\x69\x32\x30");
  1581. sig_req(rc_plci,ASSIGN,DSIG_ID);
  1582. send_req(rc_plci);
  1583. }
  1584. else
  1585. {
  1586. Info = _OUT_OF_PLCI;
  1587. }
  1588. if(!Info)
  1589. {
  1590. add_s(rc_plci,CPN,&msg[0]);
  1591. add_ai(rc_plci, &msg[1]);
  1592. sig_req(rc_plci,NCR_FACILITY,0);
  1593. send_req(rc_plci);
  1594. return false;
  1595. /* for application controlled supplementary services */
  1596. }
  1597. }
  1598. if (!rc_plci)
  1599. {
  1600. Info = _WRONG_MESSAGE_FORMAT;
  1601. }
  1602. if(!Info)
  1603. {
  1604. send_req(rc_plci);
  1605. }
  1606. else
  1607. { /* appl is not assigned to a PLCI or error condition */
  1608. dbug(1,dprintf("localInfoCon"));
  1609. sendf(appl,
  1610. _INFO_R|CONFIRM,
  1611. Id,
  1612. Number,
  1613. "w",Info);
  1614. }
  1615. return false;
  1616. }
  1617. static byte info_res(dword Id, word Number, DIVA_CAPI_ADAPTER *a,
  1618. PLCI *plci, APPL *appl, API_PARSE *msg)
  1619. {
  1620. dbug(1,dprintf("info_res"));
  1621. return false;
  1622. }
  1623. static byte alert_req(dword Id, word Number, DIVA_CAPI_ADAPTER *a,
  1624. PLCI *plci, APPL *appl, API_PARSE *msg)
  1625. {
  1626. word Info;
  1627. byte ret;
  1628. dbug(1,dprintf("alert_req"));
  1629. Info = _WRONG_IDENTIFIER;
  1630. ret = false;
  1631. if(plci) {
  1632. Info = _ALERT_IGNORED;
  1633. if(plci->State!=INC_CON_ALERT) {
  1634. Info = _WRONG_STATE;
  1635. if(plci->State==INC_CON_PENDING) {
  1636. Info = 0;
  1637. plci->State=INC_CON_ALERT;
  1638. add_ai(plci, &msg[0]);
  1639. sig_req(plci,CALL_ALERT,0);
  1640. ret = 1;
  1641. }
  1642. }
  1643. }
  1644. sendf(appl,
  1645. _ALERT_R|CONFIRM,
  1646. Id,
  1647. Number,
  1648. "w",Info);
  1649. return ret;
  1650. }
  1651. static byte facility_req(dword Id, word Number, DIVA_CAPI_ADAPTER *a,
  1652. PLCI *plci, APPL *appl, API_PARSE *msg)
  1653. {
  1654. word Info = 0;
  1655. word i = 0;
  1656. word selector;
  1657. word SSreq;
  1658. long relatedPLCIvalue;
  1659. DIVA_CAPI_ADAPTER * relatedadapter;
  1660. byte * SSparms = "";
  1661. byte RCparms[] = "\x05\x00\x00\x02\x00\x00";
  1662. byte SSstruct[] = "\x09\x00\x00\x06\x00\x00\x00\x00\x00\x00";
  1663. API_PARSE * parms;
  1664. API_PARSE ss_parms[11];
  1665. PLCI *rplci;
  1666. byte cai[15];
  1667. dword d;
  1668. API_PARSE dummy;
  1669. dbug(1,dprintf("facility_req"));
  1670. for(i=0;i<9;i++) ss_parms[i].length = 0;
  1671. parms = &msg[1];
  1672. if(!a)
  1673. {
  1674. dbug(1,dprintf("wrong Ctrl"));
  1675. Info = _WRONG_IDENTIFIER;
  1676. }
  1677. selector = GET_WORD(msg[0].info);
  1678. if(!Info)
  1679. {
  1680. switch(selector)
  1681. {
  1682. case SELECTOR_HANDSET:
  1683. Info = AdvCodecSupport(a, plci, appl, HOOK_SUPPORT);
  1684. break;
  1685. case SELECTOR_SU_SERV:
  1686. if(!msg[1].length)
  1687. {
  1688. Info = _WRONG_MESSAGE_FORMAT;
  1689. break;
  1690. }
  1691. SSreq = GET_WORD(&(msg[1].info[1]));
  1692. PUT_WORD(&RCparms[1],SSreq);
  1693. SSparms = RCparms;
  1694. switch(SSreq)
  1695. {
  1696. case S_GET_SUPPORTED_SERVICES:
  1697. if((i=get_plci(a)))
  1698. {
  1699. rplci = &a->plci[i-1];
  1700. rplci->appl = appl;
  1701. add_p(rplci,CAI,"\x01\x80");
  1702. add_p(rplci,UID,"\x06\x43\x61\x70\x69\x32\x30");
  1703. sig_req(rplci,ASSIGN,DSIG_ID);
  1704. send_req(rplci);
  1705. }
  1706. else
  1707. {
  1708. PUT_DWORD(&SSstruct[6], MASK_TERMINAL_PORTABILITY);
  1709. SSparms = (byte *)SSstruct;
  1710. break;
  1711. }
  1712. rplci->internal_command = GETSERV_REQ_PEND;
  1713. rplci->number = Number;
  1714. rplci->appl = appl;
  1715. sig_req(rplci,S_SUPPORTED,0);
  1716. send_req(rplci);
  1717. return false;
  1718. break;
  1719. case S_LISTEN:
  1720. if(parms->length==7)
  1721. {
  1722. if(api_parse(&parms->info[1],(word)parms->length,"wbd",ss_parms))
  1723. {
  1724. dbug(1,dprintf("format wrong"));
  1725. Info = _WRONG_MESSAGE_FORMAT;
  1726. break;
  1727. }
  1728. }
  1729. else
  1730. {
  1731. Info = _WRONG_MESSAGE_FORMAT;
  1732. break;
  1733. }
  1734. a->Notification_Mask[appl->Id-1] = GET_DWORD(ss_parms[2].info);
  1735. if(a->Notification_Mask[appl->Id-1] & SMASK_MWI) /* MWI active? */
  1736. {
  1737. if((i=get_plci(a)))
  1738. {
  1739. rplci = &a->plci[i-1];
  1740. rplci->appl = appl;
  1741. add_p(rplci,CAI,"\x01\x80");
  1742. add_p(rplci,UID,"\x06\x43\x61\x70\x69\x32\x30");
  1743. sig_req(rplci,ASSIGN,DSIG_ID);
  1744. send_req(rplci);
  1745. }
  1746. else
  1747. {
  1748. break;
  1749. }
  1750. rplci->internal_command = GET_MWI_STATE;
  1751. rplci->number = Number;
  1752. sig_req(rplci,MWI_POLL,0);
  1753. send_req(rplci);
  1754. }
  1755. break;
  1756. case S_HOLD:
  1757. api_parse(&parms->info[1],(word)parms->length,"ws",ss_parms);
  1758. if(plci && plci->State && plci->SuppState==IDLE)
  1759. {
  1760. plci->SuppState = HOLD_REQUEST;
  1761. plci->command = C_HOLD_REQ;
  1762. add_s(plci,CAI,&ss_parms[1]);
  1763. sig_req(plci,CALL_HOLD,0);
  1764. send_req(plci);
  1765. return false;
  1766. }
  1767. else Info = 0x3010; /* wrong state */
  1768. break;
  1769. case S_RETRIEVE:
  1770. if(plci && plci->State && plci->SuppState==CALL_HELD)
  1771. {
  1772. if(Id & EXT_CONTROLLER)
  1773. {
  1774. if(AdvCodecSupport(a, plci, appl, 0))
  1775. {
  1776. Info = 0x3010; /* wrong state */
  1777. break;
  1778. }
  1779. }
  1780. else plci->tel = 0;
  1781. plci->SuppState = RETRIEVE_REQUEST;
  1782. plci->command = C_RETRIEVE_REQ;
  1783. if(plci->spoofed_msg==SPOOFING_REQUIRED)
  1784. {
  1785. plci->spoofed_msg = CALL_RETRIEVE;
  1786. plci->internal_command = BLOCK_PLCI;
  1787. plci->command = 0;
  1788. dbug(1,dprintf("Spoof"));
  1789. return false;
  1790. }
  1791. else
  1792. {
  1793. sig_req(plci,CALL_RETRIEVE,0);
  1794. send_req(plci);
  1795. return false;
  1796. }
  1797. }
  1798. else Info = 0x3010; /* wrong state */
  1799. break;
  1800. case S_SUSPEND:
  1801. if(parms->length)
  1802. {
  1803. if(api_parse(&parms->info[1],(word)parms->length,"wbs",ss_parms))
  1804. {
  1805. dbug(1,dprintf("format wrong"));
  1806. Info = _WRONG_MESSAGE_FORMAT;
  1807. break;
  1808. }
  1809. }
  1810. if(plci && plci->State)
  1811. {
  1812. add_s(plci,CAI,&ss_parms[2]);
  1813. plci->command = SUSPEND_REQ;
  1814. sig_req(plci,SUSPEND,0);
  1815. plci->State = SUSPENDING;
  1816. send_req(plci);
  1817. }
  1818. else Info = 0x3010; /* wrong state */
  1819. break;
  1820. case S_RESUME:
  1821. if(!(i=get_plci(a)) )
  1822. {
  1823. Info = _OUT_OF_PLCI;
  1824. break;
  1825. }
  1826. rplci = &a->plci[i-1];
  1827. rplci->appl = appl;
  1828. rplci->number = Number;
  1829. rplci->tel = 0;
  1830. rplci->call_dir = CALL_DIR_OUT | CALL_DIR_ORIGINATE;
  1831. /* check 'external controller' bit for codec support */
  1832. if(Id & EXT_CONTROLLER)
  1833. {
  1834. if(AdvCodecSupport(a, rplci, appl, 0) )
  1835. {
  1836. rplci->Id = 0;
  1837. Info = 0x300A;
  1838. break;
  1839. }
  1840. }
  1841. if(parms->length)
  1842. {
  1843. if(api_parse(&parms->info[1],(word)parms->length,"wbs",ss_parms))
  1844. {
  1845. dbug(1,dprintf("format wrong"));
  1846. rplci->Id = 0;
  1847. Info = _WRONG_MESSAGE_FORMAT;
  1848. break;
  1849. }
  1850. }
  1851. dummy.length = 0;
  1852. dummy.info = "\x00";
  1853. add_b1(rplci, &dummy, 0, 0);
  1854. if (a->Info_Mask[appl->Id-1] & 0x200)
  1855. {
  1856. /* early B3 connect (CIP mask bit 9) no release after a disc */
  1857. add_p(rplci,LLI,"\x01\x01");
  1858. }
  1859. add_p(rplci,UID,"\x06\x43\x61\x70\x69\x32\x30");
  1860. sig_req(rplci,ASSIGN,DSIG_ID);
  1861. send_req(rplci);
  1862. add_s(rplci,CAI,&ss_parms[2]);
  1863. rplci->command = RESUME_REQ;
  1864. sig_req(rplci,RESUME,0);
  1865. rplci->State = RESUMING;
  1866. send_req(rplci);
  1867. break;
  1868. case S_CONF_BEGIN: /* Request */
  1869. case S_CONF_DROP:
  1870. case S_CONF_ISOLATE:
  1871. case S_CONF_REATTACH:
  1872. if(api_parse(&parms->info[1],(word)parms->length,"wbd",ss_parms))
  1873. {
  1874. dbug(1,dprintf("format wrong"));
  1875. Info = _WRONG_MESSAGE_FORMAT;
  1876. break;
  1877. }
  1878. if(plci && plci->State && ((plci->SuppState==IDLE)||(plci->SuppState==CALL_HELD)))
  1879. {
  1880. d = GET_DWORD(ss_parms[2].info);
  1881. if(d>=0x80)
  1882. {
  1883. dbug(1,dprintf("format wrong"));
  1884. Info = _WRONG_MESSAGE_FORMAT;
  1885. break;
  1886. }
  1887. plci->ptyState = (byte)SSreq;
  1888. plci->command = 0;
  1889. cai[0] = 2;
  1890. switch(SSreq)
  1891. {
  1892. case S_CONF_BEGIN:
  1893. cai[1] = CONF_BEGIN;
  1894. plci->internal_command = CONF_BEGIN_REQ_PEND;
  1895. break;
  1896. case S_CONF_DROP:
  1897. cai[1] = CONF_DROP;
  1898. plci->internal_command = CONF_DROP_REQ_PEND;
  1899. break;
  1900. case S_CONF_ISOLATE:
  1901. cai[1] = CONF_ISOLATE;
  1902. plci->internal_command = CONF_ISOLATE_REQ_PEND;
  1903. break;
  1904. case S_CONF_REATTACH:
  1905. cai[1] = CONF_REATTACH;
  1906. plci->internal_command = CONF_REATTACH_REQ_PEND;
  1907. break;
  1908. }
  1909. cai[2] = (byte)d; /* Conference Size resp. PartyId */
  1910. add_p(plci,CAI,cai);
  1911. sig_req(plci,S_SERVICE,0);
  1912. send_req(plci);
  1913. return false;
  1914. }
  1915. else Info = 0x3010; /* wrong state */
  1916. break;
  1917. case S_ECT:
  1918. case S_3PTY_BEGIN:
  1919. case S_3PTY_END:
  1920. case S_CONF_ADD:
  1921. if(parms->length==7)
  1922. {
  1923. if(api_parse(&parms->info[1],(word)parms->length,"wbd",ss_parms))
  1924. {
  1925. dbug(1,dprintf("format wrong"));
  1926. Info = _WRONG_MESSAGE_FORMAT;
  1927. break;
  1928. }
  1929. }
  1930. else if(parms->length==8) /* workaround for the T-View-S */
  1931. {
  1932. if(api_parse(&parms->info[1],(word)parms->length,"wbdb",ss_parms))
  1933. {
  1934. dbug(1,dprintf("format wrong"));
  1935. Info = _WRONG_MESSAGE_FORMAT;
  1936. break;
  1937. }
  1938. }
  1939. else
  1940. {
  1941. Info = _WRONG_MESSAGE_FORMAT;
  1942. break;
  1943. }
  1944. if(!msg[1].length)
  1945. {
  1946. Info = _WRONG_MESSAGE_FORMAT;
  1947. break;
  1948. }
  1949. if (!plci)
  1950. {
  1951. Info = _WRONG_IDENTIFIER;
  1952. break;
  1953. }
  1954. relatedPLCIvalue = GET_DWORD(ss_parms[2].info);
  1955. relatedPLCIvalue &= 0x0000FFFF;
  1956. dbug(1,dprintf("PTY/ECT/addCONF,relPLCI=%lx",relatedPLCIvalue));
  1957. /* controller starts with 0 up to (max_adapter - 1) */
  1958. if (((relatedPLCIvalue & 0x7f) == 0)
  1959. || (MapController ((byte)(relatedPLCIvalue & 0x7f)) == 0)
  1960. || (MapController ((byte)(relatedPLCIvalue & 0x7f)) > max_adapter))
  1961. {
  1962. if(SSreq==S_3PTY_END)
  1963. {
  1964. dbug(1, dprintf("wrong Controller use 2nd PLCI=PLCI"));
  1965. rplci = plci;
  1966. }
  1967. else
  1968. {
  1969. Info = 0x3010; /* wrong state */
  1970. break;
  1971. }
  1972. }
  1973. else
  1974. {
  1975. relatedadapter = &adapter[MapController ((byte)(relatedPLCIvalue & 0x7f))-1];
  1976. relatedPLCIvalue >>=8;
  1977. /* find PLCI PTR*/
  1978. for(i=0,rplci=NULL;i<relatedadapter->max_plci;i++)
  1979. {
  1980. if(relatedadapter->plci[i].Id == (byte)relatedPLCIvalue)
  1981. {
  1982. rplci = &relatedadapter->plci[i];
  1983. }
  1984. }
  1985. if(!rplci || !relatedPLCIvalue)
  1986. {
  1987. if(SSreq==S_3PTY_END)
  1988. {
  1989. dbug(1, dprintf("use 2nd PLCI=PLCI"));
  1990. rplci = plci;
  1991. }
  1992. else
  1993. {
  1994. Info = 0x3010; /* wrong state */
  1995. break;
  1996. }
  1997. }
  1998. }
  1999. /*
  2000. dbug(1,dprintf("rplci:%x",rplci));
  2001. dbug(1,dprintf("plci:%x",plci));
  2002. dbug(1,dprintf("rplci->ptyState:%x",rplci->ptyState));
  2003. dbug(1,dprintf("plci->ptyState:%x",plci->ptyState));
  2004. dbug(1,dprintf("SSreq:%x",SSreq));
  2005. dbug(1,dprintf("rplci->internal_command:%x",rplci->internal_command));
  2006. dbug(1,dprintf("rplci->appl:%x",rplci->appl));
  2007. dbug(1,dprintf("rplci->Id:%x",rplci->Id));
  2008. */
  2009. /* send PTY/ECT req, cannot check all states because of US stuff */
  2010. if( !rplci->internal_command && rplci->appl )
  2011. {
  2012. plci->command = 0;
  2013. rplci->relatedPTYPLCI = plci;
  2014. plci->relatedPTYPLCI = rplci;
  2015. rplci->ptyState = (byte)SSreq;
  2016. if(SSreq==S_ECT)
  2017. {
  2018. rplci->internal_command = ECT_REQ_PEND;
  2019. cai[1] = ECT_EXECUTE;
  2020. rplci->vswitchstate=0;
  2021. rplci->vsprot=0;
  2022. rplci->vsprotdialect=0;
  2023. plci->vswitchstate=0;
  2024. plci->vsprot=0;
  2025. plci->vsprotdialect=0;
  2026. }
  2027. else if(SSreq==S_CONF_ADD)
  2028. {
  2029. rplci->internal_command = CONF_ADD_REQ_PEND;
  2030. cai[1] = CONF_ADD;
  2031. }
  2032. else
  2033. {
  2034. rplci->internal_command = PTY_REQ_PEND;
  2035. cai[1] = (byte)(SSreq-3);
  2036. }
  2037. rplci->number = Number;
  2038. if(plci!=rplci) /* explicit invocation */
  2039. {
  2040. cai[0] = 2;
  2041. cai[2] = plci->Sig.Id;
  2042. dbug(1,dprintf("explicit invocation"));
  2043. }
  2044. else
  2045. {
  2046. dbug(1,dprintf("implicit invocation"));
  2047. cai[0] = 1;
  2048. }
  2049. add_p(rplci,CAI,cai);
  2050. sig_req(rplci,S_SERVICE,0);
  2051. send_req(rplci);
  2052. return false;
  2053. }
  2054. else
  2055. {
  2056. dbug(0,dprintf("Wrong line"));
  2057. Info = 0x3010; /* wrong state */
  2058. break;
  2059. }
  2060. break;
  2061. case S_CALL_DEFLECTION:
  2062. if(api_parse(&parms->info[1],(word)parms->length,"wbwss",ss_parms))
  2063. {
  2064. dbug(1,dprintf("format wrong"));
  2065. Info = _WRONG_MESSAGE_FORMAT;
  2066. break;
  2067. }
  2068. if (!plci)
  2069. {
  2070. Info = _WRONG_IDENTIFIER;
  2071. break;
  2072. }
  2073. /* reuse unused screening indicator */
  2074. ss_parms[3].info[3] = (byte)GET_WORD(&(ss_parms[2].info[0]));
  2075. plci->command = 0;
  2076. plci->internal_command = CD_REQ_PEND;
  2077. appl->CDEnable = true;
  2078. cai[0] = 1;
  2079. cai[1] = CALL_DEFLECTION;
  2080. add_p(plci,CAI,cai);
  2081. add_p(plci,CPN,ss_parms[3].info);
  2082. sig_req(plci,S_SERVICE,0);
  2083. send_req(plci);
  2084. return false;
  2085. break;
  2086. case S_CALL_FORWARDING_START:
  2087. if(api_parse(&parms->info[1],(word)parms->length,"wbdwwsss",ss_parms))
  2088. {
  2089. dbug(1,dprintf("format wrong"));
  2090. Info = _WRONG_MESSAGE_FORMAT;
  2091. break;
  2092. }
  2093. if((i=get_plci(a)))
  2094. {
  2095. rplci = &a->plci[i-1];
  2096. rplci->appl = appl;
  2097. add_p(rplci,CAI,"\x01\x80");
  2098. add_p(rplci,UID,"\x06\x43\x61\x70\x69\x32\x30");
  2099. sig_req(rplci,ASSIGN,DSIG_ID);
  2100. send_req(rplci);
  2101. }
  2102. else
  2103. {
  2104. Info = _OUT_OF_PLCI;
  2105. break;
  2106. }
  2107. /* reuse unused screening indicator */
  2108. rplci->internal_command = CF_START_PEND;
  2109. rplci->appl = appl;
  2110. rplci->number = Number;
  2111. appl->S_Handle = GET_DWORD(&(ss_parms[2].info[0]));
  2112. cai[0] = 2;
  2113. cai[1] = 0x70|(byte)GET_WORD(&(ss_parms[3].info[0])); /* Function */
  2114. cai[2] = (byte)GET_WORD(&(ss_parms[4].info[0])); /* Basic Service */
  2115. add_p(rplci,CAI,cai);
  2116. add_p(rplci,OAD,ss_parms[5].info);
  2117. add_p(rplci,CPN,ss_parms[6].info);
  2118. sig_req(rplci,S_SERVICE,0);
  2119. send_req(rplci);
  2120. return false;
  2121. break;
  2122. case S_INTERROGATE_DIVERSION:
  2123. case S_INTERROGATE_NUMBERS:
  2124. case S_CALL_FORWARDING_STOP:
  2125. case S_CCBS_REQUEST:
  2126. case S_CCBS_DEACTIVATE:
  2127. case S_CCBS_INTERROGATE:
  2128. switch(SSreq)
  2129. {
  2130. case S_INTERROGATE_NUMBERS:
  2131. if(api_parse(&parms->info[1],(word)parms->length,"wbd",ss_parms))
  2132. {
  2133. dbug(0,dprintf("format wrong"));
  2134. Info = _WRONG_MESSAGE_FORMAT;
  2135. }
  2136. break;
  2137. case S_CCBS_REQUEST:
  2138. case S_CCBS_DEACTIVATE:
  2139. if(api_parse(&parms->info[1],(word)parms->length,"wbdw",ss_parms))
  2140. {
  2141. dbug(0,dprintf("format wrong"));
  2142. Info = _WRONG_MESSAGE_FORMAT;
  2143. }
  2144. break;
  2145. case S_CCBS_INTERROGATE:
  2146. if(api_parse(&parms->info[1],(word)parms->length,"wbdws",ss_parms))
  2147. {
  2148. dbug(0,dprintf("format wrong"));
  2149. Info = _WRONG_MESSAGE_FORMAT;
  2150. }
  2151. break;
  2152. default:
  2153. if(api_parse(&parms->info[1],(word)parms->length,"wbdwws",ss_parms))
  2154. {
  2155. dbug(0,dprintf("format wrong"));
  2156. Info = _WRONG_MESSAGE_FORMAT;
  2157. break;
  2158. }
  2159. break;
  2160. }
  2161. if(Info) break;
  2162. if((i=get_plci(a)))
  2163. {
  2164. rplci = &a->plci[i-1];
  2165. switch(SSreq)
  2166. {
  2167. case S_INTERROGATE_DIVERSION: /* use cai with S_SERVICE below */
  2168. cai[1] = 0x60|(byte)GET_WORD(&(ss_parms[3].info[0])); /* Function */
  2169. rplci->internal_command = INTERR_DIVERSION_REQ_PEND; /* move to rplci if assigned */
  2170. break;
  2171. case S_INTERROGATE_NUMBERS: /* use cai with S_SERVICE below */
  2172. cai[1] = DIVERSION_INTERROGATE_NUM; /* Function */
  2173. rplci->internal_command = INTERR_NUMBERS_REQ_PEND; /* move to rplci if assigned */
  2174. break;
  2175. case S_CALL_FORWARDING_STOP:
  2176. rplci->internal_command = CF_STOP_PEND;
  2177. cai[1] = 0x80|(byte)GET_WORD(&(ss_parms[3].info[0])); /* Function */
  2178. break;
  2179. case S_CCBS_REQUEST:
  2180. cai[1] = CCBS_REQUEST;
  2181. rplci->internal_command = CCBS_REQUEST_REQ_PEND;
  2182. break;
  2183. case S_CCBS_DEACTIVATE:
  2184. cai[1] = CCBS_DEACTIVATE;
  2185. rplci->internal_command = CCBS_DEACTIVATE_REQ_PEND;
  2186. break;
  2187. case S_CCBS_INTERROGATE:
  2188. cai[1] = CCBS_INTERROGATE;
  2189. rplci->internal_command = CCBS_INTERROGATE_REQ_PEND;
  2190. break;
  2191. default:
  2192. cai[1] = 0;
  2193. break;
  2194. }
  2195. rplci->appl = appl;
  2196. rplci->number = Number;
  2197. add_p(rplci,CAI,"\x01\x80");
  2198. add_p(rplci,UID,"\x06\x43\x61\x70\x69\x32\x30");
  2199. sig_req(rplci,ASSIGN,DSIG_ID);
  2200. send_req(rplci);
  2201. }
  2202. else
  2203. {
  2204. Info = _OUT_OF_PLCI;
  2205. break;
  2206. }
  2207. appl->S_Handle = GET_DWORD(&(ss_parms[2].info[0]));
  2208. switch(SSreq)
  2209. {
  2210. case S_INTERROGATE_NUMBERS:
  2211. cai[0] = 1;
  2212. add_p(rplci,CAI,cai);
  2213. break;
  2214. case S_CCBS_REQUEST:
  2215. case S_CCBS_DEACTIVATE:
  2216. cai[0] = 3;
  2217. PUT_WORD(&cai[2],GET_WORD(&(ss_parms[3].info[0])));
  2218. add_p(rplci,CAI,cai);
  2219. break;
  2220. case S_CCBS_INTERROGATE:
  2221. cai[0] = 3;
  2222. PUT_WORD(&cai[2],GET_WORD(&(ss_parms[3].info[0])));
  2223. add_p(rplci,CAI,cai);
  2224. add_p(rplci,OAD,ss_parms[4].info);
  2225. break;
  2226. default:
  2227. cai[0] = 2;
  2228. cai[2] = (byte)GET_WORD(&(ss_parms[4].info[0])); /* Basic Service */
  2229. add_p(rplci,CAI,cai);
  2230. add_p(rplci,OAD,ss_parms[5].info);
  2231. break;
  2232. }
  2233. sig_req(rplci,S_SERVICE,0);
  2234. send_req(rplci);
  2235. return false;
  2236. break;
  2237. case S_MWI_ACTIVATE:
  2238. if(api_parse(&parms->info[1],(word)parms->length,"wbwdwwwssss",ss_parms))
  2239. {
  2240. dbug(1,dprintf("format wrong"));
  2241. Info = _WRONG_MESSAGE_FORMAT;
  2242. break;
  2243. }
  2244. if(!plci)
  2245. {
  2246. if((i=get_plci(a)))
  2247. {
  2248. rplci = &a->plci[i-1];
  2249. rplci->appl = appl;
  2250. rplci->cr_enquiry=true;
  2251. add_p(rplci,CAI,"\x01\x80");
  2252. add_p(rplci,UID,"\x06\x43\x61\x70\x69\x32\x30");
  2253. sig_req(rplci,ASSIGN,DSIG_ID);
  2254. send_req(rplci);
  2255. }
  2256. else
  2257. {
  2258. Info = _OUT_OF_PLCI;
  2259. break;
  2260. }
  2261. }
  2262. else
  2263. {
  2264. rplci = plci;
  2265. rplci->cr_enquiry=false;
  2266. }
  2267. rplci->command = 0;
  2268. rplci->internal_command = MWI_ACTIVATE_REQ_PEND;
  2269. rplci->appl = appl;
  2270. rplci->number = Number;
  2271. cai[0] = 13;
  2272. cai[1] = ACTIVATION_MWI; /* Function */
  2273. PUT_WORD(&cai[2],GET_WORD(&(ss_parms[2].info[0]))); /* Basic Service */
  2274. PUT_DWORD(&cai[4],GET_DWORD(&(ss_parms[3].info[0]))); /* Number of Messages */
  2275. PUT_WORD(&cai[8],GET_WORD(&(ss_parms[4].info[0]))); /* Message Status */
  2276. PUT_WORD(&cai[10],GET_WORD(&(ss_parms[5].info[0]))); /* Message Reference */
  2277. PUT_WORD(&cai[12],GET_WORD(&(ss_parms[6].info[0]))); /* Invocation Mode */
  2278. add_p(rplci,CAI,cai);
  2279. add_p(rplci,CPN,ss_parms[7].info); /* Receiving User Number */
  2280. add_p(rplci,OAD,ss_parms[8].info); /* Controlling User Number */
  2281. add_p(rplci,OSA,ss_parms[9].info); /* Controlling User Provided Number */
  2282. add_p(rplci,UID,ss_parms[10].info); /* Time */
  2283. sig_req(rplci,S_SERVICE,0);
  2284. send_req(rplci);
  2285. return false;
  2286. case S_MWI_DEACTIVATE:
  2287. if(api_parse(&parms->info[1],(word)parms->length,"wbwwss",ss_parms))
  2288. {
  2289. dbug(1,dprintf("format wrong"));
  2290. Info = _WRONG_MESSAGE_FORMAT;
  2291. break;
  2292. }
  2293. if(!plci)
  2294. {
  2295. if((i=get_plci(a)))
  2296. {
  2297. rplci = &a->plci[i-1];
  2298. rplci->appl = appl;
  2299. rplci->cr_enquiry=true;
  2300. add_p(rplci,CAI,"\x01\x80");
  2301. add_p(rplci,UID,"\x06\x43\x61\x70\x69\x32\x30");
  2302. sig_req(rplci,ASSIGN,DSIG_ID);
  2303. send_req(rplci);
  2304. }
  2305. else
  2306. {
  2307. Info = _OUT_OF_PLCI;
  2308. break;
  2309. }
  2310. }
  2311. else
  2312. {
  2313. rplci = plci;
  2314. rplci->cr_enquiry=false;
  2315. }
  2316. rplci->command = 0;
  2317. rplci->internal_command = MWI_DEACTIVATE_REQ_PEND;
  2318. rplci->appl = appl;
  2319. rplci->number = Number;
  2320. cai[0] = 5;
  2321. cai[1] = DEACTIVATION_MWI; /* Function */
  2322. PUT_WORD(&cai[2],GET_WORD(&(ss_parms[2].info[0]))); /* Basic Service */
  2323. PUT_WORD(&cai[4],GET_WORD(&(ss_parms[3].info[0]))); /* Invocation Mode */
  2324. add_p(rplci,CAI,cai);
  2325. add_p(rplci,CPN,ss_parms[4].info); /* Receiving User Number */
  2326. add_p(rplci,OAD,ss_parms[5].info); /* Controlling User Number */
  2327. sig_req(rplci,S_SERVICE,0);
  2328. send_req(rplci);
  2329. return false;
  2330. default:
  2331. Info = 0x300E; /* not supported */
  2332. break;
  2333. }
  2334. break; /* case SELECTOR_SU_SERV: end */
  2335. case SELECTOR_DTMF:
  2336. return (dtmf_request (Id, Number, a, plci, appl, msg));
  2337. case SELECTOR_LINE_INTERCONNECT:
  2338. return (mixer_request (Id, Number, a, plci, appl, msg));
  2339. case PRIV_SELECTOR_ECHO_CANCELLER:
  2340. appl->appl_flags |= APPL_FLAG_PRIV_EC_SPEC;
  2341. return (ec_request (Id, Number, a, plci, appl, msg));
  2342. case SELECTOR_ECHO_CANCELLER:
  2343. appl->appl_flags &= ~APPL_FLAG_PRIV_EC_SPEC;
  2344. return (ec_request (Id, Number, a, plci, appl, msg));
  2345. case SELECTOR_V42BIS:
  2346. default:
  2347. Info = _FACILITY_NOT_SUPPORTED;
  2348. break;
  2349. } /* end of switch(selector) */
  2350. }
  2351. dbug(1,dprintf("SendFacRc"));
  2352. sendf(appl,
  2353. _FACILITY_R|CONFIRM,
  2354. Id,
  2355. Number,
  2356. "wws",Info,selector,SSparms);
  2357. return false;
  2358. }
  2359. static byte facility_res(dword Id, word Number, DIVA_CAPI_ADAPTER *a,
  2360. PLCI *plci, APPL *appl, API_PARSE *msg)
  2361. {
  2362. dbug(1,dprintf("facility_res"));
  2363. return false;
  2364. }
  2365. static byte connect_b3_req(dword Id, word Number, DIVA_CAPI_ADAPTER *a,
  2366. PLCI *plci, APPL *appl, API_PARSE *parms)
  2367. {
  2368. word Info = 0;
  2369. byte req;
  2370. byte len;
  2371. word w;
  2372. word fax_control_bits, fax_feature_bits, fax_info_change;
  2373. API_PARSE * ncpi;
  2374. byte pvc[2];
  2375. API_PARSE fax_parms[9];
  2376. word i;
  2377. dbug(1,dprintf("connect_b3_req"));
  2378. if(plci)
  2379. {
  2380. if ((plci->State == IDLE) || (plci->State == OUTG_DIS_PENDING)
  2381. || (plci->State == INC_DIS_PENDING) || (plci->SuppState != IDLE))
  2382. {
  2383. Info = _WRONG_STATE;
  2384. }
  2385. else
  2386. {
  2387. /* local reply if assign unsuccessfull
  2388. or B3 protocol allows only one layer 3 connection
  2389. and already connected
  2390. or B2 protocol not any LAPD
  2391. and connect_b3_req contradicts originate/answer direction */
  2392. if (!plci->NL.Id
  2393. || (((plci->B3_prot != B3_T90NL) && (plci->B3_prot != B3_ISO8208) && (plci->B3_prot != B3_X25_DCE))
  2394. && ((plci->channels != 0)
  2395. || (((plci->B2_prot != B2_SDLC) && (plci->B2_prot != B2_LAPD) && (plci->B2_prot != B2_LAPD_FREE_SAPI_SEL))
  2396. && ((plci->call_dir & CALL_DIR_ANSWER) && !(plci->call_dir & CALL_DIR_FORCE_OUTG_NL))))))
  2397. {
  2398. dbug(1,dprintf("B3 already connected=%d or no NL.Id=0x%x, dir=%d sstate=0x%x",
  2399. plci->channels,plci->NL.Id,plci->call_dir,plci->SuppState));
  2400. Info = _WRONG_STATE;
  2401. sendf(appl,
  2402. _CONNECT_B3_R|CONFIRM,
  2403. Id,
  2404. Number,
  2405. "w",Info);
  2406. return false;
  2407. }
  2408. plci->requested_options_conn = 0;
  2409. req = N_CONNECT;
  2410. ncpi = &parms[0];
  2411. if(plci->B3_prot==2 || plci->B3_prot==3)
  2412. {
  2413. if(ncpi->length>2)
  2414. {
  2415. /* check for PVC */
  2416. if(ncpi->info[2] || ncpi->info[3])
  2417. {
  2418. pvc[0] = ncpi->info[3];
  2419. pvc[1] = ncpi->info[2];
  2420. add_d(plci,2,pvc);
  2421. req = N_RESET;
  2422. }
  2423. else
  2424. {
  2425. if(ncpi->info[1] &1) req = N_CONNECT | N_D_BIT;
  2426. add_d(plci,(word)(ncpi->length-3),&ncpi->info[4]);
  2427. }
  2428. }
  2429. }
  2430. else if(plci->B3_prot==5)
  2431. {
  2432. if (plci->NL.Id && !plci->nl_remove_id)
  2433. {
  2434. fax_control_bits = GET_WORD(&((T30_INFO *)plci->fax_connect_info_buffer)->control_bits_low);
  2435. fax_feature_bits = GET_WORD(&((T30_INFO *)plci->fax_connect_info_buffer)->feature_bits_low);
  2436. if (!(fax_control_bits & T30_CONTROL_BIT_MORE_DOCUMENTS)
  2437. || (fax_feature_bits & T30_FEATURE_BIT_MORE_DOCUMENTS))
  2438. {
  2439. len = (byte)(&(((T30_INFO *) 0)->universal_6));
  2440. fax_info_change = false;
  2441. if (ncpi->length >= 4)
  2442. {
  2443. w = GET_WORD(&ncpi->info[3]);
  2444. if ((w & 0x0001) != ((word)(((T30_INFO *)(plci->fax_connect_info_buffer))->resolution & 0x0001)))
  2445. {
  2446. ((T30_INFO *)(plci->fax_connect_info_buffer))->resolution =
  2447. (byte)((((T30_INFO *)(plci->fax_connect_info_buffer))->resolution & ~T30_RESOLUTION_R8_0770_OR_200) |
  2448. ((w & 0x0001) ? T30_RESOLUTION_R8_0770_OR_200 : 0));
  2449. fax_info_change = true;
  2450. }
  2451. fax_control_bits &= ~(T30_CONTROL_BIT_REQUEST_POLLING | T30_CONTROL_BIT_MORE_DOCUMENTS);
  2452. if (w & 0x0002) /* Fax-polling request */
  2453. fax_control_bits |= T30_CONTROL_BIT_REQUEST_POLLING;
  2454. if ((w & 0x0004) /* Request to send / poll another document */
  2455. && (a->manufacturer_features & MANUFACTURER_FEATURE_FAX_MORE_DOCUMENTS))
  2456. {
  2457. fax_control_bits |= T30_CONTROL_BIT_MORE_DOCUMENTS;
  2458. }
  2459. if (ncpi->length >= 6)
  2460. {
  2461. w = GET_WORD(&ncpi->info[5]);
  2462. if (((byte) w) != ((T30_INFO *)(plci->fax_connect_info_buffer))->data_format)
  2463. {
  2464. ((T30_INFO *)(plci->fax_connect_info_buffer))->data_format = (byte) w;
  2465. fax_info_change = true;
  2466. }
  2467. if ((a->man_profile.private_options & (1L << PRIVATE_FAX_SUB_SEP_PWD))
  2468. && (GET_WORD(&ncpi->info[5]) & 0x8000)) /* Private SEP/SUB/PWD enable */
  2469. {
  2470. plci->requested_options_conn |= (1L << PRIVATE_FAX_SUB_SEP_PWD);
  2471. }
  2472. if ((a->man_profile.private_options & (1L << PRIVATE_FAX_NONSTANDARD))
  2473. && (GET_WORD(&ncpi->info[5]) & 0x4000)) /* Private non-standard facilities enable */
  2474. {
  2475. plci->requested_options_conn |= (1L << PRIVATE_FAX_NONSTANDARD);
  2476. }
  2477. fax_control_bits &= ~(T30_CONTROL_BIT_ACCEPT_SUBADDRESS | T30_CONTROL_BIT_ACCEPT_SEL_POLLING |
  2478. T30_CONTROL_BIT_ACCEPT_PASSWORD);
  2479. if ((plci->requested_options_conn | plci->requested_options | a->requested_options_table[appl->Id-1])
  2480. & ((1L << PRIVATE_FAX_SUB_SEP_PWD) | (1L << PRIVATE_FAX_NONSTANDARD)))
  2481. {
  2482. if (api_parse (&ncpi->info[1], ncpi->length, "wwwwsss", fax_parms))
  2483. Info = _WRONG_MESSAGE_FORMAT;
  2484. else
  2485. {
  2486. if ((plci->requested_options_conn | plci->requested_options | a->requested_options_table[appl->Id-1])
  2487. & (1L << PRIVATE_FAX_SUB_SEP_PWD))
  2488. {
  2489. fax_control_bits |= T30_CONTROL_BIT_ACCEPT_SUBADDRESS | T30_CONTROL_BIT_ACCEPT_PASSWORD;
  2490. if (fax_control_bits & T30_CONTROL_BIT_ACCEPT_POLLING)
  2491. fax_control_bits |= T30_CONTROL_BIT_ACCEPT_SEL_POLLING;
  2492. }
  2493. w = fax_parms[4].length;
  2494. if (w > 20)
  2495. w = 20;
  2496. ((T30_INFO *)(plci->fax_connect_info_buffer))->station_id_len = (byte) w;
  2497. for (i = 0; i < w; i++)
  2498. ((T30_INFO *)(plci->fax_connect_info_buffer))->station_id[i] = fax_parms[4].info[1+i];
  2499. ((T30_INFO *)(plci->fax_connect_info_buffer))->head_line_len = 0;
  2500. len = (byte)(((T30_INFO *) 0)->station_id + 20);
  2501. w = fax_parms[5].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[5].info[1+i];
  2507. w = fax_parms[6].length;
  2508. if (w > 20)
  2509. w = 20;
  2510. plci->fax_connect_info_buffer[len++] = (byte) w;
  2511. for (i = 0; i < w; i++)
  2512. plci->fax_connect_info_buffer[len++] = fax_parms[6].info[1+i];
  2513. if ((plci->requested_options_conn | plci->requested_options | a->requested_options_table[appl->Id-1])
  2514. & (1L << PRIVATE_FAX_NONSTANDARD))
  2515. {
  2516. if (api_parse (&ncpi->info[1], ncpi->length, "wwwwssss", fax_parms))
  2517. {
  2518. dbug(1,dprintf("non-standard facilities info missing or wrong format"));
  2519. plci->fax_connect_info_buffer[len++] = 0;
  2520. }
  2521. else
  2522. {
  2523. if ((fax_parms[7].length >= 3) && (fax_parms[7].info[1] >= 2))
  2524. plci->nsf_control_bits = GET_WORD(&fax_parms[7].info[2]);
  2525. plci->fax_connect_info_buffer[len++] = (byte)(fax_parms[7].length);
  2526. for (i = 0; i < fax_parms[7].length; i++)
  2527. plci->fax_connect_info_buffer[len++] = fax_parms[7].info[1+i];
  2528. }
  2529. }
  2530. }
  2531. }
  2532. else
  2533. {
  2534. len = (byte)(&(((T30_INFO *) 0)->universal_6));
  2535. }
  2536. fax_info_change = true;
  2537. }
  2538. if (fax_control_bits != GET_WORD(&((T30_INFO *)plci->fax_connect_info_buffer)->control_bits_low))
  2539. {
  2540. PUT_WORD (&((T30_INFO *)plci->fax_connect_info_buffer)->control_bits_low, fax_control_bits);
  2541. fax_info_change = true;
  2542. }
  2543. }
  2544. if (Info == GOOD)
  2545. {
  2546. plci->fax_connect_info_length = len;
  2547. if (fax_info_change)
  2548. {
  2549. if (fax_feature_bits & T30_FEATURE_BIT_MORE_DOCUMENTS)
  2550. {
  2551. start_internal_command (Id, plci, fax_connect_info_command);
  2552. return false;
  2553. }
  2554. else
  2555. {
  2556. start_internal_command (Id, plci, fax_adjust_b23_command);
  2557. return false;
  2558. }
  2559. }
  2560. }
  2561. }
  2562. else Info = _WRONG_STATE;
  2563. }
  2564. else Info = _WRONG_STATE;
  2565. }
  2566. else if (plci->B3_prot == B3_RTP)
  2567. {
  2568. plci->internal_req_buffer[0] = ncpi->length + 1;
  2569. plci->internal_req_buffer[1] = UDATA_REQUEST_RTP_RECONFIGURE;
  2570. for (w = 0; w < ncpi->length; w++)
  2571. plci->internal_req_buffer[2+w] = ncpi->info[1+w];
  2572. start_internal_command (Id, plci, rtp_connect_b3_req_command);
  2573. return false;
  2574. }
  2575. if(!Info)
  2576. {
  2577. nl_req_ncci(plci,req,0);
  2578. return 1;
  2579. }
  2580. }
  2581. }
  2582. else Info = _WRONG_IDENTIFIER;
  2583. sendf(appl,
  2584. _CONNECT_B3_R|CONFIRM,
  2585. Id,
  2586. Number,
  2587. "w",Info);
  2588. return false;
  2589. }
  2590. static byte connect_b3_res(dword Id, word Number, DIVA_CAPI_ADAPTER *a,
  2591. PLCI *plci, APPL *appl, API_PARSE *parms)
  2592. {
  2593. word ncci;
  2594. API_PARSE * ncpi;
  2595. byte req;
  2596. word w;
  2597. API_PARSE fax_parms[9];
  2598. word i;
  2599. byte len;
  2600. dbug(1,dprintf("connect_b3_res"));
  2601. ncci = (word)(Id>>16);
  2602. if(plci && ncci) {
  2603. if(a->ncci_state[ncci]==INC_CON_PENDING) {
  2604. if (GET_WORD (&parms[0].info[0]) != 0)
  2605. {
  2606. a->ncci_state[ncci] = OUTG_REJ_PENDING;
  2607. channel_request_xon (plci, a->ncci_ch[ncci]);
  2608. channel_xmit_xon (plci);
  2609. cleanup_ncci_data (plci, ncci);
  2610. nl_req_ncci(plci,N_DISC,(byte)ncci);
  2611. return 1;
  2612. }
  2613. a->ncci_state[ncci] = INC_ACT_PENDING;
  2614. req = N_CONNECT_ACK;
  2615. ncpi = &parms[1];
  2616. if ((plci->B3_prot == 4) || (plci->B3_prot == 5) || (plci->B3_prot == 7))
  2617. {
  2618. if ((plci->requested_options_conn | plci->requested_options | a->requested_options_table[plci->appl->Id-1])
  2619. & (1L << PRIVATE_FAX_NONSTANDARD))
  2620. {
  2621. if (((plci->B3_prot == 4) || (plci->B3_prot == 5))
  2622. && (plci->nsf_control_bits & T30_NSF_CONTROL_BIT_ENABLE_NSF)
  2623. && (plci->nsf_control_bits & T30_NSF_CONTROL_BIT_NEGOTIATE_RESP))
  2624. {
  2625. len = ((byte)(((T30_INFO *) 0)->station_id + 20));
  2626. if (plci->fax_connect_info_length < len)
  2627. {
  2628. ((T30_INFO *)(plci->fax_connect_info_buffer))->station_id_len = 0;
  2629. ((T30_INFO *)(plci->fax_connect_info_buffer))->head_line_len = 0;
  2630. }
  2631. if (api_parse (&ncpi->info[1], ncpi->length, "wwwwssss", fax_parms))
  2632. {
  2633. dbug(1,dprintf("non-standard facilities info missing or wrong format"));
  2634. }
  2635. else
  2636. {
  2637. if (plci->fax_connect_info_length <= len)
  2638. plci->fax_connect_info_buffer[len] = 0;
  2639. len += 1 + plci->fax_connect_info_buffer[len];
  2640. if (plci->fax_connect_info_length <= len)
  2641. plci->fax_connect_info_buffer[len] = 0;
  2642. len += 1 + plci->fax_connect_info_buffer[len];
  2643. if ((fax_parms[7].length >= 3) && (fax_parms[7].info[1] >= 2))
  2644. plci->nsf_control_bits = GET_WORD(&fax_parms[7].info[2]);
  2645. plci->fax_connect_info_buffer[len++] = (byte)(fax_parms[7].length);
  2646. for (i = 0; i < fax_parms[7].length; i++)
  2647. plci->fax_connect_info_buffer[len++] = fax_parms[7].info[1+i];
  2648. }
  2649. plci->fax_connect_info_length = len;
  2650. ((T30_INFO *)(plci->fax_connect_info_buffer))->code = 0;
  2651. start_internal_command (Id, plci, fax_connect_ack_command);
  2652. return false;
  2653. }
  2654. }
  2655. nl_req_ncci(plci,req,(byte)ncci);
  2656. if ((plci->ncpi_state & NCPI_VALID_CONNECT_B3_ACT)
  2657. && !(plci->ncpi_state & NCPI_CONNECT_B3_ACT_SENT))
  2658. {
  2659. if (plci->B3_prot == 4)
  2660. sendf(appl,_CONNECT_B3_ACTIVE_I,Id,0,"s","");
  2661. else
  2662. sendf(appl,_CONNECT_B3_ACTIVE_I,Id,0,"S",plci->ncpi_buffer);
  2663. plci->ncpi_state |= NCPI_CONNECT_B3_ACT_SENT;
  2664. }
  2665. }
  2666. else if (plci->B3_prot == B3_RTP)
  2667. {
  2668. plci->internal_req_buffer[0] = ncpi->length + 1;
  2669. plci->internal_req_buffer[1] = UDATA_REQUEST_RTP_RECONFIGURE;
  2670. for (w = 0; w < ncpi->length; w++)
  2671. plci->internal_req_buffer[2+w] = ncpi->info[1+w];
  2672. start_internal_command (Id, plci, rtp_connect_b3_res_command);
  2673. return false;
  2674. }
  2675. else
  2676. {
  2677. if(ncpi->length>2) {
  2678. if(ncpi->info[1] &1) req = N_CONNECT_ACK | N_D_BIT;
  2679. add_d(plci,(word)(ncpi->length-3),&ncpi->info[4]);
  2680. }
  2681. nl_req_ncci(plci,req,(byte)ncci);
  2682. sendf(appl,_CONNECT_B3_ACTIVE_I,Id,0,"s","");
  2683. if (plci->adjust_b_restore)
  2684. {
  2685. plci->adjust_b_restore = false;
  2686. start_internal_command (Id, plci, adjust_b_restore);
  2687. }
  2688. }
  2689. return 1;
  2690. }
  2691. }
  2692. return false;
  2693. }
  2694. static byte connect_b3_a_res(dword Id, word Number, DIVA_CAPI_ADAPTER *a,
  2695. PLCI *plci, APPL *appl, API_PARSE *parms)
  2696. {
  2697. word ncci;
  2698. ncci = (word)(Id>>16);
  2699. dbug(1,dprintf("connect_b3_a_res(ncci=0x%x)",ncci));
  2700. if (plci && ncci && (plci->State != IDLE) && (plci->State != INC_DIS_PENDING)
  2701. && (plci->State != OUTG_DIS_PENDING))
  2702. {
  2703. if(a->ncci_state[ncci]==INC_ACT_PENDING) {
  2704. a->ncci_state[ncci] = CONNECTED;
  2705. if(plci->State!=INC_CON_CONNECTED_ALERT) plci->State = CONNECTED;
  2706. channel_request_xon (plci, a->ncci_ch[ncci]);
  2707. channel_xmit_xon (plci);
  2708. }
  2709. }
  2710. return false;
  2711. }
  2712. static byte disconnect_b3_req(dword Id, word Number, DIVA_CAPI_ADAPTER *a,
  2713. PLCI *plci, APPL *appl, API_PARSE *parms)
  2714. {
  2715. word Info;
  2716. word ncci;
  2717. API_PARSE * ncpi;
  2718. dbug(1,dprintf("disconnect_b3_req"));
  2719. Info = _WRONG_IDENTIFIER;
  2720. ncci = (word)(Id>>16);
  2721. if (plci && ncci)
  2722. {
  2723. Info = _WRONG_STATE;
  2724. if ((a->ncci_state[ncci] == CONNECTED)
  2725. || (a->ncci_state[ncci] == OUTG_CON_PENDING)
  2726. || (a->ncci_state[ncci] == INC_CON_PENDING)
  2727. || (a->ncci_state[ncci] == INC_ACT_PENDING))
  2728. {
  2729. a->ncci_state[ncci] = OUTG_DIS_PENDING;
  2730. channel_request_xon (plci, a->ncci_ch[ncci]);
  2731. channel_xmit_xon (plci);
  2732. if (a->ncci[ncci].data_pending
  2733. && ((plci->B3_prot == B3_TRANSPARENT)
  2734. || (plci->B3_prot == B3_T30)
  2735. || (plci->B3_prot == B3_T30_WITH_EXTENSIONS)))
  2736. {
  2737. plci->send_disc = (byte)ncci;
  2738. plci->command = 0;
  2739. return false;
  2740. }
  2741. else
  2742. {
  2743. cleanup_ncci_data (plci, ncci);
  2744. if(plci->B3_prot==2 || plci->B3_prot==3)
  2745. {
  2746. ncpi = &parms[0];
  2747. if(ncpi->length>3)
  2748. {
  2749. add_d(plci, (word)(ncpi->length - 3) ,(byte *)&(ncpi->info[4]));
  2750. }
  2751. }
  2752. nl_req_ncci(plci,N_DISC,(byte)ncci);
  2753. }
  2754. return 1;
  2755. }
  2756. }
  2757. sendf(appl,
  2758. _DISCONNECT_B3_R|CONFIRM,
  2759. Id,
  2760. Number,
  2761. "w",Info);
  2762. return false;
  2763. }
  2764. static byte disconnect_b3_res(dword Id, word Number, DIVA_CAPI_ADAPTER *a,
  2765. PLCI *plci, APPL *appl, API_PARSE *parms)
  2766. {
  2767. word ncci;
  2768. word i;
  2769. ncci = (word)(Id>>16);
  2770. dbug(1,dprintf("disconnect_b3_res(ncci=0x%x",ncci));
  2771. if(plci && ncci) {
  2772. plci->requested_options_conn = 0;
  2773. plci->fax_connect_info_length = 0;
  2774. plci->ncpi_state = 0x00;
  2775. if (((plci->B3_prot != B3_T90NL) && (plci->B3_prot != B3_ISO8208) && (plci->B3_prot != B3_X25_DCE))
  2776. && ((plci->B2_prot != B2_LAPD) && (plci->B2_prot != B2_LAPD_FREE_SAPI_SEL)))
  2777. {
  2778. plci->call_dir |= CALL_DIR_FORCE_OUTG_NL;
  2779. }
  2780. for(i=0; i<MAX_CHANNELS_PER_PLCI && plci->inc_dis_ncci_table[i]!=(byte)ncci; i++);
  2781. if(i<MAX_CHANNELS_PER_PLCI) {
  2782. if(plci->channels)plci->channels--;
  2783. for(; i<MAX_CHANNELS_PER_PLCI-1; i++) plci->inc_dis_ncci_table[i] = plci->inc_dis_ncci_table[i+1];
  2784. plci->inc_dis_ncci_table[MAX_CHANNELS_PER_PLCI-1] = 0;
  2785. ncci_free_receive_buffers (plci, ncci);
  2786. if((plci->State==IDLE || plci->State==SUSPENDING) && !plci->channels){
  2787. if(plci->State == SUSPENDING){
  2788. sendf(plci->appl,
  2789. _FACILITY_I,
  2790. Id & 0xffffL,
  2791. 0,
  2792. "ws", (word)3, "\x03\x04\x00\x00");
  2793. sendf(plci->appl, _DISCONNECT_I, Id & 0xffffL, 0, "w", 0);
  2794. }
  2795. plci_remove(plci);
  2796. plci->State=IDLE;
  2797. }
  2798. }
  2799. else
  2800. {
  2801. if ((a->manufacturer_features & MANUFACTURER_FEATURE_FAX_PAPER_FORMATS)
  2802. && ((plci->B3_prot == 4) || (plci->B3_prot == 5))
  2803. && (a->ncci_state[ncci] == INC_DIS_PENDING))
  2804. {
  2805. ncci_free_receive_buffers (plci, ncci);
  2806. nl_req_ncci(plci,N_EDATA,(byte)ncci);
  2807. plci->adapter->ncci_state[ncci] = IDLE;
  2808. start_internal_command (Id, plci, fax_disconnect_command);
  2809. return 1;
  2810. }
  2811. }
  2812. }
  2813. return false;
  2814. }
  2815. static byte data_b3_req(dword Id, word Number, DIVA_CAPI_ADAPTER *a,
  2816. PLCI *plci, APPL *appl, API_PARSE *parms)
  2817. {
  2818. NCCI *ncci_ptr;
  2819. DATA_B3_DESC *data;
  2820. word Info;
  2821. word ncci;
  2822. word i;
  2823. dbug(1,dprintf("data_b3_req"));
  2824. Info = _WRONG_IDENTIFIER;
  2825. ncci = (word)(Id>>16);
  2826. dbug(1,dprintf("ncci=0x%x, plci=0x%x",ncci,plci));
  2827. if (plci && ncci)
  2828. {
  2829. Info = _WRONG_STATE;
  2830. if ((a->ncci_state[ncci] == CONNECTED)
  2831. || (a->ncci_state[ncci] == INC_ACT_PENDING))
  2832. {
  2833. /* queue data */
  2834. ncci_ptr = &(a->ncci[ncci]);
  2835. i = ncci_ptr->data_out + ncci_ptr->data_pending;
  2836. if (i >= MAX_DATA_B3)
  2837. i -= MAX_DATA_B3;
  2838. data = &(ncci_ptr->DBuffer[i]);
  2839. data->Number = Number;
  2840. if ((((byte *)(parms[0].info)) >= ((byte *)(plci->msg_in_queue)))
  2841. && (((byte *)(parms[0].info)) < ((byte *)(plci->msg_in_queue)) + sizeof(plci->msg_in_queue)))
  2842. {
  2843. data->P = (byte *)(long)(*((dword *)(parms[0].info)));
  2844. }
  2845. else
  2846. data->P = TransmitBufferSet(appl,*(dword *)parms[0].info);
  2847. data->Length = GET_WORD(parms[1].info);
  2848. data->Handle = GET_WORD(parms[2].info);
  2849. data->Flags = GET_WORD(parms[3].info);
  2850. (ncci_ptr->data_pending)++;
  2851. /* check for delivery confirmation */
  2852. if (data->Flags & 0x0004)
  2853. {
  2854. i = ncci_ptr->data_ack_out + ncci_ptr->data_ack_pending;
  2855. if (i >= MAX_DATA_ACK)
  2856. i -= MAX_DATA_ACK;
  2857. ncci_ptr->DataAck[i].Number = data->Number;
  2858. ncci_ptr->DataAck[i].Handle = data->Handle;
  2859. (ncci_ptr->data_ack_pending)++;
  2860. }
  2861. send_data(plci);
  2862. return false;
  2863. }
  2864. }
  2865. if (appl)
  2866. {
  2867. if (plci)
  2868. {
  2869. if ((((byte *)(parms[0].info)) >= ((byte *)(plci->msg_in_queue)))
  2870. && (((byte *)(parms[0].info)) < ((byte *)(plci->msg_in_queue)) + sizeof(plci->msg_in_queue)))
  2871. {
  2872. TransmitBufferFree (appl, (byte *)(long)(*((dword *)(parms[0].info))));
  2873. }
  2874. }
  2875. sendf(appl,
  2876. _DATA_B3_R|CONFIRM,
  2877. Id,
  2878. Number,
  2879. "ww",GET_WORD(parms[2].info),Info);
  2880. }
  2881. return false;
  2882. }
  2883. static byte data_b3_res(dword Id, word Number, DIVA_CAPI_ADAPTER *a,
  2884. PLCI *plci, APPL *appl, API_PARSE *parms)
  2885. {
  2886. word n;
  2887. word ncci;
  2888. word NCCIcode;
  2889. dbug(1,dprintf("data_b3_res"));
  2890. ncci = (word)(Id>>16);
  2891. if(plci && ncci) {
  2892. n = GET_WORD(parms[0].info);
  2893. dbug(1,dprintf("free(%d)",n));
  2894. NCCIcode = ncci | (((word) a->Id) << 8);
  2895. if(n<appl->MaxBuffer &&
  2896. appl->DataNCCI[n]==NCCIcode &&
  2897. (byte)(appl->DataFlags[n]>>8)==plci->Id) {
  2898. dbug(1,dprintf("found"));
  2899. appl->DataNCCI[n] = 0;
  2900. if (channel_can_xon (plci, a->ncci_ch[ncci])) {
  2901. channel_request_xon (plci, a->ncci_ch[ncci]);
  2902. }
  2903. channel_xmit_xon (plci);
  2904. if(appl->DataFlags[n] &4) {
  2905. nl_req_ncci(plci,N_DATA_ACK,(byte)ncci);
  2906. return 1;
  2907. }
  2908. }
  2909. }
  2910. return false;
  2911. }
  2912. static byte reset_b3_req(dword Id, word Number, DIVA_CAPI_ADAPTER *a,
  2913. PLCI *plci, APPL *appl, API_PARSE *parms)
  2914. {
  2915. word Info;
  2916. word ncci;
  2917. dbug(1,dprintf("reset_b3_req"));
  2918. Info = _WRONG_IDENTIFIER;
  2919. ncci = (word)(Id>>16);
  2920. if(plci && ncci)
  2921. {
  2922. Info = _WRONG_STATE;
  2923. switch (plci->B3_prot)
  2924. {
  2925. case B3_ISO8208:
  2926. case B3_X25_DCE:
  2927. if(a->ncci_state[ncci]==CONNECTED)
  2928. {
  2929. nl_req_ncci(plci,N_RESET,(byte)ncci);
  2930. send_req(plci);
  2931. Info = GOOD;
  2932. }
  2933. break;
  2934. case B3_TRANSPARENT:
  2935. if(a->ncci_state[ncci]==CONNECTED)
  2936. {
  2937. start_internal_command (Id, plci, reset_b3_command);
  2938. Info = GOOD;
  2939. }
  2940. break;
  2941. }
  2942. }
  2943. /* reset_b3 must result in a reset_b3_con & reset_b3_Ind */
  2944. sendf(appl,
  2945. _RESET_B3_R|CONFIRM,
  2946. Id,
  2947. Number,
  2948. "w",Info);
  2949. return false;
  2950. }
  2951. static byte reset_b3_res(dword Id, word Number, DIVA_CAPI_ADAPTER *a,
  2952. PLCI *plci, APPL *appl, API_PARSE *parms)
  2953. {
  2954. word ncci;
  2955. dbug(1,dprintf("reset_b3_res"));
  2956. ncci = (word)(Id>>16);
  2957. if(plci && ncci) {
  2958. switch (plci->B3_prot)
  2959. {
  2960. case B3_ISO8208:
  2961. case B3_X25_DCE:
  2962. if(a->ncci_state[ncci]==INC_RES_PENDING)
  2963. {
  2964. a->ncci_state[ncci] = CONNECTED;
  2965. nl_req_ncci(plci,N_RESET_ACK,(byte)ncci);
  2966. return true;
  2967. }
  2968. break;
  2969. }
  2970. }
  2971. return false;
  2972. }
  2973. static byte connect_b3_t90_a_res(dword Id, word Number, DIVA_CAPI_ADAPTER *a,
  2974. PLCI *plci, APPL *appl, API_PARSE *parms)
  2975. {
  2976. word ncci;
  2977. API_PARSE * ncpi;
  2978. byte req;
  2979. dbug(1,dprintf("connect_b3_t90_a_res"));
  2980. ncci = (word)(Id>>16);
  2981. if(plci && ncci) {
  2982. if(a->ncci_state[ncci]==INC_ACT_PENDING) {
  2983. a->ncci_state[ncci] = CONNECTED;
  2984. }
  2985. else if(a->ncci_state[ncci]==INC_CON_PENDING) {
  2986. a->ncci_state[ncci] = CONNECTED;
  2987. req = N_CONNECT_ACK;
  2988. /* parms[0]==0 for CAPI original message definition! */
  2989. if(parms[0].info) {
  2990. ncpi = &parms[1];
  2991. if(ncpi->length>2) {
  2992. if(ncpi->info[1] &1) req = N_CONNECT_ACK | N_D_BIT;
  2993. add_d(plci,(word)(ncpi->length-3),&ncpi->info[4]);
  2994. }
  2995. }
  2996. nl_req_ncci(plci,req,(byte)ncci);
  2997. return 1;
  2998. }
  2999. }
  3000. return false;
  3001. }
  3002. static byte select_b_req(dword Id, word Number, DIVA_CAPI_ADAPTER *a,
  3003. PLCI *plci, APPL *appl, API_PARSE *msg)
  3004. {
  3005. word Info=0;
  3006. word i;
  3007. byte tel;
  3008. API_PARSE bp_parms[7];
  3009. if(!plci || !msg)
  3010. {
  3011. Info = _WRONG_IDENTIFIER;
  3012. }
  3013. else
  3014. {
  3015. dbug(1,dprintf("select_b_req[%d],PLCI=0x%x,Tel=0x%x,NL=0x%x,appl=0x%x,sstate=0x%x",
  3016. msg->length,plci->Id,plci->tel,plci->NL.Id,plci->appl,plci->SuppState));
  3017. dbug(1,dprintf("PlciState=0x%x",plci->State));
  3018. for(i=0;i<7;i++) bp_parms[i].length = 0;
  3019. /* check if no channel is open, no B3 connected only */
  3020. if((plci->State == IDLE) || (plci->State == OUTG_DIS_PENDING) || (plci->State == INC_DIS_PENDING)
  3021. || (plci->SuppState != IDLE) || plci->channels || plci->nl_remove_id)
  3022. {
  3023. Info = _WRONG_STATE;
  3024. }
  3025. /* check message format and fill bp_parms pointer */
  3026. else if(msg->length && api_parse(&msg->info[1], (word)msg->length, "wwwsss", bp_parms))
  3027. {
  3028. Info = _WRONG_MESSAGE_FORMAT;
  3029. }
  3030. else
  3031. {
  3032. if((plci->State==INC_CON_PENDING) || (plci->State==INC_CON_ALERT)) /* send alert tone inband to the network, */
  3033. { /* e.g. Qsig or RBS or Cornet-N or xess PRI */
  3034. if(Id & EXT_CONTROLLER)
  3035. {
  3036. sendf(appl, _SELECT_B_REQ|CONFIRM, Id, Number, "w", 0x2002); /* wrong controller */
  3037. return 0;
  3038. }
  3039. plci->State=INC_CON_CONNECTED_ALERT;
  3040. plci->appl = appl;
  3041. clear_c_ind_mask_bit (plci, (word)(appl->Id-1));
  3042. dump_c_ind_mask (plci);
  3043. for(i=0; i<max_appl; i++) /* disconnect the other appls */
  3044. { /* its quasi a connect */
  3045. if(test_c_ind_mask_bit (plci, i))
  3046. sendf(&application[i], _DISCONNECT_I, Id, 0, "w", _OTHER_APPL_CONNECTED);
  3047. }
  3048. }
  3049. api_save_msg(msg, "s", &plci->saved_msg);
  3050. tel = plci->tel;
  3051. if(Id & EXT_CONTROLLER)
  3052. {
  3053. if(tel) /* external controller in use by this PLCI */
  3054. {
  3055. if(a->AdvSignalAppl && a->AdvSignalAppl!=appl)
  3056. {
  3057. dbug(1,dprintf("Ext_Ctrl in use 1"));
  3058. Info = _WRONG_STATE;
  3059. }
  3060. }
  3061. else /* external controller NOT in use by this PLCI ? */
  3062. {
  3063. if(a->AdvSignalPLCI)
  3064. {
  3065. dbug(1,dprintf("Ext_Ctrl in use 2"));
  3066. Info = _WRONG_STATE;
  3067. }
  3068. else /* activate the codec */
  3069. {
  3070. dbug(1,dprintf("Ext_Ctrl start"));
  3071. if(AdvCodecSupport(a, plci, appl, 0) )
  3072. {
  3073. dbug(1,dprintf("Error in codec procedures"));
  3074. Info = _WRONG_STATE;
  3075. }
  3076. else if(plci->spoofed_msg==SPOOFING_REQUIRED) /* wait until codec is active */
  3077. {
  3078. plci->spoofed_msg = AWAITING_SELECT_B;
  3079. plci->internal_command = BLOCK_PLCI; /* lock other commands */
  3080. plci->command = 0;
  3081. dbug(1,dprintf("continue if codec loaded"));
  3082. return false;
  3083. }
  3084. }
  3085. }
  3086. }
  3087. else /* external controller bit is OFF */
  3088. {
  3089. if(tel) /* external controller in use, need to switch off */
  3090. {
  3091. if(a->AdvSignalAppl==appl)
  3092. {
  3093. CodecIdCheck(a, plci);
  3094. plci->tel = 0;
  3095. plci->adv_nl = 0;
  3096. dbug(1,dprintf("Ext_Ctrl disable"));
  3097. }
  3098. else
  3099. {
  3100. dbug(1,dprintf("Ext_Ctrl not requested"));
  3101. }
  3102. }
  3103. }
  3104. if (!Info)
  3105. {
  3106. if (plci->call_dir & CALL_DIR_OUT)
  3107. plci->call_dir = CALL_DIR_OUT | CALL_DIR_ORIGINATE;
  3108. else if (plci->call_dir & CALL_DIR_IN)
  3109. plci->call_dir = CALL_DIR_IN | CALL_DIR_ANSWER;
  3110. start_internal_command (Id, plci, select_b_command);
  3111. return false;
  3112. }
  3113. }
  3114. }
  3115. sendf(appl, _SELECT_B_REQ|CONFIRM, Id, Number, "w", Info);
  3116. return false;
  3117. }
  3118. static byte manufacturer_req(dword Id, word Number, DIVA_CAPI_ADAPTER *a,
  3119. PLCI *plci, APPL *appl, API_PARSE *parms)
  3120. {
  3121. word command;
  3122. word i;
  3123. word ncci;
  3124. API_PARSE * m;
  3125. API_PARSE m_parms[5];
  3126. word codec;
  3127. byte req;
  3128. byte ch;
  3129. byte dir;
  3130. static byte chi[2] = {0x01,0x00};
  3131. static byte lli[2] = {0x01,0x00};
  3132. static byte codec_cai[2] = {0x01,0x01};
  3133. static byte null_msg = {0};
  3134. static API_PARSE null_parms = { 0, &null_msg };
  3135. PLCI * v_plci;
  3136. word Info=0;
  3137. dbug(1,dprintf("manufacturer_req"));
  3138. for(i=0;i<5;i++) m_parms[i].length = 0;
  3139. if(GET_DWORD(parms[0].info)!=_DI_MANU_ID) {
  3140. Info = _WRONG_MESSAGE_FORMAT;
  3141. }
  3142. command = GET_WORD(parms[1].info);
  3143. m = &parms[2];
  3144. if (!Info)
  3145. {
  3146. switch(command) {
  3147. case _DI_ASSIGN_PLCI:
  3148. if(api_parse(&m->info[1],(word)m->length,"wbbs",m_parms)) {
  3149. Info = _WRONG_MESSAGE_FORMAT;
  3150. break;
  3151. }
  3152. codec = GET_WORD(m_parms[0].info);
  3153. ch = m_parms[1].info[0];
  3154. dir = m_parms[2].info[0];
  3155. if((i=get_plci(a))) {
  3156. plci = &a->plci[i-1];
  3157. plci->appl = appl;
  3158. plci->command = _MANUFACTURER_R;
  3159. plci->m_command = command;
  3160. plci->number = Number;
  3161. plci->State = LOCAL_CONNECT;
  3162. Id = ( ((word)plci->Id<<8)|plci->adapter->Id|0x80);
  3163. dbug(1,dprintf("ManCMD,plci=0x%x",Id));
  3164. if((ch==1 || ch==2) && (dir<=2)) {
  3165. chi[1] = (byte)(0x80|ch);
  3166. lli[1] = 0;
  3167. plci->call_dir = CALL_DIR_OUT | CALL_DIR_ORIGINATE;
  3168. switch(codec)
  3169. {
  3170. case 0:
  3171. Info = add_b1(plci,&m_parms[3],0,0);
  3172. break;
  3173. case 1:
  3174. add_p(plci,CAI,codec_cai);
  3175. break;
  3176. /* manual 'swich on' to the codec support without signalling */
  3177. /* first 'assign plci' with this function, then use */
  3178. case 2:
  3179. if(AdvCodecSupport(a, plci, appl, 0) ) {
  3180. Info = _RESOURCE_ERROR;
  3181. }
  3182. else {
  3183. Info = add_b1(plci,&null_parms,0,B1_FACILITY_LOCAL);
  3184. lli[1] = 0x10; /* local call codec stream */
  3185. }
  3186. break;
  3187. }
  3188. plci->State = LOCAL_CONNECT;
  3189. plci->manufacturer = true;
  3190. plci->command = _MANUFACTURER_R;
  3191. plci->m_command = command;
  3192. plci->number = Number;
  3193. if(!Info)
  3194. {
  3195. add_p(plci,LLI,lli);
  3196. add_p(plci,CHI,chi);
  3197. add_p(plci,UID,"\x06\x43\x61\x70\x69\x32\x30");
  3198. sig_req(plci,ASSIGN,DSIG_ID);
  3199. if(!codec)
  3200. {
  3201. Info = add_b23(plci,&m_parms[3]);
  3202. if(!Info)
  3203. {
  3204. nl_req_ncci(plci,ASSIGN,0);
  3205. send_req(plci);
  3206. }
  3207. }
  3208. if(!Info)
  3209. {
  3210. dbug(1,dprintf("dir=0x%x,spoof=0x%x",dir,plci->spoofed_msg));
  3211. if (plci->spoofed_msg==SPOOFING_REQUIRED)
  3212. {
  3213. api_save_msg (m_parms, "wbbs", &plci->saved_msg);
  3214. plci->spoofed_msg = AWAITING_MANUF_CON;
  3215. plci->internal_command = BLOCK_PLCI; /* reject other req meanwhile */
  3216. plci->command = 0;
  3217. send_req(plci);
  3218. return false;
  3219. }
  3220. if(dir==1) {
  3221. sig_req(plci,CALL_REQ,0);
  3222. }
  3223. else if(!dir){
  3224. sig_req(plci,LISTEN_REQ,0);
  3225. }
  3226. send_req(plci);
  3227. }
  3228. else
  3229. {
  3230. sendf(appl,
  3231. _MANUFACTURER_R|CONFIRM,
  3232. Id,
  3233. Number,
  3234. "dww",_DI_MANU_ID,command,Info);
  3235. return 2;
  3236. }
  3237. }
  3238. }
  3239. }
  3240. else Info = _OUT_OF_PLCI;
  3241. break;
  3242. case _DI_IDI_CTRL:
  3243. if(!plci)
  3244. {
  3245. Info = _WRONG_IDENTIFIER;
  3246. break;
  3247. }
  3248. if(api_parse(&m->info[1],(word)m->length,"bs",m_parms)) {
  3249. Info = _WRONG_MESSAGE_FORMAT;
  3250. break;
  3251. }
  3252. req = m_parms[0].info[0];
  3253. plci->command = _MANUFACTURER_R;
  3254. plci->m_command = command;
  3255. plci->number = Number;
  3256. if(req==CALL_REQ)
  3257. {
  3258. plci->b_channel = getChannel(&m_parms[1]);
  3259. mixer_set_bchannel_id_esc (plci, plci->b_channel);
  3260. if(plci->spoofed_msg==SPOOFING_REQUIRED)
  3261. {
  3262. plci->spoofed_msg = CALL_REQ | AWAITING_MANUF_CON;
  3263. plci->internal_command = BLOCK_PLCI; /* reject other req meanwhile */
  3264. plci->command = 0;
  3265. break;
  3266. }
  3267. }
  3268. else if(req==LAW_REQ)
  3269. {
  3270. plci->cr_enquiry = true;
  3271. }
  3272. add_ss(plci,FTY,&m_parms[1]);
  3273. sig_req(plci,req,0);
  3274. send_req(plci);
  3275. if(req==HANGUP)
  3276. {
  3277. if (plci->NL.Id && !plci->nl_remove_id)
  3278. {
  3279. if (plci->channels)
  3280. {
  3281. for (ncci = 1; ncci < MAX_NCCI+1; ncci++)
  3282. {
  3283. if ((a->ncci_plci[ncci] == plci->Id) && (a->ncci_state[ncci] == CONNECTED))
  3284. {
  3285. a->ncci_state[ncci] = OUTG_DIS_PENDING;
  3286. cleanup_ncci_data (plci, ncci);
  3287. nl_req_ncci(plci,N_DISC,(byte)ncci);
  3288. }
  3289. }
  3290. }
  3291. mixer_remove (plci);
  3292. nl_req_ncci(plci,REMOVE,0);
  3293. send_req(plci);
  3294. }
  3295. }
  3296. break;
  3297. case _DI_SIG_CTRL:
  3298. /* signalling control for loop activation B-channel */
  3299. if(!plci)
  3300. {
  3301. Info = _WRONG_IDENTIFIER;
  3302. break;
  3303. }
  3304. if(m->length){
  3305. plci->command = _MANUFACTURER_R;
  3306. plci->number = Number;
  3307. add_ss(plci,FTY,m);
  3308. sig_req(plci,SIG_CTRL,0);
  3309. send_req(plci);
  3310. }
  3311. else Info = _WRONG_MESSAGE_FORMAT;
  3312. break;
  3313. case _DI_RXT_CTRL:
  3314. /* activation control for receiver/transmitter B-channel */
  3315. if(!plci)
  3316. {
  3317. Info = _WRONG_IDENTIFIER;
  3318. break;
  3319. }
  3320. if(m->length){
  3321. plci->command = _MANUFACTURER_R;
  3322. plci->number = Number;
  3323. add_ss(plci,FTY,m);
  3324. sig_req(plci,DSP_CTRL,0);
  3325. send_req(plci);
  3326. }
  3327. else Info = _WRONG_MESSAGE_FORMAT;
  3328. break;
  3329. case _DI_ADV_CODEC:
  3330. case _DI_DSP_CTRL:
  3331. /* TEL_CTRL commands to support non standard adjustments: */
  3332. /* Ring on/off, Handset micro volume, external micro vol. */
  3333. /* handset+external speaker volume, receiver+transm. gain,*/
  3334. /* handsfree on (hookinfo off), set mixer command */
  3335. if(command == _DI_ADV_CODEC)
  3336. {
  3337. if(!a->AdvCodecPLCI) {
  3338. Info = _WRONG_STATE;
  3339. break;
  3340. }
  3341. v_plci = a->AdvCodecPLCI;
  3342. }
  3343. else
  3344. {
  3345. if (plci
  3346. && (m->length >= 3)
  3347. && (m->info[1] == 0x1c)
  3348. && (m->info[2] >= 1))
  3349. {
  3350. if (m->info[3] == DSP_CTRL_OLD_SET_MIXER_COEFFICIENTS)
  3351. {
  3352. if ((plci->tel != ADV_VOICE) || (plci != a->AdvSignalPLCI))
  3353. {
  3354. Info = _WRONG_STATE;
  3355. break;
  3356. }
  3357. a->adv_voice_coef_length = m->info[2] - 1;
  3358. if (a->adv_voice_coef_length > m->length - 3)
  3359. a->adv_voice_coef_length = (byte)(m->length - 3);
  3360. if (a->adv_voice_coef_length > ADV_VOICE_COEF_BUFFER_SIZE)
  3361. a->adv_voice_coef_length = ADV_VOICE_COEF_BUFFER_SIZE;
  3362. for (i = 0; i < a->adv_voice_coef_length; i++)
  3363. a->adv_voice_coef_buffer[i] = m->info[4 + i];
  3364. if (plci->B1_facilities & B1_FACILITY_VOICE)
  3365. adv_voice_write_coefs (plci, ADV_VOICE_WRITE_UPDATE);
  3366. break;
  3367. }
  3368. else if (m->info[3] == DSP_CTRL_SET_DTMF_PARAMETERS)
  3369. {
  3370. if (!(a->manufacturer_features & MANUFACTURER_FEATURE_DTMF_PARAMETERS))
  3371. {
  3372. Info = _FACILITY_NOT_SUPPORTED;
  3373. break;
  3374. }
  3375. plci->dtmf_parameter_length = m->info[2] - 1;
  3376. if (plci->dtmf_parameter_length > m->length - 3)
  3377. plci->dtmf_parameter_length = (byte)(m->length - 3);
  3378. if (plci->dtmf_parameter_length > DTMF_PARAMETER_BUFFER_SIZE)
  3379. plci->dtmf_parameter_length = DTMF_PARAMETER_BUFFER_SIZE;
  3380. for (i = 0; i < plci->dtmf_parameter_length; i++)
  3381. plci->dtmf_parameter_buffer[i] = m->info[4+i];
  3382. if (plci->B1_facilities & B1_FACILITY_DTMFR)
  3383. dtmf_parameter_write (plci);
  3384. break;
  3385. }
  3386. }
  3387. v_plci = plci;
  3388. }
  3389. if(!v_plci)
  3390. {
  3391. Info = _WRONG_IDENTIFIER;
  3392. break;
  3393. }
  3394. if(m->length){
  3395. add_ss(v_plci,FTY,m);
  3396. sig_req(v_plci,TEL_CTRL,0);
  3397. send_req(v_plci);
  3398. }
  3399. else Info = _WRONG_MESSAGE_FORMAT;
  3400. break;
  3401. case _DI_OPTIONS_REQUEST:
  3402. if(api_parse(&m->info[1],(word)m->length,"d",m_parms)) {
  3403. Info = _WRONG_MESSAGE_FORMAT;
  3404. break;
  3405. }
  3406. if (GET_DWORD (m_parms[0].info) & ~a->man_profile.private_options)
  3407. {
  3408. Info = _FACILITY_NOT_SUPPORTED;
  3409. break;
  3410. }
  3411. a->requested_options_table[appl->Id-1] = GET_DWORD (m_parms[0].info);
  3412. break;
  3413. default:
  3414. Info = _WRONG_MESSAGE_FORMAT;
  3415. break;
  3416. }
  3417. }
  3418. sendf(appl,
  3419. _MANUFACTURER_R|CONFIRM,
  3420. Id,
  3421. Number,
  3422. "dww",_DI_MANU_ID,command,Info);
  3423. return false;
  3424. }
  3425. static byte manufacturer_res(dword Id, word Number, DIVA_CAPI_ADAPTER *a,
  3426. PLCI *plci, APPL *appl, API_PARSE *msg)
  3427. {
  3428. word indication;
  3429. API_PARSE m_parms[3];
  3430. API_PARSE *ncpi;
  3431. API_PARSE fax_parms[9];
  3432. word i;
  3433. byte len;
  3434. dbug(1,dprintf("manufacturer_res"));
  3435. if ((msg[0].length == 0)
  3436. || (msg[1].length == 0)
  3437. || (GET_DWORD(msg[0].info)!=_DI_MANU_ID))
  3438. {
  3439. return false;
  3440. }
  3441. indication = GET_WORD(msg[1].info);
  3442. switch (indication)
  3443. {
  3444. case _DI_NEGOTIATE_B3:
  3445. if(!plci)
  3446. break;
  3447. if (((plci->B3_prot != 4) && (plci->B3_prot != 5))
  3448. || !(plci->ncpi_state & NCPI_NEGOTIATE_B3_SENT))
  3449. {
  3450. dbug(1,dprintf("wrong state for NEGOTIATE_B3 parameters"));
  3451. break;
  3452. }
  3453. if (api_parse (&msg[2].info[1], msg[2].length, "ws", m_parms))
  3454. {
  3455. dbug(1,dprintf("wrong format in NEGOTIATE_B3 parameters"));
  3456. break;
  3457. }
  3458. ncpi = &m_parms[1];
  3459. len = ((byte)(((T30_INFO *) 0)->station_id + 20));
  3460. if (plci->fax_connect_info_length < len)
  3461. {
  3462. ((T30_INFO *)(plci->fax_connect_info_buffer))->station_id_len = 0;
  3463. ((T30_INFO *)(plci->fax_connect_info_buffer))->head_line_len = 0;
  3464. }
  3465. if (api_parse (&ncpi->info[1], ncpi->length, "wwwwssss", fax_parms))
  3466. {
  3467. dbug(1,dprintf("non-standard facilities info missing or wrong format"));
  3468. }
  3469. else
  3470. {
  3471. if (plci->fax_connect_info_length <= len)
  3472. plci->fax_connect_info_buffer[len] = 0;
  3473. len += 1 + plci->fax_connect_info_buffer[len];
  3474. if (plci->fax_connect_info_length <= len)
  3475. plci->fax_connect_info_buffer[len] = 0;
  3476. len += 1 + plci->fax_connect_info_buffer[len];
  3477. if ((fax_parms[7].length >= 3) && (fax_parms[7].info[1] >= 2))
  3478. plci->nsf_control_bits = GET_WORD(&fax_parms[7].info[2]);
  3479. plci->fax_connect_info_buffer[len++] = (byte)(fax_parms[7].length);
  3480. for (i = 0; i < fax_parms[7].length; i++)
  3481. plci->fax_connect_info_buffer[len++] = fax_parms[7].info[1+i];
  3482. }
  3483. plci->fax_connect_info_length = len;
  3484. plci->fax_edata_ack_length = plci->fax_connect_info_length;
  3485. start_internal_command (Id, plci, fax_edata_ack_command);
  3486. break;
  3487. }
  3488. return false;
  3489. }
  3490. /*------------------------------------------------------------------*/
  3491. /* IDI callback function */
  3492. /*------------------------------------------------------------------*/
  3493. void callback(ENTITY * e)
  3494. {
  3495. DIVA_CAPI_ADAPTER * a;
  3496. APPL * appl;
  3497. PLCI * plci;
  3498. CAPI_MSG *m;
  3499. word i, j;
  3500. byte rc;
  3501. byte ch;
  3502. byte req;
  3503. byte global_req;
  3504. int no_cancel_rc;
  3505. dbug(1,dprintf("%x:CB(%x:Req=%x,Rc=%x,Ind=%x)",
  3506. (e->user[0]+1)&0x7fff,e->Id,e->Req,e->Rc,e->Ind));
  3507. a = &(adapter[(byte)e->user[0]]);
  3508. plci = &(a->plci[e->user[1]]);
  3509. no_cancel_rc = DIVA_CAPI_SUPPORTS_NO_CANCEL(a);
  3510. /*
  3511. If new protocol code and new XDI is used then CAPI should work
  3512. fully in accordance with IDI cpec an look on callback field instead
  3513. of Rc field for return codes.
  3514. */
  3515. if (((e->complete == 0xff) && no_cancel_rc) ||
  3516. (e->Rc && !no_cancel_rc)) {
  3517. rc = e->Rc;
  3518. ch = e->RcCh;
  3519. req = e->Req;
  3520. e->Rc = 0;
  3521. if (e->user[0] & 0x8000)
  3522. {
  3523. /*
  3524. If REMOVE request was sent then we have to wait until
  3525. return code with Id set to zero arrives.
  3526. All other return codes should be ignored.
  3527. */
  3528. if (req == REMOVE)
  3529. {
  3530. if (e->Id)
  3531. {
  3532. dbug(1,dprintf("cancel RC in REMOVE state"));
  3533. return;
  3534. }
  3535. channel_flow_control_remove (plci);
  3536. for (i = 0; i < 256; i++)
  3537. {
  3538. if (a->FlowControlIdTable[i] == plci->nl_remove_id)
  3539. a->FlowControlIdTable[i] = 0;
  3540. }
  3541. plci->nl_remove_id = 0;
  3542. if (plci->rx_dma_descriptor > 0) {
  3543. diva_free_dma_descriptor (plci, plci->rx_dma_descriptor - 1);
  3544. plci->rx_dma_descriptor = 0;
  3545. }
  3546. }
  3547. if (rc == OK_FC)
  3548. {
  3549. a->FlowControlIdTable[ch] = e->Id;
  3550. a->FlowControlSkipTable[ch] = 0;
  3551. a->ch_flow_control[ch] |= N_OK_FC_PENDING;
  3552. a->ch_flow_plci[ch] = plci->Id;
  3553. plci->nl_req = 0;
  3554. }
  3555. else
  3556. {
  3557. /*
  3558. Cancel return codes self, if feature was requested
  3559. */
  3560. if (no_cancel_rc && (a->FlowControlIdTable[ch] == e->Id) && e->Id) {
  3561. a->FlowControlIdTable[ch] = 0;
  3562. if ((rc == OK) && a->FlowControlSkipTable[ch]) {
  3563. dbug(3,dprintf ("XDI CAPI: RC cancelled Id:0x02, Ch:%02x", e->Id, ch));
  3564. return;
  3565. }
  3566. }
  3567. if (a->ch_flow_control[ch] & N_OK_FC_PENDING)
  3568. {
  3569. a->ch_flow_control[ch] &= ~N_OK_FC_PENDING;
  3570. if (ch == e->ReqCh)
  3571. plci->nl_req = 0;
  3572. }
  3573. else
  3574. plci->nl_req = 0;
  3575. }
  3576. if (plci->nl_req)
  3577. control_rc (plci, 0, rc, ch, 0, true);
  3578. else
  3579. {
  3580. if (req == N_XON)
  3581. {
  3582. channel_x_on (plci, ch);
  3583. if (plci->internal_command)
  3584. control_rc (plci, req, rc, ch, 0, true);
  3585. }
  3586. else
  3587. {
  3588. if (plci->nl_global_req)
  3589. {
  3590. global_req = plci->nl_global_req;
  3591. plci->nl_global_req = 0;
  3592. if (rc != ASSIGN_OK) {
  3593. e->Id = 0;
  3594. if (plci->rx_dma_descriptor > 0) {
  3595. diva_free_dma_descriptor (plci, plci->rx_dma_descriptor - 1);
  3596. plci->rx_dma_descriptor = 0;
  3597. }
  3598. }
  3599. channel_xmit_xon (plci);
  3600. control_rc (plci, 0, rc, ch, global_req, true);
  3601. }
  3602. else if (plci->data_sent)
  3603. {
  3604. channel_xmit_xon (plci);
  3605. plci->data_sent = false;
  3606. plci->NL.XNum = 1;
  3607. data_rc (plci, ch);
  3608. if (plci->internal_command)
  3609. control_rc (plci, req, rc, ch, 0, true);
  3610. }
  3611. else
  3612. {
  3613. channel_xmit_xon (plci);
  3614. control_rc (plci, req, rc, ch, 0, true);
  3615. }
  3616. }
  3617. }
  3618. }
  3619. else
  3620. {
  3621. /*
  3622. If REMOVE request was sent then we have to wait until
  3623. return code with Id set to zero arrives.
  3624. All other return codes should be ignored.
  3625. */
  3626. if (req == REMOVE)
  3627. {
  3628. if (e->Id)
  3629. {
  3630. dbug(1,dprintf("cancel RC in REMOVE state"));
  3631. return;
  3632. }
  3633. plci->sig_remove_id = 0;
  3634. }
  3635. plci->sig_req = 0;
  3636. if (plci->sig_global_req)
  3637. {
  3638. global_req = plci->sig_global_req;
  3639. plci->sig_global_req = 0;
  3640. if (rc != ASSIGN_OK)
  3641. e->Id = 0;
  3642. channel_xmit_xon (plci);
  3643. control_rc (plci, 0, rc, ch, global_req, false);
  3644. }
  3645. else
  3646. {
  3647. channel_xmit_xon (plci);
  3648. control_rc (plci, req, rc, ch, 0, false);
  3649. }
  3650. }
  3651. /*
  3652. Again: in accordance with IDI spec Rc and Ind can't be delivered in the
  3653. same callback. Also if new XDI and protocol code used then jump
  3654. direct to finish.
  3655. */
  3656. if (no_cancel_rc) {
  3657. channel_xmit_xon(plci);
  3658. goto capi_callback_suffix;
  3659. }
  3660. }
  3661. channel_xmit_xon(plci);
  3662. if (e->Ind) {
  3663. if (e->user[0] &0x8000) {
  3664. byte Ind = e->Ind & 0x0f;
  3665. byte Ch = e->IndCh;
  3666. if (((Ind==N_DISC) || (Ind==N_DISC_ACK)) &&
  3667. (a->ch_flow_plci[Ch] == plci->Id)) {
  3668. if (a->ch_flow_control[Ch] & N_RX_FLOW_CONTROL_MASK) {
  3669. dbug(3,dprintf ("XDI CAPI: I: pending N-XON Ch:%02x", Ch));
  3670. }
  3671. a->ch_flow_control[Ch] &= ~N_RX_FLOW_CONTROL_MASK;
  3672. }
  3673. nl_ind(plci);
  3674. if ((e->RNR != 1) &&
  3675. (a->ch_flow_plci[Ch] == plci->Id) &&
  3676. (a->ch_flow_control[Ch] & N_RX_FLOW_CONTROL_MASK)) {
  3677. a->ch_flow_control[Ch] &= ~N_RX_FLOW_CONTROL_MASK;
  3678. dbug(3,dprintf ("XDI CAPI: I: remove faked N-XON Ch:%02x", Ch));
  3679. }
  3680. } else {
  3681. sig_ind(plci);
  3682. }
  3683. e->Ind = 0;
  3684. }
  3685. capi_callback_suffix:
  3686. while (!plci->req_in
  3687. && !plci->internal_command
  3688. && (plci->msg_in_write_pos != plci->msg_in_read_pos))
  3689. {
  3690. j = (plci->msg_in_read_pos == plci->msg_in_wrap_pos) ? 0 : plci->msg_in_read_pos;
  3691. i = (((CAPI_MSG *)(&((byte *)(plci->msg_in_queue))[j]))->header.length + 3) & 0xfffc;
  3692. m = (CAPI_MSG *)(&((byte *)(plci->msg_in_queue))[j]);
  3693. appl = *((APPL * *)(&((byte *)(plci->msg_in_queue))[j+i]));
  3694. dbug(1,dprintf("dequeue msg(0x%04x) - write=%d read=%d wrap=%d",
  3695. m->header.command, plci->msg_in_write_pos, plci->msg_in_read_pos, plci->msg_in_wrap_pos));
  3696. if (plci->msg_in_read_pos == plci->msg_in_wrap_pos)
  3697. {
  3698. plci->msg_in_wrap_pos = MSG_IN_QUEUE_SIZE;
  3699. plci->msg_in_read_pos = i + MSG_IN_OVERHEAD;
  3700. }
  3701. else
  3702. {
  3703. plci->msg_in_read_pos = j + i + MSG_IN_OVERHEAD;
  3704. }
  3705. if (plci->msg_in_read_pos == plci->msg_in_write_pos)
  3706. {
  3707. plci->msg_in_write_pos = MSG_IN_QUEUE_SIZE;
  3708. plci->msg_in_read_pos = MSG_IN_QUEUE_SIZE;
  3709. }
  3710. else if (plci->msg_in_read_pos == plci->msg_in_wrap_pos)
  3711. {
  3712. plci->msg_in_read_pos = MSG_IN_QUEUE_SIZE;
  3713. plci->msg_in_wrap_pos = MSG_IN_QUEUE_SIZE;
  3714. }
  3715. i = api_put (appl, m);
  3716. if (i != 0)
  3717. {
  3718. if (m->header.command == _DATA_B3_R)
  3719. TransmitBufferFree (appl, (byte *)(long)(m->info.data_b3_req.Data));
  3720. dbug(1,dprintf("Error 0x%04x from msg(0x%04x)", i, m->header.command));
  3721. break;
  3722. }
  3723. if (plci->li_notify_update)
  3724. {
  3725. plci->li_notify_update = false;
  3726. mixer_notify_update (plci, false);
  3727. }
  3728. }
  3729. send_data(plci);
  3730. send_req(plci);
  3731. }
  3732. static void control_rc(PLCI *plci, byte req, byte rc, byte ch, byte global_req,
  3733. byte nl_rc)
  3734. {
  3735. dword Id;
  3736. dword rId;
  3737. word Number;
  3738. word Info=0;
  3739. word i;
  3740. word ncci;
  3741. DIVA_CAPI_ADAPTER * a;
  3742. APPL * appl;
  3743. PLCI * rplci;
  3744. byte SSparms[] = "\x05\x00\x00\x02\x00\x00";
  3745. byte SSstruct[] = "\x09\x00\x00\x06\x00\x00\x00\x00\x00\x00";
  3746. if (!plci) {
  3747. dbug(0,dprintf("A: control_rc, no plci %02x:%02x:%02x:%02x:%02x", req, rc, ch, global_req, nl_rc));
  3748. return;
  3749. }
  3750. dbug(1,dprintf("req0_in/out=%d/%d",plci->req_in,plci->req_out));
  3751. if(plci->req_in!=plci->req_out)
  3752. {
  3753. if (nl_rc || (global_req != ASSIGN) || (rc == ASSIGN_OK))
  3754. {
  3755. dbug(1,dprintf("req_1return"));
  3756. return;
  3757. }
  3758. /* cancel outstanding request on the PLCI after SIG ASSIGN failure */
  3759. }
  3760. plci->req_in = plci->req_in_start = plci->req_out = 0;
  3761. dbug(1,dprintf("control_rc"));
  3762. appl = plci->appl;
  3763. a = plci->adapter;
  3764. ncci = a->ch_ncci[ch];
  3765. if(appl)
  3766. {
  3767. Id = (((dword)(ncci ? ncci : ch)) << 16) | ((word)plci->Id << 8) | a->Id;
  3768. if(plci->tel && plci->SuppState!=CALL_HELD) Id|=EXT_CONTROLLER;
  3769. Number = plci->number;
  3770. 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));
  3771. dbug(1,dprintf("channels=0x%x",plci->channels));
  3772. if (plci_remove_check(plci))
  3773. return;
  3774. if(req==REMOVE && rc==ASSIGN_OK)
  3775. {
  3776. sig_req(plci,HANGUP,0);
  3777. sig_req(plci,REMOVE,0);
  3778. send_req(plci);
  3779. }
  3780. if(plci->command)
  3781. {
  3782. switch(plci->command)
  3783. {
  3784. case C_HOLD_REQ:
  3785. dbug(1,dprintf("HoldRC=0x%x",rc));
  3786. SSparms[1] = (byte)S_HOLD;
  3787. if(rc!=OK)
  3788. {
  3789. plci->SuppState = IDLE;
  3790. Info = 0x2001;
  3791. }
  3792. sendf(appl,_FACILITY_R|CONFIRM,Id,Number,"wws",Info,3,SSparms);
  3793. break;
  3794. case C_RETRIEVE_REQ:
  3795. dbug(1,dprintf("RetrieveRC=0x%x",rc));
  3796. SSparms[1] = (byte)S_RETRIEVE;
  3797. if(rc!=OK)
  3798. {
  3799. plci->SuppState = CALL_HELD;
  3800. Info = 0x2001;
  3801. }
  3802. sendf(appl,_FACILITY_R|CONFIRM,Id,Number,"wws",Info,3,SSparms);
  3803. break;
  3804. case _INFO_R:
  3805. dbug(1,dprintf("InfoRC=0x%x",rc));
  3806. if(rc!=OK) Info=_WRONG_STATE;
  3807. sendf(appl,_INFO_R|CONFIRM,Id,Number,"w",Info);
  3808. break;
  3809. case _CONNECT_R:
  3810. dbug(1,dprintf("Connect_R=0x%x/0x%x/0x%x/0x%x",req,rc,global_req,nl_rc));
  3811. if (plci->State == INC_DIS_PENDING)
  3812. break;
  3813. if(plci->Sig.Id!=0xff)
  3814. {
  3815. if (((global_req == ASSIGN) && (rc != ASSIGN_OK))
  3816. || (!nl_rc && (req == CALL_REQ) && (rc != OK)))
  3817. {
  3818. dbug(1,dprintf("No more IDs/Call_Req failed"));
  3819. sendf(appl,_CONNECT_R|CONFIRM,Id&0xffL,Number,"w",_OUT_OF_PLCI);
  3820. plci_remove(plci);
  3821. plci->State = IDLE;
  3822. break;
  3823. }
  3824. if(plci->State!=LOCAL_CONNECT)plci->State = OUTG_CON_PENDING;
  3825. sendf(appl,_CONNECT_R|CONFIRM,Id,Number,"w",0);
  3826. }
  3827. else /* D-ch activation */
  3828. {
  3829. if (rc != ASSIGN_OK)
  3830. {
  3831. dbug(1,dprintf("No more IDs/X.25 Call_Req failed"));
  3832. sendf(appl,_CONNECT_R|CONFIRM,Id&0xffL,Number,"w",_OUT_OF_PLCI);
  3833. plci_remove(plci);
  3834. plci->State = IDLE;
  3835. break;
  3836. }
  3837. sendf(appl,_CONNECT_R|CONFIRM,Id,Number,"w",0);
  3838. sendf(plci->appl,_CONNECT_ACTIVE_I,Id,0,"sss","","","");
  3839. plci->State = INC_ACT_PENDING;
  3840. }
  3841. break;
  3842. case _CONNECT_I|RESPONSE:
  3843. if (plci->State != INC_DIS_PENDING)
  3844. plci->State = INC_CON_ACCEPT;
  3845. break;
  3846. case _DISCONNECT_R:
  3847. if (plci->State == INC_DIS_PENDING)
  3848. break;
  3849. if(plci->Sig.Id!=0xff)
  3850. {
  3851. plci->State = OUTG_DIS_PENDING;
  3852. sendf(appl,_DISCONNECT_R|CONFIRM,Id,Number,"w",0);
  3853. }
  3854. break;
  3855. case SUSPEND_REQ:
  3856. break;
  3857. case RESUME_REQ:
  3858. break;
  3859. case _CONNECT_B3_R:
  3860. if(rc!=OK)
  3861. {
  3862. sendf(appl,_CONNECT_B3_R|CONFIRM,Id,Number,"w",_WRONG_IDENTIFIER);
  3863. break;
  3864. }
  3865. ncci = get_ncci (plci, ch, 0);
  3866. Id = (Id & 0xffff) | (((dword) ncci) << 16);
  3867. plci->channels++;
  3868. if(req==N_RESET)
  3869. {
  3870. a->ncci_state[ncci] = INC_ACT_PENDING;
  3871. sendf(appl,_CONNECT_B3_R|CONFIRM,Id,Number,"w",0);
  3872. sendf(appl,_CONNECT_B3_ACTIVE_I,Id,0,"s","");
  3873. }
  3874. else
  3875. {
  3876. a->ncci_state[ncci] = OUTG_CON_PENDING;
  3877. sendf(appl,_CONNECT_B3_R|CONFIRM,Id,Number,"w",0);
  3878. }
  3879. break;
  3880. case _CONNECT_B3_I|RESPONSE:
  3881. break;
  3882. case _RESET_B3_R:
  3883. /* sendf(appl,_RESET_B3_R|CONFIRM,Id,Number,"w",0);*/
  3884. break;
  3885. case _DISCONNECT_B3_R:
  3886. sendf(appl,_DISCONNECT_B3_R|CONFIRM,Id,Number,"w",0);
  3887. break;
  3888. case _MANUFACTURER_R:
  3889. break;
  3890. case PERM_LIST_REQ:
  3891. if(rc!=OK)
  3892. {
  3893. Info = _WRONG_IDENTIFIER;
  3894. sendf(plci->appl,_CONNECT_R|CONFIRM,Id,Number,"w",Info);
  3895. plci_remove(plci);
  3896. }
  3897. else
  3898. sendf(plci->appl,_CONNECT_R|CONFIRM,Id,Number,"w",Info);
  3899. break;
  3900. default:
  3901. break;
  3902. }
  3903. plci->command = 0;
  3904. }
  3905. else if (plci->internal_command)
  3906. {
  3907. switch(plci->internal_command)
  3908. {
  3909. case BLOCK_PLCI:
  3910. return;
  3911. case GET_MWI_STATE:
  3912. if(rc==OK) /* command supported, wait for indication */
  3913. {
  3914. return;
  3915. }
  3916. plci_remove(plci);
  3917. break;
  3918. /* Get Supported Services */
  3919. case GETSERV_REQ_PEND:
  3920. if(rc==OK) /* command supported, wait for indication */
  3921. {
  3922. break;
  3923. }
  3924. PUT_DWORD(&SSstruct[6], MASK_TERMINAL_PORTABILITY);
  3925. sendf(appl, _FACILITY_R|CONFIRM, Id, Number, "wws",0,3,SSstruct);
  3926. plci_remove(plci);
  3927. break;
  3928. case INTERR_DIVERSION_REQ_PEND: /* Interrogate Parameters */
  3929. case INTERR_NUMBERS_REQ_PEND:
  3930. case CF_START_PEND: /* Call Forwarding Start pending */
  3931. case CF_STOP_PEND: /* Call Forwarding Stop pending */
  3932. case CCBS_REQUEST_REQ_PEND:
  3933. case CCBS_DEACTIVATE_REQ_PEND:
  3934. case CCBS_INTERROGATE_REQ_PEND:
  3935. switch(plci->internal_command)
  3936. {
  3937. case INTERR_DIVERSION_REQ_PEND:
  3938. SSparms[1] = S_INTERROGATE_DIVERSION;
  3939. break;
  3940. case INTERR_NUMBERS_REQ_PEND:
  3941. SSparms[1] = S_INTERROGATE_NUMBERS;
  3942. break;
  3943. case CF_START_PEND:
  3944. SSparms[1] = S_CALL_FORWARDING_START;
  3945. break;
  3946. case CF_STOP_PEND:
  3947. SSparms[1] = S_CALL_FORWARDING_STOP;
  3948. break;
  3949. case CCBS_REQUEST_REQ_PEND:
  3950. SSparms[1] = S_CCBS_REQUEST;
  3951. break;
  3952. case CCBS_DEACTIVATE_REQ_PEND:
  3953. SSparms[1] = S_CCBS_DEACTIVATE;
  3954. break;
  3955. case CCBS_INTERROGATE_REQ_PEND:
  3956. SSparms[1] = S_CCBS_INTERROGATE;
  3957. break;
  3958. }
  3959. if(global_req==ASSIGN)
  3960. {
  3961. dbug(1,dprintf("AssignDiversion_RC=0x%x/0x%x",req,rc));
  3962. return;
  3963. }
  3964. if(!plci->appl) break;
  3965. if(rc==ISDN_GUARD_REJ)
  3966. {
  3967. Info = _CAPI_GUARD_ERROR;
  3968. }
  3969. else if(rc!=OK)
  3970. {
  3971. Info = _SUPPLEMENTARY_SERVICE_NOT_SUPPORTED;
  3972. }
  3973. sendf(plci->appl,_FACILITY_R|CONFIRM,Id&0x7,
  3974. plci->number,"wws",Info,(word)3,SSparms);
  3975. if(Info) plci_remove(plci);
  3976. break;
  3977. /* 3pty conference pending */
  3978. case PTY_REQ_PEND:
  3979. if(!plci->relatedPTYPLCI) break;
  3980. rplci = plci->relatedPTYPLCI;
  3981. SSparms[1] = plci->ptyState;
  3982. rId = ((word)rplci->Id<<8)|rplci->adapter->Id;
  3983. if(rplci->tel) rId|=EXT_CONTROLLER;
  3984. if(rc!=OK)
  3985. {
  3986. Info = 0x300E; /* not supported */
  3987. plci->relatedPTYPLCI = NULL;
  3988. plci->ptyState = 0;
  3989. }
  3990. sendf(rplci->appl,
  3991. _FACILITY_R|CONFIRM,
  3992. rId,
  3993. plci->number,
  3994. "wws",Info,(word)3,SSparms);
  3995. break;
  3996. /* Explicit Call Transfer pending */
  3997. case ECT_REQ_PEND:
  3998. dbug(1,dprintf("ECT_RC=0x%x/0x%x",req,rc));
  3999. if(!plci->relatedPTYPLCI) break;
  4000. rplci = plci->relatedPTYPLCI;
  4001. SSparms[1] = S_ECT;
  4002. rId = ((word)rplci->Id<<8)|rplci->adapter->Id;
  4003. if(rplci->tel) rId|=EXT_CONTROLLER;
  4004. if(rc!=OK)
  4005. {
  4006. Info = 0x300E; /* not supported */
  4007. plci->relatedPTYPLCI = NULL;
  4008. plci->ptyState = 0;
  4009. }
  4010. sendf(rplci->appl,
  4011. _FACILITY_R|CONFIRM,
  4012. rId,
  4013. plci->number,
  4014. "wws",Info,(word)3,SSparms);
  4015. break;
  4016. case _MANUFACTURER_R:
  4017. dbug(1,dprintf("_Manufacturer_R=0x%x/0x%x",req,rc));
  4018. if ((global_req == ASSIGN) && (rc != ASSIGN_OK))
  4019. {
  4020. dbug(1,dprintf("No more IDs"));
  4021. sendf(appl,_MANUFACTURER_R|CONFIRM,Id,Number,"dww",_DI_MANU_ID,_MANUFACTURER_R,_OUT_OF_PLCI);
  4022. plci_remove(plci); /* after codec init, internal codec commands pending */
  4023. }
  4024. break;
  4025. case _CONNECT_R:
  4026. dbug(1,dprintf("_Connect_R=0x%x/0x%x",req,rc));
  4027. if ((global_req == ASSIGN) && (rc != ASSIGN_OK))
  4028. {
  4029. dbug(1,dprintf("No more IDs"));
  4030. sendf(appl,_CONNECT_R|CONFIRM,Id&0xffL,Number,"w",_OUT_OF_PLCI);
  4031. plci_remove(plci); /* after codec init, internal codec commands pending */
  4032. }
  4033. break;
  4034. case PERM_COD_HOOK: /* finished with Hook_Ind */
  4035. return;
  4036. case PERM_COD_CALL:
  4037. dbug(1,dprintf("***Codec Connect_Pending A, Rc = 0x%x",rc));
  4038. plci->internal_command = PERM_COD_CONN_PEND;
  4039. return;
  4040. case PERM_COD_ASSIGN:
  4041. dbug(1,dprintf("***Codec Assign A, Rc = 0x%x",rc));
  4042. if(rc!=ASSIGN_OK) break;
  4043. sig_req(plci,CALL_REQ,0);
  4044. send_req(plci);
  4045. plci->internal_command = PERM_COD_CALL;
  4046. return;
  4047. /* Null Call Reference Request pending */
  4048. case C_NCR_FAC_REQ:
  4049. dbug(1,dprintf("NCR_FAC=0x%x/0x%x",req,rc));
  4050. if(global_req==ASSIGN)
  4051. {
  4052. if(rc==ASSIGN_OK)
  4053. {
  4054. return;
  4055. }
  4056. else
  4057. {
  4058. sendf(appl,_INFO_R|CONFIRM,Id&0xf,Number,"w",_WRONG_STATE);
  4059. appl->NullCREnable = false;
  4060. plci_remove(plci);
  4061. }
  4062. }
  4063. else if(req==NCR_FACILITY)
  4064. {
  4065. if(rc==OK)
  4066. {
  4067. sendf(appl,_INFO_R|CONFIRM,Id&0xf,Number,"w",0);
  4068. }
  4069. else
  4070. {
  4071. sendf(appl,_INFO_R|CONFIRM,Id&0xf,Number,"w",_WRONG_STATE);
  4072. appl->NullCREnable = false;
  4073. }
  4074. plci_remove(plci);
  4075. }
  4076. break;
  4077. case HOOK_ON_REQ:
  4078. if(plci->channels)
  4079. {
  4080. if(a->ncci_state[ncci]==CONNECTED)
  4081. {
  4082. a->ncci_state[ncci] = OUTG_DIS_PENDING;
  4083. cleanup_ncci_data (plci, ncci);
  4084. nl_req_ncci(plci,N_DISC,(byte)ncci);
  4085. }
  4086. break;
  4087. }
  4088. break;
  4089. case HOOK_OFF_REQ:
  4090. if (plci->State == INC_DIS_PENDING)
  4091. break;
  4092. sig_req(plci,CALL_REQ,0);
  4093. send_req(plci);
  4094. plci->State=OUTG_CON_PENDING;
  4095. break;
  4096. case MWI_ACTIVATE_REQ_PEND:
  4097. case MWI_DEACTIVATE_REQ_PEND:
  4098. if(global_req == ASSIGN && rc==ASSIGN_OK)
  4099. {
  4100. dbug(1,dprintf("MWI_REQ assigned"));
  4101. return;
  4102. }
  4103. else if(rc!=OK)
  4104. {
  4105. if(rc==WRONG_IE)
  4106. {
  4107. Info = 0x2007; /* Illegal message parameter coding */
  4108. dbug(1,dprintf("MWI_REQ invalid parameter"));
  4109. }
  4110. else
  4111. {
  4112. Info = 0x300B; /* not supported */
  4113. dbug(1,dprintf("MWI_REQ not supported"));
  4114. }
  4115. /* 0x3010: Request not allowed in this state */
  4116. PUT_WORD(&SSparms[4],0x300E); /* SS not supported */
  4117. }
  4118. if(plci->internal_command==MWI_ACTIVATE_REQ_PEND)
  4119. {
  4120. PUT_WORD(&SSparms[1],S_MWI_ACTIVATE);
  4121. }
  4122. else PUT_WORD(&SSparms[1],S_MWI_DEACTIVATE);
  4123. if(plci->cr_enquiry)
  4124. {
  4125. sendf(plci->appl,
  4126. _FACILITY_R|CONFIRM,
  4127. Id&0xf,
  4128. plci->number,
  4129. "wws",Info,(word)3,SSparms);
  4130. if(rc!=OK) plci_remove(plci);
  4131. }
  4132. else
  4133. {
  4134. sendf(plci->appl,
  4135. _FACILITY_R|CONFIRM,
  4136. Id,
  4137. plci->number,
  4138. "wws",Info,(word)3,SSparms);
  4139. }
  4140. break;
  4141. case CONF_BEGIN_REQ_PEND:
  4142. case CONF_ADD_REQ_PEND:
  4143. case CONF_SPLIT_REQ_PEND:
  4144. case CONF_DROP_REQ_PEND:
  4145. case CONF_ISOLATE_REQ_PEND:
  4146. case CONF_REATTACH_REQ_PEND:
  4147. dbug(1,dprintf("CONF_RC=0x%x/0x%x",req,rc));
  4148. if((plci->internal_command==CONF_ADD_REQ_PEND)&&(!plci->relatedPTYPLCI)) break;
  4149. rplci = plci;
  4150. rId = Id;
  4151. switch(plci->internal_command)
  4152. {
  4153. case CONF_BEGIN_REQ_PEND:
  4154. SSparms[1] = S_CONF_BEGIN;
  4155. break;
  4156. case CONF_ADD_REQ_PEND:
  4157. SSparms[1] = S_CONF_ADD;
  4158. rplci = plci->relatedPTYPLCI;
  4159. rId = ((word)rplci->Id<<8)|rplci->adapter->Id;
  4160. break;
  4161. case CONF_SPLIT_REQ_PEND:
  4162. SSparms[1] = S_CONF_SPLIT;
  4163. break;
  4164. case CONF_DROP_REQ_PEND:
  4165. SSparms[1] = S_CONF_DROP;
  4166. break;
  4167. case CONF_ISOLATE_REQ_PEND:
  4168. SSparms[1] = S_CONF_ISOLATE;
  4169. break;
  4170. case CONF_REATTACH_REQ_PEND:
  4171. SSparms[1] = S_CONF_REATTACH;
  4172. break;
  4173. }
  4174. if(rc!=OK)
  4175. {
  4176. Info = 0x300E; /* not supported */
  4177. plci->relatedPTYPLCI = NULL;
  4178. plci->ptyState = 0;
  4179. }
  4180. sendf(rplci->appl,
  4181. _FACILITY_R|CONFIRM,
  4182. rId,
  4183. plci->number,
  4184. "wws",Info,(word)3,SSparms);
  4185. break;
  4186. case VSWITCH_REQ_PEND:
  4187. if(rc!=OK)
  4188. {
  4189. if(plci->relatedPTYPLCI)
  4190. {
  4191. plci->relatedPTYPLCI->vswitchstate=0;
  4192. plci->relatedPTYPLCI->vsprot=0;
  4193. plci->relatedPTYPLCI->vsprotdialect=0;
  4194. }
  4195. plci->vswitchstate=0;
  4196. plci->vsprot=0;
  4197. plci->vsprotdialect=0;
  4198. }
  4199. else
  4200. {
  4201. if(plci->relatedPTYPLCI &&
  4202. plci->vswitchstate==1 &&
  4203. plci->relatedPTYPLCI->vswitchstate==3) /* join complete */
  4204. plci->vswitchstate=3;
  4205. }
  4206. break;
  4207. /* Call Deflection Request pending (SSCT) */
  4208. case CD_REQ_PEND:
  4209. SSparms[1] = S_CALL_DEFLECTION;
  4210. if(rc!=OK)
  4211. {
  4212. Info = 0x300E; /* not supported */
  4213. plci->appl->CDEnable = 0;
  4214. }
  4215. sendf(plci->appl,_FACILITY_R|CONFIRM,Id,
  4216. plci->number,"wws",Info,(word)3,SSparms);
  4217. break;
  4218. case RTP_CONNECT_B3_REQ_COMMAND_2:
  4219. if (rc == OK)
  4220. {
  4221. ncci = get_ncci (plci, ch, 0);
  4222. Id = (Id & 0xffff) | (((dword) ncci) << 16);
  4223. plci->channels++;
  4224. a->ncci_state[ncci] = OUTG_CON_PENDING;
  4225. }
  4226. default:
  4227. if (plci->internal_command_queue[0])
  4228. {
  4229. (*(plci->internal_command_queue[0]))(Id, plci, rc);
  4230. if (plci->internal_command)
  4231. return;
  4232. }
  4233. break;
  4234. }
  4235. next_internal_command (Id, plci);
  4236. }
  4237. }
  4238. else /* appl==0 */
  4239. {
  4240. Id = ((word)plci->Id<<8)|plci->adapter->Id;
  4241. if(plci->tel) Id|=EXT_CONTROLLER;
  4242. switch(plci->internal_command)
  4243. {
  4244. case BLOCK_PLCI:
  4245. return;
  4246. case START_L1_SIG_ASSIGN_PEND:
  4247. case REM_L1_SIG_ASSIGN_PEND:
  4248. if(global_req == ASSIGN)
  4249. {
  4250. break;
  4251. }
  4252. else
  4253. {
  4254. dbug(1,dprintf("***L1 Req rem PLCI"));
  4255. plci->internal_command = 0;
  4256. sig_req(plci,REMOVE,0);
  4257. send_req(plci);
  4258. }
  4259. break;
  4260. /* Call Deflection Request pending, just no appl ptr assigned */
  4261. case CD_REQ_PEND:
  4262. SSparms[1] = S_CALL_DEFLECTION;
  4263. if(rc!=OK)
  4264. {
  4265. Info = 0x300E; /* not supported */
  4266. }
  4267. for(i=0; i<max_appl; i++)
  4268. {
  4269. if(application[i].CDEnable)
  4270. {
  4271. if(!application[i].Id) application[i].CDEnable = 0;
  4272. else
  4273. {
  4274. sendf(&application[i],_FACILITY_R|CONFIRM,Id,
  4275. plci->number,"wws",Info,(word)3,SSparms);
  4276. if(Info) application[i].CDEnable = 0;
  4277. }
  4278. }
  4279. }
  4280. plci->internal_command = 0;
  4281. break;
  4282. case PERM_COD_HOOK: /* finished with Hook_Ind */
  4283. return;
  4284. case PERM_COD_CALL:
  4285. plci->internal_command = PERM_COD_CONN_PEND;
  4286. dbug(1,dprintf("***Codec Connect_Pending, Rc = 0x%x",rc));
  4287. return;
  4288. case PERM_COD_ASSIGN:
  4289. dbug(1,dprintf("***Codec Assign, Rc = 0x%x",rc));
  4290. plci->internal_command = 0;
  4291. if(rc!=ASSIGN_OK) break;
  4292. plci->internal_command = PERM_COD_CALL;
  4293. sig_req(plci,CALL_REQ,0);
  4294. send_req(plci);
  4295. return;
  4296. case LISTEN_SIG_ASSIGN_PEND:
  4297. if(rc == ASSIGN_OK)
  4298. {
  4299. plci->internal_command = 0;
  4300. dbug(1,dprintf("ListenCheck, new SIG_ID = 0x%x",plci->Sig.Id));
  4301. add_p(plci,ESC,"\x02\x18\x00"); /* support call waiting */
  4302. sig_req(plci,INDICATE_REQ,0);
  4303. send_req(plci);
  4304. }
  4305. else
  4306. {
  4307. dbug(1,dprintf("ListenCheck failed (assignRc=0x%x)",rc));
  4308. a->listen_active--;
  4309. plci_remove(plci);
  4310. plci->State = IDLE;
  4311. }
  4312. break;
  4313. case USELAW_REQ:
  4314. if(global_req == ASSIGN)
  4315. {
  4316. if (rc==ASSIGN_OK)
  4317. {
  4318. sig_req(plci,LAW_REQ,0);
  4319. send_req(plci);
  4320. dbug(1,dprintf("Auto-Law assigned"));
  4321. }
  4322. else
  4323. {
  4324. dbug(1,dprintf("Auto-Law assign failed"));
  4325. a->automatic_law = 3;
  4326. plci->internal_command = 0;
  4327. a->automatic_lawPLCI = NULL;
  4328. }
  4329. break;
  4330. }
  4331. else if(req == LAW_REQ && rc==OK)
  4332. {
  4333. dbug(1,dprintf("Auto-Law initiated"));
  4334. a->automatic_law = 2;
  4335. plci->internal_command = 0;
  4336. }
  4337. else
  4338. {
  4339. dbug(1,dprintf("Auto-Law not supported"));
  4340. a->automatic_law = 3;
  4341. plci->internal_command = 0;
  4342. sig_req(plci,REMOVE,0);
  4343. send_req(plci);
  4344. a->automatic_lawPLCI = NULL;
  4345. }
  4346. break;
  4347. }
  4348. plci_remove_check(plci);
  4349. }
  4350. }
  4351. static void data_rc(PLCI *plci, byte ch)
  4352. {
  4353. dword Id;
  4354. DIVA_CAPI_ADAPTER * a;
  4355. NCCI *ncci_ptr;
  4356. DATA_B3_DESC *data;
  4357. word ncci;
  4358. if (plci->appl)
  4359. {
  4360. TransmitBufferFree (plci->appl, plci->data_sent_ptr);
  4361. a = plci->adapter;
  4362. ncci = a->ch_ncci[ch];
  4363. if (ncci && (a->ncci_plci[ncci] == plci->Id))
  4364. {
  4365. ncci_ptr = &(a->ncci[ncci]);
  4366. dbug(1,dprintf("data_out=%d, data_pending=%d",ncci_ptr->data_out,ncci_ptr->data_pending));
  4367. if (ncci_ptr->data_pending)
  4368. {
  4369. data = &(ncci_ptr->DBuffer[ncci_ptr->data_out]);
  4370. if (!(data->Flags &4) && a->ncci_state[ncci])
  4371. {
  4372. Id = (((dword)ncci)<<16)|((word)plci->Id<<8)|a->Id;
  4373. if(plci->tel) Id|=EXT_CONTROLLER;
  4374. sendf(plci->appl,_DATA_B3_R|CONFIRM,Id,data->Number,
  4375. "ww",data->Handle,0);
  4376. }
  4377. (ncci_ptr->data_out)++;
  4378. if (ncci_ptr->data_out == MAX_DATA_B3)
  4379. ncci_ptr->data_out = 0;
  4380. (ncci_ptr->data_pending)--;
  4381. }
  4382. }
  4383. }
  4384. }
  4385. static void data_ack(PLCI *plci, byte ch)
  4386. {
  4387. dword Id;
  4388. DIVA_CAPI_ADAPTER * a;
  4389. NCCI *ncci_ptr;
  4390. word ncci;
  4391. a = plci->adapter;
  4392. ncci = a->ch_ncci[ch];
  4393. ncci_ptr = &(a->ncci[ncci]);
  4394. if (ncci_ptr->data_ack_pending)
  4395. {
  4396. if (a->ncci_state[ncci] && (a->ncci_plci[ncci] == plci->Id))
  4397. {
  4398. Id = (((dword)ncci)<<16)|((word)plci->Id<<8)|a->Id;
  4399. if(plci->tel) Id|=EXT_CONTROLLER;
  4400. sendf(plci->appl,_DATA_B3_R|CONFIRM,Id,ncci_ptr->DataAck[ncci_ptr->data_ack_out].Number,
  4401. "ww",ncci_ptr->DataAck[ncci_ptr->data_ack_out].Handle,0);
  4402. }
  4403. (ncci_ptr->data_ack_out)++;
  4404. if (ncci_ptr->data_ack_out == MAX_DATA_ACK)
  4405. ncci_ptr->data_ack_out = 0;
  4406. (ncci_ptr->data_ack_pending)--;
  4407. }
  4408. }
  4409. static void sig_ind(PLCI *plci)
  4410. {
  4411. dword x_Id;
  4412. dword Id;
  4413. dword rId;
  4414. word Number = 0;
  4415. word i;
  4416. word cip;
  4417. dword cip_mask;
  4418. byte *ie;
  4419. DIVA_CAPI_ADAPTER * a;
  4420. API_PARSE saved_parms[MAX_MSG_PARMS+1];
  4421. #define MAXPARMSIDS 31
  4422. byte * parms[MAXPARMSIDS];
  4423. byte * add_i[4];
  4424. byte * multi_fac_parms[MAX_MULTI_IE];
  4425. byte * multi_pi_parms [MAX_MULTI_IE];
  4426. byte * multi_ssext_parms [MAX_MULTI_IE];
  4427. byte * multi_CiPN_parms [MAX_MULTI_IE];
  4428. byte * multi_vswitch_parms [MAX_MULTI_IE];
  4429. byte ai_len;
  4430. byte *esc_chi = "";
  4431. byte *esc_law = "";
  4432. byte *pty_cai = "";
  4433. byte *esc_cr = "";
  4434. byte *esc_profile = "";
  4435. byte facility[256];
  4436. PLCI * tplci = NULL;
  4437. byte chi[] = "\x02\x18\x01";
  4438. byte voice_cai[] = "\x06\x14\x00\x00\x00\x00\x08";
  4439. byte resume_cau[] = "\x05\x05\x00\x02\x00\x00";
  4440. /* ESC_MSGTYPE must be the last but one message, a new IE has to be */
  4441. /* included before the ESC_MSGTYPE and MAXPARMSIDS has to be incremented */
  4442. /* SMSG is situated at the end because its 0 (for compatibility reasons */
  4443. /* (see Info_Mask Bit 4, first IE. then the message type) */
  4444. word parms_id[] =
  4445. {MAXPARMSIDS, CPN, 0xff, DSA, OSA, BC, LLC, HLC, ESC_CAUSE, DSP, DT, CHA,
  4446. UUI, CONG_RR, CONG_RNR, ESC_CHI, KEY, CHI, CAU, ESC_LAW,
  4447. RDN, RDX, CONN_NR, RIN, NI, CAI, ESC_CR,
  4448. CST, ESC_PROFILE, 0xff, ESC_MSGTYPE, SMSG};
  4449. /* 14 FTY repl by ESC_CHI */
  4450. /* 18 PI repl by ESC_LAW */
  4451. /* removed OAD changed to 0xff for future use, OAD is multiIE now */
  4452. word multi_fac_id[] = {1, FTY};
  4453. word multi_pi_id[] = {1, PI};
  4454. word multi_CiPN_id[] = {1, OAD};
  4455. word multi_ssext_id[] = {1, ESC_SSEXT};
  4456. word multi_vswitch_id[] = {1, ESC_VSWITCH};
  4457. byte * cau;
  4458. word ncci;
  4459. byte SS_Ind[] = "\x05\x02\x00\x02\x00\x00"; /* Hold_Ind struct*/
  4460. byte CF_Ind[] = "\x09\x02\x00\x06\x00\x00\x00\x00\x00\x00";
  4461. byte Interr_Err_Ind[] = "\x0a\x02\x00\x07\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00";
  4462. byte CONF_Ind[] = "\x09\x16\x00\x06\x00\x00\0x00\0x00\0x00\0x00";
  4463. byte force_mt_info = false;
  4464. byte dir;
  4465. dword d;
  4466. word w;
  4467. a = plci->adapter;
  4468. Id = ((word)plci->Id<<8)|a->Id;
  4469. PUT_WORD(&SS_Ind[4],0x0000);
  4470. if (plci->sig_remove_id)
  4471. {
  4472. plci->Sig.RNR = 2; /* discard */
  4473. dbug(1,dprintf("SIG discard while remove pending"));
  4474. return;
  4475. }
  4476. if(plci->tel && plci->SuppState!=CALL_HELD) Id|=EXT_CONTROLLER;
  4477. dbug(1,dprintf("SigInd-Id=%08lx,plci=%x,tel=%x,state=0x%x,channels=%d,Discflowcl=%d",
  4478. Id,plci->Id,plci->tel,plci->State,plci->channels,plci->hangup_flow_ctrl_timer));
  4479. if(plci->Sig.Ind==CALL_HOLD_ACK && plci->channels)
  4480. {
  4481. plci->Sig.RNR = 1;
  4482. return;
  4483. }
  4484. if(plci->Sig.Ind==HANGUP && plci->channels)
  4485. {
  4486. plci->Sig.RNR = 1;
  4487. plci->hangup_flow_ctrl_timer++;
  4488. /* recover the network layer after timeout */
  4489. if(plci->hangup_flow_ctrl_timer==100)
  4490. {
  4491. dbug(1,dprintf("Exceptional disc"));
  4492. plci->Sig.RNR = 0;
  4493. plci->hangup_flow_ctrl_timer = 0;
  4494. for (ncci = 1; ncci < MAX_NCCI+1; ncci++)
  4495. {
  4496. if (a->ncci_plci[ncci] == plci->Id)
  4497. {
  4498. cleanup_ncci_data (plci, ncci);
  4499. if(plci->channels)plci->channels--;
  4500. if (plci->appl)
  4501. sendf(plci->appl,_DISCONNECT_B3_I, (((dword) ncci) << 16) | Id,0,"ws",0,"");
  4502. }
  4503. }
  4504. if (plci->appl)
  4505. sendf(plci->appl, _DISCONNECT_I, Id, 0, "w", 0);
  4506. plci_remove(plci);
  4507. plci->State=IDLE;
  4508. }
  4509. return;
  4510. }
  4511. /* do first parse the info with no OAD in, because OAD will be converted */
  4512. /* first the multiple facility IE, then mult. progress ind. */
  4513. /* then the parameters for the info_ind + conn_ind */
  4514. IndParse(plci,multi_fac_id,multi_fac_parms,MAX_MULTI_IE);
  4515. IndParse(plci,multi_pi_id,multi_pi_parms,MAX_MULTI_IE);
  4516. IndParse(plci,multi_ssext_id,multi_ssext_parms,MAX_MULTI_IE);
  4517. IndParse(plci,multi_vswitch_id,multi_vswitch_parms,MAX_MULTI_IE);
  4518. IndParse(plci,parms_id,parms,0);
  4519. IndParse(plci,multi_CiPN_id,multi_CiPN_parms,MAX_MULTI_IE);
  4520. esc_chi = parms[14];
  4521. esc_law = parms[18];
  4522. pty_cai = parms[24];
  4523. esc_cr = parms[25];
  4524. esc_profile = parms[27];
  4525. if(esc_cr[0] && plci)
  4526. {
  4527. if(plci->cr_enquiry && plci->appl)
  4528. {
  4529. plci->cr_enquiry = false;
  4530. /* d = MANU_ID */
  4531. /* w = m_command */
  4532. /* b = total length */
  4533. /* b = indication type */
  4534. /* b = length of all IEs */
  4535. /* b = IE1 */
  4536. /* S = IE1 length + cont. */
  4537. /* b = IE2 */
  4538. /* S = IE2 length + cont. */
  4539. sendf(plci->appl,
  4540. _MANUFACTURER_I,
  4541. Id,
  4542. 0,
  4543. "dwbbbbSbS",_DI_MANU_ID,plci->m_command,
  4544. 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);
  4545. }
  4546. }
  4547. /* create the additional info structure */
  4548. add_i[1] = parms[15]; /* KEY of additional info */
  4549. add_i[2] = parms[11]; /* UUI of additional info */
  4550. ai_len = AddInfo(add_i,multi_fac_parms, esc_chi, facility);
  4551. /* the ESC_LAW indicates if u-Law or a-Law is actually used by the card */
  4552. /* indication returns by the card if requested by the function */
  4553. /* AutomaticLaw() after driver init */
  4554. if (a->automatic_law<4)
  4555. {
  4556. if(esc_law[0]){
  4557. if(esc_law[2]){
  4558. dbug(0,dprintf("u-Law selected"));
  4559. a->u_law = 1;
  4560. }
  4561. else {
  4562. dbug(0,dprintf("a-Law selected"));
  4563. a->u_law = 0;
  4564. }
  4565. a->automatic_law = 4;
  4566. if(plci==a->automatic_lawPLCI) {
  4567. plci->internal_command = 0;
  4568. sig_req(plci,REMOVE,0);
  4569. send_req(plci);
  4570. a->automatic_lawPLCI = NULL;
  4571. }
  4572. }
  4573. if (esc_profile[0])
  4574. {
  4575. dbug (1, dprintf ("[%06x] CardProfile: %lx %lx %lx %lx %lx",
  4576. UnMapController (a->Id), GET_DWORD (&esc_profile[6]),
  4577. GET_DWORD (&esc_profile[10]), GET_DWORD (&esc_profile[14]),
  4578. GET_DWORD (&esc_profile[18]), GET_DWORD (&esc_profile[46])));
  4579. a->profile.Global_Options &= 0x000000ffL;
  4580. a->profile.B1_Protocols &= 0x000003ffL;
  4581. a->profile.B2_Protocols &= 0x00001fdfL;
  4582. a->profile.B3_Protocols &= 0x000000b7L;
  4583. a->profile.Global_Options &= GET_DWORD (&esc_profile[6]) |
  4584. GL_BCHANNEL_OPERATION_SUPPORTED;
  4585. a->profile.B1_Protocols &= GET_DWORD (&esc_profile[10]);
  4586. a->profile.B2_Protocols &= GET_DWORD (&esc_profile[14]);
  4587. a->profile.B3_Protocols &= GET_DWORD (&esc_profile[18]);
  4588. a->manufacturer_features = GET_DWORD (&esc_profile[46]);
  4589. a->man_profile.private_options = 0;
  4590. if (a->manufacturer_features & MANUFACTURER_FEATURE_ECHO_CANCELLER)
  4591. {
  4592. a->man_profile.private_options |= 1L << PRIVATE_ECHO_CANCELLER;
  4593. a->profile.Global_Options |= GL_ECHO_CANCELLER_SUPPORTED;
  4594. }
  4595. if (a->manufacturer_features & MANUFACTURER_FEATURE_RTP)
  4596. a->man_profile.private_options |= 1L << PRIVATE_RTP;
  4597. a->man_profile.rtp_primary_payloads = GET_DWORD (&esc_profile[50]);
  4598. a->man_profile.rtp_additional_payloads = GET_DWORD (&esc_profile[54]);
  4599. if (a->manufacturer_features & MANUFACTURER_FEATURE_T38)
  4600. a->man_profile.private_options |= 1L << PRIVATE_T38;
  4601. if (a->manufacturer_features & MANUFACTURER_FEATURE_FAX_SUB_SEP_PWD)
  4602. a->man_profile.private_options |= 1L << PRIVATE_FAX_SUB_SEP_PWD;
  4603. if (a->manufacturer_features & MANUFACTURER_FEATURE_V18)
  4604. a->man_profile.private_options |= 1L << PRIVATE_V18;
  4605. if (a->manufacturer_features & MANUFACTURER_FEATURE_DTMF_TONE)
  4606. a->man_profile.private_options |= 1L << PRIVATE_DTMF_TONE;
  4607. if (a->manufacturer_features & MANUFACTURER_FEATURE_PIAFS)
  4608. a->man_profile.private_options |= 1L << PRIVATE_PIAFS;
  4609. if (a->manufacturer_features & MANUFACTURER_FEATURE_FAX_PAPER_FORMATS)
  4610. a->man_profile.private_options |= 1L << PRIVATE_FAX_PAPER_FORMATS;
  4611. if (a->manufacturer_features & MANUFACTURER_FEATURE_VOWN)
  4612. a->man_profile.private_options |= 1L << PRIVATE_VOWN;
  4613. if (a->manufacturer_features & MANUFACTURER_FEATURE_FAX_NONSTANDARD)
  4614. a->man_profile.private_options |= 1L << PRIVATE_FAX_NONSTANDARD;
  4615. }
  4616. else
  4617. {
  4618. a->profile.Global_Options &= 0x0000007fL;
  4619. a->profile.B1_Protocols &= 0x000003dfL;
  4620. a->profile.B2_Protocols &= 0x00001adfL;
  4621. a->profile.B3_Protocols &= 0x000000b7L;
  4622. a->manufacturer_features &= MANUFACTURER_FEATURE_HARDDTMF;
  4623. }
  4624. if (a->manufacturer_features & (MANUFACTURER_FEATURE_HARDDTMF |
  4625. MANUFACTURER_FEATURE_SOFTDTMF_SEND | MANUFACTURER_FEATURE_SOFTDTMF_RECEIVE))
  4626. {
  4627. a->profile.Global_Options |= GL_DTMF_SUPPORTED;
  4628. }
  4629. a->manufacturer_features &= ~MANUFACTURER_FEATURE_OOB_CHANNEL;
  4630. dbug (1, dprintf ("[%06x] Profile: %lx %lx %lx %lx %lx",
  4631. UnMapController (a->Id), a->profile.Global_Options,
  4632. a->profile.B1_Protocols, a->profile.B2_Protocols,
  4633. a->profile.B3_Protocols, a->manufacturer_features));
  4634. }
  4635. /* codec plci for the handset/hook state support is just an internal id */
  4636. if(plci!=a->AdvCodecPLCI)
  4637. {
  4638. force_mt_info = SendMultiIE(plci,Id,multi_fac_parms, FTY, 0x20, 0);
  4639. force_mt_info |= SendMultiIE(plci,Id,multi_pi_parms, PI, 0x210, 0);
  4640. SendSSExtInd(NULL,plci,Id,multi_ssext_parms);
  4641. SendInfo(plci,Id, parms, force_mt_info);
  4642. VSwitchReqInd(plci,Id,multi_vswitch_parms);
  4643. }
  4644. /* switch the codec to the b-channel */
  4645. if(esc_chi[0] && plci && !plci->SuppState){
  4646. plci->b_channel = esc_chi[esc_chi[0]]&0x1f;
  4647. mixer_set_bchannel_id_esc (plci, plci->b_channel);
  4648. dbug(1,dprintf("storeChannel=0x%x",plci->b_channel));
  4649. if(plci->tel==ADV_VOICE && plci->appl) {
  4650. SetVoiceChannel(a->AdvCodecPLCI, esc_chi, a);
  4651. }
  4652. }
  4653. if(plci->appl) Number = plci->appl->Number++;
  4654. switch(plci->Sig.Ind) {
  4655. /* Response to Get_Supported_Services request */
  4656. case S_SUPPORTED:
  4657. dbug(1,dprintf("S_Supported"));
  4658. if(!plci->appl) break;
  4659. if(pty_cai[0]==4)
  4660. {
  4661. PUT_DWORD(&CF_Ind[6],GET_DWORD(&pty_cai[1]) );
  4662. }
  4663. else
  4664. {
  4665. PUT_DWORD(&CF_Ind[6],MASK_TERMINAL_PORTABILITY | MASK_HOLD_RETRIEVE);
  4666. }
  4667. PUT_WORD (&CF_Ind[1], 0);
  4668. PUT_WORD (&CF_Ind[4], 0);
  4669. sendf(plci->appl,_FACILITY_R|CONFIRM,Id&0x7,plci->number, "wws",0,3,CF_Ind);
  4670. plci_remove(plci);
  4671. break;
  4672. /* Supplementary Service rejected */
  4673. case S_SERVICE_REJ:
  4674. dbug(1,dprintf("S_Reject=0x%x",pty_cai[5]));
  4675. if(!pty_cai[0]) break;
  4676. switch (pty_cai[5])
  4677. {
  4678. case ECT_EXECUTE:
  4679. case THREE_PTY_END:
  4680. case THREE_PTY_BEGIN:
  4681. if(!plci->relatedPTYPLCI) break;
  4682. tplci = plci->relatedPTYPLCI;
  4683. rId = ( (word)tplci->Id<<8)|tplci->adapter->Id;
  4684. if(tplci->tel) rId|=EXT_CONTROLLER;
  4685. if(pty_cai[5]==ECT_EXECUTE)
  4686. {
  4687. PUT_WORD(&SS_Ind[1],S_ECT);
  4688. plci->vswitchstate=0;
  4689. plci->relatedPTYPLCI->vswitchstate=0;
  4690. }
  4691. else
  4692. {
  4693. PUT_WORD(&SS_Ind[1],pty_cai[5]+3);
  4694. }
  4695. if(pty_cai[2]!=0xff)
  4696. {
  4697. PUT_WORD(&SS_Ind[4],0x3600|(word)pty_cai[2]);
  4698. }
  4699. else
  4700. {
  4701. PUT_WORD(&SS_Ind[4],0x300E);
  4702. }
  4703. plci->relatedPTYPLCI = NULL;
  4704. plci->ptyState = 0;
  4705. sendf(tplci->appl,_FACILITY_I,rId,0,"ws",3, SS_Ind);
  4706. break;
  4707. case CALL_DEFLECTION:
  4708. if(pty_cai[2]!=0xff)
  4709. {
  4710. PUT_WORD(&SS_Ind[4],0x3600|(word)pty_cai[2]);
  4711. }
  4712. else
  4713. {
  4714. PUT_WORD(&SS_Ind[4],0x300E);
  4715. }
  4716. PUT_WORD(&SS_Ind[1],pty_cai[5]);
  4717. for(i=0; i<max_appl; i++)
  4718. {
  4719. if(application[i].CDEnable)
  4720. {
  4721. if(application[i].Id) sendf(&application[i],_FACILITY_I,Id,0,"ws",3, SS_Ind);
  4722. application[i].CDEnable = false;
  4723. }
  4724. }
  4725. break;
  4726. case DEACTIVATION_DIVERSION:
  4727. case ACTIVATION_DIVERSION:
  4728. case DIVERSION_INTERROGATE_CFU:
  4729. case DIVERSION_INTERROGATE_CFB:
  4730. case DIVERSION_INTERROGATE_CFNR:
  4731. case DIVERSION_INTERROGATE_NUM:
  4732. case CCBS_REQUEST:
  4733. case CCBS_DEACTIVATE:
  4734. case CCBS_INTERROGATE:
  4735. if(!plci->appl) break;
  4736. if(pty_cai[2]!=0xff)
  4737. {
  4738. PUT_WORD(&Interr_Err_Ind[4],0x3600|(word)pty_cai[2]);
  4739. }
  4740. else
  4741. {
  4742. PUT_WORD(&Interr_Err_Ind[4],0x300E);
  4743. }
  4744. switch (pty_cai[5])
  4745. {
  4746. case DEACTIVATION_DIVERSION:
  4747. dbug(1,dprintf("Deact_Div"));
  4748. Interr_Err_Ind[0]=0x9;
  4749. Interr_Err_Ind[3]=0x6;
  4750. PUT_WORD(&Interr_Err_Ind[1],S_CALL_FORWARDING_STOP);
  4751. break;
  4752. case ACTIVATION_DIVERSION:
  4753. dbug(1,dprintf("Act_Div"));
  4754. Interr_Err_Ind[0]=0x9;
  4755. Interr_Err_Ind[3]=0x6;
  4756. PUT_WORD(&Interr_Err_Ind[1],S_CALL_FORWARDING_START);
  4757. break;
  4758. case DIVERSION_INTERROGATE_CFU:
  4759. case DIVERSION_INTERROGATE_CFB:
  4760. case DIVERSION_INTERROGATE_CFNR:
  4761. dbug(1,dprintf("Interr_Div"));
  4762. Interr_Err_Ind[0]=0xa;
  4763. Interr_Err_Ind[3]=0x7;
  4764. PUT_WORD(&Interr_Err_Ind[1],S_INTERROGATE_DIVERSION);
  4765. break;
  4766. case DIVERSION_INTERROGATE_NUM:
  4767. dbug(1,dprintf("Interr_Num"));
  4768. Interr_Err_Ind[0]=0xa;
  4769. Interr_Err_Ind[3]=0x7;
  4770. PUT_WORD(&Interr_Err_Ind[1],S_INTERROGATE_NUMBERS);
  4771. break;
  4772. case CCBS_REQUEST:
  4773. dbug(1,dprintf("CCBS Request"));
  4774. Interr_Err_Ind[0]=0xd;
  4775. Interr_Err_Ind[3]=0xa;
  4776. PUT_WORD(&Interr_Err_Ind[1],S_CCBS_REQUEST);
  4777. break;
  4778. case CCBS_DEACTIVATE:
  4779. dbug(1,dprintf("CCBS Deactivate"));
  4780. Interr_Err_Ind[0]=0x9;
  4781. Interr_Err_Ind[3]=0x6;
  4782. PUT_WORD(&Interr_Err_Ind[1],S_CCBS_DEACTIVATE);
  4783. break;
  4784. case CCBS_INTERROGATE:
  4785. dbug(1,dprintf("CCBS Interrogate"));
  4786. Interr_Err_Ind[0]=0xb;
  4787. Interr_Err_Ind[3]=0x8;
  4788. PUT_WORD(&Interr_Err_Ind[1],S_CCBS_INTERROGATE);
  4789. break;
  4790. }
  4791. PUT_DWORD(&Interr_Err_Ind[6],plci->appl->S_Handle);
  4792. sendf(plci->appl,_FACILITY_I,Id&0x7,0,"ws",3, Interr_Err_Ind);
  4793. plci_remove(plci);
  4794. break;
  4795. case ACTIVATION_MWI:
  4796. case DEACTIVATION_MWI:
  4797. if(pty_cai[5]==ACTIVATION_MWI)
  4798. {
  4799. PUT_WORD(&SS_Ind[1],S_MWI_ACTIVATE);
  4800. }
  4801. else PUT_WORD(&SS_Ind[1],S_MWI_DEACTIVATE);
  4802. if(pty_cai[2]!=0xff)
  4803. {
  4804. PUT_WORD(&SS_Ind[4],0x3600|(word)pty_cai[2]);
  4805. }
  4806. else
  4807. {
  4808. PUT_WORD(&SS_Ind[4],0x300E);
  4809. }
  4810. if(plci->cr_enquiry)
  4811. {
  4812. sendf(plci->appl,_FACILITY_I,Id&0xf,0,"ws",3, SS_Ind);
  4813. plci_remove(plci);
  4814. }
  4815. else
  4816. {
  4817. sendf(plci->appl,_FACILITY_I,Id,0,"ws",3, SS_Ind);
  4818. }
  4819. break;
  4820. case CONF_ADD: /* ERROR */
  4821. case CONF_BEGIN:
  4822. case CONF_DROP:
  4823. case CONF_ISOLATE:
  4824. case CONF_REATTACH:
  4825. CONF_Ind[0]=9;
  4826. CONF_Ind[3]=6;
  4827. switch(pty_cai[5])
  4828. {
  4829. case CONF_BEGIN:
  4830. PUT_WORD(&CONF_Ind[1],S_CONF_BEGIN);
  4831. plci->ptyState = 0;
  4832. break;
  4833. case CONF_DROP:
  4834. CONF_Ind[0]=5;
  4835. CONF_Ind[3]=2;
  4836. PUT_WORD(&CONF_Ind[1],S_CONF_DROP);
  4837. plci->ptyState = CONNECTED;
  4838. break;
  4839. case CONF_ISOLATE:
  4840. CONF_Ind[0]=5;
  4841. CONF_Ind[3]=2;
  4842. PUT_WORD(&CONF_Ind[1],S_CONF_ISOLATE);
  4843. plci->ptyState = CONNECTED;
  4844. break;
  4845. case CONF_REATTACH:
  4846. CONF_Ind[0]=5;
  4847. CONF_Ind[3]=2;
  4848. PUT_WORD(&CONF_Ind[1],S_CONF_REATTACH);
  4849. plci->ptyState = CONNECTED;
  4850. break;
  4851. case CONF_ADD:
  4852. PUT_WORD(&CONF_Ind[1],S_CONF_ADD);
  4853. plci->relatedPTYPLCI = NULL;
  4854. tplci=plci->relatedPTYPLCI;
  4855. if(tplci) tplci->ptyState = CONNECTED;
  4856. plci->ptyState = CONNECTED;
  4857. break;
  4858. }
  4859. if(pty_cai[2]!=0xff)
  4860. {
  4861. PUT_WORD(&CONF_Ind[4],0x3600|(word)pty_cai[2]);
  4862. }
  4863. else
  4864. {
  4865. PUT_WORD(&CONF_Ind[4],0x3303); /* Time-out: network did not respond
  4866. within the required time */
  4867. }
  4868. PUT_DWORD(&CONF_Ind[6],0x0);
  4869. sendf(plci->appl,_FACILITY_I,Id,0,"ws",3, CONF_Ind);
  4870. break;
  4871. }
  4872. break;
  4873. /* Supplementary Service indicates success */
  4874. case S_SERVICE:
  4875. dbug(1,dprintf("Service_Ind"));
  4876. PUT_WORD (&CF_Ind[4], 0);
  4877. switch (pty_cai[5])
  4878. {
  4879. case THREE_PTY_END:
  4880. case THREE_PTY_BEGIN:
  4881. case ECT_EXECUTE:
  4882. if(!plci->relatedPTYPLCI) break;
  4883. tplci = plci->relatedPTYPLCI;
  4884. rId = ( (word)tplci->Id<<8)|tplci->adapter->Id;
  4885. if(tplci->tel) rId|=EXT_CONTROLLER;
  4886. if(pty_cai[5]==ECT_EXECUTE)
  4887. {
  4888. PUT_WORD(&SS_Ind[1],S_ECT);
  4889. if(plci->vswitchstate!=3)
  4890. {
  4891. plci->ptyState = IDLE;
  4892. plci->relatedPTYPLCI = NULL;
  4893. plci->ptyState = 0;
  4894. }
  4895. dbug(1,dprintf("ECT OK"));
  4896. sendf(tplci->appl,_FACILITY_I,rId,0,"ws",3, SS_Ind);
  4897. }
  4898. else
  4899. {
  4900. switch (plci->ptyState)
  4901. {
  4902. case S_3PTY_BEGIN:
  4903. plci->ptyState = CONNECTED;
  4904. dbug(1,dprintf("3PTY ON"));
  4905. break;
  4906. case S_3PTY_END:
  4907. plci->ptyState = IDLE;
  4908. plci->relatedPTYPLCI = NULL;
  4909. plci->ptyState = 0;
  4910. dbug(1,dprintf("3PTY OFF"));
  4911. break;
  4912. }
  4913. PUT_WORD(&SS_Ind[1],pty_cai[5]+3);
  4914. sendf(tplci->appl,_FACILITY_I,rId,0,"ws",3, SS_Ind);
  4915. }
  4916. break;
  4917. case CALL_DEFLECTION:
  4918. PUT_WORD(&SS_Ind[1],pty_cai[5]);
  4919. for(i=0; i<max_appl; i++)
  4920. {
  4921. if(application[i].CDEnable)
  4922. {
  4923. if(application[i].Id) sendf(&application[i],_FACILITY_I,Id,0,"ws",3, SS_Ind);
  4924. application[i].CDEnable = false;
  4925. }
  4926. }
  4927. break;
  4928. case DEACTIVATION_DIVERSION:
  4929. case ACTIVATION_DIVERSION:
  4930. if(!plci->appl) break;
  4931. PUT_WORD(&CF_Ind[1],pty_cai[5]+2);
  4932. PUT_DWORD(&CF_Ind[6],plci->appl->S_Handle);
  4933. sendf(plci->appl,_FACILITY_I,Id&0x7,0,"ws",3, CF_Ind);
  4934. plci_remove(plci);
  4935. break;
  4936. case DIVERSION_INTERROGATE_CFU:
  4937. case DIVERSION_INTERROGATE_CFB:
  4938. case DIVERSION_INTERROGATE_CFNR:
  4939. case DIVERSION_INTERROGATE_NUM:
  4940. case CCBS_REQUEST:
  4941. case CCBS_DEACTIVATE:
  4942. case CCBS_INTERROGATE:
  4943. if(!plci->appl) break;
  4944. switch (pty_cai[5])
  4945. {
  4946. case DIVERSION_INTERROGATE_CFU:
  4947. case DIVERSION_INTERROGATE_CFB:
  4948. case DIVERSION_INTERROGATE_CFNR:
  4949. dbug(1,dprintf("Interr_Div"));
  4950. PUT_WORD(&pty_cai[1],S_INTERROGATE_DIVERSION);
  4951. pty_cai[3]=pty_cai[0]-3; /* Supplementary Service-specific parameter len */
  4952. break;
  4953. case DIVERSION_INTERROGATE_NUM:
  4954. dbug(1,dprintf("Interr_Num"));
  4955. PUT_WORD(&pty_cai[1],S_INTERROGATE_NUMBERS);
  4956. pty_cai[3]=pty_cai[0]-3; /* Supplementary Service-specific parameter len */
  4957. break;
  4958. case CCBS_REQUEST:
  4959. dbug(1,dprintf("CCBS Request"));
  4960. PUT_WORD(&pty_cai[1],S_CCBS_REQUEST);
  4961. pty_cai[3]=pty_cai[0]-3; /* Supplementary Service-specific parameter len */
  4962. break;
  4963. case CCBS_DEACTIVATE:
  4964. dbug(1,dprintf("CCBS Deactivate"));
  4965. PUT_WORD(&pty_cai[1],S_CCBS_DEACTIVATE);
  4966. pty_cai[3]=pty_cai[0]-3; /* Supplementary Service-specific parameter len */
  4967. break;
  4968. case CCBS_INTERROGATE:
  4969. dbug(1,dprintf("CCBS Interrogate"));
  4970. PUT_WORD(&pty_cai[1],S_CCBS_INTERROGATE);
  4971. pty_cai[3]=pty_cai[0]-3; /* Supplementary Service-specific parameter len */
  4972. break;
  4973. }
  4974. PUT_WORD(&pty_cai[4],0); /* Supplementary Service Reason */
  4975. PUT_DWORD(&pty_cai[6],plci->appl->S_Handle);
  4976. sendf(plci->appl,_FACILITY_I,Id&0x7,0,"wS",3, pty_cai);
  4977. plci_remove(plci);
  4978. break;
  4979. case ACTIVATION_MWI:
  4980. case DEACTIVATION_MWI:
  4981. if(pty_cai[5]==ACTIVATION_MWI)
  4982. {
  4983. PUT_WORD(&SS_Ind[1],S_MWI_ACTIVATE);
  4984. }
  4985. else PUT_WORD(&SS_Ind[1],S_MWI_DEACTIVATE);
  4986. if(plci->cr_enquiry)
  4987. {
  4988. sendf(plci->appl,_FACILITY_I,Id&0xf,0,"ws",3, SS_Ind);
  4989. plci_remove(plci);
  4990. }
  4991. else
  4992. {
  4993. sendf(plci->appl,_FACILITY_I,Id,0,"ws",3, SS_Ind);
  4994. }
  4995. break;
  4996. case MWI_INDICATION:
  4997. if(pty_cai[0]>=0x12)
  4998. {
  4999. PUT_WORD(&pty_cai[3],S_MWI_INDICATE);
  5000. pty_cai[2]=pty_cai[0]-2; /* len Parameter */
  5001. pty_cai[5]=pty_cai[0]-5; /* Supplementary Service-specific parameter len */
  5002. if(plci->appl && (a->Notification_Mask[plci->appl->Id-1]&SMASK_MWI))
  5003. {
  5004. if(plci->internal_command==GET_MWI_STATE) /* result on Message Waiting Listen */
  5005. {
  5006. sendf(plci->appl,_FACILITY_I,Id&0xf,0,"wS",3, &pty_cai[2]);
  5007. plci_remove(plci);
  5008. return;
  5009. }
  5010. else sendf(plci->appl,_FACILITY_I,Id,0,"wS",3, &pty_cai[2]);
  5011. pty_cai[0]=0;
  5012. }
  5013. else
  5014. {
  5015. for(i=0; i<max_appl; i++)
  5016. {
  5017. if(a->Notification_Mask[i]&SMASK_MWI)
  5018. {
  5019. sendf(&application[i],_FACILITY_I,Id&0x7,0,"wS",3, &pty_cai[2]);
  5020. pty_cai[0]=0;
  5021. }
  5022. }
  5023. }
  5024. if(!pty_cai[0])
  5025. { /* acknowledge */
  5026. facility[2]= 0; /* returncode */
  5027. }
  5028. else facility[2]= 0xff;
  5029. }
  5030. else
  5031. {
  5032. /* reject */
  5033. facility[2]= 0xff; /* returncode */
  5034. }
  5035. facility[0]= 2;
  5036. facility[1]= MWI_RESPONSE; /* Function */
  5037. add_p(plci,CAI,facility);
  5038. add_p(plci,ESC,multi_ssext_parms[0]); /* remembered parameter -> only one possible */
  5039. sig_req(plci,S_SERVICE,0);
  5040. send_req(plci);
  5041. plci->command = 0;
  5042. next_internal_command (Id, plci);
  5043. break;
  5044. case CONF_ADD: /* OK */
  5045. case CONF_BEGIN:
  5046. case CONF_DROP:
  5047. case CONF_ISOLATE:
  5048. case CONF_REATTACH:
  5049. case CONF_PARTYDISC:
  5050. CONF_Ind[0]=9;
  5051. CONF_Ind[3]=6;
  5052. switch(pty_cai[5])
  5053. {
  5054. case CONF_BEGIN:
  5055. PUT_WORD(&CONF_Ind[1],S_CONF_BEGIN);
  5056. if(pty_cai[0]==6)
  5057. {
  5058. d=pty_cai[6];
  5059. PUT_DWORD(&CONF_Ind[6],d); /* PartyID */
  5060. }
  5061. else
  5062. {
  5063. PUT_DWORD(&CONF_Ind[6],0x0);
  5064. }
  5065. break;
  5066. case CONF_ISOLATE:
  5067. PUT_WORD(&CONF_Ind[1],S_CONF_ISOLATE);
  5068. CONF_Ind[0]=5;
  5069. CONF_Ind[3]=2;
  5070. break;
  5071. case CONF_REATTACH:
  5072. PUT_WORD(&CONF_Ind[1],S_CONF_REATTACH);
  5073. CONF_Ind[0]=5;
  5074. CONF_Ind[3]=2;
  5075. break;
  5076. case CONF_DROP:
  5077. PUT_WORD(&CONF_Ind[1],S_CONF_DROP);
  5078. CONF_Ind[0]=5;
  5079. CONF_Ind[3]=2;
  5080. break;
  5081. case CONF_ADD:
  5082. PUT_WORD(&CONF_Ind[1],S_CONF_ADD);
  5083. d=pty_cai[6];
  5084. PUT_DWORD(&CONF_Ind[6],d); /* PartyID */
  5085. tplci=plci->relatedPTYPLCI;
  5086. if(tplci) tplci->ptyState = CONNECTED;
  5087. break;
  5088. case CONF_PARTYDISC:
  5089. CONF_Ind[0]=7;
  5090. CONF_Ind[3]=4;
  5091. PUT_WORD(&CONF_Ind[1],S_CONF_PARTYDISC);
  5092. d=pty_cai[6];
  5093. PUT_DWORD(&CONF_Ind[4],d); /* PartyID */
  5094. break;
  5095. }
  5096. plci->ptyState = CONNECTED;
  5097. sendf(plci->appl,_FACILITY_I,Id,0,"ws",3, CONF_Ind);
  5098. break;
  5099. case CCBS_INFO_RETAIN:
  5100. case CCBS_ERASECALLLINKAGEID:
  5101. case CCBS_STOP_ALERTING:
  5102. CONF_Ind[0]=5;
  5103. CONF_Ind[3]=2;
  5104. switch(pty_cai[5])
  5105. {
  5106. case CCBS_INFO_RETAIN:
  5107. PUT_WORD(&CONF_Ind[1],S_CCBS_INFO_RETAIN);
  5108. break;
  5109. case CCBS_STOP_ALERTING:
  5110. PUT_WORD(&CONF_Ind[1],S_CCBS_STOP_ALERTING);
  5111. break;
  5112. case CCBS_ERASECALLLINKAGEID:
  5113. PUT_WORD(&CONF_Ind[1],S_CCBS_ERASECALLLINKAGEID);
  5114. CONF_Ind[0]=7;
  5115. CONF_Ind[3]=4;
  5116. CONF_Ind[6]=0;
  5117. CONF_Ind[7]=0;
  5118. break;
  5119. }
  5120. w=pty_cai[6];
  5121. PUT_WORD(&CONF_Ind[4],w); /* PartyID */
  5122. if(plci->appl && (a->Notification_Mask[plci->appl->Id-1]&SMASK_CCBS))
  5123. {
  5124. sendf(plci->appl,_FACILITY_I,Id,0,"ws",3, CONF_Ind);
  5125. }
  5126. else
  5127. {
  5128. for(i=0; i<max_appl; i++)
  5129. if(a->Notification_Mask[i]&SMASK_CCBS)
  5130. sendf(&application[i],_FACILITY_I,Id&0x7,0,"ws",3, CONF_Ind);
  5131. }
  5132. break;
  5133. }
  5134. break;
  5135. case CALL_HOLD_REJ:
  5136. cau = parms[7];
  5137. if(cau)
  5138. {
  5139. i = _L3_CAUSE | cau[2];
  5140. if(cau[2]==0) i = 0x3603;
  5141. }
  5142. else
  5143. {
  5144. i = 0x3603;
  5145. }
  5146. PUT_WORD(&SS_Ind[1],S_HOLD);
  5147. PUT_WORD(&SS_Ind[4],i);
  5148. if(plci->SuppState == HOLD_REQUEST)
  5149. {
  5150. plci->SuppState = IDLE;
  5151. sendf(plci->appl,_FACILITY_I,Id,0,"ws",3, SS_Ind);
  5152. }
  5153. break;
  5154. case CALL_HOLD_ACK:
  5155. if(plci->SuppState == HOLD_REQUEST)
  5156. {
  5157. plci->SuppState = CALL_HELD;
  5158. CodecIdCheck(a, plci);
  5159. start_internal_command (Id, plci, hold_save_command);
  5160. }
  5161. break;
  5162. case CALL_RETRIEVE_REJ:
  5163. cau = parms[7];
  5164. if(cau)
  5165. {
  5166. i = _L3_CAUSE | cau[2];
  5167. if(cau[2]==0) i = 0x3603;
  5168. }
  5169. else
  5170. {
  5171. i = 0x3603;
  5172. }
  5173. PUT_WORD(&SS_Ind[1],S_RETRIEVE);
  5174. PUT_WORD(&SS_Ind[4],i);
  5175. if(plci->SuppState == RETRIEVE_REQUEST)
  5176. {
  5177. plci->SuppState = CALL_HELD;
  5178. CodecIdCheck(a, plci);
  5179. sendf(plci->appl,_FACILITY_I,Id,0,"ws",3, SS_Ind);
  5180. }
  5181. break;
  5182. case CALL_RETRIEVE_ACK:
  5183. PUT_WORD(&SS_Ind[1],S_RETRIEVE);
  5184. if(plci->SuppState == RETRIEVE_REQUEST)
  5185. {
  5186. plci->SuppState = IDLE;
  5187. plci->call_dir |= CALL_DIR_FORCE_OUTG_NL;
  5188. plci->b_channel = esc_chi[esc_chi[0]]&0x1f;
  5189. if(plci->tel)
  5190. {
  5191. mixer_set_bchannel_id_esc (plci, plci->b_channel);
  5192. dbug(1,dprintf("RetrChannel=0x%x",plci->b_channel));
  5193. SetVoiceChannel(a->AdvCodecPLCI, esc_chi, a);
  5194. if(plci->B2_prot==B2_TRANSPARENT && plci->B3_prot==B3_TRANSPARENT)
  5195. {
  5196. dbug(1,dprintf("Get B-ch"));
  5197. start_internal_command (Id, plci, retrieve_restore_command);
  5198. }
  5199. else
  5200. sendf(plci->appl,_FACILITY_I,Id,0,"ws",3, SS_Ind);
  5201. }
  5202. else
  5203. start_internal_command (Id, plci, retrieve_restore_command);
  5204. }
  5205. break;
  5206. case INDICATE_IND:
  5207. if(plci->State != LISTENING) {
  5208. sig_req(plci,HANGUP,0);
  5209. send_req(plci);
  5210. break;
  5211. }
  5212. cip = find_cip(a,parms[4],parms[6]);
  5213. cip_mask = 1L<<cip;
  5214. dbug(1,dprintf("cip=%d,cip_mask=%lx",cip,cip_mask));
  5215. clear_c_ind_mask (plci);
  5216. if (!remove_started && !a->adapter_disabled)
  5217. {
  5218. set_c_ind_mask_bit (plci, MAX_APPL);
  5219. group_optimization(a, plci);
  5220. for(i=0; i<max_appl; i++) {
  5221. if(application[i].Id
  5222. && (a->CIP_Mask[i]&1 || a->CIP_Mask[i]&cip_mask)
  5223. && CPN_filter_ok(parms[0],a,i)
  5224. && test_group_ind_mask_bit (plci, i) ) {
  5225. dbug(1,dprintf("storedcip_mask[%d]=0x%lx",i,a->CIP_Mask[i] ));
  5226. set_c_ind_mask_bit (plci, i);
  5227. dump_c_ind_mask (plci);
  5228. plci->State = INC_CON_PENDING;
  5229. plci->call_dir = (plci->call_dir & ~(CALL_DIR_OUT | CALL_DIR_ORIGINATE)) |
  5230. CALL_DIR_IN | CALL_DIR_ANSWER;
  5231. if(esc_chi[0]) {
  5232. plci->b_channel = esc_chi[esc_chi[0]]&0x1f;
  5233. mixer_set_bchannel_id_esc (plci, plci->b_channel);
  5234. }
  5235. /* if a listen on the ext controller is done, check if hook states */
  5236. /* are supported or if just a on board codec must be activated */
  5237. if(a->codec_listen[i] && !a->AdvSignalPLCI) {
  5238. if(a->profile.Global_Options & HANDSET)
  5239. plci->tel = ADV_VOICE;
  5240. else if(a->profile.Global_Options & ON_BOARD_CODEC)
  5241. plci->tel = CODEC;
  5242. if(plci->tel) Id|=EXT_CONTROLLER;
  5243. a->codec_listen[i] = plci;
  5244. }
  5245. sendf(&application[i],_CONNECT_I,Id,0,
  5246. "wSSSSSSSbSSSSS", cip, /* CIP */
  5247. parms[0], /* CalledPartyNumber */
  5248. multi_CiPN_parms[0], /* CallingPartyNumber */
  5249. parms[2], /* CalledPartySubad */
  5250. parms[3], /* CallingPartySubad */
  5251. parms[4], /* BearerCapability */
  5252. parms[5], /* LowLC */
  5253. parms[6], /* HighLC */
  5254. ai_len, /* nested struct add_i */
  5255. add_i[0], /* B channel info */
  5256. add_i[1], /* keypad facility */
  5257. add_i[2], /* user user data */
  5258. add_i[3], /* nested facility */
  5259. multi_CiPN_parms[1] /* second CiPN(SCR) */
  5260. );
  5261. SendSSExtInd(&application[i],
  5262. plci,
  5263. Id,
  5264. multi_ssext_parms);
  5265. SendSetupInfo(&application[i],
  5266. plci,
  5267. Id,
  5268. parms,
  5269. SendMultiIE(plci,Id,multi_pi_parms, PI, 0x210, true));
  5270. }
  5271. }
  5272. clear_c_ind_mask_bit (plci, MAX_APPL);
  5273. dump_c_ind_mask (plci);
  5274. }
  5275. if(c_ind_mask_empty (plci)) {
  5276. sig_req(plci,HANGUP,0);
  5277. send_req(plci);
  5278. plci->State = IDLE;
  5279. }
  5280. plci->notifiedcall = 0;
  5281. a->listen_active--;
  5282. listen_check(a);
  5283. break;
  5284. case CALL_PEND_NOTIFY:
  5285. plci->notifiedcall = 1;
  5286. listen_check(a);
  5287. break;
  5288. case CALL_IND:
  5289. case CALL_CON:
  5290. if(plci->State==ADVANCED_VOICE_SIG || plci->State==ADVANCED_VOICE_NOSIG)
  5291. {
  5292. if(plci->internal_command==PERM_COD_CONN_PEND)
  5293. {
  5294. if(plci->State==ADVANCED_VOICE_NOSIG)
  5295. {
  5296. dbug(1,dprintf("***Codec OK"));
  5297. if(a->AdvSignalPLCI)
  5298. {
  5299. tplci = a->AdvSignalPLCI;
  5300. if(tplci->spoofed_msg)
  5301. {
  5302. dbug(1,dprintf("***Spoofed Msg(0x%x)",tplci->spoofed_msg));
  5303. tplci->command = 0;
  5304. tplci->internal_command = 0;
  5305. x_Id = ((word)tplci->Id<<8)|tplci->adapter->Id | 0x80;
  5306. switch (tplci->spoofed_msg)
  5307. {
  5308. case CALL_RES:
  5309. tplci->command = _CONNECT_I|RESPONSE;
  5310. api_load_msg (&tplci->saved_msg, saved_parms);
  5311. add_b1(tplci,&saved_parms[1],0,tplci->B1_facilities);
  5312. if (tplci->adapter->Info_Mask[tplci->appl->Id-1] & 0x200)
  5313. {
  5314. /* early B3 connect (CIP mask bit 9) no release after a disc */
  5315. add_p(tplci,LLI,"\x01\x01");
  5316. }
  5317. add_s(tplci, CONN_NR, &saved_parms[2]);
  5318. add_s(tplci, LLC, &saved_parms[4]);
  5319. add_ai(tplci, &saved_parms[5]);
  5320. tplci->State = INC_CON_ACCEPT;
  5321. sig_req(tplci, CALL_RES,0);
  5322. send_req(tplci);
  5323. break;
  5324. case AWAITING_SELECT_B:
  5325. dbug(1,dprintf("Select_B continue"));
  5326. start_internal_command (x_Id, tplci, select_b_command);
  5327. break;
  5328. case AWAITING_MANUF_CON: /* Get_Plci per Manufacturer_Req to ext controller */
  5329. if(!tplci->Sig.Id)
  5330. {
  5331. dbug(1,dprintf("No SigID!"));
  5332. sendf(tplci->appl, _MANUFACTURER_R|CONFIRM,x_Id,tplci->number, "dww",_DI_MANU_ID,_MANUFACTURER_R,_OUT_OF_PLCI);
  5333. plci_remove(tplci);
  5334. break;
  5335. }
  5336. tplci->command = _MANUFACTURER_R;
  5337. api_load_msg (&tplci->saved_msg, saved_parms);
  5338. dir = saved_parms[2].info[0];
  5339. if(dir==1) {
  5340. sig_req(tplci,CALL_REQ,0);
  5341. }
  5342. else if(!dir){
  5343. sig_req(tplci,LISTEN_REQ,0);
  5344. }
  5345. send_req(tplci);
  5346. sendf(tplci->appl, _MANUFACTURER_R|CONFIRM,x_Id,tplci->number, "dww",_DI_MANU_ID,_MANUFACTURER_R,0);
  5347. break;
  5348. case (CALL_REQ|AWAITING_MANUF_CON):
  5349. sig_req(tplci,CALL_REQ,0);
  5350. send_req(tplci);
  5351. break;
  5352. case CALL_REQ:
  5353. if(!tplci->Sig.Id)
  5354. {
  5355. dbug(1,dprintf("No SigID!"));
  5356. sendf(tplci->appl,_CONNECT_R|CONFIRM,tplci->adapter->Id,0,"w",_OUT_OF_PLCI);
  5357. plci_remove(tplci);
  5358. break;
  5359. }
  5360. tplci->command = _CONNECT_R;
  5361. api_load_msg (&tplci->saved_msg, saved_parms);
  5362. add_s(tplci,CPN,&saved_parms[1]);
  5363. add_s(tplci,DSA,&saved_parms[3]);
  5364. add_ai(tplci,&saved_parms[9]);
  5365. sig_req(tplci,CALL_REQ,0);
  5366. send_req(tplci);
  5367. break;
  5368. case CALL_RETRIEVE:
  5369. tplci->command = C_RETRIEVE_REQ;
  5370. sig_req(tplci,CALL_RETRIEVE,0);
  5371. send_req(tplci);
  5372. break;
  5373. }
  5374. tplci->spoofed_msg = 0;
  5375. if (tplci->internal_command == 0)
  5376. next_internal_command (x_Id, tplci);
  5377. }
  5378. }
  5379. next_internal_command (Id, plci);
  5380. break;
  5381. }
  5382. dbug(1,dprintf("***Codec Hook Init Req"));
  5383. plci->internal_command = PERM_COD_HOOK;
  5384. add_p(plci,FTY,"\x01\x09"); /* Get Hook State*/
  5385. sig_req(plci,TEL_CTRL,0);
  5386. send_req(plci);
  5387. }
  5388. }
  5389. else if(plci->command != _MANUFACTURER_R /* old style permanent connect */
  5390. && plci->State!=INC_ACT_PENDING)
  5391. {
  5392. mixer_set_bchannel_id_esc (plci, plci->b_channel);
  5393. if(plci->tel == ADV_VOICE && plci->SuppState == IDLE) /* with permanent codec switch on immediately */
  5394. {
  5395. chi[2] = plci->b_channel;
  5396. SetVoiceChannel(a->AdvCodecPLCI, chi, a);
  5397. }
  5398. sendf(plci->appl,_CONNECT_ACTIVE_I,Id,0,"Sss",parms[21],"","");
  5399. plci->State = INC_ACT_PENDING;
  5400. }
  5401. break;
  5402. case TEL_CTRL:
  5403. Number = 0;
  5404. ie = multi_fac_parms[0]; /* inspect the facility hook indications */
  5405. if(plci->State==ADVANCED_VOICE_SIG && ie[0]){
  5406. switch (ie[1]&0x91) {
  5407. case 0x80: /* hook off */
  5408. case 0x81:
  5409. if(plci->internal_command==PERM_COD_HOOK)
  5410. {
  5411. dbug(1,dprintf("init:hook_off"));
  5412. plci->hook_state = ie[1];
  5413. next_internal_command (Id, plci);
  5414. break;
  5415. }
  5416. else /* ignore doubled hook indications */
  5417. {
  5418. if( ((plci->hook_state)&0xf0)==0x80)
  5419. {
  5420. dbug(1,dprintf("ignore hook"));
  5421. break;
  5422. }
  5423. plci->hook_state = ie[1]&0x91;
  5424. }
  5425. /* check for incoming call pending */
  5426. /* and signal '+'.Appl must decide */
  5427. /* with connect_res if call must */
  5428. /* accepted or not */
  5429. for(i=0, tplci=NULL;i<max_appl;i++){
  5430. if(a->codec_listen[i]
  5431. && (a->codec_listen[i]->State==INC_CON_PENDING
  5432. ||a->codec_listen[i]->State==INC_CON_ALERT) ){
  5433. tplci = a->codec_listen[i];
  5434. tplci->appl = &application[i];
  5435. }
  5436. }
  5437. /* no incoming call, do outgoing call */
  5438. /* and signal '+' if outg. setup */
  5439. if(!a->AdvSignalPLCI && !tplci){
  5440. if((i=get_plci(a))) {
  5441. a->AdvSignalPLCI = &a->plci[i-1];
  5442. tplci = a->AdvSignalPLCI;
  5443. tplci->tel = ADV_VOICE;
  5444. PUT_WORD(&voice_cai[5],a->AdvSignalAppl->MaxDataLength);
  5445. if (a->Info_Mask[a->AdvSignalAppl->Id-1] & 0x200){
  5446. /* early B3 connect (CIP mask bit 9) no release after a disc */
  5447. add_p(tplci,LLI,"\x01\x01");
  5448. }
  5449. add_p(tplci, CAI, voice_cai);
  5450. add_p(tplci, OAD, a->TelOAD);
  5451. add_p(tplci, OSA, a->TelOSA);
  5452. add_p(tplci,SHIFT|6,NULL);
  5453. add_p(tplci,SIN,"\x02\x01\x00");
  5454. add_p(tplci,UID,"\x06\x43\x61\x70\x69\x32\x30");
  5455. sig_req(tplci,ASSIGN,DSIG_ID);
  5456. a->AdvSignalPLCI->internal_command = HOOK_OFF_REQ;
  5457. a->AdvSignalPLCI->command = 0;
  5458. tplci->appl = a->AdvSignalAppl;
  5459. tplci->call_dir = CALL_DIR_OUT | CALL_DIR_ORIGINATE;
  5460. send_req(tplci);
  5461. }
  5462. }
  5463. if(!tplci) break;
  5464. Id = ((word)tplci->Id<<8)|a->Id;
  5465. Id|=EXT_CONTROLLER;
  5466. sendf(tplci->appl,
  5467. _FACILITY_I,
  5468. Id,
  5469. 0,
  5470. "ws", (word)0, "\x01+");
  5471. break;
  5472. case 0x90: /* hook on */
  5473. case 0x91:
  5474. if(plci->internal_command==PERM_COD_HOOK)
  5475. {
  5476. dbug(1,dprintf("init:hook_on"));
  5477. plci->hook_state = ie[1]&0x91;
  5478. next_internal_command (Id, plci);
  5479. break;
  5480. }
  5481. else /* ignore doubled hook indications */
  5482. {
  5483. if( ((plci->hook_state)&0xf0)==0x90) break;
  5484. plci->hook_state = ie[1]&0x91;
  5485. }
  5486. /* hangup the adv. voice call and signal '-' to the appl */
  5487. if(a->AdvSignalPLCI) {
  5488. Id = ((word)a->AdvSignalPLCI->Id<<8)|a->Id;
  5489. if(plci->tel) Id|=EXT_CONTROLLER;
  5490. sendf(a->AdvSignalAppl,
  5491. _FACILITY_I,
  5492. Id,
  5493. 0,
  5494. "ws", (word)0, "\x01-");
  5495. a->AdvSignalPLCI->internal_command = HOOK_ON_REQ;
  5496. a->AdvSignalPLCI->command = 0;
  5497. sig_req(a->AdvSignalPLCI,HANGUP,0);
  5498. send_req(a->AdvSignalPLCI);
  5499. }
  5500. break;
  5501. }
  5502. }
  5503. break;
  5504. case RESUME:
  5505. clear_c_ind_mask_bit (plci, (word)(plci->appl->Id-1));
  5506. PUT_WORD(&resume_cau[4],GOOD);
  5507. sendf(plci->appl,_FACILITY_I,Id,0,"ws", (word)3, resume_cau);
  5508. break;
  5509. case SUSPEND:
  5510. clear_c_ind_mask (plci);
  5511. if (plci->NL.Id && !plci->nl_remove_id) {
  5512. mixer_remove (plci);
  5513. nl_req_ncci(plci,REMOVE,0);
  5514. }
  5515. if (!plci->sig_remove_id) {
  5516. plci->internal_command = 0;
  5517. sig_req(plci,REMOVE,0);
  5518. }
  5519. send_req(plci);
  5520. if(!plci->channels) {
  5521. sendf(plci->appl,_FACILITY_I,Id,0,"ws", (word)3, "\x05\x04\x00\x02\x00\x00");
  5522. sendf(plci->appl, _DISCONNECT_I, Id, 0, "w", 0);
  5523. }
  5524. break;
  5525. case SUSPEND_REJ:
  5526. break;
  5527. case HANGUP:
  5528. plci->hangup_flow_ctrl_timer=0;
  5529. if(plci->manufacturer && plci->State==LOCAL_CONNECT) break;
  5530. cau = parms[7];
  5531. if(cau) {
  5532. i = _L3_CAUSE | cau[2];
  5533. if(cau[2]==0) i = 0;
  5534. else if(cau[2]==8) i = _L1_ERROR;
  5535. else if(cau[2]==9 || cau[2]==10) i = _L2_ERROR;
  5536. else if(cau[2]==5) i = _CAPI_GUARD_ERROR;
  5537. }
  5538. else {
  5539. i = _L3_ERROR;
  5540. }
  5541. if(plci->State==INC_CON_PENDING || plci->State==INC_CON_ALERT)
  5542. {
  5543. for(i=0; i<max_appl; i++)
  5544. {
  5545. if(test_c_ind_mask_bit (plci, i))
  5546. sendf(&application[i], _DISCONNECT_I, Id, 0, "w", 0);
  5547. }
  5548. }
  5549. else
  5550. {
  5551. clear_c_ind_mask (plci);
  5552. }
  5553. if(!plci->appl)
  5554. {
  5555. if (plci->State == LISTENING)
  5556. {
  5557. plci->notifiedcall=0;
  5558. a->listen_active--;
  5559. }
  5560. plci->State = INC_DIS_PENDING;
  5561. if(c_ind_mask_empty (plci))
  5562. {
  5563. plci->State = IDLE;
  5564. if (plci->NL.Id && !plci->nl_remove_id)
  5565. {
  5566. mixer_remove (plci);
  5567. nl_req_ncci(plci,REMOVE,0);
  5568. }
  5569. if (!plci->sig_remove_id)
  5570. {
  5571. plci->internal_command = 0;
  5572. sig_req(plci,REMOVE,0);
  5573. }
  5574. send_req(plci);
  5575. }
  5576. }
  5577. else
  5578. {
  5579. /* collision of DISCONNECT or CONNECT_RES with HANGUP can */
  5580. /* result in a second HANGUP! Don't generate another */
  5581. /* DISCONNECT */
  5582. if(plci->State!=IDLE && plci->State!=INC_DIS_PENDING)
  5583. {
  5584. if(plci->State==RESUMING)
  5585. {
  5586. PUT_WORD(&resume_cau[4],i);
  5587. sendf(plci->appl,_FACILITY_I,Id,0,"ws", (word)3, resume_cau);
  5588. }
  5589. plci->State = INC_DIS_PENDING;
  5590. sendf(plci->appl,_DISCONNECT_I,Id,0,"w",i);
  5591. }
  5592. }
  5593. break;
  5594. case SSEXT_IND:
  5595. SendSSExtInd(NULL,plci,Id,multi_ssext_parms);
  5596. break;
  5597. case VSWITCH_REQ:
  5598. VSwitchReqInd(plci,Id,multi_vswitch_parms);
  5599. break;
  5600. case VSWITCH_IND:
  5601. if(plci->relatedPTYPLCI &&
  5602. plci->vswitchstate==3 &&
  5603. plci->relatedPTYPLCI->vswitchstate==3 &&
  5604. parms[MAXPARMSIDS-1][0])
  5605. {
  5606. add_p(plci->relatedPTYPLCI,SMSG,parms[MAXPARMSIDS-1]);
  5607. sig_req(plci->relatedPTYPLCI,VSWITCH_REQ,0);
  5608. send_req(plci->relatedPTYPLCI);
  5609. }
  5610. else VSwitchReqInd(plci,Id,multi_vswitch_parms);
  5611. break;
  5612. }
  5613. }
  5614. static void SendSetupInfo(APPL * appl, PLCI * plci, dword Id, byte * * parms, byte Info_Sent_Flag)
  5615. {
  5616. word i;
  5617. byte * ie;
  5618. word Info_Number;
  5619. byte * Info_Element;
  5620. word Info_Mask = 0;
  5621. dbug(1,dprintf("SetupInfo"));
  5622. for(i=0; i<MAXPARMSIDS; i++) {
  5623. ie = parms[i];
  5624. Info_Number = 0;
  5625. Info_Element = ie;
  5626. if(ie[0]) {
  5627. switch(i) {
  5628. case 0:
  5629. dbug(1,dprintf("CPN "));
  5630. Info_Number = 0x0070;
  5631. Info_Mask = 0x80;
  5632. Info_Sent_Flag = true;
  5633. break;
  5634. case 8: /* display */
  5635. dbug(1,dprintf("display(%d)",i));
  5636. Info_Number = 0x0028;
  5637. Info_Mask = 0x04;
  5638. Info_Sent_Flag = true;
  5639. break;
  5640. case 16: /* Channel Id */
  5641. dbug(1,dprintf("CHI"));
  5642. Info_Number = 0x0018;
  5643. Info_Mask = 0x100;
  5644. Info_Sent_Flag = true;
  5645. mixer_set_bchannel_id (plci, Info_Element);
  5646. break;
  5647. case 19: /* Redirected Number */
  5648. dbug(1,dprintf("RDN"));
  5649. Info_Number = 0x0074;
  5650. Info_Mask = 0x400;
  5651. Info_Sent_Flag = true;
  5652. break;
  5653. case 20: /* Redirected Number extended */
  5654. dbug(1,dprintf("RDX"));
  5655. Info_Number = 0x0073;
  5656. Info_Mask = 0x400;
  5657. Info_Sent_Flag = true;
  5658. break;
  5659. case 22: /* Redirecing Number */
  5660. dbug(1,dprintf("RIN"));
  5661. Info_Number = 0x0076;
  5662. Info_Mask = 0x400;
  5663. Info_Sent_Flag = true;
  5664. break;
  5665. default:
  5666. Info_Number = 0;
  5667. break;
  5668. }
  5669. }
  5670. if(i==MAXPARMSIDS-2){ /* to indicate the message type "Setup" */
  5671. Info_Number = 0x8000 |5;
  5672. Info_Mask = 0x10;
  5673. Info_Element = "";
  5674. }
  5675. if(Info_Sent_Flag && Info_Number){
  5676. if(plci->adapter->Info_Mask[appl->Id-1] & Info_Mask) {
  5677. sendf(appl,_INFO_I,Id,0,"wS",Info_Number,Info_Element);
  5678. }
  5679. }
  5680. }
  5681. }
  5682. static void SendInfo(PLCI *plci, dword Id, byte **parms, byte iesent)
  5683. {
  5684. word i;
  5685. word j;
  5686. word k;
  5687. byte * ie;
  5688. word Info_Number;
  5689. byte * Info_Element;
  5690. word Info_Mask = 0;
  5691. static byte charges[5] = {4,0,0,0,0};
  5692. static byte cause[] = {0x02,0x80,0x00};
  5693. APPL *appl;
  5694. dbug(1,dprintf("InfoParse "));
  5695. if(
  5696. !plci->appl
  5697. && !plci->State
  5698. && plci->Sig.Ind!=NCR_FACILITY
  5699. )
  5700. {
  5701. dbug(1,dprintf("NoParse "));
  5702. return;
  5703. }
  5704. cause[2] = 0;
  5705. for(i=0; i<MAXPARMSIDS; i++) {
  5706. ie = parms[i];
  5707. Info_Number = 0;
  5708. Info_Element = ie;
  5709. if(ie[0]) {
  5710. switch(i) {
  5711. case 0:
  5712. dbug(1,dprintf("CPN "));
  5713. Info_Number = 0x0070;
  5714. Info_Mask = 0x80;
  5715. break;
  5716. case 7: /* ESC_CAU */
  5717. dbug(1,dprintf("cau(0x%x)",ie[2]));
  5718. Info_Number = 0x0008;
  5719. Info_Mask = 0x00;
  5720. cause[2] = ie[2];
  5721. Info_Element = NULL;
  5722. break;
  5723. case 8: /* display */
  5724. dbug(1,dprintf("display(%d)",i));
  5725. Info_Number = 0x0028;
  5726. Info_Mask = 0x04;
  5727. break;
  5728. case 9: /* Date display */
  5729. dbug(1,dprintf("date(%d)",i));
  5730. Info_Number = 0x0029;
  5731. Info_Mask = 0x02;
  5732. break;
  5733. case 10: /* charges */
  5734. for(j=0;j<4;j++) charges[1+j] = 0;
  5735. for(j=0; j<ie[0] && !(ie[1+j]&0x80); j++);
  5736. for(k=1,j++; j<ie[0] && k<=4; j++,k++) charges[k] = ie[1+j];
  5737. Info_Number = 0x4000;
  5738. Info_Mask = 0x40;
  5739. Info_Element = charges;
  5740. break;
  5741. case 11: /* user user info */
  5742. dbug(1,dprintf("uui"));
  5743. Info_Number = 0x007E;
  5744. Info_Mask = 0x08;
  5745. break;
  5746. case 12: /* congestion receiver ready */
  5747. dbug(1,dprintf("clRDY"));
  5748. Info_Number = 0x00B0;
  5749. Info_Mask = 0x08;
  5750. Info_Element = "";
  5751. break;
  5752. case 13: /* congestion receiver not ready */
  5753. dbug(1,dprintf("clNRDY"));
  5754. Info_Number = 0x00BF;
  5755. Info_Mask = 0x08;
  5756. Info_Element = "";
  5757. break;
  5758. case 15: /* Keypad Facility */
  5759. dbug(1,dprintf("KEY"));
  5760. Info_Number = 0x002C;
  5761. Info_Mask = 0x20;
  5762. break;
  5763. case 16: /* Channel Id */
  5764. dbug(1,dprintf("CHI"));
  5765. Info_Number = 0x0018;
  5766. Info_Mask = 0x100;
  5767. mixer_set_bchannel_id (plci, Info_Element);
  5768. break;
  5769. case 17: /* if no 1tr6 cause, send full cause, else esc_cause */
  5770. dbug(1,dprintf("q9cau(0x%x)",ie[2]));
  5771. if(!cause[2] || cause[2]<0x80) break; /* eg. layer 1 error */
  5772. Info_Number = 0x0008;
  5773. Info_Mask = 0x01;
  5774. if(cause[2] != ie[2]) Info_Element = cause;
  5775. break;
  5776. case 19: /* Redirected Number */
  5777. dbug(1,dprintf("RDN"));
  5778. Info_Number = 0x0074;
  5779. Info_Mask = 0x400;
  5780. break;
  5781. case 22: /* Redirecing Number */
  5782. dbug(1,dprintf("RIN"));
  5783. Info_Number = 0x0076;
  5784. Info_Mask = 0x400;
  5785. break;
  5786. case 23: /* Notification Indicator */
  5787. dbug(1,dprintf("NI"));
  5788. Info_Number = (word)NI;
  5789. Info_Mask = 0x210;
  5790. break;
  5791. case 26: /* Call State */
  5792. dbug(1,dprintf("CST"));
  5793. Info_Number = (word)CST;
  5794. Info_Mask = 0x01; /* do with cause i.e. for now */
  5795. break;
  5796. case MAXPARMSIDS-2: /* Escape Message Type, must be the last indication */
  5797. dbug(1,dprintf("ESC/MT[0x%x]",ie[3]));
  5798. Info_Number = 0x8000 |ie[3];
  5799. if(iesent) Info_Mask = 0xffff;
  5800. else Info_Mask = 0x10;
  5801. Info_Element = "";
  5802. break;
  5803. default:
  5804. Info_Number = 0;
  5805. Info_Mask = 0;
  5806. Info_Element = "";
  5807. break;
  5808. }
  5809. }
  5810. if(plci->Sig.Ind==NCR_FACILITY) /* check controller broadcast */
  5811. {
  5812. for(j=0; j<max_appl; j++)
  5813. {
  5814. appl = &application[j];
  5815. if(Info_Number
  5816. && appl->Id
  5817. && plci->adapter->Info_Mask[appl->Id-1] &Info_Mask)
  5818. {
  5819. dbug(1,dprintf("NCR_Ind"));
  5820. iesent=true;
  5821. sendf(&application[j],_INFO_I,Id&0x0f,0,"wS",Info_Number,Info_Element);
  5822. }
  5823. }
  5824. }
  5825. else if(!plci->appl)
  5826. { /* overlap receiving broadcast */
  5827. if(Info_Number==CPN
  5828. || Info_Number==KEY
  5829. || Info_Number==NI
  5830. || Info_Number==DSP
  5831. || Info_Number==UUI )
  5832. {
  5833. for(j=0; j<max_appl; j++)
  5834. {
  5835. if(test_c_ind_mask_bit (plci, j))
  5836. {
  5837. dbug(1,dprintf("Ovl_Ind"));
  5838. iesent=true;
  5839. sendf(&application[j],_INFO_I,Id,0,"wS",Info_Number,Info_Element);
  5840. }
  5841. }
  5842. }
  5843. } /* all other signalling states */
  5844. else if(Info_Number
  5845. && plci->adapter->Info_Mask[plci->appl->Id-1] &Info_Mask)
  5846. {
  5847. dbug(1,dprintf("Std_Ind"));
  5848. iesent=true;
  5849. sendf(plci->appl,_INFO_I,Id,0,"wS",Info_Number,Info_Element);
  5850. }
  5851. }
  5852. }
  5853. static byte SendMultiIE(PLCI *plci, dword Id, byte **parms, byte ie_type,
  5854. dword info_mask, byte setupParse)
  5855. {
  5856. word i;
  5857. word j;
  5858. byte * ie;
  5859. word Info_Number;
  5860. byte * Info_Element;
  5861. APPL *appl;
  5862. word Info_Mask = 0;
  5863. byte iesent=0;
  5864. if(
  5865. !plci->appl
  5866. && !plci->State
  5867. && plci->Sig.Ind!=NCR_FACILITY
  5868. && !setupParse
  5869. )
  5870. {
  5871. dbug(1,dprintf("NoM-IEParse "));
  5872. return 0;
  5873. }
  5874. dbug(1,dprintf("M-IEParse "));
  5875. for(i=0; i<MAX_MULTI_IE; i++)
  5876. {
  5877. ie = parms[i];
  5878. Info_Number = 0;
  5879. Info_Element = ie;
  5880. if(ie[0])
  5881. {
  5882. dbug(1,dprintf("[Ind0x%x]:IE=0x%x",plci->Sig.Ind,ie_type));
  5883. Info_Number = (word)ie_type;
  5884. Info_Mask = (word)info_mask;
  5885. }
  5886. if(plci->Sig.Ind==NCR_FACILITY) /* check controller broadcast */
  5887. {
  5888. for(j=0; j<max_appl; j++)
  5889. {
  5890. appl = &application[j];
  5891. if(Info_Number
  5892. && appl->Id
  5893. && plci->adapter->Info_Mask[appl->Id-1] &Info_Mask)
  5894. {
  5895. iesent = true;
  5896. dbug(1,dprintf("Mlt_NCR_Ind"));
  5897. sendf(&application[j],_INFO_I,Id&0x0f,0,"wS",Info_Number,Info_Element);
  5898. }
  5899. }
  5900. }
  5901. else if(!plci->appl && Info_Number)
  5902. { /* overlap receiving broadcast */
  5903. for(j=0; j<max_appl; j++)
  5904. {
  5905. if(test_c_ind_mask_bit (plci, j))
  5906. {
  5907. iesent = true;
  5908. dbug(1,dprintf("Mlt_Ovl_Ind"));
  5909. sendf(&application[j],_INFO_I,Id,0,"wS",Info_Number,Info_Element);
  5910. }
  5911. }
  5912. } /* all other signalling states */
  5913. else if(Info_Number
  5914. && plci->adapter->Info_Mask[plci->appl->Id-1] &Info_Mask)
  5915. {
  5916. iesent = true;
  5917. dbug(1,dprintf("Mlt_Std_Ind"));
  5918. sendf(plci->appl,_INFO_I,Id,0,"wS",Info_Number,Info_Element);
  5919. }
  5920. }
  5921. return iesent;
  5922. }
  5923. static void SendSSExtInd(APPL * appl, PLCI * plci, dword Id, byte * * parms)
  5924. {
  5925. word i;
  5926. /* Format of multi_ssext_parms[i][]:
  5927. 0 byte length
  5928. 1 byte SSEXTIE
  5929. 2 byte SSEXT_REQ/SSEXT_IND
  5930. 3 byte length
  5931. 4 word SSExtCommand
  5932. 6... Params
  5933. */
  5934. if(
  5935. plci
  5936. && plci->State
  5937. && plci->Sig.Ind!=NCR_FACILITY
  5938. )
  5939. for(i=0;i<MAX_MULTI_IE;i++)
  5940. {
  5941. if(parms[i][0]<6) continue;
  5942. if(parms[i][2]==SSEXT_REQ) continue;
  5943. if(appl)
  5944. {
  5945. parms[i][0]=0; /* kill it */
  5946. sendf(appl,_MANUFACTURER_I,
  5947. Id,
  5948. 0,
  5949. "dwS",
  5950. _DI_MANU_ID,
  5951. _DI_SSEXT_CTRL,
  5952. &parms[i][3]);
  5953. }
  5954. else if(plci->appl)
  5955. {
  5956. parms[i][0]=0; /* kill it */
  5957. sendf(plci->appl,_MANUFACTURER_I,
  5958. Id,
  5959. 0,
  5960. "dwS",
  5961. _DI_MANU_ID,
  5962. _DI_SSEXT_CTRL,
  5963. &parms[i][3]);
  5964. }
  5965. }
  5966. };
  5967. static void nl_ind(PLCI *plci)
  5968. {
  5969. byte ch;
  5970. word ncci;
  5971. dword Id;
  5972. DIVA_CAPI_ADAPTER * a;
  5973. word NCCIcode;
  5974. APPL * APPLptr;
  5975. word count;
  5976. word Num;
  5977. word i, ncpi_state;
  5978. byte len, ncci_state;
  5979. word msg;
  5980. word info = 0;
  5981. word fax_feature_bits;
  5982. byte fax_send_edata_ack;
  5983. static byte v120_header_buffer[2 + 3];
  5984. static word fax_info[] = {
  5985. 0, /* T30_SUCCESS */
  5986. _FAX_NO_CONNECTION, /* T30_ERR_NO_DIS_RECEIVED */
  5987. _FAX_PROTOCOL_ERROR, /* T30_ERR_TIMEOUT_NO_RESPONSE */
  5988. _FAX_PROTOCOL_ERROR, /* T30_ERR_RETRY_NO_RESPONSE */
  5989. _FAX_PROTOCOL_ERROR, /* T30_ERR_TOO_MANY_REPEATS */
  5990. _FAX_PROTOCOL_ERROR, /* T30_ERR_UNEXPECTED_MESSAGE */
  5991. _FAX_REMOTE_ABORT, /* T30_ERR_UNEXPECTED_DCN */
  5992. _FAX_LOCAL_ABORT, /* T30_ERR_DTC_UNSUPPORTED */
  5993. _FAX_TRAINING_ERROR, /* T30_ERR_ALL_RATES_FAILED */
  5994. _FAX_TRAINING_ERROR, /* T30_ERR_TOO_MANY_TRAINS */
  5995. _FAX_PARAMETER_ERROR, /* T30_ERR_RECEIVE_CORRUPTED */
  5996. _FAX_REMOTE_ABORT, /* T30_ERR_UNEXPECTED_DISC */
  5997. _FAX_LOCAL_ABORT, /* T30_ERR_APPLICATION_DISC */
  5998. _FAX_REMOTE_REJECT, /* T30_ERR_INCOMPATIBLE_DIS */
  5999. _FAX_LOCAL_ABORT, /* T30_ERR_INCOMPATIBLE_DCS */
  6000. _FAX_PROTOCOL_ERROR, /* T30_ERR_TIMEOUT_NO_COMMAND */
  6001. _FAX_PROTOCOL_ERROR, /* T30_ERR_RETRY_NO_COMMAND */
  6002. _FAX_PROTOCOL_ERROR, /* T30_ERR_TIMEOUT_COMMAND_TOO_LONG */
  6003. _FAX_PROTOCOL_ERROR, /* T30_ERR_TIMEOUT_RESPONSE_TOO_LONG */
  6004. _FAX_NO_CONNECTION, /* T30_ERR_NOT_IDENTIFIED */
  6005. _FAX_PROTOCOL_ERROR, /* T30_ERR_SUPERVISORY_TIMEOUT */
  6006. _FAX_PARAMETER_ERROR, /* T30_ERR_TOO_LONG_SCAN_LINE */
  6007. _FAX_PROTOCOL_ERROR, /* T30_ERR_RETRY_NO_PAGE_AFTER_MPS */
  6008. _FAX_PROTOCOL_ERROR, /* T30_ERR_RETRY_NO_PAGE_AFTER_CFR */
  6009. _FAX_PROTOCOL_ERROR, /* T30_ERR_RETRY_NO_DCS_AFTER_FTT */
  6010. _FAX_PROTOCOL_ERROR, /* T30_ERR_RETRY_NO_DCS_AFTER_EOM */
  6011. _FAX_PROTOCOL_ERROR, /* T30_ERR_RETRY_NO_DCS_AFTER_MPS */
  6012. _FAX_PROTOCOL_ERROR, /* T30_ERR_RETRY_NO_DCN_AFTER_MCF */
  6013. _FAX_PROTOCOL_ERROR, /* T30_ERR_RETRY_NO_DCN_AFTER_RTN */
  6014. _FAX_PROTOCOL_ERROR, /* T30_ERR_RETRY_NO_CFR */
  6015. _FAX_PROTOCOL_ERROR, /* T30_ERR_RETRY_NO_MCF_AFTER_EOP */
  6016. _FAX_PROTOCOL_ERROR, /* T30_ERR_RETRY_NO_MCF_AFTER_EOM */
  6017. _FAX_PROTOCOL_ERROR, /* T30_ERR_RETRY_NO_MCF_AFTER_MPS */
  6018. 0x331d, /* T30_ERR_SUB_SEP_UNSUPPORTED */
  6019. 0x331e, /* T30_ERR_PWD_UNSUPPORTED */
  6020. 0x331f, /* T30_ERR_SUB_SEP_PWD_UNSUPPORTED */
  6021. _FAX_PROTOCOL_ERROR, /* T30_ERR_INVALID_COMMAND_FRAME */
  6022. _FAX_PARAMETER_ERROR, /* T30_ERR_UNSUPPORTED_PAGE_CODING */
  6023. _FAX_PARAMETER_ERROR, /* T30_ERR_INVALID_PAGE_CODING */
  6024. _FAX_REMOTE_REJECT, /* T30_ERR_INCOMPATIBLE_PAGE_CONFIG */
  6025. _FAX_LOCAL_ABORT, /* T30_ERR_TIMEOUT_FROM_APPLICATION */
  6026. _FAX_PROTOCOL_ERROR, /* T30_ERR_V34FAX_NO_REACTION_ON_MARK */
  6027. _FAX_PROTOCOL_ERROR, /* T30_ERR_V34FAX_TRAINING_TIMEOUT */
  6028. _FAX_PROTOCOL_ERROR, /* T30_ERR_V34FAX_UNEXPECTED_V21 */
  6029. _FAX_PROTOCOL_ERROR, /* T30_ERR_V34FAX_PRIMARY_CTS_ON */
  6030. _FAX_LOCAL_ABORT, /* T30_ERR_V34FAX_TURNAROUND_POLLING */
  6031. _FAX_LOCAL_ABORT /* T30_ERR_V34FAX_V8_INCOMPATIBILITY */
  6032. };
  6033. byte dtmf_code_buffer[CAPIDTMF_RECV_DIGIT_BUFFER_SIZE + 1];
  6034. static word rtp_info[] = {
  6035. GOOD, /* RTP_SUCCESS */
  6036. 0x3600 /* RTP_ERR_SSRC_OR_PAYLOAD_CHANGE */
  6037. };
  6038. static dword udata_forwarding_table[0x100 / sizeof(dword)] =
  6039. {
  6040. 0x0020301e, 0x00000000, 0x00000000, 0x00000000,
  6041. 0x00000000, 0x00000000, 0x00000000, 0x00000000
  6042. };
  6043. ch = plci->NL.IndCh;
  6044. a = plci->adapter;
  6045. ncci = a->ch_ncci[ch];
  6046. Id = (((dword)(ncci ? ncci : ch)) << 16) | (((word) plci->Id) << 8) | a->Id;
  6047. if(plci->tel) Id|=EXT_CONTROLLER;
  6048. APPLptr = plci->appl;
  6049. 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",
  6050. plci->NL.Id,Id,plci->Id,plci->tel,plci->State,ch,plci->channels,plci->NL.Ind &0x0f));
  6051. /* in the case if no connect_active_Ind was sent to the appl we wait for */
  6052. if (plci->nl_remove_id)
  6053. {
  6054. plci->NL.RNR = 2; /* discard */
  6055. dbug(1,dprintf("NL discard while remove pending"));
  6056. return;
  6057. }
  6058. if((plci->NL.Ind &0x0f)==N_CONNECT)
  6059. {
  6060. if(plci->State==INC_DIS_PENDING
  6061. || plci->State==OUTG_DIS_PENDING
  6062. || plci->State==IDLE)
  6063. {
  6064. plci->NL.RNR = 2; /* discard */
  6065. dbug(1,dprintf("discard n_connect"));
  6066. return;
  6067. }
  6068. if(plci->State < INC_ACT_PENDING)
  6069. {
  6070. plci->NL.RNR = 1; /* flow control */
  6071. channel_x_off (plci, ch, N_XON_CONNECT_IND);
  6072. return;
  6073. }
  6074. }
  6075. if(!APPLptr) /* no application or invalid data */
  6076. { /* while reloading the DSP */
  6077. dbug(1,dprintf("discard1"));
  6078. plci->NL.RNR = 2;
  6079. return;
  6080. }
  6081. if (((plci->NL.Ind &0x0f) == N_UDATA)
  6082. && (((plci->B2_prot != B2_SDLC) && ((plci->B1_resource == 17) || (plci->B1_resource == 18)))
  6083. || (plci->B2_prot == 7)
  6084. || (plci->B3_prot == 7)) )
  6085. {
  6086. plci->ncpi_buffer[0] = 0;
  6087. ncpi_state = plci->ncpi_state;
  6088. if (plci->NL.complete == 1)
  6089. {
  6090. byte * data = &plci->NL.RBuffer->P[0];
  6091. if ((plci->NL.RBuffer->length >= 12)
  6092. &&( (*data == DSP_UDATA_INDICATION_DCD_ON)
  6093. ||(*data == DSP_UDATA_INDICATION_CTS_ON)) )
  6094. {
  6095. word conn_opt, ncpi_opt = 0x00;
  6096. /* HexDump ("MDM N_UDATA:", plci->NL.RBuffer->length, data); */
  6097. if (*data == DSP_UDATA_INDICATION_DCD_ON)
  6098. plci->ncpi_state |= NCPI_MDM_DCD_ON_RECEIVED;
  6099. if (*data == DSP_UDATA_INDICATION_CTS_ON)
  6100. plci->ncpi_state |= NCPI_MDM_CTS_ON_RECEIVED;
  6101. data++; /* indication code */
  6102. data += 2; /* timestamp */
  6103. if ((*data == DSP_CONNECTED_NORM_V18) || (*data == DSP_CONNECTED_NORM_VOWN))
  6104. ncpi_state &= ~(NCPI_MDM_DCD_ON_RECEIVED | NCPI_MDM_CTS_ON_RECEIVED);
  6105. data++; /* connected norm */
  6106. conn_opt = GET_WORD(data);
  6107. data += 2; /* connected options */
  6108. PUT_WORD (&(plci->ncpi_buffer[1]), (word)(GET_DWORD(data) & 0x0000FFFF));
  6109. if (conn_opt & DSP_CONNECTED_OPTION_MASK_V42)
  6110. {
  6111. ncpi_opt |= MDM_NCPI_ECM_V42;
  6112. }
  6113. else if (conn_opt & DSP_CONNECTED_OPTION_MASK_MNP)
  6114. {
  6115. ncpi_opt |= MDM_NCPI_ECM_MNP;
  6116. }
  6117. else
  6118. {
  6119. ncpi_opt |= MDM_NCPI_TRANSPARENT;
  6120. }
  6121. if (conn_opt & DSP_CONNECTED_OPTION_MASK_COMPRESSION)
  6122. {
  6123. ncpi_opt |= MDM_NCPI_COMPRESSED;
  6124. }
  6125. PUT_WORD (&(plci->ncpi_buffer[3]), ncpi_opt);
  6126. plci->ncpi_buffer[0] = 4;
  6127. plci->ncpi_state |= NCPI_VALID_CONNECT_B3_IND | NCPI_VALID_CONNECT_B3_ACT | NCPI_VALID_DISC_B3_IND;
  6128. }
  6129. }
  6130. if (plci->B3_prot == 7)
  6131. {
  6132. if (((a->ncci_state[ncci] == INC_ACT_PENDING) || (a->ncci_state[ncci] == OUTG_CON_PENDING))
  6133. && (plci->ncpi_state & NCPI_VALID_CONNECT_B3_ACT)
  6134. && !(plci->ncpi_state & NCPI_CONNECT_B3_ACT_SENT))
  6135. {
  6136. a->ncci_state[ncci] = INC_ACT_PENDING;
  6137. sendf(plci->appl,_CONNECT_B3_ACTIVE_I,Id,0,"S",plci->ncpi_buffer);
  6138. plci->ncpi_state |= NCPI_CONNECT_B3_ACT_SENT;
  6139. }
  6140. }
  6141. if (!((plci->requested_options_conn | plci->requested_options | plci->adapter->requested_options_table[plci->appl->Id-1])
  6142. & ((1L << PRIVATE_V18) | (1L << PRIVATE_VOWN)))
  6143. || !(ncpi_state & NCPI_MDM_DCD_ON_RECEIVED)
  6144. || !(ncpi_state & NCPI_MDM_CTS_ON_RECEIVED))
  6145. {
  6146. plci->NL.RNR = 2;
  6147. return;
  6148. }
  6149. }
  6150. if(plci->NL.complete == 2)
  6151. {
  6152. if (((plci->NL.Ind &0x0f) == N_UDATA)
  6153. && !(udata_forwarding_table[plci->RData[0].P[0] >> 5] & (1L << (plci->RData[0].P[0] & 0x1f))))
  6154. {
  6155. switch(plci->RData[0].P[0])
  6156. {
  6157. case DTMF_UDATA_INDICATION_FAX_CALLING_TONE:
  6158. if (plci->dtmf_rec_active & DTMF_LISTEN_ACTIVE_FLAG)
  6159. sendf(plci->appl, _FACILITY_I, Id & 0xffffL, 0,"ws", SELECTOR_DTMF, "\x01X");
  6160. break;
  6161. case DTMF_UDATA_INDICATION_ANSWER_TONE:
  6162. if (plci->dtmf_rec_active & DTMF_LISTEN_ACTIVE_FLAG)
  6163. sendf(plci->appl, _FACILITY_I, Id & 0xffffL, 0,"ws", SELECTOR_DTMF, "\x01Y");
  6164. break;
  6165. case DTMF_UDATA_INDICATION_DIGITS_RECEIVED:
  6166. dtmf_indication (Id, plci, plci->RData[0].P, plci->RData[0].PLength);
  6167. break;
  6168. case DTMF_UDATA_INDICATION_DIGITS_SENT:
  6169. dtmf_confirmation (Id, plci);
  6170. break;
  6171. case UDATA_INDICATION_MIXER_TAP_DATA:
  6172. capidtmf_recv_process_block (&(plci->capidtmf_state), plci->RData[0].P + 1, (word)(plci->RData[0].PLength - 1));
  6173. i = capidtmf_indication (&(plci->capidtmf_state), dtmf_code_buffer + 1);
  6174. if (i != 0)
  6175. {
  6176. dtmf_code_buffer[0] = DTMF_UDATA_INDICATION_DIGITS_RECEIVED;
  6177. dtmf_indication (Id, plci, dtmf_code_buffer, (word)(i + 1));
  6178. }
  6179. break;
  6180. case UDATA_INDICATION_MIXER_COEFS_SET:
  6181. mixer_indication_coefs_set (Id, plci);
  6182. break;
  6183. case UDATA_INDICATION_XCONNECT_FROM:
  6184. mixer_indication_xconnect_from (Id, plci, plci->RData[0].P, plci->RData[0].PLength);
  6185. break;
  6186. case UDATA_INDICATION_XCONNECT_TO:
  6187. mixer_indication_xconnect_to (Id, plci, plci->RData[0].P, plci->RData[0].PLength);
  6188. break;
  6189. case LEC_UDATA_INDICATION_DISABLE_DETECT:
  6190. ec_indication (Id, plci, plci->RData[0].P, plci->RData[0].PLength);
  6191. break;
  6192. default:
  6193. break;
  6194. }
  6195. }
  6196. else
  6197. {
  6198. if ((plci->RData[0].PLength != 0)
  6199. && ((plci->B2_prot == B2_V120_ASYNC)
  6200. || (plci->B2_prot == B2_V120_ASYNC_V42BIS)
  6201. || (plci->B2_prot == B2_V120_BIT_TRANSPARENT)))
  6202. {
  6203. sendf(plci->appl,_DATA_B3_I,Id,0,
  6204. "dwww",
  6205. plci->RData[1].P,
  6206. (plci->NL.RNum < 2) ? 0 : plci->RData[1].PLength,
  6207. plci->RNum,
  6208. plci->RFlags);
  6209. }
  6210. else
  6211. {
  6212. sendf(plci->appl,_DATA_B3_I,Id,0,
  6213. "dwww",
  6214. plci->RData[0].P,
  6215. plci->RData[0].PLength,
  6216. plci->RNum,
  6217. plci->RFlags);
  6218. }
  6219. }
  6220. return;
  6221. }
  6222. fax_feature_bits = 0;
  6223. if((plci->NL.Ind &0x0f)==N_CONNECT ||
  6224. (plci->NL.Ind &0x0f)==N_CONNECT_ACK ||
  6225. (plci->NL.Ind &0x0f)==N_DISC ||
  6226. (plci->NL.Ind &0x0f)==N_EDATA ||
  6227. (plci->NL.Ind &0x0f)==N_DISC_ACK)
  6228. {
  6229. info = 0;
  6230. plci->ncpi_buffer[0] = 0;
  6231. switch (plci->B3_prot) {
  6232. case 0: /*XPARENT*/
  6233. case 1: /*T.90 NL*/
  6234. break; /* no network control protocol info - jfr */
  6235. case 2: /*ISO8202*/
  6236. case 3: /*X25 DCE*/
  6237. for(i=0; i<plci->NL.RLength; i++) plci->ncpi_buffer[4+i] = plci->NL.RBuffer->P[i];
  6238. plci->ncpi_buffer[0] = (byte)(i+3);
  6239. plci->ncpi_buffer[1] = (byte)(plci->NL.Ind &N_D_BIT? 1:0);
  6240. plci->ncpi_buffer[2] = 0;
  6241. plci->ncpi_buffer[3] = 0;
  6242. break;
  6243. case 4: /*T.30 - FAX*/
  6244. case 5: /*T.30 - FAX*/
  6245. if(plci->NL.RLength>=sizeof(T30_INFO))
  6246. {
  6247. dbug(1,dprintf("FaxStatus %04x", ((T30_INFO *)plci->NL.RBuffer->P)->code));
  6248. len = 9;
  6249. PUT_WORD(&(plci->ncpi_buffer[1]),((T30_INFO *)plci->NL.RBuffer->P)->rate_div_2400 * 2400);
  6250. fax_feature_bits = GET_WORD(&((T30_INFO *)plci->NL.RBuffer->P)->feature_bits_low);
  6251. i = (((T30_INFO *)plci->NL.RBuffer->P)->resolution & T30_RESOLUTION_R8_0770_OR_200) ? 0x0001 : 0x0000;
  6252. if (plci->B3_prot == 5)
  6253. {
  6254. if (!(fax_feature_bits & T30_FEATURE_BIT_ECM))
  6255. i |= 0x8000; /* This is not an ECM connection */
  6256. if (fax_feature_bits & T30_FEATURE_BIT_T6_CODING)
  6257. i |= 0x4000; /* This is a connection with MMR compression */
  6258. if (fax_feature_bits & T30_FEATURE_BIT_2D_CODING)
  6259. i |= 0x2000; /* This is a connection with MR compression */
  6260. if (fax_feature_bits & T30_FEATURE_BIT_MORE_DOCUMENTS)
  6261. i |= 0x0004; /* More documents */
  6262. if (fax_feature_bits & T30_FEATURE_BIT_POLLING)
  6263. i |= 0x0002; /* Fax-polling indication */
  6264. }
  6265. dbug(1,dprintf("FAX Options %04x %04x",fax_feature_bits,i));
  6266. PUT_WORD(&(plci->ncpi_buffer[3]),i);
  6267. PUT_WORD(&(plci->ncpi_buffer[5]),((T30_INFO *)plci->NL.RBuffer->P)->data_format);
  6268. plci->ncpi_buffer[7] = ((T30_INFO *)plci->NL.RBuffer->P)->pages_low;
  6269. plci->ncpi_buffer[8] = ((T30_INFO *)plci->NL.RBuffer->P)->pages_high;
  6270. plci->ncpi_buffer[len] = 0;
  6271. if(((T30_INFO *)plci->NL.RBuffer->P)->station_id_len)
  6272. {
  6273. plci->ncpi_buffer[len] = 20;
  6274. for (i = 0; i < 20; i++)
  6275. plci->ncpi_buffer[++len] = ((T30_INFO *)plci->NL.RBuffer->P)->station_id[i];
  6276. }
  6277. if (((plci->NL.Ind & 0x0f) == N_DISC) || ((plci->NL.Ind & 0x0f) == N_DISC_ACK))
  6278. {
  6279. if (((T30_INFO *)plci->NL.RBuffer->P)->code < ARRAY_SIZE(fax_info))
  6280. info = fax_info[((T30_INFO *)plci->NL.RBuffer->P)->code];
  6281. else
  6282. info = _FAX_PROTOCOL_ERROR;
  6283. }
  6284. if ((plci->requested_options_conn | plci->requested_options | a->requested_options_table[plci->appl->Id-1])
  6285. & ((1L << PRIVATE_FAX_SUB_SEP_PWD) | (1L << PRIVATE_FAX_NONSTANDARD)))
  6286. {
  6287. i = ((word)(((T30_INFO *) 0)->station_id + 20)) + ((T30_INFO *)plci->NL.RBuffer->P)->head_line_len;
  6288. while (i < plci->NL.RBuffer->length)
  6289. plci->ncpi_buffer[++len] = plci->NL.RBuffer->P[i++];
  6290. }
  6291. plci->ncpi_buffer[0] = len;
  6292. fax_feature_bits = GET_WORD(&((T30_INFO *)plci->NL.RBuffer->P)->feature_bits_low);
  6293. PUT_WORD(&((T30_INFO *)plci->fax_connect_info_buffer)->feature_bits_low, fax_feature_bits);
  6294. plci->ncpi_state |= NCPI_VALID_CONNECT_B3_IND;
  6295. if (((plci->NL.Ind &0x0f) == N_CONNECT_ACK)
  6296. || (((plci->NL.Ind &0x0f) == N_CONNECT)
  6297. && (fax_feature_bits & T30_FEATURE_BIT_POLLING))
  6298. || (((plci->NL.Ind &0x0f) == N_EDATA)
  6299. && ((((T30_INFO *)plci->NL.RBuffer->P)->code == EDATA_T30_TRAIN_OK)
  6300. || (((T30_INFO *)plci->NL.RBuffer->P)->code == EDATA_T30_DIS)
  6301. || (((T30_INFO *)plci->NL.RBuffer->P)->code == EDATA_T30_DTC))))
  6302. {
  6303. plci->ncpi_state |= NCPI_VALID_CONNECT_B3_ACT;
  6304. }
  6305. if (((plci->NL.Ind &0x0f) == N_DISC)
  6306. || ((plci->NL.Ind &0x0f) == N_DISC_ACK)
  6307. || (((plci->NL.Ind &0x0f) == N_EDATA)
  6308. && (((T30_INFO *)plci->NL.RBuffer->P)->code == EDATA_T30_EOP_CAPI)))
  6309. {
  6310. plci->ncpi_state |= NCPI_VALID_CONNECT_B3_ACT | NCPI_VALID_DISC_B3_IND;
  6311. }
  6312. }
  6313. break;
  6314. case B3_RTP:
  6315. if (((plci->NL.Ind & 0x0f) == N_DISC) || ((plci->NL.Ind & 0x0f) == N_DISC_ACK))
  6316. {
  6317. if (plci->NL.RLength != 0)
  6318. {
  6319. info = rtp_info[plci->NL.RBuffer->P[0]];
  6320. plci->ncpi_buffer[0] = plci->NL.RLength - 1;
  6321. for (i = 1; i < plci->NL.RLength; i++)
  6322. plci->ncpi_buffer[i] = plci->NL.RBuffer->P[i];
  6323. }
  6324. }
  6325. break;
  6326. }
  6327. plci->NL.RNR = 2;
  6328. }
  6329. switch(plci->NL.Ind &0x0f) {
  6330. case N_EDATA:
  6331. if ((plci->B3_prot == 4) || (plci->B3_prot == 5))
  6332. {
  6333. dbug(1,dprintf("EDATA ncci=0x%x state=%d code=%02x", ncci, a->ncci_state[ncci],
  6334. ((T30_INFO *)plci->NL.RBuffer->P)->code));
  6335. fax_send_edata_ack = (((T30_INFO *)(plci->fax_connect_info_buffer))->operating_mode == T30_OPERATING_MODE_CAPI_NEG);
  6336. if ((plci->nsf_control_bits & T30_NSF_CONTROL_BIT_ENABLE_NSF)
  6337. && (plci->nsf_control_bits & (T30_NSF_CONTROL_BIT_NEGOTIATE_IND | T30_NSF_CONTROL_BIT_NEGOTIATE_RESP))
  6338. && (((T30_INFO *)plci->NL.RBuffer->P)->code == EDATA_T30_DIS)
  6339. && (a->ncci_state[ncci] == OUTG_CON_PENDING)
  6340. && (plci->ncpi_state & NCPI_VALID_CONNECT_B3_ACT)
  6341. && !(plci->ncpi_state & NCPI_NEGOTIATE_B3_SENT))
  6342. {
  6343. ((T30_INFO *)(plci->fax_connect_info_buffer))->code = ((T30_INFO *)plci->NL.RBuffer->P)->code;
  6344. sendf(plci->appl,_MANUFACTURER_I,Id,0,"dwbS",_DI_MANU_ID,_DI_NEGOTIATE_B3,
  6345. (byte)(plci->ncpi_buffer[0] + 1), plci->ncpi_buffer);
  6346. plci->ncpi_state |= NCPI_NEGOTIATE_B3_SENT;
  6347. if (plci->nsf_control_bits & T30_NSF_CONTROL_BIT_NEGOTIATE_RESP)
  6348. fax_send_edata_ack = false;
  6349. }
  6350. if (a->manufacturer_features & MANUFACTURER_FEATURE_FAX_PAPER_FORMATS)
  6351. {
  6352. switch (((T30_INFO *)plci->NL.RBuffer->P)->code)
  6353. {
  6354. case EDATA_T30_DIS:
  6355. if ((a->ncci_state[ncci] == OUTG_CON_PENDING)
  6356. && !(GET_WORD(&((T30_INFO *)plci->fax_connect_info_buffer)->control_bits_low) & T30_CONTROL_BIT_REQUEST_POLLING)
  6357. && (plci->ncpi_state & NCPI_VALID_CONNECT_B3_ACT)
  6358. && !(plci->ncpi_state & NCPI_CONNECT_B3_ACT_SENT))
  6359. {
  6360. a->ncci_state[ncci] = INC_ACT_PENDING;
  6361. if (plci->B3_prot == 4)
  6362. sendf(plci->appl,_CONNECT_B3_ACTIVE_I,Id,0,"s","");
  6363. else
  6364. sendf(plci->appl,_CONNECT_B3_ACTIVE_I,Id,0,"S",plci->ncpi_buffer);
  6365. plci->ncpi_state |= NCPI_CONNECT_B3_ACT_SENT;
  6366. }
  6367. break;
  6368. case EDATA_T30_TRAIN_OK:
  6369. if ((a->ncci_state[ncci] == INC_ACT_PENDING)
  6370. && (plci->ncpi_state & NCPI_VALID_CONNECT_B3_ACT)
  6371. && !(plci->ncpi_state & NCPI_CONNECT_B3_ACT_SENT))
  6372. {
  6373. if (plci->B3_prot == 4)
  6374. sendf(plci->appl,_CONNECT_B3_ACTIVE_I,Id,0,"s","");
  6375. else
  6376. sendf(plci->appl,_CONNECT_B3_ACTIVE_I,Id,0,"S",plci->ncpi_buffer);
  6377. plci->ncpi_state |= NCPI_CONNECT_B3_ACT_SENT;
  6378. }
  6379. break;
  6380. case EDATA_T30_EOP_CAPI:
  6381. if (a->ncci_state[ncci] == CONNECTED)
  6382. {
  6383. sendf(plci->appl,_DISCONNECT_B3_I,Id,0,"wS",GOOD,plci->ncpi_buffer);
  6384. a->ncci_state[ncci] = INC_DIS_PENDING;
  6385. plci->ncpi_state = 0;
  6386. fax_send_edata_ack = false;
  6387. }
  6388. break;
  6389. }
  6390. }
  6391. else
  6392. {
  6393. switch (((T30_INFO *)plci->NL.RBuffer->P)->code)
  6394. {
  6395. case EDATA_T30_TRAIN_OK:
  6396. if ((a->ncci_state[ncci] == INC_ACT_PENDING)
  6397. && (plci->ncpi_state & NCPI_VALID_CONNECT_B3_ACT)
  6398. && !(plci->ncpi_state & NCPI_CONNECT_B3_ACT_SENT))
  6399. {
  6400. if (plci->B3_prot == 4)
  6401. sendf(plci->appl,_CONNECT_B3_ACTIVE_I,Id,0,"s","");
  6402. else
  6403. sendf(plci->appl,_CONNECT_B3_ACTIVE_I,Id,0,"S",plci->ncpi_buffer);
  6404. plci->ncpi_state |= NCPI_CONNECT_B3_ACT_SENT;
  6405. }
  6406. break;
  6407. }
  6408. }
  6409. if (fax_send_edata_ack)
  6410. {
  6411. ((T30_INFO *)(plci->fax_connect_info_buffer))->code = ((T30_INFO *)plci->NL.RBuffer->P)->code;
  6412. plci->fax_edata_ack_length = 1;
  6413. start_internal_command (Id, plci, fax_edata_ack_command);
  6414. }
  6415. }
  6416. else
  6417. {
  6418. dbug(1,dprintf("EDATA ncci=0x%x state=%d", ncci, a->ncci_state[ncci]));
  6419. }
  6420. break;
  6421. case N_CONNECT:
  6422. if (!a->ch_ncci[ch])
  6423. {
  6424. ncci = get_ncci (plci, ch, 0);
  6425. Id = (Id & 0xffff) | (((dword) ncci) << 16);
  6426. }
  6427. dbug(1,dprintf("N_CONNECT: ch=%d state=%d plci=%lx plci_Id=%lx plci_State=%d",
  6428. ch, a->ncci_state[ncci], a->ncci_plci[ncci], plci->Id, plci->State));
  6429. msg = _CONNECT_B3_I;
  6430. if (a->ncci_state[ncci] == IDLE)
  6431. plci->channels++;
  6432. else if (plci->B3_prot == 1)
  6433. msg = _CONNECT_B3_T90_ACTIVE_I;
  6434. a->ncci_state[ncci] = INC_CON_PENDING;
  6435. if(plci->B3_prot == 4)
  6436. sendf(plci->appl,msg,Id,0,"s","");
  6437. else
  6438. sendf(plci->appl,msg,Id,0,"S",plci->ncpi_buffer);
  6439. break;
  6440. case N_CONNECT_ACK:
  6441. dbug(1,dprintf("N_connect_Ack"));
  6442. if (plci->internal_command_queue[0]
  6443. && ((plci->adjust_b_state == ADJUST_B_CONNECT_2)
  6444. || (plci->adjust_b_state == ADJUST_B_CONNECT_3)
  6445. || (plci->adjust_b_state == ADJUST_B_CONNECT_4)))
  6446. {
  6447. (*(plci->internal_command_queue[0]))(Id, plci, 0);
  6448. if (!plci->internal_command)
  6449. next_internal_command (Id, plci);
  6450. break;
  6451. }
  6452. msg = _CONNECT_B3_ACTIVE_I;
  6453. if (plci->B3_prot == 1)
  6454. {
  6455. if (a->ncci_state[ncci] != OUTG_CON_PENDING)
  6456. msg = _CONNECT_B3_T90_ACTIVE_I;
  6457. a->ncci_state[ncci] = INC_ACT_PENDING;
  6458. sendf(plci->appl,msg,Id,0,"S",plci->ncpi_buffer);
  6459. }
  6460. else if ((plci->B3_prot == 4) || (plci->B3_prot == 5) || (plci->B3_prot == 7))
  6461. {
  6462. if ((a->ncci_state[ncci] == OUTG_CON_PENDING)
  6463. && (plci->ncpi_state & NCPI_VALID_CONNECT_B3_ACT)
  6464. && !(plci->ncpi_state & NCPI_CONNECT_B3_ACT_SENT))
  6465. {
  6466. a->ncci_state[ncci] = INC_ACT_PENDING;
  6467. if (plci->B3_prot == 4)
  6468. sendf(plci->appl,msg,Id,0,"s","");
  6469. else
  6470. sendf(plci->appl,msg,Id,0,"S",plci->ncpi_buffer);
  6471. plci->ncpi_state |= NCPI_CONNECT_B3_ACT_SENT;
  6472. }
  6473. }
  6474. else
  6475. {
  6476. a->ncci_state[ncci] = INC_ACT_PENDING;
  6477. sendf(plci->appl,msg,Id,0,"S",plci->ncpi_buffer);
  6478. }
  6479. if (plci->adjust_b_restore)
  6480. {
  6481. plci->adjust_b_restore = false;
  6482. start_internal_command (Id, plci, adjust_b_restore);
  6483. }
  6484. break;
  6485. case N_DISC:
  6486. case N_DISC_ACK:
  6487. if (plci->internal_command_queue[0]
  6488. && ((plci->internal_command == FAX_DISCONNECT_COMMAND_1)
  6489. || (plci->internal_command == FAX_DISCONNECT_COMMAND_2)
  6490. || (plci->internal_command == FAX_DISCONNECT_COMMAND_3)))
  6491. {
  6492. (*(plci->internal_command_queue[0]))(Id, plci, 0);
  6493. if (!plci->internal_command)
  6494. next_internal_command (Id, plci);
  6495. }
  6496. ncci_state = a->ncci_state[ncci];
  6497. ncci_remove (plci, ncci, false);
  6498. /* with N_DISC or N_DISC_ACK the IDI frees the respective */
  6499. /* channel, so we cannot store the state in ncci_state! The */
  6500. /* information which channel we received a N_DISC is thus */
  6501. /* stored in the inc_dis_ncci_table buffer. */
  6502. for(i=0; plci->inc_dis_ncci_table[i]; i++);
  6503. plci->inc_dis_ncci_table[i] = (byte) ncci;
  6504. /* need a connect_b3_ind before a disconnect_b3_ind with FAX */
  6505. if (!plci->channels
  6506. && (plci->B1_resource == 16)
  6507. && (plci->State <= CONNECTED))
  6508. {
  6509. len = 9;
  6510. i = ((T30_INFO *)plci->fax_connect_info_buffer)->rate_div_2400 * 2400;
  6511. PUT_WORD (&plci->ncpi_buffer[1], i);
  6512. PUT_WORD (&plci->ncpi_buffer[3], 0);
  6513. i = ((T30_INFO *)plci->fax_connect_info_buffer)->data_format;
  6514. PUT_WORD (&plci->ncpi_buffer[5], i);
  6515. PUT_WORD (&plci->ncpi_buffer[7], 0);
  6516. plci->ncpi_buffer[len] = 0;
  6517. plci->ncpi_buffer[0] = len;
  6518. if(plci->B3_prot == 4)
  6519. sendf(plci->appl,_CONNECT_B3_I,Id,0,"s","");
  6520. else
  6521. {
  6522. if ((plci->requested_options_conn | plci->requested_options | a->requested_options_table[plci->appl->Id-1])
  6523. & ((1L << PRIVATE_FAX_SUB_SEP_PWD) | (1L << PRIVATE_FAX_NONSTANDARD)))
  6524. {
  6525. plci->ncpi_buffer[++len] = 0;
  6526. plci->ncpi_buffer[++len] = 0;
  6527. plci->ncpi_buffer[++len] = 0;
  6528. plci->ncpi_buffer[0] = len;
  6529. }
  6530. sendf(plci->appl,_CONNECT_B3_I,Id,0,"S",plci->ncpi_buffer);
  6531. }
  6532. sendf(plci->appl,_DISCONNECT_B3_I,Id,0,"wS",info,plci->ncpi_buffer);
  6533. plci->ncpi_state = 0;
  6534. sig_req(plci,HANGUP,0);
  6535. send_req(plci);
  6536. plci->State = OUTG_DIS_PENDING;
  6537. /* disc here */
  6538. }
  6539. else if ((a->manufacturer_features & MANUFACTURER_FEATURE_FAX_PAPER_FORMATS)
  6540. && ((plci->B3_prot == 4) || (plci->B3_prot == 5))
  6541. && ((ncci_state == INC_DIS_PENDING) || (ncci_state == IDLE)))
  6542. {
  6543. if (ncci_state == IDLE)
  6544. {
  6545. if (plci->channels)
  6546. plci->channels--;
  6547. if((plci->State==IDLE || plci->State==SUSPENDING) && !plci->channels){
  6548. if(plci->State == SUSPENDING){
  6549. sendf(plci->appl,
  6550. _FACILITY_I,
  6551. Id & 0xffffL,
  6552. 0,
  6553. "ws", (word)3, "\x03\x04\x00\x00");
  6554. sendf(plci->appl, _DISCONNECT_I, Id & 0xffffL, 0, "w", 0);
  6555. }
  6556. plci_remove(plci);
  6557. plci->State=IDLE;
  6558. }
  6559. }
  6560. }
  6561. else if (plci->channels)
  6562. {
  6563. sendf(plci->appl,_DISCONNECT_B3_I,Id,0,"wS",info,plci->ncpi_buffer);
  6564. plci->ncpi_state = 0;
  6565. if ((ncci_state == OUTG_REJ_PENDING)
  6566. && ((plci->B3_prot != B3_T90NL) && (plci->B3_prot != B3_ISO8208) && (plci->B3_prot != B3_X25_DCE)))
  6567. {
  6568. sig_req(plci,HANGUP,0);
  6569. send_req(plci);
  6570. plci->State = OUTG_DIS_PENDING;
  6571. }
  6572. }
  6573. break;
  6574. case N_RESET:
  6575. a->ncci_state[ncci] = INC_RES_PENDING;
  6576. sendf(plci->appl,_RESET_B3_I,Id,0,"S",plci->ncpi_buffer);
  6577. break;
  6578. case N_RESET_ACK:
  6579. a->ncci_state[ncci] = CONNECTED;
  6580. sendf(plci->appl,_RESET_B3_I,Id,0,"S",plci->ncpi_buffer);
  6581. break;
  6582. case N_UDATA:
  6583. if (!(udata_forwarding_table[plci->NL.RBuffer->P[0] >> 5] & (1L << (plci->NL.RBuffer->P[0] & 0x1f))))
  6584. {
  6585. plci->RData[0].P = plci->internal_ind_buffer + (-((int)(long)(plci->internal_ind_buffer)) & 3);
  6586. plci->RData[0].PLength = INTERNAL_IND_BUFFER_SIZE;
  6587. plci->NL.R = plci->RData;
  6588. plci->NL.RNum = 1;
  6589. return;
  6590. }
  6591. case N_BDATA:
  6592. case N_DATA:
  6593. if (((a->ncci_state[ncci] != CONNECTED) && (plci->B2_prot == 1)) /* transparent */
  6594. || (a->ncci_state[ncci] == IDLE)
  6595. || (a->ncci_state[ncci] == INC_DIS_PENDING))
  6596. {
  6597. plci->NL.RNR = 2;
  6598. break;
  6599. }
  6600. if ((a->ncci_state[ncci] != CONNECTED)
  6601. && (a->ncci_state[ncci] != OUTG_DIS_PENDING)
  6602. && (a->ncci_state[ncci] != OUTG_REJ_PENDING))
  6603. {
  6604. dbug(1,dprintf("flow control"));
  6605. plci->NL.RNR = 1; /* flow control */
  6606. channel_x_off (plci, ch, 0);
  6607. break;
  6608. }
  6609. NCCIcode = ncci | (((word)a->Id) << 8);
  6610. /* count all buffers within the Application pool */
  6611. /* belonging to the same NCCI. If this is below the */
  6612. /* number of buffers available per NCCI we accept */
  6613. /* this packet, otherwise we reject it */
  6614. count = 0;
  6615. Num = 0xffff;
  6616. for(i=0; i<APPLptr->MaxBuffer; i++) {
  6617. if(NCCIcode==APPLptr->DataNCCI[i]) count++;
  6618. if(!APPLptr->DataNCCI[i] && Num==0xffff) Num = i;
  6619. }
  6620. if(count>=APPLptr->MaxNCCIData || Num==0xffff)
  6621. {
  6622. dbug(3,dprintf("Flow-Control"));
  6623. plci->NL.RNR = 1;
  6624. if( ++(APPLptr->NCCIDataFlowCtrlTimer)>=
  6625. (word)((a->manufacturer_features & MANUFACTURER_FEATURE_OOB_CHANNEL) ? 40 : 2000))
  6626. {
  6627. plci->NL.RNR = 2;
  6628. dbug(3,dprintf("DiscardData"));
  6629. } else {
  6630. channel_x_off (plci, ch, 0);
  6631. }
  6632. break;
  6633. }
  6634. else
  6635. {
  6636. APPLptr->NCCIDataFlowCtrlTimer = 0;
  6637. }
  6638. plci->RData[0].P = ReceiveBufferGet(APPLptr,Num);
  6639. if(!plci->RData[0].P) {
  6640. plci->NL.RNR = 1;
  6641. channel_x_off (plci, ch, 0);
  6642. break;
  6643. }
  6644. APPLptr->DataNCCI[Num] = NCCIcode;
  6645. APPLptr->DataFlags[Num] = (plci->Id<<8) | (plci->NL.Ind>>4);
  6646. dbug(3,dprintf("Buffer(%d), Max = %d",Num,APPLptr->MaxBuffer));
  6647. plci->RNum = Num;
  6648. plci->RFlags = plci->NL.Ind>>4;
  6649. plci->RData[0].PLength = APPLptr->MaxDataLength;
  6650. plci->NL.R = plci->RData;
  6651. if ((plci->NL.RLength != 0)
  6652. && ((plci->B2_prot == B2_V120_ASYNC)
  6653. || (plci->B2_prot == B2_V120_ASYNC_V42BIS)
  6654. || (plci->B2_prot == B2_V120_BIT_TRANSPARENT)))
  6655. {
  6656. plci->RData[1].P = plci->RData[0].P;
  6657. plci->RData[1].PLength = plci->RData[0].PLength;
  6658. plci->RData[0].P = v120_header_buffer + (-((int) v120_header_buffer) & 3);
  6659. if ((plci->NL.RBuffer->P[0] & V120_HEADER_EXTEND_BIT) || (plci->NL.RLength == 1))
  6660. plci->RData[0].PLength = 1;
  6661. else
  6662. plci->RData[0].PLength = 2;
  6663. if (plci->NL.RBuffer->P[0] & V120_HEADER_BREAK_BIT)
  6664. plci->RFlags |= 0x0010;
  6665. if (plci->NL.RBuffer->P[0] & (V120_HEADER_C1_BIT | V120_HEADER_C2_BIT))
  6666. plci->RFlags |= 0x8000;
  6667. plci->NL.RNum = 2;
  6668. }
  6669. else
  6670. {
  6671. if((plci->NL.Ind &0x0f)==N_UDATA)
  6672. plci->RFlags |= 0x0010;
  6673. else if ((plci->B3_prot == B3_RTP) && ((plci->NL.Ind & 0x0f) == N_BDATA))
  6674. plci->RFlags |= 0x0001;
  6675. plci->NL.RNum = 1;
  6676. }
  6677. break;
  6678. case N_DATA_ACK:
  6679. data_ack (plci, ch);
  6680. break;
  6681. default:
  6682. plci->NL.RNR = 2;
  6683. break;
  6684. }
  6685. }
  6686. /*------------------------------------------------------------------*/
  6687. /* find a free PLCI */
  6688. /*------------------------------------------------------------------*/
  6689. static word get_plci(DIVA_CAPI_ADAPTER *a)
  6690. {
  6691. word i,j;
  6692. PLCI * plci;
  6693. dump_plcis (a);
  6694. for(i=0;i<a->max_plci && a->plci[i].Id;i++);
  6695. if(i==a->max_plci) {
  6696. dbug(1,dprintf("get_plci: out of PLCIs"));
  6697. return 0;
  6698. }
  6699. plci = &a->plci[i];
  6700. plci->Id = (byte)(i+1);
  6701. plci->Sig.Id = 0;
  6702. plci->NL.Id = 0;
  6703. plci->sig_req = 0;
  6704. plci->nl_req = 0;
  6705. plci->appl = NULL;
  6706. plci->relatedPTYPLCI = NULL;
  6707. plci->State = IDLE;
  6708. plci->SuppState = IDLE;
  6709. plci->channels = 0;
  6710. plci->tel = 0;
  6711. plci->B1_resource = 0;
  6712. plci->B2_prot = 0;
  6713. plci->B3_prot = 0;
  6714. plci->command = 0;
  6715. plci->m_command = 0;
  6716. init_internal_command_queue (plci);
  6717. plci->number = 0;
  6718. plci->req_in_start = 0;
  6719. plci->req_in = 0;
  6720. plci->req_out = 0;
  6721. plci->msg_in_write_pos = MSG_IN_QUEUE_SIZE;
  6722. plci->msg_in_read_pos = MSG_IN_QUEUE_SIZE;
  6723. plci->msg_in_wrap_pos = MSG_IN_QUEUE_SIZE;
  6724. plci->data_sent = false;
  6725. plci->send_disc = 0;
  6726. plci->sig_global_req = 0;
  6727. plci->sig_remove_id = 0;
  6728. plci->nl_global_req = 0;
  6729. plci->nl_remove_id = 0;
  6730. plci->adv_nl = 0;
  6731. plci->manufacturer = false;
  6732. plci->call_dir = CALL_DIR_OUT | CALL_DIR_ORIGINATE;
  6733. plci->spoofed_msg = 0;
  6734. plci->ptyState = 0;
  6735. plci->cr_enquiry = false;
  6736. plci->hangup_flow_ctrl_timer = 0;
  6737. plci->ncci_ring_list = 0;
  6738. for(j=0;j<MAX_CHANNELS_PER_PLCI;j++) plci->inc_dis_ncci_table[j] = 0;
  6739. clear_c_ind_mask (plci);
  6740. set_group_ind_mask (plci);
  6741. plci->fax_connect_info_length = 0;
  6742. plci->nsf_control_bits = 0;
  6743. plci->ncpi_state = 0x00;
  6744. plci->ncpi_buffer[0] = 0;
  6745. plci->requested_options_conn = 0;
  6746. plci->requested_options = 0;
  6747. plci->notifiedcall = 0;
  6748. plci->vswitchstate = 0;
  6749. plci->vsprot = 0;
  6750. plci->vsprotdialect = 0;
  6751. init_b1_config (plci);
  6752. dbug(1,dprintf("get_plci(%x)",plci->Id));
  6753. return i+1;
  6754. }
  6755. /*------------------------------------------------------------------*/
  6756. /* put a parameter in the parameter buffer */
  6757. /*------------------------------------------------------------------*/
  6758. static void add_p(PLCI * plci, byte code, byte * p)
  6759. {
  6760. word p_length;
  6761. p_length = 0;
  6762. if(p) p_length = p[0];
  6763. add_ie(plci, code, p, p_length);
  6764. }
  6765. /*------------------------------------------------------------------*/
  6766. /* put a structure in the parameter buffer */
  6767. /*------------------------------------------------------------------*/
  6768. static void add_s(PLCI * plci, byte code, API_PARSE * p)
  6769. {
  6770. if(p) add_ie(plci, code, p->info, (word)p->length);
  6771. }
  6772. /*------------------------------------------------------------------*/
  6773. /* put multiple structures in the parameter buffer */
  6774. /*------------------------------------------------------------------*/
  6775. static void add_ss(PLCI * plci, byte code, API_PARSE * p)
  6776. {
  6777. byte i;
  6778. if(p){
  6779. dbug(1,dprintf("add_ss(%x,len=%d)",code,p->length));
  6780. for(i=2;i<(byte)p->length;i+=p->info[i]+2){
  6781. dbug(1,dprintf("add_ss_ie(%x,len=%d)",p->info[i-1],p->info[i]));
  6782. add_ie(plci, p->info[i-1], (byte *)&(p->info[i]), (word)p->info[i]);
  6783. }
  6784. }
  6785. }
  6786. /*------------------------------------------------------------------*/
  6787. /* return the channel number sent by the application in a esc_chi */
  6788. /*------------------------------------------------------------------*/
  6789. static byte getChannel(API_PARSE * p)
  6790. {
  6791. byte i;
  6792. if(p){
  6793. for(i=2;i<(byte)p->length;i+=p->info[i]+2){
  6794. if(p->info[i]==2){
  6795. if(p->info[i-1]==ESC && p->info[i+1]==CHI) return (p->info[i+2]);
  6796. }
  6797. }
  6798. }
  6799. return 0;
  6800. }
  6801. /*------------------------------------------------------------------*/
  6802. /* put an information element in the parameter buffer */
  6803. /*------------------------------------------------------------------*/
  6804. static void add_ie(PLCI * plci, byte code, byte * p, word p_length)
  6805. {
  6806. word i;
  6807. if(!(code &0x80) && !p_length) return;
  6808. if(plci->req_in==plci->req_in_start) {
  6809. plci->req_in +=2;
  6810. }
  6811. else {
  6812. plci->req_in--;
  6813. }
  6814. plci->RBuffer[plci->req_in++] = code;
  6815. if(p) {
  6816. plci->RBuffer[plci->req_in++] = (byte)p_length;
  6817. for(i=0;i<p_length;i++) plci->RBuffer[plci->req_in++] = p[1+i];
  6818. }
  6819. plci->RBuffer[plci->req_in++] = 0;
  6820. }
  6821. /*------------------------------------------------------------------*/
  6822. /* put a unstructured data into the buffer */
  6823. /*------------------------------------------------------------------*/
  6824. static void add_d(PLCI *plci, word length, byte *p)
  6825. {
  6826. word i;
  6827. if(plci->req_in==plci->req_in_start) {
  6828. plci->req_in +=2;
  6829. }
  6830. else {
  6831. plci->req_in--;
  6832. }
  6833. for(i=0;i<length;i++) plci->RBuffer[plci->req_in++] = p[i];
  6834. }
  6835. /*------------------------------------------------------------------*/
  6836. /* put parameters from the Additional Info parameter in the */
  6837. /* parameter buffer */
  6838. /*------------------------------------------------------------------*/
  6839. static void add_ai(PLCI *plci, API_PARSE *ai)
  6840. {
  6841. word i;
  6842. API_PARSE ai_parms[5];
  6843. for(i=0;i<5;i++) ai_parms[i].length = 0;
  6844. if(!ai->length)
  6845. return;
  6846. if(api_parse(&ai->info[1], (word)ai->length, "ssss", ai_parms))
  6847. return;
  6848. add_s (plci,KEY,&ai_parms[1]);
  6849. add_s (plci,UUI,&ai_parms[2]);
  6850. add_ss(plci,FTY,&ai_parms[3]);
  6851. }
  6852. /*------------------------------------------------------------------*/
  6853. /* put parameter for b1 protocol in the parameter buffer */
  6854. /*------------------------------------------------------------------*/
  6855. static word add_b1(PLCI *plci, API_PARSE *bp, word b_channel_info,
  6856. word b1_facilities)
  6857. {
  6858. API_PARSE bp_parms[8];
  6859. API_PARSE mdm_cfg[9];
  6860. API_PARSE global_config[2];
  6861. byte cai[256];
  6862. byte resource[] = {5,9,13,12,16,39,9,17,17,18};
  6863. byte voice_cai[] = "\x06\x14\x00\x00\x00\x00\x08";
  6864. word i;
  6865. API_PARSE mdm_cfg_v18[4];
  6866. word j, n, w;
  6867. dword d;
  6868. for(i=0;i<8;i++) bp_parms[i].length = 0;
  6869. for(i=0;i<2;i++) global_config[i].length = 0;
  6870. dbug(1,dprintf("add_b1"));
  6871. api_save_msg(bp, "s", &plci->B_protocol);
  6872. if(b_channel_info==2){
  6873. plci->B1_resource = 0;
  6874. adjust_b1_facilities (plci, plci->B1_resource, b1_facilities);
  6875. add_p(plci, CAI, "\x01\x00");
  6876. dbug(1,dprintf("Cai=1,0 (no resource)"));
  6877. return 0;
  6878. }
  6879. if(plci->tel == CODEC_PERMANENT) return 0;
  6880. else if(plci->tel == CODEC){
  6881. plci->B1_resource = 1;
  6882. adjust_b1_facilities (plci, plci->B1_resource, b1_facilities);
  6883. add_p(plci, CAI, "\x01\x01");
  6884. dbug(1,dprintf("Cai=1,1 (Codec)"));
  6885. return 0;
  6886. }
  6887. else if(plci->tel == ADV_VOICE){
  6888. plci->B1_resource = add_b1_facilities (plci, 9, (word)(b1_facilities | B1_FACILITY_VOICE));
  6889. adjust_b1_facilities (plci, plci->B1_resource, (word)(b1_facilities | B1_FACILITY_VOICE));
  6890. voice_cai[1] = plci->B1_resource;
  6891. PUT_WORD (&voice_cai[5], plci->appl->MaxDataLength);
  6892. add_p(plci, CAI, voice_cai);
  6893. dbug(1,dprintf("Cai=1,0x%x (AdvVoice)",voice_cai[1]));
  6894. return 0;
  6895. }
  6896. plci->call_dir &= ~(CALL_DIR_ORIGINATE | CALL_DIR_ANSWER);
  6897. if (plci->call_dir & CALL_DIR_OUT)
  6898. plci->call_dir |= CALL_DIR_ORIGINATE;
  6899. else if (plci->call_dir & CALL_DIR_IN)
  6900. plci->call_dir |= CALL_DIR_ANSWER;
  6901. if(!bp->length){
  6902. plci->B1_resource = 0x5;
  6903. adjust_b1_facilities (plci, plci->B1_resource, b1_facilities);
  6904. add_p(plci, CAI, "\x01\x05");
  6905. return 0;
  6906. }
  6907. dbug(1,dprintf("b_prot_len=%d",(word)bp->length));
  6908. if(bp->length>256) return _WRONG_MESSAGE_FORMAT;
  6909. if(api_parse(&bp->info[1], (word)bp->length, "wwwsssb", bp_parms))
  6910. {
  6911. bp_parms[6].length = 0;
  6912. if(api_parse(&bp->info[1], (word)bp->length, "wwwsss", bp_parms))
  6913. {
  6914. dbug(1,dprintf("b-form.!"));
  6915. return _WRONG_MESSAGE_FORMAT;
  6916. }
  6917. }
  6918. else if (api_parse(&bp->info[1], (word)bp->length, "wwwssss", bp_parms))
  6919. {
  6920. dbug(1,dprintf("b-form.!"));
  6921. return _WRONG_MESSAGE_FORMAT;
  6922. }
  6923. if(bp_parms[6].length)
  6924. {
  6925. if(api_parse(&bp_parms[6].info[1], (word)bp_parms[6].length, "w", global_config))
  6926. {
  6927. return _WRONG_MESSAGE_FORMAT;
  6928. }
  6929. switch(GET_WORD(global_config[0].info))
  6930. {
  6931. case 1:
  6932. plci->call_dir = (plci->call_dir & ~CALL_DIR_ANSWER) | CALL_DIR_ORIGINATE;
  6933. break;
  6934. case 2:
  6935. plci->call_dir = (plci->call_dir & ~CALL_DIR_ORIGINATE) | CALL_DIR_ANSWER;
  6936. break;
  6937. }
  6938. }
  6939. dbug(1,dprintf("call_dir=%04x", plci->call_dir));
  6940. if ((GET_WORD(bp_parms[0].info) == B1_RTP)
  6941. && (plci->adapter->man_profile.private_options & (1L << PRIVATE_RTP)))
  6942. {
  6943. plci->B1_resource = add_b1_facilities (plci, 31, (word)(b1_facilities & ~B1_FACILITY_VOICE));
  6944. adjust_b1_facilities (plci, plci->B1_resource, (word)(b1_facilities & ~B1_FACILITY_VOICE));
  6945. cai[1] = plci->B1_resource;
  6946. cai[2] = 0;
  6947. cai[3] = 0;
  6948. cai[4] = 0;
  6949. PUT_WORD(&cai[5],plci->appl->MaxDataLength);
  6950. for (i = 0; i < bp_parms[3].length; i++)
  6951. cai[7+i] = bp_parms[3].info[1+i];
  6952. cai[0] = 6 + bp_parms[3].length;
  6953. add_p(plci, CAI, cai);
  6954. return 0;
  6955. }
  6956. if ((GET_WORD(bp_parms[0].info) == B1_PIAFS)
  6957. && (plci->adapter->man_profile.private_options & (1L << PRIVATE_PIAFS)))
  6958. {
  6959. plci->B1_resource = add_b1_facilities (plci, 35/* PIAFS HARDWARE FACILITY */, (word)(b1_facilities & ~B1_FACILITY_VOICE));
  6960. adjust_b1_facilities (plci, plci->B1_resource, (word)(b1_facilities & ~B1_FACILITY_VOICE));
  6961. cai[1] = plci->B1_resource;
  6962. cai[2] = 0;
  6963. cai[3] = 0;
  6964. cai[4] = 0;
  6965. PUT_WORD(&cai[5],plci->appl->MaxDataLength);
  6966. cai[0] = 6;
  6967. add_p(plci, CAI, cai);
  6968. return 0;
  6969. }
  6970. if ((GET_WORD(bp_parms[0].info) >= 32)
  6971. || (!((1L << GET_WORD(bp_parms[0].info)) & plci->adapter->profile.B1_Protocols)
  6972. && ((GET_WORD(bp_parms[0].info) != 3)
  6973. || !((1L << B1_HDLC) & plci->adapter->profile.B1_Protocols)
  6974. || ((bp_parms[3].length != 0) && (GET_WORD(&bp_parms[3].info[1]) != 0) && (GET_WORD(&bp_parms[3].info[1]) != 56000)))))
  6975. {
  6976. return _B1_NOT_SUPPORTED;
  6977. }
  6978. plci->B1_resource = add_b1_facilities (plci, resource[GET_WORD(bp_parms[0].info)],
  6979. (word)(b1_facilities & ~B1_FACILITY_VOICE));
  6980. adjust_b1_facilities (plci, plci->B1_resource, (word)(b1_facilities & ~B1_FACILITY_VOICE));
  6981. cai[0] = 6;
  6982. cai[1] = plci->B1_resource;
  6983. for (i=2;i<sizeof(cai);i++) cai[i] = 0;
  6984. if ((GET_WORD(bp_parms[0].info) == B1_MODEM_ALL_NEGOTIATE)
  6985. || (GET_WORD(bp_parms[0].info) == B1_MODEM_ASYNC)
  6986. || (GET_WORD(bp_parms[0].info) == B1_MODEM_SYNC_HDLC))
  6987. { /* B1 - modem */
  6988. for (i=0;i<7;i++) mdm_cfg[i].length = 0;
  6989. if (bp_parms[3].length)
  6990. {
  6991. if(api_parse(&bp_parms[3].info[1],(word)bp_parms[3].length,"wwwwww", mdm_cfg))
  6992. {
  6993. return (_WRONG_MESSAGE_FORMAT);
  6994. }
  6995. cai[2] = 0; /* Bit rate for adaptation */
  6996. dbug(1,dprintf("MDM Max Bit Rate:<%d>", GET_WORD(mdm_cfg[0].info)));
  6997. PUT_WORD (&cai[13], 0); /* Min Tx speed */
  6998. PUT_WORD (&cai[15], GET_WORD(mdm_cfg[0].info)); /* Max Tx speed */
  6999. PUT_WORD (&cai[17], 0); /* Min Rx speed */
  7000. PUT_WORD (&cai[19], GET_WORD(mdm_cfg[0].info)); /* Max Rx speed */
  7001. cai[3] = 0; /* Async framing parameters */
  7002. switch (GET_WORD (mdm_cfg[2].info))
  7003. { /* Parity */
  7004. case 1: /* odd parity */
  7005. cai[3] |= (DSP_CAI_ASYNC_PARITY_ENABLE | DSP_CAI_ASYNC_PARITY_ODD);
  7006. dbug(1,dprintf("MDM: odd parity"));
  7007. break;
  7008. case 2: /* even parity */
  7009. cai[3] |= (DSP_CAI_ASYNC_PARITY_ENABLE | DSP_CAI_ASYNC_PARITY_EVEN);
  7010. dbug(1,dprintf("MDM: even parity"));
  7011. break;
  7012. default:
  7013. dbug(1,dprintf("MDM: no parity"));
  7014. break;
  7015. }
  7016. switch (GET_WORD (mdm_cfg[3].info))
  7017. { /* stop bits */
  7018. case 1: /* 2 stop bits */
  7019. cai[3] |= DSP_CAI_ASYNC_TWO_STOP_BITS;
  7020. dbug(1,dprintf("MDM: 2 stop bits"));
  7021. break;
  7022. default:
  7023. dbug(1,dprintf("MDM: 1 stop bit"));
  7024. break;
  7025. }
  7026. switch (GET_WORD (mdm_cfg[1].info))
  7027. { /* char length */
  7028. case 5:
  7029. cai[3] |= DSP_CAI_ASYNC_CHAR_LENGTH_5;
  7030. dbug(1,dprintf("MDM: 5 bits"));
  7031. break;
  7032. case 6:
  7033. cai[3] |= DSP_CAI_ASYNC_CHAR_LENGTH_6;
  7034. dbug(1,dprintf("MDM: 6 bits"));
  7035. break;
  7036. case 7:
  7037. cai[3] |= DSP_CAI_ASYNC_CHAR_LENGTH_7;
  7038. dbug(1,dprintf("MDM: 7 bits"));
  7039. break;
  7040. default:
  7041. dbug(1,dprintf("MDM: 8 bits"));
  7042. break;
  7043. }
  7044. cai[7] = 0; /* Line taking options */
  7045. cai[8] = 0; /* Modulation negotiation options */
  7046. cai[9] = 0; /* Modulation options */
  7047. if (((plci->call_dir & CALL_DIR_ORIGINATE) != 0) ^ ((plci->call_dir & CALL_DIR_OUT) != 0))
  7048. {
  7049. cai[9] |= DSP_CAI_MODEM_REVERSE_DIRECTION;
  7050. dbug(1, dprintf("MDM: Reverse direction"));
  7051. }
  7052. if (GET_WORD (mdm_cfg[4].info) & MDM_CAPI_DISABLE_RETRAIN)
  7053. {
  7054. cai[9] |= DSP_CAI_MODEM_DISABLE_RETRAIN;
  7055. dbug(1, dprintf("MDM: Disable retrain"));
  7056. }
  7057. if (GET_WORD (mdm_cfg[4].info) & MDM_CAPI_DISABLE_RING_TONE)
  7058. {
  7059. cai[7] |= DSP_CAI_MODEM_DISABLE_CALLING_TONE | DSP_CAI_MODEM_DISABLE_ANSWER_TONE;
  7060. dbug(1, dprintf("MDM: Disable ring tone"));
  7061. }
  7062. if (GET_WORD (mdm_cfg[4].info) & MDM_CAPI_GUARD_1800)
  7063. {
  7064. cai[8] |= DSP_CAI_MODEM_GUARD_TONE_1800HZ;
  7065. dbug(1, dprintf("MDM: 1800 guard tone"));
  7066. }
  7067. else if (GET_WORD (mdm_cfg[4].info) & MDM_CAPI_GUARD_550 )
  7068. {
  7069. cai[8] |= DSP_CAI_MODEM_GUARD_TONE_550HZ;
  7070. dbug(1, dprintf("MDM: 550 guard tone"));
  7071. }
  7072. if ((GET_WORD (mdm_cfg[5].info) & 0x00ff) == MDM_CAPI_NEG_V100)
  7073. {
  7074. cai[8] |= DSP_CAI_MODEM_NEGOTIATE_V100;
  7075. dbug(1, dprintf("MDM: V100"));
  7076. }
  7077. else if ((GET_WORD (mdm_cfg[5].info) & 0x00ff) == MDM_CAPI_NEG_MOD_CLASS)
  7078. {
  7079. cai[8] |= DSP_CAI_MODEM_NEGOTIATE_IN_CLASS;
  7080. dbug(1, dprintf("MDM: IN CLASS"));
  7081. }
  7082. else if ((GET_WORD (mdm_cfg[5].info) & 0x00ff) == MDM_CAPI_NEG_DISABLED)
  7083. {
  7084. cai[8] |= DSP_CAI_MODEM_NEGOTIATE_DISABLED;
  7085. dbug(1, dprintf("MDM: DISABLED"));
  7086. }
  7087. cai[0] = 20;
  7088. if ((plci->adapter->man_profile.private_options & (1L << PRIVATE_V18))
  7089. && (GET_WORD(mdm_cfg[5].info) & 0x8000)) /* Private V.18 enable */
  7090. {
  7091. plci->requested_options |= 1L << PRIVATE_V18;
  7092. }
  7093. if (GET_WORD(mdm_cfg[5].info) & 0x4000) /* Private VOWN enable */
  7094. plci->requested_options |= 1L << PRIVATE_VOWN;
  7095. if ((plci->requested_options_conn | plci->requested_options | plci->adapter->requested_options_table[plci->appl->Id-1])
  7096. & ((1L << PRIVATE_V18) | (1L << PRIVATE_VOWN)))
  7097. {
  7098. if (!api_parse(&bp_parms[3].info[1],(word)bp_parms[3].length,"wwwwwws", mdm_cfg))
  7099. {
  7100. i = 27;
  7101. if (mdm_cfg[6].length >= 4)
  7102. {
  7103. d = GET_DWORD(&mdm_cfg[6].info[1]);
  7104. cai[7] |= (byte) d; /* line taking options */
  7105. cai[9] |= (byte)(d >> 8); /* modulation options */
  7106. cai[++i] = (byte)(d >> 16); /* vown modulation options */
  7107. cai[++i] = (byte)(d >> 24);
  7108. if (mdm_cfg[6].length >= 8)
  7109. {
  7110. d = GET_DWORD(&mdm_cfg[6].info[5]);
  7111. cai[10] |= (byte) d; /* disabled modulations mask */
  7112. cai[11] |= (byte)(d >> 8);
  7113. if (mdm_cfg[6].length >= 12)
  7114. {
  7115. d = GET_DWORD(&mdm_cfg[6].info[9]);
  7116. cai[12] = (byte) d; /* enabled modulations mask */
  7117. cai[++i] = (byte)(d >> 8); /* vown enabled modulations */
  7118. cai[++i] = (byte)(d >> 16);
  7119. cai[++i] = (byte)(d >> 24);
  7120. cai[++i] = 0;
  7121. if (mdm_cfg[6].length >= 14)
  7122. {
  7123. w = GET_WORD(&mdm_cfg[6].info[13]);
  7124. if (w != 0)
  7125. PUT_WORD(&cai[13], w); /* min tx speed */
  7126. if (mdm_cfg[6].length >= 16)
  7127. {
  7128. w = GET_WORD(&mdm_cfg[6].info[15]);
  7129. if (w != 0)
  7130. PUT_WORD(&cai[15], w); /* max tx speed */
  7131. if (mdm_cfg[6].length >= 18)
  7132. {
  7133. w = GET_WORD(&mdm_cfg[6].info[17]);
  7134. if (w != 0)
  7135. PUT_WORD(&cai[17], w); /* min rx speed */
  7136. if (mdm_cfg[6].length >= 20)
  7137. {
  7138. w = GET_WORD(&mdm_cfg[6].info[19]);
  7139. if (w != 0)
  7140. PUT_WORD(&cai[19], w); /* max rx speed */
  7141. if (mdm_cfg[6].length >= 22)
  7142. {
  7143. w = GET_WORD(&mdm_cfg[6].info[21]);
  7144. cai[23] = (byte)(-((short) w)); /* transmit level */
  7145. if (mdm_cfg[6].length >= 24)
  7146. {
  7147. w = GET_WORD(&mdm_cfg[6].info[23]);
  7148. cai[22] |= (byte) w; /* info options mask */
  7149. cai[21] |= (byte)(w >> 8); /* disabled symbol rates */
  7150. }
  7151. }
  7152. }
  7153. }
  7154. }
  7155. }
  7156. }
  7157. }
  7158. }
  7159. cai[27] = i - 27;
  7160. i++;
  7161. if (!api_parse(&bp_parms[3].info[1],(word)bp_parms[3].length,"wwwwwwss", mdm_cfg))
  7162. {
  7163. if (!api_parse(&mdm_cfg[7].info[1],(word)mdm_cfg[7].length,"sss", mdm_cfg_v18))
  7164. {
  7165. for (n = 0; n < 3; n++)
  7166. {
  7167. cai[i] = (byte)(mdm_cfg_v18[n].length);
  7168. for (j = 1; j < ((word)(cai[i] + 1)); j++)
  7169. cai[i+j] = mdm_cfg_v18[n].info[j];
  7170. i += cai[i] + 1;
  7171. }
  7172. }
  7173. }
  7174. cai[0] = (byte)(i - 1);
  7175. }
  7176. }
  7177. }
  7178. }
  7179. if(GET_WORD(bp_parms[0].info)==2 || /* V.110 async */
  7180. GET_WORD(bp_parms[0].info)==3 ) /* V.110 sync */
  7181. {
  7182. if(bp_parms[3].length){
  7183. dbug(1,dprintf("V.110,%d",GET_WORD(&bp_parms[3].info[1])));
  7184. switch(GET_WORD(&bp_parms[3].info[1])){ /* Rate */
  7185. case 0:
  7186. case 56000:
  7187. if(GET_WORD(bp_parms[0].info)==3){ /* V.110 sync 56k */
  7188. dbug(1,dprintf("56k sync HSCX"));
  7189. cai[1] = 8;
  7190. cai[2] = 0;
  7191. cai[3] = 0;
  7192. }
  7193. else if(GET_WORD(bp_parms[0].info)==2){
  7194. dbug(1,dprintf("56k async DSP"));
  7195. cai[2] = 9;
  7196. }
  7197. break;
  7198. case 50: cai[2] = 1; break;
  7199. case 75: cai[2] = 1; break;
  7200. case 110: cai[2] = 1; break;
  7201. case 150: cai[2] = 1; break;
  7202. case 200: cai[2] = 1; break;
  7203. case 300: cai[2] = 1; break;
  7204. case 600: cai[2] = 1; break;
  7205. case 1200: cai[2] = 2; break;
  7206. case 2400: cai[2] = 3; break;
  7207. case 4800: cai[2] = 4; break;
  7208. case 7200: cai[2] = 10; break;
  7209. case 9600: cai[2] = 5; break;
  7210. case 12000: cai[2] = 13; break;
  7211. case 24000: cai[2] = 0; break;
  7212. case 14400: cai[2] = 11; break;
  7213. case 19200: cai[2] = 6; break;
  7214. case 28800: cai[2] = 12; break;
  7215. case 38400: cai[2] = 7; break;
  7216. case 48000: cai[2] = 8; break;
  7217. case 76: cai[2] = 15; break; /* 75/1200 */
  7218. case 1201: cai[2] = 14; break; /* 1200/75 */
  7219. case 56001: cai[2] = 9; break; /* V.110 56000 */
  7220. default:
  7221. return _B1_PARM_NOT_SUPPORTED;
  7222. }
  7223. cai[3] = 0;
  7224. if (cai[1] == 13) /* v.110 async */
  7225. {
  7226. if (bp_parms[3].length >= 8)
  7227. {
  7228. switch (GET_WORD (&bp_parms[3].info[3]))
  7229. { /* char length */
  7230. case 5:
  7231. cai[3] |= DSP_CAI_ASYNC_CHAR_LENGTH_5;
  7232. break;
  7233. case 6:
  7234. cai[3] |= DSP_CAI_ASYNC_CHAR_LENGTH_6;
  7235. break;
  7236. case 7:
  7237. cai[3] |= DSP_CAI_ASYNC_CHAR_LENGTH_7;
  7238. break;
  7239. }
  7240. switch (GET_WORD (&bp_parms[3].info[5]))
  7241. { /* Parity */
  7242. case 1: /* odd parity */
  7243. cai[3] |= (DSP_CAI_ASYNC_PARITY_ENABLE | DSP_CAI_ASYNC_PARITY_ODD);
  7244. break;
  7245. case 2: /* even parity */
  7246. cai[3] |= (DSP_CAI_ASYNC_PARITY_ENABLE | DSP_CAI_ASYNC_PARITY_EVEN);
  7247. break;
  7248. }
  7249. switch (GET_WORD (&bp_parms[3].info[7]))
  7250. { /* stop bits */
  7251. case 1: /* 2 stop bits */
  7252. cai[3] |= DSP_CAI_ASYNC_TWO_STOP_BITS;
  7253. break;
  7254. }
  7255. }
  7256. }
  7257. }
  7258. else if(cai[1]==8 || GET_WORD(bp_parms[0].info)==3 ){
  7259. dbug(1,dprintf("V.110 default 56k sync"));
  7260. cai[1] = 8;
  7261. cai[2] = 0;
  7262. cai[3] = 0;
  7263. }
  7264. else {
  7265. dbug(1,dprintf("V.110 default 9600 async"));
  7266. cai[2] = 5;
  7267. }
  7268. }
  7269. PUT_WORD(&cai[5],plci->appl->MaxDataLength);
  7270. 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]));
  7271. /* HexDump ("CAI", sizeof(cai), &cai[0]); */
  7272. add_p(plci, CAI, cai);
  7273. return 0;
  7274. }
  7275. /*------------------------------------------------------------------*/
  7276. /* put parameter for b2 and B3 protocol in the parameter buffer */
  7277. /*------------------------------------------------------------------*/
  7278. static word add_b23(PLCI *plci, API_PARSE *bp)
  7279. {
  7280. word i, fax_control_bits;
  7281. byte pos, len;
  7282. byte SAPI = 0x40; /* default SAPI 16 for x.31 */
  7283. API_PARSE bp_parms[8];
  7284. API_PARSE * b1_config;
  7285. API_PARSE * b2_config;
  7286. API_PARSE b2_config_parms[8];
  7287. API_PARSE * b3_config;
  7288. API_PARSE b3_config_parms[6];
  7289. API_PARSE global_config[2];
  7290. static byte llc[3] = {2,0,0};
  7291. static byte dlc[20] = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
  7292. static byte nlc[256];
  7293. static byte lli[12] = {1,1};
  7294. const byte llc2_out[] = {1,2,4,6,2,0,0,0, X75_V42BIS,V120_L2,V120_V42BIS,V120_L2,6};
  7295. const byte llc2_in[] = {1,3,4,6,3,0,0,0, X75_V42BIS,V120_L2,V120_V42BIS,V120_L2,6};
  7296. const byte llc3[] = {4,3,2,2,6,6,0};
  7297. const byte header[] = {0,2,3,3,0,0,0};
  7298. for(i=0;i<8;i++) bp_parms[i].length = 0;
  7299. for(i=0;i<6;i++) b2_config_parms[i].length = 0;
  7300. for(i=0;i<5;i++) b3_config_parms[i].length = 0;
  7301. lli[0] = 1;
  7302. lli[1] = 1;
  7303. if (plci->adapter->manufacturer_features & MANUFACTURER_FEATURE_XONOFF_FLOW_CONTROL)
  7304. lli[1] |= 2;
  7305. if (plci->adapter->manufacturer_features & MANUFACTURER_FEATURE_OOB_CHANNEL)
  7306. lli[1] |= 4;
  7307. if ((lli[1] & 0x02) && (diva_xdi_extended_features & DIVA_CAPI_USE_CMA)) {
  7308. lli[1] |= 0x10;
  7309. if (plci->rx_dma_descriptor <= 0) {
  7310. plci->rx_dma_descriptor=diva_get_dma_descriptor(plci,&plci->rx_dma_magic);
  7311. if (plci->rx_dma_descriptor >= 0)
  7312. plci->rx_dma_descriptor++;
  7313. }
  7314. if (plci->rx_dma_descriptor > 0) {
  7315. lli[0] = 6;
  7316. lli[1] |= 0x40;
  7317. lli[2] = (byte)(plci->rx_dma_descriptor - 1);
  7318. lli[3] = (byte)plci->rx_dma_magic;
  7319. lli[4] = (byte)(plci->rx_dma_magic >> 8);
  7320. lli[5] = (byte)(plci->rx_dma_magic >> 16);
  7321. lli[6] = (byte)(plci->rx_dma_magic >> 24);
  7322. }
  7323. }
  7324. if (DIVA_CAPI_SUPPORTS_NO_CANCEL(plci->adapter)) {
  7325. lli[1] |= 0x20;
  7326. }
  7327. dbug(1,dprintf("add_b23"));
  7328. api_save_msg(bp, "s", &plci->B_protocol);
  7329. if(!bp->length && plci->tel)
  7330. {
  7331. plci->adv_nl = true;
  7332. dbug(1,dprintf("Default adv.Nl"));
  7333. add_p(plci,LLI,lli);
  7334. plci->B2_prot = 1 /*XPARENT*/;
  7335. plci->B3_prot = 0 /*XPARENT*/;
  7336. llc[1] = 2;
  7337. llc[2] = 4;
  7338. add_p(plci, LLC, llc);
  7339. dlc[0] = 2;
  7340. PUT_WORD(&dlc[1],plci->appl->MaxDataLength);
  7341. add_p(plci, DLC, dlc);
  7342. return 0;
  7343. }
  7344. if(!bp->length) /*default*/
  7345. {
  7346. dbug(1,dprintf("ret default"));
  7347. add_p(plci,LLI,lli);
  7348. plci->B2_prot = 0 /*X.75 */;
  7349. plci->B3_prot = 0 /*XPARENT*/;
  7350. llc[1] = 1;
  7351. llc[2] = 4;
  7352. add_p(plci, LLC, llc);
  7353. dlc[0] = 2;
  7354. PUT_WORD(&dlc[1],plci->appl->MaxDataLength);
  7355. add_p(plci, DLC, dlc);
  7356. return 0;
  7357. }
  7358. dbug(1,dprintf("b_prot_len=%d",(word)bp->length));
  7359. if((word)bp->length > 256) return _WRONG_MESSAGE_FORMAT;
  7360. if(api_parse(&bp->info[1], (word)bp->length, "wwwsssb", bp_parms))
  7361. {
  7362. bp_parms[6].length = 0;
  7363. if(api_parse(&bp->info[1], (word)bp->length, "wwwsss", bp_parms))
  7364. {
  7365. dbug(1,dprintf("b-form.!"));
  7366. return _WRONG_MESSAGE_FORMAT;
  7367. }
  7368. }
  7369. else if (api_parse(&bp->info[1], (word)bp->length, "wwwssss", bp_parms))
  7370. {
  7371. dbug(1,dprintf("b-form.!"));
  7372. return _WRONG_MESSAGE_FORMAT;
  7373. }
  7374. if(plci->tel==ADV_VOICE) /* transparent B on advanced voice */
  7375. {
  7376. if(GET_WORD(bp_parms[1].info)!=1
  7377. || GET_WORD(bp_parms[2].info)!=0) return _B2_NOT_SUPPORTED;
  7378. plci->adv_nl = true;
  7379. }
  7380. else if(plci->tel) return _B2_NOT_SUPPORTED;
  7381. if ((GET_WORD(bp_parms[1].info) == B2_RTP)
  7382. && (GET_WORD(bp_parms[2].info) == B3_RTP)
  7383. && (plci->adapter->man_profile.private_options & (1L << PRIVATE_RTP)))
  7384. {
  7385. add_p(plci,LLI,lli);
  7386. plci->B2_prot = (byte) GET_WORD(bp_parms[1].info);
  7387. plci->B3_prot = (byte) GET_WORD(bp_parms[2].info);
  7388. llc[1] = (plci->call_dir & (CALL_DIR_ORIGINATE | CALL_DIR_FORCE_OUTG_NL)) ? 14 : 13;
  7389. llc[2] = 4;
  7390. add_p(plci, LLC, llc);
  7391. dlc[0] = 2;
  7392. PUT_WORD(&dlc[1],plci->appl->MaxDataLength);
  7393. dlc[3] = 3; /* Addr A */
  7394. dlc[4] = 1; /* Addr B */
  7395. dlc[5] = 7; /* modulo mode */
  7396. dlc[6] = 7; /* window size */
  7397. dlc[7] = 0; /* XID len Lo */
  7398. dlc[8] = 0; /* XID len Hi */
  7399. for (i = 0; i < bp_parms[4].length; i++)
  7400. dlc[9+i] = bp_parms[4].info[1+i];
  7401. dlc[0] = (byte)(8 + bp_parms[4].length);
  7402. add_p(plci, DLC, dlc);
  7403. for (i = 0; i < bp_parms[5].length; i++)
  7404. nlc[1+i] = bp_parms[5].info[1+i];
  7405. nlc[0] = (byte)(bp_parms[5].length);
  7406. add_p(plci, NLC, nlc);
  7407. return 0;
  7408. }
  7409. if ((GET_WORD(bp_parms[1].info) >= 32)
  7410. || (!((1L << GET_WORD(bp_parms[1].info)) & plci->adapter->profile.B2_Protocols)
  7411. && ((GET_WORD(bp_parms[1].info) != B2_PIAFS)
  7412. || !(plci->adapter->man_profile.private_options & (1L << PRIVATE_PIAFS)))))
  7413. {
  7414. return _B2_NOT_SUPPORTED;
  7415. }
  7416. if ((GET_WORD(bp_parms[2].info) >= 32)
  7417. || !((1L << GET_WORD(bp_parms[2].info)) & plci->adapter->profile.B3_Protocols))
  7418. {
  7419. return _B3_NOT_SUPPORTED;
  7420. }
  7421. if ((GET_WORD(bp_parms[1].info) != B2_SDLC)
  7422. && ((GET_WORD(bp_parms[0].info) == B1_MODEM_ALL_NEGOTIATE)
  7423. || (GET_WORD(bp_parms[0].info) == B1_MODEM_ASYNC)
  7424. || (GET_WORD(bp_parms[0].info) == B1_MODEM_SYNC_HDLC)))
  7425. {
  7426. return (add_modem_b23 (plci, bp_parms));
  7427. }
  7428. add_p(plci,LLI,lli);
  7429. plci->B2_prot = (byte) GET_WORD(bp_parms[1].info);
  7430. plci->B3_prot = (byte) GET_WORD(bp_parms[2].info);
  7431. if(plci->B2_prot==12) SAPI = 0; /* default SAPI D-channel */
  7432. if(bp_parms[6].length)
  7433. {
  7434. if(api_parse(&bp_parms[6].info[1], (word)bp_parms[6].length, "w", global_config))
  7435. {
  7436. return _WRONG_MESSAGE_FORMAT;
  7437. }
  7438. switch(GET_WORD(global_config[0].info))
  7439. {
  7440. case 1:
  7441. plci->call_dir = (plci->call_dir & ~CALL_DIR_ANSWER) | CALL_DIR_ORIGINATE;
  7442. break;
  7443. case 2:
  7444. plci->call_dir = (plci->call_dir & ~CALL_DIR_ORIGINATE) | CALL_DIR_ANSWER;
  7445. break;
  7446. }
  7447. }
  7448. dbug(1,dprintf("call_dir=%04x", plci->call_dir));
  7449. if (plci->B2_prot == B2_PIAFS)
  7450. llc[1] = PIAFS_CRC;
  7451. else
  7452. /* IMPLEMENT_PIAFS */
  7453. {
  7454. llc[1] = (plci->call_dir & (CALL_DIR_ORIGINATE | CALL_DIR_FORCE_OUTG_NL)) ?
  7455. llc2_out[GET_WORD(bp_parms[1].info)] : llc2_in[GET_WORD(bp_parms[1].info)];
  7456. }
  7457. llc[2] = llc3[GET_WORD(bp_parms[2].info)];
  7458. add_p(plci, LLC, llc);
  7459. dlc[0] = 2;
  7460. PUT_WORD(&dlc[1], plci->appl->MaxDataLength +
  7461. header[GET_WORD(bp_parms[2].info)]);
  7462. b1_config = &bp_parms[3];
  7463. nlc[0] = 0;
  7464. if(plci->B3_prot == 4
  7465. || plci->B3_prot == 5)
  7466. {
  7467. for (i=0;i<sizeof(T30_INFO);i++) nlc[i] = 0;
  7468. nlc[0] = sizeof(T30_INFO);
  7469. if (plci->adapter->manufacturer_features & MANUFACTURER_FEATURE_FAX_PAPER_FORMATS)
  7470. ((T30_INFO *)&nlc[1])->operating_mode = T30_OPERATING_MODE_CAPI;
  7471. ((T30_INFO *)&nlc[1])->rate_div_2400 = 0xff;
  7472. if(b1_config->length>=2)
  7473. {
  7474. ((T30_INFO *)&nlc[1])->rate_div_2400 = (byte)(GET_WORD(&b1_config->info[1])/2400);
  7475. }
  7476. }
  7477. b2_config = &bp_parms[4];
  7478. if (llc[1] == PIAFS_CRC)
  7479. {
  7480. if (plci->B3_prot != B3_TRANSPARENT)
  7481. {
  7482. return _B_STACK_NOT_SUPPORTED;
  7483. }
  7484. if(b2_config->length && api_parse(&b2_config->info[1], (word)b2_config->length, "bwww", b2_config_parms)) {
  7485. return _WRONG_MESSAGE_FORMAT;
  7486. }
  7487. PUT_WORD(&dlc[1],plci->appl->MaxDataLength);
  7488. dlc[3] = 0; /* Addr A */
  7489. dlc[4] = 0; /* Addr B */
  7490. dlc[5] = 0; /* modulo mode */
  7491. dlc[6] = 0; /* window size */
  7492. if (b2_config->length >= 7){
  7493. dlc[ 7] = 7;
  7494. dlc[ 8] = 0;
  7495. dlc[ 9] = b2_config_parms[0].info[0]; /* PIAFS protocol Speed configuration */
  7496. dlc[10] = b2_config_parms[1].info[0]; /* V.42bis P0 */
  7497. dlc[11] = b2_config_parms[1].info[1]; /* V.42bis P0 */
  7498. dlc[12] = b2_config_parms[2].info[0]; /* V.42bis P1 */
  7499. dlc[13] = b2_config_parms[2].info[1]; /* V.42bis P1 */
  7500. dlc[14] = b2_config_parms[3].info[0]; /* V.42bis P2 */
  7501. dlc[15] = b2_config_parms[3].info[1]; /* V.42bis P2 */
  7502. dlc[ 0] = 15;
  7503. if(b2_config->length >= 8) { /* PIAFS control abilities */
  7504. dlc[ 7] = 10;
  7505. dlc[16] = 2; /* Length of PIAFS extention */
  7506. dlc[17] = PIAFS_UDATA_ABILITIES; /* control (UDATA) ability */
  7507. dlc[18] = b2_config_parms[4].info[0]; /* value */
  7508. dlc[ 0] = 18;
  7509. }
  7510. }
  7511. else /* default values, 64K, variable, no compression */
  7512. {
  7513. dlc[ 7] = 7;
  7514. dlc[ 8] = 0;
  7515. dlc[ 9] = 0x03; /* PIAFS protocol Speed configuration */
  7516. dlc[10] = 0x03; /* V.42bis P0 */
  7517. dlc[11] = 0; /* V.42bis P0 */
  7518. dlc[12] = 0; /* V.42bis P1 */
  7519. dlc[13] = 0; /* V.42bis P1 */
  7520. dlc[14] = 0; /* V.42bis P2 */
  7521. dlc[15] = 0; /* V.42bis P2 */
  7522. dlc[ 0] = 15;
  7523. }
  7524. add_p(plci, DLC, dlc);
  7525. }
  7526. else
  7527. if ((llc[1] == V120_L2) || (llc[1] == V120_V42BIS))
  7528. {
  7529. if (plci->B3_prot != B3_TRANSPARENT)
  7530. return _B_STACK_NOT_SUPPORTED;
  7531. dlc[0] = 6;
  7532. PUT_WORD (&dlc[1], GET_WORD (&dlc[1]) + 2);
  7533. dlc[3] = 0x08;
  7534. dlc[4] = 0x01;
  7535. dlc[5] = 127;
  7536. dlc[6] = 7;
  7537. if (b2_config->length != 0)
  7538. {
  7539. if((llc[1]==V120_V42BIS) && api_parse(&b2_config->info[1], (word)b2_config->length, "bbbbwww", b2_config_parms)) {
  7540. return _WRONG_MESSAGE_FORMAT;
  7541. }
  7542. dlc[3] = (byte)((b2_config->info[2] << 3) | ((b2_config->info[1] >> 5) & 0x04));
  7543. dlc[4] = (byte)((b2_config->info[1] << 1) | 0x01);
  7544. if (b2_config->info[3] != 128)
  7545. {
  7546. dbug(1,dprintf("1D-dlc= %x %x %x %x %x", dlc[0], dlc[1], dlc[2], dlc[3], dlc[4]));
  7547. return _B2_PARM_NOT_SUPPORTED;
  7548. }
  7549. dlc[5] = (byte)(b2_config->info[3] - 1);
  7550. dlc[6] = b2_config->info[4];
  7551. if(llc[1]==V120_V42BIS){
  7552. if (b2_config->length >= 10){
  7553. dlc[ 7] = 6;
  7554. dlc[ 8] = 0;
  7555. dlc[ 9] = b2_config_parms[4].info[0];
  7556. dlc[10] = b2_config_parms[4].info[1];
  7557. dlc[11] = b2_config_parms[5].info[0];
  7558. dlc[12] = b2_config_parms[5].info[1];
  7559. dlc[13] = b2_config_parms[6].info[0];
  7560. dlc[14] = b2_config_parms[6].info[1];
  7561. dlc[ 0] = 14;
  7562. dbug(1,dprintf("b2_config_parms[4].info[0] [1]: %x %x", b2_config_parms[4].info[0], b2_config_parms[4].info[1]));
  7563. dbug(1,dprintf("b2_config_parms[5].info[0] [1]: %x %x", b2_config_parms[5].info[0], b2_config_parms[5].info[1]));
  7564. dbug(1,dprintf("b2_config_parms[6].info[0] [1]: %x %x", b2_config_parms[6].info[0], b2_config_parms[6].info[1]));
  7565. }
  7566. else {
  7567. dlc[ 6] = 14;
  7568. }
  7569. }
  7570. }
  7571. }
  7572. else
  7573. {
  7574. if(b2_config->length)
  7575. {
  7576. dbug(1,dprintf("B2-Config"));
  7577. if(llc[1]==X75_V42BIS){
  7578. if(api_parse(&b2_config->info[1], (word)b2_config->length, "bbbbwww", b2_config_parms))
  7579. {
  7580. return _WRONG_MESSAGE_FORMAT;
  7581. }
  7582. }
  7583. else {
  7584. if(api_parse(&b2_config->info[1], (word)b2_config->length, "bbbbs", b2_config_parms))
  7585. {
  7586. return _WRONG_MESSAGE_FORMAT;
  7587. }
  7588. }
  7589. /* if B2 Protocol is LAPD, b2_config structure is different */
  7590. if(llc[1]==6)
  7591. {
  7592. dlc[0] = 4;
  7593. if(b2_config->length>=1) dlc[2] = b2_config->info[1]; /* TEI */
  7594. else dlc[2] = 0x01;
  7595. if( (b2_config->length>=2) && (plci->B2_prot==12) )
  7596. {
  7597. SAPI = b2_config->info[2]; /* SAPI */
  7598. }
  7599. dlc[1] = SAPI;
  7600. if( (b2_config->length>=3) && (b2_config->info[3]==128) )
  7601. {
  7602. dlc[3] = 127; /* Mode */
  7603. }
  7604. else
  7605. {
  7606. dlc[3] = 7; /* Mode */
  7607. }
  7608. if(b2_config->length>=4) dlc[4] = b2_config->info[4]; /* Window */
  7609. else dlc[4] = 1;
  7610. dbug(1,dprintf("D-dlc[%d]=%x,%x,%x,%x", dlc[0], dlc[1], dlc[2], dlc[3], dlc[4]));
  7611. if(b2_config->length>5) return _B2_PARM_NOT_SUPPORTED;
  7612. }
  7613. else
  7614. {
  7615. dlc[0] = (byte)(b2_config_parms[4].length+6);
  7616. dlc[3] = b2_config->info[1];
  7617. dlc[4] = b2_config->info[2];
  7618. if(b2_config->info[3]!=8 && b2_config->info[3]!=128){
  7619. dbug(1,dprintf("1D-dlc= %x %x %x %x %x", dlc[0], dlc[1], dlc[2], dlc[3], dlc[4]));
  7620. return _B2_PARM_NOT_SUPPORTED;
  7621. }
  7622. dlc[5] = (byte)(b2_config->info[3]-1);
  7623. dlc[6] = b2_config->info[4];
  7624. if(dlc[6]>dlc[5]){
  7625. 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]));
  7626. return _B2_PARM_NOT_SUPPORTED;
  7627. }
  7628. if(llc[1]==X75_V42BIS) {
  7629. if (b2_config->length >= 10){
  7630. dlc[ 7] = 6;
  7631. dlc[ 8] = 0;
  7632. dlc[ 9] = b2_config_parms[4].info[0];
  7633. dlc[10] = b2_config_parms[4].info[1];
  7634. dlc[11] = b2_config_parms[5].info[0];
  7635. dlc[12] = b2_config_parms[5].info[1];
  7636. dlc[13] = b2_config_parms[6].info[0];
  7637. dlc[14] = b2_config_parms[6].info[1];
  7638. dlc[ 0] = 14;
  7639. dbug(1,dprintf("b2_config_parms[4].info[0] [1]: %x %x", b2_config_parms[4].info[0], b2_config_parms[4].info[1]));
  7640. dbug(1,dprintf("b2_config_parms[5].info[0] [1]: %x %x", b2_config_parms[5].info[0], b2_config_parms[5].info[1]));
  7641. dbug(1,dprintf("b2_config_parms[6].info[0] [1]: %x %x", b2_config_parms[6].info[0], b2_config_parms[6].info[1]));
  7642. }
  7643. else {
  7644. dlc[ 6] = 14;
  7645. }
  7646. }
  7647. else {
  7648. PUT_WORD(&dlc[7], (word)b2_config_parms[4].length);
  7649. for(i=0; i<b2_config_parms[4].length; i++)
  7650. dlc[11+i] = b2_config_parms[4].info[1+i];
  7651. }
  7652. }
  7653. }
  7654. }
  7655. add_p(plci, DLC, dlc);
  7656. b3_config = &bp_parms[5];
  7657. if(b3_config->length)
  7658. {
  7659. if(plci->B3_prot == 4
  7660. || plci->B3_prot == 5)
  7661. {
  7662. if(api_parse(&b3_config->info[1], (word)b3_config->length, "wwss", b3_config_parms))
  7663. {
  7664. return _WRONG_MESSAGE_FORMAT;
  7665. }
  7666. i = GET_WORD((byte *)(b3_config_parms[0].info));
  7667. ((T30_INFO *)&nlc[1])->resolution = (byte)(((i & 0x0001) ||
  7668. ((plci->B3_prot == 4) && (((byte)(GET_WORD((byte *)b3_config_parms[1].info))) != 5))) ? T30_RESOLUTION_R8_0770_OR_200 : 0);
  7669. ((T30_INFO *)&nlc[1])->data_format = (byte)(GET_WORD((byte *)b3_config_parms[1].info));
  7670. fax_control_bits = T30_CONTROL_BIT_ALL_FEATURES;
  7671. if ((((T30_INFO *)&nlc[1])->rate_div_2400 != 0) && (((T30_INFO *)&nlc[1])->rate_div_2400 <= 6))
  7672. fax_control_bits &= ~T30_CONTROL_BIT_ENABLE_V34FAX;
  7673. if (plci->adapter->manufacturer_features & MANUFACTURER_FEATURE_FAX_PAPER_FORMATS)
  7674. {
  7675. if ((plci->requested_options_conn | plci->requested_options | plci->adapter->requested_options_table[plci->appl->Id-1])
  7676. & (1L << PRIVATE_FAX_PAPER_FORMATS))
  7677. {
  7678. ((T30_INFO *)&nlc[1])->resolution |= T30_RESOLUTION_R8_1540 |
  7679. T30_RESOLUTION_R16_1540_OR_400 | T30_RESOLUTION_300_300 |
  7680. T30_RESOLUTION_INCH_BASED | T30_RESOLUTION_METRIC_BASED;
  7681. }
  7682. ((T30_INFO *)&nlc[1])->recording_properties =
  7683. T30_RECORDING_WIDTH_ISO_A3 |
  7684. (T30_RECORDING_LENGTH_UNLIMITED << 2) |
  7685. (T30_MIN_SCANLINE_TIME_00_00_00 << 4);
  7686. }
  7687. if(plci->B3_prot == 5)
  7688. {
  7689. if (i & 0x0002) /* Accept incoming fax-polling requests */
  7690. fax_control_bits |= T30_CONTROL_BIT_ACCEPT_POLLING;
  7691. if (i & 0x2000) /* Do not use MR compression */
  7692. fax_control_bits &= ~T30_CONTROL_BIT_ENABLE_2D_CODING;
  7693. if (i & 0x4000) /* Do not use MMR compression */
  7694. fax_control_bits &= ~T30_CONTROL_BIT_ENABLE_T6_CODING;
  7695. if (i & 0x8000) /* Do not use ECM */
  7696. fax_control_bits &= ~T30_CONTROL_BIT_ENABLE_ECM;
  7697. if (plci->fax_connect_info_length != 0)
  7698. {
  7699. ((T30_INFO *)&nlc[1])->resolution = ((T30_INFO *)plci->fax_connect_info_buffer)->resolution;
  7700. ((T30_INFO *)&nlc[1])->data_format = ((T30_INFO *)plci->fax_connect_info_buffer)->data_format;
  7701. ((T30_INFO *)&nlc[1])->recording_properties = ((T30_INFO *)plci->fax_connect_info_buffer)->recording_properties;
  7702. fax_control_bits |= GET_WORD(&((T30_INFO *)plci->fax_connect_info_buffer)->control_bits_low) &
  7703. (T30_CONTROL_BIT_REQUEST_POLLING | T30_CONTROL_BIT_MORE_DOCUMENTS);
  7704. }
  7705. }
  7706. /* copy station id to NLC */
  7707. for(i=0; i<20; i++)
  7708. {
  7709. if(i<b3_config_parms[2].length)
  7710. {
  7711. ((T30_INFO *)&nlc[1])->station_id[i] = ((byte *)b3_config_parms[2].info)[1+i];
  7712. }
  7713. else
  7714. {
  7715. ((T30_INFO *)&nlc[1])->station_id[i] = ' ';
  7716. }
  7717. }
  7718. ((T30_INFO *)&nlc[1])->station_id_len = 20;
  7719. /* copy head line to NLC */
  7720. if(b3_config_parms[3].length)
  7721. {
  7722. pos = (byte)(fax_head_line_time (&(((T30_INFO *)&nlc[1])->station_id[20])));
  7723. if (pos != 0)
  7724. {
  7725. if (CAPI_MAX_DATE_TIME_LENGTH + 2 + b3_config_parms[3].length > CAPI_MAX_HEAD_LINE_SPACE)
  7726. pos = 0;
  7727. else
  7728. {
  7729. ((T30_INFO *)&nlc[1])->station_id[20 + pos++] = ' ';
  7730. ((T30_INFO *)&nlc[1])->station_id[20 + pos++] = ' ';
  7731. len = (byte)b3_config_parms[2].length;
  7732. if (len > 20)
  7733. len = 20;
  7734. if (CAPI_MAX_DATE_TIME_LENGTH + 2 + len + 2 + b3_config_parms[3].length <= CAPI_MAX_HEAD_LINE_SPACE)
  7735. {
  7736. for (i = 0; i < len; i++)
  7737. ((T30_INFO *)&nlc[1])->station_id[20 + pos++] = ((byte *)b3_config_parms[2].info)[1+i];
  7738. ((T30_INFO *)&nlc[1])->station_id[20 + pos++] = ' ';
  7739. ((T30_INFO *)&nlc[1])->station_id[20 + pos++] = ' ';
  7740. }
  7741. }
  7742. }
  7743. len = (byte)b3_config_parms[3].length;
  7744. if (len > CAPI_MAX_HEAD_LINE_SPACE - pos)
  7745. len = (byte)(CAPI_MAX_HEAD_LINE_SPACE - pos);
  7746. ((T30_INFO *)&nlc[1])->head_line_len = (byte)(pos + len);
  7747. nlc[0] += (byte)(pos + len);
  7748. for (i = 0; i < len; i++)
  7749. ((T30_INFO *)&nlc[1])->station_id[20 + pos++] = ((byte *)b3_config_parms[3].info)[1+i];
  7750. }
  7751. else
  7752. ((T30_INFO *)&nlc[1])->head_line_len = 0;
  7753. plci->nsf_control_bits = 0;
  7754. if(plci->B3_prot == 5)
  7755. {
  7756. if ((plci->adapter->man_profile.private_options & (1L << PRIVATE_FAX_SUB_SEP_PWD))
  7757. && (GET_WORD((byte *)b3_config_parms[1].info) & 0x8000)) /* Private SUB/SEP/PWD enable */
  7758. {
  7759. plci->requested_options |= 1L << PRIVATE_FAX_SUB_SEP_PWD;
  7760. }
  7761. if ((plci->adapter->man_profile.private_options & (1L << PRIVATE_FAX_NONSTANDARD))
  7762. && (GET_WORD((byte *)b3_config_parms[1].info) & 0x4000)) /* Private non-standard facilities enable */
  7763. {
  7764. plci->requested_options |= 1L << PRIVATE_FAX_NONSTANDARD;
  7765. }
  7766. if ((plci->requested_options_conn | plci->requested_options | plci->adapter->requested_options_table[plci->appl->Id-1])
  7767. & ((1L << PRIVATE_FAX_SUB_SEP_PWD) | (1L << PRIVATE_FAX_NONSTANDARD)))
  7768. {
  7769. if ((plci->requested_options_conn | plci->requested_options | plci->adapter->requested_options_table[plci->appl->Id-1])
  7770. & (1L << PRIVATE_FAX_SUB_SEP_PWD))
  7771. {
  7772. fax_control_bits |= T30_CONTROL_BIT_ACCEPT_SUBADDRESS | T30_CONTROL_BIT_ACCEPT_PASSWORD;
  7773. if (fax_control_bits & T30_CONTROL_BIT_ACCEPT_POLLING)
  7774. fax_control_bits |= T30_CONTROL_BIT_ACCEPT_SEL_POLLING;
  7775. }
  7776. len = nlc[0];
  7777. pos = ((byte)(((T30_INFO *) 0)->station_id + 20));
  7778. if (pos < plci->fax_connect_info_length)
  7779. {
  7780. for (i = 1 + plci->fax_connect_info_buffer[pos]; i != 0; i--)
  7781. nlc[++len] = plci->fax_connect_info_buffer[pos++];
  7782. }
  7783. else
  7784. nlc[++len] = 0;
  7785. if (pos < plci->fax_connect_info_length)
  7786. {
  7787. for (i = 1 + plci->fax_connect_info_buffer[pos]; i != 0; i--)
  7788. nlc[++len] = plci->fax_connect_info_buffer[pos++];
  7789. }
  7790. else
  7791. nlc[++len] = 0;
  7792. if ((plci->requested_options_conn | plci->requested_options | plci->adapter->requested_options_table[plci->appl->Id-1])
  7793. & (1L << PRIVATE_FAX_NONSTANDARD))
  7794. {
  7795. if ((pos < plci->fax_connect_info_length) && (plci->fax_connect_info_buffer[pos] != 0))
  7796. {
  7797. if ((plci->fax_connect_info_buffer[pos] >= 3) && (plci->fax_connect_info_buffer[pos+1] >= 2))
  7798. plci->nsf_control_bits = GET_WORD(&plci->fax_connect_info_buffer[pos+2]);
  7799. for (i = 1 + plci->fax_connect_info_buffer[pos]; i != 0; i--)
  7800. nlc[++len] = plci->fax_connect_info_buffer[pos++];
  7801. }
  7802. else
  7803. {
  7804. if(api_parse(&b3_config->info[1], (word)b3_config->length, "wwsss", b3_config_parms))
  7805. {
  7806. dbug(1,dprintf("non-standard facilities info missing or wrong format"));
  7807. nlc[++len] = 0;
  7808. }
  7809. else
  7810. {
  7811. if ((b3_config_parms[4].length >= 3) && (b3_config_parms[4].info[1] >= 2))
  7812. plci->nsf_control_bits = GET_WORD(&b3_config_parms[4].info[2]);
  7813. nlc[++len] = (byte)(b3_config_parms[4].length);
  7814. for (i = 0; i < b3_config_parms[4].length; i++)
  7815. nlc[++len] = b3_config_parms[4].info[1+i];
  7816. }
  7817. }
  7818. }
  7819. nlc[0] = len;
  7820. if ((plci->nsf_control_bits & T30_NSF_CONTROL_BIT_ENABLE_NSF)
  7821. && (plci->nsf_control_bits & T30_NSF_CONTROL_BIT_NEGOTIATE_RESP))
  7822. {
  7823. ((T30_INFO *)&nlc[1])->operating_mode = T30_OPERATING_MODE_CAPI_NEG;
  7824. }
  7825. }
  7826. }
  7827. PUT_WORD(&(((T30_INFO *)&nlc[1])->control_bits_low), fax_control_bits);
  7828. len = ((byte)(((T30_INFO *) 0)->station_id + 20));
  7829. for (i = 0; i < len; i++)
  7830. plci->fax_connect_info_buffer[i] = nlc[1+i];
  7831. ((T30_INFO *) plci->fax_connect_info_buffer)->head_line_len = 0;
  7832. i += ((T30_INFO *)&nlc[1])->head_line_len;
  7833. while (i < nlc[0])
  7834. plci->fax_connect_info_buffer[len++] = nlc[++i];
  7835. plci->fax_connect_info_length = len;
  7836. }
  7837. else
  7838. {
  7839. nlc[0] = 14;
  7840. if(b3_config->length!=16)
  7841. return _B3_PARM_NOT_SUPPORTED;
  7842. for(i=0; i<12; i++) nlc[1+i] = b3_config->info[1+i];
  7843. if(GET_WORD(&b3_config->info[13])!=8 && GET_WORD(&b3_config->info[13])!=128)
  7844. return _B3_PARM_NOT_SUPPORTED;
  7845. nlc[13] = b3_config->info[13];
  7846. if(GET_WORD(&b3_config->info[15])>=nlc[13])
  7847. return _B3_PARM_NOT_SUPPORTED;
  7848. nlc[14] = b3_config->info[15];
  7849. }
  7850. }
  7851. else
  7852. {
  7853. if (plci->B3_prot == 4
  7854. || plci->B3_prot == 5 /*T.30 - FAX*/ ) return _B3_PARM_NOT_SUPPORTED;
  7855. }
  7856. add_p(plci, NLC, nlc);
  7857. return 0;
  7858. }
  7859. /*----------------------------------------------------------------*/
  7860. /* make the same as add_b23, but only for the modem related */
  7861. /* L2 and L3 B-Chan protocol. */
  7862. /* */
  7863. /* Enabled L2 and L3 Configurations: */
  7864. /* If L1 == Modem all negotiation */
  7865. /* only L2 == Modem with full negotiation is allowed */
  7866. /* If L1 == Modem async or sync */
  7867. /* only L2 == Transparent is allowed */
  7868. /* L3 == Modem or L3 == Transparent are allowed */
  7869. /* B2 Configuration for modem: */
  7870. /* word : enable/disable compression, bitoptions */
  7871. /* B3 Configuration for modem: */
  7872. /* empty */
  7873. /*----------------------------------------------------------------*/
  7874. static word add_modem_b23 (PLCI * plci, API_PARSE* bp_parms)
  7875. {
  7876. static byte lli[12] = {1,1};
  7877. static byte llc[3] = {2,0,0};
  7878. static byte dlc[16] = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
  7879. API_PARSE mdm_config[2];
  7880. word i;
  7881. word b2_config = 0;
  7882. for(i=0;i<2;i++) mdm_config[i].length = 0;
  7883. for(i=0;i<sizeof(dlc);i++) dlc[i] = 0;
  7884. if (((GET_WORD(bp_parms[0].info) == B1_MODEM_ALL_NEGOTIATE)
  7885. && (GET_WORD(bp_parms[1].info) != B2_MODEM_EC_COMPRESSION))
  7886. || ((GET_WORD(bp_parms[0].info) != B1_MODEM_ALL_NEGOTIATE)
  7887. && (GET_WORD(bp_parms[1].info) != B2_TRANSPARENT)))
  7888. {
  7889. return (_B_STACK_NOT_SUPPORTED);
  7890. }
  7891. if ((GET_WORD(bp_parms[2].info) != B3_MODEM)
  7892. && (GET_WORD(bp_parms[2].info) != B3_TRANSPARENT))
  7893. {
  7894. return (_B_STACK_NOT_SUPPORTED);
  7895. }
  7896. plci->B2_prot = (byte) GET_WORD(bp_parms[1].info);
  7897. plci->B3_prot = (byte) GET_WORD(bp_parms[2].info);
  7898. if ((GET_WORD(bp_parms[1].info) == B2_MODEM_EC_COMPRESSION) && bp_parms[4].length)
  7899. {
  7900. if (api_parse (&bp_parms[4].info[1],
  7901. (word)bp_parms[4].length, "w",
  7902. mdm_config))
  7903. {
  7904. return (_WRONG_MESSAGE_FORMAT);
  7905. }
  7906. b2_config = GET_WORD(mdm_config[0].info);
  7907. }
  7908. /* OK, L2 is modem */
  7909. lli[0] = 1;
  7910. lli[1] = 1;
  7911. if (plci->adapter->manufacturer_features & MANUFACTURER_FEATURE_XONOFF_FLOW_CONTROL)
  7912. lli[1] |= 2;
  7913. if (plci->adapter->manufacturer_features & MANUFACTURER_FEATURE_OOB_CHANNEL)
  7914. lli[1] |= 4;
  7915. if ((lli[1] & 0x02) && (diva_xdi_extended_features & DIVA_CAPI_USE_CMA)) {
  7916. lli[1] |= 0x10;
  7917. if (plci->rx_dma_descriptor <= 0) {
  7918. plci->rx_dma_descriptor=diva_get_dma_descriptor(plci,&plci->rx_dma_magic);
  7919. if (plci->rx_dma_descriptor >= 0)
  7920. plci->rx_dma_descriptor++;
  7921. }
  7922. if (plci->rx_dma_descriptor > 0) {
  7923. lli[1] |= 0x40;
  7924. lli[0] = 6;
  7925. lli[2] = (byte)(plci->rx_dma_descriptor - 1);
  7926. lli[3] = (byte)plci->rx_dma_magic;
  7927. lli[4] = (byte)(plci->rx_dma_magic >> 8);
  7928. lli[5] = (byte)(plci->rx_dma_magic >> 16);
  7929. lli[6] = (byte)(plci->rx_dma_magic >> 24);
  7930. }
  7931. }
  7932. if (DIVA_CAPI_SUPPORTS_NO_CANCEL(plci->adapter)) {
  7933. lli[1] |= 0x20;
  7934. }
  7935. llc[1] = (plci->call_dir & (CALL_DIR_ORIGINATE | CALL_DIR_FORCE_OUTG_NL)) ?
  7936. /*V42*/ 10 : /*V42_IN*/ 9;
  7937. llc[2] = 4; /* pass L3 always transparent */
  7938. add_p(plci, LLI, lli);
  7939. add_p(plci, LLC, llc);
  7940. i = 1;
  7941. PUT_WORD (&dlc[i], plci->appl->MaxDataLength);
  7942. i += 2;
  7943. if (GET_WORD(bp_parms[1].info) == B2_MODEM_EC_COMPRESSION)
  7944. {
  7945. if (bp_parms[4].length)
  7946. {
  7947. dbug(1, dprintf("MDM b2_config=%02x", b2_config));
  7948. dlc[i++] = 3; /* Addr A */
  7949. dlc[i++] = 1; /* Addr B */
  7950. dlc[i++] = 7; /* modulo mode */
  7951. dlc[i++] = 7; /* window size */
  7952. dlc[i++] = 0; /* XID len Lo */
  7953. dlc[i++] = 0; /* XID len Hi */
  7954. if (b2_config & MDM_B2_DISABLE_V42bis)
  7955. {
  7956. dlc[i] |= DLC_MODEMPROT_DISABLE_V42_V42BIS;
  7957. }
  7958. if (b2_config & MDM_B2_DISABLE_MNP)
  7959. {
  7960. dlc[i] |= DLC_MODEMPROT_DISABLE_MNP_MNP5;
  7961. }
  7962. if (b2_config & MDM_B2_DISABLE_TRANS)
  7963. {
  7964. dlc[i] |= DLC_MODEMPROT_REQUIRE_PROTOCOL;
  7965. }
  7966. if (b2_config & MDM_B2_DISABLE_V42)
  7967. {
  7968. dlc[i] |= DLC_MODEMPROT_DISABLE_V42_DETECT;
  7969. }
  7970. if (b2_config & MDM_B2_DISABLE_COMP)
  7971. {
  7972. dlc[i] |= DLC_MODEMPROT_DISABLE_COMPRESSION;
  7973. }
  7974. i++;
  7975. }
  7976. }
  7977. else
  7978. {
  7979. dlc[i++] = 3; /* Addr A */
  7980. dlc[i++] = 1; /* Addr B */
  7981. dlc[i++] = 7; /* modulo mode */
  7982. dlc[i++] = 7; /* window size */
  7983. dlc[i++] = 0; /* XID len Lo */
  7984. dlc[i++] = 0; /* XID len Hi */
  7985. dlc[i++] = DLC_MODEMPROT_DISABLE_V42_V42BIS |
  7986. DLC_MODEMPROT_DISABLE_MNP_MNP5 |
  7987. DLC_MODEMPROT_DISABLE_V42_DETECT |
  7988. DLC_MODEMPROT_DISABLE_COMPRESSION;
  7989. }
  7990. dlc[0] = (byte)(i - 1);
  7991. /* HexDump ("DLC", sizeof(dlc), &dlc[0]); */
  7992. add_p(plci, DLC, dlc);
  7993. return (0);
  7994. }
  7995. /*------------------------------------------------------------------*/
  7996. /* send a request for the signaling entity */
  7997. /*------------------------------------------------------------------*/
  7998. static void sig_req(PLCI *plci, byte req, byte Id)
  7999. {
  8000. if(!plci) return;
  8001. if(plci->adapter->adapter_disabled) return;
  8002. dbug(1,dprintf("sig_req(%x)",req));
  8003. if (req == REMOVE)
  8004. plci->sig_remove_id = plci->Sig.Id;
  8005. if(plci->req_in==plci->req_in_start) {
  8006. plci->req_in +=2;
  8007. plci->RBuffer[plci->req_in++] = 0;
  8008. }
  8009. PUT_WORD(&plci->RBuffer[plci->req_in_start], plci->req_in-plci->req_in_start-2);
  8010. plci->RBuffer[plci->req_in++] = Id; /* sig/nl flag */
  8011. plci->RBuffer[plci->req_in++] = req; /* request */
  8012. plci->RBuffer[plci->req_in++] = 0; /* channel */
  8013. plci->req_in_start = plci->req_in;
  8014. }
  8015. /*------------------------------------------------------------------*/
  8016. /* send a request for the network layer entity */
  8017. /*------------------------------------------------------------------*/
  8018. static void nl_req_ncci(PLCI *plci, byte req, byte ncci)
  8019. {
  8020. if(!plci) return;
  8021. if(plci->adapter->adapter_disabled) return;
  8022. dbug(1,dprintf("nl_req %02x %02x %02x", plci->Id, req, ncci));
  8023. if (req == REMOVE)
  8024. {
  8025. plci->nl_remove_id = plci->NL.Id;
  8026. ncci_remove (plci, 0, (byte)(ncci != 0));
  8027. ncci = 0;
  8028. }
  8029. if(plci->req_in==plci->req_in_start) {
  8030. plci->req_in +=2;
  8031. plci->RBuffer[plci->req_in++] = 0;
  8032. }
  8033. PUT_WORD(&plci->RBuffer[plci->req_in_start], plci->req_in-plci->req_in_start-2);
  8034. plci->RBuffer[plci->req_in++] = 1; /* sig/nl flag */
  8035. plci->RBuffer[plci->req_in++] = req; /* request */
  8036. plci->RBuffer[plci->req_in++] = plci->adapter->ncci_ch[ncci]; /* channel */
  8037. plci->req_in_start = plci->req_in;
  8038. }
  8039. static void send_req(PLCI *plci)
  8040. {
  8041. ENTITY * e;
  8042. word l;
  8043. /* word i; */
  8044. if(!plci) return;
  8045. if(plci->adapter->adapter_disabled) return;
  8046. channel_xmit_xon (plci);
  8047. /* if nothing to do, return */
  8048. if(plci->req_in==plci->req_out) return;
  8049. dbug(1,dprintf("send_req(in=%d,out=%d)",plci->req_in,plci->req_out));
  8050. if(plci->nl_req || plci->sig_req) return;
  8051. l = GET_WORD(&plci->RBuffer[plci->req_out]);
  8052. plci->req_out += 2;
  8053. plci->XData[0].P = &plci->RBuffer[plci->req_out];
  8054. plci->req_out += l;
  8055. if(plci->RBuffer[plci->req_out]==1)
  8056. {
  8057. e = &plci->NL;
  8058. plci->req_out++;
  8059. e->Req = plci->nl_req = plci->RBuffer[plci->req_out++];
  8060. e->ReqCh = plci->RBuffer[plci->req_out++];
  8061. if(!(e->Id & 0x1f))
  8062. {
  8063. e->Id = NL_ID;
  8064. plci->RBuffer[plci->req_out-4] = CAI;
  8065. plci->RBuffer[plci->req_out-3] = 1;
  8066. plci->RBuffer[plci->req_out-2] = (plci->Sig.Id==0xff) ? 0 : plci->Sig.Id;
  8067. plci->RBuffer[plci->req_out-1] = 0;
  8068. l+=3;
  8069. plci->nl_global_req = plci->nl_req;
  8070. }
  8071. dbug(1,dprintf("%x:NLREQ(%x:%x:%x)",plci->adapter->Id,e->Id,e->Req,e->ReqCh));
  8072. }
  8073. else
  8074. {
  8075. e = &plci->Sig;
  8076. if(plci->RBuffer[plci->req_out])
  8077. e->Id = plci->RBuffer[plci->req_out];
  8078. plci->req_out++;
  8079. e->Req = plci->sig_req = plci->RBuffer[plci->req_out++];
  8080. e->ReqCh = plci->RBuffer[plci->req_out++];
  8081. if(!(e->Id & 0x1f))
  8082. plci->sig_global_req = plci->sig_req;
  8083. dbug(1,dprintf("%x:SIGREQ(%x:%x:%x)",plci->adapter->Id,e->Id,e->Req,e->ReqCh));
  8084. }
  8085. plci->XData[0].PLength = l;
  8086. e->X = plci->XData;
  8087. plci->adapter->request(e);
  8088. dbug(1,dprintf("send_ok"));
  8089. }
  8090. static void send_data(PLCI *plci)
  8091. {
  8092. DIVA_CAPI_ADAPTER * a;
  8093. DATA_B3_DESC * data;
  8094. NCCI *ncci_ptr;
  8095. word ncci;
  8096. if (!plci->nl_req && plci->ncci_ring_list)
  8097. {
  8098. a = plci->adapter;
  8099. ncci = plci->ncci_ring_list;
  8100. do
  8101. {
  8102. ncci = a->ncci_next[ncci];
  8103. ncci_ptr = &(a->ncci[ncci]);
  8104. if (!(a->ncci_ch[ncci]
  8105. && (a->ch_flow_control[a->ncci_ch[ncci]] & N_OK_FC_PENDING)))
  8106. {
  8107. if (ncci_ptr->data_pending)
  8108. {
  8109. if ((a->ncci_state[ncci] == CONNECTED)
  8110. || (a->ncci_state[ncci] == INC_ACT_PENDING)
  8111. || (plci->send_disc == ncci))
  8112. {
  8113. data = &(ncci_ptr->DBuffer[ncci_ptr->data_out]);
  8114. if ((plci->B2_prot == B2_V120_ASYNC)
  8115. || (plci->B2_prot == B2_V120_ASYNC_V42BIS)
  8116. || (plci->B2_prot == B2_V120_BIT_TRANSPARENT))
  8117. {
  8118. plci->NData[1].P = TransmitBufferGet (plci->appl, data->P);
  8119. plci->NData[1].PLength = data->Length;
  8120. if (data->Flags & 0x10)
  8121. plci->NData[0].P = v120_break_header;
  8122. else
  8123. plci->NData[0].P = v120_default_header;
  8124. plci->NData[0].PLength = 1 ;
  8125. plci->NL.XNum = 2;
  8126. plci->NL.Req = plci->nl_req = (byte)((data->Flags&0x07)<<4 |N_DATA);
  8127. }
  8128. else
  8129. {
  8130. plci->NData[0].P = TransmitBufferGet (plci->appl, data->P);
  8131. plci->NData[0].PLength = data->Length;
  8132. if (data->Flags & 0x10)
  8133. plci->NL.Req = plci->nl_req = (byte)N_UDATA;
  8134. else if ((plci->B3_prot == B3_RTP) && (data->Flags & 0x01))
  8135. plci->NL.Req = plci->nl_req = (byte)N_BDATA;
  8136. else
  8137. plci->NL.Req = plci->nl_req = (byte)((data->Flags&0x07)<<4 |N_DATA);
  8138. }
  8139. plci->NL.X = plci->NData;
  8140. plci->NL.ReqCh = a->ncci_ch[ncci];
  8141. dbug(1,dprintf("%x:DREQ(%x:%x)",a->Id,plci->NL.Id,plci->NL.Req));
  8142. plci->data_sent = true;
  8143. plci->data_sent_ptr = data->P;
  8144. a->request(&plci->NL);
  8145. }
  8146. else {
  8147. cleanup_ncci_data (plci, ncci);
  8148. }
  8149. }
  8150. else if (plci->send_disc == ncci)
  8151. {
  8152. /* dprintf("N_DISC"); */
  8153. plci->NData[0].PLength = 0;
  8154. plci->NL.ReqCh = a->ncci_ch[ncci];
  8155. plci->NL.Req = plci->nl_req = N_DISC;
  8156. a->request(&plci->NL);
  8157. plci->command = _DISCONNECT_B3_R;
  8158. plci->send_disc = 0;
  8159. }
  8160. }
  8161. } while (!plci->nl_req && (ncci != plci->ncci_ring_list));
  8162. plci->ncci_ring_list = ncci;
  8163. }
  8164. }
  8165. static void listen_check(DIVA_CAPI_ADAPTER *a)
  8166. {
  8167. word i,j;
  8168. PLCI * plci;
  8169. byte activnotifiedcalls = 0;
  8170. dbug(1,dprintf("listen_check(%d,%d)",a->listen_active,a->max_listen));
  8171. if (!remove_started && !a->adapter_disabled)
  8172. {
  8173. for(i=0;i<a->max_plci;i++)
  8174. {
  8175. plci = &(a->plci[i]);
  8176. if(plci->notifiedcall) activnotifiedcalls++;
  8177. }
  8178. dbug(1,dprintf("listen_check(%d)",activnotifiedcalls));
  8179. for(i=a->listen_active; i < ((word)(a->max_listen+activnotifiedcalls)); i++) {
  8180. if((j=get_plci(a))) {
  8181. a->listen_active++;
  8182. plci = &a->plci[j-1];
  8183. plci->State = LISTENING;
  8184. add_p(plci,OAD,"\x01\xfd");
  8185. add_p(plci,KEY,"\x04\x43\x41\x32\x30");
  8186. add_p(plci,CAI,"\x01\xc0");
  8187. add_p(plci,UID,"\x06\x43\x61\x70\x69\x32\x30");
  8188. add_p(plci,LLI,"\x01\xc4"); /* support Dummy CR FAC + MWI + SpoofNotify */
  8189. add_p(plci,SHIFT|6,NULL);
  8190. add_p(plci,SIN,"\x02\x00\x00");
  8191. plci->internal_command = LISTEN_SIG_ASSIGN_PEND; /* do indicate_req if OK */
  8192. sig_req(plci,ASSIGN,DSIG_ID);
  8193. send_req(plci);
  8194. }
  8195. }
  8196. }
  8197. }
  8198. /*------------------------------------------------------------------*/
  8199. /* functions for all parameters sent in INDs */
  8200. /*------------------------------------------------------------------*/
  8201. static void IndParse(PLCI *plci, word *parms_id, byte **parms, byte multiIEsize)
  8202. {
  8203. word ploc; /* points to current location within packet */
  8204. byte w;
  8205. byte wlen;
  8206. byte codeset,lock;
  8207. byte * in;
  8208. word i;
  8209. word code;
  8210. word mIEindex = 0;
  8211. ploc = 0;
  8212. codeset = 0;
  8213. lock = 0;
  8214. in = plci->Sig.RBuffer->P;
  8215. for(i=0; i<parms_id[0]; i++) /* multiIE parms_id contains just the 1st */
  8216. { /* element but parms array is larger */
  8217. parms[i] = (byte *)"";
  8218. }
  8219. for(i=0; i<multiIEsize; i++)
  8220. {
  8221. parms[i] = (byte *)"";
  8222. }
  8223. while(ploc<plci->Sig.RBuffer->length-1) {
  8224. /* read information element id and length */
  8225. w = in[ploc];
  8226. if(w & 0x80) {
  8227. /* w &=0xf0; removed, cannot detect congestion levels */
  8228. /* upper 4 bit masked with w==SHIFT now */
  8229. wlen = 0;
  8230. }
  8231. else {
  8232. wlen = (byte)(in[ploc+1]+1);
  8233. }
  8234. /* check if length valid (not exceeding end of packet) */
  8235. if((ploc+wlen) > 270) return ;
  8236. if(lock & 0x80) lock &=0x7f;
  8237. else codeset = lock;
  8238. if((w&0xf0)==SHIFT) {
  8239. codeset = in[ploc];
  8240. if(!(codeset & 0x08)) lock = (byte)(codeset & 7);
  8241. codeset &=7;
  8242. lock |=0x80;
  8243. }
  8244. else {
  8245. if(w==ESC && wlen>=3) code = in[ploc+2] |0x800;
  8246. else code = w;
  8247. code |= (codeset<<8);
  8248. for(i=1; i<parms_id[0]+1 && parms_id[i]!=code; i++);
  8249. if(i<parms_id[0]+1) {
  8250. if(!multiIEsize) { /* with multiIEs use next field index, */
  8251. mIEindex = i-1; /* with normal IEs use same index like parms_id */
  8252. }
  8253. parms[mIEindex] = &in[ploc+1];
  8254. dbug(1,dprintf("mIE[%d]=0x%x",*parms[mIEindex],in[ploc]));
  8255. if(parms_id[i]==OAD
  8256. || parms_id[i]==CONN_NR
  8257. || parms_id[i]==CAD) {
  8258. if(in[ploc+2] &0x80) {
  8259. in[ploc+0] = (byte)(in[ploc+1]+1);
  8260. in[ploc+1] = (byte)(in[ploc+2] &0x7f);
  8261. in[ploc+2] = 0x80;
  8262. parms[mIEindex] = &in[ploc];
  8263. }
  8264. }
  8265. mIEindex++; /* effects multiIEs only */
  8266. }
  8267. }
  8268. ploc +=(wlen+1);
  8269. }
  8270. return ;
  8271. }
  8272. /*------------------------------------------------------------------*/
  8273. /* try to match a cip from received BC and HLC */
  8274. /*------------------------------------------------------------------*/
  8275. static byte ie_compare(byte *ie1, byte *ie2)
  8276. {
  8277. word i;
  8278. if(!ie1 || ! ie2) return false;
  8279. if(!ie1[0]) return false;
  8280. for(i=0;i<(word)(ie1[0]+1);i++) if(ie1[i]!=ie2[i]) return false;
  8281. return true;
  8282. }
  8283. static word find_cip(DIVA_CAPI_ADAPTER *a, byte *bc, byte *hlc)
  8284. {
  8285. word i;
  8286. word j;
  8287. for(i=9;i && !ie_compare(bc,cip_bc[i][a->u_law]);i--);
  8288. for(j=16;j<29 &&
  8289. (!ie_compare(bc,cip_bc[j][a->u_law]) || !ie_compare(hlc,cip_hlc[j])); j++);
  8290. if(j==29) return i;
  8291. return j;
  8292. }
  8293. static byte AddInfo(byte **add_i,
  8294. byte **fty_i,
  8295. byte *esc_chi,
  8296. byte *facility)
  8297. {
  8298. byte i;
  8299. byte j;
  8300. byte k;
  8301. byte flen;
  8302. byte len=0;
  8303. /* facility is a nested structure */
  8304. /* FTY can be more than once */
  8305. if (esc_chi[0] && !(esc_chi[esc_chi[0]] & 0x7f))
  8306. {
  8307. add_i[0] = (byte *)"\x02\x02\x00"; /* use neither b nor d channel */
  8308. }
  8309. else
  8310. {
  8311. add_i[0] = (byte *)"";
  8312. }
  8313. if(!fty_i[0][0])
  8314. {
  8315. add_i[3] = (byte *)"";
  8316. }
  8317. else
  8318. { /* facility array found */
  8319. for(i=0,j=1;i<MAX_MULTI_IE && fty_i[i][0];i++)
  8320. {
  8321. dbug(1,dprintf("AddIFac[%d]",fty_i[i][0]));
  8322. len += fty_i[i][0];
  8323. len += 2;
  8324. flen=fty_i[i][0];
  8325. facility[j++]=0x1c; /* copy fac IE */
  8326. for(k=0;k<=flen;k++,j++)
  8327. {
  8328. facility[j]=fty_i[i][k];
  8329. /* dbug(1,dprintf("%x ",facility[j])); */
  8330. }
  8331. }
  8332. facility[0] = len;
  8333. add_i[3] = facility;
  8334. }
  8335. /* dbug(1,dprintf("FacArrLen=%d ",len)); */
  8336. len = add_i[0][0]+add_i[1][0]+add_i[2][0]+add_i[3][0];
  8337. len += 4; /* calculate length of all */
  8338. return(len);
  8339. }
  8340. /*------------------------------------------------------------------*/
  8341. /* voice and codec features */
  8342. /*------------------------------------------------------------------*/
  8343. static void SetVoiceChannel(PLCI *plci, byte *chi, DIVA_CAPI_ADAPTER *a)
  8344. {
  8345. byte voice_chi[] = "\x02\x18\x01";
  8346. byte channel;
  8347. channel = chi[chi[0]]&0x3;
  8348. dbug(1,dprintf("ExtDevON(Ch=0x%x)",channel));
  8349. voice_chi[2] = (channel) ? channel : 1;
  8350. add_p(plci,FTY,"\x02\x01\x07"); /* B On, default on 1 */
  8351. add_p(plci,ESC,voice_chi); /* Channel */
  8352. sig_req(plci,TEL_CTRL,0);
  8353. send_req(plci);
  8354. if(a->AdvSignalPLCI)
  8355. {
  8356. adv_voice_write_coefs (a->AdvSignalPLCI, ADV_VOICE_WRITE_ACTIVATION);
  8357. }
  8358. }
  8359. static void VoiceChannelOff(PLCI *plci)
  8360. {
  8361. dbug(1,dprintf("ExtDevOFF"));
  8362. add_p(plci,FTY,"\x02\x01\x08"); /* B Off */
  8363. sig_req(plci,TEL_CTRL,0);
  8364. send_req(plci);
  8365. if(plci->adapter->AdvSignalPLCI)
  8366. {
  8367. adv_voice_clear_config (plci->adapter->AdvSignalPLCI);
  8368. }
  8369. }
  8370. static word AdvCodecSupport(DIVA_CAPI_ADAPTER *a, PLCI *plci, APPL *appl,
  8371. byte hook_listen)
  8372. {
  8373. word j;
  8374. PLCI *splci;
  8375. /* check if hardware supports handset with hook states (adv.codec) */
  8376. /* or if just a on board codec is supported */
  8377. /* the advanced codec plci is just for internal use */
  8378. /* diva Pro with on-board codec: */
  8379. if(a->profile.Global_Options & HANDSET)
  8380. {
  8381. /* new call, but hook states are already signalled */
  8382. if(a->AdvCodecFLAG)
  8383. {
  8384. if(a->AdvSignalAppl!=appl || a->AdvSignalPLCI)
  8385. {
  8386. dbug(1,dprintf("AdvSigPlci=0x%x",a->AdvSignalPLCI));
  8387. return 0x2001; /* codec in use by another application */
  8388. }
  8389. if(plci!=NULL)
  8390. {
  8391. a->AdvSignalPLCI = plci;
  8392. plci->tel=ADV_VOICE;
  8393. }
  8394. return 0; /* adv codec still used */
  8395. }
  8396. if((j=get_plci(a)))
  8397. {
  8398. splci = &a->plci[j-1];
  8399. splci->tel = CODEC_PERMANENT;
  8400. /* hook_listen indicates if a facility_req with handset/hook support */
  8401. /* was sent. Otherwise if just a call on an external device was made */
  8402. /* the codec will be used but the hook info will be discarded (just */
  8403. /* the external controller is in use */
  8404. if(hook_listen) splci->State = ADVANCED_VOICE_SIG;
  8405. else
  8406. {
  8407. splci->State = ADVANCED_VOICE_NOSIG;
  8408. if(plci)
  8409. {
  8410. plci->spoofed_msg = SPOOFING_REQUIRED;
  8411. }
  8412. /* indicate D-ch connect if */
  8413. } /* codec is connected OK */
  8414. if(plci!=NULL)
  8415. {
  8416. a->AdvSignalPLCI = plci;
  8417. plci->tel=ADV_VOICE;
  8418. }
  8419. a->AdvSignalAppl = appl;
  8420. a->AdvCodecFLAG = true;
  8421. a->AdvCodecPLCI = splci;
  8422. add_p(splci,CAI,"\x01\x15");
  8423. add_p(splci,LLI,"\x01\x00");
  8424. add_p(splci,ESC,"\x02\x18\x00");
  8425. add_p(splci,UID,"\x06\x43\x61\x70\x69\x32\x30");
  8426. splci->internal_command = PERM_COD_ASSIGN;
  8427. dbug(1,dprintf("Codec Assign"));
  8428. sig_req(splci,ASSIGN,DSIG_ID);
  8429. send_req(splci);
  8430. }
  8431. else
  8432. {
  8433. return 0x2001; /* wrong state, no more plcis */
  8434. }
  8435. }
  8436. else if(a->profile.Global_Options & ON_BOARD_CODEC)
  8437. {
  8438. if(hook_listen) return 0x300B; /* Facility not supported */
  8439. /* no hook with SCOM */
  8440. if(plci!=NULL) plci->tel = CODEC;
  8441. dbug(1,dprintf("S/SCOM codec"));
  8442. /* first time we use the scom-s codec we must shut down the internal */
  8443. /* handset application of the card. This can be done by an assign with */
  8444. /* a cai with the 0x80 bit set. Assign return code is 'out of resource'*/
  8445. if(!a->scom_appl_disable){
  8446. if((j=get_plci(a))) {
  8447. splci = &a->plci[j-1];
  8448. add_p(splci,CAI,"\x01\x80");
  8449. add_p(splci,UID,"\x06\x43\x61\x70\x69\x32\x30");
  8450. sig_req(splci,ASSIGN,0xC0); /* 0xc0 is the TEL_ID */
  8451. send_req(splci);
  8452. a->scom_appl_disable = true;
  8453. }
  8454. else{
  8455. return 0x2001; /* wrong state, no more plcis */
  8456. }
  8457. }
  8458. }
  8459. else return 0x300B; /* Facility not supported */
  8460. return 0;
  8461. }
  8462. static void CodecIdCheck(DIVA_CAPI_ADAPTER *a, PLCI *plci)
  8463. {
  8464. dbug(1,dprintf("CodecIdCheck"));
  8465. if(a->AdvSignalPLCI == plci)
  8466. {
  8467. dbug(1,dprintf("PLCI owns codec"));
  8468. VoiceChannelOff(a->AdvCodecPLCI);
  8469. if(a->AdvCodecPLCI->State == ADVANCED_VOICE_NOSIG)
  8470. {
  8471. dbug(1,dprintf("remove temp codec PLCI"));
  8472. plci_remove(a->AdvCodecPLCI);
  8473. a->AdvCodecFLAG = 0;
  8474. a->AdvCodecPLCI = NULL;
  8475. a->AdvSignalAppl = NULL;
  8476. }
  8477. a->AdvSignalPLCI = NULL;
  8478. }
  8479. }
  8480. /* -------------------------------------------------------------------
  8481. Ask for physical address of card on PCI bus
  8482. ------------------------------------------------------------------- */
  8483. static void diva_ask_for_xdi_sdram_bar (DIVA_CAPI_ADAPTER * a,
  8484. IDI_SYNC_REQ * preq) {
  8485. a->sdram_bar = 0;
  8486. if (diva_xdi_extended_features & DIVA_CAPI_XDI_PROVIDES_SDRAM_BAR) {
  8487. ENTITY * e = (ENTITY *)preq;
  8488. e->user[0] = a->Id - 1;
  8489. preq->xdi_sdram_bar.info.bar = 0;
  8490. preq->xdi_sdram_bar.Req = 0;
  8491. preq->xdi_sdram_bar.Rc = IDI_SYNC_REQ_XDI_GET_ADAPTER_SDRAM_BAR;
  8492. (*(a->request))(e);
  8493. a->sdram_bar = preq->xdi_sdram_bar.info.bar;
  8494. dbug(3,dprintf("A(%d) SDRAM BAR = %08x", a->Id, a->sdram_bar));
  8495. }
  8496. }
  8497. /* -------------------------------------------------------------------
  8498. Ask XDI about extended features
  8499. ------------------------------------------------------------------- */
  8500. static void diva_get_extended_adapter_features (DIVA_CAPI_ADAPTER * a) {
  8501. IDI_SYNC_REQ * preq;
  8502. char buffer[ ((sizeof(preq->xdi_extended_features)+4) > sizeof(ENTITY)) ? (sizeof(preq->xdi_extended_features)+4) : sizeof(ENTITY)];
  8503. char features[4];
  8504. preq = (IDI_SYNC_REQ *)&buffer[0];
  8505. if (!diva_xdi_extended_features) {
  8506. ENTITY * e = (ENTITY *)preq;
  8507. diva_xdi_extended_features |= 0x80000000;
  8508. e->user[0] = a->Id - 1;
  8509. preq->xdi_extended_features.Req = 0;
  8510. preq->xdi_extended_features.Rc = IDI_SYNC_REQ_XDI_GET_EXTENDED_FEATURES;
  8511. preq->xdi_extended_features.info.buffer_length_in_bytes = sizeof(features);
  8512. preq->xdi_extended_features.info.features = &features[0];
  8513. (*(a->request))(e);
  8514. if (features[0] & DIVA_XDI_EXTENDED_FEATURES_VALID) {
  8515. /*
  8516. Check features located in the byte '0'
  8517. */
  8518. if (features[0] & DIVA_XDI_EXTENDED_FEATURE_CMA) {
  8519. diva_xdi_extended_features |= DIVA_CAPI_USE_CMA;
  8520. }
  8521. if (features[0] & DIVA_XDI_EXTENDED_FEATURE_RX_DMA) {
  8522. diva_xdi_extended_features |= DIVA_CAPI_XDI_PROVIDES_RX_DMA;
  8523. dbug(1,dprintf("XDI provides RxDMA"));
  8524. }
  8525. if (features[0] & DIVA_XDI_EXTENDED_FEATURE_SDRAM_BAR) {
  8526. diva_xdi_extended_features |= DIVA_CAPI_XDI_PROVIDES_SDRAM_BAR;
  8527. }
  8528. if (features[0] & DIVA_XDI_EXTENDED_FEATURE_NO_CANCEL_RC) {
  8529. diva_xdi_extended_features |= DIVA_CAPI_XDI_PROVIDES_NO_CANCEL;
  8530. dbug(3,dprintf("XDI provides NO_CANCEL_RC feature"));
  8531. }
  8532. }
  8533. }
  8534. diva_ask_for_xdi_sdram_bar (a, preq);
  8535. }
  8536. /*------------------------------------------------------------------*/
  8537. /* automatic law */
  8538. /*------------------------------------------------------------------*/
  8539. /* called from OS specific part after init time to get the Law */
  8540. /* a-law (Euro) and u-law (us,japan) use different BCs in the Setup message */
  8541. void AutomaticLaw(DIVA_CAPI_ADAPTER *a)
  8542. {
  8543. word j;
  8544. PLCI *splci;
  8545. if(a->automatic_law) {
  8546. return;
  8547. }
  8548. if((j=get_plci(a))) {
  8549. diva_get_extended_adapter_features (a);
  8550. splci = &a->plci[j-1];
  8551. a->automatic_lawPLCI = splci;
  8552. a->automatic_law = 1;
  8553. add_p(splci,CAI,"\x01\x80");
  8554. add_p(splci,UID,"\x06\x43\x61\x70\x69\x32\x30");
  8555. splci->internal_command = USELAW_REQ;
  8556. splci->command = 0;
  8557. splci->number = 0;
  8558. sig_req(splci,ASSIGN,DSIG_ID);
  8559. send_req(splci);
  8560. }
  8561. }
  8562. /* called from OS specific part if an application sends an Capi20Release */
  8563. word CapiRelease(word Id)
  8564. {
  8565. word i, j, appls_found;
  8566. PLCI *plci;
  8567. APPL *this;
  8568. DIVA_CAPI_ADAPTER *a;
  8569. if (!Id)
  8570. {
  8571. dbug(0,dprintf("A: CapiRelease(Id==0)"));
  8572. return (_WRONG_APPL_ID);
  8573. }
  8574. this = &application[Id-1]; /* get application pointer */
  8575. for(i=0,appls_found=0; i<max_appl; i++)
  8576. {
  8577. if(application[i].Id) /* an application has been found */
  8578. {
  8579. appls_found++;
  8580. }
  8581. }
  8582. for(i=0; i<max_adapter; i++) /* scan all adapters... */
  8583. {
  8584. a = &adapter[i];
  8585. if (a->request)
  8586. {
  8587. a->Info_Mask[Id-1] = 0;
  8588. a->CIP_Mask[Id-1] = 0;
  8589. a->Notification_Mask[Id-1] = 0;
  8590. a->codec_listen[Id-1] = NULL;
  8591. a->requested_options_table[Id-1] = 0;
  8592. for(j=0; j<a->max_plci; j++) /* and all PLCIs connected */
  8593. { /* with this application */
  8594. plci = &a->plci[j];
  8595. if(plci->Id) /* if plci owns no application */
  8596. { /* it may be not jet connected */
  8597. if(plci->State==INC_CON_PENDING
  8598. || plci->State==INC_CON_ALERT)
  8599. {
  8600. if(test_c_ind_mask_bit (plci, (word)(Id-1)))
  8601. {
  8602. clear_c_ind_mask_bit (plci, (word)(Id-1));
  8603. if(c_ind_mask_empty (plci))
  8604. {
  8605. sig_req(plci,HANGUP,0);
  8606. send_req(plci);
  8607. plci->State = OUTG_DIS_PENDING;
  8608. }
  8609. }
  8610. }
  8611. if(test_c_ind_mask_bit (plci, (word)(Id-1)))
  8612. {
  8613. clear_c_ind_mask_bit (plci, (word)(Id-1));
  8614. if(c_ind_mask_empty (plci))
  8615. {
  8616. if(!plci->appl)
  8617. {
  8618. plci_remove(plci);
  8619. plci->State = IDLE;
  8620. }
  8621. }
  8622. }
  8623. if(plci->appl==this)
  8624. {
  8625. plci->appl = NULL;
  8626. plci_remove(plci);
  8627. plci->State = IDLE;
  8628. }
  8629. }
  8630. }
  8631. listen_check(a);
  8632. if(a->flag_dynamic_l1_down)
  8633. {
  8634. if(appls_found==1) /* last application does a capi release */
  8635. {
  8636. if((j=get_plci(a)))
  8637. {
  8638. plci = &a->plci[j-1];
  8639. plci->command = 0;
  8640. add_p(plci,OAD,"\x01\xfd");
  8641. add_p(plci,CAI,"\x01\x80");
  8642. add_p(plci,UID,"\x06\x43\x61\x70\x69\x32\x30");
  8643. add_p(plci,SHIFT|6,NULL);
  8644. add_p(plci,SIN,"\x02\x00\x00");
  8645. plci->internal_command = REM_L1_SIG_ASSIGN_PEND;
  8646. sig_req(plci,ASSIGN,DSIG_ID);
  8647. add_p(plci,FTY,"\x02\xff\x06"); /* l1 down */
  8648. sig_req(plci,SIG_CTRL,0);
  8649. send_req(plci);
  8650. }
  8651. }
  8652. }
  8653. if(a->AdvSignalAppl==this)
  8654. {
  8655. this->NullCREnable = false;
  8656. if (a->AdvCodecPLCI)
  8657. {
  8658. plci_remove(a->AdvCodecPLCI);
  8659. a->AdvCodecPLCI->tel = 0;
  8660. a->AdvCodecPLCI->adv_nl = 0;
  8661. }
  8662. a->AdvSignalAppl = NULL;
  8663. a->AdvSignalPLCI = NULL;
  8664. a->AdvCodecFLAG = 0;
  8665. a->AdvCodecPLCI = NULL;
  8666. }
  8667. }
  8668. }
  8669. this->Id = 0;
  8670. return GOOD;
  8671. }
  8672. static word plci_remove_check(PLCI *plci)
  8673. {
  8674. if(!plci) return true;
  8675. if(!plci->NL.Id && c_ind_mask_empty (plci))
  8676. {
  8677. if(plci->Sig.Id == 0xff)
  8678. plci->Sig.Id = 0;
  8679. if(!plci->Sig.Id)
  8680. {
  8681. dbug(1,dprintf("plci_remove_complete(%x)",plci->Id));
  8682. dbug(1,dprintf("tel=0x%x,Sig=0x%x",plci->tel,plci->Sig.Id));
  8683. if (plci->Id)
  8684. {
  8685. CodecIdCheck(plci->adapter, plci);
  8686. clear_b1_config (plci);
  8687. ncci_remove (plci, 0, false);
  8688. plci_free_msg_in_queue (plci);
  8689. channel_flow_control_remove (plci);
  8690. plci->Id = 0;
  8691. plci->State = IDLE;
  8692. plci->channels = 0;
  8693. plci->appl = NULL;
  8694. plci->notifiedcall = 0;
  8695. }
  8696. listen_check(plci->adapter);
  8697. return true;
  8698. }
  8699. }
  8700. return false;
  8701. }
  8702. /*------------------------------------------------------------------*/
  8703. static byte plci_nl_busy (PLCI *plci)
  8704. {
  8705. /* only applicable for non-multiplexed protocols */
  8706. return (plci->nl_req
  8707. || (plci->ncci_ring_list
  8708. && plci->adapter->ncci_ch[plci->ncci_ring_list]
  8709. && (plci->adapter->ch_flow_control[plci->adapter->ncci_ch[plci->ncci_ring_list]] & N_OK_FC_PENDING)));
  8710. }
  8711. /*------------------------------------------------------------------*/
  8712. /* DTMF facilities */
  8713. /*------------------------------------------------------------------*/
  8714. static struct
  8715. {
  8716. byte send_mask;
  8717. byte listen_mask;
  8718. byte character;
  8719. byte code;
  8720. } dtmf_digit_map[] =
  8721. {
  8722. { 0x01, 0x01, 0x23, DTMF_DIGIT_TONE_CODE_HASHMARK },
  8723. { 0x01, 0x01, 0x2a, DTMF_DIGIT_TONE_CODE_STAR },
  8724. { 0x01, 0x01, 0x30, DTMF_DIGIT_TONE_CODE_0 },
  8725. { 0x01, 0x01, 0x31, DTMF_DIGIT_TONE_CODE_1 },
  8726. { 0x01, 0x01, 0x32, DTMF_DIGIT_TONE_CODE_2 },
  8727. { 0x01, 0x01, 0x33, DTMF_DIGIT_TONE_CODE_3 },
  8728. { 0x01, 0x01, 0x34, DTMF_DIGIT_TONE_CODE_4 },
  8729. { 0x01, 0x01, 0x35, DTMF_DIGIT_TONE_CODE_5 },
  8730. { 0x01, 0x01, 0x36, DTMF_DIGIT_TONE_CODE_6 },
  8731. { 0x01, 0x01, 0x37, DTMF_DIGIT_TONE_CODE_7 },
  8732. { 0x01, 0x01, 0x38, DTMF_DIGIT_TONE_CODE_8 },
  8733. { 0x01, 0x01, 0x39, DTMF_DIGIT_TONE_CODE_9 },
  8734. { 0x01, 0x01, 0x41, DTMF_DIGIT_TONE_CODE_A },
  8735. { 0x01, 0x01, 0x42, DTMF_DIGIT_TONE_CODE_B },
  8736. { 0x01, 0x01, 0x43, DTMF_DIGIT_TONE_CODE_C },
  8737. { 0x01, 0x01, 0x44, DTMF_DIGIT_TONE_CODE_D },
  8738. { 0x01, 0x00, 0x61, DTMF_DIGIT_TONE_CODE_A },
  8739. { 0x01, 0x00, 0x62, DTMF_DIGIT_TONE_CODE_B },
  8740. { 0x01, 0x00, 0x63, DTMF_DIGIT_TONE_CODE_C },
  8741. { 0x01, 0x00, 0x64, DTMF_DIGIT_TONE_CODE_D },
  8742. { 0x04, 0x04, 0x80, DTMF_SIGNAL_NO_TONE },
  8743. { 0x00, 0x04, 0x81, DTMF_SIGNAL_UNIDENTIFIED_TONE },
  8744. { 0x04, 0x04, 0x82, DTMF_SIGNAL_DIAL_TONE },
  8745. { 0x04, 0x04, 0x83, DTMF_SIGNAL_PABX_INTERNAL_DIAL_TONE },
  8746. { 0x04, 0x04, 0x84, DTMF_SIGNAL_SPECIAL_DIAL_TONE },
  8747. { 0x04, 0x04, 0x85, DTMF_SIGNAL_SECOND_DIAL_TONE },
  8748. { 0x04, 0x04, 0x86, DTMF_SIGNAL_RINGING_TONE },
  8749. { 0x04, 0x04, 0x87, DTMF_SIGNAL_SPECIAL_RINGING_TONE },
  8750. { 0x04, 0x04, 0x88, DTMF_SIGNAL_BUSY_TONE },
  8751. { 0x04, 0x04, 0x89, DTMF_SIGNAL_CONGESTION_TONE },
  8752. { 0x04, 0x04, 0x8a, DTMF_SIGNAL_SPECIAL_INFORMATION_TONE },
  8753. { 0x04, 0x04, 0x8b, DTMF_SIGNAL_COMFORT_TONE },
  8754. { 0x04, 0x04, 0x8c, DTMF_SIGNAL_HOLD_TONE },
  8755. { 0x04, 0x04, 0x8d, DTMF_SIGNAL_RECORD_TONE },
  8756. { 0x04, 0x04, 0x8e, DTMF_SIGNAL_CALLER_WAITING_TONE },
  8757. { 0x04, 0x04, 0x8f, DTMF_SIGNAL_CALL_WAITING_TONE },
  8758. { 0x04, 0x04, 0x90, DTMF_SIGNAL_PAY_TONE },
  8759. { 0x04, 0x04, 0x91, DTMF_SIGNAL_POSITIVE_INDICATION_TONE },
  8760. { 0x04, 0x04, 0x92, DTMF_SIGNAL_NEGATIVE_INDICATION_TONE },
  8761. { 0x04, 0x04, 0x93, DTMF_SIGNAL_WARNING_TONE },
  8762. { 0x04, 0x04, 0x94, DTMF_SIGNAL_INTRUSION_TONE },
  8763. { 0x04, 0x04, 0x95, DTMF_SIGNAL_CALLING_CARD_SERVICE_TONE },
  8764. { 0x04, 0x04, 0x96, DTMF_SIGNAL_PAYPHONE_RECOGNITION_TONE },
  8765. { 0x04, 0x04, 0x97, DTMF_SIGNAL_CPE_ALERTING_SIGNAL },
  8766. { 0x04, 0x04, 0x98, DTMF_SIGNAL_OFF_HOOK_WARNING_TONE },
  8767. { 0x04, 0x04, 0xbf, DTMF_SIGNAL_INTERCEPT_TONE },
  8768. { 0x04, 0x04, 0xc0, DTMF_SIGNAL_MODEM_CALLING_TONE },
  8769. { 0x04, 0x04, 0xc1, DTMF_SIGNAL_FAX_CALLING_TONE },
  8770. { 0x04, 0x04, 0xc2, DTMF_SIGNAL_ANSWER_TONE },
  8771. { 0x04, 0x04, 0xc3, DTMF_SIGNAL_REVERSED_ANSWER_TONE },
  8772. { 0x04, 0x04, 0xc4, DTMF_SIGNAL_ANSAM_TONE },
  8773. { 0x04, 0x04, 0xc5, DTMF_SIGNAL_REVERSED_ANSAM_TONE },
  8774. { 0x04, 0x04, 0xc6, DTMF_SIGNAL_BELL103_ANSWER_TONE },
  8775. { 0x04, 0x04, 0xc7, DTMF_SIGNAL_FAX_FLAGS },
  8776. { 0x04, 0x04, 0xc8, DTMF_SIGNAL_G2_FAX_GROUP_ID },
  8777. { 0x00, 0x04, 0xc9, DTMF_SIGNAL_HUMAN_SPEECH },
  8778. { 0x04, 0x04, 0xca, DTMF_SIGNAL_ANSWERING_MACHINE_390 },
  8779. { 0x02, 0x02, 0xf1, DTMF_MF_DIGIT_TONE_CODE_1 },
  8780. { 0x02, 0x02, 0xf2, DTMF_MF_DIGIT_TONE_CODE_2 },
  8781. { 0x02, 0x02, 0xf3, DTMF_MF_DIGIT_TONE_CODE_3 },
  8782. { 0x02, 0x02, 0xf4, DTMF_MF_DIGIT_TONE_CODE_4 },
  8783. { 0x02, 0x02, 0xf5, DTMF_MF_DIGIT_TONE_CODE_5 },
  8784. { 0x02, 0x02, 0xf6, DTMF_MF_DIGIT_TONE_CODE_6 },
  8785. { 0x02, 0x02, 0xf7, DTMF_MF_DIGIT_TONE_CODE_7 },
  8786. { 0x02, 0x02, 0xf8, DTMF_MF_DIGIT_TONE_CODE_8 },
  8787. { 0x02, 0x02, 0xf9, DTMF_MF_DIGIT_TONE_CODE_9 },
  8788. { 0x02, 0x02, 0xfa, DTMF_MF_DIGIT_TONE_CODE_0 },
  8789. { 0x02, 0x02, 0xfb, DTMF_MF_DIGIT_TONE_CODE_K1 },
  8790. { 0x02, 0x02, 0xfc, DTMF_MF_DIGIT_TONE_CODE_K2 },
  8791. { 0x02, 0x02, 0xfd, DTMF_MF_DIGIT_TONE_CODE_KP },
  8792. { 0x02, 0x02, 0xfe, DTMF_MF_DIGIT_TONE_CODE_S1 },
  8793. { 0x02, 0x02, 0xff, DTMF_MF_DIGIT_TONE_CODE_ST },
  8794. };
  8795. #define DTMF_DIGIT_MAP_ENTRIES ARRAY_SIZE(dtmf_digit_map)
  8796. static void dtmf_enable_receiver (PLCI *plci, byte enable_mask)
  8797. {
  8798. word min_digit_duration, min_gap_duration;
  8799. dbug (1, dprintf ("[%06lx] %s,%d: dtmf_enable_receiver %02x",
  8800. (dword)((plci->Id << 8) | UnMapController (plci->adapter->Id)),
  8801. (char *)(FILE_), __LINE__, enable_mask));
  8802. if (enable_mask != 0)
  8803. {
  8804. min_digit_duration = (plci->dtmf_rec_pulse_ms == 0) ? 40 : plci->dtmf_rec_pulse_ms;
  8805. min_gap_duration = (plci->dtmf_rec_pause_ms == 0) ? 40 : plci->dtmf_rec_pause_ms;
  8806. plci->internal_req_buffer[0] = DTMF_UDATA_REQUEST_ENABLE_RECEIVER;
  8807. PUT_WORD (&plci->internal_req_buffer[1], min_digit_duration);
  8808. PUT_WORD (&plci->internal_req_buffer[3], min_gap_duration);
  8809. plci->NData[0].PLength = 5;
  8810. PUT_WORD (&plci->internal_req_buffer[5], INTERNAL_IND_BUFFER_SIZE);
  8811. plci->NData[0].PLength += 2;
  8812. capidtmf_recv_enable (&(plci->capidtmf_state), min_digit_duration, min_gap_duration);
  8813. }
  8814. else
  8815. {
  8816. plci->internal_req_buffer[0] = DTMF_UDATA_REQUEST_DISABLE_RECEIVER;
  8817. plci->NData[0].PLength = 1;
  8818. capidtmf_recv_disable (&(plci->capidtmf_state));
  8819. }
  8820. plci->NData[0].P = plci->internal_req_buffer;
  8821. plci->NL.X = plci->NData;
  8822. plci->NL.ReqCh = 0;
  8823. plci->NL.Req = plci->nl_req = (byte) N_UDATA;
  8824. plci->adapter->request (&plci->NL);
  8825. }
  8826. static void dtmf_send_digits (PLCI *plci, byte *digit_buffer, word digit_count)
  8827. {
  8828. word w, i;
  8829. dbug (1, dprintf ("[%06lx] %s,%d: dtmf_send_digits %d",
  8830. (dword)((plci->Id << 8) | UnMapController (plci->adapter->Id)),
  8831. (char *)(FILE_), __LINE__, digit_count));
  8832. plci->internal_req_buffer[0] = DTMF_UDATA_REQUEST_SEND_DIGITS;
  8833. w = (plci->dtmf_send_pulse_ms == 0) ? 40 : plci->dtmf_send_pulse_ms;
  8834. PUT_WORD (&plci->internal_req_buffer[1], w);
  8835. w = (plci->dtmf_send_pause_ms == 0) ? 40 : plci->dtmf_send_pause_ms;
  8836. PUT_WORD (&plci->internal_req_buffer[3], w);
  8837. for (i = 0; i < digit_count; i++)
  8838. {
  8839. w = 0;
  8840. while ((w < DTMF_DIGIT_MAP_ENTRIES)
  8841. && (digit_buffer[i] != dtmf_digit_map[w].character))
  8842. {
  8843. w++;
  8844. }
  8845. plci->internal_req_buffer[5+i] = (w < DTMF_DIGIT_MAP_ENTRIES) ?
  8846. dtmf_digit_map[w].code : DTMF_DIGIT_TONE_CODE_STAR;
  8847. }
  8848. plci->NData[0].PLength = 5 + digit_count;
  8849. plci->NData[0].P = plci->internal_req_buffer;
  8850. plci->NL.X = plci->NData;
  8851. plci->NL.ReqCh = 0;
  8852. plci->NL.Req = plci->nl_req = (byte) N_UDATA;
  8853. plci->adapter->request (&plci->NL);
  8854. }
  8855. static void dtmf_rec_clear_config (PLCI *plci)
  8856. {
  8857. dbug (1, dprintf ("[%06lx] %s,%d: dtmf_rec_clear_config",
  8858. (dword)((plci->Id << 8) | UnMapController (plci->adapter->Id)),
  8859. (char *)(FILE_), __LINE__));
  8860. plci->dtmf_rec_active = 0;
  8861. plci->dtmf_rec_pulse_ms = 0;
  8862. plci->dtmf_rec_pause_ms = 0;
  8863. capidtmf_init (&(plci->capidtmf_state), plci->adapter->u_law);
  8864. }
  8865. static void dtmf_send_clear_config (PLCI *plci)
  8866. {
  8867. dbug (1, dprintf ("[%06lx] %s,%d: dtmf_send_clear_config",
  8868. (dword)((plci->Id << 8) | UnMapController (plci->adapter->Id)),
  8869. (char *)(FILE_), __LINE__));
  8870. plci->dtmf_send_requests = 0;
  8871. plci->dtmf_send_pulse_ms = 0;
  8872. plci->dtmf_send_pause_ms = 0;
  8873. }
  8874. static void dtmf_prepare_switch (dword Id, PLCI *plci)
  8875. {
  8876. dbug (1, dprintf ("[%06lx] %s,%d: dtmf_prepare_switch",
  8877. UnMapId (Id), (char *)(FILE_), __LINE__));
  8878. while (plci->dtmf_send_requests != 0)
  8879. dtmf_confirmation (Id, plci);
  8880. }
  8881. static word dtmf_save_config (dword Id, PLCI *plci, byte Rc)
  8882. {
  8883. dbug (1, dprintf ("[%06lx] %s,%d: dtmf_save_config %02x %d",
  8884. UnMapId (Id), (char *)(FILE_), __LINE__, Rc, plci->adjust_b_state));
  8885. return (GOOD);
  8886. }
  8887. static word dtmf_restore_config (dword Id, PLCI *plci, byte Rc)
  8888. {
  8889. word Info;
  8890. dbug (1, dprintf ("[%06lx] %s,%d: dtmf_restore_config %02x %d",
  8891. UnMapId (Id), (char *)(FILE_), __LINE__, Rc, plci->adjust_b_state));
  8892. Info = GOOD;
  8893. if (plci->B1_facilities & B1_FACILITY_DTMFR)
  8894. {
  8895. switch (plci->adjust_b_state)
  8896. {
  8897. case ADJUST_B_RESTORE_DTMF_1:
  8898. plci->internal_command = plci->adjust_b_command;
  8899. if (plci_nl_busy (plci))
  8900. {
  8901. plci->adjust_b_state = ADJUST_B_RESTORE_DTMF_1;
  8902. break;
  8903. }
  8904. dtmf_enable_receiver (plci, plci->dtmf_rec_active);
  8905. plci->adjust_b_state = ADJUST_B_RESTORE_DTMF_2;
  8906. break;
  8907. case ADJUST_B_RESTORE_DTMF_2:
  8908. if ((Rc != OK) && (Rc != OK_FC))
  8909. {
  8910. dbug (1, dprintf ("[%06lx] %s,%d: Reenable DTMF receiver failed %02x",
  8911. UnMapId (Id), (char *)(FILE_), __LINE__, Rc));
  8912. Info = _WRONG_STATE;
  8913. break;
  8914. }
  8915. break;
  8916. }
  8917. }
  8918. return (Info);
  8919. }
  8920. static void dtmf_command (dword Id, PLCI *plci, byte Rc)
  8921. {
  8922. word internal_command, Info;
  8923. byte mask;
  8924. byte result[4];
  8925. dbug (1, dprintf ("[%06lx] %s,%d: dtmf_command %02x %04x %04x %d %d %d %d",
  8926. UnMapId (Id), (char *)(FILE_), __LINE__, Rc, plci->internal_command,
  8927. plci->dtmf_cmd, plci->dtmf_rec_pulse_ms, plci->dtmf_rec_pause_ms,
  8928. plci->dtmf_send_pulse_ms, plci->dtmf_send_pause_ms));
  8929. Info = GOOD;
  8930. result[0] = 2;
  8931. PUT_WORD (&result[1], DTMF_SUCCESS);
  8932. internal_command = plci->internal_command;
  8933. plci->internal_command = 0;
  8934. mask = 0x01;
  8935. switch (plci->dtmf_cmd)
  8936. {
  8937. case DTMF_LISTEN_TONE_START:
  8938. mask <<= 1;
  8939. case DTMF_LISTEN_MF_START:
  8940. mask <<= 1;
  8941. case DTMF_LISTEN_START:
  8942. switch (internal_command)
  8943. {
  8944. default:
  8945. adjust_b1_resource (Id, plci, NULL, (word)(plci->B1_facilities |
  8946. B1_FACILITY_DTMFR), DTMF_COMMAND_1);
  8947. case DTMF_COMMAND_1:
  8948. if (adjust_b_process (Id, plci, Rc) != GOOD)
  8949. {
  8950. dbug (1, dprintf ("[%06lx] %s,%d: Load DTMF failed",
  8951. UnMapId (Id), (char *)(FILE_), __LINE__));
  8952. Info = _FACILITY_NOT_SUPPORTED;
  8953. break;
  8954. }
  8955. if (plci->internal_command)
  8956. return;
  8957. case DTMF_COMMAND_2:
  8958. if (plci_nl_busy (plci))
  8959. {
  8960. plci->internal_command = DTMF_COMMAND_2;
  8961. return;
  8962. }
  8963. plci->internal_command = DTMF_COMMAND_3;
  8964. dtmf_enable_receiver (plci, (byte)(plci->dtmf_rec_active | mask));
  8965. return;
  8966. case DTMF_COMMAND_3:
  8967. if ((Rc != OK) && (Rc != OK_FC))
  8968. {
  8969. dbug (1, dprintf ("[%06lx] %s,%d: Enable DTMF receiver failed %02x",
  8970. UnMapId (Id), (char *)(FILE_), __LINE__, Rc));
  8971. Info = _FACILITY_NOT_SUPPORTED;
  8972. break;
  8973. }
  8974. plci->tone_last_indication_code = DTMF_SIGNAL_NO_TONE;
  8975. plci->dtmf_rec_active |= mask;
  8976. break;
  8977. }
  8978. break;
  8979. case DTMF_LISTEN_TONE_STOP:
  8980. mask <<= 1;
  8981. case DTMF_LISTEN_MF_STOP:
  8982. mask <<= 1;
  8983. case DTMF_LISTEN_STOP:
  8984. switch (internal_command)
  8985. {
  8986. default:
  8987. plci->dtmf_rec_active &= ~mask;
  8988. if (plci->dtmf_rec_active)
  8989. break;
  8990. /*
  8991. case DTMF_COMMAND_1:
  8992. if (plci->dtmf_rec_active)
  8993. {
  8994. if (plci_nl_busy (plci))
  8995. {
  8996. plci->internal_command = DTMF_COMMAND_1;
  8997. return;
  8998. }
  8999. plci->dtmf_rec_active &= ~mask;
  9000. plci->internal_command = DTMF_COMMAND_2;
  9001. dtmf_enable_receiver (plci, false);
  9002. return;
  9003. }
  9004. Rc = OK;
  9005. case DTMF_COMMAND_2:
  9006. if ((Rc != OK) && (Rc != OK_FC))
  9007. {
  9008. dbug (1, dprintf ("[%06lx] %s,%d: Disable DTMF receiver failed %02x",
  9009. UnMapId (Id), (char far *)(FILE_), __LINE__, Rc));
  9010. Info = _FACILITY_NOT_SUPPORTED;
  9011. break;
  9012. }
  9013. */
  9014. adjust_b1_resource (Id, plci, NULL, (word)(plci->B1_facilities &
  9015. ~(B1_FACILITY_DTMFX | B1_FACILITY_DTMFR)), DTMF_COMMAND_3);
  9016. case DTMF_COMMAND_3:
  9017. if (adjust_b_process (Id, plci, Rc) != GOOD)
  9018. {
  9019. dbug (1, dprintf ("[%06lx] %s,%d: Unload DTMF failed",
  9020. UnMapId (Id), (char *)(FILE_), __LINE__));
  9021. Info = _FACILITY_NOT_SUPPORTED;
  9022. break;
  9023. }
  9024. if (plci->internal_command)
  9025. return;
  9026. break;
  9027. }
  9028. break;
  9029. case DTMF_SEND_TONE:
  9030. mask <<= 1;
  9031. case DTMF_SEND_MF:
  9032. mask <<= 1;
  9033. case DTMF_DIGITS_SEND:
  9034. switch (internal_command)
  9035. {
  9036. default:
  9037. adjust_b1_resource (Id, plci, NULL, (word)(plci->B1_facilities |
  9038. ((plci->dtmf_parameter_length != 0) ? B1_FACILITY_DTMFX | B1_FACILITY_DTMFR : B1_FACILITY_DTMFX)),
  9039. DTMF_COMMAND_1);
  9040. case DTMF_COMMAND_1:
  9041. if (adjust_b_process (Id, plci, Rc) != GOOD)
  9042. {
  9043. dbug (1, dprintf ("[%06lx] %s,%d: Load DTMF failed",
  9044. UnMapId (Id), (char *)(FILE_), __LINE__));
  9045. Info = _FACILITY_NOT_SUPPORTED;
  9046. break;
  9047. }
  9048. if (plci->internal_command)
  9049. return;
  9050. case DTMF_COMMAND_2:
  9051. if (plci_nl_busy (plci))
  9052. {
  9053. plci->internal_command = DTMF_COMMAND_2;
  9054. return;
  9055. }
  9056. plci->dtmf_msg_number_queue[(plci->dtmf_send_requests)++] = plci->number;
  9057. plci->internal_command = DTMF_COMMAND_3;
  9058. dtmf_send_digits (plci, &plci->saved_msg.parms[3].info[1], plci->saved_msg.parms[3].length);
  9059. return;
  9060. case DTMF_COMMAND_3:
  9061. if ((Rc != OK) && (Rc != OK_FC))
  9062. {
  9063. dbug (1, dprintf ("[%06lx] %s,%d: Send DTMF digits failed %02x",
  9064. UnMapId (Id), (char *)(FILE_), __LINE__, Rc));
  9065. if (plci->dtmf_send_requests != 0)
  9066. (plci->dtmf_send_requests)--;
  9067. Info = _FACILITY_NOT_SUPPORTED;
  9068. break;
  9069. }
  9070. return;
  9071. }
  9072. break;
  9073. }
  9074. sendf (plci->appl, _FACILITY_R | CONFIRM, Id & 0xffffL, plci->number,
  9075. "wws", Info, SELECTOR_DTMF, result);
  9076. }
  9077. static byte dtmf_request (dword Id, word Number, DIVA_CAPI_ADAPTER *a, PLCI *plci, APPL *appl, API_PARSE *msg)
  9078. {
  9079. word Info;
  9080. word i, j;
  9081. byte mask;
  9082. API_PARSE dtmf_parms[5];
  9083. byte result[40];
  9084. dbug (1, dprintf ("[%06lx] %s,%d: dtmf_request",
  9085. UnMapId (Id), (char *)(FILE_), __LINE__));
  9086. Info = GOOD;
  9087. result[0] = 2;
  9088. PUT_WORD (&result[1], DTMF_SUCCESS);
  9089. if (!(a->profile.Global_Options & GL_DTMF_SUPPORTED))
  9090. {
  9091. dbug (1, dprintf ("[%06lx] %s,%d: Facility not supported",
  9092. UnMapId (Id), (char *)(FILE_), __LINE__));
  9093. Info = _FACILITY_NOT_SUPPORTED;
  9094. }
  9095. else if (api_parse (&msg[1].info[1], msg[1].length, "w", dtmf_parms))
  9096. {
  9097. dbug (1, dprintf ("[%06lx] %s,%d: Wrong message format",
  9098. UnMapId (Id), (char *)(FILE_), __LINE__));
  9099. Info = _WRONG_MESSAGE_FORMAT;
  9100. }
  9101. else if ((GET_WORD (dtmf_parms[0].info) == DTMF_GET_SUPPORTED_DETECT_CODES)
  9102. || (GET_WORD (dtmf_parms[0].info) == DTMF_GET_SUPPORTED_SEND_CODES))
  9103. {
  9104. if (!((a->requested_options_table[appl->Id-1])
  9105. & (1L << PRIVATE_DTMF_TONE)))
  9106. {
  9107. dbug (1, dprintf ("[%06lx] %s,%d: DTMF unknown request %04x",
  9108. UnMapId (Id), (char *)(FILE_), __LINE__, GET_WORD (dtmf_parms[0].info)));
  9109. PUT_WORD (&result[1], DTMF_UNKNOWN_REQUEST);
  9110. }
  9111. else
  9112. {
  9113. for (i = 0; i < 32; i++)
  9114. result[4 + i] = 0;
  9115. if (GET_WORD (dtmf_parms[0].info) == DTMF_GET_SUPPORTED_DETECT_CODES)
  9116. {
  9117. for (i = 0; i < DTMF_DIGIT_MAP_ENTRIES; i++)
  9118. {
  9119. if (dtmf_digit_map[i].listen_mask != 0)
  9120. result[4 + (dtmf_digit_map[i].character >> 3)] |= (1 << (dtmf_digit_map[i].character & 0x7));
  9121. }
  9122. }
  9123. else
  9124. {
  9125. for (i = 0; i < DTMF_DIGIT_MAP_ENTRIES; i++)
  9126. {
  9127. if (dtmf_digit_map[i].send_mask != 0)
  9128. result[4 + (dtmf_digit_map[i].character >> 3)] |= (1 << (dtmf_digit_map[i].character & 0x7));
  9129. }
  9130. }
  9131. result[0] = 3 + 32;
  9132. result[3] = 32;
  9133. }
  9134. }
  9135. else if (plci == NULL)
  9136. {
  9137. dbug (1, dprintf ("[%06lx] %s,%d: Wrong PLCI",
  9138. UnMapId (Id), (char *)(FILE_), __LINE__));
  9139. Info = _WRONG_IDENTIFIER;
  9140. }
  9141. else
  9142. {
  9143. if (!plci->State
  9144. || !plci->NL.Id || plci->nl_remove_id)
  9145. {
  9146. dbug (1, dprintf ("[%06lx] %s,%d: Wrong state",
  9147. UnMapId (Id), (char *)(FILE_), __LINE__));
  9148. Info = _WRONG_STATE;
  9149. }
  9150. else
  9151. {
  9152. plci->command = 0;
  9153. plci->dtmf_cmd = GET_WORD (dtmf_parms[0].info);
  9154. mask = 0x01;
  9155. switch (plci->dtmf_cmd)
  9156. {
  9157. case DTMF_LISTEN_TONE_START:
  9158. case DTMF_LISTEN_TONE_STOP:
  9159. mask <<= 1;
  9160. case DTMF_LISTEN_MF_START:
  9161. case DTMF_LISTEN_MF_STOP:
  9162. mask <<= 1;
  9163. if (!((plci->requested_options_conn | plci->requested_options | plci->adapter->requested_options_table[appl->Id-1])
  9164. & (1L << PRIVATE_DTMF_TONE)))
  9165. {
  9166. dbug (1, dprintf ("[%06lx] %s,%d: DTMF unknown request %04x",
  9167. UnMapId (Id), (char *)(FILE_), __LINE__, GET_WORD (dtmf_parms[0].info)));
  9168. PUT_WORD (&result[1], DTMF_UNKNOWN_REQUEST);
  9169. break;
  9170. }
  9171. case DTMF_LISTEN_START:
  9172. case DTMF_LISTEN_STOP:
  9173. if (!(a->manufacturer_features & MANUFACTURER_FEATURE_HARDDTMF)
  9174. && !(a->manufacturer_features & MANUFACTURER_FEATURE_SOFTDTMF_RECEIVE))
  9175. {
  9176. dbug (1, dprintf ("[%06lx] %s,%d: Facility not supported",
  9177. UnMapId (Id), (char *)(FILE_), __LINE__));
  9178. Info = _FACILITY_NOT_SUPPORTED;
  9179. break;
  9180. }
  9181. if (mask & DTMF_LISTEN_ACTIVE_FLAG)
  9182. {
  9183. if (api_parse (&msg[1].info[1], msg[1].length, "wwws", dtmf_parms))
  9184. {
  9185. plci->dtmf_rec_pulse_ms = 0;
  9186. plci->dtmf_rec_pause_ms = 0;
  9187. }
  9188. else
  9189. {
  9190. plci->dtmf_rec_pulse_ms = GET_WORD (dtmf_parms[1].info);
  9191. plci->dtmf_rec_pause_ms = GET_WORD (dtmf_parms[2].info);
  9192. }
  9193. }
  9194. start_internal_command (Id, plci, dtmf_command);
  9195. return (false);
  9196. case DTMF_SEND_TONE:
  9197. mask <<= 1;
  9198. case DTMF_SEND_MF:
  9199. mask <<= 1;
  9200. if (!((plci->requested_options_conn | plci->requested_options | plci->adapter->requested_options_table[appl->Id-1])
  9201. & (1L << PRIVATE_DTMF_TONE)))
  9202. {
  9203. dbug (1, dprintf ("[%06lx] %s,%d: DTMF unknown request %04x",
  9204. UnMapId (Id), (char *)(FILE_), __LINE__, GET_WORD (dtmf_parms[0].info)));
  9205. PUT_WORD (&result[1], DTMF_UNKNOWN_REQUEST);
  9206. break;
  9207. }
  9208. case DTMF_DIGITS_SEND:
  9209. if (api_parse (&msg[1].info[1], msg[1].length, "wwws", dtmf_parms))
  9210. {
  9211. dbug (1, dprintf ("[%06lx] %s,%d: Wrong message format",
  9212. UnMapId (Id), (char *)(FILE_), __LINE__));
  9213. Info = _WRONG_MESSAGE_FORMAT;
  9214. break;
  9215. }
  9216. if (mask & DTMF_LISTEN_ACTIVE_FLAG)
  9217. {
  9218. plci->dtmf_send_pulse_ms = GET_WORD (dtmf_parms[1].info);
  9219. plci->dtmf_send_pause_ms = GET_WORD (dtmf_parms[2].info);
  9220. }
  9221. i = 0;
  9222. j = 0;
  9223. while ((i < dtmf_parms[3].length) && (j < DTMF_DIGIT_MAP_ENTRIES))
  9224. {
  9225. j = 0;
  9226. while ((j < DTMF_DIGIT_MAP_ENTRIES)
  9227. && ((dtmf_parms[3].info[i+1] != dtmf_digit_map[j].character)
  9228. || ((dtmf_digit_map[j].send_mask & mask) == 0)))
  9229. {
  9230. j++;
  9231. }
  9232. i++;
  9233. }
  9234. if (j == DTMF_DIGIT_MAP_ENTRIES)
  9235. {
  9236. dbug (1, dprintf ("[%06lx] %s,%d: Incorrect DTMF digit %02x",
  9237. UnMapId (Id), (char *)(FILE_), __LINE__, dtmf_parms[3].info[i]));
  9238. PUT_WORD (&result[1], DTMF_INCORRECT_DIGIT);
  9239. break;
  9240. }
  9241. if (plci->dtmf_send_requests >= ARRAY_SIZE(plci->dtmf_msg_number_queue))
  9242. {
  9243. dbug (1, dprintf ("[%06lx] %s,%d: DTMF request overrun",
  9244. UnMapId (Id), (char *)(FILE_), __LINE__));
  9245. Info = _WRONG_STATE;
  9246. break;
  9247. }
  9248. api_save_msg (dtmf_parms, "wwws", &plci->saved_msg);
  9249. start_internal_command (Id, plci, dtmf_command);
  9250. return (false);
  9251. default:
  9252. dbug (1, dprintf ("[%06lx] %s,%d: DTMF unknown request %04x",
  9253. UnMapId (Id), (char *)(FILE_), __LINE__, plci->dtmf_cmd));
  9254. PUT_WORD (&result[1], DTMF_UNKNOWN_REQUEST);
  9255. }
  9256. }
  9257. }
  9258. sendf (appl, _FACILITY_R | CONFIRM, Id & 0xffffL, Number,
  9259. "wws", Info, SELECTOR_DTMF, result);
  9260. return (false);
  9261. }
  9262. static void dtmf_confirmation (dword Id, PLCI *plci)
  9263. {
  9264. word Info;
  9265. word i;
  9266. byte result[4];
  9267. dbug (1, dprintf ("[%06lx] %s,%d: dtmf_confirmation",
  9268. UnMapId (Id), (char *)(FILE_), __LINE__));
  9269. Info = GOOD;
  9270. result[0] = 2;
  9271. PUT_WORD (&result[1], DTMF_SUCCESS);
  9272. if (plci->dtmf_send_requests != 0)
  9273. {
  9274. sendf (plci->appl, _FACILITY_R | CONFIRM, Id & 0xffffL, plci->dtmf_msg_number_queue[0],
  9275. "wws", GOOD, SELECTOR_DTMF, result);
  9276. (plci->dtmf_send_requests)--;
  9277. for (i = 0; i < plci->dtmf_send_requests; i++)
  9278. plci->dtmf_msg_number_queue[i] = plci->dtmf_msg_number_queue[i+1];
  9279. }
  9280. }
  9281. static void dtmf_indication (dword Id, PLCI *plci, byte *msg, word length)
  9282. {
  9283. word i, j, n;
  9284. dbug (1, dprintf ("[%06lx] %s,%d: dtmf_indication",
  9285. UnMapId (Id), (char *)(FILE_), __LINE__));
  9286. n = 0;
  9287. for (i = 1; i < length; i++)
  9288. {
  9289. j = 0;
  9290. while ((j < DTMF_DIGIT_MAP_ENTRIES)
  9291. && ((msg[i] != dtmf_digit_map[j].code)
  9292. || ((dtmf_digit_map[j].listen_mask & plci->dtmf_rec_active) == 0)))
  9293. {
  9294. j++;
  9295. }
  9296. if (j < DTMF_DIGIT_MAP_ENTRIES)
  9297. {
  9298. if ((dtmf_digit_map[j].listen_mask & DTMF_TONE_LISTEN_ACTIVE_FLAG)
  9299. && (plci->tone_last_indication_code == DTMF_SIGNAL_NO_TONE)
  9300. && (dtmf_digit_map[j].character != DTMF_SIGNAL_UNIDENTIFIED_TONE))
  9301. {
  9302. if (n + 1 == i)
  9303. {
  9304. for (i = length; i > n + 1; i--)
  9305. msg[i] = msg[i - 1];
  9306. length++;
  9307. i++;
  9308. }
  9309. msg[++n] = DTMF_SIGNAL_UNIDENTIFIED_TONE;
  9310. }
  9311. plci->tone_last_indication_code = dtmf_digit_map[j].character;
  9312. msg[++n] = dtmf_digit_map[j].character;
  9313. }
  9314. }
  9315. if (n != 0)
  9316. {
  9317. msg[0] = (byte) n;
  9318. sendf (plci->appl, _FACILITY_I, Id & 0xffffL, 0, "wS", SELECTOR_DTMF, msg);
  9319. }
  9320. }
  9321. /*------------------------------------------------------------------*/
  9322. /* DTMF parameters */
  9323. /*------------------------------------------------------------------*/
  9324. static void dtmf_parameter_write (PLCI *plci)
  9325. {
  9326. word i;
  9327. byte parameter_buffer[DTMF_PARAMETER_BUFFER_SIZE + 2];
  9328. dbug (1, dprintf ("[%06lx] %s,%d: dtmf_parameter_write",
  9329. (dword)((plci->Id << 8) | UnMapController (plci->adapter->Id)),
  9330. (char *)(FILE_), __LINE__));
  9331. parameter_buffer[0] = plci->dtmf_parameter_length + 1;
  9332. parameter_buffer[1] = DSP_CTRL_SET_DTMF_PARAMETERS;
  9333. for (i = 0; i < plci->dtmf_parameter_length; i++)
  9334. parameter_buffer[2+i] = plci->dtmf_parameter_buffer[i];
  9335. add_p (plci, FTY, parameter_buffer);
  9336. sig_req (plci, TEL_CTRL, 0);
  9337. send_req (plci);
  9338. }
  9339. static void dtmf_parameter_clear_config (PLCI *plci)
  9340. {
  9341. dbug (1, dprintf ("[%06lx] %s,%d: dtmf_parameter_clear_config",
  9342. (dword)((plci->Id << 8) | UnMapController (plci->adapter->Id)),
  9343. (char *)(FILE_), __LINE__));
  9344. plci->dtmf_parameter_length = 0;
  9345. }
  9346. static void dtmf_parameter_prepare_switch (dword Id, PLCI *plci)
  9347. {
  9348. dbug (1, dprintf ("[%06lx] %s,%d: dtmf_parameter_prepare_switch",
  9349. UnMapId (Id), (char *)(FILE_), __LINE__));
  9350. }
  9351. static word dtmf_parameter_save_config (dword Id, PLCI *plci, byte Rc)
  9352. {
  9353. dbug (1, dprintf ("[%06lx] %s,%d: dtmf_parameter_save_config %02x %d",
  9354. UnMapId (Id), (char *)(FILE_), __LINE__, Rc, plci->adjust_b_state));
  9355. return (GOOD);
  9356. }
  9357. static word dtmf_parameter_restore_config (dword Id, PLCI *plci, byte Rc)
  9358. {
  9359. word Info;
  9360. dbug (1, dprintf ("[%06lx] %s,%d: dtmf_parameter_restore_config %02x %d",
  9361. UnMapId (Id), (char *)(FILE_), __LINE__, Rc, plci->adjust_b_state));
  9362. Info = GOOD;
  9363. if ((plci->B1_facilities & B1_FACILITY_DTMFR)
  9364. && (plci->dtmf_parameter_length != 0))
  9365. {
  9366. switch (plci->adjust_b_state)
  9367. {
  9368. case ADJUST_B_RESTORE_DTMF_PARAMETER_1:
  9369. plci->internal_command = plci->adjust_b_command;
  9370. if (plci->sig_req)
  9371. {
  9372. plci->adjust_b_state = ADJUST_B_RESTORE_DTMF_PARAMETER_1;
  9373. break;
  9374. }
  9375. dtmf_parameter_write (plci);
  9376. plci->adjust_b_state = ADJUST_B_RESTORE_DTMF_PARAMETER_2;
  9377. break;
  9378. case ADJUST_B_RESTORE_DTMF_PARAMETER_2:
  9379. if ((Rc != OK) && (Rc != OK_FC))
  9380. {
  9381. dbug (1, dprintf ("[%06lx] %s,%d: Restore DTMF parameters failed %02x",
  9382. UnMapId (Id), (char *)(FILE_), __LINE__, Rc));
  9383. Info = _WRONG_STATE;
  9384. break;
  9385. }
  9386. break;
  9387. }
  9388. }
  9389. return (Info);
  9390. }
  9391. /*------------------------------------------------------------------*/
  9392. /* Line interconnect facilities */
  9393. /*------------------------------------------------------------------*/
  9394. LI_CONFIG *li_config_table;
  9395. word li_total_channels;
  9396. /*------------------------------------------------------------------*/
  9397. /* translate a CHI information element to a channel number */
  9398. /* returns 0xff - any channel */
  9399. /* 0xfe - chi wrong coding */
  9400. /* 0xfd - D-channel */
  9401. /* 0x00 - no channel */
  9402. /* else channel number / PRI: timeslot */
  9403. /* if channels is provided we accept more than one channel. */
  9404. /*------------------------------------------------------------------*/
  9405. static byte chi_to_channel (byte *chi, dword *pchannelmap)
  9406. {
  9407. int p;
  9408. int i;
  9409. dword map;
  9410. byte excl;
  9411. byte ofs;
  9412. byte ch;
  9413. if (pchannelmap) *pchannelmap = 0;
  9414. if(!chi[0]) return 0xff;
  9415. excl = 0;
  9416. if(chi[1] & 0x20) {
  9417. if(chi[0]==1 && chi[1]==0xac) return 0xfd; /* exclusive d-channel */
  9418. for(i=1; i<chi[0] && !(chi[i] &0x80); i++);
  9419. if(i==chi[0] || !(chi[i] &0x80)) return 0xfe;
  9420. if((chi[1] |0xc8)!=0xe9) return 0xfe;
  9421. if(chi[1] &0x08) excl = 0x40;
  9422. /* int. id present */
  9423. if(chi[1] &0x40) {
  9424. p=i+1;
  9425. for(i=p; i<chi[0] && !(chi[i] &0x80); i++);
  9426. if(i==chi[0] || !(chi[i] &0x80)) return 0xfe;
  9427. }
  9428. /* coding standard, Number/Map, Channel Type */
  9429. p=i+1;
  9430. for(i=p; i<chi[0] && !(chi[i] &0x80); i++);
  9431. if(i==chi[0] || !(chi[i] &0x80)) return 0xfe;
  9432. if((chi[p]|0xd0)!=0xd3) return 0xfe;
  9433. /* Number/Map */
  9434. if(chi[p] &0x10) {
  9435. /* map */
  9436. if((chi[0]-p)==4) ofs = 0;
  9437. else if((chi[0]-p)==3) ofs = 1;
  9438. else return 0xfe;
  9439. ch = 0;
  9440. map = 0;
  9441. for(i=0; i<4 && p<chi[0]; i++) {
  9442. p++;
  9443. ch += 8;
  9444. map <<= 8;
  9445. if(chi[p]) {
  9446. for (ch=0; !(chi[p] & (1 << ch)); ch++);
  9447. map |= chi[p];
  9448. }
  9449. }
  9450. ch += ofs;
  9451. map <<= ofs;
  9452. }
  9453. else {
  9454. /* number */
  9455. p=i+1;
  9456. ch = chi[p] &0x3f;
  9457. if(pchannelmap) {
  9458. if((byte)(chi[0]-p)>30) return 0xfe;
  9459. map = 0;
  9460. for(i=p; i<=chi[0]; i++) {
  9461. if ((chi[i] &0x7f) > 31) return 0xfe;
  9462. map |= (1L << (chi[i] &0x7f));
  9463. }
  9464. }
  9465. else {
  9466. if(p!=chi[0]) return 0xfe;
  9467. if (ch > 31) return 0xfe;
  9468. map = (1L << ch);
  9469. }
  9470. if(chi[p] &0x40) return 0xfe;
  9471. }
  9472. if (pchannelmap) *pchannelmap = map;
  9473. else if (map != ((dword)(1L << ch))) return 0xfe;
  9474. return (byte)(excl | ch);
  9475. }
  9476. else { /* not PRI */
  9477. for(i=1; i<chi[0] && !(chi[i] &0x80); i++);
  9478. if(i!=chi[0] || !(chi[i] &0x80)) return 0xfe;
  9479. if(chi[1] &0x08) excl = 0x40;
  9480. switch(chi[1] |0x98) {
  9481. case 0x98: return 0;
  9482. case 0x99:
  9483. if (pchannelmap) *pchannelmap = 2;
  9484. return excl |1;
  9485. case 0x9a:
  9486. if (pchannelmap) *pchannelmap = 4;
  9487. return excl |2;
  9488. case 0x9b: return 0xff;
  9489. case 0x9c: return 0xfd; /* d-ch */
  9490. default: return 0xfe;
  9491. }
  9492. }
  9493. }
  9494. static void mixer_set_bchannel_id_esc (PLCI *plci, byte bchannel_id)
  9495. {
  9496. DIVA_CAPI_ADAPTER *a;
  9497. PLCI *splci;
  9498. byte old_id;
  9499. a = plci->adapter;
  9500. old_id = plci->li_bchannel_id;
  9501. if (a->li_pri)
  9502. {
  9503. if ((old_id != 0) && (li_config_table[a->li_base + (old_id - 1)].plci == plci))
  9504. li_config_table[a->li_base + (old_id - 1)].plci = NULL;
  9505. plci->li_bchannel_id = (bchannel_id & 0x1f) + 1;
  9506. if (li_config_table[a->li_base + (plci->li_bchannel_id - 1)].plci == NULL)
  9507. li_config_table[a->li_base + (plci->li_bchannel_id - 1)].plci = plci;
  9508. }
  9509. else
  9510. {
  9511. if (((bchannel_id & 0x03) == 1) || ((bchannel_id & 0x03) == 2))
  9512. {
  9513. if ((old_id != 0) && (li_config_table[a->li_base + (old_id - 1)].plci == plci))
  9514. li_config_table[a->li_base + (old_id - 1)].plci = NULL;
  9515. plci->li_bchannel_id = bchannel_id & 0x03;
  9516. if ((a->AdvSignalPLCI != NULL) && (a->AdvSignalPLCI != plci) && (a->AdvSignalPLCI->tel == ADV_VOICE))
  9517. {
  9518. splci = a->AdvSignalPLCI;
  9519. if (li_config_table[a->li_base + (2 - plci->li_bchannel_id)].plci == NULL)
  9520. {
  9521. if ((splci->li_bchannel_id != 0)
  9522. && (li_config_table[a->li_base + (splci->li_bchannel_id - 1)].plci == splci))
  9523. {
  9524. li_config_table[a->li_base + (splci->li_bchannel_id - 1)].plci = NULL;
  9525. }
  9526. splci->li_bchannel_id = 3 - plci->li_bchannel_id;
  9527. li_config_table[a->li_base + (2 - plci->li_bchannel_id)].plci = splci;
  9528. dbug (1, dprintf ("[%06lx] %s,%d: adv_voice_set_bchannel_id_esc %d",
  9529. (dword)((splci->Id << 8) | UnMapController (splci->adapter->Id)),
  9530. (char *)(FILE_), __LINE__, splci->li_bchannel_id));
  9531. }
  9532. }
  9533. if (li_config_table[a->li_base + (plci->li_bchannel_id - 1)].plci == NULL)
  9534. li_config_table[a->li_base + (plci->li_bchannel_id - 1)].plci = plci;
  9535. }
  9536. }
  9537. if ((old_id == 0) && (plci->li_bchannel_id != 0)
  9538. && (li_config_table[a->li_base + (plci->li_bchannel_id - 1)].plci == plci))
  9539. {
  9540. mixer_clear_config (plci);
  9541. }
  9542. dbug (1, dprintf ("[%06lx] %s,%d: mixer_set_bchannel_id_esc %d %d",
  9543. (dword)((plci->Id << 8) | UnMapController (plci->adapter->Id)),
  9544. (char *)(FILE_), __LINE__, bchannel_id, plci->li_bchannel_id));
  9545. }
  9546. static void mixer_set_bchannel_id (PLCI *plci, byte *chi)
  9547. {
  9548. DIVA_CAPI_ADAPTER *a;
  9549. PLCI *splci;
  9550. byte ch, old_id;
  9551. a = plci->adapter;
  9552. old_id = plci->li_bchannel_id;
  9553. ch = chi_to_channel (chi, NULL);
  9554. if (!(ch & 0x80))
  9555. {
  9556. if (a->li_pri)
  9557. {
  9558. if ((old_id != 0) && (li_config_table[a->li_base + (old_id - 1)].plci == plci))
  9559. li_config_table[a->li_base + (old_id - 1)].plci = NULL;
  9560. plci->li_bchannel_id = (ch & 0x1f) + 1;
  9561. if (li_config_table[a->li_base + (plci->li_bchannel_id - 1)].plci == NULL)
  9562. li_config_table[a->li_base + (plci->li_bchannel_id - 1)].plci = plci;
  9563. }
  9564. else
  9565. {
  9566. if (((ch & 0x1f) == 1) || ((ch & 0x1f) == 2))
  9567. {
  9568. if ((old_id != 0) && (li_config_table[a->li_base + (old_id - 1)].plci == plci))
  9569. li_config_table[a->li_base + (old_id - 1)].plci = NULL;
  9570. plci->li_bchannel_id = ch & 0x1f;
  9571. if ((a->AdvSignalPLCI != NULL) && (a->AdvSignalPLCI != plci) && (a->AdvSignalPLCI->tel == ADV_VOICE))
  9572. {
  9573. splci = a->AdvSignalPLCI;
  9574. if (li_config_table[a->li_base + (2 - plci->li_bchannel_id)].plci == NULL)
  9575. {
  9576. if ((splci->li_bchannel_id != 0)
  9577. && (li_config_table[a->li_base + (splci->li_bchannel_id - 1)].plci == splci))
  9578. {
  9579. li_config_table[a->li_base + (splci->li_bchannel_id - 1)].plci = NULL;
  9580. }
  9581. splci->li_bchannel_id = 3 - plci->li_bchannel_id;
  9582. li_config_table[a->li_base + (2 - plci->li_bchannel_id)].plci = splci;
  9583. dbug (1, dprintf ("[%06lx] %s,%d: adv_voice_set_bchannel_id %d",
  9584. (dword)((splci->Id << 8) | UnMapController (splci->adapter->Id)),
  9585. (char *)(FILE_), __LINE__, splci->li_bchannel_id));
  9586. }
  9587. }
  9588. if (li_config_table[a->li_base + (plci->li_bchannel_id - 1)].plci == NULL)
  9589. li_config_table[a->li_base + (plci->li_bchannel_id - 1)].plci = plci;
  9590. }
  9591. }
  9592. }
  9593. if ((old_id == 0) && (plci->li_bchannel_id != 0)
  9594. && (li_config_table[a->li_base + (plci->li_bchannel_id - 1)].plci == plci))
  9595. {
  9596. mixer_clear_config (plci);
  9597. }
  9598. dbug (1, dprintf ("[%06lx] %s,%d: mixer_set_bchannel_id %02x %d",
  9599. (dword)((plci->Id << 8) | UnMapController (plci->adapter->Id)),
  9600. (char *)(FILE_), __LINE__, ch, plci->li_bchannel_id));
  9601. }
  9602. #define MIXER_MAX_DUMP_CHANNELS 34
  9603. static void mixer_calculate_coefs (DIVA_CAPI_ADAPTER *a)
  9604. {
  9605. static char hex_digit_table[0x10] = {'0','1','2','3','4','5','6','7','8','9','a','b','c','d','e','f'};
  9606. word n, i, j;
  9607. char *p;
  9608. char hex_line[2 * MIXER_MAX_DUMP_CHANNELS + MIXER_MAX_DUMP_CHANNELS / 8 + 4];
  9609. dbug (1, dprintf ("[%06lx] %s,%d: mixer_calculate_coefs",
  9610. (dword)(UnMapController (a->Id)), (char *)(FILE_), __LINE__));
  9611. for (i = 0; i < li_total_channels; i++)
  9612. {
  9613. li_config_table[i].channel &= LI_CHANNEL_ADDRESSES_SET;
  9614. if (li_config_table[i].chflags != 0)
  9615. li_config_table[i].channel |= LI_CHANNEL_INVOLVED;
  9616. else
  9617. {
  9618. for (j = 0; j < li_total_channels; j++)
  9619. {
  9620. if (((li_config_table[i].flag_table[j]) != 0)
  9621. || ((li_config_table[j].flag_table[i]) != 0))
  9622. {
  9623. li_config_table[i].channel |= LI_CHANNEL_INVOLVED;
  9624. }
  9625. if (((li_config_table[i].flag_table[j] & LI_FLAG_CONFERENCE) != 0)
  9626. || ((li_config_table[j].flag_table[i] & LI_FLAG_CONFERENCE) != 0))
  9627. {
  9628. li_config_table[i].channel |= LI_CHANNEL_CONFERENCE;
  9629. }
  9630. }
  9631. }
  9632. }
  9633. for (i = 0; i < li_total_channels; i++)
  9634. {
  9635. for (j = 0; j < li_total_channels; j++)
  9636. {
  9637. li_config_table[i].coef_table[j] &= ~(LI_COEF_CH_CH | LI_COEF_CH_PC | LI_COEF_PC_CH | LI_COEF_PC_PC);
  9638. if (li_config_table[i].flag_table[j] & LI_FLAG_CONFERENCE)
  9639. li_config_table[i].coef_table[j] |= LI_COEF_CH_CH;
  9640. }
  9641. }
  9642. for (n = 0; n < li_total_channels; n++)
  9643. {
  9644. if (li_config_table[n].channel & LI_CHANNEL_CONFERENCE)
  9645. {
  9646. for (i = 0; i < li_total_channels; i++)
  9647. {
  9648. if (li_config_table[i].channel & LI_CHANNEL_CONFERENCE)
  9649. {
  9650. for (j = 0; j < li_total_channels; j++)
  9651. {
  9652. li_config_table[i].coef_table[j] |=
  9653. li_config_table[i].coef_table[n] & li_config_table[n].coef_table[j];
  9654. }
  9655. }
  9656. }
  9657. }
  9658. }
  9659. for (i = 0; i < li_total_channels; i++)
  9660. {
  9661. if (li_config_table[i].channel & LI_CHANNEL_INVOLVED)
  9662. {
  9663. li_config_table[i].coef_table[i] &= ~LI_COEF_CH_CH;
  9664. for (j = 0; j < li_total_channels; j++)
  9665. {
  9666. if (li_config_table[i].coef_table[j] & LI_COEF_CH_CH)
  9667. li_config_table[i].flag_table[j] |= LI_FLAG_CONFERENCE;
  9668. }
  9669. if (li_config_table[i].flag_table[i] & LI_FLAG_CONFERENCE)
  9670. li_config_table[i].coef_table[i] |= LI_COEF_CH_CH;
  9671. }
  9672. }
  9673. for (i = 0; i < li_total_channels; i++)
  9674. {
  9675. if (li_config_table[i].channel & LI_CHANNEL_INVOLVED)
  9676. {
  9677. for (j = 0; j < li_total_channels; j++)
  9678. {
  9679. if (li_config_table[i].flag_table[j] & LI_FLAG_INTERCONNECT)
  9680. li_config_table[i].coef_table[j] |= LI_COEF_CH_CH;
  9681. if (li_config_table[i].flag_table[j] & LI_FLAG_MONITOR)
  9682. li_config_table[i].coef_table[j] |= LI_COEF_CH_PC;
  9683. if (li_config_table[i].flag_table[j] & LI_FLAG_MIX)
  9684. li_config_table[i].coef_table[j] |= LI_COEF_PC_CH;
  9685. if (li_config_table[i].flag_table[j] & LI_FLAG_PCCONNECT)
  9686. li_config_table[i].coef_table[j] |= LI_COEF_PC_PC;
  9687. }
  9688. if (li_config_table[i].chflags & LI_CHFLAG_MONITOR)
  9689. {
  9690. for (j = 0; j < li_total_channels; j++)
  9691. {
  9692. if (li_config_table[i].flag_table[j] & LI_FLAG_INTERCONNECT)
  9693. {
  9694. li_config_table[i].coef_table[j] |= LI_COEF_CH_PC;
  9695. if (li_config_table[j].chflags & LI_CHFLAG_MIX)
  9696. li_config_table[i].coef_table[j] |= LI_COEF_PC_CH | LI_COEF_PC_PC;
  9697. }
  9698. }
  9699. }
  9700. if (li_config_table[i].chflags & LI_CHFLAG_MIX)
  9701. {
  9702. for (j = 0; j < li_total_channels; j++)
  9703. {
  9704. if (li_config_table[j].flag_table[i] & LI_FLAG_INTERCONNECT)
  9705. li_config_table[j].coef_table[i] |= LI_COEF_PC_CH;
  9706. }
  9707. }
  9708. if (li_config_table[i].chflags & LI_CHFLAG_LOOP)
  9709. {
  9710. for (j = 0; j < li_total_channels; j++)
  9711. {
  9712. if (li_config_table[i].flag_table[j] & LI_FLAG_INTERCONNECT)
  9713. {
  9714. for (n = 0; n < li_total_channels; n++)
  9715. {
  9716. if (li_config_table[n].flag_table[i] & LI_FLAG_INTERCONNECT)
  9717. {
  9718. li_config_table[n].coef_table[j] |= LI_COEF_CH_CH;
  9719. if (li_config_table[j].chflags & LI_CHFLAG_MIX)
  9720. {
  9721. li_config_table[n].coef_table[j] |= LI_COEF_PC_CH;
  9722. if (li_config_table[n].chflags & LI_CHFLAG_MONITOR)
  9723. li_config_table[n].coef_table[j] |= LI_COEF_CH_PC | LI_COEF_PC_PC;
  9724. }
  9725. else if (li_config_table[n].chflags & LI_CHFLAG_MONITOR)
  9726. li_config_table[n].coef_table[j] |= LI_COEF_CH_PC;
  9727. }
  9728. }
  9729. }
  9730. }
  9731. }
  9732. }
  9733. }
  9734. for (i = 0; i < li_total_channels; i++)
  9735. {
  9736. if (li_config_table[i].channel & LI_CHANNEL_INVOLVED)
  9737. {
  9738. if (li_config_table[i].chflags & (LI_CHFLAG_MONITOR | LI_CHFLAG_MIX | LI_CHFLAG_LOOP))
  9739. li_config_table[i].channel |= LI_CHANNEL_ACTIVE;
  9740. if (li_config_table[i].chflags & LI_CHFLAG_MONITOR)
  9741. li_config_table[i].channel |= LI_CHANNEL_RX_DATA;
  9742. if (li_config_table[i].chflags & LI_CHFLAG_MIX)
  9743. li_config_table[i].channel |= LI_CHANNEL_TX_DATA;
  9744. for (j = 0; j < li_total_channels; j++)
  9745. {
  9746. if ((li_config_table[i].flag_table[j] &
  9747. (LI_FLAG_INTERCONNECT | LI_FLAG_PCCONNECT | LI_FLAG_CONFERENCE | LI_FLAG_MONITOR))
  9748. || (li_config_table[j].flag_table[i] &
  9749. (LI_FLAG_INTERCONNECT | LI_FLAG_PCCONNECT | LI_FLAG_CONFERENCE | LI_FLAG_ANNOUNCEMENT | LI_FLAG_MIX)))
  9750. {
  9751. li_config_table[i].channel |= LI_CHANNEL_ACTIVE;
  9752. }
  9753. if (li_config_table[i].flag_table[j] & (LI_FLAG_PCCONNECT | LI_FLAG_MONITOR))
  9754. li_config_table[i].channel |= LI_CHANNEL_RX_DATA;
  9755. if (li_config_table[j].flag_table[i] & (LI_FLAG_PCCONNECT | LI_FLAG_ANNOUNCEMENT | LI_FLAG_MIX))
  9756. li_config_table[i].channel |= LI_CHANNEL_TX_DATA;
  9757. }
  9758. if (!(li_config_table[i].channel & LI_CHANNEL_ACTIVE))
  9759. {
  9760. li_config_table[i].coef_table[i] |= LI_COEF_PC_CH | LI_COEF_CH_PC;
  9761. li_config_table[i].channel |= LI_CHANNEL_TX_DATA | LI_CHANNEL_RX_DATA;
  9762. }
  9763. }
  9764. }
  9765. for (i = 0; i < li_total_channels; i++)
  9766. {
  9767. if (li_config_table[i].channel & LI_CHANNEL_INVOLVED)
  9768. {
  9769. j = 0;
  9770. while ((j < li_total_channels) && !(li_config_table[i].flag_table[j] & LI_FLAG_ANNOUNCEMENT))
  9771. j++;
  9772. if (j < li_total_channels)
  9773. {
  9774. for (j = 0; j < li_total_channels; j++)
  9775. {
  9776. li_config_table[i].coef_table[j] &= ~(LI_COEF_CH_CH | LI_COEF_PC_CH);
  9777. if (li_config_table[i].flag_table[j] & LI_FLAG_ANNOUNCEMENT)
  9778. li_config_table[i].coef_table[j] |= LI_COEF_PC_CH;
  9779. }
  9780. }
  9781. }
  9782. }
  9783. n = li_total_channels;
  9784. if (n > MIXER_MAX_DUMP_CHANNELS)
  9785. n = MIXER_MAX_DUMP_CHANNELS;
  9786. p = hex_line;
  9787. for (j = 0; j < n; j++)
  9788. {
  9789. if ((j & 0x7) == 0)
  9790. *(p++) = ' ';
  9791. *(p++) = hex_digit_table[li_config_table[j].curchnl >> 4];
  9792. *(p++) = hex_digit_table[li_config_table[j].curchnl & 0xf];
  9793. }
  9794. *p = '\0';
  9795. dbug (1, dprintf ("[%06lx] CURRENT %s",
  9796. (dword)(UnMapController (a->Id)), (char *) hex_line));
  9797. p = hex_line;
  9798. for (j = 0; j < n; j++)
  9799. {
  9800. if ((j & 0x7) == 0)
  9801. *(p++) = ' ';
  9802. *(p++) = hex_digit_table[li_config_table[j].channel >> 4];
  9803. *(p++) = hex_digit_table[li_config_table[j].channel & 0xf];
  9804. }
  9805. *p = '\0';
  9806. dbug (1, dprintf ("[%06lx] CHANNEL %s",
  9807. (dword)(UnMapController (a->Id)), (char *) hex_line));
  9808. p = hex_line;
  9809. for (j = 0; j < n; j++)
  9810. {
  9811. if ((j & 0x7) == 0)
  9812. *(p++) = ' ';
  9813. *(p++) = hex_digit_table[li_config_table[j].chflags >> 4];
  9814. *(p++) = hex_digit_table[li_config_table[j].chflags & 0xf];
  9815. }
  9816. *p = '\0';
  9817. dbug (1, dprintf ("[%06lx] CHFLAG %s",
  9818. (dword)(UnMapController (a->Id)), (char *) hex_line));
  9819. for (i = 0; i < n; i++)
  9820. {
  9821. p = hex_line;
  9822. for (j = 0; j < n; j++)
  9823. {
  9824. if ((j & 0x7) == 0)
  9825. *(p++) = ' ';
  9826. *(p++) = hex_digit_table[li_config_table[i].flag_table[j] >> 4];
  9827. *(p++) = hex_digit_table[li_config_table[i].flag_table[j] & 0xf];
  9828. }
  9829. *p = '\0';
  9830. dbug (1, dprintf ("[%06lx] FLAG[%02x]%s",
  9831. (dword)(UnMapController (a->Id)), i, (char *) hex_line));
  9832. }
  9833. for (i = 0; i < n; i++)
  9834. {
  9835. p = hex_line;
  9836. for (j = 0; j < n; j++)
  9837. {
  9838. if ((j & 0x7) == 0)
  9839. *(p++) = ' ';
  9840. *(p++) = hex_digit_table[li_config_table[i].coef_table[j] >> 4];
  9841. *(p++) = hex_digit_table[li_config_table[i].coef_table[j] & 0xf];
  9842. }
  9843. *p = '\0';
  9844. dbug (1, dprintf ("[%06lx] COEF[%02x]%s",
  9845. (dword)(UnMapController (a->Id)), i, (char *) hex_line));
  9846. }
  9847. }
  9848. static struct
  9849. {
  9850. byte mask;
  9851. byte line_flags;
  9852. } mixer_write_prog_pri[] =
  9853. {
  9854. { LI_COEF_CH_CH, 0 },
  9855. { LI_COEF_CH_PC, MIXER_COEF_LINE_TO_PC_FLAG },
  9856. { LI_COEF_PC_CH, MIXER_COEF_LINE_FROM_PC_FLAG },
  9857. { LI_COEF_PC_PC, MIXER_COEF_LINE_TO_PC_FLAG | MIXER_COEF_LINE_FROM_PC_FLAG }
  9858. };
  9859. static struct
  9860. {
  9861. byte from_ch;
  9862. byte to_ch;
  9863. byte mask;
  9864. byte xconnect_override;
  9865. } mixer_write_prog_bri[] =
  9866. {
  9867. { 0, 0, LI_COEF_CH_CH, 0x01 }, /* B to B */
  9868. { 1, 0, LI_COEF_CH_CH, 0x01 }, /* Alt B to B */
  9869. { 0, 0, LI_COEF_PC_CH, 0x80 }, /* PC to B */
  9870. { 1, 0, LI_COEF_PC_CH, 0x01 }, /* Alt PC to B */
  9871. { 2, 0, LI_COEF_CH_CH, 0x00 }, /* IC to B */
  9872. { 3, 0, LI_COEF_CH_CH, 0x00 }, /* Alt IC to B */
  9873. { 0, 0, LI_COEF_CH_PC, 0x80 }, /* B to PC */
  9874. { 1, 0, LI_COEF_CH_PC, 0x01 }, /* Alt B to PC */
  9875. { 0, 0, LI_COEF_PC_PC, 0x01 }, /* PC to PC */
  9876. { 1, 0, LI_COEF_PC_PC, 0x01 }, /* Alt PC to PC */
  9877. { 2, 0, LI_COEF_CH_PC, 0x00 }, /* IC to PC */
  9878. { 3, 0, LI_COEF_CH_PC, 0x00 }, /* Alt IC to PC */
  9879. { 0, 2, LI_COEF_CH_CH, 0x00 }, /* B to IC */
  9880. { 1, 2, LI_COEF_CH_CH, 0x00 }, /* Alt B to IC */
  9881. { 0, 2, LI_COEF_PC_CH, 0x00 }, /* PC to IC */
  9882. { 1, 2, LI_COEF_PC_CH, 0x00 }, /* Alt PC to IC */
  9883. { 2, 2, LI_COEF_CH_CH, 0x00 }, /* IC to IC */
  9884. { 3, 2, LI_COEF_CH_CH, 0x00 }, /* Alt IC to IC */
  9885. { 1, 1, LI_COEF_CH_CH, 0x01 }, /* Alt B to Alt B */
  9886. { 0, 1, LI_COEF_CH_CH, 0x01 }, /* B to Alt B */
  9887. { 1, 1, LI_COEF_PC_CH, 0x80 }, /* Alt PC to Alt B */
  9888. { 0, 1, LI_COEF_PC_CH, 0x01 }, /* PC to Alt B */
  9889. { 3, 1, LI_COEF_CH_CH, 0x00 }, /* Alt IC to Alt B */
  9890. { 2, 1, LI_COEF_CH_CH, 0x00 }, /* IC to Alt B */
  9891. { 1, 1, LI_COEF_CH_PC, 0x80 }, /* Alt B to Alt PC */
  9892. { 0, 1, LI_COEF_CH_PC, 0x01 }, /* B to Alt PC */
  9893. { 1, 1, LI_COEF_PC_PC, 0x01 }, /* Alt PC to Alt PC */
  9894. { 0, 1, LI_COEF_PC_PC, 0x01 }, /* PC to Alt PC */
  9895. { 3, 1, LI_COEF_CH_PC, 0x00 }, /* Alt IC to Alt PC */
  9896. { 2, 1, LI_COEF_CH_PC, 0x00 }, /* IC to Alt PC */
  9897. { 1, 3, LI_COEF_CH_CH, 0x00 }, /* Alt B to Alt IC */
  9898. { 0, 3, LI_COEF_CH_CH, 0x00 }, /* B to Alt IC */
  9899. { 1, 3, LI_COEF_PC_CH, 0x00 }, /* Alt PC to Alt IC */
  9900. { 0, 3, LI_COEF_PC_CH, 0x00 }, /* PC to Alt IC */
  9901. { 3, 3, LI_COEF_CH_CH, 0x00 }, /* Alt IC to Alt IC */
  9902. { 2, 3, LI_COEF_CH_CH, 0x00 } /* IC to Alt IC */
  9903. };
  9904. static byte mixer_swapped_index_bri[] =
  9905. {
  9906. 18, /* B to B */
  9907. 19, /* Alt B to B */
  9908. 20, /* PC to B */
  9909. 21, /* Alt PC to B */
  9910. 22, /* IC to B */
  9911. 23, /* Alt IC to B */
  9912. 24, /* B to PC */
  9913. 25, /* Alt B to PC */
  9914. 26, /* PC to PC */
  9915. 27, /* Alt PC to PC */
  9916. 28, /* IC to PC */
  9917. 29, /* Alt IC to PC */
  9918. 30, /* B to IC */
  9919. 31, /* Alt B to IC */
  9920. 32, /* PC to IC */
  9921. 33, /* Alt PC to IC */
  9922. 34, /* IC to IC */
  9923. 35, /* Alt IC to IC */
  9924. 0, /* Alt B to Alt B */
  9925. 1, /* B to Alt B */
  9926. 2, /* Alt PC to Alt B */
  9927. 3, /* PC to Alt B */
  9928. 4, /* Alt IC to Alt B */
  9929. 5, /* IC to Alt B */
  9930. 6, /* Alt B to Alt PC */
  9931. 7, /* B to Alt PC */
  9932. 8, /* Alt PC to Alt PC */
  9933. 9, /* PC to Alt PC */
  9934. 10, /* Alt IC to Alt PC */
  9935. 11, /* IC to Alt PC */
  9936. 12, /* Alt B to Alt IC */
  9937. 13, /* B to Alt IC */
  9938. 14, /* Alt PC to Alt IC */
  9939. 15, /* PC to Alt IC */
  9940. 16, /* Alt IC to Alt IC */
  9941. 17 /* IC to Alt IC */
  9942. };
  9943. static struct
  9944. {
  9945. byte mask;
  9946. byte from_pc;
  9947. byte to_pc;
  9948. } xconnect_write_prog[] =
  9949. {
  9950. { LI_COEF_CH_CH, false, false },
  9951. { LI_COEF_CH_PC, false, true },
  9952. { LI_COEF_PC_CH, true, false },
  9953. { LI_COEF_PC_PC, true, true }
  9954. };
  9955. static void xconnect_query_addresses (PLCI *plci)
  9956. {
  9957. DIVA_CAPI_ADAPTER *a;
  9958. word w, ch;
  9959. byte *p;
  9960. dbug (1, dprintf ("[%06lx] %s,%d: xconnect_query_addresses",
  9961. (dword)((plci->Id << 8) | UnMapController (plci->adapter->Id)),
  9962. (char *)(FILE_), __LINE__));
  9963. a = plci->adapter;
  9964. if (a->li_pri && ((plci->li_bchannel_id == 0)
  9965. || (li_config_table[a->li_base + (plci->li_bchannel_id - 1)].plci != plci)))
  9966. {
  9967. dbug (1, dprintf ("[%06x] %s,%d: Channel id wiped out",
  9968. (dword)((plci->Id << 8) | UnMapController (plci->adapter->Id)),
  9969. (char *)(FILE_), __LINE__));
  9970. return;
  9971. }
  9972. p = plci->internal_req_buffer;
  9973. ch = (a->li_pri) ? plci->li_bchannel_id - 1 : 0;
  9974. *(p++) = UDATA_REQUEST_XCONNECT_FROM;
  9975. w = ch;
  9976. *(p++) = (byte) w;
  9977. *(p++) = (byte)(w >> 8);
  9978. w = ch | XCONNECT_CHANNEL_PORT_PC;
  9979. *(p++) = (byte) w;
  9980. *(p++) = (byte)(w >> 8);
  9981. plci->NData[0].P = plci->internal_req_buffer;
  9982. plci->NData[0].PLength = p - plci->internal_req_buffer;
  9983. plci->NL.X = plci->NData;
  9984. plci->NL.ReqCh = 0;
  9985. plci->NL.Req = plci->nl_req = (byte) N_UDATA;
  9986. plci->adapter->request (&plci->NL);
  9987. }
  9988. static void xconnect_write_coefs (PLCI *plci, word internal_command)
  9989. {
  9990. dbug (1, dprintf ("[%06lx] %s,%d: xconnect_write_coefs %04x",
  9991. (dword)((plci->Id << 8) | UnMapController (plci->adapter->Id)),
  9992. (char *)(FILE_), __LINE__, internal_command));
  9993. plci->li_write_command = internal_command;
  9994. plci->li_write_channel = 0;
  9995. }
  9996. static byte xconnect_write_coefs_process (dword Id, PLCI *plci, byte Rc)
  9997. {
  9998. DIVA_CAPI_ADAPTER *a;
  9999. word w, n, i, j, r, s, to_ch;
  10000. dword d;
  10001. byte *p;
  10002. struct xconnect_transfer_address_s *transfer_address;
  10003. byte ch_map[MIXER_CHANNELS_BRI];
  10004. dbug (1, dprintf ("[%06x] %s,%d: xconnect_write_coefs_process %02x %d",
  10005. UnMapId (Id), (char *)(FILE_), __LINE__, Rc, plci->li_write_channel));
  10006. a = plci->adapter;
  10007. if ((plci->li_bchannel_id == 0)
  10008. || (li_config_table[a->li_base + (plci->li_bchannel_id - 1)].plci != plci))
  10009. {
  10010. dbug (1, dprintf ("[%06x] %s,%d: Channel id wiped out",
  10011. UnMapId (Id), (char *)(FILE_), __LINE__));
  10012. return (true);
  10013. }
  10014. i = a->li_base + (plci->li_bchannel_id - 1);
  10015. j = plci->li_write_channel;
  10016. p = plci->internal_req_buffer;
  10017. if (j != 0)
  10018. {
  10019. if ((Rc != OK) && (Rc != OK_FC))
  10020. {
  10021. dbug (1, dprintf ("[%06lx] %s,%d: LI write coefs failed %02x",
  10022. UnMapId (Id), (char *)(FILE_), __LINE__, Rc));
  10023. return (false);
  10024. }
  10025. }
  10026. if (li_config_table[i].adapter->manufacturer_features & MANUFACTURER_FEATURE_XCONNECT)
  10027. {
  10028. r = 0;
  10029. s = 0;
  10030. if (j < li_total_channels)
  10031. {
  10032. if (li_config_table[i].channel & LI_CHANNEL_ADDRESSES_SET)
  10033. {
  10034. s = ((li_config_table[i].send_b.card_address.low | li_config_table[i].send_b.card_address.high) ?
  10035. (LI_COEF_CH_CH | LI_COEF_CH_PC | LI_COEF_PC_CH | LI_COEF_PC_PC) : (LI_COEF_CH_PC | LI_COEF_PC_PC)) &
  10036. ((li_config_table[i].send_pc.card_address.low | li_config_table[i].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_PC_CH));
  10038. }
  10039. r = ((li_config_table[i].coef_table[j] & 0xf) ^ (li_config_table[i].coef_table[j] >> 4));
  10040. while ((j < li_total_channels)
  10041. && ((r == 0)
  10042. || (!(li_config_table[j].channel & LI_CHANNEL_ADDRESSES_SET))
  10043. || (!li_config_table[j].adapter->li_pri
  10044. && (j >= li_config_table[j].adapter->li_base + MIXER_BCHANNELS_BRI))
  10045. || (((li_config_table[j].send_b.card_address.low != li_config_table[i].send_b.card_address.low)
  10046. || (li_config_table[j].send_b.card_address.high != li_config_table[i].send_b.card_address.high))
  10047. && (!(a->manufacturer_features & MANUFACTURER_FEATURE_DMACONNECT)
  10048. || !(li_config_table[j].adapter->manufacturer_features & MANUFACTURER_FEATURE_DMACONNECT)))
  10049. || ((li_config_table[j].adapter->li_base != a->li_base)
  10050. && !(r & s &
  10051. ((li_config_table[j].send_b.card_address.low | li_config_table[j].send_b.card_address.high) ?
  10052. (LI_COEF_CH_CH | LI_COEF_CH_PC | LI_COEF_PC_CH | LI_COEF_PC_PC) : (LI_COEF_PC_CH | LI_COEF_PC_PC)) &
  10053. ((li_config_table[j].send_pc.card_address.low | li_config_table[j].send_pc.card_address.high) ?
  10054. (LI_COEF_CH_CH | LI_COEF_CH_PC | LI_COEF_PC_CH | LI_COEF_PC_PC) : (LI_COEF_CH_CH | LI_COEF_CH_PC))))))
  10055. {
  10056. j++;
  10057. if (j < li_total_channels)
  10058. r = ((li_config_table[i].coef_table[j] & 0xf) ^ (li_config_table[i].coef_table[j] >> 4));
  10059. }
  10060. }
  10061. if (j < li_total_channels)
  10062. {
  10063. plci->internal_command = plci->li_write_command;
  10064. if (plci_nl_busy (plci))
  10065. return (true);
  10066. to_ch = (a->li_pri) ? plci->li_bchannel_id - 1 : 0;
  10067. *(p++) = UDATA_REQUEST_XCONNECT_TO;
  10068. do
  10069. {
  10070. if (li_config_table[j].adapter->li_base != a->li_base)
  10071. {
  10072. r &= s &
  10073. ((li_config_table[j].send_b.card_address.low | li_config_table[j].send_b.card_address.high) ?
  10074. (LI_COEF_CH_CH | LI_COEF_CH_PC | LI_COEF_PC_CH | LI_COEF_PC_PC) : (LI_COEF_PC_CH | LI_COEF_PC_PC)) &
  10075. ((li_config_table[j].send_pc.card_address.low | li_config_table[j].send_pc.card_address.high) ?
  10076. (LI_COEF_CH_CH | LI_COEF_CH_PC | LI_COEF_PC_CH | LI_COEF_PC_PC) : (LI_COEF_CH_CH | LI_COEF_CH_PC));
  10077. }
  10078. n = 0;
  10079. do
  10080. {
  10081. if (r & xconnect_write_prog[n].mask)
  10082. {
  10083. if (xconnect_write_prog[n].from_pc)
  10084. transfer_address = &(li_config_table[j].send_pc);
  10085. else
  10086. transfer_address = &(li_config_table[j].send_b);
  10087. d = transfer_address->card_address.low;
  10088. *(p++) = (byte) d;
  10089. *(p++) = (byte)(d >> 8);
  10090. *(p++) = (byte)(d >> 16);
  10091. *(p++) = (byte)(d >> 24);
  10092. d = transfer_address->card_address.high;
  10093. *(p++) = (byte) d;
  10094. *(p++) = (byte)(d >> 8);
  10095. *(p++) = (byte)(d >> 16);
  10096. *(p++) = (byte)(d >> 24);
  10097. d = transfer_address->offset;
  10098. *(p++) = (byte) d;
  10099. *(p++) = (byte)(d >> 8);
  10100. *(p++) = (byte)(d >> 16);
  10101. *(p++) = (byte)(d >> 24);
  10102. w = xconnect_write_prog[n].to_pc ? to_ch | XCONNECT_CHANNEL_PORT_PC : to_ch;
  10103. *(p++) = (byte) w;
  10104. *(p++) = (byte)(w >> 8);
  10105. w = ((li_config_table[i].coef_table[j] & xconnect_write_prog[n].mask) == 0) ? 0x01 :
  10106. (li_config_table[i].adapter->u_law ?
  10107. (li_config_table[j].adapter->u_law ? 0x80 : 0x86) :
  10108. (li_config_table[j].adapter->u_law ? 0x7a : 0x80));
  10109. *(p++) = (byte) w;
  10110. *(p++) = (byte) 0;
  10111. li_config_table[i].coef_table[j] ^= xconnect_write_prog[n].mask << 4;
  10112. }
  10113. n++;
  10114. } while ((n < ARRAY_SIZE(xconnect_write_prog))
  10115. && ((p - plci->internal_req_buffer) + 16 < INTERNAL_REQ_BUFFER_SIZE));
  10116. if (n == ARRAY_SIZE(xconnect_write_prog))
  10117. {
  10118. do
  10119. {
  10120. j++;
  10121. if (j < li_total_channels)
  10122. r = ((li_config_table[i].coef_table[j] & 0xf) ^ (li_config_table[i].coef_table[j] >> 4));
  10123. } while ((j < li_total_channels)
  10124. && ((r == 0)
  10125. || (!(li_config_table[j].channel & LI_CHANNEL_ADDRESSES_SET))
  10126. || (!li_config_table[j].adapter->li_pri
  10127. && (j >= li_config_table[j].adapter->li_base + MIXER_BCHANNELS_BRI))
  10128. || (((li_config_table[j].send_b.card_address.low != li_config_table[i].send_b.card_address.low)
  10129. || (li_config_table[j].send_b.card_address.high != li_config_table[i].send_b.card_address.high))
  10130. && (!(a->manufacturer_features & MANUFACTURER_FEATURE_DMACONNECT)
  10131. || !(li_config_table[j].adapter->manufacturer_features & MANUFACTURER_FEATURE_DMACONNECT)))
  10132. || ((li_config_table[j].adapter->li_base != a->li_base)
  10133. && !(r & s &
  10134. ((li_config_table[j].send_b.card_address.low | li_config_table[j].send_b.card_address.high) ?
  10135. (LI_COEF_CH_CH | LI_COEF_CH_PC | LI_COEF_PC_CH | LI_COEF_PC_PC) : (LI_COEF_PC_CH | LI_COEF_PC_PC)) &
  10136. ((li_config_table[j].send_pc.card_address.low | li_config_table[j].send_pc.card_address.high) ?
  10137. (LI_COEF_CH_CH | LI_COEF_CH_PC | LI_COEF_PC_CH | LI_COEF_PC_PC) : (LI_COEF_CH_CH | LI_COEF_CH_PC))))));
  10138. }
  10139. } while ((j < li_total_channels)
  10140. && ((p - plci->internal_req_buffer) + 16 < INTERNAL_REQ_BUFFER_SIZE));
  10141. }
  10142. else if (j == li_total_channels)
  10143. {
  10144. plci->internal_command = plci->li_write_command;
  10145. if (plci_nl_busy (plci))
  10146. return (true);
  10147. if (a->li_pri)
  10148. {
  10149. *(p++) = UDATA_REQUEST_SET_MIXER_COEFS_PRI_SYNC;
  10150. w = 0;
  10151. if (li_config_table[i].channel & LI_CHANNEL_TX_DATA)
  10152. w |= MIXER_FEATURE_ENABLE_TX_DATA;
  10153. if (li_config_table[i].channel & LI_CHANNEL_RX_DATA)
  10154. w |= MIXER_FEATURE_ENABLE_RX_DATA;
  10155. *(p++) = (byte) w;
  10156. *(p++) = (byte)(w >> 8);
  10157. }
  10158. else
  10159. {
  10160. *(p++) = UDATA_REQUEST_SET_MIXER_COEFS_BRI;
  10161. w = 0;
  10162. if ((plci->tel == ADV_VOICE) && (plci == a->AdvSignalPLCI)
  10163. && (ADV_VOICE_NEW_COEF_BASE + sizeof(word) <= a->adv_voice_coef_length))
  10164. {
  10165. w = GET_WORD (a->adv_voice_coef_buffer + ADV_VOICE_NEW_COEF_BASE);
  10166. }
  10167. if (li_config_table[i].channel & LI_CHANNEL_TX_DATA)
  10168. w |= MIXER_FEATURE_ENABLE_TX_DATA;
  10169. if (li_config_table[i].channel & LI_CHANNEL_RX_DATA)
  10170. w |= MIXER_FEATURE_ENABLE_RX_DATA;
  10171. *(p++) = (byte) w;
  10172. *(p++) = (byte)(w >> 8);
  10173. for (j = 0; j < sizeof(ch_map); j += 2)
  10174. {
  10175. if (plci->li_bchannel_id == 2)
  10176. {
  10177. ch_map[j] = (byte)(j+1);
  10178. ch_map[j+1] = (byte) j;
  10179. }
  10180. else
  10181. {
  10182. ch_map[j] = (byte) j;
  10183. ch_map[j+1] = (byte)(j+1);
  10184. }
  10185. }
  10186. for (n = 0; n < ARRAY_SIZE(mixer_write_prog_bri); n++)
  10187. {
  10188. i = a->li_base + ch_map[mixer_write_prog_bri[n].to_ch];
  10189. j = a->li_base + ch_map[mixer_write_prog_bri[n].from_ch];
  10190. if (li_config_table[i].channel & li_config_table[j].channel & LI_CHANNEL_INVOLVED)
  10191. {
  10192. *p = (mixer_write_prog_bri[n].xconnect_override != 0) ?
  10193. mixer_write_prog_bri[n].xconnect_override :
  10194. ((li_config_table[i].coef_table[j] & mixer_write_prog_bri[n].mask) ? 0x80 : 0x01);
  10195. if ((i >= a->li_base + MIXER_BCHANNELS_BRI) || (j >= a->li_base + MIXER_BCHANNELS_BRI))
  10196. {
  10197. w = ((li_config_table[i].coef_table[j] & 0xf) ^ (li_config_table[i].coef_table[j] >> 4));
  10198. li_config_table[i].coef_table[j] ^= (w & mixer_write_prog_bri[n].mask) << 4;
  10199. }
  10200. }
  10201. else
  10202. {
  10203. *p = 0x00;
  10204. if ((a->AdvSignalPLCI != NULL) && (a->AdvSignalPLCI->tel == ADV_VOICE))
  10205. {
  10206. w = (plci == a->AdvSignalPLCI) ? n : mixer_swapped_index_bri[n];
  10207. if (ADV_VOICE_NEW_COEF_BASE + sizeof(word) + w < a->adv_voice_coef_length)
  10208. *p = a->adv_voice_coef_buffer[ADV_VOICE_NEW_COEF_BASE + sizeof(word) + w];
  10209. }
  10210. }
  10211. p++;
  10212. }
  10213. }
  10214. j = li_total_channels + 1;
  10215. }
  10216. }
  10217. else
  10218. {
  10219. if (j <= li_total_channels)
  10220. {
  10221. plci->internal_command = plci->li_write_command;
  10222. if (plci_nl_busy (plci))
  10223. return (true);
  10224. if (j < a->li_base)
  10225. j = a->li_base;
  10226. if (a->li_pri)
  10227. {
  10228. *(p++) = UDATA_REQUEST_SET_MIXER_COEFS_PRI_SYNC;
  10229. w = 0;
  10230. if (li_config_table[i].channel & LI_CHANNEL_TX_DATA)
  10231. w |= MIXER_FEATURE_ENABLE_TX_DATA;
  10232. if (li_config_table[i].channel & LI_CHANNEL_RX_DATA)
  10233. w |= MIXER_FEATURE_ENABLE_RX_DATA;
  10234. *(p++) = (byte) w;
  10235. *(p++) = (byte)(w >> 8);
  10236. for (n = 0; n < ARRAY_SIZE(mixer_write_prog_pri); n++)
  10237. {
  10238. *(p++) = (byte)((plci->li_bchannel_id - 1) | mixer_write_prog_pri[n].line_flags);
  10239. for (j = a->li_base; j < a->li_base + MIXER_CHANNELS_PRI; j++)
  10240. {
  10241. w = ((li_config_table[i].coef_table[j] & 0xf) ^ (li_config_table[i].coef_table[j] >> 4));
  10242. if (w & mixer_write_prog_pri[n].mask)
  10243. {
  10244. *(p++) = (li_config_table[i].coef_table[j] & mixer_write_prog_pri[n].mask) ? 0x80 : 0x01;
  10245. li_config_table[i].coef_table[j] ^= mixer_write_prog_pri[n].mask << 4;
  10246. }
  10247. else
  10248. *(p++) = 0x00;
  10249. }
  10250. *(p++) = (byte)((plci->li_bchannel_id - 1) | MIXER_COEF_LINE_ROW_FLAG | mixer_write_prog_pri[n].line_flags);
  10251. for (j = a->li_base; j < a->li_base + MIXER_CHANNELS_PRI; j++)
  10252. {
  10253. w = ((li_config_table[j].coef_table[i] & 0xf) ^ (li_config_table[j].coef_table[i] >> 4));
  10254. if (w & mixer_write_prog_pri[n].mask)
  10255. {
  10256. *(p++) = (li_config_table[j].coef_table[i] & mixer_write_prog_pri[n].mask) ? 0x80 : 0x01;
  10257. li_config_table[j].coef_table[i] ^= mixer_write_prog_pri[n].mask << 4;
  10258. }
  10259. else
  10260. *(p++) = 0x00;
  10261. }
  10262. }
  10263. }
  10264. else
  10265. {
  10266. *(p++) = UDATA_REQUEST_SET_MIXER_COEFS_BRI;
  10267. w = 0;
  10268. if ((plci->tel == ADV_VOICE) && (plci == a->AdvSignalPLCI)
  10269. && (ADV_VOICE_NEW_COEF_BASE + sizeof(word) <= a->adv_voice_coef_length))
  10270. {
  10271. w = GET_WORD (a->adv_voice_coef_buffer + ADV_VOICE_NEW_COEF_BASE);
  10272. }
  10273. if (li_config_table[i].channel & LI_CHANNEL_TX_DATA)
  10274. w |= MIXER_FEATURE_ENABLE_TX_DATA;
  10275. if (li_config_table[i].channel & LI_CHANNEL_RX_DATA)
  10276. w |= MIXER_FEATURE_ENABLE_RX_DATA;
  10277. *(p++) = (byte) w;
  10278. *(p++) = (byte)(w >> 8);
  10279. for (j = 0; j < sizeof(ch_map); j += 2)
  10280. {
  10281. if (plci->li_bchannel_id == 2)
  10282. {
  10283. ch_map[j] = (byte)(j+1);
  10284. ch_map[j+1] = (byte) j;
  10285. }
  10286. else
  10287. {
  10288. ch_map[j] = (byte) j;
  10289. ch_map[j+1] = (byte)(j+1);
  10290. }
  10291. }
  10292. for (n = 0; n < ARRAY_SIZE(mixer_write_prog_bri); n++)
  10293. {
  10294. i = a->li_base + ch_map[mixer_write_prog_bri[n].to_ch];
  10295. j = a->li_base + ch_map[mixer_write_prog_bri[n].from_ch];
  10296. if (li_config_table[i].channel & li_config_table[j].channel & LI_CHANNEL_INVOLVED)
  10297. {
  10298. *p = ((li_config_table[i].coef_table[j] & mixer_write_prog_bri[n].mask) ? 0x80 : 0x01);
  10299. w = ((li_config_table[i].coef_table[j] & 0xf) ^ (li_config_table[i].coef_table[j] >> 4));
  10300. li_config_table[i].coef_table[j] ^= (w & mixer_write_prog_bri[n].mask) << 4;
  10301. }
  10302. else
  10303. {
  10304. *p = 0x00;
  10305. if ((a->AdvSignalPLCI != NULL) && (a->AdvSignalPLCI->tel == ADV_VOICE))
  10306. {
  10307. w = (plci == a->AdvSignalPLCI) ? n : mixer_swapped_index_bri[n];
  10308. if (ADV_VOICE_NEW_COEF_BASE + sizeof(word) + w < a->adv_voice_coef_length)
  10309. *p = a->adv_voice_coef_buffer[ADV_VOICE_NEW_COEF_BASE + sizeof(word) + w];
  10310. }
  10311. }
  10312. p++;
  10313. }
  10314. }
  10315. j = li_total_channels + 1;
  10316. }
  10317. }
  10318. plci->li_write_channel = j;
  10319. if (p != plci->internal_req_buffer)
  10320. {
  10321. plci->NData[0].P = plci->internal_req_buffer;
  10322. plci->NData[0].PLength = p - plci->internal_req_buffer;
  10323. plci->NL.X = plci->NData;
  10324. plci->NL.ReqCh = 0;
  10325. plci->NL.Req = plci->nl_req = (byte) N_UDATA;
  10326. plci->adapter->request (&plci->NL);
  10327. }
  10328. return (true);
  10329. }
  10330. static void mixer_notify_update (PLCI *plci, byte others)
  10331. {
  10332. DIVA_CAPI_ADAPTER *a;
  10333. word i, w;
  10334. PLCI *notify_plci;
  10335. byte msg[sizeof(CAPI_MSG_HEADER) + 6];
  10336. dbug (1, dprintf ("[%06lx] %s,%d: mixer_notify_update %d",
  10337. (dword)((plci->Id << 8) | UnMapController (plci->adapter->Id)),
  10338. (char *)(FILE_), __LINE__, others));
  10339. a = plci->adapter;
  10340. if (a->profile.Global_Options & GL_LINE_INTERCONNECT_SUPPORTED)
  10341. {
  10342. if (others)
  10343. plci->li_notify_update = true;
  10344. i = 0;
  10345. do
  10346. {
  10347. notify_plci = NULL;
  10348. if (others)
  10349. {
  10350. while ((i < li_total_channels) && (li_config_table[i].plci == NULL))
  10351. i++;
  10352. if (i < li_total_channels)
  10353. notify_plci = li_config_table[i++].plci;
  10354. }
  10355. else
  10356. {
  10357. if ((plci->li_bchannel_id != 0)
  10358. && (li_config_table[a->li_base + (plci->li_bchannel_id - 1)].plci == plci))
  10359. {
  10360. notify_plci = plci;
  10361. }
  10362. }
  10363. if ((notify_plci != NULL)
  10364. && !notify_plci->li_notify_update
  10365. && (notify_plci->appl != NULL)
  10366. && (notify_plci->State)
  10367. && notify_plci->NL.Id && !notify_plci->nl_remove_id)
  10368. {
  10369. notify_plci->li_notify_update = true;
  10370. ((CAPI_MSG *) msg)->header.length = 18;
  10371. ((CAPI_MSG *) msg)->header.appl_id = notify_plci->appl->Id;
  10372. ((CAPI_MSG *) msg)->header.command = _FACILITY_R;
  10373. ((CAPI_MSG *) msg)->header.number = 0;
  10374. ((CAPI_MSG *) msg)->header.controller = notify_plci->adapter->Id;
  10375. ((CAPI_MSG *) msg)->header.plci = notify_plci->Id;
  10376. ((CAPI_MSG *) msg)->header.ncci = 0;
  10377. ((CAPI_MSG *) msg)->info.facility_req.Selector = SELECTOR_LINE_INTERCONNECT;
  10378. ((CAPI_MSG *) msg)->info.facility_req.structs[0] = 3;
  10379. PUT_WORD (&(((CAPI_MSG *) msg)->info.facility_req.structs[1]), LI_REQ_SILENT_UPDATE);
  10380. ((CAPI_MSG *) msg)->info.facility_req.structs[3] = 0;
  10381. w = api_put (notify_plci->appl, (CAPI_MSG *) msg);
  10382. if (w != _QUEUE_FULL)
  10383. {
  10384. if (w != 0)
  10385. {
  10386. dbug (1, dprintf ("[%06lx] %s,%d: Interconnect notify failed %06x %d",
  10387. (dword)((plci->Id << 8) | UnMapController (plci->adapter->Id)),
  10388. (char *)(FILE_), __LINE__,
  10389. (dword)((notify_plci->Id << 8) | UnMapController (notify_plci->adapter->Id)), w));
  10390. }
  10391. notify_plci->li_notify_update = false;
  10392. }
  10393. }
  10394. } while (others && (notify_plci != NULL));
  10395. if (others)
  10396. plci->li_notify_update = false;
  10397. }
  10398. }
  10399. static void mixer_clear_config (PLCI *plci)
  10400. {
  10401. DIVA_CAPI_ADAPTER *a;
  10402. word i, j;
  10403. dbug (1, dprintf ("[%06lx] %s,%d: mixer_clear_config",
  10404. (dword)((plci->Id << 8) | UnMapController (plci->adapter->Id)),
  10405. (char *)(FILE_), __LINE__));
  10406. plci->li_notify_update = false;
  10407. plci->li_plci_b_write_pos = 0;
  10408. plci->li_plci_b_read_pos = 0;
  10409. plci->li_plci_b_req_pos = 0;
  10410. a = plci->adapter;
  10411. if ((plci->li_bchannel_id != 0)
  10412. && (li_config_table[a->li_base + (plci->li_bchannel_id - 1)].plci == plci))
  10413. {
  10414. i = a->li_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[j].flag_table[i] = 0;
  10421. li_config_table[i].flag_table[j] = 0;
  10422. li_config_table[i].coef_table[j] = 0;
  10423. li_config_table[j].coef_table[i] = 0;
  10424. }
  10425. if (!a->li_pri)
  10426. {
  10427. li_config_table[i].coef_table[i] |= LI_COEF_CH_PC_SET | LI_COEF_PC_CH_SET;
  10428. if ((plci->tel == ADV_VOICE) && (plci == a->AdvSignalPLCI))
  10429. {
  10430. i = a->li_base + MIXER_IC_CHANNEL_BASE + (plci->li_bchannel_id - 1);
  10431. li_config_table[i].curchnl = 0;
  10432. li_config_table[i].channel = 0;
  10433. li_config_table[i].chflags = 0;
  10434. for (j = 0; j < li_total_channels; j++)
  10435. {
  10436. li_config_table[i].flag_table[j] = 0;
  10437. li_config_table[j].flag_table[i] = 0;
  10438. li_config_table[i].coef_table[j] = 0;
  10439. li_config_table[j].coef_table[i] = 0;
  10440. }
  10441. if (a->manufacturer_features & MANUFACTURER_FEATURE_SLAVE_CODEC)
  10442. {
  10443. i = a->li_base + MIXER_IC_CHANNEL_BASE + (2 - plci->li_bchannel_id);
  10444. li_config_table[i].curchnl = 0;
  10445. li_config_table[i].channel = 0;
  10446. li_config_table[i].chflags = 0;
  10447. for (j = 0; j < li_total_channels; j++)
  10448. {
  10449. li_config_table[i].flag_table[j] = 0;
  10450. li_config_table[j].flag_table[i] = 0;
  10451. li_config_table[i].coef_table[j] = 0;
  10452. li_config_table[j].coef_table[i] = 0;
  10453. }
  10454. }
  10455. }
  10456. }
  10457. }
  10458. }
  10459. static void mixer_prepare_switch (dword Id, PLCI *plci)
  10460. {
  10461. dbug (1, dprintf ("[%06lx] %s,%d: mixer_prepare_switch",
  10462. UnMapId (Id), (char *)(FILE_), __LINE__));
  10463. do
  10464. {
  10465. mixer_indication_coefs_set (Id, plci);
  10466. } while (plci->li_plci_b_read_pos != plci->li_plci_b_req_pos);
  10467. }
  10468. static word mixer_save_config (dword Id, PLCI *plci, byte Rc)
  10469. {
  10470. DIVA_CAPI_ADAPTER *a;
  10471. word i, j;
  10472. dbug (1, dprintf ("[%06lx] %s,%d: mixer_save_config %02x %d",
  10473. UnMapId (Id), (char *)(FILE_), __LINE__, Rc, plci->adjust_b_state));
  10474. a = plci->adapter;
  10475. if ((plci->li_bchannel_id != 0)
  10476. && (li_config_table[a->li_base + (plci->li_bchannel_id - 1)].plci == plci))
  10477. {
  10478. i = a->li_base + (plci->li_bchannel_id - 1);
  10479. for (j = 0; j < li_total_channels; j++)
  10480. {
  10481. li_config_table[i].coef_table[j] &= 0xf;
  10482. li_config_table[j].coef_table[i] &= 0xf;
  10483. }
  10484. if (!a->li_pri)
  10485. li_config_table[i].coef_table[i] |= LI_COEF_CH_PC_SET | LI_COEF_PC_CH_SET;
  10486. }
  10487. return (GOOD);
  10488. }
  10489. static word mixer_restore_config (dword Id, PLCI *plci, byte Rc)
  10490. {
  10491. DIVA_CAPI_ADAPTER *a;
  10492. word Info;
  10493. dbug (1, dprintf ("[%06lx] %s,%d: mixer_restore_config %02x %d",
  10494. UnMapId (Id), (char *)(FILE_), __LINE__, Rc, plci->adjust_b_state));
  10495. Info = GOOD;
  10496. a = plci->adapter;
  10497. if ((plci->B1_facilities & B1_FACILITY_MIXER)
  10498. && (plci->li_bchannel_id != 0)
  10499. && (li_config_table[a->li_base + (plci->li_bchannel_id - 1)].plci == plci))
  10500. {
  10501. switch (plci->adjust_b_state)
  10502. {
  10503. case ADJUST_B_RESTORE_MIXER_1:
  10504. if (a->manufacturer_features & MANUFACTURER_FEATURE_XCONNECT)
  10505. {
  10506. plci->internal_command = plci->adjust_b_command;
  10507. if (plci_nl_busy (plci))
  10508. {
  10509. plci->adjust_b_state = ADJUST_B_RESTORE_MIXER_1;
  10510. break;
  10511. }
  10512. xconnect_query_addresses (plci);
  10513. plci->adjust_b_state = ADJUST_B_RESTORE_MIXER_2;
  10514. break;
  10515. }
  10516. plci->adjust_b_state = ADJUST_B_RESTORE_MIXER_5;
  10517. Rc = OK;
  10518. case ADJUST_B_RESTORE_MIXER_2:
  10519. case ADJUST_B_RESTORE_MIXER_3:
  10520. case ADJUST_B_RESTORE_MIXER_4:
  10521. if ((Rc != OK) && (Rc != OK_FC) && (Rc != 0))
  10522. {
  10523. dbug (1, dprintf ("[%06lx] %s,%d: Adjust B query addresses failed %02x",
  10524. UnMapId (Id), (char *)(FILE_), __LINE__, Rc));
  10525. Info = _WRONG_STATE;
  10526. break;
  10527. }
  10528. if (Rc == OK)
  10529. {
  10530. if (plci->adjust_b_state == ADJUST_B_RESTORE_MIXER_2)
  10531. plci->adjust_b_state = ADJUST_B_RESTORE_MIXER_3;
  10532. else if (plci->adjust_b_state == ADJUST_B_RESTORE_MIXER_4)
  10533. plci->adjust_b_state = ADJUST_B_RESTORE_MIXER_5;
  10534. }
  10535. else if (Rc == 0)
  10536. {
  10537. if (plci->adjust_b_state == ADJUST_B_RESTORE_MIXER_2)
  10538. plci->adjust_b_state = ADJUST_B_RESTORE_MIXER_4;
  10539. else if (plci->adjust_b_state == ADJUST_B_RESTORE_MIXER_3)
  10540. plci->adjust_b_state = ADJUST_B_RESTORE_MIXER_5;
  10541. }
  10542. if (plci->adjust_b_state != ADJUST_B_RESTORE_MIXER_5)
  10543. {
  10544. plci->internal_command = plci->adjust_b_command;
  10545. break;
  10546. }
  10547. case ADJUST_B_RESTORE_MIXER_5:
  10548. xconnect_write_coefs (plci, plci->adjust_b_command);
  10549. plci->adjust_b_state = ADJUST_B_RESTORE_MIXER_6;
  10550. Rc = OK;
  10551. case ADJUST_B_RESTORE_MIXER_6:
  10552. if (!xconnect_write_coefs_process (Id, plci, Rc))
  10553. {
  10554. dbug (1, dprintf ("[%06lx] %s,%d: Write mixer coefs failed",
  10555. UnMapId (Id), (char *)(FILE_), __LINE__));
  10556. Info = _FACILITY_NOT_SUPPORTED;
  10557. break;
  10558. }
  10559. if (plci->internal_command)
  10560. break;
  10561. plci->adjust_b_state = ADJUST_B_RESTORE_MIXER_7;
  10562. case ADJUST_B_RESTORE_MIXER_7:
  10563. break;
  10564. }
  10565. }
  10566. return (Info);
  10567. }
  10568. static void mixer_command (dword Id, PLCI *plci, byte Rc)
  10569. {
  10570. DIVA_CAPI_ADAPTER *a;
  10571. word i, internal_command, Info;
  10572. dbug (1, dprintf ("[%06lx] %s,%d: mixer_command %02x %04x %04x",
  10573. UnMapId (Id), (char *)(FILE_), __LINE__, Rc, plci->internal_command,
  10574. plci->li_cmd));
  10575. Info = GOOD;
  10576. a = plci->adapter;
  10577. internal_command = plci->internal_command;
  10578. plci->internal_command = 0;
  10579. switch (plci->li_cmd)
  10580. {
  10581. case LI_REQ_CONNECT:
  10582. case LI_REQ_DISCONNECT:
  10583. case LI_REQ_SILENT_UPDATE:
  10584. switch (internal_command)
  10585. {
  10586. default:
  10587. if (plci->li_channel_bits & LI_CHANNEL_INVOLVED)
  10588. {
  10589. adjust_b1_resource (Id, plci, NULL, (word)(plci->B1_facilities |
  10590. B1_FACILITY_MIXER), MIXER_COMMAND_1);
  10591. }
  10592. case MIXER_COMMAND_1:
  10593. if (plci->li_channel_bits & LI_CHANNEL_INVOLVED)
  10594. {
  10595. if (adjust_b_process (Id, plci, Rc) != GOOD)
  10596. {
  10597. dbug (1, dprintf ("[%06lx] %s,%d: Load mixer failed",
  10598. UnMapId (Id), (char *)(FILE_), __LINE__));
  10599. Info = _FACILITY_NOT_SUPPORTED;
  10600. break;
  10601. }
  10602. if (plci->internal_command)
  10603. return;
  10604. }
  10605. plci->li_plci_b_req_pos = plci->li_plci_b_write_pos;
  10606. if ((plci->li_channel_bits & LI_CHANNEL_INVOLVED)
  10607. || ((get_b1_facilities (plci, plci->B1_resource) & B1_FACILITY_MIXER)
  10608. && (add_b1_facilities (plci, plci->B1_resource, (word)(plci->B1_facilities &
  10609. ~B1_FACILITY_MIXER)) == plci->B1_resource)))
  10610. {
  10611. xconnect_write_coefs (plci, MIXER_COMMAND_2);
  10612. }
  10613. else
  10614. {
  10615. do
  10616. {
  10617. mixer_indication_coefs_set (Id, plci);
  10618. } while (plci->li_plci_b_read_pos != plci->li_plci_b_req_pos);
  10619. }
  10620. case MIXER_COMMAND_2:
  10621. if ((plci->li_channel_bits & LI_CHANNEL_INVOLVED)
  10622. || ((get_b1_facilities (plci, plci->B1_resource) & B1_FACILITY_MIXER)
  10623. && (add_b1_facilities (plci, plci->B1_resource, (word)(plci->B1_facilities &
  10624. ~B1_FACILITY_MIXER)) == plci->B1_resource)))
  10625. {
  10626. if (!xconnect_write_coefs_process (Id, plci, Rc))
  10627. {
  10628. dbug (1, dprintf ("[%06lx] %s,%d: Write mixer coefs failed",
  10629. UnMapId (Id), (char *)(FILE_), __LINE__));
  10630. if (plci->li_plci_b_write_pos != plci->li_plci_b_req_pos)
  10631. {
  10632. do
  10633. {
  10634. plci->li_plci_b_write_pos = (plci->li_plci_b_write_pos == 0) ?
  10635. LI_PLCI_B_QUEUE_ENTRIES-1 : plci->li_plci_b_write_pos - 1;
  10636. i = (plci->li_plci_b_write_pos == 0) ?
  10637. LI_PLCI_B_QUEUE_ENTRIES-1 : plci->li_plci_b_write_pos - 1;
  10638. } while ((plci->li_plci_b_write_pos != plci->li_plci_b_req_pos)
  10639. && !(plci->li_plci_b_queue[i] & LI_PLCI_B_LAST_FLAG));
  10640. }
  10641. Info = _FACILITY_NOT_SUPPORTED;
  10642. break;
  10643. }
  10644. if (plci->internal_command)
  10645. return;
  10646. }
  10647. if (!(plci->li_channel_bits & LI_CHANNEL_INVOLVED))
  10648. {
  10649. adjust_b1_resource (Id, plci, NULL, (word)(plci->B1_facilities &
  10650. ~B1_FACILITY_MIXER), MIXER_COMMAND_3);
  10651. }
  10652. case MIXER_COMMAND_3:
  10653. if (!(plci->li_channel_bits & LI_CHANNEL_INVOLVED))
  10654. {
  10655. if (adjust_b_process (Id, plci, Rc) != GOOD)
  10656. {
  10657. dbug (1, dprintf ("[%06lx] %s,%d: Unload mixer failed",
  10658. UnMapId (Id), (char *)(FILE_), __LINE__));
  10659. Info = _FACILITY_NOT_SUPPORTED;
  10660. break;
  10661. }
  10662. if (plci->internal_command)
  10663. return;
  10664. }
  10665. break;
  10666. }
  10667. break;
  10668. }
  10669. if ((plci->li_bchannel_id == 0)
  10670. || (li_config_table[a->li_base + (plci->li_bchannel_id - 1)].plci != plci))
  10671. {
  10672. dbug (1, dprintf ("[%06x] %s,%d: Channel id wiped out %d",
  10673. UnMapId (Id), (char *)(FILE_), __LINE__, (int)(plci->li_bchannel_id)));
  10674. }
  10675. else
  10676. {
  10677. i = a->li_base + (plci->li_bchannel_id - 1);
  10678. li_config_table[i].curchnl = plci->li_channel_bits;
  10679. if (!a->li_pri && (plci->tel == ADV_VOICE) && (plci == a->AdvSignalPLCI))
  10680. {
  10681. i = a->li_base + MIXER_IC_CHANNEL_BASE + (plci->li_bchannel_id - 1);
  10682. li_config_table[i].curchnl = plci->li_channel_bits;
  10683. if (a->manufacturer_features & MANUFACTURER_FEATURE_SLAVE_CODEC)
  10684. {
  10685. i = a->li_base + MIXER_IC_CHANNEL_BASE + (2 - plci->li_bchannel_id);
  10686. li_config_table[i].curchnl = plci->li_channel_bits;
  10687. }
  10688. }
  10689. }
  10690. }
  10691. static void li_update_connect (dword Id, DIVA_CAPI_ADAPTER *a, PLCI *plci,
  10692. dword plci_b_id, byte connect, dword li_flags)
  10693. {
  10694. word i, ch_a, ch_a_v, ch_a_s, ch_b, ch_b_v, ch_b_s;
  10695. PLCI *plci_b;
  10696. DIVA_CAPI_ADAPTER *a_b;
  10697. a_b = &(adapter[MapController ((byte)(plci_b_id & 0x7f)) - 1]);
  10698. plci_b = &(a_b->plci[((plci_b_id >> 8) & 0xff) - 1]);
  10699. ch_a = a->li_base + (plci->li_bchannel_id - 1);
  10700. if (!a->li_pri && (plci->tel == ADV_VOICE)
  10701. && (plci == a->AdvSignalPLCI) && (Id & EXT_CONTROLLER))
  10702. {
  10703. ch_a_v = ch_a + MIXER_IC_CHANNEL_BASE;
  10704. ch_a_s = (a->manufacturer_features & MANUFACTURER_FEATURE_SLAVE_CODEC) ?
  10705. a->li_base + MIXER_IC_CHANNEL_BASE + (2 - plci->li_bchannel_id) : ch_a_v;
  10706. }
  10707. else
  10708. {
  10709. ch_a_v = ch_a;
  10710. ch_a_s = ch_a;
  10711. }
  10712. ch_b = a_b->li_base + (plci_b->li_bchannel_id - 1);
  10713. if (!a_b->li_pri && (plci_b->tel == ADV_VOICE)
  10714. && (plci_b == a_b->AdvSignalPLCI) && (plci_b_id & EXT_CONTROLLER))
  10715. {
  10716. ch_b_v = ch_b + MIXER_IC_CHANNEL_BASE;
  10717. ch_b_s = (a_b->manufacturer_features & MANUFACTURER_FEATURE_SLAVE_CODEC) ?
  10718. a_b->li_base + MIXER_IC_CHANNEL_BASE + (2 - plci_b->li_bchannel_id) : ch_b_v;
  10719. }
  10720. else
  10721. {
  10722. ch_b_v = ch_b;
  10723. ch_b_s = ch_b;
  10724. }
  10725. if (connect)
  10726. {
  10727. li_config_table[ch_a].flag_table[ch_a_v] &= ~LI_FLAG_MONITOR;
  10728. li_config_table[ch_a].flag_table[ch_a_s] &= ~LI_FLAG_MONITOR;
  10729. li_config_table[ch_a_v].flag_table[ch_a] &= ~(LI_FLAG_ANNOUNCEMENT | LI_FLAG_MIX);
  10730. li_config_table[ch_a_s].flag_table[ch_a] &= ~(LI_FLAG_ANNOUNCEMENT | LI_FLAG_MIX);
  10731. }
  10732. li_config_table[ch_a].flag_table[ch_b_v] &= ~LI_FLAG_MONITOR;
  10733. li_config_table[ch_a].flag_table[ch_b_s] &= ~LI_FLAG_MONITOR;
  10734. li_config_table[ch_b_v].flag_table[ch_a] &= ~(LI_FLAG_ANNOUNCEMENT | LI_FLAG_MIX);
  10735. li_config_table[ch_b_s].flag_table[ch_a] &= ~(LI_FLAG_ANNOUNCEMENT | LI_FLAG_MIX);
  10736. if (ch_a_v == ch_b_v)
  10737. {
  10738. li_config_table[ch_a_v].flag_table[ch_b_v] &= ~LI_FLAG_CONFERENCE;
  10739. li_config_table[ch_a_s].flag_table[ch_b_s] &= ~LI_FLAG_CONFERENCE;
  10740. }
  10741. else
  10742. {
  10743. if (li_config_table[ch_a_v].flag_table[ch_b_v] & LI_FLAG_CONFERENCE)
  10744. {
  10745. for (i = 0; i < li_total_channels; i++)
  10746. {
  10747. if (i != ch_a_v)
  10748. li_config_table[ch_a_v].flag_table[i] &= ~LI_FLAG_CONFERENCE;
  10749. }
  10750. }
  10751. if (li_config_table[ch_a_s].flag_table[ch_b_v] & LI_FLAG_CONFERENCE)
  10752. {
  10753. for (i = 0; i < li_total_channels; i++)
  10754. {
  10755. if (i != ch_a_s)
  10756. li_config_table[ch_a_s].flag_table[i] &= ~LI_FLAG_CONFERENCE;
  10757. }
  10758. }
  10759. if (li_config_table[ch_b_v].flag_table[ch_a_v] & LI_FLAG_CONFERENCE)
  10760. {
  10761. for (i = 0; i < li_total_channels; i++)
  10762. {
  10763. if (i != ch_a_v)
  10764. li_config_table[i].flag_table[ch_a_v] &= ~LI_FLAG_CONFERENCE;
  10765. }
  10766. }
  10767. if (li_config_table[ch_b_v].flag_table[ch_a_s] & LI_FLAG_CONFERENCE)
  10768. {
  10769. for (i = 0; i < li_total_channels; i++)
  10770. {
  10771. if (i != ch_a_s)
  10772. li_config_table[i].flag_table[ch_a_s] &= ~LI_FLAG_CONFERENCE;
  10773. }
  10774. }
  10775. }
  10776. if (li_flags & LI_FLAG_CONFERENCE_A_B)
  10777. {
  10778. li_config_table[ch_b_v].flag_table[ch_a_v] |= LI_FLAG_CONFERENCE;
  10779. li_config_table[ch_b_s].flag_table[ch_a_v] |= LI_FLAG_CONFERENCE;
  10780. li_config_table[ch_b_v].flag_table[ch_a_s] |= LI_FLAG_CONFERENCE;
  10781. li_config_table[ch_b_s].flag_table[ch_a_s] |= LI_FLAG_CONFERENCE;
  10782. }
  10783. if (li_flags & LI_FLAG_CONFERENCE_B_A)
  10784. {
  10785. li_config_table[ch_a_v].flag_table[ch_b_v] |= LI_FLAG_CONFERENCE;
  10786. li_config_table[ch_a_v].flag_table[ch_b_s] |= LI_FLAG_CONFERENCE;
  10787. li_config_table[ch_a_s].flag_table[ch_b_v] |= LI_FLAG_CONFERENCE;
  10788. li_config_table[ch_a_s].flag_table[ch_b_s] |= LI_FLAG_CONFERENCE;
  10789. }
  10790. if (li_flags & LI_FLAG_MONITOR_A)
  10791. {
  10792. li_config_table[ch_a].flag_table[ch_a_v] |= LI_FLAG_MONITOR;
  10793. li_config_table[ch_a].flag_table[ch_a_s] |= LI_FLAG_MONITOR;
  10794. }
  10795. if (li_flags & LI_FLAG_MONITOR_B)
  10796. {
  10797. li_config_table[ch_a].flag_table[ch_b_v] |= LI_FLAG_MONITOR;
  10798. li_config_table[ch_a].flag_table[ch_b_s] |= LI_FLAG_MONITOR;
  10799. }
  10800. if (li_flags & LI_FLAG_ANNOUNCEMENT_A)
  10801. {
  10802. li_config_table[ch_a_v].flag_table[ch_a] |= LI_FLAG_ANNOUNCEMENT;
  10803. li_config_table[ch_a_s].flag_table[ch_a] |= LI_FLAG_ANNOUNCEMENT;
  10804. }
  10805. if (li_flags & LI_FLAG_ANNOUNCEMENT_B)
  10806. {
  10807. li_config_table[ch_b_v].flag_table[ch_a] |= LI_FLAG_ANNOUNCEMENT;
  10808. li_config_table[ch_b_s].flag_table[ch_a] |= LI_FLAG_ANNOUNCEMENT;
  10809. }
  10810. if (li_flags & LI_FLAG_MIX_A)
  10811. {
  10812. li_config_table[ch_a_v].flag_table[ch_a] |= LI_FLAG_MIX;
  10813. li_config_table[ch_a_s].flag_table[ch_a] |= LI_FLAG_MIX;
  10814. }
  10815. if (li_flags & LI_FLAG_MIX_B)
  10816. {
  10817. li_config_table[ch_b_v].flag_table[ch_a] |= LI_FLAG_MIX;
  10818. li_config_table[ch_b_s].flag_table[ch_a] |= LI_FLAG_MIX;
  10819. }
  10820. if (ch_a_v != ch_a_s)
  10821. {
  10822. li_config_table[ch_a_v].flag_table[ch_a_s] |= LI_FLAG_CONFERENCE;
  10823. li_config_table[ch_a_s].flag_table[ch_a_v] |= LI_FLAG_CONFERENCE;
  10824. }
  10825. if (ch_b_v != ch_b_s)
  10826. {
  10827. li_config_table[ch_b_v].flag_table[ch_b_s] |= LI_FLAG_CONFERENCE;
  10828. li_config_table[ch_b_s].flag_table[ch_b_v] |= LI_FLAG_CONFERENCE;
  10829. }
  10830. }
  10831. static void li2_update_connect (dword Id, DIVA_CAPI_ADAPTER *a, PLCI *plci,
  10832. dword plci_b_id, byte connect, dword li_flags)
  10833. {
  10834. word ch_a, ch_a_v, ch_a_s, ch_b, ch_b_v, ch_b_s;
  10835. PLCI *plci_b;
  10836. DIVA_CAPI_ADAPTER *a_b;
  10837. a_b = &(adapter[MapController ((byte)(plci_b_id & 0x7f)) - 1]);
  10838. plci_b = &(a_b->plci[((plci_b_id >> 8) & 0xff) - 1]);
  10839. ch_a = a->li_base + (plci->li_bchannel_id - 1);
  10840. if (!a->li_pri && (plci->tel == ADV_VOICE)
  10841. && (plci == a->AdvSignalPLCI) && (Id & EXT_CONTROLLER))
  10842. {
  10843. ch_a_v = ch_a + MIXER_IC_CHANNEL_BASE;
  10844. ch_a_s = (a->manufacturer_features & MANUFACTURER_FEATURE_SLAVE_CODEC) ?
  10845. a->li_base + MIXER_IC_CHANNEL_BASE + (2 - plci->li_bchannel_id) : ch_a_v;
  10846. }
  10847. else
  10848. {
  10849. ch_a_v = ch_a;
  10850. ch_a_s = ch_a;
  10851. }
  10852. ch_b = a_b->li_base + (plci_b->li_bchannel_id - 1);
  10853. if (!a_b->li_pri && (plci_b->tel == ADV_VOICE)
  10854. && (plci_b == a_b->AdvSignalPLCI) && (plci_b_id & EXT_CONTROLLER))
  10855. {
  10856. ch_b_v = ch_b + MIXER_IC_CHANNEL_BASE;
  10857. ch_b_s = (a_b->manufacturer_features & MANUFACTURER_FEATURE_SLAVE_CODEC) ?
  10858. a_b->li_base + MIXER_IC_CHANNEL_BASE + (2 - plci_b->li_bchannel_id) : ch_b_v;
  10859. }
  10860. else
  10861. {
  10862. ch_b_v = ch_b;
  10863. ch_b_s = ch_b;
  10864. }
  10865. if (connect)
  10866. {
  10867. li_config_table[ch_b].flag_table[ch_b_v] &= ~LI_FLAG_MONITOR;
  10868. li_config_table[ch_b].flag_table[ch_b_s] &= ~LI_FLAG_MONITOR;
  10869. li_config_table[ch_b_v].flag_table[ch_b] &= ~LI_FLAG_MIX;
  10870. li_config_table[ch_b_s].flag_table[ch_b] &= ~LI_FLAG_MIX;
  10871. li_config_table[ch_b].flag_table[ch_b] &= ~LI_FLAG_PCCONNECT;
  10872. li_config_table[ch_b].chflags &= ~(LI_CHFLAG_MONITOR | LI_CHFLAG_MIX | LI_CHFLAG_LOOP);
  10873. }
  10874. li_config_table[ch_b_v].flag_table[ch_a_v] &= ~(LI_FLAG_INTERCONNECT | LI_FLAG_CONFERENCE);
  10875. li_config_table[ch_b_s].flag_table[ch_a_v] &= ~(LI_FLAG_INTERCONNECT | LI_FLAG_CONFERENCE);
  10876. li_config_table[ch_b_v].flag_table[ch_a_s] &= ~(LI_FLAG_INTERCONNECT | LI_FLAG_CONFERENCE);
  10877. li_config_table[ch_b_s].flag_table[ch_a_s] &= ~(LI_FLAG_INTERCONNECT | LI_FLAG_CONFERENCE);
  10878. li_config_table[ch_a_v].flag_table[ch_b_v] &= ~(LI_FLAG_INTERCONNECT | LI_FLAG_CONFERENCE);
  10879. li_config_table[ch_a_v].flag_table[ch_b_s] &= ~(LI_FLAG_INTERCONNECT | LI_FLAG_CONFERENCE);
  10880. li_config_table[ch_a_s].flag_table[ch_b_v] &= ~(LI_FLAG_INTERCONNECT | LI_FLAG_CONFERENCE);
  10881. li_config_table[ch_a_s].flag_table[ch_b_s] &= ~(LI_FLAG_INTERCONNECT | LI_FLAG_CONFERENCE);
  10882. if (li_flags & LI2_FLAG_INTERCONNECT_A_B)
  10883. {
  10884. li_config_table[ch_b_v].flag_table[ch_a_v] |= LI_FLAG_INTERCONNECT;
  10885. li_config_table[ch_b_s].flag_table[ch_a_v] |= LI_FLAG_INTERCONNECT;
  10886. li_config_table[ch_b_v].flag_table[ch_a_s] |= LI_FLAG_INTERCONNECT;
  10887. li_config_table[ch_b_s].flag_table[ch_a_s] |= LI_FLAG_INTERCONNECT;
  10888. }
  10889. if (li_flags & LI2_FLAG_INTERCONNECT_B_A)
  10890. {
  10891. li_config_table[ch_a_v].flag_table[ch_b_v] |= LI_FLAG_INTERCONNECT;
  10892. li_config_table[ch_a_v].flag_table[ch_b_s] |= LI_FLAG_INTERCONNECT;
  10893. li_config_table[ch_a_s].flag_table[ch_b_v] |= LI_FLAG_INTERCONNECT;
  10894. li_config_table[ch_a_s].flag_table[ch_b_s] |= LI_FLAG_INTERCONNECT;
  10895. }
  10896. if (li_flags & LI2_FLAG_MONITOR_B)
  10897. {
  10898. li_config_table[ch_b].flag_table[ch_b_v] |= LI_FLAG_MONITOR;
  10899. li_config_table[ch_b].flag_table[ch_b_s] |= LI_FLAG_MONITOR;
  10900. }
  10901. if (li_flags & LI2_FLAG_MIX_B)
  10902. {
  10903. li_config_table[ch_b_v].flag_table[ch_b] |= LI_FLAG_MIX;
  10904. li_config_table[ch_b_s].flag_table[ch_b] |= LI_FLAG_MIX;
  10905. }
  10906. if (li_flags & LI2_FLAG_MONITOR_X)
  10907. li_config_table[ch_b].chflags |= LI_CHFLAG_MONITOR;
  10908. if (li_flags & LI2_FLAG_MIX_X)
  10909. li_config_table[ch_b].chflags |= LI_CHFLAG_MIX;
  10910. if (li_flags & LI2_FLAG_LOOP_B)
  10911. {
  10912. li_config_table[ch_b_v].flag_table[ch_b_v] |= LI_FLAG_INTERCONNECT;
  10913. li_config_table[ch_b_s].flag_table[ch_b_v] |= LI_FLAG_INTERCONNECT;
  10914. li_config_table[ch_b_v].flag_table[ch_b_s] |= LI_FLAG_INTERCONNECT;
  10915. li_config_table[ch_b_s].flag_table[ch_b_s] |= LI_FLAG_INTERCONNECT;
  10916. }
  10917. if (li_flags & LI2_FLAG_LOOP_PC)
  10918. li_config_table[ch_b].flag_table[ch_b] |= LI_FLAG_PCCONNECT;
  10919. if (li_flags & LI2_FLAG_LOOP_X)
  10920. li_config_table[ch_b].chflags |= LI_CHFLAG_LOOP;
  10921. if (li_flags & LI2_FLAG_PCCONNECT_A_B)
  10922. li_config_table[ch_b_s].flag_table[ch_a_s] |= LI_FLAG_PCCONNECT;
  10923. if (li_flags & LI2_FLAG_PCCONNECT_B_A)
  10924. li_config_table[ch_a_s].flag_table[ch_b_s] |= LI_FLAG_PCCONNECT;
  10925. if (ch_a_v != ch_a_s)
  10926. {
  10927. li_config_table[ch_a_v].flag_table[ch_a_s] |= LI_FLAG_CONFERENCE;
  10928. li_config_table[ch_a_s].flag_table[ch_a_v] |= LI_FLAG_CONFERENCE;
  10929. }
  10930. if (ch_b_v != ch_b_s)
  10931. {
  10932. li_config_table[ch_b_v].flag_table[ch_b_s] |= LI_FLAG_CONFERENCE;
  10933. li_config_table[ch_b_s].flag_table[ch_b_v] |= LI_FLAG_CONFERENCE;
  10934. }
  10935. }
  10936. static word li_check_main_plci (dword Id, PLCI *plci)
  10937. {
  10938. if (plci == NULL)
  10939. {
  10940. dbug (1, dprintf ("[%06lx] %s,%d: Wrong PLCI",
  10941. UnMapId (Id), (char *)(FILE_), __LINE__));
  10942. return (_WRONG_IDENTIFIER);
  10943. }
  10944. if (!plci->State
  10945. || !plci->NL.Id || plci->nl_remove_id
  10946. || (plci->li_bchannel_id == 0))
  10947. {
  10948. dbug (1, dprintf ("[%06lx] %s,%d: Wrong state",
  10949. UnMapId (Id), (char *)(FILE_), __LINE__));
  10950. return (_WRONG_STATE);
  10951. }
  10952. li_config_table[plci->adapter->li_base + (plci->li_bchannel_id - 1)].plci = plci;
  10953. return (GOOD);
  10954. }
  10955. static PLCI *li_check_plci_b (dword Id, PLCI *plci,
  10956. dword plci_b_id, word plci_b_write_pos, byte *p_result)
  10957. {
  10958. byte ctlr_b;
  10959. PLCI *plci_b;
  10960. if (((plci->li_plci_b_read_pos > plci_b_write_pos) ? plci->li_plci_b_read_pos :
  10961. LI_PLCI_B_QUEUE_ENTRIES + plci->li_plci_b_read_pos) - plci_b_write_pos - 1 < 2)
  10962. {
  10963. dbug (1, dprintf ("[%06lx] %s,%d: LI request overrun",
  10964. UnMapId (Id), (char *)(FILE_), __LINE__));
  10965. PUT_WORD (p_result, _REQUEST_NOT_ALLOWED_IN_THIS_STATE);
  10966. return (NULL);
  10967. }
  10968. ctlr_b = 0;
  10969. if ((plci_b_id & 0x7f) != 0)
  10970. {
  10971. ctlr_b = MapController ((byte)(plci_b_id & 0x7f));
  10972. if ((ctlr_b > max_adapter) || ((ctlr_b != 0) && (adapter[ctlr_b - 1].request == NULL)))
  10973. ctlr_b = 0;
  10974. }
  10975. if ((ctlr_b == 0)
  10976. || (((plci_b_id >> 8) & 0xff) == 0)
  10977. || (((plci_b_id >> 8) & 0xff) > adapter[ctlr_b - 1].max_plci))
  10978. {
  10979. dbug (1, dprintf ("[%06lx] %s,%d: LI invalid second PLCI %08lx",
  10980. UnMapId (Id), (char *)(FILE_), __LINE__, plci_b_id));
  10981. PUT_WORD (p_result, _WRONG_IDENTIFIER);
  10982. return (NULL);
  10983. }
  10984. plci_b = &(adapter[ctlr_b - 1].plci[((plci_b_id >> 8) & 0xff) - 1]);
  10985. if (!plci_b->State
  10986. || !plci_b->NL.Id || plci_b->nl_remove_id
  10987. || (plci_b->li_bchannel_id == 0))
  10988. {
  10989. dbug (1, dprintf ("[%06lx] %s,%d: LI peer in wrong state %08lx",
  10990. UnMapId (Id), (char *)(FILE_), __LINE__, plci_b_id));
  10991. PUT_WORD (p_result, _REQUEST_NOT_ALLOWED_IN_THIS_STATE);
  10992. return (NULL);
  10993. }
  10994. li_config_table[plci_b->adapter->li_base + (plci_b->li_bchannel_id - 1)].plci = plci_b;
  10995. if (((byte)(plci_b_id & ~EXT_CONTROLLER)) !=
  10996. ((byte)(UnMapController (plci->adapter->Id) & ~EXT_CONTROLLER))
  10997. && (!(plci->adapter->manufacturer_features & MANUFACTURER_FEATURE_XCONNECT)
  10998. || !(plci_b->adapter->manufacturer_features & MANUFACTURER_FEATURE_XCONNECT)))
  10999. {
  11000. dbug (1, dprintf ("[%06lx] %s,%d: LI not on same ctrl %08lx",
  11001. UnMapId (Id), (char *)(FILE_), __LINE__, plci_b_id));
  11002. PUT_WORD (p_result, _WRONG_IDENTIFIER);
  11003. return (NULL);
  11004. }
  11005. if (!(get_b1_facilities (plci_b, add_b1_facilities (plci_b, plci_b->B1_resource,
  11006. (word)(plci_b->B1_facilities | B1_FACILITY_MIXER))) & B1_FACILITY_MIXER))
  11007. {
  11008. dbug (1, dprintf ("[%06lx] %s,%d: Interconnect peer cannot mix %d",
  11009. UnMapId (Id), (char *)(FILE_), __LINE__, plci_b->B1_resource));
  11010. PUT_WORD (p_result, _REQUEST_NOT_ALLOWED_IN_THIS_STATE);
  11011. return (NULL);
  11012. }
  11013. return (plci_b);
  11014. }
  11015. static PLCI *li2_check_plci_b (dword Id, PLCI *plci,
  11016. dword plci_b_id, word plci_b_write_pos, byte *p_result)
  11017. {
  11018. byte ctlr_b;
  11019. PLCI *plci_b;
  11020. if (((plci->li_plci_b_read_pos > plci_b_write_pos) ? plci->li_plci_b_read_pos :
  11021. LI_PLCI_B_QUEUE_ENTRIES + plci->li_plci_b_read_pos) - plci_b_write_pos - 1 < 2)
  11022. {
  11023. dbug (1, dprintf ("[%06lx] %s,%d: LI request overrun",
  11024. UnMapId (Id), (char *)(FILE_), __LINE__));
  11025. PUT_WORD (p_result, _WRONG_STATE);
  11026. return (NULL);
  11027. }
  11028. ctlr_b = 0;
  11029. if ((plci_b_id & 0x7f) != 0)
  11030. {
  11031. ctlr_b = MapController ((byte)(plci_b_id & 0x7f));
  11032. if ((ctlr_b > max_adapter) || ((ctlr_b != 0) && (adapter[ctlr_b - 1].request == NULL)))
  11033. ctlr_b = 0;
  11034. }
  11035. if ((ctlr_b == 0)
  11036. || (((plci_b_id >> 8) & 0xff) == 0)
  11037. || (((plci_b_id >> 8) & 0xff) > adapter[ctlr_b - 1].max_plci))
  11038. {
  11039. dbug (1, dprintf ("[%06lx] %s,%d: LI invalid second PLCI %08lx",
  11040. UnMapId (Id), (char *)(FILE_), __LINE__, plci_b_id));
  11041. PUT_WORD (p_result, _WRONG_IDENTIFIER);
  11042. return (NULL);
  11043. }
  11044. plci_b = &(adapter[ctlr_b - 1].plci[((plci_b_id >> 8) & 0xff) - 1]);
  11045. if (!plci_b->State
  11046. || !plci_b->NL.Id || plci_b->nl_remove_id
  11047. || (plci_b->li_bchannel_id == 0)
  11048. || (li_config_table[plci_b->adapter->li_base + (plci_b->li_bchannel_id - 1)].plci != plci_b))
  11049. {
  11050. dbug (1, dprintf ("[%06lx] %s,%d: LI peer in wrong state %08lx",
  11051. UnMapId (Id), (char *)(FILE_), __LINE__, plci_b_id));
  11052. PUT_WORD (p_result, _WRONG_STATE);
  11053. return (NULL);
  11054. }
  11055. if (((byte)(plci_b_id & ~EXT_CONTROLLER)) !=
  11056. ((byte)(UnMapController (plci->adapter->Id) & ~EXT_CONTROLLER))
  11057. && (!(plci->adapter->manufacturer_features & MANUFACTURER_FEATURE_XCONNECT)
  11058. || !(plci_b->adapter->manufacturer_features & MANUFACTURER_FEATURE_XCONNECT)))
  11059. {
  11060. dbug (1, dprintf ("[%06lx] %s,%d: LI not on same ctrl %08lx",
  11061. UnMapId (Id), (char *)(FILE_), __LINE__, plci_b_id));
  11062. PUT_WORD (p_result, _WRONG_IDENTIFIER);
  11063. return (NULL);
  11064. }
  11065. if (!(get_b1_facilities (plci_b, add_b1_facilities (plci_b, plci_b->B1_resource,
  11066. (word)(plci_b->B1_facilities | B1_FACILITY_MIXER))) & B1_FACILITY_MIXER))
  11067. {
  11068. dbug (1, dprintf ("[%06lx] %s,%d: Interconnect peer cannot mix %d",
  11069. UnMapId (Id), (char *)(FILE_), __LINE__, plci_b->B1_resource));
  11070. PUT_WORD (p_result, _WRONG_STATE);
  11071. return (NULL);
  11072. }
  11073. return (plci_b);
  11074. }
  11075. static byte mixer_request (dword Id, word Number, DIVA_CAPI_ADAPTER *a, PLCI *plci, APPL *appl, API_PARSE *msg)
  11076. {
  11077. word Info;
  11078. word i;
  11079. dword d, li_flags, plci_b_id;
  11080. PLCI *plci_b;
  11081. API_PARSE li_parms[3];
  11082. API_PARSE li_req_parms[3];
  11083. API_PARSE li_participant_struct[2];
  11084. API_PARSE li_participant_parms[3];
  11085. word participant_parms_pos;
  11086. byte result_buffer[32];
  11087. byte *result;
  11088. word result_pos;
  11089. word plci_b_write_pos;
  11090. dbug (1, dprintf ("[%06lx] %s,%d: mixer_request",
  11091. UnMapId (Id), (char *)(FILE_), __LINE__));
  11092. Info = GOOD;
  11093. result = result_buffer;
  11094. result_buffer[0] = 0;
  11095. if (!(a->profile.Global_Options & GL_LINE_INTERCONNECT_SUPPORTED))
  11096. {
  11097. dbug (1, dprintf ("[%06lx] %s,%d: Facility not supported",
  11098. UnMapId (Id), (char *)(FILE_), __LINE__));
  11099. Info = _FACILITY_NOT_SUPPORTED;
  11100. }
  11101. else if (api_parse (&msg[1].info[1], msg[1].length, "ws", li_parms))
  11102. {
  11103. dbug (1, dprintf ("[%06lx] %s,%d: Wrong message format",
  11104. UnMapId (Id), (char *)(FILE_), __LINE__));
  11105. Info = _WRONG_MESSAGE_FORMAT;
  11106. }
  11107. else
  11108. {
  11109. result_buffer[0] = 3;
  11110. PUT_WORD (&result_buffer[1], GET_WORD (li_parms[0].info));
  11111. result_buffer[3] = 0;
  11112. switch (GET_WORD (li_parms[0].info))
  11113. {
  11114. case LI_GET_SUPPORTED_SERVICES:
  11115. if (appl->appl_flags & APPL_FLAG_OLD_LI_SPEC)
  11116. {
  11117. result_buffer[0] = 17;
  11118. result_buffer[3] = 14;
  11119. PUT_WORD (&result_buffer[4], GOOD);
  11120. d = 0;
  11121. if (a->manufacturer_features & MANUFACTURER_FEATURE_MIXER_CH_CH)
  11122. d |= LI_CONFERENCING_SUPPORTED;
  11123. if (a->manufacturer_features & MANUFACTURER_FEATURE_MIXER_CH_PC)
  11124. d |= LI_MONITORING_SUPPORTED;
  11125. if (a->manufacturer_features & MANUFACTURER_FEATURE_MIXER_PC_CH)
  11126. d |= LI_ANNOUNCEMENTS_SUPPORTED | LI_MIXING_SUPPORTED;
  11127. if (a->manufacturer_features & MANUFACTURER_FEATURE_XCONNECT)
  11128. d |= LI_CROSS_CONTROLLER_SUPPORTED;
  11129. PUT_DWORD (&result_buffer[6], d);
  11130. if (a->manufacturer_features & MANUFACTURER_FEATURE_XCONNECT)
  11131. {
  11132. d = 0;
  11133. for (i = 0; i < li_total_channels; i++)
  11134. {
  11135. if ((li_config_table[i].adapter->manufacturer_features & MANUFACTURER_FEATURE_XCONNECT)
  11136. && (li_config_table[i].adapter->li_pri
  11137. || (i < li_config_table[i].adapter->li_base + MIXER_BCHANNELS_BRI)))
  11138. {
  11139. d++;
  11140. }
  11141. }
  11142. }
  11143. else
  11144. {
  11145. d = a->li_pri ? a->li_channels : MIXER_BCHANNELS_BRI;
  11146. }
  11147. PUT_DWORD (&result_buffer[10], d / 2);
  11148. PUT_DWORD (&result_buffer[14], d);
  11149. }
  11150. else
  11151. {
  11152. result_buffer[0] = 25;
  11153. result_buffer[3] = 22;
  11154. PUT_WORD (&result_buffer[4], GOOD);
  11155. d = LI2_ASYMMETRIC_SUPPORTED | LI2_B_LOOPING_SUPPORTED | LI2_X_LOOPING_SUPPORTED;
  11156. if (a->manufacturer_features & MANUFACTURER_FEATURE_MIXER_CH_PC)
  11157. d |= LI2_MONITORING_SUPPORTED | LI2_REMOTE_MONITORING_SUPPORTED;
  11158. if (a->manufacturer_features & MANUFACTURER_FEATURE_MIXER_PC_CH)
  11159. d |= LI2_MIXING_SUPPORTED | LI2_REMOTE_MIXING_SUPPORTED;
  11160. if (a->manufacturer_features & MANUFACTURER_FEATURE_MIXER_PC_PC)
  11161. d |= LI2_PC_LOOPING_SUPPORTED;
  11162. if (a->manufacturer_features & MANUFACTURER_FEATURE_XCONNECT)
  11163. d |= LI2_CROSS_CONTROLLER_SUPPORTED;
  11164. PUT_DWORD (&result_buffer[6], d);
  11165. d = a->li_pri ? a->li_channels : MIXER_BCHANNELS_BRI;
  11166. PUT_DWORD (&result_buffer[10], d / 2);
  11167. PUT_DWORD (&result_buffer[14], d - 1);
  11168. if (a->manufacturer_features & MANUFACTURER_FEATURE_XCONNECT)
  11169. {
  11170. d = 0;
  11171. for (i = 0; i < li_total_channels; i++)
  11172. {
  11173. if ((li_config_table[i].adapter->manufacturer_features & MANUFACTURER_FEATURE_XCONNECT)
  11174. && (li_config_table[i].adapter->li_pri
  11175. || (i < li_config_table[i].adapter->li_base + MIXER_BCHANNELS_BRI)))
  11176. {
  11177. d++;
  11178. }
  11179. }
  11180. }
  11181. PUT_DWORD (&result_buffer[18], d / 2);
  11182. PUT_DWORD (&result_buffer[22], d - 1);
  11183. }
  11184. break;
  11185. case LI_REQ_CONNECT:
  11186. if (li_parms[1].length == 8)
  11187. {
  11188. appl->appl_flags |= APPL_FLAG_OLD_LI_SPEC;
  11189. if (api_parse (&li_parms[1].info[1], li_parms[1].length, "dd", li_req_parms))
  11190. {
  11191. dbug (1, dprintf ("[%06lx] %s,%d: Wrong message format",
  11192. UnMapId (Id), (char *)(FILE_), __LINE__));
  11193. Info = _WRONG_MESSAGE_FORMAT;
  11194. break;
  11195. }
  11196. plci_b_id = GET_DWORD (li_req_parms[0].info) & 0xffff;
  11197. li_flags = GET_DWORD (li_req_parms[1].info);
  11198. Info = li_check_main_plci (Id, plci);
  11199. result_buffer[0] = 9;
  11200. result_buffer[3] = 6;
  11201. PUT_DWORD (&result_buffer[4], plci_b_id);
  11202. PUT_WORD (&result_buffer[8], GOOD);
  11203. if (Info != GOOD)
  11204. break;
  11205. result = plci->saved_msg.info;
  11206. for (i = 0; i <= result_buffer[0]; i++)
  11207. result[i] = result_buffer[i];
  11208. plci_b_write_pos = plci->li_plci_b_write_pos;
  11209. plci_b = li_check_plci_b (Id, plci, plci_b_id, plci_b_write_pos, &result[8]);
  11210. if (plci_b == NULL)
  11211. break;
  11212. li_update_connect (Id, a, plci, plci_b_id, true, li_flags);
  11213. plci->li_plci_b_queue[plci_b_write_pos] = plci_b_id | LI_PLCI_B_LAST_FLAG;
  11214. plci_b_write_pos = (plci_b_write_pos == LI_PLCI_B_QUEUE_ENTRIES-1) ? 0 : plci_b_write_pos + 1;
  11215. plci->li_plci_b_write_pos = plci_b_write_pos;
  11216. }
  11217. else
  11218. {
  11219. appl->appl_flags &= ~APPL_FLAG_OLD_LI_SPEC;
  11220. if (api_parse (&li_parms[1].info[1], li_parms[1].length, "ds", li_req_parms))
  11221. {
  11222. dbug (1, dprintf ("[%06lx] %s,%d: Wrong message format",
  11223. UnMapId (Id), (char *)(FILE_), __LINE__));
  11224. Info = _WRONG_MESSAGE_FORMAT;
  11225. break;
  11226. }
  11227. li_flags = GET_DWORD (li_req_parms[0].info) & ~(LI2_FLAG_INTERCONNECT_A_B | LI2_FLAG_INTERCONNECT_B_A);
  11228. Info = li_check_main_plci (Id, plci);
  11229. result_buffer[0] = 7;
  11230. result_buffer[3] = 4;
  11231. PUT_WORD (&result_buffer[4], Info);
  11232. result_buffer[6] = 0;
  11233. if (Info != GOOD)
  11234. break;
  11235. result = plci->saved_msg.info;
  11236. for (i = 0; i <= result_buffer[0]; i++)
  11237. result[i] = result_buffer[i];
  11238. plci_b_write_pos = plci->li_plci_b_write_pos;
  11239. participant_parms_pos = 0;
  11240. result_pos = 7;
  11241. li2_update_connect (Id, a, plci, UnMapId (Id), true, li_flags);
  11242. while (participant_parms_pos < li_req_parms[1].length)
  11243. {
  11244. result[result_pos] = 6;
  11245. result_pos += 7;
  11246. PUT_DWORD (&result[result_pos - 6], 0);
  11247. PUT_WORD (&result[result_pos - 2], GOOD);
  11248. if (api_parse (&li_req_parms[1].info[1 + participant_parms_pos],
  11249. (word)(li_parms[1].length - participant_parms_pos), "s", li_participant_struct))
  11250. {
  11251. dbug (1, dprintf ("[%06lx] %s,%d: Wrong message format",
  11252. UnMapId (Id), (char *)(FILE_), __LINE__));
  11253. PUT_WORD (&result[result_pos - 2], _WRONG_MESSAGE_FORMAT);
  11254. break;
  11255. }
  11256. if (api_parse (&li_participant_struct[0].info[1],
  11257. li_participant_struct[0].length, "dd", li_participant_parms))
  11258. {
  11259. dbug (1, dprintf ("[%06lx] %s,%d: Wrong message format",
  11260. UnMapId (Id), (char *)(FILE_), __LINE__));
  11261. PUT_WORD (&result[result_pos - 2], _WRONG_MESSAGE_FORMAT);
  11262. break;
  11263. }
  11264. plci_b_id = GET_DWORD (li_participant_parms[0].info) & 0xffff;
  11265. li_flags = GET_DWORD (li_participant_parms[1].info);
  11266. PUT_DWORD (&result[result_pos - 6], plci_b_id);
  11267. if (sizeof(result) - result_pos < 7)
  11268. {
  11269. dbug (1, dprintf ("[%06lx] %s,%d: LI result overrun",
  11270. UnMapId (Id), (char *)(FILE_), __LINE__));
  11271. PUT_WORD (&result[result_pos - 2], _WRONG_STATE);
  11272. break;
  11273. }
  11274. plci_b = li2_check_plci_b (Id, plci, plci_b_id, plci_b_write_pos, &result[result_pos - 2]);
  11275. if (plci_b != NULL)
  11276. {
  11277. li2_update_connect (Id, a, plci, plci_b_id, true, li_flags);
  11278. plci->li_plci_b_queue[plci_b_write_pos] = plci_b_id |
  11279. ((li_flags & (LI2_FLAG_INTERCONNECT_A_B | LI2_FLAG_INTERCONNECT_B_A |
  11280. LI2_FLAG_PCCONNECT_A_B | LI2_FLAG_PCCONNECT_B_A)) ? 0 : LI_PLCI_B_DISC_FLAG);
  11281. plci_b_write_pos = (plci_b_write_pos == LI_PLCI_B_QUEUE_ENTRIES-1) ? 0 : plci_b_write_pos + 1;
  11282. }
  11283. participant_parms_pos = (word)((&li_participant_struct[0].info[1 + li_participant_struct[0].length]) -
  11284. (&li_req_parms[1].info[1]));
  11285. }
  11286. result[0] = (byte)(result_pos - 1);
  11287. result[3] = (byte)(result_pos - 4);
  11288. result[6] = (byte)(result_pos - 7);
  11289. i = (plci_b_write_pos == 0) ? LI_PLCI_B_QUEUE_ENTRIES-1 : plci_b_write_pos - 1;
  11290. if ((plci_b_write_pos == plci->li_plci_b_read_pos)
  11291. || (plci->li_plci_b_queue[i] & LI_PLCI_B_LAST_FLAG))
  11292. {
  11293. plci->li_plci_b_queue[plci_b_write_pos] = LI_PLCI_B_SKIP_FLAG | LI_PLCI_B_LAST_FLAG;
  11294. plci_b_write_pos = (plci_b_write_pos == LI_PLCI_B_QUEUE_ENTRIES-1) ? 0 : plci_b_write_pos + 1;
  11295. }
  11296. else
  11297. plci->li_plci_b_queue[i] |= LI_PLCI_B_LAST_FLAG;
  11298. plci->li_plci_b_write_pos = plci_b_write_pos;
  11299. }
  11300. mixer_calculate_coefs (a);
  11301. plci->li_channel_bits = li_config_table[a->li_base + (plci->li_bchannel_id - 1)].channel;
  11302. mixer_notify_update (plci, true);
  11303. sendf (appl, _FACILITY_R | CONFIRM, Id & 0xffffL, Number,
  11304. "wwS", Info, SELECTOR_LINE_INTERCONNECT, result);
  11305. plci->command = 0;
  11306. plci->li_cmd = GET_WORD (li_parms[0].info);
  11307. start_internal_command (Id, plci, mixer_command);
  11308. return (false);
  11309. case LI_REQ_DISCONNECT:
  11310. if (li_parms[1].length == 4)
  11311. {
  11312. appl->appl_flags |= APPL_FLAG_OLD_LI_SPEC;
  11313. if (api_parse (&li_parms[1].info[1], li_parms[1].length, "d", li_req_parms))
  11314. {
  11315. dbug (1, dprintf ("[%06lx] %s,%d: Wrong message format",
  11316. UnMapId (Id), (char *)(FILE_), __LINE__));
  11317. Info = _WRONG_MESSAGE_FORMAT;
  11318. break;
  11319. }
  11320. plci_b_id = GET_DWORD (li_req_parms[0].info) & 0xffff;
  11321. Info = li_check_main_plci (Id, plci);
  11322. result_buffer[0] = 9;
  11323. result_buffer[3] = 6;
  11324. PUT_DWORD (&result_buffer[4], GET_DWORD (li_req_parms[0].info));
  11325. PUT_WORD (&result_buffer[8], GOOD);
  11326. if (Info != GOOD)
  11327. break;
  11328. result = plci->saved_msg.info;
  11329. for (i = 0; i <= result_buffer[0]; i++)
  11330. result[i] = result_buffer[i];
  11331. plci_b_write_pos = plci->li_plci_b_write_pos;
  11332. plci_b = li_check_plci_b (Id, plci, plci_b_id, plci_b_write_pos, &result[8]);
  11333. if (plci_b == NULL)
  11334. break;
  11335. li_update_connect (Id, a, plci, plci_b_id, false, 0);
  11336. plci->li_plci_b_queue[plci_b_write_pos] = plci_b_id | LI_PLCI_B_DISC_FLAG | LI_PLCI_B_LAST_FLAG;
  11337. plci_b_write_pos = (plci_b_write_pos == LI_PLCI_B_QUEUE_ENTRIES-1) ? 0 : plci_b_write_pos + 1;
  11338. plci->li_plci_b_write_pos = plci_b_write_pos;
  11339. }
  11340. else
  11341. {
  11342. appl->appl_flags &= ~APPL_FLAG_OLD_LI_SPEC;
  11343. if (api_parse (&li_parms[1].info[1], li_parms[1].length, "s", li_req_parms))
  11344. {
  11345. dbug (1, dprintf ("[%06lx] %s,%d: Wrong message format",
  11346. UnMapId (Id), (char *)(FILE_), __LINE__));
  11347. Info = _WRONG_MESSAGE_FORMAT;
  11348. break;
  11349. }
  11350. Info = li_check_main_plci (Id, plci);
  11351. result_buffer[0] = 7;
  11352. result_buffer[3] = 4;
  11353. PUT_WORD (&result_buffer[4], Info);
  11354. result_buffer[6] = 0;
  11355. if (Info != GOOD)
  11356. break;
  11357. result = plci->saved_msg.info;
  11358. for (i = 0; i <= result_buffer[0]; i++)
  11359. result[i] = result_buffer[i];
  11360. plci_b_write_pos = plci->li_plci_b_write_pos;
  11361. participant_parms_pos = 0;
  11362. result_pos = 7;
  11363. while (participant_parms_pos < li_req_parms[0].length)
  11364. {
  11365. result[result_pos] = 6;
  11366. result_pos += 7;
  11367. PUT_DWORD (&result[result_pos - 6], 0);
  11368. PUT_WORD (&result[result_pos - 2], GOOD);
  11369. if (api_parse (&li_req_parms[0].info[1 + participant_parms_pos],
  11370. (word)(li_parms[1].length - participant_parms_pos), "s", li_participant_struct))
  11371. {
  11372. dbug (1, dprintf ("[%06lx] %s,%d: Wrong message format",
  11373. UnMapId (Id), (char *)(FILE_), __LINE__));
  11374. PUT_WORD (&result[result_pos - 2], _WRONG_MESSAGE_FORMAT);
  11375. break;
  11376. }
  11377. if (api_parse (&li_participant_struct[0].info[1],
  11378. li_participant_struct[0].length, "d", li_participant_parms))
  11379. {
  11380. dbug (1, dprintf ("[%06lx] %s,%d: Wrong message format",
  11381. UnMapId (Id), (char *)(FILE_), __LINE__));
  11382. PUT_WORD (&result[result_pos - 2], _WRONG_MESSAGE_FORMAT);
  11383. break;
  11384. }
  11385. plci_b_id = GET_DWORD (li_participant_parms[0].info) & 0xffff;
  11386. PUT_DWORD (&result[result_pos - 6], plci_b_id);
  11387. if (sizeof(result) - result_pos < 7)
  11388. {
  11389. dbug (1, dprintf ("[%06lx] %s,%d: LI result overrun",
  11390. UnMapId (Id), (char *)(FILE_), __LINE__));
  11391. PUT_WORD (&result[result_pos - 2], _WRONG_STATE);
  11392. break;
  11393. }
  11394. plci_b = li2_check_plci_b (Id, plci, plci_b_id, plci_b_write_pos, &result[result_pos - 2]);
  11395. if (plci_b != NULL)
  11396. {
  11397. li2_update_connect (Id, a, plci, plci_b_id, false, 0);
  11398. plci->li_plci_b_queue[plci_b_write_pos] = plci_b_id | LI_PLCI_B_DISC_FLAG;
  11399. plci_b_write_pos = (plci_b_write_pos == LI_PLCI_B_QUEUE_ENTRIES-1) ? 0 : plci_b_write_pos + 1;
  11400. }
  11401. participant_parms_pos = (word)((&li_participant_struct[0].info[1 + li_participant_struct[0].length]) -
  11402. (&li_req_parms[0].info[1]));
  11403. }
  11404. result[0] = (byte)(result_pos - 1);
  11405. result[3] = (byte)(result_pos - 4);
  11406. result[6] = (byte)(result_pos - 7);
  11407. i = (plci_b_write_pos == 0) ? LI_PLCI_B_QUEUE_ENTRIES-1 : plci_b_write_pos - 1;
  11408. if ((plci_b_write_pos == plci->li_plci_b_read_pos)
  11409. || (plci->li_plci_b_queue[i] & LI_PLCI_B_LAST_FLAG))
  11410. {
  11411. plci->li_plci_b_queue[plci_b_write_pos] = LI_PLCI_B_SKIP_FLAG | LI_PLCI_B_LAST_FLAG;
  11412. plci_b_write_pos = (plci_b_write_pos == LI_PLCI_B_QUEUE_ENTRIES-1) ? 0 : plci_b_write_pos + 1;
  11413. }
  11414. else
  11415. plci->li_plci_b_queue[i] |= LI_PLCI_B_LAST_FLAG;
  11416. plci->li_plci_b_write_pos = plci_b_write_pos;
  11417. }
  11418. mixer_calculate_coefs (a);
  11419. plci->li_channel_bits = li_config_table[a->li_base + (plci->li_bchannel_id - 1)].channel;
  11420. mixer_notify_update (plci, true);
  11421. sendf (appl, _FACILITY_R | CONFIRM, Id & 0xffffL, Number,
  11422. "wwS", Info, SELECTOR_LINE_INTERCONNECT, result);
  11423. plci->command = 0;
  11424. plci->li_cmd = GET_WORD (li_parms[0].info);
  11425. start_internal_command (Id, plci, mixer_command);
  11426. return (false);
  11427. case LI_REQ_SILENT_UPDATE:
  11428. if (!plci || !plci->State
  11429. || !plci->NL.Id || plci->nl_remove_id
  11430. || (plci->li_bchannel_id == 0)
  11431. || (li_config_table[plci->adapter->li_base + (plci->li_bchannel_id - 1)].plci != plci))
  11432. {
  11433. dbug (1, dprintf ("[%06lx] %s,%d: Wrong state",
  11434. UnMapId (Id), (char *)(FILE_), __LINE__));
  11435. return (false);
  11436. }
  11437. plci_b_write_pos = plci->li_plci_b_write_pos;
  11438. if (((plci->li_plci_b_read_pos > plci_b_write_pos) ? plci->li_plci_b_read_pos :
  11439. LI_PLCI_B_QUEUE_ENTRIES + plci->li_plci_b_read_pos) - plci_b_write_pos - 1 < 2)
  11440. {
  11441. dbug (1, dprintf ("[%06lx] %s,%d: LI request overrun",
  11442. UnMapId (Id), (char *)(FILE_), __LINE__));
  11443. return (false);
  11444. }
  11445. i = (plci_b_write_pos == 0) ? LI_PLCI_B_QUEUE_ENTRIES-1 : plci_b_write_pos - 1;
  11446. if ((plci_b_write_pos == plci->li_plci_b_read_pos)
  11447. || (plci->li_plci_b_queue[i] & LI_PLCI_B_LAST_FLAG))
  11448. {
  11449. plci->li_plci_b_queue[plci_b_write_pos] = LI_PLCI_B_SKIP_FLAG | LI_PLCI_B_LAST_FLAG;
  11450. plci_b_write_pos = (plci_b_write_pos == LI_PLCI_B_QUEUE_ENTRIES-1) ? 0 : plci_b_write_pos + 1;
  11451. }
  11452. else
  11453. plci->li_plci_b_queue[i] |= LI_PLCI_B_LAST_FLAG;
  11454. plci->li_plci_b_write_pos = plci_b_write_pos;
  11455. plci->li_channel_bits = li_config_table[a->li_base + (plci->li_bchannel_id - 1)].channel;
  11456. plci->command = 0;
  11457. plci->li_cmd = GET_WORD (li_parms[0].info);
  11458. start_internal_command (Id, plci, mixer_command);
  11459. return (false);
  11460. default:
  11461. dbug (1, dprintf ("[%06lx] %s,%d: LI unknown request %04x",
  11462. UnMapId (Id), (char *)(FILE_), __LINE__, GET_WORD (li_parms[0].info)));
  11463. Info = _FACILITY_NOT_SUPPORTED;
  11464. }
  11465. }
  11466. sendf (appl, _FACILITY_R | CONFIRM, Id & 0xffffL, Number,
  11467. "wwS", Info, SELECTOR_LINE_INTERCONNECT, result);
  11468. return (false);
  11469. }
  11470. static void mixer_indication_coefs_set (dword Id, PLCI *plci)
  11471. {
  11472. dword d;
  11473. DIVA_CAPI_ADAPTER *a;
  11474. byte result[12];
  11475. dbug (1, dprintf ("[%06lx] %s,%d: mixer_indication_coefs_set",
  11476. UnMapId (Id), (char *)(FILE_), __LINE__));
  11477. a = plci->adapter;
  11478. if (plci->li_plci_b_read_pos != plci->li_plci_b_req_pos)
  11479. {
  11480. do
  11481. {
  11482. d = plci->li_plci_b_queue[plci->li_plci_b_read_pos];
  11483. if (!(d & LI_PLCI_B_SKIP_FLAG))
  11484. {
  11485. if (plci->appl->appl_flags & APPL_FLAG_OLD_LI_SPEC)
  11486. {
  11487. if (d & LI_PLCI_B_DISC_FLAG)
  11488. {
  11489. result[0] = 5;
  11490. PUT_WORD (&result[1], LI_IND_DISCONNECT);
  11491. result[3] = 2;
  11492. PUT_WORD (&result[4], _LI_USER_INITIATED);
  11493. }
  11494. else
  11495. {
  11496. result[0] = 7;
  11497. PUT_WORD (&result[1], LI_IND_CONNECT_ACTIVE);
  11498. result[3] = 4;
  11499. PUT_DWORD (&result[4], d & ~LI_PLCI_B_FLAG_MASK);
  11500. }
  11501. }
  11502. else
  11503. {
  11504. if (d & LI_PLCI_B_DISC_FLAG)
  11505. {
  11506. result[0] = 9;
  11507. PUT_WORD (&result[1], LI_IND_DISCONNECT);
  11508. result[3] = 6;
  11509. PUT_DWORD (&result[4], d & ~LI_PLCI_B_FLAG_MASK);
  11510. PUT_WORD (&result[8], _LI_USER_INITIATED);
  11511. }
  11512. else
  11513. {
  11514. result[0] = 7;
  11515. PUT_WORD (&result[1], LI_IND_CONNECT_ACTIVE);
  11516. result[3] = 4;
  11517. PUT_DWORD (&result[4], d & ~LI_PLCI_B_FLAG_MASK);
  11518. }
  11519. }
  11520. sendf (plci->appl, _FACILITY_I, Id & 0xffffL, 0,
  11521. "ws", SELECTOR_LINE_INTERCONNECT, result);
  11522. }
  11523. plci->li_plci_b_read_pos = (plci->li_plci_b_read_pos == LI_PLCI_B_QUEUE_ENTRIES-1) ?
  11524. 0 : plci->li_plci_b_read_pos + 1;
  11525. } while (!(d & LI_PLCI_B_LAST_FLAG) && (plci->li_plci_b_read_pos != plci->li_plci_b_req_pos));
  11526. }
  11527. }
  11528. static void mixer_indication_xconnect_from (dword Id, PLCI *plci, byte *msg, word length)
  11529. {
  11530. word i, j, ch;
  11531. struct xconnect_transfer_address_s s, *p;
  11532. DIVA_CAPI_ADAPTER *a;
  11533. dbug (1, dprintf ("[%06lx] %s,%d: mixer_indication_xconnect_from %d",
  11534. UnMapId (Id), (char *)(FILE_), __LINE__, (int) length));
  11535. a = plci->adapter;
  11536. i = 1;
  11537. for (i = 1; i < length; i += 16)
  11538. {
  11539. s.card_address.low = msg[i] | (msg[i+1] << 8) | (((dword)(msg[i+2])) << 16) | (((dword)(msg[i+3])) << 24);
  11540. s.card_address.high = msg[i+4] | (msg[i+5] << 8) | (((dword)(msg[i+6])) << 16) | (((dword)(msg[i+7])) << 24);
  11541. s.offset = msg[i+8] | (msg[i+9] << 8) | (((dword)(msg[i+10])) << 16) | (((dword)(msg[i+11])) << 24);
  11542. ch = msg[i+12] | (msg[i+13] << 8);
  11543. j = ch & XCONNECT_CHANNEL_NUMBER_MASK;
  11544. if (!a->li_pri && (plci->li_bchannel_id == 2))
  11545. j = 1 - j;
  11546. j += a->li_base;
  11547. if (ch & XCONNECT_CHANNEL_PORT_PC)
  11548. p = &(li_config_table[j].send_pc);
  11549. else
  11550. p = &(li_config_table[j].send_b);
  11551. p->card_address.low = s.card_address.low;
  11552. p->card_address.high = s.card_address.high;
  11553. p->offset = s.offset;
  11554. li_config_table[j].channel |= LI_CHANNEL_ADDRESSES_SET;
  11555. }
  11556. if (plci->internal_command_queue[0]
  11557. && ((plci->adjust_b_state == ADJUST_B_RESTORE_MIXER_2)
  11558. || (plci->adjust_b_state == ADJUST_B_RESTORE_MIXER_3)
  11559. || (plci->adjust_b_state == ADJUST_B_RESTORE_MIXER_4)))
  11560. {
  11561. (*(plci->internal_command_queue[0]))(Id, plci, 0);
  11562. if (!plci->internal_command)
  11563. next_internal_command (Id, plci);
  11564. }
  11565. mixer_notify_update (plci, true);
  11566. }
  11567. static void mixer_indication_xconnect_to (dword Id, PLCI *plci, byte *msg, word length)
  11568. {
  11569. dbug (1, dprintf ("[%06lx] %s,%d: mixer_indication_xconnect_to %d",
  11570. UnMapId (Id), (char *)(FILE_), __LINE__, (int) length));
  11571. }
  11572. static byte mixer_notify_source_removed (PLCI *plci, dword plci_b_id)
  11573. {
  11574. word plci_b_write_pos;
  11575. plci_b_write_pos = plci->li_plci_b_write_pos;
  11576. if (((plci->li_plci_b_read_pos > plci_b_write_pos) ? plci->li_plci_b_read_pos :
  11577. LI_PLCI_B_QUEUE_ENTRIES + plci->li_plci_b_read_pos) - plci_b_write_pos - 1 < 1)
  11578. {
  11579. dbug (1, dprintf ("[%06lx] %s,%d: LI request overrun",
  11580. (dword)((plci->Id << 8) | UnMapController (plci->adapter->Id)),
  11581. (char *)(FILE_), __LINE__));
  11582. return (false);
  11583. }
  11584. plci->li_plci_b_queue[plci_b_write_pos] = plci_b_id | LI_PLCI_B_DISC_FLAG;
  11585. plci_b_write_pos = (plci_b_write_pos == LI_PLCI_B_QUEUE_ENTRIES-1) ? 0 : plci_b_write_pos + 1;
  11586. plci->li_plci_b_write_pos = plci_b_write_pos;
  11587. return (true);
  11588. }
  11589. static void mixer_remove (PLCI *plci)
  11590. {
  11591. DIVA_CAPI_ADAPTER *a;
  11592. PLCI *notify_plci;
  11593. dword plci_b_id;
  11594. word i, j;
  11595. dbug (1, dprintf ("[%06lx] %s,%d: mixer_remove",
  11596. (dword)((plci->Id << 8) | UnMapController (plci->adapter->Id)),
  11597. (char *)(FILE_), __LINE__));
  11598. a = plci->adapter;
  11599. plci_b_id = (plci->Id << 8) | UnMapController (plci->adapter->Id);
  11600. if (a->profile.Global_Options & GL_LINE_INTERCONNECT_SUPPORTED)
  11601. {
  11602. if ((plci->li_bchannel_id != 0)
  11603. && (li_config_table[a->li_base + (plci->li_bchannel_id - 1)].plci == plci))
  11604. {
  11605. i = a->li_base + (plci->li_bchannel_id - 1);
  11606. if ((li_config_table[i].curchnl | li_config_table[i].channel) & LI_CHANNEL_INVOLVED)
  11607. {
  11608. for (j = 0; j < li_total_channels; j++)
  11609. {
  11610. if ((li_config_table[i].flag_table[j] & LI_FLAG_INTERCONNECT)
  11611. || (li_config_table[j].flag_table[i] & LI_FLAG_INTERCONNECT))
  11612. {
  11613. notify_plci = li_config_table[j].plci;
  11614. if ((notify_plci != NULL)
  11615. && (notify_plci != plci)
  11616. && (notify_plci->appl != NULL)
  11617. && !(notify_plci->appl->appl_flags & APPL_FLAG_OLD_LI_SPEC)
  11618. && (notify_plci->State)
  11619. && notify_plci->NL.Id && !notify_plci->nl_remove_id)
  11620. {
  11621. mixer_notify_source_removed (notify_plci, plci_b_id);
  11622. }
  11623. }
  11624. }
  11625. mixer_clear_config (plci);
  11626. mixer_calculate_coefs (a);
  11627. mixer_notify_update (plci, true);
  11628. }
  11629. li_config_table[i].plci = NULL;
  11630. plci->li_bchannel_id = 0;
  11631. }
  11632. }
  11633. }
  11634. /*------------------------------------------------------------------*/
  11635. /* Echo canceller facilities */
  11636. /*------------------------------------------------------------------*/
  11637. static void ec_write_parameters (PLCI *plci)
  11638. {
  11639. word w;
  11640. byte parameter_buffer[6];
  11641. dbug (1, dprintf ("[%06lx] %s,%d: ec_write_parameters",
  11642. (dword)((plci->Id << 8) | UnMapController (plci->adapter->Id)),
  11643. (char *)(FILE_), __LINE__));
  11644. parameter_buffer[0] = 5;
  11645. parameter_buffer[1] = DSP_CTRL_SET_LEC_PARAMETERS;
  11646. PUT_WORD (&parameter_buffer[2], plci->ec_idi_options);
  11647. plci->ec_idi_options &= ~LEC_RESET_COEFFICIENTS;
  11648. w = (plci->ec_tail_length == 0) ? 128 : plci->ec_tail_length;
  11649. PUT_WORD (&parameter_buffer[4], w);
  11650. add_p (plci, FTY, parameter_buffer);
  11651. sig_req (plci, TEL_CTRL, 0);
  11652. send_req (plci);
  11653. }
  11654. static void ec_clear_config (PLCI *plci)
  11655. {
  11656. dbug (1, dprintf ("[%06lx] %s,%d: ec_clear_config",
  11657. (dword)((plci->Id << 8) | UnMapController (plci->adapter->Id)),
  11658. (char *)(FILE_), __LINE__));
  11659. plci->ec_idi_options = LEC_ENABLE_ECHO_CANCELLER |
  11660. LEC_MANUAL_DISABLE | LEC_ENABLE_NONLINEAR_PROCESSING;
  11661. plci->ec_tail_length = 0;
  11662. }
  11663. static void ec_prepare_switch (dword Id, PLCI *plci)
  11664. {
  11665. dbug (1, dprintf ("[%06lx] %s,%d: ec_prepare_switch",
  11666. UnMapId (Id), (char *)(FILE_), __LINE__));
  11667. }
  11668. static word ec_save_config (dword Id, PLCI *plci, byte Rc)
  11669. {
  11670. dbug (1, dprintf ("[%06lx] %s,%d: ec_save_config %02x %d",
  11671. UnMapId (Id), (char *)(FILE_), __LINE__, Rc, plci->adjust_b_state));
  11672. return (GOOD);
  11673. }
  11674. static word ec_restore_config (dword Id, PLCI *plci, byte Rc)
  11675. {
  11676. word Info;
  11677. dbug (1, dprintf ("[%06lx] %s,%d: ec_restore_config %02x %d",
  11678. UnMapId (Id), (char *)(FILE_), __LINE__, Rc, plci->adjust_b_state));
  11679. Info = GOOD;
  11680. if (plci->B1_facilities & B1_FACILITY_EC)
  11681. {
  11682. switch (plci->adjust_b_state)
  11683. {
  11684. case ADJUST_B_RESTORE_EC_1:
  11685. plci->internal_command = plci->adjust_b_command;
  11686. if (plci->sig_req)
  11687. {
  11688. plci->adjust_b_state = ADJUST_B_RESTORE_EC_1;
  11689. break;
  11690. }
  11691. ec_write_parameters (plci);
  11692. plci->adjust_b_state = ADJUST_B_RESTORE_EC_2;
  11693. break;
  11694. case ADJUST_B_RESTORE_EC_2:
  11695. if ((Rc != OK) && (Rc != OK_FC))
  11696. {
  11697. dbug (1, dprintf ("[%06lx] %s,%d: Restore EC failed %02x",
  11698. UnMapId (Id), (char *)(FILE_), __LINE__, Rc));
  11699. Info = _WRONG_STATE;
  11700. break;
  11701. }
  11702. break;
  11703. }
  11704. }
  11705. return (Info);
  11706. }
  11707. static void ec_command (dword Id, PLCI *plci, byte Rc)
  11708. {
  11709. word internal_command, Info;
  11710. byte result[8];
  11711. dbug (1, dprintf ("[%06lx] %s,%d: ec_command %02x %04x %04x %04x %d",
  11712. UnMapId (Id), (char *)(FILE_), __LINE__, Rc, plci->internal_command,
  11713. plci->ec_cmd, plci->ec_idi_options, plci->ec_tail_length));
  11714. Info = GOOD;
  11715. if (plci->appl->appl_flags & APPL_FLAG_PRIV_EC_SPEC)
  11716. {
  11717. result[0] = 2;
  11718. PUT_WORD (&result[1], EC_SUCCESS);
  11719. }
  11720. else
  11721. {
  11722. result[0] = 5;
  11723. PUT_WORD (&result[1], plci->ec_cmd);
  11724. result[3] = 2;
  11725. PUT_WORD (&result[4], GOOD);
  11726. }
  11727. internal_command = plci->internal_command;
  11728. plci->internal_command = 0;
  11729. switch (plci->ec_cmd)
  11730. {
  11731. case EC_ENABLE_OPERATION:
  11732. case EC_FREEZE_COEFFICIENTS:
  11733. case EC_RESUME_COEFFICIENT_UPDATE:
  11734. case EC_RESET_COEFFICIENTS:
  11735. switch (internal_command)
  11736. {
  11737. default:
  11738. adjust_b1_resource (Id, plci, NULL, (word)(plci->B1_facilities |
  11739. B1_FACILITY_EC), EC_COMMAND_1);
  11740. case EC_COMMAND_1:
  11741. if (adjust_b_process (Id, plci, Rc) != GOOD)
  11742. {
  11743. dbug (1, dprintf ("[%06lx] %s,%d: Load EC failed",
  11744. UnMapId (Id), (char *)(FILE_), __LINE__));
  11745. Info = _FACILITY_NOT_SUPPORTED;
  11746. break;
  11747. }
  11748. if (plci->internal_command)
  11749. return;
  11750. case EC_COMMAND_2:
  11751. if (plci->sig_req)
  11752. {
  11753. plci->internal_command = EC_COMMAND_2;
  11754. return;
  11755. }
  11756. plci->internal_command = EC_COMMAND_3;
  11757. ec_write_parameters (plci);
  11758. return;
  11759. case EC_COMMAND_3:
  11760. if ((Rc != OK) && (Rc != OK_FC))
  11761. {
  11762. dbug (1, dprintf ("[%06lx] %s,%d: Enable EC failed %02x",
  11763. UnMapId (Id), (char *)(FILE_), __LINE__, Rc));
  11764. Info = _FACILITY_NOT_SUPPORTED;
  11765. break;
  11766. }
  11767. break;
  11768. }
  11769. break;
  11770. case EC_DISABLE_OPERATION:
  11771. switch (internal_command)
  11772. {
  11773. default:
  11774. case EC_COMMAND_1:
  11775. if (plci->B1_facilities & B1_FACILITY_EC)
  11776. {
  11777. if (plci->sig_req)
  11778. {
  11779. plci->internal_command = EC_COMMAND_1;
  11780. return;
  11781. }
  11782. plci->internal_command = EC_COMMAND_2;
  11783. ec_write_parameters (plci);
  11784. return;
  11785. }
  11786. Rc = OK;
  11787. case EC_COMMAND_2:
  11788. if ((Rc != OK) && (Rc != OK_FC))
  11789. {
  11790. dbug (1, dprintf ("[%06lx] %s,%d: Disable EC failed %02x",
  11791. UnMapId (Id), (char *)(FILE_), __LINE__, Rc));
  11792. Info = _FACILITY_NOT_SUPPORTED;
  11793. break;
  11794. }
  11795. adjust_b1_resource (Id, plci, NULL, (word)(plci->B1_facilities &
  11796. ~B1_FACILITY_EC), EC_COMMAND_3);
  11797. case EC_COMMAND_3:
  11798. if (adjust_b_process (Id, plci, Rc) != GOOD)
  11799. {
  11800. dbug (1, dprintf ("[%06lx] %s,%d: Unload EC failed",
  11801. UnMapId (Id), (char *)(FILE_), __LINE__));
  11802. Info = _FACILITY_NOT_SUPPORTED;
  11803. break;
  11804. }
  11805. if (plci->internal_command)
  11806. return;
  11807. break;
  11808. }
  11809. break;
  11810. }
  11811. sendf (plci->appl, _FACILITY_R | CONFIRM, Id & 0xffffL, plci->number,
  11812. "wws", Info, (plci->appl->appl_flags & APPL_FLAG_PRIV_EC_SPEC) ?
  11813. PRIV_SELECTOR_ECHO_CANCELLER : SELECTOR_ECHO_CANCELLER, result);
  11814. }
  11815. static byte ec_request (dword Id, word Number, DIVA_CAPI_ADAPTER *a, PLCI *plci, APPL *appl, API_PARSE *msg)
  11816. {
  11817. word Info;
  11818. word opt;
  11819. API_PARSE ec_parms[3];
  11820. byte result[16];
  11821. dbug (1, dprintf ("[%06lx] %s,%d: ec_request",
  11822. UnMapId (Id), (char *)(FILE_), __LINE__));
  11823. Info = GOOD;
  11824. result[0] = 0;
  11825. if (!(a->man_profile.private_options & (1L << PRIVATE_ECHO_CANCELLER)))
  11826. {
  11827. dbug (1, dprintf ("[%06lx] %s,%d: Facility not supported",
  11828. UnMapId (Id), (char *)(FILE_), __LINE__));
  11829. Info = _FACILITY_NOT_SUPPORTED;
  11830. }
  11831. else
  11832. {
  11833. if (appl->appl_flags & APPL_FLAG_PRIV_EC_SPEC)
  11834. {
  11835. if (api_parse (&msg[1].info[1], msg[1].length, "w", ec_parms))
  11836. {
  11837. dbug (1, dprintf ("[%06lx] %s,%d: Wrong message format",
  11838. UnMapId (Id), (char *)(FILE_), __LINE__));
  11839. Info = _WRONG_MESSAGE_FORMAT;
  11840. }
  11841. else
  11842. {
  11843. if (plci == NULL)
  11844. {
  11845. dbug (1, dprintf ("[%06lx] %s,%d: Wrong PLCI",
  11846. UnMapId (Id), (char *)(FILE_), __LINE__));
  11847. Info = _WRONG_IDENTIFIER;
  11848. }
  11849. else if (!plci->State || !plci->NL.Id || plci->nl_remove_id)
  11850. {
  11851. dbug (1, dprintf ("[%06lx] %s,%d: Wrong state",
  11852. UnMapId (Id), (char *)(FILE_), __LINE__));
  11853. Info = _WRONG_STATE;
  11854. }
  11855. else
  11856. {
  11857. plci->command = 0;
  11858. plci->ec_cmd = GET_WORD (ec_parms[0].info);
  11859. plci->ec_idi_options &= ~(LEC_MANUAL_DISABLE | LEC_RESET_COEFFICIENTS);
  11860. result[0] = 2;
  11861. PUT_WORD (&result[1], EC_SUCCESS);
  11862. if (msg[1].length >= 4)
  11863. {
  11864. opt = GET_WORD (&ec_parms[0].info[2]);
  11865. plci->ec_idi_options &= ~(LEC_ENABLE_NONLINEAR_PROCESSING |
  11866. LEC_ENABLE_2100HZ_DETECTOR | LEC_REQUIRE_2100HZ_REVERSALS);
  11867. if (!(opt & EC_DISABLE_NON_LINEAR_PROCESSING))
  11868. plci->ec_idi_options |= LEC_ENABLE_NONLINEAR_PROCESSING;
  11869. if (opt & EC_DETECT_DISABLE_TONE)
  11870. plci->ec_idi_options |= LEC_ENABLE_2100HZ_DETECTOR;
  11871. if (!(opt & EC_DO_NOT_REQUIRE_REVERSALS))
  11872. plci->ec_idi_options |= LEC_REQUIRE_2100HZ_REVERSALS;
  11873. if (msg[1].length >= 6)
  11874. {
  11875. plci->ec_tail_length = GET_WORD (&ec_parms[0].info[4]);
  11876. }
  11877. }
  11878. switch (plci->ec_cmd)
  11879. {
  11880. case EC_ENABLE_OPERATION:
  11881. plci->ec_idi_options &= ~LEC_FREEZE_COEFFICIENTS;
  11882. start_internal_command (Id, plci, ec_command);
  11883. return (false);
  11884. case EC_DISABLE_OPERATION:
  11885. plci->ec_idi_options = LEC_ENABLE_ECHO_CANCELLER |
  11886. LEC_MANUAL_DISABLE | LEC_ENABLE_NONLINEAR_PROCESSING |
  11887. LEC_RESET_COEFFICIENTS;
  11888. start_internal_command (Id, plci, ec_command);
  11889. return (false);
  11890. case EC_FREEZE_COEFFICIENTS:
  11891. plci->ec_idi_options |= LEC_FREEZE_COEFFICIENTS;
  11892. start_internal_command (Id, plci, ec_command);
  11893. return (false);
  11894. case EC_RESUME_COEFFICIENT_UPDATE:
  11895. plci->ec_idi_options &= ~LEC_FREEZE_COEFFICIENTS;
  11896. start_internal_command (Id, plci, ec_command);
  11897. return (false);
  11898. case EC_RESET_COEFFICIENTS:
  11899. plci->ec_idi_options |= LEC_RESET_COEFFICIENTS;
  11900. start_internal_command (Id, plci, ec_command);
  11901. return (false);
  11902. default:
  11903. dbug (1, dprintf ("[%06lx] %s,%d: EC unknown request %04x",
  11904. UnMapId (Id), (char *)(FILE_), __LINE__, plci->ec_cmd));
  11905. PUT_WORD (&result[1], EC_UNSUPPORTED_OPERATION);
  11906. }
  11907. }
  11908. }
  11909. }
  11910. else
  11911. {
  11912. if (api_parse (&msg[1].info[1], msg[1].length, "ws", ec_parms))
  11913. {
  11914. dbug (1, dprintf ("[%06lx] %s,%d: Wrong message format",
  11915. UnMapId (Id), (char *)(FILE_), __LINE__));
  11916. Info = _WRONG_MESSAGE_FORMAT;
  11917. }
  11918. else
  11919. {
  11920. if (GET_WORD (ec_parms[0].info) == EC_GET_SUPPORTED_SERVICES)
  11921. {
  11922. result[0] = 11;
  11923. PUT_WORD (&result[1], EC_GET_SUPPORTED_SERVICES);
  11924. result[3] = 8;
  11925. PUT_WORD (&result[4], GOOD);
  11926. PUT_WORD (&result[6], 0x0007);
  11927. PUT_WORD (&result[8], LEC_MAX_SUPPORTED_TAIL_LENGTH);
  11928. PUT_WORD (&result[10], 0);
  11929. }
  11930. else if (plci == NULL)
  11931. {
  11932. dbug (1, dprintf ("[%06lx] %s,%d: Wrong PLCI",
  11933. UnMapId (Id), (char *)(FILE_), __LINE__));
  11934. Info = _WRONG_IDENTIFIER;
  11935. }
  11936. else if (!plci->State || !plci->NL.Id || plci->nl_remove_id)
  11937. {
  11938. dbug (1, dprintf ("[%06lx] %s,%d: Wrong state",
  11939. UnMapId (Id), (char *)(FILE_), __LINE__));
  11940. Info = _WRONG_STATE;
  11941. }
  11942. else
  11943. {
  11944. plci->command = 0;
  11945. plci->ec_cmd = GET_WORD (ec_parms[0].info);
  11946. plci->ec_idi_options &= ~(LEC_MANUAL_DISABLE | LEC_RESET_COEFFICIENTS);
  11947. result[0] = 5;
  11948. PUT_WORD (&result[1], plci->ec_cmd);
  11949. result[3] = 2;
  11950. PUT_WORD (&result[4], GOOD);
  11951. plci->ec_idi_options &= ~(LEC_ENABLE_NONLINEAR_PROCESSING |
  11952. LEC_ENABLE_2100HZ_DETECTOR | LEC_REQUIRE_2100HZ_REVERSALS);
  11953. plci->ec_tail_length = 0;
  11954. if (ec_parms[1].length >= 2)
  11955. {
  11956. opt = GET_WORD (&ec_parms[1].info[1]);
  11957. if (opt & EC_ENABLE_NON_LINEAR_PROCESSING)
  11958. plci->ec_idi_options |= LEC_ENABLE_NONLINEAR_PROCESSING;
  11959. if (opt & EC_DETECT_DISABLE_TONE)
  11960. plci->ec_idi_options |= LEC_ENABLE_2100HZ_DETECTOR;
  11961. if (!(opt & EC_DO_NOT_REQUIRE_REVERSALS))
  11962. plci->ec_idi_options |= LEC_REQUIRE_2100HZ_REVERSALS;
  11963. if (ec_parms[1].length >= 4)
  11964. {
  11965. plci->ec_tail_length = GET_WORD (&ec_parms[1].info[3]);
  11966. }
  11967. }
  11968. switch (plci->ec_cmd)
  11969. {
  11970. case EC_ENABLE_OPERATION:
  11971. plci->ec_idi_options &= ~LEC_FREEZE_COEFFICIENTS;
  11972. start_internal_command (Id, plci, ec_command);
  11973. return (false);
  11974. case EC_DISABLE_OPERATION:
  11975. plci->ec_idi_options = LEC_ENABLE_ECHO_CANCELLER |
  11976. LEC_MANUAL_DISABLE | LEC_ENABLE_NONLINEAR_PROCESSING |
  11977. LEC_RESET_COEFFICIENTS;
  11978. start_internal_command (Id, plci, ec_command);
  11979. return (false);
  11980. default:
  11981. dbug (1, dprintf ("[%06lx] %s,%d: EC unknown request %04x",
  11982. UnMapId (Id), (char *)(FILE_), __LINE__, plci->ec_cmd));
  11983. PUT_WORD (&result[4], _FACILITY_SPECIFIC_FUNCTION_NOT_SUPP);
  11984. }
  11985. }
  11986. }
  11987. }
  11988. }
  11989. sendf (appl, _FACILITY_R | CONFIRM, Id & 0xffffL, Number,
  11990. "wws", Info, (appl->appl_flags & APPL_FLAG_PRIV_EC_SPEC) ?
  11991. PRIV_SELECTOR_ECHO_CANCELLER : SELECTOR_ECHO_CANCELLER, result);
  11992. return (false);
  11993. }
  11994. static void ec_indication (dword Id, PLCI *plci, byte *msg, word length)
  11995. {
  11996. byte result[8];
  11997. dbug (1, dprintf ("[%06lx] %s,%d: ec_indication",
  11998. UnMapId (Id), (char *)(FILE_), __LINE__));
  11999. if (!(plci->ec_idi_options & LEC_MANUAL_DISABLE))
  12000. {
  12001. if (plci->appl->appl_flags & APPL_FLAG_PRIV_EC_SPEC)
  12002. {
  12003. result[0] = 2;
  12004. PUT_WORD (&result[1], 0);
  12005. switch (msg[1])
  12006. {
  12007. case LEC_DISABLE_TYPE_CONTIGNUOUS_2100HZ:
  12008. PUT_WORD (&result[1], EC_BYPASS_DUE_TO_CONTINUOUS_2100HZ);
  12009. break;
  12010. case LEC_DISABLE_TYPE_REVERSED_2100HZ:
  12011. PUT_WORD (&result[1], EC_BYPASS_DUE_TO_REVERSED_2100HZ);
  12012. break;
  12013. case LEC_DISABLE_RELEASED:
  12014. PUT_WORD (&result[1], EC_BYPASS_RELEASED);
  12015. break;
  12016. }
  12017. }
  12018. else
  12019. {
  12020. result[0] = 5;
  12021. PUT_WORD (&result[1], EC_BYPASS_INDICATION);
  12022. result[3] = 2;
  12023. PUT_WORD (&result[4], 0);
  12024. switch (msg[1])
  12025. {
  12026. case LEC_DISABLE_TYPE_CONTIGNUOUS_2100HZ:
  12027. PUT_WORD (&result[4], EC_BYPASS_DUE_TO_CONTINUOUS_2100HZ);
  12028. break;
  12029. case LEC_DISABLE_TYPE_REVERSED_2100HZ:
  12030. PUT_WORD (&result[4], EC_BYPASS_DUE_TO_REVERSED_2100HZ);
  12031. break;
  12032. case LEC_DISABLE_RELEASED:
  12033. PUT_WORD (&result[4], EC_BYPASS_RELEASED);
  12034. break;
  12035. }
  12036. }
  12037. sendf (plci->appl, _FACILITY_I, Id & 0xffffL, 0, "ws", (plci->appl->appl_flags & APPL_FLAG_PRIV_EC_SPEC) ?
  12038. PRIV_SELECTOR_ECHO_CANCELLER : SELECTOR_ECHO_CANCELLER, result);
  12039. }
  12040. }
  12041. /*------------------------------------------------------------------*/
  12042. /* Advanced voice */
  12043. /*------------------------------------------------------------------*/
  12044. static void adv_voice_write_coefs (PLCI *plci, word write_command)
  12045. {
  12046. DIVA_CAPI_ADAPTER *a;
  12047. word i;
  12048. byte *p;
  12049. word w, n, j, k;
  12050. byte ch_map[MIXER_CHANNELS_BRI];
  12051. byte coef_buffer[ADV_VOICE_COEF_BUFFER_SIZE + 2];
  12052. dbug (1, dprintf ("[%06lx] %s,%d: adv_voice_write_coefs %d",
  12053. (dword)((plci->Id << 8) | UnMapController (plci->adapter->Id)),
  12054. (char *)(FILE_), __LINE__, write_command));
  12055. a = plci->adapter;
  12056. p = coef_buffer + 1;
  12057. *(p++) = DSP_CTRL_OLD_SET_MIXER_COEFFICIENTS;
  12058. i = 0;
  12059. while (i + sizeof(word) <= a->adv_voice_coef_length)
  12060. {
  12061. PUT_WORD (p, GET_WORD (a->adv_voice_coef_buffer + i));
  12062. p += 2;
  12063. i += 2;
  12064. }
  12065. while (i < ADV_VOICE_OLD_COEF_COUNT * sizeof(word))
  12066. {
  12067. PUT_WORD (p, 0x8000);
  12068. p += 2;
  12069. i += 2;
  12070. }
  12071. if (!a->li_pri && (plci->li_bchannel_id == 0))
  12072. {
  12073. if ((li_config_table[a->li_base].plci == NULL) && (li_config_table[a->li_base + 1].plci != NULL))
  12074. {
  12075. plci->li_bchannel_id = 1;
  12076. li_config_table[a->li_base].plci = plci;
  12077. dbug (1, dprintf ("[%06lx] %s,%d: adv_voice_set_bchannel_id %d",
  12078. (dword)((plci->Id << 8) | UnMapController (plci->adapter->Id)),
  12079. (char *)(FILE_), __LINE__, plci->li_bchannel_id));
  12080. }
  12081. else if ((li_config_table[a->li_base].plci != NULL) && (li_config_table[a->li_base + 1].plci == NULL))
  12082. {
  12083. plci->li_bchannel_id = 2;
  12084. li_config_table[a->li_base + 1].plci = plci;
  12085. dbug (1, dprintf ("[%06lx] %s,%d: adv_voice_set_bchannel_id %d",
  12086. (dword)((plci->Id << 8) | UnMapController (plci->adapter->Id)),
  12087. (char *)(FILE_), __LINE__, plci->li_bchannel_id));
  12088. }
  12089. }
  12090. if (!a->li_pri && (plci->li_bchannel_id != 0)
  12091. && (li_config_table[a->li_base + (plci->li_bchannel_id - 1)].plci == plci))
  12092. {
  12093. i = a->li_base + (plci->li_bchannel_id - 1);
  12094. switch (write_command)
  12095. {
  12096. case ADV_VOICE_WRITE_ACTIVATION:
  12097. j = a->li_base + MIXER_IC_CHANNEL_BASE + (plci->li_bchannel_id - 1);
  12098. k = a->li_base + MIXER_IC_CHANNEL_BASE + (2 - plci->li_bchannel_id);
  12099. if (!(plci->B1_facilities & B1_FACILITY_MIXER))
  12100. {
  12101. li_config_table[j].flag_table[i] |= LI_FLAG_CONFERENCE | LI_FLAG_MIX;
  12102. li_config_table[i].flag_table[j] |= LI_FLAG_CONFERENCE | LI_FLAG_MONITOR;
  12103. }
  12104. if (a->manufacturer_features & MANUFACTURER_FEATURE_SLAVE_CODEC)
  12105. {
  12106. li_config_table[k].flag_table[i] |= LI_FLAG_CONFERENCE | LI_FLAG_MIX;
  12107. li_config_table[i].flag_table[k] |= LI_FLAG_CONFERENCE | LI_FLAG_MONITOR;
  12108. li_config_table[k].flag_table[j] |= LI_FLAG_CONFERENCE;
  12109. li_config_table[j].flag_table[k] |= LI_FLAG_CONFERENCE;
  12110. }
  12111. mixer_calculate_coefs (a);
  12112. li_config_table[i].curchnl = li_config_table[i].channel;
  12113. li_config_table[j].curchnl = li_config_table[j].channel;
  12114. if (a->manufacturer_features & MANUFACTURER_FEATURE_SLAVE_CODEC)
  12115. li_config_table[k].curchnl = li_config_table[k].channel;
  12116. break;
  12117. case ADV_VOICE_WRITE_DEACTIVATION:
  12118. for (j = 0; j < li_total_channels; j++)
  12119. {
  12120. li_config_table[i].flag_table[j] = 0;
  12121. li_config_table[j].flag_table[i] = 0;
  12122. }
  12123. k = a->li_base + MIXER_IC_CHANNEL_BASE + (plci->li_bchannel_id - 1);
  12124. for (j = 0; j < li_total_channels; j++)
  12125. {
  12126. li_config_table[k].flag_table[j] = 0;
  12127. li_config_table[j].flag_table[k] = 0;
  12128. }
  12129. if (a->manufacturer_features & MANUFACTURER_FEATURE_SLAVE_CODEC)
  12130. {
  12131. k = a->li_base + MIXER_IC_CHANNEL_BASE + (2 - plci->li_bchannel_id);
  12132. for (j = 0; j < li_total_channels; j++)
  12133. {
  12134. li_config_table[k].flag_table[j] = 0;
  12135. li_config_table[j].flag_table[k] = 0;
  12136. }
  12137. }
  12138. mixer_calculate_coefs (a);
  12139. break;
  12140. }
  12141. if (plci->B1_facilities & B1_FACILITY_MIXER)
  12142. {
  12143. w = 0;
  12144. if (ADV_VOICE_NEW_COEF_BASE + sizeof(word) <= a->adv_voice_coef_length)
  12145. w = GET_WORD (a->adv_voice_coef_buffer + ADV_VOICE_NEW_COEF_BASE);
  12146. if (li_config_table[i].channel & LI_CHANNEL_TX_DATA)
  12147. w |= MIXER_FEATURE_ENABLE_TX_DATA;
  12148. if (li_config_table[i].channel & LI_CHANNEL_RX_DATA)
  12149. w |= MIXER_FEATURE_ENABLE_RX_DATA;
  12150. *(p++) = (byte) w;
  12151. *(p++) = (byte)(w >> 8);
  12152. for (j = 0; j < sizeof(ch_map); j += 2)
  12153. {
  12154. ch_map[j] = (byte)(j + (plci->li_bchannel_id - 1));
  12155. ch_map[j+1] = (byte)(j + (2 - plci->li_bchannel_id));
  12156. }
  12157. for (n = 0; n < ARRAY_SIZE(mixer_write_prog_bri); n++)
  12158. {
  12159. i = a->li_base + ch_map[mixer_write_prog_bri[n].to_ch];
  12160. j = a->li_base + ch_map[mixer_write_prog_bri[n].from_ch];
  12161. if (li_config_table[i].channel & li_config_table[j].channel & LI_CHANNEL_INVOLVED)
  12162. {
  12163. *(p++) = ((li_config_table[i].coef_table[j] & mixer_write_prog_bri[n].mask) ? 0x80 : 0x01);
  12164. w = ((li_config_table[i].coef_table[j] & 0xf) ^ (li_config_table[i].coef_table[j] >> 4));
  12165. li_config_table[i].coef_table[j] ^= (w & mixer_write_prog_bri[n].mask) << 4;
  12166. }
  12167. else
  12168. {
  12169. *(p++) = (ADV_VOICE_NEW_COEF_BASE + sizeof(word) + n < a->adv_voice_coef_length) ?
  12170. a->adv_voice_coef_buffer[ADV_VOICE_NEW_COEF_BASE + sizeof(word) + n] : 0x00;
  12171. }
  12172. }
  12173. }
  12174. else
  12175. {
  12176. for (i = ADV_VOICE_NEW_COEF_BASE; i < a->adv_voice_coef_length; i++)
  12177. *(p++) = a->adv_voice_coef_buffer[i];
  12178. }
  12179. }
  12180. else
  12181. {
  12182. for (i = ADV_VOICE_NEW_COEF_BASE; i < a->adv_voice_coef_length; i++)
  12183. *(p++) = a->adv_voice_coef_buffer[i];
  12184. }
  12185. coef_buffer[0] = (p - coef_buffer) - 1;
  12186. add_p (plci, FTY, coef_buffer);
  12187. sig_req (plci, TEL_CTRL, 0);
  12188. send_req (plci);
  12189. }
  12190. static void adv_voice_clear_config (PLCI *plci)
  12191. {
  12192. DIVA_CAPI_ADAPTER *a;
  12193. word i, j;
  12194. dbug (1, dprintf ("[%06lx] %s,%d: adv_voice_clear_config",
  12195. (dword)((plci->Id << 8) | UnMapController (plci->adapter->Id)),
  12196. (char *)(FILE_), __LINE__));
  12197. a = plci->adapter;
  12198. if ((plci->tel == ADV_VOICE) && (plci == a->AdvSignalPLCI))
  12199. {
  12200. a->adv_voice_coef_length = 0;
  12201. if (!a->li_pri && (plci->li_bchannel_id != 0)
  12202. && (li_config_table[a->li_base + (plci->li_bchannel_id - 1)].plci == plci))
  12203. {
  12204. i = a->li_base + (plci->li_bchannel_id - 1);
  12205. li_config_table[i].curchnl = 0;
  12206. li_config_table[i].channel = 0;
  12207. li_config_table[i].chflags = 0;
  12208. for (j = 0; j < li_total_channels; j++)
  12209. {
  12210. li_config_table[i].flag_table[j] = 0;
  12211. li_config_table[j].flag_table[i] = 0;
  12212. li_config_table[i].coef_table[j] = 0;
  12213. li_config_table[j].coef_table[i] = 0;
  12214. }
  12215. li_config_table[i].coef_table[i] |= LI_COEF_CH_PC_SET | LI_COEF_PC_CH_SET;
  12216. i = a->li_base + MIXER_IC_CHANNEL_BASE + (plci->li_bchannel_id - 1);
  12217. li_config_table[i].curchnl = 0;
  12218. li_config_table[i].channel = 0;
  12219. li_config_table[i].chflags = 0;
  12220. for (j = 0; j < li_total_channels; j++)
  12221. {
  12222. li_config_table[i].flag_table[j] = 0;
  12223. li_config_table[j].flag_table[i] = 0;
  12224. li_config_table[i].coef_table[j] = 0;
  12225. li_config_table[j].coef_table[i] = 0;
  12226. }
  12227. if (a->manufacturer_features & MANUFACTURER_FEATURE_SLAVE_CODEC)
  12228. {
  12229. i = a->li_base + MIXER_IC_CHANNEL_BASE + (2 - plci->li_bchannel_id);
  12230. li_config_table[i].curchnl = 0;
  12231. li_config_table[i].channel = 0;
  12232. li_config_table[i].chflags = 0;
  12233. for (j = 0; j < li_total_channels; j++)
  12234. {
  12235. li_config_table[i].flag_table[j] = 0;
  12236. li_config_table[j].flag_table[i] = 0;
  12237. li_config_table[i].coef_table[j] = 0;
  12238. li_config_table[j].coef_table[i] = 0;
  12239. }
  12240. }
  12241. }
  12242. }
  12243. }
  12244. static void adv_voice_prepare_switch (dword Id, PLCI *plci)
  12245. {
  12246. dbug (1, dprintf ("[%06lx] %s,%d: adv_voice_prepare_switch",
  12247. UnMapId (Id), (char *)(FILE_), __LINE__));
  12248. }
  12249. static word adv_voice_save_config (dword Id, PLCI *plci, byte Rc)
  12250. {
  12251. dbug (1, dprintf ("[%06lx] %s,%d: adv_voice_save_config %02x %d",
  12252. UnMapId (Id), (char *)(FILE_), __LINE__, Rc, plci->adjust_b_state));
  12253. return (GOOD);
  12254. }
  12255. static word adv_voice_restore_config (dword Id, PLCI *plci, byte Rc)
  12256. {
  12257. DIVA_CAPI_ADAPTER *a;
  12258. word Info;
  12259. dbug (1, dprintf ("[%06lx] %s,%d: adv_voice_restore_config %02x %d",
  12260. UnMapId (Id), (char *)(FILE_), __LINE__, Rc, plci->adjust_b_state));
  12261. Info = GOOD;
  12262. a = plci->adapter;
  12263. if ((plci->B1_facilities & B1_FACILITY_VOICE)
  12264. && (plci->tel == ADV_VOICE) && (plci == a->AdvSignalPLCI))
  12265. {
  12266. switch (plci->adjust_b_state)
  12267. {
  12268. case ADJUST_B_RESTORE_VOICE_1:
  12269. plci->internal_command = plci->adjust_b_command;
  12270. if (plci->sig_req)
  12271. {
  12272. plci->adjust_b_state = ADJUST_B_RESTORE_VOICE_1;
  12273. break;
  12274. }
  12275. adv_voice_write_coefs (plci, ADV_VOICE_WRITE_UPDATE);
  12276. plci->adjust_b_state = ADJUST_B_RESTORE_VOICE_2;
  12277. break;
  12278. case ADJUST_B_RESTORE_VOICE_2:
  12279. if ((Rc != OK) && (Rc != OK_FC))
  12280. {
  12281. dbug (1, dprintf ("[%06lx] %s,%d: Restore voice config failed %02x",
  12282. UnMapId (Id), (char *)(FILE_), __LINE__, Rc));
  12283. Info = _WRONG_STATE;
  12284. break;
  12285. }
  12286. break;
  12287. }
  12288. }
  12289. return (Info);
  12290. }
  12291. /*------------------------------------------------------------------*/
  12292. /* B1 resource switching */
  12293. /*------------------------------------------------------------------*/
  12294. static byte b1_facilities_table[] =
  12295. {
  12296. 0x00, /* 0 No bchannel resources */
  12297. 0x00, /* 1 Codec (automatic law) */
  12298. 0x00, /* 2 Codec (A-law) */
  12299. 0x00, /* 3 Codec (y-law) */
  12300. 0x00, /* 4 HDLC for X.21 */
  12301. 0x00, /* 5 HDLC */
  12302. 0x00, /* 6 External Device 0 */
  12303. 0x00, /* 7 External Device 1 */
  12304. 0x00, /* 8 HDLC 56k */
  12305. 0x00, /* 9 Transparent */
  12306. 0x00, /* 10 Loopback to network */
  12307. 0x00, /* 11 Test pattern to net */
  12308. 0x00, /* 12 Rate adaptation sync */
  12309. 0x00, /* 13 Rate adaptation async */
  12310. 0x00, /* 14 R-Interface */
  12311. 0x00, /* 15 HDLC 128k leased line */
  12312. 0x00, /* 16 FAX */
  12313. 0x00, /* 17 Modem async */
  12314. 0x00, /* 18 Modem sync HDLC */
  12315. 0x00, /* 19 V.110 async HDLC */
  12316. 0x12, /* 20 Adv voice (Trans,mixer) */
  12317. 0x00, /* 21 Codec connected to IC */
  12318. 0x0c, /* 22 Trans,DTMF */
  12319. 0x1e, /* 23 Trans,DTMF+mixer */
  12320. 0x1f, /* 24 Trans,DTMF+mixer+local */
  12321. 0x13, /* 25 Trans,mixer+local */
  12322. 0x12, /* 26 HDLC,mixer */
  12323. 0x12, /* 27 HDLC 56k,mixer */
  12324. 0x2c, /* 28 Trans,LEC+DTMF */
  12325. 0x3e, /* 29 Trans,LEC+DTMF+mixer */
  12326. 0x3f, /* 30 Trans,LEC+DTMF+mixer+local */
  12327. 0x2c, /* 31 RTP,LEC+DTMF */
  12328. 0x3e, /* 32 RTP,LEC+DTMF+mixer */
  12329. 0x3f, /* 33 RTP,LEC+DTMF+mixer+local */
  12330. 0x00, /* 34 Signaling task */
  12331. 0x00, /* 35 PIAFS */
  12332. 0x0c, /* 36 Trans,DTMF+TONE */
  12333. 0x1e, /* 37 Trans,DTMF+TONE+mixer */
  12334. 0x1f /* 38 Trans,DTMF+TONE+mixer+local*/
  12335. };
  12336. static word get_b1_facilities (PLCI * plci, byte b1_resource)
  12337. {
  12338. word b1_facilities;
  12339. b1_facilities = b1_facilities_table[b1_resource];
  12340. if ((b1_resource == 9) || (b1_resource == 20) || (b1_resource == 25))
  12341. {
  12342. if (!(((plci->requested_options_conn | plci->requested_options) & (1L << PRIVATE_DTMF_TONE))
  12343. || (plci->appl && (plci->adapter->requested_options_table[plci->appl->Id-1] & (1L << PRIVATE_DTMF_TONE)))))
  12344. {
  12345. if (plci->adapter->manufacturer_features & MANUFACTURER_FEATURE_SOFTDTMF_SEND)
  12346. b1_facilities |= B1_FACILITY_DTMFX;
  12347. if (plci->adapter->manufacturer_features & MANUFACTURER_FEATURE_SOFTDTMF_RECEIVE)
  12348. b1_facilities |= B1_FACILITY_DTMFR;
  12349. }
  12350. }
  12351. if ((b1_resource == 17) || (b1_resource == 18))
  12352. {
  12353. if (plci->adapter->manufacturer_features & (MANUFACTURER_FEATURE_V18 | MANUFACTURER_FEATURE_VOWN))
  12354. b1_facilities |= B1_FACILITY_DTMFX | B1_FACILITY_DTMFR;
  12355. }
  12356. /*
  12357. dbug (1, dprintf ("[%06lx] %s,%d: get_b1_facilities %d %04x",
  12358. (dword)((plci->Id << 8) | UnMapController (plci->adapter->Id)),
  12359. (char far *)(FILE_), __LINE__, b1_resource, b1_facilites));
  12360. */
  12361. return (b1_facilities);
  12362. }
  12363. static byte add_b1_facilities (PLCI * plci, byte b1_resource, word b1_facilities)
  12364. {
  12365. byte b;
  12366. switch (b1_resource)
  12367. {
  12368. case 5:
  12369. case 26:
  12370. if (b1_facilities & (B1_FACILITY_MIXER | B1_FACILITY_VOICE))
  12371. b = 26;
  12372. else
  12373. b = 5;
  12374. break;
  12375. case 8:
  12376. case 27:
  12377. if (b1_facilities & (B1_FACILITY_MIXER | B1_FACILITY_VOICE))
  12378. b = 27;
  12379. else
  12380. b = 8;
  12381. break;
  12382. case 9:
  12383. case 20:
  12384. case 22:
  12385. case 23:
  12386. case 24:
  12387. case 25:
  12388. case 28:
  12389. case 29:
  12390. case 30:
  12391. case 36:
  12392. case 37:
  12393. case 38:
  12394. if (b1_facilities & B1_FACILITY_EC)
  12395. {
  12396. if (b1_facilities & B1_FACILITY_LOCAL)
  12397. b = 30;
  12398. else if (b1_facilities & (B1_FACILITY_MIXER | B1_FACILITY_VOICE))
  12399. b = 29;
  12400. else
  12401. b = 28;
  12402. }
  12403. else if ((b1_facilities & (B1_FACILITY_DTMFX | B1_FACILITY_DTMFR | B1_FACILITY_MIXER))
  12404. && (((plci->requested_options_conn | plci->requested_options) & (1L << PRIVATE_DTMF_TONE))
  12405. || (plci->appl && (plci->adapter->requested_options_table[plci->appl->Id-1] & (1L << PRIVATE_DTMF_TONE)))))
  12406. {
  12407. if (b1_facilities & B1_FACILITY_LOCAL)
  12408. b = 38;
  12409. else if (b1_facilities & (B1_FACILITY_MIXER | B1_FACILITY_VOICE))
  12410. b = 37;
  12411. else
  12412. b = 36;
  12413. }
  12414. else if (((plci->adapter->manufacturer_features & MANUFACTURER_FEATURE_HARDDTMF)
  12415. && !(plci->adapter->manufacturer_features & MANUFACTURER_FEATURE_SOFTDTMF_RECEIVE))
  12416. || ((b1_facilities & B1_FACILITY_DTMFR)
  12417. && ((b1_facilities & B1_FACILITY_MIXER)
  12418. || !(plci->adapter->manufacturer_features & MANUFACTURER_FEATURE_SOFTDTMF_RECEIVE)))
  12419. || ((b1_facilities & B1_FACILITY_DTMFX)
  12420. && ((b1_facilities & B1_FACILITY_MIXER)
  12421. || !(plci->adapter->manufacturer_features & MANUFACTURER_FEATURE_SOFTDTMF_SEND))))
  12422. {
  12423. if (b1_facilities & B1_FACILITY_LOCAL)
  12424. b = 24;
  12425. else if (b1_facilities & (B1_FACILITY_MIXER | B1_FACILITY_VOICE))
  12426. b = 23;
  12427. else
  12428. b = 22;
  12429. }
  12430. else
  12431. {
  12432. if (b1_facilities & B1_FACILITY_LOCAL)
  12433. b = 25;
  12434. else if (b1_facilities & (B1_FACILITY_MIXER | B1_FACILITY_VOICE))
  12435. b = 20;
  12436. else
  12437. b = 9;
  12438. }
  12439. break;
  12440. case 31:
  12441. case 32:
  12442. case 33:
  12443. if (b1_facilities & B1_FACILITY_LOCAL)
  12444. b = 33;
  12445. else if (b1_facilities & (B1_FACILITY_MIXER | B1_FACILITY_VOICE))
  12446. b = 32;
  12447. else
  12448. b = 31;
  12449. break;
  12450. default:
  12451. b = b1_resource;
  12452. }
  12453. dbug (1, dprintf ("[%06lx] %s,%d: add_b1_facilities %d %04x %d %04x",
  12454. (dword)((plci->Id << 8) | UnMapController (plci->adapter->Id)),
  12455. (char *)(FILE_), __LINE__,
  12456. b1_resource, b1_facilities, b, get_b1_facilities (plci, b)));
  12457. return (b);
  12458. }
  12459. static void adjust_b1_facilities (PLCI *plci, byte new_b1_resource, word new_b1_facilities)
  12460. {
  12461. word removed_facilities;
  12462. dbug (1, dprintf ("[%06lx] %s,%d: adjust_b1_facilities %d %04x %04x",
  12463. (dword)((plci->Id << 8) | UnMapController (plci->adapter->Id)),
  12464. (char *)(FILE_), __LINE__, new_b1_resource, new_b1_facilities,
  12465. new_b1_facilities & get_b1_facilities (plci, new_b1_resource)));
  12466. new_b1_facilities &= get_b1_facilities (plci, new_b1_resource);
  12467. removed_facilities = plci->B1_facilities & ~new_b1_facilities;
  12468. if (removed_facilities & B1_FACILITY_EC)
  12469. ec_clear_config (plci);
  12470. if (removed_facilities & B1_FACILITY_DTMFR)
  12471. {
  12472. dtmf_rec_clear_config (plci);
  12473. dtmf_parameter_clear_config (plci);
  12474. }
  12475. if (removed_facilities & B1_FACILITY_DTMFX)
  12476. dtmf_send_clear_config (plci);
  12477. if (removed_facilities & B1_FACILITY_MIXER)
  12478. mixer_clear_config (plci);
  12479. if (removed_facilities & B1_FACILITY_VOICE)
  12480. adv_voice_clear_config (plci);
  12481. plci->B1_facilities = new_b1_facilities;
  12482. }
  12483. static void adjust_b_clear (PLCI *plci)
  12484. {
  12485. dbug (1, dprintf ("[%06lx] %s,%d: adjust_b_clear",
  12486. (dword)((plci->Id << 8) | UnMapController (plci->adapter->Id)),
  12487. (char *)(FILE_), __LINE__));
  12488. plci->adjust_b_restore = false;
  12489. }
  12490. static word adjust_b_process (dword Id, PLCI *plci, byte Rc)
  12491. {
  12492. word Info;
  12493. byte b1_resource;
  12494. NCCI * ncci_ptr;
  12495. API_PARSE bp[2];
  12496. dbug (1, dprintf ("[%06lx] %s,%d: adjust_b_process %02x %d",
  12497. UnMapId (Id), (char *)(FILE_), __LINE__, Rc, plci->adjust_b_state));
  12498. Info = GOOD;
  12499. switch (plci->adjust_b_state)
  12500. {
  12501. case ADJUST_B_START:
  12502. if ((plci->adjust_b_parms_msg == NULL)
  12503. && (plci->adjust_b_mode & ADJUST_B_MODE_SWITCH_L1)
  12504. && ((plci->adjust_b_mode & ~(ADJUST_B_MODE_SAVE | ADJUST_B_MODE_SWITCH_L1 |
  12505. ADJUST_B_MODE_NO_RESOURCE | ADJUST_B_MODE_RESTORE)) == 0))
  12506. {
  12507. b1_resource = (plci->adjust_b_mode == ADJUST_B_MODE_NO_RESOURCE) ?
  12508. 0 : add_b1_facilities (plci, plci->B1_resource, plci->adjust_b_facilities);
  12509. if (b1_resource == plci->B1_resource)
  12510. {
  12511. adjust_b1_facilities (plci, b1_resource, plci->adjust_b_facilities);
  12512. break;
  12513. }
  12514. if (plci->adjust_b_facilities & ~get_b1_facilities (plci, b1_resource))
  12515. {
  12516. dbug (1, dprintf ("[%06lx] %s,%d: Adjust B nonsupported facilities %d %d %04x",
  12517. UnMapId (Id), (char *)(FILE_), __LINE__,
  12518. plci->B1_resource, b1_resource, plci->adjust_b_facilities));
  12519. Info = _WRONG_STATE;
  12520. break;
  12521. }
  12522. }
  12523. if (plci->adjust_b_mode & ADJUST_B_MODE_SAVE)
  12524. {
  12525. mixer_prepare_switch (Id, plci);
  12526. dtmf_prepare_switch (Id, plci);
  12527. dtmf_parameter_prepare_switch (Id, plci);
  12528. ec_prepare_switch (Id, plci);
  12529. adv_voice_prepare_switch (Id, plci);
  12530. }
  12531. plci->adjust_b_state = ADJUST_B_SAVE_MIXER_1;
  12532. Rc = OK;
  12533. case ADJUST_B_SAVE_MIXER_1:
  12534. if (plci->adjust_b_mode & ADJUST_B_MODE_SAVE)
  12535. {
  12536. Info = mixer_save_config (Id, plci, Rc);
  12537. if ((Info != GOOD) || plci->internal_command)
  12538. break;
  12539. }
  12540. plci->adjust_b_state = ADJUST_B_SAVE_DTMF_1;
  12541. Rc = OK;
  12542. case ADJUST_B_SAVE_DTMF_1:
  12543. if (plci->adjust_b_mode & ADJUST_B_MODE_SAVE)
  12544. {
  12545. Info = dtmf_save_config (Id, plci, Rc);
  12546. if ((Info != GOOD) || plci->internal_command)
  12547. break;
  12548. }
  12549. plci->adjust_b_state = ADJUST_B_REMOVE_L23_1;
  12550. case ADJUST_B_REMOVE_L23_1:
  12551. if ((plci->adjust_b_mode & ADJUST_B_MODE_REMOVE_L23)
  12552. && plci->NL.Id && !plci->nl_remove_id)
  12553. {
  12554. plci->internal_command = plci->adjust_b_command;
  12555. if (plci->adjust_b_ncci != 0)
  12556. {
  12557. ncci_ptr = &(plci->adapter->ncci[plci->adjust_b_ncci]);
  12558. while (ncci_ptr->data_pending)
  12559. {
  12560. plci->data_sent_ptr = ncci_ptr->DBuffer[ncci_ptr->data_out].P;
  12561. data_rc (plci, plci->adapter->ncci_ch[plci->adjust_b_ncci]);
  12562. }
  12563. while (ncci_ptr->data_ack_pending)
  12564. data_ack (plci, plci->adapter->ncci_ch[plci->adjust_b_ncci]);
  12565. }
  12566. nl_req_ncci (plci, REMOVE,
  12567. (byte)((plci->adjust_b_mode & ADJUST_B_MODE_CONNECT) ? plci->adjust_b_ncci : 0));
  12568. send_req (plci);
  12569. plci->adjust_b_state = ADJUST_B_REMOVE_L23_2;
  12570. break;
  12571. }
  12572. plci->adjust_b_state = ADJUST_B_REMOVE_L23_2;
  12573. Rc = OK;
  12574. case ADJUST_B_REMOVE_L23_2:
  12575. if ((Rc != OK) && (Rc != OK_FC))
  12576. {
  12577. dbug (1, dprintf ("[%06lx] %s,%d: Adjust B remove failed %02x",
  12578. UnMapId (Id), (char *)(FILE_), __LINE__, Rc));
  12579. Info = _WRONG_STATE;
  12580. break;
  12581. }
  12582. if (plci->adjust_b_mode & ADJUST_B_MODE_REMOVE_L23)
  12583. {
  12584. if (plci_nl_busy (plci))
  12585. {
  12586. plci->internal_command = plci->adjust_b_command;
  12587. break;
  12588. }
  12589. }
  12590. plci->adjust_b_state = ADJUST_B_SAVE_EC_1;
  12591. Rc = OK;
  12592. case ADJUST_B_SAVE_EC_1:
  12593. if (plci->adjust_b_mode & ADJUST_B_MODE_SAVE)
  12594. {
  12595. Info = ec_save_config (Id, plci, Rc);
  12596. if ((Info != GOOD) || plci->internal_command)
  12597. break;
  12598. }
  12599. plci->adjust_b_state = ADJUST_B_SAVE_DTMF_PARAMETER_1;
  12600. Rc = OK;
  12601. case ADJUST_B_SAVE_DTMF_PARAMETER_1:
  12602. if (plci->adjust_b_mode & ADJUST_B_MODE_SAVE)
  12603. {
  12604. Info = dtmf_parameter_save_config (Id, plci, Rc);
  12605. if ((Info != GOOD) || plci->internal_command)
  12606. break;
  12607. }
  12608. plci->adjust_b_state = ADJUST_B_SAVE_VOICE_1;
  12609. Rc = OK;
  12610. case ADJUST_B_SAVE_VOICE_1:
  12611. if (plci->adjust_b_mode & ADJUST_B_MODE_SAVE)
  12612. {
  12613. Info = adv_voice_save_config (Id, plci, Rc);
  12614. if ((Info != GOOD) || plci->internal_command)
  12615. break;
  12616. }
  12617. plci->adjust_b_state = ADJUST_B_SWITCH_L1_1;
  12618. case ADJUST_B_SWITCH_L1_1:
  12619. if (plci->adjust_b_mode & ADJUST_B_MODE_SWITCH_L1)
  12620. {
  12621. if (plci->sig_req)
  12622. {
  12623. plci->internal_command = plci->adjust_b_command;
  12624. break;
  12625. }
  12626. if (plci->adjust_b_parms_msg != NULL)
  12627. api_load_msg (plci->adjust_b_parms_msg, bp);
  12628. else
  12629. api_load_msg (&plci->B_protocol, bp);
  12630. Info = add_b1 (plci, bp,
  12631. (word)((plci->adjust_b_mode & ADJUST_B_MODE_NO_RESOURCE) ? 2 : 0),
  12632. plci->adjust_b_facilities);
  12633. if (Info != GOOD)
  12634. {
  12635. dbug (1, dprintf ("[%06lx] %s,%d: Adjust B invalid L1 parameters %d %04x",
  12636. UnMapId (Id), (char *)(FILE_), __LINE__,
  12637. plci->B1_resource, plci->adjust_b_facilities));
  12638. break;
  12639. }
  12640. plci->internal_command = plci->adjust_b_command;
  12641. sig_req (plci, RESOURCES, 0);
  12642. send_req (plci);
  12643. plci->adjust_b_state = ADJUST_B_SWITCH_L1_2;
  12644. break;
  12645. }
  12646. plci->adjust_b_state = ADJUST_B_SWITCH_L1_2;
  12647. Rc = OK;
  12648. case ADJUST_B_SWITCH_L1_2:
  12649. if ((Rc != OK) && (Rc != OK_FC))
  12650. {
  12651. dbug (1, dprintf ("[%06lx] %s,%d: Adjust B switch failed %02x %d %04x",
  12652. UnMapId (Id), (char *)(FILE_), __LINE__,
  12653. Rc, plci->B1_resource, plci->adjust_b_facilities));
  12654. Info = _WRONG_STATE;
  12655. break;
  12656. }
  12657. plci->adjust_b_state = ADJUST_B_RESTORE_VOICE_1;
  12658. Rc = OK;
  12659. case ADJUST_B_RESTORE_VOICE_1:
  12660. case ADJUST_B_RESTORE_VOICE_2:
  12661. if (plci->adjust_b_mode & ADJUST_B_MODE_RESTORE)
  12662. {
  12663. Info = adv_voice_restore_config (Id, plci, Rc);
  12664. if ((Info != GOOD) || plci->internal_command)
  12665. break;
  12666. }
  12667. plci->adjust_b_state = ADJUST_B_RESTORE_DTMF_PARAMETER_1;
  12668. Rc = OK;
  12669. case ADJUST_B_RESTORE_DTMF_PARAMETER_1:
  12670. case ADJUST_B_RESTORE_DTMF_PARAMETER_2:
  12671. if (plci->adjust_b_mode & ADJUST_B_MODE_RESTORE)
  12672. {
  12673. Info = dtmf_parameter_restore_config (Id, plci, Rc);
  12674. if ((Info != GOOD) || plci->internal_command)
  12675. break;
  12676. }
  12677. plci->adjust_b_state = ADJUST_B_RESTORE_EC_1;
  12678. Rc = OK;
  12679. case ADJUST_B_RESTORE_EC_1:
  12680. case ADJUST_B_RESTORE_EC_2:
  12681. if (plci->adjust_b_mode & ADJUST_B_MODE_RESTORE)
  12682. {
  12683. Info = ec_restore_config (Id, plci, Rc);
  12684. if ((Info != GOOD) || plci->internal_command)
  12685. break;
  12686. }
  12687. plci->adjust_b_state = ADJUST_B_ASSIGN_L23_1;
  12688. case ADJUST_B_ASSIGN_L23_1:
  12689. if (plci->adjust_b_mode & ADJUST_B_MODE_ASSIGN_L23)
  12690. {
  12691. if (plci_nl_busy (plci))
  12692. {
  12693. plci->internal_command = plci->adjust_b_command;
  12694. break;
  12695. }
  12696. if (plci->adjust_b_mode & ADJUST_B_MODE_CONNECT)
  12697. plci->call_dir |= CALL_DIR_FORCE_OUTG_NL;
  12698. if (plci->adjust_b_parms_msg != NULL)
  12699. api_load_msg (plci->adjust_b_parms_msg, bp);
  12700. else
  12701. api_load_msg (&plci->B_protocol, bp);
  12702. Info = add_b23 (plci, bp);
  12703. if (Info != GOOD)
  12704. {
  12705. dbug (1, dprintf ("[%06lx] %s,%d: Adjust B invalid L23 parameters %04x",
  12706. UnMapId (Id), (char *)(FILE_), __LINE__, Info));
  12707. break;
  12708. }
  12709. plci->internal_command = plci->adjust_b_command;
  12710. nl_req_ncci (plci, ASSIGN, 0);
  12711. send_req (plci);
  12712. plci->adjust_b_state = ADJUST_B_ASSIGN_L23_2;
  12713. break;
  12714. }
  12715. plci->adjust_b_state = ADJUST_B_ASSIGN_L23_2;
  12716. Rc = ASSIGN_OK;
  12717. case ADJUST_B_ASSIGN_L23_2:
  12718. if ((Rc != OK) && (Rc != OK_FC) && (Rc != ASSIGN_OK))
  12719. {
  12720. dbug (1, dprintf ("[%06lx] %s,%d: Adjust B assign failed %02x",
  12721. UnMapId (Id), (char *)(FILE_), __LINE__, Rc));
  12722. Info = _WRONG_STATE;
  12723. break;
  12724. }
  12725. if (plci->adjust_b_mode & ADJUST_B_MODE_ASSIGN_L23)
  12726. {
  12727. if (Rc != ASSIGN_OK)
  12728. {
  12729. plci->internal_command = plci->adjust_b_command;
  12730. break;
  12731. }
  12732. }
  12733. if (plci->adjust_b_mode & ADJUST_B_MODE_USER_CONNECT)
  12734. {
  12735. plci->adjust_b_restore = true;
  12736. break;
  12737. }
  12738. plci->adjust_b_state = ADJUST_B_CONNECT_1;
  12739. case ADJUST_B_CONNECT_1:
  12740. if (plci->adjust_b_mode & ADJUST_B_MODE_CONNECT)
  12741. {
  12742. plci->internal_command = plci->adjust_b_command;
  12743. if (plci_nl_busy (plci))
  12744. break;
  12745. nl_req_ncci (plci, N_CONNECT, 0);
  12746. send_req (plci);
  12747. plci->adjust_b_state = ADJUST_B_CONNECT_2;
  12748. break;
  12749. }
  12750. plci->adjust_b_state = ADJUST_B_RESTORE_DTMF_1;
  12751. Rc = OK;
  12752. case ADJUST_B_CONNECT_2:
  12753. case ADJUST_B_CONNECT_3:
  12754. case ADJUST_B_CONNECT_4:
  12755. if ((Rc != OK) && (Rc != OK_FC) && (Rc != 0))
  12756. {
  12757. dbug (1, dprintf ("[%06lx] %s,%d: Adjust B connect failed %02x",
  12758. UnMapId (Id), (char *)(FILE_), __LINE__, Rc));
  12759. Info = _WRONG_STATE;
  12760. break;
  12761. }
  12762. if (Rc == OK)
  12763. {
  12764. if (plci->adjust_b_mode & ADJUST_B_MODE_CONNECT)
  12765. {
  12766. get_ncci (plci, (byte)(Id >> 16), plci->adjust_b_ncci);
  12767. Id = (Id & 0xffff) | (((dword)(plci->adjust_b_ncci)) << 16);
  12768. }
  12769. if (plci->adjust_b_state == ADJUST_B_CONNECT_2)
  12770. plci->adjust_b_state = ADJUST_B_CONNECT_3;
  12771. else if (plci->adjust_b_state == ADJUST_B_CONNECT_4)
  12772. plci->adjust_b_state = ADJUST_B_RESTORE_DTMF_1;
  12773. }
  12774. else if (Rc == 0)
  12775. {
  12776. if (plci->adjust_b_state == ADJUST_B_CONNECT_2)
  12777. plci->adjust_b_state = ADJUST_B_CONNECT_4;
  12778. else if (plci->adjust_b_state == ADJUST_B_CONNECT_3)
  12779. plci->adjust_b_state = ADJUST_B_RESTORE_DTMF_1;
  12780. }
  12781. if (plci->adjust_b_state != ADJUST_B_RESTORE_DTMF_1)
  12782. {
  12783. plci->internal_command = plci->adjust_b_command;
  12784. break;
  12785. }
  12786. Rc = OK;
  12787. case ADJUST_B_RESTORE_DTMF_1:
  12788. case ADJUST_B_RESTORE_DTMF_2:
  12789. if (plci->adjust_b_mode & ADJUST_B_MODE_RESTORE)
  12790. {
  12791. Info = dtmf_restore_config (Id, plci, Rc);
  12792. if ((Info != GOOD) || plci->internal_command)
  12793. break;
  12794. }
  12795. plci->adjust_b_state = ADJUST_B_RESTORE_MIXER_1;
  12796. Rc = OK;
  12797. case ADJUST_B_RESTORE_MIXER_1:
  12798. case ADJUST_B_RESTORE_MIXER_2:
  12799. case ADJUST_B_RESTORE_MIXER_3:
  12800. case ADJUST_B_RESTORE_MIXER_4:
  12801. case ADJUST_B_RESTORE_MIXER_5:
  12802. case ADJUST_B_RESTORE_MIXER_6:
  12803. case ADJUST_B_RESTORE_MIXER_7:
  12804. if (plci->adjust_b_mode & ADJUST_B_MODE_RESTORE)
  12805. {
  12806. Info = mixer_restore_config (Id, plci, Rc);
  12807. if ((Info != GOOD) || plci->internal_command)
  12808. break;
  12809. }
  12810. plci->adjust_b_state = ADJUST_B_END;
  12811. case ADJUST_B_END:
  12812. break;
  12813. }
  12814. return (Info);
  12815. }
  12816. static void adjust_b1_resource (dword Id, PLCI *plci, API_SAVE *bp_msg, word b1_facilities, word internal_command)
  12817. {
  12818. dbug (1, dprintf ("[%06lx] %s,%d: adjust_b1_resource %d %04x",
  12819. UnMapId (Id), (char *)(FILE_), __LINE__,
  12820. plci->B1_resource, b1_facilities));
  12821. plci->adjust_b_parms_msg = bp_msg;
  12822. plci->adjust_b_facilities = b1_facilities;
  12823. plci->adjust_b_command = internal_command;
  12824. plci->adjust_b_ncci = (word)(Id >> 16);
  12825. if ((bp_msg == NULL) && (plci->B1_resource == 0))
  12826. plci->adjust_b_mode = ADJUST_B_MODE_SAVE | ADJUST_B_MODE_NO_RESOURCE | ADJUST_B_MODE_SWITCH_L1;
  12827. else
  12828. plci->adjust_b_mode = ADJUST_B_MODE_SAVE | ADJUST_B_MODE_SWITCH_L1 | ADJUST_B_MODE_RESTORE;
  12829. plci->adjust_b_state = ADJUST_B_START;
  12830. dbug (1, dprintf ("[%06lx] %s,%d: Adjust B1 resource %d %04x...",
  12831. UnMapId (Id), (char *)(FILE_), __LINE__,
  12832. plci->B1_resource, b1_facilities));
  12833. }
  12834. static void adjust_b_restore (dword Id, PLCI *plci, byte Rc)
  12835. {
  12836. word internal_command;
  12837. dbug (1, dprintf ("[%06lx] %s,%d: adjust_b_restore %02x %04x",
  12838. UnMapId (Id), (char *)(FILE_), __LINE__, Rc, plci->internal_command));
  12839. internal_command = plci->internal_command;
  12840. plci->internal_command = 0;
  12841. switch (internal_command)
  12842. {
  12843. default:
  12844. plci->command = 0;
  12845. if (plci->req_in != 0)
  12846. {
  12847. plci->internal_command = ADJUST_B_RESTORE_1;
  12848. break;
  12849. }
  12850. Rc = OK;
  12851. case ADJUST_B_RESTORE_1:
  12852. if ((Rc != OK) && (Rc != OK_FC))
  12853. {
  12854. dbug (1, dprintf ("[%06lx] %s,%d: Adjust B enqueued failed %02x",
  12855. UnMapId (Id), (char *)(FILE_), __LINE__, Rc));
  12856. }
  12857. plci->adjust_b_parms_msg = NULL;
  12858. plci->adjust_b_facilities = plci->B1_facilities;
  12859. plci->adjust_b_command = ADJUST_B_RESTORE_2;
  12860. plci->adjust_b_ncci = (word)(Id >> 16);
  12861. plci->adjust_b_mode = ADJUST_B_MODE_RESTORE;
  12862. plci->adjust_b_state = ADJUST_B_START;
  12863. dbug (1, dprintf ("[%06lx] %s,%d: Adjust B restore...",
  12864. UnMapId (Id), (char *)(FILE_), __LINE__));
  12865. case ADJUST_B_RESTORE_2:
  12866. if (adjust_b_process (Id, plci, Rc) != GOOD)
  12867. {
  12868. dbug (1, dprintf ("[%06lx] %s,%d: Adjust B restore failed",
  12869. UnMapId (Id), (char *)(FILE_), __LINE__));
  12870. }
  12871. if (plci->internal_command)
  12872. break;
  12873. break;
  12874. }
  12875. }
  12876. static void reset_b3_command (dword Id, PLCI *plci, byte Rc)
  12877. {
  12878. word Info;
  12879. word internal_command;
  12880. dbug (1, dprintf ("[%06lx] %s,%d: reset_b3_command %02x %04x",
  12881. UnMapId (Id), (char *)(FILE_), __LINE__, Rc, plci->internal_command));
  12882. Info = GOOD;
  12883. internal_command = plci->internal_command;
  12884. plci->internal_command = 0;
  12885. switch (internal_command)
  12886. {
  12887. default:
  12888. plci->command = 0;
  12889. plci->adjust_b_parms_msg = NULL;
  12890. plci->adjust_b_facilities = plci->B1_facilities;
  12891. plci->adjust_b_command = RESET_B3_COMMAND_1;
  12892. plci->adjust_b_ncci = (word)(Id >> 16);
  12893. plci->adjust_b_mode = ADJUST_B_MODE_REMOVE_L23 | ADJUST_B_MODE_ASSIGN_L23 | ADJUST_B_MODE_CONNECT;
  12894. plci->adjust_b_state = ADJUST_B_START;
  12895. dbug (1, dprintf ("[%06lx] %s,%d: Reset B3...",
  12896. UnMapId (Id), (char *)(FILE_), __LINE__));
  12897. case RESET_B3_COMMAND_1:
  12898. Info = adjust_b_process (Id, plci, Rc);
  12899. if (Info != GOOD)
  12900. {
  12901. dbug (1, dprintf ("[%06lx] %s,%d: Reset failed",
  12902. UnMapId (Id), (char *)(FILE_), __LINE__));
  12903. break;
  12904. }
  12905. if (plci->internal_command)
  12906. return;
  12907. break;
  12908. }
  12909. /* sendf (plci->appl, _RESET_B3_R | CONFIRM, Id, plci->number, "w", Info);*/
  12910. sendf(plci->appl,_RESET_B3_I,Id,0,"s","");
  12911. }
  12912. static void select_b_command (dword Id, PLCI *plci, byte Rc)
  12913. {
  12914. word Info;
  12915. word internal_command;
  12916. byte esc_chi[3];
  12917. dbug (1, dprintf ("[%06lx] %s,%d: select_b_command %02x %04x",
  12918. UnMapId (Id), (char *)(FILE_), __LINE__, Rc, plci->internal_command));
  12919. Info = GOOD;
  12920. internal_command = plci->internal_command;
  12921. plci->internal_command = 0;
  12922. switch (internal_command)
  12923. {
  12924. default:
  12925. plci->command = 0;
  12926. plci->adjust_b_parms_msg = &plci->saved_msg;
  12927. if ((plci->tel == ADV_VOICE) && (plci == plci->adapter->AdvSignalPLCI))
  12928. plci->adjust_b_facilities = plci->B1_facilities | B1_FACILITY_VOICE;
  12929. else
  12930. plci->adjust_b_facilities = plci->B1_facilities & ~B1_FACILITY_VOICE;
  12931. plci->adjust_b_command = SELECT_B_COMMAND_1;
  12932. plci->adjust_b_ncci = (word)(Id >> 16);
  12933. if (plci->saved_msg.parms[0].length == 0)
  12934. {
  12935. plci->adjust_b_mode = ADJUST_B_MODE_SAVE | ADJUST_B_MODE_REMOVE_L23 | ADJUST_B_MODE_SWITCH_L1 |
  12936. ADJUST_B_MODE_NO_RESOURCE;
  12937. }
  12938. else
  12939. {
  12940. plci->adjust_b_mode = ADJUST_B_MODE_SAVE | ADJUST_B_MODE_REMOVE_L23 | ADJUST_B_MODE_SWITCH_L1 |
  12941. ADJUST_B_MODE_ASSIGN_L23 | ADJUST_B_MODE_USER_CONNECT | ADJUST_B_MODE_RESTORE;
  12942. }
  12943. plci->adjust_b_state = ADJUST_B_START;
  12944. dbug (1, dprintf ("[%06lx] %s,%d: Select B protocol...",
  12945. UnMapId (Id), (char *)(FILE_), __LINE__));
  12946. case SELECT_B_COMMAND_1:
  12947. Info = adjust_b_process (Id, plci, Rc);
  12948. if (Info != GOOD)
  12949. {
  12950. dbug (1, dprintf ("[%06lx] %s,%d: Select B protocol failed",
  12951. UnMapId (Id), (char *)(FILE_), __LINE__));
  12952. break;
  12953. }
  12954. if (plci->internal_command)
  12955. return;
  12956. if (plci->tel == ADV_VOICE)
  12957. {
  12958. esc_chi[0] = 0x02;
  12959. esc_chi[1] = 0x18;
  12960. esc_chi[2] = plci->b_channel;
  12961. SetVoiceChannel (plci->adapter->AdvCodecPLCI, esc_chi, plci->adapter);
  12962. }
  12963. break;
  12964. }
  12965. sendf (plci->appl, _SELECT_B_REQ | CONFIRM, Id, plci->number, "w", Info);
  12966. }
  12967. static void fax_connect_ack_command (dword Id, PLCI *plci, byte Rc)
  12968. {
  12969. word Info;
  12970. word internal_command;
  12971. dbug (1, dprintf ("[%06lx] %s,%d: fax_connect_ack_command %02x %04x",
  12972. UnMapId (Id), (char *)(FILE_), __LINE__, Rc, plci->internal_command));
  12973. Info = GOOD;
  12974. internal_command = plci->internal_command;
  12975. plci->internal_command = 0;
  12976. switch (internal_command)
  12977. {
  12978. default:
  12979. plci->command = 0;
  12980. case FAX_CONNECT_ACK_COMMAND_1:
  12981. if (plci_nl_busy (plci))
  12982. {
  12983. plci->internal_command = FAX_CONNECT_ACK_COMMAND_1;
  12984. return;
  12985. }
  12986. plci->internal_command = FAX_CONNECT_ACK_COMMAND_2;
  12987. plci->NData[0].P = plci->fax_connect_info_buffer;
  12988. plci->NData[0].PLength = plci->fax_connect_info_length;
  12989. plci->NL.X = plci->NData;
  12990. plci->NL.ReqCh = 0;
  12991. plci->NL.Req = plci->nl_req = (byte) N_CONNECT_ACK;
  12992. plci->adapter->request (&plci->NL);
  12993. return;
  12994. case FAX_CONNECT_ACK_COMMAND_2:
  12995. if ((Rc != OK) && (Rc != OK_FC))
  12996. {
  12997. dbug (1, dprintf ("[%06lx] %s,%d: FAX issue CONNECT ACK failed %02x",
  12998. UnMapId (Id), (char *)(FILE_), __LINE__, Rc));
  12999. break;
  13000. }
  13001. }
  13002. if ((plci->ncpi_state & NCPI_VALID_CONNECT_B3_ACT)
  13003. && !(plci->ncpi_state & NCPI_CONNECT_B3_ACT_SENT))
  13004. {
  13005. if (plci->B3_prot == 4)
  13006. sendf(plci->appl,_CONNECT_B3_ACTIVE_I,Id,0,"s","");
  13007. else
  13008. sendf(plci->appl,_CONNECT_B3_ACTIVE_I,Id,0,"S",plci->ncpi_buffer);
  13009. plci->ncpi_state |= NCPI_CONNECT_B3_ACT_SENT;
  13010. }
  13011. }
  13012. static void fax_edata_ack_command (dword Id, PLCI *plci, byte Rc)
  13013. {
  13014. word Info;
  13015. word internal_command;
  13016. dbug (1, dprintf ("[%06lx] %s,%d: fax_edata_ack_command %02x %04x",
  13017. UnMapId (Id), (char *)(FILE_), __LINE__, Rc, plci->internal_command));
  13018. Info = GOOD;
  13019. internal_command = plci->internal_command;
  13020. plci->internal_command = 0;
  13021. switch (internal_command)
  13022. {
  13023. default:
  13024. plci->command = 0;
  13025. case FAX_EDATA_ACK_COMMAND_1:
  13026. if (plci_nl_busy (plci))
  13027. {
  13028. plci->internal_command = FAX_EDATA_ACK_COMMAND_1;
  13029. return;
  13030. }
  13031. plci->internal_command = FAX_EDATA_ACK_COMMAND_2;
  13032. plci->NData[0].P = plci->fax_connect_info_buffer;
  13033. plci->NData[0].PLength = plci->fax_edata_ack_length;
  13034. plci->NL.X = plci->NData;
  13035. plci->NL.ReqCh = 0;
  13036. plci->NL.Req = plci->nl_req = (byte) N_EDATA;
  13037. plci->adapter->request (&plci->NL);
  13038. return;
  13039. case FAX_EDATA_ACK_COMMAND_2:
  13040. if ((Rc != OK) && (Rc != OK_FC))
  13041. {
  13042. dbug (1, dprintf ("[%06lx] %s,%d: FAX issue EDATA ACK failed %02x",
  13043. UnMapId (Id), (char *)(FILE_), __LINE__, Rc));
  13044. break;
  13045. }
  13046. }
  13047. }
  13048. static void fax_connect_info_command (dword Id, PLCI *plci, byte Rc)
  13049. {
  13050. word Info;
  13051. word internal_command;
  13052. dbug (1, dprintf ("[%06lx] %s,%d: fax_connect_info_command %02x %04x",
  13053. UnMapId (Id), (char *)(FILE_), __LINE__, Rc, plci->internal_command));
  13054. Info = GOOD;
  13055. internal_command = plci->internal_command;
  13056. plci->internal_command = 0;
  13057. switch (internal_command)
  13058. {
  13059. default:
  13060. plci->command = 0;
  13061. case FAX_CONNECT_INFO_COMMAND_1:
  13062. if (plci_nl_busy (plci))
  13063. {
  13064. plci->internal_command = FAX_CONNECT_INFO_COMMAND_1;
  13065. return;
  13066. }
  13067. plci->internal_command = FAX_CONNECT_INFO_COMMAND_2;
  13068. plci->NData[0].P = plci->fax_connect_info_buffer;
  13069. plci->NData[0].PLength = plci->fax_connect_info_length;
  13070. plci->NL.X = plci->NData;
  13071. plci->NL.ReqCh = 0;
  13072. plci->NL.Req = plci->nl_req = (byte) N_EDATA;
  13073. plci->adapter->request (&plci->NL);
  13074. return;
  13075. case FAX_CONNECT_INFO_COMMAND_2:
  13076. if ((Rc != OK) && (Rc != OK_FC))
  13077. {
  13078. dbug (1, dprintf ("[%06lx] %s,%d: FAX setting connect info failed %02x",
  13079. UnMapId (Id), (char *)(FILE_), __LINE__, Rc));
  13080. Info = _WRONG_STATE;
  13081. break;
  13082. }
  13083. if (plci_nl_busy (plci))
  13084. {
  13085. plci->internal_command = FAX_CONNECT_INFO_COMMAND_2;
  13086. return;
  13087. }
  13088. plci->command = _CONNECT_B3_R;
  13089. nl_req_ncci (plci, N_CONNECT, 0);
  13090. send_req (plci);
  13091. return;
  13092. }
  13093. sendf (plci->appl, _CONNECT_B3_R | CONFIRM, Id, plci->number, "w", Info);
  13094. }
  13095. static void fax_adjust_b23_command (dword Id, PLCI *plci, byte Rc)
  13096. {
  13097. word Info;
  13098. word internal_command;
  13099. dbug (1, dprintf ("[%06lx] %s,%d: fax_adjust_b23_command %02x %04x",
  13100. UnMapId (Id), (char *)(FILE_), __LINE__, Rc, plci->internal_command));
  13101. Info = GOOD;
  13102. internal_command = plci->internal_command;
  13103. plci->internal_command = 0;
  13104. switch (internal_command)
  13105. {
  13106. default:
  13107. plci->command = 0;
  13108. plci->adjust_b_parms_msg = NULL;
  13109. plci->adjust_b_facilities = plci->B1_facilities;
  13110. plci->adjust_b_command = FAX_ADJUST_B23_COMMAND_1;
  13111. plci->adjust_b_ncci = (word)(Id >> 16);
  13112. plci->adjust_b_mode = ADJUST_B_MODE_REMOVE_L23 | ADJUST_B_MODE_ASSIGN_L23;
  13113. plci->adjust_b_state = ADJUST_B_START;
  13114. dbug (1, dprintf ("[%06lx] %s,%d: FAX adjust B23...",
  13115. UnMapId (Id), (char *)(FILE_), __LINE__));
  13116. case FAX_ADJUST_B23_COMMAND_1:
  13117. Info = adjust_b_process (Id, plci, Rc);
  13118. if (Info != GOOD)
  13119. {
  13120. dbug (1, dprintf ("[%06lx] %s,%d: FAX adjust failed",
  13121. UnMapId (Id), (char *)(FILE_), __LINE__));
  13122. break;
  13123. }
  13124. if (plci->internal_command)
  13125. return;
  13126. case FAX_ADJUST_B23_COMMAND_2:
  13127. if (plci_nl_busy (plci))
  13128. {
  13129. plci->internal_command = FAX_ADJUST_B23_COMMAND_2;
  13130. return;
  13131. }
  13132. plci->command = _CONNECT_B3_R;
  13133. nl_req_ncci (plci, N_CONNECT, 0);
  13134. send_req (plci);
  13135. return;
  13136. }
  13137. sendf (plci->appl, _CONNECT_B3_R | CONFIRM, Id, plci->number, "w", Info);
  13138. }
  13139. static void fax_disconnect_command (dword Id, PLCI *plci, byte Rc)
  13140. {
  13141. word internal_command;
  13142. dbug (1, dprintf ("[%06lx] %s,%d: fax_disconnect_command %02x %04x",
  13143. UnMapId (Id), (char *)(FILE_), __LINE__, Rc, plci->internal_command));
  13144. internal_command = plci->internal_command;
  13145. plci->internal_command = 0;
  13146. switch (internal_command)
  13147. {
  13148. default:
  13149. plci->command = 0;
  13150. plci->internal_command = FAX_DISCONNECT_COMMAND_1;
  13151. return;
  13152. case FAX_DISCONNECT_COMMAND_1:
  13153. case FAX_DISCONNECT_COMMAND_2:
  13154. case FAX_DISCONNECT_COMMAND_3:
  13155. if ((Rc != OK) && (Rc != OK_FC) && (Rc != 0))
  13156. {
  13157. dbug (1, dprintf ("[%06lx] %s,%d: FAX disconnect EDATA failed %02x",
  13158. UnMapId (Id), (char *)(FILE_), __LINE__, Rc));
  13159. break;
  13160. }
  13161. if (Rc == OK)
  13162. {
  13163. if ((internal_command == FAX_DISCONNECT_COMMAND_1)
  13164. || (internal_command == FAX_DISCONNECT_COMMAND_2))
  13165. {
  13166. plci->internal_command = FAX_DISCONNECT_COMMAND_2;
  13167. }
  13168. }
  13169. else if (Rc == 0)
  13170. {
  13171. if (internal_command == FAX_DISCONNECT_COMMAND_1)
  13172. plci->internal_command = FAX_DISCONNECT_COMMAND_3;
  13173. }
  13174. return;
  13175. }
  13176. }
  13177. static void rtp_connect_b3_req_command (dword Id, PLCI *plci, byte Rc)
  13178. {
  13179. word Info;
  13180. word internal_command;
  13181. dbug (1, dprintf ("[%06lx] %s,%d: rtp_connect_b3_req_command %02x %04x",
  13182. UnMapId (Id), (char *)(FILE_), __LINE__, Rc, plci->internal_command));
  13183. Info = GOOD;
  13184. internal_command = plci->internal_command;
  13185. plci->internal_command = 0;
  13186. switch (internal_command)
  13187. {
  13188. default:
  13189. plci->command = 0;
  13190. case RTP_CONNECT_B3_REQ_COMMAND_1:
  13191. if (plci_nl_busy (plci))
  13192. {
  13193. plci->internal_command = RTP_CONNECT_B3_REQ_COMMAND_1;
  13194. return;
  13195. }
  13196. plci->internal_command = RTP_CONNECT_B3_REQ_COMMAND_2;
  13197. nl_req_ncci (plci, N_CONNECT, 0);
  13198. send_req (plci);
  13199. return;
  13200. case RTP_CONNECT_B3_REQ_COMMAND_2:
  13201. if ((Rc != OK) && (Rc != OK_FC))
  13202. {
  13203. dbug (1, dprintf ("[%06lx] %s,%d: RTP setting connect info failed %02x",
  13204. UnMapId (Id), (char *)(FILE_), __LINE__, Rc));
  13205. Info = _WRONG_STATE;
  13206. break;
  13207. }
  13208. if (plci_nl_busy (plci))
  13209. {
  13210. plci->internal_command = RTP_CONNECT_B3_REQ_COMMAND_2;
  13211. return;
  13212. }
  13213. plci->internal_command = RTP_CONNECT_B3_REQ_COMMAND_3;
  13214. plci->NData[0].PLength = plci->internal_req_buffer[0];
  13215. plci->NData[0].P = plci->internal_req_buffer + 1;
  13216. plci->NL.X = plci->NData;
  13217. plci->NL.ReqCh = 0;
  13218. plci->NL.Req = plci->nl_req = (byte) N_UDATA;
  13219. plci->adapter->request (&plci->NL);
  13220. break;
  13221. case RTP_CONNECT_B3_REQ_COMMAND_3:
  13222. return;
  13223. }
  13224. sendf (plci->appl, _CONNECT_B3_R | CONFIRM, Id, plci->number, "w", Info);
  13225. }
  13226. static void rtp_connect_b3_res_command (dword Id, PLCI *plci, byte Rc)
  13227. {
  13228. word Info;
  13229. word internal_command;
  13230. dbug (1, dprintf ("[%06lx] %s,%d: rtp_connect_b3_res_command %02x %04x",
  13231. UnMapId (Id), (char *)(FILE_), __LINE__, Rc, plci->internal_command));
  13232. Info = GOOD;
  13233. internal_command = plci->internal_command;
  13234. plci->internal_command = 0;
  13235. switch (internal_command)
  13236. {
  13237. default:
  13238. plci->command = 0;
  13239. case RTP_CONNECT_B3_RES_COMMAND_1:
  13240. if (plci_nl_busy (plci))
  13241. {
  13242. plci->internal_command = RTP_CONNECT_B3_RES_COMMAND_1;
  13243. return;
  13244. }
  13245. plci->internal_command = RTP_CONNECT_B3_RES_COMMAND_2;
  13246. nl_req_ncci (plci, N_CONNECT_ACK, (byte)(Id >> 16));
  13247. send_req (plci);
  13248. return;
  13249. case RTP_CONNECT_B3_RES_COMMAND_2:
  13250. if ((Rc != OK) && (Rc != OK_FC))
  13251. {
  13252. dbug (1, dprintf ("[%06lx] %s,%d: RTP setting connect resp info failed %02x",
  13253. UnMapId (Id), (char *)(FILE_), __LINE__, Rc));
  13254. Info = _WRONG_STATE;
  13255. break;
  13256. }
  13257. if (plci_nl_busy (plci))
  13258. {
  13259. plci->internal_command = RTP_CONNECT_B3_RES_COMMAND_2;
  13260. return;
  13261. }
  13262. sendf (plci->appl, _CONNECT_B3_ACTIVE_I, Id, 0, "s", "");
  13263. plci->internal_command = RTP_CONNECT_B3_RES_COMMAND_3;
  13264. plci->NData[0].PLength = plci->internal_req_buffer[0];
  13265. plci->NData[0].P = plci->internal_req_buffer + 1;
  13266. plci->NL.X = plci->NData;
  13267. plci->NL.ReqCh = 0;
  13268. plci->NL.Req = plci->nl_req = (byte) N_UDATA;
  13269. plci->adapter->request (&plci->NL);
  13270. return;
  13271. case RTP_CONNECT_B3_RES_COMMAND_3:
  13272. return;
  13273. }
  13274. }
  13275. static void hold_save_command (dword Id, PLCI *plci, byte Rc)
  13276. {
  13277. byte SS_Ind[] = "\x05\x02\x00\x02\x00\x00"; /* Hold_Ind struct*/
  13278. word Info;
  13279. word internal_command;
  13280. dbug (1, dprintf ("[%06lx] %s,%d: hold_save_command %02x %04x",
  13281. UnMapId (Id), (char *)(FILE_), __LINE__, Rc, plci->internal_command));
  13282. Info = GOOD;
  13283. internal_command = plci->internal_command;
  13284. plci->internal_command = 0;
  13285. switch (internal_command)
  13286. {
  13287. default:
  13288. if (!plci->NL.Id)
  13289. break;
  13290. plci->command = 0;
  13291. plci->adjust_b_parms_msg = NULL;
  13292. plci->adjust_b_facilities = plci->B1_facilities;
  13293. plci->adjust_b_command = HOLD_SAVE_COMMAND_1;
  13294. plci->adjust_b_ncci = (word)(Id >> 16);
  13295. plci->adjust_b_mode = ADJUST_B_MODE_SAVE | ADJUST_B_MODE_REMOVE_L23;
  13296. plci->adjust_b_state = ADJUST_B_START;
  13297. dbug (1, dprintf ("[%06lx] %s,%d: HOLD save...",
  13298. UnMapId (Id), (char *)(FILE_), __LINE__));
  13299. case HOLD_SAVE_COMMAND_1:
  13300. Info = adjust_b_process (Id, plci, Rc);
  13301. if (Info != GOOD)
  13302. {
  13303. dbug (1, dprintf ("[%06lx] %s,%d: HOLD save failed",
  13304. UnMapId (Id), (char *)(FILE_), __LINE__));
  13305. break;
  13306. }
  13307. if (plci->internal_command)
  13308. return;
  13309. }
  13310. sendf (plci->appl, _FACILITY_I, Id & 0xffffL, 0, "ws", 3, SS_Ind);
  13311. }
  13312. static void retrieve_restore_command (dword Id, PLCI *plci, byte Rc)
  13313. {
  13314. byte SS_Ind[] = "\x05\x03\x00\x02\x00\x00"; /* Retrieve_Ind struct*/
  13315. word Info;
  13316. word internal_command;
  13317. dbug (1, dprintf ("[%06lx] %s,%d: retrieve_restore_command %02x %04x",
  13318. UnMapId (Id), (char *)(FILE_), __LINE__, Rc, plci->internal_command));
  13319. Info = GOOD;
  13320. internal_command = plci->internal_command;
  13321. plci->internal_command = 0;
  13322. switch (internal_command)
  13323. {
  13324. default:
  13325. plci->command = 0;
  13326. plci->adjust_b_parms_msg = NULL;
  13327. plci->adjust_b_facilities = plci->B1_facilities;
  13328. plci->adjust_b_command = RETRIEVE_RESTORE_COMMAND_1;
  13329. plci->adjust_b_ncci = (word)(Id >> 16);
  13330. plci->adjust_b_mode = ADJUST_B_MODE_ASSIGN_L23 | ADJUST_B_MODE_USER_CONNECT | ADJUST_B_MODE_RESTORE;
  13331. plci->adjust_b_state = ADJUST_B_START;
  13332. dbug (1, dprintf ("[%06lx] %s,%d: RETRIEVE restore...",
  13333. UnMapId (Id), (char *)(FILE_), __LINE__));
  13334. case RETRIEVE_RESTORE_COMMAND_1:
  13335. Info = adjust_b_process (Id, plci, Rc);
  13336. if (Info != GOOD)
  13337. {
  13338. dbug (1, dprintf ("[%06lx] %s,%d: RETRIEVE restore failed",
  13339. UnMapId (Id), (char *)(FILE_), __LINE__));
  13340. break;
  13341. }
  13342. if (plci->internal_command)
  13343. return;
  13344. }
  13345. sendf (plci->appl, _FACILITY_I, Id & 0xffffL, 0, "ws", 3, SS_Ind);
  13346. }
  13347. static void init_b1_config (PLCI *plci)
  13348. {
  13349. dbug (1, dprintf ("[%06lx] %s,%d: init_b1_config",
  13350. (dword)((plci->Id << 8) | UnMapController (plci->adapter->Id)),
  13351. (char *)(FILE_), __LINE__));
  13352. plci->B1_resource = 0;
  13353. plci->B1_facilities = 0;
  13354. plci->li_bchannel_id = 0;
  13355. mixer_clear_config (plci);
  13356. ec_clear_config (plci);
  13357. dtmf_rec_clear_config (plci);
  13358. dtmf_send_clear_config (plci);
  13359. dtmf_parameter_clear_config (plci);
  13360. adv_voice_clear_config (plci);
  13361. adjust_b_clear (plci);
  13362. }
  13363. static void clear_b1_config (PLCI *plci)
  13364. {
  13365. dbug (1, dprintf ("[%06lx] %s,%d: clear_b1_config",
  13366. (dword)((plci->Id << 8) | UnMapController (plci->adapter->Id)),
  13367. (char *)(FILE_), __LINE__));
  13368. adv_voice_clear_config (plci);
  13369. adjust_b_clear (plci);
  13370. ec_clear_config (plci);
  13371. dtmf_rec_clear_config (plci);
  13372. dtmf_send_clear_config (plci);
  13373. dtmf_parameter_clear_config (plci);
  13374. if ((plci->li_bchannel_id != 0)
  13375. && (li_config_table[plci->adapter->li_base + (plci->li_bchannel_id - 1)].plci == plci))
  13376. {
  13377. mixer_clear_config (plci);
  13378. li_config_table[plci->adapter->li_base + (plci->li_bchannel_id - 1)].plci = NULL;
  13379. plci->li_bchannel_id = 0;
  13380. }
  13381. plci->B1_resource = 0;
  13382. plci->B1_facilities = 0;
  13383. }
  13384. /* -----------------------------------------------------------------
  13385. XON protocol local helpers
  13386. ----------------------------------------------------------------- */
  13387. static void channel_flow_control_remove (PLCI * plci) {
  13388. DIVA_CAPI_ADAPTER * a = plci->adapter;
  13389. word i;
  13390. for(i=1;i<MAX_NL_CHANNEL+1;i++) {
  13391. if (a->ch_flow_plci[i] == plci->Id) {
  13392. a->ch_flow_plci[i] = 0;
  13393. a->ch_flow_control[i] = 0;
  13394. }
  13395. }
  13396. }
  13397. static void channel_x_on (PLCI * plci, byte ch) {
  13398. DIVA_CAPI_ADAPTER * a = plci->adapter;
  13399. if (a->ch_flow_control[ch] & N_XON_SENT) {
  13400. a->ch_flow_control[ch] &= ~N_XON_SENT;
  13401. }
  13402. }
  13403. static void channel_x_off (PLCI * plci, byte ch, byte flag) {
  13404. DIVA_CAPI_ADAPTER * a = plci->adapter;
  13405. if ((a->ch_flow_control[ch] & N_RX_FLOW_CONTROL_MASK) == 0) {
  13406. a->ch_flow_control[ch] |= (N_CH_XOFF | flag);
  13407. a->ch_flow_plci[ch] = plci->Id;
  13408. a->ch_flow_control_pending++;
  13409. }
  13410. }
  13411. static void channel_request_xon (PLCI * plci, byte ch) {
  13412. DIVA_CAPI_ADAPTER * a = plci->adapter;
  13413. if (a->ch_flow_control[ch] & N_CH_XOFF) {
  13414. a->ch_flow_control[ch] |= N_XON_REQ;
  13415. a->ch_flow_control[ch] &= ~N_CH_XOFF;
  13416. a->ch_flow_control[ch] &= ~N_XON_CONNECT_IND;
  13417. }
  13418. }
  13419. static void channel_xmit_extended_xon (PLCI * plci) {
  13420. DIVA_CAPI_ADAPTER * a;
  13421. int max_ch = ARRAY_SIZE(a->ch_flow_control);
  13422. int i, one_requested = 0;
  13423. if ((!plci) || (!plci->Id) || ((a = plci->adapter) == NULL)) {
  13424. return;
  13425. }
  13426. for (i = 0; i < max_ch; i++) {
  13427. if ((a->ch_flow_control[i] & N_CH_XOFF) &&
  13428. (a->ch_flow_control[i] & N_XON_CONNECT_IND) &&
  13429. (plci->Id == a->ch_flow_plci[i])) {
  13430. channel_request_xon (plci, (byte)i);
  13431. one_requested = 1;
  13432. }
  13433. }
  13434. if (one_requested) {
  13435. channel_xmit_xon (plci);
  13436. }
  13437. }
  13438. /*
  13439. Try to xmit next X_ON
  13440. */
  13441. static int find_channel_with_pending_x_on (DIVA_CAPI_ADAPTER * a, PLCI * plci) {
  13442. int max_ch = ARRAY_SIZE(a->ch_flow_control);
  13443. int i;
  13444. if (!(plci->adapter->manufacturer_features & MANUFACTURER_FEATURE_XONOFF_FLOW_CONTROL)) {
  13445. return (0);
  13446. }
  13447. if (a->last_flow_control_ch >= max_ch) {
  13448. a->last_flow_control_ch = 1;
  13449. }
  13450. for (i=a->last_flow_control_ch; i < max_ch; i++) {
  13451. if ((a->ch_flow_control[i] & N_XON_REQ) &&
  13452. (plci->Id == a->ch_flow_plci[i])) {
  13453. a->last_flow_control_ch = i+1;
  13454. return (i);
  13455. }
  13456. }
  13457. for (i = 1; i < a->last_flow_control_ch; i++) {
  13458. if ((a->ch_flow_control[i] & N_XON_REQ) &&
  13459. (plci->Id == a->ch_flow_plci[i])) {
  13460. a->last_flow_control_ch = i+1;
  13461. return (i);
  13462. }
  13463. }
  13464. return (0);
  13465. }
  13466. static void channel_xmit_xon (PLCI * plci) {
  13467. DIVA_CAPI_ADAPTER * a = plci->adapter;
  13468. byte ch;
  13469. if (plci->nl_req || !plci->NL.Id || plci->nl_remove_id) {
  13470. return;
  13471. }
  13472. if ((ch = (byte)find_channel_with_pending_x_on (a, plci)) == 0) {
  13473. return;
  13474. }
  13475. a->ch_flow_control[ch] &= ~N_XON_REQ;
  13476. a->ch_flow_control[ch] |= N_XON_SENT;
  13477. plci->NL.Req = plci->nl_req = (byte)N_XON;
  13478. plci->NL.ReqCh = ch;
  13479. plci->NL.X = plci->NData;
  13480. plci->NL.XNum = 1;
  13481. plci->NData[0].P = &plci->RBuffer[0];
  13482. plci->NData[0].PLength = 0;
  13483. plci->adapter->request(&plci->NL);
  13484. }
  13485. static int channel_can_xon (PLCI * plci, byte ch) {
  13486. APPL * APPLptr;
  13487. DIVA_CAPI_ADAPTER * a;
  13488. word NCCIcode;
  13489. dword count;
  13490. word Num;
  13491. word i;
  13492. APPLptr = plci->appl;
  13493. a = plci->adapter;
  13494. if (!APPLptr)
  13495. return (0);
  13496. NCCIcode = a->ch_ncci[ch] | (((word) a->Id) << 8);
  13497. /* count all buffers within the Application pool */
  13498. /* belonging to the same NCCI. XON if a first is */
  13499. /* used. */
  13500. count = 0;
  13501. Num = 0xffff;
  13502. for(i=0; i<APPLptr->MaxBuffer; i++) {
  13503. if(NCCIcode==APPLptr->DataNCCI[i]) count++;
  13504. if(!APPLptr->DataNCCI[i] && Num==0xffff) Num = i;
  13505. }
  13506. if ((count > 2) || (Num == 0xffff)) {
  13507. return (0);
  13508. }
  13509. return (1);
  13510. }
  13511. /*------------------------------------------------------------------*/
  13512. static word CPN_filter_ok(byte *cpn,DIVA_CAPI_ADAPTER * a,word offset)
  13513. {
  13514. return 1;
  13515. }
  13516. /**********************************************************************************/
  13517. /* function groups the listening applications according to the CIP mask and the */
  13518. /* Info_Mask. Each group gets just one Connect_Ind. Some application manufacturer */
  13519. /* are not multi-instance capable, so they start e.g. 30 applications what causes */
  13520. /* big problems on application level (one call, 30 Connect_Ind, ect). The */
  13521. /* function must be enabled by setting "a->group_optimization_enabled" from the */
  13522. /* OS specific part (per adapter). */
  13523. /**********************************************************************************/
  13524. static void group_optimization(DIVA_CAPI_ADAPTER * a, PLCI * plci)
  13525. {
  13526. word i,j,k,busy,group_found;
  13527. dword info_mask_group[MAX_CIP_TYPES];
  13528. dword cip_mask_group[MAX_CIP_TYPES];
  13529. word appl_number_group_type[MAX_APPL];
  13530. PLCI *auxplci;
  13531. set_group_ind_mask (plci); /* all APPLs within this inc. call are allowed to dial in */
  13532. if(!a->group_optimization_enabled)
  13533. {
  13534. dbug(1,dprintf("No group optimization"));
  13535. return;
  13536. }
  13537. dbug(1,dprintf("Group optimization = 0x%x...", a->group_optimization_enabled));
  13538. for(i=0;i<MAX_CIP_TYPES;i++)
  13539. {
  13540. info_mask_group[i] = 0;
  13541. cip_mask_group [i] = 0;
  13542. }
  13543. for(i=0;i<MAX_APPL;i++)
  13544. {
  13545. appl_number_group_type[i] = 0;
  13546. }
  13547. for(i=0; i<max_appl; i++) /* check if any multi instance capable application is present */
  13548. { /* group_optimization set to 1 means not to optimize multi-instance capable applications (default) */
  13549. if(application[i].Id && (application[i].MaxNCCI) > 1 && (a->CIP_Mask[i]) && (a->group_optimization_enabled ==1) )
  13550. {
  13551. dbug(1,dprintf("Multi-Instance capable, no optimization required"));
  13552. return; /* allow good application unfiltered access */
  13553. }
  13554. }
  13555. for(i=0; i<max_appl; i++) /* Build CIP Groups */
  13556. {
  13557. if(application[i].Id && a->CIP_Mask[i] )
  13558. {
  13559. for(k=0,busy=false; k<a->max_plci; k++)
  13560. {
  13561. if(a->plci[k].Id)
  13562. {
  13563. auxplci = &a->plci[k];
  13564. if(auxplci->appl == &application[i]) /* application has a busy PLCI */
  13565. {
  13566. busy = true;
  13567. dbug(1,dprintf("Appl 0x%x is busy",i+1));
  13568. }
  13569. else if(test_c_ind_mask_bit (auxplci, i)) /* application has an incoming call pending */
  13570. {
  13571. busy = true;
  13572. dbug(1,dprintf("Appl 0x%x has inc. call pending",i+1));
  13573. }
  13574. }
  13575. }
  13576. for(j=0,group_found=0; j<=(MAX_CIP_TYPES) && !busy &&!group_found; j++) /* build groups with free applications only */
  13577. {
  13578. if(j==MAX_CIP_TYPES) /* all groups are in use but group still not found */
  13579. { /* the MAX_CIP_TYPES group enables all calls because of field overflow */
  13580. appl_number_group_type[i] = MAX_CIP_TYPES;
  13581. group_found=true;
  13582. dbug(1,dprintf("Field overflow appl 0x%x",i+1));
  13583. }
  13584. else if( (info_mask_group[j]==a->CIP_Mask[i]) && (cip_mask_group[j]==a->Info_Mask[i]) )
  13585. { /* is group already present ? */
  13586. appl_number_group_type[i] = j|0x80; /* store the group number for each application */
  13587. group_found=true;
  13588. 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]));
  13589. }
  13590. else if(!info_mask_group[j])
  13591. { /* establish a new group */
  13592. appl_number_group_type[i] = j|0x80; /* store the group number for each application */
  13593. info_mask_group[j] = a->CIP_Mask[i]; /* store the new CIP mask for the new group */
  13594. cip_mask_group[j] = a->Info_Mask[i]; /* store the new Info_Mask for this new group */
  13595. group_found=true;
  13596. 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]));
  13597. }
  13598. }
  13599. }
  13600. }
  13601. for(i=0; i<max_appl; i++) /* Build group_optimization_mask_table */
  13602. {
  13603. if(appl_number_group_type[i]) /* application is free, has listens and is member of a group */
  13604. {
  13605. if(appl_number_group_type[i] == MAX_CIP_TYPES)
  13606. {
  13607. dbug(1,dprintf("OverflowGroup 0x%x, valid appl = 0x%x, call enabled",appl_number_group_type[i],i+1));
  13608. }
  13609. else
  13610. {
  13611. dbug(1,dprintf("Group 0x%x, valid appl = 0x%x",appl_number_group_type[i],i+1));
  13612. for(j=i+1; j<max_appl; j++) /* search other group members and mark them as busy */
  13613. {
  13614. if(appl_number_group_type[i] == appl_number_group_type[j])
  13615. {
  13616. dbug(1,dprintf("Appl 0x%x is member of group 0x%x, no call",j+1,appl_number_group_type[j]));
  13617. clear_group_ind_mask_bit (plci, j); /* disable call on other group members */
  13618. appl_number_group_type[j] = 0; /* remove disabled group member from group list */
  13619. }
  13620. }
  13621. }
  13622. }
  13623. else /* application should not get a call */
  13624. {
  13625. clear_group_ind_mask_bit (plci, i);
  13626. }
  13627. }
  13628. }
  13629. /* OS notifies the driver about a application Capi_Register */
  13630. word CapiRegister(word id)
  13631. {
  13632. word i,j,appls_found;
  13633. PLCI *plci;
  13634. DIVA_CAPI_ADAPTER *a;
  13635. for(i=0,appls_found=0; i<max_appl; i++)
  13636. {
  13637. if( application[i].Id && (application[i].Id!=id) )
  13638. {
  13639. appls_found++; /* an application has been found */
  13640. }
  13641. }
  13642. if(appls_found) return true;
  13643. for(i=0; i<max_adapter; i++) /* scan all adapters... */
  13644. {
  13645. a = &adapter[i];
  13646. if(a->request)
  13647. {
  13648. if(a->flag_dynamic_l1_down) /* remove adapter from L1 tristate (Huntgroup) */
  13649. {
  13650. if(!appls_found) /* first application does a capi register */
  13651. {
  13652. if((j=get_plci(a))) /* activate L1 of all adapters */
  13653. {
  13654. plci = &a->plci[j-1];
  13655. plci->command = 0;
  13656. add_p(plci,OAD,"\x01\xfd");
  13657. add_p(plci,CAI,"\x01\x80");
  13658. add_p(plci,UID,"\x06\x43\x61\x70\x69\x32\x30");
  13659. add_p(plci,SHIFT|6,NULL);
  13660. add_p(plci,SIN,"\x02\x00\x00");
  13661. plci->internal_command = START_L1_SIG_ASSIGN_PEND;
  13662. sig_req(plci,ASSIGN,DSIG_ID);
  13663. add_p(plci,FTY,"\x02\xff\x07"); /* l1 start */
  13664. sig_req(plci,SIG_CTRL,0);
  13665. send_req(plci);
  13666. }
  13667. }
  13668. }
  13669. }
  13670. }
  13671. return false;
  13672. }
  13673. /*------------------------------------------------------------------*/
  13674. /* Functions for virtual Switching e.g. Transfer by join, Conference */
  13675. static void VSwitchReqInd(PLCI *plci, dword Id, byte **parms)
  13676. {
  13677. word i;
  13678. /* Format of vswitch_t:
  13679. 0 byte length
  13680. 1 byte VSWITCHIE
  13681. 2 byte VSWITCH_REQ/VSWITCH_IND
  13682. 3 byte reserved
  13683. 4 word VSwitchcommand
  13684. 6 word returnerror
  13685. 8... Params
  13686. */
  13687. if(!plci ||
  13688. !plci->appl ||
  13689. !plci->State ||
  13690. plci->Sig.Ind==NCR_FACILITY
  13691. )
  13692. return;
  13693. for(i=0;i<MAX_MULTI_IE;i++)
  13694. {
  13695. if(!parms[i][0]) continue;
  13696. if(parms[i][0]<7)
  13697. {
  13698. parms[i][0]=0; /* kill it */
  13699. continue;
  13700. }
  13701. dbug(1,dprintf("VSwitchReqInd(%d)",parms[i][4]));
  13702. switch(parms[i][4])
  13703. {
  13704. case VSJOIN:
  13705. if(!plci->relatedPTYPLCI ||
  13706. (plci->ptyState!=S_ECT && plci->relatedPTYPLCI->ptyState!=S_ECT))
  13707. { /* Error */
  13708. break;
  13709. }
  13710. /* remember all necessary informations */
  13711. if(parms[i][0]!=11 || parms[i][8]!=3) /* Length Test */
  13712. {
  13713. break;
  13714. }
  13715. if(parms[i][2]==VSWITCH_IND && parms[i][9]==1)
  13716. { /* first indication after ECT-Request on Consultation Call */
  13717. plci->vswitchstate=parms[i][9];
  13718. parms[i][9]=2; /* State */
  13719. /* now ask first Call to join */
  13720. }
  13721. else if(parms[i][2]==VSWITCH_REQ && parms[i][9]==3)
  13722. { /* Answer of VSWITCH_REQ from first Call */
  13723. plci->vswitchstate=parms[i][9];
  13724. /* tell consultation call to join
  13725. and the protocol capabilities of the first call */
  13726. }
  13727. else
  13728. { /* Error */
  13729. break;
  13730. }
  13731. plci->vsprot=parms[i][10]; /* protocol */
  13732. plci->vsprotdialect=parms[i][11]; /* protocoldialect */
  13733. /* send join request to related PLCI */
  13734. parms[i][1]=VSWITCHIE;
  13735. parms[i][2]=VSWITCH_REQ;
  13736. plci->relatedPTYPLCI->command = 0;
  13737. plci->relatedPTYPLCI->internal_command = VSWITCH_REQ_PEND;
  13738. add_p(plci->relatedPTYPLCI,ESC,&parms[i][0]);
  13739. sig_req(plci->relatedPTYPLCI,VSWITCH_REQ,0);
  13740. send_req(plci->relatedPTYPLCI);
  13741. break;
  13742. case VSTRANSPORT:
  13743. default:
  13744. if(plci->relatedPTYPLCI &&
  13745. plci->vswitchstate==3 &&
  13746. plci->relatedPTYPLCI->vswitchstate==3)
  13747. {
  13748. add_p(plci->relatedPTYPLCI,ESC,&parms[i][0]);
  13749. sig_req(plci->relatedPTYPLCI,VSWITCH_REQ,0);
  13750. send_req(plci->relatedPTYPLCI);
  13751. }
  13752. break;
  13753. }
  13754. parms[i][0]=0; /* kill it */
  13755. }
  13756. }
  13757. /*------------------------------------------------------------------*/
  13758. static int diva_get_dma_descriptor (PLCI *plci, dword *dma_magic) {
  13759. ENTITY e;
  13760. IDI_SYNC_REQ* pReq = (IDI_SYNC_REQ*)&e;
  13761. if (!(diva_xdi_extended_features & DIVA_CAPI_XDI_PROVIDES_RX_DMA)) {
  13762. return (-1);
  13763. }
  13764. pReq->xdi_dma_descriptor_operation.Req = 0;
  13765. pReq->xdi_dma_descriptor_operation.Rc = IDI_SYNC_REQ_DMA_DESCRIPTOR_OPERATION;
  13766. pReq->xdi_dma_descriptor_operation.info.operation = IDI_SYNC_REQ_DMA_DESCRIPTOR_ALLOC;
  13767. pReq->xdi_dma_descriptor_operation.info.descriptor_number = -1;
  13768. pReq->xdi_dma_descriptor_operation.info.descriptor_address = NULL;
  13769. pReq->xdi_dma_descriptor_operation.info.descriptor_magic = 0;
  13770. e.user[0] = plci->adapter->Id - 1;
  13771. plci->adapter->request((ENTITY*)pReq);
  13772. if (!pReq->xdi_dma_descriptor_operation.info.operation &&
  13773. (pReq->xdi_dma_descriptor_operation.info.descriptor_number >= 0) &&
  13774. pReq->xdi_dma_descriptor_operation.info.descriptor_magic) {
  13775. *dma_magic = pReq->xdi_dma_descriptor_operation.info.descriptor_magic;
  13776. dbug(3,dprintf("dma_alloc, a:%d (%d-%08x)",
  13777. plci->adapter->Id,
  13778. pReq->xdi_dma_descriptor_operation.info.descriptor_number,
  13779. *dma_magic));
  13780. return (pReq->xdi_dma_descriptor_operation.info.descriptor_number);
  13781. } else {
  13782. dbug(1,dprintf("dma_alloc failed"));
  13783. return (-1);
  13784. }
  13785. }
  13786. static void diva_free_dma_descriptor (PLCI *plci, int nr) {
  13787. ENTITY e;
  13788. IDI_SYNC_REQ* pReq = (IDI_SYNC_REQ*)&e;
  13789. if (nr < 0) {
  13790. return;
  13791. }
  13792. pReq->xdi_dma_descriptor_operation.Req = 0;
  13793. pReq->xdi_dma_descriptor_operation.Rc = IDI_SYNC_REQ_DMA_DESCRIPTOR_OPERATION;
  13794. pReq->xdi_dma_descriptor_operation.info.operation = IDI_SYNC_REQ_DMA_DESCRIPTOR_FREE;
  13795. pReq->xdi_dma_descriptor_operation.info.descriptor_number = nr;
  13796. pReq->xdi_dma_descriptor_operation.info.descriptor_address = NULL;
  13797. pReq->xdi_dma_descriptor_operation.info.descriptor_magic = 0;
  13798. e.user[0] = plci->adapter->Id - 1;
  13799. plci->adapter->request((ENTITY*)pReq);
  13800. if (!pReq->xdi_dma_descriptor_operation.info.operation) {
  13801. dbug(1,dprintf("dma_free(%d)", nr));
  13802. } else {
  13803. dbug(1,dprintf("dma_free failed (%d)", nr));
  13804. }
  13805. }
  13806. /*------------------------------------------------------------------*/