hdlc_fr.c 30 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306
  1. /*
  2. * Generic HDLC support routines for Linux
  3. * Frame Relay support
  4. *
  5. * Copyright (C) 1999 - 2006 Krzysztof Halasa <khc@pm.waw.pl>
  6. *
  7. * This program is free software; you can redistribute it and/or modify it
  8. * under the terms of version 2 of the GNU General Public License
  9. * as published by the Free Software Foundation.
  10. *
  11. Theory of PVC state
  12. DCE mode:
  13. (exist,new) -> 0,0 when "PVC create" or if "link unreliable"
  14. 0,x -> 1,1 if "link reliable" when sending FULL STATUS
  15. 1,1 -> 1,0 if received FULL STATUS ACK
  16. (active) -> 0 when "ifconfig PVC down" or "link unreliable" or "PVC create"
  17. -> 1 when "PVC up" and (exist,new) = 1,0
  18. DTE mode:
  19. (exist,new,active) = FULL STATUS if "link reliable"
  20. = 0, 0, 0 if "link unreliable"
  21. No LMI:
  22. active = open and "link reliable"
  23. exist = new = not used
  24. CCITT LMI: ITU-T Q.933 Annex A
  25. ANSI LMI: ANSI T1.617 Annex D
  26. CISCO LMI: the original, aka "Gang of Four" LMI
  27. */
  28. #include <linux/errno.h>
  29. #include <linux/etherdevice.h>
  30. #include <linux/hdlc.h>
  31. #include <linux/if_arp.h>
  32. #include <linux/inetdevice.h>
  33. #include <linux/init.h>
  34. #include <linux/kernel.h>
  35. #include <linux/module.h>
  36. #include <linux/pkt_sched.h>
  37. #include <linux/poll.h>
  38. #include <linux/rtnetlink.h>
  39. #include <linux/skbuff.h>
  40. #include <linux/slab.h>
  41. #undef DEBUG_PKT
  42. #undef DEBUG_ECN
  43. #undef DEBUG_LINK
  44. #undef DEBUG_PROTO
  45. #undef DEBUG_PVC
  46. #define FR_UI 0x03
  47. #define FR_PAD 0x00
  48. #define NLPID_IP 0xCC
  49. #define NLPID_IPV6 0x8E
  50. #define NLPID_SNAP 0x80
  51. #define NLPID_PAD 0x00
  52. #define NLPID_CCITT_ANSI_LMI 0x08
  53. #define NLPID_CISCO_LMI 0x09
  54. #define LMI_CCITT_ANSI_DLCI 0 /* LMI DLCI */
  55. #define LMI_CISCO_DLCI 1023
  56. #define LMI_CALLREF 0x00 /* Call Reference */
  57. #define LMI_ANSI_LOCKSHIFT 0x95 /* ANSI locking shift */
  58. #define LMI_ANSI_CISCO_REPTYPE 0x01 /* report type */
  59. #define LMI_CCITT_REPTYPE 0x51
  60. #define LMI_ANSI_CISCO_ALIVE 0x03 /* keep alive */
  61. #define LMI_CCITT_ALIVE 0x53
  62. #define LMI_ANSI_CISCO_PVCSTAT 0x07 /* PVC status */
  63. #define LMI_CCITT_PVCSTAT 0x57
  64. #define LMI_FULLREP 0x00 /* full report */
  65. #define LMI_INTEGRITY 0x01 /* link integrity report */
  66. #define LMI_SINGLE 0x02 /* single PVC report */
  67. #define LMI_STATUS_ENQUIRY 0x75
  68. #define LMI_STATUS 0x7D /* reply */
  69. #define LMI_REPT_LEN 1 /* report type element length */
  70. #define LMI_INTEG_LEN 2 /* link integrity element length */
  71. #define LMI_CCITT_CISCO_LENGTH 13 /* LMI frame lengths */
  72. #define LMI_ANSI_LENGTH 14
  73. typedef struct {
  74. #if defined(__LITTLE_ENDIAN_BITFIELD)
  75. unsigned ea1: 1;
  76. unsigned cr: 1;
  77. unsigned dlcih: 6;
  78. unsigned ea2: 1;
  79. unsigned de: 1;
  80. unsigned becn: 1;
  81. unsigned fecn: 1;
  82. unsigned dlcil: 4;
  83. #else
  84. unsigned dlcih: 6;
  85. unsigned cr: 1;
  86. unsigned ea1: 1;
  87. unsigned dlcil: 4;
  88. unsigned fecn: 1;
  89. unsigned becn: 1;
  90. unsigned de: 1;
  91. unsigned ea2: 1;
  92. #endif
  93. }__packed fr_hdr;
  94. typedef struct pvc_device_struct {
  95. struct net_device *frad;
  96. struct net_device *main;
  97. struct net_device *ether; /* bridged Ethernet interface */
  98. struct pvc_device_struct *next; /* Sorted in ascending DLCI order */
  99. int dlci;
  100. int open_count;
  101. struct {
  102. unsigned int new: 1;
  103. unsigned int active: 1;
  104. unsigned int exist: 1;
  105. unsigned int deleted: 1;
  106. unsigned int fecn: 1;
  107. unsigned int becn: 1;
  108. unsigned int bandwidth; /* Cisco LMI reporting only */
  109. }state;
  110. }pvc_device;
  111. struct frad_state {
  112. fr_proto settings;
  113. pvc_device *first_pvc;
  114. int dce_pvc_count;
  115. struct timer_list timer;
  116. unsigned long last_poll;
  117. int reliable;
  118. int dce_changed;
  119. int request;
  120. int fullrep_sent;
  121. u32 last_errors; /* last errors bit list */
  122. u8 n391cnt;
  123. u8 txseq; /* TX sequence number */
  124. u8 rxseq; /* RX sequence number */
  125. };
  126. static int fr_ioctl(struct net_device *dev, struct ifreq *ifr);
  127. static inline u16 q922_to_dlci(u8 *hdr)
  128. {
  129. return ((hdr[0] & 0xFC) << 2) | ((hdr[1] & 0xF0) >> 4);
  130. }
  131. static inline void dlci_to_q922(u8 *hdr, u16 dlci)
  132. {
  133. hdr[0] = (dlci >> 2) & 0xFC;
  134. hdr[1] = ((dlci << 4) & 0xF0) | 0x01;
  135. }
  136. static inline struct frad_state* state(hdlc_device *hdlc)
  137. {
  138. return(struct frad_state *)(hdlc->state);
  139. }
  140. static inline pvc_device* find_pvc(hdlc_device *hdlc, u16 dlci)
  141. {
  142. pvc_device *pvc = state(hdlc)->first_pvc;
  143. while (pvc) {
  144. if (pvc->dlci == dlci)
  145. return pvc;
  146. if (pvc->dlci > dlci)
  147. return NULL; /* the list is sorted */
  148. pvc = pvc->next;
  149. }
  150. return NULL;
  151. }
  152. static pvc_device* add_pvc(struct net_device *dev, u16 dlci)
  153. {
  154. hdlc_device *hdlc = dev_to_hdlc(dev);
  155. pvc_device *pvc, **pvc_p = &state(hdlc)->first_pvc;
  156. while (*pvc_p) {
  157. if ((*pvc_p)->dlci == dlci)
  158. return *pvc_p;
  159. if ((*pvc_p)->dlci > dlci)
  160. break; /* the list is sorted */
  161. pvc_p = &(*pvc_p)->next;
  162. }
  163. pvc = kzalloc(sizeof(pvc_device), GFP_ATOMIC);
  164. #ifdef DEBUG_PVC
  165. printk(KERN_DEBUG "add_pvc: allocated pvc %p, frad %p\n", pvc, dev);
  166. #endif
  167. if (!pvc)
  168. return NULL;
  169. pvc->dlci = dlci;
  170. pvc->frad = dev;
  171. pvc->next = *pvc_p; /* Put it in the chain */
  172. *pvc_p = pvc;
  173. return pvc;
  174. }
  175. static inline int pvc_is_used(pvc_device *pvc)
  176. {
  177. return pvc->main || pvc->ether;
  178. }
  179. static inline void pvc_carrier(int on, pvc_device *pvc)
  180. {
  181. if (on) {
  182. if (pvc->main)
  183. if (!netif_carrier_ok(pvc->main))
  184. netif_carrier_on(pvc->main);
  185. if (pvc->ether)
  186. if (!netif_carrier_ok(pvc->ether))
  187. netif_carrier_on(pvc->ether);
  188. } else {
  189. if (pvc->main)
  190. if (netif_carrier_ok(pvc->main))
  191. netif_carrier_off(pvc->main);
  192. if (pvc->ether)
  193. if (netif_carrier_ok(pvc->ether))
  194. netif_carrier_off(pvc->ether);
  195. }
  196. }
  197. static inline void delete_unused_pvcs(hdlc_device *hdlc)
  198. {
  199. pvc_device **pvc_p = &state(hdlc)->first_pvc;
  200. while (*pvc_p) {
  201. if (!pvc_is_used(*pvc_p)) {
  202. pvc_device *pvc = *pvc_p;
  203. #ifdef DEBUG_PVC
  204. printk(KERN_DEBUG "freeing unused pvc: %p\n", pvc);
  205. #endif
  206. *pvc_p = pvc->next;
  207. kfree(pvc);
  208. continue;
  209. }
  210. pvc_p = &(*pvc_p)->next;
  211. }
  212. }
  213. static inline struct net_device** get_dev_p(pvc_device *pvc, int type)
  214. {
  215. if (type == ARPHRD_ETHER)
  216. return &pvc->ether;
  217. else
  218. return &pvc->main;
  219. }
  220. static int fr_hard_header(struct sk_buff **skb_p, u16 dlci)
  221. {
  222. u16 head_len;
  223. struct sk_buff *skb = *skb_p;
  224. switch (skb->protocol) {
  225. case cpu_to_be16(NLPID_CCITT_ANSI_LMI):
  226. head_len = 4;
  227. skb_push(skb, head_len);
  228. skb->data[3] = NLPID_CCITT_ANSI_LMI;
  229. break;
  230. case cpu_to_be16(NLPID_CISCO_LMI):
  231. head_len = 4;
  232. skb_push(skb, head_len);
  233. skb->data[3] = NLPID_CISCO_LMI;
  234. break;
  235. case cpu_to_be16(ETH_P_IP):
  236. head_len = 4;
  237. skb_push(skb, head_len);
  238. skb->data[3] = NLPID_IP;
  239. break;
  240. case cpu_to_be16(ETH_P_IPV6):
  241. head_len = 4;
  242. skb_push(skb, head_len);
  243. skb->data[3] = NLPID_IPV6;
  244. break;
  245. case cpu_to_be16(ETH_P_802_3):
  246. head_len = 10;
  247. if (skb_headroom(skb) < head_len) {
  248. struct sk_buff *skb2 = skb_realloc_headroom(skb,
  249. head_len);
  250. if (!skb2)
  251. return -ENOBUFS;
  252. dev_kfree_skb(skb);
  253. skb = *skb_p = skb2;
  254. }
  255. skb_push(skb, head_len);
  256. skb->data[3] = FR_PAD;
  257. skb->data[4] = NLPID_SNAP;
  258. skb->data[5] = FR_PAD;
  259. skb->data[6] = 0x80;
  260. skb->data[7] = 0xC2;
  261. skb->data[8] = 0x00;
  262. skb->data[9] = 0x07; /* bridged Ethernet frame w/out FCS */
  263. break;
  264. default:
  265. head_len = 10;
  266. skb_push(skb, head_len);
  267. skb->data[3] = FR_PAD;
  268. skb->data[4] = NLPID_SNAP;
  269. skb->data[5] = FR_PAD;
  270. skb->data[6] = FR_PAD;
  271. skb->data[7] = FR_PAD;
  272. *(__be16*)(skb->data + 8) = skb->protocol;
  273. }
  274. dlci_to_q922(skb->data, dlci);
  275. skb->data[2] = FR_UI;
  276. return 0;
  277. }
  278. static int pvc_open(struct net_device *dev)
  279. {
  280. pvc_device *pvc = dev->ml_priv;
  281. if ((pvc->frad->flags & IFF_UP) == 0)
  282. return -EIO; /* Frad must be UP in order to activate PVC */
  283. if (pvc->open_count++ == 0) {
  284. hdlc_device *hdlc = dev_to_hdlc(pvc->frad);
  285. if (state(hdlc)->settings.lmi == LMI_NONE)
  286. pvc->state.active = netif_carrier_ok(pvc->frad);
  287. pvc_carrier(pvc->state.active, pvc);
  288. state(hdlc)->dce_changed = 1;
  289. }
  290. return 0;
  291. }
  292. static int pvc_close(struct net_device *dev)
  293. {
  294. pvc_device *pvc = dev->ml_priv;
  295. if (--pvc->open_count == 0) {
  296. hdlc_device *hdlc = dev_to_hdlc(pvc->frad);
  297. if (state(hdlc)->settings.lmi == LMI_NONE)
  298. pvc->state.active = 0;
  299. if (state(hdlc)->settings.dce) {
  300. state(hdlc)->dce_changed = 1;
  301. pvc->state.active = 0;
  302. }
  303. }
  304. return 0;
  305. }
  306. static int pvc_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
  307. {
  308. pvc_device *pvc = dev->ml_priv;
  309. fr_proto_pvc_info info;
  310. if (ifr->ifr_settings.type == IF_GET_PROTO) {
  311. if (dev->type == ARPHRD_ETHER)
  312. ifr->ifr_settings.type = IF_PROTO_FR_ETH_PVC;
  313. else
  314. ifr->ifr_settings.type = IF_PROTO_FR_PVC;
  315. if (ifr->ifr_settings.size < sizeof(info)) {
  316. /* data size wanted */
  317. ifr->ifr_settings.size = sizeof(info);
  318. return -ENOBUFS;
  319. }
  320. info.dlci = pvc->dlci;
  321. memcpy(info.master, pvc->frad->name, IFNAMSIZ);
  322. if (copy_to_user(ifr->ifr_settings.ifs_ifsu.fr_pvc_info,
  323. &info, sizeof(info)))
  324. return -EFAULT;
  325. return 0;
  326. }
  327. return -EINVAL;
  328. }
  329. static netdev_tx_t pvc_xmit(struct sk_buff *skb, struct net_device *dev)
  330. {
  331. pvc_device *pvc = dev->ml_priv;
  332. if (pvc->state.active) {
  333. if (dev->type == ARPHRD_ETHER) {
  334. int pad = ETH_ZLEN - skb->len;
  335. if (pad > 0) { /* Pad the frame with zeros */
  336. int len = skb->len;
  337. if (skb_tailroom(skb) < pad)
  338. if (pskb_expand_head(skb, 0, pad,
  339. GFP_ATOMIC)) {
  340. dev->stats.tx_dropped++;
  341. dev_kfree_skb(skb);
  342. return NETDEV_TX_OK;
  343. }
  344. skb_put(skb, pad);
  345. memset(skb->data + len, 0, pad);
  346. }
  347. skb->protocol = cpu_to_be16(ETH_P_802_3);
  348. }
  349. if (!fr_hard_header(&skb, pvc->dlci)) {
  350. dev->stats.tx_bytes += skb->len;
  351. dev->stats.tx_packets++;
  352. if (pvc->state.fecn) /* TX Congestion counter */
  353. dev->stats.tx_compressed++;
  354. skb->dev = pvc->frad;
  355. dev_queue_xmit(skb);
  356. return NETDEV_TX_OK;
  357. }
  358. }
  359. dev->stats.tx_dropped++;
  360. dev_kfree_skb(skb);
  361. return NETDEV_TX_OK;
  362. }
  363. static inline void fr_log_dlci_active(pvc_device *pvc)
  364. {
  365. printk(KERN_INFO "%s: DLCI %d [%s%s%s]%s %s\n",
  366. pvc->frad->name,
  367. pvc->dlci,
  368. pvc->main ? pvc->main->name : "",
  369. pvc->main && pvc->ether ? " " : "",
  370. pvc->ether ? pvc->ether->name : "",
  371. pvc->state.new ? " new" : "",
  372. !pvc->state.exist ? "deleted" :
  373. pvc->state.active ? "active" : "inactive");
  374. }
  375. static inline u8 fr_lmi_nextseq(u8 x)
  376. {
  377. x++;
  378. return x ? x : 1;
  379. }
  380. static void fr_lmi_send(struct net_device *dev, int fullrep)
  381. {
  382. hdlc_device *hdlc = dev_to_hdlc(dev);
  383. struct sk_buff *skb;
  384. pvc_device *pvc = state(hdlc)->first_pvc;
  385. int lmi = state(hdlc)->settings.lmi;
  386. int dce = state(hdlc)->settings.dce;
  387. int len = lmi == LMI_ANSI ? LMI_ANSI_LENGTH : LMI_CCITT_CISCO_LENGTH;
  388. int stat_len = (lmi == LMI_CISCO) ? 6 : 3;
  389. u8 *data;
  390. int i = 0;
  391. if (dce && fullrep) {
  392. len += state(hdlc)->dce_pvc_count * (2 + stat_len);
  393. if (len > HDLC_MAX_MRU) {
  394. printk(KERN_WARNING "%s: Too many PVCs while sending "
  395. "LMI full report\n", dev->name);
  396. return;
  397. }
  398. }
  399. skb = dev_alloc_skb(len);
  400. if (!skb) {
  401. printk(KERN_WARNING "%s: Memory squeeze on fr_lmi_send()\n",
  402. dev->name);
  403. return;
  404. }
  405. memset(skb->data, 0, len);
  406. skb_reserve(skb, 4);
  407. if (lmi == LMI_CISCO) {
  408. skb->protocol = cpu_to_be16(NLPID_CISCO_LMI);
  409. fr_hard_header(&skb, LMI_CISCO_DLCI);
  410. } else {
  411. skb->protocol = cpu_to_be16(NLPID_CCITT_ANSI_LMI);
  412. fr_hard_header(&skb, LMI_CCITT_ANSI_DLCI);
  413. }
  414. data = skb_tail_pointer(skb);
  415. data[i++] = LMI_CALLREF;
  416. data[i++] = dce ? LMI_STATUS : LMI_STATUS_ENQUIRY;
  417. if (lmi == LMI_ANSI)
  418. data[i++] = LMI_ANSI_LOCKSHIFT;
  419. data[i++] = lmi == LMI_CCITT ? LMI_CCITT_REPTYPE :
  420. LMI_ANSI_CISCO_REPTYPE;
  421. data[i++] = LMI_REPT_LEN;
  422. data[i++] = fullrep ? LMI_FULLREP : LMI_INTEGRITY;
  423. data[i++] = lmi == LMI_CCITT ? LMI_CCITT_ALIVE : LMI_ANSI_CISCO_ALIVE;
  424. data[i++] = LMI_INTEG_LEN;
  425. data[i++] = state(hdlc)->txseq =
  426. fr_lmi_nextseq(state(hdlc)->txseq);
  427. data[i++] = state(hdlc)->rxseq;
  428. if (dce && fullrep) {
  429. while (pvc) {
  430. data[i++] = lmi == LMI_CCITT ? LMI_CCITT_PVCSTAT :
  431. LMI_ANSI_CISCO_PVCSTAT;
  432. data[i++] = stat_len;
  433. /* LMI start/restart */
  434. if (state(hdlc)->reliable && !pvc->state.exist) {
  435. pvc->state.exist = pvc->state.new = 1;
  436. fr_log_dlci_active(pvc);
  437. }
  438. /* ifconfig PVC up */
  439. if (pvc->open_count && !pvc->state.active &&
  440. pvc->state.exist && !pvc->state.new) {
  441. pvc_carrier(1, pvc);
  442. pvc->state.active = 1;
  443. fr_log_dlci_active(pvc);
  444. }
  445. if (lmi == LMI_CISCO) {
  446. data[i] = pvc->dlci >> 8;
  447. data[i + 1] = pvc->dlci & 0xFF;
  448. } else {
  449. data[i] = (pvc->dlci >> 4) & 0x3F;
  450. data[i + 1] = ((pvc->dlci << 3) & 0x78) | 0x80;
  451. data[i + 2] = 0x80;
  452. }
  453. if (pvc->state.new)
  454. data[i + 2] |= 0x08;
  455. else if (pvc->state.active)
  456. data[i + 2] |= 0x02;
  457. i += stat_len;
  458. pvc = pvc->next;
  459. }
  460. }
  461. skb_put(skb, i);
  462. skb->priority = TC_PRIO_CONTROL;
  463. skb->dev = dev;
  464. skb_reset_network_header(skb);
  465. dev_queue_xmit(skb);
  466. }
  467. static void fr_set_link_state(int reliable, struct net_device *dev)
  468. {
  469. hdlc_device *hdlc = dev_to_hdlc(dev);
  470. pvc_device *pvc = state(hdlc)->first_pvc;
  471. state(hdlc)->reliable = reliable;
  472. if (reliable) {
  473. netif_dormant_off(dev);
  474. state(hdlc)->n391cnt = 0; /* Request full status */
  475. state(hdlc)->dce_changed = 1;
  476. if (state(hdlc)->settings.lmi == LMI_NONE) {
  477. while (pvc) { /* Activate all PVCs */
  478. pvc_carrier(1, pvc);
  479. pvc->state.exist = pvc->state.active = 1;
  480. pvc->state.new = 0;
  481. pvc = pvc->next;
  482. }
  483. }
  484. } else {
  485. netif_dormant_on(dev);
  486. while (pvc) { /* Deactivate all PVCs */
  487. pvc_carrier(0, pvc);
  488. pvc->state.exist = pvc->state.active = 0;
  489. pvc->state.new = 0;
  490. if (!state(hdlc)->settings.dce)
  491. pvc->state.bandwidth = 0;
  492. pvc = pvc->next;
  493. }
  494. }
  495. }
  496. static void fr_timer(unsigned long arg)
  497. {
  498. struct net_device *dev = (struct net_device *)arg;
  499. hdlc_device *hdlc = dev_to_hdlc(dev);
  500. int i, cnt = 0, reliable;
  501. u32 list;
  502. if (state(hdlc)->settings.dce) {
  503. reliable = state(hdlc)->request &&
  504. time_before(jiffies, state(hdlc)->last_poll +
  505. state(hdlc)->settings.t392 * HZ);
  506. state(hdlc)->request = 0;
  507. } else {
  508. state(hdlc)->last_errors <<= 1; /* Shift the list */
  509. if (state(hdlc)->request) {
  510. if (state(hdlc)->reliable)
  511. printk(KERN_INFO "%s: No LMI status reply "
  512. "received\n", dev->name);
  513. state(hdlc)->last_errors |= 1;
  514. }
  515. list = state(hdlc)->last_errors;
  516. for (i = 0; i < state(hdlc)->settings.n393; i++, list >>= 1)
  517. cnt += (list & 1); /* errors count */
  518. reliable = (cnt < state(hdlc)->settings.n392);
  519. }
  520. if (state(hdlc)->reliable != reliable) {
  521. printk(KERN_INFO "%s: Link %sreliable\n", dev->name,
  522. reliable ? "" : "un");
  523. fr_set_link_state(reliable, dev);
  524. }
  525. if (state(hdlc)->settings.dce)
  526. state(hdlc)->timer.expires = jiffies +
  527. state(hdlc)->settings.t392 * HZ;
  528. else {
  529. if (state(hdlc)->n391cnt)
  530. state(hdlc)->n391cnt--;
  531. fr_lmi_send(dev, state(hdlc)->n391cnt == 0);
  532. state(hdlc)->last_poll = jiffies;
  533. state(hdlc)->request = 1;
  534. state(hdlc)->timer.expires = jiffies +
  535. state(hdlc)->settings.t391 * HZ;
  536. }
  537. state(hdlc)->timer.function = fr_timer;
  538. state(hdlc)->timer.data = arg;
  539. add_timer(&state(hdlc)->timer);
  540. }
  541. static int fr_lmi_recv(struct net_device *dev, struct sk_buff *skb)
  542. {
  543. hdlc_device *hdlc = dev_to_hdlc(dev);
  544. pvc_device *pvc;
  545. u8 rxseq, txseq;
  546. int lmi = state(hdlc)->settings.lmi;
  547. int dce = state(hdlc)->settings.dce;
  548. int stat_len = (lmi == LMI_CISCO) ? 6 : 3, reptype, error, no_ram, i;
  549. if (skb->len < (lmi == LMI_ANSI ? LMI_ANSI_LENGTH :
  550. LMI_CCITT_CISCO_LENGTH)) {
  551. printk(KERN_INFO "%s: Short LMI frame\n", dev->name);
  552. return 1;
  553. }
  554. if (skb->data[3] != (lmi == LMI_CISCO ? NLPID_CISCO_LMI :
  555. NLPID_CCITT_ANSI_LMI)) {
  556. printk(KERN_INFO "%s: Received non-LMI frame with LMI DLCI\n",
  557. dev->name);
  558. return 1;
  559. }
  560. if (skb->data[4] != LMI_CALLREF) {
  561. printk(KERN_INFO "%s: Invalid LMI Call reference (0x%02X)\n",
  562. dev->name, skb->data[4]);
  563. return 1;
  564. }
  565. if (skb->data[5] != (dce ? LMI_STATUS_ENQUIRY : LMI_STATUS)) {
  566. printk(KERN_INFO "%s: Invalid LMI Message type (0x%02X)\n",
  567. dev->name, skb->data[5]);
  568. return 1;
  569. }
  570. if (lmi == LMI_ANSI) {
  571. if (skb->data[6] != LMI_ANSI_LOCKSHIFT) {
  572. printk(KERN_INFO "%s: Not ANSI locking shift in LMI"
  573. " message (0x%02X)\n", dev->name, skb->data[6]);
  574. return 1;
  575. }
  576. i = 7;
  577. } else
  578. i = 6;
  579. if (skb->data[i] != (lmi == LMI_CCITT ? LMI_CCITT_REPTYPE :
  580. LMI_ANSI_CISCO_REPTYPE)) {
  581. printk(KERN_INFO "%s: Not an LMI Report type IE (0x%02X)\n",
  582. dev->name, skb->data[i]);
  583. return 1;
  584. }
  585. if (skb->data[++i] != LMI_REPT_LEN) {
  586. printk(KERN_INFO "%s: Invalid LMI Report type IE length"
  587. " (%u)\n", dev->name, skb->data[i]);
  588. return 1;
  589. }
  590. reptype = skb->data[++i];
  591. if (reptype != LMI_INTEGRITY && reptype != LMI_FULLREP) {
  592. printk(KERN_INFO "%s: Unsupported LMI Report type (0x%02X)\n",
  593. dev->name, reptype);
  594. return 1;
  595. }
  596. if (skb->data[++i] != (lmi == LMI_CCITT ? LMI_CCITT_ALIVE :
  597. LMI_ANSI_CISCO_ALIVE)) {
  598. printk(KERN_INFO "%s: Not an LMI Link integrity verification"
  599. " IE (0x%02X)\n", dev->name, skb->data[i]);
  600. return 1;
  601. }
  602. if (skb->data[++i] != LMI_INTEG_LEN) {
  603. printk(KERN_INFO "%s: Invalid LMI Link integrity verification"
  604. " IE length (%u)\n", dev->name, skb->data[i]);
  605. return 1;
  606. }
  607. i++;
  608. state(hdlc)->rxseq = skb->data[i++]; /* TX sequence from peer */
  609. rxseq = skb->data[i++]; /* Should confirm our sequence */
  610. txseq = state(hdlc)->txseq;
  611. if (dce)
  612. state(hdlc)->last_poll = jiffies;
  613. error = 0;
  614. if (!state(hdlc)->reliable)
  615. error = 1;
  616. if (rxseq == 0 || rxseq != txseq) { /* Ask for full report next time */
  617. state(hdlc)->n391cnt = 0;
  618. error = 1;
  619. }
  620. if (dce) {
  621. if (state(hdlc)->fullrep_sent && !error) {
  622. /* Stop sending full report - the last one has been confirmed by DTE */
  623. state(hdlc)->fullrep_sent = 0;
  624. pvc = state(hdlc)->first_pvc;
  625. while (pvc) {
  626. if (pvc->state.new) {
  627. pvc->state.new = 0;
  628. /* Tell DTE that new PVC is now active */
  629. state(hdlc)->dce_changed = 1;
  630. }
  631. pvc = pvc->next;
  632. }
  633. }
  634. if (state(hdlc)->dce_changed) {
  635. reptype = LMI_FULLREP;
  636. state(hdlc)->fullrep_sent = 1;
  637. state(hdlc)->dce_changed = 0;
  638. }
  639. state(hdlc)->request = 1; /* got request */
  640. fr_lmi_send(dev, reptype == LMI_FULLREP ? 1 : 0);
  641. return 0;
  642. }
  643. /* DTE */
  644. state(hdlc)->request = 0; /* got response, no request pending */
  645. if (error)
  646. return 0;
  647. if (reptype != LMI_FULLREP)
  648. return 0;
  649. pvc = state(hdlc)->first_pvc;
  650. while (pvc) {
  651. pvc->state.deleted = 1;
  652. pvc = pvc->next;
  653. }
  654. no_ram = 0;
  655. while (skb->len >= i + 2 + stat_len) {
  656. u16 dlci;
  657. u32 bw;
  658. unsigned int active, new;
  659. if (skb->data[i] != (lmi == LMI_CCITT ? LMI_CCITT_PVCSTAT :
  660. LMI_ANSI_CISCO_PVCSTAT)) {
  661. printk(KERN_INFO "%s: Not an LMI PVC status IE"
  662. " (0x%02X)\n", dev->name, skb->data[i]);
  663. return 1;
  664. }
  665. if (skb->data[++i] != stat_len) {
  666. printk(KERN_INFO "%s: Invalid LMI PVC status IE length"
  667. " (%u)\n", dev->name, skb->data[i]);
  668. return 1;
  669. }
  670. i++;
  671. new = !! (skb->data[i + 2] & 0x08);
  672. active = !! (skb->data[i + 2] & 0x02);
  673. if (lmi == LMI_CISCO) {
  674. dlci = (skb->data[i] << 8) | skb->data[i + 1];
  675. bw = (skb->data[i + 3] << 16) |
  676. (skb->data[i + 4] << 8) |
  677. (skb->data[i + 5]);
  678. } else {
  679. dlci = ((skb->data[i] & 0x3F) << 4) |
  680. ((skb->data[i + 1] & 0x78) >> 3);
  681. bw = 0;
  682. }
  683. pvc = add_pvc(dev, dlci);
  684. if (!pvc && !no_ram) {
  685. printk(KERN_WARNING
  686. "%s: Memory squeeze on fr_lmi_recv()\n",
  687. dev->name);
  688. no_ram = 1;
  689. }
  690. if (pvc) {
  691. pvc->state.exist = 1;
  692. pvc->state.deleted = 0;
  693. if (active != pvc->state.active ||
  694. new != pvc->state.new ||
  695. bw != pvc->state.bandwidth ||
  696. !pvc->state.exist) {
  697. pvc->state.new = new;
  698. pvc->state.active = active;
  699. pvc->state.bandwidth = bw;
  700. pvc_carrier(active, pvc);
  701. fr_log_dlci_active(pvc);
  702. }
  703. }
  704. i += stat_len;
  705. }
  706. pvc = state(hdlc)->first_pvc;
  707. while (pvc) {
  708. if (pvc->state.deleted && pvc->state.exist) {
  709. pvc_carrier(0, pvc);
  710. pvc->state.active = pvc->state.new = 0;
  711. pvc->state.exist = 0;
  712. pvc->state.bandwidth = 0;
  713. fr_log_dlci_active(pvc);
  714. }
  715. pvc = pvc->next;
  716. }
  717. /* Next full report after N391 polls */
  718. state(hdlc)->n391cnt = state(hdlc)->settings.n391;
  719. return 0;
  720. }
  721. static int fr_rx(struct sk_buff *skb)
  722. {
  723. struct net_device *frad = skb->dev;
  724. hdlc_device *hdlc = dev_to_hdlc(frad);
  725. fr_hdr *fh = (fr_hdr*)skb->data;
  726. u8 *data = skb->data;
  727. u16 dlci;
  728. pvc_device *pvc;
  729. struct net_device *dev = NULL;
  730. if (skb->len <= 4 || fh->ea1 || data[2] != FR_UI)
  731. goto rx_error;
  732. dlci = q922_to_dlci(skb->data);
  733. if ((dlci == LMI_CCITT_ANSI_DLCI &&
  734. (state(hdlc)->settings.lmi == LMI_ANSI ||
  735. state(hdlc)->settings.lmi == LMI_CCITT)) ||
  736. (dlci == LMI_CISCO_DLCI &&
  737. state(hdlc)->settings.lmi == LMI_CISCO)) {
  738. if (fr_lmi_recv(frad, skb))
  739. goto rx_error;
  740. dev_kfree_skb_any(skb);
  741. return NET_RX_SUCCESS;
  742. }
  743. pvc = find_pvc(hdlc, dlci);
  744. if (!pvc) {
  745. #ifdef DEBUG_PKT
  746. printk(KERN_INFO "%s: No PVC for received frame's DLCI %d\n",
  747. frad->name, dlci);
  748. #endif
  749. dev_kfree_skb_any(skb);
  750. return NET_RX_DROP;
  751. }
  752. if (pvc->state.fecn != fh->fecn) {
  753. #ifdef DEBUG_ECN
  754. printk(KERN_DEBUG "%s: DLCI %d FECN O%s\n", frad->name,
  755. dlci, fh->fecn ? "N" : "FF");
  756. #endif
  757. pvc->state.fecn ^= 1;
  758. }
  759. if (pvc->state.becn != fh->becn) {
  760. #ifdef DEBUG_ECN
  761. printk(KERN_DEBUG "%s: DLCI %d BECN O%s\n", frad->name,
  762. dlci, fh->becn ? "N" : "FF");
  763. #endif
  764. pvc->state.becn ^= 1;
  765. }
  766. if ((skb = skb_share_check(skb, GFP_ATOMIC)) == NULL) {
  767. frad->stats.rx_dropped++;
  768. return NET_RX_DROP;
  769. }
  770. if (data[3] == NLPID_IP) {
  771. skb_pull(skb, 4); /* Remove 4-byte header (hdr, UI, NLPID) */
  772. dev = pvc->main;
  773. skb->protocol = htons(ETH_P_IP);
  774. } else if (data[3] == NLPID_IPV6) {
  775. skb_pull(skb, 4); /* Remove 4-byte header (hdr, UI, NLPID) */
  776. dev = pvc->main;
  777. skb->protocol = htons(ETH_P_IPV6);
  778. } else if (skb->len > 10 && data[3] == FR_PAD &&
  779. data[4] == NLPID_SNAP && data[5] == FR_PAD) {
  780. u16 oui = ntohs(*(__be16*)(data + 6));
  781. u16 pid = ntohs(*(__be16*)(data + 8));
  782. skb_pull(skb, 10);
  783. switch ((((u32)oui) << 16) | pid) {
  784. case ETH_P_ARP: /* routed frame with SNAP */
  785. case ETH_P_IPX:
  786. case ETH_P_IP: /* a long variant */
  787. case ETH_P_IPV6:
  788. dev = pvc->main;
  789. skb->protocol = htons(pid);
  790. break;
  791. case 0x80C20007: /* bridged Ethernet frame */
  792. if ((dev = pvc->ether) != NULL)
  793. skb->protocol = eth_type_trans(skb, dev);
  794. break;
  795. default:
  796. printk(KERN_INFO "%s: Unsupported protocol, OUI=%x "
  797. "PID=%x\n", frad->name, oui, pid);
  798. dev_kfree_skb_any(skb);
  799. return NET_RX_DROP;
  800. }
  801. } else {
  802. printk(KERN_INFO "%s: Unsupported protocol, NLPID=%x "
  803. "length = %i\n", frad->name, data[3], skb->len);
  804. dev_kfree_skb_any(skb);
  805. return NET_RX_DROP;
  806. }
  807. if (dev) {
  808. dev->stats.rx_packets++; /* PVC traffic */
  809. dev->stats.rx_bytes += skb->len;
  810. if (pvc->state.becn)
  811. dev->stats.rx_compressed++;
  812. skb->dev = dev;
  813. netif_rx(skb);
  814. return NET_RX_SUCCESS;
  815. } else {
  816. dev_kfree_skb_any(skb);
  817. return NET_RX_DROP;
  818. }
  819. rx_error:
  820. frad->stats.rx_errors++; /* Mark error */
  821. dev_kfree_skb_any(skb);
  822. return NET_RX_DROP;
  823. }
  824. static void fr_start(struct net_device *dev)
  825. {
  826. hdlc_device *hdlc = dev_to_hdlc(dev);
  827. #ifdef DEBUG_LINK
  828. printk(KERN_DEBUG "fr_start\n");
  829. #endif
  830. if (state(hdlc)->settings.lmi != LMI_NONE) {
  831. state(hdlc)->reliable = 0;
  832. state(hdlc)->dce_changed = 1;
  833. state(hdlc)->request = 0;
  834. state(hdlc)->fullrep_sent = 0;
  835. state(hdlc)->last_errors = 0xFFFFFFFF;
  836. state(hdlc)->n391cnt = 0;
  837. state(hdlc)->txseq = state(hdlc)->rxseq = 0;
  838. init_timer(&state(hdlc)->timer);
  839. /* First poll after 1 s */
  840. state(hdlc)->timer.expires = jiffies + HZ;
  841. state(hdlc)->timer.function = fr_timer;
  842. state(hdlc)->timer.data = (unsigned long)dev;
  843. add_timer(&state(hdlc)->timer);
  844. } else
  845. fr_set_link_state(1, dev);
  846. }
  847. static void fr_stop(struct net_device *dev)
  848. {
  849. hdlc_device *hdlc = dev_to_hdlc(dev);
  850. #ifdef DEBUG_LINK
  851. printk(KERN_DEBUG "fr_stop\n");
  852. #endif
  853. if (state(hdlc)->settings.lmi != LMI_NONE)
  854. del_timer_sync(&state(hdlc)->timer);
  855. fr_set_link_state(0, dev);
  856. }
  857. static void fr_close(struct net_device *dev)
  858. {
  859. hdlc_device *hdlc = dev_to_hdlc(dev);
  860. pvc_device *pvc = state(hdlc)->first_pvc;
  861. while (pvc) { /* Shutdown all PVCs for this FRAD */
  862. if (pvc->main)
  863. dev_close(pvc->main);
  864. if (pvc->ether)
  865. dev_close(pvc->ether);
  866. pvc = pvc->next;
  867. }
  868. }
  869. static void pvc_setup(struct net_device *dev)
  870. {
  871. dev->type = ARPHRD_DLCI;
  872. dev->flags = IFF_POINTOPOINT;
  873. dev->hard_header_len = 10;
  874. dev->addr_len = 2;
  875. dev->priv_flags &= ~IFF_XMIT_DST_RELEASE;
  876. }
  877. static const struct net_device_ops pvc_ops = {
  878. .ndo_open = pvc_open,
  879. .ndo_stop = pvc_close,
  880. .ndo_change_mtu = hdlc_change_mtu,
  881. .ndo_start_xmit = pvc_xmit,
  882. .ndo_do_ioctl = pvc_ioctl,
  883. };
  884. static int fr_add_pvc(struct net_device *frad, unsigned int dlci, int type)
  885. {
  886. hdlc_device *hdlc = dev_to_hdlc(frad);
  887. pvc_device *pvc;
  888. struct net_device *dev;
  889. int used;
  890. if ((pvc = add_pvc(frad, dlci)) == NULL) {
  891. printk(KERN_WARNING "%s: Memory squeeze on fr_add_pvc()\n",
  892. frad->name);
  893. return -ENOBUFS;
  894. }
  895. if (*get_dev_p(pvc, type))
  896. return -EEXIST;
  897. used = pvc_is_used(pvc);
  898. if (type == ARPHRD_ETHER) {
  899. dev = alloc_netdev(0, "pvceth%d", ether_setup);
  900. dev->priv_flags &= ~IFF_TX_SKB_SHARING;
  901. } else
  902. dev = alloc_netdev(0, "pvc%d", pvc_setup);
  903. if (!dev) {
  904. printk(KERN_WARNING "%s: Memory squeeze on fr_pvc()\n",
  905. frad->name);
  906. delete_unused_pvcs(hdlc);
  907. return -ENOBUFS;
  908. }
  909. if (type == ARPHRD_ETHER)
  910. random_ether_addr(dev->dev_addr);
  911. else {
  912. *(__be16*)dev->dev_addr = htons(dlci);
  913. dlci_to_q922(dev->broadcast, dlci);
  914. }
  915. dev->netdev_ops = &pvc_ops;
  916. dev->mtu = HDLC_MAX_MTU;
  917. dev->tx_queue_len = 0;
  918. dev->ml_priv = pvc;
  919. if (register_netdevice(dev) != 0) {
  920. free_netdev(dev);
  921. delete_unused_pvcs(hdlc);
  922. return -EIO;
  923. }
  924. dev->destructor = free_netdev;
  925. *get_dev_p(pvc, type) = dev;
  926. if (!used) {
  927. state(hdlc)->dce_changed = 1;
  928. state(hdlc)->dce_pvc_count++;
  929. }
  930. return 0;
  931. }
  932. static int fr_del_pvc(hdlc_device *hdlc, unsigned int dlci, int type)
  933. {
  934. pvc_device *pvc;
  935. struct net_device *dev;
  936. if ((pvc = find_pvc(hdlc, dlci)) == NULL)
  937. return -ENOENT;
  938. if ((dev = *get_dev_p(pvc, type)) == NULL)
  939. return -ENOENT;
  940. if (dev->flags & IFF_UP)
  941. return -EBUSY; /* PVC in use */
  942. unregister_netdevice(dev); /* the destructor will free_netdev(dev) */
  943. *get_dev_p(pvc, type) = NULL;
  944. if (!pvc_is_used(pvc)) {
  945. state(hdlc)->dce_pvc_count--;
  946. state(hdlc)->dce_changed = 1;
  947. }
  948. delete_unused_pvcs(hdlc);
  949. return 0;
  950. }
  951. static void fr_destroy(struct net_device *frad)
  952. {
  953. hdlc_device *hdlc = dev_to_hdlc(frad);
  954. pvc_device *pvc = state(hdlc)->first_pvc;
  955. state(hdlc)->first_pvc = NULL; /* All PVCs destroyed */
  956. state(hdlc)->dce_pvc_count = 0;
  957. state(hdlc)->dce_changed = 1;
  958. while (pvc) {
  959. pvc_device *next = pvc->next;
  960. /* destructors will free_netdev() main and ether */
  961. if (pvc->main)
  962. unregister_netdevice(pvc->main);
  963. if (pvc->ether)
  964. unregister_netdevice(pvc->ether);
  965. kfree(pvc);
  966. pvc = next;
  967. }
  968. }
  969. static struct hdlc_proto proto = {
  970. .close = fr_close,
  971. .start = fr_start,
  972. .stop = fr_stop,
  973. .detach = fr_destroy,
  974. .ioctl = fr_ioctl,
  975. .netif_rx = fr_rx,
  976. .module = THIS_MODULE,
  977. };
  978. static int fr_ioctl(struct net_device *dev, struct ifreq *ifr)
  979. {
  980. fr_proto __user *fr_s = ifr->ifr_settings.ifs_ifsu.fr;
  981. const size_t size = sizeof(fr_proto);
  982. fr_proto new_settings;
  983. hdlc_device *hdlc = dev_to_hdlc(dev);
  984. fr_proto_pvc pvc;
  985. int result;
  986. switch (ifr->ifr_settings.type) {
  987. case IF_GET_PROTO:
  988. if (dev_to_hdlc(dev)->proto != &proto) /* Different proto */
  989. return -EINVAL;
  990. ifr->ifr_settings.type = IF_PROTO_FR;
  991. if (ifr->ifr_settings.size < size) {
  992. ifr->ifr_settings.size = size; /* data size wanted */
  993. return -ENOBUFS;
  994. }
  995. if (copy_to_user(fr_s, &state(hdlc)->settings, size))
  996. return -EFAULT;
  997. return 0;
  998. case IF_PROTO_FR:
  999. if (!capable(CAP_NET_ADMIN))
  1000. return -EPERM;
  1001. if (dev->flags & IFF_UP)
  1002. return -EBUSY;
  1003. if (copy_from_user(&new_settings, fr_s, size))
  1004. return -EFAULT;
  1005. if (new_settings.lmi == LMI_DEFAULT)
  1006. new_settings.lmi = LMI_ANSI;
  1007. if ((new_settings.lmi != LMI_NONE &&
  1008. new_settings.lmi != LMI_ANSI &&
  1009. new_settings.lmi != LMI_CCITT &&
  1010. new_settings.lmi != LMI_CISCO) ||
  1011. new_settings.t391 < 1 ||
  1012. new_settings.t392 < 2 ||
  1013. new_settings.n391 < 1 ||
  1014. new_settings.n392 < 1 ||
  1015. new_settings.n393 < new_settings.n392 ||
  1016. new_settings.n393 > 32 ||
  1017. (new_settings.dce != 0 &&
  1018. new_settings.dce != 1))
  1019. return -EINVAL;
  1020. result=hdlc->attach(dev, ENCODING_NRZ,PARITY_CRC16_PR1_CCITT);
  1021. if (result)
  1022. return result;
  1023. if (dev_to_hdlc(dev)->proto != &proto) { /* Different proto */
  1024. result = attach_hdlc_protocol(dev, &proto,
  1025. sizeof(struct frad_state));
  1026. if (result)
  1027. return result;
  1028. state(hdlc)->first_pvc = NULL;
  1029. state(hdlc)->dce_pvc_count = 0;
  1030. }
  1031. memcpy(&state(hdlc)->settings, &new_settings, size);
  1032. dev->type = ARPHRD_FRAD;
  1033. return 0;
  1034. case IF_PROTO_FR_ADD_PVC:
  1035. case IF_PROTO_FR_DEL_PVC:
  1036. case IF_PROTO_FR_ADD_ETH_PVC:
  1037. case IF_PROTO_FR_DEL_ETH_PVC:
  1038. if (dev_to_hdlc(dev)->proto != &proto) /* Different proto */
  1039. return -EINVAL;
  1040. if (!capable(CAP_NET_ADMIN))
  1041. return -EPERM;
  1042. if (copy_from_user(&pvc, ifr->ifr_settings.ifs_ifsu.fr_pvc,
  1043. sizeof(fr_proto_pvc)))
  1044. return -EFAULT;
  1045. if (pvc.dlci <= 0 || pvc.dlci >= 1024)
  1046. return -EINVAL; /* Only 10 bits, DLCI 0 reserved */
  1047. if (ifr->ifr_settings.type == IF_PROTO_FR_ADD_ETH_PVC ||
  1048. ifr->ifr_settings.type == IF_PROTO_FR_DEL_ETH_PVC)
  1049. result = ARPHRD_ETHER; /* bridged Ethernet device */
  1050. else
  1051. result = ARPHRD_DLCI;
  1052. if (ifr->ifr_settings.type == IF_PROTO_FR_ADD_PVC ||
  1053. ifr->ifr_settings.type == IF_PROTO_FR_ADD_ETH_PVC)
  1054. return fr_add_pvc(dev, pvc.dlci, result);
  1055. else
  1056. return fr_del_pvc(hdlc, pvc.dlci, result);
  1057. }
  1058. return -EINVAL;
  1059. }
  1060. static int __init mod_init(void)
  1061. {
  1062. register_hdlc_protocol(&proto);
  1063. return 0;
  1064. }
  1065. static void __exit mod_exit(void)
  1066. {
  1067. unregister_hdlc_protocol(&proto);
  1068. }
  1069. module_init(mod_init);
  1070. module_exit(mod_exit);
  1071. MODULE_AUTHOR("Krzysztof Halasa <khc@pm.waw.pl>");
  1072. MODULE_DESCRIPTION("Frame-Relay protocol support for generic HDLC");
  1073. MODULE_LICENSE("GPL v2");