Loading...
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 | /* * NET An implementation of the IEEE 802.2 LLC protocol for the * LINUX operating system. LLC is implemented as a set of * state machines and callbacks for higher networking layers. * * Code for initialization, termination, registration and * MAC layer glue. * * Written by Tim Alpaerts, Tim_Alpaerts@toyota-motor-europe.com * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License * as published by the Free Software Foundation; either version * 2 of the License, or (at your option) any later version. * * Changes * Alan Cox : Chainsawed to Linux format * Added llc_ to names * Started restructuring handlers */ #include <linux/module.h> #include <linux/version.h> #include <linux/kernel.h> #include <linux/malloc.h> #include <linux/unistd.h> #include <linux/netdevice.h> #include <linux/init.h> #include <net/p8022.h> #include <asm/byteorder.h> #include <net/llc_frame.h> #include <net/llc.h> /* * All incoming frames pass thru mac_data_indicate(). * On entry the llc structure related to the frame is passed as parameter. * The received sk_buffs with pdus other than I_CMD and I_RSP * are freed by mac_data_indicate() after processing, * the I pdu buffers are freed by the cl2llc client when it no longer needs * the skb. */ int llc_mac_data_indicate(llcptr lp, struct sk_buff *skb) { int ll; /* logical length == 802.3 length field */ unsigned char p_flag; unsigned char type; frameptr fr; int free=1; lp->inc_skb=NULL; /* * Truncate buffer to true 802.3 length * [FIXME: move to 802.2 demux] */ ll = *(skb->data -2) * 256 + *(skb->data -1); skb_trim( skb, ll ); fr = (frameptr) skb->data; type = llc_decode_frametype( fr ); if (type <= FRMR_RSP) { /* * PDU is of the type 2 set */ if ((lp->llc_mode == MODE_ABM)||(type == SABME_CMD)) llc_process_otype2_frame(lp, skb, type); } else { /* * PDU belongs to type 1 set */ p_flag = fr->u_hdr.u_pflag; switch(type) { case TEST_CMD: llc_sendpdu(lp, TEST_RSP, 0,ll -3, fr->u_hdr.u_info); break; case TEST_RSP: lp->llc_callbacks|=LLC_TEST_INDICATION; lp->inc_skb=skb; free=0; break; case XID_CMD: /* * Basic format XID is handled by LLC itself * Doc 5.4.1.1.2 p 48/49 */ if ((ll == 6)&&(fr->u_hdr.u_info[0] == 0x81)) { lp->k = fr->u_hdr.u_info[2]; llc_sendpdu(lp, XID_RSP, fr->u_hdr.u_pflag, ll -3, fr->u_hdr.u_info); } break; case XID_RSP: if( ll == 6 && fr->u_hdr.u_info[0] == 0x81 ) { lp->k = fr->u_hdr.u_info[2]; } lp->llc_callbacks|=LLC_XID_INDICATION; lp->inc_skb=skb; free=0; break; case UI_CMD: lp->llc_callbacks|=LLC_UI_DATA; skb_pull(skb,3); lp->inc_skb=skb; free=0; break; default: /* * All other type 1 pdus ignored for now */ } } if (free&&(!(IS_IFRAME(fr)))) { /* * No auto free for I pdus */ skb->sk = NULL; kfree_skb(skb); } if(lp->llc_callbacks) { if ( lp->llc_event != NULL ) lp->llc_event(lp); lp->llc_callbacks=0; } return 0; } /* * Create an LLC client. As it is the job of the caller to clean up * LLC's on device down, the device list must be locked before this call. */ int register_cl2llc_client(llcptr lp, const char *device, void (*event)(llcptr), u8 *rmac, u8 ssap, u8 dsap) { char eye_init[] = "LLC\0"; memset(lp, 0, sizeof(*lp)); lp->dev = dev_get(device); if(lp->dev == NULL) return -ENODEV; memcpy(lp->eye, eye_init, sizeof(lp->eye)); lp->rw = 1; lp->k = 127; lp->n1 = 1490; lp->n2 = 10; lp->timer_interval[P_TIMER] = HZ; /* 1 sec */ lp->timer_interval[REJ_TIMER] = HZ/8; lp->timer_interval[ACK_TIMER] = HZ/8; lp->timer_interval[BUSY_TIMER] = HZ*2; lp->local_sap = ssap; lp->llc_event = event; memcpy(lp->remote_mac, rmac, sizeof(lp->remote_mac)); lp->state = 0; lp->llc_mode = MODE_ADM; lp->remote_sap = dsap; skb_queue_head_init(&lp->atq); skb_queue_head_init(&lp->rtq); MOD_INC_USE_COUNT; return 0; } void unregister_cl2llc_client(llcptr lp) { llc_cancel_timers(lp); MOD_DEC_USE_COUNT; kfree(lp); } EXPORT_SYMBOL(register_cl2llc_client); EXPORT_SYMBOL(unregister_cl2llc_client); EXPORT_SYMBOL(llc_data_request); EXPORT_SYMBOL(llc_unit_data_request); EXPORT_SYMBOL(llc_test_request); EXPORT_SYMBOL(llc_xid_request); EXPORT_SYMBOL(llc_mac_data_indicate); EXPORT_SYMBOL(llc_cancel_timers); #define ALL_TYPES_8022 0 __initfunc(void llc_init(struct net_proto *proto)) { printk(KERN_NOTICE "IEEE 802.2 LLC for Linux 2.1 (c) 1996 Tim Alpaerts\n"); return; } #ifdef MODULE int init_module(void) { llc_init(NULL); return 0; } void cleanup_module(void) { } #endif |