llc_c_ac.c 35 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441
  1. /*
  2. * llc_c_ac.c - actions performed during connection state transition.
  3. *
  4. * Description:
  5. * Functions in this module are implementation of connection component actions
  6. * Details of actions can be found in IEEE-802.2 standard document.
  7. * All functions have one connection and one event as input argument. All of
  8. * them return 0 On success and 1 otherwise.
  9. *
  10. * Copyright (c) 1997 by Procom Technology, Inc.
  11. * 2001-2003 by Arnaldo Carvalho de Melo <acme@conectiva.com.br>
  12. *
  13. * This program can be redistributed or modified under the terms of the
  14. * GNU General Public License as published by the Free Software Foundation.
  15. * This program is distributed without any warranty or implied warranty
  16. * of merchantability or fitness for a particular purpose.
  17. *
  18. * See the GNU General Public License for more details.
  19. */
  20. #include <linux/netdevice.h>
  21. #include <net/llc_conn.h>
  22. #include <net/llc_sap.h>
  23. #include <net/sock.h>
  24. #include <net/llc_c_ev.h>
  25. #include <net/llc_c_ac.h>
  26. #include <net/llc_c_st.h>
  27. #include <net/llc_pdu.h>
  28. #include <net/llc.h>
  29. #include "llc_output.h"
  30. static int llc_conn_ac_inc_vs_by_1(struct sock *sk, struct sk_buff *skb);
  31. static void llc_process_tmr_ev(struct sock *sk, struct sk_buff *skb);
  32. static int llc_conn_ac_data_confirm(struct sock *sk, struct sk_buff *ev);
  33. static int llc_conn_ac_inc_npta_value(struct sock *sk, struct sk_buff *skb);
  34. static int llc_conn_ac_send_rr_rsp_f_set_ackpf(struct sock *sk,
  35. struct sk_buff *skb);
  36. static int llc_conn_ac_set_p_flag_1(struct sock *sk, struct sk_buff *skb);
  37. #define INCORRECT 0
  38. int llc_conn_ac_clear_remote_busy(struct sock *sk, struct sk_buff *skb)
  39. {
  40. struct llc_sock *llc = llc_sk(sk);
  41. if (llc->remote_busy_flag) {
  42. u8 nr;
  43. struct llc_pdu_sn *pdu = llc_pdu_sn_hdr(skb);
  44. llc->remote_busy_flag = 0;
  45. del_timer(&llc->busy_state_timer.timer);
  46. nr = LLC_I_GET_NR(pdu);
  47. llc_conn_resend_i_pdu_as_cmd(sk, nr, 0);
  48. }
  49. return 0;
  50. }
  51. int llc_conn_ac_conn_ind(struct sock *sk, struct sk_buff *skb)
  52. {
  53. struct llc_conn_state_ev *ev = llc_conn_ev(skb);
  54. ev->ind_prim = LLC_CONN_PRIM;
  55. return 0;
  56. }
  57. int llc_conn_ac_conn_confirm(struct sock *sk, struct sk_buff *skb)
  58. {
  59. struct llc_conn_state_ev *ev = llc_conn_ev(skb);
  60. ev->cfm_prim = LLC_CONN_PRIM;
  61. return 0;
  62. }
  63. static int llc_conn_ac_data_confirm(struct sock *sk, struct sk_buff *skb)
  64. {
  65. struct llc_conn_state_ev *ev = llc_conn_ev(skb);
  66. ev->cfm_prim = LLC_DATA_PRIM;
  67. return 0;
  68. }
  69. int llc_conn_ac_data_ind(struct sock *sk, struct sk_buff *skb)
  70. {
  71. llc_conn_rtn_pdu(sk, skb);
  72. return 0;
  73. }
  74. int llc_conn_ac_disc_ind(struct sock *sk, struct sk_buff *skb)
  75. {
  76. struct llc_conn_state_ev *ev = llc_conn_ev(skb);
  77. u8 reason = 0;
  78. int rc = 0;
  79. if (ev->type == LLC_CONN_EV_TYPE_PDU) {
  80. struct llc_pdu_un *pdu = llc_pdu_un_hdr(skb);
  81. if (LLC_PDU_IS_RSP(pdu) &&
  82. LLC_PDU_TYPE_IS_U(pdu) &&
  83. LLC_U_PDU_RSP(pdu) == LLC_2_PDU_RSP_DM)
  84. reason = LLC_DISC_REASON_RX_DM_RSP_PDU;
  85. else if (LLC_PDU_IS_CMD(pdu) &&
  86. LLC_PDU_TYPE_IS_U(pdu) &&
  87. LLC_U_PDU_CMD(pdu) == LLC_2_PDU_CMD_DISC)
  88. reason = LLC_DISC_REASON_RX_DISC_CMD_PDU;
  89. } else if (ev->type == LLC_CONN_EV_TYPE_ACK_TMR)
  90. reason = LLC_DISC_REASON_ACK_TMR_EXP;
  91. else
  92. rc = -EINVAL;
  93. if (!rc) {
  94. ev->reason = reason;
  95. ev->ind_prim = LLC_DISC_PRIM;
  96. }
  97. return rc;
  98. }
  99. int llc_conn_ac_disc_confirm(struct sock *sk, struct sk_buff *skb)
  100. {
  101. struct llc_conn_state_ev *ev = llc_conn_ev(skb);
  102. ev->reason = ev->status;
  103. ev->cfm_prim = LLC_DISC_PRIM;
  104. return 0;
  105. }
  106. int llc_conn_ac_rst_ind(struct sock *sk, struct sk_buff *skb)
  107. {
  108. u8 reason = 0;
  109. int rc = 1;
  110. struct llc_conn_state_ev *ev = llc_conn_ev(skb);
  111. struct llc_pdu_un *pdu = llc_pdu_un_hdr(skb);
  112. struct llc_sock *llc = llc_sk(sk);
  113. switch (ev->type) {
  114. case LLC_CONN_EV_TYPE_PDU:
  115. if (LLC_PDU_IS_RSP(pdu) &&
  116. LLC_PDU_TYPE_IS_U(pdu) &&
  117. LLC_U_PDU_RSP(pdu) == LLC_2_PDU_RSP_FRMR) {
  118. reason = LLC_RESET_REASON_LOCAL;
  119. rc = 0;
  120. } else if (LLC_PDU_IS_CMD(pdu) &&
  121. LLC_PDU_TYPE_IS_U(pdu) &&
  122. LLC_U_PDU_CMD(pdu) == LLC_2_PDU_CMD_SABME) {
  123. reason = LLC_RESET_REASON_REMOTE;
  124. rc = 0;
  125. }
  126. break;
  127. case LLC_CONN_EV_TYPE_ACK_TMR:
  128. case LLC_CONN_EV_TYPE_P_TMR:
  129. case LLC_CONN_EV_TYPE_REJ_TMR:
  130. case LLC_CONN_EV_TYPE_BUSY_TMR:
  131. if (llc->retry_count > llc->n2) {
  132. reason = LLC_RESET_REASON_LOCAL;
  133. rc = 0;
  134. }
  135. break;
  136. }
  137. if (!rc) {
  138. ev->reason = reason;
  139. ev->ind_prim = LLC_RESET_PRIM;
  140. }
  141. return rc;
  142. }
  143. int llc_conn_ac_rst_confirm(struct sock *sk, struct sk_buff *skb)
  144. {
  145. struct llc_conn_state_ev *ev = llc_conn_ev(skb);
  146. ev->reason = 0;
  147. ev->cfm_prim = LLC_RESET_PRIM;
  148. return 0;
  149. }
  150. int llc_conn_ac_clear_remote_busy_if_f_eq_1(struct sock *sk,
  151. struct sk_buff *skb)
  152. {
  153. struct llc_pdu_sn *pdu = llc_pdu_sn_hdr(skb);
  154. if (LLC_PDU_IS_RSP(pdu) &&
  155. LLC_PDU_TYPE_IS_I(pdu) &&
  156. LLC_I_PF_IS_1(pdu) && llc_sk(sk)->ack_pf)
  157. llc_conn_ac_clear_remote_busy(sk, skb);
  158. return 0;
  159. }
  160. int llc_conn_ac_stop_rej_tmr_if_data_flag_eq_2(struct sock *sk,
  161. struct sk_buff *skb)
  162. {
  163. struct llc_sock *llc = llc_sk(sk);
  164. if (llc->data_flag == 2)
  165. del_timer(&llc->rej_sent_timer.timer);
  166. return 0;
  167. }
  168. int llc_conn_ac_send_disc_cmd_p_set_x(struct sock *sk, struct sk_buff *skb)
  169. {
  170. int rc = -ENOBUFS;
  171. struct llc_sock *llc = llc_sk(sk);
  172. struct sk_buff *nskb = llc_alloc_frame(sk, llc->dev);
  173. if (nskb) {
  174. struct llc_sap *sap = llc->sap;
  175. llc_pdu_header_init(nskb, LLC_PDU_TYPE_U, sap->laddr.lsap,
  176. llc->daddr.lsap, LLC_PDU_CMD);
  177. llc_pdu_init_as_disc_cmd(nskb, 1);
  178. rc = llc_mac_hdr_init(nskb, llc->dev->dev_addr, llc->daddr.mac);
  179. if (unlikely(rc))
  180. goto free;
  181. llc_conn_send_pdu(sk, nskb);
  182. llc_conn_ac_set_p_flag_1(sk, skb);
  183. }
  184. out:
  185. return rc;
  186. free:
  187. kfree_skb(nskb);
  188. goto out;
  189. }
  190. int llc_conn_ac_send_dm_rsp_f_set_p(struct sock *sk, struct sk_buff *skb)
  191. {
  192. int rc = -ENOBUFS;
  193. struct llc_sock *llc = llc_sk(sk);
  194. struct sk_buff *nskb = llc_alloc_frame(sk, llc->dev);
  195. if (nskb) {
  196. struct llc_sap *sap = llc->sap;
  197. u8 f_bit;
  198. llc_pdu_decode_pf_bit(skb, &f_bit);
  199. llc_pdu_header_init(nskb, LLC_PDU_TYPE_U, sap->laddr.lsap,
  200. llc->daddr.lsap, LLC_PDU_RSP);
  201. llc_pdu_init_as_dm_rsp(nskb, f_bit);
  202. rc = llc_mac_hdr_init(nskb, llc->dev->dev_addr, llc->daddr.mac);
  203. if (unlikely(rc))
  204. goto free;
  205. llc_conn_send_pdu(sk, nskb);
  206. }
  207. out:
  208. return rc;
  209. free:
  210. kfree_skb(nskb);
  211. goto out;
  212. }
  213. int llc_conn_ac_send_dm_rsp_f_set_1(struct sock *sk, struct sk_buff *skb)
  214. {
  215. int rc = -ENOBUFS;
  216. struct llc_sock *llc = llc_sk(sk);
  217. struct sk_buff *nskb = llc_alloc_frame(sk, llc->dev);
  218. if (nskb) {
  219. struct llc_sap *sap = llc->sap;
  220. llc_pdu_header_init(nskb, LLC_PDU_TYPE_U, sap->laddr.lsap,
  221. llc->daddr.lsap, LLC_PDU_RSP);
  222. llc_pdu_init_as_dm_rsp(nskb, 1);
  223. rc = llc_mac_hdr_init(nskb, llc->dev->dev_addr, llc->daddr.mac);
  224. if (unlikely(rc))
  225. goto free;
  226. llc_conn_send_pdu(sk, nskb);
  227. }
  228. out:
  229. return rc;
  230. free:
  231. kfree_skb(nskb);
  232. goto out;
  233. }
  234. int llc_conn_ac_send_frmr_rsp_f_set_x(struct sock *sk, struct sk_buff *skb)
  235. {
  236. u8 f_bit;
  237. int rc = -ENOBUFS;
  238. struct sk_buff *nskb;
  239. struct llc_pdu_sn *pdu = llc_pdu_sn_hdr(skb);
  240. struct llc_sock *llc = llc_sk(sk);
  241. llc->rx_pdu_hdr = *((u32 *)pdu);
  242. if (LLC_PDU_IS_CMD(pdu))
  243. llc_pdu_decode_pf_bit(skb, &f_bit);
  244. else
  245. f_bit = 0;
  246. nskb = llc_alloc_frame(sk, llc->dev);
  247. if (nskb) {
  248. struct llc_sap *sap = llc->sap;
  249. llc_pdu_header_init(nskb, LLC_PDU_TYPE_U, sap->laddr.lsap,
  250. llc->daddr.lsap, LLC_PDU_RSP);
  251. llc_pdu_init_as_frmr_rsp(nskb, pdu, f_bit, llc->vS,
  252. llc->vR, INCORRECT);
  253. rc = llc_mac_hdr_init(nskb, llc->dev->dev_addr, llc->daddr.mac);
  254. if (unlikely(rc))
  255. goto free;
  256. llc_conn_send_pdu(sk, nskb);
  257. }
  258. out:
  259. return rc;
  260. free:
  261. kfree_skb(nskb);
  262. goto out;
  263. }
  264. int llc_conn_ac_resend_frmr_rsp_f_set_0(struct sock *sk, struct sk_buff *skb)
  265. {
  266. int rc = -ENOBUFS;
  267. struct llc_sock *llc = llc_sk(sk);
  268. struct sk_buff *nskb = llc_alloc_frame(sk, llc->dev);
  269. if (nskb) {
  270. struct llc_sap *sap = llc->sap;
  271. struct llc_pdu_sn *pdu = (struct llc_pdu_sn *)&llc->rx_pdu_hdr;
  272. llc_pdu_header_init(nskb, LLC_PDU_TYPE_U, sap->laddr.lsap,
  273. llc->daddr.lsap, LLC_PDU_RSP);
  274. llc_pdu_init_as_frmr_rsp(nskb, pdu, 0, llc->vS,
  275. llc->vR, INCORRECT);
  276. rc = llc_mac_hdr_init(nskb, llc->dev->dev_addr, llc->daddr.mac);
  277. if (unlikely(rc))
  278. goto free;
  279. llc_conn_send_pdu(sk, nskb);
  280. }
  281. out:
  282. return rc;
  283. free:
  284. kfree_skb(nskb);
  285. goto out;
  286. }
  287. int llc_conn_ac_resend_frmr_rsp_f_set_p(struct sock *sk, struct sk_buff *skb)
  288. {
  289. u8 f_bit;
  290. int rc = -ENOBUFS;
  291. struct sk_buff *nskb;
  292. struct llc_sock *llc = llc_sk(sk);
  293. llc_pdu_decode_pf_bit(skb, &f_bit);
  294. nskb = llc_alloc_frame(sk, llc->dev);
  295. if (nskb) {
  296. struct llc_sap *sap = llc->sap;
  297. struct llc_pdu_sn *pdu = llc_pdu_sn_hdr(skb);
  298. llc_pdu_header_init(nskb, LLC_PDU_TYPE_U, sap->laddr.lsap,
  299. llc->daddr.lsap, LLC_PDU_RSP);
  300. llc_pdu_init_as_frmr_rsp(nskb, pdu, f_bit, llc->vS,
  301. llc->vR, INCORRECT);
  302. rc = llc_mac_hdr_init(nskb, llc->dev->dev_addr, llc->daddr.mac);
  303. if (unlikely(rc))
  304. goto free;
  305. llc_conn_send_pdu(sk, nskb);
  306. }
  307. out:
  308. return rc;
  309. free:
  310. kfree_skb(nskb);
  311. goto out;
  312. }
  313. int llc_conn_ac_send_i_cmd_p_set_1(struct sock *sk, struct sk_buff *skb)
  314. {
  315. int rc;
  316. struct llc_sock *llc = llc_sk(sk);
  317. struct llc_sap *sap = llc->sap;
  318. llc_pdu_header_init(skb, LLC_PDU_TYPE_I, sap->laddr.lsap,
  319. llc->daddr.lsap, LLC_PDU_CMD);
  320. llc_pdu_init_as_i_cmd(skb, 1, llc->vS, llc->vR);
  321. rc = llc_mac_hdr_init(skb, llc->dev->dev_addr, llc->daddr.mac);
  322. if (likely(!rc)) {
  323. llc_conn_send_pdu(sk, skb);
  324. llc_conn_ac_inc_vs_by_1(sk, skb);
  325. }
  326. return rc;
  327. }
  328. static int llc_conn_ac_send_i_cmd_p_set_0(struct sock *sk, struct sk_buff *skb)
  329. {
  330. int rc;
  331. struct llc_sock *llc = llc_sk(sk);
  332. struct llc_sap *sap = llc->sap;
  333. llc_pdu_header_init(skb, LLC_PDU_TYPE_I, sap->laddr.lsap,
  334. llc->daddr.lsap, LLC_PDU_CMD);
  335. llc_pdu_init_as_i_cmd(skb, 0, llc->vS, llc->vR);
  336. rc = llc_mac_hdr_init(skb, llc->dev->dev_addr, llc->daddr.mac);
  337. if (likely(!rc)) {
  338. llc_conn_send_pdu(sk, skb);
  339. llc_conn_ac_inc_vs_by_1(sk, skb);
  340. }
  341. return rc;
  342. }
  343. int llc_conn_ac_send_i_xxx_x_set_0(struct sock *sk, struct sk_buff *skb)
  344. {
  345. int rc;
  346. struct llc_sock *llc = llc_sk(sk);
  347. struct llc_sap *sap = llc->sap;
  348. llc_pdu_header_init(skb, LLC_PDU_TYPE_I, sap->laddr.lsap,
  349. llc->daddr.lsap, LLC_PDU_CMD);
  350. llc_pdu_init_as_i_cmd(skb, 0, llc->vS, llc->vR);
  351. rc = llc_mac_hdr_init(skb, llc->dev->dev_addr, llc->daddr.mac);
  352. if (likely(!rc)) {
  353. llc_conn_send_pdu(sk, skb);
  354. llc_conn_ac_inc_vs_by_1(sk, skb);
  355. }
  356. return 0;
  357. }
  358. int llc_conn_ac_resend_i_xxx_x_set_0(struct sock *sk, struct sk_buff *skb)
  359. {
  360. struct llc_pdu_sn *pdu = llc_pdu_sn_hdr(skb);
  361. u8 nr = LLC_I_GET_NR(pdu);
  362. llc_conn_resend_i_pdu_as_cmd(sk, nr, 0);
  363. return 0;
  364. }
  365. int llc_conn_ac_resend_i_xxx_x_set_0_or_send_rr(struct sock *sk,
  366. struct sk_buff *skb)
  367. {
  368. u8 nr;
  369. struct llc_pdu_sn *pdu = llc_pdu_sn_hdr(skb);
  370. int rc = -ENOBUFS;
  371. struct llc_sock *llc = llc_sk(sk);
  372. struct sk_buff *nskb = llc_alloc_frame(sk, llc->dev);
  373. if (nskb) {
  374. struct llc_sap *sap = llc->sap;
  375. llc_pdu_header_init(nskb, LLC_PDU_TYPE_U, sap->laddr.lsap,
  376. llc->daddr.lsap, LLC_PDU_RSP);
  377. llc_pdu_init_as_rr_rsp(nskb, 0, llc->vR);
  378. rc = llc_mac_hdr_init(nskb, llc->dev->dev_addr, llc->daddr.mac);
  379. if (likely(!rc))
  380. llc_conn_send_pdu(sk, nskb);
  381. else
  382. kfree_skb(skb);
  383. }
  384. if (rc) {
  385. nr = LLC_I_GET_NR(pdu);
  386. rc = 0;
  387. llc_conn_resend_i_pdu_as_cmd(sk, nr, 0);
  388. }
  389. return rc;
  390. }
  391. int llc_conn_ac_resend_i_rsp_f_set_1(struct sock *sk, struct sk_buff *skb)
  392. {
  393. struct llc_pdu_sn *pdu = llc_pdu_sn_hdr(skb);
  394. u8 nr = LLC_I_GET_NR(pdu);
  395. llc_conn_resend_i_pdu_as_rsp(sk, nr, 1);
  396. return 0;
  397. }
  398. int llc_conn_ac_send_rej_cmd_p_set_1(struct sock *sk, struct sk_buff *skb)
  399. {
  400. int rc = -ENOBUFS;
  401. struct llc_sock *llc = llc_sk(sk);
  402. struct sk_buff *nskb = llc_alloc_frame(sk, llc->dev);
  403. if (nskb) {
  404. struct llc_sap *sap = llc->sap;
  405. llc_pdu_header_init(nskb, LLC_PDU_TYPE_S, sap->laddr.lsap,
  406. llc->daddr.lsap, LLC_PDU_CMD);
  407. llc_pdu_init_as_rej_cmd(nskb, 1, llc->vR);
  408. rc = llc_mac_hdr_init(nskb, llc->dev->dev_addr, llc->daddr.mac);
  409. if (unlikely(rc))
  410. goto free;
  411. llc_conn_send_pdu(sk, nskb);
  412. }
  413. out:
  414. return rc;
  415. free:
  416. kfree_skb(nskb);
  417. goto out;
  418. }
  419. int llc_conn_ac_send_rej_rsp_f_set_1(struct sock *sk, struct sk_buff *skb)
  420. {
  421. int rc = -ENOBUFS;
  422. struct llc_sock *llc = llc_sk(sk);
  423. struct sk_buff *nskb = llc_alloc_frame(sk, llc->dev);
  424. if (nskb) {
  425. struct llc_sap *sap = llc->sap;
  426. llc_pdu_header_init(nskb, LLC_PDU_TYPE_S, sap->laddr.lsap,
  427. llc->daddr.lsap, LLC_PDU_RSP);
  428. llc_pdu_init_as_rej_rsp(nskb, 1, llc->vR);
  429. rc = llc_mac_hdr_init(nskb, llc->dev->dev_addr, llc->daddr.mac);
  430. if (unlikely(rc))
  431. goto free;
  432. llc_conn_send_pdu(sk, nskb);
  433. }
  434. out:
  435. return rc;
  436. free:
  437. kfree_skb(nskb);
  438. goto out;
  439. }
  440. int llc_conn_ac_send_rej_xxx_x_set_0(struct sock *sk, struct sk_buff *skb)
  441. {
  442. int rc = -ENOBUFS;
  443. struct llc_sock *llc = llc_sk(sk);
  444. struct sk_buff *nskb = llc_alloc_frame(sk, llc->dev);
  445. if (nskb) {
  446. struct llc_sap *sap = llc->sap;
  447. llc_pdu_header_init(nskb, LLC_PDU_TYPE_S, sap->laddr.lsap,
  448. llc->daddr.lsap, LLC_PDU_RSP);
  449. llc_pdu_init_as_rej_rsp(nskb, 0, llc->vR);
  450. rc = llc_mac_hdr_init(nskb, llc->dev->dev_addr, llc->daddr.mac);
  451. if (unlikely(rc))
  452. goto free;
  453. llc_conn_send_pdu(sk, nskb);
  454. }
  455. out:
  456. return rc;
  457. free:
  458. kfree_skb(nskb);
  459. goto out;
  460. }
  461. int llc_conn_ac_send_rnr_cmd_p_set_1(struct sock *sk, struct sk_buff *skb)
  462. {
  463. int rc = -ENOBUFS;
  464. struct llc_sock *llc = llc_sk(sk);
  465. struct sk_buff *nskb = llc_alloc_frame(sk, llc->dev);
  466. if (nskb) {
  467. struct llc_sap *sap = llc->sap;
  468. llc_pdu_header_init(nskb, LLC_PDU_TYPE_S, sap->laddr.lsap,
  469. llc->daddr.lsap, LLC_PDU_CMD);
  470. llc_pdu_init_as_rnr_cmd(nskb, 1, llc->vR);
  471. rc = llc_mac_hdr_init(nskb, llc->dev->dev_addr, llc->daddr.mac);
  472. if (unlikely(rc))
  473. goto free;
  474. llc_conn_send_pdu(sk, nskb);
  475. }
  476. out:
  477. return rc;
  478. free:
  479. kfree_skb(nskb);
  480. goto out;
  481. }
  482. int llc_conn_ac_send_rnr_rsp_f_set_1(struct sock *sk, struct sk_buff *skb)
  483. {
  484. int rc = -ENOBUFS;
  485. struct llc_sock *llc = llc_sk(sk);
  486. struct sk_buff *nskb = llc_alloc_frame(sk, llc->dev);
  487. if (nskb) {
  488. struct llc_sap *sap = llc->sap;
  489. llc_pdu_header_init(nskb, LLC_PDU_TYPE_S, sap->laddr.lsap,
  490. llc->daddr.lsap, LLC_PDU_RSP);
  491. llc_pdu_init_as_rnr_rsp(nskb, 1, llc->vR);
  492. rc = llc_mac_hdr_init(nskb, llc->dev->dev_addr, llc->daddr.mac);
  493. if (unlikely(rc))
  494. goto free;
  495. llc_conn_send_pdu(sk, nskb);
  496. }
  497. out:
  498. return rc;
  499. free:
  500. kfree_skb(nskb);
  501. goto out;
  502. }
  503. int llc_conn_ac_send_rnr_xxx_x_set_0(struct sock *sk, struct sk_buff *skb)
  504. {
  505. int rc = -ENOBUFS;
  506. struct llc_sock *llc = llc_sk(sk);
  507. struct sk_buff *nskb = llc_alloc_frame(sk, llc->dev);
  508. if (nskb) {
  509. struct llc_sap *sap = llc->sap;
  510. llc_pdu_header_init(nskb, LLC_PDU_TYPE_S, sap->laddr.lsap,
  511. llc->daddr.lsap, LLC_PDU_RSP);
  512. llc_pdu_init_as_rnr_rsp(nskb, 0, llc->vR);
  513. rc = llc_mac_hdr_init(nskb, llc->dev->dev_addr, llc->daddr.mac);
  514. if (unlikely(rc))
  515. goto free;
  516. llc_conn_send_pdu(sk, nskb);
  517. }
  518. out:
  519. return rc;
  520. free:
  521. kfree_skb(nskb);
  522. goto out;
  523. }
  524. int llc_conn_ac_set_remote_busy(struct sock *sk, struct sk_buff *skb)
  525. {
  526. struct llc_sock *llc = llc_sk(sk);
  527. if (!llc->remote_busy_flag) {
  528. llc->remote_busy_flag = 1;
  529. mod_timer(&llc->busy_state_timer.timer,
  530. jiffies + llc->busy_state_timer.expire);
  531. }
  532. return 0;
  533. }
  534. int llc_conn_ac_opt_send_rnr_xxx_x_set_0(struct sock *sk, struct sk_buff *skb)
  535. {
  536. int rc = -ENOBUFS;
  537. struct llc_sock *llc = llc_sk(sk);
  538. struct sk_buff *nskb = llc_alloc_frame(sk, llc->dev);
  539. if (nskb) {
  540. struct llc_sap *sap = llc->sap;
  541. llc_pdu_header_init(nskb, LLC_PDU_TYPE_S, sap->laddr.lsap,
  542. llc->daddr.lsap, LLC_PDU_RSP);
  543. llc_pdu_init_as_rnr_rsp(nskb, 0, llc->vR);
  544. rc = llc_mac_hdr_init(nskb, llc->dev->dev_addr, llc->daddr.mac);
  545. if (unlikely(rc))
  546. goto free;
  547. llc_conn_send_pdu(sk, nskb);
  548. }
  549. out:
  550. return rc;
  551. free:
  552. kfree_skb(nskb);
  553. goto out;
  554. }
  555. int llc_conn_ac_send_rr_cmd_p_set_1(struct sock *sk, struct sk_buff *skb)
  556. {
  557. int rc = -ENOBUFS;
  558. struct llc_sock *llc = llc_sk(sk);
  559. struct sk_buff *nskb = llc_alloc_frame(sk, llc->dev);
  560. if (nskb) {
  561. struct llc_sap *sap = llc->sap;
  562. llc_pdu_header_init(nskb, LLC_PDU_TYPE_S, sap->laddr.lsap,
  563. llc->daddr.lsap, LLC_PDU_CMD);
  564. llc_pdu_init_as_rr_cmd(nskb, 1, llc->vR);
  565. rc = llc_mac_hdr_init(nskb, llc->dev->dev_addr, llc->daddr.mac);
  566. if (unlikely(rc))
  567. goto free;
  568. llc_conn_send_pdu(sk, nskb);
  569. }
  570. out:
  571. return rc;
  572. free:
  573. kfree_skb(nskb);
  574. goto out;
  575. }
  576. int llc_conn_ac_send_rr_rsp_f_set_1(struct sock *sk, struct sk_buff *skb)
  577. {
  578. int rc = -ENOBUFS;
  579. struct llc_sock *llc = llc_sk(sk);
  580. struct sk_buff *nskb = llc_alloc_frame(sk, llc->dev);
  581. if (nskb) {
  582. struct llc_sap *sap = llc->sap;
  583. u8 f_bit = 1;
  584. llc_pdu_header_init(nskb, LLC_PDU_TYPE_S, sap->laddr.lsap,
  585. llc->daddr.lsap, LLC_PDU_RSP);
  586. llc_pdu_init_as_rr_rsp(nskb, f_bit, llc->vR);
  587. rc = llc_mac_hdr_init(nskb, llc->dev->dev_addr, llc->daddr.mac);
  588. if (unlikely(rc))
  589. goto free;
  590. llc_conn_send_pdu(sk, nskb);
  591. }
  592. out:
  593. return rc;
  594. free:
  595. kfree_skb(nskb);
  596. goto out;
  597. }
  598. int llc_conn_ac_send_ack_rsp_f_set_1(struct sock *sk, struct sk_buff *skb)
  599. {
  600. int rc = -ENOBUFS;
  601. struct llc_sock *llc = llc_sk(sk);
  602. struct sk_buff *nskb = llc_alloc_frame(sk, llc->dev);
  603. if (nskb) {
  604. struct llc_sap *sap = llc->sap;
  605. llc_pdu_header_init(nskb, LLC_PDU_TYPE_S, sap->laddr.lsap,
  606. llc->daddr.lsap, LLC_PDU_RSP);
  607. llc_pdu_init_as_rr_rsp(nskb, 1, llc->vR);
  608. rc = llc_mac_hdr_init(nskb, llc->dev->dev_addr, llc->daddr.mac);
  609. if (unlikely(rc))
  610. goto free;
  611. llc_conn_send_pdu(sk, nskb);
  612. }
  613. out:
  614. return rc;
  615. free:
  616. kfree_skb(nskb);
  617. goto out;
  618. }
  619. int llc_conn_ac_send_rr_xxx_x_set_0(struct sock *sk, struct sk_buff *skb)
  620. {
  621. int rc = -ENOBUFS;
  622. struct llc_sock *llc = llc_sk(sk);
  623. struct sk_buff *nskb = llc_alloc_frame(sk, llc->dev);
  624. if (nskb) {
  625. struct llc_sap *sap = llc->sap;
  626. llc_pdu_header_init(nskb, LLC_PDU_TYPE_S, sap->laddr.lsap,
  627. llc->daddr.lsap, LLC_PDU_RSP);
  628. llc_pdu_init_as_rr_rsp(nskb, 0, llc->vR);
  629. rc = llc_mac_hdr_init(nskb, llc->dev->dev_addr, llc->daddr.mac);
  630. if (unlikely(rc))
  631. goto free;
  632. llc_conn_send_pdu(sk, nskb);
  633. }
  634. out:
  635. return rc;
  636. free:
  637. kfree_skb(nskb);
  638. goto out;
  639. }
  640. int llc_conn_ac_send_ack_xxx_x_set_0(struct sock *sk, struct sk_buff *skb)
  641. {
  642. int rc = -ENOBUFS;
  643. struct llc_sock *llc = llc_sk(sk);
  644. struct sk_buff *nskb = llc_alloc_frame(sk, llc->dev);
  645. if (nskb) {
  646. struct llc_sap *sap = llc->sap;
  647. llc_pdu_header_init(nskb, LLC_PDU_TYPE_S, sap->laddr.lsap,
  648. llc->daddr.lsap, LLC_PDU_RSP);
  649. llc_pdu_init_as_rr_rsp(nskb, 0, llc->vR);
  650. rc = llc_mac_hdr_init(nskb, llc->dev->dev_addr, llc->daddr.mac);
  651. if (unlikely(rc))
  652. goto free;
  653. llc_conn_send_pdu(sk, nskb);
  654. }
  655. out:
  656. return rc;
  657. free:
  658. kfree_skb(nskb);
  659. goto out;
  660. }
  661. void llc_conn_set_p_flag(struct sock *sk, u8 value)
  662. {
  663. int state_changed = llc_sk(sk)->p_flag && !value;
  664. llc_sk(sk)->p_flag = value;
  665. if (state_changed)
  666. sk->sk_state_change(sk);
  667. }
  668. int llc_conn_ac_send_sabme_cmd_p_set_x(struct sock *sk, struct sk_buff *skb)
  669. {
  670. int rc = -ENOBUFS;
  671. struct llc_sock *llc = llc_sk(sk);
  672. struct sk_buff *nskb = llc_alloc_frame(sk, llc->dev);
  673. if (nskb) {
  674. struct llc_sap *sap = llc->sap;
  675. u8 *dmac = llc->daddr.mac;
  676. if (llc->dev->flags & IFF_LOOPBACK)
  677. dmac = llc->dev->dev_addr;
  678. llc_pdu_header_init(nskb, LLC_PDU_TYPE_U, sap->laddr.lsap,
  679. llc->daddr.lsap, LLC_PDU_CMD);
  680. llc_pdu_init_as_sabme_cmd(nskb, 1);
  681. rc = llc_mac_hdr_init(nskb, llc->dev->dev_addr, dmac);
  682. if (unlikely(rc))
  683. goto free;
  684. llc_conn_send_pdu(sk, nskb);
  685. llc_conn_set_p_flag(sk, 1);
  686. }
  687. out:
  688. return rc;
  689. free:
  690. kfree_skb(nskb);
  691. goto out;
  692. }
  693. int llc_conn_ac_send_ua_rsp_f_set_p(struct sock *sk, struct sk_buff *skb)
  694. {
  695. u8 f_bit;
  696. int rc = -ENOBUFS;
  697. struct llc_sock *llc = llc_sk(sk);
  698. struct sk_buff *nskb = llc_alloc_frame(sk, llc->dev);
  699. llc_pdu_decode_pf_bit(skb, &f_bit);
  700. if (nskb) {
  701. struct llc_sap *sap = llc->sap;
  702. nskb->dev = llc->dev;
  703. llc_pdu_header_init(nskb, LLC_PDU_TYPE_U, sap->laddr.lsap,
  704. llc->daddr.lsap, LLC_PDU_RSP);
  705. llc_pdu_init_as_ua_rsp(nskb, f_bit);
  706. rc = llc_mac_hdr_init(nskb, llc->dev->dev_addr, llc->daddr.mac);
  707. if (unlikely(rc))
  708. goto free;
  709. llc_conn_send_pdu(sk, nskb);
  710. }
  711. out:
  712. return rc;
  713. free:
  714. kfree_skb(nskb);
  715. goto out;
  716. }
  717. int llc_conn_ac_set_s_flag_0(struct sock *sk, struct sk_buff *skb)
  718. {
  719. llc_sk(sk)->s_flag = 0;
  720. return 0;
  721. }
  722. int llc_conn_ac_set_s_flag_1(struct sock *sk, struct sk_buff *skb)
  723. {
  724. llc_sk(sk)->s_flag = 1;
  725. return 0;
  726. }
  727. int llc_conn_ac_start_p_timer(struct sock *sk, struct sk_buff *skb)
  728. {
  729. struct llc_sock *llc = llc_sk(sk);
  730. llc_conn_set_p_flag(sk, 1);
  731. mod_timer(&llc->pf_cycle_timer.timer,
  732. jiffies + llc->pf_cycle_timer.expire);
  733. return 0;
  734. }
  735. /**
  736. * llc_conn_ac_send_ack_if_needed - check if ack is needed
  737. * @sk: current connection structure
  738. * @skb: current event
  739. *
  740. * Checks number of received PDUs which have not been acknowledged, yet,
  741. * If number of them reaches to "npta"(Number of PDUs To Acknowledge) then
  742. * sends an RR response as acknowledgement for them. Returns 0 for
  743. * success, 1 otherwise.
  744. */
  745. int llc_conn_ac_send_ack_if_needed(struct sock *sk, struct sk_buff *skb)
  746. {
  747. u8 pf_bit;
  748. struct llc_sock *llc = llc_sk(sk);
  749. llc_pdu_decode_pf_bit(skb, &pf_bit);
  750. llc->ack_pf |= pf_bit & 1;
  751. if (!llc->ack_must_be_send) {
  752. llc->first_pdu_Ns = llc->vR;
  753. llc->ack_must_be_send = 1;
  754. llc->ack_pf = pf_bit & 1;
  755. }
  756. if (((llc->vR - llc->first_pdu_Ns + 1 + LLC_2_SEQ_NBR_MODULO)
  757. % LLC_2_SEQ_NBR_MODULO) >= llc->npta) {
  758. llc_conn_ac_send_rr_rsp_f_set_ackpf(sk, skb);
  759. llc->ack_must_be_send = 0;
  760. llc->ack_pf = 0;
  761. llc_conn_ac_inc_npta_value(sk, skb);
  762. }
  763. return 0;
  764. }
  765. /**
  766. * llc_conn_ac_rst_sendack_flag - resets ack_must_be_send flag
  767. * @sk: current connection structure
  768. * @skb: current event
  769. *
  770. * This action resets ack_must_be_send flag of given connection, this flag
  771. * indicates if there is any PDU which has not been acknowledged yet.
  772. * Returns 0 for success, 1 otherwise.
  773. */
  774. int llc_conn_ac_rst_sendack_flag(struct sock *sk, struct sk_buff *skb)
  775. {
  776. llc_sk(sk)->ack_must_be_send = llc_sk(sk)->ack_pf = 0;
  777. return 0;
  778. }
  779. /**
  780. * llc_conn_ac_send_i_rsp_f_set_ackpf - acknowledge received PDUs
  781. * @sk: current connection structure
  782. * @skb: current event
  783. *
  784. * Sends an I response PDU with f-bit set to ack_pf flag as acknowledge to
  785. * all received PDUs which have not been acknowledged, yet. ack_pf flag is
  786. * set to one if one PDU with p-bit set to one is received. Returns 0 for
  787. * success, 1 otherwise.
  788. */
  789. static int llc_conn_ac_send_i_rsp_f_set_ackpf(struct sock *sk,
  790. struct sk_buff *skb)
  791. {
  792. int rc;
  793. struct llc_sock *llc = llc_sk(sk);
  794. struct llc_sap *sap = llc->sap;
  795. llc_pdu_header_init(skb, LLC_PDU_TYPE_I, sap->laddr.lsap,
  796. llc->daddr.lsap, LLC_PDU_RSP);
  797. llc_pdu_init_as_i_cmd(skb, llc->ack_pf, llc->vS, llc->vR);
  798. rc = llc_mac_hdr_init(skb, llc->dev->dev_addr, llc->daddr.mac);
  799. if (likely(!rc)) {
  800. llc_conn_send_pdu(sk, skb);
  801. llc_conn_ac_inc_vs_by_1(sk, skb);
  802. }
  803. return rc;
  804. }
  805. /**
  806. * llc_conn_ac_send_i_as_ack - sends an I-format PDU to acknowledge rx PDUs
  807. * @sk: current connection structure.
  808. * @skb: current event.
  809. *
  810. * This action sends an I-format PDU as acknowledge to received PDUs which
  811. * have not been acknowledged, yet, if there is any. By using of this
  812. * action number of acknowledgements decreases, this technic is called
  813. * piggy backing. Returns 0 for success, 1 otherwise.
  814. */
  815. int llc_conn_ac_send_i_as_ack(struct sock *sk, struct sk_buff *skb)
  816. {
  817. struct llc_sock *llc = llc_sk(sk);
  818. if (llc->ack_must_be_send) {
  819. llc_conn_ac_send_i_rsp_f_set_ackpf(sk, skb);
  820. llc->ack_must_be_send = 0 ;
  821. llc->ack_pf = 0;
  822. } else
  823. llc_conn_ac_send_i_cmd_p_set_0(sk, skb);
  824. return 0;
  825. }
  826. /**
  827. * llc_conn_ac_send_rr_rsp_f_set_ackpf - ack all rx PDUs not yet acked
  828. * @sk: current connection structure.
  829. * @skb: current event.
  830. *
  831. * This action sends an RR response with f-bit set to ack_pf flag as
  832. * acknowledge to all received PDUs which have not been acknowledged, yet,
  833. * if there is any. ack_pf flag indicates if a PDU has been received with
  834. * p-bit set to one. Returns 0 for success, 1 otherwise.
  835. */
  836. static int llc_conn_ac_send_rr_rsp_f_set_ackpf(struct sock *sk,
  837. struct sk_buff *skb)
  838. {
  839. int rc = -ENOBUFS;
  840. struct llc_sock *llc = llc_sk(sk);
  841. struct sk_buff *nskb = llc_alloc_frame(sk, llc->dev);
  842. if (nskb) {
  843. struct llc_sap *sap = llc->sap;
  844. llc_pdu_header_init(nskb, LLC_PDU_TYPE_S, sap->laddr.lsap,
  845. llc->daddr.lsap, LLC_PDU_RSP);
  846. llc_pdu_init_as_rr_rsp(nskb, llc->ack_pf, llc->vR);
  847. rc = llc_mac_hdr_init(nskb, llc->dev->dev_addr, llc->daddr.mac);
  848. if (unlikely(rc))
  849. goto free;
  850. llc_conn_send_pdu(sk, nskb);
  851. }
  852. out:
  853. return rc;
  854. free:
  855. kfree_skb(nskb);
  856. goto out;
  857. }
  858. /**
  859. * llc_conn_ac_inc_npta_value - tries to make value of npta greater
  860. * @sk: current connection structure.
  861. * @skb: current event.
  862. *
  863. * After "inc_cntr" times calling of this action, "npta" increase by one.
  864. * this action tries to make vale of "npta" greater as possible; number of
  865. * acknowledgements decreases by increasing of "npta". Returns 0 for
  866. * success, 1 otherwise.
  867. */
  868. static int llc_conn_ac_inc_npta_value(struct sock *sk, struct sk_buff *skb)
  869. {
  870. struct llc_sock *llc = llc_sk(sk);
  871. if (!llc->inc_cntr) {
  872. llc->dec_step = 0;
  873. llc->dec_cntr = llc->inc_cntr = 2;
  874. ++llc->npta;
  875. if (llc->npta > (u8) ~LLC_2_SEQ_NBR_MODULO)
  876. llc->npta = (u8) ~LLC_2_SEQ_NBR_MODULO;
  877. } else
  878. --llc->inc_cntr;
  879. return 0;
  880. }
  881. /**
  882. * llc_conn_ac_adjust_npta_by_rr - decreases "npta" by one
  883. * @sk: current connection structure.
  884. * @skb: current event.
  885. *
  886. * After receiving "dec_cntr" times RR command, this action decreases
  887. * "npta" by one. Returns 0 for success, 1 otherwise.
  888. */
  889. int llc_conn_ac_adjust_npta_by_rr(struct sock *sk, struct sk_buff *skb)
  890. {
  891. struct llc_sock *llc = llc_sk(sk);
  892. if (!llc->connect_step && !llc->remote_busy_flag) {
  893. if (!llc->dec_step) {
  894. if (!llc->dec_cntr) {
  895. llc->inc_cntr = llc->dec_cntr = 2;
  896. if (llc->npta > 0)
  897. llc->npta = llc->npta - 1;
  898. } else
  899. llc->dec_cntr -=1;
  900. }
  901. } else
  902. llc->connect_step = 0 ;
  903. return 0;
  904. }
  905. /**
  906. * llc_conn_ac_adjust_npta_by_rnr - decreases "npta" by one
  907. * @sk: current connection structure.
  908. * @skb: current event.
  909. *
  910. * After receiving "dec_cntr" times RNR command, this action decreases
  911. * "npta" by one. Returns 0 for success, 1 otherwise.
  912. */
  913. int llc_conn_ac_adjust_npta_by_rnr(struct sock *sk, struct sk_buff *skb)
  914. {
  915. struct llc_sock *llc = llc_sk(sk);
  916. if (llc->remote_busy_flag)
  917. if (!llc->dec_step) {
  918. if (!llc->dec_cntr) {
  919. llc->inc_cntr = llc->dec_cntr = 2;
  920. if (llc->npta > 0)
  921. --llc->npta;
  922. } else
  923. --llc->dec_cntr;
  924. }
  925. return 0;
  926. }
  927. /**
  928. * llc_conn_ac_dec_tx_win_size - decreases tx window size
  929. * @sk: current connection structure.
  930. * @skb: current event.
  931. *
  932. * After receiving of a REJ command or response, transmit window size is
  933. * decreased by number of PDUs which are outstanding yet. Returns 0 for
  934. * success, 1 otherwise.
  935. */
  936. int llc_conn_ac_dec_tx_win_size(struct sock *sk, struct sk_buff *skb)
  937. {
  938. struct llc_sock *llc = llc_sk(sk);
  939. u8 unacked_pdu = skb_queue_len(&llc->pdu_unack_q);
  940. if (llc->k - unacked_pdu < 1)
  941. llc->k = 1;
  942. else
  943. llc->k -= unacked_pdu;
  944. return 0;
  945. }
  946. /**
  947. * llc_conn_ac_inc_tx_win_size - tx window size is inc by 1
  948. * @sk: current connection structure.
  949. * @skb: current event.
  950. *
  951. * After receiving an RR response with f-bit set to one, transmit window
  952. * size is increased by one. Returns 0 for success, 1 otherwise.
  953. */
  954. int llc_conn_ac_inc_tx_win_size(struct sock *sk, struct sk_buff *skb)
  955. {
  956. struct llc_sock *llc = llc_sk(sk);
  957. llc->k += 1;
  958. if (llc->k > (u8) ~LLC_2_SEQ_NBR_MODULO)
  959. llc->k = (u8) ~LLC_2_SEQ_NBR_MODULO;
  960. return 0;
  961. }
  962. int llc_conn_ac_stop_all_timers(struct sock *sk, struct sk_buff *skb)
  963. {
  964. struct llc_sock *llc = llc_sk(sk);
  965. del_timer(&llc->pf_cycle_timer.timer);
  966. del_timer(&llc->ack_timer.timer);
  967. del_timer(&llc->rej_sent_timer.timer);
  968. del_timer(&llc->busy_state_timer.timer);
  969. llc->ack_must_be_send = 0;
  970. llc->ack_pf = 0;
  971. return 0;
  972. }
  973. int llc_conn_ac_stop_other_timers(struct sock *sk, struct sk_buff *skb)
  974. {
  975. struct llc_sock *llc = llc_sk(sk);
  976. del_timer(&llc->rej_sent_timer.timer);
  977. del_timer(&llc->pf_cycle_timer.timer);
  978. del_timer(&llc->busy_state_timer.timer);
  979. llc->ack_must_be_send = 0;
  980. llc->ack_pf = 0;
  981. return 0;
  982. }
  983. int llc_conn_ac_start_ack_timer(struct sock *sk, struct sk_buff *skb)
  984. {
  985. struct llc_sock *llc = llc_sk(sk);
  986. mod_timer(&llc->ack_timer.timer, jiffies + llc->ack_timer.expire);
  987. return 0;
  988. }
  989. int llc_conn_ac_start_rej_timer(struct sock *sk, struct sk_buff *skb)
  990. {
  991. struct llc_sock *llc = llc_sk(sk);
  992. mod_timer(&llc->rej_sent_timer.timer,
  993. jiffies + llc->rej_sent_timer.expire);
  994. return 0;
  995. }
  996. int llc_conn_ac_start_ack_tmr_if_not_running(struct sock *sk,
  997. struct sk_buff *skb)
  998. {
  999. struct llc_sock *llc = llc_sk(sk);
  1000. if (!timer_pending(&llc->ack_timer.timer))
  1001. mod_timer(&llc->ack_timer.timer,
  1002. jiffies + llc->ack_timer.expire);
  1003. return 0;
  1004. }
  1005. int llc_conn_ac_stop_ack_timer(struct sock *sk, struct sk_buff *skb)
  1006. {
  1007. del_timer(&llc_sk(sk)->ack_timer.timer);
  1008. return 0;
  1009. }
  1010. int llc_conn_ac_stop_p_timer(struct sock *sk, struct sk_buff *skb)
  1011. {
  1012. struct llc_sock *llc = llc_sk(sk);
  1013. del_timer(&llc->pf_cycle_timer.timer);
  1014. llc_conn_set_p_flag(sk, 0);
  1015. return 0;
  1016. }
  1017. int llc_conn_ac_stop_rej_timer(struct sock *sk, struct sk_buff *skb)
  1018. {
  1019. del_timer(&llc_sk(sk)->rej_sent_timer.timer);
  1020. return 0;
  1021. }
  1022. int llc_conn_ac_upd_nr_received(struct sock *sk, struct sk_buff *skb)
  1023. {
  1024. int acked;
  1025. u16 unacked = 0;
  1026. struct llc_pdu_sn *pdu = llc_pdu_sn_hdr(skb);
  1027. struct llc_sock *llc = llc_sk(sk);
  1028. llc->last_nr = PDU_SUPV_GET_Nr(pdu);
  1029. acked = llc_conn_remove_acked_pdus(sk, llc->last_nr, &unacked);
  1030. /* On loopback we don't queue I frames in unack_pdu_q queue. */
  1031. if (acked > 0 || (llc->dev->flags & IFF_LOOPBACK)) {
  1032. llc->retry_count = 0;
  1033. del_timer(&llc->ack_timer.timer);
  1034. if (llc->failed_data_req) {
  1035. /* already, we did not accept data from upper layer
  1036. * (tx_window full or unacceptable state). Now, we
  1037. * can send data and must inform to upper layer.
  1038. */
  1039. llc->failed_data_req = 0;
  1040. llc_conn_ac_data_confirm(sk, skb);
  1041. }
  1042. if (unacked)
  1043. mod_timer(&llc->ack_timer.timer,
  1044. jiffies + llc->ack_timer.expire);
  1045. } else if (llc->failed_data_req) {
  1046. u8 f_bit;
  1047. llc_pdu_decode_pf_bit(skb, &f_bit);
  1048. if (f_bit == 1) {
  1049. llc->failed_data_req = 0;
  1050. llc_conn_ac_data_confirm(sk, skb);
  1051. }
  1052. }
  1053. return 0;
  1054. }
  1055. int llc_conn_ac_upd_p_flag(struct sock *sk, struct sk_buff *skb)
  1056. {
  1057. struct llc_pdu_sn *pdu = llc_pdu_sn_hdr(skb);
  1058. if (LLC_PDU_IS_RSP(pdu)) {
  1059. u8 f_bit;
  1060. llc_pdu_decode_pf_bit(skb, &f_bit);
  1061. if (f_bit) {
  1062. llc_conn_set_p_flag(sk, 0);
  1063. llc_conn_ac_stop_p_timer(sk, skb);
  1064. }
  1065. }
  1066. return 0;
  1067. }
  1068. int llc_conn_ac_set_data_flag_2(struct sock *sk, struct sk_buff *skb)
  1069. {
  1070. llc_sk(sk)->data_flag = 2;
  1071. return 0;
  1072. }
  1073. int llc_conn_ac_set_data_flag_0(struct sock *sk, struct sk_buff *skb)
  1074. {
  1075. llc_sk(sk)->data_flag = 0;
  1076. return 0;
  1077. }
  1078. int llc_conn_ac_set_data_flag_1(struct sock *sk, struct sk_buff *skb)
  1079. {
  1080. llc_sk(sk)->data_flag = 1;
  1081. return 0;
  1082. }
  1083. int llc_conn_ac_set_data_flag_1_if_data_flag_eq_0(struct sock *sk,
  1084. struct sk_buff *skb)
  1085. {
  1086. if (!llc_sk(sk)->data_flag)
  1087. llc_sk(sk)->data_flag = 1;
  1088. return 0;
  1089. }
  1090. int llc_conn_ac_set_p_flag_0(struct sock *sk, struct sk_buff *skb)
  1091. {
  1092. llc_conn_set_p_flag(sk, 0);
  1093. return 0;
  1094. }
  1095. static int llc_conn_ac_set_p_flag_1(struct sock *sk, struct sk_buff *skb)
  1096. {
  1097. llc_conn_set_p_flag(sk, 1);
  1098. return 0;
  1099. }
  1100. int llc_conn_ac_set_remote_busy_0(struct sock *sk, struct sk_buff *skb)
  1101. {
  1102. llc_sk(sk)->remote_busy_flag = 0;
  1103. return 0;
  1104. }
  1105. int llc_conn_ac_set_cause_flag_0(struct sock *sk, struct sk_buff *skb)
  1106. {
  1107. llc_sk(sk)->cause_flag = 0;
  1108. return 0;
  1109. }
  1110. int llc_conn_ac_set_cause_flag_1(struct sock *sk, struct sk_buff *skb)
  1111. {
  1112. llc_sk(sk)->cause_flag = 1;
  1113. return 0;
  1114. }
  1115. int llc_conn_ac_set_retry_cnt_0(struct sock *sk, struct sk_buff *skb)
  1116. {
  1117. llc_sk(sk)->retry_count = 0;
  1118. return 0;
  1119. }
  1120. int llc_conn_ac_inc_retry_cnt_by_1(struct sock *sk, struct sk_buff *skb)
  1121. {
  1122. llc_sk(sk)->retry_count++;
  1123. return 0;
  1124. }
  1125. int llc_conn_ac_set_vr_0(struct sock *sk, struct sk_buff *skb)
  1126. {
  1127. llc_sk(sk)->vR = 0;
  1128. return 0;
  1129. }
  1130. int llc_conn_ac_inc_vr_by_1(struct sock *sk, struct sk_buff *skb)
  1131. {
  1132. llc_sk(sk)->vR = PDU_GET_NEXT_Vr(llc_sk(sk)->vR);
  1133. return 0;
  1134. }
  1135. int llc_conn_ac_set_vs_0(struct sock *sk, struct sk_buff *skb)
  1136. {
  1137. llc_sk(sk)->vS = 0;
  1138. return 0;
  1139. }
  1140. int llc_conn_ac_set_vs_nr(struct sock *sk, struct sk_buff *skb)
  1141. {
  1142. llc_sk(sk)->vS = llc_sk(sk)->last_nr;
  1143. return 0;
  1144. }
  1145. static int llc_conn_ac_inc_vs_by_1(struct sock *sk, struct sk_buff *skb)
  1146. {
  1147. llc_sk(sk)->vS = (llc_sk(sk)->vS + 1) % LLC_2_SEQ_NBR_MODULO;
  1148. return 0;
  1149. }
  1150. static void llc_conn_tmr_common_cb(unsigned long timeout_data, u8 type)
  1151. {
  1152. struct sock *sk = (struct sock *)timeout_data;
  1153. struct sk_buff *skb = alloc_skb(0, GFP_ATOMIC);
  1154. bh_lock_sock(sk);
  1155. if (skb) {
  1156. struct llc_conn_state_ev *ev = llc_conn_ev(skb);
  1157. skb_set_owner_r(skb, sk);
  1158. ev->type = type;
  1159. llc_process_tmr_ev(sk, skb);
  1160. }
  1161. bh_unlock_sock(sk);
  1162. }
  1163. void llc_conn_pf_cycle_tmr_cb(unsigned long timeout_data)
  1164. {
  1165. llc_conn_tmr_common_cb(timeout_data, LLC_CONN_EV_TYPE_P_TMR);
  1166. }
  1167. void llc_conn_busy_tmr_cb(unsigned long timeout_data)
  1168. {
  1169. llc_conn_tmr_common_cb(timeout_data, LLC_CONN_EV_TYPE_BUSY_TMR);
  1170. }
  1171. void llc_conn_ack_tmr_cb(unsigned long timeout_data)
  1172. {
  1173. llc_conn_tmr_common_cb(timeout_data, LLC_CONN_EV_TYPE_ACK_TMR);
  1174. }
  1175. void llc_conn_rej_tmr_cb(unsigned long timeout_data)
  1176. {
  1177. llc_conn_tmr_common_cb(timeout_data, LLC_CONN_EV_TYPE_REJ_TMR);
  1178. }
  1179. int llc_conn_ac_rst_vs(struct sock *sk, struct sk_buff *skb)
  1180. {
  1181. llc_sk(sk)->X = llc_sk(sk)->vS;
  1182. llc_conn_ac_set_vs_nr(sk, skb);
  1183. return 0;
  1184. }
  1185. int llc_conn_ac_upd_vs(struct sock *sk, struct sk_buff *skb)
  1186. {
  1187. struct llc_pdu_sn *pdu = llc_pdu_sn_hdr(skb);
  1188. u8 nr = PDU_SUPV_GET_Nr(pdu);
  1189. if (llc_circular_between(llc_sk(sk)->vS, nr, llc_sk(sk)->X))
  1190. llc_conn_ac_set_vs_nr(sk, skb);
  1191. return 0;
  1192. }
  1193. /*
  1194. * Non-standard actions; these not contained in IEEE specification; for
  1195. * our own usage
  1196. */
  1197. /**
  1198. * llc_conn_disc - removes connection from SAP list and frees it
  1199. * @sk: closed connection
  1200. * @skb: occurred event
  1201. */
  1202. int llc_conn_disc(struct sock *sk, struct sk_buff *skb)
  1203. {
  1204. /* FIXME: this thing seems to want to die */
  1205. return 0;
  1206. }
  1207. /**
  1208. * llc_conn_reset - resets connection
  1209. * @sk : reseting connection.
  1210. * @skb: occurred event.
  1211. *
  1212. * Stop all timers, empty all queues and reset all flags.
  1213. */
  1214. int llc_conn_reset(struct sock *sk, struct sk_buff *skb)
  1215. {
  1216. llc_sk_reset(sk);
  1217. return 0;
  1218. }
  1219. /**
  1220. * llc_circular_between - designates that b is between a and c or not
  1221. * @a: lower bound
  1222. * @b: element to see if is between a and b
  1223. * @c: upper bound
  1224. *
  1225. * This function designates that b is between a and c or not (for example,
  1226. * 0 is between 127 and 1). Returns 1 if b is between a and c, 0
  1227. * otherwise.
  1228. */
  1229. u8 llc_circular_between(u8 a, u8 b, u8 c)
  1230. {
  1231. b = b - a;
  1232. c = c - a;
  1233. return b <= c;
  1234. }
  1235. /**
  1236. * llc_process_tmr_ev - timer backend
  1237. * @sk: active connection
  1238. * @skb: occurred event
  1239. *
  1240. * This function is called from timer callback functions. When connection
  1241. * is busy (during sending a data frame) timer expiration event must be
  1242. * queued. Otherwise this event can be sent to connection state machine.
  1243. * Queued events will process by llc_backlog_rcv function after sending
  1244. * data frame.
  1245. */
  1246. static void llc_process_tmr_ev(struct sock *sk, struct sk_buff *skb)
  1247. {
  1248. if (llc_sk(sk)->state == LLC_CONN_OUT_OF_SVC) {
  1249. printk(KERN_WARNING "%s: timer called on closed connection\n",
  1250. __FUNCTION__);
  1251. kfree_skb(skb);
  1252. } else {
  1253. if (!sock_owned_by_user(sk))
  1254. llc_conn_state_process(sk, skb);
  1255. else {
  1256. llc_set_backlog_type(skb, LLC_EVENT);
  1257. sk_add_backlog(sk, skb);
  1258. }
  1259. }
  1260. }