message.c 476 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521752275237524752575267527752875297530753175327533753475357536753775387539754075417542754375447545754675477548754975507551755275537554755575567557755875597560756175627563756475657566756775687569757075717572757375747575757675777578757975807581758275837584758575867587758875897590759175927593759475957596759775987599760076017602760376047605760676077608760976107611761276137614761576167617761876197620762176227623762476257626762776287629763076317632763376347635763676377638763976407641764276437644764576467647764876497650765176527653765476557656765776587659766076617662766376647665766676677668766976707671767276737674767576767677767876797680768176827683768476857686768776887689769076917692769376947695769676977698769977007701770277037704770577067707770877097710771177127713771477157716771777187719772077217722772377247725772677277728772977307731773277337734773577367737773877397740774177427743774477457746774777487749775077517752775377547755775677577758775977607761776277637764776577667767776877697770777177727773777477757776777777787779778077817782778377847785778677877788778977907791779277937794779577967797779877997800780178027803780478057806780778087809781078117812781378147815781678177818781978207821782278237824782578267827782878297830783178327833783478357836783778387839784078417842784378447845784678477848784978507851785278537854785578567857785878597860786178627863786478657866786778687869787078717872787378747875787678777878787978807881788278837884788578867887788878897890789178927893789478957896789778987899790079017902790379047905790679077908790979107911791279137914791579167917791879197920792179227923792479257926792779287929793079317932793379347935793679377938793979407941794279437944794579467947794879497950795179527953795479557956795779587959796079617962796379647965796679677968796979707971797279737974797579767977797879797980798179827983798479857986798779887989799079917992799379947995799679977998799980008001800280038004800580068007800880098010801180128013801480158016801780188019802080218022802380248025802680278028802980308031803280338034803580368037803880398040804180428043804480458046804780488049805080518052805380548055805680578058805980608061806280638064806580668067806880698070807180728073807480758076807780788079808080818082808380848085808680878088808980908091809280938094809580968097809880998100810181028103810481058106810781088109811081118112811381148115811681178118811981208121812281238124812581268127812881298130813181328133813481358136813781388139814081418142814381448145814681478148814981508151815281538154815581568157815881598160816181628163816481658166816781688169817081718172817381748175817681778178817981808181818281838184818581868187818881898190819181928193819481958196819781988199820082018202820382048205820682078208820982108211821282138214821582168217821882198220822182228223822482258226822782288229823082318232823382348235823682378238823982408241824282438244824582468247824882498250825182528253825482558256825782588259826082618262826382648265826682678268826982708271827282738274827582768277827882798280828182828283828482858286828782888289829082918292829382948295829682978298829983008301830283038304830583068307830883098310831183128313831483158316831783188319832083218322832383248325832683278328832983308331833283338334833583368337833883398340834183428343834483458346834783488349835083518352835383548355835683578358835983608361836283638364836583668367836883698370837183728373837483758376837783788379838083818382838383848385838683878388838983908391839283938394839583968397839883998400840184028403840484058406840784088409841084118412841384148415841684178418841984208421842284238424842584268427842884298430843184328433843484358436843784388439844084418442844384448445844684478448844984508451845284538454845584568457845884598460846184628463846484658466846784688469847084718472847384748475847684778478847984808481848284838484848584868487848884898490849184928493849484958496849784988499850085018502850385048505850685078508850985108511851285138514851585168517851885198520852185228523852485258526852785288529853085318532853385348535853685378538853985408541854285438544854585468547854885498550855185528553855485558556855785588559856085618562856385648565856685678568856985708571857285738574857585768577857885798580858185828583858485858586858785888589859085918592859385948595859685978598859986008601860286038604860586068607860886098610861186128613861486158616861786188619862086218622862386248625862686278628862986308631863286338634863586368637863886398640864186428643864486458646864786488649865086518652865386548655865686578658865986608661866286638664866586668667866886698670867186728673867486758676867786788679868086818682868386848685868686878688868986908691869286938694869586968697869886998700870187028703870487058706870787088709871087118712871387148715871687178718871987208721872287238724872587268727872887298730873187328733873487358736873787388739874087418742874387448745874687478748874987508751875287538754875587568757875887598760876187628763876487658766876787688769877087718772877387748775877687778778877987808781878287838784878587868787878887898790879187928793879487958796879787988799880088018802880388048805880688078808880988108811881288138814881588168817881888198820882188228823882488258826882788288829883088318832883388348835883688378838883988408841884288438844884588468847884888498850885188528853885488558856885788588859886088618862886388648865886688678868886988708871887288738874887588768877887888798880888188828883888488858886888788888889889088918892889388948895889688978898889989008901890289038904890589068907890889098910891189128913891489158916891789188919892089218922892389248925892689278928892989308931893289338934893589368937893889398940894189428943894489458946894789488949895089518952895389548955895689578958895989608961896289638964896589668967896889698970897189728973897489758976897789788979898089818982898389848985898689878988898989908991899289938994899589968997899889999000900190029003900490059006900790089009901090119012901390149015901690179018901990209021902290239024902590269027902890299030903190329033903490359036903790389039904090419042904390449045904690479048904990509051905290539054905590569057905890599060906190629063906490659066906790689069907090719072907390749075907690779078907990809081908290839084908590869087908890899090909190929093909490959096909790989099910091019102910391049105910691079108910991109111911291139114911591169117911891199120912191229123912491259126912791289129913091319132913391349135913691379138913991409141914291439144914591469147914891499150915191529153915491559156915791589159916091619162916391649165916691679168916991709171917291739174917591769177917891799180918191829183918491859186918791889189919091919192919391949195919691979198919992009201920292039204920592069207920892099210921192129213921492159216921792189219922092219222922392249225922692279228922992309231923292339234923592369237923892399240924192429243924492459246924792489249925092519252925392549255925692579258925992609261926292639264926592669267926892699270927192729273927492759276927792789279928092819282928392849285928692879288928992909291929292939294929592969297929892999300930193029303930493059306930793089309931093119312931393149315931693179318931993209321932293239324932593269327932893299330933193329333933493359336933793389339934093419342934393449345934693479348934993509351935293539354935593569357935893599360936193629363936493659366936793689369937093719372937393749375937693779378937993809381938293839384938593869387938893899390939193929393939493959396939793989399940094019402940394049405940694079408940994109411941294139414941594169417941894199420942194229423942494259426942794289429943094319432943394349435943694379438943994409441944294439444944594469447944894499450945194529453945494559456945794589459946094619462946394649465946694679468946994709471947294739474947594769477947894799480948194829483948494859486948794889489949094919492949394949495949694979498949995009501950295039504950595069507950895099510951195129513951495159516951795189519952095219522952395249525952695279528952995309531953295339534953595369537953895399540954195429543954495459546954795489549955095519552955395549555955695579558955995609561956295639564956595669567956895699570957195729573957495759576957795789579958095819582958395849585958695879588958995909591959295939594959595969597959895999600960196029603960496059606960796089609961096119612961396149615961696179618961996209621962296239624962596269627962896299630963196329633963496359636963796389639964096419642964396449645964696479648964996509651965296539654965596569657965896599660966196629663966496659666966796689669967096719672967396749675967696779678967996809681968296839684968596869687968896899690969196929693969496959696969796989699970097019702970397049705970697079708970997109711971297139714971597169717971897199720972197229723972497259726972797289729973097319732973397349735973697379738973997409741974297439744974597469747974897499750975197529753975497559756975797589759976097619762976397649765976697679768976997709771977297739774977597769777977897799780978197829783978497859786978797889789979097919792979397949795979697979798979998009801980298039804980598069807980898099810981198129813981498159816981798189819982098219822982398249825982698279828982998309831983298339834983598369837983898399840984198429843984498459846984798489849985098519852985398549855985698579858985998609861986298639864986598669867986898699870987198729873987498759876987798789879988098819882988398849885988698879888988998909891989298939894989598969897989898999900990199029903990499059906990799089909991099119912991399149915991699179918991999209921992299239924992599269927992899299930993199329933993499359936993799389939994099419942994399449945994699479948994999509951995299539954995599569957995899599960996199629963996499659966996799689969997099719972997399749975997699779978997999809981998299839984998599869987998899899990999199929993999499959996999799989999100001000110002100031000410005100061000710008100091001010011100121001310014100151001610017100181001910020100211002210023100241002510026100271002810029100301003110032100331003410035100361003710038100391004010041100421004310044100451004610047100481004910050100511005210053100541005510056100571005810059100601006110062100631006410065100661006710068100691007010071100721007310074100751007610077100781007910080100811008210083100841008510086100871008810089100901009110092100931009410095100961009710098100991010010101101021010310104101051010610107101081010910110101111011210113101141011510116101171011810119101201012110122101231012410125101261012710128101291013010131101321013310134101351013610137101381013910140101411014210143101441014510146101471014810149101501015110152101531015410155101561015710158101591016010161101621016310164101651016610167101681016910170101711017210173101741017510176101771017810179101801018110182101831018410185101861018710188101891019010191101921019310194101951019610197101981019910200102011020210203102041020510206102071020810209102101021110212102131021410215102161021710218102191022010221102221022310224102251022610227102281022910230102311023210233102341023510236102371023810239102401024110242102431024410245102461024710248102491025010251102521025310254102551025610257102581025910260102611026210263102641026510266102671026810269102701027110272102731027410275102761027710278102791028010281102821028310284102851028610287102881028910290102911029210293102941029510296102971029810299103001030110302103031030410305103061030710308103091031010311103121031310314103151031610317103181031910320103211032210323103241032510326103271032810329103301033110332103331033410335103361033710338103391034010341103421034310344103451034610347103481034910350103511035210353103541035510356103571035810359103601036110362103631036410365103661036710368103691037010371103721037310374103751037610377103781037910380103811038210383103841038510386103871038810389103901039110392103931039410395103961039710398103991040010401104021040310404104051040610407104081040910410104111041210413104141041510416104171041810419104201042110422104231042410425104261042710428104291043010431104321043310434104351043610437104381043910440104411044210443104441044510446104471044810449104501045110452104531045410455104561045710458104591046010461104621046310464104651046610467104681046910470104711047210473104741047510476104771047810479104801048110482104831048410485104861048710488104891049010491104921049310494104951049610497104981049910500105011050210503105041050510506105071050810509105101051110512105131051410515105161051710518105191052010521105221052310524105251052610527105281052910530105311053210533105341053510536105371053810539105401054110542105431054410545105461054710548105491055010551105521055310554105551055610557105581055910560105611056210563105641056510566105671056810569105701057110572105731057410575105761057710578105791058010581105821058310584105851058610587105881058910590105911059210593105941059510596105971059810599106001060110602106031060410605106061060710608106091061010611106121061310614106151061610617106181061910620106211062210623106241062510626106271062810629106301063110632106331063410635106361063710638106391064010641106421064310644106451064610647106481064910650106511065210653106541065510656106571065810659106601066110662106631066410665106661066710668106691067010671106721067310674106751067610677106781067910680106811068210683106841068510686106871068810689106901069110692106931069410695106961069710698106991070010701107021070310704107051070610707107081070910710107111071210713107141071510716107171071810719107201072110722107231072410725107261072710728107291073010731107321073310734107351073610737107381073910740107411074210743107441074510746107471074810749107501075110752107531075410755107561075710758107591076010761107621076310764107651076610767107681076910770107711077210773107741077510776107771077810779107801078110782107831078410785107861078710788107891079010791107921079310794107951079610797107981079910800108011080210803108041080510806108071080810809108101081110812108131081410815108161081710818108191082010821108221082310824108251082610827108281082910830108311083210833108341083510836108371083810839108401084110842108431084410845108461084710848108491085010851108521085310854108551085610857108581085910860108611086210863108641086510866108671086810869108701087110872108731087410875108761087710878108791088010881108821088310884108851088610887108881088910890108911089210893108941089510896108971089810899109001090110902109031090410905109061090710908109091091010911109121091310914109151091610917109181091910920109211092210923109241092510926109271092810929109301093110932109331093410935109361093710938109391094010941109421094310944109451094610947109481094910950109511095210953109541095510956109571095810959109601096110962109631096410965109661096710968109691097010971109721097310974109751097610977109781097910980109811098210983109841098510986109871098810989109901099110992109931099410995109961099710998109991100011001110021100311004110051100611007110081100911010110111101211013110141101511016110171101811019110201102111022110231102411025110261102711028110291103011031110321103311034110351103611037110381103911040110411104211043110441104511046110471104811049110501105111052110531105411055110561105711058110591106011061110621106311064110651106611067110681106911070110711107211073110741107511076110771107811079110801108111082110831108411085110861108711088110891109011091110921109311094110951109611097110981109911100111011110211103111041110511106111071110811109111101111111112111131111411115111161111711118111191112011121111221112311124111251112611127111281112911130111311113211133111341113511136111371113811139111401114111142111431114411145111461114711148111491115011151111521115311154111551115611157111581115911160111611116211163111641116511166111671116811169111701117111172111731117411175111761117711178111791118011181111821118311184111851118611187111881118911190111911119211193111941119511196111971119811199112001120111202112031120411205112061120711208112091121011211112121121311214112151121611217112181121911220112211122211223112241122511226112271122811229112301123111232112331123411235112361123711238112391124011241112421124311244112451124611247112481124911250112511125211253112541125511256112571125811259112601126111262112631126411265112661126711268112691127011271112721127311274112751127611277112781127911280112811128211283112841128511286112871128811289112901129111292112931129411295112961129711298112991130011301113021130311304113051130611307113081130911310113111131211313113141131511316113171131811319113201132111322113231132411325113261132711328113291133011331113321133311334113351133611337113381133911340113411134211343113441134511346113471134811349113501135111352113531135411355113561135711358113591136011361113621136311364113651136611367113681136911370113711137211373113741137511376113771137811379113801138111382113831138411385113861138711388113891139011391113921139311394113951139611397113981139911400114011140211403114041140511406114071140811409114101141111412114131141411415114161141711418114191142011421114221142311424114251142611427114281142911430114311143211433114341143511436114371143811439114401144111442114431144411445114461144711448114491145011451114521145311454114551145611457114581145911460114611146211463114641146511466114671146811469114701147111472114731147411475114761147711478114791148011481114821148311484114851148611487114881148911490114911149211493114941149511496114971149811499115001150111502115031150411505115061150711508115091151011511115121151311514115151151611517115181151911520115211152211523115241152511526115271152811529115301153111532115331153411535115361153711538115391154011541115421154311544115451154611547115481154911550115511155211553115541155511556115571155811559115601156111562115631156411565115661156711568115691157011571115721157311574115751157611577115781157911580115811158211583115841158511586115871158811589115901159111592115931159411595115961159711598115991160011601116021160311604116051160611607116081160911610116111161211613116141161511616116171161811619116201162111622116231162411625116261162711628116291163011631116321163311634116351163611637116381163911640116411164211643116441164511646116471164811649116501165111652116531165411655116561165711658116591166011661116621166311664116651166611667116681166911670116711167211673116741167511676116771167811679116801168111682116831168411685116861168711688116891169011691116921169311694116951169611697116981169911700117011170211703117041170511706117071170811709117101171111712117131171411715117161171711718117191172011721117221172311724117251172611727117281172911730117311173211733117341173511736117371173811739117401174111742117431174411745117461174711748117491175011751117521175311754117551175611757117581175911760117611176211763117641176511766117671176811769117701177111772117731177411775117761177711778117791178011781117821178311784117851178611787117881178911790117911179211793117941179511796117971179811799118001180111802118031180411805118061180711808118091181011811118121181311814118151181611817118181181911820118211182211823118241182511826118271182811829118301183111832118331183411835118361183711838118391184011841118421184311844118451184611847118481184911850118511185211853118541185511856118571185811859118601186111862118631186411865118661186711868118691187011871118721187311874118751187611877118781187911880118811188211883118841188511886118871188811889118901189111892118931189411895118961189711898118991190011901119021190311904119051190611907119081190911910119111191211913119141191511916119171191811919119201192111922119231192411925119261192711928119291193011931119321193311934119351193611937119381193911940119411194211943119441194511946119471194811949119501195111952119531195411955119561195711958119591196011961119621196311964119651196611967119681196911970119711197211973119741197511976119771197811979119801198111982119831198411985119861198711988119891199011991119921199311994119951199611997119981199912000120011200212003120041200512006120071200812009120101201112012120131201412015120161201712018120191202012021120221202312024120251202612027120281202912030120311203212033120341203512036120371203812039120401204112042120431204412045120461204712048120491205012051120521205312054120551205612057120581205912060120611206212063120641206512066120671206812069120701207112072120731207412075120761207712078120791208012081120821208312084120851208612087120881208912090120911209212093120941209512096120971209812099121001210112102121031210412105121061210712108121091211012111121121211312114121151211612117121181211912120121211212212123121241212512126121271212812129121301213112132121331213412135121361213712138121391214012141121421214312144121451214612147121481214912150121511215212153121541215512156121571215812159121601216112162121631216412165121661216712168121691217012171121721217312174121751217612177121781217912180121811218212183121841218512186121871218812189121901219112192121931219412195121961219712198121991220012201122021220312204122051220612207122081220912210122111221212213122141221512216122171221812219122201222112222122231222412225122261222712228122291223012231122321223312234122351223612237122381223912240122411224212243122441224512246122471224812249122501225112252122531225412255122561225712258122591226012261122621226312264122651226612267122681226912270122711227212273122741227512276122771227812279122801228112282122831228412285122861228712288122891229012291122921229312294122951229612297122981229912300123011230212303123041230512306123071230812309123101231112312123131231412315123161231712318123191232012321123221232312324123251232612327123281232912330123311233212333123341233512336123371233812339123401234112342123431234412345123461234712348123491235012351123521235312354123551235612357123581235912360123611236212363123641236512366123671236812369123701237112372123731237412375123761237712378123791238012381123821238312384123851238612387123881238912390123911239212393123941239512396123971239812399124001240112402124031240412405124061240712408124091241012411124121241312414124151241612417124181241912420124211242212423124241242512426124271242812429124301243112432124331243412435124361243712438124391244012441124421244312444124451244612447124481244912450124511245212453124541245512456124571245812459124601246112462124631246412465124661246712468124691247012471124721247312474124751247612477124781247912480124811248212483124841248512486124871248812489124901249112492124931249412495124961249712498124991250012501125021250312504125051250612507125081250912510125111251212513125141251512516125171251812519125201252112522125231252412525125261252712528125291253012531125321253312534125351253612537125381253912540125411254212543125441254512546125471254812549125501255112552125531255412555125561255712558125591256012561125621256312564125651256612567125681256912570125711257212573125741257512576125771257812579125801258112582125831258412585125861258712588125891259012591125921259312594125951259612597125981259912600126011260212603126041260512606126071260812609126101261112612126131261412615126161261712618126191262012621126221262312624126251262612627126281262912630126311263212633126341263512636126371263812639126401264112642126431264412645126461264712648126491265012651126521265312654126551265612657126581265912660126611266212663126641266512666126671266812669126701267112672126731267412675126761267712678126791268012681126821268312684126851268612687126881268912690126911269212693126941269512696126971269812699127001270112702127031270412705127061270712708127091271012711127121271312714127151271612717127181271912720127211272212723127241272512726127271272812729127301273112732127331273412735127361273712738127391274012741127421274312744127451274612747127481274912750127511275212753127541275512756127571275812759127601276112762127631276412765127661276712768127691277012771127721277312774127751277612777127781277912780127811278212783127841278512786127871278812789127901279112792127931279412795127961279712798127991280012801128021280312804128051280612807128081280912810128111281212813128141281512816128171281812819128201282112822128231282412825128261282712828128291283012831128321283312834128351283612837128381283912840128411284212843128441284512846128471284812849128501285112852128531285412855128561285712858128591286012861128621286312864128651286612867128681286912870128711287212873128741287512876128771287812879128801288112882128831288412885128861288712888128891289012891128921289312894128951289612897128981289912900129011290212903129041290512906129071290812909129101291112912129131291412915129161291712918129191292012921129221292312924129251292612927129281292912930129311293212933129341293512936129371293812939129401294112942129431294412945129461294712948129491295012951129521295312954129551295612957129581295912960129611296212963129641296512966129671296812969129701297112972129731297412975129761297712978129791298012981129821298312984129851298612987129881298912990129911299212993129941299512996129971299812999130001300113002130031300413005130061300713008130091301013011130121301313014130151301613017130181301913020130211302213023130241302513026130271302813029130301303113032130331303413035130361303713038130391304013041130421304313044130451304613047130481304913050130511305213053130541305513056130571305813059130601306113062130631306413065130661306713068130691307013071130721307313074130751307613077130781307913080130811308213083130841308513086130871308813089130901309113092130931309413095130961309713098130991310013101131021310313104131051310613107131081310913110131111311213113131141311513116131171311813119131201312113122131231312413125131261312713128131291313013131131321313313134131351313613137131381313913140131411314213143131441314513146131471314813149131501315113152131531315413155131561315713158131591316013161131621316313164131651316613167131681316913170131711317213173131741317513176131771317813179131801318113182131831318413185131861318713188131891319013191131921319313194131951319613197131981319913200132011320213203132041320513206132071320813209132101321113212132131321413215132161321713218132191322013221132221322313224132251322613227132281322913230132311323213233132341323513236132371323813239132401324113242132431324413245132461324713248132491325013251132521325313254132551325613257132581325913260132611326213263132641326513266132671326813269132701327113272132731327413275132761327713278132791328013281132821328313284132851328613287132881328913290132911329213293132941329513296132971329813299133001330113302133031330413305133061330713308133091331013311133121331313314133151331613317133181331913320133211332213323133241332513326133271332813329133301333113332133331333413335133361333713338133391334013341133421334313344133451334613347133481334913350133511335213353133541335513356133571335813359133601336113362133631336413365133661336713368133691337013371133721337313374133751337613377133781337913380133811338213383133841338513386133871338813389133901339113392133931339413395133961339713398133991340013401134021340313404134051340613407134081340913410134111341213413134141341513416134171341813419134201342113422134231342413425134261342713428134291343013431134321343313434134351343613437134381343913440134411344213443134441344513446134471344813449134501345113452134531345413455134561345713458134591346013461134621346313464134651346613467134681346913470134711347213473134741347513476134771347813479134801348113482134831348413485134861348713488134891349013491134921349313494134951349613497134981349913500135011350213503135041350513506135071350813509135101351113512135131351413515135161351713518135191352013521135221352313524135251352613527135281352913530135311353213533135341353513536135371353813539135401354113542135431354413545135461354713548135491355013551135521355313554135551355613557135581355913560135611356213563135641356513566135671356813569135701357113572135731357413575135761357713578135791358013581135821358313584135851358613587135881358913590135911359213593135941359513596135971359813599136001360113602136031360413605136061360713608136091361013611136121361313614136151361613617136181361913620136211362213623136241362513626136271362813629136301363113632136331363413635136361363713638136391364013641136421364313644136451364613647136481364913650136511365213653136541365513656136571365813659136601366113662136631366413665136661366713668136691367013671136721367313674136751367613677136781367913680136811368213683136841368513686136871368813689136901369113692136931369413695136961369713698136991370013701137021370313704137051370613707137081370913710137111371213713137141371513716137171371813719137201372113722137231372413725137261372713728137291373013731137321373313734137351373613737137381373913740137411374213743137441374513746137471374813749137501375113752137531375413755137561375713758137591376013761137621376313764137651376613767137681376913770137711377213773137741377513776137771377813779137801378113782137831378413785137861378713788137891379013791137921379313794137951379613797137981379913800138011380213803138041380513806138071380813809138101381113812138131381413815138161381713818138191382013821138221382313824138251382613827138281382913830138311383213833138341383513836138371383813839138401384113842138431384413845138461384713848138491385013851138521385313854138551385613857138581385913860138611386213863138641386513866138671386813869138701387113872138731387413875138761387713878138791388013881138821388313884138851388613887138881388913890138911389213893138941389513896138971389813899139001390113902139031390413905139061390713908139091391013911139121391313914139151391613917139181391913920139211392213923139241392513926139271392813929139301393113932139331393413935139361393713938139391394013941139421394313944139451394613947139481394913950139511395213953139541395513956139571395813959139601396113962139631396413965139661396713968139691397013971139721397313974139751397613977139781397913980139811398213983139841398513986139871398813989139901399113992139931399413995139961399713998139991400014001140021400314004140051400614007140081400914010140111401214013140141401514016140171401814019140201402114022140231402414025140261402714028140291403014031140321403314034140351403614037140381403914040140411404214043140441404514046140471404814049140501405114052140531405414055140561405714058140591406014061140621406314064140651406614067140681406914070140711407214073140741407514076140771407814079140801408114082140831408414085140861408714088140891409014091140921409314094140951409614097140981409914100141011410214103141041410514106141071410814109141101411114112141131411414115141161411714118141191412014121141221412314124141251412614127141281412914130141311413214133141341413514136141371413814139141401414114142141431414414145141461414714148141491415014151141521415314154141551415614157141581415914160141611416214163141641416514166141671416814169141701417114172141731417414175141761417714178141791418014181141821418314184141851418614187141881418914190141911419214193141941419514196141971419814199142001420114202142031420414205142061420714208142091421014211142121421314214142151421614217142181421914220142211422214223142241422514226142271422814229142301423114232142331423414235142361423714238142391424014241142421424314244142451424614247142481424914250142511425214253142541425514256142571425814259142601426114262142631426414265142661426714268142691427014271142721427314274142751427614277142781427914280142811428214283142841428514286142871428814289142901429114292142931429414295142961429714298142991430014301143021430314304143051430614307143081430914310143111431214313143141431514316143171431814319143201432114322143231432414325143261432714328143291433014331143321433314334143351433614337143381433914340143411434214343143441434514346143471434814349143501435114352143531435414355143561435714358143591436014361143621436314364143651436614367143681436914370143711437214373143741437514376143771437814379143801438114382143831438414385143861438714388143891439014391143921439314394143951439614397143981439914400144011440214403144041440514406144071440814409144101441114412144131441414415144161441714418144191442014421144221442314424144251442614427144281442914430144311443214433144341443514436144371443814439144401444114442144431444414445144461444714448144491445014451144521445314454144551445614457144581445914460144611446214463144641446514466144671446814469144701447114472144731447414475144761447714478144791448014481144821448314484144851448614487144881448914490144911449214493144941449514496144971449814499145001450114502145031450414505145061450714508145091451014511145121451314514145151451614517145181451914520145211452214523145241452514526145271452814529145301453114532145331453414535145361453714538145391454014541145421454314544145451454614547145481454914550145511455214553145541455514556145571455814559145601456114562145631456414565145661456714568145691457014571145721457314574145751457614577145781457914580145811458214583145841458514586145871458814589145901459114592145931459414595145961459714598145991460014601146021460314604146051460614607146081460914610146111461214613146141461514616146171461814619146201462114622146231462414625146261462714628146291463014631146321463314634146351463614637146381463914640146411464214643146441464514646146471464814649146501465114652146531465414655146561465714658146591466014661146621466314664146651466614667146681466914670146711467214673146741467514676146771467814679146801468114682146831468414685146861468714688146891469014691146921469314694146951469614697146981469914700147011470214703147041470514706147071470814709147101471114712147131471414715147161471714718147191472014721147221472314724147251472614727147281472914730147311473214733147341473514736147371473814739147401474114742147431474414745147461474714748147491475014751147521475314754147551475614757147581475914760147611476214763147641476514766147671476814769147701477114772147731477414775147761477714778147791478014781147821478314784147851478614787147881478914790147911479214793147941479514796147971479814799148001480114802148031480414805148061480714808148091481014811148121481314814148151481614817148181481914820148211482214823148241482514826148271482814829148301483114832148331483414835148361483714838148391484014841148421484314844148451484614847148481484914850148511485214853148541485514856148571485814859148601486114862148631486414865148661486714868148691487014871148721487314874148751487614877148781487914880148811488214883148841488514886148871488814889148901489114892148931489414895148961489714898148991490014901149021490314904149051490614907149081490914910149111491214913149141491514916149171491814919149201492114922149231492414925149261492714928149291493014931149321493314934149351493614937149381493914940149411494214943149441494514946149471494814949149501495114952149531495414955149561495714958149591496014961149621496314964149651496614967149681496914970149711497214973149741497514976149771497814979149801498114982149831498414985149861498714988149891499014991149921499314994149951499614997149981499915000150011500215003150041500515006150071500815009150101501115012150131501415015150161501715018150191502015021150221502315024150251502615027150281502915030150311503215033150341503515036150371503815039150401504115042150431504415045
  1. /*
  2. *
  3. Copyright (c) Eicon Networks, 2002.
  4. *
  5. This source file is supplied for the use with
  6. Eicon Networks range of DIVA Server Adapters.
  7. *
  8. Eicon File Revision : 2.1
  9. *
  10. This program is free software; you can redistribute it and/or modify
  11. it under the terms of the GNU General Public License as published by
  12. the Free Software Foundation; either version 2, or (at your option)
  13. any later version.
  14. *
  15. This program is distributed in the hope that it will be useful,
  16. but WITHOUT ANY WARRANTY OF ANY KIND WHATSOEVER INCLUDING ANY
  17. implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  18. See the GNU General Public License for more details.
  19. *
  20. You should have received a copy of the GNU General Public License
  21. along with this program; if not, write to the Free Software
  22. Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  23. *
  24. */
  25. #include "platform.h"
  26. #include "di_defs.h"
  27. #include "pc.h"
  28. #include "capi20.h"
  29. #include "divacapi.h"
  30. #include "mdm_msg.h"
  31. #include "divasync.h"
  32. #define FILE_ "MESSAGE.C"
  33. #define dprintf
  34. /*------------------------------------------------------------------*/
  35. /* This is options supported for all adapters that are server by */
  36. /* XDI driver. Allo it is not necessary to ask it from every adapter*/
  37. /* and it is not necessary to save it separate for every adapter */
  38. /* Macrose defined here have only local meaning */
  39. /*------------------------------------------------------------------*/
  40. static dword diva_xdi_extended_features = 0;
  41. #define DIVA_CAPI_USE_CMA 0x00000001
  42. #define DIVA_CAPI_XDI_PROVIDES_SDRAM_BAR 0x00000002
  43. #define DIVA_CAPI_XDI_PROVIDES_NO_CANCEL 0x00000004
  44. #define DIVA_CAPI_XDI_PROVIDES_RX_DMA 0x00000008
  45. /*
  46. CAPI can request to process all return codes self only if:
  47. protocol code supports this && xdi supports this
  48. */
  49. #define DIVA_CAPI_SUPPORTS_NO_CANCEL(__a__) (((__a__)->manufacturer_features&MANUFACTURER_FEATURE_XONOFF_FLOW_CONTROL)&& ((__a__)->manufacturer_features & MANUFACTURER_FEATURE_OK_FC_LABEL) && (diva_xdi_extended_features & DIVA_CAPI_XDI_PROVIDES_NO_CANCEL))
  50. /*------------------------------------------------------------------*/
  51. /* local function prototypes */
  52. /*------------------------------------------------------------------*/
  53. static void group_optimization(DIVA_CAPI_ADAPTER * a, PLCI * plci);
  54. static void set_group_ind_mask (PLCI *plci);
  55. static void clear_group_ind_mask_bit (PLCI *plci, word b);
  56. static byte test_group_ind_mask_bit (PLCI *plci, word b);
  57. void AutomaticLaw(DIVA_CAPI_ADAPTER *);
  58. word CapiRelease(word);
  59. word CapiRegister(word);
  60. word api_put(APPL *, CAPI_MSG *);
  61. static word api_parse(byte *, word, byte *, API_PARSE *);
  62. static void api_save_msg(API_PARSE *in, byte *format, API_SAVE *out);
  63. static void api_load_msg(API_SAVE *in, API_PARSE *out);
  64. word api_remove_start(void);
  65. void api_remove_complete(void);
  66. static void plci_remove(PLCI *);
  67. static void diva_get_extended_adapter_features (DIVA_CAPI_ADAPTER * a);
  68. static void diva_ask_for_xdi_sdram_bar (DIVA_CAPI_ADAPTER *, IDI_SYNC_REQ *);
  69. void callback(ENTITY *);
  70. static void control_rc(PLCI *, byte, byte, byte, byte, byte);
  71. static void data_rc(PLCI *, byte);
  72. static void data_ack(PLCI *, byte);
  73. static void sig_ind(PLCI *);
  74. static void SendInfo(PLCI *, dword, byte * *, byte);
  75. static void SendSetupInfo(APPL *, PLCI *, dword, byte * *, byte);
  76. static void SendSSExtInd(APPL *, PLCI * plci, dword Id, byte * * parms);
  77. static void VSwitchReqInd(PLCI *plci, dword Id, byte **parms);
  78. static void nl_ind(PLCI *);
  79. static byte connect_req(dword, word, DIVA_CAPI_ADAPTER *, PLCI *, APPL *, API_PARSE *);
  80. static byte connect_res(dword, word, DIVA_CAPI_ADAPTER *, PLCI *, APPL *, API_PARSE *);
  81. static byte connect_a_res(dword,word, DIVA_CAPI_ADAPTER *, PLCI *, APPL *, API_PARSE *);
  82. static byte disconnect_req(dword, word, DIVA_CAPI_ADAPTER *, PLCI *, APPL *, API_PARSE *);
  83. static byte disconnect_res(dword, word, DIVA_CAPI_ADAPTER *, PLCI *, APPL *, API_PARSE *);
  84. static byte listen_req(dword, word, DIVA_CAPI_ADAPTER *, PLCI *, APPL *, API_PARSE *);
  85. static byte info_req(dword, word, DIVA_CAPI_ADAPTER *, PLCI *, APPL *, API_PARSE *);
  86. static byte info_res(dword, word, DIVA_CAPI_ADAPTER *, PLCI *, APPL *, API_PARSE *);
  87. static byte alert_req(dword, word, DIVA_CAPI_ADAPTER *, PLCI *, APPL *, API_PARSE *);
  88. static byte facility_req(dword, word, DIVA_CAPI_ADAPTER *, PLCI *, APPL *, API_PARSE *);
  89. static byte facility_res(dword, word, DIVA_CAPI_ADAPTER *, PLCI *, APPL *, API_PARSE *);
  90. static byte connect_b3_req(dword, word, DIVA_CAPI_ADAPTER *, PLCI *, APPL *, API_PARSE *);
  91. static byte connect_b3_res(dword, word, DIVA_CAPI_ADAPTER *, PLCI *, APPL *, API_PARSE *);
  92. static byte connect_b3_a_res(dword, word, DIVA_CAPI_ADAPTER *, PLCI *, APPL *, API_PARSE *);
  93. static byte disconnect_b3_req(dword, word, DIVA_CAPI_ADAPTER *, PLCI *, APPL *, API_PARSE *);
  94. static byte disconnect_b3_res(dword, word, DIVA_CAPI_ADAPTER *, PLCI *, APPL *, API_PARSE *);
  95. static byte data_b3_req(dword, word, DIVA_CAPI_ADAPTER *, PLCI *, APPL *, API_PARSE *);
  96. static byte data_b3_res(dword, word, DIVA_CAPI_ADAPTER *, PLCI *, APPL *, API_PARSE *);
  97. static byte reset_b3_req(dword, word, DIVA_CAPI_ADAPTER *, PLCI *, APPL *, API_PARSE *);
  98. static byte reset_b3_res(dword, word, DIVA_CAPI_ADAPTER *, PLCI *, APPL *, API_PARSE *);
  99. static byte connect_b3_t90_a_res(dword, word, DIVA_CAPI_ADAPTER *, PLCI *, APPL *, API_PARSE *);
  100. static byte select_b_req(dword, word, DIVA_CAPI_ADAPTER *, PLCI *, APPL *, API_PARSE *);
  101. static byte manufacturer_req(dword, word, DIVA_CAPI_ADAPTER *, PLCI *, APPL *, API_PARSE *);
  102. static byte manufacturer_res(dword, word, DIVA_CAPI_ADAPTER *, PLCI *, APPL *, API_PARSE *);
  103. static word get_plci(DIVA_CAPI_ADAPTER *);
  104. static void add_p(PLCI *, byte, byte *);
  105. static void add_s(PLCI * plci, byte code, API_PARSE * p);
  106. static void add_ss(PLCI * plci, byte code, API_PARSE * p);
  107. static void add_ie(PLCI * plci, byte code, byte * p, word p_length);
  108. static void add_d(PLCI *, word, byte *);
  109. static void add_ai(PLCI *, API_PARSE *);
  110. static word add_b1(PLCI *, API_PARSE *, word, word);
  111. static word add_b23(PLCI *, API_PARSE *);
  112. static word add_modem_b23 (PLCI * plci, API_PARSE* bp_parms);
  113. static void sig_req(PLCI *, byte, byte);
  114. static void nl_req_ncci(PLCI *, byte, byte);
  115. static void send_req(PLCI *);
  116. static void send_data(PLCI *);
  117. static word plci_remove_check(PLCI *);
  118. static void listen_check(DIVA_CAPI_ADAPTER *);
  119. static byte AddInfo(byte **, byte **, byte *, byte *);
  120. static byte getChannel(API_PARSE *);
  121. static void IndParse(PLCI *, word *, byte **, byte);
  122. static byte ie_compare(byte *, byte *);
  123. static word find_cip(DIVA_CAPI_ADAPTER *, byte *, byte *);
  124. static word CPN_filter_ok(byte *cpn,DIVA_CAPI_ADAPTER *,word);
  125. /*
  126. XON protocol helpers
  127. */
  128. static void channel_flow_control_remove (PLCI * plci);
  129. static void channel_x_off (PLCI * plci, byte ch, byte flag);
  130. static void channel_x_on (PLCI * plci, byte ch);
  131. static void channel_request_xon (PLCI * plci, byte ch);
  132. static void channel_xmit_xon (PLCI * plci);
  133. static int channel_can_xon (PLCI * plci, byte ch);
  134. static void channel_xmit_extended_xon (PLCI * plci);
  135. static byte SendMultiIE(PLCI * plci, dword Id, byte * * parms, byte ie_type, dword info_mask, byte setupParse);
  136. static word AdvCodecSupport(DIVA_CAPI_ADAPTER *, PLCI *, APPL *, byte);
  137. static void CodecIdCheck(DIVA_CAPI_ADAPTER *, PLCI *);
  138. static void SetVoiceChannel(PLCI *, byte *, DIVA_CAPI_ADAPTER * );
  139. static void VoiceChannelOff(PLCI *plci);
  140. static void adv_voice_write_coefs (PLCI *plci, word write_command);
  141. static void adv_voice_clear_config (PLCI *plci);
  142. static word get_b1_facilities (PLCI * plci, byte b1_resource);
  143. static byte add_b1_facilities (PLCI * plci, byte b1_resource, word b1_facilities);
  144. static void adjust_b1_facilities (PLCI *plci, byte new_b1_resource, word new_b1_facilities);
  145. static word adjust_b_process (dword Id, PLCI *plci, byte Rc);
  146. static void adjust_b1_resource (dword Id, PLCI *plci, API_SAVE *bp_msg, word b1_facilities, word internal_command);
  147. static void adjust_b_restore (dword Id, PLCI *plci, byte Rc);
  148. static void reset_b3_command (dword Id, PLCI *plci, byte Rc);
  149. static void select_b_command (dword Id, PLCI *plci, byte Rc);
  150. static void fax_connect_ack_command (dword Id, PLCI *plci, byte Rc);
  151. static void fax_edata_ack_command (dword Id, PLCI *plci, byte Rc);
  152. static void fax_connect_info_command (dword Id, PLCI *plci, byte Rc);
  153. static void fax_adjust_b23_command (dword Id, PLCI *plci, byte Rc);
  154. static void fax_disconnect_command (dword Id, PLCI *plci, byte Rc);
  155. static void hold_save_command (dword Id, PLCI *plci, byte Rc);
  156. static void retrieve_restore_command (dword Id, PLCI *plci, byte Rc);
  157. static void init_b1_config (PLCI *plci);
  158. static void clear_b1_config (PLCI *plci);
  159. static void dtmf_command (dword Id, PLCI *plci, byte Rc);
  160. static byte dtmf_request (dword Id, word Number, DIVA_CAPI_ADAPTER *a, PLCI *plci, APPL *appl, API_PARSE *msg);
  161. static void dtmf_confirmation (dword Id, PLCI *plci);
  162. static void dtmf_indication (dword Id, PLCI *plci, byte *msg, word length);
  163. static void dtmf_parameter_write (PLCI *plci);
  164. static void mixer_set_bchannel_id_esc (PLCI *plci, byte bchannel_id);
  165. static void mixer_set_bchannel_id (PLCI *plci, byte *chi);
  166. static void mixer_clear_config (PLCI *plci);
  167. static void mixer_notify_update (PLCI *plci, byte others);
  168. static void mixer_command (dword Id, PLCI *plci, byte Rc);
  169. static byte mixer_request (dword Id, word Number, DIVA_CAPI_ADAPTER *a, PLCI *plci, APPL *appl, API_PARSE *msg);
  170. static void mixer_indication_coefs_set (dword Id, PLCI *plci);
  171. static void mixer_indication_xconnect_from (dword Id, PLCI *plci, byte *msg, word length);
  172. static void mixer_indication_xconnect_to (dword Id, PLCI *plci, byte *msg, word length);
  173. static void mixer_remove (PLCI *plci);
  174. static void ec_command (dword Id, PLCI *plci, byte Rc);
  175. static byte ec_request (dword Id, word Number, DIVA_CAPI_ADAPTER *a, PLCI *plci, APPL *appl, API_PARSE *msg);
  176. static void ec_indication (dword Id, PLCI *plci, byte *msg, word length);
  177. static void rtp_connect_b3_req_command (dword Id, PLCI *plci, byte Rc);
  178. static void rtp_connect_b3_res_command (dword Id, PLCI *plci, byte Rc);
  179. static int diva_get_dma_descriptor (PLCI *plci, dword *dma_magic);
  180. static void diva_free_dma_descriptor (PLCI *plci, int nr);
  181. /*------------------------------------------------------------------*/
  182. /* external function prototypes */
  183. /*------------------------------------------------------------------*/
  184. extern byte MapController (byte);
  185. extern byte UnMapController (byte);
  186. #define MapId(Id) (((Id) & 0xffffff00L) | MapController ((byte)(Id)))
  187. #define UnMapId(Id) (((Id) & 0xffffff00L) | UnMapController ((byte)(Id)))
  188. void sendf(APPL *, word, dword, word, byte *, ...);
  189. void * TransmitBufferSet(APPL * appl, dword ref);
  190. void * TransmitBufferGet(APPL * appl, void * p);
  191. void TransmitBufferFree(APPL * appl, void * p);
  192. void * ReceiveBufferGet(APPL * appl, int Num);
  193. int fax_head_line_time (char *buffer);
  194. /*------------------------------------------------------------------*/
  195. /* Global data definitions */
  196. /*------------------------------------------------------------------*/
  197. extern byte max_adapter;
  198. extern byte max_appl;
  199. extern DIVA_CAPI_ADAPTER * adapter;
  200. extern APPL * application;
  201. static byte remove_started = false;
  202. static PLCI dummy_plci;
  203. static struct _ftable {
  204. word command;
  205. byte * format;
  206. byte (* function)(dword, word, DIVA_CAPI_ADAPTER *, PLCI *, APPL *, API_PARSE *);
  207. } ftable[] = {
  208. {_DATA_B3_R, "dwww", data_b3_req},
  209. {_DATA_B3_I|RESPONSE, "w", data_b3_res},
  210. {_INFO_R, "ss", info_req},
  211. {_INFO_I|RESPONSE, "", info_res},
  212. {_CONNECT_R, "wsssssssss", connect_req},
  213. {_CONNECT_I|RESPONSE, "wsssss", connect_res},
  214. {_CONNECT_ACTIVE_I|RESPONSE, "", connect_a_res},
  215. {_DISCONNECT_R, "s", disconnect_req},
  216. {_DISCONNECT_I|RESPONSE, "", disconnect_res},
  217. {_LISTEN_R, "dddss", listen_req},
  218. {_ALERT_R, "s", alert_req},
  219. {_FACILITY_R, "ws", facility_req},
  220. {_FACILITY_I|RESPONSE, "ws", facility_res},
  221. {_CONNECT_B3_R, "s", connect_b3_req},
  222. {_CONNECT_B3_I|RESPONSE, "ws", connect_b3_res},
  223. {_CONNECT_B3_ACTIVE_I|RESPONSE, "", connect_b3_a_res},
  224. {_DISCONNECT_B3_R, "s", disconnect_b3_req},
  225. {_DISCONNECT_B3_I|RESPONSE, "", disconnect_b3_res},
  226. {_RESET_B3_R, "s", reset_b3_req},
  227. {_RESET_B3_I|RESPONSE, "", reset_b3_res},
  228. {_CONNECT_B3_T90_ACTIVE_I|RESPONSE, "ws", connect_b3_t90_a_res},
  229. {_CONNECT_B3_T90_ACTIVE_I|RESPONSE, "", connect_b3_t90_a_res},
  230. {_SELECT_B_REQ, "s", select_b_req},
  231. {_MANUFACTURER_R, "dws", manufacturer_req},
  232. {_MANUFACTURER_I|RESPONSE, "dws", manufacturer_res},
  233. {_MANUFACTURER_I|RESPONSE, "", manufacturer_res}
  234. };
  235. static byte * cip_bc[29][2] = {
  236. { "", "" }, /* 0 */
  237. { "\x03\x80\x90\xa3", "\x03\x80\x90\xa2" }, /* 1 */
  238. { "\x02\x88\x90", "\x02\x88\x90" }, /* 2 */
  239. { "\x02\x89\x90", "\x02\x89\x90" }, /* 3 */
  240. { "\x03\x90\x90\xa3", "\x03\x90\x90\xa2" }, /* 4 */
  241. { "\x03\x91\x90\xa5", "\x03\x91\x90\xa5" }, /* 5 */
  242. { "\x02\x98\x90", "\x02\x98\x90" }, /* 6 */
  243. { "\x04\x88\xc0\xc6\xe6", "\x04\x88\xc0\xc6\xe6" }, /* 7 */
  244. { "\x04\x88\x90\x21\x8f", "\x04\x88\x90\x21\x8f" }, /* 8 */
  245. { "\x03\x91\x90\xa5", "\x03\x91\x90\xa5" }, /* 9 */
  246. { "", "" }, /* 10 */
  247. { "", "" }, /* 11 */
  248. { "", "" }, /* 12 */
  249. { "", "" }, /* 13 */
  250. { "", "" }, /* 14 */
  251. { "", "" }, /* 15 */
  252. { "\x03\x80\x90\xa3", "\x03\x80\x90\xa2" }, /* 16 */
  253. { "\x03\x90\x90\xa3", "\x03\x90\x90\xa2" }, /* 17 */
  254. { "\x02\x88\x90", "\x02\x88\x90" }, /* 18 */
  255. { "\x02\x88\x90", "\x02\x88\x90" }, /* 19 */
  256. { "\x02\x88\x90", "\x02\x88\x90" }, /* 20 */
  257. { "\x02\x88\x90", "\x02\x88\x90" }, /* 21 */
  258. { "\x02\x88\x90", "\x02\x88\x90" }, /* 22 */
  259. { "\x02\x88\x90", "\x02\x88\x90" }, /* 23 */
  260. { "\x02\x88\x90", "\x02\x88\x90" }, /* 24 */
  261. { "\x02\x88\x90", "\x02\x88\x90" }, /* 25 */
  262. { "\x03\x91\x90\xa5", "\x03\x91\x90\xa5" }, /* 26 */
  263. { "\x03\x91\x90\xa5", "\x03\x91\x90\xa5" }, /* 27 */
  264. { "\x02\x88\x90", "\x02\x88\x90" } /* 28 */
  265. };
  266. static byte * cip_hlc[29] = {
  267. "", /* 0 */
  268. "", /* 1 */
  269. "", /* 2 */
  270. "", /* 3 */
  271. "", /* 4 */
  272. "", /* 5 */
  273. "", /* 6 */
  274. "", /* 7 */
  275. "", /* 8 */
  276. "", /* 9 */
  277. "", /* 10 */
  278. "", /* 11 */
  279. "", /* 12 */
  280. "", /* 13 */
  281. "", /* 14 */
  282. "", /* 15 */
  283. "\x02\x91\x81", /* 16 */
  284. "\x02\x91\x84", /* 17 */
  285. "\x02\x91\xa1", /* 18 */
  286. "\x02\x91\xa4", /* 19 */
  287. "\x02\x91\xa8", /* 20 */
  288. "\x02\x91\xb1", /* 21 */
  289. "\x02\x91\xb2", /* 22 */
  290. "\x02\x91\xb5", /* 23 */
  291. "\x02\x91\xb8", /* 24 */
  292. "\x02\x91\xc1", /* 25 */
  293. "\x02\x91\x81", /* 26 */
  294. "\x03\x91\xe0\x01", /* 27 */
  295. "\x03\x91\xe0\x02" /* 28 */
  296. };
  297. /*------------------------------------------------------------------*/
  298. #define V120_HEADER_LENGTH 1
  299. #define V120_HEADER_EXTEND_BIT 0x80
  300. #define V120_HEADER_BREAK_BIT 0x40
  301. #define V120_HEADER_C1_BIT 0x04
  302. #define V120_HEADER_C2_BIT 0x08
  303. #define V120_HEADER_FLUSH_COND (V120_HEADER_BREAK_BIT | V120_HEADER_C1_BIT | V120_HEADER_C2_BIT)
  304. static byte v120_default_header[] =
  305. {
  306. 0x83 /* Ext, BR , res, res, C2 , C1 , B , F */
  307. };
  308. static byte v120_break_header[] =
  309. {
  310. 0xc3 | V120_HEADER_BREAK_BIT /* Ext, BR , res, res, C2 , C1 , B , F */
  311. };
  312. /*------------------------------------------------------------------*/
  313. /* API_PUT function */
  314. /*------------------------------------------------------------------*/
  315. word api_put(APPL * appl, CAPI_MSG * msg)
  316. {
  317. word i, j, k, l, n;
  318. word ret;
  319. byte c;
  320. byte controller;
  321. DIVA_CAPI_ADAPTER * a;
  322. PLCI * plci;
  323. NCCI * ncci_ptr;
  324. word ncci;
  325. CAPI_MSG *m;
  326. API_PARSE msg_parms[MAX_MSG_PARMS+1];
  327. if (msg->header.length < sizeof (msg->header) ||
  328. msg->header.length > MAX_MSG_SIZE) {
  329. dbug(1,dprintf("bad len"));
  330. return _BAD_MSG;
  331. }
  332. controller = (byte)((msg->header.controller &0x7f)-1);
  333. /* controller starts with 0 up to (max_adapter - 1) */
  334. if ( controller >= max_adapter )
  335. {
  336. dbug(1,dprintf("invalid ctrl"));
  337. return _BAD_MSG;
  338. }
  339. a = &adapter[controller];
  340. plci = NULL;
  341. if ((msg->header.plci != 0) && (msg->header.plci <= a->max_plci) && !a->adapter_disabled)
  342. {
  343. dbug(1,dprintf("plci=%x",msg->header.plci));
  344. plci = &a->plci[msg->header.plci-1];
  345. ncci = GET_WORD(&msg->header.ncci);
  346. if (plci->Id
  347. && (plci->appl
  348. || (plci->State == INC_CON_PENDING)
  349. || (plci->State == INC_CON_ALERT)
  350. || (msg->header.command == (_DISCONNECT_I|RESPONSE)))
  351. && ((ncci == 0)
  352. || (msg->header.command == (_DISCONNECT_B3_I|RESPONSE))
  353. || ((ncci < MAX_NCCI+1) && (a->ncci_plci[ncci] == plci->Id))))
  354. {
  355. i = plci->msg_in_read_pos;
  356. j = plci->msg_in_write_pos;
  357. if (j >= i)
  358. {
  359. if (j + msg->header.length + MSG_IN_OVERHEAD <= MSG_IN_QUEUE_SIZE)
  360. i += MSG_IN_QUEUE_SIZE - j;
  361. else
  362. j = 0;
  363. }
  364. else
  365. {
  366. n = (((CAPI_MSG *)(plci->msg_in_queue))->header.length + MSG_IN_OVERHEAD + 3) & 0xfffc;
  367. if (i > MSG_IN_QUEUE_SIZE - n)
  368. i = MSG_IN_QUEUE_SIZE - n + 1;
  369. i -= j;
  370. }
  371. if (i <= ((msg->header.length + MSG_IN_OVERHEAD + 3) & 0xfffc))
  372. {
  373. dbug(0,dprintf("Q-FULL1(msg) - len=%d write=%d read=%d wrap=%d free=%d",
  374. msg->header.length, plci->msg_in_write_pos,
  375. plci->msg_in_read_pos, plci->msg_in_wrap_pos, i));
  376. return _QUEUE_FULL;
  377. }
  378. c = false;
  379. if ((((byte *) msg) < ((byte *)(plci->msg_in_queue)))
  380. || (((byte *) msg) >= ((byte *)(plci->msg_in_queue)) + sizeof(plci->msg_in_queue)))
  381. {
  382. if (plci->msg_in_write_pos != plci->msg_in_read_pos)
  383. c = true;
  384. }
  385. if (msg->header.command == _DATA_B3_R)
  386. {
  387. if (msg->header.length < 20)
  388. {
  389. dbug(1,dprintf("DATA_B3 REQ wrong length %d", msg->header.length));
  390. return _BAD_MSG;
  391. }
  392. ncci_ptr = &(a->ncci[ncci]);
  393. n = ncci_ptr->data_pending;
  394. l = ncci_ptr->data_ack_pending;
  395. k = plci->msg_in_read_pos;
  396. while (k != plci->msg_in_write_pos)
  397. {
  398. if (k == plci->msg_in_wrap_pos)
  399. k = 0;
  400. if ((((CAPI_MSG *)(&((byte *)(plci->msg_in_queue))[k]))->header.command == _DATA_B3_R)
  401. && (((CAPI_MSG *)(&((byte *)(plci->msg_in_queue))[k]))->header.ncci == ncci))
  402. {
  403. n++;
  404. if (((CAPI_MSG *)(&((byte *)(plci->msg_in_queue))[k]))->info.data_b3_req.Flags & 0x0004)
  405. l++;
  406. }
  407. k += (((CAPI_MSG *)(&((byte *)(plci->msg_in_queue))[k]))->header.length +
  408. MSG_IN_OVERHEAD + 3) & 0xfffc;
  409. }
  410. if ((n >= MAX_DATA_B3) || (l >= MAX_DATA_ACK))
  411. {
  412. dbug(0,dprintf("Q-FULL2(data) - pending=%d/%d ack_pending=%d/%d",
  413. ncci_ptr->data_pending, n, ncci_ptr->data_ack_pending, l));
  414. return _QUEUE_FULL;
  415. }
  416. if (plci->req_in || plci->internal_command)
  417. {
  418. if ((((byte *) msg) >= ((byte *)(plci->msg_in_queue)))
  419. && (((byte *) msg) < ((byte *)(plci->msg_in_queue)) + sizeof(plci->msg_in_queue)))
  420. {
  421. dbug(0,dprintf("Q-FULL3(requeue)"));
  422. return _QUEUE_FULL;
  423. }
  424. c = true;
  425. }
  426. }
  427. else
  428. {
  429. if (plci->req_in || plci->internal_command)
  430. c = true;
  431. else
  432. {
  433. plci->command = msg->header.command;
  434. plci->number = msg->header.number;
  435. }
  436. }
  437. if (c)
  438. {
  439. dbug(1,dprintf("enqueue msg(0x%04x,0x%x,0x%x) - len=%d write=%d read=%d wrap=%d free=%d",
  440. msg->header.command, plci->req_in, plci->internal_command,
  441. msg->header.length, plci->msg_in_write_pos,
  442. plci->msg_in_read_pos, plci->msg_in_wrap_pos, i));
  443. if (j == 0)
  444. plci->msg_in_wrap_pos = plci->msg_in_write_pos;
  445. m = (CAPI_MSG *)(&((byte *)(plci->msg_in_queue))[j]);
  446. for (i = 0; i < msg->header.length; i++)
  447. ((byte *)(plci->msg_in_queue))[j++] = ((byte *) msg)[i];
  448. if (m->header.command == _DATA_B3_R)
  449. {
  450. m->info.data_b3_req.Data = (dword)(long)(TransmitBufferSet (appl, m->info.data_b3_req.Data));
  451. }
  452. j = (j + 3) & 0xfffc;
  453. *((APPL * *)(&((byte *)(plci->msg_in_queue))[j])) = appl;
  454. plci->msg_in_write_pos = j + MSG_IN_OVERHEAD;
  455. return 0;
  456. }
  457. }
  458. else
  459. {
  460. plci = NULL;
  461. }
  462. }
  463. dbug(1,dprintf("com=%x",msg->header.command));
  464. for(j=0;j<MAX_MSG_PARMS+1;j++) msg_parms[j].length = 0;
  465. for(i=0, ret = _BAD_MSG;
  466. i<(sizeof(ftable)/sizeof(struct _ftable));
  467. i++) {
  468. if(ftable[i].command==msg->header.command) {
  469. /* break loop if the message is correct, otherwise continue scan */
  470. /* (for example: CONNECT_B3_T90_ACT_RES has two specifications) */
  471. if(!api_parse(msg->info.b,(word)(msg->header.length-12),ftable[i].format,msg_parms)) {
  472. ret = 0;
  473. break;
  474. }
  475. for(j=0;j<MAX_MSG_PARMS+1;j++) msg_parms[j].length = 0;
  476. }
  477. }
  478. if(ret) {
  479. dbug(1,dprintf("BAD_MSG"));
  480. if(plci) plci->command = 0;
  481. return ret;
  482. }
  483. c = ftable[i].function(GET_DWORD(&msg->header.controller),
  484. msg->header.number,
  485. a,
  486. plci,
  487. appl,
  488. msg_parms);
  489. channel_xmit_extended_xon (plci);
  490. if(c==1) send_req(plci);
  491. if(c==2 && plci) plci->req_in = plci->req_in_start = plci->req_out = 0;
  492. if(plci && !plci->req_in) plci->command = 0;
  493. return 0;
  494. }
  495. /*------------------------------------------------------------------*/
  496. /* api_parse function, check the format of api messages */
  497. /*------------------------------------------------------------------*/
  498. 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] != NULL)
  630. i++;
  631. plci->internal_command_queue[i] = command_function;
  632. }
  633. }
  634. static void next_internal_command (dword Id, PLCI *plci)
  635. {
  636. word i;
  637. dbug (1, dprintf ("[%06lx] %s,%d: next_internal_command",
  638. UnMapId (Id), (char *)(FILE_), __LINE__));
  639. plci->internal_command = 0;
  640. plci->internal_command_queue[0] = NULL;
  641. while (plci->internal_command_queue[1] != NULL)
  642. {
  643. for (i = 0; i < MAX_INTERNAL_COMMAND_LEVELS - 1; i++)
  644. plci->internal_command_queue[i] = plci->internal_command_queue[i+1];
  645. plci->internal_command_queue[MAX_INTERNAL_COMMAND_LEVELS - 1] = NULL;
  646. (*(plci->internal_command_queue[0]))(Id, plci, OK);
  647. if (plci->internal_command != 0)
  648. return;
  649. plci->internal_command_queue[0] = NULL;
  650. }
  651. }
  652. /*------------------------------------------------------------------*/
  653. /* NCCI allocate/remove function */
  654. /*------------------------------------------------------------------*/
  655. static dword ncci_mapping_bug = 0;
  656. static word get_ncci (PLCI *plci, byte ch, word force_ncci)
  657. {
  658. DIVA_CAPI_ADAPTER *a;
  659. word ncci, i, j, k;
  660. a = plci->adapter;
  661. if (!ch || a->ch_ncci[ch])
  662. {
  663. ncci_mapping_bug++;
  664. dbug(1,dprintf("NCCI mapping exists %ld %02x %02x %02x-%02x",
  665. ncci_mapping_bug, ch, force_ncci, a->ncci_ch[a->ch_ncci[ch]], a->ch_ncci[ch]));
  666. ncci = ch;
  667. }
  668. else
  669. {
  670. if (force_ncci)
  671. ncci = force_ncci;
  672. else
  673. {
  674. if ((ch < MAX_NCCI+1) && !a->ncci_ch[ch])
  675. ncci = ch;
  676. else
  677. {
  678. ncci = 1;
  679. while ((ncci < MAX_NCCI+1) && a->ncci_ch[ncci])
  680. ncci++;
  681. if (ncci == MAX_NCCI+1)
  682. {
  683. ncci_mapping_bug++;
  684. i = 1;
  685. do
  686. {
  687. j = 1;
  688. while ((j < MAX_NCCI+1) && (a->ncci_ch[j] != i))
  689. j++;
  690. k = j;
  691. if (j < MAX_NCCI+1)
  692. {
  693. do
  694. {
  695. j++;
  696. } while ((j < MAX_NCCI+1) && (a->ncci_ch[j] != i));
  697. }
  698. } while ((i < MAX_NL_CHANNEL+1) && (j < MAX_NCCI+1));
  699. if (i < MAX_NL_CHANNEL+1)
  700. {
  701. dbug(1,dprintf("NCCI mapping overflow %ld %02x %02x %02x-%02x-%02x",
  702. ncci_mapping_bug, ch, force_ncci, i, k, j));
  703. }
  704. else
  705. {
  706. dbug(1,dprintf("NCCI mapping overflow %ld %02x %02x",
  707. ncci_mapping_bug, ch, force_ncci));
  708. }
  709. ncci = ch;
  710. }
  711. }
  712. a->ncci_plci[ncci] = plci->Id;
  713. a->ncci_state[ncci] = IDLE;
  714. if (!plci->ncci_ring_list)
  715. plci->ncci_ring_list = ncci;
  716. else
  717. a->ncci_next[ncci] = a->ncci_next[plci->ncci_ring_list];
  718. a->ncci_next[plci->ncci_ring_list] = (byte) ncci;
  719. }
  720. a->ncci_ch[ncci] = ch;
  721. a->ch_ncci[ch] = (byte) ncci;
  722. dbug(1,dprintf("NCCI mapping established %ld %02x %02x %02x-%02x",
  723. ncci_mapping_bug, ch, force_ncci, ch, ncci));
  724. }
  725. return (ncci);
  726. }
  727. static void ncci_free_receive_buffers (PLCI *plci, word ncci)
  728. {
  729. DIVA_CAPI_ADAPTER *a;
  730. APPL *appl;
  731. word i, ncci_code;
  732. dword Id;
  733. a = plci->adapter;
  734. Id = (((dword) ncci) << 16) | (((word)(plci->Id)) << 8) | a->Id;
  735. if (ncci)
  736. {
  737. if (a->ncci_plci[ncci] == plci->Id)
  738. {
  739. if (!plci->appl)
  740. {
  741. ncci_mapping_bug++;
  742. dbug(1,dprintf("NCCI mapping appl expected %ld %08lx",
  743. ncci_mapping_bug, Id));
  744. }
  745. else
  746. {
  747. appl = plci->appl;
  748. ncci_code = ncci | (((word) a->Id) << 8);
  749. for (i = 0; i < appl->MaxBuffer; i++)
  750. {
  751. if ((appl->DataNCCI[i] == ncci_code)
  752. && (((byte)(appl->DataFlags[i] >> 8)) == plci->Id))
  753. {
  754. appl->DataNCCI[i] = 0;
  755. }
  756. }
  757. }
  758. }
  759. }
  760. else
  761. {
  762. for (ncci = 1; ncci < MAX_NCCI+1; ncci++)
  763. {
  764. if (a->ncci_plci[ncci] == plci->Id)
  765. {
  766. if (!plci->appl)
  767. {
  768. ncci_mapping_bug++;
  769. dbug(1,dprintf("NCCI mapping no appl %ld %08lx",
  770. ncci_mapping_bug, Id));
  771. }
  772. else
  773. {
  774. appl = plci->appl;
  775. ncci_code = ncci | (((word) a->Id) << 8);
  776. for (i = 0; i < appl->MaxBuffer; i++)
  777. {
  778. if ((appl->DataNCCI[i] == ncci_code)
  779. && (((byte)(appl->DataFlags[i] >> 8)) == plci->Id))
  780. {
  781. appl->DataNCCI[i] = 0;
  782. }
  783. }
  784. }
  785. }
  786. }
  787. }
  788. }
  789. static void cleanup_ncci_data (PLCI *plci, word ncci)
  790. {
  791. NCCI *ncci_ptr;
  792. if (ncci && (plci->adapter->ncci_plci[ncci] == plci->Id))
  793. {
  794. ncci_ptr = &(plci->adapter->ncci[ncci]);
  795. if (plci->appl)
  796. {
  797. while (ncci_ptr->data_pending != 0)
  798. {
  799. if (!plci->data_sent || (ncci_ptr->DBuffer[ncci_ptr->data_out].P != plci->data_sent_ptr))
  800. TransmitBufferFree (plci->appl, ncci_ptr->DBuffer[ncci_ptr->data_out].P);
  801. (ncci_ptr->data_out)++;
  802. if (ncci_ptr->data_out == MAX_DATA_B3)
  803. ncci_ptr->data_out = 0;
  804. (ncci_ptr->data_pending)--;
  805. }
  806. }
  807. ncci_ptr->data_out = 0;
  808. ncci_ptr->data_pending = 0;
  809. ncci_ptr->data_ack_out = 0;
  810. ncci_ptr->data_ack_pending = 0;
  811. }
  812. }
  813. static void ncci_remove (PLCI *plci, word ncci, byte preserve_ncci)
  814. {
  815. DIVA_CAPI_ADAPTER *a;
  816. dword Id;
  817. word i;
  818. a = plci->adapter;
  819. Id = (((dword) ncci) << 16) | (((word)(plci->Id)) << 8) | a->Id;
  820. if (!preserve_ncci)
  821. ncci_free_receive_buffers (plci, ncci);
  822. if (ncci)
  823. {
  824. if (a->ncci_plci[ncci] != plci->Id)
  825. {
  826. ncci_mapping_bug++;
  827. dbug(1,dprintf("NCCI mapping doesn't exist %ld %08lx %02x",
  828. ncci_mapping_bug, Id, preserve_ncci));
  829. }
  830. else
  831. {
  832. cleanup_ncci_data (plci, ncci);
  833. dbug(1,dprintf("NCCI mapping released %ld %08lx %02x %02x-%02x",
  834. ncci_mapping_bug, Id, preserve_ncci, a->ncci_ch[ncci], ncci));
  835. a->ch_ncci[a->ncci_ch[ncci]] = 0;
  836. if (!preserve_ncci)
  837. {
  838. a->ncci_ch[ncci] = 0;
  839. a->ncci_plci[ncci] = 0;
  840. a->ncci_state[ncci] = IDLE;
  841. i = plci->ncci_ring_list;
  842. while ((i != 0) && (a->ncci_next[i] != plci->ncci_ring_list) && (a->ncci_next[i] != ncci))
  843. i = a->ncci_next[i];
  844. if ((i != 0) && (a->ncci_next[i] == ncci))
  845. {
  846. if (i == ncci)
  847. plci->ncci_ring_list = 0;
  848. else if (plci->ncci_ring_list == ncci)
  849. plci->ncci_ring_list = i;
  850. a->ncci_next[i] = a->ncci_next[ncci];
  851. }
  852. a->ncci_next[ncci] = 0;
  853. }
  854. }
  855. }
  856. else
  857. {
  858. for (ncci = 1; ncci < MAX_NCCI+1; ncci++)
  859. {
  860. if (a->ncci_plci[ncci] == plci->Id)
  861. {
  862. cleanup_ncci_data (plci, ncci);
  863. dbug(1,dprintf("NCCI mapping released %ld %08lx %02x %02x-%02x",
  864. ncci_mapping_bug, Id, preserve_ncci, a->ncci_ch[ncci], ncci));
  865. a->ch_ncci[a->ncci_ch[ncci]] = 0;
  866. if (!preserve_ncci)
  867. {
  868. a->ncci_ch[ncci] = 0;
  869. a->ncci_plci[ncci] = 0;
  870. a->ncci_state[ncci] = IDLE;
  871. a->ncci_next[ncci] = 0;
  872. }
  873. }
  874. }
  875. if (!preserve_ncci)
  876. plci->ncci_ring_list = 0;
  877. }
  878. }
  879. /*------------------------------------------------------------------*/
  880. /* PLCI remove function */
  881. /*------------------------------------------------------------------*/
  882. static void plci_free_msg_in_queue (PLCI *plci)
  883. {
  884. word i;
  885. if (plci->appl)
  886. {
  887. i = plci->msg_in_read_pos;
  888. while (i != plci->msg_in_write_pos)
  889. {
  890. if (i == plci->msg_in_wrap_pos)
  891. i = 0;
  892. if (((CAPI_MSG *)(&((byte *)(plci->msg_in_queue))[i]))->header.command == _DATA_B3_R)
  893. {
  894. TransmitBufferFree (plci->appl,
  895. (byte *)(long)(((CAPI_MSG *)(&((byte *)(plci->msg_in_queue))[i]))->info.data_b3_req.Data));
  896. }
  897. i += (((CAPI_MSG *)(&((byte *)(plci->msg_in_queue))[i]))->header.length +
  898. MSG_IN_OVERHEAD + 3) & 0xfffc;
  899. }
  900. }
  901. plci->msg_in_write_pos = MSG_IN_QUEUE_SIZE;
  902. plci->msg_in_read_pos = MSG_IN_QUEUE_SIZE;
  903. plci->msg_in_wrap_pos = MSG_IN_QUEUE_SIZE;
  904. }
  905. static void plci_remove(PLCI * plci)
  906. {
  907. if(!plci) {
  908. dbug(1,dprintf("plci_remove(no plci)"));
  909. return;
  910. }
  911. init_internal_command_queue (plci);
  912. dbug(1,dprintf("plci_remove(%x,tel=%x)",plci->Id,plci->tel));
  913. if(plci_remove_check(plci))
  914. {
  915. return;
  916. }
  917. if (plci->Sig.Id == 0xff)
  918. {
  919. dbug(1,dprintf("D-channel X.25 plci->NL.Id:%0x", plci->NL.Id));
  920. if (plci->NL.Id && !plci->nl_remove_id)
  921. {
  922. nl_req_ncci(plci,REMOVE,0);
  923. send_req(plci);
  924. }
  925. }
  926. else
  927. {
  928. if (!plci->sig_remove_id
  929. && (plci->Sig.Id
  930. || (plci->req_in!=plci->req_out)
  931. || (plci->nl_req || plci->sig_req)))
  932. {
  933. sig_req(plci,HANGUP,0);
  934. send_req(plci);
  935. }
  936. }
  937. ncci_remove (plci, 0, false);
  938. plci_free_msg_in_queue (plci);
  939. plci->channels = 0;
  940. plci->appl = NULL;
  941. if ((plci->State == INC_CON_PENDING) || (plci->State == INC_CON_ALERT))
  942. plci->State = OUTG_DIS_PENDING;
  943. }
  944. /*------------------------------------------------------------------*/
  945. /* Application Group function helpers */
  946. /*------------------------------------------------------------------*/
  947. static void set_group_ind_mask (PLCI *plci)
  948. {
  949. word i;
  950. for (i = 0; i < C_IND_MASK_DWORDS; i++)
  951. plci->group_optimization_mask_table[i] = 0xffffffffL;
  952. }
  953. static void clear_group_ind_mask_bit (PLCI *plci, word b)
  954. {
  955. plci->group_optimization_mask_table[b >> 5] &= ~(1L << (b & 0x1f));
  956. }
  957. static byte test_group_ind_mask_bit (PLCI *plci, word b)
  958. {
  959. return ((plci->group_optimization_mask_table[b >> 5] & (1L << (b & 0x1f))) != 0);
  960. }
  961. /*------------------------------------------------------------------*/
  962. /* c_ind_mask operations for arbitrary MAX_APPL */
  963. /*------------------------------------------------------------------*/
  964. static void clear_c_ind_mask (PLCI *plci)
  965. {
  966. word i;
  967. for (i = 0; i < C_IND_MASK_DWORDS; i++)
  968. plci->c_ind_mask_table[i] = 0;
  969. }
  970. static byte c_ind_mask_empty (PLCI *plci)
  971. {
  972. word i;
  973. i = 0;
  974. while ((i < C_IND_MASK_DWORDS) && (plci->c_ind_mask_table[i] == 0))
  975. i++;
  976. return (i == C_IND_MASK_DWORDS);
  977. }
  978. static void set_c_ind_mask_bit (PLCI *plci, word b)
  979. {
  980. plci->c_ind_mask_table[b >> 5] |= (1L << (b & 0x1f));
  981. }
  982. static void clear_c_ind_mask_bit (PLCI *plci, word b)
  983. {
  984. plci->c_ind_mask_table[b >> 5] &= ~(1L << (b & 0x1f));
  985. }
  986. static byte test_c_ind_mask_bit (PLCI *plci, word b)
  987. {
  988. return ((plci->c_ind_mask_table[b >> 5] & (1L << (b & 0x1f))) != 0);
  989. }
  990. static void dump_c_ind_mask (PLCI *plci)
  991. {
  992. static char hex_digit_table[0x10] =
  993. {'0','1','2','3','4','5','6','7','8','9','a','b','c','d','e','f'};
  994. word i, j, k;
  995. dword d;
  996. char *p;
  997. char buf[40];
  998. for (i = 0; i < C_IND_MASK_DWORDS; i += 4)
  999. {
  1000. p = buf + 36;
  1001. *p = '\0';
  1002. for (j = 0; j < 4; j++)
  1003. {
  1004. if (i+j < C_IND_MASK_DWORDS)
  1005. {
  1006. d = plci->c_ind_mask_table[i+j];
  1007. for (k = 0; k < 8; k++)
  1008. {
  1009. *(--p) = hex_digit_table[d & 0xf];
  1010. d >>= 4;
  1011. }
  1012. }
  1013. else if (i != 0)
  1014. {
  1015. for (k = 0; k < 8; k++)
  1016. *(--p) = ' ';
  1017. }
  1018. *(--p) = ' ';
  1019. }
  1020. dbug(1,dprintf ("c_ind_mask =%s", (char *) p));
  1021. }
  1022. }
  1023. #define dump_plcis(a)
  1024. /*------------------------------------------------------------------*/
  1025. /* translation function for each message */
  1026. /*------------------------------------------------------------------*/
  1027. 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 *)(long)(*((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 *)(long)(*((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 *)(long)(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 length + 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 < ARRAY_SIZE(fax_info))
  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)(long)(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!=NULL)
  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!=NULL)
  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!=NULL) 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 ARRAY_SIZE(dtmf_digit_map)
  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 >= ARRAY_SIZE(plci->dtmf_msg_number_queue))
  9214. {
  9215. dbug (1, dprintf ("[%06lx] %s,%d: DTMF request overrun",
  9216. UnMapId (Id), (char *)(FILE_), __LINE__));
  9217. Info = _WRONG_STATE;
  9218. break;
  9219. }
  9220. api_save_msg (dtmf_parms, "wwws", &plci->saved_msg);
  9221. start_internal_command (Id, plci, dtmf_command);
  9222. return (false);
  9223. default:
  9224. dbug (1, dprintf ("[%06lx] %s,%d: DTMF unknown request %04x",
  9225. UnMapId (Id), (char *)(FILE_), __LINE__, plci->dtmf_cmd));
  9226. PUT_WORD (&result[1], DTMF_UNKNOWN_REQUEST);
  9227. }
  9228. }
  9229. }
  9230. sendf (appl, _FACILITY_R | CONFIRM, Id & 0xffffL, Number,
  9231. "wws", Info, SELECTOR_DTMF, result);
  9232. return (false);
  9233. }
  9234. static void dtmf_confirmation (dword Id, PLCI *plci)
  9235. {
  9236. word Info;
  9237. word i;
  9238. byte result[4];
  9239. dbug (1, dprintf ("[%06lx] %s,%d: dtmf_confirmation",
  9240. UnMapId (Id), (char *)(FILE_), __LINE__));
  9241. Info = GOOD;
  9242. result[0] = 2;
  9243. PUT_WORD (&result[1], DTMF_SUCCESS);
  9244. if (plci->dtmf_send_requests != 0)
  9245. {
  9246. sendf (plci->appl, _FACILITY_R | CONFIRM, Id & 0xffffL, plci->dtmf_msg_number_queue[0],
  9247. "wws", GOOD, SELECTOR_DTMF, result);
  9248. (plci->dtmf_send_requests)--;
  9249. for (i = 0; i < plci->dtmf_send_requests; i++)
  9250. plci->dtmf_msg_number_queue[i] = plci->dtmf_msg_number_queue[i+1];
  9251. }
  9252. }
  9253. static void dtmf_indication (dword Id, PLCI *plci, byte *msg, word length)
  9254. {
  9255. word i, j, n;
  9256. dbug (1, dprintf ("[%06lx] %s,%d: dtmf_indication",
  9257. UnMapId (Id), (char *)(FILE_), __LINE__));
  9258. n = 0;
  9259. for (i = 1; i < length; i++)
  9260. {
  9261. j = 0;
  9262. while ((j < DTMF_DIGIT_MAP_ENTRIES)
  9263. && ((msg[i] != dtmf_digit_map[j].code)
  9264. || ((dtmf_digit_map[j].listen_mask & plci->dtmf_rec_active) == 0)))
  9265. {
  9266. j++;
  9267. }
  9268. if (j < DTMF_DIGIT_MAP_ENTRIES)
  9269. {
  9270. if ((dtmf_digit_map[j].listen_mask & DTMF_TONE_LISTEN_ACTIVE_FLAG)
  9271. && (plci->tone_last_indication_code == DTMF_SIGNAL_NO_TONE)
  9272. && (dtmf_digit_map[j].character != DTMF_SIGNAL_UNIDENTIFIED_TONE))
  9273. {
  9274. if (n + 1 == i)
  9275. {
  9276. for (i = length; i > n + 1; i--)
  9277. msg[i] = msg[i - 1];
  9278. length++;
  9279. i++;
  9280. }
  9281. msg[++n] = DTMF_SIGNAL_UNIDENTIFIED_TONE;
  9282. }
  9283. plci->tone_last_indication_code = dtmf_digit_map[j].character;
  9284. msg[++n] = dtmf_digit_map[j].character;
  9285. }
  9286. }
  9287. if (n != 0)
  9288. {
  9289. msg[0] = (byte) n;
  9290. sendf (plci->appl, _FACILITY_I, Id & 0xffffL, 0, "wS", SELECTOR_DTMF, msg);
  9291. }
  9292. }
  9293. /*------------------------------------------------------------------*/
  9294. /* DTMF parameters */
  9295. /*------------------------------------------------------------------*/
  9296. static void dtmf_parameter_write (PLCI *plci)
  9297. {
  9298. word i;
  9299. byte parameter_buffer[DTMF_PARAMETER_BUFFER_SIZE + 2];
  9300. dbug (1, dprintf ("[%06lx] %s,%d: dtmf_parameter_write",
  9301. (dword)((plci->Id << 8) | UnMapController (plci->adapter->Id)),
  9302. (char *)(FILE_), __LINE__));
  9303. parameter_buffer[0] = plci->dtmf_parameter_length + 1;
  9304. parameter_buffer[1] = DSP_CTRL_SET_DTMF_PARAMETERS;
  9305. for (i = 0; i < plci->dtmf_parameter_length; i++)
  9306. parameter_buffer[2+i] = plci->dtmf_parameter_buffer[i];
  9307. add_p (plci, FTY, parameter_buffer);
  9308. sig_req (plci, TEL_CTRL, 0);
  9309. send_req (plci);
  9310. }
  9311. static void dtmf_parameter_clear_config (PLCI *plci)
  9312. {
  9313. dbug (1, dprintf ("[%06lx] %s,%d: dtmf_parameter_clear_config",
  9314. (dword)((plci->Id << 8) | UnMapController (plci->adapter->Id)),
  9315. (char *)(FILE_), __LINE__));
  9316. plci->dtmf_parameter_length = 0;
  9317. }
  9318. static void dtmf_parameter_prepare_switch (dword Id, PLCI *plci)
  9319. {
  9320. dbug (1, dprintf ("[%06lx] %s,%d: dtmf_parameter_prepare_switch",
  9321. UnMapId (Id), (char *)(FILE_), __LINE__));
  9322. }
  9323. static word dtmf_parameter_save_config (dword Id, PLCI *plci, byte Rc)
  9324. {
  9325. dbug (1, dprintf ("[%06lx] %s,%d: dtmf_parameter_save_config %02x %d",
  9326. UnMapId (Id), (char *)(FILE_), __LINE__, Rc, plci->adjust_b_state));
  9327. return (GOOD);
  9328. }
  9329. static word dtmf_parameter_restore_config (dword Id, PLCI *plci, byte Rc)
  9330. {
  9331. word Info;
  9332. dbug (1, dprintf ("[%06lx] %s,%d: dtmf_parameter_restore_config %02x %d",
  9333. UnMapId (Id), (char *)(FILE_), __LINE__, Rc, plci->adjust_b_state));
  9334. Info = GOOD;
  9335. if ((plci->B1_facilities & B1_FACILITY_DTMFR)
  9336. && (plci->dtmf_parameter_length != 0))
  9337. {
  9338. switch (plci->adjust_b_state)
  9339. {
  9340. case ADJUST_B_RESTORE_DTMF_PARAMETER_1:
  9341. plci->internal_command = plci->adjust_b_command;
  9342. if (plci->sig_req)
  9343. {
  9344. plci->adjust_b_state = ADJUST_B_RESTORE_DTMF_PARAMETER_1;
  9345. break;
  9346. }
  9347. dtmf_parameter_write (plci);
  9348. plci->adjust_b_state = ADJUST_B_RESTORE_DTMF_PARAMETER_2;
  9349. break;
  9350. case ADJUST_B_RESTORE_DTMF_PARAMETER_2:
  9351. if ((Rc != OK) && (Rc != OK_FC))
  9352. {
  9353. dbug (1, dprintf ("[%06lx] %s,%d: Restore DTMF parameters failed %02x",
  9354. UnMapId (Id), (char *)(FILE_), __LINE__, Rc));
  9355. Info = _WRONG_STATE;
  9356. break;
  9357. }
  9358. break;
  9359. }
  9360. }
  9361. return (Info);
  9362. }
  9363. /*------------------------------------------------------------------*/
  9364. /* Line interconnect facilities */
  9365. /*------------------------------------------------------------------*/
  9366. LI_CONFIG *li_config_table;
  9367. word li_total_channels;
  9368. /*------------------------------------------------------------------*/
  9369. /* translate a CHI information element to a channel number */
  9370. /* returns 0xff - any channel */
  9371. /* 0xfe - chi wrong coding */
  9372. /* 0xfd - D-channel */
  9373. /* 0x00 - no channel */
  9374. /* else channel number / PRI: timeslot */
  9375. /* if channels is provided we accept more than one channel. */
  9376. /*------------------------------------------------------------------*/
  9377. static byte chi_to_channel (byte *chi, dword *pchannelmap)
  9378. {
  9379. int p;
  9380. int i;
  9381. dword map;
  9382. byte excl;
  9383. byte ofs;
  9384. byte ch;
  9385. if (pchannelmap) *pchannelmap = 0;
  9386. if(!chi[0]) return 0xff;
  9387. excl = 0;
  9388. if(chi[1] & 0x20) {
  9389. if(chi[0]==1 && chi[1]==0xac) return 0xfd; /* exclusive d-channel */
  9390. for(i=1; i<chi[0] && !(chi[i] &0x80); i++);
  9391. if(i==chi[0] || !(chi[i] &0x80)) return 0xfe;
  9392. if((chi[1] |0xc8)!=0xe9) return 0xfe;
  9393. if(chi[1] &0x08) excl = 0x40;
  9394. /* int. id present */
  9395. if(chi[1] &0x40) {
  9396. p=i+1;
  9397. for(i=p; i<chi[0] && !(chi[i] &0x80); i++);
  9398. if(i==chi[0] || !(chi[i] &0x80)) return 0xfe;
  9399. }
  9400. /* coding standard, Number/Map, Channel Type */
  9401. p=i+1;
  9402. for(i=p; i<chi[0] && !(chi[i] &0x80); i++);
  9403. if(i==chi[0] || !(chi[i] &0x80)) return 0xfe;
  9404. if((chi[p]|0xd0)!=0xd3) return 0xfe;
  9405. /* Number/Map */
  9406. if(chi[p] &0x10) {
  9407. /* map */
  9408. if((chi[0]-p)==4) ofs = 0;
  9409. else if((chi[0]-p)==3) ofs = 1;
  9410. else return 0xfe;
  9411. ch = 0;
  9412. map = 0;
  9413. for(i=0; i<4 && p<chi[0]; i++) {
  9414. p++;
  9415. ch += 8;
  9416. map <<= 8;
  9417. if(chi[p]) {
  9418. for (ch=0; !(chi[p] & (1 << ch)); ch++);
  9419. map |= chi[p];
  9420. }
  9421. }
  9422. ch += ofs;
  9423. map <<= ofs;
  9424. }
  9425. else {
  9426. /* number */
  9427. p=i+1;
  9428. ch = chi[p] &0x3f;
  9429. if(pchannelmap) {
  9430. if((byte)(chi[0]-p)>30) return 0xfe;
  9431. map = 0;
  9432. for(i=p; i<=chi[0]; i++) {
  9433. if ((chi[i] &0x7f) > 31) return 0xfe;
  9434. map |= (1L << (chi[i] &0x7f));
  9435. }
  9436. }
  9437. else {
  9438. if(p!=chi[0]) return 0xfe;
  9439. if (ch > 31) return 0xfe;
  9440. map = (1L << ch);
  9441. }
  9442. if(chi[p] &0x40) return 0xfe;
  9443. }
  9444. if (pchannelmap) *pchannelmap = map;
  9445. else if (map != ((dword)(1L << ch))) return 0xfe;
  9446. return (byte)(excl | ch);
  9447. }
  9448. else { /* not PRI */
  9449. for(i=1; i<chi[0] && !(chi[i] &0x80); i++);
  9450. if(i!=chi[0] || !(chi[i] &0x80)) return 0xfe;
  9451. if(chi[1] &0x08) excl = 0x40;
  9452. switch(chi[1] |0x98) {
  9453. case 0x98: return 0;
  9454. case 0x99:
  9455. if (pchannelmap) *pchannelmap = 2;
  9456. return excl |1;
  9457. case 0x9a:
  9458. if (pchannelmap) *pchannelmap = 4;
  9459. return excl |2;
  9460. case 0x9b: return 0xff;
  9461. case 0x9c: return 0xfd; /* d-ch */
  9462. default: return 0xfe;
  9463. }
  9464. }
  9465. }
  9466. static void mixer_set_bchannel_id_esc (PLCI *plci, byte bchannel_id)
  9467. {
  9468. DIVA_CAPI_ADAPTER *a;
  9469. PLCI *splci;
  9470. byte old_id;
  9471. a = plci->adapter;
  9472. old_id = plci->li_bchannel_id;
  9473. if (a->li_pri)
  9474. {
  9475. if ((old_id != 0) && (li_config_table[a->li_base + (old_id - 1)].plci == plci))
  9476. li_config_table[a->li_base + (old_id - 1)].plci = NULL;
  9477. plci->li_bchannel_id = (bchannel_id & 0x1f) + 1;
  9478. if (li_config_table[a->li_base + (plci->li_bchannel_id - 1)].plci == NULL)
  9479. li_config_table[a->li_base + (plci->li_bchannel_id - 1)].plci = plci;
  9480. }
  9481. else
  9482. {
  9483. if (((bchannel_id & 0x03) == 1) || ((bchannel_id & 0x03) == 2))
  9484. {
  9485. if ((old_id != 0) && (li_config_table[a->li_base + (old_id - 1)].plci == plci))
  9486. li_config_table[a->li_base + (old_id - 1)].plci = NULL;
  9487. plci->li_bchannel_id = bchannel_id & 0x03;
  9488. if ((a->AdvSignalPLCI != NULL) && (a->AdvSignalPLCI != plci) && (a->AdvSignalPLCI->tel == ADV_VOICE))
  9489. {
  9490. splci = a->AdvSignalPLCI;
  9491. if (li_config_table[a->li_base + (2 - plci->li_bchannel_id)].plci == NULL)
  9492. {
  9493. if ((splci->li_bchannel_id != 0)
  9494. && (li_config_table[a->li_base + (splci->li_bchannel_id - 1)].plci == splci))
  9495. {
  9496. li_config_table[a->li_base + (splci->li_bchannel_id - 1)].plci = NULL;
  9497. }
  9498. splci->li_bchannel_id = 3 - plci->li_bchannel_id;
  9499. li_config_table[a->li_base + (2 - plci->li_bchannel_id)].plci = splci;
  9500. dbug (1, dprintf ("[%06lx] %s,%d: adv_voice_set_bchannel_id_esc %d",
  9501. (dword)((splci->Id << 8) | UnMapController (splci->adapter->Id)),
  9502. (char *)(FILE_), __LINE__, splci->li_bchannel_id));
  9503. }
  9504. }
  9505. if (li_config_table[a->li_base + (plci->li_bchannel_id - 1)].plci == NULL)
  9506. li_config_table[a->li_base + (plci->li_bchannel_id - 1)].plci = plci;
  9507. }
  9508. }
  9509. if ((old_id == 0) && (plci->li_bchannel_id != 0)
  9510. && (li_config_table[a->li_base + (plci->li_bchannel_id - 1)].plci == plci))
  9511. {
  9512. mixer_clear_config (plci);
  9513. }
  9514. dbug (1, dprintf ("[%06lx] %s,%d: mixer_set_bchannel_id_esc %d %d",
  9515. (dword)((plci->Id << 8) | UnMapController (plci->adapter->Id)),
  9516. (char *)(FILE_), __LINE__, bchannel_id, plci->li_bchannel_id));
  9517. }
  9518. static void mixer_set_bchannel_id (PLCI *plci, byte *chi)
  9519. {
  9520. DIVA_CAPI_ADAPTER *a;
  9521. PLCI *splci;
  9522. byte ch, old_id;
  9523. a = plci->adapter;
  9524. old_id = plci->li_bchannel_id;
  9525. ch = chi_to_channel (chi, NULL);
  9526. if (!(ch & 0x80))
  9527. {
  9528. if (a->li_pri)
  9529. {
  9530. if ((old_id != 0) && (li_config_table[a->li_base + (old_id - 1)].plci == plci))
  9531. li_config_table[a->li_base + (old_id - 1)].plci = NULL;
  9532. plci->li_bchannel_id = (ch & 0x1f) + 1;
  9533. if (li_config_table[a->li_base + (plci->li_bchannel_id - 1)].plci == NULL)
  9534. li_config_table[a->li_base + (plci->li_bchannel_id - 1)].plci = plci;
  9535. }
  9536. else
  9537. {
  9538. if (((ch & 0x1f) == 1) || ((ch & 0x1f) == 2))
  9539. {
  9540. if ((old_id != 0) && (li_config_table[a->li_base + (old_id - 1)].plci == plci))
  9541. li_config_table[a->li_base + (old_id - 1)].plci = NULL;
  9542. plci->li_bchannel_id = ch & 0x1f;
  9543. if ((a->AdvSignalPLCI != NULL) && (a->AdvSignalPLCI != plci) && (a->AdvSignalPLCI->tel == ADV_VOICE))
  9544. {
  9545. splci = a->AdvSignalPLCI;
  9546. if (li_config_table[a->li_base + (2 - plci->li_bchannel_id)].plci == NULL)
  9547. {
  9548. if ((splci->li_bchannel_id != 0)
  9549. && (li_config_table[a->li_base + (splci->li_bchannel_id - 1)].plci == splci))
  9550. {
  9551. li_config_table[a->li_base + (splci->li_bchannel_id - 1)].plci = NULL;
  9552. }
  9553. splci->li_bchannel_id = 3 - plci->li_bchannel_id;
  9554. li_config_table[a->li_base + (2 - plci->li_bchannel_id)].plci = splci;
  9555. dbug (1, dprintf ("[%06lx] %s,%d: adv_voice_set_bchannel_id %d",
  9556. (dword)((splci->Id << 8) | UnMapController (splci->adapter->Id)),
  9557. (char *)(FILE_), __LINE__, splci->li_bchannel_id));
  9558. }
  9559. }
  9560. if (li_config_table[a->li_base + (plci->li_bchannel_id - 1)].plci == NULL)
  9561. li_config_table[a->li_base + (plci->li_bchannel_id - 1)].plci = plci;
  9562. }
  9563. }
  9564. }
  9565. if ((old_id == 0) && (plci->li_bchannel_id != 0)
  9566. && (li_config_table[a->li_base + (plci->li_bchannel_id - 1)].plci == plci))
  9567. {
  9568. mixer_clear_config (plci);
  9569. }
  9570. dbug (1, dprintf ("[%06lx] %s,%d: mixer_set_bchannel_id %02x %d",
  9571. (dword)((plci->Id << 8) | UnMapController (plci->adapter->Id)),
  9572. (char *)(FILE_), __LINE__, ch, plci->li_bchannel_id));
  9573. }
  9574. #define MIXER_MAX_DUMP_CHANNELS 34
  9575. static void mixer_calculate_coefs (DIVA_CAPI_ADAPTER *a)
  9576. {
  9577. static char hex_digit_table[0x10] = {'0','1','2','3','4','5','6','7','8','9','a','b','c','d','e','f'};
  9578. word n, i, j;
  9579. char *p;
  9580. char hex_line[2 * MIXER_MAX_DUMP_CHANNELS + MIXER_MAX_DUMP_CHANNELS / 8 + 4];
  9581. dbug (1, dprintf ("[%06lx] %s,%d: mixer_calculate_coefs",
  9582. (dword)(UnMapController (a->Id)), (char *)(FILE_), __LINE__));
  9583. for (i = 0; i < li_total_channels; i++)
  9584. {
  9585. li_config_table[i].channel &= LI_CHANNEL_ADDRESSES_SET;
  9586. if (li_config_table[i].chflags != 0)
  9587. li_config_table[i].channel |= LI_CHANNEL_INVOLVED;
  9588. else
  9589. {
  9590. for (j = 0; j < li_total_channels; j++)
  9591. {
  9592. if (((li_config_table[i].flag_table[j]) != 0)
  9593. || ((li_config_table[j].flag_table[i]) != 0))
  9594. {
  9595. li_config_table[i].channel |= LI_CHANNEL_INVOLVED;
  9596. }
  9597. if (((li_config_table[i].flag_table[j] & LI_FLAG_CONFERENCE) != 0)
  9598. || ((li_config_table[j].flag_table[i] & LI_FLAG_CONFERENCE) != 0))
  9599. {
  9600. li_config_table[i].channel |= LI_CHANNEL_CONFERENCE;
  9601. }
  9602. }
  9603. }
  9604. }
  9605. for (i = 0; i < li_total_channels; i++)
  9606. {
  9607. for (j = 0; j < li_total_channels; j++)
  9608. {
  9609. li_config_table[i].coef_table[j] &= ~(LI_COEF_CH_CH | LI_COEF_CH_PC | LI_COEF_PC_CH | LI_COEF_PC_PC);
  9610. if (li_config_table[i].flag_table[j] & LI_FLAG_CONFERENCE)
  9611. li_config_table[i].coef_table[j] |= LI_COEF_CH_CH;
  9612. }
  9613. }
  9614. for (n = 0; n < li_total_channels; n++)
  9615. {
  9616. if (li_config_table[n].channel & LI_CHANNEL_CONFERENCE)
  9617. {
  9618. for (i = 0; i < li_total_channels; i++)
  9619. {
  9620. if (li_config_table[i].channel & LI_CHANNEL_CONFERENCE)
  9621. {
  9622. for (j = 0; j < li_total_channels; j++)
  9623. {
  9624. li_config_table[i].coef_table[j] |=
  9625. li_config_table[i].coef_table[n] & li_config_table[n].coef_table[j];
  9626. }
  9627. }
  9628. }
  9629. }
  9630. }
  9631. for (i = 0; i < li_total_channels; i++)
  9632. {
  9633. if (li_config_table[i].channel & LI_CHANNEL_INVOLVED)
  9634. {
  9635. li_config_table[i].coef_table[i] &= ~LI_COEF_CH_CH;
  9636. for (j = 0; j < li_total_channels; j++)
  9637. {
  9638. if (li_config_table[i].coef_table[j] & LI_COEF_CH_CH)
  9639. li_config_table[i].flag_table[j] |= LI_FLAG_CONFERENCE;
  9640. }
  9641. if (li_config_table[i].flag_table[i] & LI_FLAG_CONFERENCE)
  9642. li_config_table[i].coef_table[i] |= LI_COEF_CH_CH;
  9643. }
  9644. }
  9645. for (i = 0; i < li_total_channels; i++)
  9646. {
  9647. if (li_config_table[i].channel & LI_CHANNEL_INVOLVED)
  9648. {
  9649. for (j = 0; j < li_total_channels; j++)
  9650. {
  9651. if (li_config_table[i].flag_table[j] & LI_FLAG_INTERCONNECT)
  9652. li_config_table[i].coef_table[j] |= LI_COEF_CH_CH;
  9653. if (li_config_table[i].flag_table[j] & LI_FLAG_MONITOR)
  9654. li_config_table[i].coef_table[j] |= LI_COEF_CH_PC;
  9655. if (li_config_table[i].flag_table[j] & LI_FLAG_MIX)
  9656. li_config_table[i].coef_table[j] |= LI_COEF_PC_CH;
  9657. if (li_config_table[i].flag_table[j] & LI_FLAG_PCCONNECT)
  9658. li_config_table[i].coef_table[j] |= LI_COEF_PC_PC;
  9659. }
  9660. if (li_config_table[i].chflags & LI_CHFLAG_MONITOR)
  9661. {
  9662. for (j = 0; j < li_total_channels; j++)
  9663. {
  9664. if (li_config_table[i].flag_table[j] & LI_FLAG_INTERCONNECT)
  9665. {
  9666. li_config_table[i].coef_table[j] |= LI_COEF_CH_PC;
  9667. if (li_config_table[j].chflags & LI_CHFLAG_MIX)
  9668. li_config_table[i].coef_table[j] |= LI_COEF_PC_CH | LI_COEF_PC_PC;
  9669. }
  9670. }
  9671. }
  9672. if (li_config_table[i].chflags & LI_CHFLAG_MIX)
  9673. {
  9674. for (j = 0; j < li_total_channels; j++)
  9675. {
  9676. if (li_config_table[j].flag_table[i] & LI_FLAG_INTERCONNECT)
  9677. li_config_table[j].coef_table[i] |= LI_COEF_PC_CH;
  9678. }
  9679. }
  9680. if (li_config_table[i].chflags & LI_CHFLAG_LOOP)
  9681. {
  9682. for (j = 0; j < li_total_channels; j++)
  9683. {
  9684. if (li_config_table[i].flag_table[j] & LI_FLAG_INTERCONNECT)
  9685. {
  9686. for (n = 0; n < li_total_channels; n++)
  9687. {
  9688. if (li_config_table[n].flag_table[i] & LI_FLAG_INTERCONNECT)
  9689. {
  9690. li_config_table[n].coef_table[j] |= LI_COEF_CH_CH;
  9691. if (li_config_table[j].chflags & LI_CHFLAG_MIX)
  9692. {
  9693. li_config_table[n].coef_table[j] |= LI_COEF_PC_CH;
  9694. if (li_config_table[n].chflags & LI_CHFLAG_MONITOR)
  9695. li_config_table[n].coef_table[j] |= LI_COEF_CH_PC | LI_COEF_PC_PC;
  9696. }
  9697. else if (li_config_table[n].chflags & LI_CHFLAG_MONITOR)
  9698. li_config_table[n].coef_table[j] |= LI_COEF_CH_PC;
  9699. }
  9700. }
  9701. }
  9702. }
  9703. }
  9704. }
  9705. }
  9706. for (i = 0; i < li_total_channels; i++)
  9707. {
  9708. if (li_config_table[i].channel & LI_CHANNEL_INVOLVED)
  9709. {
  9710. if (li_config_table[i].chflags & (LI_CHFLAG_MONITOR | LI_CHFLAG_MIX | LI_CHFLAG_LOOP))
  9711. li_config_table[i].channel |= LI_CHANNEL_ACTIVE;
  9712. if (li_config_table[i].chflags & LI_CHFLAG_MONITOR)
  9713. li_config_table[i].channel |= LI_CHANNEL_RX_DATA;
  9714. if (li_config_table[i].chflags & LI_CHFLAG_MIX)
  9715. li_config_table[i].channel |= LI_CHANNEL_TX_DATA;
  9716. for (j = 0; j < li_total_channels; j++)
  9717. {
  9718. if ((li_config_table[i].flag_table[j] &
  9719. (LI_FLAG_INTERCONNECT | LI_FLAG_PCCONNECT | LI_FLAG_CONFERENCE | LI_FLAG_MONITOR))
  9720. || (li_config_table[j].flag_table[i] &
  9721. (LI_FLAG_INTERCONNECT | LI_FLAG_PCCONNECT | LI_FLAG_CONFERENCE | LI_FLAG_ANNOUNCEMENT | LI_FLAG_MIX)))
  9722. {
  9723. li_config_table[i].channel |= LI_CHANNEL_ACTIVE;
  9724. }
  9725. if (li_config_table[i].flag_table[j] & (LI_FLAG_PCCONNECT | LI_FLAG_MONITOR))
  9726. li_config_table[i].channel |= LI_CHANNEL_RX_DATA;
  9727. if (li_config_table[j].flag_table[i] & (LI_FLAG_PCCONNECT | LI_FLAG_ANNOUNCEMENT | LI_FLAG_MIX))
  9728. li_config_table[i].channel |= LI_CHANNEL_TX_DATA;
  9729. }
  9730. if (!(li_config_table[i].channel & LI_CHANNEL_ACTIVE))
  9731. {
  9732. li_config_table[i].coef_table[i] |= LI_COEF_PC_CH | LI_COEF_CH_PC;
  9733. li_config_table[i].channel |= LI_CHANNEL_TX_DATA | LI_CHANNEL_RX_DATA;
  9734. }
  9735. }
  9736. }
  9737. for (i = 0; i < li_total_channels; i++)
  9738. {
  9739. if (li_config_table[i].channel & LI_CHANNEL_INVOLVED)
  9740. {
  9741. j = 0;
  9742. while ((j < li_total_channels) && !(li_config_table[i].flag_table[j] & LI_FLAG_ANNOUNCEMENT))
  9743. j++;
  9744. if (j < li_total_channels)
  9745. {
  9746. for (j = 0; j < li_total_channels; j++)
  9747. {
  9748. li_config_table[i].coef_table[j] &= ~(LI_COEF_CH_CH | LI_COEF_PC_CH);
  9749. if (li_config_table[i].flag_table[j] & LI_FLAG_ANNOUNCEMENT)
  9750. li_config_table[i].coef_table[j] |= LI_COEF_PC_CH;
  9751. }
  9752. }
  9753. }
  9754. }
  9755. n = li_total_channels;
  9756. if (n > MIXER_MAX_DUMP_CHANNELS)
  9757. n = MIXER_MAX_DUMP_CHANNELS;
  9758. p = hex_line;
  9759. for (j = 0; j < n; j++)
  9760. {
  9761. if ((j & 0x7) == 0)
  9762. *(p++) = ' ';
  9763. *(p++) = hex_digit_table[li_config_table[j].curchnl >> 4];
  9764. *(p++) = hex_digit_table[li_config_table[j].curchnl & 0xf];
  9765. }
  9766. *p = '\0';
  9767. dbug (1, dprintf ("[%06lx] CURRENT %s",
  9768. (dword)(UnMapController (a->Id)), (char *) hex_line));
  9769. p = hex_line;
  9770. for (j = 0; j < n; j++)
  9771. {
  9772. if ((j & 0x7) == 0)
  9773. *(p++) = ' ';
  9774. *(p++) = hex_digit_table[li_config_table[j].channel >> 4];
  9775. *(p++) = hex_digit_table[li_config_table[j].channel & 0xf];
  9776. }
  9777. *p = '\0';
  9778. dbug (1, dprintf ("[%06lx] CHANNEL %s",
  9779. (dword)(UnMapController (a->Id)), (char *) hex_line));
  9780. p = hex_line;
  9781. for (j = 0; j < n; j++)
  9782. {
  9783. if ((j & 0x7) == 0)
  9784. *(p++) = ' ';
  9785. *(p++) = hex_digit_table[li_config_table[j].chflags >> 4];
  9786. *(p++) = hex_digit_table[li_config_table[j].chflags & 0xf];
  9787. }
  9788. *p = '\0';
  9789. dbug (1, dprintf ("[%06lx] CHFLAG %s",
  9790. (dword)(UnMapController (a->Id)), (char *) hex_line));
  9791. for (i = 0; i < n; i++)
  9792. {
  9793. p = hex_line;
  9794. for (j = 0; j < n; j++)
  9795. {
  9796. if ((j & 0x7) == 0)
  9797. *(p++) = ' ';
  9798. *(p++) = hex_digit_table[li_config_table[i].flag_table[j] >> 4];
  9799. *(p++) = hex_digit_table[li_config_table[i].flag_table[j] & 0xf];
  9800. }
  9801. *p = '\0';
  9802. dbug (1, dprintf ("[%06lx] FLAG[%02x]%s",
  9803. (dword)(UnMapController (a->Id)), i, (char *) hex_line));
  9804. }
  9805. for (i = 0; i < n; i++)
  9806. {
  9807. p = hex_line;
  9808. for (j = 0; j < n; j++)
  9809. {
  9810. if ((j & 0x7) == 0)
  9811. *(p++) = ' ';
  9812. *(p++) = hex_digit_table[li_config_table[i].coef_table[j] >> 4];
  9813. *(p++) = hex_digit_table[li_config_table[i].coef_table[j] & 0xf];
  9814. }
  9815. *p = '\0';
  9816. dbug (1, dprintf ("[%06lx] COEF[%02x]%s",
  9817. (dword)(UnMapController (a->Id)), i, (char *) hex_line));
  9818. }
  9819. }
  9820. static struct
  9821. {
  9822. byte mask;
  9823. byte line_flags;
  9824. } mixer_write_prog_pri[] =
  9825. {
  9826. { LI_COEF_CH_CH, 0 },
  9827. { LI_COEF_CH_PC, MIXER_COEF_LINE_TO_PC_FLAG },
  9828. { LI_COEF_PC_CH, MIXER_COEF_LINE_FROM_PC_FLAG },
  9829. { LI_COEF_PC_PC, MIXER_COEF_LINE_TO_PC_FLAG | MIXER_COEF_LINE_FROM_PC_FLAG }
  9830. };
  9831. static struct
  9832. {
  9833. byte from_ch;
  9834. byte to_ch;
  9835. byte mask;
  9836. byte xconnect_override;
  9837. } mixer_write_prog_bri[] =
  9838. {
  9839. { 0, 0, LI_COEF_CH_CH, 0x01 }, /* B to B */
  9840. { 1, 0, LI_COEF_CH_CH, 0x01 }, /* Alt B to B */
  9841. { 0, 0, LI_COEF_PC_CH, 0x80 }, /* PC to B */
  9842. { 1, 0, LI_COEF_PC_CH, 0x01 }, /* Alt PC to B */
  9843. { 2, 0, LI_COEF_CH_CH, 0x00 }, /* IC to B */
  9844. { 3, 0, LI_COEF_CH_CH, 0x00 }, /* Alt IC to B */
  9845. { 0, 0, LI_COEF_CH_PC, 0x80 }, /* B to PC */
  9846. { 1, 0, LI_COEF_CH_PC, 0x01 }, /* Alt B to PC */
  9847. { 0, 0, LI_COEF_PC_PC, 0x01 }, /* PC to PC */
  9848. { 1, 0, LI_COEF_PC_PC, 0x01 }, /* Alt PC to PC */
  9849. { 2, 0, LI_COEF_CH_PC, 0x00 }, /* IC to PC */
  9850. { 3, 0, LI_COEF_CH_PC, 0x00 }, /* Alt IC to PC */
  9851. { 0, 2, LI_COEF_CH_CH, 0x00 }, /* B to IC */
  9852. { 1, 2, LI_COEF_CH_CH, 0x00 }, /* Alt B to IC */
  9853. { 0, 2, LI_COEF_PC_CH, 0x00 }, /* PC to IC */
  9854. { 1, 2, LI_COEF_PC_CH, 0x00 }, /* Alt PC to IC */
  9855. { 2, 2, LI_COEF_CH_CH, 0x00 }, /* IC to IC */
  9856. { 3, 2, LI_COEF_CH_CH, 0x00 }, /* Alt IC to IC */
  9857. { 1, 1, LI_COEF_CH_CH, 0x01 }, /* Alt B to Alt B */
  9858. { 0, 1, LI_COEF_CH_CH, 0x01 }, /* B to Alt B */
  9859. { 1, 1, LI_COEF_PC_CH, 0x80 }, /* Alt PC to Alt B */
  9860. { 0, 1, LI_COEF_PC_CH, 0x01 }, /* PC to Alt B */
  9861. { 3, 1, LI_COEF_CH_CH, 0x00 }, /* Alt IC to Alt B */
  9862. { 2, 1, LI_COEF_CH_CH, 0x00 }, /* IC to Alt B */
  9863. { 1, 1, LI_COEF_CH_PC, 0x80 }, /* Alt B to Alt PC */
  9864. { 0, 1, LI_COEF_CH_PC, 0x01 }, /* B to Alt PC */
  9865. { 1, 1, LI_COEF_PC_PC, 0x01 }, /* Alt PC to Alt PC */
  9866. { 0, 1, LI_COEF_PC_PC, 0x01 }, /* PC to Alt PC */
  9867. { 3, 1, LI_COEF_CH_PC, 0x00 }, /* Alt IC to Alt PC */
  9868. { 2, 1, LI_COEF_CH_PC, 0x00 }, /* IC to Alt PC */
  9869. { 1, 3, LI_COEF_CH_CH, 0x00 }, /* Alt B to Alt IC */
  9870. { 0, 3, LI_COEF_CH_CH, 0x00 }, /* B to Alt IC */
  9871. { 1, 3, LI_COEF_PC_CH, 0x00 }, /* Alt PC to Alt IC */
  9872. { 0, 3, LI_COEF_PC_CH, 0x00 }, /* PC to Alt IC */
  9873. { 3, 3, LI_COEF_CH_CH, 0x00 }, /* Alt IC to Alt IC */
  9874. { 2, 3, LI_COEF_CH_CH, 0x00 } /* IC to Alt IC */
  9875. };
  9876. static byte mixer_swapped_index_bri[] =
  9877. {
  9878. 18, /* B to B */
  9879. 19, /* Alt B to B */
  9880. 20, /* PC to B */
  9881. 21, /* Alt PC to B */
  9882. 22, /* IC to B */
  9883. 23, /* Alt IC to B */
  9884. 24, /* B to PC */
  9885. 25, /* Alt B to PC */
  9886. 26, /* PC to PC */
  9887. 27, /* Alt PC to PC */
  9888. 28, /* IC to PC */
  9889. 29, /* Alt IC to PC */
  9890. 30, /* B to IC */
  9891. 31, /* Alt B to IC */
  9892. 32, /* PC to IC */
  9893. 33, /* Alt PC to IC */
  9894. 34, /* IC to IC */
  9895. 35, /* Alt IC to IC */
  9896. 0, /* Alt B to Alt B */
  9897. 1, /* B to Alt B */
  9898. 2, /* Alt PC to Alt B */
  9899. 3, /* PC to Alt B */
  9900. 4, /* Alt IC to Alt B */
  9901. 5, /* IC to Alt B */
  9902. 6, /* Alt B to Alt PC */
  9903. 7, /* B to Alt PC */
  9904. 8, /* Alt PC to Alt PC */
  9905. 9, /* PC to Alt PC */
  9906. 10, /* Alt IC to Alt PC */
  9907. 11, /* IC to Alt PC */
  9908. 12, /* Alt B to Alt IC */
  9909. 13, /* B to Alt IC */
  9910. 14, /* Alt PC to Alt IC */
  9911. 15, /* PC to Alt IC */
  9912. 16, /* Alt IC to Alt IC */
  9913. 17 /* IC to Alt IC */
  9914. };
  9915. static struct
  9916. {
  9917. byte mask;
  9918. byte from_pc;
  9919. byte to_pc;
  9920. } xconnect_write_prog[] =
  9921. {
  9922. { LI_COEF_CH_CH, false, false },
  9923. { LI_COEF_CH_PC, false, true },
  9924. { LI_COEF_PC_CH, true, false },
  9925. { LI_COEF_PC_PC, true, true }
  9926. };
  9927. static void xconnect_query_addresses (PLCI *plci)
  9928. {
  9929. DIVA_CAPI_ADAPTER *a;
  9930. word w, ch;
  9931. byte *p;
  9932. dbug (1, dprintf ("[%06lx] %s,%d: xconnect_query_addresses",
  9933. (dword)((plci->Id << 8) | UnMapController (plci->adapter->Id)),
  9934. (char *)(FILE_), __LINE__));
  9935. a = plci->adapter;
  9936. if (a->li_pri && ((plci->li_bchannel_id == 0)
  9937. || (li_config_table[a->li_base + (plci->li_bchannel_id - 1)].plci != plci)))
  9938. {
  9939. dbug (1, dprintf ("[%06x] %s,%d: Channel id wiped out",
  9940. (dword)((plci->Id << 8) | UnMapController (plci->adapter->Id)),
  9941. (char *)(FILE_), __LINE__));
  9942. return;
  9943. }
  9944. p = plci->internal_req_buffer;
  9945. ch = (a->li_pri) ? plci->li_bchannel_id - 1 : 0;
  9946. *(p++) = UDATA_REQUEST_XCONNECT_FROM;
  9947. w = ch;
  9948. *(p++) = (byte) w;
  9949. *(p++) = (byte)(w >> 8);
  9950. w = ch | XCONNECT_CHANNEL_PORT_PC;
  9951. *(p++) = (byte) w;
  9952. *(p++) = (byte)(w >> 8);
  9953. plci->NData[0].P = plci->internal_req_buffer;
  9954. plci->NData[0].PLength = p - plci->internal_req_buffer;
  9955. plci->NL.X = plci->NData;
  9956. plci->NL.ReqCh = 0;
  9957. plci->NL.Req = plci->nl_req = (byte) N_UDATA;
  9958. plci->adapter->request (&plci->NL);
  9959. }
  9960. static void xconnect_write_coefs (PLCI *plci, word internal_command)
  9961. {
  9962. dbug (1, dprintf ("[%06lx] %s,%d: xconnect_write_coefs %04x",
  9963. (dword)((plci->Id << 8) | UnMapController (plci->adapter->Id)),
  9964. (char *)(FILE_), __LINE__, internal_command));
  9965. plci->li_write_command = internal_command;
  9966. plci->li_write_channel = 0;
  9967. }
  9968. static byte xconnect_write_coefs_process (dword Id, PLCI *plci, byte Rc)
  9969. {
  9970. DIVA_CAPI_ADAPTER *a;
  9971. word w, n, i, j, r, s, to_ch;
  9972. dword d;
  9973. byte *p;
  9974. struct xconnect_transfer_address_s *transfer_address;
  9975. byte ch_map[MIXER_CHANNELS_BRI];
  9976. dbug (1, dprintf ("[%06x] %s,%d: xconnect_write_coefs_process %02x %d",
  9977. UnMapId (Id), (char *)(FILE_), __LINE__, Rc, plci->li_write_channel));
  9978. a = plci->adapter;
  9979. if ((plci->li_bchannel_id == 0)
  9980. || (li_config_table[a->li_base + (plci->li_bchannel_id - 1)].plci != plci))
  9981. {
  9982. dbug (1, dprintf ("[%06x] %s,%d: Channel id wiped out",
  9983. UnMapId (Id), (char *)(FILE_), __LINE__));
  9984. return (true);
  9985. }
  9986. i = a->li_base + (plci->li_bchannel_id - 1);
  9987. j = plci->li_write_channel;
  9988. p = plci->internal_req_buffer;
  9989. if (j != 0)
  9990. {
  9991. if ((Rc != OK) && (Rc != OK_FC))
  9992. {
  9993. dbug (1, dprintf ("[%06lx] %s,%d: LI write coefs failed %02x",
  9994. UnMapId (Id), (char *)(FILE_), __LINE__, Rc));
  9995. return (false);
  9996. }
  9997. }
  9998. if (li_config_table[i].adapter->manufacturer_features & MANUFACTURER_FEATURE_XCONNECT)
  9999. {
  10000. r = 0;
  10001. s = 0;
  10002. if (j < li_total_channels)
  10003. {
  10004. if (li_config_table[i].channel & LI_CHANNEL_ADDRESSES_SET)
  10005. {
  10006. s = ((li_config_table[i].send_b.card_address.low | li_config_table[i].send_b.card_address.high) ?
  10007. (LI_COEF_CH_CH | LI_COEF_CH_PC | LI_COEF_PC_CH | LI_COEF_PC_PC) : (LI_COEF_CH_PC | LI_COEF_PC_PC)) &
  10008. ((li_config_table[i].send_pc.card_address.low | li_config_table[i].send_pc.card_address.high) ?
  10009. (LI_COEF_CH_CH | LI_COEF_CH_PC | LI_COEF_PC_CH | LI_COEF_PC_PC) : (LI_COEF_CH_CH | LI_COEF_PC_CH));
  10010. }
  10011. r = ((li_config_table[i].coef_table[j] & 0xf) ^ (li_config_table[i].coef_table[j] >> 4));
  10012. while ((j < li_total_channels)
  10013. && ((r == 0)
  10014. || (!(li_config_table[j].channel & LI_CHANNEL_ADDRESSES_SET))
  10015. || (!li_config_table[j].adapter->li_pri
  10016. && (j >= li_config_table[j].adapter->li_base + MIXER_BCHANNELS_BRI))
  10017. || (((li_config_table[j].send_b.card_address.low != li_config_table[i].send_b.card_address.low)
  10018. || (li_config_table[j].send_b.card_address.high != li_config_table[i].send_b.card_address.high))
  10019. && (!(a->manufacturer_features & MANUFACTURER_FEATURE_DMACONNECT)
  10020. || !(li_config_table[j].adapter->manufacturer_features & MANUFACTURER_FEATURE_DMACONNECT)))
  10021. || ((li_config_table[j].adapter->li_base != a->li_base)
  10022. && !(r & s &
  10023. ((li_config_table[j].send_b.card_address.low | li_config_table[j].send_b.card_address.high) ?
  10024. (LI_COEF_CH_CH | LI_COEF_CH_PC | LI_COEF_PC_CH | LI_COEF_PC_PC) : (LI_COEF_PC_CH | LI_COEF_PC_PC)) &
  10025. ((li_config_table[j].send_pc.card_address.low | li_config_table[j].send_pc.card_address.high) ?
  10026. (LI_COEF_CH_CH | LI_COEF_CH_PC | LI_COEF_PC_CH | LI_COEF_PC_PC) : (LI_COEF_CH_CH | LI_COEF_CH_PC))))))
  10027. {
  10028. j++;
  10029. if (j < li_total_channels)
  10030. r = ((li_config_table[i].coef_table[j] & 0xf) ^ (li_config_table[i].coef_table[j] >> 4));
  10031. }
  10032. }
  10033. if (j < li_total_channels)
  10034. {
  10035. plci->internal_command = plci->li_write_command;
  10036. if (plci_nl_busy (plci))
  10037. return (true);
  10038. to_ch = (a->li_pri) ? plci->li_bchannel_id - 1 : 0;
  10039. *(p++) = UDATA_REQUEST_XCONNECT_TO;
  10040. do
  10041. {
  10042. if (li_config_table[j].adapter->li_base != a->li_base)
  10043. {
  10044. r &= s &
  10045. ((li_config_table[j].send_b.card_address.low | li_config_table[j].send_b.card_address.high) ?
  10046. (LI_COEF_CH_CH | LI_COEF_CH_PC | LI_COEF_PC_CH | LI_COEF_PC_PC) : (LI_COEF_PC_CH | LI_COEF_PC_PC)) &
  10047. ((li_config_table[j].send_pc.card_address.low | li_config_table[j].send_pc.card_address.high) ?
  10048. (LI_COEF_CH_CH | LI_COEF_CH_PC | LI_COEF_PC_CH | LI_COEF_PC_PC) : (LI_COEF_CH_CH | LI_COEF_CH_PC));
  10049. }
  10050. n = 0;
  10051. do
  10052. {
  10053. if (r & xconnect_write_prog[n].mask)
  10054. {
  10055. if (xconnect_write_prog[n].from_pc)
  10056. transfer_address = &(li_config_table[j].send_pc);
  10057. else
  10058. transfer_address = &(li_config_table[j].send_b);
  10059. d = transfer_address->card_address.low;
  10060. *(p++) = (byte) d;
  10061. *(p++) = (byte)(d >> 8);
  10062. *(p++) = (byte)(d >> 16);
  10063. *(p++) = (byte)(d >> 24);
  10064. d = transfer_address->card_address.high;
  10065. *(p++) = (byte) d;
  10066. *(p++) = (byte)(d >> 8);
  10067. *(p++) = (byte)(d >> 16);
  10068. *(p++) = (byte)(d >> 24);
  10069. d = transfer_address->offset;
  10070. *(p++) = (byte) d;
  10071. *(p++) = (byte)(d >> 8);
  10072. *(p++) = (byte)(d >> 16);
  10073. *(p++) = (byte)(d >> 24);
  10074. w = xconnect_write_prog[n].to_pc ? to_ch | XCONNECT_CHANNEL_PORT_PC : to_ch;
  10075. *(p++) = (byte) w;
  10076. *(p++) = (byte)(w >> 8);
  10077. w = ((li_config_table[i].coef_table[j] & xconnect_write_prog[n].mask) == 0) ? 0x01 :
  10078. (li_config_table[i].adapter->u_law ?
  10079. (li_config_table[j].adapter->u_law ? 0x80 : 0x86) :
  10080. (li_config_table[j].adapter->u_law ? 0x7a : 0x80));
  10081. *(p++) = (byte) w;
  10082. *(p++) = (byte) 0;
  10083. li_config_table[i].coef_table[j] ^= xconnect_write_prog[n].mask << 4;
  10084. }
  10085. n++;
  10086. } while ((n < ARRAY_SIZE(xconnect_write_prog))
  10087. && ((p - plci->internal_req_buffer) + 16 < INTERNAL_REQ_BUFFER_SIZE));
  10088. if (n == ARRAY_SIZE(xconnect_write_prog))
  10089. {
  10090. do
  10091. {
  10092. j++;
  10093. if (j < li_total_channels)
  10094. r = ((li_config_table[i].coef_table[j] & 0xf) ^ (li_config_table[i].coef_table[j] >> 4));
  10095. } while ((j < li_total_channels)
  10096. && ((r == 0)
  10097. || (!(li_config_table[j].channel & LI_CHANNEL_ADDRESSES_SET))
  10098. || (!li_config_table[j].adapter->li_pri
  10099. && (j >= li_config_table[j].adapter->li_base + MIXER_BCHANNELS_BRI))
  10100. || (((li_config_table[j].send_b.card_address.low != li_config_table[i].send_b.card_address.low)
  10101. || (li_config_table[j].send_b.card_address.high != li_config_table[i].send_b.card_address.high))
  10102. && (!(a->manufacturer_features & MANUFACTURER_FEATURE_DMACONNECT)
  10103. || !(li_config_table[j].adapter->manufacturer_features & MANUFACTURER_FEATURE_DMACONNECT)))
  10104. || ((li_config_table[j].adapter->li_base != a->li_base)
  10105. && !(r & s &
  10106. ((li_config_table[j].send_b.card_address.low | li_config_table[j].send_b.card_address.high) ?
  10107. (LI_COEF_CH_CH | LI_COEF_CH_PC | LI_COEF_PC_CH | LI_COEF_PC_PC) : (LI_COEF_PC_CH | LI_COEF_PC_PC)) &
  10108. ((li_config_table[j].send_pc.card_address.low | li_config_table[j].send_pc.card_address.high) ?
  10109. (LI_COEF_CH_CH | LI_COEF_CH_PC | LI_COEF_PC_CH | LI_COEF_PC_PC) : (LI_COEF_CH_CH | LI_COEF_CH_PC))))));
  10110. }
  10111. } while ((j < li_total_channels)
  10112. && ((p - plci->internal_req_buffer) + 16 < INTERNAL_REQ_BUFFER_SIZE));
  10113. }
  10114. else if (j == li_total_channels)
  10115. {
  10116. plci->internal_command = plci->li_write_command;
  10117. if (plci_nl_busy (plci))
  10118. return (true);
  10119. if (a->li_pri)
  10120. {
  10121. *(p++) = UDATA_REQUEST_SET_MIXER_COEFS_PRI_SYNC;
  10122. w = 0;
  10123. if (li_config_table[i].channel & LI_CHANNEL_TX_DATA)
  10124. w |= MIXER_FEATURE_ENABLE_TX_DATA;
  10125. if (li_config_table[i].channel & LI_CHANNEL_RX_DATA)
  10126. w |= MIXER_FEATURE_ENABLE_RX_DATA;
  10127. *(p++) = (byte) w;
  10128. *(p++) = (byte)(w >> 8);
  10129. }
  10130. else
  10131. {
  10132. *(p++) = UDATA_REQUEST_SET_MIXER_COEFS_BRI;
  10133. w = 0;
  10134. if ((plci->tel == ADV_VOICE) && (plci == a->AdvSignalPLCI)
  10135. && (ADV_VOICE_NEW_COEF_BASE + sizeof(word) <= a->adv_voice_coef_length))
  10136. {
  10137. w = GET_WORD (a->adv_voice_coef_buffer + ADV_VOICE_NEW_COEF_BASE);
  10138. }
  10139. if (li_config_table[i].channel & LI_CHANNEL_TX_DATA)
  10140. w |= MIXER_FEATURE_ENABLE_TX_DATA;
  10141. if (li_config_table[i].channel & LI_CHANNEL_RX_DATA)
  10142. w |= MIXER_FEATURE_ENABLE_RX_DATA;
  10143. *(p++) = (byte) w;
  10144. *(p++) = (byte)(w >> 8);
  10145. for (j = 0; j < sizeof(ch_map); j += 2)
  10146. {
  10147. if (plci->li_bchannel_id == 2)
  10148. {
  10149. ch_map[j] = (byte)(j+1);
  10150. ch_map[j+1] = (byte) j;
  10151. }
  10152. else
  10153. {
  10154. ch_map[j] = (byte) j;
  10155. ch_map[j+1] = (byte)(j+1);
  10156. }
  10157. }
  10158. for (n = 0; n < ARRAY_SIZE(mixer_write_prog_bri); n++)
  10159. {
  10160. i = a->li_base + ch_map[mixer_write_prog_bri[n].to_ch];
  10161. j = a->li_base + ch_map[mixer_write_prog_bri[n].from_ch];
  10162. if (li_config_table[i].channel & li_config_table[j].channel & LI_CHANNEL_INVOLVED)
  10163. {
  10164. *p = (mixer_write_prog_bri[n].xconnect_override != 0) ?
  10165. mixer_write_prog_bri[n].xconnect_override :
  10166. ((li_config_table[i].coef_table[j] & mixer_write_prog_bri[n].mask) ? 0x80 : 0x01);
  10167. if ((i >= a->li_base + MIXER_BCHANNELS_BRI) || (j >= a->li_base + MIXER_BCHANNELS_BRI))
  10168. {
  10169. w = ((li_config_table[i].coef_table[j] & 0xf) ^ (li_config_table[i].coef_table[j] >> 4));
  10170. li_config_table[i].coef_table[j] ^= (w & mixer_write_prog_bri[n].mask) << 4;
  10171. }
  10172. }
  10173. else
  10174. {
  10175. *p = 0x00;
  10176. if ((a->AdvSignalPLCI != NULL) && (a->AdvSignalPLCI->tel == ADV_VOICE))
  10177. {
  10178. w = (plci == a->AdvSignalPLCI) ? n : mixer_swapped_index_bri[n];
  10179. if (ADV_VOICE_NEW_COEF_BASE + sizeof(word) + w < a->adv_voice_coef_length)
  10180. *p = a->adv_voice_coef_buffer[ADV_VOICE_NEW_COEF_BASE + sizeof(word) + w];
  10181. }
  10182. }
  10183. p++;
  10184. }
  10185. }
  10186. j = li_total_channels + 1;
  10187. }
  10188. }
  10189. else
  10190. {
  10191. if (j <= li_total_channels)
  10192. {
  10193. plci->internal_command = plci->li_write_command;
  10194. if (plci_nl_busy (plci))
  10195. return (true);
  10196. if (j < a->li_base)
  10197. j = a->li_base;
  10198. if (a->li_pri)
  10199. {
  10200. *(p++) = UDATA_REQUEST_SET_MIXER_COEFS_PRI_SYNC;
  10201. w = 0;
  10202. if (li_config_table[i].channel & LI_CHANNEL_TX_DATA)
  10203. w |= MIXER_FEATURE_ENABLE_TX_DATA;
  10204. if (li_config_table[i].channel & LI_CHANNEL_RX_DATA)
  10205. w |= MIXER_FEATURE_ENABLE_RX_DATA;
  10206. *(p++) = (byte) w;
  10207. *(p++) = (byte)(w >> 8);
  10208. for (n = 0; n < ARRAY_SIZE(mixer_write_prog_pri); n++)
  10209. {
  10210. *(p++) = (byte)((plci->li_bchannel_id - 1) | mixer_write_prog_pri[n].line_flags);
  10211. for (j = a->li_base; j < a->li_base + MIXER_CHANNELS_PRI; j++)
  10212. {
  10213. w = ((li_config_table[i].coef_table[j] & 0xf) ^ (li_config_table[i].coef_table[j] >> 4));
  10214. if (w & mixer_write_prog_pri[n].mask)
  10215. {
  10216. *(p++) = (li_config_table[i].coef_table[j] & mixer_write_prog_pri[n].mask) ? 0x80 : 0x01;
  10217. li_config_table[i].coef_table[j] ^= mixer_write_prog_pri[n].mask << 4;
  10218. }
  10219. else
  10220. *(p++) = 0x00;
  10221. }
  10222. *(p++) = (byte)((plci->li_bchannel_id - 1) | MIXER_COEF_LINE_ROW_FLAG | mixer_write_prog_pri[n].line_flags);
  10223. for (j = a->li_base; j < a->li_base + MIXER_CHANNELS_PRI; j++)
  10224. {
  10225. w = ((li_config_table[j].coef_table[i] & 0xf) ^ (li_config_table[j].coef_table[i] >> 4));
  10226. if (w & mixer_write_prog_pri[n].mask)
  10227. {
  10228. *(p++) = (li_config_table[j].coef_table[i] & mixer_write_prog_pri[n].mask) ? 0x80 : 0x01;
  10229. li_config_table[j].coef_table[i] ^= mixer_write_prog_pri[n].mask << 4;
  10230. }
  10231. else
  10232. *(p++) = 0x00;
  10233. }
  10234. }
  10235. }
  10236. else
  10237. {
  10238. *(p++) = UDATA_REQUEST_SET_MIXER_COEFS_BRI;
  10239. w = 0;
  10240. if ((plci->tel == ADV_VOICE) && (plci == a->AdvSignalPLCI)
  10241. && (ADV_VOICE_NEW_COEF_BASE + sizeof(word) <= a->adv_voice_coef_length))
  10242. {
  10243. w = GET_WORD (a->adv_voice_coef_buffer + ADV_VOICE_NEW_COEF_BASE);
  10244. }
  10245. if (li_config_table[i].channel & LI_CHANNEL_TX_DATA)
  10246. w |= MIXER_FEATURE_ENABLE_TX_DATA;
  10247. if (li_config_table[i].channel & LI_CHANNEL_RX_DATA)
  10248. w |= MIXER_FEATURE_ENABLE_RX_DATA;
  10249. *(p++) = (byte) w;
  10250. *(p++) = (byte)(w >> 8);
  10251. for (j = 0; j < sizeof(ch_map); j += 2)
  10252. {
  10253. if (plci->li_bchannel_id == 2)
  10254. {
  10255. ch_map[j] = (byte)(j+1);
  10256. ch_map[j+1] = (byte) j;
  10257. }
  10258. else
  10259. {
  10260. ch_map[j] = (byte) j;
  10261. ch_map[j+1] = (byte)(j+1);
  10262. }
  10263. }
  10264. for (n = 0; n < ARRAY_SIZE(mixer_write_prog_bri); n++)
  10265. {
  10266. i = a->li_base + ch_map[mixer_write_prog_bri[n].to_ch];
  10267. j = a->li_base + ch_map[mixer_write_prog_bri[n].from_ch];
  10268. if (li_config_table[i].channel & li_config_table[j].channel & LI_CHANNEL_INVOLVED)
  10269. {
  10270. *p = ((li_config_table[i].coef_table[j] & mixer_write_prog_bri[n].mask) ? 0x80 : 0x01);
  10271. w = ((li_config_table[i].coef_table[j] & 0xf) ^ (li_config_table[i].coef_table[j] >> 4));
  10272. li_config_table[i].coef_table[j] ^= (w & mixer_write_prog_bri[n].mask) << 4;
  10273. }
  10274. else
  10275. {
  10276. *p = 0x00;
  10277. if ((a->AdvSignalPLCI != NULL) && (a->AdvSignalPLCI->tel == ADV_VOICE))
  10278. {
  10279. w = (plci == a->AdvSignalPLCI) ? n : mixer_swapped_index_bri[n];
  10280. if (ADV_VOICE_NEW_COEF_BASE + sizeof(word) + w < a->adv_voice_coef_length)
  10281. *p = a->adv_voice_coef_buffer[ADV_VOICE_NEW_COEF_BASE + sizeof(word) + w];
  10282. }
  10283. }
  10284. p++;
  10285. }
  10286. }
  10287. j = li_total_channels + 1;
  10288. }
  10289. }
  10290. plci->li_write_channel = j;
  10291. if (p != plci->internal_req_buffer)
  10292. {
  10293. plci->NData[0].P = plci->internal_req_buffer;
  10294. plci->NData[0].PLength = p - plci->internal_req_buffer;
  10295. plci->NL.X = plci->NData;
  10296. plci->NL.ReqCh = 0;
  10297. plci->NL.Req = plci->nl_req = (byte) N_UDATA;
  10298. plci->adapter->request (&plci->NL);
  10299. }
  10300. return (true);
  10301. }
  10302. static void mixer_notify_update (PLCI *plci, byte others)
  10303. {
  10304. DIVA_CAPI_ADAPTER *a;
  10305. word i, w;
  10306. PLCI *notify_plci;
  10307. byte msg[sizeof(CAPI_MSG_HEADER) + 6];
  10308. dbug (1, dprintf ("[%06lx] %s,%d: mixer_notify_update %d",
  10309. (dword)((plci->Id << 8) | UnMapController (plci->adapter->Id)),
  10310. (char *)(FILE_), __LINE__, others));
  10311. a = plci->adapter;
  10312. if (a->profile.Global_Options & GL_LINE_INTERCONNECT_SUPPORTED)
  10313. {
  10314. if (others)
  10315. plci->li_notify_update = true;
  10316. i = 0;
  10317. do
  10318. {
  10319. notify_plci = NULL;
  10320. if (others)
  10321. {
  10322. while ((i < li_total_channels) && (li_config_table[i].plci == NULL))
  10323. i++;
  10324. if (i < li_total_channels)
  10325. notify_plci = li_config_table[i++].plci;
  10326. }
  10327. else
  10328. {
  10329. if ((plci->li_bchannel_id != 0)
  10330. && (li_config_table[a->li_base + (plci->li_bchannel_id - 1)].plci == plci))
  10331. {
  10332. notify_plci = plci;
  10333. }
  10334. }
  10335. if ((notify_plci != NULL)
  10336. && !notify_plci->li_notify_update
  10337. && (notify_plci->appl != NULL)
  10338. && (notify_plci->State)
  10339. && notify_plci->NL.Id && !notify_plci->nl_remove_id)
  10340. {
  10341. notify_plci->li_notify_update = true;
  10342. ((CAPI_MSG *) msg)->header.length = 18;
  10343. ((CAPI_MSG *) msg)->header.appl_id = notify_plci->appl->Id;
  10344. ((CAPI_MSG *) msg)->header.command = _FACILITY_R;
  10345. ((CAPI_MSG *) msg)->header.number = 0;
  10346. ((CAPI_MSG *) msg)->header.controller = notify_plci->adapter->Id;
  10347. ((CAPI_MSG *) msg)->header.plci = notify_plci->Id;
  10348. ((CAPI_MSG *) msg)->header.ncci = 0;
  10349. ((CAPI_MSG *) msg)->info.facility_req.Selector = SELECTOR_LINE_INTERCONNECT;
  10350. ((CAPI_MSG *) msg)->info.facility_req.structs[0] = 3;
  10351. PUT_WORD (&(((CAPI_MSG *) msg)->info.facility_req.structs[1]), LI_REQ_SILENT_UPDATE);
  10352. ((CAPI_MSG *) msg)->info.facility_req.structs[3] = 0;
  10353. w = api_put (notify_plci->appl, (CAPI_MSG *) msg);
  10354. if (w != _QUEUE_FULL)
  10355. {
  10356. if (w != 0)
  10357. {
  10358. dbug (1, dprintf ("[%06lx] %s,%d: Interconnect notify failed %06x %d",
  10359. (dword)((plci->Id << 8) | UnMapController (plci->adapter->Id)),
  10360. (char *)(FILE_), __LINE__,
  10361. (dword)((notify_plci->Id << 8) | UnMapController (notify_plci->adapter->Id)), w));
  10362. }
  10363. notify_plci->li_notify_update = false;
  10364. }
  10365. }
  10366. } while (others && (notify_plci != NULL));
  10367. if (others)
  10368. plci->li_notify_update = false;
  10369. }
  10370. }
  10371. static void mixer_clear_config (PLCI *plci)
  10372. {
  10373. DIVA_CAPI_ADAPTER *a;
  10374. word i, j;
  10375. dbug (1, dprintf ("[%06lx] %s,%d: mixer_clear_config",
  10376. (dword)((plci->Id << 8) | UnMapController (plci->adapter->Id)),
  10377. (char *)(FILE_), __LINE__));
  10378. plci->li_notify_update = false;
  10379. plci->li_plci_b_write_pos = 0;
  10380. plci->li_plci_b_read_pos = 0;
  10381. plci->li_plci_b_req_pos = 0;
  10382. a = plci->adapter;
  10383. if ((plci->li_bchannel_id != 0)
  10384. && (li_config_table[a->li_base + (plci->li_bchannel_id - 1)].plci == plci))
  10385. {
  10386. i = a->li_base + (plci->li_bchannel_id - 1);
  10387. li_config_table[i].curchnl = 0;
  10388. li_config_table[i].channel = 0;
  10389. li_config_table[i].chflags = 0;
  10390. for (j = 0; j < li_total_channels; j++)
  10391. {
  10392. li_config_table[j].flag_table[i] = 0;
  10393. li_config_table[i].flag_table[j] = 0;
  10394. li_config_table[i].coef_table[j] = 0;
  10395. li_config_table[j].coef_table[i] = 0;
  10396. }
  10397. if (!a->li_pri)
  10398. {
  10399. li_config_table[i].coef_table[i] |= LI_COEF_CH_PC_SET | LI_COEF_PC_CH_SET;
  10400. if ((plci->tel == ADV_VOICE) && (plci == a->AdvSignalPLCI))
  10401. {
  10402. i = a->li_base + MIXER_IC_CHANNEL_BASE + (plci->li_bchannel_id - 1);
  10403. li_config_table[i].curchnl = 0;
  10404. li_config_table[i].channel = 0;
  10405. li_config_table[i].chflags = 0;
  10406. for (j = 0; j < li_total_channels; j++)
  10407. {
  10408. li_config_table[i].flag_table[j] = 0;
  10409. li_config_table[j].flag_table[i] = 0;
  10410. li_config_table[i].coef_table[j] = 0;
  10411. li_config_table[j].coef_table[i] = 0;
  10412. }
  10413. if (a->manufacturer_features & MANUFACTURER_FEATURE_SLAVE_CODEC)
  10414. {
  10415. i = a->li_base + MIXER_IC_CHANNEL_BASE + (2 - plci->li_bchannel_id);
  10416. li_config_table[i].curchnl = 0;
  10417. li_config_table[i].channel = 0;
  10418. li_config_table[i].chflags = 0;
  10419. for (j = 0; j < li_total_channels; j++)
  10420. {
  10421. li_config_table[i].flag_table[j] = 0;
  10422. li_config_table[j].flag_table[i] = 0;
  10423. li_config_table[i].coef_table[j] = 0;
  10424. li_config_table[j].coef_table[i] = 0;
  10425. }
  10426. }
  10427. }
  10428. }
  10429. }
  10430. }
  10431. static void mixer_prepare_switch (dword Id, PLCI *plci)
  10432. {
  10433. dbug (1, dprintf ("[%06lx] %s,%d: mixer_prepare_switch",
  10434. UnMapId (Id), (char *)(FILE_), __LINE__));
  10435. do
  10436. {
  10437. mixer_indication_coefs_set (Id, plci);
  10438. } while (plci->li_plci_b_read_pos != plci->li_plci_b_req_pos);
  10439. }
  10440. static word mixer_save_config (dword Id, PLCI *plci, byte Rc)
  10441. {
  10442. DIVA_CAPI_ADAPTER *a;
  10443. word i, j;
  10444. dbug (1, dprintf ("[%06lx] %s,%d: mixer_save_config %02x %d",
  10445. UnMapId (Id), (char *)(FILE_), __LINE__, Rc, plci->adjust_b_state));
  10446. a = plci->adapter;
  10447. if ((plci->li_bchannel_id != 0)
  10448. && (li_config_table[a->li_base + (plci->li_bchannel_id - 1)].plci == plci))
  10449. {
  10450. i = a->li_base + (plci->li_bchannel_id - 1);
  10451. for (j = 0; j < li_total_channels; j++)
  10452. {
  10453. li_config_table[i].coef_table[j] &= 0xf;
  10454. li_config_table[j].coef_table[i] &= 0xf;
  10455. }
  10456. if (!a->li_pri)
  10457. li_config_table[i].coef_table[i] |= LI_COEF_CH_PC_SET | LI_COEF_PC_CH_SET;
  10458. }
  10459. return (GOOD);
  10460. }
  10461. static word mixer_restore_config (dword Id, PLCI *plci, byte Rc)
  10462. {
  10463. DIVA_CAPI_ADAPTER *a;
  10464. word Info;
  10465. dbug (1, dprintf ("[%06lx] %s,%d: mixer_restore_config %02x %d",
  10466. UnMapId (Id), (char *)(FILE_), __LINE__, Rc, plci->adjust_b_state));
  10467. Info = GOOD;
  10468. a = plci->adapter;
  10469. if ((plci->B1_facilities & B1_FACILITY_MIXER)
  10470. && (plci->li_bchannel_id != 0)
  10471. && (li_config_table[a->li_base + (plci->li_bchannel_id - 1)].plci == plci))
  10472. {
  10473. switch (plci->adjust_b_state)
  10474. {
  10475. case ADJUST_B_RESTORE_MIXER_1:
  10476. if (a->manufacturer_features & MANUFACTURER_FEATURE_XCONNECT)
  10477. {
  10478. plci->internal_command = plci->adjust_b_command;
  10479. if (plci_nl_busy (plci))
  10480. {
  10481. plci->adjust_b_state = ADJUST_B_RESTORE_MIXER_1;
  10482. break;
  10483. }
  10484. xconnect_query_addresses (plci);
  10485. plci->adjust_b_state = ADJUST_B_RESTORE_MIXER_2;
  10486. break;
  10487. }
  10488. plci->adjust_b_state = ADJUST_B_RESTORE_MIXER_5;
  10489. Rc = OK;
  10490. case ADJUST_B_RESTORE_MIXER_2:
  10491. case ADJUST_B_RESTORE_MIXER_3:
  10492. case ADJUST_B_RESTORE_MIXER_4:
  10493. if ((Rc != OK) && (Rc != OK_FC) && (Rc != 0))
  10494. {
  10495. dbug (1, dprintf ("[%06lx] %s,%d: Adjust B query addresses failed %02x",
  10496. UnMapId (Id), (char *)(FILE_), __LINE__, Rc));
  10497. Info = _WRONG_STATE;
  10498. break;
  10499. }
  10500. if (Rc == OK)
  10501. {
  10502. if (plci->adjust_b_state == ADJUST_B_RESTORE_MIXER_2)
  10503. plci->adjust_b_state = ADJUST_B_RESTORE_MIXER_3;
  10504. else if (plci->adjust_b_state == ADJUST_B_RESTORE_MIXER_4)
  10505. plci->adjust_b_state = ADJUST_B_RESTORE_MIXER_5;
  10506. }
  10507. else if (Rc == 0)
  10508. {
  10509. if (plci->adjust_b_state == ADJUST_B_RESTORE_MIXER_2)
  10510. plci->adjust_b_state = ADJUST_B_RESTORE_MIXER_4;
  10511. else if (plci->adjust_b_state == ADJUST_B_RESTORE_MIXER_3)
  10512. plci->adjust_b_state = ADJUST_B_RESTORE_MIXER_5;
  10513. }
  10514. if (plci->adjust_b_state != ADJUST_B_RESTORE_MIXER_5)
  10515. {
  10516. plci->internal_command = plci->adjust_b_command;
  10517. break;
  10518. }
  10519. case ADJUST_B_RESTORE_MIXER_5:
  10520. xconnect_write_coefs (plci, plci->adjust_b_command);
  10521. plci->adjust_b_state = ADJUST_B_RESTORE_MIXER_6;
  10522. Rc = OK;
  10523. case ADJUST_B_RESTORE_MIXER_6:
  10524. if (!xconnect_write_coefs_process (Id, plci, Rc))
  10525. {
  10526. dbug (1, dprintf ("[%06lx] %s,%d: Write mixer coefs failed",
  10527. UnMapId (Id), (char *)(FILE_), __LINE__));
  10528. Info = _FACILITY_NOT_SUPPORTED;
  10529. break;
  10530. }
  10531. if (plci->internal_command)
  10532. break;
  10533. plci->adjust_b_state = ADJUST_B_RESTORE_MIXER_7;
  10534. case ADJUST_B_RESTORE_MIXER_7:
  10535. break;
  10536. }
  10537. }
  10538. return (Info);
  10539. }
  10540. static void mixer_command (dword Id, PLCI *plci, byte Rc)
  10541. {
  10542. DIVA_CAPI_ADAPTER *a;
  10543. word i, internal_command, Info;
  10544. dbug (1, dprintf ("[%06lx] %s,%d: mixer_command %02x %04x %04x",
  10545. UnMapId (Id), (char *)(FILE_), __LINE__, Rc, plci->internal_command,
  10546. plci->li_cmd));
  10547. Info = GOOD;
  10548. a = plci->adapter;
  10549. internal_command = plci->internal_command;
  10550. plci->internal_command = 0;
  10551. switch (plci->li_cmd)
  10552. {
  10553. case LI_REQ_CONNECT:
  10554. case LI_REQ_DISCONNECT:
  10555. case LI_REQ_SILENT_UPDATE:
  10556. switch (internal_command)
  10557. {
  10558. default:
  10559. if (plci->li_channel_bits & LI_CHANNEL_INVOLVED)
  10560. {
  10561. adjust_b1_resource (Id, plci, NULL, (word)(plci->B1_facilities |
  10562. B1_FACILITY_MIXER), MIXER_COMMAND_1);
  10563. }
  10564. case MIXER_COMMAND_1:
  10565. if (plci->li_channel_bits & LI_CHANNEL_INVOLVED)
  10566. {
  10567. if (adjust_b_process (Id, plci, Rc) != GOOD)
  10568. {
  10569. dbug (1, dprintf ("[%06lx] %s,%d: Load mixer failed",
  10570. UnMapId (Id), (char *)(FILE_), __LINE__));
  10571. Info = _FACILITY_NOT_SUPPORTED;
  10572. break;
  10573. }
  10574. if (plci->internal_command)
  10575. return;
  10576. }
  10577. plci->li_plci_b_req_pos = plci->li_plci_b_write_pos;
  10578. if ((plci->li_channel_bits & LI_CHANNEL_INVOLVED)
  10579. || ((get_b1_facilities (plci, plci->B1_resource) & B1_FACILITY_MIXER)
  10580. && (add_b1_facilities (plci, plci->B1_resource, (word)(plci->B1_facilities &
  10581. ~B1_FACILITY_MIXER)) == plci->B1_resource)))
  10582. {
  10583. xconnect_write_coefs (plci, MIXER_COMMAND_2);
  10584. }
  10585. else
  10586. {
  10587. do
  10588. {
  10589. mixer_indication_coefs_set (Id, plci);
  10590. } while (plci->li_plci_b_read_pos != plci->li_plci_b_req_pos);
  10591. }
  10592. case MIXER_COMMAND_2:
  10593. if ((plci->li_channel_bits & LI_CHANNEL_INVOLVED)
  10594. || ((get_b1_facilities (plci, plci->B1_resource) & B1_FACILITY_MIXER)
  10595. && (add_b1_facilities (plci, plci->B1_resource, (word)(plci->B1_facilities &
  10596. ~B1_FACILITY_MIXER)) == plci->B1_resource)))
  10597. {
  10598. if (!xconnect_write_coefs_process (Id, plci, Rc))
  10599. {
  10600. dbug (1, dprintf ("[%06lx] %s,%d: Write mixer coefs failed",
  10601. UnMapId (Id), (char *)(FILE_), __LINE__));
  10602. if (plci->li_plci_b_write_pos != plci->li_plci_b_req_pos)
  10603. {
  10604. do
  10605. {
  10606. plci->li_plci_b_write_pos = (plci->li_plci_b_write_pos == 0) ?
  10607. LI_PLCI_B_QUEUE_ENTRIES-1 : plci->li_plci_b_write_pos - 1;
  10608. i = (plci->li_plci_b_write_pos == 0) ?
  10609. LI_PLCI_B_QUEUE_ENTRIES-1 : plci->li_plci_b_write_pos - 1;
  10610. } while ((plci->li_plci_b_write_pos != plci->li_plci_b_req_pos)
  10611. && !(plci->li_plci_b_queue[i] & LI_PLCI_B_LAST_FLAG));
  10612. }
  10613. Info = _FACILITY_NOT_SUPPORTED;
  10614. break;
  10615. }
  10616. if (plci->internal_command)
  10617. return;
  10618. }
  10619. if (!(plci->li_channel_bits & LI_CHANNEL_INVOLVED))
  10620. {
  10621. adjust_b1_resource (Id, plci, NULL, (word)(plci->B1_facilities &
  10622. ~B1_FACILITY_MIXER), MIXER_COMMAND_3);
  10623. }
  10624. case MIXER_COMMAND_3:
  10625. if (!(plci->li_channel_bits & LI_CHANNEL_INVOLVED))
  10626. {
  10627. if (adjust_b_process (Id, plci, Rc) != GOOD)
  10628. {
  10629. dbug (1, dprintf ("[%06lx] %s,%d: Unload mixer failed",
  10630. UnMapId (Id), (char *)(FILE_), __LINE__));
  10631. Info = _FACILITY_NOT_SUPPORTED;
  10632. break;
  10633. }
  10634. if (plci->internal_command)
  10635. return;
  10636. }
  10637. break;
  10638. }
  10639. break;
  10640. }
  10641. if ((plci->li_bchannel_id == 0)
  10642. || (li_config_table[a->li_base + (plci->li_bchannel_id - 1)].plci != plci))
  10643. {
  10644. dbug (1, dprintf ("[%06x] %s,%d: Channel id wiped out %d",
  10645. UnMapId (Id), (char *)(FILE_), __LINE__, (int)(plci->li_bchannel_id)));
  10646. }
  10647. else
  10648. {
  10649. i = a->li_base + (plci->li_bchannel_id - 1);
  10650. li_config_table[i].curchnl = plci->li_channel_bits;
  10651. if (!a->li_pri && (plci->tel == ADV_VOICE) && (plci == a->AdvSignalPLCI))
  10652. {
  10653. i = a->li_base + MIXER_IC_CHANNEL_BASE + (plci->li_bchannel_id - 1);
  10654. li_config_table[i].curchnl = plci->li_channel_bits;
  10655. if (a->manufacturer_features & MANUFACTURER_FEATURE_SLAVE_CODEC)
  10656. {
  10657. i = a->li_base + MIXER_IC_CHANNEL_BASE + (2 - plci->li_bchannel_id);
  10658. li_config_table[i].curchnl = plci->li_channel_bits;
  10659. }
  10660. }
  10661. }
  10662. }
  10663. static void li_update_connect (dword Id, DIVA_CAPI_ADAPTER *a, PLCI *plci,
  10664. dword plci_b_id, byte connect, dword li_flags)
  10665. {
  10666. word i, ch_a, ch_a_v, ch_a_s, ch_b, ch_b_v, ch_b_s;
  10667. PLCI *plci_b;
  10668. DIVA_CAPI_ADAPTER *a_b;
  10669. a_b = &(adapter[MapController ((byte)(plci_b_id & 0x7f)) - 1]);
  10670. plci_b = &(a_b->plci[((plci_b_id >> 8) & 0xff) - 1]);
  10671. ch_a = a->li_base + (plci->li_bchannel_id - 1);
  10672. if (!a->li_pri && (plci->tel == ADV_VOICE)
  10673. && (plci == a->AdvSignalPLCI) && (Id & EXT_CONTROLLER))
  10674. {
  10675. ch_a_v = ch_a + MIXER_IC_CHANNEL_BASE;
  10676. ch_a_s = (a->manufacturer_features & MANUFACTURER_FEATURE_SLAVE_CODEC) ?
  10677. a->li_base + MIXER_IC_CHANNEL_BASE + (2 - plci->li_bchannel_id) : ch_a_v;
  10678. }
  10679. else
  10680. {
  10681. ch_a_v = ch_a;
  10682. ch_a_s = ch_a;
  10683. }
  10684. ch_b = a_b->li_base + (plci_b->li_bchannel_id - 1);
  10685. if (!a_b->li_pri && (plci_b->tel == ADV_VOICE)
  10686. && (plci_b == a_b->AdvSignalPLCI) && (plci_b_id & EXT_CONTROLLER))
  10687. {
  10688. ch_b_v = ch_b + MIXER_IC_CHANNEL_BASE;
  10689. ch_b_s = (a_b->manufacturer_features & MANUFACTURER_FEATURE_SLAVE_CODEC) ?
  10690. a_b->li_base + MIXER_IC_CHANNEL_BASE + (2 - plci_b->li_bchannel_id) : ch_b_v;
  10691. }
  10692. else
  10693. {
  10694. ch_b_v = ch_b;
  10695. ch_b_s = ch_b;
  10696. }
  10697. if (connect)
  10698. {
  10699. li_config_table[ch_a].flag_table[ch_a_v] &= ~LI_FLAG_MONITOR;
  10700. li_config_table[ch_a].flag_table[ch_a_s] &= ~LI_FLAG_MONITOR;
  10701. li_config_table[ch_a_v].flag_table[ch_a] &= ~(LI_FLAG_ANNOUNCEMENT | LI_FLAG_MIX);
  10702. li_config_table[ch_a_s].flag_table[ch_a] &= ~(LI_FLAG_ANNOUNCEMENT | LI_FLAG_MIX);
  10703. }
  10704. li_config_table[ch_a].flag_table[ch_b_v] &= ~LI_FLAG_MONITOR;
  10705. li_config_table[ch_a].flag_table[ch_b_s] &= ~LI_FLAG_MONITOR;
  10706. li_config_table[ch_b_v].flag_table[ch_a] &= ~(LI_FLAG_ANNOUNCEMENT | LI_FLAG_MIX);
  10707. li_config_table[ch_b_s].flag_table[ch_a] &= ~(LI_FLAG_ANNOUNCEMENT | LI_FLAG_MIX);
  10708. if (ch_a_v == ch_b_v)
  10709. {
  10710. li_config_table[ch_a_v].flag_table[ch_b_v] &= ~LI_FLAG_CONFERENCE;
  10711. li_config_table[ch_a_s].flag_table[ch_b_s] &= ~LI_FLAG_CONFERENCE;
  10712. }
  10713. else
  10714. {
  10715. if (li_config_table[ch_a_v].flag_table[ch_b_v] & LI_FLAG_CONFERENCE)
  10716. {
  10717. for (i = 0; i < li_total_channels; i++)
  10718. {
  10719. if (i != ch_a_v)
  10720. li_config_table[ch_a_v].flag_table[i] &= ~LI_FLAG_CONFERENCE;
  10721. }
  10722. }
  10723. if (li_config_table[ch_a_s].flag_table[ch_b_v] & LI_FLAG_CONFERENCE)
  10724. {
  10725. for (i = 0; i < li_total_channels; i++)
  10726. {
  10727. if (i != ch_a_s)
  10728. li_config_table[ch_a_s].flag_table[i] &= ~LI_FLAG_CONFERENCE;
  10729. }
  10730. }
  10731. if (li_config_table[ch_b_v].flag_table[ch_a_v] & LI_FLAG_CONFERENCE)
  10732. {
  10733. for (i = 0; i < li_total_channels; i++)
  10734. {
  10735. if (i != ch_a_v)
  10736. li_config_table[i].flag_table[ch_a_v] &= ~LI_FLAG_CONFERENCE;
  10737. }
  10738. }
  10739. if (li_config_table[ch_b_v].flag_table[ch_a_s] & LI_FLAG_CONFERENCE)
  10740. {
  10741. for (i = 0; i < li_total_channels; i++)
  10742. {
  10743. if (i != ch_a_s)
  10744. li_config_table[i].flag_table[ch_a_s] &= ~LI_FLAG_CONFERENCE;
  10745. }
  10746. }
  10747. }
  10748. if (li_flags & LI_FLAG_CONFERENCE_A_B)
  10749. {
  10750. li_config_table[ch_b_v].flag_table[ch_a_v] |= LI_FLAG_CONFERENCE;
  10751. li_config_table[ch_b_s].flag_table[ch_a_v] |= LI_FLAG_CONFERENCE;
  10752. li_config_table[ch_b_v].flag_table[ch_a_s] |= LI_FLAG_CONFERENCE;
  10753. li_config_table[ch_b_s].flag_table[ch_a_s] |= LI_FLAG_CONFERENCE;
  10754. }
  10755. if (li_flags & LI_FLAG_CONFERENCE_B_A)
  10756. {
  10757. li_config_table[ch_a_v].flag_table[ch_b_v] |= LI_FLAG_CONFERENCE;
  10758. li_config_table[ch_a_v].flag_table[ch_b_s] |= LI_FLAG_CONFERENCE;
  10759. li_config_table[ch_a_s].flag_table[ch_b_v] |= LI_FLAG_CONFERENCE;
  10760. li_config_table[ch_a_s].flag_table[ch_b_s] |= LI_FLAG_CONFERENCE;
  10761. }
  10762. if (li_flags & LI_FLAG_MONITOR_A)
  10763. {
  10764. li_config_table[ch_a].flag_table[ch_a_v] |= LI_FLAG_MONITOR;
  10765. li_config_table[ch_a].flag_table[ch_a_s] |= LI_FLAG_MONITOR;
  10766. }
  10767. if (li_flags & LI_FLAG_MONITOR_B)
  10768. {
  10769. li_config_table[ch_a].flag_table[ch_b_v] |= LI_FLAG_MONITOR;
  10770. li_config_table[ch_a].flag_table[ch_b_s] |= LI_FLAG_MONITOR;
  10771. }
  10772. if (li_flags & LI_FLAG_ANNOUNCEMENT_A)
  10773. {
  10774. li_config_table[ch_a_v].flag_table[ch_a] |= LI_FLAG_ANNOUNCEMENT;
  10775. li_config_table[ch_a_s].flag_table[ch_a] |= LI_FLAG_ANNOUNCEMENT;
  10776. }
  10777. if (li_flags & LI_FLAG_ANNOUNCEMENT_B)
  10778. {
  10779. li_config_table[ch_b_v].flag_table[ch_a] |= LI_FLAG_ANNOUNCEMENT;
  10780. li_config_table[ch_b_s].flag_table[ch_a] |= LI_FLAG_ANNOUNCEMENT;
  10781. }
  10782. if (li_flags & LI_FLAG_MIX_A)
  10783. {
  10784. li_config_table[ch_a_v].flag_table[ch_a] |= LI_FLAG_MIX;
  10785. li_config_table[ch_a_s].flag_table[ch_a] |= LI_FLAG_MIX;
  10786. }
  10787. if (li_flags & LI_FLAG_MIX_B)
  10788. {
  10789. li_config_table[ch_b_v].flag_table[ch_a] |= LI_FLAG_MIX;
  10790. li_config_table[ch_b_s].flag_table[ch_a] |= LI_FLAG_MIX;
  10791. }
  10792. if (ch_a_v != ch_a_s)
  10793. {
  10794. li_config_table[ch_a_v].flag_table[ch_a_s] |= LI_FLAG_CONFERENCE;
  10795. li_config_table[ch_a_s].flag_table[ch_a_v] |= LI_FLAG_CONFERENCE;
  10796. }
  10797. if (ch_b_v != ch_b_s)
  10798. {
  10799. li_config_table[ch_b_v].flag_table[ch_b_s] |= LI_FLAG_CONFERENCE;
  10800. li_config_table[ch_b_s].flag_table[ch_b_v] |= LI_FLAG_CONFERENCE;
  10801. }
  10802. }
  10803. static void li2_update_connect (dword Id, DIVA_CAPI_ADAPTER *a, PLCI *plci,
  10804. dword plci_b_id, byte connect, dword li_flags)
  10805. {
  10806. word ch_a, ch_a_v, ch_a_s, ch_b, ch_b_v, ch_b_s;
  10807. PLCI *plci_b;
  10808. DIVA_CAPI_ADAPTER *a_b;
  10809. a_b = &(adapter[MapController ((byte)(plci_b_id & 0x7f)) - 1]);
  10810. plci_b = &(a_b->plci[((plci_b_id >> 8) & 0xff) - 1]);
  10811. ch_a = a->li_base + (plci->li_bchannel_id - 1);
  10812. if (!a->li_pri && (plci->tel == ADV_VOICE)
  10813. && (plci == a->AdvSignalPLCI) && (Id & EXT_CONTROLLER))
  10814. {
  10815. ch_a_v = ch_a + MIXER_IC_CHANNEL_BASE;
  10816. ch_a_s = (a->manufacturer_features & MANUFACTURER_FEATURE_SLAVE_CODEC) ?
  10817. a->li_base + MIXER_IC_CHANNEL_BASE + (2 - plci->li_bchannel_id) : ch_a_v;
  10818. }
  10819. else
  10820. {
  10821. ch_a_v = ch_a;
  10822. ch_a_s = ch_a;
  10823. }
  10824. ch_b = a_b->li_base + (plci_b->li_bchannel_id - 1);
  10825. if (!a_b->li_pri && (plci_b->tel == ADV_VOICE)
  10826. && (plci_b == a_b->AdvSignalPLCI) && (plci_b_id & EXT_CONTROLLER))
  10827. {
  10828. ch_b_v = ch_b + MIXER_IC_CHANNEL_BASE;
  10829. ch_b_s = (a_b->manufacturer_features & MANUFACTURER_FEATURE_SLAVE_CODEC) ?
  10830. a_b->li_base + MIXER_IC_CHANNEL_BASE + (2 - plci_b->li_bchannel_id) : ch_b_v;
  10831. }
  10832. else
  10833. {
  10834. ch_b_v = ch_b;
  10835. ch_b_s = ch_b;
  10836. }
  10837. if (connect)
  10838. {
  10839. li_config_table[ch_b].flag_table[ch_b_v] &= ~LI_FLAG_MONITOR;
  10840. li_config_table[ch_b].flag_table[ch_b_s] &= ~LI_FLAG_MONITOR;
  10841. li_config_table[ch_b_v].flag_table[ch_b] &= ~LI_FLAG_MIX;
  10842. li_config_table[ch_b_s].flag_table[ch_b] &= ~LI_FLAG_MIX;
  10843. li_config_table[ch_b].flag_table[ch_b] &= ~LI_FLAG_PCCONNECT;
  10844. li_config_table[ch_b].chflags &= ~(LI_CHFLAG_MONITOR | LI_CHFLAG_MIX | LI_CHFLAG_LOOP);
  10845. }
  10846. li_config_table[ch_b_v].flag_table[ch_a_v] &= ~(LI_FLAG_INTERCONNECT | LI_FLAG_CONFERENCE);
  10847. li_config_table[ch_b_s].flag_table[ch_a_v] &= ~(LI_FLAG_INTERCONNECT | LI_FLAG_CONFERENCE);
  10848. li_config_table[ch_b_v].flag_table[ch_a_s] &= ~(LI_FLAG_INTERCONNECT | LI_FLAG_CONFERENCE);
  10849. li_config_table[ch_b_s].flag_table[ch_a_s] &= ~(LI_FLAG_INTERCONNECT | LI_FLAG_CONFERENCE);
  10850. li_config_table[ch_a_v].flag_table[ch_b_v] &= ~(LI_FLAG_INTERCONNECT | LI_FLAG_CONFERENCE);
  10851. li_config_table[ch_a_v].flag_table[ch_b_s] &= ~(LI_FLAG_INTERCONNECT | LI_FLAG_CONFERENCE);
  10852. li_config_table[ch_a_s].flag_table[ch_b_v] &= ~(LI_FLAG_INTERCONNECT | LI_FLAG_CONFERENCE);
  10853. li_config_table[ch_a_s].flag_table[ch_b_s] &= ~(LI_FLAG_INTERCONNECT | LI_FLAG_CONFERENCE);
  10854. if (li_flags & LI2_FLAG_INTERCONNECT_A_B)
  10855. {
  10856. li_config_table[ch_b_v].flag_table[ch_a_v] |= LI_FLAG_INTERCONNECT;
  10857. li_config_table[ch_b_s].flag_table[ch_a_v] |= LI_FLAG_INTERCONNECT;
  10858. li_config_table[ch_b_v].flag_table[ch_a_s] |= LI_FLAG_INTERCONNECT;
  10859. li_config_table[ch_b_s].flag_table[ch_a_s] |= LI_FLAG_INTERCONNECT;
  10860. }
  10861. if (li_flags & LI2_FLAG_INTERCONNECT_B_A)
  10862. {
  10863. li_config_table[ch_a_v].flag_table[ch_b_v] |= LI_FLAG_INTERCONNECT;
  10864. li_config_table[ch_a_v].flag_table[ch_b_s] |= LI_FLAG_INTERCONNECT;
  10865. li_config_table[ch_a_s].flag_table[ch_b_v] |= LI_FLAG_INTERCONNECT;
  10866. li_config_table[ch_a_s].flag_table[ch_b_s] |= LI_FLAG_INTERCONNECT;
  10867. }
  10868. if (li_flags & LI2_FLAG_MONITOR_B)
  10869. {
  10870. li_config_table[ch_b].flag_table[ch_b_v] |= LI_FLAG_MONITOR;
  10871. li_config_table[ch_b].flag_table[ch_b_s] |= LI_FLAG_MONITOR;
  10872. }
  10873. if (li_flags & LI2_FLAG_MIX_B)
  10874. {
  10875. li_config_table[ch_b_v].flag_table[ch_b] |= LI_FLAG_MIX;
  10876. li_config_table[ch_b_s].flag_table[ch_b] |= LI_FLAG_MIX;
  10877. }
  10878. if (li_flags & LI2_FLAG_MONITOR_X)
  10879. li_config_table[ch_b].chflags |= LI_CHFLAG_MONITOR;
  10880. if (li_flags & LI2_FLAG_MIX_X)
  10881. li_config_table[ch_b].chflags |= LI_CHFLAG_MIX;
  10882. if (li_flags & LI2_FLAG_LOOP_B)
  10883. {
  10884. li_config_table[ch_b_v].flag_table[ch_b_v] |= LI_FLAG_INTERCONNECT;
  10885. li_config_table[ch_b_s].flag_table[ch_b_v] |= LI_FLAG_INTERCONNECT;
  10886. li_config_table[ch_b_v].flag_table[ch_b_s] |= LI_FLAG_INTERCONNECT;
  10887. li_config_table[ch_b_s].flag_table[ch_b_s] |= LI_FLAG_INTERCONNECT;
  10888. }
  10889. if (li_flags & LI2_FLAG_LOOP_PC)
  10890. li_config_table[ch_b].flag_table[ch_b] |= LI_FLAG_PCCONNECT;
  10891. if (li_flags & LI2_FLAG_LOOP_X)
  10892. li_config_table[ch_b].chflags |= LI_CHFLAG_LOOP;
  10893. if (li_flags & LI2_FLAG_PCCONNECT_A_B)
  10894. li_config_table[ch_b_s].flag_table[ch_a_s] |= LI_FLAG_PCCONNECT;
  10895. if (li_flags & LI2_FLAG_PCCONNECT_B_A)
  10896. li_config_table[ch_a_s].flag_table[ch_b_s] |= LI_FLAG_PCCONNECT;
  10897. if (ch_a_v != ch_a_s)
  10898. {
  10899. li_config_table[ch_a_v].flag_table[ch_a_s] |= LI_FLAG_CONFERENCE;
  10900. li_config_table[ch_a_s].flag_table[ch_a_v] |= LI_FLAG_CONFERENCE;
  10901. }
  10902. if (ch_b_v != ch_b_s)
  10903. {
  10904. li_config_table[ch_b_v].flag_table[ch_b_s] |= LI_FLAG_CONFERENCE;
  10905. li_config_table[ch_b_s].flag_table[ch_b_v] |= LI_FLAG_CONFERENCE;
  10906. }
  10907. }
  10908. static word li_check_main_plci (dword Id, PLCI *plci)
  10909. {
  10910. if (plci == NULL)
  10911. {
  10912. dbug (1, dprintf ("[%06lx] %s,%d: Wrong PLCI",
  10913. UnMapId (Id), (char *)(FILE_), __LINE__));
  10914. return (_WRONG_IDENTIFIER);
  10915. }
  10916. if (!plci->State
  10917. || !plci->NL.Id || plci->nl_remove_id
  10918. || (plci->li_bchannel_id == 0))
  10919. {
  10920. dbug (1, dprintf ("[%06lx] %s,%d: Wrong state",
  10921. UnMapId (Id), (char *)(FILE_), __LINE__));
  10922. return (_WRONG_STATE);
  10923. }
  10924. li_config_table[plci->adapter->li_base + (plci->li_bchannel_id - 1)].plci = plci;
  10925. return (GOOD);
  10926. }
  10927. static PLCI *li_check_plci_b (dword Id, PLCI *plci,
  10928. dword plci_b_id, word plci_b_write_pos, byte *p_result)
  10929. {
  10930. byte ctlr_b;
  10931. PLCI *plci_b;
  10932. if (((plci->li_plci_b_read_pos > plci_b_write_pos) ? plci->li_plci_b_read_pos :
  10933. LI_PLCI_B_QUEUE_ENTRIES + plci->li_plci_b_read_pos) - plci_b_write_pos - 1 < 2)
  10934. {
  10935. dbug (1, dprintf ("[%06lx] %s,%d: LI request overrun",
  10936. UnMapId (Id), (char *)(FILE_), __LINE__));
  10937. PUT_WORD (p_result, _REQUEST_NOT_ALLOWED_IN_THIS_STATE);
  10938. return (NULL);
  10939. }
  10940. ctlr_b = 0;
  10941. if ((plci_b_id & 0x7f) != 0)
  10942. {
  10943. ctlr_b = MapController ((byte)(plci_b_id & 0x7f));
  10944. if ((ctlr_b > max_adapter) || ((ctlr_b != 0) && (adapter[ctlr_b - 1].request == NULL)))
  10945. ctlr_b = 0;
  10946. }
  10947. if ((ctlr_b == 0)
  10948. || (((plci_b_id >> 8) & 0xff) == 0)
  10949. || (((plci_b_id >> 8) & 0xff) > adapter[ctlr_b - 1].max_plci))
  10950. {
  10951. dbug (1, dprintf ("[%06lx] %s,%d: LI invalid second PLCI %08lx",
  10952. UnMapId (Id), (char *)(FILE_), __LINE__, plci_b_id));
  10953. PUT_WORD (p_result, _WRONG_IDENTIFIER);
  10954. return (NULL);
  10955. }
  10956. plci_b = &(adapter[ctlr_b - 1].plci[((plci_b_id >> 8) & 0xff) - 1]);
  10957. if (!plci_b->State
  10958. || !plci_b->NL.Id || plci_b->nl_remove_id
  10959. || (plci_b->li_bchannel_id == 0))
  10960. {
  10961. dbug (1, dprintf ("[%06lx] %s,%d: LI peer in wrong state %08lx",
  10962. UnMapId (Id), (char *)(FILE_), __LINE__, plci_b_id));
  10963. PUT_WORD (p_result, _REQUEST_NOT_ALLOWED_IN_THIS_STATE);
  10964. return (NULL);
  10965. }
  10966. li_config_table[plci_b->adapter->li_base + (plci_b->li_bchannel_id - 1)].plci = plci_b;
  10967. if (((byte)(plci_b_id & ~EXT_CONTROLLER)) !=
  10968. ((byte)(UnMapController (plci->adapter->Id) & ~EXT_CONTROLLER))
  10969. && (!(plci->adapter->manufacturer_features & MANUFACTURER_FEATURE_XCONNECT)
  10970. || !(plci_b->adapter->manufacturer_features & MANUFACTURER_FEATURE_XCONNECT)))
  10971. {
  10972. dbug (1, dprintf ("[%06lx] %s,%d: LI not on same ctrl %08lx",
  10973. UnMapId (Id), (char *)(FILE_), __LINE__, plci_b_id));
  10974. PUT_WORD (p_result, _WRONG_IDENTIFIER);
  10975. return (NULL);
  10976. }
  10977. if (!(get_b1_facilities (plci_b, add_b1_facilities (plci_b, plci_b->B1_resource,
  10978. (word)(plci_b->B1_facilities | B1_FACILITY_MIXER))) & B1_FACILITY_MIXER))
  10979. {
  10980. dbug (1, dprintf ("[%06lx] %s,%d: Interconnect peer cannot mix %d",
  10981. UnMapId (Id), (char *)(FILE_), __LINE__, plci_b->B1_resource));
  10982. PUT_WORD (p_result, _REQUEST_NOT_ALLOWED_IN_THIS_STATE);
  10983. return (NULL);
  10984. }
  10985. return (plci_b);
  10986. }
  10987. static PLCI *li2_check_plci_b (dword Id, PLCI *plci,
  10988. dword plci_b_id, word plci_b_write_pos, byte *p_result)
  10989. {
  10990. byte ctlr_b;
  10991. PLCI *plci_b;
  10992. if (((plci->li_plci_b_read_pos > plci_b_write_pos) ? plci->li_plci_b_read_pos :
  10993. LI_PLCI_B_QUEUE_ENTRIES + plci->li_plci_b_read_pos) - plci_b_write_pos - 1 < 2)
  10994. {
  10995. dbug (1, dprintf ("[%06lx] %s,%d: LI request overrun",
  10996. UnMapId (Id), (char *)(FILE_), __LINE__));
  10997. PUT_WORD (p_result, _WRONG_STATE);
  10998. return (NULL);
  10999. }
  11000. ctlr_b = 0;
  11001. if ((plci_b_id & 0x7f) != 0)
  11002. {
  11003. ctlr_b = MapController ((byte)(plci_b_id & 0x7f));
  11004. if ((ctlr_b > max_adapter) || ((ctlr_b != 0) && (adapter[ctlr_b - 1].request == NULL)))
  11005. ctlr_b = 0;
  11006. }
  11007. if ((ctlr_b == 0)
  11008. || (((plci_b_id >> 8) & 0xff) == 0)
  11009. || (((plci_b_id >> 8) & 0xff) > adapter[ctlr_b - 1].max_plci))
  11010. {
  11011. dbug (1, dprintf ("[%06lx] %s,%d: LI invalid second PLCI %08lx",
  11012. UnMapId (Id), (char *)(FILE_), __LINE__, plci_b_id));
  11013. PUT_WORD (p_result, _WRONG_IDENTIFIER);
  11014. return (NULL);
  11015. }
  11016. plci_b = &(adapter[ctlr_b - 1].plci[((plci_b_id >> 8) & 0xff) - 1]);
  11017. if (!plci_b->State
  11018. || !plci_b->NL.Id || plci_b->nl_remove_id
  11019. || (plci_b->li_bchannel_id == 0)
  11020. || (li_config_table[plci_b->adapter->li_base + (plci_b->li_bchannel_id - 1)].plci != plci_b))
  11021. {
  11022. dbug (1, dprintf ("[%06lx] %s,%d: LI peer in wrong state %08lx",
  11023. UnMapId (Id), (char *)(FILE_), __LINE__, plci_b_id));
  11024. PUT_WORD (p_result, _WRONG_STATE);
  11025. return (NULL);
  11026. }
  11027. if (((byte)(plci_b_id & ~EXT_CONTROLLER)) !=
  11028. ((byte)(UnMapController (plci->adapter->Id) & ~EXT_CONTROLLER))
  11029. && (!(plci->adapter->manufacturer_features & MANUFACTURER_FEATURE_XCONNECT)
  11030. || !(plci_b->adapter->manufacturer_features & MANUFACTURER_FEATURE_XCONNECT)))
  11031. {
  11032. dbug (1, dprintf ("[%06lx] %s,%d: LI not on same ctrl %08lx",
  11033. UnMapId (Id), (char *)(FILE_), __LINE__, plci_b_id));
  11034. PUT_WORD (p_result, _WRONG_IDENTIFIER);
  11035. return (NULL);
  11036. }
  11037. if (!(get_b1_facilities (plci_b, add_b1_facilities (plci_b, plci_b->B1_resource,
  11038. (word)(plci_b->B1_facilities | B1_FACILITY_MIXER))) & B1_FACILITY_MIXER))
  11039. {
  11040. dbug (1, dprintf ("[%06lx] %s,%d: Interconnect peer cannot mix %d",
  11041. UnMapId (Id), (char *)(FILE_), __LINE__, plci_b->B1_resource));
  11042. PUT_WORD (p_result, _WRONG_STATE);
  11043. return (NULL);
  11044. }
  11045. return (plci_b);
  11046. }
  11047. static byte mixer_request (dword Id, word Number, DIVA_CAPI_ADAPTER *a, PLCI *plci, APPL *appl, API_PARSE *msg)
  11048. {
  11049. word Info;
  11050. word i;
  11051. dword d, li_flags, plci_b_id;
  11052. PLCI *plci_b;
  11053. API_PARSE li_parms[3];
  11054. API_PARSE li_req_parms[3];
  11055. API_PARSE li_participant_struct[2];
  11056. API_PARSE li_participant_parms[3];
  11057. word participant_parms_pos;
  11058. byte result_buffer[32];
  11059. byte *result;
  11060. word result_pos;
  11061. word plci_b_write_pos;
  11062. dbug (1, dprintf ("[%06lx] %s,%d: mixer_request",
  11063. UnMapId (Id), (char *)(FILE_), __LINE__));
  11064. Info = GOOD;
  11065. result = result_buffer;
  11066. result_buffer[0] = 0;
  11067. if (!(a->profile.Global_Options & GL_LINE_INTERCONNECT_SUPPORTED))
  11068. {
  11069. dbug (1, dprintf ("[%06lx] %s,%d: Facility not supported",
  11070. UnMapId (Id), (char *)(FILE_), __LINE__));
  11071. Info = _FACILITY_NOT_SUPPORTED;
  11072. }
  11073. else if (api_parse (&msg[1].info[1], msg[1].length, "ws", li_parms))
  11074. {
  11075. dbug (1, dprintf ("[%06lx] %s,%d: Wrong message format",
  11076. UnMapId (Id), (char *)(FILE_), __LINE__));
  11077. Info = _WRONG_MESSAGE_FORMAT;
  11078. }
  11079. else
  11080. {
  11081. result_buffer[0] = 3;
  11082. PUT_WORD (&result_buffer[1], GET_WORD (li_parms[0].info));
  11083. result_buffer[3] = 0;
  11084. switch (GET_WORD (li_parms[0].info))
  11085. {
  11086. case LI_GET_SUPPORTED_SERVICES:
  11087. if (appl->appl_flags & APPL_FLAG_OLD_LI_SPEC)
  11088. {
  11089. result_buffer[0] = 17;
  11090. result_buffer[3] = 14;
  11091. PUT_WORD (&result_buffer[4], GOOD);
  11092. d = 0;
  11093. if (a->manufacturer_features & MANUFACTURER_FEATURE_MIXER_CH_CH)
  11094. d |= LI_CONFERENCING_SUPPORTED;
  11095. if (a->manufacturer_features & MANUFACTURER_FEATURE_MIXER_CH_PC)
  11096. d |= LI_MONITORING_SUPPORTED;
  11097. if (a->manufacturer_features & MANUFACTURER_FEATURE_MIXER_PC_CH)
  11098. d |= LI_ANNOUNCEMENTS_SUPPORTED | LI_MIXING_SUPPORTED;
  11099. if (a->manufacturer_features & MANUFACTURER_FEATURE_XCONNECT)
  11100. d |= LI_CROSS_CONTROLLER_SUPPORTED;
  11101. PUT_DWORD (&result_buffer[6], d);
  11102. if (a->manufacturer_features & MANUFACTURER_FEATURE_XCONNECT)
  11103. {
  11104. d = 0;
  11105. for (i = 0; i < li_total_channels; i++)
  11106. {
  11107. if ((li_config_table[i].adapter->manufacturer_features & MANUFACTURER_FEATURE_XCONNECT)
  11108. && (li_config_table[i].adapter->li_pri
  11109. || (i < li_config_table[i].adapter->li_base + MIXER_BCHANNELS_BRI)))
  11110. {
  11111. d++;
  11112. }
  11113. }
  11114. }
  11115. else
  11116. {
  11117. d = a->li_pri ? a->li_channels : MIXER_BCHANNELS_BRI;
  11118. }
  11119. PUT_DWORD (&result_buffer[10], d / 2);
  11120. PUT_DWORD (&result_buffer[14], d);
  11121. }
  11122. else
  11123. {
  11124. result_buffer[0] = 25;
  11125. result_buffer[3] = 22;
  11126. PUT_WORD (&result_buffer[4], GOOD);
  11127. d = LI2_ASYMMETRIC_SUPPORTED | LI2_B_LOOPING_SUPPORTED | LI2_X_LOOPING_SUPPORTED;
  11128. if (a->manufacturer_features & MANUFACTURER_FEATURE_MIXER_CH_PC)
  11129. d |= LI2_MONITORING_SUPPORTED | LI2_REMOTE_MONITORING_SUPPORTED;
  11130. if (a->manufacturer_features & MANUFACTURER_FEATURE_MIXER_PC_CH)
  11131. d |= LI2_MIXING_SUPPORTED | LI2_REMOTE_MIXING_SUPPORTED;
  11132. if (a->manufacturer_features & MANUFACTURER_FEATURE_MIXER_PC_PC)
  11133. d |= LI2_PC_LOOPING_SUPPORTED;
  11134. if (a->manufacturer_features & MANUFACTURER_FEATURE_XCONNECT)
  11135. d |= LI2_CROSS_CONTROLLER_SUPPORTED;
  11136. PUT_DWORD (&result_buffer[6], d);
  11137. d = a->li_pri ? a->li_channels : MIXER_BCHANNELS_BRI;
  11138. PUT_DWORD (&result_buffer[10], d / 2);
  11139. PUT_DWORD (&result_buffer[14], d - 1);
  11140. if (a->manufacturer_features & MANUFACTURER_FEATURE_XCONNECT)
  11141. {
  11142. d = 0;
  11143. for (i = 0; i < li_total_channels; i++)
  11144. {
  11145. if ((li_config_table[i].adapter->manufacturer_features & MANUFACTURER_FEATURE_XCONNECT)
  11146. && (li_config_table[i].adapter->li_pri
  11147. || (i < li_config_table[i].adapter->li_base + MIXER_BCHANNELS_BRI)))
  11148. {
  11149. d++;
  11150. }
  11151. }
  11152. }
  11153. PUT_DWORD (&result_buffer[18], d / 2);
  11154. PUT_DWORD (&result_buffer[22], d - 1);
  11155. }
  11156. break;
  11157. case LI_REQ_CONNECT:
  11158. if (li_parms[1].length == 8)
  11159. {
  11160. appl->appl_flags |= APPL_FLAG_OLD_LI_SPEC;
  11161. if (api_parse (&li_parms[1].info[1], li_parms[1].length, "dd", li_req_parms))
  11162. {
  11163. dbug (1, dprintf ("[%06lx] %s,%d: Wrong message format",
  11164. UnMapId (Id), (char *)(FILE_), __LINE__));
  11165. Info = _WRONG_MESSAGE_FORMAT;
  11166. break;
  11167. }
  11168. plci_b_id = GET_DWORD (li_req_parms[0].info) & 0xffff;
  11169. li_flags = GET_DWORD (li_req_parms[1].info);
  11170. Info = li_check_main_plci (Id, plci);
  11171. result_buffer[0] = 9;
  11172. result_buffer[3] = 6;
  11173. PUT_DWORD (&result_buffer[4], plci_b_id);
  11174. PUT_WORD (&result_buffer[8], GOOD);
  11175. if (Info != GOOD)
  11176. break;
  11177. result = plci->saved_msg.info;
  11178. for (i = 0; i <= result_buffer[0]; i++)
  11179. result[i] = result_buffer[i];
  11180. plci_b_write_pos = plci->li_plci_b_write_pos;
  11181. plci_b = li_check_plci_b (Id, plci, plci_b_id, plci_b_write_pos, &result[8]);
  11182. if (plci_b == NULL)
  11183. break;
  11184. li_update_connect (Id, a, plci, plci_b_id, true, li_flags);
  11185. plci->li_plci_b_queue[plci_b_write_pos] = plci_b_id | LI_PLCI_B_LAST_FLAG;
  11186. plci_b_write_pos = (plci_b_write_pos == LI_PLCI_B_QUEUE_ENTRIES-1) ? 0 : plci_b_write_pos + 1;
  11187. plci->li_plci_b_write_pos = plci_b_write_pos;
  11188. }
  11189. else
  11190. {
  11191. appl->appl_flags &= ~APPL_FLAG_OLD_LI_SPEC;
  11192. if (api_parse (&li_parms[1].info[1], li_parms[1].length, "ds", li_req_parms))
  11193. {
  11194. dbug (1, dprintf ("[%06lx] %s,%d: Wrong message format",
  11195. UnMapId (Id), (char *)(FILE_), __LINE__));
  11196. Info = _WRONG_MESSAGE_FORMAT;
  11197. break;
  11198. }
  11199. li_flags = GET_DWORD (li_req_parms[0].info) & ~(LI2_FLAG_INTERCONNECT_A_B | LI2_FLAG_INTERCONNECT_B_A);
  11200. Info = li_check_main_plci (Id, plci);
  11201. result_buffer[0] = 7;
  11202. result_buffer[3] = 4;
  11203. PUT_WORD (&result_buffer[4], Info);
  11204. result_buffer[6] = 0;
  11205. if (Info != GOOD)
  11206. break;
  11207. result = plci->saved_msg.info;
  11208. for (i = 0; i <= result_buffer[0]; i++)
  11209. result[i] = result_buffer[i];
  11210. plci_b_write_pos = plci->li_plci_b_write_pos;
  11211. participant_parms_pos = 0;
  11212. result_pos = 7;
  11213. li2_update_connect (Id, a, plci, UnMapId (Id), true, li_flags);
  11214. while (participant_parms_pos < li_req_parms[1].length)
  11215. {
  11216. result[result_pos] = 6;
  11217. result_pos += 7;
  11218. PUT_DWORD (&result[result_pos - 6], 0);
  11219. PUT_WORD (&result[result_pos - 2], GOOD);
  11220. if (api_parse (&li_req_parms[1].info[1 + participant_parms_pos],
  11221. (word)(li_parms[1].length - participant_parms_pos), "s", li_participant_struct))
  11222. {
  11223. dbug (1, dprintf ("[%06lx] %s,%d: Wrong message format",
  11224. UnMapId (Id), (char *)(FILE_), __LINE__));
  11225. PUT_WORD (&result[result_pos - 2], _WRONG_MESSAGE_FORMAT);
  11226. break;
  11227. }
  11228. if (api_parse (&li_participant_struct[0].info[1],
  11229. li_participant_struct[0].length, "dd", li_participant_parms))
  11230. {
  11231. dbug (1, dprintf ("[%06lx] %s,%d: Wrong message format",
  11232. UnMapId (Id), (char *)(FILE_), __LINE__));
  11233. PUT_WORD (&result[result_pos - 2], _WRONG_MESSAGE_FORMAT);
  11234. break;
  11235. }
  11236. plci_b_id = GET_DWORD (li_participant_parms[0].info) & 0xffff;
  11237. li_flags = GET_DWORD (li_participant_parms[1].info);
  11238. PUT_DWORD (&result[result_pos - 6], plci_b_id);
  11239. if (sizeof(result) - result_pos < 7)
  11240. {
  11241. dbug (1, dprintf ("[%06lx] %s,%d: LI result overrun",
  11242. UnMapId (Id), (char *)(FILE_), __LINE__));
  11243. PUT_WORD (&result[result_pos - 2], _WRONG_STATE);
  11244. break;
  11245. }
  11246. plci_b = li2_check_plci_b (Id, plci, plci_b_id, plci_b_write_pos, &result[result_pos - 2]);
  11247. if (plci_b != NULL)
  11248. {
  11249. li2_update_connect (Id, a, plci, plci_b_id, true, li_flags);
  11250. plci->li_plci_b_queue[plci_b_write_pos] = plci_b_id |
  11251. ((li_flags & (LI2_FLAG_INTERCONNECT_A_B | LI2_FLAG_INTERCONNECT_B_A |
  11252. LI2_FLAG_PCCONNECT_A_B | LI2_FLAG_PCCONNECT_B_A)) ? 0 : LI_PLCI_B_DISC_FLAG);
  11253. plci_b_write_pos = (plci_b_write_pos == LI_PLCI_B_QUEUE_ENTRIES-1) ? 0 : plci_b_write_pos + 1;
  11254. }
  11255. participant_parms_pos = (word)((&li_participant_struct[0].info[1 + li_participant_struct[0].length]) -
  11256. (&li_req_parms[1].info[1]));
  11257. }
  11258. result[0] = (byte)(result_pos - 1);
  11259. result[3] = (byte)(result_pos - 4);
  11260. result[6] = (byte)(result_pos - 7);
  11261. i = (plci_b_write_pos == 0) ? LI_PLCI_B_QUEUE_ENTRIES-1 : plci_b_write_pos - 1;
  11262. if ((plci_b_write_pos == plci->li_plci_b_read_pos)
  11263. || (plci->li_plci_b_queue[i] & LI_PLCI_B_LAST_FLAG))
  11264. {
  11265. plci->li_plci_b_queue[plci_b_write_pos] = LI_PLCI_B_SKIP_FLAG | LI_PLCI_B_LAST_FLAG;
  11266. plci_b_write_pos = (plci_b_write_pos == LI_PLCI_B_QUEUE_ENTRIES-1) ? 0 : plci_b_write_pos + 1;
  11267. }
  11268. else
  11269. plci->li_plci_b_queue[i] |= LI_PLCI_B_LAST_FLAG;
  11270. plci->li_plci_b_write_pos = plci_b_write_pos;
  11271. }
  11272. mixer_calculate_coefs (a);
  11273. plci->li_channel_bits = li_config_table[a->li_base + (plci->li_bchannel_id - 1)].channel;
  11274. mixer_notify_update (plci, true);
  11275. sendf (appl, _FACILITY_R | CONFIRM, Id & 0xffffL, Number,
  11276. "wwS", Info, SELECTOR_LINE_INTERCONNECT, result);
  11277. plci->command = 0;
  11278. plci->li_cmd = GET_WORD (li_parms[0].info);
  11279. start_internal_command (Id, plci, mixer_command);
  11280. return (false);
  11281. case LI_REQ_DISCONNECT:
  11282. if (li_parms[1].length == 4)
  11283. {
  11284. appl->appl_flags |= APPL_FLAG_OLD_LI_SPEC;
  11285. if (api_parse (&li_parms[1].info[1], li_parms[1].length, "d", li_req_parms))
  11286. {
  11287. dbug (1, dprintf ("[%06lx] %s,%d: Wrong message format",
  11288. UnMapId (Id), (char *)(FILE_), __LINE__));
  11289. Info = _WRONG_MESSAGE_FORMAT;
  11290. break;
  11291. }
  11292. plci_b_id = GET_DWORD (li_req_parms[0].info) & 0xffff;
  11293. Info = li_check_main_plci (Id, plci);
  11294. result_buffer[0] = 9;
  11295. result_buffer[3] = 6;
  11296. PUT_DWORD (&result_buffer[4], GET_DWORD (li_req_parms[0].info));
  11297. PUT_WORD (&result_buffer[8], GOOD);
  11298. if (Info != GOOD)
  11299. break;
  11300. result = plci->saved_msg.info;
  11301. for (i = 0; i <= result_buffer[0]; i++)
  11302. result[i] = result_buffer[i];
  11303. plci_b_write_pos = plci->li_plci_b_write_pos;
  11304. plci_b = li_check_plci_b (Id, plci, plci_b_id, plci_b_write_pos, &result[8]);
  11305. if (plci_b == NULL)
  11306. break;
  11307. li_update_connect (Id, a, plci, plci_b_id, false, 0);
  11308. plci->li_plci_b_queue[plci_b_write_pos] = plci_b_id | LI_PLCI_B_DISC_FLAG | LI_PLCI_B_LAST_FLAG;
  11309. plci_b_write_pos = (plci_b_write_pos == LI_PLCI_B_QUEUE_ENTRIES-1) ? 0 : plci_b_write_pos + 1;
  11310. plci->li_plci_b_write_pos = plci_b_write_pos;
  11311. }
  11312. else
  11313. {
  11314. appl->appl_flags &= ~APPL_FLAG_OLD_LI_SPEC;
  11315. if (api_parse (&li_parms[1].info[1], li_parms[1].length, "s", li_req_parms))
  11316. {
  11317. dbug (1, dprintf ("[%06lx] %s,%d: Wrong message format",
  11318. UnMapId (Id), (char *)(FILE_), __LINE__));
  11319. Info = _WRONG_MESSAGE_FORMAT;
  11320. break;
  11321. }
  11322. Info = li_check_main_plci (Id, plci);
  11323. result_buffer[0] = 7;
  11324. result_buffer[3] = 4;
  11325. PUT_WORD (&result_buffer[4], Info);
  11326. result_buffer[6] = 0;
  11327. if (Info != GOOD)
  11328. break;
  11329. result = plci->saved_msg.info;
  11330. for (i = 0; i <= result_buffer[0]; i++)
  11331. result[i] = result_buffer[i];
  11332. plci_b_write_pos = plci->li_plci_b_write_pos;
  11333. participant_parms_pos = 0;
  11334. result_pos = 7;
  11335. while (participant_parms_pos < li_req_parms[0].length)
  11336. {
  11337. result[result_pos] = 6;
  11338. result_pos += 7;
  11339. PUT_DWORD (&result[result_pos - 6], 0);
  11340. PUT_WORD (&result[result_pos - 2], GOOD);
  11341. if (api_parse (&li_req_parms[0].info[1 + participant_parms_pos],
  11342. (word)(li_parms[1].length - participant_parms_pos), "s", li_participant_struct))
  11343. {
  11344. dbug (1, dprintf ("[%06lx] %s,%d: Wrong message format",
  11345. UnMapId (Id), (char *)(FILE_), __LINE__));
  11346. PUT_WORD (&result[result_pos - 2], _WRONG_MESSAGE_FORMAT);
  11347. break;
  11348. }
  11349. if (api_parse (&li_participant_struct[0].info[1],
  11350. li_participant_struct[0].length, "d", li_participant_parms))
  11351. {
  11352. dbug (1, dprintf ("[%06lx] %s,%d: Wrong message format",
  11353. UnMapId (Id), (char *)(FILE_), __LINE__));
  11354. PUT_WORD (&result[result_pos - 2], _WRONG_MESSAGE_FORMAT);
  11355. break;
  11356. }
  11357. plci_b_id = GET_DWORD (li_participant_parms[0].info) & 0xffff;
  11358. PUT_DWORD (&result[result_pos - 6], plci_b_id);
  11359. if (sizeof(result) - result_pos < 7)
  11360. {
  11361. dbug (1, dprintf ("[%06lx] %s,%d: LI result overrun",
  11362. UnMapId (Id), (char *)(FILE_), __LINE__));
  11363. PUT_WORD (&result[result_pos - 2], _WRONG_STATE);
  11364. break;
  11365. }
  11366. plci_b = li2_check_plci_b (Id, plci, plci_b_id, plci_b_write_pos, &result[result_pos - 2]);
  11367. if (plci_b != NULL)
  11368. {
  11369. li2_update_connect (Id, a, plci, plci_b_id, false, 0);
  11370. plci->li_plci_b_queue[plci_b_write_pos] = plci_b_id | LI_PLCI_B_DISC_FLAG;
  11371. plci_b_write_pos = (plci_b_write_pos == LI_PLCI_B_QUEUE_ENTRIES-1) ? 0 : plci_b_write_pos + 1;
  11372. }
  11373. participant_parms_pos = (word)((&li_participant_struct[0].info[1 + li_participant_struct[0].length]) -
  11374. (&li_req_parms[0].info[1]));
  11375. }
  11376. result[0] = (byte)(result_pos - 1);
  11377. result[3] = (byte)(result_pos - 4);
  11378. result[6] = (byte)(result_pos - 7);
  11379. i = (plci_b_write_pos == 0) ? LI_PLCI_B_QUEUE_ENTRIES-1 : plci_b_write_pos - 1;
  11380. if ((plci_b_write_pos == plci->li_plci_b_read_pos)
  11381. || (plci->li_plci_b_queue[i] & LI_PLCI_B_LAST_FLAG))
  11382. {
  11383. plci->li_plci_b_queue[plci_b_write_pos] = LI_PLCI_B_SKIP_FLAG | LI_PLCI_B_LAST_FLAG;
  11384. plci_b_write_pos = (plci_b_write_pos == LI_PLCI_B_QUEUE_ENTRIES-1) ? 0 : plci_b_write_pos + 1;
  11385. }
  11386. else
  11387. plci->li_plci_b_queue[i] |= LI_PLCI_B_LAST_FLAG;
  11388. plci->li_plci_b_write_pos = plci_b_write_pos;
  11389. }
  11390. mixer_calculate_coefs (a);
  11391. plci->li_channel_bits = li_config_table[a->li_base + (plci->li_bchannel_id - 1)].channel;
  11392. mixer_notify_update (plci, true);
  11393. sendf (appl, _FACILITY_R | CONFIRM, Id & 0xffffL, Number,
  11394. "wwS", Info, SELECTOR_LINE_INTERCONNECT, result);
  11395. plci->command = 0;
  11396. plci->li_cmd = GET_WORD (li_parms[0].info);
  11397. start_internal_command (Id, plci, mixer_command);
  11398. return (false);
  11399. case LI_REQ_SILENT_UPDATE:
  11400. if (!plci || !plci->State
  11401. || !plci->NL.Id || plci->nl_remove_id
  11402. || (plci->li_bchannel_id == 0)
  11403. || (li_config_table[plci->adapter->li_base + (plci->li_bchannel_id - 1)].plci != plci))
  11404. {
  11405. dbug (1, dprintf ("[%06lx] %s,%d: Wrong state",
  11406. UnMapId (Id), (char *)(FILE_), __LINE__));
  11407. return (false);
  11408. }
  11409. plci_b_write_pos = plci->li_plci_b_write_pos;
  11410. if (((plci->li_plci_b_read_pos > plci_b_write_pos) ? plci->li_plci_b_read_pos :
  11411. LI_PLCI_B_QUEUE_ENTRIES + plci->li_plci_b_read_pos) - plci_b_write_pos - 1 < 2)
  11412. {
  11413. dbug (1, dprintf ("[%06lx] %s,%d: LI request overrun",
  11414. UnMapId (Id), (char *)(FILE_), __LINE__));
  11415. return (false);
  11416. }
  11417. i = (plci_b_write_pos == 0) ? LI_PLCI_B_QUEUE_ENTRIES-1 : plci_b_write_pos - 1;
  11418. if ((plci_b_write_pos == plci->li_plci_b_read_pos)
  11419. || (plci->li_plci_b_queue[i] & LI_PLCI_B_LAST_FLAG))
  11420. {
  11421. plci->li_plci_b_queue[plci_b_write_pos] = LI_PLCI_B_SKIP_FLAG | LI_PLCI_B_LAST_FLAG;
  11422. plci_b_write_pos = (plci_b_write_pos == LI_PLCI_B_QUEUE_ENTRIES-1) ? 0 : plci_b_write_pos + 1;
  11423. }
  11424. else
  11425. plci->li_plci_b_queue[i] |= LI_PLCI_B_LAST_FLAG;
  11426. plci->li_plci_b_write_pos = plci_b_write_pos;
  11427. plci->li_channel_bits = li_config_table[a->li_base + (plci->li_bchannel_id - 1)].channel;
  11428. plci->command = 0;
  11429. plci->li_cmd = GET_WORD (li_parms[0].info);
  11430. start_internal_command (Id, plci, mixer_command);
  11431. return (false);
  11432. default:
  11433. dbug (1, dprintf ("[%06lx] %s,%d: LI unknown request %04x",
  11434. UnMapId (Id), (char *)(FILE_), __LINE__, GET_WORD (li_parms[0].info)));
  11435. Info = _FACILITY_NOT_SUPPORTED;
  11436. }
  11437. }
  11438. sendf (appl, _FACILITY_R | CONFIRM, Id & 0xffffL, Number,
  11439. "wwS", Info, SELECTOR_LINE_INTERCONNECT, result);
  11440. return (false);
  11441. }
  11442. static void mixer_indication_coefs_set (dword Id, PLCI *plci)
  11443. {
  11444. dword d;
  11445. DIVA_CAPI_ADAPTER *a;
  11446. byte result[12];
  11447. dbug (1, dprintf ("[%06lx] %s,%d: mixer_indication_coefs_set",
  11448. UnMapId (Id), (char *)(FILE_), __LINE__));
  11449. a = plci->adapter;
  11450. if (plci->li_plci_b_read_pos != plci->li_plci_b_req_pos)
  11451. {
  11452. do
  11453. {
  11454. d = plci->li_plci_b_queue[plci->li_plci_b_read_pos];
  11455. if (!(d & LI_PLCI_B_SKIP_FLAG))
  11456. {
  11457. if (plci->appl->appl_flags & APPL_FLAG_OLD_LI_SPEC)
  11458. {
  11459. if (d & LI_PLCI_B_DISC_FLAG)
  11460. {
  11461. result[0] = 5;
  11462. PUT_WORD (&result[1], LI_IND_DISCONNECT);
  11463. result[3] = 2;
  11464. PUT_WORD (&result[4], _LI_USER_INITIATED);
  11465. }
  11466. else
  11467. {
  11468. result[0] = 7;
  11469. PUT_WORD (&result[1], LI_IND_CONNECT_ACTIVE);
  11470. result[3] = 4;
  11471. PUT_DWORD (&result[4], d & ~LI_PLCI_B_FLAG_MASK);
  11472. }
  11473. }
  11474. else
  11475. {
  11476. if (d & LI_PLCI_B_DISC_FLAG)
  11477. {
  11478. result[0] = 9;
  11479. PUT_WORD (&result[1], LI_IND_DISCONNECT);
  11480. result[3] = 6;
  11481. PUT_DWORD (&result[4], d & ~LI_PLCI_B_FLAG_MASK);
  11482. PUT_WORD (&result[8], _LI_USER_INITIATED);
  11483. }
  11484. else
  11485. {
  11486. result[0] = 7;
  11487. PUT_WORD (&result[1], LI_IND_CONNECT_ACTIVE);
  11488. result[3] = 4;
  11489. PUT_DWORD (&result[4], d & ~LI_PLCI_B_FLAG_MASK);
  11490. }
  11491. }
  11492. sendf (plci->appl, _FACILITY_I, Id & 0xffffL, 0,
  11493. "ws", SELECTOR_LINE_INTERCONNECT, result);
  11494. }
  11495. plci->li_plci_b_read_pos = (plci->li_plci_b_read_pos == LI_PLCI_B_QUEUE_ENTRIES-1) ?
  11496. 0 : plci->li_plci_b_read_pos + 1;
  11497. } while (!(d & LI_PLCI_B_LAST_FLAG) && (plci->li_plci_b_read_pos != plci->li_plci_b_req_pos));
  11498. }
  11499. }
  11500. static void mixer_indication_xconnect_from (dword Id, PLCI *plci, byte *msg, word length)
  11501. {
  11502. word i, j, ch;
  11503. struct xconnect_transfer_address_s s, *p;
  11504. DIVA_CAPI_ADAPTER *a;
  11505. dbug (1, dprintf ("[%06lx] %s,%d: mixer_indication_xconnect_from %d",
  11506. UnMapId (Id), (char *)(FILE_), __LINE__, (int) length));
  11507. a = plci->adapter;
  11508. i = 1;
  11509. for (i = 1; i < length; i += 16)
  11510. {
  11511. s.card_address.low = msg[i] | (msg[i+1] << 8) | (((dword)(msg[i+2])) << 16) | (((dword)(msg[i+3])) << 24);
  11512. s.card_address.high = msg[i+4] | (msg[i+5] << 8) | (((dword)(msg[i+6])) << 16) | (((dword)(msg[i+7])) << 24);
  11513. s.offset = msg[i+8] | (msg[i+9] << 8) | (((dword)(msg[i+10])) << 16) | (((dword)(msg[i+11])) << 24);
  11514. ch = msg[i+12] | (msg[i+13] << 8);
  11515. j = ch & XCONNECT_CHANNEL_NUMBER_MASK;
  11516. if (!a->li_pri && (plci->li_bchannel_id == 2))
  11517. j = 1 - j;
  11518. j += a->li_base;
  11519. if (ch & XCONNECT_CHANNEL_PORT_PC)
  11520. p = &(li_config_table[j].send_pc);
  11521. else
  11522. p = &(li_config_table[j].send_b);
  11523. p->card_address.low = s.card_address.low;
  11524. p->card_address.high = s.card_address.high;
  11525. p->offset = s.offset;
  11526. li_config_table[j].channel |= LI_CHANNEL_ADDRESSES_SET;
  11527. }
  11528. if (plci->internal_command_queue[0]
  11529. && ((plci->adjust_b_state == ADJUST_B_RESTORE_MIXER_2)
  11530. || (plci->adjust_b_state == ADJUST_B_RESTORE_MIXER_3)
  11531. || (plci->adjust_b_state == ADJUST_B_RESTORE_MIXER_4)))
  11532. {
  11533. (*(plci->internal_command_queue[0]))(Id, plci, 0);
  11534. if (!plci->internal_command)
  11535. next_internal_command (Id, plci);
  11536. }
  11537. mixer_notify_update (plci, true);
  11538. }
  11539. static void mixer_indication_xconnect_to (dword Id, PLCI *plci, byte *msg, word length)
  11540. {
  11541. dbug (1, dprintf ("[%06lx] %s,%d: mixer_indication_xconnect_to %d",
  11542. UnMapId (Id), (char *)(FILE_), __LINE__, (int) length));
  11543. }
  11544. static byte mixer_notify_source_removed (PLCI *plci, dword plci_b_id)
  11545. {
  11546. word plci_b_write_pos;
  11547. plci_b_write_pos = plci->li_plci_b_write_pos;
  11548. if (((plci->li_plci_b_read_pos > plci_b_write_pos) ? plci->li_plci_b_read_pos :
  11549. LI_PLCI_B_QUEUE_ENTRIES + plci->li_plci_b_read_pos) - plci_b_write_pos - 1 < 1)
  11550. {
  11551. dbug (1, dprintf ("[%06lx] %s,%d: LI request overrun",
  11552. (dword)((plci->Id << 8) | UnMapController (plci->adapter->Id)),
  11553. (char *)(FILE_), __LINE__));
  11554. return (false);
  11555. }
  11556. plci->li_plci_b_queue[plci_b_write_pos] = plci_b_id | LI_PLCI_B_DISC_FLAG;
  11557. plci_b_write_pos = (plci_b_write_pos == LI_PLCI_B_QUEUE_ENTRIES-1) ? 0 : plci_b_write_pos + 1;
  11558. plci->li_plci_b_write_pos = plci_b_write_pos;
  11559. return (true);
  11560. }
  11561. static void mixer_remove (PLCI *plci)
  11562. {
  11563. DIVA_CAPI_ADAPTER *a;
  11564. PLCI *notify_plci;
  11565. dword plci_b_id;
  11566. word i, j;
  11567. dbug (1, dprintf ("[%06lx] %s,%d: mixer_remove",
  11568. (dword)((plci->Id << 8) | UnMapController (plci->adapter->Id)),
  11569. (char *)(FILE_), __LINE__));
  11570. a = plci->adapter;
  11571. plci_b_id = (plci->Id << 8) | UnMapController (plci->adapter->Id);
  11572. if (a->profile.Global_Options & GL_LINE_INTERCONNECT_SUPPORTED)
  11573. {
  11574. if ((plci->li_bchannel_id != 0)
  11575. && (li_config_table[a->li_base + (plci->li_bchannel_id - 1)].plci == plci))
  11576. {
  11577. i = a->li_base + (plci->li_bchannel_id - 1);
  11578. if ((li_config_table[i].curchnl | li_config_table[i].channel) & LI_CHANNEL_INVOLVED)
  11579. {
  11580. for (j = 0; j < li_total_channels; j++)
  11581. {
  11582. if ((li_config_table[i].flag_table[j] & LI_FLAG_INTERCONNECT)
  11583. || (li_config_table[j].flag_table[i] & LI_FLAG_INTERCONNECT))
  11584. {
  11585. notify_plci = li_config_table[j].plci;
  11586. if ((notify_plci != NULL)
  11587. && (notify_plci != plci)
  11588. && (notify_plci->appl != NULL)
  11589. && !(notify_plci->appl->appl_flags & APPL_FLAG_OLD_LI_SPEC)
  11590. && (notify_plci->State)
  11591. && notify_plci->NL.Id && !notify_plci->nl_remove_id)
  11592. {
  11593. mixer_notify_source_removed (notify_plci, plci_b_id);
  11594. }
  11595. }
  11596. }
  11597. mixer_clear_config (plci);
  11598. mixer_calculate_coefs (a);
  11599. mixer_notify_update (plci, true);
  11600. }
  11601. li_config_table[i].plci = NULL;
  11602. plci->li_bchannel_id = 0;
  11603. }
  11604. }
  11605. }
  11606. /*------------------------------------------------------------------*/
  11607. /* Echo canceller facilities */
  11608. /*------------------------------------------------------------------*/
  11609. static void ec_write_parameters (PLCI *plci)
  11610. {
  11611. word w;
  11612. byte parameter_buffer[6];
  11613. dbug (1, dprintf ("[%06lx] %s,%d: ec_write_parameters",
  11614. (dword)((plci->Id << 8) | UnMapController (plci->adapter->Id)),
  11615. (char *)(FILE_), __LINE__));
  11616. parameter_buffer[0] = 5;
  11617. parameter_buffer[1] = DSP_CTRL_SET_LEC_PARAMETERS;
  11618. PUT_WORD (&parameter_buffer[2], plci->ec_idi_options);
  11619. plci->ec_idi_options &= ~LEC_RESET_COEFFICIENTS;
  11620. w = (plci->ec_tail_length == 0) ? 128 : plci->ec_tail_length;
  11621. PUT_WORD (&parameter_buffer[4], w);
  11622. add_p (plci, FTY, parameter_buffer);
  11623. sig_req (plci, TEL_CTRL, 0);
  11624. send_req (plci);
  11625. }
  11626. static void ec_clear_config (PLCI *plci)
  11627. {
  11628. dbug (1, dprintf ("[%06lx] %s,%d: ec_clear_config",
  11629. (dword)((plci->Id << 8) | UnMapController (plci->adapter->Id)),
  11630. (char *)(FILE_), __LINE__));
  11631. plci->ec_idi_options = LEC_ENABLE_ECHO_CANCELLER |
  11632. LEC_MANUAL_DISABLE | LEC_ENABLE_NONLINEAR_PROCESSING;
  11633. plci->ec_tail_length = 0;
  11634. }
  11635. static void ec_prepare_switch (dword Id, PLCI *plci)
  11636. {
  11637. dbug (1, dprintf ("[%06lx] %s,%d: ec_prepare_switch",
  11638. UnMapId (Id), (char *)(FILE_), __LINE__));
  11639. }
  11640. static word ec_save_config (dword Id, PLCI *plci, byte Rc)
  11641. {
  11642. dbug (1, dprintf ("[%06lx] %s,%d: ec_save_config %02x %d",
  11643. UnMapId (Id), (char *)(FILE_), __LINE__, Rc, plci->adjust_b_state));
  11644. return (GOOD);
  11645. }
  11646. static word ec_restore_config (dword Id, PLCI *plci, byte Rc)
  11647. {
  11648. word Info;
  11649. dbug (1, dprintf ("[%06lx] %s,%d: ec_restore_config %02x %d",
  11650. UnMapId (Id), (char *)(FILE_), __LINE__, Rc, plci->adjust_b_state));
  11651. Info = GOOD;
  11652. if (plci->B1_facilities & B1_FACILITY_EC)
  11653. {
  11654. switch (plci->adjust_b_state)
  11655. {
  11656. case ADJUST_B_RESTORE_EC_1:
  11657. plci->internal_command = plci->adjust_b_command;
  11658. if (plci->sig_req)
  11659. {
  11660. plci->adjust_b_state = ADJUST_B_RESTORE_EC_1;
  11661. break;
  11662. }
  11663. ec_write_parameters (plci);
  11664. plci->adjust_b_state = ADJUST_B_RESTORE_EC_2;
  11665. break;
  11666. case ADJUST_B_RESTORE_EC_2:
  11667. if ((Rc != OK) && (Rc != OK_FC))
  11668. {
  11669. dbug (1, dprintf ("[%06lx] %s,%d: Restore EC failed %02x",
  11670. UnMapId (Id), (char *)(FILE_), __LINE__, Rc));
  11671. Info = _WRONG_STATE;
  11672. break;
  11673. }
  11674. break;
  11675. }
  11676. }
  11677. return (Info);
  11678. }
  11679. static void ec_command (dword Id, PLCI *plci, byte Rc)
  11680. {
  11681. word internal_command, Info;
  11682. byte result[8];
  11683. dbug (1, dprintf ("[%06lx] %s,%d: ec_command %02x %04x %04x %04x %d",
  11684. UnMapId (Id), (char *)(FILE_), __LINE__, Rc, plci->internal_command,
  11685. plci->ec_cmd, plci->ec_idi_options, plci->ec_tail_length));
  11686. Info = GOOD;
  11687. if (plci->appl->appl_flags & APPL_FLAG_PRIV_EC_SPEC)
  11688. {
  11689. result[0] = 2;
  11690. PUT_WORD (&result[1], EC_SUCCESS);
  11691. }
  11692. else
  11693. {
  11694. result[0] = 5;
  11695. PUT_WORD (&result[1], plci->ec_cmd);
  11696. result[3] = 2;
  11697. PUT_WORD (&result[4], GOOD);
  11698. }
  11699. internal_command = plci->internal_command;
  11700. plci->internal_command = 0;
  11701. switch (plci->ec_cmd)
  11702. {
  11703. case EC_ENABLE_OPERATION:
  11704. case EC_FREEZE_COEFFICIENTS:
  11705. case EC_RESUME_COEFFICIENT_UPDATE:
  11706. case EC_RESET_COEFFICIENTS:
  11707. switch (internal_command)
  11708. {
  11709. default:
  11710. adjust_b1_resource (Id, plci, NULL, (word)(plci->B1_facilities |
  11711. B1_FACILITY_EC), EC_COMMAND_1);
  11712. case EC_COMMAND_1:
  11713. if (adjust_b_process (Id, plci, Rc) != GOOD)
  11714. {
  11715. dbug (1, dprintf ("[%06lx] %s,%d: Load EC failed",
  11716. UnMapId (Id), (char *)(FILE_), __LINE__));
  11717. Info = _FACILITY_NOT_SUPPORTED;
  11718. break;
  11719. }
  11720. if (plci->internal_command)
  11721. return;
  11722. case EC_COMMAND_2:
  11723. if (plci->sig_req)
  11724. {
  11725. plci->internal_command = EC_COMMAND_2;
  11726. return;
  11727. }
  11728. plci->internal_command = EC_COMMAND_3;
  11729. ec_write_parameters (plci);
  11730. return;
  11731. case EC_COMMAND_3:
  11732. if ((Rc != OK) && (Rc != OK_FC))
  11733. {
  11734. dbug (1, dprintf ("[%06lx] %s,%d: Enable EC failed %02x",
  11735. UnMapId (Id), (char *)(FILE_), __LINE__, Rc));
  11736. Info = _FACILITY_NOT_SUPPORTED;
  11737. break;
  11738. }
  11739. break;
  11740. }
  11741. break;
  11742. case EC_DISABLE_OPERATION:
  11743. switch (internal_command)
  11744. {
  11745. default:
  11746. case EC_COMMAND_1:
  11747. if (plci->B1_facilities & B1_FACILITY_EC)
  11748. {
  11749. if (plci->sig_req)
  11750. {
  11751. plci->internal_command = EC_COMMAND_1;
  11752. return;
  11753. }
  11754. plci->internal_command = EC_COMMAND_2;
  11755. ec_write_parameters (plci);
  11756. return;
  11757. }
  11758. Rc = OK;
  11759. case EC_COMMAND_2:
  11760. if ((Rc != OK) && (Rc != OK_FC))
  11761. {
  11762. dbug (1, dprintf ("[%06lx] %s,%d: Disable EC failed %02x",
  11763. UnMapId (Id), (char *)(FILE_), __LINE__, Rc));
  11764. Info = _FACILITY_NOT_SUPPORTED;
  11765. break;
  11766. }
  11767. adjust_b1_resource (Id, plci, NULL, (word)(plci->B1_facilities &
  11768. ~B1_FACILITY_EC), EC_COMMAND_3);
  11769. case EC_COMMAND_3:
  11770. if (adjust_b_process (Id, plci, Rc) != GOOD)
  11771. {
  11772. dbug (1, dprintf ("[%06lx] %s,%d: Unload EC failed",
  11773. UnMapId (Id), (char *)(FILE_), __LINE__));
  11774. Info = _FACILITY_NOT_SUPPORTED;
  11775. break;
  11776. }
  11777. if (plci->internal_command)
  11778. return;
  11779. break;
  11780. }
  11781. break;
  11782. }
  11783. sendf (plci->appl, _FACILITY_R | CONFIRM, Id & 0xffffL, plci->number,
  11784. "wws", Info, (plci->appl->appl_flags & APPL_FLAG_PRIV_EC_SPEC) ?
  11785. PRIV_SELECTOR_ECHO_CANCELLER : SELECTOR_ECHO_CANCELLER, result);
  11786. }
  11787. static byte ec_request (dword Id, word Number, DIVA_CAPI_ADAPTER *a, PLCI *plci, APPL *appl, API_PARSE *msg)
  11788. {
  11789. word Info;
  11790. word opt;
  11791. API_PARSE ec_parms[3];
  11792. byte result[16];
  11793. dbug (1, dprintf ("[%06lx] %s,%d: ec_request",
  11794. UnMapId (Id), (char *)(FILE_), __LINE__));
  11795. Info = GOOD;
  11796. result[0] = 0;
  11797. if (!(a->man_profile.private_options & (1L << PRIVATE_ECHO_CANCELLER)))
  11798. {
  11799. dbug (1, dprintf ("[%06lx] %s,%d: Facility not supported",
  11800. UnMapId (Id), (char *)(FILE_), __LINE__));
  11801. Info = _FACILITY_NOT_SUPPORTED;
  11802. }
  11803. else
  11804. {
  11805. if (appl->appl_flags & APPL_FLAG_PRIV_EC_SPEC)
  11806. {
  11807. if (api_parse (&msg[1].info[1], msg[1].length, "w", ec_parms))
  11808. {
  11809. dbug (1, dprintf ("[%06lx] %s,%d: Wrong message format",
  11810. UnMapId (Id), (char *)(FILE_), __LINE__));
  11811. Info = _WRONG_MESSAGE_FORMAT;
  11812. }
  11813. else
  11814. {
  11815. if (plci == NULL)
  11816. {
  11817. dbug (1, dprintf ("[%06lx] %s,%d: Wrong PLCI",
  11818. UnMapId (Id), (char *)(FILE_), __LINE__));
  11819. Info = _WRONG_IDENTIFIER;
  11820. }
  11821. else if (!plci->State || !plci->NL.Id || plci->nl_remove_id)
  11822. {
  11823. dbug (1, dprintf ("[%06lx] %s,%d: Wrong state",
  11824. UnMapId (Id), (char *)(FILE_), __LINE__));
  11825. Info = _WRONG_STATE;
  11826. }
  11827. else
  11828. {
  11829. plci->command = 0;
  11830. plci->ec_cmd = GET_WORD (ec_parms[0].info);
  11831. plci->ec_idi_options &= ~(LEC_MANUAL_DISABLE | LEC_RESET_COEFFICIENTS);
  11832. result[0] = 2;
  11833. PUT_WORD (&result[1], EC_SUCCESS);
  11834. if (msg[1].length >= 4)
  11835. {
  11836. opt = GET_WORD (&ec_parms[0].info[2]);
  11837. plci->ec_idi_options &= ~(LEC_ENABLE_NONLINEAR_PROCESSING |
  11838. LEC_ENABLE_2100HZ_DETECTOR | LEC_REQUIRE_2100HZ_REVERSALS);
  11839. if (!(opt & EC_DISABLE_NON_LINEAR_PROCESSING))
  11840. plci->ec_idi_options |= LEC_ENABLE_NONLINEAR_PROCESSING;
  11841. if (opt & EC_DETECT_DISABLE_TONE)
  11842. plci->ec_idi_options |= LEC_ENABLE_2100HZ_DETECTOR;
  11843. if (!(opt & EC_DO_NOT_REQUIRE_REVERSALS))
  11844. plci->ec_idi_options |= LEC_REQUIRE_2100HZ_REVERSALS;
  11845. if (msg[1].length >= 6)
  11846. {
  11847. plci->ec_tail_length = GET_WORD (&ec_parms[0].info[4]);
  11848. }
  11849. }
  11850. switch (plci->ec_cmd)
  11851. {
  11852. case EC_ENABLE_OPERATION:
  11853. plci->ec_idi_options &= ~LEC_FREEZE_COEFFICIENTS;
  11854. start_internal_command (Id, plci, ec_command);
  11855. return (false);
  11856. case EC_DISABLE_OPERATION:
  11857. plci->ec_idi_options = LEC_ENABLE_ECHO_CANCELLER |
  11858. LEC_MANUAL_DISABLE | LEC_ENABLE_NONLINEAR_PROCESSING |
  11859. LEC_RESET_COEFFICIENTS;
  11860. start_internal_command (Id, plci, ec_command);
  11861. return (false);
  11862. case EC_FREEZE_COEFFICIENTS:
  11863. plci->ec_idi_options |= LEC_FREEZE_COEFFICIENTS;
  11864. start_internal_command (Id, plci, ec_command);
  11865. return (false);
  11866. case EC_RESUME_COEFFICIENT_UPDATE:
  11867. plci->ec_idi_options &= ~LEC_FREEZE_COEFFICIENTS;
  11868. start_internal_command (Id, plci, ec_command);
  11869. return (false);
  11870. case EC_RESET_COEFFICIENTS:
  11871. plci->ec_idi_options |= LEC_RESET_COEFFICIENTS;
  11872. start_internal_command (Id, plci, ec_command);
  11873. return (false);
  11874. default:
  11875. dbug (1, dprintf ("[%06lx] %s,%d: EC unknown request %04x",
  11876. UnMapId (Id), (char *)(FILE_), __LINE__, plci->ec_cmd));
  11877. PUT_WORD (&result[1], EC_UNSUPPORTED_OPERATION);
  11878. }
  11879. }
  11880. }
  11881. }
  11882. else
  11883. {
  11884. if (api_parse (&msg[1].info[1], msg[1].length, "ws", ec_parms))
  11885. {
  11886. dbug (1, dprintf ("[%06lx] %s,%d: Wrong message format",
  11887. UnMapId (Id), (char *)(FILE_), __LINE__));
  11888. Info = _WRONG_MESSAGE_FORMAT;
  11889. }
  11890. else
  11891. {
  11892. if (GET_WORD (ec_parms[0].info) == EC_GET_SUPPORTED_SERVICES)
  11893. {
  11894. result[0] = 11;
  11895. PUT_WORD (&result[1], EC_GET_SUPPORTED_SERVICES);
  11896. result[3] = 8;
  11897. PUT_WORD (&result[4], GOOD);
  11898. PUT_WORD (&result[6], 0x0007);
  11899. PUT_WORD (&result[8], LEC_MAX_SUPPORTED_TAIL_LENGTH);
  11900. PUT_WORD (&result[10], 0);
  11901. }
  11902. else if (plci == NULL)
  11903. {
  11904. dbug (1, dprintf ("[%06lx] %s,%d: Wrong PLCI",
  11905. UnMapId (Id), (char *)(FILE_), __LINE__));
  11906. Info = _WRONG_IDENTIFIER;
  11907. }
  11908. else if (!plci->State || !plci->NL.Id || plci->nl_remove_id)
  11909. {
  11910. dbug (1, dprintf ("[%06lx] %s,%d: Wrong state",
  11911. UnMapId (Id), (char *)(FILE_), __LINE__));
  11912. Info = _WRONG_STATE;
  11913. }
  11914. else
  11915. {
  11916. plci->command = 0;
  11917. plci->ec_cmd = GET_WORD (ec_parms[0].info);
  11918. plci->ec_idi_options &= ~(LEC_MANUAL_DISABLE | LEC_RESET_COEFFICIENTS);
  11919. result[0] = 5;
  11920. PUT_WORD (&result[1], plci->ec_cmd);
  11921. result[3] = 2;
  11922. PUT_WORD (&result[4], GOOD);
  11923. plci->ec_idi_options &= ~(LEC_ENABLE_NONLINEAR_PROCESSING |
  11924. LEC_ENABLE_2100HZ_DETECTOR | LEC_REQUIRE_2100HZ_REVERSALS);
  11925. plci->ec_tail_length = 0;
  11926. if (ec_parms[1].length >= 2)
  11927. {
  11928. opt = GET_WORD (&ec_parms[1].info[1]);
  11929. if (opt & EC_ENABLE_NON_LINEAR_PROCESSING)
  11930. plci->ec_idi_options |= LEC_ENABLE_NONLINEAR_PROCESSING;
  11931. if (opt & EC_DETECT_DISABLE_TONE)
  11932. plci->ec_idi_options |= LEC_ENABLE_2100HZ_DETECTOR;
  11933. if (!(opt & EC_DO_NOT_REQUIRE_REVERSALS))
  11934. plci->ec_idi_options |= LEC_REQUIRE_2100HZ_REVERSALS;
  11935. if (ec_parms[1].length >= 4)
  11936. {
  11937. plci->ec_tail_length = GET_WORD (&ec_parms[1].info[3]);
  11938. }
  11939. }
  11940. switch (plci->ec_cmd)
  11941. {
  11942. case EC_ENABLE_OPERATION:
  11943. plci->ec_idi_options &= ~LEC_FREEZE_COEFFICIENTS;
  11944. start_internal_command (Id, plci, ec_command);
  11945. return (false);
  11946. case EC_DISABLE_OPERATION:
  11947. plci->ec_idi_options = LEC_ENABLE_ECHO_CANCELLER |
  11948. LEC_MANUAL_DISABLE | LEC_ENABLE_NONLINEAR_PROCESSING |
  11949. LEC_RESET_COEFFICIENTS;
  11950. start_internal_command (Id, plci, ec_command);
  11951. return (false);
  11952. default:
  11953. dbug (1, dprintf ("[%06lx] %s,%d: EC unknown request %04x",
  11954. UnMapId (Id), (char *)(FILE_), __LINE__, plci->ec_cmd));
  11955. PUT_WORD (&result[4], _FACILITY_SPECIFIC_FUNCTION_NOT_SUPP);
  11956. }
  11957. }
  11958. }
  11959. }
  11960. }
  11961. sendf (appl, _FACILITY_R | CONFIRM, Id & 0xffffL, Number,
  11962. "wws", Info, (appl->appl_flags & APPL_FLAG_PRIV_EC_SPEC) ?
  11963. PRIV_SELECTOR_ECHO_CANCELLER : SELECTOR_ECHO_CANCELLER, result);
  11964. return (false);
  11965. }
  11966. static void ec_indication (dword Id, PLCI *plci, byte *msg, word length)
  11967. {
  11968. byte result[8];
  11969. dbug (1, dprintf ("[%06lx] %s,%d: ec_indication",
  11970. UnMapId (Id), (char *)(FILE_), __LINE__));
  11971. if (!(plci->ec_idi_options & LEC_MANUAL_DISABLE))
  11972. {
  11973. if (plci->appl->appl_flags & APPL_FLAG_PRIV_EC_SPEC)
  11974. {
  11975. result[0] = 2;
  11976. PUT_WORD (&result[1], 0);
  11977. switch (msg[1])
  11978. {
  11979. case LEC_DISABLE_TYPE_CONTIGNUOUS_2100HZ:
  11980. PUT_WORD (&result[1], EC_BYPASS_DUE_TO_CONTINUOUS_2100HZ);
  11981. break;
  11982. case LEC_DISABLE_TYPE_REVERSED_2100HZ:
  11983. PUT_WORD (&result[1], EC_BYPASS_DUE_TO_REVERSED_2100HZ);
  11984. break;
  11985. case LEC_DISABLE_RELEASED:
  11986. PUT_WORD (&result[1], EC_BYPASS_RELEASED);
  11987. break;
  11988. }
  11989. }
  11990. else
  11991. {
  11992. result[0] = 5;
  11993. PUT_WORD (&result[1], EC_BYPASS_INDICATION);
  11994. result[3] = 2;
  11995. PUT_WORD (&result[4], 0);
  11996. switch (msg[1])
  11997. {
  11998. case LEC_DISABLE_TYPE_CONTIGNUOUS_2100HZ:
  11999. PUT_WORD (&result[4], EC_BYPASS_DUE_TO_CONTINUOUS_2100HZ);
  12000. break;
  12001. case LEC_DISABLE_TYPE_REVERSED_2100HZ:
  12002. PUT_WORD (&result[4], EC_BYPASS_DUE_TO_REVERSED_2100HZ);
  12003. break;
  12004. case LEC_DISABLE_RELEASED:
  12005. PUT_WORD (&result[4], EC_BYPASS_RELEASED);
  12006. break;
  12007. }
  12008. }
  12009. sendf (plci->appl, _FACILITY_I, Id & 0xffffL, 0, "ws", (plci->appl->appl_flags & APPL_FLAG_PRIV_EC_SPEC) ?
  12010. PRIV_SELECTOR_ECHO_CANCELLER : SELECTOR_ECHO_CANCELLER, result);
  12011. }
  12012. }
  12013. /*------------------------------------------------------------------*/
  12014. /* Advanced voice */
  12015. /*------------------------------------------------------------------*/
  12016. static void adv_voice_write_coefs (PLCI *plci, word write_command)
  12017. {
  12018. DIVA_CAPI_ADAPTER *a;
  12019. word i;
  12020. byte *p;
  12021. word w, n, j, k;
  12022. byte ch_map[MIXER_CHANNELS_BRI];
  12023. byte coef_buffer[ADV_VOICE_COEF_BUFFER_SIZE + 2];
  12024. dbug (1, dprintf ("[%06lx] %s,%d: adv_voice_write_coefs %d",
  12025. (dword)((plci->Id << 8) | UnMapController (plci->adapter->Id)),
  12026. (char *)(FILE_), __LINE__, write_command));
  12027. a = plci->adapter;
  12028. p = coef_buffer + 1;
  12029. *(p++) = DSP_CTRL_OLD_SET_MIXER_COEFFICIENTS;
  12030. i = 0;
  12031. while (i + sizeof(word) <= a->adv_voice_coef_length)
  12032. {
  12033. PUT_WORD (p, GET_WORD (a->adv_voice_coef_buffer + i));
  12034. p += 2;
  12035. i += 2;
  12036. }
  12037. while (i < ADV_VOICE_OLD_COEF_COUNT * sizeof(word))
  12038. {
  12039. PUT_WORD (p, 0x8000);
  12040. p += 2;
  12041. i += 2;
  12042. }
  12043. if (!a->li_pri && (plci->li_bchannel_id == 0))
  12044. {
  12045. if ((li_config_table[a->li_base].plci == NULL) && (li_config_table[a->li_base + 1].plci != NULL))
  12046. {
  12047. plci->li_bchannel_id = 1;
  12048. li_config_table[a->li_base].plci = plci;
  12049. dbug (1, dprintf ("[%06lx] %s,%d: adv_voice_set_bchannel_id %d",
  12050. (dword)((plci->Id << 8) | UnMapController (plci->adapter->Id)),
  12051. (char *)(FILE_), __LINE__, plci->li_bchannel_id));
  12052. }
  12053. else if ((li_config_table[a->li_base].plci != NULL) && (li_config_table[a->li_base + 1].plci == NULL))
  12054. {
  12055. plci->li_bchannel_id = 2;
  12056. li_config_table[a->li_base + 1].plci = plci;
  12057. dbug (1, dprintf ("[%06lx] %s,%d: adv_voice_set_bchannel_id %d",
  12058. (dword)((plci->Id << 8) | UnMapController (plci->adapter->Id)),
  12059. (char *)(FILE_), __LINE__, plci->li_bchannel_id));
  12060. }
  12061. }
  12062. if (!a->li_pri && (plci->li_bchannel_id != 0)
  12063. && (li_config_table[a->li_base + (plci->li_bchannel_id - 1)].plci == plci))
  12064. {
  12065. i = a->li_base + (plci->li_bchannel_id - 1);
  12066. switch (write_command)
  12067. {
  12068. case ADV_VOICE_WRITE_ACTIVATION:
  12069. j = a->li_base + MIXER_IC_CHANNEL_BASE + (plci->li_bchannel_id - 1);
  12070. k = a->li_base + MIXER_IC_CHANNEL_BASE + (2 - plci->li_bchannel_id);
  12071. if (!(plci->B1_facilities & B1_FACILITY_MIXER))
  12072. {
  12073. li_config_table[j].flag_table[i] |= LI_FLAG_CONFERENCE | LI_FLAG_MIX;
  12074. li_config_table[i].flag_table[j] |= LI_FLAG_CONFERENCE | LI_FLAG_MONITOR;
  12075. }
  12076. if (a->manufacturer_features & MANUFACTURER_FEATURE_SLAVE_CODEC)
  12077. {
  12078. li_config_table[k].flag_table[i] |= LI_FLAG_CONFERENCE | LI_FLAG_MIX;
  12079. li_config_table[i].flag_table[k] |= LI_FLAG_CONFERENCE | LI_FLAG_MONITOR;
  12080. li_config_table[k].flag_table[j] |= LI_FLAG_CONFERENCE;
  12081. li_config_table[j].flag_table[k] |= LI_FLAG_CONFERENCE;
  12082. }
  12083. mixer_calculate_coefs (a);
  12084. li_config_table[i].curchnl = li_config_table[i].channel;
  12085. li_config_table[j].curchnl = li_config_table[j].channel;
  12086. if (a->manufacturer_features & MANUFACTURER_FEATURE_SLAVE_CODEC)
  12087. li_config_table[k].curchnl = li_config_table[k].channel;
  12088. break;
  12089. case ADV_VOICE_WRITE_DEACTIVATION:
  12090. for (j = 0; j < li_total_channels; j++)
  12091. {
  12092. li_config_table[i].flag_table[j] = 0;
  12093. li_config_table[j].flag_table[i] = 0;
  12094. }
  12095. k = a->li_base + MIXER_IC_CHANNEL_BASE + (plci->li_bchannel_id - 1);
  12096. for (j = 0; j < li_total_channels; j++)
  12097. {
  12098. li_config_table[k].flag_table[j] = 0;
  12099. li_config_table[j].flag_table[k] = 0;
  12100. }
  12101. if (a->manufacturer_features & MANUFACTURER_FEATURE_SLAVE_CODEC)
  12102. {
  12103. k = a->li_base + MIXER_IC_CHANNEL_BASE + (2 - plci->li_bchannel_id);
  12104. for (j = 0; j < li_total_channels; j++)
  12105. {
  12106. li_config_table[k].flag_table[j] = 0;
  12107. li_config_table[j].flag_table[k] = 0;
  12108. }
  12109. }
  12110. mixer_calculate_coefs (a);
  12111. break;
  12112. }
  12113. if (plci->B1_facilities & B1_FACILITY_MIXER)
  12114. {
  12115. w = 0;
  12116. if (ADV_VOICE_NEW_COEF_BASE + sizeof(word) <= a->adv_voice_coef_length)
  12117. w = GET_WORD (a->adv_voice_coef_buffer + ADV_VOICE_NEW_COEF_BASE);
  12118. if (li_config_table[i].channel & LI_CHANNEL_TX_DATA)
  12119. w |= MIXER_FEATURE_ENABLE_TX_DATA;
  12120. if (li_config_table[i].channel & LI_CHANNEL_RX_DATA)
  12121. w |= MIXER_FEATURE_ENABLE_RX_DATA;
  12122. *(p++) = (byte) w;
  12123. *(p++) = (byte)(w >> 8);
  12124. for (j = 0; j < sizeof(ch_map); j += 2)
  12125. {
  12126. ch_map[j] = (byte)(j + (plci->li_bchannel_id - 1));
  12127. ch_map[j+1] = (byte)(j + (2 - plci->li_bchannel_id));
  12128. }
  12129. for (n = 0; n < ARRAY_SIZE(mixer_write_prog_bri); n++)
  12130. {
  12131. i = a->li_base + ch_map[mixer_write_prog_bri[n].to_ch];
  12132. j = a->li_base + ch_map[mixer_write_prog_bri[n].from_ch];
  12133. if (li_config_table[i].channel & li_config_table[j].channel & LI_CHANNEL_INVOLVED)
  12134. {
  12135. *(p++) = ((li_config_table[i].coef_table[j] & mixer_write_prog_bri[n].mask) ? 0x80 : 0x01);
  12136. w = ((li_config_table[i].coef_table[j] & 0xf) ^ (li_config_table[i].coef_table[j] >> 4));
  12137. li_config_table[i].coef_table[j] ^= (w & mixer_write_prog_bri[n].mask) << 4;
  12138. }
  12139. else
  12140. {
  12141. *(p++) = (ADV_VOICE_NEW_COEF_BASE + sizeof(word) + n < a->adv_voice_coef_length) ?
  12142. a->adv_voice_coef_buffer[ADV_VOICE_NEW_COEF_BASE + sizeof(word) + n] : 0x00;
  12143. }
  12144. }
  12145. }
  12146. else
  12147. {
  12148. for (i = ADV_VOICE_NEW_COEF_BASE; i < a->adv_voice_coef_length; i++)
  12149. *(p++) = a->adv_voice_coef_buffer[i];
  12150. }
  12151. }
  12152. else
  12153. {
  12154. for (i = ADV_VOICE_NEW_COEF_BASE; i < a->adv_voice_coef_length; i++)
  12155. *(p++) = a->adv_voice_coef_buffer[i];
  12156. }
  12157. coef_buffer[0] = (p - coef_buffer) - 1;
  12158. add_p (plci, FTY, coef_buffer);
  12159. sig_req (plci, TEL_CTRL, 0);
  12160. send_req (plci);
  12161. }
  12162. static void adv_voice_clear_config (PLCI *plci)
  12163. {
  12164. DIVA_CAPI_ADAPTER *a;
  12165. word i, j;
  12166. dbug (1, dprintf ("[%06lx] %s,%d: adv_voice_clear_config",
  12167. (dword)((plci->Id << 8) | UnMapController (plci->adapter->Id)),
  12168. (char *)(FILE_), __LINE__));
  12169. a = plci->adapter;
  12170. if ((plci->tel == ADV_VOICE) && (plci == a->AdvSignalPLCI))
  12171. {
  12172. a->adv_voice_coef_length = 0;
  12173. if (!a->li_pri && (plci->li_bchannel_id != 0)
  12174. && (li_config_table[a->li_base + (plci->li_bchannel_id - 1)].plci == plci))
  12175. {
  12176. i = a->li_base + (plci->li_bchannel_id - 1);
  12177. li_config_table[i].curchnl = 0;
  12178. li_config_table[i].channel = 0;
  12179. li_config_table[i].chflags = 0;
  12180. for (j = 0; j < li_total_channels; j++)
  12181. {
  12182. li_config_table[i].flag_table[j] = 0;
  12183. li_config_table[j].flag_table[i] = 0;
  12184. li_config_table[i].coef_table[j] = 0;
  12185. li_config_table[j].coef_table[i] = 0;
  12186. }
  12187. li_config_table[i].coef_table[i] |= LI_COEF_CH_PC_SET | LI_COEF_PC_CH_SET;
  12188. i = a->li_base + MIXER_IC_CHANNEL_BASE + (plci->li_bchannel_id - 1);
  12189. li_config_table[i].curchnl = 0;
  12190. li_config_table[i].channel = 0;
  12191. li_config_table[i].chflags = 0;
  12192. for (j = 0; j < li_total_channels; j++)
  12193. {
  12194. li_config_table[i].flag_table[j] = 0;
  12195. li_config_table[j].flag_table[i] = 0;
  12196. li_config_table[i].coef_table[j] = 0;
  12197. li_config_table[j].coef_table[i] = 0;
  12198. }
  12199. if (a->manufacturer_features & MANUFACTURER_FEATURE_SLAVE_CODEC)
  12200. {
  12201. i = a->li_base + MIXER_IC_CHANNEL_BASE + (2 - plci->li_bchannel_id);
  12202. li_config_table[i].curchnl = 0;
  12203. li_config_table[i].channel = 0;
  12204. li_config_table[i].chflags = 0;
  12205. for (j = 0; j < li_total_channels; j++)
  12206. {
  12207. li_config_table[i].flag_table[j] = 0;
  12208. li_config_table[j].flag_table[i] = 0;
  12209. li_config_table[i].coef_table[j] = 0;
  12210. li_config_table[j].coef_table[i] = 0;
  12211. }
  12212. }
  12213. }
  12214. }
  12215. }
  12216. static void adv_voice_prepare_switch (dword Id, PLCI *plci)
  12217. {
  12218. dbug (1, dprintf ("[%06lx] %s,%d: adv_voice_prepare_switch",
  12219. UnMapId (Id), (char *)(FILE_), __LINE__));
  12220. }
  12221. static word adv_voice_save_config (dword Id, PLCI *plci, byte Rc)
  12222. {
  12223. dbug (1, dprintf ("[%06lx] %s,%d: adv_voice_save_config %02x %d",
  12224. UnMapId (Id), (char *)(FILE_), __LINE__, Rc, plci->adjust_b_state));
  12225. return (GOOD);
  12226. }
  12227. static word adv_voice_restore_config (dword Id, PLCI *plci, byte Rc)
  12228. {
  12229. DIVA_CAPI_ADAPTER *a;
  12230. word Info;
  12231. dbug (1, dprintf ("[%06lx] %s,%d: adv_voice_restore_config %02x %d",
  12232. UnMapId (Id), (char *)(FILE_), __LINE__, Rc, plci->adjust_b_state));
  12233. Info = GOOD;
  12234. a = plci->adapter;
  12235. if ((plci->B1_facilities & B1_FACILITY_VOICE)
  12236. && (plci->tel == ADV_VOICE) && (plci == a->AdvSignalPLCI))
  12237. {
  12238. switch (plci->adjust_b_state)
  12239. {
  12240. case ADJUST_B_RESTORE_VOICE_1:
  12241. plci->internal_command = plci->adjust_b_command;
  12242. if (plci->sig_req)
  12243. {
  12244. plci->adjust_b_state = ADJUST_B_RESTORE_VOICE_1;
  12245. break;
  12246. }
  12247. adv_voice_write_coefs (plci, ADV_VOICE_WRITE_UPDATE);
  12248. plci->adjust_b_state = ADJUST_B_RESTORE_VOICE_2;
  12249. break;
  12250. case ADJUST_B_RESTORE_VOICE_2:
  12251. if ((Rc != OK) && (Rc != OK_FC))
  12252. {
  12253. dbug (1, dprintf ("[%06lx] %s,%d: Restore voice config failed %02x",
  12254. UnMapId (Id), (char *)(FILE_), __LINE__, Rc));
  12255. Info = _WRONG_STATE;
  12256. break;
  12257. }
  12258. break;
  12259. }
  12260. }
  12261. return (Info);
  12262. }
  12263. /*------------------------------------------------------------------*/
  12264. /* B1 resource switching */
  12265. /*------------------------------------------------------------------*/
  12266. static byte b1_facilities_table[] =
  12267. {
  12268. 0x00, /* 0 No bchannel resources */
  12269. 0x00, /* 1 Codec (automatic law) */
  12270. 0x00, /* 2 Codec (A-law) */
  12271. 0x00, /* 3 Codec (y-law) */
  12272. 0x00, /* 4 HDLC for X.21 */
  12273. 0x00, /* 5 HDLC */
  12274. 0x00, /* 6 External Device 0 */
  12275. 0x00, /* 7 External Device 1 */
  12276. 0x00, /* 8 HDLC 56k */
  12277. 0x00, /* 9 Transparent */
  12278. 0x00, /* 10 Loopback to network */
  12279. 0x00, /* 11 Test pattern to net */
  12280. 0x00, /* 12 Rate adaptation sync */
  12281. 0x00, /* 13 Rate adaptation async */
  12282. 0x00, /* 14 R-Interface */
  12283. 0x00, /* 15 HDLC 128k leased line */
  12284. 0x00, /* 16 FAX */
  12285. 0x00, /* 17 Modem async */
  12286. 0x00, /* 18 Modem sync HDLC */
  12287. 0x00, /* 19 V.110 async HDLC */
  12288. 0x12, /* 20 Adv voice (Trans,mixer) */
  12289. 0x00, /* 21 Codec connected to IC */
  12290. 0x0c, /* 22 Trans,DTMF */
  12291. 0x1e, /* 23 Trans,DTMF+mixer */
  12292. 0x1f, /* 24 Trans,DTMF+mixer+local */
  12293. 0x13, /* 25 Trans,mixer+local */
  12294. 0x12, /* 26 HDLC,mixer */
  12295. 0x12, /* 27 HDLC 56k,mixer */
  12296. 0x2c, /* 28 Trans,LEC+DTMF */
  12297. 0x3e, /* 29 Trans,LEC+DTMF+mixer */
  12298. 0x3f, /* 30 Trans,LEC+DTMF+mixer+local */
  12299. 0x2c, /* 31 RTP,LEC+DTMF */
  12300. 0x3e, /* 32 RTP,LEC+DTMF+mixer */
  12301. 0x3f, /* 33 RTP,LEC+DTMF+mixer+local */
  12302. 0x00, /* 34 Signaling task */
  12303. 0x00, /* 35 PIAFS */
  12304. 0x0c, /* 36 Trans,DTMF+TONE */
  12305. 0x1e, /* 37 Trans,DTMF+TONE+mixer */
  12306. 0x1f /* 38 Trans,DTMF+TONE+mixer+local*/
  12307. };
  12308. static word get_b1_facilities (PLCI * plci, byte b1_resource)
  12309. {
  12310. word b1_facilities;
  12311. b1_facilities = b1_facilities_table[b1_resource];
  12312. if ((b1_resource == 9) || (b1_resource == 20) || (b1_resource == 25))
  12313. {
  12314. if (!(((plci->requested_options_conn | plci->requested_options) & (1L << PRIVATE_DTMF_TONE))
  12315. || (plci->appl && (plci->adapter->requested_options_table[plci->appl->Id-1] & (1L << PRIVATE_DTMF_TONE)))))
  12316. {
  12317. if (plci->adapter->manufacturer_features & MANUFACTURER_FEATURE_SOFTDTMF_SEND)
  12318. b1_facilities |= B1_FACILITY_DTMFX;
  12319. if (plci->adapter->manufacturer_features & MANUFACTURER_FEATURE_SOFTDTMF_RECEIVE)
  12320. b1_facilities |= B1_FACILITY_DTMFR;
  12321. }
  12322. }
  12323. if ((b1_resource == 17) || (b1_resource == 18))
  12324. {
  12325. if (plci->adapter->manufacturer_features & (MANUFACTURER_FEATURE_V18 | MANUFACTURER_FEATURE_VOWN))
  12326. b1_facilities |= B1_FACILITY_DTMFX | B1_FACILITY_DTMFR;
  12327. }
  12328. /*
  12329. dbug (1, dprintf ("[%06lx] %s,%d: get_b1_facilities %d %04x",
  12330. (dword)((plci->Id << 8) | UnMapController (plci->adapter->Id)),
  12331. (char far *)(FILE_), __LINE__, b1_resource, b1_facilites));
  12332. */
  12333. return (b1_facilities);
  12334. }
  12335. static byte add_b1_facilities (PLCI * plci, byte b1_resource, word b1_facilities)
  12336. {
  12337. byte b;
  12338. switch (b1_resource)
  12339. {
  12340. case 5:
  12341. case 26:
  12342. if (b1_facilities & (B1_FACILITY_MIXER | B1_FACILITY_VOICE))
  12343. b = 26;
  12344. else
  12345. b = 5;
  12346. break;
  12347. case 8:
  12348. case 27:
  12349. if (b1_facilities & (B1_FACILITY_MIXER | B1_FACILITY_VOICE))
  12350. b = 27;
  12351. else
  12352. b = 8;
  12353. break;
  12354. case 9:
  12355. case 20:
  12356. case 22:
  12357. case 23:
  12358. case 24:
  12359. case 25:
  12360. case 28:
  12361. case 29:
  12362. case 30:
  12363. case 36:
  12364. case 37:
  12365. case 38:
  12366. if (b1_facilities & B1_FACILITY_EC)
  12367. {
  12368. if (b1_facilities & B1_FACILITY_LOCAL)
  12369. b = 30;
  12370. else if (b1_facilities & (B1_FACILITY_MIXER | B1_FACILITY_VOICE))
  12371. b = 29;
  12372. else
  12373. b = 28;
  12374. }
  12375. else if ((b1_facilities & (B1_FACILITY_DTMFX | B1_FACILITY_DTMFR | B1_FACILITY_MIXER))
  12376. && (((plci->requested_options_conn | plci->requested_options) & (1L << PRIVATE_DTMF_TONE))
  12377. || (plci->appl && (plci->adapter->requested_options_table[plci->appl->Id-1] & (1L << PRIVATE_DTMF_TONE)))))
  12378. {
  12379. if (b1_facilities & B1_FACILITY_LOCAL)
  12380. b = 38;
  12381. else if (b1_facilities & (B1_FACILITY_MIXER | B1_FACILITY_VOICE))
  12382. b = 37;
  12383. else
  12384. b = 36;
  12385. }
  12386. else if (((plci->adapter->manufacturer_features & MANUFACTURER_FEATURE_HARDDTMF)
  12387. && !(plci->adapter->manufacturer_features & MANUFACTURER_FEATURE_SOFTDTMF_RECEIVE))
  12388. || ((b1_facilities & B1_FACILITY_DTMFR)
  12389. && ((b1_facilities & B1_FACILITY_MIXER)
  12390. || !(plci->adapter->manufacturer_features & MANUFACTURER_FEATURE_SOFTDTMF_RECEIVE)))
  12391. || ((b1_facilities & B1_FACILITY_DTMFX)
  12392. && ((b1_facilities & B1_FACILITY_MIXER)
  12393. || !(plci->adapter->manufacturer_features & MANUFACTURER_FEATURE_SOFTDTMF_SEND))))
  12394. {
  12395. if (b1_facilities & B1_FACILITY_LOCAL)
  12396. b = 24;
  12397. else if (b1_facilities & (B1_FACILITY_MIXER | B1_FACILITY_VOICE))
  12398. b = 23;
  12399. else
  12400. b = 22;
  12401. }
  12402. else
  12403. {
  12404. if (b1_facilities & B1_FACILITY_LOCAL)
  12405. b = 25;
  12406. else if (b1_facilities & (B1_FACILITY_MIXER | B1_FACILITY_VOICE))
  12407. b = 20;
  12408. else
  12409. b = 9;
  12410. }
  12411. break;
  12412. case 31:
  12413. case 32:
  12414. case 33:
  12415. if (b1_facilities & B1_FACILITY_LOCAL)
  12416. b = 33;
  12417. else if (b1_facilities & (B1_FACILITY_MIXER | B1_FACILITY_VOICE))
  12418. b = 32;
  12419. else
  12420. b = 31;
  12421. break;
  12422. default:
  12423. b = b1_resource;
  12424. }
  12425. dbug (1, dprintf ("[%06lx] %s,%d: add_b1_facilities %d %04x %d %04x",
  12426. (dword)((plci->Id << 8) | UnMapController (plci->adapter->Id)),
  12427. (char *)(FILE_), __LINE__,
  12428. b1_resource, b1_facilities, b, get_b1_facilities (plci, b)));
  12429. return (b);
  12430. }
  12431. static void adjust_b1_facilities (PLCI *plci, byte new_b1_resource, word new_b1_facilities)
  12432. {
  12433. word removed_facilities;
  12434. dbug (1, dprintf ("[%06lx] %s,%d: adjust_b1_facilities %d %04x %04x",
  12435. (dword)((plci->Id << 8) | UnMapController (plci->adapter->Id)),
  12436. (char *)(FILE_), __LINE__, new_b1_resource, new_b1_facilities,
  12437. new_b1_facilities & get_b1_facilities (plci, new_b1_resource)));
  12438. new_b1_facilities &= get_b1_facilities (plci, new_b1_resource);
  12439. removed_facilities = plci->B1_facilities & ~new_b1_facilities;
  12440. if (removed_facilities & B1_FACILITY_EC)
  12441. ec_clear_config (plci);
  12442. if (removed_facilities & B1_FACILITY_DTMFR)
  12443. {
  12444. dtmf_rec_clear_config (plci);
  12445. dtmf_parameter_clear_config (plci);
  12446. }
  12447. if (removed_facilities & B1_FACILITY_DTMFX)
  12448. dtmf_send_clear_config (plci);
  12449. if (removed_facilities & B1_FACILITY_MIXER)
  12450. mixer_clear_config (plci);
  12451. if (removed_facilities & B1_FACILITY_VOICE)
  12452. adv_voice_clear_config (plci);
  12453. plci->B1_facilities = new_b1_facilities;
  12454. }
  12455. static void adjust_b_clear (PLCI *plci)
  12456. {
  12457. dbug (1, dprintf ("[%06lx] %s,%d: adjust_b_clear",
  12458. (dword)((plci->Id << 8) | UnMapController (plci->adapter->Id)),
  12459. (char *)(FILE_), __LINE__));
  12460. plci->adjust_b_restore = false;
  12461. }
  12462. static word adjust_b_process (dword Id, PLCI *plci, byte Rc)
  12463. {
  12464. word Info;
  12465. byte b1_resource;
  12466. NCCI * ncci_ptr;
  12467. API_PARSE bp[2];
  12468. dbug (1, dprintf ("[%06lx] %s,%d: adjust_b_process %02x %d",
  12469. UnMapId (Id), (char *)(FILE_), __LINE__, Rc, plci->adjust_b_state));
  12470. Info = GOOD;
  12471. switch (plci->adjust_b_state)
  12472. {
  12473. case ADJUST_B_START:
  12474. if ((plci->adjust_b_parms_msg == NULL)
  12475. && (plci->adjust_b_mode & ADJUST_B_MODE_SWITCH_L1)
  12476. && ((plci->adjust_b_mode & ~(ADJUST_B_MODE_SAVE | ADJUST_B_MODE_SWITCH_L1 |
  12477. ADJUST_B_MODE_NO_RESOURCE | ADJUST_B_MODE_RESTORE)) == 0))
  12478. {
  12479. b1_resource = (plci->adjust_b_mode == ADJUST_B_MODE_NO_RESOURCE) ?
  12480. 0 : add_b1_facilities (plci, plci->B1_resource, plci->adjust_b_facilities);
  12481. if (b1_resource == plci->B1_resource)
  12482. {
  12483. adjust_b1_facilities (plci, b1_resource, plci->adjust_b_facilities);
  12484. break;
  12485. }
  12486. if (plci->adjust_b_facilities & ~get_b1_facilities (plci, b1_resource))
  12487. {
  12488. dbug (1, dprintf ("[%06lx] %s,%d: Adjust B nonsupported facilities %d %d %04x",
  12489. UnMapId (Id), (char *)(FILE_), __LINE__,
  12490. plci->B1_resource, b1_resource, plci->adjust_b_facilities));
  12491. Info = _WRONG_STATE;
  12492. break;
  12493. }
  12494. }
  12495. if (plci->adjust_b_mode & ADJUST_B_MODE_SAVE)
  12496. {
  12497. mixer_prepare_switch (Id, plci);
  12498. dtmf_prepare_switch (Id, plci);
  12499. dtmf_parameter_prepare_switch (Id, plci);
  12500. ec_prepare_switch (Id, plci);
  12501. adv_voice_prepare_switch (Id, plci);
  12502. }
  12503. plci->adjust_b_state = ADJUST_B_SAVE_MIXER_1;
  12504. Rc = OK;
  12505. case ADJUST_B_SAVE_MIXER_1:
  12506. if (plci->adjust_b_mode & ADJUST_B_MODE_SAVE)
  12507. {
  12508. Info = mixer_save_config (Id, plci, Rc);
  12509. if ((Info != GOOD) || plci->internal_command)
  12510. break;
  12511. }
  12512. plci->adjust_b_state = ADJUST_B_SAVE_DTMF_1;
  12513. Rc = OK;
  12514. case ADJUST_B_SAVE_DTMF_1:
  12515. if (plci->adjust_b_mode & ADJUST_B_MODE_SAVE)
  12516. {
  12517. Info = dtmf_save_config (Id, plci, Rc);
  12518. if ((Info != GOOD) || plci->internal_command)
  12519. break;
  12520. }
  12521. plci->adjust_b_state = ADJUST_B_REMOVE_L23_1;
  12522. case ADJUST_B_REMOVE_L23_1:
  12523. if ((plci->adjust_b_mode & ADJUST_B_MODE_REMOVE_L23)
  12524. && plci->NL.Id && !plci->nl_remove_id)
  12525. {
  12526. plci->internal_command = plci->adjust_b_command;
  12527. if (plci->adjust_b_ncci != 0)
  12528. {
  12529. ncci_ptr = &(plci->adapter->ncci[plci->adjust_b_ncci]);
  12530. while (ncci_ptr->data_pending)
  12531. {
  12532. plci->data_sent_ptr = ncci_ptr->DBuffer[ncci_ptr->data_out].P;
  12533. data_rc (plci, plci->adapter->ncci_ch[plci->adjust_b_ncci]);
  12534. }
  12535. while (ncci_ptr->data_ack_pending)
  12536. data_ack (plci, plci->adapter->ncci_ch[plci->adjust_b_ncci]);
  12537. }
  12538. nl_req_ncci (plci, REMOVE,
  12539. (byte)((plci->adjust_b_mode & ADJUST_B_MODE_CONNECT) ? plci->adjust_b_ncci : 0));
  12540. send_req (plci);
  12541. plci->adjust_b_state = ADJUST_B_REMOVE_L23_2;
  12542. break;
  12543. }
  12544. plci->adjust_b_state = ADJUST_B_REMOVE_L23_2;
  12545. Rc = OK;
  12546. case ADJUST_B_REMOVE_L23_2:
  12547. if ((Rc != OK) && (Rc != OK_FC))
  12548. {
  12549. dbug (1, dprintf ("[%06lx] %s,%d: Adjust B remove failed %02x",
  12550. UnMapId (Id), (char *)(FILE_), __LINE__, Rc));
  12551. Info = _WRONG_STATE;
  12552. break;
  12553. }
  12554. if (plci->adjust_b_mode & ADJUST_B_MODE_REMOVE_L23)
  12555. {
  12556. if (plci_nl_busy (plci))
  12557. {
  12558. plci->internal_command = plci->adjust_b_command;
  12559. break;
  12560. }
  12561. }
  12562. plci->adjust_b_state = ADJUST_B_SAVE_EC_1;
  12563. Rc = OK;
  12564. case ADJUST_B_SAVE_EC_1:
  12565. if (plci->adjust_b_mode & ADJUST_B_MODE_SAVE)
  12566. {
  12567. Info = ec_save_config (Id, plci, Rc);
  12568. if ((Info != GOOD) || plci->internal_command)
  12569. break;
  12570. }
  12571. plci->adjust_b_state = ADJUST_B_SAVE_DTMF_PARAMETER_1;
  12572. Rc = OK;
  12573. case ADJUST_B_SAVE_DTMF_PARAMETER_1:
  12574. if (plci->adjust_b_mode & ADJUST_B_MODE_SAVE)
  12575. {
  12576. Info = dtmf_parameter_save_config (Id, plci, Rc);
  12577. if ((Info != GOOD) || plci->internal_command)
  12578. break;
  12579. }
  12580. plci->adjust_b_state = ADJUST_B_SAVE_VOICE_1;
  12581. Rc = OK;
  12582. case ADJUST_B_SAVE_VOICE_1:
  12583. if (plci->adjust_b_mode & ADJUST_B_MODE_SAVE)
  12584. {
  12585. Info = adv_voice_save_config (Id, plci, Rc);
  12586. if ((Info != GOOD) || plci->internal_command)
  12587. break;
  12588. }
  12589. plci->adjust_b_state = ADJUST_B_SWITCH_L1_1;
  12590. case ADJUST_B_SWITCH_L1_1:
  12591. if (plci->adjust_b_mode & ADJUST_B_MODE_SWITCH_L1)
  12592. {
  12593. if (plci->sig_req)
  12594. {
  12595. plci->internal_command = plci->adjust_b_command;
  12596. break;
  12597. }
  12598. if (plci->adjust_b_parms_msg != NULL)
  12599. api_load_msg (plci->adjust_b_parms_msg, bp);
  12600. else
  12601. api_load_msg (&plci->B_protocol, bp);
  12602. Info = add_b1 (plci, bp,
  12603. (word)((plci->adjust_b_mode & ADJUST_B_MODE_NO_RESOURCE) ? 2 : 0),
  12604. plci->adjust_b_facilities);
  12605. if (Info != GOOD)
  12606. {
  12607. dbug (1, dprintf ("[%06lx] %s,%d: Adjust B invalid L1 parameters %d %04x",
  12608. UnMapId (Id), (char *)(FILE_), __LINE__,
  12609. plci->B1_resource, plci->adjust_b_facilities));
  12610. break;
  12611. }
  12612. plci->internal_command = plci->adjust_b_command;
  12613. sig_req (plci, RESOURCES, 0);
  12614. send_req (plci);
  12615. plci->adjust_b_state = ADJUST_B_SWITCH_L1_2;
  12616. break;
  12617. }
  12618. plci->adjust_b_state = ADJUST_B_SWITCH_L1_2;
  12619. Rc = OK;
  12620. case ADJUST_B_SWITCH_L1_2:
  12621. if ((Rc != OK) && (Rc != OK_FC))
  12622. {
  12623. dbug (1, dprintf ("[%06lx] %s,%d: Adjust B switch failed %02x %d %04x",
  12624. UnMapId (Id), (char *)(FILE_), __LINE__,
  12625. Rc, plci->B1_resource, plci->adjust_b_facilities));
  12626. Info = _WRONG_STATE;
  12627. break;
  12628. }
  12629. plci->adjust_b_state = ADJUST_B_RESTORE_VOICE_1;
  12630. Rc = OK;
  12631. case ADJUST_B_RESTORE_VOICE_1:
  12632. case ADJUST_B_RESTORE_VOICE_2:
  12633. if (plci->adjust_b_mode & ADJUST_B_MODE_RESTORE)
  12634. {
  12635. Info = adv_voice_restore_config (Id, plci, Rc);
  12636. if ((Info != GOOD) || plci->internal_command)
  12637. break;
  12638. }
  12639. plci->adjust_b_state = ADJUST_B_RESTORE_DTMF_PARAMETER_1;
  12640. Rc = OK;
  12641. case ADJUST_B_RESTORE_DTMF_PARAMETER_1:
  12642. case ADJUST_B_RESTORE_DTMF_PARAMETER_2:
  12643. if (plci->adjust_b_mode & ADJUST_B_MODE_RESTORE)
  12644. {
  12645. Info = dtmf_parameter_restore_config (Id, plci, Rc);
  12646. if ((Info != GOOD) || plci->internal_command)
  12647. break;
  12648. }
  12649. plci->adjust_b_state = ADJUST_B_RESTORE_EC_1;
  12650. Rc = OK;
  12651. case ADJUST_B_RESTORE_EC_1:
  12652. case ADJUST_B_RESTORE_EC_2:
  12653. if (plci->adjust_b_mode & ADJUST_B_MODE_RESTORE)
  12654. {
  12655. Info = ec_restore_config (Id, plci, Rc);
  12656. if ((Info != GOOD) || plci->internal_command)
  12657. break;
  12658. }
  12659. plci->adjust_b_state = ADJUST_B_ASSIGN_L23_1;
  12660. case ADJUST_B_ASSIGN_L23_1:
  12661. if (plci->adjust_b_mode & ADJUST_B_MODE_ASSIGN_L23)
  12662. {
  12663. if (plci_nl_busy (plci))
  12664. {
  12665. plci->internal_command = plci->adjust_b_command;
  12666. break;
  12667. }
  12668. if (plci->adjust_b_mode & ADJUST_B_MODE_CONNECT)
  12669. plci->call_dir |= CALL_DIR_FORCE_OUTG_NL;
  12670. if (plci->adjust_b_parms_msg != NULL)
  12671. api_load_msg (plci->adjust_b_parms_msg, bp);
  12672. else
  12673. api_load_msg (&plci->B_protocol, bp);
  12674. Info = add_b23 (plci, bp);
  12675. if (Info != GOOD)
  12676. {
  12677. dbug (1, dprintf ("[%06lx] %s,%d: Adjust B invalid L23 parameters %04x",
  12678. UnMapId (Id), (char *)(FILE_), __LINE__, Info));
  12679. break;
  12680. }
  12681. plci->internal_command = plci->adjust_b_command;
  12682. nl_req_ncci (plci, ASSIGN, 0);
  12683. send_req (plci);
  12684. plci->adjust_b_state = ADJUST_B_ASSIGN_L23_2;
  12685. break;
  12686. }
  12687. plci->adjust_b_state = ADJUST_B_ASSIGN_L23_2;
  12688. Rc = ASSIGN_OK;
  12689. case ADJUST_B_ASSIGN_L23_2:
  12690. if ((Rc != OK) && (Rc != OK_FC) && (Rc != ASSIGN_OK))
  12691. {
  12692. dbug (1, dprintf ("[%06lx] %s,%d: Adjust B assign failed %02x",
  12693. UnMapId (Id), (char *)(FILE_), __LINE__, Rc));
  12694. Info = _WRONG_STATE;
  12695. break;
  12696. }
  12697. if (plci->adjust_b_mode & ADJUST_B_MODE_ASSIGN_L23)
  12698. {
  12699. if (Rc != ASSIGN_OK)
  12700. {
  12701. plci->internal_command = plci->adjust_b_command;
  12702. break;
  12703. }
  12704. }
  12705. if (plci->adjust_b_mode & ADJUST_B_MODE_USER_CONNECT)
  12706. {
  12707. plci->adjust_b_restore = true;
  12708. break;
  12709. }
  12710. plci->adjust_b_state = ADJUST_B_CONNECT_1;
  12711. case ADJUST_B_CONNECT_1:
  12712. if (plci->adjust_b_mode & ADJUST_B_MODE_CONNECT)
  12713. {
  12714. plci->internal_command = plci->adjust_b_command;
  12715. if (plci_nl_busy (plci))
  12716. break;
  12717. nl_req_ncci (plci, N_CONNECT, 0);
  12718. send_req (plci);
  12719. plci->adjust_b_state = ADJUST_B_CONNECT_2;
  12720. break;
  12721. }
  12722. plci->adjust_b_state = ADJUST_B_RESTORE_DTMF_1;
  12723. Rc = OK;
  12724. case ADJUST_B_CONNECT_2:
  12725. case ADJUST_B_CONNECT_3:
  12726. case ADJUST_B_CONNECT_4:
  12727. if ((Rc != OK) && (Rc != OK_FC) && (Rc != 0))
  12728. {
  12729. dbug (1, dprintf ("[%06lx] %s,%d: Adjust B connect failed %02x",
  12730. UnMapId (Id), (char *)(FILE_), __LINE__, Rc));
  12731. Info = _WRONG_STATE;
  12732. break;
  12733. }
  12734. if (Rc == OK)
  12735. {
  12736. if (plci->adjust_b_mode & ADJUST_B_MODE_CONNECT)
  12737. {
  12738. get_ncci (plci, (byte)(Id >> 16), plci->adjust_b_ncci);
  12739. Id = (Id & 0xffff) | (((dword)(plci->adjust_b_ncci)) << 16);
  12740. }
  12741. if (plci->adjust_b_state == ADJUST_B_CONNECT_2)
  12742. plci->adjust_b_state = ADJUST_B_CONNECT_3;
  12743. else if (plci->adjust_b_state == ADJUST_B_CONNECT_4)
  12744. plci->adjust_b_state = ADJUST_B_RESTORE_DTMF_1;
  12745. }
  12746. else if (Rc == 0)
  12747. {
  12748. if (plci->adjust_b_state == ADJUST_B_CONNECT_2)
  12749. plci->adjust_b_state = ADJUST_B_CONNECT_4;
  12750. else if (plci->adjust_b_state == ADJUST_B_CONNECT_3)
  12751. plci->adjust_b_state = ADJUST_B_RESTORE_DTMF_1;
  12752. }
  12753. if (plci->adjust_b_state != ADJUST_B_RESTORE_DTMF_1)
  12754. {
  12755. plci->internal_command = plci->adjust_b_command;
  12756. break;
  12757. }
  12758. Rc = OK;
  12759. case ADJUST_B_RESTORE_DTMF_1:
  12760. case ADJUST_B_RESTORE_DTMF_2:
  12761. if (plci->adjust_b_mode & ADJUST_B_MODE_RESTORE)
  12762. {
  12763. Info = dtmf_restore_config (Id, plci, Rc);
  12764. if ((Info != GOOD) || plci->internal_command)
  12765. break;
  12766. }
  12767. plci->adjust_b_state = ADJUST_B_RESTORE_MIXER_1;
  12768. Rc = OK;
  12769. case ADJUST_B_RESTORE_MIXER_1:
  12770. case ADJUST_B_RESTORE_MIXER_2:
  12771. case ADJUST_B_RESTORE_MIXER_3:
  12772. case ADJUST_B_RESTORE_MIXER_4:
  12773. case ADJUST_B_RESTORE_MIXER_5:
  12774. case ADJUST_B_RESTORE_MIXER_6:
  12775. case ADJUST_B_RESTORE_MIXER_7:
  12776. if (plci->adjust_b_mode & ADJUST_B_MODE_RESTORE)
  12777. {
  12778. Info = mixer_restore_config (Id, plci, Rc);
  12779. if ((Info != GOOD) || plci->internal_command)
  12780. break;
  12781. }
  12782. plci->adjust_b_state = ADJUST_B_END;
  12783. case ADJUST_B_END:
  12784. break;
  12785. }
  12786. return (Info);
  12787. }
  12788. static void adjust_b1_resource (dword Id, PLCI *plci, API_SAVE *bp_msg, word b1_facilities, word internal_command)
  12789. {
  12790. dbug (1, dprintf ("[%06lx] %s,%d: adjust_b1_resource %d %04x",
  12791. UnMapId (Id), (char *)(FILE_), __LINE__,
  12792. plci->B1_resource, b1_facilities));
  12793. plci->adjust_b_parms_msg = bp_msg;
  12794. plci->adjust_b_facilities = b1_facilities;
  12795. plci->adjust_b_command = internal_command;
  12796. plci->adjust_b_ncci = (word)(Id >> 16);
  12797. if ((bp_msg == NULL) && (plci->B1_resource == 0))
  12798. plci->adjust_b_mode = ADJUST_B_MODE_SAVE | ADJUST_B_MODE_NO_RESOURCE | ADJUST_B_MODE_SWITCH_L1;
  12799. else
  12800. plci->adjust_b_mode = ADJUST_B_MODE_SAVE | ADJUST_B_MODE_SWITCH_L1 | ADJUST_B_MODE_RESTORE;
  12801. plci->adjust_b_state = ADJUST_B_START;
  12802. dbug (1, dprintf ("[%06lx] %s,%d: Adjust B1 resource %d %04x...",
  12803. UnMapId (Id), (char *)(FILE_), __LINE__,
  12804. plci->B1_resource, b1_facilities));
  12805. }
  12806. static void adjust_b_restore (dword Id, PLCI *plci, byte Rc)
  12807. {
  12808. word internal_command;
  12809. dbug (1, dprintf ("[%06lx] %s,%d: adjust_b_restore %02x %04x",
  12810. UnMapId (Id), (char *)(FILE_), __LINE__, Rc, plci->internal_command));
  12811. internal_command = plci->internal_command;
  12812. plci->internal_command = 0;
  12813. switch (internal_command)
  12814. {
  12815. default:
  12816. plci->command = 0;
  12817. if (plci->req_in != 0)
  12818. {
  12819. plci->internal_command = ADJUST_B_RESTORE_1;
  12820. break;
  12821. }
  12822. Rc = OK;
  12823. case ADJUST_B_RESTORE_1:
  12824. if ((Rc != OK) && (Rc != OK_FC))
  12825. {
  12826. dbug (1, dprintf ("[%06lx] %s,%d: Adjust B enqueued failed %02x",
  12827. UnMapId (Id), (char *)(FILE_), __LINE__, Rc));
  12828. }
  12829. plci->adjust_b_parms_msg = NULL;
  12830. plci->adjust_b_facilities = plci->B1_facilities;
  12831. plci->adjust_b_command = ADJUST_B_RESTORE_2;
  12832. plci->adjust_b_ncci = (word)(Id >> 16);
  12833. plci->adjust_b_mode = ADJUST_B_MODE_RESTORE;
  12834. plci->adjust_b_state = ADJUST_B_START;
  12835. dbug (1, dprintf ("[%06lx] %s,%d: Adjust B restore...",
  12836. UnMapId (Id), (char *)(FILE_), __LINE__));
  12837. case ADJUST_B_RESTORE_2:
  12838. if (adjust_b_process (Id, plci, Rc) != GOOD)
  12839. {
  12840. dbug (1, dprintf ("[%06lx] %s,%d: Adjust B restore failed",
  12841. UnMapId (Id), (char *)(FILE_), __LINE__));
  12842. }
  12843. if (plci->internal_command)
  12844. break;
  12845. break;
  12846. }
  12847. }
  12848. static void reset_b3_command (dword Id, PLCI *plci, byte Rc)
  12849. {
  12850. word Info;
  12851. word internal_command;
  12852. dbug (1, dprintf ("[%06lx] %s,%d: reset_b3_command %02x %04x",
  12853. UnMapId (Id), (char *)(FILE_), __LINE__, Rc, plci->internal_command));
  12854. Info = GOOD;
  12855. internal_command = plci->internal_command;
  12856. plci->internal_command = 0;
  12857. switch (internal_command)
  12858. {
  12859. default:
  12860. plci->command = 0;
  12861. plci->adjust_b_parms_msg = NULL;
  12862. plci->adjust_b_facilities = plci->B1_facilities;
  12863. plci->adjust_b_command = RESET_B3_COMMAND_1;
  12864. plci->adjust_b_ncci = (word)(Id >> 16);
  12865. plci->adjust_b_mode = ADJUST_B_MODE_REMOVE_L23 | ADJUST_B_MODE_ASSIGN_L23 | ADJUST_B_MODE_CONNECT;
  12866. plci->adjust_b_state = ADJUST_B_START;
  12867. dbug (1, dprintf ("[%06lx] %s,%d: Reset B3...",
  12868. UnMapId (Id), (char *)(FILE_), __LINE__));
  12869. case RESET_B3_COMMAND_1:
  12870. Info = adjust_b_process (Id, plci, Rc);
  12871. if (Info != GOOD)
  12872. {
  12873. dbug (1, dprintf ("[%06lx] %s,%d: Reset failed",
  12874. UnMapId (Id), (char *)(FILE_), __LINE__));
  12875. break;
  12876. }
  12877. if (plci->internal_command)
  12878. return;
  12879. break;
  12880. }
  12881. /* sendf (plci->appl, _RESET_B3_R | CONFIRM, Id, plci->number, "w", Info);*/
  12882. sendf(plci->appl,_RESET_B3_I,Id,0,"s","");
  12883. }
  12884. static void select_b_command (dword Id, PLCI *plci, byte Rc)
  12885. {
  12886. word Info;
  12887. word internal_command;
  12888. byte esc_chi[3];
  12889. dbug (1, dprintf ("[%06lx] %s,%d: select_b_command %02x %04x",
  12890. UnMapId (Id), (char *)(FILE_), __LINE__, Rc, plci->internal_command));
  12891. Info = GOOD;
  12892. internal_command = plci->internal_command;
  12893. plci->internal_command = 0;
  12894. switch (internal_command)
  12895. {
  12896. default:
  12897. plci->command = 0;
  12898. plci->adjust_b_parms_msg = &plci->saved_msg;
  12899. if ((plci->tel == ADV_VOICE) && (plci == plci->adapter->AdvSignalPLCI))
  12900. plci->adjust_b_facilities = plci->B1_facilities | B1_FACILITY_VOICE;
  12901. else
  12902. plci->adjust_b_facilities = plci->B1_facilities & ~B1_FACILITY_VOICE;
  12903. plci->adjust_b_command = SELECT_B_COMMAND_1;
  12904. plci->adjust_b_ncci = (word)(Id >> 16);
  12905. if (plci->saved_msg.parms[0].length == 0)
  12906. {
  12907. plci->adjust_b_mode = ADJUST_B_MODE_SAVE | ADJUST_B_MODE_REMOVE_L23 | ADJUST_B_MODE_SWITCH_L1 |
  12908. ADJUST_B_MODE_NO_RESOURCE;
  12909. }
  12910. else
  12911. {
  12912. plci->adjust_b_mode = ADJUST_B_MODE_SAVE | ADJUST_B_MODE_REMOVE_L23 | ADJUST_B_MODE_SWITCH_L1 |
  12913. ADJUST_B_MODE_ASSIGN_L23 | ADJUST_B_MODE_USER_CONNECT | ADJUST_B_MODE_RESTORE;
  12914. }
  12915. plci->adjust_b_state = ADJUST_B_START;
  12916. dbug (1, dprintf ("[%06lx] %s,%d: Select B protocol...",
  12917. UnMapId (Id), (char *)(FILE_), __LINE__));
  12918. case SELECT_B_COMMAND_1:
  12919. Info = adjust_b_process (Id, plci, Rc);
  12920. if (Info != GOOD)
  12921. {
  12922. dbug (1, dprintf ("[%06lx] %s,%d: Select B protocol failed",
  12923. UnMapId (Id), (char *)(FILE_), __LINE__));
  12924. break;
  12925. }
  12926. if (plci->internal_command)
  12927. return;
  12928. if (plci->tel == ADV_VOICE)
  12929. {
  12930. esc_chi[0] = 0x02;
  12931. esc_chi[1] = 0x18;
  12932. esc_chi[2] = plci->b_channel;
  12933. SetVoiceChannel (plci->adapter->AdvCodecPLCI, esc_chi, plci->adapter);
  12934. }
  12935. break;
  12936. }
  12937. sendf (plci->appl, _SELECT_B_REQ | CONFIRM, Id, plci->number, "w", Info);
  12938. }
  12939. static void fax_connect_ack_command (dword Id, PLCI *plci, byte Rc)
  12940. {
  12941. word Info;
  12942. word internal_command;
  12943. dbug (1, dprintf ("[%06lx] %s,%d: fax_connect_ack_command %02x %04x",
  12944. UnMapId (Id), (char *)(FILE_), __LINE__, Rc, plci->internal_command));
  12945. Info = GOOD;
  12946. internal_command = plci->internal_command;
  12947. plci->internal_command = 0;
  12948. switch (internal_command)
  12949. {
  12950. default:
  12951. plci->command = 0;
  12952. case FAX_CONNECT_ACK_COMMAND_1:
  12953. if (plci_nl_busy (plci))
  12954. {
  12955. plci->internal_command = FAX_CONNECT_ACK_COMMAND_1;
  12956. return;
  12957. }
  12958. plci->internal_command = FAX_CONNECT_ACK_COMMAND_2;
  12959. plci->NData[0].P = plci->fax_connect_info_buffer;
  12960. plci->NData[0].PLength = plci->fax_connect_info_length;
  12961. plci->NL.X = plci->NData;
  12962. plci->NL.ReqCh = 0;
  12963. plci->NL.Req = plci->nl_req = (byte) N_CONNECT_ACK;
  12964. plci->adapter->request (&plci->NL);
  12965. return;
  12966. case FAX_CONNECT_ACK_COMMAND_2:
  12967. if ((Rc != OK) && (Rc != OK_FC))
  12968. {
  12969. dbug (1, dprintf ("[%06lx] %s,%d: FAX issue CONNECT ACK failed %02x",
  12970. UnMapId (Id), (char *)(FILE_), __LINE__, Rc));
  12971. break;
  12972. }
  12973. }
  12974. if ((plci->ncpi_state & NCPI_VALID_CONNECT_B3_ACT)
  12975. && !(plci->ncpi_state & NCPI_CONNECT_B3_ACT_SENT))
  12976. {
  12977. if (plci->B3_prot == 4)
  12978. sendf(plci->appl,_CONNECT_B3_ACTIVE_I,Id,0,"s","");
  12979. else
  12980. sendf(plci->appl,_CONNECT_B3_ACTIVE_I,Id,0,"S",plci->ncpi_buffer);
  12981. plci->ncpi_state |= NCPI_CONNECT_B3_ACT_SENT;
  12982. }
  12983. }
  12984. static void fax_edata_ack_command (dword Id, PLCI *plci, byte Rc)
  12985. {
  12986. word Info;
  12987. word internal_command;
  12988. dbug (1, dprintf ("[%06lx] %s,%d: fax_edata_ack_command %02x %04x",
  12989. UnMapId (Id), (char *)(FILE_), __LINE__, Rc, plci->internal_command));
  12990. Info = GOOD;
  12991. internal_command = plci->internal_command;
  12992. plci->internal_command = 0;
  12993. switch (internal_command)
  12994. {
  12995. default:
  12996. plci->command = 0;
  12997. case FAX_EDATA_ACK_COMMAND_1:
  12998. if (plci_nl_busy (plci))
  12999. {
  13000. plci->internal_command = FAX_EDATA_ACK_COMMAND_1;
  13001. return;
  13002. }
  13003. plci->internal_command = FAX_EDATA_ACK_COMMAND_2;
  13004. plci->NData[0].P = plci->fax_connect_info_buffer;
  13005. plci->NData[0].PLength = plci->fax_edata_ack_length;
  13006. plci->NL.X = plci->NData;
  13007. plci->NL.ReqCh = 0;
  13008. plci->NL.Req = plci->nl_req = (byte) N_EDATA;
  13009. plci->adapter->request (&plci->NL);
  13010. return;
  13011. case FAX_EDATA_ACK_COMMAND_2:
  13012. if ((Rc != OK) && (Rc != OK_FC))
  13013. {
  13014. dbug (1, dprintf ("[%06lx] %s,%d: FAX issue EDATA ACK failed %02x",
  13015. UnMapId (Id), (char *)(FILE_), __LINE__, Rc));
  13016. break;
  13017. }
  13018. }
  13019. }
  13020. static void fax_connect_info_command (dword Id, PLCI *plci, byte Rc)
  13021. {
  13022. word Info;
  13023. word internal_command;
  13024. dbug (1, dprintf ("[%06lx] %s,%d: fax_connect_info_command %02x %04x",
  13025. UnMapId (Id), (char *)(FILE_), __LINE__, Rc, plci->internal_command));
  13026. Info = GOOD;
  13027. internal_command = plci->internal_command;
  13028. plci->internal_command = 0;
  13029. switch (internal_command)
  13030. {
  13031. default:
  13032. plci->command = 0;
  13033. case FAX_CONNECT_INFO_COMMAND_1:
  13034. if (plci_nl_busy (plci))
  13035. {
  13036. plci->internal_command = FAX_CONNECT_INFO_COMMAND_1;
  13037. return;
  13038. }
  13039. plci->internal_command = FAX_CONNECT_INFO_COMMAND_2;
  13040. plci->NData[0].P = plci->fax_connect_info_buffer;
  13041. plci->NData[0].PLength = plci->fax_connect_info_length;
  13042. plci->NL.X = plci->NData;
  13043. plci->NL.ReqCh = 0;
  13044. plci->NL.Req = plci->nl_req = (byte) N_EDATA;
  13045. plci->adapter->request (&plci->NL);
  13046. return;
  13047. case FAX_CONNECT_INFO_COMMAND_2:
  13048. if ((Rc != OK) && (Rc != OK_FC))
  13049. {
  13050. dbug (1, dprintf ("[%06lx] %s,%d: FAX setting connect info failed %02x",
  13051. UnMapId (Id), (char *)(FILE_), __LINE__, Rc));
  13052. Info = _WRONG_STATE;
  13053. break;
  13054. }
  13055. if (plci_nl_busy (plci))
  13056. {
  13057. plci->internal_command = FAX_CONNECT_INFO_COMMAND_2;
  13058. return;
  13059. }
  13060. plci->command = _CONNECT_B3_R;
  13061. nl_req_ncci (plci, N_CONNECT, 0);
  13062. send_req (plci);
  13063. return;
  13064. }
  13065. sendf (plci->appl, _CONNECT_B3_R | CONFIRM, Id, plci->number, "w", Info);
  13066. }
  13067. static void fax_adjust_b23_command (dword Id, PLCI *plci, byte Rc)
  13068. {
  13069. word Info;
  13070. word internal_command;
  13071. dbug (1, dprintf ("[%06lx] %s,%d: fax_adjust_b23_command %02x %04x",
  13072. UnMapId (Id), (char *)(FILE_), __LINE__, Rc, plci->internal_command));
  13073. Info = GOOD;
  13074. internal_command = plci->internal_command;
  13075. plci->internal_command = 0;
  13076. switch (internal_command)
  13077. {
  13078. default:
  13079. plci->command = 0;
  13080. plci->adjust_b_parms_msg = NULL;
  13081. plci->adjust_b_facilities = plci->B1_facilities;
  13082. plci->adjust_b_command = FAX_ADJUST_B23_COMMAND_1;
  13083. plci->adjust_b_ncci = (word)(Id >> 16);
  13084. plci->adjust_b_mode = ADJUST_B_MODE_REMOVE_L23 | ADJUST_B_MODE_ASSIGN_L23;
  13085. plci->adjust_b_state = ADJUST_B_START;
  13086. dbug (1, dprintf ("[%06lx] %s,%d: FAX adjust B23...",
  13087. UnMapId (Id), (char *)(FILE_), __LINE__));
  13088. case FAX_ADJUST_B23_COMMAND_1:
  13089. Info = adjust_b_process (Id, plci, Rc);
  13090. if (Info != GOOD)
  13091. {
  13092. dbug (1, dprintf ("[%06lx] %s,%d: FAX adjust failed",
  13093. UnMapId (Id), (char *)(FILE_), __LINE__));
  13094. break;
  13095. }
  13096. if (plci->internal_command)
  13097. return;
  13098. case FAX_ADJUST_B23_COMMAND_2:
  13099. if (plci_nl_busy (plci))
  13100. {
  13101. plci->internal_command = FAX_ADJUST_B23_COMMAND_2;
  13102. return;
  13103. }
  13104. plci->command = _CONNECT_B3_R;
  13105. nl_req_ncci (plci, N_CONNECT, 0);
  13106. send_req (plci);
  13107. return;
  13108. }
  13109. sendf (plci->appl, _CONNECT_B3_R | CONFIRM, Id, plci->number, "w", Info);
  13110. }
  13111. static void fax_disconnect_command (dword Id, PLCI *plci, byte Rc)
  13112. {
  13113. word internal_command;
  13114. dbug (1, dprintf ("[%06lx] %s,%d: fax_disconnect_command %02x %04x",
  13115. UnMapId (Id), (char *)(FILE_), __LINE__, Rc, plci->internal_command));
  13116. internal_command = plci->internal_command;
  13117. plci->internal_command = 0;
  13118. switch (internal_command)
  13119. {
  13120. default:
  13121. plci->command = 0;
  13122. plci->internal_command = FAX_DISCONNECT_COMMAND_1;
  13123. return;
  13124. case FAX_DISCONNECT_COMMAND_1:
  13125. case FAX_DISCONNECT_COMMAND_2:
  13126. case FAX_DISCONNECT_COMMAND_3:
  13127. if ((Rc != OK) && (Rc != OK_FC) && (Rc != 0))
  13128. {
  13129. dbug (1, dprintf ("[%06lx] %s,%d: FAX disconnect EDATA failed %02x",
  13130. UnMapId (Id), (char *)(FILE_), __LINE__, Rc));
  13131. break;
  13132. }
  13133. if (Rc == OK)
  13134. {
  13135. if ((internal_command == FAX_DISCONNECT_COMMAND_1)
  13136. || (internal_command == FAX_DISCONNECT_COMMAND_2))
  13137. {
  13138. plci->internal_command = FAX_DISCONNECT_COMMAND_2;
  13139. }
  13140. }
  13141. else if (Rc == 0)
  13142. {
  13143. if (internal_command == FAX_DISCONNECT_COMMAND_1)
  13144. plci->internal_command = FAX_DISCONNECT_COMMAND_3;
  13145. }
  13146. return;
  13147. }
  13148. }
  13149. static void rtp_connect_b3_req_command (dword Id, PLCI *plci, byte Rc)
  13150. {
  13151. word Info;
  13152. word internal_command;
  13153. dbug (1, dprintf ("[%06lx] %s,%d: rtp_connect_b3_req_command %02x %04x",
  13154. UnMapId (Id), (char *)(FILE_), __LINE__, Rc, plci->internal_command));
  13155. Info = GOOD;
  13156. internal_command = plci->internal_command;
  13157. plci->internal_command = 0;
  13158. switch (internal_command)
  13159. {
  13160. default:
  13161. plci->command = 0;
  13162. case RTP_CONNECT_B3_REQ_COMMAND_1:
  13163. if (plci_nl_busy (plci))
  13164. {
  13165. plci->internal_command = RTP_CONNECT_B3_REQ_COMMAND_1;
  13166. return;
  13167. }
  13168. plci->internal_command = RTP_CONNECT_B3_REQ_COMMAND_2;
  13169. nl_req_ncci (plci, N_CONNECT, 0);
  13170. send_req (plci);
  13171. return;
  13172. case RTP_CONNECT_B3_REQ_COMMAND_2:
  13173. if ((Rc != OK) && (Rc != OK_FC))
  13174. {
  13175. dbug (1, dprintf ("[%06lx] %s,%d: RTP setting connect info failed %02x",
  13176. UnMapId (Id), (char *)(FILE_), __LINE__, Rc));
  13177. Info = _WRONG_STATE;
  13178. break;
  13179. }
  13180. if (plci_nl_busy (plci))
  13181. {
  13182. plci->internal_command = RTP_CONNECT_B3_REQ_COMMAND_2;
  13183. return;
  13184. }
  13185. plci->internal_command = RTP_CONNECT_B3_REQ_COMMAND_3;
  13186. plci->NData[0].PLength = plci->internal_req_buffer[0];
  13187. plci->NData[0].P = plci->internal_req_buffer + 1;
  13188. plci->NL.X = plci->NData;
  13189. plci->NL.ReqCh = 0;
  13190. plci->NL.Req = plci->nl_req = (byte) N_UDATA;
  13191. plci->adapter->request (&plci->NL);
  13192. break;
  13193. case RTP_CONNECT_B3_REQ_COMMAND_3:
  13194. return;
  13195. }
  13196. sendf (plci->appl, _CONNECT_B3_R | CONFIRM, Id, plci->number, "w", Info);
  13197. }
  13198. static void rtp_connect_b3_res_command (dword Id, PLCI *plci, byte Rc)
  13199. {
  13200. word Info;
  13201. word internal_command;
  13202. dbug (1, dprintf ("[%06lx] %s,%d: rtp_connect_b3_res_command %02x %04x",
  13203. UnMapId (Id), (char *)(FILE_), __LINE__, Rc, plci->internal_command));
  13204. Info = GOOD;
  13205. internal_command = plci->internal_command;
  13206. plci->internal_command = 0;
  13207. switch (internal_command)
  13208. {
  13209. default:
  13210. plci->command = 0;
  13211. case RTP_CONNECT_B3_RES_COMMAND_1:
  13212. if (plci_nl_busy (plci))
  13213. {
  13214. plci->internal_command = RTP_CONNECT_B3_RES_COMMAND_1;
  13215. return;
  13216. }
  13217. plci->internal_command = RTP_CONNECT_B3_RES_COMMAND_2;
  13218. nl_req_ncci (plci, N_CONNECT_ACK, (byte)(Id >> 16));
  13219. send_req (plci);
  13220. return;
  13221. case RTP_CONNECT_B3_RES_COMMAND_2:
  13222. if ((Rc != OK) && (Rc != OK_FC))
  13223. {
  13224. dbug (1, dprintf ("[%06lx] %s,%d: RTP setting connect resp info failed %02x",
  13225. UnMapId (Id), (char *)(FILE_), __LINE__, Rc));
  13226. Info = _WRONG_STATE;
  13227. break;
  13228. }
  13229. if (plci_nl_busy (plci))
  13230. {
  13231. plci->internal_command = RTP_CONNECT_B3_RES_COMMAND_2;
  13232. return;
  13233. }
  13234. sendf (plci->appl, _CONNECT_B3_ACTIVE_I, Id, 0, "s", "");
  13235. plci->internal_command = RTP_CONNECT_B3_RES_COMMAND_3;
  13236. plci->NData[0].PLength = plci->internal_req_buffer[0];
  13237. plci->NData[0].P = plci->internal_req_buffer + 1;
  13238. plci->NL.X = plci->NData;
  13239. plci->NL.ReqCh = 0;
  13240. plci->NL.Req = plci->nl_req = (byte) N_UDATA;
  13241. plci->adapter->request (&plci->NL);
  13242. return;
  13243. case RTP_CONNECT_B3_RES_COMMAND_3:
  13244. return;
  13245. }
  13246. }
  13247. static void hold_save_command (dword Id, PLCI *plci, byte Rc)
  13248. {
  13249. byte SS_Ind[] = "\x05\x02\x00\x02\x00\x00"; /* Hold_Ind struct*/
  13250. word Info;
  13251. word internal_command;
  13252. dbug (1, dprintf ("[%06lx] %s,%d: hold_save_command %02x %04x",
  13253. UnMapId (Id), (char *)(FILE_), __LINE__, Rc, plci->internal_command));
  13254. Info = GOOD;
  13255. internal_command = plci->internal_command;
  13256. plci->internal_command = 0;
  13257. switch (internal_command)
  13258. {
  13259. default:
  13260. if (!plci->NL.Id)
  13261. break;
  13262. plci->command = 0;
  13263. plci->adjust_b_parms_msg = NULL;
  13264. plci->adjust_b_facilities = plci->B1_facilities;
  13265. plci->adjust_b_command = HOLD_SAVE_COMMAND_1;
  13266. plci->adjust_b_ncci = (word)(Id >> 16);
  13267. plci->adjust_b_mode = ADJUST_B_MODE_SAVE | ADJUST_B_MODE_REMOVE_L23;
  13268. plci->adjust_b_state = ADJUST_B_START;
  13269. dbug (1, dprintf ("[%06lx] %s,%d: HOLD save...",
  13270. UnMapId (Id), (char *)(FILE_), __LINE__));
  13271. case HOLD_SAVE_COMMAND_1:
  13272. Info = adjust_b_process (Id, plci, Rc);
  13273. if (Info != GOOD)
  13274. {
  13275. dbug (1, dprintf ("[%06lx] %s,%d: HOLD save failed",
  13276. UnMapId (Id), (char *)(FILE_), __LINE__));
  13277. break;
  13278. }
  13279. if (plci->internal_command)
  13280. return;
  13281. }
  13282. sendf (plci->appl, _FACILITY_I, Id & 0xffffL, 0, "ws", 3, SS_Ind);
  13283. }
  13284. static void retrieve_restore_command (dword Id, PLCI *plci, byte Rc)
  13285. {
  13286. byte SS_Ind[] = "\x05\x03\x00\x02\x00\x00"; /* Retrieve_Ind struct*/
  13287. word Info;
  13288. word internal_command;
  13289. dbug (1, dprintf ("[%06lx] %s,%d: retrieve_restore_command %02x %04x",
  13290. UnMapId (Id), (char *)(FILE_), __LINE__, Rc, plci->internal_command));
  13291. Info = GOOD;
  13292. internal_command = plci->internal_command;
  13293. plci->internal_command = 0;
  13294. switch (internal_command)
  13295. {
  13296. default:
  13297. plci->command = 0;
  13298. plci->adjust_b_parms_msg = NULL;
  13299. plci->adjust_b_facilities = plci->B1_facilities;
  13300. plci->adjust_b_command = RETRIEVE_RESTORE_COMMAND_1;
  13301. plci->adjust_b_ncci = (word)(Id >> 16);
  13302. plci->adjust_b_mode = ADJUST_B_MODE_ASSIGN_L23 | ADJUST_B_MODE_USER_CONNECT | ADJUST_B_MODE_RESTORE;
  13303. plci->adjust_b_state = ADJUST_B_START;
  13304. dbug (1, dprintf ("[%06lx] %s,%d: RETRIEVE restore...",
  13305. UnMapId (Id), (char *)(FILE_), __LINE__));
  13306. case RETRIEVE_RESTORE_COMMAND_1:
  13307. Info = adjust_b_process (Id, plci, Rc);
  13308. if (Info != GOOD)
  13309. {
  13310. dbug (1, dprintf ("[%06lx] %s,%d: RETRIEVE restore failed",
  13311. UnMapId (Id), (char *)(FILE_), __LINE__));
  13312. break;
  13313. }
  13314. if (plci->internal_command)
  13315. return;
  13316. }
  13317. sendf (plci->appl, _FACILITY_I, Id & 0xffffL, 0, "ws", 3, SS_Ind);
  13318. }
  13319. static void init_b1_config (PLCI *plci)
  13320. {
  13321. dbug (1, dprintf ("[%06lx] %s,%d: init_b1_config",
  13322. (dword)((plci->Id << 8) | UnMapController (plci->adapter->Id)),
  13323. (char *)(FILE_), __LINE__));
  13324. plci->B1_resource = 0;
  13325. plci->B1_facilities = 0;
  13326. plci->li_bchannel_id = 0;
  13327. mixer_clear_config (plci);
  13328. ec_clear_config (plci);
  13329. dtmf_rec_clear_config (plci);
  13330. dtmf_send_clear_config (plci);
  13331. dtmf_parameter_clear_config (plci);
  13332. adv_voice_clear_config (plci);
  13333. adjust_b_clear (plci);
  13334. }
  13335. static void clear_b1_config (PLCI *plci)
  13336. {
  13337. dbug (1, dprintf ("[%06lx] %s,%d: clear_b1_config",
  13338. (dword)((plci->Id << 8) | UnMapController (plci->adapter->Id)),
  13339. (char *)(FILE_), __LINE__));
  13340. adv_voice_clear_config (plci);
  13341. adjust_b_clear (plci);
  13342. ec_clear_config (plci);
  13343. dtmf_rec_clear_config (plci);
  13344. dtmf_send_clear_config (plci);
  13345. dtmf_parameter_clear_config (plci);
  13346. if ((plci->li_bchannel_id != 0)
  13347. && (li_config_table[plci->adapter->li_base + (plci->li_bchannel_id - 1)].plci == plci))
  13348. {
  13349. mixer_clear_config (plci);
  13350. li_config_table[plci->adapter->li_base + (plci->li_bchannel_id - 1)].plci = NULL;
  13351. plci->li_bchannel_id = 0;
  13352. }
  13353. plci->B1_resource = 0;
  13354. plci->B1_facilities = 0;
  13355. }
  13356. /* -----------------------------------------------------------------
  13357. XON protocol local helpers
  13358. ----------------------------------------------------------------- */
  13359. static void channel_flow_control_remove (PLCI * plci) {
  13360. DIVA_CAPI_ADAPTER * a = plci->adapter;
  13361. word i;
  13362. for(i=1;i<MAX_NL_CHANNEL+1;i++) {
  13363. if (a->ch_flow_plci[i] == plci->Id) {
  13364. a->ch_flow_plci[i] = 0;
  13365. a->ch_flow_control[i] = 0;
  13366. }
  13367. }
  13368. }
  13369. static void channel_x_on (PLCI * plci, byte ch) {
  13370. DIVA_CAPI_ADAPTER * a = plci->adapter;
  13371. if (a->ch_flow_control[ch] & N_XON_SENT) {
  13372. a->ch_flow_control[ch] &= ~N_XON_SENT;
  13373. }
  13374. }
  13375. static void channel_x_off (PLCI * plci, byte ch, byte flag) {
  13376. DIVA_CAPI_ADAPTER * a = plci->adapter;
  13377. if ((a->ch_flow_control[ch] & N_RX_FLOW_CONTROL_MASK) == 0) {
  13378. a->ch_flow_control[ch] |= (N_CH_XOFF | flag);
  13379. a->ch_flow_plci[ch] = plci->Id;
  13380. a->ch_flow_control_pending++;
  13381. }
  13382. }
  13383. static void channel_request_xon (PLCI * plci, byte ch) {
  13384. DIVA_CAPI_ADAPTER * a = plci->adapter;
  13385. if (a->ch_flow_control[ch] & N_CH_XOFF) {
  13386. a->ch_flow_control[ch] |= N_XON_REQ;
  13387. a->ch_flow_control[ch] &= ~N_CH_XOFF;
  13388. a->ch_flow_control[ch] &= ~N_XON_CONNECT_IND;
  13389. }
  13390. }
  13391. static void channel_xmit_extended_xon (PLCI * plci) {
  13392. DIVA_CAPI_ADAPTER * a;
  13393. int max_ch = ARRAY_SIZE(a->ch_flow_control);
  13394. int i, one_requested = 0;
  13395. if ((!plci) || (!plci->Id) || ((a = plci->adapter) == NULL)) {
  13396. return;
  13397. }
  13398. for (i = 0; i < max_ch; i++) {
  13399. if ((a->ch_flow_control[i] & N_CH_XOFF) &&
  13400. (a->ch_flow_control[i] & N_XON_CONNECT_IND) &&
  13401. (plci->Id == a->ch_flow_plci[i])) {
  13402. channel_request_xon (plci, (byte)i);
  13403. one_requested = 1;
  13404. }
  13405. }
  13406. if (one_requested) {
  13407. channel_xmit_xon (plci);
  13408. }
  13409. }
  13410. /*
  13411. Try to xmit next X_ON
  13412. */
  13413. static int find_channel_with_pending_x_on (DIVA_CAPI_ADAPTER * a, PLCI * plci) {
  13414. int max_ch = ARRAY_SIZE(a->ch_flow_control);
  13415. int i;
  13416. if (!(plci->adapter->manufacturer_features & MANUFACTURER_FEATURE_XONOFF_FLOW_CONTROL)) {
  13417. return (0);
  13418. }
  13419. if (a->last_flow_control_ch >= max_ch) {
  13420. a->last_flow_control_ch = 1;
  13421. }
  13422. for (i=a->last_flow_control_ch; i < max_ch; i++) {
  13423. if ((a->ch_flow_control[i] & N_XON_REQ) &&
  13424. (plci->Id == a->ch_flow_plci[i])) {
  13425. a->last_flow_control_ch = i+1;
  13426. return (i);
  13427. }
  13428. }
  13429. for (i = 1; i < a->last_flow_control_ch; i++) {
  13430. if ((a->ch_flow_control[i] & N_XON_REQ) &&
  13431. (plci->Id == a->ch_flow_plci[i])) {
  13432. a->last_flow_control_ch = i+1;
  13433. return (i);
  13434. }
  13435. }
  13436. return (0);
  13437. }
  13438. static void channel_xmit_xon (PLCI * plci) {
  13439. DIVA_CAPI_ADAPTER * a = plci->adapter;
  13440. byte ch;
  13441. if (plci->nl_req || !plci->NL.Id || plci->nl_remove_id) {
  13442. return;
  13443. }
  13444. if ((ch = (byte)find_channel_with_pending_x_on (a, plci)) == 0) {
  13445. return;
  13446. }
  13447. a->ch_flow_control[ch] &= ~N_XON_REQ;
  13448. a->ch_flow_control[ch] |= N_XON_SENT;
  13449. plci->NL.Req = plci->nl_req = (byte)N_XON;
  13450. plci->NL.ReqCh = ch;
  13451. plci->NL.X = plci->NData;
  13452. plci->NL.XNum = 1;
  13453. plci->NData[0].P = &plci->RBuffer[0];
  13454. plci->NData[0].PLength = 0;
  13455. plci->adapter->request(&plci->NL);
  13456. }
  13457. static int channel_can_xon (PLCI * plci, byte ch) {
  13458. APPL * APPLptr;
  13459. DIVA_CAPI_ADAPTER * a;
  13460. word NCCIcode;
  13461. dword count;
  13462. word Num;
  13463. word i;
  13464. APPLptr = plci->appl;
  13465. a = plci->adapter;
  13466. if (!APPLptr)
  13467. return (0);
  13468. NCCIcode = a->ch_ncci[ch] | (((word) a->Id) << 8);
  13469. /* count all buffers within the Application pool */
  13470. /* belonging to the same NCCI. XON if a first is */
  13471. /* used. */
  13472. count = 0;
  13473. Num = 0xffff;
  13474. for(i=0; i<APPLptr->MaxBuffer; i++) {
  13475. if(NCCIcode==APPLptr->DataNCCI[i]) count++;
  13476. if(!APPLptr->DataNCCI[i] && Num==0xffff) Num = i;
  13477. }
  13478. if ((count > 2) || (Num == 0xffff)) {
  13479. return (0);
  13480. }
  13481. return (1);
  13482. }
  13483. /*------------------------------------------------------------------*/
  13484. static word CPN_filter_ok(byte *cpn,DIVA_CAPI_ADAPTER * a,word offset)
  13485. {
  13486. return 1;
  13487. }
  13488. /**********************************************************************************/
  13489. /* function groups the listening applications according to the CIP mask and the */
  13490. /* Info_Mask. Each group gets just one Connect_Ind. Some application manufacturer */
  13491. /* are not multi-instance capable, so they start e.g. 30 applications what causes */
  13492. /* big problems on application level (one call, 30 Connect_Ind, ect). The */
  13493. /* function must be enabled by setting "a->group_optimization_enabled" from the */
  13494. /* OS specific part (per adapter). */
  13495. /**********************************************************************************/
  13496. static void group_optimization(DIVA_CAPI_ADAPTER * a, PLCI * plci)
  13497. {
  13498. word i,j,k,busy,group_found;
  13499. dword info_mask_group[MAX_CIP_TYPES];
  13500. dword cip_mask_group[MAX_CIP_TYPES];
  13501. word appl_number_group_type[MAX_APPL];
  13502. PLCI *auxplci;
  13503. set_group_ind_mask (plci); /* all APPLs within this inc. call are allowed to dial in */
  13504. if(!a->group_optimization_enabled)
  13505. {
  13506. dbug(1,dprintf("No group optimization"));
  13507. return;
  13508. }
  13509. dbug(1,dprintf("Group optimization = 0x%x...", a->group_optimization_enabled));
  13510. for(i=0;i<MAX_CIP_TYPES;i++)
  13511. {
  13512. info_mask_group[i] = 0;
  13513. cip_mask_group [i] = 0;
  13514. }
  13515. for(i=0;i<MAX_APPL;i++)
  13516. {
  13517. appl_number_group_type[i] = 0;
  13518. }
  13519. for(i=0; i<max_appl; i++) /* check if any multi instance capable application is present */
  13520. { /* group_optimization set to 1 means not to optimize multi-instance capable applications (default) */
  13521. if(application[i].Id && (application[i].MaxNCCI) > 1 && (a->CIP_Mask[i]) && (a->group_optimization_enabled ==1) )
  13522. {
  13523. dbug(1,dprintf("Multi-Instance capable, no optimization required"));
  13524. return; /* allow good application unfiltered access */
  13525. }
  13526. }
  13527. for(i=0; i<max_appl; i++) /* Build CIP Groups */
  13528. {
  13529. if(application[i].Id && a->CIP_Mask[i] )
  13530. {
  13531. for(k=0,busy=false; k<a->max_plci; k++)
  13532. {
  13533. if(a->plci[k].Id)
  13534. {
  13535. auxplci = &a->plci[k];
  13536. if(auxplci->appl == &application[i]) /* application has a busy PLCI */
  13537. {
  13538. busy = true;
  13539. dbug(1,dprintf("Appl 0x%x is busy",i+1));
  13540. }
  13541. else if(test_c_ind_mask_bit (auxplci, i)) /* application has an incoming call pending */
  13542. {
  13543. busy = true;
  13544. dbug(1,dprintf("Appl 0x%x has inc. call pending",i+1));
  13545. }
  13546. }
  13547. }
  13548. for(j=0,group_found=0; j<=(MAX_CIP_TYPES) && !busy &&!group_found; j++) /* build groups with free applications only */
  13549. {
  13550. if(j==MAX_CIP_TYPES) /* all groups are in use but group still not found */
  13551. { /* the MAX_CIP_TYPES group enables all calls because of field overflow */
  13552. appl_number_group_type[i] = MAX_CIP_TYPES;
  13553. group_found=true;
  13554. dbug(1,dprintf("Field overflow appl 0x%x",i+1));
  13555. }
  13556. else if( (info_mask_group[j]==a->CIP_Mask[i]) && (cip_mask_group[j]==a->Info_Mask[i]) )
  13557. { /* is group already present ? */
  13558. appl_number_group_type[i] = j|0x80; /* store the group number for each application */
  13559. group_found=true;
  13560. 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]));
  13561. }
  13562. else if(!info_mask_group[j])
  13563. { /* establish a new group */
  13564. appl_number_group_type[i] = j|0x80; /* store the group number for each application */
  13565. info_mask_group[j] = a->CIP_Mask[i]; /* store the new CIP mask for the new group */
  13566. cip_mask_group[j] = a->Info_Mask[i]; /* store the new Info_Mask for this new group */
  13567. group_found=true;
  13568. 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]));
  13569. }
  13570. }
  13571. }
  13572. }
  13573. for(i=0; i<max_appl; i++) /* Build group_optimization_mask_table */
  13574. {
  13575. if(appl_number_group_type[i]) /* application is free, has listens and is member of a group */
  13576. {
  13577. if(appl_number_group_type[i] == MAX_CIP_TYPES)
  13578. {
  13579. dbug(1,dprintf("OverflowGroup 0x%x, valid appl = 0x%x, call enabled",appl_number_group_type[i],i+1));
  13580. }
  13581. else
  13582. {
  13583. dbug(1,dprintf("Group 0x%x, valid appl = 0x%x",appl_number_group_type[i],i+1));
  13584. for(j=i+1; j<max_appl; j++) /* search other group members and mark them as busy */
  13585. {
  13586. if(appl_number_group_type[i] == appl_number_group_type[j])
  13587. {
  13588. dbug(1,dprintf("Appl 0x%x is member of group 0x%x, no call",j+1,appl_number_group_type[j]));
  13589. clear_group_ind_mask_bit (plci, j); /* disable call on other group members */
  13590. appl_number_group_type[j] = 0; /* remove disabled group member from group list */
  13591. }
  13592. }
  13593. }
  13594. }
  13595. else /* application should not get a call */
  13596. {
  13597. clear_group_ind_mask_bit (plci, i);
  13598. }
  13599. }
  13600. }
  13601. /* OS notifies the driver about a application Capi_Register */
  13602. word CapiRegister(word id)
  13603. {
  13604. word i,j,appls_found;
  13605. PLCI *plci;
  13606. DIVA_CAPI_ADAPTER *a;
  13607. for(i=0,appls_found=0; i<max_appl; i++)
  13608. {
  13609. if( application[i].Id && (application[i].Id!=id) )
  13610. {
  13611. appls_found++; /* an application has been found */
  13612. }
  13613. }
  13614. if(appls_found) return true;
  13615. for(i=0; i<max_adapter; i++) /* scan all adapters... */
  13616. {
  13617. a = &adapter[i];
  13618. if(a->request)
  13619. {
  13620. if(a->flag_dynamic_l1_down) /* remove adapter from L1 tristate (Huntgroup) */
  13621. {
  13622. if(!appls_found) /* first application does a capi register */
  13623. {
  13624. if((j=get_plci(a))) /* activate L1 of all adapters */
  13625. {
  13626. plci = &a->plci[j-1];
  13627. plci->command = 0;
  13628. add_p(plci,OAD,"\x01\xfd");
  13629. add_p(plci,CAI,"\x01\x80");
  13630. add_p(plci,UID,"\x06\x43\x61\x70\x69\x32\x30");
  13631. add_p(plci,SHIFT|6,NULL);
  13632. add_p(plci,SIN,"\x02\x00\x00");
  13633. plci->internal_command = START_L1_SIG_ASSIGN_PEND;
  13634. sig_req(plci,ASSIGN,DSIG_ID);
  13635. add_p(plci,FTY,"\x02\xff\x07"); /* l1 start */
  13636. sig_req(plci,SIG_CTRL,0);
  13637. send_req(plci);
  13638. }
  13639. }
  13640. }
  13641. }
  13642. }
  13643. return false;
  13644. }
  13645. /*------------------------------------------------------------------*/
  13646. /* Functions for virtual Switching e.g. Transfer by join, Conference */
  13647. static void VSwitchReqInd(PLCI *plci, dword Id, byte **parms)
  13648. {
  13649. word i;
  13650. /* Format of vswitch_t:
  13651. 0 byte length
  13652. 1 byte VSWITCHIE
  13653. 2 byte VSWITCH_REQ/VSWITCH_IND
  13654. 3 byte reserved
  13655. 4 word VSwitchcommand
  13656. 6 word returnerror
  13657. 8... Params
  13658. */
  13659. if(!plci ||
  13660. !plci->appl ||
  13661. !plci->State ||
  13662. plci->Sig.Ind==NCR_FACILITY
  13663. )
  13664. return;
  13665. for(i=0;i<MAX_MULTI_IE;i++)
  13666. {
  13667. if(!parms[i][0]) continue;
  13668. if(parms[i][0]<7)
  13669. {
  13670. parms[i][0]=0; /* kill it */
  13671. continue;
  13672. }
  13673. dbug(1,dprintf("VSwitchReqInd(%d)",parms[i][4]));
  13674. switch(parms[i][4])
  13675. {
  13676. case VSJOIN:
  13677. if(!plci->relatedPTYPLCI ||
  13678. (plci->ptyState!=S_ECT && plci->relatedPTYPLCI->ptyState!=S_ECT))
  13679. { /* Error */
  13680. break;
  13681. }
  13682. /* remember all necessary informations */
  13683. if(parms[i][0]!=11 || parms[i][8]!=3) /* Length Test */
  13684. {
  13685. break;
  13686. }
  13687. if(parms[i][2]==VSWITCH_IND && parms[i][9]==1)
  13688. { /* first indication after ECT-Request on Consultation Call */
  13689. plci->vswitchstate=parms[i][9];
  13690. parms[i][9]=2; /* State */
  13691. /* now ask first Call to join */
  13692. }
  13693. else if(parms[i][2]==VSWITCH_REQ && parms[i][9]==3)
  13694. { /* Answer of VSWITCH_REQ from first Call */
  13695. plci->vswitchstate=parms[i][9];
  13696. /* tell consultation call to join
  13697. and the protocol capabilities of the first call */
  13698. }
  13699. else
  13700. { /* Error */
  13701. break;
  13702. }
  13703. plci->vsprot=parms[i][10]; /* protocol */
  13704. plci->vsprotdialect=parms[i][11]; /* protocoldialect */
  13705. /* send join request to related PLCI */
  13706. parms[i][1]=VSWITCHIE;
  13707. parms[i][2]=VSWITCH_REQ;
  13708. plci->relatedPTYPLCI->command = 0;
  13709. plci->relatedPTYPLCI->internal_command = VSWITCH_REQ_PEND;
  13710. add_p(plci->relatedPTYPLCI,ESC,&parms[i][0]);
  13711. sig_req(plci->relatedPTYPLCI,VSWITCH_REQ,0);
  13712. send_req(plci->relatedPTYPLCI);
  13713. break;
  13714. case VSTRANSPORT:
  13715. default:
  13716. if(plci->relatedPTYPLCI &&
  13717. plci->vswitchstate==3 &&
  13718. plci->relatedPTYPLCI->vswitchstate==3)
  13719. {
  13720. add_p(plci->relatedPTYPLCI,ESC,&parms[i][0]);
  13721. sig_req(plci->relatedPTYPLCI,VSWITCH_REQ,0);
  13722. send_req(plci->relatedPTYPLCI);
  13723. }
  13724. break;
  13725. }
  13726. parms[i][0]=0; /* kill it */
  13727. }
  13728. }
  13729. /*------------------------------------------------------------------*/
  13730. static int diva_get_dma_descriptor (PLCI *plci, dword *dma_magic) {
  13731. ENTITY e;
  13732. IDI_SYNC_REQ* pReq = (IDI_SYNC_REQ*)&e;
  13733. if (!(diva_xdi_extended_features & DIVA_CAPI_XDI_PROVIDES_RX_DMA)) {
  13734. return (-1);
  13735. }
  13736. pReq->xdi_dma_descriptor_operation.Req = 0;
  13737. pReq->xdi_dma_descriptor_operation.Rc = IDI_SYNC_REQ_DMA_DESCRIPTOR_OPERATION;
  13738. pReq->xdi_dma_descriptor_operation.info.operation = IDI_SYNC_REQ_DMA_DESCRIPTOR_ALLOC;
  13739. pReq->xdi_dma_descriptor_operation.info.descriptor_number = -1;
  13740. pReq->xdi_dma_descriptor_operation.info.descriptor_address = NULL;
  13741. pReq->xdi_dma_descriptor_operation.info.descriptor_magic = 0;
  13742. e.user[0] = plci->adapter->Id - 1;
  13743. plci->adapter->request((ENTITY*)pReq);
  13744. if (!pReq->xdi_dma_descriptor_operation.info.operation &&
  13745. (pReq->xdi_dma_descriptor_operation.info.descriptor_number >= 0) &&
  13746. pReq->xdi_dma_descriptor_operation.info.descriptor_magic) {
  13747. *dma_magic = pReq->xdi_dma_descriptor_operation.info.descriptor_magic;
  13748. dbug(3,dprintf("dma_alloc, a:%d (%d-%08x)",
  13749. plci->adapter->Id,
  13750. pReq->xdi_dma_descriptor_operation.info.descriptor_number,
  13751. *dma_magic));
  13752. return (pReq->xdi_dma_descriptor_operation.info.descriptor_number);
  13753. } else {
  13754. dbug(1,dprintf("dma_alloc failed"));
  13755. return (-1);
  13756. }
  13757. }
  13758. static void diva_free_dma_descriptor (PLCI *plci, int nr) {
  13759. ENTITY e;
  13760. IDI_SYNC_REQ* pReq = (IDI_SYNC_REQ*)&e;
  13761. if (nr < 0) {
  13762. return;
  13763. }
  13764. pReq->xdi_dma_descriptor_operation.Req = 0;
  13765. pReq->xdi_dma_descriptor_operation.Rc = IDI_SYNC_REQ_DMA_DESCRIPTOR_OPERATION;
  13766. pReq->xdi_dma_descriptor_operation.info.operation = IDI_SYNC_REQ_DMA_DESCRIPTOR_FREE;
  13767. pReq->xdi_dma_descriptor_operation.info.descriptor_number = nr;
  13768. pReq->xdi_dma_descriptor_operation.info.descriptor_address = NULL;
  13769. pReq->xdi_dma_descriptor_operation.info.descriptor_magic = 0;
  13770. e.user[0] = plci->adapter->Id - 1;
  13771. plci->adapter->request((ENTITY*)pReq);
  13772. if (!pReq->xdi_dma_descriptor_operation.info.operation) {
  13773. dbug(1,dprintf("dma_free(%d)", nr));
  13774. } else {
  13775. dbug(1,dprintf("dma_free failed (%d)", nr));
  13776. }
  13777. }
  13778. /*------------------------------------------------------------------*/