message.c 476 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774777577767777777877797780778177827783778477857786778777887789779077917792779377947795779677977798779978007801780278037804780578067807780878097810781178127813781478157816781778187819782078217822782378247825782678277828782978307831783278337834783578367837783878397840784178427843784478457846784778487849785078517852785378547855785678577858785978607861786278637864786578667867786878697870787178727873787478757876787778787879788078817882788378847885788678877888788978907891789278937894789578967897789878997900790179027903790479057906790779087909791079117912791379147915791679177918791979207921792279237924792579267927792879297930793179327933793479357936793779387939794079417942794379447945794679477948794979507951795279537954795579567957795879597960796179627963796479657966796779687969797079717972797379747975797679777978797979807981798279837984798579867987798879897990799179927993799479957996799779987999800080018002800380048005800680078008800980108011801280138014801580168017801880198020802180228023802480258026802780288029803080318032803380348035803680378038803980408041804280438044804580468047804880498050805180528053805480558056805780588059806080618062806380648065806680678068806980708071807280738074807580768077807880798080808180828083808480858086808780888089809080918092809380948095809680978098809981008101810281038104810581068107810881098110811181128113811481158116811781188119812081218122812381248125812681278128812981308131813281338134813581368137813881398140814181428143814481458146814781488149815081518152815381548155815681578158815981608161816281638164816581668167816881698170817181728173817481758176817781788179818081818182818381848185818681878188818981908191819281938194819581968197819881998200820182028203820482058206820782088209821082118212821382148215821682178218821982208221822282238224822582268227822882298230823182328233823482358236823782388239824082418242824382448245824682478248824982508251825282538254825582568257825882598260826182628263826482658266826782688269827082718272827382748275827682778278827982808281828282838284828582868287828882898290829182928293829482958296829782988299830083018302830383048305830683078308830983108311831283138314831583168317831883198320832183228323832483258326832783288329833083318332833383348335833683378338833983408341834283438344834583468347834883498350835183528353835483558356835783588359836083618362836383648365836683678368836983708371837283738374837583768377837883798380838183828383838483858386838783888389839083918392839383948395839683978398839984008401840284038404840584068407840884098410841184128413841484158416841784188419842084218422842384248425842684278428842984308431843284338434843584368437843884398440844184428443844484458446844784488449845084518452845384548455845684578458845984608461846284638464846584668467846884698470847184728473847484758476847784788479848084818482848384848485848684878488848984908491849284938494849584968497849884998500850185028503850485058506850785088509851085118512851385148515851685178518851985208521852285238524852585268527852885298530853185328533853485358536853785388539854085418542854385448545854685478548854985508551855285538554855585568557855885598560856185628563856485658566856785688569857085718572857385748575857685778578857985808581858285838584858585868587858885898590859185928593859485958596859785988599860086018602860386048605860686078608860986108611861286138614861586168617861886198620862186228623862486258626862786288629863086318632863386348635863686378638863986408641864286438644864586468647864886498650865186528653865486558656865786588659866086618662866386648665866686678668866986708671867286738674867586768677867886798680868186828683868486858686868786888689869086918692869386948695869686978698869987008701870287038704870587068707870887098710871187128713871487158716871787188719872087218722872387248725872687278728872987308731873287338734873587368737873887398740874187428743874487458746874787488749875087518752875387548755875687578758875987608761876287638764876587668767876887698770877187728773877487758776877787788779878087818782878387848785878687878788878987908791879287938794879587968797879887998800880188028803880488058806880788088809881088118812881388148815881688178818881988208821882288238824882588268827882888298830883188328833883488358836883788388839884088418842884388448845884688478848884988508851885288538854885588568857885888598860886188628863886488658866886788688869887088718872887388748875887688778878887988808881888288838884888588868887888888898890889188928893889488958896889788988899890089018902890389048905890689078908890989108911891289138914891589168917891889198920892189228923892489258926892789288929893089318932893389348935893689378938893989408941894289438944894589468947894889498950895189528953895489558956895789588959896089618962896389648965896689678968896989708971897289738974897589768977897889798980898189828983898489858986898789888989899089918992899389948995899689978998899990009001900290039004900590069007900890099010901190129013901490159016901790189019902090219022902390249025902690279028902990309031903290339034903590369037903890399040904190429043904490459046904790489049905090519052905390549055905690579058905990609061906290639064906590669067906890699070907190729073907490759076907790789079908090819082908390849085908690879088908990909091909290939094909590969097909890999100910191029103910491059106910791089109911091119112911391149115911691179118911991209121912291239124912591269127912891299130913191329133913491359136913791389139914091419142914391449145914691479148914991509151915291539154915591569157915891599160916191629163916491659166916791689169917091719172917391749175917691779178917991809181918291839184918591869187918891899190919191929193919491959196919791989199920092019202920392049205920692079208920992109211921292139214921592169217921892199220922192229223922492259226922792289229923092319232923392349235923692379238923992409241924292439244924592469247924892499250925192529253925492559256925792589259926092619262926392649265926692679268926992709271927292739274927592769277927892799280928192829283928492859286928792889289929092919292929392949295929692979298929993009301930293039304930593069307930893099310931193129313931493159316931793189319932093219322932393249325932693279328932993309331933293339334933593369337933893399340934193429343934493459346934793489349935093519352935393549355935693579358935993609361936293639364936593669367936893699370937193729373937493759376937793789379938093819382938393849385938693879388938993909391939293939394939593969397939893999400940194029403940494059406940794089409941094119412941394149415941694179418941994209421942294239424942594269427942894299430943194329433943494359436943794389439944094419442944394449445944694479448944994509451945294539454945594569457945894599460946194629463946494659466946794689469947094719472947394749475947694779478947994809481948294839484948594869487948894899490949194929493949494959496949794989499950095019502950395049505950695079508950995109511951295139514951595169517951895199520952195229523952495259526952795289529953095319532953395349535953695379538953995409541954295439544954595469547954895499550955195529553955495559556955795589559956095619562956395649565956695679568956995709571957295739574957595769577957895799580958195829583958495859586958795889589959095919592959395949595959695979598959996009601960296039604960596069607960896099610961196129613961496159616961796189619962096219622962396249625962696279628962996309631963296339634963596369637963896399640964196429643964496459646964796489649965096519652965396549655965696579658965996609661966296639664966596669667966896699670967196729673967496759676967796789679968096819682968396849685968696879688968996909691969296939694969596969697969896999700970197029703970497059706970797089709971097119712971397149715971697179718971997209721972297239724972597269727972897299730973197329733973497359736973797389739974097419742974397449745974697479748974997509751975297539754975597569757975897599760976197629763976497659766976797689769977097719772977397749775977697779778977997809781978297839784978597869787978897899790979197929793979497959796979797989799980098019802980398049805980698079808980998109811981298139814981598169817981898199820982198229823982498259826982798289829983098319832983398349835983698379838983998409841984298439844984598469847984898499850985198529853985498559856985798589859986098619862986398649865986698679868986998709871987298739874987598769877987898799880988198829883988498859886988798889889989098919892989398949895989698979898989999009901990299039904990599069907990899099910991199129913991499159916991799189919992099219922992399249925992699279928992999309931993299339934993599369937993899399940994199429943994499459946994799489949995099519952995399549955995699579958995999609961996299639964996599669967996899699970997199729973997499759976997799789979998099819982998399849985998699879988998999909991999299939994999599969997999899991000010001100021000310004100051000610007100081000910010100111001210013100141001510016100171001810019100201002110022100231002410025100261002710028100291003010031100321003310034100351003610037100381003910040100411004210043100441004510046100471004810049100501005110052100531005410055100561005710058100591006010061100621006310064100651006610067100681006910070100711007210073100741007510076100771007810079100801008110082100831008410085100861008710088100891009010091100921009310094100951009610097100981009910100101011010210103101041010510106101071010810109101101011110112101131011410115101161011710118101191012010121101221012310124101251012610127101281012910130101311013210133101341013510136101371013810139101401014110142101431014410145101461014710148101491015010151101521015310154101551015610157101581015910160101611016210163101641016510166101671016810169101701017110172101731017410175101761017710178101791018010181101821018310184101851018610187101881018910190101911019210193101941019510196101971019810199102001020110202102031020410205102061020710208102091021010211102121021310214102151021610217102181021910220102211022210223102241022510226102271022810229102301023110232102331023410235102361023710238102391024010241102421024310244102451024610247102481024910250102511025210253102541025510256102571025810259102601026110262102631026410265102661026710268102691027010271102721027310274102751027610277102781027910280102811028210283102841028510286102871028810289102901029110292102931029410295102961029710298102991030010301103021030310304103051030610307103081030910310103111031210313103141031510316103171031810319103201032110322103231032410325103261032710328103291033010331103321033310334103351033610337103381033910340103411034210343103441034510346103471034810349103501035110352103531035410355103561035710358103591036010361103621036310364103651036610367103681036910370103711037210373103741037510376103771037810379103801038110382103831038410385103861038710388103891039010391103921039310394103951039610397103981039910400104011040210403104041040510406104071040810409104101041110412104131041410415104161041710418104191042010421104221042310424104251042610427104281042910430104311043210433104341043510436104371043810439104401044110442104431044410445104461044710448104491045010451104521045310454104551045610457104581045910460104611046210463104641046510466104671046810469104701047110472104731047410475104761047710478104791048010481104821048310484104851048610487104881048910490104911049210493104941049510496104971049810499105001050110502105031050410505105061050710508105091051010511105121051310514105151051610517105181051910520105211052210523105241052510526105271052810529105301053110532105331053410535105361053710538105391054010541105421054310544105451054610547105481054910550105511055210553105541055510556105571055810559105601056110562105631056410565105661056710568105691057010571105721057310574105751057610577105781057910580105811058210583105841058510586105871058810589105901059110592105931059410595105961059710598105991060010601106021060310604106051060610607106081060910610106111061210613106141061510616106171061810619106201062110622106231062410625106261062710628106291063010631106321063310634106351063610637106381063910640106411064210643106441064510646106471064810649106501065110652106531065410655106561065710658106591066010661106621066310664106651066610667106681066910670106711067210673106741067510676106771067810679106801068110682106831068410685106861068710688106891069010691106921069310694106951069610697106981069910700107011070210703107041070510706107071070810709107101071110712107131071410715107161071710718107191072010721107221072310724107251072610727107281072910730107311073210733107341073510736107371073810739107401074110742107431074410745107461074710748107491075010751107521075310754107551075610757107581075910760107611076210763107641076510766107671076810769107701077110772107731077410775107761077710778107791078010781107821078310784107851078610787107881078910790107911079210793107941079510796107971079810799108001080110802108031080410805108061080710808108091081010811108121081310814108151081610817108181081910820108211082210823108241082510826108271082810829108301083110832108331083410835108361083710838108391084010841108421084310844108451084610847108481084910850108511085210853108541085510856108571085810859108601086110862108631086410865108661086710868108691087010871108721087310874108751087610877108781087910880108811088210883108841088510886108871088810889108901089110892108931089410895108961089710898108991090010901109021090310904109051090610907109081090910910109111091210913109141091510916109171091810919109201092110922109231092410925109261092710928109291093010931109321093310934109351093610937109381093910940109411094210943109441094510946109471094810949109501095110952109531095410955109561095710958109591096010961109621096310964109651096610967109681096910970109711097210973109741097510976109771097810979109801098110982109831098410985109861098710988109891099010991109921099310994109951099610997109981099911000110011100211003110041100511006110071100811009110101101111012110131101411015110161101711018110191102011021110221102311024110251102611027110281102911030110311103211033110341103511036110371103811039110401104111042110431104411045110461104711048110491105011051110521105311054110551105611057110581105911060110611106211063110641106511066110671106811069110701107111072110731107411075110761107711078110791108011081110821108311084110851108611087110881108911090110911109211093110941109511096110971109811099111001110111102111031110411105111061110711108111091111011111111121111311114111151111611117111181111911120111211112211123111241112511126111271112811129111301113111132111331113411135111361113711138111391114011141111421114311144111451114611147111481114911150111511115211153111541115511156111571115811159111601116111162111631116411165111661116711168111691117011171111721117311174111751117611177111781117911180111811118211183111841118511186111871118811189111901119111192111931119411195111961119711198111991120011201112021120311204112051120611207112081120911210112111121211213112141121511216112171121811219112201122111222112231122411225112261122711228112291123011231112321123311234112351123611237112381123911240112411124211243112441124511246112471124811249112501125111252112531125411255112561125711258112591126011261112621126311264112651126611267112681126911270112711127211273112741127511276112771127811279112801128111282112831128411285112861128711288112891129011291112921129311294112951129611297112981129911300113011130211303113041130511306113071130811309113101131111312113131131411315113161131711318113191132011321113221132311324113251132611327113281132911330113311133211333113341133511336113371133811339113401134111342113431134411345113461134711348113491135011351113521135311354113551135611357113581135911360113611136211363113641136511366113671136811369113701137111372113731137411375113761137711378113791138011381113821138311384113851138611387113881138911390113911139211393113941139511396113971139811399114001140111402114031140411405114061140711408114091141011411114121141311414114151141611417114181141911420114211142211423114241142511426114271142811429114301143111432114331143411435114361143711438114391144011441114421144311444114451144611447114481144911450114511145211453114541145511456114571145811459114601146111462114631146411465114661146711468114691147011471114721147311474114751147611477114781147911480114811148211483114841148511486114871148811489114901149111492114931149411495114961149711498114991150011501115021150311504115051150611507115081150911510115111151211513115141151511516115171151811519115201152111522115231152411525115261152711528115291153011531115321153311534115351153611537115381153911540115411154211543115441154511546115471154811549115501155111552115531155411555115561155711558115591156011561115621156311564115651156611567115681156911570115711157211573115741157511576115771157811579115801158111582115831158411585115861158711588115891159011591115921159311594115951159611597115981159911600116011160211603116041160511606116071160811609116101161111612116131161411615116161161711618116191162011621116221162311624116251162611627116281162911630116311163211633116341163511636116371163811639116401164111642116431164411645116461164711648116491165011651116521165311654116551165611657116581165911660116611166211663116641166511666116671166811669116701167111672116731167411675116761167711678116791168011681116821168311684116851168611687116881168911690116911169211693116941169511696116971169811699117001170111702117031170411705117061170711708117091171011711117121171311714117151171611717117181171911720117211172211723117241172511726117271172811729117301173111732117331173411735117361173711738117391174011741117421174311744117451174611747117481174911750117511175211753117541175511756117571175811759117601176111762117631176411765117661176711768117691177011771117721177311774117751177611777117781177911780117811178211783117841178511786117871178811789117901179111792117931179411795117961179711798117991180011801118021180311804118051180611807118081180911810118111181211813118141181511816118171181811819118201182111822118231182411825118261182711828118291183011831118321183311834118351183611837118381183911840118411184211843118441184511846118471184811849118501185111852118531185411855118561185711858118591186011861118621186311864118651186611867118681186911870118711187211873118741187511876118771187811879118801188111882118831188411885118861188711888118891189011891118921189311894118951189611897118981189911900119011190211903119041190511906119071190811909119101191111912119131191411915119161191711918119191192011921119221192311924119251192611927119281192911930119311193211933119341193511936119371193811939119401194111942119431194411945119461194711948119491195011951119521195311954119551195611957119581195911960119611196211963119641196511966119671196811969119701197111972119731197411975119761197711978119791198011981119821198311984119851198611987119881198911990119911199211993119941199511996119971199811999120001200112002120031200412005120061200712008120091201012011120121201312014120151201612017120181201912020120211202212023120241202512026120271202812029120301203112032120331203412035120361203712038120391204012041120421204312044120451204612047120481204912050120511205212053120541205512056120571205812059120601206112062120631206412065120661206712068120691207012071120721207312074120751207612077120781207912080120811208212083120841208512086120871208812089120901209112092120931209412095120961209712098120991210012101121021210312104121051210612107121081210912110121111211212113121141211512116121171211812119121201212112122121231212412125121261212712128121291213012131121321213312134121351213612137121381213912140121411214212143121441214512146121471214812149121501215112152121531215412155121561215712158121591216012161121621216312164121651216612167121681216912170121711217212173121741217512176121771217812179121801218112182121831218412185121861218712188121891219012191121921219312194121951219612197121981219912200122011220212203122041220512206122071220812209122101221112212122131221412215122161221712218122191222012221122221222312224122251222612227122281222912230122311223212233122341223512236122371223812239122401224112242122431224412245122461224712248122491225012251122521225312254122551225612257122581225912260122611226212263122641226512266122671226812269122701227112272122731227412275122761227712278122791228012281122821228312284122851228612287122881228912290122911229212293122941229512296122971229812299123001230112302123031230412305123061230712308123091231012311123121231312314123151231612317123181231912320123211232212323123241232512326123271232812329123301233112332123331233412335123361233712338123391234012341123421234312344123451234612347123481234912350123511235212353123541235512356123571235812359123601236112362123631236412365123661236712368123691237012371123721237312374123751237612377123781237912380123811238212383123841238512386123871238812389123901239112392123931239412395123961239712398123991240012401124021240312404124051240612407124081240912410124111241212413124141241512416124171241812419124201242112422124231242412425124261242712428124291243012431124321243312434124351243612437124381243912440124411244212443124441244512446124471244812449124501245112452124531245412455124561245712458124591246012461124621246312464124651246612467124681246912470124711247212473124741247512476124771247812479124801248112482124831248412485124861248712488124891249012491124921249312494124951249612497124981249912500125011250212503125041250512506125071250812509125101251112512125131251412515125161251712518125191252012521125221252312524125251252612527125281252912530125311253212533125341253512536125371253812539125401254112542125431254412545125461254712548125491255012551125521255312554125551255612557125581255912560125611256212563125641256512566125671256812569125701257112572125731257412575125761257712578125791258012581125821258312584125851258612587125881258912590125911259212593125941259512596125971259812599126001260112602126031260412605126061260712608126091261012611126121261312614126151261612617126181261912620126211262212623126241262512626126271262812629126301263112632126331263412635126361263712638126391264012641126421264312644126451264612647126481264912650126511265212653126541265512656126571265812659126601266112662126631266412665126661266712668126691267012671126721267312674126751267612677126781267912680126811268212683126841268512686126871268812689126901269112692126931269412695126961269712698126991270012701127021270312704127051270612707127081270912710127111271212713127141271512716127171271812719127201272112722127231272412725127261272712728127291273012731127321273312734127351273612737127381273912740127411274212743127441274512746127471274812749127501275112752127531275412755127561275712758127591276012761127621276312764127651276612767127681276912770127711277212773127741277512776127771277812779127801278112782127831278412785127861278712788127891279012791127921279312794127951279612797127981279912800128011280212803128041280512806128071280812809128101281112812128131281412815128161281712818128191282012821128221282312824128251282612827128281282912830128311283212833128341283512836128371283812839128401284112842128431284412845128461284712848128491285012851128521285312854128551285612857128581285912860128611286212863128641286512866128671286812869128701287112872128731287412875128761287712878128791288012881128821288312884128851288612887128881288912890128911289212893128941289512896128971289812899129001290112902129031290412905129061290712908129091291012911129121291312914129151291612917129181291912920129211292212923129241292512926129271292812929129301293112932129331293412935129361293712938129391294012941129421294312944129451294612947129481294912950129511295212953129541295512956129571295812959129601296112962129631296412965129661296712968129691297012971129721297312974129751297612977129781297912980129811298212983129841298512986129871298812989129901299112992129931299412995129961299712998129991300013001130021300313004130051300613007130081300913010130111301213013130141301513016130171301813019130201302113022130231302413025130261302713028130291303013031130321303313034130351303613037130381303913040130411304213043130441304513046130471304813049130501305113052130531305413055130561305713058130591306013061130621306313064130651306613067130681306913070130711307213073130741307513076130771307813079130801308113082130831308413085130861308713088130891309013091130921309313094130951309613097130981309913100131011310213103131041310513106131071310813109131101311113112131131311413115131161311713118131191312013121131221312313124131251312613127131281312913130131311313213133131341313513136131371313813139131401314113142131431314413145131461314713148131491315013151131521315313154131551315613157131581315913160131611316213163131641316513166131671316813169131701317113172131731317413175131761317713178131791318013181131821318313184131851318613187131881318913190131911319213193131941319513196131971319813199132001320113202132031320413205132061320713208132091321013211132121321313214132151321613217132181321913220132211322213223132241322513226132271322813229132301323113232132331323413235132361323713238132391324013241132421324313244132451324613247132481324913250132511325213253132541325513256132571325813259132601326113262132631326413265132661326713268132691327013271132721327313274132751327613277132781327913280132811328213283132841328513286132871328813289132901329113292132931329413295132961329713298132991330013301133021330313304133051330613307133081330913310133111331213313133141331513316133171331813319133201332113322133231332413325133261332713328133291333013331133321333313334133351333613337133381333913340133411334213343133441334513346133471334813349133501335113352133531335413355133561335713358133591336013361133621336313364133651336613367133681336913370133711337213373133741337513376133771337813379133801338113382133831338413385133861338713388133891339013391133921339313394133951339613397133981339913400134011340213403134041340513406134071340813409134101341113412134131341413415134161341713418134191342013421134221342313424134251342613427134281342913430134311343213433134341343513436134371343813439134401344113442134431344413445134461344713448134491345013451134521345313454134551345613457134581345913460134611346213463134641346513466134671346813469134701347113472134731347413475134761347713478134791348013481134821348313484134851348613487134881348913490134911349213493134941349513496134971349813499135001350113502135031350413505135061350713508135091351013511135121351313514135151351613517135181351913520135211352213523135241352513526135271352813529135301353113532135331353413535135361353713538135391354013541135421354313544135451354613547135481354913550135511355213553135541355513556135571355813559135601356113562135631356413565135661356713568135691357013571135721357313574135751357613577135781357913580135811358213583135841358513586135871358813589135901359113592135931359413595135961359713598135991360013601136021360313604136051360613607136081360913610136111361213613136141361513616136171361813619136201362113622136231362413625136261362713628136291363013631136321363313634136351363613637136381363913640136411364213643136441364513646136471364813649136501365113652136531365413655136561365713658136591366013661136621366313664136651366613667136681366913670136711367213673136741367513676136771367813679136801368113682136831368413685136861368713688136891369013691136921369313694136951369613697136981369913700137011370213703137041370513706137071370813709137101371113712137131371413715137161371713718137191372013721137221372313724137251372613727137281372913730137311373213733137341373513736137371373813739137401374113742137431374413745137461374713748137491375013751137521375313754137551375613757137581375913760137611376213763137641376513766137671376813769137701377113772137731377413775137761377713778137791378013781137821378313784137851378613787137881378913790137911379213793137941379513796137971379813799138001380113802138031380413805138061380713808138091381013811138121381313814138151381613817138181381913820138211382213823138241382513826138271382813829138301383113832138331383413835138361383713838138391384013841138421384313844138451384613847138481384913850138511385213853138541385513856138571385813859138601386113862138631386413865138661386713868138691387013871138721387313874138751387613877138781387913880138811388213883138841388513886138871388813889138901389113892138931389413895138961389713898138991390013901139021390313904139051390613907139081390913910139111391213913139141391513916139171391813919139201392113922139231392413925139261392713928139291393013931139321393313934139351393613937139381393913940139411394213943139441394513946139471394813949139501395113952139531395413955139561395713958139591396013961139621396313964139651396613967139681396913970139711397213973139741397513976139771397813979139801398113982139831398413985139861398713988139891399013991139921399313994139951399613997139981399914000140011400214003140041400514006140071400814009140101401114012140131401414015140161401714018140191402014021140221402314024140251402614027140281402914030140311403214033140341403514036140371403814039140401404114042140431404414045140461404714048140491405014051140521405314054140551405614057140581405914060140611406214063140641406514066140671406814069140701407114072140731407414075140761407714078140791408014081140821408314084140851408614087140881408914090140911409214093140941409514096140971409814099141001410114102141031410414105141061410714108141091411014111141121411314114141151411614117141181411914120141211412214123141241412514126141271412814129141301413114132141331413414135141361413714138141391414014141141421414314144141451414614147141481414914150141511415214153141541415514156141571415814159141601416114162141631416414165141661416714168141691417014171141721417314174141751417614177141781417914180141811418214183141841418514186141871418814189141901419114192141931419414195141961419714198141991420014201142021420314204142051420614207142081420914210142111421214213142141421514216142171421814219142201422114222142231422414225142261422714228142291423014231142321423314234142351423614237142381423914240142411424214243142441424514246142471424814249142501425114252142531425414255142561425714258142591426014261142621426314264142651426614267142681426914270142711427214273142741427514276142771427814279142801428114282142831428414285142861428714288142891429014291142921429314294142951429614297142981429914300143011430214303143041430514306143071430814309143101431114312143131431414315143161431714318143191432014321143221432314324143251432614327143281432914330143311433214333143341433514336143371433814339143401434114342143431434414345143461434714348143491435014351143521435314354143551435614357143581435914360143611436214363143641436514366143671436814369143701437114372143731437414375143761437714378143791438014381143821438314384143851438614387143881438914390143911439214393143941439514396143971439814399144001440114402144031440414405144061440714408144091441014411144121441314414144151441614417144181441914420144211442214423144241442514426144271442814429144301443114432144331443414435144361443714438144391444014441144421444314444144451444614447144481444914450144511445214453144541445514456144571445814459144601446114462144631446414465144661446714468144691447014471144721447314474144751447614477144781447914480144811448214483144841448514486144871448814489144901449114492144931449414495144961449714498144991450014501145021450314504145051450614507145081450914510145111451214513145141451514516145171451814519145201452114522145231452414525145261452714528145291453014531145321453314534145351453614537145381453914540145411454214543145441454514546145471454814549145501455114552145531455414555145561455714558145591456014561145621456314564145651456614567145681456914570145711457214573145741457514576145771457814579145801458114582145831458414585145861458714588145891459014591145921459314594145951459614597145981459914600146011460214603146041460514606146071460814609146101461114612146131461414615146161461714618146191462014621146221462314624146251462614627146281462914630146311463214633146341463514636146371463814639146401464114642146431464414645146461464714648146491465014651146521465314654146551465614657146581465914660146611466214663146641466514666146671466814669146701467114672146731467414675146761467714678146791468014681146821468314684146851468614687146881468914690146911469214693146941469514696146971469814699147001470114702147031470414705147061470714708147091471014711147121471314714147151471614717147181471914720147211472214723147241472514726147271472814729147301473114732147331473414735147361473714738147391474014741147421474314744147451474614747147481474914750147511475214753147541475514756147571475814759147601476114762147631476414765147661476714768147691477014771147721477314774147751477614777147781477914780147811478214783147841478514786147871478814789147901479114792147931479414795147961479714798147991480014801148021480314804148051480614807148081480914810148111481214813148141481514816148171481814819148201482114822148231482414825148261482714828148291483014831148321483314834148351483614837148381483914840148411484214843148441484514846148471484814849148501485114852148531485414855148561485714858148591486014861148621486314864148651486614867148681486914870148711487214873148741487514876148771487814879148801488114882148831488414885148861488714888148891489014891148921489314894148951489614897148981489914900149011490214903149041490514906149071490814909149101491114912149131491414915149161491714918149191492014921149221492314924149251492614927149281492914930149311493214933149341493514936149371493814939149401494114942149431494414945149461494714948149491495014951149521495314954149551495614957149581495914960149611496214963149641496514966149671496814969149701497114972149731497414975149761497714978149791498014981149821498314984149851498614987149881498914990149911499214993149941499514996149971499814999150001500115002150031500415005150061500715008150091501015011150121501315014150151501615017150181501915020150211502215023150241502515026150271502815029150301503115032150331503415035150361503715038150391504015041150421504315044150451504615047
  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)(TransmitBufferSet (appl, m->info.data_b3_req.Data));
  451. }
  452. j = (j + 3) & 0xfffc;
  453. *((APPL * *)(&((byte *)(plci->msg_in_queue))[j])) = appl;
  454. plci->msg_in_write_pos = j + MSG_IN_OVERHEAD;
  455. return 0;
  456. }
  457. }
  458. else
  459. {
  460. plci = NULL;
  461. }
  462. }
  463. dbug(1,dprintf("com=%x",msg->header.command));
  464. for(j=0;j<MAX_MSG_PARMS+1;j++) msg_parms[j].length = 0;
  465. for(i=0, ret = _BAD_MSG;
  466. i<(sizeof(ftable)/sizeof(struct _ftable));
  467. i++) {
  468. if(ftable[i].command==msg->header.command) {
  469. /* break loop if the message is correct, otherwise continue scan */
  470. /* (for example: CONNECT_B3_T90_ACT_RES has two specifications) */
  471. if(!api_parse(msg->info.b,(word)(msg->header.length-12),ftable[i].format,msg_parms)) {
  472. ret = 0;
  473. break;
  474. }
  475. for(j=0;j<MAX_MSG_PARMS+1;j++) msg_parms[j].length = 0;
  476. }
  477. }
  478. if(ret) {
  479. dbug(1,dprintf("BAD_MSG"));
  480. if(plci) plci->command = 0;
  481. return ret;
  482. }
  483. c = ftable[i].function(GET_DWORD(&msg->header.controller),
  484. msg->header.number,
  485. a,
  486. plci,
  487. appl,
  488. msg_parms);
  489. channel_xmit_extended_xon (plci);
  490. if(c==1) send_req(plci);
  491. if(c==2 && plci) plci->req_in = plci->req_in_start = plci->req_out = 0;
  492. if(plci && !plci->req_in) plci->command = 0;
  493. return 0;
  494. }
  495. /*------------------------------------------------------------------*/
  496. /* api_parse function, check the format of api messages */
  497. /*------------------------------------------------------------------*/
  498. word api_parse(byte * msg, word length, byte * format, API_PARSE * parms)
  499. {
  500. word i;
  501. word p;
  502. for(i=0,p=0; format[i]; i++) {
  503. if(parms)
  504. {
  505. parms[i].info = &msg[p];
  506. }
  507. switch(format[i]) {
  508. case 'b':
  509. p +=1;
  510. break;
  511. case 'w':
  512. p +=2;
  513. break;
  514. case 'd':
  515. p +=4;
  516. break;
  517. case 's':
  518. if(msg[p]==0xff) {
  519. parms[i].info +=2;
  520. parms[i].length = msg[p+1] + (msg[p+2]<<8);
  521. p +=(parms[i].length +3);
  522. }
  523. else {
  524. parms[i].length = msg[p];
  525. p +=(parms[i].length +1);
  526. }
  527. break;
  528. }
  529. if(p>length) return TRUE;
  530. }
  531. if(parms) parms[i].info = NULL;
  532. return FALSE;
  533. }
  534. void api_save_msg(API_PARSE *in, byte *format, API_SAVE *out)
  535. {
  536. word i, j, n = 0;
  537. byte *p;
  538. p = out->info;
  539. for (i = 0; format[i] != '\0'; i++)
  540. {
  541. out->parms[i].info = p;
  542. out->parms[i].length = in[i].length;
  543. switch (format[i])
  544. {
  545. case 'b':
  546. n = 1;
  547. break;
  548. case 'w':
  549. n = 2;
  550. break;
  551. case 'd':
  552. n = 4;
  553. break;
  554. case 's':
  555. n = in[i].length + 1;
  556. break;
  557. }
  558. for (j = 0; j < n; j++)
  559. *(p++) = in[i].info[j];
  560. }
  561. out->parms[i].info = NULL;
  562. out->parms[i].length = 0;
  563. }
  564. void api_load_msg(API_SAVE *in, API_PARSE *out)
  565. {
  566. word i;
  567. i = 0;
  568. do
  569. {
  570. out[i].info = in->parms[i].info;
  571. out[i].length = in->parms[i].length;
  572. } while (in->parms[i++].info);
  573. }
  574. /*------------------------------------------------------------------*/
  575. /* CAPI remove function */
  576. /*------------------------------------------------------------------*/
  577. word api_remove_start(void)
  578. {
  579. word i;
  580. word j;
  581. if(!remove_started) {
  582. remove_started = TRUE;
  583. for(i=0;i<max_adapter;i++) {
  584. if(adapter[i].request) {
  585. for(j=0;j<adapter[i].max_plci;j++) {
  586. if(adapter[i].plci[j].Sig.Id) plci_remove(&adapter[i].plci[j]);
  587. }
  588. }
  589. }
  590. return 1;
  591. }
  592. else {
  593. for(i=0;i<max_adapter;i++) {
  594. if(adapter[i].request) {
  595. for(j=0;j<adapter[i].max_plci;j++) {
  596. if(adapter[i].plci[j].Sig.Id) return 1;
  597. }
  598. }
  599. }
  600. }
  601. api_remove_complete();
  602. return 0;
  603. }
  604. /*------------------------------------------------------------------*/
  605. /* internal command queue */
  606. /*------------------------------------------------------------------*/
  607. static void init_internal_command_queue (PLCI *plci)
  608. {
  609. word i;
  610. dbug (1, dprintf ("%s,%d: init_internal_command_queue",
  611. (char *)(FILE_), __LINE__));
  612. plci->internal_command = 0;
  613. for (i = 0; i < MAX_INTERNAL_COMMAND_LEVELS; i++)
  614. plci->internal_command_queue[i] = NULL;
  615. }
  616. static void start_internal_command (dword Id, PLCI *plci, t_std_internal_command command_function)
  617. {
  618. word i;
  619. dbug (1, dprintf ("[%06lx] %s,%d: start_internal_command",
  620. UnMapId (Id), (char *)(FILE_), __LINE__));
  621. if (plci->internal_command == 0)
  622. {
  623. plci->internal_command_queue[0] = command_function;
  624. (* command_function)(Id, plci, OK);
  625. }
  626. else
  627. {
  628. i = 1;
  629. while (plci->internal_command_queue[i] != 0)
  630. i++;
  631. plci->internal_command_queue[i] = command_function;
  632. }
  633. }
  634. static void next_internal_command (dword Id, PLCI *plci)
  635. {
  636. word i;
  637. dbug (1, dprintf ("[%06lx] %s,%d: next_internal_command",
  638. UnMapId (Id), (char *)(FILE_), __LINE__));
  639. plci->internal_command = 0;
  640. plci->internal_command_queue[0] = NULL;
  641. while (plci->internal_command_queue[1] != 0)
  642. {
  643. for (i = 0; i < MAX_INTERNAL_COMMAND_LEVELS - 1; i++)
  644. plci->internal_command_queue[i] = plci->internal_command_queue[i+1];
  645. plci->internal_command_queue[MAX_INTERNAL_COMMAND_LEVELS - 1] = NULL;
  646. (*(plci->internal_command_queue[0]))(Id, plci, OK);
  647. if (plci->internal_command != 0)
  648. return;
  649. plci->internal_command_queue[0] = NULL;
  650. }
  651. }
  652. /*------------------------------------------------------------------*/
  653. /* NCCI allocate/remove function */
  654. /*------------------------------------------------------------------*/
  655. static dword ncci_mapping_bug = 0;
  656. static word get_ncci (PLCI *plci, byte ch, word force_ncci)
  657. {
  658. DIVA_CAPI_ADAPTER *a;
  659. word ncci, i, j, k;
  660. a = plci->adapter;
  661. if (!ch || a->ch_ncci[ch])
  662. {
  663. ncci_mapping_bug++;
  664. dbug(1,dprintf("NCCI mapping exists %ld %02x %02x %02x-%02x",
  665. ncci_mapping_bug, ch, force_ncci, a->ncci_ch[a->ch_ncci[ch]], a->ch_ncci[ch]));
  666. ncci = ch;
  667. }
  668. else
  669. {
  670. if (force_ncci)
  671. ncci = force_ncci;
  672. else
  673. {
  674. if ((ch < MAX_NCCI+1) && !a->ncci_ch[ch])
  675. ncci = ch;
  676. else
  677. {
  678. ncci = 1;
  679. while ((ncci < MAX_NCCI+1) && a->ncci_ch[ncci])
  680. ncci++;
  681. if (ncci == MAX_NCCI+1)
  682. {
  683. ncci_mapping_bug++;
  684. i = 1;
  685. do
  686. {
  687. j = 1;
  688. while ((j < MAX_NCCI+1) && (a->ncci_ch[j] != i))
  689. j++;
  690. k = j;
  691. if (j < MAX_NCCI+1)
  692. {
  693. do
  694. {
  695. j++;
  696. } while ((j < MAX_NCCI+1) && (a->ncci_ch[j] != i));
  697. }
  698. } while ((i < MAX_NL_CHANNEL+1) && (j < MAX_NCCI+1));
  699. if (i < MAX_NL_CHANNEL+1)
  700. {
  701. dbug(1,dprintf("NCCI mapping overflow %ld %02x %02x %02x-%02x-%02x",
  702. ncci_mapping_bug, ch, force_ncci, i, k, j));
  703. }
  704. else
  705. {
  706. dbug(1,dprintf("NCCI mapping overflow %ld %02x %02x",
  707. ncci_mapping_bug, ch, force_ncci));
  708. }
  709. ncci = ch;
  710. }
  711. }
  712. a->ncci_plci[ncci] = plci->Id;
  713. a->ncci_state[ncci] = IDLE;
  714. if (!plci->ncci_ring_list)
  715. plci->ncci_ring_list = ncci;
  716. else
  717. a->ncci_next[ncci] = a->ncci_next[plci->ncci_ring_list];
  718. a->ncci_next[plci->ncci_ring_list] = (byte) ncci;
  719. }
  720. a->ncci_ch[ncci] = ch;
  721. a->ch_ncci[ch] = (byte) ncci;
  722. dbug(1,dprintf("NCCI mapping established %ld %02x %02x %02x-%02x",
  723. ncci_mapping_bug, ch, force_ncci, ch, ncci));
  724. }
  725. return (ncci);
  726. }
  727. static void ncci_free_receive_buffers (PLCI *plci, word ncci)
  728. {
  729. DIVA_CAPI_ADAPTER *a;
  730. APPL *appl;
  731. word i, ncci_code;
  732. dword Id;
  733. a = plci->adapter;
  734. Id = (((dword) ncci) << 16) | (((word)(plci->Id)) << 8) | a->Id;
  735. if (ncci)
  736. {
  737. if (a->ncci_plci[ncci] == plci->Id)
  738. {
  739. if (!plci->appl)
  740. {
  741. ncci_mapping_bug++;
  742. dbug(1,dprintf("NCCI mapping appl expected %ld %08lx",
  743. ncci_mapping_bug, Id));
  744. }
  745. else
  746. {
  747. appl = plci->appl;
  748. ncci_code = ncci | (((word) a->Id) << 8);
  749. for (i = 0; i < appl->MaxBuffer; i++)
  750. {
  751. if ((appl->DataNCCI[i] == ncci_code)
  752. && (((byte)(appl->DataFlags[i] >> 8)) == plci->Id))
  753. {
  754. appl->DataNCCI[i] = 0;
  755. }
  756. }
  757. }
  758. }
  759. }
  760. else
  761. {
  762. for (ncci = 1; ncci < MAX_NCCI+1; ncci++)
  763. {
  764. if (a->ncci_plci[ncci] == plci->Id)
  765. {
  766. if (!plci->appl)
  767. {
  768. ncci_mapping_bug++;
  769. dbug(1,dprintf("NCCI mapping no appl %ld %08lx",
  770. ncci_mapping_bug, Id));
  771. }
  772. else
  773. {
  774. appl = plci->appl;
  775. ncci_code = ncci | (((word) a->Id) << 8);
  776. for (i = 0; i < appl->MaxBuffer; i++)
  777. {
  778. if ((appl->DataNCCI[i] == ncci_code)
  779. && (((byte)(appl->DataFlags[i] >> 8)) == plci->Id))
  780. {
  781. appl->DataNCCI[i] = 0;
  782. }
  783. }
  784. }
  785. }
  786. }
  787. }
  788. }
  789. static void cleanup_ncci_data (PLCI *plci, word ncci)
  790. {
  791. NCCI *ncci_ptr;
  792. if (ncci && (plci->adapter->ncci_plci[ncci] == plci->Id))
  793. {
  794. ncci_ptr = &(plci->adapter->ncci[ncci]);
  795. if (plci->appl)
  796. {
  797. while (ncci_ptr->data_pending != 0)
  798. {
  799. if (!plci->data_sent || (ncci_ptr->DBuffer[ncci_ptr->data_out].P != plci->data_sent_ptr))
  800. TransmitBufferFree (plci->appl, ncci_ptr->DBuffer[ncci_ptr->data_out].P);
  801. (ncci_ptr->data_out)++;
  802. if (ncci_ptr->data_out == MAX_DATA_B3)
  803. ncci_ptr->data_out = 0;
  804. (ncci_ptr->data_pending)--;
  805. }
  806. }
  807. ncci_ptr->data_out = 0;
  808. ncci_ptr->data_pending = 0;
  809. ncci_ptr->data_ack_out = 0;
  810. ncci_ptr->data_ack_pending = 0;
  811. }
  812. }
  813. static void ncci_remove (PLCI *plci, word ncci, byte preserve_ncci)
  814. {
  815. DIVA_CAPI_ADAPTER *a;
  816. dword Id;
  817. word i;
  818. a = plci->adapter;
  819. Id = (((dword) ncci) << 16) | (((word)(plci->Id)) << 8) | a->Id;
  820. if (!preserve_ncci)
  821. ncci_free_receive_buffers (plci, ncci);
  822. if (ncci)
  823. {
  824. if (a->ncci_plci[ncci] != plci->Id)
  825. {
  826. ncci_mapping_bug++;
  827. dbug(1,dprintf("NCCI mapping doesn't exist %ld %08lx %02x",
  828. ncci_mapping_bug, Id, preserve_ncci));
  829. }
  830. else
  831. {
  832. cleanup_ncci_data (plci, ncci);
  833. dbug(1,dprintf("NCCI mapping released %ld %08lx %02x %02x-%02x",
  834. ncci_mapping_bug, Id, preserve_ncci, a->ncci_ch[ncci], ncci));
  835. a->ch_ncci[a->ncci_ch[ncci]] = 0;
  836. if (!preserve_ncci)
  837. {
  838. a->ncci_ch[ncci] = 0;
  839. a->ncci_plci[ncci] = 0;
  840. a->ncci_state[ncci] = IDLE;
  841. i = plci->ncci_ring_list;
  842. while ((i != 0) && (a->ncci_next[i] != plci->ncci_ring_list) && (a->ncci_next[i] != ncci))
  843. i = a->ncci_next[i];
  844. if ((i != 0) && (a->ncci_next[i] == ncci))
  845. {
  846. if (i == ncci)
  847. plci->ncci_ring_list = 0;
  848. else if (plci->ncci_ring_list == ncci)
  849. plci->ncci_ring_list = i;
  850. a->ncci_next[i] = a->ncci_next[ncci];
  851. }
  852. a->ncci_next[ncci] = 0;
  853. }
  854. }
  855. }
  856. else
  857. {
  858. for (ncci = 1; ncci < MAX_NCCI+1; ncci++)
  859. {
  860. if (a->ncci_plci[ncci] == plci->Id)
  861. {
  862. cleanup_ncci_data (plci, ncci);
  863. dbug(1,dprintf("NCCI mapping released %ld %08lx %02x %02x-%02x",
  864. ncci_mapping_bug, Id, preserve_ncci, a->ncci_ch[ncci], ncci));
  865. a->ch_ncci[a->ncci_ch[ncci]] = 0;
  866. if (!preserve_ncci)
  867. {
  868. a->ncci_ch[ncci] = 0;
  869. a->ncci_plci[ncci] = 0;
  870. a->ncci_state[ncci] = IDLE;
  871. a->ncci_next[ncci] = 0;
  872. }
  873. }
  874. }
  875. if (!preserve_ncci)
  876. plci->ncci_ring_list = 0;
  877. }
  878. }
  879. /*------------------------------------------------------------------*/
  880. /* PLCI remove function */
  881. /*------------------------------------------------------------------*/
  882. static void plci_free_msg_in_queue (PLCI *plci)
  883. {
  884. word i;
  885. if (plci->appl)
  886. {
  887. i = plci->msg_in_read_pos;
  888. while (i != plci->msg_in_write_pos)
  889. {
  890. if (i == plci->msg_in_wrap_pos)
  891. i = 0;
  892. if (((CAPI_MSG *)(&((byte *)(plci->msg_in_queue))[i]))->header.command == _DATA_B3_R)
  893. {
  894. TransmitBufferFree (plci->appl,
  895. (byte *)(((CAPI_MSG *)(&((byte *)(plci->msg_in_queue))[i]))->info.data_b3_req.Data));
  896. }
  897. i += (((CAPI_MSG *)(&((byte *)(plci->msg_in_queue))[i]))->header.length +
  898. MSG_IN_OVERHEAD + 3) & 0xfffc;
  899. }
  900. }
  901. plci->msg_in_write_pos = MSG_IN_QUEUE_SIZE;
  902. plci->msg_in_read_pos = MSG_IN_QUEUE_SIZE;
  903. plci->msg_in_wrap_pos = MSG_IN_QUEUE_SIZE;
  904. }
  905. static void plci_remove(PLCI * plci)
  906. {
  907. if(!plci) {
  908. dbug(1,dprintf("plci_remove(no plci)"));
  909. return;
  910. }
  911. init_internal_command_queue (plci);
  912. dbug(1,dprintf("plci_remove(%x,tel=%x)",plci->Id,plci->tel));
  913. if(plci_remove_check(plci))
  914. {
  915. return;
  916. }
  917. if (plci->Sig.Id == 0xff)
  918. {
  919. dbug(1,dprintf("D-channel X.25 plci->NL.Id:%0x", plci->NL.Id));
  920. if (plci->NL.Id && !plci->nl_remove_id)
  921. {
  922. nl_req_ncci(plci,REMOVE,0);
  923. send_req(plci);
  924. }
  925. }
  926. else
  927. {
  928. if (!plci->sig_remove_id
  929. && (plci->Sig.Id
  930. || (plci->req_in!=plci->req_out)
  931. || (plci->nl_req || plci->sig_req)))
  932. {
  933. sig_req(plci,HANGUP,0);
  934. send_req(plci);
  935. }
  936. }
  937. ncci_remove (plci, 0, FALSE);
  938. plci_free_msg_in_queue (plci);
  939. plci->channels = 0;
  940. plci->appl = NULL;
  941. if ((plci->State == INC_CON_PENDING) || (plci->State == INC_CON_ALERT))
  942. plci->State = OUTG_DIS_PENDING;
  943. }
  944. /*------------------------------------------------------------------*/
  945. /* Application Group function helpers */
  946. /*------------------------------------------------------------------*/
  947. static void set_group_ind_mask (PLCI *plci)
  948. {
  949. word i;
  950. for (i = 0; i < C_IND_MASK_DWORDS; i++)
  951. plci->group_optimization_mask_table[i] = 0xffffffffL;
  952. }
  953. static void clear_group_ind_mask_bit (PLCI *plci, word b)
  954. {
  955. plci->group_optimization_mask_table[b >> 5] &= ~(1L << (b & 0x1f));
  956. }
  957. static byte test_group_ind_mask_bit (PLCI *plci, word b)
  958. {
  959. return ((plci->group_optimization_mask_table[b >> 5] & (1L << (b & 0x1f))) != 0);
  960. }
  961. /*------------------------------------------------------------------*/
  962. /* c_ind_mask operations for arbitrary MAX_APPL */
  963. /*------------------------------------------------------------------*/
  964. static void clear_c_ind_mask (PLCI *plci)
  965. {
  966. word i;
  967. for (i = 0; i < C_IND_MASK_DWORDS; i++)
  968. plci->c_ind_mask_table[i] = 0;
  969. }
  970. static byte c_ind_mask_empty (PLCI *plci)
  971. {
  972. word i;
  973. i = 0;
  974. while ((i < C_IND_MASK_DWORDS) && (plci->c_ind_mask_table[i] == 0))
  975. i++;
  976. return (i == C_IND_MASK_DWORDS);
  977. }
  978. static void set_c_ind_mask_bit (PLCI *plci, word b)
  979. {
  980. plci->c_ind_mask_table[b >> 5] |= (1L << (b & 0x1f));
  981. }
  982. static void clear_c_ind_mask_bit (PLCI *plci, word b)
  983. {
  984. plci->c_ind_mask_table[b >> 5] &= ~(1L << (b & 0x1f));
  985. }
  986. static byte test_c_ind_mask_bit (PLCI *plci, word b)
  987. {
  988. return ((plci->c_ind_mask_table[b >> 5] & (1L << (b & 0x1f))) != 0);
  989. }
  990. static void dump_c_ind_mask (PLCI *plci)
  991. {
  992. static char hex_digit_table[0x10] =
  993. {'0','1','2','3','4','5','6','7','8','9','a','b','c','d','e','f'};
  994. word i, j, k;
  995. dword d;
  996. char *p;
  997. char buf[40];
  998. for (i = 0; i < C_IND_MASK_DWORDS; i += 4)
  999. {
  1000. p = buf + 36;
  1001. *p = '\0';
  1002. for (j = 0; j < 4; j++)
  1003. {
  1004. if (i+j < C_IND_MASK_DWORDS)
  1005. {
  1006. d = plci->c_ind_mask_table[i+j];
  1007. for (k = 0; k < 8; k++)
  1008. {
  1009. *(--p) = hex_digit_table[d & 0xf];
  1010. d >>= 4;
  1011. }
  1012. }
  1013. else if (i != 0)
  1014. {
  1015. for (k = 0; k < 8; k++)
  1016. *(--p) = ' ';
  1017. }
  1018. *(--p) = ' ';
  1019. }
  1020. dbug(1,dprintf ("c_ind_mask =%s", (char *) p));
  1021. }
  1022. }
  1023. #define dump_plcis(a)
  1024. /*------------------------------------------------------------------*/
  1025. /* translation function for each message */
  1026. /*------------------------------------------------------------------*/
  1027. byte connect_req(dword Id, word Number, DIVA_CAPI_ADAPTER * a, PLCI * plci, APPL * appl, API_PARSE * parms)
  1028. {
  1029. word ch;
  1030. word i;
  1031. word Info;
  1032. word CIP;
  1033. byte LinkLayer;
  1034. API_PARSE * ai;
  1035. API_PARSE * bp;
  1036. API_PARSE ai_parms[5];
  1037. word channel = 0;
  1038. dword ch_mask;
  1039. byte m;
  1040. static byte esc_chi[35] = {0x02,0x18,0x01};
  1041. static byte lli[2] = {0x01,0x00};
  1042. byte noCh = 0;
  1043. word dir = 0;
  1044. byte *p_chi = "";
  1045. for(i=0;i<5;i++) ai_parms[i].length = 0;
  1046. dbug(1,dprintf("connect_req(%d)",parms->length));
  1047. Info = _WRONG_IDENTIFIER;
  1048. if(a)
  1049. {
  1050. if(a->adapter_disabled)
  1051. {
  1052. dbug(1,dprintf("adapter disabled"));
  1053. Id = ((word)1<<8)|a->Id;
  1054. sendf(appl,_CONNECT_R|CONFIRM,Id,Number,"w",0);
  1055. sendf(appl, _DISCONNECT_I, Id, 0, "w", _L1_ERROR);
  1056. return FALSE;
  1057. }
  1058. Info = _OUT_OF_PLCI;
  1059. if((i=get_plci(a)))
  1060. {
  1061. Info = 0;
  1062. plci = &a->plci[i-1];
  1063. plci->appl = appl;
  1064. plci->call_dir = CALL_DIR_OUT | CALL_DIR_ORIGINATE;
  1065. /* check 'external controller' bit for codec support */
  1066. if(Id & EXT_CONTROLLER)
  1067. {
  1068. if(AdvCodecSupport(a, plci, appl, 0) )
  1069. {
  1070. plci->Id = 0;
  1071. sendf(appl, _CONNECT_R|CONFIRM, Id, Number, "w", _WRONG_IDENTIFIER);
  1072. return 2;
  1073. }
  1074. }
  1075. ai = &parms[9];
  1076. bp = &parms[5];
  1077. ch = 0;
  1078. if(bp->length)LinkLayer = bp->info[3];
  1079. else LinkLayer = 0;
  1080. if(ai->length)
  1081. {
  1082. ch=0xffff;
  1083. if(!api_parse(&ai->info[1],(word)ai->length,"ssss",ai_parms))
  1084. {
  1085. ch = 0;
  1086. if(ai_parms[0].length)
  1087. {
  1088. ch = GET_WORD(ai_parms[0].info+1);
  1089. if(ch>4) ch=0; /* safety -> ignore ChannelID */
  1090. if(ch==4) /* explizit CHI in message */
  1091. {
  1092. /* check length of B-CH struct */
  1093. if((ai_parms[0].info)[3]>=1)
  1094. {
  1095. if((ai_parms[0].info)[4]==CHI)
  1096. {
  1097. p_chi = &((ai_parms[0].info)[5]);
  1098. }
  1099. else
  1100. {
  1101. p_chi = &((ai_parms[0].info)[3]);
  1102. }
  1103. if(p_chi[0]>35) /* check length of channel ID */
  1104. {
  1105. Info = _WRONG_MESSAGE_FORMAT;
  1106. }
  1107. }
  1108. else Info = _WRONG_MESSAGE_FORMAT;
  1109. }
  1110. if(ch==3 && ai_parms[0].length>=7 && ai_parms[0].length<=36)
  1111. {
  1112. dir = GET_WORD(ai_parms[0].info+3);
  1113. ch_mask = 0;
  1114. m = 0x3f;
  1115. for(i=0; i+5<=ai_parms[0].length; i++)
  1116. {
  1117. if(ai_parms[0].info[i+5]!=0)
  1118. {
  1119. if((ai_parms[0].info[i+5] | m) != 0xff)
  1120. Info = _WRONG_MESSAGE_FORMAT;
  1121. else
  1122. {
  1123. if (ch_mask == 0)
  1124. channel = i;
  1125. ch_mask |= 1L << i;
  1126. }
  1127. }
  1128. m = 0;
  1129. }
  1130. if (ch_mask == 0)
  1131. Info = _WRONG_MESSAGE_FORMAT;
  1132. if (!Info)
  1133. {
  1134. if ((ai_parms[0].length == 36) || (ch_mask != ((dword)(1L << channel))))
  1135. {
  1136. esc_chi[0] = (byte)(ai_parms[0].length - 2);
  1137. for(i=0; i+5<=ai_parms[0].length; i++)
  1138. esc_chi[i+3] = ai_parms[0].info[i+5];
  1139. }
  1140. else
  1141. esc_chi[0] = 2;
  1142. esc_chi[2] = (byte)channel;
  1143. plci->b_channel = (byte)channel; /* not correct for ETSI ch 17..31 */
  1144. add_p(plci,LLI,lli);
  1145. add_p(plci,ESC,esc_chi);
  1146. plci->State = LOCAL_CONNECT;
  1147. if(!dir) plci->call_dir |= CALL_DIR_FORCE_OUTG_NL; /* dir 0=DTE, 1=DCE */
  1148. }
  1149. }
  1150. }
  1151. }
  1152. else Info = _WRONG_MESSAGE_FORMAT;
  1153. }
  1154. dbug(1,dprintf("ch=%x,dir=%x,p_ch=%d",ch,dir,channel));
  1155. plci->command = _CONNECT_R;
  1156. plci->number = Number;
  1157. /* x.31 or D-ch free SAPI in LinkLayer? */
  1158. if(ch==1 && LinkLayer!=3 && LinkLayer!=12) noCh = TRUE;
  1159. if((ch==0 || ch==2 || noCh || ch==3 || ch==4) && !Info)
  1160. {
  1161. /* B-channel used for B3 connections (ch==0), or no B channel */
  1162. /* is used (ch==2) or perm. connection (3) is used do a CALL */
  1163. if(noCh) Info = add_b1(plci,&parms[5],2,0); /* no resource */
  1164. else Info = add_b1(plci,&parms[5],ch,0);
  1165. add_s(plci,OAD,&parms[2]);
  1166. add_s(plci,OSA,&parms[4]);
  1167. add_s(plci,BC,&parms[6]);
  1168. add_s(plci,LLC,&parms[7]);
  1169. add_s(plci,HLC,&parms[8]);
  1170. CIP = GET_WORD(parms[0].info);
  1171. if (a->Info_Mask[appl->Id-1] & 0x200)
  1172. {
  1173. /* early B3 connect (CIP mask bit 9) no release after a disc */
  1174. add_p(plci,LLI,"\x01\x01");
  1175. }
  1176. if(GET_WORD(parms[0].info)<29) {
  1177. add_p(plci,BC,cip_bc[GET_WORD(parms[0].info)][a->u_law]);
  1178. add_p(plci,HLC,cip_hlc[GET_WORD(parms[0].info)]);
  1179. }
  1180. add_p(plci,UID,"\x06\x43\x61\x70\x69\x32\x30");
  1181. sig_req(plci,ASSIGN,DSIG_ID);
  1182. }
  1183. else if(ch==1) {
  1184. /* D-Channel used for B3 connections */
  1185. plci->Sig.Id = 0xff;
  1186. Info = 0;
  1187. }
  1188. if(!Info && ch!=2 && !noCh ) {
  1189. Info = add_b23(plci,&parms[5]);
  1190. if(!Info) {
  1191. if(!(plci->tel && !plci->adv_nl))nl_req_ncci(plci,ASSIGN,0);
  1192. }
  1193. }
  1194. if(!Info)
  1195. {
  1196. if(ch==0 || ch==2 || ch==3 || noCh || ch==4)
  1197. {
  1198. if(plci->spoofed_msg==SPOOFING_REQUIRED)
  1199. {
  1200. api_save_msg(parms, "wsssssssss", &plci->saved_msg);
  1201. plci->spoofed_msg = CALL_REQ;
  1202. plci->internal_command = BLOCK_PLCI;
  1203. plci->command = 0;
  1204. dbug(1,dprintf("Spoof"));
  1205. send_req(plci);
  1206. return FALSE;
  1207. }
  1208. if(ch==4)add_p(plci,CHI,p_chi);
  1209. add_s(plci,CPN,&parms[1]);
  1210. add_s(plci,DSA,&parms[3]);
  1211. if(noCh) add_p(plci,ESC,"\x02\x18\xfd"); /* D-channel, no B-L3 */
  1212. add_ai(plci,&parms[9]);
  1213. if(!dir)sig_req(plci,CALL_REQ,0);
  1214. else
  1215. {
  1216. plci->command = PERM_LIST_REQ;
  1217. plci->appl = appl;
  1218. sig_req(plci,LISTEN_REQ,0);
  1219. send_req(plci);
  1220. return FALSE;
  1221. }
  1222. }
  1223. send_req(plci);
  1224. return FALSE;
  1225. }
  1226. plci->Id = 0;
  1227. }
  1228. }
  1229. sendf(appl,
  1230. _CONNECT_R|CONFIRM,
  1231. Id,
  1232. Number,
  1233. "w",Info);
  1234. return 2;
  1235. }
  1236. byte connect_res(dword Id, word Number, DIVA_CAPI_ADAPTER * a, 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. byte connect_a_res(dword Id, word Number, DIVA_CAPI_ADAPTER * a, PLCI * plci, APPL * appl, API_PARSE * msg)
  1386. {
  1387. dbug(1,dprintf("connect_a_res"));
  1388. return FALSE;
  1389. }
  1390. byte disconnect_req(dword Id, word Number, DIVA_CAPI_ADAPTER * a, PLCI * plci, APPL * appl, API_PARSE * msg)
  1391. {
  1392. word Info;
  1393. word i;
  1394. dbug(1,dprintf("disconnect_req"));
  1395. Info = _WRONG_IDENTIFIER;
  1396. if(plci)
  1397. {
  1398. if(plci->State==INC_CON_PENDING || plci->State==INC_CON_ALERT)
  1399. {
  1400. clear_c_ind_mask_bit (plci, (word)(appl->Id-1));
  1401. plci->appl = appl;
  1402. for(i=0; i<max_appl; i++)
  1403. {
  1404. if(test_c_ind_mask_bit (plci, i))
  1405. sendf(&application[i], _DISCONNECT_I, Id, 0, "w", 0);
  1406. }
  1407. plci->State = OUTG_DIS_PENDING;
  1408. }
  1409. if(plci->Sig.Id && plci->appl)
  1410. {
  1411. Info = 0;
  1412. if(plci->Sig.Id!=0xff)
  1413. {
  1414. if(plci->State!=INC_DIS_PENDING)
  1415. {
  1416. add_ai(plci, &msg[0]);
  1417. sig_req(plci,HANGUP,0);
  1418. plci->State = OUTG_DIS_PENDING;
  1419. return 1;
  1420. }
  1421. }
  1422. else
  1423. {
  1424. if (plci->NL.Id && !plci->nl_remove_id)
  1425. {
  1426. mixer_remove (plci);
  1427. nl_req_ncci(plci,REMOVE,0);
  1428. sendf(appl,_DISCONNECT_R|CONFIRM,Id,Number,"w",0);
  1429. sendf(appl, _DISCONNECT_I, Id, 0, "w", 0);
  1430. plci->State = INC_DIS_PENDING;
  1431. }
  1432. return 1;
  1433. }
  1434. }
  1435. }
  1436. if(!appl) return FALSE;
  1437. sendf(appl, _DISCONNECT_R|CONFIRM, Id, Number, "w",Info);
  1438. return FALSE;
  1439. }
  1440. byte disconnect_res(dword Id, word Number, DIVA_CAPI_ADAPTER * a, PLCI * plci, APPL * appl, API_PARSE * msg)
  1441. {
  1442. dbug(1,dprintf("disconnect_res"));
  1443. if(plci)
  1444. {
  1445. /* clear ind mask bit, just in case of collsion of */
  1446. /* DISCONNECT_IND and CONNECT_RES */
  1447. clear_c_ind_mask_bit (plci, (word)(appl->Id-1));
  1448. ncci_free_receive_buffers (plci, 0);
  1449. if(plci_remove_check(plci))
  1450. {
  1451. return 0;
  1452. }
  1453. if(plci->State==INC_DIS_PENDING
  1454. || plci->State==SUSPENDING) {
  1455. if(c_ind_mask_empty (plci)) {
  1456. if(plci->State!=SUSPENDING)plci->State = IDLE;
  1457. dbug(1,dprintf("chs=%d",plci->channels));
  1458. if(!plci->channels) {
  1459. plci_remove(plci);
  1460. }
  1461. }
  1462. }
  1463. }
  1464. return 0;
  1465. }
  1466. byte listen_req(dword Id, word Number, DIVA_CAPI_ADAPTER * a, PLCI * plci, APPL * appl, API_PARSE * parms)
  1467. {
  1468. word Info;
  1469. byte i;
  1470. dbug(1,dprintf("listen_req(Appl=0x%x)",appl->Id));
  1471. Info = _WRONG_IDENTIFIER;
  1472. if(a) {
  1473. Info = 0;
  1474. a->Info_Mask[appl->Id-1] = GET_DWORD(parms[0].info);
  1475. a->CIP_Mask[appl->Id-1] = GET_DWORD(parms[1].info);
  1476. dbug(1,dprintf("CIP_MASK=0x%lx",GET_DWORD(parms[1].info)));
  1477. if (a->Info_Mask[appl->Id-1] & 0x200){ /* early B3 connect provides */
  1478. a->Info_Mask[appl->Id-1] |= 0x10; /* call progression infos */
  1479. }
  1480. /* check if external controller listen and switch listen on or off*/
  1481. if(Id&EXT_CONTROLLER && GET_DWORD(parms[1].info)){
  1482. if(a->profile.Global_Options & ON_BOARD_CODEC) {
  1483. dummy_plci.State = IDLE;
  1484. a->codec_listen[appl->Id-1] = &dummy_plci;
  1485. a->TelOAD[0] = (byte)(parms[3].length);
  1486. for(i=1;parms[3].length>=i && i<22;i++) {
  1487. a->TelOAD[i] = parms[3].info[i];
  1488. }
  1489. a->TelOAD[i] = 0;
  1490. a->TelOSA[0] = (byte)(parms[4].length);
  1491. for(i=1;parms[4].length>=i && i<22;i++) {
  1492. a->TelOSA[i] = parms[4].info[i];
  1493. }
  1494. a->TelOSA[i] = 0;
  1495. }
  1496. else Info = 0x2002; /* wrong controller, codec not supported */
  1497. }
  1498. else{ /* clear listen */
  1499. a->codec_listen[appl->Id-1] = (PLCI *)0;
  1500. }
  1501. }
  1502. sendf(appl,
  1503. _LISTEN_R|CONFIRM,
  1504. Id,
  1505. Number,
  1506. "w",Info);
  1507. if (a) listen_check(a);
  1508. return FALSE;
  1509. }
  1510. byte info_req(dword Id, word Number, DIVA_CAPI_ADAPTER * a, PLCI * plci, APPL * appl, API_PARSE * msg)
  1511. {
  1512. word i;
  1513. API_PARSE * ai;
  1514. PLCI * rc_plci = NULL;
  1515. API_PARSE ai_parms[5];
  1516. word Info = 0;
  1517. dbug(1,dprintf("info_req"));
  1518. for(i=0;i<5;i++) ai_parms[i].length = 0;
  1519. ai = &msg[1];
  1520. if(ai->length)
  1521. {
  1522. if(api_parse(&ai->info[1],(word)ai->length,"ssss",ai_parms))
  1523. {
  1524. dbug(1,dprintf("AddInfo wrong"));
  1525. Info = _WRONG_MESSAGE_FORMAT;
  1526. }
  1527. }
  1528. if(!a) Info = _WRONG_STATE;
  1529. if(!Info && plci)
  1530. { /* no fac, with CPN, or KEY */
  1531. rc_plci = plci;
  1532. if(!ai_parms[3].length && plci->State && (msg[0].length || ai_parms[1].length) )
  1533. {
  1534. /* overlap sending option */
  1535. dbug(1,dprintf("OvlSnd"));
  1536. add_s(plci,CPN,&msg[0]);
  1537. add_s(plci,KEY,&ai_parms[1]);
  1538. sig_req(plci,INFO_REQ,0);
  1539. send_req(plci);
  1540. return FALSE;
  1541. }
  1542. if(plci->State && ai_parms[2].length)
  1543. {
  1544. /* User_Info option */
  1545. dbug(1,dprintf("UUI"));
  1546. add_s(plci,UUI,&ai_parms[2]);
  1547. sig_req(plci,USER_DATA,0);
  1548. }
  1549. else if(plci->State && ai_parms[3].length)
  1550. {
  1551. /* Facility option */
  1552. dbug(1,dprintf("FAC"));
  1553. add_s(plci,CPN,&msg[0]);
  1554. add_ai(plci, &msg[1]);
  1555. sig_req(plci,FACILITY_REQ,0);
  1556. }
  1557. else
  1558. {
  1559. Info = _WRONG_STATE;
  1560. }
  1561. }
  1562. else if((ai_parms[1].length || ai_parms[2].length || ai_parms[3].length) && !Info)
  1563. {
  1564. /* NCR_Facility option -> send UUI and Keypad too */
  1565. dbug(1,dprintf("NCR_FAC"));
  1566. if((i=get_plci(a)))
  1567. {
  1568. rc_plci = &a->plci[i-1];
  1569. appl->NullCREnable = TRUE;
  1570. rc_plci->internal_command = C_NCR_FAC_REQ;
  1571. rc_plci->appl = appl;
  1572. add_p(rc_plci,CAI,"\x01\x80");
  1573. add_p(rc_plci,UID,"\x06\x43\x61\x70\x69\x32\x30");
  1574. sig_req(rc_plci,ASSIGN,DSIG_ID);
  1575. send_req(rc_plci);
  1576. }
  1577. else
  1578. {
  1579. Info = _OUT_OF_PLCI;
  1580. }
  1581. if(!Info)
  1582. {
  1583. add_s(rc_plci,CPN,&msg[0]);
  1584. add_ai(rc_plci, &msg[1]);
  1585. sig_req(rc_plci,NCR_FACILITY,0);
  1586. send_req(rc_plci);
  1587. return FALSE;
  1588. /* for application controlled supplementary services */
  1589. }
  1590. }
  1591. if (!rc_plci)
  1592. {
  1593. Info = _WRONG_MESSAGE_FORMAT;
  1594. }
  1595. if(!Info)
  1596. {
  1597. send_req(rc_plci);
  1598. }
  1599. else
  1600. { /* appl is not assigned to a PLCI or error condition */
  1601. dbug(1,dprintf("localInfoCon"));
  1602. sendf(appl,
  1603. _INFO_R|CONFIRM,
  1604. Id,
  1605. Number,
  1606. "w",Info);
  1607. }
  1608. return FALSE;
  1609. }
  1610. byte info_res(dword Id, word Number, DIVA_CAPI_ADAPTER * a, PLCI * plci, APPL * appl, API_PARSE * msg)
  1611. {
  1612. dbug(1,dprintf("info_res"));
  1613. return FALSE;
  1614. }
  1615. byte alert_req(dword Id, word Number, DIVA_CAPI_ADAPTER * a, PLCI * plci, APPL * appl, API_PARSE * msg)
  1616. {
  1617. word Info;
  1618. byte ret;
  1619. dbug(1,dprintf("alert_req"));
  1620. Info = _WRONG_IDENTIFIER;
  1621. ret = FALSE;
  1622. if(plci) {
  1623. Info = _ALERT_IGNORED;
  1624. if(plci->State!=INC_CON_ALERT) {
  1625. Info = _WRONG_STATE;
  1626. if(plci->State==INC_CON_PENDING) {
  1627. Info = 0;
  1628. plci->State=INC_CON_ALERT;
  1629. add_ai(plci, &msg[0]);
  1630. sig_req(plci,CALL_ALERT,0);
  1631. ret = 1;
  1632. }
  1633. }
  1634. }
  1635. sendf(appl,
  1636. _ALERT_R|CONFIRM,
  1637. Id,
  1638. Number,
  1639. "w",Info);
  1640. return ret;
  1641. }
  1642. byte facility_req(dword Id, word Number, DIVA_CAPI_ADAPTER * a, PLCI * plci, APPL * appl, API_PARSE * msg)
  1643. {
  1644. word Info = 0;
  1645. word i = 0;
  1646. word selector;
  1647. word SSreq;
  1648. long relatedPLCIvalue;
  1649. DIVA_CAPI_ADAPTER * relatedadapter;
  1650. byte * SSparms = "";
  1651. byte RCparms[] = "\x05\x00\x00\x02\x00\x00";
  1652. byte SSstruct[] = "\x09\x00\x00\x06\x00\x00\x00\x00\x00\x00";
  1653. API_PARSE * parms;
  1654. API_PARSE ss_parms[11];
  1655. PLCI *rplci;
  1656. byte cai[15];
  1657. dword d;
  1658. API_PARSE dummy;
  1659. dbug(1,dprintf("facility_req"));
  1660. for(i=0;i<9;i++) ss_parms[i].length = 0;
  1661. parms = &msg[1];
  1662. if(!a)
  1663. {
  1664. dbug(1,dprintf("wrong Ctrl"));
  1665. Info = _WRONG_IDENTIFIER;
  1666. }
  1667. selector = GET_WORD(msg[0].info);
  1668. if(!Info)
  1669. {
  1670. switch(selector)
  1671. {
  1672. case SELECTOR_HANDSET:
  1673. Info = AdvCodecSupport(a, plci, appl, HOOK_SUPPORT);
  1674. break;
  1675. case SELECTOR_SU_SERV:
  1676. if(!msg[1].length)
  1677. {
  1678. Info = _WRONG_MESSAGE_FORMAT;
  1679. break;
  1680. }
  1681. SSreq = GET_WORD(&(msg[1].info[1]));
  1682. PUT_WORD(&RCparms[1],SSreq);
  1683. SSparms = RCparms;
  1684. switch(SSreq)
  1685. {
  1686. case S_GET_SUPPORTED_SERVICES:
  1687. if((i=get_plci(a)))
  1688. {
  1689. rplci = &a->plci[i-1];
  1690. rplci->appl = appl;
  1691. add_p(rplci,CAI,"\x01\x80");
  1692. add_p(rplci,UID,"\x06\x43\x61\x70\x69\x32\x30");
  1693. sig_req(rplci,ASSIGN,DSIG_ID);
  1694. send_req(rplci);
  1695. }
  1696. else
  1697. {
  1698. PUT_DWORD(&SSstruct[6], MASK_TERMINAL_PORTABILITY);
  1699. SSparms = (byte *)SSstruct;
  1700. break;
  1701. }
  1702. rplci->internal_command = GETSERV_REQ_PEND;
  1703. rplci->number = Number;
  1704. rplci->appl = appl;
  1705. sig_req(rplci,S_SUPPORTED,0);
  1706. send_req(rplci);
  1707. return FALSE;
  1708. break;
  1709. case S_LISTEN:
  1710. if(parms->length==7)
  1711. {
  1712. if(api_parse(&parms->info[1],(word)parms->length,"wbd",ss_parms))
  1713. {
  1714. dbug(1,dprintf("format wrong"));
  1715. Info = _WRONG_MESSAGE_FORMAT;
  1716. break;
  1717. }
  1718. }
  1719. else
  1720. {
  1721. Info = _WRONG_MESSAGE_FORMAT;
  1722. break;
  1723. }
  1724. a->Notification_Mask[appl->Id-1] = GET_DWORD(ss_parms[2].info);
  1725. if(a->Notification_Mask[appl->Id-1] & SMASK_MWI) /* MWI active? */
  1726. {
  1727. if((i=get_plci(a)))
  1728. {
  1729. rplci = &a->plci[i-1];
  1730. rplci->appl = appl;
  1731. add_p(rplci,CAI,"\x01\x80");
  1732. add_p(rplci,UID,"\x06\x43\x61\x70\x69\x32\x30");
  1733. sig_req(rplci,ASSIGN,DSIG_ID);
  1734. send_req(rplci);
  1735. }
  1736. else
  1737. {
  1738. break;
  1739. }
  1740. rplci->internal_command = GET_MWI_STATE;
  1741. rplci->number = Number;
  1742. sig_req(rplci,MWI_POLL,0);
  1743. send_req(rplci);
  1744. }
  1745. break;
  1746. case S_HOLD:
  1747. api_parse(&parms->info[1],(word)parms->length,"ws",ss_parms);
  1748. if(plci && plci->State && plci->SuppState==IDLE)
  1749. {
  1750. plci->SuppState = HOLD_REQUEST;
  1751. plci->command = C_HOLD_REQ;
  1752. add_s(plci,CAI,&ss_parms[1]);
  1753. sig_req(plci,CALL_HOLD,0);
  1754. send_req(plci);
  1755. return FALSE;
  1756. }
  1757. else Info = 0x3010; /* wrong state */
  1758. break;
  1759. case S_RETRIEVE:
  1760. if(plci && plci->State && plci->SuppState==CALL_HELD)
  1761. {
  1762. if(Id & EXT_CONTROLLER)
  1763. {
  1764. if(AdvCodecSupport(a, plci, appl, 0))
  1765. {
  1766. Info = 0x3010; /* wrong state */
  1767. break;
  1768. }
  1769. }
  1770. else plci->tel = 0;
  1771. plci->SuppState = RETRIEVE_REQUEST;
  1772. plci->command = C_RETRIEVE_REQ;
  1773. if(plci->spoofed_msg==SPOOFING_REQUIRED)
  1774. {
  1775. plci->spoofed_msg = CALL_RETRIEVE;
  1776. plci->internal_command = BLOCK_PLCI;
  1777. plci->command = 0;
  1778. dbug(1,dprintf("Spoof"));
  1779. return FALSE;
  1780. }
  1781. else
  1782. {
  1783. sig_req(plci,CALL_RETRIEVE,0);
  1784. send_req(plci);
  1785. return FALSE;
  1786. }
  1787. }
  1788. else Info = 0x3010; /* wrong state */
  1789. break;
  1790. case S_SUSPEND:
  1791. if(parms->length)
  1792. {
  1793. if(api_parse(&parms->info[1],(word)parms->length,"wbs",ss_parms))
  1794. {
  1795. dbug(1,dprintf("format wrong"));
  1796. Info = _WRONG_MESSAGE_FORMAT;
  1797. break;
  1798. }
  1799. }
  1800. if(plci && plci->State)
  1801. {
  1802. add_s(plci,CAI,&ss_parms[2]);
  1803. plci->command = SUSPEND_REQ;
  1804. sig_req(plci,SUSPEND,0);
  1805. plci->State = SUSPENDING;
  1806. send_req(plci);
  1807. }
  1808. else Info = 0x3010; /* wrong state */
  1809. break;
  1810. case S_RESUME:
  1811. if(!(i=get_plci(a)) )
  1812. {
  1813. Info = _OUT_OF_PLCI;
  1814. break;
  1815. }
  1816. rplci = &a->plci[i-1];
  1817. rplci->appl = appl;
  1818. rplci->number = Number;
  1819. rplci->tel = 0;
  1820. rplci->call_dir = CALL_DIR_OUT | CALL_DIR_ORIGINATE;
  1821. /* check 'external controller' bit for codec support */
  1822. if(Id & EXT_CONTROLLER)
  1823. {
  1824. if(AdvCodecSupport(a, rplci, appl, 0) )
  1825. {
  1826. rplci->Id = 0;
  1827. Info = 0x300A;
  1828. break;
  1829. }
  1830. }
  1831. if(parms->length)
  1832. {
  1833. if(api_parse(&parms->info[1],(word)parms->length,"wbs",ss_parms))
  1834. {
  1835. dbug(1,dprintf("format wrong"));
  1836. rplci->Id = 0;
  1837. Info = _WRONG_MESSAGE_FORMAT;
  1838. break;
  1839. }
  1840. }
  1841. dummy.length = 0;
  1842. dummy.info = "\x00";
  1843. add_b1(rplci, &dummy, 0, 0);
  1844. if (a->Info_Mask[appl->Id-1] & 0x200)
  1845. {
  1846. /* early B3 connect (CIP mask bit 9) no release after a disc */
  1847. add_p(rplci,LLI,"\x01\x01");
  1848. }
  1849. add_p(rplci,UID,"\x06\x43\x61\x70\x69\x32\x30");
  1850. sig_req(rplci,ASSIGN,DSIG_ID);
  1851. send_req(rplci);
  1852. add_s(rplci,CAI,&ss_parms[2]);
  1853. rplci->command = RESUME_REQ;
  1854. sig_req(rplci,RESUME,0);
  1855. rplci->State = RESUMING;
  1856. send_req(rplci);
  1857. break;
  1858. case S_CONF_BEGIN: /* Request */
  1859. case S_CONF_DROP:
  1860. case S_CONF_ISOLATE:
  1861. case S_CONF_REATTACH:
  1862. if(api_parse(&parms->info[1],(word)parms->length,"wbd",ss_parms))
  1863. {
  1864. dbug(1,dprintf("format wrong"));
  1865. Info = _WRONG_MESSAGE_FORMAT;
  1866. break;
  1867. }
  1868. if(plci && plci->State && ((plci->SuppState==IDLE)||(plci->SuppState==CALL_HELD)))
  1869. {
  1870. d = GET_DWORD(ss_parms[2].info);
  1871. if(d>=0x80)
  1872. {
  1873. dbug(1,dprintf("format wrong"));
  1874. Info = _WRONG_MESSAGE_FORMAT;
  1875. break;
  1876. }
  1877. plci->ptyState = (byte)SSreq;
  1878. plci->command = 0;
  1879. cai[0] = 2;
  1880. switch(SSreq)
  1881. {
  1882. case S_CONF_BEGIN:
  1883. cai[1] = CONF_BEGIN;
  1884. plci->internal_command = CONF_BEGIN_REQ_PEND;
  1885. break;
  1886. case S_CONF_DROP:
  1887. cai[1] = CONF_DROP;
  1888. plci->internal_command = CONF_DROP_REQ_PEND;
  1889. break;
  1890. case S_CONF_ISOLATE:
  1891. cai[1] = CONF_ISOLATE;
  1892. plci->internal_command = CONF_ISOLATE_REQ_PEND;
  1893. break;
  1894. case S_CONF_REATTACH:
  1895. cai[1] = CONF_REATTACH;
  1896. plci->internal_command = CONF_REATTACH_REQ_PEND;
  1897. break;
  1898. }
  1899. cai[2] = (byte)d; /* Conference Size resp. PartyId */
  1900. add_p(plci,CAI,cai);
  1901. sig_req(plci,S_SERVICE,0);
  1902. send_req(plci);
  1903. return FALSE;
  1904. }
  1905. else Info = 0x3010; /* wrong state */
  1906. break;
  1907. case S_ECT:
  1908. case S_3PTY_BEGIN:
  1909. case S_3PTY_END:
  1910. case S_CONF_ADD:
  1911. if(parms->length==7)
  1912. {
  1913. if(api_parse(&parms->info[1],(word)parms->length,"wbd",ss_parms))
  1914. {
  1915. dbug(1,dprintf("format wrong"));
  1916. Info = _WRONG_MESSAGE_FORMAT;
  1917. break;
  1918. }
  1919. }
  1920. else if(parms->length==8) /* workaround for the T-View-S */
  1921. {
  1922. if(api_parse(&parms->info[1],(word)parms->length,"wbdb",ss_parms))
  1923. {
  1924. dbug(1,dprintf("format wrong"));
  1925. Info = _WRONG_MESSAGE_FORMAT;
  1926. break;
  1927. }
  1928. }
  1929. else
  1930. {
  1931. Info = _WRONG_MESSAGE_FORMAT;
  1932. break;
  1933. }
  1934. if(!msg[1].length)
  1935. {
  1936. Info = _WRONG_MESSAGE_FORMAT;
  1937. break;
  1938. }
  1939. if (!plci)
  1940. {
  1941. Info = _WRONG_IDENTIFIER;
  1942. break;
  1943. }
  1944. relatedPLCIvalue = GET_DWORD(ss_parms[2].info);
  1945. relatedPLCIvalue &= 0x0000FFFF;
  1946. dbug(1,dprintf("PTY/ECT/addCONF,relPLCI=%lx",relatedPLCIvalue));
  1947. /* controller starts with 0 up to (max_adapter - 1) */
  1948. if (((relatedPLCIvalue & 0x7f) == 0)
  1949. || (MapController ((byte)(relatedPLCIvalue & 0x7f)) == 0)
  1950. || (MapController ((byte)(relatedPLCIvalue & 0x7f)) > max_adapter))
  1951. {
  1952. if(SSreq==S_3PTY_END)
  1953. {
  1954. dbug(1, dprintf("wrong Controller use 2nd PLCI=PLCI"));
  1955. rplci = plci;
  1956. }
  1957. else
  1958. {
  1959. Info = 0x3010; /* wrong state */
  1960. break;
  1961. }
  1962. }
  1963. else
  1964. {
  1965. relatedadapter = &adapter[MapController ((byte)(relatedPLCIvalue & 0x7f))-1];
  1966. relatedPLCIvalue >>=8;
  1967. /* find PLCI PTR*/
  1968. for(i=0,rplci=NULL;i<relatedadapter->max_plci;i++)
  1969. {
  1970. if(relatedadapter->plci[i].Id == (byte)relatedPLCIvalue)
  1971. {
  1972. rplci = &relatedadapter->plci[i];
  1973. }
  1974. }
  1975. if(!rplci || !relatedPLCIvalue)
  1976. {
  1977. if(SSreq==S_3PTY_END)
  1978. {
  1979. dbug(1, dprintf("use 2nd PLCI=PLCI"));
  1980. rplci = plci;
  1981. }
  1982. else
  1983. {
  1984. Info = 0x3010; /* wrong state */
  1985. break;
  1986. }
  1987. }
  1988. }
  1989. /*
  1990. dbug(1,dprintf("rplci:%x",rplci));
  1991. dbug(1,dprintf("plci:%x",plci));
  1992. dbug(1,dprintf("rplci->ptyState:%x",rplci->ptyState));
  1993. dbug(1,dprintf("plci->ptyState:%x",plci->ptyState));
  1994. dbug(1,dprintf("SSreq:%x",SSreq));
  1995. dbug(1,dprintf("rplci->internal_command:%x",rplci->internal_command));
  1996. dbug(1,dprintf("rplci->appl:%x",rplci->appl));
  1997. dbug(1,dprintf("rplci->Id:%x",rplci->Id));
  1998. */
  1999. /* send PTY/ECT req, cannot check all states because of US stuff */
  2000. if( !rplci->internal_command && rplci->appl )
  2001. {
  2002. plci->command = 0;
  2003. rplci->relatedPTYPLCI = plci;
  2004. plci->relatedPTYPLCI = rplci;
  2005. rplci->ptyState = (byte)SSreq;
  2006. if(SSreq==S_ECT)
  2007. {
  2008. rplci->internal_command = ECT_REQ_PEND;
  2009. cai[1] = ECT_EXECUTE;
  2010. rplci->vswitchstate=0;
  2011. rplci->vsprot=0;
  2012. rplci->vsprotdialect=0;
  2013. plci->vswitchstate=0;
  2014. plci->vsprot=0;
  2015. plci->vsprotdialect=0;
  2016. }
  2017. else if(SSreq==S_CONF_ADD)
  2018. {
  2019. rplci->internal_command = CONF_ADD_REQ_PEND;
  2020. cai[1] = CONF_ADD;
  2021. }
  2022. else
  2023. {
  2024. rplci->internal_command = PTY_REQ_PEND;
  2025. cai[1] = (byte)(SSreq-3);
  2026. }
  2027. rplci->number = Number;
  2028. if(plci!=rplci) /* explicit invocation */
  2029. {
  2030. cai[0] = 2;
  2031. cai[2] = plci->Sig.Id;
  2032. dbug(1,dprintf("explicit invocation"));
  2033. }
  2034. else
  2035. {
  2036. dbug(1,dprintf("implicit invocation"));
  2037. cai[0] = 1;
  2038. }
  2039. add_p(rplci,CAI,cai);
  2040. sig_req(rplci,S_SERVICE,0);
  2041. send_req(rplci);
  2042. return FALSE;
  2043. }
  2044. else
  2045. {
  2046. dbug(0,dprintf("Wrong line"));
  2047. Info = 0x3010; /* wrong state */
  2048. break;
  2049. }
  2050. break;
  2051. case S_CALL_DEFLECTION:
  2052. if(api_parse(&parms->info[1],(word)parms->length,"wbwss",ss_parms))
  2053. {
  2054. dbug(1,dprintf("format wrong"));
  2055. Info = _WRONG_MESSAGE_FORMAT;
  2056. break;
  2057. }
  2058. if (!plci)
  2059. {
  2060. Info = _WRONG_IDENTIFIER;
  2061. break;
  2062. }
  2063. /* reuse unused screening indicator */
  2064. ss_parms[3].info[3] = (byte)GET_WORD(&(ss_parms[2].info[0]));
  2065. plci->command = 0;
  2066. plci->internal_command = CD_REQ_PEND;
  2067. appl->CDEnable = TRUE;
  2068. cai[0] = 1;
  2069. cai[1] = CALL_DEFLECTION;
  2070. add_p(plci,CAI,cai);
  2071. add_p(plci,CPN,ss_parms[3].info);
  2072. sig_req(plci,S_SERVICE,0);
  2073. send_req(plci);
  2074. return FALSE;
  2075. break;
  2076. case S_CALL_FORWARDING_START:
  2077. if(api_parse(&parms->info[1],(word)parms->length,"wbdwwsss",ss_parms))
  2078. {
  2079. dbug(1,dprintf("format wrong"));
  2080. Info = _WRONG_MESSAGE_FORMAT;
  2081. break;
  2082. }
  2083. if((i=get_plci(a)))
  2084. {
  2085. rplci = &a->plci[i-1];
  2086. rplci->appl = appl;
  2087. add_p(rplci,CAI,"\x01\x80");
  2088. add_p(rplci,UID,"\x06\x43\x61\x70\x69\x32\x30");
  2089. sig_req(rplci,ASSIGN,DSIG_ID);
  2090. send_req(rplci);
  2091. }
  2092. else
  2093. {
  2094. Info = _OUT_OF_PLCI;
  2095. break;
  2096. }
  2097. /* reuse unused screening indicator */
  2098. rplci->internal_command = CF_START_PEND;
  2099. rplci->appl = appl;
  2100. rplci->number = Number;
  2101. appl->S_Handle = GET_DWORD(&(ss_parms[2].info[0]));
  2102. cai[0] = 2;
  2103. cai[1] = 0x70|(byte)GET_WORD(&(ss_parms[3].info[0])); /* Function */
  2104. cai[2] = (byte)GET_WORD(&(ss_parms[4].info[0])); /* Basic Service */
  2105. add_p(rplci,CAI,cai);
  2106. add_p(rplci,OAD,ss_parms[5].info);
  2107. add_p(rplci,CPN,ss_parms[6].info);
  2108. sig_req(rplci,S_SERVICE,0);
  2109. send_req(rplci);
  2110. return FALSE;
  2111. break;
  2112. case S_INTERROGATE_DIVERSION:
  2113. case S_INTERROGATE_NUMBERS:
  2114. case S_CALL_FORWARDING_STOP:
  2115. case S_CCBS_REQUEST:
  2116. case S_CCBS_DEACTIVATE:
  2117. case S_CCBS_INTERROGATE:
  2118. switch(SSreq)
  2119. {
  2120. case S_INTERROGATE_NUMBERS:
  2121. if(api_parse(&parms->info[1],(word)parms->length,"wbd",ss_parms))
  2122. {
  2123. dbug(0,dprintf("format wrong"));
  2124. Info = _WRONG_MESSAGE_FORMAT;
  2125. }
  2126. break;
  2127. case S_CCBS_REQUEST:
  2128. case S_CCBS_DEACTIVATE:
  2129. if(api_parse(&parms->info[1],(word)parms->length,"wbdw",ss_parms))
  2130. {
  2131. dbug(0,dprintf("format wrong"));
  2132. Info = _WRONG_MESSAGE_FORMAT;
  2133. }
  2134. break;
  2135. case S_CCBS_INTERROGATE:
  2136. if(api_parse(&parms->info[1],(word)parms->length,"wbdws",ss_parms))
  2137. {
  2138. dbug(0,dprintf("format wrong"));
  2139. Info = _WRONG_MESSAGE_FORMAT;
  2140. }
  2141. break;
  2142. default:
  2143. if(api_parse(&parms->info[1],(word)parms->length,"wbdwws",ss_parms))
  2144. {
  2145. dbug(0,dprintf("format wrong"));
  2146. Info = _WRONG_MESSAGE_FORMAT;
  2147. break;
  2148. }
  2149. break;
  2150. }
  2151. if(Info) break;
  2152. if((i=get_plci(a)))
  2153. {
  2154. rplci = &a->plci[i-1];
  2155. switch(SSreq)
  2156. {
  2157. case S_INTERROGATE_DIVERSION: /* use cai with S_SERVICE below */
  2158. cai[1] = 0x60|(byte)GET_WORD(&(ss_parms[3].info[0])); /* Function */
  2159. rplci->internal_command = INTERR_DIVERSION_REQ_PEND; /* move to rplci if assigned */
  2160. break;
  2161. case S_INTERROGATE_NUMBERS: /* use cai with S_SERVICE below */
  2162. cai[1] = DIVERSION_INTERROGATE_NUM; /* Function */
  2163. rplci->internal_command = INTERR_NUMBERS_REQ_PEND; /* move to rplci if assigned */
  2164. break;
  2165. case S_CALL_FORWARDING_STOP:
  2166. rplci->internal_command = CF_STOP_PEND;
  2167. cai[1] = 0x80|(byte)GET_WORD(&(ss_parms[3].info[0])); /* Function */
  2168. break;
  2169. case S_CCBS_REQUEST:
  2170. cai[1] = CCBS_REQUEST;
  2171. rplci->internal_command = CCBS_REQUEST_REQ_PEND;
  2172. break;
  2173. case S_CCBS_DEACTIVATE:
  2174. cai[1] = CCBS_DEACTIVATE;
  2175. rplci->internal_command = CCBS_DEACTIVATE_REQ_PEND;
  2176. break;
  2177. case S_CCBS_INTERROGATE:
  2178. cai[1] = CCBS_INTERROGATE;
  2179. rplci->internal_command = CCBS_INTERROGATE_REQ_PEND;
  2180. break;
  2181. default:
  2182. cai[1] = 0;
  2183. break;
  2184. }
  2185. rplci->appl = appl;
  2186. rplci->number = Number;
  2187. add_p(rplci,CAI,"\x01\x80");
  2188. add_p(rplci,UID,"\x06\x43\x61\x70\x69\x32\x30");
  2189. sig_req(rplci,ASSIGN,DSIG_ID);
  2190. send_req(rplci);
  2191. }
  2192. else
  2193. {
  2194. Info = _OUT_OF_PLCI;
  2195. break;
  2196. }
  2197. appl->S_Handle = GET_DWORD(&(ss_parms[2].info[0]));
  2198. switch(SSreq)
  2199. {
  2200. case S_INTERROGATE_NUMBERS:
  2201. cai[0] = 1;
  2202. add_p(rplci,CAI,cai);
  2203. break;
  2204. case S_CCBS_REQUEST:
  2205. case S_CCBS_DEACTIVATE:
  2206. cai[0] = 3;
  2207. PUT_WORD(&cai[2],GET_WORD(&(ss_parms[3].info[0])));
  2208. add_p(rplci,CAI,cai);
  2209. break;
  2210. case S_CCBS_INTERROGATE:
  2211. cai[0] = 3;
  2212. PUT_WORD(&cai[2],GET_WORD(&(ss_parms[3].info[0])));
  2213. add_p(rplci,CAI,cai);
  2214. add_p(rplci,OAD,ss_parms[4].info);
  2215. break;
  2216. default:
  2217. cai[0] = 2;
  2218. cai[2] = (byte)GET_WORD(&(ss_parms[4].info[0])); /* Basic Service */
  2219. add_p(rplci,CAI,cai);
  2220. add_p(rplci,OAD,ss_parms[5].info);
  2221. break;
  2222. }
  2223. sig_req(rplci,S_SERVICE,0);
  2224. send_req(rplci);
  2225. return FALSE;
  2226. break;
  2227. case S_MWI_ACTIVATE:
  2228. if(api_parse(&parms->info[1],(word)parms->length,"wbwdwwwssss",ss_parms))
  2229. {
  2230. dbug(1,dprintf("format wrong"));
  2231. Info = _WRONG_MESSAGE_FORMAT;
  2232. break;
  2233. }
  2234. if(!plci)
  2235. {
  2236. if((i=get_plci(a)))
  2237. {
  2238. rplci = &a->plci[i-1];
  2239. rplci->appl = appl;
  2240. rplci->cr_enquiry=TRUE;
  2241. add_p(rplci,CAI,"\x01\x80");
  2242. add_p(rplci,UID,"\x06\x43\x61\x70\x69\x32\x30");
  2243. sig_req(rplci,ASSIGN,DSIG_ID);
  2244. send_req(rplci);
  2245. }
  2246. else
  2247. {
  2248. Info = _OUT_OF_PLCI;
  2249. break;
  2250. }
  2251. }
  2252. else
  2253. {
  2254. rplci = plci;
  2255. rplci->cr_enquiry=FALSE;
  2256. }
  2257. rplci->command = 0;
  2258. rplci->internal_command = MWI_ACTIVATE_REQ_PEND;
  2259. rplci->appl = appl;
  2260. rplci->number = Number;
  2261. cai[0] = 13;
  2262. cai[1] = ACTIVATION_MWI; /* Function */
  2263. PUT_WORD(&cai[2],GET_WORD(&(ss_parms[2].info[0]))); /* Basic Service */
  2264. PUT_DWORD(&cai[4],GET_DWORD(&(ss_parms[3].info[0]))); /* Number of Messages */
  2265. PUT_WORD(&cai[8],GET_WORD(&(ss_parms[4].info[0]))); /* Message Status */
  2266. PUT_WORD(&cai[10],GET_WORD(&(ss_parms[5].info[0]))); /* Message Reference */
  2267. PUT_WORD(&cai[12],GET_WORD(&(ss_parms[6].info[0]))); /* Invocation Mode */
  2268. add_p(rplci,CAI,cai);
  2269. add_p(rplci,CPN,ss_parms[7].info); /* Receiving User Number */
  2270. add_p(rplci,OAD,ss_parms[8].info); /* Controlling User Number */
  2271. add_p(rplci,OSA,ss_parms[9].info); /* Controlling User Provided Number */
  2272. add_p(rplci,UID,ss_parms[10].info); /* Time */
  2273. sig_req(rplci,S_SERVICE,0);
  2274. send_req(rplci);
  2275. return FALSE;
  2276. case S_MWI_DEACTIVATE:
  2277. if(api_parse(&parms->info[1],(word)parms->length,"wbwwss",ss_parms))
  2278. {
  2279. dbug(1,dprintf("format wrong"));
  2280. Info = _WRONG_MESSAGE_FORMAT;
  2281. break;
  2282. }
  2283. if(!plci)
  2284. {
  2285. if((i=get_plci(a)))
  2286. {
  2287. rplci = &a->plci[i-1];
  2288. rplci->appl = appl;
  2289. rplci->cr_enquiry=TRUE;
  2290. add_p(rplci,CAI,"\x01\x80");
  2291. add_p(rplci,UID,"\x06\x43\x61\x70\x69\x32\x30");
  2292. sig_req(rplci,ASSIGN,DSIG_ID);
  2293. send_req(rplci);
  2294. }
  2295. else
  2296. {
  2297. Info = _OUT_OF_PLCI;
  2298. break;
  2299. }
  2300. }
  2301. else
  2302. {
  2303. rplci = plci;
  2304. rplci->cr_enquiry=FALSE;
  2305. }
  2306. rplci->command = 0;
  2307. rplci->internal_command = MWI_DEACTIVATE_REQ_PEND;
  2308. rplci->appl = appl;
  2309. rplci->number = Number;
  2310. cai[0] = 5;
  2311. cai[1] = DEACTIVATION_MWI; /* Function */
  2312. PUT_WORD(&cai[2],GET_WORD(&(ss_parms[2].info[0]))); /* Basic Service */
  2313. PUT_WORD(&cai[4],GET_WORD(&(ss_parms[3].info[0]))); /* Invocation Mode */
  2314. add_p(rplci,CAI,cai);
  2315. add_p(rplci,CPN,ss_parms[4].info); /* Receiving User Number */
  2316. add_p(rplci,OAD,ss_parms[5].info); /* Controlling User Number */
  2317. sig_req(rplci,S_SERVICE,0);
  2318. send_req(rplci);
  2319. return FALSE;
  2320. default:
  2321. Info = 0x300E; /* not supported */
  2322. break;
  2323. }
  2324. break; /* case SELECTOR_SU_SERV: end */
  2325. case SELECTOR_DTMF:
  2326. return (dtmf_request (Id, Number, a, plci, appl, msg));
  2327. case SELECTOR_LINE_INTERCONNECT:
  2328. return (mixer_request (Id, Number, a, plci, appl, msg));
  2329. case PRIV_SELECTOR_ECHO_CANCELLER:
  2330. appl->appl_flags |= APPL_FLAG_PRIV_EC_SPEC;
  2331. return (ec_request (Id, Number, a, plci, appl, msg));
  2332. case SELECTOR_ECHO_CANCELLER:
  2333. appl->appl_flags &= ~APPL_FLAG_PRIV_EC_SPEC;
  2334. return (ec_request (Id, Number, a, plci, appl, msg));
  2335. case SELECTOR_V42BIS:
  2336. default:
  2337. Info = _FACILITY_NOT_SUPPORTED;
  2338. break;
  2339. } /* end of switch(selector) */
  2340. }
  2341. dbug(1,dprintf("SendFacRc"));
  2342. sendf(appl,
  2343. _FACILITY_R|CONFIRM,
  2344. Id,
  2345. Number,
  2346. "wws",Info,selector,SSparms);
  2347. return FALSE;
  2348. }
  2349. byte facility_res(dword Id, word Number, DIVA_CAPI_ADAPTER * a, PLCI * plci, APPL * appl, API_PARSE * msg)
  2350. {
  2351. dbug(1,dprintf("facility_res"));
  2352. return FALSE;
  2353. }
  2354. byte connect_b3_req(dword Id, word Number, DIVA_CAPI_ADAPTER * a, PLCI * plci, APPL * appl, API_PARSE * parms)
  2355. {
  2356. word Info = 0;
  2357. byte req;
  2358. byte len;
  2359. word w;
  2360. word fax_control_bits, fax_feature_bits, fax_info_change;
  2361. API_PARSE * ncpi;
  2362. byte pvc[2];
  2363. API_PARSE fax_parms[9];
  2364. word i;
  2365. dbug(1,dprintf("connect_b3_req"));
  2366. if(plci)
  2367. {
  2368. if ((plci->State == IDLE) || (plci->State == OUTG_DIS_PENDING)
  2369. || (plci->State == INC_DIS_PENDING) || (plci->SuppState != IDLE))
  2370. {
  2371. Info = _WRONG_STATE;
  2372. }
  2373. else
  2374. {
  2375. /* local reply if assign unsuccessfull
  2376. or B3 protocol allows only one layer 3 connection
  2377. and already connected
  2378. or B2 protocol not any LAPD
  2379. and connect_b3_req contradicts originate/answer direction */
  2380. if (!plci->NL.Id
  2381. || (((plci->B3_prot != B3_T90NL) && (plci->B3_prot != B3_ISO8208) && (plci->B3_prot != B3_X25_DCE))
  2382. && ((plci->channels != 0)
  2383. || (((plci->B2_prot != B2_SDLC) && (plci->B2_prot != B2_LAPD) && (plci->B2_prot != B2_LAPD_FREE_SAPI_SEL))
  2384. && ((plci->call_dir & CALL_DIR_ANSWER) && !(plci->call_dir & CALL_DIR_FORCE_OUTG_NL))))))
  2385. {
  2386. dbug(1,dprintf("B3 already connected=%d or no NL.Id=0x%x, dir=%d sstate=0x%x",
  2387. plci->channels,plci->NL.Id,plci->call_dir,plci->SuppState));
  2388. Info = _WRONG_STATE;
  2389. sendf(appl,
  2390. _CONNECT_B3_R|CONFIRM,
  2391. Id,
  2392. Number,
  2393. "w",Info);
  2394. return FALSE;
  2395. }
  2396. plci->requested_options_conn = 0;
  2397. req = N_CONNECT;
  2398. ncpi = &parms[0];
  2399. if(plci->B3_prot==2 || plci->B3_prot==3)
  2400. {
  2401. if(ncpi->length>2)
  2402. {
  2403. /* check for PVC */
  2404. if(ncpi->info[2] || ncpi->info[3])
  2405. {
  2406. pvc[0] = ncpi->info[3];
  2407. pvc[1] = ncpi->info[2];
  2408. add_d(plci,2,pvc);
  2409. req = N_RESET;
  2410. }
  2411. else
  2412. {
  2413. if(ncpi->info[1] &1) req = N_CONNECT | N_D_BIT;
  2414. add_d(plci,(word)(ncpi->length-3),&ncpi->info[4]);
  2415. }
  2416. }
  2417. }
  2418. else if(plci->B3_prot==5)
  2419. {
  2420. if (plci->NL.Id && !plci->nl_remove_id)
  2421. {
  2422. fax_control_bits = GET_WORD(&((T30_INFO *)plci->fax_connect_info_buffer)->control_bits_low);
  2423. fax_feature_bits = GET_WORD(&((T30_INFO *)plci->fax_connect_info_buffer)->feature_bits_low);
  2424. if (!(fax_control_bits & T30_CONTROL_BIT_MORE_DOCUMENTS)
  2425. || (fax_feature_bits & T30_FEATURE_BIT_MORE_DOCUMENTS))
  2426. {
  2427. len = (byte)(&(((T30_INFO *) 0)->universal_6));
  2428. fax_info_change = FALSE;
  2429. if (ncpi->length >= 4)
  2430. {
  2431. w = GET_WORD(&ncpi->info[3]);
  2432. if ((w & 0x0001) != ((word)(((T30_INFO *)(plci->fax_connect_info_buffer))->resolution & 0x0001)))
  2433. {
  2434. ((T30_INFO *)(plci->fax_connect_info_buffer))->resolution =
  2435. (byte)((((T30_INFO *)(plci->fax_connect_info_buffer))->resolution & ~T30_RESOLUTION_R8_0770_OR_200) |
  2436. ((w & 0x0001) ? T30_RESOLUTION_R8_0770_OR_200 : 0));
  2437. fax_info_change = TRUE;
  2438. }
  2439. fax_control_bits &= ~(T30_CONTROL_BIT_REQUEST_POLLING | T30_CONTROL_BIT_MORE_DOCUMENTS);
  2440. if (w & 0x0002) /* Fax-polling request */
  2441. fax_control_bits |= T30_CONTROL_BIT_REQUEST_POLLING;
  2442. if ((w & 0x0004) /* Request to send / poll another document */
  2443. && (a->manufacturer_features & MANUFACTURER_FEATURE_FAX_MORE_DOCUMENTS))
  2444. {
  2445. fax_control_bits |= T30_CONTROL_BIT_MORE_DOCUMENTS;
  2446. }
  2447. if (ncpi->length >= 6)
  2448. {
  2449. w = GET_WORD(&ncpi->info[5]);
  2450. if (((byte) w) != ((T30_INFO *)(plci->fax_connect_info_buffer))->data_format)
  2451. {
  2452. ((T30_INFO *)(plci->fax_connect_info_buffer))->data_format = (byte) w;
  2453. fax_info_change = TRUE;
  2454. }
  2455. if ((a->man_profile.private_options & (1L << PRIVATE_FAX_SUB_SEP_PWD))
  2456. && (GET_WORD(&ncpi->info[5]) & 0x8000)) /* Private SEP/SUB/PWD enable */
  2457. {
  2458. plci->requested_options_conn |= (1L << PRIVATE_FAX_SUB_SEP_PWD);
  2459. }
  2460. if ((a->man_profile.private_options & (1L << PRIVATE_FAX_NONSTANDARD))
  2461. && (GET_WORD(&ncpi->info[5]) & 0x4000)) /* Private non-standard facilities enable */
  2462. {
  2463. plci->requested_options_conn |= (1L << PRIVATE_FAX_NONSTANDARD);
  2464. }
  2465. fax_control_bits &= ~(T30_CONTROL_BIT_ACCEPT_SUBADDRESS | T30_CONTROL_BIT_ACCEPT_SEL_POLLING |
  2466. T30_CONTROL_BIT_ACCEPT_PASSWORD);
  2467. if ((plci->requested_options_conn | plci->requested_options | a->requested_options_table[appl->Id-1])
  2468. & ((1L << PRIVATE_FAX_SUB_SEP_PWD) | (1L << PRIVATE_FAX_NONSTANDARD)))
  2469. {
  2470. if (api_parse (&ncpi->info[1], ncpi->length, "wwwwsss", fax_parms))
  2471. Info = _WRONG_MESSAGE_FORMAT;
  2472. else
  2473. {
  2474. if ((plci->requested_options_conn | plci->requested_options | a->requested_options_table[appl->Id-1])
  2475. & (1L << PRIVATE_FAX_SUB_SEP_PWD))
  2476. {
  2477. fax_control_bits |= T30_CONTROL_BIT_ACCEPT_SUBADDRESS | T30_CONTROL_BIT_ACCEPT_PASSWORD;
  2478. if (fax_control_bits & T30_CONTROL_BIT_ACCEPT_POLLING)
  2479. fax_control_bits |= T30_CONTROL_BIT_ACCEPT_SEL_POLLING;
  2480. }
  2481. w = fax_parms[4].length;
  2482. if (w > 20)
  2483. w = 20;
  2484. ((T30_INFO *)(plci->fax_connect_info_buffer))->station_id_len = (byte) w;
  2485. for (i = 0; i < w; i++)
  2486. ((T30_INFO *)(plci->fax_connect_info_buffer))->station_id[i] = fax_parms[4].info[1+i];
  2487. ((T30_INFO *)(plci->fax_connect_info_buffer))->head_line_len = 0;
  2488. len = (byte)(((T30_INFO *) 0)->station_id + 20);
  2489. w = fax_parms[5].length;
  2490. if (w > 20)
  2491. w = 20;
  2492. plci->fax_connect_info_buffer[len++] = (byte) w;
  2493. for (i = 0; i < w; i++)
  2494. plci->fax_connect_info_buffer[len++] = fax_parms[5].info[1+i];
  2495. w = fax_parms[6].length;
  2496. if (w > 20)
  2497. w = 20;
  2498. plci->fax_connect_info_buffer[len++] = (byte) w;
  2499. for (i = 0; i < w; i++)
  2500. plci->fax_connect_info_buffer[len++] = fax_parms[6].info[1+i];
  2501. if ((plci->requested_options_conn | plci->requested_options | a->requested_options_table[appl->Id-1])
  2502. & (1L << PRIVATE_FAX_NONSTANDARD))
  2503. {
  2504. if (api_parse (&ncpi->info[1], ncpi->length, "wwwwssss", fax_parms))
  2505. {
  2506. dbug(1,dprintf("non-standard facilities info missing or wrong format"));
  2507. plci->fax_connect_info_buffer[len++] = 0;
  2508. }
  2509. else
  2510. {
  2511. if ((fax_parms[7].length >= 3) && (fax_parms[7].info[1] >= 2))
  2512. plci->nsf_control_bits = GET_WORD(&fax_parms[7].info[2]);
  2513. plci->fax_connect_info_buffer[len++] = (byte)(fax_parms[7].length);
  2514. for (i = 0; i < fax_parms[7].length; i++)
  2515. plci->fax_connect_info_buffer[len++] = fax_parms[7].info[1+i];
  2516. }
  2517. }
  2518. }
  2519. }
  2520. else
  2521. {
  2522. len = (byte)(&(((T30_INFO *) 0)->universal_6));
  2523. }
  2524. fax_info_change = TRUE;
  2525. }
  2526. if (fax_control_bits != GET_WORD(&((T30_INFO *)plci->fax_connect_info_buffer)->control_bits_low))
  2527. {
  2528. PUT_WORD (&((T30_INFO *)plci->fax_connect_info_buffer)->control_bits_low, fax_control_bits);
  2529. fax_info_change = TRUE;
  2530. }
  2531. }
  2532. if (Info == GOOD)
  2533. {
  2534. plci->fax_connect_info_length = len;
  2535. if (fax_info_change)
  2536. {
  2537. if (fax_feature_bits & T30_FEATURE_BIT_MORE_DOCUMENTS)
  2538. {
  2539. start_internal_command (Id, plci, fax_connect_info_command);
  2540. return FALSE;
  2541. }
  2542. else
  2543. {
  2544. start_internal_command (Id, plci, fax_adjust_b23_command);
  2545. return FALSE;
  2546. }
  2547. }
  2548. }
  2549. }
  2550. else Info = _WRONG_STATE;
  2551. }
  2552. else Info = _WRONG_STATE;
  2553. }
  2554. else if (plci->B3_prot == B3_RTP)
  2555. {
  2556. plci->internal_req_buffer[0] = ncpi->length + 1;
  2557. plci->internal_req_buffer[1] = UDATA_REQUEST_RTP_RECONFIGURE;
  2558. for (w = 0; w < ncpi->length; w++)
  2559. plci->internal_req_buffer[2+w] = ncpi->info[1+w];
  2560. start_internal_command (Id, plci, rtp_connect_b3_req_command);
  2561. return FALSE;
  2562. }
  2563. if(!Info)
  2564. {
  2565. nl_req_ncci(plci,req,0);
  2566. return 1;
  2567. }
  2568. }
  2569. }
  2570. else Info = _WRONG_IDENTIFIER;
  2571. sendf(appl,
  2572. _CONNECT_B3_R|CONFIRM,
  2573. Id,
  2574. Number,
  2575. "w",Info);
  2576. return FALSE;
  2577. }
  2578. byte connect_b3_res(dword Id, word Number, DIVA_CAPI_ADAPTER * a, PLCI * plci, APPL * appl, API_PARSE * parms)
  2579. {
  2580. word ncci;
  2581. API_PARSE * ncpi;
  2582. byte req;
  2583. word w;
  2584. API_PARSE fax_parms[9];
  2585. word i;
  2586. byte len;
  2587. dbug(1,dprintf("connect_b3_res"));
  2588. ncci = (word)(Id>>16);
  2589. if(plci && ncci) {
  2590. if(a->ncci_state[ncci]==INC_CON_PENDING) {
  2591. if (GET_WORD (&parms[0].info[0]) != 0)
  2592. {
  2593. a->ncci_state[ncci] = OUTG_REJ_PENDING;
  2594. channel_request_xon (plci, a->ncci_ch[ncci]);
  2595. channel_xmit_xon (plci);
  2596. cleanup_ncci_data (plci, ncci);
  2597. nl_req_ncci(plci,N_DISC,(byte)ncci);
  2598. return 1;
  2599. }
  2600. a->ncci_state[ncci] = INC_ACT_PENDING;
  2601. req = N_CONNECT_ACK;
  2602. ncpi = &parms[1];
  2603. if ((plci->B3_prot == 4) || (plci->B3_prot == 5) || (plci->B3_prot == 7))
  2604. {
  2605. if ((plci->requested_options_conn | plci->requested_options | a->requested_options_table[plci->appl->Id-1])
  2606. & (1L << PRIVATE_FAX_NONSTANDARD))
  2607. {
  2608. if (((plci->B3_prot == 4) || (plci->B3_prot == 5))
  2609. && (plci->nsf_control_bits & T30_NSF_CONTROL_BIT_ENABLE_NSF)
  2610. && (plci->nsf_control_bits & T30_NSF_CONTROL_BIT_NEGOTIATE_RESP))
  2611. {
  2612. len = ((byte)(((T30_INFO *) 0)->station_id + 20));
  2613. if (plci->fax_connect_info_length < len)
  2614. {
  2615. ((T30_INFO *)(plci->fax_connect_info_buffer))->station_id_len = 0;
  2616. ((T30_INFO *)(plci->fax_connect_info_buffer))->head_line_len = 0;
  2617. }
  2618. if (api_parse (&ncpi->info[1], ncpi->length, "wwwwssss", fax_parms))
  2619. {
  2620. dbug(1,dprintf("non-standard facilities info missing or wrong format"));
  2621. }
  2622. else
  2623. {
  2624. if (plci->fax_connect_info_length <= len)
  2625. plci->fax_connect_info_buffer[len] = 0;
  2626. len += 1 + plci->fax_connect_info_buffer[len];
  2627. if (plci->fax_connect_info_length <= len)
  2628. plci->fax_connect_info_buffer[len] = 0;
  2629. len += 1 + plci->fax_connect_info_buffer[len];
  2630. if ((fax_parms[7].length >= 3) && (fax_parms[7].info[1] >= 2))
  2631. plci->nsf_control_bits = GET_WORD(&fax_parms[7].info[2]);
  2632. plci->fax_connect_info_buffer[len++] = (byte)(fax_parms[7].length);
  2633. for (i = 0; i < fax_parms[7].length; i++)
  2634. plci->fax_connect_info_buffer[len++] = fax_parms[7].info[1+i];
  2635. }
  2636. plci->fax_connect_info_length = len;
  2637. ((T30_INFO *)(plci->fax_connect_info_buffer))->code = 0;
  2638. start_internal_command (Id, plci, fax_connect_ack_command);
  2639. return FALSE;
  2640. }
  2641. }
  2642. nl_req_ncci(plci,req,(byte)ncci);
  2643. if ((plci->ncpi_state & NCPI_VALID_CONNECT_B3_ACT)
  2644. && !(plci->ncpi_state & NCPI_CONNECT_B3_ACT_SENT))
  2645. {
  2646. if (plci->B3_prot == 4)
  2647. sendf(appl,_CONNECT_B3_ACTIVE_I,Id,0,"s","");
  2648. else
  2649. sendf(appl,_CONNECT_B3_ACTIVE_I,Id,0,"S",plci->ncpi_buffer);
  2650. plci->ncpi_state |= NCPI_CONNECT_B3_ACT_SENT;
  2651. }
  2652. }
  2653. else if (plci->B3_prot == B3_RTP)
  2654. {
  2655. plci->internal_req_buffer[0] = ncpi->length + 1;
  2656. plci->internal_req_buffer[1] = UDATA_REQUEST_RTP_RECONFIGURE;
  2657. for (w = 0; w < ncpi->length; w++)
  2658. plci->internal_req_buffer[2+w] = ncpi->info[1+w];
  2659. start_internal_command (Id, plci, rtp_connect_b3_res_command);
  2660. return FALSE;
  2661. }
  2662. else
  2663. {
  2664. if(ncpi->length>2) {
  2665. if(ncpi->info[1] &1) req = N_CONNECT_ACK | N_D_BIT;
  2666. add_d(plci,(word)(ncpi->length-3),&ncpi->info[4]);
  2667. }
  2668. nl_req_ncci(plci,req,(byte)ncci);
  2669. sendf(appl,_CONNECT_B3_ACTIVE_I,Id,0,"s","");
  2670. if (plci->adjust_b_restore)
  2671. {
  2672. plci->adjust_b_restore = FALSE;
  2673. start_internal_command (Id, plci, adjust_b_restore);
  2674. }
  2675. }
  2676. return 1;
  2677. }
  2678. }
  2679. return FALSE;
  2680. }
  2681. byte connect_b3_a_res(dword Id, word Number, DIVA_CAPI_ADAPTER * a, PLCI * plci, APPL * appl, API_PARSE * parms)
  2682. {
  2683. word ncci;
  2684. ncci = (word)(Id>>16);
  2685. dbug(1,dprintf("connect_b3_a_res(ncci=0x%x)",ncci));
  2686. if (plci && ncci && (plci->State != IDLE) && (plci->State != INC_DIS_PENDING)
  2687. && (plci->State != OUTG_DIS_PENDING))
  2688. {
  2689. if(a->ncci_state[ncci]==INC_ACT_PENDING) {
  2690. a->ncci_state[ncci] = CONNECTED;
  2691. if(plci->State!=INC_CON_CONNECTED_ALERT) plci->State = CONNECTED;
  2692. channel_request_xon (plci, a->ncci_ch[ncci]);
  2693. channel_xmit_xon (plci);
  2694. }
  2695. }
  2696. return FALSE;
  2697. }
  2698. byte disconnect_b3_req(dword Id, word Number, DIVA_CAPI_ADAPTER * a, PLCI * plci, APPL * appl, API_PARSE * parms)
  2699. {
  2700. word Info;
  2701. word ncci;
  2702. API_PARSE * ncpi;
  2703. dbug(1,dprintf("disconnect_b3_req"));
  2704. Info = _WRONG_IDENTIFIER;
  2705. ncci = (word)(Id>>16);
  2706. if (plci && ncci)
  2707. {
  2708. Info = _WRONG_STATE;
  2709. if ((a->ncci_state[ncci] == CONNECTED)
  2710. || (a->ncci_state[ncci] == OUTG_CON_PENDING)
  2711. || (a->ncci_state[ncci] == INC_CON_PENDING)
  2712. || (a->ncci_state[ncci] == INC_ACT_PENDING))
  2713. {
  2714. a->ncci_state[ncci] = OUTG_DIS_PENDING;
  2715. channel_request_xon (plci, a->ncci_ch[ncci]);
  2716. channel_xmit_xon (plci);
  2717. if (a->ncci[ncci].data_pending
  2718. && ((plci->B3_prot == B3_TRANSPARENT)
  2719. || (plci->B3_prot == B3_T30)
  2720. || (plci->B3_prot == B3_T30_WITH_EXTENSIONS)))
  2721. {
  2722. plci->send_disc = (byte)ncci;
  2723. plci->command = 0;
  2724. return FALSE;
  2725. }
  2726. else
  2727. {
  2728. cleanup_ncci_data (plci, ncci);
  2729. if(plci->B3_prot==2 || plci->B3_prot==3)
  2730. {
  2731. ncpi = &parms[0];
  2732. if(ncpi->length>3)
  2733. {
  2734. add_d(plci, (word)(ncpi->length - 3) ,(byte *)&(ncpi->info[4]));
  2735. }
  2736. }
  2737. nl_req_ncci(plci,N_DISC,(byte)ncci);
  2738. }
  2739. return 1;
  2740. }
  2741. }
  2742. sendf(appl,
  2743. _DISCONNECT_B3_R|CONFIRM,
  2744. Id,
  2745. Number,
  2746. "w",Info);
  2747. return FALSE;
  2748. }
  2749. byte disconnect_b3_res(dword Id, word Number, DIVA_CAPI_ADAPTER * a, PLCI * plci, APPL * appl, API_PARSE * parms)
  2750. {
  2751. word ncci;
  2752. word i;
  2753. ncci = (word)(Id>>16);
  2754. dbug(1,dprintf("disconnect_b3_res(ncci=0x%x",ncci));
  2755. if(plci && ncci) {
  2756. plci->requested_options_conn = 0;
  2757. plci->fax_connect_info_length = 0;
  2758. plci->ncpi_state = 0x00;
  2759. if (((plci->B3_prot != B3_T90NL) && (plci->B3_prot != B3_ISO8208) && (plci->B3_prot != B3_X25_DCE))
  2760. && ((plci->B2_prot != B2_LAPD) && (plci->B2_prot != B2_LAPD_FREE_SAPI_SEL)))
  2761. {
  2762. plci->call_dir |= CALL_DIR_FORCE_OUTG_NL;
  2763. }
  2764. for(i=0; i<MAX_CHANNELS_PER_PLCI && plci->inc_dis_ncci_table[i]!=(byte)ncci; i++);
  2765. if(i<MAX_CHANNELS_PER_PLCI) {
  2766. if(plci->channels)plci->channels--;
  2767. for(; i<MAX_CHANNELS_PER_PLCI-1; i++) plci->inc_dis_ncci_table[i] = plci->inc_dis_ncci_table[i+1];
  2768. plci->inc_dis_ncci_table[MAX_CHANNELS_PER_PLCI-1] = 0;
  2769. ncci_free_receive_buffers (plci, ncci);
  2770. if((plci->State==IDLE || plci->State==SUSPENDING) && !plci->channels){
  2771. if(plci->State == SUSPENDING){
  2772. sendf(plci->appl,
  2773. _FACILITY_I,
  2774. Id & 0xffffL,
  2775. 0,
  2776. "ws", (word)3, "\x03\x04\x00\x00");
  2777. sendf(plci->appl, _DISCONNECT_I, Id & 0xffffL, 0, "w", 0);
  2778. }
  2779. plci_remove(plci);
  2780. plci->State=IDLE;
  2781. }
  2782. }
  2783. else
  2784. {
  2785. if ((a->manufacturer_features & MANUFACTURER_FEATURE_FAX_PAPER_FORMATS)
  2786. && ((plci->B3_prot == 4) || (plci->B3_prot == 5))
  2787. && (a->ncci_state[ncci] == INC_DIS_PENDING))
  2788. {
  2789. ncci_free_receive_buffers (plci, ncci);
  2790. nl_req_ncci(plci,N_EDATA,(byte)ncci);
  2791. plci->adapter->ncci_state[ncci] = IDLE;
  2792. start_internal_command (Id, plci, fax_disconnect_command);
  2793. return 1;
  2794. }
  2795. }
  2796. }
  2797. return FALSE;
  2798. }
  2799. byte data_b3_req(dword Id, word Number, DIVA_CAPI_ADAPTER * a, PLCI * plci, APPL * appl, API_PARSE * parms)
  2800. {
  2801. NCCI *ncci_ptr;
  2802. DATA_B3_DESC *data;
  2803. word Info;
  2804. word ncci;
  2805. word i;
  2806. dbug(1,dprintf("data_b3_req"));
  2807. Info = _WRONG_IDENTIFIER;
  2808. ncci = (word)(Id>>16);
  2809. dbug(1,dprintf("ncci=0x%x, plci=0x%x",ncci,plci));
  2810. if (plci && ncci)
  2811. {
  2812. Info = _WRONG_STATE;
  2813. if ((a->ncci_state[ncci] == CONNECTED)
  2814. || (a->ncci_state[ncci] == INC_ACT_PENDING))
  2815. {
  2816. /* queue data */
  2817. ncci_ptr = &(a->ncci[ncci]);
  2818. i = ncci_ptr->data_out + ncci_ptr->data_pending;
  2819. if (i >= MAX_DATA_B3)
  2820. i -= MAX_DATA_B3;
  2821. data = &(ncci_ptr->DBuffer[i]);
  2822. data->Number = Number;
  2823. if ((((byte *)(parms[0].info)) >= ((byte *)(plci->msg_in_queue)))
  2824. && (((byte *)(parms[0].info)) < ((byte *)(plci->msg_in_queue)) + sizeof(plci->msg_in_queue)))
  2825. {
  2826. data->P = (byte *)(*((dword *)(parms[0].info)));
  2827. }
  2828. else
  2829. data->P = TransmitBufferSet(appl,*(dword *)parms[0].info);
  2830. data->Length = GET_WORD(parms[1].info);
  2831. data->Handle = GET_WORD(parms[2].info);
  2832. data->Flags = GET_WORD(parms[3].info);
  2833. (ncci_ptr->data_pending)++;
  2834. /* check for delivery confirmation */
  2835. if (data->Flags & 0x0004)
  2836. {
  2837. i = ncci_ptr->data_ack_out + ncci_ptr->data_ack_pending;
  2838. if (i >= MAX_DATA_ACK)
  2839. i -= MAX_DATA_ACK;
  2840. ncci_ptr->DataAck[i].Number = data->Number;
  2841. ncci_ptr->DataAck[i].Handle = data->Handle;
  2842. (ncci_ptr->data_ack_pending)++;
  2843. }
  2844. send_data(plci);
  2845. return FALSE;
  2846. }
  2847. }
  2848. if (appl)
  2849. {
  2850. if (plci)
  2851. {
  2852. if ((((byte *)(parms[0].info)) >= ((byte *)(plci->msg_in_queue)))
  2853. && (((byte *)(parms[0].info)) < ((byte *)(plci->msg_in_queue)) + sizeof(plci->msg_in_queue)))
  2854. {
  2855. TransmitBufferFree (appl, (byte *)(*((dword *)(parms[0].info))));
  2856. }
  2857. }
  2858. sendf(appl,
  2859. _DATA_B3_R|CONFIRM,
  2860. Id,
  2861. Number,
  2862. "ww",GET_WORD(parms[2].info),Info);
  2863. }
  2864. return FALSE;
  2865. }
  2866. byte data_b3_res(dword Id, word Number, DIVA_CAPI_ADAPTER * a, PLCI * plci, APPL * appl, API_PARSE * parms)
  2867. {
  2868. word n;
  2869. word ncci;
  2870. word NCCIcode;
  2871. dbug(1,dprintf("data_b3_res"));
  2872. ncci = (word)(Id>>16);
  2873. if(plci && ncci) {
  2874. n = GET_WORD(parms[0].info);
  2875. dbug(1,dprintf("free(%d)",n));
  2876. NCCIcode = ncci | (((word) a->Id) << 8);
  2877. if(n<appl->MaxBuffer &&
  2878. appl->DataNCCI[n]==NCCIcode &&
  2879. (byte)(appl->DataFlags[n]>>8)==plci->Id) {
  2880. dbug(1,dprintf("found"));
  2881. appl->DataNCCI[n] = 0;
  2882. if (channel_can_xon (plci, a->ncci_ch[ncci])) {
  2883. channel_request_xon (plci, a->ncci_ch[ncci]);
  2884. }
  2885. channel_xmit_xon (plci);
  2886. if(appl->DataFlags[n] &4) {
  2887. nl_req_ncci(plci,N_DATA_ACK,(byte)ncci);
  2888. return 1;
  2889. }
  2890. }
  2891. }
  2892. return FALSE;
  2893. }
  2894. byte reset_b3_req(dword Id, word Number, DIVA_CAPI_ADAPTER * a, PLCI * plci, APPL * appl, API_PARSE * parms)
  2895. {
  2896. word Info;
  2897. word ncci;
  2898. dbug(1,dprintf("reset_b3_req"));
  2899. Info = _WRONG_IDENTIFIER;
  2900. ncci = (word)(Id>>16);
  2901. if(plci && ncci)
  2902. {
  2903. Info = _WRONG_STATE;
  2904. switch (plci->B3_prot)
  2905. {
  2906. case B3_ISO8208:
  2907. case B3_X25_DCE:
  2908. if(a->ncci_state[ncci]==CONNECTED)
  2909. {
  2910. nl_req_ncci(plci,N_RESET,(byte)ncci);
  2911. send_req(plci);
  2912. Info = GOOD;
  2913. }
  2914. break;
  2915. case B3_TRANSPARENT:
  2916. if(a->ncci_state[ncci]==CONNECTED)
  2917. {
  2918. start_internal_command (Id, plci, reset_b3_command);
  2919. Info = GOOD;
  2920. }
  2921. break;
  2922. }
  2923. }
  2924. /* reset_b3 must result in a reset_b3_con & reset_b3_Ind */
  2925. sendf(appl,
  2926. _RESET_B3_R|CONFIRM,
  2927. Id,
  2928. Number,
  2929. "w",Info);
  2930. return FALSE;
  2931. }
  2932. byte reset_b3_res(dword Id, word Number, DIVA_CAPI_ADAPTER * a, PLCI * plci, APPL * appl, API_PARSE * parms)
  2933. {
  2934. word ncci;
  2935. dbug(1,dprintf("reset_b3_res"));
  2936. ncci = (word)(Id>>16);
  2937. if(plci && ncci) {
  2938. switch (plci->B3_prot)
  2939. {
  2940. case B3_ISO8208:
  2941. case B3_X25_DCE:
  2942. if(a->ncci_state[ncci]==INC_RES_PENDING)
  2943. {
  2944. a->ncci_state[ncci] = CONNECTED;
  2945. nl_req_ncci(plci,N_RESET_ACK,(byte)ncci);
  2946. return TRUE;
  2947. }
  2948. break;
  2949. }
  2950. }
  2951. return FALSE;
  2952. }
  2953. byte connect_b3_t90_a_res(dword Id, word Number, DIVA_CAPI_ADAPTER * a, PLCI * plci, APPL * appl, API_PARSE * parms)
  2954. {
  2955. word ncci;
  2956. API_PARSE * ncpi;
  2957. byte req;
  2958. dbug(1,dprintf("connect_b3_t90_a_res"));
  2959. ncci = (word)(Id>>16);
  2960. if(plci && ncci) {
  2961. if(a->ncci_state[ncci]==INC_ACT_PENDING) {
  2962. a->ncci_state[ncci] = CONNECTED;
  2963. }
  2964. else if(a->ncci_state[ncci]==INC_CON_PENDING) {
  2965. a->ncci_state[ncci] = CONNECTED;
  2966. req = N_CONNECT_ACK;
  2967. /* parms[0]==0 for CAPI original message definition! */
  2968. if(parms[0].info) {
  2969. ncpi = &parms[1];
  2970. if(ncpi->length>2) {
  2971. if(ncpi->info[1] &1) req = N_CONNECT_ACK | N_D_BIT;
  2972. add_d(plci,(word)(ncpi->length-3),&ncpi->info[4]);
  2973. }
  2974. }
  2975. nl_req_ncci(plci,req,(byte)ncci);
  2976. return 1;
  2977. }
  2978. }
  2979. return FALSE;
  2980. }
  2981. byte select_b_req(dword Id, word Number, DIVA_CAPI_ADAPTER * a, PLCI * plci, APPL * appl, API_PARSE * msg)
  2982. {
  2983. word Info=0;
  2984. word i;
  2985. byte tel;
  2986. API_PARSE bp_parms[7];
  2987. if(!plci || !msg)
  2988. {
  2989. Info = _WRONG_IDENTIFIER;
  2990. }
  2991. else
  2992. {
  2993. dbug(1,dprintf("select_b_req[%d],PLCI=0x%x,Tel=0x%x,NL=0x%x,appl=0x%x,sstate=0x%x",
  2994. msg->length,plci->Id,plci->tel,plci->NL.Id,plci->appl,plci->SuppState));
  2995. dbug(1,dprintf("PlciState=0x%x",plci->State));
  2996. for(i=0;i<7;i++) bp_parms[i].length = 0;
  2997. /* check if no channel is open, no B3 connected only */
  2998. if((plci->State == IDLE) || (plci->State == OUTG_DIS_PENDING) || (plci->State == INC_DIS_PENDING)
  2999. || (plci->SuppState != IDLE) || plci->channels || plci->nl_remove_id)
  3000. {
  3001. Info = _WRONG_STATE;
  3002. }
  3003. /* check message format and fill bp_parms pointer */
  3004. else if(msg->length && api_parse(&msg->info[1], (word)msg->length, "wwwsss", bp_parms))
  3005. {
  3006. Info = _WRONG_MESSAGE_FORMAT;
  3007. }
  3008. else
  3009. {
  3010. if((plci->State==INC_CON_PENDING) || (plci->State==INC_CON_ALERT)) /* send alert tone inband to the network, */
  3011. { /* e.g. Qsig or RBS or Cornet-N or xess PRI */
  3012. if(Id & EXT_CONTROLLER)
  3013. {
  3014. sendf(appl, _SELECT_B_REQ|CONFIRM, Id, Number, "w", 0x2002); /* wrong controller */
  3015. return 0;
  3016. }
  3017. plci->State=INC_CON_CONNECTED_ALERT;
  3018. plci->appl = appl;
  3019. clear_c_ind_mask_bit (plci, (word)(appl->Id-1));
  3020. dump_c_ind_mask (plci);
  3021. for(i=0; i<max_appl; i++) /* disconnect the other appls */
  3022. { /* its quasi a connect */
  3023. if(test_c_ind_mask_bit (plci, i))
  3024. sendf(&application[i], _DISCONNECT_I, Id, 0, "w", _OTHER_APPL_CONNECTED);
  3025. }
  3026. }
  3027. api_save_msg(msg, "s", &plci->saved_msg);
  3028. tel = plci->tel;
  3029. if(Id & EXT_CONTROLLER)
  3030. {
  3031. if(tel) /* external controller in use by this PLCI */
  3032. {
  3033. if(a->AdvSignalAppl && a->AdvSignalAppl!=appl)
  3034. {
  3035. dbug(1,dprintf("Ext_Ctrl in use 1"));
  3036. Info = _WRONG_STATE;
  3037. }
  3038. }
  3039. else /* external controller NOT in use by this PLCI ? */
  3040. {
  3041. if(a->AdvSignalPLCI)
  3042. {
  3043. dbug(1,dprintf("Ext_Ctrl in use 2"));
  3044. Info = _WRONG_STATE;
  3045. }
  3046. else /* activate the codec */
  3047. {
  3048. dbug(1,dprintf("Ext_Ctrl start"));
  3049. if(AdvCodecSupport(a, plci, appl, 0) )
  3050. {
  3051. dbug(1,dprintf("Error in codec procedures"));
  3052. Info = _WRONG_STATE;
  3053. }
  3054. else if(plci->spoofed_msg==SPOOFING_REQUIRED) /* wait until codec is active */
  3055. {
  3056. plci->spoofed_msg = AWAITING_SELECT_B;
  3057. plci->internal_command = BLOCK_PLCI; /* lock other commands */
  3058. plci->command = 0;
  3059. dbug(1,dprintf("continue if codec loaded"));
  3060. return FALSE;
  3061. }
  3062. }
  3063. }
  3064. }
  3065. else /* external controller bit is OFF */
  3066. {
  3067. if(tel) /* external controller in use, need to switch off */
  3068. {
  3069. if(a->AdvSignalAppl==appl)
  3070. {
  3071. CodecIdCheck(a, plci);
  3072. plci->tel = 0;
  3073. plci->adv_nl = 0;
  3074. dbug(1,dprintf("Ext_Ctrl disable"));
  3075. }
  3076. else
  3077. {
  3078. dbug(1,dprintf("Ext_Ctrl not requested"));
  3079. }
  3080. }
  3081. }
  3082. if (!Info)
  3083. {
  3084. if (plci->call_dir & CALL_DIR_OUT)
  3085. plci->call_dir = CALL_DIR_OUT | CALL_DIR_ORIGINATE;
  3086. else if (plci->call_dir & CALL_DIR_IN)
  3087. plci->call_dir = CALL_DIR_IN | CALL_DIR_ANSWER;
  3088. start_internal_command (Id, plci, select_b_command);
  3089. return FALSE;
  3090. }
  3091. }
  3092. }
  3093. sendf(appl, _SELECT_B_REQ|CONFIRM, Id, Number, "w", Info);
  3094. return FALSE;
  3095. }
  3096. byte manufacturer_req(dword Id, word Number, DIVA_CAPI_ADAPTER * a, PLCI * plci, APPL * appl, API_PARSE * parms)
  3097. {
  3098. word command;
  3099. word i;
  3100. word ncci;
  3101. API_PARSE * m;
  3102. API_PARSE m_parms[5];
  3103. word codec;
  3104. byte req;
  3105. byte ch;
  3106. byte dir;
  3107. static byte chi[2] = {0x01,0x00};
  3108. static byte lli[2] = {0x01,0x00};
  3109. static byte codec_cai[2] = {0x01,0x01};
  3110. static byte null_msg = {0};
  3111. static API_PARSE null_parms = { 0, &null_msg };
  3112. PLCI * v_plci;
  3113. word Info=0;
  3114. dbug(1,dprintf("manufacturer_req"));
  3115. for(i=0;i<5;i++) m_parms[i].length = 0;
  3116. if(GET_DWORD(parms[0].info)!=_DI_MANU_ID) {
  3117. Info = _WRONG_MESSAGE_FORMAT;
  3118. }
  3119. command = GET_WORD(parms[1].info);
  3120. m = &parms[2];
  3121. if (!Info)
  3122. {
  3123. switch(command) {
  3124. case _DI_ASSIGN_PLCI:
  3125. if(api_parse(&m->info[1],(word)m->length,"wbbs",m_parms)) {
  3126. Info = _WRONG_MESSAGE_FORMAT;
  3127. break;
  3128. }
  3129. codec = GET_WORD(m_parms[0].info);
  3130. ch = m_parms[1].info[0];
  3131. dir = m_parms[2].info[0];
  3132. if((i=get_plci(a))) {
  3133. plci = &a->plci[i-1];
  3134. plci->appl = appl;
  3135. plci->command = _MANUFACTURER_R;
  3136. plci->m_command = command;
  3137. plci->number = Number;
  3138. plci->State = LOCAL_CONNECT;
  3139. Id = ( ((word)plci->Id<<8)|plci->adapter->Id|0x80);
  3140. dbug(1,dprintf("ManCMD,plci=0x%x",Id));
  3141. if((ch==1 || ch==2) && (dir<=2)) {
  3142. chi[1] = (byte)(0x80|ch);
  3143. lli[1] = 0;
  3144. plci->call_dir = CALL_DIR_OUT | CALL_DIR_ORIGINATE;
  3145. switch(codec)
  3146. {
  3147. case 0:
  3148. Info = add_b1(plci,&m_parms[3],0,0);
  3149. break;
  3150. case 1:
  3151. add_p(plci,CAI,codec_cai);
  3152. break;
  3153. /* manual 'swich on' to the codec support without signalling */
  3154. /* first 'assign plci' with this function, then use */
  3155. case 2:
  3156. if(AdvCodecSupport(a, plci, appl, 0) ) {
  3157. Info = _RESOURCE_ERROR;
  3158. }
  3159. else {
  3160. Info = add_b1(plci,&null_parms,0,B1_FACILITY_LOCAL);
  3161. lli[1] = 0x10; /* local call codec stream */
  3162. }
  3163. break;
  3164. }
  3165. plci->State = LOCAL_CONNECT;
  3166. plci->manufacturer = TRUE;
  3167. plci->command = _MANUFACTURER_R;
  3168. plci->m_command = command;
  3169. plci->number = Number;
  3170. if(!Info)
  3171. {
  3172. add_p(plci,LLI,lli);
  3173. add_p(plci,CHI,chi);
  3174. add_p(plci,UID,"\x06\x43\x61\x70\x69\x32\x30");
  3175. sig_req(plci,ASSIGN,DSIG_ID);
  3176. if(!codec)
  3177. {
  3178. Info = add_b23(plci,&m_parms[3]);
  3179. if(!Info)
  3180. {
  3181. nl_req_ncci(plci,ASSIGN,0);
  3182. send_req(plci);
  3183. }
  3184. }
  3185. if(!Info)
  3186. {
  3187. dbug(1,dprintf("dir=0x%x,spoof=0x%x",dir,plci->spoofed_msg));
  3188. if (plci->spoofed_msg==SPOOFING_REQUIRED)
  3189. {
  3190. api_save_msg (m_parms, "wbbs", &plci->saved_msg);
  3191. plci->spoofed_msg = AWAITING_MANUF_CON;
  3192. plci->internal_command = BLOCK_PLCI; /* reject other req meanwhile */
  3193. plci->command = 0;
  3194. send_req(plci);
  3195. return FALSE;
  3196. }
  3197. if(dir==1) {
  3198. sig_req(plci,CALL_REQ,0);
  3199. }
  3200. else if(!dir){
  3201. sig_req(plci,LISTEN_REQ,0);
  3202. }
  3203. send_req(plci);
  3204. }
  3205. else
  3206. {
  3207. sendf(appl,
  3208. _MANUFACTURER_R|CONFIRM,
  3209. Id,
  3210. Number,
  3211. "dww",_DI_MANU_ID,command,Info);
  3212. return 2;
  3213. }
  3214. }
  3215. }
  3216. }
  3217. else Info = _OUT_OF_PLCI;
  3218. break;
  3219. case _DI_IDI_CTRL:
  3220. if(!plci)
  3221. {
  3222. Info = _WRONG_IDENTIFIER;
  3223. break;
  3224. }
  3225. if(api_parse(&m->info[1],(word)m->length,"bs",m_parms)) {
  3226. Info = _WRONG_MESSAGE_FORMAT;
  3227. break;
  3228. }
  3229. req = m_parms[0].info[0];
  3230. plci->command = _MANUFACTURER_R;
  3231. plci->m_command = command;
  3232. plci->number = Number;
  3233. if(req==CALL_REQ)
  3234. {
  3235. plci->b_channel = getChannel(&m_parms[1]);
  3236. mixer_set_bchannel_id_esc (plci, plci->b_channel);
  3237. if(plci->spoofed_msg==SPOOFING_REQUIRED)
  3238. {
  3239. plci->spoofed_msg = CALL_REQ | AWAITING_MANUF_CON;
  3240. plci->internal_command = BLOCK_PLCI; /* reject other req meanwhile */
  3241. plci->command = 0;
  3242. break;
  3243. }
  3244. }
  3245. else if(req==LAW_REQ)
  3246. {
  3247. plci->cr_enquiry = TRUE;
  3248. }
  3249. add_ss(plci,FTY,&m_parms[1]);
  3250. sig_req(plci,req,0);
  3251. send_req(plci);
  3252. if(req==HANGUP)
  3253. {
  3254. if (plci->NL.Id && !plci->nl_remove_id)
  3255. {
  3256. if (plci->channels)
  3257. {
  3258. for (ncci = 1; ncci < MAX_NCCI+1; ncci++)
  3259. {
  3260. if ((a->ncci_plci[ncci] == plci->Id) && (a->ncci_state[ncci] == CONNECTED))
  3261. {
  3262. a->ncci_state[ncci] = OUTG_DIS_PENDING;
  3263. cleanup_ncci_data (plci, ncci);
  3264. nl_req_ncci(plci,N_DISC,(byte)ncci);
  3265. }
  3266. }
  3267. }
  3268. mixer_remove (plci);
  3269. nl_req_ncci(plci,REMOVE,0);
  3270. send_req(plci);
  3271. }
  3272. }
  3273. break;
  3274. case _DI_SIG_CTRL:
  3275. /* signalling control for loop activation B-channel */
  3276. if(!plci)
  3277. {
  3278. Info = _WRONG_IDENTIFIER;
  3279. break;
  3280. }
  3281. if(m->length){
  3282. plci->command = _MANUFACTURER_R;
  3283. plci->number = Number;
  3284. add_ss(plci,FTY,m);
  3285. sig_req(plci,SIG_CTRL,0);
  3286. send_req(plci);
  3287. }
  3288. else Info = _WRONG_MESSAGE_FORMAT;
  3289. break;
  3290. case _DI_RXT_CTRL:
  3291. /* activation control for receiver/transmitter B-channel */
  3292. if(!plci)
  3293. {
  3294. Info = _WRONG_IDENTIFIER;
  3295. break;
  3296. }
  3297. if(m->length){
  3298. plci->command = _MANUFACTURER_R;
  3299. plci->number = Number;
  3300. add_ss(plci,FTY,m);
  3301. sig_req(plci,DSP_CTRL,0);
  3302. send_req(plci);
  3303. }
  3304. else Info = _WRONG_MESSAGE_FORMAT;
  3305. break;
  3306. case _DI_ADV_CODEC:
  3307. case _DI_DSP_CTRL:
  3308. /* TEL_CTRL commands to support non standard adjustments: */
  3309. /* Ring on/off, Handset micro volume, external micro vol. */
  3310. /* handset+external speaker volume, receiver+transm. gain,*/
  3311. /* handsfree on (hookinfo off), set mixer command */
  3312. if(command == _DI_ADV_CODEC)
  3313. {
  3314. if(!a->AdvCodecPLCI) {
  3315. Info = _WRONG_STATE;
  3316. break;
  3317. }
  3318. v_plci = a->AdvCodecPLCI;
  3319. }
  3320. else
  3321. {
  3322. if (plci
  3323. && (m->length >= 3)
  3324. && (m->info[1] == 0x1c)
  3325. && (m->info[2] >= 1))
  3326. {
  3327. if (m->info[3] == DSP_CTRL_OLD_SET_MIXER_COEFFICIENTS)
  3328. {
  3329. if ((plci->tel != ADV_VOICE) || (plci != a->AdvSignalPLCI))
  3330. {
  3331. Info = _WRONG_STATE;
  3332. break;
  3333. }
  3334. a->adv_voice_coef_length = m->info[2] - 1;
  3335. if (a->adv_voice_coef_length > m->length - 3)
  3336. a->adv_voice_coef_length = (byte)(m->length - 3);
  3337. if (a->adv_voice_coef_length > ADV_VOICE_COEF_BUFFER_SIZE)
  3338. a->adv_voice_coef_length = ADV_VOICE_COEF_BUFFER_SIZE;
  3339. for (i = 0; i < a->adv_voice_coef_length; i++)
  3340. a->adv_voice_coef_buffer[i] = m->info[4 + i];
  3341. if (plci->B1_facilities & B1_FACILITY_VOICE)
  3342. adv_voice_write_coefs (plci, ADV_VOICE_WRITE_UPDATE);
  3343. break;
  3344. }
  3345. else if (m->info[3] == DSP_CTRL_SET_DTMF_PARAMETERS)
  3346. {
  3347. if (!(a->manufacturer_features & MANUFACTURER_FEATURE_DTMF_PARAMETERS))
  3348. {
  3349. Info = _FACILITY_NOT_SUPPORTED;
  3350. break;
  3351. }
  3352. plci->dtmf_parameter_length = m->info[2] - 1;
  3353. if (plci->dtmf_parameter_length > m->length - 3)
  3354. plci->dtmf_parameter_length = (byte)(m->length - 3);
  3355. if (plci->dtmf_parameter_length > DTMF_PARAMETER_BUFFER_SIZE)
  3356. plci->dtmf_parameter_length = DTMF_PARAMETER_BUFFER_SIZE;
  3357. for (i = 0; i < plci->dtmf_parameter_length; i++)
  3358. plci->dtmf_parameter_buffer[i] = m->info[4+i];
  3359. if (plci->B1_facilities & B1_FACILITY_DTMFR)
  3360. dtmf_parameter_write (plci);
  3361. break;
  3362. }
  3363. }
  3364. v_plci = plci;
  3365. }
  3366. if(!v_plci)
  3367. {
  3368. Info = _WRONG_IDENTIFIER;
  3369. break;
  3370. }
  3371. if(m->length){
  3372. add_ss(v_plci,FTY,m);
  3373. sig_req(v_plci,TEL_CTRL,0);
  3374. send_req(v_plci);
  3375. }
  3376. else Info = _WRONG_MESSAGE_FORMAT;
  3377. break;
  3378. case _DI_OPTIONS_REQUEST:
  3379. if(api_parse(&m->info[1],(word)m->length,"d",m_parms)) {
  3380. Info = _WRONG_MESSAGE_FORMAT;
  3381. break;
  3382. }
  3383. if (GET_DWORD (m_parms[0].info) & ~a->man_profile.private_options)
  3384. {
  3385. Info = _FACILITY_NOT_SUPPORTED;
  3386. break;
  3387. }
  3388. a->requested_options_table[appl->Id-1] = GET_DWORD (m_parms[0].info);
  3389. break;
  3390. default:
  3391. Info = _WRONG_MESSAGE_FORMAT;
  3392. break;
  3393. }
  3394. }
  3395. sendf(appl,
  3396. _MANUFACTURER_R|CONFIRM,
  3397. Id,
  3398. Number,
  3399. "dww",_DI_MANU_ID,command,Info);
  3400. return FALSE;
  3401. }
  3402. byte manufacturer_res(dword Id, word Number, DIVA_CAPI_ADAPTER * a, PLCI * plci, APPL * appl, API_PARSE * msg)
  3403. {
  3404. word indication;
  3405. API_PARSE m_parms[3];
  3406. API_PARSE *ncpi;
  3407. API_PARSE fax_parms[9];
  3408. word i;
  3409. byte len;
  3410. dbug(1,dprintf("manufacturer_res"));
  3411. if ((msg[0].length == 0)
  3412. || (msg[1].length == 0)
  3413. || (GET_DWORD(msg[0].info)!=_DI_MANU_ID))
  3414. {
  3415. return FALSE;
  3416. }
  3417. indication = GET_WORD(msg[1].info);
  3418. switch (indication)
  3419. {
  3420. case _DI_NEGOTIATE_B3:
  3421. if(!plci)
  3422. break;
  3423. if (((plci->B3_prot != 4) && (plci->B3_prot != 5))
  3424. || !(plci->ncpi_state & NCPI_NEGOTIATE_B3_SENT))
  3425. {
  3426. dbug(1,dprintf("wrong state for NEGOTIATE_B3 parameters"));
  3427. break;
  3428. }
  3429. if (api_parse (&msg[2].info[1], msg[2].length, "ws", m_parms))
  3430. {
  3431. dbug(1,dprintf("wrong format in NEGOTIATE_B3 parameters"));
  3432. break;
  3433. }
  3434. ncpi = &m_parms[1];
  3435. len = ((byte)(((T30_INFO *) 0)->station_id + 20));
  3436. if (plci->fax_connect_info_length < len)
  3437. {
  3438. ((T30_INFO *)(plci->fax_connect_info_buffer))->station_id_len = 0;
  3439. ((T30_INFO *)(plci->fax_connect_info_buffer))->head_line_len = 0;
  3440. }
  3441. if (api_parse (&ncpi->info[1], ncpi->length, "wwwwssss", fax_parms))
  3442. {
  3443. dbug(1,dprintf("non-standard facilities info missing or wrong format"));
  3444. }
  3445. else
  3446. {
  3447. if (plci->fax_connect_info_length <= len)
  3448. plci->fax_connect_info_buffer[len] = 0;
  3449. len += 1 + plci->fax_connect_info_buffer[len];
  3450. if (plci->fax_connect_info_length <= len)
  3451. plci->fax_connect_info_buffer[len] = 0;
  3452. len += 1 + plci->fax_connect_info_buffer[len];
  3453. if ((fax_parms[7].length >= 3) && (fax_parms[7].info[1] >= 2))
  3454. plci->nsf_control_bits = GET_WORD(&fax_parms[7].info[2]);
  3455. plci->fax_connect_info_buffer[len++] = (byte)(fax_parms[7].length);
  3456. for (i = 0; i < fax_parms[7].length; i++)
  3457. plci->fax_connect_info_buffer[len++] = fax_parms[7].info[1+i];
  3458. }
  3459. plci->fax_connect_info_length = len;
  3460. plci->fax_edata_ack_length = plci->fax_connect_info_length;
  3461. start_internal_command (Id, plci, fax_edata_ack_command);
  3462. break;
  3463. }
  3464. return FALSE;
  3465. }
  3466. /*------------------------------------------------------------------*/
  3467. /* IDI callback function */
  3468. /*------------------------------------------------------------------*/
  3469. void callback(ENTITY * e)
  3470. {
  3471. DIVA_CAPI_ADAPTER * a;
  3472. APPL * appl;
  3473. PLCI * plci;
  3474. CAPI_MSG *m;
  3475. word i, j;
  3476. byte rc;
  3477. byte ch;
  3478. byte req;
  3479. byte global_req;
  3480. int no_cancel_rc;
  3481. dbug(1,dprintf("%x:CB(%x:Req=%x,Rc=%x,Ind=%x)",
  3482. (e->user[0]+1)&0x7fff,e->Id,e->Req,e->Rc,e->Ind));
  3483. a = &(adapter[(byte)e->user[0]]);
  3484. plci = &(a->plci[e->user[1]]);
  3485. no_cancel_rc = DIVA_CAPI_SUPPORTS_NO_CANCEL(a);
  3486. /*
  3487. If new protocol code and new XDI is used then CAPI should work
  3488. fully in accordance with IDI cpec an look on callback field instead
  3489. of Rc field for return codes.
  3490. */
  3491. if (((e->complete == 0xff) && no_cancel_rc) ||
  3492. (e->Rc && !no_cancel_rc)) {
  3493. rc = e->Rc;
  3494. ch = e->RcCh;
  3495. req = e->Req;
  3496. e->Rc = 0;
  3497. if (e->user[0] & 0x8000)
  3498. {
  3499. /*
  3500. If REMOVE request was sent then we have to wait until
  3501. return code with Id set to zero arrives.
  3502. All other return codes should be ignored.
  3503. */
  3504. if (req == REMOVE)
  3505. {
  3506. if (e->Id)
  3507. {
  3508. dbug(1,dprintf("cancel RC in REMOVE state"));
  3509. return;
  3510. }
  3511. channel_flow_control_remove (plci);
  3512. for (i = 0; i < 256; i++)
  3513. {
  3514. if (a->FlowControlIdTable[i] == plci->nl_remove_id)
  3515. a->FlowControlIdTable[i] = 0;
  3516. }
  3517. plci->nl_remove_id = 0;
  3518. if (plci->rx_dma_descriptor > 0) {
  3519. diva_free_dma_descriptor (plci, plci->rx_dma_descriptor - 1);
  3520. plci->rx_dma_descriptor = 0;
  3521. }
  3522. }
  3523. if (rc == OK_FC)
  3524. {
  3525. a->FlowControlIdTable[ch] = e->Id;
  3526. a->FlowControlSkipTable[ch] = 0;
  3527. a->ch_flow_control[ch] |= N_OK_FC_PENDING;
  3528. a->ch_flow_plci[ch] = plci->Id;
  3529. plci->nl_req = 0;
  3530. }
  3531. else
  3532. {
  3533. /*
  3534. Cancel return codes self, if feature was requested
  3535. */
  3536. if (no_cancel_rc && (a->FlowControlIdTable[ch] == e->Id) && e->Id) {
  3537. a->FlowControlIdTable[ch] = 0;
  3538. if ((rc == OK) && a->FlowControlSkipTable[ch]) {
  3539. dbug(3,dprintf ("XDI CAPI: RC cancelled Id:0x02, Ch:%02x", e->Id, ch));
  3540. return;
  3541. }
  3542. }
  3543. if (a->ch_flow_control[ch] & N_OK_FC_PENDING)
  3544. {
  3545. a->ch_flow_control[ch] &= ~N_OK_FC_PENDING;
  3546. if (ch == e->ReqCh)
  3547. plci->nl_req = 0;
  3548. }
  3549. else
  3550. plci->nl_req = 0;
  3551. }
  3552. if (plci->nl_req)
  3553. control_rc (plci, 0, rc, ch, 0, TRUE);
  3554. else
  3555. {
  3556. if (req == N_XON)
  3557. {
  3558. channel_x_on (plci, ch);
  3559. if (plci->internal_command)
  3560. control_rc (plci, req, rc, ch, 0, TRUE);
  3561. }
  3562. else
  3563. {
  3564. if (plci->nl_global_req)
  3565. {
  3566. global_req = plci->nl_global_req;
  3567. plci->nl_global_req = 0;
  3568. if (rc != ASSIGN_OK) {
  3569. e->Id = 0;
  3570. if (plci->rx_dma_descriptor > 0) {
  3571. diva_free_dma_descriptor (plci, plci->rx_dma_descriptor - 1);
  3572. plci->rx_dma_descriptor = 0;
  3573. }
  3574. }
  3575. channel_xmit_xon (plci);
  3576. control_rc (plci, 0, rc, ch, global_req, TRUE);
  3577. }
  3578. else if (plci->data_sent)
  3579. {
  3580. channel_xmit_xon (plci);
  3581. plci->data_sent = FALSE;
  3582. plci->NL.XNum = 1;
  3583. data_rc (plci, ch);
  3584. if (plci->internal_command)
  3585. control_rc (plci, req, rc, ch, 0, TRUE);
  3586. }
  3587. else
  3588. {
  3589. channel_xmit_xon (plci);
  3590. control_rc (plci, req, rc, ch, 0, TRUE);
  3591. }
  3592. }
  3593. }
  3594. }
  3595. else
  3596. {
  3597. /*
  3598. If REMOVE request was sent then we have to wait until
  3599. return code with Id set to zero arrives.
  3600. All other return codes should be ignored.
  3601. */
  3602. if (req == REMOVE)
  3603. {
  3604. if (e->Id)
  3605. {
  3606. dbug(1,dprintf("cancel RC in REMOVE state"));
  3607. return;
  3608. }
  3609. plci->sig_remove_id = 0;
  3610. }
  3611. plci->sig_req = 0;
  3612. if (plci->sig_global_req)
  3613. {
  3614. global_req = plci->sig_global_req;
  3615. plci->sig_global_req = 0;
  3616. if (rc != ASSIGN_OK)
  3617. e->Id = 0;
  3618. channel_xmit_xon (plci);
  3619. control_rc (plci, 0, rc, ch, global_req, FALSE);
  3620. }
  3621. else
  3622. {
  3623. channel_xmit_xon (plci);
  3624. control_rc (plci, req, rc, ch, 0, FALSE);
  3625. }
  3626. }
  3627. /*
  3628. Again: in accordance with IDI spec Rc and Ind can't be delivered in the
  3629. same callback. Also if new XDI and protocol code used then jump
  3630. direct to finish.
  3631. */
  3632. if (no_cancel_rc) {
  3633. channel_xmit_xon(plci);
  3634. goto capi_callback_suffix;
  3635. }
  3636. }
  3637. channel_xmit_xon(plci);
  3638. if (e->Ind) {
  3639. if (e->user[0] &0x8000) {
  3640. byte Ind = e->Ind & 0x0f;
  3641. byte Ch = e->IndCh;
  3642. if (((Ind==N_DISC) || (Ind==N_DISC_ACK)) &&
  3643. (a->ch_flow_plci[Ch] == plci->Id)) {
  3644. if (a->ch_flow_control[Ch] & N_RX_FLOW_CONTROL_MASK) {
  3645. dbug(3,dprintf ("XDI CAPI: I: pending N-XON Ch:%02x", Ch));
  3646. }
  3647. a->ch_flow_control[Ch] &= ~N_RX_FLOW_CONTROL_MASK;
  3648. }
  3649. nl_ind(plci);
  3650. if ((e->RNR != 1) &&
  3651. (a->ch_flow_plci[Ch] == plci->Id) &&
  3652. (a->ch_flow_control[Ch] & N_RX_FLOW_CONTROL_MASK)) {
  3653. a->ch_flow_control[Ch] &= ~N_RX_FLOW_CONTROL_MASK;
  3654. dbug(3,dprintf ("XDI CAPI: I: remove faked N-XON Ch:%02x", Ch));
  3655. }
  3656. } else {
  3657. sig_ind(plci);
  3658. }
  3659. e->Ind = 0;
  3660. }
  3661. capi_callback_suffix:
  3662. while (!plci->req_in
  3663. && !plci->internal_command
  3664. && (plci->msg_in_write_pos != plci->msg_in_read_pos))
  3665. {
  3666. j = (plci->msg_in_read_pos == plci->msg_in_wrap_pos) ? 0 : plci->msg_in_read_pos;
  3667. i = (((CAPI_MSG *)(&((byte *)(plci->msg_in_queue))[j]))->header.length + 3) & 0xfffc;
  3668. m = (CAPI_MSG *)(&((byte *)(plci->msg_in_queue))[j]);
  3669. appl = *((APPL * *)(&((byte *)(plci->msg_in_queue))[j+i]));
  3670. dbug(1,dprintf("dequeue msg(0x%04x) - write=%d read=%d wrap=%d",
  3671. m->header.command, plci->msg_in_write_pos, plci->msg_in_read_pos, plci->msg_in_wrap_pos));
  3672. if (plci->msg_in_read_pos == plci->msg_in_wrap_pos)
  3673. {
  3674. plci->msg_in_wrap_pos = MSG_IN_QUEUE_SIZE;
  3675. plci->msg_in_read_pos = i + MSG_IN_OVERHEAD;
  3676. }
  3677. else
  3678. {
  3679. plci->msg_in_read_pos = j + i + MSG_IN_OVERHEAD;
  3680. }
  3681. if (plci->msg_in_read_pos == plci->msg_in_write_pos)
  3682. {
  3683. plci->msg_in_write_pos = MSG_IN_QUEUE_SIZE;
  3684. plci->msg_in_read_pos = MSG_IN_QUEUE_SIZE;
  3685. }
  3686. else if (plci->msg_in_read_pos == plci->msg_in_wrap_pos)
  3687. {
  3688. plci->msg_in_read_pos = MSG_IN_QUEUE_SIZE;
  3689. plci->msg_in_wrap_pos = MSG_IN_QUEUE_SIZE;
  3690. }
  3691. i = api_put (appl, m);
  3692. if (i != 0)
  3693. {
  3694. if (m->header.command == _DATA_B3_R)
  3695. TransmitBufferFree (appl, (byte *)(m->info.data_b3_req.Data));
  3696. dbug(1,dprintf("Error 0x%04x from msg(0x%04x)", i, m->header.command));
  3697. break;
  3698. }
  3699. if (plci->li_notify_update)
  3700. {
  3701. plci->li_notify_update = FALSE;
  3702. mixer_notify_update (plci, FALSE);
  3703. }
  3704. }
  3705. send_data(plci);
  3706. send_req(plci);
  3707. }
  3708. void control_rc(PLCI * plci, byte req, byte rc, byte ch, byte global_req, byte nl_rc)
  3709. {
  3710. dword Id;
  3711. dword rId;
  3712. word Number;
  3713. word Info=0;
  3714. word i;
  3715. word ncci;
  3716. DIVA_CAPI_ADAPTER * a;
  3717. APPL * appl;
  3718. PLCI * rplci;
  3719. byte SSparms[] = "\x05\x00\x00\x02\x00\x00";
  3720. byte SSstruct[] = "\x09\x00\x00\x06\x00\x00\x00\x00\x00\x00";
  3721. if (!plci) {
  3722. dbug(0,dprintf("A: control_rc, no plci %02x:%02x:%02x:%02x:%02x", req, rc, ch, global_req, nl_rc));
  3723. return;
  3724. }
  3725. dbug(1,dprintf("req0_in/out=%d/%d",plci->req_in,plci->req_out));
  3726. if(plci->req_in!=plci->req_out)
  3727. {
  3728. if (nl_rc || (global_req != ASSIGN) || (rc == ASSIGN_OK))
  3729. {
  3730. dbug(1,dprintf("req_1return"));
  3731. return;
  3732. }
  3733. /* cancel outstanding request on the PLCI after SIG ASSIGN failure */
  3734. }
  3735. plci->req_in = plci->req_in_start = plci->req_out = 0;
  3736. dbug(1,dprintf("control_rc"));
  3737. appl = plci->appl;
  3738. a = plci->adapter;
  3739. ncci = a->ch_ncci[ch];
  3740. if(appl)
  3741. {
  3742. Id = (((dword)(ncci ? ncci : ch)) << 16) | ((word)plci->Id << 8) | a->Id;
  3743. if(plci->tel && plci->SuppState!=CALL_HELD) Id|=EXT_CONTROLLER;
  3744. Number = plci->number;
  3745. 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));
  3746. dbug(1,dprintf("channels=0x%x",plci->channels));
  3747. if (plci_remove_check(plci))
  3748. return;
  3749. if(req==REMOVE && rc==ASSIGN_OK)
  3750. {
  3751. sig_req(plci,HANGUP,0);
  3752. sig_req(plci,REMOVE,0);
  3753. send_req(plci);
  3754. }
  3755. if(plci->command)
  3756. {
  3757. switch(plci->command)
  3758. {
  3759. case C_HOLD_REQ:
  3760. dbug(1,dprintf("HoldRC=0x%x",rc));
  3761. SSparms[1] = (byte)S_HOLD;
  3762. if(rc!=OK)
  3763. {
  3764. plci->SuppState = IDLE;
  3765. Info = 0x2001;
  3766. }
  3767. sendf(appl,_FACILITY_R|CONFIRM,Id,Number,"wws",Info,3,SSparms);
  3768. break;
  3769. case C_RETRIEVE_REQ:
  3770. dbug(1,dprintf("RetrieveRC=0x%x",rc));
  3771. SSparms[1] = (byte)S_RETRIEVE;
  3772. if(rc!=OK)
  3773. {
  3774. plci->SuppState = CALL_HELD;
  3775. Info = 0x2001;
  3776. }
  3777. sendf(appl,_FACILITY_R|CONFIRM,Id,Number,"wws",Info,3,SSparms);
  3778. break;
  3779. case _INFO_R:
  3780. dbug(1,dprintf("InfoRC=0x%x",rc));
  3781. if(rc!=OK) Info=_WRONG_STATE;
  3782. sendf(appl,_INFO_R|CONFIRM,Id,Number,"w",Info);
  3783. break;
  3784. case _CONNECT_R:
  3785. dbug(1,dprintf("Connect_R=0x%x/0x%x/0x%x/0x%x",req,rc,global_req,nl_rc));
  3786. if (plci->State == INC_DIS_PENDING)
  3787. break;
  3788. if(plci->Sig.Id!=0xff)
  3789. {
  3790. if (((global_req == ASSIGN) && (rc != ASSIGN_OK))
  3791. || (!nl_rc && (req == CALL_REQ) && (rc != OK)))
  3792. {
  3793. dbug(1,dprintf("No more IDs/Call_Req failed"));
  3794. sendf(appl,_CONNECT_R|CONFIRM,Id&0xffL,Number,"w",_OUT_OF_PLCI);
  3795. plci_remove(plci);
  3796. plci->State = IDLE;
  3797. break;
  3798. }
  3799. if(plci->State!=LOCAL_CONNECT)plci->State = OUTG_CON_PENDING;
  3800. sendf(appl,_CONNECT_R|CONFIRM,Id,Number,"w",0);
  3801. }
  3802. else /* D-ch activation */
  3803. {
  3804. if (rc != ASSIGN_OK)
  3805. {
  3806. dbug(1,dprintf("No more IDs/X.25 Call_Req failed"));
  3807. sendf(appl,_CONNECT_R|CONFIRM,Id&0xffL,Number,"w",_OUT_OF_PLCI);
  3808. plci_remove(plci);
  3809. plci->State = IDLE;
  3810. break;
  3811. }
  3812. sendf(appl,_CONNECT_R|CONFIRM,Id,Number,"w",0);
  3813. sendf(plci->appl,_CONNECT_ACTIVE_I,Id,0,"sss","","","");
  3814. plci->State = INC_ACT_PENDING;
  3815. }
  3816. break;
  3817. case _CONNECT_I|RESPONSE:
  3818. if (plci->State != INC_DIS_PENDING)
  3819. plci->State = INC_CON_ACCEPT;
  3820. break;
  3821. case _DISCONNECT_R:
  3822. if (plci->State == INC_DIS_PENDING)
  3823. break;
  3824. if(plci->Sig.Id!=0xff)
  3825. {
  3826. plci->State = OUTG_DIS_PENDING;
  3827. sendf(appl,_DISCONNECT_R|CONFIRM,Id,Number,"w",0);
  3828. }
  3829. break;
  3830. case SUSPEND_REQ:
  3831. break;
  3832. case RESUME_REQ:
  3833. break;
  3834. case _CONNECT_B3_R:
  3835. if(rc!=OK)
  3836. {
  3837. sendf(appl,_CONNECT_B3_R|CONFIRM,Id,Number,"w",_WRONG_IDENTIFIER);
  3838. break;
  3839. }
  3840. ncci = get_ncci (plci, ch, 0);
  3841. Id = (Id & 0xffff) | (((dword) ncci) << 16);
  3842. plci->channels++;
  3843. if(req==N_RESET)
  3844. {
  3845. a->ncci_state[ncci] = INC_ACT_PENDING;
  3846. sendf(appl,_CONNECT_B3_R|CONFIRM,Id,Number,"w",0);
  3847. sendf(appl,_CONNECT_B3_ACTIVE_I,Id,0,"s","");
  3848. }
  3849. else
  3850. {
  3851. a->ncci_state[ncci] = OUTG_CON_PENDING;
  3852. sendf(appl,_CONNECT_B3_R|CONFIRM,Id,Number,"w",0);
  3853. }
  3854. break;
  3855. case _CONNECT_B3_I|RESPONSE:
  3856. break;
  3857. case _RESET_B3_R:
  3858. /* sendf(appl,_RESET_B3_R|CONFIRM,Id,Number,"w",0);*/
  3859. break;
  3860. case _DISCONNECT_B3_R:
  3861. sendf(appl,_DISCONNECT_B3_R|CONFIRM,Id,Number,"w",0);
  3862. break;
  3863. case _MANUFACTURER_R:
  3864. break;
  3865. case PERM_LIST_REQ:
  3866. if(rc!=OK)
  3867. {
  3868. Info = _WRONG_IDENTIFIER;
  3869. sendf(plci->appl,_CONNECT_R|CONFIRM,Id,Number,"w",Info);
  3870. plci_remove(plci);
  3871. }
  3872. else
  3873. sendf(plci->appl,_CONNECT_R|CONFIRM,Id,Number,"w",Info);
  3874. break;
  3875. default:
  3876. break;
  3877. }
  3878. plci->command = 0;
  3879. }
  3880. else if (plci->internal_command)
  3881. {
  3882. switch(plci->internal_command)
  3883. {
  3884. case BLOCK_PLCI:
  3885. return;
  3886. case GET_MWI_STATE:
  3887. if(rc==OK) /* command supported, wait for indication */
  3888. {
  3889. return;
  3890. }
  3891. plci_remove(plci);
  3892. break;
  3893. /* Get Supported Services */
  3894. case GETSERV_REQ_PEND:
  3895. if(rc==OK) /* command supported, wait for indication */
  3896. {
  3897. break;
  3898. }
  3899. PUT_DWORD(&SSstruct[6], MASK_TERMINAL_PORTABILITY);
  3900. sendf(appl, _FACILITY_R|CONFIRM, Id, Number, "wws",0,3,SSstruct);
  3901. plci_remove(plci);
  3902. break;
  3903. case INTERR_DIVERSION_REQ_PEND: /* Interrogate Parameters */
  3904. case INTERR_NUMBERS_REQ_PEND:
  3905. case CF_START_PEND: /* Call Forwarding Start pending */
  3906. case CF_STOP_PEND: /* Call Forwarding Stop pending */
  3907. case CCBS_REQUEST_REQ_PEND:
  3908. case CCBS_DEACTIVATE_REQ_PEND:
  3909. case CCBS_INTERROGATE_REQ_PEND:
  3910. switch(plci->internal_command)
  3911. {
  3912. case INTERR_DIVERSION_REQ_PEND:
  3913. SSparms[1] = S_INTERROGATE_DIVERSION;
  3914. break;
  3915. case INTERR_NUMBERS_REQ_PEND:
  3916. SSparms[1] = S_INTERROGATE_NUMBERS;
  3917. break;
  3918. case CF_START_PEND:
  3919. SSparms[1] = S_CALL_FORWARDING_START;
  3920. break;
  3921. case CF_STOP_PEND:
  3922. SSparms[1] = S_CALL_FORWARDING_STOP;
  3923. break;
  3924. case CCBS_REQUEST_REQ_PEND:
  3925. SSparms[1] = S_CCBS_REQUEST;
  3926. break;
  3927. case CCBS_DEACTIVATE_REQ_PEND:
  3928. SSparms[1] = S_CCBS_DEACTIVATE;
  3929. break;
  3930. case CCBS_INTERROGATE_REQ_PEND:
  3931. SSparms[1] = S_CCBS_INTERROGATE;
  3932. break;
  3933. }
  3934. if(global_req==ASSIGN)
  3935. {
  3936. dbug(1,dprintf("AssignDiversion_RC=0x%x/0x%x",req,rc));
  3937. return;
  3938. }
  3939. if(!plci->appl) break;
  3940. if(rc==ISDN_GUARD_REJ)
  3941. {
  3942. Info = _CAPI_GUARD_ERROR;
  3943. }
  3944. else if(rc!=OK)
  3945. {
  3946. Info = _SUPPLEMENTARY_SERVICE_NOT_SUPPORTED;
  3947. }
  3948. sendf(plci->appl,_FACILITY_R|CONFIRM,Id&0x7,
  3949. plci->number,"wws",Info,(word)3,SSparms);
  3950. if(Info) plci_remove(plci);
  3951. break;
  3952. /* 3pty conference pending */
  3953. case PTY_REQ_PEND:
  3954. if(!plci->relatedPTYPLCI) break;
  3955. rplci = plci->relatedPTYPLCI;
  3956. SSparms[1] = plci->ptyState;
  3957. rId = ((word)rplci->Id<<8)|rplci->adapter->Id;
  3958. if(rplci->tel) rId|=EXT_CONTROLLER;
  3959. if(rc!=OK)
  3960. {
  3961. Info = 0x300E; /* not supported */
  3962. plci->relatedPTYPLCI = NULL;
  3963. plci->ptyState = 0;
  3964. }
  3965. sendf(rplci->appl,
  3966. _FACILITY_R|CONFIRM,
  3967. rId,
  3968. plci->number,
  3969. "wws",Info,(word)3,SSparms);
  3970. break;
  3971. /* Explicit Call Transfer pending */
  3972. case ECT_REQ_PEND:
  3973. dbug(1,dprintf("ECT_RC=0x%x/0x%x",req,rc));
  3974. if(!plci->relatedPTYPLCI) break;
  3975. rplci = plci->relatedPTYPLCI;
  3976. SSparms[1] = S_ECT;
  3977. rId = ((word)rplci->Id<<8)|rplci->adapter->Id;
  3978. if(rplci->tel) rId|=EXT_CONTROLLER;
  3979. if(rc!=OK)
  3980. {
  3981. Info = 0x300E; /* not supported */
  3982. plci->relatedPTYPLCI = NULL;
  3983. plci->ptyState = 0;
  3984. }
  3985. sendf(rplci->appl,
  3986. _FACILITY_R|CONFIRM,
  3987. rId,
  3988. plci->number,
  3989. "wws",Info,(word)3,SSparms);
  3990. break;
  3991. case _MANUFACTURER_R:
  3992. dbug(1,dprintf("_Manufacturer_R=0x%x/0x%x",req,rc));
  3993. if ((global_req == ASSIGN) && (rc != ASSIGN_OK))
  3994. {
  3995. dbug(1,dprintf("No more IDs"));
  3996. sendf(appl,_MANUFACTURER_R|CONFIRM,Id,Number,"dww",_DI_MANU_ID,_MANUFACTURER_R,_OUT_OF_PLCI);
  3997. plci_remove(plci); /* after codec init, internal codec commands pending */
  3998. }
  3999. break;
  4000. case _CONNECT_R:
  4001. dbug(1,dprintf("_Connect_R=0x%x/0x%x",req,rc));
  4002. if ((global_req == ASSIGN) && (rc != ASSIGN_OK))
  4003. {
  4004. dbug(1,dprintf("No more IDs"));
  4005. sendf(appl,_CONNECT_R|CONFIRM,Id&0xffL,Number,"w",_OUT_OF_PLCI);
  4006. plci_remove(plci); /* after codec init, internal codec commands pending */
  4007. }
  4008. break;
  4009. case PERM_COD_HOOK: /* finished with Hook_Ind */
  4010. return;
  4011. case PERM_COD_CALL:
  4012. dbug(1,dprintf("***Codec Connect_Pending A, Rc = 0x%x",rc));
  4013. plci->internal_command = PERM_COD_CONN_PEND;
  4014. return;
  4015. case PERM_COD_ASSIGN:
  4016. dbug(1,dprintf("***Codec Assign A, Rc = 0x%x",rc));
  4017. if(rc!=ASSIGN_OK) break;
  4018. sig_req(plci,CALL_REQ,0);
  4019. send_req(plci);
  4020. plci->internal_command = PERM_COD_CALL;
  4021. return;
  4022. /* Null Call Reference Request pending */
  4023. case C_NCR_FAC_REQ:
  4024. dbug(1,dprintf("NCR_FAC=0x%x/0x%x",req,rc));
  4025. if(global_req==ASSIGN)
  4026. {
  4027. if(rc==ASSIGN_OK)
  4028. {
  4029. return;
  4030. }
  4031. else
  4032. {
  4033. sendf(appl,_INFO_R|CONFIRM,Id&0xf,Number,"w",_WRONG_STATE);
  4034. appl->NullCREnable = FALSE;
  4035. plci_remove(plci);
  4036. }
  4037. }
  4038. else if(req==NCR_FACILITY)
  4039. {
  4040. if(rc==OK)
  4041. {
  4042. sendf(appl,_INFO_R|CONFIRM,Id&0xf,Number,"w",0);
  4043. }
  4044. else
  4045. {
  4046. sendf(appl,_INFO_R|CONFIRM,Id&0xf,Number,"w",_WRONG_STATE);
  4047. appl->NullCREnable = FALSE;
  4048. }
  4049. plci_remove(plci);
  4050. }
  4051. break;
  4052. case HOOK_ON_REQ:
  4053. if(plci->channels)
  4054. {
  4055. if(a->ncci_state[ncci]==CONNECTED)
  4056. {
  4057. a->ncci_state[ncci] = OUTG_DIS_PENDING;
  4058. cleanup_ncci_data (plci, ncci);
  4059. nl_req_ncci(plci,N_DISC,(byte)ncci);
  4060. }
  4061. break;
  4062. }
  4063. break;
  4064. case HOOK_OFF_REQ:
  4065. if (plci->State == INC_DIS_PENDING)
  4066. break;
  4067. sig_req(plci,CALL_REQ,0);
  4068. send_req(plci);
  4069. plci->State=OUTG_CON_PENDING;
  4070. break;
  4071. case MWI_ACTIVATE_REQ_PEND:
  4072. case MWI_DEACTIVATE_REQ_PEND:
  4073. if(global_req == ASSIGN && rc==ASSIGN_OK)
  4074. {
  4075. dbug(1,dprintf("MWI_REQ assigned"));
  4076. return;
  4077. }
  4078. else if(rc!=OK)
  4079. {
  4080. if(rc==WRONG_IE)
  4081. {
  4082. Info = 0x2007; /* Illegal message parameter coding */
  4083. dbug(1,dprintf("MWI_REQ invalid parameter"));
  4084. }
  4085. else
  4086. {
  4087. Info = 0x300B; /* not supported */
  4088. dbug(1,dprintf("MWI_REQ not supported"));
  4089. }
  4090. /* 0x3010: Request not allowed in this state */
  4091. PUT_WORD(&SSparms[4],0x300E); /* SS not supported */
  4092. }
  4093. if(plci->internal_command==MWI_ACTIVATE_REQ_PEND)
  4094. {
  4095. PUT_WORD(&SSparms[1],S_MWI_ACTIVATE);
  4096. }
  4097. else PUT_WORD(&SSparms[1],S_MWI_DEACTIVATE);
  4098. if(plci->cr_enquiry)
  4099. {
  4100. sendf(plci->appl,
  4101. _FACILITY_R|CONFIRM,
  4102. Id&0xf,
  4103. plci->number,
  4104. "wws",Info,(word)3,SSparms);
  4105. if(rc!=OK) plci_remove(plci);
  4106. }
  4107. else
  4108. {
  4109. sendf(plci->appl,
  4110. _FACILITY_R|CONFIRM,
  4111. Id,
  4112. plci->number,
  4113. "wws",Info,(word)3,SSparms);
  4114. }
  4115. break;
  4116. case CONF_BEGIN_REQ_PEND:
  4117. case CONF_ADD_REQ_PEND:
  4118. case CONF_SPLIT_REQ_PEND:
  4119. case CONF_DROP_REQ_PEND:
  4120. case CONF_ISOLATE_REQ_PEND:
  4121. case CONF_REATTACH_REQ_PEND:
  4122. dbug(1,dprintf("CONF_RC=0x%x/0x%x",req,rc));
  4123. if((plci->internal_command==CONF_ADD_REQ_PEND)&&(!plci->relatedPTYPLCI)) break;
  4124. rplci = plci;
  4125. rId = Id;
  4126. switch(plci->internal_command)
  4127. {
  4128. case CONF_BEGIN_REQ_PEND:
  4129. SSparms[1] = S_CONF_BEGIN;
  4130. break;
  4131. case CONF_ADD_REQ_PEND:
  4132. SSparms[1] = S_CONF_ADD;
  4133. rplci = plci->relatedPTYPLCI;
  4134. rId = ((word)rplci->Id<<8)|rplci->adapter->Id;
  4135. break;
  4136. case CONF_SPLIT_REQ_PEND:
  4137. SSparms[1] = S_CONF_SPLIT;
  4138. break;
  4139. case CONF_DROP_REQ_PEND:
  4140. SSparms[1] = S_CONF_DROP;
  4141. break;
  4142. case CONF_ISOLATE_REQ_PEND:
  4143. SSparms[1] = S_CONF_ISOLATE;
  4144. break;
  4145. case CONF_REATTACH_REQ_PEND:
  4146. SSparms[1] = S_CONF_REATTACH;
  4147. break;
  4148. }
  4149. if(rc!=OK)
  4150. {
  4151. Info = 0x300E; /* not supported */
  4152. plci->relatedPTYPLCI = NULL;
  4153. plci->ptyState = 0;
  4154. }
  4155. sendf(rplci->appl,
  4156. _FACILITY_R|CONFIRM,
  4157. rId,
  4158. plci->number,
  4159. "wws",Info,(word)3,SSparms);
  4160. break;
  4161. case VSWITCH_REQ_PEND:
  4162. if(rc!=OK)
  4163. {
  4164. if(plci->relatedPTYPLCI)
  4165. {
  4166. plci->relatedPTYPLCI->vswitchstate=0;
  4167. plci->relatedPTYPLCI->vsprot=0;
  4168. plci->relatedPTYPLCI->vsprotdialect=0;
  4169. }
  4170. plci->vswitchstate=0;
  4171. plci->vsprot=0;
  4172. plci->vsprotdialect=0;
  4173. }
  4174. else
  4175. {
  4176. if(plci->relatedPTYPLCI &&
  4177. plci->vswitchstate==1 &&
  4178. plci->relatedPTYPLCI->vswitchstate==3) /* join complete */
  4179. plci->vswitchstate=3;
  4180. }
  4181. break;
  4182. /* Call Deflection Request pending (SSCT) */
  4183. case CD_REQ_PEND:
  4184. SSparms[1] = S_CALL_DEFLECTION;
  4185. if(rc!=OK)
  4186. {
  4187. Info = 0x300E; /* not supported */
  4188. plci->appl->CDEnable = 0;
  4189. }
  4190. sendf(plci->appl,_FACILITY_R|CONFIRM,Id,
  4191. plci->number,"wws",Info,(word)3,SSparms);
  4192. break;
  4193. case RTP_CONNECT_B3_REQ_COMMAND_2:
  4194. if (rc == OK)
  4195. {
  4196. ncci = get_ncci (plci, ch, 0);
  4197. Id = (Id & 0xffff) | (((dword) ncci) << 16);
  4198. plci->channels++;
  4199. a->ncci_state[ncci] = OUTG_CON_PENDING;
  4200. }
  4201. default:
  4202. if (plci->internal_command_queue[0])
  4203. {
  4204. (*(plci->internal_command_queue[0]))(Id, plci, rc);
  4205. if (plci->internal_command)
  4206. return;
  4207. }
  4208. break;
  4209. }
  4210. next_internal_command (Id, plci);
  4211. }
  4212. }
  4213. else /* appl==0 */
  4214. {
  4215. Id = ((word)plci->Id<<8)|plci->adapter->Id;
  4216. if(plci->tel) Id|=EXT_CONTROLLER;
  4217. switch(plci->internal_command)
  4218. {
  4219. case BLOCK_PLCI:
  4220. return;
  4221. case START_L1_SIG_ASSIGN_PEND:
  4222. case REM_L1_SIG_ASSIGN_PEND:
  4223. if(global_req == ASSIGN)
  4224. {
  4225. break;
  4226. }
  4227. else
  4228. {
  4229. dbug(1,dprintf("***L1 Req rem PLCI"));
  4230. plci->internal_command = 0;
  4231. sig_req(plci,REMOVE,0);
  4232. send_req(plci);
  4233. }
  4234. break;
  4235. /* Call Deflection Request pending, just no appl ptr assigned */
  4236. case CD_REQ_PEND:
  4237. SSparms[1] = S_CALL_DEFLECTION;
  4238. if(rc!=OK)
  4239. {
  4240. Info = 0x300E; /* not supported */
  4241. }
  4242. for(i=0; i<max_appl; i++)
  4243. {
  4244. if(application[i].CDEnable)
  4245. {
  4246. if(!application[i].Id) application[i].CDEnable = 0;
  4247. else
  4248. {
  4249. sendf(&application[i],_FACILITY_R|CONFIRM,Id,
  4250. plci->number,"wws",Info,(word)3,SSparms);
  4251. if(Info) application[i].CDEnable = 0;
  4252. }
  4253. }
  4254. }
  4255. plci->internal_command = 0;
  4256. break;
  4257. case PERM_COD_HOOK: /* finished with Hook_Ind */
  4258. return;
  4259. case PERM_COD_CALL:
  4260. plci->internal_command = PERM_COD_CONN_PEND;
  4261. dbug(1,dprintf("***Codec Connect_Pending, Rc = 0x%x",rc));
  4262. return;
  4263. case PERM_COD_ASSIGN:
  4264. dbug(1,dprintf("***Codec Assign, Rc = 0x%x",rc));
  4265. plci->internal_command = 0;
  4266. if(rc!=ASSIGN_OK) break;
  4267. plci->internal_command = PERM_COD_CALL;
  4268. sig_req(plci,CALL_REQ,0);
  4269. send_req(plci);
  4270. return;
  4271. case LISTEN_SIG_ASSIGN_PEND:
  4272. if(rc == ASSIGN_OK)
  4273. {
  4274. plci->internal_command = 0;
  4275. dbug(1,dprintf("ListenCheck, new SIG_ID = 0x%x",plci->Sig.Id));
  4276. add_p(plci,ESC,"\x02\x18\x00"); /* support call waiting */
  4277. sig_req(plci,INDICATE_REQ,0);
  4278. send_req(plci);
  4279. }
  4280. else
  4281. {
  4282. dbug(1,dprintf("ListenCheck failed (assignRc=0x%x)",rc));
  4283. a->listen_active--;
  4284. plci_remove(plci);
  4285. plci->State = IDLE;
  4286. }
  4287. break;
  4288. case USELAW_REQ:
  4289. if(global_req == ASSIGN)
  4290. {
  4291. if (rc==ASSIGN_OK)
  4292. {
  4293. sig_req(plci,LAW_REQ,0);
  4294. send_req(plci);
  4295. dbug(1,dprintf("Auto-Law assigned"));
  4296. }
  4297. else
  4298. {
  4299. dbug(1,dprintf("Auto-Law assign failed"));
  4300. a->automatic_law = 3;
  4301. plci->internal_command = 0;
  4302. a->automatic_lawPLCI = NULL;
  4303. }
  4304. break;
  4305. }
  4306. else if(req == LAW_REQ && rc==OK)
  4307. {
  4308. dbug(1,dprintf("Auto-Law initiated"));
  4309. a->automatic_law = 2;
  4310. plci->internal_command = 0;
  4311. }
  4312. else
  4313. {
  4314. dbug(1,dprintf("Auto-Law not supported"));
  4315. a->automatic_law = 3;
  4316. plci->internal_command = 0;
  4317. sig_req(plci,REMOVE,0);
  4318. send_req(plci);
  4319. a->automatic_lawPLCI = NULL;
  4320. }
  4321. break;
  4322. }
  4323. plci_remove_check(plci);
  4324. }
  4325. }
  4326. void data_rc(PLCI * plci, byte ch)
  4327. {
  4328. dword Id;
  4329. DIVA_CAPI_ADAPTER * a;
  4330. NCCI *ncci_ptr;
  4331. DATA_B3_DESC *data;
  4332. word ncci;
  4333. if (plci->appl)
  4334. {
  4335. TransmitBufferFree (plci->appl, plci->data_sent_ptr);
  4336. a = plci->adapter;
  4337. ncci = a->ch_ncci[ch];
  4338. if (ncci && (a->ncci_plci[ncci] == plci->Id))
  4339. {
  4340. ncci_ptr = &(a->ncci[ncci]);
  4341. dbug(1,dprintf("data_out=%d, data_pending=%d",ncci_ptr->data_out,ncci_ptr->data_pending));
  4342. if (ncci_ptr->data_pending)
  4343. {
  4344. data = &(ncci_ptr->DBuffer[ncci_ptr->data_out]);
  4345. if (!(data->Flags &4) && a->ncci_state[ncci])
  4346. {
  4347. Id = (((dword)ncci)<<16)|((word)plci->Id<<8)|a->Id;
  4348. if(plci->tel) Id|=EXT_CONTROLLER;
  4349. sendf(plci->appl,_DATA_B3_R|CONFIRM,Id,data->Number,
  4350. "ww",data->Handle,0);
  4351. }
  4352. (ncci_ptr->data_out)++;
  4353. if (ncci_ptr->data_out == MAX_DATA_B3)
  4354. ncci_ptr->data_out = 0;
  4355. (ncci_ptr->data_pending)--;
  4356. }
  4357. }
  4358. }
  4359. }
  4360. void data_ack(PLCI * plci, byte ch)
  4361. {
  4362. dword Id;
  4363. DIVA_CAPI_ADAPTER * a;
  4364. NCCI *ncci_ptr;
  4365. word ncci;
  4366. a = plci->adapter;
  4367. ncci = a->ch_ncci[ch];
  4368. ncci_ptr = &(a->ncci[ncci]);
  4369. if (ncci_ptr->data_ack_pending)
  4370. {
  4371. if (a->ncci_state[ncci] && (a->ncci_plci[ncci] == plci->Id))
  4372. {
  4373. Id = (((dword)ncci)<<16)|((word)plci->Id<<8)|a->Id;
  4374. if(plci->tel) Id|=EXT_CONTROLLER;
  4375. sendf(plci->appl,_DATA_B3_R|CONFIRM,Id,ncci_ptr->DataAck[ncci_ptr->data_ack_out].Number,
  4376. "ww",ncci_ptr->DataAck[ncci_ptr->data_ack_out].Handle,0);
  4377. }
  4378. (ncci_ptr->data_ack_out)++;
  4379. if (ncci_ptr->data_ack_out == MAX_DATA_ACK)
  4380. ncci_ptr->data_ack_out = 0;
  4381. (ncci_ptr->data_ack_pending)--;
  4382. }
  4383. }
  4384. void sig_ind(PLCI * plci)
  4385. {
  4386. dword x_Id;
  4387. dword Id;
  4388. dword rId;
  4389. word Number = 0;
  4390. word i;
  4391. word cip;
  4392. dword cip_mask;
  4393. byte *ie;
  4394. DIVA_CAPI_ADAPTER * a;
  4395. API_PARSE saved_parms[MAX_MSG_PARMS+1];
  4396. #define MAXPARMSIDS 31
  4397. byte * parms[MAXPARMSIDS];
  4398. byte * add_i[4];
  4399. byte * multi_fac_parms[MAX_MULTI_IE];
  4400. byte * multi_pi_parms [MAX_MULTI_IE];
  4401. byte * multi_ssext_parms [MAX_MULTI_IE];
  4402. byte * multi_CiPN_parms [MAX_MULTI_IE];
  4403. byte * multi_vswitch_parms [MAX_MULTI_IE];
  4404. byte ai_len;
  4405. byte *esc_chi = "";
  4406. byte *esc_law = "";
  4407. byte *pty_cai = "";
  4408. byte *esc_cr = "";
  4409. byte *esc_profile = "";
  4410. byte facility[256];
  4411. PLCI * tplci = NULL;
  4412. byte chi[] = "\x02\x18\x01";
  4413. byte voice_cai[] = "\x06\x14\x00\x00\x00\x00\x08";
  4414. byte resume_cau[] = "\x05\x05\x00\x02\x00\x00";
  4415. /* ESC_MSGTYPE must be the last but one message, a new IE has to be */
  4416. /* included before the ESC_MSGTYPE and MAXPARMSIDS has to be incremented */
  4417. /* SMSG is situated at the end because its 0 (for compatibility reasons */
  4418. /* (see Info_Mask Bit 4, first IE. then the message type) */
  4419. word parms_id[] =
  4420. {MAXPARMSIDS, CPN, 0xff, DSA, OSA, BC, LLC, HLC, ESC_CAUSE, DSP, DT, CHA,
  4421. UUI, CONG_RR, CONG_RNR, ESC_CHI, KEY, CHI, CAU, ESC_LAW,
  4422. RDN, RDX, CONN_NR, RIN, NI, CAI, ESC_CR,
  4423. CST, ESC_PROFILE, 0xff, ESC_MSGTYPE, SMSG};
  4424. /* 14 FTY repl by ESC_CHI */
  4425. /* 18 PI repl by ESC_LAW */
  4426. /* removed OAD changed to 0xff for future use, OAD is multiIE now */
  4427. word multi_fac_id[] = {1, FTY};
  4428. word multi_pi_id[] = {1, PI};
  4429. word multi_CiPN_id[] = {1, OAD};
  4430. word multi_ssext_id[] = {1, ESC_SSEXT};
  4431. word multi_vswitch_id[] = {1, ESC_VSWITCH};
  4432. byte * cau;
  4433. word ncci;
  4434. byte SS_Ind[] = "\x05\x02\x00\x02\x00\x00"; /* Hold_Ind struct*/
  4435. byte CF_Ind[] = "\x09\x02\x00\x06\x00\x00\x00\x00\x00\x00";
  4436. byte Interr_Err_Ind[] = "\x0a\x02\x00\x07\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00";
  4437. byte CONF_Ind[] = "\x09\x16\x00\x06\x00\x00\0x00\0x00\0x00\0x00";
  4438. byte force_mt_info = FALSE;
  4439. byte dir;
  4440. dword d;
  4441. word w;
  4442. a = plci->adapter;
  4443. Id = ((word)plci->Id<<8)|a->Id;
  4444. PUT_WORD(&SS_Ind[4],0x0000);
  4445. if (plci->sig_remove_id)
  4446. {
  4447. plci->Sig.RNR = 2; /* discard */
  4448. dbug(1,dprintf("SIG discard while remove pending"));
  4449. return;
  4450. }
  4451. if(plci->tel && plci->SuppState!=CALL_HELD) Id|=EXT_CONTROLLER;
  4452. dbug(1,dprintf("SigInd-Id=%08lx,plci=%x,tel=%x,state=0x%x,channels=%d,Discflowcl=%d",
  4453. Id,plci->Id,plci->tel,plci->State,plci->channels,plci->hangup_flow_ctrl_timer));
  4454. if(plci->Sig.Ind==CALL_HOLD_ACK && plci->channels)
  4455. {
  4456. plci->Sig.RNR = 1;
  4457. return;
  4458. }
  4459. if(plci->Sig.Ind==HANGUP && plci->channels)
  4460. {
  4461. plci->Sig.RNR = 1;
  4462. plci->hangup_flow_ctrl_timer++;
  4463. /* recover the network layer after timeout */
  4464. if(plci->hangup_flow_ctrl_timer==100)
  4465. {
  4466. dbug(1,dprintf("Exceptional disc"));
  4467. plci->Sig.RNR = 0;
  4468. plci->hangup_flow_ctrl_timer = 0;
  4469. for (ncci = 1; ncci < MAX_NCCI+1; ncci++)
  4470. {
  4471. if (a->ncci_plci[ncci] == plci->Id)
  4472. {
  4473. cleanup_ncci_data (plci, ncci);
  4474. if(plci->channels)plci->channels--;
  4475. if (plci->appl)
  4476. sendf(plci->appl,_DISCONNECT_B3_I, (((dword) ncci) << 16) | Id,0,"ws",0,"");
  4477. }
  4478. }
  4479. if (plci->appl)
  4480. sendf(plci->appl, _DISCONNECT_I, Id, 0, "w", 0);
  4481. plci_remove(plci);
  4482. plci->State=IDLE;
  4483. }
  4484. return;
  4485. }
  4486. /* do first parse the info with no OAD in, because OAD will be converted */
  4487. /* first the multiple facility IE, then mult. progress ind. */
  4488. /* then the parameters for the info_ind + conn_ind */
  4489. IndParse(plci,multi_fac_id,multi_fac_parms,MAX_MULTI_IE);
  4490. IndParse(plci,multi_pi_id,multi_pi_parms,MAX_MULTI_IE);
  4491. IndParse(plci,multi_ssext_id,multi_ssext_parms,MAX_MULTI_IE);
  4492. IndParse(plci,multi_vswitch_id,multi_vswitch_parms,MAX_MULTI_IE);
  4493. IndParse(plci,parms_id,parms,0);
  4494. IndParse(plci,multi_CiPN_id,multi_CiPN_parms,MAX_MULTI_IE);
  4495. esc_chi = parms[14];
  4496. esc_law = parms[18];
  4497. pty_cai = parms[24];
  4498. esc_cr = parms[25];
  4499. esc_profile = parms[27];
  4500. if(esc_cr[0] && plci)
  4501. {
  4502. if(plci->cr_enquiry && plci->appl)
  4503. {
  4504. plci->cr_enquiry = FALSE;
  4505. /* d = MANU_ID */
  4506. /* w = m_command */
  4507. /* b = total length */
  4508. /* b = indication type */
  4509. /* b = length of all IEs */
  4510. /* b = IE1 */
  4511. /* S = IE1 length + cont. */
  4512. /* b = IE2 */
  4513. /* S = IE2 lenght + cont. */
  4514. sendf(plci->appl,
  4515. _MANUFACTURER_I,
  4516. Id,
  4517. 0,
  4518. "dwbbbbSbS",_DI_MANU_ID,plci->m_command,
  4519. 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);
  4520. }
  4521. }
  4522. /* create the additional info structure */
  4523. add_i[1] = parms[15]; /* KEY of additional info */
  4524. add_i[2] = parms[11]; /* UUI of additional info */
  4525. ai_len = AddInfo(add_i,multi_fac_parms, esc_chi, facility);
  4526. /* the ESC_LAW indicates if u-Law or a-Law is actually used by the card */
  4527. /* indication returns by the card if requested by the function */
  4528. /* AutomaticLaw() after driver init */
  4529. if (a->automatic_law<4)
  4530. {
  4531. if(esc_law[0]){
  4532. if(esc_law[2]){
  4533. dbug(0,dprintf("u-Law selected"));
  4534. a->u_law = 1;
  4535. }
  4536. else {
  4537. dbug(0,dprintf("a-Law selected"));
  4538. a->u_law = 0;
  4539. }
  4540. a->automatic_law = 4;
  4541. if(plci==a->automatic_lawPLCI) {
  4542. plci->internal_command = 0;
  4543. sig_req(plci,REMOVE,0);
  4544. send_req(plci);
  4545. a->automatic_lawPLCI = NULL;
  4546. }
  4547. }
  4548. if (esc_profile[0])
  4549. {
  4550. dbug (1, dprintf ("[%06x] CardProfile: %lx %lx %lx %lx %lx",
  4551. UnMapController (a->Id), GET_DWORD (&esc_profile[6]),
  4552. GET_DWORD (&esc_profile[10]), GET_DWORD (&esc_profile[14]),
  4553. GET_DWORD (&esc_profile[18]), GET_DWORD (&esc_profile[46])));
  4554. a->profile.Global_Options &= 0x000000ffL;
  4555. a->profile.B1_Protocols &= 0x000003ffL;
  4556. a->profile.B2_Protocols &= 0x00001fdfL;
  4557. a->profile.B3_Protocols &= 0x000000b7L;
  4558. a->profile.Global_Options &= GET_DWORD (&esc_profile[6]) |
  4559. GL_BCHANNEL_OPERATION_SUPPORTED;
  4560. a->profile.B1_Protocols &= GET_DWORD (&esc_profile[10]);
  4561. a->profile.B2_Protocols &= GET_DWORD (&esc_profile[14]);
  4562. a->profile.B3_Protocols &= GET_DWORD (&esc_profile[18]);
  4563. a->manufacturer_features = GET_DWORD (&esc_profile[46]);
  4564. a->man_profile.private_options = 0;
  4565. if (a->manufacturer_features & MANUFACTURER_FEATURE_ECHO_CANCELLER)
  4566. {
  4567. a->man_profile.private_options |= 1L << PRIVATE_ECHO_CANCELLER;
  4568. a->profile.Global_Options |= GL_ECHO_CANCELLER_SUPPORTED;
  4569. }
  4570. if (a->manufacturer_features & MANUFACTURER_FEATURE_RTP)
  4571. a->man_profile.private_options |= 1L << PRIVATE_RTP;
  4572. a->man_profile.rtp_primary_payloads = GET_DWORD (&esc_profile[50]);
  4573. a->man_profile.rtp_additional_payloads = GET_DWORD (&esc_profile[54]);
  4574. if (a->manufacturer_features & MANUFACTURER_FEATURE_T38)
  4575. a->man_profile.private_options |= 1L << PRIVATE_T38;
  4576. if (a->manufacturer_features & MANUFACTURER_FEATURE_FAX_SUB_SEP_PWD)
  4577. a->man_profile.private_options |= 1L << PRIVATE_FAX_SUB_SEP_PWD;
  4578. if (a->manufacturer_features & MANUFACTURER_FEATURE_V18)
  4579. a->man_profile.private_options |= 1L << PRIVATE_V18;
  4580. if (a->manufacturer_features & MANUFACTURER_FEATURE_DTMF_TONE)
  4581. a->man_profile.private_options |= 1L << PRIVATE_DTMF_TONE;
  4582. if (a->manufacturer_features & MANUFACTURER_FEATURE_PIAFS)
  4583. a->man_profile.private_options |= 1L << PRIVATE_PIAFS;
  4584. if (a->manufacturer_features & MANUFACTURER_FEATURE_FAX_PAPER_FORMATS)
  4585. a->man_profile.private_options |= 1L << PRIVATE_FAX_PAPER_FORMATS;
  4586. if (a->manufacturer_features & MANUFACTURER_FEATURE_VOWN)
  4587. a->man_profile.private_options |= 1L << PRIVATE_VOWN;
  4588. if (a->manufacturer_features & MANUFACTURER_FEATURE_FAX_NONSTANDARD)
  4589. a->man_profile.private_options |= 1L << PRIVATE_FAX_NONSTANDARD;
  4590. }
  4591. else
  4592. {
  4593. a->profile.Global_Options &= 0x0000007fL;
  4594. a->profile.B1_Protocols &= 0x000003dfL;
  4595. a->profile.B2_Protocols &= 0x00001adfL;
  4596. a->profile.B3_Protocols &= 0x000000b7L;
  4597. a->manufacturer_features &= MANUFACTURER_FEATURE_HARDDTMF;
  4598. }
  4599. if (a->manufacturer_features & (MANUFACTURER_FEATURE_HARDDTMF |
  4600. MANUFACTURER_FEATURE_SOFTDTMF_SEND | MANUFACTURER_FEATURE_SOFTDTMF_RECEIVE))
  4601. {
  4602. a->profile.Global_Options |= GL_DTMF_SUPPORTED;
  4603. }
  4604. a->manufacturer_features &= ~MANUFACTURER_FEATURE_OOB_CHANNEL;
  4605. dbug (1, dprintf ("[%06x] Profile: %lx %lx %lx %lx %lx",
  4606. UnMapController (a->Id), a->profile.Global_Options,
  4607. a->profile.B1_Protocols, a->profile.B2_Protocols,
  4608. a->profile.B3_Protocols, a->manufacturer_features));
  4609. }
  4610. /* codec plci for the handset/hook state support is just an internal id */
  4611. if(plci!=a->AdvCodecPLCI)
  4612. {
  4613. force_mt_info = SendMultiIE(plci,Id,multi_fac_parms, FTY, 0x20, 0);
  4614. force_mt_info |= SendMultiIE(plci,Id,multi_pi_parms, PI, 0x210, 0);
  4615. SendSSExtInd(NULL,plci,Id,multi_ssext_parms);
  4616. SendInfo(plci,Id, parms, force_mt_info);
  4617. VSwitchReqInd(plci,Id,multi_vswitch_parms);
  4618. }
  4619. /* switch the codec to the b-channel */
  4620. if(esc_chi[0] && plci && !plci->SuppState){
  4621. plci->b_channel = esc_chi[esc_chi[0]]&0x1f;
  4622. mixer_set_bchannel_id_esc (plci, plci->b_channel);
  4623. dbug(1,dprintf("storeChannel=0x%x",plci->b_channel));
  4624. if(plci->tel==ADV_VOICE && plci->appl) {
  4625. SetVoiceChannel(a->AdvCodecPLCI, esc_chi, a);
  4626. }
  4627. }
  4628. if(plci->appl) Number = plci->appl->Number++;
  4629. switch(plci->Sig.Ind) {
  4630. /* Response to Get_Supported_Services request */
  4631. case S_SUPPORTED:
  4632. dbug(1,dprintf("S_Supported"));
  4633. if(!plci->appl) break;
  4634. if(pty_cai[0]==4)
  4635. {
  4636. PUT_DWORD(&CF_Ind[6],GET_DWORD(&pty_cai[1]) );
  4637. }
  4638. else
  4639. {
  4640. PUT_DWORD(&CF_Ind[6],MASK_TERMINAL_PORTABILITY | MASK_HOLD_RETRIEVE);
  4641. }
  4642. PUT_WORD (&CF_Ind[1], 0);
  4643. PUT_WORD (&CF_Ind[4], 0);
  4644. sendf(plci->appl,_FACILITY_R|CONFIRM,Id&0x7,plci->number, "wws",0,3,CF_Ind);
  4645. plci_remove(plci);
  4646. break;
  4647. /* Supplementary Service rejected */
  4648. case S_SERVICE_REJ:
  4649. dbug(1,dprintf("S_Reject=0x%x",pty_cai[5]));
  4650. if(!pty_cai[0]) break;
  4651. switch (pty_cai[5])
  4652. {
  4653. case ECT_EXECUTE:
  4654. case THREE_PTY_END:
  4655. case THREE_PTY_BEGIN:
  4656. if(!plci->relatedPTYPLCI) break;
  4657. tplci = plci->relatedPTYPLCI;
  4658. rId = ( (word)tplci->Id<<8)|tplci->adapter->Id;
  4659. if(tplci->tel) rId|=EXT_CONTROLLER;
  4660. if(pty_cai[5]==ECT_EXECUTE)
  4661. {
  4662. PUT_WORD(&SS_Ind[1],S_ECT);
  4663. plci->vswitchstate=0;
  4664. plci->relatedPTYPLCI->vswitchstate=0;
  4665. }
  4666. else
  4667. {
  4668. PUT_WORD(&SS_Ind[1],pty_cai[5]+3);
  4669. }
  4670. if(pty_cai[2]!=0xff)
  4671. {
  4672. PUT_WORD(&SS_Ind[4],0x3600|(word)pty_cai[2]);
  4673. }
  4674. else
  4675. {
  4676. PUT_WORD(&SS_Ind[4],0x300E);
  4677. }
  4678. plci->relatedPTYPLCI = NULL;
  4679. plci->ptyState = 0;
  4680. sendf(tplci->appl,_FACILITY_I,rId,0,"ws",3, SS_Ind);
  4681. break;
  4682. case CALL_DEFLECTION:
  4683. if(pty_cai[2]!=0xff)
  4684. {
  4685. PUT_WORD(&SS_Ind[4],0x3600|(word)pty_cai[2]);
  4686. }
  4687. else
  4688. {
  4689. PUT_WORD(&SS_Ind[4],0x300E);
  4690. }
  4691. PUT_WORD(&SS_Ind[1],pty_cai[5]);
  4692. for(i=0; i<max_appl; i++)
  4693. {
  4694. if(application[i].CDEnable)
  4695. {
  4696. if(application[i].Id) sendf(&application[i],_FACILITY_I,Id,0,"ws",3, SS_Ind);
  4697. application[i].CDEnable = FALSE;
  4698. }
  4699. }
  4700. break;
  4701. case DEACTIVATION_DIVERSION:
  4702. case ACTIVATION_DIVERSION:
  4703. case DIVERSION_INTERROGATE_CFU:
  4704. case DIVERSION_INTERROGATE_CFB:
  4705. case DIVERSION_INTERROGATE_CFNR:
  4706. case DIVERSION_INTERROGATE_NUM:
  4707. case CCBS_REQUEST:
  4708. case CCBS_DEACTIVATE:
  4709. case CCBS_INTERROGATE:
  4710. if(!plci->appl) break;
  4711. if(pty_cai[2]!=0xff)
  4712. {
  4713. PUT_WORD(&Interr_Err_Ind[4],0x3600|(word)pty_cai[2]);
  4714. }
  4715. else
  4716. {
  4717. PUT_WORD(&Interr_Err_Ind[4],0x300E);
  4718. }
  4719. switch (pty_cai[5])
  4720. {
  4721. case DEACTIVATION_DIVERSION:
  4722. dbug(1,dprintf("Deact_Div"));
  4723. Interr_Err_Ind[0]=0x9;
  4724. Interr_Err_Ind[3]=0x6;
  4725. PUT_WORD(&Interr_Err_Ind[1],S_CALL_FORWARDING_STOP);
  4726. break;
  4727. case ACTIVATION_DIVERSION:
  4728. dbug(1,dprintf("Act_Div"));
  4729. Interr_Err_Ind[0]=0x9;
  4730. Interr_Err_Ind[3]=0x6;
  4731. PUT_WORD(&Interr_Err_Ind[1],S_CALL_FORWARDING_START);
  4732. break;
  4733. case DIVERSION_INTERROGATE_CFU:
  4734. case DIVERSION_INTERROGATE_CFB:
  4735. case DIVERSION_INTERROGATE_CFNR:
  4736. dbug(1,dprintf("Interr_Div"));
  4737. Interr_Err_Ind[0]=0xa;
  4738. Interr_Err_Ind[3]=0x7;
  4739. PUT_WORD(&Interr_Err_Ind[1],S_INTERROGATE_DIVERSION);
  4740. break;
  4741. case DIVERSION_INTERROGATE_NUM:
  4742. dbug(1,dprintf("Interr_Num"));
  4743. Interr_Err_Ind[0]=0xa;
  4744. Interr_Err_Ind[3]=0x7;
  4745. PUT_WORD(&Interr_Err_Ind[1],S_INTERROGATE_NUMBERS);
  4746. break;
  4747. case CCBS_REQUEST:
  4748. dbug(1,dprintf("CCBS Request"));
  4749. Interr_Err_Ind[0]=0xd;
  4750. Interr_Err_Ind[3]=0xa;
  4751. PUT_WORD(&Interr_Err_Ind[1],S_CCBS_REQUEST);
  4752. break;
  4753. case CCBS_DEACTIVATE:
  4754. dbug(1,dprintf("CCBS Deactivate"));
  4755. Interr_Err_Ind[0]=0x9;
  4756. Interr_Err_Ind[3]=0x6;
  4757. PUT_WORD(&Interr_Err_Ind[1],S_CCBS_DEACTIVATE);
  4758. break;
  4759. case CCBS_INTERROGATE:
  4760. dbug(1,dprintf("CCBS Interrogate"));
  4761. Interr_Err_Ind[0]=0xb;
  4762. Interr_Err_Ind[3]=0x8;
  4763. PUT_WORD(&Interr_Err_Ind[1],S_CCBS_INTERROGATE);
  4764. break;
  4765. }
  4766. PUT_DWORD(&Interr_Err_Ind[6],plci->appl->S_Handle);
  4767. sendf(plci->appl,_FACILITY_I,Id&0x7,0,"ws",3, Interr_Err_Ind);
  4768. plci_remove(plci);
  4769. break;
  4770. case ACTIVATION_MWI:
  4771. case DEACTIVATION_MWI:
  4772. if(pty_cai[5]==ACTIVATION_MWI)
  4773. {
  4774. PUT_WORD(&SS_Ind[1],S_MWI_ACTIVATE);
  4775. }
  4776. else PUT_WORD(&SS_Ind[1],S_MWI_DEACTIVATE);
  4777. if(pty_cai[2]!=0xff)
  4778. {
  4779. PUT_WORD(&SS_Ind[4],0x3600|(word)pty_cai[2]);
  4780. }
  4781. else
  4782. {
  4783. PUT_WORD(&SS_Ind[4],0x300E);
  4784. }
  4785. if(plci->cr_enquiry)
  4786. {
  4787. sendf(plci->appl,_FACILITY_I,Id&0xf,0,"ws",3, SS_Ind);
  4788. plci_remove(plci);
  4789. }
  4790. else
  4791. {
  4792. sendf(plci->appl,_FACILITY_I,Id,0,"ws",3, SS_Ind);
  4793. }
  4794. break;
  4795. case CONF_ADD: /* ERROR */
  4796. case CONF_BEGIN:
  4797. case CONF_DROP:
  4798. case CONF_ISOLATE:
  4799. case CONF_REATTACH:
  4800. CONF_Ind[0]=9;
  4801. CONF_Ind[3]=6;
  4802. switch(pty_cai[5])
  4803. {
  4804. case CONF_BEGIN:
  4805. PUT_WORD(&CONF_Ind[1],S_CONF_BEGIN);
  4806. plci->ptyState = 0;
  4807. break;
  4808. case CONF_DROP:
  4809. CONF_Ind[0]=5;
  4810. CONF_Ind[3]=2;
  4811. PUT_WORD(&CONF_Ind[1],S_CONF_DROP);
  4812. plci->ptyState = CONNECTED;
  4813. break;
  4814. case CONF_ISOLATE:
  4815. CONF_Ind[0]=5;
  4816. CONF_Ind[3]=2;
  4817. PUT_WORD(&CONF_Ind[1],S_CONF_ISOLATE);
  4818. plci->ptyState = CONNECTED;
  4819. break;
  4820. case CONF_REATTACH:
  4821. CONF_Ind[0]=5;
  4822. CONF_Ind[3]=2;
  4823. PUT_WORD(&CONF_Ind[1],S_CONF_REATTACH);
  4824. plci->ptyState = CONNECTED;
  4825. break;
  4826. case CONF_ADD:
  4827. PUT_WORD(&CONF_Ind[1],S_CONF_ADD);
  4828. plci->relatedPTYPLCI = NULL;
  4829. tplci=plci->relatedPTYPLCI;
  4830. if(tplci) tplci->ptyState = CONNECTED;
  4831. plci->ptyState = CONNECTED;
  4832. break;
  4833. }
  4834. if(pty_cai[2]!=0xff)
  4835. {
  4836. PUT_WORD(&CONF_Ind[4],0x3600|(word)pty_cai[2]);
  4837. }
  4838. else
  4839. {
  4840. PUT_WORD(&CONF_Ind[4],0x3303); /* Time-out: network did not respond
  4841. within the required time */
  4842. }
  4843. PUT_DWORD(&CONF_Ind[6],0x0);
  4844. sendf(plci->appl,_FACILITY_I,Id,0,"ws",3, CONF_Ind);
  4845. break;
  4846. }
  4847. break;
  4848. /* Supplementary Service indicates success */
  4849. case S_SERVICE:
  4850. dbug(1,dprintf("Service_Ind"));
  4851. PUT_WORD (&CF_Ind[4], 0);
  4852. switch (pty_cai[5])
  4853. {
  4854. case THREE_PTY_END:
  4855. case THREE_PTY_BEGIN:
  4856. case ECT_EXECUTE:
  4857. if(!plci->relatedPTYPLCI) break;
  4858. tplci = plci->relatedPTYPLCI;
  4859. rId = ( (word)tplci->Id<<8)|tplci->adapter->Id;
  4860. if(tplci->tel) rId|=EXT_CONTROLLER;
  4861. if(pty_cai[5]==ECT_EXECUTE)
  4862. {
  4863. PUT_WORD(&SS_Ind[1],S_ECT);
  4864. if(plci->vswitchstate!=3)
  4865. {
  4866. plci->ptyState = IDLE;
  4867. plci->relatedPTYPLCI = NULL;
  4868. plci->ptyState = 0;
  4869. }
  4870. dbug(1,dprintf("ECT OK"));
  4871. sendf(tplci->appl,_FACILITY_I,rId,0,"ws",3, SS_Ind);
  4872. }
  4873. else
  4874. {
  4875. switch (plci->ptyState)
  4876. {
  4877. case S_3PTY_BEGIN:
  4878. plci->ptyState = CONNECTED;
  4879. dbug(1,dprintf("3PTY ON"));
  4880. break;
  4881. case S_3PTY_END:
  4882. plci->ptyState = IDLE;
  4883. plci->relatedPTYPLCI = NULL;
  4884. plci->ptyState = 0;
  4885. dbug(1,dprintf("3PTY OFF"));
  4886. break;
  4887. }
  4888. PUT_WORD(&SS_Ind[1],pty_cai[5]+3);
  4889. sendf(tplci->appl,_FACILITY_I,rId,0,"ws",3, SS_Ind);
  4890. }
  4891. break;
  4892. case CALL_DEFLECTION:
  4893. PUT_WORD(&SS_Ind[1],pty_cai[5]);
  4894. for(i=0; i<max_appl; i++)
  4895. {
  4896. if(application[i].CDEnable)
  4897. {
  4898. if(application[i].Id) sendf(&application[i],_FACILITY_I,Id,0,"ws",3, SS_Ind);
  4899. application[i].CDEnable = FALSE;
  4900. }
  4901. }
  4902. break;
  4903. case DEACTIVATION_DIVERSION:
  4904. case ACTIVATION_DIVERSION:
  4905. if(!plci->appl) break;
  4906. PUT_WORD(&CF_Ind[1],pty_cai[5]+2);
  4907. PUT_DWORD(&CF_Ind[6],plci->appl->S_Handle);
  4908. sendf(plci->appl,_FACILITY_I,Id&0x7,0,"ws",3, CF_Ind);
  4909. plci_remove(plci);
  4910. break;
  4911. case DIVERSION_INTERROGATE_CFU:
  4912. case DIVERSION_INTERROGATE_CFB:
  4913. case DIVERSION_INTERROGATE_CFNR:
  4914. case DIVERSION_INTERROGATE_NUM:
  4915. case CCBS_REQUEST:
  4916. case CCBS_DEACTIVATE:
  4917. case CCBS_INTERROGATE:
  4918. if(!plci->appl) break;
  4919. switch (pty_cai[5])
  4920. {
  4921. case DIVERSION_INTERROGATE_CFU:
  4922. case DIVERSION_INTERROGATE_CFB:
  4923. case DIVERSION_INTERROGATE_CFNR:
  4924. dbug(1,dprintf("Interr_Div"));
  4925. PUT_WORD(&pty_cai[1],S_INTERROGATE_DIVERSION);
  4926. pty_cai[3]=pty_cai[0]-3; /* Supplementary Service-specific parameter len */
  4927. break;
  4928. case DIVERSION_INTERROGATE_NUM:
  4929. dbug(1,dprintf("Interr_Num"));
  4930. PUT_WORD(&pty_cai[1],S_INTERROGATE_NUMBERS);
  4931. pty_cai[3]=pty_cai[0]-3; /* Supplementary Service-specific parameter len */
  4932. break;
  4933. case CCBS_REQUEST:
  4934. dbug(1,dprintf("CCBS Request"));
  4935. PUT_WORD(&pty_cai[1],S_CCBS_REQUEST);
  4936. pty_cai[3]=pty_cai[0]-3; /* Supplementary Service-specific parameter len */
  4937. break;
  4938. case CCBS_DEACTIVATE:
  4939. dbug(1,dprintf("CCBS Deactivate"));
  4940. PUT_WORD(&pty_cai[1],S_CCBS_DEACTIVATE);
  4941. pty_cai[3]=pty_cai[0]-3; /* Supplementary Service-specific parameter len */
  4942. break;
  4943. case CCBS_INTERROGATE:
  4944. dbug(1,dprintf("CCBS Interrogate"));
  4945. PUT_WORD(&pty_cai[1],S_CCBS_INTERROGATE);
  4946. pty_cai[3]=pty_cai[0]-3; /* Supplementary Service-specific parameter len */
  4947. break;
  4948. }
  4949. PUT_WORD(&pty_cai[4],0); /* Supplementary Service Reason */
  4950. PUT_DWORD(&pty_cai[6],plci->appl->S_Handle);
  4951. sendf(plci->appl,_FACILITY_I,Id&0x7,0,"wS",3, pty_cai);
  4952. plci_remove(plci);
  4953. break;
  4954. case ACTIVATION_MWI:
  4955. case DEACTIVATION_MWI:
  4956. if(pty_cai[5]==ACTIVATION_MWI)
  4957. {
  4958. PUT_WORD(&SS_Ind[1],S_MWI_ACTIVATE);
  4959. }
  4960. else PUT_WORD(&SS_Ind[1],S_MWI_DEACTIVATE);
  4961. if(plci->cr_enquiry)
  4962. {
  4963. sendf(plci->appl,_FACILITY_I,Id&0xf,0,"ws",3, SS_Ind);
  4964. plci_remove(plci);
  4965. }
  4966. else
  4967. {
  4968. sendf(plci->appl,_FACILITY_I,Id,0,"ws",3, SS_Ind);
  4969. }
  4970. break;
  4971. case MWI_INDICATION:
  4972. if(pty_cai[0]>=0x12)
  4973. {
  4974. PUT_WORD(&pty_cai[3],S_MWI_INDICATE);
  4975. pty_cai[2]=pty_cai[0]-2; /* len Parameter */
  4976. pty_cai[5]=pty_cai[0]-5; /* Supplementary Service-specific parameter len */
  4977. if(plci->appl && (a->Notification_Mask[plci->appl->Id-1]&SMASK_MWI))
  4978. {
  4979. if(plci->internal_command==GET_MWI_STATE) /* result on Message Waiting Listen */
  4980. {
  4981. sendf(plci->appl,_FACILITY_I,Id&0xf,0,"wS",3, &pty_cai[2]);
  4982. plci_remove(plci);
  4983. return;
  4984. }
  4985. else sendf(plci->appl,_FACILITY_I,Id,0,"wS",3, &pty_cai[2]);
  4986. pty_cai[0]=0;
  4987. }
  4988. else
  4989. {
  4990. for(i=0; i<max_appl; i++)
  4991. {
  4992. if(a->Notification_Mask[i]&SMASK_MWI)
  4993. {
  4994. sendf(&application[i],_FACILITY_I,Id&0x7,0,"wS",3, &pty_cai[2]);
  4995. pty_cai[0]=0;
  4996. }
  4997. }
  4998. }
  4999. if(!pty_cai[0])
  5000. { /* acknowledge */
  5001. facility[2]= 0; /* returncode */
  5002. }
  5003. else facility[2]= 0xff;
  5004. }
  5005. else
  5006. {
  5007. /* reject */
  5008. facility[2]= 0xff; /* returncode */
  5009. }
  5010. facility[0]= 2;
  5011. facility[1]= MWI_RESPONSE; /* Function */
  5012. add_p(plci,CAI,facility);
  5013. add_p(plci,ESC,multi_ssext_parms[0]); /* remembered parameter -> only one possible */
  5014. sig_req(plci,S_SERVICE,0);
  5015. send_req(plci);
  5016. plci->command = 0;
  5017. next_internal_command (Id, plci);
  5018. break;
  5019. case CONF_ADD: /* OK */
  5020. case CONF_BEGIN:
  5021. case CONF_DROP:
  5022. case CONF_ISOLATE:
  5023. case CONF_REATTACH:
  5024. case CONF_PARTYDISC:
  5025. CONF_Ind[0]=9;
  5026. CONF_Ind[3]=6;
  5027. switch(pty_cai[5])
  5028. {
  5029. case CONF_BEGIN:
  5030. PUT_WORD(&CONF_Ind[1],S_CONF_BEGIN);
  5031. if(pty_cai[0]==6)
  5032. {
  5033. d=pty_cai[6];
  5034. PUT_DWORD(&CONF_Ind[6],d); /* PartyID */
  5035. }
  5036. else
  5037. {
  5038. PUT_DWORD(&CONF_Ind[6],0x0);
  5039. }
  5040. break;
  5041. case CONF_ISOLATE:
  5042. PUT_WORD(&CONF_Ind[1],S_CONF_ISOLATE);
  5043. CONF_Ind[0]=5;
  5044. CONF_Ind[3]=2;
  5045. break;
  5046. case CONF_REATTACH:
  5047. PUT_WORD(&CONF_Ind[1],S_CONF_REATTACH);
  5048. CONF_Ind[0]=5;
  5049. CONF_Ind[3]=2;
  5050. break;
  5051. case CONF_DROP:
  5052. PUT_WORD(&CONF_Ind[1],S_CONF_DROP);
  5053. CONF_Ind[0]=5;
  5054. CONF_Ind[3]=2;
  5055. break;
  5056. case CONF_ADD:
  5057. PUT_WORD(&CONF_Ind[1],S_CONF_ADD);
  5058. d=pty_cai[6];
  5059. PUT_DWORD(&CONF_Ind[6],d); /* PartyID */
  5060. tplci=plci->relatedPTYPLCI;
  5061. if(tplci) tplci->ptyState = CONNECTED;
  5062. break;
  5063. case CONF_PARTYDISC:
  5064. CONF_Ind[0]=7;
  5065. CONF_Ind[3]=4;
  5066. PUT_WORD(&CONF_Ind[1],S_CONF_PARTYDISC);
  5067. d=pty_cai[6];
  5068. PUT_DWORD(&CONF_Ind[4],d); /* PartyID */
  5069. break;
  5070. }
  5071. plci->ptyState = CONNECTED;
  5072. sendf(plci->appl,_FACILITY_I,Id,0,"ws",3, CONF_Ind);
  5073. break;
  5074. case CCBS_INFO_RETAIN:
  5075. case CCBS_ERASECALLLINKAGEID:
  5076. case CCBS_STOP_ALERTING:
  5077. CONF_Ind[0]=5;
  5078. CONF_Ind[3]=2;
  5079. switch(pty_cai[5])
  5080. {
  5081. case CCBS_INFO_RETAIN:
  5082. PUT_WORD(&CONF_Ind[1],S_CCBS_INFO_RETAIN);
  5083. break;
  5084. case CCBS_STOP_ALERTING:
  5085. PUT_WORD(&CONF_Ind[1],S_CCBS_STOP_ALERTING);
  5086. break;
  5087. case CCBS_ERASECALLLINKAGEID:
  5088. PUT_WORD(&CONF_Ind[1],S_CCBS_ERASECALLLINKAGEID);
  5089. CONF_Ind[0]=7;
  5090. CONF_Ind[3]=4;
  5091. CONF_Ind[6]=0;
  5092. CONF_Ind[7]=0;
  5093. break;
  5094. }
  5095. w=pty_cai[6];
  5096. PUT_WORD(&CONF_Ind[4],w); /* PartyID */
  5097. if(plci->appl && (a->Notification_Mask[plci->appl->Id-1]&SMASK_CCBS))
  5098. {
  5099. sendf(plci->appl,_FACILITY_I,Id,0,"ws",3, CONF_Ind);
  5100. }
  5101. else
  5102. {
  5103. for(i=0; i<max_appl; i++)
  5104. if(a->Notification_Mask[i]&SMASK_CCBS)
  5105. sendf(&application[i],_FACILITY_I,Id&0x7,0,"ws",3, CONF_Ind);
  5106. }
  5107. break;
  5108. }
  5109. break;
  5110. case CALL_HOLD_REJ:
  5111. cau = parms[7];
  5112. if(cau)
  5113. {
  5114. i = _L3_CAUSE | cau[2];
  5115. if(cau[2]==0) i = 0x3603;
  5116. }
  5117. else
  5118. {
  5119. i = 0x3603;
  5120. }
  5121. PUT_WORD(&SS_Ind[1],S_HOLD);
  5122. PUT_WORD(&SS_Ind[4],i);
  5123. if(plci->SuppState == HOLD_REQUEST)
  5124. {
  5125. plci->SuppState = IDLE;
  5126. sendf(plci->appl,_FACILITY_I,Id,0,"ws",3, SS_Ind);
  5127. }
  5128. break;
  5129. case CALL_HOLD_ACK:
  5130. if(plci->SuppState == HOLD_REQUEST)
  5131. {
  5132. plci->SuppState = CALL_HELD;
  5133. CodecIdCheck(a, plci);
  5134. start_internal_command (Id, plci, hold_save_command);
  5135. }
  5136. break;
  5137. case CALL_RETRIEVE_REJ:
  5138. cau = parms[7];
  5139. if(cau)
  5140. {
  5141. i = _L3_CAUSE | cau[2];
  5142. if(cau[2]==0) i = 0x3603;
  5143. }
  5144. else
  5145. {
  5146. i = 0x3603;
  5147. }
  5148. PUT_WORD(&SS_Ind[1],S_RETRIEVE);
  5149. PUT_WORD(&SS_Ind[4],i);
  5150. if(plci->SuppState == RETRIEVE_REQUEST)
  5151. {
  5152. plci->SuppState = CALL_HELD;
  5153. CodecIdCheck(a, plci);
  5154. sendf(plci->appl,_FACILITY_I,Id,0,"ws",3, SS_Ind);
  5155. }
  5156. break;
  5157. case CALL_RETRIEVE_ACK:
  5158. PUT_WORD(&SS_Ind[1],S_RETRIEVE);
  5159. if(plci->SuppState == RETRIEVE_REQUEST)
  5160. {
  5161. plci->SuppState = IDLE;
  5162. plci->call_dir |= CALL_DIR_FORCE_OUTG_NL;
  5163. plci->b_channel = esc_chi[esc_chi[0]]&0x1f;
  5164. if(plci->tel)
  5165. {
  5166. mixer_set_bchannel_id_esc (plci, plci->b_channel);
  5167. dbug(1,dprintf("RetrChannel=0x%x",plci->b_channel));
  5168. SetVoiceChannel(a->AdvCodecPLCI, esc_chi, a);
  5169. if(plci->B2_prot==B2_TRANSPARENT && plci->B3_prot==B3_TRANSPARENT)
  5170. {
  5171. dbug(1,dprintf("Get B-ch"));
  5172. start_internal_command (Id, plci, retrieve_restore_command);
  5173. }
  5174. else
  5175. sendf(plci->appl,_FACILITY_I,Id,0,"ws",3, SS_Ind);
  5176. }
  5177. else
  5178. start_internal_command (Id, plci, retrieve_restore_command);
  5179. }
  5180. break;
  5181. case INDICATE_IND:
  5182. if(plci->State != LISTENING) {
  5183. sig_req(plci,HANGUP,0);
  5184. send_req(plci);
  5185. break;
  5186. }
  5187. cip = find_cip(a,parms[4],parms[6]);
  5188. cip_mask = 1L<<cip;
  5189. dbug(1,dprintf("cip=%d,cip_mask=%lx",cip,cip_mask));
  5190. clear_c_ind_mask (plci);
  5191. if (!remove_started && !a->adapter_disabled)
  5192. {
  5193. set_c_ind_mask_bit (plci, MAX_APPL);
  5194. group_optimization(a, plci);
  5195. for(i=0; i<max_appl; i++) {
  5196. if(application[i].Id
  5197. && (a->CIP_Mask[i]&1 || a->CIP_Mask[i]&cip_mask)
  5198. && CPN_filter_ok(parms[0],a,i)
  5199. && test_group_ind_mask_bit (plci, i) ) {
  5200. dbug(1,dprintf("storedcip_mask[%d]=0x%lx",i,a->CIP_Mask[i] ));
  5201. set_c_ind_mask_bit (plci, i);
  5202. dump_c_ind_mask (plci);
  5203. plci->State = INC_CON_PENDING;
  5204. plci->call_dir = (plci->call_dir & ~(CALL_DIR_OUT | CALL_DIR_ORIGINATE)) |
  5205. CALL_DIR_IN | CALL_DIR_ANSWER;
  5206. if(esc_chi[0]) {
  5207. plci->b_channel = esc_chi[esc_chi[0]]&0x1f;
  5208. mixer_set_bchannel_id_esc (plci, plci->b_channel);
  5209. }
  5210. /* if a listen on the ext controller is done, check if hook states */
  5211. /* are supported or if just a on board codec must be activated */
  5212. if(a->codec_listen[i] && !a->AdvSignalPLCI) {
  5213. if(a->profile.Global_Options & HANDSET)
  5214. plci->tel = ADV_VOICE;
  5215. else if(a->profile.Global_Options & ON_BOARD_CODEC)
  5216. plci->tel = CODEC;
  5217. if(plci->tel) Id|=EXT_CONTROLLER;
  5218. a->codec_listen[i] = plci;
  5219. }
  5220. sendf(&application[i],_CONNECT_I,Id,0,
  5221. "wSSSSSSSbSSSSS", cip, /* CIP */
  5222. parms[0], /* CalledPartyNumber */
  5223. multi_CiPN_parms[0], /* CallingPartyNumber */
  5224. parms[2], /* CalledPartySubad */
  5225. parms[3], /* CallingPartySubad */
  5226. parms[4], /* BearerCapability */
  5227. parms[5], /* LowLC */
  5228. parms[6], /* HighLC */
  5229. ai_len, /* nested struct add_i */
  5230. add_i[0], /* B channel info */
  5231. add_i[1], /* keypad facility */
  5232. add_i[2], /* user user data */
  5233. add_i[3], /* nested facility */
  5234. multi_CiPN_parms[1] /* second CiPN(SCR) */
  5235. );
  5236. SendSSExtInd(&application[i],
  5237. plci,
  5238. Id,
  5239. multi_ssext_parms);
  5240. SendSetupInfo(&application[i],
  5241. plci,
  5242. Id,
  5243. parms,
  5244. SendMultiIE(plci,Id,multi_pi_parms, PI, 0x210, TRUE));
  5245. }
  5246. }
  5247. clear_c_ind_mask_bit (plci, MAX_APPL);
  5248. dump_c_ind_mask (plci);
  5249. }
  5250. if(c_ind_mask_empty (plci)) {
  5251. sig_req(plci,HANGUP,0);
  5252. send_req(plci);
  5253. plci->State = IDLE;
  5254. }
  5255. plci->notifiedcall = 0;
  5256. a->listen_active--;
  5257. listen_check(a);
  5258. break;
  5259. case CALL_PEND_NOTIFY:
  5260. plci->notifiedcall = 1;
  5261. listen_check(a);
  5262. break;
  5263. case CALL_IND:
  5264. case CALL_CON:
  5265. if(plci->State==ADVANCED_VOICE_SIG || plci->State==ADVANCED_VOICE_NOSIG)
  5266. {
  5267. if(plci->internal_command==PERM_COD_CONN_PEND)
  5268. {
  5269. if(plci->State==ADVANCED_VOICE_NOSIG)
  5270. {
  5271. dbug(1,dprintf("***Codec OK"));
  5272. if(a->AdvSignalPLCI)
  5273. {
  5274. tplci = a->AdvSignalPLCI;
  5275. if(tplci->spoofed_msg)
  5276. {
  5277. dbug(1,dprintf("***Spoofed Msg(0x%x)",tplci->spoofed_msg));
  5278. tplci->command = 0;
  5279. tplci->internal_command = 0;
  5280. x_Id = ((word)tplci->Id<<8)|tplci->adapter->Id | 0x80;
  5281. switch (tplci->spoofed_msg)
  5282. {
  5283. case CALL_RES:
  5284. tplci->command = _CONNECT_I|RESPONSE;
  5285. api_load_msg (&tplci->saved_msg, saved_parms);
  5286. add_b1(tplci,&saved_parms[1],0,tplci->B1_facilities);
  5287. if (tplci->adapter->Info_Mask[tplci->appl->Id-1] & 0x200)
  5288. {
  5289. /* early B3 connect (CIP mask bit 9) no release after a disc */
  5290. add_p(tplci,LLI,"\x01\x01");
  5291. }
  5292. add_s(tplci, CONN_NR, &saved_parms[2]);
  5293. add_s(tplci, LLC, &saved_parms[4]);
  5294. add_ai(tplci, &saved_parms[5]);
  5295. tplci->State = INC_CON_ACCEPT;
  5296. sig_req(tplci, CALL_RES,0);
  5297. send_req(tplci);
  5298. break;
  5299. case AWAITING_SELECT_B:
  5300. dbug(1,dprintf("Select_B continue"));
  5301. start_internal_command (x_Id, tplci, select_b_command);
  5302. break;
  5303. case AWAITING_MANUF_CON: /* Get_Plci per Manufacturer_Req to ext controller */
  5304. if(!tplci->Sig.Id)
  5305. {
  5306. dbug(1,dprintf("No SigID!"));
  5307. sendf(tplci->appl, _MANUFACTURER_R|CONFIRM,x_Id,tplci->number, "dww",_DI_MANU_ID,_MANUFACTURER_R,_OUT_OF_PLCI);
  5308. plci_remove(tplci);
  5309. break;
  5310. }
  5311. tplci->command = _MANUFACTURER_R;
  5312. api_load_msg (&tplci->saved_msg, saved_parms);
  5313. dir = saved_parms[2].info[0];
  5314. if(dir==1) {
  5315. sig_req(tplci,CALL_REQ,0);
  5316. }
  5317. else if(!dir){
  5318. sig_req(tplci,LISTEN_REQ,0);
  5319. }
  5320. send_req(tplci);
  5321. sendf(tplci->appl, _MANUFACTURER_R|CONFIRM,x_Id,tplci->number, "dww",_DI_MANU_ID,_MANUFACTURER_R,0);
  5322. break;
  5323. case (CALL_REQ|AWAITING_MANUF_CON):
  5324. sig_req(tplci,CALL_REQ,0);
  5325. send_req(tplci);
  5326. break;
  5327. case CALL_REQ:
  5328. if(!tplci->Sig.Id)
  5329. {
  5330. dbug(1,dprintf("No SigID!"));
  5331. sendf(tplci->appl,_CONNECT_R|CONFIRM,tplci->adapter->Id,0,"w",_OUT_OF_PLCI);
  5332. plci_remove(tplci);
  5333. break;
  5334. }
  5335. tplci->command = _CONNECT_R;
  5336. api_load_msg (&tplci->saved_msg, saved_parms);
  5337. add_s(tplci,CPN,&saved_parms[1]);
  5338. add_s(tplci,DSA,&saved_parms[3]);
  5339. add_ai(tplci,&saved_parms[9]);
  5340. sig_req(tplci,CALL_REQ,0);
  5341. send_req(tplci);
  5342. break;
  5343. case CALL_RETRIEVE:
  5344. tplci->command = C_RETRIEVE_REQ;
  5345. sig_req(tplci,CALL_RETRIEVE,0);
  5346. send_req(tplci);
  5347. break;
  5348. }
  5349. tplci->spoofed_msg = 0;
  5350. if (tplci->internal_command == 0)
  5351. next_internal_command (x_Id, tplci);
  5352. }
  5353. }
  5354. next_internal_command (Id, plci);
  5355. break;
  5356. }
  5357. dbug(1,dprintf("***Codec Hook Init Req"));
  5358. plci->internal_command = PERM_COD_HOOK;
  5359. add_p(plci,FTY,"\x01\x09"); /* Get Hook State*/
  5360. sig_req(plci,TEL_CTRL,0);
  5361. send_req(plci);
  5362. }
  5363. }
  5364. else if(plci->command != _MANUFACTURER_R /* old style permanent connect */
  5365. && plci->State!=INC_ACT_PENDING)
  5366. {
  5367. mixer_set_bchannel_id_esc (plci, plci->b_channel);
  5368. if(plci->tel == ADV_VOICE && plci->SuppState == IDLE) /* with permanent codec switch on immediately */
  5369. {
  5370. chi[2] = plci->b_channel;
  5371. SetVoiceChannel(a->AdvCodecPLCI, chi, a);
  5372. }
  5373. sendf(plci->appl,_CONNECT_ACTIVE_I,Id,0,"Sss",parms[21],"","");
  5374. plci->State = INC_ACT_PENDING;
  5375. }
  5376. break;
  5377. case TEL_CTRL:
  5378. Number = 0;
  5379. ie = multi_fac_parms[0]; /* inspect the facility hook indications */
  5380. if(plci->State==ADVANCED_VOICE_SIG && ie[0]){
  5381. switch (ie[1]&0x91) {
  5382. case 0x80: /* hook off */
  5383. case 0x81:
  5384. if(plci->internal_command==PERM_COD_HOOK)
  5385. {
  5386. dbug(1,dprintf("init:hook_off"));
  5387. plci->hook_state = ie[1];
  5388. next_internal_command (Id, plci);
  5389. break;
  5390. }
  5391. else /* ignore doubled hook indications */
  5392. {
  5393. if( ((plci->hook_state)&0xf0)==0x80)
  5394. {
  5395. dbug(1,dprintf("ignore hook"));
  5396. break;
  5397. }
  5398. plci->hook_state = ie[1]&0x91;
  5399. }
  5400. /* check for incoming call pending */
  5401. /* and signal '+'.Appl must decide */
  5402. /* with connect_res if call must */
  5403. /* accepted or not */
  5404. for(i=0, tplci=NULL;i<max_appl;i++){
  5405. if(a->codec_listen[i]
  5406. && (a->codec_listen[i]->State==INC_CON_PENDING
  5407. ||a->codec_listen[i]->State==INC_CON_ALERT) ){
  5408. tplci = a->codec_listen[i];
  5409. tplci->appl = &application[i];
  5410. }
  5411. }
  5412. /* no incoming call, do outgoing call */
  5413. /* and signal '+' if outg. setup */
  5414. if(!a->AdvSignalPLCI && !tplci){
  5415. if((i=get_plci(a))) {
  5416. a->AdvSignalPLCI = &a->plci[i-1];
  5417. tplci = a->AdvSignalPLCI;
  5418. tplci->tel = ADV_VOICE;
  5419. PUT_WORD(&voice_cai[5],a->AdvSignalAppl->MaxDataLength);
  5420. if (a->Info_Mask[a->AdvSignalAppl->Id-1] & 0x200){
  5421. /* early B3 connect (CIP mask bit 9) no release after a disc */
  5422. add_p(tplci,LLI,"\x01\x01");
  5423. }
  5424. add_p(tplci, CAI, voice_cai);
  5425. add_p(tplci, OAD, a->TelOAD);
  5426. add_p(tplci, OSA, a->TelOSA);
  5427. add_p(tplci,SHIFT|6,NULL);
  5428. add_p(tplci,SIN,"\x02\x01\x00");
  5429. add_p(tplci,UID,"\x06\x43\x61\x70\x69\x32\x30");
  5430. sig_req(tplci,ASSIGN,DSIG_ID);
  5431. a->AdvSignalPLCI->internal_command = HOOK_OFF_REQ;
  5432. a->AdvSignalPLCI->command = 0;
  5433. tplci->appl = a->AdvSignalAppl;
  5434. tplci->call_dir = CALL_DIR_OUT | CALL_DIR_ORIGINATE;
  5435. send_req(tplci);
  5436. }
  5437. }
  5438. if(!tplci) break;
  5439. Id = ((word)tplci->Id<<8)|a->Id;
  5440. Id|=EXT_CONTROLLER;
  5441. sendf(tplci->appl,
  5442. _FACILITY_I,
  5443. Id,
  5444. 0,
  5445. "ws", (word)0, "\x01+");
  5446. break;
  5447. case 0x90: /* hook on */
  5448. case 0x91:
  5449. if(plci->internal_command==PERM_COD_HOOK)
  5450. {
  5451. dbug(1,dprintf("init:hook_on"));
  5452. plci->hook_state = ie[1]&0x91;
  5453. next_internal_command (Id, plci);
  5454. break;
  5455. }
  5456. else /* ignore doubled hook indications */
  5457. {
  5458. if( ((plci->hook_state)&0xf0)==0x90) break;
  5459. plci->hook_state = ie[1]&0x91;
  5460. }
  5461. /* hangup the adv. voice call and signal '-' to the appl */
  5462. if(a->AdvSignalPLCI) {
  5463. Id = ((word)a->AdvSignalPLCI->Id<<8)|a->Id;
  5464. if(plci->tel) Id|=EXT_CONTROLLER;
  5465. sendf(a->AdvSignalAppl,
  5466. _FACILITY_I,
  5467. Id,
  5468. 0,
  5469. "ws", (word)0, "\x01-");
  5470. a->AdvSignalPLCI->internal_command = HOOK_ON_REQ;
  5471. a->AdvSignalPLCI->command = 0;
  5472. sig_req(a->AdvSignalPLCI,HANGUP,0);
  5473. send_req(a->AdvSignalPLCI);
  5474. }
  5475. break;
  5476. }
  5477. }
  5478. break;
  5479. case RESUME:
  5480. clear_c_ind_mask_bit (plci, (word)(plci->appl->Id-1));
  5481. PUT_WORD(&resume_cau[4],GOOD);
  5482. sendf(plci->appl,_FACILITY_I,Id,0,"ws", (word)3, resume_cau);
  5483. break;
  5484. case SUSPEND:
  5485. clear_c_ind_mask (plci);
  5486. if (plci->NL.Id && !plci->nl_remove_id) {
  5487. mixer_remove (plci);
  5488. nl_req_ncci(plci,REMOVE,0);
  5489. }
  5490. if (!plci->sig_remove_id) {
  5491. plci->internal_command = 0;
  5492. sig_req(plci,REMOVE,0);
  5493. }
  5494. send_req(plci);
  5495. if(!plci->channels) {
  5496. sendf(plci->appl,_FACILITY_I,Id,0,"ws", (word)3, "\x05\x04\x00\x02\x00\x00");
  5497. sendf(plci->appl, _DISCONNECT_I, Id, 0, "w", 0);
  5498. }
  5499. break;
  5500. case SUSPEND_REJ:
  5501. break;
  5502. case HANGUP:
  5503. plci->hangup_flow_ctrl_timer=0;
  5504. if(plci->manufacturer && plci->State==LOCAL_CONNECT) break;
  5505. cau = parms[7];
  5506. if(cau) {
  5507. i = _L3_CAUSE | cau[2];
  5508. if(cau[2]==0) i = 0;
  5509. else if(cau[2]==8) i = _L1_ERROR;
  5510. else if(cau[2]==9 || cau[2]==10) i = _L2_ERROR;
  5511. else if(cau[2]==5) i = _CAPI_GUARD_ERROR;
  5512. }
  5513. else {
  5514. i = _L3_ERROR;
  5515. }
  5516. if(plci->State==INC_CON_PENDING || plci->State==INC_CON_ALERT)
  5517. {
  5518. for(i=0; i<max_appl; i++)
  5519. {
  5520. if(test_c_ind_mask_bit (plci, i))
  5521. sendf(&application[i], _DISCONNECT_I, Id, 0, "w", 0);
  5522. }
  5523. }
  5524. else
  5525. {
  5526. clear_c_ind_mask (plci);
  5527. }
  5528. if(!plci->appl)
  5529. {
  5530. if (plci->State == LISTENING)
  5531. {
  5532. plci->notifiedcall=0;
  5533. a->listen_active--;
  5534. }
  5535. plci->State = INC_DIS_PENDING;
  5536. if(c_ind_mask_empty (plci))
  5537. {
  5538. plci->State = IDLE;
  5539. if (plci->NL.Id && !plci->nl_remove_id)
  5540. {
  5541. mixer_remove (plci);
  5542. nl_req_ncci(plci,REMOVE,0);
  5543. }
  5544. if (!plci->sig_remove_id)
  5545. {
  5546. plci->internal_command = 0;
  5547. sig_req(plci,REMOVE,0);
  5548. }
  5549. send_req(plci);
  5550. }
  5551. }
  5552. else
  5553. {
  5554. /* collision of DISCONNECT or CONNECT_RES with HANGUP can */
  5555. /* result in a second HANGUP! Don't generate another */
  5556. /* DISCONNECT */
  5557. if(plci->State!=IDLE && plci->State!=INC_DIS_PENDING)
  5558. {
  5559. if(plci->State==RESUMING)
  5560. {
  5561. PUT_WORD(&resume_cau[4],i);
  5562. sendf(plci->appl,_FACILITY_I,Id,0,"ws", (word)3, resume_cau);
  5563. }
  5564. plci->State = INC_DIS_PENDING;
  5565. sendf(plci->appl,_DISCONNECT_I,Id,0,"w",i);
  5566. }
  5567. }
  5568. break;
  5569. case SSEXT_IND:
  5570. SendSSExtInd(NULL,plci,Id,multi_ssext_parms);
  5571. break;
  5572. case VSWITCH_REQ:
  5573. VSwitchReqInd(plci,Id,multi_vswitch_parms);
  5574. break;
  5575. case VSWITCH_IND:
  5576. if(plci->relatedPTYPLCI &&
  5577. plci->vswitchstate==3 &&
  5578. plci->relatedPTYPLCI->vswitchstate==3 &&
  5579. parms[MAXPARMSIDS-1][0])
  5580. {
  5581. add_p(plci->relatedPTYPLCI,SMSG,parms[MAXPARMSIDS-1]);
  5582. sig_req(plci->relatedPTYPLCI,VSWITCH_REQ,0);
  5583. send_req(plci->relatedPTYPLCI);
  5584. }
  5585. else VSwitchReqInd(plci,Id,multi_vswitch_parms);
  5586. break;
  5587. }
  5588. }
  5589. static void SendSetupInfo(APPL * appl, PLCI * plci, dword Id, byte * * parms, byte Info_Sent_Flag)
  5590. {
  5591. word i;
  5592. byte * ie;
  5593. word Info_Number;
  5594. byte * Info_Element;
  5595. word Info_Mask = 0;
  5596. dbug(1,dprintf("SetupInfo"));
  5597. for(i=0; i<MAXPARMSIDS; i++) {
  5598. ie = parms[i];
  5599. Info_Number = 0;
  5600. Info_Element = ie;
  5601. if(ie[0]) {
  5602. switch(i) {
  5603. case 0:
  5604. dbug(1,dprintf("CPN "));
  5605. Info_Number = 0x0070;
  5606. Info_Mask = 0x80;
  5607. Info_Sent_Flag = TRUE;
  5608. break;
  5609. case 8: /* display */
  5610. dbug(1,dprintf("display(%d)",i));
  5611. Info_Number = 0x0028;
  5612. Info_Mask = 0x04;
  5613. Info_Sent_Flag = TRUE;
  5614. break;
  5615. case 16: /* Channel Id */
  5616. dbug(1,dprintf("CHI"));
  5617. Info_Number = 0x0018;
  5618. Info_Mask = 0x100;
  5619. Info_Sent_Flag = TRUE;
  5620. mixer_set_bchannel_id (plci, Info_Element);
  5621. break;
  5622. case 19: /* Redirected Number */
  5623. dbug(1,dprintf("RDN"));
  5624. Info_Number = 0x0074;
  5625. Info_Mask = 0x400;
  5626. Info_Sent_Flag = TRUE;
  5627. break;
  5628. case 20: /* Redirected Number extended */
  5629. dbug(1,dprintf("RDX"));
  5630. Info_Number = 0x0073;
  5631. Info_Mask = 0x400;
  5632. Info_Sent_Flag = TRUE;
  5633. break;
  5634. case 22: /* Redirecing Number */
  5635. dbug(1,dprintf("RIN"));
  5636. Info_Number = 0x0076;
  5637. Info_Mask = 0x400;
  5638. Info_Sent_Flag = TRUE;
  5639. break;
  5640. default:
  5641. Info_Number = 0;
  5642. break;
  5643. }
  5644. }
  5645. if(i==MAXPARMSIDS-2){ /* to indicate the message type "Setup" */
  5646. Info_Number = 0x8000 |5;
  5647. Info_Mask = 0x10;
  5648. Info_Element = "";
  5649. }
  5650. if(Info_Sent_Flag && Info_Number){
  5651. if(plci->adapter->Info_Mask[appl->Id-1] & Info_Mask) {
  5652. sendf(appl,_INFO_I,Id,0,"wS",Info_Number,Info_Element);
  5653. }
  5654. }
  5655. }
  5656. }
  5657. void SendInfo(PLCI * plci, dword Id, byte * * parms, byte iesent)
  5658. {
  5659. word i;
  5660. word j;
  5661. word k;
  5662. byte * ie;
  5663. word Info_Number;
  5664. byte * Info_Element;
  5665. word Info_Mask = 0;
  5666. static byte charges[5] = {4,0,0,0,0};
  5667. static byte cause[] = {0x02,0x80,0x00};
  5668. APPL *appl;
  5669. dbug(1,dprintf("InfoParse "));
  5670. if(
  5671. !plci->appl
  5672. && !plci->State
  5673. && plci->Sig.Ind!=NCR_FACILITY
  5674. )
  5675. {
  5676. dbug(1,dprintf("NoParse "));
  5677. return;
  5678. }
  5679. cause[2] = 0;
  5680. for(i=0; i<MAXPARMSIDS; i++) {
  5681. ie = parms[i];
  5682. Info_Number = 0;
  5683. Info_Element = ie;
  5684. if(ie[0]) {
  5685. switch(i) {
  5686. case 0:
  5687. dbug(1,dprintf("CPN "));
  5688. Info_Number = 0x0070;
  5689. Info_Mask = 0x80;
  5690. break;
  5691. case 7: /* ESC_CAU */
  5692. dbug(1,dprintf("cau(0x%x)",ie[2]));
  5693. Info_Number = 0x0008;
  5694. Info_Mask = 0x00;
  5695. cause[2] = ie[2];
  5696. Info_Element = NULL;
  5697. break;
  5698. case 8: /* display */
  5699. dbug(1,dprintf("display(%d)",i));
  5700. Info_Number = 0x0028;
  5701. Info_Mask = 0x04;
  5702. break;
  5703. case 9: /* Date display */
  5704. dbug(1,dprintf("date(%d)",i));
  5705. Info_Number = 0x0029;
  5706. Info_Mask = 0x02;
  5707. break;
  5708. case 10: /* charges */
  5709. for(j=0;j<4;j++) charges[1+j] = 0;
  5710. for(j=0; j<ie[0] && !(ie[1+j]&0x80); j++);
  5711. for(k=1,j++; j<ie[0] && k<=4; j++,k++) charges[k] = ie[1+j];
  5712. Info_Number = 0x4000;
  5713. Info_Mask = 0x40;
  5714. Info_Element = charges;
  5715. break;
  5716. case 11: /* user user info */
  5717. dbug(1,dprintf("uui"));
  5718. Info_Number = 0x007E;
  5719. Info_Mask = 0x08;
  5720. break;
  5721. case 12: /* congestion receiver ready */
  5722. dbug(1,dprintf("clRDY"));
  5723. Info_Number = 0x00B0;
  5724. Info_Mask = 0x08;
  5725. Info_Element = "";
  5726. break;
  5727. case 13: /* congestion receiver not ready */
  5728. dbug(1,dprintf("clNRDY"));
  5729. Info_Number = 0x00BF;
  5730. Info_Mask = 0x08;
  5731. Info_Element = "";
  5732. break;
  5733. case 15: /* Keypad Facility */
  5734. dbug(1,dprintf("KEY"));
  5735. Info_Number = 0x002C;
  5736. Info_Mask = 0x20;
  5737. break;
  5738. case 16: /* Channel Id */
  5739. dbug(1,dprintf("CHI"));
  5740. Info_Number = 0x0018;
  5741. Info_Mask = 0x100;
  5742. mixer_set_bchannel_id (plci, Info_Element);
  5743. break;
  5744. case 17: /* if no 1tr6 cause, send full cause, else esc_cause */
  5745. dbug(1,dprintf("q9cau(0x%x)",ie[2]));
  5746. if(!cause[2] || cause[2]<0x80) break; /* eg. layer 1 error */
  5747. Info_Number = 0x0008;
  5748. Info_Mask = 0x01;
  5749. if(cause[2] != ie[2]) Info_Element = cause;
  5750. break;
  5751. case 19: /* Redirected Number */
  5752. dbug(1,dprintf("RDN"));
  5753. Info_Number = 0x0074;
  5754. Info_Mask = 0x400;
  5755. break;
  5756. case 22: /* Redirecing Number */
  5757. dbug(1,dprintf("RIN"));
  5758. Info_Number = 0x0076;
  5759. Info_Mask = 0x400;
  5760. break;
  5761. case 23: /* Notification Indicator */
  5762. dbug(1,dprintf("NI"));
  5763. Info_Number = (word)NI;
  5764. Info_Mask = 0x210;
  5765. break;
  5766. case 26: /* Call State */
  5767. dbug(1,dprintf("CST"));
  5768. Info_Number = (word)CST;
  5769. Info_Mask = 0x01; /* do with cause i.e. for now */
  5770. break;
  5771. case MAXPARMSIDS-2: /* Escape Message Type, must be the last indication */
  5772. dbug(1,dprintf("ESC/MT[0x%x]",ie[3]));
  5773. Info_Number = 0x8000 |ie[3];
  5774. if(iesent) Info_Mask = 0xffff;
  5775. else Info_Mask = 0x10;
  5776. Info_Element = "";
  5777. break;
  5778. default:
  5779. Info_Number = 0;
  5780. Info_Mask = 0;
  5781. Info_Element = "";
  5782. break;
  5783. }
  5784. }
  5785. if(plci->Sig.Ind==NCR_FACILITY) /* check controller broadcast */
  5786. {
  5787. for(j=0; j<max_appl; j++)
  5788. {
  5789. appl = &application[j];
  5790. if(Info_Number
  5791. && appl->Id
  5792. && plci->adapter->Info_Mask[appl->Id-1] &Info_Mask)
  5793. {
  5794. dbug(1,dprintf("NCR_Ind"));
  5795. iesent=TRUE;
  5796. sendf(&application[j],_INFO_I,Id&0x0f,0,"wS",Info_Number,Info_Element);
  5797. }
  5798. }
  5799. }
  5800. else if(!plci->appl)
  5801. { /* overlap receiving broadcast */
  5802. if(Info_Number==CPN
  5803. || Info_Number==KEY
  5804. || Info_Number==NI
  5805. || Info_Number==DSP
  5806. || Info_Number==UUI )
  5807. {
  5808. for(j=0; j<max_appl; j++)
  5809. {
  5810. if(test_c_ind_mask_bit (plci, j))
  5811. {
  5812. dbug(1,dprintf("Ovl_Ind"));
  5813. iesent=TRUE;
  5814. sendf(&application[j],_INFO_I,Id,0,"wS",Info_Number,Info_Element);
  5815. }
  5816. }
  5817. }
  5818. } /* all other signalling states */
  5819. else if(Info_Number
  5820. && plci->adapter->Info_Mask[plci->appl->Id-1] &Info_Mask)
  5821. {
  5822. dbug(1,dprintf("Std_Ind"));
  5823. iesent=TRUE;
  5824. sendf(plci->appl,_INFO_I,Id,0,"wS",Info_Number,Info_Element);
  5825. }
  5826. }
  5827. }
  5828. byte SendMultiIE(PLCI * plci, dword Id, byte * * parms, byte ie_type, dword info_mask, byte setupParse)
  5829. {
  5830. word i;
  5831. word j;
  5832. byte * ie;
  5833. word Info_Number;
  5834. byte * Info_Element;
  5835. APPL *appl;
  5836. word Info_Mask = 0;
  5837. byte iesent=0;
  5838. if(
  5839. !plci->appl
  5840. && !plci->State
  5841. && plci->Sig.Ind!=NCR_FACILITY
  5842. && !setupParse
  5843. )
  5844. {
  5845. dbug(1,dprintf("NoM-IEParse "));
  5846. return 0;
  5847. }
  5848. dbug(1,dprintf("M-IEParse "));
  5849. for(i=0; i<MAX_MULTI_IE; i++)
  5850. {
  5851. ie = parms[i];
  5852. Info_Number = 0;
  5853. Info_Element = ie;
  5854. if(ie[0])
  5855. {
  5856. dbug(1,dprintf("[Ind0x%x]:IE=0x%x",plci->Sig.Ind,ie_type));
  5857. Info_Number = (word)ie_type;
  5858. Info_Mask = (word)info_mask;
  5859. }
  5860. if(plci->Sig.Ind==NCR_FACILITY) /* check controller broadcast */
  5861. {
  5862. for(j=0; j<max_appl; j++)
  5863. {
  5864. appl = &application[j];
  5865. if(Info_Number
  5866. && appl->Id
  5867. && plci->adapter->Info_Mask[appl->Id-1] &Info_Mask)
  5868. {
  5869. iesent = TRUE;
  5870. dbug(1,dprintf("Mlt_NCR_Ind"));
  5871. sendf(&application[j],_INFO_I,Id&0x0f,0,"wS",Info_Number,Info_Element);
  5872. }
  5873. }
  5874. }
  5875. else if(!plci->appl && Info_Number)
  5876. { /* overlap receiving broadcast */
  5877. for(j=0; j<max_appl; j++)
  5878. {
  5879. if(test_c_ind_mask_bit (plci, j))
  5880. {
  5881. iesent = TRUE;
  5882. dbug(1,dprintf("Mlt_Ovl_Ind"));
  5883. sendf(&application[j],_INFO_I,Id,0,"wS",Info_Number,Info_Element);
  5884. }
  5885. }
  5886. } /* all other signalling states */
  5887. else if(Info_Number
  5888. && plci->adapter->Info_Mask[plci->appl->Id-1] &Info_Mask)
  5889. {
  5890. iesent = TRUE;
  5891. dbug(1,dprintf("Mlt_Std_Ind"));
  5892. sendf(plci->appl,_INFO_I,Id,0,"wS",Info_Number,Info_Element);
  5893. }
  5894. }
  5895. return iesent;
  5896. }
  5897. static void SendSSExtInd(APPL * appl, PLCI * plci, dword Id, byte * * parms)
  5898. {
  5899. word i;
  5900. /* Format of multi_ssext_parms[i][]:
  5901. 0 byte length
  5902. 1 byte SSEXTIE
  5903. 2 byte SSEXT_REQ/SSEXT_IND
  5904. 3 byte length
  5905. 4 word SSExtCommand
  5906. 6... Params
  5907. */
  5908. if(
  5909. plci
  5910. && plci->State
  5911. && plci->Sig.Ind!=NCR_FACILITY
  5912. )
  5913. for(i=0;i<MAX_MULTI_IE;i++)
  5914. {
  5915. if(parms[i][0]<6) continue;
  5916. if(parms[i][2]==SSEXT_REQ) continue;
  5917. if(appl)
  5918. {
  5919. parms[i][0]=0; /* kill it */
  5920. sendf(appl,_MANUFACTURER_I,
  5921. Id,
  5922. 0,
  5923. "dwS",
  5924. _DI_MANU_ID,
  5925. _DI_SSEXT_CTRL,
  5926. &parms[i][3]);
  5927. }
  5928. else if(plci->appl)
  5929. {
  5930. parms[i][0]=0; /* kill it */
  5931. sendf(plci->appl,_MANUFACTURER_I,
  5932. Id,
  5933. 0,
  5934. "dwS",
  5935. _DI_MANU_ID,
  5936. _DI_SSEXT_CTRL,
  5937. &parms[i][3]);
  5938. }
  5939. }
  5940. };
  5941. void nl_ind(PLCI * plci)
  5942. {
  5943. byte ch;
  5944. word ncci;
  5945. dword Id;
  5946. DIVA_CAPI_ADAPTER * a;
  5947. word NCCIcode;
  5948. APPL * APPLptr;
  5949. word count;
  5950. word Num;
  5951. word i, ncpi_state;
  5952. byte len, ncci_state;
  5953. word msg;
  5954. word info = 0;
  5955. word fax_feature_bits;
  5956. byte fax_send_edata_ack;
  5957. static byte v120_header_buffer[2 + 3];
  5958. static word fax_info[] = {
  5959. 0, /* T30_SUCCESS */
  5960. _FAX_NO_CONNECTION, /* T30_ERR_NO_DIS_RECEIVED */
  5961. _FAX_PROTOCOL_ERROR, /* T30_ERR_TIMEOUT_NO_RESPONSE */
  5962. _FAX_PROTOCOL_ERROR, /* T30_ERR_RETRY_NO_RESPONSE */
  5963. _FAX_PROTOCOL_ERROR, /* T30_ERR_TOO_MANY_REPEATS */
  5964. _FAX_PROTOCOL_ERROR, /* T30_ERR_UNEXPECTED_MESSAGE */
  5965. _FAX_REMOTE_ABORT, /* T30_ERR_UNEXPECTED_DCN */
  5966. _FAX_LOCAL_ABORT, /* T30_ERR_DTC_UNSUPPORTED */
  5967. _FAX_TRAINING_ERROR, /* T30_ERR_ALL_RATES_FAILED */
  5968. _FAX_TRAINING_ERROR, /* T30_ERR_TOO_MANY_TRAINS */
  5969. _FAX_PARAMETER_ERROR, /* T30_ERR_RECEIVE_CORRUPTED */
  5970. _FAX_REMOTE_ABORT, /* T30_ERR_UNEXPECTED_DISC */
  5971. _FAX_LOCAL_ABORT, /* T30_ERR_APPLICATION_DISC */
  5972. _FAX_REMOTE_REJECT, /* T30_ERR_INCOMPATIBLE_DIS */
  5973. _FAX_LOCAL_ABORT, /* T30_ERR_INCOMPATIBLE_DCS */
  5974. _FAX_PROTOCOL_ERROR, /* T30_ERR_TIMEOUT_NO_COMMAND */
  5975. _FAX_PROTOCOL_ERROR, /* T30_ERR_RETRY_NO_COMMAND */
  5976. _FAX_PROTOCOL_ERROR, /* T30_ERR_TIMEOUT_COMMAND_TOO_LONG */
  5977. _FAX_PROTOCOL_ERROR, /* T30_ERR_TIMEOUT_RESPONSE_TOO_LONG */
  5978. _FAX_NO_CONNECTION, /* T30_ERR_NOT_IDENTIFIED */
  5979. _FAX_PROTOCOL_ERROR, /* T30_ERR_SUPERVISORY_TIMEOUT */
  5980. _FAX_PARAMETER_ERROR, /* T30_ERR_TOO_LONG_SCAN_LINE */
  5981. _FAX_PROTOCOL_ERROR, /* T30_ERR_RETRY_NO_PAGE_AFTER_MPS */
  5982. _FAX_PROTOCOL_ERROR, /* T30_ERR_RETRY_NO_PAGE_AFTER_CFR */
  5983. _FAX_PROTOCOL_ERROR, /* T30_ERR_RETRY_NO_DCS_AFTER_FTT */
  5984. _FAX_PROTOCOL_ERROR, /* T30_ERR_RETRY_NO_DCS_AFTER_EOM */
  5985. _FAX_PROTOCOL_ERROR, /* T30_ERR_RETRY_NO_DCS_AFTER_MPS */
  5986. _FAX_PROTOCOL_ERROR, /* T30_ERR_RETRY_NO_DCN_AFTER_MCF */
  5987. _FAX_PROTOCOL_ERROR, /* T30_ERR_RETRY_NO_DCN_AFTER_RTN */
  5988. _FAX_PROTOCOL_ERROR, /* T30_ERR_RETRY_NO_CFR */
  5989. _FAX_PROTOCOL_ERROR, /* T30_ERR_RETRY_NO_MCF_AFTER_EOP */
  5990. _FAX_PROTOCOL_ERROR, /* T30_ERR_RETRY_NO_MCF_AFTER_EOM */
  5991. _FAX_PROTOCOL_ERROR, /* T30_ERR_RETRY_NO_MCF_AFTER_MPS */
  5992. 0x331d, /* T30_ERR_SUB_SEP_UNSUPPORTED */
  5993. 0x331e, /* T30_ERR_PWD_UNSUPPORTED */
  5994. 0x331f, /* T30_ERR_SUB_SEP_PWD_UNSUPPORTED */
  5995. _FAX_PROTOCOL_ERROR, /* T30_ERR_INVALID_COMMAND_FRAME */
  5996. _FAX_PARAMETER_ERROR, /* T30_ERR_UNSUPPORTED_PAGE_CODING */
  5997. _FAX_PARAMETER_ERROR, /* T30_ERR_INVALID_PAGE_CODING */
  5998. _FAX_REMOTE_REJECT, /* T30_ERR_INCOMPATIBLE_PAGE_CONFIG */
  5999. _FAX_LOCAL_ABORT, /* T30_ERR_TIMEOUT_FROM_APPLICATION */
  6000. _FAX_PROTOCOL_ERROR, /* T30_ERR_V34FAX_NO_REACTION_ON_MARK */
  6001. _FAX_PROTOCOL_ERROR, /* T30_ERR_V34FAX_TRAINING_TIMEOUT */
  6002. _FAX_PROTOCOL_ERROR, /* T30_ERR_V34FAX_UNEXPECTED_V21 */
  6003. _FAX_PROTOCOL_ERROR, /* T30_ERR_V34FAX_PRIMARY_CTS_ON */
  6004. _FAX_LOCAL_ABORT, /* T30_ERR_V34FAX_TURNAROUND_POLLING */
  6005. _FAX_LOCAL_ABORT /* T30_ERR_V34FAX_V8_INCOMPATIBILITY */
  6006. };
  6007. byte dtmf_code_buffer[CAPIDTMF_RECV_DIGIT_BUFFER_SIZE + 1];
  6008. static word rtp_info[] = {
  6009. GOOD, /* RTP_SUCCESS */
  6010. 0x3600 /* RTP_ERR_SSRC_OR_PAYLOAD_CHANGE */
  6011. };
  6012. static dword udata_forwarding_table[0x100 / sizeof(dword)] =
  6013. {
  6014. 0x0020301e, 0x00000000, 0x00000000, 0x00000000,
  6015. 0x00000000, 0x00000000, 0x00000000, 0x00000000
  6016. };
  6017. ch = plci->NL.IndCh;
  6018. a = plci->adapter;
  6019. ncci = a->ch_ncci[ch];
  6020. Id = (((dword)(ncci ? ncci : ch)) << 16) | (((word) plci->Id) << 8) | a->Id;
  6021. if(plci->tel) Id|=EXT_CONTROLLER;
  6022. APPLptr = plci->appl;
  6023. 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",
  6024. plci->NL.Id,Id,plci->Id,plci->tel,plci->State,ch,plci->channels,plci->NL.Ind &0x0f));
  6025. /* in the case if no connect_active_Ind was sent to the appl we wait for */
  6026. if (plci->nl_remove_id)
  6027. {
  6028. plci->NL.RNR = 2; /* discard */
  6029. dbug(1,dprintf("NL discard while remove pending"));
  6030. return;
  6031. }
  6032. if((plci->NL.Ind &0x0f)==N_CONNECT)
  6033. {
  6034. if(plci->State==INC_DIS_PENDING
  6035. || plci->State==OUTG_DIS_PENDING
  6036. || plci->State==IDLE)
  6037. {
  6038. plci->NL.RNR = 2; /* discard */
  6039. dbug(1,dprintf("discard n_connect"));
  6040. return;
  6041. }
  6042. if(plci->State < INC_ACT_PENDING)
  6043. {
  6044. plci->NL.RNR = 1; /* flow control */
  6045. channel_x_off (plci, ch, N_XON_CONNECT_IND);
  6046. return;
  6047. }
  6048. }
  6049. if(!APPLptr) /* no application or invalid data */
  6050. { /* while reloading the DSP */
  6051. dbug(1,dprintf("discard1"));
  6052. plci->NL.RNR = 2;
  6053. return;
  6054. }
  6055. if (((plci->NL.Ind &0x0f) == N_UDATA)
  6056. && (((plci->B2_prot != B2_SDLC) && ((plci->B1_resource == 17) || (plci->B1_resource == 18)))
  6057. || (plci->B2_prot == 7)
  6058. || (plci->B3_prot == 7)) )
  6059. {
  6060. plci->ncpi_buffer[0] = 0;
  6061. ncpi_state = plci->ncpi_state;
  6062. if (plci->NL.complete == 1)
  6063. {
  6064. byte * data = &plci->NL.RBuffer->P[0];
  6065. if ((plci->NL.RBuffer->length >= 12)
  6066. &&( (*data == DSP_UDATA_INDICATION_DCD_ON)
  6067. ||(*data == DSP_UDATA_INDICATION_CTS_ON)) )
  6068. {
  6069. word conn_opt, ncpi_opt = 0x00;
  6070. /* HexDump ("MDM N_UDATA:", plci->NL.RBuffer->length, data); */
  6071. if (*data == DSP_UDATA_INDICATION_DCD_ON)
  6072. plci->ncpi_state |= NCPI_MDM_DCD_ON_RECEIVED;
  6073. if (*data == DSP_UDATA_INDICATION_CTS_ON)
  6074. plci->ncpi_state |= NCPI_MDM_CTS_ON_RECEIVED;
  6075. data++; /* indication code */
  6076. data += 2; /* timestamp */
  6077. if ((*data == DSP_CONNECTED_NORM_V18) || (*data == DSP_CONNECTED_NORM_VOWN))
  6078. ncpi_state &= ~(NCPI_MDM_DCD_ON_RECEIVED | NCPI_MDM_CTS_ON_RECEIVED);
  6079. data++; /* connected norm */
  6080. conn_opt = GET_WORD(data);
  6081. data += 2; /* connected options */
  6082. PUT_WORD (&(plci->ncpi_buffer[1]), (word)(GET_DWORD(data) & 0x0000FFFF));
  6083. if (conn_opt & DSP_CONNECTED_OPTION_MASK_V42)
  6084. {
  6085. ncpi_opt |= MDM_NCPI_ECM_V42;
  6086. }
  6087. else if (conn_opt & DSP_CONNECTED_OPTION_MASK_MNP)
  6088. {
  6089. ncpi_opt |= MDM_NCPI_ECM_MNP;
  6090. }
  6091. else
  6092. {
  6093. ncpi_opt |= MDM_NCPI_TRANSPARENT;
  6094. }
  6095. if (conn_opt & DSP_CONNECTED_OPTION_MASK_COMPRESSION)
  6096. {
  6097. ncpi_opt |= MDM_NCPI_COMPRESSED;
  6098. }
  6099. PUT_WORD (&(plci->ncpi_buffer[3]), ncpi_opt);
  6100. plci->ncpi_buffer[0] = 4;
  6101. plci->ncpi_state |= NCPI_VALID_CONNECT_B3_IND | NCPI_VALID_CONNECT_B3_ACT | NCPI_VALID_DISC_B3_IND;
  6102. }
  6103. }
  6104. if (plci->B3_prot == 7)
  6105. {
  6106. if (((a->ncci_state[ncci] == INC_ACT_PENDING) || (a->ncci_state[ncci] == OUTG_CON_PENDING))
  6107. && (plci->ncpi_state & NCPI_VALID_CONNECT_B3_ACT)
  6108. && !(plci->ncpi_state & NCPI_CONNECT_B3_ACT_SENT))
  6109. {
  6110. a->ncci_state[ncci] = INC_ACT_PENDING;
  6111. sendf(plci->appl,_CONNECT_B3_ACTIVE_I,Id,0,"S",plci->ncpi_buffer);
  6112. plci->ncpi_state |= NCPI_CONNECT_B3_ACT_SENT;
  6113. }
  6114. }
  6115. if (!((plci->requested_options_conn | plci->requested_options | plci->adapter->requested_options_table[plci->appl->Id-1])
  6116. & ((1L << PRIVATE_V18) | (1L << PRIVATE_VOWN)))
  6117. || !(ncpi_state & NCPI_MDM_DCD_ON_RECEIVED)
  6118. || !(ncpi_state & NCPI_MDM_CTS_ON_RECEIVED))
  6119. {
  6120. plci->NL.RNR = 2;
  6121. return;
  6122. }
  6123. }
  6124. if(plci->NL.complete == 2)
  6125. {
  6126. if (((plci->NL.Ind &0x0f) == N_UDATA)
  6127. && !(udata_forwarding_table[plci->RData[0].P[0] >> 5] & (1L << (plci->RData[0].P[0] & 0x1f))))
  6128. {
  6129. switch(plci->RData[0].P[0])
  6130. {
  6131. case DTMF_UDATA_INDICATION_FAX_CALLING_TONE:
  6132. if (plci->dtmf_rec_active & DTMF_LISTEN_ACTIVE_FLAG)
  6133. sendf(plci->appl, _FACILITY_I, Id & 0xffffL, 0,"ws", SELECTOR_DTMF, "\x01X");
  6134. break;
  6135. case DTMF_UDATA_INDICATION_ANSWER_TONE:
  6136. if (plci->dtmf_rec_active & DTMF_LISTEN_ACTIVE_FLAG)
  6137. sendf(plci->appl, _FACILITY_I, Id & 0xffffL, 0,"ws", SELECTOR_DTMF, "\x01Y");
  6138. break;
  6139. case DTMF_UDATA_INDICATION_DIGITS_RECEIVED:
  6140. dtmf_indication (Id, plci, plci->RData[0].P, plci->RData[0].PLength);
  6141. break;
  6142. case DTMF_UDATA_INDICATION_DIGITS_SENT:
  6143. dtmf_confirmation (Id, plci);
  6144. break;
  6145. case UDATA_INDICATION_MIXER_TAP_DATA:
  6146. capidtmf_recv_process_block (&(plci->capidtmf_state), plci->RData[0].P + 1, (word)(plci->RData[0].PLength - 1));
  6147. i = capidtmf_indication (&(plci->capidtmf_state), dtmf_code_buffer + 1);
  6148. if (i != 0)
  6149. {
  6150. dtmf_code_buffer[0] = DTMF_UDATA_INDICATION_DIGITS_RECEIVED;
  6151. dtmf_indication (Id, plci, dtmf_code_buffer, (word)(i + 1));
  6152. }
  6153. break;
  6154. case UDATA_INDICATION_MIXER_COEFS_SET:
  6155. mixer_indication_coefs_set (Id, plci);
  6156. break;
  6157. case UDATA_INDICATION_XCONNECT_FROM:
  6158. mixer_indication_xconnect_from (Id, plci, plci->RData[0].P, plci->RData[0].PLength);
  6159. break;
  6160. case UDATA_INDICATION_XCONNECT_TO:
  6161. mixer_indication_xconnect_to (Id, plci, plci->RData[0].P, plci->RData[0].PLength);
  6162. break;
  6163. case LEC_UDATA_INDICATION_DISABLE_DETECT:
  6164. ec_indication (Id, plci, plci->RData[0].P, plci->RData[0].PLength);
  6165. break;
  6166. default:
  6167. break;
  6168. }
  6169. }
  6170. else
  6171. {
  6172. if ((plci->RData[0].PLength != 0)
  6173. && ((plci->B2_prot == B2_V120_ASYNC)
  6174. || (plci->B2_prot == B2_V120_ASYNC_V42BIS)
  6175. || (plci->B2_prot == B2_V120_BIT_TRANSPARENT)))
  6176. {
  6177. sendf(plci->appl,_DATA_B3_I,Id,0,
  6178. "dwww",
  6179. plci->RData[1].P,
  6180. (plci->NL.RNum < 2) ? 0 : plci->RData[1].PLength,
  6181. plci->RNum,
  6182. plci->RFlags);
  6183. }
  6184. else
  6185. {
  6186. sendf(plci->appl,_DATA_B3_I,Id,0,
  6187. "dwww",
  6188. plci->RData[0].P,
  6189. plci->RData[0].PLength,
  6190. plci->RNum,
  6191. plci->RFlags);
  6192. }
  6193. }
  6194. return;
  6195. }
  6196. fax_feature_bits = 0;
  6197. if((plci->NL.Ind &0x0f)==N_CONNECT ||
  6198. (plci->NL.Ind &0x0f)==N_CONNECT_ACK ||
  6199. (plci->NL.Ind &0x0f)==N_DISC ||
  6200. (plci->NL.Ind &0x0f)==N_EDATA ||
  6201. (plci->NL.Ind &0x0f)==N_DISC_ACK)
  6202. {
  6203. info = 0;
  6204. plci->ncpi_buffer[0] = 0;
  6205. switch (plci->B3_prot) {
  6206. case 0: /*XPARENT*/
  6207. case 1: /*T.90 NL*/
  6208. break; /* no network control protocol info - jfr */
  6209. case 2: /*ISO8202*/
  6210. case 3: /*X25 DCE*/
  6211. for(i=0; i<plci->NL.RLength; i++) plci->ncpi_buffer[4+i] = plci->NL.RBuffer->P[i];
  6212. plci->ncpi_buffer[0] = (byte)(i+3);
  6213. plci->ncpi_buffer[1] = (byte)(plci->NL.Ind &N_D_BIT? 1:0);
  6214. plci->ncpi_buffer[2] = 0;
  6215. plci->ncpi_buffer[3] = 0;
  6216. break;
  6217. case 4: /*T.30 - FAX*/
  6218. case 5: /*T.30 - FAX*/
  6219. if(plci->NL.RLength>=sizeof(T30_INFO))
  6220. {
  6221. dbug(1,dprintf("FaxStatus %04x", ((T30_INFO *)plci->NL.RBuffer->P)->code));
  6222. len = 9;
  6223. PUT_WORD(&(plci->ncpi_buffer[1]),((T30_INFO *)plci->NL.RBuffer->P)->rate_div_2400 * 2400);
  6224. fax_feature_bits = GET_WORD(&((T30_INFO *)plci->NL.RBuffer->P)->feature_bits_low);
  6225. i = (((T30_INFO *)plci->NL.RBuffer->P)->resolution & T30_RESOLUTION_R8_0770_OR_200) ? 0x0001 : 0x0000;
  6226. if (plci->B3_prot == 5)
  6227. {
  6228. if (!(fax_feature_bits & T30_FEATURE_BIT_ECM))
  6229. i |= 0x8000; /* This is not an ECM connection */
  6230. if (fax_feature_bits & T30_FEATURE_BIT_T6_CODING)
  6231. i |= 0x4000; /* This is a connection with MMR compression */
  6232. if (fax_feature_bits & T30_FEATURE_BIT_2D_CODING)
  6233. i |= 0x2000; /* This is a connection with MR compression */
  6234. if (fax_feature_bits & T30_FEATURE_BIT_MORE_DOCUMENTS)
  6235. i |= 0x0004; /* More documents */
  6236. if (fax_feature_bits & T30_FEATURE_BIT_POLLING)
  6237. i |= 0x0002; /* Fax-polling indication */
  6238. }
  6239. dbug(1,dprintf("FAX Options %04x %04x",fax_feature_bits,i));
  6240. PUT_WORD(&(plci->ncpi_buffer[3]),i);
  6241. PUT_WORD(&(plci->ncpi_buffer[5]),((T30_INFO *)plci->NL.RBuffer->P)->data_format);
  6242. plci->ncpi_buffer[7] = ((T30_INFO *)plci->NL.RBuffer->P)->pages_low;
  6243. plci->ncpi_buffer[8] = ((T30_INFO *)plci->NL.RBuffer->P)->pages_high;
  6244. plci->ncpi_buffer[len] = 0;
  6245. if(((T30_INFO *)plci->NL.RBuffer->P)->station_id_len)
  6246. {
  6247. plci->ncpi_buffer[len] = 20;
  6248. for (i = 0; i < 20; i++)
  6249. plci->ncpi_buffer[++len] = ((T30_INFO *)plci->NL.RBuffer->P)->station_id[i];
  6250. }
  6251. if (((plci->NL.Ind & 0x0f) == N_DISC) || ((plci->NL.Ind & 0x0f) == N_DISC_ACK))
  6252. {
  6253. if (((T30_INFO *)plci->NL.RBuffer->P)->code < sizeof(fax_info) / sizeof(fax_info[0]))
  6254. info = fax_info[((T30_INFO *)plci->NL.RBuffer->P)->code];
  6255. else
  6256. info = _FAX_PROTOCOL_ERROR;
  6257. }
  6258. if ((plci->requested_options_conn | plci->requested_options | a->requested_options_table[plci->appl->Id-1])
  6259. & ((1L << PRIVATE_FAX_SUB_SEP_PWD) | (1L << PRIVATE_FAX_NONSTANDARD)))
  6260. {
  6261. i = ((word)(((T30_INFO *) 0)->station_id + 20)) + ((T30_INFO *)plci->NL.RBuffer->P)->head_line_len;
  6262. while (i < plci->NL.RBuffer->length)
  6263. plci->ncpi_buffer[++len] = plci->NL.RBuffer->P[i++];
  6264. }
  6265. plci->ncpi_buffer[0] = len;
  6266. fax_feature_bits = GET_WORD(&((T30_INFO *)plci->NL.RBuffer->P)->feature_bits_low);
  6267. PUT_WORD(&((T30_INFO *)plci->fax_connect_info_buffer)->feature_bits_low, fax_feature_bits);
  6268. plci->ncpi_state |= NCPI_VALID_CONNECT_B3_IND;
  6269. if (((plci->NL.Ind &0x0f) == N_CONNECT_ACK)
  6270. || (((plci->NL.Ind &0x0f) == N_CONNECT)
  6271. && (fax_feature_bits & T30_FEATURE_BIT_POLLING))
  6272. || (((plci->NL.Ind &0x0f) == N_EDATA)
  6273. && ((((T30_INFO *)plci->NL.RBuffer->P)->code == EDATA_T30_TRAIN_OK)
  6274. || (((T30_INFO *)plci->NL.RBuffer->P)->code == EDATA_T30_DIS)
  6275. || (((T30_INFO *)plci->NL.RBuffer->P)->code == EDATA_T30_DTC))))
  6276. {
  6277. plci->ncpi_state |= NCPI_VALID_CONNECT_B3_ACT;
  6278. }
  6279. if (((plci->NL.Ind &0x0f) == N_DISC)
  6280. || ((plci->NL.Ind &0x0f) == N_DISC_ACK)
  6281. || (((plci->NL.Ind &0x0f) == N_EDATA)
  6282. && (((T30_INFO *)plci->NL.RBuffer->P)->code == EDATA_T30_EOP_CAPI)))
  6283. {
  6284. plci->ncpi_state |= NCPI_VALID_CONNECT_B3_ACT | NCPI_VALID_DISC_B3_IND;
  6285. }
  6286. }
  6287. break;
  6288. case B3_RTP:
  6289. if (((plci->NL.Ind & 0x0f) == N_DISC) || ((plci->NL.Ind & 0x0f) == N_DISC_ACK))
  6290. {
  6291. if (plci->NL.RLength != 0)
  6292. {
  6293. info = rtp_info[plci->NL.RBuffer->P[0]];
  6294. plci->ncpi_buffer[0] = plci->NL.RLength - 1;
  6295. for (i = 1; i < plci->NL.RLength; i++)
  6296. plci->ncpi_buffer[i] = plci->NL.RBuffer->P[i];
  6297. }
  6298. }
  6299. break;
  6300. }
  6301. plci->NL.RNR = 2;
  6302. }
  6303. switch(plci->NL.Ind &0x0f) {
  6304. case N_EDATA:
  6305. if ((plci->B3_prot == 4) || (plci->B3_prot == 5))
  6306. {
  6307. dbug(1,dprintf("EDATA ncci=0x%x state=%d code=%02x", ncci, a->ncci_state[ncci],
  6308. ((T30_INFO *)plci->NL.RBuffer->P)->code));
  6309. fax_send_edata_ack = (((T30_INFO *)(plci->fax_connect_info_buffer))->operating_mode == T30_OPERATING_MODE_CAPI_NEG);
  6310. if ((plci->nsf_control_bits & T30_NSF_CONTROL_BIT_ENABLE_NSF)
  6311. && (plci->nsf_control_bits & (T30_NSF_CONTROL_BIT_NEGOTIATE_IND | T30_NSF_CONTROL_BIT_NEGOTIATE_RESP))
  6312. && (((T30_INFO *)plci->NL.RBuffer->P)->code == EDATA_T30_DIS)
  6313. && (a->ncci_state[ncci] == OUTG_CON_PENDING)
  6314. && (plci->ncpi_state & NCPI_VALID_CONNECT_B3_ACT)
  6315. && !(plci->ncpi_state & NCPI_NEGOTIATE_B3_SENT))
  6316. {
  6317. ((T30_INFO *)(plci->fax_connect_info_buffer))->code = ((T30_INFO *)plci->NL.RBuffer->P)->code;
  6318. sendf(plci->appl,_MANUFACTURER_I,Id,0,"dwbS",_DI_MANU_ID,_DI_NEGOTIATE_B3,
  6319. (byte)(plci->ncpi_buffer[0] + 1), plci->ncpi_buffer);
  6320. plci->ncpi_state |= NCPI_NEGOTIATE_B3_SENT;
  6321. if (plci->nsf_control_bits & T30_NSF_CONTROL_BIT_NEGOTIATE_RESP)
  6322. fax_send_edata_ack = FALSE;
  6323. }
  6324. if (a->manufacturer_features & MANUFACTURER_FEATURE_FAX_PAPER_FORMATS)
  6325. {
  6326. switch (((T30_INFO *)plci->NL.RBuffer->P)->code)
  6327. {
  6328. case EDATA_T30_DIS:
  6329. if ((a->ncci_state[ncci] == OUTG_CON_PENDING)
  6330. && !(GET_WORD(&((T30_INFO *)plci->fax_connect_info_buffer)->control_bits_low) & T30_CONTROL_BIT_REQUEST_POLLING)
  6331. && (plci->ncpi_state & NCPI_VALID_CONNECT_B3_ACT)
  6332. && !(plci->ncpi_state & NCPI_CONNECT_B3_ACT_SENT))
  6333. {
  6334. a->ncci_state[ncci] = INC_ACT_PENDING;
  6335. if (plci->B3_prot == 4)
  6336. sendf(plci->appl,_CONNECT_B3_ACTIVE_I,Id,0,"s","");
  6337. else
  6338. sendf(plci->appl,_CONNECT_B3_ACTIVE_I,Id,0,"S",plci->ncpi_buffer);
  6339. plci->ncpi_state |= NCPI_CONNECT_B3_ACT_SENT;
  6340. }
  6341. break;
  6342. case EDATA_T30_TRAIN_OK:
  6343. if ((a->ncci_state[ncci] == INC_ACT_PENDING)
  6344. && (plci->ncpi_state & NCPI_VALID_CONNECT_B3_ACT)
  6345. && !(plci->ncpi_state & NCPI_CONNECT_B3_ACT_SENT))
  6346. {
  6347. if (plci->B3_prot == 4)
  6348. sendf(plci->appl,_CONNECT_B3_ACTIVE_I,Id,0,"s","");
  6349. else
  6350. sendf(plci->appl,_CONNECT_B3_ACTIVE_I,Id,0,"S",plci->ncpi_buffer);
  6351. plci->ncpi_state |= NCPI_CONNECT_B3_ACT_SENT;
  6352. }
  6353. break;
  6354. case EDATA_T30_EOP_CAPI:
  6355. if (a->ncci_state[ncci] == CONNECTED)
  6356. {
  6357. sendf(plci->appl,_DISCONNECT_B3_I,Id,0,"wS",GOOD,plci->ncpi_buffer);
  6358. a->ncci_state[ncci] = INC_DIS_PENDING;
  6359. plci->ncpi_state = 0;
  6360. fax_send_edata_ack = FALSE;
  6361. }
  6362. break;
  6363. }
  6364. }
  6365. else
  6366. {
  6367. switch (((T30_INFO *)plci->NL.RBuffer->P)->code)
  6368. {
  6369. case EDATA_T30_TRAIN_OK:
  6370. if ((a->ncci_state[ncci] == INC_ACT_PENDING)
  6371. && (plci->ncpi_state & NCPI_VALID_CONNECT_B3_ACT)
  6372. && !(plci->ncpi_state & NCPI_CONNECT_B3_ACT_SENT))
  6373. {
  6374. if (plci->B3_prot == 4)
  6375. sendf(plci->appl,_CONNECT_B3_ACTIVE_I,Id,0,"s","");
  6376. else
  6377. sendf(plci->appl,_CONNECT_B3_ACTIVE_I,Id,0,"S",plci->ncpi_buffer);
  6378. plci->ncpi_state |= NCPI_CONNECT_B3_ACT_SENT;
  6379. }
  6380. break;
  6381. }
  6382. }
  6383. if (fax_send_edata_ack)
  6384. {
  6385. ((T30_INFO *)(plci->fax_connect_info_buffer))->code = ((T30_INFO *)plci->NL.RBuffer->P)->code;
  6386. plci->fax_edata_ack_length = 1;
  6387. start_internal_command (Id, plci, fax_edata_ack_command);
  6388. }
  6389. }
  6390. else
  6391. {
  6392. dbug(1,dprintf("EDATA ncci=0x%x state=%d", ncci, a->ncci_state[ncci]));
  6393. }
  6394. break;
  6395. case N_CONNECT:
  6396. if (!a->ch_ncci[ch])
  6397. {
  6398. ncci = get_ncci (plci, ch, 0);
  6399. Id = (Id & 0xffff) | (((dword) ncci) << 16);
  6400. }
  6401. dbug(1,dprintf("N_CONNECT: ch=%d state=%d plci=%lx plci_Id=%lx plci_State=%d",
  6402. ch, a->ncci_state[ncci], a->ncci_plci[ncci], plci->Id, plci->State));
  6403. msg = _CONNECT_B3_I;
  6404. if (a->ncci_state[ncci] == IDLE)
  6405. plci->channels++;
  6406. else if (plci->B3_prot == 1)
  6407. msg = _CONNECT_B3_T90_ACTIVE_I;
  6408. a->ncci_state[ncci] = INC_CON_PENDING;
  6409. if(plci->B3_prot == 4)
  6410. sendf(plci->appl,msg,Id,0,"s","");
  6411. else
  6412. sendf(plci->appl,msg,Id,0,"S",plci->ncpi_buffer);
  6413. break;
  6414. case N_CONNECT_ACK:
  6415. dbug(1,dprintf("N_connect_Ack"));
  6416. if (plci->internal_command_queue[0]
  6417. && ((plci->adjust_b_state == ADJUST_B_CONNECT_2)
  6418. || (plci->adjust_b_state == ADJUST_B_CONNECT_3)
  6419. || (plci->adjust_b_state == ADJUST_B_CONNECT_4)))
  6420. {
  6421. (*(plci->internal_command_queue[0]))(Id, plci, 0);
  6422. if (!plci->internal_command)
  6423. next_internal_command (Id, plci);
  6424. break;
  6425. }
  6426. msg = _CONNECT_B3_ACTIVE_I;
  6427. if (plci->B3_prot == 1)
  6428. {
  6429. if (a->ncci_state[ncci] != OUTG_CON_PENDING)
  6430. msg = _CONNECT_B3_T90_ACTIVE_I;
  6431. a->ncci_state[ncci] = INC_ACT_PENDING;
  6432. sendf(plci->appl,msg,Id,0,"S",plci->ncpi_buffer);
  6433. }
  6434. else if ((plci->B3_prot == 4) || (plci->B3_prot == 5) || (plci->B3_prot == 7))
  6435. {
  6436. if ((a->ncci_state[ncci] == OUTG_CON_PENDING)
  6437. && (plci->ncpi_state & NCPI_VALID_CONNECT_B3_ACT)
  6438. && !(plci->ncpi_state & NCPI_CONNECT_B3_ACT_SENT))
  6439. {
  6440. a->ncci_state[ncci] = INC_ACT_PENDING;
  6441. if (plci->B3_prot == 4)
  6442. sendf(plci->appl,msg,Id,0,"s","");
  6443. else
  6444. sendf(plci->appl,msg,Id,0,"S",plci->ncpi_buffer);
  6445. plci->ncpi_state |= NCPI_CONNECT_B3_ACT_SENT;
  6446. }
  6447. }
  6448. else
  6449. {
  6450. a->ncci_state[ncci] = INC_ACT_PENDING;
  6451. sendf(plci->appl,msg,Id,0,"S",plci->ncpi_buffer);
  6452. }
  6453. if (plci->adjust_b_restore)
  6454. {
  6455. plci->adjust_b_restore = FALSE;
  6456. start_internal_command (Id, plci, adjust_b_restore);
  6457. }
  6458. break;
  6459. case N_DISC:
  6460. case N_DISC_ACK:
  6461. if (plci->internal_command_queue[0]
  6462. && ((plci->internal_command == FAX_DISCONNECT_COMMAND_1)
  6463. || (plci->internal_command == FAX_DISCONNECT_COMMAND_2)
  6464. || (plci->internal_command == FAX_DISCONNECT_COMMAND_3)))
  6465. {
  6466. (*(plci->internal_command_queue[0]))(Id, plci, 0);
  6467. if (!plci->internal_command)
  6468. next_internal_command (Id, plci);
  6469. }
  6470. ncci_state = a->ncci_state[ncci];
  6471. ncci_remove (plci, ncci, FALSE);
  6472. /* with N_DISC or N_DISC_ACK the IDI frees the respective */
  6473. /* channel, so we cannot store the state in ncci_state! The */
  6474. /* information which channel we received a N_DISC is thus */
  6475. /* stored in the inc_dis_ncci_table buffer. */
  6476. for(i=0; plci->inc_dis_ncci_table[i]; i++);
  6477. plci->inc_dis_ncci_table[i] = (byte) ncci;
  6478. /* need a connect_b3_ind before a disconnect_b3_ind with FAX */
  6479. if (!plci->channels
  6480. && (plci->B1_resource == 16)
  6481. && (plci->State <= CONNECTED))
  6482. {
  6483. len = 9;
  6484. i = ((T30_INFO *)plci->fax_connect_info_buffer)->rate_div_2400 * 2400;
  6485. PUT_WORD (&plci->ncpi_buffer[1], i);
  6486. PUT_WORD (&plci->ncpi_buffer[3], 0);
  6487. i = ((T30_INFO *)plci->fax_connect_info_buffer)->data_format;
  6488. PUT_WORD (&plci->ncpi_buffer[5], i);
  6489. PUT_WORD (&plci->ncpi_buffer[7], 0);
  6490. plci->ncpi_buffer[len] = 0;
  6491. plci->ncpi_buffer[0] = len;
  6492. if(plci->B3_prot == 4)
  6493. sendf(plci->appl,_CONNECT_B3_I,Id,0,"s","");
  6494. else
  6495. {
  6496. if ((plci->requested_options_conn | plci->requested_options | a->requested_options_table[plci->appl->Id-1])
  6497. & ((1L << PRIVATE_FAX_SUB_SEP_PWD) | (1L << PRIVATE_FAX_NONSTANDARD)))
  6498. {
  6499. plci->ncpi_buffer[++len] = 0;
  6500. plci->ncpi_buffer[++len] = 0;
  6501. plci->ncpi_buffer[++len] = 0;
  6502. plci->ncpi_buffer[0] = len;
  6503. }
  6504. sendf(plci->appl,_CONNECT_B3_I,Id,0,"S",plci->ncpi_buffer);
  6505. }
  6506. sendf(plci->appl,_DISCONNECT_B3_I,Id,0,"wS",info,plci->ncpi_buffer);
  6507. plci->ncpi_state = 0;
  6508. sig_req(plci,HANGUP,0);
  6509. send_req(plci);
  6510. plci->State = OUTG_DIS_PENDING;
  6511. /* disc here */
  6512. }
  6513. else if ((a->manufacturer_features & MANUFACTURER_FEATURE_FAX_PAPER_FORMATS)
  6514. && ((plci->B3_prot == 4) || (plci->B3_prot == 5))
  6515. && ((ncci_state == INC_DIS_PENDING) || (ncci_state == IDLE)))
  6516. {
  6517. if (ncci_state == IDLE)
  6518. {
  6519. if (plci->channels)
  6520. plci->channels--;
  6521. if((plci->State==IDLE || plci->State==SUSPENDING) && !plci->channels){
  6522. if(plci->State == SUSPENDING){
  6523. sendf(plci->appl,
  6524. _FACILITY_I,
  6525. Id & 0xffffL,
  6526. 0,
  6527. "ws", (word)3, "\x03\x04\x00\x00");
  6528. sendf(plci->appl, _DISCONNECT_I, Id & 0xffffL, 0, "w", 0);
  6529. }
  6530. plci_remove(plci);
  6531. plci->State=IDLE;
  6532. }
  6533. }
  6534. }
  6535. else if (plci->channels)
  6536. {
  6537. sendf(plci->appl,_DISCONNECT_B3_I,Id,0,"wS",info,plci->ncpi_buffer);
  6538. plci->ncpi_state = 0;
  6539. if ((ncci_state == OUTG_REJ_PENDING)
  6540. && ((plci->B3_prot != B3_T90NL) && (plci->B3_prot != B3_ISO8208) && (plci->B3_prot != B3_X25_DCE)))
  6541. {
  6542. sig_req(plci,HANGUP,0);
  6543. send_req(plci);
  6544. plci->State = OUTG_DIS_PENDING;
  6545. }
  6546. }
  6547. break;
  6548. case N_RESET:
  6549. a->ncci_state[ncci] = INC_RES_PENDING;
  6550. sendf(plci->appl,_RESET_B3_I,Id,0,"S",plci->ncpi_buffer);
  6551. break;
  6552. case N_RESET_ACK:
  6553. a->ncci_state[ncci] = CONNECTED;
  6554. sendf(plci->appl,_RESET_B3_I,Id,0,"S",plci->ncpi_buffer);
  6555. break;
  6556. case N_UDATA:
  6557. if (!(udata_forwarding_table[plci->NL.RBuffer->P[0] >> 5] & (1L << (plci->NL.RBuffer->P[0] & 0x1f))))
  6558. {
  6559. plci->RData[0].P = plci->internal_ind_buffer + (-((int)(plci->internal_ind_buffer)) & 3);
  6560. plci->RData[0].PLength = INTERNAL_IND_BUFFER_SIZE;
  6561. plci->NL.R = plci->RData;
  6562. plci->NL.RNum = 1;
  6563. return;
  6564. }
  6565. case N_BDATA:
  6566. case N_DATA:
  6567. if (((a->ncci_state[ncci] != CONNECTED) && (plci->B2_prot == 1)) /* transparent */
  6568. || (a->ncci_state[ncci] == IDLE)
  6569. || (a->ncci_state[ncci] == INC_DIS_PENDING))
  6570. {
  6571. plci->NL.RNR = 2;
  6572. break;
  6573. }
  6574. if ((a->ncci_state[ncci] != CONNECTED)
  6575. && (a->ncci_state[ncci] != OUTG_DIS_PENDING)
  6576. && (a->ncci_state[ncci] != OUTG_REJ_PENDING))
  6577. {
  6578. dbug(1,dprintf("flow control"));
  6579. plci->NL.RNR = 1; /* flow control */
  6580. channel_x_off (plci, ch, 0);
  6581. break;
  6582. }
  6583. NCCIcode = ncci | (((word)a->Id) << 8);
  6584. /* count all buffers within the Application pool */
  6585. /* belonging to the same NCCI. If this is below the */
  6586. /* number of buffers available per NCCI we accept */
  6587. /* this packet, otherwise we reject it */
  6588. count = 0;
  6589. Num = 0xffff;
  6590. for(i=0; i<APPLptr->MaxBuffer; i++) {
  6591. if(NCCIcode==APPLptr->DataNCCI[i]) count++;
  6592. if(!APPLptr->DataNCCI[i] && Num==0xffff) Num = i;
  6593. }
  6594. if(count>=APPLptr->MaxNCCIData || Num==0xffff)
  6595. {
  6596. dbug(3,dprintf("Flow-Control"));
  6597. plci->NL.RNR = 1;
  6598. if( ++(APPLptr->NCCIDataFlowCtrlTimer)>=
  6599. (word)((a->manufacturer_features & MANUFACTURER_FEATURE_OOB_CHANNEL) ? 40 : 2000))
  6600. {
  6601. plci->NL.RNR = 2;
  6602. dbug(3,dprintf("DiscardData"));
  6603. } else {
  6604. channel_x_off (plci, ch, 0);
  6605. }
  6606. break;
  6607. }
  6608. else
  6609. {
  6610. APPLptr->NCCIDataFlowCtrlTimer = 0;
  6611. }
  6612. plci->RData[0].P = ReceiveBufferGet(APPLptr,Num);
  6613. if(!plci->RData[0].P) {
  6614. plci->NL.RNR = 1;
  6615. channel_x_off (plci, ch, 0);
  6616. break;
  6617. }
  6618. APPLptr->DataNCCI[Num] = NCCIcode;
  6619. APPLptr->DataFlags[Num] = (plci->Id<<8) | (plci->NL.Ind>>4);
  6620. dbug(3,dprintf("Buffer(%d), Max = %d",Num,APPLptr->MaxBuffer));
  6621. plci->RNum = Num;
  6622. plci->RFlags = plci->NL.Ind>>4;
  6623. plci->RData[0].PLength = APPLptr->MaxDataLength;
  6624. plci->NL.R = plci->RData;
  6625. if ((plci->NL.RLength != 0)
  6626. && ((plci->B2_prot == B2_V120_ASYNC)
  6627. || (plci->B2_prot == B2_V120_ASYNC_V42BIS)
  6628. || (plci->B2_prot == B2_V120_BIT_TRANSPARENT)))
  6629. {
  6630. plci->RData[1].P = plci->RData[0].P;
  6631. plci->RData[1].PLength = plci->RData[0].PLength;
  6632. plci->RData[0].P = v120_header_buffer + (-((int) v120_header_buffer) & 3);
  6633. if ((plci->NL.RBuffer->P[0] & V120_HEADER_EXTEND_BIT) || (plci->NL.RLength == 1))
  6634. plci->RData[0].PLength = 1;
  6635. else
  6636. plci->RData[0].PLength = 2;
  6637. if (plci->NL.RBuffer->P[0] & V120_HEADER_BREAK_BIT)
  6638. plci->RFlags |= 0x0010;
  6639. if (plci->NL.RBuffer->P[0] & (V120_HEADER_C1_BIT | V120_HEADER_C2_BIT))
  6640. plci->RFlags |= 0x8000;
  6641. plci->NL.RNum = 2;
  6642. }
  6643. else
  6644. {
  6645. if((plci->NL.Ind &0x0f)==N_UDATA)
  6646. plci->RFlags |= 0x0010;
  6647. else if ((plci->B3_prot == B3_RTP) && ((plci->NL.Ind & 0x0f) == N_BDATA))
  6648. plci->RFlags |= 0x0001;
  6649. plci->NL.RNum = 1;
  6650. }
  6651. break;
  6652. case N_DATA_ACK:
  6653. data_ack (plci, ch);
  6654. break;
  6655. default:
  6656. plci->NL.RNR = 2;
  6657. break;
  6658. }
  6659. }
  6660. /*------------------------------------------------------------------*/
  6661. /* find a free PLCI */
  6662. /*------------------------------------------------------------------*/
  6663. word get_plci(DIVA_CAPI_ADAPTER * a)
  6664. {
  6665. word i,j;
  6666. PLCI * plci;
  6667. dump_plcis (a);
  6668. for(i=0;i<a->max_plci && a->plci[i].Id;i++);
  6669. if(i==a->max_plci) {
  6670. dbug(1,dprintf("get_plci: out of PLCIs"));
  6671. return 0;
  6672. }
  6673. plci = &a->plci[i];
  6674. plci->Id = (byte)(i+1);
  6675. plci->Sig.Id = 0;
  6676. plci->NL.Id = 0;
  6677. plci->sig_req = 0;
  6678. plci->nl_req = 0;
  6679. plci->appl = NULL;
  6680. plci->relatedPTYPLCI = NULL;
  6681. plci->State = IDLE;
  6682. plci->SuppState = IDLE;
  6683. plci->channels = 0;
  6684. plci->tel = 0;
  6685. plci->B1_resource = 0;
  6686. plci->B2_prot = 0;
  6687. plci->B3_prot = 0;
  6688. plci->command = 0;
  6689. plci->m_command = 0;
  6690. init_internal_command_queue (plci);
  6691. plci->number = 0;
  6692. plci->req_in_start = 0;
  6693. plci->req_in = 0;
  6694. plci->req_out = 0;
  6695. plci->msg_in_write_pos = MSG_IN_QUEUE_SIZE;
  6696. plci->msg_in_read_pos = MSG_IN_QUEUE_SIZE;
  6697. plci->msg_in_wrap_pos = MSG_IN_QUEUE_SIZE;
  6698. plci->data_sent = FALSE;
  6699. plci->send_disc = 0;
  6700. plci->sig_global_req = 0;
  6701. plci->sig_remove_id = 0;
  6702. plci->nl_global_req = 0;
  6703. plci->nl_remove_id = 0;
  6704. plci->adv_nl = 0;
  6705. plci->manufacturer = FALSE;
  6706. plci->call_dir = CALL_DIR_OUT | CALL_DIR_ORIGINATE;
  6707. plci->spoofed_msg = 0;
  6708. plci->ptyState = 0;
  6709. plci->cr_enquiry = FALSE;
  6710. plci->hangup_flow_ctrl_timer = 0;
  6711. plci->ncci_ring_list = 0;
  6712. for(j=0;j<MAX_CHANNELS_PER_PLCI;j++) plci->inc_dis_ncci_table[j] = 0;
  6713. clear_c_ind_mask (plci);
  6714. set_group_ind_mask (plci);
  6715. plci->fax_connect_info_length = 0;
  6716. plci->nsf_control_bits = 0;
  6717. plci->ncpi_state = 0x00;
  6718. plci->ncpi_buffer[0] = 0;
  6719. plci->requested_options_conn = 0;
  6720. plci->requested_options = 0;
  6721. plci->notifiedcall = 0;
  6722. plci->vswitchstate = 0;
  6723. plci->vsprot = 0;
  6724. plci->vsprotdialect = 0;
  6725. init_b1_config (plci);
  6726. dbug(1,dprintf("get_plci(%x)",plci->Id));
  6727. return i+1;
  6728. }
  6729. /*------------------------------------------------------------------*/
  6730. /* put a parameter in the parameter buffer */
  6731. /*------------------------------------------------------------------*/
  6732. static void add_p(PLCI * plci, byte code, byte * p)
  6733. {
  6734. word p_length;
  6735. p_length = 0;
  6736. if(p) p_length = p[0];
  6737. add_ie(plci, code, p, p_length);
  6738. }
  6739. /*------------------------------------------------------------------*/
  6740. /* put a structure in the parameter buffer */
  6741. /*------------------------------------------------------------------*/
  6742. static void add_s(PLCI * plci, byte code, API_PARSE * p)
  6743. {
  6744. if(p) add_ie(plci, code, p->info, (word)p->length);
  6745. }
  6746. /*------------------------------------------------------------------*/
  6747. /* put multiple structures in the parameter buffer */
  6748. /*------------------------------------------------------------------*/
  6749. static void add_ss(PLCI * plci, byte code, API_PARSE * p)
  6750. {
  6751. byte i;
  6752. if(p){
  6753. dbug(1,dprintf("add_ss(%x,len=%d)",code,p->length));
  6754. for(i=2;i<(byte)p->length;i+=p->info[i]+2){
  6755. dbug(1,dprintf("add_ss_ie(%x,len=%d)",p->info[i-1],p->info[i]));
  6756. add_ie(plci, p->info[i-1], (byte *)&(p->info[i]), (word)p->info[i]);
  6757. }
  6758. }
  6759. }
  6760. /*------------------------------------------------------------------*/
  6761. /* return the channel number sent by the application in a esc_chi */
  6762. /*------------------------------------------------------------------*/
  6763. static byte getChannel(API_PARSE * p)
  6764. {
  6765. byte i;
  6766. if(p){
  6767. for(i=2;i<(byte)p->length;i+=p->info[i]+2){
  6768. if(p->info[i]==2){
  6769. if(p->info[i-1]==ESC && p->info[i+1]==CHI) return (p->info[i+2]);
  6770. }
  6771. }
  6772. }
  6773. return 0;
  6774. }
  6775. /*------------------------------------------------------------------*/
  6776. /* put an information element in the parameter buffer */
  6777. /*------------------------------------------------------------------*/
  6778. static void add_ie(PLCI * plci, byte code, byte * p, word p_length)
  6779. {
  6780. word i;
  6781. if(!(code &0x80) && !p_length) return;
  6782. if(plci->req_in==plci->req_in_start) {
  6783. plci->req_in +=2;
  6784. }
  6785. else {
  6786. plci->req_in--;
  6787. }
  6788. plci->RBuffer[plci->req_in++] = code;
  6789. if(p) {
  6790. plci->RBuffer[plci->req_in++] = (byte)p_length;
  6791. for(i=0;i<p_length;i++) plci->RBuffer[plci->req_in++] = p[1+i];
  6792. }
  6793. plci->RBuffer[plci->req_in++] = 0;
  6794. }
  6795. /*------------------------------------------------------------------*/
  6796. /* put a unstructured data into the buffer */
  6797. /*------------------------------------------------------------------*/
  6798. void add_d(PLCI * plci, word length, byte * p)
  6799. {
  6800. word i;
  6801. if(plci->req_in==plci->req_in_start) {
  6802. plci->req_in +=2;
  6803. }
  6804. else {
  6805. plci->req_in--;
  6806. }
  6807. for(i=0;i<length;i++) plci->RBuffer[plci->req_in++] = p[i];
  6808. }
  6809. /*------------------------------------------------------------------*/
  6810. /* put parameters from the Additional Info parameter in the */
  6811. /* parameter buffer */
  6812. /*------------------------------------------------------------------*/
  6813. void add_ai(PLCI * plci, API_PARSE * ai)
  6814. {
  6815. word i;
  6816. API_PARSE ai_parms[5];
  6817. for(i=0;i<5;i++) ai_parms[i].length = 0;
  6818. if(!ai->length)
  6819. return;
  6820. if(api_parse(&ai->info[1], (word)ai->length, "ssss", ai_parms))
  6821. return;
  6822. add_s (plci,KEY,&ai_parms[1]);
  6823. add_s (plci,UUI,&ai_parms[2]);
  6824. add_ss(plci,FTY,&ai_parms[3]);
  6825. }
  6826. /*------------------------------------------------------------------*/
  6827. /* put parameter for b1 protocol in the parameter buffer */
  6828. /*------------------------------------------------------------------*/
  6829. word add_b1(PLCI * plci, API_PARSE * bp, word b_channel_info, word b1_facilities)
  6830. {
  6831. API_PARSE bp_parms[8];
  6832. API_PARSE mdm_cfg[9];
  6833. API_PARSE global_config[2];
  6834. byte cai[256];
  6835. byte resource[] = {5,9,13,12,16,39,9,17,17,18};
  6836. byte voice_cai[] = "\x06\x14\x00\x00\x00\x00\x08";
  6837. word i;
  6838. API_PARSE mdm_cfg_v18[4];
  6839. word j, n, w;
  6840. dword d;
  6841. for(i=0;i<8;i++) bp_parms[i].length = 0;
  6842. for(i=0;i<2;i++) global_config[i].length = 0;
  6843. dbug(1,dprintf("add_b1"));
  6844. api_save_msg(bp, "s", &plci->B_protocol);
  6845. if(b_channel_info==2){
  6846. plci->B1_resource = 0;
  6847. adjust_b1_facilities (plci, plci->B1_resource, b1_facilities);
  6848. add_p(plci, CAI, "\x01\x00");
  6849. dbug(1,dprintf("Cai=1,0 (no resource)"));
  6850. return 0;
  6851. }
  6852. if(plci->tel == CODEC_PERMANENT) return 0;
  6853. else if(plci->tel == CODEC){
  6854. plci->B1_resource = 1;
  6855. adjust_b1_facilities (plci, plci->B1_resource, b1_facilities);
  6856. add_p(plci, CAI, "\x01\x01");
  6857. dbug(1,dprintf("Cai=1,1 (Codec)"));
  6858. return 0;
  6859. }
  6860. else if(plci->tel == ADV_VOICE){
  6861. plci->B1_resource = add_b1_facilities (plci, 9, (word)(b1_facilities | B1_FACILITY_VOICE));
  6862. adjust_b1_facilities (plci, plci->B1_resource, (word)(b1_facilities | B1_FACILITY_VOICE));
  6863. voice_cai[1] = plci->B1_resource;
  6864. PUT_WORD (&voice_cai[5], plci->appl->MaxDataLength);
  6865. add_p(plci, CAI, voice_cai);
  6866. dbug(1,dprintf("Cai=1,0x%x (AdvVoice)",voice_cai[1]));
  6867. return 0;
  6868. }
  6869. plci->call_dir &= ~(CALL_DIR_ORIGINATE | CALL_DIR_ANSWER);
  6870. if (plci->call_dir & CALL_DIR_OUT)
  6871. plci->call_dir |= CALL_DIR_ORIGINATE;
  6872. else if (plci->call_dir & CALL_DIR_IN)
  6873. plci->call_dir |= CALL_DIR_ANSWER;
  6874. if(!bp->length){
  6875. plci->B1_resource = 0x5;
  6876. adjust_b1_facilities (plci, plci->B1_resource, b1_facilities);
  6877. add_p(plci, CAI, "\x01\x05");
  6878. return 0;
  6879. }
  6880. dbug(1,dprintf("b_prot_len=%d",(word)bp->length));
  6881. if(bp->length>256) return _WRONG_MESSAGE_FORMAT;
  6882. if(api_parse(&bp->info[1], (word)bp->length, "wwwsssb", bp_parms))
  6883. {
  6884. bp_parms[6].length = 0;
  6885. if(api_parse(&bp->info[1], (word)bp->length, "wwwsss", bp_parms))
  6886. {
  6887. dbug(1,dprintf("b-form.!"));
  6888. return _WRONG_MESSAGE_FORMAT;
  6889. }
  6890. }
  6891. else if (api_parse(&bp->info[1], (word)bp->length, "wwwssss", bp_parms))
  6892. {
  6893. dbug(1,dprintf("b-form.!"));
  6894. return _WRONG_MESSAGE_FORMAT;
  6895. }
  6896. if(bp_parms[6].length)
  6897. {
  6898. if(api_parse(&bp_parms[6].info[1], (word)bp_parms[6].length, "w", global_config))
  6899. {
  6900. return _WRONG_MESSAGE_FORMAT;
  6901. }
  6902. switch(GET_WORD(global_config[0].info))
  6903. {
  6904. case 1:
  6905. plci->call_dir = (plci->call_dir & ~CALL_DIR_ANSWER) | CALL_DIR_ORIGINATE;
  6906. break;
  6907. case 2:
  6908. plci->call_dir = (plci->call_dir & ~CALL_DIR_ORIGINATE) | CALL_DIR_ANSWER;
  6909. break;
  6910. }
  6911. }
  6912. dbug(1,dprintf("call_dir=%04x", plci->call_dir));
  6913. if ((GET_WORD(bp_parms[0].info) == B1_RTP)
  6914. && (plci->adapter->man_profile.private_options & (1L << PRIVATE_RTP)))
  6915. {
  6916. plci->B1_resource = add_b1_facilities (plci, 31, (word)(b1_facilities & ~B1_FACILITY_VOICE));
  6917. adjust_b1_facilities (plci, plci->B1_resource, (word)(b1_facilities & ~B1_FACILITY_VOICE));
  6918. cai[1] = plci->B1_resource;
  6919. cai[2] = 0;
  6920. cai[3] = 0;
  6921. cai[4] = 0;
  6922. PUT_WORD(&cai[5],plci->appl->MaxDataLength);
  6923. for (i = 0; i < bp_parms[3].length; i++)
  6924. cai[7+i] = bp_parms[3].info[1+i];
  6925. cai[0] = 6 + bp_parms[3].length;
  6926. add_p(plci, CAI, cai);
  6927. return 0;
  6928. }
  6929. if ((GET_WORD(bp_parms[0].info) == B1_PIAFS)
  6930. && (plci->adapter->man_profile.private_options & (1L << PRIVATE_PIAFS)))
  6931. {
  6932. plci->B1_resource = add_b1_facilities (plci, 35/* PIAFS HARDWARE FACILITY */, (word)(b1_facilities & ~B1_FACILITY_VOICE));
  6933. adjust_b1_facilities (plci, plci->B1_resource, (word)(b1_facilities & ~B1_FACILITY_VOICE));
  6934. cai[1] = plci->B1_resource;
  6935. cai[2] = 0;
  6936. cai[3] = 0;
  6937. cai[4] = 0;
  6938. PUT_WORD(&cai[5],plci->appl->MaxDataLength);
  6939. cai[0] = 6;
  6940. add_p(plci, CAI, cai);
  6941. return 0;
  6942. }
  6943. if ((GET_WORD(bp_parms[0].info) >= 32)
  6944. || (!((1L << GET_WORD(bp_parms[0].info)) & plci->adapter->profile.B1_Protocols)
  6945. && ((GET_WORD(bp_parms[0].info) != 3)
  6946. || !((1L << B1_HDLC) & plci->adapter->profile.B1_Protocols)
  6947. || ((bp_parms[3].length != 0) && (GET_WORD(&bp_parms[3].info[1]) != 0) && (GET_WORD(&bp_parms[3].info[1]) != 56000)))))
  6948. {
  6949. return _B1_NOT_SUPPORTED;
  6950. }
  6951. plci->B1_resource = add_b1_facilities (plci, resource[GET_WORD(bp_parms[0].info)],
  6952. (word)(b1_facilities & ~B1_FACILITY_VOICE));
  6953. adjust_b1_facilities (plci, plci->B1_resource, (word)(b1_facilities & ~B1_FACILITY_VOICE));
  6954. cai[0] = 6;
  6955. cai[1] = plci->B1_resource;
  6956. for (i=2;i<sizeof(cai);i++) cai[i] = 0;
  6957. if ((GET_WORD(bp_parms[0].info) == B1_MODEM_ALL_NEGOTIATE)
  6958. || (GET_WORD(bp_parms[0].info) == B1_MODEM_ASYNC)
  6959. || (GET_WORD(bp_parms[0].info) == B1_MODEM_SYNC_HDLC))
  6960. { /* B1 - modem */
  6961. for (i=0;i<7;i++) mdm_cfg[i].length = 0;
  6962. if (bp_parms[3].length)
  6963. {
  6964. if(api_parse(&bp_parms[3].info[1],(word)bp_parms[3].length,"wwwwww", mdm_cfg))
  6965. {
  6966. return (_WRONG_MESSAGE_FORMAT);
  6967. }
  6968. cai[2] = 0; /* Bit rate for adaptation */
  6969. dbug(1,dprintf("MDM Max Bit Rate:<%d>", GET_WORD(mdm_cfg[0].info)));
  6970. PUT_WORD (&cai[13], 0); /* Min Tx speed */
  6971. PUT_WORD (&cai[15], GET_WORD(mdm_cfg[0].info)); /* Max Tx speed */
  6972. PUT_WORD (&cai[17], 0); /* Min Rx speed */
  6973. PUT_WORD (&cai[19], GET_WORD(mdm_cfg[0].info)); /* Max Rx speed */
  6974. cai[3] = 0; /* Async framing parameters */
  6975. switch (GET_WORD (mdm_cfg[2].info))
  6976. { /* Parity */
  6977. case 1: /* odd parity */
  6978. cai[3] |= (DSP_CAI_ASYNC_PARITY_ENABLE | DSP_CAI_ASYNC_PARITY_ODD);
  6979. dbug(1,dprintf("MDM: odd parity"));
  6980. break;
  6981. case 2: /* even parity */
  6982. cai[3] |= (DSP_CAI_ASYNC_PARITY_ENABLE | DSP_CAI_ASYNC_PARITY_EVEN);
  6983. dbug(1,dprintf("MDM: even parity"));
  6984. break;
  6985. default:
  6986. dbug(1,dprintf("MDM: no parity"));
  6987. break;
  6988. }
  6989. switch (GET_WORD (mdm_cfg[3].info))
  6990. { /* stop bits */
  6991. case 1: /* 2 stop bits */
  6992. cai[3] |= DSP_CAI_ASYNC_TWO_STOP_BITS;
  6993. dbug(1,dprintf("MDM: 2 stop bits"));
  6994. break;
  6995. default:
  6996. dbug(1,dprintf("MDM: 1 stop bit"));
  6997. break;
  6998. }
  6999. switch (GET_WORD (mdm_cfg[1].info))
  7000. { /* char length */
  7001. case 5:
  7002. cai[3] |= DSP_CAI_ASYNC_CHAR_LENGTH_5;
  7003. dbug(1,dprintf("MDM: 5 bits"));
  7004. break;
  7005. case 6:
  7006. cai[3] |= DSP_CAI_ASYNC_CHAR_LENGTH_6;
  7007. dbug(1,dprintf("MDM: 6 bits"));
  7008. break;
  7009. case 7:
  7010. cai[3] |= DSP_CAI_ASYNC_CHAR_LENGTH_7;
  7011. dbug(1,dprintf("MDM: 7 bits"));
  7012. break;
  7013. default:
  7014. dbug(1,dprintf("MDM: 8 bits"));
  7015. break;
  7016. }
  7017. cai[7] = 0; /* Line taking options */
  7018. cai[8] = 0; /* Modulation negotiation options */
  7019. cai[9] = 0; /* Modulation options */
  7020. if (((plci->call_dir & CALL_DIR_ORIGINATE) != 0) ^ ((plci->call_dir & CALL_DIR_OUT) != 0))
  7021. {
  7022. cai[9] |= DSP_CAI_MODEM_REVERSE_DIRECTION;
  7023. dbug(1, dprintf("MDM: Reverse direction"));
  7024. }
  7025. if (GET_WORD (mdm_cfg[4].info) & MDM_CAPI_DISABLE_RETRAIN)
  7026. {
  7027. cai[9] |= DSP_CAI_MODEM_DISABLE_RETRAIN;
  7028. dbug(1, dprintf("MDM: Disable retrain"));
  7029. }
  7030. if (GET_WORD (mdm_cfg[4].info) & MDM_CAPI_DISABLE_RING_TONE)
  7031. {
  7032. cai[7] |= DSP_CAI_MODEM_DISABLE_CALLING_TONE | DSP_CAI_MODEM_DISABLE_ANSWER_TONE;
  7033. dbug(1, dprintf("MDM: Disable ring tone"));
  7034. }
  7035. if (GET_WORD (mdm_cfg[4].info) & MDM_CAPI_GUARD_1800)
  7036. {
  7037. cai[8] |= DSP_CAI_MODEM_GUARD_TONE_1800HZ;
  7038. dbug(1, dprintf("MDM: 1800 guard tone"));
  7039. }
  7040. else if (GET_WORD (mdm_cfg[4].info) & MDM_CAPI_GUARD_550 )
  7041. {
  7042. cai[8] |= DSP_CAI_MODEM_GUARD_TONE_550HZ;
  7043. dbug(1, dprintf("MDM: 550 guard tone"));
  7044. }
  7045. if ((GET_WORD (mdm_cfg[5].info) & 0x00ff) == MDM_CAPI_NEG_V100)
  7046. {
  7047. cai[8] |= DSP_CAI_MODEM_NEGOTIATE_V100;
  7048. dbug(1, dprintf("MDM: V100"));
  7049. }
  7050. else if ((GET_WORD (mdm_cfg[5].info) & 0x00ff) == MDM_CAPI_NEG_MOD_CLASS)
  7051. {
  7052. cai[8] |= DSP_CAI_MODEM_NEGOTIATE_IN_CLASS;
  7053. dbug(1, dprintf("MDM: IN CLASS"));
  7054. }
  7055. else if ((GET_WORD (mdm_cfg[5].info) & 0x00ff) == MDM_CAPI_NEG_DISABLED)
  7056. {
  7057. cai[8] |= DSP_CAI_MODEM_NEGOTIATE_DISABLED;
  7058. dbug(1, dprintf("MDM: DISABLED"));
  7059. }
  7060. cai[0] = 20;
  7061. if ((plci->adapter->man_profile.private_options & (1L << PRIVATE_V18))
  7062. && (GET_WORD(mdm_cfg[5].info) & 0x8000)) /* Private V.18 enable */
  7063. {
  7064. plci->requested_options |= 1L << PRIVATE_V18;
  7065. }
  7066. if (GET_WORD(mdm_cfg[5].info) & 0x4000) /* Private VOWN enable */
  7067. plci->requested_options |= 1L << PRIVATE_VOWN;
  7068. if ((plci->requested_options_conn | plci->requested_options | plci->adapter->requested_options_table[plci->appl->Id-1])
  7069. & ((1L << PRIVATE_V18) | (1L << PRIVATE_VOWN)))
  7070. {
  7071. if (!api_parse(&bp_parms[3].info[1],(word)bp_parms[3].length,"wwwwwws", mdm_cfg))
  7072. {
  7073. i = 27;
  7074. if (mdm_cfg[6].length >= 4)
  7075. {
  7076. d = GET_DWORD(&mdm_cfg[6].info[1]);
  7077. cai[7] |= (byte) d; /* line taking options */
  7078. cai[9] |= (byte)(d >> 8); /* modulation options */
  7079. cai[++i] = (byte)(d >> 16); /* vown modulation options */
  7080. cai[++i] = (byte)(d >> 24);
  7081. if (mdm_cfg[6].length >= 8)
  7082. {
  7083. d = GET_DWORD(&mdm_cfg[6].info[5]);
  7084. cai[10] |= (byte) d; /* disabled modulations mask */
  7085. cai[11] |= (byte)(d >> 8);
  7086. if (mdm_cfg[6].length >= 12)
  7087. {
  7088. d = GET_DWORD(&mdm_cfg[6].info[9]);
  7089. cai[12] = (byte) d; /* enabled modulations mask */
  7090. cai[++i] = (byte)(d >> 8); /* vown enabled modulations */
  7091. cai[++i] = (byte)(d >> 16);
  7092. cai[++i] = (byte)(d >> 24);
  7093. cai[++i] = 0;
  7094. if (mdm_cfg[6].length >= 14)
  7095. {
  7096. w = GET_WORD(&mdm_cfg[6].info[13]);
  7097. if (w != 0)
  7098. PUT_WORD(&cai[13], w); /* min tx speed */
  7099. if (mdm_cfg[6].length >= 16)
  7100. {
  7101. w = GET_WORD(&mdm_cfg[6].info[15]);
  7102. if (w != 0)
  7103. PUT_WORD(&cai[15], w); /* max tx speed */
  7104. if (mdm_cfg[6].length >= 18)
  7105. {
  7106. w = GET_WORD(&mdm_cfg[6].info[17]);
  7107. if (w != 0)
  7108. PUT_WORD(&cai[17], w); /* min rx speed */
  7109. if (mdm_cfg[6].length >= 20)
  7110. {
  7111. w = GET_WORD(&mdm_cfg[6].info[19]);
  7112. if (w != 0)
  7113. PUT_WORD(&cai[19], w); /* max rx speed */
  7114. if (mdm_cfg[6].length >= 22)
  7115. {
  7116. w = GET_WORD(&mdm_cfg[6].info[21]);
  7117. cai[23] = (byte)(-((short) w)); /* transmit level */
  7118. if (mdm_cfg[6].length >= 24)
  7119. {
  7120. w = GET_WORD(&mdm_cfg[6].info[23]);
  7121. cai[22] |= (byte) w; /* info options mask */
  7122. cai[21] |= (byte)(w >> 8); /* disabled symbol rates */
  7123. }
  7124. }
  7125. }
  7126. }
  7127. }
  7128. }
  7129. }
  7130. }
  7131. }
  7132. cai[27] = i - 27;
  7133. i++;
  7134. if (!api_parse(&bp_parms[3].info[1],(word)bp_parms[3].length,"wwwwwwss", mdm_cfg))
  7135. {
  7136. if (!api_parse(&mdm_cfg[7].info[1],(word)mdm_cfg[7].length,"sss", mdm_cfg_v18))
  7137. {
  7138. for (n = 0; n < 3; n++)
  7139. {
  7140. cai[i] = (byte)(mdm_cfg_v18[n].length);
  7141. for (j = 1; j < ((word)(cai[i] + 1)); j++)
  7142. cai[i+j] = mdm_cfg_v18[n].info[j];
  7143. i += cai[i] + 1;
  7144. }
  7145. }
  7146. }
  7147. cai[0] = (byte)(i - 1);
  7148. }
  7149. }
  7150. }
  7151. }
  7152. if(GET_WORD(bp_parms[0].info)==2 || /* V.110 async */
  7153. GET_WORD(bp_parms[0].info)==3 ) /* V.110 sync */
  7154. {
  7155. if(bp_parms[3].length){
  7156. dbug(1,dprintf("V.110,%d",GET_WORD(&bp_parms[3].info[1])));
  7157. switch(GET_WORD(&bp_parms[3].info[1])){ /* Rate */
  7158. case 0:
  7159. case 56000:
  7160. if(GET_WORD(bp_parms[0].info)==3){ /* V.110 sync 56k */
  7161. dbug(1,dprintf("56k sync HSCX"));
  7162. cai[1] = 8;
  7163. cai[2] = 0;
  7164. cai[3] = 0;
  7165. }
  7166. else if(GET_WORD(bp_parms[0].info)==2){
  7167. dbug(1,dprintf("56k async DSP"));
  7168. cai[2] = 9;
  7169. }
  7170. break;
  7171. case 50: cai[2] = 1; break;
  7172. case 75: cai[2] = 1; break;
  7173. case 110: cai[2] = 1; break;
  7174. case 150: cai[2] = 1; break;
  7175. case 200: cai[2] = 1; break;
  7176. case 300: cai[2] = 1; break;
  7177. case 600: cai[2] = 1; break;
  7178. case 1200: cai[2] = 2; break;
  7179. case 2400: cai[2] = 3; break;
  7180. case 4800: cai[2] = 4; break;
  7181. case 7200: cai[2] = 10; break;
  7182. case 9600: cai[2] = 5; break;
  7183. case 12000: cai[2] = 13; break;
  7184. case 24000: cai[2] = 0; break;
  7185. case 14400: cai[2] = 11; break;
  7186. case 19200: cai[2] = 6; break;
  7187. case 28800: cai[2] = 12; break;
  7188. case 38400: cai[2] = 7; break;
  7189. case 48000: cai[2] = 8; break;
  7190. case 76: cai[2] = 15; break; /* 75/1200 */
  7191. case 1201: cai[2] = 14; break; /* 1200/75 */
  7192. case 56001: cai[2] = 9; break; /* V.110 56000 */
  7193. default:
  7194. return _B1_PARM_NOT_SUPPORTED;
  7195. }
  7196. cai[3] = 0;
  7197. if (cai[1] == 13) /* v.110 async */
  7198. {
  7199. if (bp_parms[3].length >= 8)
  7200. {
  7201. switch (GET_WORD (&bp_parms[3].info[3]))
  7202. { /* char length */
  7203. case 5:
  7204. cai[3] |= DSP_CAI_ASYNC_CHAR_LENGTH_5;
  7205. break;
  7206. case 6:
  7207. cai[3] |= DSP_CAI_ASYNC_CHAR_LENGTH_6;
  7208. break;
  7209. case 7:
  7210. cai[3] |= DSP_CAI_ASYNC_CHAR_LENGTH_7;
  7211. break;
  7212. }
  7213. switch (GET_WORD (&bp_parms[3].info[5]))
  7214. { /* Parity */
  7215. case 1: /* odd parity */
  7216. cai[3] |= (DSP_CAI_ASYNC_PARITY_ENABLE | DSP_CAI_ASYNC_PARITY_ODD);
  7217. break;
  7218. case 2: /* even parity */
  7219. cai[3] |= (DSP_CAI_ASYNC_PARITY_ENABLE | DSP_CAI_ASYNC_PARITY_EVEN);
  7220. break;
  7221. }
  7222. switch (GET_WORD (&bp_parms[3].info[7]))
  7223. { /* stop bits */
  7224. case 1: /* 2 stop bits */
  7225. cai[3] |= DSP_CAI_ASYNC_TWO_STOP_BITS;
  7226. break;
  7227. }
  7228. }
  7229. }
  7230. }
  7231. else if(cai[1]==8 || GET_WORD(bp_parms[0].info)==3 ){
  7232. dbug(1,dprintf("V.110 default 56k sync"));
  7233. cai[1] = 8;
  7234. cai[2] = 0;
  7235. cai[3] = 0;
  7236. }
  7237. else {
  7238. dbug(1,dprintf("V.110 default 9600 async"));
  7239. cai[2] = 5;
  7240. }
  7241. }
  7242. PUT_WORD(&cai[5],plci->appl->MaxDataLength);
  7243. 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]));
  7244. /* HexDump ("CAI", sizeof(cai), &cai[0]); */
  7245. add_p(plci, CAI, cai);
  7246. return 0;
  7247. }
  7248. /*------------------------------------------------------------------*/
  7249. /* put parameter for b2 and B3 protocol in the parameter buffer */
  7250. /*------------------------------------------------------------------*/
  7251. word add_b23(PLCI * plci, API_PARSE * bp)
  7252. {
  7253. word i, fax_control_bits;
  7254. byte pos, len;
  7255. byte SAPI = 0x40; /* default SAPI 16 for x.31 */
  7256. API_PARSE bp_parms[8];
  7257. API_PARSE * b1_config;
  7258. API_PARSE * b2_config;
  7259. API_PARSE b2_config_parms[8];
  7260. API_PARSE * b3_config;
  7261. API_PARSE b3_config_parms[6];
  7262. API_PARSE global_config[2];
  7263. static byte llc[3] = {2,0,0};
  7264. static byte dlc[20] = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
  7265. static byte nlc[256];
  7266. static byte lli[12] = {1,1};
  7267. const byte llc2_out[] = {1,2,4,6,2,0,0,0, X75_V42BIS,V120_L2,V120_V42BIS,V120_L2,6};
  7268. const byte llc2_in[] = {1,3,4,6,3,0,0,0, X75_V42BIS,V120_L2,V120_V42BIS,V120_L2,6};
  7269. const byte llc3[] = {4,3,2,2,6,6,0};
  7270. const byte header[] = {0,2,3,3,0,0,0};
  7271. for(i=0;i<8;i++) bp_parms[i].length = 0;
  7272. for(i=0;i<6;i++) b2_config_parms[i].length = 0;
  7273. for(i=0;i<5;i++) b3_config_parms[i].length = 0;
  7274. lli[0] = 1;
  7275. lli[1] = 1;
  7276. if (plci->adapter->manufacturer_features & MANUFACTURER_FEATURE_XONOFF_FLOW_CONTROL)
  7277. lli[1] |= 2;
  7278. if (plci->adapter->manufacturer_features & MANUFACTURER_FEATURE_OOB_CHANNEL)
  7279. lli[1] |= 4;
  7280. if ((lli[1] & 0x02) && (diva_xdi_extended_features & DIVA_CAPI_USE_CMA)) {
  7281. lli[1] |= 0x10;
  7282. if (plci->rx_dma_descriptor <= 0) {
  7283. plci->rx_dma_descriptor=diva_get_dma_descriptor(plci,&plci->rx_dma_magic);
  7284. if (plci->rx_dma_descriptor >= 0)
  7285. plci->rx_dma_descriptor++;
  7286. }
  7287. if (plci->rx_dma_descriptor > 0) {
  7288. lli[0] = 6;
  7289. lli[1] |= 0x40;
  7290. lli[2] = (byte)(plci->rx_dma_descriptor - 1);
  7291. lli[3] = (byte)plci->rx_dma_magic;
  7292. lli[4] = (byte)(plci->rx_dma_magic >> 8);
  7293. lli[5] = (byte)(plci->rx_dma_magic >> 16);
  7294. lli[6] = (byte)(plci->rx_dma_magic >> 24);
  7295. }
  7296. }
  7297. if (DIVA_CAPI_SUPPORTS_NO_CANCEL(plci->adapter)) {
  7298. lli[1] |= 0x20;
  7299. }
  7300. dbug(1,dprintf("add_b23"));
  7301. api_save_msg(bp, "s", &plci->B_protocol);
  7302. if(!bp->length && plci->tel)
  7303. {
  7304. plci->adv_nl = TRUE;
  7305. dbug(1,dprintf("Default adv.Nl"));
  7306. add_p(plci,LLI,lli);
  7307. plci->B2_prot = 1 /*XPARENT*/;
  7308. plci->B3_prot = 0 /*XPARENT*/;
  7309. llc[1] = 2;
  7310. llc[2] = 4;
  7311. add_p(plci, LLC, llc);
  7312. dlc[0] = 2;
  7313. PUT_WORD(&dlc[1],plci->appl->MaxDataLength);
  7314. add_p(plci, DLC, dlc);
  7315. return 0;
  7316. }
  7317. if(!bp->length) /*default*/
  7318. {
  7319. dbug(1,dprintf("ret default"));
  7320. add_p(plci,LLI,lli);
  7321. plci->B2_prot = 0 /*X.75 */;
  7322. plci->B3_prot = 0 /*XPARENT*/;
  7323. llc[1] = 1;
  7324. llc[2] = 4;
  7325. add_p(plci, LLC, llc);
  7326. dlc[0] = 2;
  7327. PUT_WORD(&dlc[1],plci->appl->MaxDataLength);
  7328. add_p(plci, DLC, dlc);
  7329. return 0;
  7330. }
  7331. dbug(1,dprintf("b_prot_len=%d",(word)bp->length));
  7332. if((word)bp->length > 256) return _WRONG_MESSAGE_FORMAT;
  7333. if(api_parse(&bp->info[1], (word)bp->length, "wwwsssb", bp_parms))
  7334. {
  7335. bp_parms[6].length = 0;
  7336. if(api_parse(&bp->info[1], (word)bp->length, "wwwsss", bp_parms))
  7337. {
  7338. dbug(1,dprintf("b-form.!"));
  7339. return _WRONG_MESSAGE_FORMAT;
  7340. }
  7341. }
  7342. else if (api_parse(&bp->info[1], (word)bp->length, "wwwssss", bp_parms))
  7343. {
  7344. dbug(1,dprintf("b-form.!"));
  7345. return _WRONG_MESSAGE_FORMAT;
  7346. }
  7347. if(plci->tel==ADV_VOICE) /* transparent B on advanced voice */
  7348. {
  7349. if(GET_WORD(bp_parms[1].info)!=1
  7350. || GET_WORD(bp_parms[2].info)!=0) return _B2_NOT_SUPPORTED;
  7351. plci->adv_nl = TRUE;
  7352. }
  7353. else if(plci->tel) return _B2_NOT_SUPPORTED;
  7354. if ((GET_WORD(bp_parms[1].info) == B2_RTP)
  7355. && (GET_WORD(bp_parms[2].info) == B3_RTP)
  7356. && (plci->adapter->man_profile.private_options & (1L << PRIVATE_RTP)))
  7357. {
  7358. add_p(plci,LLI,lli);
  7359. plci->B2_prot = (byte) GET_WORD(bp_parms[1].info);
  7360. plci->B3_prot = (byte) GET_WORD(bp_parms[2].info);
  7361. llc[1] = (plci->call_dir & (CALL_DIR_ORIGINATE | CALL_DIR_FORCE_OUTG_NL)) ? 14 : 13;
  7362. llc[2] = 4;
  7363. add_p(plci, LLC, llc);
  7364. dlc[0] = 2;
  7365. PUT_WORD(&dlc[1],plci->appl->MaxDataLength);
  7366. dlc[3] = 3; /* Addr A */
  7367. dlc[4] = 1; /* Addr B */
  7368. dlc[5] = 7; /* modulo mode */
  7369. dlc[6] = 7; /* window size */
  7370. dlc[7] = 0; /* XID len Lo */
  7371. dlc[8] = 0; /* XID len Hi */
  7372. for (i = 0; i < bp_parms[4].length; i++)
  7373. dlc[9+i] = bp_parms[4].info[1+i];
  7374. dlc[0] = (byte)(8 + bp_parms[4].length);
  7375. add_p(plci, DLC, dlc);
  7376. for (i = 0; i < bp_parms[5].length; i++)
  7377. nlc[1+i] = bp_parms[5].info[1+i];
  7378. nlc[0] = (byte)(bp_parms[5].length);
  7379. add_p(plci, NLC, nlc);
  7380. return 0;
  7381. }
  7382. if ((GET_WORD(bp_parms[1].info) >= 32)
  7383. || (!((1L << GET_WORD(bp_parms[1].info)) & plci->adapter->profile.B2_Protocols)
  7384. && ((GET_WORD(bp_parms[1].info) != B2_PIAFS)
  7385. || !(plci->adapter->man_profile.private_options & (1L << PRIVATE_PIAFS)))))
  7386. {
  7387. return _B2_NOT_SUPPORTED;
  7388. }
  7389. if ((GET_WORD(bp_parms[2].info) >= 32)
  7390. || !((1L << GET_WORD(bp_parms[2].info)) & plci->adapter->profile.B3_Protocols))
  7391. {
  7392. return _B3_NOT_SUPPORTED;
  7393. }
  7394. if ((GET_WORD(bp_parms[1].info) != B2_SDLC)
  7395. && ((GET_WORD(bp_parms[0].info) == B1_MODEM_ALL_NEGOTIATE)
  7396. || (GET_WORD(bp_parms[0].info) == B1_MODEM_ASYNC)
  7397. || (GET_WORD(bp_parms[0].info) == B1_MODEM_SYNC_HDLC)))
  7398. {
  7399. return (add_modem_b23 (plci, bp_parms));
  7400. }
  7401. add_p(plci,LLI,lli);
  7402. plci->B2_prot = (byte) GET_WORD(bp_parms[1].info);
  7403. plci->B3_prot = (byte) GET_WORD(bp_parms[2].info);
  7404. if(plci->B2_prot==12) SAPI = 0; /* default SAPI D-channel */
  7405. if(bp_parms[6].length)
  7406. {
  7407. if(api_parse(&bp_parms[6].info[1], (word)bp_parms[6].length, "w", global_config))
  7408. {
  7409. return _WRONG_MESSAGE_FORMAT;
  7410. }
  7411. switch(GET_WORD(global_config[0].info))
  7412. {
  7413. case 1:
  7414. plci->call_dir = (plci->call_dir & ~CALL_DIR_ANSWER) | CALL_DIR_ORIGINATE;
  7415. break;
  7416. case 2:
  7417. plci->call_dir = (plci->call_dir & ~CALL_DIR_ORIGINATE) | CALL_DIR_ANSWER;
  7418. break;
  7419. }
  7420. }
  7421. dbug(1,dprintf("call_dir=%04x", plci->call_dir));
  7422. if (plci->B2_prot == B2_PIAFS)
  7423. llc[1] = PIAFS_CRC;
  7424. else
  7425. /* IMPLEMENT_PIAFS */
  7426. {
  7427. llc[1] = (plci->call_dir & (CALL_DIR_ORIGINATE | CALL_DIR_FORCE_OUTG_NL)) ?
  7428. llc2_out[GET_WORD(bp_parms[1].info)] : llc2_in[GET_WORD(bp_parms[1].info)];
  7429. }
  7430. llc[2] = llc3[GET_WORD(bp_parms[2].info)];
  7431. add_p(plci, LLC, llc);
  7432. dlc[0] = 2;
  7433. PUT_WORD(&dlc[1], plci->appl->MaxDataLength +
  7434. header[GET_WORD(bp_parms[2].info)]);
  7435. b1_config = &bp_parms[3];
  7436. nlc[0] = 0;
  7437. if(plci->B3_prot == 4
  7438. || plci->B3_prot == 5)
  7439. {
  7440. for (i=0;i<sizeof(T30_INFO);i++) nlc[i] = 0;
  7441. nlc[0] = sizeof(T30_INFO);
  7442. if (plci->adapter->manufacturer_features & MANUFACTURER_FEATURE_FAX_PAPER_FORMATS)
  7443. ((T30_INFO *)&nlc[1])->operating_mode = T30_OPERATING_MODE_CAPI;
  7444. ((T30_INFO *)&nlc[1])->rate_div_2400 = 0xff;
  7445. if(b1_config->length>=2)
  7446. {
  7447. ((T30_INFO *)&nlc[1])->rate_div_2400 = (byte)(GET_WORD(&b1_config->info[1])/2400);
  7448. }
  7449. }
  7450. b2_config = &bp_parms[4];
  7451. if (llc[1] == PIAFS_CRC)
  7452. {
  7453. if (plci->B3_prot != B3_TRANSPARENT)
  7454. {
  7455. return _B_STACK_NOT_SUPPORTED;
  7456. }
  7457. if(b2_config->length && api_parse(&b2_config->info[1], (word)b2_config->length, "bwww", b2_config_parms)) {
  7458. return _WRONG_MESSAGE_FORMAT;
  7459. }
  7460. PUT_WORD(&dlc[1],plci->appl->MaxDataLength);
  7461. dlc[3] = 0; /* Addr A */
  7462. dlc[4] = 0; /* Addr B */
  7463. dlc[5] = 0; /* modulo mode */
  7464. dlc[6] = 0; /* window size */
  7465. if (b2_config->length >= 7){
  7466. dlc[ 7] = 7;
  7467. dlc[ 8] = 0;
  7468. dlc[ 9] = b2_config_parms[0].info[0]; /* PIAFS protocol Speed configuration */
  7469. dlc[10] = b2_config_parms[1].info[0]; /* V.42bis P0 */
  7470. dlc[11] = b2_config_parms[1].info[1]; /* V.42bis P0 */
  7471. dlc[12] = b2_config_parms[2].info[0]; /* V.42bis P1 */
  7472. dlc[13] = b2_config_parms[2].info[1]; /* V.42bis P1 */
  7473. dlc[14] = b2_config_parms[3].info[0]; /* V.42bis P2 */
  7474. dlc[15] = b2_config_parms[3].info[1]; /* V.42bis P2 */
  7475. dlc[ 0] = 15;
  7476. if(b2_config->length >= 8) { /* PIAFS control abilities */
  7477. dlc[ 7] = 10;
  7478. dlc[16] = 2; /* Length of PIAFS extention */
  7479. dlc[17] = PIAFS_UDATA_ABILITIES; /* control (UDATA) ability */
  7480. dlc[18] = b2_config_parms[4].info[0]; /* value */
  7481. dlc[ 0] = 18;
  7482. }
  7483. }
  7484. else /* default values, 64K, variable, no compression */
  7485. {
  7486. dlc[ 7] = 7;
  7487. dlc[ 8] = 0;
  7488. dlc[ 9] = 0x03; /* PIAFS protocol Speed configuration */
  7489. dlc[10] = 0x03; /* V.42bis P0 */
  7490. dlc[11] = 0; /* V.42bis P0 */
  7491. dlc[12] = 0; /* V.42bis P1 */
  7492. dlc[13] = 0; /* V.42bis P1 */
  7493. dlc[14] = 0; /* V.42bis P2 */
  7494. dlc[15] = 0; /* V.42bis P2 */
  7495. dlc[ 0] = 15;
  7496. }
  7497. add_p(plci, DLC, dlc);
  7498. }
  7499. else
  7500. if ((llc[1] == V120_L2) || (llc[1] == V120_V42BIS))
  7501. {
  7502. if (plci->B3_prot != B3_TRANSPARENT)
  7503. return _B_STACK_NOT_SUPPORTED;
  7504. dlc[0] = 6;
  7505. PUT_WORD (&dlc[1], GET_WORD (&dlc[1]) + 2);
  7506. dlc[3] = 0x08;
  7507. dlc[4] = 0x01;
  7508. dlc[5] = 127;
  7509. dlc[6] = 7;
  7510. if (b2_config->length != 0)
  7511. {
  7512. if((llc[1]==V120_V42BIS) && api_parse(&b2_config->info[1], (word)b2_config->length, "bbbbwww", b2_config_parms)) {
  7513. return _WRONG_MESSAGE_FORMAT;
  7514. }
  7515. dlc[3] = (byte)((b2_config->info[2] << 3) | ((b2_config->info[1] >> 5) & 0x04));
  7516. dlc[4] = (byte)((b2_config->info[1] << 1) | 0x01);
  7517. if (b2_config->info[3] != 128)
  7518. {
  7519. dbug(1,dprintf("1D-dlc= %x %x %x %x %x", dlc[0], dlc[1], dlc[2], dlc[3], dlc[4]));
  7520. return _B2_PARM_NOT_SUPPORTED;
  7521. }
  7522. dlc[5] = (byte)(b2_config->info[3] - 1);
  7523. dlc[6] = b2_config->info[4];
  7524. if(llc[1]==V120_V42BIS){
  7525. if (b2_config->length >= 10){
  7526. dlc[ 7] = 6;
  7527. dlc[ 8] = 0;
  7528. dlc[ 9] = b2_config_parms[4].info[0];
  7529. dlc[10] = b2_config_parms[4].info[1];
  7530. dlc[11] = b2_config_parms[5].info[0];
  7531. dlc[12] = b2_config_parms[5].info[1];
  7532. dlc[13] = b2_config_parms[6].info[0];
  7533. dlc[14] = b2_config_parms[6].info[1];
  7534. dlc[ 0] = 14;
  7535. dbug(1,dprintf("b2_config_parms[4].info[0] [1]: %x %x", b2_config_parms[4].info[0], b2_config_parms[4].info[1]));
  7536. dbug(1,dprintf("b2_config_parms[5].info[0] [1]: %x %x", b2_config_parms[5].info[0], b2_config_parms[5].info[1]));
  7537. dbug(1,dprintf("b2_config_parms[6].info[0] [1]: %x %x", b2_config_parms[6].info[0], b2_config_parms[6].info[1]));
  7538. }
  7539. else {
  7540. dlc[ 6] = 14;
  7541. }
  7542. }
  7543. }
  7544. }
  7545. else
  7546. {
  7547. if(b2_config->length)
  7548. {
  7549. dbug(1,dprintf("B2-Config"));
  7550. if(llc[1]==X75_V42BIS){
  7551. if(api_parse(&b2_config->info[1], (word)b2_config->length, "bbbbwww", b2_config_parms))
  7552. {
  7553. return _WRONG_MESSAGE_FORMAT;
  7554. }
  7555. }
  7556. else {
  7557. if(api_parse(&b2_config->info[1], (word)b2_config->length, "bbbbs", b2_config_parms))
  7558. {
  7559. return _WRONG_MESSAGE_FORMAT;
  7560. }
  7561. }
  7562. /* if B2 Protocol is LAPD, b2_config structure is different */
  7563. if(llc[1]==6)
  7564. {
  7565. dlc[0] = 4;
  7566. if(b2_config->length>=1) dlc[2] = b2_config->info[1]; /* TEI */
  7567. else dlc[2] = 0x01;
  7568. if( (b2_config->length>=2) && (plci->B2_prot==12) )
  7569. {
  7570. SAPI = b2_config->info[2]; /* SAPI */
  7571. }
  7572. dlc[1] = SAPI;
  7573. if( (b2_config->length>=3) && (b2_config->info[3]==128) )
  7574. {
  7575. dlc[3] = 127; /* Mode */
  7576. }
  7577. else
  7578. {
  7579. dlc[3] = 7; /* Mode */
  7580. }
  7581. if(b2_config->length>=4) dlc[4] = b2_config->info[4]; /* Window */
  7582. else dlc[4] = 1;
  7583. dbug(1,dprintf("D-dlc[%d]=%x,%x,%x,%x", dlc[0], dlc[1], dlc[2], dlc[3], dlc[4]));
  7584. if(b2_config->length>5) return _B2_PARM_NOT_SUPPORTED;
  7585. }
  7586. else
  7587. {
  7588. dlc[0] = (byte)(b2_config_parms[4].length+6);
  7589. dlc[3] = b2_config->info[1];
  7590. dlc[4] = b2_config->info[2];
  7591. if(b2_config->info[3]!=8 && b2_config->info[3]!=128){
  7592. dbug(1,dprintf("1D-dlc= %x %x %x %x %x", dlc[0], dlc[1], dlc[2], dlc[3], dlc[4]));
  7593. return _B2_PARM_NOT_SUPPORTED;
  7594. }
  7595. dlc[5] = (byte)(b2_config->info[3]-1);
  7596. dlc[6] = b2_config->info[4];
  7597. if(dlc[6]>dlc[5]){
  7598. 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]));
  7599. return _B2_PARM_NOT_SUPPORTED;
  7600. }
  7601. if(llc[1]==X75_V42BIS) {
  7602. if (b2_config->length >= 10){
  7603. dlc[ 7] = 6;
  7604. dlc[ 8] = 0;
  7605. dlc[ 9] = b2_config_parms[4].info[0];
  7606. dlc[10] = b2_config_parms[4].info[1];
  7607. dlc[11] = b2_config_parms[5].info[0];
  7608. dlc[12] = b2_config_parms[5].info[1];
  7609. dlc[13] = b2_config_parms[6].info[0];
  7610. dlc[14] = b2_config_parms[6].info[1];
  7611. dlc[ 0] = 14;
  7612. dbug(1,dprintf("b2_config_parms[4].info[0] [1]: %x %x", b2_config_parms[4].info[0], b2_config_parms[4].info[1]));
  7613. dbug(1,dprintf("b2_config_parms[5].info[0] [1]: %x %x", b2_config_parms[5].info[0], b2_config_parms[5].info[1]));
  7614. dbug(1,dprintf("b2_config_parms[6].info[0] [1]: %x %x", b2_config_parms[6].info[0], b2_config_parms[6].info[1]));
  7615. }
  7616. else {
  7617. dlc[ 6] = 14;
  7618. }
  7619. }
  7620. else {
  7621. PUT_WORD(&dlc[7], (word)b2_config_parms[4].length);
  7622. for(i=0; i<b2_config_parms[4].length; i++)
  7623. dlc[11+i] = b2_config_parms[4].info[1+i];
  7624. }
  7625. }
  7626. }
  7627. }
  7628. add_p(plci, DLC, dlc);
  7629. b3_config = &bp_parms[5];
  7630. if(b3_config->length)
  7631. {
  7632. if(plci->B3_prot == 4
  7633. || plci->B3_prot == 5)
  7634. {
  7635. if(api_parse(&b3_config->info[1], (word)b3_config->length, "wwss", b3_config_parms))
  7636. {
  7637. return _WRONG_MESSAGE_FORMAT;
  7638. }
  7639. i = GET_WORD((byte *)(b3_config_parms[0].info));
  7640. ((T30_INFO *)&nlc[1])->resolution = (byte)(((i & 0x0001) ||
  7641. ((plci->B3_prot == 4) && (((byte)(GET_WORD((byte *)b3_config_parms[1].info))) != 5))) ? T30_RESOLUTION_R8_0770_OR_200 : 0);
  7642. ((T30_INFO *)&nlc[1])->data_format = (byte)(GET_WORD((byte *)b3_config_parms[1].info));
  7643. fax_control_bits = T30_CONTROL_BIT_ALL_FEATURES;
  7644. if ((((T30_INFO *)&nlc[1])->rate_div_2400 != 0) && (((T30_INFO *)&nlc[1])->rate_div_2400 <= 6))
  7645. fax_control_bits &= ~T30_CONTROL_BIT_ENABLE_V34FAX;
  7646. if (plci->adapter->manufacturer_features & MANUFACTURER_FEATURE_FAX_PAPER_FORMATS)
  7647. {
  7648. if ((plci->requested_options_conn | plci->requested_options | plci->adapter->requested_options_table[plci->appl->Id-1])
  7649. & (1L << PRIVATE_FAX_PAPER_FORMATS))
  7650. {
  7651. ((T30_INFO *)&nlc[1])->resolution |= T30_RESOLUTION_R8_1540 |
  7652. T30_RESOLUTION_R16_1540_OR_400 | T30_RESOLUTION_300_300 |
  7653. T30_RESOLUTION_INCH_BASED | T30_RESOLUTION_METRIC_BASED;
  7654. }
  7655. ((T30_INFO *)&nlc[1])->recording_properties =
  7656. T30_RECORDING_WIDTH_ISO_A3 |
  7657. (T30_RECORDING_LENGTH_UNLIMITED << 2) |
  7658. (T30_MIN_SCANLINE_TIME_00_00_00 << 4);
  7659. }
  7660. if(plci->B3_prot == 5)
  7661. {
  7662. if (i & 0x0002) /* Accept incoming fax-polling requests */
  7663. fax_control_bits |= T30_CONTROL_BIT_ACCEPT_POLLING;
  7664. if (i & 0x2000) /* Do not use MR compression */
  7665. fax_control_bits &= ~T30_CONTROL_BIT_ENABLE_2D_CODING;
  7666. if (i & 0x4000) /* Do not use MMR compression */
  7667. fax_control_bits &= ~T30_CONTROL_BIT_ENABLE_T6_CODING;
  7668. if (i & 0x8000) /* Do not use ECM */
  7669. fax_control_bits &= ~T30_CONTROL_BIT_ENABLE_ECM;
  7670. if (plci->fax_connect_info_length != 0)
  7671. {
  7672. ((T30_INFO *)&nlc[1])->resolution = ((T30_INFO *)plci->fax_connect_info_buffer)->resolution;
  7673. ((T30_INFO *)&nlc[1])->data_format = ((T30_INFO *)plci->fax_connect_info_buffer)->data_format;
  7674. ((T30_INFO *)&nlc[1])->recording_properties = ((T30_INFO *)plci->fax_connect_info_buffer)->recording_properties;
  7675. fax_control_bits |= GET_WORD(&((T30_INFO *)plci->fax_connect_info_buffer)->control_bits_low) &
  7676. (T30_CONTROL_BIT_REQUEST_POLLING | T30_CONTROL_BIT_MORE_DOCUMENTS);
  7677. }
  7678. }
  7679. /* copy station id to NLC */
  7680. for(i=0; i<20; i++)
  7681. {
  7682. if(i<b3_config_parms[2].length)
  7683. {
  7684. ((T30_INFO *)&nlc[1])->station_id[i] = ((byte *)b3_config_parms[2].info)[1+i];
  7685. }
  7686. else
  7687. {
  7688. ((T30_INFO *)&nlc[1])->station_id[i] = ' ';
  7689. }
  7690. }
  7691. ((T30_INFO *)&nlc[1])->station_id_len = 20;
  7692. /* copy head line to NLC */
  7693. if(b3_config_parms[3].length)
  7694. {
  7695. pos = (byte)(fax_head_line_time (&(((T30_INFO *)&nlc[1])->station_id[20])));
  7696. if (pos != 0)
  7697. {
  7698. if (CAPI_MAX_DATE_TIME_LENGTH + 2 + b3_config_parms[3].length > CAPI_MAX_HEAD_LINE_SPACE)
  7699. pos = 0;
  7700. else
  7701. {
  7702. ((T30_INFO *)&nlc[1])->station_id[20 + pos++] = ' ';
  7703. ((T30_INFO *)&nlc[1])->station_id[20 + pos++] = ' ';
  7704. len = (byte)b3_config_parms[2].length;
  7705. if (len > 20)
  7706. len = 20;
  7707. if (CAPI_MAX_DATE_TIME_LENGTH + 2 + len + 2 + b3_config_parms[3].length <= CAPI_MAX_HEAD_LINE_SPACE)
  7708. {
  7709. for (i = 0; i < len; i++)
  7710. ((T30_INFO *)&nlc[1])->station_id[20 + pos++] = ((byte *)b3_config_parms[2].info)[1+i];
  7711. ((T30_INFO *)&nlc[1])->station_id[20 + pos++] = ' ';
  7712. ((T30_INFO *)&nlc[1])->station_id[20 + pos++] = ' ';
  7713. }
  7714. }
  7715. }
  7716. len = (byte)b3_config_parms[3].length;
  7717. if (len > CAPI_MAX_HEAD_LINE_SPACE - pos)
  7718. len = (byte)(CAPI_MAX_HEAD_LINE_SPACE - pos);
  7719. ((T30_INFO *)&nlc[1])->head_line_len = (byte)(pos + len);
  7720. nlc[0] += (byte)(pos + len);
  7721. for (i = 0; i < len; i++)
  7722. ((T30_INFO *)&nlc[1])->station_id[20 + pos++] = ((byte *)b3_config_parms[3].info)[1+i];
  7723. }
  7724. else
  7725. ((T30_INFO *)&nlc[1])->head_line_len = 0;
  7726. plci->nsf_control_bits = 0;
  7727. if(plci->B3_prot == 5)
  7728. {
  7729. if ((plci->adapter->man_profile.private_options & (1L << PRIVATE_FAX_SUB_SEP_PWD))
  7730. && (GET_WORD((byte *)b3_config_parms[1].info) & 0x8000)) /* Private SUB/SEP/PWD enable */
  7731. {
  7732. plci->requested_options |= 1L << PRIVATE_FAX_SUB_SEP_PWD;
  7733. }
  7734. if ((plci->adapter->man_profile.private_options & (1L << PRIVATE_FAX_NONSTANDARD))
  7735. && (GET_WORD((byte *)b3_config_parms[1].info) & 0x4000)) /* Private non-standard facilities enable */
  7736. {
  7737. plci->requested_options |= 1L << PRIVATE_FAX_NONSTANDARD;
  7738. }
  7739. if ((plci->requested_options_conn | plci->requested_options | plci->adapter->requested_options_table[plci->appl->Id-1])
  7740. & ((1L << PRIVATE_FAX_SUB_SEP_PWD) | (1L << PRIVATE_FAX_NONSTANDARD)))
  7741. {
  7742. if ((plci->requested_options_conn | plci->requested_options | plci->adapter->requested_options_table[plci->appl->Id-1])
  7743. & (1L << PRIVATE_FAX_SUB_SEP_PWD))
  7744. {
  7745. fax_control_bits |= T30_CONTROL_BIT_ACCEPT_SUBADDRESS | T30_CONTROL_BIT_ACCEPT_PASSWORD;
  7746. if (fax_control_bits & T30_CONTROL_BIT_ACCEPT_POLLING)
  7747. fax_control_bits |= T30_CONTROL_BIT_ACCEPT_SEL_POLLING;
  7748. }
  7749. len = nlc[0];
  7750. pos = ((byte)(((T30_INFO *) 0)->station_id + 20));
  7751. if (pos < plci->fax_connect_info_length)
  7752. {
  7753. for (i = 1 + plci->fax_connect_info_buffer[pos]; i != 0; i--)
  7754. nlc[++len] = plci->fax_connect_info_buffer[pos++];
  7755. }
  7756. else
  7757. nlc[++len] = 0;
  7758. if (pos < plci->fax_connect_info_length)
  7759. {
  7760. for (i = 1 + plci->fax_connect_info_buffer[pos]; i != 0; i--)
  7761. nlc[++len] = plci->fax_connect_info_buffer[pos++];
  7762. }
  7763. else
  7764. nlc[++len] = 0;
  7765. if ((plci->requested_options_conn | plci->requested_options | plci->adapter->requested_options_table[plci->appl->Id-1])
  7766. & (1L << PRIVATE_FAX_NONSTANDARD))
  7767. {
  7768. if ((pos < plci->fax_connect_info_length) && (plci->fax_connect_info_buffer[pos] != 0))
  7769. {
  7770. if ((plci->fax_connect_info_buffer[pos] >= 3) && (plci->fax_connect_info_buffer[pos+1] >= 2))
  7771. plci->nsf_control_bits = GET_WORD(&plci->fax_connect_info_buffer[pos+2]);
  7772. for (i = 1 + plci->fax_connect_info_buffer[pos]; i != 0; i--)
  7773. nlc[++len] = plci->fax_connect_info_buffer[pos++];
  7774. }
  7775. else
  7776. {
  7777. if(api_parse(&b3_config->info[1], (word)b3_config->length, "wwsss", b3_config_parms))
  7778. {
  7779. dbug(1,dprintf("non-standard facilities info missing or wrong format"));
  7780. nlc[++len] = 0;
  7781. }
  7782. else
  7783. {
  7784. if ((b3_config_parms[4].length >= 3) && (b3_config_parms[4].info[1] >= 2))
  7785. plci->nsf_control_bits = GET_WORD(&b3_config_parms[4].info[2]);
  7786. nlc[++len] = (byte)(b3_config_parms[4].length);
  7787. for (i = 0; i < b3_config_parms[4].length; i++)
  7788. nlc[++len] = b3_config_parms[4].info[1+i];
  7789. }
  7790. }
  7791. }
  7792. nlc[0] = len;
  7793. if ((plci->nsf_control_bits & T30_NSF_CONTROL_BIT_ENABLE_NSF)
  7794. && (plci->nsf_control_bits & T30_NSF_CONTROL_BIT_NEGOTIATE_RESP))
  7795. {
  7796. ((T30_INFO *)&nlc[1])->operating_mode = T30_OPERATING_MODE_CAPI_NEG;
  7797. }
  7798. }
  7799. }
  7800. PUT_WORD(&(((T30_INFO *)&nlc[1])->control_bits_low), fax_control_bits);
  7801. len = ((byte)(((T30_INFO *) 0)->station_id + 20));
  7802. for (i = 0; i < len; i++)
  7803. plci->fax_connect_info_buffer[i] = nlc[1+i];
  7804. ((T30_INFO *) plci->fax_connect_info_buffer)->head_line_len = 0;
  7805. i += ((T30_INFO *)&nlc[1])->head_line_len;
  7806. while (i < nlc[0])
  7807. plci->fax_connect_info_buffer[len++] = nlc[++i];
  7808. plci->fax_connect_info_length = len;
  7809. }
  7810. else
  7811. {
  7812. nlc[0] = 14;
  7813. if(b3_config->length!=16)
  7814. return _B3_PARM_NOT_SUPPORTED;
  7815. for(i=0; i<12; i++) nlc[1+i] = b3_config->info[1+i];
  7816. if(GET_WORD(&b3_config->info[13])!=8 && GET_WORD(&b3_config->info[13])!=128)
  7817. return _B3_PARM_NOT_SUPPORTED;
  7818. nlc[13] = b3_config->info[13];
  7819. if(GET_WORD(&b3_config->info[15])>=nlc[13])
  7820. return _B3_PARM_NOT_SUPPORTED;
  7821. nlc[14] = b3_config->info[15];
  7822. }
  7823. }
  7824. else
  7825. {
  7826. if (plci->B3_prot == 4
  7827. || plci->B3_prot == 5 /*T.30 - FAX*/ ) return _B3_PARM_NOT_SUPPORTED;
  7828. }
  7829. add_p(plci, NLC, nlc);
  7830. return 0;
  7831. }
  7832. /*----------------------------------------------------------------*/
  7833. /* make the same as add_b23, but only for the modem related */
  7834. /* L2 and L3 B-Chan protocol. */
  7835. /* */
  7836. /* Enabled L2 and L3 Configurations: */
  7837. /* If L1 == Modem all negotiation */
  7838. /* only L2 == Modem with full negotiation is allowed */
  7839. /* If L1 == Modem async or sync */
  7840. /* only L2 == Transparent is allowed */
  7841. /* L3 == Modem or L3 == Transparent are allowed */
  7842. /* B2 Configuration for modem: */
  7843. /* word : enable/disable compression, bitoptions */
  7844. /* B3 Configuration for modem: */
  7845. /* empty */
  7846. /*----------------------------------------------------------------*/
  7847. static word add_modem_b23 (PLCI * plci, API_PARSE* bp_parms)
  7848. {
  7849. static byte lli[12] = {1,1};
  7850. static byte llc[3] = {2,0,0};
  7851. static byte dlc[16] = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
  7852. API_PARSE mdm_config[2];
  7853. word i;
  7854. word b2_config = 0;
  7855. for(i=0;i<2;i++) mdm_config[i].length = 0;
  7856. for(i=0;i<sizeof(dlc);i++) dlc[i] = 0;
  7857. if (((GET_WORD(bp_parms[0].info) == B1_MODEM_ALL_NEGOTIATE)
  7858. && (GET_WORD(bp_parms[1].info) != B2_MODEM_EC_COMPRESSION))
  7859. || ((GET_WORD(bp_parms[0].info) != B1_MODEM_ALL_NEGOTIATE)
  7860. && (GET_WORD(bp_parms[1].info) != B2_TRANSPARENT)))
  7861. {
  7862. return (_B_STACK_NOT_SUPPORTED);
  7863. }
  7864. if ((GET_WORD(bp_parms[2].info) != B3_MODEM)
  7865. && (GET_WORD(bp_parms[2].info) != B3_TRANSPARENT))
  7866. {
  7867. return (_B_STACK_NOT_SUPPORTED);
  7868. }
  7869. plci->B2_prot = (byte) GET_WORD(bp_parms[1].info);
  7870. plci->B3_prot = (byte) GET_WORD(bp_parms[2].info);
  7871. if ((GET_WORD(bp_parms[1].info) == B2_MODEM_EC_COMPRESSION) && bp_parms[4].length)
  7872. {
  7873. if (api_parse (&bp_parms[4].info[1],
  7874. (word)bp_parms[4].length, "w",
  7875. mdm_config))
  7876. {
  7877. return (_WRONG_MESSAGE_FORMAT);
  7878. }
  7879. b2_config = GET_WORD(mdm_config[0].info);
  7880. }
  7881. /* OK, L2 is modem */
  7882. lli[0] = 1;
  7883. lli[1] = 1;
  7884. if (plci->adapter->manufacturer_features & MANUFACTURER_FEATURE_XONOFF_FLOW_CONTROL)
  7885. lli[1] |= 2;
  7886. if (plci->adapter->manufacturer_features & MANUFACTURER_FEATURE_OOB_CHANNEL)
  7887. lli[1] |= 4;
  7888. if ((lli[1] & 0x02) && (diva_xdi_extended_features & DIVA_CAPI_USE_CMA)) {
  7889. lli[1] |= 0x10;
  7890. if (plci->rx_dma_descriptor <= 0) {
  7891. plci->rx_dma_descriptor=diva_get_dma_descriptor(plci,&plci->rx_dma_magic);
  7892. if (plci->rx_dma_descriptor >= 0)
  7893. plci->rx_dma_descriptor++;
  7894. }
  7895. if (plci->rx_dma_descriptor > 0) {
  7896. lli[1] |= 0x40;
  7897. lli[0] = 6;
  7898. lli[2] = (byte)(plci->rx_dma_descriptor - 1);
  7899. lli[3] = (byte)plci->rx_dma_magic;
  7900. lli[4] = (byte)(plci->rx_dma_magic >> 8);
  7901. lli[5] = (byte)(plci->rx_dma_magic >> 16);
  7902. lli[6] = (byte)(plci->rx_dma_magic >> 24);
  7903. }
  7904. }
  7905. if (DIVA_CAPI_SUPPORTS_NO_CANCEL(plci->adapter)) {
  7906. lli[1] |= 0x20;
  7907. }
  7908. llc[1] = (plci->call_dir & (CALL_DIR_ORIGINATE | CALL_DIR_FORCE_OUTG_NL)) ?
  7909. /*V42*/ 10 : /*V42_IN*/ 9;
  7910. llc[2] = 4; /* pass L3 always transparent */
  7911. add_p(plci, LLI, lli);
  7912. add_p(plci, LLC, llc);
  7913. i = 1;
  7914. PUT_WORD (&dlc[i], plci->appl->MaxDataLength);
  7915. i += 2;
  7916. if (GET_WORD(bp_parms[1].info) == B2_MODEM_EC_COMPRESSION)
  7917. {
  7918. if (bp_parms[4].length)
  7919. {
  7920. dbug(1, dprintf("MDM b2_config=%02x", b2_config));
  7921. dlc[i++] = 3; /* Addr A */
  7922. dlc[i++] = 1; /* Addr B */
  7923. dlc[i++] = 7; /* modulo mode */
  7924. dlc[i++] = 7; /* window size */
  7925. dlc[i++] = 0; /* XID len Lo */
  7926. dlc[i++] = 0; /* XID len Hi */
  7927. if (b2_config & MDM_B2_DISABLE_V42bis)
  7928. {
  7929. dlc[i] |= DLC_MODEMPROT_DISABLE_V42_V42BIS;
  7930. }
  7931. if (b2_config & MDM_B2_DISABLE_MNP)
  7932. {
  7933. dlc[i] |= DLC_MODEMPROT_DISABLE_MNP_MNP5;
  7934. }
  7935. if (b2_config & MDM_B2_DISABLE_TRANS)
  7936. {
  7937. dlc[i] |= DLC_MODEMPROT_REQUIRE_PROTOCOL;
  7938. }
  7939. if (b2_config & MDM_B2_DISABLE_V42)
  7940. {
  7941. dlc[i] |= DLC_MODEMPROT_DISABLE_V42_DETECT;
  7942. }
  7943. if (b2_config & MDM_B2_DISABLE_COMP)
  7944. {
  7945. dlc[i] |= DLC_MODEMPROT_DISABLE_COMPRESSION;
  7946. }
  7947. i++;
  7948. }
  7949. }
  7950. else
  7951. {
  7952. dlc[i++] = 3; /* Addr A */
  7953. dlc[i++] = 1; /* Addr B */
  7954. dlc[i++] = 7; /* modulo mode */
  7955. dlc[i++] = 7; /* window size */
  7956. dlc[i++] = 0; /* XID len Lo */
  7957. dlc[i++] = 0; /* XID len Hi */
  7958. dlc[i++] = DLC_MODEMPROT_DISABLE_V42_V42BIS |
  7959. DLC_MODEMPROT_DISABLE_MNP_MNP5 |
  7960. DLC_MODEMPROT_DISABLE_V42_DETECT |
  7961. DLC_MODEMPROT_DISABLE_COMPRESSION;
  7962. }
  7963. dlc[0] = (byte)(i - 1);
  7964. /* HexDump ("DLC", sizeof(dlc), &dlc[0]); */
  7965. add_p(plci, DLC, dlc);
  7966. return (0);
  7967. }
  7968. /*------------------------------------------------------------------*/
  7969. /* send a request for the signaling entity */
  7970. /*------------------------------------------------------------------*/
  7971. void sig_req(PLCI * plci, byte req, byte Id)
  7972. {
  7973. if(!plci) return;
  7974. if(plci->adapter->adapter_disabled) return;
  7975. dbug(1,dprintf("sig_req(%x)",req));
  7976. if (req == REMOVE)
  7977. plci->sig_remove_id = plci->Sig.Id;
  7978. if(plci->req_in==plci->req_in_start) {
  7979. plci->req_in +=2;
  7980. plci->RBuffer[plci->req_in++] = 0;
  7981. }
  7982. PUT_WORD(&plci->RBuffer[plci->req_in_start], plci->req_in-plci->req_in_start-2);
  7983. plci->RBuffer[plci->req_in++] = Id; /* sig/nl flag */
  7984. plci->RBuffer[plci->req_in++] = req; /* request */
  7985. plci->RBuffer[plci->req_in++] = 0; /* channel */
  7986. plci->req_in_start = plci->req_in;
  7987. }
  7988. /*------------------------------------------------------------------*/
  7989. /* send a request for the network layer entity */
  7990. /*------------------------------------------------------------------*/
  7991. void nl_req_ncci(PLCI * plci, byte req, byte ncci)
  7992. {
  7993. if(!plci) return;
  7994. if(plci->adapter->adapter_disabled) return;
  7995. dbug(1,dprintf("nl_req %02x %02x %02x", plci->Id, req, ncci));
  7996. if (req == REMOVE)
  7997. {
  7998. plci->nl_remove_id = plci->NL.Id;
  7999. ncci_remove (plci, 0, (byte)(ncci != 0));
  8000. ncci = 0;
  8001. }
  8002. if(plci->req_in==plci->req_in_start) {
  8003. plci->req_in +=2;
  8004. plci->RBuffer[plci->req_in++] = 0;
  8005. }
  8006. PUT_WORD(&plci->RBuffer[plci->req_in_start], plci->req_in-plci->req_in_start-2);
  8007. plci->RBuffer[plci->req_in++] = 1; /* sig/nl flag */
  8008. plci->RBuffer[plci->req_in++] = req; /* request */
  8009. plci->RBuffer[plci->req_in++] = plci->adapter->ncci_ch[ncci]; /* channel */
  8010. plci->req_in_start = plci->req_in;
  8011. }
  8012. void send_req(PLCI * plci)
  8013. {
  8014. ENTITY * e;
  8015. word l;
  8016. /* word i; */
  8017. if(!plci) return;
  8018. if(plci->adapter->adapter_disabled) return;
  8019. channel_xmit_xon (plci);
  8020. /* if nothing to do, return */
  8021. if(plci->req_in==plci->req_out) return;
  8022. dbug(1,dprintf("send_req(in=%d,out=%d)",plci->req_in,plci->req_out));
  8023. if(plci->nl_req || plci->sig_req) return;
  8024. l = GET_WORD(&plci->RBuffer[plci->req_out]);
  8025. plci->req_out += 2;
  8026. plci->XData[0].P = &plci->RBuffer[plci->req_out];
  8027. plci->req_out += l;
  8028. if(plci->RBuffer[plci->req_out]==1)
  8029. {
  8030. e = &plci->NL;
  8031. plci->req_out++;
  8032. e->Req = plci->nl_req = plci->RBuffer[plci->req_out++];
  8033. e->ReqCh = plci->RBuffer[plci->req_out++];
  8034. if(!(e->Id & 0x1f))
  8035. {
  8036. e->Id = NL_ID;
  8037. plci->RBuffer[plci->req_out-4] = CAI;
  8038. plci->RBuffer[plci->req_out-3] = 1;
  8039. plci->RBuffer[plci->req_out-2] = (plci->Sig.Id==0xff) ? 0 : plci->Sig.Id;
  8040. plci->RBuffer[plci->req_out-1] = 0;
  8041. l+=3;
  8042. plci->nl_global_req = plci->nl_req;
  8043. }
  8044. dbug(1,dprintf("%x:NLREQ(%x:%x:%x)",plci->adapter->Id,e->Id,e->Req,e->ReqCh));
  8045. }
  8046. else
  8047. {
  8048. e = &plci->Sig;
  8049. if(plci->RBuffer[plci->req_out])
  8050. e->Id = plci->RBuffer[plci->req_out];
  8051. plci->req_out++;
  8052. e->Req = plci->sig_req = plci->RBuffer[plci->req_out++];
  8053. e->ReqCh = plci->RBuffer[plci->req_out++];
  8054. if(!(e->Id & 0x1f))
  8055. plci->sig_global_req = plci->sig_req;
  8056. dbug(1,dprintf("%x:SIGREQ(%x:%x:%x)",plci->adapter->Id,e->Id,e->Req,e->ReqCh));
  8057. }
  8058. plci->XData[0].PLength = l;
  8059. e->X = plci->XData;
  8060. plci->adapter->request(e);
  8061. dbug(1,dprintf("send_ok"));
  8062. }
  8063. void send_data(PLCI * plci)
  8064. {
  8065. DIVA_CAPI_ADAPTER * a;
  8066. DATA_B3_DESC * data;
  8067. NCCI *ncci_ptr;
  8068. word ncci;
  8069. if (!plci->nl_req && plci->ncci_ring_list)
  8070. {
  8071. a = plci->adapter;
  8072. ncci = plci->ncci_ring_list;
  8073. do
  8074. {
  8075. ncci = a->ncci_next[ncci];
  8076. ncci_ptr = &(a->ncci[ncci]);
  8077. if (!(a->ncci_ch[ncci]
  8078. && (a->ch_flow_control[a->ncci_ch[ncci]] & N_OK_FC_PENDING)))
  8079. {
  8080. if (ncci_ptr->data_pending)
  8081. {
  8082. if ((a->ncci_state[ncci] == CONNECTED)
  8083. || (a->ncci_state[ncci] == INC_ACT_PENDING)
  8084. || (plci->send_disc == ncci))
  8085. {
  8086. data = &(ncci_ptr->DBuffer[ncci_ptr->data_out]);
  8087. if ((plci->B2_prot == B2_V120_ASYNC)
  8088. || (plci->B2_prot == B2_V120_ASYNC_V42BIS)
  8089. || (plci->B2_prot == B2_V120_BIT_TRANSPARENT))
  8090. {
  8091. plci->NData[1].P = TransmitBufferGet (plci->appl, data->P);
  8092. plci->NData[1].PLength = data->Length;
  8093. if (data->Flags & 0x10)
  8094. plci->NData[0].P = v120_break_header;
  8095. else
  8096. plci->NData[0].P = v120_default_header;
  8097. plci->NData[0].PLength = 1 ;
  8098. plci->NL.XNum = 2;
  8099. plci->NL.Req = plci->nl_req = (byte)((data->Flags&0x07)<<4 |N_DATA);
  8100. }
  8101. else
  8102. {
  8103. plci->NData[0].P = TransmitBufferGet (plci->appl, data->P);
  8104. plci->NData[0].PLength = data->Length;
  8105. if (data->Flags & 0x10)
  8106. plci->NL.Req = plci->nl_req = (byte)N_UDATA;
  8107. else if ((plci->B3_prot == B3_RTP) && (data->Flags & 0x01))
  8108. plci->NL.Req = plci->nl_req = (byte)N_BDATA;
  8109. else
  8110. plci->NL.Req = plci->nl_req = (byte)((data->Flags&0x07)<<4 |N_DATA);
  8111. }
  8112. plci->NL.X = plci->NData;
  8113. plci->NL.ReqCh = a->ncci_ch[ncci];
  8114. dbug(1,dprintf("%x:DREQ(%x:%x)",a->Id,plci->NL.Id,plci->NL.Req));
  8115. plci->data_sent = TRUE;
  8116. plci->data_sent_ptr = data->P;
  8117. a->request(&plci->NL);
  8118. }
  8119. else {
  8120. cleanup_ncci_data (plci, ncci);
  8121. }
  8122. }
  8123. else if (plci->send_disc == ncci)
  8124. {
  8125. /* dprintf("N_DISC"); */
  8126. plci->NData[0].PLength = 0;
  8127. plci->NL.ReqCh = a->ncci_ch[ncci];
  8128. plci->NL.Req = plci->nl_req = N_DISC;
  8129. a->request(&plci->NL);
  8130. plci->command = _DISCONNECT_B3_R;
  8131. plci->send_disc = 0;
  8132. }
  8133. }
  8134. } while (!plci->nl_req && (ncci != plci->ncci_ring_list));
  8135. plci->ncci_ring_list = ncci;
  8136. }
  8137. }
  8138. void listen_check(DIVA_CAPI_ADAPTER * a)
  8139. {
  8140. word i,j;
  8141. PLCI * plci;
  8142. byte activnotifiedcalls = 0;
  8143. dbug(1,dprintf("listen_check(%d,%d)",a->listen_active,a->max_listen));
  8144. if (!remove_started && !a->adapter_disabled)
  8145. {
  8146. for(i=0;i<a->max_plci;i++)
  8147. {
  8148. plci = &(a->plci[i]);
  8149. if(plci->notifiedcall) activnotifiedcalls++;
  8150. }
  8151. dbug(1,dprintf("listen_check(%d)",activnotifiedcalls));
  8152. for(i=a->listen_active; i < ((word)(a->max_listen+activnotifiedcalls)); i++) {
  8153. if((j=get_plci(a))) {
  8154. a->listen_active++;
  8155. plci = &a->plci[j-1];
  8156. plci->State = LISTENING;
  8157. add_p(plci,OAD,"\x01\xfd");
  8158. add_p(plci,KEY,"\x04\x43\x41\x32\x30");
  8159. add_p(plci,CAI,"\x01\xc0");
  8160. add_p(plci,UID,"\x06\x43\x61\x70\x69\x32\x30");
  8161. add_p(plci,LLI,"\x01\xc4"); /* support Dummy CR FAC + MWI + SpoofNotify */
  8162. add_p(plci,SHIFT|6,NULL);
  8163. add_p(plci,SIN,"\x02\x00\x00");
  8164. plci->internal_command = LISTEN_SIG_ASSIGN_PEND; /* do indicate_req if OK */
  8165. sig_req(plci,ASSIGN,DSIG_ID);
  8166. send_req(plci);
  8167. }
  8168. }
  8169. }
  8170. }
  8171. /*------------------------------------------------------------------*/
  8172. /* functions for all parameters sent in INDs */
  8173. /*------------------------------------------------------------------*/
  8174. void IndParse(PLCI * plci, word * parms_id, byte ** parms, byte multiIEsize)
  8175. {
  8176. word ploc; /* points to current location within packet */
  8177. byte w;
  8178. byte wlen;
  8179. byte codeset,lock;
  8180. byte * in;
  8181. word i;
  8182. word code;
  8183. word mIEindex = 0;
  8184. ploc = 0;
  8185. codeset = 0;
  8186. lock = 0;
  8187. in = plci->Sig.RBuffer->P;
  8188. for(i=0; i<parms_id[0]; i++) /* multiIE parms_id contains just the 1st */
  8189. { /* element but parms array is larger */
  8190. parms[i] = (byte *)"";
  8191. }
  8192. for(i=0; i<multiIEsize; i++)
  8193. {
  8194. parms[i] = (byte *)"";
  8195. }
  8196. while(ploc<plci->Sig.RBuffer->length-1) {
  8197. /* read information element id and length */
  8198. w = in[ploc];
  8199. if(w & 0x80) {
  8200. /* w &=0xf0; removed, cannot detect congestion levels */
  8201. /* upper 4 bit masked with w==SHIFT now */
  8202. wlen = 0;
  8203. }
  8204. else {
  8205. wlen = (byte)(in[ploc+1]+1);
  8206. }
  8207. /* check if length valid (not exceeding end of packet) */
  8208. if((ploc+wlen) > 270) return ;
  8209. if(lock & 0x80) lock &=0x7f;
  8210. else codeset = lock;
  8211. if((w&0xf0)==SHIFT) {
  8212. codeset = in[ploc];
  8213. if(!(codeset & 0x08)) lock = (byte)(codeset & 7);
  8214. codeset &=7;
  8215. lock |=0x80;
  8216. }
  8217. else {
  8218. if(w==ESC && wlen>=3) code = in[ploc+2] |0x800;
  8219. else code = w;
  8220. code |= (codeset<<8);
  8221. for(i=1; i<parms_id[0]+1 && parms_id[i]!=code; i++);
  8222. if(i<parms_id[0]+1) {
  8223. if(!multiIEsize) { /* with multiIEs use next field index, */
  8224. mIEindex = i-1; /* with normal IEs use same index like parms_id */
  8225. }
  8226. parms[mIEindex] = &in[ploc+1];
  8227. dbug(1,dprintf("mIE[%d]=0x%x",*parms[mIEindex],in[ploc]));
  8228. if(parms_id[i]==OAD
  8229. || parms_id[i]==CONN_NR
  8230. || parms_id[i]==CAD) {
  8231. if(in[ploc+2] &0x80) {
  8232. in[ploc+0] = (byte)(in[ploc+1]+1);
  8233. in[ploc+1] = (byte)(in[ploc+2] &0x7f);
  8234. in[ploc+2] = 0x80;
  8235. parms[mIEindex] = &in[ploc];
  8236. }
  8237. }
  8238. mIEindex++; /* effects multiIEs only */
  8239. }
  8240. }
  8241. ploc +=(wlen+1);
  8242. }
  8243. return ;
  8244. }
  8245. /*------------------------------------------------------------------*/
  8246. /* try to match a cip from received BC and HLC */
  8247. /*------------------------------------------------------------------*/
  8248. byte ie_compare(byte * ie1, byte * ie2)
  8249. {
  8250. word i;
  8251. if(!ie1 || ! ie2) return FALSE;
  8252. if(!ie1[0]) return FALSE;
  8253. for(i=0;i<(word)(ie1[0]+1);i++) if(ie1[i]!=ie2[i]) return FALSE;
  8254. return TRUE;
  8255. }
  8256. word find_cip(DIVA_CAPI_ADAPTER * a, byte * bc, byte * hlc)
  8257. {
  8258. word i;
  8259. word j;
  8260. for(i=9;i && !ie_compare(bc,cip_bc[i][a->u_law]);i--);
  8261. for(j=16;j<29 &&
  8262. (!ie_compare(bc,cip_bc[j][a->u_law]) || !ie_compare(hlc,cip_hlc[j])); j++);
  8263. if(j==29) return i;
  8264. return j;
  8265. }
  8266. static byte AddInfo(byte **add_i,
  8267. byte **fty_i,
  8268. byte *esc_chi,
  8269. byte *facility)
  8270. {
  8271. byte i;
  8272. byte j;
  8273. byte k;
  8274. byte flen;
  8275. byte len=0;
  8276. /* facility is a nested structure */
  8277. /* FTY can be more than once */
  8278. if(esc_chi[0] && !(esc_chi[esc_chi[0]])&0x7f )
  8279. {
  8280. add_i[0] = (byte *)"\x02\x02\x00"; /* use neither b nor d channel */
  8281. }
  8282. else
  8283. {
  8284. add_i[0] = (byte *)"";
  8285. }
  8286. if(!fty_i[0][0])
  8287. {
  8288. add_i[3] = (byte *)"";
  8289. }
  8290. else
  8291. { /* facility array found */
  8292. for(i=0,j=1;i<MAX_MULTI_IE && fty_i[i][0];i++)
  8293. {
  8294. dbug(1,dprintf("AddIFac[%d]",fty_i[i][0]));
  8295. len += fty_i[i][0];
  8296. len += 2;
  8297. flen=fty_i[i][0];
  8298. facility[j++]=0x1c; /* copy fac IE */
  8299. for(k=0;k<=flen;k++,j++)
  8300. {
  8301. facility[j]=fty_i[i][k];
  8302. /* dbug(1,dprintf("%x ",facility[j])); */
  8303. }
  8304. }
  8305. facility[0] = len;
  8306. add_i[3] = facility;
  8307. }
  8308. /* dbug(1,dprintf("FacArrLen=%d ",len)); */
  8309. len = add_i[0][0]+add_i[1][0]+add_i[2][0]+add_i[3][0];
  8310. len += 4; /* calculate length of all */
  8311. return(len);
  8312. }
  8313. /*------------------------------------------------------------------*/
  8314. /* voice and codec features */
  8315. /*------------------------------------------------------------------*/
  8316. void SetVoiceChannel(PLCI *plci, byte *chi, DIVA_CAPI_ADAPTER * a)
  8317. {
  8318. byte voice_chi[] = "\x02\x18\x01";
  8319. byte channel;
  8320. channel = chi[chi[0]]&0x3;
  8321. dbug(1,dprintf("ExtDevON(Ch=0x%x)",channel));
  8322. voice_chi[2] = (channel) ? channel : 1;
  8323. add_p(plci,FTY,"\x02\x01\x07"); /* B On, default on 1 */
  8324. add_p(plci,ESC,voice_chi); /* Channel */
  8325. sig_req(plci,TEL_CTRL,0);
  8326. send_req(plci);
  8327. if(a->AdvSignalPLCI)
  8328. {
  8329. adv_voice_write_coefs (a->AdvSignalPLCI, ADV_VOICE_WRITE_ACTIVATION);
  8330. }
  8331. }
  8332. void VoiceChannelOff(PLCI *plci)
  8333. {
  8334. dbug(1,dprintf("ExtDevOFF"));
  8335. add_p(plci,FTY,"\x02\x01\x08"); /* B Off */
  8336. sig_req(plci,TEL_CTRL,0);
  8337. send_req(plci);
  8338. if(plci->adapter->AdvSignalPLCI)
  8339. {
  8340. adv_voice_clear_config (plci->adapter->AdvSignalPLCI);
  8341. }
  8342. }
  8343. word AdvCodecSupport(DIVA_CAPI_ADAPTER *a, PLCI *plci, APPL *appl, byte hook_listen)
  8344. {
  8345. word j;
  8346. PLCI *splci;
  8347. /* check if hardware supports handset with hook states (adv.codec) */
  8348. /* or if just a on board codec is supported */
  8349. /* the advanced codec plci is just for internal use */
  8350. /* diva Pro with on-board codec: */
  8351. if(a->profile.Global_Options & HANDSET)
  8352. {
  8353. /* new call, but hook states are already signalled */
  8354. if(a->AdvCodecFLAG)
  8355. {
  8356. if(a->AdvSignalAppl!=appl || a->AdvSignalPLCI)
  8357. {
  8358. dbug(1,dprintf("AdvSigPlci=0x%x",a->AdvSignalPLCI));
  8359. return 0x2001; /* codec in use by another application */
  8360. }
  8361. if(plci!=0)
  8362. {
  8363. a->AdvSignalPLCI = plci;
  8364. plci->tel=ADV_VOICE;
  8365. }
  8366. return 0; /* adv codec still used */
  8367. }
  8368. if((j=get_plci(a)))
  8369. {
  8370. splci = &a->plci[j-1];
  8371. splci->tel = CODEC_PERMANENT;
  8372. /* hook_listen indicates if a facility_req with handset/hook support */
  8373. /* was sent. Otherwise if just a call on an external device was made */
  8374. /* the codec will be used but the hook info will be discarded (just */
  8375. /* the external controller is in use */
  8376. if(hook_listen) splci->State = ADVANCED_VOICE_SIG;
  8377. else
  8378. {
  8379. splci->State = ADVANCED_VOICE_NOSIG;
  8380. if(plci)
  8381. {
  8382. plci->spoofed_msg = SPOOFING_REQUIRED;
  8383. }
  8384. /* indicate D-ch connect if */
  8385. } /* codec is connected OK */
  8386. if(plci!=0)
  8387. {
  8388. a->AdvSignalPLCI = plci;
  8389. plci->tel=ADV_VOICE;
  8390. }
  8391. a->AdvSignalAppl = appl;
  8392. a->AdvCodecFLAG = TRUE;
  8393. a->AdvCodecPLCI = splci;
  8394. add_p(splci,CAI,"\x01\x15");
  8395. add_p(splci,LLI,"\x01\x00");
  8396. add_p(splci,ESC,"\x02\x18\x00");
  8397. add_p(splci,UID,"\x06\x43\x61\x70\x69\x32\x30");
  8398. splci->internal_command = PERM_COD_ASSIGN;
  8399. dbug(1,dprintf("Codec Assign"));
  8400. sig_req(splci,ASSIGN,DSIG_ID);
  8401. send_req(splci);
  8402. }
  8403. else
  8404. {
  8405. return 0x2001; /* wrong state, no more plcis */
  8406. }
  8407. }
  8408. else if(a->profile.Global_Options & ON_BOARD_CODEC)
  8409. {
  8410. if(hook_listen) return 0x300B; /* Facility not supported */
  8411. /* no hook with SCOM */
  8412. if(plci!=0) plci->tel = CODEC;
  8413. dbug(1,dprintf("S/SCOM codec"));
  8414. /* first time we use the scom-s codec we must shut down the internal */
  8415. /* handset application of the card. This can be done by an assign with */
  8416. /* a cai with the 0x80 bit set. Assign return code is 'out of resource'*/
  8417. if(!a->scom_appl_disable){
  8418. if((j=get_plci(a))) {
  8419. splci = &a->plci[j-1];
  8420. add_p(splci,CAI,"\x01\x80");
  8421. add_p(splci,UID,"\x06\x43\x61\x70\x69\x32\x30");
  8422. sig_req(splci,ASSIGN,0xC0); /* 0xc0 is the TEL_ID */
  8423. send_req(splci);
  8424. a->scom_appl_disable = TRUE;
  8425. }
  8426. else{
  8427. return 0x2001; /* wrong state, no more plcis */
  8428. }
  8429. }
  8430. }
  8431. else return 0x300B; /* Facility not supported */
  8432. return 0;
  8433. }
  8434. void CodecIdCheck(DIVA_CAPI_ADAPTER *a, PLCI *plci)
  8435. {
  8436. dbug(1,dprintf("CodecIdCheck"));
  8437. if(a->AdvSignalPLCI == plci)
  8438. {
  8439. dbug(1,dprintf("PLCI owns codec"));
  8440. VoiceChannelOff(a->AdvCodecPLCI);
  8441. if(a->AdvCodecPLCI->State == ADVANCED_VOICE_NOSIG)
  8442. {
  8443. dbug(1,dprintf("remove temp codec PLCI"));
  8444. plci_remove(a->AdvCodecPLCI);
  8445. a->AdvCodecFLAG = 0;
  8446. a->AdvCodecPLCI = NULL;
  8447. a->AdvSignalAppl = NULL;
  8448. }
  8449. a->AdvSignalPLCI = NULL;
  8450. }
  8451. }
  8452. /* -------------------------------------------------------------------
  8453. Ask for physical address of card on PCI bus
  8454. ------------------------------------------------------------------- */
  8455. static void diva_ask_for_xdi_sdram_bar (DIVA_CAPI_ADAPTER * a,
  8456. IDI_SYNC_REQ * preq) {
  8457. a->sdram_bar = 0;
  8458. if (diva_xdi_extended_features & DIVA_CAPI_XDI_PROVIDES_SDRAM_BAR) {
  8459. ENTITY * e = (ENTITY *)preq;
  8460. e->user[0] = a->Id - 1;
  8461. preq->xdi_sdram_bar.info.bar = 0;
  8462. preq->xdi_sdram_bar.Req = 0;
  8463. preq->xdi_sdram_bar.Rc = IDI_SYNC_REQ_XDI_GET_ADAPTER_SDRAM_BAR;
  8464. (*(a->request))(e);
  8465. a->sdram_bar = preq->xdi_sdram_bar.info.bar;
  8466. dbug(3,dprintf("A(%d) SDRAM BAR = %08x", a->Id, a->sdram_bar));
  8467. }
  8468. }
  8469. /* -------------------------------------------------------------------
  8470. Ask XDI about extended features
  8471. ------------------------------------------------------------------- */
  8472. static void diva_get_extended_adapter_features (DIVA_CAPI_ADAPTER * a) {
  8473. IDI_SYNC_REQ * preq;
  8474. char buffer[ ((sizeof(preq->xdi_extended_features)+4) > sizeof(ENTITY)) ? (sizeof(preq->xdi_extended_features)+4) : sizeof(ENTITY)];
  8475. char features[4];
  8476. preq = (IDI_SYNC_REQ *)&buffer[0];
  8477. if (!diva_xdi_extended_features) {
  8478. ENTITY * e = (ENTITY *)preq;
  8479. diva_xdi_extended_features |= 0x80000000;
  8480. e->user[0] = a->Id - 1;
  8481. preq->xdi_extended_features.Req = 0;
  8482. preq->xdi_extended_features.Rc = IDI_SYNC_REQ_XDI_GET_EXTENDED_FEATURES;
  8483. preq->xdi_extended_features.info.buffer_length_in_bytes = sizeof(features);
  8484. preq->xdi_extended_features.info.features = &features[0];
  8485. (*(a->request))(e);
  8486. if (features[0] & DIVA_XDI_EXTENDED_FEATURES_VALID) {
  8487. /*
  8488. Check features located in the byte '0'
  8489. */
  8490. if (features[0] & DIVA_XDI_EXTENDED_FEATURE_CMA) {
  8491. diva_xdi_extended_features |= DIVA_CAPI_USE_CMA;
  8492. }
  8493. if (features[0] & DIVA_XDI_EXTENDED_FEATURE_RX_DMA) {
  8494. diva_xdi_extended_features |= DIVA_CAPI_XDI_PROVIDES_RX_DMA;
  8495. dbug(1,dprintf("XDI provides RxDMA"));
  8496. }
  8497. if (features[0] & DIVA_XDI_EXTENDED_FEATURE_SDRAM_BAR) {
  8498. diva_xdi_extended_features |= DIVA_CAPI_XDI_PROVIDES_SDRAM_BAR;
  8499. }
  8500. if (features[0] & DIVA_XDI_EXTENDED_FEATURE_NO_CANCEL_RC) {
  8501. diva_xdi_extended_features |= DIVA_CAPI_XDI_PROVIDES_NO_CANCEL;
  8502. dbug(3,dprintf("XDI provides NO_CANCEL_RC feature"));
  8503. }
  8504. }
  8505. }
  8506. diva_ask_for_xdi_sdram_bar (a, preq);
  8507. }
  8508. /*------------------------------------------------------------------*/
  8509. /* automatic law */
  8510. /*------------------------------------------------------------------*/
  8511. /* called from OS specific part after init time to get the Law */
  8512. /* a-law (Euro) and u-law (us,japan) use different BCs in the Setup message */
  8513. void AutomaticLaw(DIVA_CAPI_ADAPTER *a)
  8514. {
  8515. word j;
  8516. PLCI *splci;
  8517. if(a->automatic_law) {
  8518. return;
  8519. }
  8520. if((j=get_plci(a))) {
  8521. diva_get_extended_adapter_features (a);
  8522. splci = &a->plci[j-1];
  8523. a->automatic_lawPLCI = splci;
  8524. a->automatic_law = 1;
  8525. add_p(splci,CAI,"\x01\x80");
  8526. add_p(splci,UID,"\x06\x43\x61\x70\x69\x32\x30");
  8527. splci->internal_command = USELAW_REQ;
  8528. splci->command = 0;
  8529. splci->number = 0;
  8530. sig_req(splci,ASSIGN,DSIG_ID);
  8531. send_req(splci);
  8532. }
  8533. }
  8534. /* called from OS specific part if an application sends an Capi20Release */
  8535. word CapiRelease(word Id)
  8536. {
  8537. word i, j, appls_found;
  8538. PLCI *plci;
  8539. APPL *this;
  8540. DIVA_CAPI_ADAPTER *a;
  8541. if (!Id)
  8542. {
  8543. dbug(0,dprintf("A: CapiRelease(Id==0)"));
  8544. return (_WRONG_APPL_ID);
  8545. }
  8546. this = &application[Id-1]; /* get application pointer */
  8547. for(i=0,appls_found=0; i<max_appl; i++)
  8548. {
  8549. if(application[i].Id) /* an application has been found */
  8550. {
  8551. appls_found++;
  8552. }
  8553. }
  8554. for(i=0; i<max_adapter; i++) /* scan all adapters... */
  8555. {
  8556. a = &adapter[i];
  8557. if (a->request)
  8558. {
  8559. a->Info_Mask[Id-1] = 0;
  8560. a->CIP_Mask[Id-1] = 0;
  8561. a->Notification_Mask[Id-1] = 0;
  8562. a->codec_listen[Id-1] = NULL;
  8563. a->requested_options_table[Id-1] = 0;
  8564. for(j=0; j<a->max_plci; j++) /* and all PLCIs connected */
  8565. { /* with this application */
  8566. plci = &a->plci[j];
  8567. if(plci->Id) /* if plci owns no application */
  8568. { /* it may be not jet connected */
  8569. if(plci->State==INC_CON_PENDING
  8570. || plci->State==INC_CON_ALERT)
  8571. {
  8572. if(test_c_ind_mask_bit (plci, (word)(Id-1)))
  8573. {
  8574. clear_c_ind_mask_bit (plci, (word)(Id-1));
  8575. if(c_ind_mask_empty (plci))
  8576. {
  8577. sig_req(plci,HANGUP,0);
  8578. send_req(plci);
  8579. plci->State = OUTG_DIS_PENDING;
  8580. }
  8581. }
  8582. }
  8583. if(test_c_ind_mask_bit (plci, (word)(Id-1)))
  8584. {
  8585. clear_c_ind_mask_bit (plci, (word)(Id-1));
  8586. if(c_ind_mask_empty (plci))
  8587. {
  8588. if(!plci->appl)
  8589. {
  8590. plci_remove(plci);
  8591. plci->State = IDLE;
  8592. }
  8593. }
  8594. }
  8595. if(plci->appl==this)
  8596. {
  8597. plci->appl = NULL;
  8598. plci_remove(plci);
  8599. plci->State = IDLE;
  8600. }
  8601. }
  8602. }
  8603. listen_check(a);
  8604. if(a->flag_dynamic_l1_down)
  8605. {
  8606. if(appls_found==1) /* last application does a capi release */
  8607. {
  8608. if((j=get_plci(a)))
  8609. {
  8610. plci = &a->plci[j-1];
  8611. plci->command = 0;
  8612. add_p(plci,OAD,"\x01\xfd");
  8613. add_p(plci,CAI,"\x01\x80");
  8614. add_p(plci,UID,"\x06\x43\x61\x70\x69\x32\x30");
  8615. add_p(plci,SHIFT|6,NULL);
  8616. add_p(plci,SIN,"\x02\x00\x00");
  8617. plci->internal_command = REM_L1_SIG_ASSIGN_PEND;
  8618. sig_req(plci,ASSIGN,DSIG_ID);
  8619. add_p(plci,FTY,"\x02\xff\x06"); /* l1 down */
  8620. sig_req(plci,SIG_CTRL,0);
  8621. send_req(plci);
  8622. }
  8623. }
  8624. }
  8625. if(a->AdvSignalAppl==this)
  8626. {
  8627. this->NullCREnable = FALSE;
  8628. if (a->AdvCodecPLCI)
  8629. {
  8630. plci_remove(a->AdvCodecPLCI);
  8631. a->AdvCodecPLCI->tel = 0;
  8632. a->AdvCodecPLCI->adv_nl = 0;
  8633. }
  8634. a->AdvSignalAppl = NULL;
  8635. a->AdvSignalPLCI = NULL;
  8636. a->AdvCodecFLAG = 0;
  8637. a->AdvCodecPLCI = NULL;
  8638. }
  8639. }
  8640. }
  8641. this->Id = 0;
  8642. return GOOD;
  8643. }
  8644. static word plci_remove_check(PLCI *plci)
  8645. {
  8646. if(!plci) return TRUE;
  8647. if(!plci->NL.Id && c_ind_mask_empty (plci))
  8648. {
  8649. if(plci->Sig.Id == 0xff)
  8650. plci->Sig.Id = 0;
  8651. if(!plci->Sig.Id)
  8652. {
  8653. dbug(1,dprintf("plci_remove_complete(%x)",plci->Id));
  8654. dbug(1,dprintf("tel=0x%x,Sig=0x%x",plci->tel,plci->Sig.Id));
  8655. if (plci->Id)
  8656. {
  8657. CodecIdCheck(plci->adapter, plci);
  8658. clear_b1_config (plci);
  8659. ncci_remove (plci, 0, FALSE);
  8660. plci_free_msg_in_queue (plci);
  8661. channel_flow_control_remove (plci);
  8662. plci->Id = 0;
  8663. plci->State = IDLE;
  8664. plci->channels = 0;
  8665. plci->appl = NULL;
  8666. plci->notifiedcall = 0;
  8667. }
  8668. listen_check(plci->adapter);
  8669. return TRUE;
  8670. }
  8671. }
  8672. return FALSE;
  8673. }
  8674. /*------------------------------------------------------------------*/
  8675. static byte plci_nl_busy (PLCI *plci)
  8676. {
  8677. /* only applicable for non-multiplexed protocols */
  8678. return (plci->nl_req
  8679. || (plci->ncci_ring_list
  8680. && plci->adapter->ncci_ch[plci->ncci_ring_list]
  8681. && (plci->adapter->ch_flow_control[plci->adapter->ncci_ch[plci->ncci_ring_list]] & N_OK_FC_PENDING)));
  8682. }
  8683. /*------------------------------------------------------------------*/
  8684. /* DTMF facilities */
  8685. /*------------------------------------------------------------------*/
  8686. static struct
  8687. {
  8688. byte send_mask;
  8689. byte listen_mask;
  8690. byte character;
  8691. byte code;
  8692. } dtmf_digit_map[] =
  8693. {
  8694. { 0x01, 0x01, 0x23, DTMF_DIGIT_TONE_CODE_HASHMARK },
  8695. { 0x01, 0x01, 0x2a, DTMF_DIGIT_TONE_CODE_STAR },
  8696. { 0x01, 0x01, 0x30, DTMF_DIGIT_TONE_CODE_0 },
  8697. { 0x01, 0x01, 0x31, DTMF_DIGIT_TONE_CODE_1 },
  8698. { 0x01, 0x01, 0x32, DTMF_DIGIT_TONE_CODE_2 },
  8699. { 0x01, 0x01, 0x33, DTMF_DIGIT_TONE_CODE_3 },
  8700. { 0x01, 0x01, 0x34, DTMF_DIGIT_TONE_CODE_4 },
  8701. { 0x01, 0x01, 0x35, DTMF_DIGIT_TONE_CODE_5 },
  8702. { 0x01, 0x01, 0x36, DTMF_DIGIT_TONE_CODE_6 },
  8703. { 0x01, 0x01, 0x37, DTMF_DIGIT_TONE_CODE_7 },
  8704. { 0x01, 0x01, 0x38, DTMF_DIGIT_TONE_CODE_8 },
  8705. { 0x01, 0x01, 0x39, DTMF_DIGIT_TONE_CODE_9 },
  8706. { 0x01, 0x01, 0x41, DTMF_DIGIT_TONE_CODE_A },
  8707. { 0x01, 0x01, 0x42, DTMF_DIGIT_TONE_CODE_B },
  8708. { 0x01, 0x01, 0x43, DTMF_DIGIT_TONE_CODE_C },
  8709. { 0x01, 0x01, 0x44, DTMF_DIGIT_TONE_CODE_D },
  8710. { 0x01, 0x00, 0x61, DTMF_DIGIT_TONE_CODE_A },
  8711. { 0x01, 0x00, 0x62, DTMF_DIGIT_TONE_CODE_B },
  8712. { 0x01, 0x00, 0x63, DTMF_DIGIT_TONE_CODE_C },
  8713. { 0x01, 0x00, 0x64, DTMF_DIGIT_TONE_CODE_D },
  8714. { 0x04, 0x04, 0x80, DTMF_SIGNAL_NO_TONE },
  8715. { 0x00, 0x04, 0x81, DTMF_SIGNAL_UNIDENTIFIED_TONE },
  8716. { 0x04, 0x04, 0x82, DTMF_SIGNAL_DIAL_TONE },
  8717. { 0x04, 0x04, 0x83, DTMF_SIGNAL_PABX_INTERNAL_DIAL_TONE },
  8718. { 0x04, 0x04, 0x84, DTMF_SIGNAL_SPECIAL_DIAL_TONE },
  8719. { 0x04, 0x04, 0x85, DTMF_SIGNAL_SECOND_DIAL_TONE },
  8720. { 0x04, 0x04, 0x86, DTMF_SIGNAL_RINGING_TONE },
  8721. { 0x04, 0x04, 0x87, DTMF_SIGNAL_SPECIAL_RINGING_TONE },
  8722. { 0x04, 0x04, 0x88, DTMF_SIGNAL_BUSY_TONE },
  8723. { 0x04, 0x04, 0x89, DTMF_SIGNAL_CONGESTION_TONE },
  8724. { 0x04, 0x04, 0x8a, DTMF_SIGNAL_SPECIAL_INFORMATION_TONE },
  8725. { 0x04, 0x04, 0x8b, DTMF_SIGNAL_COMFORT_TONE },
  8726. { 0x04, 0x04, 0x8c, DTMF_SIGNAL_HOLD_TONE },
  8727. { 0x04, 0x04, 0x8d, DTMF_SIGNAL_RECORD_TONE },
  8728. { 0x04, 0x04, 0x8e, DTMF_SIGNAL_CALLER_WAITING_TONE },
  8729. { 0x04, 0x04, 0x8f, DTMF_SIGNAL_CALL_WAITING_TONE },
  8730. { 0x04, 0x04, 0x90, DTMF_SIGNAL_PAY_TONE },
  8731. { 0x04, 0x04, 0x91, DTMF_SIGNAL_POSITIVE_INDICATION_TONE },
  8732. { 0x04, 0x04, 0x92, DTMF_SIGNAL_NEGATIVE_INDICATION_TONE },
  8733. { 0x04, 0x04, 0x93, DTMF_SIGNAL_WARNING_TONE },
  8734. { 0x04, 0x04, 0x94, DTMF_SIGNAL_INTRUSION_TONE },
  8735. { 0x04, 0x04, 0x95, DTMF_SIGNAL_CALLING_CARD_SERVICE_TONE },
  8736. { 0x04, 0x04, 0x96, DTMF_SIGNAL_PAYPHONE_RECOGNITION_TONE },
  8737. { 0x04, 0x04, 0x97, DTMF_SIGNAL_CPE_ALERTING_SIGNAL },
  8738. { 0x04, 0x04, 0x98, DTMF_SIGNAL_OFF_HOOK_WARNING_TONE },
  8739. { 0x04, 0x04, 0xbf, DTMF_SIGNAL_INTERCEPT_TONE },
  8740. { 0x04, 0x04, 0xc0, DTMF_SIGNAL_MODEM_CALLING_TONE },
  8741. { 0x04, 0x04, 0xc1, DTMF_SIGNAL_FAX_CALLING_TONE },
  8742. { 0x04, 0x04, 0xc2, DTMF_SIGNAL_ANSWER_TONE },
  8743. { 0x04, 0x04, 0xc3, DTMF_SIGNAL_REVERSED_ANSWER_TONE },
  8744. { 0x04, 0x04, 0xc4, DTMF_SIGNAL_ANSAM_TONE },
  8745. { 0x04, 0x04, 0xc5, DTMF_SIGNAL_REVERSED_ANSAM_TONE },
  8746. { 0x04, 0x04, 0xc6, DTMF_SIGNAL_BELL103_ANSWER_TONE },
  8747. { 0x04, 0x04, 0xc7, DTMF_SIGNAL_FAX_FLAGS },
  8748. { 0x04, 0x04, 0xc8, DTMF_SIGNAL_G2_FAX_GROUP_ID },
  8749. { 0x00, 0x04, 0xc9, DTMF_SIGNAL_HUMAN_SPEECH },
  8750. { 0x04, 0x04, 0xca, DTMF_SIGNAL_ANSWERING_MACHINE_390 },
  8751. { 0x02, 0x02, 0xf1, DTMF_MF_DIGIT_TONE_CODE_1 },
  8752. { 0x02, 0x02, 0xf2, DTMF_MF_DIGIT_TONE_CODE_2 },
  8753. { 0x02, 0x02, 0xf3, DTMF_MF_DIGIT_TONE_CODE_3 },
  8754. { 0x02, 0x02, 0xf4, DTMF_MF_DIGIT_TONE_CODE_4 },
  8755. { 0x02, 0x02, 0xf5, DTMF_MF_DIGIT_TONE_CODE_5 },
  8756. { 0x02, 0x02, 0xf6, DTMF_MF_DIGIT_TONE_CODE_6 },
  8757. { 0x02, 0x02, 0xf7, DTMF_MF_DIGIT_TONE_CODE_7 },
  8758. { 0x02, 0x02, 0xf8, DTMF_MF_DIGIT_TONE_CODE_8 },
  8759. { 0x02, 0x02, 0xf9, DTMF_MF_DIGIT_TONE_CODE_9 },
  8760. { 0x02, 0x02, 0xfa, DTMF_MF_DIGIT_TONE_CODE_0 },
  8761. { 0x02, 0x02, 0xfb, DTMF_MF_DIGIT_TONE_CODE_K1 },
  8762. { 0x02, 0x02, 0xfc, DTMF_MF_DIGIT_TONE_CODE_K2 },
  8763. { 0x02, 0x02, 0xfd, DTMF_MF_DIGIT_TONE_CODE_KP },
  8764. { 0x02, 0x02, 0xfe, DTMF_MF_DIGIT_TONE_CODE_S1 },
  8765. { 0x02, 0x02, 0xff, DTMF_MF_DIGIT_TONE_CODE_ST },
  8766. };
  8767. #define DTMF_DIGIT_MAP_ENTRIES (sizeof(dtmf_digit_map) / sizeof(dtmf_digit_map[0]))
  8768. static void dtmf_enable_receiver (PLCI *plci, byte enable_mask)
  8769. {
  8770. word min_digit_duration, min_gap_duration;
  8771. dbug (1, dprintf ("[%06lx] %s,%d: dtmf_enable_receiver %02x",
  8772. (dword)((plci->Id << 8) | UnMapController (plci->adapter->Id)),
  8773. (char *)(FILE_), __LINE__, enable_mask));
  8774. if (enable_mask != 0)
  8775. {
  8776. min_digit_duration = (plci->dtmf_rec_pulse_ms == 0) ? 40 : plci->dtmf_rec_pulse_ms;
  8777. min_gap_duration = (plci->dtmf_rec_pause_ms == 0) ? 40 : plci->dtmf_rec_pause_ms;
  8778. plci->internal_req_buffer[0] = DTMF_UDATA_REQUEST_ENABLE_RECEIVER;
  8779. PUT_WORD (&plci->internal_req_buffer[1], min_digit_duration);
  8780. PUT_WORD (&plci->internal_req_buffer[3], min_gap_duration);
  8781. plci->NData[0].PLength = 5;
  8782. PUT_WORD (&plci->internal_req_buffer[5], INTERNAL_IND_BUFFER_SIZE);
  8783. plci->NData[0].PLength += 2;
  8784. capidtmf_recv_enable (&(plci->capidtmf_state), min_digit_duration, min_gap_duration);
  8785. }
  8786. else
  8787. {
  8788. plci->internal_req_buffer[0] = DTMF_UDATA_REQUEST_DISABLE_RECEIVER;
  8789. plci->NData[0].PLength = 1;
  8790. capidtmf_recv_disable (&(plci->capidtmf_state));
  8791. }
  8792. plci->NData[0].P = plci->internal_req_buffer;
  8793. plci->NL.X = plci->NData;
  8794. plci->NL.ReqCh = 0;
  8795. plci->NL.Req = plci->nl_req = (byte) N_UDATA;
  8796. plci->adapter->request (&plci->NL);
  8797. }
  8798. static void dtmf_send_digits (PLCI *plci, byte *digit_buffer, word digit_count)
  8799. {
  8800. word w, i;
  8801. dbug (1, dprintf ("[%06lx] %s,%d: dtmf_send_digits %d",
  8802. (dword)((plci->Id << 8) | UnMapController (plci->adapter->Id)),
  8803. (char *)(FILE_), __LINE__, digit_count));
  8804. plci->internal_req_buffer[0] = DTMF_UDATA_REQUEST_SEND_DIGITS;
  8805. w = (plci->dtmf_send_pulse_ms == 0) ? 40 : plci->dtmf_send_pulse_ms;
  8806. PUT_WORD (&plci->internal_req_buffer[1], w);
  8807. w = (plci->dtmf_send_pause_ms == 0) ? 40 : plci->dtmf_send_pause_ms;
  8808. PUT_WORD (&plci->internal_req_buffer[3], w);
  8809. for (i = 0; i < digit_count; i++)
  8810. {
  8811. w = 0;
  8812. while ((w < DTMF_DIGIT_MAP_ENTRIES)
  8813. && (digit_buffer[i] != dtmf_digit_map[w].character))
  8814. {
  8815. w++;
  8816. }
  8817. plci->internal_req_buffer[5+i] = (w < DTMF_DIGIT_MAP_ENTRIES) ?
  8818. dtmf_digit_map[w].code : DTMF_DIGIT_TONE_CODE_STAR;
  8819. }
  8820. plci->NData[0].PLength = 5 + digit_count;
  8821. plci->NData[0].P = plci->internal_req_buffer;
  8822. plci->NL.X = plci->NData;
  8823. plci->NL.ReqCh = 0;
  8824. plci->NL.Req = plci->nl_req = (byte) N_UDATA;
  8825. plci->adapter->request (&plci->NL);
  8826. }
  8827. static void dtmf_rec_clear_config (PLCI *plci)
  8828. {
  8829. dbug (1, dprintf ("[%06lx] %s,%d: dtmf_rec_clear_config",
  8830. (dword)((plci->Id << 8) | UnMapController (plci->adapter->Id)),
  8831. (char *)(FILE_), __LINE__));
  8832. plci->dtmf_rec_active = 0;
  8833. plci->dtmf_rec_pulse_ms = 0;
  8834. plci->dtmf_rec_pause_ms = 0;
  8835. capidtmf_init (&(plci->capidtmf_state), plci->adapter->u_law);
  8836. }
  8837. static void dtmf_send_clear_config (PLCI *plci)
  8838. {
  8839. dbug (1, dprintf ("[%06lx] %s,%d: dtmf_send_clear_config",
  8840. (dword)((plci->Id << 8) | UnMapController (plci->adapter->Id)),
  8841. (char *)(FILE_), __LINE__));
  8842. plci->dtmf_send_requests = 0;
  8843. plci->dtmf_send_pulse_ms = 0;
  8844. plci->dtmf_send_pause_ms = 0;
  8845. }
  8846. static void dtmf_prepare_switch (dword Id, PLCI *plci)
  8847. {
  8848. dbug (1, dprintf ("[%06lx] %s,%d: dtmf_prepare_switch",
  8849. UnMapId (Id), (char *)(FILE_), __LINE__));
  8850. while (plci->dtmf_send_requests != 0)
  8851. dtmf_confirmation (Id, plci);
  8852. }
  8853. static word dtmf_save_config (dword Id, PLCI *plci, byte Rc)
  8854. {
  8855. dbug (1, dprintf ("[%06lx] %s,%d: dtmf_save_config %02x %d",
  8856. UnMapId (Id), (char *)(FILE_), __LINE__, Rc, plci->adjust_b_state));
  8857. return (GOOD);
  8858. }
  8859. static word dtmf_restore_config (dword Id, PLCI *plci, byte Rc)
  8860. {
  8861. word Info;
  8862. dbug (1, dprintf ("[%06lx] %s,%d: dtmf_restore_config %02x %d",
  8863. UnMapId (Id), (char *)(FILE_), __LINE__, Rc, plci->adjust_b_state));
  8864. Info = GOOD;
  8865. if (plci->B1_facilities & B1_FACILITY_DTMFR)
  8866. {
  8867. switch (plci->adjust_b_state)
  8868. {
  8869. case ADJUST_B_RESTORE_DTMF_1:
  8870. plci->internal_command = plci->adjust_b_command;
  8871. if (plci_nl_busy (plci))
  8872. {
  8873. plci->adjust_b_state = ADJUST_B_RESTORE_DTMF_1;
  8874. break;
  8875. }
  8876. dtmf_enable_receiver (plci, plci->dtmf_rec_active);
  8877. plci->adjust_b_state = ADJUST_B_RESTORE_DTMF_2;
  8878. break;
  8879. case ADJUST_B_RESTORE_DTMF_2:
  8880. if ((Rc != OK) && (Rc != OK_FC))
  8881. {
  8882. dbug (1, dprintf ("[%06lx] %s,%d: Reenable DTMF receiver failed %02x",
  8883. UnMapId (Id), (char *)(FILE_), __LINE__, Rc));
  8884. Info = _WRONG_STATE;
  8885. break;
  8886. }
  8887. break;
  8888. }
  8889. }
  8890. return (Info);
  8891. }
  8892. static void dtmf_command (dword Id, PLCI *plci, byte Rc)
  8893. {
  8894. word internal_command, Info;
  8895. byte mask;
  8896. byte result[4];
  8897. dbug (1, dprintf ("[%06lx] %s,%d: dtmf_command %02x %04x %04x %d %d %d %d",
  8898. UnMapId (Id), (char *)(FILE_), __LINE__, Rc, plci->internal_command,
  8899. plci->dtmf_cmd, plci->dtmf_rec_pulse_ms, plci->dtmf_rec_pause_ms,
  8900. plci->dtmf_send_pulse_ms, plci->dtmf_send_pause_ms));
  8901. Info = GOOD;
  8902. result[0] = 2;
  8903. PUT_WORD (&result[1], DTMF_SUCCESS);
  8904. internal_command = plci->internal_command;
  8905. plci->internal_command = 0;
  8906. mask = 0x01;
  8907. switch (plci->dtmf_cmd)
  8908. {
  8909. case DTMF_LISTEN_TONE_START:
  8910. mask <<= 1;
  8911. case DTMF_LISTEN_MF_START:
  8912. mask <<= 1;
  8913. case DTMF_LISTEN_START:
  8914. switch (internal_command)
  8915. {
  8916. default:
  8917. adjust_b1_resource (Id, plci, NULL, (word)(plci->B1_facilities |
  8918. B1_FACILITY_DTMFR), DTMF_COMMAND_1);
  8919. case DTMF_COMMAND_1:
  8920. if (adjust_b_process (Id, plci, Rc) != GOOD)
  8921. {
  8922. dbug (1, dprintf ("[%06lx] %s,%d: Load DTMF failed",
  8923. UnMapId (Id), (char *)(FILE_), __LINE__));
  8924. Info = _FACILITY_NOT_SUPPORTED;
  8925. break;
  8926. }
  8927. if (plci->internal_command)
  8928. return;
  8929. case DTMF_COMMAND_2:
  8930. if (plci_nl_busy (plci))
  8931. {
  8932. plci->internal_command = DTMF_COMMAND_2;
  8933. return;
  8934. }
  8935. plci->internal_command = DTMF_COMMAND_3;
  8936. dtmf_enable_receiver (plci, (byte)(plci->dtmf_rec_active | mask));
  8937. return;
  8938. case DTMF_COMMAND_3:
  8939. if ((Rc != OK) && (Rc != OK_FC))
  8940. {
  8941. dbug (1, dprintf ("[%06lx] %s,%d: Enable DTMF receiver failed %02x",
  8942. UnMapId (Id), (char *)(FILE_), __LINE__, Rc));
  8943. Info = _FACILITY_NOT_SUPPORTED;
  8944. break;
  8945. }
  8946. plci->tone_last_indication_code = DTMF_SIGNAL_NO_TONE;
  8947. plci->dtmf_rec_active |= mask;
  8948. break;
  8949. }
  8950. break;
  8951. case DTMF_LISTEN_TONE_STOP:
  8952. mask <<= 1;
  8953. case DTMF_LISTEN_MF_STOP:
  8954. mask <<= 1;
  8955. case DTMF_LISTEN_STOP:
  8956. switch (internal_command)
  8957. {
  8958. default:
  8959. plci->dtmf_rec_active &= ~mask;
  8960. if (plci->dtmf_rec_active)
  8961. break;
  8962. /*
  8963. case DTMF_COMMAND_1:
  8964. if (plci->dtmf_rec_active)
  8965. {
  8966. if (plci_nl_busy (plci))
  8967. {
  8968. plci->internal_command = DTMF_COMMAND_1;
  8969. return;
  8970. }
  8971. plci->dtmf_rec_active &= ~mask;
  8972. plci->internal_command = DTMF_COMMAND_2;
  8973. dtmf_enable_receiver (plci, FALSE);
  8974. return;
  8975. }
  8976. Rc = OK;
  8977. case DTMF_COMMAND_2:
  8978. if ((Rc != OK) && (Rc != OK_FC))
  8979. {
  8980. dbug (1, dprintf ("[%06lx] %s,%d: Disable DTMF receiver failed %02x",
  8981. UnMapId (Id), (char far *)(FILE_), __LINE__, Rc));
  8982. Info = _FACILITY_NOT_SUPPORTED;
  8983. break;
  8984. }
  8985. */
  8986. adjust_b1_resource (Id, plci, NULL, (word)(plci->B1_facilities &
  8987. ~(B1_FACILITY_DTMFX | B1_FACILITY_DTMFR)), DTMF_COMMAND_3);
  8988. case DTMF_COMMAND_3:
  8989. if (adjust_b_process (Id, plci, Rc) != GOOD)
  8990. {
  8991. dbug (1, dprintf ("[%06lx] %s,%d: Unload DTMF failed",
  8992. UnMapId (Id), (char *)(FILE_), __LINE__));
  8993. Info = _FACILITY_NOT_SUPPORTED;
  8994. break;
  8995. }
  8996. if (plci->internal_command)
  8997. return;
  8998. break;
  8999. }
  9000. break;
  9001. case DTMF_SEND_TONE:
  9002. mask <<= 1;
  9003. case DTMF_SEND_MF:
  9004. mask <<= 1;
  9005. case DTMF_DIGITS_SEND:
  9006. switch (internal_command)
  9007. {
  9008. default:
  9009. adjust_b1_resource (Id, plci, NULL, (word)(plci->B1_facilities |
  9010. ((plci->dtmf_parameter_length != 0) ? B1_FACILITY_DTMFX | B1_FACILITY_DTMFR : B1_FACILITY_DTMFX)),
  9011. DTMF_COMMAND_1);
  9012. case DTMF_COMMAND_1:
  9013. if (adjust_b_process (Id, plci, Rc) != GOOD)
  9014. {
  9015. dbug (1, dprintf ("[%06lx] %s,%d: Load DTMF failed",
  9016. UnMapId (Id), (char *)(FILE_), __LINE__));
  9017. Info = _FACILITY_NOT_SUPPORTED;
  9018. break;
  9019. }
  9020. if (plci->internal_command)
  9021. return;
  9022. case DTMF_COMMAND_2:
  9023. if (plci_nl_busy (plci))
  9024. {
  9025. plci->internal_command = DTMF_COMMAND_2;
  9026. return;
  9027. }
  9028. plci->dtmf_msg_number_queue[(plci->dtmf_send_requests)++] = plci->number;
  9029. plci->internal_command = DTMF_COMMAND_3;
  9030. dtmf_send_digits (plci, &plci->saved_msg.parms[3].info[1], plci->saved_msg.parms[3].length);
  9031. return;
  9032. case DTMF_COMMAND_3:
  9033. if ((Rc != OK) && (Rc != OK_FC))
  9034. {
  9035. dbug (1, dprintf ("[%06lx] %s,%d: Send DTMF digits failed %02x",
  9036. UnMapId (Id), (char *)(FILE_), __LINE__, Rc));
  9037. if (plci->dtmf_send_requests != 0)
  9038. (plci->dtmf_send_requests)--;
  9039. Info = _FACILITY_NOT_SUPPORTED;
  9040. break;
  9041. }
  9042. return;
  9043. }
  9044. break;
  9045. }
  9046. sendf (plci->appl, _FACILITY_R | CONFIRM, Id & 0xffffL, plci->number,
  9047. "wws", Info, SELECTOR_DTMF, result);
  9048. }
  9049. static byte dtmf_request (dword Id, word Number, DIVA_CAPI_ADAPTER *a, PLCI *plci, APPL *appl, API_PARSE *msg)
  9050. {
  9051. word Info;
  9052. word i, j;
  9053. byte mask;
  9054. API_PARSE dtmf_parms[5];
  9055. byte result[40];
  9056. dbug (1, dprintf ("[%06lx] %s,%d: dtmf_request",
  9057. UnMapId (Id), (char *)(FILE_), __LINE__));
  9058. Info = GOOD;
  9059. result[0] = 2;
  9060. PUT_WORD (&result[1], DTMF_SUCCESS);
  9061. if (!(a->profile.Global_Options & GL_DTMF_SUPPORTED))
  9062. {
  9063. dbug (1, dprintf ("[%06lx] %s,%d: Facility not supported",
  9064. UnMapId (Id), (char *)(FILE_), __LINE__));
  9065. Info = _FACILITY_NOT_SUPPORTED;
  9066. }
  9067. else if (api_parse (&msg[1].info[1], msg[1].length, "w", dtmf_parms))
  9068. {
  9069. dbug (1, dprintf ("[%06lx] %s,%d: Wrong message format",
  9070. UnMapId (Id), (char *)(FILE_), __LINE__));
  9071. Info = _WRONG_MESSAGE_FORMAT;
  9072. }
  9073. else if ((GET_WORD (dtmf_parms[0].info) == DTMF_GET_SUPPORTED_DETECT_CODES)
  9074. || (GET_WORD (dtmf_parms[0].info) == DTMF_GET_SUPPORTED_SEND_CODES))
  9075. {
  9076. if (!((a->requested_options_table[appl->Id-1])
  9077. & (1L << PRIVATE_DTMF_TONE)))
  9078. {
  9079. dbug (1, dprintf ("[%06lx] %s,%d: DTMF unknown request %04x",
  9080. UnMapId (Id), (char *)(FILE_), __LINE__, GET_WORD (dtmf_parms[0].info)));
  9081. PUT_WORD (&result[1], DTMF_UNKNOWN_REQUEST);
  9082. }
  9083. else
  9084. {
  9085. for (i = 0; i < 32; i++)
  9086. result[4 + i] = 0;
  9087. if (GET_WORD (dtmf_parms[0].info) == DTMF_GET_SUPPORTED_DETECT_CODES)
  9088. {
  9089. for (i = 0; i < DTMF_DIGIT_MAP_ENTRIES; i++)
  9090. {
  9091. if (dtmf_digit_map[i].listen_mask != 0)
  9092. result[4 + (dtmf_digit_map[i].character >> 3)] |= (1 << (dtmf_digit_map[i].character & 0x7));
  9093. }
  9094. }
  9095. else
  9096. {
  9097. for (i = 0; i < DTMF_DIGIT_MAP_ENTRIES; i++)
  9098. {
  9099. if (dtmf_digit_map[i].send_mask != 0)
  9100. result[4 + (dtmf_digit_map[i].character >> 3)] |= (1 << (dtmf_digit_map[i].character & 0x7));
  9101. }
  9102. }
  9103. result[0] = 3 + 32;
  9104. result[3] = 32;
  9105. }
  9106. }
  9107. else if (plci == NULL)
  9108. {
  9109. dbug (1, dprintf ("[%06lx] %s,%d: Wrong PLCI",
  9110. UnMapId (Id), (char *)(FILE_), __LINE__));
  9111. Info = _WRONG_IDENTIFIER;
  9112. }
  9113. else
  9114. {
  9115. if (!plci->State
  9116. || !plci->NL.Id || plci->nl_remove_id)
  9117. {
  9118. dbug (1, dprintf ("[%06lx] %s,%d: Wrong state",
  9119. UnMapId (Id), (char *)(FILE_), __LINE__));
  9120. Info = _WRONG_STATE;
  9121. }
  9122. else
  9123. {
  9124. plci->command = 0;
  9125. plci->dtmf_cmd = GET_WORD (dtmf_parms[0].info);
  9126. mask = 0x01;
  9127. switch (plci->dtmf_cmd)
  9128. {
  9129. case DTMF_LISTEN_TONE_START:
  9130. case DTMF_LISTEN_TONE_STOP:
  9131. mask <<= 1;
  9132. case DTMF_LISTEN_MF_START:
  9133. case DTMF_LISTEN_MF_STOP:
  9134. mask <<= 1;
  9135. if (!((plci->requested_options_conn | plci->requested_options | plci->adapter->requested_options_table[appl->Id-1])
  9136. & (1L << PRIVATE_DTMF_TONE)))
  9137. {
  9138. dbug (1, dprintf ("[%06lx] %s,%d: DTMF unknown request %04x",
  9139. UnMapId (Id), (char *)(FILE_), __LINE__, GET_WORD (dtmf_parms[0].info)));
  9140. PUT_WORD (&result[1], DTMF_UNKNOWN_REQUEST);
  9141. break;
  9142. }
  9143. case DTMF_LISTEN_START:
  9144. case DTMF_LISTEN_STOP:
  9145. if (!(a->manufacturer_features & MANUFACTURER_FEATURE_HARDDTMF)
  9146. && !(a->manufacturer_features & MANUFACTURER_FEATURE_SOFTDTMF_RECEIVE))
  9147. {
  9148. dbug (1, dprintf ("[%06lx] %s,%d: Facility not supported",
  9149. UnMapId (Id), (char *)(FILE_), __LINE__));
  9150. Info = _FACILITY_NOT_SUPPORTED;
  9151. break;
  9152. }
  9153. if (mask & DTMF_LISTEN_ACTIVE_FLAG)
  9154. {
  9155. if (api_parse (&msg[1].info[1], msg[1].length, "wwws", dtmf_parms))
  9156. {
  9157. plci->dtmf_rec_pulse_ms = 0;
  9158. plci->dtmf_rec_pause_ms = 0;
  9159. }
  9160. else
  9161. {
  9162. plci->dtmf_rec_pulse_ms = GET_WORD (dtmf_parms[1].info);
  9163. plci->dtmf_rec_pause_ms = GET_WORD (dtmf_parms[2].info);
  9164. }
  9165. }
  9166. start_internal_command (Id, plci, dtmf_command);
  9167. return (FALSE);
  9168. case DTMF_SEND_TONE:
  9169. mask <<= 1;
  9170. case DTMF_SEND_MF:
  9171. mask <<= 1;
  9172. if (!((plci->requested_options_conn | plci->requested_options | plci->adapter->requested_options_table[appl->Id-1])
  9173. & (1L << PRIVATE_DTMF_TONE)))
  9174. {
  9175. dbug (1, dprintf ("[%06lx] %s,%d: DTMF unknown request %04x",
  9176. UnMapId (Id), (char *)(FILE_), __LINE__, GET_WORD (dtmf_parms[0].info)));
  9177. PUT_WORD (&result[1], DTMF_UNKNOWN_REQUEST);
  9178. break;
  9179. }
  9180. case DTMF_DIGITS_SEND:
  9181. if (api_parse (&msg[1].info[1], msg[1].length, "wwws", dtmf_parms))
  9182. {
  9183. dbug (1, dprintf ("[%06lx] %s,%d: Wrong message format",
  9184. UnMapId (Id), (char *)(FILE_), __LINE__));
  9185. Info = _WRONG_MESSAGE_FORMAT;
  9186. break;
  9187. }
  9188. if (mask & DTMF_LISTEN_ACTIVE_FLAG)
  9189. {
  9190. plci->dtmf_send_pulse_ms = GET_WORD (dtmf_parms[1].info);
  9191. plci->dtmf_send_pause_ms = GET_WORD (dtmf_parms[2].info);
  9192. }
  9193. i = 0;
  9194. j = 0;
  9195. while ((i < dtmf_parms[3].length) && (j < DTMF_DIGIT_MAP_ENTRIES))
  9196. {
  9197. j = 0;
  9198. while ((j < DTMF_DIGIT_MAP_ENTRIES)
  9199. && ((dtmf_parms[3].info[i+1] != dtmf_digit_map[j].character)
  9200. || ((dtmf_digit_map[j].send_mask & mask) == 0)))
  9201. {
  9202. j++;
  9203. }
  9204. i++;
  9205. }
  9206. if (j == DTMF_DIGIT_MAP_ENTRIES)
  9207. {
  9208. dbug (1, dprintf ("[%06lx] %s,%d: Incorrect DTMF digit %02x",
  9209. UnMapId (Id), (char *)(FILE_), __LINE__, dtmf_parms[3].info[i]));
  9210. PUT_WORD (&result[1], DTMF_INCORRECT_DIGIT);
  9211. break;
  9212. }
  9213. if (plci->dtmf_send_requests >=
  9214. sizeof(plci->dtmf_msg_number_queue) / sizeof(plci->dtmf_msg_number_queue[0]))
  9215. {
  9216. dbug (1, dprintf ("[%06lx] %s,%d: DTMF request overrun",
  9217. UnMapId (Id), (char *)(FILE_), __LINE__));
  9218. Info = _WRONG_STATE;
  9219. break;
  9220. }
  9221. api_save_msg (dtmf_parms, "wwws", &plci->saved_msg);
  9222. start_internal_command (Id, plci, dtmf_command);
  9223. return (FALSE);
  9224. default:
  9225. dbug (1, dprintf ("[%06lx] %s,%d: DTMF unknown request %04x",
  9226. UnMapId (Id), (char *)(FILE_), __LINE__, plci->dtmf_cmd));
  9227. PUT_WORD (&result[1], DTMF_UNKNOWN_REQUEST);
  9228. }
  9229. }
  9230. }
  9231. sendf (appl, _FACILITY_R | CONFIRM, Id & 0xffffL, Number,
  9232. "wws", Info, SELECTOR_DTMF, result);
  9233. return (FALSE);
  9234. }
  9235. static void dtmf_confirmation (dword Id, PLCI *plci)
  9236. {
  9237. word Info;
  9238. word i;
  9239. byte result[4];
  9240. dbug (1, dprintf ("[%06lx] %s,%d: dtmf_confirmation",
  9241. UnMapId (Id), (char *)(FILE_), __LINE__));
  9242. Info = GOOD;
  9243. result[0] = 2;
  9244. PUT_WORD (&result[1], DTMF_SUCCESS);
  9245. if (plci->dtmf_send_requests != 0)
  9246. {
  9247. sendf (plci->appl, _FACILITY_R | CONFIRM, Id & 0xffffL, plci->dtmf_msg_number_queue[0],
  9248. "wws", GOOD, SELECTOR_DTMF, result);
  9249. (plci->dtmf_send_requests)--;
  9250. for (i = 0; i < plci->dtmf_send_requests; i++)
  9251. plci->dtmf_msg_number_queue[i] = plci->dtmf_msg_number_queue[i+1];
  9252. }
  9253. }
  9254. static void dtmf_indication (dword Id, PLCI *plci, byte *msg, word length)
  9255. {
  9256. word i, j, n;
  9257. dbug (1, dprintf ("[%06lx] %s,%d: dtmf_indication",
  9258. UnMapId (Id), (char *)(FILE_), __LINE__));
  9259. n = 0;
  9260. for (i = 1; i < length; i++)
  9261. {
  9262. j = 0;
  9263. while ((j < DTMF_DIGIT_MAP_ENTRIES)
  9264. && ((msg[i] != dtmf_digit_map[j].code)
  9265. || ((dtmf_digit_map[j].listen_mask & plci->dtmf_rec_active) == 0)))
  9266. {
  9267. j++;
  9268. }
  9269. if (j < DTMF_DIGIT_MAP_ENTRIES)
  9270. {
  9271. if ((dtmf_digit_map[j].listen_mask & DTMF_TONE_LISTEN_ACTIVE_FLAG)
  9272. && (plci->tone_last_indication_code == DTMF_SIGNAL_NO_TONE)
  9273. && (dtmf_digit_map[j].character != DTMF_SIGNAL_UNIDENTIFIED_TONE))
  9274. {
  9275. if (n + 1 == i)
  9276. {
  9277. for (i = length; i > n + 1; i--)
  9278. msg[i] = msg[i - 1];
  9279. length++;
  9280. i++;
  9281. }
  9282. msg[++n] = DTMF_SIGNAL_UNIDENTIFIED_TONE;
  9283. }
  9284. plci->tone_last_indication_code = dtmf_digit_map[j].character;
  9285. msg[++n] = dtmf_digit_map[j].character;
  9286. }
  9287. }
  9288. if (n != 0)
  9289. {
  9290. msg[0] = (byte) n;
  9291. sendf (plci->appl, _FACILITY_I, Id & 0xffffL, 0, "wS", SELECTOR_DTMF, msg);
  9292. }
  9293. }
  9294. /*------------------------------------------------------------------*/
  9295. /* DTMF parameters */
  9296. /*------------------------------------------------------------------*/
  9297. static void dtmf_parameter_write (PLCI *plci)
  9298. {
  9299. word i;
  9300. byte parameter_buffer[DTMF_PARAMETER_BUFFER_SIZE + 2];
  9301. dbug (1, dprintf ("[%06lx] %s,%d: dtmf_parameter_write",
  9302. (dword)((plci->Id << 8) | UnMapController (plci->adapter->Id)),
  9303. (char *)(FILE_), __LINE__));
  9304. parameter_buffer[0] = plci->dtmf_parameter_length + 1;
  9305. parameter_buffer[1] = DSP_CTRL_SET_DTMF_PARAMETERS;
  9306. for (i = 0; i < plci->dtmf_parameter_length; i++)
  9307. parameter_buffer[2+i] = plci->dtmf_parameter_buffer[i];
  9308. add_p (plci, FTY, parameter_buffer);
  9309. sig_req (plci, TEL_CTRL, 0);
  9310. send_req (plci);
  9311. }
  9312. static void dtmf_parameter_clear_config (PLCI *plci)
  9313. {
  9314. dbug (1, dprintf ("[%06lx] %s,%d: dtmf_parameter_clear_config",
  9315. (dword)((plci->Id << 8) | UnMapController (plci->adapter->Id)),
  9316. (char *)(FILE_), __LINE__));
  9317. plci->dtmf_parameter_length = 0;
  9318. }
  9319. static void dtmf_parameter_prepare_switch (dword Id, PLCI *plci)
  9320. {
  9321. dbug (1, dprintf ("[%06lx] %s,%d: dtmf_parameter_prepare_switch",
  9322. UnMapId (Id), (char *)(FILE_), __LINE__));
  9323. }
  9324. static word dtmf_parameter_save_config (dword Id, PLCI *plci, byte Rc)
  9325. {
  9326. dbug (1, dprintf ("[%06lx] %s,%d: dtmf_parameter_save_config %02x %d",
  9327. UnMapId (Id), (char *)(FILE_), __LINE__, Rc, plci->adjust_b_state));
  9328. return (GOOD);
  9329. }
  9330. static word dtmf_parameter_restore_config (dword Id, PLCI *plci, byte Rc)
  9331. {
  9332. word Info;
  9333. dbug (1, dprintf ("[%06lx] %s,%d: dtmf_parameter_restore_config %02x %d",
  9334. UnMapId (Id), (char *)(FILE_), __LINE__, Rc, plci->adjust_b_state));
  9335. Info = GOOD;
  9336. if ((plci->B1_facilities & B1_FACILITY_DTMFR)
  9337. && (plci->dtmf_parameter_length != 0))
  9338. {
  9339. switch (plci->adjust_b_state)
  9340. {
  9341. case ADJUST_B_RESTORE_DTMF_PARAMETER_1:
  9342. plci->internal_command = plci->adjust_b_command;
  9343. if (plci->sig_req)
  9344. {
  9345. plci->adjust_b_state = ADJUST_B_RESTORE_DTMF_PARAMETER_1;
  9346. break;
  9347. }
  9348. dtmf_parameter_write (plci);
  9349. plci->adjust_b_state = ADJUST_B_RESTORE_DTMF_PARAMETER_2;
  9350. break;
  9351. case ADJUST_B_RESTORE_DTMF_PARAMETER_2:
  9352. if ((Rc != OK) && (Rc != OK_FC))
  9353. {
  9354. dbug (1, dprintf ("[%06lx] %s,%d: Restore DTMF parameters failed %02x",
  9355. UnMapId (Id), (char *)(FILE_), __LINE__, Rc));
  9356. Info = _WRONG_STATE;
  9357. break;
  9358. }
  9359. break;
  9360. }
  9361. }
  9362. return (Info);
  9363. }
  9364. /*------------------------------------------------------------------*/
  9365. /* Line interconnect facilities */
  9366. /*------------------------------------------------------------------*/
  9367. LI_CONFIG *li_config_table;
  9368. word li_total_channels;
  9369. /*------------------------------------------------------------------*/
  9370. /* translate a CHI information element to a channel number */
  9371. /* returns 0xff - any channel */
  9372. /* 0xfe - chi wrong coding */
  9373. /* 0xfd - D-channel */
  9374. /* 0x00 - no channel */
  9375. /* else channel number / PRI: timeslot */
  9376. /* if channels is provided we accept more than one channel. */
  9377. /*------------------------------------------------------------------*/
  9378. static byte chi_to_channel (byte *chi, dword *pchannelmap)
  9379. {
  9380. int p;
  9381. int i;
  9382. dword map;
  9383. byte excl;
  9384. byte ofs;
  9385. byte ch;
  9386. if (pchannelmap) *pchannelmap = 0;
  9387. if(!chi[0]) return 0xff;
  9388. excl = 0;
  9389. if(chi[1] & 0x20) {
  9390. if(chi[0]==1 && chi[1]==0xac) return 0xfd; /* exclusive d-channel */
  9391. for(i=1; i<chi[0] && !(chi[i] &0x80); i++);
  9392. if(i==chi[0] || !(chi[i] &0x80)) return 0xfe;
  9393. if((chi[1] |0xc8)!=0xe9) return 0xfe;
  9394. if(chi[1] &0x08) excl = 0x40;
  9395. /* int. id present */
  9396. if(chi[1] &0x40) {
  9397. p=i+1;
  9398. for(i=p; i<chi[0] && !(chi[i] &0x80); i++);
  9399. if(i==chi[0] || !(chi[i] &0x80)) return 0xfe;
  9400. }
  9401. /* coding standard, Number/Map, Channel Type */
  9402. p=i+1;
  9403. for(i=p; i<chi[0] && !(chi[i] &0x80); i++);
  9404. if(i==chi[0] || !(chi[i] &0x80)) return 0xfe;
  9405. if((chi[p]|0xd0)!=0xd3) return 0xfe;
  9406. /* Number/Map */
  9407. if(chi[p] &0x10) {
  9408. /* map */
  9409. if((chi[0]-p)==4) ofs = 0;
  9410. else if((chi[0]-p)==3) ofs = 1;
  9411. else return 0xfe;
  9412. ch = 0;
  9413. map = 0;
  9414. for(i=0; i<4 && p<chi[0]; i++) {
  9415. p++;
  9416. ch += 8;
  9417. map <<= 8;
  9418. if(chi[p]) {
  9419. for (ch=0; !(chi[p] & (1 << ch)); ch++);
  9420. map |= chi[p];
  9421. }
  9422. }
  9423. ch += ofs;
  9424. map <<= ofs;
  9425. }
  9426. else {
  9427. /* number */
  9428. p=i+1;
  9429. ch = chi[p] &0x3f;
  9430. if(pchannelmap) {
  9431. if((byte)(chi[0]-p)>30) return 0xfe;
  9432. map = 0;
  9433. for(i=p; i<=chi[0]; i++) {
  9434. if ((chi[i] &0x7f) > 31) return 0xfe;
  9435. map |= (1L << (chi[i] &0x7f));
  9436. }
  9437. }
  9438. else {
  9439. if(p!=chi[0]) return 0xfe;
  9440. if (ch > 31) return 0xfe;
  9441. map = (1L << ch);
  9442. }
  9443. if(chi[p] &0x40) return 0xfe;
  9444. }
  9445. if (pchannelmap) *pchannelmap = map;
  9446. else if (map != ((dword)(1L << ch))) return 0xfe;
  9447. return (byte)(excl | ch);
  9448. }
  9449. else { /* not PRI */
  9450. for(i=1; i<chi[0] && !(chi[i] &0x80); i++);
  9451. if(i!=chi[0] || !(chi[i] &0x80)) return 0xfe;
  9452. if(chi[1] &0x08) excl = 0x40;
  9453. switch(chi[1] |0x98) {
  9454. case 0x98: return 0;
  9455. case 0x99:
  9456. if (pchannelmap) *pchannelmap = 2;
  9457. return excl |1;
  9458. case 0x9a:
  9459. if (pchannelmap) *pchannelmap = 4;
  9460. return excl |2;
  9461. case 0x9b: return 0xff;
  9462. case 0x9c: return 0xfd; /* d-ch */
  9463. default: return 0xfe;
  9464. }
  9465. }
  9466. }
  9467. static void mixer_set_bchannel_id_esc (PLCI *plci, byte bchannel_id)
  9468. {
  9469. DIVA_CAPI_ADAPTER *a;
  9470. PLCI *splci;
  9471. byte old_id;
  9472. a = plci->adapter;
  9473. old_id = plci->li_bchannel_id;
  9474. if (a->li_pri)
  9475. {
  9476. if ((old_id != 0) && (li_config_table[a->li_base + (old_id - 1)].plci == plci))
  9477. li_config_table[a->li_base + (old_id - 1)].plci = NULL;
  9478. plci->li_bchannel_id = (bchannel_id & 0x1f) + 1;
  9479. if (li_config_table[a->li_base + (plci->li_bchannel_id - 1)].plci == NULL)
  9480. li_config_table[a->li_base + (plci->li_bchannel_id - 1)].plci = plci;
  9481. }
  9482. else
  9483. {
  9484. if (((bchannel_id & 0x03) == 1) || ((bchannel_id & 0x03) == 2))
  9485. {
  9486. if ((old_id != 0) && (li_config_table[a->li_base + (old_id - 1)].plci == plci))
  9487. li_config_table[a->li_base + (old_id - 1)].plci = NULL;
  9488. plci->li_bchannel_id = bchannel_id & 0x03;
  9489. if ((a->AdvSignalPLCI != NULL) && (a->AdvSignalPLCI != plci) && (a->AdvSignalPLCI->tel == ADV_VOICE))
  9490. {
  9491. splci = a->AdvSignalPLCI;
  9492. if (li_config_table[a->li_base + (2 - plci->li_bchannel_id)].plci == NULL)
  9493. {
  9494. if ((splci->li_bchannel_id != 0)
  9495. && (li_config_table[a->li_base + (splci->li_bchannel_id - 1)].plci == splci))
  9496. {
  9497. li_config_table[a->li_base + (splci->li_bchannel_id - 1)].plci = NULL;
  9498. }
  9499. splci->li_bchannel_id = 3 - plci->li_bchannel_id;
  9500. li_config_table[a->li_base + (2 - plci->li_bchannel_id)].plci = splci;
  9501. dbug (1, dprintf ("[%06lx] %s,%d: adv_voice_set_bchannel_id_esc %d",
  9502. (dword)((splci->Id << 8) | UnMapController (splci->adapter->Id)),
  9503. (char *)(FILE_), __LINE__, splci->li_bchannel_id));
  9504. }
  9505. }
  9506. if (li_config_table[a->li_base + (plci->li_bchannel_id - 1)].plci == NULL)
  9507. li_config_table[a->li_base + (plci->li_bchannel_id - 1)].plci = plci;
  9508. }
  9509. }
  9510. if ((old_id == 0) && (plci->li_bchannel_id != 0)
  9511. && (li_config_table[a->li_base + (plci->li_bchannel_id - 1)].plci == plci))
  9512. {
  9513. mixer_clear_config (plci);
  9514. }
  9515. dbug (1, dprintf ("[%06lx] %s,%d: mixer_set_bchannel_id_esc %d %d",
  9516. (dword)((plci->Id << 8) | UnMapController (plci->adapter->Id)),
  9517. (char *)(FILE_), __LINE__, bchannel_id, plci->li_bchannel_id));
  9518. }
  9519. static void mixer_set_bchannel_id (PLCI *plci, byte *chi)
  9520. {
  9521. DIVA_CAPI_ADAPTER *a;
  9522. PLCI *splci;
  9523. byte ch, old_id;
  9524. a = plci->adapter;
  9525. old_id = plci->li_bchannel_id;
  9526. ch = chi_to_channel (chi, NULL);
  9527. if (!(ch & 0x80))
  9528. {
  9529. if (a->li_pri)
  9530. {
  9531. if ((old_id != 0) && (li_config_table[a->li_base + (old_id - 1)].plci == plci))
  9532. li_config_table[a->li_base + (old_id - 1)].plci = NULL;
  9533. plci->li_bchannel_id = (ch & 0x1f) + 1;
  9534. if (li_config_table[a->li_base + (plci->li_bchannel_id - 1)].plci == NULL)
  9535. li_config_table[a->li_base + (plci->li_bchannel_id - 1)].plci = plci;
  9536. }
  9537. else
  9538. {
  9539. if (((ch & 0x1f) == 1) || ((ch & 0x1f) == 2))
  9540. {
  9541. if ((old_id != 0) && (li_config_table[a->li_base + (old_id - 1)].plci == plci))
  9542. li_config_table[a->li_base + (old_id - 1)].plci = NULL;
  9543. plci->li_bchannel_id = ch & 0x1f;
  9544. if ((a->AdvSignalPLCI != NULL) && (a->AdvSignalPLCI != plci) && (a->AdvSignalPLCI->tel == ADV_VOICE))
  9545. {
  9546. splci = a->AdvSignalPLCI;
  9547. if (li_config_table[a->li_base + (2 - plci->li_bchannel_id)].plci == NULL)
  9548. {
  9549. if ((splci->li_bchannel_id != 0)
  9550. && (li_config_table[a->li_base + (splci->li_bchannel_id - 1)].plci == splci))
  9551. {
  9552. li_config_table[a->li_base + (splci->li_bchannel_id - 1)].plci = NULL;
  9553. }
  9554. splci->li_bchannel_id = 3 - plci->li_bchannel_id;
  9555. li_config_table[a->li_base + (2 - plci->li_bchannel_id)].plci = splci;
  9556. dbug (1, dprintf ("[%06lx] %s,%d: adv_voice_set_bchannel_id %d",
  9557. (dword)((splci->Id << 8) | UnMapController (splci->adapter->Id)),
  9558. (char *)(FILE_), __LINE__, splci->li_bchannel_id));
  9559. }
  9560. }
  9561. if (li_config_table[a->li_base + (plci->li_bchannel_id - 1)].plci == NULL)
  9562. li_config_table[a->li_base + (plci->li_bchannel_id - 1)].plci = plci;
  9563. }
  9564. }
  9565. }
  9566. if ((old_id == 0) && (plci->li_bchannel_id != 0)
  9567. && (li_config_table[a->li_base + (plci->li_bchannel_id - 1)].plci == plci))
  9568. {
  9569. mixer_clear_config (plci);
  9570. }
  9571. dbug (1, dprintf ("[%06lx] %s,%d: mixer_set_bchannel_id %02x %d",
  9572. (dword)((plci->Id << 8) | UnMapController (plci->adapter->Id)),
  9573. (char *)(FILE_), __LINE__, ch, plci->li_bchannel_id));
  9574. }
  9575. #define MIXER_MAX_DUMP_CHANNELS 34
  9576. static void mixer_calculate_coefs (DIVA_CAPI_ADAPTER *a)
  9577. {
  9578. static char hex_digit_table[0x10] = {'0','1','2','3','4','5','6','7','8','9','a','b','c','d','e','f'};
  9579. word n, i, j;
  9580. char *p;
  9581. char hex_line[2 * MIXER_MAX_DUMP_CHANNELS + MIXER_MAX_DUMP_CHANNELS / 8 + 4];
  9582. dbug (1, dprintf ("[%06lx] %s,%d: mixer_calculate_coefs",
  9583. (dword)(UnMapController (a->Id)), (char *)(FILE_), __LINE__));
  9584. for (i = 0; i < li_total_channels; i++)
  9585. {
  9586. li_config_table[i].channel &= LI_CHANNEL_ADDRESSES_SET;
  9587. if (li_config_table[i].chflags != 0)
  9588. li_config_table[i].channel |= LI_CHANNEL_INVOLVED;
  9589. else
  9590. {
  9591. for (j = 0; j < li_total_channels; j++)
  9592. {
  9593. if (((li_config_table[i].flag_table[j]) != 0)
  9594. || ((li_config_table[j].flag_table[i]) != 0))
  9595. {
  9596. li_config_table[i].channel |= LI_CHANNEL_INVOLVED;
  9597. }
  9598. if (((li_config_table[i].flag_table[j] & LI_FLAG_CONFERENCE) != 0)
  9599. || ((li_config_table[j].flag_table[i] & LI_FLAG_CONFERENCE) != 0))
  9600. {
  9601. li_config_table[i].channel |= LI_CHANNEL_CONFERENCE;
  9602. }
  9603. }
  9604. }
  9605. }
  9606. for (i = 0; i < li_total_channels; i++)
  9607. {
  9608. for (j = 0; j < li_total_channels; j++)
  9609. {
  9610. li_config_table[i].coef_table[j] &= ~(LI_COEF_CH_CH | LI_COEF_CH_PC | LI_COEF_PC_CH | LI_COEF_PC_PC);
  9611. if (li_config_table[i].flag_table[j] & LI_FLAG_CONFERENCE)
  9612. li_config_table[i].coef_table[j] |= LI_COEF_CH_CH;
  9613. }
  9614. }
  9615. for (n = 0; n < li_total_channels; n++)
  9616. {
  9617. if (li_config_table[n].channel & LI_CHANNEL_CONFERENCE)
  9618. {
  9619. for (i = 0; i < li_total_channels; i++)
  9620. {
  9621. if (li_config_table[i].channel & LI_CHANNEL_CONFERENCE)
  9622. {
  9623. for (j = 0; j < li_total_channels; j++)
  9624. {
  9625. li_config_table[i].coef_table[j] |=
  9626. li_config_table[i].coef_table[n] & li_config_table[n].coef_table[j];
  9627. }
  9628. }
  9629. }
  9630. }
  9631. }
  9632. for (i = 0; i < li_total_channels; i++)
  9633. {
  9634. if (li_config_table[i].channel & LI_CHANNEL_INVOLVED)
  9635. {
  9636. li_config_table[i].coef_table[i] &= ~LI_COEF_CH_CH;
  9637. for (j = 0; j < li_total_channels; j++)
  9638. {
  9639. if (li_config_table[i].coef_table[j] & LI_COEF_CH_CH)
  9640. li_config_table[i].flag_table[j] |= LI_FLAG_CONFERENCE;
  9641. }
  9642. if (li_config_table[i].flag_table[i] & LI_FLAG_CONFERENCE)
  9643. li_config_table[i].coef_table[i] |= LI_COEF_CH_CH;
  9644. }
  9645. }
  9646. for (i = 0; i < li_total_channels; i++)
  9647. {
  9648. if (li_config_table[i].channel & LI_CHANNEL_INVOLVED)
  9649. {
  9650. for (j = 0; j < li_total_channels; j++)
  9651. {
  9652. if (li_config_table[i].flag_table[j] & LI_FLAG_INTERCONNECT)
  9653. li_config_table[i].coef_table[j] |= LI_COEF_CH_CH;
  9654. if (li_config_table[i].flag_table[j] & LI_FLAG_MONITOR)
  9655. li_config_table[i].coef_table[j] |= LI_COEF_CH_PC;
  9656. if (li_config_table[i].flag_table[j] & LI_FLAG_MIX)
  9657. li_config_table[i].coef_table[j] |= LI_COEF_PC_CH;
  9658. if (li_config_table[i].flag_table[j] & LI_FLAG_PCCONNECT)
  9659. li_config_table[i].coef_table[j] |= LI_COEF_PC_PC;
  9660. }
  9661. if (li_config_table[i].chflags & LI_CHFLAG_MONITOR)
  9662. {
  9663. for (j = 0; j < li_total_channels; j++)
  9664. {
  9665. if (li_config_table[i].flag_table[j] & LI_FLAG_INTERCONNECT)
  9666. {
  9667. li_config_table[i].coef_table[j] |= LI_COEF_CH_PC;
  9668. if (li_config_table[j].chflags & LI_CHFLAG_MIX)
  9669. li_config_table[i].coef_table[j] |= LI_COEF_PC_CH | LI_COEF_PC_PC;
  9670. }
  9671. }
  9672. }
  9673. if (li_config_table[i].chflags & LI_CHFLAG_MIX)
  9674. {
  9675. for (j = 0; j < li_total_channels; j++)
  9676. {
  9677. if (li_config_table[j].flag_table[i] & LI_FLAG_INTERCONNECT)
  9678. li_config_table[j].coef_table[i] |= LI_COEF_PC_CH;
  9679. }
  9680. }
  9681. if (li_config_table[i].chflags & LI_CHFLAG_LOOP)
  9682. {
  9683. for (j = 0; j < li_total_channels; j++)
  9684. {
  9685. if (li_config_table[i].flag_table[j] & LI_FLAG_INTERCONNECT)
  9686. {
  9687. for (n = 0; n < li_total_channels; n++)
  9688. {
  9689. if (li_config_table[n].flag_table[i] & LI_FLAG_INTERCONNECT)
  9690. {
  9691. li_config_table[n].coef_table[j] |= LI_COEF_CH_CH;
  9692. if (li_config_table[j].chflags & LI_CHFLAG_MIX)
  9693. {
  9694. li_config_table[n].coef_table[j] |= LI_COEF_PC_CH;
  9695. if (li_config_table[n].chflags & LI_CHFLAG_MONITOR)
  9696. li_config_table[n].coef_table[j] |= LI_COEF_CH_PC | LI_COEF_PC_PC;
  9697. }
  9698. else if (li_config_table[n].chflags & LI_CHFLAG_MONITOR)
  9699. li_config_table[n].coef_table[j] |= LI_COEF_CH_PC;
  9700. }
  9701. }
  9702. }
  9703. }
  9704. }
  9705. }
  9706. }
  9707. for (i = 0; i < li_total_channels; i++)
  9708. {
  9709. if (li_config_table[i].channel & LI_CHANNEL_INVOLVED)
  9710. {
  9711. if (li_config_table[i].chflags & (LI_CHFLAG_MONITOR | LI_CHFLAG_MIX | LI_CHFLAG_LOOP))
  9712. li_config_table[i].channel |= LI_CHANNEL_ACTIVE;
  9713. if (li_config_table[i].chflags & LI_CHFLAG_MONITOR)
  9714. li_config_table[i].channel |= LI_CHANNEL_RX_DATA;
  9715. if (li_config_table[i].chflags & LI_CHFLAG_MIX)
  9716. li_config_table[i].channel |= LI_CHANNEL_TX_DATA;
  9717. for (j = 0; j < li_total_channels; j++)
  9718. {
  9719. if ((li_config_table[i].flag_table[j] &
  9720. (LI_FLAG_INTERCONNECT | LI_FLAG_PCCONNECT | LI_FLAG_CONFERENCE | LI_FLAG_MONITOR))
  9721. || (li_config_table[j].flag_table[i] &
  9722. (LI_FLAG_INTERCONNECT | LI_FLAG_PCCONNECT | LI_FLAG_CONFERENCE | LI_FLAG_ANNOUNCEMENT | LI_FLAG_MIX)))
  9723. {
  9724. li_config_table[i].channel |= LI_CHANNEL_ACTIVE;
  9725. }
  9726. if (li_config_table[i].flag_table[j] & (LI_FLAG_PCCONNECT | LI_FLAG_MONITOR))
  9727. li_config_table[i].channel |= LI_CHANNEL_RX_DATA;
  9728. if (li_config_table[j].flag_table[i] & (LI_FLAG_PCCONNECT | LI_FLAG_ANNOUNCEMENT | LI_FLAG_MIX))
  9729. li_config_table[i].channel |= LI_CHANNEL_TX_DATA;
  9730. }
  9731. if (!(li_config_table[i].channel & LI_CHANNEL_ACTIVE))
  9732. {
  9733. li_config_table[i].coef_table[i] |= LI_COEF_PC_CH | LI_COEF_CH_PC;
  9734. li_config_table[i].channel |= LI_CHANNEL_TX_DATA | LI_CHANNEL_RX_DATA;
  9735. }
  9736. }
  9737. }
  9738. for (i = 0; i < li_total_channels; i++)
  9739. {
  9740. if (li_config_table[i].channel & LI_CHANNEL_INVOLVED)
  9741. {
  9742. j = 0;
  9743. while ((j < li_total_channels) && !(li_config_table[i].flag_table[j] & LI_FLAG_ANNOUNCEMENT))
  9744. j++;
  9745. if (j < li_total_channels)
  9746. {
  9747. for (j = 0; j < li_total_channels; j++)
  9748. {
  9749. li_config_table[i].coef_table[j] &= ~(LI_COEF_CH_CH | LI_COEF_PC_CH);
  9750. if (li_config_table[i].flag_table[j] & LI_FLAG_ANNOUNCEMENT)
  9751. li_config_table[i].coef_table[j] |= LI_COEF_PC_CH;
  9752. }
  9753. }
  9754. }
  9755. }
  9756. n = li_total_channels;
  9757. if (n > MIXER_MAX_DUMP_CHANNELS)
  9758. n = MIXER_MAX_DUMP_CHANNELS;
  9759. p = hex_line;
  9760. for (j = 0; j < n; j++)
  9761. {
  9762. if ((j & 0x7) == 0)
  9763. *(p++) = ' ';
  9764. *(p++) = hex_digit_table[li_config_table[j].curchnl >> 4];
  9765. *(p++) = hex_digit_table[li_config_table[j].curchnl & 0xf];
  9766. }
  9767. *p = '\0';
  9768. dbug (1, dprintf ("[%06lx] CURRENT %s",
  9769. (dword)(UnMapController (a->Id)), (char *) hex_line));
  9770. p = hex_line;
  9771. for (j = 0; j < n; j++)
  9772. {
  9773. if ((j & 0x7) == 0)
  9774. *(p++) = ' ';
  9775. *(p++) = hex_digit_table[li_config_table[j].channel >> 4];
  9776. *(p++) = hex_digit_table[li_config_table[j].channel & 0xf];
  9777. }
  9778. *p = '\0';
  9779. dbug (1, dprintf ("[%06lx] CHANNEL %s",
  9780. (dword)(UnMapController (a->Id)), (char *) hex_line));
  9781. p = hex_line;
  9782. for (j = 0; j < n; j++)
  9783. {
  9784. if ((j & 0x7) == 0)
  9785. *(p++) = ' ';
  9786. *(p++) = hex_digit_table[li_config_table[j].chflags >> 4];
  9787. *(p++) = hex_digit_table[li_config_table[j].chflags & 0xf];
  9788. }
  9789. *p = '\0';
  9790. dbug (1, dprintf ("[%06lx] CHFLAG %s",
  9791. (dword)(UnMapController (a->Id)), (char *) hex_line));
  9792. for (i = 0; i < n; i++)
  9793. {
  9794. p = hex_line;
  9795. for (j = 0; j < n; j++)
  9796. {
  9797. if ((j & 0x7) == 0)
  9798. *(p++) = ' ';
  9799. *(p++) = hex_digit_table[li_config_table[i].flag_table[j] >> 4];
  9800. *(p++) = hex_digit_table[li_config_table[i].flag_table[j] & 0xf];
  9801. }
  9802. *p = '\0';
  9803. dbug (1, dprintf ("[%06lx] FLAG[%02x]%s",
  9804. (dword)(UnMapController (a->Id)), i, (char *) hex_line));
  9805. }
  9806. for (i = 0; i < n; i++)
  9807. {
  9808. p = hex_line;
  9809. for (j = 0; j < n; j++)
  9810. {
  9811. if ((j & 0x7) == 0)
  9812. *(p++) = ' ';
  9813. *(p++) = hex_digit_table[li_config_table[i].coef_table[j] >> 4];
  9814. *(p++) = hex_digit_table[li_config_table[i].coef_table[j] & 0xf];
  9815. }
  9816. *p = '\0';
  9817. dbug (1, dprintf ("[%06lx] COEF[%02x]%s",
  9818. (dword)(UnMapController (a->Id)), i, (char *) hex_line));
  9819. }
  9820. }
  9821. static struct
  9822. {
  9823. byte mask;
  9824. byte line_flags;
  9825. } mixer_write_prog_pri[] =
  9826. {
  9827. { LI_COEF_CH_CH, 0 },
  9828. { LI_COEF_CH_PC, MIXER_COEF_LINE_TO_PC_FLAG },
  9829. { LI_COEF_PC_CH, MIXER_COEF_LINE_FROM_PC_FLAG },
  9830. { LI_COEF_PC_PC, MIXER_COEF_LINE_TO_PC_FLAG | MIXER_COEF_LINE_FROM_PC_FLAG }
  9831. };
  9832. static struct
  9833. {
  9834. byte from_ch;
  9835. byte to_ch;
  9836. byte mask;
  9837. byte xconnect_override;
  9838. } mixer_write_prog_bri[] =
  9839. {
  9840. { 0, 0, LI_COEF_CH_CH, 0x01 }, /* B to B */
  9841. { 1, 0, LI_COEF_CH_CH, 0x01 }, /* Alt B to B */
  9842. { 0, 0, LI_COEF_PC_CH, 0x80 }, /* PC to B */
  9843. { 1, 0, LI_COEF_PC_CH, 0x01 }, /* Alt PC to B */
  9844. { 2, 0, LI_COEF_CH_CH, 0x00 }, /* IC to B */
  9845. { 3, 0, LI_COEF_CH_CH, 0x00 }, /* Alt IC to B */
  9846. { 0, 0, LI_COEF_CH_PC, 0x80 }, /* B to PC */
  9847. { 1, 0, LI_COEF_CH_PC, 0x01 }, /* Alt B to PC */
  9848. { 0, 0, LI_COEF_PC_PC, 0x01 }, /* PC to PC */
  9849. { 1, 0, LI_COEF_PC_PC, 0x01 }, /* Alt PC to PC */
  9850. { 2, 0, LI_COEF_CH_PC, 0x00 }, /* IC to PC */
  9851. { 3, 0, LI_COEF_CH_PC, 0x00 }, /* Alt IC to PC */
  9852. { 0, 2, LI_COEF_CH_CH, 0x00 }, /* B to IC */
  9853. { 1, 2, LI_COEF_CH_CH, 0x00 }, /* Alt B to IC */
  9854. { 0, 2, LI_COEF_PC_CH, 0x00 }, /* PC to IC */
  9855. { 1, 2, LI_COEF_PC_CH, 0x00 }, /* Alt PC to IC */
  9856. { 2, 2, LI_COEF_CH_CH, 0x00 }, /* IC to IC */
  9857. { 3, 2, LI_COEF_CH_CH, 0x00 }, /* Alt IC to IC */
  9858. { 1, 1, LI_COEF_CH_CH, 0x01 }, /* Alt B to Alt B */
  9859. { 0, 1, LI_COEF_CH_CH, 0x01 }, /* B to Alt B */
  9860. { 1, 1, LI_COEF_PC_CH, 0x80 }, /* Alt PC to Alt B */
  9861. { 0, 1, LI_COEF_PC_CH, 0x01 }, /* PC to Alt B */
  9862. { 3, 1, LI_COEF_CH_CH, 0x00 }, /* Alt IC to Alt B */
  9863. { 2, 1, LI_COEF_CH_CH, 0x00 }, /* IC to Alt B */
  9864. { 1, 1, LI_COEF_CH_PC, 0x80 }, /* Alt B to Alt PC */
  9865. { 0, 1, LI_COEF_CH_PC, 0x01 }, /* B to Alt PC */
  9866. { 1, 1, LI_COEF_PC_PC, 0x01 }, /* Alt PC to Alt PC */
  9867. { 0, 1, LI_COEF_PC_PC, 0x01 }, /* PC to Alt PC */
  9868. { 3, 1, LI_COEF_CH_PC, 0x00 }, /* Alt IC to Alt PC */
  9869. { 2, 1, LI_COEF_CH_PC, 0x00 }, /* IC to Alt PC */
  9870. { 1, 3, LI_COEF_CH_CH, 0x00 }, /* Alt B to Alt IC */
  9871. { 0, 3, LI_COEF_CH_CH, 0x00 }, /* B to Alt IC */
  9872. { 1, 3, LI_COEF_PC_CH, 0x00 }, /* Alt PC to Alt IC */
  9873. { 0, 3, LI_COEF_PC_CH, 0x00 }, /* PC to Alt IC */
  9874. { 3, 3, LI_COEF_CH_CH, 0x00 }, /* Alt IC to Alt IC */
  9875. { 2, 3, LI_COEF_CH_CH, 0x00 } /* IC to Alt IC */
  9876. };
  9877. static byte mixer_swapped_index_bri[] =
  9878. {
  9879. 18, /* B to B */
  9880. 19, /* Alt B to B */
  9881. 20, /* PC to B */
  9882. 21, /* Alt PC to B */
  9883. 22, /* IC to B */
  9884. 23, /* Alt IC to B */
  9885. 24, /* B to PC */
  9886. 25, /* Alt B to PC */
  9887. 26, /* PC to PC */
  9888. 27, /* Alt PC to PC */
  9889. 28, /* IC to PC */
  9890. 29, /* Alt IC to PC */
  9891. 30, /* B to IC */
  9892. 31, /* Alt B to IC */
  9893. 32, /* PC to IC */
  9894. 33, /* Alt PC to IC */
  9895. 34, /* IC to IC */
  9896. 35, /* Alt IC to IC */
  9897. 0, /* Alt B to Alt B */
  9898. 1, /* B to Alt B */
  9899. 2, /* Alt PC to Alt B */
  9900. 3, /* PC to Alt B */
  9901. 4, /* Alt IC to Alt B */
  9902. 5, /* IC to Alt B */
  9903. 6, /* Alt B to Alt PC */
  9904. 7, /* B to Alt PC */
  9905. 8, /* Alt PC to Alt PC */
  9906. 9, /* PC to Alt PC */
  9907. 10, /* Alt IC to Alt PC */
  9908. 11, /* IC to Alt PC */
  9909. 12, /* Alt B to Alt IC */
  9910. 13, /* B to Alt IC */
  9911. 14, /* Alt PC to Alt IC */
  9912. 15, /* PC to Alt IC */
  9913. 16, /* Alt IC to Alt IC */
  9914. 17 /* IC to Alt IC */
  9915. };
  9916. static struct
  9917. {
  9918. byte mask;
  9919. byte from_pc;
  9920. byte to_pc;
  9921. } xconnect_write_prog[] =
  9922. {
  9923. { LI_COEF_CH_CH, FALSE, FALSE },
  9924. { LI_COEF_CH_PC, FALSE, TRUE },
  9925. { LI_COEF_PC_CH, TRUE, FALSE },
  9926. { LI_COEF_PC_PC, TRUE, TRUE }
  9927. };
  9928. static void xconnect_query_addresses (PLCI *plci)
  9929. {
  9930. DIVA_CAPI_ADAPTER *a;
  9931. word w, ch;
  9932. byte *p;
  9933. dbug (1, dprintf ("[%06lx] %s,%d: xconnect_query_addresses",
  9934. (dword)((plci->Id << 8) | UnMapController (plci->adapter->Id)),
  9935. (char *)(FILE_), __LINE__));
  9936. a = plci->adapter;
  9937. if (a->li_pri && ((plci->li_bchannel_id == 0)
  9938. || (li_config_table[a->li_base + (plci->li_bchannel_id - 1)].plci != plci)))
  9939. {
  9940. dbug (1, dprintf ("[%06x] %s,%d: Channel id wiped out",
  9941. (dword)((plci->Id << 8) | UnMapController (plci->adapter->Id)),
  9942. (char *)(FILE_), __LINE__));
  9943. return;
  9944. }
  9945. p = plci->internal_req_buffer;
  9946. ch = (a->li_pri) ? plci->li_bchannel_id - 1 : 0;
  9947. *(p++) = UDATA_REQUEST_XCONNECT_FROM;
  9948. w = ch;
  9949. *(p++) = (byte) w;
  9950. *(p++) = (byte)(w >> 8);
  9951. w = ch | XCONNECT_CHANNEL_PORT_PC;
  9952. *(p++) = (byte) w;
  9953. *(p++) = (byte)(w >> 8);
  9954. plci->NData[0].P = plci->internal_req_buffer;
  9955. plci->NData[0].PLength = p - plci->internal_req_buffer;
  9956. plci->NL.X = plci->NData;
  9957. plci->NL.ReqCh = 0;
  9958. plci->NL.Req = plci->nl_req = (byte) N_UDATA;
  9959. plci->adapter->request (&plci->NL);
  9960. }
  9961. static void xconnect_write_coefs (PLCI *plci, word internal_command)
  9962. {
  9963. dbug (1, dprintf ("[%06lx] %s,%d: xconnect_write_coefs %04x",
  9964. (dword)((plci->Id << 8) | UnMapController (plci->adapter->Id)),
  9965. (char *)(FILE_), __LINE__, internal_command));
  9966. plci->li_write_command = internal_command;
  9967. plci->li_write_channel = 0;
  9968. }
  9969. static byte xconnect_write_coefs_process (dword Id, PLCI *plci, byte Rc)
  9970. {
  9971. DIVA_CAPI_ADAPTER *a;
  9972. word w, n, i, j, r, s, to_ch;
  9973. dword d;
  9974. byte *p;
  9975. struct xconnect_transfer_address_s *transfer_address;
  9976. byte ch_map[MIXER_CHANNELS_BRI];
  9977. dbug (1, dprintf ("[%06x] %s,%d: xconnect_write_coefs_process %02x %d",
  9978. UnMapId (Id), (char *)(FILE_), __LINE__, Rc, plci->li_write_channel));
  9979. a = plci->adapter;
  9980. if ((plci->li_bchannel_id == 0)
  9981. || (li_config_table[a->li_base + (plci->li_bchannel_id - 1)].plci != plci))
  9982. {
  9983. dbug (1, dprintf ("[%06x] %s,%d: Channel id wiped out",
  9984. UnMapId (Id), (char *)(FILE_), __LINE__));
  9985. return (TRUE);
  9986. }
  9987. i = a->li_base + (plci->li_bchannel_id - 1);
  9988. j = plci->li_write_channel;
  9989. p = plci->internal_req_buffer;
  9990. if (j != 0)
  9991. {
  9992. if ((Rc != OK) && (Rc != OK_FC))
  9993. {
  9994. dbug (1, dprintf ("[%06lx] %s,%d: LI write coefs failed %02x",
  9995. UnMapId (Id), (char *)(FILE_), __LINE__, Rc));
  9996. return (FALSE);
  9997. }
  9998. }
  9999. if (li_config_table[i].adapter->manufacturer_features & MANUFACTURER_FEATURE_XCONNECT)
  10000. {
  10001. r = 0;
  10002. s = 0;
  10003. if (j < li_total_channels)
  10004. {
  10005. if (li_config_table[i].channel & LI_CHANNEL_ADDRESSES_SET)
  10006. {
  10007. s = ((li_config_table[i].send_b.card_address.low | li_config_table[i].send_b.card_address.high) ?
  10008. (LI_COEF_CH_CH | LI_COEF_CH_PC | LI_COEF_PC_CH | LI_COEF_PC_PC) : (LI_COEF_CH_PC | LI_COEF_PC_PC)) &
  10009. ((li_config_table[i].send_pc.card_address.low | li_config_table[i].send_pc.card_address.high) ?
  10010. (LI_COEF_CH_CH | LI_COEF_CH_PC | LI_COEF_PC_CH | LI_COEF_PC_PC) : (LI_COEF_CH_CH | LI_COEF_PC_CH));
  10011. }
  10012. r = ((li_config_table[i].coef_table[j] & 0xf) ^ (li_config_table[i].coef_table[j] >> 4));
  10013. while ((j < li_total_channels)
  10014. && ((r == 0)
  10015. || (!(li_config_table[j].channel & LI_CHANNEL_ADDRESSES_SET))
  10016. || (!li_config_table[j].adapter->li_pri
  10017. && (j >= li_config_table[j].adapter->li_base + MIXER_BCHANNELS_BRI))
  10018. || (((li_config_table[j].send_b.card_address.low != li_config_table[i].send_b.card_address.low)
  10019. || (li_config_table[j].send_b.card_address.high != li_config_table[i].send_b.card_address.high))
  10020. && (!(a->manufacturer_features & MANUFACTURER_FEATURE_DMACONNECT)
  10021. || !(li_config_table[j].adapter->manufacturer_features & MANUFACTURER_FEATURE_DMACONNECT)))
  10022. || ((li_config_table[j].adapter->li_base != a->li_base)
  10023. && !(r & s &
  10024. ((li_config_table[j].send_b.card_address.low | li_config_table[j].send_b.card_address.high) ?
  10025. (LI_COEF_CH_CH | LI_COEF_CH_PC | LI_COEF_PC_CH | LI_COEF_PC_PC) : (LI_COEF_PC_CH | LI_COEF_PC_PC)) &
  10026. ((li_config_table[j].send_pc.card_address.low | li_config_table[j].send_pc.card_address.high) ?
  10027. (LI_COEF_CH_CH | LI_COEF_CH_PC | LI_COEF_PC_CH | LI_COEF_PC_PC) : (LI_COEF_CH_CH | LI_COEF_CH_PC))))))
  10028. {
  10029. j++;
  10030. if (j < li_total_channels)
  10031. r = ((li_config_table[i].coef_table[j] & 0xf) ^ (li_config_table[i].coef_table[j] >> 4));
  10032. }
  10033. }
  10034. if (j < li_total_channels)
  10035. {
  10036. plci->internal_command = plci->li_write_command;
  10037. if (plci_nl_busy (plci))
  10038. return (TRUE);
  10039. to_ch = (a->li_pri) ? plci->li_bchannel_id - 1 : 0;
  10040. *(p++) = UDATA_REQUEST_XCONNECT_TO;
  10041. do
  10042. {
  10043. if (li_config_table[j].adapter->li_base != a->li_base)
  10044. {
  10045. r &= s &
  10046. ((li_config_table[j].send_b.card_address.low | li_config_table[j].send_b.card_address.high) ?
  10047. (LI_COEF_CH_CH | LI_COEF_CH_PC | LI_COEF_PC_CH | LI_COEF_PC_PC) : (LI_COEF_PC_CH | LI_COEF_PC_PC)) &
  10048. ((li_config_table[j].send_pc.card_address.low | li_config_table[j].send_pc.card_address.high) ?
  10049. (LI_COEF_CH_CH | LI_COEF_CH_PC | LI_COEF_PC_CH | LI_COEF_PC_PC) : (LI_COEF_CH_CH | LI_COEF_CH_PC));
  10050. }
  10051. n = 0;
  10052. do
  10053. {
  10054. if (r & xconnect_write_prog[n].mask)
  10055. {
  10056. if (xconnect_write_prog[n].from_pc)
  10057. transfer_address = &(li_config_table[j].send_pc);
  10058. else
  10059. transfer_address = &(li_config_table[j].send_b);
  10060. d = transfer_address->card_address.low;
  10061. *(p++) = (byte) d;
  10062. *(p++) = (byte)(d >> 8);
  10063. *(p++) = (byte)(d >> 16);
  10064. *(p++) = (byte)(d >> 24);
  10065. d = transfer_address->card_address.high;
  10066. *(p++) = (byte) d;
  10067. *(p++) = (byte)(d >> 8);
  10068. *(p++) = (byte)(d >> 16);
  10069. *(p++) = (byte)(d >> 24);
  10070. d = transfer_address->offset;
  10071. *(p++) = (byte) d;
  10072. *(p++) = (byte)(d >> 8);
  10073. *(p++) = (byte)(d >> 16);
  10074. *(p++) = (byte)(d >> 24);
  10075. w = xconnect_write_prog[n].to_pc ? to_ch | XCONNECT_CHANNEL_PORT_PC : to_ch;
  10076. *(p++) = (byte) w;
  10077. *(p++) = (byte)(w >> 8);
  10078. w = ((li_config_table[i].coef_table[j] & xconnect_write_prog[n].mask) == 0) ? 0x01 :
  10079. (li_config_table[i].adapter->u_law ?
  10080. (li_config_table[j].adapter->u_law ? 0x80 : 0x86) :
  10081. (li_config_table[j].adapter->u_law ? 0x7a : 0x80));
  10082. *(p++) = (byte) w;
  10083. *(p++) = (byte) 0;
  10084. li_config_table[i].coef_table[j] ^= xconnect_write_prog[n].mask << 4;
  10085. }
  10086. n++;
  10087. } while ((n < sizeof(xconnect_write_prog) / sizeof(xconnect_write_prog[0]))
  10088. && ((p - plci->internal_req_buffer) + 16 < INTERNAL_REQ_BUFFER_SIZE));
  10089. if (n == sizeof(xconnect_write_prog) / sizeof(xconnect_write_prog[0]))
  10090. {
  10091. do
  10092. {
  10093. j++;
  10094. if (j < li_total_channels)
  10095. r = ((li_config_table[i].coef_table[j] & 0xf) ^ (li_config_table[i].coef_table[j] >> 4));
  10096. } while ((j < li_total_channels)
  10097. && ((r == 0)
  10098. || (!(li_config_table[j].channel & LI_CHANNEL_ADDRESSES_SET))
  10099. || (!li_config_table[j].adapter->li_pri
  10100. && (j >= li_config_table[j].adapter->li_base + MIXER_BCHANNELS_BRI))
  10101. || (((li_config_table[j].send_b.card_address.low != li_config_table[i].send_b.card_address.low)
  10102. || (li_config_table[j].send_b.card_address.high != li_config_table[i].send_b.card_address.high))
  10103. && (!(a->manufacturer_features & MANUFACTURER_FEATURE_DMACONNECT)
  10104. || !(li_config_table[j].adapter->manufacturer_features & MANUFACTURER_FEATURE_DMACONNECT)))
  10105. || ((li_config_table[j].adapter->li_base != a->li_base)
  10106. && !(r & s &
  10107. ((li_config_table[j].send_b.card_address.low | li_config_table[j].send_b.card_address.high) ?
  10108. (LI_COEF_CH_CH | LI_COEF_CH_PC | LI_COEF_PC_CH | LI_COEF_PC_PC) : (LI_COEF_PC_CH | LI_COEF_PC_PC)) &
  10109. ((li_config_table[j].send_pc.card_address.low | li_config_table[j].send_pc.card_address.high) ?
  10110. (LI_COEF_CH_CH | LI_COEF_CH_PC | LI_COEF_PC_CH | LI_COEF_PC_PC) : (LI_COEF_CH_CH | LI_COEF_CH_PC))))));
  10111. }
  10112. } while ((j < li_total_channels)
  10113. && ((p - plci->internal_req_buffer) + 16 < INTERNAL_REQ_BUFFER_SIZE));
  10114. }
  10115. else if (j == li_total_channels)
  10116. {
  10117. plci->internal_command = plci->li_write_command;
  10118. if (plci_nl_busy (plci))
  10119. return (TRUE);
  10120. if (a->li_pri)
  10121. {
  10122. *(p++) = UDATA_REQUEST_SET_MIXER_COEFS_PRI_SYNC;
  10123. w = 0;
  10124. if (li_config_table[i].channel & LI_CHANNEL_TX_DATA)
  10125. w |= MIXER_FEATURE_ENABLE_TX_DATA;
  10126. if (li_config_table[i].channel & LI_CHANNEL_RX_DATA)
  10127. w |= MIXER_FEATURE_ENABLE_RX_DATA;
  10128. *(p++) = (byte) w;
  10129. *(p++) = (byte)(w >> 8);
  10130. }
  10131. else
  10132. {
  10133. *(p++) = UDATA_REQUEST_SET_MIXER_COEFS_BRI;
  10134. w = 0;
  10135. if ((plci->tel == ADV_VOICE) && (plci == a->AdvSignalPLCI)
  10136. && (ADV_VOICE_NEW_COEF_BASE + sizeof(word) <= a->adv_voice_coef_length))
  10137. {
  10138. w = GET_WORD (a->adv_voice_coef_buffer + ADV_VOICE_NEW_COEF_BASE);
  10139. }
  10140. if (li_config_table[i].channel & LI_CHANNEL_TX_DATA)
  10141. w |= MIXER_FEATURE_ENABLE_TX_DATA;
  10142. if (li_config_table[i].channel & LI_CHANNEL_RX_DATA)
  10143. w |= MIXER_FEATURE_ENABLE_RX_DATA;
  10144. *(p++) = (byte) w;
  10145. *(p++) = (byte)(w >> 8);
  10146. for (j = 0; j < sizeof(ch_map); j += 2)
  10147. {
  10148. if (plci->li_bchannel_id == 2)
  10149. {
  10150. ch_map[j] = (byte)(j+1);
  10151. ch_map[j+1] = (byte) j;
  10152. }
  10153. else
  10154. {
  10155. ch_map[j] = (byte) j;
  10156. ch_map[j+1] = (byte)(j+1);
  10157. }
  10158. }
  10159. for (n = 0; n < sizeof(mixer_write_prog_bri) / sizeof(mixer_write_prog_bri[0]); n++)
  10160. {
  10161. i = a->li_base + ch_map[mixer_write_prog_bri[n].to_ch];
  10162. j = a->li_base + ch_map[mixer_write_prog_bri[n].from_ch];
  10163. if (li_config_table[i].channel & li_config_table[j].channel & LI_CHANNEL_INVOLVED)
  10164. {
  10165. *p = (mixer_write_prog_bri[n].xconnect_override != 0) ?
  10166. mixer_write_prog_bri[n].xconnect_override :
  10167. ((li_config_table[i].coef_table[j] & mixer_write_prog_bri[n].mask) ? 0x80 : 0x01);
  10168. if ((i >= a->li_base + MIXER_BCHANNELS_BRI) || (j >= a->li_base + MIXER_BCHANNELS_BRI))
  10169. {
  10170. w = ((li_config_table[i].coef_table[j] & 0xf) ^ (li_config_table[i].coef_table[j] >> 4));
  10171. li_config_table[i].coef_table[j] ^= (w & mixer_write_prog_bri[n].mask) << 4;
  10172. }
  10173. }
  10174. else
  10175. {
  10176. *p = 0x00;
  10177. if ((a->AdvSignalPLCI != NULL) && (a->AdvSignalPLCI->tel == ADV_VOICE))
  10178. {
  10179. w = (plci == a->AdvSignalPLCI) ? n : mixer_swapped_index_bri[n];
  10180. if (ADV_VOICE_NEW_COEF_BASE + sizeof(word) + w < a->adv_voice_coef_length)
  10181. *p = a->adv_voice_coef_buffer[ADV_VOICE_NEW_COEF_BASE + sizeof(word) + w];
  10182. }
  10183. }
  10184. p++;
  10185. }
  10186. }
  10187. j = li_total_channels + 1;
  10188. }
  10189. }
  10190. else
  10191. {
  10192. if (j <= li_total_channels)
  10193. {
  10194. plci->internal_command = plci->li_write_command;
  10195. if (plci_nl_busy (plci))
  10196. return (TRUE);
  10197. if (j < a->li_base)
  10198. j = a->li_base;
  10199. if (a->li_pri)
  10200. {
  10201. *(p++) = UDATA_REQUEST_SET_MIXER_COEFS_PRI_SYNC;
  10202. w = 0;
  10203. if (li_config_table[i].channel & LI_CHANNEL_TX_DATA)
  10204. w |= MIXER_FEATURE_ENABLE_TX_DATA;
  10205. if (li_config_table[i].channel & LI_CHANNEL_RX_DATA)
  10206. w |= MIXER_FEATURE_ENABLE_RX_DATA;
  10207. *(p++) = (byte) w;
  10208. *(p++) = (byte)(w >> 8);
  10209. for (n = 0; n < sizeof(mixer_write_prog_pri) / sizeof(mixer_write_prog_pri[0]); n++)
  10210. {
  10211. *(p++) = (byte)((plci->li_bchannel_id - 1) | mixer_write_prog_pri[n].line_flags);
  10212. for (j = a->li_base; j < a->li_base + MIXER_CHANNELS_PRI; j++)
  10213. {
  10214. w = ((li_config_table[i].coef_table[j] & 0xf) ^ (li_config_table[i].coef_table[j] >> 4));
  10215. if (w & mixer_write_prog_pri[n].mask)
  10216. {
  10217. *(p++) = (li_config_table[i].coef_table[j] & mixer_write_prog_pri[n].mask) ? 0x80 : 0x01;
  10218. li_config_table[i].coef_table[j] ^= mixer_write_prog_pri[n].mask << 4;
  10219. }
  10220. else
  10221. *(p++) = 0x00;
  10222. }
  10223. *(p++) = (byte)((plci->li_bchannel_id - 1) | MIXER_COEF_LINE_ROW_FLAG | mixer_write_prog_pri[n].line_flags);
  10224. for (j = a->li_base; j < a->li_base + MIXER_CHANNELS_PRI; j++)
  10225. {
  10226. w = ((li_config_table[j].coef_table[i] & 0xf) ^ (li_config_table[j].coef_table[i] >> 4));
  10227. if (w & mixer_write_prog_pri[n].mask)
  10228. {
  10229. *(p++) = (li_config_table[j].coef_table[i] & mixer_write_prog_pri[n].mask) ? 0x80 : 0x01;
  10230. li_config_table[j].coef_table[i] ^= mixer_write_prog_pri[n].mask << 4;
  10231. }
  10232. else
  10233. *(p++) = 0x00;
  10234. }
  10235. }
  10236. }
  10237. else
  10238. {
  10239. *(p++) = UDATA_REQUEST_SET_MIXER_COEFS_BRI;
  10240. w = 0;
  10241. if ((plci->tel == ADV_VOICE) && (plci == a->AdvSignalPLCI)
  10242. && (ADV_VOICE_NEW_COEF_BASE + sizeof(word) <= a->adv_voice_coef_length))
  10243. {
  10244. w = GET_WORD (a->adv_voice_coef_buffer + ADV_VOICE_NEW_COEF_BASE);
  10245. }
  10246. if (li_config_table[i].channel & LI_CHANNEL_TX_DATA)
  10247. w |= MIXER_FEATURE_ENABLE_TX_DATA;
  10248. if (li_config_table[i].channel & LI_CHANNEL_RX_DATA)
  10249. w |= MIXER_FEATURE_ENABLE_RX_DATA;
  10250. *(p++) = (byte) w;
  10251. *(p++) = (byte)(w >> 8);
  10252. for (j = 0; j < sizeof(ch_map); j += 2)
  10253. {
  10254. if (plci->li_bchannel_id == 2)
  10255. {
  10256. ch_map[j] = (byte)(j+1);
  10257. ch_map[j+1] = (byte) j;
  10258. }
  10259. else
  10260. {
  10261. ch_map[j] = (byte) j;
  10262. ch_map[j+1] = (byte)(j+1);
  10263. }
  10264. }
  10265. for (n = 0; n < sizeof(mixer_write_prog_bri) / sizeof(mixer_write_prog_bri[0]); n++)
  10266. {
  10267. i = a->li_base + ch_map[mixer_write_prog_bri[n].to_ch];
  10268. j = a->li_base + ch_map[mixer_write_prog_bri[n].from_ch];
  10269. if (li_config_table[i].channel & li_config_table[j].channel & LI_CHANNEL_INVOLVED)
  10270. {
  10271. *p = ((li_config_table[i].coef_table[j] & mixer_write_prog_bri[n].mask) ? 0x80 : 0x01);
  10272. w = ((li_config_table[i].coef_table[j] & 0xf) ^ (li_config_table[i].coef_table[j] >> 4));
  10273. li_config_table[i].coef_table[j] ^= (w & mixer_write_prog_bri[n].mask) << 4;
  10274. }
  10275. else
  10276. {
  10277. *p = 0x00;
  10278. if ((a->AdvSignalPLCI != NULL) && (a->AdvSignalPLCI->tel == ADV_VOICE))
  10279. {
  10280. w = (plci == a->AdvSignalPLCI) ? n : mixer_swapped_index_bri[n];
  10281. if (ADV_VOICE_NEW_COEF_BASE + sizeof(word) + w < a->adv_voice_coef_length)
  10282. *p = a->adv_voice_coef_buffer[ADV_VOICE_NEW_COEF_BASE + sizeof(word) + w];
  10283. }
  10284. }
  10285. p++;
  10286. }
  10287. }
  10288. j = li_total_channels + 1;
  10289. }
  10290. }
  10291. plci->li_write_channel = j;
  10292. if (p != plci->internal_req_buffer)
  10293. {
  10294. plci->NData[0].P = plci->internal_req_buffer;
  10295. plci->NData[0].PLength = p - plci->internal_req_buffer;
  10296. plci->NL.X = plci->NData;
  10297. plci->NL.ReqCh = 0;
  10298. plci->NL.Req = plci->nl_req = (byte) N_UDATA;
  10299. plci->adapter->request (&plci->NL);
  10300. }
  10301. return (TRUE);
  10302. }
  10303. static void mixer_notify_update (PLCI *plci, byte others)
  10304. {
  10305. DIVA_CAPI_ADAPTER *a;
  10306. word i, w;
  10307. PLCI *notify_plci;
  10308. byte msg[sizeof(CAPI_MSG_HEADER) + 6];
  10309. dbug (1, dprintf ("[%06lx] %s,%d: mixer_notify_update %d",
  10310. (dword)((plci->Id << 8) | UnMapController (plci->adapter->Id)),
  10311. (char *)(FILE_), __LINE__, others));
  10312. a = plci->adapter;
  10313. if (a->profile.Global_Options & GL_LINE_INTERCONNECT_SUPPORTED)
  10314. {
  10315. if (others)
  10316. plci->li_notify_update = TRUE;
  10317. i = 0;
  10318. do
  10319. {
  10320. notify_plci = NULL;
  10321. if (others)
  10322. {
  10323. while ((i < li_total_channels) && (li_config_table[i].plci == NULL))
  10324. i++;
  10325. if (i < li_total_channels)
  10326. notify_plci = li_config_table[i++].plci;
  10327. }
  10328. else
  10329. {
  10330. if ((plci->li_bchannel_id != 0)
  10331. && (li_config_table[a->li_base + (plci->li_bchannel_id - 1)].plci == plci))
  10332. {
  10333. notify_plci = plci;
  10334. }
  10335. }
  10336. if ((notify_plci != NULL)
  10337. && !notify_plci->li_notify_update
  10338. && (notify_plci->appl != NULL)
  10339. && (notify_plci->State)
  10340. && notify_plci->NL.Id && !notify_plci->nl_remove_id)
  10341. {
  10342. notify_plci->li_notify_update = TRUE;
  10343. ((CAPI_MSG *) msg)->header.length = 18;
  10344. ((CAPI_MSG *) msg)->header.appl_id = notify_plci->appl->Id;
  10345. ((CAPI_MSG *) msg)->header.command = _FACILITY_R;
  10346. ((CAPI_MSG *) msg)->header.number = 0;
  10347. ((CAPI_MSG *) msg)->header.controller = notify_plci->adapter->Id;
  10348. ((CAPI_MSG *) msg)->header.plci = notify_plci->Id;
  10349. ((CAPI_MSG *) msg)->header.ncci = 0;
  10350. ((CAPI_MSG *) msg)->info.facility_req.Selector = SELECTOR_LINE_INTERCONNECT;
  10351. ((CAPI_MSG *) msg)->info.facility_req.structs[0] = 3;
  10352. PUT_WORD (&(((CAPI_MSG *) msg)->info.facility_req.structs[1]), LI_REQ_SILENT_UPDATE);
  10353. ((CAPI_MSG *) msg)->info.facility_req.structs[3] = 0;
  10354. w = api_put (notify_plci->appl, (CAPI_MSG *) msg);
  10355. if (w != _QUEUE_FULL)
  10356. {
  10357. if (w != 0)
  10358. {
  10359. dbug (1, dprintf ("[%06lx] %s,%d: Interconnect notify failed %06x %d",
  10360. (dword)((plci->Id << 8) | UnMapController (plci->adapter->Id)),
  10361. (char *)(FILE_), __LINE__,
  10362. (dword)((notify_plci->Id << 8) | UnMapController (notify_plci->adapter->Id)), w));
  10363. }
  10364. notify_plci->li_notify_update = FALSE;
  10365. }
  10366. }
  10367. } while (others && (notify_plci != NULL));
  10368. if (others)
  10369. plci->li_notify_update = FALSE;
  10370. }
  10371. }
  10372. static void mixer_clear_config (PLCI *plci)
  10373. {
  10374. DIVA_CAPI_ADAPTER *a;
  10375. word i, j;
  10376. dbug (1, dprintf ("[%06lx] %s,%d: mixer_clear_config",
  10377. (dword)((plci->Id << 8) | UnMapController (plci->adapter->Id)),
  10378. (char *)(FILE_), __LINE__));
  10379. plci->li_notify_update = FALSE;
  10380. plci->li_plci_b_write_pos = 0;
  10381. plci->li_plci_b_read_pos = 0;
  10382. plci->li_plci_b_req_pos = 0;
  10383. a = plci->adapter;
  10384. if ((plci->li_bchannel_id != 0)
  10385. && (li_config_table[a->li_base + (plci->li_bchannel_id - 1)].plci == plci))
  10386. {
  10387. i = a->li_base + (plci->li_bchannel_id - 1);
  10388. li_config_table[i].curchnl = 0;
  10389. li_config_table[i].channel = 0;
  10390. li_config_table[i].chflags = 0;
  10391. for (j = 0; j < li_total_channels; j++)
  10392. {
  10393. li_config_table[j].flag_table[i] = 0;
  10394. li_config_table[i].flag_table[j] = 0;
  10395. li_config_table[i].coef_table[j] = 0;
  10396. li_config_table[j].coef_table[i] = 0;
  10397. }
  10398. if (!a->li_pri)
  10399. {
  10400. li_config_table[i].coef_table[i] |= LI_COEF_CH_PC_SET | LI_COEF_PC_CH_SET;
  10401. if ((plci->tel == ADV_VOICE) && (plci == a->AdvSignalPLCI))
  10402. {
  10403. i = a->li_base + MIXER_IC_CHANNEL_BASE + (plci->li_bchannel_id - 1);
  10404. li_config_table[i].curchnl = 0;
  10405. li_config_table[i].channel = 0;
  10406. li_config_table[i].chflags = 0;
  10407. for (j = 0; j < li_total_channels; j++)
  10408. {
  10409. li_config_table[i].flag_table[j] = 0;
  10410. li_config_table[j].flag_table[i] = 0;
  10411. li_config_table[i].coef_table[j] = 0;
  10412. li_config_table[j].coef_table[i] = 0;
  10413. }
  10414. if (a->manufacturer_features & MANUFACTURER_FEATURE_SLAVE_CODEC)
  10415. {
  10416. i = a->li_base + MIXER_IC_CHANNEL_BASE + (2 - plci->li_bchannel_id);
  10417. li_config_table[i].curchnl = 0;
  10418. li_config_table[i].channel = 0;
  10419. li_config_table[i].chflags = 0;
  10420. for (j = 0; j < li_total_channels; j++)
  10421. {
  10422. li_config_table[i].flag_table[j] = 0;
  10423. li_config_table[j].flag_table[i] = 0;
  10424. li_config_table[i].coef_table[j] = 0;
  10425. li_config_table[j].coef_table[i] = 0;
  10426. }
  10427. }
  10428. }
  10429. }
  10430. }
  10431. }
  10432. static void mixer_prepare_switch (dword Id, PLCI *plci)
  10433. {
  10434. dbug (1, dprintf ("[%06lx] %s,%d: mixer_prepare_switch",
  10435. UnMapId (Id), (char *)(FILE_), __LINE__));
  10436. do
  10437. {
  10438. mixer_indication_coefs_set (Id, plci);
  10439. } while (plci->li_plci_b_read_pos != plci->li_plci_b_req_pos);
  10440. }
  10441. static word mixer_save_config (dword Id, PLCI *plci, byte Rc)
  10442. {
  10443. DIVA_CAPI_ADAPTER *a;
  10444. word i, j;
  10445. dbug (1, dprintf ("[%06lx] %s,%d: mixer_save_config %02x %d",
  10446. UnMapId (Id), (char *)(FILE_), __LINE__, Rc, plci->adjust_b_state));
  10447. a = plci->adapter;
  10448. if ((plci->li_bchannel_id != 0)
  10449. && (li_config_table[a->li_base + (plci->li_bchannel_id - 1)].plci == plci))
  10450. {
  10451. i = a->li_base + (plci->li_bchannel_id - 1);
  10452. for (j = 0; j < li_total_channels; j++)
  10453. {
  10454. li_config_table[i].coef_table[j] &= 0xf;
  10455. li_config_table[j].coef_table[i] &= 0xf;
  10456. }
  10457. if (!a->li_pri)
  10458. li_config_table[i].coef_table[i] |= LI_COEF_CH_PC_SET | LI_COEF_PC_CH_SET;
  10459. }
  10460. return (GOOD);
  10461. }
  10462. static word mixer_restore_config (dword Id, PLCI *plci, byte Rc)
  10463. {
  10464. DIVA_CAPI_ADAPTER *a;
  10465. word Info;
  10466. dbug (1, dprintf ("[%06lx] %s,%d: mixer_restore_config %02x %d",
  10467. UnMapId (Id), (char *)(FILE_), __LINE__, Rc, plci->adjust_b_state));
  10468. Info = GOOD;
  10469. a = plci->adapter;
  10470. if ((plci->B1_facilities & B1_FACILITY_MIXER)
  10471. && (plci->li_bchannel_id != 0)
  10472. && (li_config_table[a->li_base + (plci->li_bchannel_id - 1)].plci == plci))
  10473. {
  10474. switch (plci->adjust_b_state)
  10475. {
  10476. case ADJUST_B_RESTORE_MIXER_1:
  10477. if (a->manufacturer_features & MANUFACTURER_FEATURE_XCONNECT)
  10478. {
  10479. plci->internal_command = plci->adjust_b_command;
  10480. if (plci_nl_busy (plci))
  10481. {
  10482. plci->adjust_b_state = ADJUST_B_RESTORE_MIXER_1;
  10483. break;
  10484. }
  10485. xconnect_query_addresses (plci);
  10486. plci->adjust_b_state = ADJUST_B_RESTORE_MIXER_2;
  10487. break;
  10488. }
  10489. plci->adjust_b_state = ADJUST_B_RESTORE_MIXER_5;
  10490. Rc = OK;
  10491. case ADJUST_B_RESTORE_MIXER_2:
  10492. case ADJUST_B_RESTORE_MIXER_3:
  10493. case ADJUST_B_RESTORE_MIXER_4:
  10494. if ((Rc != OK) && (Rc != OK_FC) && (Rc != 0))
  10495. {
  10496. dbug (1, dprintf ("[%06lx] %s,%d: Adjust B query addresses failed %02x",
  10497. UnMapId (Id), (char *)(FILE_), __LINE__, Rc));
  10498. Info = _WRONG_STATE;
  10499. break;
  10500. }
  10501. if (Rc == OK)
  10502. {
  10503. if (plci->adjust_b_state == ADJUST_B_RESTORE_MIXER_2)
  10504. plci->adjust_b_state = ADJUST_B_RESTORE_MIXER_3;
  10505. else if (plci->adjust_b_state == ADJUST_B_RESTORE_MIXER_4)
  10506. plci->adjust_b_state = ADJUST_B_RESTORE_MIXER_5;
  10507. }
  10508. else if (Rc == 0)
  10509. {
  10510. if (plci->adjust_b_state == ADJUST_B_RESTORE_MIXER_2)
  10511. plci->adjust_b_state = ADJUST_B_RESTORE_MIXER_4;
  10512. else if (plci->adjust_b_state == ADJUST_B_RESTORE_MIXER_3)
  10513. plci->adjust_b_state = ADJUST_B_RESTORE_MIXER_5;
  10514. }
  10515. if (plci->adjust_b_state != ADJUST_B_RESTORE_MIXER_5)
  10516. {
  10517. plci->internal_command = plci->adjust_b_command;
  10518. break;
  10519. }
  10520. case ADJUST_B_RESTORE_MIXER_5:
  10521. xconnect_write_coefs (plci, plci->adjust_b_command);
  10522. plci->adjust_b_state = ADJUST_B_RESTORE_MIXER_6;
  10523. Rc = OK;
  10524. case ADJUST_B_RESTORE_MIXER_6:
  10525. if (!xconnect_write_coefs_process (Id, plci, Rc))
  10526. {
  10527. dbug (1, dprintf ("[%06lx] %s,%d: Write mixer coefs failed",
  10528. UnMapId (Id), (char *)(FILE_), __LINE__));
  10529. Info = _FACILITY_NOT_SUPPORTED;
  10530. break;
  10531. }
  10532. if (plci->internal_command)
  10533. break;
  10534. plci->adjust_b_state = ADJUST_B_RESTORE_MIXER_7;
  10535. case ADJUST_B_RESTORE_MIXER_7:
  10536. break;
  10537. }
  10538. }
  10539. return (Info);
  10540. }
  10541. static void mixer_command (dword Id, PLCI *plci, byte Rc)
  10542. {
  10543. DIVA_CAPI_ADAPTER *a;
  10544. word i, internal_command, Info;
  10545. dbug (1, dprintf ("[%06lx] %s,%d: mixer_command %02x %04x %04x",
  10546. UnMapId (Id), (char *)(FILE_), __LINE__, Rc, plci->internal_command,
  10547. plci->li_cmd));
  10548. Info = GOOD;
  10549. a = plci->adapter;
  10550. internal_command = plci->internal_command;
  10551. plci->internal_command = 0;
  10552. switch (plci->li_cmd)
  10553. {
  10554. case LI_REQ_CONNECT:
  10555. case LI_REQ_DISCONNECT:
  10556. case LI_REQ_SILENT_UPDATE:
  10557. switch (internal_command)
  10558. {
  10559. default:
  10560. if (plci->li_channel_bits & LI_CHANNEL_INVOLVED)
  10561. {
  10562. adjust_b1_resource (Id, plci, NULL, (word)(plci->B1_facilities |
  10563. B1_FACILITY_MIXER), MIXER_COMMAND_1);
  10564. }
  10565. case MIXER_COMMAND_1:
  10566. if (plci->li_channel_bits & LI_CHANNEL_INVOLVED)
  10567. {
  10568. if (adjust_b_process (Id, plci, Rc) != GOOD)
  10569. {
  10570. dbug (1, dprintf ("[%06lx] %s,%d: Load mixer failed",
  10571. UnMapId (Id), (char *)(FILE_), __LINE__));
  10572. Info = _FACILITY_NOT_SUPPORTED;
  10573. break;
  10574. }
  10575. if (plci->internal_command)
  10576. return;
  10577. }
  10578. plci->li_plci_b_req_pos = plci->li_plci_b_write_pos;
  10579. if ((plci->li_channel_bits & LI_CHANNEL_INVOLVED)
  10580. || ((get_b1_facilities (plci, plci->B1_resource) & B1_FACILITY_MIXER)
  10581. && (add_b1_facilities (plci, plci->B1_resource, (word)(plci->B1_facilities &
  10582. ~B1_FACILITY_MIXER)) == plci->B1_resource)))
  10583. {
  10584. xconnect_write_coefs (plci, MIXER_COMMAND_2);
  10585. }
  10586. else
  10587. {
  10588. do
  10589. {
  10590. mixer_indication_coefs_set (Id, plci);
  10591. } while (plci->li_plci_b_read_pos != plci->li_plci_b_req_pos);
  10592. }
  10593. case MIXER_COMMAND_2:
  10594. if ((plci->li_channel_bits & LI_CHANNEL_INVOLVED)
  10595. || ((get_b1_facilities (plci, plci->B1_resource) & B1_FACILITY_MIXER)
  10596. && (add_b1_facilities (plci, plci->B1_resource, (word)(plci->B1_facilities &
  10597. ~B1_FACILITY_MIXER)) == plci->B1_resource)))
  10598. {
  10599. if (!xconnect_write_coefs_process (Id, plci, Rc))
  10600. {
  10601. dbug (1, dprintf ("[%06lx] %s,%d: Write mixer coefs failed",
  10602. UnMapId (Id), (char *)(FILE_), __LINE__));
  10603. if (plci->li_plci_b_write_pos != plci->li_plci_b_req_pos)
  10604. {
  10605. do
  10606. {
  10607. plci->li_plci_b_write_pos = (plci->li_plci_b_write_pos == 0) ?
  10608. LI_PLCI_B_QUEUE_ENTRIES-1 : plci->li_plci_b_write_pos - 1;
  10609. i = (plci->li_plci_b_write_pos == 0) ?
  10610. LI_PLCI_B_QUEUE_ENTRIES-1 : plci->li_plci_b_write_pos - 1;
  10611. } while ((plci->li_plci_b_write_pos != plci->li_plci_b_req_pos)
  10612. && !(plci->li_plci_b_queue[i] & LI_PLCI_B_LAST_FLAG));
  10613. }
  10614. Info = _FACILITY_NOT_SUPPORTED;
  10615. break;
  10616. }
  10617. if (plci->internal_command)
  10618. return;
  10619. }
  10620. if (!(plci->li_channel_bits & LI_CHANNEL_INVOLVED))
  10621. {
  10622. adjust_b1_resource (Id, plci, NULL, (word)(plci->B1_facilities &
  10623. ~B1_FACILITY_MIXER), MIXER_COMMAND_3);
  10624. }
  10625. case MIXER_COMMAND_3:
  10626. if (!(plci->li_channel_bits & LI_CHANNEL_INVOLVED))
  10627. {
  10628. if (adjust_b_process (Id, plci, Rc) != GOOD)
  10629. {
  10630. dbug (1, dprintf ("[%06lx] %s,%d: Unload mixer failed",
  10631. UnMapId (Id), (char *)(FILE_), __LINE__));
  10632. Info = _FACILITY_NOT_SUPPORTED;
  10633. break;
  10634. }
  10635. if (plci->internal_command)
  10636. return;
  10637. }
  10638. break;
  10639. }
  10640. break;
  10641. }
  10642. if ((plci->li_bchannel_id == 0)
  10643. || (li_config_table[a->li_base + (plci->li_bchannel_id - 1)].plci != plci))
  10644. {
  10645. dbug (1, dprintf ("[%06x] %s,%d: Channel id wiped out %d",
  10646. UnMapId (Id), (char *)(FILE_), __LINE__, (int)(plci->li_bchannel_id)));
  10647. }
  10648. else
  10649. {
  10650. i = a->li_base + (plci->li_bchannel_id - 1);
  10651. li_config_table[i].curchnl = plci->li_channel_bits;
  10652. if (!a->li_pri && (plci->tel == ADV_VOICE) && (plci == a->AdvSignalPLCI))
  10653. {
  10654. i = a->li_base + MIXER_IC_CHANNEL_BASE + (plci->li_bchannel_id - 1);
  10655. li_config_table[i].curchnl = plci->li_channel_bits;
  10656. if (a->manufacturer_features & MANUFACTURER_FEATURE_SLAVE_CODEC)
  10657. {
  10658. i = a->li_base + MIXER_IC_CHANNEL_BASE + (2 - plci->li_bchannel_id);
  10659. li_config_table[i].curchnl = plci->li_channel_bits;
  10660. }
  10661. }
  10662. }
  10663. }
  10664. static void li_update_connect (dword Id, DIVA_CAPI_ADAPTER *a, PLCI *plci,
  10665. dword plci_b_id, byte connect, dword li_flags)
  10666. {
  10667. word i, ch_a, ch_a_v, ch_a_s, ch_b, ch_b_v, ch_b_s;
  10668. PLCI *plci_b;
  10669. DIVA_CAPI_ADAPTER *a_b;
  10670. a_b = &(adapter[MapController ((byte)(plci_b_id & 0x7f)) - 1]);
  10671. plci_b = &(a_b->plci[((plci_b_id >> 8) & 0xff) - 1]);
  10672. ch_a = a->li_base + (plci->li_bchannel_id - 1);
  10673. if (!a->li_pri && (plci->tel == ADV_VOICE)
  10674. && (plci == a->AdvSignalPLCI) && (Id & EXT_CONTROLLER))
  10675. {
  10676. ch_a_v = ch_a + MIXER_IC_CHANNEL_BASE;
  10677. ch_a_s = (a->manufacturer_features & MANUFACTURER_FEATURE_SLAVE_CODEC) ?
  10678. a->li_base + MIXER_IC_CHANNEL_BASE + (2 - plci->li_bchannel_id) : ch_a_v;
  10679. }
  10680. else
  10681. {
  10682. ch_a_v = ch_a;
  10683. ch_a_s = ch_a;
  10684. }
  10685. ch_b = a_b->li_base + (plci_b->li_bchannel_id - 1);
  10686. if (!a_b->li_pri && (plci_b->tel == ADV_VOICE)
  10687. && (plci_b == a_b->AdvSignalPLCI) && (plci_b_id & EXT_CONTROLLER))
  10688. {
  10689. ch_b_v = ch_b + MIXER_IC_CHANNEL_BASE;
  10690. ch_b_s = (a_b->manufacturer_features & MANUFACTURER_FEATURE_SLAVE_CODEC) ?
  10691. a_b->li_base + MIXER_IC_CHANNEL_BASE + (2 - plci_b->li_bchannel_id) : ch_b_v;
  10692. }
  10693. else
  10694. {
  10695. ch_b_v = ch_b;
  10696. ch_b_s = ch_b;
  10697. }
  10698. if (connect)
  10699. {
  10700. li_config_table[ch_a].flag_table[ch_a_v] &= ~LI_FLAG_MONITOR;
  10701. li_config_table[ch_a].flag_table[ch_a_s] &= ~LI_FLAG_MONITOR;
  10702. li_config_table[ch_a_v].flag_table[ch_a] &= ~(LI_FLAG_ANNOUNCEMENT | LI_FLAG_MIX);
  10703. li_config_table[ch_a_s].flag_table[ch_a] &= ~(LI_FLAG_ANNOUNCEMENT | LI_FLAG_MIX);
  10704. }
  10705. li_config_table[ch_a].flag_table[ch_b_v] &= ~LI_FLAG_MONITOR;
  10706. li_config_table[ch_a].flag_table[ch_b_s] &= ~LI_FLAG_MONITOR;
  10707. li_config_table[ch_b_v].flag_table[ch_a] &= ~(LI_FLAG_ANNOUNCEMENT | LI_FLAG_MIX);
  10708. li_config_table[ch_b_s].flag_table[ch_a] &= ~(LI_FLAG_ANNOUNCEMENT | LI_FLAG_MIX);
  10709. if (ch_a_v == ch_b_v)
  10710. {
  10711. li_config_table[ch_a_v].flag_table[ch_b_v] &= ~LI_FLAG_CONFERENCE;
  10712. li_config_table[ch_a_s].flag_table[ch_b_s] &= ~LI_FLAG_CONFERENCE;
  10713. }
  10714. else
  10715. {
  10716. if (li_config_table[ch_a_v].flag_table[ch_b_v] & LI_FLAG_CONFERENCE)
  10717. {
  10718. for (i = 0; i < li_total_channels; i++)
  10719. {
  10720. if (i != ch_a_v)
  10721. li_config_table[ch_a_v].flag_table[i] &= ~LI_FLAG_CONFERENCE;
  10722. }
  10723. }
  10724. if (li_config_table[ch_a_s].flag_table[ch_b_v] & LI_FLAG_CONFERENCE)
  10725. {
  10726. for (i = 0; i < li_total_channels; i++)
  10727. {
  10728. if (i != ch_a_s)
  10729. li_config_table[ch_a_s].flag_table[i] &= ~LI_FLAG_CONFERENCE;
  10730. }
  10731. }
  10732. if (li_config_table[ch_b_v].flag_table[ch_a_v] & LI_FLAG_CONFERENCE)
  10733. {
  10734. for (i = 0; i < li_total_channels; i++)
  10735. {
  10736. if (i != ch_a_v)
  10737. li_config_table[i].flag_table[ch_a_v] &= ~LI_FLAG_CONFERENCE;
  10738. }
  10739. }
  10740. if (li_config_table[ch_b_v].flag_table[ch_a_s] & LI_FLAG_CONFERENCE)
  10741. {
  10742. for (i = 0; i < li_total_channels; i++)
  10743. {
  10744. if (i != ch_a_s)
  10745. li_config_table[i].flag_table[ch_a_s] &= ~LI_FLAG_CONFERENCE;
  10746. }
  10747. }
  10748. }
  10749. if (li_flags & LI_FLAG_CONFERENCE_A_B)
  10750. {
  10751. li_config_table[ch_b_v].flag_table[ch_a_v] |= LI_FLAG_CONFERENCE;
  10752. li_config_table[ch_b_s].flag_table[ch_a_v] |= LI_FLAG_CONFERENCE;
  10753. li_config_table[ch_b_v].flag_table[ch_a_s] |= LI_FLAG_CONFERENCE;
  10754. li_config_table[ch_b_s].flag_table[ch_a_s] |= LI_FLAG_CONFERENCE;
  10755. }
  10756. if (li_flags & LI_FLAG_CONFERENCE_B_A)
  10757. {
  10758. li_config_table[ch_a_v].flag_table[ch_b_v] |= LI_FLAG_CONFERENCE;
  10759. li_config_table[ch_a_v].flag_table[ch_b_s] |= LI_FLAG_CONFERENCE;
  10760. li_config_table[ch_a_s].flag_table[ch_b_v] |= LI_FLAG_CONFERENCE;
  10761. li_config_table[ch_a_s].flag_table[ch_b_s] |= LI_FLAG_CONFERENCE;
  10762. }
  10763. if (li_flags & LI_FLAG_MONITOR_A)
  10764. {
  10765. li_config_table[ch_a].flag_table[ch_a_v] |= LI_FLAG_MONITOR;
  10766. li_config_table[ch_a].flag_table[ch_a_s] |= LI_FLAG_MONITOR;
  10767. }
  10768. if (li_flags & LI_FLAG_MONITOR_B)
  10769. {
  10770. li_config_table[ch_a].flag_table[ch_b_v] |= LI_FLAG_MONITOR;
  10771. li_config_table[ch_a].flag_table[ch_b_s] |= LI_FLAG_MONITOR;
  10772. }
  10773. if (li_flags & LI_FLAG_ANNOUNCEMENT_A)
  10774. {
  10775. li_config_table[ch_a_v].flag_table[ch_a] |= LI_FLAG_ANNOUNCEMENT;
  10776. li_config_table[ch_a_s].flag_table[ch_a] |= LI_FLAG_ANNOUNCEMENT;
  10777. }
  10778. if (li_flags & LI_FLAG_ANNOUNCEMENT_B)
  10779. {
  10780. li_config_table[ch_b_v].flag_table[ch_a] |= LI_FLAG_ANNOUNCEMENT;
  10781. li_config_table[ch_b_s].flag_table[ch_a] |= LI_FLAG_ANNOUNCEMENT;
  10782. }
  10783. if (li_flags & LI_FLAG_MIX_A)
  10784. {
  10785. li_config_table[ch_a_v].flag_table[ch_a] |= LI_FLAG_MIX;
  10786. li_config_table[ch_a_s].flag_table[ch_a] |= LI_FLAG_MIX;
  10787. }
  10788. if (li_flags & LI_FLAG_MIX_B)
  10789. {
  10790. li_config_table[ch_b_v].flag_table[ch_a] |= LI_FLAG_MIX;
  10791. li_config_table[ch_b_s].flag_table[ch_a] |= LI_FLAG_MIX;
  10792. }
  10793. if (ch_a_v != ch_a_s)
  10794. {
  10795. li_config_table[ch_a_v].flag_table[ch_a_s] |= LI_FLAG_CONFERENCE;
  10796. li_config_table[ch_a_s].flag_table[ch_a_v] |= LI_FLAG_CONFERENCE;
  10797. }
  10798. if (ch_b_v != ch_b_s)
  10799. {
  10800. li_config_table[ch_b_v].flag_table[ch_b_s] |= LI_FLAG_CONFERENCE;
  10801. li_config_table[ch_b_s].flag_table[ch_b_v] |= LI_FLAG_CONFERENCE;
  10802. }
  10803. }
  10804. static void li2_update_connect (dword Id, DIVA_CAPI_ADAPTER *a, PLCI *plci,
  10805. dword plci_b_id, byte connect, dword li_flags)
  10806. {
  10807. word ch_a, ch_a_v, ch_a_s, ch_b, ch_b_v, ch_b_s;
  10808. PLCI *plci_b;
  10809. DIVA_CAPI_ADAPTER *a_b;
  10810. a_b = &(adapter[MapController ((byte)(plci_b_id & 0x7f)) - 1]);
  10811. plci_b = &(a_b->plci[((plci_b_id >> 8) & 0xff) - 1]);
  10812. ch_a = a->li_base + (plci->li_bchannel_id - 1);
  10813. if (!a->li_pri && (plci->tel == ADV_VOICE)
  10814. && (plci == a->AdvSignalPLCI) && (Id & EXT_CONTROLLER))
  10815. {
  10816. ch_a_v = ch_a + MIXER_IC_CHANNEL_BASE;
  10817. ch_a_s = (a->manufacturer_features & MANUFACTURER_FEATURE_SLAVE_CODEC) ?
  10818. a->li_base + MIXER_IC_CHANNEL_BASE + (2 - plci->li_bchannel_id) : ch_a_v;
  10819. }
  10820. else
  10821. {
  10822. ch_a_v = ch_a;
  10823. ch_a_s = ch_a;
  10824. }
  10825. ch_b = a_b->li_base + (plci_b->li_bchannel_id - 1);
  10826. if (!a_b->li_pri && (plci_b->tel == ADV_VOICE)
  10827. && (plci_b == a_b->AdvSignalPLCI) && (plci_b_id & EXT_CONTROLLER))
  10828. {
  10829. ch_b_v = ch_b + MIXER_IC_CHANNEL_BASE;
  10830. ch_b_s = (a_b->manufacturer_features & MANUFACTURER_FEATURE_SLAVE_CODEC) ?
  10831. a_b->li_base + MIXER_IC_CHANNEL_BASE + (2 - plci_b->li_bchannel_id) : ch_b_v;
  10832. }
  10833. else
  10834. {
  10835. ch_b_v = ch_b;
  10836. ch_b_s = ch_b;
  10837. }
  10838. if (connect)
  10839. {
  10840. li_config_table[ch_b].flag_table[ch_b_v] &= ~LI_FLAG_MONITOR;
  10841. li_config_table[ch_b].flag_table[ch_b_s] &= ~LI_FLAG_MONITOR;
  10842. li_config_table[ch_b_v].flag_table[ch_b] &= ~LI_FLAG_MIX;
  10843. li_config_table[ch_b_s].flag_table[ch_b] &= ~LI_FLAG_MIX;
  10844. li_config_table[ch_b].flag_table[ch_b] &= ~LI_FLAG_PCCONNECT;
  10845. li_config_table[ch_b].chflags &= ~(LI_CHFLAG_MONITOR | LI_CHFLAG_MIX | LI_CHFLAG_LOOP);
  10846. }
  10847. li_config_table[ch_b_v].flag_table[ch_a_v] &= ~(LI_FLAG_INTERCONNECT | LI_FLAG_CONFERENCE);
  10848. li_config_table[ch_b_s].flag_table[ch_a_v] &= ~(LI_FLAG_INTERCONNECT | LI_FLAG_CONFERENCE);
  10849. li_config_table[ch_b_v].flag_table[ch_a_s] &= ~(LI_FLAG_INTERCONNECT | LI_FLAG_CONFERENCE);
  10850. li_config_table[ch_b_s].flag_table[ch_a_s] &= ~(LI_FLAG_INTERCONNECT | LI_FLAG_CONFERENCE);
  10851. li_config_table[ch_a_v].flag_table[ch_b_v] &= ~(LI_FLAG_INTERCONNECT | LI_FLAG_CONFERENCE);
  10852. li_config_table[ch_a_v].flag_table[ch_b_s] &= ~(LI_FLAG_INTERCONNECT | LI_FLAG_CONFERENCE);
  10853. li_config_table[ch_a_s].flag_table[ch_b_v] &= ~(LI_FLAG_INTERCONNECT | LI_FLAG_CONFERENCE);
  10854. li_config_table[ch_a_s].flag_table[ch_b_s] &= ~(LI_FLAG_INTERCONNECT | LI_FLAG_CONFERENCE);
  10855. if (li_flags & LI2_FLAG_INTERCONNECT_A_B)
  10856. {
  10857. li_config_table[ch_b_v].flag_table[ch_a_v] |= LI_FLAG_INTERCONNECT;
  10858. li_config_table[ch_b_s].flag_table[ch_a_v] |= LI_FLAG_INTERCONNECT;
  10859. li_config_table[ch_b_v].flag_table[ch_a_s] |= LI_FLAG_INTERCONNECT;
  10860. li_config_table[ch_b_s].flag_table[ch_a_s] |= LI_FLAG_INTERCONNECT;
  10861. }
  10862. if (li_flags & LI2_FLAG_INTERCONNECT_B_A)
  10863. {
  10864. li_config_table[ch_a_v].flag_table[ch_b_v] |= LI_FLAG_INTERCONNECT;
  10865. li_config_table[ch_a_v].flag_table[ch_b_s] |= LI_FLAG_INTERCONNECT;
  10866. li_config_table[ch_a_s].flag_table[ch_b_v] |= LI_FLAG_INTERCONNECT;
  10867. li_config_table[ch_a_s].flag_table[ch_b_s] |= LI_FLAG_INTERCONNECT;
  10868. }
  10869. if (li_flags & LI2_FLAG_MONITOR_B)
  10870. {
  10871. li_config_table[ch_b].flag_table[ch_b_v] |= LI_FLAG_MONITOR;
  10872. li_config_table[ch_b].flag_table[ch_b_s] |= LI_FLAG_MONITOR;
  10873. }
  10874. if (li_flags & LI2_FLAG_MIX_B)
  10875. {
  10876. li_config_table[ch_b_v].flag_table[ch_b] |= LI_FLAG_MIX;
  10877. li_config_table[ch_b_s].flag_table[ch_b] |= LI_FLAG_MIX;
  10878. }
  10879. if (li_flags & LI2_FLAG_MONITOR_X)
  10880. li_config_table[ch_b].chflags |= LI_CHFLAG_MONITOR;
  10881. if (li_flags & LI2_FLAG_MIX_X)
  10882. li_config_table[ch_b].chflags |= LI_CHFLAG_MIX;
  10883. if (li_flags & LI2_FLAG_LOOP_B)
  10884. {
  10885. li_config_table[ch_b_v].flag_table[ch_b_v] |= LI_FLAG_INTERCONNECT;
  10886. li_config_table[ch_b_s].flag_table[ch_b_v] |= LI_FLAG_INTERCONNECT;
  10887. li_config_table[ch_b_v].flag_table[ch_b_s] |= LI_FLAG_INTERCONNECT;
  10888. li_config_table[ch_b_s].flag_table[ch_b_s] |= LI_FLAG_INTERCONNECT;
  10889. }
  10890. if (li_flags & LI2_FLAG_LOOP_PC)
  10891. li_config_table[ch_b].flag_table[ch_b] |= LI_FLAG_PCCONNECT;
  10892. if (li_flags & LI2_FLAG_LOOP_X)
  10893. li_config_table[ch_b].chflags |= LI_CHFLAG_LOOP;
  10894. if (li_flags & LI2_FLAG_PCCONNECT_A_B)
  10895. li_config_table[ch_b_s].flag_table[ch_a_s] |= LI_FLAG_PCCONNECT;
  10896. if (li_flags & LI2_FLAG_PCCONNECT_B_A)
  10897. li_config_table[ch_a_s].flag_table[ch_b_s] |= LI_FLAG_PCCONNECT;
  10898. if (ch_a_v != ch_a_s)
  10899. {
  10900. li_config_table[ch_a_v].flag_table[ch_a_s] |= LI_FLAG_CONFERENCE;
  10901. li_config_table[ch_a_s].flag_table[ch_a_v] |= LI_FLAG_CONFERENCE;
  10902. }
  10903. if (ch_b_v != ch_b_s)
  10904. {
  10905. li_config_table[ch_b_v].flag_table[ch_b_s] |= LI_FLAG_CONFERENCE;
  10906. li_config_table[ch_b_s].flag_table[ch_b_v] |= LI_FLAG_CONFERENCE;
  10907. }
  10908. }
  10909. static word li_check_main_plci (dword Id, PLCI *plci)
  10910. {
  10911. if (plci == NULL)
  10912. {
  10913. dbug (1, dprintf ("[%06lx] %s,%d: Wrong PLCI",
  10914. UnMapId (Id), (char *)(FILE_), __LINE__));
  10915. return (_WRONG_IDENTIFIER);
  10916. }
  10917. if (!plci->State
  10918. || !plci->NL.Id || plci->nl_remove_id
  10919. || (plci->li_bchannel_id == 0))
  10920. {
  10921. dbug (1, dprintf ("[%06lx] %s,%d: Wrong state",
  10922. UnMapId (Id), (char *)(FILE_), __LINE__));
  10923. return (_WRONG_STATE);
  10924. }
  10925. li_config_table[plci->adapter->li_base + (plci->li_bchannel_id - 1)].plci = plci;
  10926. return (GOOD);
  10927. }
  10928. static PLCI *li_check_plci_b (dword Id, PLCI *plci,
  10929. dword plci_b_id, word plci_b_write_pos, byte *p_result)
  10930. {
  10931. byte ctlr_b;
  10932. PLCI *plci_b;
  10933. if (((plci->li_plci_b_read_pos > plci_b_write_pos) ? plci->li_plci_b_read_pos :
  10934. LI_PLCI_B_QUEUE_ENTRIES + plci->li_plci_b_read_pos) - plci_b_write_pos - 1 < 2)
  10935. {
  10936. dbug (1, dprintf ("[%06lx] %s,%d: LI request overrun",
  10937. UnMapId (Id), (char *)(FILE_), __LINE__));
  10938. PUT_WORD (p_result, _REQUEST_NOT_ALLOWED_IN_THIS_STATE);
  10939. return (NULL);
  10940. }
  10941. ctlr_b = 0;
  10942. if ((plci_b_id & 0x7f) != 0)
  10943. {
  10944. ctlr_b = MapController ((byte)(plci_b_id & 0x7f));
  10945. if ((ctlr_b > max_adapter) || ((ctlr_b != 0) && (adapter[ctlr_b - 1].request == NULL)))
  10946. ctlr_b = 0;
  10947. }
  10948. if ((ctlr_b == 0)
  10949. || (((plci_b_id >> 8) & 0xff) == 0)
  10950. || (((plci_b_id >> 8) & 0xff) > adapter[ctlr_b - 1].max_plci))
  10951. {
  10952. dbug (1, dprintf ("[%06lx] %s,%d: LI invalid second PLCI %08lx",
  10953. UnMapId (Id), (char *)(FILE_), __LINE__, plci_b_id));
  10954. PUT_WORD (p_result, _WRONG_IDENTIFIER);
  10955. return (NULL);
  10956. }
  10957. plci_b = &(adapter[ctlr_b - 1].plci[((plci_b_id >> 8) & 0xff) - 1]);
  10958. if (!plci_b->State
  10959. || !plci_b->NL.Id || plci_b->nl_remove_id
  10960. || (plci_b->li_bchannel_id == 0))
  10961. {
  10962. dbug (1, dprintf ("[%06lx] %s,%d: LI peer in wrong state %08lx",
  10963. UnMapId (Id), (char *)(FILE_), __LINE__, plci_b_id));
  10964. PUT_WORD (p_result, _REQUEST_NOT_ALLOWED_IN_THIS_STATE);
  10965. return (NULL);
  10966. }
  10967. li_config_table[plci_b->adapter->li_base + (plci_b->li_bchannel_id - 1)].plci = plci_b;
  10968. if (((byte)(plci_b_id & ~EXT_CONTROLLER)) !=
  10969. ((byte)(UnMapController (plci->adapter->Id) & ~EXT_CONTROLLER))
  10970. && (!(plci->adapter->manufacturer_features & MANUFACTURER_FEATURE_XCONNECT)
  10971. || !(plci_b->adapter->manufacturer_features & MANUFACTURER_FEATURE_XCONNECT)))
  10972. {
  10973. dbug (1, dprintf ("[%06lx] %s,%d: LI not on same ctrl %08lx",
  10974. UnMapId (Id), (char *)(FILE_), __LINE__, plci_b_id));
  10975. PUT_WORD (p_result, _WRONG_IDENTIFIER);
  10976. return (NULL);
  10977. }
  10978. if (!(get_b1_facilities (plci_b, add_b1_facilities (plci_b, plci_b->B1_resource,
  10979. (word)(plci_b->B1_facilities | B1_FACILITY_MIXER))) & B1_FACILITY_MIXER))
  10980. {
  10981. dbug (1, dprintf ("[%06lx] %s,%d: Interconnect peer cannot mix %d",
  10982. UnMapId (Id), (char *)(FILE_), __LINE__, plci_b->B1_resource));
  10983. PUT_WORD (p_result, _REQUEST_NOT_ALLOWED_IN_THIS_STATE);
  10984. return (NULL);
  10985. }
  10986. return (plci_b);
  10987. }
  10988. static PLCI *li2_check_plci_b (dword Id, PLCI *plci,
  10989. dword plci_b_id, word plci_b_write_pos, byte *p_result)
  10990. {
  10991. byte ctlr_b;
  10992. PLCI *plci_b;
  10993. if (((plci->li_plci_b_read_pos > plci_b_write_pos) ? plci->li_plci_b_read_pos :
  10994. LI_PLCI_B_QUEUE_ENTRIES + plci->li_plci_b_read_pos) - plci_b_write_pos - 1 < 2)
  10995. {
  10996. dbug (1, dprintf ("[%06lx] %s,%d: LI request overrun",
  10997. UnMapId (Id), (char *)(FILE_), __LINE__));
  10998. PUT_WORD (p_result, _WRONG_STATE);
  10999. return (NULL);
  11000. }
  11001. ctlr_b = 0;
  11002. if ((plci_b_id & 0x7f) != 0)
  11003. {
  11004. ctlr_b = MapController ((byte)(plci_b_id & 0x7f));
  11005. if ((ctlr_b > max_adapter) || ((ctlr_b != 0) && (adapter[ctlr_b - 1].request == NULL)))
  11006. ctlr_b = 0;
  11007. }
  11008. if ((ctlr_b == 0)
  11009. || (((plci_b_id >> 8) & 0xff) == 0)
  11010. || (((plci_b_id >> 8) & 0xff) > adapter[ctlr_b - 1].max_plci))
  11011. {
  11012. dbug (1, dprintf ("[%06lx] %s,%d: LI invalid second PLCI %08lx",
  11013. UnMapId (Id), (char *)(FILE_), __LINE__, plci_b_id));
  11014. PUT_WORD (p_result, _WRONG_IDENTIFIER);
  11015. return (NULL);
  11016. }
  11017. plci_b = &(adapter[ctlr_b - 1].plci[((plci_b_id >> 8) & 0xff) - 1]);
  11018. if (!plci_b->State
  11019. || !plci_b->NL.Id || plci_b->nl_remove_id
  11020. || (plci_b->li_bchannel_id == 0)
  11021. || (li_config_table[plci_b->adapter->li_base + (plci_b->li_bchannel_id - 1)].plci != plci_b))
  11022. {
  11023. dbug (1, dprintf ("[%06lx] %s,%d: LI peer in wrong state %08lx",
  11024. UnMapId (Id), (char *)(FILE_), __LINE__, plci_b_id));
  11025. PUT_WORD (p_result, _WRONG_STATE);
  11026. return (NULL);
  11027. }
  11028. if (((byte)(plci_b_id & ~EXT_CONTROLLER)) !=
  11029. ((byte)(UnMapController (plci->adapter->Id) & ~EXT_CONTROLLER))
  11030. && (!(plci->adapter->manufacturer_features & MANUFACTURER_FEATURE_XCONNECT)
  11031. || !(plci_b->adapter->manufacturer_features & MANUFACTURER_FEATURE_XCONNECT)))
  11032. {
  11033. dbug (1, dprintf ("[%06lx] %s,%d: LI not on same ctrl %08lx",
  11034. UnMapId (Id), (char *)(FILE_), __LINE__, plci_b_id));
  11035. PUT_WORD (p_result, _WRONG_IDENTIFIER);
  11036. return (NULL);
  11037. }
  11038. if (!(get_b1_facilities (plci_b, add_b1_facilities (plci_b, plci_b->B1_resource,
  11039. (word)(plci_b->B1_facilities | B1_FACILITY_MIXER))) & B1_FACILITY_MIXER))
  11040. {
  11041. dbug (1, dprintf ("[%06lx] %s,%d: Interconnect peer cannot mix %d",
  11042. UnMapId (Id), (char *)(FILE_), __LINE__, plci_b->B1_resource));
  11043. PUT_WORD (p_result, _WRONG_STATE);
  11044. return (NULL);
  11045. }
  11046. return (plci_b);
  11047. }
  11048. static byte mixer_request (dword Id, word Number, DIVA_CAPI_ADAPTER *a, PLCI *plci, APPL *appl, API_PARSE *msg)
  11049. {
  11050. word Info;
  11051. word i;
  11052. dword d, li_flags, plci_b_id;
  11053. PLCI *plci_b;
  11054. API_PARSE li_parms[3];
  11055. API_PARSE li_req_parms[3];
  11056. API_PARSE li_participant_struct[2];
  11057. API_PARSE li_participant_parms[3];
  11058. word participant_parms_pos;
  11059. byte result_buffer[32];
  11060. byte *result;
  11061. word result_pos;
  11062. word plci_b_write_pos;
  11063. dbug (1, dprintf ("[%06lx] %s,%d: mixer_request",
  11064. UnMapId (Id), (char *)(FILE_), __LINE__));
  11065. Info = GOOD;
  11066. result = result_buffer;
  11067. result_buffer[0] = 0;
  11068. if (!(a->profile.Global_Options & GL_LINE_INTERCONNECT_SUPPORTED))
  11069. {
  11070. dbug (1, dprintf ("[%06lx] %s,%d: Facility not supported",
  11071. UnMapId (Id), (char *)(FILE_), __LINE__));
  11072. Info = _FACILITY_NOT_SUPPORTED;
  11073. }
  11074. else if (api_parse (&msg[1].info[1], msg[1].length, "ws", li_parms))
  11075. {
  11076. dbug (1, dprintf ("[%06lx] %s,%d: Wrong message format",
  11077. UnMapId (Id), (char *)(FILE_), __LINE__));
  11078. Info = _WRONG_MESSAGE_FORMAT;
  11079. }
  11080. else
  11081. {
  11082. result_buffer[0] = 3;
  11083. PUT_WORD (&result_buffer[1], GET_WORD (li_parms[0].info));
  11084. result_buffer[3] = 0;
  11085. switch (GET_WORD (li_parms[0].info))
  11086. {
  11087. case LI_GET_SUPPORTED_SERVICES:
  11088. if (appl->appl_flags & APPL_FLAG_OLD_LI_SPEC)
  11089. {
  11090. result_buffer[0] = 17;
  11091. result_buffer[3] = 14;
  11092. PUT_WORD (&result_buffer[4], GOOD);
  11093. d = 0;
  11094. if (a->manufacturer_features & MANUFACTURER_FEATURE_MIXER_CH_CH)
  11095. d |= LI_CONFERENCING_SUPPORTED;
  11096. if (a->manufacturer_features & MANUFACTURER_FEATURE_MIXER_CH_PC)
  11097. d |= LI_MONITORING_SUPPORTED;
  11098. if (a->manufacturer_features & MANUFACTURER_FEATURE_MIXER_PC_CH)
  11099. d |= LI_ANNOUNCEMENTS_SUPPORTED | LI_MIXING_SUPPORTED;
  11100. if (a->manufacturer_features & MANUFACTURER_FEATURE_XCONNECT)
  11101. d |= LI_CROSS_CONTROLLER_SUPPORTED;
  11102. PUT_DWORD (&result_buffer[6], d);
  11103. if (a->manufacturer_features & MANUFACTURER_FEATURE_XCONNECT)
  11104. {
  11105. d = 0;
  11106. for (i = 0; i < li_total_channels; i++)
  11107. {
  11108. if ((li_config_table[i].adapter->manufacturer_features & MANUFACTURER_FEATURE_XCONNECT)
  11109. && (li_config_table[i].adapter->li_pri
  11110. || (i < li_config_table[i].adapter->li_base + MIXER_BCHANNELS_BRI)))
  11111. {
  11112. d++;
  11113. }
  11114. }
  11115. }
  11116. else
  11117. {
  11118. d = a->li_pri ? a->li_channels : MIXER_BCHANNELS_BRI;
  11119. }
  11120. PUT_DWORD (&result_buffer[10], d / 2);
  11121. PUT_DWORD (&result_buffer[14], d);
  11122. }
  11123. else
  11124. {
  11125. result_buffer[0] = 25;
  11126. result_buffer[3] = 22;
  11127. PUT_WORD (&result_buffer[4], GOOD);
  11128. d = LI2_ASYMMETRIC_SUPPORTED | LI2_B_LOOPING_SUPPORTED | LI2_X_LOOPING_SUPPORTED;
  11129. if (a->manufacturer_features & MANUFACTURER_FEATURE_MIXER_CH_PC)
  11130. d |= LI2_MONITORING_SUPPORTED | LI2_REMOTE_MONITORING_SUPPORTED;
  11131. if (a->manufacturer_features & MANUFACTURER_FEATURE_MIXER_PC_CH)
  11132. d |= LI2_MIXING_SUPPORTED | LI2_REMOTE_MIXING_SUPPORTED;
  11133. if (a->manufacturer_features & MANUFACTURER_FEATURE_MIXER_PC_PC)
  11134. d |= LI2_PC_LOOPING_SUPPORTED;
  11135. if (a->manufacturer_features & MANUFACTURER_FEATURE_XCONNECT)
  11136. d |= LI2_CROSS_CONTROLLER_SUPPORTED;
  11137. PUT_DWORD (&result_buffer[6], d);
  11138. d = a->li_pri ? a->li_channels : MIXER_BCHANNELS_BRI;
  11139. PUT_DWORD (&result_buffer[10], d / 2);
  11140. PUT_DWORD (&result_buffer[14], d - 1);
  11141. if (a->manufacturer_features & MANUFACTURER_FEATURE_XCONNECT)
  11142. {
  11143. d = 0;
  11144. for (i = 0; i < li_total_channels; i++)
  11145. {
  11146. if ((li_config_table[i].adapter->manufacturer_features & MANUFACTURER_FEATURE_XCONNECT)
  11147. && (li_config_table[i].adapter->li_pri
  11148. || (i < li_config_table[i].adapter->li_base + MIXER_BCHANNELS_BRI)))
  11149. {
  11150. d++;
  11151. }
  11152. }
  11153. }
  11154. PUT_DWORD (&result_buffer[18], d / 2);
  11155. PUT_DWORD (&result_buffer[22], d - 1);
  11156. }
  11157. break;
  11158. case LI_REQ_CONNECT:
  11159. if (li_parms[1].length == 8)
  11160. {
  11161. appl->appl_flags |= APPL_FLAG_OLD_LI_SPEC;
  11162. if (api_parse (&li_parms[1].info[1], li_parms[1].length, "dd", li_req_parms))
  11163. {
  11164. dbug (1, dprintf ("[%06lx] %s,%d: Wrong message format",
  11165. UnMapId (Id), (char *)(FILE_), __LINE__));
  11166. Info = _WRONG_MESSAGE_FORMAT;
  11167. break;
  11168. }
  11169. plci_b_id = GET_DWORD (li_req_parms[0].info) & 0xffff;
  11170. li_flags = GET_DWORD (li_req_parms[1].info);
  11171. Info = li_check_main_plci (Id, plci);
  11172. result_buffer[0] = 9;
  11173. result_buffer[3] = 6;
  11174. PUT_DWORD (&result_buffer[4], plci_b_id);
  11175. PUT_WORD (&result_buffer[8], GOOD);
  11176. if (Info != GOOD)
  11177. break;
  11178. result = plci->saved_msg.info;
  11179. for (i = 0; i <= result_buffer[0]; i++)
  11180. result[i] = result_buffer[i];
  11181. plci_b_write_pos = plci->li_plci_b_write_pos;
  11182. plci_b = li_check_plci_b (Id, plci, plci_b_id, plci_b_write_pos, &result[8]);
  11183. if (plci_b == NULL)
  11184. break;
  11185. li_update_connect (Id, a, plci, plci_b_id, TRUE, li_flags);
  11186. plci->li_plci_b_queue[plci_b_write_pos] = plci_b_id | LI_PLCI_B_LAST_FLAG;
  11187. plci_b_write_pos = (plci_b_write_pos == LI_PLCI_B_QUEUE_ENTRIES-1) ? 0 : plci_b_write_pos + 1;
  11188. plci->li_plci_b_write_pos = plci_b_write_pos;
  11189. }
  11190. else
  11191. {
  11192. appl->appl_flags &= ~APPL_FLAG_OLD_LI_SPEC;
  11193. if (api_parse (&li_parms[1].info[1], li_parms[1].length, "ds", li_req_parms))
  11194. {
  11195. dbug (1, dprintf ("[%06lx] %s,%d: Wrong message format",
  11196. UnMapId (Id), (char *)(FILE_), __LINE__));
  11197. Info = _WRONG_MESSAGE_FORMAT;
  11198. break;
  11199. }
  11200. li_flags = GET_DWORD (li_req_parms[0].info) & ~(LI2_FLAG_INTERCONNECT_A_B | LI2_FLAG_INTERCONNECT_B_A);
  11201. Info = li_check_main_plci (Id, plci);
  11202. result_buffer[0] = 7;
  11203. result_buffer[3] = 4;
  11204. PUT_WORD (&result_buffer[4], Info);
  11205. result_buffer[6] = 0;
  11206. if (Info != GOOD)
  11207. break;
  11208. result = plci->saved_msg.info;
  11209. for (i = 0; i <= result_buffer[0]; i++)
  11210. result[i] = result_buffer[i];
  11211. plci_b_write_pos = plci->li_plci_b_write_pos;
  11212. participant_parms_pos = 0;
  11213. result_pos = 7;
  11214. li2_update_connect (Id, a, plci, UnMapId (Id), TRUE, li_flags);
  11215. while (participant_parms_pos < li_req_parms[1].length)
  11216. {
  11217. result[result_pos] = 6;
  11218. result_pos += 7;
  11219. PUT_DWORD (&result[result_pos - 6], 0);
  11220. PUT_WORD (&result[result_pos - 2], GOOD);
  11221. if (api_parse (&li_req_parms[1].info[1 + participant_parms_pos],
  11222. (word)(li_parms[1].length - participant_parms_pos), "s", li_participant_struct))
  11223. {
  11224. dbug (1, dprintf ("[%06lx] %s,%d: Wrong message format",
  11225. UnMapId (Id), (char *)(FILE_), __LINE__));
  11226. PUT_WORD (&result[result_pos - 2], _WRONG_MESSAGE_FORMAT);
  11227. break;
  11228. }
  11229. if (api_parse (&li_participant_struct[0].info[1],
  11230. li_participant_struct[0].length, "dd", li_participant_parms))
  11231. {
  11232. dbug (1, dprintf ("[%06lx] %s,%d: Wrong message format",
  11233. UnMapId (Id), (char *)(FILE_), __LINE__));
  11234. PUT_WORD (&result[result_pos - 2], _WRONG_MESSAGE_FORMAT);
  11235. break;
  11236. }
  11237. plci_b_id = GET_DWORD (li_participant_parms[0].info) & 0xffff;
  11238. li_flags = GET_DWORD (li_participant_parms[1].info);
  11239. PUT_DWORD (&result[result_pos - 6], plci_b_id);
  11240. if (sizeof(result) - result_pos < 7)
  11241. {
  11242. dbug (1, dprintf ("[%06lx] %s,%d: LI result overrun",
  11243. UnMapId (Id), (char *)(FILE_), __LINE__));
  11244. PUT_WORD (&result[result_pos - 2], _WRONG_STATE);
  11245. break;
  11246. }
  11247. plci_b = li2_check_plci_b (Id, plci, plci_b_id, plci_b_write_pos, &result[result_pos - 2]);
  11248. if (plci_b != NULL)
  11249. {
  11250. li2_update_connect (Id, a, plci, plci_b_id, TRUE, li_flags);
  11251. plci->li_plci_b_queue[plci_b_write_pos] = plci_b_id |
  11252. ((li_flags & (LI2_FLAG_INTERCONNECT_A_B | LI2_FLAG_INTERCONNECT_B_A |
  11253. LI2_FLAG_PCCONNECT_A_B | LI2_FLAG_PCCONNECT_B_A)) ? 0 : LI_PLCI_B_DISC_FLAG);
  11254. plci_b_write_pos = (plci_b_write_pos == LI_PLCI_B_QUEUE_ENTRIES-1) ? 0 : plci_b_write_pos + 1;
  11255. }
  11256. participant_parms_pos = (word)((&li_participant_struct[0].info[1 + li_participant_struct[0].length]) -
  11257. (&li_req_parms[1].info[1]));
  11258. }
  11259. result[0] = (byte)(result_pos - 1);
  11260. result[3] = (byte)(result_pos - 4);
  11261. result[6] = (byte)(result_pos - 7);
  11262. i = (plci_b_write_pos == 0) ? LI_PLCI_B_QUEUE_ENTRIES-1 : plci_b_write_pos - 1;
  11263. if ((plci_b_write_pos == plci->li_plci_b_read_pos)
  11264. || (plci->li_plci_b_queue[i] & LI_PLCI_B_LAST_FLAG))
  11265. {
  11266. plci->li_plci_b_queue[plci_b_write_pos] = LI_PLCI_B_SKIP_FLAG | LI_PLCI_B_LAST_FLAG;
  11267. plci_b_write_pos = (plci_b_write_pos == LI_PLCI_B_QUEUE_ENTRIES-1) ? 0 : plci_b_write_pos + 1;
  11268. }
  11269. else
  11270. plci->li_plci_b_queue[i] |= LI_PLCI_B_LAST_FLAG;
  11271. plci->li_plci_b_write_pos = plci_b_write_pos;
  11272. }
  11273. mixer_calculate_coefs (a);
  11274. plci->li_channel_bits = li_config_table[a->li_base + (plci->li_bchannel_id - 1)].channel;
  11275. mixer_notify_update (plci, TRUE);
  11276. sendf (appl, _FACILITY_R | CONFIRM, Id & 0xffffL, Number,
  11277. "wwS", Info, SELECTOR_LINE_INTERCONNECT, result);
  11278. plci->command = 0;
  11279. plci->li_cmd = GET_WORD (li_parms[0].info);
  11280. start_internal_command (Id, plci, mixer_command);
  11281. return (FALSE);
  11282. case LI_REQ_DISCONNECT:
  11283. if (li_parms[1].length == 4)
  11284. {
  11285. appl->appl_flags |= APPL_FLAG_OLD_LI_SPEC;
  11286. if (api_parse (&li_parms[1].info[1], li_parms[1].length, "d", li_req_parms))
  11287. {
  11288. dbug (1, dprintf ("[%06lx] %s,%d: Wrong message format",
  11289. UnMapId (Id), (char *)(FILE_), __LINE__));
  11290. Info = _WRONG_MESSAGE_FORMAT;
  11291. break;
  11292. }
  11293. plci_b_id = GET_DWORD (li_req_parms[0].info) & 0xffff;
  11294. Info = li_check_main_plci (Id, plci);
  11295. result_buffer[0] = 9;
  11296. result_buffer[3] = 6;
  11297. PUT_DWORD (&result_buffer[4], GET_DWORD (li_req_parms[0].info));
  11298. PUT_WORD (&result_buffer[8], GOOD);
  11299. if (Info != GOOD)
  11300. break;
  11301. result = plci->saved_msg.info;
  11302. for (i = 0; i <= result_buffer[0]; i++)
  11303. result[i] = result_buffer[i];
  11304. plci_b_write_pos = plci->li_plci_b_write_pos;
  11305. plci_b = li_check_plci_b (Id, plci, plci_b_id, plci_b_write_pos, &result[8]);
  11306. if (plci_b == NULL)
  11307. break;
  11308. li_update_connect (Id, a, plci, plci_b_id, FALSE, 0);
  11309. plci->li_plci_b_queue[plci_b_write_pos] = plci_b_id | LI_PLCI_B_DISC_FLAG | LI_PLCI_B_LAST_FLAG;
  11310. plci_b_write_pos = (plci_b_write_pos == LI_PLCI_B_QUEUE_ENTRIES-1) ? 0 : plci_b_write_pos + 1;
  11311. plci->li_plci_b_write_pos = plci_b_write_pos;
  11312. }
  11313. else
  11314. {
  11315. appl->appl_flags &= ~APPL_FLAG_OLD_LI_SPEC;
  11316. if (api_parse (&li_parms[1].info[1], li_parms[1].length, "s", li_req_parms))
  11317. {
  11318. dbug (1, dprintf ("[%06lx] %s,%d: Wrong message format",
  11319. UnMapId (Id), (char *)(FILE_), __LINE__));
  11320. Info = _WRONG_MESSAGE_FORMAT;
  11321. break;
  11322. }
  11323. Info = li_check_main_plci (Id, plci);
  11324. result_buffer[0] = 7;
  11325. result_buffer[3] = 4;
  11326. PUT_WORD (&result_buffer[4], Info);
  11327. result_buffer[6] = 0;
  11328. if (Info != GOOD)
  11329. break;
  11330. result = plci->saved_msg.info;
  11331. for (i = 0; i <= result_buffer[0]; i++)
  11332. result[i] = result_buffer[i];
  11333. plci_b_write_pos = plci->li_plci_b_write_pos;
  11334. participant_parms_pos = 0;
  11335. result_pos = 7;
  11336. while (participant_parms_pos < li_req_parms[0].length)
  11337. {
  11338. result[result_pos] = 6;
  11339. result_pos += 7;
  11340. PUT_DWORD (&result[result_pos - 6], 0);
  11341. PUT_WORD (&result[result_pos - 2], GOOD);
  11342. if (api_parse (&li_req_parms[0].info[1 + participant_parms_pos],
  11343. (word)(li_parms[1].length - participant_parms_pos), "s", li_participant_struct))
  11344. {
  11345. dbug (1, dprintf ("[%06lx] %s,%d: Wrong message format",
  11346. UnMapId (Id), (char *)(FILE_), __LINE__));
  11347. PUT_WORD (&result[result_pos - 2], _WRONG_MESSAGE_FORMAT);
  11348. break;
  11349. }
  11350. if (api_parse (&li_participant_struct[0].info[1],
  11351. li_participant_struct[0].length, "d", li_participant_parms))
  11352. {
  11353. dbug (1, dprintf ("[%06lx] %s,%d: Wrong message format",
  11354. UnMapId (Id), (char *)(FILE_), __LINE__));
  11355. PUT_WORD (&result[result_pos - 2], _WRONG_MESSAGE_FORMAT);
  11356. break;
  11357. }
  11358. plci_b_id = GET_DWORD (li_participant_parms[0].info) & 0xffff;
  11359. PUT_DWORD (&result[result_pos - 6], plci_b_id);
  11360. if (sizeof(result) - result_pos < 7)
  11361. {
  11362. dbug (1, dprintf ("[%06lx] %s,%d: LI result overrun",
  11363. UnMapId (Id), (char *)(FILE_), __LINE__));
  11364. PUT_WORD (&result[result_pos - 2], _WRONG_STATE);
  11365. break;
  11366. }
  11367. plci_b = li2_check_plci_b (Id, plci, plci_b_id, plci_b_write_pos, &result[result_pos - 2]);
  11368. if (plci_b != NULL)
  11369. {
  11370. li2_update_connect (Id, a, plci, plci_b_id, FALSE, 0);
  11371. plci->li_plci_b_queue[plci_b_write_pos] = plci_b_id | LI_PLCI_B_DISC_FLAG;
  11372. plci_b_write_pos = (plci_b_write_pos == LI_PLCI_B_QUEUE_ENTRIES-1) ? 0 : plci_b_write_pos + 1;
  11373. }
  11374. participant_parms_pos = (word)((&li_participant_struct[0].info[1 + li_participant_struct[0].length]) -
  11375. (&li_req_parms[0].info[1]));
  11376. }
  11377. result[0] = (byte)(result_pos - 1);
  11378. result[3] = (byte)(result_pos - 4);
  11379. result[6] = (byte)(result_pos - 7);
  11380. i = (plci_b_write_pos == 0) ? LI_PLCI_B_QUEUE_ENTRIES-1 : plci_b_write_pos - 1;
  11381. if ((plci_b_write_pos == plci->li_plci_b_read_pos)
  11382. || (plci->li_plci_b_queue[i] & LI_PLCI_B_LAST_FLAG))
  11383. {
  11384. plci->li_plci_b_queue[plci_b_write_pos] = LI_PLCI_B_SKIP_FLAG | LI_PLCI_B_LAST_FLAG;
  11385. plci_b_write_pos = (plci_b_write_pos == LI_PLCI_B_QUEUE_ENTRIES-1) ? 0 : plci_b_write_pos + 1;
  11386. }
  11387. else
  11388. plci->li_plci_b_queue[i] |= LI_PLCI_B_LAST_FLAG;
  11389. plci->li_plci_b_write_pos = plci_b_write_pos;
  11390. }
  11391. mixer_calculate_coefs (a);
  11392. plci->li_channel_bits = li_config_table[a->li_base + (plci->li_bchannel_id - 1)].channel;
  11393. mixer_notify_update (plci, TRUE);
  11394. sendf (appl, _FACILITY_R | CONFIRM, Id & 0xffffL, Number,
  11395. "wwS", Info, SELECTOR_LINE_INTERCONNECT, result);
  11396. plci->command = 0;
  11397. plci->li_cmd = GET_WORD (li_parms[0].info);
  11398. start_internal_command (Id, plci, mixer_command);
  11399. return (FALSE);
  11400. case LI_REQ_SILENT_UPDATE:
  11401. if (!plci || !plci->State
  11402. || !plci->NL.Id || plci->nl_remove_id
  11403. || (plci->li_bchannel_id == 0)
  11404. || (li_config_table[plci->adapter->li_base + (plci->li_bchannel_id - 1)].plci != plci))
  11405. {
  11406. dbug (1, dprintf ("[%06lx] %s,%d: Wrong state",
  11407. UnMapId (Id), (char *)(FILE_), __LINE__));
  11408. return (FALSE);
  11409. }
  11410. plci_b_write_pos = plci->li_plci_b_write_pos;
  11411. if (((plci->li_plci_b_read_pos > plci_b_write_pos) ? plci->li_plci_b_read_pos :
  11412. LI_PLCI_B_QUEUE_ENTRIES + plci->li_plci_b_read_pos) - plci_b_write_pos - 1 < 2)
  11413. {
  11414. dbug (1, dprintf ("[%06lx] %s,%d: LI request overrun",
  11415. UnMapId (Id), (char *)(FILE_), __LINE__));
  11416. return (FALSE);
  11417. }
  11418. i = (plci_b_write_pos == 0) ? LI_PLCI_B_QUEUE_ENTRIES-1 : plci_b_write_pos - 1;
  11419. if ((plci_b_write_pos == plci->li_plci_b_read_pos)
  11420. || (plci->li_plci_b_queue[i] & LI_PLCI_B_LAST_FLAG))
  11421. {
  11422. plci->li_plci_b_queue[plci_b_write_pos] = LI_PLCI_B_SKIP_FLAG | LI_PLCI_B_LAST_FLAG;
  11423. plci_b_write_pos = (plci_b_write_pos == LI_PLCI_B_QUEUE_ENTRIES-1) ? 0 : plci_b_write_pos + 1;
  11424. }
  11425. else
  11426. plci->li_plci_b_queue[i] |= LI_PLCI_B_LAST_FLAG;
  11427. plci->li_plci_b_write_pos = plci_b_write_pos;
  11428. plci->li_channel_bits = li_config_table[a->li_base + (plci->li_bchannel_id - 1)].channel;
  11429. plci->command = 0;
  11430. plci->li_cmd = GET_WORD (li_parms[0].info);
  11431. start_internal_command (Id, plci, mixer_command);
  11432. return (FALSE);
  11433. default:
  11434. dbug (1, dprintf ("[%06lx] %s,%d: LI unknown request %04x",
  11435. UnMapId (Id), (char *)(FILE_), __LINE__, GET_WORD (li_parms[0].info)));
  11436. Info = _FACILITY_NOT_SUPPORTED;
  11437. }
  11438. }
  11439. sendf (appl, _FACILITY_R | CONFIRM, Id & 0xffffL, Number,
  11440. "wwS", Info, SELECTOR_LINE_INTERCONNECT, result);
  11441. return (FALSE);
  11442. }
  11443. static void mixer_indication_coefs_set (dword Id, PLCI *plci)
  11444. {
  11445. dword d;
  11446. DIVA_CAPI_ADAPTER *a;
  11447. byte result[12];
  11448. dbug (1, dprintf ("[%06lx] %s,%d: mixer_indication_coefs_set",
  11449. UnMapId (Id), (char *)(FILE_), __LINE__));
  11450. a = plci->adapter;
  11451. if (plci->li_plci_b_read_pos != plci->li_plci_b_req_pos)
  11452. {
  11453. do
  11454. {
  11455. d = plci->li_plci_b_queue[plci->li_plci_b_read_pos];
  11456. if (!(d & LI_PLCI_B_SKIP_FLAG))
  11457. {
  11458. if (plci->appl->appl_flags & APPL_FLAG_OLD_LI_SPEC)
  11459. {
  11460. if (d & LI_PLCI_B_DISC_FLAG)
  11461. {
  11462. result[0] = 5;
  11463. PUT_WORD (&result[1], LI_IND_DISCONNECT);
  11464. result[3] = 2;
  11465. PUT_WORD (&result[4], _LI_USER_INITIATED);
  11466. }
  11467. else
  11468. {
  11469. result[0] = 7;
  11470. PUT_WORD (&result[1], LI_IND_CONNECT_ACTIVE);
  11471. result[3] = 4;
  11472. PUT_DWORD (&result[4], d & ~LI_PLCI_B_FLAG_MASK);
  11473. }
  11474. }
  11475. else
  11476. {
  11477. if (d & LI_PLCI_B_DISC_FLAG)
  11478. {
  11479. result[0] = 9;
  11480. PUT_WORD (&result[1], LI_IND_DISCONNECT);
  11481. result[3] = 6;
  11482. PUT_DWORD (&result[4], d & ~LI_PLCI_B_FLAG_MASK);
  11483. PUT_WORD (&result[8], _LI_USER_INITIATED);
  11484. }
  11485. else
  11486. {
  11487. result[0] = 7;
  11488. PUT_WORD (&result[1], LI_IND_CONNECT_ACTIVE);
  11489. result[3] = 4;
  11490. PUT_DWORD (&result[4], d & ~LI_PLCI_B_FLAG_MASK);
  11491. }
  11492. }
  11493. sendf (plci->appl, _FACILITY_I, Id & 0xffffL, 0,
  11494. "ws", SELECTOR_LINE_INTERCONNECT, result);
  11495. }
  11496. plci->li_plci_b_read_pos = (plci->li_plci_b_read_pos == LI_PLCI_B_QUEUE_ENTRIES-1) ?
  11497. 0 : plci->li_plci_b_read_pos + 1;
  11498. } while (!(d & LI_PLCI_B_LAST_FLAG) && (plci->li_plci_b_read_pos != plci->li_plci_b_req_pos));
  11499. }
  11500. }
  11501. static void mixer_indication_xconnect_from (dword Id, PLCI *plci, byte *msg, word length)
  11502. {
  11503. word i, j, ch;
  11504. struct xconnect_transfer_address_s s, *p;
  11505. DIVA_CAPI_ADAPTER *a;
  11506. dbug (1, dprintf ("[%06lx] %s,%d: mixer_indication_xconnect_from %d",
  11507. UnMapId (Id), (char *)(FILE_), __LINE__, (int) length));
  11508. a = plci->adapter;
  11509. i = 1;
  11510. for (i = 1; i < length; i += 16)
  11511. {
  11512. s.card_address.low = msg[i] | (msg[i+1] << 8) | (((dword)(msg[i+2])) << 16) | (((dword)(msg[i+3])) << 24);
  11513. s.card_address.high = msg[i+4] | (msg[i+5] << 8) | (((dword)(msg[i+6])) << 16) | (((dword)(msg[i+7])) << 24);
  11514. s.offset = msg[i+8] | (msg[i+9] << 8) | (((dword)(msg[i+10])) << 16) | (((dword)(msg[i+11])) << 24);
  11515. ch = msg[i+12] | (msg[i+13] << 8);
  11516. j = ch & XCONNECT_CHANNEL_NUMBER_MASK;
  11517. if (!a->li_pri && (plci->li_bchannel_id == 2))
  11518. j = 1 - j;
  11519. j += a->li_base;
  11520. if (ch & XCONNECT_CHANNEL_PORT_PC)
  11521. p = &(li_config_table[j].send_pc);
  11522. else
  11523. p = &(li_config_table[j].send_b);
  11524. p->card_address.low = s.card_address.low;
  11525. p->card_address.high = s.card_address.high;
  11526. p->offset = s.offset;
  11527. li_config_table[j].channel |= LI_CHANNEL_ADDRESSES_SET;
  11528. }
  11529. if (plci->internal_command_queue[0]
  11530. && ((plci->adjust_b_state == ADJUST_B_RESTORE_MIXER_2)
  11531. || (plci->adjust_b_state == ADJUST_B_RESTORE_MIXER_3)
  11532. || (plci->adjust_b_state == ADJUST_B_RESTORE_MIXER_4)))
  11533. {
  11534. (*(plci->internal_command_queue[0]))(Id, plci, 0);
  11535. if (!plci->internal_command)
  11536. next_internal_command (Id, plci);
  11537. }
  11538. mixer_notify_update (plci, TRUE);
  11539. }
  11540. static void mixer_indication_xconnect_to (dword Id, PLCI *plci, byte *msg, word length)
  11541. {
  11542. dbug (1, dprintf ("[%06lx] %s,%d: mixer_indication_xconnect_to %d",
  11543. UnMapId (Id), (char *)(FILE_), __LINE__, (int) length));
  11544. }
  11545. static byte mixer_notify_source_removed (PLCI *plci, dword plci_b_id)
  11546. {
  11547. word plci_b_write_pos;
  11548. plci_b_write_pos = plci->li_plci_b_write_pos;
  11549. if (((plci->li_plci_b_read_pos > plci_b_write_pos) ? plci->li_plci_b_read_pos :
  11550. LI_PLCI_B_QUEUE_ENTRIES + plci->li_plci_b_read_pos) - plci_b_write_pos - 1 < 1)
  11551. {
  11552. dbug (1, dprintf ("[%06lx] %s,%d: LI request overrun",
  11553. (dword)((plci->Id << 8) | UnMapController (plci->adapter->Id)),
  11554. (char *)(FILE_), __LINE__));
  11555. return (FALSE);
  11556. }
  11557. plci->li_plci_b_queue[plci_b_write_pos] = plci_b_id | LI_PLCI_B_DISC_FLAG;
  11558. plci_b_write_pos = (plci_b_write_pos == LI_PLCI_B_QUEUE_ENTRIES-1) ? 0 : plci_b_write_pos + 1;
  11559. plci->li_plci_b_write_pos = plci_b_write_pos;
  11560. return (TRUE);
  11561. }
  11562. static void mixer_remove (PLCI *plci)
  11563. {
  11564. DIVA_CAPI_ADAPTER *a;
  11565. PLCI *notify_plci;
  11566. dword plci_b_id;
  11567. word i, j;
  11568. dbug (1, dprintf ("[%06lx] %s,%d: mixer_remove",
  11569. (dword)((plci->Id << 8) | UnMapController (plci->adapter->Id)),
  11570. (char *)(FILE_), __LINE__));
  11571. a = plci->adapter;
  11572. plci_b_id = (plci->Id << 8) | UnMapController (plci->adapter->Id);
  11573. if (a->profile.Global_Options & GL_LINE_INTERCONNECT_SUPPORTED)
  11574. {
  11575. if ((plci->li_bchannel_id != 0)
  11576. && (li_config_table[a->li_base + (plci->li_bchannel_id - 1)].plci == plci))
  11577. {
  11578. i = a->li_base + (plci->li_bchannel_id - 1);
  11579. if ((li_config_table[i].curchnl | li_config_table[i].channel) & LI_CHANNEL_INVOLVED)
  11580. {
  11581. for (j = 0; j < li_total_channels; j++)
  11582. {
  11583. if ((li_config_table[i].flag_table[j] & LI_FLAG_INTERCONNECT)
  11584. || (li_config_table[j].flag_table[i] & LI_FLAG_INTERCONNECT))
  11585. {
  11586. notify_plci = li_config_table[j].plci;
  11587. if ((notify_plci != NULL)
  11588. && (notify_plci != plci)
  11589. && (notify_plci->appl != NULL)
  11590. && !(notify_plci->appl->appl_flags & APPL_FLAG_OLD_LI_SPEC)
  11591. && (notify_plci->State)
  11592. && notify_plci->NL.Id && !notify_plci->nl_remove_id)
  11593. {
  11594. mixer_notify_source_removed (notify_plci, plci_b_id);
  11595. }
  11596. }
  11597. }
  11598. mixer_clear_config (plci);
  11599. mixer_calculate_coefs (a);
  11600. mixer_notify_update (plci, TRUE);
  11601. }
  11602. li_config_table[i].plci = NULL;
  11603. plci->li_bchannel_id = 0;
  11604. }
  11605. }
  11606. }
  11607. /*------------------------------------------------------------------*/
  11608. /* Echo canceller facilities */
  11609. /*------------------------------------------------------------------*/
  11610. static void ec_write_parameters (PLCI *plci)
  11611. {
  11612. word w;
  11613. byte parameter_buffer[6];
  11614. dbug (1, dprintf ("[%06lx] %s,%d: ec_write_parameters",
  11615. (dword)((plci->Id << 8) | UnMapController (plci->adapter->Id)),
  11616. (char *)(FILE_), __LINE__));
  11617. parameter_buffer[0] = 5;
  11618. parameter_buffer[1] = DSP_CTRL_SET_LEC_PARAMETERS;
  11619. PUT_WORD (&parameter_buffer[2], plci->ec_idi_options);
  11620. plci->ec_idi_options &= ~LEC_RESET_COEFFICIENTS;
  11621. w = (plci->ec_tail_length == 0) ? 128 : plci->ec_tail_length;
  11622. PUT_WORD (&parameter_buffer[4], w);
  11623. add_p (plci, FTY, parameter_buffer);
  11624. sig_req (plci, TEL_CTRL, 0);
  11625. send_req (plci);
  11626. }
  11627. static void ec_clear_config (PLCI *plci)
  11628. {
  11629. dbug (1, dprintf ("[%06lx] %s,%d: ec_clear_config",
  11630. (dword)((plci->Id << 8) | UnMapController (plci->adapter->Id)),
  11631. (char *)(FILE_), __LINE__));
  11632. plci->ec_idi_options = LEC_ENABLE_ECHO_CANCELLER |
  11633. LEC_MANUAL_DISABLE | LEC_ENABLE_NONLINEAR_PROCESSING;
  11634. plci->ec_tail_length = 0;
  11635. }
  11636. static void ec_prepare_switch (dword Id, PLCI *plci)
  11637. {
  11638. dbug (1, dprintf ("[%06lx] %s,%d: ec_prepare_switch",
  11639. UnMapId (Id), (char *)(FILE_), __LINE__));
  11640. }
  11641. static word ec_save_config (dword Id, PLCI *plci, byte Rc)
  11642. {
  11643. dbug (1, dprintf ("[%06lx] %s,%d: ec_save_config %02x %d",
  11644. UnMapId (Id), (char *)(FILE_), __LINE__, Rc, plci->adjust_b_state));
  11645. return (GOOD);
  11646. }
  11647. static word ec_restore_config (dword Id, PLCI *plci, byte Rc)
  11648. {
  11649. word Info;
  11650. dbug (1, dprintf ("[%06lx] %s,%d: ec_restore_config %02x %d",
  11651. UnMapId (Id), (char *)(FILE_), __LINE__, Rc, plci->adjust_b_state));
  11652. Info = GOOD;
  11653. if (plci->B1_facilities & B1_FACILITY_EC)
  11654. {
  11655. switch (plci->adjust_b_state)
  11656. {
  11657. case ADJUST_B_RESTORE_EC_1:
  11658. plci->internal_command = plci->adjust_b_command;
  11659. if (plci->sig_req)
  11660. {
  11661. plci->adjust_b_state = ADJUST_B_RESTORE_EC_1;
  11662. break;
  11663. }
  11664. ec_write_parameters (plci);
  11665. plci->adjust_b_state = ADJUST_B_RESTORE_EC_2;
  11666. break;
  11667. case ADJUST_B_RESTORE_EC_2:
  11668. if ((Rc != OK) && (Rc != OK_FC))
  11669. {
  11670. dbug (1, dprintf ("[%06lx] %s,%d: Restore EC failed %02x",
  11671. UnMapId (Id), (char *)(FILE_), __LINE__, Rc));
  11672. Info = _WRONG_STATE;
  11673. break;
  11674. }
  11675. break;
  11676. }
  11677. }
  11678. return (Info);
  11679. }
  11680. static void ec_command (dword Id, PLCI *plci, byte Rc)
  11681. {
  11682. word internal_command, Info;
  11683. byte result[8];
  11684. dbug (1, dprintf ("[%06lx] %s,%d: ec_command %02x %04x %04x %04x %d",
  11685. UnMapId (Id), (char *)(FILE_), __LINE__, Rc, plci->internal_command,
  11686. plci->ec_cmd, plci->ec_idi_options, plci->ec_tail_length));
  11687. Info = GOOD;
  11688. if (plci->appl->appl_flags & APPL_FLAG_PRIV_EC_SPEC)
  11689. {
  11690. result[0] = 2;
  11691. PUT_WORD (&result[1], EC_SUCCESS);
  11692. }
  11693. else
  11694. {
  11695. result[0] = 5;
  11696. PUT_WORD (&result[1], plci->ec_cmd);
  11697. result[3] = 2;
  11698. PUT_WORD (&result[4], GOOD);
  11699. }
  11700. internal_command = plci->internal_command;
  11701. plci->internal_command = 0;
  11702. switch (plci->ec_cmd)
  11703. {
  11704. case EC_ENABLE_OPERATION:
  11705. case EC_FREEZE_COEFFICIENTS:
  11706. case EC_RESUME_COEFFICIENT_UPDATE:
  11707. case EC_RESET_COEFFICIENTS:
  11708. switch (internal_command)
  11709. {
  11710. default:
  11711. adjust_b1_resource (Id, plci, NULL, (word)(plci->B1_facilities |
  11712. B1_FACILITY_EC), EC_COMMAND_1);
  11713. case EC_COMMAND_1:
  11714. if (adjust_b_process (Id, plci, Rc) != GOOD)
  11715. {
  11716. dbug (1, dprintf ("[%06lx] %s,%d: Load EC failed",
  11717. UnMapId (Id), (char *)(FILE_), __LINE__));
  11718. Info = _FACILITY_NOT_SUPPORTED;
  11719. break;
  11720. }
  11721. if (plci->internal_command)
  11722. return;
  11723. case EC_COMMAND_2:
  11724. if (plci->sig_req)
  11725. {
  11726. plci->internal_command = EC_COMMAND_2;
  11727. return;
  11728. }
  11729. plci->internal_command = EC_COMMAND_3;
  11730. ec_write_parameters (plci);
  11731. return;
  11732. case EC_COMMAND_3:
  11733. if ((Rc != OK) && (Rc != OK_FC))
  11734. {
  11735. dbug (1, dprintf ("[%06lx] %s,%d: Enable EC failed %02x",
  11736. UnMapId (Id), (char *)(FILE_), __LINE__, Rc));
  11737. Info = _FACILITY_NOT_SUPPORTED;
  11738. break;
  11739. }
  11740. break;
  11741. }
  11742. break;
  11743. case EC_DISABLE_OPERATION:
  11744. switch (internal_command)
  11745. {
  11746. default:
  11747. case EC_COMMAND_1:
  11748. if (plci->B1_facilities & B1_FACILITY_EC)
  11749. {
  11750. if (plci->sig_req)
  11751. {
  11752. plci->internal_command = EC_COMMAND_1;
  11753. return;
  11754. }
  11755. plci->internal_command = EC_COMMAND_2;
  11756. ec_write_parameters (plci);
  11757. return;
  11758. }
  11759. Rc = OK;
  11760. case EC_COMMAND_2:
  11761. if ((Rc != OK) && (Rc != OK_FC))
  11762. {
  11763. dbug (1, dprintf ("[%06lx] %s,%d: Disable EC failed %02x",
  11764. UnMapId (Id), (char *)(FILE_), __LINE__, Rc));
  11765. Info = _FACILITY_NOT_SUPPORTED;
  11766. break;
  11767. }
  11768. adjust_b1_resource (Id, plci, NULL, (word)(plci->B1_facilities &
  11769. ~B1_FACILITY_EC), EC_COMMAND_3);
  11770. case EC_COMMAND_3:
  11771. if (adjust_b_process (Id, plci, Rc) != GOOD)
  11772. {
  11773. dbug (1, dprintf ("[%06lx] %s,%d: Unload EC failed",
  11774. UnMapId (Id), (char *)(FILE_), __LINE__));
  11775. Info = _FACILITY_NOT_SUPPORTED;
  11776. break;
  11777. }
  11778. if (plci->internal_command)
  11779. return;
  11780. break;
  11781. }
  11782. break;
  11783. }
  11784. sendf (plci->appl, _FACILITY_R | CONFIRM, Id & 0xffffL, plci->number,
  11785. "wws", Info, (plci->appl->appl_flags & APPL_FLAG_PRIV_EC_SPEC) ?
  11786. PRIV_SELECTOR_ECHO_CANCELLER : SELECTOR_ECHO_CANCELLER, result);
  11787. }
  11788. static byte ec_request (dword Id, word Number, DIVA_CAPI_ADAPTER *a, PLCI *plci, APPL *appl, API_PARSE *msg)
  11789. {
  11790. word Info;
  11791. word opt;
  11792. API_PARSE ec_parms[3];
  11793. byte result[16];
  11794. dbug (1, dprintf ("[%06lx] %s,%d: ec_request",
  11795. UnMapId (Id), (char *)(FILE_), __LINE__));
  11796. Info = GOOD;
  11797. result[0] = 0;
  11798. if (!(a->man_profile.private_options & (1L << PRIVATE_ECHO_CANCELLER)))
  11799. {
  11800. dbug (1, dprintf ("[%06lx] %s,%d: Facility not supported",
  11801. UnMapId (Id), (char *)(FILE_), __LINE__));
  11802. Info = _FACILITY_NOT_SUPPORTED;
  11803. }
  11804. else
  11805. {
  11806. if (appl->appl_flags & APPL_FLAG_PRIV_EC_SPEC)
  11807. {
  11808. if (api_parse (&msg[1].info[1], msg[1].length, "w", ec_parms))
  11809. {
  11810. dbug (1, dprintf ("[%06lx] %s,%d: Wrong message format",
  11811. UnMapId (Id), (char *)(FILE_), __LINE__));
  11812. Info = _WRONG_MESSAGE_FORMAT;
  11813. }
  11814. else
  11815. {
  11816. if (plci == NULL)
  11817. {
  11818. dbug (1, dprintf ("[%06lx] %s,%d: Wrong PLCI",
  11819. UnMapId (Id), (char *)(FILE_), __LINE__));
  11820. Info = _WRONG_IDENTIFIER;
  11821. }
  11822. else if (!plci->State || !plci->NL.Id || plci->nl_remove_id)
  11823. {
  11824. dbug (1, dprintf ("[%06lx] %s,%d: Wrong state",
  11825. UnMapId (Id), (char *)(FILE_), __LINE__));
  11826. Info = _WRONG_STATE;
  11827. }
  11828. else
  11829. {
  11830. plci->command = 0;
  11831. plci->ec_cmd = GET_WORD (ec_parms[0].info);
  11832. plci->ec_idi_options &= ~(LEC_MANUAL_DISABLE | LEC_RESET_COEFFICIENTS);
  11833. result[0] = 2;
  11834. PUT_WORD (&result[1], EC_SUCCESS);
  11835. if (msg[1].length >= 4)
  11836. {
  11837. opt = GET_WORD (&ec_parms[0].info[2]);
  11838. plci->ec_idi_options &= ~(LEC_ENABLE_NONLINEAR_PROCESSING |
  11839. LEC_ENABLE_2100HZ_DETECTOR | LEC_REQUIRE_2100HZ_REVERSALS);
  11840. if (!(opt & EC_DISABLE_NON_LINEAR_PROCESSING))
  11841. plci->ec_idi_options |= LEC_ENABLE_NONLINEAR_PROCESSING;
  11842. if (opt & EC_DETECT_DISABLE_TONE)
  11843. plci->ec_idi_options |= LEC_ENABLE_2100HZ_DETECTOR;
  11844. if (!(opt & EC_DO_NOT_REQUIRE_REVERSALS))
  11845. plci->ec_idi_options |= LEC_REQUIRE_2100HZ_REVERSALS;
  11846. if (msg[1].length >= 6)
  11847. {
  11848. plci->ec_tail_length = GET_WORD (&ec_parms[0].info[4]);
  11849. }
  11850. }
  11851. switch (plci->ec_cmd)
  11852. {
  11853. case EC_ENABLE_OPERATION:
  11854. plci->ec_idi_options &= ~LEC_FREEZE_COEFFICIENTS;
  11855. start_internal_command (Id, plci, ec_command);
  11856. return (FALSE);
  11857. case EC_DISABLE_OPERATION:
  11858. plci->ec_idi_options = LEC_ENABLE_ECHO_CANCELLER |
  11859. LEC_MANUAL_DISABLE | LEC_ENABLE_NONLINEAR_PROCESSING |
  11860. LEC_RESET_COEFFICIENTS;
  11861. start_internal_command (Id, plci, ec_command);
  11862. return (FALSE);
  11863. case EC_FREEZE_COEFFICIENTS:
  11864. plci->ec_idi_options |= LEC_FREEZE_COEFFICIENTS;
  11865. start_internal_command (Id, plci, ec_command);
  11866. return (FALSE);
  11867. case EC_RESUME_COEFFICIENT_UPDATE:
  11868. plci->ec_idi_options &= ~LEC_FREEZE_COEFFICIENTS;
  11869. start_internal_command (Id, plci, ec_command);
  11870. return (FALSE);
  11871. case EC_RESET_COEFFICIENTS:
  11872. plci->ec_idi_options |= LEC_RESET_COEFFICIENTS;
  11873. start_internal_command (Id, plci, ec_command);
  11874. return (FALSE);
  11875. default:
  11876. dbug (1, dprintf ("[%06lx] %s,%d: EC unknown request %04x",
  11877. UnMapId (Id), (char *)(FILE_), __LINE__, plci->ec_cmd));
  11878. PUT_WORD (&result[1], EC_UNSUPPORTED_OPERATION);
  11879. }
  11880. }
  11881. }
  11882. }
  11883. else
  11884. {
  11885. if (api_parse (&msg[1].info[1], msg[1].length, "ws", ec_parms))
  11886. {
  11887. dbug (1, dprintf ("[%06lx] %s,%d: Wrong message format",
  11888. UnMapId (Id), (char *)(FILE_), __LINE__));
  11889. Info = _WRONG_MESSAGE_FORMAT;
  11890. }
  11891. else
  11892. {
  11893. if (GET_WORD (ec_parms[0].info) == EC_GET_SUPPORTED_SERVICES)
  11894. {
  11895. result[0] = 11;
  11896. PUT_WORD (&result[1], EC_GET_SUPPORTED_SERVICES);
  11897. result[3] = 8;
  11898. PUT_WORD (&result[4], GOOD);
  11899. PUT_WORD (&result[6], 0x0007);
  11900. PUT_WORD (&result[8], LEC_MAX_SUPPORTED_TAIL_LENGTH);
  11901. PUT_WORD (&result[10], 0);
  11902. }
  11903. else if (plci == NULL)
  11904. {
  11905. dbug (1, dprintf ("[%06lx] %s,%d: Wrong PLCI",
  11906. UnMapId (Id), (char *)(FILE_), __LINE__));
  11907. Info = _WRONG_IDENTIFIER;
  11908. }
  11909. else if (!plci->State || !plci->NL.Id || plci->nl_remove_id)
  11910. {
  11911. dbug (1, dprintf ("[%06lx] %s,%d: Wrong state",
  11912. UnMapId (Id), (char *)(FILE_), __LINE__));
  11913. Info = _WRONG_STATE;
  11914. }
  11915. else
  11916. {
  11917. plci->command = 0;
  11918. plci->ec_cmd = GET_WORD (ec_parms[0].info);
  11919. plci->ec_idi_options &= ~(LEC_MANUAL_DISABLE | LEC_RESET_COEFFICIENTS);
  11920. result[0] = 5;
  11921. PUT_WORD (&result[1], plci->ec_cmd);
  11922. result[3] = 2;
  11923. PUT_WORD (&result[4], GOOD);
  11924. plci->ec_idi_options &= ~(LEC_ENABLE_NONLINEAR_PROCESSING |
  11925. LEC_ENABLE_2100HZ_DETECTOR | LEC_REQUIRE_2100HZ_REVERSALS);
  11926. plci->ec_tail_length = 0;
  11927. if (ec_parms[1].length >= 2)
  11928. {
  11929. opt = GET_WORD (&ec_parms[1].info[1]);
  11930. if (opt & EC_ENABLE_NON_LINEAR_PROCESSING)
  11931. plci->ec_idi_options |= LEC_ENABLE_NONLINEAR_PROCESSING;
  11932. if (opt & EC_DETECT_DISABLE_TONE)
  11933. plci->ec_idi_options |= LEC_ENABLE_2100HZ_DETECTOR;
  11934. if (!(opt & EC_DO_NOT_REQUIRE_REVERSALS))
  11935. plci->ec_idi_options |= LEC_REQUIRE_2100HZ_REVERSALS;
  11936. if (ec_parms[1].length >= 4)
  11937. {
  11938. plci->ec_tail_length = GET_WORD (&ec_parms[1].info[3]);
  11939. }
  11940. }
  11941. switch (plci->ec_cmd)
  11942. {
  11943. case EC_ENABLE_OPERATION:
  11944. plci->ec_idi_options &= ~LEC_FREEZE_COEFFICIENTS;
  11945. start_internal_command (Id, plci, ec_command);
  11946. return (FALSE);
  11947. case EC_DISABLE_OPERATION:
  11948. plci->ec_idi_options = LEC_ENABLE_ECHO_CANCELLER |
  11949. LEC_MANUAL_DISABLE | LEC_ENABLE_NONLINEAR_PROCESSING |
  11950. LEC_RESET_COEFFICIENTS;
  11951. start_internal_command (Id, plci, ec_command);
  11952. return (FALSE);
  11953. default:
  11954. dbug (1, dprintf ("[%06lx] %s,%d: EC unknown request %04x",
  11955. UnMapId (Id), (char *)(FILE_), __LINE__, plci->ec_cmd));
  11956. PUT_WORD (&result[4], _FACILITY_SPECIFIC_FUNCTION_NOT_SUPP);
  11957. }
  11958. }
  11959. }
  11960. }
  11961. }
  11962. sendf (appl, _FACILITY_R | CONFIRM, Id & 0xffffL, Number,
  11963. "wws", Info, (appl->appl_flags & APPL_FLAG_PRIV_EC_SPEC) ?
  11964. PRIV_SELECTOR_ECHO_CANCELLER : SELECTOR_ECHO_CANCELLER, result);
  11965. return (FALSE);
  11966. }
  11967. static void ec_indication (dword Id, PLCI *plci, byte *msg, word length)
  11968. {
  11969. byte result[8];
  11970. dbug (1, dprintf ("[%06lx] %s,%d: ec_indication",
  11971. UnMapId (Id), (char *)(FILE_), __LINE__));
  11972. if (!(plci->ec_idi_options & LEC_MANUAL_DISABLE))
  11973. {
  11974. if (plci->appl->appl_flags & APPL_FLAG_PRIV_EC_SPEC)
  11975. {
  11976. result[0] = 2;
  11977. PUT_WORD (&result[1], 0);
  11978. switch (msg[1])
  11979. {
  11980. case LEC_DISABLE_TYPE_CONTIGNUOUS_2100HZ:
  11981. PUT_WORD (&result[1], EC_BYPASS_DUE_TO_CONTINUOUS_2100HZ);
  11982. break;
  11983. case LEC_DISABLE_TYPE_REVERSED_2100HZ:
  11984. PUT_WORD (&result[1], EC_BYPASS_DUE_TO_REVERSED_2100HZ);
  11985. break;
  11986. case LEC_DISABLE_RELEASED:
  11987. PUT_WORD (&result[1], EC_BYPASS_RELEASED);
  11988. break;
  11989. }
  11990. }
  11991. else
  11992. {
  11993. result[0] = 5;
  11994. PUT_WORD (&result[1], EC_BYPASS_INDICATION);
  11995. result[3] = 2;
  11996. PUT_WORD (&result[4], 0);
  11997. switch (msg[1])
  11998. {
  11999. case LEC_DISABLE_TYPE_CONTIGNUOUS_2100HZ:
  12000. PUT_WORD (&result[4], EC_BYPASS_DUE_TO_CONTINUOUS_2100HZ);
  12001. break;
  12002. case LEC_DISABLE_TYPE_REVERSED_2100HZ:
  12003. PUT_WORD (&result[4], EC_BYPASS_DUE_TO_REVERSED_2100HZ);
  12004. break;
  12005. case LEC_DISABLE_RELEASED:
  12006. PUT_WORD (&result[4], EC_BYPASS_RELEASED);
  12007. break;
  12008. }
  12009. }
  12010. sendf (plci->appl, _FACILITY_I, Id & 0xffffL, 0, "ws", (plci->appl->appl_flags & APPL_FLAG_PRIV_EC_SPEC) ?
  12011. PRIV_SELECTOR_ECHO_CANCELLER : SELECTOR_ECHO_CANCELLER, result);
  12012. }
  12013. }
  12014. /*------------------------------------------------------------------*/
  12015. /* Advanced voice */
  12016. /*------------------------------------------------------------------*/
  12017. static void adv_voice_write_coefs (PLCI *plci, word write_command)
  12018. {
  12019. DIVA_CAPI_ADAPTER *a;
  12020. word i;
  12021. byte *p;
  12022. word w, n, j, k;
  12023. byte ch_map[MIXER_CHANNELS_BRI];
  12024. byte coef_buffer[ADV_VOICE_COEF_BUFFER_SIZE + 2];
  12025. dbug (1, dprintf ("[%06lx] %s,%d: adv_voice_write_coefs %d",
  12026. (dword)((plci->Id << 8) | UnMapController (plci->adapter->Id)),
  12027. (char *)(FILE_), __LINE__, write_command));
  12028. a = plci->adapter;
  12029. p = coef_buffer + 1;
  12030. *(p++) = DSP_CTRL_OLD_SET_MIXER_COEFFICIENTS;
  12031. i = 0;
  12032. while (i + sizeof(word) <= a->adv_voice_coef_length)
  12033. {
  12034. PUT_WORD (p, GET_WORD (a->adv_voice_coef_buffer + i));
  12035. p += 2;
  12036. i += 2;
  12037. }
  12038. while (i < ADV_VOICE_OLD_COEF_COUNT * sizeof(word))
  12039. {
  12040. PUT_WORD (p, 0x8000);
  12041. p += 2;
  12042. i += 2;
  12043. }
  12044. if (!a->li_pri && (plci->li_bchannel_id == 0))
  12045. {
  12046. if ((li_config_table[a->li_base].plci == NULL) && (li_config_table[a->li_base + 1].plci != NULL))
  12047. {
  12048. plci->li_bchannel_id = 1;
  12049. li_config_table[a->li_base].plci = plci;
  12050. dbug (1, dprintf ("[%06lx] %s,%d: adv_voice_set_bchannel_id %d",
  12051. (dword)((plci->Id << 8) | UnMapController (plci->adapter->Id)),
  12052. (char *)(FILE_), __LINE__, plci->li_bchannel_id));
  12053. }
  12054. else if ((li_config_table[a->li_base].plci != NULL) && (li_config_table[a->li_base + 1].plci == NULL))
  12055. {
  12056. plci->li_bchannel_id = 2;
  12057. li_config_table[a->li_base + 1].plci = plci;
  12058. dbug (1, dprintf ("[%06lx] %s,%d: adv_voice_set_bchannel_id %d",
  12059. (dword)((plci->Id << 8) | UnMapController (plci->adapter->Id)),
  12060. (char *)(FILE_), __LINE__, plci->li_bchannel_id));
  12061. }
  12062. }
  12063. if (!a->li_pri && (plci->li_bchannel_id != 0)
  12064. && (li_config_table[a->li_base + (plci->li_bchannel_id - 1)].plci == plci))
  12065. {
  12066. i = a->li_base + (plci->li_bchannel_id - 1);
  12067. switch (write_command)
  12068. {
  12069. case ADV_VOICE_WRITE_ACTIVATION:
  12070. j = a->li_base + MIXER_IC_CHANNEL_BASE + (plci->li_bchannel_id - 1);
  12071. k = a->li_base + MIXER_IC_CHANNEL_BASE + (2 - plci->li_bchannel_id);
  12072. if (!(plci->B1_facilities & B1_FACILITY_MIXER))
  12073. {
  12074. li_config_table[j].flag_table[i] |= LI_FLAG_CONFERENCE | LI_FLAG_MIX;
  12075. li_config_table[i].flag_table[j] |= LI_FLAG_CONFERENCE | LI_FLAG_MONITOR;
  12076. }
  12077. if (a->manufacturer_features & MANUFACTURER_FEATURE_SLAVE_CODEC)
  12078. {
  12079. li_config_table[k].flag_table[i] |= LI_FLAG_CONFERENCE | LI_FLAG_MIX;
  12080. li_config_table[i].flag_table[k] |= LI_FLAG_CONFERENCE | LI_FLAG_MONITOR;
  12081. li_config_table[k].flag_table[j] |= LI_FLAG_CONFERENCE;
  12082. li_config_table[j].flag_table[k] |= LI_FLAG_CONFERENCE;
  12083. }
  12084. mixer_calculate_coefs (a);
  12085. li_config_table[i].curchnl = li_config_table[i].channel;
  12086. li_config_table[j].curchnl = li_config_table[j].channel;
  12087. if (a->manufacturer_features & MANUFACTURER_FEATURE_SLAVE_CODEC)
  12088. li_config_table[k].curchnl = li_config_table[k].channel;
  12089. break;
  12090. case ADV_VOICE_WRITE_DEACTIVATION:
  12091. for (j = 0; j < li_total_channels; j++)
  12092. {
  12093. li_config_table[i].flag_table[j] = 0;
  12094. li_config_table[j].flag_table[i] = 0;
  12095. }
  12096. k = a->li_base + MIXER_IC_CHANNEL_BASE + (plci->li_bchannel_id - 1);
  12097. for (j = 0; j < li_total_channels; j++)
  12098. {
  12099. li_config_table[k].flag_table[j] = 0;
  12100. li_config_table[j].flag_table[k] = 0;
  12101. }
  12102. if (a->manufacturer_features & MANUFACTURER_FEATURE_SLAVE_CODEC)
  12103. {
  12104. k = a->li_base + MIXER_IC_CHANNEL_BASE + (2 - plci->li_bchannel_id);
  12105. for (j = 0; j < li_total_channels; j++)
  12106. {
  12107. li_config_table[k].flag_table[j] = 0;
  12108. li_config_table[j].flag_table[k] = 0;
  12109. }
  12110. }
  12111. mixer_calculate_coefs (a);
  12112. break;
  12113. }
  12114. if (plci->B1_facilities & B1_FACILITY_MIXER)
  12115. {
  12116. w = 0;
  12117. if (ADV_VOICE_NEW_COEF_BASE + sizeof(word) <= a->adv_voice_coef_length)
  12118. w = GET_WORD (a->adv_voice_coef_buffer + ADV_VOICE_NEW_COEF_BASE);
  12119. if (li_config_table[i].channel & LI_CHANNEL_TX_DATA)
  12120. w |= MIXER_FEATURE_ENABLE_TX_DATA;
  12121. if (li_config_table[i].channel & LI_CHANNEL_RX_DATA)
  12122. w |= MIXER_FEATURE_ENABLE_RX_DATA;
  12123. *(p++) = (byte) w;
  12124. *(p++) = (byte)(w >> 8);
  12125. for (j = 0; j < sizeof(ch_map); j += 2)
  12126. {
  12127. ch_map[j] = (byte)(j + (plci->li_bchannel_id - 1));
  12128. ch_map[j+1] = (byte)(j + (2 - plci->li_bchannel_id));
  12129. }
  12130. for (n = 0; n < sizeof(mixer_write_prog_bri) / sizeof(mixer_write_prog_bri[0]); n++)
  12131. {
  12132. i = a->li_base + ch_map[mixer_write_prog_bri[n].to_ch];
  12133. j = a->li_base + ch_map[mixer_write_prog_bri[n].from_ch];
  12134. if (li_config_table[i].channel & li_config_table[j].channel & LI_CHANNEL_INVOLVED)
  12135. {
  12136. *(p++) = ((li_config_table[i].coef_table[j] & mixer_write_prog_bri[n].mask) ? 0x80 : 0x01);
  12137. w = ((li_config_table[i].coef_table[j] & 0xf) ^ (li_config_table[i].coef_table[j] >> 4));
  12138. li_config_table[i].coef_table[j] ^= (w & mixer_write_prog_bri[n].mask) << 4;
  12139. }
  12140. else
  12141. {
  12142. *(p++) = (ADV_VOICE_NEW_COEF_BASE + sizeof(word) + n < a->adv_voice_coef_length) ?
  12143. a->adv_voice_coef_buffer[ADV_VOICE_NEW_COEF_BASE + sizeof(word) + n] : 0x00;
  12144. }
  12145. }
  12146. }
  12147. else
  12148. {
  12149. for (i = ADV_VOICE_NEW_COEF_BASE; i < a->adv_voice_coef_length; i++)
  12150. *(p++) = a->adv_voice_coef_buffer[i];
  12151. }
  12152. }
  12153. else
  12154. {
  12155. for (i = ADV_VOICE_NEW_COEF_BASE; i < a->adv_voice_coef_length; i++)
  12156. *(p++) = a->adv_voice_coef_buffer[i];
  12157. }
  12158. coef_buffer[0] = (p - coef_buffer) - 1;
  12159. add_p (plci, FTY, coef_buffer);
  12160. sig_req (plci, TEL_CTRL, 0);
  12161. send_req (plci);
  12162. }
  12163. static void adv_voice_clear_config (PLCI *plci)
  12164. {
  12165. DIVA_CAPI_ADAPTER *a;
  12166. word i, j;
  12167. dbug (1, dprintf ("[%06lx] %s,%d: adv_voice_clear_config",
  12168. (dword)((plci->Id << 8) | UnMapController (plci->adapter->Id)),
  12169. (char *)(FILE_), __LINE__));
  12170. a = plci->adapter;
  12171. if ((plci->tel == ADV_VOICE) && (plci == a->AdvSignalPLCI))
  12172. {
  12173. a->adv_voice_coef_length = 0;
  12174. if (!a->li_pri && (plci->li_bchannel_id != 0)
  12175. && (li_config_table[a->li_base + (plci->li_bchannel_id - 1)].plci == plci))
  12176. {
  12177. i = a->li_base + (plci->li_bchannel_id - 1);
  12178. li_config_table[i].curchnl = 0;
  12179. li_config_table[i].channel = 0;
  12180. li_config_table[i].chflags = 0;
  12181. for (j = 0; j < li_total_channels; j++)
  12182. {
  12183. li_config_table[i].flag_table[j] = 0;
  12184. li_config_table[j].flag_table[i] = 0;
  12185. li_config_table[i].coef_table[j] = 0;
  12186. li_config_table[j].coef_table[i] = 0;
  12187. }
  12188. li_config_table[i].coef_table[i] |= LI_COEF_CH_PC_SET | LI_COEF_PC_CH_SET;
  12189. i = a->li_base + MIXER_IC_CHANNEL_BASE + (plci->li_bchannel_id - 1);
  12190. li_config_table[i].curchnl = 0;
  12191. li_config_table[i].channel = 0;
  12192. li_config_table[i].chflags = 0;
  12193. for (j = 0; j < li_total_channels; j++)
  12194. {
  12195. li_config_table[i].flag_table[j] = 0;
  12196. li_config_table[j].flag_table[i] = 0;
  12197. li_config_table[i].coef_table[j] = 0;
  12198. li_config_table[j].coef_table[i] = 0;
  12199. }
  12200. if (a->manufacturer_features & MANUFACTURER_FEATURE_SLAVE_CODEC)
  12201. {
  12202. i = a->li_base + MIXER_IC_CHANNEL_BASE + (2 - plci->li_bchannel_id);
  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. }
  12214. }
  12215. }
  12216. }
  12217. static void adv_voice_prepare_switch (dword Id, PLCI *plci)
  12218. {
  12219. dbug (1, dprintf ("[%06lx] %s,%d: adv_voice_prepare_switch",
  12220. UnMapId (Id), (char *)(FILE_), __LINE__));
  12221. }
  12222. static word adv_voice_save_config (dword Id, PLCI *plci, byte Rc)
  12223. {
  12224. dbug (1, dprintf ("[%06lx] %s,%d: adv_voice_save_config %02x %d",
  12225. UnMapId (Id), (char *)(FILE_), __LINE__, Rc, plci->adjust_b_state));
  12226. return (GOOD);
  12227. }
  12228. static word adv_voice_restore_config (dword Id, PLCI *plci, byte Rc)
  12229. {
  12230. DIVA_CAPI_ADAPTER *a;
  12231. word Info;
  12232. dbug (1, dprintf ("[%06lx] %s,%d: adv_voice_restore_config %02x %d",
  12233. UnMapId (Id), (char *)(FILE_), __LINE__, Rc, plci->adjust_b_state));
  12234. Info = GOOD;
  12235. a = plci->adapter;
  12236. if ((plci->B1_facilities & B1_FACILITY_VOICE)
  12237. && (plci->tel == ADV_VOICE) && (plci == a->AdvSignalPLCI))
  12238. {
  12239. switch (plci->adjust_b_state)
  12240. {
  12241. case ADJUST_B_RESTORE_VOICE_1:
  12242. plci->internal_command = plci->adjust_b_command;
  12243. if (plci->sig_req)
  12244. {
  12245. plci->adjust_b_state = ADJUST_B_RESTORE_VOICE_1;
  12246. break;
  12247. }
  12248. adv_voice_write_coefs (plci, ADV_VOICE_WRITE_UPDATE);
  12249. plci->adjust_b_state = ADJUST_B_RESTORE_VOICE_2;
  12250. break;
  12251. case ADJUST_B_RESTORE_VOICE_2:
  12252. if ((Rc != OK) && (Rc != OK_FC))
  12253. {
  12254. dbug (1, dprintf ("[%06lx] %s,%d: Restore voice config failed %02x",
  12255. UnMapId (Id), (char *)(FILE_), __LINE__, Rc));
  12256. Info = _WRONG_STATE;
  12257. break;
  12258. }
  12259. break;
  12260. }
  12261. }
  12262. return (Info);
  12263. }
  12264. /*------------------------------------------------------------------*/
  12265. /* B1 resource switching */
  12266. /*------------------------------------------------------------------*/
  12267. static byte b1_facilities_table[] =
  12268. {
  12269. 0x00, /* 0 No bchannel resources */
  12270. 0x00, /* 1 Codec (automatic law) */
  12271. 0x00, /* 2 Codec (A-law) */
  12272. 0x00, /* 3 Codec (y-law) */
  12273. 0x00, /* 4 HDLC for X.21 */
  12274. 0x00, /* 5 HDLC */
  12275. 0x00, /* 6 External Device 0 */
  12276. 0x00, /* 7 External Device 1 */
  12277. 0x00, /* 8 HDLC 56k */
  12278. 0x00, /* 9 Transparent */
  12279. 0x00, /* 10 Loopback to network */
  12280. 0x00, /* 11 Test pattern to net */
  12281. 0x00, /* 12 Rate adaptation sync */
  12282. 0x00, /* 13 Rate adaptation async */
  12283. 0x00, /* 14 R-Interface */
  12284. 0x00, /* 15 HDLC 128k leased line */
  12285. 0x00, /* 16 FAX */
  12286. 0x00, /* 17 Modem async */
  12287. 0x00, /* 18 Modem sync HDLC */
  12288. 0x00, /* 19 V.110 async HDLC */
  12289. 0x12, /* 20 Adv voice (Trans,mixer) */
  12290. 0x00, /* 21 Codec connected to IC */
  12291. 0x0c, /* 22 Trans,DTMF */
  12292. 0x1e, /* 23 Trans,DTMF+mixer */
  12293. 0x1f, /* 24 Trans,DTMF+mixer+local */
  12294. 0x13, /* 25 Trans,mixer+local */
  12295. 0x12, /* 26 HDLC,mixer */
  12296. 0x12, /* 27 HDLC 56k,mixer */
  12297. 0x2c, /* 28 Trans,LEC+DTMF */
  12298. 0x3e, /* 29 Trans,LEC+DTMF+mixer */
  12299. 0x3f, /* 30 Trans,LEC+DTMF+mixer+local */
  12300. 0x2c, /* 31 RTP,LEC+DTMF */
  12301. 0x3e, /* 32 RTP,LEC+DTMF+mixer */
  12302. 0x3f, /* 33 RTP,LEC+DTMF+mixer+local */
  12303. 0x00, /* 34 Signaling task */
  12304. 0x00, /* 35 PIAFS */
  12305. 0x0c, /* 36 Trans,DTMF+TONE */
  12306. 0x1e, /* 37 Trans,DTMF+TONE+mixer */
  12307. 0x1f /* 38 Trans,DTMF+TONE+mixer+local*/
  12308. };
  12309. static word get_b1_facilities (PLCI * plci, byte b1_resource)
  12310. {
  12311. word b1_facilities;
  12312. b1_facilities = b1_facilities_table[b1_resource];
  12313. if ((b1_resource == 9) || (b1_resource == 20) || (b1_resource == 25))
  12314. {
  12315. if (!(((plci->requested_options_conn | plci->requested_options) & (1L << PRIVATE_DTMF_TONE))
  12316. || (plci->appl && (plci->adapter->requested_options_table[plci->appl->Id-1] & (1L << PRIVATE_DTMF_TONE)))))
  12317. {
  12318. if (plci->adapter->manufacturer_features & MANUFACTURER_FEATURE_SOFTDTMF_SEND)
  12319. b1_facilities |= B1_FACILITY_DTMFX;
  12320. if (plci->adapter->manufacturer_features & MANUFACTURER_FEATURE_SOFTDTMF_RECEIVE)
  12321. b1_facilities |= B1_FACILITY_DTMFR;
  12322. }
  12323. }
  12324. if ((b1_resource == 17) || (b1_resource == 18))
  12325. {
  12326. if (plci->adapter->manufacturer_features & (MANUFACTURER_FEATURE_V18 | MANUFACTURER_FEATURE_VOWN))
  12327. b1_facilities |= B1_FACILITY_DTMFX | B1_FACILITY_DTMFR;
  12328. }
  12329. /*
  12330. dbug (1, dprintf ("[%06lx] %s,%d: get_b1_facilities %d %04x",
  12331. (dword)((plci->Id << 8) | UnMapController (plci->adapter->Id)),
  12332. (char far *)(FILE_), __LINE__, b1_resource, b1_facilites));
  12333. */
  12334. return (b1_facilities);
  12335. }
  12336. static byte add_b1_facilities (PLCI * plci, byte b1_resource, word b1_facilities)
  12337. {
  12338. byte b;
  12339. switch (b1_resource)
  12340. {
  12341. case 5:
  12342. case 26:
  12343. if (b1_facilities & (B1_FACILITY_MIXER | B1_FACILITY_VOICE))
  12344. b = 26;
  12345. else
  12346. b = 5;
  12347. break;
  12348. case 8:
  12349. case 27:
  12350. if (b1_facilities & (B1_FACILITY_MIXER | B1_FACILITY_VOICE))
  12351. b = 27;
  12352. else
  12353. b = 8;
  12354. break;
  12355. case 9:
  12356. case 20:
  12357. case 22:
  12358. case 23:
  12359. case 24:
  12360. case 25:
  12361. case 28:
  12362. case 29:
  12363. case 30:
  12364. case 36:
  12365. case 37:
  12366. case 38:
  12367. if (b1_facilities & B1_FACILITY_EC)
  12368. {
  12369. if (b1_facilities & B1_FACILITY_LOCAL)
  12370. b = 30;
  12371. else if (b1_facilities & (B1_FACILITY_MIXER | B1_FACILITY_VOICE))
  12372. b = 29;
  12373. else
  12374. b = 28;
  12375. }
  12376. else if ((b1_facilities & (B1_FACILITY_DTMFX | B1_FACILITY_DTMFR | B1_FACILITY_MIXER))
  12377. && (((plci->requested_options_conn | plci->requested_options) & (1L << PRIVATE_DTMF_TONE))
  12378. || (plci->appl && (plci->adapter->requested_options_table[plci->appl->Id-1] & (1L << PRIVATE_DTMF_TONE)))))
  12379. {
  12380. if (b1_facilities & B1_FACILITY_LOCAL)
  12381. b = 38;
  12382. else if (b1_facilities & (B1_FACILITY_MIXER | B1_FACILITY_VOICE))
  12383. b = 37;
  12384. else
  12385. b = 36;
  12386. }
  12387. else if (((plci->adapter->manufacturer_features & MANUFACTURER_FEATURE_HARDDTMF)
  12388. && !(plci->adapter->manufacturer_features & MANUFACTURER_FEATURE_SOFTDTMF_RECEIVE))
  12389. || ((b1_facilities & B1_FACILITY_DTMFR)
  12390. && ((b1_facilities & B1_FACILITY_MIXER)
  12391. || !(plci->adapter->manufacturer_features & MANUFACTURER_FEATURE_SOFTDTMF_RECEIVE)))
  12392. || ((b1_facilities & B1_FACILITY_DTMFX)
  12393. && ((b1_facilities & B1_FACILITY_MIXER)
  12394. || !(plci->adapter->manufacturer_features & MANUFACTURER_FEATURE_SOFTDTMF_SEND))))
  12395. {
  12396. if (b1_facilities & B1_FACILITY_LOCAL)
  12397. b = 24;
  12398. else if (b1_facilities & (B1_FACILITY_MIXER | B1_FACILITY_VOICE))
  12399. b = 23;
  12400. else
  12401. b = 22;
  12402. }
  12403. else
  12404. {
  12405. if (b1_facilities & B1_FACILITY_LOCAL)
  12406. b = 25;
  12407. else if (b1_facilities & (B1_FACILITY_MIXER | B1_FACILITY_VOICE))
  12408. b = 20;
  12409. else
  12410. b = 9;
  12411. }
  12412. break;
  12413. case 31:
  12414. case 32:
  12415. case 33:
  12416. if (b1_facilities & B1_FACILITY_LOCAL)
  12417. b = 33;
  12418. else if (b1_facilities & (B1_FACILITY_MIXER | B1_FACILITY_VOICE))
  12419. b = 32;
  12420. else
  12421. b = 31;
  12422. break;
  12423. default:
  12424. b = b1_resource;
  12425. }
  12426. dbug (1, dprintf ("[%06lx] %s,%d: add_b1_facilities %d %04x %d %04x",
  12427. (dword)((plci->Id << 8) | UnMapController (plci->adapter->Id)),
  12428. (char *)(FILE_), __LINE__,
  12429. b1_resource, b1_facilities, b, get_b1_facilities (plci, b)));
  12430. return (b);
  12431. }
  12432. static void adjust_b1_facilities (PLCI *plci, byte new_b1_resource, word new_b1_facilities)
  12433. {
  12434. word removed_facilities;
  12435. dbug (1, dprintf ("[%06lx] %s,%d: adjust_b1_facilities %d %04x %04x",
  12436. (dword)((plci->Id << 8) | UnMapController (plci->adapter->Id)),
  12437. (char *)(FILE_), __LINE__, new_b1_resource, new_b1_facilities,
  12438. new_b1_facilities & get_b1_facilities (plci, new_b1_resource)));
  12439. new_b1_facilities &= get_b1_facilities (plci, new_b1_resource);
  12440. removed_facilities = plci->B1_facilities & ~new_b1_facilities;
  12441. if (removed_facilities & B1_FACILITY_EC)
  12442. ec_clear_config (plci);
  12443. if (removed_facilities & B1_FACILITY_DTMFR)
  12444. {
  12445. dtmf_rec_clear_config (plci);
  12446. dtmf_parameter_clear_config (plci);
  12447. }
  12448. if (removed_facilities & B1_FACILITY_DTMFX)
  12449. dtmf_send_clear_config (plci);
  12450. if (removed_facilities & B1_FACILITY_MIXER)
  12451. mixer_clear_config (plci);
  12452. if (removed_facilities & B1_FACILITY_VOICE)
  12453. adv_voice_clear_config (plci);
  12454. plci->B1_facilities = new_b1_facilities;
  12455. }
  12456. static void adjust_b_clear (PLCI *plci)
  12457. {
  12458. dbug (1, dprintf ("[%06lx] %s,%d: adjust_b_clear",
  12459. (dword)((plci->Id << 8) | UnMapController (plci->adapter->Id)),
  12460. (char *)(FILE_), __LINE__));
  12461. plci->adjust_b_restore = FALSE;
  12462. }
  12463. static word adjust_b_process (dword Id, PLCI *plci, byte Rc)
  12464. {
  12465. word Info;
  12466. byte b1_resource;
  12467. NCCI * ncci_ptr;
  12468. API_PARSE bp[2];
  12469. dbug (1, dprintf ("[%06lx] %s,%d: adjust_b_process %02x %d",
  12470. UnMapId (Id), (char *)(FILE_), __LINE__, Rc, plci->adjust_b_state));
  12471. Info = GOOD;
  12472. switch (plci->adjust_b_state)
  12473. {
  12474. case ADJUST_B_START:
  12475. if ((plci->adjust_b_parms_msg == NULL)
  12476. && (plci->adjust_b_mode & ADJUST_B_MODE_SWITCH_L1)
  12477. && ((plci->adjust_b_mode & ~(ADJUST_B_MODE_SAVE | ADJUST_B_MODE_SWITCH_L1 |
  12478. ADJUST_B_MODE_NO_RESOURCE | ADJUST_B_MODE_RESTORE)) == 0))
  12479. {
  12480. b1_resource = (plci->adjust_b_mode == ADJUST_B_MODE_NO_RESOURCE) ?
  12481. 0 : add_b1_facilities (plci, plci->B1_resource, plci->adjust_b_facilities);
  12482. if (b1_resource == plci->B1_resource)
  12483. {
  12484. adjust_b1_facilities (plci, b1_resource, plci->adjust_b_facilities);
  12485. break;
  12486. }
  12487. if (plci->adjust_b_facilities & ~get_b1_facilities (plci, b1_resource))
  12488. {
  12489. dbug (1, dprintf ("[%06lx] %s,%d: Adjust B nonsupported facilities %d %d %04x",
  12490. UnMapId (Id), (char *)(FILE_), __LINE__,
  12491. plci->B1_resource, b1_resource, plci->adjust_b_facilities));
  12492. Info = _WRONG_STATE;
  12493. break;
  12494. }
  12495. }
  12496. if (plci->adjust_b_mode & ADJUST_B_MODE_SAVE)
  12497. {
  12498. mixer_prepare_switch (Id, plci);
  12499. dtmf_prepare_switch (Id, plci);
  12500. dtmf_parameter_prepare_switch (Id, plci);
  12501. ec_prepare_switch (Id, plci);
  12502. adv_voice_prepare_switch (Id, plci);
  12503. }
  12504. plci->adjust_b_state = ADJUST_B_SAVE_MIXER_1;
  12505. Rc = OK;
  12506. case ADJUST_B_SAVE_MIXER_1:
  12507. if (plci->adjust_b_mode & ADJUST_B_MODE_SAVE)
  12508. {
  12509. Info = mixer_save_config (Id, plci, Rc);
  12510. if ((Info != GOOD) || plci->internal_command)
  12511. break;
  12512. }
  12513. plci->adjust_b_state = ADJUST_B_SAVE_DTMF_1;
  12514. Rc = OK;
  12515. case ADJUST_B_SAVE_DTMF_1:
  12516. if (plci->adjust_b_mode & ADJUST_B_MODE_SAVE)
  12517. {
  12518. Info = dtmf_save_config (Id, plci, Rc);
  12519. if ((Info != GOOD) || plci->internal_command)
  12520. break;
  12521. }
  12522. plci->adjust_b_state = ADJUST_B_REMOVE_L23_1;
  12523. case ADJUST_B_REMOVE_L23_1:
  12524. if ((plci->adjust_b_mode & ADJUST_B_MODE_REMOVE_L23)
  12525. && plci->NL.Id && !plci->nl_remove_id)
  12526. {
  12527. plci->internal_command = plci->adjust_b_command;
  12528. if (plci->adjust_b_ncci != 0)
  12529. {
  12530. ncci_ptr = &(plci->adapter->ncci[plci->adjust_b_ncci]);
  12531. while (ncci_ptr->data_pending)
  12532. {
  12533. plci->data_sent_ptr = ncci_ptr->DBuffer[ncci_ptr->data_out].P;
  12534. data_rc (plci, plci->adapter->ncci_ch[plci->adjust_b_ncci]);
  12535. }
  12536. while (ncci_ptr->data_ack_pending)
  12537. data_ack (plci, plci->adapter->ncci_ch[plci->adjust_b_ncci]);
  12538. }
  12539. nl_req_ncci (plci, REMOVE,
  12540. (byte)((plci->adjust_b_mode & ADJUST_B_MODE_CONNECT) ? plci->adjust_b_ncci : 0));
  12541. send_req (plci);
  12542. plci->adjust_b_state = ADJUST_B_REMOVE_L23_2;
  12543. break;
  12544. }
  12545. plci->adjust_b_state = ADJUST_B_REMOVE_L23_2;
  12546. Rc = OK;
  12547. case ADJUST_B_REMOVE_L23_2:
  12548. if ((Rc != OK) && (Rc != OK_FC))
  12549. {
  12550. dbug (1, dprintf ("[%06lx] %s,%d: Adjust B remove failed %02x",
  12551. UnMapId (Id), (char *)(FILE_), __LINE__, Rc));
  12552. Info = _WRONG_STATE;
  12553. break;
  12554. }
  12555. if (plci->adjust_b_mode & ADJUST_B_MODE_REMOVE_L23)
  12556. {
  12557. if (plci_nl_busy (plci))
  12558. {
  12559. plci->internal_command = plci->adjust_b_command;
  12560. break;
  12561. }
  12562. }
  12563. plci->adjust_b_state = ADJUST_B_SAVE_EC_1;
  12564. Rc = OK;
  12565. case ADJUST_B_SAVE_EC_1:
  12566. if (plci->adjust_b_mode & ADJUST_B_MODE_SAVE)
  12567. {
  12568. Info = ec_save_config (Id, plci, Rc);
  12569. if ((Info != GOOD) || plci->internal_command)
  12570. break;
  12571. }
  12572. plci->adjust_b_state = ADJUST_B_SAVE_DTMF_PARAMETER_1;
  12573. Rc = OK;
  12574. case ADJUST_B_SAVE_DTMF_PARAMETER_1:
  12575. if (plci->adjust_b_mode & ADJUST_B_MODE_SAVE)
  12576. {
  12577. Info = dtmf_parameter_save_config (Id, plci, Rc);
  12578. if ((Info != GOOD) || plci->internal_command)
  12579. break;
  12580. }
  12581. plci->adjust_b_state = ADJUST_B_SAVE_VOICE_1;
  12582. Rc = OK;
  12583. case ADJUST_B_SAVE_VOICE_1:
  12584. if (plci->adjust_b_mode & ADJUST_B_MODE_SAVE)
  12585. {
  12586. Info = adv_voice_save_config (Id, plci, Rc);
  12587. if ((Info != GOOD) || plci->internal_command)
  12588. break;
  12589. }
  12590. plci->adjust_b_state = ADJUST_B_SWITCH_L1_1;
  12591. case ADJUST_B_SWITCH_L1_1:
  12592. if (plci->adjust_b_mode & ADJUST_B_MODE_SWITCH_L1)
  12593. {
  12594. if (plci->sig_req)
  12595. {
  12596. plci->internal_command = plci->adjust_b_command;
  12597. break;
  12598. }
  12599. if (plci->adjust_b_parms_msg != NULL)
  12600. api_load_msg (plci->adjust_b_parms_msg, bp);
  12601. else
  12602. api_load_msg (&plci->B_protocol, bp);
  12603. Info = add_b1 (plci, bp,
  12604. (word)((plci->adjust_b_mode & ADJUST_B_MODE_NO_RESOURCE) ? 2 : 0),
  12605. plci->adjust_b_facilities);
  12606. if (Info != GOOD)
  12607. {
  12608. dbug (1, dprintf ("[%06lx] %s,%d: Adjust B invalid L1 parameters %d %04x",
  12609. UnMapId (Id), (char *)(FILE_), __LINE__,
  12610. plci->B1_resource, plci->adjust_b_facilities));
  12611. break;
  12612. }
  12613. plci->internal_command = plci->adjust_b_command;
  12614. sig_req (plci, RESOURCES, 0);
  12615. send_req (plci);
  12616. plci->adjust_b_state = ADJUST_B_SWITCH_L1_2;
  12617. break;
  12618. }
  12619. plci->adjust_b_state = ADJUST_B_SWITCH_L1_2;
  12620. Rc = OK;
  12621. case ADJUST_B_SWITCH_L1_2:
  12622. if ((Rc != OK) && (Rc != OK_FC))
  12623. {
  12624. dbug (1, dprintf ("[%06lx] %s,%d: Adjust B switch failed %02x %d %04x",
  12625. UnMapId (Id), (char *)(FILE_), __LINE__,
  12626. Rc, plci->B1_resource, plci->adjust_b_facilities));
  12627. Info = _WRONG_STATE;
  12628. break;
  12629. }
  12630. plci->adjust_b_state = ADJUST_B_RESTORE_VOICE_1;
  12631. Rc = OK;
  12632. case ADJUST_B_RESTORE_VOICE_1:
  12633. case ADJUST_B_RESTORE_VOICE_2:
  12634. if (plci->adjust_b_mode & ADJUST_B_MODE_RESTORE)
  12635. {
  12636. Info = adv_voice_restore_config (Id, plci, Rc);
  12637. if ((Info != GOOD) || plci->internal_command)
  12638. break;
  12639. }
  12640. plci->adjust_b_state = ADJUST_B_RESTORE_DTMF_PARAMETER_1;
  12641. Rc = OK;
  12642. case ADJUST_B_RESTORE_DTMF_PARAMETER_1:
  12643. case ADJUST_B_RESTORE_DTMF_PARAMETER_2:
  12644. if (plci->adjust_b_mode & ADJUST_B_MODE_RESTORE)
  12645. {
  12646. Info = dtmf_parameter_restore_config (Id, plci, Rc);
  12647. if ((Info != GOOD) || plci->internal_command)
  12648. break;
  12649. }
  12650. plci->adjust_b_state = ADJUST_B_RESTORE_EC_1;
  12651. Rc = OK;
  12652. case ADJUST_B_RESTORE_EC_1:
  12653. case ADJUST_B_RESTORE_EC_2:
  12654. if (plci->adjust_b_mode & ADJUST_B_MODE_RESTORE)
  12655. {
  12656. Info = ec_restore_config (Id, plci, Rc);
  12657. if ((Info != GOOD) || plci->internal_command)
  12658. break;
  12659. }
  12660. plci->adjust_b_state = ADJUST_B_ASSIGN_L23_1;
  12661. case ADJUST_B_ASSIGN_L23_1:
  12662. if (plci->adjust_b_mode & ADJUST_B_MODE_ASSIGN_L23)
  12663. {
  12664. if (plci_nl_busy (plci))
  12665. {
  12666. plci->internal_command = plci->adjust_b_command;
  12667. break;
  12668. }
  12669. if (plci->adjust_b_mode & ADJUST_B_MODE_CONNECT)
  12670. plci->call_dir |= CALL_DIR_FORCE_OUTG_NL;
  12671. if (plci->adjust_b_parms_msg != NULL)
  12672. api_load_msg (plci->adjust_b_parms_msg, bp);
  12673. else
  12674. api_load_msg (&plci->B_protocol, bp);
  12675. Info = add_b23 (plci, bp);
  12676. if (Info != GOOD)
  12677. {
  12678. dbug (1, dprintf ("[%06lx] %s,%d: Adjust B invalid L23 parameters %04x",
  12679. UnMapId (Id), (char *)(FILE_), __LINE__, Info));
  12680. break;
  12681. }
  12682. plci->internal_command = plci->adjust_b_command;
  12683. nl_req_ncci (plci, ASSIGN, 0);
  12684. send_req (plci);
  12685. plci->adjust_b_state = ADJUST_B_ASSIGN_L23_2;
  12686. break;
  12687. }
  12688. plci->adjust_b_state = ADJUST_B_ASSIGN_L23_2;
  12689. Rc = ASSIGN_OK;
  12690. case ADJUST_B_ASSIGN_L23_2:
  12691. if ((Rc != OK) && (Rc != OK_FC) && (Rc != ASSIGN_OK))
  12692. {
  12693. dbug (1, dprintf ("[%06lx] %s,%d: Adjust B assign failed %02x",
  12694. UnMapId (Id), (char *)(FILE_), __LINE__, Rc));
  12695. Info = _WRONG_STATE;
  12696. break;
  12697. }
  12698. if (plci->adjust_b_mode & ADJUST_B_MODE_ASSIGN_L23)
  12699. {
  12700. if (Rc != ASSIGN_OK)
  12701. {
  12702. plci->internal_command = plci->adjust_b_command;
  12703. break;
  12704. }
  12705. }
  12706. if (plci->adjust_b_mode & ADJUST_B_MODE_USER_CONNECT)
  12707. {
  12708. plci->adjust_b_restore = TRUE;
  12709. break;
  12710. }
  12711. plci->adjust_b_state = ADJUST_B_CONNECT_1;
  12712. case ADJUST_B_CONNECT_1:
  12713. if (plci->adjust_b_mode & ADJUST_B_MODE_CONNECT)
  12714. {
  12715. plci->internal_command = plci->adjust_b_command;
  12716. if (plci_nl_busy (plci))
  12717. break;
  12718. nl_req_ncci (plci, N_CONNECT, 0);
  12719. send_req (plci);
  12720. plci->adjust_b_state = ADJUST_B_CONNECT_2;
  12721. break;
  12722. }
  12723. plci->adjust_b_state = ADJUST_B_RESTORE_DTMF_1;
  12724. Rc = OK;
  12725. case ADJUST_B_CONNECT_2:
  12726. case ADJUST_B_CONNECT_3:
  12727. case ADJUST_B_CONNECT_4:
  12728. if ((Rc != OK) && (Rc != OK_FC) && (Rc != 0))
  12729. {
  12730. dbug (1, dprintf ("[%06lx] %s,%d: Adjust B connect failed %02x",
  12731. UnMapId (Id), (char *)(FILE_), __LINE__, Rc));
  12732. Info = _WRONG_STATE;
  12733. break;
  12734. }
  12735. if (Rc == OK)
  12736. {
  12737. if (plci->adjust_b_mode & ADJUST_B_MODE_CONNECT)
  12738. {
  12739. get_ncci (plci, (byte)(Id >> 16), plci->adjust_b_ncci);
  12740. Id = (Id & 0xffff) | (((dword)(plci->adjust_b_ncci)) << 16);
  12741. }
  12742. if (plci->adjust_b_state == ADJUST_B_CONNECT_2)
  12743. plci->adjust_b_state = ADJUST_B_CONNECT_3;
  12744. else if (plci->adjust_b_state == ADJUST_B_CONNECT_4)
  12745. plci->adjust_b_state = ADJUST_B_RESTORE_DTMF_1;
  12746. }
  12747. else if (Rc == 0)
  12748. {
  12749. if (plci->adjust_b_state == ADJUST_B_CONNECT_2)
  12750. plci->adjust_b_state = ADJUST_B_CONNECT_4;
  12751. else if (plci->adjust_b_state == ADJUST_B_CONNECT_3)
  12752. plci->adjust_b_state = ADJUST_B_RESTORE_DTMF_1;
  12753. }
  12754. if (plci->adjust_b_state != ADJUST_B_RESTORE_DTMF_1)
  12755. {
  12756. plci->internal_command = plci->adjust_b_command;
  12757. break;
  12758. }
  12759. Rc = OK;
  12760. case ADJUST_B_RESTORE_DTMF_1:
  12761. case ADJUST_B_RESTORE_DTMF_2:
  12762. if (plci->adjust_b_mode & ADJUST_B_MODE_RESTORE)
  12763. {
  12764. Info = dtmf_restore_config (Id, plci, Rc);
  12765. if ((Info != GOOD) || plci->internal_command)
  12766. break;
  12767. }
  12768. plci->adjust_b_state = ADJUST_B_RESTORE_MIXER_1;
  12769. Rc = OK;
  12770. case ADJUST_B_RESTORE_MIXER_1:
  12771. case ADJUST_B_RESTORE_MIXER_2:
  12772. case ADJUST_B_RESTORE_MIXER_3:
  12773. case ADJUST_B_RESTORE_MIXER_4:
  12774. case ADJUST_B_RESTORE_MIXER_5:
  12775. case ADJUST_B_RESTORE_MIXER_6:
  12776. case ADJUST_B_RESTORE_MIXER_7:
  12777. if (plci->adjust_b_mode & ADJUST_B_MODE_RESTORE)
  12778. {
  12779. Info = mixer_restore_config (Id, plci, Rc);
  12780. if ((Info != GOOD) || plci->internal_command)
  12781. break;
  12782. }
  12783. plci->adjust_b_state = ADJUST_B_END;
  12784. case ADJUST_B_END:
  12785. break;
  12786. }
  12787. return (Info);
  12788. }
  12789. static void adjust_b1_resource (dword Id, PLCI *plci, API_SAVE *bp_msg, word b1_facilities, word internal_command)
  12790. {
  12791. dbug (1, dprintf ("[%06lx] %s,%d: adjust_b1_resource %d %04x",
  12792. UnMapId (Id), (char *)(FILE_), __LINE__,
  12793. plci->B1_resource, b1_facilities));
  12794. plci->adjust_b_parms_msg = bp_msg;
  12795. plci->adjust_b_facilities = b1_facilities;
  12796. plci->adjust_b_command = internal_command;
  12797. plci->adjust_b_ncci = (word)(Id >> 16);
  12798. if ((bp_msg == NULL) && (plci->B1_resource == 0))
  12799. plci->adjust_b_mode = ADJUST_B_MODE_SAVE | ADJUST_B_MODE_NO_RESOURCE | ADJUST_B_MODE_SWITCH_L1;
  12800. else
  12801. plci->adjust_b_mode = ADJUST_B_MODE_SAVE | ADJUST_B_MODE_SWITCH_L1 | ADJUST_B_MODE_RESTORE;
  12802. plci->adjust_b_state = ADJUST_B_START;
  12803. dbug (1, dprintf ("[%06lx] %s,%d: Adjust B1 resource %d %04x...",
  12804. UnMapId (Id), (char *)(FILE_), __LINE__,
  12805. plci->B1_resource, b1_facilities));
  12806. }
  12807. static void adjust_b_restore (dword Id, PLCI *plci, byte Rc)
  12808. {
  12809. word internal_command;
  12810. dbug (1, dprintf ("[%06lx] %s,%d: adjust_b_restore %02x %04x",
  12811. UnMapId (Id), (char *)(FILE_), __LINE__, Rc, plci->internal_command));
  12812. internal_command = plci->internal_command;
  12813. plci->internal_command = 0;
  12814. switch (internal_command)
  12815. {
  12816. default:
  12817. plci->command = 0;
  12818. if (plci->req_in != 0)
  12819. {
  12820. plci->internal_command = ADJUST_B_RESTORE_1;
  12821. break;
  12822. }
  12823. Rc = OK;
  12824. case ADJUST_B_RESTORE_1:
  12825. if ((Rc != OK) && (Rc != OK_FC))
  12826. {
  12827. dbug (1, dprintf ("[%06lx] %s,%d: Adjust B enqueued failed %02x",
  12828. UnMapId (Id), (char *)(FILE_), __LINE__, Rc));
  12829. }
  12830. plci->adjust_b_parms_msg = NULL;
  12831. plci->adjust_b_facilities = plci->B1_facilities;
  12832. plci->adjust_b_command = ADJUST_B_RESTORE_2;
  12833. plci->adjust_b_ncci = (word)(Id >> 16);
  12834. plci->adjust_b_mode = ADJUST_B_MODE_RESTORE;
  12835. plci->adjust_b_state = ADJUST_B_START;
  12836. dbug (1, dprintf ("[%06lx] %s,%d: Adjust B restore...",
  12837. UnMapId (Id), (char *)(FILE_), __LINE__));
  12838. case ADJUST_B_RESTORE_2:
  12839. if (adjust_b_process (Id, plci, Rc) != GOOD)
  12840. {
  12841. dbug (1, dprintf ("[%06lx] %s,%d: Adjust B restore failed",
  12842. UnMapId (Id), (char *)(FILE_), __LINE__));
  12843. }
  12844. if (plci->internal_command)
  12845. break;
  12846. break;
  12847. }
  12848. }
  12849. static void reset_b3_command (dword Id, PLCI *plci, byte Rc)
  12850. {
  12851. word Info;
  12852. word internal_command;
  12853. dbug (1, dprintf ("[%06lx] %s,%d: reset_b3_command %02x %04x",
  12854. UnMapId (Id), (char *)(FILE_), __LINE__, Rc, plci->internal_command));
  12855. Info = GOOD;
  12856. internal_command = plci->internal_command;
  12857. plci->internal_command = 0;
  12858. switch (internal_command)
  12859. {
  12860. default:
  12861. plci->command = 0;
  12862. plci->adjust_b_parms_msg = NULL;
  12863. plci->adjust_b_facilities = plci->B1_facilities;
  12864. plci->adjust_b_command = RESET_B3_COMMAND_1;
  12865. plci->adjust_b_ncci = (word)(Id >> 16);
  12866. plci->adjust_b_mode = ADJUST_B_MODE_REMOVE_L23 | ADJUST_B_MODE_ASSIGN_L23 | ADJUST_B_MODE_CONNECT;
  12867. plci->adjust_b_state = ADJUST_B_START;
  12868. dbug (1, dprintf ("[%06lx] %s,%d: Reset B3...",
  12869. UnMapId (Id), (char *)(FILE_), __LINE__));
  12870. case RESET_B3_COMMAND_1:
  12871. Info = adjust_b_process (Id, plci, Rc);
  12872. if (Info != GOOD)
  12873. {
  12874. dbug (1, dprintf ("[%06lx] %s,%d: Reset failed",
  12875. UnMapId (Id), (char *)(FILE_), __LINE__));
  12876. break;
  12877. }
  12878. if (plci->internal_command)
  12879. return;
  12880. break;
  12881. }
  12882. /* sendf (plci->appl, _RESET_B3_R | CONFIRM, Id, plci->number, "w", Info);*/
  12883. sendf(plci->appl,_RESET_B3_I,Id,0,"s","");
  12884. }
  12885. static void select_b_command (dword Id, PLCI *plci, byte Rc)
  12886. {
  12887. word Info;
  12888. word internal_command;
  12889. byte esc_chi[3];
  12890. dbug (1, dprintf ("[%06lx] %s,%d: select_b_command %02x %04x",
  12891. UnMapId (Id), (char *)(FILE_), __LINE__, Rc, plci->internal_command));
  12892. Info = GOOD;
  12893. internal_command = plci->internal_command;
  12894. plci->internal_command = 0;
  12895. switch (internal_command)
  12896. {
  12897. default:
  12898. plci->command = 0;
  12899. plci->adjust_b_parms_msg = &plci->saved_msg;
  12900. if ((plci->tel == ADV_VOICE) && (plci == plci->adapter->AdvSignalPLCI))
  12901. plci->adjust_b_facilities = plci->B1_facilities | B1_FACILITY_VOICE;
  12902. else
  12903. plci->adjust_b_facilities = plci->B1_facilities & ~B1_FACILITY_VOICE;
  12904. plci->adjust_b_command = SELECT_B_COMMAND_1;
  12905. plci->adjust_b_ncci = (word)(Id >> 16);
  12906. if (plci->saved_msg.parms[0].length == 0)
  12907. {
  12908. plci->adjust_b_mode = ADJUST_B_MODE_SAVE | ADJUST_B_MODE_REMOVE_L23 | ADJUST_B_MODE_SWITCH_L1 |
  12909. ADJUST_B_MODE_NO_RESOURCE;
  12910. }
  12911. else
  12912. {
  12913. plci->adjust_b_mode = ADJUST_B_MODE_SAVE | ADJUST_B_MODE_REMOVE_L23 | ADJUST_B_MODE_SWITCH_L1 |
  12914. ADJUST_B_MODE_ASSIGN_L23 | ADJUST_B_MODE_USER_CONNECT | ADJUST_B_MODE_RESTORE;
  12915. }
  12916. plci->adjust_b_state = ADJUST_B_START;
  12917. dbug (1, dprintf ("[%06lx] %s,%d: Select B protocol...",
  12918. UnMapId (Id), (char *)(FILE_), __LINE__));
  12919. case SELECT_B_COMMAND_1:
  12920. Info = adjust_b_process (Id, plci, Rc);
  12921. if (Info != GOOD)
  12922. {
  12923. dbug (1, dprintf ("[%06lx] %s,%d: Select B protocol failed",
  12924. UnMapId (Id), (char *)(FILE_), __LINE__));
  12925. break;
  12926. }
  12927. if (plci->internal_command)
  12928. return;
  12929. if (plci->tel == ADV_VOICE)
  12930. {
  12931. esc_chi[0] = 0x02;
  12932. esc_chi[1] = 0x18;
  12933. esc_chi[2] = plci->b_channel;
  12934. SetVoiceChannel (plci->adapter->AdvCodecPLCI, esc_chi, plci->adapter);
  12935. }
  12936. break;
  12937. }
  12938. sendf (plci->appl, _SELECT_B_REQ | CONFIRM, Id, plci->number, "w", Info);
  12939. }
  12940. static void fax_connect_ack_command (dword Id, PLCI *plci, byte Rc)
  12941. {
  12942. word Info;
  12943. word internal_command;
  12944. dbug (1, dprintf ("[%06lx] %s,%d: fax_connect_ack_command %02x %04x",
  12945. UnMapId (Id), (char *)(FILE_), __LINE__, Rc, plci->internal_command));
  12946. Info = GOOD;
  12947. internal_command = plci->internal_command;
  12948. plci->internal_command = 0;
  12949. switch (internal_command)
  12950. {
  12951. default:
  12952. plci->command = 0;
  12953. case FAX_CONNECT_ACK_COMMAND_1:
  12954. if (plci_nl_busy (plci))
  12955. {
  12956. plci->internal_command = FAX_CONNECT_ACK_COMMAND_1;
  12957. return;
  12958. }
  12959. plci->internal_command = FAX_CONNECT_ACK_COMMAND_2;
  12960. plci->NData[0].P = plci->fax_connect_info_buffer;
  12961. plci->NData[0].PLength = plci->fax_connect_info_length;
  12962. plci->NL.X = plci->NData;
  12963. plci->NL.ReqCh = 0;
  12964. plci->NL.Req = plci->nl_req = (byte) N_CONNECT_ACK;
  12965. plci->adapter->request (&plci->NL);
  12966. return;
  12967. case FAX_CONNECT_ACK_COMMAND_2:
  12968. if ((Rc != OK) && (Rc != OK_FC))
  12969. {
  12970. dbug (1, dprintf ("[%06lx] %s,%d: FAX issue CONNECT ACK failed %02x",
  12971. UnMapId (Id), (char *)(FILE_), __LINE__, Rc));
  12972. break;
  12973. }
  12974. }
  12975. if ((plci->ncpi_state & NCPI_VALID_CONNECT_B3_ACT)
  12976. && !(plci->ncpi_state & NCPI_CONNECT_B3_ACT_SENT))
  12977. {
  12978. if (plci->B3_prot == 4)
  12979. sendf(plci->appl,_CONNECT_B3_ACTIVE_I,Id,0,"s","");
  12980. else
  12981. sendf(plci->appl,_CONNECT_B3_ACTIVE_I,Id,0,"S",plci->ncpi_buffer);
  12982. plci->ncpi_state |= NCPI_CONNECT_B3_ACT_SENT;
  12983. }
  12984. }
  12985. static void fax_edata_ack_command (dword Id, PLCI *plci, byte Rc)
  12986. {
  12987. word Info;
  12988. word internal_command;
  12989. dbug (1, dprintf ("[%06lx] %s,%d: fax_edata_ack_command %02x %04x",
  12990. UnMapId (Id), (char *)(FILE_), __LINE__, Rc, plci->internal_command));
  12991. Info = GOOD;
  12992. internal_command = plci->internal_command;
  12993. plci->internal_command = 0;
  12994. switch (internal_command)
  12995. {
  12996. default:
  12997. plci->command = 0;
  12998. case FAX_EDATA_ACK_COMMAND_1:
  12999. if (plci_nl_busy (plci))
  13000. {
  13001. plci->internal_command = FAX_EDATA_ACK_COMMAND_1;
  13002. return;
  13003. }
  13004. plci->internal_command = FAX_EDATA_ACK_COMMAND_2;
  13005. plci->NData[0].P = plci->fax_connect_info_buffer;
  13006. plci->NData[0].PLength = plci->fax_edata_ack_length;
  13007. plci->NL.X = plci->NData;
  13008. plci->NL.ReqCh = 0;
  13009. plci->NL.Req = plci->nl_req = (byte) N_EDATA;
  13010. plci->adapter->request (&plci->NL);
  13011. return;
  13012. case FAX_EDATA_ACK_COMMAND_2:
  13013. if ((Rc != OK) && (Rc != OK_FC))
  13014. {
  13015. dbug (1, dprintf ("[%06lx] %s,%d: FAX issue EDATA ACK failed %02x",
  13016. UnMapId (Id), (char *)(FILE_), __LINE__, Rc));
  13017. break;
  13018. }
  13019. }
  13020. }
  13021. static void fax_connect_info_command (dword Id, PLCI *plci, byte Rc)
  13022. {
  13023. word Info;
  13024. word internal_command;
  13025. dbug (1, dprintf ("[%06lx] %s,%d: fax_connect_info_command %02x %04x",
  13026. UnMapId (Id), (char *)(FILE_), __LINE__, Rc, plci->internal_command));
  13027. Info = GOOD;
  13028. internal_command = plci->internal_command;
  13029. plci->internal_command = 0;
  13030. switch (internal_command)
  13031. {
  13032. default:
  13033. plci->command = 0;
  13034. case FAX_CONNECT_INFO_COMMAND_1:
  13035. if (plci_nl_busy (plci))
  13036. {
  13037. plci->internal_command = FAX_CONNECT_INFO_COMMAND_1;
  13038. return;
  13039. }
  13040. plci->internal_command = FAX_CONNECT_INFO_COMMAND_2;
  13041. plci->NData[0].P = plci->fax_connect_info_buffer;
  13042. plci->NData[0].PLength = plci->fax_connect_info_length;
  13043. plci->NL.X = plci->NData;
  13044. plci->NL.ReqCh = 0;
  13045. plci->NL.Req = plci->nl_req = (byte) N_EDATA;
  13046. plci->adapter->request (&plci->NL);
  13047. return;
  13048. case FAX_CONNECT_INFO_COMMAND_2:
  13049. if ((Rc != OK) && (Rc != OK_FC))
  13050. {
  13051. dbug (1, dprintf ("[%06lx] %s,%d: FAX setting connect info failed %02x",
  13052. UnMapId (Id), (char *)(FILE_), __LINE__, Rc));
  13053. Info = _WRONG_STATE;
  13054. break;
  13055. }
  13056. if (plci_nl_busy (plci))
  13057. {
  13058. plci->internal_command = FAX_CONNECT_INFO_COMMAND_2;
  13059. return;
  13060. }
  13061. plci->command = _CONNECT_B3_R;
  13062. nl_req_ncci (plci, N_CONNECT, 0);
  13063. send_req (plci);
  13064. return;
  13065. }
  13066. sendf (plci->appl, _CONNECT_B3_R | CONFIRM, Id, plci->number, "w", Info);
  13067. }
  13068. static void fax_adjust_b23_command (dword Id, PLCI *plci, byte Rc)
  13069. {
  13070. word Info;
  13071. word internal_command;
  13072. dbug (1, dprintf ("[%06lx] %s,%d: fax_adjust_b23_command %02x %04x",
  13073. UnMapId (Id), (char *)(FILE_), __LINE__, Rc, plci->internal_command));
  13074. Info = GOOD;
  13075. internal_command = plci->internal_command;
  13076. plci->internal_command = 0;
  13077. switch (internal_command)
  13078. {
  13079. default:
  13080. plci->command = 0;
  13081. plci->adjust_b_parms_msg = NULL;
  13082. plci->adjust_b_facilities = plci->B1_facilities;
  13083. plci->adjust_b_command = FAX_ADJUST_B23_COMMAND_1;
  13084. plci->adjust_b_ncci = (word)(Id >> 16);
  13085. plci->adjust_b_mode = ADJUST_B_MODE_REMOVE_L23 | ADJUST_B_MODE_ASSIGN_L23;
  13086. plci->adjust_b_state = ADJUST_B_START;
  13087. dbug (1, dprintf ("[%06lx] %s,%d: FAX adjust B23...",
  13088. UnMapId (Id), (char *)(FILE_), __LINE__));
  13089. case FAX_ADJUST_B23_COMMAND_1:
  13090. Info = adjust_b_process (Id, plci, Rc);
  13091. if (Info != GOOD)
  13092. {
  13093. dbug (1, dprintf ("[%06lx] %s,%d: FAX adjust failed",
  13094. UnMapId (Id), (char *)(FILE_), __LINE__));
  13095. break;
  13096. }
  13097. if (plci->internal_command)
  13098. return;
  13099. case FAX_ADJUST_B23_COMMAND_2:
  13100. if (plci_nl_busy (plci))
  13101. {
  13102. plci->internal_command = FAX_ADJUST_B23_COMMAND_2;
  13103. return;
  13104. }
  13105. plci->command = _CONNECT_B3_R;
  13106. nl_req_ncci (plci, N_CONNECT, 0);
  13107. send_req (plci);
  13108. return;
  13109. }
  13110. sendf (plci->appl, _CONNECT_B3_R | CONFIRM, Id, plci->number, "w", Info);
  13111. }
  13112. static void fax_disconnect_command (dword Id, PLCI *plci, byte Rc)
  13113. {
  13114. word internal_command;
  13115. dbug (1, dprintf ("[%06lx] %s,%d: fax_disconnect_command %02x %04x",
  13116. UnMapId (Id), (char *)(FILE_), __LINE__, Rc, plci->internal_command));
  13117. internal_command = plci->internal_command;
  13118. plci->internal_command = 0;
  13119. switch (internal_command)
  13120. {
  13121. default:
  13122. plci->command = 0;
  13123. plci->internal_command = FAX_DISCONNECT_COMMAND_1;
  13124. return;
  13125. case FAX_DISCONNECT_COMMAND_1:
  13126. case FAX_DISCONNECT_COMMAND_2:
  13127. case FAX_DISCONNECT_COMMAND_3:
  13128. if ((Rc != OK) && (Rc != OK_FC) && (Rc != 0))
  13129. {
  13130. dbug (1, dprintf ("[%06lx] %s,%d: FAX disconnect EDATA failed %02x",
  13131. UnMapId (Id), (char *)(FILE_), __LINE__, Rc));
  13132. break;
  13133. }
  13134. if (Rc == OK)
  13135. {
  13136. if ((internal_command == FAX_DISCONNECT_COMMAND_1)
  13137. || (internal_command == FAX_DISCONNECT_COMMAND_2))
  13138. {
  13139. plci->internal_command = FAX_DISCONNECT_COMMAND_2;
  13140. }
  13141. }
  13142. else if (Rc == 0)
  13143. {
  13144. if (internal_command == FAX_DISCONNECT_COMMAND_1)
  13145. plci->internal_command = FAX_DISCONNECT_COMMAND_3;
  13146. }
  13147. return;
  13148. }
  13149. }
  13150. static void rtp_connect_b3_req_command (dword Id, PLCI *plci, byte Rc)
  13151. {
  13152. word Info;
  13153. word internal_command;
  13154. dbug (1, dprintf ("[%06lx] %s,%d: rtp_connect_b3_req_command %02x %04x",
  13155. UnMapId (Id), (char *)(FILE_), __LINE__, Rc, plci->internal_command));
  13156. Info = GOOD;
  13157. internal_command = plci->internal_command;
  13158. plci->internal_command = 0;
  13159. switch (internal_command)
  13160. {
  13161. default:
  13162. plci->command = 0;
  13163. case RTP_CONNECT_B3_REQ_COMMAND_1:
  13164. if (plci_nl_busy (plci))
  13165. {
  13166. plci->internal_command = RTP_CONNECT_B3_REQ_COMMAND_1;
  13167. return;
  13168. }
  13169. plci->internal_command = RTP_CONNECT_B3_REQ_COMMAND_2;
  13170. nl_req_ncci (plci, N_CONNECT, 0);
  13171. send_req (plci);
  13172. return;
  13173. case RTP_CONNECT_B3_REQ_COMMAND_2:
  13174. if ((Rc != OK) && (Rc != OK_FC))
  13175. {
  13176. dbug (1, dprintf ("[%06lx] %s,%d: RTP setting connect info failed %02x",
  13177. UnMapId (Id), (char *)(FILE_), __LINE__, Rc));
  13178. Info = _WRONG_STATE;
  13179. break;
  13180. }
  13181. if (plci_nl_busy (plci))
  13182. {
  13183. plci->internal_command = RTP_CONNECT_B3_REQ_COMMAND_2;
  13184. return;
  13185. }
  13186. plci->internal_command = RTP_CONNECT_B3_REQ_COMMAND_3;
  13187. plci->NData[0].PLength = plci->internal_req_buffer[0];
  13188. plci->NData[0].P = plci->internal_req_buffer + 1;
  13189. plci->NL.X = plci->NData;
  13190. plci->NL.ReqCh = 0;
  13191. plci->NL.Req = plci->nl_req = (byte) N_UDATA;
  13192. plci->adapter->request (&plci->NL);
  13193. break;
  13194. case RTP_CONNECT_B3_REQ_COMMAND_3:
  13195. return;
  13196. }
  13197. sendf (plci->appl, _CONNECT_B3_R | CONFIRM, Id, plci->number, "w", Info);
  13198. }
  13199. static void rtp_connect_b3_res_command (dword Id, PLCI *plci, byte Rc)
  13200. {
  13201. word Info;
  13202. word internal_command;
  13203. dbug (1, dprintf ("[%06lx] %s,%d: rtp_connect_b3_res_command %02x %04x",
  13204. UnMapId (Id), (char *)(FILE_), __LINE__, Rc, plci->internal_command));
  13205. Info = GOOD;
  13206. internal_command = plci->internal_command;
  13207. plci->internal_command = 0;
  13208. switch (internal_command)
  13209. {
  13210. default:
  13211. plci->command = 0;
  13212. case RTP_CONNECT_B3_RES_COMMAND_1:
  13213. if (plci_nl_busy (plci))
  13214. {
  13215. plci->internal_command = RTP_CONNECT_B3_RES_COMMAND_1;
  13216. return;
  13217. }
  13218. plci->internal_command = RTP_CONNECT_B3_RES_COMMAND_2;
  13219. nl_req_ncci (plci, N_CONNECT_ACK, (byte)(Id >> 16));
  13220. send_req (plci);
  13221. return;
  13222. case RTP_CONNECT_B3_RES_COMMAND_2:
  13223. if ((Rc != OK) && (Rc != OK_FC))
  13224. {
  13225. dbug (1, dprintf ("[%06lx] %s,%d: RTP setting connect resp info failed %02x",
  13226. UnMapId (Id), (char *)(FILE_), __LINE__, Rc));
  13227. Info = _WRONG_STATE;
  13228. break;
  13229. }
  13230. if (plci_nl_busy (plci))
  13231. {
  13232. plci->internal_command = RTP_CONNECT_B3_RES_COMMAND_2;
  13233. return;
  13234. }
  13235. sendf (plci->appl, _CONNECT_B3_ACTIVE_I, Id, 0, "s", "");
  13236. plci->internal_command = RTP_CONNECT_B3_RES_COMMAND_3;
  13237. plci->NData[0].PLength = plci->internal_req_buffer[0];
  13238. plci->NData[0].P = plci->internal_req_buffer + 1;
  13239. plci->NL.X = plci->NData;
  13240. plci->NL.ReqCh = 0;
  13241. plci->NL.Req = plci->nl_req = (byte) N_UDATA;
  13242. plci->adapter->request (&plci->NL);
  13243. return;
  13244. case RTP_CONNECT_B3_RES_COMMAND_3:
  13245. return;
  13246. }
  13247. }
  13248. static void hold_save_command (dword Id, PLCI *plci, byte Rc)
  13249. {
  13250. byte SS_Ind[] = "\x05\x02\x00\x02\x00\x00"; /* Hold_Ind struct*/
  13251. word Info;
  13252. word internal_command;
  13253. dbug (1, dprintf ("[%06lx] %s,%d: hold_save_command %02x %04x",
  13254. UnMapId (Id), (char *)(FILE_), __LINE__, Rc, plci->internal_command));
  13255. Info = GOOD;
  13256. internal_command = plci->internal_command;
  13257. plci->internal_command = 0;
  13258. switch (internal_command)
  13259. {
  13260. default:
  13261. if (!plci->NL.Id)
  13262. break;
  13263. plci->command = 0;
  13264. plci->adjust_b_parms_msg = NULL;
  13265. plci->adjust_b_facilities = plci->B1_facilities;
  13266. plci->adjust_b_command = HOLD_SAVE_COMMAND_1;
  13267. plci->adjust_b_ncci = (word)(Id >> 16);
  13268. plci->adjust_b_mode = ADJUST_B_MODE_SAVE | ADJUST_B_MODE_REMOVE_L23;
  13269. plci->adjust_b_state = ADJUST_B_START;
  13270. dbug (1, dprintf ("[%06lx] %s,%d: HOLD save...",
  13271. UnMapId (Id), (char *)(FILE_), __LINE__));
  13272. case HOLD_SAVE_COMMAND_1:
  13273. Info = adjust_b_process (Id, plci, Rc);
  13274. if (Info != GOOD)
  13275. {
  13276. dbug (1, dprintf ("[%06lx] %s,%d: HOLD save failed",
  13277. UnMapId (Id), (char *)(FILE_), __LINE__));
  13278. break;
  13279. }
  13280. if (plci->internal_command)
  13281. return;
  13282. }
  13283. sendf (plci->appl, _FACILITY_I, Id & 0xffffL, 0, "ws", 3, SS_Ind);
  13284. }
  13285. static void retrieve_restore_command (dword Id, PLCI *plci, byte Rc)
  13286. {
  13287. byte SS_Ind[] = "\x05\x03\x00\x02\x00\x00"; /* Retrieve_Ind struct*/
  13288. word Info;
  13289. word internal_command;
  13290. dbug (1, dprintf ("[%06lx] %s,%d: retrieve_restore_command %02x %04x",
  13291. UnMapId (Id), (char *)(FILE_), __LINE__, Rc, plci->internal_command));
  13292. Info = GOOD;
  13293. internal_command = plci->internal_command;
  13294. plci->internal_command = 0;
  13295. switch (internal_command)
  13296. {
  13297. default:
  13298. plci->command = 0;
  13299. plci->adjust_b_parms_msg = NULL;
  13300. plci->adjust_b_facilities = plci->B1_facilities;
  13301. plci->adjust_b_command = RETRIEVE_RESTORE_COMMAND_1;
  13302. plci->adjust_b_ncci = (word)(Id >> 16);
  13303. plci->adjust_b_mode = ADJUST_B_MODE_ASSIGN_L23 | ADJUST_B_MODE_USER_CONNECT | ADJUST_B_MODE_RESTORE;
  13304. plci->adjust_b_state = ADJUST_B_START;
  13305. dbug (1, dprintf ("[%06lx] %s,%d: RETRIEVE restore...",
  13306. UnMapId (Id), (char *)(FILE_), __LINE__));
  13307. case RETRIEVE_RESTORE_COMMAND_1:
  13308. Info = adjust_b_process (Id, plci, Rc);
  13309. if (Info != GOOD)
  13310. {
  13311. dbug (1, dprintf ("[%06lx] %s,%d: RETRIEVE restore failed",
  13312. UnMapId (Id), (char *)(FILE_), __LINE__));
  13313. break;
  13314. }
  13315. if (plci->internal_command)
  13316. return;
  13317. }
  13318. sendf (plci->appl, _FACILITY_I, Id & 0xffffL, 0, "ws", 3, SS_Ind);
  13319. }
  13320. static void init_b1_config (PLCI *plci)
  13321. {
  13322. dbug (1, dprintf ("[%06lx] %s,%d: init_b1_config",
  13323. (dword)((plci->Id << 8) | UnMapController (plci->adapter->Id)),
  13324. (char *)(FILE_), __LINE__));
  13325. plci->B1_resource = 0;
  13326. plci->B1_facilities = 0;
  13327. plci->li_bchannel_id = 0;
  13328. mixer_clear_config (plci);
  13329. ec_clear_config (plci);
  13330. dtmf_rec_clear_config (plci);
  13331. dtmf_send_clear_config (plci);
  13332. dtmf_parameter_clear_config (plci);
  13333. adv_voice_clear_config (plci);
  13334. adjust_b_clear (plci);
  13335. }
  13336. static void clear_b1_config (PLCI *plci)
  13337. {
  13338. dbug (1, dprintf ("[%06lx] %s,%d: clear_b1_config",
  13339. (dword)((plci->Id << 8) | UnMapController (plci->adapter->Id)),
  13340. (char *)(FILE_), __LINE__));
  13341. adv_voice_clear_config (plci);
  13342. adjust_b_clear (plci);
  13343. ec_clear_config (plci);
  13344. dtmf_rec_clear_config (plci);
  13345. dtmf_send_clear_config (plci);
  13346. dtmf_parameter_clear_config (plci);
  13347. if ((plci->li_bchannel_id != 0)
  13348. && (li_config_table[plci->adapter->li_base + (plci->li_bchannel_id - 1)].plci == plci))
  13349. {
  13350. mixer_clear_config (plci);
  13351. li_config_table[plci->adapter->li_base + (plci->li_bchannel_id - 1)].plci = NULL;
  13352. plci->li_bchannel_id = 0;
  13353. }
  13354. plci->B1_resource = 0;
  13355. plci->B1_facilities = 0;
  13356. }
  13357. /* -----------------------------------------------------------------
  13358. XON protocol local helpers
  13359. ----------------------------------------------------------------- */
  13360. static void channel_flow_control_remove (PLCI * plci) {
  13361. DIVA_CAPI_ADAPTER * a = plci->adapter;
  13362. word i;
  13363. for(i=1;i<MAX_NL_CHANNEL+1;i++) {
  13364. if (a->ch_flow_plci[i] == plci->Id) {
  13365. a->ch_flow_plci[i] = 0;
  13366. a->ch_flow_control[i] = 0;
  13367. }
  13368. }
  13369. }
  13370. static void channel_x_on (PLCI * plci, byte ch) {
  13371. DIVA_CAPI_ADAPTER * a = plci->adapter;
  13372. if (a->ch_flow_control[ch] & N_XON_SENT) {
  13373. a->ch_flow_control[ch] &= ~N_XON_SENT;
  13374. }
  13375. }
  13376. static void channel_x_off (PLCI * plci, byte ch, byte flag) {
  13377. DIVA_CAPI_ADAPTER * a = plci->adapter;
  13378. if ((a->ch_flow_control[ch] & N_RX_FLOW_CONTROL_MASK) == 0) {
  13379. a->ch_flow_control[ch] |= (N_CH_XOFF | flag);
  13380. a->ch_flow_plci[ch] = plci->Id;
  13381. a->ch_flow_control_pending++;
  13382. }
  13383. }
  13384. static void channel_request_xon (PLCI * plci, byte ch) {
  13385. DIVA_CAPI_ADAPTER * a = plci->adapter;
  13386. if (a->ch_flow_control[ch] & N_CH_XOFF) {
  13387. a->ch_flow_control[ch] |= N_XON_REQ;
  13388. a->ch_flow_control[ch] &= ~N_CH_XOFF;
  13389. a->ch_flow_control[ch] &= ~N_XON_CONNECT_IND;
  13390. }
  13391. }
  13392. static void channel_xmit_extended_xon (PLCI * plci) {
  13393. DIVA_CAPI_ADAPTER * a;
  13394. int max_ch = sizeof(a->ch_flow_control)/sizeof(a->ch_flow_control[0]);
  13395. int i, one_requested = 0;
  13396. if ((!plci) || (!plci->Id) || ((a = plci->adapter) == 0)) {
  13397. return;
  13398. }
  13399. for (i = 0; i < max_ch; i++) {
  13400. if ((a->ch_flow_control[i] & N_CH_XOFF) &&
  13401. (a->ch_flow_control[i] & N_XON_CONNECT_IND) &&
  13402. (plci->Id == a->ch_flow_plci[i])) {
  13403. channel_request_xon (plci, (byte)i);
  13404. one_requested = 1;
  13405. }
  13406. }
  13407. if (one_requested) {
  13408. channel_xmit_xon (plci);
  13409. }
  13410. }
  13411. /*
  13412. Try to xmit next X_ON
  13413. */
  13414. static int find_channel_with_pending_x_on (DIVA_CAPI_ADAPTER * a, PLCI * plci) {
  13415. int max_ch = sizeof(a->ch_flow_control)/sizeof(a->ch_flow_control[0]);
  13416. int i;
  13417. if (!(plci->adapter->manufacturer_features & MANUFACTURER_FEATURE_XONOFF_FLOW_CONTROL)) {
  13418. return (0);
  13419. }
  13420. if (a->last_flow_control_ch >= max_ch) {
  13421. a->last_flow_control_ch = 1;
  13422. }
  13423. for (i=a->last_flow_control_ch; i < max_ch; i++) {
  13424. if ((a->ch_flow_control[i] & N_XON_REQ) &&
  13425. (plci->Id == a->ch_flow_plci[i])) {
  13426. a->last_flow_control_ch = i+1;
  13427. return (i);
  13428. }
  13429. }
  13430. for (i = 1; i < a->last_flow_control_ch; i++) {
  13431. if ((a->ch_flow_control[i] & N_XON_REQ) &&
  13432. (plci->Id == a->ch_flow_plci[i])) {
  13433. a->last_flow_control_ch = i+1;
  13434. return (i);
  13435. }
  13436. }
  13437. return (0);
  13438. }
  13439. static void channel_xmit_xon (PLCI * plci) {
  13440. DIVA_CAPI_ADAPTER * a = plci->adapter;
  13441. byte ch;
  13442. if (plci->nl_req || !plci->NL.Id || plci->nl_remove_id) {
  13443. return;
  13444. }
  13445. if ((ch = (byte)find_channel_with_pending_x_on (a, plci)) == 0) {
  13446. return;
  13447. }
  13448. a->ch_flow_control[ch] &= ~N_XON_REQ;
  13449. a->ch_flow_control[ch] |= N_XON_SENT;
  13450. plci->NL.Req = plci->nl_req = (byte)N_XON;
  13451. plci->NL.ReqCh = ch;
  13452. plci->NL.X = plci->NData;
  13453. plci->NL.XNum = 1;
  13454. plci->NData[0].P = &plci->RBuffer[0];
  13455. plci->NData[0].PLength = 0;
  13456. plci->adapter->request(&plci->NL);
  13457. }
  13458. static int channel_can_xon (PLCI * plci, byte ch) {
  13459. APPL * APPLptr;
  13460. DIVA_CAPI_ADAPTER * a;
  13461. word NCCIcode;
  13462. dword count;
  13463. word Num;
  13464. word i;
  13465. APPLptr = plci->appl;
  13466. a = plci->adapter;
  13467. if (!APPLptr)
  13468. return (0);
  13469. NCCIcode = a->ch_ncci[ch] | (((word) a->Id) << 8);
  13470. /* count all buffers within the Application pool */
  13471. /* belonging to the same NCCI. XON if a first is */
  13472. /* used. */
  13473. count = 0;
  13474. Num = 0xffff;
  13475. for(i=0; i<APPLptr->MaxBuffer; i++) {
  13476. if(NCCIcode==APPLptr->DataNCCI[i]) count++;
  13477. if(!APPLptr->DataNCCI[i] && Num==0xffff) Num = i;
  13478. }
  13479. if ((count > 2) || (Num == 0xffff)) {
  13480. return (0);
  13481. }
  13482. return (1);
  13483. }
  13484. /*------------------------------------------------------------------*/
  13485. static word CPN_filter_ok(byte *cpn,DIVA_CAPI_ADAPTER * a,word offset)
  13486. {
  13487. return 1;
  13488. }
  13489. /**********************************************************************************/
  13490. /* function groups the listening applications according to the CIP mask and the */
  13491. /* Info_Mask. Each group gets just one Connect_Ind. Some application manufacturer */
  13492. /* are not multi-instance capable, so they start e.g. 30 applications what causes */
  13493. /* big problems on application level (one call, 30 Connect_Ind, ect). The */
  13494. /* function must be enabled by setting "a->group_optimization_enabled" from the */
  13495. /* OS specific part (per adapter). */
  13496. /**********************************************************************************/
  13497. static void group_optimization(DIVA_CAPI_ADAPTER * a, PLCI * plci)
  13498. {
  13499. word i,j,k,busy,group_found;
  13500. dword info_mask_group[MAX_CIP_TYPES];
  13501. dword cip_mask_group[MAX_CIP_TYPES];
  13502. word appl_number_group_type[MAX_APPL];
  13503. PLCI *auxplci;
  13504. set_group_ind_mask (plci); /* all APPLs within this inc. call are allowed to dial in */
  13505. if(!a->group_optimization_enabled)
  13506. {
  13507. dbug(1,dprintf("No group optimization"));
  13508. return;
  13509. }
  13510. dbug(1,dprintf("Group optimization = 0x%x...", a->group_optimization_enabled));
  13511. for(i=0;i<MAX_CIP_TYPES;i++)
  13512. {
  13513. info_mask_group[i] = 0;
  13514. cip_mask_group [i] = 0;
  13515. }
  13516. for(i=0;i<MAX_APPL;i++)
  13517. {
  13518. appl_number_group_type[i] = 0;
  13519. }
  13520. for(i=0; i<max_appl; i++) /* check if any multi instance capable application is present */
  13521. { /* group_optimization set to 1 means not to optimize multi-instance capable applications (default) */
  13522. if(application[i].Id && (application[i].MaxNCCI) > 1 && (a->CIP_Mask[i]) && (a->group_optimization_enabled ==1) )
  13523. {
  13524. dbug(1,dprintf("Multi-Instance capable, no optimization required"));
  13525. return; /* allow good application unfiltered access */
  13526. }
  13527. }
  13528. for(i=0; i<max_appl; i++) /* Build CIP Groups */
  13529. {
  13530. if(application[i].Id && a->CIP_Mask[i] )
  13531. {
  13532. for(k=0,busy=FALSE; k<a->max_plci; k++)
  13533. {
  13534. if(a->plci[k].Id)
  13535. {
  13536. auxplci = &a->plci[k];
  13537. if(auxplci->appl == &application[i]) /* application has a busy PLCI */
  13538. {
  13539. busy = TRUE;
  13540. dbug(1,dprintf("Appl 0x%x is busy",i+1));
  13541. }
  13542. else if(test_c_ind_mask_bit (auxplci, i)) /* application has an incoming call pending */
  13543. {
  13544. busy = TRUE;
  13545. dbug(1,dprintf("Appl 0x%x has inc. call pending",i+1));
  13546. }
  13547. }
  13548. }
  13549. for(j=0,group_found=0; j<=(MAX_CIP_TYPES) && !busy &&!group_found; j++) /* build groups with free applications only */
  13550. {
  13551. if(j==MAX_CIP_TYPES) /* all groups are in use but group still not found */
  13552. { /* the MAX_CIP_TYPES group enables all calls because of field overflow */
  13553. appl_number_group_type[i] = MAX_CIP_TYPES;
  13554. group_found=TRUE;
  13555. dbug(1,dprintf("Field overflow appl 0x%x",i+1));
  13556. }
  13557. else if( (info_mask_group[j]==a->CIP_Mask[i]) && (cip_mask_group[j]==a->Info_Mask[i]) )
  13558. { /* is group already present ? */
  13559. appl_number_group_type[i] = j|0x80; /* store the group number for each application */
  13560. group_found=TRUE;
  13561. 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]));
  13562. }
  13563. else if(!info_mask_group[j])
  13564. { /* establish a new group */
  13565. appl_number_group_type[i] = j|0x80; /* store the group number for each application */
  13566. info_mask_group[j] = a->CIP_Mask[i]; /* store the new CIP mask for the new group */
  13567. cip_mask_group[j] = a->Info_Mask[i]; /* store the new Info_Mask for this new group */
  13568. group_found=TRUE;
  13569. 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]));
  13570. }
  13571. }
  13572. }
  13573. }
  13574. for(i=0; i<max_appl; i++) /* Build group_optimization_mask_table */
  13575. {
  13576. if(appl_number_group_type[i]) /* application is free, has listens and is member of a group */
  13577. {
  13578. if(appl_number_group_type[i] == MAX_CIP_TYPES)
  13579. {
  13580. dbug(1,dprintf("OverflowGroup 0x%x, valid appl = 0x%x, call enabled",appl_number_group_type[i],i+1));
  13581. }
  13582. else
  13583. {
  13584. dbug(1,dprintf("Group 0x%x, valid appl = 0x%x",appl_number_group_type[i],i+1));
  13585. for(j=i+1; j<max_appl; j++) /* search other group members and mark them as busy */
  13586. {
  13587. if(appl_number_group_type[i] == appl_number_group_type[j])
  13588. {
  13589. dbug(1,dprintf("Appl 0x%x is member of group 0x%x, no call",j+1,appl_number_group_type[j]));
  13590. clear_group_ind_mask_bit (plci, j); /* disable call on other group members */
  13591. appl_number_group_type[j] = 0; /* remove disabled group member from group list */
  13592. }
  13593. }
  13594. }
  13595. }
  13596. else /* application should not get a call */
  13597. {
  13598. clear_group_ind_mask_bit (plci, i);
  13599. }
  13600. }
  13601. }
  13602. /* OS notifies the driver about a application Capi_Register */
  13603. word CapiRegister(word id)
  13604. {
  13605. word i,j,appls_found;
  13606. PLCI *plci;
  13607. DIVA_CAPI_ADAPTER *a;
  13608. for(i=0,appls_found=0; i<max_appl; i++)
  13609. {
  13610. if( application[i].Id && (application[i].Id!=id) )
  13611. {
  13612. appls_found++; /* an application has been found */
  13613. }
  13614. }
  13615. if(appls_found) return TRUE;
  13616. for(i=0; i<max_adapter; i++) /* scan all adapters... */
  13617. {
  13618. a = &adapter[i];
  13619. if(a->request)
  13620. {
  13621. if(a->flag_dynamic_l1_down) /* remove adapter from L1 tristate (Huntgroup) */
  13622. {
  13623. if(!appls_found) /* first application does a capi register */
  13624. {
  13625. if((j=get_plci(a))) /* activate L1 of all adapters */
  13626. {
  13627. plci = &a->plci[j-1];
  13628. plci->command = 0;
  13629. add_p(plci,OAD,"\x01\xfd");
  13630. add_p(plci,CAI,"\x01\x80");
  13631. add_p(plci,UID,"\x06\x43\x61\x70\x69\x32\x30");
  13632. add_p(plci,SHIFT|6,NULL);
  13633. add_p(plci,SIN,"\x02\x00\x00");
  13634. plci->internal_command = START_L1_SIG_ASSIGN_PEND;
  13635. sig_req(plci,ASSIGN,DSIG_ID);
  13636. add_p(plci,FTY,"\x02\xff\x07"); /* l1 start */
  13637. sig_req(plci,SIG_CTRL,0);
  13638. send_req(plci);
  13639. }
  13640. }
  13641. }
  13642. }
  13643. }
  13644. return FALSE;
  13645. }
  13646. /*------------------------------------------------------------------*/
  13647. /* Functions for virtual Switching e.g. Transfer by join, Conference */
  13648. static void VSwitchReqInd(PLCI *plci, dword Id, byte **parms)
  13649. {
  13650. word i;
  13651. /* Format of vswitch_t:
  13652. 0 byte length
  13653. 1 byte VSWITCHIE
  13654. 2 byte VSWITCH_REQ/VSWITCH_IND
  13655. 3 byte reserved
  13656. 4 word VSwitchcommand
  13657. 6 word returnerror
  13658. 8... Params
  13659. */
  13660. if(!plci ||
  13661. !plci->appl ||
  13662. !plci->State ||
  13663. plci->Sig.Ind==NCR_FACILITY
  13664. )
  13665. return;
  13666. for(i=0;i<MAX_MULTI_IE;i++)
  13667. {
  13668. if(!parms[i][0]) continue;
  13669. if(parms[i][0]<7)
  13670. {
  13671. parms[i][0]=0; /* kill it */
  13672. continue;
  13673. }
  13674. dbug(1,dprintf("VSwitchReqInd(%d)",parms[i][4]));
  13675. switch(parms[i][4])
  13676. {
  13677. case VSJOIN:
  13678. if(!plci->relatedPTYPLCI ||
  13679. (plci->ptyState!=S_ECT && plci->relatedPTYPLCI->ptyState!=S_ECT))
  13680. { /* Error */
  13681. break;
  13682. }
  13683. /* remember all necessary informations */
  13684. if(parms[i][0]!=11 || parms[i][8]!=3) /* Length Test */
  13685. {
  13686. break;
  13687. }
  13688. if(parms[i][2]==VSWITCH_IND && parms[i][9]==1)
  13689. { /* first indication after ECT-Request on Consultation Call */
  13690. plci->vswitchstate=parms[i][9];
  13691. parms[i][9]=2; /* State */
  13692. /* now ask first Call to join */
  13693. }
  13694. else if(parms[i][2]==VSWITCH_REQ && parms[i][9]==3)
  13695. { /* Answer of VSWITCH_REQ from first Call */
  13696. plci->vswitchstate=parms[i][9];
  13697. /* tell consultation call to join
  13698. and the protocol capabilities of the first call */
  13699. }
  13700. else
  13701. { /* Error */
  13702. break;
  13703. }
  13704. plci->vsprot=parms[i][10]; /* protocol */
  13705. plci->vsprotdialect=parms[i][11]; /* protocoldialect */
  13706. /* send join request to related PLCI */
  13707. parms[i][1]=VSWITCHIE;
  13708. parms[i][2]=VSWITCH_REQ;
  13709. plci->relatedPTYPLCI->command = 0;
  13710. plci->relatedPTYPLCI->internal_command = VSWITCH_REQ_PEND;
  13711. add_p(plci->relatedPTYPLCI,ESC,&parms[i][0]);
  13712. sig_req(plci->relatedPTYPLCI,VSWITCH_REQ,0);
  13713. send_req(plci->relatedPTYPLCI);
  13714. break;
  13715. case VSTRANSPORT:
  13716. default:
  13717. if(plci->relatedPTYPLCI &&
  13718. plci->vswitchstate==3 &&
  13719. plci->relatedPTYPLCI->vswitchstate==3)
  13720. {
  13721. add_p(plci->relatedPTYPLCI,ESC,&parms[i][0]);
  13722. sig_req(plci->relatedPTYPLCI,VSWITCH_REQ,0);
  13723. send_req(plci->relatedPTYPLCI);
  13724. }
  13725. break;
  13726. }
  13727. parms[i][0]=0; /* kill it */
  13728. }
  13729. }
  13730. /*------------------------------------------------------------------*/
  13731. static int diva_get_dma_descriptor (PLCI *plci, dword *dma_magic) {
  13732. ENTITY e;
  13733. IDI_SYNC_REQ* pReq = (IDI_SYNC_REQ*)&e;
  13734. if (!(diva_xdi_extended_features & DIVA_CAPI_XDI_PROVIDES_RX_DMA)) {
  13735. return (-1);
  13736. }
  13737. pReq->xdi_dma_descriptor_operation.Req = 0;
  13738. pReq->xdi_dma_descriptor_operation.Rc = IDI_SYNC_REQ_DMA_DESCRIPTOR_OPERATION;
  13739. pReq->xdi_dma_descriptor_operation.info.operation = IDI_SYNC_REQ_DMA_DESCRIPTOR_ALLOC;
  13740. pReq->xdi_dma_descriptor_operation.info.descriptor_number = -1;
  13741. pReq->xdi_dma_descriptor_operation.info.descriptor_address = NULL;
  13742. pReq->xdi_dma_descriptor_operation.info.descriptor_magic = 0;
  13743. e.user[0] = plci->adapter->Id - 1;
  13744. plci->adapter->request((ENTITY*)pReq);
  13745. if (!pReq->xdi_dma_descriptor_operation.info.operation &&
  13746. (pReq->xdi_dma_descriptor_operation.info.descriptor_number >= 0) &&
  13747. pReq->xdi_dma_descriptor_operation.info.descriptor_magic) {
  13748. *dma_magic = pReq->xdi_dma_descriptor_operation.info.descriptor_magic;
  13749. dbug(3,dprintf("dma_alloc, a:%d (%d-%08x)",
  13750. plci->adapter->Id,
  13751. pReq->xdi_dma_descriptor_operation.info.descriptor_number,
  13752. *dma_magic));
  13753. return (pReq->xdi_dma_descriptor_operation.info.descriptor_number);
  13754. } else {
  13755. dbug(1,dprintf("dma_alloc failed"));
  13756. return (-1);
  13757. }
  13758. }
  13759. static void diva_free_dma_descriptor (PLCI *plci, int nr) {
  13760. ENTITY e;
  13761. IDI_SYNC_REQ* pReq = (IDI_SYNC_REQ*)&e;
  13762. if (nr < 0) {
  13763. return;
  13764. }
  13765. pReq->xdi_dma_descriptor_operation.Req = 0;
  13766. pReq->xdi_dma_descriptor_operation.Rc = IDI_SYNC_REQ_DMA_DESCRIPTOR_OPERATION;
  13767. pReq->xdi_dma_descriptor_operation.info.operation = IDI_SYNC_REQ_DMA_DESCRIPTOR_FREE;
  13768. pReq->xdi_dma_descriptor_operation.info.descriptor_number = nr;
  13769. pReq->xdi_dma_descriptor_operation.info.descriptor_address = NULL;
  13770. pReq->xdi_dma_descriptor_operation.info.descriptor_magic = 0;
  13771. e.user[0] = plci->adapter->Id - 1;
  13772. plci->adapter->request((ENTITY*)pReq);
  13773. if (!pReq->xdi_dma_descriptor_operation.info.operation) {
  13774. dbug(1,dprintf("dma_free(%d)", nr));
  13775. } else {
  13776. dbug(1,dprintf("dma_free failed (%d)", nr));
  13777. }
  13778. }
  13779. /*------------------------------------------------------------------*/