llc_main.c 17 KB
Newer Older
Arnaldo Carvalho de Melo's avatar
Arnaldo Carvalho de Melo committed
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
/*
 * llc_main.c - This module contains main functions to manage station, saps
 * 	and connections of the LLC.
 *
 * Copyright (c) 1997 by Procom Technology, Inc.
 * 		 2001 by Arnaldo Carvalho de Melo <acme@conectiva.com.br>
 *
 * This program can be redistributed or modified under the terms of the
 * GNU General Public License as published by the Free Software Foundation.
 * This program is distributed without any warranty or implied warranty
 * of merchantability or fitness for a particular purpose.
 *
 * See the GNU General Public License for more details.
 */
#include <linux/kernel.h>
#include <linux/netdevice.h>
#include <net/sock.h>
#include <linux/sched.h>
#include <linux/init.h>
#include <linux/module.h>
#include <linux/proc_fs.h>
#include <net/llc_if.h>
#include <net/llc_sap.h>
#include <net/llc_conn.h>
#include <net/llc_main.h>
#include <net/llc_evnt.h>
#include <net/llc_actn.h>
#include <net/llc_stat.h>
#include <net/llc_c_ac.h>
#include <net/llc_s_ac.h>
#include <net/llc_c_ev.h>
#include <net/llc_c_st.h>
#include <net/llc_s_ev.h>
#include <net/llc_s_st.h>
#include <net/llc_mac.h>
#include <linux/llc.h>

/* static function prototypes */
static void llc_station_service_events(struct llc_station *station);
static void llc_station_free_ev(struct llc_station *station,
41
				struct sk_buff *skb);
Arnaldo Carvalho de Melo's avatar
Arnaldo Carvalho de Melo committed
42 43
static void llc_station_send_pdus(struct llc_station *station);
static u16 llc_station_next_state(struct llc_station *station,
44
				  struct sk_buff *skb);
Arnaldo Carvalho de Melo's avatar
Arnaldo Carvalho de Melo committed
45 46
static u16 llc_exec_station_trans_actions(struct llc_station *station,
					  struct llc_station_state_trans *trans,
47
					  struct sk_buff *skb);
Arnaldo Carvalho de Melo's avatar
Arnaldo Carvalho de Melo committed
48 49
static struct llc_station_state_trans *
			     llc_find_station_trans(struct llc_station *station,
50
						    struct sk_buff *skb);
Arnaldo Carvalho de Melo's avatar
Arnaldo Carvalho de Melo committed
51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70
static int llc_rtn_all_conns(struct llc_sap *sap);

static struct llc_station llc_main_station;	/* only one of its kind */

/**
 *	llc_sap_alloc - allocates and initializes sap.
 *
 *	Allocates and initializes sap.
 */
struct llc_sap *llc_sap_alloc(void)
{
	struct llc_sap *sap = kmalloc(sizeof(*sap), GFP_ATOMIC);

	if (sap) {
		memset(sap, 0, sizeof(*sap));
		sap->state = LLC_SAP_STATE_ACTIVE;
		memcpy(sap->laddr.mac, llc_main_station.mac_sa, ETH_ALEN);
		spin_lock_init(&sap->sk_list.lock);
		INIT_LIST_HEAD(&sap->sk_list.list);
		skb_queue_head_init(&sap->mac_pdu_q);
71 72
		sap->llc_ind_prim.data = &sap->llc_ind_data_prim;
		sap->llc_cfm_prim.data = &sap->llc_cfm_data_prim;
Arnaldo Carvalho de Melo's avatar
Arnaldo Carvalho de Melo committed
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
	}
	return sap;
}

/**
 *	llc_free_sap - frees a sap
 *	@sap: Address of the sap
 *
 * 	Frees all associated connections (if any), removes this sap from
 * 	the list of saps in te station and them frees the memory for this sap.
 */
