llc_c_ac.c 35 KB

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