lapb_in.c 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563
  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. #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
  18. #include <linux/errno.h>
  19. #include <linux/types.h>
  20. #include <linux/socket.h>
  21. #include <linux/in.h>
  22. #include <linux/kernel.h>
  23. #include <linux/timer.h>
  24. #include <linux/string.h>
  25. #include <linux/sockios.h>
  26. #include <linux/net.h>
  27. #include <linux/inet.h>
  28. #include <linux/netdevice.h>
  29. #include <linux/skbuff.h>
  30. #include <linux/slab.h>
  31. #include <net/sock.h>
  32. #include <asm/uaccess.h>
  33. #include <linux/fcntl.h>
  34. #include <linux/mm.h>
  35. #include <linux/interrupt.h>
  36. #include <net/lapb.h>
  37. /*
  38. * State machine for state 0, Disconnected State.
  39. * The handling of the timer(s) is in file lapb_timer.c.
  40. */
  41. static void lapb_state0_machine(struct lapb_cb *lapb, struct sk_buff *skb,
  42. struct lapb_frame *frame)
  43. {
  44. switch (frame->type) {
  45. case LAPB_SABM:
  46. lapb_dbg(1, "(%p) S0 RX SABM(%d)\n", lapb->dev, frame->pf);
  47. if (lapb->mode & LAPB_EXTENDED) {
  48. lapb_dbg(1, "(%p) S0 TX DM(%d)\n",
  49. lapb->dev, frame->pf);
  50. lapb_send_control(lapb, LAPB_DM, frame->pf,
  51. LAPB_RESPONSE);
  52. } else {
  53. lapb_dbg(1, "(%p) S0 TX UA(%d)\n",
  54. lapb->dev, frame->pf);
  55. lapb_dbg(0, "(%p) S0 -> S3\n", lapb->dev);
  56. lapb_send_control(lapb, LAPB_UA, frame->pf,
  57. LAPB_RESPONSE);
  58. lapb_stop_t1timer(lapb);
  59. lapb_stop_t2timer(lapb);
  60. lapb->state = LAPB_STATE_3;
  61. lapb->condition = 0x00;
  62. lapb->n2count = 0;
  63. lapb->vs = 0;
  64. lapb->vr = 0;
  65. lapb->va = 0;
  66. lapb_connect_indication(lapb, LAPB_OK);
  67. }
  68. break;
  69. case LAPB_SABME:
  70. lapb_dbg(1, "(%p) S0 RX SABME(%d)\n", lapb->dev, frame->pf);
  71. if (lapb->mode & LAPB_EXTENDED) {
  72. lapb_dbg(1, "(%p) S0 TX UA(%d)\n",
  73. lapb->dev, frame->pf);
  74. lapb_dbg(0, "(%p) S0 -> S3\n", lapb->dev);
  75. lapb_send_control(lapb, LAPB_UA, frame->pf,
  76. LAPB_RESPONSE);
  77. lapb_stop_t1timer(lapb);
  78. lapb_stop_t2timer(lapb);
  79. lapb->state = LAPB_STATE_3;
  80. lapb->condition = 0x00;
  81. lapb->n2count = 0;
  82. lapb->vs = 0;
  83. lapb->vr = 0;
  84. lapb->va = 0;
  85. lapb_connect_indication(lapb, LAPB_OK);
  86. } else {
  87. lapb_dbg(1, "(%p) S0 TX DM(%d)\n",
  88. lapb->dev, frame->pf);
  89. lapb_send_control(lapb, LAPB_DM, frame->pf,
  90. LAPB_RESPONSE);
  91. }
  92. break;
  93. case LAPB_DISC:
  94. lapb_dbg(1, "(%p) S0 RX DISC(%d)\n", lapb->dev, frame->pf);
  95. lapb_dbg(1, "(%p) S0 TX UA(%d)\n", lapb->dev, frame->pf);
  96. lapb_send_control(lapb, LAPB_UA, frame->pf, LAPB_RESPONSE);
  97. break;
  98. default:
  99. break;
  100. }
  101. kfree_skb(skb);
  102. }
  103. /*
  104. * State machine for state 1, Awaiting Connection State.
  105. * The handling of the timer(s) is in file lapb_timer.c.
  106. */
  107. static void lapb_state1_machine(struct lapb_cb *lapb, struct sk_buff *skb,
  108. struct lapb_frame *frame)
  109. {
  110. switch (frame->type) {
  111. case LAPB_SABM:
  112. lapb_dbg(1, "(%p) S1 RX SABM(%d)\n", lapb->dev, frame->pf);
  113. if (lapb->mode & LAPB_EXTENDED) {
  114. lapb_dbg(1, "(%p) S1 TX DM(%d)\n",
  115. lapb->dev, frame->pf);
  116. lapb_send_control(lapb, LAPB_DM, frame->pf,
  117. LAPB_RESPONSE);
  118. } else {
  119. lapb_dbg(1, "(%p) S1 TX UA(%d)\n",
  120. lapb->dev, frame->pf);
  121. lapb_send_control(lapb, LAPB_UA, frame->pf,
  122. LAPB_RESPONSE);
  123. }
  124. break;
  125. case LAPB_SABME:
  126. lapb_dbg(1, "(%p) S1 RX SABME(%d)\n", lapb->dev, frame->pf);
  127. if (lapb->mode & LAPB_EXTENDED) {
  128. lapb_dbg(1, "(%p) S1 TX UA(%d)\n",
  129. lapb->dev, frame->pf);
  130. lapb_send_control(lapb, LAPB_UA, frame->pf,
  131. LAPB_RESPONSE);
  132. } else {
  133. lapb_dbg(1, "(%p) S1 TX DM(%d)\n",
  134. lapb->dev, frame->pf);
  135. lapb_send_control(lapb, LAPB_DM, frame->pf,
  136. LAPB_RESPONSE);
  137. }
  138. break;
  139. case LAPB_DISC:
  140. lapb_dbg(1, "(%p) S1 RX DISC(%d)\n", lapb->dev, frame->pf);
  141. lapb_dbg(1, "(%p) S1 TX DM(%d)\n", lapb->dev, frame->pf);
  142. lapb_send_control(lapb, LAPB_DM, frame->pf, LAPB_RESPONSE);
  143. break;
  144. case LAPB_UA:
  145. lapb_dbg(1, "(%p) S1 RX UA(%d)\n", lapb->dev, frame->pf);
  146. if (frame->pf) {
  147. lapb_dbg(0, "(%p) S1 -> S3\n", lapb->dev);
  148. lapb_stop_t1timer(lapb);
  149. lapb_stop_t2timer(lapb);
  150. lapb->state = LAPB_STATE_3;
  151. lapb->condition = 0x00;
  152. lapb->n2count = 0;
  153. lapb->vs = 0;
  154. lapb->vr = 0;
  155. lapb->va = 0;
  156. lapb_connect_confirmation(lapb, LAPB_OK);
  157. }
  158. break;
  159. case LAPB_DM:
  160. lapb_dbg(1, "(%p) S1 RX DM(%d)\n", lapb->dev, frame->pf);
  161. if (frame->pf) {
  162. lapb_dbg(0, "(%p) S1 -> S0\n", lapb->dev);
  163. lapb_clear_queues(lapb);
  164. lapb->state = LAPB_STATE_0;
  165. lapb_start_t1timer(lapb);
  166. lapb_stop_t2timer(lapb);
  167. lapb_disconnect_indication(lapb, LAPB_REFUSED);
  168. }
  169. break;
  170. }
  171. kfree_skb(skb);
  172. }
  173. /*
  174. * State machine for state 2, Awaiting Release State.
  175. * The handling of the timer(s) is in file lapb_timer.c
  176. */
  177. static void lapb_state2_machine(struct lapb_cb *lapb, struct sk_buff *skb,
  178. struct lapb_frame *frame)
  179. {
  180. switch (frame->type) {
  181. case LAPB_SABM:
  182. case LAPB_SABME:
  183. lapb_dbg(1, "(%p) S2 RX {SABM,SABME}(%d)\n",
  184. lapb->dev, frame->pf);
  185. lapb_dbg(1, "(%p) S2 TX DM(%d)\n", lapb->dev, frame->pf);
  186. lapb_send_control(lapb, LAPB_DM, frame->pf, LAPB_RESPONSE);
  187. break;
  188. case LAPB_DISC:
  189. lapb_dbg(1, "(%p) S2 RX DISC(%d)\n", lapb->dev, frame->pf);
  190. lapb_dbg(1, "(%p) S2 TX UA(%d)\n", lapb->dev, frame->pf);
  191. lapb_send_control(lapb, LAPB_UA, frame->pf, LAPB_RESPONSE);
  192. break;
  193. case LAPB_UA:
  194. lapb_dbg(1, "(%p) S2 RX UA(%d)\n", lapb->dev, frame->pf);
  195. if (frame->pf) {
  196. lapb_dbg(0, "(%p) S2 -> S0\n", lapb->dev);
  197. lapb->state = LAPB_STATE_0;
  198. lapb_start_t1timer(lapb);
  199. lapb_stop_t2timer(lapb);
  200. lapb_disconnect_confirmation(lapb, LAPB_OK);
  201. }
  202. break;
  203. case LAPB_DM:
  204. lapb_dbg(1, "(%p) S2 RX DM(%d)\n", lapb->dev, frame->pf);
  205. if (frame->pf) {
  206. lapb_dbg(0, "(%p) S2 -> S0\n", lapb->dev);
  207. lapb->state = LAPB_STATE_0;
  208. lapb_start_t1timer(lapb);
  209. lapb_stop_t2timer(lapb);
  210. lapb_disconnect_confirmation(lapb, LAPB_NOTCONNECTED);
  211. }
  212. break;
  213. case LAPB_I:
  214. case LAPB_REJ:
  215. case LAPB_RNR:
  216. case LAPB_RR:
  217. lapb_dbg(1, "(%p) S2 RX {I,REJ,RNR,RR}(%d)\n",
  218. lapb->dev, frame->pf);
  219. lapb_dbg(1, "(%p) S2 RX DM(%d)\n", lapb->dev, frame->pf);
  220. if (frame->pf)
  221. lapb_send_control(lapb, LAPB_DM, frame->pf,
  222. LAPB_RESPONSE);
  223. break;
  224. }
  225. kfree_skb(skb);
  226. }
  227. /*
  228. * State machine for state 3, Connected State.
  229. * The handling of the timer(s) is in file lapb_timer.c
  230. */
  231. static void lapb_state3_machine(struct lapb_cb *lapb, struct sk_buff *skb,
  232. struct lapb_frame *frame)
  233. {
  234. int queued = 0;
  235. int modulus = (lapb->mode & LAPB_EXTENDED) ? LAPB_EMODULUS :
  236. LAPB_SMODULUS;
  237. switch (frame->type) {
  238. case LAPB_SABM:
  239. lapb_dbg(1, "(%p) S3 RX SABM(%d)\n", lapb->dev, frame->pf);
  240. if (lapb->mode & LAPB_EXTENDED) {
  241. lapb_dbg(1, "(%p) S3 TX DM(%d)\n",
  242. lapb->dev, frame->pf);
  243. lapb_send_control(lapb, LAPB_DM, frame->pf,
  244. LAPB_RESPONSE);
  245. } else {
  246. lapb_dbg(1, "(%p) S3 TX UA(%d)\n",
  247. lapb->dev, frame->pf);
  248. lapb_send_control(lapb, LAPB_UA, frame->pf,
  249. LAPB_RESPONSE);
  250. lapb_stop_t1timer(lapb);
  251. lapb_stop_t2timer(lapb);
  252. lapb->condition = 0x00;
  253. lapb->n2count = 0;
  254. lapb->vs = 0;
  255. lapb->vr = 0;
  256. lapb->va = 0;
  257. lapb_requeue_frames(lapb);
  258. }
  259. break;
  260. case LAPB_SABME:
  261. lapb_dbg(1, "(%p) S3 RX SABME(%d)\n", lapb->dev, frame->pf);
  262. if (lapb->mode & LAPB_EXTENDED) {
  263. lapb_dbg(1, "(%p) S3 TX UA(%d)\n",
  264. lapb->dev, frame->pf);
  265. lapb_send_control(lapb, LAPB_UA, frame->pf,
  266. LAPB_RESPONSE);
  267. lapb_stop_t1timer(lapb);
  268. lapb_stop_t2timer(lapb);
  269. lapb->condition = 0x00;
  270. lapb->n2count = 0;
  271. lapb->vs = 0;
  272. lapb->vr = 0;
  273. lapb->va = 0;
  274. lapb_requeue_frames(lapb);
  275. } else {
  276. lapb_dbg(1, "(%p) S3 TX DM(%d)\n",
  277. lapb->dev, frame->pf);
  278. lapb_send_control(lapb, LAPB_DM, frame->pf,
  279. LAPB_RESPONSE);
  280. }
  281. break;
  282. case LAPB_DISC:
  283. lapb_dbg(1, "(%p) S3 RX DISC(%d)\n", lapb->dev, frame->pf);
  284. lapb_dbg(0, "(%p) S3 -> S0\n", lapb->dev);
  285. lapb_clear_queues(lapb);
  286. lapb_send_control(lapb, LAPB_UA, frame->pf, LAPB_RESPONSE);
  287. lapb_start_t1timer(lapb);
  288. lapb_stop_t2timer(lapb);
  289. lapb->state = LAPB_STATE_0;
  290. lapb_disconnect_indication(lapb, LAPB_OK);
  291. break;
  292. case LAPB_DM:
  293. lapb_dbg(1, "(%p) S3 RX DM(%d)\n", lapb->dev, frame->pf);
  294. lapb_dbg(0, "(%p) S3 -> S0\n", lapb->dev);
  295. lapb_clear_queues(lapb);
  296. lapb->state = LAPB_STATE_0;
  297. lapb_start_t1timer(lapb);
  298. lapb_stop_t2timer(lapb);
  299. lapb_disconnect_indication(lapb, LAPB_NOTCONNECTED);
  300. break;
  301. case LAPB_RNR:
  302. lapb_dbg(1, "(%p) S3 RX RNR(%d) R%d\n",
  303. lapb->dev, frame->pf, frame->nr);
  304. lapb->condition |= LAPB_PEER_RX_BUSY_CONDITION;
  305. lapb_check_need_response(lapb, frame->cr, frame->pf);
  306. if (lapb_validate_nr(lapb, frame->nr)) {
  307. lapb_check_iframes_acked(lapb, frame->nr);
  308. } else {
  309. lapb->frmr_data = *frame;
  310. lapb->frmr_type = LAPB_FRMR_Z;
  311. lapb_transmit_frmr(lapb);
  312. lapb_dbg(0, "(%p) S3 -> S4\n", lapb->dev);
  313. lapb_start_t1timer(lapb);
  314. lapb_stop_t2timer(lapb);
  315. lapb->state = LAPB_STATE_4;
  316. lapb->n2count = 0;
  317. }
  318. break;
  319. case LAPB_RR:
  320. lapb_dbg(1, "(%p) S3 RX RR(%d) R%d\n",
  321. lapb->dev, frame->pf, frame->nr);
  322. lapb->condition &= ~LAPB_PEER_RX_BUSY_CONDITION;
  323. lapb_check_need_response(lapb, frame->cr, frame->pf);
  324. if (lapb_validate_nr(lapb, frame->nr)) {
  325. lapb_check_iframes_acked(lapb, frame->nr);
  326. } else {
  327. lapb->frmr_data = *frame;
  328. lapb->frmr_type = LAPB_FRMR_Z;
  329. lapb_transmit_frmr(lapb);
  330. lapb_dbg(0, "(%p) S3 -> S4\n", lapb->dev);
  331. lapb_start_t1timer(lapb);
  332. lapb_stop_t2timer(lapb);
  333. lapb->state = LAPB_STATE_4;
  334. lapb->n2count = 0;
  335. }
  336. break;
  337. case LAPB_REJ:
  338. lapb_dbg(1, "(%p) S3 RX REJ(%d) R%d\n",
  339. lapb->dev, frame->pf, frame->nr);
  340. lapb->condition &= ~LAPB_PEER_RX_BUSY_CONDITION;
  341. lapb_check_need_response(lapb, frame->cr, frame->pf);
  342. if (lapb_validate_nr(lapb, frame->nr)) {
  343. lapb_frames_acked(lapb, frame->nr);
  344. lapb_stop_t1timer(lapb);
  345. lapb->n2count = 0;
  346. lapb_requeue_frames(lapb);
  347. } else {
  348. lapb->frmr_data = *frame;
  349. lapb->frmr_type = LAPB_FRMR_Z;
  350. lapb_transmit_frmr(lapb);
  351. lapb_dbg(0, "(%p) S3 -> S4\n", lapb->dev);
  352. lapb_start_t1timer(lapb);
  353. lapb_stop_t2timer(lapb);
  354. lapb->state = LAPB_STATE_4;
  355. lapb->n2count = 0;
  356. }
  357. break;
  358. case LAPB_I:
  359. lapb_dbg(1, "(%p) S3 RX I(%d) S%d R%d\n",
  360. lapb->dev, frame->pf, frame->ns, frame->nr);
  361. if (!lapb_validate_nr(lapb, frame->nr)) {
  362. lapb->frmr_data = *frame;
  363. lapb->frmr_type = LAPB_FRMR_Z;
  364. lapb_transmit_frmr(lapb);
  365. lapb_dbg(0, "(%p) S3 -> S4\n", lapb->dev);
  366. lapb_start_t1timer(lapb);
  367. lapb_stop_t2timer(lapb);
  368. lapb->state = LAPB_STATE_4;
  369. lapb->n2count = 0;
  370. break;
  371. }
  372. if (lapb->condition & LAPB_PEER_RX_BUSY_CONDITION)
  373. lapb_frames_acked(lapb, frame->nr);
  374. else
  375. lapb_check_iframes_acked(lapb, frame->nr);
  376. if (frame->ns == lapb->vr) {
  377. int cn;
  378. cn = lapb_data_indication(lapb, skb);
  379. queued = 1;
  380. /*
  381. * If upper layer has dropped the frame, we
  382. * basically ignore any further protocol
  383. * processing. This will cause the peer
  384. * to re-transmit the frame later like
  385. * a frame lost on the wire.
  386. */
  387. if (cn == NET_RX_DROP) {
  388. pr_debug("rx congestion\n");
  389. break;
  390. }
  391. lapb->vr = (lapb->vr + 1) % modulus;
  392. lapb->condition &= ~LAPB_REJECT_CONDITION;
  393. if (frame->pf)
  394. lapb_enquiry_response(lapb);
  395. else {
  396. if (!(lapb->condition &
  397. LAPB_ACK_PENDING_CONDITION)) {
  398. lapb->condition |= LAPB_ACK_PENDING_CONDITION;
  399. lapb_start_t2timer(lapb);
  400. }
  401. }
  402. } else {
  403. if (lapb->condition & LAPB_REJECT_CONDITION) {
  404. if (frame->pf)
  405. lapb_enquiry_response(lapb);
  406. } else {
  407. lapb_dbg(1, "(%p) S3 TX REJ(%d) R%d\n",
  408. lapb->dev, frame->pf, lapb->vr);
  409. lapb->condition |= LAPB_REJECT_CONDITION;
  410. lapb_send_control(lapb, LAPB_REJ, frame->pf,
  411. LAPB_RESPONSE);
  412. lapb->condition &= ~LAPB_ACK_PENDING_CONDITION;
  413. }
  414. }
  415. break;
  416. case LAPB_FRMR:
  417. lapb_dbg(1, "(%p) S3 RX FRMR(%d) %02X %02X %02X %02X %02X\n",
  418. lapb->dev, frame->pf,
  419. skb->data[0], skb->data[1], skb->data[2],
  420. skb->data[3], skb->data[4]);
  421. lapb_establish_data_link(lapb);
  422. lapb_dbg(0, "(%p) S3 -> S1\n", lapb->dev);
  423. lapb_requeue_frames(lapb);
  424. lapb->state = LAPB_STATE_1;
  425. break;
  426. case LAPB_ILLEGAL:
  427. lapb_dbg(1, "(%p) S3 RX ILLEGAL(%d)\n", lapb->dev, frame->pf);
  428. lapb->frmr_data = *frame;
  429. lapb->frmr_type = LAPB_FRMR_W;
  430. lapb_transmit_frmr(lapb);
  431. lapb_dbg(0, "(%p) S3 -> S4\n", lapb->dev);
  432. lapb_start_t1timer(lapb);
  433. lapb_stop_t2timer(lapb);
  434. lapb->state = LAPB_STATE_4;
  435. lapb->n2count = 0;
  436. break;
  437. }
  438. if (!queued)
  439. kfree_skb(skb);
  440. }
  441. /*
  442. * State machine for state 4, Frame Reject State.
  443. * The handling of the timer(s) is in file lapb_timer.c.
  444. */
  445. static void lapb_state4_machine(struct lapb_cb *lapb, struct sk_buff *skb,
  446. struct lapb_frame *frame)
  447. {
  448. switch (frame->type) {
  449. case LAPB_SABM:
  450. lapb_dbg(1, "(%p) S4 RX SABM(%d)\n", lapb->dev, frame->pf);
  451. if (lapb->mode & LAPB_EXTENDED) {
  452. lapb_dbg(1, "(%p) S4 TX DM(%d)\n",
  453. lapb->dev, frame->pf);
  454. lapb_send_control(lapb, LAPB_DM, frame->pf,
  455. LAPB_RESPONSE);
  456. } else {
  457. lapb_dbg(1, "(%p) S4 TX UA(%d)\n",
  458. lapb->dev, frame->pf);
  459. lapb_dbg(0, "(%p) S4 -> S3\n", lapb->dev);
  460. lapb_send_control(lapb, LAPB_UA, frame->pf,
  461. LAPB_RESPONSE);
  462. lapb_stop_t1timer(lapb);
  463. lapb_stop_t2timer(lapb);
  464. lapb->state = LAPB_STATE_3;
  465. lapb->condition = 0x00;
  466. lapb->n2count = 0;
  467. lapb->vs = 0;
  468. lapb->vr = 0;
  469. lapb->va = 0;
  470. lapb_connect_indication(lapb, LAPB_OK);
  471. }
  472. break;
  473. case LAPB_SABME:
  474. lapb_dbg(1, "(%p) S4 RX SABME(%d)\n", lapb->dev, frame->pf);
  475. if (lapb->mode & LAPB_EXTENDED) {
  476. lapb_dbg(1, "(%p) S4 TX UA(%d)\n",
  477. lapb->dev, frame->pf);
  478. lapb_dbg(0, "(%p) S4 -> S3\n", lapb->dev);
  479. lapb_send_control(lapb, LAPB_UA, frame->pf,
  480. LAPB_RESPONSE);
  481. lapb_stop_t1timer(lapb);
  482. lapb_stop_t2timer(lapb);
  483. lapb->state = LAPB_STATE_3;
  484. lapb->condition = 0x00;
  485. lapb->n2count = 0;
  486. lapb->vs = 0;
  487. lapb->vr = 0;
  488. lapb->va = 0;
  489. lapb_connect_indication(lapb, LAPB_OK);
  490. } else {
  491. lapb_dbg(1, "(%p) S4 TX DM(%d)\n",
  492. lapb->dev, frame->pf);
  493. lapb_send_control(lapb, LAPB_DM, frame->pf,
  494. LAPB_RESPONSE);
  495. }
  496. break;
  497. }
  498. kfree_skb(skb);
  499. }
  500. /*
  501. * Process an incoming LAPB frame
  502. */
  503. void lapb_data_input(struct lapb_cb *lapb, struct sk_buff *skb)
  504. {
  505. struct lapb_frame frame;
  506. if (lapb_decode(lapb, skb, &frame) < 0) {
  507. kfree_skb(skb);
  508. return;
  509. }
  510. switch (lapb->state) {
  511. case LAPB_STATE_0:
  512. lapb_state0_machine(lapb, skb, &frame); break;
  513. case LAPB_STATE_1:
  514. lapb_state1_machine(lapb, skb, &frame); break;
  515. case LAPB_STATE_2:
  516. lapb_state2_machine(lapb, skb, &frame); break;
  517. case LAPB_STATE_3:
  518. lapb_state3_machine(lapb, skb, &frame); break;
  519. case LAPB_STATE_4:
  520. lapb_state4_machine(lapb, skb, &frame); break;
  521. }
  522. lapb_kick(lapb);
  523. }