void llc_free_sap(struct llc_sap *sap)
{
	struct llc_station *station = sap->parent_station;

	llc_rtn_all_conns(sap);
	spin_lock_bh(&station->sap_list.lock);
	list_del(&sap->node);
	spin_unlock_bh(&station->sap_list.lock);
	kfree(sap);
}

/**
 *	llc_sap_save - add sap to station list
 *	@sap: Address of the sap
 *
 *	Adds a sap to the LLC's station sap list.
 */
void llc_sap_save(struct llc_sap *sap)
{
	spin_lock_bh(&llc_main_station.sap_list.lock);
	list_add_tail(&sap->node, &llc_main_station.sap_list.list);
	spin_unlock_bh(&llc_main_station.sap_list.lock);
}

/**
 *	llc_sap_find - searchs a SAP in station
 *	@sap_value: sap to be found
 *
 *	Searchs for a sap in the sap list of the LLC's station upon the sap ID.
 *	Returns the sap or %NULL if not found.
 */
struct llc_sap *llc_sap_find(u8 sap_value)
{
	struct llc_sap* sap = NULL;
	struct list_head *entry;

	spin_lock_bh(&llc_main_station.sap_list.lock);
	list_for_each(entry, &llc_main_station.sap_list.list) {
		sap = list_entry(entry, struct llc_sap, node);
		if (sap->laddr.lsap == sap_value)
			break;
	}
	if (entry == &llc_main_station.sap_list.list) /* not found */
		sap = NULL;
	spin_unlock_bh(&llc_main_station.sap_list.lock);
	return sap;
}

/**
 *	llc_backlog_rcv - Processes rx frames and expired timers.
 *	@sk: LLC sock (p8022 connection)
 *	@skb: queued rx frame or event
 *
 *	This function processes frames that has received and timers that has
 *	expired during sending an I pdu (refer to data_req_handler).  frames
139
 *	queue by llc_rcv function (llc_mac.c) and timers queue by timer
Arnaldo Carvalho de Melo's avatar
Arnaldo Carvalho de Melo committed
140 141 142 143 144 145 146
 *	callback functions(llc_c_ac.c).
 */
static int llc_backlog_rcv(struct sock *sk, struct sk_buff *skb)
{
	int rc = 0;
	struct llc_opt *llc = llc_sk(sk);

147
	if (llc_backlog_type(skb) == LLC_PACKET) {
Arnaldo Carvalho de Melo's avatar
Arnaldo Carvalho de Melo committed
148 149 150 151
		if (llc->state > 1) /* not closed */
			rc = llc_pdu_router(llc->sap, sk, skb, LLC_TYPE_2);
		else
			kfree_skb(skb);
152
	} else if (llc_backlog_type(skb) == LLC_EVENT) {
Arnaldo Carvalho de Melo's avatar
Arnaldo Carvalho de Melo committed
153 154
		/* timer expiration event */
		if (llc->state > 1)  /* not closed */
155
			rc = llc_conn_state_process(sk, skb);
Arnaldo Carvalho de Melo's avatar
Arnaldo Carvalho de Melo committed
156
		else
157 158 159 160
			llc_conn_free_ev(skb);
		kfree_skb(skb);
	} else {
		printk(KERN_ERR "%s: invalid skb in backlog\n", __FUNCTION__);
Arnaldo Carvalho de Melo's avatar
Arnaldo Carvalho de Melo committed
161 162
		kfree_skb(skb);
	}
163

Arnaldo Carvalho de Melo's avatar
Arnaldo Carvalho de Melo committed
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
	return rc;
}

/**
 *     llc_sock_init - Initialize a socket with default llc values.
 *     @sk: socket to intiailize.
 */
