llc_c_ac.c 36 KB

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