lapb_in.c 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701
  1. /*
  2. * LAPB release 002
  3. *
  4. * This code REQUIRES 2.1.15 or higher/ NET3.038
  5. *
  6. * This module:
  7. * This module is free software; you can redistribute it and/or
  8. * modify it under the terms of the GNU General Public License
  9. * as published by the Free Software Foundation; either version
  10. * 2 of the License, or (at your option) any later version.
  11. *
  12. * History
  13. * LAPB 001 Jonathan Naulor Started Coding
  14. * LAPB 002 Jonathan Naylor New timer architecture.
  15. * 2000-10-29 Henner Eisen lapb_data_indication() return status.
  16. */
  17. #include <linux/errno.h>
  18. #include <linux/types.h>
  19. #include <linux/socket.h>
  20. #include <linux/in.h>
  21. #include <linux/kernel.h>
  22. #include <linux/timer.h>
  23. #include <linux/string.h>
  24. #include <linux/sockios.h>
  25. #include <linux/net.h>
  26. #include <linux/inet.h>
  27. #include <linux/netdevice.h>
  28. #include <linux/skbuff.h>
  29. #include <linux/slab.h>
  30. #include <net/sock.h>
  31. #include <asm/uaccess.h>
  32. #include <linux/fcntl.h>
  33. #include <linux/mm.h>
  34. #include <linux/interrupt.h>
  35. #include <net/lapb.h>
  36. /*
  37. * State machine for state 0, Disconnected State.
  38. * The handling of the timer(s) is in file lapb_timer.c.
  39. */
  40. static void lapb_state0_machine(struct lapb_cb *lapb, struct sk_buff *skb,
  41. struct lapb_frame *frame)
  42. {
  43. switch (frame->type) {
  44. case LAPB_SABM:
  45. #if LAPB_DEBUG > 1
  46. printk(KERN_DEBUG "lapb: (%p) S0 RX SABM(%d)\n",
  47. lapb->dev, frame->pf);
  48. #endif
  49. if (lapb->mode & LAPB_EXTENDED) {
  50. #if LAPB_DEBUG > 1
  51. printk(KERN_DEBUG "lapb: (%p) S0 TX DM(%d)\n",
  52. lapb->dev, frame->pf);
  53. #endif
  54. lapb_send_control(lapb, LAPB_DM, frame->pf,
  55. LAPB_RESPONSE);
  56. } else {
  57. #if LAPB_DEBUG > 1
  58. printk(KERN_DEBUG "lapb: (%p) S0 TX UA(%d)\n",
  59. lapb->dev, frame->pf);
  60. #endif
  61. #if LAPB_DEBUG > 0
  62. printk(KERN_DEBUG "lapb: (%p) S0 -> S3\n", lapb->dev);
  63. #endif
  64. lapb_send_control(lapb, LAPB_UA, frame->pf,
  65. LAPB_RESPONSE);
  66. lapb_stop_t1timer(lapb);
  67. lapb_stop_t2timer(lapb);
  68. lapb->state = LAPB_STATE_3;
  69. lapb->condition = 0x00;
  70. lapb->n2count = 0;
  71. lapb->vs = 0;
  72. lapb->vr = 0;
  73. lapb->va = 0;
  74. lapb_connect_indication(lapb, LAPB_OK);
  75. }
  76. break;
  77. case LAPB_SABME:
  78. #if LAPB_DEBUG > 1
  79. printk(KERN_DEBUG "lapb: (%p) S0 RX SABME(%d)\n",
  80. lapb->dev, frame->pf);
  81. #endif
  82. if (lapb->mode & LAPB_EXTENDED) {
  83. #if LAPB_DEBUG > 1
  84. printk(KERN_DEBUG "lapb: (%p) S0 TX UA(%d)\n",
  85. lapb->dev, frame->pf);
  86. #endif
  87. #if LAPB_DEBUG > 0
  88. printk(KERN_DEBUG "lapb: (%p) S0 -> S3\n", lapb->dev);
  89. #endif
  90. lapb_send_control(lapb, LAPB_UA, frame->pf,
  91. LAPB_RESPONSE);
  92. lapb_stop_t1timer(lapb);
  93. lapb_stop_t2timer(lapb);
  94. lapb->state = LAPB_STATE_3;
  95. lapb->condition = 0x00;
  96. lapb->n2count = 0;
  97. lapb->vs = 0;
  98. lapb->vr = 0;
  99. lapb->va = 0;
  100. lapb_connect_indication(lapb, LAPB_OK);
  101. } else {
  102. #if LAPB_DEBUG > 1
  103. printk(KERN_DEBUG "lapb: (%p) S0 TX DM(%d)\n",
  104. lapb->dev, frame->pf);
  105. #endif
  106. lapb_send_control(lapb, LAPB_DM, frame->pf,
  107. LAPB_RESPONSE);
  108. }
  109. break;
  110. case LAPB_DISC:
  111. #if LAPB_DEBUG > 1
  112. printk(KERN_DEBUG "lapb: (%p) S0 RX DISC(%d)\n",
  113. lapb->dev, frame->pf);
  114. printk(KERN_DEBUG "lapb: (%p) S0 TX UA(%d)\n",
  115. lapb->dev, frame->pf);
  116. #endif
  117. lapb_send_control(lapb, LAPB_UA, frame->pf, LAPB_RESPONSE);
  118. break;
  119. default:
  120. break;
  121. }
  122. kfree_skb(skb);
  123. }
  124. /*
  125. * State machine for state 1, Awaiting Connection State.
  126. * The handling of the timer(s) is in file lapb_timer.c.
  127. */
  128. static void lapb_state1_machine(struct lapb_cb *lapb, struct sk_buff *skb,
  129. struct lapb_frame *frame)
  130. {
  131. switch (frame->type) {
  132. case LAPB_SABM:
  133. #if LAPB_DEBUG > 1
  134. printk(KERN_DEBUG "lapb: (%p) S1 RX SABM(%d)\n",
  135. lapb->dev, frame->pf);
  136. #endif
  137. if (lapb->mode & LAPB_EXTENDED) {
  138. #if LAPB_DEBUG > 1
  139. printk(KERN_DEBUG "lapb: (%p) S1 TX DM(%d)\n",
  140. lapb->dev, frame->pf);
  141. #endif
  142. lapb_send_control(lapb, LAPB_DM, frame->pf,
  143. LAPB_RESPONSE);
  144. } else {
  145. #if LAPB_DEBUG > 1
  146. printk(KERN_DEBUG "lapb: (%p) S1 TX UA(%d)\n",
  147. lapb->dev, frame->pf);
  148. #endif
  149. lapb_send_control(lapb, LAPB_UA, frame->pf,
  150. LAPB_RESPONSE);
  151. }
  152. break;
  153. case LAPB_SABME:
  154. #if LAPB_DEBUG > 1
  155. printk(KERN_DEBUG "lapb: (%p) S1 RX SABME(%d)\n",
  156. lapb->dev, frame->pf);
  157. #endif
  158. if (lapb->mode & LAPB_EXTENDED) {
  159. #if LAPB_DEBUG > 1
  160. printk(KERN_DEBUG "lapb: (%p) S1 TX UA(%d)\n",
  161. lapb->dev, frame->pf);
  162. #endif
  163. lapb_send_control(lapb, LAPB_UA, frame->pf,
  164. LAPB_RESPONSE);
  165. } else {
  166. #if LAPB_DEBUG > 1
  167. printk(KERN_DEBUG "lapb: (%p) S1 TX DM(%d)\n",
  168. lapb->dev, frame->pf);
  169. #endif
  170. lapb_send_control(lapb, LAPB_DM, frame->pf,
  171. LAPB_RESPONSE);
  172. }
  173. break;
  174. case LAPB_DISC:
  175. #if LAPB_DEBUG > 1
  176. printk(KERN_DEBUG "lapb: (%p) S1 RX DISC(%d)\n",
  177. lapb->dev, frame->pf);
  178. printk(KERN_DEBUG "lapb: (%p) S1 TX DM(%d)\n",
  179. lapb->dev, frame->pf);
  180. #endif
  181. lapb_send_control(lapb, LAPB_DM, frame->pf, LAPB_RESPONSE);
  182. break;
  183. case LAPB_UA:
  184. #if LAPB_DEBUG > 1
  185. printk(KERN_DEBUG "lapb: (%p) S1 RX UA(%d)\n",
  186. lapb->dev, frame->pf);
  187. #endif
  188. if (frame->pf) {
  189. #if LAPB_DEBUG > 0
  190. printk(KERN_DEBUG "lapb: (%p) S1 -> S3\n", lapb->dev);
  191. #endif
  192. lapb_stop_t1timer(lapb);
  193. lapb_stop_t2timer(lapb);
  194. lapb->state = LAPB_STATE_3;
  195. lapb->condition = 0x00;
  196. lapb->n2count = 0;
  197. lapb->vs = 0;
  198. lapb->vr = 0;
  199. lapb->va = 0;
  200. lapb_connect_confirmation(lapb, LAPB_OK);
  201. }
  202. break;
  203. case LAPB_DM:
  204. #if LAPB_DEBUG > 1
  205. printk(KERN_DEBUG "lapb: (%p) S1 RX DM(%d)\n",
  206. lapb->dev, frame->pf);
  207. #endif
  208. if (frame->pf) {
  209. #if LAPB_DEBUG > 0
  210. printk(KERN_DEBUG "lapb: (%p) S1 -> S0\n", lapb->dev);
  211. #endif
  212. lapb_clear_queues(lapb);
  213. lapb->state = LAPB_STATE_0;
  214. lapb_start_t1timer(lapb);
  215. lapb_stop_t2timer(lapb);
  216. lapb_disconnect_indication(lapb, LAPB_REFUSED);
  217. }
  218. break;
  219. }
  220. kfree_skb(skb);
  221. }
  222. /*
  223. * State machine for state 2, Awaiting Release State.
  224. * The handling of the timer(s) is in file lapb_timer.c
  225. */
  226. static void lapb_state2_machine(struct lapb_cb *lapb, struct sk_buff *skb,
  227. struct lapb_frame *frame)
  228. {
  229. switch (frame->type) {
  230. case LAPB_SABM:
  231. case LAPB_SABME:
  232. #if LAPB_DEBUG > 1
  233. printk(KERN_DEBUG "lapb: (%p) S2 RX {SABM,SABME}(%d)\n",
  234. lapb->dev, frame->pf);
  235. printk(KERN_DEBUG "lapb: (%p) S2 TX DM(%d)\n",
  236. lapb->dev, frame->pf);
  237. #endif
  238. lapb_send_control(lapb, LAPB_DM, frame->pf, LAPB_RESPONSE);
  239. break;
  240. case LAPB_DISC:
  241. #if LAPB_DEBUG > 1
  242. printk(KERN_DEBUG "lapb: (%p) S2 RX DISC(%d)\n",
  243. lapb->dev, frame->pf);
  244. printk(KERN_DEBUG "lapb: (%p) S2 TX UA(%d)\n",
  245. lapb->dev, frame->pf);
  246. #endif
  247. lapb_send_control(lapb, LAPB_UA, frame->pf, LAPB_RESPONSE);
  248. break;
  249. case LAPB_UA:
  250. #if LAPB_DEBUG > 1
  251. printk(KERN_DEBUG "lapb: (%p) S2 RX UA(%d)\n",
  252. lapb->dev, frame->pf);
  253. #endif
  254. if (frame->pf) {
  255. #if LAPB_DEBUG > 0
  256. printk(KERN_DEBUG "lapb: (%p) S2 -> S0\n", lapb->dev);
  257. #endif
  258. lapb->state = LAPB_STATE_0;
  259. lapb_start_t1timer(lapb);
  260. lapb_stop_t2timer(lapb);
  261. lapb_disconnect_confirmation(lapb, LAPB_OK);
  262. }
  263. break;
  264. case LAPB_DM:
  265. #if LAPB_DEBUG > 1
  266. printk(KERN_DEBUG "lapb: (%p) S2 RX DM(%d)\n",
  267. lapb->dev, frame->pf);
  268. #endif
  269. if (frame->pf) {
  270. #if LAPB_DEBUG > 0
  271. printk(KERN_DEBUG "lapb: (%p) S2 -> S0\n", lapb->dev);
  272. #endif
  273. lapb->state = LAPB_STATE_0;
  274. lapb_start_t1timer(lapb);
  275. lapb_stop_t2timer(lapb);
  276. lapb_disconnect_confirmation(lapb, LAPB_NOTCONNECTED);
  277. }
  278. break;
  279. case LAPB_I:
  280. case LAPB_REJ:
  281. case LAPB_RNR:
  282. case LAPB_RR:
  283. #if LAPB_DEBUG > 1
  284. printk(KERN_DEBUG "lapb: (%p) S2 RX {I,REJ,RNR,RR}(%d)\n",
  285. lapb->dev, frame->pf);
  286. printk(KERN_DEBUG "lapb: (%p) S2 RX DM(%d)\n",
  287. lapb->dev, frame->pf);
  288. #endif
  289. if (frame->pf)
  290. lapb_send_control(lapb, LAPB_DM, frame->pf,
  291. LAPB_RESPONSE);
  292. break;
  293. }
  294. kfree_skb(skb);
  295. }
  296. /*
  297. * State machine for state 3, Connected State.
  298. * The handling of the timer(s) is in file lapb_timer.c
  299. */
  300. static void lapb_state3_machine(struct lapb_cb *lapb, struct sk_buff *skb,
  301. struct lapb_frame *frame)
  302. {
  303. int queued = 0;
  304. int modulus = (lapb->mode & LAPB_EXTENDED) ? LAPB_EMODULUS :
  305. LAPB_SMODULUS;
  306. switch (frame->type) {
  307. case LAPB_SABM:
  308. #if LAPB_DEBUG > 1
  309. printk(KERN_DEBUG "lapb: (%p) S3 RX SABM(%d)\n",
  310. lapb->dev, frame->pf);
  311. #endif
  312. if (lapb->mode & LAPB_EXTENDED) {
  313. #if LAPB_DEBUG > 1
  314. printk(KERN_DEBUG "lapb: (%p) S3 TX DM(%d)\n",
  315. lapb->dev, frame->pf);
  316. #endif
  317. lapb_send_control(lapb, LAPB_DM, frame->pf,
  318. LAPB_RESPONSE);
  319. } else {
  320. #if LAPB_DEBUG > 1
  321. printk(KERN_DEBUG "lapb: (%p) S3 TX UA(%d)\n",
  322. lapb->dev, frame->pf);
  323. #endif
  324. lapb_send_control(lapb, LAPB_UA, frame->pf,
  325. LAPB_RESPONSE);
  326. lapb_stop_t1timer(lapb);
  327. lapb_stop_t2timer(lapb);
  328. lapb->condition = 0x00;
  329. lapb->n2count = 0;
  330. lapb->vs = 0;
  331. lapb->vr = 0;
  332. lapb->va = 0;
  333. lapb_requeue_frames(lapb);
  334. }
  335. break;
  336. case LAPB_SABME:
  337. #if LAPB_DEBUG > 1
  338. printk(KERN_DEBUG "lapb: (%p) S3 RX SABME(%d)\n",
  339. lapb->dev, frame->pf);
  340. #endif
  341. if (lapb->mode & LAPB_EXTENDED) {
  342. #if LAPB_DEBUG > 1
  343. printk(KERN_DEBUG "lapb: (%p) S3 TX UA(%d)\n",
  344. lapb->dev, frame->pf);
  345. #endif
  346. lapb_send_control(lapb, LAPB_UA, frame->pf,
  347. LAPB_RESPONSE);
  348. lapb_stop_t1timer(lapb);
  349. lapb_stop_t2timer(lapb);
  350. lapb->condition = 0x00;
  351. lapb->n2count = 0;
  352. lapb->vs = 0;
  353. lapb->vr = 0;
  354. lapb->va = 0;
  355. lapb_requeue_frames(lapb);
  356. } else {
  357. #if LAPB_DEBUG > 1
  358. printk(KERN_DEBUG "lapb: (%p) S3 TX DM(%d)\n",
  359. lapb->dev, frame->pf);
  360. #endif
  361. lapb_send_control(lapb, LAPB_DM, frame->pf,
  362. LAPB_RESPONSE);
  363. }
  364. break;
  365. case LAPB_DISC:
  366. #if LAPB_DEBUG > 1
  367. printk(KERN_DEBUG "lapb: (%p) S3 RX DISC(%d)\n",
  368. lapb->dev, frame->pf);
  369. #endif
  370. #if LAPB_DEBUG > 0
  371. printk(KERN_DEBUG "lapb: (%p) S3 -> S0\n", lapb->dev);
  372. #endif
  373. lapb_clear_queues(lapb);
  374. lapb_send_control(lapb, LAPB_UA, frame->pf, LAPB_RESPONSE);
  375. lapb_start_t1timer(lapb);
  376. lapb_stop_t2timer(lapb);
  377. lapb->state = LAPB_STATE_0;
  378. lapb_disconnect_indication(lapb, LAPB_OK);
  379. break;
  380. case LAPB_DM:
  381. #if LAPB_DEBUG > 1
  382. printk(KERN_DEBUG "lapb: (%p) S3 RX DM(%d)\n",
  383. lapb->dev, frame->pf);
  384. #endif
  385. #if LAPB_DEBUG > 0
  386. printk(KERN_DEBUG "lapb: (%p) S3 -> S0\n", lapb->dev);
  387. #endif
  388. lapb_clear_queues(lapb);
  389. lapb->state = LAPB_STATE_0;
  390. lapb_start_t1timer(lapb);
  391. lapb_stop_t2timer(lapb);
  392. lapb_disconnect_indication(lapb, LAPB_NOTCONNECTED);
  393. break;
  394. case LAPB_RNR:
  395. #if LAPB_DEBUG > 1
  396. printk(KERN_DEBUG "lapb: (%p) S3 RX RNR(%d) R%d\n",
  397. lapb->dev, frame->pf, frame->nr);
  398. #endif
  399. lapb->condition |= LAPB_PEER_RX_BUSY_CONDITION;
  400. lapb_check_need_response(lapb, frame->cr, frame->pf);
  401. if (lapb_validate_nr(lapb, frame->nr)) {
  402. lapb_check_iframes_acked(lapb, frame->nr);
  403. } else {
  404. lapb->frmr_data = *frame;
  405. lapb->frmr_type = LAPB_FRMR_Z;
  406. lapb_transmit_frmr(lapb);
  407. #if LAPB_DEBUG > 0
  408. printk(KERN_DEBUG "lapb: (%p) S3 -> S4\n", lapb->dev);
  409. #endif
  410. lapb_start_t1timer(lapb);
  411. lapb_stop_t2timer(lapb);
  412. lapb->state = LAPB_STATE_4;
  413. lapb->n2count = 0;
  414. }
  415. break;
  416. case LAPB_RR:
  417. #if LAPB_DEBUG > 1
  418. printk(KERN_DEBUG "lapb: (%p) S3 RX RR(%d) R%d\n",
  419. lapb->dev, frame->pf, frame->nr);
  420. #endif
  421. lapb->condition &= ~LAPB_PEER_RX_BUSY_CONDITION;
  422. lapb_check_need_response(lapb, frame->cr, frame->pf);
  423. if (lapb_validate_nr(lapb, frame->nr)) {
  424. lapb_check_iframes_acked(lapb, frame->nr);
  425. } else {
  426. lapb->frmr_data = *frame;
  427. lapb->frmr_type = LAPB_FRMR_Z;
  428. lapb_transmit_frmr(lapb);
  429. #if LAPB_DEBUG > 0
  430. printk(KERN_DEBUG "lapb: (%p) S3 -> S4\n", lapb->dev);
  431. #endif
  432. lapb_start_t1timer(lapb);
  433. lapb_stop_t2timer(lapb);
  434. lapb->state = LAPB_STATE_4;
  435. lapb->n2count = 0;
  436. }
  437. break;
  438. case LAPB_REJ:
  439. #if LAPB_DEBUG > 1
  440. printk(KERN_DEBUG "lapb: (%p) S3 RX REJ(%d) R%d\n",
  441. lapb->dev, frame->pf, frame->nr);
  442. #endif
  443. lapb->condition &= ~LAPB_PEER_RX_BUSY_CONDITION;
  444. lapb_check_need_response(lapb, frame->cr, frame->pf);
  445. if (lapb_validate_nr(lapb, frame->nr)) {
  446. lapb_frames_acked(lapb, frame->nr);
  447. lapb_stop_t1timer(lapb);
  448. lapb->n2count = 0;
  449. lapb_requeue_frames(lapb);
  450. } else {
  451. lapb->frmr_data = *frame;
  452. lapb->frmr_type = LAPB_FRMR_Z;
  453. lapb_transmit_frmr(lapb);
  454. #if LAPB_DEBUG > 0
  455. printk(KERN_DEBUG "lapb: (%p) S3 -> S4\n", lapb->dev);
  456. #endif
  457. lapb_start_t1timer(lapb);
  458. lapb_stop_t2timer(lapb);
  459. lapb->state = LAPB_STATE_4;
  460. lapb->n2count = 0;
  461. }
  462. break;
  463. case LAPB_I:
  464. #if LAPB_DEBUG > 1
  465. printk(KERN_DEBUG "lapb: (%p) S3 RX I(%d) S%d R%d\n",
  466. lapb->dev, frame->pf, frame->ns, frame->nr);
  467. #endif
  468. if (!lapb_validate_nr(lapb, frame->nr)) {
  469. lapb->frmr_data = *frame;
  470. lapb->frmr_type = LAPB_FRMR_Z;
  471. lapb_transmit_frmr(lapb);
  472. #if LAPB_DEBUG > 0
  473. printk(KERN_DEBUG "lapb: (%p) S3 -> S4\n", lapb->dev);
  474. #endif
  475. lapb_start_t1timer(lapb);
  476. lapb_stop_t2timer(lapb);
  477. lapb->state = LAPB_STATE_4;
  478. lapb->n2count = 0;
  479. break;
  480. }
  481. if (lapb->condition & LAPB_PEER_RX_BUSY_CONDITION)
  482. lapb_frames_acked(lapb, frame->nr);
  483. else
  484. lapb_check_iframes_acked(lapb, frame->nr);
  485. if (frame->ns == lapb->vr) {
  486. int cn;
  487. cn = lapb_data_indication(lapb, skb);
  488. queued = 1;
  489. /*
  490. * If upper layer has dropped the frame, we
  491. * basically ignore any further protocol
  492. * processing. This will cause the peer
  493. * to re-transmit the frame later like
  494. * a frame lost on the wire.
  495. */
  496. if (cn == NET_RX_DROP) {
  497. printk(KERN_DEBUG "LAPB: rx congestion\n");
  498. break;
  499. }
  500. lapb->vr = (lapb->vr + 1) % modulus;
  501. lapb->condition &= ~LAPB_REJECT_CONDITION;
  502. if (frame->pf)
  503. lapb_enquiry_response(lapb);
  504. else {
  505. if (!(lapb->condition &
  506. LAPB_ACK_PENDING_CONDITION)) {
  507. lapb->condition |= LAPB_ACK_PENDING_CONDITION;
  508. lapb_start_t2timer(lapb);
  509. }
  510. }
  511. } else {
  512. if (lapb->condition & LAPB_REJECT_CONDITION) {
  513. if (frame->pf)
  514. lapb_enquiry_response(lapb);
  515. } else {
  516. #if LAPB_DEBUG > 1
  517. printk(KERN_DEBUG
  518. "lapb: (%p) S3 TX REJ(%d) R%d\n",
  519. lapb->dev, frame->pf, lapb->vr);
  520. #endif
  521. lapb->condition |= LAPB_REJECT_CONDITION;
  522. lapb_send_control(lapb, LAPB_REJ, frame->pf,
  523. LAPB_RESPONSE);
  524. lapb->condition &= ~LAPB_ACK_PENDING_CONDITION;
  525. }
  526. }
  527. break;
  528. case LAPB_FRMR:
  529. #if LAPB_DEBUG > 1
  530. printk(KERN_DEBUG "lapb: (%p) S3 RX FRMR(%d) %02X "
  531. "%02X %02X %02X %02X\n", lapb->dev, frame->pf,
  532. skb->data[0], skb->data[1], skb->data[2],
  533. skb->data[3], skb->data[4]);
  534. #endif
  535. lapb_establish_data_link(lapb);
  536. #if LAPB_DEBUG > 0
  537. printk(KERN_DEBUG "lapb: (%p) S3 -> S1\n", lapb->dev);
  538. #endif
  539. lapb_requeue_frames(lapb);
  540. lapb->state = LAPB_STATE_1;
  541. break;
  542. case LAPB_ILLEGAL:
  543. #if LAPB_DEBUG > 1
  544. printk(KERN_DEBUG "lapb: (%p) S3 RX ILLEGAL(%d)\n",
  545. lapb->dev, frame->pf);
  546. #endif
  547. lapb->frmr_data = *frame;
  548. lapb->frmr_type = LAPB_FRMR_W;
  549. lapb_transmit_frmr(lapb);
  550. #if LAPB_DEBUG > 0
  551. printk(KERN_DEBUG "lapb: (%p) S3 -> S4\n", lapb->dev);
  552. #endif
  553. lapb_start_t1timer(lapb);
  554. lapb_stop_t2timer(lapb);
  555. lapb->state = LAPB_STATE_4;
  556. lapb->n2count = 0;
  557. break;
  558. }
  559. if (!queued)
  560. kfree_skb(skb);
  561. }
  562. /*
  563. * State machine for state 4, Frame Reject State.
  564. * The handling of the timer(s) is in file lapb_timer.c.
  565. */
  566. static void lapb_state4_machine(struct lapb_cb *lapb, struct sk_buff *skb,
  567. struct lapb_frame *frame)
  568. {
  569. switch (frame->type) {
  570. case LAPB_SABM:
  571. #if LAPB_DEBUG > 1
  572. printk(KERN_DEBUG "lapb: (%p) S4 RX SABM(%d)\n",
  573. lapb->dev, frame->pf);
  574. #endif
  575. if (lapb->mode & LAPB_EXTENDED) {
  576. #if LAPB_DEBUG > 1
  577. printk(KERN_DEBUG "lapb: (%p) S4 TX DM(%d)\n",
  578. lapb->dev, frame->pf);
  579. #endif
  580. lapb_send_control(lapb, LAPB_DM, frame->pf,
  581. LAPB_RESPONSE);
  582. } else {
  583. #if LAPB_DEBUG > 1
  584. printk(KERN_DEBUG "lapb: (%p) S4 TX UA(%d)\n",
  585. lapb->dev, frame->pf);
  586. #endif
  587. #if LAPB_DEBUG > 0
  588. printk(KERN_DEBUG "lapb: (%p) S4 -> S3\n", lapb->dev);
  589. #endif
  590. lapb_send_control(lapb, LAPB_UA, frame->pf,
  591. LAPB_RESPONSE);
  592. lapb_stop_t1timer(lapb);
  593. lapb_stop_t2timer(lapb);
  594. lapb->state = LAPB_STATE_3;
  595. lapb->condition = 0x00;
  596. lapb->n2count = 0;
  597. lapb->vs = 0;
  598. lapb->vr = 0;
  599. lapb->va = 0;
  600. lapb_connect_indication(lapb, LAPB_OK);
  601. }
  602. break;
  603. case LAPB_SABME:
  604. #if LAPB_DEBUG > 1
  605. printk(KERN_DEBUG "lapb: (%p) S4 RX SABME(%d)\n",
  606. lapb->dev, frame->pf);
  607. #endif
  608. if (lapb->mode & LAPB_EXTENDED) {
  609. #if LAPB_DEBUG > 1
  610. printk(KERN_DEBUG "lapb: (%p) S4 TX UA(%d)\n",
  611. lapb->dev, frame->pf);
  612. #endif
  613. #if LAPB_DEBUG > 0
  614. printk(KERN_DEBUG "lapb: (%p) S4 -> S3\n", lapb->dev);
  615. #endif
  616. lapb_send_control(lapb, LAPB_UA, frame->pf,
  617. LAPB_RESPONSE);
  618. lapb_stop_t1timer(lapb);
  619. lapb_stop_t2timer(lapb);
  620. lapb->state = LAPB_STATE_3;
  621. lapb->condition = 0x00;
  622. lapb->n2count = 0;
  623. lapb->vs = 0;
  624. lapb->vr = 0;
  625. lapb->va = 0;
  626. lapb_connect_indication(lapb, LAPB_OK);
  627. } else {
  628. #if LAPB_DEBUG > 1
  629. printk(KERN_DEBUG "lapb: (%p) S4 TX DM(%d)\n",
  630. lapb->dev, frame->pf);
  631. #endif
  632. lapb_send_control(lapb, LAPB_DM, frame->pf,
  633. LAPB_RESPONSE);
  634. }
  635. break;
  636. }
  637. kfree_skb(skb);
  638. }
  639. /*
  640. * Process an incoming LAPB frame
  641. */
  642. void lapb_data_input(struct lapb_cb *lapb, struct sk_buff *skb)
  643. {
  644. struct lapb_frame frame;
  645. if (lapb_decode(lapb, skb, &frame) < 0) {
  646. kfree_skb(skb);
  647. return;
  648. }
  649. switch (lapb->state) {
  650. case LAPB_STATE_0:
  651. lapb_state0_machine(lapb, skb, &frame); break;
  652. case LAPB_STATE_1:
  653. lapb_state1_machine(lapb, skb, &frame); break;
  654. case LAPB_STATE_2:
  655. lapb_state2_machine(lapb, skb, &frame); break;
  656. case LAPB_STATE_3:
  657. lapb_state3_machine(lapb, skb, &frame); break;
  658. case LAPB_STATE_4:
  659. lapb_state4_machine(lapb, skb, &frame); break;
  660. }
  661. lapb_kick(lapb);
  662. }