int llc_sock_init(struct sock* sk)
{
	struct llc_opt *llc = kmalloc(sizeof(*llc), GFP_ATOMIC);
	int rc = -ENOMEM;

	if (!llc)
		goto out;
	memset(llc, 0, sizeof(*llc));
	rc = 0;
	llc->sk			     = sk;
	llc->state		     = LLC_CONN_STATE_ADM;
	llc->inc_cntr		     = llc->dec_cntr = 2;
	llc->dec_step		     = llc->connect_step = 1;
	llc->ack_timer.expire	     = LLC_ACK_TIME;
	llc->pf_cycle_timer.expire   = LLC_P_TIME;
	llc->rej_sent_timer.expire   = LLC_REJ_TIME;
	llc->busy_state_timer.expire = LLC_BUSY_TIME;
	llc->n2			     = 2;   /* max retransmit */
	llc->k			     = 2;   /* tx win size, will adjust dynam */
	llc->rw			     = 128; /* rx win size (opt and equal to
					     * tx_win of remote LLC)
					     */
	skb_queue_head_init(&llc->pdu_unack_q);
	sk->backlog_rcv = llc_backlog_rcv;
	llc_sk(sk) = llc;
out:
	return rc;
}

/**
 *	__llc_sock_alloc - Allocates LLC sock
202
 *	@family: upper layer protocol family
Arnaldo Carvalho de Melo's avatar
Arnaldo Carvalho de Melo committed
203 204 205 206
 *
 *	Allocates a LLC sock and initializes it. Returns the new LLC sock
 *	or %NULL if there's no memory available for one
 */
207
struct sock *__llc_sock_alloc(int family)
Arnaldo Carvalho de Melo's avatar
Arnaldo Carvalho de Melo committed
208
{
209
	struct sock *sk = sk_alloc(family, GFP_ATOMIC, 1, NULL);
Arnaldo Carvalho de Melo's avatar
Arnaldo Carvalho de Melo committed
210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236

	if (!sk)
		goto out;
	if (llc_sock_init(sk))
		goto outsk;
	sock_init_data(NULL, sk);
out:
	return sk;
outsk:
	sk_free(sk);
	sk = NULL;
	goto out;
}

/**
 *	__llc_sock_free - Frees a LLC socket
 *	@sk - socket to free
 *
 *	Frees a LLC socket
 */
void __llc_sock_free(struct sock *sk, u8 free)
{
	struct llc_opt *llc = llc_sk(sk);

	llc->state = LLC_CONN_OUT_OF_SVC;
	/* stop all (possibly) running timers */
	llc_conn_ac_stop_all_timers(sk, NULL);
237
#ifdef DEBUG_LLC_CONN_ALLOC
238
	printk(KERN_INFO "%s: unackq=%d, txq=%d\n", __FUNCTION__,
Arnaldo Carvalho de Melo's avatar
Arnaldo Carvalho de Melo committed
239 240
		skb_queue_len(&llc->pdu_unack_q),
		skb_queue_len(&sk->write_queue));
241
#endif
Arnaldo Carvalho de Melo's avatar
Arnaldo Carvalho de Melo committed
242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322
	skb_queue_purge(&sk->write_queue);
	skb_queue_purge(&llc->pdu_unack_q);
	if (free)
		sock_put(sk);
}

/**
 *	llc_sock_reset - resets a connection
 *	@sk: LLC socket to reset
 *
 *	Resets a connection to the out of service state. Stops its timers
 *	and frees any frames in the queues of the connection.
 */
void llc_sock_reset(struct sock *sk)
{
	struct llc_opt *llc = llc_sk(sk);

	llc_conn_ac_stop_all_timers(sk, NULL);
	skb_queue_purge(&sk->write_queue);
	skb_queue_purge(&llc->pdu_unack_q);
	llc->remote_busy_flag	= 0;
	llc->cause_flag		= 0;
	llc->retry_count	= 0;
	llc->p_flag		= 0;
	llc->f_flag		= 0;
	llc->s_flag		= 0;
	llc->ack_pf		= 0;
	llc->first_pdu_Ns	= 0;
	llc->ack_must_be_send	= 0;
	llc->dec_step		= 1;
	llc->inc_cntr		= 2;
	llc->dec_cntr		= 2;
	llc->X			= 0;
	llc->failed_data_req	= 0 ;
	llc->last_nr		= 0;
}

