llc_c_ac.c 35 KB

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