isdn_ttyfax.c 25 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124
  1. /* $Id: isdn_ttyfax.c,v 1.1.2.2 2004/01/12 22:37:19 keil Exp $
  2. *
  3. * Linux ISDN subsystem, tty_fax AT-command emulator (linklevel).
  4. *
  5. * Copyright 1999 by Armin Schindler (mac@melware.de)
  6. * Copyright 1999 by Ralf Spachmann (mel@melware.de)
  7. * Copyright 1999 by Cytronics & Melware
  8. *
  9. * This software may be used and distributed according to the terms
  10. * of the GNU General Public License, incorporated herein by reference.
  11. *
  12. */
  13. #undef ISDN_TTY_FAX_STAT_DEBUG
  14. #undef ISDN_TTY_FAX_CMD_DEBUG
  15. #include <linux/isdn.h>
  16. #include "isdn_common.h"
  17. #include "isdn_tty.h"
  18. #include "isdn_ttyfax.h"
  19. static char *isdn_tty_fax_revision = "$Revision: 1.1.2.2 $";
  20. #define PARSE_ERROR1 { isdn_tty_fax_modem_result(1, info); return 1; }
  21. static char *
  22. isdn_getrev(const char *revision)
  23. {
  24. char *rev;
  25. char *p;
  26. if ((p = strchr(revision, ':'))) {
  27. rev = p + 2;
  28. p = strchr(rev, '$');
  29. *--p = 0;
  30. } else
  31. rev = "???";
  32. return rev;
  33. }
  34. /*
  35. * Fax Class 2 Modem results
  36. *
  37. */
  38. static void
  39. isdn_tty_fax_modem_result(int code, modem_info * info)
  40. {
  41. atemu *m = &info->emu;
  42. T30_s *f = info->fax;
  43. char rs[50];
  44. char rss[50];
  45. char *rp;
  46. int i;
  47. static char *msg[] =
  48. {"OK", "ERROR", "+FCON", "+FCSI:", "+FDIS:",
  49. "+FHNG:", "+FDCS:", "CONNECT", "+FTSI:",
  50. "+FCFR", "+FPTS:", "+FET:"};
  51. isdn_tty_at_cout("\r\n", info);
  52. isdn_tty_at_cout(msg[code], info);
  53. #ifdef ISDN_TTY_FAX_CMD_DEBUG
  54. printk(KERN_DEBUG "isdn_tty: Fax send %s on ttyI%d\n",
  55. msg[code], info->line);
  56. #endif
  57. switch (code) {
  58. case 0: /* OK */
  59. break;
  60. case 1: /* ERROR */
  61. break;
  62. case 2: /* +FCON */
  63. /* Append CPN, if enabled */
  64. if ((m->mdmreg[REG_CPNFCON] & BIT_CPNFCON) &&
  65. (!(dev->usage[info->isdn_channel] & ISDN_USAGE_OUTGOING))) {
  66. sprintf(rs, "/%s", m->cpn);
  67. isdn_tty_at_cout(rs, info);
  68. }
  69. info->online = 1;
  70. f->fet = 0;
  71. if (f->phase == ISDN_FAX_PHASE_A)
  72. f->phase = ISDN_FAX_PHASE_B;
  73. break;
  74. case 3: /* +FCSI */
  75. case 8: /* +FTSI */
  76. sprintf(rs, "\"%s\"", f->r_id);
  77. isdn_tty_at_cout(rs, info);
  78. break;
  79. case 4: /* +FDIS */
  80. rs[0] = 0;
  81. rp = &f->r_resolution;
  82. for (i = 0; i < 8; i++) {
  83. sprintf(rss, "%c%s", rp[i] + 48,
  84. (i < 7) ? "," : "");
  85. strcat(rs, rss);
  86. }
  87. isdn_tty_at_cout(rs, info);
  88. #ifdef ISDN_TTY_FAX_CMD_DEBUG
  89. printk(KERN_DEBUG "isdn_tty: Fax DIS=%s on ttyI%d\n",
  90. rs, info->line);
  91. #endif
  92. break;
  93. case 5: /* +FHNG */
  94. sprintf(rs, "%d", f->code);
  95. isdn_tty_at_cout(rs, info);
  96. info->faxonline = 0;
  97. break;
  98. case 6: /* +FDCS */
  99. rs[0] = 0;
  100. rp = &f->r_resolution;
  101. for (i = 0; i < 8; i++) {
  102. sprintf(rss, "%c%s", rp[i] + 48,
  103. (i < 7) ? "," : "");
  104. strcat(rs, rss);
  105. }
  106. isdn_tty_at_cout(rs, info);
  107. #ifdef ISDN_TTY_FAX_CMD_DEBUG
  108. printk(KERN_DEBUG "isdn_tty: Fax DCS=%s on ttyI%d\n",
  109. rs, info->line);
  110. #endif
  111. break;
  112. case 7: /* CONNECT */
  113. info->faxonline |= 2;
  114. break;
  115. case 9: /* FCFR */
  116. break;
  117. case 10: /* FPTS */
  118. isdn_tty_at_cout("1", info);
  119. break;
  120. case 11: /* FET */
  121. sprintf(rs, "%d", f->fet);
  122. isdn_tty_at_cout(rs, info);
  123. break;
  124. }
  125. isdn_tty_at_cout("\r\n", info);
  126. switch (code) {
  127. case 7: /* CONNECT */
  128. info->online = 2;
  129. if (info->faxonline & 1) {
  130. sprintf(rs, "%c", XON);
  131. isdn_tty_at_cout(rs, info);
  132. }
  133. break;
  134. }
  135. }
  136. static int
  137. isdn_tty_fax_command1(modem_info * info, isdn_ctrl * c)
  138. {
  139. static char *msg[] =
  140. {"OK", "CONNECT", "NO CARRIER", "ERROR", "FCERROR"};
  141. #ifdef ISDN_TTY_FAX_CMD_DEBUG
  142. printk(KERN_DEBUG "isdn_tty: FCLASS1 cmd(%d)\n", c->parm.aux.cmd);
  143. #endif
  144. if (c->parm.aux.cmd < ISDN_FAX_CLASS1_QUERY) {
  145. if (info->online)
  146. info->online = 1;
  147. isdn_tty_at_cout("\r\n", info);
  148. isdn_tty_at_cout(msg[c->parm.aux.cmd], info);
  149. isdn_tty_at_cout("\r\n", info);
  150. }
  151. switch (c->parm.aux.cmd) {
  152. case ISDN_FAX_CLASS1_CONNECT:
  153. info->online = 2;
  154. break;
  155. case ISDN_FAX_CLASS1_OK:
  156. case ISDN_FAX_CLASS1_FCERROR:
  157. case ISDN_FAX_CLASS1_ERROR:
  158. case ISDN_FAX_CLASS1_NOCARR:
  159. break;
  160. case ISDN_FAX_CLASS1_QUERY:
  161. isdn_tty_at_cout("\r\n", info);
  162. if (!c->parm.aux.para[0]) {
  163. isdn_tty_at_cout(msg[ISDN_FAX_CLASS1_ERROR], info);
  164. isdn_tty_at_cout("\r\n", info);
  165. } else {
  166. isdn_tty_at_cout(c->parm.aux.para, info);
  167. isdn_tty_at_cout("\r\nOK\r\n", info);
  168. }
  169. break;
  170. }
  171. return (0);
  172. }
  173. int
  174. isdn_tty_fax_command(modem_info * info, isdn_ctrl * c)
  175. {
  176. T30_s *f = info->fax;
  177. char rs[10];
  178. if (TTY_IS_FCLASS1(info))
  179. return (isdn_tty_fax_command1(info, c));
  180. #ifdef ISDN_TTY_FAX_CMD_DEBUG
  181. printk(KERN_DEBUG "isdn_tty: Fax cmd %d on ttyI%d\n",
  182. f->r_code, info->line);
  183. #endif
  184. switch (f->r_code) {
  185. case ISDN_TTY_FAX_FCON:
  186. info->faxonline = 1;
  187. isdn_tty_fax_modem_result(2, info); /* +FCON */
  188. return (0);
  189. case ISDN_TTY_FAX_FCON_I:
  190. info->faxonline = 16;
  191. isdn_tty_fax_modem_result(2, info); /* +FCON */
  192. return (0);
  193. case ISDN_TTY_FAX_RID:
  194. if (info->faxonline & 1)
  195. isdn_tty_fax_modem_result(3, info); /* +FCSI */
  196. if (info->faxonline & 16)
  197. isdn_tty_fax_modem_result(8, info); /* +FTSI */
  198. return (0);
  199. case ISDN_TTY_FAX_DIS:
  200. isdn_tty_fax_modem_result(4, info); /* +FDIS */
  201. return (0);
  202. case ISDN_TTY_FAX_HNG:
  203. if (f->phase == ISDN_FAX_PHASE_C) {
  204. if (f->direction == ISDN_TTY_FAX_CONN_IN) {
  205. sprintf(rs, "%c%c", DLE, ETX);
  206. isdn_tty_at_cout(rs, info);
  207. } else {
  208. sprintf(rs, "%c", 0x18);
  209. isdn_tty_at_cout(rs, info);
  210. }
  211. info->faxonline &= ~2; /* leave data mode */
  212. info->online = 1;
  213. }
  214. f->phase = ISDN_FAX_PHASE_E;
  215. isdn_tty_fax_modem_result(5, info); /* +FHNG */
  216. isdn_tty_fax_modem_result(0, info); /* OK */
  217. return (0);
  218. case ISDN_TTY_FAX_DCS:
  219. isdn_tty_fax_modem_result(6, info); /* +FDCS */
  220. isdn_tty_fax_modem_result(7, info); /* CONNECT */
  221. f->phase = ISDN_FAX_PHASE_C;
  222. return (0);
  223. case ISDN_TTY_FAX_TRAIN_OK:
  224. isdn_tty_fax_modem_result(6, info); /* +FDCS */
  225. isdn_tty_fax_modem_result(0, info); /* OK */
  226. return (0);
  227. case ISDN_TTY_FAX_SENT:
  228. isdn_tty_fax_modem_result(0, info); /* OK */
  229. return (0);
  230. case ISDN_TTY_FAX_CFR:
  231. isdn_tty_fax_modem_result(9, info); /* +FCFR */
  232. return (0);
  233. case ISDN_TTY_FAX_ET:
  234. sprintf(rs, "%c%c", DLE, ETX);
  235. isdn_tty_at_cout(rs, info);
  236. isdn_tty_fax_modem_result(10, info); /* +FPTS */
  237. isdn_tty_fax_modem_result(11, info); /* +FET */
  238. isdn_tty_fax_modem_result(0, info); /* OK */
  239. info->faxonline &= ~2; /* leave data mode */
  240. info->online = 1;
  241. f->phase = ISDN_FAX_PHASE_D;
  242. return (0);
  243. case ISDN_TTY_FAX_PTS:
  244. isdn_tty_fax_modem_result(10, info); /* +FPTS */
  245. if (f->direction == ISDN_TTY_FAX_CONN_OUT) {
  246. if (f->fet == 1)
  247. f->phase = ISDN_FAX_PHASE_B;
  248. if (f->fet == 0)
  249. isdn_tty_fax_modem_result(0, info); /* OK */
  250. }
  251. return (0);
  252. case ISDN_TTY_FAX_EOP:
  253. info->faxonline &= ~2; /* leave data mode */
  254. info->online = 1;
  255. f->phase = ISDN_FAX_PHASE_D;
  256. return (0);
  257. }
  258. return (-1);
  259. }
  260. void
  261. isdn_tty_fax_bitorder(modem_info * info, struct sk_buff *skb)
  262. {
  263. __u8 LeftMask;
  264. __u8 RightMask;
  265. __u8 fBit;
  266. __u8 Data;
  267. int i;
  268. if (!info->fax->bor) {
  269. for (i = 0; i < skb->len; i++) {
  270. Data = skb->data[i];
  271. for (
  272. LeftMask = 0x80, RightMask = 0x01;
  273. LeftMask > RightMask;
  274. LeftMask >>= 1, RightMask <<= 1
  275. ) {
  276. fBit = (Data & LeftMask);
  277. if (Data & RightMask)
  278. Data |= LeftMask;
  279. else
  280. Data &= ~LeftMask;
  281. if (fBit)
  282. Data |= RightMask;
  283. else
  284. Data &= ~RightMask;
  285. }
  286. skb->data[i] = Data;
  287. }
  288. }
  289. }
  290. /*
  291. * Parse AT+F.. FAX class 1 commands
  292. */
  293. static int
  294. isdn_tty_cmd_FCLASS1(char **p, modem_info * info)
  295. {
  296. static char *cmd[] =
  297. {"AE", "TS", "RS", "TM", "RM", "TH", "RH"};
  298. isdn_ctrl c;
  299. int par, i;
  300. u_long flags;
  301. for (c.parm.aux.cmd = 0; c.parm.aux.cmd < 7; c.parm.aux.cmd++)
  302. if (!strncmp(p[0], cmd[c.parm.aux.cmd], 2))
  303. break;
  304. #ifdef ISDN_TTY_FAX_CMD_DEBUG
  305. printk(KERN_DEBUG "isdn_tty_cmd_FCLASS1 (%s,%d)\n", p[0], c.parm.aux.cmd);
  306. #endif
  307. if (c.parm.aux.cmd == 7)
  308. PARSE_ERROR1;
  309. p[0] += 2;
  310. switch (*p[0]) {
  311. case '?':
  312. p[0]++;
  313. c.parm.aux.subcmd = AT_QUERY;
  314. break;
  315. case '=':
  316. p[0]++;
  317. if (*p[0] == '?') {
  318. p[0]++;
  319. c.parm.aux.subcmd = AT_EQ_QUERY;
  320. } else {
  321. par = isdn_getnum(p);
  322. if ((par < 0) || (par > 255))
  323. PARSE_ERROR1;
  324. c.parm.aux.subcmd = AT_EQ_VALUE;
  325. c.parm.aux.para[0] = par;
  326. }
  327. break;
  328. case 0:
  329. c.parm.aux.subcmd = AT_COMMAND;
  330. break;
  331. default:
  332. PARSE_ERROR1;
  333. }
  334. c.command = ISDN_CMD_FAXCMD;
  335. #ifdef ISDN_TTY_FAX_CMD_DEBUG
  336. printk(KERN_DEBUG "isdn_tty_cmd_FCLASS1 %d/%d/%d)\n",
  337. c.parm.aux.cmd, c.parm.aux.subcmd, c.parm.aux.para[0]);
  338. #endif
  339. if (info->isdn_driver < 0) {
  340. if ((c.parm.aux.subcmd == AT_EQ_VALUE) ||
  341. (c.parm.aux.subcmd == AT_COMMAND)) {
  342. PARSE_ERROR1;
  343. }
  344. spin_lock_irqsave(&dev->lock, flags);
  345. /* get a temporary connection to the first free fax driver */
  346. i = isdn_get_free_channel(ISDN_USAGE_FAX, ISDN_PROTO_L2_FAX,
  347. ISDN_PROTO_L3_FCLASS1, -1, -1, "00");
  348. if (i < 0) {
  349. spin_unlock_irqrestore(&dev->lock, flags);
  350. PARSE_ERROR1;
  351. }
  352. info->isdn_driver = dev->drvmap[i];
  353. info->isdn_channel = dev->chanmap[i];
  354. info->drv_index = i;
  355. dev->m_idx[i] = info->line;
  356. spin_unlock_irqrestore(&dev->lock, flags);
  357. c.driver = info->isdn_driver;
  358. c.arg = info->isdn_channel;
  359. isdn_command(&c);
  360. spin_lock_irqsave(&dev->lock, flags);
  361. isdn_free_channel(info->isdn_driver, info->isdn_channel,
  362. ISDN_USAGE_FAX);
  363. info->isdn_driver = -1;
  364. info->isdn_channel = -1;
  365. if (info->drv_index >= 0) {
  366. dev->m_idx[info->drv_index] = -1;
  367. info->drv_index = -1;
  368. }
  369. spin_unlock_irqrestore(&dev->lock, flags);
  370. } else {
  371. c.driver = info->isdn_driver;
  372. c.arg = info->isdn_channel;
  373. isdn_command(&c);
  374. }
  375. return 1;
  376. }
  377. /*
  378. * Parse AT+F.. FAX class 2 commands
  379. */
  380. static int
  381. isdn_tty_cmd_FCLASS2(char **p, modem_info * info)
  382. {
  383. atemu *m = &info->emu;
  384. T30_s *f = info->fax;
  385. isdn_ctrl cmd;
  386. int par;
  387. char rs[50];
  388. char rss[50];
  389. int maxdccval[] =
  390. {1, 5, 2, 2, 3, 2, 0, 7};
  391. /* FAA still unchanged */
  392. if (!strncmp(p[0], "AA", 2)) { /* TODO */
  393. p[0] += 2;
  394. switch (*p[0]) {
  395. case '?':
  396. p[0]++;
  397. sprintf(rs, "\r\n%d", 0);
  398. isdn_tty_at_cout(rs, info);
  399. break;
  400. case '=':
  401. p[0]++;
  402. par = isdn_getnum(p);
  403. if ((par < 0) || (par > 255))
  404. PARSE_ERROR1;
  405. break;
  406. default:
  407. PARSE_ERROR1;
  408. }
  409. return 0;
  410. }
  411. /* BADLIN=value - dummy 0=disable errorchk disabled, 1-255 nr. of lines for making page bad */
  412. if (!strncmp(p[0], "BADLIN", 6)) {
  413. p[0] += 6;
  414. switch (*p[0]) {
  415. case '?':
  416. p[0]++;
  417. sprintf(rs, "\r\n%d", f->badlin);
  418. isdn_tty_at_cout(rs, info);
  419. break;
  420. case '=':
  421. p[0]++;
  422. if (*p[0] == '?') {
  423. p[0]++;
  424. sprintf(rs, "\r\n0-255");
  425. isdn_tty_at_cout(rs, info);
  426. } else {
  427. par = isdn_getnum(p);
  428. if ((par < 0) || (par > 255))
  429. PARSE_ERROR1;
  430. f->badlin = par;
  431. #ifdef ISDN_TTY_FAX_STAT_DEBUG
  432. printk(KERN_DEBUG "isdn_tty: Fax FBADLIN=%d\n", par);
  433. #endif
  434. }
  435. break;
  436. default:
  437. PARSE_ERROR1;
  438. }
  439. return 0;
  440. }
  441. /* BADMUL=value - dummy 0=disable errorchk disabled (threshold multiplier) */
  442. if (!strncmp(p[0], "BADMUL", 6)) {
  443. p[0] += 6;
  444. switch (*p[0]) {
  445. case '?':
  446. p[0]++;
  447. sprintf(rs, "\r\n%d", f->badmul);
  448. isdn_tty_at_cout(rs, info);
  449. break;
  450. case '=':
  451. p[0]++;
  452. if (*p[0] == '?') {
  453. p[0]++;
  454. sprintf(rs, "\r\n0-255");
  455. isdn_tty_at_cout(rs, info);
  456. } else {
  457. par = isdn_getnum(p);
  458. if ((par < 0) || (par > 255))
  459. PARSE_ERROR1;
  460. f->badmul = par;
  461. #ifdef ISDN_TTY_FAX_STAT_DEBUG
  462. printk(KERN_DEBUG "isdn_tty: Fax FBADMUL=%d\n", par);
  463. #endif
  464. }
  465. break;
  466. default:
  467. PARSE_ERROR1;
  468. }
  469. return 0;
  470. }
  471. /* BOR=n - Phase C bit order, 0=direct, 1=reverse */
  472. if (!strncmp(p[0], "BOR", 3)) {
  473. p[0] += 3;
  474. switch (*p[0]) {
  475. case '?':
  476. p[0]++;
  477. sprintf(rs, "\r\n%d", f->bor);
  478. isdn_tty_at_cout(rs, info);
  479. break;
  480. case '=':
  481. p[0]++;
  482. if (*p[0] == '?') {
  483. p[0]++;
  484. sprintf(rs, "\r\n0,1");
  485. isdn_tty_at_cout(rs, info);
  486. } else {
  487. par = isdn_getnum(p);
  488. if ((par < 0) || (par > 1))
  489. PARSE_ERROR1;
  490. f->bor = par;
  491. #ifdef ISDN_TTY_FAX_STAT_DEBUG
  492. printk(KERN_DEBUG "isdn_tty: Fax FBOR=%d\n", par);
  493. #endif
  494. }
  495. break;
  496. default:
  497. PARSE_ERROR1;
  498. }
  499. return 0;
  500. }
  501. /* NBC=n - No Best Capabilities */
  502. if (!strncmp(p[0], "NBC", 3)) {
  503. p[0] += 3;
  504. switch (*p[0]) {
  505. case '?':
  506. p[0]++;
  507. sprintf(rs, "\r\n%d", f->nbc);
  508. isdn_tty_at_cout(rs, info);
  509. break;
  510. case '=':
  511. p[0]++;
  512. if (*p[0] == '?') {
  513. p[0]++;
  514. sprintf(rs, "\r\n0,1");
  515. isdn_tty_at_cout(rs, info);
  516. } else {
  517. par = isdn_getnum(p);
  518. if ((par < 0) || (par > 1))
  519. PARSE_ERROR1;
  520. f->nbc = par;
  521. #ifdef ISDN_TTY_FAX_STAT_DEBUG
  522. printk(KERN_DEBUG "isdn_tty: Fax FNBC=%d\n", par);
  523. #endif
  524. }
  525. break;
  526. default:
  527. PARSE_ERROR1;
  528. }
  529. return 0;
  530. }
  531. /* BUF? - Readonly buffersize readout */
  532. if (!strncmp(p[0], "BUF?", 4)) {
  533. p[0] += 4;
  534. #ifdef ISDN_TTY_FAX_STAT_DEBUG
  535. printk(KERN_DEBUG "isdn_tty: Fax FBUF? (%d) \n", (16 * m->mdmreg[REG_PSIZE]));
  536. #endif
  537. p[0]++;
  538. sprintf(rs, "\r\n %d ", (16 * m->mdmreg[REG_PSIZE]));
  539. isdn_tty_at_cout(rs, info);
  540. return 0;
  541. }
  542. /* CIG=string - local fax station id string for polling rx */
  543. if (!strncmp(p[0], "CIG", 3)) {
  544. int i, r;
  545. p[0] += 3;
  546. switch (*p[0]) {
  547. case '?':
  548. p[0]++;
  549. sprintf(rs, "\r\n\"%s\"", f->pollid);
  550. isdn_tty_at_cout(rs, info);
  551. break;
  552. case '=':
  553. p[0]++;
  554. if (*p[0] == '?') {
  555. p[0]++;
  556. sprintf(rs, "\r\n\"STRING\"");
  557. isdn_tty_at_cout(rs, info);
  558. } else {
  559. if (*p[0] == '"')
  560. p[0]++;
  561. for (i = 0; (*p[0]) && i < (FAXIDLEN - 1) && (*p[0] != '"'); i++) {
  562. f->pollid[i] = *p[0]++;
  563. }
  564. if (*p[0] == '"')
  565. p[0]++;
  566. for (r = i; r < FAXIDLEN; r++) {
  567. f->pollid[r] = 32;
  568. }
  569. f->pollid[FAXIDLEN - 1] = 0;
  570. #ifdef ISDN_TTY_FAX_STAT_DEBUG
  571. printk(KERN_DEBUG "isdn_tty: Fax local poll ID rx \"%s\"\n", f->pollid);
  572. #endif
  573. }
  574. break;
  575. default:
  576. PARSE_ERROR1;
  577. }
  578. return 0;
  579. }
  580. /* CQ=n - copy qlty chk, 0= no chk, 1=only 1D chk, 2=1D+2D chk */
  581. if (!strncmp(p[0], "CQ", 2)) {
  582. p[0] += 2;
  583. switch (*p[0]) {
  584. case '?':
  585. p[0]++;
  586. sprintf(rs, "\r\n%d", f->cq);
  587. isdn_tty_at_cout(rs, info);
  588. break;
  589. case '=':
  590. p[0]++;
  591. if (*p[0] == '?') {
  592. p[0]++;
  593. sprintf(rs, "\r\n0,1,2");
  594. isdn_tty_at_cout(rs, info);
  595. } else {
  596. par = isdn_getnum(p);
  597. if ((par < 0) || (par > 2))
  598. PARSE_ERROR1;
  599. f->cq = par;
  600. #ifdef ISDN_TTY_FAX_STAT_DEBUG
  601. printk(KERN_DEBUG "isdn_tty: Fax FCQ=%d\n", par);
  602. #endif
  603. }
  604. break;
  605. default:
  606. PARSE_ERROR1;
  607. }
  608. return 0;
  609. }
  610. /* CR=n - can receive? 0= no data rx or poll remote dev, 1=do receive data or poll remote dev */
  611. if (!strncmp(p[0], "CR", 2)) {
  612. p[0] += 2;
  613. switch (*p[0]) {
  614. case '?':
  615. p[0]++;
  616. sprintf(rs, "\r\n%d", f->cr); /* read actual value from struct and print */
  617. isdn_tty_at_cout(rs, info);
  618. break;
  619. case '=':
  620. p[0]++;
  621. if (*p[0] == '?') {
  622. p[0]++;
  623. sprintf(rs, "\r\n0,1"); /* display online help */
  624. isdn_tty_at_cout(rs, info);
  625. } else {
  626. par = isdn_getnum(p);
  627. if ((par < 0) || (par > 1))
  628. PARSE_ERROR1;
  629. f->cr = par;
  630. #ifdef ISDN_TTY_FAX_STAT_DEBUG
  631. printk(KERN_DEBUG "isdn_tty: Fax FCR=%d\n", par);
  632. #endif
  633. }
  634. break;
  635. default:
  636. PARSE_ERROR1;
  637. }
  638. return 0;
  639. }
  640. /* CTCRTY=value - ECM retry count */
  641. if (!strncmp(p[0], "CTCRTY", 6)) {
  642. p[0] += 6;
  643. switch (*p[0]) {
  644. case '?':
  645. p[0]++;
  646. sprintf(rs, "\r\n%d", f->ctcrty);
  647. isdn_tty_at_cout(rs, info);
  648. break;
  649. case '=':
  650. p[0]++;
  651. if (*p[0] == '?') {
  652. p[0]++;
  653. sprintf(rs, "\r\n0-255");
  654. isdn_tty_at_cout(rs, info);
  655. } else {
  656. par = isdn_getnum(p);
  657. if ((par < 0) || (par > 255))
  658. PARSE_ERROR1;
  659. f->ctcrty = par;
  660. #ifdef ISDN_TTY_FAX_STAT_DEBUG
  661. printk(KERN_DEBUG "isdn_tty: Fax FCTCRTY=%d\n", par);
  662. #endif
  663. }
  664. break;
  665. default:
  666. PARSE_ERROR1;
  667. }
  668. return 0;
  669. }
  670. /* DCC=vr,br,wd,ln,df,ec,bf,st - DCE capabilities parms */
  671. if (!strncmp(p[0], "DCC", 3)) {
  672. char *rp = &f->resolution;
  673. int i;
  674. p[0] += 3;
  675. switch (*p[0]) {
  676. case '?':
  677. p[0]++;
  678. strcpy(rs, "\r\n");
  679. for (i = 0; i < 8; i++) {
  680. sprintf(rss, "%c%s", rp[i] + 48,
  681. (i < 7) ? "," : "");
  682. strcat(rs, rss);
  683. }
  684. isdn_tty_at_cout(rs, info);
  685. break;
  686. case '=':
  687. p[0]++;
  688. if (*p[0] == '?') {
  689. isdn_tty_at_cout("\r\n(0,1),(0-5),(0-2),(0-2),(0-3),(0-2),(0),(0-7)", info);
  690. p[0]++;
  691. } else {
  692. for (i = 0; (((*p[0] >= '0') && (*p[0] <= '9')) || (*p[0] == ',')) && (i < 8); i++) {
  693. if (*p[0] != ',') {
  694. if ((*p[0] - 48) > maxdccval[i]) {
  695. PARSE_ERROR1;
  696. }
  697. rp[i] = *p[0] - 48;
  698. p[0]++;
  699. if (*p[0] == ',')
  700. p[0]++;
  701. } else
  702. p[0]++;
  703. }
  704. #ifdef ISDN_TTY_FAX_STAT_DEBUG
  705. printk(KERN_DEBUG "isdn_tty: Fax FDCC capabilities DCE=%d,%d,%d,%d,%d,%d,%d,%d\n",
  706. rp[0], rp[1], rp[2], rp[3], rp[4], rp[5], rp[6], rp[7]);
  707. #endif
  708. }
  709. break;
  710. default:
  711. PARSE_ERROR1;
  712. }
  713. return 0;
  714. }
  715. /* DIS=vr,br,wd,ln,df,ec,bf,st - current session parms */
  716. if (!strncmp(p[0], "DIS", 3)) {
  717. char *rp = &f->resolution;
  718. int i;
  719. p[0] += 3;
  720. switch (*p[0]) {
  721. case '?':
  722. p[0]++;
  723. strcpy(rs, "\r\n");
  724. for (i = 0; i < 8; i++) {
  725. sprintf(rss, "%c%s", rp[i] + 48,
  726. (i < 7) ? "," : "");
  727. strcat(rs, rss);
  728. }
  729. isdn_tty_at_cout(rs, info);
  730. break;
  731. case '=':
  732. p[0]++;
  733. if (*p[0] == '?') {
  734. isdn_tty_at_cout("\r\n(0,1),(0-5),(0-2),(0-2),(0-3),(0-2),(0),(0-7)", info);
  735. p[0]++;
  736. } else {
  737. for (i = 0; (((*p[0] >= '0') && (*p[0] <= '9')) || (*p[0] == ',')) && (i < 8); i++) {
  738. if (*p[0] != ',') {
  739. if ((*p[0] - 48) > maxdccval[i]) {
  740. PARSE_ERROR1;
  741. }
  742. rp[i] = *p[0] - 48;
  743. p[0]++;
  744. if (*p[0] == ',')
  745. p[0]++;
  746. } else
  747. p[0]++;
  748. }
  749. #ifdef ISDN_TTY_FAX_STAT_DEBUG
  750. printk(KERN_DEBUG "isdn_tty: Fax FDIS session parms=%d,%d,%d,%d,%d,%d,%d,%d\n",
  751. rp[0], rp[1], rp[2], rp[3], rp[4], rp[5], rp[6], rp[7]);
  752. #endif
  753. }
  754. break;
  755. default:
  756. PARSE_ERROR1;
  757. }
  758. return 0;
  759. }
  760. /* DR - Receive Phase C data command, initiates document reception */
  761. if (!strncmp(p[0], "DR", 2)) {
  762. p[0] += 2;
  763. if ((info->faxonline & 16) && /* incoming connection */
  764. ((f->phase == ISDN_FAX_PHASE_B) || (f->phase == ISDN_FAX_PHASE_D))) {
  765. #ifdef ISDN_TTY_FAX_STAT_DEBUG
  766. printk(KERN_DEBUG "isdn_tty: Fax FDR\n");
  767. #endif
  768. f->code = ISDN_TTY_FAX_DR;
  769. cmd.driver = info->isdn_driver;
  770. cmd.arg = info->isdn_channel;
  771. cmd.command = ISDN_CMD_FAXCMD;
  772. isdn_command(&cmd);
  773. if (f->phase == ISDN_FAX_PHASE_B) {
  774. f->phase = ISDN_FAX_PHASE_C;
  775. } else if (f->phase == ISDN_FAX_PHASE_D) {
  776. switch (f->fet) {
  777. case 0: /* next page will be received */
  778. f->phase = ISDN_FAX_PHASE_C;
  779. isdn_tty_fax_modem_result(7, info); /* CONNECT */
  780. break;
  781. case 1: /* next doc will be received */
  782. f->phase = ISDN_FAX_PHASE_B;
  783. break;
  784. case 2: /* fax session is terminating */
  785. f->phase = ISDN_FAX_PHASE_E;
  786. break;
  787. default:
  788. PARSE_ERROR1;
  789. }
  790. }
  791. } else {
  792. PARSE_ERROR1;
  793. }
  794. return 1;
  795. }
  796. /* DT=df,vr,wd,ln - TX phase C data command (release DCE to proceed with negotiation) */
  797. if (!strncmp(p[0], "DT", 2)) {
  798. int i, val[] =
  799. {4, 0, 2, 3};
  800. char *rp = &f->resolution;
  801. p[0] += 2;
  802. if (!(info->faxonline & 1)) /* not outgoing connection */
  803. PARSE_ERROR1;
  804. for (i = 0; (((*p[0] >= '0') && (*p[0] <= '9')) || (*p[0] == ',')) && (i < 4); i++) {
  805. if (*p[0] != ',') {
  806. if ((*p[0] - 48) > maxdccval[val[i]]) {
  807. PARSE_ERROR1;
  808. }
  809. rp[val[i]] = *p[0] - 48;
  810. p[0]++;
  811. if (*p[0] == ',')
  812. p[0]++;
  813. } else
  814. p[0]++;
  815. }
  816. #ifdef ISDN_TTY_FAX_STAT_DEBUG
  817. printk(KERN_DEBUG "isdn_tty: Fax FDT tx data command parms=%d,%d,%d,%d\n",
  818. rp[4], rp[0], rp[2], rp[3]);
  819. #endif
  820. if ((f->phase == ISDN_FAX_PHASE_B) || (f->phase == ISDN_FAX_PHASE_D)) {
  821. f->code = ISDN_TTY_FAX_DT;
  822. cmd.driver = info->isdn_driver;
  823. cmd.arg = info->isdn_channel;
  824. cmd.command = ISDN_CMD_FAXCMD;
  825. isdn_command(&cmd);
  826. if (f->phase == ISDN_FAX_PHASE_D) {
  827. f->phase = ISDN_FAX_PHASE_C;
  828. isdn_tty_fax_modem_result(7, info); /* CONNECT */
  829. }
  830. } else {
  831. PARSE_ERROR1;
  832. }
  833. return 1;
  834. }
  835. /* ECM=n - Error mode control 0=disabled, 2=enabled, handled by DCE alone incl. buff of partial pages */
  836. if (!strncmp(p[0], "ECM", 3)) {
  837. p[0] += 3;
  838. switch (*p[0]) {
  839. case '?':
  840. p[0]++;
  841. sprintf(rs, "\r\n%d", f->ecm);
  842. isdn_tty_at_cout(rs, info);
  843. break;
  844. case '=':
  845. p[0]++;
  846. if (*p[0] == '?') {
  847. p[0]++;
  848. sprintf(rs, "\r\n0,2");
  849. isdn_tty_at_cout(rs, info);
  850. } else {
  851. par = isdn_getnum(p);
  852. if ((par != 0) && (par != 2))
  853. PARSE_ERROR1;
  854. f->ecm = par;
  855. #ifdef ISDN_TTY_FAX_STAT_DEBUG
  856. printk(KERN_DEBUG "isdn_tty: Fax FECM=%d\n", par);
  857. #endif
  858. }
  859. break;
  860. default:
  861. PARSE_ERROR1;
  862. }
  863. return 0;
  864. }
  865. /* ET=n - End of page or document */
  866. if (!strncmp(p[0], "ET=", 3)) {
  867. p[0] += 3;
  868. if (*p[0] == '?') {
  869. p[0]++;
  870. sprintf(rs, "\r\n0-2");
  871. isdn_tty_at_cout(rs, info);
  872. } else {
  873. if ((f->phase != ISDN_FAX_PHASE_D) ||
  874. (!(info->faxonline & 1)))
  875. PARSE_ERROR1;
  876. par = isdn_getnum(p);
  877. if ((par < 0) || (par > 2))
  878. PARSE_ERROR1;
  879. f->fet = par;
  880. f->code = ISDN_TTY_FAX_ET;
  881. cmd.driver = info->isdn_driver;
  882. cmd.arg = info->isdn_channel;
  883. cmd.command = ISDN_CMD_FAXCMD;
  884. isdn_command(&cmd);
  885. #ifdef ISDN_TTY_FAX_STAT_DEBUG
  886. printk(KERN_DEBUG "isdn_tty: Fax FET=%d\n", par);
  887. #endif
  888. return 1;
  889. }
  890. return 0;
  891. }
  892. /* K - terminate */
  893. if (!strncmp(p[0], "K", 1)) {
  894. p[0] += 1;
  895. if ((f->phase == ISDN_FAX_PHASE_IDLE) || (f->phase == ISDN_FAX_PHASE_E))
  896. PARSE_ERROR1;
  897. isdn_tty_modem_hup(info, 1);
  898. return 1;
  899. }
  900. /* LID=string - local fax ID */
  901. if (!strncmp(p[0], "LID", 3)) {
  902. int i, r;
  903. p[0] += 3;
  904. switch (*p[0]) {
  905. case '?':
  906. p[0]++;
  907. sprintf(rs, "\r\n\"%s\"", f->id);
  908. isdn_tty_at_cout(rs, info);
  909. break;
  910. case '=':
  911. p[0]++;
  912. if (*p[0] == '?') {
  913. p[0]++;
  914. sprintf(rs, "\r\n\"STRING\"");
  915. isdn_tty_at_cout(rs, info);
  916. } else {
  917. if (*p[0] == '"')
  918. p[0]++;
  919. for (i = 0; (*p[0]) && i < (FAXIDLEN - 1) && (*p[0] != '"'); i++) {
  920. f->id[i] = *p[0]++;
  921. }
  922. if (*p[0] == '"')
  923. p[0]++;
  924. for (r = i; r < FAXIDLEN; r++) {
  925. f->id[r] = 32;
  926. }
  927. f->id[FAXIDLEN - 1] = 0;
  928. #ifdef ISDN_TTY_FAX_STAT_DEBUG
  929. printk(KERN_DEBUG "isdn_tty: Fax local ID \"%s\"\n", f->id);
  930. #endif
  931. }
  932. break;
  933. default:
  934. PARSE_ERROR1;
  935. }
  936. return 0;
  937. }
  938. /* MDL? - DCE Model */
  939. if (!strncmp(p[0], "MDL?", 4)) {
  940. p[0] += 4;
  941. #ifdef ISDN_TTY_FAX_STAT_DEBUG
  942. printk(KERN_DEBUG "isdn_tty: FMDL?\n");
  943. #endif
  944. isdn_tty_at_cout("\r\nisdn4linux", info);
  945. return 0;
  946. }
  947. /* MFR? - DCE Manufacturer */
  948. if (!strncmp(p[0], "MFR?", 4)) {
  949. p[0] += 4;
  950. #ifdef ISDN_TTY_FAX_STAT_DEBUG
  951. printk(KERN_DEBUG "isdn_tty: FMFR?\n");
  952. #endif
  953. isdn_tty_at_cout("\r\nisdn4linux", info);
  954. return 0;
  955. }
  956. /* MINSP=n - Minimum Speed for Phase C */
  957. if (!strncmp(p[0], "MINSP", 5)) {
  958. p[0] += 5;
  959. switch (*p[0]) {
  960. case '?':
  961. p[0]++;
  962. sprintf(rs, "\r\n%d", f->minsp);
  963. isdn_tty_at_cout(rs, info);
  964. break;
  965. case '=':
  966. p[0]++;
  967. if (*p[0] == '?') {
  968. p[0]++;
  969. sprintf(rs, "\r\n0-5");
  970. isdn_tty_at_cout(rs, info);
  971. } else {
  972. par = isdn_getnum(p);
  973. if ((par < 0) || (par > 5))
  974. PARSE_ERROR1;
  975. f->minsp = par;
  976. #ifdef ISDN_TTY_FAX_STAT_DEBUG
  977. printk(KERN_DEBUG "isdn_tty: Fax FMINSP=%d\n", par);
  978. #endif
  979. }
  980. break;
  981. default:
  982. PARSE_ERROR1;
  983. }
  984. return 0;
  985. }
  986. /* PHCTO=value - DTE phase C timeout */
  987. if (!strncmp(p[0], "PHCTO", 5)) {
  988. p[0] += 5;
  989. switch (*p[0]) {
  990. case '?':
  991. p[0]++;
  992. sprintf(rs, "\r\n%d", f->phcto);
  993. isdn_tty_at_cout(rs, info);
  994. break;
  995. case '=':
  996. p[0]++;
  997. if (*p[0] == '?') {
  998. p[0]++;
  999. sprintf(rs, "\r\n0-255");
  1000. isdn_tty_at_cout(rs, info);
  1001. } else {
  1002. par = isdn_getnum(p);
  1003. if ((par < 0) || (par > 255))
  1004. PARSE_ERROR1;
  1005. f->phcto = par;
  1006. #ifdef ISDN_TTY_FAX_STAT_DEBUG
  1007. printk(KERN_DEBUG "isdn_tty: Fax FPHCTO=%d\n", par);
  1008. #endif
  1009. }
  1010. break;
  1011. default:
  1012. PARSE_ERROR1;
  1013. }
  1014. return 0;
  1015. }
  1016. /* REL=n - Phase C received EOL alignment */
  1017. if (!strncmp(p[0], "REL", 3)) {
  1018. p[0] += 3;
  1019. switch (*p[0]) {
  1020. case '?':
  1021. p[0]++;
  1022. sprintf(rs, "\r\n%d", f->rel);
  1023. isdn_tty_at_cout(rs, info);
  1024. break;
  1025. case '=':
  1026. p[0]++;
  1027. if (*p[0] == '?') {
  1028. p[0]++;
  1029. sprintf(rs, "\r\n0,1");
  1030. isdn_tty_at_cout(rs, info);
  1031. } else {
  1032. par = isdn_getnum(p);
  1033. if ((par < 0) || (par > 1))
  1034. PARSE_ERROR1;
  1035. f->rel = par;
  1036. #ifdef ISDN_TTY_FAX_STAT_DEBUG
  1037. printk(KERN_DEBUG "isdn_tty: Fax FREL=%d\n", par);
  1038. #endif
  1039. }
  1040. break;
  1041. default:
  1042. PARSE_ERROR1;
  1043. }
  1044. return 0;
  1045. }
  1046. /* REV? - DCE Revision */
  1047. if (!strncmp(p[0], "REV?", 4)) {
  1048. p[0] += 4;
  1049. #ifdef ISDN_TTY_FAX_STAT_DEBUG
  1050. printk(KERN_DEBUG "isdn_tty: FREV?\n");
  1051. #endif
  1052. strcpy(rss, isdn_tty_fax_revision);
  1053. sprintf(rs, "\r\nRev: %s", isdn_getrev(rss));
  1054. isdn_tty_at_cout(rs, info);
  1055. return 0;
  1056. }
  1057. /* Phase C Transmit Data Block Size */
  1058. if (!strncmp(p[0], "TBC=", 4)) { /* dummy, not used */
  1059. p[0] += 4;
  1060. #ifdef ISDN_TTY_FAX_STAT_DEBUG
  1061. printk(KERN_DEBUG "isdn_tty: Fax FTBC=%c\n", *p[0]);
  1062. #endif
  1063. switch (*p[0]) {
  1064. case '0':
  1065. p[0]++;
  1066. break;
  1067. default:
  1068. PARSE_ERROR1;
  1069. }
  1070. return 0;
  1071. }
  1072. printk(KERN_DEBUG "isdn_tty: unknown token=>AT+F%s<\n", p[0]);
  1073. PARSE_ERROR1;
  1074. }
  1075. int
  1076. isdn_tty_cmd_PLUSF_FAX(char **p, modem_info * info)
  1077. {
  1078. if (TTY_IS_FCLASS2(info))
  1079. return (isdn_tty_cmd_FCLASS2(p, info));
  1080. else if (TTY_IS_FCLASS1(info))
  1081. return (isdn_tty_cmd_FCLASS1(p, info));
  1082. PARSE_ERROR1;
  1083. }