/**
 *	llc_rtn_all_conns - Closes all connections of a sap
 *	@sap: sap to close its connections
 *
 *	Closes all connections of a sap. Returns 0 if all actions complete
 *	successfully, nonzero otherwise
 */
static int llc_rtn_all_conns(struct llc_sap *sap)
{
	int rc = 0;
	union llc_u_prim_data prim_data;
	struct llc_prim_if_block prim;
	struct list_head *entry, *tmp;

	spin_lock_bh(&sap->sk_list.lock);
	if (list_empty(&sap->sk_list.list))
		goto out;
	list_for_each_safe(entry, tmp, &sap->sk_list.list) {
		struct llc_opt *llc = list_entry(entry, struct llc_opt, node);

		prim.sap = sap;
		prim_data.disc.sk = llc->sk;
		prim.prim = LLC_DISC_PRIM;
		prim.data = &prim_data;
		llc->state = LLC_CONN_STATE_TEMP;
		if (sap->req(&prim))
			rc = 1;
	}
out:
	spin_unlock_bh(&sap->sk_list.lock);
	return rc;
}

/**
 *	llc_station_get - get addr of global station.
 *
 *	Returns address of a place to copy the global station to it.
 */
struct llc_station *llc_station_get(void)
{
	return &llc_main_station;
}

/**
323
 *	llc_station_state_process: queue event and try to process queue.
Arnaldo Carvalho de Melo's avatar
Arnaldo Carvalho de Melo committed
324
 *	@station: Address of the station
325
 *	@skb: Address of the event
Arnaldo Carvalho de Melo's avatar
Arnaldo Carvalho de Melo committed
326 327 328 329
 *
 *	Queues an event (on the station event queue) for handling by the
 *	station state machine and attempts to process any queued-up events.
 */
330
void llc_station_state_process(struct llc_station *station, struct sk_buff *skb)
Arnaldo Carvalho de Melo's avatar
Arnaldo Carvalho de Melo committed
331 332
{
	spin_lock_bh(&station->ev_q.lock);
333
	skb_queue_tail(&station->ev_q.list, skb);
Arnaldo Carvalho de Melo's avatar
Arnaldo Carvalho de Melo committed
334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373
	llc_station_service_events(station);
	spin_unlock_bh(&station->ev_q.lock);
}

/**
 *	llc_station_send_pdu - queues PDU to send
 *	@station: Address of the station
 *	@skb: Address of the PDU
 *
 *	Queues a PDU to send to the MAC layer.
 */
void llc_station_send_pdu(struct llc_station *station, struct sk_buff *skb)
{
	skb_queue_tail(&station->mac_pdu_q, skb);
	llc_station_send_pdus(station);
}

/**
 *	llc_station_send_pdus - tries to send queued PDUs
 *	@station: Address of the station
 *
 *	Tries to send any PDUs queued in the station mac_pdu_q to the MAC
 *	layer.
 */
static void llc_station_send_pdus(struct llc_station *station)
{
	struct sk_buff *skb;

	while ((skb = skb_dequeue(&station->mac_pdu_q)) != NULL) {
		int rc = mac_send_pdu(skb);

		kfree_skb(skb);
		if (rc)
			break;
	}
}

/**
 *	llc_station_free_ev - frees an event
 *	@station: Address of the station
374
 *	@skb: Address of the event
Arnaldo Carvalho de Melo's avatar
Arnaldo Carvalho de Melo committed
375 376 377 378
 *
 *	Frees an event.
 */
static void llc_station_free_ev(struct llc_station *station,
379
				struct sk_buff *skb)
