chan_ooh323.c 122 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466
  1. /*
  2. * Copyright (C) 2004-2005 by Objective Systems, Inc.
  3. *
  4. * This software is furnished under an open source license and may be
  5. * used and copied only in accordance with the terms of this license.
  6. * The text of the license may generally be found in the root
  7. * directory of this installation in the COPYING file. It
  8. * can also be viewed online at the following URL:
  9. *
  10. * http://www.obj-sys.com/open/license.html
  11. *
  12. * Any redistributions of this file including modified versions must
  13. * maintain this copyright notice.
  14. *
  15. *****************************************************************************/
  16. /* Reworked version I, Nov-2009, by Alexandr Anikin, may@telecom-service.ru */
  17. /*** MODULEINFO
  18. <defaultenabled>no</defaultenabled>
  19. <support_level>extended</support_level>
  20. ***/
  21. #include "chan_ooh323.h"
  22. #include <math.h>
  23. #define FORMAT_STRING_SIZE 512
  24. /* Defaults */
  25. #define DEFAULT_CONTEXT "default"
  26. #define DEFAULT_H323ID "Asterisk PBX"
  27. #define DEFAULT_LOGFILE "/var/log/asterisk/h323_log"
  28. #define DEFAULT_H323ACCNT "ast_h323"
  29. /* Flags */
  30. #define H323_SILENCESUPPRESSION (1<<0)
  31. #define H323_GKROUTED (1<<1)
  32. #define H323_TUNNELING (1<<2)
  33. #define H323_FASTSTART (1<<3)
  34. #define H323_OUTGOING (1<<4)
  35. #define H323_ALREADYGONE (1<<5)
  36. #define H323_NEEDDESTROY (1<<6)
  37. #define H323_DISABLEGK (1<<7)
  38. #define H323_NEEDSTART (1<<8)
  39. #define MAXT30 240
  40. #define T38TOAUDIOTIMEOUT 30
  41. #define T38_DISABLED 0
  42. #define T38_ENABLED 1
  43. #define T38_FAXGW 1
  44. /* Channel description */
  45. static const char type[] = "OOH323";
  46. static const char tdesc[] = "Objective Systems H323 Channel Driver";
  47. static const char config[] = "ooh323.conf";
  48. struct ast_module *myself;
  49. static struct ast_jb_conf default_jbconf =
  50. {
  51. .flags = 0,
  52. .max_size = -1,
  53. .resync_threshold = -1,
  54. .impl = ""
  55. };
  56. static struct ast_jb_conf global_jbconf;
  57. /* Channel Definition */
  58. static struct ast_channel *ooh323_request(const char *type, format_t format,
  59. const struct ast_channel *requestor, void *data, int *cause);
  60. static int ooh323_digit_begin(struct ast_channel *ast, char digit);
  61. static int ooh323_digit_end(struct ast_channel *ast, char digit, unsigned int duration);
  62. static int ooh323_call(struct ast_channel *ast, char *dest, int timeout);
  63. static int ooh323_hangup(struct ast_channel *ast);
  64. static int ooh323_answer(struct ast_channel *ast);
  65. static struct ast_frame *ooh323_read(struct ast_channel *ast);
  66. static int ooh323_write(struct ast_channel *ast, struct ast_frame *f);
  67. static int ooh323_indicate(struct ast_channel *ast, int condition, const void *data, size_t datalen);
  68. static int ooh323_queryoption(struct ast_channel *ast, int option, void *data, int *datalen);
  69. static int ooh323_fixup(struct ast_channel *oldchan, struct ast_channel *newchan);
  70. static enum ast_rtp_glue_result ooh323_get_rtp_peer(struct ast_channel *chan, struct ast_rtp_instance **rtp);
  71. static enum ast_rtp_glue_result ooh323_get_vrtp_peer(struct ast_channel *chan, struct ast_rtp_instance **rtp);
  72. static int ooh323_set_rtp_peer(struct ast_channel *chan, struct ast_rtp_instance *rtp,
  73. struct ast_rtp_instance *vrtp, struct ast_rtp_instance *trtp, format_t codecs, int nat_active);
  74. static struct ast_udptl *ooh323_get_udptl_peer(struct ast_channel *chan);
  75. static int ooh323_set_udptl_peer(struct ast_channel *chan, struct ast_udptl *udptl);
  76. static void print_codec_to_cli(int fd, struct ast_codec_pref *pref);
  77. struct ooh323_peer *find_friend(const char *name, int port);
  78. static const struct ast_channel_tech ooh323_tech = {
  79. .type = type,
  80. .description = tdesc,
  81. .capabilities = -1,
  82. .properties = AST_CHAN_TP_WANTSJITTER | AST_CHAN_TP_CREATESJITTER,
  83. .requester = ooh323_request,
  84. .send_digit_begin = ooh323_digit_begin,
  85. .send_digit_end = ooh323_digit_end,
  86. .call = ooh323_call,
  87. .hangup = ooh323_hangup,
  88. .answer = ooh323_answer,
  89. .read = ooh323_read,
  90. .write = ooh323_write,
  91. .exception = ooh323_read,
  92. .indicate = ooh323_indicate,
  93. .fixup = ooh323_fixup,
  94. .send_html = 0,
  95. .queryoption = ooh323_queryoption,
  96. .bridge = ast_rtp_instance_bridge, /* XXX chan unlocked ? */
  97. .early_bridge = ast_rtp_instance_early_bridge,
  98. };
  99. static struct ast_rtp_glue ooh323_rtp = {
  100. .type = type,
  101. .get_rtp_info = ooh323_get_rtp_peer,
  102. .get_vrtp_info = ooh323_get_vrtp_peer,
  103. .update_peer = ooh323_set_rtp_peer,
  104. };
  105. static struct ast_udptl_protocol ooh323_udptl = {
  106. type: "H323",
  107. get_udptl_info: ooh323_get_udptl_peer,
  108. set_udptl_peer: ooh323_set_udptl_peer,
  109. };
  110. struct ooh323_user;
  111. /* H.323 channel private structure */
  112. static struct ooh323_pvt {
  113. ast_mutex_t lock; /* Channel private lock */
  114. struct ast_rtp_instance *rtp;
  115. struct ast_rtp_instance *vrtp; /* Placeholder for now */
  116. int t38support; /* T.38 mode - disable, transparent, faxgw */
  117. int rtptimeout;
  118. struct ast_udptl *udptl;
  119. int faxmode;
  120. int t38_tx_enable;
  121. int t38_init;
  122. struct sockaddr_in udptlredirip;
  123. time_t lastTxT38;
  124. int chmodepend;
  125. struct ast_channel *owner; /* Master Channel */
  126. union {
  127. char *user; /* cooperating user/peer */
  128. char *peer;
  129. } neighbor;
  130. time_t lastrtptx;
  131. time_t lastrtprx;
  132. unsigned int flags;
  133. unsigned int call_reference;
  134. char *callToken;
  135. char *username;
  136. char *host;
  137. char *callerid_name;
  138. char *callerid_num;
  139. char caller_h323id[AST_MAX_EXTENSION];
  140. char caller_dialedDigits[AST_MAX_EXTENSION];
  141. char caller_email[AST_MAX_EXTENSION];
  142. char caller_url[256];
  143. char callee_h323id[AST_MAX_EXTENSION];
  144. char callee_dialedDigits[AST_MAX_EXTENSION];
  145. char callee_email[AST_MAX_EXTENSION];
  146. char callee_url[AST_MAX_EXTENSION];
  147. int port;
  148. format_t readformat; /* negotiated read format */
  149. format_t writeformat; /* negotiated write format */
  150. format_t capability;
  151. struct ast_codec_pref prefs;
  152. int dtmfmode;
  153. int dtmfcodec;
  154. char exten[AST_MAX_EXTENSION]; /* Requested extension */
  155. char context[AST_MAX_EXTENSION]; /* Context where to start */
  156. char accountcode[256]; /* Account code */
  157. int nat;
  158. int amaflags;
  159. int progsent; /* progress is sent */
  160. int alertsent; /* alerting is sent */
  161. int g729onlyA; /* G.729 only A */
  162. struct ast_dsp *vad;
  163. struct OOH323Regex *rtpmask; /* rtp ip regexp */
  164. char rtpmaskstr[120];
  165. int rtdrcount, rtdrinterval; /* roundtripdelayreq */
  166. int faststart, h245tunneling; /* faststart & h245 tunneling */
  167. struct ooh323_pvt *next; /* Next entity */
  168. } *iflist = NULL;
  169. /* Protect the channel/interface list (ooh323_pvt) */
  170. AST_MUTEX_DEFINE_STATIC(iflock);
  171. /* Profile of H.323 user registered with PBX*/
  172. struct ooh323_user{
  173. ast_mutex_t lock;
  174. char name[256];
  175. char context[AST_MAX_EXTENSION];
  176. int incominglimit;
  177. unsigned inUse;
  178. char accountcode[20];
  179. int amaflags;
  180. format_t capability;
  181. struct ast_codec_pref prefs;
  182. int dtmfmode;
  183. int dtmfcodec;
  184. int t38support;
  185. int rtptimeout;
  186. int mUseIP; /* Use IP address or H323-ID to search user */
  187. char mIP[20];
  188. struct OOH323Regex *rtpmask;
  189. char rtpmaskstr[120];
  190. int rtdrcount, rtdrinterval;
  191. int faststart, h245tunneling;
  192. int g729onlyA;
  193. struct ooh323_user *next;
  194. };
  195. /* Profile of valid asterisk peers */
  196. struct ooh323_peer{
  197. ast_mutex_t lock;
  198. char name[256];
  199. unsigned outgoinglimit;
  200. unsigned outUse;
  201. format_t capability;
  202. struct ast_codec_pref prefs;
  203. char accountcode[20];
  204. int amaflags;
  205. int dtmfmode;
  206. int dtmfcodec;
  207. int t38support;
  208. int mFriend; /* indicates defined as friend */
  209. char ip[20];
  210. int port;
  211. char *h323id; /* H323-ID alias, which asterisk will register with gk to reach this peer*/
  212. char *email; /* Email alias, which asterisk will register with gk to reach this peer*/
  213. char *url; /* url alias, which asterisk will register with gk to reach this peer*/
  214. char *e164; /* e164 alias, which asterisk will register with gk to reach this peer*/
  215. int rtptimeout;
  216. struct OOH323Regex *rtpmask;
  217. char rtpmaskstr[120];
  218. int rtdrcount,rtdrinterval;
  219. int faststart, h245tunneling;
  220. int g729onlyA;
  221. struct ooh323_peer *next;
  222. };
  223. /* List of H.323 users known to PBX */
  224. static struct ast_user_list {
  225. struct ooh323_user *users;
  226. ast_mutex_t lock;
  227. } userl;
  228. static struct ast_peer_list {
  229. struct ooh323_peer *peers;
  230. ast_mutex_t lock;
  231. } peerl;
  232. /* Mutex to protect H.323 reload process */
  233. static int h323_reloading = 0;
  234. AST_MUTEX_DEFINE_STATIC(h323_reload_lock);
  235. /* Mutex to protect usage counter */
  236. static int usecnt = 0;
  237. AST_MUTEX_DEFINE_STATIC(usecnt_lock);
  238. AST_MUTEX_DEFINE_STATIC(ooh323c_cmd_lock);
  239. static long callnumber = 0;
  240. AST_MUTEX_DEFINE_STATIC(ooh323c_cn_lock);
  241. /* stack callbacks */
  242. int onAlerting(ooCallData *call);
  243. int onProgress(ooCallData *call);
  244. int onNewCallCreated(ooCallData *call);
  245. int onOutgoingCall(ooCallData *call);
  246. int onCallEstablished(ooCallData *call);
  247. int onCallCleared(ooCallData *call);
  248. void onModeChanged(ooCallData *call, int t38mode);
  249. static char gLogFile[256] = DEFAULT_LOGFILE;
  250. static int gPort = 1720;
  251. static char gIP[20];
  252. static char gCallerID[AST_MAX_EXTENSION] = "";
  253. static struct ooAliases *gAliasList;
  254. static format_t gCapability = AST_FORMAT_ULAW;
  255. static struct ast_codec_pref gPrefs;
  256. static int gDTMFMode = H323_DTMF_RFC2833;
  257. static int gDTMFCodec = 101;
  258. static int gT38Support = T38_FAXGW;
  259. static char gGatekeeper[100];
  260. static enum RasGatekeeperMode gRasGkMode = RasNoGatekeeper;
  261. static int gIsGateway = 0;
  262. static int gFastStart = 1;
  263. static int gTunneling = 1;
  264. static int gBeMaster = 0;
  265. static int gMediaWaitForConnect = 0;
  266. static int gTOS = 0;
  267. static int gRTPTimeout = 60;
  268. static int g729onlyA = 0;
  269. static char gAccountcode[80] = DEFAULT_H323ACCNT;
  270. static int gAMAFLAGS;
  271. static char gContext[AST_MAX_EXTENSION] = DEFAULT_CONTEXT;
  272. static int gIncomingLimit = 1024;
  273. static int gOutgoingLimit = 1024;
  274. OOBOOL gH323Debug = FALSE;
  275. static int gTRCLVL = OOTRCLVLERR;
  276. static int gRTDRCount = 0, gRTDRInterval = 0;
  277. static int t35countrycode = 0;
  278. static int t35extensions = 0;
  279. static int manufacturer = 0;
  280. static char vendor[AST_MAX_EXTENSION] = "";
  281. static char version[AST_MAX_EXTENSION] = "";
  282. static struct ooh323_config
  283. {
  284. int mTCPPortStart;
  285. int mTCPPortEnd;
  286. } ooconfig;
  287. /** Asterisk RTP stuff*/
  288. static struct sched_context *sched;
  289. static struct io_context *io;
  290. /* Protect the monitoring thread, so only one process can kill or start it,
  291. and not when it's doing something critical. */
  292. AST_MUTEX_DEFINE_STATIC(monlock);
  293. /* This is the thread for the monitor which checks for input on the channels
  294. which are not currently in use. */
  295. static pthread_t monitor_thread = AST_PTHREADT_NULL;
  296. static struct ast_channel *ooh323_new(struct ooh323_pvt *i, int state,
  297. const char *host, int capability, const char *linkedid)
  298. {
  299. struct ast_channel *ch = NULL;
  300. int fmt = 0;
  301. if (gH323Debug)
  302. ast_verbose("--- ooh323_new - %s, %d\n", host, capability);
  303. /* Don't hold a h323 pvt lock while we allocate a channel */
  304. ast_mutex_unlock(&i->lock);
  305. ast_mutex_lock(&ooh323c_cn_lock);
  306. ch = ast_channel_alloc(1, state, i->callerid_num, i->callerid_name,
  307. i->accountcode, i->exten, i->context, linkedid, i->amaflags,
  308. "OOH323/%s-%ld", host, callnumber);
  309. callnumber++;
  310. ast_mutex_unlock(&ooh323c_cn_lock);
  311. ast_mutex_lock(&i->lock);
  312. if (ch) {
  313. ast_channel_lock(ch);
  314. ch->tech = &ooh323_tech;
  315. if (capability)
  316. fmt = ast_best_codec(capability);
  317. if (!fmt)
  318. fmt = ast_codec_pref_index(&i->prefs, 0);
  319. ch->nativeformats = ch->rawwriteformat = ch->rawreadformat = fmt;
  320. ast_channel_set_fd(ch, 0, ast_rtp_instance_fd(i->rtp, 0));
  321. ast_channel_set_fd(ch, 1, ast_rtp_instance_fd(i->rtp, 1));
  322. ast_channel_set_fd(ch, 5, ast_udptl_fd(i->udptl));
  323. ast_jb_configure(ch, &global_jbconf);
  324. if (state == AST_STATE_RING)
  325. ch->rings = 1;
  326. ch->adsicpe = AST_ADSI_UNAVAILABLE;
  327. ast_set_write_format(ch, fmt);
  328. ast_set_read_format(ch, fmt);
  329. ch->tech_pvt = i;
  330. i->owner = ch;
  331. ast_module_ref(myself);
  332. /* Allocate dsp for in-band DTMF support */
  333. if (i->dtmfmode & H323_DTMF_INBAND) {
  334. i->vad = ast_dsp_new();
  335. ast_dsp_set_features(i->vad, DSP_FEATURE_DIGIT_DETECT);
  336. ast_dsp_set_features(i->vad,
  337. DSP_FEATURE_DIGIT_DETECT | DSP_FEATURE_FAX_DETECT);
  338. ast_dsp_set_faxmode(i->vad,
  339. DSP_FAXMODE_DETECT_CNG | DSP_FAXMODE_DETECT_CED);
  340. if (i->dtmfmode & H323_DTMF_INBANDRELAX)
  341. ast_dsp_set_digitmode(i->vad, DSP_DIGITMODE_DTMF | DSP_DIGITMODE_RELAXDTMF);
  342. }
  343. ast_mutex_lock(&usecnt_lock);
  344. usecnt++;
  345. ast_mutex_unlock(&usecnt_lock);
  346. /* Notify the module monitors that use count for resource has changed*/
  347. ast_update_use_count();
  348. ast_copy_string(ch->context, i->context, sizeof(ch->context));
  349. ast_copy_string(ch->exten, i->exten, sizeof(ch->exten));
  350. ch->priority = 1;
  351. if(!ast_test_flag(i, H323_OUTGOING)) {
  352. if (!ast_strlen_zero(i->caller_h323id)) {
  353. pbx_builtin_setvar_helper(ch, "_CALLER_H323ID", i->caller_h323id);
  354. }
  355. if (!ast_strlen_zero(i->caller_dialedDigits)) {
  356. pbx_builtin_setvar_helper(ch, "_CALLER_H323DIALEDDIGITS",
  357. i->caller_dialedDigits);
  358. }
  359. if (!ast_strlen_zero(i->caller_email)) {
  360. pbx_builtin_setvar_helper(ch, "_CALLER_H323EMAIL",
  361. i->caller_email);
  362. }
  363. if (!ast_strlen_zero(i->caller_url)) {
  364. pbx_builtin_setvar_helper(ch, "_CALLER_H323URL", i->caller_url);
  365. }
  366. }
  367. if (!ast_strlen_zero(i->accountcode))
  368. ast_string_field_set(ch, accountcode, i->accountcode);
  369. if (i->amaflags)
  370. ch->amaflags = i->amaflags;
  371. ast_setstate(ch, state);
  372. if (state != AST_STATE_DOWN) {
  373. if (ast_pbx_start(ch)) {
  374. ast_log(LOG_WARNING, "Unable to start PBX on %s\n", ch->name);
  375. ast_channel_unlock(ch);
  376. ast_hangup(ch);
  377. ch = NULL;
  378. }
  379. }
  380. if (ch) {
  381. manager_event(EVENT_FLAG_SYSTEM, "ChannelUpdate",
  382. "Channel: %s\r\nChanneltype: %s\r\n"
  383. "CallRef: %d\r\n", ch->name, "OOH323", i->call_reference);
  384. }
  385. } else
  386. ast_log(LOG_WARNING, "Unable to allocate channel structure\n");
  387. if(ch) ast_channel_unlock(ch);
  388. if (gH323Debug)
  389. ast_verbose("+++ h323_new\n");
  390. return ch;
  391. }
  392. static struct ooh323_pvt *ooh323_alloc(int callref, char *callToken)
  393. {
  394. struct ooh323_pvt *pvt = NULL;
  395. struct sockaddr_in ouraddr;
  396. struct ast_sockaddr tmp;
  397. struct in_addr ipAddr;
  398. if (gH323Debug)
  399. ast_verbose("--- ooh323_alloc\n");
  400. if (!(pvt = ast_calloc(1, sizeof(*pvt)))) {
  401. ast_log(LOG_ERROR, "Couldn't allocate private ooh323 structure\n");
  402. return NULL;
  403. }
  404. ast_mutex_init(&pvt->lock);
  405. ast_mutex_lock(&pvt->lock);
  406. if (!inet_aton(gIP, &ipAddr)) {
  407. ast_log(LOG_ERROR, "Invalid OOH323 driver ip address\n");
  408. ast_mutex_unlock(&pvt->lock);
  409. ast_mutex_destroy(&pvt->lock);
  410. ast_free(pvt);
  411. return NULL;
  412. }
  413. ouraddr.sin_family = AF_INET;
  414. ouraddr.sin_addr = ipAddr;
  415. ast_sockaddr_from_sin(&tmp, &ouraddr);
  416. if (!(pvt->rtp = ast_rtp_instance_new("asterisk", sched, &tmp, NULL))) {
  417. ast_log(LOG_WARNING, "Unable to create RTP session: %s\n",
  418. strerror(errno));
  419. ast_mutex_unlock(&pvt->lock);
  420. ast_mutex_destroy(&pvt->lock);
  421. ast_free(pvt);
  422. return NULL;
  423. }
  424. ast_rtp_instance_set_qos(pvt->rtp, gTOS, 0, "ooh323-rtp");
  425. if (!(pvt->udptl = ast_udptl_new_with_bindaddr(sched, io, 0, &tmp))) {
  426. ast_log(LOG_WARNING, "Unable to create UDPTL session: %s\n",
  427. strerror(errno));
  428. ast_mutex_unlock(&pvt->lock);
  429. ast_mutex_destroy(&pvt->lock);
  430. ast_free(pvt);
  431. return NULL;
  432. }
  433. ast_udptl_set_error_correction_scheme(pvt->udptl, UDPTL_ERROR_CORRECTION_NONE);
  434. ast_udptl_set_far_max_datagram(pvt->udptl, 144);
  435. pvt->faxmode = 0;
  436. pvt->t38support = gT38Support;
  437. pvt->rtptimeout = gRTPTimeout;
  438. pvt->rtdrinterval = gRTDRInterval;
  439. pvt->rtdrcount = gRTDRCount;
  440. pvt->g729onlyA = g729onlyA;
  441. pvt->call_reference = callref;
  442. if (callToken)
  443. pvt->callToken = strdup(callToken);
  444. /* whether to use gk for this call */
  445. if (gRasGkMode == RasNoGatekeeper)
  446. OO_SETFLAG(pvt->flags, H323_DISABLEGK);
  447. pvt->dtmfmode = gDTMFMode;
  448. pvt->dtmfcodec = gDTMFCodec;
  449. ast_copy_string(pvt->context, gContext, sizeof(pvt->context));
  450. ast_copy_string(pvt->accountcode, gAccountcode, sizeof(pvt->accountcode));
  451. pvt->amaflags = gAMAFLAGS;
  452. pvt->capability = gCapability;
  453. memcpy(&pvt->prefs, &gPrefs, sizeof(pvt->prefs));
  454. ast_mutex_unlock(&pvt->lock);
  455. /* Add to interface list */
  456. ast_mutex_lock(&iflock);
  457. pvt->next = iflist;
  458. iflist = pvt;
  459. ast_mutex_unlock(&iflock);
  460. if (gH323Debug)
  461. ast_verbose("+++ ooh323_alloc\n");
  462. return pvt;
  463. }
  464. /*
  465. Possible data values - peername, exten/peername, exten@ip
  466. */
  467. static struct ast_channel *ooh323_request(const char *type, format_t format,
  468. const struct ast_channel *requestor, void *data, int *cause)
  469. {
  470. struct ast_channel *chan = NULL;
  471. struct ooh323_pvt *p = NULL;
  472. struct ooh323_peer *peer = NULL;
  473. char *dest = NULL;
  474. char *ext = NULL;
  475. char tmp[256];
  476. char formats[FORMAT_STRING_SIZE];
  477. int port = 0;
  478. if (gH323Debug)
  479. ast_verbose("--- ooh323_request - data %s format %s\n", (char*)data,
  480. ast_getformatname_multiple(formats,FORMAT_STRING_SIZE,format));
  481. format &= AST_FORMAT_AUDIO_MASK;
  482. if (!format) {
  483. ast_log(LOG_NOTICE, "Asked to get a channel of unsupported format '%lld'\n", (long long) format);
  484. return NULL;
  485. }
  486. p = ooh323_alloc(0,0); /* Initial callRef is zero */
  487. if (!p) {
  488. ast_log(LOG_WARNING, "Unable to build pvt data for '%s'\n", (char*)data);
  489. return NULL;
  490. }
  491. ast_mutex_lock(&p->lock);
  492. /* This is an outgoing call, since ooh323_request is called */
  493. ast_set_flag(p, H323_OUTGOING);
  494. ast_copy_string(tmp, data, sizeof(tmp));
  495. dest = strchr(tmp, '/');
  496. if (dest) {
  497. *dest = '\0';
  498. dest++;
  499. ext = dest;
  500. dest = tmp;
  501. } else if ((dest = strchr(tmp, '@'))) {
  502. *dest = '\0';
  503. dest++;
  504. ext = tmp;
  505. } else {
  506. dest = tmp;
  507. ext = NULL;
  508. }
  509. #if 0
  510. if ((sport = strchr(dest, ':'))) {
  511. *sport = '\0';
  512. sport++;
  513. port = atoi(sport);
  514. }
  515. #endif
  516. if (dest) {
  517. peer = find_peer(dest, port);
  518. } else{
  519. ast_mutex_lock(&iflock);
  520. ast_mutex_unlock(&p->lock);
  521. ooh323_destroy(p);
  522. ast_mutex_unlock(&iflock);
  523. ast_log(LOG_ERROR, "Destination format is not supported\n");
  524. return NULL;
  525. }
  526. if (peer) {
  527. p->username = strdup(peer->name);
  528. p->host = strdup(peer->ip);
  529. p->port = peer->port;
  530. /* Disable gk as we are going to call a known peer*/
  531. /* OO_SETFLAG(p->flags, H323_DISABLEGK); */
  532. if (ext)
  533. ast_copy_string(p->exten, ext, sizeof(p->exten));
  534. p->capability = peer->capability;
  535. memcpy(&p->prefs, &peer->prefs, sizeof(struct ast_codec_pref));
  536. p->g729onlyA = peer->g729onlyA;
  537. p->dtmfmode |= peer->dtmfmode;
  538. p->dtmfcodec = peer->dtmfcodec;
  539. p->t38support = peer->t38support;
  540. p->rtptimeout = peer->rtptimeout;
  541. p->faststart = peer->faststart;
  542. p->h245tunneling = peer->h245tunneling;
  543. if (peer->rtpmask && peer->rtpmaskstr[0]) {
  544. p->rtpmask = peer->rtpmask;
  545. ast_copy_string(p->rtpmaskstr, peer->rtpmaskstr, sizeof(p->rtpmaskstr));
  546. }
  547. if (peer->rtdrinterval) {
  548. p->rtdrinterval = peer->rtdrinterval;
  549. p->rtdrcount = peer->rtdrcount;
  550. }
  551. ast_copy_string(p->accountcode, peer->accountcode, sizeof(p->accountcode));
  552. p->amaflags = peer->amaflags;
  553. } else {
  554. if (gRasGkMode == RasNoGatekeeper) {
  555. /* no gk and no peer */
  556. ast_log(LOG_ERROR, "Call to undefined peer %s", dest);
  557. ast_mutex_lock(&iflock);
  558. ast_mutex_unlock(&p->lock);
  559. ooh323_destroy(p);
  560. ast_mutex_unlock(&iflock);
  561. return NULL;
  562. }
  563. p->g729onlyA = g729onlyA;
  564. p->dtmfmode = gDTMFMode;
  565. p->dtmfcodec = gDTMFCodec;
  566. p->t38support = gT38Support;
  567. p->rtptimeout = gRTPTimeout;
  568. p->capability = gCapability;
  569. p->rtdrinterval = gRTDRInterval;
  570. p->rtdrcount = gRTDRCount;
  571. p->faststart = gFastStart;
  572. p->h245tunneling = gTunneling;
  573. memcpy(&p->prefs, &gPrefs, sizeof(struct ast_codec_pref));
  574. p->username = strdup(dest);
  575. p->host = strdup(dest);
  576. if (port > 0) {
  577. p->port = port;
  578. }
  579. if (ext) {
  580. ast_copy_string(p->exten, ext, sizeof(p->exten));
  581. }
  582. }
  583. chan = ooh323_new(p, AST_STATE_DOWN, p->username, format,
  584. requestor ? requestor->linkedid : NULL);
  585. ast_mutex_unlock(&p->lock);
  586. if (!chan) {
  587. ast_mutex_lock(&iflock);
  588. ooh323_destroy(p);
  589. ast_mutex_unlock(&iflock);
  590. } else {
  591. ast_mutex_lock(&p->lock);
  592. p->callToken = (char*)ast_malloc(AST_MAX_EXTENSION);
  593. if(!p->callToken) {
  594. ast_mutex_unlock(&p->lock);
  595. ast_mutex_lock(&iflock);
  596. ooh323_destroy(p);
  597. ast_mutex_unlock(&iflock);
  598. ast_log(LOG_ERROR, "Failed to allocate memory for callToken\n");
  599. return NULL;
  600. }
  601. ast_mutex_unlock(&p->lock);
  602. ast_mutex_lock(&ooh323c_cmd_lock);
  603. ooMakeCall(data, p->callToken, AST_MAX_EXTENSION, NULL);
  604. ast_mutex_unlock(&ooh323c_cmd_lock);
  605. }
  606. restart_monitor();
  607. if (gH323Debug)
  608. ast_verbose("+++ ooh323_request\n");
  609. return chan;
  610. }
  611. static struct ooh323_pvt* find_call(ooCallData *call)
  612. {
  613. struct ooh323_pvt *p;
  614. if (gH323Debug)
  615. ast_verbose("--- find_call\n");
  616. ast_mutex_lock(&iflock);
  617. for (p = iflist; p; p = p->next) {
  618. if (p->callToken && !strcmp(p->callToken, call->callToken)) {
  619. break;
  620. }
  621. }
  622. ast_mutex_unlock(&iflock);
  623. if (gH323Debug)
  624. ast_verbose("+++ find_call\n");
  625. return p;
  626. }
  627. struct ooh323_user *find_user(const char * name, const char* ip)
  628. {
  629. struct ooh323_user *user;
  630. if (gH323Debug)
  631. ast_verbose("--- find_user: %s, %s\n",name,ip);
  632. ast_mutex_lock(&userl.lock);
  633. for (user = userl.users; user; user = user->next) {
  634. if (ip && user->mUseIP && !strcmp(user->mIP, ip)) {
  635. break;
  636. }
  637. if (name && !strcmp(user->name, name)) {
  638. break;
  639. }
  640. }
  641. ast_mutex_unlock(&userl.lock);
  642. if (gH323Debug)
  643. ast_verbose("+++ find_user\n");
  644. return user;
  645. }
  646. struct ooh323_peer *find_friend(const char *name, int port)
  647. {
  648. struct ooh323_peer *peer;
  649. if (gH323Debug)
  650. ast_verbose("--- find_friend \"%s\"\n", name);
  651. ast_mutex_lock(&peerl.lock);
  652. for (peer = peerl.peers; peer; peer = peer->next) {
  653. if (gH323Debug) {
  654. ast_verbose(" comparing with \"%s\"\n", peer->ip);
  655. }
  656. if (!strcmp(peer->ip, name)) {
  657. if (port <= 0 || (port > 0 && peer->port == port)) {
  658. break;
  659. }
  660. }
  661. }
  662. ast_mutex_unlock(&peerl.lock);
  663. if (gH323Debug) {
  664. if (peer) {
  665. ast_verbose(" found matching friend\n");
  666. }
  667. ast_verbose("+++ find_friend \"%s\"\n", name);
  668. }
  669. return peer;
  670. }
  671. struct ooh323_peer *find_peer(const char * name, int port)
  672. {
  673. struct ooh323_peer *peer;
  674. if (gH323Debug)
  675. ast_verbose("--- find_peer \"%s\"\n", name);
  676. ast_mutex_lock(&peerl.lock);
  677. for (peer = peerl.peers; peer; peer = peer->next) {
  678. if (gH323Debug) {
  679. ast_verbose(" comparing with \"%s\"\n", peer->ip);
  680. }
  681. if (!strcasecmp(peer->name, name))
  682. break;
  683. if (peer->h323id && !strcasecmp(peer->h323id, name))
  684. break;
  685. if (peer->e164 && !strcasecmp(peer->e164, name))
  686. break;
  687. /*
  688. if (!strcmp(peer->ip, name)) {
  689. if (port > 0 && peer->port == port) { break; }
  690. else if (port <= 0) { break; }
  691. }
  692. */
  693. }
  694. ast_mutex_unlock(&peerl.lock);
  695. if (gH323Debug) {
  696. if (peer) {
  697. ast_verbose(" found matching peer\n");
  698. }
  699. ast_verbose("+++ find_peer \"%s\"\n", name);
  700. }
  701. return peer;
  702. }
  703. static int ooh323_digit_begin(struct ast_channel *chan, char digit)
  704. {
  705. char dtmf[2];
  706. struct ooh323_pvt *p = (struct ooh323_pvt *) chan->tech_pvt;
  707. int res = 0;
  708. if (gH323Debug)
  709. ast_verbose("--- ooh323_digit_begin\n");
  710. if (!p) {
  711. ast_log(LOG_ERROR, "No private structure for call\n");
  712. return -1;
  713. }
  714. ast_mutex_lock(&p->lock);
  715. if (digit == 'e' && !p->faxmode && p->t38support != T38_DISABLED) {
  716. if (!p->chmodepend) {
  717. if (gH323Debug)
  718. ast_verbose("request to change %s to t.38 because fax cng\n",
  719. p->callToken);
  720. p->chmodepend = 1;
  721. ooRequestChangeMode(p->callToken, 1);
  722. }
  723. } else if (p->rtp && ((p->dtmfmode & H323_DTMF_RFC2833) || (p->dtmfmode & H323_DTMF_CISCO))) {
  724. ast_rtp_instance_dtmf_begin(p->rtp, digit);
  725. } else if (((p->dtmfmode & H323_DTMF_Q931) ||
  726. (p->dtmfmode & H323_DTMF_H245ALPHANUMERIC) ||
  727. (p->dtmfmode & H323_DTMF_H245SIGNAL))) {
  728. dtmf[0] = digit;
  729. dtmf[1] = '\0';
  730. ooSendDTMFDigit(p->callToken, dtmf);
  731. } else if (p->dtmfmode & H323_DTMF_INBAND) {
  732. res = -1; // tell Asterisk to generate inband indications
  733. }
  734. ast_mutex_unlock(&p->lock);
  735. if (gH323Debug) {
  736. ast_verbose("+++ ooh323_digit_begin %d\n", res);
  737. }
  738. return res;
  739. }
  740. static int ooh323_digit_end(struct ast_channel *chan, char digit, unsigned int duration)
  741. {
  742. struct ooh323_pvt *p = (struct ooh323_pvt *) chan->tech_pvt;
  743. int res = 0;
  744. if (gH323Debug)
  745. ast_verbose("--- ooh323_digit_end\n");
  746. if (!p) {
  747. ast_log(LOG_ERROR, "No private structure for call\n");
  748. return -1;
  749. }
  750. ast_mutex_lock(&p->lock);
  751. if (p->rtp && ((p->dtmfmode & H323_DTMF_RFC2833) || (p->dtmfmode & H323_DTMF_CISCO)) ) {
  752. ast_rtp_instance_dtmf_end(p->rtp, digit);
  753. } else if(p->dtmfmode & H323_DTMF_INBAND) {
  754. res = -1; // tell Asterisk to stop inband indications
  755. }
  756. ast_mutex_unlock(&p->lock);
  757. if (gH323Debug) {
  758. ast_verbose("+++ ooh323_digit_end, res = %d\n", res);
  759. }
  760. return res;
  761. }
  762. static int ooh323_call(struct ast_channel *ast, char *dest, int timeout)
  763. {
  764. struct ooh323_pvt *p = ast->tech_pvt;
  765. char destination[256];
  766. int res=0, i;
  767. const char *val = NULL;
  768. ooCallOptions opts = {
  769. .fastStart = TRUE,
  770. .tunneling = TRUE,
  771. .disableGk = TRUE,
  772. .callMode = OO_CALLMODE_AUDIOCALL,
  773. .transfercap = 0
  774. };
  775. if (gH323Debug)
  776. ast_verbose("--- ooh323_call- %s\n", dest);
  777. if ((ast->_state != AST_STATE_DOWN) && (ast->_state != AST_STATE_RESERVED)) {
  778. ast_log(LOG_WARNING, "ooh323_call called on %s, neither down nor "
  779. "reserved\n", ast->name);
  780. return -1;
  781. }
  782. ast_mutex_lock(&p->lock);
  783. ast_set_flag(p, H323_OUTGOING);
  784. if (ast->connected.id.number.valid && ast->connected.id.number.str) {
  785. free(p->callerid_num);
  786. p->callerid_num = strdup(ast->connected.id.number.str);
  787. }
  788. if (ast->connected.id.name.valid && ast->connected.id.name.str) {
  789. free(p->callerid_name);
  790. p->callerid_name = strdup(ast->connected.id.name.str);
  791. } else if (ast->connected.id.number.valid && ast->connected.id.number.str) {
  792. free(p->callerid_name);
  793. p->callerid_name = strdup(ast->connected.id.number.str);
  794. } else {
  795. ast->connected.id.name.valid = 1;
  796. free(ast->connected.id.name.str);
  797. ast->connected.id.name.str = strdup(gCallerID);
  798. free(p->callerid_name);
  799. p->callerid_name = strdup(ast->connected.id.name.str);
  800. }
  801. /* Retrieve vars */
  802. if ((val = pbx_builtin_getvar_helper(ast, "CALLER_H323ID"))) {
  803. ast_copy_string(p->caller_h323id, val, sizeof(p->caller_h323id));
  804. }
  805. if ((val = pbx_builtin_getvar_helper(ast, "CALLER_H323DIALEDDIGITS"))) {
  806. ast_copy_string(p->caller_dialedDigits, val, sizeof(p->caller_dialedDigits));
  807. if(!p->callerid_num)
  808. p->callerid_num = strdup(val);
  809. }
  810. if ((val = pbx_builtin_getvar_helper(ast, "CALLER_H323EMAIL"))) {
  811. ast_copy_string(p->caller_email, val, sizeof(p->caller_email));
  812. }
  813. if ((val = pbx_builtin_getvar_helper(ast, "CALLER_H323URL"))) {
  814. ast_copy_string(p->caller_url, val, sizeof(p->caller_url));
  815. }
  816. if (p->host && p->port != 0)
  817. snprintf(destination, sizeof(destination), "%s:%d", p->host, p->port);
  818. else if (p->host)
  819. snprintf(destination, sizeof(destination), "%s", p->host);
  820. else
  821. ast_copy_string(destination, dest, sizeof(destination));
  822. destination[sizeof(destination)-1]='\0';
  823. opts.transfercap = ast->transfercapability;
  824. opts.fastStart = p->faststart;
  825. opts.tunneling = p->h245tunneling;
  826. for (i=0;i<480 && !isRunning(p->callToken);i++) usleep(12000);
  827. if(OO_TESTFLAG(p->flags, H323_DISABLEGK)) {
  828. res = ooRunCall(destination, p->callToken, AST_MAX_EXTENSION, &opts);
  829. } else {
  830. res = ooRunCall(destination, p->callToken, AST_MAX_EXTENSION, NULL);
  831. }
  832. ast_mutex_unlock(&p->lock);
  833. if (res != OO_OK) {
  834. ast_log(LOG_ERROR, "Failed to make call\n");
  835. return -1; /* ToDO: cleanup */
  836. }
  837. if (gH323Debug)
  838. ast_verbose("+++ ooh323_call\n");
  839. return 0;
  840. }
  841. static int ooh323_hangup(struct ast_channel *ast)
  842. {
  843. struct ooh323_pvt *p = ast->tech_pvt;
  844. int q931cause = AST_CAUSE_NORMAL_CLEARING;
  845. if (gH323Debug)
  846. ast_verbose("--- ooh323_hangup\n");
  847. if (p) {
  848. ast_mutex_lock(&p->lock);
  849. if (ast->hangupcause) {
  850. q931cause = ast->hangupcause;
  851. } else {
  852. const char *cause = pbx_builtin_getvar_helper(ast, "DIALSTATUS");
  853. if (cause) {
  854. if (!strcmp(cause, "CONGESTION")) {
  855. q931cause = AST_CAUSE_NORMAL_CIRCUIT_CONGESTION;
  856. } else if (!strcmp(cause, "BUSY")) {
  857. q931cause = AST_CAUSE_USER_BUSY;
  858. } else if (!strcmp(cause, "CHANISUNVAIL")) {
  859. q931cause = AST_CAUSE_REQUESTED_CHAN_UNAVAIL;
  860. } else if (!strcmp(cause, "NOANSWER")) {
  861. q931cause = AST_CAUSE_NO_ANSWER;
  862. } else if (!strcmp(cause, "CANCEL")) {
  863. q931cause = AST_CAUSE_CALL_REJECTED;
  864. }
  865. }
  866. }
  867. if (gH323Debug)
  868. ast_verbose(" hanging %s with cause: %d\n", p->username, q931cause);
  869. ast->tech_pvt = NULL;
  870. if (!ast_test_flag(p, H323_ALREADYGONE)) {
  871. ooHangCall(p->callToken,
  872. ooh323_convert_hangupcause_asteriskToH323(q931cause), q931cause);
  873. ast_set_flag(p, H323_ALREADYGONE);
  874. /* ast_mutex_unlock(&p->lock); */
  875. } else
  876. ast_set_flag(p, H323_NEEDDESTROY);
  877. /* detach channel here */
  878. if (p->owner) {
  879. p->owner->tech_pvt = NULL;
  880. p->owner = NULL;
  881. ast_module_unref(myself);
  882. }
  883. ast_mutex_unlock(&p->lock);
  884. ast_mutex_lock(&usecnt_lock);
  885. usecnt--;
  886. ast_mutex_unlock(&usecnt_lock);
  887. /* Notify the module monitors that use count for resource has changed */
  888. ast_update_use_count();
  889. } else {
  890. ast_debug(1, "No call to hangup\n" );
  891. }
  892. if (gH323Debug)
  893. ast_verbose("+++ ooh323_hangup\n");
  894. return 0;
  895. }
  896. static int ooh323_answer(struct ast_channel *ast)
  897. {
  898. struct ooh323_pvt *p = ast->tech_pvt;
  899. char *callToken = (char *)NULL;
  900. if (gH323Debug)
  901. ast_verbose("--- ooh323_answer\n");
  902. if (p) {
  903. ast_mutex_lock(&p->lock);
  904. callToken = (p->callToken ? strdup(p->callToken) : NULL);
  905. if (ast->_state != AST_STATE_UP) {
  906. ast_channel_lock(ast);
  907. if (!p->alertsent) {
  908. if (gH323Debug) {
  909. ast_debug(1, "Sending forced ringback for %s, res = %d\n",
  910. callToken, ooManualRingback(callToken));
  911. } else {
  912. ooManualRingback(callToken);
  913. }
  914. p->alertsent = 1;
  915. }
  916. ast_setstate(ast, AST_STATE_UP);
  917. if (option_debug)
  918. ast_debug(1, "ooh323_answer(%s)\n", ast->name);
  919. ast_channel_unlock(ast);
  920. ooAnswerCall(p->callToken);
  921. }
  922. if (callToken) {
  923. free(callToken);
  924. }
  925. ast_mutex_unlock(&p->lock);
  926. }
  927. if (gH323Debug)
  928. ast_verbose("+++ ooh323_answer\n");
  929. return 0;
  930. }
  931. static struct ast_frame *ooh323_read(struct ast_channel *ast)
  932. {
  933. struct ast_frame *fr;
  934. static struct ast_frame null_frame = { AST_FRAME_NULL, };
  935. struct ooh323_pvt *p = ast->tech_pvt;
  936. if (!p) return &null_frame;
  937. ast_mutex_lock(&p->lock);
  938. if (p->rtp)
  939. fr = ooh323_rtp_read(ast, p);
  940. else
  941. fr = &null_frame;
  942. /* time(&p->lastrtprx); */
  943. ast_mutex_unlock(&p->lock);
  944. return fr;
  945. }
  946. static int ooh323_write(struct ast_channel *ast, struct ast_frame *f)
  947. {
  948. struct ooh323_pvt *p = ast->tech_pvt;
  949. int res = 0;
  950. char buf[256];
  951. if (p) {
  952. ast_mutex_lock(&p->lock);
  953. if (f->frametype == AST_FRAME_MODEM) {
  954. ast_debug(1, "Send UDPTL %d/%d len %d for %s\n",
  955. f->frametype, f->subclass.integer, f->datalen, ast->name);
  956. if (p->udptl)
  957. res = ast_udptl_write(p->udptl, f);
  958. ast_mutex_unlock(&p->lock);
  959. return res;
  960. }
  961. if (f->frametype == AST_FRAME_VOICE) {
  962. /* sending progress for first */
  963. if (!ast_test_flag(p, H323_OUTGOING) && !p->progsent &&
  964. p->callToken) {
  965. ooManualProgress(p->callToken);
  966. p->progsent = 1;
  967. }
  968. if (!(f->subclass.codec & ast->nativeformats)) {
  969. if (ast->nativeformats != 0) {
  970. ast_log(LOG_WARNING,
  971. "Asked to transmit frame type %s, while native formats is %s (read/write = %s/%s)\n",
  972. ast_getformatname(f->subclass.codec),
  973. ast_getformatname_multiple(buf, sizeof(buf), ast->nativeformats),
  974. ast_getformatname(ast->readformat),
  975. ast_getformatname(ast->writeformat));
  976. ast_set_write_format(ast, f->subclass.codec);
  977. } else {
  978. /* ast_set_write_format(ast, f->subclass);
  979. ast->nativeformats = f->subclass; */
  980. }
  981. ast_mutex_unlock(&p->lock);
  982. return 0;
  983. }
  984. if (p->rtp)
  985. res = ast_rtp_instance_write(p->rtp, f);
  986. ast_mutex_unlock(&p->lock);
  987. } else if (f->frametype == AST_FRAME_IMAGE) {
  988. ast_mutex_unlock(&p->lock);
  989. return 0;
  990. } else {
  991. ast_log(LOG_WARNING, "Can't send %d type frames with OOH323 write\n",
  992. f->frametype);
  993. ast_mutex_unlock(&p->lock);
  994. return 0;
  995. }
  996. }
  997. return res;
  998. }
  999. static int ooh323_indicate(struct ast_channel *ast, int condition, const void *data, size_t datalen)
  1000. {
  1001. struct ooh323_pvt *p = (struct ooh323_pvt *) ast->tech_pvt;
  1002. char *callToken = (char *)NULL;
  1003. int res = -1;
  1004. if (!p) return -1;
  1005. ast_mutex_lock(&p->lock);
  1006. callToken = (p->callToken ? strdup(p->callToken) : NULL);
  1007. ast_mutex_unlock(&p->lock);
  1008. if (!callToken) {
  1009. if (gH323Debug)
  1010. ast_verbose(" ooh323_indicate - No callToken\n");
  1011. return -1;
  1012. }
  1013. if (gH323Debug)
  1014. ast_verbose("----- ooh323_indicate %d on call %s\n", condition, callToken);
  1015. ast_mutex_lock(&p->lock);
  1016. switch (condition) {
  1017. case AST_CONTROL_INCOMPLETE:
  1018. /* While h323 does support overlapped dialing, this channel driver does not
  1019. * at this time. Treat a response of Incomplete as if it were congestion.
  1020. */
  1021. case AST_CONTROL_CONGESTION:
  1022. if (!ast_test_flag(p, H323_ALREADYGONE)) {
  1023. ooHangCall(callToken, OO_REASON_LOCAL_CONGESTED, AST_CAUSE_SWITCH_CONGESTION);
  1024. ast_set_flag(p, H323_ALREADYGONE);
  1025. }
  1026. break;
  1027. case AST_CONTROL_BUSY:
  1028. if (!ast_test_flag(p, H323_ALREADYGONE)) {
  1029. ooHangCall(callToken, OO_REASON_LOCAL_BUSY, AST_CAUSE_USER_BUSY);
  1030. ast_set_flag(p, H323_ALREADYGONE);
  1031. }
  1032. break;
  1033. case AST_CONTROL_HOLD:
  1034. ast_moh_start(ast, data, NULL);
  1035. break;
  1036. case AST_CONTROL_UNHOLD:
  1037. ast_moh_stop(ast);
  1038. break;
  1039. case AST_CONTROL_PROGRESS:
  1040. if (ast->_state != AST_STATE_UP) {
  1041. if (!p->progsent) {
  1042. if (gH323Debug)
  1043. ast_log(LOG_DEBUG,"Sending manual progress for %s, res = %d\n", callToken,
  1044. ooManualProgress(callToken));
  1045. else
  1046. ooManualProgress(callToken);
  1047. p->progsent = 1;
  1048. }
  1049. }
  1050. break;
  1051. case AST_CONTROL_RINGING:
  1052. if (ast->_state == AST_STATE_RING || ast->_state == AST_STATE_RINGING) {
  1053. if (!p->alertsent) {
  1054. if (gH323Debug) {
  1055. ast_debug(1, "Sending manual ringback for %s, res = %d\n",
  1056. callToken,
  1057. ooManualRingback(callToken));
  1058. } else {
  1059. ooManualRingback(callToken);
  1060. }
  1061. p->alertsent = 1;
  1062. }
  1063. }
  1064. break;
  1065. case AST_CONTROL_SRCUPDATE:
  1066. if (p->rtp) {
  1067. ast_rtp_instance_update_source(p->rtp);
  1068. }
  1069. break;
  1070. case AST_CONTROL_SRCCHANGE:
  1071. if (p->rtp) {
  1072. ast_rtp_instance_change_source(p->rtp);
  1073. }
  1074. break;
  1075. case AST_CONTROL_CONNECTED_LINE:
  1076. if (!ast->connected.id.name.valid
  1077. || ast_strlen_zero(ast->connected.id.name.str)) {
  1078. break;
  1079. }
  1080. if (gH323Debug)
  1081. ast_log(LOG_DEBUG, "Sending connected line info for %s (%s)\n",
  1082. callToken, ast->connected.id.name.str);
  1083. ooSetANI(callToken, ast->connected.id.name.str);
  1084. break;
  1085. case AST_CONTROL_T38_PARAMETERS:
  1086. if (p->t38support != T38_ENABLED) {
  1087. struct ast_control_t38_parameters parameters = { .request_response = 0 };
  1088. parameters.request_response = AST_T38_REFUSED;
  1089. ast_queue_control_data(ast, AST_CONTROL_T38_PARAMETERS,
  1090. &parameters, sizeof(parameters));
  1091. break;
  1092. }
  1093. if (datalen != sizeof(struct ast_control_t38_parameters)) {
  1094. ast_log(LOG_ERROR, "Invalid datalen for AST_CONTROL_T38. "
  1095. "Expected %d, got %d\n",
  1096. (int)sizeof(enum ast_control_t38), (int)datalen);
  1097. } else {
  1098. const struct ast_control_t38_parameters *parameters = data;
  1099. enum ast_control_t38 message = parameters->request_response;
  1100. switch (message) {
  1101. case AST_T38_REQUEST_NEGOTIATE:
  1102. if (!p->chmodepend && !p->faxmode) {
  1103. ooRequestChangeMode(p->callToken, 1);
  1104. p->chmodepend = 1;
  1105. res = 0;
  1106. }
  1107. break;
  1108. case AST_T38_REQUEST_TERMINATE:
  1109. if (!p->chmodepend && p->faxmode) {
  1110. ooRequestChangeMode(p->callToken, 0);
  1111. p->chmodepend = 1;
  1112. res = 0;
  1113. }
  1114. break;
  1115. default:
  1116. ;
  1117. }
  1118. }
  1119. break;
  1120. case AST_CONTROL_PROCEEDING:
  1121. case -1:
  1122. break;
  1123. default:
  1124. ast_log(LOG_WARNING, "Don't know how to indicate condition %d on %s\n",
  1125. condition, callToken);
  1126. }
  1127. ast_mutex_unlock(&p->lock);
  1128. if (gH323Debug)
  1129. ast_verbose("++++ ooh323_indicate %d on %s\n", condition, callToken);
  1130. free(callToken);
  1131. return res;
  1132. }
  1133. static int ooh323_queryoption(struct ast_channel *ast, int option, void *data, int *datalen)
  1134. {
  1135. struct ooh323_pvt *p = (struct ooh323_pvt *) ast->tech_pvt;
  1136. int res = -1;
  1137. enum ast_t38_state state = T38_STATE_UNAVAILABLE;
  1138. char* cp;
  1139. if (!p) return -1;
  1140. ast_mutex_lock(&p->lock);
  1141. if (gH323Debug)
  1142. ast_verbose("----- ooh323_queryoption %d on channel %s\n", option, ast->name);
  1143. switch (option) {
  1144. case AST_OPTION_T38_STATE:
  1145. if (*datalen != sizeof(enum ast_t38_state)) {
  1146. ast_log(LOG_ERROR, "Invalid datalen for AST_OPTION_T38_STATE option."
  1147. " Expected %d, got %d\n", (int)sizeof(enum ast_t38_state), *datalen);
  1148. break;
  1149. }
  1150. if (p->t38support != T38_DISABLED)
  1151. state = T38_STATE_UNKNOWN;
  1152. if (p->faxmode)
  1153. state = (p->chmodepend) ? T38_STATE_UNKNOWN : T38_STATE_NEGOTIATED;
  1154. else if (p->chmodepend)
  1155. state = T38_STATE_NEGOTIATING;
  1156. *((enum ast_t38_state *) data) = state;
  1157. res = 0;
  1158. break;
  1159. case AST_OPTION_DIGIT_DETECT:
  1160. cp = (char *) data;
  1161. *cp = p->vad ? 1 : 0;
  1162. ast_debug(1, "Reporting digit detection %sabled on %s\n",
  1163. *cp ? "en" : "dis", ast->name);
  1164. res = 0;
  1165. break;
  1166. default: ;
  1167. }
  1168. if (gH323Debug)
  1169. ast_verbose("+++++ ooh323_queryoption %d on channel %s\n", option, ast->name);
  1170. ast_mutex_unlock(&p->lock);
  1171. return res;
  1172. }
  1173. static int ooh323_fixup(struct ast_channel *oldchan, struct ast_channel *newchan)
  1174. {
  1175. struct ooh323_pvt *p = newchan->tech_pvt;
  1176. if (!p) return -1;
  1177. if (gH323Debug)
  1178. ast_verbose("--- ooh323c ooh323_fixup\n");
  1179. ast_mutex_lock(&p->lock);
  1180. if (p->owner != oldchan) {
  1181. ast_log(LOG_WARNING, "Old channel wasn't %p but was %p\n", oldchan, p->owner);
  1182. ast_mutex_unlock(&p->lock);
  1183. return -1;
  1184. }
  1185. if (p->owner == oldchan) {
  1186. p->owner = newchan;
  1187. } else {
  1188. p->owner = oldchan;
  1189. }
  1190. ast_mutex_unlock(&p->lock);
  1191. if (gH323Debug)
  1192. ast_verbose("+++ ooh323c ooh323_fixup \n");
  1193. return 0;
  1194. }
  1195. void ooh323_set_write_format(ooCallData *call, int fmt, int txframes)
  1196. {
  1197. struct ooh323_pvt *p = NULL;
  1198. char formats[FORMAT_STRING_SIZE];
  1199. if (gH323Debug)
  1200. ast_verbose("--- ooh323_update_writeformat %s/%d\n",
  1201. ast_getformatname_multiple(formats,FORMAT_STRING_SIZE, fmt), txframes);
  1202. p = find_call(call);
  1203. if (!p) {
  1204. ast_log(LOG_ERROR, "No matching call found for %s\n", call->callToken);
  1205. return;
  1206. }
  1207. ast_mutex_lock(&p->lock);
  1208. p->writeformat = fmt;
  1209. if (p->owner) {
  1210. while (p->owner && ast_channel_trylock(p->owner)) {
  1211. ast_debug(1,"Failed to grab lock, trying again\n");
  1212. DEADLOCK_AVOIDANCE(&p->lock);
  1213. }
  1214. if (!p->owner) {
  1215. ast_mutex_unlock(&p->lock);
  1216. ast_log(LOG_ERROR, "Channel has no owner\n");
  1217. return;
  1218. }
  1219. if (gH323Debug)
  1220. ast_verbose("Writeformat before update %s/%s\n",
  1221. ast_getformatname_multiple(formats,FORMAT_STRING_SIZE, p->owner->writeformat),
  1222. ast_getformatname_multiple(formats,FORMAT_STRING_SIZE, p->owner->nativeformats));
  1223. if (txframes)
  1224. ast_codec_pref_setsize(&p->prefs, fmt, txframes);
  1225. ast_rtp_codecs_packetization_set(ast_rtp_instance_get_codecs(p->rtp), p->rtp, &p->prefs);
  1226. if (p->dtmfmode & H323_DTMF_RFC2833 && p->dtmfcodec) {
  1227. ast_rtp_codecs_payloads_set_rtpmap_type(ast_rtp_instance_get_codecs(p->rtp),
  1228. p->rtp, p->dtmfcodec, "audio", "telephone-event", 0);
  1229. }
  1230. if (p->dtmfmode & H323_DTMF_CISCO && p->dtmfcodec) {
  1231. ast_rtp_codecs_payloads_set_rtpmap_type(ast_rtp_instance_get_codecs(p->rtp),
  1232. p->rtp, p->dtmfcodec, "audio", "cisco-telephone-event", 0);
  1233. }
  1234. p->owner->nativeformats = fmt;
  1235. ast_set_write_format(p->owner, p->owner->writeformat);
  1236. ast_set_read_format(p->owner, p->owner->readformat);
  1237. ast_channel_unlock(p->owner);
  1238. } else
  1239. ast_log(LOG_ERROR, "No owner found\n");
  1240. ast_mutex_unlock(&p->lock);
  1241. if (gH323Debug)
  1242. ast_verbose("+++ ooh323_update_writeformat\n");
  1243. }
  1244. void ooh323_set_read_format(ooCallData *call, int fmt)
  1245. {
  1246. struct ooh323_pvt *p = NULL;
  1247. char formats[FORMAT_STRING_SIZE];
  1248. if (gH323Debug)
  1249. ast_verbose("--- ooh323_update_readformat %s\n",
  1250. ast_getformatname_multiple(formats,FORMAT_STRING_SIZE, fmt));
  1251. p = find_call(call);
  1252. if (!p) {
  1253. ast_log(LOG_ERROR, "No matching call found for %s\n", call->callToken);
  1254. return;
  1255. }
  1256. ast_mutex_lock(&p->lock);
  1257. p->readformat = fmt;
  1258. if (p->owner) {
  1259. while (p->owner && ast_channel_trylock(p->owner)) {
  1260. ast_debug(1,"Failed to grab lock, trying again\n");
  1261. DEADLOCK_AVOIDANCE(&p->lock);
  1262. }
  1263. if (!p->owner) {
  1264. ast_mutex_unlock(&p->lock);
  1265. ast_log(LOG_ERROR, "Channel has no owner\n");
  1266. return;
  1267. }
  1268. if (gH323Debug)
  1269. ast_verbose("Readformat before update %s\n",
  1270. ast_getformatname_multiple(formats,FORMAT_STRING_SIZE, p->owner->readformat));
  1271. p->owner->nativeformats = fmt;
  1272. ast_set_read_format(p->owner, p->owner->readformat);
  1273. ast_channel_unlock(p->owner);
  1274. } else
  1275. ast_log(LOG_ERROR, "No owner found\n");
  1276. ast_mutex_unlock(&p->lock);
  1277. if (gH323Debug)
  1278. ast_verbose("+++ ooh323_update_readformat\n");
  1279. }
  1280. int onAlerting(ooCallData *call)
  1281. {
  1282. struct ooh323_pvt *p = NULL;
  1283. struct ast_channel *c = NULL;
  1284. if (gH323Debug)
  1285. ast_verbose("--- onAlerting %s\n", call->callToken);
  1286. p = find_call(call);
  1287. if(!p) {
  1288. ast_log(LOG_ERROR, "No matching call found\n");
  1289. return -1;
  1290. }
  1291. ast_mutex_lock(&p->lock);
  1292. if (!p->owner) {
  1293. ast_mutex_unlock(&p->lock);
  1294. ast_log(LOG_ERROR, "Channel has no owner\n");
  1295. return 0;
  1296. }
  1297. while (p->owner && ast_channel_trylock(p->owner)) {
  1298. ast_debug(1,"Failed to grab lock, trying again\n");
  1299. DEADLOCK_AVOIDANCE(&p->lock);
  1300. }
  1301. if (!p->owner) {
  1302. ast_mutex_unlock(&p->lock);
  1303. ast_log(LOG_ERROR, "Channel has no owner\n");
  1304. return 0;
  1305. }
  1306. c = p->owner;
  1307. if (call->remoteDisplayName) {
  1308. struct ast_party_connected_line connected;
  1309. struct ast_set_party_connected_line update_connected;
  1310. memset(&update_connected, 0, sizeof(update_connected));
  1311. update_connected.id.name = 1;
  1312. ast_party_connected_line_init(&connected);
  1313. connected.id.name.valid = 1;
  1314. connected.id.name.str = (char *) call->remoteDisplayName;
  1315. connected.source = AST_CONNECTED_LINE_UPDATE_SOURCE_ANSWER;
  1316. ast_channel_queue_connected_line_update(c, &connected, &update_connected);
  1317. }
  1318. if (c->_state != AST_STATE_UP)
  1319. ast_setstate(c, AST_STATE_RINGING);
  1320. ast_queue_control(c, AST_CONTROL_RINGING);
  1321. ast_channel_unlock(c);
  1322. ast_mutex_unlock(&p->lock);
  1323. if (gH323Debug)
  1324. ast_verbose("+++ onAlerting %s\n", call->callToken);
  1325. return OO_OK;
  1326. }
  1327. int onProgress(ooCallData *call)
  1328. {
  1329. struct ooh323_pvt *p = NULL;
  1330. struct ast_channel *c = NULL;
  1331. if (gH323Debug)
  1332. ast_verbose("--- onProgress %s\n", call->callToken);
  1333. p = find_call(call);
  1334. if(!p) {
  1335. ast_log(LOG_ERROR, "No matching call found\n");
  1336. return -1;
  1337. }
  1338. ast_mutex_lock(&p->lock);
  1339. if (!p->owner) {
  1340. ast_mutex_unlock(&p->lock);
  1341. ast_log(LOG_ERROR, "Channel has no owner\n");
  1342. return 0;
  1343. }
  1344. while (p->owner && ast_channel_trylock(p->owner)) {
  1345. ast_debug(1,"Failed to grab lock, trying again\n");
  1346. DEADLOCK_AVOIDANCE(&p->lock);
  1347. }
  1348. if (!p->owner) {
  1349. ast_mutex_unlock(&p->lock);
  1350. ast_log(LOG_ERROR, "Channel has no owner\n");
  1351. return 0;
  1352. }
  1353. c = p->owner;
  1354. if (call->remoteDisplayName) {
  1355. struct ast_party_connected_line connected;
  1356. struct ast_set_party_connected_line update_connected;
  1357. memset(&update_connected, 0, sizeof(update_connected));
  1358. update_connected.id.name = 1;
  1359. ast_party_connected_line_init(&connected);
  1360. connected.id.name.valid = 1;
  1361. connected.id.name.str = (char *) call->remoteDisplayName;
  1362. connected.source = AST_CONNECTED_LINE_UPDATE_SOURCE_ANSWER;
  1363. ast_channel_queue_connected_line_update(c, &connected, &update_connected);
  1364. }
  1365. if (c->_state != AST_STATE_UP)
  1366. ast_setstate(c, AST_STATE_RINGING);
  1367. ast_queue_control(c, AST_CONTROL_PROGRESS);
  1368. ast_channel_unlock(c);
  1369. ast_mutex_unlock(&p->lock);
  1370. if (gH323Debug)
  1371. ast_verbose("+++ onProgress %s\n", call->callToken);
  1372. return OO_OK;
  1373. }
  1374. /**
  1375. * Callback for sending digits from H.323 up to asterisk
  1376. *
  1377. */
  1378. int ooh323_onReceivedDigit(OOH323CallData *call, const char *digit)
  1379. {
  1380. struct ooh323_pvt *p = NULL;
  1381. struct ast_frame f;
  1382. int res;
  1383. ast_debug(1, "Received Digit: %c\n", digit[0]);
  1384. p = find_call(call);
  1385. if (!p) {
  1386. ast_log(LOG_ERROR, "Failed to find a matching call.\n");
  1387. return -1;
  1388. }
  1389. if (!p->owner) {
  1390. ast_log(LOG_ERROR, "Channel has no owner\n");
  1391. return -1;
  1392. }
  1393. ast_mutex_lock(&p->lock);
  1394. memset(&f, 0, sizeof(f));
  1395. f.frametype = AST_FRAME_DTMF;
  1396. f.subclass.integer = digit[0];
  1397. f.datalen = 0;
  1398. f.samples = 800;
  1399. f.offset = 0;
  1400. f.data.ptr = NULL;
  1401. f.mallocd = 0;
  1402. f.src = "SEND_DIGIT";
  1403. while (p->owner && ast_channel_trylock(p->owner)) {
  1404. ast_debug(1,"Failed to grab lock, trying again\n");
  1405. DEADLOCK_AVOIDANCE(&p->lock);
  1406. }
  1407. if (!p->owner) {
  1408. ast_mutex_unlock(&p->lock);
  1409. ast_log(LOG_ERROR, "Channel has no owner\n");
  1410. return 0;
  1411. }
  1412. res = ast_queue_frame(p->owner, &f);
  1413. ast_channel_unlock(p->owner);
  1414. ast_mutex_unlock(&p->lock);
  1415. return res;
  1416. }
  1417. int ooh323_onReceivedSetup(ooCallData *call, Q931Message *pmsg)
  1418. {
  1419. struct ooh323_pvt *p = NULL;
  1420. struct ooh323_user *user = NULL;
  1421. struct ast_channel *c = NULL;
  1422. ooAliases *alias = NULL;
  1423. char *at = NULL;
  1424. char number [OO_MAX_NUMBER_LENGTH];
  1425. if (gH323Debug)
  1426. ast_verbose("--- ooh323_onReceivedSetup %s\n", call->callToken);
  1427. if (!(p = ooh323_alloc(call->callReference, call->callToken))) {
  1428. ast_log(LOG_ERROR, "Failed to create a new call.\n");
  1429. return -1;
  1430. }
  1431. ast_mutex_lock(&p->lock);
  1432. ast_clear_flag(p, H323_OUTGOING);
  1433. if (call->remoteDisplayName) {
  1434. p->callerid_name = strdup(call->remoteDisplayName);
  1435. }
  1436. if (ooCallGetCallingPartyNumber(call, number, OO_MAX_NUMBER_LENGTH) == OO_OK) {
  1437. p->callerid_num = strdup(number);
  1438. }
  1439. if (call->remoteAliases) {
  1440. for (alias = call->remoteAliases; alias; alias = alias->next) {
  1441. if (alias->type == T_H225AliasAddress_h323_ID) {
  1442. if (!p->callerid_name) {
  1443. p->callerid_name = strdup(alias->value);
  1444. }
  1445. ast_copy_string(p->caller_h323id, alias->value, sizeof(p->caller_h323id));
  1446. }
  1447. else if(alias->type == T_H225AliasAddress_dialedDigits)
  1448. {
  1449. if(!p->callerid_num)
  1450. p->callerid_num = strdup(alias->value);
  1451. ast_copy_string(p->caller_dialedDigits, alias->value,
  1452. sizeof(p->caller_dialedDigits));
  1453. }
  1454. else if(alias->type == T_H225AliasAddress_email_ID)
  1455. {
  1456. ast_copy_string(p->caller_email, alias->value, sizeof(p->caller_email));
  1457. }
  1458. else if(alias->type == T_H225AliasAddress_url_ID)
  1459. {
  1460. ast_copy_string(p->caller_url, alias->value, sizeof(p->caller_url));
  1461. }
  1462. }
  1463. }
  1464. number[0] = '\0';
  1465. if(ooCallGetCalledPartyNumber(call, number, OO_MAX_NUMBER_LENGTH)== OO_OK) {
  1466. strncpy(p->exten, number, sizeof(p->exten)-1);
  1467. } else {
  1468. update_our_aliases(call, p);
  1469. if (!ast_strlen_zero(p->callee_dialedDigits)) {
  1470. ast_copy_string(p->exten, p->callee_dialedDigits, sizeof(p->exten));
  1471. } else if(!ast_strlen_zero(p->callee_h323id)) {
  1472. ast_copy_string(p->exten, p->callee_h323id, sizeof(p->exten));
  1473. } else if(!ast_strlen_zero(p->callee_email)) {
  1474. ast_copy_string(p->exten, p->callee_email, sizeof(p->exten));
  1475. if ((at = strchr(p->exten, '@'))) {
  1476. *at = '\0';
  1477. }
  1478. }
  1479. }
  1480. /* if no extension found, set to default 's' */
  1481. if (ast_strlen_zero(p->exten)) {
  1482. p->exten[0]='s';
  1483. p->exten[1]='\0';
  1484. }
  1485. user = find_user(p->callerid_name, call->remoteIP);
  1486. if(user && (user->incominglimit == 0 || user->inUse < user->incominglimit)) {
  1487. ast_mutex_lock(&user->lock);
  1488. p->username = strdup(user->name);
  1489. p->neighbor.user = user->mUseIP ? ast_strdup(user->mIP) :
  1490. ast_strdup(user->name);
  1491. ast_copy_string(p->context, user->context, sizeof(p->context));
  1492. ast_copy_string(p->accountcode, user->accountcode, sizeof(p->accountcode));
  1493. p->amaflags = user->amaflags;
  1494. p->capability = user->capability;
  1495. p->g729onlyA = user->g729onlyA;
  1496. memcpy(&p->prefs, &user->prefs, sizeof(struct ast_codec_pref));
  1497. p->dtmfmode |= user->dtmfmode;
  1498. p->dtmfcodec = user->dtmfcodec;
  1499. p->t38support = user->t38support;
  1500. p->rtptimeout = user->rtptimeout;
  1501. p->h245tunneling = user->h245tunneling;
  1502. p->faststart = user->faststart;
  1503. if (p->faststart)
  1504. OO_SETFLAG(call->flags, OO_M_FASTSTART);
  1505. else
  1506. OO_CLRFLAG(call->flags, OO_M_FASTSTART);
  1507. /* if we disable h245tun for this user then we clear flag */
  1508. /* in any other case we don't must touch this */
  1509. /* ie if we receive setup without h245tun but enabled
  1510. we can't enable it per call */
  1511. if (!p->h245tunneling)
  1512. OO_CLRFLAG(call->flags, OO_M_TUNNELING);
  1513. if (user->rtpmask && user->rtpmaskstr[0]) {
  1514. p->rtpmask = user->rtpmask;
  1515. ast_copy_string(p->rtpmaskstr, user->rtpmaskstr,
  1516. sizeof(p->rtpmaskstr));
  1517. }
  1518. if (user->rtdrcount > 0 && user->rtdrinterval > 0) {
  1519. p->rtdrcount = user->rtdrcount;
  1520. p->rtdrinterval = user->rtdrinterval;
  1521. }
  1522. if (user->incominglimit) user->inUse++;
  1523. ast_mutex_unlock(&user->lock);
  1524. } else {
  1525. if (!OO_TESTFLAG(p->flags,H323_DISABLEGK)) {
  1526. p->username = strdup(call->remoteIP);
  1527. } else {
  1528. ast_mutex_unlock(&p->lock);
  1529. ast_log(LOG_ERROR, "Unacceptable ip %s\n", call->remoteIP);
  1530. if (!user)
  1531. ooHangCall(call->callToken, ooh323_convert_hangupcause_asteriskToH323(AST_CAUSE_CALL_REJECTED), AST_CAUSE_CALL_REJECTED);
  1532. else
  1533. ooHangCall(call->callToken, ooh323_convert_hangupcause_asteriskToH323(AST_CAUSE_NORMAL_CIRCUIT_CONGESTION), AST_CAUSE_NORMAL_CIRCUIT_CONGESTION);
  1534. ast_set_flag(p, H323_NEEDDESTROY);
  1535. return -1;
  1536. }
  1537. }
  1538. ooh323c_set_capability_for_call(call, &p->prefs, p->capability, p->dtmfmode, p->dtmfcodec,
  1539. p->t38support, p->g729onlyA);
  1540. configure_local_rtp(p, call);
  1541. /* Incoming call */
  1542. c = ooh323_new(p, AST_STATE_RING, p->username, 0, NULL);
  1543. if(!c) {
  1544. ast_mutex_unlock(&p->lock);
  1545. ast_log(LOG_ERROR, "Could not create ast_channel\n");
  1546. return -1;
  1547. }
  1548. ast_mutex_unlock(&p->lock);
  1549. if (gH323Debug)
  1550. ast_verbose("+++ ooh323_onReceivedSetup - Determined context %s, "
  1551. "extension %s\n", p->context, p->exten);
  1552. return OO_OK;
  1553. }
  1554. int onOutgoingCall(ooCallData *call)
  1555. {
  1556. struct ooh323_pvt *p = NULL;
  1557. int i = 0;
  1558. if (gH323Debug)
  1559. ast_verbose("--- onOutgoingCall %lx: %s\n", (long unsigned int) call, call->callToken);
  1560. if (!strcmp(call->callType, "outgoing")) {
  1561. p = find_call(call);
  1562. if (!p) {
  1563. ast_log(LOG_ERROR, "Failed to find a matching call.\n");
  1564. return -1;
  1565. }
  1566. ast_mutex_lock(&p->lock);
  1567. if (!ast_strlen_zero(p->callerid_name)) {
  1568. ooCallSetCallerId(call, p->callerid_name);
  1569. }
  1570. if (!ast_strlen_zero(p->callerid_num)) {
  1571. i = 0;
  1572. while (*(p->callerid_num + i) != '\0') {
  1573. if(!isdigit(*(p->callerid_num+i))) { break; }
  1574. i++;
  1575. }
  1576. if(*(p->callerid_num+i) == '\0')
  1577. ooCallSetCallingPartyNumber(call, p->callerid_num);
  1578. else {
  1579. if(!p->callerid_name)
  1580. ooCallSetCallerId(call, p->callerid_num);
  1581. }
  1582. }
  1583. if (!ast_strlen_zero(p->caller_h323id))
  1584. ooCallAddAliasH323ID(call, p->caller_h323id);
  1585. if (!ast_strlen_zero(p->caller_dialedDigits)) {
  1586. if (gH323Debug) {
  1587. ast_verbose("Setting dialed digits %s\n", p->caller_dialedDigits);
  1588. }
  1589. ooCallAddAliasDialedDigits(call, p->caller_dialedDigits);
  1590. } else if (!ast_strlen_zero(p->callerid_num)) {
  1591. if (ooIsDailedDigit(p->callerid_num)) {
  1592. if (gH323Debug) {
  1593. ast_verbose("setting callid number %s\n", p->callerid_num);
  1594. }
  1595. ooCallAddAliasDialedDigits(call, p->callerid_num);
  1596. } else if (ast_strlen_zero(p->caller_h323id)) {
  1597. ooCallAddAliasH323ID(call, p->callerid_num);
  1598. }
  1599. }
  1600. if (p->rtpmask && p->rtpmaskstr[0]) {
  1601. call->rtpMask = p->rtpmask;
  1602. ast_mutex_lock(&call->rtpMask->lock);
  1603. call->rtpMask->inuse++;
  1604. ast_mutex_unlock(&call->rtpMask->lock);
  1605. ast_copy_string(call->rtpMaskStr, p->rtpmaskstr, sizeof(call->rtpMaskStr));
  1606. }
  1607. ast_mutex_unlock(&p->lock);
  1608. }
  1609. if (gH323Debug)
  1610. ast_verbose("+++ onOutgoingCall %s\n", call->callToken);
  1611. return OO_OK;
  1612. }
  1613. int onNewCallCreated(ooCallData *call)
  1614. {
  1615. struct ooh323_pvt *p = NULL;
  1616. int i = 0;
  1617. if (gH323Debug)
  1618. ast_verbose("--- onNewCallCreated %lx: %s\n", (long unsigned int) call, call->callToken);
  1619. ast_mutex_lock(&call->Lock);
  1620. if (ooh323c_start_call_thread(call)) {
  1621. ast_log(LOG_ERROR,"Failed to create call thread.\n");
  1622. ast_mutex_unlock(&call->Lock);
  1623. return -1;
  1624. }
  1625. if (!strcmp(call->callType, "outgoing")) {
  1626. p = find_call(call);
  1627. if (!p) {
  1628. ast_log(LOG_ERROR, "Failed to find a matching call.\n");
  1629. ast_mutex_unlock(&call->Lock);
  1630. return -1;
  1631. }
  1632. ast_mutex_lock(&p->lock);
  1633. if (!ast_strlen_zero(p->callerid_name)) {
  1634. ooCallSetCallerId(call, p->callerid_name);
  1635. }
  1636. if (!ast_strlen_zero(p->callerid_num)) {
  1637. i = 0;
  1638. while (*(p->callerid_num + i) != '\0') {
  1639. if(!isdigit(*(p->callerid_num+i))) { break; }
  1640. i++;
  1641. }
  1642. if(*(p->callerid_num+i) == '\0')
  1643. ooCallSetCallingPartyNumber(call, p->callerid_num);
  1644. else {
  1645. if(ast_strlen_zero(p->callerid_name))
  1646. ooCallSetCallerId(call, p->callerid_num);
  1647. }
  1648. }
  1649. if (!ast_strlen_zero(p->caller_h323id))
  1650. ooCallAddAliasH323ID(call, p->caller_h323id);
  1651. if (!ast_strlen_zero(p->caller_dialedDigits)) {
  1652. if (gH323Debug) {
  1653. ast_verbose("Setting dialed digits %s\n", p->caller_dialedDigits);
  1654. }
  1655. ooCallAddAliasDialedDigits(call, p->caller_dialedDigits);
  1656. } else if (!ast_strlen_zero(p->callerid_num)) {
  1657. if (ooIsDailedDigit(p->callerid_num)) {
  1658. if (gH323Debug) {
  1659. ast_verbose("setting callid number %s\n", p->callerid_num);
  1660. }
  1661. ooCallAddAliasDialedDigits(call, p->callerid_num);
  1662. } else if (ast_strlen_zero(p->caller_h323id)) {
  1663. ooCallAddAliasH323ID(call, p->callerid_num);
  1664. }
  1665. }
  1666. if (!ast_strlen_zero(p->exten)) {
  1667. if (ooIsDailedDigit(p->exten)) {
  1668. ooCallSetCalledPartyNumber(call, p->exten);
  1669. ooCallAddRemoteAliasDialedDigits(call, p->exten);
  1670. } else {
  1671. ooCallAddRemoteAliasH323ID(call, p->exten);
  1672. }
  1673. }
  1674. if (gH323Debug) {
  1675. char prefsBuf[256];
  1676. ast_codec_pref_string(&p->prefs, prefsBuf, sizeof(prefsBuf));
  1677. ast_verbose(" Outgoing call %s(%s) - Codec prefs - %s\n",
  1678. p->username?p->username:"NULL", call->callToken, prefsBuf);
  1679. }
  1680. ooh323c_set_capability_for_call(call, &p->prefs, p->capability,
  1681. p->dtmfmode, p->dtmfcodec, p->t38support, p->g729onlyA);
  1682. configure_local_rtp(p, call);
  1683. ast_mutex_unlock(&p->lock);
  1684. }
  1685. ast_mutex_unlock(&call->Lock);
  1686. if (gH323Debug)
  1687. ast_verbose("+++ onNewCallCreated %s\n", call->callToken);
  1688. return OO_OK;
  1689. }
  1690. int onCallEstablished(ooCallData *call)
  1691. {
  1692. struct ooh323_pvt *p = NULL;
  1693. if (gH323Debug)
  1694. ast_verbose("--- onCallEstablished %s\n", call->callToken);
  1695. if (!(p = find_call(call))) {
  1696. ast_log(LOG_ERROR, "Failed to find a matching call.\n");
  1697. return -1;
  1698. }
  1699. if(ast_test_flag(p, H323_OUTGOING)) {
  1700. ast_mutex_lock(&p->lock);
  1701. if (!p->owner) {
  1702. ast_mutex_unlock(&p->lock);
  1703. ast_log(LOG_ERROR, "Channel has no owner\n");
  1704. return -1;
  1705. }
  1706. while (p->owner && ast_channel_trylock(p->owner)) {
  1707. ast_debug(1,"Failed to grab lock, trying again\n");
  1708. DEADLOCK_AVOIDANCE(&p->lock);
  1709. }
  1710. if (p->owner) {
  1711. struct ast_channel* c = p->owner;
  1712. if (call->remoteDisplayName) {
  1713. struct ast_party_connected_line connected;
  1714. struct ast_set_party_connected_line update_connected;
  1715. memset(&update_connected, 0, sizeof(update_connected));
  1716. update_connected.id.name = 1;
  1717. ast_party_connected_line_init(&connected);
  1718. connected.id.name.valid = 1;
  1719. connected.id.name.str = (char *) call->remoteDisplayName;
  1720. connected.source = AST_CONNECTED_LINE_UPDATE_SOURCE_ANSWER;
  1721. ast_channel_queue_connected_line_update(c, &connected, &update_connected);
  1722. }
  1723. ast_queue_control(c, AST_CONTROL_ANSWER);
  1724. ast_channel_unlock(p->owner);
  1725. manager_event(EVENT_FLAG_SYSTEM,"ChannelUpdate","Channel: %s\r\nChanneltype: %s\r\n"
  1726. "CallRef: %d\r\n", c->name, "OOH323", p->call_reference);
  1727. }
  1728. ast_mutex_unlock(&p->lock);
  1729. }
  1730. if (gH323Debug)
  1731. ast_verbose("+++ onCallEstablished %s\n", call->callToken);
  1732. return OO_OK;
  1733. }
  1734. int onCallCleared(ooCallData *call)
  1735. {
  1736. struct ooh323_pvt *p = NULL;
  1737. int ownerLock = 0;
  1738. if (gH323Debug)
  1739. ast_verbose("--- onCallCleared %s \n", call->callToken);
  1740. if ((p = find_call(call))) {
  1741. ast_mutex_lock(&p->lock);
  1742. while (p->owner) {
  1743. if (ast_channel_trylock(p->owner)) {
  1744. ooTrace(OOTRCLVLINFO, "Failed to grab lock, trying again\n");
  1745. ast_log(LOG_DEBUG,"Failed to grab lock, trying again\n");
  1746. DEADLOCK_AVOIDANCE(&p->lock);
  1747. } else {
  1748. ownerLock = 1; break;
  1749. }
  1750. }
  1751. if (ownerLock) {
  1752. if (!ast_test_flag(p, H323_ALREADYGONE)) {
  1753. ast_set_flag(p, H323_ALREADYGONE);
  1754. p->owner->hangupcause = call->q931cause;
  1755. p->owner->_softhangup |= AST_SOFTHANGUP_DEV;
  1756. ast_queue_hangup_with_cause(p->owner,call->q931cause);
  1757. }
  1758. }
  1759. if(p->owner) {
  1760. p->owner->tech_pvt = NULL;
  1761. ast_channel_unlock(p->owner);
  1762. p->owner = NULL;
  1763. ast_module_unref(myself);
  1764. }
  1765. ast_set_flag(p, H323_NEEDDESTROY);
  1766. ooh323c_stop_call_thread(call);
  1767. ast_mutex_unlock(&p->lock);
  1768. ast_mutex_lock(&usecnt_lock);
  1769. usecnt--;
  1770. ast_mutex_unlock(&usecnt_lock);
  1771. }
  1772. if (gH323Debug)
  1773. ast_verbose("+++ onCallCleared\n");
  1774. return OO_OK;
  1775. }
  1776. /* static void ooh323_delete_user(struct ooh323_user *user)
  1777. {
  1778. struct ooh323_user *prev = NULL, *cur = NULL;
  1779. if (gH323Debug)
  1780. ast_verbose("--- ooh323_delete_user\n");
  1781. if (user) {
  1782. cur = userl.users;
  1783. ast_mutex_lock(&userl.lock);
  1784. while (cur) {
  1785. if (cur == user) break;
  1786. prev = cur;
  1787. cur = cur->next;
  1788. }
  1789. if (cur) {
  1790. if (prev)
  1791. prev->next = cur->next;
  1792. else
  1793. userl.users = cur->next;
  1794. }
  1795. ast_mutex_unlock(&userl.lock);
  1796. free(user);
  1797. }
  1798. if (gH323Debug)
  1799. ast_verbose("+++ ooh323_delete_user\n");
  1800. } */
  1801. void ooh323_delete_peer(struct ooh323_peer *peer)
  1802. {
  1803. struct ooh323_peer *prev = NULL, *cur = NULL;
  1804. if (gH323Debug)
  1805. ast_verbose("--- ooh323_delete_peer\n");
  1806. if (peer) {
  1807. cur = peerl.peers;
  1808. ast_mutex_lock(&peerl.lock);
  1809. while(cur) {
  1810. if(cur==peer) break;
  1811. prev = cur;
  1812. cur = cur->next;
  1813. }
  1814. if (cur) {
  1815. if(prev)
  1816. prev->next = cur->next;
  1817. else
  1818. peerl.peers = cur->next;
  1819. }
  1820. ast_mutex_unlock(&peerl.lock);
  1821. if(peer->h323id) free(peer->h323id);
  1822. if(peer->email) free(peer->email);
  1823. if(peer->url) free(peer->url);
  1824. if(peer->e164) free(peer->e164);
  1825. free(peer);
  1826. }
  1827. if (gH323Debug)
  1828. ast_verbose("+++ ooh323_delete_peer\n");
  1829. }
  1830. static struct ooh323_user *build_user(const char *name, struct ast_variable *v)
  1831. {
  1832. struct ooh323_user *user = NULL;
  1833. if (gH323Debug)
  1834. ast_verbose("--- build_user\n");
  1835. user = ast_calloc(1,sizeof(struct ooh323_user));
  1836. if (user) {
  1837. memset(user, 0, sizeof(struct ooh323_user));
  1838. ast_mutex_init(&user->lock);
  1839. ast_copy_string(user->name, name, sizeof(user->name));
  1840. user->capability = gCapability;
  1841. memcpy(&user->prefs, &gPrefs, sizeof(user->prefs));
  1842. user->rtptimeout = gRTPTimeout;
  1843. user->dtmfmode = gDTMFMode;
  1844. user->dtmfcodec = gDTMFCodec;
  1845. user->t38support = gT38Support;
  1846. user->faststart = gFastStart;
  1847. user->h245tunneling = gTunneling;
  1848. user->g729onlyA = g729onlyA;
  1849. /* set default context */
  1850. ast_copy_string(user->context, gContext, sizeof(user->context));
  1851. ast_copy_string(user->accountcode, gAccountcode, sizeof(user->accountcode));
  1852. user->amaflags = gAMAFLAGS;
  1853. while (v) {
  1854. if (!strcasecmp(v->name, "context")) {
  1855. ast_copy_string(user->context, v->value, sizeof(user->context));
  1856. } else if (!strcasecmp(v->name, "incominglimit")) {
  1857. user->incominglimit = atoi(v->value);
  1858. if (user->incominglimit < 0)
  1859. user->incominglimit = 0;
  1860. } else if (!strcasecmp(v->name, "accountcode")) {
  1861. strncpy(user->accountcode, v->value,
  1862. sizeof(user->accountcode)-1);
  1863. } else if (!strcasecmp(v->name, "roundtrip")) {
  1864. sscanf(v->value, "%d,%d", &user->rtdrcount, &user->rtdrinterval);
  1865. } else if (!strcasecmp(v->name, "faststart")) {
  1866. user->faststart = ast_true(v->value);
  1867. } else if (!strcasecmp(v->name, "h245tunneling")) {
  1868. user->h245tunneling = ast_true(v->value);
  1869. } else if (!strcasecmp(v->name, "g729onlyA")) {
  1870. user->g729onlyA = ast_true(v->value);
  1871. } else if (!strcasecmp(v->name, "rtptimeout")) {
  1872. user->rtptimeout = atoi(v->value);
  1873. if (user->rtptimeout < 0)
  1874. user->rtptimeout = gRTPTimeout;
  1875. } else if (!strcasecmp(v->name, "rtpmask")) {
  1876. if ((user->rtpmask = malloc(sizeof(struct OOH323Regex))) &&
  1877. (regcomp(&user->rtpmask->regex, v->value, REG_EXTENDED)
  1878. == 0)) {
  1879. ast_mutex_init(&user->rtpmask->lock);
  1880. user->rtpmask->inuse = 1;
  1881. ast_copy_string(user->rtpmaskstr, v->value,
  1882. sizeof(user->rtpmaskstr));
  1883. } else user->rtpmask = NULL;
  1884. } else if (!strcasecmp(v->name, "disallow")) {
  1885. ast_parse_allow_disallow(&user->prefs,
  1886. &user->capability, v->value, 0);
  1887. } else if (!strcasecmp(v->name, "allow")) {
  1888. const char* tcodecs = v->value;
  1889. if (!strcasecmp(v->value, "all")) {
  1890. tcodecs = "ulaw,alaw,g729,g723,gsm";
  1891. }
  1892. ast_parse_allow_disallow(&user->prefs,
  1893. &user->capability, tcodecs, 1);
  1894. } else if (!strcasecmp(v->name, "amaflags")) {
  1895. user->amaflags = ast_cdr_amaflags2int(v->value);
  1896. } else if (!strcasecmp(v->name, "ip")) {
  1897. strncpy(user->mIP, v->value, sizeof(user->mIP)-1);
  1898. user->mUseIP = 1;
  1899. } else if (!strcasecmp(v->name, "host")) {
  1900. strncpy(user->mIP, v->value, sizeof(user->mIP)-1);
  1901. user->mUseIP = 1;
  1902. } else if (!strcasecmp(v->name, "dtmfmode")) {
  1903. if (!strcasecmp(v->value, "rfc2833"))
  1904. user->dtmfmode = H323_DTMF_RFC2833;
  1905. if (!strcasecmp(v->value, "cisco"))
  1906. user->dtmfmode = H323_DTMF_CISCO;
  1907. else if (!strcasecmp(v->value, "q931keypad"))
  1908. user->dtmfmode = H323_DTMF_Q931;
  1909. else if (!strcasecmp(v->value, "h245alphanumeric"))
  1910. user->dtmfmode = H323_DTMF_H245ALPHANUMERIC;
  1911. else if (!strcasecmp(v->value, "h245signal"))
  1912. user->dtmfmode = H323_DTMF_H245SIGNAL;
  1913. else if (!strcasecmp(v->value, "inband"))
  1914. user->dtmfmode = H323_DTMF_INBAND;
  1915. } else if (!strcasecmp(v->name, "relaxdtmf")) {
  1916. user->dtmfmode |= ast_true(v->value) ? H323_DTMF_INBANDRELAX : 0;
  1917. } else if (!strcasecmp(v->name, "dtmfcodec") && atoi(v->value)) {
  1918. user->dtmfcodec = atoi(v->value);
  1919. } else if (!strcasecmp(v->name, "t38support")) {
  1920. if (!strcasecmp(v->value, "disabled"))
  1921. user->t38support = T38_DISABLED;
  1922. if (!strcasecmp(v->value, "no"))
  1923. user->t38support = T38_DISABLED;
  1924. else if (!strcasecmp(v->value, "faxgw"))
  1925. user->t38support = T38_FAXGW;
  1926. else if (!strcasecmp(v->value, "yes"))
  1927. user->t38support = T38_ENABLED;
  1928. }
  1929. v = v->next;
  1930. }
  1931. }
  1932. if (gH323Debug)
  1933. ast_verbose("+++ build_user\n");
  1934. return user;
  1935. }
  1936. static struct ooh323_peer *build_peer(const char *name, struct ast_variable *v, int friend_type)
  1937. {
  1938. struct ooh323_peer *peer = NULL;
  1939. if (gH323Debug)
  1940. ast_verbose("--- build_peer\n");
  1941. peer = ast_calloc(1, sizeof(*peer));
  1942. if (peer) {
  1943. memset(peer, 0, sizeof(struct ooh323_peer));
  1944. ast_mutex_init(&peer->lock);
  1945. ast_copy_string(peer->name, name, sizeof(peer->name));
  1946. peer->capability = gCapability;
  1947. memcpy(&peer->prefs, &gPrefs, sizeof(peer->prefs));
  1948. peer->rtptimeout = gRTPTimeout;
  1949. ast_copy_string(peer->accountcode, gAccountcode, sizeof(peer->accountcode));
  1950. peer->amaflags = gAMAFLAGS;
  1951. peer->dtmfmode = gDTMFMode;
  1952. peer->dtmfcodec = gDTMFCodec;
  1953. peer->t38support = gT38Support;
  1954. peer->faststart = gFastStart;
  1955. peer->h245tunneling = gTunneling;
  1956. peer->g729onlyA = g729onlyA;
  1957. peer->port = 1720;
  1958. if (0 == friend_type) {
  1959. peer->mFriend = 1;
  1960. }
  1961. while (v) {
  1962. if (!strcasecmp(v->name, "h323id")) {
  1963. if (!(peer->h323id = ast_strdup(v->value))) {
  1964. ast_log(LOG_ERROR, "Could not allocate memory for h323id of "
  1965. "peer %s\n", name);
  1966. ooh323_delete_peer(peer);
  1967. return NULL;
  1968. }
  1969. } else if (!strcasecmp(v->name, "e164")) {
  1970. if (!(peer->e164 = ast_strdup(v->value))) {
  1971. ast_log(LOG_ERROR, "Could not allocate memory for e164 of "
  1972. "peer %s\n", name);
  1973. ooh323_delete_peer(peer);
  1974. return NULL;
  1975. }
  1976. } else if (!strcasecmp(v->name, "email")) {
  1977. if (!(peer->email = ast_strdup(v->value))) {
  1978. ast_log(LOG_ERROR, "Could not allocate memory for email of "
  1979. "peer %s\n", name);
  1980. ooh323_delete_peer(peer);
  1981. return NULL;
  1982. }
  1983. } else if (!strcasecmp(v->name, "url")) {
  1984. if (!(peer->url = ast_strdup(v->value))) {
  1985. ast_log(LOG_ERROR, "Could not allocate memory for h323id of "
  1986. "peer %s\n", name);
  1987. ooh323_delete_peer(peer);
  1988. return NULL;
  1989. }
  1990. } else if (!strcasecmp(v->name, "port")) {
  1991. peer->port = atoi(v->value);
  1992. } else if (!strcasecmp(v->name, "ip")) {
  1993. ast_copy_string(peer->ip, v->value, sizeof(peer->ip));
  1994. } else if (!strcasecmp(v->name, "host")) {
  1995. ast_copy_string(peer->ip, v->value, sizeof(peer->ip));
  1996. } else if (!strcasecmp(v->name, "outgoinglimit")) {
  1997. peer->outgoinglimit = atoi(v->value);
  1998. if (peer->outgoinglimit < 0)
  1999. peer->outgoinglimit = 0;
  2000. } else if (!strcasecmp(v->name, "accountcode")) {
  2001. ast_copy_string(peer->accountcode, v->value, sizeof(peer->accountcode));
  2002. } else if (!strcasecmp(v->name, "faststart")) {
  2003. peer->faststart = ast_true(v->value);
  2004. } else if (!strcasecmp(v->name, "h245tunneling")) {
  2005. peer->h245tunneling = ast_true(v->value);
  2006. } else if (!strcasecmp(v->name, "g729onlyA")) {
  2007. peer->g729onlyA = ast_true(v->value);
  2008. } else if (!strcasecmp(v->name, "rtptimeout")) {
  2009. peer->rtptimeout = atoi(v->value);
  2010. if(peer->rtptimeout < 0)
  2011. peer->rtptimeout = gRTPTimeout;
  2012. } else if (!strcasecmp(v->name, "rtpmask")) {
  2013. if ((peer->rtpmask = malloc(sizeof(struct OOH323Regex))) &&
  2014. (regcomp(&peer->rtpmask->regex, v->value, REG_EXTENDED)
  2015. == 0)) {
  2016. ast_mutex_init(&peer->rtpmask->lock);
  2017. peer->rtpmask->inuse = 1;
  2018. ast_copy_string(peer->rtpmaskstr, v->value,
  2019. sizeof(peer->rtpmaskstr));
  2020. } else peer->rtpmask = NULL;
  2021. } else if (!strcasecmp(v->name, "disallow")) {
  2022. ast_parse_allow_disallow(&peer->prefs, &peer->capability,
  2023. v->value, 0);
  2024. } else if (!strcasecmp(v->name, "allow")) {
  2025. const char* tcodecs = v->value;
  2026. if (!strcasecmp(v->value, "all")) {
  2027. tcodecs = "ulaw,alaw,g729,g723,gsm";
  2028. }
  2029. ast_parse_allow_disallow(&peer->prefs, &peer->capability,
  2030. tcodecs, 1);
  2031. } else if (!strcasecmp(v->name, "amaflags")) {
  2032. peer->amaflags = ast_cdr_amaflags2int(v->value);
  2033. } else if (!strcasecmp(v->name, "roundtrip")) {
  2034. sscanf(v->value, "%d,%d", &peer->rtdrcount, &peer->rtdrinterval);
  2035. } else if (!strcasecmp(v->name, "dtmfmode")) {
  2036. if (!strcasecmp(v->value, "rfc2833"))
  2037. peer->dtmfmode = H323_DTMF_RFC2833;
  2038. if (!strcasecmp(v->value, "cisco"))
  2039. peer->dtmfmode = H323_DTMF_CISCO;
  2040. else if (!strcasecmp(v->value, "q931keypad"))
  2041. peer->dtmfmode = H323_DTMF_Q931;
  2042. else if (!strcasecmp(v->value, "h245alphanumeric"))
  2043. peer->dtmfmode = H323_DTMF_H245ALPHANUMERIC;
  2044. else if (!strcasecmp(v->value, "h245signal"))
  2045. peer->dtmfmode = H323_DTMF_H245SIGNAL;
  2046. else if (!strcasecmp(v->value, "inband"))
  2047. peer->dtmfmode = H323_DTMF_INBAND;
  2048. } else if (!strcasecmp(v->name, "relaxdtmf")) {
  2049. peer->dtmfmode |= ast_true(v->value) ? H323_DTMF_INBANDRELAX : 0;
  2050. } else if (!strcasecmp(v->name, "dtmfcodec") && atoi(v->value)) {
  2051. peer->dtmfcodec = atoi(v->value);
  2052. } else if (!strcasecmp(v->name, "t38support")) {
  2053. if (!strcasecmp(v->value, "disabled"))
  2054. peer->t38support = T38_DISABLED;
  2055. if (!strcasecmp(v->value, "no"))
  2056. peer->t38support = T38_DISABLED;
  2057. else if (!strcasecmp(v->value, "faxgw"))
  2058. peer->t38support = T38_FAXGW;
  2059. else if (!strcasecmp(v->value, "yes"))
  2060. peer->t38support = T38_ENABLED;
  2061. }
  2062. v = v->next;
  2063. }
  2064. }
  2065. if (gH323Debug)
  2066. ast_verbose("+++ build_peer\n");
  2067. return peer;
  2068. }
  2069. static int ooh323_do_reload(void)
  2070. {
  2071. if (gH323Debug) {
  2072. ast_verbose("--- ooh323_do_reload\n");
  2073. }
  2074. reload_config(1);
  2075. if (gH323Debug) {
  2076. ast_verbose("+++ ooh323_do_reload\n");
  2077. }
  2078. return 0;
  2079. }
  2080. /*--- h323_reload: Force reload of module from cli ---*/
  2081. char *handle_cli_ooh323_reload(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
  2082. {
  2083. switch (cmd) {
  2084. case CLI_INIT:
  2085. e->command = "ooh323 reload";
  2086. e->usage =
  2087. "Usage: ooh323 reload\n"
  2088. " Reload OOH323 config.\n";
  2089. return NULL;
  2090. case CLI_GENERATE:
  2091. return NULL;
  2092. }
  2093. if (a->argc != 2)
  2094. return CLI_SHOWUSAGE;
  2095. if (gH323Debug)
  2096. ast_verbose("--- ooh323_reload\n");
  2097. ast_mutex_lock(&h323_reload_lock);
  2098. if (h323_reloading) {
  2099. ast_verbose("Previous OOH323 reload not yet done\n");
  2100. } else {
  2101. h323_reloading = 1;
  2102. }
  2103. ast_mutex_unlock(&h323_reload_lock);
  2104. restart_monitor();
  2105. if (gH323Debug)
  2106. ast_verbose("+++ ooh323_reload\n");
  2107. return 0;
  2108. }
  2109. int reload_config(int reload)
  2110. {
  2111. int format;
  2112. struct ooAliases *pNewAlias = NULL, *cur, *prev;
  2113. struct ast_config *cfg;
  2114. struct ast_variable *v;
  2115. struct ast_flags config_flags = { reload ? CONFIG_FLAG_FILEUNCHANGED : 0 };
  2116. struct ooh323_user *user = NULL;
  2117. struct ooh323_peer *peer = NULL;
  2118. char *cat;
  2119. const char *utype;
  2120. if (gH323Debug)
  2121. ast_verbose("--- reload_config\n");
  2122. cfg = ast_config_load((char*)config, config_flags);
  2123. /* We *must* have a config file otherwise stop immediately */
  2124. if (!cfg) {
  2125. ast_log(LOG_NOTICE, "Unable to load config %s, OOH323 disabled\n", config);
  2126. return 1;
  2127. } else if (cfg == CONFIG_STATUS_FILEUNCHANGED)
  2128. return RESULT_SUCCESS;
  2129. if (reload) {
  2130. delete_users();
  2131. delete_peers();
  2132. if (gH323Debug) {
  2133. ast_verbose(" reload_config - Freeing up alias list\n");
  2134. }
  2135. cur = gAliasList;
  2136. while (cur) {
  2137. prev = cur;
  2138. cur = cur->next;
  2139. free(prev->value);
  2140. free(prev);
  2141. }
  2142. gAliasList = NULL;
  2143. }
  2144. /* Inintialize everything to default */
  2145. strcpy(gLogFile, DEFAULT_LOGFILE);
  2146. gPort = 1720;
  2147. gIP[0] = '\0';
  2148. strcpy(gCallerID, DEFAULT_H323ID);
  2149. gCapability = AST_FORMAT_ALAW;
  2150. memset(&gPrefs, 0, sizeof(struct ast_codec_pref));
  2151. gDTMFMode = H323_DTMF_RFC2833;
  2152. gDTMFCodec = 101;
  2153. gT38Support = T38_FAXGW;
  2154. gTRCLVL = OOTRCLVLERR;
  2155. gRasGkMode = RasNoGatekeeper;
  2156. gGatekeeper[0] = '\0';
  2157. gRTPTimeout = 60;
  2158. gRTDRInterval = 0;
  2159. gRTDRCount = 0;
  2160. strcpy(gAccountcode, DEFAULT_H323ACCNT);
  2161. gFastStart = 1;
  2162. gTunneling = 1;
  2163. gTOS = 0;
  2164. strcpy(gContext, DEFAULT_CONTEXT);
  2165. gAliasList = NULL;
  2166. gMediaWaitForConnect = 0;
  2167. ooconfig.mTCPPortStart = 12030;
  2168. ooconfig.mTCPPortEnd = 12230;
  2169. memcpy(&global_jbconf, &default_jbconf, sizeof(struct ast_jb_conf));
  2170. v = ast_variable_browse(cfg, "general");
  2171. while (v) {
  2172. if (!ast_jb_read_conf(&global_jbconf, v->name, v->value)) {
  2173. v = v->next;
  2174. continue;
  2175. }
  2176. if (!strcasecmp(v->name, "port")) {
  2177. gPort = (int)strtol(v->value, NULL, 10);
  2178. } else if (!strcasecmp(v->name, "bindaddr")) {
  2179. ast_copy_string(gIP, v->value, sizeof(gIP));
  2180. } else if (!strcasecmp(v->name, "h225portrange")) {
  2181. char* endlimit = 0;
  2182. char temp[512];
  2183. ast_copy_string(temp, v->value, sizeof(temp));
  2184. endlimit = strchr(temp, ',');
  2185. if (endlimit) {
  2186. *endlimit = '\0';
  2187. endlimit++;
  2188. ooconfig.mTCPPortStart = atoi(temp);
  2189. ooconfig.mTCPPortEnd = atoi(endlimit);
  2190. } else {
  2191. ast_log(LOG_ERROR, "h225portrange: Invalid format, separate port range with \",\"\n");
  2192. }
  2193. } else if (!strcasecmp(v->name, "gateway")) {
  2194. gIsGateway = ast_true(v->value);
  2195. } else if (!strcasecmp(v->name, "faststart")) {
  2196. gFastStart = ast_true(v->value);
  2197. if (gFastStart)
  2198. ooH323EpEnableFastStart();
  2199. else
  2200. ooH323EpDisableFastStart();
  2201. } else if (!strcasecmp(v->name, "mediawaitforconnect")) {
  2202. gMediaWaitForConnect = ast_true(v->value);
  2203. if (gMediaWaitForConnect)
  2204. ooH323EpEnableMediaWaitForConnect();
  2205. else
  2206. ooH323EpDisableMediaWaitForConnect();
  2207. } else if (!strcasecmp(v->name, "h245tunneling")) {
  2208. gTunneling = ast_true(v->value);
  2209. if (gTunneling)
  2210. ooH323EpEnableH245Tunneling();
  2211. else
  2212. ooH323EpDisableH245Tunneling();
  2213. } else if (!strcasecmp(v->name, "g729onlyA")) {
  2214. g729onlyA = ast_true(v->value);
  2215. } else if (!strcasecmp(v->name, "roundtrip")) {
  2216. sscanf(v->value, "%d,%d", &gRTDRCount, &gRTDRInterval);
  2217. } else if (!strcasecmp(v->name, "trybemaster")) {
  2218. gBeMaster = ast_true(v->value);
  2219. if (gBeMaster)
  2220. ooH323EpTryBeMaster(1);
  2221. else
  2222. ooH323EpTryBeMaster(0);
  2223. } else if (!strcasecmp(v->name, "h323id")) {
  2224. pNewAlias = malloc(sizeof(struct ooAliases));
  2225. if (!pNewAlias) {
  2226. ast_log(LOG_ERROR, "Failed to allocate memory for h323id alias\n");
  2227. return 1;
  2228. }
  2229. if (gAliasList == NULL) { /* first h323id - set as callerid if callerid is not set */
  2230. ast_copy_string(gCallerID, v->value, sizeof(gCallerID));
  2231. }
  2232. pNewAlias->type = T_H225AliasAddress_h323_ID;
  2233. pNewAlias->value = strdup(v->value);
  2234. pNewAlias->next = gAliasList;
  2235. gAliasList = pNewAlias;
  2236. pNewAlias = NULL;
  2237. } else if (!strcasecmp(v->name, "e164")) {
  2238. pNewAlias = malloc(sizeof(struct ooAliases));
  2239. if (!pNewAlias) {
  2240. ast_log(LOG_ERROR, "Failed to allocate memory for e164 alias\n");
  2241. return 1;
  2242. }
  2243. pNewAlias->type = T_H225AliasAddress_dialedDigits;
  2244. pNewAlias->value = strdup(v->value);
  2245. pNewAlias->next = gAliasList;
  2246. gAliasList = pNewAlias;
  2247. pNewAlias = NULL;
  2248. } else if (!strcasecmp(v->name, "email")) {
  2249. pNewAlias = malloc(sizeof(struct ooAliases));
  2250. if (!pNewAlias) {
  2251. ast_log(LOG_ERROR, "Failed to allocate memory for email alias\n");
  2252. return 1;
  2253. }
  2254. pNewAlias->type = T_H225AliasAddress_email_ID;
  2255. pNewAlias->value = strdup(v->value);
  2256. pNewAlias->next = gAliasList;
  2257. gAliasList = pNewAlias;
  2258. pNewAlias = NULL;
  2259. } else if (!strcasecmp(v->name, "t35country")) {
  2260. t35countrycode = atoi(v->value);
  2261. } else if (!strcasecmp(v->name, "t35extensions")) {
  2262. t35extensions = atoi(v->value);
  2263. } else if (!strcasecmp(v->name, "manufacturer")) {
  2264. manufacturer = atoi(v->value);
  2265. } else if (!strcasecmp(v->name, "vendorid")) {
  2266. ast_copy_string(vendor, v->value, sizeof(vendor));
  2267. } else if (!strcasecmp(v->name, "versionid")) {
  2268. ast_copy_string(version, v->value, sizeof(version));
  2269. } else if (!strcasecmp(v->name, "callerid")) {
  2270. ast_copy_string(gCallerID, v->value, sizeof(gCallerID));
  2271. } else if (!strcasecmp(v->name, "incominglimit")) {
  2272. gIncomingLimit = atoi(v->value);
  2273. } else if (!strcasecmp(v->name, "outgoinglimit")) {
  2274. gOutgoingLimit = atoi(v->value);
  2275. } else if (!strcasecmp(v->name, "gatekeeper")) {
  2276. if (!strcasecmp(v->value, "DISABLE")) {
  2277. gRasGkMode = RasNoGatekeeper;
  2278. } else if (!strcasecmp(v->value, "DISCOVER")) {
  2279. gRasGkMode = RasDiscoverGatekeeper;
  2280. } else {
  2281. gRasGkMode = RasUseSpecificGatekeeper;
  2282. strncpy(gGatekeeper, v->value, sizeof(gGatekeeper)-1);
  2283. }
  2284. } else if (!strcasecmp(v->name, "logfile")) {
  2285. strncpy(gLogFile, v->value, sizeof(gLogFile)-1);
  2286. } else if (!strcasecmp(v->name, "context")) {
  2287. strncpy(gContext, v->value, sizeof(gContext)-1);
  2288. ast_verbose(VERBOSE_PREFIX_3 " == Setting default context to %s\n",
  2289. gContext);
  2290. } else if (!strcasecmp(v->name, "rtptimeout")) {
  2291. gRTPTimeout = atoi(v->value);
  2292. if (gRTPTimeout <= 0)
  2293. gRTPTimeout = 60;
  2294. } else if (!strcasecmp(v->name, "tos")) {
  2295. if (sscanf(v->value, "%30i", &format) == 1)
  2296. gTOS = format & 0xff;
  2297. else if (!strcasecmp(v->value, "lowdelay"))
  2298. gTOS = IPTOS_LOWDELAY;
  2299. else if (!strcasecmp(v->value, "throughput"))
  2300. gTOS = IPTOS_THROUGHPUT;
  2301. else if (!strcasecmp(v->value, "reliability"))
  2302. gTOS = IPTOS_RELIABILITY;
  2303. else if (!strcasecmp(v->value, "mincost"))
  2304. gTOS = IPTOS_MINCOST;
  2305. else if (!strcasecmp(v->value, "none"))
  2306. gTOS = 0;
  2307. else
  2308. ast_log(LOG_WARNING, "Invalid tos value at line %d, should be "
  2309. "'lowdelay', 'throughput', 'reliability', "
  2310. "'mincost', or 'none'\n", v->lineno);
  2311. } else if (!strcasecmp(v->name, "amaflags")) {
  2312. gAMAFLAGS = ast_cdr_amaflags2int(v->value);
  2313. } else if (!strcasecmp(v->name, "accountcode")) {
  2314. ast_copy_string(gAccountcode, v->value, sizeof(gAccountcode));
  2315. } else if (!strcasecmp(v->name, "disallow")) {
  2316. ast_parse_allow_disallow(&gPrefs, &gCapability, v->value, 0);
  2317. } else if (!strcasecmp(v->name, "allow")) {
  2318. const char* tcodecs = v->value;
  2319. if (!strcasecmp(v->value, "all")) {
  2320. tcodecs = "ulaw,alaw,g729,g723,gsm";
  2321. }
  2322. ast_parse_allow_disallow(&gPrefs, &gCapability, tcodecs, 1);
  2323. } else if (!strcasecmp(v->name, "dtmfmode")) {
  2324. if (!strcasecmp(v->value, "inband"))
  2325. gDTMFMode = H323_DTMF_INBAND;
  2326. else if (!strcasecmp(v->value, "rfc2833"))
  2327. gDTMFMode = H323_DTMF_RFC2833;
  2328. else if (!strcasecmp(v->value, "cisco"))
  2329. gDTMFMode = H323_DTMF_CISCO;
  2330. else if (!strcasecmp(v->value, "q931keypad"))
  2331. gDTMFMode = H323_DTMF_Q931;
  2332. else if (!strcasecmp(v->value, "h245alphanumeric"))
  2333. gDTMFMode = H323_DTMF_H245ALPHANUMERIC;
  2334. else if (!strcasecmp(v->value, "h245signal"))
  2335. gDTMFMode = H323_DTMF_H245SIGNAL;
  2336. else {
  2337. ast_log(LOG_WARNING, "Unknown dtmf mode '%s', using rfc2833\n",
  2338. v->value);
  2339. gDTMFMode = H323_DTMF_RFC2833;
  2340. }
  2341. } else if (!strcasecmp(v->name, "relaxdtmf")) {
  2342. gDTMFMode |= ast_true(v->value) ? H323_DTMF_INBANDRELAX : 0;
  2343. } else if (!strcasecmp(v->name, "dtmfcodec") && atoi(v->value)) {
  2344. gDTMFCodec = atoi(v->value);
  2345. } else if (!strcasecmp(v->name, "t38support")) {
  2346. if (!strcasecmp(v->value, "disabled"))
  2347. gT38Support = T38_DISABLED;
  2348. if (!strcasecmp(v->value, "no"))
  2349. gT38Support = T38_DISABLED;
  2350. else if (!strcasecmp(v->value, "faxgw"))
  2351. gT38Support = T38_FAXGW;
  2352. else if (!strcasecmp(v->value, "yes"))
  2353. gT38Support = T38_ENABLED;
  2354. } else if (!strcasecmp(v->name, "tracelevel")) {
  2355. gTRCLVL = atoi(v->value);
  2356. ooH323EpSetTraceLevel(gTRCLVL);
  2357. }
  2358. v = v->next;
  2359. }
  2360. for (cat = ast_category_browse(cfg, NULL); cat; cat = ast_category_browse(cfg, cat)) {
  2361. if (strcasecmp(cat, "general")) {
  2362. int friend_type = 0;
  2363. utype = ast_variable_retrieve(cfg, cat, "type");
  2364. if (utype) {
  2365. friend_type = strcasecmp(utype, "friend");
  2366. if (!strcmp(utype, "user") || 0 == friend_type) {
  2367. user = build_user(cat, ast_variable_browse(cfg, cat));
  2368. if (user) {
  2369. ast_mutex_lock(&userl.lock);
  2370. user->next = userl.users;
  2371. userl.users = user;
  2372. ast_mutex_unlock(&userl.lock);
  2373. } else {
  2374. ast_log(LOG_WARNING, "Failed to build user %s\n", cat);
  2375. }
  2376. }
  2377. if (!strcasecmp(utype, "peer") || 0 == friend_type) {
  2378. peer = build_peer(cat, ast_variable_browse(cfg, cat), friend_type);
  2379. if (peer) {
  2380. ast_mutex_lock(&peerl.lock);
  2381. peer->next = peerl.peers;
  2382. peerl.peers = peer;
  2383. ast_mutex_unlock(&peerl.lock);
  2384. } else {
  2385. ast_log(LOG_WARNING, "Failed to build peer %s\n", cat);
  2386. }
  2387. }
  2388. }
  2389. }
  2390. }
  2391. ast_config_destroy(cfg);
  2392. /* Determine ip address if neccessary */
  2393. if (ast_strlen_zero(gIP)) {
  2394. ooGetLocalIPAddress(gIP);
  2395. if (!strcmp(gIP, "127.0.0.1")) {
  2396. ast_log(LOG_NOTICE, "Failed to determine local ip address. Please "
  2397. "specify it in ooh323.conf. OOH323 Disabled\n");
  2398. return 1;
  2399. }
  2400. }
  2401. if (gH323Debug)
  2402. ast_verbose("+++ reload_config\n");
  2403. return 0;
  2404. }
  2405. static char *handle_cli_ooh323_show_peer(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
  2406. {
  2407. char ip_port[30];
  2408. struct ooh323_peer *prev = NULL, *peer = NULL;
  2409. switch (cmd) {
  2410. case CLI_INIT:
  2411. e->command = "ooh323 show peer";
  2412. e->usage =
  2413. "Usage: ooh323 show peer <name>\n"
  2414. " List details of specific OOH323 peer.\n";
  2415. return NULL;
  2416. case CLI_GENERATE:
  2417. return NULL;
  2418. }
  2419. if (a->argc != 4)
  2420. return CLI_SHOWUSAGE;
  2421. ast_mutex_lock(&peerl.lock);
  2422. peer = peerl.peers;
  2423. while (peer) {
  2424. ast_mutex_lock(&peer->lock);
  2425. if(!strcmp(peer->name, a->argv[3]))
  2426. break;
  2427. else {
  2428. prev = peer;
  2429. peer = peer->next;
  2430. ast_mutex_unlock(&prev->lock);
  2431. }
  2432. }
  2433. if (peer) {
  2434. sprintf(ip_port, "%s:%d", peer->ip, peer->port);
  2435. ast_cli(a->fd, "%-15.15s%s\n", "Name: ", peer->name);
  2436. ast_cli(a->fd, "%s:%s,%s\n", "FastStart/H.245 Tunneling", peer->faststart?"yes":"no",
  2437. peer->h245tunneling?"yes":"no");
  2438. ast_cli(a->fd, "%-15.15s%s", "Format Prefs: ", "(");
  2439. print_codec_to_cli(a->fd, &peer->prefs);
  2440. ast_cli(a->fd, ")\n");
  2441. ast_cli(a->fd, "%-15.15s", "DTMF Mode: ");
  2442. if (peer->dtmfmode & H323_DTMF_CISCO) {
  2443. ast_cli(a->fd, "%s\n", "cisco");
  2444. ast_cli(a->fd, "%-15.15s%d\n", "DTMF Codec: ", peer->dtmfcodec);
  2445. } else if (peer->dtmfmode & H323_DTMF_RFC2833) {
  2446. ast_cli(a->fd, "%s\n", "rfc2833");
  2447. ast_cli(a->fd, "%-15.15s%d\n", "DTMF Codec: ", peer->dtmfcodec);
  2448. } else if (peer->dtmfmode & H323_DTMF_Q931)
  2449. ast_cli(a->fd, "%s\n", "q931keypad");
  2450. else if (peer->dtmfmode & H323_DTMF_H245ALPHANUMERIC)
  2451. ast_cli(a->fd, "%s\n", "h245alphanumeric");
  2452. else if (peer->dtmfmode & H323_DTMF_H245SIGNAL)
  2453. ast_cli(a->fd, "%s\n", "h245signal");
  2454. else if (peer->dtmfmode & H323_DTMF_INBAND && peer->dtmfmode & H323_DTMF_INBANDRELAX)
  2455. ast_cli(a->fd, "%s\n", "inband-relaxed");
  2456. else if (peer->dtmfmode & H323_DTMF_INBAND)
  2457. ast_cli(a->fd, "%s\n", "inband");
  2458. else
  2459. ast_cli(a->fd, "%s\n", "unknown");
  2460. ast_cli(a->fd,"%-15s", "T.38 Mode: ");
  2461. if (peer->t38support == T38_DISABLED)
  2462. ast_cli(a->fd, "%s\n", "disabled");
  2463. else if (peer->t38support == T38_FAXGW)
  2464. ast_cli(a->fd, "%s\n", "faxgw/chan_sip compatible");
  2465. ast_cli(a->fd, "%-15.15s%s\n", "AccountCode: ", peer->accountcode);
  2466. ast_cli(a->fd, "%-15.15s%s\n", "AMA flags: ",
  2467. ast_cdr_flags2str(peer->amaflags));
  2468. ast_cli(a->fd, "%-15.15s%s\n", "IP:Port: ", ip_port);
  2469. ast_cli(a->fd, "%-15.15s%d\n", "OutgoingLimit: ", peer->outgoinglimit);
  2470. ast_cli(a->fd, "%-15.15s%d\n", "rtptimeout: ", peer->rtptimeout);
  2471. if (peer->rtpmaskstr[0])
  2472. ast_cli(a->fd, "%-15.15s%s\n", "rtpmask: ", peer->rtpmaskstr);
  2473. if (peer->rtdrcount && peer->rtdrinterval)
  2474. ast_cli(a->fd, "%-15.15s%d,%d\n", "RoundTrip: ", peer->rtdrcount, peer->rtdrinterval);
  2475. ast_mutex_unlock(&peer->lock);
  2476. } else {
  2477. ast_cli(a->fd, "Peer %s not found\n", a->argv[3]);
  2478. ast_cli(a->fd, "\n");
  2479. }
  2480. ast_mutex_unlock(&peerl.lock);
  2481. return CLI_SUCCESS;
  2482. }
  2483. static char *handle_cli_ooh323_show_peers(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
  2484. {
  2485. struct ooh323_peer *prev = NULL, *peer = NULL;
  2486. char formats[FORMAT_STRING_SIZE];
  2487. char ip_port[30];
  2488. #define FORMAT "%-15.15s %-15.15s %-23.23s %-s\n"
  2489. switch (cmd) {
  2490. case CLI_INIT:
  2491. e->command = "ooh323 show peers";
  2492. e->usage =
  2493. "Usage: ooh323 show peers\n"
  2494. " Lists all known OOH323 peers.\n";
  2495. return NULL;
  2496. case CLI_GENERATE:
  2497. return NULL;
  2498. }
  2499. if (a->argc != 3)
  2500. return CLI_SHOWUSAGE;
  2501. ast_cli(a->fd, FORMAT, "Name", "Accountcode", "ip:port", "Formats");
  2502. ast_mutex_lock(&peerl.lock);
  2503. peer = peerl.peers;
  2504. while (peer) {
  2505. ast_mutex_lock(&peer->lock);
  2506. snprintf(ip_port, sizeof(ip_port), "%s:%d", peer->ip, peer->port);
  2507. ast_cli(a->fd, FORMAT, peer->name,
  2508. peer->accountcode,
  2509. ip_port,
  2510. ast_getformatname_multiple(formats,FORMAT_STRING_SIZE,peer->capability));
  2511. prev = peer;
  2512. peer = peer->next;
  2513. ast_mutex_unlock(&prev->lock);
  2514. }
  2515. ast_mutex_unlock(&peerl.lock);
  2516. #undef FORMAT
  2517. return CLI_SUCCESS;
  2518. }
  2519. /*! \brief Print codec list from preference to CLI/manager */
  2520. static void print_codec_to_cli(int fd, struct ast_codec_pref *pref)
  2521. {
  2522. int x, codec;
  2523. for (x = 0; x < 32; x++) {
  2524. codec = ast_codec_pref_index(pref, x);
  2525. if (!codec)
  2526. break;
  2527. ast_cli(fd, "%s", ast_getformatname(codec));
  2528. ast_cli(fd, ":%d", pref->framing[x]);
  2529. if (x < 31 && ast_codec_pref_index(pref, x + 1))
  2530. ast_cli(fd, ",");
  2531. }
  2532. if (!x)
  2533. ast_cli(fd, "none");
  2534. }
  2535. static char *handle_cli_ooh323_show_user(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
  2536. {
  2537. struct ooh323_user *prev = NULL, *user = NULL;
  2538. switch (cmd) {
  2539. case CLI_INIT:
  2540. e->command = "ooh323 show user";
  2541. e->usage =
  2542. "Usage: ooh323 show user <name>\n"
  2543. " List details of specific OOH323 user.\n";
  2544. return NULL;
  2545. case CLI_GENERATE:
  2546. return NULL;
  2547. }
  2548. if (a->argc != 4)
  2549. return CLI_SHOWUSAGE;
  2550. ast_mutex_lock(&userl.lock);
  2551. user = userl.users;
  2552. while (user) {
  2553. ast_mutex_lock(&user->lock);
  2554. if(!strcmp(user->name, a->argv[3])) {
  2555. break;
  2556. } else {
  2557. prev = user;
  2558. user = user->next;
  2559. ast_mutex_unlock(&prev->lock);
  2560. }
  2561. }
  2562. if (user) {
  2563. ast_cli(a->fd, "%-15.15s%s\n", "Name: ", user->name);
  2564. ast_cli(a->fd, "%s:%s,%s\n", "FastStart/H.245 Tunneling", user->faststart?"yes":"no",
  2565. user->h245tunneling?"yes":"no");
  2566. ast_cli(a->fd, "%-15.15s%s", "Format Prefs: ", "(");
  2567. print_codec_to_cli(a->fd, &user->prefs);
  2568. ast_cli(a->fd, ")\n");
  2569. ast_cli(a->fd, "%-15.15s", "DTMF Mode: ");
  2570. if (user->dtmfmode & H323_DTMF_CISCO) {
  2571. ast_cli(a->fd, "%s\n", "cisco");
  2572. ast_cli(a->fd, "%-15.15s%d\n", "DTMF Codec: ", user->dtmfcodec);
  2573. } else if (user->dtmfmode & H323_DTMF_RFC2833) {
  2574. ast_cli(a->fd, "%s\n", "rfc2833");
  2575. ast_cli(a->fd, "%-15.15s%d\n", "DTMF Codec: ", user->dtmfcodec);
  2576. } else if (user->dtmfmode & H323_DTMF_Q931)
  2577. ast_cli(a->fd, "%s\n", "q931keypad");
  2578. else if (user->dtmfmode & H323_DTMF_H245ALPHANUMERIC)
  2579. ast_cli(a->fd, "%s\n", "h245alphanumeric");
  2580. else if (user->dtmfmode & H323_DTMF_H245SIGNAL)
  2581. ast_cli(a->fd, "%s\n", "h245signal");
  2582. else if (user->dtmfmode & H323_DTMF_INBAND && user->dtmfmode & H323_DTMF_INBANDRELAX)
  2583. ast_cli(a->fd, "%s\n", "inband-relaxed");
  2584. else if (user->dtmfmode & H323_DTMF_INBAND)
  2585. ast_cli(a->fd, "%s\n", "inband");
  2586. else
  2587. ast_cli(a->fd, "%s\n", "unknown");
  2588. ast_cli(a->fd,"%-15s", "T.38 Mode: ");
  2589. if (user->t38support == T38_DISABLED)
  2590. ast_cli(a->fd, "%s\n", "disabled");
  2591. else if (user->t38support == T38_FAXGW)
  2592. ast_cli(a->fd, "%s\n", "faxgw/chan_sip compatible");
  2593. ast_cli(a->fd, "%-15.15s%s\n", "AccountCode: ", user->accountcode);
  2594. ast_cli(a->fd, "%-15.15s%s\n", "AMA flags: ",
  2595. ast_cdr_flags2str(user->amaflags));
  2596. ast_cli(a->fd, "%-15.15s%s\n", "Context: ", user->context);
  2597. ast_cli(a->fd, "%-15.15s%d\n", "IncomingLimit: ", user->incominglimit);
  2598. ast_cli(a->fd, "%-15.15s%d\n", "InUse: ", user->inUse);
  2599. ast_cli(a->fd, "%-15.15s%d\n", "rtptimeout: ", user->rtptimeout);
  2600. if (user->rtpmaskstr[0])
  2601. ast_cli(a->fd, "%-15.15s%s\n", "rtpmask: ", user->rtpmaskstr);
  2602. ast_mutex_unlock(&user->lock);
  2603. if (user->rtdrcount && user->rtdrinterval)
  2604. ast_cli(a->fd, "%-15.15s%d,%d\n", "RoundTrip: ", user->rtdrcount, user->rtdrinterval);
  2605. } else {
  2606. ast_cli(a->fd, "User %s not found\n", a->argv[3]);
  2607. ast_cli(a->fd, "\n");
  2608. }
  2609. ast_mutex_unlock(&userl.lock);
  2610. return CLI_SUCCESS;
  2611. }
  2612. static char *handle_cli_ooh323_show_users(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
  2613. {
  2614. struct ooh323_user *prev = NULL, *user = NULL;
  2615. char formats[FORMAT_STRING_SIZE];
  2616. #define FORMAT1 "%-15.15s %-15.15s %-15.15s %-s\n"
  2617. switch (cmd) {
  2618. case CLI_INIT:
  2619. e->command = "ooh323 show users";
  2620. e->usage =
  2621. "Usage: ooh323 show users \n"
  2622. " Lists all known OOH323 users.\n";
  2623. return NULL;
  2624. case CLI_GENERATE:
  2625. return NULL;
  2626. }
  2627. if (a->argc != 3)
  2628. return CLI_SHOWUSAGE;
  2629. ast_cli(a->fd, FORMAT1, "Username", "Accountcode", "Context", "Formats");
  2630. ast_mutex_lock(&userl.lock);
  2631. user = userl.users;
  2632. while(user)
  2633. {
  2634. ast_mutex_lock(&user->lock);
  2635. ast_cli(a->fd, FORMAT1, user->name,
  2636. user->accountcode, user->context,
  2637. ast_getformatname_multiple(formats, FORMAT_STRING_SIZE, user->capability));
  2638. prev = user;
  2639. user = user->next;
  2640. ast_mutex_unlock(&prev->lock);
  2641. }
  2642. ast_mutex_unlock(&userl.lock);
  2643. #undef FORMAT1
  2644. return RESULT_SUCCESS;
  2645. }
  2646. static char *handle_cli_ooh323_set_debug(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
  2647. {
  2648. switch (cmd) {
  2649. case CLI_INIT:
  2650. e->command = "ooh323 set debug [off]";
  2651. e->usage =
  2652. "Usage: ooh323 set debug [off]\n"
  2653. " Enables/Disables debugging of OOH323 channel driver\n";
  2654. return NULL;
  2655. case CLI_GENERATE:
  2656. return NULL;
  2657. }
  2658. if (a->argc < 3 || a->argc > 4)
  2659. return CLI_SHOWUSAGE;
  2660. if (a->argc == 4 && strcasecmp(a->argv[3], "off"))
  2661. return CLI_SHOWUSAGE;
  2662. gH323Debug = (a->argc == 4) ? FALSE : TRUE;
  2663. ast_cli(a->fd, "OOH323 Debugging %s\n", gH323Debug ? "Enabled" : "Disabled");
  2664. return CLI_SUCCESS;
  2665. }
  2666. #if 0
  2667. static int ooh323_show_channels(int fd, int argc, char *argv[])
  2668. {
  2669. return RESULT_SUCCESS;
  2670. }
  2671. #endif
  2672. static char *handle_cli_ooh323_show_config(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
  2673. {
  2674. char value[FORMAT_STRING_SIZE];
  2675. ooAliases *pAlias = NULL, *pAliasNext = NULL;;
  2676. switch (cmd) {
  2677. case CLI_INIT:
  2678. e->command = "ooh323 show config";
  2679. e->usage =
  2680. "Usage: ooh323 show config\n"
  2681. " Shows global configuration of H.323 channel driver\n";
  2682. return NULL;
  2683. case CLI_GENERATE:
  2684. return NULL;
  2685. }
  2686. if (a->argc != 3)
  2687. return CLI_SHOWUSAGE;
  2688. ast_cli(a->fd, "\nObjective Open H.323 Channel Driver's Config:\n");
  2689. snprintf(value, sizeof(value), "%s:%d", gIP, gPort);
  2690. ast_cli(a->fd, "%-20s%s\n", "IP:Port: ", value);
  2691. ast_cli(a->fd, "%-20s%d-%d\n", "H.225 port range: ",
  2692. ooconfig.mTCPPortStart, ooconfig.mTCPPortEnd);
  2693. ast_cli(a->fd, "%-20s%s\n", "FastStart", gFastStart?"yes":"no");
  2694. ast_cli(a->fd, "%-20s%s\n", "Tunneling", gTunneling?"yes":"no");
  2695. ast_cli(a->fd, "%-20s%s\n", "CallerId", gCallerID);
  2696. ast_cli(a->fd, "%-20s%s\n", "MediaWaitForConnect",
  2697. gMediaWaitForConnect?"yes":"no");
  2698. #if (0)
  2699. extern OOH323EndPoint gH323ep;
  2700. ast_cli(a->fd, "%-20s%s\n", "FASTSTART",
  2701. (OO_TESTFLAG(gH323ep.flags, OO_M_FASTSTART) != 0) ? "yes" : "no");
  2702. ast_cli(a->fd, "%-20s%s\n", "TUNNELING",
  2703. (OO_TESTFLAG(gH323ep.flags, OO_M_TUNNELING) != 0) ? "yes" : "no");
  2704. ast_cli(a->fd, "%-20s%s\n", "MEDIAWAITFORCONN",
  2705. (OO_TESTFLAG(gH323ep.flags, OO_M_MEDIAWAITFORCONN) != 0) ? "yes" : "no");
  2706. #endif
  2707. if (gRasGkMode == RasNoGatekeeper)
  2708. snprintf(value, sizeof(value), "%s", "No Gatekeeper");
  2709. else if (gRasGkMode == RasDiscoverGatekeeper)
  2710. snprintf(value, sizeof(value), "%s", "Discover");
  2711. else
  2712. snprintf(value, sizeof(value), "%s", gGatekeeper);
  2713. ast_cli(a->fd, "%-20s%s\n", "Gatekeeper:", value);
  2714. ast_cli(a->fd, "%-20s%s\n", "H.323 LogFile:", gLogFile);
  2715. ast_cli(a->fd, "%-20s%s\n", "Context:", gContext);
  2716. ast_cli(a->fd, "%-20s%s\n", "Capability:",
  2717. ast_getformatname_multiple(value,FORMAT_STRING_SIZE,gCapability));
  2718. ast_cli(a->fd, "%-20s", "DTMF Mode: ");
  2719. if (gDTMFMode & H323_DTMF_CISCO) {
  2720. ast_cli(a->fd, "%s\n", "cisco");
  2721. ast_cli(a->fd, "%-15.15s%d\n", "DTMF Codec: ", gDTMFCodec);
  2722. } else if (gDTMFMode & H323_DTMF_RFC2833) {
  2723. ast_cli(a->fd, "%s\n", "rfc2833");
  2724. ast_cli(a->fd, "%-15.15s%d\n", "DTMF Codec: ", gDTMFCodec);
  2725. } else if (gDTMFMode & H323_DTMF_Q931)
  2726. ast_cli(a->fd, "%s\n", "q931keypad");
  2727. else if (gDTMFMode & H323_DTMF_H245ALPHANUMERIC)
  2728. ast_cli(a->fd, "%s\n", "h245alphanumeric");
  2729. else if (gDTMFMode & H323_DTMF_H245SIGNAL)
  2730. ast_cli(a->fd, "%s\n", "h245signal");
  2731. else if (gDTMFMode & H323_DTMF_INBAND && gDTMFMode & H323_DTMF_INBANDRELAX)
  2732. ast_cli(a->fd, "%s\n", "inband-relaxed");
  2733. else if (gDTMFMode & H323_DTMF_INBAND)
  2734. ast_cli(a->fd, "%s\n", "inband");
  2735. else
  2736. ast_cli(a->fd, "%s\n", "unknown");
  2737. ast_cli(a->fd,"%-20s", "T.38 Mode: ");
  2738. if (gT38Support == T38_DISABLED)
  2739. ast_cli(a->fd, "%s\n", "disabled");
  2740. else if (gT38Support == T38_FAXGW)
  2741. ast_cli(a->fd, "%s\n", "faxgw/chan_sip compatible");
  2742. if (gRTDRCount && gRTDRInterval)
  2743. ast_cli(a->fd, "%-15.15s%d,%d\n", "RoundTrip: ", gRTDRCount, gRTDRInterval);
  2744. ast_cli(a->fd, "%-20s%ld\n", "Call counter: ", callnumber);
  2745. ast_cli(a->fd, "%-20s%s\n", "AccountCode: ", gAccountcode);
  2746. ast_cli(a->fd, "%-20s%s\n", "AMA flags: ", ast_cdr_flags2str(gAMAFLAGS));
  2747. pAlias = gAliasList;
  2748. if(pAlias) {
  2749. ast_cli(a->fd, "%-20s\n", "Aliases: ");
  2750. }
  2751. while (pAlias) {
  2752. pAliasNext = pAlias->next;
  2753. if (pAliasNext) {
  2754. ast_cli(a->fd,"\t%-30s\t%-30s\n",pAlias->value, pAliasNext->value);
  2755. pAlias = pAliasNext->next;
  2756. }
  2757. else{
  2758. ast_cli(a->fd,"\t%-30s\n",pAlias->value);
  2759. pAlias = pAlias->next;
  2760. }
  2761. }
  2762. return CLI_SUCCESS;
  2763. }
  2764. static struct ast_cli_entry cli_ooh323[] = {
  2765. AST_CLI_DEFINE(handle_cli_ooh323_set_debug, "Enable/Disable OOH323 debugging"),
  2766. AST_CLI_DEFINE(handle_cli_ooh323_show_config, "Show details on global configuration of H.323 channel driver"),
  2767. AST_CLI_DEFINE(handle_cli_ooh323_show_peer, "Show details on specific OOH323 peer"),
  2768. AST_CLI_DEFINE(handle_cli_ooh323_show_peers, "Show defined OOH323 peers"),
  2769. AST_CLI_DEFINE(handle_cli_ooh323_show_user, "Show details on specific OOH323 user"),
  2770. AST_CLI_DEFINE(handle_cli_ooh323_show_users, "Show defined OOH323 users"),
  2771. AST_CLI_DEFINE(handle_cli_ooh323_reload, "reload ooh323 config")
  2772. };
  2773. static int load_module(void)
  2774. {
  2775. int res;
  2776. struct ooAliases * pNewAlias = NULL;
  2777. struct ooh323_peer *peer = NULL;
  2778. OOH225MsgCallbacks h225Callbacks = {0, 0, 0, 0};
  2779. OOH323CALLBACKS h323Callbacks = {
  2780. .onNewCallCreated = onNewCallCreated,
  2781. .onAlerting = onAlerting,
  2782. .onProgress = onProgress,
  2783. .onIncomingCall = NULL,
  2784. .onOutgoingCall = onOutgoingCall,
  2785. .onCallEstablished = onCallEstablished,
  2786. .onCallCleared = onCallCleared,
  2787. .openLogicalChannels = NULL,
  2788. .onReceivedDTMF = ooh323_onReceivedDigit,
  2789. .onModeChanged = onModeChanged
  2790. };
  2791. myself = ast_module_info->self;
  2792. h225Callbacks.onReceivedSetup = &ooh323_onReceivedSetup;
  2793. userl.users = NULL;
  2794. ast_mutex_init(&userl.lock);
  2795. peerl.peers = NULL;
  2796. ast_mutex_init(&peerl.lock);
  2797. #if 0
  2798. ast_register_atexit(&ast_ooh323c_exit);
  2799. #endif
  2800. if (!(sched = sched_context_create())) {
  2801. ast_log(LOG_WARNING, "Unable to create schedule context\n");
  2802. }
  2803. if (!(io = io_context_create())) {
  2804. ast_log(LOG_WARNING, "Unable to create I/O context\n");
  2805. }
  2806. if (!(res = reload_config(0))) {
  2807. /* Make sure we can register our OOH323 channel type */
  2808. if (ast_channel_register(&ooh323_tech)) {
  2809. ast_log(LOG_ERROR, "Unable to register channel class %s\n", type);
  2810. return 0;
  2811. }
  2812. ast_rtp_glue_register(&ooh323_rtp);
  2813. ast_udptl_proto_register(&ooh323_udptl);
  2814. ast_cli_register_multiple(cli_ooh323, sizeof(cli_ooh323) / sizeof(struct ast_cli_entry));
  2815. /* fire up the H.323 Endpoint */
  2816. if (OO_OK != ooH323EpInitialize(OO_CALLMODE_AUDIOCALL, gLogFile)) {
  2817. ast_log(LOG_ERROR, "Failed to initialize OOH323 endpoint-"
  2818. "OOH323 Disabled\n");
  2819. return 1;
  2820. }
  2821. if (gIsGateway)
  2822. ooH323EpSetAsGateway();
  2823. ooH323EpSetVersionInfo(t35countrycode, t35extensions, manufacturer,
  2824. vendor, version);
  2825. ooH323EpDisableAutoAnswer();
  2826. ooH323EpSetH225MsgCallbacks(h225Callbacks);
  2827. ooH323EpSetTraceLevel(gTRCLVL);
  2828. ooH323EpSetLocalAddress(gIP, gPort);
  2829. ooH323EpSetCallerID(gCallerID);
  2830. if(ooH323EpSetTCPPortRange(ooconfig.mTCPPortStart,
  2831. ooconfig.mTCPPortEnd) == OO_FAILED) {
  2832. ast_log(LOG_ERROR, "h225portrange: Failed to set range\n");
  2833. }
  2834. /* Set aliases if any */
  2835. for (pNewAlias = gAliasList; pNewAlias; pNewAlias = pNewAlias->next) {
  2836. switch (pNewAlias->type) {
  2837. case T_H225AliasAddress_h323_ID:
  2838. ooH323EpAddAliasH323ID(pNewAlias->value);
  2839. break;
  2840. case T_H225AliasAddress_dialedDigits:
  2841. ooH323EpAddAliasDialedDigits(pNewAlias->value);
  2842. break;
  2843. case T_H225AliasAddress_email_ID:
  2844. ooH323EpAddAliasEmailID(pNewAlias->value);
  2845. break;
  2846. default:
  2847. ;
  2848. }
  2849. }
  2850. ast_mutex_lock(&peerl.lock);
  2851. peer = peerl.peers;
  2852. while (peer) {
  2853. if(peer->h323id) ooH323EpAddAliasH323ID(peer->h323id);
  2854. if(peer->email) ooH323EpAddAliasEmailID(peer->email);
  2855. if(peer->e164) ooH323EpAddAliasDialedDigits(peer->e164);
  2856. if(peer->url) ooH323EpAddAliasURLID(peer->url);
  2857. peer = peer->next;
  2858. }
  2859. ast_mutex_unlock(&peerl.lock);
  2860. if (gMediaWaitForConnect)
  2861. ooH323EpEnableMediaWaitForConnect();
  2862. else
  2863. ooH323EpDisableMediaWaitForConnect();
  2864. /* Fast start and tunneling options */
  2865. if (gFastStart)
  2866. ooH323EpEnableFastStart();
  2867. else
  2868. ooH323EpDisableFastStart();
  2869. if (!gTunneling)
  2870. ooH323EpDisableH245Tunneling();
  2871. if (gBeMaster)
  2872. ooH323EpTryBeMaster(1);
  2873. ooH323EpEnableManualRingback();
  2874. /* Gatekeeper */
  2875. if (gRasGkMode == RasUseSpecificGatekeeper)
  2876. ooGkClientInit(gRasGkMode, gGatekeeper, 0);
  2877. else if (gRasGkMode == RasDiscoverGatekeeper)
  2878. ooGkClientInit(gRasGkMode, 0, 0);
  2879. /* Register callbacks */
  2880. ooH323EpSetH323Callbacks(h323Callbacks);
  2881. /* Add endpoint capabilities */
  2882. if (ooh323c_set_capability(&gPrefs, gCapability, gDTMFMode, gDTMFCodec) < 0) {
  2883. ast_log(LOG_ERROR, "Capabilities failure for OOH323. OOH323 Disabled.\n");
  2884. return 1;
  2885. }
  2886. /* Create H.323 listener */
  2887. if (ooCreateH323Listener() != OO_OK) {
  2888. ast_log(LOG_ERROR, "OOH323 Listener Creation failure. "
  2889. "OOH323 DISABLED\n");
  2890. ooH323EpDestroy();
  2891. return 1;
  2892. }
  2893. if (ooh323c_start_stack_thread() < 0) {
  2894. ast_log(LOG_ERROR, "Failed to start OOH323 stack thread. "
  2895. "OOH323 DISABLED\n");
  2896. ooH323EpDestroy();
  2897. return 1;
  2898. }
  2899. /* And start the monitor for the first time */
  2900. restart_monitor();
  2901. }
  2902. return 0;
  2903. }
  2904. static void *do_monitor(void *data)
  2905. {
  2906. int res;
  2907. int reloading;
  2908. struct ooh323_pvt *h323 = NULL;
  2909. time_t t;
  2910. for (;;) {
  2911. struct ooh323_pvt *h323_next;
  2912. /* Check for a reload request */
  2913. ast_mutex_lock(&h323_reload_lock);
  2914. reloading = h323_reloading;
  2915. h323_reloading = 0;
  2916. ast_mutex_unlock(&h323_reload_lock);
  2917. if (reloading) {
  2918. ast_verb(1, "Reloading H.323\n");
  2919. ooh323_do_reload();
  2920. }
  2921. /* Check for interfaces needing to be killed */
  2922. ast_mutex_lock(&iflock);
  2923. time(&t);
  2924. h323 = iflist;
  2925. while (h323) {
  2926. h323_next = h323->next;
  2927. /* TODO: Need to add rtptimeout keepalive support */
  2928. if (ast_test_flag(h323, H323_NEEDDESTROY)) {
  2929. ooh323_destroy (h323);
  2930. } /* else if (ast_test_flag(h323, H323_NEEDSTART) && h323->owner) {
  2931. ast_channel_lock(h323->owner);
  2932. if (ast_pbx_start(h323->owner)) {
  2933. ast_log(LOG_WARNING, "Unable to start PBX on %s\n", h323->owner->name);
  2934. ast_channel_unlock(h323->owner);
  2935. ast_hangup(h323->owner);
  2936. }
  2937. ast_channel_unlock(h323->owner);
  2938. ast_clear_flag(h323, H323_NEEDSTART);
  2939. } */
  2940. h323 = h323_next;
  2941. }
  2942. ast_mutex_unlock(&iflock);
  2943. pthread_testcancel();
  2944. /* Wait for sched or io */
  2945. res = ast_sched_wait(sched);
  2946. if ((res < 0) || (res > 1000)) {
  2947. res = 1000;
  2948. }
  2949. res = ast_io_wait(io, res);
  2950. pthread_testcancel();
  2951. ast_mutex_lock(&monlock);
  2952. if (res >= 0) {
  2953. ast_sched_runq(sched);
  2954. }
  2955. ast_mutex_unlock(&monlock);
  2956. }
  2957. /* Never reached */
  2958. return NULL;
  2959. }
  2960. int restart_monitor(void)
  2961. {
  2962. pthread_attr_t attr;
  2963. /* If we're supposed to be stopped -- stay stopped */
  2964. if (monitor_thread == AST_PTHREADT_STOP)
  2965. return 0;
  2966. if (ast_mutex_lock(&monlock)) {
  2967. ast_log(LOG_WARNING, "Unable to lock monitor\n");
  2968. return -1;
  2969. }
  2970. if (monitor_thread == pthread_self()) {
  2971. ast_mutex_unlock(&monlock);
  2972. ast_log(LOG_WARNING, "Cannot kill myself\n");
  2973. return -1;
  2974. }
  2975. if (monitor_thread != AST_PTHREADT_NULL) {
  2976. /* Wake up the thread */
  2977. pthread_kill(monitor_thread, SIGURG);
  2978. } else {
  2979. pthread_attr_init(&attr);
  2980. pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED);
  2981. /* Start a new monitor */
  2982. if (ast_pthread_create(&monitor_thread, &attr, do_monitor, NULL) < 0) {
  2983. ast_mutex_unlock(&monlock);
  2984. ast_log(LOG_ERROR, "Unable to start monitor thread.\n");
  2985. return -1;
  2986. }
  2987. }
  2988. ast_mutex_unlock(&monlock);
  2989. return 0;
  2990. }
  2991. int ooh323_destroy(struct ooh323_pvt *p)
  2992. {
  2993. /* NOTE: Assumes iflock already acquired */
  2994. struct ooh323_pvt *prev = NULL, *cur = NULL;
  2995. struct ooh323_user *user = NULL;
  2996. if (gH323Debug) {
  2997. ast_verbose("--- ooh323_destroy \n");
  2998. if (p)
  2999. ast_verbose(" Destroying %s\n", p->username);
  3000. }
  3001. cur = iflist;
  3002. while (cur) {
  3003. if (cur == p) { break; }
  3004. prev = cur;
  3005. cur = cur->next;
  3006. }
  3007. if (cur) {
  3008. ast_mutex_lock(&cur->lock);
  3009. if (prev)
  3010. prev->next = cur->next;
  3011. else
  3012. iflist = cur->next;
  3013. if (cur->callToken) {
  3014. if (gH323Debug)
  3015. ast_verbose(" Destroying %s\n", cur->callToken);
  3016. ast_free(cur->callToken);
  3017. cur->callToken = 0;
  3018. }
  3019. if (cur->username) {
  3020. free(cur->username);
  3021. cur->username = 0;
  3022. }
  3023. if (cur->host) {
  3024. free(cur->host);
  3025. cur->host = 0;
  3026. }
  3027. if (cur->callerid_name) {
  3028. free(cur->callerid_name);
  3029. cur->callerid_name = 0;
  3030. }
  3031. if (cur->callerid_num) {
  3032. free(cur->callerid_num);
  3033. cur->callerid_num = 0;
  3034. }
  3035. if (cur->rtp) {
  3036. ast_rtp_instance_destroy(cur->rtp);
  3037. cur->rtp = NULL;
  3038. }
  3039. if (cur->udptl) {
  3040. ast_udptl_destroy(cur->udptl);
  3041. cur->udptl = NULL;
  3042. }
  3043. /* Unlink us from the owner if we have one */
  3044. if (cur->owner) {
  3045. while(ast_channel_trylock(cur->owner)) {
  3046. ast_debug(1,"Failed to grab lock, trying again\n");
  3047. DEADLOCK_AVOIDANCE(&cur->lock);
  3048. }
  3049. ast_debug(1, "Detaching from %s\n", cur->owner->name);
  3050. cur->owner->tech_pvt = NULL;
  3051. ast_channel_unlock(cur->owner);
  3052. cur->owner = NULL;
  3053. ast_module_unref(myself);
  3054. }
  3055. if (cur->vad) {
  3056. ast_dsp_free(cur->vad);
  3057. cur->vad = NULL;
  3058. }
  3059. /* decrement user/peer count */
  3060. if(!ast_test_flag(cur, H323_OUTGOING)) {
  3061. if (cur->neighbor.user) {
  3062. user = find_user(p->callerid_name, cur->neighbor.user);
  3063. if(user && user->inUse > 0) {
  3064. ast_mutex_lock(&user->lock);
  3065. user->inUse--;
  3066. ast_mutex_unlock(&user->lock);
  3067. }
  3068. free(cur->neighbor.user);
  3069. }
  3070. } else {
  3071. /* outgoing limit decrement here !!! */
  3072. }
  3073. ast_mutex_unlock(&cur->lock);
  3074. ast_mutex_destroy(&cur->lock);
  3075. ast_free(cur);
  3076. }
  3077. if (gH323Debug)
  3078. ast_verbose("+++ ooh323_destroy\n");
  3079. return 0;
  3080. }
  3081. int delete_peers()
  3082. {
  3083. struct ooh323_peer *cur = NULL, *prev = NULL;
  3084. ast_mutex_lock(&peerl.lock);
  3085. cur = peerl.peers;
  3086. while (cur) {
  3087. prev = cur;
  3088. cur = cur->next;
  3089. ast_mutex_destroy(&prev->lock);
  3090. if(prev->h323id) free(prev->h323id);
  3091. if(prev->email) free(prev->email);
  3092. if(prev->url) free(prev->url);
  3093. if(prev->e164) free(prev->e164);
  3094. if(prev->rtpmask) {
  3095. ast_mutex_lock(&prev->rtpmask->lock);
  3096. prev->rtpmask->inuse--;
  3097. ast_mutex_unlock(&prev->rtpmask->lock);
  3098. if (prev->rtpmask->inuse == 0) {
  3099. regfree(&prev->rtpmask->regex);
  3100. ast_mutex_destroy(&prev->rtpmask->lock);
  3101. free(prev->rtpmask);
  3102. }
  3103. }
  3104. free(prev);
  3105. if (cur == peerl.peers) {
  3106. break;
  3107. }
  3108. }
  3109. peerl.peers = NULL;
  3110. ast_mutex_unlock(&peerl.lock);
  3111. return 0;
  3112. }
  3113. int delete_users()
  3114. {
  3115. struct ooh323_user *cur = NULL, *prev = NULL;
  3116. ast_mutex_lock(&userl.lock);
  3117. cur = userl.users;
  3118. while (cur) {
  3119. prev = cur;
  3120. cur = cur->next;
  3121. ast_mutex_destroy(&prev->lock);
  3122. if(prev->rtpmask) {
  3123. ast_mutex_lock(&prev->rtpmask->lock);
  3124. prev->rtpmask->inuse--;
  3125. ast_mutex_unlock(&prev->rtpmask->lock);
  3126. if (prev->rtpmask->inuse == 0) {
  3127. regfree(&prev->rtpmask->regex);
  3128. ast_mutex_destroy(&prev->rtpmask->lock);
  3129. free(prev->rtpmask);
  3130. }
  3131. }
  3132. free(prev);
  3133. if (cur == userl.users) {
  3134. break;
  3135. }
  3136. }
  3137. userl.users = NULL;
  3138. ast_mutex_unlock(&userl.lock);
  3139. return 0;
  3140. }
  3141. static int unload_module(void)
  3142. {
  3143. struct ooh323_pvt *p;
  3144. struct ooAliases *cur = NULL, *prev = NULL;
  3145. if (gH323Debug) {
  3146. ast_verbose("--- ooh323 unload_module \n");
  3147. }
  3148. /* First, take us out of the channel loop */
  3149. ast_cli_unregister_multiple(cli_ooh323, sizeof(cli_ooh323) / sizeof(struct ast_cli_entry));
  3150. ast_rtp_glue_unregister(&ooh323_rtp);
  3151. ast_udptl_proto_unregister(&ooh323_udptl);
  3152. ast_channel_unregister(&ooh323_tech);
  3153. #if 0
  3154. ast_unregister_atexit(&ast_ooh323c_exit);
  3155. #endif
  3156. if (gH323Debug) {
  3157. ast_verbose(" unload_module - hanging up all interfaces\n");
  3158. }
  3159. if (!ast_mutex_lock(&iflock)) {
  3160. /* Hangup all interfaces if they have an owner */
  3161. p = iflist;
  3162. while (p) {
  3163. if (p->owner) {
  3164. ast_softhangup(p->owner, AST_SOFTHANGUP_APPUNLOAD);
  3165. }
  3166. p = p->next;
  3167. }
  3168. iflist = NULL;
  3169. ast_mutex_unlock(&iflock);
  3170. } else {
  3171. ast_log(LOG_WARNING, "Unable to lock the interface list\n");
  3172. return -1;
  3173. }
  3174. if (gH323Debug) {
  3175. ast_verbose(" unload_module - stopping monitor thread\n");
  3176. }
  3177. if (monitor_thread != AST_PTHREADT_NULL) {
  3178. if (!ast_mutex_lock(&monlock)) {
  3179. if (monitor_thread && (monitor_thread != AST_PTHREADT_STOP)) {
  3180. pthread_cancel(monitor_thread);
  3181. pthread_kill(monitor_thread, SIGURG);
  3182. pthread_join(monitor_thread, NULL);
  3183. }
  3184. monitor_thread = AST_PTHREADT_STOP;
  3185. ast_mutex_unlock(&monlock);
  3186. } else {
  3187. ast_log(LOG_WARNING, "Unable to lock the monitor\n");
  3188. return -1;
  3189. }
  3190. }
  3191. if (gH323Debug) {
  3192. ast_verbose(" unload_module - stopping stack thread\n");
  3193. }
  3194. ooh323c_stop_stack_thread();
  3195. if (gH323Debug) {
  3196. ast_verbose(" unload_module - freeing up memory used by interfaces\n");
  3197. }
  3198. if (!ast_mutex_lock(&iflock)) {
  3199. struct ooh323_pvt *pl;
  3200. /* Destroy all the interfaces and free their memory */
  3201. p = iflist;
  3202. while (p) {
  3203. pl = p;
  3204. p = p->next;
  3205. /* Free associated memory */
  3206. ooh323_destroy(pl);
  3207. }
  3208. iflist = NULL;
  3209. ast_mutex_unlock(&iflock);
  3210. } else {
  3211. ast_log(LOG_WARNING, "Unable to lock the interface list\n");
  3212. return -1;
  3213. }
  3214. if (gH323Debug) {
  3215. ast_verbose(" unload_module - deleting users\n");
  3216. }
  3217. delete_users();
  3218. if (gH323Debug) {
  3219. ast_verbose(" unload_module - deleting peers\n");
  3220. }
  3221. delete_peers();
  3222. if (gH323Debug) {
  3223. ast_verbose(" unload_module - Freeing up alias list\n");
  3224. }
  3225. cur = gAliasList;
  3226. while (cur) {
  3227. prev = cur;
  3228. cur = cur->next;
  3229. free(prev->value);
  3230. free(prev);
  3231. }
  3232. gAliasList = NULL;
  3233. if (gH323Debug) {
  3234. ast_verbose(" unload_module- destroying OOH323 endpoint \n");
  3235. }
  3236. ooH323EpDestroy();
  3237. if (gH323Debug) {
  3238. ast_verbose("+++ ooh323 unload_module \n");
  3239. }
  3240. return 0;
  3241. }
  3242. static enum ast_rtp_glue_result ooh323_get_rtp_peer(struct ast_channel *chan, struct ast_rtp_instance **rtp)
  3243. {
  3244. struct ooh323_pvt *p = NULL;
  3245. enum ast_rtp_glue_result res = AST_RTP_GLUE_RESULT_LOCAL;
  3246. if (!(p = (struct ooh323_pvt *) chan->tech_pvt))
  3247. return AST_RTP_GLUE_RESULT_FORBID;
  3248. if (!(p->rtp)) {
  3249. return AST_RTP_GLUE_RESULT_FORBID;
  3250. }
  3251. *rtp = p->rtp ? ao2_ref(p->rtp, +1), p->rtp : NULL;
  3252. res = AST_RTP_GLUE_RESULT_LOCAL;
  3253. if (ast_test_flag(&global_jbconf, AST_JB_FORCED)) {
  3254. res = AST_RTP_GLUE_RESULT_FORBID;
  3255. }
  3256. return res;
  3257. }
  3258. static enum ast_rtp_glue_result ooh323_get_vrtp_peer(struct ast_channel *chan, struct ast_rtp_instance **rtp)
  3259. {
  3260. struct ooh323_pvt *p = NULL;
  3261. enum ast_rtp_glue_result res = AST_RTP_GLUE_RESULT_LOCAL;
  3262. if (!(p = (struct ooh323_pvt *) chan->tech_pvt))
  3263. return AST_RTP_GLUE_RESULT_FORBID;
  3264. if (!(p->rtp)) {
  3265. return AST_RTP_GLUE_RESULT_FORBID;
  3266. }
  3267. *rtp = p->vrtp ? ao2_ref(p->vrtp, +1), p->vrtp : NULL;
  3268. res = AST_RTP_GLUE_RESULT_LOCAL;
  3269. return res;
  3270. }
  3271. int ooh323_update_capPrefsOrderForCall
  3272. (ooCallData *call, struct ast_codec_pref *prefs)
  3273. {
  3274. int i = 0;
  3275. int codec = ast_codec_pref_index(prefs, i);
  3276. ooResetCapPrefs(call);
  3277. while (codec) {
  3278. ooAppendCapToCapPrefs(call, ooh323_convertAsteriskCapToH323Cap(codec));
  3279. codec = ast_codec_pref_index(prefs, ++i);
  3280. }
  3281. return 0;
  3282. }
  3283. int ooh323_convertAsteriskCapToH323Cap(format_t cap)
  3284. {
  3285. char formats[FORMAT_STRING_SIZE];
  3286. switch (cap) {
  3287. case AST_FORMAT_ULAW:
  3288. return OO_G711ULAW64K;
  3289. case AST_FORMAT_ALAW:
  3290. return OO_G711ALAW64K;
  3291. case AST_FORMAT_GSM:
  3292. return OO_GSMFULLRATE;
  3293. #ifdef AST_FORMAT_AMRNB
  3294. case AST_FORMAT_AMRNB:
  3295. return OO_AMRNB;
  3296. #endif
  3297. #ifdef AST_FORMAT_SPEEX
  3298. case AST_FORMAT_SPEEX:
  3299. return OO_SPEEX;
  3300. #endif
  3301. case AST_FORMAT_G729A:
  3302. return OO_G729A;
  3303. case AST_FORMAT_G726:
  3304. return OO_G726;
  3305. case AST_FORMAT_G726_AAL2:
  3306. return OO_G726AAL2;
  3307. case AST_FORMAT_G723_1:
  3308. return OO_G7231;
  3309. case AST_FORMAT_H263:
  3310. return OO_H263VIDEO;
  3311. default:
  3312. ast_log(LOG_NOTICE, "Don't know how to deal with mode %s\n",
  3313. ast_getformatname_multiple(formats,FORMAT_STRING_SIZE,cap));
  3314. return -1;
  3315. }
  3316. }
  3317. static int ooh323_set_rtp_peer(struct ast_channel *chan, struct ast_rtp_instance *rtp,
  3318. struct ast_rtp_instance *vrtp, struct ast_rtp_instance *trtp, format_t codecs, int nat_active)
  3319. {
  3320. /* XXX Deal with Video */
  3321. struct ooh323_pvt *p;
  3322. struct sockaddr_in them;
  3323. struct sockaddr_in us;
  3324. struct ast_sockaddr tmp;
  3325. if (gH323Debug)
  3326. ast_verbose("--- ooh323_set_peer - %s\n", chan->name);
  3327. if (!rtp) {
  3328. return 0;
  3329. }
  3330. p = (struct ooh323_pvt *) chan->tech_pvt;
  3331. if (!p) {
  3332. ast_log(LOG_ERROR, "No Private Structure, this is bad\n");
  3333. return -1;
  3334. }
  3335. ast_rtp_instance_get_remote_address(rtp, &tmp);
  3336. ast_sockaddr_to_sin(&tmp, &them);
  3337. ast_rtp_instance_get_local_address(rtp, &tmp);
  3338. ast_sockaddr_to_sin(&tmp, &us);
  3339. return 0;
  3340. }
  3341. int configure_local_rtp(struct ooh323_pvt *p, ooCallData *call)
  3342. {
  3343. struct sockaddr_in us;
  3344. struct ast_sockaddr tmp;
  3345. ooMediaInfo mediaInfo;
  3346. int x;
  3347. format_t format = 0;
  3348. if (gH323Debug)
  3349. ast_verbose("--- configure_local_rtp\n");
  3350. if (p->rtp) {
  3351. ast_rtp_codecs_packetization_set(ast_rtp_instance_get_codecs(p->rtp), p->rtp, &p->prefs);
  3352. if (p->dtmfmode & H323_DTMF_RFC2833 && p->dtmfcodec) {
  3353. ast_rtp_instance_set_prop(p->rtp, AST_RTP_PROPERTY_DTMF, 1);
  3354. ast_rtp_codecs_payloads_set_rtpmap_type(ast_rtp_instance_get_codecs(p->rtp),
  3355. p->rtp, p->dtmfcodec, "audio", "telephone-event", 0);
  3356. }
  3357. if (p->dtmfmode & H323_DTMF_CISCO && p->dtmfcodec) {
  3358. ast_rtp_instance_set_prop(p->rtp, AST_RTP_PROPERTY_DTMF, 1);
  3359. ast_rtp_codecs_payloads_set_rtpmap_type(ast_rtp_instance_get_codecs(p->rtp),
  3360. p->rtp, p->dtmfcodec, "audio", "cisco-telephone-event", 0);
  3361. }
  3362. /* figure out our local RTP port and tell the H.323 stack about it*/
  3363. ast_rtp_instance_get_local_address(p->rtp, &tmp);
  3364. ast_sockaddr_to_sin(&tmp, &us);
  3365. if (p->rtptimeout) {
  3366. ast_rtp_instance_set_timeout(p->rtp, p->rtptimeout);
  3367. }
  3368. ast_rtp_instance_set_prop(p->rtp, AST_RTP_PROPERTY_RTCP, 1);
  3369. }
  3370. if (p->rtdrcount) {
  3371. if (gH323Debug)
  3372. ast_verbose("Setup RTDR info: %d, %d\n", p->rtdrinterval, p->rtdrcount);
  3373. call->rtdrInterval = p->rtdrinterval;
  3374. call->rtdrCount = p->rtdrcount;
  3375. }
  3376. ast_copy_string(mediaInfo.lMediaIP, ast_inet_ntoa(us.sin_addr), sizeof(mediaInfo.lMediaIP));
  3377. mediaInfo.lMediaPort = ntohs(us.sin_port);
  3378. mediaInfo.lMediaCntrlPort = mediaInfo.lMediaPort +1;
  3379. for (x = 0; 0 != (format = ast_codec_pref_index(&p->prefs, x)); x++) {
  3380. strcpy(mediaInfo.dir, "transmit");
  3381. mediaInfo.cap = ooh323_convertAsteriskCapToH323Cap(format);
  3382. ooAddMediaInfo(call, mediaInfo);
  3383. strcpy(mediaInfo.dir, "receive");
  3384. ooAddMediaInfo(call, mediaInfo);
  3385. if (mediaInfo.cap == OO_G729A) {
  3386. strcpy(mediaInfo.dir, "transmit");
  3387. mediaInfo.cap = OO_G729;
  3388. ooAddMediaInfo(call, mediaInfo);
  3389. strcpy(mediaInfo.dir, "receive");
  3390. ooAddMediaInfo(call, mediaInfo);
  3391. strcpy(mediaInfo.dir, "transmit");
  3392. mediaInfo.cap = OO_G729B;
  3393. ooAddMediaInfo(call, mediaInfo);
  3394. strcpy(mediaInfo.dir, "receive");
  3395. ooAddMediaInfo(call, mediaInfo);
  3396. }
  3397. }
  3398. if (p->udptl) {
  3399. struct ast_sockaddr us_tmp;
  3400. ast_sockaddr_from_sin(&us_tmp, &us);
  3401. ast_udptl_get_us(p->udptl, &us_tmp);
  3402. ast_sockaddr_to_sin(&us_tmp, &us);
  3403. }
  3404. ast_copy_string(mediaInfo.lMediaIP, ast_inet_ntoa(us.sin_addr), sizeof(mediaInfo.lMediaIP));
  3405. mediaInfo.lMediaPort = ntohs(us.sin_port);
  3406. mediaInfo.lMediaCntrlPort = mediaInfo.lMediaPort +1;
  3407. mediaInfo.cap = OO_T38;
  3408. strcpy(mediaInfo.dir, "transmit");
  3409. ooAddMediaInfo(call, mediaInfo);
  3410. strcpy(mediaInfo.dir, "receive");
  3411. ooAddMediaInfo(call, mediaInfo);
  3412. if (gH323Debug)
  3413. ast_verbose("+++ configure_local_rtp\n");
  3414. return 1;
  3415. }
  3416. void setup_rtp_connection(ooCallData *call, const char *remoteIp,
  3417. int remotePort)
  3418. {
  3419. struct ooh323_pvt *p = NULL;
  3420. struct sockaddr_in them;
  3421. struct ast_sockaddr tmp;
  3422. if (gH323Debug)
  3423. ast_verbose("--- setup_rtp_connection %s:%d\n", remoteIp, remotePort);
  3424. /* Find the call or allocate a private structure if call not found */
  3425. p = find_call(call);
  3426. if (!p) {
  3427. ast_log(LOG_ERROR, "Something is wrong: rtp\n");
  3428. return;
  3429. }
  3430. them.sin_family = AF_INET;
  3431. them.sin_addr.s_addr = inet_addr(remoteIp); /* only works for IPv4 */
  3432. them.sin_port = htons(remotePort);
  3433. ast_sockaddr_from_sin(&tmp, &them);
  3434. ast_rtp_instance_set_remote_address(p->rtp, &tmp);
  3435. if (p->writeformat & AST_FORMAT_G726_AAL2)
  3436. ast_rtp_codecs_payloads_set_rtpmap_type(ast_rtp_instance_get_codecs(p->rtp), p->rtp, 2,
  3437. "audio", "G726-32", AST_RTP_OPT_G726_NONSTANDARD);
  3438. if(gH323Debug)
  3439. ast_verbose("+++ setup_rtp_connection\n");
  3440. return;
  3441. }
  3442. void close_rtp_connection(ooCallData *call)
  3443. {
  3444. struct ooh323_pvt *p = NULL;
  3445. if(gH323Debug)
  3446. ast_verbose("--- close_rtp_connection\n");
  3447. p = find_call(call);
  3448. if (!p) {
  3449. ast_log(LOG_ERROR, "Couldn't find matching call to close rtp "
  3450. "connection\n");
  3451. return;
  3452. }
  3453. ast_mutex_lock(&p->lock);
  3454. if (p->rtp) {
  3455. ast_rtp_instance_stop(p->rtp);
  3456. }
  3457. ast_mutex_unlock(&p->lock);
  3458. if(gH323Debug)
  3459. ast_verbose("+++ close_rtp_connection\n");
  3460. return;
  3461. }
  3462. /*
  3463. udptl handling functions
  3464. */
  3465. static struct ast_udptl *ooh323_get_udptl_peer(struct ast_channel *chan)
  3466. {
  3467. struct ooh323_pvt *p;
  3468. struct ast_udptl *udptl = NULL;
  3469. p = chan->tech_pvt;
  3470. if (!p)
  3471. return NULL;
  3472. ast_mutex_lock(&p->lock);
  3473. if (p->udptl)
  3474. udptl = p->udptl;
  3475. ast_mutex_unlock(&p->lock);
  3476. return udptl;
  3477. }
  3478. static int ooh323_set_udptl_peer(struct ast_channel *chan, struct ast_udptl *udptl)
  3479. {
  3480. struct ooh323_pvt *p;
  3481. p = chan->tech_pvt;
  3482. if (!p)
  3483. return -1;
  3484. ast_mutex_lock(&p->lock);
  3485. if (udptl) {
  3486. struct ast_sockaddr udptl_addr;
  3487. ast_udptl_get_peer(udptl, &udptl_addr);
  3488. ast_sockaddr_to_sin(&udptl_addr, &p->udptlredirip);
  3489. } else
  3490. memset(&p->udptlredirip, 0, sizeof(p->udptlredirip));
  3491. ast_mutex_unlock(&p->lock);
  3492. return 0;
  3493. }
  3494. void setup_udptl_connection(ooCallData *call, const char *remoteIp,
  3495. int remotePort)
  3496. {
  3497. struct ooh323_pvt *p = NULL;
  3498. struct sockaddr_in them;
  3499. struct ast_sockaddr them_addr;
  3500. if (gH323Debug)
  3501. ast_verbose("--- setup_udptl_connection\n");
  3502. /* Find the call or allocate a private structure if call not found */
  3503. p = find_call(call);
  3504. if (!p) {
  3505. ast_log(LOG_ERROR, "Something is wrong: rtp\n");
  3506. return;
  3507. }
  3508. ast_mutex_lock(&p->lock);
  3509. if (p->owner) {
  3510. while (p->owner && ast_channel_trylock(p->owner)) {
  3511. ast_debug(1,"Failed to grab lock, trying again\n");
  3512. DEADLOCK_AVOIDANCE(&p->lock);
  3513. }
  3514. if (!p->owner) {
  3515. ast_mutex_unlock(&p->lock);
  3516. ast_log(LOG_ERROR, "Channel has no owner\n");
  3517. return;
  3518. }
  3519. } else {
  3520. ast_mutex_unlock(&p->lock);
  3521. ast_log(LOG_ERROR, "Channel has no owner\n");
  3522. return;
  3523. }
  3524. them.sin_family = AF_INET;
  3525. them.sin_addr.s_addr = inet_addr(remoteIp); /* only works for IPv4 */
  3526. them.sin_port = htons(remotePort);
  3527. ast_sockaddr_from_sin(&them_addr, &them);
  3528. ast_udptl_set_peer(p->udptl, &them_addr);
  3529. ast_udptl_set_tag(p->udptl, "%s", p->owner->name);
  3530. p->t38_tx_enable = 1;
  3531. p->lastTxT38 = time(NULL);
  3532. if (p->t38support == T38_ENABLED) {
  3533. struct ast_control_t38_parameters parameters = { .request_response = 0 };
  3534. parameters.request_response = AST_T38_NEGOTIATED;
  3535. parameters.max_ifp = ast_udptl_get_far_max_ifp(p->udptl);
  3536. parameters.rate = AST_T38_RATE_14400;
  3537. ast_queue_control_data(p->owner, AST_CONTROL_T38_PARAMETERS, &parameters, sizeof(parameters));
  3538. }
  3539. if (gH323Debug)
  3540. ast_debug(1, "Receiving UDPTL %s:%d\n", ast_inet_ntoa(them.sin_addr),
  3541. ntohs(them.sin_port));
  3542. ast_channel_unlock(p->owner);
  3543. ast_mutex_unlock(&p->lock);
  3544. if(gH323Debug)
  3545. ast_verbose("+++ setup_udptl_connection\n");
  3546. return;
  3547. }
  3548. void close_udptl_connection(ooCallData *call)
  3549. {
  3550. struct ooh323_pvt *p = NULL;
  3551. if(gH323Debug)
  3552. ast_verbose("--- close_udptl_connection\n");
  3553. p = find_call(call);
  3554. if (!p) {
  3555. ast_log(LOG_ERROR, "Couldn't find matching call to close udptl "
  3556. "connection\n");
  3557. return;
  3558. }
  3559. ast_mutex_lock(&p->lock);
  3560. if (p->owner) {
  3561. while (p->owner && ast_channel_trylock(p->owner)) {
  3562. ast_debug(1,"Failed to grab lock, trying again\n");
  3563. DEADLOCK_AVOIDANCE(&p->lock);
  3564. }
  3565. if (!p->owner) {
  3566. ast_mutex_unlock(&p->lock);
  3567. ast_log(LOG_ERROR, "Channel has no owner\n");
  3568. return;
  3569. }
  3570. } else {
  3571. ast_mutex_unlock(&p->lock);
  3572. ast_log(LOG_ERROR, "Channel has no owner\n");
  3573. return;
  3574. }
  3575. p->t38_tx_enable = 0;
  3576. if (p->t38support == T38_ENABLED) {
  3577. struct ast_control_t38_parameters parameters = { .request_response = 0 };
  3578. parameters.request_response = AST_T38_TERMINATED;
  3579. ast_queue_control_data(p->owner, AST_CONTROL_T38_PARAMETERS, &parameters, sizeof(parameters));
  3580. }
  3581. ast_channel_unlock(p->owner);
  3582. ast_mutex_unlock(&p->lock);
  3583. if(gH323Debug)
  3584. ast_verbose("+++ close_udptl_connection\n");
  3585. return;
  3586. }
  3587. /* end of udptl handling */
  3588. int update_our_aliases(ooCallData *call, struct ooh323_pvt *p)
  3589. {
  3590. int updated = -1;
  3591. ooAliases *psAlias = NULL;
  3592. if (!call->ourAliases)
  3593. return updated;
  3594. for (psAlias = call->ourAliases; psAlias; psAlias = psAlias->next) {
  3595. if (psAlias->type == T_H225AliasAddress_h323_ID) {
  3596. ast_copy_string(p->callee_h323id, psAlias->value, sizeof(p->callee_h323id));
  3597. updated = 1;
  3598. }
  3599. if (psAlias->type == T_H225AliasAddress_dialedDigits) {
  3600. ast_copy_string(p->callee_dialedDigits, psAlias->value,
  3601. sizeof(p->callee_dialedDigits));
  3602. updated = 1;
  3603. }
  3604. if (psAlias->type == T_H225AliasAddress_url_ID) {
  3605. ast_copy_string(p->callee_url, psAlias->value, sizeof(p->callee_url));
  3606. updated = 1;
  3607. }
  3608. if (psAlias->type == T_H225AliasAddress_email_ID) {
  3609. ast_copy_string(p->callee_email, psAlias->value, sizeof(p->callee_email));
  3610. updated = 1;
  3611. }
  3612. }
  3613. return updated;
  3614. }
  3615. struct ast_frame *ooh323_rtp_read(struct ast_channel *ast, struct ooh323_pvt *p)
  3616. {
  3617. /* Retrieve audio/etc from channel. Assumes p->lock is already held. */
  3618. struct ast_frame *f;
  3619. static struct ast_frame null_frame = { AST_FRAME_NULL, };
  3620. switch (ast->fdno) {
  3621. case 0:
  3622. f = ast_rtp_instance_read(p->rtp, 0); /* RTP Audio */
  3623. break;
  3624. case 1:
  3625. f = ast_rtp_instance_read(p->rtp, 1); /* RTCP Control Channel */
  3626. break;
  3627. case 2:
  3628. f = ast_rtp_instance_read(p->vrtp, 0); /* RTP Video */
  3629. break;
  3630. case 3:
  3631. f = ast_rtp_instance_read(p->vrtp, 1); /* RTCP Control Channel for video */
  3632. break;
  3633. case 5:
  3634. f = ast_udptl_read(p->udptl); /* UDPTL t.38 data */
  3635. if (gH323Debug) ast_debug(1, "Got UDPTL %d/%d len %d for %s\n",
  3636. f->frametype, f->subclass.integer, f->datalen, ast->name);
  3637. break;
  3638. default:
  3639. f = &null_frame;
  3640. }
  3641. if (f && p->owner) {
  3642. /* We already hold the channel lock */
  3643. if (f->frametype == AST_FRAME_VOICE && !p->faxmode) {
  3644. if (f->subclass.codec != p->owner->nativeformats) {
  3645. ast_debug(1, "Oooh, voice format changed to %s\n", ast_getformatname(f->subclass.codec));
  3646. p->owner->nativeformats = f->subclass.codec;
  3647. ast_set_read_format(p->owner, p->owner->readformat);
  3648. ast_set_write_format(p->owner, p->owner->writeformat);
  3649. }
  3650. if ((p->dtmfmode & H323_DTMF_INBAND) && p->vad &&
  3651. (f->subclass.codec == AST_FORMAT_SLINEAR || f->subclass.codec == AST_FORMAT_ALAW ||
  3652. f->subclass.codec == AST_FORMAT_ULAW)) {
  3653. f = ast_dsp_process(p->owner, p->vad, f);
  3654. if (f && (f->frametype == AST_FRAME_DTMF))
  3655. ast_debug(1, "* Detected inband DTMF '%c'\n", f->subclass.integer);
  3656. }
  3657. }
  3658. }
  3659. return f;
  3660. }
  3661. void onModeChanged(ooCallData *call, int t38mode) {
  3662. struct ooh323_pvt *p;
  3663. p = find_call(call);
  3664. if (!p) {
  3665. ast_log(LOG_ERROR, "No matching call found for %s\n", call->callToken);
  3666. return;
  3667. }
  3668. ast_mutex_lock(&p->lock);
  3669. if (gH323Debug)
  3670. ast_debug(1, "change mode to %d for %s\n", t38mode, call->callToken);
  3671. if (t38mode == p->faxmode) {
  3672. if (gH323Debug)
  3673. ast_debug(1, "mode for %s is already %d\n", call->callToken,
  3674. t38mode);
  3675. ast_mutex_unlock(&p->lock);
  3676. return;
  3677. }
  3678. if (p->owner) {
  3679. while (p->owner && ast_channel_trylock(p->owner)) {
  3680. ast_debug(1,"Failed to grab lock, trying again\n");
  3681. DEADLOCK_AVOIDANCE(&p->lock);
  3682. }
  3683. if (!p->owner) {
  3684. ast_mutex_unlock(&p->lock);
  3685. ast_log(LOG_ERROR, "Channel has no owner\n");
  3686. return;
  3687. }
  3688. } else {
  3689. ast_mutex_unlock(&p->lock);
  3690. ast_log(LOG_ERROR, "Channel has no owner\n");
  3691. return;
  3692. }
  3693. if (t38mode) {
  3694. if (p->t38support == T38_ENABLED) {
  3695. /* AST_T38_CONTROL mode */
  3696. struct ast_control_t38_parameters parameters = { .request_response = 0 };
  3697. parameters.request_response = AST_T38_REQUEST_NEGOTIATE;
  3698. if (call->T38FarMaxDatagram) {
  3699. ast_udptl_set_far_max_datagram(p->udptl, call->T38FarMaxDatagram);
  3700. } else {
  3701. ast_udptl_set_far_max_datagram(p->udptl, 144);
  3702. }
  3703. if (call->T38Version) {
  3704. parameters.version = call->T38Version;
  3705. }
  3706. parameters.max_ifp = ast_udptl_get_far_max_ifp(p->udptl);
  3707. parameters.rate = AST_T38_RATE_14400;
  3708. ast_queue_control_data(p->owner, AST_CONTROL_T38_PARAMETERS,
  3709. &parameters, sizeof(parameters));
  3710. p->faxmode = 1;
  3711. }
  3712. } else {
  3713. if (p->t38support == T38_ENABLED) {
  3714. struct ast_control_t38_parameters parameters = { .request_response = 0 };
  3715. parameters.request_response = AST_T38_REQUEST_TERMINATE;
  3716. parameters.max_ifp = ast_udptl_get_far_max_ifp(p->udptl);
  3717. parameters.rate = AST_T38_RATE_14400;
  3718. ast_queue_control_data(p->owner, AST_CONTROL_T38_PARAMETERS,
  3719. &parameters, sizeof(parameters));
  3720. }
  3721. p->faxmode = 0;
  3722. p->t38_init = 0;
  3723. }
  3724. p->chmodepend = 0;
  3725. ast_channel_unlock(p->owner);
  3726. ast_mutex_unlock(&p->lock);
  3727. }
  3728. int ooh323_convert_hangupcause_asteriskToH323(int cause)
  3729. {
  3730. switch (cause) {
  3731. case AST_CAUSE_CALL_REJECTED:
  3732. return OO_REASON_REMOTE_REJECTED;
  3733. case AST_CAUSE_UNALLOCATED:
  3734. return OO_REASON_NOUSER;
  3735. case AST_CAUSE_BUSY:
  3736. return OO_REASON_REMOTE_BUSY;
  3737. case AST_CAUSE_BEARERCAPABILITY_NOTAVAIL:
  3738. return OO_REASON_NOCOMMON_CAPABILITIES;
  3739. case AST_CAUSE_CONGESTION:
  3740. return OO_REASON_REMOTE_BUSY;
  3741. case AST_CAUSE_NO_ANSWER:
  3742. return OO_REASON_REMOTE_NOANSWER;
  3743. case AST_CAUSE_NORMAL:
  3744. return OO_REASON_REMOTE_CLEARED;
  3745. case AST_CAUSE_FAILURE:
  3746. default:
  3747. return OO_REASON_UNKNOWN;
  3748. }
  3749. return 0;
  3750. }
  3751. int ooh323_convert_hangupcause_h323ToAsterisk(int cause)
  3752. {
  3753. switch (cause) {
  3754. case OO_REASON_REMOTE_REJECTED:
  3755. return AST_CAUSE_CALL_REJECTED;
  3756. case OO_REASON_NOUSER:
  3757. return AST_CAUSE_UNALLOCATED;
  3758. case OO_REASON_REMOTE_BUSY:
  3759. case OO_REASON_LOCAL_BUSY:
  3760. return AST_CAUSE_BUSY;
  3761. case OO_REASON_NOCOMMON_CAPABILITIES: /* No codecs approved */
  3762. return AST_CAUSE_BEARERCAPABILITY_NOTAVAIL;
  3763. case OO_REASON_REMOTE_CONGESTED:
  3764. case OO_REASON_LOCAL_CONGESTED:
  3765. return AST_CAUSE_CONGESTION;
  3766. case OO_REASON_REMOTE_NOANSWER:
  3767. return AST_CAUSE_NO_ANSWER;
  3768. case OO_REASON_UNKNOWN:
  3769. case OO_REASON_INVALIDMESSAGE:
  3770. case OO_REASON_TRANSPORTFAILURE:
  3771. return AST_CAUSE_FAILURE;
  3772. case OO_REASON_REMOTE_CLEARED:
  3773. return AST_CAUSE_NORMAL;
  3774. default:
  3775. return AST_CAUSE_NORMAL;
  3776. }
  3777. /* Never reached */
  3778. return 0;
  3779. }
  3780. #if 0
  3781. void ast_ooh323c_exit()
  3782. {
  3783. ooGkClientDestroy();
  3784. }
  3785. #endif
  3786. AST_MODULE_INFO_STANDARD(ASTERISK_GPL_KEY, "Objective Systems H323 Channel");