n_r3964.c 31 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272
  1. /* r3964 linediscipline for linux
  2. *
  3. * -----------------------------------------------------------
  4. * Copyright by
  5. * Philips Automation Projects
  6. * Kassel (Germany)
  7. * http://www.pap-philips.de
  8. * -----------------------------------------------------------
  9. * This software may be used and distributed according to the terms of
  10. * the GNU General Public License, incorporated herein by reference.
  11. *
  12. * Author:
  13. * L. Haag
  14. *
  15. * $Log: n_r3964.c,v $
  16. * Revision 1.1.1.1 2007/06/12 07:27:10 eyryu
  17. * s3c-linux-2.6.21.5
  18. *
  19. * Revision 1.10 2001/03/18 13:02:24 dwmw2
  20. * Fix timer usage, use spinlocks properly.
  21. *
  22. * Revision 1.9 2001/03/18 12:52:14 dwmw2
  23. * Merge changes in 2.4.2
  24. *
  25. * Revision 1.8 2000/03/23 14:14:54 dwmw2
  26. * Fix race in sleeping in r3964_read()
  27. *
  28. * Revision 1.7 1999/28/08 11:41:50 dwmw2
  29. * Port to 2.3 kernel
  30. *
  31. * Revision 1.6 1998/09/30 00:40:40 dwmw2
  32. * Fixed compilation on 2.0.x kernels
  33. * Updated to newly registered tty-ldisc number 9
  34. *
  35. * Revision 1.5 1998/09/04 21:57:36 dwmw2
  36. * Signal handling bug fixes, port to 2.1.x.
  37. *
  38. * Revision 1.4 1998/04/02 20:26:59 lhaag
  39. * select, blocking, ...
  40. *
  41. * Revision 1.3 1998/02/12 18:58:43 root
  42. * fixed some memory leaks
  43. * calculation of checksum characters
  44. *
  45. * Revision 1.2 1998/02/07 13:03:34 root
  46. * ioctl read_telegram
  47. *
  48. * Revision 1.1 1998/02/06 19:21:03 root
  49. * Initial revision
  50. *
  51. *
  52. */
  53. #include <linux/module.h>
  54. #include <linux/kernel.h>
  55. #include <linux/sched.h>
  56. #include <linux/types.h>
  57. #include <linux/fcntl.h>
  58. #include <linux/interrupt.h>
  59. #include <linux/ptrace.h>
  60. #include <linux/ioport.h>
  61. #include <linux/in.h>
  62. #include <linux/slab.h>
  63. #include <linux/tty.h>
  64. #include <linux/errno.h>
  65. #include <linux/string.h> /* used in new tty drivers */
  66. #include <linux/signal.h> /* used in new tty drivers */
  67. #include <linux/ioctl.h>
  68. #include <linux/n_r3964.h>
  69. #include <linux/poll.h>
  70. #include <linux/init.h>
  71. #include <asm/uaccess.h>
  72. /*#define DEBUG_QUEUE*/
  73. /* Log successful handshake and protocol operations */
  74. /*#define DEBUG_PROTO_S*/
  75. /* Log handshake and protocol errors: */
  76. /*#define DEBUG_PROTO_E*/
  77. /* Log Linediscipline operations (open, close, read, write...): */
  78. /*#define DEBUG_LDISC*/
  79. /* Log module and memory operations (init, cleanup; kmalloc, kfree): */
  80. /*#define DEBUG_MODUL*/
  81. /* Macro helpers for debug output: */
  82. #define TRACE(format, args...) printk("r3964: " format "\n" , ## args)
  83. #ifdef DEBUG_MODUL
  84. #define TRACE_M(format, args...) printk("r3964: " format "\n" , ## args)
  85. #else
  86. #define TRACE_M(fmt, arg...) do {} while (0)
  87. #endif
  88. #ifdef DEBUG_PROTO_S
  89. #define TRACE_PS(format, args...) printk("r3964: " format "\n" , ## args)
  90. #else
  91. #define TRACE_PS(fmt, arg...) do {} while (0)
  92. #endif
  93. #ifdef DEBUG_PROTO_E
  94. #define TRACE_PE(format, args...) printk("r3964: " format "\n" , ## args)
  95. #else
  96. #define TRACE_PE(fmt, arg...) do {} while (0)
  97. #endif
  98. #ifdef DEBUG_LDISC
  99. #define TRACE_L(format, args...) printk("r3964: " format "\n" , ## args)
  100. #else
  101. #define TRACE_L(fmt, arg...) do {} while (0)
  102. #endif
  103. #ifdef DEBUG_QUEUE
  104. #define TRACE_Q(format, args...) printk("r3964: " format "\n" , ## args)
  105. #else
  106. #define TRACE_Q(fmt, arg...) do {} while (0)
  107. #endif
  108. static void add_tx_queue(struct r3964_info *, struct r3964_block_header *);
  109. static void remove_from_tx_queue(struct r3964_info *pInfo, int error_code);
  110. static void put_char(struct r3964_info *pInfo, unsigned char ch);
  111. static void trigger_transmit(struct r3964_info *pInfo);
  112. static void retry_transmit(struct r3964_info *pInfo);
  113. static void transmit_block(struct r3964_info *pInfo);
  114. static void receive_char(struct r3964_info *pInfo, const unsigned char c);
  115. static void receive_error(struct r3964_info *pInfo, const char flag);
  116. static void on_timeout(unsigned long priv);
  117. static int enable_signals(struct r3964_info *pInfo, struct pid *pid, int arg);
  118. static int read_telegram(struct r3964_info *pInfo, struct pid *pid,
  119. unsigned char __user * buf);
  120. static void add_msg(struct r3964_client_info *pClient, int msg_id, int arg,
  121. int error_code, struct r3964_block_header *pBlock);
  122. static struct r3964_message *remove_msg(struct r3964_info *pInfo,
  123. struct r3964_client_info *pClient);
  124. static void remove_client_block(struct r3964_info *pInfo,
  125. struct r3964_client_info *pClient);
  126. static int r3964_open(struct tty_struct *tty);
  127. static void r3964_close(struct tty_struct *tty);
  128. static ssize_t r3964_read(struct tty_struct *tty, struct file *file,
  129. unsigned char __user * buf, size_t nr);
  130. static ssize_t r3964_write(struct tty_struct *tty, struct file *file,
  131. const unsigned char *buf, size_t nr);
  132. static int r3964_ioctl(struct tty_struct *tty, struct file *file,
  133. unsigned int cmd, unsigned long arg);
  134. static void r3964_set_termios(struct tty_struct *tty, struct ktermios *old);
  135. static unsigned int r3964_poll(struct tty_struct *tty, struct file *file,
  136. struct poll_table_struct *wait);
  137. static void r3964_receive_buf(struct tty_struct *tty, const unsigned char *cp,
  138. char *fp, int count);
  139. static struct tty_ldisc tty_ldisc_N_R3964 = {
  140. .owner = THIS_MODULE,
  141. .magic = TTY_LDISC_MAGIC,
  142. .name = "R3964",
  143. .open = r3964_open,
  144. .close = r3964_close,
  145. .read = r3964_read,
  146. .write = r3964_write,
  147. .ioctl = r3964_ioctl,
  148. .set_termios = r3964_set_termios,
  149. .poll = r3964_poll,
  150. .receive_buf = r3964_receive_buf,
  151. };
  152. static void dump_block(const unsigned char *block, unsigned int length)
  153. {
  154. unsigned int i, j;
  155. char linebuf[16 * 3 + 1];
  156. for (i = 0; i < length; i += 16) {
  157. for (j = 0; (j < 16) && (j + i < length); j++) {
  158. sprintf(linebuf + 3 * j, "%02x ", block[i + j]);
  159. }
  160. linebuf[3 * j] = '\0';
  161. TRACE_PS("%s", linebuf);
  162. }
  163. }
  164. /*************************************************************
  165. * Driver initialisation
  166. *************************************************************/
  167. /*************************************************************
  168. * Module support routines
  169. *************************************************************/
  170. static void __exit r3964_exit(void)
  171. {
  172. int status;
  173. TRACE_M("cleanup_module()");
  174. status = tty_unregister_ldisc(N_R3964);
  175. if (status != 0) {
  176. printk(KERN_ERR "r3964: error unregistering linediscipline: "
  177. "%d\n", status);
  178. } else {
  179. TRACE_L("linediscipline successfully unregistered");
  180. }
  181. }
  182. static int __init r3964_init(void)
  183. {
  184. int status;
  185. printk("r3964: Philips r3964 Driver $Revision: 1.1.1.1 $\n");
  186. /*
  187. * Register the tty line discipline
  188. */
  189. status = tty_register_ldisc(N_R3964, &tty_ldisc_N_R3964);
  190. if (status == 0) {
  191. TRACE_L("line discipline %d registered", N_R3964);
  192. TRACE_L("flags=%x num=%x", tty_ldisc_N_R3964.flags,
  193. tty_ldisc_N_R3964.num);
  194. TRACE_L("open=%p", tty_ldisc_N_R3964.open);
  195. TRACE_L("tty_ldisc_N_R3964 = %p", &tty_ldisc_N_R3964);
  196. } else {
  197. printk(KERN_ERR "r3964: error registering line discipline: "
  198. "%d\n", status);
  199. }
  200. return status;
  201. }
  202. module_init(r3964_init);
  203. module_exit(r3964_exit);
  204. /*************************************************************
  205. * Protocol implementation routines
  206. *************************************************************/
  207. static void add_tx_queue(struct r3964_info *pInfo,
  208. struct r3964_block_header *pHeader)
  209. {
  210. unsigned long flags;
  211. spin_lock_irqsave(&pInfo->lock, flags);
  212. pHeader->next = NULL;
  213. if (pInfo->tx_last == NULL) {
  214. pInfo->tx_first = pInfo->tx_last = pHeader;
  215. } else {
  216. pInfo->tx_last->next = pHeader;
  217. pInfo->tx_last = pHeader;
  218. }
  219. spin_unlock_irqrestore(&pInfo->lock, flags);
  220. TRACE_Q("add_tx_queue %p, length %d, tx_first = %p",
  221. pHeader, pHeader->length, pInfo->tx_first);
  222. }
  223. static void remove_from_tx_queue(struct r3964_info *pInfo, int error_code)
  224. {
  225. struct r3964_block_header *pHeader;
  226. unsigned long flags;
  227. #ifdef DEBUG_QUEUE
  228. struct r3964_block_header *pDump;
  229. #endif
  230. pHeader = pInfo->tx_first;
  231. if (pHeader == NULL)
  232. return;
  233. #ifdef DEBUG_QUEUE
  234. printk("r3964: remove_from_tx_queue: %p, length %u - ",
  235. pHeader, pHeader->length);
  236. for (pDump = pHeader; pDump; pDump = pDump->next)
  237. printk("%p ", pDump);
  238. printk("\n");
  239. #endif
  240. if (pHeader->owner) {
  241. if (error_code) {
  242. add_msg(pHeader->owner, R3964_MSG_ACK, 0,
  243. error_code, NULL);
  244. } else {
  245. add_msg(pHeader->owner, R3964_MSG_ACK, pHeader->length,
  246. error_code, NULL);
  247. }
  248. wake_up_interruptible(&pInfo->read_wait);
  249. }
  250. spin_lock_irqsave(&pInfo->lock, flags);
  251. pInfo->tx_first = pHeader->next;
  252. if (pInfo->tx_first == NULL) {
  253. pInfo->tx_last = NULL;
  254. }
  255. spin_unlock_irqrestore(&pInfo->lock, flags);
  256. kfree(pHeader);
  257. TRACE_M("remove_from_tx_queue - kfree %p", pHeader);
  258. TRACE_Q("remove_from_tx_queue: tx_first = %p, tx_last = %p",
  259. pInfo->tx_first, pInfo->tx_last);
  260. }
  261. static void add_rx_queue(struct r3964_info *pInfo,
  262. struct r3964_block_header *pHeader)
  263. {
  264. unsigned long flags;
  265. spin_lock_irqsave(&pInfo->lock, flags);
  266. pHeader->next = NULL;
  267. if (pInfo->rx_last == NULL) {
  268. pInfo->rx_first = pInfo->rx_last = pHeader;
  269. } else {
  270. pInfo->rx_last->next = pHeader;
  271. pInfo->rx_last = pHeader;
  272. }
  273. pInfo->blocks_in_rx_queue++;
  274. spin_unlock_irqrestore(&pInfo->lock, flags);
  275. TRACE_Q("add_rx_queue: %p, length = %d, rx_first = %p, count = %d",
  276. pHeader, pHeader->length,
  277. pInfo->rx_first, pInfo->blocks_in_rx_queue);
  278. }
  279. static void remove_from_rx_queue(struct r3964_info *pInfo,
  280. struct r3964_block_header *pHeader)
  281. {
  282. unsigned long flags;
  283. struct r3964_block_header *pFind;
  284. if (pHeader == NULL)
  285. return;
  286. TRACE_Q("remove_from_rx_queue: rx_first = %p, rx_last = %p, count = %d",
  287. pInfo->rx_first, pInfo->rx_last, pInfo->blocks_in_rx_queue);
  288. TRACE_Q("remove_from_rx_queue: %p, length %u",
  289. pHeader, pHeader->length);
  290. spin_lock_irqsave(&pInfo->lock, flags);
  291. if (pInfo->rx_first == pHeader) {
  292. /* Remove the first block in the linked list: */
  293. pInfo->rx_first = pHeader->next;
  294. if (pInfo->rx_first == NULL) {
  295. pInfo->rx_last = NULL;
  296. }
  297. pInfo->blocks_in_rx_queue--;
  298. } else {
  299. /* Find block to remove: */
  300. for (pFind = pInfo->rx_first; pFind; pFind = pFind->next) {
  301. if (pFind->next == pHeader) {
  302. /* Got it. */
  303. pFind->next = pHeader->next;
  304. pInfo->blocks_in_rx_queue--;
  305. if (pFind->next == NULL) {
  306. /* Oh, removed the last one! */
  307. pInfo->rx_last = pFind;
  308. }
  309. break;
  310. }
  311. }
  312. }
  313. spin_unlock_irqrestore(&pInfo->lock, flags);
  314. kfree(pHeader);
  315. TRACE_M("remove_from_rx_queue - kfree %p", pHeader);
  316. TRACE_Q("remove_from_rx_queue: rx_first = %p, rx_last = %p, count = %d",
  317. pInfo->rx_first, pInfo->rx_last, pInfo->blocks_in_rx_queue);
  318. }
  319. static void put_char(struct r3964_info *pInfo, unsigned char ch)
  320. {
  321. struct tty_struct *tty = pInfo->tty;
  322. if (tty == NULL)
  323. return;
  324. if (tty->driver->put_char) {
  325. tty->driver->put_char(tty, ch);
  326. }
  327. pInfo->bcc ^= ch;
  328. }
  329. static void flush(struct r3964_info *pInfo)
  330. {
  331. struct tty_struct *tty = pInfo->tty;
  332. if (tty == NULL)
  333. return;
  334. if (tty->driver->flush_chars) {
  335. tty->driver->flush_chars(tty);
  336. }
  337. }
  338. static void trigger_transmit(struct r3964_info *pInfo)
  339. {
  340. unsigned long flags;
  341. spin_lock_irqsave(&pInfo->lock, flags);
  342. if ((pInfo->state == R3964_IDLE) && (pInfo->tx_first != NULL)) {
  343. pInfo->state = R3964_TX_REQUEST;
  344. pInfo->nRetry = 0;
  345. pInfo->flags &= ~R3964_ERROR;
  346. mod_timer(&pInfo->tmr, jiffies + R3964_TO_QVZ);
  347. spin_unlock_irqrestore(&pInfo->lock, flags);
  348. TRACE_PS("trigger_transmit - sent STX");
  349. put_char(pInfo, STX);
  350. flush(pInfo);
  351. pInfo->bcc = 0;
  352. } else {
  353. spin_unlock_irqrestore(&pInfo->lock, flags);
  354. }
  355. }
  356. static void retry_transmit(struct r3964_info *pInfo)
  357. {
  358. if (pInfo->nRetry < R3964_MAX_RETRIES) {
  359. TRACE_PE("transmission failed. Retry #%d", pInfo->nRetry);
  360. pInfo->bcc = 0;
  361. put_char(pInfo, STX);
  362. flush(pInfo);
  363. pInfo->state = R3964_TX_REQUEST;
  364. pInfo->nRetry++;
  365. mod_timer(&pInfo->tmr, jiffies + R3964_TO_QVZ);
  366. } else {
  367. TRACE_PE("transmission failed after %d retries",
  368. R3964_MAX_RETRIES);
  369. remove_from_tx_queue(pInfo, R3964_TX_FAIL);
  370. put_char(pInfo, NAK);
  371. flush(pInfo);
  372. pInfo->state = R3964_IDLE;
  373. trigger_transmit(pInfo);
  374. }
  375. }
  376. static void transmit_block(struct r3964_info *pInfo)
  377. {
  378. struct tty_struct *tty = pInfo->tty;
  379. struct r3964_block_header *pBlock = pInfo->tx_first;
  380. int room = 0;
  381. if ((tty == NULL) || (pBlock == NULL)) {
  382. return;
  383. }
  384. if (tty->driver->write_room)
  385. room = tty->driver->write_room(tty);
  386. TRACE_PS("transmit_block %p, room %d, length %d",
  387. pBlock, room, pBlock->length);
  388. while (pInfo->tx_position < pBlock->length) {
  389. if (room < 2)
  390. break;
  391. if (pBlock->data[pInfo->tx_position] == DLE) {
  392. /* send additional DLE char: */
  393. put_char(pInfo, DLE);
  394. }
  395. put_char(pInfo, pBlock->data[pInfo->tx_position++]);
  396. room--;
  397. }
  398. if ((pInfo->tx_position == pBlock->length) && (room >= 3)) {
  399. put_char(pInfo, DLE);
  400. put_char(pInfo, ETX);
  401. if (pInfo->flags & R3964_BCC) {
  402. put_char(pInfo, pInfo->bcc);
  403. }
  404. pInfo->state = R3964_WAIT_FOR_TX_ACK;
  405. mod_timer(&pInfo->tmr, jiffies + R3964_TO_QVZ);
  406. }
  407. flush(pInfo);
  408. }
  409. static void on_receive_block(struct r3964_info *pInfo)
  410. {
  411. unsigned int length;
  412. struct r3964_client_info *pClient;
  413. struct r3964_block_header *pBlock;
  414. length = pInfo->rx_position;
  415. /* compare byte checksum characters: */
  416. if (pInfo->flags & R3964_BCC) {
  417. if (pInfo->bcc != pInfo->last_rx) {
  418. TRACE_PE("checksum error - got %x but expected %x",
  419. pInfo->last_rx, pInfo->bcc);
  420. pInfo->flags |= R3964_CHECKSUM;
  421. }
  422. }
  423. /* check for errors (parity, overrun,...): */
  424. if (pInfo->flags & R3964_ERROR) {
  425. TRACE_PE("on_receive_block - transmission failed error %x",
  426. pInfo->flags & R3964_ERROR);
  427. put_char(pInfo, NAK);
  428. flush(pInfo);
  429. if (pInfo->nRetry < R3964_MAX_RETRIES) {
  430. pInfo->state = R3964_WAIT_FOR_RX_REPEAT;
  431. pInfo->nRetry++;
  432. mod_timer(&pInfo->tmr, jiffies + R3964_TO_RX_PANIC);
  433. } else {
  434. TRACE_PE("on_receive_block - failed after max retries");
  435. pInfo->state = R3964_IDLE;
  436. }
  437. return;
  438. }
  439. /* received block; submit DLE: */
  440. put_char(pInfo, DLE);
  441. flush(pInfo);
  442. del_timer_sync(&pInfo->tmr);
  443. TRACE_PS(" rx success: got %d chars", length);
  444. /* prepare struct r3964_block_header: */
  445. pBlock = kmalloc(length + sizeof(struct r3964_block_header),
  446. GFP_KERNEL);
  447. TRACE_M("on_receive_block - kmalloc %p", pBlock);
  448. if (pBlock == NULL)
  449. return;
  450. pBlock->length = length;
  451. pBlock->data = ((unsigned char *)pBlock) +
  452. sizeof(struct r3964_block_header);
  453. pBlock->locks = 0;
  454. pBlock->next = NULL;
  455. pBlock->owner = NULL;
  456. memcpy(pBlock->data, pInfo->rx_buf, length);
  457. /* queue block into rx_queue: */
  458. add_rx_queue(pInfo, pBlock);
  459. /* notify attached client processes: */
  460. for (pClient = pInfo->firstClient; pClient; pClient = pClient->next) {
  461. if (pClient->sig_flags & R3964_SIG_DATA) {
  462. add_msg(pClient, R3964_MSG_DATA, length, R3964_OK,
  463. pBlock);
  464. }
  465. }
  466. wake_up_interruptible(&pInfo->read_wait);
  467. pInfo->state = R3964_IDLE;
  468. trigger_transmit(pInfo);
  469. }
  470. static void receive_char(struct r3964_info *pInfo, const unsigned char c)
  471. {
  472. switch (pInfo->state) {
  473. case R3964_TX_REQUEST:
  474. if (c == DLE) {
  475. TRACE_PS("TX_REQUEST - got DLE");
  476. pInfo->state = R3964_TRANSMITTING;
  477. pInfo->tx_position = 0;
  478. transmit_block(pInfo);
  479. } else if (c == STX) {
  480. if (pInfo->nRetry == 0) {
  481. TRACE_PE("TX_REQUEST - init conflict");
  482. if (pInfo->priority == R3964_SLAVE) {
  483. goto start_receiving;
  484. }
  485. } else {
  486. TRACE_PE("TX_REQUEST - secondary init "
  487. "conflict!? Switching to SLAVE mode "
  488. "for next rx.");
  489. goto start_receiving;
  490. }
  491. } else {
  492. TRACE_PE("TX_REQUEST - char != DLE: %x", c);
  493. retry_transmit(pInfo);
  494. }
  495. break;
  496. case R3964_TRANSMITTING:
  497. if (c == NAK) {
  498. TRACE_PE("TRANSMITTING - got NAK");
  499. retry_transmit(pInfo);
  500. } else {
  501. TRACE_PE("TRANSMITTING - got invalid char");
  502. pInfo->state = R3964_WAIT_ZVZ_BEFORE_TX_RETRY;
  503. mod_timer(&pInfo->tmr, jiffies + R3964_TO_ZVZ);
  504. }
  505. break;
  506. case R3964_WAIT_FOR_TX_ACK:
  507. if (c == DLE) {
  508. TRACE_PS("WAIT_FOR_TX_ACK - got DLE");
  509. remove_from_tx_queue(pInfo, R3964_OK);
  510. pInfo->state = R3964_IDLE;
  511. trigger_transmit(pInfo);
  512. } else {
  513. retry_transmit(pInfo);
  514. }
  515. break;
  516. case R3964_WAIT_FOR_RX_REPEAT:
  517. /* FALLTROUGH */
  518. case R3964_IDLE:
  519. if (c == STX) {
  520. /* Prevent rx_queue from overflow: */
  521. if (pInfo->blocks_in_rx_queue >=
  522. R3964_MAX_BLOCKS_IN_RX_QUEUE) {
  523. TRACE_PE("IDLE - got STX but no space in "
  524. "rx_queue!");
  525. pInfo->state = R3964_WAIT_FOR_RX_BUF;
  526. mod_timer(&pInfo->tmr,
  527. jiffies + R3964_TO_NO_BUF);
  528. break;
  529. }
  530. start_receiving:
  531. /* Ok, start receiving: */
  532. TRACE_PS("IDLE - got STX");
  533. pInfo->rx_position = 0;
  534. pInfo->last_rx = 0;
  535. pInfo->flags &= ~R3964_ERROR;
  536. pInfo->state = R3964_RECEIVING;
  537. mod_timer(&pInfo->tmr, jiffies + R3964_TO_ZVZ);
  538. pInfo->nRetry = 0;
  539. put_char(pInfo, DLE);
  540. flush(pInfo);
  541. pInfo->bcc = 0;
  542. }
  543. break;
  544. case R3964_RECEIVING:
  545. if (pInfo->rx_position < RX_BUF_SIZE) {
  546. pInfo->bcc ^= c;
  547. if (c == DLE) {
  548. if (pInfo->last_rx == DLE) {
  549. pInfo->last_rx = 0;
  550. goto char_to_buf;
  551. }
  552. pInfo->last_rx = DLE;
  553. break;
  554. } else if ((c == ETX) && (pInfo->last_rx == DLE)) {
  555. if (pInfo->flags & R3964_BCC) {
  556. pInfo->state = R3964_WAIT_FOR_BCC;
  557. mod_timer(&pInfo->tmr,
  558. jiffies + R3964_TO_ZVZ);
  559. } else {
  560. on_receive_block(pInfo);
  561. }
  562. } else {
  563. pInfo->last_rx = c;
  564. char_to_buf:
  565. pInfo->rx_buf[pInfo->rx_position++] = c;
  566. mod_timer(&pInfo->tmr, jiffies + R3964_TO_ZVZ);
  567. }
  568. }
  569. /* else: overflow-msg? BUF_SIZE>MTU; should not happen? */
  570. break;
  571. case R3964_WAIT_FOR_BCC:
  572. pInfo->last_rx = c;
  573. on_receive_block(pInfo);
  574. break;
  575. }
  576. }
  577. static void receive_error(struct r3964_info *pInfo, const char flag)
  578. {
  579. switch (flag) {
  580. case TTY_NORMAL:
  581. break;
  582. case TTY_BREAK:
  583. TRACE_PE("received break");
  584. pInfo->flags |= R3964_BREAK;
  585. break;
  586. case TTY_PARITY:
  587. TRACE_PE("parity error");
  588. pInfo->flags |= R3964_PARITY;
  589. break;
  590. case TTY_FRAME:
  591. TRACE_PE("frame error");
  592. pInfo->flags |= R3964_FRAME;
  593. break;
  594. case TTY_OVERRUN:
  595. TRACE_PE("frame overrun");
  596. pInfo->flags |= R3964_OVERRUN;
  597. break;
  598. default:
  599. TRACE_PE("receive_error - unknown flag %d", flag);
  600. pInfo->flags |= R3964_UNKNOWN;
  601. break;
  602. }
  603. }
  604. static void on_timeout(unsigned long priv)
  605. {
  606. struct r3964_info *pInfo = (void *)priv;
  607. switch (pInfo->state) {
  608. case R3964_TX_REQUEST:
  609. TRACE_PE("TX_REQUEST - timeout");
  610. retry_transmit(pInfo);
  611. break;
  612. case R3964_WAIT_ZVZ_BEFORE_TX_RETRY:
  613. put_char(pInfo, NAK);
  614. flush(pInfo);
  615. retry_transmit(pInfo);
  616. break;
  617. case R3964_WAIT_FOR_TX_ACK:
  618. TRACE_PE("WAIT_FOR_TX_ACK - timeout");
  619. retry_transmit(pInfo);
  620. break;
  621. case R3964_WAIT_FOR_RX_BUF:
  622. TRACE_PE("WAIT_FOR_RX_BUF - timeout");
  623. put_char(pInfo, NAK);
  624. flush(pInfo);
  625. pInfo->state = R3964_IDLE;
  626. break;
  627. case R3964_RECEIVING:
  628. TRACE_PE("RECEIVING - timeout after %d chars",
  629. pInfo->rx_position);
  630. put_char(pInfo, NAK);
  631. flush(pInfo);
  632. pInfo->state = R3964_IDLE;
  633. break;
  634. case R3964_WAIT_FOR_RX_REPEAT:
  635. TRACE_PE("WAIT_FOR_RX_REPEAT - timeout");
  636. pInfo->state = R3964_IDLE;
  637. break;
  638. case R3964_WAIT_FOR_BCC:
  639. TRACE_PE("WAIT_FOR_BCC - timeout");
  640. put_char(pInfo, NAK);
  641. flush(pInfo);
  642. pInfo->state = R3964_IDLE;
  643. break;
  644. }
  645. }
  646. static struct r3964_client_info *findClient(struct r3964_info *pInfo,
  647. struct pid *pid)
  648. {
  649. struct r3964_client_info *pClient;
  650. for (pClient = pInfo->firstClient; pClient; pClient = pClient->next) {
  651. if (pClient->pid == pid) {
  652. return pClient;
  653. }
  654. }
  655. return NULL;
  656. }
  657. static int enable_signals(struct r3964_info *pInfo, struct pid *pid, int arg)
  658. {
  659. struct r3964_client_info *pClient;
  660. struct r3964_client_info **ppClient;
  661. struct r3964_message *pMsg;
  662. if ((arg & R3964_SIG_ALL) == 0) {
  663. /* Remove client from client list */
  664. for (ppClient = &pInfo->firstClient; *ppClient;
  665. ppClient = &(*ppClient)->next) {
  666. pClient = *ppClient;
  667. if (pClient->pid == pid) {
  668. TRACE_PS("removing client %d from client list",
  669. pid_nr(pid));
  670. *ppClient = pClient->next;
  671. while (pClient->msg_count) {
  672. pMsg = remove_msg(pInfo, pClient);
  673. if (pMsg) {
  674. kfree(pMsg);
  675. TRACE_M("enable_signals - msg "
  676. "kfree %p", pMsg);
  677. }
  678. }
  679. put_pid(pClient->pid);
  680. kfree(pClient);
  681. TRACE_M("enable_signals - kfree %p", pClient);
  682. return 0;
  683. }
  684. }
  685. return -EINVAL;
  686. } else {
  687. pClient = findClient(pInfo, pid);
  688. if (pClient) {
  689. /* update signal options */
  690. pClient->sig_flags = arg;
  691. } else {
  692. /* add client to client list */
  693. pClient = kmalloc(sizeof(struct r3964_client_info),
  694. GFP_KERNEL);
  695. TRACE_M("enable_signals - kmalloc %p", pClient);
  696. if (pClient == NULL)
  697. return -ENOMEM;
  698. TRACE_PS("add client %d to client list", pid_nr(pid));
  699. spin_lock_init(&pClient->lock);
  700. pClient->sig_flags = arg;
  701. pClient->pid = get_pid(pid);
  702. pClient->next = pInfo->firstClient;
  703. pClient->first_msg = NULL;
  704. pClient->last_msg = NULL;
  705. pClient->next_block_to_read = NULL;
  706. pClient->msg_count = 0;
  707. pInfo->firstClient = pClient;
  708. }
  709. }
  710. return 0;
  711. }
  712. static int read_telegram(struct r3964_info *pInfo, struct pid *pid,
  713. unsigned char __user * buf)
  714. {
  715. struct r3964_client_info *pClient;
  716. struct r3964_block_header *block;
  717. if (!buf) {
  718. return -EINVAL;
  719. }
  720. pClient = findClient(pInfo, pid);
  721. if (pClient == NULL) {
  722. return -EINVAL;
  723. }
  724. block = pClient->next_block_to_read;
  725. if (!block) {
  726. return 0;
  727. } else {
  728. if (copy_to_user(buf, block->data, block->length))
  729. return -EFAULT;
  730. remove_client_block(pInfo, pClient);
  731. return block->length;
  732. }
  733. return -EINVAL;
  734. }
  735. static void add_msg(struct r3964_client_info *pClient, int msg_id, int arg,
  736. int error_code, struct r3964_block_header *pBlock)
  737. {
  738. struct r3964_message *pMsg;
  739. unsigned long flags;
  740. if (pClient->msg_count < R3964_MAX_MSG_COUNT - 1) {
  741. queue_the_message:
  742. pMsg = kmalloc(sizeof(struct r3964_message),
  743. error_code ? GFP_ATOMIC : GFP_KERNEL);
  744. TRACE_M("add_msg - kmalloc %p", pMsg);
  745. if (pMsg == NULL) {
  746. return;
  747. }
  748. spin_lock_irqsave(&pClient->lock, flags);
  749. pMsg->msg_id = msg_id;
  750. pMsg->arg = arg;
  751. pMsg->error_code = error_code;
  752. pMsg->block = pBlock;
  753. pMsg->next = NULL;
  754. if (pClient->last_msg == NULL) {
  755. pClient->first_msg = pClient->last_msg = pMsg;
  756. } else {
  757. pClient->last_msg->next = pMsg;
  758. pClient->last_msg = pMsg;
  759. }
  760. pClient->msg_count++;
  761. if (pBlock != NULL) {
  762. pBlock->locks++;
  763. }
  764. spin_unlock_irqrestore(&pClient->lock, flags);
  765. } else {
  766. if ((pClient->last_msg->msg_id == R3964_MSG_ACK)
  767. && (pClient->last_msg->error_code == R3964_OVERFLOW)) {
  768. pClient->last_msg->arg++;
  769. TRACE_PE("add_msg - inc prev OVERFLOW-msg");
  770. } else {
  771. msg_id = R3964_MSG_ACK;
  772. arg = 0;
  773. error_code = R3964_OVERFLOW;
  774. pBlock = NULL;
  775. TRACE_PE("add_msg - queue OVERFLOW-msg");
  776. goto queue_the_message;
  777. }
  778. }
  779. /* Send SIGIO signal to client process: */
  780. if (pClient->sig_flags & R3964_USE_SIGIO) {
  781. kill_pid(pClient->pid, SIGIO, 1);
  782. }
  783. }
  784. static struct r3964_message *remove_msg(struct r3964_info *pInfo,
  785. struct r3964_client_info *pClient)
  786. {
  787. struct r3964_message *pMsg = NULL;
  788. unsigned long flags;
  789. if (pClient->first_msg) {
  790. spin_lock_irqsave(&pClient->lock, flags);
  791. pMsg = pClient->first_msg;
  792. pClient->first_msg = pMsg->next;
  793. if (pClient->first_msg == NULL) {
  794. pClient->last_msg = NULL;
  795. }
  796. pClient->msg_count--;
  797. if (pMsg->block) {
  798. remove_client_block(pInfo, pClient);
  799. pClient->next_block_to_read = pMsg->block;
  800. }
  801. spin_unlock_irqrestore(&pClient->lock, flags);
  802. }
  803. return pMsg;
  804. }
  805. static void remove_client_block(struct r3964_info *pInfo,
  806. struct r3964_client_info *pClient)
  807. {
  808. struct r3964_block_header *block;
  809. TRACE_PS("remove_client_block PID %d", pid_nr(pClient->pid));
  810. block = pClient->next_block_to_read;
  811. if (block) {
  812. block->locks--;
  813. if (block->locks == 0) {
  814. remove_from_rx_queue(pInfo, block);
  815. }
  816. }
  817. pClient->next_block_to_read = NULL;
  818. }
  819. /*************************************************************
  820. * Line discipline routines
  821. *************************************************************/
  822. static int r3964_open(struct tty_struct *tty)
  823. {
  824. struct r3964_info *pInfo;
  825. TRACE_L("open");
  826. TRACE_L("tty=%p, PID=%d, disc_data=%p",
  827. tty, current->pid, tty->disc_data);
  828. pInfo = kmalloc(sizeof(struct r3964_info), GFP_KERNEL);
  829. TRACE_M("r3964_open - info kmalloc %p", pInfo);
  830. if (!pInfo) {
  831. printk(KERN_ERR "r3964: failed to alloc info structure\n");
  832. return -ENOMEM;
  833. }
  834. pInfo->rx_buf = kmalloc(RX_BUF_SIZE, GFP_KERNEL);
  835. TRACE_M("r3964_open - rx_buf kmalloc %p", pInfo->rx_buf);
  836. if (!pInfo->rx_buf) {
  837. printk(KERN_ERR "r3964: failed to alloc receive buffer\n");
  838. kfree(pInfo);
  839. TRACE_M("r3964_open - info kfree %p", pInfo);
  840. return -ENOMEM;
  841. }
  842. pInfo->tx_buf = kmalloc(TX_BUF_SIZE, GFP_KERNEL);
  843. TRACE_M("r3964_open - tx_buf kmalloc %p", pInfo->tx_buf);
  844. if (!pInfo->tx_buf) {
  845. printk(KERN_ERR "r3964: failed to alloc transmit buffer\n");
  846. kfree(pInfo->rx_buf);
  847. TRACE_M("r3964_open - rx_buf kfree %p", pInfo->rx_buf);
  848. kfree(pInfo);
  849. TRACE_M("r3964_open - info kfree %p", pInfo);
  850. return -ENOMEM;
  851. }
  852. spin_lock_init(&pInfo->lock);
  853. pInfo->tty = tty;
  854. init_waitqueue_head(&pInfo->read_wait);
  855. pInfo->priority = R3964_MASTER;
  856. pInfo->rx_first = pInfo->rx_last = NULL;
  857. pInfo->tx_first = pInfo->tx_last = NULL;
  858. pInfo->rx_position = 0;
  859. pInfo->tx_position = 0;
  860. pInfo->last_rx = 0;
  861. pInfo->blocks_in_rx_queue = 0;
  862. pInfo->firstClient = NULL;
  863. pInfo->state = R3964_IDLE;
  864. pInfo->flags = R3964_DEBUG;
  865. pInfo->nRetry = 0;
  866. tty->disc_data = pInfo;
  867. tty->receive_room = 65536;
  868. setup_timer(&pInfo->tmr, on_timeout, (unsigned long)pInfo);
  869. return 0;
  870. }
  871. static void r3964_close(struct tty_struct *tty)
  872. {
  873. struct r3964_info *pInfo = (struct r3964_info *)tty->disc_data;
  874. struct r3964_client_info *pClient, *pNext;
  875. struct r3964_message *pMsg;
  876. struct r3964_block_header *pHeader, *pNextHeader;
  877. unsigned long flags;
  878. TRACE_L("close");
  879. /*
  880. * Make sure that our task queue isn't activated. If it
  881. * is, take it out of the linked list.
  882. */
  883. del_timer_sync(&pInfo->tmr);
  884. /* Remove client-structs and message queues: */
  885. pClient = pInfo->firstClient;
  886. while (pClient) {
  887. pNext = pClient->next;
  888. while (pClient->msg_count) {
  889. pMsg = remove_msg(pInfo, pClient);
  890. if (pMsg) {
  891. kfree(pMsg);
  892. TRACE_M("r3964_close - msg kfree %p", pMsg);
  893. }
  894. }
  895. put_pid(pClient->pid);
  896. kfree(pClient);
  897. TRACE_M("r3964_close - client kfree %p", pClient);
  898. pClient = pNext;
  899. }
  900. /* Remove jobs from tx_queue: */
  901. spin_lock_irqsave(&pInfo->lock, flags);
  902. pHeader = pInfo->tx_first;
  903. pInfo->tx_first = pInfo->tx_last = NULL;
  904. spin_unlock_irqrestore(&pInfo->lock, flags);
  905. while (pHeader) {
  906. pNextHeader = pHeader->next;
  907. kfree(pHeader);
  908. pHeader = pNextHeader;
  909. }
  910. /* Free buffers: */
  911. wake_up_interruptible(&pInfo->read_wait);
  912. kfree(pInfo->rx_buf);
  913. TRACE_M("r3964_close - rx_buf kfree %p", pInfo->rx_buf);
  914. kfree(pInfo->tx_buf);
  915. TRACE_M("r3964_close - tx_buf kfree %p", pInfo->tx_buf);
  916. kfree(pInfo);
  917. TRACE_M("r3964_close - info kfree %p", pInfo);
  918. }
  919. static ssize_t r3964_read(struct tty_struct *tty, struct file *file,
  920. unsigned char __user * buf, size_t nr)
  921. {
  922. struct r3964_info *pInfo = (struct r3964_info *)tty->disc_data;
  923. struct r3964_client_info *pClient;
  924. struct r3964_message *pMsg;
  925. struct r3964_client_message theMsg;
  926. DECLARE_WAITQUEUE(wait, current);
  927. int count;
  928. TRACE_L("read()");
  929. pClient = findClient(pInfo, task_pid(current));
  930. if (pClient) {
  931. pMsg = remove_msg(pInfo, pClient);
  932. if (pMsg == NULL) {
  933. /* no messages available. */
  934. if (file->f_flags & O_NONBLOCK) {
  935. return -EAGAIN;
  936. }
  937. /* block until there is a message: */
  938. add_wait_queue(&pInfo->read_wait, &wait);
  939. repeat:
  940. current->state = TASK_INTERRUPTIBLE;
  941. pMsg = remove_msg(pInfo, pClient);
  942. if (!pMsg && !signal_pending(current)) {
  943. schedule();
  944. goto repeat;
  945. }
  946. current->state = TASK_RUNNING;
  947. remove_wait_queue(&pInfo->read_wait, &wait);
  948. }
  949. /* If we still haven't got a message, we must have been signalled */
  950. if (!pMsg)
  951. return -EINTR;
  952. /* deliver msg to client process: */
  953. theMsg.msg_id = pMsg->msg_id;
  954. theMsg.arg = pMsg->arg;
  955. theMsg.error_code = pMsg->error_code;
  956. count = sizeof(struct r3964_client_message);
  957. kfree(pMsg);
  958. TRACE_M("r3964_read - msg kfree %p", pMsg);
  959. if (copy_to_user(buf, &theMsg, count))
  960. return -EFAULT;
  961. TRACE_PS("read - return %d", count);
  962. return count;
  963. }
  964. return -EPERM;
  965. }
  966. static ssize_t r3964_write(struct tty_struct *tty, struct file *file,
  967. const unsigned char *data, size_t count)
  968. {
  969. struct r3964_info *pInfo = (struct r3964_info *)tty->disc_data;
  970. struct r3964_block_header *pHeader;
  971. struct r3964_client_info *pClient;
  972. unsigned char *new_data;
  973. TRACE_L("write request, %d characters", count);
  974. /*
  975. * Verify the pointers
  976. */
  977. if (!pInfo)
  978. return -EIO;
  979. /*
  980. * Ensure that the caller does not wish to send too much.
  981. */
  982. if (count > R3964_MTU) {
  983. if (pInfo->flags & R3964_DEBUG) {
  984. TRACE_L(KERN_WARNING "r3964_write: truncating user "
  985. "packet from %u to mtu %d", count, R3964_MTU);
  986. }
  987. count = R3964_MTU;
  988. }
  989. /*
  990. * Allocate a buffer for the data and copy it from the buffer with header prepended
  991. */
  992. new_data = kmalloc(count + sizeof(struct r3964_block_header),
  993. GFP_KERNEL);
  994. TRACE_M("r3964_write - kmalloc %p", new_data);
  995. if (new_data == NULL) {
  996. if (pInfo->flags & R3964_DEBUG) {
  997. printk(KERN_ERR "r3964_write: no memory\n");
  998. }
  999. return -ENOSPC;
  1000. }
  1001. pHeader = (struct r3964_block_header *)new_data;
  1002. pHeader->data = new_data + sizeof(struct r3964_block_header);
  1003. pHeader->length = count;
  1004. pHeader->locks = 0;
  1005. pHeader->owner = NULL;
  1006. pClient = findClient(pInfo, task_pid(current));
  1007. if (pClient) {
  1008. pHeader->owner = pClient;
  1009. }
  1010. memcpy(pHeader->data, data, count); /* We already verified this */
  1011. if (pInfo->flags & R3964_DEBUG) {
  1012. dump_block(pHeader->data, count);
  1013. }
  1014. /*
  1015. * Add buffer to transmit-queue:
  1016. */
  1017. add_tx_queue(pInfo, pHeader);
  1018. trigger_transmit(pInfo);
  1019. return 0;
  1020. }
  1021. static int r3964_ioctl(struct tty_struct *tty, struct file *file,
  1022. unsigned int cmd, unsigned long arg)
  1023. {
  1024. struct r3964_info *pInfo = (struct r3964_info *)tty->disc_data;
  1025. if (pInfo == NULL)
  1026. return -EINVAL;
  1027. switch (cmd) {
  1028. case R3964_ENABLE_SIGNALS:
  1029. return enable_signals(pInfo, task_pid(current), arg);
  1030. case R3964_SETPRIORITY:
  1031. if (arg < R3964_MASTER || arg > R3964_SLAVE)
  1032. return -EINVAL;
  1033. pInfo->priority = arg & 0xff;
  1034. return 0;
  1035. case R3964_USE_BCC:
  1036. if (arg)
  1037. pInfo->flags |= R3964_BCC;
  1038. else
  1039. pInfo->flags &= ~R3964_BCC;
  1040. return 0;
  1041. case R3964_READ_TELEGRAM:
  1042. return read_telegram(pInfo, task_pid(current),
  1043. (unsigned char __user *)arg);
  1044. default:
  1045. return -ENOIOCTLCMD;
  1046. }
  1047. }
  1048. static void r3964_set_termios(struct tty_struct *tty, struct ktermios *old)
  1049. {
  1050. TRACE_L("set_termios");
  1051. }
  1052. /* Called without the kernel lock held - fine */
  1053. static unsigned int r3964_poll(struct tty_struct *tty, struct file *file,
  1054. struct poll_table_struct *wait)
  1055. {
  1056. struct r3964_info *pInfo = (struct r3964_info *)tty->disc_data;
  1057. struct r3964_client_info *pClient;
  1058. struct r3964_message *pMsg = NULL;
  1059. unsigned long flags;
  1060. int result = POLLOUT;
  1061. TRACE_L("POLL");
  1062. pClient = findClient(pInfo, task_pid(current));
  1063. if (pClient) {
  1064. poll_wait(file, &pInfo->read_wait, wait);
  1065. spin_lock_irqsave(&pInfo->lock, flags);
  1066. pMsg = pClient->first_msg;
  1067. spin_unlock_irqrestore(&pInfo->lock, flags);
  1068. if (pMsg)
  1069. result |= POLLIN | POLLRDNORM;
  1070. } else {
  1071. result = -EINVAL;
  1072. }
  1073. return result;
  1074. }
  1075. static void r3964_receive_buf(struct tty_struct *tty, const unsigned char *cp,
  1076. char *fp, int count)
  1077. {
  1078. struct r3964_info *pInfo = (struct r3964_info *)tty->disc_data;
  1079. const unsigned char *p;
  1080. char *f, flags = 0;
  1081. int i;
  1082. for (i = count, p = cp, f = fp; i; i--, p++) {
  1083. if (f)
  1084. flags = *f++;
  1085. if (flags == TTY_NORMAL) {
  1086. receive_char(pInfo, *p);
  1087. } else {
  1088. receive_error(pInfo, flags);
  1089. }
  1090. }
  1091. }
  1092. MODULE_LICENSE("GPL");
  1093. MODULE_ALIAS_LDISC(N_R3964);