Arnaldo Carvalho de Melo's avatar
Arnaldo Carvalho de Melo committed
380
{
381
	struct llc_station_state_ev *ev = llc_station_ev(skb);
Arnaldo Carvalho de Melo's avatar
Arnaldo Carvalho de Melo committed
382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400

	if (ev->type == LLC_STATION_EV_TYPE_PDU)
		kfree_skb(skb);
}

/**
 *	llc_station_service_events - service events in the queue
 *	@station: Address of the station
 *
 *	Get an event from the station event queue (if any); attempt to service
 *	the event; if event serviced, get the next event (if any) on the event
 *	queue; if event not service, re-queue the event on the event queue and
 *	attempt to service the next event; when serviced all events in queue,
 *	finished; if don't transition to different state, just service all
 *	events once; if transition to new state, service all events again.
 *	Caller must hold station->ev_q.lock.
 */
static void llc_station_service_events(struct llc_station *station)
{
401
	struct sk_buff *skb;
Arnaldo Carvalho de Melo's avatar
Arnaldo Carvalho de Melo committed
402

403 404
	while ((skb = skb_dequeue(&station->ev_q.list)) != NULL)
		llc_station_next_state(station, skb);
Arnaldo Carvalho de Melo's avatar
Arnaldo Carvalho de Melo committed
405 406 407 408 409
}

/**
 *	llc_station_next_state - processes event and goes to the next state
 *	@station: Address of the station
410
 *	@skb: Address of the event
Arnaldo Carvalho de Melo's avatar
Arnaldo Carvalho de Melo committed
411 412 413 414 415
 *
 *	Processes an event, executes any transitions related to that event and
 *	updates the state of the station.
 */
static u16 llc_station_next_state(struct llc_station *station,
416
				  struct sk_buff *skb)
Arnaldo Carvalho de Melo's avatar
Arnaldo Carvalho de Melo committed
417 418 419 420 421 422
{
	u16 rc = 1;
	struct llc_station_state_trans *trans;

	if (station->state > LLC_NBR_STATION_STATES)
		goto out;
423
	trans = llc_find_station_trans(station, skb);
Arnaldo Carvalho de Melo's avatar
Arnaldo Carvalho de Melo committed
424 425 426 427 428
	if (trans) {
		/* got the state to which we next transition; perform the
		 * actions associated with this transition before actually
		 * transitioning to the next state
		 */
429
		rc = llc_exec_station_trans_actions(station, trans, skb);
Arnaldo Carvalho de Melo's avatar
Arnaldo Carvalho de Melo committed
430 431 432 433 434 435 436 437 438 439 440
		if (!rc)
			/* transition station to next state if all actions
			 * execute successfully; done; wait for next event
			 */
			station->state = trans->next_state;
	} else
		/* event not recognized in current state; re-queue it for
		 * processing again at a later time; return failure
		 */
		rc = 0;
out:
441
	llc_station_free_ev(station, skb);
Arnaldo Carvalho de Melo's avatar
Arnaldo Carvalho de Melo committed
442 443 444 445 446 447
	return rc;
}

/**
 *	llc_find_station_trans - finds transition for this event
 *	@station: Address of the station
448
 *	@skb: Address of the event
Arnaldo Carvalho de Melo's avatar
Arnaldo Carvalho de Melo committed
449 450 451 452 453 454
 *
 *	Search thru events of the current state of the station until list
 *	exhausted or it's obvious that the event is not valid for the current
 *	state. Returns the address of the transition if cound, %NULL otherwise.
 */
static struct llc_station_state_trans *
455 456
			llc_find_station_trans(struct llc_station *station,
					       struct sk_buff *skb)
Arnaldo Carvalho de Melo's avatar
Arnaldo Carvalho de Melo committed
457 458 459 460 461 462 463 464
{
	int i = 0;
	struct llc_station_state_trans *rc = NULL;
	struct llc_station_state_trans **next_trans;
	struct llc_station_state *curr_state =
				&llc_station_state_table[station->state - 1];

	for (next_trans = curr_state->transitions; next_trans[i]->ev; i++)
465
		if (!next_trans[i]->ev(station, skb)) {
Arnaldo Carvalho de Melo's avatar
Arnaldo Carvalho de Melo committed
466 467 468 469 470 471 472 473 474 475
			rc = next_trans[i];
			break;
		}
	return rc;
}

