l3dss1.c 81 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227
  1. /* $Id: l3dss1.c,v 2.32.2.3 2004/01/13 14:31:25 keil Exp $
  2. *
  3. * EURO/DSS1 D-channel protocol
  4. *
  5. * German 1TR6 D-channel protocol
  6. *
  7. * Author Karsten Keil
  8. * based on the teles driver from Jan den Ouden
  9. * Copyright by Karsten Keil <keil@isdn4linux.de>
  10. *
  11. * This software may be used and distributed according to the terms
  12. * of the GNU General Public License, incorporated herein by reference.
  13. *
  14. * For changes and modifications please read
  15. * Documentation/isdn/HiSax.cert
  16. *
  17. * Thanks to Jan den Ouden
  18. * Fritz Elfert
  19. *
  20. */
  21. #include "hisax.h"
  22. #include "isdnl3.h"
  23. #include "l3dss1.h"
  24. #include <linux/ctype.h>
  25. #include <linux/slab.h>
  26. extern char *HiSax_getrev(const char *revision);
  27. static const char *dss1_revision = "$Revision: 2.32.2.3 $";
  28. #define EXT_BEARER_CAPS 1
  29. #define MsgHead(ptr, cref, mty) \
  30. *ptr++ = 0x8; \
  31. if (cref == -1) { \
  32. *ptr++ = 0x0; \
  33. } else { \
  34. *ptr++ = 0x1; \
  35. *ptr++ = cref^0x80; \
  36. } \
  37. *ptr++ = mty
  38. /**********************************************/
  39. /* get a new invoke id for remote operations. */
  40. /* Only a return value != 0 is valid */
  41. /**********************************************/
  42. static unsigned char new_invoke_id(struct PStack *p)
  43. {
  44. unsigned char retval;
  45. int i;
  46. i = 32; /* maximum search depth */
  47. retval = p->prot.dss1.last_invoke_id + 1; /* try new id */
  48. while ((i) && (p->prot.dss1.invoke_used[retval >> 3] == 0xFF)) {
  49. p->prot.dss1.last_invoke_id = (retval & 0xF8) + 8;
  50. i--;
  51. }
  52. if (i) {
  53. while (p->prot.dss1.invoke_used[retval >> 3] & (1 << (retval & 7)))
  54. retval++;
  55. } else
  56. retval = 0;
  57. p->prot.dss1.last_invoke_id = retval;
  58. p->prot.dss1.invoke_used[retval >> 3] |= (1 << (retval & 7));
  59. return(retval);
  60. } /* new_invoke_id */
  61. /*************************/
  62. /* free a used invoke id */
  63. /*************************/
  64. static void free_invoke_id(struct PStack *p, unsigned char id)
  65. {
  66. if (!id) return; /* 0 = invalid value */
  67. p->prot.dss1.invoke_used[id >> 3] &= ~(1 << (id & 7));
  68. } /* free_invoke_id */
  69. /**********************************************************/
  70. /* create a new l3 process and fill in dss1 specific data */
  71. /**********************************************************/
  72. static struct l3_process
  73. *dss1_new_l3_process(struct PStack *st, int cr)
  74. { struct l3_process *proc;
  75. if (!(proc = new_l3_process(st, cr)))
  76. return(NULL);
  77. proc->prot.dss1.invoke_id = 0;
  78. proc->prot.dss1.remote_operation = 0;
  79. proc->prot.dss1.uus1_data[0] = '\0';
  80. return(proc);
  81. } /* dss1_new_l3_process */
  82. /************************************************/
  83. /* free a l3 process and all dss1 specific data */
  84. /************************************************/
  85. static void
  86. dss1_release_l3_process(struct l3_process *p)
  87. {
  88. free_invoke_id(p->st,p->prot.dss1.invoke_id);
  89. release_l3_process(p);
  90. } /* dss1_release_l3_process */
  91. /********************************************************/
  92. /* search a process with invoke id id and dummy callref */
  93. /********************************************************/
  94. static struct l3_process *
  95. l3dss1_search_dummy_proc(struct PStack *st, int id)
  96. { struct l3_process *pc = st->l3.proc; /* start of processes */
  97. if (!id) return(NULL);
  98. while (pc)
  99. { if ((pc->callref == -1) && (pc->prot.dss1.invoke_id == id))
  100. return(pc);
  101. pc = pc->next;
  102. }
  103. return(NULL);
  104. } /* l3dss1_search_dummy_proc */
  105. /*******************************************************************/
  106. /* called when a facility message with a dummy callref is received */
  107. /* and a return result is delivered. id specifies the invoke id. */
  108. /*******************************************************************/
  109. static void
  110. l3dss1_dummy_return_result(struct PStack *st, int id, u_char *p, u_char nlen)
  111. { isdn_ctrl ic;
  112. struct IsdnCardState *cs;
  113. struct l3_process *pc = NULL;
  114. if ((pc = l3dss1_search_dummy_proc(st, id)))
  115. { L3DelTimer(&pc->timer); /* remove timer */
  116. cs = pc->st->l1.hardware;
  117. ic.driver = cs->myid;
  118. ic.command = ISDN_STAT_PROT;
  119. ic.arg = DSS1_STAT_INVOKE_RES;
  120. ic.parm.dss1_io.hl_id = pc->prot.dss1.invoke_id;
  121. ic.parm.dss1_io.ll_id = pc->prot.dss1.ll_id;
  122. ic.parm.dss1_io.proc = pc->prot.dss1.proc;
  123. ic.parm.dss1_io.timeout= 0;
  124. ic.parm.dss1_io.datalen = nlen;
  125. ic.parm.dss1_io.data = p;
  126. free_invoke_id(pc->st, pc->prot.dss1.invoke_id);
  127. pc->prot.dss1.invoke_id = 0; /* reset id */
  128. cs->iif.statcallb(&ic);
  129. dss1_release_l3_process(pc);
  130. }
  131. else
  132. l3_debug(st, "dummy return result id=0x%x result len=%d",id,nlen);
  133. } /* l3dss1_dummy_return_result */
  134. /*******************************************************************/
  135. /* called when a facility message with a dummy callref is received */
  136. /* and a return error is delivered. id specifies the invoke id. */
  137. /*******************************************************************/
  138. static void
  139. l3dss1_dummy_error_return(struct PStack *st, int id, ulong error)
  140. { isdn_ctrl ic;
  141. struct IsdnCardState *cs;
  142. struct l3_process *pc = NULL;
  143. if ((pc = l3dss1_search_dummy_proc(st, id)))
  144. { L3DelTimer(&pc->timer); /* remove timer */
  145. cs = pc->st->l1.hardware;
  146. ic.driver = cs->myid;
  147. ic.command = ISDN_STAT_PROT;
  148. ic.arg = DSS1_STAT_INVOKE_ERR;
  149. ic.parm.dss1_io.hl_id = pc->prot.dss1.invoke_id;
  150. ic.parm.dss1_io.ll_id = pc->prot.dss1.ll_id;
  151. ic.parm.dss1_io.proc = pc->prot.dss1.proc;
  152. ic.parm.dss1_io.timeout= error;
  153. ic.parm.dss1_io.datalen = 0;
  154. ic.parm.dss1_io.data = NULL;
  155. free_invoke_id(pc->st, pc->prot.dss1.invoke_id);
  156. pc->prot.dss1.invoke_id = 0; /* reset id */
  157. cs->iif.statcallb(&ic);
  158. dss1_release_l3_process(pc);
  159. }
  160. else
  161. l3_debug(st, "dummy return error id=0x%x error=0x%lx",id,error);
  162. } /* l3dss1_error_return */
  163. /*******************************************************************/
  164. /* called when a facility message with a dummy callref is received */
  165. /* and a invoke is delivered. id specifies the invoke id. */
  166. /*******************************************************************/
  167. static void
  168. l3dss1_dummy_invoke(struct PStack *st, int cr, int id,
  169. int ident, u_char *p, u_char nlen)
  170. { isdn_ctrl ic;
  171. struct IsdnCardState *cs;
  172. l3_debug(st, "dummy invoke %s id=0x%x ident=0x%x datalen=%d",
  173. (cr == -1) ? "local" : "broadcast",id,ident,nlen);
  174. if (cr >= -1) return; /* ignore local data */
  175. cs = st->l1.hardware;
  176. ic.driver = cs->myid;
  177. ic.command = ISDN_STAT_PROT;
  178. ic.arg = DSS1_STAT_INVOKE_BRD;
  179. ic.parm.dss1_io.hl_id = id;
  180. ic.parm.dss1_io.ll_id = 0;
  181. ic.parm.dss1_io.proc = ident;
  182. ic.parm.dss1_io.timeout= 0;
  183. ic.parm.dss1_io.datalen = nlen;
  184. ic.parm.dss1_io.data = p;
  185. cs->iif.statcallb(&ic);
  186. } /* l3dss1_dummy_invoke */
  187. static void
  188. l3dss1_parse_facility(struct PStack *st, struct l3_process *pc,
  189. int cr, u_char * p)
  190. {
  191. int qd_len = 0;
  192. unsigned char nlen = 0, ilen, cp_tag;
  193. int ident, id;
  194. ulong err_ret;
  195. if (pc)
  196. st = pc->st; /* valid Stack */
  197. else
  198. if ((!st) || (cr >= 0)) return; /* neither pc nor st specified */
  199. p++;
  200. qd_len = *p++;
  201. if (qd_len == 0) {
  202. l3_debug(st, "qd_len == 0");
  203. return;
  204. }
  205. if ((*p & 0x1F) != 0x11) { /* Service discriminator, supplementary service */
  206. l3_debug(st, "supplementary service != 0x11");
  207. return;
  208. }
  209. while (qd_len > 0 && !(*p & 0x80)) { /* extension ? */
  210. p++;
  211. qd_len--;
  212. }
  213. if (qd_len < 2) {
  214. l3_debug(st, "qd_len < 2");
  215. return;
  216. }
  217. p++;
  218. qd_len--;
  219. if ((*p & 0xE0) != 0xA0) { /* class and form */
  220. l3_debug(st, "class and form != 0xA0");
  221. return;
  222. }
  223. cp_tag = *p & 0x1F; /* remember tag value */
  224. p++;
  225. qd_len--;
  226. if (qd_len < 1)
  227. { l3_debug(st, "qd_len < 1");
  228. return;
  229. }
  230. if (*p & 0x80)
  231. { /* length format indefinite or limited */
  232. nlen = *p++ & 0x7F; /* number of len bytes or indefinite */
  233. if ((qd_len-- < ((!nlen) ? 3 : (1 + nlen))) ||
  234. (nlen > 1))
  235. { l3_debug(st, "length format error or not implemented");
  236. return;
  237. }
  238. if (nlen == 1)
  239. { nlen = *p++; /* complete length */
  240. qd_len--;
  241. }
  242. else
  243. { qd_len -= 2; /* trailing null bytes */
  244. if ((*(p+qd_len)) || (*(p+qd_len+1)))
  245. { l3_debug(st,"length format indefinite error");
  246. return;
  247. }
  248. nlen = qd_len;
  249. }
  250. }
  251. else
  252. { nlen = *p++;
  253. qd_len--;
  254. }
  255. if (qd_len < nlen)
  256. { l3_debug(st, "qd_len < nlen");
  257. return;
  258. }
  259. qd_len -= nlen;
  260. if (nlen < 2)
  261. { l3_debug(st, "nlen < 2");
  262. return;
  263. }
  264. if (*p != 0x02)
  265. { /* invoke identifier tag */
  266. l3_debug(st, "invoke identifier tag !=0x02");
  267. return;
  268. }
  269. p++;
  270. nlen--;
  271. if (*p & 0x80)
  272. { /* length format */
  273. l3_debug(st, "invoke id length format 2");
  274. return;
  275. }
  276. ilen = *p++;
  277. nlen--;
  278. if (ilen > nlen || ilen == 0)
  279. { l3_debug(st, "ilen > nlen || ilen == 0");
  280. return;
  281. }
  282. nlen -= ilen;
  283. id = 0;
  284. while (ilen > 0)
  285. { id = (id << 8) | (*p++ & 0xFF); /* invoke identifier */
  286. ilen--;
  287. }
  288. switch (cp_tag) { /* component tag */
  289. case 1: /* invoke */
  290. if (nlen < 2) {
  291. l3_debug(st, "nlen < 2 22");
  292. return;
  293. }
  294. if (*p != 0x02) { /* operation value */
  295. l3_debug(st, "operation value !=0x02");
  296. return;
  297. }
  298. p++;
  299. nlen--;
  300. ilen = *p++;
  301. nlen--;
  302. if (ilen > nlen || ilen == 0) {
  303. l3_debug(st, "ilen > nlen || ilen == 0 22");
  304. return;
  305. }
  306. nlen -= ilen;
  307. ident = 0;
  308. while (ilen > 0) {
  309. ident = (ident << 8) | (*p++ & 0xFF);
  310. ilen--;
  311. }
  312. if (!pc)
  313. { l3dss1_dummy_invoke(st, cr, id, ident, p, nlen);
  314. return;
  315. }
  316. #ifdef HISAX_DE_AOC
  317. {
  318. #define FOO1(s,a,b) \
  319. while(nlen > 1) { \
  320. int ilen = p[1]; \
  321. if(nlen < ilen+2) { \
  322. l3_debug(st, "FOO1 nlen < ilen+2"); \
  323. return; \
  324. } \
  325. nlen -= ilen+2; \
  326. if((*p & 0xFF) == (a)) { \
  327. int nlen = ilen; \
  328. p += 2; \
  329. b; \
  330. } else { \
  331. p += ilen+2; \
  332. } \
  333. }
  334. switch (ident) {
  335. case 0x22: /* during */
  336. FOO1("1A", 0x30, FOO1("1C", 0xA1, FOO1("1D", 0x30, FOO1("1E", 0x02, ( {
  337. ident = 0;
  338. nlen = (nlen)?nlen:0; /* Make gcc happy */
  339. while (ilen > 0) {
  340. ident = (ident << 8) | *p++;
  341. ilen--;
  342. }
  343. if (ident > pc->para.chargeinfo) {
  344. pc->para.chargeinfo = ident;
  345. st->l3.l3l4(st, CC_CHARGE | INDICATION, pc);
  346. }
  347. if (st->l3.debug & L3_DEB_CHARGE) {
  348. if (*(p + 2) == 0) {
  349. l3_debug(st, "charging info during %d", pc->para.chargeinfo);
  350. }
  351. else {
  352. l3_debug(st, "charging info final %d", pc->para.chargeinfo);
  353. }
  354. }
  355. }
  356. )))))
  357. break;
  358. case 0x24: /* final */
  359. FOO1("2A", 0x30, FOO1("2B", 0x30, FOO1("2C", 0xA1, FOO1("2D", 0x30, FOO1("2E", 0x02, ( {
  360. ident = 0;
  361. nlen = (nlen)?nlen:0; /* Make gcc happy */
  362. while (ilen > 0) {
  363. ident = (ident << 8) | *p++;
  364. ilen--;
  365. }
  366. if (ident > pc->para.chargeinfo) {
  367. pc->para.chargeinfo = ident;
  368. st->l3.l3l4(st, CC_CHARGE | INDICATION, pc);
  369. }
  370. if (st->l3.debug & L3_DEB_CHARGE) {
  371. l3_debug(st, "charging info final %d", pc->para.chargeinfo);
  372. }
  373. }
  374. ))))))
  375. break;
  376. default:
  377. l3_debug(st, "invoke break invalid ident %02x",ident);
  378. break;
  379. }
  380. #undef FOO1
  381. }
  382. #else /* not HISAX_DE_AOC */
  383. l3_debug(st, "invoke break");
  384. #endif /* not HISAX_DE_AOC */
  385. break;
  386. case 2: /* return result */
  387. /* if no process available handle separately */
  388. if (!pc)
  389. { if (cr == -1)
  390. l3dss1_dummy_return_result(st, id, p, nlen);
  391. return;
  392. }
  393. if ((pc->prot.dss1.invoke_id) && (pc->prot.dss1.invoke_id == id))
  394. { /* Diversion successful */
  395. free_invoke_id(st,pc->prot.dss1.invoke_id);
  396. pc->prot.dss1.remote_result = 0; /* success */
  397. pc->prot.dss1.invoke_id = 0;
  398. pc->redir_result = pc->prot.dss1.remote_result;
  399. st->l3.l3l4(st, CC_REDIR | INDICATION, pc); } /* Diversion successful */
  400. else
  401. l3_debug(st,"return error unknown identifier");
  402. break;
  403. case 3: /* return error */
  404. err_ret = 0;
  405. if (nlen < 2)
  406. { l3_debug(st, "return error nlen < 2");
  407. return;
  408. }
  409. if (*p != 0x02)
  410. { /* result tag */
  411. l3_debug(st, "invoke error tag !=0x02");
  412. return;
  413. }
  414. p++;
  415. nlen--;
  416. if (*p > 4)
  417. { /* length format */
  418. l3_debug(st, "invoke return errlen > 4 ");
  419. return;
  420. }
  421. ilen = *p++;
  422. nlen--;
  423. if (ilen > nlen || ilen == 0)
  424. { l3_debug(st, "error return ilen > nlen || ilen == 0");
  425. return;
  426. }
  427. nlen -= ilen;
  428. while (ilen > 0)
  429. { err_ret = (err_ret << 8) | (*p++ & 0xFF); /* error value */
  430. ilen--;
  431. }
  432. /* if no process available handle separately */
  433. if (!pc)
  434. { if (cr == -1)
  435. l3dss1_dummy_error_return(st, id, err_ret);
  436. return;
  437. }
  438. if ((pc->prot.dss1.invoke_id) && (pc->prot.dss1.invoke_id == id))
  439. { /* Deflection error */
  440. free_invoke_id(st,pc->prot.dss1.invoke_id);
  441. pc->prot.dss1.remote_result = err_ret; /* result */
  442. pc->prot.dss1.invoke_id = 0;
  443. pc->redir_result = pc->prot.dss1.remote_result;
  444. st->l3.l3l4(st, CC_REDIR | INDICATION, pc);
  445. } /* Deflection error */
  446. else
  447. l3_debug(st,"return result unknown identifier");
  448. break;
  449. default:
  450. l3_debug(st, "facility default break tag=0x%02x",cp_tag);
  451. break;
  452. }
  453. }
  454. static void
  455. l3dss1_message(struct l3_process *pc, u_char mt)
  456. {
  457. struct sk_buff *skb;
  458. u_char *p;
  459. if (!(skb = l3_alloc_skb(4)))
  460. return;
  461. p = skb_put(skb, 4);
  462. MsgHead(p, pc->callref, mt);
  463. l3_msg(pc->st, DL_DATA | REQUEST, skb);
  464. }
  465. static void
  466. l3dss1_message_cause(struct l3_process *pc, u_char mt, u_char cause)
  467. {
  468. struct sk_buff *skb;
  469. u_char tmp[16];
  470. u_char *p = tmp;
  471. int l;
  472. MsgHead(p, pc->callref, mt);
  473. *p++ = IE_CAUSE;
  474. *p++ = 0x2;
  475. *p++ = 0x80;
  476. *p++ = cause | 0x80;
  477. l = p - tmp;
  478. if (!(skb = l3_alloc_skb(l)))
  479. return;
  480. memcpy(skb_put(skb, l), tmp, l);
  481. l3_msg(pc->st, DL_DATA | REQUEST, skb);
  482. }
  483. static void
  484. l3dss1_status_send(struct l3_process *pc, u_char pr, void *arg)
  485. {
  486. u_char tmp[16];
  487. u_char *p = tmp;
  488. int l;
  489. struct sk_buff *skb;
  490. MsgHead(p, pc->callref, MT_STATUS);
  491. *p++ = IE_CAUSE;
  492. *p++ = 0x2;
  493. *p++ = 0x80;
  494. *p++ = pc->para.cause | 0x80;
  495. *p++ = IE_CALL_STATE;
  496. *p++ = 0x1;
  497. *p++ = pc->state & 0x3f;
  498. l = p - tmp;
  499. if (!(skb = l3_alloc_skb(l)))
  500. return;
  501. memcpy(skb_put(skb, l), tmp, l);
  502. l3_msg(pc->st, DL_DATA | REQUEST, skb);
  503. }
  504. static void
  505. l3dss1_msg_without_setup(struct l3_process *pc, u_char pr, void *arg)
  506. {
  507. /* This routine is called if here was no SETUP made (checks in dss1up and in
  508. * l3dss1_setup) and a RELEASE_COMPLETE have to be sent with an error code
  509. * MT_STATUS_ENQUIRE in the NULL state is handled too
  510. */
  511. u_char tmp[16];
  512. u_char *p = tmp;
  513. int l;
  514. struct sk_buff *skb;
  515. switch (pc->para.cause) {
  516. case 81: /* invalid callreference */
  517. case 88: /* incomp destination */
  518. case 96: /* mandory IE missing */
  519. case 100: /* invalid IE contents */
  520. case 101: /* incompatible Callstate */
  521. MsgHead(p, pc->callref, MT_RELEASE_COMPLETE);
  522. *p++ = IE_CAUSE;
  523. *p++ = 0x2;
  524. *p++ = 0x80;
  525. *p++ = pc->para.cause | 0x80;
  526. break;
  527. default:
  528. printk(KERN_ERR "HiSax l3dss1_msg_without_setup wrong cause %d\n",
  529. pc->para.cause);
  530. return;
  531. }
  532. l = p - tmp;
  533. if (!(skb = l3_alloc_skb(l)))
  534. return;
  535. memcpy(skb_put(skb, l), tmp, l);
  536. l3_msg(pc->st, DL_DATA | REQUEST, skb);
  537. dss1_release_l3_process(pc);
  538. }
  539. static int ie_ALERTING[] = {IE_BEARER, IE_CHANNEL_ID | IE_MANDATORY_1,
  540. IE_FACILITY, IE_PROGRESS, IE_DISPLAY, IE_SIGNAL, IE_HLC,
  541. IE_USER_USER, -1};
  542. static int ie_CALL_PROCEEDING[] = {IE_BEARER, IE_CHANNEL_ID | IE_MANDATORY_1,
  543. IE_FACILITY, IE_PROGRESS, IE_DISPLAY, IE_HLC, -1};
  544. static int ie_CONNECT[] = {IE_BEARER, IE_CHANNEL_ID | IE_MANDATORY_1,
  545. IE_FACILITY, IE_PROGRESS, IE_DISPLAY, IE_DATE, IE_SIGNAL,
  546. IE_CONNECT_PN, IE_CONNECT_SUB, IE_LLC, IE_HLC, IE_USER_USER, -1};
  547. static int ie_CONNECT_ACKNOWLEDGE[] = {IE_CHANNEL_ID, IE_DISPLAY, IE_SIGNAL, -1};
  548. static int ie_DISCONNECT[] = {IE_CAUSE | IE_MANDATORY, IE_FACILITY,
  549. IE_PROGRESS, IE_DISPLAY, IE_SIGNAL, IE_USER_USER, -1};
  550. static int ie_INFORMATION[] = {IE_COMPLETE, IE_DISPLAY, IE_KEYPAD, IE_SIGNAL,
  551. IE_CALLED_PN, -1};
  552. static int ie_NOTIFY[] = {IE_BEARER, IE_NOTIFY | IE_MANDATORY, IE_DISPLAY, -1};
  553. static int ie_PROGRESS[] = {IE_BEARER, IE_CAUSE, IE_FACILITY, IE_PROGRESS |
  554. IE_MANDATORY, IE_DISPLAY, IE_HLC, IE_USER_USER, -1};
  555. static int ie_RELEASE[] = {IE_CAUSE | IE_MANDATORY_1, IE_FACILITY, IE_DISPLAY,
  556. IE_SIGNAL, IE_USER_USER, -1};
  557. /* a RELEASE_COMPLETE with errors don't require special actions
  558. static int ie_RELEASE_COMPLETE[] = {IE_CAUSE | IE_MANDATORY_1, IE_DISPLAY, IE_SIGNAL, IE_USER_USER, -1};
  559. */
  560. static int ie_RESUME_ACKNOWLEDGE[] = {IE_CHANNEL_ID| IE_MANDATORY, IE_FACILITY,
  561. IE_DISPLAY, -1};
  562. static int ie_RESUME_REJECT[] = {IE_CAUSE | IE_MANDATORY, IE_DISPLAY, -1};
  563. static int ie_SETUP[] = {IE_COMPLETE, IE_BEARER | IE_MANDATORY,
  564. IE_CHANNEL_ID| IE_MANDATORY, IE_FACILITY, IE_PROGRESS,
  565. IE_NET_FAC, IE_DISPLAY, IE_KEYPAD, IE_SIGNAL, IE_CALLING_PN,
  566. IE_CALLING_SUB, IE_CALLED_PN, IE_CALLED_SUB, IE_REDIR_NR,
  567. IE_LLC, IE_HLC, IE_USER_USER, -1};
  568. static int ie_SETUP_ACKNOWLEDGE[] = {IE_CHANNEL_ID | IE_MANDATORY, IE_FACILITY,
  569. IE_PROGRESS, IE_DISPLAY, IE_SIGNAL, -1};
  570. static int ie_STATUS[] = {IE_CAUSE | IE_MANDATORY, IE_CALL_STATE |
  571. IE_MANDATORY, IE_DISPLAY, -1};
  572. static int ie_STATUS_ENQUIRY[] = {IE_DISPLAY, -1};
  573. static int ie_SUSPEND_ACKNOWLEDGE[] = {IE_DISPLAY, IE_FACILITY, -1};
  574. static int ie_SUSPEND_REJECT[] = {IE_CAUSE | IE_MANDATORY, IE_DISPLAY, -1};
  575. /* not used
  576. * static int ie_CONGESTION_CONTROL[] = {IE_CONGESTION | IE_MANDATORY,
  577. * IE_CAUSE | IE_MANDATORY, IE_DISPLAY, -1};
  578. * static int ie_USER_INFORMATION[] = {IE_MORE_DATA, IE_USER_USER | IE_MANDATORY, -1};
  579. * static int ie_RESTART[] = {IE_CHANNEL_ID, IE_DISPLAY, IE_RESTART_IND |
  580. * IE_MANDATORY, -1};
  581. */
  582. static int ie_FACILITY[] = {IE_FACILITY | IE_MANDATORY, IE_DISPLAY, -1};
  583. static int comp_required[] = {1,2,3,5,6,7,9,10,11,14,15,-1};
  584. static int l3_valid_states[] = {0,1,2,3,4,6,7,8,9,10,11,12,15,17,19,25,-1};
  585. struct ie_len {
  586. int ie;
  587. int len;
  588. };
  589. static
  590. struct ie_len max_ie_len[] = {
  591. {IE_SEGMENT, 4},
  592. {IE_BEARER, 12},
  593. {IE_CAUSE, 32},
  594. {IE_CALL_ID, 10},
  595. {IE_CALL_STATE, 3},
  596. {IE_CHANNEL_ID, 34},
  597. {IE_FACILITY, 255},
  598. {IE_PROGRESS, 4},
  599. {IE_NET_FAC, 255},
  600. {IE_NOTIFY, 3},
  601. {IE_DISPLAY, 82},
  602. {IE_DATE, 8},
  603. {IE_KEYPAD, 34},
  604. {IE_SIGNAL, 3},
  605. {IE_INFORATE, 6},
  606. {IE_E2E_TDELAY, 11},
  607. {IE_TDELAY_SEL, 5},
  608. {IE_PACK_BINPARA, 3},
  609. {IE_PACK_WINSIZE, 4},
  610. {IE_PACK_SIZE, 4},
  611. {IE_CUG, 7},
  612. {IE_REV_CHARGE, 3},
  613. {IE_CALLING_PN, 24},
  614. {IE_CALLING_SUB, 23},
  615. {IE_CALLED_PN, 24},
  616. {IE_CALLED_SUB, 23},
  617. {IE_REDIR_NR, 255},
  618. {IE_TRANS_SEL, 255},
  619. {IE_RESTART_IND, 3},
  620. {IE_LLC, 18},
  621. {IE_HLC, 5},
  622. {IE_USER_USER, 131},
  623. {-1,0},
  624. };
  625. static int
  626. getmax_ie_len(u_char ie) {
  627. int i = 0;
  628. while (max_ie_len[i].ie != -1) {
  629. if (max_ie_len[i].ie == ie)
  630. return(max_ie_len[i].len);
  631. i++;
  632. }
  633. return(255);
  634. }
  635. static int
  636. ie_in_set(struct l3_process *pc, u_char ie, int *checklist) {
  637. int ret = 1;
  638. while (*checklist != -1) {
  639. if ((*checklist & 0xff) == ie) {
  640. if (ie & 0x80)
  641. return(-ret);
  642. else
  643. return(ret);
  644. }
  645. ret++;
  646. checklist++;
  647. }
  648. return(0);
  649. }
  650. static int
  651. check_infoelements(struct l3_process *pc, struct sk_buff *skb, int *checklist)
  652. {
  653. int *cl = checklist;
  654. u_char mt;
  655. u_char *p, ie;
  656. int l, newpos, oldpos;
  657. int err_seq = 0, err_len = 0, err_compr = 0, err_ureg = 0;
  658. u_char codeset = 0;
  659. u_char old_codeset = 0;
  660. u_char codelock = 1;
  661. p = skb->data;
  662. /* skip cr */
  663. p++;
  664. l = (*p++) & 0xf;
  665. p += l;
  666. mt = *p++;
  667. oldpos = 0;
  668. while ((p - skb->data) < skb->len) {
  669. if ((*p & 0xf0) == 0x90) { /* shift codeset */
  670. old_codeset = codeset;
  671. codeset = *p & 7;
  672. if (*p & 0x08)
  673. codelock = 0;
  674. else
  675. codelock = 1;
  676. if (pc->debug & L3_DEB_CHECK)
  677. l3_debug(pc->st, "check IE shift%scodeset %d->%d",
  678. codelock ? " locking ": " ", old_codeset, codeset);
  679. p++;
  680. continue;
  681. }
  682. if (!codeset) { /* only codeset 0 */
  683. if ((newpos = ie_in_set(pc, *p, cl))) {
  684. if (newpos > 0) {
  685. if (newpos < oldpos)
  686. err_seq++;
  687. else
  688. oldpos = newpos;
  689. }
  690. } else {
  691. if (ie_in_set(pc, *p, comp_required))
  692. err_compr++;
  693. else
  694. err_ureg++;
  695. }
  696. }
  697. ie = *p++;
  698. if (ie & 0x80) {
  699. l = 1;
  700. } else {
  701. l = *p++;
  702. p += l;
  703. l += 2;
  704. }
  705. if (!codeset && (l > getmax_ie_len(ie)))
  706. err_len++;
  707. if (!codelock) {
  708. if (pc->debug & L3_DEB_CHECK)
  709. l3_debug(pc->st, "check IE shift back codeset %d->%d",
  710. codeset, old_codeset);
  711. codeset = old_codeset;
  712. codelock = 1;
  713. }
  714. }
  715. if (err_compr | err_ureg | err_len | err_seq) {
  716. if (pc->debug & L3_DEB_CHECK)
  717. l3_debug(pc->st, "check IE MT(%x) %d/%d/%d/%d",
  718. mt, err_compr, err_ureg, err_len, err_seq);
  719. if (err_compr)
  720. return(ERR_IE_COMPREHENSION);
  721. if (err_ureg)
  722. return(ERR_IE_UNRECOGNIZED);
  723. if (err_len)
  724. return(ERR_IE_LENGTH);
  725. if (err_seq)
  726. return(ERR_IE_SEQUENCE);
  727. }
  728. return(0);
  729. }
  730. /* verify if a message type exists and contain no IE error */
  731. static int
  732. l3dss1_check_messagetype_validity(struct l3_process *pc, int mt, void *arg)
  733. {
  734. switch (mt) {
  735. case MT_ALERTING:
  736. case MT_CALL_PROCEEDING:
  737. case MT_CONNECT:
  738. case MT_CONNECT_ACKNOWLEDGE:
  739. case MT_DISCONNECT:
  740. case MT_INFORMATION:
  741. case MT_FACILITY:
  742. case MT_NOTIFY:
  743. case MT_PROGRESS:
  744. case MT_RELEASE:
  745. case MT_RELEASE_COMPLETE:
  746. case MT_SETUP:
  747. case MT_SETUP_ACKNOWLEDGE:
  748. case MT_RESUME_ACKNOWLEDGE:
  749. case MT_RESUME_REJECT:
  750. case MT_SUSPEND_ACKNOWLEDGE:
  751. case MT_SUSPEND_REJECT:
  752. case MT_USER_INFORMATION:
  753. case MT_RESTART:
  754. case MT_RESTART_ACKNOWLEDGE:
  755. case MT_CONGESTION_CONTROL:
  756. case MT_STATUS:
  757. case MT_STATUS_ENQUIRY:
  758. if (pc->debug & L3_DEB_CHECK)
  759. l3_debug(pc->st, "l3dss1_check_messagetype_validity mt(%x) OK", mt);
  760. break;
  761. case MT_RESUME: /* RESUME only in user->net */
  762. case MT_SUSPEND: /* SUSPEND only in user->net */
  763. default:
  764. if (pc->debug & (L3_DEB_CHECK | L3_DEB_WARN))
  765. l3_debug(pc->st, "l3dss1_check_messagetype_validity mt(%x) fail", mt);
  766. pc->para.cause = 97;
  767. l3dss1_status_send(pc, 0, NULL);
  768. return(1);
  769. }
  770. return(0);
  771. }
  772. static void
  773. l3dss1_std_ie_err(struct l3_process *pc, int ret) {
  774. if (pc->debug & L3_DEB_CHECK)
  775. l3_debug(pc->st, "check_infoelements ret %d", ret);
  776. switch(ret) {
  777. case 0:
  778. break;
  779. case ERR_IE_COMPREHENSION:
  780. pc->para.cause = 96;
  781. l3dss1_status_send(pc, 0, NULL);
  782. break;
  783. case ERR_IE_UNRECOGNIZED:
  784. pc->para.cause = 99;
  785. l3dss1_status_send(pc, 0, NULL);
  786. break;
  787. case ERR_IE_LENGTH:
  788. pc->para.cause = 100;
  789. l3dss1_status_send(pc, 0, NULL);
  790. break;
  791. case ERR_IE_SEQUENCE:
  792. default:
  793. break;
  794. }
  795. }
  796. static int
  797. l3dss1_get_channel_id(struct l3_process *pc, struct sk_buff *skb) {
  798. u_char *p;
  799. p = skb->data;
  800. if ((p = findie(p, skb->len, IE_CHANNEL_ID, 0))) {
  801. p++;
  802. if (*p != 1) { /* len for BRI = 1 */
  803. if (pc->debug & L3_DEB_WARN)
  804. l3_debug(pc->st, "wrong chid len %d", *p);
  805. return (-2);
  806. }
  807. p++;
  808. if (*p & 0x60) { /* only base rate interface */
  809. if (pc->debug & L3_DEB_WARN)
  810. l3_debug(pc->st, "wrong chid %x", *p);
  811. return (-3);
  812. }
  813. return(*p & 0x3);
  814. } else
  815. return(-1);
  816. }
  817. static int
  818. l3dss1_get_cause(struct l3_process *pc, struct sk_buff *skb) {
  819. u_char l, i=0;
  820. u_char *p;
  821. p = skb->data;
  822. pc->para.cause = 31;
  823. pc->para.loc = 0;
  824. if ((p = findie(p, skb->len, IE_CAUSE, 0))) {
  825. p++;
  826. l = *p++;
  827. if (l>30)
  828. return(1);
  829. if (l) {
  830. pc->para.loc = *p++;
  831. l--;
  832. } else {
  833. return(2);
  834. }
  835. if (l && !(pc->para.loc & 0x80)) {
  836. l--;
  837. p++; /* skip recommendation */
  838. }
  839. if (l) {
  840. pc->para.cause = *p++;
  841. l--;
  842. if (!(pc->para.cause & 0x80))
  843. return(3);
  844. } else
  845. return(4);
  846. while (l && (i<6)) {
  847. pc->para.diag[i++] = *p++;
  848. l--;
  849. }
  850. } else
  851. return(-1);
  852. return(0);
  853. }
  854. static void
  855. l3dss1_msg_with_uus(struct l3_process *pc, u_char cmd)
  856. {
  857. struct sk_buff *skb;
  858. u_char tmp[16+40];
  859. u_char *p = tmp;
  860. int l;
  861. MsgHead(p, pc->callref, cmd);
  862. if (pc->prot.dss1.uus1_data[0])
  863. { *p++ = IE_USER_USER; /* UUS info element */
  864. *p++ = strlen(pc->prot.dss1.uus1_data) + 1;
  865. *p++ = 0x04; /* IA5 chars */
  866. strcpy(p,pc->prot.dss1.uus1_data);
  867. p += strlen(pc->prot.dss1.uus1_data);
  868. pc->prot.dss1.uus1_data[0] = '\0';
  869. }
  870. l = p - tmp;
  871. if (!(skb = l3_alloc_skb(l)))
  872. return;
  873. memcpy(skb_put(skb, l), tmp, l);
  874. l3_msg(pc->st, DL_DATA | REQUEST, skb);
  875. } /* l3dss1_msg_with_uus */
  876. static void
  877. l3dss1_release_req(struct l3_process *pc, u_char pr, void *arg)
  878. {
  879. StopAllL3Timer(pc);
  880. newl3state(pc, 19);
  881. if (!pc->prot.dss1.uus1_data[0])
  882. l3dss1_message(pc, MT_RELEASE);
  883. else
  884. l3dss1_msg_with_uus(pc, MT_RELEASE);
  885. L3AddTimer(&pc->timer, T308, CC_T308_1);
  886. }
  887. static void
  888. l3dss1_release_cmpl(struct l3_process *pc, u_char pr, void *arg)
  889. {
  890. struct sk_buff *skb = arg;
  891. int ret;
  892. if ((ret = l3dss1_get_cause(pc, skb))>0) {
  893. if (pc->debug & L3_DEB_WARN)
  894. l3_debug(pc->st, "RELCMPL get_cause ret(%d)",ret);
  895. } else if (ret < 0)
  896. pc->para.cause = NO_CAUSE;
  897. StopAllL3Timer(pc);
  898. newl3state(pc, 0);
  899. pc->st->l3.l3l4(pc->st, CC_RELEASE | CONFIRM, pc);
  900. dss1_release_l3_process(pc);
  901. }
  902. #ifdef EXT_BEARER_CAPS
  903. static u_char *
  904. EncodeASyncParams(u_char * p, u_char si2)
  905. { // 7c 06 88 90 21 42 00 bb
  906. p[0] = 0;
  907. p[1] = 0x40; // Intermediate rate: 16 kbit/s jj 2000.02.19
  908. p[2] = 0x80;
  909. if (si2 & 32) // 7 data bits
  910. p[2] += 16;
  911. else // 8 data bits
  912. p[2] += 24;
  913. if (si2 & 16) // 2 stop bits
  914. p[2] += 96;
  915. else // 1 stop bit
  916. p[2] += 32;
  917. if (si2 & 8) // even parity
  918. p[2] += 2;
  919. else // no parity
  920. p[2] += 3;
  921. switch (si2 & 0x07) {
  922. case 0:
  923. p[0] = 66; // 1200 bit/s
  924. break;
  925. case 1:
  926. p[0] = 88; // 1200/75 bit/s
  927. break;
  928. case 2:
  929. p[0] = 87; // 75/1200 bit/s
  930. break;
  931. case 3:
  932. p[0] = 67; // 2400 bit/s
  933. break;
  934. case 4:
  935. p[0] = 69; // 4800 bit/s
  936. break;
  937. case 5:
  938. p[0] = 72; // 9600 bit/s
  939. break;
  940. case 6:
  941. p[0] = 73; // 14400 bit/s
  942. break;
  943. case 7:
  944. p[0] = 75; // 19200 bit/s
  945. break;
  946. }
  947. return p + 3;
  948. }
  949. static u_char
  950. EncodeSyncParams(u_char si2, u_char ai)
  951. {
  952. switch (si2) {
  953. case 0:
  954. return ai + 2; // 1200 bit/s
  955. case 1:
  956. return ai + 24; // 1200/75 bit/s
  957. case 2:
  958. return ai + 23; // 75/1200 bit/s
  959. case 3:
  960. return ai + 3; // 2400 bit/s
  961. case 4:
  962. return ai + 5; // 4800 bit/s
  963. case 5:
  964. return ai + 8; // 9600 bit/s
  965. case 6:
  966. return ai + 9; // 14400 bit/s
  967. case 7:
  968. return ai + 11; // 19200 bit/s
  969. case 8:
  970. return ai + 14; // 48000 bit/s
  971. case 9:
  972. return ai + 15; // 56000 bit/s
  973. case 15:
  974. return ai + 40; // negotiate bit/s
  975. default:
  976. break;
  977. }
  978. return ai;
  979. }
  980. static u_char
  981. DecodeASyncParams(u_char si2, u_char * p)
  982. {
  983. u_char info;
  984. switch (p[5]) {
  985. case 66: // 1200 bit/s
  986. break; // si2 don't change
  987. case 88: // 1200/75 bit/s
  988. si2 += 1;
  989. break;
  990. case 87: // 75/1200 bit/s
  991. si2 += 2;
  992. break;
  993. case 67: // 2400 bit/s
  994. si2 += 3;
  995. break;
  996. case 69: // 4800 bit/s
  997. si2 += 4;
  998. break;
  999. case 72: // 9600 bit/s
  1000. si2 += 5;
  1001. break;
  1002. case 73: // 14400 bit/s
  1003. si2 += 6;
  1004. break;
  1005. case 75: // 19200 bit/s
  1006. si2 += 7;
  1007. break;
  1008. }
  1009. info = p[7] & 0x7f;
  1010. if ((info & 16) && (!(info & 8))) // 7 data bits
  1011. si2 += 32; // else 8 data bits
  1012. if ((info & 96) == 96) // 2 stop bits
  1013. si2 += 16; // else 1 stop bit
  1014. if ((info & 2) && (!(info & 1))) // even parity
  1015. si2 += 8; // else no parity
  1016. return si2;
  1017. }
  1018. static u_char
  1019. DecodeSyncParams(u_char si2, u_char info)
  1020. {
  1021. info &= 0x7f;
  1022. switch (info) {
  1023. case 40: // bit/s negotiation failed ai := 165 not 175!
  1024. return si2 + 15;
  1025. case 15: // 56000 bit/s failed, ai := 0 not 169 !
  1026. return si2 + 9;
  1027. case 14: // 48000 bit/s
  1028. return si2 + 8;
  1029. case 11: // 19200 bit/s
  1030. return si2 + 7;
  1031. case 9: // 14400 bit/s
  1032. return si2 + 6;
  1033. case 8: // 9600 bit/s
  1034. return si2 + 5;
  1035. case 5: // 4800 bit/s
  1036. return si2 + 4;
  1037. case 3: // 2400 bit/s
  1038. return si2 + 3;
  1039. case 23: // 75/1200 bit/s
  1040. return si2 + 2;
  1041. case 24: // 1200/75 bit/s
  1042. return si2 + 1;
  1043. default: // 1200 bit/s
  1044. return si2;
  1045. }
  1046. }
  1047. static u_char
  1048. DecodeSI2(struct sk_buff *skb)
  1049. {
  1050. u_char *p; //, *pend=skb->data + skb->len;
  1051. if ((p = findie(skb->data, skb->len, 0x7c, 0))) {
  1052. switch (p[4] & 0x0f) {
  1053. case 0x01:
  1054. if (p[1] == 0x04) // sync. Bitratenadaption
  1055. return DecodeSyncParams(160, p[5]); // V.110/X.30
  1056. else if (p[1] == 0x06) // async. Bitratenadaption
  1057. return DecodeASyncParams(192, p); // V.110/X.30
  1058. break;
  1059. case 0x08: // if (p[5] == 0x02) // sync. Bitratenadaption
  1060. if (p[1] > 3)
  1061. return DecodeSyncParams(176, p[5]); // V.120
  1062. break;
  1063. }
  1064. }
  1065. return 0;
  1066. }
  1067. #endif
  1068. static void
  1069. l3dss1_setup_req(struct l3_process *pc, u_char pr,
  1070. void *arg)
  1071. {
  1072. struct sk_buff *skb;
  1073. u_char tmp[128];
  1074. u_char *p = tmp;
  1075. u_char channel = 0;
  1076. u_char send_keypad;
  1077. u_char screen = 0x80;
  1078. u_char *teln;
  1079. u_char *msn;
  1080. u_char *sub;
  1081. u_char *sp;
  1082. int l;
  1083. MsgHead(p, pc->callref, MT_SETUP);
  1084. teln = pc->para.setup.phone;
  1085. #ifndef CONFIG_HISAX_NO_KEYPAD
  1086. send_keypad = (strchr(teln,'*') || strchr(teln,'#')) ? 1 : 0;
  1087. #else
  1088. send_keypad = 0;
  1089. #endif
  1090. #ifndef CONFIG_HISAX_NO_SENDCOMPLETE
  1091. if (!send_keypad)
  1092. *p++ = 0xa1; /* complete indicator */
  1093. #endif
  1094. /*
  1095. * Set Bearer Capability, Map info from 1TR6-convention to EDSS1
  1096. */
  1097. switch (pc->para.setup.si1) {
  1098. case 1: /* Telephony */
  1099. *p++ = IE_BEARER;
  1100. *p++ = 0x3; /* Length */
  1101. *p++ = 0x90; /* Coding Std. CCITT, 3.1 kHz audio */
  1102. *p++ = 0x90; /* Circuit-Mode 64kbps */
  1103. *p++ = 0xa3; /* A-Law Audio */
  1104. break;
  1105. case 5: /* Datatransmission 64k, BTX */
  1106. case 7: /* Datatransmission 64k */
  1107. default:
  1108. *p++ = IE_BEARER;
  1109. *p++ = 0x2; /* Length */
  1110. *p++ = 0x88; /* Coding Std. CCITT, unrestr. dig. Inform. */
  1111. *p++ = 0x90; /* Circuit-Mode 64kbps */
  1112. break;
  1113. }
  1114. if (send_keypad) {
  1115. *p++ = IE_KEYPAD;
  1116. *p++ = strlen(teln);
  1117. while (*teln)
  1118. *p++ = (*teln++) & 0x7F;
  1119. }
  1120. /*
  1121. * What about info2? Mapping to High-Layer-Compatibility?
  1122. */
  1123. if ((*teln) && (!send_keypad)) {
  1124. /* parse number for special things */
  1125. if (!isdigit(*teln)) {
  1126. switch (0x5f & *teln) {
  1127. case 'C':
  1128. channel = 0x08;
  1129. case 'P':
  1130. channel |= 0x80;
  1131. teln++;
  1132. if (*teln == '1')
  1133. channel |= 0x01;
  1134. else
  1135. channel |= 0x02;
  1136. break;
  1137. case 'R':
  1138. screen = 0xA0;
  1139. break;
  1140. case 'D':
  1141. screen = 0x80;
  1142. break;
  1143. default:
  1144. if (pc->debug & L3_DEB_WARN)
  1145. l3_debug(pc->st, "Wrong MSN Code");
  1146. break;
  1147. }
  1148. teln++;
  1149. }
  1150. }
  1151. if (channel) {
  1152. *p++ = IE_CHANNEL_ID;
  1153. *p++ = 1;
  1154. *p++ = channel;
  1155. }
  1156. msn = pc->para.setup.eazmsn;
  1157. sub = NULL;
  1158. sp = msn;
  1159. while (*sp) {
  1160. if ('.' == *sp) {
  1161. sub = sp;
  1162. *sp = 0;
  1163. } else
  1164. sp++;
  1165. }
  1166. if (*msn) {
  1167. *p++ = IE_CALLING_PN;
  1168. *p++ = strlen(msn) + (screen ? 2 : 1);
  1169. /* Classify as AnyPref. */
  1170. if (screen) {
  1171. *p++ = 0x01; /* Ext = '0'B, Type = '000'B, Plan = '0001'B. */
  1172. *p++ = screen;
  1173. } else
  1174. *p++ = 0x81; /* Ext = '1'B, Type = '000'B, Plan = '0001'B. */
  1175. while (*msn)
  1176. *p++ = *msn++ & 0x7f;
  1177. }
  1178. if (sub) {
  1179. *sub++ = '.';
  1180. *p++ = IE_CALLING_SUB;
  1181. *p++ = strlen(sub) + 2;
  1182. *p++ = 0x80; /* NSAP coded */
  1183. *p++ = 0x50; /* local IDI format */
  1184. while (*sub)
  1185. *p++ = *sub++ & 0x7f;
  1186. }
  1187. sub = NULL;
  1188. sp = teln;
  1189. while (*sp) {
  1190. if ('.' == *sp) {
  1191. sub = sp;
  1192. *sp = 0;
  1193. } else
  1194. sp++;
  1195. }
  1196. if (!send_keypad) {
  1197. *p++ = IE_CALLED_PN;
  1198. *p++ = strlen(teln) + 1;
  1199. /* Classify as AnyPref. */
  1200. *p++ = 0x81; /* Ext = '1'B, Type = '000'B, Plan = '0001'B. */
  1201. while (*teln)
  1202. *p++ = *teln++ & 0x7f;
  1203. if (sub) {
  1204. *sub++ = '.';
  1205. *p++ = IE_CALLED_SUB;
  1206. *p++ = strlen(sub) + 2;
  1207. *p++ = 0x80; /* NSAP coded */
  1208. *p++ = 0x50; /* local IDI format */
  1209. while (*sub)
  1210. *p++ = *sub++ & 0x7f;
  1211. }
  1212. }
  1213. #ifdef EXT_BEARER_CAPS
  1214. if ((pc->para.setup.si2 >= 160) && (pc->para.setup.si2 <= 175)) { // sync. Bitratenadaption, V.110/X.30
  1215. *p++ = IE_LLC;
  1216. *p++ = 0x04;
  1217. *p++ = 0x88;
  1218. *p++ = 0x90;
  1219. *p++ = 0x21;
  1220. *p++ = EncodeSyncParams(pc->para.setup.si2 - 160, 0x80);
  1221. } else if ((pc->para.setup.si2 >= 176) && (pc->para.setup.si2 <= 191)) { // sync. Bitratenadaption, V.120
  1222. *p++ = IE_LLC;
  1223. *p++ = 0x05;
  1224. *p++ = 0x88;
  1225. *p++ = 0x90;
  1226. *p++ = 0x28;
  1227. *p++ = EncodeSyncParams(pc->para.setup.si2 - 176, 0);
  1228. *p++ = 0x82;
  1229. } else if (pc->para.setup.si2 >= 192) { // async. Bitratenadaption, V.110/X.30
  1230. *p++ = IE_LLC;
  1231. *p++ = 0x06;
  1232. *p++ = 0x88;
  1233. *p++ = 0x90;
  1234. *p++ = 0x21;
  1235. p = EncodeASyncParams(p, pc->para.setup.si2 - 192);
  1236. #ifndef CONFIG_HISAX_NO_LLC
  1237. } else {
  1238. switch (pc->para.setup.si1) {
  1239. case 1: /* Telephony */
  1240. *p++ = IE_LLC;
  1241. *p++ = 0x3; /* Length */
  1242. *p++ = 0x90; /* Coding Std. CCITT, 3.1 kHz audio */
  1243. *p++ = 0x90; /* Circuit-Mode 64kbps */
  1244. *p++ = 0xa3; /* A-Law Audio */
  1245. break;
  1246. case 5: /* Datatransmission 64k, BTX */
  1247. case 7: /* Datatransmission 64k */
  1248. default:
  1249. *p++ = IE_LLC;
  1250. *p++ = 0x2; /* Length */
  1251. *p++ = 0x88; /* Coding Std. CCITT, unrestr. dig. Inform. */
  1252. *p++ = 0x90; /* Circuit-Mode 64kbps */
  1253. break;
  1254. }
  1255. #endif
  1256. }
  1257. #endif
  1258. l = p - tmp;
  1259. if (!(skb = l3_alloc_skb(l)))
  1260. return;
  1261. memcpy(skb_put(skb, l), tmp, l);
  1262. L3DelTimer(&pc->timer);
  1263. L3AddTimer(&pc->timer, T303, CC_T303);
  1264. newl3state(pc, 1);
  1265. l3_msg(pc->st, DL_DATA | REQUEST, skb);
  1266. }
  1267. static void
  1268. l3dss1_call_proc(struct l3_process *pc, u_char pr, void *arg)
  1269. {
  1270. struct sk_buff *skb = arg;
  1271. int id, ret;
  1272. if ((id = l3dss1_get_channel_id(pc, skb)) >= 0) {
  1273. if ((0 == id) || ((3 == id) && (0x10 == pc->para.moderate))) {
  1274. if (pc->debug & L3_DEB_WARN)
  1275. l3_debug(pc->st, "setup answer with wrong chid %x", id);
  1276. pc->para.cause = 100;
  1277. l3dss1_status_send(pc, pr, NULL);
  1278. return;
  1279. }
  1280. pc->para.bchannel = id;
  1281. } else if (1 == pc->state) {
  1282. if (pc->debug & L3_DEB_WARN)
  1283. l3_debug(pc->st, "setup answer wrong chid (ret %d)", id);
  1284. if (id == -1)
  1285. pc->para.cause = 96;
  1286. else
  1287. pc->para.cause = 100;
  1288. l3dss1_status_send(pc, pr, NULL);
  1289. return;
  1290. }
  1291. /* Now we are on none mandatory IEs */
  1292. ret = check_infoelements(pc, skb, ie_CALL_PROCEEDING);
  1293. if (ERR_IE_COMPREHENSION == ret) {
  1294. l3dss1_std_ie_err(pc, ret);
  1295. return;
  1296. }
  1297. L3DelTimer(&pc->timer);
  1298. newl3state(pc, 3);
  1299. L3AddTimer(&pc->timer, T310, CC_T310);
  1300. if (ret) /* STATUS for none mandatory IE errors after actions are taken */
  1301. l3dss1_std_ie_err(pc, ret);
  1302. pc->st->l3.l3l4(pc->st, CC_PROCEEDING | INDICATION, pc);
  1303. }
  1304. static void
  1305. l3dss1_setup_ack(struct l3_process *pc, u_char pr, void *arg)
  1306. {
  1307. struct sk_buff *skb = arg;
  1308. int id, ret;
  1309. if ((id = l3dss1_get_channel_id(pc, skb)) >= 0) {
  1310. if ((0 == id) || ((3 == id) && (0x10 == pc->para.moderate))) {
  1311. if (pc->debug & L3_DEB_WARN)
  1312. l3_debug(pc->st, "setup answer with wrong chid %x", id);
  1313. pc->para.cause = 100;
  1314. l3dss1_status_send(pc, pr, NULL);
  1315. return;
  1316. }
  1317. pc->para.bchannel = id;
  1318. } else {
  1319. if (pc->debug & L3_DEB_WARN)
  1320. l3_debug(pc->st, "setup answer wrong chid (ret %d)", id);
  1321. if (id == -1)
  1322. pc->para.cause = 96;
  1323. else
  1324. pc->para.cause = 100;
  1325. l3dss1_status_send(pc, pr, NULL);
  1326. return;
  1327. }
  1328. /* Now we are on none mandatory IEs */
  1329. ret = check_infoelements(pc, skb, ie_SETUP_ACKNOWLEDGE);
  1330. if (ERR_IE_COMPREHENSION == ret) {
  1331. l3dss1_std_ie_err(pc, ret);
  1332. return;
  1333. }
  1334. L3DelTimer(&pc->timer);
  1335. newl3state(pc, 2);
  1336. L3AddTimer(&pc->timer, T304, CC_T304);
  1337. if (ret) /* STATUS for none mandatory IE errors after actions are taken */
  1338. l3dss1_std_ie_err(pc, ret);
  1339. pc->st->l3.l3l4(pc->st, CC_MORE_INFO | INDICATION, pc);
  1340. }
  1341. static void
  1342. l3dss1_disconnect(struct l3_process *pc, u_char pr, void *arg)
  1343. {
  1344. struct sk_buff *skb = arg;
  1345. u_char *p;
  1346. int ret;
  1347. u_char cause = 0;
  1348. StopAllL3Timer(pc);
  1349. if ((ret = l3dss1_get_cause(pc, skb))) {
  1350. if (pc->debug & L3_DEB_WARN)
  1351. l3_debug(pc->st, "DISC get_cause ret(%d)", ret);
  1352. if (ret < 0)
  1353. cause = 96;
  1354. else if (ret > 0)
  1355. cause = 100;
  1356. }
  1357. if ((p = findie(skb->data, skb->len, IE_FACILITY, 0)))
  1358. l3dss1_parse_facility(pc->st, pc, pc->callref, p);
  1359. ret = check_infoelements(pc, skb, ie_DISCONNECT);
  1360. if (ERR_IE_COMPREHENSION == ret)
  1361. cause = 96;
  1362. else if ((!cause) && (ERR_IE_UNRECOGNIZED == ret))
  1363. cause = 99;
  1364. ret = pc->state;
  1365. newl3state(pc, 12);
  1366. if (cause)
  1367. newl3state(pc, 19);
  1368. if (11 != ret)
  1369. pc->st->l3.l3l4(pc->st, CC_DISCONNECT | INDICATION, pc);
  1370. else if (!cause)
  1371. l3dss1_release_req(pc, pr, NULL);
  1372. if (cause) {
  1373. l3dss1_message_cause(pc, MT_RELEASE, cause);
  1374. L3AddTimer(&pc->timer, T308, CC_T308_1);
  1375. }
  1376. }
  1377. static void
  1378. l3dss1_connect(struct l3_process *pc, u_char pr, void *arg)
  1379. {
  1380. struct sk_buff *skb = arg;
  1381. int ret;
  1382. ret = check_infoelements(pc, skb, ie_CONNECT);
  1383. if (ERR_IE_COMPREHENSION == ret) {
  1384. l3dss1_std_ie_err(pc, ret);
  1385. return;
  1386. }
  1387. L3DelTimer(&pc->timer); /* T310 */
  1388. newl3state(pc, 10);
  1389. pc->para.chargeinfo = 0;
  1390. /* here should inserted COLP handling KKe */
  1391. if (ret)
  1392. l3dss1_std_ie_err(pc, ret);
  1393. pc->st->l3.l3l4(pc->st, CC_SETUP | CONFIRM, pc);
  1394. }
  1395. static void
  1396. l3dss1_alerting(struct l3_process *pc, u_char pr, void *arg)
  1397. {
  1398. struct sk_buff *skb = arg;
  1399. int ret;
  1400. ret = check_infoelements(pc, skb, ie_ALERTING);
  1401. if (ERR_IE_COMPREHENSION == ret) {
  1402. l3dss1_std_ie_err(pc, ret);
  1403. return;
  1404. }
  1405. L3DelTimer(&pc->timer); /* T304 */
  1406. newl3state(pc, 4);
  1407. if (ret)
  1408. l3dss1_std_ie_err(pc, ret);
  1409. pc->st->l3.l3l4(pc->st, CC_ALERTING | INDICATION, pc);
  1410. }
  1411. static void
  1412. l3dss1_setup(struct l3_process *pc, u_char pr, void *arg)
  1413. {
  1414. u_char *p;
  1415. int bcfound = 0;
  1416. char tmp[80];
  1417. struct sk_buff *skb = arg;
  1418. int id;
  1419. int err = 0;
  1420. /*
  1421. * Bearer Capabilities
  1422. */
  1423. p = skb->data;
  1424. /* only the first occurrence 'll be detected ! */
  1425. if ((p = findie(p, skb->len, 0x04, 0))) {
  1426. if ((p[1] < 2) || (p[1] > 11))
  1427. err = 1;
  1428. else {
  1429. pc->para.setup.si2 = 0;
  1430. switch (p[2] & 0x7f) {
  1431. case 0x00: /* Speech */
  1432. case 0x10: /* 3.1 Khz audio */
  1433. pc->para.setup.si1 = 1;
  1434. break;
  1435. case 0x08: /* Unrestricted digital information */
  1436. pc->para.setup.si1 = 7;
  1437. /* JIM, 05.11.97 I wanna set service indicator 2 */
  1438. #ifdef EXT_BEARER_CAPS
  1439. pc->para.setup.si2 = DecodeSI2(skb);
  1440. #endif
  1441. break;
  1442. case 0x09: /* Restricted digital information */
  1443. pc->para.setup.si1 = 2;
  1444. break;
  1445. case 0x11:
  1446. /* Unrestr. digital information with
  1447. * tones/announcements ( or 7 kHz audio
  1448. */
  1449. pc->para.setup.si1 = 3;
  1450. break;
  1451. case 0x18: /* Video */
  1452. pc->para.setup.si1 = 4;
  1453. break;
  1454. default:
  1455. err = 2;
  1456. break;
  1457. }
  1458. switch (p[3] & 0x7f) {
  1459. case 0x40: /* packed mode */
  1460. pc->para.setup.si1 = 8;
  1461. break;
  1462. case 0x10: /* 64 kbit */
  1463. case 0x11: /* 2*64 kbit */
  1464. case 0x13: /* 384 kbit */
  1465. case 0x15: /* 1536 kbit */
  1466. case 0x17: /* 1920 kbit */
  1467. pc->para.moderate = p[3] & 0x7f;
  1468. break;
  1469. default:
  1470. err = 3;
  1471. break;
  1472. }
  1473. }
  1474. if (pc->debug & L3_DEB_SI)
  1475. l3_debug(pc->st, "SI=%d, AI=%d",
  1476. pc->para.setup.si1, pc->para.setup.si2);
  1477. if (err) {
  1478. if (pc->debug & L3_DEB_WARN)
  1479. l3_debug(pc->st, "setup with wrong bearer(l=%d:%x,%x)",
  1480. p[1], p[2], p[3]);
  1481. pc->para.cause = 100;
  1482. l3dss1_msg_without_setup(pc, pr, NULL);
  1483. return;
  1484. }
  1485. } else {
  1486. if (pc->debug & L3_DEB_WARN)
  1487. l3_debug(pc->st, "setup without bearer capabilities");
  1488. /* ETS 300-104 1.3.3 */
  1489. pc->para.cause = 96;
  1490. l3dss1_msg_without_setup(pc, pr, NULL);
  1491. return;
  1492. }
  1493. /*
  1494. * Channel Identification
  1495. */
  1496. if ((id = l3dss1_get_channel_id(pc, skb)) >= 0) {
  1497. if ((pc->para.bchannel = id)) {
  1498. if ((3 == id) && (0x10 == pc->para.moderate)) {
  1499. if (pc->debug & L3_DEB_WARN)
  1500. l3_debug(pc->st, "setup with wrong chid %x",
  1501. id);
  1502. pc->para.cause = 100;
  1503. l3dss1_msg_without_setup(pc, pr, NULL);
  1504. return;
  1505. }
  1506. bcfound++;
  1507. } else
  1508. { if (pc->debug & L3_DEB_WARN)
  1509. l3_debug(pc->st, "setup without bchannel, call waiting");
  1510. bcfound++;
  1511. }
  1512. } else {
  1513. if (pc->debug & L3_DEB_WARN)
  1514. l3_debug(pc->st, "setup with wrong chid ret %d", id);
  1515. if (id == -1)
  1516. pc->para.cause = 96;
  1517. else
  1518. pc->para.cause = 100;
  1519. l3dss1_msg_without_setup(pc, pr, NULL);
  1520. return;
  1521. }
  1522. /* Now we are on none mandatory IEs */
  1523. err = check_infoelements(pc, skb, ie_SETUP);
  1524. if (ERR_IE_COMPREHENSION == err) {
  1525. pc->para.cause = 96;
  1526. l3dss1_msg_without_setup(pc, pr, NULL);
  1527. return;
  1528. }
  1529. p = skb->data;
  1530. if ((p = findie(p, skb->len, 0x70, 0)))
  1531. iecpy(pc->para.setup.eazmsn, p, 1);
  1532. else
  1533. pc->para.setup.eazmsn[0] = 0;
  1534. p = skb->data;
  1535. if ((p = findie(p, skb->len, 0x71, 0))) {
  1536. /* Called party subaddress */
  1537. if ((p[1] >= 2) && (p[2] == 0x80) && (p[3] == 0x50)) {
  1538. tmp[0] = '.';
  1539. iecpy(&tmp[1], p, 2);
  1540. strcat(pc->para.setup.eazmsn, tmp);
  1541. } else if (pc->debug & L3_DEB_WARN)
  1542. l3_debug(pc->st, "wrong called subaddress");
  1543. }
  1544. p = skb->data;
  1545. if ((p = findie(p, skb->len, 0x6c, 0))) {
  1546. pc->para.setup.plan = p[2];
  1547. if (p[2] & 0x80) {
  1548. iecpy(pc->para.setup.phone, p, 1);
  1549. pc->para.setup.screen = 0;
  1550. } else {
  1551. iecpy(pc->para.setup.phone, p, 2);
  1552. pc->para.setup.screen = p[3];
  1553. }
  1554. } else {
  1555. pc->para.setup.phone[0] = 0;
  1556. pc->para.setup.plan = 0;
  1557. pc->para.setup.screen = 0;
  1558. }
  1559. p = skb->data;
  1560. if ((p = findie(p, skb->len, 0x6d, 0))) {
  1561. /* Calling party subaddress */
  1562. if ((p[1] >= 2) && (p[2] == 0x80) && (p[3] == 0x50)) {
  1563. tmp[0] = '.';
  1564. iecpy(&tmp[1], p, 2);
  1565. strcat(pc->para.setup.phone, tmp);
  1566. } else if (pc->debug & L3_DEB_WARN)
  1567. l3_debug(pc->st, "wrong calling subaddress");
  1568. }
  1569. newl3state(pc, 6);
  1570. if (err) /* STATUS for none mandatory IE errors after actions are taken */
  1571. l3dss1_std_ie_err(pc, err);
  1572. pc->st->l3.l3l4(pc->st, CC_SETUP | INDICATION, pc);
  1573. }
  1574. static void
  1575. l3dss1_reset(struct l3_process *pc, u_char pr, void *arg)
  1576. {
  1577. dss1_release_l3_process(pc);
  1578. }
  1579. static void
  1580. l3dss1_disconnect_req(struct l3_process *pc, u_char pr, void *arg)
  1581. {
  1582. struct sk_buff *skb;
  1583. u_char tmp[16+40];
  1584. u_char *p = tmp;
  1585. int l;
  1586. u_char cause = 16;
  1587. if (pc->para.cause != NO_CAUSE)
  1588. cause = pc->para.cause;
  1589. StopAllL3Timer(pc);
  1590. MsgHead(p, pc->callref, MT_DISCONNECT);
  1591. *p++ = IE_CAUSE;
  1592. *p++ = 0x2;
  1593. *p++ = 0x80;
  1594. *p++ = cause | 0x80;
  1595. if (pc->prot.dss1.uus1_data[0])
  1596. { *p++ = IE_USER_USER; /* UUS info element */
  1597. *p++ = strlen(pc->prot.dss1.uus1_data) + 1;
  1598. *p++ = 0x04; /* IA5 chars */
  1599. strcpy(p,pc->prot.dss1.uus1_data);
  1600. p += strlen(pc->prot.dss1.uus1_data);
  1601. pc->prot.dss1.uus1_data[0] = '\0';
  1602. }
  1603. l = p - tmp;
  1604. if (!(skb = l3_alloc_skb(l)))
  1605. return;
  1606. memcpy(skb_put(skb, l), tmp, l);
  1607. newl3state(pc, 11);
  1608. l3_msg(pc->st, DL_DATA | REQUEST, skb);
  1609. L3AddTimer(&pc->timer, T305, CC_T305);
  1610. }
  1611. static void
  1612. l3dss1_setup_rsp(struct l3_process *pc, u_char pr,
  1613. void *arg)
  1614. {
  1615. if (!pc->para.bchannel)
  1616. { if (pc->debug & L3_DEB_WARN)
  1617. l3_debug(pc->st, "D-chan connect for waiting call");
  1618. l3dss1_disconnect_req(pc, pr, arg);
  1619. return;
  1620. }
  1621. newl3state(pc, 8);
  1622. l3dss1_message(pc, MT_CONNECT);
  1623. L3DelTimer(&pc->timer);
  1624. L3AddTimer(&pc->timer, T313, CC_T313);
  1625. }
  1626. static void
  1627. l3dss1_connect_ack(struct l3_process *pc, u_char pr, void *arg)
  1628. {
  1629. struct sk_buff *skb = arg;
  1630. int ret;
  1631. ret = check_infoelements(pc, skb, ie_CONNECT_ACKNOWLEDGE);
  1632. if (ERR_IE_COMPREHENSION == ret) {
  1633. l3dss1_std_ie_err(pc, ret);
  1634. return;
  1635. }
  1636. newl3state(pc, 10);
  1637. L3DelTimer(&pc->timer);
  1638. if (ret)
  1639. l3dss1_std_ie_err(pc, ret);
  1640. pc->st->l3.l3l4(pc->st, CC_SETUP_COMPL | INDICATION, pc);
  1641. }
  1642. static void
  1643. l3dss1_reject_req(struct l3_process *pc, u_char pr, void *arg)
  1644. {
  1645. struct sk_buff *skb;
  1646. u_char tmp[16];
  1647. u_char *p = tmp;
  1648. int l;
  1649. u_char cause = 21;
  1650. if (pc->para.cause != NO_CAUSE)
  1651. cause = pc->para.cause;
  1652. MsgHead(p, pc->callref, MT_RELEASE_COMPLETE);
  1653. *p++ = IE_CAUSE;
  1654. *p++ = 0x2;
  1655. *p++ = 0x80;
  1656. *p++ = cause | 0x80;
  1657. l = p - tmp;
  1658. if (!(skb = l3_alloc_skb(l)))
  1659. return;
  1660. memcpy(skb_put(skb, l), tmp, l);
  1661. l3_msg(pc->st, DL_DATA | REQUEST, skb);
  1662. pc->st->l3.l3l4(pc->st, CC_RELEASE | INDICATION, pc);
  1663. newl3state(pc, 0);
  1664. dss1_release_l3_process(pc);
  1665. }
  1666. static void
  1667. l3dss1_release(struct l3_process *pc, u_char pr, void *arg)
  1668. {
  1669. struct sk_buff *skb = arg;
  1670. u_char *p;
  1671. int ret, cause=0;
  1672. StopAllL3Timer(pc);
  1673. if ((ret = l3dss1_get_cause(pc, skb))>0) {
  1674. if (pc->debug & L3_DEB_WARN)
  1675. l3_debug(pc->st, "REL get_cause ret(%d)", ret);
  1676. } else if (ret<0)
  1677. pc->para.cause = NO_CAUSE;
  1678. if ((p = findie(skb->data, skb->len, IE_FACILITY, 0))) {
  1679. l3dss1_parse_facility(pc->st, pc, pc->callref, p);
  1680. }
  1681. if ((ret<0) && (pc->state != 11))
  1682. cause = 96;
  1683. else if (ret>0)
  1684. cause = 100;
  1685. ret = check_infoelements(pc, skb, ie_RELEASE);
  1686. if (ERR_IE_COMPREHENSION == ret)
  1687. cause = 96;
  1688. else if ((ERR_IE_UNRECOGNIZED == ret) && (!cause))
  1689. cause = 99;
  1690. if (cause)
  1691. l3dss1_message_cause(pc, MT_RELEASE_COMPLETE, cause);
  1692. else
  1693. l3dss1_message(pc, MT_RELEASE_COMPLETE);
  1694. pc->st->l3.l3l4(pc->st, CC_RELEASE | INDICATION, pc);
  1695. newl3state(pc, 0);
  1696. dss1_release_l3_process(pc);
  1697. }
  1698. static void
  1699. l3dss1_alert_req(struct l3_process *pc, u_char pr,
  1700. void *arg)
  1701. {
  1702. newl3state(pc, 7);
  1703. if (!pc->prot.dss1.uus1_data[0])
  1704. l3dss1_message(pc, MT_ALERTING);
  1705. else
  1706. l3dss1_msg_with_uus(pc, MT_ALERTING);
  1707. }
  1708. static void
  1709. l3dss1_proceed_req(struct l3_process *pc, u_char pr,
  1710. void *arg)
  1711. {
  1712. newl3state(pc, 9);
  1713. l3dss1_message(pc, MT_CALL_PROCEEDING);
  1714. pc->st->l3.l3l4(pc->st, CC_PROCEED_SEND | INDICATION, pc);
  1715. }
  1716. static void
  1717. l3dss1_setup_ack_req(struct l3_process *pc, u_char pr,
  1718. void *arg)
  1719. {
  1720. newl3state(pc, 25);
  1721. L3DelTimer(&pc->timer);
  1722. L3AddTimer(&pc->timer, T302, CC_T302);
  1723. l3dss1_message(pc, MT_SETUP_ACKNOWLEDGE);
  1724. }
  1725. /********************************************/
  1726. /* deliver a incoming display message to HL */
  1727. /********************************************/
  1728. static void
  1729. l3dss1_deliver_display(struct l3_process *pc, int pr, u_char *infp)
  1730. { u_char len;
  1731. isdn_ctrl ic;
  1732. struct IsdnCardState *cs;
  1733. char *p;
  1734. if (*infp++ != IE_DISPLAY) return;
  1735. if ((len = *infp++) > 80) return; /* total length <= 82 */
  1736. if (!pc->chan) return;
  1737. p = ic.parm.display;
  1738. while (len--)
  1739. *p++ = *infp++;
  1740. *p = '\0';
  1741. ic.command = ISDN_STAT_DISPLAY;
  1742. cs = pc->st->l1.hardware;
  1743. ic.driver = cs->myid;
  1744. ic.arg = pc->chan->chan;
  1745. cs->iif.statcallb(&ic);
  1746. } /* l3dss1_deliver_display */
  1747. static void
  1748. l3dss1_progress(struct l3_process *pc, u_char pr, void *arg)
  1749. {
  1750. struct sk_buff *skb = arg;
  1751. int err = 0;
  1752. u_char *p;
  1753. if ((p = findie(skb->data, skb->len, IE_PROGRESS, 0))) {
  1754. if (p[1] != 2) {
  1755. err = 1;
  1756. pc->para.cause = 100;
  1757. } else if (!(p[2] & 0x70)) {
  1758. switch (p[2]) {
  1759. case 0x80:
  1760. case 0x81:
  1761. case 0x82:
  1762. case 0x84:
  1763. case 0x85:
  1764. case 0x87:
  1765. case 0x8a:
  1766. switch (p[3]) {
  1767. case 0x81:
  1768. case 0x82:
  1769. case 0x83:
  1770. case 0x84:
  1771. case 0x88:
  1772. break;
  1773. default:
  1774. err = 2;
  1775. pc->para.cause = 100;
  1776. break;
  1777. }
  1778. break;
  1779. default:
  1780. err = 3;
  1781. pc->para.cause = 100;
  1782. break;
  1783. }
  1784. }
  1785. } else {
  1786. pc->para.cause = 96;
  1787. err = 4;
  1788. }
  1789. if (err) {
  1790. if (pc->debug & L3_DEB_WARN)
  1791. l3_debug(pc->st, "progress error %d", err);
  1792. l3dss1_status_send(pc, pr, NULL);
  1793. return;
  1794. }
  1795. /* Now we are on none mandatory IEs */
  1796. err = check_infoelements(pc, skb, ie_PROGRESS);
  1797. if (err)
  1798. l3dss1_std_ie_err(pc, err);
  1799. if (ERR_IE_COMPREHENSION != err)
  1800. pc->st->l3.l3l4(pc->st, CC_PROGRESS | INDICATION, pc);
  1801. }
  1802. static void
  1803. l3dss1_notify(struct l3_process *pc, u_char pr, void *arg)
  1804. {
  1805. struct sk_buff *skb = arg;
  1806. int err = 0;
  1807. u_char *p;
  1808. if ((p = findie(skb->data, skb->len, IE_NOTIFY, 0))) {
  1809. if (p[1] != 1) {
  1810. err = 1;
  1811. pc->para.cause = 100;
  1812. } else {
  1813. switch (p[2]) {
  1814. case 0x80:
  1815. case 0x81:
  1816. case 0x82:
  1817. break;
  1818. default:
  1819. pc->para.cause = 100;
  1820. err = 2;
  1821. break;
  1822. }
  1823. }
  1824. } else {
  1825. pc->para.cause = 96;
  1826. err = 3;
  1827. }
  1828. if (err) {
  1829. if (pc->debug & L3_DEB_WARN)
  1830. l3_debug(pc->st, "notify error %d", err);
  1831. l3dss1_status_send(pc, pr, NULL);
  1832. return;
  1833. }
  1834. /* Now we are on none mandatory IEs */
  1835. err = check_infoelements(pc, skb, ie_NOTIFY);
  1836. if (err)
  1837. l3dss1_std_ie_err(pc, err);
  1838. if (ERR_IE_COMPREHENSION != err)
  1839. pc->st->l3.l3l4(pc->st, CC_NOTIFY | INDICATION, pc);
  1840. }
  1841. static void
  1842. l3dss1_status_enq(struct l3_process *pc, u_char pr, void *arg)
  1843. {
  1844. int ret;
  1845. struct sk_buff *skb = arg;
  1846. ret = check_infoelements(pc, skb, ie_STATUS_ENQUIRY);
  1847. l3dss1_std_ie_err(pc, ret);
  1848. pc->para.cause = 30; /* response to STATUS_ENQUIRY */
  1849. l3dss1_status_send(pc, pr, NULL);
  1850. }
  1851. static void
  1852. l3dss1_information(struct l3_process *pc, u_char pr, void *arg)
  1853. {
  1854. int ret;
  1855. struct sk_buff *skb = arg;
  1856. u_char *p;
  1857. char tmp[32];
  1858. ret = check_infoelements(pc, skb, ie_INFORMATION);
  1859. if (ret)
  1860. l3dss1_std_ie_err(pc, ret);
  1861. if (pc->state == 25) { /* overlap receiving */
  1862. L3DelTimer(&pc->timer);
  1863. p = skb->data;
  1864. if ((p = findie(p, skb->len, 0x70, 0))) {
  1865. iecpy(tmp, p, 1);
  1866. strcat(pc->para.setup.eazmsn, tmp);
  1867. pc->st->l3.l3l4(pc->st, CC_MORE_INFO | INDICATION, pc);
  1868. }
  1869. L3AddTimer(&pc->timer, T302, CC_T302);
  1870. }
  1871. }
  1872. /******************************/
  1873. /* handle deflection requests */
  1874. /******************************/
  1875. static void l3dss1_redir_req(struct l3_process *pc, u_char pr, void *arg)
  1876. {
  1877. struct sk_buff *skb;
  1878. u_char tmp[128];
  1879. u_char *p = tmp;
  1880. u_char *subp;
  1881. u_char len_phone = 0;
  1882. u_char len_sub = 0;
  1883. int l;
  1884. strcpy(pc->prot.dss1.uus1_data,pc->chan->setup.eazmsn); /* copy uus element if available */
  1885. if (!pc->chan->setup.phone[0])
  1886. { pc->para.cause = -1;
  1887. l3dss1_disconnect_req(pc,pr,arg); /* disconnect immediately */
  1888. return;
  1889. } /* only uus */
  1890. if (pc->prot.dss1.invoke_id)
  1891. free_invoke_id(pc->st,pc->prot.dss1.invoke_id);
  1892. if (!(pc->prot.dss1.invoke_id = new_invoke_id(pc->st)))
  1893. return;
  1894. MsgHead(p, pc->callref, MT_FACILITY);
  1895. for (subp = pc->chan->setup.phone; (*subp) && (*subp != '.'); subp++) len_phone++; /* len of phone number */
  1896. if (*subp++ == '.') len_sub = strlen(subp) + 2; /* length including info subaddress element */
  1897. *p++ = 0x1c; /* Facility info element */
  1898. *p++ = len_phone + len_sub + 2 + 2 + 8 + 3 + 3; /* length of element */
  1899. *p++ = 0x91; /* remote operations protocol */
  1900. *p++ = 0xa1; /* invoke component */
  1901. *p++ = len_phone + len_sub + 2 + 2 + 8 + 3; /* length of data */
  1902. *p++ = 0x02; /* invoke id tag, integer */
  1903. *p++ = 0x01; /* length */
  1904. *p++ = pc->prot.dss1.invoke_id; /* invoke id */
  1905. *p++ = 0x02; /* operation value tag, integer */
  1906. *p++ = 0x01; /* length */
  1907. *p++ = 0x0D; /* Call Deflect */
  1908. *p++ = 0x30; /* sequence phone number */
  1909. *p++ = len_phone + 2 + 2 + 3 + len_sub; /* length */
  1910. *p++ = 0x30; /* Deflected to UserNumber */
  1911. *p++ = len_phone+2+len_sub; /* length */
  1912. *p++ = 0x80; /* NumberDigits */
  1913. *p++ = len_phone; /* length */
  1914. for (l = 0; l < len_phone; l++)
  1915. *p++ = pc->chan->setup.phone[l];
  1916. if (len_sub)
  1917. { *p++ = 0x04; /* called party subaddress */
  1918. *p++ = len_sub - 2;
  1919. while (*subp) *p++ = *subp++;
  1920. }
  1921. *p++ = 0x01; /* screening identifier */
  1922. *p++ = 0x01;
  1923. *p++ = pc->chan->setup.screen;
  1924. l = p - tmp;
  1925. if (!(skb = l3_alloc_skb(l))) return;
  1926. memcpy(skb_put(skb, l), tmp, l);
  1927. l3_msg(pc->st, DL_DATA | REQUEST, skb);
  1928. } /* l3dss1_redir_req */
  1929. /********************************************/
  1930. /* handle deflection request in early state */
  1931. /********************************************/
  1932. static void l3dss1_redir_req_early(struct l3_process *pc, u_char pr, void *arg)
  1933. {
  1934. l3dss1_proceed_req(pc,pr,arg);
  1935. l3dss1_redir_req(pc,pr,arg);
  1936. } /* l3dss1_redir_req_early */
  1937. /***********************************************/
  1938. /* handle special commands for this protocol. */
  1939. /* Examples are call independent services like */
  1940. /* remote operations with dummy callref. */
  1941. /***********************************************/
  1942. static int l3dss1_cmd_global(struct PStack *st, isdn_ctrl *ic)
  1943. { u_char id;
  1944. u_char temp[265];
  1945. u_char *p = temp;
  1946. int i, l, proc_len;
  1947. struct sk_buff *skb;
  1948. struct l3_process *pc = NULL;
  1949. switch (ic->arg)
  1950. { case DSS1_CMD_INVOKE:
  1951. if (ic->parm.dss1_io.datalen < 0) return(-2); /* invalid parameter */
  1952. for (proc_len = 1, i = ic->parm.dss1_io.proc >> 8; i; i++)
  1953. i = i >> 8; /* add one byte */
  1954. l = ic->parm.dss1_io.datalen + proc_len + 8; /* length excluding ie header */
  1955. if (l > 255)
  1956. return(-2); /* too long */
  1957. if (!(id = new_invoke_id(st)))
  1958. return(0); /* first get a invoke id -> return if no available */
  1959. i = -1;
  1960. MsgHead(p, i, MT_FACILITY); /* build message head */
  1961. *p++ = 0x1C; /* Facility IE */
  1962. *p++ = l; /* length of ie */
  1963. *p++ = 0x91; /* remote operations */
  1964. *p++ = 0xA1; /* invoke */
  1965. *p++ = l - 3; /* length of invoke */
  1966. *p++ = 0x02; /* invoke id tag */
  1967. *p++ = 0x01; /* length is 1 */
  1968. *p++ = id; /* invoke id */
  1969. *p++ = 0x02; /* operation */
  1970. *p++ = proc_len; /* length of operation */
  1971. for (i = proc_len; i; i--)
  1972. *p++ = (ic->parm.dss1_io.proc >> (i-1)) & 0xFF;
  1973. memcpy(p, ic->parm.dss1_io.data, ic->parm.dss1_io.datalen); /* copy data */
  1974. l = (p - temp) + ic->parm.dss1_io.datalen; /* total length */
  1975. if (ic->parm.dss1_io.timeout > 0)
  1976. if (!(pc = dss1_new_l3_process(st, -1)))
  1977. { free_invoke_id(st, id);
  1978. return(-2);
  1979. }
  1980. pc->prot.dss1.ll_id = ic->parm.dss1_io.ll_id; /* remember id */
  1981. pc->prot.dss1.proc = ic->parm.dss1_io.proc; /* and procedure */
  1982. if (!(skb = l3_alloc_skb(l)))
  1983. { free_invoke_id(st, id);
  1984. if (pc) dss1_release_l3_process(pc);
  1985. return(-2);
  1986. }
  1987. memcpy(skb_put(skb, l), temp, l);
  1988. if (pc)
  1989. { pc->prot.dss1.invoke_id = id; /* remember id */
  1990. L3AddTimer(&pc->timer, ic->parm.dss1_io.timeout, CC_TDSS1_IO | REQUEST);
  1991. }
  1992. l3_msg(st, DL_DATA | REQUEST, skb);
  1993. ic->parm.dss1_io.hl_id = id; /* return id */
  1994. return(0);
  1995. case DSS1_CMD_INVOKE_ABORT:
  1996. if ((pc = l3dss1_search_dummy_proc(st, ic->parm.dss1_io.hl_id)))
  1997. { L3DelTimer(&pc->timer); /* remove timer */
  1998. dss1_release_l3_process(pc);
  1999. return(0);
  2000. }
  2001. else
  2002. { l3_debug(st, "l3dss1_cmd_global abort unknown id");
  2003. return(-2);
  2004. }
  2005. break;
  2006. default:
  2007. l3_debug(st, "l3dss1_cmd_global unknown cmd 0x%lx", ic->arg);
  2008. return(-1);
  2009. } /* switch ic-> arg */
  2010. return(-1);
  2011. } /* l3dss1_cmd_global */
  2012. static void
  2013. l3dss1_io_timer(struct l3_process *pc)
  2014. { isdn_ctrl ic;
  2015. struct IsdnCardState *cs = pc->st->l1.hardware;
  2016. L3DelTimer(&pc->timer); /* remove timer */
  2017. ic.driver = cs->myid;
  2018. ic.command = ISDN_STAT_PROT;
  2019. ic.arg = DSS1_STAT_INVOKE_ERR;
  2020. ic.parm.dss1_io.hl_id = pc->prot.dss1.invoke_id;
  2021. ic.parm.dss1_io.ll_id = pc->prot.dss1.ll_id;
  2022. ic.parm.dss1_io.proc = pc->prot.dss1.proc;
  2023. ic.parm.dss1_io.timeout= -1;
  2024. ic.parm.dss1_io.datalen = 0;
  2025. ic.parm.dss1_io.data = NULL;
  2026. free_invoke_id(pc->st, pc->prot.dss1.invoke_id);
  2027. pc->prot.dss1.invoke_id = 0; /* reset id */
  2028. cs->iif.statcallb(&ic);
  2029. dss1_release_l3_process(pc);
  2030. } /* l3dss1_io_timer */
  2031. static void
  2032. l3dss1_release_ind(struct l3_process *pc, u_char pr, void *arg)
  2033. {
  2034. u_char *p;
  2035. struct sk_buff *skb = arg;
  2036. int callState = 0;
  2037. p = skb->data;
  2038. if ((p = findie(p, skb->len, IE_CALL_STATE, 0))) {
  2039. p++;
  2040. if (1 == *p++)
  2041. callState = *p;
  2042. }
  2043. if (callState == 0) {
  2044. /* ETS 300-104 7.6.1, 8.6.1, 10.6.1... and 16.1
  2045. * set down layer 3 without sending any message
  2046. */
  2047. pc->st->l3.l3l4(pc->st, CC_RELEASE | INDICATION, pc);
  2048. newl3state(pc, 0);
  2049. dss1_release_l3_process(pc);
  2050. } else {
  2051. pc->st->l3.l3l4(pc->st, CC_IGNORE | INDICATION, pc);
  2052. }
  2053. }
  2054. static void
  2055. l3dss1_dummy(struct l3_process *pc, u_char pr, void *arg)
  2056. {
  2057. }
  2058. static void
  2059. l3dss1_t302(struct l3_process *pc, u_char pr, void *arg)
  2060. {
  2061. L3DelTimer(&pc->timer);
  2062. pc->para.loc = 0;
  2063. pc->para.cause = 28; /* invalid number */
  2064. l3dss1_disconnect_req(pc, pr, NULL);
  2065. pc->st->l3.l3l4(pc->st, CC_SETUP_ERR, pc);
  2066. }
  2067. static void
  2068. l3dss1_t303(struct l3_process *pc, u_char pr, void *arg)
  2069. {
  2070. if (pc->N303 > 0) {
  2071. pc->N303--;
  2072. L3DelTimer(&pc->timer);
  2073. l3dss1_setup_req(pc, pr, arg);
  2074. } else {
  2075. L3DelTimer(&pc->timer);
  2076. l3dss1_message_cause(pc, MT_RELEASE_COMPLETE, 102);
  2077. pc->st->l3.l3l4(pc->st, CC_NOSETUP_RSP, pc);
  2078. dss1_release_l3_process(pc);
  2079. }
  2080. }
  2081. static void
  2082. l3dss1_t304(struct l3_process *pc, u_char pr, void *arg)
  2083. {
  2084. L3DelTimer(&pc->timer);
  2085. pc->para.loc = 0;
  2086. pc->para.cause = 102;
  2087. l3dss1_disconnect_req(pc, pr, NULL);
  2088. pc->st->l3.l3l4(pc->st, CC_SETUP_ERR, pc);
  2089. }
  2090. static void
  2091. l3dss1_t305(struct l3_process *pc, u_char pr, void *arg)
  2092. {
  2093. u_char tmp[16];
  2094. u_char *p = tmp;
  2095. int l;
  2096. struct sk_buff *skb;
  2097. u_char cause = 16;
  2098. L3DelTimer(&pc->timer);
  2099. if (pc->para.cause != NO_CAUSE)
  2100. cause = pc->para.cause;
  2101. MsgHead(p, pc->callref, MT_RELEASE);
  2102. *p++ = IE_CAUSE;
  2103. *p++ = 0x2;
  2104. *p++ = 0x80;
  2105. *p++ = cause | 0x80;
  2106. l = p - tmp;
  2107. if (!(skb = l3_alloc_skb(l)))
  2108. return;
  2109. memcpy(skb_put(skb, l), tmp, l);
  2110. newl3state(pc, 19);
  2111. l3_msg(pc->st, DL_DATA | REQUEST, skb);
  2112. L3AddTimer(&pc->timer, T308, CC_T308_1);
  2113. }
  2114. static void
  2115. l3dss1_t310(struct l3_process *pc, u_char pr, void *arg)
  2116. {
  2117. L3DelTimer(&pc->timer);
  2118. pc->para.loc = 0;
  2119. pc->para.cause = 102;
  2120. l3dss1_disconnect_req(pc, pr, NULL);
  2121. pc->st->l3.l3l4(pc->st, CC_SETUP_ERR, pc);
  2122. }
  2123. static void
  2124. l3dss1_t313(struct l3_process *pc, u_char pr, void *arg)
  2125. {
  2126. L3DelTimer(&pc->timer);
  2127. pc->para.loc = 0;
  2128. pc->para.cause = 102;
  2129. l3dss1_disconnect_req(pc, pr, NULL);
  2130. pc->st->l3.l3l4(pc->st, CC_CONNECT_ERR, pc);
  2131. }
  2132. static void
  2133. l3dss1_t308_1(struct l3_process *pc, u_char pr, void *arg)
  2134. {
  2135. newl3state(pc, 19);
  2136. L3DelTimer(&pc->timer);
  2137. l3dss1_message(pc, MT_RELEASE);
  2138. L3AddTimer(&pc->timer, T308, CC_T308_2);
  2139. }
  2140. static void
  2141. l3dss1_t308_2(struct l3_process *pc, u_char pr, void *arg)
  2142. {
  2143. L3DelTimer(&pc->timer);
  2144. pc->st->l3.l3l4(pc->st, CC_RELEASE_ERR, pc);
  2145. dss1_release_l3_process(pc);
  2146. }
  2147. static void
  2148. l3dss1_t318(struct l3_process *pc, u_char pr, void *arg)
  2149. {
  2150. L3DelTimer(&pc->timer);
  2151. pc->para.cause = 102; /* Timer expiry */
  2152. pc->para.loc = 0; /* local */
  2153. pc->st->l3.l3l4(pc->st, CC_RESUME_ERR, pc);
  2154. newl3state(pc, 19);
  2155. l3dss1_message(pc, MT_RELEASE);
  2156. L3AddTimer(&pc->timer, T308, CC_T308_1);
  2157. }
  2158. static void
  2159. l3dss1_t319(struct l3_process *pc, u_char pr, void *arg)
  2160. {
  2161. L3DelTimer(&pc->timer);
  2162. pc->para.cause = 102; /* Timer expiry */
  2163. pc->para.loc = 0; /* local */
  2164. pc->st->l3.l3l4(pc->st, CC_SUSPEND_ERR, pc);
  2165. newl3state(pc, 10);
  2166. }
  2167. static void
  2168. l3dss1_restart(struct l3_process *pc, u_char pr, void *arg)
  2169. {
  2170. L3DelTimer(&pc->timer);
  2171. pc->st->l3.l3l4(pc->st, CC_RELEASE | INDICATION, pc);
  2172. dss1_release_l3_process(pc);
  2173. }
  2174. static void
  2175. l3dss1_status(struct l3_process *pc, u_char pr, void *arg)
  2176. {
  2177. u_char *p;
  2178. struct sk_buff *skb = arg;
  2179. int ret;
  2180. u_char cause = 0, callState = 0;
  2181. if ((ret = l3dss1_get_cause(pc, skb))) {
  2182. if (pc->debug & L3_DEB_WARN)
  2183. l3_debug(pc->st, "STATUS get_cause ret(%d)",ret);
  2184. if (ret < 0)
  2185. cause = 96;
  2186. else if (ret > 0)
  2187. cause = 100;
  2188. }
  2189. if ((p = findie(skb->data, skb->len, IE_CALL_STATE, 0))) {
  2190. p++;
  2191. if (1 == *p++) {
  2192. callState = *p;
  2193. if (!ie_in_set(pc, *p, l3_valid_states))
  2194. cause = 100;
  2195. } else
  2196. cause = 100;
  2197. } else
  2198. cause = 96;
  2199. if (!cause) { /* no error before */
  2200. ret = check_infoelements(pc, skb, ie_STATUS);
  2201. if (ERR_IE_COMPREHENSION == ret)
  2202. cause = 96;
  2203. else if (ERR_IE_UNRECOGNIZED == ret)
  2204. cause = 99;
  2205. }
  2206. if (cause) {
  2207. u_char tmp;
  2208. if (pc->debug & L3_DEB_WARN)
  2209. l3_debug(pc->st, "STATUS error(%d/%d)",ret,cause);
  2210. tmp = pc->para.cause;
  2211. pc->para.cause = cause;
  2212. l3dss1_status_send(pc, 0, NULL);
  2213. if (cause == 99)
  2214. pc->para.cause = tmp;
  2215. else
  2216. return;
  2217. }
  2218. cause = pc->para.cause;
  2219. if (((cause & 0x7f) == 111) && (callState == 0)) {
  2220. /* ETS 300-104 7.6.1, 8.6.1, 10.6.1...
  2221. * if received MT_STATUS with cause == 111 and call
  2222. * state == 0, then we must set down layer 3
  2223. */
  2224. pc->st->l3.l3l4(pc->st, CC_RELEASE | INDICATION, pc);
  2225. newl3state(pc, 0);
  2226. dss1_release_l3_process(pc);
  2227. }
  2228. }
  2229. static void
  2230. l3dss1_facility(struct l3_process *pc, u_char pr, void *arg)
  2231. {
  2232. struct sk_buff *skb = arg;
  2233. int ret;
  2234. ret = check_infoelements(pc, skb, ie_FACILITY);
  2235. l3dss1_std_ie_err(pc, ret);
  2236. {
  2237. u_char *p;
  2238. if ((p = findie(skb->data, skb->len, IE_FACILITY, 0)))
  2239. l3dss1_parse_facility(pc->st, pc, pc->callref, p);
  2240. }
  2241. }
  2242. static void
  2243. l3dss1_suspend_req(struct l3_process *pc, u_char pr, void *arg)
  2244. {
  2245. struct sk_buff *skb;
  2246. u_char tmp[32];
  2247. u_char *p = tmp;
  2248. u_char i, l;
  2249. u_char *msg = pc->chan->setup.phone;
  2250. MsgHead(p, pc->callref, MT_SUSPEND);
  2251. l = *msg++;
  2252. if (l && (l <= 10)) { /* Max length 10 octets */
  2253. *p++ = IE_CALL_ID;
  2254. *p++ = l;
  2255. for (i = 0; i < l; i++)
  2256. *p++ = *msg++;
  2257. } else if (l) {
  2258. l3_debug(pc->st, "SUS wrong CALL_ID len %d", l);
  2259. return;
  2260. }
  2261. l = p - tmp;
  2262. if (!(skb = l3_alloc_skb(l)))
  2263. return;
  2264. memcpy(skb_put(skb, l), tmp, l);
  2265. l3_msg(pc->st, DL_DATA | REQUEST, skb);
  2266. newl3state(pc, 15);
  2267. L3AddTimer(&pc->timer, T319, CC_T319);
  2268. }
  2269. static void
  2270. l3dss1_suspend_ack(struct l3_process *pc, u_char pr, void *arg)
  2271. {
  2272. struct sk_buff *skb = arg;
  2273. int ret;
  2274. L3DelTimer(&pc->timer);
  2275. newl3state(pc, 0);
  2276. pc->para.cause = NO_CAUSE;
  2277. pc->st->l3.l3l4(pc->st, CC_SUSPEND | CONFIRM, pc);
  2278. /* We don't handle suspend_ack for IE errors now */
  2279. if ((ret = check_infoelements(pc, skb, ie_SUSPEND_ACKNOWLEDGE)))
  2280. if (pc->debug & L3_DEB_WARN)
  2281. l3_debug(pc->st, "SUSPACK check ie(%d)",ret);
  2282. dss1_release_l3_process(pc);
  2283. }
  2284. static void
  2285. l3dss1_suspend_rej(struct l3_process *pc, u_char pr, void *arg)
  2286. {
  2287. struct sk_buff *skb = arg;
  2288. int ret;
  2289. if ((ret = l3dss1_get_cause(pc, skb))) {
  2290. if (pc->debug & L3_DEB_WARN)
  2291. l3_debug(pc->st, "SUSP_REJ get_cause ret(%d)",ret);
  2292. if (ret < 0)
  2293. pc->para.cause = 96;
  2294. else
  2295. pc->para.cause = 100;
  2296. l3dss1_status_send(pc, pr, NULL);
  2297. return;
  2298. }
  2299. ret = check_infoelements(pc, skb, ie_SUSPEND_REJECT);
  2300. if (ERR_IE_COMPREHENSION == ret) {
  2301. l3dss1_std_ie_err(pc, ret);
  2302. return;
  2303. }
  2304. L3DelTimer(&pc->timer);
  2305. pc->st->l3.l3l4(pc->st, CC_SUSPEND_ERR, pc);
  2306. newl3state(pc, 10);
  2307. if (ret) /* STATUS for none mandatory IE errors after actions are taken */
  2308. l3dss1_std_ie_err(pc, ret);
  2309. }
  2310. static void
  2311. l3dss1_resume_req(struct l3_process *pc, u_char pr, void *arg)
  2312. {
  2313. struct sk_buff *skb;
  2314. u_char tmp[32];
  2315. u_char *p = tmp;
  2316. u_char i, l;
  2317. u_char *msg = pc->para.setup.phone;
  2318. MsgHead(p, pc->callref, MT_RESUME);
  2319. l = *msg++;
  2320. if (l && (l <= 10)) { /* Max length 10 octets */
  2321. *p++ = IE_CALL_ID;
  2322. *p++ = l;
  2323. for (i = 0; i < l; i++)
  2324. *p++ = *msg++;
  2325. } else if (l) {
  2326. l3_debug(pc->st, "RES wrong CALL_ID len %d", l);
  2327. return;
  2328. }
  2329. l = p - tmp;
  2330. if (!(skb = l3_alloc_skb(l)))
  2331. return;
  2332. memcpy(skb_put(skb, l), tmp, l);
  2333. l3_msg(pc->st, DL_DATA | REQUEST, skb);
  2334. newl3state(pc, 17);
  2335. L3AddTimer(&pc->timer, T318, CC_T318);
  2336. }
  2337. static void
  2338. l3dss1_resume_ack(struct l3_process *pc, u_char pr, void *arg)
  2339. {
  2340. struct sk_buff *skb = arg;
  2341. int id, ret;
  2342. if ((id = l3dss1_get_channel_id(pc, skb)) > 0) {
  2343. if ((0 == id) || ((3 == id) && (0x10 == pc->para.moderate))) {
  2344. if (pc->debug & L3_DEB_WARN)
  2345. l3_debug(pc->st, "resume ack with wrong chid %x", id);
  2346. pc->para.cause = 100;
  2347. l3dss1_status_send(pc, pr, NULL);
  2348. return;
  2349. }
  2350. pc->para.bchannel = id;
  2351. } else if (1 == pc->state) {
  2352. if (pc->debug & L3_DEB_WARN)
  2353. l3_debug(pc->st, "resume ack without chid (ret %d)", id);
  2354. pc->para.cause = 96;
  2355. l3dss1_status_send(pc, pr, NULL);
  2356. return;
  2357. }
  2358. ret = check_infoelements(pc, skb, ie_RESUME_ACKNOWLEDGE);
  2359. if (ERR_IE_COMPREHENSION == ret) {
  2360. l3dss1_std_ie_err(pc, ret);
  2361. return;
  2362. }
  2363. L3DelTimer(&pc->timer);
  2364. pc->st->l3.l3l4(pc->st, CC_RESUME | CONFIRM, pc);
  2365. newl3state(pc, 10);
  2366. if (ret) /* STATUS for none mandatory IE errors after actions are taken */
  2367. l3dss1_std_ie_err(pc, ret);
  2368. }
  2369. static void
  2370. l3dss1_resume_rej(struct l3_process *pc, u_char pr, void *arg)
  2371. {
  2372. struct sk_buff *skb = arg;
  2373. int ret;
  2374. if ((ret = l3dss1_get_cause(pc, skb))) {
  2375. if (pc->debug & L3_DEB_WARN)
  2376. l3_debug(pc->st, "RES_REJ get_cause ret(%d)",ret);
  2377. if (ret < 0)
  2378. pc->para.cause = 96;
  2379. else
  2380. pc->para.cause = 100;
  2381. l3dss1_status_send(pc, pr, NULL);
  2382. return;
  2383. }
  2384. ret = check_infoelements(pc, skb, ie_RESUME_REJECT);
  2385. if (ERR_IE_COMPREHENSION == ret) {
  2386. l3dss1_std_ie_err(pc, ret);
  2387. return;
  2388. }
  2389. L3DelTimer(&pc->timer);
  2390. pc->st->l3.l3l4(pc->st, CC_RESUME_ERR, pc);
  2391. newl3state(pc, 0);
  2392. if (ret) /* STATUS for none mandatory IE errors after actions are taken */
  2393. l3dss1_std_ie_err(pc, ret);
  2394. dss1_release_l3_process(pc);
  2395. }
  2396. static void
  2397. l3dss1_global_restart(struct l3_process *pc, u_char pr, void *arg)
  2398. {
  2399. u_char tmp[32];
  2400. u_char *p;
  2401. u_char ri, ch = 0, chan = 0;
  2402. int l;
  2403. struct sk_buff *skb = arg;
  2404. struct l3_process *up;
  2405. newl3state(pc, 2);
  2406. L3DelTimer(&pc->timer);
  2407. p = skb->data;
  2408. if ((p = findie(p, skb->len, IE_RESTART_IND, 0))) {
  2409. ri = p[2];
  2410. l3_debug(pc->st, "Restart %x", ri);
  2411. } else {
  2412. l3_debug(pc->st, "Restart without restart IE");
  2413. ri = 0x86;
  2414. }
  2415. p = skb->data;
  2416. if ((p = findie(p, skb->len, IE_CHANNEL_ID, 0))) {
  2417. chan = p[2] & 3;
  2418. ch = p[2];
  2419. if (pc->st->l3.debug)
  2420. l3_debug(pc->st, "Restart for channel %d", chan);
  2421. }
  2422. newl3state(pc, 2);
  2423. up = pc->st->l3.proc;
  2424. while (up) {
  2425. if ((ri & 7) == 7)
  2426. up->st->lli.l4l3(up->st, CC_RESTART | REQUEST, up);
  2427. else if (up->para.bchannel == chan)
  2428. up->st->lli.l4l3(up->st, CC_RESTART | REQUEST, up);
  2429. up = up->next;
  2430. }
  2431. p = tmp;
  2432. MsgHead(p, pc->callref, MT_RESTART_ACKNOWLEDGE);
  2433. if (chan) {
  2434. *p++ = IE_CHANNEL_ID;
  2435. *p++ = 1;
  2436. *p++ = ch | 0x80;
  2437. }
  2438. *p++ = 0x79; /* RESTART Ind */
  2439. *p++ = 1;
  2440. *p++ = ri;
  2441. l = p - tmp;
  2442. if (!(skb = l3_alloc_skb(l)))
  2443. return;
  2444. memcpy(skb_put(skb, l), tmp, l);
  2445. newl3state(pc, 0);
  2446. l3_msg(pc->st, DL_DATA | REQUEST, skb);
  2447. }
  2448. static void
  2449. l3dss1_dl_reset(struct l3_process *pc, u_char pr, void *arg)
  2450. {
  2451. pc->para.cause = 0x29; /* Temporary failure */
  2452. pc->para.loc = 0;
  2453. l3dss1_disconnect_req(pc, pr, NULL);
  2454. pc->st->l3.l3l4(pc->st, CC_SETUP_ERR, pc);
  2455. }
  2456. static void
  2457. l3dss1_dl_release(struct l3_process *pc, u_char pr, void *arg)
  2458. {
  2459. newl3state(pc, 0);
  2460. pc->para.cause = 0x1b; /* Destination out of order */
  2461. pc->para.loc = 0;
  2462. pc->st->l3.l3l4(pc->st, CC_RELEASE | INDICATION, pc);
  2463. release_l3_process(pc);
  2464. }
  2465. static void
  2466. l3dss1_dl_reestablish(struct l3_process *pc, u_char pr, void *arg)
  2467. {
  2468. L3DelTimer(&pc->timer);
  2469. L3AddTimer(&pc->timer, T309, CC_T309);
  2470. l3_msg(pc->st, DL_ESTABLISH | REQUEST, NULL);
  2471. }
  2472. static void
  2473. l3dss1_dl_reest_status(struct l3_process *pc, u_char pr, void *arg)
  2474. {
  2475. L3DelTimer(&pc->timer);
  2476. pc->para.cause = 0x1F; /* normal, unspecified */
  2477. l3dss1_status_send(pc, 0, NULL);
  2478. }
  2479. /* *INDENT-OFF* */
  2480. static struct stateentry downstatelist[] =
  2481. {
  2482. {SBIT(0),
  2483. CC_SETUP | REQUEST, l3dss1_setup_req},
  2484. {SBIT(0),
  2485. CC_RESUME | REQUEST, l3dss1_resume_req},
  2486. {SBIT(1) | SBIT(2) | SBIT(3) | SBIT(4) | SBIT(6) | SBIT(7) | SBIT(8) | SBIT(9) | SBIT(10) | SBIT(25),
  2487. CC_DISCONNECT | REQUEST, l3dss1_disconnect_req},
  2488. {SBIT(12),
  2489. CC_RELEASE | REQUEST, l3dss1_release_req},
  2490. {ALL_STATES,
  2491. CC_RESTART | REQUEST, l3dss1_restart},
  2492. {SBIT(6) | SBIT(25),
  2493. CC_IGNORE | REQUEST, l3dss1_reset},
  2494. {SBIT(6) | SBIT(25),
  2495. CC_REJECT | REQUEST, l3dss1_reject_req},
  2496. {SBIT(6) | SBIT(25),
  2497. CC_PROCEED_SEND | REQUEST, l3dss1_proceed_req},
  2498. {SBIT(6),
  2499. CC_MORE_INFO | REQUEST, l3dss1_setup_ack_req},
  2500. {SBIT(25),
  2501. CC_MORE_INFO | REQUEST, l3dss1_dummy},
  2502. {SBIT(6) | SBIT(9) | SBIT(25),
  2503. CC_ALERTING | REQUEST, l3dss1_alert_req},
  2504. {SBIT(6) | SBIT(7) | SBIT(9) | SBIT(25),
  2505. CC_SETUP | RESPONSE, l3dss1_setup_rsp},
  2506. {SBIT(10),
  2507. CC_SUSPEND | REQUEST, l3dss1_suspend_req},
  2508. {SBIT(7) | SBIT(9) | SBIT(25),
  2509. CC_REDIR | REQUEST, l3dss1_redir_req},
  2510. {SBIT(6),
  2511. CC_REDIR | REQUEST, l3dss1_redir_req_early},
  2512. {SBIT(9) | SBIT(25),
  2513. CC_DISCONNECT | REQUEST, l3dss1_disconnect_req},
  2514. {SBIT(25),
  2515. CC_T302, l3dss1_t302},
  2516. {SBIT(1),
  2517. CC_T303, l3dss1_t303},
  2518. {SBIT(2),
  2519. CC_T304, l3dss1_t304},
  2520. {SBIT(3),
  2521. CC_T310, l3dss1_t310},
  2522. {SBIT(8),
  2523. CC_T313, l3dss1_t313},
  2524. {SBIT(11),
  2525. CC_T305, l3dss1_t305},
  2526. {SBIT(15),
  2527. CC_T319, l3dss1_t319},
  2528. {SBIT(17),
  2529. CC_T318, l3dss1_t318},
  2530. {SBIT(19),
  2531. CC_T308_1, l3dss1_t308_1},
  2532. {SBIT(19),
  2533. CC_T308_2, l3dss1_t308_2},
  2534. {SBIT(10),
  2535. CC_T309, l3dss1_dl_release},
  2536. };
  2537. static struct stateentry datastatelist[] =
  2538. {
  2539. {ALL_STATES,
  2540. MT_STATUS_ENQUIRY, l3dss1_status_enq},
  2541. {ALL_STATES,
  2542. MT_FACILITY, l3dss1_facility},
  2543. {SBIT(19),
  2544. MT_STATUS, l3dss1_release_ind},
  2545. {ALL_STATES,
  2546. MT_STATUS, l3dss1_status},
  2547. {SBIT(0),
  2548. MT_SETUP, l3dss1_setup},
  2549. {SBIT(6) | SBIT(7) | SBIT(8) | SBIT(9) | SBIT(10) | SBIT(11) | SBIT(12) |
  2550. SBIT(15) | SBIT(17) | SBIT(19) | SBIT(25),
  2551. MT_SETUP, l3dss1_dummy},
  2552. {SBIT(1) | SBIT(2),
  2553. MT_CALL_PROCEEDING, l3dss1_call_proc},
  2554. {SBIT(1),
  2555. MT_SETUP_ACKNOWLEDGE, l3dss1_setup_ack},
  2556. {SBIT(2) | SBIT(3),
  2557. MT_ALERTING, l3dss1_alerting},
  2558. {SBIT(2) | SBIT(3),
  2559. MT_PROGRESS, l3dss1_progress},
  2560. {SBIT(2) | SBIT(3) | SBIT(4) | SBIT(7) | SBIT(8) | SBIT(9) | SBIT(10) |
  2561. SBIT(11) | SBIT(12) | SBIT(15) | SBIT(17) | SBIT(19) | SBIT(25),
  2562. MT_INFORMATION, l3dss1_information},
  2563. {SBIT(10) | SBIT(11) | SBIT(15),
  2564. MT_NOTIFY, l3dss1_notify},
  2565. {SBIT(0) | SBIT(1) | SBIT(2) | SBIT(3) | SBIT(4) | SBIT(7) | SBIT(8) | SBIT(10) |
  2566. SBIT(11) | SBIT(12) | SBIT(15) | SBIT(17) | SBIT(19) | SBIT(25),
  2567. MT_RELEASE_COMPLETE, l3dss1_release_cmpl},
  2568. {SBIT(1) | SBIT(2) | SBIT(3) | SBIT(4) | SBIT(7) | SBIT(8) | SBIT(9) | SBIT(10) | SBIT(11) | SBIT(12) | SBIT(15) | SBIT(17) | SBIT(25),
  2569. MT_RELEASE, l3dss1_release},
  2570. {SBIT(19), MT_RELEASE, l3dss1_release_ind},
  2571. {SBIT(1) | SBIT(2) | SBIT(3) | SBIT(4) | SBIT(7) | SBIT(8) | SBIT(9) | SBIT(10) | SBIT(11) | SBIT(15) | SBIT(17) | SBIT(25),
  2572. MT_DISCONNECT, l3dss1_disconnect},
  2573. {SBIT(19),
  2574. MT_DISCONNECT, l3dss1_dummy},
  2575. {SBIT(1) | SBIT(2) | SBIT(3) | SBIT(4),
  2576. MT_CONNECT, l3dss1_connect},
  2577. {SBIT(8),
  2578. MT_CONNECT_ACKNOWLEDGE, l3dss1_connect_ack},
  2579. {SBIT(15),
  2580. MT_SUSPEND_ACKNOWLEDGE, l3dss1_suspend_ack},
  2581. {SBIT(15),
  2582. MT_SUSPEND_REJECT, l3dss1_suspend_rej},
  2583. {SBIT(17),
  2584. MT_RESUME_ACKNOWLEDGE, l3dss1_resume_ack},
  2585. {SBIT(17),
  2586. MT_RESUME_REJECT, l3dss1_resume_rej},
  2587. };
  2588. static struct stateentry globalmes_list[] =
  2589. {
  2590. {ALL_STATES,
  2591. MT_STATUS, l3dss1_status},
  2592. {SBIT(0),
  2593. MT_RESTART, l3dss1_global_restart},
  2594. /* {SBIT(1),
  2595. MT_RESTART_ACKNOWLEDGE, l3dss1_restart_ack},
  2596. */
  2597. };
  2598. static struct stateentry manstatelist[] =
  2599. {
  2600. {SBIT(2),
  2601. DL_ESTABLISH | INDICATION, l3dss1_dl_reset},
  2602. {SBIT(10),
  2603. DL_ESTABLISH | CONFIRM, l3dss1_dl_reest_status},
  2604. {SBIT(10),
  2605. DL_RELEASE | INDICATION, l3dss1_dl_reestablish},
  2606. {ALL_STATES,
  2607. DL_RELEASE | INDICATION, l3dss1_dl_release},
  2608. };
  2609. /* *INDENT-ON* */
  2610. static void
  2611. global_handler(struct PStack *st, int mt, struct sk_buff *skb)
  2612. {
  2613. u_char tmp[16];
  2614. u_char *p = tmp;
  2615. int l;
  2616. int i;
  2617. struct l3_process *proc = st->l3.global;
  2618. proc->callref = skb->data[2]; /* cr flag */
  2619. for (i = 0; i < ARRAY_SIZE(globalmes_list); i++)
  2620. if ((mt == globalmes_list[i].primitive) &&
  2621. ((1 << proc->state) & globalmes_list[i].state))
  2622. break;
  2623. if (i == ARRAY_SIZE(globalmes_list)) {
  2624. if (st->l3.debug & L3_DEB_STATE) {
  2625. l3_debug(st, "dss1 global state %d mt %x unhandled",
  2626. proc->state, mt);
  2627. }
  2628. MsgHead(p, proc->callref, MT_STATUS);
  2629. *p++ = IE_CAUSE;
  2630. *p++ = 0x2;
  2631. *p++ = 0x80;
  2632. *p++ = 81 |0x80; /* invalid cr */
  2633. *p++ = 0x14; /* CallState */
  2634. *p++ = 0x1;
  2635. *p++ = proc->state & 0x3f;
  2636. l = p - tmp;
  2637. if (!(skb = l3_alloc_skb(l)))
  2638. return;
  2639. memcpy(skb_put(skb, l), tmp, l);
  2640. l3_msg(proc->st, DL_DATA | REQUEST, skb);
  2641. } else {
  2642. if (st->l3.debug & L3_DEB_STATE) {
  2643. l3_debug(st, "dss1 global %d mt %x",
  2644. proc->state, mt);
  2645. }
  2646. globalmes_list[i].rout(proc, mt, skb);
  2647. }
  2648. }
  2649. static void
  2650. dss1up(struct PStack *st, int pr, void *arg)
  2651. {
  2652. int i, mt, cr, callState;
  2653. char *ptr;
  2654. u_char *p;
  2655. struct sk_buff *skb = arg;
  2656. struct l3_process *proc;
  2657. switch (pr) {
  2658. case (DL_DATA | INDICATION):
  2659. case (DL_UNIT_DATA | INDICATION):
  2660. break;
  2661. case (DL_ESTABLISH | CONFIRM):
  2662. case (DL_ESTABLISH | INDICATION):
  2663. case (DL_RELEASE | INDICATION):
  2664. case (DL_RELEASE | CONFIRM):
  2665. l3_msg(st, pr, arg);
  2666. return;
  2667. break;
  2668. default:
  2669. printk(KERN_ERR "HiSax dss1up unknown pr=%04x\n", pr);
  2670. return;
  2671. }
  2672. if (skb->len < 3) {
  2673. l3_debug(st, "dss1up frame too short(%d)", skb->len);
  2674. dev_kfree_skb(skb);
  2675. return;
  2676. }
  2677. if (skb->data[0] != PROTO_DIS_EURO) {
  2678. if (st->l3.debug & L3_DEB_PROTERR) {
  2679. l3_debug(st, "dss1up%sunexpected discriminator %x message len %d",
  2680. (pr == (DL_DATA | INDICATION)) ? " " : "(broadcast) ",
  2681. skb->data[0], skb->len);
  2682. }
  2683. dev_kfree_skb(skb);
  2684. return;
  2685. }
  2686. cr = getcallref(skb->data);
  2687. if (skb->len < ((skb->data[1] & 0x0f) + 3)) {
  2688. l3_debug(st, "dss1up frame too short(%d)", skb->len);
  2689. dev_kfree_skb(skb);
  2690. return;
  2691. }
  2692. mt = skb->data[skb->data[1] + 2];
  2693. if (st->l3.debug & L3_DEB_STATE)
  2694. l3_debug(st, "dss1up cr %d", cr);
  2695. if (cr == -2) { /* wrong Callref */
  2696. if (st->l3.debug & L3_DEB_WARN)
  2697. l3_debug(st, "dss1up wrong Callref");
  2698. dev_kfree_skb(skb);
  2699. return;
  2700. } else if (cr == -1) { /* Dummy Callref */
  2701. if (mt == MT_FACILITY)
  2702. if ((p = findie(skb->data, skb->len, IE_FACILITY, 0))) {
  2703. l3dss1_parse_facility(st, NULL,
  2704. (pr == (DL_DATA | INDICATION)) ? -1 : -2, p);
  2705. dev_kfree_skb(skb);
  2706. return;
  2707. }
  2708. if (st->l3.debug & L3_DEB_WARN)
  2709. l3_debug(st, "dss1up dummy Callref (no facility msg or ie)");
  2710. dev_kfree_skb(skb);
  2711. return;
  2712. } else if ((((skb->data[1] & 0x0f) == 1) && (0==(cr & 0x7f))) ||
  2713. (((skb->data[1] & 0x0f) == 2) && (0==(cr & 0x7fff)))) { /* Global CallRef */
  2714. if (st->l3.debug & L3_DEB_STATE)
  2715. l3_debug(st, "dss1up Global CallRef");
  2716. global_handler(st, mt, skb);
  2717. dev_kfree_skb(skb);
  2718. return;
  2719. } else if (!(proc = getl3proc(st, cr))) {
  2720. /* No transaction process exist, that means no call with
  2721. * this callreference is active
  2722. */
  2723. if (mt == MT_SETUP) {
  2724. /* Setup creates a new transaction process */
  2725. if (skb->data[2] & 0x80) {
  2726. /* Setup with wrong CREF flag */
  2727. if (st->l3.debug & L3_DEB_STATE)
  2728. l3_debug(st, "dss1up wrong CRef flag");
  2729. dev_kfree_skb(skb);
  2730. return;
  2731. }
  2732. if (!(proc = dss1_new_l3_process(st, cr))) {
  2733. /* May be to answer with RELEASE_COMPLETE and
  2734. * CAUSE 0x2f "Resource unavailable", but this
  2735. * need a new_l3_process too ... arghh
  2736. */
  2737. dev_kfree_skb(skb);
  2738. return;
  2739. }
  2740. } else if (mt == MT_STATUS) {
  2741. if ((ptr = findie(skb->data, skb->len, IE_CAUSE, 0)) != NULL) {
  2742. ptr++;
  2743. if (*ptr++ == 2)
  2744. ptr++;
  2745. }
  2746. callState = 0;
  2747. if ((ptr = findie(skb->data, skb->len, IE_CALL_STATE, 0)) != NULL) {
  2748. ptr++;
  2749. if (*ptr++ == 2)
  2750. ptr++;
  2751. callState = *ptr;
  2752. }
  2753. /* ETS 300-104 part 2.4.1
  2754. * if setup has not been made and a message type
  2755. * MT_STATUS is received with call state == 0,
  2756. * we must send nothing
  2757. */
  2758. if (callState != 0) {
  2759. /* ETS 300-104 part 2.4.2
  2760. * if setup has not been made and a message type
  2761. * MT_STATUS is received with call state != 0,
  2762. * we must send MT_RELEASE_COMPLETE cause 101
  2763. */
  2764. if ((proc = dss1_new_l3_process(st, cr))) {
  2765. proc->para.cause = 101;
  2766. l3dss1_msg_without_setup(proc, 0, NULL);
  2767. }
  2768. }
  2769. dev_kfree_skb(skb);
  2770. return;
  2771. } else if (mt == MT_RELEASE_COMPLETE) {
  2772. dev_kfree_skb(skb);
  2773. return;
  2774. } else {
  2775. /* ETS 300-104 part 2
  2776. * if setup has not been made and a message type
  2777. * (except MT_SETUP and RELEASE_COMPLETE) is received,
  2778. * we must send MT_RELEASE_COMPLETE cause 81 */
  2779. dev_kfree_skb(skb);
  2780. if ((proc = dss1_new_l3_process(st, cr))) {
  2781. proc->para.cause = 81;
  2782. l3dss1_msg_without_setup(proc, 0, NULL);
  2783. }
  2784. return;
  2785. }
  2786. }
  2787. if (l3dss1_check_messagetype_validity(proc, mt, skb)) {
  2788. dev_kfree_skb(skb);
  2789. return;
  2790. }
  2791. if ((p = findie(skb->data, skb->len, IE_DISPLAY, 0)) != NULL)
  2792. l3dss1_deliver_display(proc, pr, p); /* Display IE included */
  2793. for (i = 0; i < ARRAY_SIZE(datastatelist); i++)
  2794. if ((mt == datastatelist[i].primitive) &&
  2795. ((1 << proc->state) & datastatelist[i].state))
  2796. break;
  2797. if (i == ARRAY_SIZE(datastatelist)) {
  2798. if (st->l3.debug & L3_DEB_STATE) {
  2799. l3_debug(st, "dss1up%sstate %d mt %#x unhandled",
  2800. (pr == (DL_DATA | INDICATION)) ? " " : "(broadcast) ",
  2801. proc->state, mt);
  2802. }
  2803. if ((MT_RELEASE_COMPLETE != mt) && (MT_RELEASE != mt)) {
  2804. proc->para.cause = 101;
  2805. l3dss1_status_send(proc, pr, skb);
  2806. }
  2807. } else {
  2808. if (st->l3.debug & L3_DEB_STATE) {
  2809. l3_debug(st, "dss1up%sstate %d mt %x",
  2810. (pr == (DL_DATA | INDICATION)) ? " " : "(broadcast) ",
  2811. proc->state, mt);
  2812. }
  2813. datastatelist[i].rout(proc, pr, skb);
  2814. }
  2815. dev_kfree_skb(skb);
  2816. return;
  2817. }
  2818. static void
  2819. dss1down(struct PStack *st, int pr, void *arg)
  2820. {
  2821. int i, cr;
  2822. struct l3_process *proc;
  2823. struct Channel *chan;
  2824. if ((DL_ESTABLISH | REQUEST) == pr) {
  2825. l3_msg(st, pr, NULL);
  2826. return;
  2827. } else if (((CC_SETUP | REQUEST) == pr) || ((CC_RESUME | REQUEST) == pr)) {
  2828. chan = arg;
  2829. cr = newcallref();
  2830. cr |= 0x80;
  2831. if ((proc = dss1_new_l3_process(st, cr))) {
  2832. proc->chan = chan;
  2833. chan->proc = proc;
  2834. memcpy(&proc->para.setup, &chan->setup, sizeof(setup_parm));
  2835. proc->callref = cr;
  2836. }
  2837. } else {
  2838. proc = arg;
  2839. }
  2840. if (!proc) {
  2841. printk(KERN_ERR "HiSax dss1down without proc pr=%04x\n", pr);
  2842. return;
  2843. }
  2844. if ( pr == (CC_TDSS1_IO | REQUEST)) {
  2845. l3dss1_io_timer(proc); /* timer expires */
  2846. return;
  2847. }
  2848. for (i = 0; i < ARRAY_SIZE(downstatelist); i++)
  2849. if ((pr == downstatelist[i].primitive) &&
  2850. ((1 << proc->state) & downstatelist[i].state))
  2851. break;
  2852. if (i == ARRAY_SIZE(downstatelist)) {
  2853. if (st->l3.debug & L3_DEB_STATE) {
  2854. l3_debug(st, "dss1down state %d prim %#x unhandled",
  2855. proc->state, pr);
  2856. }
  2857. } else {
  2858. if (st->l3.debug & L3_DEB_STATE) {
  2859. l3_debug(st, "dss1down state %d prim %#x",
  2860. proc->state, pr);
  2861. }
  2862. downstatelist[i].rout(proc, pr, arg);
  2863. }
  2864. }
  2865. static void
  2866. dss1man(struct PStack *st, int pr, void *arg)
  2867. {
  2868. int i;
  2869. struct l3_process *proc = arg;
  2870. if (!proc) {
  2871. printk(KERN_ERR "HiSax dss1man without proc pr=%04x\n", pr);
  2872. return;
  2873. }
  2874. for (i = 0; i < ARRAY_SIZE(manstatelist); i++)
  2875. if ((pr == manstatelist[i].primitive) &&
  2876. ((1 << proc->state) & manstatelist[i].state))
  2877. break;
  2878. if (i == ARRAY_SIZE(manstatelist)) {
  2879. if (st->l3.debug & L3_DEB_STATE) {
  2880. l3_debug(st, "cr %d dss1man state %d prim %#x unhandled",
  2881. proc->callref & 0x7f, proc->state, pr);
  2882. }
  2883. } else {
  2884. if (st->l3.debug & L3_DEB_STATE) {
  2885. l3_debug(st, "cr %d dss1man state %d prim %#x",
  2886. proc->callref & 0x7f, proc->state, pr);
  2887. }
  2888. manstatelist[i].rout(proc, pr, arg);
  2889. }
  2890. }
  2891. void
  2892. setstack_dss1(struct PStack *st)
  2893. {
  2894. char tmp[64];
  2895. int i;
  2896. st->lli.l4l3 = dss1down;
  2897. st->lli.l4l3_proto = l3dss1_cmd_global;
  2898. st->l2.l2l3 = dss1up;
  2899. st->l3.l3ml3 = dss1man;
  2900. st->l3.N303 = 1;
  2901. st->prot.dss1.last_invoke_id = 0;
  2902. st->prot.dss1.invoke_used[0] = 1; /* Bit 0 must always be set to 1 */
  2903. i = 1;
  2904. while (i < 32)
  2905. st->prot.dss1.invoke_used[i++] = 0;
  2906. if (!(st->l3.global = kmalloc(sizeof(struct l3_process), GFP_ATOMIC))) {
  2907. printk(KERN_ERR "HiSax can't get memory for dss1 global CR\n");
  2908. } else {
  2909. st->l3.global->state = 0;
  2910. st->l3.global->callref = 0;
  2911. st->l3.global->next = NULL;
  2912. st->l3.global->debug = L3_DEB_WARN;
  2913. st->l3.global->st = st;
  2914. st->l3.global->N303 = 1;
  2915. st->l3.global->prot.dss1.invoke_id = 0;
  2916. L3InitTimer(st->l3.global, &st->l3.global->timer);
  2917. }
  2918. strcpy(tmp, dss1_revision);
  2919. printk(KERN_INFO "HiSax: DSS1 Rev. %s\n", HiSax_getrev(tmp));
  2920. }