l3ni1.c 75 KB

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