/**
 *	llc_exec_station_trans_actions - executes actions for transition
 *	@station: Address of the station
 *	@trans: Address of the transition
476
 *	@skb: Address of the event that caused the transition
Arnaldo Carvalho de Melo's avatar
Arnaldo Carvalho de Melo committed
477 478 479 480 481 482
 *
 *	Executes actions of a transition of the station state machine. Returns
 *	0 if all actions complete successfully, nonzero otherwise.
 */
static u16 llc_exec_station_trans_actions(struct llc_station *station,
					  struct llc_station_state_trans *trans,
483
					  struct sk_buff *skb)
Arnaldo Carvalho de Melo's avatar
Arnaldo Carvalho de Melo committed
484 485
{
	u16 rc = 0;
486
	llc_station_action_t *next_action = trans->ev_actions;
Arnaldo Carvalho de Melo's avatar
Arnaldo Carvalho de Melo committed
487

488 489
	for (; next_action && *next_action; next_action++)
		if ((*next_action)(station, skb))
Arnaldo Carvalho de Melo's avatar
Arnaldo Carvalho de Melo committed
490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557
			rc = 1;
	return rc;
}

/**
 *	llc_alloc_frame - allocates sk_buff for frame
 *
 *	Allocates an sk_buff for frame and initializes sk_buff fields.
 *	Returns allocated skb or %NULL when out of memory.
 */
struct sk_buff *llc_alloc_frame(void)
{
	struct sk_buff *skb = alloc_skb(128, GFP_ATOMIC);

	if (skb) {
		skb_reserve(skb, 50);
		skb->nh.raw   = skb->h.raw = skb->data;
		skb->protocol = htons(ETH_P_802_2);
		skb->dev      = dev_base->next;
		skb->mac.raw  = skb->head;
	}
	return skb;
}

static int llc_proc_get_info(char *bf, char **start, off_t offset, int length)
{
	struct llc_opt *llc;
	struct list_head *sap_entry, *llc_entry;
	off_t begin = 0, pos = 0;
	int len = 0;

	spin_lock_bh(&llc_main_station.sap_list.lock);
	list_for_each(sap_entry, &llc_main_station.sap_list.list) {
		struct llc_sap *sap = list_entry(sap_entry, struct llc_sap,
						 node);

		len += sprintf(bf + len, "lsap=%d\n", sap->laddr.lsap);
		spin_lock_bh(&sap->sk_list.lock);
		if (list_empty(&sap->sk_list.list)) {
			len += sprintf(bf + len, "no connections\n");
			goto unlock;
		}
		len += sprintf(bf + len,
				"connection list:\nstate  retr txwin rxwin\n");
		list_for_each(llc_entry, &sap->sk_list.list) {
			llc = list_entry(llc_entry, struct llc_opt, node);
			len += sprintf(bf + len, "  %-5d%-5d%-6d%-5d\n",
					llc->state, llc->retry_count, llc->k,
					llc->rw);
		}
unlock:	
		spin_unlock_bh(&sap->sk_list.lock);
		pos = begin + len;
		if (pos < offset) {
			len = 0; /* Keep dumping into the buffer start */
			begin = pos;
		}
		if (pos > offset + length) /* We have dumped enough */
			break;
	}
	spin_unlock_bh(&llc_main_station.sap_list.lock);

	/* The data in question runs from begin to begin + len */
	*start = bf + (offset - begin); /* Start of wanted data */
	len -= (offset - begin); /* Remove unwanted header data from length */
	return len;
}

558 559
static struct packet_type llc_packet_type = {
	.type = __constant_htons(ETH_P_802_2),
560
	.func = llc_rcv,
561
	.data = (void *)1,
562 563 564 565
};

