llc_actn.c 3.73 KB
Newer Older
Arnaldo Carvalho de Melo's avatar
Arnaldo Carvalho de Melo committed
1 2 3 4 5 6 7 8 9 10
/*
 * llc_actn.c - Implementation of actions of station component of LLC
 *
 * Description :
 *   Functions in this module are implementation of station component actions.
 *   Details of actions can be found in IEEE-802.2 standard document.
 *   All functions have one station and one event as input argument. All of
 *   them return 0 On success and 1 otherwise.
 *
 * Copyright (c) 1997 by Procom Technology, Inc.
11
 * 		 2001-2003 by Arnaldo Carvalho de Melo <acme@conectiva.com.br>
Arnaldo Carvalho de Melo's avatar
Arnaldo Carvalho de Melo committed
12 13 14 15 16 17 18 19 20 21 22 23
 *
 * 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/netdevice.h>
#include <net/llc_if.h>
#include <net/llc_evnt.h>
#include <net/llc_pdu.h>
24 25
#include <net/llc_sap.h>
#include <net/llc_station.h>
26
#include "llc_output.h"
Arnaldo Carvalho de Melo's avatar
Arnaldo Carvalho de Melo committed
27 28

int llc_station_ac_start_ack_timer(struct llc_station *station,
29
				   struct sk_buff *skb)
Arnaldo Carvalho de Melo's avatar
Arnaldo Carvalho de Melo committed
30
{
31
	mod_timer(&station->ack_timer, jiffies + LLC_ACK_TIME * HZ);
Arnaldo Carvalho de Melo's avatar
Arnaldo Carvalho de Melo committed
32 33 34 35
	return 0;
}

int llc_station_ac_set_retry_cnt_0(struct llc_station *station,
36
				   struct sk_buff *skb)
Arnaldo Carvalho de Melo's avatar
Arnaldo Carvalho de Melo committed
37 38 39 40 41 42
{
	station->retry_count = 0;
	return 0;
}

int llc_station_ac_inc_retry_cnt_by_1(struct llc_station *station,
43
				      struct sk_buff *skb)
Arnaldo Carvalho de Melo's avatar
Arnaldo Carvalho de Melo committed
44 45 46 47 48 49
{
	station->retry_count++;
	return 0;
}

int llc_station_ac_set_xid_r_cnt_0(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
{
	station->xid_r_count = 0;
	return 0;
}

int llc_station_ac_inc_xid_r_cnt_by_1(struct llc_station *station,
57
				      struct sk_buff *skb)
Arnaldo Carvalho de Melo's avatar
Arnaldo Carvalho de Melo committed
58 59 60 61 62 63
{
	station->xid_r_count++;
	return 0;
}

int llc_station_ac_send_null_dsap_xid_c(struct llc_station *station,
64
					struct sk_buff *skb)
Arnaldo Carvalho de Melo's avatar
Arnaldo Carvalho de Melo committed
65 66
{
	int rc = 1;
67
	struct sk_buff *nskb = llc_alloc_frame();
Arnaldo Carvalho de Melo's avatar
Arnaldo Carvalho de Melo committed
68

69
	if (!nskb)
Arnaldo Carvalho de Melo's avatar
Arnaldo Carvalho de Melo committed
70
		goto out;
71 72
	llc_pdu_header_init(nskb, LLC_PDU_TYPE_U, 0, 0, LLC_PDU_CMD);
	llc_pdu_init_as_xid_cmd(nskb, LLC_XID_NULL_CLASS_2, 127);
73 74 75
	rc = llc_mac_hdr_init(nskb, station->mac_sa, station->mac_sa);
	if (rc)
		goto free;
76
	llc_station_send_pdu(station, nskb);
Arnaldo Carvalho de Melo's avatar
Arnaldo Carvalho de Melo committed
77 78
out:
	return rc;
79 80 81
free:
	kfree_skb(skb);
	goto out;
Arnaldo Carvalho de Melo's avatar
Arnaldo Carvalho de Melo committed
82 83 84
}

int llc_station_ac_send_xid_r(struct llc_station *station,
85
			      struct sk_buff *skb)
Arnaldo Carvalho de Melo's avatar
Arnaldo Carvalho de Melo committed
86 87 88
{
	u8 mac_da[ETH_ALEN], dsap;
	int rc = 1;
89
	struct sk_buff* nskb = llc_alloc_frame();
Arnaldo Carvalho de Melo's avatar
Arnaldo Carvalho de Melo committed
90

91
	if (!nskb)
Arnaldo Carvalho de Melo's avatar
Arnaldo Carvalho de Melo committed
92 93
		goto out;
	rc = 0;
94 95 96 97 98
	nskb->dev = skb->dev;
	llc_pdu_decode_sa(skb, mac_da);
	llc_pdu_decode_ssap(skb, &dsap);
	llc_pdu_header_init(nskb, LLC_PDU_TYPE_U, 0, dsap, LLC_PDU_RSP);
	llc_pdu_init_as_xid_rsp(nskb, LLC_XID_NULL_CLASS_2, 127);
99 100 101
	rc = llc_mac_hdr_init(nskb, station->mac_sa, mac_da);
	if (rc)
		goto free;
102
	llc_station_send_pdu(station, nskb);
Arnaldo Carvalho de Melo's avatar
Arnaldo Carvalho de Melo committed
103 104
out:
	return rc;
105 106 107
free:
	kfree_skb(skb);
	goto out;
Arnaldo Carvalho de Melo's avatar
Arnaldo Carvalho de Melo committed
108 109 110
}

int llc_station_ac_send_test_r(struct llc_station *station,
111
			       struct sk_buff *skb)
Arnaldo Carvalho de Melo's avatar
Arnaldo Carvalho de Melo committed
112 113 114
{
	u8 mac_da[ETH_ALEN], dsap;
	int rc = 1;
115
	struct sk_buff *nskb = llc_alloc_frame();
Arnaldo Carvalho de Melo's avatar
Arnaldo Carvalho de Melo committed
116

117
	if (!nskb)
Arnaldo Carvalho de Melo's avatar
Arnaldo Carvalho de Melo committed
118 119
		goto out;
	rc = 0;
120 121 122 123 124
	nskb->dev = skb->dev;
	llc_pdu_decode_sa(skb, mac_da);
	llc_pdu_decode_ssap(skb, &dsap);
	llc_pdu_header_init(nskb, LLC_PDU_TYPE_U, 0, dsap, LLC_PDU_RSP);
       	llc_pdu_init_as_test_rsp(nskb, skb);
125 126 127
	rc = llc_mac_hdr_init(nskb, station->mac_sa, mac_da);
	if (rc)
		goto free;
128
	llc_station_send_pdu(station, nskb);
Arnaldo Carvalho de Melo's avatar
Arnaldo Carvalho de Melo committed
129 130
out:
	return rc;
131 132 133
free:
	kfree_skb(skb);
	goto out;
Arnaldo Carvalho de Melo's avatar
Arnaldo Carvalho de Melo committed
134 135 136
}

int llc_station_ac_report_status(struct llc_station *station,
137
				 struct sk_buff *skb)
Arnaldo Carvalho de Melo's avatar
Arnaldo Carvalho de Melo committed
138 139 140 141
{
	return 0;
}

142
void llc_station_ack_tmr_cb(unsigned long timeout_data)
Arnaldo Carvalho de Melo's avatar
Arnaldo Carvalho de Melo committed
143 144
{
	struct llc_station *station = (struct llc_station *)timeout_data;
145
	struct sk_buff *skb = alloc_skb(0, GFP_ATOMIC);
Arnaldo Carvalho de Melo's avatar
Arnaldo Carvalho de Melo committed
146

147 148 149
	if (skb) {
		struct llc_station_state_ev *ev = llc_station_ev(skb);

Arnaldo Carvalho de Melo's avatar
Arnaldo Carvalho de Melo committed
150
		ev->type = LLC_STATION_EV_TYPE_ACK_TMR;
151
		llc_station_state_process(station, skb);
Arnaldo Carvalho de Melo's avatar
Arnaldo Carvalho de Melo committed
152 153
	}
}