message.c 476 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774777577767777777877797780778177827783778477857786778777887789779077917792779377947795779677977798779978007801780278037804780578067807780878097810781178127813781478157816781778187819782078217822782378247825782678277828782978307831783278337834783578367837783878397840784178427843784478457846784778487849785078517852785378547855785678577858785978607861786278637864786578667867786878697870787178727873787478757876787778787879788078817882788378847885788678877888788978907891789278937894789578967897789878997900790179027903790479057906790779087909791079117912791379147915791679177918791979207921792279237924792579267927792879297930793179327933793479357936793779387939794079417942794379447945794679477948794979507951795279537954795579567957795879597960796179627963796479657966796779687969797079717972797379747975797679777978797979807981798279837984798579867987798879897990799179927993799479957996799779987999800080018002800380048005800680078008800980108011801280138014801580168017801880198020802180228023802480258026802780288029803080318032803380348035803680378038803980408041804280438044804580468047804880498050805180528053805480558056805780588059806080618062806380648065806680678068806980708071807280738074807580768077807880798080808180828083808480858086808780888089809080918092809380948095809680978098809981008101810281038104810581068107810881098110811181128113811481158116811781188119812081218122812381248125812681278128812981308131813281338134813581368137813881398140814181428143814481458146814781488149815081518152815381548155815681578158815981608161816281638164816581668167816881698170817181728173817481758176817781788179818081818182818381848185818681878188818981908191819281938194819581968197819881998200820182028203820482058206820782088209821082118212821382148215821682178218821982208221822282238224822582268227822882298230823182328233823482358236823782388239824082418242824382448245824682478248824982508251825282538254825582568257825882598260826182628263826482658266826782688269827082718272827382748275827682778278827982808281828282838284828582868287828882898290829182928293829482958296829782988299830083018302830383048305830683078308830983108311831283138314831583168317831883198320832183228323832483258326832783288329833083318332833383348335833683378338833983408341834283438344834583468347834883498350835183528353835483558356835783588359836083618362836383648365836683678368836983708371837283738374837583768377837883798380838183828383838483858386838783888389839083918392839383948395839683978398839984008401840284038404840584068407840884098410841184128413841484158416841784188419842084218422842384248425842684278428842984308431843284338434843584368437843884398440844184428443844484458446844784488449845084518452845384548455845684578458845984608461846284638464846584668467846884698470847184728473847484758476847784788479848084818482848384848485848684878488848984908491849284938494849584968497849884998500850185028503850485058506850785088509851085118512851385148515851685178518851985208521852285238524852585268527852885298530853185328533853485358536853785388539854085418542854385448545854685478548854985508551855285538554855585568557855885598560856185628563856485658566856785688569857085718572857385748575857685778578857985808581858285838584858585868587858885898590859185928593859485958596859785988599860086018602860386048605860686078608860986108611861286138614861586168617861886198620862186228623862486258626862786288629863086318632863386348635863686378638863986408641864286438644864586468647864886498650865186528653865486558656865786588659866086618662866386648665866686678668866986708671867286738674867586768677867886798680868186828683868486858686868786888689869086918692869386948695869686978698869987008701870287038704870587068707870887098710871187128713871487158716871787188719872087218722872387248725872687278728872987308731873287338734873587368737873887398740874187428743874487458746874787488749875087518752875387548755875687578758875987608761876287638764876587668767876887698770877187728773877487758776877787788779878087818782878387848785878687878788878987908791879287938794879587968797879887998800880188028803880488058806880788088809881088118812881388148815881688178818881988208821882288238824882588268827882888298830883188328833883488358836883788388839884088418842884388448845884688478848884988508851885288538854885588568857885888598860886188628863886488658866886788688869887088718872887388748875887688778878887988808881888288838884888588868887888888898890889188928893889488958896889788988899890089018902890389048905890689078908890989108911891289138914891589168917891889198920892189228923892489258926892789288929893089318932893389348935893689378938893989408941894289438944894589468947894889498950895189528953895489558956895789588959896089618962896389648965896689678968896989708971897289738974897589768977897889798980898189828983898489858986898789888989899089918992899389948995899689978998899990009001900290039004900590069007900890099010901190129013901490159016901790189019902090219022902390249025902690279028902990309031903290339034903590369037903890399040904190429043904490459046904790489049905090519052905390549055905690579058905990609061906290639064906590669067906890699070907190729073907490759076907790789079908090819082908390849085908690879088908990909091909290939094909590969097909890999100910191029103910491059106910791089109911091119112911391149115911691179118911991209121912291239124912591269127912891299130913191329133913491359136913791389139914091419142914391449145914691479148914991509151915291539154915591569157915891599160916191629163916491659166916791689169917091719172917391749175917691779178917991809181918291839184918591869187918891899190919191929193919491959196919791989199920092019202920392049205920692079208920992109211921292139214921592169217921892199220922192229223922492259226922792289229923092319232923392349235923692379238923992409241924292439244924592469247924892499250925192529253925492559256925792589259926092619262926392649265926692679268926992709271927292739274927592769277927892799280928192829283928492859286928792889289929092919292929392949295929692979298929993009301930293039304930593069307930893099310931193129313931493159316931793189319932093219322932393249325932693279328932993309331933293339334933593369337933893399340934193429343934493459346934793489349935093519352935393549355935693579358935993609361936293639364936593669367936893699370937193729373937493759376937793789379938093819382938393849385938693879388938993909391939293939394939593969397939893999400940194029403940494059406940794089409941094119412941394149415941694179418941994209421942294239424942594269427942894299430943194329433943494359436943794389439944094419442944394449445944694479448944994509451945294539454945594569457945894599460946194629463946494659466946794689469947094719472947394749475947694779478947994809481948294839484948594869487948894899490949194929493949494959496949794989499950095019502950395049505950695079508950995109511951295139514951595169517951895199520952195229523952495259526952795289529953095319532953395349535953695379538953995409541954295439544954595469547954895499550955195529553955495559556955795589559956095619562956395649565956695679568956995709571957295739574957595769577957895799580958195829583958495859586958795889589959095919592959395949595959695979598959996009601960296039604960596069607960896099610961196129613961496159616961796189619962096219622962396249625962696279628962996309631963296339634963596369637963896399640964196429643964496459646964796489649965096519652965396549655965696579658965996609661966296639664966596669667966896699670967196729673967496759676967796789679968096819682968396849685968696879688968996909691969296939694969596969697969896999700970197029703970497059706970797089709971097119712971397149715971697179718971997209721972297239724972597269727972897299730973197329733973497359736973797389739974097419742974397449745974697479748974997509751975297539754975597569757975897599760976197629763976497659766976797689769977097719772977397749775977697779778977997809781978297839784978597869787978897899790979197929793979497959796979797989799980098019802980398049805980698079808980998109811981298139814981598169817981898199820982198229823982498259826982798289829983098319832983398349835983698379838983998409841984298439844984598469847984898499850985198529853985498559856985798589859986098619862986398649865986698679868986998709871987298739874987598769877987898799880988198829883988498859886988798889889989098919892989398949895989698979898989999009901990299039904990599069907990899099910991199129913991499159916991799189919992099219922992399249925992699279928992999309931993299339934993599369937993899399940994199429943994499459946994799489949995099519952995399549955995699579958995999609961996299639964996599669967996899699970997199729973997499759976997799789979998099819982998399849985998699879988998999909991999299939994999599969997999899991000010001100021000310004100051000610007100081000910010100111001210013100141001510016100171001810019100201002110022100231002410025100261002710028100291003010031100321003310034100351003610037100381003910040100411004210043100441004510046100471004810049100501005110052100531005410055100561005710058100591006010061100621006310064100651006610067100681006910070100711007210073100741007510076100771007810079100801008110082100831008410085100861008710088100891009010091100921009310094100951009610097100981009910100101011010210103101041010510106101071010810109101101011110112101131011410115101161011710118101191012010121101221012310124101251012610127101281012910130101311013210133101341013510136101371013810139101401014110142101431014410145101461014710148101491015010151101521015310154101551015610157101581015910160101611016210163101641016510166101671016810169101701017110172101731017410175101761017710178101791018010181101821018310184101851018610187101881018910190101911019210193101941019510196101971019810199102001020110202102031020410205102061020710208102091021010211102121021310214102151021610217102181021910220102211022210223102241022510226102271022810229102301023110232102331023410235102361023710238102391024010241102421024310244102451024610247102481024910250102511025210253102541025510256102571025810259102601026110262102631026410265102661026710268102691027010271102721027310274102751027610277102781027910280102811028210283102841028510286102871028810289102901029110292102931029410295102961029710298102991030010301103021030310304103051030610307103081030910310103111031210313103141031510316103171031810319103201032110322103231032410325103261032710328103291033010331103321033310334103351033610337103381033910340103411034210343103441034510346103471034810349103501035110352103531035410355103561035710358103591036010361103621036310364103651036610367103681036910370103711037210373103741037510376103771037810379103801038110382103831038410385103861038710388103891039010391103921039310394103951039610397103981039910400104011040210403104041040510406104071040810409104101041110412104131041410415104161041710418104191042010421104221042310424104251042610427104281042910430104311043210433104341043510436104371043810439104401044110442104431044410445104461044710448104491045010451104521045310454104551045610457104581045910460104611046210463104641046510466104671046810469104701047110472104731047410475104761047710478104791048010481104821048310484104851048610487104881048910490104911049210493104941049510496104971049810499105001050110502105031050410505105061050710508105091051010511105121051310514105151051610517105181051910520105211052210523105241052510526105271052810529105301053110532105331053410535105361053710538105391054010541105421054310544105451054610547105481054910550105511055210553105541055510556105571055810559105601056110562105631056410565105661056710568105691057010571105721057310574105751057610577105781057910580105811058210583105841058510586105871058810589105901059110592105931059410595105961059710598105991060010601106021060310604106051060610607106081060910610106111061210613106141061510616106171061810619106201062110622106231062410625106261062710628106291063010631106321063310634106351063610637106381063910640106411064210643106441064510646106471064810649106501065110652106531065410655106561065710658106591066010661106621066310664106651066610667106681066910670106711067210673106741067510676106771067810679106801068110682106831068410685106861068710688106891069010691106921069310694106951069610697106981069910700107011070210703107041070510706107071070810709107101071110712107131071410715107161071710718107191072010721107221072310724107251072610727107281072910730107311073210733107341073510736107371073810739107401074110742107431074410745107461074710748107491075010751107521075310754107551075610757107581075910760107611076210763107641076510766107671076810769107701077110772107731077410775107761077710778107791078010781107821078310784107851078610787107881078910790107911079210793107941079510796107971079810799108001080110802108031080410805108061080710808108091081010811108121081310814108151081610817108181081910820108211082210823108241082510826108271082810829108301083110832108331083410835108361083710838108391084010841108421084310844108451084610847108481084910850108511085210853108541085510856108571085810859108601086110862108631086410865108661086710868108691087010871108721087310874108751087610877108781087910880108811088210883108841088510886108871088810889108901089110892108931089410895108961089710898108991090010901109021090310904109051090610907109081090910910109111091210913109141091510916109171091810919109201092110922109231092410925109261092710928109291093010931109321093310934109351093610937109381093910940109411094210943109441094510946109471094810949109501095110952109531095410955109561095710958109591096010961109621096310964109651096610967109681096910970109711097210973109741097510976109771097810979109801098110982109831098410985109861098710988109891099010991109921099310994109951099610997109981099911000110011100211003110041100511006110071100811009110101101111012110131101411015110161101711018110191102011021110221102311024110251102611027110281102911030110311103211033110341103511036110371103811039110401104111042110431104411045110461104711048110491105011051110521105311054110551105611057110581105911060110611106211063110641106511066110671106811069110701107111072110731107411075110761107711078110791108011081110821108311084110851108611087110881108911090110911109211093110941109511096110971109811099111001110111102111031110411105111061110711108111091111011111111121111311114111151111611117111181111911120111211112211123111241112511126111271112811129111301113111132111331113411135111361113711138111391114011141111421114311144111451114611147111481114911150111511115211153111541115511156111571115811159111601116111162111631116411165111661116711168111691117011171111721117311174111751117611177111781117911180111811118211183111841118511186111871118811189111901119111192111931119411195111961119711198111991120011201112021120311204112051120611207112081120911210112111121211213112141121511216112171121811219112201122111222112231122411225112261122711228112291123011231112321123311234112351123611237112381123911240112411124211243112441124511246112471124811249112501125111252112531125411255112561125711258112591126011261112621126311264112651126611267112681126911270112711127211273112741127511276112771127811279112801128111282112831128411285112861128711288112891129011291112921129311294112951129611297112981129911300113011130211303113041130511306113071130811309113101131111312113131131411315113161131711318113191132011321113221132311324113251132611327113281132911330113311133211333113341133511336113371133811339113401134111342113431134411345113461134711348113491135011351113521135311354113551135611357113581135911360113611136211363113641136511366113671136811369113701137111372113731137411375113761137711378113791138011381113821138311384113851138611387113881138911390113911139211393113941139511396113971139811399114001140111402114031140411405114061140711408114091141011411114121141311414114151141611417114181141911420114211142211423114241142511426114271142811429114301143111432114331143411435114361143711438114391144011441114421144311444114451144611447114481144911450114511145211453114541145511456114571145811459114601146111462114631146411465114661146711468114691147011471114721147311474114751147611477114781147911480114811148211483114841148511486114871148811489114901149111492114931149411495114961149711498114991150011501115021150311504115051150611507115081150911510115111151211513115141151511516115171151811519115201152111522115231152411525115261152711528115291153011531115321153311534115351153611537115381153911540115411154211543115441154511546115471154811549115501155111552115531155411555115561155711558115591156011561115621156311564115651156611567115681156911570115711157211573115741157511576115771157811579115801158111582115831158411585115861158711588115891159011591115921159311594115951159611597115981159911600116011160211603116041160511606116071160811609116101161111612116131161411615116161161711618116191162011621116221162311624116251162611627116281162911630116311163211633116341163511636116371163811639116401164111642116431164411645116461164711648116491165011651116521165311654116551165611657116581165911660116611166211663116641166511666116671166811669116701167111672116731167411675116761167711678116791168011681116821168311684116851168611687116881168911690116911169211693116941169511696116971169811699117001170111702117031170411705117061170711708117091171011711117121171311714117151171611717117181171911720117211172211723117241172511726117271172811729117301173111732117331173411735117361173711738117391174011741117421174311744117451174611747117481174911750117511175211753117541175511756117571175811759117601176111762117631176411765117661176711768117691177011771117721177311774117751177611777117781177911780117811178211783117841178511786117871178811789117901179111792117931179411795117961179711798117991180011801118021180311804118051180611807118081180911810118111181211813118141181511816118171181811819118201182111822118231182411825118261182711828118291183011831118321183311834118351183611837118381183911840118411184211843118441184511846118471184811849118501185111852118531185411855118561185711858118591186011861118621186311864118651186611867118681186911870118711187211873118741187511876118771187811879118801188111882118831188411885118861188711888118891189011891118921189311894118951189611897118981189911900119011190211903119041190511906119071190811909119101191111912119131191411915119161191711918119191192011921119221192311924119251192611927119281192911930119311193211933119341193511936119371193811939119401194111942119431194411945119461194711948119491195011951119521195311954119551195611957119581195911960119611196211963119641196511966119671196811969119701197111972119731197411975119761197711978119791198011981119821198311984119851198611987119881198911990119911199211993119941199511996119971199811999120001200112002120031200412005120061200712008120091201012011120121201312014120151201612017120181201912020120211202212023120241202512026120271202812029120301203112032120331203412035120361203712038120391204012041120421204312044120451204612047120481204912050120511205212053120541205512056120571205812059120601206112062120631206412065120661206712068120691207012071120721207312074120751207612077120781207912080120811208212083120841208512086120871208812089120901209112092120931209412095120961209712098120991210012101121021210312104121051210612107121081210912110121111211212113121141211512116121171211812119121201212112122121231212412125121261212712128121291213012131121321213312134121351213612137121381213912140121411214212143121441214512146121471214812149121501215112152121531215412155121561215712158121591216012161121621216312164121651216612167121681216912170121711217212173121741217512176121771217812179121801218112182121831218412185121861218712188121891219012191121921219312194121951219612197121981219912200122011220212203122041220512206122071220812209122101221112212122131221412215122161221712218122191222012221122221222312224122251222612227122281222912230122311223212233122341223512236122371223812239122401224112242122431224412245122461224712248122491225012251122521225312254122551225612257122581225912260122611226212263122641226512266122671226812269122701227112272122731227412275122761227712278122791228012281122821228312284122851228612287122881228912290122911229212293122941229512296122971229812299123001230112302123031230412305123061230712308123091231012311123121231312314123151231612317123181231912320123211232212323123241232512326123271232812329123301233112332123331233412335123361233712338123391234012341123421234312344123451234612347123481234912350123511235212353123541235512356123571235812359123601236112362123631236412365123661236712368123691237012371123721237312374123751237612377123781237912380123811238212383123841238512386123871238812389123901239112392123931239412395123961239712398123991240012401124021240312404124051240612407124081240912410124111241212413124141241512416124171241812419124201242112422124231242412425124261242712428124291243012431124321243312434124351243612437124381243912440124411244212443124441244512446124471244812449124501245112452124531245412455124561245712458124591246012461124621246312464124651246612467124681246912470124711247212473124741247512476124771247812479124801248112482124831248412485124861248712488124891249012491124921249312494124951249612497124981249912500125011250212503125041250512506125071250812509125101251112512125131251412515125161251712518125191252012521125221252312524125251252612527125281252912530125311253212533125341253512536125371253812539125401254112542125431254412545125461254712548125491255012551125521255312554125551255612557125581255912560125611256212563125641256512566125671256812569125701257112572125731257412575125761257712578125791258012581125821258312584125851258612587125881258912590125911259212593125941259512596125971259812599126001260112602126031260412605126061260712608126091261012611126121261312614126151261612617126181261912620126211262212623126241262512626126271262812629126301263112632126331263412635126361263712638126391264012641126421264312644126451264612647126481264912650126511265212653126541265512656126571265812659126601266112662126631266412665126661266712668126691267012671126721267312674126751267612677126781267912680126811268212683126841268512686126871268812689126901269112692126931269412695126961269712698126991270012701127021270312704127051270612707127081270912710127111271212713127141271512716127171271812719127201272112722127231272412725127261272712728127291273012731127321273312734127351273612737127381273912740127411274212743127441274512746127471274812749127501275112752127531275412755127561275712758127591276012761127621276312764127651276612767127681276912770127711277212773127741277512776127771277812779127801278112782127831278412785127861278712788127891279012791127921279312794127951279612797127981279912800128011280212803128041280512806128071280812809128101281112812128131281412815128161281712818128191282012821128221282312824128251282612827128281282912830128311283212833128341283512836128371283812839128401284112842128431284412845128461284712848128491285012851128521285312854128551285612857128581285912860128611286212863128641286512866128671286812869128701287112872128731287412875128761287712878128791288012881128821288312884128851288612887128881288912890128911289212893128941289512896128971289812899129001290112902129031290412905129061290712908129091291012911129121291312914129151291612917129181291912920129211292212923129241292512926129271292812929129301293112932129331293412935129361293712938129391294012941129421294312944129451294612947129481294912950129511295212953129541295512956129571295812959129601296112962129631296412965129661296712968129691297012971129721297312974129751297612977129781297912980129811298212983129841298512986129871298812989129901299112992129931299412995129961299712998129991300013001130021300313004130051300613007130081300913010130111301213013130141301513016130171301813019130201302113022130231302413025130261302713028130291303013031130321303313034130351303613037130381303913040130411304213043130441304513046130471304813049130501305113052130531305413055130561305713058130591306013061130621306313064130651306613067130681306913070130711307213073130741307513076130771307813079130801308113082130831308413085130861308713088130891309013091130921309313094130951309613097130981309913100131011310213103131041310513106131071310813109131101311113112131131311413115131161311713118131191312013121131221312313124131251312613127131281312913130131311313213133131341313513136131371313813139131401314113142131431314413145131461314713148131491315013151131521315313154131551315613157131581315913160131611316213163131641316513166131671316813169131701317113172131731317413175131761317713178131791318013181131821318313184131851318613187131881318913190131911319213193131941319513196131971319813199132001320113202132031320413205132061320713208132091321013211132121321313214132151321613217132181321913220132211322213223132241322513226132271322813229132301323113232132331323413235132361323713238132391324013241132421324313244132451324613247132481324913250132511325213253132541325513256132571325813259132601326113262132631326413265132661326713268132691327013271132721327313274132751327613277132781327913280132811328213283132841328513286132871328813289132901329113292132931329413295132961329713298132991330013301133021330313304133051330613307133081330913310133111331213313133141331513316133171331813319133201332113322133231332413325133261332713328133291333013331133321333313334133351333613337133381333913340133411334213343133441334513346133471334813349133501335113352133531335413355133561335713358133591336013361133621336313364133651336613367133681336913370133711337213373133741337513376133771337813379133801338113382133831338413385133861338713388133891339013391133921339313394133951339613397133981339913400134011340213403134041340513406134071340813409134101341113412134131341413415134161341713418134191342013421134221342313424134251342613427134281342913430134311343213433134341343513436134371343813439134401344113442134431344413445134461344713448134491345013451134521345313454134551345613457134581345913460134611346213463134641346513466134671346813469134701347113472134731347413475134761347713478134791348013481134821348313484134851348613487134881348913490134911349213493134941349513496134971349813499135001350113502135031350413505135061350713508135091351013511135121351313514135151351613517135181351913520135211352213523135241352513526135271352813529135301353113532135331353413535135361353713538135391354013541135421354313544135451354613547135481354913550135511355213553135541355513556135571355813559135601356113562135631356413565135661356713568135691357013571135721357313574135751357613577135781357913580135811358213583135841358513586135871358813589135901359113592135931359413595135961359713598135991360013601136021360313604136051360613607136081360913610136111361213613136141361513616136171361813619136201362113622136231362413625136261362713628136291363013631136321363313634136351363613637136381363913640136411364213643136441364513646136471364813649136501365113652136531365413655136561365713658136591366013661136621366313664136651366613667136681366913670136711367213673136741367513676136771367813679136801368113682136831368413685136861368713688136891369013691136921369313694136951369613697136981369913700137011370213703137041370513706137071370813709137101371113712137131371413715137161371713718137191372013721137221372313724137251372613727137281372913730137311373213733137341373513736137371373813739137401374113742137431374413745137461374713748137491375013751137521375313754137551375613757137581375913760137611376213763137641376513766137671376813769137701377113772137731377413775137761377713778137791378013781137821378313784137851378613787137881378913790137911379213793137941379513796137971379813799138001380113802138031380413805138061380713808138091381013811138121381313814138151381613817138181381913820138211382213823138241382513826138271382813829138301383113832138331383413835138361383713838138391384013841138421384313844138451384613847138481384913850138511385213853138541385513856138571385813859138601386113862138631386413865138661386713868138691387013871138721387313874138751387613877138781387913880138811388213883138841388513886138871388813889138901389113892138931389413895138961389713898138991390013901139021390313904139051390613907139081390913910139111391213913139141391513916139171391813919139201392113922139231392413925139261392713928139291393013931139321393313934139351393613937139381393913940139411394213943139441394513946139471394813949139501395113952139531395413955139561395713958139591396013961139621396313964139651396613967139681396913970139711397213973139741397513976139771397813979139801398113982139831398413985139861398713988139891399013991139921399313994139951399613997139981399914000140011400214003140041400514006140071400814009140101401114012140131401414015140161401714018140191402014021140221402314024140251402614027140281402914030140311403214033140341403514036140371403814039140401404114042140431404414045140461404714048140491405014051140521405314054140551405614057140581405914060140611406214063140641406514066140671406814069140701407114072140731407414075140761407714078140791408014081140821408314084140851408614087140881408914090140911409214093140941409514096140971409814099141001410114102141031410414105141061410714108141091411014111141121411314114141151411614117141181411914120141211412214123141241412514126141271412814129141301413114132141331413414135141361413714138141391414014141141421414314144141451414614147141481414914150141511415214153141541415514156141571415814159141601416114162141631416414165141661416714168141691417014171141721417314174141751417614177141781417914180141811418214183141841418514186141871418814189141901419114192141931419414195141961419714198141991420014201142021420314204142051420614207142081420914210142111421214213142141421514216142171421814219142201422114222142231422414225142261422714228142291423014231142321423314234142351423614237142381423914240142411424214243142441424514246142471424814249142501425114252142531425414255142561425714258142591426014261142621426314264142651426614267142681426914270142711427214273142741427514276142771427814279142801428114282142831428414285142861428714288142891429014291142921429314294142951429614297142981429914300143011430214303143041430514306143071430814309143101431114312143131431414315143161431714318143191432014321143221432314324143251432614327143281432914330143311433214333143341433514336143371433814339143401434114342143431434414345143461434714348143491435014351143521435314354143551435614357143581435914360143611436214363143641436514366143671436814369143701437114372143731437414375143761437714378143791438014381143821438314384143851438614387143881438914390143911439214393143941439514396143971439814399144001440114402144031440414405144061440714408144091441014411144121441314414144151441614417144181441914420144211442214423144241442514426144271442814429144301443114432144331443414435144361443714438144391444014441144421444314444144451444614447144481444914450144511445214453144541445514456144571445814459144601446114462144631446414465144661446714468144691447014471144721447314474144751447614477144781447914480144811448214483144841448514486144871448814489144901449114492144931449414495144961449714498144991450014501145021450314504145051450614507145081450914510145111451214513145141451514516145171451814519145201452114522145231452414525145261452714528145291453014531145321453314534145351453614537145381453914540145411454214543145441454514546145471454814549145501455114552145531455414555145561455714558145591456014561145621456314564145651456614567145681456914570145711457214573145741457514576145771457814579145801458114582145831458414585145861458714588145891459014591145921459314594145951459614597145981459914600146011460214603146041460514606146071460814609146101461114612146131461414615146161461714618146191462014621146221462314624146251462614627146281462914630146311463214633146341463514636146371463814639146401464114642146431464414645146461464714648146491465014651146521465314654146551465614657146581465914660146611466214663146641466514666146671466814669146701467114672146731467414675146761467714678146791468014681146821468314684146851468614687146881468914690146911469214693146941469514696146971469814699147001470114702147031470414705147061470714708147091471014711147121471314714147151471614717147181471914720147211472214723147241472514726147271472814729147301473114732147331473414735147361473714738147391474014741147421474314744147451474614747147481474914750147511475214753147541475514756147571475814759147601476114762147631476414765147661476714768147691477014771147721477314774147751477614777147781477914780147811478214783147841478514786147871478814789147901479114792147931479414795147961479714798147991480014801148021480314804148051480614807148081480914810148111481214813148141481514816148171481814819148201482114822148231482414825148261482714828148291483014831148321483314834148351483614837148381483914840148411484214843148441484514846148471484814849148501485114852148531485414855148561485714858148591486014861148621486314864148651486614867148681486914870148711487214873148741487514876148771487814879148801488114882148831488414885148861488714888148891489014891148921489314894148951489614897148981489914900149011490214903149041490514906149071490814909149101491114912149131491414915149161491714918149191492014921149221492314924149251492614927149281492914930149311493214933149341493514936149371493814939149401494114942149431494414945149461494714948149491495014951149521495314954149551495614957149581495914960149611496214963149641496514966149671496814969149701497114972149731497414975149761497714978149791498014981149821498314984149851498614987149881498914990149911499214993149941499514996149971499814999150001500115002150031500415005150061500715008150091501015011150121501315014150151501615017150181501915020150211502215023150241502515026150271502815029150301503115032150331503415035150361503715038150391504015041150421504315044150451504615047150481504915050150511505215053150541505515056150571505815059150601506115062150631506415065150661506715068150691507015071
  1. /*
  2. *
  3. Copyright (c) Eicon Networks, 2002.
  4. *
  5. This source file is supplied for the use with
  6. Eicon Networks range of DIVA Server Adapters.
  7. *
  8. Eicon File Revision : 2.1
  9. *
  10. This program is free software; you can redistribute it and/or modify
  11. it under the terms of the GNU General Public License as published by
  12. the Free Software Foundation; either version 2, or (at your option)
  13. any later version.
  14. *
  15. This program is distributed in the hope that it will be useful,
  16. but WITHOUT ANY WARRANTY OF ANY KIND WHATSOEVER INCLUDING ANY
  17. implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  18. See the GNU General Public License for more details.
  19. *
  20. You should have received a copy of the GNU General Public License
  21. along with this program; if not, write to the Free Software
  22. Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  23. *
  24. */
  25. #include "platform.h"
  26. #include "di_defs.h"
  27. #include "pc.h"
  28. #include "capi20.h"
  29. #include "divacapi.h"
  30. #include "mdm_msg.h"
  31. #include "divasync.h"
  32. #define FILE_ "MESSAGE.C"
  33. #define dprintf
  34. /*------------------------------------------------------------------*/
  35. /* This is options supported for all adapters that are server by */
  36. /* XDI driver. Allo it is not necessary to ask it from every adapter*/
  37. /* and it is not necessary to save it separate for every adapter */
  38. /* Macrose defined here have only local meaning */
  39. /*------------------------------------------------------------------*/
  40. static dword diva_xdi_extended_features = 0;
  41. #define DIVA_CAPI_USE_CMA 0x00000001
  42. #define DIVA_CAPI_XDI_PROVIDES_SDRAM_BAR 0x00000002
  43. #define DIVA_CAPI_XDI_PROVIDES_NO_CANCEL 0x00000004
  44. #define DIVA_CAPI_XDI_PROVIDES_RX_DMA 0x00000008
  45. /*
  46. CAPI can request to process all return codes self only if:
  47. protocol code supports this && xdi supports this
  48. */
  49. #define DIVA_CAPI_SUPPORTS_NO_CANCEL(__a__) (((__a__)->manufacturer_features&MANUFACTURER_FEATURE_XONOFF_FLOW_CONTROL)&& ((__a__)->manufacturer_features & MANUFACTURER_FEATURE_OK_FC_LABEL) && (diva_xdi_extended_features & DIVA_CAPI_XDI_PROVIDES_NO_CANCEL))
  50. /*------------------------------------------------------------------*/
  51. /* local function prototypes */
  52. /*------------------------------------------------------------------*/
  53. static void group_optimization(DIVA_CAPI_ADAPTER * a, PLCI * plci);
  54. static void set_group_ind_mask (PLCI *plci);
  55. static void clear_group_ind_mask_bit (PLCI *plci, word b);
  56. static byte test_group_ind_mask_bit (PLCI *plci, word b);
  57. void AutomaticLaw(DIVA_CAPI_ADAPTER *);
  58. word CapiRelease(word);
  59. word CapiRegister(word);
  60. word api_put(APPL *, CAPI_MSG *);
  61. static word api_parse(byte *, word, byte *, API_PARSE *);
  62. static void api_save_msg(API_PARSE *in, byte *format, API_SAVE *out);
  63. static void api_load_msg(API_SAVE *in, API_PARSE *out);
  64. word api_remove_start(void);
  65. void api_remove_complete(void);
  66. static void plci_remove(PLCI *);
  67. static void diva_get_extended_adapter_features (DIVA_CAPI_ADAPTER * a);
  68. static void diva_ask_for_xdi_sdram_bar (DIVA_CAPI_ADAPTER *, IDI_SYNC_REQ *);
  69. void callback(ENTITY *);
  70. static void control_rc(PLCI *, byte, byte, byte, byte, byte);
  71. static void data_rc(PLCI *, byte);
  72. static void data_ack(PLCI *, byte);
  73. static void sig_ind(PLCI *);
  74. static void SendInfo(PLCI *, dword, byte * *, byte);
  75. static void SendSetupInfo(APPL *, PLCI *, dword, byte * *, byte);
  76. static void SendSSExtInd(APPL *, PLCI * plci, dword Id, byte * * parms);
  77. static void VSwitchReqInd(PLCI *plci, dword Id, byte **parms);
  78. static void nl_ind(PLCI *);
  79. static byte connect_req(dword, word, DIVA_CAPI_ADAPTER *, PLCI *, APPL *, API_PARSE *);
  80. static byte connect_res(dword, word, DIVA_CAPI_ADAPTER *, PLCI *, APPL *, API_PARSE *);
  81. static byte connect_a_res(dword,word, DIVA_CAPI_ADAPTER *, PLCI *, APPL *, API_PARSE *);
  82. static byte disconnect_req(dword, word, DIVA_CAPI_ADAPTER *, PLCI *, APPL *, API_PARSE *);
  83. static byte disconnect_res(dword, word, DIVA_CAPI_ADAPTER *, PLCI *, APPL *, API_PARSE *);
  84. static byte listen_req(dword, word, DIVA_CAPI_ADAPTER *, PLCI *, APPL *, API_PARSE *);
  85. static byte info_req(dword, word, DIVA_CAPI_ADAPTER *, PLCI *, APPL *, API_PARSE *);
  86. static byte info_res(dword, word, DIVA_CAPI_ADAPTER *, PLCI *, APPL *, API_PARSE *);
  87. static byte alert_req(dword, word, DIVA_CAPI_ADAPTER *, PLCI *, APPL *, API_PARSE *);
  88. static byte facility_req(dword, word, DIVA_CAPI_ADAPTER *, PLCI *, APPL *, API_PARSE *);
  89. static byte facility_res(dword, word, DIVA_CAPI_ADAPTER *, PLCI *, APPL *, API_PARSE *);
  90. static byte connect_b3_req(dword, word, DIVA_CAPI_ADAPTER *, PLCI *, APPL *, API_PARSE *);
  91. static byte connect_b3_res(dword, word, DIVA_CAPI_ADAPTER *, PLCI *, APPL *, API_PARSE *);
  92. static byte connect_b3_a_res(dword, word, DIVA_CAPI_ADAPTER *, PLCI *, APPL *, API_PARSE *);
  93. static byte disconnect_b3_req(dword, word, DIVA_CAPI_ADAPTER *, PLCI *, APPL *, API_PARSE *);
  94. static byte disconnect_b3_res(dword, word, DIVA_CAPI_ADAPTER *, PLCI *, APPL *, API_PARSE *);
  95. static byte data_b3_req(dword, word, DIVA_CAPI_ADAPTER *, PLCI *, APPL *, API_PARSE *);
  96. static byte data_b3_res(dword, word, DIVA_CAPI_ADAPTER *, PLCI *, APPL *, API_PARSE *);
  97. static byte reset_b3_req(dword, word, DIVA_CAPI_ADAPTER *, PLCI *, APPL *, API_PARSE *);
  98. static byte reset_b3_res(dword, word, DIVA_CAPI_ADAPTER *, PLCI *, APPL *, API_PARSE *);
  99. static byte connect_b3_t90_a_res(dword, word, DIVA_CAPI_ADAPTER *, PLCI *, APPL *, API_PARSE *);
  100. static byte select_b_req(dword, word, DIVA_CAPI_ADAPTER *, PLCI *, APPL *, API_PARSE *);
  101. static byte manufacturer_req(dword, word, DIVA_CAPI_ADAPTER *, PLCI *, APPL *, API_PARSE *);
  102. static byte manufacturer_res(dword, word, DIVA_CAPI_ADAPTER *, PLCI *, APPL *, API_PARSE *);
  103. static word get_plci(DIVA_CAPI_ADAPTER *);
  104. static void add_p(PLCI *, byte, byte *);
  105. static void add_s(PLCI * plci, byte code, API_PARSE * p);
  106. static void add_ss(PLCI * plci, byte code, API_PARSE * p);
  107. static void add_ie(PLCI * plci, byte code, byte * p, word p_length);
  108. static void add_d(PLCI *, word, byte *);
  109. static void add_ai(PLCI *, API_PARSE *);
  110. static word add_b1(PLCI *, API_PARSE *, word, word);
  111. static word add_b23(PLCI *, API_PARSE *);
  112. static word add_modem_b23 (PLCI * plci, API_PARSE* bp_parms);
  113. static void sig_req(PLCI *, byte, byte);
  114. static void nl_req_ncci(PLCI *, byte, byte);
  115. static void send_req(PLCI *);
  116. static void send_data(PLCI *);
  117. static word plci_remove_check(PLCI *);
  118. static void listen_check(DIVA_CAPI_ADAPTER *);
  119. static byte AddInfo(byte **, byte **, byte *, byte *);
  120. static byte getChannel(API_PARSE *);
  121. static void IndParse(PLCI *, word *, byte **, byte);
  122. static byte ie_compare(byte *, byte *);
  123. static word find_cip(DIVA_CAPI_ADAPTER *, byte *, byte *);
  124. static word CPN_filter_ok(byte *cpn,DIVA_CAPI_ADAPTER *,word);
  125. /*
  126. XON protocol helpers
  127. */
  128. static void channel_flow_control_remove (PLCI * plci);
  129. static void channel_x_off (PLCI * plci, byte ch, byte flag);
  130. static void channel_x_on (PLCI * plci, byte ch);
  131. static void channel_request_xon (PLCI * plci, byte ch);
  132. static void channel_xmit_xon (PLCI * plci);
  133. static int channel_can_xon (PLCI * plci, byte ch);
  134. static void channel_xmit_extended_xon (PLCI * plci);
  135. static byte SendMultiIE(PLCI * plci, dword Id, byte * * parms, byte ie_type, dword info_mask, byte setupParse);
  136. static word AdvCodecSupport(DIVA_CAPI_ADAPTER *, PLCI *, APPL *, byte);
  137. static void CodecIdCheck(DIVA_CAPI_ADAPTER *, PLCI *);
  138. static void SetVoiceChannel(PLCI *, byte *, DIVA_CAPI_ADAPTER * );
  139. static void VoiceChannelOff(PLCI *plci);
  140. static void adv_voice_write_coefs (PLCI *plci, word write_command);
  141. static void adv_voice_clear_config (PLCI *plci);
  142. static word get_b1_facilities (PLCI * plci, byte b1_resource);
  143. static byte add_b1_facilities (PLCI * plci, byte b1_resource, word b1_facilities);
  144. static void adjust_b1_facilities (PLCI *plci, byte new_b1_resource, word new_b1_facilities);
  145. static word adjust_b_process (dword Id, PLCI *plci, byte Rc);
  146. static void adjust_b1_resource (dword Id, PLCI *plci, API_SAVE *bp_msg, word b1_facilities, word internal_command);
  147. static void adjust_b_restore (dword Id, PLCI *plci, byte Rc);
  148. static void reset_b3_command (dword Id, PLCI *plci, byte Rc);
  149. static void select_b_command (dword Id, PLCI *plci, byte Rc);
  150. static void fax_connect_ack_command (dword Id, PLCI *plci, byte Rc);
  151. static void fax_edata_ack_command (dword Id, PLCI *plci, byte Rc);
  152. static void fax_connect_info_command (dword Id, PLCI *plci, byte Rc);
  153. static void fax_adjust_b23_command (dword Id, PLCI *plci, byte Rc);
  154. static void fax_disconnect_command (dword Id, PLCI *plci, byte Rc);
  155. static void hold_save_command (dword Id, PLCI *plci, byte Rc);
  156. static void retrieve_restore_command (dword Id, PLCI *plci, byte Rc);
  157. static void init_b1_config (PLCI *plci);
  158. static void clear_b1_config (PLCI *plci);
  159. static void dtmf_command (dword Id, PLCI *plci, byte Rc);
  160. static byte dtmf_request (dword Id, word Number, DIVA_CAPI_ADAPTER *a, PLCI *plci, APPL *appl, API_PARSE *msg);
  161. static void dtmf_confirmation (dword Id, PLCI *plci);
  162. static void dtmf_indication (dword Id, PLCI *plci, byte *msg, word length);
  163. static void dtmf_parameter_write (PLCI *plci);
  164. static void mixer_set_bchannel_id_esc (PLCI *plci, byte bchannel_id);
  165. static void mixer_set_bchannel_id (PLCI *plci, byte *chi);
  166. static void mixer_clear_config (PLCI *plci);
  167. static void mixer_notify_update (PLCI *plci, byte others);
  168. static void mixer_command (dword Id, PLCI *plci, byte Rc);
  169. static byte mixer_request (dword Id, word Number, DIVA_CAPI_ADAPTER *a, PLCI *plci, APPL *appl, API_PARSE *msg);
  170. static void mixer_indication_coefs_set (dword Id, PLCI *plci);
  171. static void mixer_indication_xconnect_from (dword Id, PLCI *plci, byte *msg, word length);
  172. static void mixer_indication_xconnect_to (dword Id, PLCI *plci, byte *msg, word length);
  173. static void mixer_remove (PLCI *plci);
  174. static void ec_command (dword Id, PLCI *plci, byte Rc);
  175. static byte ec_request (dword Id, word Number, DIVA_CAPI_ADAPTER *a, PLCI *plci, APPL *appl, API_PARSE *msg);
  176. static void ec_indication (dword Id, PLCI *plci, byte *msg, word length);
  177. static void rtp_connect_b3_req_command (dword Id, PLCI *plci, byte Rc);
  178. static void rtp_connect_b3_res_command (dword Id, PLCI *plci, byte Rc);
  179. static int diva_get_dma_descriptor (PLCI *plci, dword *dma_magic);
  180. static void diva_free_dma_descriptor (PLCI *plci, int nr);
  181. /*------------------------------------------------------------------*/
  182. /* external function prototypes */
  183. /*------------------------------------------------------------------*/
  184. extern byte MapController (byte);
  185. extern byte UnMapController (byte);
  186. #define MapId(Id) (((Id) & 0xffffff00L) | MapController ((byte)(Id)))
  187. #define UnMapId(Id) (((Id) & 0xffffff00L) | UnMapController ((byte)(Id)))
  188. void sendf(APPL *, word, dword, word, byte *, ...);
  189. void * TransmitBufferSet(APPL * appl, dword ref);
  190. void * TransmitBufferGet(APPL * appl, void * p);
  191. void TransmitBufferFree(APPL * appl, void * p);
  192. void * ReceiveBufferGet(APPL * appl, int Num);
  193. int fax_head_line_time (char *buffer);
  194. /*------------------------------------------------------------------*/
  195. /* Global data definitions */
  196. /*------------------------------------------------------------------*/
  197. extern byte max_adapter;
  198. extern byte max_appl;
  199. extern DIVA_CAPI_ADAPTER * adapter;
  200. extern APPL * application;
  201. static byte remove_started = false;
  202. static PLCI dummy_plci;
  203. static struct _ftable {
  204. word command;
  205. byte * format;
  206. byte (* function)(dword, word, DIVA_CAPI_ADAPTER *, PLCI *, APPL *, API_PARSE *);
  207. } ftable[] = {
  208. {_DATA_B3_R, "dwww", data_b3_req},
  209. {_DATA_B3_I|RESPONSE, "w", data_b3_res},
  210. {_INFO_R, "ss", info_req},
  211. {_INFO_I|RESPONSE, "", info_res},
  212. {_CONNECT_R, "wsssssssss", connect_req},
  213. {_CONNECT_I|RESPONSE, "wsssss", connect_res},
  214. {_CONNECT_ACTIVE_I|RESPONSE, "", connect_a_res},
  215. {_DISCONNECT_R, "s", disconnect_req},
  216. {_DISCONNECT_I|RESPONSE, "", disconnect_res},
  217. {_LISTEN_R, "dddss", listen_req},
  218. {_ALERT_R, "s", alert_req},
  219. {_FACILITY_R, "ws", facility_req},
  220. {_FACILITY_I|RESPONSE, "ws", facility_res},
  221. {_CONNECT_B3_R, "s", connect_b3_req},
  222. {_CONNECT_B3_I|RESPONSE, "ws", connect_b3_res},
  223. {_CONNECT_B3_ACTIVE_I|RESPONSE, "", connect_b3_a_res},
  224. {_DISCONNECT_B3_R, "s", disconnect_b3_req},
  225. {_DISCONNECT_B3_I|RESPONSE, "", disconnect_b3_res},
  226. {_RESET_B3_R, "s", reset_b3_req},
  227. {_RESET_B3_I|RESPONSE, "", reset_b3_res},
  228. {_CONNECT_B3_T90_ACTIVE_I|RESPONSE, "ws", connect_b3_t90_a_res},
  229. {_CONNECT_B3_T90_ACTIVE_I|RESPONSE, "", connect_b3_t90_a_res},
  230. {_SELECT_B_REQ, "s", select_b_req},
  231. {_MANUFACTURER_R, "dws", manufacturer_req},
  232. {_MANUFACTURER_I|RESPONSE, "dws", manufacturer_res},
  233. {_MANUFACTURER_I|RESPONSE, "", manufacturer_res}
  234. };
  235. static byte * cip_bc[29][2] = {
  236. { "", "" }, /* 0 */
  237. { "\x03\x80\x90\xa3", "\x03\x80\x90\xa2" }, /* 1 */
  238. { "\x02\x88\x90", "\x02\x88\x90" }, /* 2 */
  239. { "\x02\x89\x90", "\x02\x89\x90" }, /* 3 */
  240. { "\x03\x90\x90\xa3", "\x03\x90\x90\xa2" }, /* 4 */
  241. { "\x03\x91\x90\xa5", "\x03\x91\x90\xa5" }, /* 5 */
  242. { "\x02\x98\x90", "\x02\x98\x90" }, /* 6 */
  243. { "\x04\x88\xc0\xc6\xe6", "\x04\x88\xc0\xc6\xe6" }, /* 7 */
  244. { "\x04\x88\x90\x21\x8f", "\x04\x88\x90\x21\x8f" }, /* 8 */
  245. { "\x03\x91\x90\xa5", "\x03\x91\x90\xa5" }, /* 9 */
  246. { "", "" }, /* 10 */
  247. { "", "" }, /* 11 */
  248. { "", "" }, /* 12 */
  249. { "", "" }, /* 13 */
  250. { "", "" }, /* 14 */
  251. { "", "" }, /* 15 */
  252. { "\x03\x80\x90\xa3", "\x03\x80\x90\xa2" }, /* 16 */
  253. { "\x03\x90\x90\xa3", "\x03\x90\x90\xa2" }, /* 17 */
  254. { "\x02\x88\x90", "\x02\x88\x90" }, /* 18 */
  255. { "\x02\x88\x90", "\x02\x88\x90" }, /* 19 */
  256. { "\x02\x88\x90", "\x02\x88\x90" }, /* 20 */
  257. { "\x02\x88\x90", "\x02\x88\x90" }, /* 21 */
  258. { "\x02\x88\x90", "\x02\x88\x90" }, /* 22 */
  259. { "\x02\x88\x90", "\x02\x88\x90" }, /* 23 */
  260. { "\x02\x88\x90", "\x02\x88\x90" }, /* 24 */
  261. { "\x02\x88\x90", "\x02\x88\x90" }, /* 25 */
  262. { "\x03\x91\x90\xa5", "\x03\x91\x90\xa5" }, /* 26 */
  263. { "\x03\x91\x90\xa5", "\x03\x91\x90\xa5" }, /* 27 */
  264. { "\x02\x88\x90", "\x02\x88\x90" } /* 28 */
  265. };
  266. static byte * cip_hlc[29] = {
  267. "", /* 0 */
  268. "", /* 1 */
  269. "", /* 2 */
  270. "", /* 3 */
  271. "", /* 4 */
  272. "", /* 5 */
  273. "", /* 6 */
  274. "", /* 7 */
  275. "", /* 8 */
  276. "", /* 9 */
  277. "", /* 10 */
  278. "", /* 11 */
  279. "", /* 12 */
  280. "", /* 13 */
  281. "", /* 14 */
  282. "", /* 15 */
  283. "\x02\x91\x81", /* 16 */
  284. "\x02\x91\x84", /* 17 */
  285. "\x02\x91\xa1", /* 18 */
  286. "\x02\x91\xa4", /* 19 */
  287. "\x02\x91\xa8", /* 20 */
  288. "\x02\x91\xb1", /* 21 */
  289. "\x02\x91\xb2", /* 22 */
  290. "\x02\x91\xb5", /* 23 */
  291. "\x02\x91\xb8", /* 24 */
  292. "\x02\x91\xc1", /* 25 */
  293. "\x02\x91\x81", /* 26 */
  294. "\x03\x91\xe0\x01", /* 27 */
  295. "\x03\x91\xe0\x02" /* 28 */
  296. };
  297. /*------------------------------------------------------------------*/
  298. #define V120_HEADER_LENGTH 1
  299. #define V120_HEADER_EXTEND_BIT 0x80
  300. #define V120_HEADER_BREAK_BIT 0x40
  301. #define V120_HEADER_C1_BIT 0x04
  302. #define V120_HEADER_C2_BIT 0x08
  303. #define V120_HEADER_FLUSH_COND (V120_HEADER_BREAK_BIT | V120_HEADER_C1_BIT | V120_HEADER_C2_BIT)
  304. static byte v120_default_header[] =
  305. {
  306. 0x83 /* Ext, BR , res, res, C2 , C1 , B , F */
  307. };
  308. static byte v120_break_header[] =
  309. {
  310. 0xc3 | V120_HEADER_BREAK_BIT /* Ext, BR , res, res, C2 , C1 , B , F */
  311. };
  312. /*------------------------------------------------------------------*/
  313. /* API_PUT function */
  314. /*------------------------------------------------------------------*/
  315. word api_put(APPL * appl, CAPI_MSG * msg)
  316. {
  317. word i, j, k, l, n;
  318. word ret;
  319. byte c;
  320. byte controller;
  321. DIVA_CAPI_ADAPTER * a;
  322. PLCI * plci;
  323. NCCI * ncci_ptr;
  324. word ncci;
  325. CAPI_MSG *m;
  326. API_PARSE msg_parms[MAX_MSG_PARMS+1];
  327. if (msg->header.length < sizeof (msg->header) ||
  328. msg->header.length > MAX_MSG_SIZE) {
  329. dbug(1,dprintf("bad len"));
  330. return _BAD_MSG;
  331. }
  332. controller = (byte)((msg->header.controller &0x7f)-1);
  333. /* controller starts with 0 up to (max_adapter - 1) */
  334. if ( controller >= max_adapter )
  335. {
  336. dbug(1,dprintf("invalid ctrl"));
  337. return _BAD_MSG;
  338. }
  339. a = &adapter[controller];
  340. plci = NULL;
  341. if ((msg->header.plci != 0) && (msg->header.plci <= a->max_plci) && !a->adapter_disabled)
  342. {
  343. dbug(1,dprintf("plci=%x",msg->header.plci));
  344. plci = &a->plci[msg->header.plci-1];
  345. ncci = GET_WORD(&msg->header.ncci);
  346. if (plci->Id
  347. && (plci->appl
  348. || (plci->State == INC_CON_PENDING)
  349. || (plci->State == INC_CON_ALERT)
  350. || (msg->header.command == (_DISCONNECT_I|RESPONSE)))
  351. && ((ncci == 0)
  352. || (msg->header.command == (_DISCONNECT_B3_I|RESPONSE))
  353. || ((ncci < MAX_NCCI+1) && (a->ncci_plci[ncci] == plci->Id))))
  354. {
  355. i = plci->msg_in_read_pos;
  356. j = plci->msg_in_write_pos;
  357. if (j >= i)
  358. {
  359. if (j + msg->header.length + MSG_IN_OVERHEAD <= MSG_IN_QUEUE_SIZE)
  360. i += MSG_IN_QUEUE_SIZE - j;
  361. else
  362. j = 0;
  363. }
  364. else
  365. {
  366. n = (((CAPI_MSG *)(plci->msg_in_queue))->header.length + MSG_IN_OVERHEAD + 3) & 0xfffc;
  367. if (i > MSG_IN_QUEUE_SIZE - n)
  368. i = MSG_IN_QUEUE_SIZE - n + 1;
  369. i -= j;
  370. }
  371. if (i <= ((msg->header.length + MSG_IN_OVERHEAD + 3) & 0xfffc))
  372. {
  373. dbug(0,dprintf("Q-FULL1(msg) - len=%d write=%d read=%d wrap=%d free=%d",
  374. msg->header.length, plci->msg_in_write_pos,
  375. plci->msg_in_read_pos, plci->msg_in_wrap_pos, i));
  376. return _QUEUE_FULL;
  377. }
  378. c = false;
  379. if ((((byte *) msg) < ((byte *)(plci->msg_in_queue)))
  380. || (((byte *) msg) >= ((byte *)(plci->msg_in_queue)) + sizeof(plci->msg_in_queue)))
  381. {
  382. if (plci->msg_in_write_pos != plci->msg_in_read_pos)
  383. c = true;
  384. }
  385. if (msg->header.command == _DATA_B3_R)
  386. {
  387. if (msg->header.length < 20)
  388. {
  389. dbug(1,dprintf("DATA_B3 REQ wrong length %d", msg->header.length));
  390. return _BAD_MSG;
  391. }
  392. ncci_ptr = &(a->ncci[ncci]);
  393. n = ncci_ptr->data_pending;
  394. l = ncci_ptr->data_ack_pending;
  395. k = plci->msg_in_read_pos;
  396. while (k != plci->msg_in_write_pos)
  397. {
  398. if (k == plci->msg_in_wrap_pos)
  399. k = 0;
  400. if ((((CAPI_MSG *)(&((byte *)(plci->msg_in_queue))[k]))->header.command == _DATA_B3_R)
  401. && (((CAPI_MSG *)(&((byte *)(plci->msg_in_queue))[k]))->header.ncci == ncci))
  402. {
  403. n++;
  404. if (((CAPI_MSG *)(&((byte *)(plci->msg_in_queue))[k]))->info.data_b3_req.Flags & 0x0004)
  405. l++;
  406. }
  407. k += (((CAPI_MSG *)(&((byte *)(plci->msg_in_queue))[k]))->header.length +
  408. MSG_IN_OVERHEAD + 3) & 0xfffc;
  409. }
  410. if ((n >= MAX_DATA_B3) || (l >= MAX_DATA_ACK))
  411. {
  412. dbug(0,dprintf("Q-FULL2(data) - pending=%d/%d ack_pending=%d/%d",
  413. ncci_ptr->data_pending, n, ncci_ptr->data_ack_pending, l));
  414. return _QUEUE_FULL;
  415. }
  416. if (plci->req_in || plci->internal_command)
  417. {
  418. if ((((byte *) msg) >= ((byte *)(plci->msg_in_queue)))
  419. && (((byte *) msg) < ((byte *)(plci->msg_in_queue)) + sizeof(plci->msg_in_queue)))
  420. {
  421. dbug(0,dprintf("Q-FULL3(requeue)"));
  422. return _QUEUE_FULL;
  423. }
  424. c = true;
  425. }
  426. }
  427. else
  428. {
  429. if (plci->req_in || plci->internal_command)
  430. c = true;
  431. else
  432. {
  433. plci->command = msg->header.command;
  434. plci->number = msg->header.number;
  435. }
  436. }
  437. if (c)
  438. {
  439. dbug(1,dprintf("enqueue msg(0x%04x,0x%x,0x%x) - len=%d write=%d read=%d wrap=%d free=%d",
  440. msg->header.command, plci->req_in, plci->internal_command,
  441. msg->header.length, plci->msg_in_write_pos,
  442. plci->msg_in_read_pos, plci->msg_in_wrap_pos, i));
  443. if (j == 0)
  444. plci->msg_in_wrap_pos = plci->msg_in_write_pos;
  445. m = (CAPI_MSG *)(&((byte *)(plci->msg_in_queue))[j]);
  446. for (i = 0; i < msg->header.length; i++)
  447. ((byte *)(plci->msg_in_queue))[j++] = ((byte *) msg)[i];
  448. if (m->header.command == _DATA_B3_R)
  449. {
  450. m->info.data_b3_req.Data = (dword)(long)(TransmitBufferSet (appl, m->info.data_b3_req.Data));
  451. }
  452. j = (j + 3) & 0xfffc;
  453. *((APPL * *)(&((byte *)(plci->msg_in_queue))[j])) = appl;
  454. plci->msg_in_write_pos = j + MSG_IN_OVERHEAD;
  455. return 0;
  456. }
  457. }
  458. else
  459. {
  460. plci = NULL;
  461. }
  462. }
  463. dbug(1,dprintf("com=%x",msg->header.command));
  464. for(j=0;j<MAX_MSG_PARMS+1;j++) msg_parms[j].length = 0;
  465. for(i=0, ret = _BAD_MSG; i < ARRAY_SIZE(ftable); i++) {
  466. if(ftable[i].command==msg->header.command) {
  467. /* break loop if the message is correct, otherwise continue scan */
  468. /* (for example: CONNECT_B3_T90_ACT_RES has two specifications) */
  469. if(!api_parse(msg->info.b,(word)(msg->header.length-12),ftable[i].format,msg_parms)) {
  470. ret = 0;
  471. break;
  472. }
  473. for(j=0;j<MAX_MSG_PARMS+1;j++) msg_parms[j].length = 0;
  474. }
  475. }
  476. if(ret) {
  477. dbug(1,dprintf("BAD_MSG"));
  478. if(plci) plci->command = 0;
  479. return ret;
  480. }
  481. c = ftable[i].function(GET_DWORD(&msg->header.controller),
  482. msg->header.number,
  483. a,
  484. plci,
  485. appl,
  486. msg_parms);
  487. channel_xmit_extended_xon (plci);
  488. if(c==1) send_req(plci);
  489. if(c==2 && plci) plci->req_in = plci->req_in_start = plci->req_out = 0;
  490. if(plci && !plci->req_in) plci->command = 0;
  491. return 0;
  492. }
  493. /*------------------------------------------------------------------*/
  494. /* api_parse function, check the format of api messages */
  495. /*------------------------------------------------------------------*/
  496. static word api_parse(byte *msg, word length, byte *format, API_PARSE *parms)
  497. {
  498. word i;
  499. word p;
  500. for(i=0,p=0; format[i]; i++) {
  501. if(parms)
  502. {
  503. parms[i].info = &msg[p];
  504. }
  505. switch(format[i]) {
  506. case 'b':
  507. p +=1;
  508. break;
  509. case 'w':
  510. p +=2;
  511. break;
  512. case 'd':
  513. p +=4;
  514. break;
  515. case 's':
  516. if(msg[p]==0xff) {
  517. parms[i].info +=2;
  518. parms[i].length = msg[p+1] + (msg[p+2]<<8);
  519. p +=(parms[i].length +3);
  520. }
  521. else {
  522. parms[i].length = msg[p];
  523. p +=(parms[i].length +1);
  524. }
  525. break;
  526. }
  527. if(p>length) return true;
  528. }
  529. if(parms) parms[i].info = NULL;
  530. return false;
  531. }
  532. static void api_save_msg(API_PARSE *in, byte *format, API_SAVE *out)
  533. {
  534. word i, j, n = 0;
  535. byte *p;
  536. p = out->info;
  537. for (i = 0; format[i] != '\0'; i++)
  538. {
  539. out->parms[i].info = p;
  540. out->parms[i].length = in[i].length;
  541. switch (format[i])
  542. {
  543. case 'b':
  544. n = 1;
  545. break;
  546. case 'w':
  547. n = 2;
  548. break;
  549. case 'd':
  550. n = 4;
  551. break;
  552. case 's':
  553. n = in[i].length + 1;
  554. break;
  555. }
  556. for (j = 0; j < n; j++)
  557. *(p++) = in[i].info[j];
  558. }
  559. out->parms[i].info = NULL;
  560. out->parms[i].length = 0;
  561. }
  562. static void api_load_msg(API_SAVE *in, API_PARSE *out)
  563. {
  564. word i;
  565. i = 0;
  566. do
  567. {
  568. out[i].info = in->parms[i].info;
  569. out[i].length = in->parms[i].length;
  570. } while (in->parms[i++].info);
  571. }
  572. /*------------------------------------------------------------------*/
  573. /* CAPI remove function */
  574. /*------------------------------------------------------------------*/
  575. word api_remove_start(void)
  576. {
  577. word i;
  578. word j;
  579. if(!remove_started) {
  580. remove_started = true;
  581. for(i=0;i<max_adapter;i++) {
  582. if(adapter[i].request) {
  583. for(j=0;j<adapter[i].max_plci;j++) {
  584. if(adapter[i].plci[j].Sig.Id) plci_remove(&adapter[i].plci[j]);
  585. }
  586. }
  587. }
  588. return 1;
  589. }
  590. else {
  591. for(i=0;i<max_adapter;i++) {
  592. if(adapter[i].request) {
  593. for(j=0;j<adapter[i].max_plci;j++) {
  594. if(adapter[i].plci[j].Sig.Id) return 1;
  595. }
  596. }
  597. }
  598. }
  599. api_remove_complete();
  600. return 0;
  601. }
  602. /*------------------------------------------------------------------*/
  603. /* internal command queue */
  604. /*------------------------------------------------------------------*/
  605. static void init_internal_command_queue (PLCI *plci)
  606. {
  607. word i;
  608. dbug (1, dprintf ("%s,%d: init_internal_command_queue",
  609. (char *)(FILE_), __LINE__));
  610. plci->internal_command = 0;
  611. for (i = 0; i < MAX_INTERNAL_COMMAND_LEVELS; i++)
  612. plci->internal_command_queue[i] = NULL;
  613. }
  614. static void start_internal_command (dword Id, PLCI *plci, t_std_internal_command command_function)
  615. {
  616. word i;
  617. dbug (1, dprintf ("[%06lx] %s,%d: start_internal_command",
  618. UnMapId (Id), (char *)(FILE_), __LINE__));
  619. if (plci->internal_command == 0)
  620. {
  621. plci->internal_command_queue[0] = command_function;
  622. (* command_function)(Id, plci, OK);
  623. }
  624. else
  625. {
  626. i = 1;
  627. while (plci->internal_command_queue[i] != NULL)
  628. i++;
  629. plci->internal_command_queue[i] = command_function;
  630. }
  631. }
  632. static void next_internal_command (dword Id, PLCI *plci)
  633. {
  634. word i;
  635. dbug (1, dprintf ("[%06lx] %s,%d: next_internal_command",
  636. UnMapId (Id), (char *)(FILE_), __LINE__));
  637. plci->internal_command = 0;
  638. plci->internal_command_queue[0] = NULL;
  639. while (plci->internal_command_queue[1] != NULL)
  640. {
  641. for (i = 0; i < MAX_INTERNAL_COMMAND_LEVELS - 1; i++)
  642. plci->internal_command_queue[i] = plci->internal_command_queue[i+1];
  643. plci->internal_command_queue[MAX_INTERNAL_COMMAND_LEVELS - 1] = NULL;
  644. (*(plci->internal_command_queue[0]))(Id, plci, OK);
  645. if (plci->internal_command != 0)
  646. return;
  647. plci->internal_command_queue[0] = NULL;
  648. }
  649. }
  650. /*------------------------------------------------------------------*/
  651. /* NCCI allocate/remove function */
  652. /*------------------------------------------------------------------*/
  653. static dword ncci_mapping_bug = 0;
  654. static word get_ncci (PLCI *plci, byte ch, word force_ncci)
  655. {
  656. DIVA_CAPI_ADAPTER *a;
  657. word ncci, i, j, k;
  658. a = plci->adapter;
  659. if (!ch || a->ch_ncci[ch])
  660. {
  661. ncci_mapping_bug++;
  662. dbug(1,dprintf("NCCI mapping exists %ld %02x %02x %02x-%02x",
  663. ncci_mapping_bug, ch, force_ncci, a->ncci_ch[a->ch_ncci[ch]], a->ch_ncci[ch]));
  664. ncci = ch;
  665. }
  666. else
  667. {
  668. if (force_ncci)
  669. ncci = force_ncci;
  670. else
  671. {
  672. if ((ch < MAX_NCCI+1) && !a->ncci_ch[ch])
  673. ncci = ch;
  674. else
  675. {
  676. ncci = 1;
  677. while ((ncci < MAX_NCCI+1) && a->ncci_ch[ncci])
  678. ncci++;
  679. if (ncci == MAX_NCCI+1)
  680. {
  681. ncci_mapping_bug++;
  682. i = 1;
  683. do
  684. {
  685. j = 1;
  686. while ((j < MAX_NCCI+1) && (a->ncci_ch[j] != i))
  687. j++;
  688. k = j;
  689. if (j < MAX_NCCI+1)
  690. {
  691. do
  692. {
  693. j++;
  694. } while ((j < MAX_NCCI+1) && (a->ncci_ch[j] != i));
  695. }
  696. } while ((i < MAX_NL_CHANNEL+1) && (j < MAX_NCCI+1));
  697. if (i < MAX_NL_CHANNEL+1)
  698. {
  699. dbug(1,dprintf("NCCI mapping overflow %ld %02x %02x %02x-%02x-%02x",
  700. ncci_mapping_bug, ch, force_ncci, i, k, j));
  701. }
  702. else
  703. {
  704. dbug(1,dprintf("NCCI mapping overflow %ld %02x %02x",
  705. ncci_mapping_bug, ch, force_ncci));
  706. }
  707. ncci = ch;
  708. }
  709. }
  710. a->ncci_plci[ncci] = plci->Id;
  711. a->ncci_state[ncci] = IDLE;
  712. if (!plci->ncci_ring_list)
  713. plci->ncci_ring_list = ncci;
  714. else
  715. a->ncci_next[ncci] = a->ncci_next[plci->ncci_ring_list];
  716. a->ncci_next[plci->ncci_ring_list] = (byte) ncci;
  717. }
  718. a->ncci_ch[ncci] = ch;
  719. a->ch_ncci[ch] = (byte) ncci;
  720. dbug(1,dprintf("NCCI mapping established %ld %02x %02x %02x-%02x",
  721. ncci_mapping_bug, ch, force_ncci, ch, ncci));
  722. }
  723. return (ncci);
  724. }
  725. static void ncci_free_receive_buffers (PLCI *plci, word ncci)
  726. {
  727. DIVA_CAPI_ADAPTER *a;
  728. APPL *appl;
  729. word i, ncci_code;
  730. dword Id;
  731. a = plci->adapter;
  732. Id = (((dword) ncci) << 16) | (((word)(plci->Id)) << 8) | a->Id;
  733. if (ncci)
  734. {
  735. if (a->ncci_plci[ncci] == plci->Id)
  736. {
  737. if (!plci->appl)
  738. {
  739. ncci_mapping_bug++;
  740. dbug(1,dprintf("NCCI mapping appl expected %ld %08lx",
  741. ncci_mapping_bug, Id));
  742. }
  743. else
  744. {
  745. appl = plci->appl;
  746. ncci_code = ncci | (((word) a->Id) << 8);
  747. for (i = 0; i < appl->MaxBuffer; i++)
  748. {
  749. if ((appl->DataNCCI[i] == ncci_code)
  750. && (((byte)(appl->DataFlags[i] >> 8)) == plci->Id))
  751. {
  752. appl->DataNCCI[i] = 0;
  753. }
  754. }
  755. }
  756. }
  757. }
  758. else
  759. {
  760. for (ncci = 1; ncci < MAX_NCCI+1; ncci++)
  761. {
  762. if (a->ncci_plci[ncci] == plci->Id)
  763. {
  764. if (!plci->appl)
  765. {
  766. ncci_mapping_bug++;
  767. dbug(1,dprintf("NCCI mapping no appl %ld %08lx",
  768. ncci_mapping_bug, Id));
  769. }
  770. else
  771. {
  772. appl = plci->appl;
  773. ncci_code = ncci | (((word) a->Id) << 8);
  774. for (i = 0; i < appl->MaxBuffer; i++)
  775. {
  776. if ((appl->DataNCCI[i] == ncci_code)
  777. && (((byte)(appl->DataFlags[i] >> 8)) == plci->Id))
  778. {
  779. appl->DataNCCI[i] = 0;
  780. }
  781. }
  782. }
  783. }
  784. }
  785. }
  786. }
  787. static void cleanup_ncci_data (PLCI *plci, word ncci)
  788. {
  789. NCCI *ncci_ptr;
  790. if (ncci && (plci->adapter->ncci_plci[ncci] == plci->Id))
  791. {
  792. ncci_ptr = &(plci->adapter->ncci[ncci]);
  793. if (plci->appl)
  794. {
  795. while (ncci_ptr->data_pending != 0)
  796. {
  797. if (!plci->data_sent || (ncci_ptr->DBuffer[ncci_ptr->data_out].P != plci->data_sent_ptr))
  798. TransmitBufferFree (plci->appl, ncci_ptr->DBuffer[ncci_ptr->data_out].P);
  799. (ncci_ptr->data_out)++;
  800. if (ncci_ptr->data_out == MAX_DATA_B3)
  801. ncci_ptr->data_out = 0;
  802. (ncci_ptr->data_pending)--;
  803. }
  804. }
  805. ncci_ptr->data_out = 0;
  806. ncci_ptr->data_pending = 0;
  807. ncci_ptr->data_ack_out = 0;
  808. ncci_ptr->data_ack_pending = 0;
  809. }
  810. }
  811. static void ncci_remove (PLCI *plci, word ncci, byte preserve_ncci)
  812. {
  813. DIVA_CAPI_ADAPTER *a;
  814. dword Id;
  815. word i;
  816. a = plci->adapter;
  817. Id = (((dword) ncci) << 16) | (((word)(plci->Id)) << 8) | a->Id;
  818. if (!preserve_ncci)
  819. ncci_free_receive_buffers (plci, ncci);
  820. if (ncci)
  821. {
  822. if (a->ncci_plci[ncci] != plci->Id)
  823. {
  824. ncci_mapping_bug++;
  825. dbug(1,dprintf("NCCI mapping doesn't exist %ld %08lx %02x",
  826. ncci_mapping_bug, Id, preserve_ncci));
  827. }
  828. else
  829. {
  830. cleanup_ncci_data (plci, ncci);
  831. dbug(1,dprintf("NCCI mapping released %ld %08lx %02x %02x-%02x",
  832. ncci_mapping_bug, Id, preserve_ncci, a->ncci_ch[ncci], ncci));
  833. a->ch_ncci[a->ncci_ch[ncci]] = 0;
  834. if (!preserve_ncci)
  835. {
  836. a->ncci_ch[ncci] = 0;
  837. a->ncci_plci[ncci] = 0;
  838. a->ncci_state[ncci] = IDLE;
  839. i = plci->ncci_ring_list;
  840. while ((i != 0) && (a->ncci_next[i] != plci->ncci_ring_list) && (a->ncci_next[i] != ncci))
  841. i = a->ncci_next[i];
  842. if ((i != 0) && (a->ncci_next[i] == ncci))
  843. {
  844. if (i == ncci)
  845. plci->ncci_ring_list = 0;
  846. else if (plci->ncci_ring_list == ncci)
  847. plci->ncci_ring_list = i;
  848. a->ncci_next[i] = a->ncci_next[ncci];
  849. }
  850. a->ncci_next[ncci] = 0;
  851. }
  852. }
  853. }
  854. else
  855. {
  856. for (ncci = 1; ncci < MAX_NCCI+1; ncci++)
  857. {
  858. if (a->ncci_plci[ncci] == plci->Id)
  859. {
  860. cleanup_ncci_data (plci, ncci);
  861. dbug(1,dprintf("NCCI mapping released %ld %08lx %02x %02x-%02x",
  862. ncci_mapping_bug, Id, preserve_ncci, a->ncci_ch[ncci], ncci));
  863. a->ch_ncci[a->ncci_ch[ncci]] = 0;
  864. if (!preserve_ncci)
  865. {
  866. a->ncci_ch[ncci] = 0;
  867. a->ncci_plci[ncci] = 0;
  868. a->ncci_state[ncci] = IDLE;
  869. a->ncci_next[ncci] = 0;
  870. }
  871. }
  872. }
  873. if (!preserve_ncci)
  874. plci->ncci_ring_list = 0;
  875. }
  876. }
  877. /*------------------------------------------------------------------*/
  878. /* PLCI remove function */
  879. /*------------------------------------------------------------------*/
  880. static void plci_free_msg_in_queue (PLCI *plci)
  881. {
  882. word i;
  883. if (plci->appl)
  884. {
  885. i = plci->msg_in_read_pos;
  886. while (i != plci->msg_in_write_pos)
  887. {
  888. if (i == plci->msg_in_wrap_pos)
  889. i = 0;
  890. if (((CAPI_MSG *)(&((byte *)(plci->msg_in_queue))[i]))->header.command == _DATA_B3_R)
  891. {
  892. TransmitBufferFree (plci->appl,
  893. (byte *)(long)(((CAPI_MSG *)(&((byte *)(plci->msg_in_queue))[i]))->info.data_b3_req.Data));
  894. }
  895. i += (((CAPI_MSG *)(&((byte *)(plci->msg_in_queue))[i]))->header.length +
  896. MSG_IN_OVERHEAD + 3) & 0xfffc;
  897. }
  898. }
  899. plci->msg_in_write_pos = MSG_IN_QUEUE_SIZE;
  900. plci->msg_in_read_pos = MSG_IN_QUEUE_SIZE;
  901. plci->msg_in_wrap_pos = MSG_IN_QUEUE_SIZE;
  902. }
  903. static void plci_remove(PLCI * plci)
  904. {
  905. if(!plci) {
  906. dbug(1,dprintf("plci_remove(no plci)"));
  907. return;
  908. }
  909. init_internal_command_queue (plci);
  910. dbug(1,dprintf("plci_remove(%x,tel=%x)",plci->Id,plci->tel));
  911. if(plci_remove_check(plci))
  912. {
  913. return;
  914. }
  915. if (plci->Sig.Id == 0xff)
  916. {
  917. dbug(1,dprintf("D-channel X.25 plci->NL.Id:%0x", plci->NL.Id));
  918. if (plci->NL.Id && !plci->nl_remove_id)
  919. {
  920. nl_req_ncci(plci,REMOVE,0);
  921. send_req(plci);
  922. }
  923. }
  924. else
  925. {
  926. if (!plci->sig_remove_id
  927. && (plci->Sig.Id
  928. || (plci->req_in!=plci->req_out)
  929. || (plci->nl_req || plci->sig_req)))
  930. {
  931. sig_req(plci,HANGUP,0);
  932. send_req(plci);
  933. }
  934. }
  935. ncci_remove (plci, 0, false);
  936. plci_free_msg_in_queue (plci);
  937. plci->channels = 0;
  938. plci->appl = NULL;
  939. if ((plci->State == INC_CON_PENDING) || (plci->State == INC_CON_ALERT))
  940. plci->State = OUTG_DIS_PENDING;
  941. }
  942. /*------------------------------------------------------------------*/
  943. /* Application Group function helpers */
  944. /*------------------------------------------------------------------*/
  945. static void set_group_ind_mask (PLCI *plci)
  946. {
  947. word i;
  948. for (i = 0; i < C_IND_MASK_DWORDS; i++)
  949. plci->group_optimization_mask_table[i] = 0xffffffffL;
  950. }
  951. static void clear_group_ind_mask_bit (PLCI *plci, word b)
  952. {
  953. plci->group_optimization_mask_table[b >> 5] &= ~(1L << (b & 0x1f));
  954. }
  955. static byte test_group_ind_mask_bit (PLCI *plci, word b)
  956. {
  957. return ((plci->group_optimization_mask_table[b >> 5] & (1L << (b & 0x1f))) != 0);
  958. }
  959. /*------------------------------------------------------------------*/
  960. /* c_ind_mask operations for arbitrary MAX_APPL */
  961. /*------------------------------------------------------------------*/
  962. static void clear_c_ind_mask (PLCI *plci)
  963. {
  964. word i;
  965. for (i = 0; i < C_IND_MASK_DWORDS; i++)
  966. plci->c_ind_mask_table[i] = 0;
  967. }
  968. static byte c_ind_mask_empty (PLCI *plci)
  969. {
  970. word i;
  971. i = 0;
  972. while ((i < C_IND_MASK_DWORDS) && (plci->c_ind_mask_table[i] == 0))
  973. i++;
  974. return (i == C_IND_MASK_DWORDS);
  975. }
  976. static void set_c_ind_mask_bit (PLCI *plci, word b)
  977. {
  978. plci->c_ind_mask_table[b >> 5] |= (1L << (b & 0x1f));
  979. }
  980. static void clear_c_ind_mask_bit (PLCI *plci, word b)
  981. {
  982. plci->c_ind_mask_table[b >> 5] &= ~(1L << (b & 0x1f));
  983. }
  984. static byte test_c_ind_mask_bit (PLCI *plci, word b)
  985. {
  986. return ((plci->c_ind_mask_table[b >> 5] & (1L << (b & 0x1f))) != 0);
  987. }
  988. static void dump_c_ind_mask (PLCI *plci)
  989. {
  990. static char hex_digit_table[0x10] =
  991. {'0','1','2','3','4','5','6','7','8','9','a','b','c','d','e','f'};
  992. word i, j, k;
  993. dword d;
  994. char *p;
  995. char buf[40];
  996. for (i = 0; i < C_IND_MASK_DWORDS; i += 4)
  997. {
  998. p = buf + 36;
  999. *p = '\0';
  1000. for (j = 0; j < 4; j++)
  1001. {
  1002. if (i+j < C_IND_MASK_DWORDS)
  1003. {
  1004. d = plci->c_ind_mask_table[i+j];
  1005. for (k = 0; k < 8; k++)
  1006. {
  1007. *(--p) = hex_digit_table[d & 0xf];
  1008. d >>= 4;
  1009. }
  1010. }
  1011. else if (i != 0)
  1012. {
  1013. for (k = 0; k < 8; k++)
  1014. *(--p) = ' ';
  1015. }
  1016. *(--p) = ' ';
  1017. }
  1018. dbug(1,dprintf ("c_ind_mask =%s", (char *) p));
  1019. }
  1020. }
  1021. #define dump_plcis(a)
  1022. /*------------------------------------------------------------------*/
  1023. /* translation function for each message */
  1024. /*------------------------------------------------------------------*/
  1025. static byte connect_req(dword Id, word Number, DIVA_CAPI_ADAPTER *a,
  1026. PLCI *plci, APPL *appl, API_PARSE *parms)
  1027. {
  1028. word ch;
  1029. word i;
  1030. word Info;
  1031. word CIP;
  1032. byte LinkLayer;
  1033. API_PARSE * ai;
  1034. API_PARSE * bp;
  1035. API_PARSE ai_parms[5];
  1036. word channel = 0;
  1037. dword ch_mask;
  1038. byte m;
  1039. static byte esc_chi[35] = {0x02,0x18,0x01};
  1040. static byte lli[2] = {0x01,0x00};
  1041. byte noCh = 0;
  1042. word dir = 0;
  1043. byte *p_chi = "";
  1044. for(i=0;i<5;i++) ai_parms[i].length = 0;
  1045. dbug(1,dprintf("connect_req(%d)",parms->length));
  1046. Info = _WRONG_IDENTIFIER;
  1047. if(a)
  1048. {
  1049. if(a->adapter_disabled)
  1050. {
  1051. dbug(1,dprintf("adapter disabled"));
  1052. Id = ((word)1<<8)|a->Id;
  1053. sendf(appl,_CONNECT_R|CONFIRM,Id,Number,"w",0);
  1054. sendf(appl, _DISCONNECT_I, Id, 0, "w", _L1_ERROR);
  1055. return false;
  1056. }
  1057. Info = _OUT_OF_PLCI;
  1058. if((i=get_plci(a)))
  1059. {
  1060. Info = 0;
  1061. plci = &a->plci[i-1];
  1062. plci->appl = appl;
  1063. plci->call_dir = CALL_DIR_OUT | CALL_DIR_ORIGINATE;
  1064. /* check 'external controller' bit for codec support */
  1065. if(Id & EXT_CONTROLLER)
  1066. {
  1067. if(AdvCodecSupport(a, plci, appl, 0) )
  1068. {
  1069. plci->Id = 0;
  1070. sendf(appl, _CONNECT_R|CONFIRM, Id, Number, "w", _WRONG_IDENTIFIER);
  1071. return 2;
  1072. }
  1073. }
  1074. ai = &parms[9];
  1075. bp = &parms[5];
  1076. ch = 0;
  1077. if(bp->length)LinkLayer = bp->info[3];
  1078. else LinkLayer = 0;
  1079. if(ai->length)
  1080. {
  1081. ch=0xffff;
  1082. if(!api_parse(&ai->info[1],(word)ai->length,"ssss",ai_parms))
  1083. {
  1084. ch = 0;
  1085. if(ai_parms[0].length)
  1086. {
  1087. ch = GET_WORD(ai_parms[0].info+1);
  1088. if(ch>4) ch=0; /* safety -> ignore ChannelID */
  1089. if(ch==4) /* explizit CHI in message */
  1090. {
  1091. /* check length of B-CH struct */
  1092. if((ai_parms[0].info)[3]>=1)
  1093. {
  1094. if((ai_parms[0].info)[4]==CHI)
  1095. {
  1096. p_chi = &((ai_parms[0].info)[5]);
  1097. }
  1098. else
  1099. {
  1100. p_chi = &((ai_parms[0].info)[3]);
  1101. }
  1102. if(p_chi[0]>35) /* check length of channel ID */
  1103. {
  1104. Info = _WRONG_MESSAGE_FORMAT;
  1105. }
  1106. }
  1107. else Info = _WRONG_MESSAGE_FORMAT;
  1108. }
  1109. if(ch==3 && ai_parms[0].length>=7 && ai_parms[0].length<=36)
  1110. {
  1111. dir = GET_WORD(ai_parms[0].info+3);
  1112. ch_mask = 0;
  1113. m = 0x3f;
  1114. for(i=0; i+5<=ai_parms[0].length; i++)
  1115. {
  1116. if(ai_parms[0].info[i+5]!=0)
  1117. {
  1118. if((ai_parms[0].info[i+5] | m) != 0xff)
  1119. Info = _WRONG_MESSAGE_FORMAT;
  1120. else
  1121. {
  1122. if (ch_mask == 0)
  1123. channel = i;
  1124. ch_mask |= 1L << i;
  1125. }
  1126. }
  1127. m = 0;
  1128. }
  1129. if (ch_mask == 0)
  1130. Info = _WRONG_MESSAGE_FORMAT;
  1131. if (!Info)
  1132. {
  1133. if ((ai_parms[0].length == 36) || (ch_mask != ((dword)(1L << channel))))
  1134. {
  1135. esc_chi[0] = (byte)(ai_parms[0].length - 2);
  1136. for(i=0; i+5<=ai_parms[0].length; i++)
  1137. esc_chi[i+3] = ai_parms[0].info[i+5];
  1138. }
  1139. else
  1140. esc_chi[0] = 2;
  1141. esc_chi[2] = (byte)channel;
  1142. plci->b_channel = (byte)channel; /* not correct for ETSI ch 17..31 */
  1143. add_p(plci,LLI,lli);
  1144. add_p(plci,ESC,esc_chi);
  1145. plci->State = LOCAL_CONNECT;
  1146. if(!dir) plci->call_dir |= CALL_DIR_FORCE_OUTG_NL; /* dir 0=DTE, 1=DCE */
  1147. }
  1148. }
  1149. }
  1150. }
  1151. else Info = _WRONG_MESSAGE_FORMAT;
  1152. }
  1153. dbug(1,dprintf("ch=%x,dir=%x,p_ch=%d",ch,dir,channel));
  1154. plci->command = _CONNECT_R;
  1155. plci->number = Number;
  1156. /* x.31 or D-ch free SAPI in LinkLayer? */
  1157. if(ch==1 && LinkLayer!=3 && LinkLayer!=12) noCh = true;
  1158. if((ch==0 || ch==2 || noCh || ch==3 || ch==4) && !Info)
  1159. {
  1160. /* B-channel used for B3 connections (ch==0), or no B channel */
  1161. /* is used (ch==2) or perm. connection (3) is used do a CALL */
  1162. if(noCh) Info = add_b1(plci,&parms[5],2,0); /* no resource */
  1163. else Info = add_b1(plci,&parms[5],ch,0);
  1164. add_s(plci,OAD,&parms[2]);
  1165. add_s(plci,OSA,&parms[4]);
  1166. add_s(plci,BC,&parms[6]);
  1167. add_s(plci,LLC,&parms[7]);
  1168. add_s(plci,HLC,&parms[8]);
  1169. CIP = GET_WORD(parms[0].info);
  1170. if (a->Info_Mask[appl->Id-1] & 0x200)
  1171. {
  1172. /* early B3 connect (CIP mask bit 9) no release after a disc */
  1173. add_p(plci,LLI,"\x01\x01");
  1174. }
  1175. if(GET_WORD(parms[0].info)<29) {
  1176. add_p(plci,BC,cip_bc[GET_WORD(parms[0].info)][a->u_law]);
  1177. add_p(plci,HLC,cip_hlc[GET_WORD(parms[0].info)]);
  1178. }
  1179. add_p(plci,UID,"\x06\x43\x61\x70\x69\x32\x30");
  1180. sig_req(plci,ASSIGN,DSIG_ID);
  1181. }
  1182. else if(ch==1) {
  1183. /* D-Channel used for B3 connections */
  1184. plci->Sig.Id = 0xff;
  1185. Info = 0;
  1186. }
  1187. if(!Info && ch!=2 && !noCh ) {
  1188. Info = add_b23(plci,&parms[5]);
  1189. if(!Info) {
  1190. if(!(plci->tel && !plci->adv_nl))nl_req_ncci(plci,ASSIGN,0);
  1191. }
  1192. }
  1193. if(!Info)
  1194. {
  1195. if(ch==0 || ch==2 || ch==3 || noCh || ch==4)
  1196. {
  1197. if(plci->spoofed_msg==SPOOFING_REQUIRED)
  1198. {
  1199. api_save_msg(parms, "wsssssssss", &plci->saved_msg);
  1200. plci->spoofed_msg = CALL_REQ;
  1201. plci->internal_command = BLOCK_PLCI;
  1202. plci->command = 0;
  1203. dbug(1,dprintf("Spoof"));
  1204. send_req(plci);
  1205. return false;
  1206. }
  1207. if(ch==4)add_p(plci,CHI,p_chi);
  1208. add_s(plci,CPN,&parms[1]);
  1209. add_s(plci,DSA,&parms[3]);
  1210. if(noCh) add_p(plci,ESC,"\x02\x18\xfd"); /* D-channel, no B-L3 */
  1211. add_ai(plci,&parms[9]);
  1212. if(!dir)sig_req(plci,CALL_REQ,0);
  1213. else
  1214. {
  1215. plci->command = PERM_LIST_REQ;
  1216. plci->appl = appl;
  1217. sig_req(plci,LISTEN_REQ,0);
  1218. send_req(plci);
  1219. return false;
  1220. }
  1221. }
  1222. send_req(plci);
  1223. return false;
  1224. }
  1225. plci->Id = 0;
  1226. }
  1227. }
  1228. sendf(appl,
  1229. _CONNECT_R|CONFIRM,
  1230. Id,
  1231. Number,
  1232. "w",Info);
  1233. return 2;
  1234. }
  1235. static byte connect_res(dword Id, word Number, DIVA_CAPI_ADAPTER *a,
  1236. PLCI *plci, APPL *appl, API_PARSE *parms)
  1237. {
  1238. word i, Info;
  1239. word Reject;
  1240. static byte cau_t[] = {0,0,0x90,0x91,0xac,0x9d,0x86,0xd8,0x9b};
  1241. static byte esc_t[] = {0x03,0x08,0x00,0x00};
  1242. API_PARSE * ai;
  1243. API_PARSE ai_parms[5];
  1244. word ch=0;
  1245. if(!plci) {
  1246. dbug(1,dprintf("connect_res(no plci)"));
  1247. return 0; /* no plci, no send */
  1248. }
  1249. dbug(1,dprintf("connect_res(State=0x%x)",plci->State));
  1250. for(i=0;i<5;i++) ai_parms[i].length = 0;
  1251. ai = &parms[5];
  1252. dbug(1,dprintf("ai->length=%d",ai->length));
  1253. if(ai->length)
  1254. {
  1255. if(!api_parse(&ai->info[1],(word)ai->length,"ssss",ai_parms))
  1256. {
  1257. dbug(1,dprintf("ai_parms[0].length=%d/0x%x",ai_parms[0].length,GET_WORD(ai_parms[0].info+1)));
  1258. ch = 0;
  1259. if(ai_parms[0].length)
  1260. {
  1261. ch = GET_WORD(ai_parms[0].info+1);
  1262. dbug(1,dprintf("BCH-I=0x%x",ch));
  1263. }
  1264. }
  1265. }
  1266. if(plci->State==INC_CON_CONNECTED_ALERT)
  1267. {
  1268. dbug(1,dprintf("Connected Alert Call_Res"));
  1269. if (a->Info_Mask[appl->Id-1] & 0x200)
  1270. {
  1271. /* early B3 connect (CIP mask bit 9) no release after a disc */
  1272. add_p(plci,LLI,"\x01\x01");
  1273. }
  1274. add_s(plci, CONN_NR, &parms[2]);
  1275. add_s(plci, LLC, &parms[4]);
  1276. add_ai(plci, &parms[5]);
  1277. plci->State = INC_CON_ACCEPT;
  1278. sig_req(plci, CALL_RES,0);
  1279. return 1;
  1280. }
  1281. else if(plci->State==INC_CON_PENDING || plci->State==INC_CON_ALERT) {
  1282. clear_c_ind_mask_bit (plci, (word)(appl->Id-1));
  1283. dump_c_ind_mask (plci);
  1284. Reject = GET_WORD(parms[0].info);
  1285. dbug(1,dprintf("Reject=0x%x",Reject));
  1286. if(Reject)
  1287. {
  1288. if(c_ind_mask_empty (plci))
  1289. {
  1290. if((Reject&0xff00)==0x3400)
  1291. {
  1292. esc_t[2] = ((byte)(Reject&0x00ff)) | 0x80;
  1293. add_p(plci,ESC,esc_t);
  1294. add_ai(plci, &parms[5]);
  1295. sig_req(plci,REJECT,0);
  1296. }
  1297. else if(Reject==1 || Reject>9)
  1298. {
  1299. add_ai(plci, &parms[5]);
  1300. sig_req(plci,HANGUP,0);
  1301. }
  1302. else
  1303. {
  1304. esc_t[2] = cau_t[(Reject&0x000f)];
  1305. add_p(plci,ESC,esc_t);
  1306. add_ai(plci, &parms[5]);
  1307. sig_req(plci,REJECT,0);
  1308. }
  1309. plci->appl = appl;
  1310. }
  1311. else
  1312. {
  1313. sendf(appl, _DISCONNECT_I, Id, 0, "w", _OTHER_APPL_CONNECTED);
  1314. }
  1315. }
  1316. else {
  1317. plci->appl = appl;
  1318. if(Id & EXT_CONTROLLER){
  1319. if(AdvCodecSupport(a, plci, appl, 0)){
  1320. dbug(1,dprintf("connect_res(error from AdvCodecSupport)"));
  1321. sig_req(plci,HANGUP,0);
  1322. return 1;
  1323. }
  1324. if(plci->tel == ADV_VOICE && a->AdvCodecPLCI)
  1325. {
  1326. Info = add_b23(plci, &parms[1]);
  1327. if (Info)
  1328. {
  1329. dbug(1,dprintf("connect_res(error from add_b23)"));
  1330. sig_req(plci,HANGUP,0);
  1331. return 1;
  1332. }
  1333. if(plci->adv_nl)
  1334. {
  1335. nl_req_ncci(plci, ASSIGN, 0);
  1336. }
  1337. }
  1338. }
  1339. else
  1340. {
  1341. plci->tel = 0;
  1342. if(ch!=2)
  1343. {
  1344. Info = add_b23(plci, &parms[1]);
  1345. if (Info)
  1346. {
  1347. dbug(1,dprintf("connect_res(error from add_b23 2)"));
  1348. sig_req(plci,HANGUP,0);
  1349. return 1;
  1350. }
  1351. }
  1352. nl_req_ncci(plci, ASSIGN, 0);
  1353. }
  1354. if(plci->spoofed_msg==SPOOFING_REQUIRED)
  1355. {
  1356. api_save_msg(parms, "wsssss", &plci->saved_msg);
  1357. plci->spoofed_msg = CALL_RES;
  1358. plci->internal_command = BLOCK_PLCI;
  1359. plci->command = 0;
  1360. dbug(1,dprintf("Spoof"));
  1361. }
  1362. else
  1363. {
  1364. add_b1 (plci, &parms[1], ch, plci->B1_facilities);
  1365. if (a->Info_Mask[appl->Id-1] & 0x200)
  1366. {
  1367. /* early B3 connect (CIP mask bit 9) no release after a disc */
  1368. add_p(plci,LLI,"\x01\x01");
  1369. }
  1370. add_s(plci, CONN_NR, &parms[2]);
  1371. add_s(plci, LLC, &parms[4]);
  1372. add_ai(plci, &parms[5]);
  1373. plci->State = INC_CON_ACCEPT;
  1374. sig_req(plci, CALL_RES,0);
  1375. }
  1376. for(i=0; i<max_appl; i++) {
  1377. if(test_c_ind_mask_bit (plci, i)) {
  1378. sendf(&application[i], _DISCONNECT_I, Id, 0, "w", _OTHER_APPL_CONNECTED);
  1379. }
  1380. }
  1381. }
  1382. }
  1383. return 1;
  1384. }
  1385. static byte connect_a_res(dword Id, word Number, DIVA_CAPI_ADAPTER *a,
  1386. PLCI *plci, APPL *appl, API_PARSE *msg)
  1387. {
  1388. dbug(1,dprintf("connect_a_res"));
  1389. return false;
  1390. }
  1391. static byte disconnect_req(dword Id, word Number, DIVA_CAPI_ADAPTER *a,
  1392. PLCI *plci, APPL *appl, API_PARSE *msg)
  1393. {
  1394. word Info;
  1395. word i;
  1396. dbug(1,dprintf("disconnect_req"));
  1397. Info = _WRONG_IDENTIFIER;
  1398. if(plci)
  1399. {
  1400. if(plci->State==INC_CON_PENDING || plci->State==INC_CON_ALERT)
  1401. {
  1402. clear_c_ind_mask_bit (plci, (word)(appl->Id-1));
  1403. plci->appl = appl;
  1404. for(i=0; i<max_appl; i++)
  1405. {
  1406. if(test_c_ind_mask_bit (plci, i))
  1407. sendf(&application[i], _DISCONNECT_I, Id, 0, "w", 0);
  1408. }
  1409. plci->State = OUTG_DIS_PENDING;
  1410. }
  1411. if(plci->Sig.Id && plci->appl)
  1412. {
  1413. Info = 0;
  1414. if(plci->Sig.Id!=0xff)
  1415. {
  1416. if(plci->State!=INC_DIS_PENDING)
  1417. {
  1418. add_ai(plci, &msg[0]);
  1419. sig_req(plci,HANGUP,0);
  1420. plci->State = OUTG_DIS_PENDING;
  1421. return 1;
  1422. }
  1423. }
  1424. else
  1425. {
  1426. if (plci->NL.Id && !plci->nl_remove_id)
  1427. {
  1428. mixer_remove (plci);
  1429. nl_req_ncci(plci,REMOVE,0);
  1430. sendf(appl,_DISCONNECT_R|CONFIRM,Id,Number,"w",0);
  1431. sendf(appl, _DISCONNECT_I, Id, 0, "w", 0);
  1432. plci->State = INC_DIS_PENDING;
  1433. }
  1434. return 1;
  1435. }
  1436. }
  1437. }
  1438. if(!appl) return false;
  1439. sendf(appl, _DISCONNECT_R|CONFIRM, Id, Number, "w",Info);
  1440. return false;
  1441. }
  1442. static byte disconnect_res(dword Id, word Number, DIVA_CAPI_ADAPTER *a,
  1443. PLCI *plci, APPL *appl, API_PARSE *msg)
  1444. {
  1445. dbug(1,dprintf("disconnect_res"));
  1446. if(plci)
  1447. {
  1448. /* clear ind mask bit, just in case of collsion of */
  1449. /* DISCONNECT_IND and CONNECT_RES */
  1450. clear_c_ind_mask_bit (plci, (word)(appl->Id-1));
  1451. ncci_free_receive_buffers (plci, 0);
  1452. if(plci_remove_check(plci))
  1453. {
  1454. return 0;
  1455. }
  1456. if(plci->State==INC_DIS_PENDING
  1457. || plci->State==SUSPENDING) {
  1458. if(c_ind_mask_empty (plci)) {
  1459. if(plci->State!=SUSPENDING)plci->State = IDLE;
  1460. dbug(1,dprintf("chs=%d",plci->channels));
  1461. if(!plci->channels) {
  1462. plci_remove(plci);
  1463. }
  1464. }
  1465. }
  1466. }
  1467. return 0;
  1468. }
  1469. static byte listen_req(dword Id, word Number, DIVA_CAPI_ADAPTER *a,
  1470. PLCI *plci, APPL *appl, API_PARSE *parms)
  1471. {
  1472. word Info;
  1473. byte i;
  1474. dbug(1,dprintf("listen_req(Appl=0x%x)",appl->Id));
  1475. Info = _WRONG_IDENTIFIER;
  1476. if(a) {
  1477. Info = 0;
  1478. a->Info_Mask[appl->Id-1] = GET_DWORD(parms[0].info);
  1479. a->CIP_Mask[appl->Id-1] = GET_DWORD(parms[1].info);
  1480. dbug(1,dprintf("CIP_MASK=0x%lx",GET_DWORD(parms[1].info)));
  1481. if (a->Info_Mask[appl->Id-1] & 0x200){ /* early B3 connect provides */
  1482. a->Info_Mask[appl->Id-1] |= 0x10; /* call progression infos */
  1483. }
  1484. /* check if external controller listen and switch listen on or off*/
  1485. if(Id&EXT_CONTROLLER && GET_DWORD(parms[1].info)){
  1486. if(a->profile.Global_Options & ON_BOARD_CODEC) {
  1487. dummy_plci.State = IDLE;
  1488. a->codec_listen[appl->Id-1] = &dummy_plci;
  1489. a->TelOAD[0] = (byte)(parms[3].length);
  1490. for(i=1;parms[3].length>=i && i<22;i++) {
  1491. a->TelOAD[i] = parms[3].info[i];
  1492. }
  1493. a->TelOAD[i] = 0;
  1494. a->TelOSA[0] = (byte)(parms[4].length);
  1495. for(i=1;parms[4].length>=i && i<22;i++) {
  1496. a->TelOSA[i] = parms[4].info[i];
  1497. }
  1498. a->TelOSA[i] = 0;
  1499. }
  1500. else Info = 0x2002; /* wrong controller, codec not supported */
  1501. }
  1502. else{ /* clear listen */
  1503. a->codec_listen[appl->Id-1] = (PLCI *)0;
  1504. }
  1505. }
  1506. sendf(appl,
  1507. _LISTEN_R|CONFIRM,
  1508. Id,
  1509. Number,
  1510. "w",Info);
  1511. if (a) listen_check(a);
  1512. return false;
  1513. }
  1514. static byte info_req(dword Id, word Number, DIVA_CAPI_ADAPTER *a,
  1515. PLCI *plci, APPL *appl, API_PARSE *msg)
  1516. {
  1517. word i;
  1518. API_PARSE * ai;
  1519. PLCI * rc_plci = NULL;
  1520. API_PARSE ai_parms[5];
  1521. word Info = 0;
  1522. dbug(1,dprintf("info_req"));
  1523. for(i=0;i<5;i++) ai_parms[i].length = 0;
  1524. ai = &msg[1];
  1525. if(ai->length)
  1526. {
  1527. if(api_parse(&ai->info[1],(word)ai->length,"ssss",ai_parms))
  1528. {
  1529. dbug(1,dprintf("AddInfo wrong"));
  1530. Info = _WRONG_MESSAGE_FORMAT;
  1531. }
  1532. }
  1533. if(!a) Info = _WRONG_STATE;
  1534. if(!Info && plci)
  1535. { /* no fac, with CPN, or KEY */
  1536. rc_plci = plci;
  1537. if(!ai_parms[3].length && plci->State && (msg[0].length || ai_parms[1].length) )
  1538. {
  1539. /* overlap sending option */
  1540. dbug(1,dprintf("OvlSnd"));
  1541. add_s(plci,CPN,&msg[0]);
  1542. add_s(plci,KEY,&ai_parms[1]);
  1543. sig_req(plci,INFO_REQ,0);
  1544. send_req(plci);
  1545. return false;
  1546. }
  1547. if(plci->State && ai_parms[2].length)
  1548. {
  1549. /* User_Info option */
  1550. dbug(1,dprintf("UUI"));
  1551. add_s(plci,UUI,&ai_parms[2]);
  1552. sig_req(plci,USER_DATA,0);
  1553. }
  1554. else if(plci->State && ai_parms[3].length)
  1555. {
  1556. /* Facility option */
  1557. dbug(1,dprintf("FAC"));
  1558. add_s(plci,CPN,&msg[0]);
  1559. add_ai(plci, &msg[1]);
  1560. sig_req(plci,FACILITY_REQ,0);
  1561. }
  1562. else
  1563. {
  1564. Info = _WRONG_STATE;
  1565. }
  1566. }
  1567. else if((ai_parms[1].length || ai_parms[2].length || ai_parms[3].length) && !Info)
  1568. {
  1569. /* NCR_Facility option -> send UUI and Keypad too */
  1570. dbug(1,dprintf("NCR_FAC"));
  1571. if((i=get_plci(a)))
  1572. {
  1573. rc_plci = &a->plci[i-1];
  1574. appl->NullCREnable = true;
  1575. rc_plci->internal_command = C_NCR_FAC_REQ;
  1576. rc_plci->appl = appl;
  1577. add_p(rc_plci,CAI,"\x01\x80");
  1578. add_p(rc_plci,UID,"\x06\x43\x61\x70\x69\x32\x30");
  1579. sig_req(rc_plci,ASSIGN,DSIG_ID);
  1580. send_req(rc_plci);
  1581. }
  1582. else
  1583. {
  1584. Info = _OUT_OF_PLCI;
  1585. }
  1586. if(!Info)
  1587. {
  1588. add_s(rc_plci,CPN,&msg[0]);
  1589. add_ai(rc_plci, &msg[1]);
  1590. sig_req(rc_plci,NCR_FACILITY,0);
  1591. send_req(rc_plci);
  1592. return false;
  1593. /* for application controlled supplementary services */
  1594. }
  1595. }
  1596. if (!rc_plci)
  1597. {
  1598. Info = _WRONG_MESSAGE_FORMAT;
  1599. }
  1600. if(!Info)
  1601. {
  1602. send_req(rc_plci);
  1603. }
  1604. else
  1605. { /* appl is not assigned to a PLCI or error condition */
  1606. dbug(1,dprintf("localInfoCon"));
  1607. sendf(appl,
  1608. _INFO_R|CONFIRM,
  1609. Id,
  1610. Number,
  1611. "w",Info);
  1612. }
  1613. return false;
  1614. }
  1615. static byte info_res(dword Id, word Number, DIVA_CAPI_ADAPTER *a,
  1616. PLCI *plci, APPL *appl, API_PARSE *msg)
  1617. {
  1618. dbug(1,dprintf("info_res"));
  1619. return false;
  1620. }
  1621. static byte alert_req(dword Id, word Number, DIVA_CAPI_ADAPTER *a,
  1622. PLCI *plci, APPL *appl, API_PARSE *msg)
  1623. {
  1624. word Info;
  1625. byte ret;
  1626. dbug(1,dprintf("alert_req"));
  1627. Info = _WRONG_IDENTIFIER;
  1628. ret = false;
  1629. if(plci) {
  1630. Info = _ALERT_IGNORED;
  1631. if(plci->State!=INC_CON_ALERT) {
  1632. Info = _WRONG_STATE;
  1633. if(plci->State==INC_CON_PENDING) {
  1634. Info = 0;
  1635. plci->State=INC_CON_ALERT;
  1636. add_ai(plci, &msg[0]);
  1637. sig_req(plci,CALL_ALERT,0);
  1638. ret = 1;
  1639. }
  1640. }
  1641. }
  1642. sendf(appl,
  1643. _ALERT_R|CONFIRM,
  1644. Id,
  1645. Number,
  1646. "w",Info);
  1647. return ret;
  1648. }
  1649. static byte facility_req(dword Id, word Number, DIVA_CAPI_ADAPTER *a,
  1650. PLCI *plci, APPL *appl, API_PARSE *msg)
  1651. {
  1652. word Info = 0;
  1653. word i = 0;
  1654. word selector;
  1655. word SSreq;
  1656. long relatedPLCIvalue;
  1657. DIVA_CAPI_ADAPTER * relatedadapter;
  1658. byte * SSparms = "";
  1659. byte RCparms[] = "\x05\x00\x00\x02\x00\x00";
  1660. byte SSstruct[] = "\x09\x00\x00\x06\x00\x00\x00\x00\x00\x00";
  1661. API_PARSE * parms;
  1662. API_PARSE ss_parms[11];
  1663. PLCI *rplci;
  1664. byte cai[15];
  1665. dword d;
  1666. API_PARSE dummy;
  1667. dbug(1,dprintf("facility_req"));
  1668. for(i=0;i<9;i++) ss_parms[i].length = 0;
  1669. parms = &msg[1];
  1670. if(!a)
  1671. {
  1672. dbug(1,dprintf("wrong Ctrl"));
  1673. Info = _WRONG_IDENTIFIER;
  1674. }
  1675. selector = GET_WORD(msg[0].info);
  1676. if(!Info)
  1677. {
  1678. switch(selector)
  1679. {
  1680. case SELECTOR_HANDSET:
  1681. Info = AdvCodecSupport(a, plci, appl, HOOK_SUPPORT);
  1682. break;
  1683. case SELECTOR_SU_SERV:
  1684. if(!msg[1].length)
  1685. {
  1686. Info = _WRONG_MESSAGE_FORMAT;
  1687. break;
  1688. }
  1689. SSreq = GET_WORD(&(msg[1].info[1]));
  1690. PUT_WORD(&RCparms[1],SSreq);
  1691. SSparms = RCparms;
  1692. switch(SSreq)
  1693. {
  1694. case S_GET_SUPPORTED_SERVICES:
  1695. if((i=get_plci(a)))
  1696. {
  1697. rplci = &a->plci[i-1];
  1698. rplci->appl = appl;
  1699. add_p(rplci,CAI,"\x01\x80");
  1700. add_p(rplci,UID,"\x06\x43\x61\x70\x69\x32\x30");
  1701. sig_req(rplci,ASSIGN,DSIG_ID);
  1702. send_req(rplci);
  1703. }
  1704. else
  1705. {
  1706. PUT_DWORD(&SSstruct[6], MASK_TERMINAL_PORTABILITY);
  1707. SSparms = (byte *)SSstruct;
  1708. break;
  1709. }
  1710. rplci->internal_command = GETSERV_REQ_PEND;
  1711. rplci->number = Number;
  1712. rplci->appl = appl;
  1713. sig_req(rplci,S_SUPPORTED,0);
  1714. send_req(rplci);
  1715. return false;
  1716. break;
  1717. case S_LISTEN:
  1718. if(parms->length==7)
  1719. {
  1720. if(api_parse(&parms->info[1],(word)parms->length,"wbd",ss_parms))
  1721. {
  1722. dbug(1,dprintf("format wrong"));
  1723. Info = _WRONG_MESSAGE_FORMAT;
  1724. break;
  1725. }
  1726. }
  1727. else
  1728. {
  1729. Info = _WRONG_MESSAGE_FORMAT;
  1730. break;
  1731. }
  1732. a->Notification_Mask[appl->Id-1] = GET_DWORD(ss_parms[2].info);
  1733. if(a->Notification_Mask[appl->Id-1] & SMASK_MWI) /* MWI active? */
  1734. {
  1735. if((i=get_plci(a)))
  1736. {
  1737. rplci = &a->plci[i-1];
  1738. rplci->appl = appl;
  1739. add_p(rplci,CAI,"\x01\x80");
  1740. add_p(rplci,UID,"\x06\x43\x61\x70\x69\x32\x30");
  1741. sig_req(rplci,ASSIGN,DSIG_ID);
  1742. send_req(rplci);
  1743. }
  1744. else
  1745. {
  1746. break;
  1747. }
  1748. rplci->internal_command = GET_MWI_STATE;
  1749. rplci->number = Number;
  1750. sig_req(rplci,MWI_POLL,0);
  1751. send_req(rplci);
  1752. }
  1753. break;
  1754. case S_HOLD:
  1755. api_parse(&parms->info[1],(word)parms->length,"ws",ss_parms);
  1756. if(plci && plci->State && plci->SuppState==IDLE)
  1757. {
  1758. plci->SuppState = HOLD_REQUEST;
  1759. plci->command = C_HOLD_REQ;
  1760. add_s(plci,CAI,&ss_parms[1]);
  1761. sig_req(plci,CALL_HOLD,0);
  1762. send_req(plci);
  1763. return false;
  1764. }
  1765. else Info = 0x3010; /* wrong state */
  1766. break;
  1767. case S_RETRIEVE:
  1768. if(plci && plci->State && plci->SuppState==CALL_HELD)
  1769. {
  1770. if(Id & EXT_CONTROLLER)
  1771. {
  1772. if(AdvCodecSupport(a, plci, appl, 0))
  1773. {
  1774. Info = 0x3010; /* wrong state */
  1775. break;
  1776. }
  1777. }
  1778. else plci->tel = 0;
  1779. plci->SuppState = RETRIEVE_REQUEST;
  1780. plci->command = C_RETRIEVE_REQ;
  1781. if(plci->spoofed_msg==SPOOFING_REQUIRED)
  1782. {
  1783. plci->spoofed_msg = CALL_RETRIEVE;
  1784. plci->internal_command = BLOCK_PLCI;
  1785. plci->command = 0;
  1786. dbug(1,dprintf("Spoof"));
  1787. return false;
  1788. }
  1789. else
  1790. {
  1791. sig_req(plci,CALL_RETRIEVE,0);
  1792. send_req(plci);
  1793. return false;
  1794. }
  1795. }
  1796. else Info = 0x3010; /* wrong state */
  1797. break;
  1798. case S_SUSPEND:
  1799. if(parms->length)
  1800. {
  1801. if(api_parse(&parms->info[1],(word)parms->length,"wbs",ss_parms))
  1802. {
  1803. dbug(1,dprintf("format wrong"));
  1804. Info = _WRONG_MESSAGE_FORMAT;
  1805. break;
  1806. }
  1807. }
  1808. if(plci && plci->State)
  1809. {
  1810. add_s(plci,CAI,&ss_parms[2]);
  1811. plci->command = SUSPEND_REQ;
  1812. sig_req(plci,SUSPEND,0);
  1813. plci->State = SUSPENDING;
  1814. send_req(plci);
  1815. }
  1816. else Info = 0x3010; /* wrong state */
  1817. break;
  1818. case S_RESUME:
  1819. if(!(i=get_plci(a)) )
  1820. {
  1821. Info = _OUT_OF_PLCI;
  1822. break;
  1823. }
  1824. rplci = &a->plci[i-1];
  1825. rplci->appl = appl;
  1826. rplci->number = Number;
  1827. rplci->tel = 0;
  1828. rplci->call_dir = CALL_DIR_OUT | CALL_DIR_ORIGINATE;
  1829. /* check 'external controller' bit for codec support */
  1830. if(Id & EXT_CONTROLLER)
  1831. {
  1832. if(AdvCodecSupport(a, rplci, appl, 0) )
  1833. {
  1834. rplci->Id = 0;
  1835. Info = 0x300A;
  1836. break;
  1837. }
  1838. }
  1839. if(parms->length)
  1840. {
  1841. if(api_parse(&parms->info[1],(word)parms->length,"wbs",ss_parms))
  1842. {
  1843. dbug(1,dprintf("format wrong"));
  1844. rplci->Id = 0;
  1845. Info = _WRONG_MESSAGE_FORMAT;
  1846. break;
  1847. }
  1848. }
  1849. dummy.length = 0;
  1850. dummy.info = "\x00";
  1851. add_b1(rplci, &dummy, 0, 0);
  1852. if (a->Info_Mask[appl->Id-1] & 0x200)
  1853. {
  1854. /* early B3 connect (CIP mask bit 9) no release after a disc */
  1855. add_p(rplci,LLI,"\x01\x01");
  1856. }
  1857. add_p(rplci,UID,"\x06\x43\x61\x70\x69\x32\x30");
  1858. sig_req(rplci,ASSIGN,DSIG_ID);
  1859. send_req(rplci);
  1860. add_s(rplci,CAI,&ss_parms[2]);
  1861. rplci->command = RESUME_REQ;
  1862. sig_req(rplci,RESUME,0);
  1863. rplci->State = RESUMING;
  1864. send_req(rplci);
  1865. break;
  1866. case S_CONF_BEGIN: /* Request */
  1867. case S_CONF_DROP:
  1868. case S_CONF_ISOLATE:
  1869. case S_CONF_REATTACH:
  1870. if(api_parse(&parms->info[1],(word)parms->length,"wbd",ss_parms))
  1871. {
  1872. dbug(1,dprintf("format wrong"));
  1873. Info = _WRONG_MESSAGE_FORMAT;
  1874. break;
  1875. }
  1876. if(plci && plci->State && ((plci->SuppState==IDLE)||(plci->SuppState==CALL_HELD)))
  1877. {
  1878. d = GET_DWORD(ss_parms[2].info);
  1879. if(d>=0x80)
  1880. {
  1881. dbug(1,dprintf("format wrong"));
  1882. Info = _WRONG_MESSAGE_FORMAT;
  1883. break;
  1884. }
  1885. plci->ptyState = (byte)SSreq;
  1886. plci->command = 0;
  1887. cai[0] = 2;
  1888. switch(SSreq)
  1889. {
  1890. case S_CONF_BEGIN:
  1891. cai[1] = CONF_BEGIN;
  1892. plci->internal_command = CONF_BEGIN_REQ_PEND;
  1893. break;
  1894. case S_CONF_DROP:
  1895. cai[1] = CONF_DROP;
  1896. plci->internal_command = CONF_DROP_REQ_PEND;
  1897. break;
  1898. case S_CONF_ISOLATE:
  1899. cai[1] = CONF_ISOLATE;
  1900. plci->internal_command = CONF_ISOLATE_REQ_PEND;
  1901. break;
  1902. case S_CONF_REATTACH:
  1903. cai[1] = CONF_REATTACH;
  1904. plci->internal_command = CONF_REATTACH_REQ_PEND;
  1905. break;
  1906. }
  1907. cai[2] = (byte)d; /* Conference Size resp. PartyId */
  1908. add_p(plci,CAI,cai);
  1909. sig_req(plci,S_SERVICE,0);
  1910. send_req(plci);
  1911. return false;
  1912. }
  1913. else Info = 0x3010; /* wrong state */
  1914. break;
  1915. case S_ECT:
  1916. case S_3PTY_BEGIN:
  1917. case S_3PTY_END:
  1918. case S_CONF_ADD:
  1919. if(parms->length==7)
  1920. {
  1921. if(api_parse(&parms->info[1],(word)parms->length,"wbd",ss_parms))
  1922. {
  1923. dbug(1,dprintf("format wrong"));
  1924. Info = _WRONG_MESSAGE_FORMAT;
  1925. break;
  1926. }
  1927. }
  1928. else if(parms->length==8) /* workaround for the T-View-S */
  1929. {
  1930. if(api_parse(&parms->info[1],(word)parms->length,"wbdb",ss_parms))
  1931. {
  1932. dbug(1,dprintf("format wrong"));
  1933. Info = _WRONG_MESSAGE_FORMAT;
  1934. break;
  1935. }
  1936. }
  1937. else
  1938. {
  1939. Info = _WRONG_MESSAGE_FORMAT;
  1940. break;
  1941. }
  1942. if(!msg[1].length)
  1943. {
  1944. Info = _WRONG_MESSAGE_FORMAT;
  1945. break;
  1946. }
  1947. if (!plci)
  1948. {
  1949. Info = _WRONG_IDENTIFIER;
  1950. break;
  1951. }
  1952. relatedPLCIvalue = GET_DWORD(ss_parms[2].info);
  1953. relatedPLCIvalue &= 0x0000FFFF;
  1954. dbug(1,dprintf("PTY/ECT/addCONF,relPLCI=%lx",relatedPLCIvalue));
  1955. /* controller starts with 0 up to (max_adapter - 1) */
  1956. if (((relatedPLCIvalue & 0x7f) == 0)
  1957. || (MapController ((byte)(relatedPLCIvalue & 0x7f)) == 0)
  1958. || (MapController ((byte)(relatedPLCIvalue & 0x7f)) > max_adapter))
  1959. {
  1960. if(SSreq==S_3PTY_END)
  1961. {
  1962. dbug(1, dprintf("wrong Controller use 2nd PLCI=PLCI"));
  1963. rplci = plci;
  1964. }
  1965. else
  1966. {
  1967. Info = 0x3010; /* wrong state */
  1968. break;
  1969. }
  1970. }
  1971. else
  1972. {
  1973. relatedadapter = &adapter[MapController ((byte)(relatedPLCIvalue & 0x7f))-1];
  1974. relatedPLCIvalue >>=8;
  1975. /* find PLCI PTR*/
  1976. for(i=0,rplci=NULL;i<relatedadapter->max_plci;i++)
  1977. {
  1978. if(relatedadapter->plci[i].Id == (byte)relatedPLCIvalue)
  1979. {
  1980. rplci = &relatedadapter->plci[i];
  1981. }
  1982. }
  1983. if(!rplci || !relatedPLCIvalue)
  1984. {
  1985. if(SSreq==S_3PTY_END)
  1986. {
  1987. dbug(1, dprintf("use 2nd PLCI=PLCI"));
  1988. rplci = plci;
  1989. }
  1990. else
  1991. {
  1992. Info = 0x3010; /* wrong state */
  1993. break;
  1994. }
  1995. }
  1996. }
  1997. /*
  1998. dbug(1,dprintf("rplci:%x",rplci));
  1999. dbug(1,dprintf("plci:%x",plci));
  2000. dbug(1,dprintf("rplci->ptyState:%x",rplci->ptyState));
  2001. dbug(1,dprintf("plci->ptyState:%x",plci->ptyState));
  2002. dbug(1,dprintf("SSreq:%x",SSreq));
  2003. dbug(1,dprintf("rplci->internal_command:%x",rplci->internal_command));
  2004. dbug(1,dprintf("rplci->appl:%x",rplci->appl));
  2005. dbug(1,dprintf("rplci->Id:%x",rplci->Id));
  2006. */
  2007. /* send PTY/ECT req, cannot check all states because of US stuff */
  2008. if( !rplci->internal_command && rplci->appl )
  2009. {
  2010. plci->command = 0;
  2011. rplci->relatedPTYPLCI = plci;
  2012. plci->relatedPTYPLCI = rplci;
  2013. rplci->ptyState = (byte)SSreq;
  2014. if(SSreq==S_ECT)
  2015. {
  2016. rplci->internal_command = ECT_REQ_PEND;
  2017. cai[1] = ECT_EXECUTE;
  2018. rplci->vswitchstate=0;
  2019. rplci->vsprot=0;
  2020. rplci->vsprotdialect=0;
  2021. plci->vswitchstate=0;
  2022. plci->vsprot=0;
  2023. plci->vsprotdialect=0;
  2024. }
  2025. else if(SSreq==S_CONF_ADD)
  2026. {
  2027. rplci->internal_command = CONF_ADD_REQ_PEND;
  2028. cai[1] = CONF_ADD;
  2029. }
  2030. else
  2031. {
  2032. rplci->internal_command = PTY_REQ_PEND;
  2033. cai[1] = (byte)(SSreq-3);
  2034. }
  2035. rplci->number = Number;
  2036. if(plci!=rplci) /* explicit invocation */
  2037. {
  2038. cai[0] = 2;
  2039. cai[2] = plci->Sig.Id;
  2040. dbug(1,dprintf("explicit invocation"));
  2041. }
  2042. else
  2043. {
  2044. dbug(1,dprintf("implicit invocation"));
  2045. cai[0] = 1;
  2046. }
  2047. add_p(rplci,CAI,cai);
  2048. sig_req(rplci,S_SERVICE,0);
  2049. send_req(rplci);
  2050. return false;
  2051. }
  2052. else
  2053. {
  2054. dbug(0,dprintf("Wrong line"));
  2055. Info = 0x3010; /* wrong state */
  2056. break;
  2057. }
  2058. break;
  2059. case S_CALL_DEFLECTION:
  2060. if(api_parse(&parms->info[1],(word)parms->length,"wbwss",ss_parms))
  2061. {
  2062. dbug(1,dprintf("format wrong"));
  2063. Info = _WRONG_MESSAGE_FORMAT;
  2064. break;
  2065. }
  2066. if (!plci)
  2067. {
  2068. Info = _WRONG_IDENTIFIER;
  2069. break;
  2070. }
  2071. /* reuse unused screening indicator */
  2072. ss_parms[3].info[3] = (byte)GET_WORD(&(ss_parms[2].info[0]));
  2073. plci->command = 0;
  2074. plci->internal_command = CD_REQ_PEND;
  2075. appl->CDEnable = true;
  2076. cai[0] = 1;
  2077. cai[1] = CALL_DEFLECTION;
  2078. add_p(plci,CAI,cai);
  2079. add_p(plci,CPN,ss_parms[3].info);
  2080. sig_req(plci,S_SERVICE,0);
  2081. send_req(plci);
  2082. return false;
  2083. break;
  2084. case S_CALL_FORWARDING_START:
  2085. if(api_parse(&parms->info[1],(word)parms->length,"wbdwwsss",ss_parms))
  2086. {
  2087. dbug(1,dprintf("format wrong"));
  2088. Info = _WRONG_MESSAGE_FORMAT;
  2089. break;
  2090. }
  2091. if((i=get_plci(a)))
  2092. {
  2093. rplci = &a->plci[i-1];
  2094. rplci->appl = appl;
  2095. add_p(rplci,CAI,"\x01\x80");
  2096. add_p(rplci,UID,"\x06\x43\x61\x70\x69\x32\x30");
  2097. sig_req(rplci,ASSIGN,DSIG_ID);
  2098. send_req(rplci);
  2099. }
  2100. else
  2101. {
  2102. Info = _OUT_OF_PLCI;
  2103. break;
  2104. }
  2105. /* reuse unused screening indicator */
  2106. rplci->internal_command = CF_START_PEND;
  2107. rplci->appl = appl;
  2108. rplci->number = Number;
  2109. appl->S_Handle = GET_DWORD(&(ss_parms[2].info[0]));
  2110. cai[0] = 2;
  2111. cai[1] = 0x70|(byte)GET_WORD(&(ss_parms[3].info[0])); /* Function */
  2112. cai[2] = (byte)GET_WORD(&(ss_parms[4].info[0])); /* Basic Service */
  2113. add_p(rplci,CAI,cai);
  2114. add_p(rplci,OAD,ss_parms[5].info);
  2115. add_p(rplci,CPN,ss_parms[6].info);
  2116. sig_req(rplci,S_SERVICE,0);
  2117. send_req(rplci);
  2118. return false;
  2119. break;
  2120. case S_INTERROGATE_DIVERSION:
  2121. case S_INTERROGATE_NUMBERS:
  2122. case S_CALL_FORWARDING_STOP:
  2123. case S_CCBS_REQUEST:
  2124. case S_CCBS_DEACTIVATE:
  2125. case S_CCBS_INTERROGATE:
  2126. switch(SSreq)
  2127. {
  2128. case S_INTERROGATE_NUMBERS:
  2129. if(api_parse(&parms->info[1],(word)parms->length,"wbd",ss_parms))
  2130. {
  2131. dbug(0,dprintf("format wrong"));
  2132. Info = _WRONG_MESSAGE_FORMAT;
  2133. }
  2134. break;
  2135. case S_CCBS_REQUEST:
  2136. case S_CCBS_DEACTIVATE:
  2137. if(api_parse(&parms->info[1],(word)parms->length,"wbdw",ss_parms))
  2138. {
  2139. dbug(0,dprintf("format wrong"));
  2140. Info = _WRONG_MESSAGE_FORMAT;
  2141. }
  2142. break;
  2143. case S_CCBS_INTERROGATE:
  2144. if(api_parse(&parms->info[1],(word)parms->length,"wbdws",ss_parms))
  2145. {
  2146. dbug(0,dprintf("format wrong"));
  2147. Info = _WRONG_MESSAGE_FORMAT;
  2148. }
  2149. break;
  2150. default:
  2151. if(api_parse(&parms->info[1],(word)parms->length,"wbdwws",ss_parms))
  2152. {
  2153. dbug(0,dprintf("format wrong"));
  2154. Info = _WRONG_MESSAGE_FORMAT;
  2155. break;
  2156. }
  2157. break;
  2158. }
  2159. if(Info) break;
  2160. if((i=get_plci(a)))
  2161. {
  2162. rplci = &a->plci[i-1];
  2163. switch(SSreq)
  2164. {
  2165. case S_INTERROGATE_DIVERSION: /* use cai with S_SERVICE below */
  2166. cai[1] = 0x60|(byte)GET_WORD(&(ss_parms[3].info[0])); /* Function */
  2167. rplci->internal_command = INTERR_DIVERSION_REQ_PEND; /* move to rplci if assigned */
  2168. break;
  2169. case S_INTERROGATE_NUMBERS: /* use cai with S_SERVICE below */
  2170. cai[1] = DIVERSION_INTERROGATE_NUM; /* Function */
  2171. rplci->internal_command = INTERR_NUMBERS_REQ_PEND; /* move to rplci if assigned */
  2172. break;
  2173. case S_CALL_FORWARDING_STOP:
  2174. rplci->internal_command = CF_STOP_PEND;
  2175. cai[1] = 0x80|(byte)GET_WORD(&(ss_parms[3].info[0])); /* Function */
  2176. break;
  2177. case S_CCBS_REQUEST:
  2178. cai[1] = CCBS_REQUEST;
  2179. rplci->internal_command = CCBS_REQUEST_REQ_PEND;
  2180. break;
  2181. case S_CCBS_DEACTIVATE:
  2182. cai[1] = CCBS_DEACTIVATE;
  2183. rplci->internal_command = CCBS_DEACTIVATE_REQ_PEND;
  2184. break;
  2185. case S_CCBS_INTERROGATE:
  2186. cai[1] = CCBS_INTERROGATE;
  2187. rplci->internal_command = CCBS_INTERROGATE_REQ_PEND;
  2188. break;
  2189. default:
  2190. cai[1] = 0;
  2191. break;
  2192. }
  2193. rplci->appl = appl;
  2194. rplci->number = Number;
  2195. add_p(rplci,CAI,"\x01\x80");
  2196. add_p(rplci,UID,"\x06\x43\x61\x70\x69\x32\x30");
  2197. sig_req(rplci,ASSIGN,DSIG_ID);
  2198. send_req(rplci);
  2199. }
  2200. else
  2201. {
  2202. Info = _OUT_OF_PLCI;
  2203. break;
  2204. }
  2205. appl->S_Handle = GET_DWORD(&(ss_parms[2].info[0]));
  2206. switch(SSreq)
  2207. {
  2208. case S_INTERROGATE_NUMBERS:
  2209. cai[0] = 1;
  2210. add_p(rplci,CAI,cai);
  2211. break;
  2212. case S_CCBS_REQUEST:
  2213. case S_CCBS_DEACTIVATE:
  2214. cai[0] = 3;
  2215. PUT_WORD(&cai[2],GET_WORD(&(ss_parms[3].info[0])));
  2216. add_p(rplci,CAI,cai);
  2217. break;
  2218. case S_CCBS_INTERROGATE:
  2219. cai[0] = 3;
  2220. PUT_WORD(&cai[2],GET_WORD(&(ss_parms[3].info[0])));
  2221. add_p(rplci,CAI,cai);
  2222. add_p(rplci,OAD,ss_parms[4].info);
  2223. break;
  2224. default:
  2225. cai[0] = 2;
  2226. cai[2] = (byte)GET_WORD(&(ss_parms[4].info[0])); /* Basic Service */
  2227. add_p(rplci,CAI,cai);
  2228. add_p(rplci,OAD,ss_parms[5].info);
  2229. break;
  2230. }
  2231. sig_req(rplci,S_SERVICE,0);
  2232. send_req(rplci);
  2233. return false;
  2234. break;
  2235. case S_MWI_ACTIVATE:
  2236. if(api_parse(&parms->info[1],(word)parms->length,"wbwdwwwssss",ss_parms))
  2237. {
  2238. dbug(1,dprintf("format wrong"));
  2239. Info = _WRONG_MESSAGE_FORMAT;
  2240. break;
  2241. }
  2242. if(!plci)
  2243. {
  2244. if((i=get_plci(a)))
  2245. {
  2246. rplci = &a->plci[i-1];
  2247. rplci->appl = appl;
  2248. rplci->cr_enquiry=true;
  2249. add_p(rplci,CAI,"\x01\x80");
  2250. add_p(rplci,UID,"\x06\x43\x61\x70\x69\x32\x30");
  2251. sig_req(rplci,ASSIGN,DSIG_ID);
  2252. send_req(rplci);
  2253. }
  2254. else
  2255. {
  2256. Info = _OUT_OF_PLCI;
  2257. break;
  2258. }
  2259. }
  2260. else
  2261. {
  2262. rplci = plci;
  2263. rplci->cr_enquiry=false;
  2264. }
  2265. rplci->command = 0;
  2266. rplci->internal_command = MWI_ACTIVATE_REQ_PEND;
  2267. rplci->appl = appl;
  2268. rplci->number = Number;
  2269. cai[0] = 13;
  2270. cai[1] = ACTIVATION_MWI; /* Function */
  2271. PUT_WORD(&cai[2],GET_WORD(&(ss_parms[2].info[0]))); /* Basic Service */
  2272. PUT_DWORD(&cai[4],GET_DWORD(&(ss_parms[3].info[0]))); /* Number of Messages */
  2273. PUT_WORD(&cai[8],GET_WORD(&(ss_parms[4].info[0]))); /* Message Status */
  2274. PUT_WORD(&cai[10],GET_WORD(&(ss_parms[5].info[0]))); /* Message Reference */
  2275. PUT_WORD(&cai[12],GET_WORD(&(ss_parms[6].info[0]))); /* Invocation Mode */
  2276. add_p(rplci,CAI,cai);
  2277. add_p(rplci,CPN,ss_parms[7].info); /* Receiving User Number */
  2278. add_p(rplci,OAD,ss_parms[8].info); /* Controlling User Number */
  2279. add_p(rplci,OSA,ss_parms[9].info); /* Controlling User Provided Number */
  2280. add_p(rplci,UID,ss_parms[10].info); /* Time */
  2281. sig_req(rplci,S_SERVICE,0);
  2282. send_req(rplci);
  2283. return false;
  2284. case S_MWI_DEACTIVATE:
  2285. if(api_parse(&parms->info[1],(word)parms->length,"wbwwss",ss_parms))
  2286. {
  2287. dbug(1,dprintf("format wrong"));
  2288. Info = _WRONG_MESSAGE_FORMAT;
  2289. break;
  2290. }
  2291. if(!plci)
  2292. {
  2293. if((i=get_plci(a)))
  2294. {
  2295. rplci = &a->plci[i-1];
  2296. rplci->appl = appl;
  2297. rplci->cr_enquiry=true;
  2298. add_p(rplci,CAI,"\x01\x80");
  2299. add_p(rplci,UID,"\x06\x43\x61\x70\x69\x32\x30");
  2300. sig_req(rplci,ASSIGN,DSIG_ID);
  2301. send_req(rplci);
  2302. }
  2303. else
  2304. {
  2305. Info = _OUT_OF_PLCI;
  2306. break;
  2307. }
  2308. }
  2309. else
  2310. {
  2311. rplci = plci;
  2312. rplci->cr_enquiry=false;
  2313. }
  2314. rplci->command = 0;
  2315. rplci->internal_command = MWI_DEACTIVATE_REQ_PEND;
  2316. rplci->appl = appl;
  2317. rplci->number = Number;
  2318. cai[0] = 5;
  2319. cai[1] = DEACTIVATION_MWI; /* Function */
  2320. PUT_WORD(&cai[2],GET_WORD(&(ss_parms[2].info[0]))); /* Basic Service */
  2321. PUT_WORD(&cai[4],GET_WORD(&(ss_parms[3].info[0]))); /* Invocation Mode */
  2322. add_p(rplci,CAI,cai);
  2323. add_p(rplci,CPN,ss_parms[4].info); /* Receiving User Number */
  2324. add_p(rplci,OAD,ss_parms[5].info); /* Controlling User Number */
  2325. sig_req(rplci,S_SERVICE,0);
  2326. send_req(rplci);
  2327. return false;
  2328. default:
  2329. Info = 0x300E; /* not supported */
  2330. break;
  2331. }
  2332. break; /* case SELECTOR_SU_SERV: end */
  2333. case SELECTOR_DTMF:
  2334. return (dtmf_request (Id, Number, a, plci, appl, msg));
  2335. case SELECTOR_LINE_INTERCONNECT:
  2336. return (mixer_request (Id, Number, a, plci, appl, msg));
  2337. case PRIV_SELECTOR_ECHO_CANCELLER:
  2338. appl->appl_flags |= APPL_FLAG_PRIV_EC_SPEC;
  2339. return (ec_request (Id, Number, a, plci, appl, msg));
  2340. case SELECTOR_ECHO_CANCELLER:
  2341. appl->appl_flags &= ~APPL_FLAG_PRIV_EC_SPEC;
  2342. return (ec_request (Id, Number, a, plci, appl, msg));
  2343. case SELECTOR_V42BIS:
  2344. default:
  2345. Info = _FACILITY_NOT_SUPPORTED;
  2346. break;
  2347. } /* end of switch(selector) */
  2348. }
  2349. dbug(1,dprintf("SendFacRc"));
  2350. sendf(appl,
  2351. _FACILITY_R|CONFIRM,
  2352. Id,
  2353. Number,
  2354. "wws",Info,selector,SSparms);
  2355. return false;
  2356. }
  2357. static byte facility_res(dword Id, word Number, DIVA_CAPI_ADAPTER *a,
  2358. PLCI *plci, APPL *appl, API_PARSE *msg)
  2359. {
  2360. dbug(1,dprintf("facility_res"));
  2361. return false;
  2362. }
  2363. static byte connect_b3_req(dword Id, word Number, DIVA_CAPI_ADAPTER *a,
  2364. PLCI *plci, APPL *appl, API_PARSE *parms)
  2365. {
  2366. word Info = 0;
  2367. byte req;
  2368. byte len;
  2369. word w;
  2370. word fax_control_bits, fax_feature_bits, fax_info_change;
  2371. API_PARSE * ncpi;
  2372. byte pvc[2];
  2373. API_PARSE fax_parms[9];
  2374. word i;
  2375. dbug(1,dprintf("connect_b3_req"));
  2376. if(plci)
  2377. {
  2378. if ((plci->State == IDLE) || (plci->State == OUTG_DIS_PENDING)
  2379. || (plci->State == INC_DIS_PENDING) || (plci->SuppState != IDLE))
  2380. {
  2381. Info = _WRONG_STATE;
  2382. }
  2383. else
  2384. {
  2385. /* local reply if assign unsuccessfull
  2386. or B3 protocol allows only one layer 3 connection
  2387. and already connected
  2388. or B2 protocol not any LAPD
  2389. and connect_b3_req contradicts originate/answer direction */
  2390. if (!plci->NL.Id
  2391. || (((plci->B3_prot != B3_T90NL) && (plci->B3_prot != B3_ISO8208) && (plci->B3_prot != B3_X25_DCE))
  2392. && ((plci->channels != 0)
  2393. || (((plci->B2_prot != B2_SDLC) && (plci->B2_prot != B2_LAPD) && (plci->B2_prot != B2_LAPD_FREE_SAPI_SEL))
  2394. && ((plci->call_dir & CALL_DIR_ANSWER) && !(plci->call_dir & CALL_DIR_FORCE_OUTG_NL))))))
  2395. {
  2396. dbug(1,dprintf("B3 already connected=%d or no NL.Id=0x%x, dir=%d sstate=0x%x",
  2397. plci->channels,plci->NL.Id,plci->call_dir,plci->SuppState));
  2398. Info = _WRONG_STATE;
  2399. sendf(appl,
  2400. _CONNECT_B3_R|CONFIRM,
  2401. Id,
  2402. Number,
  2403. "w",Info);
  2404. return false;
  2405. }
  2406. plci->requested_options_conn = 0;
  2407. req = N_CONNECT;
  2408. ncpi = &parms[0];
  2409. if(plci->B3_prot==2 || plci->B3_prot==3)
  2410. {
  2411. if(ncpi->length>2)
  2412. {
  2413. /* check for PVC */
  2414. if(ncpi->info[2] || ncpi->info[3])
  2415. {
  2416. pvc[0] = ncpi->info[3];
  2417. pvc[1] = ncpi->info[2];
  2418. add_d(plci,2,pvc);
  2419. req = N_RESET;
  2420. }
  2421. else
  2422. {
  2423. if(ncpi->info[1] &1) req = N_CONNECT | N_D_BIT;
  2424. add_d(plci,(word)(ncpi->length-3),&ncpi->info[4]);
  2425. }
  2426. }
  2427. }
  2428. else if(plci->B3_prot==5)
  2429. {
  2430. if (plci->NL.Id && !plci->nl_remove_id)
  2431. {
  2432. fax_control_bits = GET_WORD(&((T30_INFO *)plci->fax_connect_info_buffer)->control_bits_low);
  2433. fax_feature_bits = GET_WORD(&((T30_INFO *)plci->fax_connect_info_buffer)->feature_bits_low);
  2434. if (!(fax_control_bits & T30_CONTROL_BIT_MORE_DOCUMENTS)
  2435. || (fax_feature_bits & T30_FEATURE_BIT_MORE_DOCUMENTS))
  2436. {
  2437. len = offsetof(T30_INFO, universal_6);
  2438. fax_info_change = false;
  2439. if (ncpi->length >= 4)
  2440. {
  2441. w = GET_WORD(&ncpi->info[3]);
  2442. if ((w & 0x0001) != ((word)(((T30_INFO *)(plci->fax_connect_info_buffer))->resolution & 0x0001)))
  2443. {
  2444. ((T30_INFO *)(plci->fax_connect_info_buffer))->resolution =
  2445. (byte)((((T30_INFO *)(plci->fax_connect_info_buffer))->resolution & ~T30_RESOLUTION_R8_0770_OR_200) |
  2446. ((w & 0x0001) ? T30_RESOLUTION_R8_0770_OR_200 : 0));
  2447. fax_info_change = true;
  2448. }
  2449. fax_control_bits &= ~(T30_CONTROL_BIT_REQUEST_POLLING | T30_CONTROL_BIT_MORE_DOCUMENTS);
  2450. if (w & 0x0002) /* Fax-polling request */
  2451. fax_control_bits |= T30_CONTROL_BIT_REQUEST_POLLING;
  2452. if ((w & 0x0004) /* Request to send / poll another document */
  2453. && (a->manufacturer_features & MANUFACTURER_FEATURE_FAX_MORE_DOCUMENTS))
  2454. {
  2455. fax_control_bits |= T30_CONTROL_BIT_MORE_DOCUMENTS;
  2456. }
  2457. if (ncpi->length >= 6)
  2458. {
  2459. w = GET_WORD(&ncpi->info[5]);
  2460. if (((byte) w) != ((T30_INFO *)(plci->fax_connect_info_buffer))->data_format)
  2461. {
  2462. ((T30_INFO *)(plci->fax_connect_info_buffer))->data_format = (byte) w;
  2463. fax_info_change = true;
  2464. }
  2465. if ((a->man_profile.private_options & (1L << PRIVATE_FAX_SUB_SEP_PWD))
  2466. && (GET_WORD(&ncpi->info[5]) & 0x8000)) /* Private SEP/SUB/PWD enable */
  2467. {
  2468. plci->requested_options_conn |= (1L << PRIVATE_FAX_SUB_SEP_PWD);
  2469. }
  2470. if ((a->man_profile.private_options & (1L << PRIVATE_FAX_NONSTANDARD))
  2471. && (GET_WORD(&ncpi->info[5]) & 0x4000)) /* Private non-standard facilities enable */
  2472. {
  2473. plci->requested_options_conn |= (1L << PRIVATE_FAX_NONSTANDARD);
  2474. }
  2475. fax_control_bits &= ~(T30_CONTROL_BIT_ACCEPT_SUBADDRESS | T30_CONTROL_BIT_ACCEPT_SEL_POLLING |
  2476. T30_CONTROL_BIT_ACCEPT_PASSWORD);
  2477. if ((plci->requested_options_conn | plci->requested_options | a->requested_options_table[appl->Id-1])
  2478. & ((1L << PRIVATE_FAX_SUB_SEP_PWD) | (1L << PRIVATE_FAX_NONSTANDARD)))
  2479. {
  2480. if (api_parse (&ncpi->info[1], ncpi->length, "wwwwsss", fax_parms))
  2481. Info = _WRONG_MESSAGE_FORMAT;
  2482. else
  2483. {
  2484. if ((plci->requested_options_conn | plci->requested_options | a->requested_options_table[appl->Id-1])
  2485. & (1L << PRIVATE_FAX_SUB_SEP_PWD))
  2486. {
  2487. fax_control_bits |= T30_CONTROL_BIT_ACCEPT_SUBADDRESS | T30_CONTROL_BIT_ACCEPT_PASSWORD;
  2488. if (fax_control_bits & T30_CONTROL_BIT_ACCEPT_POLLING)
  2489. fax_control_bits |= T30_CONTROL_BIT_ACCEPT_SEL_POLLING;
  2490. }
  2491. w = fax_parms[4].length;
  2492. if (w > 20)
  2493. w = 20;
  2494. ((T30_INFO *)(plci->fax_connect_info_buffer))->station_id_len = (byte) w;
  2495. for (i = 0; i < w; i++)
  2496. ((T30_INFO *)(plci->fax_connect_info_buffer))->station_id[i] = fax_parms[4].info[1+i];
  2497. ((T30_INFO *)(plci->fax_connect_info_buffer))->head_line_len = 0;
  2498. len = offsetof(T30_INFO, station_id) + 20;
  2499. w = fax_parms[5].length;
  2500. if (w > 20)
  2501. w = 20;
  2502. plci->fax_connect_info_buffer[len++] = (byte) w;
  2503. for (i = 0; i < w; i++)
  2504. plci->fax_connect_info_buffer[len++] = fax_parms[5].info[1+i];
  2505. w = fax_parms[6].length;
  2506. if (w > 20)
  2507. w = 20;
  2508. plci->fax_connect_info_buffer[len++] = (byte) w;
  2509. for (i = 0; i < w; i++)
  2510. plci->fax_connect_info_buffer[len++] = fax_parms[6].info[1+i];
  2511. if ((plci->requested_options_conn | plci->requested_options | a->requested_options_table[appl->Id-1])
  2512. & (1L << PRIVATE_FAX_NONSTANDARD))
  2513. {
  2514. if (api_parse (&ncpi->info[1], ncpi->length, "wwwwssss", fax_parms))
  2515. {
  2516. dbug(1,dprintf("non-standard facilities info missing or wrong format"));
  2517. plci->fax_connect_info_buffer[len++] = 0;
  2518. }
  2519. else
  2520. {
  2521. if ((fax_parms[7].length >= 3) && (fax_parms[7].info[1] >= 2))
  2522. plci->nsf_control_bits = GET_WORD(&fax_parms[7].info[2]);
  2523. plci->fax_connect_info_buffer[len++] = (byte)(fax_parms[7].length);
  2524. for (i = 0; i < fax_parms[7].length; i++)
  2525. plci->fax_connect_info_buffer[len++] = fax_parms[7].info[1+i];
  2526. }
  2527. }
  2528. }
  2529. }
  2530. else
  2531. {
  2532. len = offsetof(T30_INFO, universal_6);
  2533. }
  2534. fax_info_change = true;
  2535. }
  2536. if (fax_control_bits != GET_WORD(&((T30_INFO *)plci->fax_connect_info_buffer)->control_bits_low))
  2537. {
  2538. PUT_WORD (&((T30_INFO *)plci->fax_connect_info_buffer)->control_bits_low, fax_control_bits);
  2539. fax_info_change = true;
  2540. }
  2541. }
  2542. if (Info == GOOD)
  2543. {
  2544. plci->fax_connect_info_length = len;
  2545. if (fax_info_change)
  2546. {
  2547. if (fax_feature_bits & T30_FEATURE_BIT_MORE_DOCUMENTS)
  2548. {
  2549. start_internal_command (Id, plci, fax_connect_info_command);
  2550. return false;
  2551. }
  2552. else
  2553. {
  2554. start_internal_command (Id, plci, fax_adjust_b23_command);
  2555. return false;
  2556. }
  2557. }
  2558. }
  2559. }
  2560. else Info = _WRONG_STATE;
  2561. }
  2562. else Info = _WRONG_STATE;
  2563. }
  2564. else if (plci->B3_prot == B3_RTP)
  2565. {
  2566. plci->internal_req_buffer[0] = ncpi->length + 1;
  2567. plci->internal_req_buffer[1] = UDATA_REQUEST_RTP_RECONFIGURE;
  2568. for (w = 0; w < ncpi->length; w++)
  2569. plci->internal_req_buffer[2+w] = ncpi->info[1+w];
  2570. start_internal_command (Id, plci, rtp_connect_b3_req_command);
  2571. return false;
  2572. }
  2573. if(!Info)
  2574. {
  2575. nl_req_ncci(plci,req,0);
  2576. return 1;
  2577. }
  2578. }
  2579. }
  2580. else Info = _WRONG_IDENTIFIER;
  2581. sendf(appl,
  2582. _CONNECT_B3_R|CONFIRM,
  2583. Id,
  2584. Number,
  2585. "w",Info);
  2586. return false;
  2587. }
  2588. static byte connect_b3_res(dword Id, word Number, DIVA_CAPI_ADAPTER *a,
  2589. PLCI *plci, APPL *appl, API_PARSE *parms)
  2590. {
  2591. word ncci;
  2592. API_PARSE * ncpi;
  2593. byte req;
  2594. word w;
  2595. API_PARSE fax_parms[9];
  2596. word i;
  2597. byte len;
  2598. dbug(1,dprintf("connect_b3_res"));
  2599. ncci = (word)(Id>>16);
  2600. if(plci && ncci) {
  2601. if(a->ncci_state[ncci]==INC_CON_PENDING) {
  2602. if (GET_WORD (&parms[0].info[0]) != 0)
  2603. {
  2604. a->ncci_state[ncci] = OUTG_REJ_PENDING;
  2605. channel_request_xon (plci, a->ncci_ch[ncci]);
  2606. channel_xmit_xon (plci);
  2607. cleanup_ncci_data (plci, ncci);
  2608. nl_req_ncci(plci,N_DISC,(byte)ncci);
  2609. return 1;
  2610. }
  2611. a->ncci_state[ncci] = INC_ACT_PENDING;
  2612. req = N_CONNECT_ACK;
  2613. ncpi = &parms[1];
  2614. if ((plci->B3_prot == 4) || (plci->B3_prot == 5) || (plci->B3_prot == 7))
  2615. {
  2616. if ((plci->requested_options_conn | plci->requested_options | a->requested_options_table[plci->appl->Id-1])
  2617. & (1L << PRIVATE_FAX_NONSTANDARD))
  2618. {
  2619. if (((plci->B3_prot == 4) || (plci->B3_prot == 5))
  2620. && (plci->nsf_control_bits & T30_NSF_CONTROL_BIT_ENABLE_NSF)
  2621. && (plci->nsf_control_bits & T30_NSF_CONTROL_BIT_NEGOTIATE_RESP))
  2622. {
  2623. len = offsetof(T30_INFO, station_id) + 20;
  2624. if (plci->fax_connect_info_length < len)
  2625. {
  2626. ((T30_INFO *)(plci->fax_connect_info_buffer))->station_id_len = 0;
  2627. ((T30_INFO *)(plci->fax_connect_info_buffer))->head_line_len = 0;
  2628. }
  2629. if (api_parse (&ncpi->info[1], ncpi->length, "wwwwssss", fax_parms))
  2630. {
  2631. dbug(1,dprintf("non-standard facilities info missing or wrong format"));
  2632. }
  2633. else
  2634. {
  2635. if (plci->fax_connect_info_length <= len)
  2636. plci->fax_connect_info_buffer[len] = 0;
  2637. len += 1 + plci->fax_connect_info_buffer[len];
  2638. if (plci->fax_connect_info_length <= len)
  2639. plci->fax_connect_info_buffer[len] = 0;
  2640. len += 1 + plci->fax_connect_info_buffer[len];
  2641. if ((fax_parms[7].length >= 3) && (fax_parms[7].info[1] >= 2))
  2642. plci->nsf_control_bits = GET_WORD(&fax_parms[7].info[2]);
  2643. plci->fax_connect_info_buffer[len++] = (byte)(fax_parms[7].length);
  2644. for (i = 0; i < fax_parms[7].length; i++)
  2645. plci->fax_connect_info_buffer[len++] = fax_parms[7].info[1+i];
  2646. }
  2647. plci->fax_connect_info_length = len;
  2648. ((T30_INFO *)(plci->fax_connect_info_buffer))->code = 0;
  2649. start_internal_command (Id, plci, fax_connect_ack_command);
  2650. return false;
  2651. }
  2652. }
  2653. nl_req_ncci(plci,req,(byte)ncci);
  2654. if ((plci->ncpi_state & NCPI_VALID_CONNECT_B3_ACT)
  2655. && !(plci->ncpi_state & NCPI_CONNECT_B3_ACT_SENT))
  2656. {
  2657. if (plci->B3_prot == 4)
  2658. sendf(appl,_CONNECT_B3_ACTIVE_I,Id,0,"s","");
  2659. else
  2660. sendf(appl,_CONNECT_B3_ACTIVE_I,Id,0,"S",plci->ncpi_buffer);
  2661. plci->ncpi_state |= NCPI_CONNECT_B3_ACT_SENT;
  2662. }
  2663. }
  2664. else if (plci->B3_prot == B3_RTP)
  2665. {
  2666. plci->internal_req_buffer[0] = ncpi->length + 1;
  2667. plci->internal_req_buffer[1] = UDATA_REQUEST_RTP_RECONFIGURE;
  2668. for (w = 0; w < ncpi->length; w++)
  2669. plci->internal_req_buffer[2+w] = ncpi->info[1+w];
  2670. start_internal_command (Id, plci, rtp_connect_b3_res_command);
  2671. return false;
  2672. }
  2673. else
  2674. {
  2675. if(ncpi->length>2) {
  2676. if(ncpi->info[1] &1) req = N_CONNECT_ACK | N_D_BIT;
  2677. add_d(plci,(word)(ncpi->length-3),&ncpi->info[4]);
  2678. }
  2679. nl_req_ncci(plci,req,(byte)ncci);
  2680. sendf(appl,_CONNECT_B3_ACTIVE_I,Id,0,"s","");
  2681. if (plci->adjust_b_restore)
  2682. {
  2683. plci->adjust_b_restore = false;
  2684. start_internal_command (Id, plci, adjust_b_restore);
  2685. }
  2686. }
  2687. return 1;
  2688. }
  2689. }
  2690. return false;
  2691. }
  2692. static byte connect_b3_a_res(dword Id, word Number, DIVA_CAPI_ADAPTER *a,
  2693. PLCI *plci, APPL *appl, API_PARSE *parms)
  2694. {
  2695. word ncci;
  2696. ncci = (word)(Id>>16);
  2697. dbug(1,dprintf("connect_b3_a_res(ncci=0x%x)",ncci));
  2698. if (plci && ncci && (plci->State != IDLE) && (plci->State != INC_DIS_PENDING)
  2699. && (plci->State != OUTG_DIS_PENDING))
  2700. {
  2701. if(a->ncci_state[ncci]==INC_ACT_PENDING) {
  2702. a->ncci_state[ncci] = CONNECTED;
  2703. if(plci->State!=INC_CON_CONNECTED_ALERT) plci->State = CONNECTED;
  2704. channel_request_xon (plci, a->ncci_ch[ncci]);
  2705. channel_xmit_xon (plci);
  2706. }
  2707. }
  2708. return false;
  2709. }
  2710. static byte disconnect_b3_req(dword Id, word Number, DIVA_CAPI_ADAPTER *a,
  2711. PLCI *plci, APPL *appl, API_PARSE *parms)
  2712. {
  2713. word Info;
  2714. word ncci;
  2715. API_PARSE * ncpi;
  2716. dbug(1,dprintf("disconnect_b3_req"));
  2717. Info = _WRONG_IDENTIFIER;
  2718. ncci = (word)(Id>>16);
  2719. if (plci && ncci)
  2720. {
  2721. Info = _WRONG_STATE;
  2722. if ((a->ncci_state[ncci] == CONNECTED)
  2723. || (a->ncci_state[ncci] == OUTG_CON_PENDING)
  2724. || (a->ncci_state[ncci] == INC_CON_PENDING)
  2725. || (a->ncci_state[ncci] == INC_ACT_PENDING))
  2726. {
  2727. a->ncci_state[ncci] = OUTG_DIS_PENDING;
  2728. channel_request_xon (plci, a->ncci_ch[ncci]);
  2729. channel_xmit_xon (plci);
  2730. if (a->ncci[ncci].data_pending
  2731. && ((plci->B3_prot == B3_TRANSPARENT)
  2732. || (plci->B3_prot == B3_T30)
  2733. || (plci->B3_prot == B3_T30_WITH_EXTENSIONS)))
  2734. {
  2735. plci->send_disc = (byte)ncci;
  2736. plci->command = 0;
  2737. return false;
  2738. }
  2739. else
  2740. {
  2741. cleanup_ncci_data (plci, ncci);
  2742. if(plci->B3_prot==2 || plci->B3_prot==3)
  2743. {
  2744. ncpi = &parms[0];
  2745. if(ncpi->length>3)
  2746. {
  2747. add_d(plci, (word)(ncpi->length - 3) ,(byte *)&(ncpi->info[4]));
  2748. }
  2749. }
  2750. nl_req_ncci(plci,N_DISC,(byte)ncci);
  2751. }
  2752. return 1;
  2753. }
  2754. }
  2755. sendf(appl,
  2756. _DISCONNECT_B3_R|CONFIRM,
  2757. Id,
  2758. Number,
  2759. "w",Info);
  2760. return false;
  2761. }
  2762. static byte disconnect_b3_res(dword Id, word Number, DIVA_CAPI_ADAPTER *a,
  2763. PLCI *plci, APPL *appl, API_PARSE *parms)
  2764. {
  2765. word ncci;
  2766. word i;
  2767. ncci = (word)(Id>>16);
  2768. dbug(1,dprintf("disconnect_b3_res(ncci=0x%x",ncci));
  2769. if(plci && ncci) {
  2770. plci->requested_options_conn = 0;
  2771. plci->fax_connect_info_length = 0;
  2772. plci->ncpi_state = 0x00;
  2773. if (((plci->B3_prot != B3_T90NL) && (plci->B3_prot != B3_ISO8208) && (plci->B3_prot != B3_X25_DCE))
  2774. && ((plci->B2_prot != B2_LAPD) && (plci->B2_prot != B2_LAPD_FREE_SAPI_SEL)))
  2775. {
  2776. plci->call_dir |= CALL_DIR_FORCE_OUTG_NL;
  2777. }
  2778. for(i=0; i<MAX_CHANNELS_PER_PLCI && plci->inc_dis_ncci_table[i]!=(byte)ncci; i++);
  2779. if(i<MAX_CHANNELS_PER_PLCI) {
  2780. if(plci->channels)plci->channels--;
  2781. for(; i<MAX_CHANNELS_PER_PLCI-1; i++) plci->inc_dis_ncci_table[i] = plci->inc_dis_ncci_table[i+1];
  2782. plci->inc_dis_ncci_table[MAX_CHANNELS_PER_PLCI-1] = 0;
  2783. ncci_free_receive_buffers (plci, ncci);
  2784. if((plci->State==IDLE || plci->State==SUSPENDING) && !plci->channels){
  2785. if(plci->State == SUSPENDING){
  2786. sendf(plci->appl,
  2787. _FACILITY_I,
  2788. Id & 0xffffL,
  2789. 0,
  2790. "ws", (word)3, "\x03\x04\x00\x00");
  2791. sendf(plci->appl, _DISCONNECT_I, Id & 0xffffL, 0, "w", 0);
  2792. }
  2793. plci_remove(plci);
  2794. plci->State=IDLE;
  2795. }
  2796. }
  2797. else
  2798. {
  2799. if ((a->manufacturer_features & MANUFACTURER_FEATURE_FAX_PAPER_FORMATS)
  2800. && ((plci->B3_prot == 4) || (plci->B3_prot == 5))
  2801. && (a->ncci_state[ncci] == INC_DIS_PENDING))
  2802. {
  2803. ncci_free_receive_buffers (plci, ncci);
  2804. nl_req_ncci(plci,N_EDATA,(byte)ncci);
  2805. plci->adapter->ncci_state[ncci] = IDLE;
  2806. start_internal_command (Id, plci, fax_disconnect_command);
  2807. return 1;
  2808. }
  2809. }
  2810. }
  2811. return false;
  2812. }
  2813. static byte data_b3_req(dword Id, word Number, DIVA_CAPI_ADAPTER *a,
  2814. PLCI *plci, APPL *appl, API_PARSE *parms)
  2815. {
  2816. NCCI *ncci_ptr;
  2817. DATA_B3_DESC *data;
  2818. word Info;
  2819. word ncci;
  2820. word i;
  2821. dbug(1,dprintf("data_b3_req"));
  2822. Info = _WRONG_IDENTIFIER;
  2823. ncci = (word)(Id>>16);
  2824. dbug(1,dprintf("ncci=0x%x, plci=0x%x",ncci,plci));
  2825. if (plci && ncci)
  2826. {
  2827. Info = _WRONG_STATE;
  2828. if ((a->ncci_state[ncci] == CONNECTED)
  2829. || (a->ncci_state[ncci] == INC_ACT_PENDING))
  2830. {
  2831. /* queue data */
  2832. ncci_ptr = &(a->ncci[ncci]);
  2833. i = ncci_ptr->data_out + ncci_ptr->data_pending;
  2834. if (i >= MAX_DATA_B3)
  2835. i -= MAX_DATA_B3;
  2836. data = &(ncci_ptr->DBuffer[i]);
  2837. data->Number = Number;
  2838. if ((((byte *)(parms[0].info)) >= ((byte *)(plci->msg_in_queue)))
  2839. && (((byte *)(parms[0].info)) < ((byte *)(plci->msg_in_queue)) + sizeof(plci->msg_in_queue)))
  2840. {
  2841. data->P = (byte *)(long)(*((dword *)(parms[0].info)));
  2842. }
  2843. else
  2844. data->P = TransmitBufferSet(appl,*(dword *)parms[0].info);
  2845. data->Length = GET_WORD(parms[1].info);
  2846. data->Handle = GET_WORD(parms[2].info);
  2847. data->Flags = GET_WORD(parms[3].info);
  2848. (ncci_ptr->data_pending)++;
  2849. /* check for delivery confirmation */
  2850. if (data->Flags & 0x0004)
  2851. {
  2852. i = ncci_ptr->data_ack_out + ncci_ptr->data_ack_pending;
  2853. if (i >= MAX_DATA_ACK)
  2854. i -= MAX_DATA_ACK;
  2855. ncci_ptr->DataAck[i].Number = data->Number;
  2856. ncci_ptr->DataAck[i].Handle = data->Handle;
  2857. (ncci_ptr->data_ack_pending)++;
  2858. }
  2859. send_data(plci);
  2860. return false;
  2861. }
  2862. }
  2863. if (appl)
  2864. {
  2865. if (plci)
  2866. {
  2867. if ((((byte *)(parms[0].info)) >= ((byte *)(plci->msg_in_queue)))
  2868. && (((byte *)(parms[0].info)) < ((byte *)(plci->msg_in_queue)) + sizeof(plci->msg_in_queue)))
  2869. {
  2870. TransmitBufferFree (appl, (byte *)(long)(*((dword *)(parms[0].info))));
  2871. }
  2872. }
  2873. sendf(appl,
  2874. _DATA_B3_R|CONFIRM,
  2875. Id,
  2876. Number,
  2877. "ww",GET_WORD(parms[2].info),Info);
  2878. }
  2879. return false;
  2880. }
  2881. static byte data_b3_res(dword Id, word Number, DIVA_CAPI_ADAPTER *a,
  2882. PLCI *plci, APPL *appl, API_PARSE *parms)
  2883. {
  2884. word n;
  2885. word ncci;
  2886. word NCCIcode;
  2887. dbug(1,dprintf("data_b3_res"));
  2888. ncci = (word)(Id>>16);
  2889. if(plci && ncci) {
  2890. n = GET_WORD(parms[0].info);
  2891. dbug(1,dprintf("free(%d)",n));
  2892. NCCIcode = ncci | (((word) a->Id) << 8);
  2893. if(n<appl->MaxBuffer &&
  2894. appl->DataNCCI[n]==NCCIcode &&
  2895. (byte)(appl->DataFlags[n]>>8)==plci->Id) {
  2896. dbug(1,dprintf("found"));
  2897. appl->DataNCCI[n] = 0;
  2898. if (channel_can_xon (plci, a->ncci_ch[ncci])) {
  2899. channel_request_xon (plci, a->ncci_ch[ncci]);
  2900. }
  2901. channel_xmit_xon (plci);
  2902. if(appl->DataFlags[n] &4) {
  2903. nl_req_ncci(plci,N_DATA_ACK,(byte)ncci);
  2904. return 1;
  2905. }
  2906. }
  2907. }
  2908. return false;
  2909. }
  2910. static byte reset_b3_req(dword Id, word Number, DIVA_CAPI_ADAPTER *a,
  2911. PLCI *plci, APPL *appl, API_PARSE *parms)
  2912. {
  2913. word Info;
  2914. word ncci;
  2915. dbug(1,dprintf("reset_b3_req"));
  2916. Info = _WRONG_IDENTIFIER;
  2917. ncci = (word)(Id>>16);
  2918. if(plci && ncci)
  2919. {
  2920. Info = _WRONG_STATE;
  2921. switch (plci->B3_prot)
  2922. {
  2923. case B3_ISO8208:
  2924. case B3_X25_DCE:
  2925. if(a->ncci_state[ncci]==CONNECTED)
  2926. {
  2927. nl_req_ncci(plci,N_RESET,(byte)ncci);
  2928. send_req(plci);
  2929. Info = GOOD;
  2930. }
  2931. break;
  2932. case B3_TRANSPARENT:
  2933. if(a->ncci_state[ncci]==CONNECTED)
  2934. {
  2935. start_internal_command (Id, plci, reset_b3_command);
  2936. Info = GOOD;
  2937. }
  2938. break;
  2939. }
  2940. }
  2941. /* reset_b3 must result in a reset_b3_con & reset_b3_Ind */
  2942. sendf(appl,
  2943. _RESET_B3_R|CONFIRM,
  2944. Id,
  2945. Number,
  2946. "w",Info);
  2947. return false;
  2948. }
  2949. static byte reset_b3_res(dword Id, word Number, DIVA_CAPI_ADAPTER *a,
  2950. PLCI *plci, APPL *appl, API_PARSE *parms)
  2951. {
  2952. word ncci;
  2953. dbug(1,dprintf("reset_b3_res"));
  2954. ncci = (word)(Id>>16);
  2955. if(plci && ncci) {
  2956. switch (plci->B3_prot)
  2957. {
  2958. case B3_ISO8208:
  2959. case B3_X25_DCE:
  2960. if(a->ncci_state[ncci]==INC_RES_PENDING)
  2961. {
  2962. a->ncci_state[ncci] = CONNECTED;
  2963. nl_req_ncci(plci,N_RESET_ACK,(byte)ncci);
  2964. return true;
  2965. }
  2966. break;
  2967. }
  2968. }
  2969. return false;
  2970. }
  2971. static byte connect_b3_t90_a_res(dword Id, word Number, DIVA_CAPI_ADAPTER *a,
  2972. PLCI *plci, APPL *appl, API_PARSE *parms)
  2973. {
  2974. word ncci;
  2975. API_PARSE * ncpi;
  2976. byte req;
  2977. dbug(1,dprintf("connect_b3_t90_a_res"));
  2978. ncci = (word)(Id>>16);
  2979. if(plci && ncci) {
  2980. if(a->ncci_state[ncci]==INC_ACT_PENDING) {
  2981. a->ncci_state[ncci] = CONNECTED;
  2982. }
  2983. else if(a->ncci_state[ncci]==INC_CON_PENDING) {
  2984. a->ncci_state[ncci] = CONNECTED;
  2985. req = N_CONNECT_ACK;
  2986. /* parms[0]==0 for CAPI original message definition! */
  2987. if(parms[0].info) {
  2988. ncpi = &parms[1];
  2989. if(ncpi->length>2) {
  2990. if(ncpi->info[1] &1) req = N_CONNECT_ACK | N_D_BIT;
  2991. add_d(plci,(word)(ncpi->length-3),&ncpi->info[4]);
  2992. }
  2993. }
  2994. nl_req_ncci(plci,req,(byte)ncci);
  2995. return 1;
  2996. }
  2997. }
  2998. return false;
  2999. }
  3000. static byte select_b_req(dword Id, word Number, DIVA_CAPI_ADAPTER *a,
  3001. PLCI *plci, APPL *appl, API_PARSE *msg)
  3002. {
  3003. word Info=0;
  3004. word i;
  3005. byte tel;
  3006. API_PARSE bp_parms[7];
  3007. if(!plci || !msg)
  3008. {
  3009. Info = _WRONG_IDENTIFIER;
  3010. }
  3011. else
  3012. {
  3013. dbug(1,dprintf("select_b_req[%d],PLCI=0x%x,Tel=0x%x,NL=0x%x,appl=0x%x,sstate=0x%x",
  3014. msg->length,plci->Id,plci->tel,plci->NL.Id,plci->appl,plci->SuppState));
  3015. dbug(1,dprintf("PlciState=0x%x",plci->State));
  3016. for(i=0;i<7;i++) bp_parms[i].length = 0;
  3017. /* check if no channel is open, no B3 connected only */
  3018. if((plci->State == IDLE) || (plci->State == OUTG_DIS_PENDING) || (plci->State == INC_DIS_PENDING)
  3019. || (plci->SuppState != IDLE) || plci->channels || plci->nl_remove_id)
  3020. {
  3021. Info = _WRONG_STATE;
  3022. }
  3023. /* check message format and fill bp_parms pointer */
  3024. else if(msg->length && api_parse(&msg->info[1], (word)msg->length, "wwwsss", bp_parms))
  3025. {
  3026. Info = _WRONG_MESSAGE_FORMAT;
  3027. }
  3028. else
  3029. {
  3030. if((plci->State==INC_CON_PENDING) || (plci->State==INC_CON_ALERT)) /* send alert tone inband to the network, */
  3031. { /* e.g. Qsig or RBS or Cornet-N or xess PRI */
  3032. if(Id & EXT_CONTROLLER)
  3033. {
  3034. sendf(appl, _SELECT_B_REQ|CONFIRM, Id, Number, "w", 0x2002); /* wrong controller */
  3035. return 0;
  3036. }
  3037. plci->State=INC_CON_CONNECTED_ALERT;
  3038. plci->appl = appl;
  3039. clear_c_ind_mask_bit (plci, (word)(appl->Id-1));
  3040. dump_c_ind_mask (plci);
  3041. for(i=0; i<max_appl; i++) /* disconnect the other appls */
  3042. { /* its quasi a connect */
  3043. if(test_c_ind_mask_bit (plci, i))
  3044. sendf(&application[i], _DISCONNECT_I, Id, 0, "w", _OTHER_APPL_CONNECTED);
  3045. }
  3046. }
  3047. api_save_msg(msg, "s", &plci->saved_msg);
  3048. tel = plci->tel;
  3049. if(Id & EXT_CONTROLLER)
  3050. {
  3051. if(tel) /* external controller in use by this PLCI */
  3052. {
  3053. if(a->AdvSignalAppl && a->AdvSignalAppl!=appl)
  3054. {
  3055. dbug(1,dprintf("Ext_Ctrl in use 1"));
  3056. Info = _WRONG_STATE;
  3057. }
  3058. }
  3059. else /* external controller NOT in use by this PLCI ? */
  3060. {
  3061. if(a->AdvSignalPLCI)
  3062. {
  3063. dbug(1,dprintf("Ext_Ctrl in use 2"));
  3064. Info = _WRONG_STATE;
  3065. }
  3066. else /* activate the codec */
  3067. {
  3068. dbug(1,dprintf("Ext_Ctrl start"));
  3069. if(AdvCodecSupport(a, plci, appl, 0) )
  3070. {
  3071. dbug(1,dprintf("Error in codec procedures"));
  3072. Info = _WRONG_STATE;
  3073. }
  3074. else if(plci->spoofed_msg==SPOOFING_REQUIRED) /* wait until codec is active */
  3075. {
  3076. plci->spoofed_msg = AWAITING_SELECT_B;
  3077. plci->internal_command = BLOCK_PLCI; /* lock other commands */
  3078. plci->command = 0;
  3079. dbug(1,dprintf("continue if codec loaded"));
  3080. return false;
  3081. }
  3082. }
  3083. }
  3084. }
  3085. else /* external controller bit is OFF */
  3086. {
  3087. if(tel) /* external controller in use, need to switch off */
  3088. {
  3089. if(a->AdvSignalAppl==appl)
  3090. {
  3091. CodecIdCheck(a, plci);
  3092. plci->tel = 0;
  3093. plci->adv_nl = 0;
  3094. dbug(1,dprintf("Ext_Ctrl disable"));
  3095. }
  3096. else
  3097. {
  3098. dbug(1,dprintf("Ext_Ctrl not requested"));
  3099. }
  3100. }
  3101. }
  3102. if (!Info)
  3103. {
  3104. if (plci->call_dir & CALL_DIR_OUT)
  3105. plci->call_dir = CALL_DIR_OUT | CALL_DIR_ORIGINATE;
  3106. else if (plci->call_dir & CALL_DIR_IN)
  3107. plci->call_dir = CALL_DIR_IN | CALL_DIR_ANSWER;
  3108. start_internal_command (Id, plci, select_b_command);
  3109. return false;
  3110. }
  3111. }
  3112. }
  3113. sendf(appl, _SELECT_B_REQ|CONFIRM, Id, Number, "w", Info);
  3114. return false;
  3115. }
  3116. static byte manufacturer_req(dword Id, word Number, DIVA_CAPI_ADAPTER *a,
  3117. PLCI *plci, APPL *appl, API_PARSE *parms)
  3118. {
  3119. word command;
  3120. word i;
  3121. word ncci;
  3122. API_PARSE * m;
  3123. API_PARSE m_parms[5];
  3124. word codec;
  3125. byte req;
  3126. byte ch;
  3127. byte dir;
  3128. static byte chi[2] = {0x01,0x00};
  3129. static byte lli[2] = {0x01,0x00};
  3130. static byte codec_cai[2] = {0x01,0x01};
  3131. static byte null_msg = {0};
  3132. static API_PARSE null_parms = { 0, &null_msg };
  3133. PLCI * v_plci;
  3134. word Info=0;
  3135. dbug(1,dprintf("manufacturer_req"));
  3136. for(i=0;i<5;i++) m_parms[i].length = 0;
  3137. if(GET_DWORD(parms[0].info)!=_DI_MANU_ID) {
  3138. Info = _WRONG_MESSAGE_FORMAT;
  3139. }
  3140. command = GET_WORD(parms[1].info);
  3141. m = &parms[2];
  3142. if (!Info)
  3143. {
  3144. switch(command) {
  3145. case _DI_ASSIGN_PLCI:
  3146. if(api_parse(&m->info[1],(word)m->length,"wbbs",m_parms)) {
  3147. Info = _WRONG_MESSAGE_FORMAT;
  3148. break;
  3149. }
  3150. codec = GET_WORD(m_parms[0].info);
  3151. ch = m_parms[1].info[0];
  3152. dir = m_parms[2].info[0];
  3153. if((i=get_plci(a))) {
  3154. plci = &a->plci[i-1];
  3155. plci->appl = appl;
  3156. plci->command = _MANUFACTURER_R;
  3157. plci->m_command = command;
  3158. plci->number = Number;
  3159. plci->State = LOCAL_CONNECT;
  3160. Id = ( ((word)plci->Id<<8)|plci->adapter->Id|0x80);
  3161. dbug(1,dprintf("ManCMD,plci=0x%x",Id));
  3162. if((ch==1 || ch==2) && (dir<=2)) {
  3163. chi[1] = (byte)(0x80|ch);
  3164. lli[1] = 0;
  3165. plci->call_dir = CALL_DIR_OUT | CALL_DIR_ORIGINATE;
  3166. switch(codec)
  3167. {
  3168. case 0:
  3169. Info = add_b1(plci,&m_parms[3],0,0);
  3170. break;
  3171. case 1:
  3172. add_p(plci,CAI,codec_cai);
  3173. break;
  3174. /* manual 'swich on' to the codec support without signalling */
  3175. /* first 'assign plci' with this function, then use */
  3176. case 2:
  3177. if(AdvCodecSupport(a, plci, appl, 0) ) {
  3178. Info = _RESOURCE_ERROR;
  3179. }
  3180. else {
  3181. Info = add_b1(plci,&null_parms,0,B1_FACILITY_LOCAL);
  3182. lli[1] = 0x10; /* local call codec stream */
  3183. }
  3184. break;
  3185. }
  3186. plci->State = LOCAL_CONNECT;
  3187. plci->manufacturer = true;
  3188. plci->command = _MANUFACTURER_R;
  3189. plci->m_command = command;
  3190. plci->number = Number;
  3191. if(!Info)
  3192. {
  3193. add_p(plci,LLI,lli);
  3194. add_p(plci,CHI,chi);
  3195. add_p(plci,UID,"\x06\x43\x61\x70\x69\x32\x30");
  3196. sig_req(plci,ASSIGN,DSIG_ID);
  3197. if(!codec)
  3198. {
  3199. Info = add_b23(plci,&m_parms[3]);
  3200. if(!Info)
  3201. {
  3202. nl_req_ncci(plci,ASSIGN,0);
  3203. send_req(plci);
  3204. }
  3205. }
  3206. if(!Info)
  3207. {
  3208. dbug(1,dprintf("dir=0x%x,spoof=0x%x",dir,plci->spoofed_msg));
  3209. if (plci->spoofed_msg==SPOOFING_REQUIRED)
  3210. {
  3211. api_save_msg (m_parms, "wbbs", &plci->saved_msg);
  3212. plci->spoofed_msg = AWAITING_MANUF_CON;
  3213. plci->internal_command = BLOCK_PLCI; /* reject other req meanwhile */
  3214. plci->command = 0;
  3215. send_req(plci);
  3216. return false;
  3217. }
  3218. if(dir==1) {
  3219. sig_req(plci,CALL_REQ,0);
  3220. }
  3221. else if(!dir){
  3222. sig_req(plci,LISTEN_REQ,0);
  3223. }
  3224. send_req(plci);
  3225. }
  3226. else
  3227. {
  3228. sendf(appl,
  3229. _MANUFACTURER_R|CONFIRM,
  3230. Id,
  3231. Number,
  3232. "dww",_DI_MANU_ID,command,Info);
  3233. return 2;
  3234. }
  3235. }
  3236. }
  3237. }
  3238. else Info = _OUT_OF_PLCI;
  3239. break;
  3240. case _DI_IDI_CTRL:
  3241. if(!plci)
  3242. {
  3243. Info = _WRONG_IDENTIFIER;
  3244. break;
  3245. }
  3246. if(api_parse(&m->info[1],(word)m->length,"bs",m_parms)) {
  3247. Info = _WRONG_MESSAGE_FORMAT;
  3248. break;
  3249. }
  3250. req = m_parms[0].info[0];
  3251. plci->command = _MANUFACTURER_R;
  3252. plci->m_command = command;
  3253. plci->number = Number;
  3254. if(req==CALL_REQ)
  3255. {
  3256. plci->b_channel = getChannel(&m_parms[1]);
  3257. mixer_set_bchannel_id_esc (plci, plci->b_channel);
  3258. if(plci->spoofed_msg==SPOOFING_REQUIRED)
  3259. {
  3260. plci->spoofed_msg = CALL_REQ | AWAITING_MANUF_CON;
  3261. plci->internal_command = BLOCK_PLCI; /* reject other req meanwhile */
  3262. plci->command = 0;
  3263. break;
  3264. }
  3265. }
  3266. else if(req==LAW_REQ)
  3267. {
  3268. plci->cr_enquiry = true;
  3269. }
  3270. add_ss(plci,FTY,&m_parms[1]);
  3271. sig_req(plci,req,0);
  3272. send_req(plci);
  3273. if(req==HANGUP)
  3274. {
  3275. if (plci->NL.Id && !plci->nl_remove_id)
  3276. {
  3277. if (plci->channels)
  3278. {
  3279. for (ncci = 1; ncci < MAX_NCCI+1; ncci++)
  3280. {
  3281. if ((a->ncci_plci[ncci] == plci->Id) && (a->ncci_state[ncci] == CONNECTED))
  3282. {
  3283. a->ncci_state[ncci] = OUTG_DIS_PENDING;
  3284. cleanup_ncci_data (plci, ncci);
  3285. nl_req_ncci(plci,N_DISC,(byte)ncci);
  3286. }
  3287. }
  3288. }
  3289. mixer_remove (plci);
  3290. nl_req_ncci(plci,REMOVE,0);
  3291. send_req(plci);
  3292. }
  3293. }
  3294. break;
  3295. case _DI_SIG_CTRL:
  3296. /* signalling control for loop activation B-channel */
  3297. if(!plci)
  3298. {
  3299. Info = _WRONG_IDENTIFIER;
  3300. break;
  3301. }
  3302. if(m->length){
  3303. plci->command = _MANUFACTURER_R;
  3304. plci->number = Number;
  3305. add_ss(plci,FTY,m);
  3306. sig_req(plci,SIG_CTRL,0);
  3307. send_req(plci);
  3308. }
  3309. else Info = _WRONG_MESSAGE_FORMAT;
  3310. break;
  3311. case _DI_RXT_CTRL:
  3312. /* activation control for receiver/transmitter B-channel */
  3313. if(!plci)
  3314. {
  3315. Info = _WRONG_IDENTIFIER;
  3316. break;
  3317. }
  3318. if(m->length){
  3319. plci->command = _MANUFACTURER_R;
  3320. plci->number = Number;
  3321. add_ss(plci,FTY,m);
  3322. sig_req(plci,DSP_CTRL,0);
  3323. send_req(plci);
  3324. }
  3325. else Info = _WRONG_MESSAGE_FORMAT;
  3326. break;
  3327. case _DI_ADV_CODEC:
  3328. case _DI_DSP_CTRL:
  3329. /* TEL_CTRL commands to support non standard adjustments: */
  3330. /* Ring on/off, Handset micro volume, external micro vol. */
  3331. /* handset+external speaker volume, receiver+transm. gain,*/
  3332. /* handsfree on (hookinfo off), set mixer command */
  3333. if(command == _DI_ADV_CODEC)
  3334. {
  3335. if(!a->AdvCodecPLCI) {
  3336. Info = _WRONG_STATE;
  3337. break;
  3338. }
  3339. v_plci = a->AdvCodecPLCI;
  3340. }
  3341. else
  3342. {
  3343. if (plci
  3344. && (m->length >= 3)
  3345. && (m->info[1] == 0x1c)
  3346. && (m->info[2] >= 1))
  3347. {
  3348. if (m->info[3] == DSP_CTRL_OLD_SET_MIXER_COEFFICIENTS)
  3349. {
  3350. if ((plci->tel != ADV_VOICE) || (plci != a->AdvSignalPLCI))
  3351. {
  3352. Info = _WRONG_STATE;
  3353. break;
  3354. }
  3355. a->adv_voice_coef_length = m->info[2] - 1;
  3356. if (a->adv_voice_coef_length > m->length - 3)
  3357. a->adv_voice_coef_length = (byte)(m->length - 3);
  3358. if (a->adv_voice_coef_length > ADV_VOICE_COEF_BUFFER_SIZE)
  3359. a->adv_voice_coef_length = ADV_VOICE_COEF_BUFFER_SIZE;
  3360. for (i = 0; i < a->adv_voice_coef_length; i++)
  3361. a->adv_voice_coef_buffer[i] = m->info[4 + i];
  3362. if (plci->B1_facilities & B1_FACILITY_VOICE)
  3363. adv_voice_write_coefs (plci, ADV_VOICE_WRITE_UPDATE);
  3364. break;
  3365. }
  3366. else if (m->info[3] == DSP_CTRL_SET_DTMF_PARAMETERS)
  3367. {
  3368. if (!(a->manufacturer_features & MANUFACTURER_FEATURE_DTMF_PARAMETERS))
  3369. {
  3370. Info = _FACILITY_NOT_SUPPORTED;
  3371. break;
  3372. }
  3373. plci->dtmf_parameter_length = m->info[2] - 1;
  3374. if (plci->dtmf_parameter_length > m->length - 3)
  3375. plci->dtmf_parameter_length = (byte)(m->length - 3);
  3376. if (plci->dtmf_parameter_length > DTMF_PARAMETER_BUFFER_SIZE)
  3377. plci->dtmf_parameter_length = DTMF_PARAMETER_BUFFER_SIZE;
  3378. for (i = 0; i < plci->dtmf_parameter_length; i++)
  3379. plci->dtmf_parameter_buffer[i] = m->info[4+i];
  3380. if (plci->B1_facilities & B1_FACILITY_DTMFR)
  3381. dtmf_parameter_write (plci);
  3382. break;
  3383. }
  3384. }
  3385. v_plci = plci;
  3386. }
  3387. if(!v_plci)
  3388. {
  3389. Info = _WRONG_IDENTIFIER;
  3390. break;
  3391. }
  3392. if(m->length){
  3393. add_ss(v_plci,FTY,m);
  3394. sig_req(v_plci,TEL_CTRL,0);
  3395. send_req(v_plci);
  3396. }
  3397. else Info = _WRONG_MESSAGE_FORMAT;
  3398. break;
  3399. case _DI_OPTIONS_REQUEST:
  3400. if(api_parse(&m->info[1],(word)m->length,"d",m_parms)) {
  3401. Info = _WRONG_MESSAGE_FORMAT;
  3402. break;
  3403. }
  3404. if (GET_DWORD (m_parms[0].info) & ~a->man_profile.private_options)
  3405. {
  3406. Info = _FACILITY_NOT_SUPPORTED;
  3407. break;
  3408. }
  3409. a->requested_options_table[appl->Id-1] = GET_DWORD (m_parms[0].info);
  3410. break;
  3411. default:
  3412. Info = _WRONG_MESSAGE_FORMAT;
  3413. break;
  3414. }
  3415. }
  3416. sendf(appl,
  3417. _MANUFACTURER_R|CONFIRM,
  3418. Id,
  3419. Number,
  3420. "dww",_DI_MANU_ID,command,Info);
  3421. return false;
  3422. }
  3423. static byte manufacturer_res(dword Id, word Number, DIVA_CAPI_ADAPTER *a,
  3424. PLCI *plci, APPL *appl, API_PARSE *msg)
  3425. {
  3426. word indication;
  3427. API_PARSE m_parms[3];
  3428. API_PARSE *ncpi;
  3429. API_PARSE fax_parms[9];
  3430. word i;
  3431. byte len;
  3432. dbug(1,dprintf("manufacturer_res"));
  3433. if ((msg[0].length == 0)
  3434. || (msg[1].length == 0)
  3435. || (GET_DWORD(msg[0].info)!=_DI_MANU_ID))
  3436. {
  3437. return false;
  3438. }
  3439. indication = GET_WORD(msg[1].info);
  3440. switch (indication)
  3441. {
  3442. case _DI_NEGOTIATE_B3:
  3443. if(!plci)
  3444. break;
  3445. if (((plci->B3_prot != 4) && (plci->B3_prot != 5))
  3446. || !(plci->ncpi_state & NCPI_NEGOTIATE_B3_SENT))
  3447. {
  3448. dbug(1,dprintf("wrong state for NEGOTIATE_B3 parameters"));
  3449. break;
  3450. }
  3451. if (api_parse (&msg[2].info[1], msg[2].length, "ws", m_parms))
  3452. {
  3453. dbug(1,dprintf("wrong format in NEGOTIATE_B3 parameters"));
  3454. break;
  3455. }
  3456. ncpi = &m_parms[1];
  3457. len = offsetof(T30_INFO, station_id) + 20;
  3458. if (plci->fax_connect_info_length < len)
  3459. {
  3460. ((T30_INFO *)(plci->fax_connect_info_buffer))->station_id_len = 0;
  3461. ((T30_INFO *)(plci->fax_connect_info_buffer))->head_line_len = 0;
  3462. }
  3463. if (api_parse (&ncpi->info[1], ncpi->length, "wwwwssss", fax_parms))
  3464. {
  3465. dbug(1,dprintf("non-standard facilities info missing or wrong format"));
  3466. }
  3467. else
  3468. {
  3469. if (plci->fax_connect_info_length <= len)
  3470. plci->fax_connect_info_buffer[len] = 0;
  3471. len += 1 + plci->fax_connect_info_buffer[len];
  3472. if (plci->fax_connect_info_length <= len)
  3473. plci->fax_connect_info_buffer[len] = 0;
  3474. len += 1 + plci->fax_connect_info_buffer[len];
  3475. if ((fax_parms[7].length >= 3) && (fax_parms[7].info[1] >= 2))
  3476. plci->nsf_control_bits = GET_WORD(&fax_parms[7].info[2]);
  3477. plci->fax_connect_info_buffer[len++] = (byte)(fax_parms[7].length);
  3478. for (i = 0; i < fax_parms[7].length; i++)
  3479. plci->fax_connect_info_buffer[len++] = fax_parms[7].info[1+i];
  3480. }
  3481. plci->fax_connect_info_length = len;
  3482. plci->fax_edata_ack_length = plci->fax_connect_info_length;
  3483. start_internal_command (Id, plci, fax_edata_ack_command);
  3484. break;
  3485. }
  3486. return false;
  3487. }
  3488. /*------------------------------------------------------------------*/
  3489. /* IDI callback function */
  3490. /*------------------------------------------------------------------*/
  3491. void callback(ENTITY * e)
  3492. {
  3493. DIVA_CAPI_ADAPTER * a;
  3494. APPL * appl;
  3495. PLCI * plci;
  3496. CAPI_MSG *m;
  3497. word i, j;
  3498. byte rc;
  3499. byte ch;
  3500. byte req;
  3501. byte global_req;
  3502. int no_cancel_rc;
  3503. dbug(1,dprintf("%x:CB(%x:Req=%x,Rc=%x,Ind=%x)",
  3504. (e->user[0]+1)&0x7fff,e->Id,e->Req,e->Rc,e->Ind));
  3505. a = &(adapter[(byte)e->user[0]]);
  3506. plci = &(a->plci[e->user[1]]);
  3507. no_cancel_rc = DIVA_CAPI_SUPPORTS_NO_CANCEL(a);
  3508. /*
  3509. If new protocol code and new XDI is used then CAPI should work
  3510. fully in accordance with IDI cpec an look on callback field instead
  3511. of Rc field for return codes.
  3512. */
  3513. if (((e->complete == 0xff) && no_cancel_rc) ||
  3514. (e->Rc && !no_cancel_rc)) {
  3515. rc = e->Rc;
  3516. ch = e->RcCh;
  3517. req = e->Req;
  3518. e->Rc = 0;
  3519. if (e->user[0] & 0x8000)
  3520. {
  3521. /*
  3522. If REMOVE request was sent then we have to wait until
  3523. return code with Id set to zero arrives.
  3524. All other return codes should be ignored.
  3525. */
  3526. if (req == REMOVE)
  3527. {
  3528. if (e->Id)
  3529. {
  3530. dbug(1,dprintf("cancel RC in REMOVE state"));
  3531. return;
  3532. }
  3533. channel_flow_control_remove (plci);
  3534. for (i = 0; i < 256; i++)
  3535. {
  3536. if (a->FlowControlIdTable[i] == plci->nl_remove_id)
  3537. a->FlowControlIdTable[i] = 0;
  3538. }
  3539. plci->nl_remove_id = 0;
  3540. if (plci->rx_dma_descriptor > 0) {
  3541. diva_free_dma_descriptor (plci, plci->rx_dma_descriptor - 1);
  3542. plci->rx_dma_descriptor = 0;
  3543. }
  3544. }
  3545. if (rc == OK_FC)
  3546. {
  3547. a->FlowControlIdTable[ch] = e->Id;
  3548. a->FlowControlSkipTable[ch] = 0;
  3549. a->ch_flow_control[ch] |= N_OK_FC_PENDING;
  3550. a->ch_flow_plci[ch] = plci->Id;
  3551. plci->nl_req = 0;
  3552. }
  3553. else
  3554. {
  3555. /*
  3556. Cancel return codes self, if feature was requested
  3557. */
  3558. if (no_cancel_rc && (a->FlowControlIdTable[ch] == e->Id) && e->Id) {
  3559. a->FlowControlIdTable[ch] = 0;
  3560. if ((rc == OK) && a->FlowControlSkipTable[ch]) {
  3561. dbug(3,dprintf ("XDI CAPI: RC cancelled Id:0x02, Ch:%02x", e->Id, ch));
  3562. return;
  3563. }
  3564. }
  3565. if (a->ch_flow_control[ch] & N_OK_FC_PENDING)
  3566. {
  3567. a->ch_flow_control[ch] &= ~N_OK_FC_PENDING;
  3568. if (ch == e->ReqCh)
  3569. plci->nl_req = 0;
  3570. }
  3571. else
  3572. plci->nl_req = 0;
  3573. }
  3574. if (plci->nl_req)
  3575. control_rc (plci, 0, rc, ch, 0, true);
  3576. else
  3577. {
  3578. if (req == N_XON)
  3579. {
  3580. channel_x_on (plci, ch);
  3581. if (plci->internal_command)
  3582. control_rc (plci, req, rc, ch, 0, true);
  3583. }
  3584. else
  3585. {
  3586. if (plci->nl_global_req)
  3587. {
  3588. global_req = plci->nl_global_req;
  3589. plci->nl_global_req = 0;
  3590. if (rc != ASSIGN_OK) {
  3591. e->Id = 0;
  3592. if (plci->rx_dma_descriptor > 0) {
  3593. diva_free_dma_descriptor (plci, plci->rx_dma_descriptor - 1);
  3594. plci->rx_dma_descriptor = 0;
  3595. }
  3596. }
  3597. channel_xmit_xon (plci);
  3598. control_rc (plci, 0, rc, ch, global_req, true);
  3599. }
  3600. else if (plci->data_sent)
  3601. {
  3602. channel_xmit_xon (plci);
  3603. plci->data_sent = false;
  3604. plci->NL.XNum = 1;
  3605. data_rc (plci, ch);
  3606. if (plci->internal_command)
  3607. control_rc (plci, req, rc, ch, 0, true);
  3608. }
  3609. else
  3610. {
  3611. channel_xmit_xon (plci);
  3612. control_rc (plci, req, rc, ch, 0, true);
  3613. }
  3614. }
  3615. }
  3616. }
  3617. else
  3618. {
  3619. /*
  3620. If REMOVE request was sent then we have to wait until
  3621. return code with Id set to zero arrives.
  3622. All other return codes should be ignored.
  3623. */
  3624. if (req == REMOVE)
  3625. {
  3626. if (e->Id)
  3627. {
  3628. dbug(1,dprintf("cancel RC in REMOVE state"));
  3629. return;
  3630. }
  3631. plci->sig_remove_id = 0;
  3632. }
  3633. plci->sig_req = 0;
  3634. if (plci->sig_global_req)
  3635. {
  3636. global_req = plci->sig_global_req;
  3637. plci->sig_global_req = 0;
  3638. if (rc != ASSIGN_OK)
  3639. e->Id = 0;
  3640. channel_xmit_xon (plci);
  3641. control_rc (plci, 0, rc, ch, global_req, false);
  3642. }
  3643. else
  3644. {
  3645. channel_xmit_xon (plci);
  3646. control_rc (plci, req, rc, ch, 0, false);
  3647. }
  3648. }
  3649. /*
  3650. Again: in accordance with IDI spec Rc and Ind can't be delivered in the
  3651. same callback. Also if new XDI and protocol code used then jump
  3652. direct to finish.
  3653. */
  3654. if (no_cancel_rc) {
  3655. channel_xmit_xon(plci);
  3656. goto capi_callback_suffix;
  3657. }
  3658. }
  3659. channel_xmit_xon(plci);
  3660. if (e->Ind) {
  3661. if (e->user[0] &0x8000) {
  3662. byte Ind = e->Ind & 0x0f;
  3663. byte Ch = e->IndCh;
  3664. if (((Ind==N_DISC) || (Ind==N_DISC_ACK)) &&
  3665. (a->ch_flow_plci[Ch] == plci->Id)) {
  3666. if (a->ch_flow_control[Ch] & N_RX_FLOW_CONTROL_MASK) {
  3667. dbug(3,dprintf ("XDI CAPI: I: pending N-XON Ch:%02x", Ch));
  3668. }
  3669. a->ch_flow_control[Ch] &= ~N_RX_FLOW_CONTROL_MASK;
  3670. }
  3671. nl_ind(plci);
  3672. if ((e->RNR != 1) &&
  3673. (a->ch_flow_plci[Ch] == plci->Id) &&
  3674. (a->ch_flow_control[Ch] & N_RX_FLOW_CONTROL_MASK)) {
  3675. a->ch_flow_control[Ch] &= ~N_RX_FLOW_CONTROL_MASK;
  3676. dbug(3,dprintf ("XDI CAPI: I: remove faked N-XON Ch:%02x", Ch));
  3677. }
  3678. } else {
  3679. sig_ind(plci);
  3680. }
  3681. e->Ind = 0;
  3682. }
  3683. capi_callback_suffix:
  3684. while (!plci->req_in
  3685. && !plci->internal_command
  3686. && (plci->msg_in_write_pos != plci->msg_in_read_pos))
  3687. {
  3688. j = (plci->msg_in_read_pos == plci->msg_in_wrap_pos) ? 0 : plci->msg_in_read_pos;
  3689. i = (((CAPI_MSG *)(&((byte *)(plci->msg_in_queue))[j]))->header.length + 3) & 0xfffc;
  3690. m = (CAPI_MSG *)(&((byte *)(plci->msg_in_queue))[j]);
  3691. appl = *((APPL * *)(&((byte *)(plci->msg_in_queue))[j+i]));
  3692. dbug(1,dprintf("dequeue msg(0x%04x) - write=%d read=%d wrap=%d",
  3693. m->header.command, plci->msg_in_write_pos, plci->msg_in_read_pos, plci->msg_in_wrap_pos));
  3694. if (plci->msg_in_read_pos == plci->msg_in_wrap_pos)
  3695. {
  3696. plci->msg_in_wrap_pos = MSG_IN_QUEUE_SIZE;
  3697. plci->msg_in_read_pos = i + MSG_IN_OVERHEAD;
  3698. }
  3699. else
  3700. {
  3701. plci->msg_in_read_pos = j + i + MSG_IN_OVERHEAD;
  3702. }
  3703. if (plci->msg_in_read_pos == plci->msg_in_write_pos)
  3704. {
  3705. plci->msg_in_write_pos = MSG_IN_QUEUE_SIZE;
  3706. plci->msg_in_read_pos = MSG_IN_QUEUE_SIZE;
  3707. }
  3708. else if (plci->msg_in_read_pos == plci->msg_in_wrap_pos)
  3709. {
  3710. plci->msg_in_read_pos = MSG_IN_QUEUE_SIZE;
  3711. plci->msg_in_wrap_pos = MSG_IN_QUEUE_SIZE;
  3712. }
  3713. i = api_put (appl, m);
  3714. if (i != 0)
  3715. {
  3716. if (m->header.command == _DATA_B3_R)
  3717. TransmitBufferFree (appl, (byte *)(long)(m->info.data_b3_req.Data));
  3718. dbug(1,dprintf("Error 0x%04x from msg(0x%04x)", i, m->header.command));
  3719. break;
  3720. }
  3721. if (plci->li_notify_update)
  3722. {
  3723. plci->li_notify_update = false;
  3724. mixer_notify_update (plci, false);
  3725. }
  3726. }
  3727. send_data(plci);
  3728. send_req(plci);
  3729. }
  3730. static void control_rc(PLCI *plci, byte req, byte rc, byte ch, byte global_req,
  3731. byte nl_rc)
  3732. {
  3733. dword Id;
  3734. dword rId;
  3735. word Number;
  3736. word Info=0;
  3737. word i;
  3738. word ncci;
  3739. DIVA_CAPI_ADAPTER * a;
  3740. APPL * appl;
  3741. PLCI * rplci;
  3742. byte SSparms[] = "\x05\x00\x00\x02\x00\x00";
  3743. byte SSstruct[] = "\x09\x00\x00\x06\x00\x00\x00\x00\x00\x00";
  3744. if (!plci) {
  3745. dbug(0,dprintf("A: control_rc, no plci %02x:%02x:%02x:%02x:%02x", req, rc, ch, global_req, nl_rc));
  3746. return;
  3747. }
  3748. dbug(1,dprintf("req0_in/out=%d/%d",plci->req_in,plci->req_out));
  3749. if(plci->req_in!=plci->req_out)
  3750. {
  3751. if (nl_rc || (global_req != ASSIGN) || (rc == ASSIGN_OK))
  3752. {
  3753. dbug(1,dprintf("req_1return"));
  3754. return;
  3755. }
  3756. /* cancel outstanding request on the PLCI after SIG ASSIGN failure */
  3757. }
  3758. plci->req_in = plci->req_in_start = plci->req_out = 0;
  3759. dbug(1,dprintf("control_rc"));
  3760. appl = plci->appl;
  3761. a = plci->adapter;
  3762. ncci = a->ch_ncci[ch];
  3763. if(appl)
  3764. {
  3765. Id = (((dword)(ncci ? ncci : ch)) << 16) | ((word)plci->Id << 8) | a->Id;
  3766. if(plci->tel && plci->SuppState!=CALL_HELD) Id|=EXT_CONTROLLER;
  3767. Number = plci->number;
  3768. 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));
  3769. dbug(1,dprintf("channels=0x%x",plci->channels));
  3770. if (plci_remove_check(plci))
  3771. return;
  3772. if(req==REMOVE && rc==ASSIGN_OK)
  3773. {
  3774. sig_req(plci,HANGUP,0);
  3775. sig_req(plci,REMOVE,0);
  3776. send_req(plci);
  3777. }
  3778. if(plci->command)
  3779. {
  3780. switch(plci->command)
  3781. {
  3782. case C_HOLD_REQ:
  3783. dbug(1,dprintf("HoldRC=0x%x",rc));
  3784. SSparms[1] = (byte)S_HOLD;
  3785. if(rc!=OK)
  3786. {
  3787. plci->SuppState = IDLE;
  3788. Info = 0x2001;
  3789. }
  3790. sendf(appl,_FACILITY_R|CONFIRM,Id,Number,"wws",Info,3,SSparms);
  3791. break;
  3792. case C_RETRIEVE_REQ:
  3793. dbug(1,dprintf("RetrieveRC=0x%x",rc));
  3794. SSparms[1] = (byte)S_RETRIEVE;
  3795. if(rc!=OK)
  3796. {
  3797. plci->SuppState = CALL_HELD;
  3798. Info = 0x2001;
  3799. }
  3800. sendf(appl,_FACILITY_R|CONFIRM,Id,Number,"wws",Info,3,SSparms);
  3801. break;
  3802. case _INFO_R:
  3803. dbug(1,dprintf("InfoRC=0x%x",rc));
  3804. if(rc!=OK) Info=_WRONG_STATE;
  3805. sendf(appl,_INFO_R|CONFIRM,Id,Number,"w",Info);
  3806. break;
  3807. case _CONNECT_R:
  3808. dbug(1,dprintf("Connect_R=0x%x/0x%x/0x%x/0x%x",req,rc,global_req,nl_rc));
  3809. if (plci->State == INC_DIS_PENDING)
  3810. break;
  3811. if(plci->Sig.Id!=0xff)
  3812. {
  3813. if (((global_req == ASSIGN) && (rc != ASSIGN_OK))
  3814. || (!nl_rc && (req == CALL_REQ) && (rc != OK)))
  3815. {
  3816. dbug(1,dprintf("No more IDs/Call_Req failed"));
  3817. sendf(appl,_CONNECT_R|CONFIRM,Id&0xffL,Number,"w",_OUT_OF_PLCI);
  3818. plci_remove(plci);
  3819. plci->State = IDLE;
  3820. break;
  3821. }
  3822. if(plci->State!=LOCAL_CONNECT)plci->State = OUTG_CON_PENDING;
  3823. sendf(appl,_CONNECT_R|CONFIRM,Id,Number,"w",0);
  3824. }
  3825. else /* D-ch activation */
  3826. {
  3827. if (rc != ASSIGN_OK)
  3828. {
  3829. dbug(1,dprintf("No more IDs/X.25 Call_Req failed"));
  3830. sendf(appl,_CONNECT_R|CONFIRM,Id&0xffL,Number,"w",_OUT_OF_PLCI);
  3831. plci_remove(plci);
  3832. plci->State = IDLE;
  3833. break;
  3834. }
  3835. sendf(appl,_CONNECT_R|CONFIRM,Id,Number,"w",0);
  3836. sendf(plci->appl,_CONNECT_ACTIVE_I,Id,0,"sss","","","");
  3837. plci->State = INC_ACT_PENDING;
  3838. }
  3839. break;
  3840. case _CONNECT_I|RESPONSE:
  3841. if (plci->State != INC_DIS_PENDING)
  3842. plci->State = INC_CON_ACCEPT;
  3843. break;
  3844. case _DISCONNECT_R:
  3845. if (plci->State == INC_DIS_PENDING)
  3846. break;
  3847. if(plci->Sig.Id!=0xff)
  3848. {
  3849. plci->State = OUTG_DIS_PENDING;
  3850. sendf(appl,_DISCONNECT_R|CONFIRM,Id,Number,"w",0);
  3851. }
  3852. break;
  3853. case SUSPEND_REQ:
  3854. break;
  3855. case RESUME_REQ:
  3856. break;
  3857. case _CONNECT_B3_R:
  3858. if(rc!=OK)
  3859. {
  3860. sendf(appl,_CONNECT_B3_R|CONFIRM,Id,Number,"w",_WRONG_IDENTIFIER);
  3861. break;
  3862. }
  3863. ncci = get_ncci (plci, ch, 0);
  3864. Id = (Id & 0xffff) | (((dword) ncci) << 16);
  3865. plci->channels++;
  3866. if(req==N_RESET)
  3867. {
  3868. a->ncci_state[ncci] = INC_ACT_PENDING;
  3869. sendf(appl,_CONNECT_B3_R|CONFIRM,Id,Number,"w",0);
  3870. sendf(appl,_CONNECT_B3_ACTIVE_I,Id,0,"s","");
  3871. }
  3872. else
  3873. {
  3874. a->ncci_state[ncci] = OUTG_CON_PENDING;
  3875. sendf(appl,_CONNECT_B3_R|CONFIRM,Id,Number,"w",0);
  3876. }
  3877. break;
  3878. case _CONNECT_B3_I|RESPONSE:
  3879. break;
  3880. case _RESET_B3_R:
  3881. /* sendf(appl,_RESET_B3_R|CONFIRM,Id,Number,"w",0);*/
  3882. break;
  3883. case _DISCONNECT_B3_R:
  3884. sendf(appl,_DISCONNECT_B3_R|CONFIRM,Id,Number,"w",0);
  3885. break;
  3886. case _MANUFACTURER_R:
  3887. break;
  3888. case PERM_LIST_REQ:
  3889. if(rc!=OK)
  3890. {
  3891. Info = _WRONG_IDENTIFIER;
  3892. sendf(plci->appl,_CONNECT_R|CONFIRM,Id,Number,"w",Info);
  3893. plci_remove(plci);
  3894. }
  3895. else
  3896. sendf(plci->appl,_CONNECT_R|CONFIRM,Id,Number,"w",Info);
  3897. break;
  3898. default:
  3899. break;
  3900. }
  3901. plci->command = 0;
  3902. }
  3903. else if (plci->internal_command)
  3904. {
  3905. switch(plci->internal_command)
  3906. {
  3907. case BLOCK_PLCI:
  3908. return;
  3909. case GET_MWI_STATE:
  3910. if(rc==OK) /* command supported, wait for indication */
  3911. {
  3912. return;
  3913. }
  3914. plci_remove(plci);
  3915. break;
  3916. /* Get Supported Services */
  3917. case GETSERV_REQ_PEND:
  3918. if(rc==OK) /* command supported, wait for indication */
  3919. {
  3920. break;
  3921. }
  3922. PUT_DWORD(&SSstruct[6], MASK_TERMINAL_PORTABILITY);
  3923. sendf(appl, _FACILITY_R|CONFIRM, Id, Number, "wws",0,3,SSstruct);
  3924. plci_remove(plci);
  3925. break;
  3926. case INTERR_DIVERSION_REQ_PEND: /* Interrogate Parameters */
  3927. case INTERR_NUMBERS_REQ_PEND:
  3928. case CF_START_PEND: /* Call Forwarding Start pending */
  3929. case CF_STOP_PEND: /* Call Forwarding Stop pending */
  3930. case CCBS_REQUEST_REQ_PEND:
  3931. case CCBS_DEACTIVATE_REQ_PEND:
  3932. case CCBS_INTERROGATE_REQ_PEND:
  3933. switch(plci->internal_command)
  3934. {
  3935. case INTERR_DIVERSION_REQ_PEND:
  3936. SSparms[1] = S_INTERROGATE_DIVERSION;
  3937. break;
  3938. case INTERR_NUMBERS_REQ_PEND:
  3939. SSparms[1] = S_INTERROGATE_NUMBERS;
  3940. break;
  3941. case CF_START_PEND:
  3942. SSparms[1] = S_CALL_FORWARDING_START;
  3943. break;
  3944. case CF_STOP_PEND:
  3945. SSparms[1] = S_CALL_FORWARDING_STOP;
  3946. break;
  3947. case CCBS_REQUEST_REQ_PEND:
  3948. SSparms[1] = S_CCBS_REQUEST;
  3949. break;
  3950. case CCBS_DEACTIVATE_REQ_PEND:
  3951. SSparms[1] = S_CCBS_DEACTIVATE;
  3952. break;
  3953. case CCBS_INTERROGATE_REQ_PEND:
  3954. SSparms[1] = S_CCBS_INTERROGATE;
  3955. break;
  3956. }
  3957. if(global_req==ASSIGN)
  3958. {
  3959. dbug(1,dprintf("AssignDiversion_RC=0x%x/0x%x",req,rc));
  3960. return;
  3961. }
  3962. if(!plci->appl) break;
  3963. if(rc==ISDN_GUARD_REJ)
  3964. {
  3965. Info = _CAPI_GUARD_ERROR;
  3966. }
  3967. else if(rc!=OK)
  3968. {
  3969. Info = _SUPPLEMENTARY_SERVICE_NOT_SUPPORTED;
  3970. }
  3971. sendf(plci->appl,_FACILITY_R|CONFIRM,Id&0x7,
  3972. plci->number,"wws",Info,(word)3,SSparms);
  3973. if(Info) plci_remove(plci);
  3974. break;
  3975. /* 3pty conference pending */
  3976. case PTY_REQ_PEND:
  3977. if(!plci->relatedPTYPLCI) break;
  3978. rplci = plci->relatedPTYPLCI;
  3979. SSparms[1] = plci->ptyState;
  3980. rId = ((word)rplci->Id<<8)|rplci->adapter->Id;
  3981. if(rplci->tel) rId|=EXT_CONTROLLER;
  3982. if(rc!=OK)
  3983. {
  3984. Info = 0x300E; /* not supported */
  3985. plci->relatedPTYPLCI = NULL;
  3986. plci->ptyState = 0;
  3987. }
  3988. sendf(rplci->appl,
  3989. _FACILITY_R|CONFIRM,
  3990. rId,
  3991. plci->number,
  3992. "wws",Info,(word)3,SSparms);
  3993. break;
  3994. /* Explicit Call Transfer pending */
  3995. case ECT_REQ_PEND:
  3996. dbug(1,dprintf("ECT_RC=0x%x/0x%x",req,rc));
  3997. if(!plci->relatedPTYPLCI) break;
  3998. rplci = plci->relatedPTYPLCI;
  3999. SSparms[1] = S_ECT;
  4000. rId = ((word)rplci->Id<<8)|rplci->adapter->Id;
  4001. if(rplci->tel) rId|=EXT_CONTROLLER;
  4002. if(rc!=OK)
  4003. {
  4004. Info = 0x300E; /* not supported */
  4005. plci->relatedPTYPLCI = NULL;
  4006. plci->ptyState = 0;
  4007. }
  4008. sendf(rplci->appl,
  4009. _FACILITY_R|CONFIRM,
  4010. rId,
  4011. plci->number,
  4012. "wws",Info,(word)3,SSparms);
  4013. break;
  4014. case _MANUFACTURER_R:
  4015. dbug(1,dprintf("_Manufacturer_R=0x%x/0x%x",req,rc));
  4016. if ((global_req == ASSIGN) && (rc != ASSIGN_OK))
  4017. {
  4018. dbug(1,dprintf("No more IDs"));
  4019. sendf(appl,_MANUFACTURER_R|CONFIRM,Id,Number,"dww",_DI_MANU_ID,_MANUFACTURER_R,_OUT_OF_PLCI);
  4020. plci_remove(plci); /* after codec init, internal codec commands pending */
  4021. }
  4022. break;
  4023. case _CONNECT_R:
  4024. dbug(1,dprintf("_Connect_R=0x%x/0x%x",req,rc));
  4025. if ((global_req == ASSIGN) && (rc != ASSIGN_OK))
  4026. {
  4027. dbug(1,dprintf("No more IDs"));
  4028. sendf(appl,_CONNECT_R|CONFIRM,Id&0xffL,Number,"w",_OUT_OF_PLCI);
  4029. plci_remove(plci); /* after codec init, internal codec commands pending */
  4030. }
  4031. break;
  4032. case PERM_COD_HOOK: /* finished with Hook_Ind */
  4033. return;
  4034. case PERM_COD_CALL:
  4035. dbug(1,dprintf("***Codec Connect_Pending A, Rc = 0x%x",rc));
  4036. plci->internal_command = PERM_COD_CONN_PEND;
  4037. return;
  4038. case PERM_COD_ASSIGN:
  4039. dbug(1,dprintf("***Codec Assign A, Rc = 0x%x",rc));
  4040. if(rc!=ASSIGN_OK) break;
  4041. sig_req(plci,CALL_REQ,0);
  4042. send_req(plci);
  4043. plci->internal_command = PERM_COD_CALL;
  4044. return;
  4045. /* Null Call Reference Request pending */
  4046. case C_NCR_FAC_REQ:
  4047. dbug(1,dprintf("NCR_FAC=0x%x/0x%x",req,rc));
  4048. if(global_req==ASSIGN)
  4049. {
  4050. if(rc==ASSIGN_OK)
  4051. {
  4052. return;
  4053. }
  4054. else
  4055. {
  4056. sendf(appl,_INFO_R|CONFIRM,Id&0xf,Number,"w",_WRONG_STATE);
  4057. appl->NullCREnable = false;
  4058. plci_remove(plci);
  4059. }
  4060. }
  4061. else if(req==NCR_FACILITY)
  4062. {
  4063. if(rc==OK)
  4064. {
  4065. sendf(appl,_INFO_R|CONFIRM,Id&0xf,Number,"w",0);
  4066. }
  4067. else
  4068. {
  4069. sendf(appl,_INFO_R|CONFIRM,Id&0xf,Number,"w",_WRONG_STATE);
  4070. appl->NullCREnable = false;
  4071. }
  4072. plci_remove(plci);
  4073. }
  4074. break;
  4075. case HOOK_ON_REQ:
  4076. if(plci->channels)
  4077. {
  4078. if(a->ncci_state[ncci]==CONNECTED)
  4079. {
  4080. a->ncci_state[ncci] = OUTG_DIS_PENDING;
  4081. cleanup_ncci_data (plci, ncci);
  4082. nl_req_ncci(plci,N_DISC,(byte)ncci);
  4083. }
  4084. break;
  4085. }
  4086. break;
  4087. case HOOK_OFF_REQ:
  4088. if (plci->State == INC_DIS_PENDING)
  4089. break;
  4090. sig_req(plci,CALL_REQ,0);
  4091. send_req(plci);
  4092. plci->State=OUTG_CON_PENDING;
  4093. break;
  4094. case MWI_ACTIVATE_REQ_PEND:
  4095. case MWI_DEACTIVATE_REQ_PEND:
  4096. if(global_req == ASSIGN && rc==ASSIGN_OK)
  4097. {
  4098. dbug(1,dprintf("MWI_REQ assigned"));
  4099. return;
  4100. }
  4101. else if(rc!=OK)
  4102. {
  4103. if(rc==WRONG_IE)
  4104. {
  4105. Info = 0x2007; /* Illegal message parameter coding */
  4106. dbug(1,dprintf("MWI_REQ invalid parameter"));
  4107. }
  4108. else
  4109. {
  4110. Info = 0x300B; /* not supported */
  4111. dbug(1,dprintf("MWI_REQ not supported"));
  4112. }
  4113. /* 0x3010: Request not allowed in this state */
  4114. PUT_WORD(&SSparms[4],0x300E); /* SS not supported */
  4115. }
  4116. if(plci->internal_command==MWI_ACTIVATE_REQ_PEND)
  4117. {
  4118. PUT_WORD(&SSparms[1],S_MWI_ACTIVATE);
  4119. }
  4120. else PUT_WORD(&SSparms[1],S_MWI_DEACTIVATE);
  4121. if(plci->cr_enquiry)
  4122. {
  4123. sendf(plci->appl,
  4124. _FACILITY_R|CONFIRM,
  4125. Id&0xf,
  4126. plci->number,
  4127. "wws",Info,(word)3,SSparms);
  4128. if(rc!=OK) plci_remove(plci);
  4129. }
  4130. else
  4131. {
  4132. sendf(plci->appl,
  4133. _FACILITY_R|CONFIRM,
  4134. Id,
  4135. plci->number,
  4136. "wws",Info,(word)3,SSparms);
  4137. }
  4138. break;
  4139. case CONF_BEGIN_REQ_PEND:
  4140. case CONF_ADD_REQ_PEND:
  4141. case CONF_SPLIT_REQ_PEND:
  4142. case CONF_DROP_REQ_PEND:
  4143. case CONF_ISOLATE_REQ_PEND:
  4144. case CONF_REATTACH_REQ_PEND:
  4145. dbug(1,dprintf("CONF_RC=0x%x/0x%x",req,rc));
  4146. if((plci->internal_command==CONF_ADD_REQ_PEND)&&(!plci->relatedPTYPLCI)) break;
  4147. rplci = plci;
  4148. rId = Id;
  4149. switch(plci->internal_command)
  4150. {
  4151. case CONF_BEGIN_REQ_PEND:
  4152. SSparms[1] = S_CONF_BEGIN;
  4153. break;
  4154. case CONF_ADD_REQ_PEND:
  4155. SSparms[1] = S_CONF_ADD;
  4156. rplci = plci->relatedPTYPLCI;
  4157. rId = ((word)rplci->Id<<8)|rplci->adapter->Id;
  4158. break;
  4159. case CONF_SPLIT_REQ_PEND:
  4160. SSparms[1] = S_CONF_SPLIT;
  4161. break;
  4162. case CONF_DROP_REQ_PEND:
  4163. SSparms[1] = S_CONF_DROP;
  4164. break;
  4165. case CONF_ISOLATE_REQ_PEND:
  4166. SSparms[1] = S_CONF_ISOLATE;
  4167. break;
  4168. case CONF_REATTACH_REQ_PEND:
  4169. SSparms[1] = S_CONF_REATTACH;
  4170. break;
  4171. }
  4172. if(rc!=OK)
  4173. {
  4174. Info = 0x300E; /* not supported */
  4175. plci->relatedPTYPLCI = NULL;
  4176. plci->ptyState = 0;
  4177. }
  4178. sendf(rplci->appl,
  4179. _FACILITY_R|CONFIRM,
  4180. rId,
  4181. plci->number,
  4182. "wws",Info,(word)3,SSparms);
  4183. break;
  4184. case VSWITCH_REQ_PEND:
  4185. if(rc!=OK)
  4186. {
  4187. if(plci->relatedPTYPLCI)
  4188. {
  4189. plci->relatedPTYPLCI->vswitchstate=0;
  4190. plci->relatedPTYPLCI->vsprot=0;
  4191. plci->relatedPTYPLCI->vsprotdialect=0;
  4192. }
  4193. plci->vswitchstate=0;
  4194. plci->vsprot=0;
  4195. plci->vsprotdialect=0;
  4196. }
  4197. else
  4198. {
  4199. if(plci->relatedPTYPLCI &&
  4200. plci->vswitchstate==1 &&
  4201. plci->relatedPTYPLCI->vswitchstate==3) /* join complete */
  4202. plci->vswitchstate=3;
  4203. }
  4204. break;
  4205. /* Call Deflection Request pending (SSCT) */
  4206. case CD_REQ_PEND:
  4207. SSparms[1] = S_CALL_DEFLECTION;
  4208. if(rc!=OK)
  4209. {
  4210. Info = 0x300E; /* not supported */
  4211. plci->appl->CDEnable = 0;
  4212. }
  4213. sendf(plci->appl,_FACILITY_R|CONFIRM,Id,
  4214. plci->number,"wws",Info,(word)3,SSparms);
  4215. break;
  4216. case RTP_CONNECT_B3_REQ_COMMAND_2:
  4217. if (rc == OK)
  4218. {
  4219. ncci = get_ncci (plci, ch, 0);
  4220. Id = (Id & 0xffff) | (((dword) ncci) << 16);
  4221. plci->channels++;
  4222. a->ncci_state[ncci] = OUTG_CON_PENDING;
  4223. }
  4224. default:
  4225. if (plci->internal_command_queue[0])
  4226. {
  4227. (*(plci->internal_command_queue[0]))(Id, plci, rc);
  4228. if (plci->internal_command)
  4229. return;
  4230. }
  4231. break;
  4232. }
  4233. next_internal_command (Id, plci);
  4234. }
  4235. }
  4236. else /* appl==0 */
  4237. {
  4238. Id = ((word)plci->Id<<8)|plci->adapter->Id;
  4239. if(plci->tel) Id|=EXT_CONTROLLER;
  4240. switch(plci->internal_command)
  4241. {
  4242. case BLOCK_PLCI:
  4243. return;
  4244. case START_L1_SIG_ASSIGN_PEND:
  4245. case REM_L1_SIG_ASSIGN_PEND:
  4246. if(global_req == ASSIGN)
  4247. {
  4248. break;
  4249. }
  4250. else
  4251. {
  4252. dbug(1,dprintf("***L1 Req rem PLCI"));
  4253. plci->internal_command = 0;
  4254. sig_req(plci,REMOVE,0);
  4255. send_req(plci);
  4256. }
  4257. break;
  4258. /* Call Deflection Request pending, just no appl ptr assigned */
  4259. case CD_REQ_PEND:
  4260. SSparms[1] = S_CALL_DEFLECTION;
  4261. if(rc!=OK)
  4262. {
  4263. Info = 0x300E; /* not supported */
  4264. }
  4265. for(i=0; i<max_appl; i++)
  4266. {
  4267. if(application[i].CDEnable)
  4268. {
  4269. if(!application[i].Id) application[i].CDEnable = 0;
  4270. else
  4271. {
  4272. sendf(&application[i],_FACILITY_R|CONFIRM,Id,
  4273. plci->number,"wws",Info,(word)3,SSparms);
  4274. if(Info) application[i].CDEnable = 0;
  4275. }
  4276. }
  4277. }
  4278. plci->internal_command = 0;
  4279. break;
  4280. case PERM_COD_HOOK: /* finished with Hook_Ind */
  4281. return;
  4282. case PERM_COD_CALL:
  4283. plci->internal_command = PERM_COD_CONN_PEND;
  4284. dbug(1,dprintf("***Codec Connect_Pending, Rc = 0x%x",rc));
  4285. return;
  4286. case PERM_COD_ASSIGN:
  4287. dbug(1,dprintf("***Codec Assign, Rc = 0x%x",rc));
  4288. plci->internal_command = 0;
  4289. if(rc!=ASSIGN_OK) break;
  4290. plci->internal_command = PERM_COD_CALL;
  4291. sig_req(plci,CALL_REQ,0);
  4292. send_req(plci);
  4293. return;
  4294. case LISTEN_SIG_ASSIGN_PEND:
  4295. if(rc == ASSIGN_OK)
  4296. {
  4297. plci->internal_command = 0;
  4298. dbug(1,dprintf("ListenCheck, new SIG_ID = 0x%x",plci->Sig.Id));
  4299. add_p(plci,ESC,"\x02\x18\x00"); /* support call waiting */
  4300. sig_req(plci,INDICATE_REQ,0);
  4301. send_req(plci);
  4302. }
  4303. else
  4304. {
  4305. dbug(1,dprintf("ListenCheck failed (assignRc=0x%x)",rc));
  4306. a->listen_active--;
  4307. plci_remove(plci);
  4308. plci->State = IDLE;
  4309. }
  4310. break;
  4311. case USELAW_REQ:
  4312. if(global_req == ASSIGN)
  4313. {
  4314. if (rc==ASSIGN_OK)
  4315. {
  4316. sig_req(plci,LAW_REQ,0);
  4317. send_req(plci);
  4318. dbug(1,dprintf("Auto-Law assigned"));
  4319. }
  4320. else
  4321. {
  4322. dbug(1,dprintf("Auto-Law assign failed"));
  4323. a->automatic_law = 3;
  4324. plci->internal_command = 0;
  4325. a->automatic_lawPLCI = NULL;
  4326. }
  4327. break;
  4328. }
  4329. else if(req == LAW_REQ && rc==OK)
  4330. {
  4331. dbug(1,dprintf("Auto-Law initiated"));
  4332. a->automatic_law = 2;
  4333. plci->internal_command = 0;
  4334. }
  4335. else
  4336. {
  4337. dbug(1,dprintf("Auto-Law not supported"));
  4338. a->automatic_law = 3;
  4339. plci->internal_command = 0;
  4340. sig_req(plci,REMOVE,0);
  4341. send_req(plci);
  4342. a->automatic_lawPLCI = NULL;
  4343. }
  4344. break;
  4345. }
  4346. plci_remove_check(plci);
  4347. }
  4348. }
  4349. static void data_rc(PLCI *plci, byte ch)
  4350. {
  4351. dword Id;
  4352. DIVA_CAPI_ADAPTER * a;
  4353. NCCI *ncci_ptr;
  4354. DATA_B3_DESC *data;
  4355. word ncci;
  4356. if (plci->appl)
  4357. {
  4358. TransmitBufferFree (plci->appl, plci->data_sent_ptr);
  4359. a = plci->adapter;
  4360. ncci = a->ch_ncci[ch];
  4361. if (ncci && (a->ncci_plci[ncci] == plci->Id))
  4362. {
  4363. ncci_ptr = &(a->ncci[ncci]);
  4364. dbug(1,dprintf("data_out=%d, data_pending=%d",ncci_ptr->data_out,ncci_ptr->data_pending));
  4365. if (ncci_ptr->data_pending)
  4366. {
  4367. data = &(ncci_ptr->DBuffer[ncci_ptr->data_out]);
  4368. if (!(data->Flags &4) && a->ncci_state[ncci])
  4369. {
  4370. Id = (((dword)ncci)<<16)|((word)plci->Id<<8)|a->Id;
  4371. if(plci->tel) Id|=EXT_CONTROLLER;
  4372. sendf(plci->appl,_DATA_B3_R|CONFIRM,Id,data->Number,
  4373. "ww",data->Handle,0);
  4374. }
  4375. (ncci_ptr->data_out)++;
  4376. if (ncci_ptr->data_out == MAX_DATA_B3)
  4377. ncci_ptr->data_out = 0;
  4378. (ncci_ptr->data_pending)--;
  4379. }
  4380. }
  4381. }
  4382. }
  4383. static void data_ack(PLCI *plci, byte ch)
  4384. {
  4385. dword Id;
  4386. DIVA_CAPI_ADAPTER * a;
  4387. NCCI *ncci_ptr;
  4388. word ncci;
  4389. a = plci->adapter;
  4390. ncci = a->ch_ncci[ch];
  4391. ncci_ptr = &(a->ncci[ncci]);
  4392. if (ncci_ptr->data_ack_pending)
  4393. {
  4394. if (a->ncci_state[ncci] && (a->ncci_plci[ncci] == plci->Id))
  4395. {
  4396. Id = (((dword)ncci)<<16)|((word)plci->Id<<8)|a->Id;
  4397. if(plci->tel) Id|=EXT_CONTROLLER;
  4398. sendf(plci->appl,_DATA_B3_R|CONFIRM,Id,ncci_ptr->DataAck[ncci_ptr->data_ack_out].Number,
  4399. "ww",ncci_ptr->DataAck[ncci_ptr->data_ack_out].Handle,0);
  4400. }
  4401. (ncci_ptr->data_ack_out)++;
  4402. if (ncci_ptr->data_ack_out == MAX_DATA_ACK)
  4403. ncci_ptr->data_ack_out = 0;
  4404. (ncci_ptr->data_ack_pending)--;
  4405. }
  4406. }
  4407. static void sig_ind(PLCI *plci)
  4408. {
  4409. dword x_Id;
  4410. dword Id;
  4411. dword rId;
  4412. word Number = 0;
  4413. word i;
  4414. word cip;
  4415. dword cip_mask;
  4416. byte *ie;
  4417. DIVA_CAPI_ADAPTER * a;
  4418. API_PARSE saved_parms[MAX_MSG_PARMS+1];
  4419. #define MAXPARMSIDS 31
  4420. byte * parms[MAXPARMSIDS];
  4421. byte * add_i[4];
  4422. byte * multi_fac_parms[MAX_MULTI_IE];
  4423. byte * multi_pi_parms [MAX_MULTI_IE];
  4424. byte * multi_ssext_parms [MAX_MULTI_IE];
  4425. byte * multi_CiPN_parms [MAX_MULTI_IE];
  4426. byte * multi_vswitch_parms [MAX_MULTI_IE];
  4427. byte ai_len;
  4428. byte *esc_chi = "";
  4429. byte *esc_law = "";
  4430. byte *pty_cai = "";
  4431. byte *esc_cr = "";
  4432. byte *esc_profile = "";
  4433. byte facility[256];
  4434. PLCI * tplci = NULL;
  4435. byte chi[] = "\x02\x18\x01";
  4436. byte voice_cai[] = "\x06\x14\x00\x00\x00\x00\x08";
  4437. byte resume_cau[] = "\x05\x05\x00\x02\x00\x00";
  4438. /* ESC_MSGTYPE must be the last but one message, a new IE has to be */
  4439. /* included before the ESC_MSGTYPE and MAXPARMSIDS has to be incremented */
  4440. /* SMSG is situated at the end because its 0 (for compatibility reasons */
  4441. /* (see Info_Mask Bit 4, first IE. then the message type) */
  4442. word parms_id[] =
  4443. {MAXPARMSIDS, CPN, 0xff, DSA, OSA, BC, LLC, HLC, ESC_CAUSE, DSP, DT, CHA,
  4444. UUI, CONG_RR, CONG_RNR, ESC_CHI, KEY, CHI, CAU, ESC_LAW,
  4445. RDN, RDX, CONN_NR, RIN, NI, CAI, ESC_CR,
  4446. CST, ESC_PROFILE, 0xff, ESC_MSGTYPE, SMSG};
  4447. /* 14 FTY repl by ESC_CHI */
  4448. /* 18 PI repl by ESC_LAW */
  4449. /* removed OAD changed to 0xff for future use, OAD is multiIE now */
  4450. word multi_fac_id[] = {1, FTY};
  4451. word multi_pi_id[] = {1, PI};
  4452. word multi_CiPN_id[] = {1, OAD};
  4453. word multi_ssext_id[] = {1, ESC_SSEXT};
  4454. word multi_vswitch_id[] = {1, ESC_VSWITCH};
  4455. byte * cau;
  4456. word ncci;
  4457. byte SS_Ind[] = "\x05\x02\x00\x02\x00\x00"; /* Hold_Ind struct*/
  4458. byte CF_Ind[] = "\x09\x02\x00\x06\x00\x00\x00\x00\x00\x00";
  4459. byte Interr_Err_Ind[] = "\x0a\x02\x00\x07\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00";
  4460. byte CONF_Ind[] = "\x09\x16\x00\x06\x00\x00\0x00\0x00\0x00\0x00";
  4461. byte force_mt_info = false;
  4462. byte dir;
  4463. dword d;
  4464. word w;
  4465. a = plci->adapter;
  4466. Id = ((word)plci->Id<<8)|a->Id;
  4467. PUT_WORD(&SS_Ind[4],0x0000);
  4468. if (plci->sig_remove_id)
  4469. {
  4470. plci->Sig.RNR = 2; /* discard */
  4471. dbug(1,dprintf("SIG discard while remove pending"));
  4472. return;
  4473. }
  4474. if(plci->tel && plci->SuppState!=CALL_HELD) Id|=EXT_CONTROLLER;
  4475. dbug(1,dprintf("SigInd-Id=%08lx,plci=%x,tel=%x,state=0x%x,channels=%d,Discflowcl=%d",
  4476. Id,plci->Id,plci->tel,plci->State,plci->channels,plci->hangup_flow_ctrl_timer));
  4477. if(plci->Sig.Ind==CALL_HOLD_ACK && plci->channels)
  4478. {
  4479. plci->Sig.RNR = 1;
  4480. return;
  4481. }
  4482. if(plci->Sig.Ind==HANGUP && plci->channels)
  4483. {
  4484. plci->Sig.RNR = 1;
  4485. plci->hangup_flow_ctrl_timer++;
  4486. /* recover the network layer after timeout */
  4487. if(plci->hangup_flow_ctrl_timer==100)
  4488. {
  4489. dbug(1,dprintf("Exceptional disc"));
  4490. plci->Sig.RNR = 0;
  4491. plci->hangup_flow_ctrl_timer = 0;
  4492. for (ncci = 1; ncci < MAX_NCCI+1; ncci++)
  4493. {
  4494. if (a->ncci_plci[ncci] == plci->Id)
  4495. {
  4496. cleanup_ncci_data (plci, ncci);
  4497. if(plci->channels)plci->channels--;
  4498. if (plci->appl)
  4499. sendf(plci->appl,_DISCONNECT_B3_I, (((dword) ncci) << 16) | Id,0,"ws",0,"");
  4500. }
  4501. }
  4502. if (plci->appl)
  4503. sendf(plci->appl, _DISCONNECT_I, Id, 0, "w", 0);
  4504. plci_remove(plci);
  4505. plci->State=IDLE;
  4506. }
  4507. return;
  4508. }
  4509. /* do first parse the info with no OAD in, because OAD will be converted */
  4510. /* first the multiple facility IE, then mult. progress ind. */
  4511. /* then the parameters for the info_ind + conn_ind */
  4512. IndParse(plci,multi_fac_id,multi_fac_parms,MAX_MULTI_IE);
  4513. IndParse(plci,multi_pi_id,multi_pi_parms,MAX_MULTI_IE);
  4514. IndParse(plci,multi_ssext_id,multi_ssext_parms,MAX_MULTI_IE);
  4515. IndParse(plci,multi_vswitch_id,multi_vswitch_parms,MAX_MULTI_IE);
  4516. IndParse(plci,parms_id,parms,0);
  4517. IndParse(plci,multi_CiPN_id,multi_CiPN_parms,MAX_MULTI_IE);
  4518. esc_chi = parms[14];
  4519. esc_law = parms[18];
  4520. pty_cai = parms[24];
  4521. esc_cr = parms[25];
  4522. esc_profile = parms[27];
  4523. if(esc_cr[0] && plci)
  4524. {
  4525. if(plci->cr_enquiry && plci->appl)
  4526. {
  4527. plci->cr_enquiry = false;
  4528. /* d = MANU_ID */
  4529. /* w = m_command */
  4530. /* b = total length */
  4531. /* b = indication type */
  4532. /* b = length of all IEs */
  4533. /* b = IE1 */
  4534. /* S = IE1 length + cont. */
  4535. /* b = IE2 */
  4536. /* S = IE2 length + cont. */
  4537. sendf(plci->appl,
  4538. _MANUFACTURER_I,
  4539. Id,
  4540. 0,
  4541. "dwbbbbSbS",_DI_MANU_ID,plci->m_command,
  4542. 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);
  4543. }
  4544. }
  4545. /* create the additional info structure */
  4546. add_i[1] = parms[15]; /* KEY of additional info */
  4547. add_i[2] = parms[11]; /* UUI of additional info */
  4548. ai_len = AddInfo(add_i,multi_fac_parms, esc_chi, facility);
  4549. /* the ESC_LAW indicates if u-Law or a-Law is actually used by the card */
  4550. /* indication returns by the card if requested by the function */
  4551. /* AutomaticLaw() after driver init */
  4552. if (a->automatic_law<4)
  4553. {
  4554. if(esc_law[0]){
  4555. if(esc_law[2]){
  4556. dbug(0,dprintf("u-Law selected"));
  4557. a->u_law = 1;
  4558. }
  4559. else {
  4560. dbug(0,dprintf("a-Law selected"));
  4561. a->u_law = 0;
  4562. }
  4563. a->automatic_law = 4;
  4564. if(plci==a->automatic_lawPLCI) {
  4565. plci->internal_command = 0;
  4566. sig_req(plci,REMOVE,0);
  4567. send_req(plci);
  4568. a->automatic_lawPLCI = NULL;
  4569. }
  4570. }
  4571. if (esc_profile[0])
  4572. {
  4573. dbug (1, dprintf ("[%06x] CardProfile: %lx %lx %lx %lx %lx",
  4574. UnMapController (a->Id), GET_DWORD (&esc_profile[6]),
  4575. GET_DWORD (&esc_profile[10]), GET_DWORD (&esc_profile[14]),
  4576. GET_DWORD (&esc_profile[18]), GET_DWORD (&esc_profile[46])));
  4577. a->profile.Global_Options &= 0x000000ffL;
  4578. a->profile.B1_Protocols &= 0x000003ffL;
  4579. a->profile.B2_Protocols &= 0x00001fdfL;
  4580. a->profile.B3_Protocols &= 0x000000b7L;
  4581. a->profile.Global_Options &= GET_DWORD (&esc_profile[6]) |
  4582. GL_BCHANNEL_OPERATION_SUPPORTED;
  4583. a->profile.B1_Protocols &= GET_DWORD (&esc_profile[10]);
  4584. a->profile.B2_Protocols &= GET_DWORD (&esc_profile[14]);
  4585. a->profile.B3_Protocols &= GET_DWORD (&esc_profile[18]);
  4586. a->manufacturer_features = GET_DWORD (&esc_profile[46]);
  4587. a->man_profile.private_options = 0;
  4588. if (a->manufacturer_features & MANUFACTURER_FEATURE_ECHO_CANCELLER)
  4589. {
  4590. a->man_profile.private_options |= 1L << PRIVATE_ECHO_CANCELLER;
  4591. a->profile.Global_Options |= GL_ECHO_CANCELLER_SUPPORTED;
  4592. }
  4593. if (a->manufacturer_features & MANUFACTURER_FEATURE_RTP)
  4594. a->man_profile.private_options |= 1L << PRIVATE_RTP;
  4595. a->man_profile.rtp_primary_payloads = GET_DWORD (&esc_profile[50]);
  4596. a->man_profile.rtp_additional_payloads = GET_DWORD (&esc_profile[54]);
  4597. if (a->manufacturer_features & MANUFACTURER_FEATURE_T38)
  4598. a->man_profile.private_options |= 1L << PRIVATE_T38;
  4599. if (a->manufacturer_features & MANUFACTURER_FEATURE_FAX_SUB_SEP_PWD)
  4600. a->man_profile.private_options |= 1L << PRIVATE_FAX_SUB_SEP_PWD;
  4601. if (a->manufacturer_features & MANUFACTURER_FEATURE_V18)
  4602. a->man_profile.private_options |= 1L << PRIVATE_V18;
  4603. if (a->manufacturer_features & MANUFACTURER_FEATURE_DTMF_TONE)
  4604. a->man_profile.private_options |= 1L << PRIVATE_DTMF_TONE;
  4605. if (a->manufacturer_features & MANUFACTURER_FEATURE_PIAFS)
  4606. a->man_profile.private_options |= 1L << PRIVATE_PIAFS;
  4607. if (a->manufacturer_features & MANUFACTURER_FEATURE_FAX_PAPER_FORMATS)
  4608. a->man_profile.private_options |= 1L << PRIVATE_FAX_PAPER_FORMATS;
  4609. if (a->manufacturer_features & MANUFACTURER_FEATURE_VOWN)
  4610. a->man_profile.private_options |= 1L << PRIVATE_VOWN;
  4611. if (a->manufacturer_features & MANUFACTURER_FEATURE_FAX_NONSTANDARD)
  4612. a->man_profile.private_options |= 1L << PRIVATE_FAX_NONSTANDARD;
  4613. }
  4614. else
  4615. {
  4616. a->profile.Global_Options &= 0x0000007fL;
  4617. a->profile.B1_Protocols &= 0x000003dfL;
  4618. a->profile.B2_Protocols &= 0x00001adfL;
  4619. a->profile.B3_Protocols &= 0x000000b7L;
  4620. a->manufacturer_features &= MANUFACTURER_FEATURE_HARDDTMF;
  4621. }
  4622. if (a->manufacturer_features & (MANUFACTURER_FEATURE_HARDDTMF |
  4623. MANUFACTURER_FEATURE_SOFTDTMF_SEND | MANUFACTURER_FEATURE_SOFTDTMF_RECEIVE))
  4624. {
  4625. a->profile.Global_Options |= GL_DTMF_SUPPORTED;
  4626. }
  4627. a->manufacturer_features &= ~MANUFACTURER_FEATURE_OOB_CHANNEL;
  4628. dbug (1, dprintf ("[%06x] Profile: %lx %lx %lx %lx %lx",
  4629. UnMapController (a->Id), a->profile.Global_Options,
  4630. a->profile.B1_Protocols, a->profile.B2_Protocols,
  4631. a->profile.B3_Protocols, a->manufacturer_features));
  4632. }
  4633. /* codec plci for the handset/hook state support is just an internal id */
  4634. if(plci!=a->AdvCodecPLCI)
  4635. {
  4636. force_mt_info = SendMultiIE(plci,Id,multi_fac_parms, FTY, 0x20, 0);
  4637. force_mt_info |= SendMultiIE(plci,Id,multi_pi_parms, PI, 0x210, 0);
  4638. SendSSExtInd(NULL,plci,Id,multi_ssext_parms);
  4639. SendInfo(plci,Id, parms, force_mt_info);
  4640. VSwitchReqInd(plci,Id,multi_vswitch_parms);
  4641. }
  4642. /* switch the codec to the b-channel */
  4643. if(esc_chi[0] && plci && !plci->SuppState){
  4644. plci->b_channel = esc_chi[esc_chi[0]]&0x1f;
  4645. mixer_set_bchannel_id_esc (plci, plci->b_channel);
  4646. dbug(1,dprintf("storeChannel=0x%x",plci->b_channel));
  4647. if(plci->tel==ADV_VOICE && plci->appl) {
  4648. SetVoiceChannel(a->AdvCodecPLCI, esc_chi, a);
  4649. }
  4650. }
  4651. if(plci->appl) Number = plci->appl->Number++;
  4652. switch(plci->Sig.Ind) {
  4653. /* Response to Get_Supported_Services request */
  4654. case S_SUPPORTED:
  4655. dbug(1,dprintf("S_Supported"));
  4656. if(!plci->appl) break;
  4657. if(pty_cai[0]==4)
  4658. {
  4659. PUT_DWORD(&CF_Ind[6],GET_DWORD(&pty_cai[1]) );
  4660. }
  4661. else
  4662. {
  4663. PUT_DWORD(&CF_Ind[6],MASK_TERMINAL_PORTABILITY | MASK_HOLD_RETRIEVE);
  4664. }
  4665. PUT_WORD (&CF_Ind[1], 0);
  4666. PUT_WORD (&CF_Ind[4], 0);
  4667. sendf(plci->appl,_FACILITY_R|CONFIRM,Id&0x7,plci->number, "wws",0,3,CF_Ind);
  4668. plci_remove(plci);
  4669. break;
  4670. /* Supplementary Service rejected */
  4671. case S_SERVICE_REJ:
  4672. dbug(1,dprintf("S_Reject=0x%x",pty_cai[5]));
  4673. if(!pty_cai[0]) break;
  4674. switch (pty_cai[5])
  4675. {
  4676. case ECT_EXECUTE:
  4677. case THREE_PTY_END:
  4678. case THREE_PTY_BEGIN:
  4679. if(!plci->relatedPTYPLCI) break;
  4680. tplci = plci->relatedPTYPLCI;
  4681. rId = ( (word)tplci->Id<<8)|tplci->adapter->Id;
  4682. if(tplci->tel) rId|=EXT_CONTROLLER;
  4683. if(pty_cai[5]==ECT_EXECUTE)
  4684. {
  4685. PUT_WORD(&SS_Ind[1],S_ECT);
  4686. plci->vswitchstate=0;
  4687. plci->relatedPTYPLCI->vswitchstate=0;
  4688. }
  4689. else
  4690. {
  4691. PUT_WORD(&SS_Ind[1],pty_cai[5]+3);
  4692. }
  4693. if(pty_cai[2]!=0xff)
  4694. {
  4695. PUT_WORD(&SS_Ind[4],0x3600|(word)pty_cai[2]);
  4696. }
  4697. else
  4698. {
  4699. PUT_WORD(&SS_Ind[4],0x300E);
  4700. }
  4701. plci->relatedPTYPLCI = NULL;
  4702. plci->ptyState = 0;
  4703. sendf(tplci->appl,_FACILITY_I,rId,0,"ws",3, SS_Ind);
  4704. break;
  4705. case CALL_DEFLECTION:
  4706. if(pty_cai[2]!=0xff)
  4707. {
  4708. PUT_WORD(&SS_Ind[4],0x3600|(word)pty_cai[2]);
  4709. }
  4710. else
  4711. {
  4712. PUT_WORD(&SS_Ind[4],0x300E);
  4713. }
  4714. PUT_WORD(&SS_Ind[1],pty_cai[5]);
  4715. for(i=0; i<max_appl; i++)
  4716. {
  4717. if(application[i].CDEnable)
  4718. {
  4719. if(application[i].Id) sendf(&application[i],_FACILITY_I,Id,0,"ws",3, SS_Ind);
  4720. application[i].CDEnable = false;
  4721. }
  4722. }
  4723. break;
  4724. case DEACTIVATION_DIVERSION:
  4725. case ACTIVATION_DIVERSION:
  4726. case DIVERSION_INTERROGATE_CFU:
  4727. case DIVERSION_INTERROGATE_CFB:
  4728. case DIVERSION_INTERROGATE_CFNR:
  4729. case DIVERSION_INTERROGATE_NUM:
  4730. case CCBS_REQUEST:
  4731. case CCBS_DEACTIVATE:
  4732. case CCBS_INTERROGATE:
  4733. if(!plci->appl) break;
  4734. if(pty_cai[2]!=0xff)
  4735. {
  4736. PUT_WORD(&Interr_Err_Ind[4],0x3600|(word)pty_cai[2]);
  4737. }
  4738. else
  4739. {
  4740. PUT_WORD(&Interr_Err_Ind[4],0x300E);
  4741. }
  4742. switch (pty_cai[5])
  4743. {
  4744. case DEACTIVATION_DIVERSION:
  4745. dbug(1,dprintf("Deact_Div"));
  4746. Interr_Err_Ind[0]=0x9;
  4747. Interr_Err_Ind[3]=0x6;
  4748. PUT_WORD(&Interr_Err_Ind[1],S_CALL_FORWARDING_STOP);
  4749. break;
  4750. case ACTIVATION_DIVERSION:
  4751. dbug(1,dprintf("Act_Div"));
  4752. Interr_Err_Ind[0]=0x9;
  4753. Interr_Err_Ind[3]=0x6;
  4754. PUT_WORD(&Interr_Err_Ind[1],S_CALL_FORWARDING_START);
  4755. break;
  4756. case DIVERSION_INTERROGATE_CFU:
  4757. case DIVERSION_INTERROGATE_CFB:
  4758. case DIVERSION_INTERROGATE_CFNR:
  4759. dbug(1,dprintf("Interr_Div"));
  4760. Interr_Err_Ind[0]=0xa;
  4761. Interr_Err_Ind[3]=0x7;
  4762. PUT_WORD(&Interr_Err_Ind[1],S_INTERROGATE_DIVERSION);
  4763. break;
  4764. case DIVERSION_INTERROGATE_NUM:
  4765. dbug(1,dprintf("Interr_Num"));
  4766. Interr_Err_Ind[0]=0xa;
  4767. Interr_Err_Ind[3]=0x7;
  4768. PUT_WORD(&Interr_Err_Ind[1],S_INTERROGATE_NUMBERS);
  4769. break;
  4770. case CCBS_REQUEST:
  4771. dbug(1,dprintf("CCBS Request"));
  4772. Interr_Err_Ind[0]=0xd;
  4773. Interr_Err_Ind[3]=0xa;
  4774. PUT_WORD(&Interr_Err_Ind[1],S_CCBS_REQUEST);
  4775. break;
  4776. case CCBS_DEACTIVATE:
  4777. dbug(1,dprintf("CCBS Deactivate"));
  4778. Interr_Err_Ind[0]=0x9;
  4779. Interr_Err_Ind[3]=0x6;
  4780. PUT_WORD(&Interr_Err_Ind[1],S_CCBS_DEACTIVATE);
  4781. break;
  4782. case CCBS_INTERROGATE:
  4783. dbug(1,dprintf("CCBS Interrogate"));
  4784. Interr_Err_Ind[0]=0xb;
  4785. Interr_Err_Ind[3]=0x8;
  4786. PUT_WORD(&Interr_Err_Ind[1],S_CCBS_INTERROGATE);
  4787. break;
  4788. }
  4789. PUT_DWORD(&Interr_Err_Ind[6],plci->appl->S_Handle);
  4790. sendf(plci->appl,_FACILITY_I,Id&0x7,0,"ws",3, Interr_Err_Ind);
  4791. plci_remove(plci);
  4792. break;
  4793. case ACTIVATION_MWI:
  4794. case DEACTIVATION_MWI:
  4795. if(pty_cai[5]==ACTIVATION_MWI)
  4796. {
  4797. PUT_WORD(&SS_Ind[1],S_MWI_ACTIVATE);
  4798. }
  4799. else PUT_WORD(&SS_Ind[1],S_MWI_DEACTIVATE);
  4800. if(pty_cai[2]!=0xff)
  4801. {
  4802. PUT_WORD(&SS_Ind[4],0x3600|(word)pty_cai[2]);
  4803. }
  4804. else
  4805. {
  4806. PUT_WORD(&SS_Ind[4],0x300E);
  4807. }
  4808. if(plci->cr_enquiry)
  4809. {
  4810. sendf(plci->appl,_FACILITY_I,Id&0xf,0,"ws",3, SS_Ind);
  4811. plci_remove(plci);
  4812. }
  4813. else
  4814. {
  4815. sendf(plci->appl,_FACILITY_I,Id,0,"ws",3, SS_Ind);
  4816. }
  4817. break;
  4818. case CONF_ADD: /* ERROR */
  4819. case CONF_BEGIN:
  4820. case CONF_DROP:
  4821. case CONF_ISOLATE:
  4822. case CONF_REATTACH:
  4823. CONF_Ind[0]=9;
  4824. CONF_Ind[3]=6;
  4825. switch(pty_cai[5])
  4826. {
  4827. case CONF_BEGIN:
  4828. PUT_WORD(&CONF_Ind[1],S_CONF_BEGIN);
  4829. plci->ptyState = 0;
  4830. break;
  4831. case CONF_DROP:
  4832. CONF_Ind[0]=5;
  4833. CONF_Ind[3]=2;
  4834. PUT_WORD(&CONF_Ind[1],S_CONF_DROP);
  4835. plci->ptyState = CONNECTED;
  4836. break;
  4837. case CONF_ISOLATE:
  4838. CONF_Ind[0]=5;
  4839. CONF_Ind[3]=2;
  4840. PUT_WORD(&CONF_Ind[1],S_CONF_ISOLATE);
  4841. plci->ptyState = CONNECTED;
  4842. break;
  4843. case CONF_REATTACH:
  4844. CONF_Ind[0]=5;
  4845. CONF_Ind[3]=2;
  4846. PUT_WORD(&CONF_Ind[1],S_CONF_REATTACH);
  4847. plci->ptyState = CONNECTED;
  4848. break;
  4849. case CONF_ADD:
  4850. PUT_WORD(&CONF_Ind[1],S_CONF_ADD);
  4851. plci->relatedPTYPLCI = NULL;
  4852. tplci=plci->relatedPTYPLCI;
  4853. if(tplci) tplci->ptyState = CONNECTED;
  4854. plci->ptyState = CONNECTED;
  4855. break;
  4856. }
  4857. if(pty_cai[2]!=0xff)
  4858. {
  4859. PUT_WORD(&CONF_Ind[4],0x3600|(word)pty_cai[2]);
  4860. }
  4861. else
  4862. {
  4863. PUT_WORD(&CONF_Ind[4],0x3303); /* Time-out: network did not respond
  4864. within the required time */
  4865. }
  4866. PUT_DWORD(&CONF_Ind[6],0x0);
  4867. sendf(plci->appl,_FACILITY_I,Id,0,"ws",3, CONF_Ind);
  4868. break;
  4869. }
  4870. break;
  4871. /* Supplementary Service indicates success */
  4872. case S_SERVICE:
  4873. dbug(1,dprintf("Service_Ind"));
  4874. PUT_WORD (&CF_Ind[4], 0);
  4875. switch (pty_cai[5])
  4876. {
  4877. case THREE_PTY_END:
  4878. case THREE_PTY_BEGIN:
  4879. case ECT_EXECUTE:
  4880. if(!plci->relatedPTYPLCI) break;
  4881. tplci = plci->relatedPTYPLCI;
  4882. rId = ( (word)tplci->Id<<8)|tplci->adapter->Id;
  4883. if(tplci->tel) rId|=EXT_CONTROLLER;
  4884. if(pty_cai[5]==ECT_EXECUTE)
  4885. {
  4886. PUT_WORD(&SS_Ind[1],S_ECT);
  4887. if(plci->vswitchstate!=3)
  4888. {
  4889. plci->ptyState = IDLE;
  4890. plci->relatedPTYPLCI = NULL;
  4891. plci->ptyState = 0;
  4892. }
  4893. dbug(1,dprintf("ECT OK"));
  4894. sendf(tplci->appl,_FACILITY_I,rId,0,"ws",3, SS_Ind);
  4895. }
  4896. else
  4897. {
  4898. switch (plci->ptyState)
  4899. {
  4900. case S_3PTY_BEGIN:
  4901. plci->ptyState = CONNECTED;
  4902. dbug(1,dprintf("3PTY ON"));
  4903. break;
  4904. case S_3PTY_END:
  4905. plci->ptyState = IDLE;
  4906. plci->relatedPTYPLCI = NULL;
  4907. plci->ptyState = 0;
  4908. dbug(1,dprintf("3PTY OFF"));
  4909. break;
  4910. }
  4911. PUT_WORD(&SS_Ind[1],pty_cai[5]+3);
  4912. sendf(tplci->appl,_FACILITY_I,rId,0,"ws",3, SS_Ind);
  4913. }
  4914. break;
  4915. case CALL_DEFLECTION:
  4916. PUT_WORD(&SS_Ind[1],pty_cai[5]);
  4917. for(i=0; i<max_appl; i++)
  4918. {
  4919. if(application[i].CDEnable)
  4920. {
  4921. if(application[i].Id) sendf(&application[i],_FACILITY_I,Id,0,"ws",3, SS_Ind);
  4922. application[i].CDEnable = false;
  4923. }
  4924. }
  4925. break;
  4926. case DEACTIVATION_DIVERSION:
  4927. case ACTIVATION_DIVERSION:
  4928. if(!plci->appl) break;
  4929. PUT_WORD(&CF_Ind[1],pty_cai[5]+2);
  4930. PUT_DWORD(&CF_Ind[6],plci->appl->S_Handle);
  4931. sendf(plci->appl,_FACILITY_I,Id&0x7,0,"ws",3, CF_Ind);
  4932. plci_remove(plci);
  4933. break;
  4934. case DIVERSION_INTERROGATE_CFU:
  4935. case DIVERSION_INTERROGATE_CFB:
  4936. case DIVERSION_INTERROGATE_CFNR:
  4937. case DIVERSION_INTERROGATE_NUM:
  4938. case CCBS_REQUEST:
  4939. case CCBS_DEACTIVATE:
  4940. case CCBS_INTERROGATE:
  4941. if(!plci->appl) break;
  4942. switch (pty_cai[5])
  4943. {
  4944. case DIVERSION_INTERROGATE_CFU:
  4945. case DIVERSION_INTERROGATE_CFB:
  4946. case DIVERSION_INTERROGATE_CFNR:
  4947. dbug(1,dprintf("Interr_Div"));
  4948. PUT_WORD(&pty_cai[1],S_INTERROGATE_DIVERSION);
  4949. pty_cai[3]=pty_cai[0]-3; /* Supplementary Service-specific parameter len */
  4950. break;
  4951. case DIVERSION_INTERROGATE_NUM:
  4952. dbug(1,dprintf("Interr_Num"));
  4953. PUT_WORD(&pty_cai[1],S_INTERROGATE_NUMBERS);
  4954. pty_cai[3]=pty_cai[0]-3; /* Supplementary Service-specific parameter len */
  4955. break;
  4956. case CCBS_REQUEST:
  4957. dbug(1,dprintf("CCBS Request"));
  4958. PUT_WORD(&pty_cai[1],S_CCBS_REQUEST);
  4959. pty_cai[3]=pty_cai[0]-3; /* Supplementary Service-specific parameter len */
  4960. break;
  4961. case CCBS_DEACTIVATE:
  4962. dbug(1,dprintf("CCBS Deactivate"));
  4963. PUT_WORD(&pty_cai[1],S_CCBS_DEACTIVATE);
  4964. pty_cai[3]=pty_cai[0]-3; /* Supplementary Service-specific parameter len */
  4965. break;
  4966. case CCBS_INTERROGATE:
  4967. dbug(1,dprintf("CCBS Interrogate"));
  4968. PUT_WORD(&pty_cai[1],S_CCBS_INTERROGATE);
  4969. pty_cai[3]=pty_cai[0]-3; /* Supplementary Service-specific parameter len */
  4970. break;
  4971. }
  4972. PUT_WORD(&pty_cai[4],0); /* Supplementary Service Reason */
  4973. PUT_DWORD(&pty_cai[6],plci->appl->S_Handle);
  4974. sendf(plci->appl,_FACILITY_I,Id&0x7,0,"wS",3, pty_cai);
  4975. plci_remove(plci);
  4976. break;
  4977. case ACTIVATION_MWI:
  4978. case DEACTIVATION_MWI:
  4979. if(pty_cai[5]==ACTIVATION_MWI)
  4980. {
  4981. PUT_WORD(&SS_Ind[1],S_MWI_ACTIVATE);
  4982. }
  4983. else PUT_WORD(&SS_Ind[1],S_MWI_DEACTIVATE);
  4984. if(plci->cr_enquiry)
  4985. {
  4986. sendf(plci->appl,_FACILITY_I,Id&0xf,0,"ws",3, SS_Ind);
  4987. plci_remove(plci);
  4988. }
  4989. else
  4990. {
  4991. sendf(plci->appl,_FACILITY_I,Id,0,"ws",3, SS_Ind);
  4992. }
  4993. break;
  4994. case MWI_INDICATION:
  4995. if(pty_cai[0]>=0x12)
  4996. {
  4997. PUT_WORD(&pty_cai[3],S_MWI_INDICATE);
  4998. pty_cai[2]=pty_cai[0]-2; /* len Parameter */
  4999. pty_cai[5]=pty_cai[0]-5; /* Supplementary Service-specific parameter len */
  5000. if(plci->appl && (a->Notification_Mask[plci->appl->Id-1]&SMASK_MWI))
  5001. {
  5002. if(plci->internal_command==GET_MWI_STATE) /* result on Message Waiting Listen */
  5003. {
  5004. sendf(plci->appl,_FACILITY_I,Id&0xf,0,"wS",3, &pty_cai[2]);
  5005. plci_remove(plci);
  5006. return;
  5007. }
  5008. else sendf(plci->appl,_FACILITY_I,Id,0,"wS",3, &pty_cai[2]);
  5009. pty_cai[0]=0;
  5010. }
  5011. else
  5012. {
  5013. for(i=0; i<max_appl; i++)
  5014. {
  5015. if(a->Notification_Mask[i]&SMASK_MWI)
  5016. {
  5017. sendf(&application[i],_FACILITY_I,Id&0x7,0,"wS",3, &pty_cai[2]);
  5018. pty_cai[0]=0;
  5019. }
  5020. }
  5021. }
  5022. if(!pty_cai[0])
  5023. { /* acknowledge */
  5024. facility[2]= 0; /* returncode */
  5025. }
  5026. else facility[2]= 0xff;
  5027. }
  5028. else
  5029. {
  5030. /* reject */
  5031. facility[2]= 0xff; /* returncode */
  5032. }
  5033. facility[0]= 2;
  5034. facility[1]= MWI_RESPONSE; /* Function */
  5035. add_p(plci,CAI,facility);
  5036. add_p(plci,ESC,multi_ssext_parms[0]); /* remembered parameter -> only one possible */
  5037. sig_req(plci,S_SERVICE,0);
  5038. send_req(plci);
  5039. plci->command = 0;
  5040. next_internal_command (Id, plci);
  5041. break;
  5042. case CONF_ADD: /* OK */
  5043. case CONF_BEGIN:
  5044. case CONF_DROP:
  5045. case CONF_ISOLATE:
  5046. case CONF_REATTACH:
  5047. case CONF_PARTYDISC:
  5048. CONF_Ind[0]=9;
  5049. CONF_Ind[3]=6;
  5050. switch(pty_cai[5])
  5051. {
  5052. case CONF_BEGIN:
  5053. PUT_WORD(&CONF_Ind[1],S_CONF_BEGIN);
  5054. if(pty_cai[0]==6)
  5055. {
  5056. d=pty_cai[6];
  5057. PUT_DWORD(&CONF_Ind[6],d); /* PartyID */
  5058. }
  5059. else
  5060. {
  5061. PUT_DWORD(&CONF_Ind[6],0x0);
  5062. }
  5063. break;
  5064. case CONF_ISOLATE:
  5065. PUT_WORD(&CONF_Ind[1],S_CONF_ISOLATE);
  5066. CONF_Ind[0]=5;
  5067. CONF_Ind[3]=2;
  5068. break;
  5069. case CONF_REATTACH:
  5070. PUT_WORD(&CONF_Ind[1],S_CONF_REATTACH);
  5071. CONF_Ind[0]=5;
  5072. CONF_Ind[3]=2;
  5073. break;
  5074. case CONF_DROP:
  5075. PUT_WORD(&CONF_Ind[1],S_CONF_DROP);
  5076. CONF_Ind[0]=5;
  5077. CONF_Ind[3]=2;
  5078. break;
  5079. case CONF_ADD:
  5080. PUT_WORD(&CONF_Ind[1],S_CONF_ADD);
  5081. d=pty_cai[6];
  5082. PUT_DWORD(&CONF_Ind[6],d); /* PartyID */
  5083. tplci=plci->relatedPTYPLCI;
  5084. if(tplci) tplci->ptyState = CONNECTED;
  5085. break;
  5086. case CONF_PARTYDISC:
  5087. CONF_Ind[0]=7;
  5088. CONF_Ind[3]=4;
  5089. PUT_WORD(&CONF_Ind[1],S_CONF_PARTYDISC);
  5090. d=pty_cai[6];
  5091. PUT_DWORD(&CONF_Ind[4],d); /* PartyID */
  5092. break;
  5093. }
  5094. plci->ptyState = CONNECTED;
  5095. sendf(plci->appl,_FACILITY_I,Id,0,"ws",3, CONF_Ind);
  5096. break;
  5097. case CCBS_INFO_RETAIN:
  5098. case CCBS_ERASECALLLINKAGEID:
  5099. case CCBS_STOP_ALERTING:
  5100. CONF_Ind[0]=5;
  5101. CONF_Ind[3]=2;
  5102. switch(pty_cai[5])
  5103. {
  5104. case CCBS_INFO_RETAIN:
  5105. PUT_WORD(&CONF_Ind[1],S_CCBS_INFO_RETAIN);
  5106. break;
  5107. case CCBS_STOP_ALERTING:
  5108. PUT_WORD(&CONF_Ind[1],S_CCBS_STOP_ALERTING);
  5109. break;
  5110. case CCBS_ERASECALLLINKAGEID:
  5111. PUT_WORD(&CONF_Ind[1],S_CCBS_ERASECALLLINKAGEID);
  5112. CONF_Ind[0]=7;
  5113. CONF_Ind[3]=4;
  5114. CONF_Ind[6]=0;
  5115. CONF_Ind[7]=0;
  5116. break;
  5117. }
  5118. w=pty_cai[6];
  5119. PUT_WORD(&CONF_Ind[4],w); /* PartyID */
  5120. if(plci->appl && (a->Notification_Mask[plci->appl->Id-1]&SMASK_CCBS))
  5121. {
  5122. sendf(plci->appl,_FACILITY_I,Id,0,"ws",3, CONF_Ind);
  5123. }
  5124. else
  5125. {
  5126. for(i=0; i<max_appl; i++)
  5127. if(a->Notification_Mask[i]&SMASK_CCBS)
  5128. sendf(&application[i],_FACILITY_I,Id&0x7,0,"ws",3, CONF_Ind);
  5129. }
  5130. break;
  5131. }
  5132. break;
  5133. case CALL_HOLD_REJ:
  5134. cau = parms[7];
  5135. if(cau)
  5136. {
  5137. i = _L3_CAUSE | cau[2];
  5138. if(cau[2]==0) i = 0x3603;
  5139. }
  5140. else
  5141. {
  5142. i = 0x3603;
  5143. }
  5144. PUT_WORD(&SS_Ind[1],S_HOLD);
  5145. PUT_WORD(&SS_Ind[4],i);
  5146. if(plci->SuppState == HOLD_REQUEST)
  5147. {
  5148. plci->SuppState = IDLE;
  5149. sendf(plci->appl,_FACILITY_I,Id,0,"ws",3, SS_Ind);
  5150. }
  5151. break;
  5152. case CALL_HOLD_ACK:
  5153. if(plci->SuppState == HOLD_REQUEST)
  5154. {
  5155. plci->SuppState = CALL_HELD;
  5156. CodecIdCheck(a, plci);
  5157. start_internal_command (Id, plci, hold_save_command);
  5158. }
  5159. break;
  5160. case CALL_RETRIEVE_REJ:
  5161. cau = parms[7];
  5162. if(cau)
  5163. {
  5164. i = _L3_CAUSE | cau[2];
  5165. if(cau[2]==0) i = 0x3603;
  5166. }
  5167. else
  5168. {
  5169. i = 0x3603;
  5170. }
  5171. PUT_WORD(&SS_Ind[1],S_RETRIEVE);
  5172. PUT_WORD(&SS_Ind[4],i);
  5173. if(plci->SuppState == RETRIEVE_REQUEST)
  5174. {
  5175. plci->SuppState = CALL_HELD;
  5176. CodecIdCheck(a, plci);
  5177. sendf(plci->appl,_FACILITY_I,Id,0,"ws",3, SS_Ind);
  5178. }
  5179. break;
  5180. case CALL_RETRIEVE_ACK:
  5181. PUT_WORD(&SS_Ind[1],S_RETRIEVE);
  5182. if(plci->SuppState == RETRIEVE_REQUEST)
  5183. {
  5184. plci->SuppState = IDLE;
  5185. plci->call_dir |= CALL_DIR_FORCE_OUTG_NL;
  5186. plci->b_channel = esc_chi[esc_chi[0]]&0x1f;
  5187. if(plci->tel)
  5188. {
  5189. mixer_set_bchannel_id_esc (plci, plci->b_channel);
  5190. dbug(1,dprintf("RetrChannel=0x%x",plci->b_channel));
  5191. SetVoiceChannel(a->AdvCodecPLCI, esc_chi, a);
  5192. if(plci->B2_prot==B2_TRANSPARENT && plci->B3_prot==B3_TRANSPARENT)
  5193. {
  5194. dbug(1,dprintf("Get B-ch"));
  5195. start_internal_command (Id, plci, retrieve_restore_command);
  5196. }
  5197. else
  5198. sendf(plci->appl,_FACILITY_I,Id,0,"ws",3, SS_Ind);
  5199. }
  5200. else
  5201. start_internal_command (Id, plci, retrieve_restore_command);
  5202. }
  5203. break;
  5204. case INDICATE_IND:
  5205. if(plci->State != LISTENING) {
  5206. sig_req(plci,HANGUP,0);
  5207. send_req(plci);
  5208. break;
  5209. }
  5210. cip = find_cip(a,parms[4],parms[6]);
  5211. cip_mask = 1L<<cip;
  5212. dbug(1,dprintf("cip=%d,cip_mask=%lx",cip,cip_mask));
  5213. clear_c_ind_mask (plci);
  5214. if (!remove_started && !a->adapter_disabled)
  5215. {
  5216. set_c_ind_mask_bit (plci, MAX_APPL);
  5217. group_optimization(a, plci);
  5218. for(i=0; i<max_appl; i++) {
  5219. if(application[i].Id
  5220. && (a->CIP_Mask[i]&1 || a->CIP_Mask[i]&cip_mask)
  5221. && CPN_filter_ok(parms[0],a,i)
  5222. && test_group_ind_mask_bit (plci, i) ) {
  5223. dbug(1,dprintf("storedcip_mask[%d]=0x%lx",i,a->CIP_Mask[i] ));
  5224. set_c_ind_mask_bit (plci, i);
  5225. dump_c_ind_mask (plci);
  5226. plci->State = INC_CON_PENDING;
  5227. plci->call_dir = (plci->call_dir & ~(CALL_DIR_OUT | CALL_DIR_ORIGINATE)) |
  5228. CALL_DIR_IN | CALL_DIR_ANSWER;
  5229. if(esc_chi[0]) {
  5230. plci->b_channel = esc_chi[esc_chi[0]]&0x1f;
  5231. mixer_set_bchannel_id_esc (plci, plci->b_channel);
  5232. }
  5233. /* if a listen on the ext controller is done, check if hook states */
  5234. /* are supported or if just a on board codec must be activated */
  5235. if(a->codec_listen[i] && !a->AdvSignalPLCI) {
  5236. if(a->profile.Global_Options & HANDSET)
  5237. plci->tel = ADV_VOICE;
  5238. else if(a->profile.Global_Options & ON_BOARD_CODEC)
  5239. plci->tel = CODEC;
  5240. if(plci->tel) Id|=EXT_CONTROLLER;
  5241. a->codec_listen[i] = plci;
  5242. }
  5243. sendf(&application[i],_CONNECT_I,Id,0,
  5244. "wSSSSSSSbSSSSS", cip, /* CIP */
  5245. parms[0], /* CalledPartyNumber */
  5246. multi_CiPN_parms[0], /* CallingPartyNumber */
  5247. parms[2], /* CalledPartySubad */
  5248. parms[3], /* CallingPartySubad */
  5249. parms[4], /* BearerCapability */
  5250. parms[5], /* LowLC */
  5251. parms[6], /* HighLC */
  5252. ai_len, /* nested struct add_i */
  5253. add_i[0], /* B channel info */
  5254. add_i[1], /* keypad facility */
  5255. add_i[2], /* user user data */
  5256. add_i[3], /* nested facility */
  5257. multi_CiPN_parms[1] /* second CiPN(SCR) */
  5258. );
  5259. SendSSExtInd(&application[i],
  5260. plci,
  5261. Id,
  5262. multi_ssext_parms);
  5263. SendSetupInfo(&application[i],
  5264. plci,
  5265. Id,
  5266. parms,
  5267. SendMultiIE(plci,Id,multi_pi_parms, PI, 0x210, true));
  5268. }
  5269. }
  5270. clear_c_ind_mask_bit (plci, MAX_APPL);
  5271. dump_c_ind_mask (plci);
  5272. }
  5273. if(c_ind_mask_empty (plci)) {
  5274. sig_req(plci,HANGUP,0);
  5275. send_req(plci);
  5276. plci->State = IDLE;
  5277. }
  5278. plci->notifiedcall = 0;
  5279. a->listen_active--;
  5280. listen_check(a);
  5281. break;
  5282. case CALL_PEND_NOTIFY:
  5283. plci->notifiedcall = 1;
  5284. listen_check(a);
  5285. break;
  5286. case CALL_IND:
  5287. case CALL_CON:
  5288. if(plci->State==ADVANCED_VOICE_SIG || plci->State==ADVANCED_VOICE_NOSIG)
  5289. {
  5290. if(plci->internal_command==PERM_COD_CONN_PEND)
  5291. {
  5292. if(plci->State==ADVANCED_VOICE_NOSIG)
  5293. {
  5294. dbug(1,dprintf("***Codec OK"));
  5295. if(a->AdvSignalPLCI)
  5296. {
  5297. tplci = a->AdvSignalPLCI;
  5298. if(tplci->spoofed_msg)
  5299. {
  5300. dbug(1,dprintf("***Spoofed Msg(0x%x)",tplci->spoofed_msg));
  5301. tplci->command = 0;
  5302. tplci->internal_command = 0;
  5303. x_Id = ((word)tplci->Id<<8)|tplci->adapter->Id | 0x80;
  5304. switch (tplci->spoofed_msg)
  5305. {
  5306. case CALL_RES:
  5307. tplci->command = _CONNECT_I|RESPONSE;
  5308. api_load_msg (&tplci->saved_msg, saved_parms);
  5309. add_b1(tplci,&saved_parms[1],0,tplci->B1_facilities);
  5310. if (tplci->adapter->Info_Mask[tplci->appl->Id-1] & 0x200)
  5311. {
  5312. /* early B3 connect (CIP mask bit 9) no release after a disc */
  5313. add_p(tplci,LLI,"\x01\x01");
  5314. }
  5315. add_s(tplci, CONN_NR, &saved_parms[2]);
  5316. add_s(tplci, LLC, &saved_parms[4]);
  5317. add_ai(tplci, &saved_parms[5]);
  5318. tplci->State = INC_CON_ACCEPT;
  5319. sig_req(tplci, CALL_RES,0);
  5320. send_req(tplci);
  5321. break;
  5322. case AWAITING_SELECT_B:
  5323. dbug(1,dprintf("Select_B continue"));
  5324. start_internal_command (x_Id, tplci, select_b_command);
  5325. break;
  5326. case AWAITING_MANUF_CON: /* Get_Plci per Manufacturer_Req to ext controller */
  5327. if(!tplci->Sig.Id)
  5328. {
  5329. dbug(1,dprintf("No SigID!"));
  5330. sendf(tplci->appl, _MANUFACTURER_R|CONFIRM,x_Id,tplci->number, "dww",_DI_MANU_ID,_MANUFACTURER_R,_OUT_OF_PLCI);
  5331. plci_remove(tplci);
  5332. break;
  5333. }
  5334. tplci->command = _MANUFACTURER_R;
  5335. api_load_msg (&tplci->saved_msg, saved_parms);
  5336. dir = saved_parms[2].info[0];
  5337. if(dir==1) {
  5338. sig_req(tplci,CALL_REQ,0);
  5339. }
  5340. else if(!dir){
  5341. sig_req(tplci,LISTEN_REQ,0);
  5342. }
  5343. send_req(tplci);
  5344. sendf(tplci->appl, _MANUFACTURER_R|CONFIRM,x_Id,tplci->number, "dww",_DI_MANU_ID,_MANUFACTURER_R,0);
  5345. break;
  5346. case (CALL_REQ|AWAITING_MANUF_CON):
  5347. sig_req(tplci,CALL_REQ,0);
  5348. send_req(tplci);
  5349. break;
  5350. case CALL_REQ:
  5351. if(!tplci->Sig.Id)
  5352. {
  5353. dbug(1,dprintf("No SigID!"));
  5354. sendf(tplci->appl,_CONNECT_R|CONFIRM,tplci->adapter->Id,0,"w",_OUT_OF_PLCI);
  5355. plci_remove(tplci);
  5356. break;
  5357. }
  5358. tplci->command = _CONNECT_R;
  5359. api_load_msg (&tplci->saved_msg, saved_parms);
  5360. add_s(tplci,CPN,&saved_parms[1]);
  5361. add_s(tplci,DSA,&saved_parms[3]);
  5362. add_ai(tplci,&saved_parms[9]);
  5363. sig_req(tplci,CALL_REQ,0);
  5364. send_req(tplci);
  5365. break;
  5366. case CALL_RETRIEVE:
  5367. tplci->command = C_RETRIEVE_REQ;
  5368. sig_req(tplci,CALL_RETRIEVE,0);
  5369. send_req(tplci);
  5370. break;
  5371. }
  5372. tplci->spoofed_msg = 0;
  5373. if (tplci->internal_command == 0)
  5374. next_internal_command (x_Id, tplci);
  5375. }
  5376. }
  5377. next_internal_command (Id, plci);
  5378. break;
  5379. }
  5380. dbug(1,dprintf("***Codec Hook Init Req"));
  5381. plci->internal_command = PERM_COD_HOOK;
  5382. add_p(plci,FTY,"\x01\x09"); /* Get Hook State*/
  5383. sig_req(plci,TEL_CTRL,0);
  5384. send_req(plci);
  5385. }
  5386. }
  5387. else if(plci->command != _MANUFACTURER_R /* old style permanent connect */
  5388. && plci->State!=INC_ACT_PENDING)
  5389. {
  5390. mixer_set_bchannel_id_esc (plci, plci->b_channel);
  5391. if(plci->tel == ADV_VOICE && plci->SuppState == IDLE) /* with permanent codec switch on immediately */
  5392. {
  5393. chi[2] = plci->b_channel;
  5394. SetVoiceChannel(a->AdvCodecPLCI, chi, a);
  5395. }
  5396. sendf(plci->appl,_CONNECT_ACTIVE_I,Id,0,"Sss",parms[21],"","");
  5397. plci->State = INC_ACT_PENDING;
  5398. }
  5399. break;
  5400. case TEL_CTRL:
  5401. Number = 0;
  5402. ie = multi_fac_parms[0]; /* inspect the facility hook indications */
  5403. if(plci->State==ADVANCED_VOICE_SIG && ie[0]){
  5404. switch (ie[1]&0x91) {
  5405. case 0x80: /* hook off */
  5406. case 0x81:
  5407. if(plci->internal_command==PERM_COD_HOOK)
  5408. {
  5409. dbug(1,dprintf("init:hook_off"));
  5410. plci->hook_state = ie[1];
  5411. next_internal_command (Id, plci);
  5412. break;
  5413. }
  5414. else /* ignore doubled hook indications */
  5415. {
  5416. if( ((plci->hook_state)&0xf0)==0x80)
  5417. {
  5418. dbug(1,dprintf("ignore hook"));
  5419. break;
  5420. }
  5421. plci->hook_state = ie[1]&0x91;
  5422. }
  5423. /* check for incoming call pending */
  5424. /* and signal '+'.Appl must decide */
  5425. /* with connect_res if call must */
  5426. /* accepted or not */
  5427. for(i=0, tplci=NULL;i<max_appl;i++){
  5428. if(a->codec_listen[i]
  5429. && (a->codec_listen[i]->State==INC_CON_PENDING
  5430. ||a->codec_listen[i]->State==INC_CON_ALERT) ){
  5431. tplci = a->codec_listen[i];
  5432. tplci->appl = &application[i];
  5433. }
  5434. }
  5435. /* no incoming call, do outgoing call */
  5436. /* and signal '+' if outg. setup */
  5437. if(!a->AdvSignalPLCI && !tplci){
  5438. if((i=get_plci(a))) {
  5439. a->AdvSignalPLCI = &a->plci[i-1];
  5440. tplci = a->AdvSignalPLCI;
  5441. tplci->tel = ADV_VOICE;
  5442. PUT_WORD(&voice_cai[5],a->AdvSignalAppl->MaxDataLength);
  5443. if (a->Info_Mask[a->AdvSignalAppl->Id-1] & 0x200){
  5444. /* early B3 connect (CIP mask bit 9) no release after a disc */
  5445. add_p(tplci,LLI,"\x01\x01");
  5446. }
  5447. add_p(tplci, CAI, voice_cai);
  5448. add_p(tplci, OAD, a->TelOAD);
  5449. add_p(tplci, OSA, a->TelOSA);
  5450. add_p(tplci,SHIFT|6,NULL);
  5451. add_p(tplci,SIN,"\x02\x01\x00");
  5452. add_p(tplci,UID,"\x06\x43\x61\x70\x69\x32\x30");
  5453. sig_req(tplci,ASSIGN,DSIG_ID);
  5454. a->AdvSignalPLCI->internal_command = HOOK_OFF_REQ;
  5455. a->AdvSignalPLCI->command = 0;
  5456. tplci->appl = a->AdvSignalAppl;
  5457. tplci->call_dir = CALL_DIR_OUT | CALL_DIR_ORIGINATE;
  5458. send_req(tplci);
  5459. }
  5460. }
  5461. if(!tplci) break;
  5462. Id = ((word)tplci->Id<<8)|a->Id;
  5463. Id|=EXT_CONTROLLER;
  5464. sendf(tplci->appl,
  5465. _FACILITY_I,
  5466. Id,
  5467. 0,
  5468. "ws", (word)0, "\x01+");
  5469. break;
  5470. case 0x90: /* hook on */
  5471. case 0x91:
  5472. if(plci->internal_command==PERM_COD_HOOK)
  5473. {
  5474. dbug(1,dprintf("init:hook_on"));
  5475. plci->hook_state = ie[1]&0x91;
  5476. next_internal_command (Id, plci);
  5477. break;
  5478. }
  5479. else /* ignore doubled hook indications */
  5480. {
  5481. if( ((plci->hook_state)&0xf0)==0x90) break;
  5482. plci->hook_state = ie[1]&0x91;
  5483. }
  5484. /* hangup the adv. voice call and signal '-' to the appl */
  5485. if(a->AdvSignalPLCI) {
  5486. Id = ((word)a->AdvSignalPLCI->Id<<8)|a->Id;
  5487. if(plci->tel) Id|=EXT_CONTROLLER;
  5488. sendf(a->AdvSignalAppl,
  5489. _FACILITY_I,
  5490. Id,
  5491. 0,
  5492. "ws", (word)0, "\x01-");
  5493. a->AdvSignalPLCI->internal_command = HOOK_ON_REQ;
  5494. a->AdvSignalPLCI->command = 0;
  5495. sig_req(a->AdvSignalPLCI,HANGUP,0);
  5496. send_req(a->AdvSignalPLCI);
  5497. }
  5498. break;
  5499. }
  5500. }
  5501. break;
  5502. case RESUME:
  5503. clear_c_ind_mask_bit (plci, (word)(plci->appl->Id-1));
  5504. PUT_WORD(&resume_cau[4],GOOD);
  5505. sendf(plci->appl,_FACILITY_I,Id,0,"ws", (word)3, resume_cau);
  5506. break;
  5507. case SUSPEND:
  5508. clear_c_ind_mask (plci);
  5509. if (plci->NL.Id && !plci->nl_remove_id) {
  5510. mixer_remove (plci);
  5511. nl_req_ncci(plci,REMOVE,0);
  5512. }
  5513. if (!plci->sig_remove_id) {
  5514. plci->internal_command = 0;
  5515. sig_req(plci,REMOVE,0);
  5516. }
  5517. send_req(plci);
  5518. if(!plci->channels) {
  5519. sendf(plci->appl,_FACILITY_I,Id,0,"ws", (word)3, "\x05\x04\x00\x02\x00\x00");
  5520. sendf(plci->appl, _DISCONNECT_I, Id, 0, "w", 0);
  5521. }
  5522. break;
  5523. case SUSPEND_REJ:
  5524. break;
  5525. case HANGUP:
  5526. plci->hangup_flow_ctrl_timer=0;
  5527. if(plci->manufacturer && plci->State==LOCAL_CONNECT) break;
  5528. cau = parms[7];
  5529. if(cau) {
  5530. i = _L3_CAUSE | cau[2];
  5531. if(cau[2]==0) i = 0;
  5532. else if(cau[2]==8) i = _L1_ERROR;
  5533. else if(cau[2]==9 || cau[2]==10) i = _L2_ERROR;
  5534. else if(cau[2]==5) i = _CAPI_GUARD_ERROR;
  5535. }
  5536. else {
  5537. i = _L3_ERROR;
  5538. }
  5539. if(plci->State==INC_CON_PENDING || plci->State==INC_CON_ALERT)
  5540. {
  5541. for(i=0; i<max_appl; i++)
  5542. {
  5543. if(test_c_ind_mask_bit (plci, i))
  5544. sendf(&application[i], _DISCONNECT_I, Id, 0, "w", 0);
  5545. }
  5546. }
  5547. else
  5548. {
  5549. clear_c_ind_mask (plci);
  5550. }
  5551. if(!plci->appl)
  5552. {
  5553. if (plci->State == LISTENING)
  5554. {
  5555. plci->notifiedcall=0;
  5556. a->listen_active--;
  5557. }
  5558. plci->State = INC_DIS_PENDING;
  5559. if(c_ind_mask_empty (plci))
  5560. {
  5561. plci->State = IDLE;
  5562. if (plci->NL.Id && !plci->nl_remove_id)
  5563. {
  5564. mixer_remove (plci);
  5565. nl_req_ncci(plci,REMOVE,0);
  5566. }
  5567. if (!plci->sig_remove_id)
  5568. {
  5569. plci->internal_command = 0;
  5570. sig_req(plci,REMOVE,0);
  5571. }
  5572. send_req(plci);
  5573. }
  5574. }
  5575. else
  5576. {
  5577. /* collision of DISCONNECT or CONNECT_RES with HANGUP can */
  5578. /* result in a second HANGUP! Don't generate another */
  5579. /* DISCONNECT */
  5580. if(plci->State!=IDLE && plci->State!=INC_DIS_PENDING)
  5581. {
  5582. if(plci->State==RESUMING)
  5583. {
  5584. PUT_WORD(&resume_cau[4],i);
  5585. sendf(plci->appl,_FACILITY_I,Id,0,"ws", (word)3, resume_cau);
  5586. }
  5587. plci->State = INC_DIS_PENDING;
  5588. sendf(plci->appl,_DISCONNECT_I,Id,0,"w",i);
  5589. }
  5590. }
  5591. break;
  5592. case SSEXT_IND:
  5593. SendSSExtInd(NULL,plci,Id,multi_ssext_parms);
  5594. break;
  5595. case VSWITCH_REQ:
  5596. VSwitchReqInd(plci,Id,multi_vswitch_parms);
  5597. break;
  5598. case VSWITCH_IND:
  5599. if(plci->relatedPTYPLCI &&
  5600. plci->vswitchstate==3 &&
  5601. plci->relatedPTYPLCI->vswitchstate==3 &&
  5602. parms[MAXPARMSIDS-1][0])
  5603. {
  5604. add_p(plci->relatedPTYPLCI,SMSG,parms[MAXPARMSIDS-1]);
  5605. sig_req(plci->relatedPTYPLCI,VSWITCH_REQ,0);
  5606. send_req(plci->relatedPTYPLCI);
  5607. }
  5608. else VSwitchReqInd(plci,Id,multi_vswitch_parms);
  5609. break;
  5610. }
  5611. }
  5612. static void SendSetupInfo(APPL * appl, PLCI * plci, dword Id, byte * * parms, byte Info_Sent_Flag)
  5613. {
  5614. word i;
  5615. byte * ie;
  5616. word Info_Number;
  5617. byte * Info_Element;
  5618. word Info_Mask = 0;
  5619. dbug(1,dprintf("SetupInfo"));
  5620. for(i=0; i<MAXPARMSIDS; i++) {
  5621. ie = parms[i];
  5622. Info_Number = 0;
  5623. Info_Element = ie;
  5624. if(ie[0]) {
  5625. switch(i) {
  5626. case 0:
  5627. dbug(1,dprintf("CPN "));
  5628. Info_Number = 0x0070;
  5629. Info_Mask = 0x80;
  5630. Info_Sent_Flag = true;
  5631. break;
  5632. case 8: /* display */
  5633. dbug(1,dprintf("display(%d)",i));
  5634. Info_Number = 0x0028;
  5635. Info_Mask = 0x04;
  5636. Info_Sent_Flag = true;
  5637. break;
  5638. case 16: /* Channel Id */
  5639. dbug(1,dprintf("CHI"));
  5640. Info_Number = 0x0018;
  5641. Info_Mask = 0x100;
  5642. Info_Sent_Flag = true;
  5643. mixer_set_bchannel_id (plci, Info_Element);
  5644. break;
  5645. case 19: /* Redirected Number */
  5646. dbug(1,dprintf("RDN"));
  5647. Info_Number = 0x0074;
  5648. Info_Mask = 0x400;
  5649. Info_Sent_Flag = true;
  5650. break;
  5651. case 20: /* Redirected Number extended */
  5652. dbug(1,dprintf("RDX"));
  5653. Info_Number = 0x0073;
  5654. Info_Mask = 0x400;
  5655. Info_Sent_Flag = true;
  5656. break;
  5657. case 22: /* Redirecing Number */
  5658. dbug(1,dprintf("RIN"));
  5659. Info_Number = 0x0076;
  5660. Info_Mask = 0x400;
  5661. Info_Sent_Flag = true;
  5662. break;
  5663. default:
  5664. Info_Number = 0;
  5665. break;
  5666. }
  5667. }
  5668. if(i==MAXPARMSIDS-2){ /* to indicate the message type "Setup" */
  5669. Info_Number = 0x8000 |5;
  5670. Info_Mask = 0x10;
  5671. Info_Element = "";
  5672. }
  5673. if(Info_Sent_Flag && Info_Number){
  5674. if(plci->adapter->Info_Mask[appl->Id-1] & Info_Mask) {
  5675. sendf(appl,_INFO_I,Id,0,"wS",Info_Number,Info_Element);
  5676. }
  5677. }
  5678. }
  5679. }
  5680. static void SendInfo(PLCI *plci, dword Id, byte **parms, byte iesent)
  5681. {
  5682. word i;
  5683. word j;
  5684. word k;
  5685. byte * ie;
  5686. word Info_Number;
  5687. byte * Info_Element;
  5688. word Info_Mask = 0;
  5689. static byte charges[5] = {4,0,0,0,0};
  5690. static byte cause[] = {0x02,0x80,0x00};
  5691. APPL *appl;
  5692. dbug(1,dprintf("InfoParse "));
  5693. if(
  5694. !plci->appl
  5695. && !plci->State
  5696. && plci->Sig.Ind!=NCR_FACILITY
  5697. )
  5698. {
  5699. dbug(1,dprintf("NoParse "));
  5700. return;
  5701. }
  5702. cause[2] = 0;
  5703. for(i=0; i<MAXPARMSIDS; i++) {
  5704. ie = parms[i];
  5705. Info_Number = 0;
  5706. Info_Element = ie;
  5707. if(ie[0]) {
  5708. switch(i) {
  5709. case 0:
  5710. dbug(1,dprintf("CPN "));
  5711. Info_Number = 0x0070;
  5712. Info_Mask = 0x80;
  5713. break;
  5714. case 7: /* ESC_CAU */
  5715. dbug(1,dprintf("cau(0x%x)",ie[2]));
  5716. Info_Number = 0x0008;
  5717. Info_Mask = 0x00;
  5718. cause[2] = ie[2];
  5719. Info_Element = NULL;
  5720. break;
  5721. case 8: /* display */
  5722. dbug(1,dprintf("display(%d)",i));
  5723. Info_Number = 0x0028;
  5724. Info_Mask = 0x04;
  5725. break;
  5726. case 9: /* Date display */
  5727. dbug(1,dprintf("date(%d)",i));
  5728. Info_Number = 0x0029;
  5729. Info_Mask = 0x02;
  5730. break;
  5731. case 10: /* charges */
  5732. for(j=0;j<4;j++) charges[1+j] = 0;
  5733. for(j=0; j<ie[0] && !(ie[1+j]&0x80); j++);
  5734. for(k=1,j++; j<ie[0] && k<=4; j++,k++) charges[k] = ie[1+j];
  5735. Info_Number = 0x4000;
  5736. Info_Mask = 0x40;
  5737. Info_Element = charges;
  5738. break;
  5739. case 11: /* user user info */
  5740. dbug(1,dprintf("uui"));
  5741. Info_Number = 0x007E;
  5742. Info_Mask = 0x08;
  5743. break;
  5744. case 12: /* congestion receiver ready */
  5745. dbug(1,dprintf("clRDY"));
  5746. Info_Number = 0x00B0;
  5747. Info_Mask = 0x08;
  5748. Info_Element = "";
  5749. break;
  5750. case 13: /* congestion receiver not ready */
  5751. dbug(1,dprintf("clNRDY"));
  5752. Info_Number = 0x00BF;
  5753. Info_Mask = 0x08;
  5754. Info_Element = "";
  5755. break;
  5756. case 15: /* Keypad Facility */
  5757. dbug(1,dprintf("KEY"));
  5758. Info_Number = 0x002C;
  5759. Info_Mask = 0x20;
  5760. break;
  5761. case 16: /* Channel Id */
  5762. dbug(1,dprintf("CHI"));
  5763. Info_Number = 0x0018;
  5764. Info_Mask = 0x100;
  5765. mixer_set_bchannel_id (plci, Info_Element);
  5766. break;
  5767. case 17: /* if no 1tr6 cause, send full cause, else esc_cause */
  5768. dbug(1,dprintf("q9cau(0x%x)",ie[2]));
  5769. if(!cause[2] || cause[2]<0x80) break; /* eg. layer 1 error */
  5770. Info_Number = 0x0008;
  5771. Info_Mask = 0x01;
  5772. if(cause[2] != ie[2]) Info_Element = cause;
  5773. break;
  5774. case 19: /* Redirected Number */
  5775. dbug(1,dprintf("RDN"));
  5776. Info_Number = 0x0074;
  5777. Info_Mask = 0x400;
  5778. break;
  5779. case 22: /* Redirecing Number */
  5780. dbug(1,dprintf("RIN"));
  5781. Info_Number = 0x0076;
  5782. Info_Mask = 0x400;
  5783. break;
  5784. case 23: /* Notification Indicator */
  5785. dbug(1,dprintf("NI"));
  5786. Info_Number = (word)NI;
  5787. Info_Mask = 0x210;
  5788. break;
  5789. case 26: /* Call State */
  5790. dbug(1,dprintf("CST"));
  5791. Info_Number = (word)CST;
  5792. Info_Mask = 0x01; /* do with cause i.e. for now */
  5793. break;
  5794. case MAXPARMSIDS-2: /* Escape Message Type, must be the last indication */
  5795. dbug(1,dprintf("ESC/MT[0x%x]",ie[3]));
  5796. Info_Number = 0x8000 |ie[3];
  5797. if(iesent) Info_Mask = 0xffff;
  5798. else Info_Mask = 0x10;
  5799. Info_Element = "";
  5800. break;
  5801. default:
  5802. Info_Number = 0;
  5803. Info_Mask = 0;
  5804. Info_Element = "";
  5805. break;
  5806. }
  5807. }
  5808. if(plci->Sig.Ind==NCR_FACILITY) /* check controller broadcast */
  5809. {
  5810. for(j=0; j<max_appl; j++)
  5811. {
  5812. appl = &application[j];
  5813. if(Info_Number
  5814. && appl->Id
  5815. && plci->adapter->Info_Mask[appl->Id-1] &Info_Mask)
  5816. {
  5817. dbug(1,dprintf("NCR_Ind"));
  5818. iesent=true;
  5819. sendf(&application[j],_INFO_I,Id&0x0f,0,"wS",Info_Number,Info_Element);
  5820. }
  5821. }
  5822. }
  5823. else if(!plci->appl)
  5824. { /* overlap receiving broadcast */
  5825. if(Info_Number==CPN
  5826. || Info_Number==KEY
  5827. || Info_Number==NI
  5828. || Info_Number==DSP
  5829. || Info_Number==UUI )
  5830. {
  5831. for(j=0; j<max_appl; j++)
  5832. {
  5833. if(test_c_ind_mask_bit (plci, j))
  5834. {
  5835. dbug(1,dprintf("Ovl_Ind"));
  5836. iesent=true;
  5837. sendf(&application[j],_INFO_I,Id,0,"wS",Info_Number,Info_Element);
  5838. }
  5839. }
  5840. }
  5841. } /* all other signalling states */
  5842. else if(Info_Number
  5843. && plci->adapter->Info_Mask[plci->appl->Id-1] &Info_Mask)
  5844. {
  5845. dbug(1,dprintf("Std_Ind"));
  5846. iesent=true;
  5847. sendf(plci->appl,_INFO_I,Id,0,"wS",Info_Number,Info_Element);
  5848. }
  5849. }
  5850. }
  5851. static byte SendMultiIE(PLCI *plci, dword Id, byte **parms, byte ie_type,
  5852. dword info_mask, byte setupParse)
  5853. {
  5854. word i;
  5855. word j;
  5856. byte * ie;
  5857. word Info_Number;
  5858. byte * Info_Element;
  5859. APPL *appl;
  5860. word Info_Mask = 0;
  5861. byte iesent=0;
  5862. if(
  5863. !plci->appl
  5864. && !plci->State
  5865. && plci->Sig.Ind!=NCR_FACILITY
  5866. && !setupParse
  5867. )
  5868. {
  5869. dbug(1,dprintf("NoM-IEParse "));
  5870. return 0;
  5871. }
  5872. dbug(1,dprintf("M-IEParse "));
  5873. for(i=0; i<MAX_MULTI_IE; i++)
  5874. {
  5875. ie = parms[i];
  5876. Info_Number = 0;
  5877. Info_Element = ie;
  5878. if(ie[0])
  5879. {
  5880. dbug(1,dprintf("[Ind0x%x]:IE=0x%x",plci->Sig.Ind,ie_type));
  5881. Info_Number = (word)ie_type;
  5882. Info_Mask = (word)info_mask;
  5883. }
  5884. if(plci->Sig.Ind==NCR_FACILITY) /* check controller broadcast */
  5885. {
  5886. for(j=0; j<max_appl; j++)
  5887. {
  5888. appl = &application[j];
  5889. if(Info_Number
  5890. && appl->Id
  5891. && plci->adapter->Info_Mask[appl->Id-1] &Info_Mask)
  5892. {
  5893. iesent = true;
  5894. dbug(1,dprintf("Mlt_NCR_Ind"));
  5895. sendf(&application[j],_INFO_I,Id&0x0f,0,"wS",Info_Number,Info_Element);
  5896. }
  5897. }
  5898. }
  5899. else if(!plci->appl && Info_Number)
  5900. { /* overlap receiving broadcast */
  5901. for(j=0; j<max_appl; j++)
  5902. {
  5903. if(test_c_ind_mask_bit (plci, j))
  5904. {
  5905. iesent = true;
  5906. dbug(1,dprintf("Mlt_Ovl_Ind"));
  5907. sendf(&application[j],_INFO_I,Id,0,"wS",Info_Number,Info_Element);
  5908. }
  5909. }
  5910. } /* all other signalling states */
  5911. else if(Info_Number
  5912. && plci->adapter->Info_Mask[plci->appl->Id-1] &Info_Mask)
  5913. {
  5914. iesent = true;
  5915. dbug(1,dprintf("Mlt_Std_Ind"));
  5916. sendf(plci->appl,_INFO_I,Id,0,"wS",Info_Number,Info_Element);
  5917. }
  5918. }
  5919. return iesent;
  5920. }
  5921. static void SendSSExtInd(APPL * appl, PLCI * plci, dword Id, byte * * parms)
  5922. {
  5923. word i;
  5924. /* Format of multi_ssext_parms[i][]:
  5925. 0 byte length
  5926. 1 byte SSEXTIE
  5927. 2 byte SSEXT_REQ/SSEXT_IND
  5928. 3 byte length
  5929. 4 word SSExtCommand
  5930. 6... Params
  5931. */
  5932. if(
  5933. plci
  5934. && plci->State
  5935. && plci->Sig.Ind!=NCR_FACILITY
  5936. )
  5937. for(i=0;i<MAX_MULTI_IE;i++)
  5938. {
  5939. if(parms[i][0]<6) continue;
  5940. if(parms[i][2]==SSEXT_REQ) continue;
  5941. if(appl)
  5942. {
  5943. parms[i][0]=0; /* kill it */
  5944. sendf(appl,_MANUFACTURER_I,
  5945. Id,
  5946. 0,
  5947. "dwS",
  5948. _DI_MANU_ID,
  5949. _DI_SSEXT_CTRL,
  5950. &parms[i][3]);
  5951. }
  5952. else if(plci->appl)
  5953. {
  5954. parms[i][0]=0; /* kill it */
  5955. sendf(plci->appl,_MANUFACTURER_I,
  5956. Id,
  5957. 0,
  5958. "dwS",
  5959. _DI_MANU_ID,
  5960. _DI_SSEXT_CTRL,
  5961. &parms[i][3]);
  5962. }
  5963. }
  5964. };
  5965. static void nl_ind(PLCI *plci)
  5966. {
  5967. byte ch;
  5968. word ncci;
  5969. dword Id;
  5970. DIVA_CAPI_ADAPTER * a;
  5971. word NCCIcode;
  5972. APPL * APPLptr;
  5973. word count;
  5974. word Num;
  5975. word i, ncpi_state;
  5976. byte len, ncci_state;
  5977. word msg;
  5978. word info = 0;
  5979. word fax_feature_bits;
  5980. byte fax_send_edata_ack;
  5981. static byte v120_header_buffer[2 + 3];
  5982. static word fax_info[] = {
  5983. 0, /* T30_SUCCESS */
  5984. _FAX_NO_CONNECTION, /* T30_ERR_NO_DIS_RECEIVED */
  5985. _FAX_PROTOCOL_ERROR, /* T30_ERR_TIMEOUT_NO_RESPONSE */
  5986. _FAX_PROTOCOL_ERROR, /* T30_ERR_RETRY_NO_RESPONSE */
  5987. _FAX_PROTOCOL_ERROR, /* T30_ERR_TOO_MANY_REPEATS */
  5988. _FAX_PROTOCOL_ERROR, /* T30_ERR_UNEXPECTED_MESSAGE */
  5989. _FAX_REMOTE_ABORT, /* T30_ERR_UNEXPECTED_DCN */
  5990. _FAX_LOCAL_ABORT, /* T30_ERR_DTC_UNSUPPORTED */
  5991. _FAX_TRAINING_ERROR, /* T30_ERR_ALL_RATES_FAILED */
  5992. _FAX_TRAINING_ERROR, /* T30_ERR_TOO_MANY_TRAINS */
  5993. _FAX_PARAMETER_ERROR, /* T30_ERR_RECEIVE_CORRUPTED */
  5994. _FAX_REMOTE_ABORT, /* T30_ERR_UNEXPECTED_DISC */
  5995. _FAX_LOCAL_ABORT, /* T30_ERR_APPLICATION_DISC */
  5996. _FAX_REMOTE_REJECT, /* T30_ERR_INCOMPATIBLE_DIS */
  5997. _FAX_LOCAL_ABORT, /* T30_ERR_INCOMPATIBLE_DCS */
  5998. _FAX_PROTOCOL_ERROR, /* T30_ERR_TIMEOUT_NO_COMMAND */
  5999. _FAX_PROTOCOL_ERROR, /* T30_ERR_RETRY_NO_COMMAND */
  6000. _FAX_PROTOCOL_ERROR, /* T30_ERR_TIMEOUT_COMMAND_TOO_LONG */
  6001. _FAX_PROTOCOL_ERROR, /* T30_ERR_TIMEOUT_RESPONSE_TOO_LONG */
  6002. _FAX_NO_CONNECTION, /* T30_ERR_NOT_IDENTIFIED */
  6003. _FAX_PROTOCOL_ERROR, /* T30_ERR_SUPERVISORY_TIMEOUT */
  6004. _FAX_PARAMETER_ERROR, /* T30_ERR_TOO_LONG_SCAN_LINE */
  6005. _FAX_PROTOCOL_ERROR, /* T30_ERR_RETRY_NO_PAGE_AFTER_MPS */
  6006. _FAX_PROTOCOL_ERROR, /* T30_ERR_RETRY_NO_PAGE_AFTER_CFR */
  6007. _FAX_PROTOCOL_ERROR, /* T30_ERR_RETRY_NO_DCS_AFTER_FTT */
  6008. _FAX_PROTOCOL_ERROR, /* T30_ERR_RETRY_NO_DCS_AFTER_EOM */
  6009. _FAX_PROTOCOL_ERROR, /* T30_ERR_RETRY_NO_DCS_AFTER_MPS */
  6010. _FAX_PROTOCOL_ERROR, /* T30_ERR_RETRY_NO_DCN_AFTER_MCF */
  6011. _FAX_PROTOCOL_ERROR, /* T30_ERR_RETRY_NO_DCN_AFTER_RTN */
  6012. _FAX_PROTOCOL_ERROR, /* T30_ERR_RETRY_NO_CFR */
  6013. _FAX_PROTOCOL_ERROR, /* T30_ERR_RETRY_NO_MCF_AFTER_EOP */
  6014. _FAX_PROTOCOL_ERROR, /* T30_ERR_RETRY_NO_MCF_AFTER_EOM */
  6015. _FAX_PROTOCOL_ERROR, /* T30_ERR_RETRY_NO_MCF_AFTER_MPS */
  6016. 0x331d, /* T30_ERR_SUB_SEP_UNSUPPORTED */
  6017. 0x331e, /* T30_ERR_PWD_UNSUPPORTED */
  6018. 0x331f, /* T30_ERR_SUB_SEP_PWD_UNSUPPORTED */
  6019. _FAX_PROTOCOL_ERROR, /* T30_ERR_INVALID_COMMAND_FRAME */
  6020. _FAX_PARAMETER_ERROR, /* T30_ERR_UNSUPPORTED_PAGE_CODING */
  6021. _FAX_PARAMETER_ERROR, /* T30_ERR_INVALID_PAGE_CODING */
  6022. _FAX_REMOTE_REJECT, /* T30_ERR_INCOMPATIBLE_PAGE_CONFIG */
  6023. _FAX_LOCAL_ABORT, /* T30_ERR_TIMEOUT_FROM_APPLICATION */
  6024. _FAX_PROTOCOL_ERROR, /* T30_ERR_V34FAX_NO_REACTION_ON_MARK */
  6025. _FAX_PROTOCOL_ERROR, /* T30_ERR_V34FAX_TRAINING_TIMEOUT */
  6026. _FAX_PROTOCOL_ERROR, /* T30_ERR_V34FAX_UNEXPECTED_V21 */
  6027. _FAX_PROTOCOL_ERROR, /* T30_ERR_V34FAX_PRIMARY_CTS_ON */
  6028. _FAX_LOCAL_ABORT, /* T30_ERR_V34FAX_TURNAROUND_POLLING */
  6029. _FAX_LOCAL_ABORT /* T30_ERR_V34FAX_V8_INCOMPATIBILITY */
  6030. };
  6031. byte dtmf_code_buffer[CAPIDTMF_RECV_DIGIT_BUFFER_SIZE + 1];
  6032. static word rtp_info[] = {
  6033. GOOD, /* RTP_SUCCESS */
  6034. 0x3600 /* RTP_ERR_SSRC_OR_PAYLOAD_CHANGE */
  6035. };
  6036. static dword udata_forwarding_table[0x100 / sizeof(dword)] =
  6037. {
  6038. 0x0020301e, 0x00000000, 0x00000000, 0x00000000,
  6039. 0x00000000, 0x00000000, 0x00000000, 0x00000000
  6040. };
  6041. ch = plci->NL.IndCh;
  6042. a = plci->adapter;
  6043. ncci = a->ch_ncci[ch];
  6044. Id = (((dword)(ncci ? ncci : ch)) << 16) | (((word) plci->Id) << 8) | a->Id;
  6045. if(plci->tel) Id|=EXT_CONTROLLER;
  6046. APPLptr = plci->appl;
  6047. 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",
  6048. plci->NL.Id,Id,plci->Id,plci->tel,plci->State,ch,plci->channels,plci->NL.Ind &0x0f));
  6049. /* in the case if no connect_active_Ind was sent to the appl we wait for */
  6050. if (plci->nl_remove_id)
  6051. {
  6052. plci->NL.RNR = 2; /* discard */
  6053. dbug(1,dprintf("NL discard while remove pending"));
  6054. return;
  6055. }
  6056. if((plci->NL.Ind &0x0f)==N_CONNECT)
  6057. {
  6058. if(plci->State==INC_DIS_PENDING
  6059. || plci->State==OUTG_DIS_PENDING
  6060. || plci->State==IDLE)
  6061. {
  6062. plci->NL.RNR = 2; /* discard */
  6063. dbug(1,dprintf("discard n_connect"));
  6064. return;
  6065. }
  6066. if(plci->State < INC_ACT_PENDING)
  6067. {
  6068. plci->NL.RNR = 1; /* flow control */
  6069. channel_x_off (plci, ch, N_XON_CONNECT_IND);
  6070. return;
  6071. }
  6072. }
  6073. if(!APPLptr) /* no application or invalid data */
  6074. { /* while reloading the DSP */
  6075. dbug(1,dprintf("discard1"));
  6076. plci->NL.RNR = 2;
  6077. return;
  6078. }
  6079. if (((plci->NL.Ind &0x0f) == N_UDATA)
  6080. && (((plci->B2_prot != B2_SDLC) && ((plci->B1_resource == 17) || (plci->B1_resource == 18)))
  6081. || (plci->B2_prot == 7)
  6082. || (plci->B3_prot == 7)) )
  6083. {
  6084. plci->ncpi_buffer[0] = 0;
  6085. ncpi_state = plci->ncpi_state;
  6086. if (plci->NL.complete == 1)
  6087. {
  6088. byte * data = &plci->NL.RBuffer->P[0];
  6089. if ((plci->NL.RBuffer->length >= 12)
  6090. &&( (*data == DSP_UDATA_INDICATION_DCD_ON)
  6091. ||(*data == DSP_UDATA_INDICATION_CTS_ON)) )
  6092. {
  6093. word conn_opt, ncpi_opt = 0x00;
  6094. /* HexDump ("MDM N_UDATA:", plci->NL.RBuffer->length, data); */
  6095. if (*data == DSP_UDATA_INDICATION_DCD_ON)
  6096. plci->ncpi_state |= NCPI_MDM_DCD_ON_RECEIVED;
  6097. if (*data == DSP_UDATA_INDICATION_CTS_ON)
  6098. plci->ncpi_state |= NCPI_MDM_CTS_ON_RECEIVED;
  6099. data++; /* indication code */
  6100. data += 2; /* timestamp */
  6101. if ((*data == DSP_CONNECTED_NORM_V18) || (*data == DSP_CONNECTED_NORM_VOWN))
  6102. ncpi_state &= ~(NCPI_MDM_DCD_ON_RECEIVED | NCPI_MDM_CTS_ON_RECEIVED);
  6103. data++; /* connected norm */
  6104. conn_opt = GET_WORD(data);
  6105. data += 2; /* connected options */
  6106. PUT_WORD (&(plci->ncpi_buffer[1]), (word)(GET_DWORD(data) & 0x0000FFFF));
  6107. if (conn_opt & DSP_CONNECTED_OPTION_MASK_V42)
  6108. {
  6109. ncpi_opt |= MDM_NCPI_ECM_V42;
  6110. }
  6111. else if (conn_opt & DSP_CONNECTED_OPTION_MASK_MNP)
  6112. {
  6113. ncpi_opt |= MDM_NCPI_ECM_MNP;
  6114. }
  6115. else
  6116. {
  6117. ncpi_opt |= MDM_NCPI_TRANSPARENT;
  6118. }
  6119. if (conn_opt & DSP_CONNECTED_OPTION_MASK_COMPRESSION)
  6120. {
  6121. ncpi_opt |= MDM_NCPI_COMPRESSED;
  6122. }
  6123. PUT_WORD (&(plci->ncpi_buffer[3]), ncpi_opt);
  6124. plci->ncpi_buffer[0] = 4;
  6125. plci->ncpi_state |= NCPI_VALID_CONNECT_B3_IND | NCPI_VALID_CONNECT_B3_ACT | NCPI_VALID_DISC_B3_IND;
  6126. }
  6127. }
  6128. if (plci->B3_prot == 7)
  6129. {
  6130. if (((a->ncci_state[ncci] == INC_ACT_PENDING) || (a->ncci_state[ncci] == OUTG_CON_PENDING))
  6131. && (plci->ncpi_state & NCPI_VALID_CONNECT_B3_ACT)
  6132. && !(plci->ncpi_state & NCPI_CONNECT_B3_ACT_SENT))
  6133. {
  6134. a->ncci_state[ncci] = INC_ACT_PENDING;
  6135. sendf(plci->appl,_CONNECT_B3_ACTIVE_I,Id,0,"S",plci->ncpi_buffer);
  6136. plci->ncpi_state |= NCPI_CONNECT_B3_ACT_SENT;
  6137. }
  6138. }
  6139. if (!((plci->requested_options_conn | plci->requested_options | plci->adapter->requested_options_table[plci->appl->Id-1])
  6140. & ((1L << PRIVATE_V18) | (1L << PRIVATE_VOWN)))
  6141. || !(ncpi_state & NCPI_MDM_DCD_ON_RECEIVED)
  6142. || !(ncpi_state & NCPI_MDM_CTS_ON_RECEIVED))
  6143. {
  6144. plci->NL.RNR = 2;
  6145. return;
  6146. }
  6147. }
  6148. if(plci->NL.complete == 2)
  6149. {
  6150. if (((plci->NL.Ind &0x0f) == N_UDATA)
  6151. && !(udata_forwarding_table[plci->RData[0].P[0] >> 5] & (1L << (plci->RData[0].P[0] & 0x1f))))
  6152. {
  6153. switch(plci->RData[0].P[0])
  6154. {
  6155. case DTMF_UDATA_INDICATION_FAX_CALLING_TONE:
  6156. if (plci->dtmf_rec_active & DTMF_LISTEN_ACTIVE_FLAG)
  6157. sendf(plci->appl, _FACILITY_I, Id & 0xffffL, 0,"ws", SELECTOR_DTMF, "\x01X");
  6158. break;
  6159. case DTMF_UDATA_INDICATION_ANSWER_TONE:
  6160. if (plci->dtmf_rec_active & DTMF_LISTEN_ACTIVE_FLAG)
  6161. sendf(plci->appl, _FACILITY_I, Id & 0xffffL, 0,"ws", SELECTOR_DTMF, "\x01Y");
  6162. break;
  6163. case DTMF_UDATA_INDICATION_DIGITS_RECEIVED:
  6164. dtmf_indication (Id, plci, plci->RData[0].P, plci->RData[0].PLength);
  6165. break;
  6166. case DTMF_UDATA_INDICATION_DIGITS_SENT:
  6167. dtmf_confirmation (Id, plci);
  6168. break;
  6169. case UDATA_INDICATION_MIXER_TAP_DATA:
  6170. capidtmf_recv_process_block (&(plci->capidtmf_state), plci->RData[0].P + 1, (word)(plci->RData[0].PLength - 1));
  6171. i = capidtmf_indication (&(plci->capidtmf_state), dtmf_code_buffer + 1);
  6172. if (i != 0)
  6173. {
  6174. dtmf_code_buffer[0] = DTMF_UDATA_INDICATION_DIGITS_RECEIVED;
  6175. dtmf_indication (Id, plci, dtmf_code_buffer, (word)(i + 1));
  6176. }
  6177. break;
  6178. case UDATA_INDICATION_MIXER_COEFS_SET:
  6179. mixer_indication_coefs_set (Id, plci);
  6180. break;
  6181. case UDATA_INDICATION_XCONNECT_FROM:
  6182. mixer_indication_xconnect_from (Id, plci, plci->RData[0].P, plci->RData[0].PLength);
  6183. break;
  6184. case UDATA_INDICATION_XCONNECT_TO:
  6185. mixer_indication_xconnect_to (Id, plci, plci->RData[0].P, plci->RData[0].PLength);
  6186. break;
  6187. case LEC_UDATA_INDICATION_DISABLE_DETECT:
  6188. ec_indication (Id, plci, plci->RData[0].P, plci->RData[0].PLength);
  6189. break;
  6190. default:
  6191. break;
  6192. }
  6193. }
  6194. else
  6195. {
  6196. if ((plci->RData[0].PLength != 0)
  6197. && ((plci->B2_prot == B2_V120_ASYNC)
  6198. || (plci->B2_prot == B2_V120_ASYNC_V42BIS)
  6199. || (plci->B2_prot == B2_V120_BIT_TRANSPARENT)))
  6200. {
  6201. sendf(plci->appl,_DATA_B3_I,Id,0,
  6202. "dwww",
  6203. plci->RData[1].P,
  6204. (plci->NL.RNum < 2) ? 0 : plci->RData[1].PLength,
  6205. plci->RNum,
  6206. plci->RFlags);
  6207. }
  6208. else
  6209. {
  6210. sendf(plci->appl,_DATA_B3_I,Id,0,
  6211. "dwww",
  6212. plci->RData[0].P,
  6213. plci->RData[0].PLength,
  6214. plci->RNum,
  6215. plci->RFlags);
  6216. }
  6217. }
  6218. return;
  6219. }
  6220. fax_feature_bits = 0;
  6221. if((plci->NL.Ind &0x0f)==N_CONNECT ||
  6222. (plci->NL.Ind &0x0f)==N_CONNECT_ACK ||
  6223. (plci->NL.Ind &0x0f)==N_DISC ||
  6224. (plci->NL.Ind &0x0f)==N_EDATA ||
  6225. (plci->NL.Ind &0x0f)==N_DISC_ACK)
  6226. {
  6227. info = 0;
  6228. plci->ncpi_buffer[0] = 0;
  6229. switch (plci->B3_prot) {
  6230. case 0: /*XPARENT*/
  6231. case 1: /*T.90 NL*/
  6232. break; /* no network control protocol info - jfr */
  6233. case 2: /*ISO8202*/
  6234. case 3: /*X25 DCE*/
  6235. for(i=0; i<plci->NL.RLength; i++) plci->ncpi_buffer[4+i] = plci->NL.RBuffer->P[i];
  6236. plci->ncpi_buffer[0] = (byte)(i+3);
  6237. plci->ncpi_buffer[1] = (byte)(plci->NL.Ind &N_D_BIT? 1:0);
  6238. plci->ncpi_buffer[2] = 0;
  6239. plci->ncpi_buffer[3] = 0;
  6240. break;
  6241. case 4: /*T.30 - FAX*/
  6242. case 5: /*T.30 - FAX*/
  6243. if(plci->NL.RLength>=sizeof(T30_INFO))
  6244. {
  6245. dbug(1,dprintf("FaxStatus %04x", ((T30_INFO *)plci->NL.RBuffer->P)->code));
  6246. len = 9;
  6247. PUT_WORD(&(plci->ncpi_buffer[1]),((T30_INFO *)plci->NL.RBuffer->P)->rate_div_2400 * 2400);
  6248. fax_feature_bits = GET_WORD(&((T30_INFO *)plci->NL.RBuffer->P)->feature_bits_low);
  6249. i = (((T30_INFO *)plci->NL.RBuffer->P)->resolution & T30_RESOLUTION_R8_0770_OR_200) ? 0x0001 : 0x0000;
  6250. if (plci->B3_prot == 5)
  6251. {
  6252. if (!(fax_feature_bits & T30_FEATURE_BIT_ECM))
  6253. i |= 0x8000; /* This is not an ECM connection */
  6254. if (fax_feature_bits & T30_FEATURE_BIT_T6_CODING)
  6255. i |= 0x4000; /* This is a connection with MMR compression */
  6256. if (fax_feature_bits & T30_FEATURE_BIT_2D_CODING)
  6257. i |= 0x2000; /* This is a connection with MR compression */
  6258. if (fax_feature_bits & T30_FEATURE_BIT_MORE_DOCUMENTS)
  6259. i |= 0x0004; /* More documents */
  6260. if (fax_feature_bits & T30_FEATURE_BIT_POLLING)
  6261. i |= 0x0002; /* Fax-polling indication */
  6262. }
  6263. dbug(1,dprintf("FAX Options %04x %04x",fax_feature_bits,i));
  6264. PUT_WORD(&(plci->ncpi_buffer[3]),i);
  6265. PUT_WORD(&(plci->ncpi_buffer[5]),((T30_INFO *)plci->NL.RBuffer->P)->data_format);
  6266. plci->ncpi_buffer[7] = ((T30_INFO *)plci->NL.RBuffer->P)->pages_low;
  6267. plci->ncpi_buffer[8] = ((T30_INFO *)plci->NL.RBuffer->P)->pages_high;
  6268. plci->ncpi_buffer[len] = 0;
  6269. if(((T30_INFO *)plci->NL.RBuffer->P)->station_id_len)
  6270. {
  6271. plci->ncpi_buffer[len] = 20;
  6272. for (i = 0; i < 20; i++)
  6273. plci->ncpi_buffer[++len] = ((T30_INFO *)plci->NL.RBuffer->P)->station_id[i];
  6274. }
  6275. if (((plci->NL.Ind & 0x0f) == N_DISC) || ((plci->NL.Ind & 0x0f) == N_DISC_ACK))
  6276. {
  6277. if (((T30_INFO *)plci->NL.RBuffer->P)->code < ARRAY_SIZE(fax_info))
  6278. info = fax_info[((T30_INFO *)plci->NL.RBuffer->P)->code];
  6279. else
  6280. info = _FAX_PROTOCOL_ERROR;
  6281. }
  6282. if ((plci->requested_options_conn | plci->requested_options | a->requested_options_table[plci->appl->Id-1])
  6283. & ((1L << PRIVATE_FAX_SUB_SEP_PWD) | (1L << PRIVATE_FAX_NONSTANDARD)))
  6284. {
  6285. i = offsetof(T30_INFO, station_id) + 20 + ((T30_INFO *)plci->NL.RBuffer->P)->head_line_len;
  6286. while (i < plci->NL.RBuffer->length)
  6287. plci->ncpi_buffer[++len] = plci->NL.RBuffer->P[i++];
  6288. }
  6289. plci->ncpi_buffer[0] = len;
  6290. fax_feature_bits = GET_WORD(&((T30_INFO *)plci->NL.RBuffer->P)->feature_bits_low);
  6291. PUT_WORD(&((T30_INFO *)plci->fax_connect_info_buffer)->feature_bits_low, fax_feature_bits);
  6292. plci->ncpi_state |= NCPI_VALID_CONNECT_B3_IND;
  6293. if (((plci->NL.Ind &0x0f) == N_CONNECT_ACK)
  6294. || (((plci->NL.Ind &0x0f) == N_CONNECT)
  6295. && (fax_feature_bits & T30_FEATURE_BIT_POLLING))
  6296. || (((plci->NL.Ind &0x0f) == N_EDATA)
  6297. && ((((T30_INFO *)plci->NL.RBuffer->P)->code == EDATA_T30_TRAIN_OK)
  6298. || (((T30_INFO *)plci->NL.RBuffer->P)->code == EDATA_T30_DIS)
  6299. || (((T30_INFO *)plci->NL.RBuffer->P)->code == EDATA_T30_DTC))))
  6300. {
  6301. plci->ncpi_state |= NCPI_VALID_CONNECT_B3_ACT;
  6302. }
  6303. if (((plci->NL.Ind &0x0f) == N_DISC)
  6304. || ((plci->NL.Ind &0x0f) == N_DISC_ACK)
  6305. || (((plci->NL.Ind &0x0f) == N_EDATA)
  6306. && (((T30_INFO *)plci->NL.RBuffer->P)->code == EDATA_T30_EOP_CAPI)))
  6307. {
  6308. plci->ncpi_state |= NCPI_VALID_CONNECT_B3_ACT | NCPI_VALID_DISC_B3_IND;
  6309. }
  6310. }
  6311. break;
  6312. case B3_RTP:
  6313. if (((plci->NL.Ind & 0x0f) == N_DISC) || ((plci->NL.Ind & 0x0f) == N_DISC_ACK))
  6314. {
  6315. if (plci->NL.RLength != 0)
  6316. {
  6317. info = rtp_info[plci->NL.RBuffer->P[0]];
  6318. plci->ncpi_buffer[0] = plci->NL.RLength - 1;
  6319. for (i = 1; i < plci->NL.RLength; i++)
  6320. plci->ncpi_buffer[i] = plci->NL.RBuffer->P[i];
  6321. }
  6322. }
  6323. break;
  6324. }
  6325. plci->NL.RNR = 2;
  6326. }
  6327. switch(plci->NL.Ind &0x0f) {
  6328. case N_EDATA:
  6329. if ((plci->B3_prot == 4) || (plci->B3_prot == 5))
  6330. {
  6331. dbug(1,dprintf("EDATA ncci=0x%x state=%d code=%02x", ncci, a->ncci_state[ncci],
  6332. ((T30_INFO *)plci->NL.RBuffer->P)->code));
  6333. fax_send_edata_ack = (((T30_INFO *)(plci->fax_connect_info_buffer))->operating_mode == T30_OPERATING_MODE_CAPI_NEG);
  6334. if ((plci->nsf_control_bits & T30_NSF_CONTROL_BIT_ENABLE_NSF)
  6335. && (plci->nsf_control_bits & (T30_NSF_CONTROL_BIT_NEGOTIATE_IND | T30_NSF_CONTROL_BIT_NEGOTIATE_RESP))
  6336. && (((T30_INFO *)plci->NL.RBuffer->P)->code == EDATA_T30_DIS)
  6337. && (a->ncci_state[ncci] == OUTG_CON_PENDING)
  6338. && (plci->ncpi_state & NCPI_VALID_CONNECT_B3_ACT)
  6339. && !(plci->ncpi_state & NCPI_NEGOTIATE_B3_SENT))
  6340. {
  6341. ((T30_INFO *)(plci->fax_connect_info_buffer))->code = ((T30_INFO *)plci->NL.RBuffer->P)->code;
  6342. sendf(plci->appl,_MANUFACTURER_I,Id,0,"dwbS",_DI_MANU_ID,_DI_NEGOTIATE_B3,
  6343. (byte)(plci->ncpi_buffer[0] + 1), plci->ncpi_buffer);
  6344. plci->ncpi_state |= NCPI_NEGOTIATE_B3_SENT;
  6345. if (plci->nsf_control_bits & T30_NSF_CONTROL_BIT_NEGOTIATE_RESP)
  6346. fax_send_edata_ack = false;
  6347. }
  6348. if (a->manufacturer_features & MANUFACTURER_FEATURE_FAX_PAPER_FORMATS)
  6349. {
  6350. switch (((T30_INFO *)plci->NL.RBuffer->P)->code)
  6351. {
  6352. case EDATA_T30_DIS:
  6353. if ((a->ncci_state[ncci] == OUTG_CON_PENDING)
  6354. && !(GET_WORD(&((T30_INFO *)plci->fax_connect_info_buffer)->control_bits_low) & T30_CONTROL_BIT_REQUEST_POLLING)
  6355. && (plci->ncpi_state & NCPI_VALID_CONNECT_B3_ACT)
  6356. && !(plci->ncpi_state & NCPI_CONNECT_B3_ACT_SENT))
  6357. {
  6358. a->ncci_state[ncci] = INC_ACT_PENDING;
  6359. if (plci->B3_prot == 4)
  6360. sendf(plci->appl,_CONNECT_B3_ACTIVE_I,Id,0,"s","");
  6361. else
  6362. sendf(plci->appl,_CONNECT_B3_ACTIVE_I,Id,0,"S",plci->ncpi_buffer);
  6363. plci->ncpi_state |= NCPI_CONNECT_B3_ACT_SENT;
  6364. }
  6365. break;
  6366. case EDATA_T30_TRAIN_OK:
  6367. if ((a->ncci_state[ncci] == INC_ACT_PENDING)
  6368. && (plci->ncpi_state & NCPI_VALID_CONNECT_B3_ACT)
  6369. && !(plci->ncpi_state & NCPI_CONNECT_B3_ACT_SENT))
  6370. {
  6371. if (plci->B3_prot == 4)
  6372. sendf(plci->appl,_CONNECT_B3_ACTIVE_I,Id,0,"s","");
  6373. else
  6374. sendf(plci->appl,_CONNECT_B3_ACTIVE_I,Id,0,"S",plci->ncpi_buffer);
  6375. plci->ncpi_state |= NCPI_CONNECT_B3_ACT_SENT;
  6376. }
  6377. break;
  6378. case EDATA_T30_EOP_CAPI:
  6379. if (a->ncci_state[ncci] == CONNECTED)
  6380. {
  6381. sendf(plci->appl,_DISCONNECT_B3_I,Id,0,"wS",GOOD,plci->ncpi_buffer);
  6382. a->ncci_state[ncci] = INC_DIS_PENDING;
  6383. plci->ncpi_state = 0;
  6384. fax_send_edata_ack = false;
  6385. }
  6386. break;
  6387. }
  6388. }
  6389. else
  6390. {
  6391. switch (((T30_INFO *)plci->NL.RBuffer->P)->code)
  6392. {
  6393. case EDATA_T30_TRAIN_OK:
  6394. if ((a->ncci_state[ncci] == INC_ACT_PENDING)
  6395. && (plci->ncpi_state & NCPI_VALID_CONNECT_B3_ACT)
  6396. && !(plci->ncpi_state & NCPI_CONNECT_B3_ACT_SENT))
  6397. {
  6398. if (plci->B3_prot == 4)
  6399. sendf(plci->appl,_CONNECT_B3_ACTIVE_I,Id,0,"s","");
  6400. else
  6401. sendf(plci->appl,_CONNECT_B3_ACTIVE_I,Id,0,"S",plci->ncpi_buffer);
  6402. plci->ncpi_state |= NCPI_CONNECT_B3_ACT_SENT;
  6403. }
  6404. break;
  6405. }
  6406. }
  6407. if (fax_send_edata_ack)
  6408. {
  6409. ((T30_INFO *)(plci->fax_connect_info_buffer))->code = ((T30_INFO *)plci->NL.RBuffer->P)->code;
  6410. plci->fax_edata_ack_length = 1;
  6411. start_internal_command (Id, plci, fax_edata_ack_command);
  6412. }
  6413. }
  6414. else
  6415. {
  6416. dbug(1,dprintf("EDATA ncci=0x%x state=%d", ncci, a->ncci_state[ncci]));
  6417. }
  6418. break;
  6419. case N_CONNECT:
  6420. if (!a->ch_ncci[ch])
  6421. {
  6422. ncci = get_ncci (plci, ch, 0);
  6423. Id = (Id & 0xffff) | (((dword) ncci) << 16);
  6424. }
  6425. dbug(1,dprintf("N_CONNECT: ch=%d state=%d plci=%lx plci_Id=%lx plci_State=%d",
  6426. ch, a->ncci_state[ncci], a->ncci_plci[ncci], plci->Id, plci->State));
  6427. msg = _CONNECT_B3_I;
  6428. if (a->ncci_state[ncci] == IDLE)
  6429. plci->channels++;
  6430. else if (plci->B3_prot == 1)
  6431. msg = _CONNECT_B3_T90_ACTIVE_I;
  6432. a->ncci_state[ncci] = INC_CON_PENDING;
  6433. if(plci->B3_prot == 4)
  6434. sendf(plci->appl,msg,Id,0,"s","");
  6435. else
  6436. sendf(plci->appl,msg,Id,0,"S",plci->ncpi_buffer);
  6437. break;
  6438. case N_CONNECT_ACK:
  6439. dbug(1,dprintf("N_connect_Ack"));
  6440. if (plci->internal_command_queue[0]
  6441. && ((plci->adjust_b_state == ADJUST_B_CONNECT_2)
  6442. || (plci->adjust_b_state == ADJUST_B_CONNECT_3)
  6443. || (plci->adjust_b_state == ADJUST_B_CONNECT_4)))
  6444. {
  6445. (*(plci->internal_command_queue[0]))(Id, plci, 0);
  6446. if (!plci->internal_command)
  6447. next_internal_command (Id, plci);
  6448. break;
  6449. }
  6450. msg = _CONNECT_B3_ACTIVE_I;
  6451. if (plci->B3_prot == 1)
  6452. {
  6453. if (a->ncci_state[ncci] != OUTG_CON_PENDING)
  6454. msg = _CONNECT_B3_T90_ACTIVE_I;
  6455. a->ncci_state[ncci] = INC_ACT_PENDING;
  6456. sendf(plci->appl,msg,Id,0,"S",plci->ncpi_buffer);
  6457. }
  6458. else if ((plci->B3_prot == 4) || (plci->B3_prot == 5) || (plci->B3_prot == 7))
  6459. {
  6460. if ((a->ncci_state[ncci] == OUTG_CON_PENDING)
  6461. && (plci->ncpi_state & NCPI_VALID_CONNECT_B3_ACT)
  6462. && !(plci->ncpi_state & NCPI_CONNECT_B3_ACT_SENT))
  6463. {
  6464. a->ncci_state[ncci] = INC_ACT_PENDING;
  6465. if (plci->B3_prot == 4)
  6466. sendf(plci->appl,msg,Id,0,"s","");
  6467. else
  6468. sendf(plci->appl,msg,Id,0,"S",plci->ncpi_buffer);
  6469. plci->ncpi_state |= NCPI_CONNECT_B3_ACT_SENT;
  6470. }
  6471. }
  6472. else
  6473. {
  6474. a->ncci_state[ncci] = INC_ACT_PENDING;
  6475. sendf(plci->appl,msg,Id,0,"S",plci->ncpi_buffer);
  6476. }
  6477. if (plci->adjust_b_restore)
  6478. {
  6479. plci->adjust_b_restore = false;
  6480. start_internal_command (Id, plci, adjust_b_restore);
  6481. }
  6482. break;
  6483. case N_DISC:
  6484. case N_DISC_ACK:
  6485. if (plci->internal_command_queue[0]
  6486. && ((plci->internal_command == FAX_DISCONNECT_COMMAND_1)
  6487. || (plci->internal_command == FAX_DISCONNECT_COMMAND_2)
  6488. || (plci->internal_command == FAX_DISCONNECT_COMMAND_3)))
  6489. {
  6490. (*(plci->internal_command_queue[0]))(Id, plci, 0);
  6491. if (!plci->internal_command)
  6492. next_internal_command (Id, plci);
  6493. }
  6494. ncci_state = a->ncci_state[ncci];
  6495. ncci_remove (plci, ncci, false);
  6496. /* with N_DISC or N_DISC_ACK the IDI frees the respective */
  6497. /* channel, so we cannot store the state in ncci_state! The */
  6498. /* information which channel we received a N_DISC is thus */
  6499. /* stored in the inc_dis_ncci_table buffer. */
  6500. for(i=0; plci->inc_dis_ncci_table[i]; i++);
  6501. plci->inc_dis_ncci_table[i] = (byte) ncci;
  6502. /* need a connect_b3_ind before a disconnect_b3_ind with FAX */
  6503. if (!plci->channels
  6504. && (plci->B1_resource == 16)
  6505. && (plci->State <= CONNECTED))
  6506. {
  6507. len = 9;
  6508. i = ((T30_INFO *)plci->fax_connect_info_buffer)->rate_div_2400 * 2400;
  6509. PUT_WORD (&plci->ncpi_buffer[1], i);
  6510. PUT_WORD (&plci->ncpi_buffer[3], 0);
  6511. i = ((T30_INFO *)plci->fax_connect_info_buffer)->data_format;
  6512. PUT_WORD (&plci->ncpi_buffer[5], i);
  6513. PUT_WORD (&plci->ncpi_buffer[7], 0);
  6514. plci->ncpi_buffer[len] = 0;
  6515. plci->ncpi_buffer[0] = len;
  6516. if(plci->B3_prot == 4)
  6517. sendf(plci->appl,_CONNECT_B3_I,Id,0,"s","");
  6518. else
  6519. {
  6520. if ((plci->requested_options_conn | plci->requested_options | a->requested_options_table[plci->appl->Id-1])
  6521. & ((1L << PRIVATE_FAX_SUB_SEP_PWD) | (1L << PRIVATE_FAX_NONSTANDARD)))
  6522. {
  6523. plci->ncpi_buffer[++len] = 0;
  6524. plci->ncpi_buffer[++len] = 0;
  6525. plci->ncpi_buffer[++len] = 0;
  6526. plci->ncpi_buffer[0] = len;
  6527. }
  6528. sendf(plci->appl,_CONNECT_B3_I,Id,0,"S",plci->ncpi_buffer);
  6529. }
  6530. sendf(plci->appl,_DISCONNECT_B3_I,Id,0,"wS",info,plci->ncpi_buffer);
  6531. plci->ncpi_state = 0;
  6532. sig_req(plci,HANGUP,0);
  6533. send_req(plci);
  6534. plci->State = OUTG_DIS_PENDING;
  6535. /* disc here */
  6536. }
  6537. else if ((a->manufacturer_features & MANUFACTURER_FEATURE_FAX_PAPER_FORMATS)
  6538. && ((plci->B3_prot == 4) || (plci->B3_prot == 5))
  6539. && ((ncci_state == INC_DIS_PENDING) || (ncci_state == IDLE)))
  6540. {
  6541. if (ncci_state == IDLE)
  6542. {
  6543. if (plci->channels)
  6544. plci->channels--;
  6545. if((plci->State==IDLE || plci->State==SUSPENDING) && !plci->channels){
  6546. if(plci->State == SUSPENDING){
  6547. sendf(plci->appl,
  6548. _FACILITY_I,
  6549. Id & 0xffffL,
  6550. 0,
  6551. "ws", (word)3, "\x03\x04\x00\x00");
  6552. sendf(plci->appl, _DISCONNECT_I, Id & 0xffffL, 0, "w", 0);
  6553. }
  6554. plci_remove(plci);
  6555. plci->State=IDLE;
  6556. }
  6557. }
  6558. }
  6559. else if (plci->channels)
  6560. {
  6561. sendf(plci->appl,_DISCONNECT_B3_I,Id,0,"wS",info,plci->ncpi_buffer);
  6562. plci->ncpi_state = 0;
  6563. if ((ncci_state == OUTG_REJ_PENDING)
  6564. && ((plci->B3_prot != B3_T90NL) && (plci->B3_prot != B3_ISO8208) && (plci->B3_prot != B3_X25_DCE)))
  6565. {
  6566. sig_req(plci,HANGUP,0);
  6567. send_req(plci);
  6568. plci->State = OUTG_DIS_PENDING;
  6569. }
  6570. }
  6571. break;
  6572. case N_RESET:
  6573. a->ncci_state[ncci] = INC_RES_PENDING;
  6574. sendf(plci->appl,_RESET_B3_I,Id,0,"S",plci->ncpi_buffer);
  6575. break;
  6576. case N_RESET_ACK:
  6577. a->ncci_state[ncci] = CONNECTED;
  6578. sendf(plci->appl,_RESET_B3_I,Id,0,"S",plci->ncpi_buffer);
  6579. break;
  6580. case N_UDATA:
  6581. if (!(udata_forwarding_table[plci->NL.RBuffer->P[0] >> 5] & (1L << (plci->NL.RBuffer->P[0] & 0x1f))))
  6582. {
  6583. plci->RData[0].P = plci->internal_ind_buffer + (-((int)(long)(plci->internal_ind_buffer)) & 3);
  6584. plci->RData[0].PLength = INTERNAL_IND_BUFFER_SIZE;
  6585. plci->NL.R = plci->RData;
  6586. plci->NL.RNum = 1;
  6587. return;
  6588. }
  6589. case N_BDATA:
  6590. case N_DATA:
  6591. if (((a->ncci_state[ncci] != CONNECTED) && (plci->B2_prot == 1)) /* transparent */
  6592. || (a->ncci_state[ncci] == IDLE)
  6593. || (a->ncci_state[ncci] == INC_DIS_PENDING))
  6594. {
  6595. plci->NL.RNR = 2;
  6596. break;
  6597. }
  6598. if ((a->ncci_state[ncci] != CONNECTED)
  6599. && (a->ncci_state[ncci] != OUTG_DIS_PENDING)
  6600. && (a->ncci_state[ncci] != OUTG_REJ_PENDING))
  6601. {
  6602. dbug(1,dprintf("flow control"));
  6603. plci->NL.RNR = 1; /* flow control */
  6604. channel_x_off (plci, ch, 0);
  6605. break;
  6606. }
  6607. NCCIcode = ncci | (((word)a->Id) << 8);
  6608. /* count all buffers within the Application pool */
  6609. /* belonging to the same NCCI. If this is below the */
  6610. /* number of buffers available per NCCI we accept */
  6611. /* this packet, otherwise we reject it */
  6612. count = 0;
  6613. Num = 0xffff;
  6614. for(i=0; i<APPLptr->MaxBuffer; i++) {
  6615. if(NCCIcode==APPLptr->DataNCCI[i]) count++;
  6616. if(!APPLptr->DataNCCI[i] && Num==0xffff) Num = i;
  6617. }
  6618. if(count>=APPLptr->MaxNCCIData || Num==0xffff)
  6619. {
  6620. dbug(3,dprintf("Flow-Control"));
  6621. plci->NL.RNR = 1;
  6622. if( ++(APPLptr->NCCIDataFlowCtrlTimer)>=
  6623. (word)((a->manufacturer_features & MANUFACTURER_FEATURE_OOB_CHANNEL) ? 40 : 2000))
  6624. {
  6625. plci->NL.RNR = 2;
  6626. dbug(3,dprintf("DiscardData"));
  6627. } else {
  6628. channel_x_off (plci, ch, 0);
  6629. }
  6630. break;
  6631. }
  6632. else
  6633. {
  6634. APPLptr->NCCIDataFlowCtrlTimer = 0;
  6635. }
  6636. plci->RData[0].P = ReceiveBufferGet(APPLptr,Num);
  6637. if(!plci->RData[0].P) {
  6638. plci->NL.RNR = 1;
  6639. channel_x_off (plci, ch, 0);
  6640. break;
  6641. }
  6642. APPLptr->DataNCCI[Num] = NCCIcode;
  6643. APPLptr->DataFlags[Num] = (plci->Id<<8) | (plci->NL.Ind>>4);
  6644. dbug(3,dprintf("Buffer(%d), Max = %d",Num,APPLptr->MaxBuffer));
  6645. plci->RNum = Num;
  6646. plci->RFlags = plci->NL.Ind>>4;
  6647. plci->RData[0].PLength = APPLptr->MaxDataLength;
  6648. plci->NL.R = plci->RData;
  6649. if ((plci->NL.RLength != 0)
  6650. && ((plci->B2_prot == B2_V120_ASYNC)
  6651. || (plci->B2_prot == B2_V120_ASYNC_V42BIS)
  6652. || (plci->B2_prot == B2_V120_BIT_TRANSPARENT)))
  6653. {
  6654. plci->RData[1].P = plci->RData[0].P;
  6655. plci->RData[1].PLength = plci->RData[0].PLength;
  6656. plci->RData[0].P = v120_header_buffer + (-((unsigned long)v120_header_buffer) & 3);
  6657. if ((plci->NL.RBuffer->P[0] & V120_HEADER_EXTEND_BIT) || (plci->NL.RLength == 1))
  6658. plci->RData[0].PLength = 1;
  6659. else
  6660. plci->RData[0].PLength = 2;
  6661. if (plci->NL.RBuffer->P[0] & V120_HEADER_BREAK_BIT)
  6662. plci->RFlags |= 0x0010;
  6663. if (plci->NL.RBuffer->P[0] & (V120_HEADER_C1_BIT | V120_HEADER_C2_BIT))
  6664. plci->RFlags |= 0x8000;
  6665. plci->NL.RNum = 2;
  6666. }
  6667. else
  6668. {
  6669. if((plci->NL.Ind &0x0f)==N_UDATA)
  6670. plci->RFlags |= 0x0010;
  6671. else if ((plci->B3_prot == B3_RTP) && ((plci->NL.Ind & 0x0f) == N_BDATA))
  6672. plci->RFlags |= 0x0001;
  6673. plci->NL.RNum = 1;
  6674. }
  6675. break;
  6676. case N_DATA_ACK:
  6677. data_ack (plci, ch);
  6678. break;
  6679. default:
  6680. plci->NL.RNR = 2;
  6681. break;
  6682. }
  6683. }
  6684. /*------------------------------------------------------------------*/
  6685. /* find a free PLCI */
  6686. /*------------------------------------------------------------------*/
  6687. static word get_plci(DIVA_CAPI_ADAPTER *a)
  6688. {
  6689. word i,j;
  6690. PLCI * plci;
  6691. dump_plcis (a);
  6692. for(i=0;i<a->max_plci && a->plci[i].Id;i++);
  6693. if(i==a->max_plci) {
  6694. dbug(1,dprintf("get_plci: out of PLCIs"));
  6695. return 0;
  6696. }
  6697. plci = &a->plci[i];
  6698. plci->Id = (byte)(i+1);
  6699. plci->Sig.Id = 0;
  6700. plci->NL.Id = 0;
  6701. plci->sig_req = 0;
  6702. plci->nl_req = 0;
  6703. plci->appl = NULL;
  6704. plci->relatedPTYPLCI = NULL;
  6705. plci->State = IDLE;
  6706. plci->SuppState = IDLE;
  6707. plci->channels = 0;
  6708. plci->tel = 0;
  6709. plci->B1_resource = 0;
  6710. plci->B2_prot = 0;
  6711. plci->B3_prot = 0;
  6712. plci->command = 0;
  6713. plci->m_command = 0;
  6714. init_internal_command_queue (plci);
  6715. plci->number = 0;
  6716. plci->req_in_start = 0;
  6717. plci->req_in = 0;
  6718. plci->req_out = 0;
  6719. plci->msg_in_write_pos = MSG_IN_QUEUE_SIZE;
  6720. plci->msg_in_read_pos = MSG_IN_QUEUE_SIZE;
  6721. plci->msg_in_wrap_pos = MSG_IN_QUEUE_SIZE;
  6722. plci->data_sent = false;
  6723. plci->send_disc = 0;
  6724. plci->sig_global_req = 0;
  6725. plci->sig_remove_id = 0;
  6726. plci->nl_global_req = 0;
  6727. plci->nl_remove_id = 0;
  6728. plci->adv_nl = 0;
  6729. plci->manufacturer = false;
  6730. plci->call_dir = CALL_DIR_OUT | CALL_DIR_ORIGINATE;
  6731. plci->spoofed_msg = 0;
  6732. plci->ptyState = 0;
  6733. plci->cr_enquiry = false;
  6734. plci->hangup_flow_ctrl_timer = 0;
  6735. plci->ncci_ring_list = 0;
  6736. for(j=0;j<MAX_CHANNELS_PER_PLCI;j++) plci->inc_dis_ncci_table[j] = 0;
  6737. clear_c_ind_mask (plci);
  6738. set_group_ind_mask (plci);
  6739. plci->fax_connect_info_length = 0;
  6740. plci->nsf_control_bits = 0;
  6741. plci->ncpi_state = 0x00;
  6742. plci->ncpi_buffer[0] = 0;
  6743. plci->requested_options_conn = 0;
  6744. plci->requested_options = 0;
  6745. plci->notifiedcall = 0;
  6746. plci->vswitchstate = 0;
  6747. plci->vsprot = 0;
  6748. plci->vsprotdialect = 0;
  6749. init_b1_config (plci);
  6750. dbug(1,dprintf("get_plci(%x)",plci->Id));
  6751. return i+1;
  6752. }
  6753. /*------------------------------------------------------------------*/
  6754. /* put a parameter in the parameter buffer */
  6755. /*------------------------------------------------------------------*/
  6756. static void add_p(PLCI * plci, byte code, byte * p)
  6757. {
  6758. word p_length;
  6759. p_length = 0;
  6760. if(p) p_length = p[0];
  6761. add_ie(plci, code, p, p_length);
  6762. }
  6763. /*------------------------------------------------------------------*/
  6764. /* put a structure in the parameter buffer */
  6765. /*------------------------------------------------------------------*/
  6766. static void add_s(PLCI * plci, byte code, API_PARSE * p)
  6767. {
  6768. if(p) add_ie(plci, code, p->info, (word)p->length);
  6769. }
  6770. /*------------------------------------------------------------------*/
  6771. /* put multiple structures in the parameter buffer */
  6772. /*------------------------------------------------------------------*/
  6773. static void add_ss(PLCI * plci, byte code, API_PARSE * p)
  6774. {
  6775. byte i;
  6776. if(p){
  6777. dbug(1,dprintf("add_ss(%x,len=%d)",code,p->length));
  6778. for(i=2;i<(byte)p->length;i+=p->info[i]+2){
  6779. dbug(1,dprintf("add_ss_ie(%x,len=%d)",p->info[i-1],p->info[i]));
  6780. add_ie(plci, p->info[i-1], (byte *)&(p->info[i]), (word)p->info[i]);
  6781. }
  6782. }
  6783. }
  6784. /*------------------------------------------------------------------*/
  6785. /* return the channel number sent by the application in a esc_chi */
  6786. /*------------------------------------------------------------------*/
  6787. static byte getChannel(API_PARSE * p)
  6788. {
  6789. byte i;
  6790. if(p){
  6791. for(i=2;i<(byte)p->length;i+=p->info[i]+2){
  6792. if(p->info[i]==2){
  6793. if(p->info[i-1]==ESC && p->info[i+1]==CHI) return (p->info[i+2]);
  6794. }
  6795. }
  6796. }
  6797. return 0;
  6798. }
  6799. /*------------------------------------------------------------------*/
  6800. /* put an information element in the parameter buffer */
  6801. /*------------------------------------------------------------------*/
  6802. static void add_ie(PLCI * plci, byte code, byte * p, word p_length)
  6803. {
  6804. word i;
  6805. if(!(code &0x80) && !p_length) return;
  6806. if(plci->req_in==plci->req_in_start) {
  6807. plci->req_in +=2;
  6808. }
  6809. else {
  6810. plci->req_in--;
  6811. }
  6812. plci->RBuffer[plci->req_in++] = code;
  6813. if(p) {
  6814. plci->RBuffer[plci->req_in++] = (byte)p_length;
  6815. for(i=0;i<p_length;i++) plci->RBuffer[plci->req_in++] = p[1+i];
  6816. }
  6817. plci->RBuffer[plci->req_in++] = 0;
  6818. }
  6819. /*------------------------------------------------------------------*/
  6820. /* put a unstructured data into the buffer */
  6821. /*------------------------------------------------------------------*/
  6822. static void add_d(PLCI *plci, word length, byte *p)
  6823. {
  6824. word i;
  6825. if(plci->req_in==plci->req_in_start) {
  6826. plci->req_in +=2;
  6827. }
  6828. else {
  6829. plci->req_in--;
  6830. }
  6831. for(i=0;i<length;i++) plci->RBuffer[plci->req_in++] = p[i];
  6832. }
  6833. /*------------------------------------------------------------------*/
  6834. /* put parameters from the Additional Info parameter in the */
  6835. /* parameter buffer */
  6836. /*------------------------------------------------------------------*/
  6837. static void add_ai(PLCI *plci, API_PARSE *ai)
  6838. {
  6839. word i;
  6840. API_PARSE ai_parms[5];
  6841. for(i=0;i<5;i++) ai_parms[i].length = 0;
  6842. if(!ai->length)
  6843. return;
  6844. if(api_parse(&ai->info[1], (word)ai->length, "ssss", ai_parms))
  6845. return;
  6846. add_s (plci,KEY,&ai_parms[1]);
  6847. add_s (plci,UUI,&ai_parms[2]);
  6848. add_ss(plci,FTY,&ai_parms[3]);
  6849. }
  6850. /*------------------------------------------------------------------*/
  6851. /* put parameter for b1 protocol in the parameter buffer */
  6852. /*------------------------------------------------------------------*/
  6853. static word add_b1(PLCI *plci, API_PARSE *bp, word b_channel_info,
  6854. word b1_facilities)
  6855. {
  6856. API_PARSE bp_parms[8];
  6857. API_PARSE mdm_cfg[9];
  6858. API_PARSE global_config[2];
  6859. byte cai[256];
  6860. byte resource[] = {5,9,13,12,16,39,9,17,17,18};
  6861. byte voice_cai[] = "\x06\x14\x00\x00\x00\x00\x08";
  6862. word i;
  6863. API_PARSE mdm_cfg_v18[4];
  6864. word j, n, w;
  6865. dword d;
  6866. for(i=0;i<8;i++) bp_parms[i].length = 0;
  6867. for(i=0;i<2;i++) global_config[i].length = 0;
  6868. dbug(1,dprintf("add_b1"));
  6869. api_save_msg(bp, "s", &plci->B_protocol);
  6870. if(b_channel_info==2){
  6871. plci->B1_resource = 0;
  6872. adjust_b1_facilities (plci, plci->B1_resource, b1_facilities);
  6873. add_p(plci, CAI, "\x01\x00");
  6874. dbug(1,dprintf("Cai=1,0 (no resource)"));
  6875. return 0;
  6876. }
  6877. if(plci->tel == CODEC_PERMANENT) return 0;
  6878. else if(plci->tel == CODEC){
  6879. plci->B1_resource = 1;
  6880. adjust_b1_facilities (plci, plci->B1_resource, b1_facilities);
  6881. add_p(plci, CAI, "\x01\x01");
  6882. dbug(1,dprintf("Cai=1,1 (Codec)"));
  6883. return 0;
  6884. }
  6885. else if(plci->tel == ADV_VOICE){
  6886. plci->B1_resource = add_b1_facilities (plci, 9, (word)(b1_facilities | B1_FACILITY_VOICE));
  6887. adjust_b1_facilities (plci, plci->B1_resource, (word)(b1_facilities | B1_FACILITY_VOICE));
  6888. voice_cai[1] = plci->B1_resource;
  6889. PUT_WORD (&voice_cai[5], plci->appl->MaxDataLength);
  6890. add_p(plci, CAI, voice_cai);
  6891. dbug(1,dprintf("Cai=1,0x%x (AdvVoice)",voice_cai[1]));
  6892. return 0;
  6893. }
  6894. plci->call_dir &= ~(CALL_DIR_ORIGINATE | CALL_DIR_ANSWER);
  6895. if (plci->call_dir & CALL_DIR_OUT)
  6896. plci->call_dir |= CALL_DIR_ORIGINATE;
  6897. else if (plci->call_dir & CALL_DIR_IN)
  6898. plci->call_dir |= CALL_DIR_ANSWER;
  6899. if(!bp->length){
  6900. plci->B1_resource = 0x5;
  6901. adjust_b1_facilities (plci, plci->B1_resource, b1_facilities);
  6902. add_p(plci, CAI, "\x01\x05");
  6903. return 0;
  6904. }
  6905. dbug(1,dprintf("b_prot_len=%d",(word)bp->length));
  6906. if(bp->length>256) return _WRONG_MESSAGE_FORMAT;
  6907. if(api_parse(&bp->info[1], (word)bp->length, "wwwsssb", bp_parms))
  6908. {
  6909. bp_parms[6].length = 0;
  6910. if(api_parse(&bp->info[1], (word)bp->length, "wwwsss", bp_parms))
  6911. {
  6912. dbug(1,dprintf("b-form.!"));
  6913. return _WRONG_MESSAGE_FORMAT;
  6914. }
  6915. }
  6916. else if (api_parse(&bp->info[1], (word)bp->length, "wwwssss", bp_parms))
  6917. {
  6918. dbug(1,dprintf("b-form.!"));
  6919. return _WRONG_MESSAGE_FORMAT;
  6920. }
  6921. if(bp_parms[6].length)
  6922. {
  6923. if(api_parse(&bp_parms[6].info[1], (word)bp_parms[6].length, "w", global_config))
  6924. {
  6925. return _WRONG_MESSAGE_FORMAT;
  6926. }
  6927. switch(GET_WORD(global_config[0].info))
  6928. {
  6929. case 1:
  6930. plci->call_dir = (plci->call_dir & ~CALL_DIR_ANSWER) | CALL_DIR_ORIGINATE;
  6931. break;
  6932. case 2:
  6933. plci->call_dir = (plci->call_dir & ~CALL_DIR_ORIGINATE) | CALL_DIR_ANSWER;
  6934. break;
  6935. }
  6936. }
  6937. dbug(1,dprintf("call_dir=%04x", plci->call_dir));
  6938. if ((GET_WORD(bp_parms[0].info) == B1_RTP)
  6939. && (plci->adapter->man_profile.private_options & (1L << PRIVATE_RTP)))
  6940. {
  6941. plci->B1_resource = add_b1_facilities (plci, 31, (word)(b1_facilities & ~B1_FACILITY_VOICE));
  6942. adjust_b1_facilities (plci, plci->B1_resource, (word)(b1_facilities & ~B1_FACILITY_VOICE));
  6943. cai[1] = plci->B1_resource;
  6944. cai[2] = 0;
  6945. cai[3] = 0;
  6946. cai[4] = 0;
  6947. PUT_WORD(&cai[5],plci->appl->MaxDataLength);
  6948. for (i = 0; i < bp_parms[3].length; i++)
  6949. cai[7+i] = bp_parms[3].info[1+i];
  6950. cai[0] = 6 + bp_parms[3].length;
  6951. add_p(plci, CAI, cai);
  6952. return 0;
  6953. }
  6954. if ((GET_WORD(bp_parms[0].info) == B1_PIAFS)
  6955. && (plci->adapter->man_profile.private_options & (1L << PRIVATE_PIAFS)))
  6956. {
  6957. plci->B1_resource = add_b1_facilities (plci, 35/* PIAFS HARDWARE FACILITY */, (word)(b1_facilities & ~B1_FACILITY_VOICE));
  6958. adjust_b1_facilities (plci, plci->B1_resource, (word)(b1_facilities & ~B1_FACILITY_VOICE));
  6959. cai[1] = plci->B1_resource;
  6960. cai[2] = 0;
  6961. cai[3] = 0;
  6962. cai[4] = 0;
  6963. PUT_WORD(&cai[5],plci->appl->MaxDataLength);
  6964. cai[0] = 6;
  6965. add_p(plci, CAI, cai);
  6966. return 0;
  6967. }
  6968. if ((GET_WORD(bp_parms[0].info) >= 32)
  6969. || (!((1L << GET_WORD(bp_parms[0].info)) & plci->adapter->profile.B1_Protocols)
  6970. && ((GET_WORD(bp_parms[0].info) != 3)
  6971. || !((1L << B1_HDLC) & plci->adapter->profile.B1_Protocols)
  6972. || ((bp_parms[3].length != 0) && (GET_WORD(&bp_parms[3].info[1]) != 0) && (GET_WORD(&bp_parms[3].info[1]) != 56000)))))
  6973. {
  6974. return _B1_NOT_SUPPORTED;
  6975. }
  6976. plci->B1_resource = add_b1_facilities (plci, resource[GET_WORD(bp_parms[0].info)],
  6977. (word)(b1_facilities & ~B1_FACILITY_VOICE));
  6978. adjust_b1_facilities (plci, plci->B1_resource, (word)(b1_facilities & ~B1_FACILITY_VOICE));
  6979. cai[0] = 6;
  6980. cai[1] = plci->B1_resource;
  6981. for (i=2;i<sizeof(cai);i++) cai[i] = 0;
  6982. if ((GET_WORD(bp_parms[0].info) == B1_MODEM_ALL_NEGOTIATE)
  6983. || (GET_WORD(bp_parms[0].info) == B1_MODEM_ASYNC)
  6984. || (GET_WORD(bp_parms[0].info) == B1_MODEM_SYNC_HDLC))
  6985. { /* B1 - modem */
  6986. for (i=0;i<7;i++) mdm_cfg[i].length = 0;
  6987. if (bp_parms[3].length)
  6988. {
  6989. if(api_parse(&bp_parms[3].info[1],(word)bp_parms[3].length,"wwwwww", mdm_cfg))
  6990. {
  6991. return (_WRONG_MESSAGE_FORMAT);
  6992. }
  6993. cai[2] = 0; /* Bit rate for adaptation */
  6994. dbug(1,dprintf("MDM Max Bit Rate:<%d>", GET_WORD(mdm_cfg[0].info)));
  6995. PUT_WORD (&cai[13], 0); /* Min Tx speed */
  6996. PUT_WORD (&cai[15], GET_WORD(mdm_cfg[0].info)); /* Max Tx speed */
  6997. PUT_WORD (&cai[17], 0); /* Min Rx speed */
  6998. PUT_WORD (&cai[19], GET_WORD(mdm_cfg[0].info)); /* Max Rx speed */
  6999. cai[3] = 0; /* Async framing parameters */
  7000. switch (GET_WORD (mdm_cfg[2].info))
  7001. { /* Parity */
  7002. case 1: /* odd parity */
  7003. cai[3] |= (DSP_CAI_ASYNC_PARITY_ENABLE | DSP_CAI_ASYNC_PARITY_ODD);
  7004. dbug(1,dprintf("MDM: odd parity"));
  7005. break;
  7006. case 2: /* even parity */
  7007. cai[3] |= (DSP_CAI_ASYNC_PARITY_ENABLE | DSP_CAI_ASYNC_PARITY_EVEN);
  7008. dbug(1,dprintf("MDM: even parity"));
  7009. break;
  7010. default:
  7011. dbug(1,dprintf("MDM: no parity"));
  7012. break;
  7013. }
  7014. switch (GET_WORD (mdm_cfg[3].info))
  7015. { /* stop bits */
  7016. case 1: /* 2 stop bits */
  7017. cai[3] |= DSP_CAI_ASYNC_TWO_STOP_BITS;
  7018. dbug(1,dprintf("MDM: 2 stop bits"));
  7019. break;
  7020. default:
  7021. dbug(1,dprintf("MDM: 1 stop bit"));
  7022. break;
  7023. }
  7024. switch (GET_WORD (mdm_cfg[1].info))
  7025. { /* char length */
  7026. case 5:
  7027. cai[3] |= DSP_CAI_ASYNC_CHAR_LENGTH_5;
  7028. dbug(1,dprintf("MDM: 5 bits"));
  7029. break;
  7030. case 6:
  7031. cai[3] |= DSP_CAI_ASYNC_CHAR_LENGTH_6;
  7032. dbug(1,dprintf("MDM: 6 bits"));
  7033. break;
  7034. case 7:
  7035. cai[3] |= DSP_CAI_ASYNC_CHAR_LENGTH_7;
  7036. dbug(1,dprintf("MDM: 7 bits"));
  7037. break;
  7038. default:
  7039. dbug(1,dprintf("MDM: 8 bits"));
  7040. break;
  7041. }
  7042. cai[7] = 0; /* Line taking options */
  7043. cai[8] = 0; /* Modulation negotiation options */
  7044. cai[9] = 0; /* Modulation options */
  7045. if (((plci->call_dir & CALL_DIR_ORIGINATE) != 0) ^ ((plci->call_dir & CALL_DIR_OUT) != 0))
  7046. {
  7047. cai[9] |= DSP_CAI_MODEM_REVERSE_DIRECTION;
  7048. dbug(1, dprintf("MDM: Reverse direction"));
  7049. }
  7050. if (GET_WORD (mdm_cfg[4].info) & MDM_CAPI_DISABLE_RETRAIN)
  7051. {
  7052. cai[9] |= DSP_CAI_MODEM_DISABLE_RETRAIN;
  7053. dbug(1, dprintf("MDM: Disable retrain"));
  7054. }
  7055. if (GET_WORD (mdm_cfg[4].info) & MDM_CAPI_DISABLE_RING_TONE)
  7056. {
  7057. cai[7] |= DSP_CAI_MODEM_DISABLE_CALLING_TONE | DSP_CAI_MODEM_DISABLE_ANSWER_TONE;
  7058. dbug(1, dprintf("MDM: Disable ring tone"));
  7059. }
  7060. if (GET_WORD (mdm_cfg[4].info) & MDM_CAPI_GUARD_1800)
  7061. {
  7062. cai[8] |= DSP_CAI_MODEM_GUARD_TONE_1800HZ;
  7063. dbug(1, dprintf("MDM: 1800 guard tone"));
  7064. }
  7065. else if (GET_WORD (mdm_cfg[4].info) & MDM_CAPI_GUARD_550 )
  7066. {
  7067. cai[8] |= DSP_CAI_MODEM_GUARD_TONE_550HZ;
  7068. dbug(1, dprintf("MDM: 550 guard tone"));
  7069. }
  7070. if ((GET_WORD (mdm_cfg[5].info) & 0x00ff) == MDM_CAPI_NEG_V100)
  7071. {
  7072. cai[8] |= DSP_CAI_MODEM_NEGOTIATE_V100;
  7073. dbug(1, dprintf("MDM: V100"));
  7074. }
  7075. else if ((GET_WORD (mdm_cfg[5].info) & 0x00ff) == MDM_CAPI_NEG_MOD_CLASS)
  7076. {
  7077. cai[8] |= DSP_CAI_MODEM_NEGOTIATE_IN_CLASS;
  7078. dbug(1, dprintf("MDM: IN CLASS"));
  7079. }
  7080. else if ((GET_WORD (mdm_cfg[5].info) & 0x00ff) == MDM_CAPI_NEG_DISABLED)
  7081. {
  7082. cai[8] |= DSP_CAI_MODEM_NEGOTIATE_DISABLED;
  7083. dbug(1, dprintf("MDM: DISABLED"));
  7084. }
  7085. cai[0] = 20;
  7086. if ((plci->adapter->man_profile.private_options & (1L << PRIVATE_V18))
  7087. && (GET_WORD(mdm_cfg[5].info) & 0x8000)) /* Private V.18 enable */
  7088. {
  7089. plci->requested_options |= 1L << PRIVATE_V18;
  7090. }
  7091. if (GET_WORD(mdm_cfg[5].info) & 0x4000) /* Private VOWN enable */
  7092. plci->requested_options |= 1L << PRIVATE_VOWN;
  7093. if ((plci->requested_options_conn | plci->requested_options | plci->adapter->requested_options_table[plci->appl->Id-1])
  7094. & ((1L << PRIVATE_V18) | (1L << PRIVATE_VOWN)))
  7095. {
  7096. if (!api_parse(&bp_parms[3].info[1],(word)bp_parms[3].length,"wwwwwws", mdm_cfg))
  7097. {
  7098. i = 27;
  7099. if (mdm_cfg[6].length >= 4)
  7100. {
  7101. d = GET_DWORD(&mdm_cfg[6].info[1]);
  7102. cai[7] |= (byte) d; /* line taking options */
  7103. cai[9] |= (byte)(d >> 8); /* modulation options */
  7104. cai[++i] = (byte)(d >> 16); /* vown modulation options */
  7105. cai[++i] = (byte)(d >> 24);
  7106. if (mdm_cfg[6].length >= 8)
  7107. {
  7108. d = GET_DWORD(&mdm_cfg[6].info[5]);
  7109. cai[10] |= (byte) d; /* disabled modulations mask */
  7110. cai[11] |= (byte)(d >> 8);
  7111. if (mdm_cfg[6].length >= 12)
  7112. {
  7113. d = GET_DWORD(&mdm_cfg[6].info[9]);
  7114. cai[12] = (byte) d; /* enabled modulations mask */
  7115. cai[++i] = (byte)(d >> 8); /* vown enabled modulations */
  7116. cai[++i] = (byte)(d >> 16);
  7117. cai[++i] = (byte)(d >> 24);
  7118. cai[++i] = 0;
  7119. if (mdm_cfg[6].length >= 14)
  7120. {
  7121. w = GET_WORD(&mdm_cfg[6].info[13]);
  7122. if (w != 0)
  7123. PUT_WORD(&cai[13], w); /* min tx speed */
  7124. if (mdm_cfg[6].length >= 16)
  7125. {
  7126. w = GET_WORD(&mdm_cfg[6].info[15]);
  7127. if (w != 0)
  7128. PUT_WORD(&cai[15], w); /* max tx speed */
  7129. if (mdm_cfg[6].length >= 18)
  7130. {
  7131. w = GET_WORD(&mdm_cfg[6].info[17]);
  7132. if (w != 0)
  7133. PUT_WORD(&cai[17], w); /* min rx speed */
  7134. if (mdm_cfg[6].length >= 20)
  7135. {
  7136. w = GET_WORD(&mdm_cfg[6].info[19]);
  7137. if (w != 0)
  7138. PUT_WORD(&cai[19], w); /* max rx speed */
  7139. if (mdm_cfg[6].length >= 22)
  7140. {
  7141. w = GET_WORD(&mdm_cfg[6].info[21]);
  7142. cai[23] = (byte)(-((short) w)); /* transmit level */
  7143. if (mdm_cfg[6].length >= 24)
  7144. {
  7145. w = GET_WORD(&mdm_cfg[6].info[23]);
  7146. cai[22] |= (byte) w; /* info options mask */
  7147. cai[21] |= (byte)(w >> 8); /* disabled symbol rates */
  7148. }
  7149. }
  7150. }
  7151. }
  7152. }
  7153. }
  7154. }
  7155. }
  7156. }
  7157. cai[27] = i - 27;
  7158. i++;
  7159. if (!api_parse(&bp_parms[3].info[1],(word)bp_parms[3].length,"wwwwwwss", mdm_cfg))
  7160. {
  7161. if (!api_parse(&mdm_cfg[7].info[1],(word)mdm_cfg[7].length,"sss", mdm_cfg_v18))
  7162. {
  7163. for (n = 0; n < 3; n++)
  7164. {
  7165. cai[i] = (byte)(mdm_cfg_v18[n].length);
  7166. for (j = 1; j < ((word)(cai[i] + 1)); j++)
  7167. cai[i+j] = mdm_cfg_v18[n].info[j];
  7168. i += cai[i] + 1;
  7169. }
  7170. }
  7171. }
  7172. cai[0] = (byte)(i - 1);
  7173. }
  7174. }
  7175. }
  7176. }
  7177. if(GET_WORD(bp_parms[0].info)==2 || /* V.110 async */
  7178. GET_WORD(bp_parms[0].info)==3 ) /* V.110 sync */
  7179. {
  7180. if(bp_parms[3].length){
  7181. dbug(1,dprintf("V.110,%d",GET_WORD(&bp_parms[3].info[1])));
  7182. switch(GET_WORD(&bp_parms[3].info[1])){ /* Rate */
  7183. case 0:
  7184. case 56000:
  7185. if(GET_WORD(bp_parms[0].info)==3){ /* V.110 sync 56k */
  7186. dbug(1,dprintf("56k sync HSCX"));
  7187. cai[1] = 8;
  7188. cai[2] = 0;
  7189. cai[3] = 0;
  7190. }
  7191. else if(GET_WORD(bp_parms[0].info)==2){
  7192. dbug(1,dprintf("56k async DSP"));
  7193. cai[2] = 9;
  7194. }
  7195. break;
  7196. case 50: cai[2] = 1; break;
  7197. case 75: cai[2] = 1; break;
  7198. case 110: cai[2] = 1; break;
  7199. case 150: cai[2] = 1; break;
  7200. case 200: cai[2] = 1; break;
  7201. case 300: cai[2] = 1; break;
  7202. case 600: cai[2] = 1; break;
  7203. case 1200: cai[2] = 2; break;
  7204. case 2400: cai[2] = 3; break;
  7205. case 4800: cai[2] = 4; break;
  7206. case 7200: cai[2] = 10; break;
  7207. case 9600: cai[2] = 5; break;
  7208. case 12000: cai[2] = 13; break;
  7209. case 24000: cai[2] = 0; break;
  7210. case 14400: cai[2] = 11; break;
  7211. case 19200: cai[2] = 6; break;
  7212. case 28800: cai[2] = 12; break;
  7213. case 38400: cai[2] = 7; break;
  7214. case 48000: cai[2] = 8; break;
  7215. case 76: cai[2] = 15; break; /* 75/1200 */
  7216. case 1201: cai[2] = 14; break; /* 1200/75 */
  7217. case 56001: cai[2] = 9; break; /* V.110 56000 */
  7218. default:
  7219. return _B1_PARM_NOT_SUPPORTED;
  7220. }
  7221. cai[3] = 0;
  7222. if (cai[1] == 13) /* v.110 async */
  7223. {
  7224. if (bp_parms[3].length >= 8)
  7225. {
  7226. switch (GET_WORD (&bp_parms[3].info[3]))
  7227. { /* char length */
  7228. case 5:
  7229. cai[3] |= DSP_CAI_ASYNC_CHAR_LENGTH_5;
  7230. break;
  7231. case 6:
  7232. cai[3] |= DSP_CAI_ASYNC_CHAR_LENGTH_6;
  7233. break;
  7234. case 7:
  7235. cai[3] |= DSP_CAI_ASYNC_CHAR_LENGTH_7;
  7236. break;
  7237. }
  7238. switch (GET_WORD (&bp_parms[3].info[5]))
  7239. { /* Parity */
  7240. case 1: /* odd parity */
  7241. cai[3] |= (DSP_CAI_ASYNC_PARITY_ENABLE | DSP_CAI_ASYNC_PARITY_ODD);
  7242. break;
  7243. case 2: /* even parity */
  7244. cai[3] |= (DSP_CAI_ASYNC_PARITY_ENABLE | DSP_CAI_ASYNC_PARITY_EVEN);
  7245. break;
  7246. }
  7247. switch (GET_WORD (&bp_parms[3].info[7]))
  7248. { /* stop bits */
  7249. case 1: /* 2 stop bits */
  7250. cai[3] |= DSP_CAI_ASYNC_TWO_STOP_BITS;
  7251. break;
  7252. }
  7253. }
  7254. }
  7255. }
  7256. else if(cai[1]==8 || GET_WORD(bp_parms[0].info)==3 ){
  7257. dbug(1,dprintf("V.110 default 56k sync"));
  7258. cai[1] = 8;
  7259. cai[2] = 0;
  7260. cai[3] = 0;
  7261. }
  7262. else {
  7263. dbug(1,dprintf("V.110 default 9600 async"));
  7264. cai[2] = 5;
  7265. }
  7266. }
  7267. PUT_WORD(&cai[5],plci->appl->MaxDataLength);
  7268. 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]));
  7269. /* HexDump ("CAI", sizeof(cai), &cai[0]); */
  7270. add_p(plci, CAI, cai);
  7271. return 0;
  7272. }
  7273. /*------------------------------------------------------------------*/
  7274. /* put parameter for b2 and B3 protocol in the parameter buffer */
  7275. /*------------------------------------------------------------------*/
  7276. static word add_b23(PLCI *plci, API_PARSE *bp)
  7277. {
  7278. word i, fax_control_bits;
  7279. byte pos, len;
  7280. byte SAPI = 0x40; /* default SAPI 16 for x.31 */
  7281. API_PARSE bp_parms[8];
  7282. API_PARSE * b1_config;
  7283. API_PARSE * b2_config;
  7284. API_PARSE b2_config_parms[8];
  7285. API_PARSE * b3_config;
  7286. API_PARSE b3_config_parms[6];
  7287. API_PARSE global_config[2];
  7288. static byte llc[3] = {2,0,0};
  7289. static byte dlc[20] = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
  7290. static byte nlc[256];
  7291. static byte lli[12] = {1,1};
  7292. const byte llc2_out[] = {1,2,4,6,2,0,0,0, X75_V42BIS,V120_L2,V120_V42BIS,V120_L2,6};
  7293. const byte llc2_in[] = {1,3,4,6,3,0,0,0, X75_V42BIS,V120_L2,V120_V42BIS,V120_L2,6};
  7294. const byte llc3[] = {4,3,2,2,6,6,0};
  7295. const byte header[] = {0,2,3,3,0,0,0};
  7296. for(i=0;i<8;i++) bp_parms[i].length = 0;
  7297. for(i=0;i<6;i++) b2_config_parms[i].length = 0;
  7298. for(i=0;i<5;i++) b3_config_parms[i].length = 0;
  7299. lli[0] = 1;
  7300. lli[1] = 1;
  7301. if (plci->adapter->manufacturer_features & MANUFACTURER_FEATURE_XONOFF_FLOW_CONTROL)
  7302. lli[1] |= 2;
  7303. if (plci->adapter->manufacturer_features & MANUFACTURER_FEATURE_OOB_CHANNEL)
  7304. lli[1] |= 4;
  7305. if ((lli[1] & 0x02) && (diva_xdi_extended_features & DIVA_CAPI_USE_CMA)) {
  7306. lli[1] |= 0x10;
  7307. if (plci->rx_dma_descriptor <= 0) {
  7308. plci->rx_dma_descriptor=diva_get_dma_descriptor(plci,&plci->rx_dma_magic);
  7309. if (plci->rx_dma_descriptor >= 0)
  7310. plci->rx_dma_descriptor++;
  7311. }
  7312. if (plci->rx_dma_descriptor > 0) {
  7313. lli[0] = 6;
  7314. lli[1] |= 0x40;
  7315. lli[2] = (byte)(plci->rx_dma_descriptor - 1);
  7316. lli[3] = (byte)plci->rx_dma_magic;
  7317. lli[4] = (byte)(plci->rx_dma_magic >> 8);
  7318. lli[5] = (byte)(plci->rx_dma_magic >> 16);
  7319. lli[6] = (byte)(plci->rx_dma_magic >> 24);
  7320. }
  7321. }
  7322. if (DIVA_CAPI_SUPPORTS_NO_CANCEL(plci->adapter)) {
  7323. lli[1] |= 0x20;
  7324. }
  7325. dbug(1,dprintf("add_b23"));
  7326. api_save_msg(bp, "s", &plci->B_protocol);
  7327. if(!bp->length && plci->tel)
  7328. {
  7329. plci->adv_nl = true;
  7330. dbug(1,dprintf("Default adv.Nl"));
  7331. add_p(plci,LLI,lli);
  7332. plci->B2_prot = 1 /*XPARENT*/;
  7333. plci->B3_prot = 0 /*XPARENT*/;
  7334. llc[1] = 2;
  7335. llc[2] = 4;
  7336. add_p(plci, LLC, llc);
  7337. dlc[0] = 2;
  7338. PUT_WORD(&dlc[1],plci->appl->MaxDataLength);
  7339. add_p(plci, DLC, dlc);
  7340. return 0;
  7341. }
  7342. if(!bp->length) /*default*/
  7343. {
  7344. dbug(1,dprintf("ret default"));
  7345. add_p(plci,LLI,lli);
  7346. plci->B2_prot = 0 /*X.75 */;
  7347. plci->B3_prot = 0 /*XPARENT*/;
  7348. llc[1] = 1;
  7349. llc[2] = 4;
  7350. add_p(plci, LLC, llc);
  7351. dlc[0] = 2;
  7352. PUT_WORD(&dlc[1],plci->appl->MaxDataLength);
  7353. add_p(plci, DLC, dlc);
  7354. return 0;
  7355. }
  7356. dbug(1,dprintf("b_prot_len=%d",(word)bp->length));
  7357. if((word)bp->length > 256) return _WRONG_MESSAGE_FORMAT;
  7358. if(api_parse(&bp->info[1], (word)bp->length, "wwwsssb", bp_parms))
  7359. {
  7360. bp_parms[6].length = 0;
  7361. if(api_parse(&bp->info[1], (word)bp->length, "wwwsss", bp_parms))
  7362. {
  7363. dbug(1,dprintf("b-form.!"));
  7364. return _WRONG_MESSAGE_FORMAT;
  7365. }
  7366. }
  7367. else if (api_parse(&bp->info[1], (word)bp->length, "wwwssss", bp_parms))
  7368. {
  7369. dbug(1,dprintf("b-form.!"));
  7370. return _WRONG_MESSAGE_FORMAT;
  7371. }
  7372. if(plci->tel==ADV_VOICE) /* transparent B on advanced voice */
  7373. {
  7374. if(GET_WORD(bp_parms[1].info)!=1
  7375. || GET_WORD(bp_parms[2].info)!=0) return _B2_NOT_SUPPORTED;
  7376. plci->adv_nl = true;
  7377. }
  7378. else if(plci->tel) return _B2_NOT_SUPPORTED;
  7379. if ((GET_WORD(bp_parms[1].info) == B2_RTP)
  7380. && (GET_WORD(bp_parms[2].info) == B3_RTP)
  7381. && (plci->adapter->man_profile.private_options & (1L << PRIVATE_RTP)))
  7382. {
  7383. add_p(plci,LLI,lli);
  7384. plci->B2_prot = (byte) GET_WORD(bp_parms[1].info);
  7385. plci->B3_prot = (byte) GET_WORD(bp_parms[2].info);
  7386. llc[1] = (plci->call_dir & (CALL_DIR_ORIGINATE | CALL_DIR_FORCE_OUTG_NL)) ? 14 : 13;
  7387. llc[2] = 4;
  7388. add_p(plci, LLC, llc);
  7389. dlc[0] = 2;
  7390. PUT_WORD(&dlc[1],plci->appl->MaxDataLength);
  7391. dlc[3] = 3; /* Addr A */
  7392. dlc[4] = 1; /* Addr B */
  7393. dlc[5] = 7; /* modulo mode */
  7394. dlc[6] = 7; /* window size */
  7395. dlc[7] = 0; /* XID len Lo */
  7396. dlc[8] = 0; /* XID len Hi */
  7397. for (i = 0; i < bp_parms[4].length; i++)
  7398. dlc[9+i] = bp_parms[4].info[1+i];
  7399. dlc[0] = (byte)(8 + bp_parms[4].length);
  7400. add_p(plci, DLC, dlc);
  7401. for (i = 0; i < bp_parms[5].length; i++)
  7402. nlc[1+i] = bp_parms[5].info[1+i];
  7403. nlc[0] = (byte)(bp_parms[5].length);
  7404. add_p(plci, NLC, nlc);
  7405. return 0;
  7406. }
  7407. if ((GET_WORD(bp_parms[1].info) >= 32)
  7408. || (!((1L << GET_WORD(bp_parms[1].info)) & plci->adapter->profile.B2_Protocols)
  7409. && ((GET_WORD(bp_parms[1].info) != B2_PIAFS)
  7410. || !(plci->adapter->man_profile.private_options & (1L << PRIVATE_PIAFS)))))
  7411. {
  7412. return _B2_NOT_SUPPORTED;
  7413. }
  7414. if ((GET_WORD(bp_parms[2].info) >= 32)
  7415. || !((1L << GET_WORD(bp_parms[2].info)) & plci->adapter->profile.B3_Protocols))
  7416. {
  7417. return _B3_NOT_SUPPORTED;
  7418. }
  7419. if ((GET_WORD(bp_parms[1].info) != B2_SDLC)
  7420. && ((GET_WORD(bp_parms[0].info) == B1_MODEM_ALL_NEGOTIATE)
  7421. || (GET_WORD(bp_parms[0].info) == B1_MODEM_ASYNC)
  7422. || (GET_WORD(bp_parms[0].info) == B1_MODEM_SYNC_HDLC)))
  7423. {
  7424. return (add_modem_b23 (plci, bp_parms));
  7425. }
  7426. add_p(plci,LLI,lli);
  7427. plci->B2_prot = (byte) GET_WORD(bp_parms[1].info);
  7428. plci->B3_prot = (byte) GET_WORD(bp_parms[2].info);
  7429. if(plci->B2_prot==12) SAPI = 0; /* default SAPI D-channel */
  7430. if(bp_parms[6].length)
  7431. {
  7432. if(api_parse(&bp_parms[6].info[1], (word)bp_parms[6].length, "w", global_config))
  7433. {
  7434. return _WRONG_MESSAGE_FORMAT;
  7435. }
  7436. switch(GET_WORD(global_config[0].info))
  7437. {
  7438. case 1:
  7439. plci->call_dir = (plci->call_dir & ~CALL_DIR_ANSWER) | CALL_DIR_ORIGINATE;
  7440. break;
  7441. case 2:
  7442. plci->call_dir = (plci->call_dir & ~CALL_DIR_ORIGINATE) | CALL_DIR_ANSWER;
  7443. break;
  7444. }
  7445. }
  7446. dbug(1,dprintf("call_dir=%04x", plci->call_dir));
  7447. if (plci->B2_prot == B2_PIAFS)
  7448. llc[1] = PIAFS_CRC;
  7449. else
  7450. /* IMPLEMENT_PIAFS */
  7451. {
  7452. llc[1] = (plci->call_dir & (CALL_DIR_ORIGINATE | CALL_DIR_FORCE_OUTG_NL)) ?
  7453. llc2_out[GET_WORD(bp_parms[1].info)] : llc2_in[GET_WORD(bp_parms[1].info)];
  7454. }
  7455. llc[2] = llc3[GET_WORD(bp_parms[2].info)];
  7456. add_p(plci, LLC, llc);
  7457. dlc[0] = 2;
  7458. PUT_WORD(&dlc[1], plci->appl->MaxDataLength +
  7459. header[GET_WORD(bp_parms[2].info)]);
  7460. b1_config = &bp_parms[3];
  7461. nlc[0] = 0;
  7462. if(plci->B3_prot == 4
  7463. || plci->B3_prot == 5)
  7464. {
  7465. for (i=0;i<sizeof(T30_INFO);i++) nlc[i] = 0;
  7466. nlc[0] = sizeof(T30_INFO);
  7467. if (plci->adapter->manufacturer_features & MANUFACTURER_FEATURE_FAX_PAPER_FORMATS)
  7468. ((T30_INFO *)&nlc[1])->operating_mode = T30_OPERATING_MODE_CAPI;
  7469. ((T30_INFO *)&nlc[1])->rate_div_2400 = 0xff;
  7470. if(b1_config->length>=2)
  7471. {
  7472. ((T30_INFO *)&nlc[1])->rate_div_2400 = (byte)(GET_WORD(&b1_config->info[1])/2400);
  7473. }
  7474. }
  7475. b2_config = &bp_parms[4];
  7476. if (llc[1] == PIAFS_CRC)
  7477. {
  7478. if (plci->B3_prot != B3_TRANSPARENT)
  7479. {
  7480. return _B_STACK_NOT_SUPPORTED;
  7481. }
  7482. if(b2_config->length && api_parse(&b2_config->info[1], (word)b2_config->length, "bwww", b2_config_parms)) {
  7483. return _WRONG_MESSAGE_FORMAT;
  7484. }
  7485. PUT_WORD(&dlc[1],plci->appl->MaxDataLength);
  7486. dlc[3] = 0; /* Addr A */
  7487. dlc[4] = 0; /* Addr B */
  7488. dlc[5] = 0; /* modulo mode */
  7489. dlc[6] = 0; /* window size */
  7490. if (b2_config->length >= 7){
  7491. dlc[ 7] = 7;
  7492. dlc[ 8] = 0;
  7493. dlc[ 9] = b2_config_parms[0].info[0]; /* PIAFS protocol Speed configuration */
  7494. dlc[10] = b2_config_parms[1].info[0]; /* V.42bis P0 */
  7495. dlc[11] = b2_config_parms[1].info[1]; /* V.42bis P0 */
  7496. dlc[12] = b2_config_parms[2].info[0]; /* V.42bis P1 */
  7497. dlc[13] = b2_config_parms[2].info[1]; /* V.42bis P1 */
  7498. dlc[14] = b2_config_parms[3].info[0]; /* V.42bis P2 */
  7499. dlc[15] = b2_config_parms[3].info[1]; /* V.42bis P2 */
  7500. dlc[ 0] = 15;
  7501. if(b2_config->length >= 8) { /* PIAFS control abilities */
  7502. dlc[ 7] = 10;
  7503. dlc[16] = 2; /* Length of PIAFS extention */
  7504. dlc[17] = PIAFS_UDATA_ABILITIES; /* control (UDATA) ability */
  7505. dlc[18] = b2_config_parms[4].info[0]; /* value */
  7506. dlc[ 0] = 18;
  7507. }
  7508. }
  7509. else /* default values, 64K, variable, no compression */
  7510. {
  7511. dlc[ 7] = 7;
  7512. dlc[ 8] = 0;
  7513. dlc[ 9] = 0x03; /* PIAFS protocol Speed configuration */
  7514. dlc[10] = 0x03; /* V.42bis P0 */
  7515. dlc[11] = 0; /* V.42bis P0 */
  7516. dlc[12] = 0; /* V.42bis P1 */
  7517. dlc[13] = 0; /* V.42bis P1 */
  7518. dlc[14] = 0; /* V.42bis P2 */
  7519. dlc[15] = 0; /* V.42bis P2 */
  7520. dlc[ 0] = 15;
  7521. }
  7522. add_p(plci, DLC, dlc);
  7523. }
  7524. else
  7525. if ((llc[1] == V120_L2) || (llc[1] == V120_V42BIS))
  7526. {
  7527. if (plci->B3_prot != B3_TRANSPARENT)
  7528. return _B_STACK_NOT_SUPPORTED;
  7529. dlc[0] = 6;
  7530. PUT_WORD (&dlc[1], GET_WORD (&dlc[1]) + 2);
  7531. dlc[3] = 0x08;
  7532. dlc[4] = 0x01;
  7533. dlc[5] = 127;
  7534. dlc[6] = 7;
  7535. if (b2_config->length != 0)
  7536. {
  7537. if((llc[1]==V120_V42BIS) && api_parse(&b2_config->info[1], (word)b2_config->length, "bbbbwww", b2_config_parms)) {
  7538. return _WRONG_MESSAGE_FORMAT;
  7539. }
  7540. dlc[3] = (byte)((b2_config->info[2] << 3) | ((b2_config->info[1] >> 5) & 0x04));
  7541. dlc[4] = (byte)((b2_config->info[1] << 1) | 0x01);
  7542. if (b2_config->info[3] != 128)
  7543. {
  7544. dbug(1,dprintf("1D-dlc= %x %x %x %x %x", dlc[0], dlc[1], dlc[2], dlc[3], dlc[4]));
  7545. return _B2_PARM_NOT_SUPPORTED;
  7546. }
  7547. dlc[5] = (byte)(b2_config->info[3] - 1);
  7548. dlc[6] = b2_config->info[4];
  7549. if(llc[1]==V120_V42BIS){
  7550. if (b2_config->length >= 10){
  7551. dlc[ 7] = 6;
  7552. dlc[ 8] = 0;
  7553. dlc[ 9] = b2_config_parms[4].info[0];
  7554. dlc[10] = b2_config_parms[4].info[1];
  7555. dlc[11] = b2_config_parms[5].info[0];
  7556. dlc[12] = b2_config_parms[5].info[1];
  7557. dlc[13] = b2_config_parms[6].info[0];
  7558. dlc[14] = b2_config_parms[6].info[1];
  7559. dlc[ 0] = 14;
  7560. dbug(1,dprintf("b2_config_parms[4].info[0] [1]: %x %x", b2_config_parms[4].info[0], b2_config_parms[4].info[1]));
  7561. dbug(1,dprintf("b2_config_parms[5].info[0] [1]: %x %x", b2_config_parms[5].info[0], b2_config_parms[5].info[1]));
  7562. dbug(1,dprintf("b2_config_parms[6].info[0] [1]: %x %x", b2_config_parms[6].info[0], b2_config_parms[6].info[1]));
  7563. }
  7564. else {
  7565. dlc[ 6] = 14;
  7566. }
  7567. }
  7568. }
  7569. }
  7570. else
  7571. {
  7572. if(b2_config->length)
  7573. {
  7574. dbug(1,dprintf("B2-Config"));
  7575. if(llc[1]==X75_V42BIS){
  7576. if(api_parse(&b2_config->info[1], (word)b2_config->length, "bbbbwww", b2_config_parms))
  7577. {
  7578. return _WRONG_MESSAGE_FORMAT;
  7579. }
  7580. }
  7581. else {
  7582. if(api_parse(&b2_config->info[1], (word)b2_config->length, "bbbbs", b2_config_parms))
  7583. {
  7584. return _WRONG_MESSAGE_FORMAT;
  7585. }
  7586. }
  7587. /* if B2 Protocol is LAPD, b2_config structure is different */
  7588. if(llc[1]==6)
  7589. {
  7590. dlc[0] = 4;
  7591. if(b2_config->length>=1) dlc[2] = b2_config->info[1]; /* TEI */
  7592. else dlc[2] = 0x01;
  7593. if( (b2_config->length>=2) && (plci->B2_prot==12) )
  7594. {
  7595. SAPI = b2_config->info[2]; /* SAPI */
  7596. }
  7597. dlc[1] = SAPI;
  7598. if( (b2_config->length>=3) && (b2_config->info[3]==128) )
  7599. {
  7600. dlc[3] = 127; /* Mode */
  7601. }
  7602. else
  7603. {
  7604. dlc[3] = 7; /* Mode */
  7605. }
  7606. if(b2_config->length>=4) dlc[4] = b2_config->info[4]; /* Window */
  7607. else dlc[4] = 1;
  7608. dbug(1,dprintf("D-dlc[%d]=%x,%x,%x,%x", dlc[0], dlc[1], dlc[2], dlc[3], dlc[4]));
  7609. if(b2_config->length>5) return _B2_PARM_NOT_SUPPORTED;
  7610. }
  7611. else
  7612. {
  7613. dlc[0] = (byte)(b2_config_parms[4].length+6);
  7614. dlc[3] = b2_config->info[1];
  7615. dlc[4] = b2_config->info[2];
  7616. if(b2_config->info[3]!=8 && b2_config->info[3]!=128){
  7617. dbug(1,dprintf("1D-dlc= %x %x %x %x %x", dlc[0], dlc[1], dlc[2], dlc[3], dlc[4]));
  7618. return _B2_PARM_NOT_SUPPORTED;
  7619. }
  7620. dlc[5] = (byte)(b2_config->info[3]-1);
  7621. dlc[6] = b2_config->info[4];
  7622. if(dlc[6]>dlc[5]){
  7623. 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]));
  7624. return _B2_PARM_NOT_SUPPORTED;
  7625. }
  7626. if(llc[1]==X75_V42BIS) {
  7627. if (b2_config->length >= 10){
  7628. dlc[ 7] = 6;
  7629. dlc[ 8] = 0;
  7630. dlc[ 9] = b2_config_parms[4].info[0];
  7631. dlc[10] = b2_config_parms[4].info[1];
  7632. dlc[11] = b2_config_parms[5].info[0];
  7633. dlc[12] = b2_config_parms[5].info[1];
  7634. dlc[13] = b2_config_parms[6].info[0];
  7635. dlc[14] = b2_config_parms[6].info[1];
  7636. dlc[ 0] = 14;
  7637. dbug(1,dprintf("b2_config_parms[4].info[0] [1]: %x %x", b2_config_parms[4].info[0], b2_config_parms[4].info[1]));
  7638. dbug(1,dprintf("b2_config_parms[5].info[0] [1]: %x %x", b2_config_parms[5].info[0], b2_config_parms[5].info[1]));
  7639. dbug(1,dprintf("b2_config_parms[6].info[0] [1]: %x %x", b2_config_parms[6].info[0], b2_config_parms[6].info[1]));
  7640. }
  7641. else {
  7642. dlc[ 6] = 14;
  7643. }
  7644. }
  7645. else {
  7646. PUT_WORD(&dlc[7], (word)b2_config_parms[4].length);
  7647. for(i=0; i<b2_config_parms[4].length; i++)
  7648. dlc[11+i] = b2_config_parms[4].info[1+i];
  7649. }
  7650. }
  7651. }
  7652. }
  7653. add_p(plci, DLC, dlc);
  7654. b3_config = &bp_parms[5];
  7655. if(b3_config->length)
  7656. {
  7657. if(plci->B3_prot == 4
  7658. || plci->B3_prot == 5)
  7659. {
  7660. if(api_parse(&b3_config->info[1], (word)b3_config->length, "wwss", b3_config_parms))
  7661. {
  7662. return _WRONG_MESSAGE_FORMAT;
  7663. }
  7664. i = GET_WORD((byte *)(b3_config_parms[0].info));
  7665. ((T30_INFO *)&nlc[1])->resolution = (byte)(((i & 0x0001) ||
  7666. ((plci->B3_prot == 4) && (((byte)(GET_WORD((byte *)b3_config_parms[1].info))) != 5))) ? T30_RESOLUTION_R8_0770_OR_200 : 0);
  7667. ((T30_INFO *)&nlc[1])->data_format = (byte)(GET_WORD((byte *)b3_config_parms[1].info));
  7668. fax_control_bits = T30_CONTROL_BIT_ALL_FEATURES;
  7669. if ((((T30_INFO *)&nlc[1])->rate_div_2400 != 0) && (((T30_INFO *)&nlc[1])->rate_div_2400 <= 6))
  7670. fax_control_bits &= ~T30_CONTROL_BIT_ENABLE_V34FAX;
  7671. if (plci->adapter->manufacturer_features & MANUFACTURER_FEATURE_FAX_PAPER_FORMATS)
  7672. {
  7673. if ((plci->requested_options_conn | plci->requested_options | plci->adapter->requested_options_table[plci->appl->Id-1])
  7674. & (1L << PRIVATE_FAX_PAPER_FORMATS))
  7675. {
  7676. ((T30_INFO *)&nlc[1])->resolution |= T30_RESOLUTION_R8_1540 |
  7677. T30_RESOLUTION_R16_1540_OR_400 | T30_RESOLUTION_300_300 |
  7678. T30_RESOLUTION_INCH_BASED | T30_RESOLUTION_METRIC_BASED;
  7679. }
  7680. ((T30_INFO *)&nlc[1])->recording_properties =
  7681. T30_RECORDING_WIDTH_ISO_A3 |
  7682. (T30_RECORDING_LENGTH_UNLIMITED << 2) |
  7683. (T30_MIN_SCANLINE_TIME_00_00_00 << 4);
  7684. }
  7685. if(plci->B3_prot == 5)
  7686. {
  7687. if (i & 0x0002) /* Accept incoming fax-polling requests */
  7688. fax_control_bits |= T30_CONTROL_BIT_ACCEPT_POLLING;
  7689. if (i & 0x2000) /* Do not use MR compression */
  7690. fax_control_bits &= ~T30_CONTROL_BIT_ENABLE_2D_CODING;
  7691. if (i & 0x4000) /* Do not use MMR compression */
  7692. fax_control_bits &= ~T30_CONTROL_BIT_ENABLE_T6_CODING;
  7693. if (i & 0x8000) /* Do not use ECM */
  7694. fax_control_bits &= ~T30_CONTROL_BIT_ENABLE_ECM;
  7695. if (plci->fax_connect_info_length != 0)
  7696. {
  7697. ((T30_INFO *)&nlc[1])->resolution = ((T30_INFO *)plci->fax_connect_info_buffer)->resolution;
  7698. ((T30_INFO *)&nlc[1])->data_format = ((T30_INFO *)plci->fax_connect_info_buffer)->data_format;
  7699. ((T30_INFO *)&nlc[1])->recording_properties = ((T30_INFO *)plci->fax_connect_info_buffer)->recording_properties;
  7700. fax_control_bits |= GET_WORD(&((T30_INFO *)plci->fax_connect_info_buffer)->control_bits_low) &
  7701. (T30_CONTROL_BIT_REQUEST_POLLING | T30_CONTROL_BIT_MORE_DOCUMENTS);
  7702. }
  7703. }
  7704. /* copy station id to NLC */
  7705. for(i=0; i<20; i++)
  7706. {
  7707. if(i<b3_config_parms[2].length)
  7708. {
  7709. ((T30_INFO *)&nlc[1])->station_id[i] = ((byte *)b3_config_parms[2].info)[1+i];
  7710. }
  7711. else
  7712. {
  7713. ((T30_INFO *)&nlc[1])->station_id[i] = ' ';
  7714. }
  7715. }
  7716. ((T30_INFO *)&nlc[1])->station_id_len = 20;
  7717. /* copy head line to NLC */
  7718. if(b3_config_parms[3].length)
  7719. {
  7720. pos = (byte)(fax_head_line_time (&(((T30_INFO *)&nlc[1])->station_id[20])));
  7721. if (pos != 0)
  7722. {
  7723. if (CAPI_MAX_DATE_TIME_LENGTH + 2 + b3_config_parms[3].length > CAPI_MAX_HEAD_LINE_SPACE)
  7724. pos = 0;
  7725. else
  7726. {
  7727. ((T30_INFO *)&nlc[1])->station_id[20 + pos++] = ' ';
  7728. ((T30_INFO *)&nlc[1])->station_id[20 + pos++] = ' ';
  7729. len = (byte)b3_config_parms[2].length;
  7730. if (len > 20)
  7731. len = 20;
  7732. if (CAPI_MAX_DATE_TIME_LENGTH + 2 + len + 2 + b3_config_parms[3].length <= CAPI_MAX_HEAD_LINE_SPACE)
  7733. {
  7734. for (i = 0; i < len; i++)
  7735. ((T30_INFO *)&nlc[1])->station_id[20 + pos++] = ((byte *)b3_config_parms[2].info)[1+i];
  7736. ((T30_INFO *)&nlc[1])->station_id[20 + pos++] = ' ';
  7737. ((T30_INFO *)&nlc[1])->station_id[20 + pos++] = ' ';
  7738. }
  7739. }
  7740. }
  7741. len = (byte)b3_config_parms[3].length;
  7742. if (len > CAPI_MAX_HEAD_LINE_SPACE - pos)
  7743. len = (byte)(CAPI_MAX_HEAD_LINE_SPACE - pos);
  7744. ((T30_INFO *)&nlc[1])->head_line_len = (byte)(pos + len);
  7745. nlc[0] += (byte)(pos + len);
  7746. for (i = 0; i < len; i++)
  7747. ((T30_INFO *)&nlc[1])->station_id[20 + pos++] = ((byte *)b3_config_parms[3].info)[1+i];
  7748. }
  7749. else
  7750. ((T30_INFO *)&nlc[1])->head_line_len = 0;
  7751. plci->nsf_control_bits = 0;
  7752. if(plci->B3_prot == 5)
  7753. {
  7754. if ((plci->adapter->man_profile.private_options & (1L << PRIVATE_FAX_SUB_SEP_PWD))
  7755. && (GET_WORD((byte *)b3_config_parms[1].info) & 0x8000)) /* Private SUB/SEP/PWD enable */
  7756. {
  7757. plci->requested_options |= 1L << PRIVATE_FAX_SUB_SEP_PWD;
  7758. }
  7759. if ((plci->adapter->man_profile.private_options & (1L << PRIVATE_FAX_NONSTANDARD))
  7760. && (GET_WORD((byte *)b3_config_parms[1].info) & 0x4000)) /* Private non-standard facilities enable */
  7761. {
  7762. plci->requested_options |= 1L << PRIVATE_FAX_NONSTANDARD;
  7763. }
  7764. if ((plci->requested_options_conn | plci->requested_options | plci->adapter->requested_options_table[plci->appl->Id-1])
  7765. & ((1L << PRIVATE_FAX_SUB_SEP_PWD) | (1L << PRIVATE_FAX_NONSTANDARD)))
  7766. {
  7767. if ((plci->requested_options_conn | plci->requested_options | plci->adapter->requested_options_table[plci->appl->Id-1])
  7768. & (1L << PRIVATE_FAX_SUB_SEP_PWD))
  7769. {
  7770. fax_control_bits |= T30_CONTROL_BIT_ACCEPT_SUBADDRESS | T30_CONTROL_BIT_ACCEPT_PASSWORD;
  7771. if (fax_control_bits & T30_CONTROL_BIT_ACCEPT_POLLING)
  7772. fax_control_bits |= T30_CONTROL_BIT_ACCEPT_SEL_POLLING;
  7773. }
  7774. len = nlc[0];
  7775. pos = offsetof(T30_INFO, station_id) + 20;
  7776. if (pos < plci->fax_connect_info_length)
  7777. {
  7778. for (i = 1 + plci->fax_connect_info_buffer[pos]; i != 0; i--)
  7779. nlc[++len] = plci->fax_connect_info_buffer[pos++];
  7780. }
  7781. else
  7782. nlc[++len] = 0;
  7783. if (pos < plci->fax_connect_info_length)
  7784. {
  7785. for (i = 1 + plci->fax_connect_info_buffer[pos]; i != 0; i--)
  7786. nlc[++len] = plci->fax_connect_info_buffer[pos++];
  7787. }
  7788. else
  7789. nlc[++len] = 0;
  7790. if ((plci->requested_options_conn | plci->requested_options | plci->adapter->requested_options_table[plci->appl->Id-1])
  7791. & (1L << PRIVATE_FAX_NONSTANDARD))
  7792. {
  7793. if ((pos < plci->fax_connect_info_length) && (plci->fax_connect_info_buffer[pos] != 0))
  7794. {
  7795. if ((plci->fax_connect_info_buffer[pos] >= 3) && (plci->fax_connect_info_buffer[pos+1] >= 2))
  7796. plci->nsf_control_bits = GET_WORD(&plci->fax_connect_info_buffer[pos+2]);
  7797. for (i = 1 + plci->fax_connect_info_buffer[pos]; i != 0; i--)
  7798. nlc[++len] = plci->fax_connect_info_buffer[pos++];
  7799. }
  7800. else
  7801. {
  7802. if(api_parse(&b3_config->info[1], (word)b3_config->length, "wwsss", b3_config_parms))
  7803. {
  7804. dbug(1,dprintf("non-standard facilities info missing or wrong format"));
  7805. nlc[++len] = 0;
  7806. }
  7807. else
  7808. {
  7809. if ((b3_config_parms[4].length >= 3) && (b3_config_parms[4].info[1] >= 2))
  7810. plci->nsf_control_bits = GET_WORD(&b3_config_parms[4].info[2]);
  7811. nlc[++len] = (byte)(b3_config_parms[4].length);
  7812. for (i = 0; i < b3_config_parms[4].length; i++)
  7813. nlc[++len] = b3_config_parms[4].info[1+i];
  7814. }
  7815. }
  7816. }
  7817. nlc[0] = len;
  7818. if ((plci->nsf_control_bits & T30_NSF_CONTROL_BIT_ENABLE_NSF)
  7819. && (plci->nsf_control_bits & T30_NSF_CONTROL_BIT_NEGOTIATE_RESP))
  7820. {
  7821. ((T30_INFO *)&nlc[1])->operating_mode = T30_OPERATING_MODE_CAPI_NEG;
  7822. }
  7823. }
  7824. }
  7825. PUT_WORD(&(((T30_INFO *)&nlc[1])->control_bits_low), fax_control_bits);
  7826. len = offsetof(T30_INFO, station_id) + 20;
  7827. for (i = 0; i < len; i++)
  7828. plci->fax_connect_info_buffer[i] = nlc[1+i];
  7829. ((T30_INFO *) plci->fax_connect_info_buffer)->head_line_len = 0;
  7830. i += ((T30_INFO *)&nlc[1])->head_line_len;
  7831. while (i < nlc[0])
  7832. plci->fax_connect_info_buffer[len++] = nlc[++i];
  7833. plci->fax_connect_info_length = len;
  7834. }
  7835. else
  7836. {
  7837. nlc[0] = 14;
  7838. if(b3_config->length!=16)
  7839. return _B3_PARM_NOT_SUPPORTED;
  7840. for(i=0; i<12; i++) nlc[1+i] = b3_config->info[1+i];
  7841. if(GET_WORD(&b3_config->info[13])!=8 && GET_WORD(&b3_config->info[13])!=128)
  7842. return _B3_PARM_NOT_SUPPORTED;
  7843. nlc[13] = b3_config->info[13];
  7844. if(GET_WORD(&b3_config->info[15])>=nlc[13])
  7845. return _B3_PARM_NOT_SUPPORTED;
  7846. nlc[14] = b3_config->info[15];
  7847. }
  7848. }
  7849. else
  7850. {
  7851. if (plci->B3_prot == 4
  7852. || plci->B3_prot == 5 /*T.30 - FAX*/ ) return _B3_PARM_NOT_SUPPORTED;
  7853. }
  7854. add_p(plci, NLC, nlc);
  7855. return 0;
  7856. }
  7857. /*----------------------------------------------------------------*/
  7858. /* make the same as add_b23, but only for the modem related */
  7859. /* L2 and L3 B-Chan protocol. */
  7860. /* */
  7861. /* Enabled L2 and L3 Configurations: */
  7862. /* If L1 == Modem all negotiation */
  7863. /* only L2 == Modem with full negotiation is allowed */
  7864. /* If L1 == Modem async or sync */
  7865. /* only L2 == Transparent is allowed */
  7866. /* L3 == Modem or L3 == Transparent are allowed */
  7867. /* B2 Configuration for modem: */
  7868. /* word : enable/disable compression, bitoptions */
  7869. /* B3 Configuration for modem: */
  7870. /* empty */
  7871. /*----------------------------------------------------------------*/
  7872. static word add_modem_b23 (PLCI * plci, API_PARSE* bp_parms)
  7873. {
  7874. static byte lli[12] = {1,1};
  7875. static byte llc[3] = {2,0,0};
  7876. static byte dlc[16] = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
  7877. API_PARSE mdm_config[2];
  7878. word i;
  7879. word b2_config = 0;
  7880. for(i=0;i<2;i++) mdm_config[i].length = 0;
  7881. for(i=0;i<sizeof(dlc);i++) dlc[i] = 0;
  7882. if (((GET_WORD(bp_parms[0].info) == B1_MODEM_ALL_NEGOTIATE)
  7883. && (GET_WORD(bp_parms[1].info) != B2_MODEM_EC_COMPRESSION))
  7884. || ((GET_WORD(bp_parms[0].info) != B1_MODEM_ALL_NEGOTIATE)
  7885. && (GET_WORD(bp_parms[1].info) != B2_TRANSPARENT)))
  7886. {
  7887. return (_B_STACK_NOT_SUPPORTED);
  7888. }
  7889. if ((GET_WORD(bp_parms[2].info) != B3_MODEM)
  7890. && (GET_WORD(bp_parms[2].info) != B3_TRANSPARENT))
  7891. {
  7892. return (_B_STACK_NOT_SUPPORTED);
  7893. }
  7894. plci->B2_prot = (byte) GET_WORD(bp_parms[1].info);
  7895. plci->B3_prot = (byte) GET_WORD(bp_parms[2].info);
  7896. if ((GET_WORD(bp_parms[1].info) == B2_MODEM_EC_COMPRESSION) && bp_parms[4].length)
  7897. {
  7898. if (api_parse (&bp_parms[4].info[1],
  7899. (word)bp_parms[4].length, "w",
  7900. mdm_config))
  7901. {
  7902. return (_WRONG_MESSAGE_FORMAT);
  7903. }
  7904. b2_config = GET_WORD(mdm_config[0].info);
  7905. }
  7906. /* OK, L2 is modem */
  7907. lli[0] = 1;
  7908. lli[1] = 1;
  7909. if (plci->adapter->manufacturer_features & MANUFACTURER_FEATURE_XONOFF_FLOW_CONTROL)
  7910. lli[1] |= 2;
  7911. if (plci->adapter->manufacturer_features & MANUFACTURER_FEATURE_OOB_CHANNEL)
  7912. lli[1] |= 4;
  7913. if ((lli[1] & 0x02) && (diva_xdi_extended_features & DIVA_CAPI_USE_CMA)) {
  7914. lli[1] |= 0x10;
  7915. if (plci->rx_dma_descriptor <= 0) {
  7916. plci->rx_dma_descriptor=diva_get_dma_descriptor(plci,&plci->rx_dma_magic);
  7917. if (plci->rx_dma_descriptor >= 0)
  7918. plci->rx_dma_descriptor++;
  7919. }
  7920. if (plci->rx_dma_descriptor > 0) {
  7921. lli[1] |= 0x40;
  7922. lli[0] = 6;
  7923. lli[2] = (byte)(plci->rx_dma_descriptor - 1);
  7924. lli[3] = (byte)plci->rx_dma_magic;
  7925. lli[4] = (byte)(plci->rx_dma_magic >> 8);
  7926. lli[5] = (byte)(plci->rx_dma_magic >> 16);
  7927. lli[6] = (byte)(plci->rx_dma_magic >> 24);
  7928. }
  7929. }
  7930. if (DIVA_CAPI_SUPPORTS_NO_CANCEL(plci->adapter)) {
  7931. lli[1] |= 0x20;
  7932. }
  7933. llc[1] = (plci->call_dir & (CALL_DIR_ORIGINATE | CALL_DIR_FORCE_OUTG_NL)) ?
  7934. /*V42*/ 10 : /*V42_IN*/ 9;
  7935. llc[2] = 4; /* pass L3 always transparent */
  7936. add_p(plci, LLI, lli);
  7937. add_p(plci, LLC, llc);
  7938. i = 1;
  7939. PUT_WORD (&dlc[i], plci->appl->MaxDataLength);
  7940. i += 2;
  7941. if (GET_WORD(bp_parms[1].info) == B2_MODEM_EC_COMPRESSION)
  7942. {
  7943. if (bp_parms[4].length)
  7944. {
  7945. dbug(1, dprintf("MDM b2_config=%02x", b2_config));
  7946. dlc[i++] = 3; /* Addr A */
  7947. dlc[i++] = 1; /* Addr B */
  7948. dlc[i++] = 7; /* modulo mode */
  7949. dlc[i++] = 7; /* window size */
  7950. dlc[i++] = 0; /* XID len Lo */
  7951. dlc[i++] = 0; /* XID len Hi */
  7952. if (b2_config & MDM_B2_DISABLE_V42bis)
  7953. {
  7954. dlc[i] |= DLC_MODEMPROT_DISABLE_V42_V42BIS;
  7955. }
  7956. if (b2_config & MDM_B2_DISABLE_MNP)
  7957. {
  7958. dlc[i] |= DLC_MODEMPROT_DISABLE_MNP_MNP5;
  7959. }
  7960. if (b2_config & MDM_B2_DISABLE_TRANS)
  7961. {
  7962. dlc[i] |= DLC_MODEMPROT_REQUIRE_PROTOCOL;
  7963. }
  7964. if (b2_config & MDM_B2_DISABLE_V42)
  7965. {
  7966. dlc[i] |= DLC_MODEMPROT_DISABLE_V42_DETECT;
  7967. }
  7968. if (b2_config & MDM_B2_DISABLE_COMP)
  7969. {
  7970. dlc[i] |= DLC_MODEMPROT_DISABLE_COMPRESSION;
  7971. }
  7972. i++;
  7973. }
  7974. }
  7975. else
  7976. {
  7977. dlc[i++] = 3; /* Addr A */
  7978. dlc[i++] = 1; /* Addr B */
  7979. dlc[i++] = 7; /* modulo mode */
  7980. dlc[i++] = 7; /* window size */
  7981. dlc[i++] = 0; /* XID len Lo */
  7982. dlc[i++] = 0; /* XID len Hi */
  7983. dlc[i++] = DLC_MODEMPROT_DISABLE_V42_V42BIS |
  7984. DLC_MODEMPROT_DISABLE_MNP_MNP5 |
  7985. DLC_MODEMPROT_DISABLE_V42_DETECT |
  7986. DLC_MODEMPROT_DISABLE_COMPRESSION;
  7987. }
  7988. dlc[0] = (byte)(i - 1);
  7989. /* HexDump ("DLC", sizeof(dlc), &dlc[0]); */
  7990. add_p(plci, DLC, dlc);
  7991. return (0);
  7992. }
  7993. /*------------------------------------------------------------------*/
  7994. /* send a request for the signaling entity */
  7995. /*------------------------------------------------------------------*/
  7996. static void sig_req(PLCI *plci, byte req, byte Id)
  7997. {
  7998. if(!plci) return;
  7999. if(plci->adapter->adapter_disabled) return;
  8000. dbug(1,dprintf("sig_req(%x)",req));
  8001. if (req == REMOVE)
  8002. plci->sig_remove_id = plci->Sig.Id;
  8003. if(plci->req_in==plci->req_in_start) {
  8004. plci->req_in +=2;
  8005. plci->RBuffer[plci->req_in++] = 0;
  8006. }
  8007. PUT_WORD(&plci->RBuffer[plci->req_in_start], plci->req_in-plci->req_in_start-2);
  8008. plci->RBuffer[plci->req_in++] = Id; /* sig/nl flag */
  8009. plci->RBuffer[plci->req_in++] = req; /* request */
  8010. plci->RBuffer[plci->req_in++] = 0; /* channel */
  8011. plci->req_in_start = plci->req_in;
  8012. }
  8013. /*------------------------------------------------------------------*/
  8014. /* send a request for the network layer entity */
  8015. /*------------------------------------------------------------------*/
  8016. static void nl_req_ncci(PLCI *plci, byte req, byte ncci)
  8017. {
  8018. if(!plci) return;
  8019. if(plci->adapter->adapter_disabled) return;
  8020. dbug(1,dprintf("nl_req %02x %02x %02x", plci->Id, req, ncci));
  8021. if (req == REMOVE)
  8022. {
  8023. plci->nl_remove_id = plci->NL.Id;
  8024. ncci_remove (plci, 0, (byte)(ncci != 0));
  8025. ncci = 0;
  8026. }
  8027. if(plci->req_in==plci->req_in_start) {
  8028. plci->req_in +=2;
  8029. plci->RBuffer[plci->req_in++] = 0;
  8030. }
  8031. PUT_WORD(&plci->RBuffer[plci->req_in_start], plci->req_in-plci->req_in_start-2);
  8032. plci->RBuffer[plci->req_in++] = 1; /* sig/nl flag */
  8033. plci->RBuffer[plci->req_in++] = req; /* request */
  8034. plci->RBuffer[plci->req_in++] = plci->adapter->ncci_ch[ncci]; /* channel */
  8035. plci->req_in_start = plci->req_in;
  8036. }
  8037. static void send_req(PLCI *plci)
  8038. {
  8039. ENTITY * e;
  8040. word l;
  8041. /* word i; */
  8042. if(!plci) return;
  8043. if(plci->adapter->adapter_disabled) return;
  8044. channel_xmit_xon (plci);
  8045. /* if nothing to do, return */
  8046. if(plci->req_in==plci->req_out) return;
  8047. dbug(1,dprintf("send_req(in=%d,out=%d)",plci->req_in,plci->req_out));
  8048. if(plci->nl_req || plci->sig_req) return;
  8049. l = GET_WORD(&plci->RBuffer[plci->req_out]);
  8050. plci->req_out += 2;
  8051. plci->XData[0].P = &plci->RBuffer[plci->req_out];
  8052. plci->req_out += l;
  8053. if(plci->RBuffer[plci->req_out]==1)
  8054. {
  8055. e = &plci->NL;
  8056. plci->req_out++;
  8057. e->Req = plci->nl_req = plci->RBuffer[plci->req_out++];
  8058. e->ReqCh = plci->RBuffer[plci->req_out++];
  8059. if(!(e->Id & 0x1f))
  8060. {
  8061. e->Id = NL_ID;
  8062. plci->RBuffer[plci->req_out-4] = CAI;
  8063. plci->RBuffer[plci->req_out-3] = 1;
  8064. plci->RBuffer[plci->req_out-2] = (plci->Sig.Id==0xff) ? 0 : plci->Sig.Id;
  8065. plci->RBuffer[plci->req_out-1] = 0;
  8066. l+=3;
  8067. plci->nl_global_req = plci->nl_req;
  8068. }
  8069. dbug(1,dprintf("%x:NLREQ(%x:%x:%x)",plci->adapter->Id,e->Id,e->Req,e->ReqCh));
  8070. }
  8071. else
  8072. {
  8073. e = &plci->Sig;
  8074. if(plci->RBuffer[plci->req_out])
  8075. e->Id = plci->RBuffer[plci->req_out];
  8076. plci->req_out++;
  8077. e->Req = plci->sig_req = plci->RBuffer[plci->req_out++];
  8078. e->ReqCh = plci->RBuffer[plci->req_out++];
  8079. if(!(e->Id & 0x1f))
  8080. plci->sig_global_req = plci->sig_req;
  8081. dbug(1,dprintf("%x:SIGREQ(%x:%x:%x)",plci->adapter->Id,e->Id,e->Req,e->ReqCh));
  8082. }
  8083. plci->XData[0].PLength = l;
  8084. e->X = plci->XData;
  8085. plci->adapter->request(e);
  8086. dbug(1,dprintf("send_ok"));
  8087. }
  8088. static void send_data(PLCI *plci)
  8089. {
  8090. DIVA_CAPI_ADAPTER * a;
  8091. DATA_B3_DESC * data;
  8092. NCCI *ncci_ptr;
  8093. word ncci;
  8094. if (!plci->nl_req && plci->ncci_ring_list)
  8095. {
  8096. a = plci->adapter;
  8097. ncci = plci->ncci_ring_list;
  8098. do
  8099. {
  8100. ncci = a->ncci_next[ncci];
  8101. ncci_ptr = &(a->ncci[ncci]);
  8102. if (!(a->ncci_ch[ncci]
  8103. && (a->ch_flow_control[a->ncci_ch[ncci]] & N_OK_FC_PENDING)))
  8104. {
  8105. if (ncci_ptr->data_pending)
  8106. {
  8107. if ((a->ncci_state[ncci] == CONNECTED)
  8108. || (a->ncci_state[ncci] == INC_ACT_PENDING)
  8109. || (plci->send_disc == ncci))
  8110. {
  8111. data = &(ncci_ptr->DBuffer[ncci_ptr->data_out]);
  8112. if ((plci->B2_prot == B2_V120_ASYNC)
  8113. || (plci->B2_prot == B2_V120_ASYNC_V42BIS)
  8114. || (plci->B2_prot == B2_V120_BIT_TRANSPARENT))
  8115. {
  8116. plci->NData[1].P = TransmitBufferGet (plci->appl, data->P);
  8117. plci->NData[1].PLength = data->Length;
  8118. if (data->Flags & 0x10)
  8119. plci->NData[0].P = v120_break_header;
  8120. else
  8121. plci->NData[0].P = v120_default_header;
  8122. plci->NData[0].PLength = 1 ;
  8123. plci->NL.XNum = 2;
  8124. plci->NL.Req = plci->nl_req = (byte)((data->Flags&0x07)<<4 |N_DATA);
  8125. }
  8126. else
  8127. {
  8128. plci->NData[0].P = TransmitBufferGet (plci->appl, data->P);
  8129. plci->NData[0].PLength = data->Length;
  8130. if (data->Flags & 0x10)
  8131. plci->NL.Req = plci->nl_req = (byte)N_UDATA;
  8132. else if ((plci->B3_prot == B3_RTP) && (data->Flags & 0x01))
  8133. plci->NL.Req = plci->nl_req = (byte)N_BDATA;
  8134. else
  8135. plci->NL.Req = plci->nl_req = (byte)((data->Flags&0x07)<<4 |N_DATA);
  8136. }
  8137. plci->NL.X = plci->NData;
  8138. plci->NL.ReqCh = a->ncci_ch[ncci];
  8139. dbug(1,dprintf("%x:DREQ(%x:%x)",a->Id,plci->NL.Id,plci->NL.Req));
  8140. plci->data_sent = true;
  8141. plci->data_sent_ptr = data->P;
  8142. a->request(&plci->NL);
  8143. }
  8144. else {
  8145. cleanup_ncci_data (plci, ncci);
  8146. }
  8147. }
  8148. else if (plci->send_disc == ncci)
  8149. {
  8150. /* dprintf("N_DISC"); */
  8151. plci->NData[0].PLength = 0;
  8152. plci->NL.ReqCh = a->ncci_ch[ncci];
  8153. plci->NL.Req = plci->nl_req = N_DISC;
  8154. a->request(&plci->NL);
  8155. plci->command = _DISCONNECT_B3_R;
  8156. plci->send_disc = 0;
  8157. }
  8158. }
  8159. } while (!plci->nl_req && (ncci != plci->ncci_ring_list));
  8160. plci->ncci_ring_list = ncci;
  8161. }
  8162. }
  8163. static void listen_check(DIVA_CAPI_ADAPTER *a)
  8164. {
  8165. word i,j;
  8166. PLCI * plci;
  8167. byte activnotifiedcalls = 0;
  8168. dbug(1,dprintf("listen_check(%d,%d)",a->listen_active,a->max_listen));
  8169. if (!remove_started && !a->adapter_disabled)
  8170. {
  8171. for(i=0;i<a->max_plci;i++)
  8172. {
  8173. plci = &(a->plci[i]);
  8174. if(plci->notifiedcall) activnotifiedcalls++;
  8175. }
  8176. dbug(1,dprintf("listen_check(%d)",activnotifiedcalls));
  8177. for(i=a->listen_active; i < ((word)(a->max_listen+activnotifiedcalls)); i++) {
  8178. if((j=get_plci(a))) {
  8179. a->listen_active++;
  8180. plci = &a->plci[j-1];
  8181. plci->State = LISTENING;
  8182. add_p(plci,OAD,"\x01\xfd");
  8183. add_p(plci,KEY,"\x04\x43\x41\x32\x30");
  8184. add_p(plci,CAI,"\x01\xc0");
  8185. add_p(plci,UID,"\x06\x43\x61\x70\x69\x32\x30");
  8186. add_p(plci,LLI,"\x01\xc4"); /* support Dummy CR FAC + MWI + SpoofNotify */
  8187. add_p(plci,SHIFT|6,NULL);
  8188. add_p(plci,SIN,"\x02\x00\x00");
  8189. plci->internal_command = LISTEN_SIG_ASSIGN_PEND; /* do indicate_req if OK */
  8190. sig_req(plci,ASSIGN,DSIG_ID);
  8191. send_req(plci);
  8192. }
  8193. }
  8194. }
  8195. }
  8196. /*------------------------------------------------------------------*/
  8197. /* functions for all parameters sent in INDs */
  8198. /*------------------------------------------------------------------*/
  8199. static void IndParse(PLCI *plci, word *parms_id, byte **parms, byte multiIEsize)
  8200. {
  8201. word ploc; /* points to current location within packet */
  8202. byte w;
  8203. byte wlen;
  8204. byte codeset,lock;
  8205. byte * in;
  8206. word i;
  8207. word code;
  8208. word mIEindex = 0;
  8209. ploc = 0;
  8210. codeset = 0;
  8211. lock = 0;
  8212. in = plci->Sig.RBuffer->P;
  8213. for(i=0; i<parms_id[0]; i++) /* multiIE parms_id contains just the 1st */
  8214. { /* element but parms array is larger */
  8215. parms[i] = (byte *)"";
  8216. }
  8217. for(i=0; i<multiIEsize; i++)
  8218. {
  8219. parms[i] = (byte *)"";
  8220. }
  8221. while(ploc<plci->Sig.RBuffer->length-1) {
  8222. /* read information element id and length */
  8223. w = in[ploc];
  8224. if(w & 0x80) {
  8225. /* w &=0xf0; removed, cannot detect congestion levels */
  8226. /* upper 4 bit masked with w==SHIFT now */
  8227. wlen = 0;
  8228. }
  8229. else {
  8230. wlen = (byte)(in[ploc+1]+1);
  8231. }
  8232. /* check if length valid (not exceeding end of packet) */
  8233. if((ploc+wlen) > 270) return ;
  8234. if(lock & 0x80) lock &=0x7f;
  8235. else codeset = lock;
  8236. if((w&0xf0)==SHIFT) {
  8237. codeset = in[ploc];
  8238. if(!(codeset & 0x08)) lock = (byte)(codeset & 7);
  8239. codeset &=7;
  8240. lock |=0x80;
  8241. }
  8242. else {
  8243. if(w==ESC && wlen>=3) code = in[ploc+2] |0x800;
  8244. else code = w;
  8245. code |= (codeset<<8);
  8246. for(i=1; i<parms_id[0]+1 && parms_id[i]!=code; i++);
  8247. if(i<parms_id[0]+1) {
  8248. if(!multiIEsize) { /* with multiIEs use next field index, */
  8249. mIEindex = i-1; /* with normal IEs use same index like parms_id */
  8250. }
  8251. parms[mIEindex] = &in[ploc+1];
  8252. dbug(1,dprintf("mIE[%d]=0x%x",*parms[mIEindex],in[ploc]));
  8253. if(parms_id[i]==OAD
  8254. || parms_id[i]==CONN_NR
  8255. || parms_id[i]==CAD) {
  8256. if(in[ploc+2] &0x80) {
  8257. in[ploc+0] = (byte)(in[ploc+1]+1);
  8258. in[ploc+1] = (byte)(in[ploc+2] &0x7f);
  8259. in[ploc+2] = 0x80;
  8260. parms[mIEindex] = &in[ploc];
  8261. }
  8262. }
  8263. mIEindex++; /* effects multiIEs only */
  8264. }
  8265. }
  8266. ploc +=(wlen+1);
  8267. }
  8268. return ;
  8269. }
  8270. /*------------------------------------------------------------------*/
  8271. /* try to match a cip from received BC and HLC */
  8272. /*------------------------------------------------------------------*/
  8273. static byte ie_compare(byte *ie1, byte *ie2)
  8274. {
  8275. word i;
  8276. if(!ie1 || ! ie2) return false;
  8277. if(!ie1[0]) return false;
  8278. for(i=0;i<(word)(ie1[0]+1);i++) if(ie1[i]!=ie2[i]) return false;
  8279. return true;
  8280. }
  8281. static word find_cip(DIVA_CAPI_ADAPTER *a, byte *bc, byte *hlc)
  8282. {
  8283. word i;
  8284. word j;
  8285. for(i=9;i && !ie_compare(bc,cip_bc[i][a->u_law]);i--);
  8286. for(j=16;j<29 &&
  8287. (!ie_compare(bc,cip_bc[j][a->u_law]) || !ie_compare(hlc,cip_hlc[j])); j++);
  8288. if(j==29) return i;
  8289. return j;
  8290. }
  8291. static byte AddInfo(byte **add_i,
  8292. byte **fty_i,
  8293. byte *esc_chi,
  8294. byte *facility)
  8295. {
  8296. byte i;
  8297. byte j;
  8298. byte k;
  8299. byte flen;
  8300. byte len=0;
  8301. /* facility is a nested structure */
  8302. /* FTY can be more than once */
  8303. if (esc_chi[0] && !(esc_chi[esc_chi[0]] & 0x7f))
  8304. {
  8305. add_i[0] = (byte *)"\x02\x02\x00"; /* use neither b nor d channel */
  8306. }
  8307. else
  8308. {
  8309. add_i[0] = (byte *)"";
  8310. }
  8311. if(!fty_i[0][0])
  8312. {
  8313. add_i[3] = (byte *)"";
  8314. }
  8315. else
  8316. { /* facility array found */
  8317. for(i=0,j=1;i<MAX_MULTI_IE && fty_i[i][0];i++)
  8318. {
  8319. dbug(1,dprintf("AddIFac[%d]",fty_i[i][0]));
  8320. len += fty_i[i][0];
  8321. len += 2;
  8322. flen=fty_i[i][0];
  8323. facility[j++]=0x1c; /* copy fac IE */
  8324. for(k=0;k<=flen;k++,j++)
  8325. {
  8326. facility[j]=fty_i[i][k];
  8327. /* dbug(1,dprintf("%x ",facility[j])); */
  8328. }
  8329. }
  8330. facility[0] = len;
  8331. add_i[3] = facility;
  8332. }
  8333. /* dbug(1,dprintf("FacArrLen=%d ",len)); */
  8334. len = add_i[0][0]+add_i[1][0]+add_i[2][0]+add_i[3][0];
  8335. len += 4; /* calculate length of all */
  8336. return(len);
  8337. }
  8338. /*------------------------------------------------------------------*/
  8339. /* voice and codec features */
  8340. /*------------------------------------------------------------------*/
  8341. static void SetVoiceChannel(PLCI *plci, byte *chi, DIVA_CAPI_ADAPTER *a)
  8342. {
  8343. byte voice_chi[] = "\x02\x18\x01";
  8344. byte channel;
  8345. channel = chi[chi[0]]&0x3;
  8346. dbug(1,dprintf("ExtDevON(Ch=0x%x)",channel));
  8347. voice_chi[2] = (channel) ? channel : 1;
  8348. add_p(plci,FTY,"\x02\x01\x07"); /* B On, default on 1 */
  8349. add_p(plci,ESC,voice_chi); /* Channel */
  8350. sig_req(plci,TEL_CTRL,0);
  8351. send_req(plci);
  8352. if(a->AdvSignalPLCI)
  8353. {
  8354. adv_voice_write_coefs (a->AdvSignalPLCI, ADV_VOICE_WRITE_ACTIVATION);
  8355. }
  8356. }
  8357. static void VoiceChannelOff(PLCI *plci)
  8358. {
  8359. dbug(1,dprintf("ExtDevOFF"));
  8360. add_p(plci,FTY,"\x02\x01\x08"); /* B Off */
  8361. sig_req(plci,TEL_CTRL,0);
  8362. send_req(plci);
  8363. if(plci->adapter->AdvSignalPLCI)
  8364. {
  8365. adv_voice_clear_config (plci->adapter->AdvSignalPLCI);
  8366. }
  8367. }
  8368. static word AdvCodecSupport(DIVA_CAPI_ADAPTER *a, PLCI *plci, APPL *appl,
  8369. byte hook_listen)
  8370. {
  8371. word j;
  8372. PLCI *splci;
  8373. /* check if hardware supports handset with hook states (adv.codec) */
  8374. /* or if just a on board codec is supported */
  8375. /* the advanced codec plci is just for internal use */
  8376. /* diva Pro with on-board codec: */
  8377. if(a->profile.Global_Options & HANDSET)
  8378. {
  8379. /* new call, but hook states are already signalled */
  8380. if(a->AdvCodecFLAG)
  8381. {
  8382. if(a->AdvSignalAppl!=appl || a->AdvSignalPLCI)
  8383. {
  8384. dbug(1,dprintf("AdvSigPlci=0x%x",a->AdvSignalPLCI));
  8385. return 0x2001; /* codec in use by another application */
  8386. }
  8387. if(plci!=NULL)
  8388. {
  8389. a->AdvSignalPLCI = plci;
  8390. plci->tel=ADV_VOICE;
  8391. }
  8392. return 0; /* adv codec still used */
  8393. }
  8394. if((j=get_plci(a)))
  8395. {
  8396. splci = &a->plci[j-1];
  8397. splci->tel = CODEC_PERMANENT;
  8398. /* hook_listen indicates if a facility_req with handset/hook support */
  8399. /* was sent. Otherwise if just a call on an external device was made */
  8400. /* the codec will be used but the hook info will be discarded (just */
  8401. /* the external controller is in use */
  8402. if(hook_listen) splci->State = ADVANCED_VOICE_SIG;
  8403. else
  8404. {
  8405. splci->State = ADVANCED_VOICE_NOSIG;
  8406. if(plci)
  8407. {
  8408. plci->spoofed_msg = SPOOFING_REQUIRED;
  8409. }
  8410. /* indicate D-ch connect if */
  8411. } /* codec is connected OK */
  8412. if(plci!=NULL)
  8413. {
  8414. a->AdvSignalPLCI = plci;
  8415. plci->tel=ADV_VOICE;
  8416. }
  8417. a->AdvSignalAppl = appl;
  8418. a->AdvCodecFLAG = true;
  8419. a->AdvCodecPLCI = splci;
  8420. add_p(splci,CAI,"\x01\x15");
  8421. add_p(splci,LLI,"\x01\x00");
  8422. add_p(splci,ESC,"\x02\x18\x00");
  8423. add_p(splci,UID,"\x06\x43\x61\x70\x69\x32\x30");
  8424. splci->internal_command = PERM_COD_ASSIGN;
  8425. dbug(1,dprintf("Codec Assign"));
  8426. sig_req(splci,ASSIGN,DSIG_ID);
  8427. send_req(splci);
  8428. }
  8429. else
  8430. {
  8431. return 0x2001; /* wrong state, no more plcis */
  8432. }
  8433. }
  8434. else if(a->profile.Global_Options & ON_BOARD_CODEC)
  8435. {
  8436. if(hook_listen) return 0x300B; /* Facility not supported */
  8437. /* no hook with SCOM */
  8438. if(plci!=NULL) plci->tel = CODEC;
  8439. dbug(1,dprintf("S/SCOM codec"));
  8440. /* first time we use the scom-s codec we must shut down the internal */
  8441. /* handset application of the card. This can be done by an assign with */
  8442. /* a cai with the 0x80 bit set. Assign return code is 'out of resource'*/
  8443. if(!a->scom_appl_disable){
  8444. if((j=get_plci(a))) {
  8445. splci = &a->plci[j-1];
  8446. add_p(splci,CAI,"\x01\x80");
  8447. add_p(splci,UID,"\x06\x43\x61\x70\x69\x32\x30");
  8448. sig_req(splci,ASSIGN,0xC0); /* 0xc0 is the TEL_ID */
  8449. send_req(splci);
  8450. a->scom_appl_disable = true;
  8451. }
  8452. else{
  8453. return 0x2001; /* wrong state, no more plcis */
  8454. }
  8455. }
  8456. }
  8457. else return 0x300B; /* Facility not supported */
  8458. return 0;
  8459. }
  8460. static void CodecIdCheck(DIVA_CAPI_ADAPTER *a, PLCI *plci)
  8461. {
  8462. dbug(1,dprintf("CodecIdCheck"));
  8463. if(a->AdvSignalPLCI == plci)
  8464. {
  8465. dbug(1,dprintf("PLCI owns codec"));
  8466. VoiceChannelOff(a->AdvCodecPLCI);
  8467. if(a->AdvCodecPLCI->State == ADVANCED_VOICE_NOSIG)
  8468. {
  8469. dbug(1,dprintf("remove temp codec PLCI"));
  8470. plci_remove(a->AdvCodecPLCI);
  8471. a->AdvCodecFLAG = 0;
  8472. a->AdvCodecPLCI = NULL;
  8473. a->AdvSignalAppl = NULL;
  8474. }
  8475. a->AdvSignalPLCI = NULL;
  8476. }
  8477. }
  8478. /* -------------------------------------------------------------------
  8479. Ask for physical address of card on PCI bus
  8480. ------------------------------------------------------------------- */
  8481. static void diva_ask_for_xdi_sdram_bar (DIVA_CAPI_ADAPTER * a,
  8482. IDI_SYNC_REQ * preq) {
  8483. a->sdram_bar = 0;
  8484. if (diva_xdi_extended_features & DIVA_CAPI_XDI_PROVIDES_SDRAM_BAR) {
  8485. ENTITY * e = (ENTITY *)preq;
  8486. e->user[0] = a->Id - 1;
  8487. preq->xdi_sdram_bar.info.bar = 0;
  8488. preq->xdi_sdram_bar.Req = 0;
  8489. preq->xdi_sdram_bar.Rc = IDI_SYNC_REQ_XDI_GET_ADAPTER_SDRAM_BAR;
  8490. (*(a->request))(e);
  8491. a->sdram_bar = preq->xdi_sdram_bar.info.bar;
  8492. dbug(3,dprintf("A(%d) SDRAM BAR = %08x", a->Id, a->sdram_bar));
  8493. }
  8494. }
  8495. /* -------------------------------------------------------------------
  8496. Ask XDI about extended features
  8497. ------------------------------------------------------------------- */
  8498. static void diva_get_extended_adapter_features (DIVA_CAPI_ADAPTER * a) {
  8499. IDI_SYNC_REQ * preq;
  8500. char buffer[ ((sizeof(preq->xdi_extended_features)+4) > sizeof(ENTITY)) ? (sizeof(preq->xdi_extended_features)+4) : sizeof(ENTITY)];
  8501. char features[4];
  8502. preq = (IDI_SYNC_REQ *)&buffer[0];
  8503. if (!diva_xdi_extended_features) {
  8504. ENTITY * e = (ENTITY *)preq;
  8505. diva_xdi_extended_features |= 0x80000000;
  8506. e->user[0] = a->Id - 1;
  8507. preq->xdi_extended_features.Req = 0;
  8508. preq->xdi_extended_features.Rc = IDI_SYNC_REQ_XDI_GET_EXTENDED_FEATURES;
  8509. preq->xdi_extended_features.info.buffer_length_in_bytes = sizeof(features);
  8510. preq->xdi_extended_features.info.features = &features[0];
  8511. (*(a->request))(e);
  8512. if (features[0] & DIVA_XDI_EXTENDED_FEATURES_VALID) {
  8513. /*
  8514. Check features located in the byte '0'
  8515. */
  8516. if (features[0] & DIVA_XDI_EXTENDED_FEATURE_CMA) {
  8517. diva_xdi_extended_features |= DIVA_CAPI_USE_CMA;
  8518. }
  8519. if (features[0] & DIVA_XDI_EXTENDED_FEATURE_RX_DMA) {
  8520. diva_xdi_extended_features |= DIVA_CAPI_XDI_PROVIDES_RX_DMA;
  8521. dbug(1,dprintf("XDI provides RxDMA"));
  8522. }
  8523. if (features[0] & DIVA_XDI_EXTENDED_FEATURE_SDRAM_BAR) {
  8524. diva_xdi_extended_features |= DIVA_CAPI_XDI_PROVIDES_SDRAM_BAR;
  8525. }
  8526. if (features[0] & DIVA_XDI_EXTENDED_FEATURE_NO_CANCEL_RC) {
  8527. diva_xdi_extended_features |= DIVA_CAPI_XDI_PROVIDES_NO_CANCEL;
  8528. dbug(3,dprintf("XDI provides NO_CANCEL_RC feature"));
  8529. }
  8530. }
  8531. }
  8532. diva_ask_for_xdi_sdram_bar (a, preq);
  8533. }
  8534. /*------------------------------------------------------------------*/
  8535. /* automatic law */
  8536. /*------------------------------------------------------------------*/
  8537. /* called from OS specific part after init time to get the Law */
  8538. /* a-law (Euro) and u-law (us,japan) use different BCs in the Setup message */
  8539. void AutomaticLaw(DIVA_CAPI_ADAPTER *a)
  8540. {
  8541. word j;
  8542. PLCI *splci;
  8543. if(a->automatic_law) {
  8544. return;
  8545. }
  8546. if((j=get_plci(a))) {
  8547. diva_get_extended_adapter_features (a);
  8548. splci = &a->plci[j-1];
  8549. a->automatic_lawPLCI = splci;
  8550. a->automatic_law = 1;
  8551. add_p(splci,CAI,"\x01\x80");
  8552. add_p(splci,UID,"\x06\x43\x61\x70\x69\x32\x30");
  8553. splci->internal_command = USELAW_REQ;
  8554. splci->command = 0;
  8555. splci->number = 0;
  8556. sig_req(splci,ASSIGN,DSIG_ID);
  8557. send_req(splci);
  8558. }
  8559. }
  8560. /* called from OS specific part if an application sends an Capi20Release */
  8561. word CapiRelease(word Id)
  8562. {
  8563. word i, j, appls_found;
  8564. PLCI *plci;
  8565. APPL *this;
  8566. DIVA_CAPI_ADAPTER *a;
  8567. if (!Id)
  8568. {
  8569. dbug(0,dprintf("A: CapiRelease(Id==0)"));
  8570. return (_WRONG_APPL_ID);
  8571. }
  8572. this = &application[Id-1]; /* get application pointer */
  8573. for(i=0,appls_found=0; i<max_appl; i++)
  8574. {
  8575. if(application[i].Id) /* an application has been found */
  8576. {
  8577. appls_found++;
  8578. }
  8579. }
  8580. for(i=0; i<max_adapter; i++) /* scan all adapters... */
  8581. {
  8582. a = &adapter[i];
  8583. if (a->request)
  8584. {
  8585. a->Info_Mask[Id-1] = 0;
  8586. a->CIP_Mask[Id-1] = 0;
  8587. a->Notification_Mask[Id-1] = 0;
  8588. a->codec_listen[Id-1] = NULL;
  8589. a->requested_options_table[Id-1] = 0;
  8590. for(j=0; j<a->max_plci; j++) /* and all PLCIs connected */
  8591. { /* with this application */
  8592. plci = &a->plci[j];
  8593. if(plci->Id) /* if plci owns no application */
  8594. { /* it may be not jet connected */
  8595. if(plci->State==INC_CON_PENDING
  8596. || plci->State==INC_CON_ALERT)
  8597. {
  8598. if(test_c_ind_mask_bit (plci, (word)(Id-1)))
  8599. {
  8600. clear_c_ind_mask_bit (plci, (word)(Id-1));
  8601. if(c_ind_mask_empty (plci))
  8602. {
  8603. sig_req(plci,HANGUP,0);
  8604. send_req(plci);
  8605. plci->State = OUTG_DIS_PENDING;
  8606. }
  8607. }
  8608. }
  8609. if(test_c_ind_mask_bit (plci, (word)(Id-1)))
  8610. {
  8611. clear_c_ind_mask_bit (plci, (word)(Id-1));
  8612. if(c_ind_mask_empty (plci))
  8613. {
  8614. if(!plci->appl)
  8615. {
  8616. plci_remove(plci);
  8617. plci->State = IDLE;
  8618. }
  8619. }
  8620. }
  8621. if(plci->appl==this)
  8622. {
  8623. plci->appl = NULL;
  8624. plci_remove(plci);
  8625. plci->State = IDLE;
  8626. }
  8627. }
  8628. }
  8629. listen_check(a);
  8630. if(a->flag_dynamic_l1_down)
  8631. {
  8632. if(appls_found==1) /* last application does a capi release */
  8633. {
  8634. if((j=get_plci(a)))
  8635. {
  8636. plci = &a->plci[j-1];
  8637. plci->command = 0;
  8638. add_p(plci,OAD,"\x01\xfd");
  8639. add_p(plci,CAI,"\x01\x80");
  8640. add_p(plci,UID,"\x06\x43\x61\x70\x69\x32\x30");
  8641. add_p(plci,SHIFT|6,NULL);
  8642. add_p(plci,SIN,"\x02\x00\x00");
  8643. plci->internal_command = REM_L1_SIG_ASSIGN_PEND;
  8644. sig_req(plci,ASSIGN,DSIG_ID);
  8645. add_p(plci,FTY,"\x02\xff\x06"); /* l1 down */
  8646. sig_req(plci,SIG_CTRL,0);
  8647. send_req(plci);
  8648. }
  8649. }
  8650. }
  8651. if(a->AdvSignalAppl==this)
  8652. {
  8653. this->NullCREnable = false;
  8654. if (a->AdvCodecPLCI)
  8655. {
  8656. plci_remove(a->AdvCodecPLCI);
  8657. a->AdvCodecPLCI->tel = 0;
  8658. a->AdvCodecPLCI->adv_nl = 0;
  8659. }
  8660. a->AdvSignalAppl = NULL;
  8661. a->AdvSignalPLCI = NULL;
  8662. a->AdvCodecFLAG = 0;
  8663. a->AdvCodecPLCI = NULL;
  8664. }
  8665. }
  8666. }
  8667. this->Id = 0;
  8668. return GOOD;
  8669. }
  8670. static word plci_remove_check(PLCI *plci)
  8671. {
  8672. if(!plci) return true;
  8673. if(!plci->NL.Id && c_ind_mask_empty (plci))
  8674. {
  8675. if(plci->Sig.Id == 0xff)
  8676. plci->Sig.Id = 0;
  8677. if(!plci->Sig.Id)
  8678. {
  8679. dbug(1,dprintf("plci_remove_complete(%x)",plci->Id));
  8680. dbug(1,dprintf("tel=0x%x,Sig=0x%x",plci->tel,plci->Sig.Id));
  8681. if (plci->Id)
  8682. {
  8683. CodecIdCheck(plci->adapter, plci);
  8684. clear_b1_config (plci);
  8685. ncci_remove (plci, 0, false);
  8686. plci_free_msg_in_queue (plci);
  8687. channel_flow_control_remove (plci);
  8688. plci->Id = 0;
  8689. plci->State = IDLE;
  8690. plci->channels = 0;
  8691. plci->appl = NULL;
  8692. plci->notifiedcall = 0;
  8693. }
  8694. listen_check(plci->adapter);
  8695. return true;
  8696. }
  8697. }
  8698. return false;
  8699. }
  8700. /*------------------------------------------------------------------*/
  8701. static byte plci_nl_busy (PLCI *plci)
  8702. {
  8703. /* only applicable for non-multiplexed protocols */
  8704. return (plci->nl_req
  8705. || (plci->ncci_ring_list
  8706. && plci->adapter->ncci_ch[plci->ncci_ring_list]
  8707. && (plci->adapter->ch_flow_control[plci->adapter->ncci_ch[plci->ncci_ring_list]] & N_OK_FC_PENDING)));
  8708. }
  8709. /*------------------------------------------------------------------*/
  8710. /* DTMF facilities */
  8711. /*------------------------------------------------------------------*/
  8712. static struct
  8713. {
  8714. byte send_mask;
  8715. byte listen_mask;
  8716. byte character;
  8717. byte code;
  8718. } dtmf_digit_map[] =
  8719. {
  8720. { 0x01, 0x01, 0x23, DTMF_DIGIT_TONE_CODE_HASHMARK },
  8721. { 0x01, 0x01, 0x2a, DTMF_DIGIT_TONE_CODE_STAR },
  8722. { 0x01, 0x01, 0x30, DTMF_DIGIT_TONE_CODE_0 },
  8723. { 0x01, 0x01, 0x31, DTMF_DIGIT_TONE_CODE_1 },
  8724. { 0x01, 0x01, 0x32, DTMF_DIGIT_TONE_CODE_2 },
  8725. { 0x01, 0x01, 0x33, DTMF_DIGIT_TONE_CODE_3 },
  8726. { 0x01, 0x01, 0x34, DTMF_DIGIT_TONE_CODE_4 },
  8727. { 0x01, 0x01, 0x35, DTMF_DIGIT_TONE_CODE_5 },
  8728. { 0x01, 0x01, 0x36, DTMF_DIGIT_TONE_CODE_6 },
  8729. { 0x01, 0x01, 0x37, DTMF_DIGIT_TONE_CODE_7 },
  8730. { 0x01, 0x01, 0x38, DTMF_DIGIT_TONE_CODE_8 },
  8731. { 0x01, 0x01, 0x39, DTMF_DIGIT_TONE_CODE_9 },
  8732. { 0x01, 0x01, 0x41, DTMF_DIGIT_TONE_CODE_A },
  8733. { 0x01, 0x01, 0x42, DTMF_DIGIT_TONE_CODE_B },
  8734. { 0x01, 0x01, 0x43, DTMF_DIGIT_TONE_CODE_C },
  8735. { 0x01, 0x01, 0x44, DTMF_DIGIT_TONE_CODE_D },
  8736. { 0x01, 0x00, 0x61, DTMF_DIGIT_TONE_CODE_A },
  8737. { 0x01, 0x00, 0x62, DTMF_DIGIT_TONE_CODE_B },
  8738. { 0x01, 0x00, 0x63, DTMF_DIGIT_TONE_CODE_C },
  8739. { 0x01, 0x00, 0x64, DTMF_DIGIT_TONE_CODE_D },
  8740. { 0x04, 0x04, 0x80, DTMF_SIGNAL_NO_TONE },
  8741. { 0x00, 0x04, 0x81, DTMF_SIGNAL_UNIDENTIFIED_TONE },
  8742. { 0x04, 0x04, 0x82, DTMF_SIGNAL_DIAL_TONE },
  8743. { 0x04, 0x04, 0x83, DTMF_SIGNAL_PABX_INTERNAL_DIAL_TONE },
  8744. { 0x04, 0x04, 0x84, DTMF_SIGNAL_SPECIAL_DIAL_TONE },
  8745. { 0x04, 0x04, 0x85, DTMF_SIGNAL_SECOND_DIAL_TONE },
  8746. { 0x04, 0x04, 0x86, DTMF_SIGNAL_RINGING_TONE },
  8747. { 0x04, 0x04, 0x87, DTMF_SIGNAL_SPECIAL_RINGING_TONE },
  8748. { 0x04, 0x04, 0x88, DTMF_SIGNAL_BUSY_TONE },
  8749. { 0x04, 0x04, 0x89, DTMF_SIGNAL_CONGESTION_TONE },
  8750. { 0x04, 0x04, 0x8a, DTMF_SIGNAL_SPECIAL_INFORMATION_TONE },
  8751. { 0x04, 0x04, 0x8b, DTMF_SIGNAL_COMFORT_TONE },
  8752. { 0x04, 0x04, 0x8c, DTMF_SIGNAL_HOLD_TONE },
  8753. { 0x04, 0x04, 0x8d, DTMF_SIGNAL_RECORD_TONE },
  8754. { 0x04, 0x04, 0x8e, DTMF_SIGNAL_CALLER_WAITING_TONE },
  8755. { 0x04, 0x04, 0x8f, DTMF_SIGNAL_CALL_WAITING_TONE },
  8756. { 0x04, 0x04, 0x90, DTMF_SIGNAL_PAY_TONE },
  8757. { 0x04, 0x04, 0x91, DTMF_SIGNAL_POSITIVE_INDICATION_TONE },
  8758. { 0x04, 0x04, 0x92, DTMF_SIGNAL_NEGATIVE_INDICATION_TONE },
  8759. { 0x04, 0x04, 0x93, DTMF_SIGNAL_WARNING_TONE },
  8760. { 0x04, 0x04, 0x94, DTMF_SIGNAL_INTRUSION_TONE },
  8761. { 0x04, 0x04, 0x95, DTMF_SIGNAL_CALLING_CARD_SERVICE_TONE },
  8762. { 0x04, 0x04, 0x96, DTMF_SIGNAL_PAYPHONE_RECOGNITION_TONE },
  8763. { 0x04, 0x04, 0x97, DTMF_SIGNAL_CPE_ALERTING_SIGNAL },
  8764. { 0x04, 0x04, 0x98, DTMF_SIGNAL_OFF_HOOK_WARNING_TONE },
  8765. { 0x04, 0x04, 0xbf, DTMF_SIGNAL_INTERCEPT_TONE },
  8766. { 0x04, 0x04, 0xc0, DTMF_SIGNAL_MODEM_CALLING_TONE },
  8767. { 0x04, 0x04, 0xc1, DTMF_SIGNAL_FAX_CALLING_TONE },
  8768. { 0x04, 0x04, 0xc2, DTMF_SIGNAL_ANSWER_TONE },
  8769. { 0x04, 0x04, 0xc3, DTMF_SIGNAL_REVERSED_ANSWER_TONE },
  8770. { 0x04, 0x04, 0xc4, DTMF_SIGNAL_ANSAM_TONE },
  8771. { 0x04, 0x04, 0xc5, DTMF_SIGNAL_REVERSED_ANSAM_TONE },
  8772. { 0x04, 0x04, 0xc6, DTMF_SIGNAL_BELL103_ANSWER_TONE },
  8773. { 0x04, 0x04, 0xc7, DTMF_SIGNAL_FAX_FLAGS },
  8774. { 0x04, 0x04, 0xc8, DTMF_SIGNAL_G2_FAX_GROUP_ID },
  8775. { 0x00, 0x04, 0xc9, DTMF_SIGNAL_HUMAN_SPEECH },
  8776. { 0x04, 0x04, 0xca, DTMF_SIGNAL_ANSWERING_MACHINE_390 },
  8777. { 0x02, 0x02, 0xf1, DTMF_MF_DIGIT_TONE_CODE_1 },
  8778. { 0x02, 0x02, 0xf2, DTMF_MF_DIGIT_TONE_CODE_2 },
  8779. { 0x02, 0x02, 0xf3, DTMF_MF_DIGIT_TONE_CODE_3 },
  8780. { 0x02, 0x02, 0xf4, DTMF_MF_DIGIT_TONE_CODE_4 },
  8781. { 0x02, 0x02, 0xf5, DTMF_MF_DIGIT_TONE_CODE_5 },
  8782. { 0x02, 0x02, 0xf6, DTMF_MF_DIGIT_TONE_CODE_6 },
  8783. { 0x02, 0x02, 0xf7, DTMF_MF_DIGIT_TONE_CODE_7 },
  8784. { 0x02, 0x02, 0xf8, DTMF_MF_DIGIT_TONE_CODE_8 },
  8785. { 0x02, 0x02, 0xf9, DTMF_MF_DIGIT_TONE_CODE_9 },
  8786. { 0x02, 0x02, 0xfa, DTMF_MF_DIGIT_TONE_CODE_0 },
  8787. { 0x02, 0x02, 0xfb, DTMF_MF_DIGIT_TONE_CODE_K1 },
  8788. { 0x02, 0x02, 0xfc, DTMF_MF_DIGIT_TONE_CODE_K2 },
  8789. { 0x02, 0x02, 0xfd, DTMF_MF_DIGIT_TONE_CODE_KP },
  8790. { 0x02, 0x02, 0xfe, DTMF_MF_DIGIT_TONE_CODE_S1 },
  8791. { 0x02, 0x02, 0xff, DTMF_MF_DIGIT_TONE_CODE_ST },
  8792. };
  8793. #define DTMF_DIGIT_MAP_ENTRIES ARRAY_SIZE(dtmf_digit_map)
  8794. static void dtmf_enable_receiver (PLCI *plci, byte enable_mask)
  8795. {
  8796. word min_digit_duration, min_gap_duration;
  8797. dbug (1, dprintf ("[%06lx] %s,%d: dtmf_enable_receiver %02x",
  8798. (dword)((plci->Id << 8) | UnMapController (plci->adapter->Id)),
  8799. (char *)(FILE_), __LINE__, enable_mask));
  8800. if (enable_mask != 0)
  8801. {
  8802. min_digit_duration = (plci->dtmf_rec_pulse_ms == 0) ? 40 : plci->dtmf_rec_pulse_ms;
  8803. min_gap_duration = (plci->dtmf_rec_pause_ms == 0) ? 40 : plci->dtmf_rec_pause_ms;
  8804. plci->internal_req_buffer[0] = DTMF_UDATA_REQUEST_ENABLE_RECEIVER;
  8805. PUT_WORD (&plci->internal_req_buffer[1], min_digit_duration);
  8806. PUT_WORD (&plci->internal_req_buffer[3], min_gap_duration);
  8807. plci->NData[0].PLength = 5;
  8808. PUT_WORD (&plci->internal_req_buffer[5], INTERNAL_IND_BUFFER_SIZE);
  8809. plci->NData[0].PLength += 2;
  8810. capidtmf_recv_enable (&(plci->capidtmf_state), min_digit_duration, min_gap_duration);
  8811. }
  8812. else
  8813. {
  8814. plci->internal_req_buffer[0] = DTMF_UDATA_REQUEST_DISABLE_RECEIVER;
  8815. plci->NData[0].PLength = 1;
  8816. capidtmf_recv_disable (&(plci->capidtmf_state));
  8817. }
  8818. plci->NData[0].P = plci->internal_req_buffer;
  8819. plci->NL.X = plci->NData;
  8820. plci->NL.ReqCh = 0;
  8821. plci->NL.Req = plci->nl_req = (byte) N_UDATA;
  8822. plci->adapter->request (&plci->NL);
  8823. }
  8824. static void dtmf_send_digits (PLCI *plci, byte *digit_buffer, word digit_count)
  8825. {
  8826. word w, i;
  8827. dbug (1, dprintf ("[%06lx] %s,%d: dtmf_send_digits %d",
  8828. (dword)((plci->Id << 8) | UnMapController (plci->adapter->Id)),
  8829. (char *)(FILE_), __LINE__, digit_count));
  8830. plci->internal_req_buffer[0] = DTMF_UDATA_REQUEST_SEND_DIGITS;
  8831. w = (plci->dtmf_send_pulse_ms == 0) ? 40 : plci->dtmf_send_pulse_ms;
  8832. PUT_WORD (&plci->internal_req_buffer[1], w);
  8833. w = (plci->dtmf_send_pause_ms == 0) ? 40 : plci->dtmf_send_pause_ms;
  8834. PUT_WORD (&plci->internal_req_buffer[3], w);
  8835. for (i = 0; i < digit_count; i++)
  8836. {
  8837. w = 0;
  8838. while ((w < DTMF_DIGIT_MAP_ENTRIES)
  8839. && (digit_buffer[i] != dtmf_digit_map[w].character))
  8840. {
  8841. w++;
  8842. }
  8843. plci->internal_req_buffer[5+i] = (w < DTMF_DIGIT_MAP_ENTRIES) ?
  8844. dtmf_digit_map[w].code : DTMF_DIGIT_TONE_CODE_STAR;
  8845. }
  8846. plci->NData[0].PLength = 5 + digit_count;
  8847. plci->NData[0].P = plci->internal_req_buffer;
  8848. plci->NL.X = plci->NData;
  8849. plci->NL.ReqCh = 0;
  8850. plci->NL.Req = plci->nl_req = (byte) N_UDATA;
  8851. plci->adapter->request (&plci->NL);
  8852. }
  8853. static void dtmf_rec_clear_config (PLCI *plci)
  8854. {
  8855. dbug (1, dprintf ("[%06lx] %s,%d: dtmf_rec_clear_config",
  8856. (dword)((plci->Id << 8) | UnMapController (plci->adapter->Id)),
  8857. (char *)(FILE_), __LINE__));
  8858. plci->dtmf_rec_active = 0;
  8859. plci->dtmf_rec_pulse_ms = 0;
  8860. plci->dtmf_rec_pause_ms = 0;
  8861. capidtmf_init (&(plci->capidtmf_state), plci->adapter->u_law);
  8862. }
  8863. static void dtmf_send_clear_config (PLCI *plci)
  8864. {
  8865. dbug (1, dprintf ("[%06lx] %s,%d: dtmf_send_clear_config",
  8866. (dword)((plci->Id << 8) | UnMapController (plci->adapter->Id)),
  8867. (char *)(FILE_), __LINE__));
  8868. plci->dtmf_send_requests = 0;
  8869. plci->dtmf_send_pulse_ms = 0;
  8870. plci->dtmf_send_pause_ms = 0;
  8871. }
  8872. static void dtmf_prepare_switch (dword Id, PLCI *plci)
  8873. {
  8874. dbug (1, dprintf ("[%06lx] %s,%d: dtmf_prepare_switch",
  8875. UnMapId (Id), (char *)(FILE_), __LINE__));
  8876. while (plci->dtmf_send_requests != 0)
  8877. dtmf_confirmation (Id, plci);
  8878. }
  8879. static word dtmf_save_config (dword Id, PLCI *plci, byte Rc)
  8880. {
  8881. dbug (1, dprintf ("[%06lx] %s,%d: dtmf_save_config %02x %d",
  8882. UnMapId (Id), (char *)(FILE_), __LINE__, Rc, plci->adjust_b_state));
  8883. return (GOOD);
  8884. }
  8885. static word dtmf_restore_config (dword Id, PLCI *plci, byte Rc)
  8886. {
  8887. word Info;
  8888. dbug (1, dprintf ("[%06lx] %s,%d: dtmf_restore_config %02x %d",
  8889. UnMapId (Id), (char *)(FILE_), __LINE__, Rc, plci->adjust_b_state));
  8890. Info = GOOD;
  8891. if (plci->B1_facilities & B1_FACILITY_DTMFR)
  8892. {
  8893. switch (plci->adjust_b_state)
  8894. {
  8895. case ADJUST_B_RESTORE_DTMF_1:
  8896. plci->internal_command = plci->adjust_b_command;
  8897. if (plci_nl_busy (plci))
  8898. {
  8899. plci->adjust_b_state = ADJUST_B_RESTORE_DTMF_1;
  8900. break;
  8901. }
  8902. dtmf_enable_receiver (plci, plci->dtmf_rec_active);
  8903. plci->adjust_b_state = ADJUST_B_RESTORE_DTMF_2;
  8904. break;
  8905. case ADJUST_B_RESTORE_DTMF_2:
  8906. if ((Rc != OK) && (Rc != OK_FC))
  8907. {
  8908. dbug (1, dprintf ("[%06lx] %s,%d: Reenable DTMF receiver failed %02x",
  8909. UnMapId (Id), (char *)(FILE_), __LINE__, Rc));
  8910. Info = _WRONG_STATE;
  8911. break;
  8912. }
  8913. break;
  8914. }
  8915. }
  8916. return (Info);
  8917. }
  8918. static void dtmf_command (dword Id, PLCI *plci, byte Rc)
  8919. {
  8920. word internal_command, Info;
  8921. byte mask;
  8922. byte result[4];
  8923. dbug (1, dprintf ("[%06lx] %s,%d: dtmf_command %02x %04x %04x %d %d %d %d",
  8924. UnMapId (Id), (char *)(FILE_), __LINE__, Rc, plci->internal_command,
  8925. plci->dtmf_cmd, plci->dtmf_rec_pulse_ms, plci->dtmf_rec_pause_ms,
  8926. plci->dtmf_send_pulse_ms, plci->dtmf_send_pause_ms));
  8927. Info = GOOD;
  8928. result[0] = 2;
  8929. PUT_WORD (&result[1], DTMF_SUCCESS);
  8930. internal_command = plci->internal_command;
  8931. plci->internal_command = 0;
  8932. mask = 0x01;
  8933. switch (plci->dtmf_cmd)
  8934. {
  8935. case DTMF_LISTEN_TONE_START:
  8936. mask <<= 1;
  8937. case DTMF_LISTEN_MF_START:
  8938. mask <<= 1;
  8939. case DTMF_LISTEN_START:
  8940. switch (internal_command)
  8941. {
  8942. default:
  8943. adjust_b1_resource (Id, plci, NULL, (word)(plci->B1_facilities |
  8944. B1_FACILITY_DTMFR), DTMF_COMMAND_1);
  8945. case DTMF_COMMAND_1:
  8946. if (adjust_b_process (Id, plci, Rc) != GOOD)
  8947. {
  8948. dbug (1, dprintf ("[%06lx] %s,%d: Load DTMF failed",
  8949. UnMapId (Id), (char *)(FILE_), __LINE__));
  8950. Info = _FACILITY_NOT_SUPPORTED;
  8951. break;
  8952. }
  8953. if (plci->internal_command)
  8954. return;
  8955. case DTMF_COMMAND_2:
  8956. if (plci_nl_busy (plci))
  8957. {
  8958. plci->internal_command = DTMF_COMMAND_2;
  8959. return;
  8960. }
  8961. plci->internal_command = DTMF_COMMAND_3;
  8962. dtmf_enable_receiver (plci, (byte)(plci->dtmf_rec_active | mask));
  8963. return;
  8964. case DTMF_COMMAND_3:
  8965. if ((Rc != OK) && (Rc != OK_FC))
  8966. {
  8967. dbug (1, dprintf ("[%06lx] %s,%d: Enable DTMF receiver failed %02x",
  8968. UnMapId (Id), (char *)(FILE_), __LINE__, Rc));
  8969. Info = _FACILITY_NOT_SUPPORTED;
  8970. break;
  8971. }
  8972. plci->tone_last_indication_code = DTMF_SIGNAL_NO_TONE;
  8973. plci->dtmf_rec_active |= mask;
  8974. break;
  8975. }
  8976. break;
  8977. case DTMF_LISTEN_TONE_STOP:
  8978. mask <<= 1;
  8979. case DTMF_LISTEN_MF_STOP:
  8980. mask <<= 1;
  8981. case DTMF_LISTEN_STOP:
  8982. switch (internal_command)
  8983. {
  8984. default:
  8985. plci->dtmf_rec_active &= ~mask;
  8986. if (plci->dtmf_rec_active)
  8987. break;
  8988. /*
  8989. case DTMF_COMMAND_1:
  8990. if (plci->dtmf_rec_active)
  8991. {
  8992. if (plci_nl_busy (plci))
  8993. {
  8994. plci->internal_command = DTMF_COMMAND_1;
  8995. return;
  8996. }
  8997. plci->dtmf_rec_active &= ~mask;
  8998. plci->internal_command = DTMF_COMMAND_2;
  8999. dtmf_enable_receiver (plci, false);
  9000. return;
  9001. }
  9002. Rc = OK;
  9003. case DTMF_COMMAND_2:
  9004. if ((Rc != OK) && (Rc != OK_FC))
  9005. {
  9006. dbug (1, dprintf ("[%06lx] %s,%d: Disable DTMF receiver failed %02x",
  9007. UnMapId (Id), (char far *)(FILE_), __LINE__, Rc));
  9008. Info = _FACILITY_NOT_SUPPORTED;
  9009. break;
  9010. }
  9011. */
  9012. adjust_b1_resource (Id, plci, NULL, (word)(plci->B1_facilities &
  9013. ~(B1_FACILITY_DTMFX | B1_FACILITY_DTMFR)), DTMF_COMMAND_3);
  9014. case DTMF_COMMAND_3:
  9015. if (adjust_b_process (Id, plci, Rc) != GOOD)
  9016. {
  9017. dbug (1, dprintf ("[%06lx] %s,%d: Unload DTMF failed",
  9018. UnMapId (Id), (char *)(FILE_), __LINE__));
  9019. Info = _FACILITY_NOT_SUPPORTED;
  9020. break;
  9021. }
  9022. if (plci->internal_command)
  9023. return;
  9024. break;
  9025. }
  9026. break;
  9027. case DTMF_SEND_TONE:
  9028. mask <<= 1;
  9029. case DTMF_SEND_MF:
  9030. mask <<= 1;
  9031. case DTMF_DIGITS_SEND:
  9032. switch (internal_command)
  9033. {
  9034. default:
  9035. adjust_b1_resource (Id, plci, NULL, (word)(plci->B1_facilities |
  9036. ((plci->dtmf_parameter_length != 0) ? B1_FACILITY_DTMFX | B1_FACILITY_DTMFR : B1_FACILITY_DTMFX)),
  9037. DTMF_COMMAND_1);
  9038. case DTMF_COMMAND_1:
  9039. if (adjust_b_process (Id, plci, Rc) != GOOD)
  9040. {
  9041. dbug (1, dprintf ("[%06lx] %s,%d: Load DTMF failed",
  9042. UnMapId (Id), (char *)(FILE_), __LINE__));
  9043. Info = _FACILITY_NOT_SUPPORTED;
  9044. break;
  9045. }
  9046. if (plci->internal_command)
  9047. return;
  9048. case DTMF_COMMAND_2:
  9049. if (plci_nl_busy (plci))
  9050. {
  9051. plci->internal_command = DTMF_COMMAND_2;
  9052. return;
  9053. }
  9054. plci->dtmf_msg_number_queue[(plci->dtmf_send_requests)++] = plci->number;
  9055. plci->internal_command = DTMF_COMMAND_3;
  9056. dtmf_send_digits (plci, &plci->saved_msg.parms[3].info[1], plci->saved_msg.parms[3].length);
  9057. return;
  9058. case DTMF_COMMAND_3:
  9059. if ((Rc != OK) && (Rc != OK_FC))
  9060. {
  9061. dbug (1, dprintf ("[%06lx] %s,%d: Send DTMF digits failed %02x",
  9062. UnMapId (Id), (char *)(FILE_), __LINE__, Rc));
  9063. if (plci->dtmf_send_requests != 0)
  9064. (plci->dtmf_send_requests)--;
  9065. Info = _FACILITY_NOT_SUPPORTED;
  9066. break;
  9067. }
  9068. return;
  9069. }
  9070. break;
  9071. }
  9072. sendf (plci->appl, _FACILITY_R | CONFIRM, Id & 0xffffL, plci->number,
  9073. "wws", Info, SELECTOR_DTMF, result);
  9074. }
  9075. static byte dtmf_request (dword Id, word Number, DIVA_CAPI_ADAPTER *a, PLCI *plci, APPL *appl, API_PARSE *msg)
  9076. {
  9077. word Info;
  9078. word i, j;
  9079. byte mask;
  9080. API_PARSE dtmf_parms[5];
  9081. byte result[40];
  9082. dbug (1, dprintf ("[%06lx] %s,%d: dtmf_request",
  9083. UnMapId (Id), (char *)(FILE_), __LINE__));
  9084. Info = GOOD;
  9085. result[0] = 2;
  9086. PUT_WORD (&result[1], DTMF_SUCCESS);
  9087. if (!(a->profile.Global_Options & GL_DTMF_SUPPORTED))
  9088. {
  9089. dbug (1, dprintf ("[%06lx] %s,%d: Facility not supported",
  9090. UnMapId (Id), (char *)(FILE_), __LINE__));
  9091. Info = _FACILITY_NOT_SUPPORTED;
  9092. }
  9093. else if (api_parse (&msg[1].info[1], msg[1].length, "w", dtmf_parms))
  9094. {
  9095. dbug (1, dprintf ("[%06lx] %s,%d: Wrong message format",
  9096. UnMapId (Id), (char *)(FILE_), __LINE__));
  9097. Info = _WRONG_MESSAGE_FORMAT;
  9098. }
  9099. else if ((GET_WORD (dtmf_parms[0].info) == DTMF_GET_SUPPORTED_DETECT_CODES)
  9100. || (GET_WORD (dtmf_parms[0].info) == DTMF_GET_SUPPORTED_SEND_CODES))
  9101. {
  9102. if (!((a->requested_options_table[appl->Id-1])
  9103. & (1L << PRIVATE_DTMF_TONE)))
  9104. {
  9105. dbug (1, dprintf ("[%06lx] %s,%d: DTMF unknown request %04x",
  9106. UnMapId (Id), (char *)(FILE_), __LINE__, GET_WORD (dtmf_parms[0].info)));
  9107. PUT_WORD (&result[1], DTMF_UNKNOWN_REQUEST);
  9108. }
  9109. else
  9110. {
  9111. for (i = 0; i < 32; i++)
  9112. result[4 + i] = 0;
  9113. if (GET_WORD (dtmf_parms[0].info) == DTMF_GET_SUPPORTED_DETECT_CODES)
  9114. {
  9115. for (i = 0; i < DTMF_DIGIT_MAP_ENTRIES; i++)
  9116. {
  9117. if (dtmf_digit_map[i].listen_mask != 0)
  9118. result[4 + (dtmf_digit_map[i].character >> 3)] |= (1 << (dtmf_digit_map[i].character & 0x7));
  9119. }
  9120. }
  9121. else
  9122. {
  9123. for (i = 0; i < DTMF_DIGIT_MAP_ENTRIES; i++)
  9124. {
  9125. if (dtmf_digit_map[i].send_mask != 0)
  9126. result[4 + (dtmf_digit_map[i].character >> 3)] |= (1 << (dtmf_digit_map[i].character & 0x7));
  9127. }
  9128. }
  9129. result[0] = 3 + 32;
  9130. result[3] = 32;
  9131. }
  9132. }
  9133. else if (plci == NULL)
  9134. {
  9135. dbug (1, dprintf ("[%06lx] %s,%d: Wrong PLCI",
  9136. UnMapId (Id), (char *)(FILE_), __LINE__));
  9137. Info = _WRONG_IDENTIFIER;
  9138. }
  9139. else
  9140. {
  9141. if (!plci->State
  9142. || !plci->NL.Id || plci->nl_remove_id)
  9143. {
  9144. dbug (1, dprintf ("[%06lx] %s,%d: Wrong state",
  9145. UnMapId (Id), (char *)(FILE_), __LINE__));
  9146. Info = _WRONG_STATE;
  9147. }
  9148. else
  9149. {
  9150. plci->command = 0;
  9151. plci->dtmf_cmd = GET_WORD (dtmf_parms[0].info);
  9152. mask = 0x01;
  9153. switch (plci->dtmf_cmd)
  9154. {
  9155. case DTMF_LISTEN_TONE_START:
  9156. case DTMF_LISTEN_TONE_STOP:
  9157. mask <<= 1;
  9158. case DTMF_LISTEN_MF_START:
  9159. case DTMF_LISTEN_MF_STOP:
  9160. mask <<= 1;
  9161. if (!((plci->requested_options_conn | plci->requested_options | plci->adapter->requested_options_table[appl->Id-1])
  9162. & (1L << PRIVATE_DTMF_TONE)))
  9163. {
  9164. dbug (1, dprintf ("[%06lx] %s,%d: DTMF unknown request %04x",
  9165. UnMapId (Id), (char *)(FILE_), __LINE__, GET_WORD (dtmf_parms[0].info)));
  9166. PUT_WORD (&result[1], DTMF_UNKNOWN_REQUEST);
  9167. break;
  9168. }
  9169. case DTMF_LISTEN_START:
  9170. case DTMF_LISTEN_STOP:
  9171. if (!(a->manufacturer_features & MANUFACTURER_FEATURE_HARDDTMF)
  9172. && !(a->manufacturer_features & MANUFACTURER_FEATURE_SOFTDTMF_RECEIVE))
  9173. {
  9174. dbug (1, dprintf ("[%06lx] %s,%d: Facility not supported",
  9175. UnMapId (Id), (char *)(FILE_), __LINE__));
  9176. Info = _FACILITY_NOT_SUPPORTED;
  9177. break;
  9178. }
  9179. if (mask & DTMF_LISTEN_ACTIVE_FLAG)
  9180. {
  9181. if (api_parse (&msg[1].info[1], msg[1].length, "wwws", dtmf_parms))
  9182. {
  9183. plci->dtmf_rec_pulse_ms = 0;
  9184. plci->dtmf_rec_pause_ms = 0;
  9185. }
  9186. else
  9187. {
  9188. plci->dtmf_rec_pulse_ms = GET_WORD (dtmf_parms[1].info);
  9189. plci->dtmf_rec_pause_ms = GET_WORD (dtmf_parms[2].info);
  9190. }
  9191. }
  9192. start_internal_command (Id, plci, dtmf_command);
  9193. return (false);
  9194. case DTMF_SEND_TONE:
  9195. mask <<= 1;
  9196. case DTMF_SEND_MF:
  9197. mask <<= 1;
  9198. if (!((plci->requested_options_conn | plci->requested_options | plci->adapter->requested_options_table[appl->Id-1])
  9199. & (1L << PRIVATE_DTMF_TONE)))
  9200. {
  9201. dbug (1, dprintf ("[%06lx] %s,%d: DTMF unknown request %04x",
  9202. UnMapId (Id), (char *)(FILE_), __LINE__, GET_WORD (dtmf_parms[0].info)));
  9203. PUT_WORD (&result[1], DTMF_UNKNOWN_REQUEST);
  9204. break;
  9205. }
  9206. case DTMF_DIGITS_SEND:
  9207. if (api_parse (&msg[1].info[1], msg[1].length, "wwws", dtmf_parms))
  9208. {
  9209. dbug (1, dprintf ("[%06lx] %s,%d: Wrong message format",
  9210. UnMapId (Id), (char *)(FILE_), __LINE__));
  9211. Info = _WRONG_MESSAGE_FORMAT;
  9212. break;
  9213. }
  9214. if (mask & DTMF_LISTEN_ACTIVE_FLAG)
  9215. {
  9216. plci->dtmf_send_pulse_ms = GET_WORD (dtmf_parms[1].info);
  9217. plci->dtmf_send_pause_ms = GET_WORD (dtmf_parms[2].info);
  9218. }
  9219. i = 0;
  9220. j = 0;
  9221. while ((i < dtmf_parms[3].length) && (j < DTMF_DIGIT_MAP_ENTRIES))
  9222. {
  9223. j = 0;
  9224. while ((j < DTMF_DIGIT_MAP_ENTRIES)
  9225. && ((dtmf_parms[3].info[i+1] != dtmf_digit_map[j].character)
  9226. || ((dtmf_digit_map[j].send_mask & mask) == 0)))
  9227. {
  9228. j++;
  9229. }
  9230. i++;
  9231. }
  9232. if (j == DTMF_DIGIT_MAP_ENTRIES)
  9233. {
  9234. dbug (1, dprintf ("[%06lx] %s,%d: Incorrect DTMF digit %02x",
  9235. UnMapId (Id), (char *)(FILE_), __LINE__, dtmf_parms[3].info[i]));
  9236. PUT_WORD (&result[1], DTMF_INCORRECT_DIGIT);
  9237. break;
  9238. }
  9239. if (plci->dtmf_send_requests >= ARRAY_SIZE(plci->dtmf_msg_number_queue))
  9240. {
  9241. dbug (1, dprintf ("[%06lx] %s,%d: DTMF request overrun",
  9242. UnMapId (Id), (char *)(FILE_), __LINE__));
  9243. Info = _WRONG_STATE;
  9244. break;
  9245. }
  9246. api_save_msg (dtmf_parms, "wwws", &plci->saved_msg);
  9247. start_internal_command (Id, plci, dtmf_command);
  9248. return (false);
  9249. default:
  9250. dbug (1, dprintf ("[%06lx] %s,%d: DTMF unknown request %04x",
  9251. UnMapId (Id), (char *)(FILE_), __LINE__, plci->dtmf_cmd));
  9252. PUT_WORD (&result[1], DTMF_UNKNOWN_REQUEST);
  9253. }
  9254. }
  9255. }
  9256. sendf (appl, _FACILITY_R | CONFIRM, Id & 0xffffL, Number,
  9257. "wws", Info, SELECTOR_DTMF, result);
  9258. return (false);
  9259. }
  9260. static void dtmf_confirmation (dword Id, PLCI *plci)
  9261. {
  9262. word Info;
  9263. word i;
  9264. byte result[4];
  9265. dbug (1, dprintf ("[%06lx] %s,%d: dtmf_confirmation",
  9266. UnMapId (Id), (char *)(FILE_), __LINE__));
  9267. Info = GOOD;
  9268. result[0] = 2;
  9269. PUT_WORD (&result[1], DTMF_SUCCESS);
  9270. if (plci->dtmf_send_requests != 0)
  9271. {
  9272. sendf (plci->appl, _FACILITY_R | CONFIRM, Id & 0xffffL, plci->dtmf_msg_number_queue[0],
  9273. "wws", GOOD, SELECTOR_DTMF, result);
  9274. (plci->dtmf_send_requests)--;
  9275. for (i = 0; i < plci->dtmf_send_requests; i++)
  9276. plci->dtmf_msg_number_queue[i] = plci->dtmf_msg_number_queue[i+1];
  9277. }
  9278. }
  9279. static void dtmf_indication (dword Id, PLCI *plci, byte *msg, word length)
  9280. {
  9281. word i, j, n;
  9282. dbug (1, dprintf ("[%06lx] %s,%d: dtmf_indication",
  9283. UnMapId (Id), (char *)(FILE_), __LINE__));
  9284. n = 0;
  9285. for (i = 1; i < length; i++)
  9286. {
  9287. j = 0;
  9288. while ((j < DTMF_DIGIT_MAP_ENTRIES)
  9289. && ((msg[i] != dtmf_digit_map[j].code)
  9290. || ((dtmf_digit_map[j].listen_mask & plci->dtmf_rec_active) == 0)))
  9291. {
  9292. j++;
  9293. }
  9294. if (j < DTMF_DIGIT_MAP_ENTRIES)
  9295. {
  9296. if ((dtmf_digit_map[j].listen_mask & DTMF_TONE_LISTEN_ACTIVE_FLAG)
  9297. && (plci->tone_last_indication_code == DTMF_SIGNAL_NO_TONE)
  9298. && (dtmf_digit_map[j].character != DTMF_SIGNAL_UNIDENTIFIED_TONE))
  9299. {
  9300. if (n + 1 == i)
  9301. {
  9302. for (i = length; i > n + 1; i--)
  9303. msg[i] = msg[i - 1];
  9304. length++;
  9305. i++;
  9306. }
  9307. msg[++n] = DTMF_SIGNAL_UNIDENTIFIED_TONE;
  9308. }
  9309. plci->tone_last_indication_code = dtmf_digit_map[j].character;
  9310. msg[++n] = dtmf_digit_map[j].character;
  9311. }
  9312. }
  9313. if (n != 0)
  9314. {
  9315. msg[0] = (byte) n;
  9316. sendf (plci->appl, _FACILITY_I, Id & 0xffffL, 0, "wS", SELECTOR_DTMF, msg);
  9317. }
  9318. }
  9319. /*------------------------------------------------------------------*/
  9320. /* DTMF parameters */
  9321. /*------------------------------------------------------------------*/
  9322. static void dtmf_parameter_write (PLCI *plci)
  9323. {
  9324. word i;
  9325. byte parameter_buffer[DTMF_PARAMETER_BUFFER_SIZE + 2];
  9326. dbug (1, dprintf ("[%06lx] %s,%d: dtmf_parameter_write",
  9327. (dword)((plci->Id << 8) | UnMapController (plci->adapter->Id)),
  9328. (char *)(FILE_), __LINE__));
  9329. parameter_buffer[0] = plci->dtmf_parameter_length + 1;
  9330. parameter_buffer[1] = DSP_CTRL_SET_DTMF_PARAMETERS;
  9331. for (i = 0; i < plci->dtmf_parameter_length; i++)
  9332. parameter_buffer[2+i] = plci->dtmf_parameter_buffer[i];
  9333. add_p (plci, FTY, parameter_buffer);
  9334. sig_req (plci, TEL_CTRL, 0);
  9335. send_req (plci);
  9336. }
  9337. static void dtmf_parameter_clear_config (PLCI *plci)
  9338. {
  9339. dbug (1, dprintf ("[%06lx] %s,%d: dtmf_parameter_clear_config",
  9340. (dword)((plci->Id << 8) | UnMapController (plci->adapter->Id)),
  9341. (char *)(FILE_), __LINE__));
  9342. plci->dtmf_parameter_length = 0;
  9343. }
  9344. static void dtmf_parameter_prepare_switch (dword Id, PLCI *plci)
  9345. {
  9346. dbug (1, dprintf ("[%06lx] %s,%d: dtmf_parameter_prepare_switch",
  9347. UnMapId (Id), (char *)(FILE_), __LINE__));
  9348. }
  9349. static word dtmf_parameter_save_config (dword Id, PLCI *plci, byte Rc)
  9350. {
  9351. dbug (1, dprintf ("[%06lx] %s,%d: dtmf_parameter_save_config %02x %d",
  9352. UnMapId (Id), (char *)(FILE_), __LINE__, Rc, plci->adjust_b_state));
  9353. return (GOOD);
  9354. }
  9355. static word dtmf_parameter_restore_config (dword Id, PLCI *plci, byte Rc)
  9356. {
  9357. word Info;
  9358. dbug (1, dprintf ("[%06lx] %s,%d: dtmf_parameter_restore_config %02x %d",
  9359. UnMapId (Id), (char *)(FILE_), __LINE__, Rc, plci->adjust_b_state));
  9360. Info = GOOD;
  9361. if ((plci->B1_facilities & B1_FACILITY_DTMFR)
  9362. && (plci->dtmf_parameter_length != 0))
  9363. {
  9364. switch (plci->adjust_b_state)
  9365. {
  9366. case ADJUST_B_RESTORE_DTMF_PARAMETER_1:
  9367. plci->internal_command = plci->adjust_b_command;
  9368. if (plci->sig_req)
  9369. {
  9370. plci->adjust_b_state = ADJUST_B_RESTORE_DTMF_PARAMETER_1;
  9371. break;
  9372. }
  9373. dtmf_parameter_write (plci);
  9374. plci->adjust_b_state = ADJUST_B_RESTORE_DTMF_PARAMETER_2;
  9375. break;
  9376. case ADJUST_B_RESTORE_DTMF_PARAMETER_2:
  9377. if ((Rc != OK) && (Rc != OK_FC))
  9378. {
  9379. dbug (1, dprintf ("[%06lx] %s,%d: Restore DTMF parameters failed %02x",
  9380. UnMapId (Id), (char *)(FILE_), __LINE__, Rc));
  9381. Info = _WRONG_STATE;
  9382. break;
  9383. }
  9384. break;
  9385. }
  9386. }
  9387. return (Info);
  9388. }
  9389. /*------------------------------------------------------------------*/
  9390. /* Line interconnect facilities */
  9391. /*------------------------------------------------------------------*/
  9392. LI_CONFIG *li_config_table;
  9393. word li_total_channels;
  9394. /*------------------------------------------------------------------*/
  9395. /* translate a CHI information element to a channel number */
  9396. /* returns 0xff - any channel */
  9397. /* 0xfe - chi wrong coding */
  9398. /* 0xfd - D-channel */
  9399. /* 0x00 - no channel */
  9400. /* else channel number / PRI: timeslot */
  9401. /* if channels is provided we accept more than one channel. */
  9402. /*------------------------------------------------------------------*/
  9403. static byte chi_to_channel (byte *chi, dword *pchannelmap)
  9404. {
  9405. int p;
  9406. int i;
  9407. dword map;
  9408. byte excl;
  9409. byte ofs;
  9410. byte ch;
  9411. if (pchannelmap) *pchannelmap = 0;
  9412. if(!chi[0]) return 0xff;
  9413. excl = 0;
  9414. if(chi[1] & 0x20) {
  9415. if(chi[0]==1 && chi[1]==0xac) return 0xfd; /* exclusive d-channel */
  9416. for(i=1; i<chi[0] && !(chi[i] &0x80); i++);
  9417. if(i==chi[0] || !(chi[i] &0x80)) return 0xfe;
  9418. if((chi[1] |0xc8)!=0xe9) return 0xfe;
  9419. if(chi[1] &0x08) excl = 0x40;
  9420. /* int. id present */
  9421. if(chi[1] &0x40) {
  9422. p=i+1;
  9423. for(i=p; i<chi[0] && !(chi[i] &0x80); i++);
  9424. if(i==chi[0] || !(chi[i] &0x80)) return 0xfe;
  9425. }
  9426. /* coding standard, Number/Map, Channel Type */
  9427. p=i+1;
  9428. for(i=p; i<chi[0] && !(chi[i] &0x80); i++);
  9429. if(i==chi[0] || !(chi[i] &0x80)) return 0xfe;
  9430. if((chi[p]|0xd0)!=0xd3) return 0xfe;
  9431. /* Number/Map */
  9432. if(chi[p] &0x10) {
  9433. /* map */
  9434. if((chi[0]-p)==4) ofs = 0;
  9435. else if((chi[0]-p)==3) ofs = 1;
  9436. else return 0xfe;
  9437. ch = 0;
  9438. map = 0;
  9439. for(i=0; i<4 && p<chi[0]; i++) {
  9440. p++;
  9441. ch += 8;
  9442. map <<= 8;
  9443. if(chi[p]) {
  9444. for (ch=0; !(chi[p] & (1 << ch)); ch++);
  9445. map |= chi[p];
  9446. }
  9447. }
  9448. ch += ofs;
  9449. map <<= ofs;
  9450. }
  9451. else {
  9452. /* number */
  9453. p=i+1;
  9454. ch = chi[p] &0x3f;
  9455. if(pchannelmap) {
  9456. if((byte)(chi[0]-p)>30) return 0xfe;
  9457. map = 0;
  9458. for(i=p; i<=chi[0]; i++) {
  9459. if ((chi[i] &0x7f) > 31) return 0xfe;
  9460. map |= (1L << (chi[i] &0x7f));
  9461. }
  9462. }
  9463. else {
  9464. if(p!=chi[0]) return 0xfe;
  9465. if (ch > 31) return 0xfe;
  9466. map = (1L << ch);
  9467. }
  9468. if(chi[p] &0x40) return 0xfe;
  9469. }
  9470. if (pchannelmap) *pchannelmap = map;
  9471. else if (map != ((dword)(1L << ch))) return 0xfe;
  9472. return (byte)(excl | ch);
  9473. }
  9474. else { /* not PRI */
  9475. for(i=1; i<chi[0] && !(chi[i] &0x80); i++);
  9476. if(i!=chi[0] || !(chi[i] &0x80)) return 0xfe;
  9477. if(chi[1] &0x08) excl = 0x40;
  9478. switch(chi[1] |0x98) {
  9479. case 0x98: return 0;
  9480. case 0x99:
  9481. if (pchannelmap) *pchannelmap = 2;
  9482. return excl |1;
  9483. case 0x9a:
  9484. if (pchannelmap) *pchannelmap = 4;
  9485. return excl |2;
  9486. case 0x9b: return 0xff;
  9487. case 0x9c: return 0xfd; /* d-ch */
  9488. default: return 0xfe;
  9489. }
  9490. }
  9491. }
  9492. static void mixer_set_bchannel_id_esc (PLCI *plci, byte bchannel_id)
  9493. {
  9494. DIVA_CAPI_ADAPTER *a;
  9495. PLCI *splci;
  9496. byte old_id;
  9497. a = plci->adapter;
  9498. old_id = plci->li_bchannel_id;
  9499. if (a->li_pri)
  9500. {
  9501. if ((old_id != 0) && (li_config_table[a->li_base + (old_id - 1)].plci == plci))
  9502. li_config_table[a->li_base + (old_id - 1)].plci = NULL;
  9503. plci->li_bchannel_id = (bchannel_id & 0x1f) + 1;
  9504. if (li_config_table[a->li_base + (plci->li_bchannel_id - 1)].plci == NULL)
  9505. li_config_table[a->li_base + (plci->li_bchannel_id - 1)].plci = plci;
  9506. }
  9507. else
  9508. {
  9509. if (((bchannel_id & 0x03) == 1) || ((bchannel_id & 0x03) == 2))
  9510. {
  9511. if ((old_id != 0) && (li_config_table[a->li_base + (old_id - 1)].plci == plci))
  9512. li_config_table[a->li_base + (old_id - 1)].plci = NULL;
  9513. plci->li_bchannel_id = bchannel_id & 0x03;
  9514. if ((a->AdvSignalPLCI != NULL) && (a->AdvSignalPLCI != plci) && (a->AdvSignalPLCI->tel == ADV_VOICE))
  9515. {
  9516. splci = a->AdvSignalPLCI;
  9517. if (li_config_table[a->li_base + (2 - plci->li_bchannel_id)].plci == NULL)
  9518. {
  9519. if ((splci->li_bchannel_id != 0)
  9520. && (li_config_table[a->li_base + (splci->li_bchannel_id - 1)].plci == splci))
  9521. {
  9522. li_config_table[a->li_base + (splci->li_bchannel_id - 1)].plci = NULL;
  9523. }
  9524. splci->li_bchannel_id = 3 - plci->li_bchannel_id;
  9525. li_config_table[a->li_base + (2 - plci->li_bchannel_id)].plci = splci;
  9526. dbug (1, dprintf ("[%06lx] %s,%d: adv_voice_set_bchannel_id_esc %d",
  9527. (dword)((splci->Id << 8) | UnMapController (splci->adapter->Id)),
  9528. (char *)(FILE_), __LINE__, splci->li_bchannel_id));
  9529. }
  9530. }
  9531. if (li_config_table[a->li_base + (plci->li_bchannel_id - 1)].plci == NULL)
  9532. li_config_table[a->li_base + (plci->li_bchannel_id - 1)].plci = plci;
  9533. }
  9534. }
  9535. if ((old_id == 0) && (plci->li_bchannel_id != 0)
  9536. && (li_config_table[a->li_base + (plci->li_bchannel_id - 1)].plci == plci))
  9537. {
  9538. mixer_clear_config (plci);
  9539. }
  9540. dbug (1, dprintf ("[%06lx] %s,%d: mixer_set_bchannel_id_esc %d %d",
  9541. (dword)((plci->Id << 8) | UnMapController (plci->adapter->Id)),
  9542. (char *)(FILE_), __LINE__, bchannel_id, plci->li_bchannel_id));
  9543. }
  9544. static void mixer_set_bchannel_id (PLCI *plci, byte *chi)
  9545. {
  9546. DIVA_CAPI_ADAPTER *a;
  9547. PLCI *splci;
  9548. byte ch, old_id;
  9549. a = plci->adapter;
  9550. old_id = plci->li_bchannel_id;
  9551. ch = chi_to_channel (chi, NULL);
  9552. if (!(ch & 0x80))
  9553. {
  9554. if (a->li_pri)
  9555. {
  9556. if ((old_id != 0) && (li_config_table[a->li_base + (old_id - 1)].plci == plci))
  9557. li_config_table[a->li_base + (old_id - 1)].plci = NULL;
  9558. plci->li_bchannel_id = (ch & 0x1f) + 1;
  9559. if (li_config_table[a->li_base + (plci->li_bchannel_id - 1)].plci == NULL)
  9560. li_config_table[a->li_base + (plci->li_bchannel_id - 1)].plci = plci;
  9561. }
  9562. else
  9563. {
  9564. if (((ch & 0x1f) == 1) || ((ch & 0x1f) == 2))
  9565. {
  9566. if ((old_id != 0) && (li_config_table[a->li_base + (old_id - 1)].plci == plci))
  9567. li_config_table[a->li_base + (old_id - 1)].plci = NULL;
  9568. plci->li_bchannel_id = ch & 0x1f;
  9569. if ((a->AdvSignalPLCI != NULL) && (a->AdvSignalPLCI != plci) && (a->AdvSignalPLCI->tel == ADV_VOICE))
  9570. {
  9571. splci = a->AdvSignalPLCI;
  9572. if (li_config_table[a->li_base + (2 - plci->li_bchannel_id)].plci == NULL)
  9573. {
  9574. if ((splci->li_bchannel_id != 0)
  9575. && (li_config_table[a->li_base + (splci->li_bchannel_id - 1)].plci == splci))
  9576. {
  9577. li_config_table[a->li_base + (splci->li_bchannel_id - 1)].plci = NULL;
  9578. }
  9579. splci->li_bchannel_id = 3 - plci->li_bchannel_id;
  9580. li_config_table[a->li_base + (2 - plci->li_bchannel_id)].plci = splci;
  9581. dbug (1, dprintf ("[%06lx] %s,%d: adv_voice_set_bchannel_id %d",
  9582. (dword)((splci->Id << 8) | UnMapController (splci->adapter->Id)),
  9583. (char *)(FILE_), __LINE__, splci->li_bchannel_id));
  9584. }
  9585. }
  9586. if (li_config_table[a->li_base + (plci->li_bchannel_id - 1)].plci == NULL)
  9587. li_config_table[a->li_base + (plci->li_bchannel_id - 1)].plci = plci;
  9588. }
  9589. }
  9590. }
  9591. if ((old_id == 0) && (plci->li_bchannel_id != 0)
  9592. && (li_config_table[a->li_base + (plci->li_bchannel_id - 1)].plci == plci))
  9593. {
  9594. mixer_clear_config (plci);
  9595. }
  9596. dbug (1, dprintf ("[%06lx] %s,%d: mixer_set_bchannel_id %02x %d",
  9597. (dword)((plci->Id << 8) | UnMapController (plci->adapter->Id)),
  9598. (char *)(FILE_), __LINE__, ch, plci->li_bchannel_id));
  9599. }
  9600. #define MIXER_MAX_DUMP_CHANNELS 34
  9601. static void mixer_calculate_coefs (DIVA_CAPI_ADAPTER *a)
  9602. {
  9603. static char hex_digit_table[0x10] = {'0','1','2','3','4','5','6','7','8','9','a','b','c','d','e','f'};
  9604. word n, i, j;
  9605. char *p;
  9606. char hex_line[2 * MIXER_MAX_DUMP_CHANNELS + MIXER_MAX_DUMP_CHANNELS / 8 + 4];
  9607. dbug (1, dprintf ("[%06lx] %s,%d: mixer_calculate_coefs",
  9608. (dword)(UnMapController (a->Id)), (char *)(FILE_), __LINE__));
  9609. for (i = 0; i < li_total_channels; i++)
  9610. {
  9611. li_config_table[i].channel &= LI_CHANNEL_ADDRESSES_SET;
  9612. if (li_config_table[i].chflags != 0)
  9613. li_config_table[i].channel |= LI_CHANNEL_INVOLVED;
  9614. else
  9615. {
  9616. for (j = 0; j < li_total_channels; j++)
  9617. {
  9618. if (((li_config_table[i].flag_table[j]) != 0)
  9619. || ((li_config_table[j].flag_table[i]) != 0))
  9620. {
  9621. li_config_table[i].channel |= LI_CHANNEL_INVOLVED;
  9622. }
  9623. if (((li_config_table[i].flag_table[j] & LI_FLAG_CONFERENCE) != 0)
  9624. || ((li_config_table[j].flag_table[i] & LI_FLAG_CONFERENCE) != 0))
  9625. {
  9626. li_config_table[i].channel |= LI_CHANNEL_CONFERENCE;
  9627. }
  9628. }
  9629. }
  9630. }
  9631. for (i = 0; i < li_total_channels; i++)
  9632. {
  9633. for (j = 0; j < li_total_channels; j++)
  9634. {
  9635. li_config_table[i].coef_table[j] &= ~(LI_COEF_CH_CH | LI_COEF_CH_PC | LI_COEF_PC_CH | LI_COEF_PC_PC);
  9636. if (li_config_table[i].flag_table[j] & LI_FLAG_CONFERENCE)
  9637. li_config_table[i].coef_table[j] |= LI_COEF_CH_CH;
  9638. }
  9639. }
  9640. for (n = 0; n < li_total_channels; n++)
  9641. {
  9642. if (li_config_table[n].channel & LI_CHANNEL_CONFERENCE)
  9643. {
  9644. for (i = 0; i < li_total_channels; i++)
  9645. {
  9646. if (li_config_table[i].channel & LI_CHANNEL_CONFERENCE)
  9647. {
  9648. for (j = 0; j < li_total_channels; j++)
  9649. {
  9650. li_config_table[i].coef_table[j] |=
  9651. li_config_table[i].coef_table[n] & li_config_table[n].coef_table[j];
  9652. }
  9653. }
  9654. }
  9655. }
  9656. }
  9657. for (i = 0; i < li_total_channels; i++)
  9658. {
  9659. if (li_config_table[i].channel & LI_CHANNEL_INVOLVED)
  9660. {
  9661. li_config_table[i].coef_table[i] &= ~LI_COEF_CH_CH;
  9662. for (j = 0; j < li_total_channels; j++)
  9663. {
  9664. if (li_config_table[i].coef_table[j] & LI_COEF_CH_CH)
  9665. li_config_table[i].flag_table[j] |= LI_FLAG_CONFERENCE;
  9666. }
  9667. if (li_config_table[i].flag_table[i] & LI_FLAG_CONFERENCE)
  9668. li_config_table[i].coef_table[i] |= LI_COEF_CH_CH;
  9669. }
  9670. }
  9671. for (i = 0; i < li_total_channels; i++)
  9672. {
  9673. if (li_config_table[i].channel & LI_CHANNEL_INVOLVED)
  9674. {
  9675. for (j = 0; j < li_total_channels; j++)
  9676. {
  9677. if (li_config_table[i].flag_table[j] & LI_FLAG_INTERCONNECT)
  9678. li_config_table[i].coef_table[j] |= LI_COEF_CH_CH;
  9679. if (li_config_table[i].flag_table[j] & LI_FLAG_MONITOR)
  9680. li_config_table[i].coef_table[j] |= LI_COEF_CH_PC;
  9681. if (li_config_table[i].flag_table[j] & LI_FLAG_MIX)
  9682. li_config_table[i].coef_table[j] |= LI_COEF_PC_CH;
  9683. if (li_config_table[i].flag_table[j] & LI_FLAG_PCCONNECT)
  9684. li_config_table[i].coef_table[j] |= LI_COEF_PC_PC;
  9685. }
  9686. if (li_config_table[i].chflags & LI_CHFLAG_MONITOR)
  9687. {
  9688. for (j = 0; j < li_total_channels; j++)
  9689. {
  9690. if (li_config_table[i].flag_table[j] & LI_FLAG_INTERCONNECT)
  9691. {
  9692. li_config_table[i].coef_table[j] |= LI_COEF_CH_PC;
  9693. if (li_config_table[j].chflags & LI_CHFLAG_MIX)
  9694. li_config_table[i].coef_table[j] |= LI_COEF_PC_CH | LI_COEF_PC_PC;
  9695. }
  9696. }
  9697. }
  9698. if (li_config_table[i].chflags & LI_CHFLAG_MIX)
  9699. {
  9700. for (j = 0; j < li_total_channels; j++)
  9701. {
  9702. if (li_config_table[j].flag_table[i] & LI_FLAG_INTERCONNECT)
  9703. li_config_table[j].coef_table[i] |= LI_COEF_PC_CH;
  9704. }
  9705. }
  9706. if (li_config_table[i].chflags & LI_CHFLAG_LOOP)
  9707. {
  9708. for (j = 0; j < li_total_channels; j++)
  9709. {
  9710. if (li_config_table[i].flag_table[j] & LI_FLAG_INTERCONNECT)
  9711. {
  9712. for (n = 0; n < li_total_channels; n++)
  9713. {
  9714. if (li_config_table[n].flag_table[i] & LI_FLAG_INTERCONNECT)
  9715. {
  9716. li_config_table[n].coef_table[j] |= LI_COEF_CH_CH;
  9717. if (li_config_table[j].chflags & LI_CHFLAG_MIX)
  9718. {
  9719. li_config_table[n].coef_table[j] |= LI_COEF_PC_CH;
  9720. if (li_config_table[n].chflags & LI_CHFLAG_MONITOR)
  9721. li_config_table[n].coef_table[j] |= LI_COEF_CH_PC | LI_COEF_PC_PC;
  9722. }
  9723. else if (li_config_table[n].chflags & LI_CHFLAG_MONITOR)
  9724. li_config_table[n].coef_table[j] |= LI_COEF_CH_PC;
  9725. }
  9726. }
  9727. }
  9728. }
  9729. }
  9730. }
  9731. }
  9732. for (i = 0; i < li_total_channels; i++)
  9733. {
  9734. if (li_config_table[i].channel & LI_CHANNEL_INVOLVED)
  9735. {
  9736. if (li_config_table[i].chflags & (LI_CHFLAG_MONITOR | LI_CHFLAG_MIX | LI_CHFLAG_LOOP))
  9737. li_config_table[i].channel |= LI_CHANNEL_ACTIVE;
  9738. if (li_config_table[i].chflags & LI_CHFLAG_MONITOR)
  9739. li_config_table[i].channel |= LI_CHANNEL_RX_DATA;
  9740. if (li_config_table[i].chflags & LI_CHFLAG_MIX)
  9741. li_config_table[i].channel |= LI_CHANNEL_TX_DATA;
  9742. for (j = 0; j < li_total_channels; j++)
  9743. {
  9744. if ((li_config_table[i].flag_table[j] &
  9745. (LI_FLAG_INTERCONNECT | LI_FLAG_PCCONNECT | LI_FLAG_CONFERENCE | LI_FLAG_MONITOR))
  9746. || (li_config_table[j].flag_table[i] &
  9747. (LI_FLAG_INTERCONNECT | LI_FLAG_PCCONNECT | LI_FLAG_CONFERENCE | LI_FLAG_ANNOUNCEMENT | LI_FLAG_MIX)))
  9748. {
  9749. li_config_table[i].channel |= LI_CHANNEL_ACTIVE;
  9750. }
  9751. if (li_config_table[i].flag_table[j] & (LI_FLAG_PCCONNECT | LI_FLAG_MONITOR))
  9752. li_config_table[i].channel |= LI_CHANNEL_RX_DATA;
  9753. if (li_config_table[j].flag_table[i] & (LI_FLAG_PCCONNECT | LI_FLAG_ANNOUNCEMENT | LI_FLAG_MIX))
  9754. li_config_table[i].channel |= LI_CHANNEL_TX_DATA;
  9755. }
  9756. if (!(li_config_table[i].channel & LI_CHANNEL_ACTIVE))
  9757. {
  9758. li_config_table[i].coef_table[i] |= LI_COEF_PC_CH | LI_COEF_CH_PC;
  9759. li_config_table[i].channel |= LI_CHANNEL_TX_DATA | LI_CHANNEL_RX_DATA;
  9760. }
  9761. }
  9762. }
  9763. for (i = 0; i < li_total_channels; i++)
  9764. {
  9765. if (li_config_table[i].channel & LI_CHANNEL_INVOLVED)
  9766. {
  9767. j = 0;
  9768. while ((j < li_total_channels) && !(li_config_table[i].flag_table[j] & LI_FLAG_ANNOUNCEMENT))
  9769. j++;
  9770. if (j < li_total_channels)
  9771. {
  9772. for (j = 0; j < li_total_channels; j++)
  9773. {
  9774. li_config_table[i].coef_table[j] &= ~(LI_COEF_CH_CH | LI_COEF_PC_CH);
  9775. if (li_config_table[i].flag_table[j] & LI_FLAG_ANNOUNCEMENT)
  9776. li_config_table[i].coef_table[j] |= LI_COEF_PC_CH;
  9777. }
  9778. }
  9779. }
  9780. }
  9781. n = li_total_channels;
  9782. if (n > MIXER_MAX_DUMP_CHANNELS)
  9783. n = MIXER_MAX_DUMP_CHANNELS;
  9784. p = hex_line;
  9785. for (j = 0; j < n; j++)
  9786. {
  9787. if ((j & 0x7) == 0)
  9788. *(p++) = ' ';
  9789. *(p++) = hex_digit_table[li_config_table[j].curchnl >> 4];
  9790. *(p++) = hex_digit_table[li_config_table[j].curchnl & 0xf];
  9791. }
  9792. *p = '\0';
  9793. dbug (1, dprintf ("[%06lx] CURRENT %s",
  9794. (dword)(UnMapController (a->Id)), (char *) hex_line));
  9795. p = hex_line;
  9796. for (j = 0; j < n; j++)
  9797. {
  9798. if ((j & 0x7) == 0)
  9799. *(p++) = ' ';
  9800. *(p++) = hex_digit_table[li_config_table[j].channel >> 4];
  9801. *(p++) = hex_digit_table[li_config_table[j].channel & 0xf];
  9802. }
  9803. *p = '\0';
  9804. dbug (1, dprintf ("[%06lx] CHANNEL %s",
  9805. (dword)(UnMapController (a->Id)), (char *) hex_line));
  9806. p = hex_line;
  9807. for (j = 0; j < n; j++)
  9808. {
  9809. if ((j & 0x7) == 0)
  9810. *(p++) = ' ';
  9811. *(p++) = hex_digit_table[li_config_table[j].chflags >> 4];
  9812. *(p++) = hex_digit_table[li_config_table[j].chflags & 0xf];
  9813. }
  9814. *p = '\0';
  9815. dbug (1, dprintf ("[%06lx] CHFLAG %s",
  9816. (dword)(UnMapController (a->Id)), (char *) hex_line));
  9817. for (i = 0; i < n; i++)
  9818. {
  9819. p = hex_line;
  9820. for (j = 0; j < n; j++)
  9821. {
  9822. if ((j & 0x7) == 0)
  9823. *(p++) = ' ';
  9824. *(p++) = hex_digit_table[li_config_table[i].flag_table[j] >> 4];
  9825. *(p++) = hex_digit_table[li_config_table[i].flag_table[j] & 0xf];
  9826. }
  9827. *p = '\0';
  9828. dbug (1, dprintf ("[%06lx] FLAG[%02x]%s",
  9829. (dword)(UnMapController (a->Id)), i, (char *) hex_line));
  9830. }
  9831. for (i = 0; i < n; i++)
  9832. {
  9833. p = hex_line;
  9834. for (j = 0; j < n; j++)
  9835. {
  9836. if ((j & 0x7) == 0)
  9837. *(p++) = ' ';
  9838. *(p++) = hex_digit_table[li_config_table[i].coef_table[j] >> 4];
  9839. *(p++) = hex_digit_table[li_config_table[i].coef_table[j] & 0xf];
  9840. }
  9841. *p = '\0';
  9842. dbug (1, dprintf ("[%06lx] COEF[%02x]%s",
  9843. (dword)(UnMapController (a->Id)), i, (char *) hex_line));
  9844. }
  9845. }
  9846. static struct
  9847. {
  9848. byte mask;
  9849. byte line_flags;
  9850. } mixer_write_prog_pri[] =
  9851. {
  9852. { LI_COEF_CH_CH, 0 },
  9853. { LI_COEF_CH_PC, MIXER_COEF_LINE_TO_PC_FLAG },
  9854. { LI_COEF_PC_CH, MIXER_COEF_LINE_FROM_PC_FLAG },
  9855. { LI_COEF_PC_PC, MIXER_COEF_LINE_TO_PC_FLAG | MIXER_COEF_LINE_FROM_PC_FLAG }
  9856. };
  9857. static struct
  9858. {
  9859. byte from_ch;
  9860. byte to_ch;
  9861. byte mask;
  9862. byte xconnect_override;
  9863. } mixer_write_prog_bri[] =
  9864. {
  9865. { 0, 0, LI_COEF_CH_CH, 0x01 }, /* B to B */
  9866. { 1, 0, LI_COEF_CH_CH, 0x01 }, /* Alt B to B */
  9867. { 0, 0, LI_COEF_PC_CH, 0x80 }, /* PC to B */
  9868. { 1, 0, LI_COEF_PC_CH, 0x01 }, /* Alt PC to B */
  9869. { 2, 0, LI_COEF_CH_CH, 0x00 }, /* IC to B */
  9870. { 3, 0, LI_COEF_CH_CH, 0x00 }, /* Alt IC to B */
  9871. { 0, 0, LI_COEF_CH_PC, 0x80 }, /* B to PC */
  9872. { 1, 0, LI_COEF_CH_PC, 0x01 }, /* Alt B to PC */
  9873. { 0, 0, LI_COEF_PC_PC, 0x01 }, /* PC to PC */
  9874. { 1, 0, LI_COEF_PC_PC, 0x01 }, /* Alt PC to PC */
  9875. { 2, 0, LI_COEF_CH_PC, 0x00 }, /* IC to PC */
  9876. { 3, 0, LI_COEF_CH_PC, 0x00 }, /* Alt IC to PC */
  9877. { 0, 2, LI_COEF_CH_CH, 0x00 }, /* B to IC */
  9878. { 1, 2, LI_COEF_CH_CH, 0x00 }, /* Alt B to IC */
  9879. { 0, 2, LI_COEF_PC_CH, 0x00 }, /* PC to IC */
  9880. { 1, 2, LI_COEF_PC_CH, 0x00 }, /* Alt PC to IC */
  9881. { 2, 2, LI_COEF_CH_CH, 0x00 }, /* IC to IC */
  9882. { 3, 2, LI_COEF_CH_CH, 0x00 }, /* Alt IC to IC */
  9883. { 1, 1, LI_COEF_CH_CH, 0x01 }, /* Alt B to Alt B */
  9884. { 0, 1, LI_COEF_CH_CH, 0x01 }, /* B to Alt B */
  9885. { 1, 1, LI_COEF_PC_CH, 0x80 }, /* Alt PC to Alt B */
  9886. { 0, 1, LI_COEF_PC_CH, 0x01 }, /* PC to Alt B */
  9887. { 3, 1, LI_COEF_CH_CH, 0x00 }, /* Alt IC to Alt B */
  9888. { 2, 1, LI_COEF_CH_CH, 0x00 }, /* IC to Alt B */
  9889. { 1, 1, LI_COEF_CH_PC, 0x80 }, /* Alt B to Alt PC */
  9890. { 0, 1, LI_COEF_CH_PC, 0x01 }, /* B to Alt PC */
  9891. { 1, 1, LI_COEF_PC_PC, 0x01 }, /* Alt PC to Alt PC */
  9892. { 0, 1, LI_COEF_PC_PC, 0x01 }, /* PC to Alt PC */
  9893. { 3, 1, LI_COEF_CH_PC, 0x00 }, /* Alt IC to Alt PC */
  9894. { 2, 1, LI_COEF_CH_PC, 0x00 }, /* IC to Alt PC */
  9895. { 1, 3, LI_COEF_CH_CH, 0x00 }, /* Alt B to Alt IC */
  9896. { 0, 3, LI_COEF_CH_CH, 0x00 }, /* B to Alt IC */
  9897. { 1, 3, LI_COEF_PC_CH, 0x00 }, /* Alt PC to Alt IC */
  9898. { 0, 3, LI_COEF_PC_CH, 0x00 }, /* PC to Alt IC */
  9899. { 3, 3, LI_COEF_CH_CH, 0x00 }, /* Alt IC to Alt IC */
  9900. { 2, 3, LI_COEF_CH_CH, 0x00 } /* IC to Alt IC */
  9901. };
  9902. static byte mixer_swapped_index_bri[] =
  9903. {
  9904. 18, /* B to B */
  9905. 19, /* Alt B to B */
  9906. 20, /* PC to B */
  9907. 21, /* Alt PC to B */
  9908. 22, /* IC to B */
  9909. 23, /* Alt IC to B */
  9910. 24, /* B to PC */
  9911. 25, /* Alt B to PC */
  9912. 26, /* PC to PC */
  9913. 27, /* Alt PC to PC */
  9914. 28, /* IC to PC */
  9915. 29, /* Alt IC to PC */
  9916. 30, /* B to IC */
  9917. 31, /* Alt B to IC */
  9918. 32, /* PC to IC */
  9919. 33, /* Alt PC to IC */
  9920. 34, /* IC to IC */
  9921. 35, /* Alt IC to IC */
  9922. 0, /* Alt B to Alt B */
  9923. 1, /* B to Alt B */
  9924. 2, /* Alt PC to Alt B */
  9925. 3, /* PC to Alt B */
  9926. 4, /* Alt IC to Alt B */
  9927. 5, /* IC to Alt B */
  9928. 6, /* Alt B to Alt PC */
  9929. 7, /* B to Alt PC */
  9930. 8, /* Alt PC to Alt PC */
  9931. 9, /* PC to Alt PC */
  9932. 10, /* Alt IC to Alt PC */
  9933. 11, /* IC to Alt PC */
  9934. 12, /* Alt B to Alt IC */
  9935. 13, /* B to Alt IC */
  9936. 14, /* Alt PC to Alt IC */
  9937. 15, /* PC to Alt IC */
  9938. 16, /* Alt IC to Alt IC */
  9939. 17 /* IC to Alt IC */
  9940. };
  9941. static struct
  9942. {
  9943. byte mask;
  9944. byte from_pc;
  9945. byte to_pc;
  9946. } xconnect_write_prog[] =
  9947. {
  9948. { LI_COEF_CH_CH, false, false },
  9949. { LI_COEF_CH_PC, false, true },
  9950. { LI_COEF_PC_CH, true, false },
  9951. { LI_COEF_PC_PC, true, true }
  9952. };
  9953. static void xconnect_query_addresses (PLCI *plci)
  9954. {
  9955. DIVA_CAPI_ADAPTER *a;
  9956. word w, ch;
  9957. byte *p;
  9958. dbug (1, dprintf ("[%06lx] %s,%d: xconnect_query_addresses",
  9959. (dword)((plci->Id << 8) | UnMapController (plci->adapter->Id)),
  9960. (char *)(FILE_), __LINE__));
  9961. a = plci->adapter;
  9962. if (a->li_pri && ((plci->li_bchannel_id == 0)
  9963. || (li_config_table[a->li_base + (plci->li_bchannel_id - 1)].plci != plci)))
  9964. {
  9965. dbug (1, dprintf ("[%06x] %s,%d: Channel id wiped out",
  9966. (dword)((plci->Id << 8) | UnMapController (plci->adapter->Id)),
  9967. (char *)(FILE_), __LINE__));
  9968. return;
  9969. }
  9970. p = plci->internal_req_buffer;
  9971. ch = (a->li_pri) ? plci->li_bchannel_id - 1 : 0;
  9972. *(p++) = UDATA_REQUEST_XCONNECT_FROM;
  9973. w = ch;
  9974. *(p++) = (byte) w;
  9975. *(p++) = (byte)(w >> 8);
  9976. w = ch | XCONNECT_CHANNEL_PORT_PC;
  9977. *(p++) = (byte) w;
  9978. *(p++) = (byte)(w >> 8);
  9979. plci->NData[0].P = plci->internal_req_buffer;
  9980. plci->NData[0].PLength = p - plci->internal_req_buffer;
  9981. plci->NL.X = plci->NData;
  9982. plci->NL.ReqCh = 0;
  9983. plci->NL.Req = plci->nl_req = (byte) N_UDATA;
  9984. plci->adapter->request (&plci->NL);
  9985. }
  9986. static void xconnect_write_coefs (PLCI *plci, word internal_command)
  9987. {
  9988. dbug (1, dprintf ("[%06lx] %s,%d: xconnect_write_coefs %04x",
  9989. (dword)((plci->Id << 8) | UnMapController (plci->adapter->Id)),
  9990. (char *)(FILE_), __LINE__, internal_command));
  9991. plci->li_write_command = internal_command;
  9992. plci->li_write_channel = 0;
  9993. }
  9994. static byte xconnect_write_coefs_process (dword Id, PLCI *plci, byte Rc)
  9995. {
  9996. DIVA_CAPI_ADAPTER *a;
  9997. word w, n, i, j, r, s, to_ch;
  9998. dword d;
  9999. byte *p;
  10000. struct xconnect_transfer_address_s *transfer_address;
  10001. byte ch_map[MIXER_CHANNELS_BRI];
  10002. dbug (1, dprintf ("[%06x] %s,%d: xconnect_write_coefs_process %02x %d",
  10003. UnMapId (Id), (char *)(FILE_), __LINE__, Rc, plci->li_write_channel));
  10004. a = plci->adapter;
  10005. if ((plci->li_bchannel_id == 0)
  10006. || (li_config_table[a->li_base + (plci->li_bchannel_id - 1)].plci != plci))
  10007. {
  10008. dbug (1, dprintf ("[%06x] %s,%d: Channel id wiped out",
  10009. UnMapId (Id), (char *)(FILE_), __LINE__));
  10010. return (true);
  10011. }
  10012. i = a->li_base + (plci->li_bchannel_id - 1);
  10013. j = plci->li_write_channel;
  10014. p = plci->internal_req_buffer;
  10015. if (j != 0)
  10016. {
  10017. if ((Rc != OK) && (Rc != OK_FC))
  10018. {
  10019. dbug (1, dprintf ("[%06lx] %s,%d: LI write coefs failed %02x",
  10020. UnMapId (Id), (char *)(FILE_), __LINE__, Rc));
  10021. return (false);
  10022. }
  10023. }
  10024. if (li_config_table[i].adapter->manufacturer_features & MANUFACTURER_FEATURE_XCONNECT)
  10025. {
  10026. r = 0;
  10027. s = 0;
  10028. if (j < li_total_channels)
  10029. {
  10030. if (li_config_table[i].channel & LI_CHANNEL_ADDRESSES_SET)
  10031. {
  10032. s = ((li_config_table[i].send_b.card_address.low | li_config_table[i].send_b.card_address.high) ?
  10033. (LI_COEF_CH_CH | LI_COEF_CH_PC | LI_COEF_PC_CH | LI_COEF_PC_PC) : (LI_COEF_CH_PC | LI_COEF_PC_PC)) &
  10034. ((li_config_table[i].send_pc.card_address.low | li_config_table[i].send_pc.card_address.high) ?
  10035. (LI_COEF_CH_CH | LI_COEF_CH_PC | LI_COEF_PC_CH | LI_COEF_PC_PC) : (LI_COEF_CH_CH | LI_COEF_PC_CH));
  10036. }
  10037. r = ((li_config_table[i].coef_table[j] & 0xf) ^ (li_config_table[i].coef_table[j] >> 4));
  10038. while ((j < li_total_channels)
  10039. && ((r == 0)
  10040. || (!(li_config_table[j].channel & LI_CHANNEL_ADDRESSES_SET))
  10041. || (!li_config_table[j].adapter->li_pri
  10042. && (j >= li_config_table[j].adapter->li_base + MIXER_BCHANNELS_BRI))
  10043. || (((li_config_table[j].send_b.card_address.low != li_config_table[i].send_b.card_address.low)
  10044. || (li_config_table[j].send_b.card_address.high != li_config_table[i].send_b.card_address.high))
  10045. && (!(a->manufacturer_features & MANUFACTURER_FEATURE_DMACONNECT)
  10046. || !(li_config_table[j].adapter->manufacturer_features & MANUFACTURER_FEATURE_DMACONNECT)))
  10047. || ((li_config_table[j].adapter->li_base != a->li_base)
  10048. && !(r & s &
  10049. ((li_config_table[j].send_b.card_address.low | li_config_table[j].send_b.card_address.high) ?
  10050. (LI_COEF_CH_CH | LI_COEF_CH_PC | LI_COEF_PC_CH | LI_COEF_PC_PC) : (LI_COEF_PC_CH | LI_COEF_PC_PC)) &
  10051. ((li_config_table[j].send_pc.card_address.low | li_config_table[j].send_pc.card_address.high) ?
  10052. (LI_COEF_CH_CH | LI_COEF_CH_PC | LI_COEF_PC_CH | LI_COEF_PC_PC) : (LI_COEF_CH_CH | LI_COEF_CH_PC))))))
  10053. {
  10054. j++;
  10055. if (j < li_total_channels)
  10056. r = ((li_config_table[i].coef_table[j] & 0xf) ^ (li_config_table[i].coef_table[j] >> 4));
  10057. }
  10058. }
  10059. if (j < li_total_channels)
  10060. {
  10061. plci->internal_command = plci->li_write_command;
  10062. if (plci_nl_busy (plci))
  10063. return (true);
  10064. to_ch = (a->li_pri) ? plci->li_bchannel_id - 1 : 0;
  10065. *(p++) = UDATA_REQUEST_XCONNECT_TO;
  10066. do
  10067. {
  10068. if (li_config_table[j].adapter->li_base != a->li_base)
  10069. {
  10070. r &= s &
  10071. ((li_config_table[j].send_b.card_address.low | li_config_table[j].send_b.card_address.high) ?
  10072. (LI_COEF_CH_CH | LI_COEF_CH_PC | LI_COEF_PC_CH | LI_COEF_PC_PC) : (LI_COEF_PC_CH | LI_COEF_PC_PC)) &
  10073. ((li_config_table[j].send_pc.card_address.low | li_config_table[j].send_pc.card_address.high) ?
  10074. (LI_COEF_CH_CH | LI_COEF_CH_PC | LI_COEF_PC_CH | LI_COEF_PC_PC) : (LI_COEF_CH_CH | LI_COEF_CH_PC));
  10075. }
  10076. n = 0;
  10077. do
  10078. {
  10079. if (r & xconnect_write_prog[n].mask)
  10080. {
  10081. if (xconnect_write_prog[n].from_pc)
  10082. transfer_address = &(li_config_table[j].send_pc);
  10083. else
  10084. transfer_address = &(li_config_table[j].send_b);
  10085. d = transfer_address->card_address.low;
  10086. *(p++) = (byte) d;
  10087. *(p++) = (byte)(d >> 8);
  10088. *(p++) = (byte)(d >> 16);
  10089. *(p++) = (byte)(d >> 24);
  10090. d = transfer_address->card_address.high;
  10091. *(p++) = (byte) d;
  10092. *(p++) = (byte)(d >> 8);
  10093. *(p++) = (byte)(d >> 16);
  10094. *(p++) = (byte)(d >> 24);
  10095. d = transfer_address->offset;
  10096. *(p++) = (byte) d;
  10097. *(p++) = (byte)(d >> 8);
  10098. *(p++) = (byte)(d >> 16);
  10099. *(p++) = (byte)(d >> 24);
  10100. w = xconnect_write_prog[n].to_pc ? to_ch | XCONNECT_CHANNEL_PORT_PC : to_ch;
  10101. *(p++) = (byte) w;
  10102. *(p++) = (byte)(w >> 8);
  10103. w = ((li_config_table[i].coef_table[j] & xconnect_write_prog[n].mask) == 0) ? 0x01 :
  10104. (li_config_table[i].adapter->u_law ?
  10105. (li_config_table[j].adapter->u_law ? 0x80 : 0x86) :
  10106. (li_config_table[j].adapter->u_law ? 0x7a : 0x80));
  10107. *(p++) = (byte) w;
  10108. *(p++) = (byte) 0;
  10109. li_config_table[i].coef_table[j] ^= xconnect_write_prog[n].mask << 4;
  10110. }
  10111. n++;
  10112. } while ((n < ARRAY_SIZE(xconnect_write_prog))
  10113. && ((p - plci->internal_req_buffer) + 16 < INTERNAL_REQ_BUFFER_SIZE));
  10114. if (n == ARRAY_SIZE(xconnect_write_prog))
  10115. {
  10116. do
  10117. {
  10118. j++;
  10119. if (j < li_total_channels)
  10120. r = ((li_config_table[i].coef_table[j] & 0xf) ^ (li_config_table[i].coef_table[j] >> 4));
  10121. } while ((j < li_total_channels)
  10122. && ((r == 0)
  10123. || (!(li_config_table[j].channel & LI_CHANNEL_ADDRESSES_SET))
  10124. || (!li_config_table[j].adapter->li_pri
  10125. && (j >= li_config_table[j].adapter->li_base + MIXER_BCHANNELS_BRI))
  10126. || (((li_config_table[j].send_b.card_address.low != li_config_table[i].send_b.card_address.low)
  10127. || (li_config_table[j].send_b.card_address.high != li_config_table[i].send_b.card_address.high))
  10128. && (!(a->manufacturer_features & MANUFACTURER_FEATURE_DMACONNECT)
  10129. || !(li_config_table[j].adapter->manufacturer_features & MANUFACTURER_FEATURE_DMACONNECT)))
  10130. || ((li_config_table[j].adapter->li_base != a->li_base)
  10131. && !(r & s &
  10132. ((li_config_table[j].send_b.card_address.low | li_config_table[j].send_b.card_address.high) ?
  10133. (LI_COEF_CH_CH | LI_COEF_CH_PC | LI_COEF_PC_CH | LI_COEF_PC_PC) : (LI_COEF_PC_CH | LI_COEF_PC_PC)) &
  10134. ((li_config_table[j].send_pc.card_address.low | li_config_table[j].send_pc.card_address.high) ?
  10135. (LI_COEF_CH_CH | LI_COEF_CH_PC | LI_COEF_PC_CH | LI_COEF_PC_PC) : (LI_COEF_CH_CH | LI_COEF_CH_PC))))));
  10136. }
  10137. } while ((j < li_total_channels)
  10138. && ((p - plci->internal_req_buffer) + 16 < INTERNAL_REQ_BUFFER_SIZE));
  10139. }
  10140. else if (j == li_total_channels)
  10141. {
  10142. plci->internal_command = plci->li_write_command;
  10143. if (plci_nl_busy (plci))
  10144. return (true);
  10145. if (a->li_pri)
  10146. {
  10147. *(p++) = UDATA_REQUEST_SET_MIXER_COEFS_PRI_SYNC;
  10148. w = 0;
  10149. if (li_config_table[i].channel & LI_CHANNEL_TX_DATA)
  10150. w |= MIXER_FEATURE_ENABLE_TX_DATA;
  10151. if (li_config_table[i].channel & LI_CHANNEL_RX_DATA)
  10152. w |= MIXER_FEATURE_ENABLE_RX_DATA;
  10153. *(p++) = (byte) w;
  10154. *(p++) = (byte)(w >> 8);
  10155. }
  10156. else
  10157. {
  10158. *(p++) = UDATA_REQUEST_SET_MIXER_COEFS_BRI;
  10159. w = 0;
  10160. if ((plci->tel == ADV_VOICE) && (plci == a->AdvSignalPLCI)
  10161. && (ADV_VOICE_NEW_COEF_BASE + sizeof(word) <= a->adv_voice_coef_length))
  10162. {
  10163. w = GET_WORD (a->adv_voice_coef_buffer + ADV_VOICE_NEW_COEF_BASE);
  10164. }
  10165. if (li_config_table[i].channel & LI_CHANNEL_TX_DATA)
  10166. w |= MIXER_FEATURE_ENABLE_TX_DATA;
  10167. if (li_config_table[i].channel & LI_CHANNEL_RX_DATA)
  10168. w |= MIXER_FEATURE_ENABLE_RX_DATA;
  10169. *(p++) = (byte) w;
  10170. *(p++) = (byte)(w >> 8);
  10171. for (j = 0; j < sizeof(ch_map); j += 2)
  10172. {
  10173. if (plci->li_bchannel_id == 2)
  10174. {
  10175. ch_map[j] = (byte)(j+1);
  10176. ch_map[j+1] = (byte) j;
  10177. }
  10178. else
  10179. {
  10180. ch_map[j] = (byte) j;
  10181. ch_map[j+1] = (byte)(j+1);
  10182. }
  10183. }
  10184. for (n = 0; n < ARRAY_SIZE(mixer_write_prog_bri); n++)
  10185. {
  10186. i = a->li_base + ch_map[mixer_write_prog_bri[n].to_ch];
  10187. j = a->li_base + ch_map[mixer_write_prog_bri[n].from_ch];
  10188. if (li_config_table[i].channel & li_config_table[j].channel & LI_CHANNEL_INVOLVED)
  10189. {
  10190. *p = (mixer_write_prog_bri[n].xconnect_override != 0) ?
  10191. mixer_write_prog_bri[n].xconnect_override :
  10192. ((li_config_table[i].coef_table[j] & mixer_write_prog_bri[n].mask) ? 0x80 : 0x01);
  10193. if ((i >= a->li_base + MIXER_BCHANNELS_BRI) || (j >= a->li_base + MIXER_BCHANNELS_BRI))
  10194. {
  10195. w = ((li_config_table[i].coef_table[j] & 0xf) ^ (li_config_table[i].coef_table[j] >> 4));
  10196. li_config_table[i].coef_table[j] ^= (w & mixer_write_prog_bri[n].mask) << 4;
  10197. }
  10198. }
  10199. else
  10200. {
  10201. *p = 0x00;
  10202. if ((a->AdvSignalPLCI != NULL) && (a->AdvSignalPLCI->tel == ADV_VOICE))
  10203. {
  10204. w = (plci == a->AdvSignalPLCI) ? n : mixer_swapped_index_bri[n];
  10205. if (ADV_VOICE_NEW_COEF_BASE + sizeof(word) + w < a->adv_voice_coef_length)
  10206. *p = a->adv_voice_coef_buffer[ADV_VOICE_NEW_COEF_BASE + sizeof(word) + w];
  10207. }
  10208. }
  10209. p++;
  10210. }
  10211. }
  10212. j = li_total_channels + 1;
  10213. }
  10214. }
  10215. else
  10216. {
  10217. if (j <= li_total_channels)
  10218. {
  10219. plci->internal_command = plci->li_write_command;
  10220. if (plci_nl_busy (plci))
  10221. return (true);
  10222. if (j < a->li_base)
  10223. j = a->li_base;
  10224. if (a->li_pri)
  10225. {
  10226. *(p++) = UDATA_REQUEST_SET_MIXER_COEFS_PRI_SYNC;
  10227. w = 0;
  10228. if (li_config_table[i].channel & LI_CHANNEL_TX_DATA)
  10229. w |= MIXER_FEATURE_ENABLE_TX_DATA;
  10230. if (li_config_table[i].channel & LI_CHANNEL_RX_DATA)
  10231. w |= MIXER_FEATURE_ENABLE_RX_DATA;
  10232. *(p++) = (byte) w;
  10233. *(p++) = (byte)(w >> 8);
  10234. for (n = 0; n < ARRAY_SIZE(mixer_write_prog_pri); n++)
  10235. {
  10236. *(p++) = (byte)((plci->li_bchannel_id - 1) | mixer_write_prog_pri[n].line_flags);
  10237. for (j = a->li_base; j < a->li_base + MIXER_CHANNELS_PRI; j++)
  10238. {
  10239. w = ((li_config_table[i].coef_table[j] & 0xf) ^ (li_config_table[i].coef_table[j] >> 4));
  10240. if (w & mixer_write_prog_pri[n].mask)
  10241. {
  10242. *(p++) = (li_config_table[i].coef_table[j] & mixer_write_prog_pri[n].mask) ? 0x80 : 0x01;
  10243. li_config_table[i].coef_table[j] ^= mixer_write_prog_pri[n].mask << 4;
  10244. }
  10245. else
  10246. *(p++) = 0x00;
  10247. }
  10248. *(p++) = (byte)((plci->li_bchannel_id - 1) | MIXER_COEF_LINE_ROW_FLAG | mixer_write_prog_pri[n].line_flags);
  10249. for (j = a->li_base; j < a->li_base + MIXER_CHANNELS_PRI; j++)
  10250. {
  10251. w = ((li_config_table[j].coef_table[i] & 0xf) ^ (li_config_table[j].coef_table[i] >> 4));
  10252. if (w & mixer_write_prog_pri[n].mask)
  10253. {
  10254. *(p++) = (li_config_table[j].coef_table[i] & mixer_write_prog_pri[n].mask) ? 0x80 : 0x01;
  10255. li_config_table[j].coef_table[i] ^= mixer_write_prog_pri[n].mask << 4;
  10256. }
  10257. else
  10258. *(p++) = 0x00;
  10259. }
  10260. }
  10261. }
  10262. else
  10263. {
  10264. *(p++) = UDATA_REQUEST_SET_MIXER_COEFS_BRI;
  10265. w = 0;
  10266. if ((plci->tel == ADV_VOICE) && (plci == a->AdvSignalPLCI)
  10267. && (ADV_VOICE_NEW_COEF_BASE + sizeof(word) <= a->adv_voice_coef_length))
  10268. {
  10269. w = GET_WORD (a->adv_voice_coef_buffer + ADV_VOICE_NEW_COEF_BASE);
  10270. }
  10271. if (li_config_table[i].channel & LI_CHANNEL_TX_DATA)
  10272. w |= MIXER_FEATURE_ENABLE_TX_DATA;
  10273. if (li_config_table[i].channel & LI_CHANNEL_RX_DATA)
  10274. w |= MIXER_FEATURE_ENABLE_RX_DATA;
  10275. *(p++) = (byte) w;
  10276. *(p++) = (byte)(w >> 8);
  10277. for (j = 0; j < sizeof(ch_map); j += 2)
  10278. {
  10279. if (plci->li_bchannel_id == 2)
  10280. {
  10281. ch_map[j] = (byte)(j+1);
  10282. ch_map[j+1] = (byte) j;
  10283. }
  10284. else
  10285. {
  10286. ch_map[j] = (byte) j;
  10287. ch_map[j+1] = (byte)(j+1);
  10288. }
  10289. }
  10290. for (n = 0; n < ARRAY_SIZE(mixer_write_prog_bri); n++)
  10291. {
  10292. i = a->li_base + ch_map[mixer_write_prog_bri[n].to_ch];
  10293. j = a->li_base + ch_map[mixer_write_prog_bri[n].from_ch];
  10294. if (li_config_table[i].channel & li_config_table[j].channel & LI_CHANNEL_INVOLVED)
  10295. {
  10296. *p = ((li_config_table[i].coef_table[j] & mixer_write_prog_bri[n].mask) ? 0x80 : 0x01);
  10297. w = ((li_config_table[i].coef_table[j] & 0xf) ^ (li_config_table[i].coef_table[j] >> 4));
  10298. li_config_table[i].coef_table[j] ^= (w & mixer_write_prog_bri[n].mask) << 4;
  10299. }
  10300. else
  10301. {
  10302. *p = 0x00;
  10303. if ((a->AdvSignalPLCI != NULL) && (a->AdvSignalPLCI->tel == ADV_VOICE))
  10304. {
  10305. w = (plci == a->AdvSignalPLCI) ? n : mixer_swapped_index_bri[n];
  10306. if (ADV_VOICE_NEW_COEF_BASE + sizeof(word) + w < a->adv_voice_coef_length)
  10307. *p = a->adv_voice_coef_buffer[ADV_VOICE_NEW_COEF_BASE + sizeof(word) + w];
  10308. }
  10309. }
  10310. p++;
  10311. }
  10312. }
  10313. j = li_total_channels + 1;
  10314. }
  10315. }
  10316. plci->li_write_channel = j;
  10317. if (p != plci->internal_req_buffer)
  10318. {
  10319. plci->NData[0].P = plci->internal_req_buffer;
  10320. plci->NData[0].PLength = p - plci->internal_req_buffer;
  10321. plci->NL.X = plci->NData;
  10322. plci->NL.ReqCh = 0;
  10323. plci->NL.Req = plci->nl_req = (byte) N_UDATA;
  10324. plci->adapter->request (&plci->NL);
  10325. }
  10326. return (true);
  10327. }
  10328. static void mixer_notify_update (PLCI *plci, byte others)
  10329. {
  10330. DIVA_CAPI_ADAPTER *a;
  10331. word i, w;
  10332. PLCI *notify_plci;
  10333. byte msg[sizeof(CAPI_MSG_HEADER) + 6];
  10334. dbug (1, dprintf ("[%06lx] %s,%d: mixer_notify_update %d",
  10335. (dword)((plci->Id << 8) | UnMapController (plci->adapter->Id)),
  10336. (char *)(FILE_), __LINE__, others));
  10337. a = plci->adapter;
  10338. if (a->profile.Global_Options & GL_LINE_INTERCONNECT_SUPPORTED)
  10339. {
  10340. if (others)
  10341. plci->li_notify_update = true;
  10342. i = 0;
  10343. do
  10344. {
  10345. notify_plci = NULL;
  10346. if (others)
  10347. {
  10348. while ((i < li_total_channels) && (li_config_table[i].plci == NULL))
  10349. i++;
  10350. if (i < li_total_channels)
  10351. notify_plci = li_config_table[i++].plci;
  10352. }
  10353. else
  10354. {
  10355. if ((plci->li_bchannel_id != 0)
  10356. && (li_config_table[a->li_base + (plci->li_bchannel_id - 1)].plci == plci))
  10357. {
  10358. notify_plci = plci;
  10359. }
  10360. }
  10361. if ((notify_plci != NULL)
  10362. && !notify_plci->li_notify_update
  10363. && (notify_plci->appl != NULL)
  10364. && (notify_plci->State)
  10365. && notify_plci->NL.Id && !notify_plci->nl_remove_id)
  10366. {
  10367. notify_plci->li_notify_update = true;
  10368. ((CAPI_MSG *) msg)->header.length = 18;
  10369. ((CAPI_MSG *) msg)->header.appl_id = notify_plci->appl->Id;
  10370. ((CAPI_MSG *) msg)->header.command = _FACILITY_R;
  10371. ((CAPI_MSG *) msg)->header.number = 0;
  10372. ((CAPI_MSG *) msg)->header.controller = notify_plci->adapter->Id;
  10373. ((CAPI_MSG *) msg)->header.plci = notify_plci->Id;
  10374. ((CAPI_MSG *) msg)->header.ncci = 0;
  10375. ((CAPI_MSG *) msg)->info.facility_req.Selector = SELECTOR_LINE_INTERCONNECT;
  10376. ((CAPI_MSG *) msg)->info.facility_req.structs[0] = 3;
  10377. PUT_WORD (&(((CAPI_MSG *) msg)->info.facility_req.structs[1]), LI_REQ_SILENT_UPDATE);
  10378. ((CAPI_MSG *) msg)->info.facility_req.structs[3] = 0;
  10379. w = api_put (notify_plci->appl, (CAPI_MSG *) msg);
  10380. if (w != _QUEUE_FULL)
  10381. {
  10382. if (w != 0)
  10383. {
  10384. dbug (1, dprintf ("[%06lx] %s,%d: Interconnect notify failed %06x %d",
  10385. (dword)((plci->Id << 8) | UnMapController (plci->adapter->Id)),
  10386. (char *)(FILE_), __LINE__,
  10387. (dword)((notify_plci->Id << 8) | UnMapController (notify_plci->adapter->Id)), w));
  10388. }
  10389. notify_plci->li_notify_update = false;
  10390. }
  10391. }
  10392. } while (others && (notify_plci != NULL));
  10393. if (others)
  10394. plci->li_notify_update = false;
  10395. }
  10396. }
  10397. static void mixer_clear_config (PLCI *plci)
  10398. {
  10399. DIVA_CAPI_ADAPTER *a;
  10400. word i, j;
  10401. dbug (1, dprintf ("[%06lx] %s,%d: mixer_clear_config",
  10402. (dword)((plci->Id << 8) | UnMapController (plci->adapter->Id)),
  10403. (char *)(FILE_), __LINE__));
  10404. plci->li_notify_update = false;
  10405. plci->li_plci_b_write_pos = 0;
  10406. plci->li_plci_b_read_pos = 0;
  10407. plci->li_plci_b_req_pos = 0;
  10408. a = plci->adapter;
  10409. if ((plci->li_bchannel_id != 0)
  10410. && (li_config_table[a->li_base + (plci->li_bchannel_id - 1)].plci == plci))
  10411. {
  10412. i = a->li_base + (plci->li_bchannel_id - 1);
  10413. li_config_table[i].curchnl = 0;
  10414. li_config_table[i].channel = 0;
  10415. li_config_table[i].chflags = 0;
  10416. for (j = 0; j < li_total_channels; j++)
  10417. {
  10418. li_config_table[j].flag_table[i] = 0;
  10419. li_config_table[i].flag_table[j] = 0;
  10420. li_config_table[i].coef_table[j] = 0;
  10421. li_config_table[j].coef_table[i] = 0;
  10422. }
  10423. if (!a->li_pri)
  10424. {
  10425. li_config_table[i].coef_table[i] |= LI_COEF_CH_PC_SET | LI_COEF_PC_CH_SET;
  10426. if ((plci->tel == ADV_VOICE) && (plci == a->AdvSignalPLCI))
  10427. {
  10428. i = a->li_base + MIXER_IC_CHANNEL_BASE + (plci->li_bchannel_id - 1);
  10429. li_config_table[i].curchnl = 0;
  10430. li_config_table[i].channel = 0;
  10431. li_config_table[i].chflags = 0;
  10432. for (j = 0; j < li_total_channels; j++)
  10433. {
  10434. li_config_table[i].flag_table[j] = 0;
  10435. li_config_table[j].flag_table[i] = 0;
  10436. li_config_table[i].coef_table[j] = 0;
  10437. li_config_table[j].coef_table[i] = 0;
  10438. }
  10439. if (a->manufacturer_features & MANUFACTURER_FEATURE_SLAVE_CODEC)
  10440. {
  10441. i = a->li_base + MIXER_IC_CHANNEL_BASE + (2 - plci->li_bchannel_id);
  10442. li_config_table[i].curchnl = 0;
  10443. li_config_table[i].channel = 0;
  10444. li_config_table[i].chflags = 0;
  10445. for (j = 0; j < li_total_channels; j++)
  10446. {
  10447. li_config_table[i].flag_table[j] = 0;
  10448. li_config_table[j].flag_table[i] = 0;
  10449. li_config_table[i].coef_table[j] = 0;
  10450. li_config_table[j].coef_table[i] = 0;
  10451. }
  10452. }
  10453. }
  10454. }
  10455. }
  10456. }
  10457. static void mixer_prepare_switch (dword Id, PLCI *plci)
  10458. {
  10459. dbug (1, dprintf ("[%06lx] %s,%d: mixer_prepare_switch",
  10460. UnMapId (Id), (char *)(FILE_), __LINE__));
  10461. do
  10462. {
  10463. mixer_indication_coefs_set (Id, plci);
  10464. } while (plci->li_plci_b_read_pos != plci->li_plci_b_req_pos);
  10465. }
  10466. static word mixer_save_config (dword Id, PLCI *plci, byte Rc)
  10467. {
  10468. DIVA_CAPI_ADAPTER *a;
  10469. word i, j;
  10470. dbug (1, dprintf ("[%06lx] %s,%d: mixer_save_config %02x %d",
  10471. UnMapId (Id), (char *)(FILE_), __LINE__, Rc, plci->adjust_b_state));
  10472. a = plci->adapter;
  10473. if ((plci->li_bchannel_id != 0)
  10474. && (li_config_table[a->li_base + (plci->li_bchannel_id - 1)].plci == plci))
  10475. {
  10476. i = a->li_base + (plci->li_bchannel_id - 1);
  10477. for (j = 0; j < li_total_channels; j++)
  10478. {
  10479. li_config_table[i].coef_table[j] &= 0xf;
  10480. li_config_table[j].coef_table[i] &= 0xf;
  10481. }
  10482. if (!a->li_pri)
  10483. li_config_table[i].coef_table[i] |= LI_COEF_CH_PC_SET | LI_COEF_PC_CH_SET;
  10484. }
  10485. return (GOOD);
  10486. }
  10487. static word mixer_restore_config (dword Id, PLCI *plci, byte Rc)
  10488. {
  10489. DIVA_CAPI_ADAPTER *a;
  10490. word Info;
  10491. dbug (1, dprintf ("[%06lx] %s,%d: mixer_restore_config %02x %d",
  10492. UnMapId (Id), (char *)(FILE_), __LINE__, Rc, plci->adjust_b_state));
  10493. Info = GOOD;
  10494. a = plci->adapter;
  10495. if ((plci->B1_facilities & B1_FACILITY_MIXER)
  10496. && (plci->li_bchannel_id != 0)
  10497. && (li_config_table[a->li_base + (plci->li_bchannel_id - 1)].plci == plci))
  10498. {
  10499. switch (plci->adjust_b_state)
  10500. {
  10501. case ADJUST_B_RESTORE_MIXER_1:
  10502. if (a->manufacturer_features & MANUFACTURER_FEATURE_XCONNECT)
  10503. {
  10504. plci->internal_command = plci->adjust_b_command;
  10505. if (plci_nl_busy (plci))
  10506. {
  10507. plci->adjust_b_state = ADJUST_B_RESTORE_MIXER_1;
  10508. break;
  10509. }
  10510. xconnect_query_addresses (plci);
  10511. plci->adjust_b_state = ADJUST_B_RESTORE_MIXER_2;
  10512. break;
  10513. }
  10514. plci->adjust_b_state = ADJUST_B_RESTORE_MIXER_5;
  10515. Rc = OK;
  10516. case ADJUST_B_RESTORE_MIXER_2:
  10517. case ADJUST_B_RESTORE_MIXER_3:
  10518. case ADJUST_B_RESTORE_MIXER_4:
  10519. if ((Rc != OK) && (Rc != OK_FC) && (Rc != 0))
  10520. {
  10521. dbug (1, dprintf ("[%06lx] %s,%d: Adjust B query addresses failed %02x",
  10522. UnMapId (Id), (char *)(FILE_), __LINE__, Rc));
  10523. Info = _WRONG_STATE;
  10524. break;
  10525. }
  10526. if (Rc == OK)
  10527. {
  10528. if (plci->adjust_b_state == ADJUST_B_RESTORE_MIXER_2)
  10529. plci->adjust_b_state = ADJUST_B_RESTORE_MIXER_3;
  10530. else if (plci->adjust_b_state == ADJUST_B_RESTORE_MIXER_4)
  10531. plci->adjust_b_state = ADJUST_B_RESTORE_MIXER_5;
  10532. }
  10533. else if (Rc == 0)
  10534. {
  10535. if (plci->adjust_b_state == ADJUST_B_RESTORE_MIXER_2)
  10536. plci->adjust_b_state = ADJUST_B_RESTORE_MIXER_4;
  10537. else if (plci->adjust_b_state == ADJUST_B_RESTORE_MIXER_3)
  10538. plci->adjust_b_state = ADJUST_B_RESTORE_MIXER_5;
  10539. }
  10540. if (plci->adjust_b_state != ADJUST_B_RESTORE_MIXER_5)
  10541. {
  10542. plci->internal_command = plci->adjust_b_command;
  10543. break;
  10544. }
  10545. case ADJUST_B_RESTORE_MIXER_5:
  10546. xconnect_write_coefs (plci, plci->adjust_b_command);
  10547. plci->adjust_b_state = ADJUST_B_RESTORE_MIXER_6;
  10548. Rc = OK;
  10549. case ADJUST_B_RESTORE_MIXER_6:
  10550. if (!xconnect_write_coefs_process (Id, plci, Rc))
  10551. {
  10552. dbug (1, dprintf ("[%06lx] %s,%d: Write mixer coefs failed",
  10553. UnMapId (Id), (char *)(FILE_), __LINE__));
  10554. Info = _FACILITY_NOT_SUPPORTED;
  10555. break;
  10556. }
  10557. if (plci->internal_command)
  10558. break;
  10559. plci->adjust_b_state = ADJUST_B_RESTORE_MIXER_7;
  10560. case ADJUST_B_RESTORE_MIXER_7:
  10561. break;
  10562. }
  10563. }
  10564. return (Info);
  10565. }
  10566. static void mixer_command (dword Id, PLCI *plci, byte Rc)
  10567. {
  10568. DIVA_CAPI_ADAPTER *a;
  10569. word i, internal_command, Info;
  10570. dbug (1, dprintf ("[%06lx] %s,%d: mixer_command %02x %04x %04x",
  10571. UnMapId (Id), (char *)(FILE_), __LINE__, Rc, plci->internal_command,
  10572. plci->li_cmd));
  10573. Info = GOOD;
  10574. a = plci->adapter;
  10575. internal_command = plci->internal_command;
  10576. plci->internal_command = 0;
  10577. switch (plci->li_cmd)
  10578. {
  10579. case LI_REQ_CONNECT:
  10580. case LI_REQ_DISCONNECT:
  10581. case LI_REQ_SILENT_UPDATE:
  10582. switch (internal_command)
  10583. {
  10584. default:
  10585. if (plci->li_channel_bits & LI_CHANNEL_INVOLVED)
  10586. {
  10587. adjust_b1_resource (Id, plci, NULL, (word)(plci->B1_facilities |
  10588. B1_FACILITY_MIXER), MIXER_COMMAND_1);
  10589. }
  10590. case MIXER_COMMAND_1:
  10591. if (plci->li_channel_bits & LI_CHANNEL_INVOLVED)
  10592. {
  10593. if (adjust_b_process (Id, plci, Rc) != GOOD)
  10594. {
  10595. dbug (1, dprintf ("[%06lx] %s,%d: Load mixer failed",
  10596. UnMapId (Id), (char *)(FILE_), __LINE__));
  10597. Info = _FACILITY_NOT_SUPPORTED;
  10598. break;
  10599. }
  10600. if (plci->internal_command)
  10601. return;
  10602. }
  10603. plci->li_plci_b_req_pos = plci->li_plci_b_write_pos;
  10604. if ((plci->li_channel_bits & LI_CHANNEL_INVOLVED)
  10605. || ((get_b1_facilities (plci, plci->B1_resource) & B1_FACILITY_MIXER)
  10606. && (add_b1_facilities (plci, plci->B1_resource, (word)(plci->B1_facilities &
  10607. ~B1_FACILITY_MIXER)) == plci->B1_resource)))
  10608. {
  10609. xconnect_write_coefs (plci, MIXER_COMMAND_2);
  10610. }
  10611. else
  10612. {
  10613. do
  10614. {
  10615. mixer_indication_coefs_set (Id, plci);
  10616. } while (plci->li_plci_b_read_pos != plci->li_plci_b_req_pos);
  10617. }
  10618. case MIXER_COMMAND_2:
  10619. if ((plci->li_channel_bits & LI_CHANNEL_INVOLVED)
  10620. || ((get_b1_facilities (plci, plci->B1_resource) & B1_FACILITY_MIXER)
  10621. && (add_b1_facilities (plci, plci->B1_resource, (word)(plci->B1_facilities &
  10622. ~B1_FACILITY_MIXER)) == plci->B1_resource)))
  10623. {
  10624. if (!xconnect_write_coefs_process (Id, plci, Rc))
  10625. {
  10626. dbug (1, dprintf ("[%06lx] %s,%d: Write mixer coefs failed",
  10627. UnMapId (Id), (char *)(FILE_), __LINE__));
  10628. if (plci->li_plci_b_write_pos != plci->li_plci_b_req_pos)
  10629. {
  10630. do
  10631. {
  10632. plci->li_plci_b_write_pos = (plci->li_plci_b_write_pos == 0) ?
  10633. LI_PLCI_B_QUEUE_ENTRIES-1 : plci->li_plci_b_write_pos - 1;
  10634. i = (plci->li_plci_b_write_pos == 0) ?
  10635. LI_PLCI_B_QUEUE_ENTRIES-1 : plci->li_plci_b_write_pos - 1;
  10636. } while ((plci->li_plci_b_write_pos != plci->li_plci_b_req_pos)
  10637. && !(plci->li_plci_b_queue[i] & LI_PLCI_B_LAST_FLAG));
  10638. }
  10639. Info = _FACILITY_NOT_SUPPORTED;
  10640. break;
  10641. }
  10642. if (plci->internal_command)
  10643. return;
  10644. }
  10645. if (!(plci->li_channel_bits & LI_CHANNEL_INVOLVED))
  10646. {
  10647. adjust_b1_resource (Id, plci, NULL, (word)(plci->B1_facilities &
  10648. ~B1_FACILITY_MIXER), MIXER_COMMAND_3);
  10649. }
  10650. case MIXER_COMMAND_3:
  10651. if (!(plci->li_channel_bits & LI_CHANNEL_INVOLVED))
  10652. {
  10653. if (adjust_b_process (Id, plci, Rc) != GOOD)
  10654. {
  10655. dbug (1, dprintf ("[%06lx] %s,%d: Unload mixer failed",
  10656. UnMapId (Id), (char *)(FILE_), __LINE__));
  10657. Info = _FACILITY_NOT_SUPPORTED;
  10658. break;
  10659. }
  10660. if (plci->internal_command)
  10661. return;
  10662. }
  10663. break;
  10664. }
  10665. break;
  10666. }
  10667. if ((plci->li_bchannel_id == 0)
  10668. || (li_config_table[a->li_base + (plci->li_bchannel_id - 1)].plci != plci))
  10669. {
  10670. dbug (1, dprintf ("[%06x] %s,%d: Channel id wiped out %d",
  10671. UnMapId (Id), (char *)(FILE_), __LINE__, (int)(plci->li_bchannel_id)));
  10672. }
  10673. else
  10674. {
  10675. i = a->li_base + (plci->li_bchannel_id - 1);
  10676. li_config_table[i].curchnl = plci->li_channel_bits;
  10677. if (!a->li_pri && (plci->tel == ADV_VOICE) && (plci == a->AdvSignalPLCI))
  10678. {
  10679. i = a->li_base + MIXER_IC_CHANNEL_BASE + (plci->li_bchannel_id - 1);
  10680. li_config_table[i].curchnl = plci->li_channel_bits;
  10681. if (a->manufacturer_features & MANUFACTURER_FEATURE_SLAVE_CODEC)
  10682. {
  10683. i = a->li_base + MIXER_IC_CHANNEL_BASE + (2 - plci->li_bchannel_id);
  10684. li_config_table[i].curchnl = plci->li_channel_bits;
  10685. }
  10686. }
  10687. }
  10688. }
  10689. static void li_update_connect (dword Id, DIVA_CAPI_ADAPTER *a, PLCI *plci,
  10690. dword plci_b_id, byte connect, dword li_flags)
  10691. {
  10692. word i, ch_a, ch_a_v, ch_a_s, ch_b, ch_b_v, ch_b_s;
  10693. PLCI *plci_b;
  10694. DIVA_CAPI_ADAPTER *a_b;
  10695. a_b = &(adapter[MapController ((byte)(plci_b_id & 0x7f)) - 1]);
  10696. plci_b = &(a_b->plci[((plci_b_id >> 8) & 0xff) - 1]);
  10697. ch_a = a->li_base + (plci->li_bchannel_id - 1);
  10698. if (!a->li_pri && (plci->tel == ADV_VOICE)
  10699. && (plci == a->AdvSignalPLCI) && (Id & EXT_CONTROLLER))
  10700. {
  10701. ch_a_v = ch_a + MIXER_IC_CHANNEL_BASE;
  10702. ch_a_s = (a->manufacturer_features & MANUFACTURER_FEATURE_SLAVE_CODEC) ?
  10703. a->li_base + MIXER_IC_CHANNEL_BASE + (2 - plci->li_bchannel_id) : ch_a_v;
  10704. }
  10705. else
  10706. {
  10707. ch_a_v = ch_a;
  10708. ch_a_s = ch_a;
  10709. }
  10710. ch_b = a_b->li_base + (plci_b->li_bchannel_id - 1);
  10711. if (!a_b->li_pri && (plci_b->tel == ADV_VOICE)
  10712. && (plci_b == a_b->AdvSignalPLCI) && (plci_b_id & EXT_CONTROLLER))
  10713. {
  10714. ch_b_v = ch_b + MIXER_IC_CHANNEL_BASE;
  10715. ch_b_s = (a_b->manufacturer_features & MANUFACTURER_FEATURE_SLAVE_CODEC) ?
  10716. a_b->li_base + MIXER_IC_CHANNEL_BASE + (2 - plci_b->li_bchannel_id) : ch_b_v;
  10717. }
  10718. else
  10719. {
  10720. ch_b_v = ch_b;
  10721. ch_b_s = ch_b;
  10722. }
  10723. if (connect)
  10724. {
  10725. li_config_table[ch_a].flag_table[ch_a_v] &= ~LI_FLAG_MONITOR;
  10726. li_config_table[ch_a].flag_table[ch_a_s] &= ~LI_FLAG_MONITOR;
  10727. li_config_table[ch_a_v].flag_table[ch_a] &= ~(LI_FLAG_ANNOUNCEMENT | LI_FLAG_MIX);
  10728. li_config_table[ch_a_s].flag_table[ch_a] &= ~(LI_FLAG_ANNOUNCEMENT | LI_FLAG_MIX);
  10729. }
  10730. li_config_table[ch_a].flag_table[ch_b_v] &= ~LI_FLAG_MONITOR;
  10731. li_config_table[ch_a].flag_table[ch_b_s] &= ~LI_FLAG_MONITOR;
  10732. li_config_table[ch_b_v].flag_table[ch_a] &= ~(LI_FLAG_ANNOUNCEMENT | LI_FLAG_MIX);
  10733. li_config_table[ch_b_s].flag_table[ch_a] &= ~(LI_FLAG_ANNOUNCEMENT | LI_FLAG_MIX);
  10734. if (ch_a_v == ch_b_v)
  10735. {
  10736. li_config_table[ch_a_v].flag_table[ch_b_v] &= ~LI_FLAG_CONFERENCE;
  10737. li_config_table[ch_a_s].flag_table[ch_b_s] &= ~LI_FLAG_CONFERENCE;
  10738. }
  10739. else
  10740. {
  10741. if (li_config_table[ch_a_v].flag_table[ch_b_v] & LI_FLAG_CONFERENCE)
  10742. {
  10743. for (i = 0; i < li_total_channels; i++)
  10744. {
  10745. if (i != ch_a_v)
  10746. li_config_table[ch_a_v].flag_table[i] &= ~LI_FLAG_CONFERENCE;
  10747. }
  10748. }
  10749. if (li_config_table[ch_a_s].flag_table[ch_b_v] & LI_FLAG_CONFERENCE)
  10750. {
  10751. for (i = 0; i < li_total_channels; i++)
  10752. {
  10753. if (i != ch_a_s)
  10754. li_config_table[ch_a_s].flag_table[i] &= ~LI_FLAG_CONFERENCE;
  10755. }
  10756. }
  10757. if (li_config_table[ch_b_v].flag_table[ch_a_v] & LI_FLAG_CONFERENCE)
  10758. {
  10759. for (i = 0; i < li_total_channels; i++)
  10760. {
  10761. if (i != ch_a_v)
  10762. li_config_table[i].flag_table[ch_a_v] &= ~LI_FLAG_CONFERENCE;
  10763. }
  10764. }
  10765. if (li_config_table[ch_b_v].flag_table[ch_a_s] & LI_FLAG_CONFERENCE)
  10766. {
  10767. for (i = 0; i < li_total_channels; i++)
  10768. {
  10769. if (i != ch_a_s)
  10770. li_config_table[i].flag_table[ch_a_s] &= ~LI_FLAG_CONFERENCE;
  10771. }
  10772. }
  10773. }
  10774. if (li_flags & LI_FLAG_CONFERENCE_A_B)
  10775. {
  10776. li_config_table[ch_b_v].flag_table[ch_a_v] |= LI_FLAG_CONFERENCE;
  10777. li_config_table[ch_b_s].flag_table[ch_a_v] |= LI_FLAG_CONFERENCE;
  10778. li_config_table[ch_b_v].flag_table[ch_a_s] |= LI_FLAG_CONFERENCE;
  10779. li_config_table[ch_b_s].flag_table[ch_a_s] |= LI_FLAG_CONFERENCE;
  10780. }
  10781. if (li_flags & LI_FLAG_CONFERENCE_B_A)
  10782. {
  10783. li_config_table[ch_a_v].flag_table[ch_b_v] |= LI_FLAG_CONFERENCE;
  10784. li_config_table[ch_a_v].flag_table[ch_b_s] |= LI_FLAG_CONFERENCE;
  10785. li_config_table[ch_a_s].flag_table[ch_b_v] |= LI_FLAG_CONFERENCE;
  10786. li_config_table[ch_a_s].flag_table[ch_b_s] |= LI_FLAG_CONFERENCE;
  10787. }
  10788. if (li_flags & LI_FLAG_MONITOR_A)
  10789. {
  10790. li_config_table[ch_a].flag_table[ch_a_v] |= LI_FLAG_MONITOR;
  10791. li_config_table[ch_a].flag_table[ch_a_s] |= LI_FLAG_MONITOR;
  10792. }
  10793. if (li_flags & LI_FLAG_MONITOR_B)
  10794. {
  10795. li_config_table[ch_a].flag_table[ch_b_v] |= LI_FLAG_MONITOR;
  10796. li_config_table[ch_a].flag_table[ch_b_s] |= LI_FLAG_MONITOR;
  10797. }
  10798. if (li_flags & LI_FLAG_ANNOUNCEMENT_A)
  10799. {
  10800. li_config_table[ch_a_v].flag_table[ch_a] |= LI_FLAG_ANNOUNCEMENT;
  10801. li_config_table[ch_a_s].flag_table[ch_a] |= LI_FLAG_ANNOUNCEMENT;
  10802. }
  10803. if (li_flags & LI_FLAG_ANNOUNCEMENT_B)
  10804. {
  10805. li_config_table[ch_b_v].flag_table[ch_a] |= LI_FLAG_ANNOUNCEMENT;
  10806. li_config_table[ch_b_s].flag_table[ch_a] |= LI_FLAG_ANNOUNCEMENT;
  10807. }
  10808. if (li_flags & LI_FLAG_MIX_A)
  10809. {
  10810. li_config_table[ch_a_v].flag_table[ch_a] |= LI_FLAG_MIX;
  10811. li_config_table[ch_a_s].flag_table[ch_a] |= LI_FLAG_MIX;
  10812. }
  10813. if (li_flags & LI_FLAG_MIX_B)
  10814. {
  10815. li_config_table[ch_b_v].flag_table[ch_a] |= LI_FLAG_MIX;
  10816. li_config_table[ch_b_s].flag_table[ch_a] |= LI_FLAG_MIX;
  10817. }
  10818. if (ch_a_v != ch_a_s)
  10819. {
  10820. li_config_table[ch_a_v].flag_table[ch_a_s] |= LI_FLAG_CONFERENCE;
  10821. li_config_table[ch_a_s].flag_table[ch_a_v] |= LI_FLAG_CONFERENCE;
  10822. }
  10823. if (ch_b_v != ch_b_s)
  10824. {
  10825. li_config_table[ch_b_v].flag_table[ch_b_s] |= LI_FLAG_CONFERENCE;
  10826. li_config_table[ch_b_s].flag_table[ch_b_v] |= LI_FLAG_CONFERENCE;
  10827. }
  10828. }
  10829. static void li2_update_connect (dword Id, DIVA_CAPI_ADAPTER *a, PLCI *plci,
  10830. dword plci_b_id, byte connect, dword li_flags)
  10831. {
  10832. word ch_a, ch_a_v, ch_a_s, ch_b, ch_b_v, ch_b_s;
  10833. PLCI *plci_b;
  10834. DIVA_CAPI_ADAPTER *a_b;
  10835. a_b = &(adapter[MapController ((byte)(plci_b_id & 0x7f)) - 1]);
  10836. plci_b = &(a_b->plci[((plci_b_id >> 8) & 0xff) - 1]);
  10837. ch_a = a->li_base + (plci->li_bchannel_id - 1);
  10838. if (!a->li_pri && (plci->tel == ADV_VOICE)
  10839. && (plci == a->AdvSignalPLCI) && (Id & EXT_CONTROLLER))
  10840. {
  10841. ch_a_v = ch_a + MIXER_IC_CHANNEL_BASE;
  10842. ch_a_s = (a->manufacturer_features & MANUFACTURER_FEATURE_SLAVE_CODEC) ?
  10843. a->li_base + MIXER_IC_CHANNEL_BASE + (2 - plci->li_bchannel_id) : ch_a_v;
  10844. }
  10845. else
  10846. {
  10847. ch_a_v = ch_a;
  10848. ch_a_s = ch_a;
  10849. }
  10850. ch_b = a_b->li_base + (plci_b->li_bchannel_id - 1);
  10851. if (!a_b->li_pri && (plci_b->tel == ADV_VOICE)
  10852. && (plci_b == a_b->AdvSignalPLCI) && (plci_b_id & EXT_CONTROLLER))
  10853. {
  10854. ch_b_v = ch_b + MIXER_IC_CHANNEL_BASE;
  10855. ch_b_s = (a_b->manufacturer_features & MANUFACTURER_FEATURE_SLAVE_CODEC) ?
  10856. a_b->li_base + MIXER_IC_CHANNEL_BASE + (2 - plci_b->li_bchannel_id) : ch_b_v;
  10857. }
  10858. else
  10859. {
  10860. ch_b_v = ch_b;
  10861. ch_b_s = ch_b;
  10862. }
  10863. if (connect)
  10864. {
  10865. li_config_table[ch_b].flag_table[ch_b_v] &= ~LI_FLAG_MONITOR;
  10866. li_config_table[ch_b].flag_table[ch_b_s] &= ~LI_FLAG_MONITOR;
  10867. li_config_table[ch_b_v].flag_table[ch_b] &= ~LI_FLAG_MIX;
  10868. li_config_table[ch_b_s].flag_table[ch_b] &= ~LI_FLAG_MIX;
  10869. li_config_table[ch_b].flag_table[ch_b] &= ~LI_FLAG_PCCONNECT;
  10870. li_config_table[ch_b].chflags &= ~(LI_CHFLAG_MONITOR | LI_CHFLAG_MIX | LI_CHFLAG_LOOP);
  10871. }
  10872. li_config_table[ch_b_v].flag_table[ch_a_v] &= ~(LI_FLAG_INTERCONNECT | LI_FLAG_CONFERENCE);
  10873. li_config_table[ch_b_s].flag_table[ch_a_v] &= ~(LI_FLAG_INTERCONNECT | LI_FLAG_CONFERENCE);
  10874. li_config_table[ch_b_v].flag_table[ch_a_s] &= ~(LI_FLAG_INTERCONNECT | LI_FLAG_CONFERENCE);
  10875. li_config_table[ch_b_s].flag_table[ch_a_s] &= ~(LI_FLAG_INTERCONNECT | LI_FLAG_CONFERENCE);
  10876. li_config_table[ch_a_v].flag_table[ch_b_v] &= ~(LI_FLAG_INTERCONNECT | LI_FLAG_CONFERENCE);
  10877. li_config_table[ch_a_v].flag_table[ch_b_s] &= ~(LI_FLAG_INTERCONNECT | LI_FLAG_CONFERENCE);
  10878. li_config_table[ch_a_s].flag_table[ch_b_v] &= ~(LI_FLAG_INTERCONNECT | LI_FLAG_CONFERENCE);
  10879. li_config_table[ch_a_s].flag_table[ch_b_s] &= ~(LI_FLAG_INTERCONNECT | LI_FLAG_CONFERENCE);
  10880. if (li_flags & LI2_FLAG_INTERCONNECT_A_B)
  10881. {
  10882. li_config_table[ch_b_v].flag_table[ch_a_v] |= LI_FLAG_INTERCONNECT;
  10883. li_config_table[ch_b_s].flag_table[ch_a_v] |= LI_FLAG_INTERCONNECT;
  10884. li_config_table[ch_b_v].flag_table[ch_a_s] |= LI_FLAG_INTERCONNECT;
  10885. li_config_table[ch_b_s].flag_table[ch_a_s] |= LI_FLAG_INTERCONNECT;
  10886. }
  10887. if (li_flags & LI2_FLAG_INTERCONNECT_B_A)
  10888. {
  10889. li_config_table[ch_a_v].flag_table[ch_b_v] |= LI_FLAG_INTERCONNECT;
  10890. li_config_table[ch_a_v].flag_table[ch_b_s] |= LI_FLAG_INTERCONNECT;
  10891. li_config_table[ch_a_s].flag_table[ch_b_v] |= LI_FLAG_INTERCONNECT;
  10892. li_config_table[ch_a_s].flag_table[ch_b_s] |= LI_FLAG_INTERCONNECT;
  10893. }
  10894. if (li_flags & LI2_FLAG_MONITOR_B)
  10895. {
  10896. li_config_table[ch_b].flag_table[ch_b_v] |= LI_FLAG_MONITOR;
  10897. li_config_table[ch_b].flag_table[ch_b_s] |= LI_FLAG_MONITOR;
  10898. }
  10899. if (li_flags & LI2_FLAG_MIX_B)
  10900. {
  10901. li_config_table[ch_b_v].flag_table[ch_b] |= LI_FLAG_MIX;
  10902. li_config_table[ch_b_s].flag_table[ch_b] |= LI_FLAG_MIX;
  10903. }
  10904. if (li_flags & LI2_FLAG_MONITOR_X)
  10905. li_config_table[ch_b].chflags |= LI_CHFLAG_MONITOR;
  10906. if (li_flags & LI2_FLAG_MIX_X)
  10907. li_config_table[ch_b].chflags |= LI_CHFLAG_MIX;
  10908. if (li_flags & LI2_FLAG_LOOP_B)
  10909. {
  10910. li_config_table[ch_b_v].flag_table[ch_b_v] |= LI_FLAG_INTERCONNECT;
  10911. li_config_table[ch_b_s].flag_table[ch_b_v] |= LI_FLAG_INTERCONNECT;
  10912. li_config_table[ch_b_v].flag_table[ch_b_s] |= LI_FLAG_INTERCONNECT;
  10913. li_config_table[ch_b_s].flag_table[ch_b_s] |= LI_FLAG_INTERCONNECT;
  10914. }
  10915. if (li_flags & LI2_FLAG_LOOP_PC)
  10916. li_config_table[ch_b].flag_table[ch_b] |= LI_FLAG_PCCONNECT;
  10917. if (li_flags & LI2_FLAG_LOOP_X)
  10918. li_config_table[ch_b].chflags |= LI_CHFLAG_LOOP;
  10919. if (li_flags & LI2_FLAG_PCCONNECT_A_B)
  10920. li_config_table[ch_b_s].flag_table[ch_a_s] |= LI_FLAG_PCCONNECT;
  10921. if (li_flags & LI2_FLAG_PCCONNECT_B_A)
  10922. li_config_table[ch_a_s].flag_table[ch_b_s] |= LI_FLAG_PCCONNECT;
  10923. if (ch_a_v != ch_a_s)
  10924. {
  10925. li_config_table[ch_a_v].flag_table[ch_a_s] |= LI_FLAG_CONFERENCE;
  10926. li_config_table[ch_a_s].flag_table[ch_a_v] |= LI_FLAG_CONFERENCE;
  10927. }
  10928. if (ch_b_v != ch_b_s)
  10929. {
  10930. li_config_table[ch_b_v].flag_table[ch_b_s] |= LI_FLAG_CONFERENCE;
  10931. li_config_table[ch_b_s].flag_table[ch_b_v] |= LI_FLAG_CONFERENCE;
  10932. }
  10933. }
  10934. static word li_check_main_plci (dword Id, PLCI *plci)
  10935. {
  10936. if (plci == NULL)
  10937. {
  10938. dbug (1, dprintf ("[%06lx] %s,%d: Wrong PLCI",
  10939. UnMapId (Id), (char *)(FILE_), __LINE__));
  10940. return (_WRONG_IDENTIFIER);
  10941. }
  10942. if (!plci->State
  10943. || !plci->NL.Id || plci->nl_remove_id
  10944. || (plci->li_bchannel_id == 0))
  10945. {
  10946. dbug (1, dprintf ("[%06lx] %s,%d: Wrong state",
  10947. UnMapId (Id), (char *)(FILE_), __LINE__));
  10948. return (_WRONG_STATE);
  10949. }
  10950. li_config_table[plci->adapter->li_base + (plci->li_bchannel_id - 1)].plci = plci;
  10951. return (GOOD);
  10952. }
  10953. static PLCI *li_check_plci_b (dword Id, PLCI *plci,
  10954. dword plci_b_id, word plci_b_write_pos, byte *p_result)
  10955. {
  10956. byte ctlr_b;
  10957. PLCI *plci_b;
  10958. if (((plci->li_plci_b_read_pos > plci_b_write_pos) ? plci->li_plci_b_read_pos :
  10959. LI_PLCI_B_QUEUE_ENTRIES + plci->li_plci_b_read_pos) - plci_b_write_pos - 1 < 2)
  10960. {
  10961. dbug (1, dprintf ("[%06lx] %s,%d: LI request overrun",
  10962. UnMapId (Id), (char *)(FILE_), __LINE__));
  10963. PUT_WORD (p_result, _REQUEST_NOT_ALLOWED_IN_THIS_STATE);
  10964. return (NULL);
  10965. }
  10966. ctlr_b = 0;
  10967. if ((plci_b_id & 0x7f) != 0)
  10968. {
  10969. ctlr_b = MapController ((byte)(plci_b_id & 0x7f));
  10970. if ((ctlr_b > max_adapter) || ((ctlr_b != 0) && (adapter[ctlr_b - 1].request == NULL)))
  10971. ctlr_b = 0;
  10972. }
  10973. if ((ctlr_b == 0)
  10974. || (((plci_b_id >> 8) & 0xff) == 0)
  10975. || (((plci_b_id >> 8) & 0xff) > adapter[ctlr_b - 1].max_plci))
  10976. {
  10977. dbug (1, dprintf ("[%06lx] %s,%d: LI invalid second PLCI %08lx",
  10978. UnMapId (Id), (char *)(FILE_), __LINE__, plci_b_id));
  10979. PUT_WORD (p_result, _WRONG_IDENTIFIER);
  10980. return (NULL);
  10981. }
  10982. plci_b = &(adapter[ctlr_b - 1].plci[((plci_b_id >> 8) & 0xff) - 1]);
  10983. if (!plci_b->State
  10984. || !plci_b->NL.Id || plci_b->nl_remove_id
  10985. || (plci_b->li_bchannel_id == 0))
  10986. {
  10987. dbug (1, dprintf ("[%06lx] %s,%d: LI peer in wrong state %08lx",
  10988. UnMapId (Id), (char *)(FILE_), __LINE__, plci_b_id));
  10989. PUT_WORD (p_result, _REQUEST_NOT_ALLOWED_IN_THIS_STATE);
  10990. return (NULL);
  10991. }
  10992. li_config_table[plci_b->adapter->li_base + (plci_b->li_bchannel_id - 1)].plci = plci_b;
  10993. if (((byte)(plci_b_id & ~EXT_CONTROLLER)) !=
  10994. ((byte)(UnMapController (plci->adapter->Id) & ~EXT_CONTROLLER))
  10995. && (!(plci->adapter->manufacturer_features & MANUFACTURER_FEATURE_XCONNECT)
  10996. || !(plci_b->adapter->manufacturer_features & MANUFACTURER_FEATURE_XCONNECT)))
  10997. {
  10998. dbug (1, dprintf ("[%06lx] %s,%d: LI not on same ctrl %08lx",
  10999. UnMapId (Id), (char *)(FILE_), __LINE__, plci_b_id));
  11000. PUT_WORD (p_result, _WRONG_IDENTIFIER);
  11001. return (NULL);
  11002. }
  11003. if (!(get_b1_facilities (plci_b, add_b1_facilities (plci_b, plci_b->B1_resource,
  11004. (word)(plci_b->B1_facilities | B1_FACILITY_MIXER))) & B1_FACILITY_MIXER))
  11005. {
  11006. dbug (1, dprintf ("[%06lx] %s,%d: Interconnect peer cannot mix %d",
  11007. UnMapId (Id), (char *)(FILE_), __LINE__, plci_b->B1_resource));
  11008. PUT_WORD (p_result, _REQUEST_NOT_ALLOWED_IN_THIS_STATE);
  11009. return (NULL);
  11010. }
  11011. return (plci_b);
  11012. }
  11013. static PLCI *li2_check_plci_b (dword Id, PLCI *plci,
  11014. dword plci_b_id, word plci_b_write_pos, byte *p_result)
  11015. {
  11016. byte ctlr_b;
  11017. PLCI *plci_b;
  11018. if (((plci->li_plci_b_read_pos > plci_b_write_pos) ? plci->li_plci_b_read_pos :
  11019. LI_PLCI_B_QUEUE_ENTRIES + plci->li_plci_b_read_pos) - plci_b_write_pos - 1 < 2)
  11020. {
  11021. dbug (1, dprintf ("[%06lx] %s,%d: LI request overrun",
  11022. UnMapId (Id), (char *)(FILE_), __LINE__));
  11023. PUT_WORD (p_result, _WRONG_STATE);
  11024. return (NULL);
  11025. }
  11026. ctlr_b = 0;
  11027. if ((plci_b_id & 0x7f) != 0)
  11028. {
  11029. ctlr_b = MapController ((byte)(plci_b_id & 0x7f));
  11030. if ((ctlr_b > max_adapter) || ((ctlr_b != 0) && (adapter[ctlr_b - 1].request == NULL)))
  11031. ctlr_b = 0;
  11032. }
  11033. if ((ctlr_b == 0)
  11034. || (((plci_b_id >> 8) & 0xff) == 0)
  11035. || (((plci_b_id >> 8) & 0xff) > adapter[ctlr_b - 1].max_plci))
  11036. {
  11037. dbug (1, dprintf ("[%06lx] %s,%d: LI invalid second PLCI %08lx",
  11038. UnMapId (Id), (char *)(FILE_), __LINE__, plci_b_id));
  11039. PUT_WORD (p_result, _WRONG_IDENTIFIER);
  11040. return (NULL);
  11041. }
  11042. plci_b = &(adapter[ctlr_b - 1].plci[((plci_b_id >> 8) & 0xff) - 1]);
  11043. if (!plci_b->State
  11044. || !plci_b->NL.Id || plci_b->nl_remove_id
  11045. || (plci_b->li_bchannel_id == 0)
  11046. || (li_config_table[plci_b->adapter->li_base + (plci_b->li_bchannel_id - 1)].plci != plci_b))
  11047. {
  11048. dbug (1, dprintf ("[%06lx] %s,%d: LI peer in wrong state %08lx",
  11049. UnMapId (Id), (char *)(FILE_), __LINE__, plci_b_id));
  11050. PUT_WORD (p_result, _WRONG_STATE);
  11051. return (NULL);
  11052. }
  11053. if (((byte)(plci_b_id & ~EXT_CONTROLLER)) !=
  11054. ((byte)(UnMapController (plci->adapter->Id) & ~EXT_CONTROLLER))
  11055. && (!(plci->adapter->manufacturer_features & MANUFACTURER_FEATURE_XCONNECT)
  11056. || !(plci_b->adapter->manufacturer_features & MANUFACTURER_FEATURE_XCONNECT)))
  11057. {
  11058. dbug (1, dprintf ("[%06lx] %s,%d: LI not on same ctrl %08lx",
  11059. UnMapId (Id), (char *)(FILE_), __LINE__, plci_b_id));
  11060. PUT_WORD (p_result, _WRONG_IDENTIFIER);
  11061. return (NULL);
  11062. }
  11063. if (!(get_b1_facilities (plci_b, add_b1_facilities (plci_b, plci_b->B1_resource,
  11064. (word)(plci_b->B1_facilities | B1_FACILITY_MIXER))) & B1_FACILITY_MIXER))
  11065. {
  11066. dbug (1, dprintf ("[%06lx] %s,%d: Interconnect peer cannot mix %d",
  11067. UnMapId (Id), (char *)(FILE_), __LINE__, plci_b->B1_resource));
  11068. PUT_WORD (p_result, _WRONG_STATE);
  11069. return (NULL);
  11070. }
  11071. return (plci_b);
  11072. }
  11073. static byte mixer_request (dword Id, word Number, DIVA_CAPI_ADAPTER *a, PLCI *plci, APPL *appl, API_PARSE *msg)
  11074. {
  11075. word Info;
  11076. word i;
  11077. dword d, li_flags, plci_b_id;
  11078. PLCI *plci_b;
  11079. API_PARSE li_parms[3];
  11080. API_PARSE li_req_parms[3];
  11081. API_PARSE li_participant_struct[2];
  11082. API_PARSE li_participant_parms[3];
  11083. word participant_parms_pos;
  11084. byte result_buffer[32];
  11085. byte *result;
  11086. word result_pos;
  11087. word plci_b_write_pos;
  11088. dbug (1, dprintf ("[%06lx] %s,%d: mixer_request",
  11089. UnMapId (Id), (char *)(FILE_), __LINE__));
  11090. Info = GOOD;
  11091. result = result_buffer;
  11092. result_buffer[0] = 0;
  11093. if (!(a->profile.Global_Options & GL_LINE_INTERCONNECT_SUPPORTED))
  11094. {
  11095. dbug (1, dprintf ("[%06lx] %s,%d: Facility not supported",
  11096. UnMapId (Id), (char *)(FILE_), __LINE__));
  11097. Info = _FACILITY_NOT_SUPPORTED;
  11098. }
  11099. else if (api_parse (&msg[1].info[1], msg[1].length, "ws", li_parms))
  11100. {
  11101. dbug (1, dprintf ("[%06lx] %s,%d: Wrong message format",
  11102. UnMapId (Id), (char *)(FILE_), __LINE__));
  11103. Info = _WRONG_MESSAGE_FORMAT;
  11104. }
  11105. else
  11106. {
  11107. result_buffer[0] = 3;
  11108. PUT_WORD (&result_buffer[1], GET_WORD (li_parms[0].info));
  11109. result_buffer[3] = 0;
  11110. switch (GET_WORD (li_parms[0].info))
  11111. {
  11112. case LI_GET_SUPPORTED_SERVICES:
  11113. if (appl->appl_flags & APPL_FLAG_OLD_LI_SPEC)
  11114. {
  11115. result_buffer[0] = 17;
  11116. result_buffer[3] = 14;
  11117. PUT_WORD (&result_buffer[4], GOOD);
  11118. d = 0;
  11119. if (a->manufacturer_features & MANUFACTURER_FEATURE_MIXER_CH_CH)
  11120. d |= LI_CONFERENCING_SUPPORTED;
  11121. if (a->manufacturer_features & MANUFACTURER_FEATURE_MIXER_CH_PC)
  11122. d |= LI_MONITORING_SUPPORTED;
  11123. if (a->manufacturer_features & MANUFACTURER_FEATURE_MIXER_PC_CH)
  11124. d |= LI_ANNOUNCEMENTS_SUPPORTED | LI_MIXING_SUPPORTED;
  11125. if (a->manufacturer_features & MANUFACTURER_FEATURE_XCONNECT)
  11126. d |= LI_CROSS_CONTROLLER_SUPPORTED;
  11127. PUT_DWORD (&result_buffer[6], d);
  11128. if (a->manufacturer_features & MANUFACTURER_FEATURE_XCONNECT)
  11129. {
  11130. d = 0;
  11131. for (i = 0; i < li_total_channels; i++)
  11132. {
  11133. if ((li_config_table[i].adapter->manufacturer_features & MANUFACTURER_FEATURE_XCONNECT)
  11134. && (li_config_table[i].adapter->li_pri
  11135. || (i < li_config_table[i].adapter->li_base + MIXER_BCHANNELS_BRI)))
  11136. {
  11137. d++;
  11138. }
  11139. }
  11140. }
  11141. else
  11142. {
  11143. d = a->li_pri ? a->li_channels : MIXER_BCHANNELS_BRI;
  11144. }
  11145. PUT_DWORD (&result_buffer[10], d / 2);
  11146. PUT_DWORD (&result_buffer[14], d);
  11147. }
  11148. else
  11149. {
  11150. result_buffer[0] = 25;
  11151. result_buffer[3] = 22;
  11152. PUT_WORD (&result_buffer[4], GOOD);
  11153. d = LI2_ASYMMETRIC_SUPPORTED | LI2_B_LOOPING_SUPPORTED | LI2_X_LOOPING_SUPPORTED;
  11154. if (a->manufacturer_features & MANUFACTURER_FEATURE_MIXER_CH_PC)
  11155. d |= LI2_MONITORING_SUPPORTED | LI2_REMOTE_MONITORING_SUPPORTED;
  11156. if (a->manufacturer_features & MANUFACTURER_FEATURE_MIXER_PC_CH)
  11157. d |= LI2_MIXING_SUPPORTED | LI2_REMOTE_MIXING_SUPPORTED;
  11158. if (a->manufacturer_features & MANUFACTURER_FEATURE_MIXER_PC_PC)
  11159. d |= LI2_PC_LOOPING_SUPPORTED;
  11160. if (a->manufacturer_features & MANUFACTURER_FEATURE_XCONNECT)
  11161. d |= LI2_CROSS_CONTROLLER_SUPPORTED;
  11162. PUT_DWORD (&result_buffer[6], d);
  11163. d = a->li_pri ? a->li_channels : MIXER_BCHANNELS_BRI;
  11164. PUT_DWORD (&result_buffer[10], d / 2);
  11165. PUT_DWORD (&result_buffer[14], d - 1);
  11166. if (a->manufacturer_features & MANUFACTURER_FEATURE_XCONNECT)
  11167. {
  11168. d = 0;
  11169. for (i = 0; i < li_total_channels; i++)
  11170. {
  11171. if ((li_config_table[i].adapter->manufacturer_features & MANUFACTURER_FEATURE_XCONNECT)
  11172. && (li_config_table[i].adapter->li_pri
  11173. || (i < li_config_table[i].adapter->li_base + MIXER_BCHANNELS_BRI)))
  11174. {
  11175. d++;
  11176. }
  11177. }
  11178. }
  11179. PUT_DWORD (&result_buffer[18], d / 2);
  11180. PUT_DWORD (&result_buffer[22], d - 1);
  11181. }
  11182. break;
  11183. case LI_REQ_CONNECT:
  11184. if (li_parms[1].length == 8)
  11185. {
  11186. appl->appl_flags |= APPL_FLAG_OLD_LI_SPEC;
  11187. if (api_parse (&li_parms[1].info[1], li_parms[1].length, "dd", li_req_parms))
  11188. {
  11189. dbug (1, dprintf ("[%06lx] %s,%d: Wrong message format",
  11190. UnMapId (Id), (char *)(FILE_), __LINE__));
  11191. Info = _WRONG_MESSAGE_FORMAT;
  11192. break;
  11193. }
  11194. plci_b_id = GET_DWORD (li_req_parms[0].info) & 0xffff;
  11195. li_flags = GET_DWORD (li_req_parms[1].info);
  11196. Info = li_check_main_plci (Id, plci);
  11197. result_buffer[0] = 9;
  11198. result_buffer[3] = 6;
  11199. PUT_DWORD (&result_buffer[4], plci_b_id);
  11200. PUT_WORD (&result_buffer[8], GOOD);
  11201. if (Info != GOOD)
  11202. break;
  11203. result = plci->saved_msg.info;
  11204. for (i = 0; i <= result_buffer[0]; i++)
  11205. result[i] = result_buffer[i];
  11206. plci_b_write_pos = plci->li_plci_b_write_pos;
  11207. plci_b = li_check_plci_b (Id, plci, plci_b_id, plci_b_write_pos, &result[8]);
  11208. if (plci_b == NULL)
  11209. break;
  11210. li_update_connect (Id, a, plci, plci_b_id, true, li_flags);
  11211. plci->li_plci_b_queue[plci_b_write_pos] = plci_b_id | LI_PLCI_B_LAST_FLAG;
  11212. plci_b_write_pos = (plci_b_write_pos == LI_PLCI_B_QUEUE_ENTRIES-1) ? 0 : plci_b_write_pos + 1;
  11213. plci->li_plci_b_write_pos = plci_b_write_pos;
  11214. }
  11215. else
  11216. {
  11217. appl->appl_flags &= ~APPL_FLAG_OLD_LI_SPEC;
  11218. if (api_parse (&li_parms[1].info[1], li_parms[1].length, "ds", li_req_parms))
  11219. {
  11220. dbug (1, dprintf ("[%06lx] %s,%d: Wrong message format",
  11221. UnMapId (Id), (char *)(FILE_), __LINE__));
  11222. Info = _WRONG_MESSAGE_FORMAT;
  11223. break;
  11224. }
  11225. li_flags = GET_DWORD (li_req_parms[0].info) & ~(LI2_FLAG_INTERCONNECT_A_B | LI2_FLAG_INTERCONNECT_B_A);
  11226. Info = li_check_main_plci (Id, plci);
  11227. result_buffer[0] = 7;
  11228. result_buffer[3] = 4;
  11229. PUT_WORD (&result_buffer[4], Info);
  11230. result_buffer[6] = 0;
  11231. if (Info != GOOD)
  11232. break;
  11233. result = plci->saved_msg.info;
  11234. for (i = 0; i <= result_buffer[0]; i++)
  11235. result[i] = result_buffer[i];
  11236. plci_b_write_pos = plci->li_plci_b_write_pos;
  11237. participant_parms_pos = 0;
  11238. result_pos = 7;
  11239. li2_update_connect (Id, a, plci, UnMapId (Id), true, li_flags);
  11240. while (participant_parms_pos < li_req_parms[1].length)
  11241. {
  11242. result[result_pos] = 6;
  11243. result_pos += 7;
  11244. PUT_DWORD (&result[result_pos - 6], 0);
  11245. PUT_WORD (&result[result_pos - 2], GOOD);
  11246. if (api_parse (&li_req_parms[1].info[1 + participant_parms_pos],
  11247. (word)(li_parms[1].length - participant_parms_pos), "s", li_participant_struct))
  11248. {
  11249. dbug (1, dprintf ("[%06lx] %s,%d: Wrong message format",
  11250. UnMapId (Id), (char *)(FILE_), __LINE__));
  11251. PUT_WORD (&result[result_pos - 2], _WRONG_MESSAGE_FORMAT);
  11252. break;
  11253. }
  11254. if (api_parse (&li_participant_struct[0].info[1],
  11255. li_participant_struct[0].length, "dd", li_participant_parms))
  11256. {
  11257. dbug (1, dprintf ("[%06lx] %s,%d: Wrong message format",
  11258. UnMapId (Id), (char *)(FILE_), __LINE__));
  11259. PUT_WORD (&result[result_pos - 2], _WRONG_MESSAGE_FORMAT);
  11260. break;
  11261. }
  11262. plci_b_id = GET_DWORD (li_participant_parms[0].info) & 0xffff;
  11263. li_flags = GET_DWORD (li_participant_parms[1].info);
  11264. PUT_DWORD (&result[result_pos - 6], plci_b_id);
  11265. if (sizeof(result) - result_pos < 7)
  11266. {
  11267. dbug (1, dprintf ("[%06lx] %s,%d: LI result overrun",
  11268. UnMapId (Id), (char *)(FILE_), __LINE__));
  11269. PUT_WORD (&result[result_pos - 2], _WRONG_STATE);
  11270. break;
  11271. }
  11272. plci_b = li2_check_plci_b (Id, plci, plci_b_id, plci_b_write_pos, &result[result_pos - 2]);
  11273. if (plci_b != NULL)
  11274. {
  11275. li2_update_connect (Id, a, plci, plci_b_id, true, li_flags);
  11276. plci->li_plci_b_queue[plci_b_write_pos] = plci_b_id |
  11277. ((li_flags & (LI2_FLAG_INTERCONNECT_A_B | LI2_FLAG_INTERCONNECT_B_A |
  11278. LI2_FLAG_PCCONNECT_A_B | LI2_FLAG_PCCONNECT_B_A)) ? 0 : LI_PLCI_B_DISC_FLAG);
  11279. plci_b_write_pos = (plci_b_write_pos == LI_PLCI_B_QUEUE_ENTRIES-1) ? 0 : plci_b_write_pos + 1;
  11280. }
  11281. participant_parms_pos = (word)((&li_participant_struct[0].info[1 + li_participant_struct[0].length]) -
  11282. (&li_req_parms[1].info[1]));
  11283. }
  11284. result[0] = (byte)(result_pos - 1);
  11285. result[3] = (byte)(result_pos - 4);
  11286. result[6] = (byte)(result_pos - 7);
  11287. i = (plci_b_write_pos == 0) ? LI_PLCI_B_QUEUE_ENTRIES-1 : plci_b_write_pos - 1;
  11288. if ((plci_b_write_pos == plci->li_plci_b_read_pos)
  11289. || (plci->li_plci_b_queue[i] & LI_PLCI_B_LAST_FLAG))
  11290. {
  11291. plci->li_plci_b_queue[plci_b_write_pos] = LI_PLCI_B_SKIP_FLAG | LI_PLCI_B_LAST_FLAG;
  11292. plci_b_write_pos = (plci_b_write_pos == LI_PLCI_B_QUEUE_ENTRIES-1) ? 0 : plci_b_write_pos + 1;
  11293. }
  11294. else
  11295. plci->li_plci_b_queue[i] |= LI_PLCI_B_LAST_FLAG;
  11296. plci->li_plci_b_write_pos = plci_b_write_pos;
  11297. }
  11298. mixer_calculate_coefs (a);
  11299. plci->li_channel_bits = li_config_table[a->li_base + (plci->li_bchannel_id - 1)].channel;
  11300. mixer_notify_update (plci, true);
  11301. sendf (appl, _FACILITY_R | CONFIRM, Id & 0xffffL, Number,
  11302. "wwS", Info, SELECTOR_LINE_INTERCONNECT, result);
  11303. plci->command = 0;
  11304. plci->li_cmd = GET_WORD (li_parms[0].info);
  11305. start_internal_command (Id, plci, mixer_command);
  11306. return (false);
  11307. case LI_REQ_DISCONNECT:
  11308. if (li_parms[1].length == 4)
  11309. {
  11310. appl->appl_flags |= APPL_FLAG_OLD_LI_SPEC;
  11311. if (api_parse (&li_parms[1].info[1], li_parms[1].length, "d", li_req_parms))
  11312. {
  11313. dbug (1, dprintf ("[%06lx] %s,%d: Wrong message format",
  11314. UnMapId (Id), (char *)(FILE_), __LINE__));
  11315. Info = _WRONG_MESSAGE_FORMAT;
  11316. break;
  11317. }
  11318. plci_b_id = GET_DWORD (li_req_parms[0].info) & 0xffff;
  11319. Info = li_check_main_plci (Id, plci);
  11320. result_buffer[0] = 9;
  11321. result_buffer[3] = 6;
  11322. PUT_DWORD (&result_buffer[4], GET_DWORD (li_req_parms[0].info));
  11323. PUT_WORD (&result_buffer[8], GOOD);
  11324. if (Info != GOOD)
  11325. break;
  11326. result = plci->saved_msg.info;
  11327. for (i = 0; i <= result_buffer[0]; i++)
  11328. result[i] = result_buffer[i];
  11329. plci_b_write_pos = plci->li_plci_b_write_pos;
  11330. plci_b = li_check_plci_b (Id, plci, plci_b_id, plci_b_write_pos, &result[8]);
  11331. if (plci_b == NULL)
  11332. break;
  11333. li_update_connect (Id, a, plci, plci_b_id, false, 0);
  11334. plci->li_plci_b_queue[plci_b_write_pos] = plci_b_id | LI_PLCI_B_DISC_FLAG | LI_PLCI_B_LAST_FLAG;
  11335. plci_b_write_pos = (plci_b_write_pos == LI_PLCI_B_QUEUE_ENTRIES-1) ? 0 : plci_b_write_pos + 1;
  11336. plci->li_plci_b_write_pos = plci_b_write_pos;
  11337. }
  11338. else
  11339. {
  11340. appl->appl_flags &= ~APPL_FLAG_OLD_LI_SPEC;
  11341. if (api_parse (&li_parms[1].info[1], li_parms[1].length, "s", li_req_parms))
  11342. {
  11343. dbug (1, dprintf ("[%06lx] %s,%d: Wrong message format",
  11344. UnMapId (Id), (char *)(FILE_), __LINE__));
  11345. Info = _WRONG_MESSAGE_FORMAT;
  11346. break;
  11347. }
  11348. Info = li_check_main_plci (Id, plci);
  11349. result_buffer[0] = 7;
  11350. result_buffer[3] = 4;
  11351. PUT_WORD (&result_buffer[4], Info);
  11352. result_buffer[6] = 0;
  11353. if (Info != GOOD)
  11354. break;
  11355. result = plci->saved_msg.info;
  11356. for (i = 0; i <= result_buffer[0]; i++)
  11357. result[i] = result_buffer[i];
  11358. plci_b_write_pos = plci->li_plci_b_write_pos;
  11359. participant_parms_pos = 0;
  11360. result_pos = 7;
  11361. while (participant_parms_pos < li_req_parms[0].length)
  11362. {
  11363. result[result_pos] = 6;
  11364. result_pos += 7;
  11365. PUT_DWORD (&result[result_pos - 6], 0);
  11366. PUT_WORD (&result[result_pos - 2], GOOD);
  11367. if (api_parse (&li_req_parms[0].info[1 + participant_parms_pos],
  11368. (word)(li_parms[1].length - participant_parms_pos), "s", li_participant_struct))
  11369. {
  11370. dbug (1, dprintf ("[%06lx] %s,%d: Wrong message format",
  11371. UnMapId (Id), (char *)(FILE_), __LINE__));
  11372. PUT_WORD (&result[result_pos - 2], _WRONG_MESSAGE_FORMAT);
  11373. break;
  11374. }
  11375. if (api_parse (&li_participant_struct[0].info[1],
  11376. li_participant_struct[0].length, "d", li_participant_parms))
  11377. {
  11378. dbug (1, dprintf ("[%06lx] %s,%d: Wrong message format",
  11379. UnMapId (Id), (char *)(FILE_), __LINE__));
  11380. PUT_WORD (&result[result_pos - 2], _WRONG_MESSAGE_FORMAT);
  11381. break;
  11382. }
  11383. plci_b_id = GET_DWORD (li_participant_parms[0].info) & 0xffff;
  11384. PUT_DWORD (&result[result_pos - 6], plci_b_id);
  11385. if (sizeof(result) - result_pos < 7)
  11386. {
  11387. dbug (1, dprintf ("[%06lx] %s,%d: LI result overrun",
  11388. UnMapId (Id), (char *)(FILE_), __LINE__));
  11389. PUT_WORD (&result[result_pos - 2], _WRONG_STATE);
  11390. break;
  11391. }
  11392. plci_b = li2_check_plci_b (Id, plci, plci_b_id, plci_b_write_pos, &result[result_pos - 2]);
  11393. if (plci_b != NULL)
  11394. {
  11395. li2_update_connect (Id, a, plci, plci_b_id, false, 0);
  11396. plci->li_plci_b_queue[plci_b_write_pos] = plci_b_id | LI_PLCI_B_DISC_FLAG;
  11397. plci_b_write_pos = (plci_b_write_pos == LI_PLCI_B_QUEUE_ENTRIES-1) ? 0 : plci_b_write_pos + 1;
  11398. }
  11399. participant_parms_pos = (word)((&li_participant_struct[0].info[1 + li_participant_struct[0].length]) -
  11400. (&li_req_parms[0].info[1]));
  11401. }
  11402. result[0] = (byte)(result_pos - 1);
  11403. result[3] = (byte)(result_pos - 4);
  11404. result[6] = (byte)(result_pos - 7);
  11405. i = (plci_b_write_pos == 0) ? LI_PLCI_B_QUEUE_ENTRIES-1 : plci_b_write_pos - 1;
  11406. if ((plci_b_write_pos == plci->li_plci_b_read_pos)
  11407. || (plci->li_plci_b_queue[i] & LI_PLCI_B_LAST_FLAG))
  11408. {
  11409. plci->li_plci_b_queue[plci_b_write_pos] = LI_PLCI_B_SKIP_FLAG | LI_PLCI_B_LAST_FLAG;
  11410. plci_b_write_pos = (plci_b_write_pos == LI_PLCI_B_QUEUE_ENTRIES-1) ? 0 : plci_b_write_pos + 1;
  11411. }
  11412. else
  11413. plci->li_plci_b_queue[i] |= LI_PLCI_B_LAST_FLAG;
  11414. plci->li_plci_b_write_pos = plci_b_write_pos;
  11415. }
  11416. mixer_calculate_coefs (a);
  11417. plci->li_channel_bits = li_config_table[a->li_base + (plci->li_bchannel_id - 1)].channel;
  11418. mixer_notify_update (plci, true);
  11419. sendf (appl, _FACILITY_R | CONFIRM, Id & 0xffffL, Number,
  11420. "wwS", Info, SELECTOR_LINE_INTERCONNECT, result);
  11421. plci->command = 0;
  11422. plci->li_cmd = GET_WORD (li_parms[0].info);
  11423. start_internal_command (Id, plci, mixer_command);
  11424. return (false);
  11425. case LI_REQ_SILENT_UPDATE:
  11426. if (!plci || !plci->State
  11427. || !plci->NL.Id || plci->nl_remove_id
  11428. || (plci->li_bchannel_id == 0)
  11429. || (li_config_table[plci->adapter->li_base + (plci->li_bchannel_id - 1)].plci != plci))
  11430. {
  11431. dbug (1, dprintf ("[%06lx] %s,%d: Wrong state",
  11432. UnMapId (Id), (char *)(FILE_), __LINE__));
  11433. return (false);
  11434. }
  11435. plci_b_write_pos = plci->li_plci_b_write_pos;
  11436. if (((plci->li_plci_b_read_pos > plci_b_write_pos) ? plci->li_plci_b_read_pos :
  11437. LI_PLCI_B_QUEUE_ENTRIES + plci->li_plci_b_read_pos) - plci_b_write_pos - 1 < 2)
  11438. {
  11439. dbug (1, dprintf ("[%06lx] %s,%d: LI request overrun",
  11440. UnMapId (Id), (char *)(FILE_), __LINE__));
  11441. return (false);
  11442. }
  11443. i = (plci_b_write_pos == 0) ? LI_PLCI_B_QUEUE_ENTRIES-1 : plci_b_write_pos - 1;
  11444. if ((plci_b_write_pos == plci->li_plci_b_read_pos)
  11445. || (plci->li_plci_b_queue[i] & LI_PLCI_B_LAST_FLAG))
  11446. {
  11447. plci->li_plci_b_queue[plci_b_write_pos] = LI_PLCI_B_SKIP_FLAG | LI_PLCI_B_LAST_FLAG;
  11448. plci_b_write_pos = (plci_b_write_pos == LI_PLCI_B_QUEUE_ENTRIES-1) ? 0 : plci_b_write_pos + 1;
  11449. }
  11450. else
  11451. plci->li_plci_b_queue[i] |= LI_PLCI_B_LAST_FLAG;
  11452. plci->li_plci_b_write_pos = plci_b_write_pos;
  11453. plci->li_channel_bits = li_config_table[a->li_base + (plci->li_bchannel_id - 1)].channel;
  11454. plci->command = 0;
  11455. plci->li_cmd = GET_WORD (li_parms[0].info);
  11456. start_internal_command (Id, plci, mixer_command);
  11457. return (false);
  11458. default:
  11459. dbug (1, dprintf ("[%06lx] %s,%d: LI unknown request %04x",
  11460. UnMapId (Id), (char *)(FILE_), __LINE__, GET_WORD (li_parms[0].info)));
  11461. Info = _FACILITY_NOT_SUPPORTED;
  11462. }
  11463. }
  11464. sendf (appl, _FACILITY_R | CONFIRM, Id & 0xffffL, Number,
  11465. "wwS", Info, SELECTOR_LINE_INTERCONNECT, result);
  11466. return (false);
  11467. }
  11468. static void mixer_indication_coefs_set (dword Id, PLCI *plci)
  11469. {
  11470. dword d;
  11471. DIVA_CAPI_ADAPTER *a;
  11472. byte result[12];
  11473. dbug (1, dprintf ("[%06lx] %s,%d: mixer_indication_coefs_set",
  11474. UnMapId (Id), (char *)(FILE_), __LINE__));
  11475. a = plci->adapter;
  11476. if (plci->li_plci_b_read_pos != plci->li_plci_b_req_pos)
  11477. {
  11478. do
  11479. {
  11480. d = plci->li_plci_b_queue[plci->li_plci_b_read_pos];
  11481. if (!(d & LI_PLCI_B_SKIP_FLAG))
  11482. {
  11483. if (plci->appl->appl_flags & APPL_FLAG_OLD_LI_SPEC)
  11484. {
  11485. if (d & LI_PLCI_B_DISC_FLAG)
  11486. {
  11487. result[0] = 5;
  11488. PUT_WORD (&result[1], LI_IND_DISCONNECT);
  11489. result[3] = 2;
  11490. PUT_WORD (&result[4], _LI_USER_INITIATED);
  11491. }
  11492. else
  11493. {
  11494. result[0] = 7;
  11495. PUT_WORD (&result[1], LI_IND_CONNECT_ACTIVE);
  11496. result[3] = 4;
  11497. PUT_DWORD (&result[4], d & ~LI_PLCI_B_FLAG_MASK);
  11498. }
  11499. }
  11500. else
  11501. {
  11502. if (d & LI_PLCI_B_DISC_FLAG)
  11503. {
  11504. result[0] = 9;
  11505. PUT_WORD (&result[1], LI_IND_DISCONNECT);
  11506. result[3] = 6;
  11507. PUT_DWORD (&result[4], d & ~LI_PLCI_B_FLAG_MASK);
  11508. PUT_WORD (&result[8], _LI_USER_INITIATED);
  11509. }
  11510. else
  11511. {
  11512. result[0] = 7;
  11513. PUT_WORD (&result[1], LI_IND_CONNECT_ACTIVE);
  11514. result[3] = 4;
  11515. PUT_DWORD (&result[4], d & ~LI_PLCI_B_FLAG_MASK);
  11516. }
  11517. }
  11518. sendf (plci->appl, _FACILITY_I, Id & 0xffffL, 0,
  11519. "ws", SELECTOR_LINE_INTERCONNECT, result);
  11520. }
  11521. plci->li_plci_b_read_pos = (plci->li_plci_b_read_pos == LI_PLCI_B_QUEUE_ENTRIES-1) ?
  11522. 0 : plci->li_plci_b_read_pos + 1;
  11523. } while (!(d & LI_PLCI_B_LAST_FLAG) && (plci->li_plci_b_read_pos != plci->li_plci_b_req_pos));
  11524. }
  11525. }
  11526. static void mixer_indication_xconnect_from (dword Id, PLCI *plci, byte *msg, word length)
  11527. {
  11528. word i, j, ch;
  11529. struct xconnect_transfer_address_s s, *p;
  11530. DIVA_CAPI_ADAPTER *a;
  11531. dbug (1, dprintf ("[%06lx] %s,%d: mixer_indication_xconnect_from %d",
  11532. UnMapId (Id), (char *)(FILE_), __LINE__, (int) length));
  11533. a = plci->adapter;
  11534. i = 1;
  11535. for (i = 1; i < length; i += 16)
  11536. {
  11537. s.card_address.low = msg[i] | (msg[i+1] << 8) | (((dword)(msg[i+2])) << 16) | (((dword)(msg[i+3])) << 24);
  11538. s.card_address.high = msg[i+4] | (msg[i+5] << 8) | (((dword)(msg[i+6])) << 16) | (((dword)(msg[i+7])) << 24);
  11539. s.offset = msg[i+8] | (msg[i+9] << 8) | (((dword)(msg[i+10])) << 16) | (((dword)(msg[i+11])) << 24);
  11540. ch = msg[i+12] | (msg[i+13] << 8);
  11541. j = ch & XCONNECT_CHANNEL_NUMBER_MASK;
  11542. if (!a->li_pri && (plci->li_bchannel_id == 2))
  11543. j = 1 - j;
  11544. j += a->li_base;
  11545. if (ch & XCONNECT_CHANNEL_PORT_PC)
  11546. p = &(li_config_table[j].send_pc);
  11547. else
  11548. p = &(li_config_table[j].send_b);
  11549. p->card_address.low = s.card_address.low;
  11550. p->card_address.high = s.card_address.high;
  11551. p->offset = s.offset;
  11552. li_config_table[j].channel |= LI_CHANNEL_ADDRESSES_SET;
  11553. }
  11554. if (plci->internal_command_queue[0]
  11555. && ((plci->adjust_b_state == ADJUST_B_RESTORE_MIXER_2)
  11556. || (plci->adjust_b_state == ADJUST_B_RESTORE_MIXER_3)
  11557. || (plci->adjust_b_state == ADJUST_B_RESTORE_MIXER_4)))
  11558. {
  11559. (*(plci->internal_command_queue[0]))(Id, plci, 0);
  11560. if (!plci->internal_command)
  11561. next_internal_command (Id, plci);
  11562. }
  11563. mixer_notify_update (plci, true);
  11564. }
  11565. static void mixer_indication_xconnect_to (dword Id, PLCI *plci, byte *msg, word length)
  11566. {
  11567. dbug (1, dprintf ("[%06lx] %s,%d: mixer_indication_xconnect_to %d",
  11568. UnMapId (Id), (char *)(FILE_), __LINE__, (int) length));
  11569. }
  11570. static byte mixer_notify_source_removed (PLCI *plci, dword plci_b_id)
  11571. {
  11572. word plci_b_write_pos;
  11573. plci_b_write_pos = plci->li_plci_b_write_pos;
  11574. if (((plci->li_plci_b_read_pos > plci_b_write_pos) ? plci->li_plci_b_read_pos :
  11575. LI_PLCI_B_QUEUE_ENTRIES + plci->li_plci_b_read_pos) - plci_b_write_pos - 1 < 1)
  11576. {
  11577. dbug (1, dprintf ("[%06lx] %s,%d: LI request overrun",
  11578. (dword)((plci->Id << 8) | UnMapController (plci->adapter->Id)),
  11579. (char *)(FILE_), __LINE__));
  11580. return (false);
  11581. }
  11582. plci->li_plci_b_queue[plci_b_write_pos] = plci_b_id | LI_PLCI_B_DISC_FLAG;
  11583. plci_b_write_pos = (plci_b_write_pos == LI_PLCI_B_QUEUE_ENTRIES-1) ? 0 : plci_b_write_pos + 1;
  11584. plci->li_plci_b_write_pos = plci_b_write_pos;
  11585. return (true);
  11586. }
  11587. static void mixer_remove (PLCI *plci)
  11588. {
  11589. DIVA_CAPI_ADAPTER *a;
  11590. PLCI *notify_plci;
  11591. dword plci_b_id;
  11592. word i, j;
  11593. dbug (1, dprintf ("[%06lx] %s,%d: mixer_remove",
  11594. (dword)((plci->Id << 8) | UnMapController (plci->adapter->Id)),
  11595. (char *)(FILE_), __LINE__));
  11596. a = plci->adapter;
  11597. plci_b_id = (plci->Id << 8) | UnMapController (plci->adapter->Id);
  11598. if (a->profile.Global_Options & GL_LINE_INTERCONNECT_SUPPORTED)
  11599. {
  11600. if ((plci->li_bchannel_id != 0)
  11601. && (li_config_table[a->li_base + (plci->li_bchannel_id - 1)].plci == plci))
  11602. {
  11603. i = a->li_base + (plci->li_bchannel_id - 1);
  11604. if ((li_config_table[i].curchnl | li_config_table[i].channel) & LI_CHANNEL_INVOLVED)
  11605. {
  11606. for (j = 0; j < li_total_channels; j++)
  11607. {
  11608. if ((li_config_table[i].flag_table[j] & LI_FLAG_INTERCONNECT)
  11609. || (li_config_table[j].flag_table[i] & LI_FLAG_INTERCONNECT))
  11610. {
  11611. notify_plci = li_config_table[j].plci;
  11612. if ((notify_plci != NULL)
  11613. && (notify_plci != plci)
  11614. && (notify_plci->appl != NULL)
  11615. && !(notify_plci->appl->appl_flags & APPL_FLAG_OLD_LI_SPEC)
  11616. && (notify_plci->State)
  11617. && notify_plci->NL.Id && !notify_plci->nl_remove_id)
  11618. {
  11619. mixer_notify_source_removed (notify_plci, plci_b_id);
  11620. }
  11621. }
  11622. }
  11623. mixer_clear_config (plci);
  11624. mixer_calculate_coefs (a);
  11625. mixer_notify_update (plci, true);
  11626. }
  11627. li_config_table[i].plci = NULL;
  11628. plci->li_bchannel_id = 0;
  11629. }
  11630. }
  11631. }
  11632. /*------------------------------------------------------------------*/
  11633. /* Echo canceller facilities */
  11634. /*------------------------------------------------------------------*/
  11635. static void ec_write_parameters (PLCI *plci)
  11636. {
  11637. word w;
  11638. byte parameter_buffer[6];
  11639. dbug (1, dprintf ("[%06lx] %s,%d: ec_write_parameters",
  11640. (dword)((plci->Id << 8) | UnMapController (plci->adapter->Id)),
  11641. (char *)(FILE_), __LINE__));
  11642. parameter_buffer[0] = 5;
  11643. parameter_buffer[1] = DSP_CTRL_SET_LEC_PARAMETERS;
  11644. PUT_WORD (&parameter_buffer[2], plci->ec_idi_options);
  11645. plci->ec_idi_options &= ~LEC_RESET_COEFFICIENTS;
  11646. w = (plci->ec_tail_length == 0) ? 128 : plci->ec_tail_length;
  11647. PUT_WORD (&parameter_buffer[4], w);
  11648. add_p (plci, FTY, parameter_buffer);
  11649. sig_req (plci, TEL_CTRL, 0);
  11650. send_req (plci);
  11651. }
  11652. static void ec_clear_config (PLCI *plci)
  11653. {
  11654. dbug (1, dprintf ("[%06lx] %s,%d: ec_clear_config",
  11655. (dword)((plci->Id << 8) | UnMapController (plci->adapter->Id)),
  11656. (char *)(FILE_), __LINE__));
  11657. plci->ec_idi_options = LEC_ENABLE_ECHO_CANCELLER |
  11658. LEC_MANUAL_DISABLE | LEC_ENABLE_NONLINEAR_PROCESSING;
  11659. plci->ec_tail_length = 0;
  11660. }
  11661. static void ec_prepare_switch (dword Id, PLCI *plci)
  11662. {
  11663. dbug (1, dprintf ("[%06lx] %s,%d: ec_prepare_switch",
  11664. UnMapId (Id), (char *)(FILE_), __LINE__));
  11665. }
  11666. static word ec_save_config (dword Id, PLCI *plci, byte Rc)
  11667. {
  11668. dbug (1, dprintf ("[%06lx] %s,%d: ec_save_config %02x %d",
  11669. UnMapId (Id), (char *)(FILE_), __LINE__, Rc, plci->adjust_b_state));
  11670. return (GOOD);
  11671. }
  11672. static word ec_restore_config (dword Id, PLCI *plci, byte Rc)
  11673. {
  11674. word Info;
  11675. dbug (1, dprintf ("[%06lx] %s,%d: ec_restore_config %02x %d",
  11676. UnMapId (Id), (char *)(FILE_), __LINE__, Rc, plci->adjust_b_state));
  11677. Info = GOOD;
  11678. if (plci->B1_facilities & B1_FACILITY_EC)
  11679. {
  11680. switch (plci->adjust_b_state)
  11681. {
  11682. case ADJUST_B_RESTORE_EC_1:
  11683. plci->internal_command = plci->adjust_b_command;
  11684. if (plci->sig_req)
  11685. {
  11686. plci->adjust_b_state = ADJUST_B_RESTORE_EC_1;
  11687. break;
  11688. }
  11689. ec_write_parameters (plci);
  11690. plci->adjust_b_state = ADJUST_B_RESTORE_EC_2;
  11691. break;
  11692. case ADJUST_B_RESTORE_EC_2:
  11693. if ((Rc != OK) && (Rc != OK_FC))
  11694. {
  11695. dbug (1, dprintf ("[%06lx] %s,%d: Restore EC failed %02x",
  11696. UnMapId (Id), (char *)(FILE_), __LINE__, Rc));
  11697. Info = _WRONG_STATE;
  11698. break;
  11699. }
  11700. break;
  11701. }
  11702. }
  11703. return (Info);
  11704. }
  11705. static void ec_command (dword Id, PLCI *plci, byte Rc)
  11706. {
  11707. word internal_command, Info;
  11708. byte result[8];
  11709. dbug (1, dprintf ("[%06lx] %s,%d: ec_command %02x %04x %04x %04x %d",
  11710. UnMapId (Id), (char *)(FILE_), __LINE__, Rc, plci->internal_command,
  11711. plci->ec_cmd, plci->ec_idi_options, plci->ec_tail_length));
  11712. Info = GOOD;
  11713. if (plci->appl->appl_flags & APPL_FLAG_PRIV_EC_SPEC)
  11714. {
  11715. result[0] = 2;
  11716. PUT_WORD (&result[1], EC_SUCCESS);
  11717. }
  11718. else
  11719. {
  11720. result[0] = 5;
  11721. PUT_WORD (&result[1], plci->ec_cmd);
  11722. result[3] = 2;
  11723. PUT_WORD (&result[4], GOOD);
  11724. }
  11725. internal_command = plci->internal_command;
  11726. plci->internal_command = 0;
  11727. switch (plci->ec_cmd)
  11728. {
  11729. case EC_ENABLE_OPERATION:
  11730. case EC_FREEZE_COEFFICIENTS:
  11731. case EC_RESUME_COEFFICIENT_UPDATE:
  11732. case EC_RESET_COEFFICIENTS:
  11733. switch (internal_command)
  11734. {
  11735. default:
  11736. adjust_b1_resource (Id, plci, NULL, (word)(plci->B1_facilities |
  11737. B1_FACILITY_EC), EC_COMMAND_1);
  11738. case EC_COMMAND_1:
  11739. if (adjust_b_process (Id, plci, Rc) != GOOD)
  11740. {
  11741. dbug (1, dprintf ("[%06lx] %s,%d: Load EC failed",
  11742. UnMapId (Id), (char *)(FILE_), __LINE__));
  11743. Info = _FACILITY_NOT_SUPPORTED;
  11744. break;
  11745. }
  11746. if (plci->internal_command)
  11747. return;
  11748. case EC_COMMAND_2:
  11749. if (plci->sig_req)
  11750. {
  11751. plci->internal_command = EC_COMMAND_2;
  11752. return;
  11753. }
  11754. plci->internal_command = EC_COMMAND_3;
  11755. ec_write_parameters (plci);
  11756. return;
  11757. case EC_COMMAND_3:
  11758. if ((Rc != OK) && (Rc != OK_FC))
  11759. {
  11760. dbug (1, dprintf ("[%06lx] %s,%d: Enable EC failed %02x",
  11761. UnMapId (Id), (char *)(FILE_), __LINE__, Rc));
  11762. Info = _FACILITY_NOT_SUPPORTED;
  11763. break;
  11764. }
  11765. break;
  11766. }
  11767. break;
  11768. case EC_DISABLE_OPERATION:
  11769. switch (internal_command)
  11770. {
  11771. default:
  11772. case EC_COMMAND_1:
  11773. if (plci->B1_facilities & B1_FACILITY_EC)
  11774. {
  11775. if (plci->sig_req)
  11776. {
  11777. plci->internal_command = EC_COMMAND_1;
  11778. return;
  11779. }
  11780. plci->internal_command = EC_COMMAND_2;
  11781. ec_write_parameters (plci);
  11782. return;
  11783. }
  11784. Rc = OK;
  11785. case EC_COMMAND_2:
  11786. if ((Rc != OK) && (Rc != OK_FC))
  11787. {
  11788. dbug (1, dprintf ("[%06lx] %s,%d: Disable EC failed %02x",
  11789. UnMapId (Id), (char *)(FILE_), __LINE__, Rc));
  11790. Info = _FACILITY_NOT_SUPPORTED;
  11791. break;
  11792. }
  11793. adjust_b1_resource (Id, plci, NULL, (word)(plci->B1_facilities &
  11794. ~B1_FACILITY_EC), EC_COMMAND_3);
  11795. case EC_COMMAND_3:
  11796. if (adjust_b_process (Id, plci, Rc) != GOOD)
  11797. {
  11798. dbug (1, dprintf ("[%06lx] %s,%d: Unload EC failed",
  11799. UnMapId (Id), (char *)(FILE_), __LINE__));
  11800. Info = _FACILITY_NOT_SUPPORTED;
  11801. break;
  11802. }
  11803. if (plci->internal_command)
  11804. return;
  11805. break;
  11806. }
  11807. break;
  11808. }
  11809. sendf (plci->appl, _FACILITY_R | CONFIRM, Id & 0xffffL, plci->number,
  11810. "wws", Info, (plci->appl->appl_flags & APPL_FLAG_PRIV_EC_SPEC) ?
  11811. PRIV_SELECTOR_ECHO_CANCELLER : SELECTOR_ECHO_CANCELLER, result);
  11812. }
  11813. static byte ec_request (dword Id, word Number, DIVA_CAPI_ADAPTER *a, PLCI *plci, APPL *appl, API_PARSE *msg)
  11814. {
  11815. word Info;
  11816. word opt;
  11817. API_PARSE ec_parms[3];
  11818. byte result[16];
  11819. dbug (1, dprintf ("[%06lx] %s,%d: ec_request",
  11820. UnMapId (Id), (char *)(FILE_), __LINE__));
  11821. Info = GOOD;
  11822. result[0] = 0;
  11823. if (!(a->man_profile.private_options & (1L << PRIVATE_ECHO_CANCELLER)))
  11824. {
  11825. dbug (1, dprintf ("[%06lx] %s,%d: Facility not supported",
  11826. UnMapId (Id), (char *)(FILE_), __LINE__));
  11827. Info = _FACILITY_NOT_SUPPORTED;
  11828. }
  11829. else
  11830. {
  11831. if (appl->appl_flags & APPL_FLAG_PRIV_EC_SPEC)
  11832. {
  11833. if (api_parse (&msg[1].info[1], msg[1].length, "w", ec_parms))
  11834. {
  11835. dbug (1, dprintf ("[%06lx] %s,%d: Wrong message format",
  11836. UnMapId (Id), (char *)(FILE_), __LINE__));
  11837. Info = _WRONG_MESSAGE_FORMAT;
  11838. }
  11839. else
  11840. {
  11841. if (plci == NULL)
  11842. {
  11843. dbug (1, dprintf ("[%06lx] %s,%d: Wrong PLCI",
  11844. UnMapId (Id), (char *)(FILE_), __LINE__));
  11845. Info = _WRONG_IDENTIFIER;
  11846. }
  11847. else if (!plci->State || !plci->NL.Id || plci->nl_remove_id)
  11848. {
  11849. dbug (1, dprintf ("[%06lx] %s,%d: Wrong state",
  11850. UnMapId (Id), (char *)(FILE_), __LINE__));
  11851. Info = _WRONG_STATE;
  11852. }
  11853. else
  11854. {
  11855. plci->command = 0;
  11856. plci->ec_cmd = GET_WORD (ec_parms[0].info);
  11857. plci->ec_idi_options &= ~(LEC_MANUAL_DISABLE | LEC_RESET_COEFFICIENTS);
  11858. result[0] = 2;
  11859. PUT_WORD (&result[1], EC_SUCCESS);
  11860. if (msg[1].length >= 4)
  11861. {
  11862. opt = GET_WORD (&ec_parms[0].info[2]);
  11863. plci->ec_idi_options &= ~(LEC_ENABLE_NONLINEAR_PROCESSING |
  11864. LEC_ENABLE_2100HZ_DETECTOR | LEC_REQUIRE_2100HZ_REVERSALS);
  11865. if (!(opt & EC_DISABLE_NON_LINEAR_PROCESSING))
  11866. plci->ec_idi_options |= LEC_ENABLE_NONLINEAR_PROCESSING;
  11867. if (opt & EC_DETECT_DISABLE_TONE)
  11868. plci->ec_idi_options |= LEC_ENABLE_2100HZ_DETECTOR;
  11869. if (!(opt & EC_DO_NOT_REQUIRE_REVERSALS))
  11870. plci->ec_idi_options |= LEC_REQUIRE_2100HZ_REVERSALS;
  11871. if (msg[1].length >= 6)
  11872. {
  11873. plci->ec_tail_length = GET_WORD (&ec_parms[0].info[4]);
  11874. }
  11875. }
  11876. switch (plci->ec_cmd)
  11877. {
  11878. case EC_ENABLE_OPERATION:
  11879. plci->ec_idi_options &= ~LEC_FREEZE_COEFFICIENTS;
  11880. start_internal_command (Id, plci, ec_command);
  11881. return (false);
  11882. case EC_DISABLE_OPERATION:
  11883. plci->ec_idi_options = LEC_ENABLE_ECHO_CANCELLER |
  11884. LEC_MANUAL_DISABLE | LEC_ENABLE_NONLINEAR_PROCESSING |
  11885. LEC_RESET_COEFFICIENTS;
  11886. start_internal_command (Id, plci, ec_command);
  11887. return (false);
  11888. case EC_FREEZE_COEFFICIENTS:
  11889. plci->ec_idi_options |= LEC_FREEZE_COEFFICIENTS;
  11890. start_internal_command (Id, plci, ec_command);
  11891. return (false);
  11892. case EC_RESUME_COEFFICIENT_UPDATE:
  11893. plci->ec_idi_options &= ~LEC_FREEZE_COEFFICIENTS;
  11894. start_internal_command (Id, plci, ec_command);
  11895. return (false);
  11896. case EC_RESET_COEFFICIENTS:
  11897. plci->ec_idi_options |= LEC_RESET_COEFFICIENTS;
  11898. start_internal_command (Id, plci, ec_command);
  11899. return (false);
  11900. default:
  11901. dbug (1, dprintf ("[%06lx] %s,%d: EC unknown request %04x",
  11902. UnMapId (Id), (char *)(FILE_), __LINE__, plci->ec_cmd));
  11903. PUT_WORD (&result[1], EC_UNSUPPORTED_OPERATION);
  11904. }
  11905. }
  11906. }
  11907. }
  11908. else
  11909. {
  11910. if (api_parse (&msg[1].info[1], msg[1].length, "ws", ec_parms))
  11911. {
  11912. dbug (1, dprintf ("[%06lx] %s,%d: Wrong message format",
  11913. UnMapId (Id), (char *)(FILE_), __LINE__));
  11914. Info = _WRONG_MESSAGE_FORMAT;
  11915. }
  11916. else
  11917. {
  11918. if (GET_WORD (ec_parms[0].info) == EC_GET_SUPPORTED_SERVICES)
  11919. {
  11920. result[0] = 11;
  11921. PUT_WORD (&result[1], EC_GET_SUPPORTED_SERVICES);
  11922. result[3] = 8;
  11923. PUT_WORD (&result[4], GOOD);
  11924. PUT_WORD (&result[6], 0x0007);
  11925. PUT_WORD (&result[8], LEC_MAX_SUPPORTED_TAIL_LENGTH);
  11926. PUT_WORD (&result[10], 0);
  11927. }
  11928. else if (plci == NULL)
  11929. {
  11930. dbug (1, dprintf ("[%06lx] %s,%d: Wrong PLCI",
  11931. UnMapId (Id), (char *)(FILE_), __LINE__));
  11932. Info = _WRONG_IDENTIFIER;
  11933. }
  11934. else if (!plci->State || !plci->NL.Id || plci->nl_remove_id)
  11935. {
  11936. dbug (1, dprintf ("[%06lx] %s,%d: Wrong state",
  11937. UnMapId (Id), (char *)(FILE_), __LINE__));
  11938. Info = _WRONG_STATE;
  11939. }
  11940. else
  11941. {
  11942. plci->command = 0;
  11943. plci->ec_cmd = GET_WORD (ec_parms[0].info);
  11944. plci->ec_idi_options &= ~(LEC_MANUAL_DISABLE | LEC_RESET_COEFFICIENTS);
  11945. result[0] = 5;
  11946. PUT_WORD (&result[1], plci->ec_cmd);
  11947. result[3] = 2;
  11948. PUT_WORD (&result[4], GOOD);
  11949. plci->ec_idi_options &= ~(LEC_ENABLE_NONLINEAR_PROCESSING |
  11950. LEC_ENABLE_2100HZ_DETECTOR | LEC_REQUIRE_2100HZ_REVERSALS);
  11951. plci->ec_tail_length = 0;
  11952. if (ec_parms[1].length >= 2)
  11953. {
  11954. opt = GET_WORD (&ec_parms[1].info[1]);
  11955. if (opt & EC_ENABLE_NON_LINEAR_PROCESSING)
  11956. plci->ec_idi_options |= LEC_ENABLE_NONLINEAR_PROCESSING;
  11957. if (opt & EC_DETECT_DISABLE_TONE)
  11958. plci->ec_idi_options |= LEC_ENABLE_2100HZ_DETECTOR;
  11959. if (!(opt & EC_DO_NOT_REQUIRE_REVERSALS))
  11960. plci->ec_idi_options |= LEC_REQUIRE_2100HZ_REVERSALS;
  11961. if (ec_parms[1].length >= 4)
  11962. {
  11963. plci->ec_tail_length = GET_WORD (&ec_parms[1].info[3]);
  11964. }
  11965. }
  11966. switch (plci->ec_cmd)
  11967. {
  11968. case EC_ENABLE_OPERATION:
  11969. plci->ec_idi_options &= ~LEC_FREEZE_COEFFICIENTS;
  11970. start_internal_command (Id, plci, ec_command);
  11971. return (false);
  11972. case EC_DISABLE_OPERATION:
  11973. plci->ec_idi_options = LEC_ENABLE_ECHO_CANCELLER |
  11974. LEC_MANUAL_DISABLE | LEC_ENABLE_NONLINEAR_PROCESSING |
  11975. LEC_RESET_COEFFICIENTS;
  11976. start_internal_command (Id, plci, ec_command);
  11977. return (false);
  11978. default:
  11979. dbug (1, dprintf ("[%06lx] %s,%d: EC unknown request %04x",
  11980. UnMapId (Id), (char *)(FILE_), __LINE__, plci->ec_cmd));
  11981. PUT_WORD (&result[4], _FACILITY_SPECIFIC_FUNCTION_NOT_SUPP);
  11982. }
  11983. }
  11984. }
  11985. }
  11986. }
  11987. sendf (appl, _FACILITY_R | CONFIRM, Id & 0xffffL, Number,
  11988. "wws", Info, (appl->appl_flags & APPL_FLAG_PRIV_EC_SPEC) ?
  11989. PRIV_SELECTOR_ECHO_CANCELLER : SELECTOR_ECHO_CANCELLER, result);
  11990. return (false);
  11991. }
  11992. static void ec_indication (dword Id, PLCI *plci, byte *msg, word length)
  11993. {
  11994. byte result[8];
  11995. dbug (1, dprintf ("[%06lx] %s,%d: ec_indication",
  11996. UnMapId (Id), (char *)(FILE_), __LINE__));
  11997. if (!(plci->ec_idi_options & LEC_MANUAL_DISABLE))
  11998. {
  11999. if (plci->appl->appl_flags & APPL_FLAG_PRIV_EC_SPEC)
  12000. {
  12001. result[0] = 2;
  12002. PUT_WORD (&result[1], 0);
  12003. switch (msg[1])
  12004. {
  12005. case LEC_DISABLE_TYPE_CONTIGNUOUS_2100HZ:
  12006. PUT_WORD (&result[1], EC_BYPASS_DUE_TO_CONTINUOUS_2100HZ);
  12007. break;
  12008. case LEC_DISABLE_TYPE_REVERSED_2100HZ:
  12009. PUT_WORD (&result[1], EC_BYPASS_DUE_TO_REVERSED_2100HZ);
  12010. break;
  12011. case LEC_DISABLE_RELEASED:
  12012. PUT_WORD (&result[1], EC_BYPASS_RELEASED);
  12013. break;
  12014. }
  12015. }
  12016. else
  12017. {
  12018. result[0] = 5;
  12019. PUT_WORD (&result[1], EC_BYPASS_INDICATION);
  12020. result[3] = 2;
  12021. PUT_WORD (&result[4], 0);
  12022. switch (msg[1])
  12023. {
  12024. case LEC_DISABLE_TYPE_CONTIGNUOUS_2100HZ:
  12025. PUT_WORD (&result[4], EC_BYPASS_DUE_TO_CONTINUOUS_2100HZ);
  12026. break;
  12027. case LEC_DISABLE_TYPE_REVERSED_2100HZ:
  12028. PUT_WORD (&result[4], EC_BYPASS_DUE_TO_REVERSED_2100HZ);
  12029. break;
  12030. case LEC_DISABLE_RELEASED:
  12031. PUT_WORD (&result[4], EC_BYPASS_RELEASED);
  12032. break;
  12033. }
  12034. }
  12035. sendf (plci->appl, _FACILITY_I, Id & 0xffffL, 0, "ws", (plci->appl->appl_flags & APPL_FLAG_PRIV_EC_SPEC) ?
  12036. PRIV_SELECTOR_ECHO_CANCELLER : SELECTOR_ECHO_CANCELLER, result);
  12037. }
  12038. }
  12039. /*------------------------------------------------------------------*/
  12040. /* Advanced voice */
  12041. /*------------------------------------------------------------------*/
  12042. static void adv_voice_write_coefs (PLCI *plci, word write_command)
  12043. {
  12044. DIVA_CAPI_ADAPTER *a;
  12045. word i;
  12046. byte *p;
  12047. word w, n, j, k;
  12048. byte ch_map[MIXER_CHANNELS_BRI];
  12049. byte coef_buffer[ADV_VOICE_COEF_BUFFER_SIZE + 2];
  12050. dbug (1, dprintf ("[%06lx] %s,%d: adv_voice_write_coefs %d",
  12051. (dword)((plci->Id << 8) | UnMapController (plci->adapter->Id)),
  12052. (char *)(FILE_), __LINE__, write_command));
  12053. a = plci->adapter;
  12054. p = coef_buffer + 1;
  12055. *(p++) = DSP_CTRL_OLD_SET_MIXER_COEFFICIENTS;
  12056. i = 0;
  12057. while (i + sizeof(word) <= a->adv_voice_coef_length)
  12058. {
  12059. PUT_WORD (p, GET_WORD (a->adv_voice_coef_buffer + i));
  12060. p += 2;
  12061. i += 2;
  12062. }
  12063. while (i < ADV_VOICE_OLD_COEF_COUNT * sizeof(word))
  12064. {
  12065. PUT_WORD (p, 0x8000);
  12066. p += 2;
  12067. i += 2;
  12068. }
  12069. if (!a->li_pri && (plci->li_bchannel_id == 0))
  12070. {
  12071. if ((li_config_table[a->li_base].plci == NULL) && (li_config_table[a->li_base + 1].plci != NULL))
  12072. {
  12073. plci->li_bchannel_id = 1;
  12074. li_config_table[a->li_base].plci = plci;
  12075. dbug (1, dprintf ("[%06lx] %s,%d: adv_voice_set_bchannel_id %d",
  12076. (dword)((plci->Id << 8) | UnMapController (plci->adapter->Id)),
  12077. (char *)(FILE_), __LINE__, plci->li_bchannel_id));
  12078. }
  12079. else if ((li_config_table[a->li_base].plci != NULL) && (li_config_table[a->li_base + 1].plci == NULL))
  12080. {
  12081. plci->li_bchannel_id = 2;
  12082. li_config_table[a->li_base + 1].plci = plci;
  12083. dbug (1, dprintf ("[%06lx] %s,%d: adv_voice_set_bchannel_id %d",
  12084. (dword)((plci->Id << 8) | UnMapController (plci->adapter->Id)),
  12085. (char *)(FILE_), __LINE__, plci->li_bchannel_id));
  12086. }
  12087. }
  12088. if (!a->li_pri && (plci->li_bchannel_id != 0)
  12089. && (li_config_table[a->li_base + (plci->li_bchannel_id - 1)].plci == plci))
  12090. {
  12091. i = a->li_base + (plci->li_bchannel_id - 1);
  12092. switch (write_command)
  12093. {
  12094. case ADV_VOICE_WRITE_ACTIVATION:
  12095. j = a->li_base + MIXER_IC_CHANNEL_BASE + (plci->li_bchannel_id - 1);
  12096. k = a->li_base + MIXER_IC_CHANNEL_BASE + (2 - plci->li_bchannel_id);
  12097. if (!(plci->B1_facilities & B1_FACILITY_MIXER))
  12098. {
  12099. li_config_table[j].flag_table[i] |= LI_FLAG_CONFERENCE | LI_FLAG_MIX;
  12100. li_config_table[i].flag_table[j] |= LI_FLAG_CONFERENCE | LI_FLAG_MONITOR;
  12101. }
  12102. if (a->manufacturer_features & MANUFACTURER_FEATURE_SLAVE_CODEC)
  12103. {
  12104. li_config_table[k].flag_table[i] |= LI_FLAG_CONFERENCE | LI_FLAG_MIX;
  12105. li_config_table[i].flag_table[k] |= LI_FLAG_CONFERENCE | LI_FLAG_MONITOR;
  12106. li_config_table[k].flag_table[j] |= LI_FLAG_CONFERENCE;
  12107. li_config_table[j].flag_table[k] |= LI_FLAG_CONFERENCE;
  12108. }
  12109. mixer_calculate_coefs (a);
  12110. li_config_table[i].curchnl = li_config_table[i].channel;
  12111. li_config_table[j].curchnl = li_config_table[j].channel;
  12112. if (a->manufacturer_features & MANUFACTURER_FEATURE_SLAVE_CODEC)
  12113. li_config_table[k].curchnl = li_config_table[k].channel;
  12114. break;
  12115. case ADV_VOICE_WRITE_DEACTIVATION:
  12116. for (j = 0; j < li_total_channels; j++)
  12117. {
  12118. li_config_table[i].flag_table[j] = 0;
  12119. li_config_table[j].flag_table[i] = 0;
  12120. }
  12121. k = a->li_base + MIXER_IC_CHANNEL_BASE + (plci->li_bchannel_id - 1);
  12122. for (j = 0; j < li_total_channels; j++)
  12123. {
  12124. li_config_table[k].flag_table[j] = 0;
  12125. li_config_table[j].flag_table[k] = 0;
  12126. }
  12127. if (a->manufacturer_features & MANUFACTURER_FEATURE_SLAVE_CODEC)
  12128. {
  12129. k = a->li_base + MIXER_IC_CHANNEL_BASE + (2 - plci->li_bchannel_id);
  12130. for (j = 0; j < li_total_channels; j++)
  12131. {
  12132. li_config_table[k].flag_table[j] = 0;
  12133. li_config_table[j].flag_table[k] = 0;
  12134. }
  12135. }
  12136. mixer_calculate_coefs (a);
  12137. break;
  12138. }
  12139. if (plci->B1_facilities & B1_FACILITY_MIXER)
  12140. {
  12141. w = 0;
  12142. if (ADV_VOICE_NEW_COEF_BASE + sizeof(word) <= a->adv_voice_coef_length)
  12143. w = GET_WORD (a->adv_voice_coef_buffer + ADV_VOICE_NEW_COEF_BASE);
  12144. if (li_config_table[i].channel & LI_CHANNEL_TX_DATA)
  12145. w |= MIXER_FEATURE_ENABLE_TX_DATA;
  12146. if (li_config_table[i].channel & LI_CHANNEL_RX_DATA)
  12147. w |= MIXER_FEATURE_ENABLE_RX_DATA;
  12148. *(p++) = (byte) w;
  12149. *(p++) = (byte)(w >> 8);
  12150. for (j = 0; j < sizeof(ch_map); j += 2)
  12151. {
  12152. ch_map[j] = (byte)(j + (plci->li_bchannel_id - 1));
  12153. ch_map[j+1] = (byte)(j + (2 - plci->li_bchannel_id));
  12154. }
  12155. for (n = 0; n < ARRAY_SIZE(mixer_write_prog_bri); n++)
  12156. {
  12157. i = a->li_base + ch_map[mixer_write_prog_bri[n].to_ch];
  12158. j = a->li_base + ch_map[mixer_write_prog_bri[n].from_ch];
  12159. if (li_config_table[i].channel & li_config_table[j].channel & LI_CHANNEL_INVOLVED)
  12160. {
  12161. *(p++) = ((li_config_table[i].coef_table[j] & mixer_write_prog_bri[n].mask) ? 0x80 : 0x01);
  12162. w = ((li_config_table[i].coef_table[j] & 0xf) ^ (li_config_table[i].coef_table[j] >> 4));
  12163. li_config_table[i].coef_table[j] ^= (w & mixer_write_prog_bri[n].mask) << 4;
  12164. }
  12165. else
  12166. {
  12167. *(p++) = (ADV_VOICE_NEW_COEF_BASE + sizeof(word) + n < a->adv_voice_coef_length) ?
  12168. a->adv_voice_coef_buffer[ADV_VOICE_NEW_COEF_BASE + sizeof(word) + n] : 0x00;
  12169. }
  12170. }
  12171. }
  12172. else
  12173. {
  12174. for (i = ADV_VOICE_NEW_COEF_BASE; i < a->adv_voice_coef_length; i++)
  12175. *(p++) = a->adv_voice_coef_buffer[i];
  12176. }
  12177. }
  12178. else
  12179. {
  12180. for (i = ADV_VOICE_NEW_COEF_BASE; i < a->adv_voice_coef_length; i++)
  12181. *(p++) = a->adv_voice_coef_buffer[i];
  12182. }
  12183. coef_buffer[0] = (p - coef_buffer) - 1;
  12184. add_p (plci, FTY, coef_buffer);
  12185. sig_req (plci, TEL_CTRL, 0);
  12186. send_req (plci);
  12187. }
  12188. static void adv_voice_clear_config (PLCI *plci)
  12189. {
  12190. DIVA_CAPI_ADAPTER *a;
  12191. word i, j;
  12192. dbug (1, dprintf ("[%06lx] %s,%d: adv_voice_clear_config",
  12193. (dword)((plci->Id << 8) | UnMapController (plci->adapter->Id)),
  12194. (char *)(FILE_), __LINE__));
  12195. a = plci->adapter;
  12196. if ((plci->tel == ADV_VOICE) && (plci == a->AdvSignalPLCI))
  12197. {
  12198. a->adv_voice_coef_length = 0;
  12199. if (!a->li_pri && (plci->li_bchannel_id != 0)
  12200. && (li_config_table[a->li_base + (plci->li_bchannel_id - 1)].plci == plci))
  12201. {
  12202. i = a->li_base + (plci->li_bchannel_id - 1);
  12203. li_config_table[i].curchnl = 0;
  12204. li_config_table[i].channel = 0;
  12205. li_config_table[i].chflags = 0;
  12206. for (j = 0; j < li_total_channels; j++)
  12207. {
  12208. li_config_table[i].flag_table[j] = 0;
  12209. li_config_table[j].flag_table[i] = 0;
  12210. li_config_table[i].coef_table[j] = 0;
  12211. li_config_table[j].coef_table[i] = 0;
  12212. }
  12213. li_config_table[i].coef_table[i] |= LI_COEF_CH_PC_SET | LI_COEF_PC_CH_SET;
  12214. i = a->li_base + MIXER_IC_CHANNEL_BASE + (plci->li_bchannel_id - 1);
  12215. li_config_table[i].curchnl = 0;
  12216. li_config_table[i].channel = 0;
  12217. li_config_table[i].chflags = 0;
  12218. for (j = 0; j < li_total_channels; j++)
  12219. {
  12220. li_config_table[i].flag_table[j] = 0;
  12221. li_config_table[j].flag_table[i] = 0;
  12222. li_config_table[i].coef_table[j] = 0;
  12223. li_config_table[j].coef_table[i] = 0;
  12224. }
  12225. if (a->manufacturer_features & MANUFACTURER_FEATURE_SLAVE_CODEC)
  12226. {
  12227. i = a->li_base + MIXER_IC_CHANNEL_BASE + (2 - plci->li_bchannel_id);
  12228. li_config_table[i].curchnl = 0;
  12229. li_config_table[i].channel = 0;
  12230. li_config_table[i].chflags = 0;
  12231. for (j = 0; j < li_total_channels; j++)
  12232. {
  12233. li_config_table[i].flag_table[j] = 0;
  12234. li_config_table[j].flag_table[i] = 0;
  12235. li_config_table[i].coef_table[j] = 0;
  12236. li_config_table[j].coef_table[i] = 0;
  12237. }
  12238. }
  12239. }
  12240. }
  12241. }
  12242. static void adv_voice_prepare_switch (dword Id, PLCI *plci)
  12243. {
  12244. dbug (1, dprintf ("[%06lx] %s,%d: adv_voice_prepare_switch",
  12245. UnMapId (Id), (char *)(FILE_), __LINE__));
  12246. }
  12247. static word adv_voice_save_config (dword Id, PLCI *plci, byte Rc)
  12248. {
  12249. dbug (1, dprintf ("[%06lx] %s,%d: adv_voice_save_config %02x %d",
  12250. UnMapId (Id), (char *)(FILE_), __LINE__, Rc, plci->adjust_b_state));
  12251. return (GOOD);
  12252. }
  12253. static word adv_voice_restore_config (dword Id, PLCI *plci, byte Rc)
  12254. {
  12255. DIVA_CAPI_ADAPTER *a;
  12256. word Info;
  12257. dbug (1, dprintf ("[%06lx] %s,%d: adv_voice_restore_config %02x %d",
  12258. UnMapId (Id), (char *)(FILE_), __LINE__, Rc, plci->adjust_b_state));
  12259. Info = GOOD;
  12260. a = plci->adapter;
  12261. if ((plci->B1_facilities & B1_FACILITY_VOICE)
  12262. && (plci->tel == ADV_VOICE) && (plci == a->AdvSignalPLCI))
  12263. {
  12264. switch (plci->adjust_b_state)
  12265. {
  12266. case ADJUST_B_RESTORE_VOICE_1:
  12267. plci->internal_command = plci->adjust_b_command;
  12268. if (plci->sig_req)
  12269. {
  12270. plci->adjust_b_state = ADJUST_B_RESTORE_VOICE_1;
  12271. break;
  12272. }
  12273. adv_voice_write_coefs (plci, ADV_VOICE_WRITE_UPDATE);
  12274. plci->adjust_b_state = ADJUST_B_RESTORE_VOICE_2;
  12275. break;
  12276. case ADJUST_B_RESTORE_VOICE_2:
  12277. if ((Rc != OK) && (Rc != OK_FC))
  12278. {
  12279. dbug (1, dprintf ("[%06lx] %s,%d: Restore voice config failed %02x",
  12280. UnMapId (Id), (char *)(FILE_), __LINE__, Rc));
  12281. Info = _WRONG_STATE;
  12282. break;
  12283. }
  12284. break;
  12285. }
  12286. }
  12287. return (Info);
  12288. }
  12289. /*------------------------------------------------------------------*/
  12290. /* B1 resource switching */
  12291. /*------------------------------------------------------------------*/
  12292. static byte b1_facilities_table[] =
  12293. {
  12294. 0x00, /* 0 No bchannel resources */
  12295. 0x00, /* 1 Codec (automatic law) */
  12296. 0x00, /* 2 Codec (A-law) */
  12297. 0x00, /* 3 Codec (y-law) */
  12298. 0x00, /* 4 HDLC for X.21 */
  12299. 0x00, /* 5 HDLC */
  12300. 0x00, /* 6 External Device 0 */
  12301. 0x00, /* 7 External Device 1 */
  12302. 0x00, /* 8 HDLC 56k */
  12303. 0x00, /* 9 Transparent */
  12304. 0x00, /* 10 Loopback to network */
  12305. 0x00, /* 11 Test pattern to net */
  12306. 0x00, /* 12 Rate adaptation sync */
  12307. 0x00, /* 13 Rate adaptation async */
  12308. 0x00, /* 14 R-Interface */
  12309. 0x00, /* 15 HDLC 128k leased line */
  12310. 0x00, /* 16 FAX */
  12311. 0x00, /* 17 Modem async */
  12312. 0x00, /* 18 Modem sync HDLC */
  12313. 0x00, /* 19 V.110 async HDLC */
  12314. 0x12, /* 20 Adv voice (Trans,mixer) */
  12315. 0x00, /* 21 Codec connected to IC */
  12316. 0x0c, /* 22 Trans,DTMF */
  12317. 0x1e, /* 23 Trans,DTMF+mixer */
  12318. 0x1f, /* 24 Trans,DTMF+mixer+local */
  12319. 0x13, /* 25 Trans,mixer+local */
  12320. 0x12, /* 26 HDLC,mixer */
  12321. 0x12, /* 27 HDLC 56k,mixer */
  12322. 0x2c, /* 28 Trans,LEC+DTMF */
  12323. 0x3e, /* 29 Trans,LEC+DTMF+mixer */
  12324. 0x3f, /* 30 Trans,LEC+DTMF+mixer+local */
  12325. 0x2c, /* 31 RTP,LEC+DTMF */
  12326. 0x3e, /* 32 RTP,LEC+DTMF+mixer */
  12327. 0x3f, /* 33 RTP,LEC+DTMF+mixer+local */
  12328. 0x00, /* 34 Signaling task */
  12329. 0x00, /* 35 PIAFS */
  12330. 0x0c, /* 36 Trans,DTMF+TONE */
  12331. 0x1e, /* 37 Trans,DTMF+TONE+mixer */
  12332. 0x1f /* 38 Trans,DTMF+TONE+mixer+local*/
  12333. };
  12334. static word get_b1_facilities (PLCI * plci, byte b1_resource)
  12335. {
  12336. word b1_facilities;
  12337. b1_facilities = b1_facilities_table[b1_resource];
  12338. if ((b1_resource == 9) || (b1_resource == 20) || (b1_resource == 25))
  12339. {
  12340. if (!(((plci->requested_options_conn | plci->requested_options) & (1L << PRIVATE_DTMF_TONE))
  12341. || (plci->appl && (plci->adapter->requested_options_table[plci->appl->Id-1] & (1L << PRIVATE_DTMF_TONE)))))
  12342. {
  12343. if (plci->adapter->manufacturer_features & MANUFACTURER_FEATURE_SOFTDTMF_SEND)
  12344. b1_facilities |= B1_FACILITY_DTMFX;
  12345. if (plci->adapter->manufacturer_features & MANUFACTURER_FEATURE_SOFTDTMF_RECEIVE)
  12346. b1_facilities |= B1_FACILITY_DTMFR;
  12347. }
  12348. }
  12349. if ((b1_resource == 17) || (b1_resource == 18))
  12350. {
  12351. if (plci->adapter->manufacturer_features & (MANUFACTURER_FEATURE_V18 | MANUFACTURER_FEATURE_VOWN))
  12352. b1_facilities |= B1_FACILITY_DTMFX | B1_FACILITY_DTMFR;
  12353. }
  12354. /*
  12355. dbug (1, dprintf ("[%06lx] %s,%d: get_b1_facilities %d %04x",
  12356. (dword)((plci->Id << 8) | UnMapController (plci->adapter->Id)),
  12357. (char far *)(FILE_), __LINE__, b1_resource, b1_facilites));
  12358. */
  12359. return (b1_facilities);
  12360. }
  12361. static byte add_b1_facilities (PLCI * plci, byte b1_resource, word b1_facilities)
  12362. {
  12363. byte b;
  12364. switch (b1_resource)
  12365. {
  12366. case 5:
  12367. case 26:
  12368. if (b1_facilities & (B1_FACILITY_MIXER | B1_FACILITY_VOICE))
  12369. b = 26;
  12370. else
  12371. b = 5;
  12372. break;
  12373. case 8:
  12374. case 27:
  12375. if (b1_facilities & (B1_FACILITY_MIXER | B1_FACILITY_VOICE))
  12376. b = 27;
  12377. else
  12378. b = 8;
  12379. break;
  12380. case 9:
  12381. case 20:
  12382. case 22:
  12383. case 23:
  12384. case 24:
  12385. case 25:
  12386. case 28:
  12387. case 29:
  12388. case 30:
  12389. case 36:
  12390. case 37:
  12391. case 38:
  12392. if (b1_facilities & B1_FACILITY_EC)
  12393. {
  12394. if (b1_facilities & B1_FACILITY_LOCAL)
  12395. b = 30;
  12396. else if (b1_facilities & (B1_FACILITY_MIXER | B1_FACILITY_VOICE))
  12397. b = 29;
  12398. else
  12399. b = 28;
  12400. }
  12401. else if ((b1_facilities & (B1_FACILITY_DTMFX | B1_FACILITY_DTMFR | B1_FACILITY_MIXER))
  12402. && (((plci->requested_options_conn | plci->requested_options) & (1L << PRIVATE_DTMF_TONE))
  12403. || (plci->appl && (plci->adapter->requested_options_table[plci->appl->Id-1] & (1L << PRIVATE_DTMF_TONE)))))
  12404. {
  12405. if (b1_facilities & B1_FACILITY_LOCAL)
  12406. b = 38;
  12407. else if (b1_facilities & (B1_FACILITY_MIXER | B1_FACILITY_VOICE))
  12408. b = 37;
  12409. else
  12410. b = 36;
  12411. }
  12412. else if (((plci->adapter->manufacturer_features & MANUFACTURER_FEATURE_HARDDTMF)
  12413. && !(plci->adapter->manufacturer_features & MANUFACTURER_FEATURE_SOFTDTMF_RECEIVE))
  12414. || ((b1_facilities & B1_FACILITY_DTMFR)
  12415. && ((b1_facilities & B1_FACILITY_MIXER)
  12416. || !(plci->adapter->manufacturer_features & MANUFACTURER_FEATURE_SOFTDTMF_RECEIVE)))
  12417. || ((b1_facilities & B1_FACILITY_DTMFX)
  12418. && ((b1_facilities & B1_FACILITY_MIXER)
  12419. || !(plci->adapter->manufacturer_features & MANUFACTURER_FEATURE_SOFTDTMF_SEND))))
  12420. {
  12421. if (b1_facilities & B1_FACILITY_LOCAL)
  12422. b = 24;
  12423. else if (b1_facilities & (B1_FACILITY_MIXER | B1_FACILITY_VOICE))
  12424. b = 23;
  12425. else
  12426. b = 22;
  12427. }
  12428. else
  12429. {
  12430. if (b1_facilities & B1_FACILITY_LOCAL)
  12431. b = 25;
  12432. else if (b1_facilities & (B1_FACILITY_MIXER | B1_FACILITY_VOICE))
  12433. b = 20;
  12434. else
  12435. b = 9;
  12436. }
  12437. break;
  12438. case 31:
  12439. case 32:
  12440. case 33:
  12441. if (b1_facilities & B1_FACILITY_LOCAL)
  12442. b = 33;
  12443. else if (b1_facilities & (B1_FACILITY_MIXER | B1_FACILITY_VOICE))
  12444. b = 32;
  12445. else
  12446. b = 31;
  12447. break;
  12448. default:
  12449. b = b1_resource;
  12450. }
  12451. dbug (1, dprintf ("[%06lx] %s,%d: add_b1_facilities %d %04x %d %04x",
  12452. (dword)((plci->Id << 8) | UnMapController (plci->adapter->Id)),
  12453. (char *)(FILE_), __LINE__,
  12454. b1_resource, b1_facilities, b, get_b1_facilities (plci, b)));
  12455. return (b);
  12456. }
  12457. static void adjust_b1_facilities (PLCI *plci, byte new_b1_resource, word new_b1_facilities)
  12458. {
  12459. word removed_facilities;
  12460. dbug (1, dprintf ("[%06lx] %s,%d: adjust_b1_facilities %d %04x %04x",
  12461. (dword)((plci->Id << 8) | UnMapController (plci->adapter->Id)),
  12462. (char *)(FILE_), __LINE__, new_b1_resource, new_b1_facilities,
  12463. new_b1_facilities & get_b1_facilities (plci, new_b1_resource)));
  12464. new_b1_facilities &= get_b1_facilities (plci, new_b1_resource);
  12465. removed_facilities = plci->B1_facilities & ~new_b1_facilities;
  12466. if (removed_facilities & B1_FACILITY_EC)
  12467. ec_clear_config (plci);
  12468. if (removed_facilities & B1_FACILITY_DTMFR)
  12469. {
  12470. dtmf_rec_clear_config (plci);
  12471. dtmf_parameter_clear_config (plci);
  12472. }
  12473. if (removed_facilities & B1_FACILITY_DTMFX)
  12474. dtmf_send_clear_config (plci);
  12475. if (removed_facilities & B1_FACILITY_MIXER)
  12476. mixer_clear_config (plci);
  12477. if (removed_facilities & B1_FACILITY_VOICE)
  12478. adv_voice_clear_config (plci);
  12479. plci->B1_facilities = new_b1_facilities;
  12480. }
  12481. static void adjust_b_clear (PLCI *plci)
  12482. {
  12483. dbug (1, dprintf ("[%06lx] %s,%d: adjust_b_clear",
  12484. (dword)((plci->Id << 8) | UnMapController (plci->adapter->Id)),
  12485. (char *)(FILE_), __LINE__));
  12486. plci->adjust_b_restore = false;
  12487. }
  12488. static word adjust_b_process (dword Id, PLCI *plci, byte Rc)
  12489. {
  12490. word Info;
  12491. byte b1_resource;
  12492. NCCI * ncci_ptr;
  12493. API_PARSE bp[2];
  12494. dbug (1, dprintf ("[%06lx] %s,%d: adjust_b_process %02x %d",
  12495. UnMapId (Id), (char *)(FILE_), __LINE__, Rc, plci->adjust_b_state));
  12496. Info = GOOD;
  12497. switch (plci->adjust_b_state)
  12498. {
  12499. case ADJUST_B_START:
  12500. if ((plci->adjust_b_parms_msg == NULL)
  12501. && (plci->adjust_b_mode & ADJUST_B_MODE_SWITCH_L1)
  12502. && ((plci->adjust_b_mode & ~(ADJUST_B_MODE_SAVE | ADJUST_B_MODE_SWITCH_L1 |
  12503. ADJUST_B_MODE_NO_RESOURCE | ADJUST_B_MODE_RESTORE)) == 0))
  12504. {
  12505. b1_resource = (plci->adjust_b_mode == ADJUST_B_MODE_NO_RESOURCE) ?
  12506. 0 : add_b1_facilities (plci, plci->B1_resource, plci->adjust_b_facilities);
  12507. if (b1_resource == plci->B1_resource)
  12508. {
  12509. adjust_b1_facilities (plci, b1_resource, plci->adjust_b_facilities);
  12510. break;
  12511. }
  12512. if (plci->adjust_b_facilities & ~get_b1_facilities (plci, b1_resource))
  12513. {
  12514. dbug (1, dprintf ("[%06lx] %s,%d: Adjust B nonsupported facilities %d %d %04x",
  12515. UnMapId (Id), (char *)(FILE_), __LINE__,
  12516. plci->B1_resource, b1_resource, plci->adjust_b_facilities));
  12517. Info = _WRONG_STATE;
  12518. break;
  12519. }
  12520. }
  12521. if (plci->adjust_b_mode & ADJUST_B_MODE_SAVE)
  12522. {
  12523. mixer_prepare_switch (Id, plci);
  12524. dtmf_prepare_switch (Id, plci);
  12525. dtmf_parameter_prepare_switch (Id, plci);
  12526. ec_prepare_switch (Id, plci);
  12527. adv_voice_prepare_switch (Id, plci);
  12528. }
  12529. plci->adjust_b_state = ADJUST_B_SAVE_MIXER_1;
  12530. Rc = OK;
  12531. case ADJUST_B_SAVE_MIXER_1:
  12532. if (plci->adjust_b_mode & ADJUST_B_MODE_SAVE)
  12533. {
  12534. Info = mixer_save_config (Id, plci, Rc);
  12535. if ((Info != GOOD) || plci->internal_command)
  12536. break;
  12537. }
  12538. plci->adjust_b_state = ADJUST_B_SAVE_DTMF_1;
  12539. Rc = OK;
  12540. case ADJUST_B_SAVE_DTMF_1:
  12541. if (plci->adjust_b_mode & ADJUST_B_MODE_SAVE)
  12542. {
  12543. Info = dtmf_save_config (Id, plci, Rc);
  12544. if ((Info != GOOD) || plci->internal_command)
  12545. break;
  12546. }
  12547. plci->adjust_b_state = ADJUST_B_REMOVE_L23_1;
  12548. case ADJUST_B_REMOVE_L23_1:
  12549. if ((plci->adjust_b_mode & ADJUST_B_MODE_REMOVE_L23)
  12550. && plci->NL.Id && !plci->nl_remove_id)
  12551. {
  12552. plci->internal_command = plci->adjust_b_command;
  12553. if (plci->adjust_b_ncci != 0)
  12554. {
  12555. ncci_ptr = &(plci->adapter->ncci[plci->adjust_b_ncci]);
  12556. while (ncci_ptr->data_pending)
  12557. {
  12558. plci->data_sent_ptr = ncci_ptr->DBuffer[ncci_ptr->data_out].P;
  12559. data_rc (plci, plci->adapter->ncci_ch[plci->adjust_b_ncci]);
  12560. }
  12561. while (ncci_ptr->data_ack_pending)
  12562. data_ack (plci, plci->adapter->ncci_ch[plci->adjust_b_ncci]);
  12563. }
  12564. nl_req_ncci (plci, REMOVE,
  12565. (byte)((plci->adjust_b_mode & ADJUST_B_MODE_CONNECT) ? plci->adjust_b_ncci : 0));
  12566. send_req (plci);
  12567. plci->adjust_b_state = ADJUST_B_REMOVE_L23_2;
  12568. break;
  12569. }
  12570. plci->adjust_b_state = ADJUST_B_REMOVE_L23_2;
  12571. Rc = OK;
  12572. case ADJUST_B_REMOVE_L23_2:
  12573. if ((Rc != OK) && (Rc != OK_FC))
  12574. {
  12575. dbug (1, dprintf ("[%06lx] %s,%d: Adjust B remove failed %02x",
  12576. UnMapId (Id), (char *)(FILE_), __LINE__, Rc));
  12577. Info = _WRONG_STATE;
  12578. break;
  12579. }
  12580. if (plci->adjust_b_mode & ADJUST_B_MODE_REMOVE_L23)
  12581. {
  12582. if (plci_nl_busy (plci))
  12583. {
  12584. plci->internal_command = plci->adjust_b_command;
  12585. break;
  12586. }
  12587. }
  12588. plci->adjust_b_state = ADJUST_B_SAVE_EC_1;
  12589. Rc = OK;
  12590. case ADJUST_B_SAVE_EC_1:
  12591. if (plci->adjust_b_mode & ADJUST_B_MODE_SAVE)
  12592. {
  12593. Info = ec_save_config (Id, plci, Rc);
  12594. if ((Info != GOOD) || plci->internal_command)
  12595. break;
  12596. }
  12597. plci->adjust_b_state = ADJUST_B_SAVE_DTMF_PARAMETER_1;
  12598. Rc = OK;
  12599. case ADJUST_B_SAVE_DTMF_PARAMETER_1:
  12600. if (plci->adjust_b_mode & ADJUST_B_MODE_SAVE)
  12601. {
  12602. Info = dtmf_parameter_save_config (Id, plci, Rc);
  12603. if ((Info != GOOD) || plci->internal_command)
  12604. break;
  12605. }
  12606. plci->adjust_b_state = ADJUST_B_SAVE_VOICE_1;
  12607. Rc = OK;
  12608. case ADJUST_B_SAVE_VOICE_1:
  12609. if (plci->adjust_b_mode & ADJUST_B_MODE_SAVE)
  12610. {
  12611. Info = adv_voice_save_config (Id, plci, Rc);
  12612. if ((Info != GOOD) || plci->internal_command)
  12613. break;
  12614. }
  12615. plci->adjust_b_state = ADJUST_B_SWITCH_L1_1;
  12616. case ADJUST_B_SWITCH_L1_1:
  12617. if (plci->adjust_b_mode & ADJUST_B_MODE_SWITCH_L1)
  12618. {
  12619. if (plci->sig_req)
  12620. {
  12621. plci->internal_command = plci->adjust_b_command;
  12622. break;
  12623. }
  12624. if (plci->adjust_b_parms_msg != NULL)
  12625. api_load_msg (plci->adjust_b_parms_msg, bp);
  12626. else
  12627. api_load_msg (&plci->B_protocol, bp);
  12628. Info = add_b1 (plci, bp,
  12629. (word)((plci->adjust_b_mode & ADJUST_B_MODE_NO_RESOURCE) ? 2 : 0),
  12630. plci->adjust_b_facilities);
  12631. if (Info != GOOD)
  12632. {
  12633. dbug (1, dprintf ("[%06lx] %s,%d: Adjust B invalid L1 parameters %d %04x",
  12634. UnMapId (Id), (char *)(FILE_), __LINE__,
  12635. plci->B1_resource, plci->adjust_b_facilities));
  12636. break;
  12637. }
  12638. plci->internal_command = plci->adjust_b_command;
  12639. sig_req (plci, RESOURCES, 0);
  12640. send_req (plci);
  12641. plci->adjust_b_state = ADJUST_B_SWITCH_L1_2;
  12642. break;
  12643. }
  12644. plci->adjust_b_state = ADJUST_B_SWITCH_L1_2;
  12645. Rc = OK;
  12646. case ADJUST_B_SWITCH_L1_2:
  12647. if ((Rc != OK) && (Rc != OK_FC))
  12648. {
  12649. dbug (1, dprintf ("[%06lx] %s,%d: Adjust B switch failed %02x %d %04x",
  12650. UnMapId (Id), (char *)(FILE_), __LINE__,
  12651. Rc, plci->B1_resource, plci->adjust_b_facilities));
  12652. Info = _WRONG_STATE;
  12653. break;
  12654. }
  12655. plci->adjust_b_state = ADJUST_B_RESTORE_VOICE_1;
  12656. Rc = OK;
  12657. case ADJUST_B_RESTORE_VOICE_1:
  12658. case ADJUST_B_RESTORE_VOICE_2:
  12659. if (plci->adjust_b_mode & ADJUST_B_MODE_RESTORE)
  12660. {
  12661. Info = adv_voice_restore_config (Id, plci, Rc);
  12662. if ((Info != GOOD) || plci->internal_command)
  12663. break;
  12664. }
  12665. plci->adjust_b_state = ADJUST_B_RESTORE_DTMF_PARAMETER_1;
  12666. Rc = OK;
  12667. case ADJUST_B_RESTORE_DTMF_PARAMETER_1:
  12668. case ADJUST_B_RESTORE_DTMF_PARAMETER_2:
  12669. if (plci->adjust_b_mode & ADJUST_B_MODE_RESTORE)
  12670. {
  12671. Info = dtmf_parameter_restore_config (Id, plci, Rc);
  12672. if ((Info != GOOD) || plci->internal_command)
  12673. break;
  12674. }
  12675. plci->adjust_b_state = ADJUST_B_RESTORE_EC_1;
  12676. Rc = OK;
  12677. case ADJUST_B_RESTORE_EC_1:
  12678. case ADJUST_B_RESTORE_EC_2:
  12679. if (plci->adjust_b_mode & ADJUST_B_MODE_RESTORE)
  12680. {
  12681. Info = ec_restore_config (Id, plci, Rc);
  12682. if ((Info != GOOD) || plci->internal_command)
  12683. break;
  12684. }
  12685. plci->adjust_b_state = ADJUST_B_ASSIGN_L23_1;
  12686. case ADJUST_B_ASSIGN_L23_1:
  12687. if (plci->adjust_b_mode & ADJUST_B_MODE_ASSIGN_L23)
  12688. {
  12689. if (plci_nl_busy (plci))
  12690. {
  12691. plci->internal_command = plci->adjust_b_command;
  12692. break;
  12693. }
  12694. if (plci->adjust_b_mode & ADJUST_B_MODE_CONNECT)
  12695. plci->call_dir |= CALL_DIR_FORCE_OUTG_NL;
  12696. if (plci->adjust_b_parms_msg != NULL)
  12697. api_load_msg (plci->adjust_b_parms_msg, bp);
  12698. else
  12699. api_load_msg (&plci->B_protocol, bp);
  12700. Info = add_b23 (plci, bp);
  12701. if (Info != GOOD)
  12702. {
  12703. dbug (1, dprintf ("[%06lx] %s,%d: Adjust B invalid L23 parameters %04x",
  12704. UnMapId (Id), (char *)(FILE_), __LINE__, Info));
  12705. break;
  12706. }
  12707. plci->internal_command = plci->adjust_b_command;
  12708. nl_req_ncci (plci, ASSIGN, 0);
  12709. send_req (plci);
  12710. plci->adjust_b_state = ADJUST_B_ASSIGN_L23_2;
  12711. break;
  12712. }
  12713. plci->adjust_b_state = ADJUST_B_ASSIGN_L23_2;
  12714. Rc = ASSIGN_OK;
  12715. case ADJUST_B_ASSIGN_L23_2:
  12716. if ((Rc != OK) && (Rc != OK_FC) && (Rc != ASSIGN_OK))
  12717. {
  12718. dbug (1, dprintf ("[%06lx] %s,%d: Adjust B assign failed %02x",
  12719. UnMapId (Id), (char *)(FILE_), __LINE__, Rc));
  12720. Info = _WRONG_STATE;
  12721. break;
  12722. }
  12723. if (plci->adjust_b_mode & ADJUST_B_MODE_ASSIGN_L23)
  12724. {
  12725. if (Rc != ASSIGN_OK)
  12726. {
  12727. plci->internal_command = plci->adjust_b_command;
  12728. break;
  12729. }
  12730. }
  12731. if (plci->adjust_b_mode & ADJUST_B_MODE_USER_CONNECT)
  12732. {
  12733. plci->adjust_b_restore = true;
  12734. break;
  12735. }
  12736. plci->adjust_b_state = ADJUST_B_CONNECT_1;
  12737. case ADJUST_B_CONNECT_1:
  12738. if (plci->adjust_b_mode & ADJUST_B_MODE_CONNECT)
  12739. {
  12740. plci->internal_command = plci->adjust_b_command;
  12741. if (plci_nl_busy (plci))
  12742. break;
  12743. nl_req_ncci (plci, N_CONNECT, 0);
  12744. send_req (plci);
  12745. plci->adjust_b_state = ADJUST_B_CONNECT_2;
  12746. break;
  12747. }
  12748. plci->adjust_b_state = ADJUST_B_RESTORE_DTMF_1;
  12749. Rc = OK;
  12750. case ADJUST_B_CONNECT_2:
  12751. case ADJUST_B_CONNECT_3:
  12752. case ADJUST_B_CONNECT_4:
  12753. if ((Rc != OK) && (Rc != OK_FC) && (Rc != 0))
  12754. {
  12755. dbug (1, dprintf ("[%06lx] %s,%d: Adjust B connect failed %02x",
  12756. UnMapId (Id), (char *)(FILE_), __LINE__, Rc));
  12757. Info = _WRONG_STATE;
  12758. break;
  12759. }
  12760. if (Rc == OK)
  12761. {
  12762. if (plci->adjust_b_mode & ADJUST_B_MODE_CONNECT)
  12763. {
  12764. get_ncci (plci, (byte)(Id >> 16), plci->adjust_b_ncci);
  12765. Id = (Id & 0xffff) | (((dword)(plci->adjust_b_ncci)) << 16);
  12766. }
  12767. if (plci->adjust_b_state == ADJUST_B_CONNECT_2)
  12768. plci->adjust_b_state = ADJUST_B_CONNECT_3;
  12769. else if (plci->adjust_b_state == ADJUST_B_CONNECT_4)
  12770. plci->adjust_b_state = ADJUST_B_RESTORE_DTMF_1;
  12771. }
  12772. else if (Rc == 0)
  12773. {
  12774. if (plci->adjust_b_state == ADJUST_B_CONNECT_2)
  12775. plci->adjust_b_state = ADJUST_B_CONNECT_4;
  12776. else if (plci->adjust_b_state == ADJUST_B_CONNECT_3)
  12777. plci->adjust_b_state = ADJUST_B_RESTORE_DTMF_1;
  12778. }
  12779. if (plci->adjust_b_state != ADJUST_B_RESTORE_DTMF_1)
  12780. {
  12781. plci->internal_command = plci->adjust_b_command;
  12782. break;
  12783. }
  12784. Rc = OK;
  12785. case ADJUST_B_RESTORE_DTMF_1:
  12786. case ADJUST_B_RESTORE_DTMF_2:
  12787. if (plci->adjust_b_mode & ADJUST_B_MODE_RESTORE)
  12788. {
  12789. Info = dtmf_restore_config (Id, plci, Rc);
  12790. if ((Info != GOOD) || plci->internal_command)
  12791. break;
  12792. }
  12793. plci->adjust_b_state = ADJUST_B_RESTORE_MIXER_1;
  12794. Rc = OK;
  12795. case ADJUST_B_RESTORE_MIXER_1:
  12796. case ADJUST_B_RESTORE_MIXER_2:
  12797. case ADJUST_B_RESTORE_MIXER_3:
  12798. case ADJUST_B_RESTORE_MIXER_4:
  12799. case ADJUST_B_RESTORE_MIXER_5:
  12800. case ADJUST_B_RESTORE_MIXER_6:
  12801. case ADJUST_B_RESTORE_MIXER_7:
  12802. if (plci->adjust_b_mode & ADJUST_B_MODE_RESTORE)
  12803. {
  12804. Info = mixer_restore_config (Id, plci, Rc);
  12805. if ((Info != GOOD) || plci->internal_command)
  12806. break;
  12807. }
  12808. plci->adjust_b_state = ADJUST_B_END;
  12809. case ADJUST_B_END:
  12810. break;
  12811. }
  12812. return (Info);
  12813. }
  12814. static void adjust_b1_resource (dword Id, PLCI *plci, API_SAVE *bp_msg, word b1_facilities, word internal_command)
  12815. {
  12816. dbug (1, dprintf ("[%06lx] %s,%d: adjust_b1_resource %d %04x",
  12817. UnMapId (Id), (char *)(FILE_), __LINE__,
  12818. plci->B1_resource, b1_facilities));
  12819. plci->adjust_b_parms_msg = bp_msg;
  12820. plci->adjust_b_facilities = b1_facilities;
  12821. plci->adjust_b_command = internal_command;
  12822. plci->adjust_b_ncci = (word)(Id >> 16);
  12823. if ((bp_msg == NULL) && (plci->B1_resource == 0))
  12824. plci->adjust_b_mode = ADJUST_B_MODE_SAVE | ADJUST_B_MODE_NO_RESOURCE | ADJUST_B_MODE_SWITCH_L1;
  12825. else
  12826. plci->adjust_b_mode = ADJUST_B_MODE_SAVE | ADJUST_B_MODE_SWITCH_L1 | ADJUST_B_MODE_RESTORE;
  12827. plci->adjust_b_state = ADJUST_B_START;
  12828. dbug (1, dprintf ("[%06lx] %s,%d: Adjust B1 resource %d %04x...",
  12829. UnMapId (Id), (char *)(FILE_), __LINE__,
  12830. plci->B1_resource, b1_facilities));
  12831. }
  12832. static void adjust_b_restore (dword Id, PLCI *plci, byte Rc)
  12833. {
  12834. word internal_command;
  12835. dbug (1, dprintf ("[%06lx] %s,%d: adjust_b_restore %02x %04x",
  12836. UnMapId (Id), (char *)(FILE_), __LINE__, Rc, plci->internal_command));
  12837. internal_command = plci->internal_command;
  12838. plci->internal_command = 0;
  12839. switch (internal_command)
  12840. {
  12841. default:
  12842. plci->command = 0;
  12843. if (plci->req_in != 0)
  12844. {
  12845. plci->internal_command = ADJUST_B_RESTORE_1;
  12846. break;
  12847. }
  12848. Rc = OK;
  12849. case ADJUST_B_RESTORE_1:
  12850. if ((Rc != OK) && (Rc != OK_FC))
  12851. {
  12852. dbug (1, dprintf ("[%06lx] %s,%d: Adjust B enqueued failed %02x",
  12853. UnMapId (Id), (char *)(FILE_), __LINE__, Rc));
  12854. }
  12855. plci->adjust_b_parms_msg = NULL;
  12856. plci->adjust_b_facilities = plci->B1_facilities;
  12857. plci->adjust_b_command = ADJUST_B_RESTORE_2;
  12858. plci->adjust_b_ncci = (word)(Id >> 16);
  12859. plci->adjust_b_mode = ADJUST_B_MODE_RESTORE;
  12860. plci->adjust_b_state = ADJUST_B_START;
  12861. dbug (1, dprintf ("[%06lx] %s,%d: Adjust B restore...",
  12862. UnMapId (Id), (char *)(FILE_), __LINE__));
  12863. case ADJUST_B_RESTORE_2:
  12864. if (adjust_b_process (Id, plci, Rc) != GOOD)
  12865. {
  12866. dbug (1, dprintf ("[%06lx] %s,%d: Adjust B restore failed",
  12867. UnMapId (Id), (char *)(FILE_), __LINE__));
  12868. }
  12869. if (plci->internal_command)
  12870. break;
  12871. break;
  12872. }
  12873. }
  12874. static void reset_b3_command (dword Id, PLCI *plci, byte Rc)
  12875. {
  12876. word Info;
  12877. word internal_command;
  12878. dbug (1, dprintf ("[%06lx] %s,%d: reset_b3_command %02x %04x",
  12879. UnMapId (Id), (char *)(FILE_), __LINE__, Rc, plci->internal_command));
  12880. Info = GOOD;
  12881. internal_command = plci->internal_command;
  12882. plci->internal_command = 0;
  12883. switch (internal_command)
  12884. {
  12885. default:
  12886. plci->command = 0;
  12887. plci->adjust_b_parms_msg = NULL;
  12888. plci->adjust_b_facilities = plci->B1_facilities;
  12889. plci->adjust_b_command = RESET_B3_COMMAND_1;
  12890. plci->adjust_b_ncci = (word)(Id >> 16);
  12891. plci->adjust_b_mode = ADJUST_B_MODE_REMOVE_L23 | ADJUST_B_MODE_ASSIGN_L23 | ADJUST_B_MODE_CONNECT;
  12892. plci->adjust_b_state = ADJUST_B_START;
  12893. dbug (1, dprintf ("[%06lx] %s,%d: Reset B3...",
  12894. UnMapId (Id), (char *)(FILE_), __LINE__));
  12895. case RESET_B3_COMMAND_1:
  12896. Info = adjust_b_process (Id, plci, Rc);
  12897. if (Info != GOOD)
  12898. {
  12899. dbug (1, dprintf ("[%06lx] %s,%d: Reset failed",
  12900. UnMapId (Id), (char *)(FILE_), __LINE__));
  12901. break;
  12902. }
  12903. if (plci->internal_command)
  12904. return;
  12905. break;
  12906. }
  12907. /* sendf (plci->appl, _RESET_B3_R | CONFIRM, Id, plci->number, "w", Info);*/
  12908. sendf(plci->appl,_RESET_B3_I,Id,0,"s","");
  12909. }
  12910. static void select_b_command (dword Id, PLCI *plci, byte Rc)
  12911. {
  12912. word Info;
  12913. word internal_command;
  12914. byte esc_chi[3];
  12915. dbug (1, dprintf ("[%06lx] %s,%d: select_b_command %02x %04x",
  12916. UnMapId (Id), (char *)(FILE_), __LINE__, Rc, plci->internal_command));
  12917. Info = GOOD;
  12918. internal_command = plci->internal_command;
  12919. plci->internal_command = 0;
  12920. switch (internal_command)
  12921. {
  12922. default:
  12923. plci->command = 0;
  12924. plci->adjust_b_parms_msg = &plci->saved_msg;
  12925. if ((plci->tel == ADV_VOICE) && (plci == plci->adapter->AdvSignalPLCI))
  12926. plci->adjust_b_facilities = plci->B1_facilities | B1_FACILITY_VOICE;
  12927. else
  12928. plci->adjust_b_facilities = plci->B1_facilities & ~B1_FACILITY_VOICE;
  12929. plci->adjust_b_command = SELECT_B_COMMAND_1;
  12930. plci->adjust_b_ncci = (word)(Id >> 16);
  12931. if (plci->saved_msg.parms[0].length == 0)
  12932. {
  12933. plci->adjust_b_mode = ADJUST_B_MODE_SAVE | ADJUST_B_MODE_REMOVE_L23 | ADJUST_B_MODE_SWITCH_L1 |
  12934. ADJUST_B_MODE_NO_RESOURCE;
  12935. }
  12936. else
  12937. {
  12938. plci->adjust_b_mode = ADJUST_B_MODE_SAVE | ADJUST_B_MODE_REMOVE_L23 | ADJUST_B_MODE_SWITCH_L1 |
  12939. ADJUST_B_MODE_ASSIGN_L23 | ADJUST_B_MODE_USER_CONNECT | ADJUST_B_MODE_RESTORE;
  12940. }
  12941. plci->adjust_b_state = ADJUST_B_START;
  12942. dbug (1, dprintf ("[%06lx] %s,%d: Select B protocol...",
  12943. UnMapId (Id), (char *)(FILE_), __LINE__));
  12944. case SELECT_B_COMMAND_1:
  12945. Info = adjust_b_process (Id, plci, Rc);
  12946. if (Info != GOOD)
  12947. {
  12948. dbug (1, dprintf ("[%06lx] %s,%d: Select B protocol failed",
  12949. UnMapId (Id), (char *)(FILE_), __LINE__));
  12950. break;
  12951. }
  12952. if (plci->internal_command)
  12953. return;
  12954. if (plci->tel == ADV_VOICE)
  12955. {
  12956. esc_chi[0] = 0x02;
  12957. esc_chi[1] = 0x18;
  12958. esc_chi[2] = plci->b_channel;
  12959. SetVoiceChannel (plci->adapter->AdvCodecPLCI, esc_chi, plci->adapter);
  12960. }
  12961. break;
  12962. }
  12963. sendf (plci->appl, _SELECT_B_REQ | CONFIRM, Id, plci->number, "w", Info);
  12964. }
  12965. static void fax_connect_ack_command (dword Id, PLCI *plci, byte Rc)
  12966. {
  12967. word Info;
  12968. word internal_command;
  12969. dbug (1, dprintf ("[%06lx] %s,%d: fax_connect_ack_command %02x %04x",
  12970. UnMapId (Id), (char *)(FILE_), __LINE__, Rc, plci->internal_command));
  12971. Info = GOOD;
  12972. internal_command = plci->internal_command;
  12973. plci->internal_command = 0;
  12974. switch (internal_command)
  12975. {
  12976. default:
  12977. plci->command = 0;
  12978. case FAX_CONNECT_ACK_COMMAND_1:
  12979. if (plci_nl_busy (plci))
  12980. {
  12981. plci->internal_command = FAX_CONNECT_ACK_COMMAND_1;
  12982. return;
  12983. }
  12984. plci->internal_command = FAX_CONNECT_ACK_COMMAND_2;
  12985. plci->NData[0].P = plci->fax_connect_info_buffer;
  12986. plci->NData[0].PLength = plci->fax_connect_info_length;
  12987. plci->NL.X = plci->NData;
  12988. plci->NL.ReqCh = 0;
  12989. plci->NL.Req = plci->nl_req = (byte) N_CONNECT_ACK;
  12990. plci->adapter->request (&plci->NL);
  12991. return;
  12992. case FAX_CONNECT_ACK_COMMAND_2:
  12993. if ((Rc != OK) && (Rc != OK_FC))
  12994. {
  12995. dbug (1, dprintf ("[%06lx] %s,%d: FAX issue CONNECT ACK failed %02x",
  12996. UnMapId (Id), (char *)(FILE_), __LINE__, Rc));
  12997. break;
  12998. }
  12999. }
  13000. if ((plci->ncpi_state & NCPI_VALID_CONNECT_B3_ACT)
  13001. && !(plci->ncpi_state & NCPI_CONNECT_B3_ACT_SENT))
  13002. {
  13003. if (plci->B3_prot == 4)
  13004. sendf(plci->appl,_CONNECT_B3_ACTIVE_I,Id,0,"s","");
  13005. else
  13006. sendf(plci->appl,_CONNECT_B3_ACTIVE_I,Id,0,"S",plci->ncpi_buffer);
  13007. plci->ncpi_state |= NCPI_CONNECT_B3_ACT_SENT;
  13008. }
  13009. }
  13010. static void fax_edata_ack_command (dword Id, PLCI *plci, byte Rc)
  13011. {
  13012. word Info;
  13013. word internal_command;
  13014. dbug (1, dprintf ("[%06lx] %s,%d: fax_edata_ack_command %02x %04x",
  13015. UnMapId (Id), (char *)(FILE_), __LINE__, Rc, plci->internal_command));
  13016. Info = GOOD;
  13017. internal_command = plci->internal_command;
  13018. plci->internal_command = 0;
  13019. switch (internal_command)
  13020. {
  13021. default:
  13022. plci->command = 0;
  13023. case FAX_EDATA_ACK_COMMAND_1:
  13024. if (plci_nl_busy (plci))
  13025. {
  13026. plci->internal_command = FAX_EDATA_ACK_COMMAND_1;
  13027. return;
  13028. }
  13029. plci->internal_command = FAX_EDATA_ACK_COMMAND_2;
  13030. plci->NData[0].P = plci->fax_connect_info_buffer;
  13031. plci->NData[0].PLength = plci->fax_edata_ack_length;
  13032. plci->NL.X = plci->NData;
  13033. plci->NL.ReqCh = 0;
  13034. plci->NL.Req = plci->nl_req = (byte) N_EDATA;
  13035. plci->adapter->request (&plci->NL);
  13036. return;
  13037. case FAX_EDATA_ACK_COMMAND_2:
  13038. if ((Rc != OK) && (Rc != OK_FC))
  13039. {
  13040. dbug (1, dprintf ("[%06lx] %s,%d: FAX issue EDATA ACK failed %02x",
  13041. UnMapId (Id), (char *)(FILE_), __LINE__, Rc));
  13042. break;
  13043. }
  13044. }
  13045. }
  13046. static void fax_connect_info_command (dword Id, PLCI *plci, byte Rc)
  13047. {
  13048. word Info;
  13049. word internal_command;
  13050. dbug (1, dprintf ("[%06lx] %s,%d: fax_connect_info_command %02x %04x",
  13051. UnMapId (Id), (char *)(FILE_), __LINE__, Rc, plci->internal_command));
  13052. Info = GOOD;
  13053. internal_command = plci->internal_command;
  13054. plci->internal_command = 0;
  13055. switch (internal_command)
  13056. {
  13057. default:
  13058. plci->command = 0;
  13059. case FAX_CONNECT_INFO_COMMAND_1:
  13060. if (plci_nl_busy (plci))
  13061. {
  13062. plci->internal_command = FAX_CONNECT_INFO_COMMAND_1;
  13063. return;
  13064. }
  13065. plci->internal_command = FAX_CONNECT_INFO_COMMAND_2;
  13066. plci->NData[0].P = plci->fax_connect_info_buffer;
  13067. plci->NData[0].PLength = plci->fax_connect_info_length;
  13068. plci->NL.X = plci->NData;
  13069. plci->NL.ReqCh = 0;
  13070. plci->NL.Req = plci->nl_req = (byte) N_EDATA;
  13071. plci->adapter->request (&plci->NL);
  13072. return;
  13073. case FAX_CONNECT_INFO_COMMAND_2:
  13074. if ((Rc != OK) && (Rc != OK_FC))
  13075. {
  13076. dbug (1, dprintf ("[%06lx] %s,%d: FAX setting connect info failed %02x",
  13077. UnMapId (Id), (char *)(FILE_), __LINE__, Rc));
  13078. Info = _WRONG_STATE;
  13079. break;
  13080. }
  13081. if (plci_nl_busy (plci))
  13082. {
  13083. plci->internal_command = FAX_CONNECT_INFO_COMMAND_2;
  13084. return;
  13085. }
  13086. plci->command = _CONNECT_B3_R;
  13087. nl_req_ncci (plci, N_CONNECT, 0);
  13088. send_req (plci);
  13089. return;
  13090. }
  13091. sendf (plci->appl, _CONNECT_B3_R | CONFIRM, Id, plci->number, "w", Info);
  13092. }
  13093. static void fax_adjust_b23_command (dword Id, PLCI *plci, byte Rc)
  13094. {
  13095. word Info;
  13096. word internal_command;
  13097. dbug (1, dprintf ("[%06lx] %s,%d: fax_adjust_b23_command %02x %04x",
  13098. UnMapId (Id), (char *)(FILE_), __LINE__, Rc, plci->internal_command));
  13099. Info = GOOD;
  13100. internal_command = plci->internal_command;
  13101. plci->internal_command = 0;
  13102. switch (internal_command)
  13103. {
  13104. default:
  13105. plci->command = 0;
  13106. plci->adjust_b_parms_msg = NULL;
  13107. plci->adjust_b_facilities = plci->B1_facilities;
  13108. plci->adjust_b_command = FAX_ADJUST_B23_COMMAND_1;
  13109. plci->adjust_b_ncci = (word)(Id >> 16);
  13110. plci->adjust_b_mode = ADJUST_B_MODE_REMOVE_L23 | ADJUST_B_MODE_ASSIGN_L23;
  13111. plci->adjust_b_state = ADJUST_B_START;
  13112. dbug (1, dprintf ("[%06lx] %s,%d: FAX adjust B23...",
  13113. UnMapId (Id), (char *)(FILE_), __LINE__));
  13114. case FAX_ADJUST_B23_COMMAND_1:
  13115. Info = adjust_b_process (Id, plci, Rc);
  13116. if (Info != GOOD)
  13117. {
  13118. dbug (1, dprintf ("[%06lx] %s,%d: FAX adjust failed",
  13119. UnMapId (Id), (char *)(FILE_), __LINE__));
  13120. break;
  13121. }
  13122. if (plci->internal_command)
  13123. return;
  13124. case FAX_ADJUST_B23_COMMAND_2:
  13125. if (plci_nl_busy (plci))
  13126. {
  13127. plci->internal_command = FAX_ADJUST_B23_COMMAND_2;
  13128. return;
  13129. }
  13130. plci->command = _CONNECT_B3_R;
  13131. nl_req_ncci (plci, N_CONNECT, 0);
  13132. send_req (plci);
  13133. return;
  13134. }
  13135. sendf (plci->appl, _CONNECT_B3_R | CONFIRM, Id, plci->number, "w", Info);
  13136. }
  13137. static void fax_disconnect_command (dword Id, PLCI *plci, byte Rc)
  13138. {
  13139. word internal_command;
  13140. dbug (1, dprintf ("[%06lx] %s,%d: fax_disconnect_command %02x %04x",
  13141. UnMapId (Id), (char *)(FILE_), __LINE__, Rc, plci->internal_command));
  13142. internal_command = plci->internal_command;
  13143. plci->internal_command = 0;
  13144. switch (internal_command)
  13145. {
  13146. default:
  13147. plci->command = 0;
  13148. plci->internal_command = FAX_DISCONNECT_COMMAND_1;
  13149. return;
  13150. case FAX_DISCONNECT_COMMAND_1:
  13151. case FAX_DISCONNECT_COMMAND_2:
  13152. case FAX_DISCONNECT_COMMAND_3:
  13153. if ((Rc != OK) && (Rc != OK_FC) && (Rc != 0))
  13154. {
  13155. dbug (1, dprintf ("[%06lx] %s,%d: FAX disconnect EDATA failed %02x",
  13156. UnMapId (Id), (char *)(FILE_), __LINE__, Rc));
  13157. break;
  13158. }
  13159. if (Rc == OK)
  13160. {
  13161. if ((internal_command == FAX_DISCONNECT_COMMAND_1)
  13162. || (internal_command == FAX_DISCONNECT_COMMAND_2))
  13163. {
  13164. plci->internal_command = FAX_DISCONNECT_COMMAND_2;
  13165. }
  13166. }
  13167. else if (Rc == 0)
  13168. {
  13169. if (internal_command == FAX_DISCONNECT_COMMAND_1)
  13170. plci->internal_command = FAX_DISCONNECT_COMMAND_3;
  13171. }
  13172. return;
  13173. }
  13174. }
  13175. static void rtp_connect_b3_req_command (dword Id, PLCI *plci, byte Rc)
  13176. {
  13177. word Info;
  13178. word internal_command;
  13179. dbug (1, dprintf ("[%06lx] %s,%d: rtp_connect_b3_req_command %02x %04x",
  13180. UnMapId (Id), (char *)(FILE_), __LINE__, Rc, plci->internal_command));
  13181. Info = GOOD;
  13182. internal_command = plci->internal_command;
  13183. plci->internal_command = 0;
  13184. switch (internal_command)
  13185. {
  13186. default:
  13187. plci->command = 0;
  13188. case RTP_CONNECT_B3_REQ_COMMAND_1:
  13189. if (plci_nl_busy (plci))
  13190. {
  13191. plci->internal_command = RTP_CONNECT_B3_REQ_COMMAND_1;
  13192. return;
  13193. }
  13194. plci->internal_command = RTP_CONNECT_B3_REQ_COMMAND_2;
  13195. nl_req_ncci (plci, N_CONNECT, 0);
  13196. send_req (plci);
  13197. return;
  13198. case RTP_CONNECT_B3_REQ_COMMAND_2:
  13199. if ((Rc != OK) && (Rc != OK_FC))
  13200. {
  13201. dbug (1, dprintf ("[%06lx] %s,%d: RTP setting connect info failed %02x",
  13202. UnMapId (Id), (char *)(FILE_), __LINE__, Rc));
  13203. Info = _WRONG_STATE;
  13204. break;
  13205. }
  13206. if (plci_nl_busy (plci))
  13207. {
  13208. plci->internal_command = RTP_CONNECT_B3_REQ_COMMAND_2;
  13209. return;
  13210. }
  13211. plci->internal_command = RTP_CONNECT_B3_REQ_COMMAND_3;
  13212. plci->NData[0].PLength = plci->internal_req_buffer[0];
  13213. plci->NData[0].P = plci->internal_req_buffer + 1;
  13214. plci->NL.X = plci->NData;
  13215. plci->NL.ReqCh = 0;
  13216. plci->NL.Req = plci->nl_req = (byte) N_UDATA;
  13217. plci->adapter->request (&plci->NL);
  13218. break;
  13219. case RTP_CONNECT_B3_REQ_COMMAND_3:
  13220. return;
  13221. }
  13222. sendf (plci->appl, _CONNECT_B3_R | CONFIRM, Id, plci->number, "w", Info);
  13223. }
  13224. static void rtp_connect_b3_res_command (dword Id, PLCI *plci, byte Rc)
  13225. {
  13226. word Info;
  13227. word internal_command;
  13228. dbug (1, dprintf ("[%06lx] %s,%d: rtp_connect_b3_res_command %02x %04x",
  13229. UnMapId (Id), (char *)(FILE_), __LINE__, Rc, plci->internal_command));
  13230. Info = GOOD;
  13231. internal_command = plci->internal_command;
  13232. plci->internal_command = 0;
  13233. switch (internal_command)
  13234. {
  13235. default:
  13236. plci->command = 0;
  13237. case RTP_CONNECT_B3_RES_COMMAND_1:
  13238. if (plci_nl_busy (plci))
  13239. {
  13240. plci->internal_command = RTP_CONNECT_B3_RES_COMMAND_1;
  13241. return;
  13242. }
  13243. plci->internal_command = RTP_CONNECT_B3_RES_COMMAND_2;
  13244. nl_req_ncci (plci, N_CONNECT_ACK, (byte)(Id >> 16));
  13245. send_req (plci);
  13246. return;
  13247. case RTP_CONNECT_B3_RES_COMMAND_2:
  13248. if ((Rc != OK) && (Rc != OK_FC))
  13249. {
  13250. dbug (1, dprintf ("[%06lx] %s,%d: RTP setting connect resp info failed %02x",
  13251. UnMapId (Id), (char *)(FILE_), __LINE__, Rc));
  13252. Info = _WRONG_STATE;
  13253. break;
  13254. }
  13255. if (plci_nl_busy (plci))
  13256. {
  13257. plci->internal_command = RTP_CONNECT_B3_RES_COMMAND_2;
  13258. return;
  13259. }
  13260. sendf (plci->appl, _CONNECT_B3_ACTIVE_I, Id, 0, "s", "");
  13261. plci->internal_command = RTP_CONNECT_B3_RES_COMMAND_3;
  13262. plci->NData[0].PLength = plci->internal_req_buffer[0];
  13263. plci->NData[0].P = plci->internal_req_buffer + 1;
  13264. plci->NL.X = plci->NData;
  13265. plci->NL.ReqCh = 0;
  13266. plci->NL.Req = plci->nl_req = (byte) N_UDATA;
  13267. plci->adapter->request (&plci->NL);
  13268. return;
  13269. case RTP_CONNECT_B3_RES_COMMAND_3:
  13270. return;
  13271. }
  13272. }
  13273. static void hold_save_command (dword Id, PLCI *plci, byte Rc)
  13274. {
  13275. byte SS_Ind[] = "\x05\x02\x00\x02\x00\x00"; /* Hold_Ind struct*/
  13276. word Info;
  13277. word internal_command;
  13278. dbug (1, dprintf ("[%06lx] %s,%d: hold_save_command %02x %04x",
  13279. UnMapId (Id), (char *)(FILE_), __LINE__, Rc, plci->internal_command));
  13280. Info = GOOD;
  13281. internal_command = plci->internal_command;
  13282. plci->internal_command = 0;
  13283. switch (internal_command)
  13284. {
  13285. default:
  13286. if (!plci->NL.Id)
  13287. break;
  13288. plci->command = 0;
  13289. plci->adjust_b_parms_msg = NULL;
  13290. plci->adjust_b_facilities = plci->B1_facilities;
  13291. plci->adjust_b_command = HOLD_SAVE_COMMAND_1;
  13292. plci->adjust_b_ncci = (word)(Id >> 16);
  13293. plci->adjust_b_mode = ADJUST_B_MODE_SAVE | ADJUST_B_MODE_REMOVE_L23;
  13294. plci->adjust_b_state = ADJUST_B_START;
  13295. dbug (1, dprintf ("[%06lx] %s,%d: HOLD save...",
  13296. UnMapId (Id), (char *)(FILE_), __LINE__));
  13297. case HOLD_SAVE_COMMAND_1:
  13298. Info = adjust_b_process (Id, plci, Rc);
  13299. if (Info != GOOD)
  13300. {
  13301. dbug (1, dprintf ("[%06lx] %s,%d: HOLD save failed",
  13302. UnMapId (Id), (char *)(FILE_), __LINE__));
  13303. break;
  13304. }
  13305. if (plci->internal_command)
  13306. return;
  13307. }
  13308. sendf (plci->appl, _FACILITY_I, Id & 0xffffL, 0, "ws", 3, SS_Ind);
  13309. }
  13310. static void retrieve_restore_command (dword Id, PLCI *plci, byte Rc)
  13311. {
  13312. byte SS_Ind[] = "\x05\x03\x00\x02\x00\x00"; /* Retrieve_Ind struct*/
  13313. word Info;
  13314. word internal_command;
  13315. dbug (1, dprintf ("[%06lx] %s,%d: retrieve_restore_command %02x %04x",
  13316. UnMapId (Id), (char *)(FILE_), __LINE__, Rc, plci->internal_command));
  13317. Info = GOOD;
  13318. internal_command = plci->internal_command;
  13319. plci->internal_command = 0;
  13320. switch (internal_command)
  13321. {
  13322. default:
  13323. plci->command = 0;
  13324. plci->adjust_b_parms_msg = NULL;
  13325. plci->adjust_b_facilities = plci->B1_facilities;
  13326. plci->adjust_b_command = RETRIEVE_RESTORE_COMMAND_1;
  13327. plci->adjust_b_ncci = (word)(Id >> 16);
  13328. plci->adjust_b_mode = ADJUST_B_MODE_ASSIGN_L23 | ADJUST_B_MODE_USER_CONNECT | ADJUST_B_MODE_RESTORE;
  13329. plci->adjust_b_state = ADJUST_B_START;
  13330. dbug (1, dprintf ("[%06lx] %s,%d: RETRIEVE restore...",
  13331. UnMapId (Id), (char *)(FILE_), __LINE__));
  13332. case RETRIEVE_RESTORE_COMMAND_1:
  13333. Info = adjust_b_process (Id, plci, Rc);
  13334. if (Info != GOOD)
  13335. {
  13336. dbug (1, dprintf ("[%06lx] %s,%d: RETRIEVE restore failed",
  13337. UnMapId (Id), (char *)(FILE_), __LINE__));
  13338. break;
  13339. }
  13340. if (plci->internal_command)
  13341. return;
  13342. }
  13343. sendf (plci->appl, _FACILITY_I, Id & 0xffffL, 0, "ws", 3, SS_Ind);
  13344. }
  13345. static void init_b1_config (PLCI *plci)
  13346. {
  13347. dbug (1, dprintf ("[%06lx] %s,%d: init_b1_config",
  13348. (dword)((plci->Id << 8) | UnMapController (plci->adapter->Id)),
  13349. (char *)(FILE_), __LINE__));
  13350. plci->B1_resource = 0;
  13351. plci->B1_facilities = 0;
  13352. plci->li_bchannel_id = 0;
  13353. mixer_clear_config (plci);
  13354. ec_clear_config (plci);
  13355. dtmf_rec_clear_config (plci);
  13356. dtmf_send_clear_config (plci);
  13357. dtmf_parameter_clear_config (plci);
  13358. adv_voice_clear_config (plci);
  13359. adjust_b_clear (plci);
  13360. }
  13361. static void clear_b1_config (PLCI *plci)
  13362. {
  13363. dbug (1, dprintf ("[%06lx] %s,%d: clear_b1_config",
  13364. (dword)((plci->Id << 8) | UnMapController (plci->adapter->Id)),
  13365. (char *)(FILE_), __LINE__));
  13366. adv_voice_clear_config (plci);
  13367. adjust_b_clear (plci);
  13368. ec_clear_config (plci);
  13369. dtmf_rec_clear_config (plci);
  13370. dtmf_send_clear_config (plci);
  13371. dtmf_parameter_clear_config (plci);
  13372. if ((plci->li_bchannel_id != 0)
  13373. && (li_config_table[plci->adapter->li_base + (plci->li_bchannel_id - 1)].plci == plci))
  13374. {
  13375. mixer_clear_config (plci);
  13376. li_config_table[plci->adapter->li_base + (plci->li_bchannel_id - 1)].plci = NULL;
  13377. plci->li_bchannel_id = 0;
  13378. }
  13379. plci->B1_resource = 0;
  13380. plci->B1_facilities = 0;
  13381. }
  13382. /* -----------------------------------------------------------------
  13383. XON protocol local helpers
  13384. ----------------------------------------------------------------- */
  13385. static void channel_flow_control_remove (PLCI * plci) {
  13386. DIVA_CAPI_ADAPTER * a = plci->adapter;
  13387. word i;
  13388. for(i=1;i<MAX_NL_CHANNEL+1;i++) {
  13389. if (a->ch_flow_plci[i] == plci->Id) {
  13390. a->ch_flow_plci[i] = 0;
  13391. a->ch_flow_control[i] = 0;
  13392. }
  13393. }
  13394. }
  13395. static void channel_x_on (PLCI * plci, byte ch) {
  13396. DIVA_CAPI_ADAPTER * a = plci->adapter;
  13397. if (a->ch_flow_control[ch] & N_XON_SENT) {
  13398. a->ch_flow_control[ch] &= ~N_XON_SENT;
  13399. }
  13400. }
  13401. static void channel_x_off (PLCI * plci, byte ch, byte flag) {
  13402. DIVA_CAPI_ADAPTER * a = plci->adapter;
  13403. if ((a->ch_flow_control[ch] & N_RX_FLOW_CONTROL_MASK) == 0) {
  13404. a->ch_flow_control[ch] |= (N_CH_XOFF | flag);
  13405. a->ch_flow_plci[ch] = plci->Id;
  13406. a->ch_flow_control_pending++;
  13407. }
  13408. }
  13409. static void channel_request_xon (PLCI * plci, byte ch) {
  13410. DIVA_CAPI_ADAPTER * a = plci->adapter;
  13411. if (a->ch_flow_control[ch] & N_CH_XOFF) {
  13412. a->ch_flow_control[ch] |= N_XON_REQ;
  13413. a->ch_flow_control[ch] &= ~N_CH_XOFF;
  13414. a->ch_flow_control[ch] &= ~N_XON_CONNECT_IND;
  13415. }
  13416. }
  13417. static void channel_xmit_extended_xon (PLCI * plci) {
  13418. DIVA_CAPI_ADAPTER * a;
  13419. int max_ch = ARRAY_SIZE(a->ch_flow_control);
  13420. int i, one_requested = 0;
  13421. if ((!plci) || (!plci->Id) || ((a = plci->adapter) == NULL)) {
  13422. return;
  13423. }
  13424. for (i = 0; i < max_ch; i++) {
  13425. if ((a->ch_flow_control[i] & N_CH_XOFF) &&
  13426. (a->ch_flow_control[i] & N_XON_CONNECT_IND) &&
  13427. (plci->Id == a->ch_flow_plci[i])) {
  13428. channel_request_xon (plci, (byte)i);
  13429. one_requested = 1;
  13430. }
  13431. }
  13432. if (one_requested) {
  13433. channel_xmit_xon (plci);
  13434. }
  13435. }
  13436. /*
  13437. Try to xmit next X_ON
  13438. */
  13439. static int find_channel_with_pending_x_on (DIVA_CAPI_ADAPTER * a, PLCI * plci) {
  13440. int max_ch = ARRAY_SIZE(a->ch_flow_control);
  13441. int i;
  13442. if (!(plci->adapter->manufacturer_features & MANUFACTURER_FEATURE_XONOFF_FLOW_CONTROL)) {
  13443. return (0);
  13444. }
  13445. if (a->last_flow_control_ch >= max_ch) {
  13446. a->last_flow_control_ch = 1;
  13447. }
  13448. for (i=a->last_flow_control_ch; i < max_ch; i++) {
  13449. if ((a->ch_flow_control[i] & N_XON_REQ) &&
  13450. (plci->Id == a->ch_flow_plci[i])) {
  13451. a->last_flow_control_ch = i+1;
  13452. return (i);
  13453. }
  13454. }
  13455. for (i = 1; i < a->last_flow_control_ch; i++) {
  13456. if ((a->ch_flow_control[i] & N_XON_REQ) &&
  13457. (plci->Id == a->ch_flow_plci[i])) {
  13458. a->last_flow_control_ch = i+1;
  13459. return (i);
  13460. }
  13461. }
  13462. return (0);
  13463. }
  13464. static void channel_xmit_xon (PLCI * plci) {
  13465. DIVA_CAPI_ADAPTER * a = plci->adapter;
  13466. byte ch;
  13467. if (plci->nl_req || !plci->NL.Id || plci->nl_remove_id) {
  13468. return;
  13469. }
  13470. if ((ch = (byte)find_channel_with_pending_x_on (a, plci)) == 0) {
  13471. return;
  13472. }
  13473. a->ch_flow_control[ch] &= ~N_XON_REQ;
  13474. a->ch_flow_control[ch] |= N_XON_SENT;
  13475. plci->NL.Req = plci->nl_req = (byte)N_XON;
  13476. plci->NL.ReqCh = ch;
  13477. plci->NL.X = plci->NData;
  13478. plci->NL.XNum = 1;
  13479. plci->NData[0].P = &plci->RBuffer[0];
  13480. plci->NData[0].PLength = 0;
  13481. plci->adapter->request(&plci->NL);
  13482. }
  13483. static int channel_can_xon (PLCI * plci, byte ch) {
  13484. APPL * APPLptr;
  13485. DIVA_CAPI_ADAPTER * a;
  13486. word NCCIcode;
  13487. dword count;
  13488. word Num;
  13489. word i;
  13490. APPLptr = plci->appl;
  13491. a = plci->adapter;
  13492. if (!APPLptr)
  13493. return (0);
  13494. NCCIcode = a->ch_ncci[ch] | (((word) a->Id) << 8);
  13495. /* count all buffers within the Application pool */
  13496. /* belonging to the same NCCI. XON if a first is */
  13497. /* used. */
  13498. count = 0;
  13499. Num = 0xffff;
  13500. for(i=0; i<APPLptr->MaxBuffer; i++) {
  13501. if(NCCIcode==APPLptr->DataNCCI[i]) count++;
  13502. if(!APPLptr->DataNCCI[i] && Num==0xffff) Num = i;
  13503. }
  13504. if ((count > 2) || (Num == 0xffff)) {
  13505. return (0);
  13506. }
  13507. return (1);
  13508. }
  13509. /*------------------------------------------------------------------*/
  13510. static word CPN_filter_ok(byte *cpn,DIVA_CAPI_ADAPTER * a,word offset)
  13511. {
  13512. return 1;
  13513. }
  13514. /**********************************************************************************/
  13515. /* function groups the listening applications according to the CIP mask and the */
  13516. /* Info_Mask. Each group gets just one Connect_Ind. Some application manufacturer */
  13517. /* are not multi-instance capable, so they start e.g. 30 applications what causes */
  13518. /* big problems on application level (one call, 30 Connect_Ind, ect). The */
  13519. /* function must be enabled by setting "a->group_optimization_enabled" from the */
  13520. /* OS specific part (per adapter). */
  13521. /**********************************************************************************/
  13522. static void group_optimization(DIVA_CAPI_ADAPTER * a, PLCI * plci)
  13523. {
  13524. word i,j,k,busy,group_found;
  13525. dword info_mask_group[MAX_CIP_TYPES];
  13526. dword cip_mask_group[MAX_CIP_TYPES];
  13527. word appl_number_group_type[MAX_APPL];
  13528. PLCI *auxplci;
  13529. set_group_ind_mask (plci); /* all APPLs within this inc. call are allowed to dial in */
  13530. if(!a->group_optimization_enabled)
  13531. {
  13532. dbug(1,dprintf("No group optimization"));
  13533. return;
  13534. }
  13535. dbug(1,dprintf("Group optimization = 0x%x...", a->group_optimization_enabled));
  13536. for(i=0;i<MAX_CIP_TYPES;i++)
  13537. {
  13538. info_mask_group[i] = 0;
  13539. cip_mask_group [i] = 0;
  13540. }
  13541. for(i=0;i<MAX_APPL;i++)
  13542. {
  13543. appl_number_group_type[i] = 0;
  13544. }
  13545. for(i=0; i<max_appl; i++) /* check if any multi instance capable application is present */
  13546. { /* group_optimization set to 1 means not to optimize multi-instance capable applications (default) */
  13547. if(application[i].Id && (application[i].MaxNCCI) > 1 && (a->CIP_Mask[i]) && (a->group_optimization_enabled ==1) )
  13548. {
  13549. dbug(1,dprintf("Multi-Instance capable, no optimization required"));
  13550. return; /* allow good application unfiltered access */
  13551. }
  13552. }
  13553. for(i=0; i<max_appl; i++) /* Build CIP Groups */
  13554. {
  13555. if(application[i].Id && a->CIP_Mask[i] )
  13556. {
  13557. for(k=0,busy=false; k<a->max_plci; k++)
  13558. {
  13559. if(a->plci[k].Id)
  13560. {
  13561. auxplci = &a->plci[k];
  13562. if(auxplci->appl == &application[i]) /* application has a busy PLCI */
  13563. {
  13564. busy = true;
  13565. dbug(1,dprintf("Appl 0x%x is busy",i+1));
  13566. }
  13567. else if(test_c_ind_mask_bit (auxplci, i)) /* application has an incoming call pending */
  13568. {
  13569. busy = true;
  13570. dbug(1,dprintf("Appl 0x%x has inc. call pending",i+1));
  13571. }
  13572. }
  13573. }
  13574. for(j=0,group_found=0; j<=(MAX_CIP_TYPES) && !busy &&!group_found; j++) /* build groups with free applications only */
  13575. {
  13576. if(j==MAX_CIP_TYPES) /* all groups are in use but group still not found */
  13577. { /* the MAX_CIP_TYPES group enables all calls because of field overflow */
  13578. appl_number_group_type[i] = MAX_CIP_TYPES;
  13579. group_found=true;
  13580. dbug(1,dprintf("Field overflow appl 0x%x",i+1));
  13581. }
  13582. else if( (info_mask_group[j]==a->CIP_Mask[i]) && (cip_mask_group[j]==a->Info_Mask[i]) )
  13583. { /* is group already present ? */
  13584. appl_number_group_type[i] = j|0x80; /* store the group number for each application */
  13585. group_found=true;
  13586. 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]));
  13587. }
  13588. else if(!info_mask_group[j])
  13589. { /* establish a new group */
  13590. appl_number_group_type[i] = j|0x80; /* store the group number for each application */
  13591. info_mask_group[j] = a->CIP_Mask[i]; /* store the new CIP mask for the new group */
  13592. cip_mask_group[j] = a->Info_Mask[i]; /* store the new Info_Mask for this new group */
  13593. group_found=true;
  13594. 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]));
  13595. }
  13596. }
  13597. }
  13598. }
  13599. for(i=0; i<max_appl; i++) /* Build group_optimization_mask_table */
  13600. {
  13601. if(appl_number_group_type[i]) /* application is free, has listens and is member of a group */
  13602. {
  13603. if(appl_number_group_type[i] == MAX_CIP_TYPES)
  13604. {
  13605. dbug(1,dprintf("OverflowGroup 0x%x, valid appl = 0x%x, call enabled",appl_number_group_type[i],i+1));
  13606. }
  13607. else
  13608. {
  13609. dbug(1,dprintf("Group 0x%x, valid appl = 0x%x",appl_number_group_type[i],i+1));
  13610. for(j=i+1; j<max_appl; j++) /* search other group members and mark them as busy */
  13611. {
  13612. if(appl_number_group_type[i] == appl_number_group_type[j])
  13613. {
  13614. dbug(1,dprintf("Appl 0x%x is member of group 0x%x, no call",j+1,appl_number_group_type[j]));
  13615. clear_group_ind_mask_bit (plci, j); /* disable call on other group members */
  13616. appl_number_group_type[j] = 0; /* remove disabled group member from group list */
  13617. }
  13618. }
  13619. }
  13620. }
  13621. else /* application should not get a call */
  13622. {
  13623. clear_group_ind_mask_bit (plci, i);
  13624. }
  13625. }
  13626. }
  13627. /* OS notifies the driver about a application Capi_Register */
  13628. word CapiRegister(word id)
  13629. {
  13630. word i,j,appls_found;
  13631. PLCI *plci;
  13632. DIVA_CAPI_ADAPTER *a;
  13633. for(i=0,appls_found=0; i<max_appl; i++)
  13634. {
  13635. if( application[i].Id && (application[i].Id!=id) )
  13636. {
  13637. appls_found++; /* an application has been found */
  13638. }
  13639. }
  13640. if(appls_found) return true;
  13641. for(i=0; i<max_adapter; i++) /* scan all adapters... */
  13642. {
  13643. a = &adapter[i];
  13644. if(a->request)
  13645. {
  13646. if(a->flag_dynamic_l1_down) /* remove adapter from L1 tristate (Huntgroup) */
  13647. {
  13648. if(!appls_found) /* first application does a capi register */
  13649. {
  13650. if((j=get_plci(a))) /* activate L1 of all adapters */
  13651. {
  13652. plci = &a->plci[j-1];
  13653. plci->command = 0;
  13654. add_p(plci,OAD,"\x01\xfd");
  13655. add_p(plci,CAI,"\x01\x80");
  13656. add_p(plci,UID,"\x06\x43\x61\x70\x69\x32\x30");
  13657. add_p(plci,SHIFT|6,NULL);
  13658. add_p(plci,SIN,"\x02\x00\x00");
  13659. plci->internal_command = START_L1_SIG_ASSIGN_PEND;
  13660. sig_req(plci,ASSIGN,DSIG_ID);
  13661. add_p(plci,FTY,"\x02\xff\x07"); /* l1 start */
  13662. sig_req(plci,SIG_CTRL,0);
  13663. send_req(plci);
  13664. }
  13665. }
  13666. }
  13667. }
  13668. }
  13669. return false;
  13670. }
  13671. /*------------------------------------------------------------------*/
  13672. /* Functions for virtual Switching e.g. Transfer by join, Conference */
  13673. static void VSwitchReqInd(PLCI *plci, dword Id, byte **parms)
  13674. {
  13675. word i;
  13676. /* Format of vswitch_t:
  13677. 0 byte length
  13678. 1 byte VSWITCHIE
  13679. 2 byte VSWITCH_REQ/VSWITCH_IND
  13680. 3 byte reserved
  13681. 4 word VSwitchcommand
  13682. 6 word returnerror
  13683. 8... Params
  13684. */
  13685. if(!plci ||
  13686. !plci->appl ||
  13687. !plci->State ||
  13688. plci->Sig.Ind==NCR_FACILITY
  13689. )
  13690. return;
  13691. for(i=0;i<MAX_MULTI_IE;i++)
  13692. {
  13693. if(!parms[i][0]) continue;
  13694. if(parms[i][0]<7)
  13695. {
  13696. parms[i][0]=0; /* kill it */
  13697. continue;
  13698. }
  13699. dbug(1,dprintf("VSwitchReqInd(%d)",parms[i][4]));
  13700. switch(parms[i][4])
  13701. {
  13702. case VSJOIN:
  13703. if(!plci->relatedPTYPLCI ||
  13704. (plci->ptyState!=S_ECT && plci->relatedPTYPLCI->ptyState!=S_ECT))
  13705. { /* Error */
  13706. break;
  13707. }
  13708. /* remember all necessary informations */
  13709. if(parms[i][0]!=11 || parms[i][8]!=3) /* Length Test */
  13710. {
  13711. break;
  13712. }
  13713. if(parms[i][2]==VSWITCH_IND && parms[i][9]==1)
  13714. { /* first indication after ECT-Request on Consultation Call */
  13715. plci->vswitchstate=parms[i][9];
  13716. parms[i][9]=2; /* State */
  13717. /* now ask first Call to join */
  13718. }
  13719. else if(parms[i][2]==VSWITCH_REQ && parms[i][9]==3)
  13720. { /* Answer of VSWITCH_REQ from first Call */
  13721. plci->vswitchstate=parms[i][9];
  13722. /* tell consultation call to join
  13723. and the protocol capabilities of the first call */
  13724. }
  13725. else
  13726. { /* Error */
  13727. break;
  13728. }
  13729. plci->vsprot=parms[i][10]; /* protocol */
  13730. plci->vsprotdialect=parms[i][11]; /* protocoldialect */
  13731. /* send join request to related PLCI */
  13732. parms[i][1]=VSWITCHIE;
  13733. parms[i][2]=VSWITCH_REQ;
  13734. plci->relatedPTYPLCI->command = 0;
  13735. plci->relatedPTYPLCI->internal_command = VSWITCH_REQ_PEND;
  13736. add_p(plci->relatedPTYPLCI,ESC,&parms[i][0]);
  13737. sig_req(plci->relatedPTYPLCI,VSWITCH_REQ,0);
  13738. send_req(plci->relatedPTYPLCI);
  13739. break;
  13740. case VSTRANSPORT:
  13741. default:
  13742. if(plci->relatedPTYPLCI &&
  13743. plci->vswitchstate==3 &&
  13744. plci->relatedPTYPLCI->vswitchstate==3)
  13745. {
  13746. add_p(plci->relatedPTYPLCI,ESC,&parms[i][0]);
  13747. sig_req(plci->relatedPTYPLCI,VSWITCH_REQ,0);
  13748. send_req(plci->relatedPTYPLCI);
  13749. }
  13750. break;
  13751. }
  13752. parms[i][0]=0; /* kill it */
  13753. }
  13754. }
  13755. /*------------------------------------------------------------------*/
  13756. static int diva_get_dma_descriptor (PLCI *plci, dword *dma_magic) {
  13757. ENTITY e;
  13758. IDI_SYNC_REQ* pReq = (IDI_SYNC_REQ*)&e;
  13759. if (!(diva_xdi_extended_features & DIVA_CAPI_XDI_PROVIDES_RX_DMA)) {
  13760. return (-1);
  13761. }
  13762. pReq->xdi_dma_descriptor_operation.Req = 0;
  13763. pReq->xdi_dma_descriptor_operation.Rc = IDI_SYNC_REQ_DMA_DESCRIPTOR_OPERATION;
  13764. pReq->xdi_dma_descriptor_operation.info.operation = IDI_SYNC_REQ_DMA_DESCRIPTOR_ALLOC;
  13765. pReq->xdi_dma_descriptor_operation.info.descriptor_number = -1;
  13766. pReq->xdi_dma_descriptor_operation.info.descriptor_address = NULL;
  13767. pReq->xdi_dma_descriptor_operation.info.descriptor_magic = 0;
  13768. e.user[0] = plci->adapter->Id - 1;
  13769. plci->adapter->request((ENTITY*)pReq);
  13770. if (!pReq->xdi_dma_descriptor_operation.info.operation &&
  13771. (pReq->xdi_dma_descriptor_operation.info.descriptor_number >= 0) &&
  13772. pReq->xdi_dma_descriptor_operation.info.descriptor_magic) {
  13773. *dma_magic = pReq->xdi_dma_descriptor_operation.info.descriptor_magic;
  13774. dbug(3,dprintf("dma_alloc, a:%d (%d-%08x)",
  13775. plci->adapter->Id,
  13776. pReq->xdi_dma_descriptor_operation.info.descriptor_number,
  13777. *dma_magic));
  13778. return (pReq->xdi_dma_descriptor_operation.info.descriptor_number);
  13779. } else {
  13780. dbug(1,dprintf("dma_alloc failed"));
  13781. return (-1);
  13782. }
  13783. }
  13784. static void diva_free_dma_descriptor (PLCI *plci, int nr) {
  13785. ENTITY e;
  13786. IDI_SYNC_REQ* pReq = (IDI_SYNC_REQ*)&e;
  13787. if (nr < 0) {
  13788. return;
  13789. }
  13790. pReq->xdi_dma_descriptor_operation.Req = 0;
  13791. pReq->xdi_dma_descriptor_operation.Rc = IDI_SYNC_REQ_DMA_DESCRIPTOR_OPERATION;
  13792. pReq->xdi_dma_descriptor_operation.info.operation = IDI_SYNC_REQ_DMA_DESCRIPTOR_FREE;
  13793. pReq->xdi_dma_descriptor_operation.info.descriptor_number = nr;
  13794. pReq->xdi_dma_descriptor_operation.info.descriptor_address = NULL;
  13795. pReq->xdi_dma_descriptor_operation.info.descriptor_magic = 0;
  13796. e.user[0] = plci->adapter->Id - 1;
  13797. plci->adapter->request((ENTITY*)pReq);
  13798. if (!pReq->xdi_dma_descriptor_operation.info.operation) {
  13799. dbug(1,dprintf("dma_free(%d)", nr));
  13800. } else {
  13801. dbug(1,dprintf("dma_free failed (%d)", nr));
  13802. }
  13803. }
  13804. /*------------------------------------------------------------------*/