static struct packet_type llc_tr_packet_type = {
	.type = __constant_htons(ETH_P_TR_802_2),
566
	.func = llc_rcv,
567
	.data = (void *)1,
568 569
};

Arnaldo Carvalho de Melo's avatar
Arnaldo Carvalho de Melo committed
570 571 572 573 574 575 576 577 578
static char llc_banner[] __initdata =
		KERN_INFO "LLC 2.0 by Procom, 1997, Arnaldo C. Melo, 2001\n"
		KERN_INFO "NET4.0 IEEE 802.2 extended support\n";
static char llc_error_msg[] __initdata =
		KERN_ERR "LLC install NOT successful.\n";

static int __init llc_init(void)
{
	u16 rc = 0;
579
	struct sk_buff *skb;
Arnaldo Carvalho de Melo's avatar
Arnaldo Carvalho de Melo committed
580 581 582 583 584 585
	struct llc_station_state_ev *ev;

	printk(llc_banner);
	INIT_LIST_HEAD(&llc_main_station.sap_list.list);
	spin_lock_init(&llc_main_station.sap_list.lock);
	skb_queue_head_init(&llc_main_station.mac_pdu_q);
586 587 588 589
	skb_queue_head_init(&llc_main_station.ev_q.list);
	spin_lock_init(&llc_main_station.ev_q.lock);
	skb = alloc_skb(1, GFP_ATOMIC);
	if (!skb)
Arnaldo Carvalho de Melo's avatar
Arnaldo Carvalho de Melo committed
590
		goto err;
591
	llc_build_offset_table();
592
	ev = llc_station_ev(skb);
Arnaldo Carvalho de Melo's avatar
Arnaldo Carvalho de Melo committed
593
	memset(ev, 0, sizeof(*ev));
594 595 596
	if (dev_base->next)
		memcpy(llc_main_station.mac_sa,
		       dev_base->next->dev_addr, ETH_ALEN);
Arnaldo Carvalho de Melo's avatar
Arnaldo Carvalho de Melo committed
597 598 599 600 601 602 603
	else
		memset(llc_main_station.mac_sa, 0, ETH_ALEN);
	llc_main_station.ack_timer.expires = jiffies + 3 * HZ;
	llc_main_station.maximum_retry	= 1;
	llc_main_station.state		= LLC_STATION_STATE_DOWN;
	ev->type	= LLC_STATION_EV_TYPE_SIMPLE;
	ev->data.a.ev	= LLC_STATION_EV_ENABLE_WITHOUT_DUP_ADDR_CHECK;
604
	rc = llc_station_next_state(&llc_main_station, skb);
Arnaldo Carvalho de Melo's avatar
Arnaldo Carvalho de Melo committed
605 606
	proc_net_create("802.2", 0, llc_proc_get_info);
	llc_ui_init();
607 608
	dev_add_pack(&llc_packet_type);
	dev_add_pack(&llc_tr_packet_type);
Arnaldo Carvalho de Melo's avatar
Arnaldo Carvalho de Melo committed
609 610 611 612 613 614 615 616 617 618 619
out:
	return rc;
err:
	printk(llc_error_msg);
	rc = 1;
	goto out;
}

static void __exit llc_exit(void)
{
	llc_ui_exit();
620 621
	dev_remove_pack(&llc_packet_type);
	dev_remove_pack(&llc_tr_packet_type);
Arnaldo Carvalho de Melo's avatar
Arnaldo Carvalho de Melo committed
622 623 624 625 626 627 628 629 630
	proc_net_remove("802.2");
}

module_init(llc_init);
module_exit(llc_exit);

MODULE_LICENSE("GPL");
MODULE_AUTHOR("Procom, 1997, Arnaldo C. Melo, Jay Schullist, 2001");
MODULE_DESCRIPTION("LLC 2.0, NET4.0 IEEE 802.2 extended support");