llc_c_ac.c 35 KB

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