capi.c 63 KB

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