app_rpt.c 162 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561
  1. /*
  2. * Asterisk -- An open source telephony toolkit.
  3. *
  4. * Copyright (C) 2002-2005, Jim Dixon, WB6NIL
  5. *
  6. * Jim Dixon, WB6NIL <jim@lambdatel.com>
  7. * Serious contributions by Steve RoDgers, WA6ZFT <hwstar@rodgers.sdcoxmail.com>
  8. *
  9. * See http://www.asterisk.org for more information about
  10. * the Asterisk project. Please do not directly contact
  11. * any of the maintainers of this project for assistance;
  12. * the project provides a web site, mailing lists and IRC
  13. * channels for your use.
  14. *
  15. * This program is free software, distributed under the terms of
  16. * the GNU General Public License Version 2. See the LICENSE file
  17. * at the top of the source tree.
  18. */
  19. /*
  20. *
  21. * Radio Repeater / Remote Base program
  22. * version 0.37 11/3/05
  23. *
  24. * See http://www.zapatatelephony.org/app_rpt.html
  25. *
  26. *
  27. * Repeater / Remote Functions:
  28. * "Simple" Mode: * - autopatch access, # - autopatch hangup
  29. * Normal mode:
  30. * See the function list in rpt.conf
  31. *
  32. * To send an asterisk (*) while dialing or talking on phone,
  33. * use the autopatch acess code.
  34. *
  35. *
  36. * status cmds:
  37. *
  38. * 1 - Force ID
  39. * 2 - Give Time of Day
  40. * 3 - Give software Version
  41. *
  42. * cop (control operator) cmds:
  43. *
  44. * 1 - System warm boot
  45. * 2 - System enable
  46. * 3 - System disable
  47. * 4 - Test Tone On
  48. * 5 - Dump System Variables on Console (debug)
  49. * 6 - PTT (phone mode only)
  50. *
  51. * ilink cmds:
  52. *
  53. * 1 - Disconnect specified link
  54. * 2 - Connect specified link -- monitor only
  55. * 3 - Connect specified link -- tranceive
  56. * 4 - Enter command mode on specified link
  57. * 5 - System status
  58. * 6 - Disconnect all links
  59. *
  60. * remote cmds:
  61. *
  62. * 1 - Recall Memory MM (*000-*099) (Gets memory from rpt.conf)
  63. * 2 - Set VFO MMMMM*KKK*O (Mhz digits, Khz digits, Offset)
  64. * 3 - Set Rx PL Tone HHH*D*
  65. * 4 - Set Tx PL Tone HHH*D* (Not currently implemented with DHE RBI-1)
  66. * 5 - Link Status (long)
  67. * 6 - Set operating mode M (FM, USB, LSB, AM, etc)
  68. * 100 - RX PL off (Default)
  69. * 101 - RX PL On
  70. * 102 - TX PL Off (Default)
  71. * 103 - TX PL On
  72. * 104 - Low Power
  73. * 105 - Med Power
  74. * 106 - Hi Power
  75. * 107 - Bump Down 20 Hz
  76. * 108 - Bump Down 100 Hz
  77. * 109 - Bump Down 500 Hz
  78. * 110 - Bump Up 20 Hz
  79. * 111 - Bump Up 100 Hz
  80. * 112 - Bump Up 500 Hz
  81. * 113 - Scan Down Slow
  82. * 114 - Scan Down Medium
  83. * 115 - Scan Down Fast
  84. * 116 - Scan Up Slow
  85. * 117 - Scan Up Medium
  86. * 118 - Scan Up Fast
  87. * 119 - Transmit allowing auto-tune
  88. * 140 - Link Status (brief)
  89. *
  90. *
  91. */
  92. /* The following is JUST GROSS!! There is some soft of underlying problem,
  93. probably in channel_iax2.c, that causes an IAX2 connection to sometimes
  94. stop transmitting randomly. We have been working for weeks to try to
  95. locate it and fix it, but to no avail We finally decided to put our
  96. tail between our legs, and just make the radio system re-connect upon
  97. network failure. This just shouldnt have to be done. For normal operation,
  98. comment-out the following line */
  99. #define RECONNECT_KLUDGE
  100. /* maximum digits in DTMF buffer, and seconds after * for DTMF command timeout */
  101. #define MAXDTMF 32
  102. #define DTMF_TIMEOUT 3
  103. #define DISC_TIME 10000 /* report disc after 10 seconds of no connect */
  104. #define MAX_RETRIES 5
  105. #define REDUNDANT_TX_TIME 2000
  106. #define RETRY_TIMER_MS 5000
  107. #define MAXREMSTR 15
  108. #define NODES "nodes"
  109. #define MEMORY "memory"
  110. #define FUNCTIONS "functions"
  111. #define TELEMETRY "telemetry"
  112. #define MORSE "morse"
  113. #define FUNCCHAR '*'
  114. #define ENDCHAR '#'
  115. #define DEFAULT_IOBASE 0x378
  116. #define MAXCONNECTTIME 5000
  117. #define MAXNODESTR 300
  118. #define ACTIONSIZE 32
  119. #define TELEPARAMSIZE 256
  120. #define REM_SCANTIME 100
  121. enum {REM_OFF,REM_MONITOR,REM_TX};
  122. enum{ID,PROC,TERM,COMPLETE,UNKEY,REMDISC,REMALREADY,REMNOTFOUND,REMGO,
  123. CONNECTED,CONNFAIL,STATUS,TIMEOUT,ID1, STATS_TIME,
  124. STATS_VERSION, IDTALKOVER, ARB_ALPHA, TEST_TONE, REV_PATCH};
  125. enum {REM_SIMPLEX,REM_MINUS,REM_PLUS};
  126. enum {REM_LOWPWR,REM_MEDPWR,REM_HIPWR};
  127. enum {DC_INDETERMINATE, DC_REQ_FLUSH, DC_ERROR, DC_COMPLETE, DC_DOKEY};
  128. enum {SOURCE_RPT, SOURCE_LNK, SOURCE_RMT, SOURCE_PHONE, SOURCE_DPHONE};
  129. enum {DLY_TELEM, DLY_ID, DLY_UNKEY, DLY_CALLTERM};
  130. enum {REM_MODE_FM,REM_MODE_USB,REM_MODE_LSB,REM_MODE_AM};
  131. enum {HF_SCAN_OFF,HF_SCAN_DOWN_SLOW,HF_SCAN_DOWN_QUICK,HF_SCAN_DOWN_FAST,HF_SCAN_UP_SLOW,HF_SCAN_UP_QUICK,HF_SCAN_UP_FAST};
  132. #include "asterisk.h"
  133. ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
  134. #include <signal.h>
  135. #include <stdio.h>
  136. #include <unistd.h>
  137. #include <string.h>
  138. #include <stdlib.h>
  139. #include <search.h>
  140. #include <sys/types.h>
  141. #include <sys/stat.h>
  142. #include <errno.h>
  143. #include <dirent.h>
  144. #include <ctype.h>
  145. #include <sys/stat.h>
  146. #include <sys/time.h>
  147. #include <sys/file.h>
  148. #include <sys/ioctl.h>
  149. #include <sys/io.h>
  150. #include <math.h>
  151. #include <tonezone.h>
  152. #include <linux/zaptel.h>
  153. #include <netinet/in.h>
  154. #include <arpa/inet.h>
  155. #include "asterisk/utils.h"
  156. #include "asterisk/lock.h"
  157. #include "asterisk/file.h"
  158. #include "asterisk/logger.h"
  159. #include "asterisk/channel.h"
  160. #include "asterisk/callerid.h"
  161. #include "asterisk/pbx.h"
  162. #include "asterisk/module.h"
  163. #include "asterisk/translate.h"
  164. #include "asterisk/features.h"
  165. #include "asterisk/options.h"
  166. #include "asterisk/cli.h"
  167. #include "asterisk/config.h"
  168. #include "asterisk/say.h"
  169. #include "asterisk/localtime.h"
  170. static char *tdesc = "Radio Repeater / Remote Base version 0.37 11/03/2005";
  171. static char *app = "Rpt";
  172. static char *synopsis = "Radio Repeater/Remote Base Control System";
  173. static char *descrip =
  174. " Rpt(nodename[|options]): Radio Remote Link or Remote Base Link Endpoint Process.\n"
  175. "\n"
  176. " Not specifying an option puts it in normal endpoint mode (where source\n"
  177. " IP and nodename are verified).\n"
  178. "\n"
  179. " Options are as follows:\n"
  180. "\n"
  181. " X - Normal endpoint mode WITHOUT security check. Only specify\n"
  182. " this if you have checked security already (like with an IAX2\n"
  183. " user/password or something).\n"
  184. "\n"
  185. " Rannounce-string[|timeout[|timeout-destination]] - Amateur Radio\n"
  186. " Reverse Autopatch. Caller is put on hold, and announcement (as\n"
  187. " specified by the 'announce-string') is played on radio system.\n"
  188. " Users of radio system can access autopatch, dial specified\n"
  189. " code, and pick up call. Announce-string is list of names of\n"
  190. " recordings, or \"PARKED\" to substitute code for un-parking,\n"
  191. " or \"NODE\" to substitute node number.\n"
  192. "\n"
  193. " P - Phone Control mode. This allows a regular phone user to have\n"
  194. " full control and audio access to the radio system. For the\n"
  195. " user to have DTMF control, the 'phone_functions' parameter\n"
  196. " must be specified for the node in 'rpt.conf'. An additional\n"
  197. " function (cop,6) must be listed so that PTT control is available.\n"
  198. "\n"
  199. " D - Dumb Phone Control mode. This allows a regular phone user to\n"
  200. " have full control and audio access to the radio system. In this\n"
  201. " mode, the PTT is activated for the entire length of the call.\n"
  202. " For the user to have DTMF control (not generally recomended in\n"
  203. " this mode), the 'dphone_functions' parameter must be specified\n"
  204. " for the node in 'rpt.conf'. Otherwise no DTMF control will be\n"
  205. " available to the phone user.\n"
  206. "\n";
  207. static int debug = 0; /* Set this >0 for extra debug output */
  208. static int nrpts = 0;
  209. char *discstr = "!!DISCONNECT!!";
  210. static char *remote_rig_ft897="ft897";
  211. static char *remote_rig_rbi="rbi";
  212. struct ast_config *cfg;
  213. STANDARD_LOCAL_USER;
  214. LOCAL_USER_DECL;
  215. #define MSWAIT 200
  216. #define HANGTIME 5000
  217. #define TOTIME 180000
  218. #define IDTIME 300000
  219. #define MAXRPTS 20
  220. #define POLITEID 30000
  221. #define FUNCTDELAY 1500
  222. static pthread_t rpt_master_thread;
  223. struct rpt;
  224. struct rpt_link
  225. {
  226. struct rpt_link *next;
  227. struct rpt_link *prev;
  228. char mode; /* 1 if in tx mode */
  229. char isremote;
  230. char phonemode;
  231. char name[MAXNODESTR]; /* identifier (routing) string */
  232. char lasttx;
  233. char lastrx;
  234. char connected;
  235. char hasconnected;
  236. char outbound;
  237. char disced;
  238. char killme;
  239. long elaptime;
  240. long disctime;
  241. long retrytimer;
  242. long retxtimer;
  243. int retries;
  244. struct ast_channel *chan;
  245. struct ast_channel *pchan;
  246. } ;
  247. struct rpt_tele
  248. {
  249. struct rpt_tele *next;
  250. struct rpt_tele *prev;
  251. struct rpt *rpt;
  252. struct ast_channel *chan;
  253. int mode;
  254. struct rpt_link mylink;
  255. char param[TELEPARAMSIZE];
  256. pthread_t threadid;
  257. } ;
  258. struct function_table_tag
  259. {
  260. char action[ACTIONSIZE];
  261. int (*function)(struct rpt *myrpt, char *param, char *digitbuf,
  262. int command_source, struct rpt_link *mylink);
  263. } ;
  264. /* Used to store the morse code patterns */
  265. struct morse_bits
  266. {
  267. int len;
  268. int ddcomb;
  269. } ;
  270. struct telem_defaults
  271. {
  272. char name[20];
  273. char value[80];
  274. } ;
  275. static struct rpt
  276. {
  277. char *name;
  278. ast_mutex_t lock;
  279. char *rxchanname;
  280. char *txchanname;
  281. char *ourcontext;
  282. char *ourcallerid;
  283. char *acctcode;
  284. char *ident;
  285. char *tonezone;
  286. char *functions;
  287. char *link_functions;
  288. char *phone_functions;
  289. char *dphone_functions;
  290. char *nodes;
  291. struct rpt_link links;
  292. int hangtime;
  293. int totime;
  294. int idtime;
  295. int unkeytocttimer;
  296. char keyed;
  297. char exttx;
  298. char localtx;
  299. char remoterx;
  300. char remotetx;
  301. char remoteon;
  302. char simple;
  303. char *remote;
  304. char tounkeyed;
  305. char tonotify;
  306. char enable;
  307. char dtmfbuf[MAXDTMF];
  308. char rem_dtmfbuf[MAXDTMF];
  309. char cmdnode[50];
  310. struct ast_channel *rxchannel,*txchannel;
  311. struct ast_channel *pchannel,*txpchannel, *remchannel;
  312. struct rpt_tele tele;
  313. pthread_t rpt_call_thread,rpt_thread;
  314. time_t rem_dtmf_time,dtmf_time_rem;
  315. int tailtimer,totimer,idtimer,txconf,conf,callmode,cidx,scantimer;
  316. int mustid;
  317. int politeid;
  318. int dtmfidx,rem_dtmfidx;
  319. long retxtimer;
  320. char mydtmf;
  321. int iobase;
  322. char exten[AST_MAX_EXTENSION];
  323. char freq[MAXREMSTR],rxpl[MAXREMSTR],txpl[MAXREMSTR];
  324. char offset;
  325. char powerlevel;
  326. char txplon;
  327. char rxplon;
  328. char remmode;
  329. char tunerequest;
  330. char hfscanmode;
  331. int hfscanstatus;
  332. char lastlinknode[MAXNODESTR];
  333. char funcchar;
  334. char endchar;
  335. char stopgen;
  336. int phone_longestfunc;
  337. int dphone_longestfunc;
  338. int link_longestfunc;
  339. int longestfunc;
  340. int longestnode;
  341. int threadrestarts;
  342. time_t disgorgetime;
  343. time_t lastthreadrestarttime;
  344. char nobusyout;
  345. } rpt_vars[MAXRPTS];
  346. /*
  347. * CLI extensions
  348. */
  349. /* Debug mode */
  350. static int rpt_do_debug(int fd, int argc, char *argv[]);
  351. static char debug_usage[] =
  352. "Usage: rpt debug level {0-7}\n"
  353. " Enables debug messages in app_rpt\n";
  354. static struct ast_cli_entry cli_debug =
  355. { { "rpt", "debug", "level" }, rpt_do_debug, "Enable app_rpt debugging", debug_usage };
  356. /*
  357. * Telemetry defaults
  358. */
  359. static struct telem_defaults tele_defs[] = {
  360. {"ct1","|t(350,0,100,3072)(500,0,100,3072)(660,0,100,3072)"},
  361. {"ct2","|t(660,880,150,3072)"},
  362. {"ct3","|t(440,0,150,3072)"},
  363. {"ct4","|t(550,0,150,3072)"},
  364. {"ct5","|t(660,0,150,3072)"},
  365. {"ct6","|t(880,0,150,3072)"},
  366. {"ct7","|t(660,440,150,3072)"},
  367. {"ct8","|t(700,1100,150,3072)"},
  368. {"remotemon","|t(1600,0,75,2048)"},
  369. {"remotetx","|t(2000,0,75,2048)(0,0,75,0)(1600,0,75,2048)"},
  370. {"cmdmode","|t(900,904,200,2048)"},
  371. {"functcomplete","|t(1000,0,100,2048)(0,0,100,0)(1000,0,100,2048)"}
  372. } ;
  373. /*
  374. * Forward decl's - these suppress compiler warnings when funcs coded further down the file than thier invokation
  375. */
  376. static int setrbi(struct rpt *myrpt);
  377. /*
  378. * Define function protos for function table here
  379. */
  380. static int function_ilink(struct rpt *myrpt, char *param, char *digitbuf, int command_source, struct rpt_link *mylink);
  381. static int function_autopatchup(struct rpt *myrpt, char *param, char *digitbuf, int command_source, struct rpt_link *mylink);
  382. static int function_autopatchdn(struct rpt *myrpt, char *param, char *digitbuf, int command_source, struct rpt_link *mylink);
  383. static int function_status(struct rpt *myrpt, char *param, char *digitbuf, int command_source, struct rpt_link *mylink);
  384. static int function_cop(struct rpt *myrpt, char *param, char *digitbuf, int command_source, struct rpt_link *mylink);
  385. static int function_remote(struct rpt *myrpt, char *param, char *digitbuf, int command_source, struct rpt_link *mylink);
  386. /*
  387. * Function table
  388. */
  389. static struct function_table_tag function_table[] = {
  390. {"cop", function_cop},
  391. {"autopatchup", function_autopatchup},
  392. {"autopatchdn", function_autopatchdn},
  393. {"ilink", function_ilink},
  394. {"status", function_status},
  395. {"remote", function_remote}
  396. } ;
  397. static int myatoi(char *str)
  398. {
  399. int ret;
  400. if (str == NULL) return -1;
  401. /* leave this %i alone, non-base-10 input is useful here */
  402. if (sscanf(str,"%i",&ret) != 1) return -1;
  403. return ret;
  404. }
  405. /*
  406. * Enable or disable debug output at a given level at the console
  407. */
  408. static int rpt_do_debug(int fd, int argc, char *argv[])
  409. {
  410. int newlevel;
  411. if (argc != 4)
  412. return RESULT_SHOWUSAGE;
  413. newlevel = myatoi(argv[3]);
  414. if((newlevel < 0) || (newlevel > 7))
  415. return RESULT_SHOWUSAGE;
  416. if(newlevel)
  417. ast_cli(fd, "app_rpt Debugging enabled, previous level: %d, new level: %d\n", debug, newlevel);
  418. else
  419. ast_cli(fd, "app_rpt Debugging disabled\n");
  420. debug = newlevel;
  421. return RESULT_SUCCESS;
  422. }
  423. static int play_tone_pair(struct ast_channel *chan, int f1, int f2, int duration, int amplitude)
  424. {
  425. int res;
  426. if ((res = ast_tonepair_start(chan, f1, f2, duration, amplitude)))
  427. return res;
  428. while(chan->generatordata) {
  429. if (ast_safe_sleep(chan,1)) return -1;
  430. }
  431. return 0;
  432. }
  433. static int play_tone(struct ast_channel *chan, int freq, int duration, int amplitude)
  434. {
  435. return play_tone_pair(chan, freq, 0, duration, amplitude);
  436. }
  437. static int play_silence(struct ast_channel *chan, int duration)
  438. {
  439. return play_tone_pair(chan, 0, 0, duration, 0);
  440. }
  441. static int send_morse(struct ast_channel *chan, char *string, int speed, int freq, int amplitude)
  442. {
  443. static struct morse_bits mbits[] = {
  444. {0, 0}, /* SPACE */
  445. {0, 0},
  446. {6, 18},/* " */
  447. {0, 0},
  448. {7, 72},/* $ */
  449. {0, 0},
  450. {0, 0},
  451. {6, 30},/* ' */
  452. {5, 13},/* ( */
  453. {6, 29},/* ) */
  454. {0, 0},
  455. {5, 10},/* + */
  456. {6, 51},/* , */
  457. {6, 33},/* - */
  458. {6, 42},/* . */
  459. {5, 9}, /* / */
  460. {5, 31},/* 0 */
  461. {5, 30},/* 1 */
  462. {5, 28},/* 2 */
  463. {5, 24},/* 3 */
  464. {5, 16},/* 4 */
  465. {5, 0}, /* 5 */
  466. {5, 1}, /* 6 */
  467. {5, 3}, /* 7 */
  468. {5, 7}, /* 8 */
  469. {5, 15},/* 9 */
  470. {6, 7}, /* : */
  471. {6, 21},/* ; */
  472. {0, 0},
  473. {5, 33},/* = */
  474. {0, 0},
  475. {6, 12},/* ? */
  476. {0, 0},
  477. {2, 2}, /* A */
  478. {4, 1}, /* B */
  479. {4, 5}, /* C */
  480. {3, 1}, /* D */
  481. {1, 0}, /* E */
  482. {4, 4}, /* F */
  483. {3, 3}, /* G */
  484. {4, 0}, /* H */
  485. {2, 0}, /* I */
  486. {4, 14},/* J */
  487. {3, 5}, /* K */
  488. {4, 2}, /* L */
  489. {2, 3}, /* M */
  490. {2, 1}, /* N */
  491. {3, 7}, /* O */
  492. {4, 6}, /* P */
  493. {4, 11},/* Q */
  494. {3, 2}, /* R */
  495. {3, 0}, /* S */
  496. {1, 1}, /* T */
  497. {3, 4}, /* U */
  498. {4, 8}, /* V */
  499. {3, 6}, /* W */
  500. {4, 9}, /* X */
  501. {4, 13},/* Y */
  502. {4, 3} /* Z */
  503. };
  504. int dottime;
  505. int dashtime;
  506. int intralettertime;
  507. int interlettertime;
  508. int interwordtime;
  509. int len, ddcomb;
  510. int res;
  511. int c;
  512. int i;
  513. int flags;
  514. res = 0;
  515. /* Approximate the dot time from the speed arg. */
  516. dottime = 900/speed;
  517. /* Establish timing releationships */
  518. dashtime = 3 * dottime;
  519. intralettertime = dottime;
  520. interlettertime = dottime * 4 ;
  521. interwordtime = dottime * 7;
  522. for(;(*string) && (!res); string++){
  523. c = *string;
  524. /* Convert lower case to upper case */
  525. if((c >= 'a') && (c <= 'z'))
  526. c -= 0x20;
  527. /* Can't deal with any char code greater than Z, skip it */
  528. if(c > 'Z')
  529. continue;
  530. /* If space char, wait the inter word time */
  531. if(c == ' '){
  532. if(!res)
  533. res = play_silence(chan, interwordtime);
  534. continue;
  535. }
  536. /* Subtract out control char offset to match our table */
  537. c -= 0x20;
  538. /* Get the character data */
  539. len = mbits[c].len;
  540. ddcomb = mbits[c].ddcomb;
  541. /* Send the character */
  542. for(; len ; len--){
  543. if(!res)
  544. res = play_tone(chan, freq, (ddcomb & 1) ? dashtime : dottime, amplitude);
  545. if(!res)
  546. res = play_silence(chan, intralettertime);
  547. ddcomb >>= 1;
  548. }
  549. /* Wait the interletter time */
  550. if(!res)
  551. res = play_silence(chan, interlettertime - intralettertime);
  552. }
  553. /* Wait for all the frames to be sent */
  554. if (!res)
  555. res = ast_waitstream(chan, "");
  556. ast_stopstream(chan);
  557. /*
  558. * Wait for the zaptel driver to physically write the tone blocks to the hardware
  559. */
  560. for(i = 0; i < 20 ; i++){
  561. flags = ZT_IOMUX_WRITEEMPTY | ZT_IOMUX_NOWAIT;
  562. res = ioctl(chan->fds[0], ZT_IOMUX, &flags);
  563. if(flags & ZT_IOMUX_WRITEEMPTY)
  564. break;
  565. if( ast_safe_sleep(chan, 50)){
  566. res = -1;
  567. break;
  568. }
  569. }
  570. return res;
  571. }
  572. static int send_tone_telemetry(struct ast_channel *chan, char *tonestring)
  573. {
  574. char *stringp;
  575. char *tonesubset;
  576. int f1,f2;
  577. int duration;
  578. int amplitude;
  579. int res;
  580. int i;
  581. int flags;
  582. res = 0;
  583. stringp = ast_strdupa(tonestring);
  584. for(;tonestring;){
  585. tonesubset = strsep(&stringp,")");
  586. if(!tonesubset)
  587. break;
  588. if(sscanf(tonesubset,"(%d,%d,%d,%d", &f1, &f2, &duration, &amplitude) != 4)
  589. break;
  590. res = play_tone_pair(chan, f1, f2, duration, amplitude);
  591. if(res)
  592. break;
  593. }
  594. if(!res)
  595. res = play_tone_pair(chan, 0, 0, 100, 0); /* This is needed to ensure the last tone segment is timed correctly */
  596. if (!res)
  597. res = ast_waitstream(chan, "");
  598. ast_stopstream(chan);
  599. /*
  600. * Wait for the zaptel driver to physically write the tone blocks to the hardware
  601. */
  602. for(i = 0; i < 20 ; i++){
  603. flags = ZT_IOMUX_WRITEEMPTY | ZT_IOMUX_NOWAIT;
  604. res = ioctl(chan->fds[0], ZT_IOMUX, &flags);
  605. if(flags & ZT_IOMUX_WRITEEMPTY)
  606. break;
  607. if( ast_safe_sleep(chan, 50)){
  608. res = -1;
  609. break;
  610. }
  611. }
  612. return res;
  613. }
  614. static int sayfile(struct ast_channel *mychannel,char *fname)
  615. {
  616. int res;
  617. res = ast_streamfile(mychannel, fname, mychannel->language);
  618. if (!res)
  619. res = ast_waitstream(mychannel, "");
  620. else
  621. ast_log(LOG_WARNING, "ast_streamfile failed on %s\n", mychannel->name);
  622. ast_stopstream(mychannel);
  623. return res;
  624. }
  625. static int saycharstr(struct ast_channel *mychannel,char *str)
  626. {
  627. int res;
  628. res = ast_say_character_str(mychannel,str,NULL,mychannel->language);
  629. if (!res)
  630. res = ast_waitstream(mychannel, "");
  631. else
  632. ast_log(LOG_WARNING, "ast_streamfile failed on %s\n", mychannel->name);
  633. ast_stopstream(mychannel);
  634. return res;
  635. }
  636. static int saynum(struct ast_channel *mychannel, int num)
  637. {
  638. int res;
  639. res = ast_say_number(mychannel, num, NULL, mychannel->language, NULL);
  640. if(!res)
  641. res = ast_waitstream(mychannel, "");
  642. else
  643. ast_log(LOG_WARNING, "ast_streamfile failed on %s\n", mychannel->name);
  644. ast_stopstream(mychannel);
  645. return res;
  646. }
  647. /* Retrieve an int from a config file */
  648. static int retrieve_astcfgint(char *category, char *name, int min, int max, int defl)
  649. {
  650. char *var;
  651. int ret;
  652. var = ast_variable_retrieve(cfg, category, name);
  653. if(var){
  654. ret = myatoi(var);
  655. if(ret < min)
  656. ret = min;
  657. if(ret > max)
  658. ret = max;
  659. }
  660. else
  661. ret = defl;
  662. return ret;
  663. }
  664. static int telem_any(struct ast_channel *chan, char *entry)
  665. {
  666. int res;
  667. char c;
  668. static int morsespeed;
  669. static int morsefreq;
  670. static int morseampl;
  671. static int morseidfreq = 0;
  672. static int morseidampl;
  673. static char mcat[] = MORSE;
  674. res = 0;
  675. if(!morseidfreq){ /* Get the morse parameters if not already loaded */
  676. morsespeed = retrieve_astcfgint( mcat, "speed", 5, 20, 20);
  677. morsefreq = retrieve_astcfgint( mcat, "frequency", 300, 3000, 800);
  678. morseampl = retrieve_astcfgint( mcat, "amplitude", 200, 8192, 4096);
  679. morseidampl = retrieve_astcfgint( mcat, "idamplitude", 200, 8192, 2048);
  680. morseidfreq = retrieve_astcfgint( mcat, "idfrequency", 300, 3000, 330);
  681. }
  682. /* Is it a file, or a tone sequence? */
  683. if(entry[0] == '|'){
  684. c = entry[1];
  685. if((c >= 'a')&&(c <= 'z'))
  686. c -= 0x20;
  687. switch(c){
  688. case 'I': /* Morse ID */
  689. res = send_morse(chan, entry + 2, morsespeed, morseidfreq, morseidampl);
  690. break;
  691. case 'M': /* Morse Message */
  692. res = send_morse(chan, entry + 2, morsespeed, morsefreq, morseampl);
  693. break;
  694. case 'T': /* Tone sequence */
  695. res = send_tone_telemetry(chan, entry + 2);
  696. break;
  697. default:
  698. res = -1;
  699. }
  700. }
  701. else
  702. res = sayfile(chan, entry); /* File */
  703. return res;
  704. }
  705. /*
  706. * This function looks up a telemetry name in the config file, and does a telemetry response as configured.
  707. *
  708. * 4 types of telemtry are handled: Morse ID, Morse Message, Tone Sequence, and a File containing a recording.
  709. */
  710. static int telem_lookup(struct ast_channel *chan, char *node, char *name)
  711. {
  712. int res;
  713. int i;
  714. char *entry;
  715. char *telemetry;
  716. char *telemetry_save;
  717. res = 0;
  718. telemetry_save = NULL;
  719. entry = NULL;
  720. /* Retrieve the section name for telemetry from the node section */
  721. telemetry = ast_variable_retrieve(cfg, node, TELEMETRY);
  722. if(telemetry){
  723. telemetry_save = ast_strdupa(telemetry);
  724. if(!telemetry_save){
  725. ast_log(LOG_WARNING,"ast_strdupa() failed in telem_lookup()\n");
  726. return res;
  727. }
  728. entry = ast_variable_retrieve(cfg, telemetry_save, name);
  729. }
  730. /* Try to look up the telemetry name */
  731. if(!entry){
  732. /* Telemetry name wasn't found in the config file, use the default */
  733. for(i = 0; i < sizeof(tele_defs)/sizeof(struct telem_defaults) ; i++){
  734. if(!strcasecmp(tele_defs[i].name, name))
  735. entry = tele_defs[i].value;
  736. }
  737. }
  738. if(entry)
  739. telem_any(chan, entry);
  740. else{
  741. ast_log(LOG_WARNING, "Telemetry name not found: %s\n", name);
  742. res = -1;
  743. }
  744. return res;
  745. }
  746. /*
  747. * Retrieve a wait interval
  748. */
  749. static int get_wait_interval(struct rpt *myrpt, int type)
  750. {
  751. int interval;
  752. char *wait_times;
  753. char *wait_times_save;
  754. wait_times_save = NULL;
  755. wait_times = ast_variable_retrieve(cfg, myrpt->name, "wait_times");
  756. if(wait_times){
  757. wait_times_save = ast_strdupa(wait_times);
  758. if(!wait_times_save){
  759. ast_log(LOG_WARNING, "Out of memory in wait_interval()\n");
  760. wait_times = NULL;
  761. }
  762. }
  763. switch(type){
  764. case DLY_TELEM:
  765. if(wait_times)
  766. interval = retrieve_astcfgint(wait_times_save, "telemwait", 500, 5000, 1000);
  767. else
  768. interval = 1000;
  769. break;
  770. case DLY_ID:
  771. if(wait_times)
  772. interval = retrieve_astcfgint(wait_times_save, "idwait",250,5000,500);
  773. else
  774. interval = 500;
  775. break;
  776. case DLY_UNKEY:
  777. if(wait_times)
  778. interval = retrieve_astcfgint(wait_times_save, "unkeywait",500,5000,1000);
  779. else
  780. interval = 1000;
  781. break;
  782. case DLY_CALLTERM:
  783. if(wait_times)
  784. interval = retrieve_astcfgint(wait_times_save, "calltermwait",500,5000,1500);
  785. else
  786. interval = 1500;
  787. break;
  788. default:
  789. return 0;
  790. }
  791. return interval;
  792. }
  793. /*
  794. * Wait a configurable interval of time
  795. */
  796. static void wait_interval(struct rpt *myrpt, int type, struct ast_channel *chan)
  797. {
  798. int interval;
  799. if((interval = get_wait_interval(myrpt, type)))
  800. ast_safe_sleep(chan,interval);
  801. return;
  802. }
  803. static void *rpt_tele_thread(void *this)
  804. {
  805. ZT_CONFINFO ci; /* conference info */
  806. int res = 0,haslink,hastx,hasremote,imdone = 0, unkeys_queued, x;
  807. struct rpt_tele *mytele = (struct rpt_tele *)this;
  808. struct rpt_tele *tlist;
  809. struct rpt *myrpt;
  810. struct rpt_link *l,*m,linkbase;
  811. struct ast_channel *mychannel;
  812. int vmajor, vminor;
  813. char *p,*ct,*ct_copy,*ident, *nodename;
  814. time_t t;
  815. struct tm localtm;
  816. /* get a pointer to myrpt */
  817. myrpt = mytele->rpt;
  818. /* Snag copies of a few key myrpt variables */
  819. ast_mutex_lock(&myrpt->lock);
  820. nodename = ast_strdupa(myrpt->name);
  821. ident = ast_strdupa(myrpt->ident);
  822. ast_mutex_unlock(&myrpt->lock);
  823. /* allocate a pseudo-channel thru asterisk */
  824. mychannel = ast_request("zap",AST_FORMAT_SLINEAR,"pseudo",NULL);
  825. if (!mychannel)
  826. {
  827. fprintf(stderr,"rpt:Sorry unable to obtain pseudo channel\n");
  828. ast_mutex_lock(&myrpt->lock);
  829. remque((struct qelem *)mytele);
  830. ast_mutex_unlock(&myrpt->lock);
  831. free(mytele);
  832. pthread_exit(NULL);
  833. }
  834. ast_mutex_lock(&myrpt->lock);
  835. mytele->chan = mychannel; /* Save a copy of the channel so we can access it externally if need be */
  836. ast_mutex_unlock(&myrpt->lock);
  837. /* make a conference for the tx */
  838. ci.chan = 0;
  839. /* If there's an ID queued, only connect the ID audio to the local tx conference so
  840. linked systems can't hear it */
  841. ci.confno = (((mytele->mode == ID) || (mytele->mode == IDTALKOVER) || (mytele->mode == UNKEY)) ?
  842. myrpt->txconf : myrpt->conf);
  843. ci.confmode = ZT_CONF_CONFANN;
  844. /* first put the channel on the conference in announce mode */
  845. if (ioctl(mychannel->fds[0],ZT_SETCONF,&ci) == -1)
  846. {
  847. ast_log(LOG_WARNING, "Unable to set conference mode to Announce\n");
  848. ast_mutex_lock(&myrpt->lock);
  849. remque((struct qelem *)mytele);
  850. ast_mutex_unlock(&myrpt->lock);
  851. free(mytele);
  852. ast_hangup(mychannel);
  853. pthread_exit(NULL);
  854. }
  855. ast_stopstream(mychannel);
  856. switch(mytele->mode)
  857. {
  858. case ID:
  859. case ID1:
  860. /* wait a bit */
  861. wait_interval(myrpt, (mytele->mode == ID) ? DLY_ID : DLY_TELEM,mychannel);
  862. res = telem_any(mychannel, ident);
  863. imdone=1;
  864. break;
  865. case IDTALKOVER:
  866. p = ast_variable_retrieve(cfg, nodename, "idtalkover");
  867. if(p)
  868. res = telem_any(mychannel, p);
  869. imdone=1;
  870. break;
  871. case PROC:
  872. /* wait a little bit longer */
  873. wait_interval(myrpt, DLY_TELEM, mychannel);
  874. res = ast_streamfile(mychannel, "rpt/callproceeding", mychannel->language);
  875. break;
  876. case TERM:
  877. /* wait a little bit longer */
  878. wait_interval(myrpt, DLY_CALLTERM, mychannel);
  879. res = ast_streamfile(mychannel, "rpt/callterminated", mychannel->language);
  880. break;
  881. case COMPLETE:
  882. /* wait a little bit */
  883. wait_interval(myrpt, DLY_TELEM, mychannel);
  884. res = telem_lookup(mychannel, myrpt->name, "functcomplete");
  885. break;
  886. case UNKEY:
  887. /*
  888. * Reset the Unkey to CT timer
  889. */
  890. x = get_wait_interval(myrpt, DLY_UNKEY);
  891. ast_mutex_lock(&myrpt->lock);
  892. myrpt->unkeytocttimer = x; /* Must be protected as it is changed below */
  893. ast_mutex_unlock(&myrpt->lock);
  894. /*
  895. * If there's one already queued, don't do another
  896. */
  897. tlist = myrpt->tele.next;
  898. unkeys_queued = 0;
  899. if (tlist != &myrpt->tele)
  900. {
  901. ast_mutex_lock(&myrpt->lock);
  902. while(tlist != &myrpt->tele){
  903. if (tlist->mode == UNKEY) unkeys_queued++;
  904. tlist = tlist->next;
  905. }
  906. ast_mutex_unlock(&myrpt->lock);
  907. }
  908. if( unkeys_queued > 1){
  909. imdone = 1;
  910. break;
  911. }
  912. /* Wait for the telemetry timer to expire */
  913. /* Periodically check the timer since it can be re-initialized above */
  914. while(myrpt->unkeytocttimer)
  915. {
  916. int ctint;
  917. if(myrpt->unkeytocttimer > 100)
  918. ctint = 100;
  919. else
  920. ctint = myrpt->unkeytocttimer;
  921. ast_safe_sleep(mychannel, ctint);
  922. ast_mutex_lock(&myrpt->lock);
  923. if(myrpt->unkeytocttimer < ctint)
  924. myrpt->unkeytocttimer = 0;
  925. else
  926. myrpt->unkeytocttimer -= ctint;
  927. ast_mutex_unlock(&myrpt->lock);
  928. }
  929. /*
  930. * Now, the carrier on the rptr rx should be gone.
  931. * If it re-appeared, then forget about sending the CT
  932. */
  933. if(myrpt->keyed){
  934. imdone = 1;
  935. break;
  936. }
  937. haslink = 0;
  938. hastx = 0;
  939. hasremote = 0;
  940. l = myrpt->links.next;
  941. if (l != &myrpt->links)
  942. {
  943. ast_mutex_lock(&myrpt->lock);
  944. while(l != &myrpt->links)
  945. {
  946. if (l->name[0] == '0')
  947. {
  948. l = l->next;
  949. continue;
  950. }
  951. haslink = 1;
  952. if (l->mode) {
  953. hastx++;
  954. if (l->isremote) hasremote++;
  955. }
  956. l = l->next;
  957. }
  958. ast_mutex_unlock(&myrpt->lock);
  959. }
  960. if (haslink)
  961. {
  962. res = telem_lookup(mychannel, myrpt->name, (!hastx) ? "remotemon" : "remotetx");
  963. if(res)
  964. ast_log(LOG_WARNING, "telem_lookup:remotexx failed on %s\n", mychannel->name);
  965. /* if in remote cmd mode, indicate it */
  966. if (myrpt->cmdnode[0])
  967. {
  968. ast_safe_sleep(mychannel,200);
  969. res = telem_lookup(mychannel, myrpt->name, "cmdmode");
  970. if(res)
  971. ast_log(LOG_WARNING, "telem_lookup:cmdmode failed on %s\n", mychannel->name);
  972. ast_stopstream(mychannel);
  973. }
  974. }
  975. else if((ct = ast_variable_retrieve(cfg, nodename, "unlinkedct"))){ /* Unlinked Courtesy Tone */
  976. ct_copy = ast_strdupa(ct);
  977. res = telem_lookup(mychannel, myrpt->name, ct_copy);
  978. if(res)
  979. ast_log(LOG_WARNING, "telem_lookup:ctx failed on %s\n", mychannel->name);
  980. }
  981. if (hasremote && (!myrpt->cmdnode[0]))
  982. {
  983. /* set for all to hear */
  984. ci.chan = 0;
  985. ci.confno = myrpt->conf;
  986. ci.confmode = ZT_CONF_CONFANN;
  987. /* first put the channel on the conference in announce mode */
  988. if (ioctl(mychannel->fds[0],ZT_SETCONF,&ci) == -1)
  989. {
  990. ast_log(LOG_WARNING, "Unable to set conference mode to Announce\n");
  991. ast_mutex_lock(&myrpt->lock);
  992. remque((struct qelem *)mytele);
  993. ast_mutex_unlock(&myrpt->lock);
  994. free(mytele);
  995. ast_hangup(mychannel);
  996. pthread_exit(NULL);
  997. }
  998. if((ct = ast_variable_retrieve(cfg, nodename, "remotect"))){ /* Unlinked Courtesy Tone */
  999. ast_safe_sleep(mychannel,200);
  1000. ct_copy = ast_strdupa(ct);
  1001. res = telem_lookup(mychannel, myrpt->name, ct_copy);
  1002. if(res)
  1003. ast_log(LOG_WARNING, "telem_lookup:ctx failed on %s\n", mychannel->name);
  1004. }
  1005. }
  1006. imdone = 1;
  1007. break;
  1008. case REMDISC:
  1009. /* wait a little bit */
  1010. wait_interval(myrpt, DLY_TELEM, mychannel);
  1011. res = ast_streamfile(mychannel, "rpt/node", mychannel->language);
  1012. if (!res)
  1013. res = ast_waitstream(mychannel, "");
  1014. else
  1015. ast_log(LOG_WARNING, "ast_streamfile failed on %s\n", mychannel->name);
  1016. ast_stopstream(mychannel);
  1017. ast_say_character_str(mychannel,mytele->mylink.name,NULL,mychannel->language);
  1018. res = ast_streamfile(mychannel, ((mytele->mylink.connected) ?
  1019. "rpt/remote_disc" : "rpt/remote_busy"), mychannel->language);
  1020. break;
  1021. case REMALREADY:
  1022. /* wait a little bit */
  1023. wait_interval(myrpt, DLY_TELEM, mychannel);
  1024. res = ast_streamfile(mychannel, "rpt/remote_already", mychannel->language);
  1025. break;
  1026. case REMNOTFOUND:
  1027. /* wait a little bit */
  1028. wait_interval(myrpt, DLY_TELEM, mychannel);
  1029. res = ast_streamfile(mychannel, "rpt/remote_notfound", mychannel->language);
  1030. break;
  1031. case REMGO:
  1032. /* wait a little bit */
  1033. wait_interval(myrpt, DLY_TELEM, mychannel);
  1034. res = ast_streamfile(mychannel, "rpt/remote_go", mychannel->language);
  1035. break;
  1036. case CONNECTED:
  1037. /* wait a little bit */
  1038. wait_interval(myrpt, DLY_TELEM, mychannel);
  1039. res = ast_streamfile(mychannel, "rpt/node", mychannel->language);
  1040. if (!res)
  1041. res = ast_waitstream(mychannel, "");
  1042. else
  1043. ast_log(LOG_WARNING, "ast_streamfile failed on %s\n", mychannel->name);
  1044. ast_stopstream(mychannel);
  1045. ast_say_character_str(mychannel,mytele->mylink.name,NULL,mychannel->language);
  1046. res = ast_streamfile(mychannel, "rpt/connected", mychannel->language);
  1047. break;
  1048. case CONNFAIL:
  1049. res = ast_streamfile(mychannel, "rpt/node", mychannel->language);
  1050. if (!res)
  1051. res = ast_waitstream(mychannel, "");
  1052. else
  1053. ast_log(LOG_WARNING, "ast_streamfile failed on %s\n", mychannel->name);
  1054. ast_stopstream(mychannel);
  1055. ast_say_character_str(mychannel,mytele->mylink.name,NULL,mychannel->language);
  1056. res = ast_streamfile(mychannel, "rpt/connection_failed", mychannel->language);
  1057. break;
  1058. case STATUS:
  1059. /* wait a little bit */
  1060. wait_interval(myrpt, DLY_TELEM, mychannel);
  1061. hastx = 0;
  1062. linkbase.next = &linkbase;
  1063. linkbase.prev = &linkbase;
  1064. ast_mutex_lock(&myrpt->lock);
  1065. /* make our own list of links */
  1066. l = myrpt->links.next;
  1067. while(l != &myrpt->links)
  1068. {
  1069. if (l->name[0] == '0')
  1070. {
  1071. l = l->next;
  1072. continue;
  1073. }
  1074. m = malloc(sizeof(struct rpt_link));
  1075. if (!m)
  1076. {
  1077. ast_log(LOG_WARNING, "Cannot alloc memory on %s\n", mychannel->name);
  1078. ast_mutex_lock(&myrpt->lock);
  1079. remque((struct qelem *)mytele);
  1080. ast_mutex_unlock(&myrpt->lock);
  1081. free(mytele);
  1082. ast_hangup(mychannel);
  1083. pthread_exit(NULL);
  1084. }
  1085. memcpy(m,l,sizeof(struct rpt_link));
  1086. m->next = m->prev = NULL;
  1087. insque((struct qelem *)m,(struct qelem *)linkbase.next);
  1088. l = l->next;
  1089. }
  1090. ast_mutex_unlock(&myrpt->lock);
  1091. res = ast_streamfile(mychannel, "rpt/node", mychannel->language);
  1092. if (!res)
  1093. res = ast_waitstream(mychannel, "");
  1094. else
  1095. ast_log(LOG_WARNING, "ast_streamfile failed on %s\n", mychannel->name);
  1096. ast_stopstream(mychannel);
  1097. ast_say_character_str(mychannel,myrpt->name,NULL,mychannel->language);
  1098. if (!res)
  1099. res = ast_waitstream(mychannel, "");
  1100. else
  1101. ast_log(LOG_WARNING, "ast_streamfile failed on %s\n", mychannel->name);
  1102. ast_stopstream(mychannel);
  1103. if (myrpt->callmode)
  1104. {
  1105. hastx = 1;
  1106. res = ast_streamfile(mychannel, "rpt/autopatch_on", mychannel->language);
  1107. if (!res)
  1108. res = ast_waitstream(mychannel, "");
  1109. else
  1110. ast_log(LOG_WARNING, "ast_streamfile failed on %s\n", mychannel->name);
  1111. ast_stopstream(mychannel);
  1112. }
  1113. l = linkbase.next;
  1114. while(l != &linkbase)
  1115. {
  1116. hastx = 1;
  1117. res = ast_streamfile(mychannel, "rpt/node", mychannel->language);
  1118. if (!res)
  1119. res = ast_waitstream(mychannel, "");
  1120. else
  1121. ast_log(LOG_WARNING, "ast_streamfile failed on %s\n", mychannel->name);
  1122. ast_stopstream(mychannel);
  1123. ast_say_character_str(mychannel,l->name,NULL,mychannel->language);
  1124. if (!res)
  1125. res = ast_waitstream(mychannel, "");
  1126. else
  1127. ast_log(LOG_WARNING, "ast_streamfile failed on %s\n", mychannel->name);
  1128. ast_stopstream(mychannel);
  1129. res = ast_streamfile(mychannel, ((l->mode) ?
  1130. "rpt/tranceive" : "rpt/monitor"), mychannel->language);
  1131. if (!res)
  1132. res = ast_waitstream(mychannel, "");
  1133. else
  1134. ast_log(LOG_WARNING, "ast_streamfile failed on %s\n", mychannel->name);
  1135. ast_stopstream(mychannel);
  1136. l = l->next;
  1137. }
  1138. if (!hastx)
  1139. {
  1140. res = ast_streamfile(mychannel, "rpt/repeat_only", mychannel->language);
  1141. if (!res)
  1142. res = ast_waitstream(mychannel, "");
  1143. else
  1144. ast_log(LOG_WARNING, "ast_streamfile failed on %s\n", mychannel->name);
  1145. ast_stopstream(mychannel);
  1146. }
  1147. /* destroy our local link queue */
  1148. l = linkbase.next;
  1149. while(l != &linkbase)
  1150. {
  1151. m = l;
  1152. l = l->next;
  1153. remque((struct qelem *)m);
  1154. free(m);
  1155. }
  1156. imdone = 1;
  1157. break;
  1158. case TIMEOUT:
  1159. res = ast_streamfile(mychannel, "rpt/node", mychannel->language);
  1160. if (!res)
  1161. res = ast_waitstream(mychannel, "");
  1162. else
  1163. ast_log(LOG_WARNING, "ast_streamfile failed on %s\n", mychannel->name);
  1164. ast_stopstream(mychannel);
  1165. ast_say_character_str(mychannel,myrpt->name,NULL,mychannel->language);
  1166. res = ast_streamfile(mychannel, "rpt/timeout", mychannel->language);
  1167. break;
  1168. case STATS_TIME:
  1169. wait_interval(myrpt, DLY_TELEM, mychannel); /* Wait a little bit */
  1170. t = time(NULL);
  1171. localtime_r(&t, &localtm);
  1172. /* Say the phase of the day is before the time */
  1173. if((localtm.tm_hour >= 0) && (localtm.tm_hour < 12))
  1174. p = "rpt/goodmorning";
  1175. else if((localtm.tm_hour >= 12) && (localtm.tm_hour < 18))
  1176. p = "rpt/goodafternoon";
  1177. else
  1178. p = "rpt/goodevening";
  1179. if (sayfile(mychannel,p) == -1)
  1180. {
  1181. imdone = 1;
  1182. break;
  1183. }
  1184. /* Say the time is ... */
  1185. if (sayfile(mychannel,"rpt/thetimeis") == -1)
  1186. {
  1187. imdone = 1;
  1188. break;
  1189. }
  1190. /* Say the time */
  1191. res = ast_say_time(mychannel, t, "", mychannel->language);
  1192. if (!res)
  1193. res = ast_waitstream(mychannel, "");
  1194. ast_stopstream(mychannel);
  1195. imdone = 1;
  1196. break;
  1197. case STATS_VERSION:
  1198. p = strstr(tdesc, "version");
  1199. if(!p)
  1200. break;
  1201. if(sscanf(p, "version %d.%d", &vmajor, &vminor) != 2)
  1202. break;
  1203. wait_interval(myrpt, DLY_TELEM, mychannel); /* Wait a little bit */
  1204. /* Say "version" */
  1205. if (sayfile(mychannel,"rpt/version") == -1)
  1206. {
  1207. imdone = 1;
  1208. break;
  1209. }
  1210. if(!res) /* Say "X" */
  1211. ast_say_number(mychannel, vmajor, "", mychannel->language, (char *) NULL);
  1212. if (!res)
  1213. res = ast_waitstream(mychannel, "");
  1214. ast_stopstream(mychannel);
  1215. if (saycharstr(mychannel,".") == -1)
  1216. {
  1217. imdone = 1;
  1218. break;
  1219. }
  1220. if(!res) /* Say "Y" */
  1221. ast_say_number(mychannel, vminor, "", mychannel->language, (char *) NULL);
  1222. if (!res){
  1223. res = ast_waitstream(mychannel, "");
  1224. ast_stopstream(mychannel);
  1225. }
  1226. else
  1227. ast_log(LOG_WARNING, "ast_streamfile failed on %s\n", mychannel->name);
  1228. imdone = 1;
  1229. break;
  1230. case ARB_ALPHA:
  1231. wait_interval(myrpt, DLY_TELEM, mychannel); /* Wait a little bit */
  1232. if(mytele->param)
  1233. saycharstr(mychannel, mytele->param);
  1234. imdone = 1;
  1235. break;
  1236. case REV_PATCH:
  1237. wait_interval(myrpt, DLY_TELEM, mychannel); /* Wait a little bit */
  1238. if(mytele->param) {
  1239. /* Parts of this section taken from app_parkandannounce */
  1240. char *tpl_working, *tpl_current;
  1241. char *tmp[100], *myparm;
  1242. int looptemp=0,i=0, dres = 0;
  1243. tpl_working = strdupa(mytele->param);
  1244. myparm = strsep(&tpl_working,",");
  1245. tpl_current=strsep(&tpl_working, ":");
  1246. while(tpl_current && looptemp < sizeof(tmp)) {
  1247. tmp[looptemp]=tpl_current;
  1248. looptemp++;
  1249. tpl_current=strsep(&tpl_working,":");
  1250. }
  1251. for(i=0; i<looptemp; i++) {
  1252. if(!strcmp(tmp[i], "PARKED")) {
  1253. ast_say_digits(mychannel, atoi(myparm), "", mychannel->language);
  1254. } else if(!strcmp(tmp[i], "NODE")) {
  1255. ast_say_digits(mychannel, atoi(myrpt->name), "", mychannel->language);
  1256. } else {
  1257. dres = ast_streamfile(mychannel, tmp[i], mychannel->language);
  1258. if(!dres) {
  1259. dres = ast_waitstream(mychannel, "");
  1260. } else {
  1261. ast_log(LOG_WARNING, "ast_streamfile of %s failed on %s\n", tmp[i], mychannel->name);
  1262. dres = 0;
  1263. }
  1264. }
  1265. }
  1266. }
  1267. imdone = 1;
  1268. break;
  1269. case TEST_TONE:
  1270. imdone = 1;
  1271. myrpt->stopgen = 0;
  1272. if ((res = ast_tonepair_start(mychannel, 1004.0, 0, 99999999, 7200.0)))
  1273. break;
  1274. while(mychannel->generatordata && (!myrpt->stopgen)) {
  1275. if (ast_safe_sleep(mychannel,1)) break;
  1276. imdone = 1;
  1277. }
  1278. break;
  1279. default:
  1280. break;
  1281. }
  1282. myrpt->stopgen = 0;
  1283. if (!imdone)
  1284. {
  1285. if (!res)
  1286. res = ast_waitstream(mychannel, "");
  1287. else {
  1288. ast_log(LOG_WARNING, "ast_streamfile failed on %s\n", mychannel->name);
  1289. res = 0;
  1290. }
  1291. }
  1292. ast_stopstream(mychannel);
  1293. ast_mutex_lock(&myrpt->lock);
  1294. remque((struct qelem *)mytele);
  1295. ast_mutex_unlock(&myrpt->lock);
  1296. free(mytele);
  1297. ast_hangup(mychannel);
  1298. pthread_exit(NULL);
  1299. }
  1300. static void rpt_telemetry(struct rpt *myrpt,int mode, void *data)
  1301. {
  1302. struct rpt_tele *tele;
  1303. struct rpt_link *mylink = (struct rpt_link *) data;
  1304. pthread_attr_t attr;
  1305. tele = malloc(sizeof(struct rpt_tele));
  1306. if (!tele)
  1307. {
  1308. ast_log(LOG_WARNING, "Unable to allocate memory\n");
  1309. pthread_exit(NULL);
  1310. return;
  1311. }
  1312. /* zero it out */
  1313. memset((char *)tele,0,sizeof(struct rpt_tele));
  1314. tele->rpt = myrpt;
  1315. tele->mode = mode;
  1316. ast_mutex_lock(&myrpt->lock);
  1317. if((mode == CONNFAIL) || (mode == REMDISC) || (mode == CONNECTED)){
  1318. memset(&tele->mylink,0,sizeof(struct rpt_link));
  1319. if (mylink){
  1320. memcpy(&tele->mylink,mylink,sizeof(struct rpt_link));
  1321. }
  1322. }
  1323. else if ((mode == ARB_ALPHA) || (mode == REV_PATCH)) {
  1324. strncpy(tele->param, (char *) data, TELEPARAMSIZE - 1);
  1325. tele->param[TELEPARAMSIZE - 1] = 0;
  1326. }
  1327. insque((struct qelem *)tele,(struct qelem *)myrpt->tele.next);
  1328. ast_mutex_unlock(&myrpt->lock);
  1329. pthread_attr_init(&attr);
  1330. pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED);
  1331. ast_pthread_create(&tele->threadid,&attr,rpt_tele_thread,(void *) tele);
  1332. return;
  1333. }
  1334. static void *rpt_call(void *this)
  1335. {
  1336. ZT_CONFINFO ci; /* conference info */
  1337. struct rpt *myrpt = (struct rpt *)this;
  1338. int res;
  1339. struct ast_frame wf;
  1340. int stopped,congstarted;
  1341. struct ast_channel *mychannel,*genchannel;
  1342. myrpt->mydtmf = 0;
  1343. /* allocate a pseudo-channel thru asterisk */
  1344. mychannel = ast_request("zap",AST_FORMAT_SLINEAR,"pseudo",NULL);
  1345. if (!mychannel)
  1346. {
  1347. fprintf(stderr,"rpt:Sorry unable to obtain pseudo channel\n");
  1348. pthread_exit(NULL);
  1349. }
  1350. ci.chan = 0;
  1351. ci.confno = myrpt->conf; /* use the pseudo conference */
  1352. ci.confmode = ZT_CONF_REALANDPSEUDO | ZT_CONF_TALKER | ZT_CONF_LISTENER
  1353. | ZT_CONF_PSEUDO_TALKER | ZT_CONF_PSEUDO_LISTENER;
  1354. /* first put the channel on the conference */
  1355. if (ioctl(mychannel->fds[0],ZT_SETCONF,&ci) == -1)
  1356. {
  1357. ast_log(LOG_WARNING, "Unable to set conference mode to Announce\n");
  1358. ast_hangup(mychannel);
  1359. myrpt->callmode = 0;
  1360. pthread_exit(NULL);
  1361. }
  1362. /* allocate a pseudo-channel thru asterisk */
  1363. genchannel = ast_request("zap",AST_FORMAT_SLINEAR,"pseudo",NULL);
  1364. if (!genchannel)
  1365. {
  1366. fprintf(stderr,"rpt:Sorry unable to obtain pseudo channel\n");
  1367. ast_hangup(mychannel);
  1368. pthread_exit(NULL);
  1369. }
  1370. ci.chan = 0;
  1371. ci.confno = myrpt->conf;
  1372. ci.confmode = ZT_CONF_REALANDPSEUDO | ZT_CONF_TALKER | ZT_CONF_LISTENER
  1373. | ZT_CONF_PSEUDO_TALKER | ZT_CONF_PSEUDO_LISTENER;
  1374. /* first put the channel on the conference */
  1375. if (ioctl(genchannel->fds[0],ZT_SETCONF,&ci) == -1)
  1376. {
  1377. ast_log(LOG_WARNING, "Unable to set conference mode to Announce\n");
  1378. ast_hangup(mychannel);
  1379. ast_hangup(genchannel);
  1380. myrpt->callmode = 0;
  1381. pthread_exit(NULL);
  1382. }
  1383. if (myrpt->tonezone && (tone_zone_set_zone(mychannel->fds[0],myrpt->tonezone) == -1))
  1384. {
  1385. ast_log(LOG_WARNING, "Unable to set tone zone %s\n",myrpt->tonezone);
  1386. ast_hangup(mychannel);
  1387. ast_hangup(genchannel);
  1388. myrpt->callmode = 0;
  1389. pthread_exit(NULL);
  1390. }
  1391. if (myrpt->tonezone && (tone_zone_set_zone(genchannel->fds[0],myrpt->tonezone) == -1))
  1392. {
  1393. ast_log(LOG_WARNING, "Unable to set tone zone %s\n",myrpt->tonezone);
  1394. ast_hangup(mychannel);
  1395. ast_hangup(genchannel);
  1396. myrpt->callmode = 0;
  1397. pthread_exit(NULL);
  1398. }
  1399. /* start dialtone */
  1400. if (tone_zone_play_tone(mychannel->fds[0],ZT_TONE_DIALTONE) < 0)
  1401. {
  1402. ast_log(LOG_WARNING, "Cannot start dialtone\n");
  1403. ast_hangup(mychannel);
  1404. ast_hangup(genchannel);
  1405. myrpt->callmode = 0;
  1406. pthread_exit(NULL);
  1407. }
  1408. stopped = 0;
  1409. congstarted = 0;
  1410. while ((myrpt->callmode == 1) || (myrpt->callmode == 4))
  1411. {
  1412. if ((myrpt->callmode == 1) && (myrpt->cidx > 0) && (!stopped))
  1413. {
  1414. stopped = 1;
  1415. /* stop dial tone */
  1416. tone_zone_play_tone(mychannel->fds[0],-1);
  1417. }
  1418. if ((myrpt->callmode == 4) && (!congstarted))
  1419. {
  1420. congstarted = 1;
  1421. /* start congestion tone */
  1422. tone_zone_play_tone(mychannel->fds[0],ZT_TONE_CONGESTION);
  1423. }
  1424. res = ast_safe_sleep(mychannel, MSWAIT);
  1425. if (res < 0)
  1426. {
  1427. ast_hangup(mychannel);
  1428. ast_hangup(genchannel);
  1429. ast_mutex_lock(&myrpt->lock);
  1430. myrpt->callmode = 0;
  1431. ast_mutex_unlock(&myrpt->lock);
  1432. pthread_exit(NULL);
  1433. }
  1434. }
  1435. /* stop any tone generation */
  1436. tone_zone_play_tone(mychannel->fds[0],-1);
  1437. /* end if done */
  1438. if (!myrpt->callmode)
  1439. {
  1440. ast_hangup(mychannel);
  1441. ast_hangup(genchannel);
  1442. ast_mutex_lock(&myrpt->lock);
  1443. myrpt->callmode = 0;
  1444. ast_mutex_unlock(&myrpt->lock);
  1445. pthread_exit(NULL);
  1446. }
  1447. if (myrpt->ourcallerid && *myrpt->ourcallerid){
  1448. char *name, *loc, *instr;
  1449. instr = strdup(myrpt->ourcallerid);
  1450. if(instr){
  1451. ast_callerid_parse(instr, &name, &loc);
  1452. if(loc){
  1453. if(mychannel->cid.cid_num)
  1454. free(mychannel->cid.cid_num);
  1455. mychannel->cid.cid_num = strdup(loc);
  1456. }
  1457. if(name){
  1458. if(mychannel->cid.cid_name)
  1459. free(mychannel->cid.cid_name);
  1460. mychannel->cid.cid_name = strdup(name);
  1461. }
  1462. free(instr);
  1463. }
  1464. }
  1465. strncpy(mychannel->exten, myrpt->exten, sizeof(mychannel->exten) - 1);
  1466. strncpy(mychannel->context, myrpt->ourcontext, sizeof(mychannel->context) - 1);
  1467. if (myrpt->acctcode)
  1468. strncpy(mychannel->accountcode, myrpt->acctcode, sizeof(mychannel->accountcode) - 1);
  1469. mychannel->priority = 1;
  1470. ast_channel_undefer_dtmf(mychannel);
  1471. if (ast_pbx_start(mychannel) < 0)
  1472. {
  1473. ast_log(LOG_WARNING, "Unable to start PBX!!\n");
  1474. ast_hangup(mychannel);
  1475. ast_hangup(genchannel);
  1476. ast_mutex_lock(&myrpt->lock);
  1477. myrpt->callmode = 0;
  1478. ast_mutex_unlock(&myrpt->lock);
  1479. pthread_exit(NULL);
  1480. }
  1481. usleep(10000);
  1482. ast_mutex_lock(&myrpt->lock);
  1483. myrpt->callmode = 3;
  1484. while(myrpt->callmode)
  1485. {
  1486. if ((!mychannel->pbx) && (myrpt->callmode != 4))
  1487. {
  1488. myrpt->callmode = 4;
  1489. ast_mutex_unlock(&myrpt->lock);
  1490. /* start congestion tone */
  1491. tone_zone_play_tone(genchannel->fds[0],ZT_TONE_CONGESTION);
  1492. ast_mutex_lock(&myrpt->lock);
  1493. }
  1494. if (myrpt->mydtmf)
  1495. {
  1496. wf.frametype = AST_FRAME_DTMF;
  1497. wf.subclass = myrpt->mydtmf;
  1498. wf.offset = 0;
  1499. wf.mallocd = 0;
  1500. wf.data = NULL;
  1501. wf.datalen = 0;
  1502. wf.samples = 0;
  1503. ast_mutex_unlock(&myrpt->lock);
  1504. ast_write(genchannel,&wf);
  1505. ast_mutex_lock(&myrpt->lock);
  1506. myrpt->mydtmf = 0;
  1507. }
  1508. ast_mutex_unlock(&myrpt->lock);
  1509. usleep(MSWAIT * 1000);
  1510. ast_mutex_lock(&myrpt->lock);
  1511. }
  1512. ast_mutex_unlock(&myrpt->lock);
  1513. tone_zone_play_tone(genchannel->fds[0],-1);
  1514. if (mychannel->pbx) ast_softhangup(mychannel,AST_SOFTHANGUP_DEV);
  1515. ast_hangup(genchannel);
  1516. ast_mutex_lock(&myrpt->lock);
  1517. myrpt->callmode = 0;
  1518. ast_mutex_unlock(&myrpt->lock);
  1519. pthread_exit(NULL);
  1520. }
  1521. static void send_link_dtmf(struct rpt *myrpt,char c)
  1522. {
  1523. char str[300];
  1524. struct ast_frame wf;
  1525. struct rpt_link *l;
  1526. snprintf(str, sizeof(str), "D %s %s %d %c", myrpt->cmdnode, myrpt->name, ++(myrpt->dtmfidx), c);
  1527. wf.frametype = AST_FRAME_TEXT;
  1528. wf.subclass = 0;
  1529. wf.offset = 0;
  1530. wf.mallocd = 1;
  1531. wf.datalen = strlen(str) + 1;
  1532. wf.samples = 0;
  1533. l = myrpt->links.next;
  1534. /* first, see if our dude is there */
  1535. while(l != &myrpt->links)
  1536. {
  1537. if (l->name[0] == '0')
  1538. {
  1539. l = l->next;
  1540. continue;
  1541. }
  1542. /* if we found it, write it and were done */
  1543. if (!strcmp(l->name,myrpt->cmdnode))
  1544. {
  1545. wf.data = strdup(str);
  1546. if (l->chan) ast_write(l->chan,&wf);
  1547. return;
  1548. }
  1549. l = l->next;
  1550. }
  1551. l = myrpt->links.next;
  1552. /* if not, give it to everyone */
  1553. while(l != &myrpt->links)
  1554. {
  1555. wf.data = strdup(str);
  1556. if (l->chan) ast_write(l->chan,&wf);
  1557. l = l->next;
  1558. }
  1559. return;
  1560. }
  1561. /*
  1562. * Internet linking function
  1563. */
  1564. static int function_ilink(struct rpt *myrpt, char *param, char *digits, int command_source, struct rpt_link *mylink)
  1565. {
  1566. char *val, *s, *s1, *s2, *tele;
  1567. char tmp[300], deststr[300] = "",modechange = 0;
  1568. char digitbuf[MAXNODESTR];
  1569. struct rpt_link *l;
  1570. ZT_CONFINFO ci; /* conference info */
  1571. if(!param)
  1572. return DC_ERROR;
  1573. if (!myrpt->enable)
  1574. return DC_ERROR;
  1575. strncpy(digitbuf,digits,MAXNODESTR - 1);
  1576. if(debug)
  1577. printf("@@@@ ilink param = %s, digitbuf = %s\n", (param)? param : "(null)", digitbuf);
  1578. switch(myatoi(param)){
  1579. case 1: /* Link off */
  1580. if ((digitbuf[0] == '0') && (myrpt->lastlinknode[0]))
  1581. strcpy(digitbuf,myrpt->lastlinknode);
  1582. val = ast_variable_retrieve(cfg, myrpt->nodes, digitbuf);
  1583. if (!val){
  1584. if(strlen(digitbuf) >= myrpt->longestnode)
  1585. return DC_ERROR;
  1586. break;
  1587. }
  1588. strncpy(tmp,val,sizeof(tmp) - 1);
  1589. s = tmp;
  1590. s1 = strsep(&s,",");
  1591. s2 = strsep(&s,",");
  1592. ast_mutex_lock(&myrpt->lock);
  1593. l = myrpt->links.next;
  1594. /* try to find this one in queue */
  1595. while(l != &myrpt->links){
  1596. if (l->name[0] == '0')
  1597. {
  1598. l = l->next;
  1599. continue;
  1600. }
  1601. /* if found matching string */
  1602. if (!strcmp(l->name, digitbuf))
  1603. break;
  1604. l = l->next;
  1605. }
  1606. if (l != &myrpt->links){ /* if found */
  1607. struct ast_frame wf;
  1608. strncpy(myrpt->lastlinknode,digitbuf,MAXNODESTR - 1);
  1609. l->retries = MAX_RETRIES + 1;
  1610. l->disced = 1;
  1611. ast_mutex_unlock(&myrpt->lock);
  1612. wf.frametype = AST_FRAME_TEXT;
  1613. wf.subclass = 0;
  1614. wf.offset = 0;
  1615. wf.mallocd = 1;
  1616. wf.datalen = strlen(discstr) + 1;
  1617. wf.samples = 0;
  1618. wf.data = strdup(discstr);
  1619. if (l->chan)
  1620. {
  1621. ast_write(l->chan,&wf);
  1622. if (ast_safe_sleep(l->chan,250) == -1) return DC_ERROR;
  1623. ast_softhangup(l->chan,AST_SOFTHANGUP_DEV);
  1624. }
  1625. rpt_telemetry(myrpt, COMPLETE, NULL);
  1626. return DC_COMPLETE;
  1627. }
  1628. ast_mutex_unlock(&myrpt->lock);
  1629. return DC_COMPLETE;
  1630. case 2: /* Link Monitor */
  1631. if ((digitbuf[0] == '0') && (myrpt->lastlinknode[0]))
  1632. strcpy(digitbuf,myrpt->lastlinknode);
  1633. val = ast_variable_retrieve(cfg, myrpt->nodes, digitbuf);
  1634. if (!val){
  1635. if(strlen(digitbuf) >= myrpt->longestnode)
  1636. return DC_ERROR;
  1637. break;
  1638. }
  1639. strncpy(tmp,val,sizeof(tmp) - 1);
  1640. s = tmp;
  1641. s1 = strsep(&s,",");
  1642. s2 = strsep(&s,",");
  1643. ast_mutex_lock(&myrpt->lock);
  1644. l = myrpt->links.next;
  1645. /* try to find this one in queue */
  1646. while(l != &myrpt->links){
  1647. if (l->name[0] == '0')
  1648. {
  1649. l = l->next;
  1650. continue;
  1651. }
  1652. /* if found matching string */
  1653. if (!strcmp(l->name, digitbuf))
  1654. break;
  1655. l = l->next;
  1656. }
  1657. /* if found */
  1658. if (l != &myrpt->links)
  1659. {
  1660. /* if already in this mode, just ignore */
  1661. if ((!l->mode) || (!l->chan)) {
  1662. ast_mutex_unlock(&myrpt->lock);
  1663. rpt_telemetry(myrpt,REMALREADY,NULL);
  1664. return DC_COMPLETE;
  1665. }
  1666. ast_mutex_unlock(&myrpt->lock);
  1667. if (l->chan) ast_softhangup(l->chan,AST_SOFTHANGUP_DEV);
  1668. l->retries = MAX_RETRIES + 1;
  1669. l->disced = 2;
  1670. modechange = 1;
  1671. } else
  1672. ast_mutex_unlock(&myrpt->lock);
  1673. strncpy(myrpt->lastlinknode,digitbuf,MAXNODESTR - 1);
  1674. /* establish call in monitor mode */
  1675. l = malloc(sizeof(struct rpt_link));
  1676. if (!l){
  1677. ast_log(LOG_WARNING, "Unable to malloc\n");
  1678. return DC_ERROR;
  1679. }
  1680. /* zero the silly thing */
  1681. memset((char *)l,0,sizeof(struct rpt_link));
  1682. snprintf(deststr, sizeof(deststr), "IAX2/%s", s1);
  1683. tele = strchr(deststr,'/');
  1684. if (!tele){
  1685. fprintf(stderr,"link2:Dial number (%s) must be in format tech/number\n",deststr);
  1686. return DC_ERROR;
  1687. }
  1688. *tele++ = 0;
  1689. l->isremote = (s && ast_true(s));
  1690. strncpy(l->name, digitbuf, MAXNODESTR - 1);
  1691. l->chan = ast_request(deststr,AST_FORMAT_SLINEAR,tele,NULL);
  1692. if (modechange) l->connected = 1;
  1693. if (l->chan){
  1694. ast_set_read_format(l->chan,AST_FORMAT_SLINEAR);
  1695. ast_set_write_format(l->chan,AST_FORMAT_SLINEAR);
  1696. l->chan->whentohangup = 0;
  1697. l->chan->appl = "Apprpt";
  1698. l->chan->data = "(Remote Rx)";
  1699. if (option_verbose > 2)
  1700. ast_verbose(VERBOSE_PREFIX_3 "rpt (remote) initiating call to %s/%s on %s\n",
  1701. deststr,tele,l->chan->name);
  1702. if(l->chan->cid.cid_num)
  1703. free(l->chan->cid.cid_num);
  1704. l->chan->cid.cid_num = strdup(myrpt->name);
  1705. ast_call(l->chan,tele,0);
  1706. }
  1707. else
  1708. {
  1709. rpt_telemetry(myrpt,CONNFAIL,l);
  1710. free(l);
  1711. if (option_verbose > 2)
  1712. ast_verbose(VERBOSE_PREFIX_3 "Unable to place call to %s/%s on %s\n",
  1713. deststr,tele,l->chan->name);
  1714. return DC_ERROR;
  1715. }
  1716. /* allocate a pseudo-channel thru asterisk */
  1717. l->pchan = ast_request("zap",AST_FORMAT_SLINEAR,"pseudo",NULL);
  1718. if (!l->pchan){
  1719. fprintf(stderr,"rpt:Sorry unable to obtain pseudo channel\n");
  1720. ast_hangup(l->chan);
  1721. free(l);
  1722. return DC_ERROR;
  1723. }
  1724. ast_set_read_format(l->pchan,AST_FORMAT_SLINEAR);
  1725. ast_set_write_format(l->pchan,AST_FORMAT_SLINEAR);
  1726. /* make a conference for the pseudo-one */
  1727. ci.chan = 0;
  1728. ci.confno = myrpt->conf;
  1729. ci.confmode = ZT_CONF_CONF | ZT_CONF_LISTENER | ZT_CONF_TALKER;
  1730. /* first put the channel on the conference in proper mode */
  1731. if (ioctl(l->pchan->fds[0],ZT_SETCONF,&ci) == -1)
  1732. {
  1733. ast_log(LOG_WARNING, "Unable to set conference mode to Announce\n");
  1734. ast_hangup(l->chan);
  1735. ast_hangup(l->pchan);
  1736. free(l);
  1737. return DC_ERROR;
  1738. }
  1739. ast_mutex_lock(&myrpt->lock);
  1740. /* insert at end of queue */
  1741. insque((struct qelem *)l,(struct qelem *)myrpt->links.next);
  1742. ast_mutex_unlock(&myrpt->lock);
  1743. rpt_telemetry(myrpt,COMPLETE,NULL);
  1744. return DC_COMPLETE;
  1745. case 3: /* Link transceive */
  1746. if ((digitbuf[0] == '0') && (myrpt->lastlinknode[0]))
  1747. strcpy(digitbuf,myrpt->lastlinknode);
  1748. val = ast_variable_retrieve(cfg, myrpt->nodes, digitbuf);
  1749. if (!val){
  1750. if(strlen(digitbuf) >= myrpt->longestnode)
  1751. return DC_ERROR;
  1752. break;
  1753. }
  1754. strncpy(tmp,val,sizeof(tmp) - 1);
  1755. s = tmp;
  1756. s1 = strsep(&s,",");
  1757. s2 = strsep(&s,",");
  1758. ast_mutex_lock(&myrpt->lock);
  1759. l = myrpt->links.next;
  1760. /* try to find this one in queue */
  1761. while(l != &myrpt->links){
  1762. if (l->name[0] == '0')
  1763. {
  1764. l = l->next;
  1765. continue;
  1766. }
  1767. /* if found matching string */
  1768. if (!strcmp(l->name, digitbuf))
  1769. break;
  1770. l = l->next;
  1771. }
  1772. /* if found */
  1773. if (l != &myrpt->links){
  1774. /* if already in this mode, just ignore */
  1775. if ((l->mode) || (!l->chan)) {
  1776. ast_mutex_unlock(&myrpt->lock);
  1777. rpt_telemetry(myrpt, REMALREADY, NULL);
  1778. return DC_COMPLETE;
  1779. }
  1780. ast_mutex_unlock(&myrpt->lock);
  1781. if (l->chan) ast_softhangup(l->chan, AST_SOFTHANGUP_DEV);
  1782. l->retries = MAX_RETRIES + 1;
  1783. l->disced = 2;
  1784. modechange = 1;
  1785. } else
  1786. ast_mutex_unlock(&myrpt->lock);
  1787. strncpy(myrpt->lastlinknode,digitbuf,MAXNODESTR - 1);
  1788. /* establish call in tranceive mode */
  1789. l = malloc(sizeof(struct rpt_link));
  1790. if (!l){
  1791. ast_log(LOG_WARNING, "Unable to malloc\n");
  1792. return(DC_ERROR);
  1793. }
  1794. /* zero the silly thing */
  1795. memset((char *)l,0,sizeof(struct rpt_link));
  1796. l->mode = 1;
  1797. l->outbound = 1;
  1798. strncpy(l->name, digitbuf, MAXNODESTR - 1);
  1799. l->isremote = (s && ast_true(s));
  1800. if (modechange) l->connected = 1;
  1801. snprintf(deststr, sizeof(deststr), "IAX2/%s", s1);
  1802. tele = strchr(deststr, '/');
  1803. if (!tele){
  1804. fprintf(stderr,"link3:Dial number (%s) must be in format tech/number\n",deststr);
  1805. free(l);
  1806. return DC_ERROR;
  1807. }
  1808. *tele++ = 0;
  1809. l->chan = ast_request(deststr, AST_FORMAT_SLINEAR, tele,NULL);
  1810. if (l->chan){
  1811. ast_set_read_format(l->chan, AST_FORMAT_SLINEAR);
  1812. ast_set_write_format(l->chan, AST_FORMAT_SLINEAR);
  1813. l->chan->whentohangup = 0;
  1814. l->chan->appl = "Apprpt";
  1815. l->chan->data = "(Remote Rx)";
  1816. if (option_verbose > 2)
  1817. ast_verbose(VERBOSE_PREFIX_3 "rpt (remote) initiating call to %s/%s on %s\n",
  1818. deststr, tele, l->chan->name);
  1819. if(l->chan->cid.cid_num)
  1820. free(l->chan->cid.cid_num);
  1821. l->chan->cid.cid_num = strdup(myrpt->name);
  1822. ast_call(l->chan,tele,999);
  1823. }
  1824. else{
  1825. rpt_telemetry(myrpt,CONNFAIL,l);
  1826. free(l);
  1827. if (option_verbose > 2)
  1828. ast_verbose(VERBOSE_PREFIX_3 "Unable to place call to %s/%s on %s\n",
  1829. deststr,tele,l->chan->name);
  1830. return DC_ERROR;
  1831. }
  1832. /* allocate a pseudo-channel thru asterisk */
  1833. l->pchan = ast_request("zap",AST_FORMAT_SLINEAR,"pseudo",NULL);
  1834. if (!l->pchan){
  1835. fprintf(stderr,"rpt:Sorry unable to obtain pseudo channel\n");
  1836. ast_hangup(l->chan);
  1837. free(l);
  1838. return DC_ERROR;
  1839. }
  1840. ast_set_read_format(l->pchan, AST_FORMAT_SLINEAR);
  1841. ast_set_write_format(l->pchan, AST_FORMAT_SLINEAR);
  1842. /* make a conference for the tx */
  1843. ci.chan = 0;
  1844. ci.confno = myrpt->conf;
  1845. ci.confmode = ZT_CONF_CONF | ZT_CONF_LISTENER | ZT_CONF_TALKER;
  1846. /* first put the channel on the conference in proper mode */
  1847. if (ioctl(l->pchan->fds[0], ZT_SETCONF, &ci) == -1)
  1848. {
  1849. ast_log(LOG_WARNING, "Unable to set conference mode to Announce\n");
  1850. ast_hangup(l->chan);
  1851. ast_hangup(l->pchan);
  1852. free(l);
  1853. return DC_ERROR;
  1854. }
  1855. ast_mutex_lock(&myrpt->lock);
  1856. /* insert at end of queue */
  1857. insque((struct qelem *)l,(struct qelem *)myrpt->links.next);
  1858. ast_mutex_unlock(&myrpt->lock);
  1859. rpt_telemetry(myrpt,COMPLETE,NULL);
  1860. return DC_COMPLETE;
  1861. case 4: /* Enter Command Mode */
  1862. /* if doesnt allow link cmd, or no links active, return */
  1863. if (((command_source != SOURCE_RPT) && (command_source != SOURCE_PHONE) && (command_source != SOURCE_DPHONE)) || (myrpt->links.next == &myrpt->links))
  1864. return DC_COMPLETE;
  1865. /* if already in cmd mode, or selected self, fughetabahtit */
  1866. if ((myrpt->cmdnode[0]) || (!strcmp(myrpt->name, digitbuf))){
  1867. rpt_telemetry(myrpt, REMALREADY, NULL);
  1868. return DC_COMPLETE;
  1869. }
  1870. if ((digitbuf[0] == '0') && (myrpt->lastlinknode[0]))
  1871. strcpy(digitbuf,myrpt->lastlinknode);
  1872. /* node must at least exist in list */
  1873. val = ast_variable_retrieve(cfg, myrpt->nodes, digitbuf);
  1874. if (!val){
  1875. if(strlen(digitbuf) >= myrpt->longestnode)
  1876. return DC_ERROR;
  1877. break;
  1878. }
  1879. ast_mutex_lock(&myrpt->lock);
  1880. strcpy(myrpt->lastlinknode,digitbuf);
  1881. strncpy(myrpt->cmdnode, digitbuf, sizeof(myrpt->cmdnode) - 1);
  1882. ast_mutex_unlock(&myrpt->lock);
  1883. rpt_telemetry(myrpt, REMGO, NULL);
  1884. return DC_COMPLETE;
  1885. case 5: /* Status */
  1886. rpt_telemetry(myrpt, STATUS, NULL);
  1887. return DC_COMPLETE;
  1888. case 6: /* All Links Off */
  1889. l = myrpt->links.next;
  1890. while(l != &myrpt->links){
  1891. if (l->chan) ast_softhangup(l->chan, AST_SOFTHANGUP_DEV); /* Hang 'em up */
  1892. l = l->next;
  1893. }
  1894. rpt_telemetry(myrpt, COMPLETE, NULL);
  1895. break;
  1896. default:
  1897. return DC_ERROR;
  1898. }
  1899. return DC_INDETERMINATE;
  1900. }
  1901. /*
  1902. * Autopatch up
  1903. */
  1904. static int function_autopatchup(struct rpt *myrpt, char *param, char *digitbuf, int command_source, struct rpt_link *mylink)
  1905. {
  1906. pthread_attr_t attr;
  1907. if (!myrpt->enable)
  1908. return DC_ERROR;
  1909. if(debug)
  1910. printf("@@@@ Autopatch up\n");
  1911. ast_mutex_lock(&myrpt->lock);
  1912. /* if on call, force * into current audio stream */
  1913. if ((myrpt->callmode == 2) || (myrpt->callmode == 3)){
  1914. myrpt->mydtmf = myrpt->funcchar;
  1915. }
  1916. if (myrpt->callmode){
  1917. ast_mutex_unlock(&myrpt->lock);
  1918. return DC_COMPLETE;
  1919. }
  1920. myrpt->callmode = 1;
  1921. myrpt->cidx = 0;
  1922. myrpt->exten[myrpt->cidx] = 0;
  1923. ast_mutex_unlock(&myrpt->lock);
  1924. pthread_attr_init(&attr);
  1925. pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED);
  1926. ast_pthread_create(&myrpt->rpt_call_thread,&attr,rpt_call,(void *) myrpt);
  1927. return DC_COMPLETE;
  1928. }
  1929. /*
  1930. * Autopatch down
  1931. */
  1932. static int function_autopatchdn(struct rpt *myrpt, char *param, char *digitbuf, int command_source, struct rpt_link *mylink)
  1933. {
  1934. if (!myrpt->enable)
  1935. return DC_ERROR;
  1936. if(debug)
  1937. printf("@@@@ Autopatch down\n");
  1938. ast_mutex_lock(&myrpt->lock);
  1939. if (!myrpt->callmode){
  1940. ast_mutex_unlock(&myrpt->lock);
  1941. return DC_COMPLETE;
  1942. }
  1943. myrpt->callmode = 0;
  1944. ast_mutex_unlock(&myrpt->lock);
  1945. rpt_telemetry(myrpt, TERM, NULL);
  1946. return DC_COMPLETE;
  1947. }
  1948. /*
  1949. * Status
  1950. */
  1951. static int function_status(struct rpt *myrpt, char *param, char *digitbuf, int command_source, struct rpt_link *mylink)
  1952. {
  1953. if(!param)
  1954. return DC_ERROR;
  1955. if (!myrpt->enable)
  1956. return DC_ERROR;
  1957. if(debug)
  1958. printf("@@@@ status param = %s, digitbuf = %s\n", (param)? param : "(null)", digitbuf);
  1959. switch(myatoi(param)){
  1960. case 1: /* System ID */
  1961. rpt_telemetry(myrpt, ID1, NULL);
  1962. return DC_COMPLETE;
  1963. case 2: /* System Time */
  1964. rpt_telemetry(myrpt, STATS_TIME, NULL);
  1965. return DC_COMPLETE;
  1966. case 3: /* app_rpt.c version */
  1967. rpt_telemetry(myrpt, STATS_VERSION, NULL);
  1968. default:
  1969. return DC_ERROR;
  1970. }
  1971. return DC_INDETERMINATE;
  1972. }
  1973. /*
  1974. * COP - Control operator
  1975. */
  1976. static int function_cop(struct rpt *myrpt, char *param, char *digitbuf, int command_source, struct rpt_link *mylink)
  1977. {
  1978. if(!param)
  1979. return DC_ERROR;
  1980. switch(myatoi(param)){
  1981. case 1: /* System reset */
  1982. system("killall -9 asterisk"); /* FIXME to drastic? */
  1983. return DC_COMPLETE;
  1984. case 2:
  1985. myrpt->enable = 1;
  1986. rpt_telemetry(myrpt, ARB_ALPHA, (void *) "RPTENA");
  1987. return DC_COMPLETE;
  1988. case 3:
  1989. myrpt->enable = 0;
  1990. return DC_COMPLETE;
  1991. case 4: /* test tone on */
  1992. rpt_telemetry(myrpt, TEST_TONE, NULL);
  1993. return DC_COMPLETE;
  1994. case 5: /* Disgorge variables to log for debug purposes */
  1995. myrpt->disgorgetime = time(NULL) + 10; /* Do it 10 seconds later */
  1996. return DC_COMPLETE;
  1997. case 6: /* Simulate COR being activated (phone only) */
  1998. if (command_source != SOURCE_PHONE) return DC_INDETERMINATE;
  1999. return DC_DOKEY;
  2000. }
  2001. return DC_INDETERMINATE;
  2002. }
  2003. /*
  2004. * Collect digits one by one until something matches
  2005. */
  2006. static int collect_function_digits(struct rpt *myrpt, char *digits,
  2007. int command_source, struct rpt_link *mylink)
  2008. {
  2009. int i;
  2010. char *stringp,*action,*param,*functiondigits;
  2011. char function_table_name[30] = "";
  2012. char workstring[80];
  2013. struct ast_variable *vp;
  2014. if(debug)
  2015. printf("@@@@ Digits collected: %s, source: %d\n", digits, command_source);
  2016. if (command_source == SOURCE_DPHONE) {
  2017. if (!myrpt->dphone_functions) return DC_INDETERMINATE;
  2018. strncpy(function_table_name, myrpt->dphone_functions, sizeof(function_table_name) - 1);
  2019. }
  2020. else if (command_source == SOURCE_PHONE) {
  2021. if (!myrpt->phone_functions) return DC_INDETERMINATE;
  2022. strncpy(function_table_name, myrpt->phone_functions, sizeof(function_table_name) - 1);
  2023. }
  2024. else if (command_source == SOURCE_LNK)
  2025. strncpy(function_table_name, myrpt->link_functions, sizeof(function_table_name) - 1);
  2026. else
  2027. strncpy(function_table_name, myrpt->functions, sizeof(function_table_name) - 1);
  2028. vp = ast_variable_browse(cfg, function_table_name);
  2029. while(vp) {
  2030. if(!strncasecmp(vp->name, digits, strlen(vp->name)))
  2031. break;
  2032. vp = vp->next;
  2033. }
  2034. if(!vp) {
  2035. int n;
  2036. n = myrpt->longestfunc;
  2037. if (command_source == SOURCE_LNK) n = myrpt->link_longestfunc;
  2038. else
  2039. if (command_source == SOURCE_PHONE) n = myrpt->phone_longestfunc;
  2040. else
  2041. if (command_source == SOURCE_DPHONE) n = myrpt->dphone_longestfunc;
  2042. if(strlen(digits) >= n)
  2043. return DC_ERROR;
  2044. else
  2045. return DC_INDETERMINATE;
  2046. }
  2047. /* Found a match, retrieve value part and parse */
  2048. strncpy(workstring, vp->value, sizeof(workstring) - 1 );
  2049. stringp = workstring;
  2050. action = strsep(&stringp, ",");
  2051. param = stringp;
  2052. if(debug)
  2053. printf("@@@@ action: %s, param = %s\n",action, (param) ? param : "(null)");
  2054. /* Look up the action */
  2055. for(i = 0 ; i < (sizeof(function_table)/sizeof(struct function_table_tag)); i++){
  2056. if(!strncasecmp(action, function_table[i].action, strlen(action)))
  2057. break;
  2058. }
  2059. if(debug)
  2060. printf("@@@@ table index i = %d\n",i);
  2061. if(i == (sizeof(function_table)/sizeof(struct function_table_tag))){
  2062. /* Error, action not in table */
  2063. return DC_ERROR;
  2064. }
  2065. if(function_table[i].function == NULL){
  2066. /* Error, function undefined */
  2067. if(debug)
  2068. printf("@@@@ NULL for action: %s\n",action);
  2069. return DC_ERROR;
  2070. }
  2071. functiondigits = digits + strlen(vp->name);
  2072. return (*function_table[i].function)(myrpt, param, functiondigits, command_source, mylink);
  2073. }
  2074. static void handle_link_data(struct rpt *myrpt, struct rpt_link *mylink,
  2075. char *str)
  2076. {
  2077. char tmp[300],cmd[300] = "",dest[300],src[300],c;
  2078. int seq, res;
  2079. struct rpt_link *l;
  2080. struct ast_frame wf;
  2081. wf.frametype = AST_FRAME_TEXT;
  2082. wf.subclass = 0;
  2083. wf.offset = 0;
  2084. wf.mallocd = 1;
  2085. wf.datalen = strlen(str) + 1;
  2086. wf.samples = 0;
  2087. /* put string in our buffer */
  2088. strncpy(tmp,str,sizeof(tmp) - 1);
  2089. if (!strcmp(tmp,discstr))
  2090. {
  2091. mylink->disced = 1;
  2092. mylink->retries = MAX_RETRIES + 1;
  2093. ast_softhangup(mylink->chan,AST_SOFTHANGUP_DEV);
  2094. return;
  2095. }
  2096. if (sscanf(tmp,"%s %s %s %d %c",cmd,dest,src,&seq,&c) != 5)
  2097. {
  2098. ast_log(LOG_WARNING, "Unable to parse link string %s\n",str);
  2099. return;
  2100. }
  2101. if (strcmp(cmd,"D"))
  2102. {
  2103. ast_log(LOG_WARNING, "Unable to parse link string %s\n",str);
  2104. return;
  2105. }
  2106. if (dest[0] == '0')
  2107. {
  2108. strcpy(dest,myrpt->name);
  2109. }
  2110. /* if not for me, redistribute to all links */
  2111. if (strcmp(dest,myrpt->name))
  2112. {
  2113. l = myrpt->links.next;
  2114. /* see if this is one in list */
  2115. while(l != &myrpt->links)
  2116. {
  2117. if (l->name[0] == '0')
  2118. {
  2119. l = l->next;
  2120. continue;
  2121. }
  2122. /* dont send back from where it came */
  2123. if ((l == mylink) || (!strcmp(l->name,mylink->name)))
  2124. {
  2125. l = l->next;
  2126. continue;
  2127. }
  2128. /* if it is, send it and we're done */
  2129. if (!strcmp(l->name,dest))
  2130. {
  2131. /* send, but not to src */
  2132. if (strcmp(l->name,src)) {
  2133. wf.data = strdup(str);
  2134. if (l->chan) ast_write(l->chan,&wf);
  2135. }
  2136. return;
  2137. }
  2138. l = l->next;
  2139. }
  2140. l = myrpt->links.next;
  2141. /* otherwise, send it to all of em */
  2142. while(l != &myrpt->links)
  2143. {
  2144. if (l->name[0] == '0')
  2145. {
  2146. l = l->next;
  2147. continue;
  2148. }
  2149. /* dont send back from where it came */
  2150. if ((l == mylink) || (!strcmp(l->name,mylink->name)))
  2151. {
  2152. l = l->next;
  2153. continue;
  2154. }
  2155. /* send, but not to src */
  2156. if (strcmp(l->name,src)) {
  2157. wf.data = strdup(str);
  2158. if (l->chan) ast_write(l->chan,&wf);
  2159. }
  2160. l = l->next;
  2161. }
  2162. return;
  2163. }
  2164. ast_mutex_lock(&myrpt->lock);
  2165. if (c == myrpt->endchar) myrpt->stopgen = 1;
  2166. if (myrpt->callmode == 1)
  2167. {
  2168. myrpt->exten[myrpt->cidx++] = c;
  2169. myrpt->exten[myrpt->cidx] = 0;
  2170. /* if this exists */
  2171. if (ast_exists_extension(myrpt->pchannel,myrpt->ourcontext,myrpt->exten,1,NULL))
  2172. {
  2173. myrpt->callmode = 2;
  2174. rpt_telemetry(myrpt,PROC,NULL);
  2175. }
  2176. /* if can continue, do so */
  2177. if (!ast_canmatch_extension(myrpt->pchannel,myrpt->ourcontext,myrpt->exten,1,NULL))
  2178. {
  2179. /* call has failed, inform user */
  2180. myrpt->callmode = 4;
  2181. }
  2182. }
  2183. if ((myrpt->callmode == 2) || (myrpt->callmode == 3))
  2184. {
  2185. myrpt->mydtmf = c;
  2186. }
  2187. if (c == myrpt->funcchar)
  2188. {
  2189. myrpt->rem_dtmfidx = 0;
  2190. myrpt->rem_dtmfbuf[myrpt->rem_dtmfidx] = 0;
  2191. time(&myrpt->rem_dtmf_time);
  2192. ast_mutex_unlock(&myrpt->lock);
  2193. return;
  2194. }
  2195. else if ((c != myrpt->endchar) && (myrpt->rem_dtmfidx >= 0))
  2196. {
  2197. time(&myrpt->rem_dtmf_time);
  2198. if (myrpt->rem_dtmfidx < MAXDTMF)
  2199. {
  2200. myrpt->rem_dtmfbuf[myrpt->rem_dtmfidx++] = c;
  2201. myrpt->rem_dtmfbuf[myrpt->rem_dtmfidx] = 0;
  2202. ast_mutex_unlock(&myrpt->lock);
  2203. strncpy(cmd, myrpt->rem_dtmfbuf, sizeof(cmd) - 1);
  2204. res = collect_function_digits(myrpt, cmd, SOURCE_LNK, mylink);
  2205. ast_mutex_lock(&myrpt->lock);
  2206. switch(res){
  2207. case DC_INDETERMINATE:
  2208. break;
  2209. case DC_REQ_FLUSH:
  2210. myrpt->rem_dtmfidx = 0;
  2211. myrpt->rem_dtmfbuf[0] = 0;
  2212. break;
  2213. case DC_COMPLETE:
  2214. myrpt->rem_dtmfbuf[0] = 0;
  2215. myrpt->rem_dtmfidx = -1;
  2216. myrpt->rem_dtmf_time = 0;
  2217. break;
  2218. case DC_ERROR:
  2219. default:
  2220. myrpt->rem_dtmfbuf[0] = 0;
  2221. myrpt->rem_dtmfidx = -1;
  2222. myrpt->rem_dtmf_time = 0;
  2223. break;
  2224. }
  2225. }
  2226. }
  2227. ast_mutex_unlock(&myrpt->lock);
  2228. return;
  2229. }
  2230. static void handle_link_phone_dtmf(struct rpt *myrpt, struct rpt_link *mylink,
  2231. char c)
  2232. {
  2233. char cmd[300];
  2234. int res;
  2235. ast_mutex_lock(&myrpt->lock);
  2236. if (c == myrpt->endchar)
  2237. {
  2238. if (mylink->lastrx)
  2239. {
  2240. mylink->lastrx = 0;
  2241. ast_mutex_unlock(&myrpt->lock);
  2242. return;
  2243. }
  2244. myrpt->stopgen = 1;
  2245. if (myrpt->cmdnode[0])
  2246. {
  2247. myrpt->cmdnode[0] = 0;
  2248. myrpt->dtmfidx = -1;
  2249. myrpt->dtmfbuf[0] = 0;
  2250. ast_mutex_unlock(&myrpt->lock);
  2251. rpt_telemetry(myrpt,COMPLETE,NULL);
  2252. ast_mutex_unlock(&myrpt->lock);
  2253. return;
  2254. }
  2255. }
  2256. if (myrpt->cmdnode[0])
  2257. {
  2258. ast_mutex_unlock(&myrpt->lock);
  2259. send_link_dtmf(myrpt,c);
  2260. return;
  2261. }
  2262. if (myrpt->callmode == 1)
  2263. {
  2264. myrpt->exten[myrpt->cidx++] = c;
  2265. myrpt->exten[myrpt->cidx] = 0;
  2266. /* if this exists */
  2267. if (ast_exists_extension(myrpt->pchannel,myrpt->ourcontext,myrpt->exten,1,NULL))
  2268. {
  2269. myrpt->callmode = 2;
  2270. rpt_telemetry(myrpt,PROC,NULL);
  2271. }
  2272. /* if can continue, do so */
  2273. if (!ast_canmatch_extension(myrpt->pchannel,myrpt->ourcontext,myrpt->exten,1,NULL))
  2274. {
  2275. /* call has failed, inform user */
  2276. myrpt->callmode = 4;
  2277. }
  2278. }
  2279. if ((myrpt->callmode == 2) || (myrpt->callmode == 3))
  2280. {
  2281. myrpt->mydtmf = c;
  2282. }
  2283. if (c == myrpt->funcchar)
  2284. {
  2285. myrpt->rem_dtmfidx = 0;
  2286. myrpt->rem_dtmfbuf[myrpt->rem_dtmfidx] = 0;
  2287. time(&myrpt->rem_dtmf_time);
  2288. ast_mutex_unlock(&myrpt->lock);
  2289. return;
  2290. }
  2291. else if ((c != myrpt->endchar) && (myrpt->rem_dtmfidx >= 0))
  2292. {
  2293. time(&myrpt->rem_dtmf_time);
  2294. if (myrpt->rem_dtmfidx < MAXDTMF)
  2295. {
  2296. myrpt->rem_dtmfbuf[myrpt->rem_dtmfidx++] = c;
  2297. myrpt->rem_dtmfbuf[myrpt->rem_dtmfidx] = 0;
  2298. ast_mutex_unlock(&myrpt->lock);
  2299. strncpy(cmd, myrpt->rem_dtmfbuf, sizeof(cmd) - 1);
  2300. res = collect_function_digits(myrpt, cmd,
  2301. ((mylink->phonemode == 2) ? SOURCE_DPHONE : SOURCE_PHONE), mylink);
  2302. ast_mutex_lock(&myrpt->lock);
  2303. switch(res){
  2304. case DC_INDETERMINATE:
  2305. break;
  2306. case DC_DOKEY:
  2307. mylink->lastrx = 1;
  2308. break;
  2309. case DC_REQ_FLUSH:
  2310. myrpt->rem_dtmfidx = 0;
  2311. myrpt->rem_dtmfbuf[0] = 0;
  2312. break;
  2313. case DC_COMPLETE:
  2314. myrpt->rem_dtmfbuf[0] = 0;
  2315. myrpt->rem_dtmfidx = -1;
  2316. myrpt->rem_dtmf_time = 0;
  2317. break;
  2318. case DC_ERROR:
  2319. default:
  2320. myrpt->rem_dtmfbuf[0] = 0;
  2321. myrpt->rem_dtmfidx = -1;
  2322. myrpt->rem_dtmf_time = 0;
  2323. break;
  2324. }
  2325. }
  2326. }
  2327. ast_mutex_unlock(&myrpt->lock);
  2328. return;
  2329. }
  2330. /* Doug Hall RBI-1 serial data definitions:
  2331. *
  2332. * Byte 0: Expansion external outputs
  2333. * Byte 1:
  2334. * Bits 0-3 are BAND as follows:
  2335. * Bits 4-5 are POWER bits as follows:
  2336. * 00 - Low Power
  2337. * 01 - Hi Power
  2338. * 02 - Med Power
  2339. * Bits 6-7 are always set
  2340. * Byte 2:
  2341. * Bits 0-3 MHZ in BCD format
  2342. * Bits 4-5 are offset as follows:
  2343. * 00 - minus
  2344. * 01 - plus
  2345. * 02 - simplex
  2346. * 03 - minus minus (whatever that is)
  2347. * Bit 6 is the 0/5 KHZ bit
  2348. * Bit 7 is always set
  2349. * Byte 3:
  2350. * Bits 0-3 are 10 KHZ in BCD format
  2351. * Bits 4-7 are 100 KHZ in BCD format
  2352. * Byte 4: PL Tone code and encode/decode enable bits
  2353. * Bits 0-5 are PL tone code (comspec binary codes)
  2354. * Bit 6 is encode enable/disable
  2355. * Bit 7 is decode enable/disable
  2356. */
  2357. /* take the frequency from the 10 mhz digits (and up) and convert it
  2358. to a band number */
  2359. static int rbi_mhztoband(char *str)
  2360. {
  2361. int i;
  2362. i = atoi(str) / 10; /* get the 10's of mhz */
  2363. switch(i)
  2364. {
  2365. case 2:
  2366. return 10;
  2367. case 5:
  2368. return 11;
  2369. case 14:
  2370. return 2;
  2371. case 22:
  2372. return 3;
  2373. case 44:
  2374. return 4;
  2375. case 124:
  2376. return 0;
  2377. case 125:
  2378. return 1;
  2379. case 126:
  2380. return 8;
  2381. case 127:
  2382. return 5;
  2383. case 128:
  2384. return 6;
  2385. case 129:
  2386. return 7;
  2387. default:
  2388. break;
  2389. }
  2390. return -1;
  2391. }
  2392. /* take a PL frequency and turn it into a code */
  2393. static int rbi_pltocode(char *str)
  2394. {
  2395. int i;
  2396. char *s;
  2397. s = strchr(str,'.');
  2398. i = 0;
  2399. if (s) i = atoi(s + 1);
  2400. i += atoi(str) * 10;
  2401. switch(i)
  2402. {
  2403. case 670:
  2404. return 0;
  2405. case 719:
  2406. return 1;
  2407. case 744:
  2408. return 2;
  2409. case 770:
  2410. return 3;
  2411. case 797:
  2412. return 4;
  2413. case 825:
  2414. return 5;
  2415. case 854:
  2416. return 6;
  2417. case 885:
  2418. return 7;
  2419. case 915:
  2420. return 8;
  2421. case 948:
  2422. return 9;
  2423. case 974:
  2424. return 10;
  2425. case 1000:
  2426. return 11;
  2427. case 1035:
  2428. return 12;
  2429. case 1072:
  2430. return 13;
  2431. case 1109:
  2432. return 14;
  2433. case 1148:
  2434. return 15;
  2435. case 1188:
  2436. return 16;
  2437. case 1230:
  2438. return 17;
  2439. case 1273:
  2440. return 18;
  2441. case 1318:
  2442. return 19;
  2443. case 1365:
  2444. return 20;
  2445. case 1413:
  2446. return 21;
  2447. case 1462:
  2448. return 22;
  2449. case 1514:
  2450. return 23;
  2451. case 1567:
  2452. return 24;
  2453. case 1622:
  2454. return 25;
  2455. case 1679:
  2456. return 26;
  2457. case 1738:
  2458. return 27;
  2459. case 1799:
  2460. return 28;
  2461. case 1862:
  2462. return 29;
  2463. case 1928:
  2464. return 30;
  2465. case 2035:
  2466. return 31;
  2467. case 2107:
  2468. return 32;
  2469. case 2181:
  2470. return 33;
  2471. case 2257:
  2472. return 34;
  2473. case 2336:
  2474. return 35;
  2475. case 2418:
  2476. return 36;
  2477. case 2503:
  2478. return 37;
  2479. }
  2480. return -1;
  2481. }
  2482. /*
  2483. * Shift out a formatted serial bit stream
  2484. */
  2485. static void rbi_out_parallel(struct rpt *myrpt,unsigned char *data)
  2486. {
  2487. int i,j;
  2488. unsigned char od,d;
  2489. static volatile long long delayvar;
  2490. for(i = 0 ; i < 5 ; i++){
  2491. od = *data++;
  2492. for(j = 0 ; j < 8 ; j++){
  2493. d = od & 1;
  2494. outb(d,myrpt->iobase);
  2495. /* >= 15 us */
  2496. for(delayvar = 1; delayvar < 15000; delayvar++);
  2497. od >>= 1;
  2498. outb(d | 2,myrpt->iobase);
  2499. /* >= 30 us */
  2500. for(delayvar = 1; delayvar < 30000; delayvar++);
  2501. outb(d,myrpt->iobase);
  2502. /* >= 10 us */
  2503. for(delayvar = 1; delayvar < 10000; delayvar++);
  2504. }
  2505. }
  2506. /* >= 50 us */
  2507. for(delayvar = 1; delayvar < 50000; delayvar++);
  2508. }
  2509. static void rbi_out(struct rpt *myrpt,unsigned char *data)
  2510. {
  2511. struct zt_radio_param r;
  2512. memset(&r,0,sizeof(struct zt_radio_param));
  2513. r.radpar = ZT_RADPAR_REMMODE;
  2514. r.data = ZT_RADPAR_REM_RBI1;
  2515. /* if setparam ioctl fails, its probably not a pciradio card */
  2516. if (ioctl(myrpt->rxchannel->fds[0],ZT_RADIO_SETPARAM,&r) == -1)
  2517. {
  2518. rbi_out_parallel(myrpt,data);
  2519. return;
  2520. }
  2521. r.radpar = ZT_RADPAR_REMCOMMAND;
  2522. memcpy(&r.data,data,5);
  2523. if (ioctl(myrpt->rxchannel->fds[0],ZT_RADIO_SETPARAM,&r) == -1)
  2524. {
  2525. ast_log(LOG_WARNING,"Cannot send RBI command for channel %s\n",myrpt->rxchannel->name);
  2526. return;
  2527. }
  2528. }
  2529. static int serial_remote_io(struct rpt *myrpt, char *txbuf, int txbytes, char *rxbuf,
  2530. int rxmaxbytes, int asciiflag)
  2531. {
  2532. int i;
  2533. struct zt_radio_param prm;
  2534. if(debug){
  2535. printf("String output was: ");
  2536. for(i = 0; i < txbytes; i++)
  2537. printf("%02X ", (unsigned char ) txbuf[i]);
  2538. printf("\n");
  2539. }
  2540. prm.radpar = ZT_RADPAR_REMMODE;
  2541. if (asciiflag) prm.data = ZT_RADPAR_REM_SERIAL_ASCII;
  2542. else prm.data = ZT_RADPAR_REM_SERIAL;
  2543. if (ioctl(myrpt->rxchannel->fds[0],ZT_RADIO_SETPARAM,&prm) == -1) return -1;
  2544. prm.radpar = ZT_RADPAR_REMCOMMAND;
  2545. prm.data = rxmaxbytes;
  2546. memcpy(prm.buf,txbuf,txbytes);
  2547. prm.index = txbytes;
  2548. if (ioctl(myrpt->rxchannel->fds[0],ZT_RADIO_SETPARAM,&prm) == -1) return -1;
  2549. if (rxbuf)
  2550. {
  2551. *rxbuf = 0;
  2552. memcpy(rxbuf,prm.buf,prm.index);
  2553. }
  2554. return(prm.index);
  2555. }
  2556. static int setrbi(struct rpt *myrpt)
  2557. {
  2558. char tmp[MAXREMSTR] = "",rbicmd[5],*s;
  2559. int band,txoffset = 0,txpower = 0,txpl;
  2560. /* must be a remote system */
  2561. if (!myrpt->remote) return(0);
  2562. /* must have rbi hardware */
  2563. if (strncmp(myrpt->remote,remote_rig_rbi,3)) return(0);
  2564. strncpy(tmp, myrpt->freq, sizeof(tmp) - 1);
  2565. s = strchr(tmp,'.');
  2566. /* if no decimal, is invalid */
  2567. if (s == NULL){
  2568. if(debug)
  2569. printf("@@@@ Frequency needs a decimal\n");
  2570. return -1;
  2571. }
  2572. *s++ = 0;
  2573. if (strlen(tmp) < 2){
  2574. if(debug)
  2575. printf("@@@@ Bad MHz digits: %s\n", tmp);
  2576. return -1;
  2577. }
  2578. if (strlen(s) < 3){
  2579. if(debug)
  2580. printf("@@@@ Bad KHz digits: %s\n", s);
  2581. return -1;
  2582. }
  2583. if ((s[2] != '0') && (s[2] != '5')){
  2584. if(debug)
  2585. printf("@@@@ KHz must end in 0 or 5: %c\n", s[2]);
  2586. return -1;
  2587. }
  2588. band = rbi_mhztoband(tmp);
  2589. if (band == -1){
  2590. if(debug)
  2591. printf("@@@@ Bad Band: %s\n", tmp);
  2592. return -1;
  2593. }
  2594. txpl = rbi_pltocode(myrpt->txpl);
  2595. if (txpl == -1){
  2596. if(debug)
  2597. printf("@@@@ Bad TX PL: %s\n", myrpt->txpl);
  2598. return -1;
  2599. }
  2600. switch(myrpt->offset)
  2601. {
  2602. case REM_MINUS:
  2603. txoffset = 0;
  2604. break;
  2605. case REM_PLUS:
  2606. txoffset = 0x10;
  2607. break;
  2608. case REM_SIMPLEX:
  2609. txoffset = 0x20;
  2610. break;
  2611. }
  2612. switch(myrpt->powerlevel)
  2613. {
  2614. case REM_LOWPWR:
  2615. txpower = 0;
  2616. break;
  2617. case REM_MEDPWR:
  2618. txpower = 0x20;
  2619. break;
  2620. case REM_HIPWR:
  2621. txpower = 0x10;
  2622. break;
  2623. }
  2624. rbicmd[0] = 0;
  2625. rbicmd[1] = band | txpower | 0xc0;
  2626. rbicmd[2] = (*(s - 2) - '0') | txoffset | 0x80;
  2627. if (s[2] == '5') rbicmd[2] |= 0x40;
  2628. rbicmd[3] = ((*s - '0') << 4) + (s[1] - '0');
  2629. rbicmd[4] = txpl;
  2630. if (myrpt->txplon) rbicmd[4] |= 0x40;
  2631. if (myrpt->rxplon) rbicmd[4] |= 0x80;
  2632. rbi_out(myrpt,rbicmd);
  2633. return 0;
  2634. }
  2635. /* Check for valid rbi frequency */
  2636. /* Hard coded limits now, configurable later, maybe? */
  2637. static int check_freq_rbi(int m, int d, int *defmode)
  2638. {
  2639. int dflmd = REM_MODE_FM;
  2640. if(m == 50){ /* 6 meters */
  2641. if(d < 10100)
  2642. return -1;
  2643. }
  2644. else if((m >= 51) && ( m < 54)){
  2645. ;
  2646. }
  2647. else if(m == 144){ /* 2 meters */
  2648. if(d < 10100)
  2649. return -1;
  2650. }
  2651. else if((m >= 145) && (m < 148)){
  2652. ;
  2653. }
  2654. else if((m >= 222) && (m < 225)){ /* 1.25 meters */
  2655. ;
  2656. }
  2657. else if((m >= 430) && (m < 450)){ /* 70 centimeters */
  2658. ;
  2659. }
  2660. else if((m >= 1240) && (m < 1300)){ /* 23 centimeters */
  2661. ;
  2662. }
  2663. else
  2664. return -1;
  2665. if(defmode)
  2666. *defmode = dflmd;
  2667. return 0;
  2668. }
  2669. /*
  2670. * Split frequency into mhz and decimals
  2671. */
  2672. static int split_freq(char *mhz, char *decimals, char *freq)
  2673. {
  2674. char freq_copy[MAXREMSTR];
  2675. char *decp;
  2676. decp = strchr(strncpy(freq_copy, freq, MAXREMSTR),'.');
  2677. if(decp){
  2678. *decp++ = 0;
  2679. strncpy(mhz, freq_copy, MAXREMSTR);
  2680. strcpy(decimals, "00000");
  2681. strncpy(decimals, decp, strlen(decp));
  2682. decimals[5] = 0;
  2683. return 0;
  2684. }
  2685. else
  2686. return -1;
  2687. }
  2688. /*
  2689. * Split ctcss frequency into hertz and decimal
  2690. */
  2691. static int split_ctcss_freq(char *hertz, char *decimal, char *freq)
  2692. {
  2693. char freq_copy[MAXREMSTR];
  2694. char *decp;
  2695. decp = strchr(strncpy(freq_copy, freq, MAXREMSTR),'.');
  2696. if(decp){
  2697. *decp++ = 0;
  2698. strncpy(hertz, freq_copy, MAXREMSTR);
  2699. strncpy(decimal, decp, strlen(decp));
  2700. decimal[strlen(decp)] = '\0';
  2701. return 0;
  2702. }
  2703. else
  2704. return -1;
  2705. }
  2706. /*
  2707. * FT-897 I/O handlers
  2708. */
  2709. /* Check to see that the frequency is valid */
  2710. /* Hard coded limits now, configurable later, maybe? */
  2711. static int check_freq_ft897(int m, int d, int *defmode)
  2712. {
  2713. int dflmd = REM_MODE_FM;
  2714. if(m == 1){ /* 160 meters */
  2715. dflmd = REM_MODE_LSB;
  2716. if(d < 80001)
  2717. return -1;
  2718. }
  2719. else if(m == 3){ /* 80 meters */
  2720. dflmd = REM_MODE_LSB;
  2721. if(d < 75001)
  2722. return -1;
  2723. }
  2724. else if(m == 7){ /* 40 meters */
  2725. dflmd = REM_MODE_LSB;
  2726. if((d < 15001) || (d > 29999))
  2727. return -1;
  2728. }
  2729. else if(m == 14){ /* 20 meters */
  2730. dflmd = REM_MODE_USB;
  2731. if((d < 15001) || (d > 34999))
  2732. return -1;
  2733. }
  2734. else if(m == 18){ /* 17 meters */
  2735. dflmd = REM_MODE_USB;
  2736. if((d < 11001) || (d > 16797))
  2737. return -1;
  2738. }
  2739. else if(m == 21){ /* 15 meters */
  2740. dflmd = REM_MODE_USB;
  2741. if((d < 20001) || (d > 44999))
  2742. return -1;
  2743. }
  2744. else if(m == 24){ /* 12 meters */
  2745. dflmd = REM_MODE_USB;
  2746. if((d < 93001) || (d > 98999))
  2747. return -1;
  2748. }
  2749. else if(m == 28){ /* 10 meters */
  2750. dflmd = REM_MODE_USB;
  2751. if(d < 30001)
  2752. return -1;
  2753. }
  2754. else if(m == 29){
  2755. if(d >= 51000)
  2756. dflmd = REM_MODE_FM;
  2757. else
  2758. dflmd = REM_MODE_USB;
  2759. if(d > 69999)
  2760. return -1;
  2761. }
  2762. else if(m == 50){ /* 6 meters */
  2763. if(d < 10100)
  2764. return -1;
  2765. if(d >= 30000)
  2766. dflmd = REM_MODE_FM;
  2767. else
  2768. dflmd = REM_MODE_USB;
  2769. }
  2770. else if((m >= 51) && ( m < 54)){
  2771. dflmd = REM_MODE_FM;
  2772. }
  2773. else if(m == 144){ /* 2 meters */
  2774. if(d < 10100)
  2775. return -1;
  2776. if(d >= 30000)
  2777. dflmd = REM_MODE_FM;
  2778. else
  2779. dflmd = REM_MODE_USB;
  2780. }
  2781. else if((m >= 145) && (m < 148)){
  2782. dflmd = REM_MODE_FM;
  2783. }
  2784. else if((m >= 430) && (m < 450)){ /* 70 centimeters */
  2785. if(m < 438)
  2786. dflmd = REM_MODE_USB;
  2787. else
  2788. dflmd = REM_MODE_FM;
  2789. ;
  2790. }
  2791. else
  2792. return -1;
  2793. if(defmode)
  2794. *defmode = dflmd;
  2795. return 0;
  2796. }
  2797. /*
  2798. * Set a new frequency for the FT897
  2799. */
  2800. static int set_freq_ft897(struct rpt *myrpt, char *newfreq)
  2801. {
  2802. char mhz[MAXREMSTR];
  2803. char decimals[MAXREMSTR];
  2804. unsigned char cmdstr[5];
  2805. int fd,m,d;
  2806. fd = 0;
  2807. if(debug)
  2808. printf("New frequency: %s\n",newfreq);
  2809. if(split_freq(mhz, decimals, newfreq))
  2810. return -1;
  2811. m = atoi(mhz);
  2812. d = atoi(decimals);
  2813. /* The FT-897 likes packed BCD frequencies */
  2814. cmdstr[0] = ((m / 100) << 4) + ((m % 100)/10); /* 100MHz 10Mhz */
  2815. cmdstr[1] = ((m % 10) << 4) + (d / 10000); /* 1MHz 100KHz */
  2816. cmdstr[2] = (((d % 10000)/1000) << 4) + ((d % 1000)/ 100); /* 10KHz 1KHz */
  2817. cmdstr[3] = (((d % 100)/10) << 4) + (d % 10); /* 100Hz 10Hz */
  2818. cmdstr[4] = 0x01; /* command */
  2819. return serial_remote_io(myrpt, cmdstr, 5, NULL, 0, 0);
  2820. }
  2821. /* ft-897 simple commands */
  2822. static int simple_command_ft897(struct rpt *myrpt, char command)
  2823. {
  2824. unsigned char cmdstr[5];
  2825. memset(cmdstr, 0, 5);
  2826. cmdstr[4] = command;
  2827. return serial_remote_io(myrpt, cmdstr, 5, NULL, 0, 0);
  2828. }
  2829. /* ft-897 offset */
  2830. static int set_offset_ft897(struct rpt *myrpt, char offset)
  2831. {
  2832. unsigned char cmdstr[5];
  2833. memset(cmdstr, 0, 5);
  2834. switch(offset){
  2835. case REM_SIMPLEX:
  2836. cmdstr[0] = 0x89;
  2837. break;
  2838. case REM_MINUS:
  2839. cmdstr[0] = 0x09;
  2840. break;
  2841. case REM_PLUS:
  2842. cmdstr[0] = 0x49;
  2843. break;
  2844. default:
  2845. return -1;
  2846. }
  2847. cmdstr[4] = 0x09;
  2848. return serial_remote_io(myrpt, cmdstr, 5, NULL, 0, 0);
  2849. }
  2850. /* ft-897 mode */
  2851. static int set_mode_ft897(struct rpt *myrpt, char newmode)
  2852. {
  2853. unsigned char cmdstr[5];
  2854. memset(cmdstr, 0, 5);
  2855. switch(newmode){
  2856. case REM_MODE_FM:
  2857. cmdstr[0] = 0x08;
  2858. break;
  2859. case REM_MODE_USB:
  2860. cmdstr[0] = 0x01;
  2861. break;
  2862. case REM_MODE_LSB:
  2863. cmdstr[0] = 0x00;
  2864. break;
  2865. case REM_MODE_AM:
  2866. cmdstr[0] = 0x04;
  2867. break;
  2868. default:
  2869. return -1;
  2870. }
  2871. cmdstr[4] = 0x07;
  2872. return serial_remote_io(myrpt, cmdstr, 5, NULL, 0, 0);
  2873. }
  2874. /* Set tone encode and decode modes */
  2875. static int set_ctcss_mode_ft897(struct rpt *myrpt, char txplon, char rxplon)
  2876. {
  2877. unsigned char cmdstr[5];
  2878. memset(cmdstr, 0, 5);
  2879. if(rxplon && txplon)
  2880. cmdstr[0] = 0x2A; /* Encode and Decode */
  2881. else if (!rxplon && txplon)
  2882. cmdstr[0] = 0x4A; /* Encode only */
  2883. else if (rxplon && !txplon)
  2884. cmdstr[0] = 0x3A; /* Encode only */
  2885. else
  2886. cmdstr[0] = 0x8A; /* OFF */
  2887. cmdstr[4] = 0x0A;
  2888. return serial_remote_io(myrpt, cmdstr, 5, NULL, 0, 0);
  2889. }
  2890. /* Set transmit and receive ctcss tone frequencies */
  2891. static int set_ctcss_freq_ft897(struct rpt *myrpt, char *txtone, char *rxtone)
  2892. {
  2893. unsigned char cmdstr[5];
  2894. char hertz[MAXREMSTR],decimal[MAXREMSTR];
  2895. int h,d;
  2896. memset(cmdstr, 0, 5);
  2897. if(split_ctcss_freq(hertz, decimal, txtone))
  2898. return -1;
  2899. h = atoi(hertz);
  2900. d = atoi(decimal);
  2901. cmdstr[0] = ((h / 100) << 4) + (h % 100)/ 10;
  2902. cmdstr[1] = ((h % 10) << 4) + (d % 10);
  2903. if(rxtone){
  2904. if(split_ctcss_freq(hertz, decimal, rxtone))
  2905. return -1;
  2906. h = atoi(hertz);
  2907. d = atoi(decimal);
  2908. cmdstr[2] = ((h / 100) << 4) + (h % 100)/ 10;
  2909. cmdstr[3] = ((h % 10) << 4) + (d % 10);
  2910. }
  2911. cmdstr[4] = 0x0B;
  2912. return serial_remote_io(myrpt, cmdstr, 5, NULL, 0, 0);
  2913. }
  2914. static int set_ft897(struct rpt *myrpt)
  2915. {
  2916. int res;
  2917. if(debug)
  2918. printf("@@@@ lock on\n");
  2919. res = simple_command_ft897(myrpt, 0x00); /* LOCK on */
  2920. if(debug)
  2921. printf("@@@@ ptt off\n");
  2922. if(!res)
  2923. res = simple_command_ft897(myrpt, 0x88); /* PTT off */
  2924. if(debug)
  2925. printf("Modulation mode\n");
  2926. if(!res)
  2927. res = set_mode_ft897(myrpt, myrpt->remmode); /* Modulation mode */
  2928. if(debug)
  2929. printf("Split off\n");
  2930. if(!res)
  2931. simple_command_ft897(myrpt, 0x82); /* Split off */
  2932. if(debug)
  2933. printf("Frequency\n");
  2934. if(!res)
  2935. res = set_freq_ft897(myrpt, myrpt->freq); /* Frequency */
  2936. if((myrpt->remmode == REM_MODE_FM)){
  2937. if(debug)
  2938. printf("Offset\n");
  2939. if(!res)
  2940. res = set_offset_ft897(myrpt, myrpt->offset); /* Offset if FM */
  2941. if((!res)&&(myrpt->rxplon || myrpt->txplon)){
  2942. if(debug)
  2943. printf("CTCSS tone freqs.\n");
  2944. res = set_ctcss_freq_ft897(myrpt, myrpt->txpl, myrpt->rxpl); /* CTCSS freqs if CTCSS is enabled */
  2945. }
  2946. if(!res){
  2947. if(debug)
  2948. printf("CTCSS mode\n");
  2949. res = set_ctcss_mode_ft897(myrpt, myrpt->txplon, myrpt->rxplon); /* CTCSS mode */
  2950. }
  2951. }
  2952. if((myrpt->remmode == REM_MODE_USB)||(myrpt->remmode == REM_MODE_LSB)){
  2953. if(debug)
  2954. printf("Clarifier off\n");
  2955. simple_command_ft897(myrpt, 0x85); /* Clarifier off if LSB or USB */
  2956. }
  2957. return res;
  2958. }
  2959. static int closerem_ft897(struct rpt *myrpt)
  2960. {
  2961. simple_command_ft897(myrpt, 0x88); /* PTT off */
  2962. return 0;
  2963. }
  2964. /*
  2965. * Bump frequency up or down by a small amount
  2966. * Return 0 if the new frequnecy is valid, or -1 if invalid
  2967. * Interval is in Hz, resolution is 10Hz
  2968. */
  2969. static int multimode_bump_freq_ft897(struct rpt *myrpt, int interval)
  2970. {
  2971. int m,d;
  2972. char mhz[MAXREMSTR], decimals[MAXREMSTR];
  2973. if(debug)
  2974. printf("Before bump: %s\n", myrpt->freq);
  2975. if(split_freq(mhz, decimals, myrpt->freq))
  2976. return -1;
  2977. m = atoi(mhz);
  2978. d = atoi(decimals);
  2979. d += (interval / 10); /* 10Hz resolution */
  2980. if(d < 0){
  2981. m--;
  2982. d += 100000;
  2983. }
  2984. else if(d >= 100000){
  2985. m++;
  2986. d -= 100000;
  2987. }
  2988. if(check_freq_ft897(m, d, NULL)){
  2989. if(debug)
  2990. printf("Bump freq invalid\n");
  2991. return -1;
  2992. }
  2993. snprintf(myrpt->freq, MAXREMSTR, "%d.%05d", m, d);
  2994. if(debug)
  2995. printf("After bump: %s\n", myrpt->freq);
  2996. return set_freq_ft897(myrpt, myrpt->freq);
  2997. }
  2998. /*
  2999. * Dispatch to correct I/O handler
  3000. */
  3001. static int setrem(struct rpt *myrpt)
  3002. {
  3003. if(!strcmp(myrpt->remote, remote_rig_ft897))
  3004. return set_ft897(myrpt);
  3005. else if(!strcmp(myrpt->remote, remote_rig_rbi))
  3006. return setrbi(myrpt);
  3007. else
  3008. return -1;
  3009. }
  3010. static int closerem(struct rpt *myrpt)
  3011. {
  3012. if(!strcmp(myrpt->remote, remote_rig_ft897))
  3013. return closerem_ft897(myrpt);
  3014. else
  3015. return 0;
  3016. }
  3017. /*
  3018. * Dispatch to correct frequency checker
  3019. */
  3020. static int check_freq(struct rpt *myrpt, int m, int d, int *defmode)
  3021. {
  3022. if(!strcmp(myrpt->remote, remote_rig_ft897))
  3023. return check_freq_ft897(m, d, defmode);
  3024. else if(!strcmp(myrpt->remote, remote_rig_rbi))
  3025. return check_freq_rbi(m, d, defmode);
  3026. else
  3027. return -1;
  3028. }
  3029. /*
  3030. * Return 1 if rig is multimode capable
  3031. */
  3032. static int multimode_capable(struct rpt *myrpt)
  3033. {
  3034. if(!strcmp(myrpt->remote, remote_rig_ft897))
  3035. return 1;
  3036. return 0;
  3037. }
  3038. /*
  3039. * Dispatch to correct frequency bumping function
  3040. */
  3041. static int multimode_bump_freq(struct rpt *myrpt, int interval)
  3042. {
  3043. if(!strcmp(myrpt->remote, remote_rig_ft897))
  3044. return multimode_bump_freq_ft897(myrpt, interval);
  3045. else
  3046. return -1;
  3047. }
  3048. /*
  3049. * Queue announcment that scan has been stopped
  3050. */
  3051. static void stop_scan(struct rpt *myrpt, int flag)
  3052. {
  3053. myrpt->hfscanmode = 0;
  3054. myrpt->hfscanstatus = ((flag) ? -2 : -1);
  3055. }
  3056. /*
  3057. * This is called periodically when in scan mode
  3058. */
  3059. static int service_scan(struct rpt *myrpt)
  3060. {
  3061. int res, interval;
  3062. char mhz[MAXREMSTR], decimals[MAXREMSTR], k10=0i, k100=0;
  3063. switch(myrpt->hfscanmode){
  3064. case HF_SCAN_DOWN_SLOW:
  3065. interval = -10; /* 100Hz /sec */
  3066. break;
  3067. case HF_SCAN_DOWN_QUICK:
  3068. interval = -50; /* 500Hz /sec */
  3069. break;
  3070. case HF_SCAN_DOWN_FAST:
  3071. interval = -200; /* 2KHz /sec */
  3072. break;
  3073. case HF_SCAN_UP_SLOW:
  3074. interval = 10; /* 100Hz /sec */
  3075. break;
  3076. case HF_SCAN_UP_QUICK:
  3077. interval = 50; /* 500 Hz/sec */
  3078. break;
  3079. case HF_SCAN_UP_FAST:
  3080. interval = 200; /* 2KHz /sec */
  3081. break;
  3082. default:
  3083. myrpt->hfscanmode = 0; /* Huh? */
  3084. return -1;
  3085. }
  3086. res = split_freq(mhz, decimals, myrpt->freq);
  3087. if(!res){
  3088. k100 =decimals[0];
  3089. k10 = decimals[1];
  3090. res = multimode_bump_freq(myrpt, interval);
  3091. }
  3092. if(!res)
  3093. res = split_freq(mhz, decimals, myrpt->freq);
  3094. if(res){
  3095. stop_scan(myrpt,1);
  3096. return -1;
  3097. }
  3098. /* Announce 10KHz boundaries */
  3099. if(k10 != decimals[1]){
  3100. int myhund = (interval < 0) ? k100 : decimals[0];
  3101. int myten = (interval < 0) ? k10 : decimals[1];
  3102. myrpt->hfscanstatus = (myten == '0') ? (myhund - '0') * 100 : (myten - '0') * 10;
  3103. }
  3104. return res;
  3105. }
  3106. static int rmt_telem_start(struct rpt *myrpt, struct ast_channel *chan, int delay)
  3107. {
  3108. myrpt->remotetx = 0;
  3109. ast_indicate(myrpt->txchannel,AST_CONTROL_RADIO_UNKEY);
  3110. if (!myrpt->remoterx)
  3111. ast_indicate(chan,AST_CONTROL_RADIO_KEY);
  3112. if (ast_safe_sleep(chan, delay) == -1)
  3113. return -1;
  3114. return 0;
  3115. }
  3116. static int rmt_telem_finish(struct rpt *myrpt, struct ast_channel *chan)
  3117. {
  3118. struct zt_params par;
  3119. if (ioctl(myrpt->txchannel->fds[0],ZT_GET_PARAMS,&par) == -1)
  3120. {
  3121. return -1;
  3122. }
  3123. if (!par.rxisoffhook)
  3124. {
  3125. ast_indicate(myrpt->remchannel,AST_CONTROL_RADIO_UNKEY);
  3126. myrpt->remoterx = 0;
  3127. }
  3128. else
  3129. {
  3130. myrpt->remoterx = 1;
  3131. }
  3132. return 0;
  3133. }
  3134. static int rmt_sayfile(struct rpt *myrpt, struct ast_channel *chan, int delay, char *filename)
  3135. {
  3136. int res;
  3137. res = rmt_telem_start(myrpt, chan, delay);
  3138. if(!res)
  3139. res = sayfile(chan, filename);
  3140. if(!res)
  3141. res = rmt_telem_finish(myrpt, chan);
  3142. return res;
  3143. }
  3144. static int rmt_saycharstr(struct rpt *myrpt, struct ast_channel *chan, int delay, char *charstr)
  3145. {
  3146. int res;
  3147. res = rmt_telem_start(myrpt, chan, delay);
  3148. if(!res)
  3149. res = saycharstr(chan, charstr);
  3150. if(!res)
  3151. res = rmt_telem_finish(myrpt, chan);
  3152. return res;
  3153. }
  3154. /*
  3155. * Remote base function
  3156. */
  3157. static int function_remote(struct rpt *myrpt, char *param, char *digitbuf, int command_source, struct rpt_link *mylink)
  3158. {
  3159. char *s,*s1,*s2,*val;
  3160. int i,j,ht,k,l,ls2,m,d,res,offset,offsave, modesave, defmode;
  3161. char multimode = 0;
  3162. char oc;
  3163. char tmp[20], freq[20] = "", savestr[20] = "";
  3164. char mhz[MAXREMSTR], decimals[MAXREMSTR];
  3165. struct ast_channel *mychannel;
  3166. if((!param) || (command_source == SOURCE_RPT) || (command_source == SOURCE_LNK))
  3167. return DC_ERROR;
  3168. multimode = multimode_capable(myrpt);
  3169. mychannel = myrpt->remchannel;
  3170. switch(myatoi(param)){
  3171. case 1: /* retrieve memory */
  3172. if(strlen(digitbuf) < 2) /* needs 2 digits */
  3173. break;
  3174. for(i = 0 ; i < 2 ; i++){
  3175. if((digitbuf[i] < '0') || (digitbuf[i] > '9'))
  3176. return DC_ERROR;
  3177. }
  3178. val = ast_variable_retrieve(cfg, MEMORY, digitbuf);
  3179. if (!val){
  3180. if (ast_safe_sleep(mychannel,1000) == -1)
  3181. return DC_ERROR;
  3182. sayfile(mychannel,"rpt/memory_notfound");
  3183. return DC_COMPLETE;
  3184. }
  3185. strncpy(tmp,val,sizeof(tmp) - 1);
  3186. s = strchr(tmp,',');
  3187. if (!s)
  3188. return DC_ERROR;
  3189. *s++ = 0;
  3190. s1 = strchr(s,',');
  3191. if (!s1)
  3192. return DC_ERROR;
  3193. *s1++ = 0;
  3194. strncpy(myrpt->freq, tmp, sizeof(myrpt->freq) - 1);
  3195. strncpy(myrpt->rxpl, s, sizeof(myrpt->rxpl) - 1);
  3196. strncpy(myrpt->txpl, s, sizeof(myrpt->rxpl) - 1);
  3197. myrpt->remmode = REM_MODE_FM;
  3198. myrpt->offset = REM_SIMPLEX;
  3199. myrpt->powerlevel = REM_MEDPWR;
  3200. myrpt->txplon = myrpt->rxplon = 0;
  3201. while(*s1)
  3202. {
  3203. switch(*s1++){
  3204. case 'A':
  3205. case 'a':
  3206. strcpy(myrpt->rxpl, "100.0");
  3207. strcpy(myrpt->txpl, "100.0");
  3208. myrpt->remmode = REM_MODE_AM;
  3209. break;
  3210. case 'B':
  3211. case 'b':
  3212. strcpy(myrpt->rxpl, "100.0");
  3213. strcpy(myrpt->txpl, "100.0");
  3214. myrpt->remmode = REM_MODE_LSB;
  3215. break;
  3216. case 'F':
  3217. myrpt->remmode = REM_MODE_FM;
  3218. break;
  3219. case 'L':
  3220. case 'l':
  3221. myrpt->powerlevel = REM_LOWPWR;
  3222. break;
  3223. case 'H':
  3224. case 'h':
  3225. myrpt->powerlevel = REM_HIPWR;
  3226. break;
  3227. case 'M':
  3228. case 'm':
  3229. myrpt->powerlevel = REM_MEDPWR;
  3230. break;
  3231. case '-':
  3232. myrpt->offset = REM_MINUS;
  3233. break;
  3234. case '+':
  3235. myrpt->offset = REM_PLUS;
  3236. break;
  3237. case 'S':
  3238. case 's':
  3239. myrpt->offset = REM_SIMPLEX;
  3240. break;
  3241. case 'T':
  3242. case 't':
  3243. myrpt->txplon = 1;
  3244. break;
  3245. case 'R':
  3246. case 'r':
  3247. myrpt->rxplon = 1;
  3248. break;
  3249. case 'U':
  3250. case 'u':
  3251. strcpy(myrpt->rxpl, "100.0");
  3252. strcpy(myrpt->txpl, "100.0");
  3253. myrpt->remmode = REM_MODE_USB;
  3254. break;
  3255. }
  3256. }
  3257. if (setrem(myrpt) == -1)
  3258. return DC_ERROR;
  3259. return DC_COMPLETE;
  3260. case 2: /* set freq and offset */
  3261. for(i = 0, j = 0, k = 0, l = 0 ; digitbuf[i] ; i++){ /* look for M+*K+*O or M+*H+* depending on mode */
  3262. if(digitbuf[i] == '*'){
  3263. j++;
  3264. continue;
  3265. }
  3266. if((digitbuf[i] < '0') || (digitbuf[i] > '9'))
  3267. goto invalid_freq;
  3268. else{
  3269. if(j == 0)
  3270. l++; /* # of digits before first * */
  3271. if(j == 1)
  3272. k++; /* # of digits after first * */
  3273. }
  3274. }
  3275. i = strlen(digitbuf) - 1;
  3276. if(multimode){
  3277. if((j > 2) || (l > 3) || (k > 6))
  3278. goto invalid_freq; /* &^@#! */
  3279. }
  3280. else{
  3281. if((j > 2) || (l > 4) || (k > 3))
  3282. goto invalid_freq; /* &^@#! */
  3283. }
  3284. /* Wait for M+*K+* */
  3285. if(j < 2)
  3286. break; /* Not yet */
  3287. /* We have a frequency */
  3288. strncpy(tmp, digitbuf ,sizeof(tmp) - 1);
  3289. s = tmp;
  3290. s1 = strsep(&s, "*"); /* Pick off MHz */
  3291. s2 = strsep(&s,"*"); /* Pick off KHz and Hz */
  3292. ls2 = strlen(s2);
  3293. switch(ls2){ /* Allow partial entry of khz and hz digits for laziness support */
  3294. case 1:
  3295. ht = 0;
  3296. k = 100 * atoi(s2);
  3297. break;
  3298. case 2:
  3299. ht = 0;
  3300. k = 10 * atoi(s2);
  3301. break;
  3302. case 3:
  3303. if(!multimode){
  3304. if((s2[2] != '0')&&(s2[2] != '5'))
  3305. goto invalid_freq;
  3306. }
  3307. ht = 0;
  3308. k = atoi(s2);
  3309. break;
  3310. case 4:
  3311. k = atoi(s2)/10;
  3312. ht = 10 * (atoi(s2+(ls2-1)));
  3313. break;
  3314. case 5:
  3315. k = atoi(s2)/100;
  3316. ht = (atoi(s2+(ls2-2)));
  3317. break;
  3318. default:
  3319. goto invalid_freq;
  3320. }
  3321. /* Check frequency for validity and establish a default mode */
  3322. snprintf(freq, sizeof(freq), "%s.%03d%02d",s1, k, ht);
  3323. if(debug)
  3324. printf("New frequency: %s\n", freq);
  3325. split_freq(mhz, decimals, freq);
  3326. m = atoi(mhz);
  3327. d = atoi(decimals);
  3328. if(check_freq(myrpt, m, d, &defmode)) /* Check to see if frequency entered is legit */
  3329. goto invalid_freq;
  3330. if((defmode == REM_MODE_FM) && (digitbuf[i] == '*')) /* If FM, user must enter and additional offset digit */
  3331. break; /* Not yet */
  3332. offset = REM_SIMPLEX; /* Assume simplex */
  3333. if(defmode == REM_MODE_FM){
  3334. oc = *s; /* Pick off offset */
  3335. if (oc){
  3336. switch(oc){
  3337. case '1':
  3338. offset = REM_MINUS;
  3339. break;
  3340. case '2':
  3341. offset = REM_SIMPLEX;
  3342. break;
  3343. case '3':
  3344. offset = REM_PLUS;
  3345. break;
  3346. default:
  3347. goto invalid_freq;
  3348. }
  3349. }
  3350. }
  3351. offsave = myrpt->offset;
  3352. modesave = myrpt->remmode;
  3353. strncpy(savestr, myrpt->freq, sizeof(savestr) - 1);
  3354. strncpy(myrpt->freq, freq, sizeof(myrpt->freq) - 1);
  3355. myrpt->offset = offset;
  3356. myrpt->remmode = defmode;
  3357. if (setrem(myrpt) == -1){
  3358. myrpt->offset = offsave;
  3359. myrpt->remmode = modesave;
  3360. strncpy(myrpt->freq, savestr, sizeof(myrpt->freq) - 1);
  3361. goto invalid_freq;
  3362. }
  3363. return DC_COMPLETE;
  3364. invalid_freq:
  3365. rmt_sayfile(myrpt, mychannel, 1000, "rpt/invalid-freq");
  3366. return DC_ERROR;
  3367. case 3: /* set rx PL tone */
  3368. for(i = 0, j = 0, k = 0, l = 0 ; digitbuf[i] ; i++){ /* look for N+*N */
  3369. if(digitbuf[i] == '*'){
  3370. j++;
  3371. continue;
  3372. }
  3373. if((digitbuf[i] < '0') || (digitbuf[i] > '9'))
  3374. return DC_ERROR;
  3375. else{
  3376. if(j)
  3377. l++;
  3378. else
  3379. k++;
  3380. }
  3381. }
  3382. if((j > 1) || (k > 3) || (l > 1))
  3383. return DC_ERROR; /* &$@^! */
  3384. i = strlen(digitbuf) - 1;
  3385. if((j != 1) || (k < 2)|| (l != 1))
  3386. break; /* Not yet */
  3387. if(debug)
  3388. printf("PL digits entered %s\n", digitbuf);
  3389. strncpy(tmp, digitbuf, sizeof(tmp) - 1);
  3390. /* see if we have at least 1 */
  3391. s = strchr(tmp,'*');
  3392. if(s)
  3393. *s = '.';
  3394. strncpy(savestr, myrpt->rxpl, sizeof(savestr) - 1);
  3395. strncpy(myrpt->rxpl, tmp, sizeof(myrpt->rxpl) - 1);
  3396. if (setrem(myrpt) == -1){
  3397. strncpy(myrpt->rxpl, savestr, sizeof(myrpt->rxpl) - 1);
  3398. return DC_ERROR;
  3399. }
  3400. return DC_COMPLETE;
  3401. case 4: /* set tx PL tone */
  3402. for(i = 0, j = 0, k = 0, l = 0 ; digitbuf[i] ; i++){ /* look for N+*N */
  3403. if(digitbuf[i] == '*'){
  3404. j++;
  3405. continue;
  3406. }
  3407. if((digitbuf[i] < '0') || (digitbuf[i] > '9'))
  3408. return DC_ERROR;
  3409. else{
  3410. if(j)
  3411. l++;
  3412. else
  3413. k++;
  3414. }
  3415. }
  3416. if((j > 1) || (k > 3) || (l > 1))
  3417. return DC_ERROR; /* &$@^! */
  3418. i = strlen(digitbuf) - 1;
  3419. if((j != 1) || (k < 2)|| (l != 1))
  3420. break; /* Not yet */
  3421. if(debug)
  3422. printf("PL digits entered %s\n", digitbuf);
  3423. strncpy(tmp, digitbuf, sizeof(tmp) - 1);
  3424. /* see if we have at least 1 */
  3425. s = strchr(tmp,'*');
  3426. if(s)
  3427. *s = '.';
  3428. strncpy(savestr, myrpt->txpl, sizeof(savestr) - 1);
  3429. strncpy(myrpt->txpl, tmp, sizeof(myrpt->txpl) - 1);
  3430. if (setrem(myrpt) == -1){
  3431. strncpy(myrpt->txpl, savestr, sizeof(myrpt->txpl) - 1);
  3432. return DC_ERROR;
  3433. }
  3434. return DC_COMPLETE;
  3435. case 6: /* MODE (FM,USB,LSB,AM) */
  3436. if(strlen(digitbuf) < 1)
  3437. break;
  3438. if(!multimode)
  3439. return DC_ERROR; /* Multimode radios only */
  3440. switch(*digitbuf){
  3441. case '1':
  3442. split_freq(mhz, decimals, myrpt->freq);
  3443. m=atoi(mhz);
  3444. if(m < 29) /* No FM allowed below 29MHz! */
  3445. return DC_ERROR;
  3446. myrpt->remmode = REM_MODE_FM;
  3447. res = rmt_saycharstr(myrpt, mychannel, 1000,"FM");
  3448. break;
  3449. case '2':
  3450. myrpt->remmode = REM_MODE_USB;
  3451. res = rmt_saycharstr(myrpt, mychannel, 1000,"USB");
  3452. break;
  3453. case '3':
  3454. myrpt->remmode = REM_MODE_LSB;
  3455. res = rmt_saycharstr(myrpt, mychannel, 1000,"LSB");
  3456. break;
  3457. case '4':
  3458. myrpt->remmode = REM_MODE_AM;
  3459. res = rmt_saycharstr(myrpt, mychannel, 1000,"AM");
  3460. break;
  3461. default:
  3462. return DC_ERROR;
  3463. }
  3464. if(res)
  3465. return DC_ERROR;
  3466. if(setrem(myrpt))
  3467. return DC_ERROR;
  3468. return DC_COMPLETE;
  3469. case 100: /* other stuff */
  3470. case 101:
  3471. case 102:
  3472. case 103:
  3473. case 104:
  3474. case 105:
  3475. case 106:
  3476. res = rmt_telem_start(myrpt, mychannel, 1000);
  3477. switch(myatoi(param)){ /* Quick commands requiring a setrem call */
  3478. case 100: /* RX PL Off */
  3479. myrpt->rxplon = 0;
  3480. if(!res)
  3481. res = sayfile(mychannel, "rpt/rxpl");
  3482. if(!res)
  3483. sayfile(mychannel, "rpt/off");
  3484. break;
  3485. case 101: /* RX PL On */
  3486. myrpt->rxplon = 1;
  3487. if(!res)
  3488. res = sayfile(mychannel, "rpt/rxpl");
  3489. if(!res)
  3490. sayfile(mychannel, "rpt/on");
  3491. break;
  3492. case 102: /* TX PL Off */
  3493. myrpt->txplon = 0;
  3494. if(!res)
  3495. res = sayfile(mychannel, "rpt/txpl");
  3496. if(!res)
  3497. sayfile(mychannel, "rpt/off");
  3498. break;
  3499. case 103: /* TX PL On */
  3500. myrpt->txplon = 1;
  3501. if(!res)
  3502. res = sayfile(mychannel, "rpt/txpl");
  3503. if(!res)
  3504. sayfile(mychannel, "rpt/on");
  3505. break;
  3506. case 104: /* Low Power */
  3507. myrpt->powerlevel = REM_LOWPWR;
  3508. if(!res)
  3509. res = sayfile(mychannel, "rpt/lopwr");
  3510. break;
  3511. case 105: /* Medium Power */
  3512. myrpt->powerlevel = REM_MEDPWR;
  3513. if(!res)
  3514. res = sayfile(mychannel, "rpt/medpwr");
  3515. break;
  3516. case 106: /* Hi Power */
  3517. myrpt->powerlevel = REM_HIPWR;
  3518. if(!res)
  3519. res = sayfile(mychannel, "rpt/hipwr");
  3520. break;
  3521. default:
  3522. if(!res)
  3523. rmt_telem_finish(myrpt, mychannel);
  3524. return DC_ERROR;
  3525. }
  3526. if(!res)
  3527. res = rmt_telem_finish(myrpt, mychannel);
  3528. if(res)
  3529. return DC_ERROR;
  3530. if (setrem(myrpt) == -1)
  3531. return DC_ERROR;
  3532. return DC_COMPLETE;
  3533. case 107: /* Bump down 20Hz */
  3534. multimode_bump_freq(myrpt, -20);
  3535. return DC_COMPLETE;
  3536. case 108: /* Bump down 100Hz */
  3537. multimode_bump_freq(myrpt, -100);
  3538. return DC_COMPLETE;
  3539. case 109: /* Bump down 500Hz */
  3540. multimode_bump_freq(myrpt, -500);
  3541. return DC_COMPLETE;
  3542. case 110: /* Bump up 20Hz */
  3543. multimode_bump_freq(myrpt, 20);
  3544. return DC_COMPLETE;
  3545. case 111: /* Bump up 100Hz */
  3546. multimode_bump_freq(myrpt, 100);
  3547. return DC_COMPLETE;
  3548. case 112: /* Bump up 500Hz */
  3549. multimode_bump_freq(myrpt, 500);
  3550. return DC_COMPLETE;
  3551. case 113:
  3552. case 114:
  3553. case 115:
  3554. case 116:
  3555. case 117:
  3556. case 118:
  3557. myrpt->remotetx = 0;
  3558. ast_indicate(myrpt->txchannel,AST_CONTROL_RADIO_UNKEY);
  3559. if (!myrpt->remoterx)
  3560. ast_indicate(mychannel,AST_CONTROL_RADIO_KEY);
  3561. if (ast_safe_sleep(mychannel,1000) == -1)
  3562. return DC_ERROR;
  3563. switch(myatoi(param)){
  3564. case 113: /* Scan down slow */
  3565. res = sayfile(mychannel,"rpt/down");
  3566. if(!res)
  3567. res = sayfile(mychannel, "rpt/slow");
  3568. if(!res){
  3569. myrpt->scantimer = REM_SCANTIME;
  3570. myrpt->hfscanmode = HF_SCAN_DOWN_SLOW;
  3571. }
  3572. break;
  3573. case 114: /* Scan down quick */
  3574. res = sayfile(mychannel,"rpt/down");
  3575. if(!res)
  3576. res = sayfile(mychannel, "rpt/quick");
  3577. if(!res){
  3578. myrpt->scantimer = REM_SCANTIME;
  3579. myrpt->hfscanmode = HF_SCAN_DOWN_QUICK;
  3580. }
  3581. break;
  3582. case 115: /* Scan down fast */
  3583. res = sayfile(mychannel,"rpt/down");
  3584. if(!res)
  3585. res = sayfile(mychannel, "rpt/fast");
  3586. if(!res){
  3587. myrpt->scantimer = REM_SCANTIME;
  3588. myrpt->hfscanmode = HF_SCAN_DOWN_FAST;
  3589. }
  3590. break;
  3591. case 116: /* Scan up slow */
  3592. res = sayfile(mychannel,"rpt/up");
  3593. if(!res)
  3594. res = sayfile(mychannel, "rpt/slow");
  3595. if(!res){
  3596. myrpt->scantimer = REM_SCANTIME;
  3597. myrpt->hfscanmode = HF_SCAN_UP_SLOW;
  3598. }
  3599. break;
  3600. case 117: /* Scan up quick */
  3601. res = sayfile(mychannel,"rpt/up");
  3602. if(!res)
  3603. res = sayfile(mychannel, "rpt/quick");
  3604. if(!res){
  3605. myrpt->scantimer = REM_SCANTIME;
  3606. myrpt->hfscanmode = HF_SCAN_UP_QUICK;
  3607. }
  3608. break;
  3609. case 118: /* Scan up fast */
  3610. res = sayfile(mychannel,"rpt/up");
  3611. if(!res)
  3612. res = sayfile(mychannel, "rpt/fast");
  3613. if(!res){
  3614. myrpt->scantimer = REM_SCANTIME;
  3615. myrpt->hfscanmode = HF_SCAN_UP_FAST;
  3616. }
  3617. break;
  3618. }
  3619. rmt_telem_finish(myrpt,mychannel);
  3620. return DC_COMPLETE;
  3621. case 119: /* Tune Request */
  3622. myrpt->tunerequest = 1;
  3623. return DC_COMPLETE;
  3624. case 5: /* Long Status */
  3625. case 140: /* Short Status */
  3626. res = rmt_telem_start(myrpt, mychannel, 1000);
  3627. res = sayfile(mychannel,"rpt/node");
  3628. if(!res)
  3629. res = saycharstr(mychannel, myrpt->name);
  3630. if(!res)
  3631. res = sayfile(mychannel,"rpt/frequency");
  3632. if(!res)
  3633. res = split_freq(mhz, decimals, myrpt->freq);
  3634. if(!res){
  3635. m = atoi(mhz);
  3636. if(m < 100)
  3637. res = saynum(mychannel, m);
  3638. else
  3639. res = saycharstr(mychannel, mhz);
  3640. }
  3641. if(!res)
  3642. res = sayfile(mychannel, "letters/dot");
  3643. if(!res)
  3644. res = saycharstr(mychannel, decimals);
  3645. if(res){
  3646. rmt_telem_finish(myrpt,mychannel);
  3647. return DC_ERROR;
  3648. }
  3649. if(myrpt->remmode == REM_MODE_FM){ /* Mode FM? */
  3650. switch(myrpt->offset){
  3651. case REM_MINUS:
  3652. res = sayfile(mychannel,"rpt/minus");
  3653. break;
  3654. case REM_SIMPLEX:
  3655. res = sayfile(mychannel,"rpt/simplex");
  3656. break;
  3657. case REM_PLUS:
  3658. res = sayfile(mychannel,"rpt/plus");
  3659. break;
  3660. default:
  3661. return DC_ERROR;
  3662. }
  3663. }
  3664. else{ /* Must be USB, LSB, or AM */
  3665. switch(myrpt->remmode){
  3666. case REM_MODE_USB:
  3667. res = saycharstr(mychannel, "USB");
  3668. break;
  3669. case REM_MODE_LSB:
  3670. res = saycharstr(mychannel, "LSB");
  3671. break;
  3672. case REM_MODE_AM:
  3673. res = saycharstr(mychannel, "AM");
  3674. break;
  3675. default:
  3676. return DC_ERROR;
  3677. }
  3678. }
  3679. if (res == -1){
  3680. rmt_telem_finish(myrpt,mychannel);
  3681. return DC_ERROR;
  3682. }
  3683. if(myatoi(param) == 140){ /* Short status? */
  3684. if(!res)
  3685. res = rmt_telem_finish(myrpt, mychannel);
  3686. if(res)
  3687. return DC_ERROR;
  3688. return DC_COMPLETE;
  3689. }
  3690. switch(myrpt->powerlevel){
  3691. case REM_LOWPWR:
  3692. res = sayfile(mychannel,"rpt/lopwr") ;
  3693. break;
  3694. case REM_MEDPWR:
  3695. res = sayfile(mychannel,"rpt/medpwr");
  3696. break;
  3697. case REM_HIPWR:
  3698. res = sayfile(mychannel,"rpt/hipwr");
  3699. break;
  3700. }
  3701. if (res || (sayfile(mychannel,"rpt/rxpl") == -1) ||
  3702. (sayfile(mychannel,"rpt/frequency") == -1) ||
  3703. (saycharstr(mychannel,myrpt->rxpl) == -1) ||
  3704. (sayfile(mychannel,"rpt/txpl") == -1) ||
  3705. (sayfile(mychannel,"rpt/frequency") == -1) ||
  3706. (saycharstr(mychannel,myrpt->txpl) == -1) ||
  3707. (sayfile(mychannel,"rpt/txpl") == -1) ||
  3708. (sayfile(mychannel,((myrpt->txplon) ? "rpt/on" : "rpt/off")) == -1) ||
  3709. (sayfile(mychannel,"rpt/rxpl") == -1) ||
  3710. (sayfile(mychannel,((myrpt->rxplon) ? "rpt/on" : "rpt/off")) == -1))
  3711. {
  3712. rmt_telem_finish(myrpt,mychannel);
  3713. return DC_ERROR;
  3714. }
  3715. if(!res)
  3716. res = rmt_telem_finish(myrpt,mychannel);
  3717. if(res)
  3718. return DC_ERROR;
  3719. return DC_COMPLETE;
  3720. default:
  3721. return DC_ERROR;
  3722. }
  3723. return DC_INDETERMINATE;
  3724. }
  3725. static int handle_remote_dtmf_digit(struct rpt *myrpt,char c, char *keyed, int phonemode)
  3726. {
  3727. time_t now;
  3728. int ret,res = 0,src;
  3729. /* Stop scan mode if in scan mode */
  3730. if(myrpt->hfscanmode){
  3731. stop_scan(myrpt,0);
  3732. return 0;
  3733. }
  3734. time(&now);
  3735. /* if timed-out */
  3736. if ((myrpt->dtmf_time_rem + DTMF_TIMEOUT) < now)
  3737. {
  3738. myrpt->dtmfidx = -1;
  3739. myrpt->dtmfbuf[0] = 0;
  3740. myrpt->dtmf_time_rem = 0;
  3741. }
  3742. /* if decode not active */
  3743. if (myrpt->dtmfidx == -1)
  3744. {
  3745. /* if not lead-in digit, dont worry */
  3746. if (c != myrpt->funcchar) return 0;
  3747. myrpt->dtmfidx = 0;
  3748. myrpt->dtmfbuf[0] = 0;
  3749. myrpt->dtmf_time_rem = now;
  3750. return 0;
  3751. }
  3752. /* if too many in buffer, start over */
  3753. if (myrpt->dtmfidx >= MAXDTMF)
  3754. {
  3755. myrpt->dtmfidx = 0;
  3756. myrpt->dtmfbuf[0] = 0;
  3757. myrpt->dtmf_time_rem = now;
  3758. }
  3759. if (c == myrpt->funcchar)
  3760. {
  3761. /* if star at beginning, or 2 together, erase buffer */
  3762. if ((myrpt->dtmfidx < 1) ||
  3763. (myrpt->dtmfbuf[myrpt->dtmfidx - 1] == myrpt->funcchar))
  3764. {
  3765. myrpt->dtmfidx = 0;
  3766. myrpt->dtmfbuf[0] = 0;
  3767. myrpt->dtmf_time_rem = now;
  3768. return 0;
  3769. }
  3770. }
  3771. myrpt->dtmfbuf[myrpt->dtmfidx++] = c;
  3772. myrpt->dtmfbuf[myrpt->dtmfidx] = 0;
  3773. myrpt->dtmf_time_rem = now;
  3774. src = SOURCE_RMT;
  3775. if (phonemode > 1) src = SOURCE_DPHONE;
  3776. else if (phonemode) src = SOURCE_PHONE;
  3777. ret = collect_function_digits(myrpt, myrpt->dtmfbuf, src, NULL);
  3778. switch(ret){
  3779. case DC_INDETERMINATE:
  3780. res = 0;
  3781. break;
  3782. case DC_DOKEY:
  3783. if (keyed) *keyed = 1;
  3784. res = 0;
  3785. break;
  3786. case DC_REQ_FLUSH:
  3787. myrpt->dtmfidx = 0;
  3788. myrpt->dtmfbuf[0] = 0;
  3789. res = 0;
  3790. break;
  3791. case DC_COMPLETE:
  3792. myrpt->dtmfbuf[0] = 0;
  3793. myrpt->dtmfidx = -1;
  3794. myrpt->dtmf_time_rem = 0;
  3795. res = 1;
  3796. break;
  3797. case DC_ERROR:
  3798. default:
  3799. myrpt->dtmfbuf[0] = 0;
  3800. myrpt->dtmfidx = -1;
  3801. myrpt->dtmf_time_rem = 0;
  3802. res = 0;
  3803. break;
  3804. }
  3805. return res;
  3806. }
  3807. static int handle_remote_data(struct rpt *myrpt, char *str)
  3808. {
  3809. char tmp[300],cmd[300],dest[300],src[300],c;
  3810. int seq,res;
  3811. /* put string in our buffer */
  3812. strncpy(tmp,str,sizeof(tmp) - 1);
  3813. if (!strcmp(tmp,discstr)) return 0;
  3814. if (sscanf(tmp,"%s %s %s %d %c",cmd,dest,src,&seq,&c) != 5)
  3815. {
  3816. ast_log(LOG_WARNING, "Unable to parse link string %s\n",str);
  3817. return 0;
  3818. }
  3819. if (strcmp(cmd,"D"))
  3820. {
  3821. ast_log(LOG_WARNING, "Unable to parse link string %s\n",str);
  3822. return 0;
  3823. }
  3824. /* if not for me, ignore */
  3825. if (strcmp(dest,myrpt->name)) return 0;
  3826. res = handle_remote_dtmf_digit(myrpt,c, NULL, 0);
  3827. if (res != 1)
  3828. return res;
  3829. myrpt->remotetx = 0;
  3830. ast_indicate(myrpt->txchannel,AST_CONTROL_RADIO_UNKEY);
  3831. if (!myrpt->remoterx)
  3832. {
  3833. ast_indicate(myrpt->remchannel,AST_CONTROL_RADIO_KEY);
  3834. }
  3835. if (ast_safe_sleep(myrpt->remchannel,1000) == -1) return -1;
  3836. res = telem_lookup(myrpt->remchannel, myrpt->name, "functcomplete");
  3837. rmt_telem_finish(myrpt,myrpt->remchannel);
  3838. return res;
  3839. }
  3840. static int handle_remote_phone_dtmf(struct rpt *myrpt, char c, char *keyed, int phonemode)
  3841. {
  3842. int res;
  3843. if (keyed && *keyed && (c == myrpt->endchar))
  3844. {
  3845. *keyed = 0;
  3846. return DC_INDETERMINATE;
  3847. }
  3848. res = handle_remote_dtmf_digit(myrpt,c,keyed, phonemode);
  3849. if (res != 1)
  3850. return res;
  3851. myrpt->remotetx = 0;
  3852. ast_indicate(myrpt->txchannel,AST_CONTROL_RADIO_UNKEY);
  3853. if (!myrpt->remoterx)
  3854. {
  3855. ast_indicate(myrpt->remchannel,AST_CONTROL_RADIO_KEY);
  3856. }
  3857. if (ast_safe_sleep(myrpt->remchannel,1000) == -1) return -1;
  3858. res = telem_lookup(myrpt->remchannel, myrpt->name, "functcomplete");
  3859. rmt_telem_finish(myrpt,myrpt->remchannel);
  3860. return res;
  3861. }
  3862. static int attempt_reconnect(struct rpt *myrpt, struct rpt_link *l)
  3863. {
  3864. char *val, *s, *s1, *s2, *tele;
  3865. char tmp[300], deststr[300] = "";
  3866. val = ast_variable_retrieve(cfg, myrpt->nodes, l->name);
  3867. if (!val)
  3868. {
  3869. fprintf(stderr,"attempt_reconnect: cannot find node %s\n",l->name);
  3870. return -1;
  3871. }
  3872. ast_mutex_lock(&myrpt->lock);
  3873. /* remove from queue */
  3874. remque((struct qelem *) l);
  3875. ast_mutex_unlock(&myrpt->lock);
  3876. strncpy(tmp,val,sizeof(tmp) - 1);
  3877. s = tmp;
  3878. s1 = strsep(&s,",");
  3879. s2 = strsep(&s,",");
  3880. snprintf(deststr, sizeof(deststr), "IAX2/%s", s1);
  3881. tele = strchr(deststr, '/');
  3882. if (!tele) {
  3883. fprintf(stderr,"attempt_reconnect:Dial number (%s) must be in format tech/number\n",deststr);
  3884. return -1;
  3885. }
  3886. *tele++ = 0;
  3887. l->elaptime = 0;
  3888. l->chan = ast_request(deststr, AST_FORMAT_SLINEAR, tele,NULL);
  3889. if (l->chan){
  3890. ast_set_read_format(l->chan, AST_FORMAT_SLINEAR);
  3891. ast_set_write_format(l->chan, AST_FORMAT_SLINEAR);
  3892. l->chan->whentohangup = 0;
  3893. l->chan->appl = "Apprpt";
  3894. l->chan->data = "(Remote Rx)";
  3895. if (option_verbose > 2)
  3896. ast_verbose(VERBOSE_PREFIX_3 "rpt (attempt_reconnect) initiating call to %s/%s on %s\n",
  3897. deststr, tele, l->chan->name);
  3898. if(l->chan->cid.cid_num)
  3899. free(l->chan->cid.cid_num);
  3900. l->chan->cid.cid_num = strdup(myrpt->name);
  3901. ast_call(l->chan,tele,999);
  3902. }
  3903. else
  3904. {
  3905. if (option_verbose > 2)
  3906. ast_verbose(VERBOSE_PREFIX_3 "Unable to place call to %s/%s on %s\n",
  3907. deststr,tele,l->chan->name);
  3908. return -1;
  3909. }
  3910. ast_mutex_lock(&myrpt->lock);
  3911. /* put back in queue queue */
  3912. insque((struct qelem *)l,(struct qelem *)myrpt->links.next);
  3913. ast_mutex_unlock(&myrpt->lock);
  3914. ast_log(LOG_NOTICE,"Reconnect Attempt to %s in process\n",l->name);
  3915. return 0;
  3916. }
  3917. /* single thread with one file (request) to dial */
  3918. static void *rpt(void *this)
  3919. {
  3920. struct rpt *myrpt = (struct rpt *)this;
  3921. char *tele,*idtalkover;
  3922. int ms = MSWAIT,lasttx=0,val,remrx=0,identqueued,nonidentqueued,res;
  3923. struct ast_channel *who;
  3924. ZT_CONFINFO ci; /* conference info */
  3925. time_t dtmf_time,t;
  3926. struct rpt_link *l,*m;
  3927. struct rpt_tele *telem;
  3928. pthread_attr_t attr;
  3929. char tmpstr[300];
  3930. char cmd[MAXDTMF+1] = "";
  3931. ast_mutex_lock(&myrpt->lock);
  3932. strncpy(tmpstr,myrpt->rxchanname,sizeof(tmpstr) - 1);
  3933. tele = strchr(tmpstr,'/');
  3934. if (!tele)
  3935. {
  3936. fprintf(stderr,"rpt:Dial number (%s) must be in format tech/number\n",myrpt->rxchanname);
  3937. ast_mutex_unlock(&myrpt->lock);
  3938. myrpt->rpt_thread = AST_PTHREADT_STOP;
  3939. pthread_exit(NULL);
  3940. }
  3941. *tele++ = 0;
  3942. myrpt->rxchannel = ast_request(tmpstr,AST_FORMAT_SLINEAR,tele,NULL);
  3943. if (myrpt->rxchannel)
  3944. {
  3945. if (myrpt->rxchannel->_state == AST_STATE_BUSY)
  3946. {
  3947. fprintf(stderr,"rpt:Sorry unable to obtain Rx channel\n");
  3948. ast_mutex_unlock(&myrpt->lock);
  3949. ast_hangup(myrpt->rxchannel);
  3950. myrpt->rpt_thread = AST_PTHREADT_STOP;
  3951. pthread_exit(NULL);
  3952. }
  3953. ast_set_read_format(myrpt->rxchannel,AST_FORMAT_SLINEAR);
  3954. ast_set_write_format(myrpt->rxchannel,AST_FORMAT_SLINEAR);
  3955. myrpt->rxchannel->whentohangup = 0;
  3956. myrpt->rxchannel->appl = "Apprpt";
  3957. myrpt->rxchannel->data = "(Repeater Rx)";
  3958. if (option_verbose > 2)
  3959. ast_verbose(VERBOSE_PREFIX_3 "rpt (Rx) initiating call to %s/%s on %s\n",
  3960. tmpstr,tele,myrpt->rxchannel->name);
  3961. ast_call(myrpt->rxchannel,tele,999);
  3962. if (myrpt->rxchannel->_state != AST_STATE_UP)
  3963. {
  3964. ast_mutex_unlock(&myrpt->lock);
  3965. ast_hangup(myrpt->rxchannel);
  3966. myrpt->rpt_thread = AST_PTHREADT_STOP;
  3967. pthread_exit(NULL);
  3968. }
  3969. }
  3970. else
  3971. {
  3972. fprintf(stderr,"rpt:Sorry unable to obtain Rx channel\n");
  3973. ast_mutex_unlock(&myrpt->lock);
  3974. myrpt->rpt_thread = AST_PTHREADT_STOP;
  3975. pthread_exit(NULL);
  3976. }
  3977. if (myrpt->txchanname)
  3978. {
  3979. strncpy(tmpstr,myrpt->txchanname,sizeof(tmpstr) - 1);
  3980. tele = strchr(tmpstr,'/');
  3981. if (!tele)
  3982. {
  3983. fprintf(stderr,"rpt:Dial number (%s) must be in format tech/number\n",myrpt->txchanname);
  3984. ast_mutex_unlock(&myrpt->lock);
  3985. ast_hangup(myrpt->rxchannel);
  3986. myrpt->rpt_thread = AST_PTHREADT_STOP;
  3987. pthread_exit(NULL);
  3988. }
  3989. *tele++ = 0;
  3990. myrpt->txchannel = ast_request(tmpstr,AST_FORMAT_SLINEAR,tele,NULL);
  3991. if (myrpt->txchannel)
  3992. {
  3993. if (myrpt->txchannel->_state == AST_STATE_BUSY)
  3994. {
  3995. fprintf(stderr,"rpt:Sorry unable to obtain Tx channel\n");
  3996. ast_mutex_unlock(&myrpt->lock);
  3997. ast_hangup(myrpt->txchannel);
  3998. ast_hangup(myrpt->rxchannel);
  3999. myrpt->rpt_thread = AST_PTHREADT_STOP;
  4000. pthread_exit(NULL);
  4001. }
  4002. ast_set_read_format(myrpt->txchannel,AST_FORMAT_SLINEAR);
  4003. ast_set_write_format(myrpt->txchannel,AST_FORMAT_SLINEAR);
  4004. myrpt->txchannel->whentohangup = 0;
  4005. myrpt->txchannel->appl = "Apprpt";
  4006. myrpt->txchannel->data = "(Repeater Tx)";
  4007. if (option_verbose > 2)
  4008. ast_verbose(VERBOSE_PREFIX_3 "rpt (Tx) initiating call to %s/%s on %s\n",
  4009. tmpstr,tele,myrpt->txchannel->name);
  4010. ast_call(myrpt->txchannel,tele,999);
  4011. if (myrpt->rxchannel->_state != AST_STATE_UP)
  4012. {
  4013. ast_mutex_unlock(&myrpt->lock);
  4014. ast_hangup(myrpt->rxchannel);
  4015. ast_hangup(myrpt->txchannel);
  4016. myrpt->rpt_thread = AST_PTHREADT_STOP;
  4017. pthread_exit(NULL);
  4018. }
  4019. }
  4020. else
  4021. {
  4022. fprintf(stderr,"rpt:Sorry unable to obtain Tx channel\n");
  4023. ast_mutex_unlock(&myrpt->lock);
  4024. ast_hangup(myrpt->rxchannel);
  4025. myrpt->rpt_thread = AST_PTHREADT_STOP;
  4026. pthread_exit(NULL);
  4027. }
  4028. }
  4029. else
  4030. {
  4031. myrpt->txchannel = myrpt->rxchannel;
  4032. }
  4033. ast_indicate(myrpt->txchannel,AST_CONTROL_RADIO_KEY);
  4034. ast_indicate(myrpt->txchannel,AST_CONTROL_RADIO_UNKEY);
  4035. /* allocate a pseudo-channel thru asterisk */
  4036. myrpt->pchannel = ast_request("zap",AST_FORMAT_SLINEAR,"pseudo",NULL);
  4037. if (!myrpt->pchannel)
  4038. {
  4039. fprintf(stderr,"rpt:Sorry unable to obtain pseudo channel\n");
  4040. ast_mutex_unlock(&myrpt->lock);
  4041. if (myrpt->txchannel != myrpt->rxchannel)
  4042. ast_hangup(myrpt->txchannel);
  4043. ast_hangup(myrpt->rxchannel);
  4044. myrpt->rpt_thread = AST_PTHREADT_STOP;
  4045. pthread_exit(NULL);
  4046. }
  4047. /* make a conference for the tx */
  4048. ci.chan = 0;
  4049. ci.confno = -1; /* make a new conf */
  4050. ci.confmode = ZT_CONF_CONF | ZT_CONF_LISTENER;
  4051. /* first put the channel on the conference in proper mode */
  4052. if (ioctl(myrpt->txchannel->fds[0],ZT_SETCONF,&ci) == -1)
  4053. {
  4054. ast_log(LOG_WARNING, "Unable to set conference mode to Announce\n");
  4055. ast_mutex_unlock(&myrpt->lock);
  4056. ast_hangup(myrpt->pchannel);
  4057. if (myrpt->txchannel != myrpt->rxchannel)
  4058. ast_hangup(myrpt->txchannel);
  4059. ast_hangup(myrpt->rxchannel);
  4060. myrpt->rpt_thread = AST_PTHREADT_STOP;
  4061. pthread_exit(NULL);
  4062. }
  4063. /* save tx conference number */
  4064. myrpt->txconf = ci.confno;
  4065. /* make a conference for the pseudo */
  4066. ci.chan = 0;
  4067. ci.confno = -1; /* make a new conf */
  4068. ci.confmode = ZT_CONF_CONFANNMON;
  4069. /* first put the channel on the conference in announce mode */
  4070. if (ioctl(myrpt->pchannel->fds[0],ZT_SETCONF,&ci) == -1)
  4071. {
  4072. ast_log(LOG_WARNING, "Unable to set conference mode to Announce\n");
  4073. ast_mutex_unlock(&myrpt->lock);
  4074. ast_hangup(myrpt->pchannel);
  4075. if (myrpt->txchannel != myrpt->rxchannel)
  4076. ast_hangup(myrpt->txchannel);
  4077. ast_hangup(myrpt->rxchannel);
  4078. myrpt->rpt_thread = AST_PTHREADT_STOP;
  4079. pthread_exit(NULL);
  4080. }
  4081. /* save pseudo channel conference number */
  4082. myrpt->conf = ci.confno;
  4083. /* allocate a pseudo-channel thru asterisk */
  4084. myrpt->txpchannel = ast_request("zap",AST_FORMAT_SLINEAR,"pseudo",NULL);
  4085. if (!myrpt->txpchannel)
  4086. {
  4087. fprintf(stderr,"rpt:Sorry unable to obtain pseudo channel\n");
  4088. ast_mutex_unlock(&myrpt->lock);
  4089. ast_hangup(myrpt->pchannel);
  4090. if (myrpt->txchannel != myrpt->rxchannel)
  4091. ast_hangup(myrpt->txchannel);
  4092. ast_hangup(myrpt->rxchannel);
  4093. myrpt->rpt_thread = AST_PTHREADT_STOP;
  4094. pthread_exit(NULL);
  4095. }
  4096. /* make a conference for the tx */
  4097. ci.chan = 0;
  4098. ci.confno = myrpt->txconf;
  4099. ci.confmode = ZT_CONF_CONF | ZT_CONF_TALKER ;
  4100. /* first put the channel on the conference in proper mode */
  4101. if (ioctl(myrpt->txpchannel->fds[0],ZT_SETCONF,&ci) == -1)
  4102. {
  4103. ast_log(LOG_WARNING, "Unable to set conference mode to Announce\n");
  4104. ast_mutex_unlock(&myrpt->lock);
  4105. ast_hangup(myrpt->txpchannel);
  4106. ast_hangup(myrpt->pchannel);
  4107. if (myrpt->txchannel != myrpt->rxchannel)
  4108. ast_hangup(myrpt->txchannel);
  4109. ast_hangup(myrpt->rxchannel);
  4110. myrpt->rpt_thread = AST_PTHREADT_STOP;
  4111. pthread_exit(NULL);
  4112. }
  4113. /* Now, the idea here is to copy from the physical rx channel buffer
  4114. into the pseudo tx buffer, and from the pseudo rx buffer into the
  4115. tx channel buffer */
  4116. myrpt->links.next = &myrpt->links;
  4117. myrpt->links.prev = &myrpt->links;
  4118. myrpt->tailtimer = 0;
  4119. myrpt->totimer = 0;
  4120. myrpt->idtimer = myrpt->politeid;
  4121. myrpt->mustid = 0;
  4122. myrpt->callmode = 0;
  4123. myrpt->tounkeyed = 0;
  4124. myrpt->tonotify = 0;
  4125. myrpt->retxtimer = 0;
  4126. lasttx = 0;
  4127. myrpt->keyed = 0;
  4128. idtalkover = ast_variable_retrieve(cfg, myrpt->name, "idtalkover");
  4129. myrpt->dtmfidx = -1;
  4130. myrpt->dtmfbuf[0] = 0;
  4131. myrpt->rem_dtmfidx = -1;
  4132. myrpt->rem_dtmfbuf[0] = 0;
  4133. dtmf_time = 0;
  4134. myrpt->rem_dtmf_time = 0;
  4135. myrpt->enable = 1;
  4136. myrpt->disgorgetime = 0;
  4137. ast_mutex_unlock(&myrpt->lock);
  4138. val = 0;
  4139. ast_channel_setoption(myrpt->rxchannel,AST_OPTION_TONE_VERIFY,&val,sizeof(char),0);
  4140. val = 1;
  4141. ast_channel_setoption(myrpt->rxchannel,AST_OPTION_RELAXDTMF,&val,sizeof(char),0);
  4142. while (ms >= 0)
  4143. {
  4144. struct ast_frame *f;
  4145. struct ast_channel *cs[300];
  4146. int totx=0,elap=0,n,toexit=0;
  4147. /* DEBUG Dump */
  4148. if((myrpt->disgorgetime) && (time(NULL) >= myrpt->disgorgetime)){
  4149. struct rpt_link *zl;
  4150. struct rpt_tele *zt;
  4151. myrpt->disgorgetime = 0;
  4152. ast_log(LOG_NOTICE,"********** Variable Dump Start (app_rpt) **********\n");
  4153. ast_log(LOG_NOTICE,"totx = %d\n",totx);
  4154. ast_log(LOG_NOTICE,"remrx = %d\n",remrx);
  4155. ast_log(LOG_NOTICE,"lasttx = %d\n",lasttx);
  4156. ast_log(LOG_NOTICE,"elap = %d\n",elap);
  4157. ast_log(LOG_NOTICE,"toexit = %d\n",toexit);
  4158. ast_log(LOG_NOTICE,"myrpt->keyed = %d\n",myrpt->keyed);
  4159. ast_log(LOG_NOTICE,"myrpt->localtx = %d\n",myrpt->localtx);
  4160. ast_log(LOG_NOTICE,"myrpt->callmode = %d\n",myrpt->callmode);
  4161. ast_log(LOG_NOTICE,"myrpt->enable = %d\n",myrpt->enable);
  4162. ast_log(LOG_NOTICE,"myrpt->mustid = %d\n",myrpt->mustid);
  4163. ast_log(LOG_NOTICE,"myrpt->tounkeyed = %d\n",myrpt->tounkeyed);
  4164. ast_log(LOG_NOTICE,"myrpt->tonotify = %d\n",myrpt->tonotify);
  4165. ast_log(LOG_NOTICE,"myrpt->retxtimer = %ld\n",myrpt->retxtimer);
  4166. ast_log(LOG_NOTICE,"myrpt->totimer = %d\n",myrpt->totimer);
  4167. ast_log(LOG_NOTICE,"myrpt->tailtimer = %d\n",myrpt->tailtimer);
  4168. zl = myrpt->links.next;
  4169. while(zl != &myrpt->links){
  4170. ast_log(LOG_NOTICE,"*** Link Name: %s ***\n",zl->name);
  4171. ast_log(LOG_NOTICE," link->lasttx %d\n",zl->lasttx);
  4172. ast_log(LOG_NOTICE," link->lastrx %d\n",zl->lastrx);
  4173. ast_log(LOG_NOTICE," link->connected %d\n",zl->connected);
  4174. ast_log(LOG_NOTICE," link->hasconnected %d\n",zl->hasconnected);
  4175. ast_log(LOG_NOTICE," link->outbound %d\n",zl->outbound);
  4176. ast_log(LOG_NOTICE," link->disced %d\n",zl->disced);
  4177. ast_log(LOG_NOTICE," link->killme %d\n",zl->killme);
  4178. ast_log(LOG_NOTICE," link->disctime %ld\n",zl->disctime);
  4179. ast_log(LOG_NOTICE," link->retrytimer %ld\n",zl->retrytimer);
  4180. ast_log(LOG_NOTICE," link->retries = %d\n",zl->retries);
  4181. zl = zl->next;
  4182. }
  4183. zt = myrpt->tele.next;
  4184. if(zt != &myrpt->tele)
  4185. ast_log(LOG_NOTICE,"*** Telemetry Queue ***\n");
  4186. while(zt != &myrpt->tele){
  4187. ast_log(LOG_NOTICE," Telemetry mode: %d\n",zt->mode);
  4188. zt = zt->next;
  4189. }
  4190. ast_log(LOG_NOTICE,"******* Variable Dump End (app_rpt) *******\n");
  4191. }
  4192. ast_mutex_lock(&myrpt->lock);
  4193. if (ast_check_hangup(myrpt->rxchannel)) break;
  4194. if (ast_check_hangup(myrpt->txchannel)) break;
  4195. if (ast_check_hangup(myrpt->pchannel)) break;
  4196. if (ast_check_hangup(myrpt->txpchannel)) break;
  4197. myrpt->localtx = myrpt->keyed && (myrpt->dtmfidx == -1) && (!myrpt->cmdnode[0]);
  4198. /* If someone's connected, and they're transmitting from their end to us, set remrx true */
  4199. l = myrpt->links.next;
  4200. remrx = 0;
  4201. while(l != &myrpt->links)
  4202. {
  4203. if (l->lastrx) remrx = 1;
  4204. l = l->next;
  4205. }
  4206. /* Create a "must_id" flag for the cleanup ID */
  4207. myrpt->mustid |= (myrpt->idtimer) && (myrpt->keyed || remrx) ;
  4208. /* Build a fresh totx from myrpt->keyed and autopatch activated */
  4209. totx = myrpt->localtx || myrpt->callmode;
  4210. /* Traverse the telemetry list to see if there's an ID queued and if there is not an ID queued */
  4211. identqueued = 0;
  4212. nonidentqueued = 0;
  4213. telem = myrpt->tele.next;
  4214. while(telem != &myrpt->tele)
  4215. {
  4216. if((telem->mode == ID) || (telem->mode == IDTALKOVER)){
  4217. identqueued = 1;
  4218. }
  4219. else
  4220. nonidentqueued = 1;
  4221. telem = telem->next;
  4222. }
  4223. /* Add in any non-id telemetry */
  4224. totx = totx || nonidentqueued;
  4225. /* Update external transmitter PTT state with everything but ID telemetry */
  4226. myrpt->exttx = totx;
  4227. /* Add in ID telemetry to local transmitter */
  4228. totx = totx || remrx || identqueued;
  4229. if (!totx)
  4230. {
  4231. myrpt->totimer = myrpt->totime;
  4232. myrpt->tounkeyed = 0;
  4233. myrpt->tonotify = 0;
  4234. }
  4235. else myrpt->tailtimer = myrpt->hangtime;
  4236. totx = totx && myrpt->totimer;
  4237. /* if timed-out and not said already, say it */
  4238. if ((!myrpt->totimer) && (!myrpt->tonotify))
  4239. {
  4240. myrpt->tonotify = 1;
  4241. ast_mutex_unlock(&myrpt->lock);
  4242. rpt_telemetry(myrpt,TIMEOUT,NULL);
  4243. ast_mutex_lock(&myrpt->lock);
  4244. }
  4245. /* if wants to transmit and in phone call, but timed out,
  4246. reset time-out timer if keyed */
  4247. if ((!totx) && (!myrpt->totimer) && (!myrpt->tounkeyed) && (!myrpt->keyed))
  4248. {
  4249. myrpt->tounkeyed = 1;
  4250. }
  4251. if ((!totx) && (!myrpt->totimer) && myrpt->tounkeyed && myrpt->keyed)
  4252. {
  4253. myrpt->totimer = myrpt->totime;
  4254. myrpt->tounkeyed = 0;
  4255. myrpt->tonotify = 0;
  4256. ast_mutex_unlock(&myrpt->lock);
  4257. continue;
  4258. }
  4259. /* if timed-out and in circuit busy after call */
  4260. if ((!totx) && (!myrpt->totimer) && (myrpt->callmode == 4))
  4261. {
  4262. myrpt->callmode = 0;
  4263. }
  4264. /* get rid of tail if timed out */
  4265. if (!myrpt->totimer) myrpt->tailtimer = 0;
  4266. /* if not timed-out, add in tail */
  4267. if (myrpt->totimer) totx = totx || myrpt->tailtimer;
  4268. /* If user or links key up or are keyed up over standard ID, switch to talkover ID, if one is defined */
  4269. if (identqueued && (myrpt->keyed || remrx) && idtalkover) {
  4270. int hasid = 0,hastalkover = 0;
  4271. telem = myrpt->tele.next;
  4272. while(telem != &myrpt->tele){
  4273. if(telem->mode == ID){
  4274. if (telem->chan) ast_softhangup(telem->chan, AST_SOFTHANGUP_DEV); /* Whoosh! */
  4275. hasid = 1;
  4276. }
  4277. if (telem->mode == IDTALKOVER) hastalkover = 1;
  4278. telem = telem->next;
  4279. }
  4280. ast_mutex_unlock(&myrpt->lock);
  4281. if (hasid && (!hastalkover)) rpt_telemetry(myrpt, IDTALKOVER, NULL); /* Start Talkover ID */
  4282. ast_mutex_lock(&myrpt->lock);
  4283. }
  4284. /* Try to be polite */
  4285. /* If the repeater has been inactive for longer than the ID time, do an initial ID in the tail*/
  4286. /* If within 30 seconds of the time to ID, try do it in the tail */
  4287. /* else if at ID time limit, do it right over the top of them */
  4288. /* Lastly, if the repeater has been keyed, and the ID timer is expired, do a clean up ID */
  4289. if (((totx && (!myrpt->exttx) && (myrpt->idtimer <= myrpt->politeid) && myrpt->tailtimer)) ||
  4290. (myrpt->mustid && (!myrpt->idtimer)))
  4291. {
  4292. myrpt->mustid = 0;
  4293. myrpt->idtimer = myrpt->idtime; /* Reset our ID timer */
  4294. ast_mutex_unlock(&myrpt->lock);
  4295. rpt_telemetry(myrpt,ID,NULL);
  4296. ast_mutex_lock(&myrpt->lock);
  4297. }
  4298. /* let telemetry transmit anyway (regardless of timeout) */
  4299. totx = totx || (myrpt->tele.next != &myrpt->tele);
  4300. if (totx && (!lasttx))
  4301. {
  4302. lasttx = 1;
  4303. ast_mutex_unlock(&myrpt->lock);
  4304. ast_indicate(myrpt->txchannel,AST_CONTROL_RADIO_KEY);
  4305. ast_mutex_lock(&myrpt->lock);
  4306. }
  4307. totx = totx && myrpt->enable;
  4308. if ((!totx) && lasttx)
  4309. {
  4310. lasttx = 0;
  4311. ast_mutex_unlock(&myrpt->lock);
  4312. ast_indicate(myrpt->txchannel,AST_CONTROL_RADIO_UNKEY);
  4313. ast_mutex_lock(&myrpt->lock);
  4314. }
  4315. time(&t);
  4316. /* if DTMF timeout */
  4317. if ((!myrpt->cmdnode[0]) && (myrpt->dtmfidx >= 0) && ((dtmf_time + DTMF_TIMEOUT) < t))
  4318. {
  4319. myrpt->dtmfidx = -1;
  4320. myrpt->dtmfbuf[0] = 0;
  4321. }
  4322. /* if remote DTMF timeout */
  4323. if ((myrpt->rem_dtmfidx >= 0) && ((myrpt->rem_dtmf_time + DTMF_TIMEOUT) < t))
  4324. {
  4325. myrpt->rem_dtmfidx = -1;
  4326. myrpt->rem_dtmfbuf[0] = 0;
  4327. }
  4328. /* Reconnect kludge */
  4329. l = myrpt->links.next;
  4330. while(l != &myrpt->links)
  4331. {
  4332. if (l->killme)
  4333. {
  4334. /* remove from queue */
  4335. remque((struct qelem *) l);
  4336. if (!strcmp(myrpt->cmdnode,l->name))
  4337. myrpt->cmdnode[0] = 0;
  4338. ast_mutex_unlock(&myrpt->lock);
  4339. /* hang-up on call to device */
  4340. if (l->chan) ast_hangup(l->chan);
  4341. ast_hangup(l->pchan);
  4342. free(l);
  4343. ast_mutex_lock(&myrpt->lock);
  4344. /* re-start link traversal */
  4345. l = myrpt->links.next;
  4346. continue;
  4347. }
  4348. l = l->next;
  4349. }
  4350. n = 0;
  4351. cs[n++] = myrpt->rxchannel;
  4352. cs[n++] = myrpt->pchannel;
  4353. cs[n++] = myrpt->txpchannel;
  4354. if (myrpt->txchannel != myrpt->rxchannel) cs[n++] = myrpt->txchannel;
  4355. l = myrpt->links.next;
  4356. while(l != &myrpt->links)
  4357. {
  4358. if ((!l->killme) && (!l->disctime) && l->chan)
  4359. {
  4360. cs[n++] = l->chan;
  4361. cs[n++] = l->pchan;
  4362. }
  4363. l = l->next;
  4364. }
  4365. ast_mutex_unlock(&myrpt->lock);
  4366. ms = MSWAIT;
  4367. who = ast_waitfor_n(cs,n,&ms);
  4368. if (who == NULL) ms = 0;
  4369. elap = MSWAIT - ms;
  4370. ast_mutex_lock(&myrpt->lock);
  4371. l = myrpt->links.next;
  4372. while(l != &myrpt->links)
  4373. {
  4374. if (!l->lasttx)
  4375. {
  4376. if ((l->retxtimer += elap) >= REDUNDANT_TX_TIME)
  4377. {
  4378. l->retxtimer = 0;
  4379. if (l->chan) ast_indicate(l->chan,AST_CONTROL_RADIO_UNKEY);
  4380. }
  4381. } else l->retxtimer = 0;
  4382. #ifdef RECONNECT_KLUDGE
  4383. if (l->disctime) /* Disconnect timer active on a channel ? */
  4384. {
  4385. l->disctime -= elap;
  4386. if (l->disctime <= 0) /* Disconnect timer expired on inbound channel ? */
  4387. l->disctime = 0; /* Yep */
  4388. }
  4389. if (l->retrytimer)
  4390. {
  4391. l->retrytimer -= elap;
  4392. if (l->retrytimer < 0) l->retrytimer = 0;
  4393. }
  4394. #endif
  4395. /* ignore non-timing channels */
  4396. if (l->elaptime < 0)
  4397. {
  4398. l = l->next;
  4399. continue;
  4400. }
  4401. l->elaptime += elap;
  4402. /* if connection has taken too long */
  4403. if ((l->elaptime > MAXCONNECTTIME) &&
  4404. ((!l->chan) || (l->chan->_state != AST_STATE_UP)))
  4405. {
  4406. l->elaptime = 0;
  4407. ast_mutex_unlock(&myrpt->lock);
  4408. if (l->chan) ast_softhangup(l->chan,AST_SOFTHANGUP_DEV);
  4409. #ifndef RECONNECT_KLUDGE
  4410. rpt_telemetry(myrpt,CONNFAIL,l);
  4411. #endif
  4412. ast_mutex_lock(&myrpt->lock);
  4413. break;
  4414. }
  4415. #ifdef RECONNECT_KLUDGE
  4416. if ((!l->chan) && (!l->retrytimer) && l->outbound &&
  4417. (l->retries++ < MAX_RETRIES) && (l->hasconnected))
  4418. {
  4419. if (l->chan) ast_hangup(l->chan);
  4420. ast_mutex_unlock(&myrpt->lock);
  4421. if ((l->name[0] != '0') && (!l->isremote))
  4422. {
  4423. l->retrytimer = MAX_RETRIES + 1;
  4424. }
  4425. else
  4426. {
  4427. if (attempt_reconnect(myrpt,l) == -1)
  4428. {
  4429. l->retrytimer = RETRY_TIMER_MS;
  4430. }
  4431. }
  4432. ast_mutex_lock(&myrpt->lock);
  4433. break;
  4434. }
  4435. if ((!l->chan) && (!l->retrytimer) && l->outbound &&
  4436. (l->retries >= MAX_RETRIES))
  4437. {
  4438. /* remove from queue */
  4439. remque((struct qelem *) l);
  4440. if (!strcmp(myrpt->cmdnode,l->name))
  4441. myrpt->cmdnode[0] = 0;
  4442. ast_mutex_unlock(&myrpt->lock);
  4443. if (l->name[0] != '0')
  4444. {
  4445. if (!l->hasconnected)
  4446. rpt_telemetry(myrpt,CONNFAIL,l);
  4447. else rpt_telemetry(myrpt,REMDISC,l);
  4448. }
  4449. /* hang-up on call to device */
  4450. ast_hangup(l->pchan);
  4451. free(l);
  4452. ast_mutex_lock(&myrpt->lock);
  4453. break;
  4454. }
  4455. if ((!l->chan) && (!l->disctime) && (!l->outbound))
  4456. {
  4457. /* remove from queue */
  4458. remque((struct qelem *) l);
  4459. if (!strcmp(myrpt->cmdnode,l->name))
  4460. myrpt->cmdnode[0] = 0;
  4461. ast_mutex_unlock(&myrpt->lock);
  4462. if (l->name[0] != '0')
  4463. {
  4464. rpt_telemetry(myrpt,REMDISC,l);
  4465. }
  4466. /* hang-up on call to device */
  4467. ast_hangup(l->pchan);
  4468. free(l);
  4469. ast_mutex_lock(&myrpt->lock);
  4470. break;
  4471. }
  4472. #endif
  4473. l = l->next;
  4474. }
  4475. if (myrpt->tailtimer) myrpt->tailtimer -= elap;
  4476. if (myrpt->tailtimer < 0) myrpt->tailtimer = 0;
  4477. if (myrpt->totimer) myrpt->totimer -= elap;
  4478. if (myrpt->totimer < 0) myrpt->totimer = 0;
  4479. if (myrpt->idtimer) myrpt->idtimer -= elap;
  4480. if (myrpt->idtimer < 0) myrpt->idtimer = 0;
  4481. ast_mutex_unlock(&myrpt->lock);
  4482. if (!ms) continue;
  4483. if (who == myrpt->rxchannel) /* if it was a read from rx */
  4484. {
  4485. f = ast_read(myrpt->rxchannel);
  4486. if (!f)
  4487. {
  4488. if (debug) printf("@@@@ rpt:Hung Up\n");
  4489. break;
  4490. }
  4491. if (f->frametype == AST_FRAME_VOICE)
  4492. {
  4493. if (!myrpt->localtx)
  4494. memset(f->data,0,f->datalen);
  4495. ast_write(myrpt->pchannel,f);
  4496. }
  4497. else if (f->frametype == AST_FRAME_DTMF)
  4498. {
  4499. char c;
  4500. c = (char) f->subclass; /* get DTMF char */
  4501. ast_frfree(f);
  4502. if (!myrpt->keyed) continue;
  4503. if (c == myrpt->endchar)
  4504. {
  4505. /* if in simple mode, kill autopatch */
  4506. if (myrpt->simple && myrpt->callmode)
  4507. {
  4508. ast_mutex_lock(&myrpt->lock);
  4509. myrpt->callmode = 0;
  4510. ast_mutex_unlock(&myrpt->lock);
  4511. rpt_telemetry(myrpt,TERM,NULL);
  4512. continue;
  4513. }
  4514. ast_mutex_lock(&myrpt->lock);
  4515. myrpt->stopgen = 1;
  4516. if (myrpt->cmdnode[0])
  4517. {
  4518. myrpt->cmdnode[0] = 0;
  4519. myrpt->dtmfidx = -1;
  4520. myrpt->dtmfbuf[0] = 0;
  4521. ast_mutex_unlock(&myrpt->lock);
  4522. rpt_telemetry(myrpt,COMPLETE,NULL);
  4523. } else ast_mutex_unlock(&myrpt->lock);
  4524. continue;
  4525. }
  4526. ast_mutex_lock(&myrpt->lock);
  4527. if (myrpt->cmdnode[0])
  4528. {
  4529. ast_mutex_unlock(&myrpt->lock);
  4530. send_link_dtmf(myrpt,c);
  4531. continue;
  4532. }
  4533. if (!myrpt->simple)
  4534. {
  4535. if (c == myrpt->funcchar)
  4536. {
  4537. myrpt->dtmfidx = 0;
  4538. myrpt->dtmfbuf[myrpt->dtmfidx] = 0;
  4539. ast_mutex_unlock(&myrpt->lock);
  4540. time(&dtmf_time);
  4541. continue;
  4542. }
  4543. else if ((c != myrpt->endchar) && (myrpt->dtmfidx >= 0))
  4544. {
  4545. time(&dtmf_time);
  4546. if (myrpt->dtmfidx < MAXDTMF)
  4547. {
  4548. myrpt->dtmfbuf[myrpt->dtmfidx++] = c;
  4549. myrpt->dtmfbuf[myrpt->dtmfidx] = 0;
  4550. strncpy(cmd, myrpt->dtmfbuf, sizeof(cmd) - 1);
  4551. ast_mutex_unlock(&myrpt->lock);
  4552. res = collect_function_digits(myrpt, cmd, SOURCE_RPT, NULL);
  4553. ast_mutex_lock(&myrpt->lock);
  4554. switch(res){
  4555. case DC_INDETERMINATE:
  4556. break;
  4557. case DC_REQ_FLUSH:
  4558. myrpt->dtmfidx = 0;
  4559. myrpt->dtmfbuf[0] = 0;
  4560. break;
  4561. case DC_COMPLETE:
  4562. myrpt->dtmfbuf[0] = 0;
  4563. myrpt->dtmfidx = -1;
  4564. dtmf_time = 0;
  4565. break;
  4566. case DC_ERROR:
  4567. default:
  4568. myrpt->dtmfbuf[0] = 0;
  4569. myrpt->dtmfidx = -1;
  4570. dtmf_time = 0;
  4571. break;
  4572. }
  4573. if(res != DC_INDETERMINATE) {
  4574. ast_mutex_unlock(&myrpt->lock);
  4575. continue;
  4576. }
  4577. }
  4578. }
  4579. }
  4580. else /* if simple */
  4581. {
  4582. if ((!myrpt->callmode) && (c == myrpt->funcchar))
  4583. {
  4584. myrpt->callmode = 1;
  4585. myrpt->cidx = 0;
  4586. myrpt->exten[myrpt->cidx] = 0;
  4587. ast_mutex_unlock(&myrpt->lock);
  4588. pthread_attr_init(&attr);
  4589. pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED);
  4590. ast_pthread_create(&myrpt->rpt_call_thread,&attr,rpt_call,(void *)myrpt);
  4591. continue;
  4592. }
  4593. }
  4594. if (myrpt->callmode == 1)
  4595. {
  4596. myrpt->exten[myrpt->cidx++] = c;
  4597. myrpt->exten[myrpt->cidx] = 0;
  4598. /* if this exists */
  4599. if (ast_exists_extension(myrpt->pchannel,myrpt->ourcontext,myrpt->exten,1,NULL))
  4600. {
  4601. myrpt->callmode = 2;
  4602. ast_mutex_unlock(&myrpt->lock);
  4603. rpt_telemetry(myrpt,PROC,NULL);
  4604. continue;
  4605. }
  4606. /* if can continue, do so */
  4607. if (!ast_canmatch_extension(myrpt->pchannel,myrpt->ourcontext,myrpt->exten,1,NULL))
  4608. {
  4609. /* call has failed, inform user */
  4610. myrpt->callmode = 4;
  4611. }
  4612. ast_mutex_unlock(&myrpt->lock);
  4613. continue;
  4614. }
  4615. if ((myrpt->callmode == 2) || (myrpt->callmode == 3))
  4616. {
  4617. myrpt->mydtmf = c;
  4618. }
  4619. ast_mutex_unlock(&myrpt->lock);
  4620. continue;
  4621. }
  4622. else if (f->frametype == AST_FRAME_CONTROL)
  4623. {
  4624. if (f->subclass == AST_CONTROL_HANGUP)
  4625. {
  4626. if (debug) printf("@@@@ rpt:Hung Up\n");
  4627. ast_frfree(f);
  4628. break;
  4629. }
  4630. /* if RX key */
  4631. if (f->subclass == AST_CONTROL_RADIO_KEY)
  4632. {
  4633. if (debug) printf("@@@@ rx key\n");
  4634. myrpt->keyed = 1;
  4635. }
  4636. /* if RX un-key */
  4637. if (f->subclass == AST_CONTROL_RADIO_UNKEY)
  4638. {
  4639. if (debug) printf("@@@@ rx un-key\n");
  4640. if(myrpt->keyed) {
  4641. rpt_telemetry(myrpt,UNKEY,NULL);
  4642. }
  4643. myrpt->keyed = 0;
  4644. }
  4645. }
  4646. ast_frfree(f);
  4647. continue;
  4648. }
  4649. if (who == myrpt->pchannel) /* if it was a read from pseudo */
  4650. {
  4651. f = ast_read(myrpt->pchannel);
  4652. if (!f)
  4653. {
  4654. if (debug) printf("@@@@ rpt:Hung Up\n");
  4655. break;
  4656. }
  4657. if (f->frametype == AST_FRAME_VOICE)
  4658. {
  4659. ast_write(myrpt->txpchannel,f);
  4660. }
  4661. if (f->frametype == AST_FRAME_CONTROL)
  4662. {
  4663. if (f->subclass == AST_CONTROL_HANGUP)
  4664. {
  4665. if (debug) printf("@@@@ rpt:Hung Up\n");
  4666. ast_frfree(f);
  4667. break;
  4668. }
  4669. }
  4670. ast_frfree(f);
  4671. continue;
  4672. }
  4673. if (who == myrpt->txchannel) /* if it was a read from tx */
  4674. {
  4675. f = ast_read(myrpt->txchannel);
  4676. if (!f)
  4677. {
  4678. if (debug) printf("@@@@ rpt:Hung Up\n");
  4679. break;
  4680. }
  4681. if (f->frametype == AST_FRAME_CONTROL)
  4682. {
  4683. if (f->subclass == AST_CONTROL_HANGUP)
  4684. {
  4685. if (debug) printf("@@@@ rpt:Hung Up\n");
  4686. ast_frfree(f);
  4687. break;
  4688. }
  4689. }
  4690. ast_frfree(f);
  4691. continue;
  4692. }
  4693. toexit = 0;
  4694. ast_mutex_lock(&myrpt->lock);
  4695. l = myrpt->links.next;
  4696. while(l != &myrpt->links)
  4697. {
  4698. if (l->disctime)
  4699. {
  4700. l = l->next;
  4701. continue;
  4702. }
  4703. if (who == l->chan) /* if it was a read from rx */
  4704. {
  4705. remrx = 0;
  4706. /* see if any other links are receiving */
  4707. m = myrpt->links.next;
  4708. while(m != &myrpt->links)
  4709. {
  4710. /* if not us, count it */
  4711. if ((m != l) && (m->lastrx)) remrx = 1;
  4712. m = m->next;
  4713. }
  4714. ast_mutex_unlock(&myrpt->lock);
  4715. totx = (((l->isremote) ? myrpt->localtx :
  4716. myrpt->exttx) || remrx) && l->mode;
  4717. if (l->chan && (l->lasttx != totx))
  4718. {
  4719. if (totx)
  4720. {
  4721. ast_indicate(l->chan,AST_CONTROL_RADIO_KEY);
  4722. }
  4723. else
  4724. {
  4725. ast_indicate(l->chan,AST_CONTROL_RADIO_UNKEY);
  4726. }
  4727. }
  4728. l->lasttx = totx;
  4729. f = ast_read(l->chan);
  4730. if (!f)
  4731. {
  4732. #ifdef RECONNECT_KLUDGE
  4733. if ((!l->disced) && (!l->outbound))
  4734. {
  4735. if ((l->name[0] == '0') || l->isremote)
  4736. l->disctime = 1;
  4737. else
  4738. l->disctime = DISC_TIME;
  4739. ast_mutex_lock(&myrpt->lock);
  4740. ast_hangup(l->chan);
  4741. l->chan = 0;
  4742. break;
  4743. }
  4744. if (l->retrytimer)
  4745. {
  4746. ast_mutex_lock(&myrpt->lock);
  4747. break;
  4748. }
  4749. if (l->outbound && (l->retries++ < MAX_RETRIES) && (l->hasconnected))
  4750. {
  4751. ast_mutex_lock(&myrpt->lock);
  4752. ast_hangup(l->chan);
  4753. l->chan = 0;
  4754. ast_mutex_unlock(&myrpt->lock);
  4755. if (attempt_reconnect(myrpt,l) == -1)
  4756. {
  4757. l->retrytimer = RETRY_TIMER_MS;
  4758. }
  4759. ast_mutex_lock(&myrpt->lock);
  4760. break;
  4761. }
  4762. #endif
  4763. ast_mutex_lock(&myrpt->lock);
  4764. /* remove from queue */
  4765. remque((struct qelem *) l);
  4766. if (!strcmp(myrpt->cmdnode,l->name))
  4767. myrpt->cmdnode[0] = 0;
  4768. ast_mutex_unlock(&myrpt->lock);
  4769. if (!l->hasconnected)
  4770. rpt_telemetry(myrpt,CONNFAIL,l);
  4771. else if (l->disced != 2) rpt_telemetry(myrpt,REMDISC,l);
  4772. /* hang-up on call to device */
  4773. ast_hangup(l->chan);
  4774. ast_hangup(l->pchan);
  4775. free(l);
  4776. ast_mutex_lock(&myrpt->lock);
  4777. break;
  4778. }
  4779. if (f->frametype == AST_FRAME_VOICE)
  4780. {
  4781. if (l->phonemode && (!l->lastrx))
  4782. {
  4783. memset(f->data,0,f->datalen);
  4784. }
  4785. ast_write(l->pchan,f);
  4786. }
  4787. if (f->frametype == AST_FRAME_TEXT)
  4788. {
  4789. handle_link_data(myrpt,l,f->data);
  4790. }
  4791. if (f->frametype == AST_FRAME_DTMF)
  4792. {
  4793. handle_link_phone_dtmf(myrpt,l,f->subclass);
  4794. }
  4795. if (f->frametype == AST_FRAME_CONTROL)
  4796. {
  4797. if (f->subclass == AST_CONTROL_ANSWER)
  4798. {
  4799. char lconnected = l->connected;
  4800. l->connected = 1;
  4801. l->hasconnected = 1;
  4802. l->elaptime = -1;
  4803. l->retries = 0;
  4804. if (!lconnected) rpt_telemetry(myrpt,CONNECTED,l);
  4805. }
  4806. /* if RX key */
  4807. if (f->subclass == AST_CONTROL_RADIO_KEY)
  4808. {
  4809. if (debug) printf("@@@@ rx key\n");
  4810. l->lastrx = 1;
  4811. }
  4812. /* if RX un-key */
  4813. if (f->subclass == AST_CONTROL_RADIO_UNKEY)
  4814. {
  4815. if (debug) printf("@@@@ rx un-key\n");
  4816. l->lastrx = 0;
  4817. }
  4818. if (f->subclass == AST_CONTROL_HANGUP)
  4819. {
  4820. ast_frfree(f);
  4821. #ifdef RECONNECT_KLUDGE
  4822. if ((!l->outbound) && (!l->disced))
  4823. {
  4824. if ((l->name[0] == '0') || l->isremote)
  4825. l->disctime = 1;
  4826. else
  4827. l->disctime = DISC_TIME;
  4828. ast_mutex_lock(&myrpt->lock);
  4829. ast_hangup(l->chan);
  4830. l->chan = 0;
  4831. break;
  4832. }
  4833. if (l->retrytimer)
  4834. {
  4835. ast_mutex_lock(&myrpt->lock);
  4836. break;
  4837. }
  4838. if (l->outbound && (l->retries++ < MAX_RETRIES) && (l->hasconnected))
  4839. {
  4840. ast_mutex_lock(&myrpt->lock);
  4841. ast_hangup(l->chan);
  4842. l->chan = 0;
  4843. ast_mutex_unlock(&myrpt->lock);
  4844. if (attempt_reconnect(myrpt,l) == -1)
  4845. {
  4846. l->retrytimer = RETRY_TIMER_MS;
  4847. }
  4848. ast_mutex_lock(&myrpt->lock);
  4849. break;
  4850. }
  4851. #endif
  4852. ast_mutex_lock(&myrpt->lock);
  4853. /* remove from queue */
  4854. remque((struct qelem *) l);
  4855. if (!strcmp(myrpt->cmdnode,l->name))
  4856. myrpt->cmdnode[0] = 0;
  4857. ast_mutex_unlock(&myrpt->lock);
  4858. if (!l->hasconnected)
  4859. rpt_telemetry(myrpt,CONNFAIL,l);
  4860. else if (l->disced != 2) rpt_telemetry(myrpt,REMDISC,l);
  4861. /* hang-up on call to device */
  4862. ast_hangup(l->chan);
  4863. ast_hangup(l->pchan);
  4864. free(l);
  4865. ast_mutex_lock(&myrpt->lock);
  4866. break;
  4867. }
  4868. }
  4869. ast_frfree(f);
  4870. ast_mutex_lock(&myrpt->lock);
  4871. break;
  4872. }
  4873. if (who == l->pchan)
  4874. {
  4875. ast_mutex_unlock(&myrpt->lock);
  4876. f = ast_read(l->pchan);
  4877. if (!f)
  4878. {
  4879. if (debug) printf("@@@@ rpt:Hung Up\n");
  4880. toexit = 1;
  4881. ast_mutex_lock(&myrpt->lock);
  4882. break;
  4883. }
  4884. if (f->frametype == AST_FRAME_VOICE)
  4885. {
  4886. if (l->chan) ast_write(l->chan,f);
  4887. }
  4888. if (f->frametype == AST_FRAME_CONTROL)
  4889. {
  4890. if (f->subclass == AST_CONTROL_HANGUP)
  4891. {
  4892. if (debug) printf("@@@@ rpt:Hung Up\n");
  4893. ast_frfree(f);
  4894. toexit = 1;
  4895. ast_mutex_lock(&myrpt->lock);
  4896. break;
  4897. }
  4898. }
  4899. ast_frfree(f);
  4900. ast_mutex_lock(&myrpt->lock);
  4901. break;
  4902. }
  4903. l = l->next;
  4904. }
  4905. ast_mutex_unlock(&myrpt->lock);
  4906. if (toexit) break;
  4907. if (who == myrpt->txpchannel) /* if it was a read from remote tx */
  4908. {
  4909. f = ast_read(myrpt->txpchannel);
  4910. if (!f)
  4911. {
  4912. if (debug) printf("@@@@ rpt:Hung Up\n");
  4913. break;
  4914. }
  4915. if (f->frametype == AST_FRAME_CONTROL)
  4916. {
  4917. if (f->subclass == AST_CONTROL_HANGUP)
  4918. {
  4919. if (debug) printf("@@@@ rpt:Hung Up\n");
  4920. ast_frfree(f);
  4921. break;
  4922. }
  4923. }
  4924. ast_frfree(f);
  4925. continue;
  4926. }
  4927. }
  4928. usleep(100000);
  4929. ast_hangup(myrpt->pchannel);
  4930. ast_hangup(myrpt->txpchannel);
  4931. if (myrpt->txchannel != myrpt->rxchannel) ast_hangup(myrpt->txchannel);
  4932. ast_hangup(myrpt->rxchannel);
  4933. ast_mutex_lock(&myrpt->lock);
  4934. l = myrpt->links.next;
  4935. while(l != &myrpt->links)
  4936. {
  4937. struct rpt_link *ll = l;
  4938. /* remove from queue */
  4939. remque((struct qelem *) l);
  4940. /* hang-up on call to device */
  4941. if (l->chan) ast_hangup(l->chan);
  4942. ast_hangup(l->pchan);
  4943. l = l->next;
  4944. free(ll);
  4945. }
  4946. ast_mutex_unlock(&myrpt->lock);
  4947. if (debug) printf("@@@@ rpt:Hung up channel\n");
  4948. myrpt->rpt_thread = AST_PTHREADT_STOP;
  4949. pthread_exit(NULL);
  4950. return NULL;
  4951. }
  4952. static void *rpt_master(void *ignore)
  4953. {
  4954. char *this,*val;
  4955. struct ast_variable *vp;
  4956. int i,j,n,longestnode;
  4957. pthread_attr_t attr;
  4958. /* start with blank config */
  4959. memset(&rpt_vars,0,sizeof(rpt_vars));
  4960. cfg = ast_config_load("rpt.conf");
  4961. if (!cfg) {
  4962. ast_log(LOG_NOTICE, "Unable to open radio repeater configuration rpt.conf. Radio Repeater disabled.\n");
  4963. pthread_exit(NULL);
  4964. }
  4965. /* go thru all the specified repeaters */
  4966. this = NULL;
  4967. n = 0;
  4968. while((this = ast_category_browse(cfg,this)) != NULL)
  4969. {
  4970. for(i = 0 ; i < strlen(this) ; i++){
  4971. if((this[i] < '0') || (this[i] > '9'))
  4972. break;
  4973. }
  4974. if(i != strlen(this))
  4975. continue; /* Not a node defn */
  4976. ast_log(LOG_DEBUG,"Loading config for repeater %s\n",this);
  4977. ast_mutex_init(&rpt_vars[n].lock);
  4978. rpt_vars[n].tele.next = &rpt_vars[n].tele;
  4979. rpt_vars[n].tele.prev = &rpt_vars[n].tele;
  4980. rpt_vars[n].rpt_thread = AST_PTHREADT_NULL;
  4981. rpt_vars[n].name = this;
  4982. rpt_vars[n].rxchanname = ast_variable_retrieve(cfg,this,"rxchannel");
  4983. rpt_vars[n].txchanname = ast_variable_retrieve(cfg,this,"txchannel");
  4984. rpt_vars[n].ourcontext = ast_variable_retrieve(cfg,this,"context");
  4985. if (!rpt_vars[n].ourcontext) rpt_vars[n].ourcontext = this;
  4986. rpt_vars[n].ourcallerid = ast_variable_retrieve(cfg,this,"callerid");
  4987. rpt_vars[n].acctcode = ast_variable_retrieve(cfg,this,"accountcode");
  4988. rpt_vars[n].ident = ast_variable_retrieve(cfg,this,"idrecording");
  4989. val = ast_variable_retrieve(cfg,this,"hangtime");
  4990. if (val) rpt_vars[n].hangtime = atoi(val);
  4991. else rpt_vars[n].hangtime = HANGTIME;
  4992. val = ast_variable_retrieve(cfg,this,"totime");
  4993. if (val) rpt_vars[n].totime = atoi(val);
  4994. else rpt_vars[n].totime = TOTIME;
  4995. rpt_vars[n].idtime = retrieve_astcfgint( this, "idtime", 60000, 2400000, IDTIME); /* Enforce a min max */
  4996. rpt_vars[n].politeid = retrieve_astcfgint( this, "politeid", 30000, 300000, POLITEID); /* Enforce a min max */
  4997. rpt_vars[n].remote = ast_variable_retrieve(cfg,this,"remote");
  4998. rpt_vars[n].tonezone = ast_variable_retrieve(cfg,this,"tonezone");
  4999. val = ast_variable_retrieve(cfg,this,"iobase");
  5000. /* do not use atoi() here, we need to be able to have
  5001. the input specified in hex or decimal so we use
  5002. sscanf with a %i */
  5003. if ((!val) || (sscanf(val,"%i",&rpt_vars[n].iobase) != 1))
  5004. rpt_vars[n].iobase = DEFAULT_IOBASE;
  5005. rpt_vars[n].simple = 0;
  5006. rpt_vars[n].functions = ast_variable_retrieve(cfg,this,"functions");
  5007. if (!rpt_vars[n].functions)
  5008. {
  5009. rpt_vars[n].functions = FUNCTIONS;
  5010. rpt_vars[n].simple = 1;
  5011. }
  5012. rpt_vars[n].link_functions = ast_variable_retrieve(cfg,this,"link_functions");
  5013. if (!rpt_vars[n].link_functions)
  5014. rpt_vars[n].link_functions = rpt_vars[n].functions;
  5015. rpt_vars[n].phone_functions = ast_variable_retrieve(cfg,this,"phone_functions");
  5016. rpt_vars[n].dphone_functions = ast_variable_retrieve(cfg,this,"dphone_functions");
  5017. val = ast_variable_retrieve(cfg,this,"funcchar");
  5018. if (!val) rpt_vars[n].funcchar = FUNCCHAR; else
  5019. rpt_vars[n].funcchar = *val;
  5020. val = ast_variable_retrieve(cfg,this,"endchar");
  5021. if (!val) rpt_vars[n].endchar = ENDCHAR; else
  5022. rpt_vars[n].endchar = *val;
  5023. val = ast_variable_retrieve(cfg,this,"nobusyout");
  5024. if (val) rpt_vars[n].nobusyout = ast_true(val);
  5025. rpt_vars[n].nodes = ast_variable_retrieve(cfg,this,"nodes");
  5026. if (!rpt_vars[n].nodes)
  5027. rpt_vars[n].nodes = NODES;
  5028. n++;
  5029. }
  5030. nrpts = n;
  5031. ast_log(LOG_DEBUG, "Total of %d repeaters configured.\n",n);
  5032. /* start em all */
  5033. for(i = 0; i < n; i++)
  5034. {
  5035. /*
  5036. * Go through the node list to determine the longest node
  5037. */
  5038. longestnode = 0;
  5039. vp = ast_variable_browse(cfg, rpt_vars[i].nodes);
  5040. while(vp){
  5041. j = strlen(vp->name);
  5042. if (j > longestnode)
  5043. longestnode = j;
  5044. vp = vp->next;
  5045. }
  5046. rpt_vars[i].longestnode = longestnode;
  5047. /*
  5048. * For this repeater, Determine the length of the longest function
  5049. */
  5050. rpt_vars[i].longestfunc = 0;
  5051. vp = ast_variable_browse(cfg, rpt_vars[i].functions);
  5052. while(vp){
  5053. j = strlen(vp->name);
  5054. if (j > rpt_vars[i].longestfunc)
  5055. rpt_vars[i].longestfunc = j;
  5056. vp = vp->next;
  5057. }
  5058. /*
  5059. * For this repeater, Determine the length of the longest function
  5060. */
  5061. rpt_vars[i].link_longestfunc = 0;
  5062. vp = ast_variable_browse(cfg, rpt_vars[i].link_functions);
  5063. while(vp){
  5064. j = strlen(vp->name);
  5065. if (j > rpt_vars[i].link_longestfunc)
  5066. rpt_vars[i].link_longestfunc = j;
  5067. vp = vp->next;
  5068. }
  5069. rpt_vars[i].phone_longestfunc = 0;
  5070. if (rpt_vars[i].phone_functions)
  5071. {
  5072. vp = ast_variable_browse(cfg, rpt_vars[i].phone_functions);
  5073. while(vp){
  5074. j = strlen(vp->name);
  5075. if (j > rpt_vars[i].phone_longestfunc)
  5076. rpt_vars[i].phone_longestfunc = j;
  5077. vp = vp->next;
  5078. }
  5079. }
  5080. rpt_vars[i].dphone_longestfunc = 0;
  5081. if (rpt_vars[i].dphone_functions)
  5082. {
  5083. vp = ast_variable_browse(cfg, rpt_vars[i].dphone_functions);
  5084. while(vp){
  5085. j = strlen(vp->name);
  5086. if (j > rpt_vars[i].dphone_longestfunc)
  5087. rpt_vars[i].dphone_longestfunc = j;
  5088. vp = vp->next;
  5089. }
  5090. }
  5091. if (!rpt_vars[i].rxchanname)
  5092. {
  5093. ast_log(LOG_WARNING,"Did not specify rxchanname for node %s\n",rpt_vars[i].name);
  5094. ast_config_destroy(cfg);
  5095. pthread_exit(NULL);
  5096. }
  5097. /* if is a remote, dont start one for it */
  5098. if (rpt_vars[i].remote)
  5099. {
  5100. strncpy(rpt_vars[i].freq, "146.580", sizeof(rpt_vars[i].freq) - 1);
  5101. strncpy(rpt_vars[i].rxpl, "100.0", sizeof(rpt_vars[i].rxpl) - 1);
  5102. strncpy(rpt_vars[i].txpl, "100.0", sizeof(rpt_vars[i].txpl) - 1);
  5103. rpt_vars[i].remmode = REM_MODE_FM;
  5104. rpt_vars[i].offset = REM_SIMPLEX;
  5105. rpt_vars[i].powerlevel = REM_MEDPWR;
  5106. continue;
  5107. }
  5108. if (!rpt_vars[i].ident)
  5109. {
  5110. ast_log(LOG_WARNING,"Did not specify ident for node %s\n",rpt_vars[i].name);
  5111. ast_config_destroy(cfg);
  5112. pthread_exit(NULL);
  5113. }
  5114. pthread_attr_init(&attr);
  5115. pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED);
  5116. ast_pthread_create(&rpt_vars[i].rpt_thread,&attr,rpt,(void *) &rpt_vars[i]);
  5117. }
  5118. usleep(500000);
  5119. for(;;)
  5120. {
  5121. /* Now monitor each thread, and restart it if necessary */
  5122. for(i = 0; i < n; i++)
  5123. {
  5124. int rv;
  5125. if (rpt_vars[i].remote) continue;
  5126. if (rpt_vars[i].rpt_thread == AST_PTHREADT_STOP)
  5127. rv = -1;
  5128. else
  5129. rv = pthread_kill(rpt_vars[i].rpt_thread,0);
  5130. if (rv)
  5131. {
  5132. if(time(NULL) - rpt_vars[i].lastthreadrestarttime <= 15)
  5133. {
  5134. if(rpt_vars[i].threadrestarts >= 5)
  5135. {
  5136. ast_log(LOG_ERROR,"Continual RPT thread restarts, killing Asterisk\n");
  5137. exit(1); /* Stuck in a restart loop, kill Asterisk and start over */
  5138. }
  5139. else
  5140. {
  5141. ast_log(LOG_NOTICE,"RPT thread restarted on %s\n",rpt_vars[i].name);
  5142. rpt_vars[i].threadrestarts++;
  5143. }
  5144. }
  5145. else
  5146. rpt_vars[i].threadrestarts = 0;
  5147. rpt_vars[i].lastthreadrestarttime = time(NULL);
  5148. pthread_attr_init(&attr);
  5149. pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED);
  5150. ast_pthread_create(&rpt_vars[i].rpt_thread,&attr,rpt,(void *) &rpt_vars[i]);
  5151. ast_log(LOG_WARNING, "rpt_thread restarted on node %s\n", rpt_vars[i].name);
  5152. }
  5153. }
  5154. usleep(2000000);
  5155. }
  5156. ast_config_destroy(cfg);
  5157. pthread_exit(NULL);
  5158. }
  5159. static int rpt_exec(struct ast_channel *chan, void *data)
  5160. {
  5161. int res=-1,i,rem_totx,n,phone_mode = 0;
  5162. struct localuser *u;
  5163. char tmp[256], keyed = 0;
  5164. char *options,*stringp,*tele;
  5165. struct rpt *myrpt;
  5166. struct ast_frame *f;
  5167. struct ast_channel *who;
  5168. struct ast_channel *cs[20];
  5169. struct rpt_link *l;
  5170. ZT_CONFINFO ci; /* conference info */
  5171. ZT_PARAMS par;
  5172. int ms,elap;
  5173. if (ast_strlen_zero(data)) {
  5174. ast_log(LOG_WARNING, "Rpt requires an argument (system node)\n");
  5175. return -1;
  5176. }
  5177. strncpy(tmp, (char *)data, sizeof(tmp)-1);
  5178. stringp=tmp;
  5179. strsep(&stringp, "|");
  5180. options = stringp;
  5181. myrpt = NULL;
  5182. /* see if we can find our specified one */
  5183. for(i = 0; i < nrpts; i++)
  5184. {
  5185. /* if name matches, assign it and exit loop */
  5186. if (!strcmp(tmp,rpt_vars[i].name))
  5187. {
  5188. myrpt = &rpt_vars[i];
  5189. break;
  5190. }
  5191. }
  5192. if (myrpt == NULL)
  5193. {
  5194. ast_log(LOG_WARNING, "Cannot find specified system node %s\n",tmp);
  5195. return -1;
  5196. }
  5197. /* if not phone access, must be an IAX connection */
  5198. if (options && ((*options == 'P') || (*options == 'D') || (*options == 'R')))
  5199. {
  5200. phone_mode = 1;
  5201. if (*options == 'D') phone_mode = 2;
  5202. ast_set_callerid(chan,"0","app_rpt user","0");
  5203. }
  5204. else
  5205. {
  5206. if (strncmp(chan->name,"IAX2",4))
  5207. {
  5208. ast_log(LOG_WARNING, "We only accept links via IAX2!!\n");
  5209. return -1;
  5210. }
  5211. }
  5212. if (options && (*options == 'R'))
  5213. {
  5214. /* Parts of this section taken from app_parkandannounce */
  5215. char *return_context;
  5216. int l, m, lot, timeout = 0;
  5217. char tmp[256],*template;
  5218. char *working, *context, *exten, *priority;
  5219. char *s,*orig_s;
  5220. ast_mutex_lock(&myrpt->lock);
  5221. m = myrpt->callmode;
  5222. ast_mutex_unlock(&myrpt->lock);
  5223. if ((!myrpt->nobusyout) && m)
  5224. {
  5225. if (chan->_state != AST_STATE_UP)
  5226. {
  5227. ast_indicate(chan,AST_CONTROL_BUSY);
  5228. }
  5229. while(ast_safe_sleep(chan,10000) != -1);
  5230. return -1;
  5231. }
  5232. if (chan->_state != AST_STATE_UP)
  5233. {
  5234. ast_answer(chan);
  5235. }
  5236. l=strlen(options)+2;
  5237. orig_s=malloc(l);
  5238. if(!orig_s) {
  5239. ast_log(LOG_WARNING, "Out of memory\n");
  5240. return -1;
  5241. }
  5242. s=orig_s;
  5243. strncpy(s,options,l);
  5244. template=strsep(&s,"|");
  5245. if(!template) {
  5246. ast_log(LOG_WARNING, "An announce template must be defined\n");
  5247. free(orig_s);
  5248. return -1;
  5249. }
  5250. if(s) {
  5251. timeout = atoi(strsep(&s, "|"));
  5252. timeout *= 1000;
  5253. }
  5254. return_context = s;
  5255. if(return_context != NULL) {
  5256. /* set the return context. Code borrowed from the Goto builtin */
  5257. working = return_context;
  5258. context = strsep(&working, "|");
  5259. exten = strsep(&working, "|");
  5260. if(!exten) {
  5261. /* Only a priority in this one */
  5262. priority = context;
  5263. exten = NULL;
  5264. context = NULL;
  5265. } else {
  5266. priority = strsep(&working, "|");
  5267. if(!priority) {
  5268. /* Only an extension and priority in this one */
  5269. priority = exten;
  5270. exten = context;
  5271. context = NULL;
  5272. }
  5273. }
  5274. if(atoi(priority) < 0) {
  5275. ast_log(LOG_WARNING, "Priority '%s' must be a number > 0\n", priority);
  5276. free(orig_s);
  5277. return -1;
  5278. }
  5279. /* At this point we have a priority and maybe an extension and a context */
  5280. chan->priority = atoi(priority);
  5281. if(exten && strcasecmp(exten, "BYEXTENSION"))
  5282. strncpy(chan->exten, exten, sizeof(chan->exten)-1);
  5283. if(context)
  5284. strncpy(chan->context, context, sizeof(chan->context)-1);
  5285. } else { /* increment the priority by default*/
  5286. chan->priority++;
  5287. }
  5288. if(option_verbose > 2) {
  5289. ast_verbose( VERBOSE_PREFIX_3 "Return Context: (%s,%s,%d) ID: %s\n", chan->context,chan->exten, chan->priority, chan->cid.cid_num);
  5290. if(!ast_exists_extension(chan, chan->context, chan->exten, chan->priority, chan->cid.cid_num)) {
  5291. ast_verbose( VERBOSE_PREFIX_3 "Warning: Return Context Invalid, call will return to default|s\n");
  5292. }
  5293. }
  5294. /* we are using masq_park here to protect * from touching the channel once we park it. If the channel comes out of timeout
  5295. before we are done announcing and the channel is messed with, Kablooeee. So we use Masq to prevent this. */
  5296. ast_masq_park_call(chan, NULL, timeout, &lot);
  5297. if (option_verbose > 2) ast_verbose( VERBOSE_PREFIX_3 "Call Parking Called, lot: %d, timeout: %d, context: %s\n", lot, timeout, return_context);
  5298. snprintf(tmp,sizeof(tmp) - 1,"%d,%s",lot,template + 1);
  5299. rpt_telemetry(myrpt,REV_PATCH,tmp);
  5300. free(orig_s);
  5301. return 0;
  5302. }
  5303. if (!options)
  5304. {
  5305. struct ast_hostent ahp;
  5306. struct hostent *hp;
  5307. struct in_addr ia;
  5308. char hisip[100],nodeip[100],*val, *s, *s1, *s2, *b,*b1;
  5309. /* look at callerid to see what node this comes from */
  5310. if (!chan->cid.cid_num) /* if doesn't have caller id */
  5311. {
  5312. ast_log(LOG_WARNING, "Doesnt have callerid on %s\n",tmp);
  5313. return -1;
  5314. }
  5315. /* get his IP from IAX2 module */
  5316. memset(hisip,0,sizeof(hisip));
  5317. pbx_substitute_variables_helper(chan,"${IAXPEER(CURRENTCHANNEL)}",hisip,sizeof(hisip) - 1);
  5318. if (!hisip[0])
  5319. {
  5320. ast_log(LOG_WARNING, "Link IP address cannot be determined!!\n");
  5321. return -1;
  5322. }
  5323. ast_callerid_parse(chan->cid.cid_num,&b,&b1);
  5324. ast_shrink_phone_number(b1);
  5325. if (!strcmp(myrpt->name,b1))
  5326. {
  5327. ast_log(LOG_WARNING, "Trying to link to self!!\n");
  5328. return -1;
  5329. }
  5330. if (*b1 < '1')
  5331. {
  5332. ast_log(LOG_WARNING, "Node %s Invalid for connection here!!\n",b1);
  5333. return -1;
  5334. }
  5335. /* look for his reported node string */
  5336. val = ast_variable_retrieve(cfg, myrpt->nodes, b1);
  5337. if (!val)
  5338. {
  5339. ast_log(LOG_WARNING, "Reported node %s cannot be found!!\n",b1);
  5340. return -1;
  5341. }
  5342. strncpy(tmp,val,sizeof(tmp) - 1);
  5343. s = tmp;
  5344. s1 = strsep(&s,",");
  5345. s2 = strsep(&s,",");
  5346. if (!s2)
  5347. {
  5348. ast_log(LOG_WARNING, "Reported node %s not in correct format!!\n",b1);
  5349. return -1;
  5350. }
  5351. if (strcmp(s2,"NONE")) {
  5352. hp = ast_gethostbyname(s2, &ahp);
  5353. if (!hp)
  5354. {
  5355. ast_log(LOG_WARNING, "Reported node %s, name %s cannot be found!!\n",b1,s2);
  5356. return -1;
  5357. }
  5358. memcpy(&ia,hp->h_addr,sizeof(in_addr_t));
  5359. ast_inet_ntoa(nodeip,sizeof(nodeip) - 1,ia);
  5360. if (strcmp(hisip,nodeip))
  5361. {
  5362. char *s3 = strchr(s1,'@');
  5363. if (s3) s1 = s3 + 1;
  5364. s3 = strchr(s1,'/');
  5365. if (s3) *s3 = 0;
  5366. hp = ast_gethostbyname(s1, &ahp);
  5367. if (!hp)
  5368. {
  5369. ast_log(LOG_WARNING, "Reported node %s, name %s cannot be found!!\n",b1,s1);
  5370. return -1;
  5371. }
  5372. memcpy(&ia,hp->h_addr,sizeof(in_addr_t));
  5373. ast_inet_ntoa(nodeip,sizeof(nodeip) - 1,ia);
  5374. if (strcmp(hisip,nodeip))
  5375. {
  5376. ast_log(LOG_WARNING, "Node %s IP %s does not match link IP %s!!\n",b1,nodeip,hisip);
  5377. return -1;
  5378. }
  5379. }
  5380. }
  5381. }
  5382. /* if is not a remote */
  5383. if (!myrpt->remote)
  5384. {
  5385. char *b,*b1;
  5386. /* look at callerid to see what node this comes from */
  5387. if (!chan->cid.cid_num) /* if doesn't have caller id */
  5388. {
  5389. ast_log(LOG_WARNING, "Doesnt have callerid on %s\n",tmp);
  5390. return -1;
  5391. }
  5392. ast_callerid_parse(chan->cid.cid_num,&b,&b1);
  5393. ast_shrink_phone_number(b1);
  5394. if (!strcmp(myrpt->name,b1))
  5395. {
  5396. ast_log(LOG_WARNING, "Trying to link to self!!\n");
  5397. return -1;
  5398. }
  5399. ast_mutex_lock(&myrpt->lock);
  5400. l = myrpt->links.next;
  5401. /* try to find this one in queue */
  5402. while(l != &myrpt->links)
  5403. {
  5404. if (l->name[0] == '0')
  5405. {
  5406. l = l->next;
  5407. continue;
  5408. }
  5409. /* if found matching string */
  5410. if (!strcmp(l->name,b1)) break;
  5411. l = l->next;
  5412. }
  5413. /* if found */
  5414. if (l != &myrpt->links)
  5415. {
  5416. l->killme = 1;
  5417. l->retries = MAX_RETRIES + 1;
  5418. l->disced = 2;
  5419. ast_mutex_unlock(&myrpt->lock);
  5420. usleep(500000);
  5421. } else
  5422. ast_mutex_unlock(&myrpt->lock);
  5423. /* establish call in tranceive mode */
  5424. l = malloc(sizeof(struct rpt_link));
  5425. if (!l)
  5426. {
  5427. ast_log(LOG_WARNING, "Unable to malloc\n");
  5428. pthread_exit(NULL);
  5429. }
  5430. /* zero the silly thing */
  5431. memset((char *)l,0,sizeof(struct rpt_link));
  5432. l->mode = 1;
  5433. strncpy(l->name,b1,MAXNODESTR - 1);
  5434. l->isremote = 0;
  5435. l->chan = chan;
  5436. l->connected = 1;
  5437. l->hasconnected = 1;
  5438. l->phonemode = phone_mode;
  5439. ast_set_read_format(l->chan,AST_FORMAT_SLINEAR);
  5440. ast_set_write_format(l->chan,AST_FORMAT_SLINEAR);
  5441. /* allocate a pseudo-channel thru asterisk */
  5442. l->pchan = ast_request("zap",AST_FORMAT_SLINEAR,"pseudo",NULL);
  5443. if (!l->pchan)
  5444. {
  5445. fprintf(stderr,"rpt:Sorry unable to obtain pseudo channel\n");
  5446. pthread_exit(NULL);
  5447. }
  5448. ast_set_read_format(l->pchan,AST_FORMAT_SLINEAR);
  5449. ast_set_write_format(l->pchan,AST_FORMAT_SLINEAR);
  5450. /* make a conference for the tx */
  5451. ci.chan = 0;
  5452. ci.confno = myrpt->conf;
  5453. ci.confmode = ZT_CONF_CONF | ZT_CONF_LISTENER | ZT_CONF_TALKER;
  5454. /* first put the channel on the conference in proper mode */
  5455. if (ioctl(l->pchan->fds[0],ZT_SETCONF,&ci) == -1)
  5456. {
  5457. ast_log(LOG_WARNING, "Unable to set conference mode to Announce\n");
  5458. pthread_exit(NULL);
  5459. }
  5460. ast_mutex_lock(&myrpt->lock);
  5461. if (phone_mode > 1) l->lastrx = 1;
  5462. /* insert at end of queue */
  5463. insque((struct qelem *)l,(struct qelem *)myrpt->links.next);
  5464. ast_mutex_unlock(&myrpt->lock);
  5465. if (chan->_state != AST_STATE_UP) {
  5466. ast_answer(chan);
  5467. }
  5468. return AST_PBX_KEEPALIVE;
  5469. }
  5470. ast_mutex_lock(&myrpt->lock);
  5471. /* if remote, error if anyone else already linked */
  5472. if (myrpt->remoteon)
  5473. {
  5474. ast_mutex_unlock(&myrpt->lock);
  5475. usleep(500000);
  5476. if (myrpt->remoteon)
  5477. {
  5478. ast_log(LOG_WARNING, "Trying to use busy link on %s\n",tmp);
  5479. return -1;
  5480. }
  5481. ast_mutex_lock(&myrpt->lock);
  5482. }
  5483. myrpt->remoteon = 1;
  5484. if (ioperm(myrpt->iobase,1,1) == -1)
  5485. {
  5486. ast_mutex_unlock(&myrpt->lock);
  5487. ast_log(LOG_WARNING, "Cant get io permission on IO port %x hex\n",myrpt->iobase);
  5488. return -1;
  5489. }
  5490. LOCAL_USER_ADD(u);
  5491. tele = strchr(myrpt->rxchanname,'/');
  5492. if (!tele)
  5493. {
  5494. fprintf(stderr,"rpt:Dial number must be in format tech/number\n");
  5495. ast_mutex_unlock(&myrpt->lock);
  5496. pthread_exit(NULL);
  5497. }
  5498. *tele++ = 0;
  5499. myrpt->rxchannel = ast_request(myrpt->rxchanname,AST_FORMAT_SLINEAR,tele,NULL);
  5500. if (myrpt->rxchannel)
  5501. {
  5502. ast_set_read_format(myrpt->rxchannel,AST_FORMAT_SLINEAR);
  5503. ast_set_write_format(myrpt->rxchannel,AST_FORMAT_SLINEAR);
  5504. myrpt->rxchannel->whentohangup = 0;
  5505. myrpt->rxchannel->appl = "Apprpt";
  5506. myrpt->rxchannel->data = "(Link Rx)";
  5507. if (option_verbose > 2)
  5508. ast_verbose(VERBOSE_PREFIX_3 "rpt (Rx) initiating call to %s/%s on %s\n",
  5509. myrpt->rxchanname,tele,myrpt->rxchannel->name);
  5510. ast_mutex_unlock(&myrpt->lock);
  5511. ast_call(myrpt->rxchannel,tele,999);
  5512. ast_mutex_lock(&myrpt->lock);
  5513. }
  5514. else
  5515. {
  5516. fprintf(stderr,"rpt:Sorry unable to obtain Rx channel\n");
  5517. ast_mutex_unlock(&myrpt->lock);
  5518. pthread_exit(NULL);
  5519. }
  5520. *--tele = '/';
  5521. if (myrpt->txchanname)
  5522. {
  5523. tele = strchr(myrpt->txchanname,'/');
  5524. if (!tele)
  5525. {
  5526. fprintf(stderr,"rpt:Dial number must be in format tech/number\n");
  5527. ast_mutex_unlock(&myrpt->lock);
  5528. ast_hangup(myrpt->rxchannel);
  5529. pthread_exit(NULL);
  5530. }
  5531. *tele++ = 0;
  5532. myrpt->txchannel = ast_request(myrpt->txchanname,AST_FORMAT_SLINEAR,tele,NULL);
  5533. if (myrpt->txchannel)
  5534. {
  5535. ast_set_read_format(myrpt->txchannel,AST_FORMAT_SLINEAR);
  5536. ast_set_write_format(myrpt->txchannel,AST_FORMAT_SLINEAR);
  5537. myrpt->txchannel->whentohangup = 0;
  5538. myrpt->txchannel->appl = "Apprpt";
  5539. myrpt->txchannel->data = "(Link Tx)";
  5540. if (option_verbose > 2)
  5541. ast_verbose(VERBOSE_PREFIX_3 "rpt (Tx) initiating call to %s/%s on %s\n",
  5542. myrpt->txchanname,tele,myrpt->txchannel->name);
  5543. ast_mutex_unlock(&myrpt->lock);
  5544. ast_call(myrpt->txchannel,tele,999);
  5545. ast_mutex_lock(&myrpt->lock);
  5546. }
  5547. else
  5548. {
  5549. fprintf(stderr,"rpt:Sorry unable to obtain Tx channel\n");
  5550. ast_mutex_unlock(&myrpt->lock);
  5551. ast_hangup(myrpt->rxchannel);
  5552. pthread_exit(NULL);
  5553. }
  5554. *--tele = '/';
  5555. }
  5556. else
  5557. {
  5558. myrpt->txchannel = myrpt->rxchannel;
  5559. }
  5560. myrpt->remoterx = 0;
  5561. myrpt->remotetx = 0;
  5562. myrpt->retxtimer = 0;
  5563. myrpt->remoteon = 1;
  5564. myrpt->dtmfidx = -1;
  5565. myrpt->dtmfbuf[0] = 0;
  5566. myrpt->dtmf_time_rem = 0;
  5567. myrpt->hfscanmode = 0;
  5568. myrpt->hfscanstatus = 0;
  5569. ast_mutex_unlock(&myrpt->lock);
  5570. setrem(myrpt);
  5571. ast_set_write_format(chan, AST_FORMAT_SLINEAR);
  5572. ast_set_read_format(chan, AST_FORMAT_SLINEAR);
  5573. /* if we are on 2w loop and are a remote, turn EC on */
  5574. if (myrpt->remote && (myrpt->rxchannel == myrpt->txchannel))
  5575. {
  5576. i = 128;
  5577. ioctl(myrpt->rxchannel->fds[0],ZT_ECHOCANCEL,&i);
  5578. }
  5579. if (chan->_state != AST_STATE_UP) {
  5580. ast_answer(chan);
  5581. }
  5582. if (ioctl(myrpt->txchannel->fds[0],ZT_GET_PARAMS,&par) != -1)
  5583. {
  5584. if (par.rxisoffhook)
  5585. {
  5586. ast_indicate(chan,AST_CONTROL_RADIO_KEY);
  5587. myrpt->remoterx = 1;
  5588. }
  5589. }
  5590. n = 0;
  5591. cs[n++] = chan;
  5592. cs[n++] = myrpt->rxchannel;
  5593. if (myrpt->rxchannel != myrpt->txchannel)
  5594. cs[n++] = myrpt->txchannel;
  5595. for(;;)
  5596. {
  5597. if (ast_check_hangup(chan)) break;
  5598. if (ast_check_hangup(myrpt->rxchannel)) break;
  5599. ms = MSWAIT;
  5600. who = ast_waitfor_n(cs,n,&ms);
  5601. if (who == NULL) ms = 0;
  5602. elap = MSWAIT - ms;
  5603. if (!ms) continue;
  5604. rem_totx = keyed;
  5605. if ((!myrpt->remoterx) && (!myrpt->remotetx))
  5606. {
  5607. if ((myrpt->retxtimer += elap) >= REDUNDANT_TX_TIME)
  5608. {
  5609. myrpt->retxtimer = 0;
  5610. ast_indicate(chan,AST_CONTROL_RADIO_UNKEY);
  5611. }
  5612. } else myrpt->retxtimer = 0;
  5613. if (rem_totx && (!myrpt->remotetx)) /* Remote base radio TX key */
  5614. {
  5615. myrpt->remotetx = 1;
  5616. ast_indicate(myrpt->txchannel,AST_CONTROL_RADIO_KEY);
  5617. }
  5618. if ((!rem_totx) && myrpt->remotetx) /* Remote base radio TX unkey */
  5619. {
  5620. myrpt->remotetx = 0;
  5621. ast_indicate(myrpt->txchannel,AST_CONTROL_RADIO_UNKEY);
  5622. }
  5623. if(myrpt->tunerequest && (!strcmp(myrpt->remote, remote_rig_ft897))){ /* ft-897 specific for now... */
  5624. myrpt->tunerequest = 0;
  5625. set_mode_ft897(myrpt, REM_MODE_AM);
  5626. simple_command_ft897(myrpt, 8);
  5627. myrpt->remotetx = 0;
  5628. ast_indicate(myrpt->txchannel,AST_CONTROL_RADIO_UNKEY);
  5629. if (!myrpt->remoterx)
  5630. ast_indicate(chan, AST_CONTROL_RADIO_KEY);
  5631. if(play_tone(chan, 800, 6000, 8192) == -1)
  5632. break;
  5633. rmt_telem_finish(myrpt,chan);
  5634. set_mode_ft897(myrpt, 0x88);
  5635. setrem(myrpt);
  5636. }
  5637. if (myrpt->hfscanmode){
  5638. myrpt->scantimer -= elap;
  5639. if(myrpt->scantimer <= 0){
  5640. myrpt->scantimer = REM_SCANTIME;
  5641. service_scan(myrpt);
  5642. }
  5643. }
  5644. if (who == chan) /* if it was a read from incomming */
  5645. {
  5646. f = ast_read(chan);
  5647. if (!f)
  5648. {
  5649. if (debug) printf("@@@@ link:Hung Up\n");
  5650. break;
  5651. }
  5652. if (f->frametype == AST_FRAME_VOICE)
  5653. {
  5654. /* if not transmitting, zero-out audio */
  5655. if (!myrpt->remotetx)
  5656. memset(f->data,0,f->datalen);
  5657. ast_write(myrpt->txchannel,f);
  5658. }
  5659. if (f->frametype == AST_FRAME_DTMF)
  5660. {
  5661. myrpt->remchannel = chan; /* Save copy of channel */
  5662. if (handle_remote_phone_dtmf(myrpt,f->subclass,&keyed,phone_mode) == -1)
  5663. {
  5664. if (debug) printf("@@@@ rpt:Hung Up\n");
  5665. ast_frfree(f);
  5666. break;
  5667. }
  5668. }
  5669. if (f->frametype == AST_FRAME_TEXT)
  5670. {
  5671. myrpt->remchannel = chan; /* Save copy of channel */
  5672. if (handle_remote_data(myrpt,f->data) == -1)
  5673. {
  5674. if (debug) printf("@@@@ rpt:Hung Up\n");
  5675. ast_frfree(f);
  5676. break;
  5677. }
  5678. }
  5679. if (f->frametype == AST_FRAME_CONTROL)
  5680. {
  5681. if (f->subclass == AST_CONTROL_HANGUP)
  5682. {
  5683. if (debug) printf("@@@@ rpt:Hung Up\n");
  5684. ast_frfree(f);
  5685. break;
  5686. }
  5687. /* if RX key */
  5688. if (f->subclass == AST_CONTROL_RADIO_KEY)
  5689. {
  5690. if (debug) printf("@@@@ rx key\n");
  5691. keyed = 1;
  5692. }
  5693. /* if RX un-key */
  5694. if (f->subclass == AST_CONTROL_RADIO_UNKEY)
  5695. {
  5696. if (debug) printf("@@@@ rx un-key\n");
  5697. keyed = 0;
  5698. }
  5699. }
  5700. if (myrpt->hfscanstatus){
  5701. myrpt->remchannel = chan; /* Save copy of channel */
  5702. myrpt->remotetx = 0;
  5703. ast_indicate(myrpt->txchannel,AST_CONTROL_RADIO_UNKEY);
  5704. if (!myrpt->remoterx)
  5705. {
  5706. ast_indicate(myrpt->remchannel,AST_CONTROL_RADIO_KEY);
  5707. }
  5708. if(myrpt->hfscanstatus < 0) {
  5709. if (myrpt->hfscanstatus == -1) {
  5710. if (ast_safe_sleep(myrpt->remchannel,1000) == -1) break;
  5711. }
  5712. sayfile(myrpt->remchannel, "rpt/stop");
  5713. }
  5714. else
  5715. {
  5716. saynum(myrpt->remchannel, myrpt->hfscanstatus );
  5717. }
  5718. rmt_telem_finish(myrpt,myrpt->remchannel);
  5719. myrpt->hfscanstatus = 0;
  5720. }
  5721. ast_frfree(f);
  5722. continue;
  5723. }
  5724. if (who == myrpt->rxchannel) /* if it was a read from radio */
  5725. {
  5726. f = ast_read(myrpt->rxchannel);
  5727. if (!f)
  5728. {
  5729. if (debug) printf("@@@@ link:Hung Up\n");
  5730. break;
  5731. }
  5732. if (f->frametype == AST_FRAME_VOICE)
  5733. {
  5734. if ((myrpt->remote) && (myrpt->remotetx))
  5735. memset(f->data,0,f->datalen);
  5736. ast_write(chan,f);
  5737. }
  5738. else if (f->frametype == AST_FRAME_CONTROL)
  5739. {
  5740. if (f->subclass == AST_CONTROL_HANGUP)
  5741. {
  5742. if (debug) printf("@@@@ rpt:Hung Up\n");
  5743. ast_frfree(f);
  5744. break;
  5745. }
  5746. /* if RX key */
  5747. if (f->subclass == AST_CONTROL_RADIO_KEY)
  5748. {
  5749. if (debug) printf("@@@@ remote rx key\n");
  5750. if (!myrpt->remotetx)
  5751. {
  5752. ast_indicate(chan,AST_CONTROL_RADIO_KEY);
  5753. myrpt->remoterx = 1;
  5754. }
  5755. }
  5756. /* if RX un-key */
  5757. if (f->subclass == AST_CONTROL_RADIO_UNKEY)
  5758. {
  5759. if (debug) printf("@@@@ remote rx un-key\n");
  5760. if (!myrpt->remotetx)
  5761. {
  5762. ast_indicate(chan,AST_CONTROL_RADIO_UNKEY);
  5763. myrpt->remoterx = 0;
  5764. }
  5765. }
  5766. }
  5767. ast_frfree(f);
  5768. continue;
  5769. }
  5770. if ((myrpt->rxchannel != myrpt->txchannel) &&
  5771. (who == myrpt->txchannel)) /* do this cuz you have to */
  5772. {
  5773. f = ast_read(myrpt->txchannel);
  5774. if (!f)
  5775. {
  5776. if (debug) printf("@@@@ link:Hung Up\n");
  5777. break;
  5778. }
  5779. if (f->frametype == AST_FRAME_CONTROL)
  5780. {
  5781. if (f->subclass == AST_CONTROL_HANGUP)
  5782. {
  5783. if (debug) printf("@@@@ rpt:Hung Up\n");
  5784. ast_frfree(f);
  5785. break;
  5786. }
  5787. }
  5788. ast_frfree(f);
  5789. continue;
  5790. }
  5791. }
  5792. ast_mutex_lock(&myrpt->lock);
  5793. if (myrpt->rxchannel != myrpt->txchannel) ast_hangup(myrpt->txchannel);
  5794. ast_hangup(myrpt->rxchannel);
  5795. myrpt->hfscanmode = 0;
  5796. myrpt->hfscanstatus = 0;
  5797. myrpt->remoteon = 0;
  5798. ast_mutex_unlock(&myrpt->lock);
  5799. closerem(myrpt);
  5800. LOCAL_USER_REMOVE(u);
  5801. return res;
  5802. }
  5803. int unload_module(void)
  5804. {
  5805. int i;
  5806. STANDARD_HANGUP_LOCALUSERS;
  5807. for(i = 0; i < nrpts; i++) {
  5808. if (!strcmp(rpt_vars[i].name,rpt_vars[i].nodes)) continue;
  5809. ast_mutex_destroy(&rpt_vars[i].lock);
  5810. }
  5811. i = ast_unregister_application(app);
  5812. /* Unregister cli extensions */
  5813. ast_cli_unregister(&cli_debug);
  5814. return i;
  5815. }
  5816. int load_module(void)
  5817. {
  5818. ast_pthread_create(&rpt_master_thread,NULL,rpt_master,NULL);
  5819. /* Register cli extensions */
  5820. ast_cli_register(&cli_debug);
  5821. return ast_register_application(app, rpt_exec, synopsis, descrip);
  5822. }
  5823. char *description(void)
  5824. {
  5825. return tdesc;
  5826. }
  5827. int usecount(void)
  5828. {
  5829. int res;
  5830. STANDARD_USECOUNT(res);
  5831. return res;
  5832. }
  5833. char *key()
  5834. {
  5835. return ASTERISK_GPL_KEY;
  5836. }