llc_c_ac.c 35 KB

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