llc_c_ac.c 35 KB

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