llc_c_ac.c 35 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445
  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. llc_conn_send_pdu(sk, skb);
  327. llc_conn_ac_inc_vs_by_1(sk, skb);
  328. }
  329. return rc;
  330. }
  331. static int llc_conn_ac_send_i_cmd_p_set_0(struct sock *sk, struct sk_buff *skb)
  332. {
  333. int rc;
  334. struct llc_sock *llc = llc_sk(sk);
  335. struct llc_sap *sap = llc->sap;
  336. llc_pdu_header_init(skb, LLC_PDU_TYPE_I, sap->laddr.lsap,
  337. llc->daddr.lsap, LLC_PDU_CMD);
  338. llc_pdu_init_as_i_cmd(skb, 0, llc->vS, llc->vR);
  339. rc = llc_mac_hdr_init(skb, llc->dev->dev_addr, llc->daddr.mac);
  340. if (likely(!rc)) {
  341. llc_conn_send_pdu(sk, skb);
  342. llc_conn_ac_inc_vs_by_1(sk, skb);
  343. }
  344. return rc;
  345. }
  346. int llc_conn_ac_send_i_xxx_x_set_0(struct sock *sk, struct sk_buff *skb)
  347. {
  348. int rc;
  349. struct llc_sock *llc = llc_sk(sk);
  350. struct llc_sap *sap = llc->sap;
  351. llc_pdu_header_init(skb, LLC_PDU_TYPE_I, sap->laddr.lsap,
  352. llc->daddr.lsap, LLC_PDU_CMD);
  353. llc_pdu_init_as_i_cmd(skb, 0, llc->vS, llc->vR);
  354. rc = llc_mac_hdr_init(skb, llc->dev->dev_addr, llc->daddr.mac);
  355. if (likely(!rc)) {
  356. llc_conn_send_pdu(sk, skb);
  357. llc_conn_ac_inc_vs_by_1(sk, skb);
  358. }
  359. return 0;
  360. }
  361. int llc_conn_ac_resend_i_xxx_x_set_0(struct sock *sk, struct sk_buff *skb)
  362. {
  363. struct llc_pdu_sn *pdu = llc_pdu_sn_hdr(skb);
  364. u8 nr = LLC_I_GET_NR(pdu);
  365. llc_conn_resend_i_pdu_as_cmd(sk, nr, 0);
  366. return 0;
  367. }
  368. int llc_conn_ac_resend_i_xxx_x_set_0_or_send_rr(struct sock *sk,
  369. struct sk_buff *skb)
  370. {
  371. u8 nr;
  372. struct llc_pdu_sn *pdu = llc_pdu_sn_hdr(skb);
  373. int rc = -ENOBUFS;
  374. struct llc_sock *llc = llc_sk(sk);
  375. struct sk_buff *nskb = llc_alloc_frame(sk, llc->dev, LLC_PDU_TYPE_U, 0);
  376. if (nskb) {
  377. struct llc_sap *sap = llc->sap;
  378. llc_pdu_header_init(nskb, LLC_PDU_TYPE_U, sap->laddr.lsap,
  379. llc->daddr.lsap, LLC_PDU_RSP);
  380. llc_pdu_init_as_rr_rsp(nskb, 0, llc->vR);
  381. rc = llc_mac_hdr_init(nskb, llc->dev->dev_addr, llc->daddr.mac);
  382. if (likely(!rc))
  383. llc_conn_send_pdu(sk, nskb);
  384. else
  385. kfree_skb(skb);
  386. }
  387. if (rc) {
  388. nr = LLC_I_GET_NR(pdu);
  389. rc = 0;
  390. llc_conn_resend_i_pdu_as_cmd(sk, nr, 0);
  391. }
  392. return rc;
  393. }
  394. int llc_conn_ac_resend_i_rsp_f_set_1(struct sock *sk, struct sk_buff *skb)
  395. {
  396. struct llc_pdu_sn *pdu = llc_pdu_sn_hdr(skb);
  397. u8 nr = LLC_I_GET_NR(pdu);
  398. llc_conn_resend_i_pdu_as_rsp(sk, nr, 1);
  399. return 0;
  400. }
  401. int llc_conn_ac_send_rej_cmd_p_set_1(struct sock *sk, struct sk_buff *skb)
  402. {
  403. int rc = -ENOBUFS;
  404. struct llc_sock *llc = llc_sk(sk);
  405. struct sk_buff *nskb = llc_alloc_frame(sk, llc->dev, LLC_PDU_TYPE_S, 0);
  406. if (nskb) {
  407. struct llc_sap *sap = llc->sap;
  408. llc_pdu_header_init(nskb, LLC_PDU_TYPE_S, sap->laddr.lsap,
  409. llc->daddr.lsap, LLC_PDU_CMD);
  410. llc_pdu_init_as_rej_cmd(nskb, 1, llc->vR);
  411. rc = llc_mac_hdr_init(nskb, llc->dev->dev_addr, llc->daddr.mac);
  412. if (unlikely(rc))
  413. goto free;
  414. llc_conn_send_pdu(sk, nskb);
  415. }
  416. out:
  417. return rc;
  418. free:
  419. kfree_skb(nskb);
  420. goto out;
  421. }
  422. int llc_conn_ac_send_rej_rsp_f_set_1(struct sock *sk, struct sk_buff *skb)
  423. {
  424. int rc = -ENOBUFS;
  425. struct llc_sock *llc = llc_sk(sk);
  426. struct sk_buff *nskb = llc_alloc_frame(sk, llc->dev, LLC_PDU_TYPE_S, 0);
  427. if (nskb) {
  428. struct llc_sap *sap = llc->sap;
  429. llc_pdu_header_init(nskb, LLC_PDU_TYPE_S, sap->laddr.lsap,
  430. llc->daddr.lsap, LLC_PDU_RSP);
  431. llc_pdu_init_as_rej_rsp(nskb, 1, llc->vR);
  432. rc = llc_mac_hdr_init(nskb, llc->dev->dev_addr, llc->daddr.mac);
  433. if (unlikely(rc))
  434. goto free;
  435. llc_conn_send_pdu(sk, nskb);
  436. }
  437. out:
  438. return rc;
  439. free:
  440. kfree_skb(nskb);
  441. goto out;
  442. }
  443. int llc_conn_ac_send_rej_xxx_x_set_0(struct sock *sk, struct sk_buff *skb)
  444. {
  445. int rc = -ENOBUFS;
  446. struct llc_sock *llc = llc_sk(sk);
  447. struct sk_buff *nskb = llc_alloc_frame(sk, llc->dev, LLC_PDU_TYPE_S, 0);
  448. if (nskb) {
  449. struct llc_sap *sap = llc->sap;
  450. llc_pdu_header_init(nskb, LLC_PDU_TYPE_S, sap->laddr.lsap,
  451. llc->daddr.lsap, LLC_PDU_RSP);
  452. llc_pdu_init_as_rej_rsp(nskb, 0, llc->vR);
  453. rc = llc_mac_hdr_init(nskb, llc->dev->dev_addr, llc->daddr.mac);
  454. if (unlikely(rc))
  455. goto free;
  456. llc_conn_send_pdu(sk, nskb);
  457. }
  458. out:
  459. return rc;
  460. free:
  461. kfree_skb(nskb);
  462. goto out;
  463. }
  464. int llc_conn_ac_send_rnr_cmd_p_set_1(struct sock *sk, struct sk_buff *skb)
  465. {
  466. int rc = -ENOBUFS;
  467. struct llc_sock *llc = llc_sk(sk);
  468. struct sk_buff *nskb = llc_alloc_frame(sk, llc->dev, LLC_PDU_TYPE_S, 0);
  469. if (nskb) {
  470. struct llc_sap *sap = llc->sap;
  471. llc_pdu_header_init(nskb, LLC_PDU_TYPE_S, sap->laddr.lsap,
  472. llc->daddr.lsap, LLC_PDU_CMD);
  473. llc_pdu_init_as_rnr_cmd(nskb, 1, llc->vR);
  474. rc = llc_mac_hdr_init(nskb, llc->dev->dev_addr, llc->daddr.mac);
  475. if (unlikely(rc))
  476. goto free;
  477. llc_conn_send_pdu(sk, nskb);
  478. }
  479. out:
  480. return rc;
  481. free:
  482. kfree_skb(nskb);
  483. goto out;
  484. }
  485. int llc_conn_ac_send_rnr_rsp_f_set_1(struct sock *sk, struct sk_buff *skb)
  486. {
  487. int rc = -ENOBUFS;
  488. struct llc_sock *llc = llc_sk(sk);
  489. struct sk_buff *nskb = llc_alloc_frame(sk, llc->dev, LLC_PDU_TYPE_S, 0);
  490. if (nskb) {
  491. struct llc_sap *sap = llc->sap;
  492. llc_pdu_header_init(nskb, LLC_PDU_TYPE_S, sap->laddr.lsap,
  493. llc->daddr.lsap, LLC_PDU_RSP);
  494. llc_pdu_init_as_rnr_rsp(nskb, 1, llc->vR);
  495. rc = llc_mac_hdr_init(nskb, llc->dev->dev_addr, llc->daddr.mac);
  496. if (unlikely(rc))
  497. goto free;
  498. llc_conn_send_pdu(sk, nskb);
  499. }
  500. out:
  501. return rc;
  502. free:
  503. kfree_skb(nskb);
  504. goto out;
  505. }
  506. int llc_conn_ac_send_rnr_xxx_x_set_0(struct sock *sk, struct sk_buff *skb)
  507. {
  508. int rc = -ENOBUFS;
  509. struct llc_sock *llc = llc_sk(sk);
  510. struct sk_buff *nskb = llc_alloc_frame(sk, llc->dev, LLC_PDU_TYPE_S, 0);
  511. if (nskb) {
  512. struct llc_sap *sap = llc->sap;
  513. llc_pdu_header_init(nskb, LLC_PDU_TYPE_S, sap->laddr.lsap,
  514. llc->daddr.lsap, LLC_PDU_RSP);
  515. llc_pdu_init_as_rnr_rsp(nskb, 0, llc->vR);
  516. rc = llc_mac_hdr_init(nskb, llc->dev->dev_addr, llc->daddr.mac);
  517. if (unlikely(rc))
  518. goto free;
  519. llc_conn_send_pdu(sk, nskb);
  520. }
  521. out:
  522. return rc;
  523. free:
  524. kfree_skb(nskb);
  525. goto out;
  526. }
  527. int llc_conn_ac_set_remote_busy(struct sock *sk, struct sk_buff *skb)
  528. {
  529. struct llc_sock *llc = llc_sk(sk);
  530. if (!llc->remote_busy_flag) {
  531. llc->remote_busy_flag = 1;
  532. mod_timer(&llc->busy_state_timer.timer,
  533. jiffies + llc->busy_state_timer.expire);
  534. }
  535. return 0;
  536. }
  537. int llc_conn_ac_opt_send_rnr_xxx_x_set_0(struct sock *sk, struct sk_buff *skb)
  538. {
  539. int rc = -ENOBUFS;
  540. struct llc_sock *llc = llc_sk(sk);
  541. struct sk_buff *nskb = llc_alloc_frame(sk, llc->dev, LLC_PDU_TYPE_S, 0);
  542. if (nskb) {
  543. struct llc_sap *sap = llc->sap;
  544. llc_pdu_header_init(nskb, LLC_PDU_TYPE_S, sap->laddr.lsap,
  545. llc->daddr.lsap, LLC_PDU_RSP);
  546. llc_pdu_init_as_rnr_rsp(nskb, 0, llc->vR);
  547. rc = llc_mac_hdr_init(nskb, llc->dev->dev_addr, llc->daddr.mac);
  548. if (unlikely(rc))
  549. goto free;
  550. llc_conn_send_pdu(sk, nskb);
  551. }
  552. out:
  553. return rc;
  554. free:
  555. kfree_skb(nskb);
  556. goto out;
  557. }
  558. int llc_conn_ac_send_rr_cmd_p_set_1(struct sock *sk, struct sk_buff *skb)
  559. {
  560. int rc = -ENOBUFS;
  561. struct llc_sock *llc = llc_sk(sk);
  562. struct sk_buff *nskb = llc_alloc_frame(sk, llc->dev, LLC_PDU_TYPE_S, 0);
  563. if (nskb) {
  564. struct llc_sap *sap = llc->sap;
  565. llc_pdu_header_init(nskb, LLC_PDU_TYPE_S, sap->laddr.lsap,
  566. llc->daddr.lsap, LLC_PDU_CMD);
  567. llc_pdu_init_as_rr_cmd(nskb, 1, llc->vR);
  568. rc = llc_mac_hdr_init(nskb, llc->dev->dev_addr, llc->daddr.mac);
  569. if (unlikely(rc))
  570. goto free;
  571. llc_conn_send_pdu(sk, nskb);
  572. }
  573. out:
  574. return rc;
  575. free:
  576. kfree_skb(nskb);
  577. goto out;
  578. }
  579. int llc_conn_ac_send_rr_rsp_f_set_1(struct sock *sk, struct sk_buff *skb)
  580. {
  581. int rc = -ENOBUFS;
  582. struct llc_sock *llc = llc_sk(sk);
  583. struct sk_buff *nskb = llc_alloc_frame(sk, llc->dev, LLC_PDU_TYPE_S, 0);
  584. if (nskb) {
  585. struct llc_sap *sap = llc->sap;
  586. u8 f_bit = 1;
  587. llc_pdu_header_init(nskb, LLC_PDU_TYPE_S, sap->laddr.lsap,
  588. llc->daddr.lsap, LLC_PDU_RSP);
  589. llc_pdu_init_as_rr_rsp(nskb, f_bit, llc->vR);
  590. rc = llc_mac_hdr_init(nskb, llc->dev->dev_addr, llc->daddr.mac);
  591. if (unlikely(rc))
  592. goto free;
  593. llc_conn_send_pdu(sk, nskb);
  594. }
  595. out:
  596. return rc;
  597. free:
  598. kfree_skb(nskb);
  599. goto out;
  600. }
  601. int llc_conn_ac_send_ack_rsp_f_set_1(struct sock *sk, struct sk_buff *skb)
  602. {
  603. int rc = -ENOBUFS;
  604. struct llc_sock *llc = llc_sk(sk);
  605. struct sk_buff *nskb = llc_alloc_frame(sk, llc->dev, LLC_PDU_TYPE_S, 0);
  606. if (nskb) {
  607. struct llc_sap *sap = llc->sap;
  608. llc_pdu_header_init(nskb, LLC_PDU_TYPE_S, sap->laddr.lsap,
  609. llc->daddr.lsap, LLC_PDU_RSP);
  610. llc_pdu_init_as_rr_rsp(nskb, 1, llc->vR);
  611. rc = llc_mac_hdr_init(nskb, llc->dev->dev_addr, llc->daddr.mac);
  612. if (unlikely(rc))
  613. goto free;
  614. llc_conn_send_pdu(sk, nskb);
  615. }
  616. out:
  617. return rc;
  618. free:
  619. kfree_skb(nskb);
  620. goto out;
  621. }
  622. int llc_conn_ac_send_rr_xxx_x_set_0(struct sock *sk, struct sk_buff *skb)
  623. {
  624. int rc = -ENOBUFS;
  625. struct llc_sock *llc = llc_sk(sk);
  626. struct sk_buff *nskb = llc_alloc_frame(sk, llc->dev, LLC_PDU_TYPE_S, 0);
  627. if (nskb) {
  628. struct llc_sap *sap = llc->sap;
  629. llc_pdu_header_init(nskb, LLC_PDU_TYPE_S, sap->laddr.lsap,
  630. llc->daddr.lsap, LLC_PDU_RSP);
  631. llc_pdu_init_as_rr_rsp(nskb, 0, llc->vR);
  632. rc = llc_mac_hdr_init(nskb, llc->dev->dev_addr, llc->daddr.mac);
  633. if (unlikely(rc))
  634. goto free;
  635. llc_conn_send_pdu(sk, nskb);
  636. }
  637. out:
  638. return rc;
  639. free:
  640. kfree_skb(nskb);
  641. goto out;
  642. }
  643. int llc_conn_ac_send_ack_xxx_x_set_0(struct sock *sk, struct sk_buff *skb)
  644. {
  645. int rc = -ENOBUFS;
  646. struct llc_sock *llc = llc_sk(sk);
  647. struct sk_buff *nskb = llc_alloc_frame(sk, llc->dev, LLC_PDU_TYPE_S, 0);
  648. if (nskb) {
  649. struct llc_sap *sap = llc->sap;
  650. llc_pdu_header_init(nskb, LLC_PDU_TYPE_S, sap->laddr.lsap,
  651. llc->daddr.lsap, LLC_PDU_RSP);
  652. llc_pdu_init_as_rr_rsp(nskb, 0, llc->vR);
  653. rc = llc_mac_hdr_init(nskb, llc->dev->dev_addr, llc->daddr.mac);
  654. if (unlikely(rc))
  655. goto free;
  656. llc_conn_send_pdu(sk, nskb);
  657. }
  658. out:
  659. return rc;
  660. free:
  661. kfree_skb(nskb);
  662. goto out;
  663. }
  664. void llc_conn_set_p_flag(struct sock *sk, u8 value)
  665. {
  666. int state_changed = llc_sk(sk)->p_flag && !value;
  667. llc_sk(sk)->p_flag = value;
  668. if (state_changed)
  669. sk->sk_state_change(sk);
  670. }
  671. int llc_conn_ac_send_sabme_cmd_p_set_x(struct sock *sk, struct sk_buff *skb)
  672. {
  673. int rc = -ENOBUFS;
  674. struct llc_sock *llc = llc_sk(sk);
  675. struct sk_buff *nskb = llc_alloc_frame(sk, llc->dev, LLC_PDU_TYPE_U, 0);
  676. if (nskb) {
  677. struct llc_sap *sap = llc->sap;
  678. u8 *dmac = llc->daddr.mac;
  679. if (llc->dev->flags & IFF_LOOPBACK)
  680. dmac = llc->dev->dev_addr;
  681. llc_pdu_header_init(nskb, LLC_PDU_TYPE_U, sap->laddr.lsap,
  682. llc->daddr.lsap, LLC_PDU_CMD);
  683. llc_pdu_init_as_sabme_cmd(nskb, 1);
  684. rc = llc_mac_hdr_init(nskb, llc->dev->dev_addr, dmac);
  685. if (unlikely(rc))
  686. goto free;
  687. llc_conn_send_pdu(sk, nskb);
  688. llc_conn_set_p_flag(sk, 1);
  689. }
  690. out:
  691. return rc;
  692. free:
  693. kfree_skb(nskb);
  694. goto out;
  695. }
  696. int llc_conn_ac_send_ua_rsp_f_set_p(struct sock *sk, struct sk_buff *skb)
  697. {
  698. u8 f_bit;
  699. int rc = -ENOBUFS;
  700. struct llc_sock *llc = llc_sk(sk);
  701. struct sk_buff *nskb = llc_alloc_frame(sk, llc->dev, LLC_PDU_TYPE_U, 0);
  702. llc_pdu_decode_pf_bit(skb, &f_bit);
  703. if (nskb) {
  704. struct llc_sap *sap = llc->sap;
  705. nskb->dev = llc->dev;
  706. llc_pdu_header_init(nskb, LLC_PDU_TYPE_U, sap->laddr.lsap,
  707. llc->daddr.lsap, LLC_PDU_RSP);
  708. llc_pdu_init_as_ua_rsp(nskb, f_bit);
  709. rc = llc_mac_hdr_init(nskb, llc->dev->dev_addr, llc->daddr.mac);
  710. if (unlikely(rc))
  711. goto free;
  712. llc_conn_send_pdu(sk, nskb);
  713. }
  714. out:
  715. return rc;
  716. free:
  717. kfree_skb(nskb);
  718. goto out;
  719. }
  720. int llc_conn_ac_set_s_flag_0(struct sock *sk, struct sk_buff *skb)
  721. {
  722. llc_sk(sk)->s_flag = 0;
  723. return 0;
  724. }
  725. int llc_conn_ac_set_s_flag_1(struct sock *sk, struct sk_buff *skb)
  726. {
  727. llc_sk(sk)->s_flag = 1;
  728. return 0;
  729. }
  730. int llc_conn_ac_start_p_timer(struct sock *sk, struct sk_buff *skb)
  731. {
  732. struct llc_sock *llc = llc_sk(sk);
  733. llc_conn_set_p_flag(sk, 1);
  734. mod_timer(&llc->pf_cycle_timer.timer,
  735. jiffies + llc->pf_cycle_timer.expire);
  736. return 0;
  737. }
  738. /**
  739. * llc_conn_ac_send_ack_if_needed - check if ack is needed
  740. * @sk: current connection structure
  741. * @skb: current event
  742. *
  743. * Checks number of received PDUs which have not been acknowledged, yet,
  744. * If number of them reaches to "npta"(Number of PDUs To Acknowledge) then
  745. * sends an RR response as acknowledgement for them. Returns 0 for
  746. * success, 1 otherwise.
  747. */
  748. int llc_conn_ac_send_ack_if_needed(struct sock *sk, struct sk_buff *skb)
  749. {
  750. u8 pf_bit;
  751. struct llc_sock *llc = llc_sk(sk);
  752. llc_pdu_decode_pf_bit(skb, &pf_bit);
  753. llc->ack_pf |= pf_bit & 1;
  754. if (!llc->ack_must_be_send) {
  755. llc->first_pdu_Ns = llc->vR;
  756. llc->ack_must_be_send = 1;
  757. llc->ack_pf = pf_bit & 1;
  758. }
  759. if (((llc->vR - llc->first_pdu_Ns + 1 + LLC_2_SEQ_NBR_MODULO)
  760. % LLC_2_SEQ_NBR_MODULO) >= llc->npta) {
  761. llc_conn_ac_send_rr_rsp_f_set_ackpf(sk, skb);
  762. llc->ack_must_be_send = 0;
  763. llc->ack_pf = 0;
  764. llc_conn_ac_inc_npta_value(sk, skb);
  765. }
  766. return 0;
  767. }
  768. /**
  769. * llc_conn_ac_rst_sendack_flag - resets ack_must_be_send flag
  770. * @sk: current connection structure
  771. * @skb: current event
  772. *
  773. * This action resets ack_must_be_send flag of given connection, this flag
  774. * indicates if there is any PDU which has not been acknowledged yet.
  775. * Returns 0 for success, 1 otherwise.
  776. */
  777. int llc_conn_ac_rst_sendack_flag(struct sock *sk, struct sk_buff *skb)
  778. {
  779. llc_sk(sk)->ack_must_be_send = llc_sk(sk)->ack_pf = 0;
  780. return 0;
  781. }
  782. /**
  783. * llc_conn_ac_send_i_rsp_f_set_ackpf - acknowledge received PDUs
  784. * @sk: current connection structure
  785. * @skb: current event
  786. *
  787. * Sends an I response PDU with f-bit set to ack_pf flag as acknowledge to
  788. * all received PDUs which have not been acknowledged, yet. ack_pf flag is
  789. * set to one if one PDU with p-bit set to one is received. Returns 0 for
  790. * success, 1 otherwise.
  791. */
  792. static int llc_conn_ac_send_i_rsp_f_set_ackpf(struct sock *sk,
  793. struct sk_buff *skb)
  794. {
  795. int rc;
  796. struct llc_sock *llc = llc_sk(sk);
  797. struct llc_sap *sap = llc->sap;
  798. llc_pdu_header_init(skb, LLC_PDU_TYPE_I, sap->laddr.lsap,
  799. llc->daddr.lsap, LLC_PDU_RSP);
  800. llc_pdu_init_as_i_cmd(skb, llc->ack_pf, llc->vS, llc->vR);
  801. rc = llc_mac_hdr_init(skb, llc->dev->dev_addr, llc->daddr.mac);
  802. if (likely(!rc)) {
  803. llc_conn_send_pdu(sk, skb);
  804. llc_conn_ac_inc_vs_by_1(sk, skb);
  805. }
  806. return rc;
  807. }
  808. /**
  809. * llc_conn_ac_send_i_as_ack - sends an I-format PDU to acknowledge rx PDUs
  810. * @sk: current connection structure.
  811. * @skb: current event.
  812. *
  813. * This action sends an I-format PDU as acknowledge to received PDUs which
  814. * have not been acknowledged, yet, if there is any. By using of this
  815. * action number of acknowledgements decreases, this technic is called
  816. * piggy backing. Returns 0 for success, 1 otherwise.
  817. */
  818. int llc_conn_ac_send_i_as_ack(struct sock *sk, struct sk_buff *skb)
  819. {
  820. struct llc_sock *llc = llc_sk(sk);
  821. if (llc->ack_must_be_send) {
  822. llc_conn_ac_send_i_rsp_f_set_ackpf(sk, skb);
  823. llc->ack_must_be_send = 0 ;
  824. llc->ack_pf = 0;
  825. } else
  826. llc_conn_ac_send_i_cmd_p_set_0(sk, skb);
  827. return 0;
  828. }
  829. /**
  830. * llc_conn_ac_send_rr_rsp_f_set_ackpf - ack all rx PDUs not yet acked
  831. * @sk: current connection structure.
  832. * @skb: current event.
  833. *
  834. * This action sends an RR response with f-bit set to ack_pf flag as
  835. * acknowledge to all received PDUs which have not been acknowledged, yet,
  836. * if there is any. ack_pf flag indicates if a PDU has been received with
  837. * p-bit set to one. Returns 0 for success, 1 otherwise.
  838. */
  839. static int llc_conn_ac_send_rr_rsp_f_set_ackpf(struct sock *sk,
  840. struct sk_buff *skb)
  841. {
  842. int rc = -ENOBUFS;
  843. struct llc_sock *llc = llc_sk(sk);
  844. struct sk_buff *nskb = llc_alloc_frame(sk, llc->dev, LLC_PDU_TYPE_S, 0);
  845. if (nskb) {
  846. struct llc_sap *sap = llc->sap;
  847. llc_pdu_header_init(nskb, LLC_PDU_TYPE_S, sap->laddr.lsap,
  848. llc->daddr.lsap, LLC_PDU_RSP);
  849. llc_pdu_init_as_rr_rsp(nskb, llc->ack_pf, llc->vR);
  850. rc = llc_mac_hdr_init(nskb, llc->dev->dev_addr, llc->daddr.mac);
  851. if (unlikely(rc))
  852. goto free;
  853. llc_conn_send_pdu(sk, nskb);
  854. }
  855. out:
  856. return rc;
  857. free:
  858. kfree_skb(nskb);
  859. goto out;
  860. }
  861. /**
  862. * llc_conn_ac_inc_npta_value - tries to make value of npta greater
  863. * @sk: current connection structure.
  864. * @skb: current event.
  865. *
  866. * After "inc_cntr" times calling of this action, "npta" increase by one.
  867. * this action tries to make vale of "npta" greater as possible; number of
  868. * acknowledgements decreases by increasing of "npta". Returns 0 for
  869. * success, 1 otherwise.
  870. */
  871. static int llc_conn_ac_inc_npta_value(struct sock *sk, struct sk_buff *skb)
  872. {
  873. struct llc_sock *llc = llc_sk(sk);
  874. if (!llc->inc_cntr) {
  875. llc->dec_step = 0;
  876. llc->dec_cntr = llc->inc_cntr = 2;
  877. ++llc->npta;
  878. if (llc->npta > (u8) ~LLC_2_SEQ_NBR_MODULO)
  879. llc->npta = (u8) ~LLC_2_SEQ_NBR_MODULO;
  880. } else
  881. --llc->inc_cntr;
  882. return 0;
  883. }
  884. /**
  885. * llc_conn_ac_adjust_npta_by_rr - decreases "npta" by one
  886. * @sk: current connection structure.
  887. * @skb: current event.
  888. *
  889. * After receiving "dec_cntr" times RR command, this action decreases
  890. * "npta" by one. Returns 0 for success, 1 otherwise.
  891. */
  892. int llc_conn_ac_adjust_npta_by_rr(struct sock *sk, struct sk_buff *skb)
  893. {
  894. struct llc_sock *llc = llc_sk(sk);
  895. if (!llc->connect_step && !llc->remote_busy_flag) {
  896. if (!llc->dec_step) {
  897. if (!llc->dec_cntr) {
  898. llc->inc_cntr = llc->dec_cntr = 2;
  899. if (llc->npta > 0)
  900. llc->npta = llc->npta - 1;
  901. } else
  902. llc->dec_cntr -=1;
  903. }
  904. } else
  905. llc->connect_step = 0 ;
  906. return 0;
  907. }
  908. /**
  909. * llc_conn_ac_adjust_npta_by_rnr - decreases "npta" by one
  910. * @sk: current connection structure.
  911. * @skb: current event.
  912. *
  913. * After receiving "dec_cntr" times RNR command, this action decreases
  914. * "npta" by one. Returns 0 for success, 1 otherwise.
  915. */
  916. int llc_conn_ac_adjust_npta_by_rnr(struct sock *sk, struct sk_buff *skb)
  917. {
  918. struct llc_sock *llc = llc_sk(sk);
  919. if (llc->remote_busy_flag)
  920. if (!llc->dec_step) {
  921. if (!llc->dec_cntr) {
  922. llc->inc_cntr = llc->dec_cntr = 2;
  923. if (llc->npta > 0)
  924. --llc->npta;
  925. } else
  926. --llc->dec_cntr;
  927. }
  928. return 0;
  929. }
  930. /**
  931. * llc_conn_ac_dec_tx_win_size - decreases tx window size
  932. * @sk: current connection structure.
  933. * @skb: current event.
  934. *
  935. * After receiving of a REJ command or response, transmit window size is
  936. * decreased by number of PDUs which are outstanding yet. Returns 0 for
  937. * success, 1 otherwise.
  938. */
  939. int llc_conn_ac_dec_tx_win_size(struct sock *sk, struct sk_buff *skb)
  940. {
  941. struct llc_sock *llc = llc_sk(sk);
  942. u8 unacked_pdu = skb_queue_len(&llc->pdu_unack_q);
  943. if (llc->k - unacked_pdu < 1)
  944. llc->k = 1;
  945. else
  946. llc->k -= unacked_pdu;
  947. return 0;
  948. }
  949. /**
  950. * llc_conn_ac_inc_tx_win_size - tx window size is inc by 1
  951. * @sk: current connection structure.
  952. * @skb: current event.
  953. *
  954. * After receiving an RR response with f-bit set to one, transmit window
  955. * size is increased by one. Returns 0 for success, 1 otherwise.
  956. */
  957. int llc_conn_ac_inc_tx_win_size(struct sock *sk, struct sk_buff *skb)
  958. {
  959. struct llc_sock *llc = llc_sk(sk);
  960. llc->k += 1;
  961. if (llc->k > (u8) ~LLC_2_SEQ_NBR_MODULO)
  962. llc->k = (u8) ~LLC_2_SEQ_NBR_MODULO;
  963. return 0;
  964. }
  965. int llc_conn_ac_stop_all_timers(struct sock *sk, struct sk_buff *skb)
  966. {
  967. struct llc_sock *llc = llc_sk(sk);
  968. del_timer(&llc->pf_cycle_timer.timer);
  969. del_timer(&llc->ack_timer.timer);
  970. del_timer(&llc->rej_sent_timer.timer);
  971. del_timer(&llc->busy_state_timer.timer);
  972. llc->ack_must_be_send = 0;
  973. llc->ack_pf = 0;
  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(unsigned long timeout_data, u8 type)
  1154. {
  1155. struct sock *sk = (struct sock *)timeout_data;
  1156. struct sk_buff *skb = alloc_skb(0, GFP_ATOMIC);
  1157. bh_lock_sock(sk);
  1158. if (skb) {
  1159. struct llc_conn_state_ev *ev = llc_conn_ev(skb);
  1160. skb_set_owner_r(skb, sk);
  1161. ev->type = type;
  1162. llc_process_tmr_ev(sk, skb);
  1163. }
  1164. bh_unlock_sock(sk);
  1165. }
  1166. void llc_conn_pf_cycle_tmr_cb(unsigned long timeout_data)
  1167. {
  1168. llc_conn_tmr_common_cb(timeout_data, LLC_CONN_EV_TYPE_P_TMR);
  1169. }
  1170. void llc_conn_busy_tmr_cb(unsigned long timeout_data)
  1171. {
  1172. llc_conn_tmr_common_cb(timeout_data, LLC_CONN_EV_TYPE_BUSY_TMR);
  1173. }
  1174. void llc_conn_ack_tmr_cb(unsigned long timeout_data)
  1175. {
  1176. llc_conn_tmr_common_cb(timeout_data, LLC_CONN_EV_TYPE_ACK_TMR);
  1177. }
  1178. void llc_conn_rej_tmr_cb(unsigned long timeout_data)
  1179. {
  1180. llc_conn_tmr_common_cb(timeout_data, LLC_CONN_EV_TYPE_REJ_TMR);
  1181. }
  1182. int llc_conn_ac_rst_vs(struct sock *sk, struct sk_buff *skb)
  1183. {
  1184. llc_sk(sk)->X = llc_sk(sk)->vS;
  1185. llc_conn_ac_set_vs_nr(sk, skb);
  1186. return 0;
  1187. }
  1188. int llc_conn_ac_upd_vs(struct sock *sk, struct sk_buff *skb)
  1189. {
  1190. struct llc_pdu_sn *pdu = llc_pdu_sn_hdr(skb);
  1191. u8 nr = PDU_SUPV_GET_Nr(pdu);
  1192. if (llc_circular_between(llc_sk(sk)->vS, nr, llc_sk(sk)->X))
  1193. llc_conn_ac_set_vs_nr(sk, skb);
  1194. return 0;
  1195. }
  1196. /*
  1197. * Non-standard actions; these not contained in IEEE specification; for
  1198. * our own usage
  1199. */
  1200. /**
  1201. * llc_conn_disc - removes connection from SAP list and frees it
  1202. * @sk: closed connection
  1203. * @skb: occurred event
  1204. */
  1205. int llc_conn_disc(struct sock *sk, struct sk_buff *skb)
  1206. {
  1207. /* FIXME: this thing seems to want to die */
  1208. return 0;
  1209. }
  1210. /**
  1211. * llc_conn_reset - resets connection
  1212. * @sk : reseting connection.
  1213. * @skb: occurred event.
  1214. *
  1215. * Stop all timers, empty all queues and reset all flags.
  1216. */
  1217. int llc_conn_reset(struct sock *sk, struct sk_buff *skb)
  1218. {
  1219. llc_sk_reset(sk);
  1220. return 0;
  1221. }
  1222. /**
  1223. * llc_circular_between - designates that b is between a and c or not
  1224. * @a: lower bound
  1225. * @b: element to see if is between a and b
  1226. * @c: upper bound
  1227. *
  1228. * This function designates that b is between a and c or not (for example,
  1229. * 0 is between 127 and 1). Returns 1 if b is between a and c, 0
  1230. * otherwise.
  1231. */
  1232. u8 llc_circular_between(u8 a, u8 b, u8 c)
  1233. {
  1234. b = b - a;
  1235. c = c - a;
  1236. return b <= c;
  1237. }
  1238. /**
  1239. * llc_process_tmr_ev - timer backend
  1240. * @sk: active connection
  1241. * @skb: occurred event
  1242. *
  1243. * This function is called from timer callback functions. When connection
  1244. * is busy (during sending a data frame) timer expiration event must be
  1245. * queued. Otherwise this event can be sent to connection state machine.
  1246. * Queued events will process by llc_backlog_rcv function after sending
  1247. * data frame.
  1248. */
  1249. static void llc_process_tmr_ev(struct sock *sk, struct sk_buff *skb)
  1250. {
  1251. if (llc_sk(sk)->state == LLC_CONN_OUT_OF_SVC) {
  1252. printk(KERN_WARNING "%s: timer called on closed connection\n",
  1253. __func__);
  1254. kfree_skb(skb);
  1255. } else {
  1256. if (!sock_owned_by_user(sk))
  1257. llc_conn_state_process(sk, skb);
  1258. else {
  1259. llc_set_backlog_type(skb, LLC_EVENT);
  1260. __sk_add_backlog(sk, skb);
  1261. }
  1262. }
  1263. }