capi.c 62 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246
  1. /*
  2. * Kernel CAPI interface for the Gigaset driver
  3. *
  4. * Copyright (c) 2009 by Tilman Schmidt <tilman@imap.cc>.
  5. *
  6. * =====================================================================
  7. * This program is free software; you can redistribute it and/or
  8. * modify it under the terms of the GNU General Public License as
  9. * published by the Free Software Foundation; either version 2 of
  10. * the License, or (at your option) any later version.
  11. * =====================================================================
  12. */
  13. #include "gigaset.h"
  14. #include <linux/proc_fs.h>
  15. #include <linux/seq_file.h>
  16. #include <linux/isdn/capilli.h>
  17. #include <linux/isdn/capicmd.h>
  18. #include <linux/isdn/capiutil.h>
  19. /* missing from kernelcapi.h */
  20. #define CapiNcpiNotSupportedByProtocol 0x0001
  21. #define CapiFlagsNotSupportedByProtocol 0x0002
  22. #define CapiAlertAlreadySent 0x0003
  23. #define CapiFacilitySpecificFunctionNotSupported 0x3011
  24. /* missing from capicmd.h */
  25. #define CAPI_CONNECT_IND_BASELEN (CAPI_MSG_BASELEN+4+2+8*1)
  26. #define CAPI_CONNECT_ACTIVE_IND_BASELEN (CAPI_MSG_BASELEN+4+3*1)
  27. #define CAPI_CONNECT_B3_IND_BASELEN (CAPI_MSG_BASELEN+4+1)
  28. #define CAPI_CONNECT_B3_ACTIVE_IND_BASELEN (CAPI_MSG_BASELEN+4+1)
  29. #define CAPI_DATA_B3_REQ_LEN64 (CAPI_MSG_BASELEN+4+4+2+2+2+8)
  30. #define CAPI_DATA_B3_CONF_LEN (CAPI_MSG_BASELEN+4+2+2)
  31. #define CAPI_DISCONNECT_IND_LEN (CAPI_MSG_BASELEN+4+2)
  32. #define CAPI_DISCONNECT_B3_IND_BASELEN (CAPI_MSG_BASELEN+4+2+1)
  33. #define CAPI_FACILITY_CONF_BASELEN (CAPI_MSG_BASELEN+4+2+2+1)
  34. /* most _CONF messages contain only Controller/PLCI/NCCI and Info parameters */
  35. #define CAPI_STDCONF_LEN (CAPI_MSG_BASELEN+4+2)
  36. #define CAPI_FACILITY_HANDSET 0x0000
  37. #define CAPI_FACILITY_DTMF 0x0001
  38. #define CAPI_FACILITY_V42BIS 0x0002
  39. #define CAPI_FACILITY_SUPPSVC 0x0003
  40. #define CAPI_FACILITY_WAKEUP 0x0004
  41. #define CAPI_FACILITY_LI 0x0005
  42. #define CAPI_SUPPSVC_GETSUPPORTED 0x0000
  43. /* missing from capiutil.h */
  44. #define CAPIMSG_PLCI_PART(m) CAPIMSG_U8(m, 9)
  45. #define CAPIMSG_NCCI_PART(m) CAPIMSG_U16(m, 10)
  46. #define CAPIMSG_HANDLE_REQ(m) CAPIMSG_U16(m, 18) /* DATA_B3_REQ/_IND only! */
  47. #define CAPIMSG_FLAGS(m) CAPIMSG_U16(m, 20)
  48. #define CAPIMSG_SETCONTROLLER(m, contr) capimsg_setu8(m, 8, contr)
  49. #define CAPIMSG_SETPLCI_PART(m, plci) capimsg_setu8(m, 9, plci)
  50. #define CAPIMSG_SETNCCI_PART(m, ncci) capimsg_setu16(m, 10, ncci)
  51. #define CAPIMSG_SETFLAGS(m, flags) capimsg_setu16(m, 20, flags)
  52. /* parameters with differing location in DATA_B3_CONF/_RESP: */
  53. #define CAPIMSG_SETHANDLE_CONF(m, handle) capimsg_setu16(m, 12, handle)
  54. #define CAPIMSG_SETINFO_CONF(m, info) capimsg_setu16(m, 14, info)
  55. /* Flags (DATA_B3_REQ/_IND) */
  56. #define CAPI_FLAGS_DELIVERY_CONFIRMATION 0x04
  57. #define CAPI_FLAGS_RESERVED (~0x1f)
  58. /* buffer sizes */
  59. #define MAX_BC_OCTETS 11
  60. #define MAX_HLC_OCTETS 3
  61. #define MAX_NUMBER_DIGITS 20
  62. #define MAX_FMT_IE_LEN 20
  63. /* values for gigaset_capi_appl.connected */
  64. #define APCONN_NONE 0 /* inactive/listening */
  65. #define APCONN_SETUP 1 /* connecting */
  66. #define APCONN_ACTIVE 2 /* B channel up */
  67. /* registered application data structure */
  68. struct gigaset_capi_appl {
  69. struct list_head ctrlist;
  70. struct gigaset_capi_appl *bcnext;
  71. u16 id;
  72. struct capi_register_params rp;
  73. u16 nextMessageNumber;
  74. u32 listenInfoMask;
  75. u32 listenCIPmask;
  76. int connected;
  77. };
  78. /* CAPI specific controller data structure */
  79. struct gigaset_capi_ctr {
  80. struct capi_ctr ctr;
  81. struct list_head appls;
  82. struct sk_buff_head sendqueue;
  83. atomic_t sendqlen;
  84. /* two _cmsg structures possibly used concurrently: */
  85. _cmsg hcmsg; /* for message composition triggered from hardware */
  86. _cmsg acmsg; /* for dissection of messages sent from application */
  87. u8 bc_buf[MAX_BC_OCTETS+1];
  88. u8 hlc_buf[MAX_HLC_OCTETS+1];
  89. u8 cgpty_buf[MAX_NUMBER_DIGITS+3];
  90. u8 cdpty_buf[MAX_NUMBER_DIGITS+2];
  91. };
  92. /* CIP Value table (from CAPI 2.0 standard, ch. 6.1) */
  93. static struct {
  94. u8 *bc;
  95. u8 *hlc;
  96. } cip2bchlc[] = {
  97. [1] = { "8090A3", NULL },
  98. /* Speech (A-law) */
  99. [2] = { "8890", NULL },
  100. /* Unrestricted digital information */
  101. [3] = { "8990", NULL },
  102. /* Restricted digital information */
  103. [4] = { "9090A3", NULL },
  104. /* 3,1 kHz audio (A-law) */
  105. [5] = { "9190", NULL },
  106. /* 7 kHz audio */
  107. [6] = { "9890", NULL },
  108. /* Video */
  109. [7] = { "88C0C6E6", NULL },
  110. /* Packet mode */
  111. [8] = { "8890218F", NULL },
  112. /* 56 kbit/s rate adaptation */
  113. [9] = { "9190A5", NULL },
  114. /* Unrestricted digital information with tones/announcements */
  115. [16] = { "8090A3", "9181" },
  116. /* Telephony */
  117. [17] = { "9090A3", "9184" },
  118. /* Group 2/3 facsimile */
  119. [18] = { "8890", "91A1" },
  120. /* Group 4 facsimile Class 1 */
  121. [19] = { "8890", "91A4" },
  122. /* Teletex service basic and mixed mode
  123. and Group 4 facsimile service Classes II and III */
  124. [20] = { "8890", "91A8" },
  125. /* Teletex service basic and processable mode */
  126. [21] = { "8890", "91B1" },
  127. /* Teletex service basic mode */
  128. [22] = { "8890", "91B2" },
  129. /* International interworking for Videotex */
  130. [23] = { "8890", "91B5" },
  131. /* Telex */
  132. [24] = { "8890", "91B8" },
  133. /* Message Handling Systems in accordance with X.400 */
  134. [25] = { "8890", "91C1" },
  135. /* OSI application in accordance with X.200 */
  136. [26] = { "9190A5", "9181" },
  137. /* 7 kHz telephony */
  138. [27] = { "9190A5", "916001" },
  139. /* Video telephony, first connection */
  140. [28] = { "8890", "916002" },
  141. /* Video telephony, second connection */
  142. };
  143. /*
  144. * helper functions
  145. * ================
  146. */
  147. /*
  148. * emit unsupported parameter warning
  149. */
  150. static inline void ignore_cstruct_param(struct cardstate *cs, _cstruct param,
  151. char *msgname, char *paramname)
  152. {
  153. if (param && *param)
  154. dev_warn(cs->dev, "%s: ignoring unsupported parameter: %s\n",
  155. msgname, paramname);
  156. }
  157. /*
  158. * convert an IE from Gigaset hex string to ETSI binary representation
  159. * including length byte
  160. * return value: result length, -1 on error
  161. */
  162. static int encode_ie(char *in, u8 *out, int maxlen)
  163. {
  164. int l = 0;
  165. while (*in) {
  166. if (!isxdigit(in[0]) || !isxdigit(in[1]) || l >= maxlen)
  167. return -1;
  168. out[++l] = (hex_to_bin(in[0]) << 4) + hex_to_bin(in[1]);
  169. in += 2;
  170. }
  171. out[0] = l;
  172. return l;
  173. }
  174. /*
  175. * convert an IE from ETSI binary representation including length byte
  176. * to Gigaset hex string
  177. */
  178. static void decode_ie(u8 *in, char *out)
  179. {
  180. int i = *in;
  181. while (i-- > 0) {
  182. /* ToDo: conversion to upper case necessary? */
  183. *out++ = toupper(hex_asc_hi(*++in));
  184. *out++ = toupper(hex_asc_lo(*in));
  185. }
  186. }
  187. /*
  188. * retrieve application data structure for an application ID
  189. */
  190. static inline struct gigaset_capi_appl *
  191. get_appl(struct gigaset_capi_ctr *iif, u16 appl)
  192. {
  193. struct gigaset_capi_appl *ap;
  194. list_for_each_entry(ap, &iif->appls, ctrlist)
  195. if (ap->id == appl)
  196. return ap;
  197. return NULL;
  198. }
  199. /*
  200. * dump CAPI message to kernel messages for debugging
  201. */
  202. static inline void dump_cmsg(enum debuglevel level, const char *tag, _cmsg *p)
  203. {
  204. #ifdef CONFIG_GIGASET_DEBUG
  205. _cdebbuf *cdb;
  206. if (!(gigaset_debuglevel & level))
  207. return;
  208. cdb = capi_cmsg2str(p);
  209. if (cdb) {
  210. gig_dbg(level, "%s: [%d] %s", tag, p->ApplId, cdb->buf);
  211. cdebbuf_free(cdb);
  212. } else {
  213. gig_dbg(level, "%s: [%d] %s", tag, p->ApplId,
  214. capi_cmd2str(p->Command, p->Subcommand));
  215. }
  216. #endif
  217. }
  218. static inline void dump_rawmsg(enum debuglevel level, const char *tag,
  219. unsigned char *data)
  220. {
  221. #ifdef CONFIG_GIGASET_DEBUG
  222. char *dbgline;
  223. int i, l;
  224. if (!(gigaset_debuglevel & level))
  225. return;
  226. l = CAPIMSG_LEN(data);
  227. if (l < 12) {
  228. gig_dbg(level, "%s: ??? LEN=%04d", tag, l);
  229. return;
  230. }
  231. gig_dbg(level, "%s: 0x%02x:0x%02x: ID=%03d #0x%04x LEN=%04d NCCI=0x%x",
  232. tag, CAPIMSG_COMMAND(data), CAPIMSG_SUBCOMMAND(data),
  233. CAPIMSG_APPID(data), CAPIMSG_MSGID(data), l,
  234. CAPIMSG_CONTROL(data));
  235. l -= 12;
  236. dbgline = kmalloc(3*l, GFP_ATOMIC);
  237. if (!dbgline)
  238. return;
  239. for (i = 0; i < l; i++) {
  240. dbgline[3*i] = hex_asc_hi(data[12+i]);
  241. dbgline[3*i+1] = hex_asc_lo(data[12+i]);
  242. dbgline[3*i+2] = ' ';
  243. }
  244. dbgline[3*l-1] = '\0';
  245. gig_dbg(level, " %s", dbgline);
  246. kfree(dbgline);
  247. if (CAPIMSG_COMMAND(data) == CAPI_DATA_B3 &&
  248. (CAPIMSG_SUBCOMMAND(data) == CAPI_REQ ||
  249. CAPIMSG_SUBCOMMAND(data) == CAPI_IND) &&
  250. CAPIMSG_DATALEN(data) > 0) {
  251. l = CAPIMSG_DATALEN(data);
  252. dbgline = kmalloc(3*l, GFP_ATOMIC);
  253. if (!dbgline)
  254. return;
  255. data += CAPIMSG_LEN(data);
  256. for (i = 0; i < l; i++) {
  257. dbgline[3*i] = hex_asc_hi(data[i]);
  258. dbgline[3*i+1] = hex_asc_lo(data[i]);
  259. dbgline[3*i+2] = ' ';
  260. }
  261. dbgline[3*l-1] = '\0';
  262. gig_dbg(level, " %s", dbgline);
  263. kfree(dbgline);
  264. }
  265. #endif
  266. }
  267. /*
  268. * format CAPI IE as string
  269. */
  270. static const char *format_ie(const char *ie)
  271. {
  272. static char result[3*MAX_FMT_IE_LEN];
  273. int len, count;
  274. char *pout = result;
  275. if (!ie)
  276. return "NULL";
  277. count = len = ie[0];
  278. if (count > MAX_FMT_IE_LEN)
  279. count = MAX_FMT_IE_LEN-1;
  280. while (count--) {
  281. *pout++ = hex_asc_hi(*++ie);
  282. *pout++ = hex_asc_lo(*ie);
  283. *pout++ = ' ';
  284. }
  285. if (len > MAX_FMT_IE_LEN) {
  286. *pout++ = '.';
  287. *pout++ = '.';
  288. *pout++ = '.';
  289. }
  290. *--pout = 0;
  291. return result;
  292. }
  293. /*
  294. * driver interface functions
  295. * ==========================
  296. */
  297. /**
  298. * gigaset_skb_sent() - acknowledge transmission of outgoing skb
  299. * @bcs: B channel descriptor structure.
  300. * @skb: sent data.
  301. *
  302. * Called by hardware module {bas,ser,usb}_gigaset when the data in a
  303. * skb has been successfully sent, for signalling completion to the LL.
  304. */
  305. void gigaset_skb_sent(struct bc_state *bcs, struct sk_buff *dskb)
  306. {
  307. struct cardstate *cs = bcs->cs;
  308. struct gigaset_capi_ctr *iif = cs->iif;
  309. struct gigaset_capi_appl *ap = bcs->ap;
  310. unsigned char *req = skb_mac_header(dskb);
  311. struct sk_buff *cskb;
  312. u16 flags;
  313. /* update statistics */
  314. ++bcs->trans_up;
  315. if (!ap) {
  316. dev_err(cs->dev, "%s: no application\n", __func__);
  317. return;
  318. }
  319. /* don't send further B3 messages if disconnected */
  320. if (ap->connected < APCONN_ACTIVE) {
  321. gig_dbg(DEBUG_LLDATA, "disconnected, discarding ack");
  322. return;
  323. }
  324. /* ToDo: honor unset "delivery confirmation" bit */
  325. flags = CAPIMSG_FLAGS(req);
  326. /* build DATA_B3_CONF message */
  327. cskb = alloc_skb(CAPI_DATA_B3_CONF_LEN, GFP_ATOMIC);
  328. if (!cskb) {
  329. dev_err(cs->dev, "%s: out of memory\n", __func__);
  330. return;
  331. }
  332. /* frequent message, avoid _cmsg overhead */
  333. CAPIMSG_SETLEN(cskb->data, CAPI_DATA_B3_CONF_LEN);
  334. CAPIMSG_SETAPPID(cskb->data, ap->id);
  335. CAPIMSG_SETCOMMAND(cskb->data, CAPI_DATA_B3);
  336. CAPIMSG_SETSUBCOMMAND(cskb->data, CAPI_CONF);
  337. CAPIMSG_SETMSGID(cskb->data, CAPIMSG_MSGID(req));
  338. CAPIMSG_SETCONTROLLER(cskb->data, iif->ctr.cnr);
  339. CAPIMSG_SETPLCI_PART(cskb->data, bcs->channel + 1);
  340. CAPIMSG_SETNCCI_PART(cskb->data, 1);
  341. CAPIMSG_SETHANDLE_CONF(cskb->data, CAPIMSG_HANDLE_REQ(req));
  342. if (flags & ~CAPI_FLAGS_DELIVERY_CONFIRMATION)
  343. CAPIMSG_SETINFO_CONF(cskb->data,
  344. CapiFlagsNotSupportedByProtocol);
  345. else
  346. CAPIMSG_SETINFO_CONF(cskb->data, CAPI_NOERROR);
  347. /* emit message */
  348. dump_rawmsg(DEBUG_LLDATA, "DATA_B3_CONF", cskb->data);
  349. capi_ctr_handle_message(&iif->ctr, ap->id, cskb);
  350. }
  351. EXPORT_SYMBOL_GPL(gigaset_skb_sent);
  352. /**
  353. * gigaset_skb_rcvd() - pass received skb to LL
  354. * @bcs: B channel descriptor structure.
  355. * @skb: received data.
  356. *
  357. * Called by hardware module {bas,ser,usb}_gigaset when user data has
  358. * been successfully received, for passing to the LL.
  359. * Warning: skb must not be accessed anymore!
  360. */
  361. void gigaset_skb_rcvd(struct bc_state *bcs, struct sk_buff *skb)
  362. {
  363. struct cardstate *cs = bcs->cs;
  364. struct gigaset_capi_ctr *iif = cs->iif;
  365. struct gigaset_capi_appl *ap = bcs->ap;
  366. int len = skb->len;
  367. /* update statistics */
  368. bcs->trans_down++;
  369. if (!ap) {
  370. dev_err(cs->dev, "%s: no application\n", __func__);
  371. return;
  372. }
  373. /* don't send further B3 messages if disconnected */
  374. if (ap->connected < APCONN_ACTIVE) {
  375. gig_dbg(DEBUG_LLDATA, "disconnected, discarding data");
  376. dev_kfree_skb_any(skb);
  377. return;
  378. }
  379. /*
  380. * prepend DATA_B3_IND message to payload
  381. * Parameters: NCCI = 1, all others 0/unused
  382. * frequent message, avoid _cmsg overhead
  383. */
  384. skb_push(skb, CAPI_DATA_B3_REQ_LEN);
  385. CAPIMSG_SETLEN(skb->data, CAPI_DATA_B3_REQ_LEN);
  386. CAPIMSG_SETAPPID(skb->data, ap->id);
  387. CAPIMSG_SETCOMMAND(skb->data, CAPI_DATA_B3);
  388. CAPIMSG_SETSUBCOMMAND(skb->data, CAPI_IND);
  389. CAPIMSG_SETMSGID(skb->data, ap->nextMessageNumber++);
  390. CAPIMSG_SETCONTROLLER(skb->data, iif->ctr.cnr);
  391. CAPIMSG_SETPLCI_PART(skb->data, bcs->channel + 1);
  392. CAPIMSG_SETNCCI_PART(skb->data, 1);
  393. /* Data parameter not used */
  394. CAPIMSG_SETDATALEN(skb->data, len);
  395. /* Data handle parameter not used */
  396. CAPIMSG_SETFLAGS(skb->data, 0);
  397. /* Data64 parameter not present */
  398. /* emit message */
  399. dump_rawmsg(DEBUG_LLDATA, "DATA_B3_IND", skb->data);
  400. capi_ctr_handle_message(&iif->ctr, ap->id, skb);
  401. }
  402. EXPORT_SYMBOL_GPL(gigaset_skb_rcvd);
  403. /**
  404. * gigaset_isdn_rcv_err() - signal receive error
  405. * @bcs: B channel descriptor structure.
  406. *
  407. * Called by hardware module {bas,ser,usb}_gigaset when a receive error
  408. * has occurred, for signalling to the LL.
  409. */
  410. void gigaset_isdn_rcv_err(struct bc_state *bcs)
  411. {
  412. /* if currently ignoring packets, just count down */
  413. if (bcs->ignore) {
  414. bcs->ignore--;
  415. return;
  416. }
  417. /* update statistics */
  418. bcs->corrupted++;
  419. /* ToDo: signal error -> LL */
  420. }
  421. EXPORT_SYMBOL_GPL(gigaset_isdn_rcv_err);
  422. /**
  423. * gigaset_isdn_icall() - signal incoming call
  424. * @at_state: connection state structure.
  425. *
  426. * Called by main module at tasklet level to notify the LL that an incoming
  427. * call has been received. @at_state contains the parameters of the call.
  428. *
  429. * Return value: call disposition (ICALL_*)
  430. */
  431. int gigaset_isdn_icall(struct at_state_t *at_state)
  432. {
  433. struct cardstate *cs = at_state->cs;
  434. struct bc_state *bcs = at_state->bcs;
  435. struct gigaset_capi_ctr *iif = cs->iif;
  436. struct gigaset_capi_appl *ap;
  437. u32 actCIPmask;
  438. struct sk_buff *skb;
  439. unsigned int msgsize;
  440. int i;
  441. /*
  442. * ToDo: signal calls without a free B channel, too
  443. * (requires a u8 handle for the at_state structure that can
  444. * be stored in the PLCI and used in the CONNECT_RESP message
  445. * handler to retrieve it)
  446. */
  447. if (!bcs)
  448. return ICALL_IGNORE;
  449. /* prepare CONNECT_IND message, using B channel number as PLCI */
  450. capi_cmsg_header(&iif->hcmsg, 0, CAPI_CONNECT, CAPI_IND, 0,
  451. iif->ctr.cnr | ((bcs->channel + 1) << 8));
  452. /* minimum size, all structs empty */
  453. msgsize = CAPI_CONNECT_IND_BASELEN;
  454. /* Bearer Capability (mandatory) */
  455. if (at_state->str_var[STR_ZBC]) {
  456. /* pass on BC from Gigaset */
  457. if (encode_ie(at_state->str_var[STR_ZBC], iif->bc_buf,
  458. MAX_BC_OCTETS) < 0) {
  459. dev_warn(cs->dev, "RING ignored - bad BC %s\n",
  460. at_state->str_var[STR_ZBC]);
  461. return ICALL_IGNORE;
  462. }
  463. /* look up corresponding CIP value */
  464. iif->hcmsg.CIPValue = 0; /* default if nothing found */
  465. for (i = 0; i < ARRAY_SIZE(cip2bchlc); i++)
  466. if (cip2bchlc[i].bc != NULL &&
  467. cip2bchlc[i].hlc == NULL &&
  468. !strcmp(cip2bchlc[i].bc,
  469. at_state->str_var[STR_ZBC])) {
  470. iif->hcmsg.CIPValue = i;
  471. break;
  472. }
  473. } else {
  474. /* no BC (internal call): assume CIP 1 (speech, A-law) */
  475. iif->hcmsg.CIPValue = 1;
  476. encode_ie(cip2bchlc[1].bc, iif->bc_buf, MAX_BC_OCTETS);
  477. }
  478. iif->hcmsg.BC = iif->bc_buf;
  479. msgsize += iif->hcmsg.BC[0];
  480. /* High Layer Compatibility (optional) */
  481. if (at_state->str_var[STR_ZHLC]) {
  482. /* pass on HLC from Gigaset */
  483. if (encode_ie(at_state->str_var[STR_ZHLC], iif->hlc_buf,
  484. MAX_HLC_OCTETS) < 0) {
  485. dev_warn(cs->dev, "RING ignored - bad HLC %s\n",
  486. at_state->str_var[STR_ZHLC]);
  487. return ICALL_IGNORE;
  488. }
  489. iif->hcmsg.HLC = iif->hlc_buf;
  490. msgsize += iif->hcmsg.HLC[0];
  491. /* look up corresponding CIP value */
  492. /* keep BC based CIP value if none found */
  493. if (at_state->str_var[STR_ZBC])
  494. for (i = 0; i < ARRAY_SIZE(cip2bchlc); i++)
  495. if (cip2bchlc[i].hlc != NULL &&
  496. !strcmp(cip2bchlc[i].hlc,
  497. at_state->str_var[STR_ZHLC]) &&
  498. !strcmp(cip2bchlc[i].bc,
  499. at_state->str_var[STR_ZBC])) {
  500. iif->hcmsg.CIPValue = i;
  501. break;
  502. }
  503. }
  504. /* Called Party Number (optional) */
  505. if (at_state->str_var[STR_ZCPN]) {
  506. i = strlen(at_state->str_var[STR_ZCPN]);
  507. if (i > MAX_NUMBER_DIGITS) {
  508. dev_warn(cs->dev, "RING ignored - bad number %s\n",
  509. at_state->str_var[STR_ZBC]);
  510. return ICALL_IGNORE;
  511. }
  512. iif->cdpty_buf[0] = i + 1;
  513. iif->cdpty_buf[1] = 0x80; /* type / numbering plan unknown */
  514. memcpy(iif->cdpty_buf+2, at_state->str_var[STR_ZCPN], i);
  515. iif->hcmsg.CalledPartyNumber = iif->cdpty_buf;
  516. msgsize += iif->hcmsg.CalledPartyNumber[0];
  517. }
  518. /* Calling Party Number (optional) */
  519. if (at_state->str_var[STR_NMBR]) {
  520. i = strlen(at_state->str_var[STR_NMBR]);
  521. if (i > MAX_NUMBER_DIGITS) {
  522. dev_warn(cs->dev, "RING ignored - bad number %s\n",
  523. at_state->str_var[STR_ZBC]);
  524. return ICALL_IGNORE;
  525. }
  526. iif->cgpty_buf[0] = i + 2;
  527. iif->cgpty_buf[1] = 0x00; /* type / numbering plan unknown */
  528. iif->cgpty_buf[2] = 0x80; /* pres. allowed, not screened */
  529. memcpy(iif->cgpty_buf+3, at_state->str_var[STR_NMBR], i);
  530. iif->hcmsg.CallingPartyNumber = iif->cgpty_buf;
  531. msgsize += iif->hcmsg.CallingPartyNumber[0];
  532. }
  533. /* remaining parameters (not supported, always left NULL):
  534. * - CalledPartySubaddress
  535. * - CallingPartySubaddress
  536. * - AdditionalInfo
  537. * - BChannelinformation
  538. * - Keypadfacility
  539. * - Useruserdata
  540. * - Facilitydataarray
  541. */
  542. gig_dbg(DEBUG_CMD, "icall: PLCI %x CIP %d BC %s",
  543. iif->hcmsg.adr.adrPLCI, iif->hcmsg.CIPValue,
  544. format_ie(iif->hcmsg.BC));
  545. gig_dbg(DEBUG_CMD, "icall: HLC %s",
  546. format_ie(iif->hcmsg.HLC));
  547. gig_dbg(DEBUG_CMD, "icall: CgPty %s",
  548. format_ie(iif->hcmsg.CallingPartyNumber));
  549. gig_dbg(DEBUG_CMD, "icall: CdPty %s",
  550. format_ie(iif->hcmsg.CalledPartyNumber));
  551. /* scan application list for matching listeners */
  552. bcs->ap = NULL;
  553. actCIPmask = 1 | (1 << iif->hcmsg.CIPValue);
  554. list_for_each_entry(ap, &iif->appls, ctrlist)
  555. if (actCIPmask & ap->listenCIPmask) {
  556. /* build CONNECT_IND message for this application */
  557. iif->hcmsg.ApplId = ap->id;
  558. iif->hcmsg.Messagenumber = ap->nextMessageNumber++;
  559. skb = alloc_skb(msgsize, GFP_ATOMIC);
  560. if (!skb) {
  561. dev_err(cs->dev, "%s: out of memory\n",
  562. __func__);
  563. break;
  564. }
  565. capi_cmsg2message(&iif->hcmsg, __skb_put(skb, msgsize));
  566. dump_cmsg(DEBUG_CMD, __func__, &iif->hcmsg);
  567. /* add to listeners on this B channel, update state */
  568. ap->bcnext = bcs->ap;
  569. bcs->ap = ap;
  570. bcs->chstate |= CHS_NOTIFY_LL;
  571. ap->connected = APCONN_SETUP;
  572. /* emit message */
  573. capi_ctr_handle_message(&iif->ctr, ap->id, skb);
  574. }
  575. /*
  576. * Return "accept" if any listeners.
  577. * Gigaset will send ALERTING.
  578. * There doesn't seem to be a way to avoid this.
  579. */
  580. return bcs->ap ? ICALL_ACCEPT : ICALL_IGNORE;
  581. }
  582. /*
  583. * send a DISCONNECT_IND message to an application
  584. * does not sleep, clobbers the controller's hcmsg structure
  585. */
  586. static void send_disconnect_ind(struct bc_state *bcs,
  587. struct gigaset_capi_appl *ap, u16 reason)
  588. {
  589. struct cardstate *cs = bcs->cs;
  590. struct gigaset_capi_ctr *iif = cs->iif;
  591. struct sk_buff *skb;
  592. if (ap->connected == APCONN_NONE)
  593. return;
  594. capi_cmsg_header(&iif->hcmsg, ap->id, CAPI_DISCONNECT, CAPI_IND,
  595. ap->nextMessageNumber++,
  596. iif->ctr.cnr | ((bcs->channel + 1) << 8));
  597. iif->hcmsg.Reason = reason;
  598. skb = alloc_skb(CAPI_DISCONNECT_IND_LEN, GFP_ATOMIC);
  599. if (!skb) {
  600. dev_err(cs->dev, "%s: out of memory\n", __func__);
  601. return;
  602. }
  603. capi_cmsg2message(&iif->hcmsg, __skb_put(skb, CAPI_DISCONNECT_IND_LEN));
  604. dump_cmsg(DEBUG_CMD, __func__, &iif->hcmsg);
  605. ap->connected = APCONN_NONE;
  606. capi_ctr_handle_message(&iif->ctr, ap->id, skb);
  607. }
  608. /*
  609. * send a DISCONNECT_B3_IND message to an application
  610. * Parameters: NCCI = 1, NCPI empty, Reason_B3 = 0
  611. * does not sleep, clobbers the controller's hcmsg structure
  612. */
  613. static void send_disconnect_b3_ind(struct bc_state *bcs,
  614. struct gigaset_capi_appl *ap)
  615. {
  616. struct cardstate *cs = bcs->cs;
  617. struct gigaset_capi_ctr *iif = cs->iif;
  618. struct sk_buff *skb;
  619. /* nothing to do if no logical connection active */
  620. if (ap->connected < APCONN_ACTIVE)
  621. return;
  622. ap->connected = APCONN_SETUP;
  623. capi_cmsg_header(&iif->hcmsg, ap->id, CAPI_DISCONNECT_B3, CAPI_IND,
  624. ap->nextMessageNumber++,
  625. iif->ctr.cnr | ((bcs->channel + 1) << 8) | (1 << 16));
  626. skb = alloc_skb(CAPI_DISCONNECT_B3_IND_BASELEN, GFP_ATOMIC);
  627. if (!skb) {
  628. dev_err(cs->dev, "%s: out of memory\n", __func__);
  629. return;
  630. }
  631. capi_cmsg2message(&iif->hcmsg,
  632. __skb_put(skb, CAPI_DISCONNECT_B3_IND_BASELEN));
  633. dump_cmsg(DEBUG_CMD, __func__, &iif->hcmsg);
  634. capi_ctr_handle_message(&iif->ctr, ap->id, skb);
  635. }
  636. /**
  637. * gigaset_isdn_connD() - signal D channel connect
  638. * @bcs: B channel descriptor structure.
  639. *
  640. * Called by main module at tasklet level to notify the LL that the D channel
  641. * connection has been established.
  642. */
  643. void gigaset_isdn_connD(struct bc_state *bcs)
  644. {
  645. struct cardstate *cs = bcs->cs;
  646. struct gigaset_capi_ctr *iif = cs->iif;
  647. struct gigaset_capi_appl *ap = bcs->ap;
  648. struct sk_buff *skb;
  649. unsigned int msgsize;
  650. if (!ap) {
  651. dev_err(cs->dev, "%s: no application\n", __func__);
  652. return;
  653. }
  654. while (ap->bcnext) {
  655. /* this should never happen */
  656. dev_warn(cs->dev, "%s: dropping extra application %u\n",
  657. __func__, ap->bcnext->id);
  658. send_disconnect_ind(bcs, ap->bcnext,
  659. CapiCallGivenToOtherApplication);
  660. ap->bcnext = ap->bcnext->bcnext;
  661. }
  662. if (ap->connected == APCONN_NONE) {
  663. dev_warn(cs->dev, "%s: application %u not connected\n",
  664. __func__, ap->id);
  665. return;
  666. }
  667. /* prepare CONNECT_ACTIVE_IND message
  668. * Note: LLC not supported by device
  669. */
  670. capi_cmsg_header(&iif->hcmsg, ap->id, CAPI_CONNECT_ACTIVE, CAPI_IND,
  671. ap->nextMessageNumber++,
  672. iif->ctr.cnr | ((bcs->channel + 1) << 8));
  673. /* minimum size, all structs empty */
  674. msgsize = CAPI_CONNECT_ACTIVE_IND_BASELEN;
  675. /* ToDo: set parameter: Connected number
  676. * (requires ev-layer state machine extension to collect
  677. * ZCON device reply)
  678. */
  679. /* build and emit CONNECT_ACTIVE_IND message */
  680. skb = alloc_skb(msgsize, GFP_ATOMIC);
  681. if (!skb) {
  682. dev_err(cs->dev, "%s: out of memory\n", __func__);
  683. return;
  684. }
  685. capi_cmsg2message(&iif->hcmsg, __skb_put(skb, msgsize));
  686. dump_cmsg(DEBUG_CMD, __func__, &iif->hcmsg);
  687. capi_ctr_handle_message(&iif->ctr, ap->id, skb);
  688. }
  689. /**
  690. * gigaset_isdn_hupD() - signal D channel hangup
  691. * @bcs: B channel descriptor structure.
  692. *
  693. * Called by main module at tasklet level to notify the LL that the D channel
  694. * connection has been shut down.
  695. */
  696. void gigaset_isdn_hupD(struct bc_state *bcs)
  697. {
  698. struct gigaset_capi_appl *ap;
  699. /*
  700. * ToDo: pass on reason code reported by device
  701. * (requires ev-layer state machine extension to collect
  702. * ZCAU device reply)
  703. */
  704. for (ap = bcs->ap; ap != NULL; ap = ap->bcnext) {
  705. send_disconnect_b3_ind(bcs, ap);
  706. send_disconnect_ind(bcs, ap, 0);
  707. }
  708. bcs->ap = NULL;
  709. }
  710. /**
  711. * gigaset_isdn_connB() - signal B channel connect
  712. * @bcs: B channel descriptor structure.
  713. *
  714. * Called by main module at tasklet level to notify the LL that the B channel
  715. * connection has been established.
  716. */
  717. void gigaset_isdn_connB(struct bc_state *bcs)
  718. {
  719. struct cardstate *cs = bcs->cs;
  720. struct gigaset_capi_ctr *iif = cs->iif;
  721. struct gigaset_capi_appl *ap = bcs->ap;
  722. struct sk_buff *skb;
  723. unsigned int msgsize;
  724. u8 command;
  725. if (!ap) {
  726. dev_err(cs->dev, "%s: no application\n", __func__);
  727. return;
  728. }
  729. while (ap->bcnext) {
  730. /* this should never happen */
  731. dev_warn(cs->dev, "%s: dropping extra application %u\n",
  732. __func__, ap->bcnext->id);
  733. send_disconnect_ind(bcs, ap->bcnext,
  734. CapiCallGivenToOtherApplication);
  735. ap->bcnext = ap->bcnext->bcnext;
  736. }
  737. if (!ap->connected) {
  738. dev_warn(cs->dev, "%s: application %u not connected\n",
  739. __func__, ap->id);
  740. return;
  741. }
  742. /*
  743. * emit CONNECT_B3_ACTIVE_IND if we already got CONNECT_B3_REQ;
  744. * otherwise we have to emit CONNECT_B3_IND first, and follow up with
  745. * CONNECT_B3_ACTIVE_IND in reply to CONNECT_B3_RESP
  746. * Parameters in both cases always: NCCI = 1, NCPI empty
  747. */
  748. if (ap->connected >= APCONN_ACTIVE) {
  749. command = CAPI_CONNECT_B3_ACTIVE;
  750. msgsize = CAPI_CONNECT_B3_ACTIVE_IND_BASELEN;
  751. } else {
  752. command = CAPI_CONNECT_B3;
  753. msgsize = CAPI_CONNECT_B3_IND_BASELEN;
  754. }
  755. capi_cmsg_header(&iif->hcmsg, ap->id, command, CAPI_IND,
  756. ap->nextMessageNumber++,
  757. iif->ctr.cnr | ((bcs->channel + 1) << 8) | (1 << 16));
  758. skb = alloc_skb(msgsize, GFP_ATOMIC);
  759. if (!skb) {
  760. dev_err(cs->dev, "%s: out of memory\n", __func__);
  761. return;
  762. }
  763. capi_cmsg2message(&iif->hcmsg, __skb_put(skb, msgsize));
  764. dump_cmsg(DEBUG_CMD, __func__, &iif->hcmsg);
  765. ap->connected = APCONN_ACTIVE;
  766. capi_ctr_handle_message(&iif->ctr, ap->id, skb);
  767. }
  768. /**
  769. * gigaset_isdn_hupB() - signal B channel hangup
  770. * @bcs: B channel descriptor structure.
  771. *
  772. * Called by main module to notify the LL that the B channel connection has
  773. * been shut down.
  774. */
  775. void gigaset_isdn_hupB(struct bc_state *bcs)
  776. {
  777. struct cardstate *cs = bcs->cs;
  778. struct gigaset_capi_appl *ap = bcs->ap;
  779. /* ToDo: assure order of DISCONNECT_B3_IND and DISCONNECT_IND ? */
  780. if (!ap) {
  781. dev_err(cs->dev, "%s: no application\n", __func__);
  782. return;
  783. }
  784. send_disconnect_b3_ind(bcs, ap);
  785. }
  786. /**
  787. * gigaset_isdn_start() - signal device availability
  788. * @cs: device descriptor structure.
  789. *
  790. * Called by main module to notify the LL that the device is available for
  791. * use.
  792. */
  793. void gigaset_isdn_start(struct cardstate *cs)
  794. {
  795. struct gigaset_capi_ctr *iif = cs->iif;
  796. /* fill profile data: manufacturer name */
  797. strcpy(iif->ctr.manu, "Siemens");
  798. /* CAPI and device version */
  799. iif->ctr.version.majorversion = 2; /* CAPI 2.0 */
  800. iif->ctr.version.minorversion = 0;
  801. /* ToDo: check/assert cs->gotfwver? */
  802. iif->ctr.version.majormanuversion = cs->fwver[0];
  803. iif->ctr.version.minormanuversion = cs->fwver[1];
  804. /* number of B channels supported */
  805. iif->ctr.profile.nbchannel = cs->channels;
  806. /* global options: internal controller, supplementary services */
  807. iif->ctr.profile.goptions = 0x11;
  808. /* B1 protocols: 64 kbit/s HDLC or transparent */
  809. iif->ctr.profile.support1 = 0x03;
  810. /* B2 protocols: transparent only */
  811. /* ToDo: X.75 SLP ? */
  812. iif->ctr.profile.support2 = 0x02;
  813. /* B3 protocols: transparent only */
  814. iif->ctr.profile.support3 = 0x01;
  815. /* no serial number */
  816. strcpy(iif->ctr.serial, "0");
  817. capi_ctr_ready(&iif->ctr);
  818. }
  819. /**
  820. * gigaset_isdn_stop() - signal device unavailability
  821. * @cs: device descriptor structure.
  822. *
  823. * Called by main module to notify the LL that the device is no longer
  824. * available for use.
  825. */
  826. void gigaset_isdn_stop(struct cardstate *cs)
  827. {
  828. struct gigaset_capi_ctr *iif = cs->iif;
  829. capi_ctr_down(&iif->ctr);
  830. }
  831. /*
  832. * kernel CAPI callback methods
  833. * ============================
  834. */
  835. /*
  836. * register CAPI application
  837. */
  838. static void gigaset_register_appl(struct capi_ctr *ctr, u16 appl,
  839. capi_register_params *rp)
  840. {
  841. struct gigaset_capi_ctr *iif
  842. = container_of(ctr, struct gigaset_capi_ctr, ctr);
  843. struct cardstate *cs = ctr->driverdata;
  844. struct gigaset_capi_appl *ap;
  845. list_for_each_entry(ap, &iif->appls, ctrlist)
  846. if (ap->id == appl) {
  847. dev_notice(cs->dev,
  848. "application %u already registered\n", appl);
  849. return;
  850. }
  851. ap = kzalloc(sizeof(*ap), GFP_KERNEL);
  852. if (!ap) {
  853. dev_err(cs->dev, "%s: out of memory\n", __func__);
  854. return;
  855. }
  856. ap->id = appl;
  857. ap->rp = *rp;
  858. list_add(&ap->ctrlist, &iif->appls);
  859. }
  860. /*
  861. * release CAPI application
  862. */
  863. static void gigaset_release_appl(struct capi_ctr *ctr, u16 appl)
  864. {
  865. struct gigaset_capi_ctr *iif
  866. = container_of(ctr, struct gigaset_capi_ctr, ctr);
  867. struct cardstate *cs = iif->ctr.driverdata;
  868. struct gigaset_capi_appl *ap, *tmp;
  869. list_for_each_entry_safe(ap, tmp, &iif->appls, ctrlist)
  870. if (ap->id == appl) {
  871. if (ap->connected != APCONN_NONE) {
  872. dev_err(cs->dev,
  873. "%s: application %u still connected\n",
  874. __func__, ap->id);
  875. /* ToDo: clear active connection */
  876. }
  877. list_del(&ap->ctrlist);
  878. kfree(ap);
  879. }
  880. }
  881. /*
  882. * =====================================================================
  883. * outgoing CAPI message handler
  884. * =====================================================================
  885. */
  886. /*
  887. * helper function: emit reply message with given Info value
  888. */
  889. static void send_conf(struct gigaset_capi_ctr *iif,
  890. struct gigaset_capi_appl *ap,
  891. struct sk_buff *skb,
  892. u16 info)
  893. {
  894. /*
  895. * _CONF replies always only have NCCI and Info parameters
  896. * so they'll fit into the _REQ message skb
  897. */
  898. capi_cmsg_answer(&iif->acmsg);
  899. iif->acmsg.Info = info;
  900. capi_cmsg2message(&iif->acmsg, skb->data);
  901. __skb_trim(skb, CAPI_STDCONF_LEN);
  902. dump_cmsg(DEBUG_CMD, __func__, &iif->acmsg);
  903. capi_ctr_handle_message(&iif->ctr, ap->id, skb);
  904. }
  905. /*
  906. * process FACILITY_REQ message
  907. */
  908. static void do_facility_req(struct gigaset_capi_ctr *iif,
  909. struct gigaset_capi_appl *ap,
  910. struct sk_buff *skb)
  911. {
  912. struct cardstate *cs = iif->ctr.driverdata;
  913. _cmsg *cmsg = &iif->acmsg;
  914. struct sk_buff *cskb;
  915. u8 *pparam;
  916. unsigned int msgsize = CAPI_FACILITY_CONF_BASELEN;
  917. u16 function, info;
  918. static u8 confparam[10]; /* max. 9 octets + length byte */
  919. /* decode message */
  920. capi_message2cmsg(cmsg, skb->data);
  921. dump_cmsg(DEBUG_CMD, __func__, cmsg);
  922. /*
  923. * Facility Request Parameter is not decoded by capi_message2cmsg()
  924. * encoding depends on Facility Selector
  925. */
  926. switch (cmsg->FacilitySelector) {
  927. case CAPI_FACILITY_DTMF: /* ToDo */
  928. info = CapiFacilityNotSupported;
  929. confparam[0] = 2; /* length */
  930. /* DTMF information: Unknown DTMF request */
  931. capimsg_setu16(confparam, 1, 2);
  932. break;
  933. case CAPI_FACILITY_V42BIS: /* not supported */
  934. info = CapiFacilityNotSupported;
  935. confparam[0] = 2; /* length */
  936. /* V.42 bis information: not available */
  937. capimsg_setu16(confparam, 1, 1);
  938. break;
  939. case CAPI_FACILITY_SUPPSVC:
  940. /* decode Function parameter */
  941. pparam = cmsg->FacilityRequestParameter;
  942. if (pparam == NULL || *pparam < 2) {
  943. dev_notice(cs->dev, "%s: %s missing\n", "FACILITY_REQ",
  944. "Facility Request Parameter");
  945. send_conf(iif, ap, skb, CapiIllMessageParmCoding);
  946. return;
  947. }
  948. function = CAPIMSG_U16(pparam, 1);
  949. switch (function) {
  950. case CAPI_SUPPSVC_GETSUPPORTED:
  951. info = CapiSuccess;
  952. /* Supplementary Service specific parameter */
  953. confparam[3] = 6; /* length */
  954. /* Supplementary services info: Success */
  955. capimsg_setu16(confparam, 4, CapiSuccess);
  956. /* Supported Services: none */
  957. capimsg_setu32(confparam, 6, 0);
  958. break;
  959. /* ToDo: add supported services */
  960. default:
  961. info = CapiFacilitySpecificFunctionNotSupported;
  962. /* Supplementary Service specific parameter */
  963. confparam[3] = 2; /* length */
  964. /* Supplementary services info: not supported */
  965. capimsg_setu16(confparam, 4,
  966. CapiSupplementaryServiceNotSupported);
  967. }
  968. /* Facility confirmation parameter */
  969. confparam[0] = confparam[3] + 3; /* total length */
  970. /* Function: copy from _REQ message */
  971. capimsg_setu16(confparam, 1, function);
  972. /* Supplementary Service specific parameter already set above */
  973. break;
  974. case CAPI_FACILITY_WAKEUP: /* ToDo */
  975. info = CapiFacilityNotSupported;
  976. confparam[0] = 2; /* length */
  977. /* Number of accepted awake request parameters: 0 */
  978. capimsg_setu16(confparam, 1, 0);
  979. break;
  980. default:
  981. info = CapiFacilityNotSupported;
  982. confparam[0] = 0; /* empty struct */
  983. }
  984. /* send FACILITY_CONF with given Info and confirmation parameter */
  985. capi_cmsg_answer(cmsg);
  986. cmsg->Info = info;
  987. cmsg->FacilityConfirmationParameter = confparam;
  988. msgsize += confparam[0]; /* length */
  989. cskb = alloc_skb(msgsize, GFP_ATOMIC);
  990. if (!cskb) {
  991. dev_err(cs->dev, "%s: out of memory\n", __func__);
  992. return;
  993. }
  994. capi_cmsg2message(cmsg, __skb_put(cskb, msgsize));
  995. dump_cmsg(DEBUG_CMD, __func__, cmsg);
  996. capi_ctr_handle_message(&iif->ctr, ap->id, cskb);
  997. }
  998. /*
  999. * process LISTEN_REQ message
  1000. * just store the masks in the application data structure
  1001. */
  1002. static void do_listen_req(struct gigaset_capi_ctr *iif,
  1003. struct gigaset_capi_appl *ap,
  1004. struct sk_buff *skb)
  1005. {
  1006. /* decode message */
  1007. capi_message2cmsg(&iif->acmsg, skb->data);
  1008. dump_cmsg(DEBUG_CMD, __func__, &iif->acmsg);
  1009. /* store listening parameters */
  1010. ap->listenInfoMask = iif->acmsg.InfoMask;
  1011. ap->listenCIPmask = iif->acmsg.CIPmask;
  1012. send_conf(iif, ap, skb, CapiSuccess);
  1013. }
  1014. /*
  1015. * process ALERT_REQ message
  1016. * nothing to do, Gigaset always alerts anyway
  1017. */
  1018. static void do_alert_req(struct gigaset_capi_ctr *iif,
  1019. struct gigaset_capi_appl *ap,
  1020. struct sk_buff *skb)
  1021. {
  1022. /* decode message */
  1023. capi_message2cmsg(&iif->acmsg, skb->data);
  1024. dump_cmsg(DEBUG_CMD, __func__, &iif->acmsg);
  1025. send_conf(iif, ap, skb, CapiAlertAlreadySent);
  1026. }
  1027. /*
  1028. * process CONNECT_REQ message
  1029. * allocate a B channel, prepare dial commands, queue a DIAL event,
  1030. * emit CONNECT_CONF reply
  1031. */
  1032. static void do_connect_req(struct gigaset_capi_ctr *iif,
  1033. struct gigaset_capi_appl *ap,
  1034. struct sk_buff *skb)
  1035. {
  1036. struct cardstate *cs = iif->ctr.driverdata;
  1037. _cmsg *cmsg = &iif->acmsg;
  1038. struct bc_state *bcs;
  1039. char **commands;
  1040. char *s;
  1041. u8 *pp;
  1042. int i, l;
  1043. u16 info;
  1044. /* decode message */
  1045. capi_message2cmsg(cmsg, skb->data);
  1046. dump_cmsg(DEBUG_CMD, __func__, cmsg);
  1047. /* get free B channel & construct PLCI */
  1048. bcs = gigaset_get_free_channel(cs);
  1049. if (!bcs) {
  1050. dev_notice(cs->dev, "%s: no B channel available\n",
  1051. "CONNECT_REQ");
  1052. send_conf(iif, ap, skb, CapiNoPlciAvailable);
  1053. return;
  1054. }
  1055. ap->bcnext = NULL;
  1056. bcs->ap = ap;
  1057. bcs->rx_bufsize = ap->rp.datablklen;
  1058. dev_kfree_skb(bcs->rx_skb);
  1059. gigaset_new_rx_skb(bcs);
  1060. cmsg->adr.adrPLCI |= (bcs->channel + 1) << 8;
  1061. /* build command table */
  1062. commands = kzalloc(AT_NUM*(sizeof *commands), GFP_KERNEL);
  1063. if (!commands)
  1064. goto oom;
  1065. /* encode parameter: Called party number */
  1066. pp = cmsg->CalledPartyNumber;
  1067. if (pp == NULL || *pp == 0) {
  1068. dev_notice(cs->dev, "%s: %s missing\n",
  1069. "CONNECT_REQ", "Called party number");
  1070. info = CapiIllMessageParmCoding;
  1071. goto error;
  1072. }
  1073. l = *pp++;
  1074. /* check type of number/numbering plan byte */
  1075. switch (*pp) {
  1076. case 0x80: /* unknown type / unknown numbering plan */
  1077. case 0x81: /* unknown type / ISDN/Telephony numbering plan */
  1078. break;
  1079. default: /* others: warn about potential misinterpretation */
  1080. dev_notice(cs->dev, "%s: %s type/plan 0x%02x unsupported\n",
  1081. "CONNECT_REQ", "Called party number", *pp);
  1082. }
  1083. pp++;
  1084. l--;
  1085. /* translate "**" internal call prefix to CTP value */
  1086. if (l >= 2 && pp[0] == '*' && pp[1] == '*') {
  1087. s = "^SCTP=0\r";
  1088. pp += 2;
  1089. l -= 2;
  1090. } else {
  1091. s = "^SCTP=1\r";
  1092. }
  1093. commands[AT_TYPE] = kstrdup(s, GFP_KERNEL);
  1094. if (!commands[AT_TYPE])
  1095. goto oom;
  1096. commands[AT_DIAL] = kmalloc(l+3, GFP_KERNEL);
  1097. if (!commands[AT_DIAL])
  1098. goto oom;
  1099. snprintf(commands[AT_DIAL], l+3, "D%.*s\r", l, pp);
  1100. /* encode parameter: Calling party number */
  1101. pp = cmsg->CallingPartyNumber;
  1102. if (pp != NULL && *pp > 0) {
  1103. l = *pp++;
  1104. /* check type of number/numbering plan byte */
  1105. /* ToDo: allow for/handle Ext=1? */
  1106. switch (*pp) {
  1107. case 0x00: /* unknown type / unknown numbering plan */
  1108. case 0x01: /* unknown type / ISDN/Telephony num. plan */
  1109. break;
  1110. default:
  1111. dev_notice(cs->dev,
  1112. "%s: %s type/plan 0x%02x unsupported\n",
  1113. "CONNECT_REQ", "Calling party number", *pp);
  1114. }
  1115. pp++;
  1116. l--;
  1117. /* check presentation indicator */
  1118. if (!l) {
  1119. dev_notice(cs->dev, "%s: %s IE truncated\n",
  1120. "CONNECT_REQ", "Calling party number");
  1121. info = CapiIllMessageParmCoding;
  1122. goto error;
  1123. }
  1124. switch (*pp & 0xfc) { /* ignore Screening indicator */
  1125. case 0x80: /* Presentation allowed */
  1126. s = "^SCLIP=1\r";
  1127. break;
  1128. case 0xa0: /* Presentation restricted */
  1129. s = "^SCLIP=0\r";
  1130. break;
  1131. default:
  1132. dev_notice(cs->dev, "%s: invalid %s 0x%02x\n",
  1133. "CONNECT_REQ",
  1134. "Presentation/Screening indicator",
  1135. *pp);
  1136. s = "^SCLIP=1\r";
  1137. }
  1138. commands[AT_CLIP] = kstrdup(s, GFP_KERNEL);
  1139. if (!commands[AT_CLIP])
  1140. goto oom;
  1141. pp++;
  1142. l--;
  1143. if (l) {
  1144. /* number */
  1145. commands[AT_MSN] = kmalloc(l+8, GFP_KERNEL);
  1146. if (!commands[AT_MSN])
  1147. goto oom;
  1148. snprintf(commands[AT_MSN], l+8, "^SMSN=%*s\r", l, pp);
  1149. }
  1150. }
  1151. /* check parameter: CIP Value */
  1152. if (cmsg->CIPValue >= ARRAY_SIZE(cip2bchlc) ||
  1153. (cmsg->CIPValue > 0 && cip2bchlc[cmsg->CIPValue].bc == NULL)) {
  1154. dev_notice(cs->dev, "%s: unknown CIP value %d\n",
  1155. "CONNECT_REQ", cmsg->CIPValue);
  1156. info = CapiCipValueUnknown;
  1157. goto error;
  1158. }
  1159. /* check/encode parameter: BC */
  1160. if (cmsg->BC && cmsg->BC[0]) {
  1161. /* explicit BC overrides CIP */
  1162. l = 2*cmsg->BC[0] + 7;
  1163. commands[AT_BC] = kmalloc(l, GFP_KERNEL);
  1164. if (!commands[AT_BC])
  1165. goto oom;
  1166. strcpy(commands[AT_BC], "^SBC=");
  1167. decode_ie(cmsg->BC, commands[AT_BC]+5);
  1168. strcpy(commands[AT_BC] + l - 2, "\r");
  1169. } else if (cip2bchlc[cmsg->CIPValue].bc) {
  1170. l = strlen(cip2bchlc[cmsg->CIPValue].bc) + 7;
  1171. commands[AT_BC] = kmalloc(l, GFP_KERNEL);
  1172. if (!commands[AT_BC])
  1173. goto oom;
  1174. snprintf(commands[AT_BC], l, "^SBC=%s\r",
  1175. cip2bchlc[cmsg->CIPValue].bc);
  1176. }
  1177. /* check/encode parameter: HLC */
  1178. if (cmsg->HLC && cmsg->HLC[0]) {
  1179. /* explicit HLC overrides CIP */
  1180. l = 2*cmsg->HLC[0] + 7;
  1181. commands[AT_HLC] = kmalloc(l, GFP_KERNEL);
  1182. if (!commands[AT_HLC])
  1183. goto oom;
  1184. strcpy(commands[AT_HLC], "^SHLC=");
  1185. decode_ie(cmsg->HLC, commands[AT_HLC]+5);
  1186. strcpy(commands[AT_HLC] + l - 2, "\r");
  1187. } else if (cip2bchlc[cmsg->CIPValue].hlc) {
  1188. l = strlen(cip2bchlc[cmsg->CIPValue].hlc) + 7;
  1189. commands[AT_HLC] = kmalloc(l, GFP_KERNEL);
  1190. if (!commands[AT_HLC])
  1191. goto oom;
  1192. snprintf(commands[AT_HLC], l, "^SHLC=%s\r",
  1193. cip2bchlc[cmsg->CIPValue].hlc);
  1194. }
  1195. /* check/encode parameter: B Protocol */
  1196. if (cmsg->BProtocol == CAPI_DEFAULT) {
  1197. bcs->proto2 = L2_HDLC;
  1198. dev_warn(cs->dev,
  1199. "B2 Protocol X.75 SLP unsupported, using Transparent\n");
  1200. } else {
  1201. switch (cmsg->B1protocol) {
  1202. case 0:
  1203. bcs->proto2 = L2_HDLC;
  1204. break;
  1205. case 1:
  1206. bcs->proto2 = L2_VOICE;
  1207. break;
  1208. default:
  1209. dev_warn(cs->dev,
  1210. "B1 Protocol %u unsupported, using Transparent\n",
  1211. cmsg->B1protocol);
  1212. bcs->proto2 = L2_VOICE;
  1213. }
  1214. if (cmsg->B2protocol != 1)
  1215. dev_warn(cs->dev,
  1216. "B2 Protocol %u unsupported, using Transparent\n",
  1217. cmsg->B2protocol);
  1218. if (cmsg->B3protocol != 0)
  1219. dev_warn(cs->dev,
  1220. "B3 Protocol %u unsupported, using Transparent\n",
  1221. cmsg->B3protocol);
  1222. ignore_cstruct_param(cs, cmsg->B1configuration,
  1223. "CONNECT_REQ", "B1 Configuration");
  1224. ignore_cstruct_param(cs, cmsg->B2configuration,
  1225. "CONNECT_REQ", "B2 Configuration");
  1226. ignore_cstruct_param(cs, cmsg->B3configuration,
  1227. "CONNECT_REQ", "B3 Configuration");
  1228. }
  1229. commands[AT_PROTO] = kmalloc(9, GFP_KERNEL);
  1230. if (!commands[AT_PROTO])
  1231. goto oom;
  1232. snprintf(commands[AT_PROTO], 9, "^SBPR=%u\r", bcs->proto2);
  1233. /* ToDo: check/encode remaining parameters */
  1234. ignore_cstruct_param(cs, cmsg->CalledPartySubaddress,
  1235. "CONNECT_REQ", "Called pty subaddr");
  1236. ignore_cstruct_param(cs, cmsg->CallingPartySubaddress,
  1237. "CONNECT_REQ", "Calling pty subaddr");
  1238. ignore_cstruct_param(cs, cmsg->LLC,
  1239. "CONNECT_REQ", "LLC");
  1240. if (cmsg->AdditionalInfo != CAPI_DEFAULT) {
  1241. ignore_cstruct_param(cs, cmsg->BChannelinformation,
  1242. "CONNECT_REQ", "B Channel Information");
  1243. ignore_cstruct_param(cs, cmsg->Keypadfacility,
  1244. "CONNECT_REQ", "Keypad Facility");
  1245. ignore_cstruct_param(cs, cmsg->Useruserdata,
  1246. "CONNECT_REQ", "User-User Data");
  1247. ignore_cstruct_param(cs, cmsg->Facilitydataarray,
  1248. "CONNECT_REQ", "Facility Data Array");
  1249. }
  1250. /* encode parameter: B channel to use */
  1251. commands[AT_ISO] = kmalloc(9, GFP_KERNEL);
  1252. if (!commands[AT_ISO])
  1253. goto oom;
  1254. snprintf(commands[AT_ISO], 9, "^SISO=%u\r",
  1255. (unsigned) bcs->channel + 1);
  1256. /* queue & schedule EV_DIAL event */
  1257. if (!gigaset_add_event(cs, &bcs->at_state, EV_DIAL, commands,
  1258. bcs->at_state.seq_index, NULL)) {
  1259. info = CAPI_MSGOSRESOURCEERR;
  1260. goto error;
  1261. }
  1262. gigaset_schedule_event(cs);
  1263. ap->connected = APCONN_SETUP;
  1264. send_conf(iif, ap, skb, CapiSuccess);
  1265. return;
  1266. oom:
  1267. dev_err(cs->dev, "%s: out of memory\n", __func__);
  1268. info = CAPI_MSGOSRESOURCEERR;
  1269. error:
  1270. if (commands)
  1271. for (i = 0; i < AT_NUM; i++)
  1272. kfree(commands[i]);
  1273. kfree(commands);
  1274. gigaset_free_channel(bcs);
  1275. send_conf(iif, ap, skb, info);
  1276. }
  1277. /*
  1278. * process CONNECT_RESP message
  1279. * checks protocol parameters and queues an ACCEPT or HUP event
  1280. */
  1281. static void do_connect_resp(struct gigaset_capi_ctr *iif,
  1282. struct gigaset_capi_appl *ap,
  1283. struct sk_buff *skb)
  1284. {
  1285. struct cardstate *cs = iif->ctr.driverdata;
  1286. _cmsg *cmsg = &iif->acmsg;
  1287. struct bc_state *bcs;
  1288. struct gigaset_capi_appl *oap;
  1289. int channel;
  1290. /* decode message */
  1291. capi_message2cmsg(cmsg, skb->data);
  1292. dump_cmsg(DEBUG_CMD, __func__, cmsg);
  1293. dev_kfree_skb_any(skb);
  1294. /* extract and check channel number from PLCI */
  1295. channel = (cmsg->adr.adrPLCI >> 8) & 0xff;
  1296. if (!channel || channel > cs->channels) {
  1297. dev_notice(cs->dev, "%s: invalid %s 0x%02x\n",
  1298. "CONNECT_RESP", "PLCI", cmsg->adr.adrPLCI);
  1299. return;
  1300. }
  1301. bcs = cs->bcs + channel - 1;
  1302. switch (cmsg->Reject) {
  1303. case 0: /* Accept */
  1304. /* drop all competing applications, keep only this one */
  1305. for (oap = bcs->ap; oap != NULL; oap = oap->bcnext)
  1306. if (oap != ap)
  1307. send_disconnect_ind(bcs, oap,
  1308. CapiCallGivenToOtherApplication);
  1309. ap->bcnext = NULL;
  1310. bcs->ap = ap;
  1311. bcs->rx_bufsize = ap->rp.datablklen;
  1312. dev_kfree_skb(bcs->rx_skb);
  1313. gigaset_new_rx_skb(bcs);
  1314. bcs->chstate |= CHS_NOTIFY_LL;
  1315. /* check/encode B channel protocol */
  1316. if (cmsg->BProtocol == CAPI_DEFAULT) {
  1317. bcs->proto2 = L2_HDLC;
  1318. dev_warn(cs->dev,
  1319. "B2 Protocol X.75 SLP unsupported, using Transparent\n");
  1320. } else {
  1321. switch (cmsg->B1protocol) {
  1322. case 0:
  1323. bcs->proto2 = L2_HDLC;
  1324. break;
  1325. case 1:
  1326. bcs->proto2 = L2_VOICE;
  1327. break;
  1328. default:
  1329. dev_warn(cs->dev,
  1330. "B1 Protocol %u unsupported, using Transparent\n",
  1331. cmsg->B1protocol);
  1332. bcs->proto2 = L2_VOICE;
  1333. }
  1334. if (cmsg->B2protocol != 1)
  1335. dev_warn(cs->dev,
  1336. "B2 Protocol %u unsupported, using Transparent\n",
  1337. cmsg->B2protocol);
  1338. if (cmsg->B3protocol != 0)
  1339. dev_warn(cs->dev,
  1340. "B3 Protocol %u unsupported, using Transparent\n",
  1341. cmsg->B3protocol);
  1342. ignore_cstruct_param(cs, cmsg->B1configuration,
  1343. "CONNECT_RESP", "B1 Configuration");
  1344. ignore_cstruct_param(cs, cmsg->B2configuration,
  1345. "CONNECT_RESP", "B2 Configuration");
  1346. ignore_cstruct_param(cs, cmsg->B3configuration,
  1347. "CONNECT_RESP", "B3 Configuration");
  1348. }
  1349. /* ToDo: check/encode remaining parameters */
  1350. ignore_cstruct_param(cs, cmsg->ConnectedNumber,
  1351. "CONNECT_RESP", "Connected Number");
  1352. ignore_cstruct_param(cs, cmsg->ConnectedSubaddress,
  1353. "CONNECT_RESP", "Connected Subaddress");
  1354. ignore_cstruct_param(cs, cmsg->LLC,
  1355. "CONNECT_RESP", "LLC");
  1356. if (cmsg->AdditionalInfo != CAPI_DEFAULT) {
  1357. ignore_cstruct_param(cs, cmsg->BChannelinformation,
  1358. "CONNECT_RESP", "BChannel Information");
  1359. ignore_cstruct_param(cs, cmsg->Keypadfacility,
  1360. "CONNECT_RESP", "Keypad Facility");
  1361. ignore_cstruct_param(cs, cmsg->Useruserdata,
  1362. "CONNECT_RESP", "User-User Data");
  1363. ignore_cstruct_param(cs, cmsg->Facilitydataarray,
  1364. "CONNECT_RESP", "Facility Data Array");
  1365. }
  1366. /* Accept call */
  1367. if (!gigaset_add_event(cs, &cs->bcs[channel-1].at_state,
  1368. EV_ACCEPT, NULL, 0, NULL))
  1369. return;
  1370. gigaset_schedule_event(cs);
  1371. return;
  1372. case 1: /* Ignore */
  1373. /* send DISCONNECT_IND to this application */
  1374. send_disconnect_ind(bcs, ap, 0);
  1375. /* remove it from the list of listening apps */
  1376. if (bcs->ap == ap) {
  1377. bcs->ap = ap->bcnext;
  1378. if (bcs->ap == NULL)
  1379. /* last one: stop ev-layer hupD notifications */
  1380. bcs->chstate &= ~CHS_NOTIFY_LL;
  1381. return;
  1382. }
  1383. for (oap = bcs->ap; oap != NULL; oap = oap->bcnext) {
  1384. if (oap->bcnext == ap) {
  1385. oap->bcnext = oap->bcnext->bcnext;
  1386. return;
  1387. }
  1388. }
  1389. dev_err(cs->dev, "%s: application %u not found\n",
  1390. __func__, ap->id);
  1391. return;
  1392. default: /* Reject */
  1393. /* drop all competing applications, keep only this one */
  1394. for (oap = bcs->ap; oap != NULL; oap = oap->bcnext)
  1395. if (oap != ap)
  1396. send_disconnect_ind(bcs, oap,
  1397. CapiCallGivenToOtherApplication);
  1398. ap->bcnext = NULL;
  1399. bcs->ap = ap;
  1400. /* reject call - will trigger DISCONNECT_IND for this app */
  1401. dev_info(cs->dev, "%s: Reject=%x\n",
  1402. "CONNECT_RESP", cmsg->Reject);
  1403. if (!gigaset_add_event(cs, &cs->bcs[channel-1].at_state,
  1404. EV_HUP, NULL, 0, NULL))
  1405. return;
  1406. gigaset_schedule_event(cs);
  1407. return;
  1408. }
  1409. }
  1410. /*
  1411. * process CONNECT_B3_REQ message
  1412. * build NCCI and emit CONNECT_B3_CONF reply
  1413. */
  1414. static void do_connect_b3_req(struct gigaset_capi_ctr *iif,
  1415. struct gigaset_capi_appl *ap,
  1416. struct sk_buff *skb)
  1417. {
  1418. struct cardstate *cs = iif->ctr.driverdata;
  1419. _cmsg *cmsg = &iif->acmsg;
  1420. int channel;
  1421. /* decode message */
  1422. capi_message2cmsg(cmsg, skb->data);
  1423. dump_cmsg(DEBUG_CMD, __func__, cmsg);
  1424. /* extract and check channel number from PLCI */
  1425. channel = (cmsg->adr.adrPLCI >> 8) & 0xff;
  1426. if (!channel || channel > cs->channels) {
  1427. dev_notice(cs->dev, "%s: invalid %s 0x%02x\n",
  1428. "CONNECT_B3_REQ", "PLCI", cmsg->adr.adrPLCI);
  1429. send_conf(iif, ap, skb, CapiIllContrPlciNcci);
  1430. return;
  1431. }
  1432. /* mark logical connection active */
  1433. ap->connected = APCONN_ACTIVE;
  1434. /* build NCCI: always 1 (one B3 connection only) */
  1435. cmsg->adr.adrNCCI |= 1 << 16;
  1436. /* NCPI parameter: not applicable for B3 Transparent */
  1437. ignore_cstruct_param(cs, cmsg->NCPI, "CONNECT_B3_REQ", "NCPI");
  1438. send_conf(iif, ap, skb, (cmsg->NCPI && cmsg->NCPI[0]) ?
  1439. CapiNcpiNotSupportedByProtocol : CapiSuccess);
  1440. }
  1441. /*
  1442. * process CONNECT_B3_RESP message
  1443. * Depending on the Reject parameter, either emit CONNECT_B3_ACTIVE_IND
  1444. * or queue EV_HUP and emit DISCONNECT_B3_IND.
  1445. * The emitted message is always shorter than the received one,
  1446. * allowing to reuse the skb.
  1447. */
  1448. static void do_connect_b3_resp(struct gigaset_capi_ctr *iif,
  1449. struct gigaset_capi_appl *ap,
  1450. struct sk_buff *skb)
  1451. {
  1452. struct cardstate *cs = iif->ctr.driverdata;
  1453. _cmsg *cmsg = &iif->acmsg;
  1454. struct bc_state *bcs;
  1455. int channel;
  1456. unsigned int msgsize;
  1457. u8 command;
  1458. /* decode message */
  1459. capi_message2cmsg(cmsg, skb->data);
  1460. dump_cmsg(DEBUG_CMD, __func__, cmsg);
  1461. /* extract and check channel number and NCCI */
  1462. channel = (cmsg->adr.adrNCCI >> 8) & 0xff;
  1463. if (!channel || channel > cs->channels ||
  1464. ((cmsg->adr.adrNCCI >> 16) & 0xffff) != 1) {
  1465. dev_notice(cs->dev, "%s: invalid %s 0x%02x\n",
  1466. "CONNECT_B3_RESP", "NCCI", cmsg->adr.adrNCCI);
  1467. dev_kfree_skb_any(skb);
  1468. return;
  1469. }
  1470. bcs = &cs->bcs[channel-1];
  1471. if (cmsg->Reject) {
  1472. /* Reject: clear B3 connect received flag */
  1473. ap->connected = APCONN_SETUP;
  1474. /* trigger hangup, causing eventual DISCONNECT_IND */
  1475. if (!gigaset_add_event(cs, &bcs->at_state,
  1476. EV_HUP, NULL, 0, NULL)) {
  1477. dev_kfree_skb_any(skb);
  1478. return;
  1479. }
  1480. gigaset_schedule_event(cs);
  1481. /* emit DISCONNECT_B3_IND */
  1482. command = CAPI_DISCONNECT_B3;
  1483. msgsize = CAPI_DISCONNECT_B3_IND_BASELEN;
  1484. } else {
  1485. /*
  1486. * Accept: emit CONNECT_B3_ACTIVE_IND immediately, as
  1487. * we only send CONNECT_B3_IND if the B channel is up
  1488. */
  1489. command = CAPI_CONNECT_B3_ACTIVE;
  1490. msgsize = CAPI_CONNECT_B3_ACTIVE_IND_BASELEN;
  1491. }
  1492. capi_cmsg_header(cmsg, ap->id, command, CAPI_IND,
  1493. ap->nextMessageNumber++, cmsg->adr.adrNCCI);
  1494. __skb_trim(skb, msgsize);
  1495. capi_cmsg2message(cmsg, skb->data);
  1496. dump_cmsg(DEBUG_CMD, __func__, cmsg);
  1497. capi_ctr_handle_message(&iif->ctr, ap->id, skb);
  1498. }
  1499. /*
  1500. * process DISCONNECT_REQ message
  1501. * schedule EV_HUP and emit DISCONNECT_B3_IND if necessary,
  1502. * emit DISCONNECT_CONF reply
  1503. */
  1504. static void do_disconnect_req(struct gigaset_capi_ctr *iif,
  1505. struct gigaset_capi_appl *ap,
  1506. struct sk_buff *skb)
  1507. {
  1508. struct cardstate *cs = iif->ctr.driverdata;
  1509. _cmsg *cmsg = &iif->acmsg;
  1510. struct bc_state *bcs;
  1511. _cmsg *b3cmsg;
  1512. struct sk_buff *b3skb;
  1513. int channel;
  1514. /* decode message */
  1515. capi_message2cmsg(cmsg, skb->data);
  1516. dump_cmsg(DEBUG_CMD, __func__, cmsg);
  1517. /* extract and check channel number from PLCI */
  1518. channel = (cmsg->adr.adrPLCI >> 8) & 0xff;
  1519. if (!channel || channel > cs->channels) {
  1520. dev_notice(cs->dev, "%s: invalid %s 0x%02x\n",
  1521. "DISCONNECT_REQ", "PLCI", cmsg->adr.adrPLCI);
  1522. send_conf(iif, ap, skb, CapiIllContrPlciNcci);
  1523. return;
  1524. }
  1525. bcs = cs->bcs + channel - 1;
  1526. /* ToDo: process parameter: Additional info */
  1527. if (cmsg->AdditionalInfo != CAPI_DEFAULT) {
  1528. ignore_cstruct_param(cs, cmsg->BChannelinformation,
  1529. "DISCONNECT_REQ", "B Channel Information");
  1530. ignore_cstruct_param(cs, cmsg->Keypadfacility,
  1531. "DISCONNECT_REQ", "Keypad Facility");
  1532. ignore_cstruct_param(cs, cmsg->Useruserdata,
  1533. "DISCONNECT_REQ", "User-User Data");
  1534. ignore_cstruct_param(cs, cmsg->Facilitydataarray,
  1535. "DISCONNECT_REQ", "Facility Data Array");
  1536. }
  1537. /* skip if DISCONNECT_IND already sent */
  1538. if (!ap->connected)
  1539. return;
  1540. /* check for active logical connection */
  1541. if (ap->connected >= APCONN_ACTIVE) {
  1542. /*
  1543. * emit DISCONNECT_B3_IND with cause 0x3301
  1544. * use separate cmsg structure, as the content of iif->acmsg
  1545. * is still needed for creating the _CONF message
  1546. */
  1547. b3cmsg = kmalloc(sizeof(*b3cmsg), GFP_KERNEL);
  1548. if (!b3cmsg) {
  1549. dev_err(cs->dev, "%s: out of memory\n", __func__);
  1550. send_conf(iif, ap, skb, CAPI_MSGOSRESOURCEERR);
  1551. return;
  1552. }
  1553. capi_cmsg_header(b3cmsg, ap->id, CAPI_DISCONNECT_B3, CAPI_IND,
  1554. ap->nextMessageNumber++,
  1555. cmsg->adr.adrPLCI | (1 << 16));
  1556. b3cmsg->Reason_B3 = CapiProtocolErrorLayer1;
  1557. b3skb = alloc_skb(CAPI_DISCONNECT_B3_IND_BASELEN, GFP_KERNEL);
  1558. if (b3skb == NULL) {
  1559. dev_err(cs->dev, "%s: out of memory\n", __func__);
  1560. send_conf(iif, ap, skb, CAPI_MSGOSRESOURCEERR);
  1561. return;
  1562. }
  1563. capi_cmsg2message(b3cmsg,
  1564. __skb_put(b3skb, CAPI_DISCONNECT_B3_IND_BASELEN));
  1565. kfree(b3cmsg);
  1566. capi_ctr_handle_message(&iif->ctr, ap->id, b3skb);
  1567. }
  1568. /* trigger hangup, causing eventual DISCONNECT_IND */
  1569. if (!gigaset_add_event(cs, &bcs->at_state, EV_HUP, NULL, 0, NULL)) {
  1570. send_conf(iif, ap, skb, CAPI_MSGOSRESOURCEERR);
  1571. return;
  1572. }
  1573. gigaset_schedule_event(cs);
  1574. /* emit reply */
  1575. send_conf(iif, ap, skb, CapiSuccess);
  1576. }
  1577. /*
  1578. * process DISCONNECT_B3_REQ message
  1579. * schedule EV_HUP and emit DISCONNECT_B3_CONF reply
  1580. */
  1581. static void do_disconnect_b3_req(struct gigaset_capi_ctr *iif,
  1582. struct gigaset_capi_appl *ap,
  1583. struct sk_buff *skb)
  1584. {
  1585. struct cardstate *cs = iif->ctr.driverdata;
  1586. _cmsg *cmsg = &iif->acmsg;
  1587. int channel;
  1588. /* decode message */
  1589. capi_message2cmsg(cmsg, skb->data);
  1590. dump_cmsg(DEBUG_CMD, __func__, cmsg);
  1591. /* extract and check channel number and NCCI */
  1592. channel = (cmsg->adr.adrNCCI >> 8) & 0xff;
  1593. if (!channel || channel > cs->channels ||
  1594. ((cmsg->adr.adrNCCI >> 16) & 0xffff) != 1) {
  1595. dev_notice(cs->dev, "%s: invalid %s 0x%02x\n",
  1596. "DISCONNECT_B3_REQ", "NCCI", cmsg->adr.adrNCCI);
  1597. send_conf(iif, ap, skb, CapiIllContrPlciNcci);
  1598. return;
  1599. }
  1600. /* reject if logical connection not active */
  1601. if (ap->connected < APCONN_ACTIVE) {
  1602. send_conf(iif, ap, skb,
  1603. CapiMessageNotSupportedInCurrentState);
  1604. return;
  1605. }
  1606. /* trigger hangup, causing eventual DISCONNECT_B3_IND */
  1607. if (!gigaset_add_event(cs, &cs->bcs[channel-1].at_state,
  1608. EV_HUP, NULL, 0, NULL)) {
  1609. send_conf(iif, ap, skb, CAPI_MSGOSRESOURCEERR);
  1610. return;
  1611. }
  1612. gigaset_schedule_event(cs);
  1613. /* NCPI parameter: not applicable for B3 Transparent */
  1614. ignore_cstruct_param(cs, cmsg->NCPI,
  1615. "DISCONNECT_B3_REQ", "NCPI");
  1616. send_conf(iif, ap, skb, (cmsg->NCPI && cmsg->NCPI[0]) ?
  1617. CapiNcpiNotSupportedByProtocol : CapiSuccess);
  1618. }
  1619. /*
  1620. * process DATA_B3_REQ message
  1621. */
  1622. static void do_data_b3_req(struct gigaset_capi_ctr *iif,
  1623. struct gigaset_capi_appl *ap,
  1624. struct sk_buff *skb)
  1625. {
  1626. struct cardstate *cs = iif->ctr.driverdata;
  1627. int channel = CAPIMSG_PLCI_PART(skb->data);
  1628. u16 ncci = CAPIMSG_NCCI_PART(skb->data);
  1629. u16 msglen = CAPIMSG_LEN(skb->data);
  1630. u16 datalen = CAPIMSG_DATALEN(skb->data);
  1631. u16 flags = CAPIMSG_FLAGS(skb->data);
  1632. /* frequent message, avoid _cmsg overhead */
  1633. dump_rawmsg(DEBUG_LLDATA, "DATA_B3_REQ", skb->data);
  1634. gig_dbg(DEBUG_LLDATA,
  1635. "Receiving data from LL (ch: %d, flg: %x, sz: %d|%d)",
  1636. channel, flags, msglen, datalen);
  1637. /* check parameters */
  1638. if (channel == 0 || channel > cs->channels || ncci != 1) {
  1639. dev_notice(cs->dev, "%s: invalid %s 0x%02x\n",
  1640. "DATA_B3_REQ", "NCCI", CAPIMSG_NCCI(skb->data));
  1641. send_conf(iif, ap, skb, CapiIllContrPlciNcci);
  1642. return;
  1643. }
  1644. if (msglen != CAPI_DATA_B3_REQ_LEN && msglen != CAPI_DATA_B3_REQ_LEN64)
  1645. dev_notice(cs->dev, "%s: unexpected length %d\n",
  1646. "DATA_B3_REQ", msglen);
  1647. if (msglen + datalen != skb->len)
  1648. dev_notice(cs->dev, "%s: length mismatch (%d+%d!=%d)\n",
  1649. "DATA_B3_REQ", msglen, datalen, skb->len);
  1650. if (msglen + datalen > skb->len) {
  1651. /* message too short for announced data length */
  1652. send_conf(iif, ap, skb, CapiIllMessageParmCoding); /* ? */
  1653. return;
  1654. }
  1655. if (flags & CAPI_FLAGS_RESERVED) {
  1656. dev_notice(cs->dev, "%s: reserved flags set (%x)\n",
  1657. "DATA_B3_REQ", flags);
  1658. send_conf(iif, ap, skb, CapiIllMessageParmCoding);
  1659. return;
  1660. }
  1661. /* reject if logical connection not active */
  1662. if (ap->connected < APCONN_ACTIVE) {
  1663. send_conf(iif, ap, skb, CapiMessageNotSupportedInCurrentState);
  1664. return;
  1665. }
  1666. /* pull CAPI message into link layer header */
  1667. skb_reset_mac_header(skb);
  1668. skb->mac_len = msglen;
  1669. skb_pull(skb, msglen);
  1670. /* pass to device-specific module */
  1671. if (cs->ops->send_skb(&cs->bcs[channel-1], skb) < 0) {
  1672. send_conf(iif, ap, skb, CAPI_MSGOSRESOURCEERR);
  1673. return;
  1674. }
  1675. /* DATA_B3_CONF reply will be sent by gigaset_skb_sent() */
  1676. /*
  1677. * ToDo: honor unset "delivery confirmation" bit
  1678. * (send DATA_B3_CONF immediately?)
  1679. */
  1680. }
  1681. /*
  1682. * process RESET_B3_REQ message
  1683. * just always reply "not supported by current protocol"
  1684. */
  1685. static void do_reset_b3_req(struct gigaset_capi_ctr *iif,
  1686. struct gigaset_capi_appl *ap,
  1687. struct sk_buff *skb)
  1688. {
  1689. /* decode message */
  1690. capi_message2cmsg(&iif->acmsg, skb->data);
  1691. dump_cmsg(DEBUG_CMD, __func__, &iif->acmsg);
  1692. send_conf(iif, ap, skb,
  1693. CapiResetProcedureNotSupportedByCurrentProtocol);
  1694. }
  1695. /*
  1696. * dump unsupported/ignored messages at most twice per minute,
  1697. * some apps send those very frequently
  1698. */
  1699. static unsigned long ignored_msg_dump_time;
  1700. /*
  1701. * unsupported CAPI message handler
  1702. */
  1703. static void do_unsupported(struct gigaset_capi_ctr *iif,
  1704. struct gigaset_capi_appl *ap,
  1705. struct sk_buff *skb)
  1706. {
  1707. /* decode message */
  1708. capi_message2cmsg(&iif->acmsg, skb->data);
  1709. if (printk_timed_ratelimit(&ignored_msg_dump_time, 30 * 1000))
  1710. dump_cmsg(DEBUG_CMD, __func__, &iif->acmsg);
  1711. send_conf(iif, ap, skb, CapiMessageNotSupportedInCurrentState);
  1712. }
  1713. /*
  1714. * CAPI message handler: no-op
  1715. */
  1716. static void do_nothing(struct gigaset_capi_ctr *iif,
  1717. struct gigaset_capi_appl *ap,
  1718. struct sk_buff *skb)
  1719. {
  1720. if (printk_timed_ratelimit(&ignored_msg_dump_time, 30 * 1000)) {
  1721. /* decode message */
  1722. capi_message2cmsg(&iif->acmsg, skb->data);
  1723. dump_cmsg(DEBUG_CMD, __func__, &iif->acmsg);
  1724. }
  1725. dev_kfree_skb_any(skb);
  1726. }
  1727. static void do_data_b3_resp(struct gigaset_capi_ctr *iif,
  1728. struct gigaset_capi_appl *ap,
  1729. struct sk_buff *skb)
  1730. {
  1731. dump_rawmsg(DEBUG_LLDATA, __func__, skb->data);
  1732. dev_kfree_skb_any(skb);
  1733. }
  1734. /* table of outgoing CAPI message handlers with lookup function */
  1735. typedef void (*capi_send_handler_t)(struct gigaset_capi_ctr *,
  1736. struct gigaset_capi_appl *,
  1737. struct sk_buff *);
  1738. static struct {
  1739. u16 cmd;
  1740. capi_send_handler_t handler;
  1741. } capi_send_handler_table[] = {
  1742. /* most frequent messages first for faster lookup */
  1743. { CAPI_DATA_B3_REQ, do_data_b3_req },
  1744. { CAPI_DATA_B3_RESP, do_data_b3_resp },
  1745. { CAPI_ALERT_REQ, do_alert_req },
  1746. { CAPI_CONNECT_ACTIVE_RESP, do_nothing },
  1747. { CAPI_CONNECT_B3_ACTIVE_RESP, do_nothing },
  1748. { CAPI_CONNECT_B3_REQ, do_connect_b3_req },
  1749. { CAPI_CONNECT_B3_RESP, do_connect_b3_resp },
  1750. { CAPI_CONNECT_B3_T90_ACTIVE_RESP, do_nothing },
  1751. { CAPI_CONNECT_REQ, do_connect_req },
  1752. { CAPI_CONNECT_RESP, do_connect_resp },
  1753. { CAPI_DISCONNECT_B3_REQ, do_disconnect_b3_req },
  1754. { CAPI_DISCONNECT_B3_RESP, do_nothing },
  1755. { CAPI_DISCONNECT_REQ, do_disconnect_req },
  1756. { CAPI_DISCONNECT_RESP, do_nothing },
  1757. { CAPI_FACILITY_REQ, do_facility_req },
  1758. { CAPI_FACILITY_RESP, do_nothing },
  1759. { CAPI_LISTEN_REQ, do_listen_req },
  1760. { CAPI_SELECT_B_PROTOCOL_REQ, do_unsupported },
  1761. { CAPI_RESET_B3_REQ, do_reset_b3_req },
  1762. { CAPI_RESET_B3_RESP, do_nothing },
  1763. /*
  1764. * ToDo: support overlap sending (requires ev-layer state
  1765. * machine extension to generate additional ATD commands)
  1766. */
  1767. { CAPI_INFO_REQ, do_unsupported },
  1768. { CAPI_INFO_RESP, do_nothing },
  1769. /*
  1770. * ToDo: what's the proper response for these?
  1771. */
  1772. { CAPI_MANUFACTURER_REQ, do_nothing },
  1773. { CAPI_MANUFACTURER_RESP, do_nothing },
  1774. };
  1775. /* look up handler */
  1776. static inline capi_send_handler_t lookup_capi_send_handler(const u16 cmd)
  1777. {
  1778. size_t i;
  1779. for (i = 0; i < ARRAY_SIZE(capi_send_handler_table); i++)
  1780. if (capi_send_handler_table[i].cmd == cmd)
  1781. return capi_send_handler_table[i].handler;
  1782. return NULL;
  1783. }
  1784. /**
  1785. * gigaset_send_message() - accept a CAPI message from an application
  1786. * @ctr: controller descriptor structure.
  1787. * @skb: CAPI message.
  1788. *
  1789. * Return value: CAPI error code
  1790. * Note: capidrv (and probably others, too) only uses the return value to
  1791. * decide whether it has to free the skb (only if result != CAPI_NOERROR (0))
  1792. */
  1793. static u16 gigaset_send_message(struct capi_ctr *ctr, struct sk_buff *skb)
  1794. {
  1795. struct gigaset_capi_ctr *iif
  1796. = container_of(ctr, struct gigaset_capi_ctr, ctr);
  1797. struct cardstate *cs = ctr->driverdata;
  1798. struct gigaset_capi_appl *ap;
  1799. capi_send_handler_t handler;
  1800. /* can only handle linear sk_buffs */
  1801. if (skb_linearize(skb) < 0) {
  1802. dev_warn(cs->dev, "%s: skb_linearize failed\n", __func__);
  1803. return CAPI_MSGOSRESOURCEERR;
  1804. }
  1805. /* retrieve application data structure */
  1806. ap = get_appl(iif, CAPIMSG_APPID(skb->data));
  1807. if (!ap) {
  1808. dev_notice(cs->dev, "%s: application %u not registered\n",
  1809. __func__, CAPIMSG_APPID(skb->data));
  1810. return CAPI_ILLAPPNR;
  1811. }
  1812. /* look up command */
  1813. handler = lookup_capi_send_handler(CAPIMSG_CMD(skb->data));
  1814. if (!handler) {
  1815. /* unknown/unsupported message type */
  1816. if (printk_ratelimit())
  1817. dev_notice(cs->dev, "%s: unsupported message %u\n",
  1818. __func__, CAPIMSG_CMD(skb->data));
  1819. return CAPI_ILLCMDORSUBCMDORMSGTOSMALL;
  1820. }
  1821. /* serialize */
  1822. if (atomic_add_return(1, &iif->sendqlen) > 1) {
  1823. /* queue behind other messages */
  1824. skb_queue_tail(&iif->sendqueue, skb);
  1825. return CAPI_NOERROR;
  1826. }
  1827. /* process message */
  1828. handler(iif, ap, skb);
  1829. /* process other messages arrived in the meantime */
  1830. while (atomic_sub_return(1, &iif->sendqlen) > 0) {
  1831. skb = skb_dequeue(&iif->sendqueue);
  1832. if (!skb) {
  1833. /* should never happen */
  1834. dev_err(cs->dev, "%s: send queue empty\n", __func__);
  1835. continue;
  1836. }
  1837. ap = get_appl(iif, CAPIMSG_APPID(skb->data));
  1838. if (!ap) {
  1839. /* could that happen? */
  1840. dev_warn(cs->dev, "%s: application %u vanished\n",
  1841. __func__, CAPIMSG_APPID(skb->data));
  1842. continue;
  1843. }
  1844. handler = lookup_capi_send_handler(CAPIMSG_CMD(skb->data));
  1845. if (!handler) {
  1846. /* should never happen */
  1847. dev_err(cs->dev, "%s: handler %x vanished\n",
  1848. __func__, CAPIMSG_CMD(skb->data));
  1849. continue;
  1850. }
  1851. handler(iif, ap, skb);
  1852. }
  1853. return CAPI_NOERROR;
  1854. }
  1855. /**
  1856. * gigaset_procinfo() - build single line description for controller
  1857. * @ctr: controller descriptor structure.
  1858. *
  1859. * Return value: pointer to generated string (null terminated)
  1860. */
  1861. static char *gigaset_procinfo(struct capi_ctr *ctr)
  1862. {
  1863. return ctr->name; /* ToDo: more? */
  1864. }
  1865. static int gigaset_proc_show(struct seq_file *m, void *v)
  1866. {
  1867. struct capi_ctr *ctr = m->private;
  1868. struct cardstate *cs = ctr->driverdata;
  1869. char *s;
  1870. int i;
  1871. seq_printf(m, "%-16s %s\n", "name", ctr->name);
  1872. seq_printf(m, "%-16s %s %s\n", "dev",
  1873. dev_driver_string(cs->dev), dev_name(cs->dev));
  1874. seq_printf(m, "%-16s %d\n", "id", cs->myid);
  1875. if (cs->gotfwver)
  1876. seq_printf(m, "%-16s %d.%d.%d.%d\n", "firmware",
  1877. cs->fwver[0], cs->fwver[1], cs->fwver[2], cs->fwver[3]);
  1878. seq_printf(m, "%-16s %d\n", "channels", cs->channels);
  1879. seq_printf(m, "%-16s %s\n", "onechannel", cs->onechannel ? "yes" : "no");
  1880. switch (cs->mode) {
  1881. case M_UNKNOWN:
  1882. s = "unknown";
  1883. break;
  1884. case M_CONFIG:
  1885. s = "config";
  1886. break;
  1887. case M_UNIMODEM:
  1888. s = "Unimodem";
  1889. break;
  1890. case M_CID:
  1891. s = "CID";
  1892. break;
  1893. default:
  1894. s = "??";
  1895. }
  1896. seq_printf(m, "%-16s %s\n", "mode", s);
  1897. switch (cs->mstate) {
  1898. case MS_UNINITIALIZED:
  1899. s = "uninitialized";
  1900. break;
  1901. case MS_INIT:
  1902. s = "init";
  1903. break;
  1904. case MS_LOCKED:
  1905. s = "locked";
  1906. break;
  1907. case MS_SHUTDOWN:
  1908. s = "shutdown";
  1909. break;
  1910. case MS_RECOVER:
  1911. s = "recover";
  1912. break;
  1913. case MS_READY:
  1914. s = "ready";
  1915. break;
  1916. default:
  1917. s = "??";
  1918. }
  1919. seq_printf(m, "%-16s %s\n", "mstate", s);
  1920. seq_printf(m, "%-16s %s\n", "running", cs->running ? "yes" : "no");
  1921. seq_printf(m, "%-16s %s\n", "connected", cs->connected ? "yes" : "no");
  1922. seq_printf(m, "%-16s %s\n", "isdn_up", cs->isdn_up ? "yes" : "no");
  1923. seq_printf(m, "%-16s %s\n", "cidmode", cs->cidmode ? "yes" : "no");
  1924. for (i = 0; i < cs->channels; i++) {
  1925. seq_printf(m, "[%d]%-13s %d\n", i, "corrupted",
  1926. cs->bcs[i].corrupted);
  1927. seq_printf(m, "[%d]%-13s %d\n", i, "trans_down",
  1928. cs->bcs[i].trans_down);
  1929. seq_printf(m, "[%d]%-13s %d\n", i, "trans_up",
  1930. cs->bcs[i].trans_up);
  1931. seq_printf(m, "[%d]%-13s %d\n", i, "chstate",
  1932. cs->bcs[i].chstate);
  1933. switch (cs->bcs[i].proto2) {
  1934. case L2_BITSYNC:
  1935. s = "bitsync";
  1936. break;
  1937. case L2_HDLC:
  1938. s = "HDLC";
  1939. break;
  1940. case L2_VOICE:
  1941. s = "voice";
  1942. break;
  1943. default:
  1944. s = "??";
  1945. }
  1946. seq_printf(m, "[%d]%-13s %s\n", i, "proto2", s);
  1947. }
  1948. return 0;
  1949. }
  1950. static int gigaset_proc_open(struct inode *inode, struct file *file)
  1951. {
  1952. return single_open(file, gigaset_proc_show, PDE(inode)->data);
  1953. }
  1954. static const struct file_operations gigaset_proc_fops = {
  1955. .owner = THIS_MODULE,
  1956. .open = gigaset_proc_open,
  1957. .read = seq_read,
  1958. .llseek = seq_lseek,
  1959. .release = single_release,
  1960. };
  1961. /**
  1962. * gigaset_isdn_regdev() - register device to LL
  1963. * @cs: device descriptor structure.
  1964. * @isdnid: device name.
  1965. *
  1966. * Return value: 1 for success, 0 for failure
  1967. */
  1968. int gigaset_isdn_regdev(struct cardstate *cs, const char *isdnid)
  1969. {
  1970. struct gigaset_capi_ctr *iif;
  1971. int rc;
  1972. iif = kmalloc(sizeof(*iif), GFP_KERNEL);
  1973. if (!iif) {
  1974. pr_err("%s: out of memory\n", __func__);
  1975. return 0;
  1976. }
  1977. /* prepare controller structure */
  1978. iif->ctr.owner = THIS_MODULE;
  1979. iif->ctr.driverdata = cs;
  1980. strncpy(iif->ctr.name, isdnid, sizeof(iif->ctr.name));
  1981. iif->ctr.driver_name = "gigaset";
  1982. iif->ctr.load_firmware = NULL;
  1983. iif->ctr.reset_ctr = NULL;
  1984. iif->ctr.register_appl = gigaset_register_appl;
  1985. iif->ctr.release_appl = gigaset_release_appl;
  1986. iif->ctr.send_message = gigaset_send_message;
  1987. iif->ctr.procinfo = gigaset_procinfo;
  1988. iif->ctr.proc_fops = &gigaset_proc_fops;
  1989. INIT_LIST_HEAD(&iif->appls);
  1990. skb_queue_head_init(&iif->sendqueue);
  1991. atomic_set(&iif->sendqlen, 0);
  1992. /* register controller with CAPI */
  1993. rc = attach_capi_ctr(&iif->ctr);
  1994. if (rc) {
  1995. pr_err("attach_capi_ctr failed (%d)\n", rc);
  1996. kfree(iif);
  1997. return 0;
  1998. }
  1999. cs->iif = iif;
  2000. cs->hw_hdr_len = CAPI_DATA_B3_REQ_LEN;
  2001. return 1;
  2002. }
  2003. /**
  2004. * gigaset_isdn_unregdev() - unregister device from LL
  2005. * @cs: device descriptor structure.
  2006. */
  2007. void gigaset_isdn_unregdev(struct cardstate *cs)
  2008. {
  2009. struct gigaset_capi_ctr *iif = cs->iif;
  2010. detach_capi_ctr(&iif->ctr);
  2011. kfree(iif);
  2012. cs->iif = NULL;
  2013. }
  2014. static struct capi_driver capi_driver_gigaset = {
  2015. .name = "gigaset",
  2016. .revision = "1.0",
  2017. };
  2018. /**
  2019. * gigaset_isdn_regdrv() - register driver to LL
  2020. */
  2021. void gigaset_isdn_regdrv(void)
  2022. {
  2023. pr_info("Kernel CAPI interface\n");
  2024. register_capi_driver(&capi_driver_gigaset);
  2025. }
  2026. /**
  2027. * gigaset_isdn_unregdrv() - unregister driver from LL
  2028. */
  2029. void gigaset_isdn_unregdrv(void)
  2030. {
  2031. unregister_capi_driver(&capi_driver_gigaset);
  2032. }