2 * llc_if.c - Defines LLC interface to upper layer
4 * Copyright (c) 1997 by Procom Technology, Inc.
5 * 2001-2003 by Arnaldo Carvalho de Melo <acme@conectiva.com.br>
7 * This program can be redistributed or modified under the terms of the
8 * GNU General Public License as published by the Free Software Foundation.
9 * This program is distributed without any warranty or implied warranty
10 * of merchantability or fitness for a particular purpose.
12 * See the GNU General Public License for more details.
14 #include <linux/config.h>
15 #include <linux/module.h>
16 #include <linux/kernel.h>
17 #include <linux/netdevice.h>
18 #include <asm/errno.h>
19 #include <net/llc_if.h>
20 #include <net/llc_sap.h>
21 #include <net/llc_s_ev.h>
22 #include <net/llc_conn.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/tcp_states.h>
29 u8 llc_mac_null_var
[IFHWADDRLEN
];
32 * llc_build_and_send_pkt - Connection data sending for upper layers.
34 * @skb: packet to send
36 * This function is called when upper layer wants to send data using
37 * connection oriented communication mode. During sending data, connection
38 * will be locked and received frames and expired timers will be queued.
39 * Returns 0 for success, -ECONNABORTED when the connection already
40 * closed and -EBUSY when sending data is not permitted in this state or
41 * LLC has send an I pdu with p bit set to 1 and is waiting for it's
44 int llc_build_and_send_pkt(struct sock
*sk
, struct sk_buff
*skb
)
46 struct llc_conn_state_ev
*ev
;
47 int rc
= -ECONNABORTED
;
48 struct llc_sock
*llc
= llc_sk(sk
);
50 if (llc
->state
== LLC_CONN_STATE_ADM
)
53 if (llc_data_accept_state(llc
->state
)) { /* data_conn_refuse */
54 llc
->failed_data_req
= 1;
58 llc
->failed_data_req
= 1;
61 ev
= llc_conn_ev(skb
);
62 ev
->type
= LLC_CONN_EV_TYPE_PRIM
;
63 ev
->prim
= LLC_DATA_PRIM
;
64 ev
->prim_type
= LLC_PRIM_TYPE_REQ
;
66 rc
= llc_conn_state_process(sk
, skb
);
72 * llc_establish_connection - Called by upper layer to establish a conn
74 * @lmac: local mac address
75 * @dmac: destination mac address
76 * @dsap: destination sap
78 * Upper layer calls this to establish an LLC connection with a remote
79 * machine. This function packages a proper event and sends it connection
80 * component state machine. Success or failure of connection
81 * establishment will inform to upper layer via calling it's confirm
82 * function and passing proper information.
84 int llc_establish_connection(struct sock
*sk
, u8
*lmac
, u8
*dmac
, u8 dsap
)
87 struct llc_addr laddr
, daddr
;
89 struct llc_sock
*llc
= llc_sk(sk
);
90 struct sock
*existing
;
92 laddr
.lsap
= llc
->sap
->laddr
.lsap
;
94 memcpy(daddr
.mac
, dmac
, sizeof(daddr
.mac
));
95 memcpy(laddr
.mac
, lmac
, sizeof(laddr
.mac
));
96 existing
= llc_lookup_established(llc
->sap
, &daddr
, &laddr
);
98 if (existing
->sk_state
== TCP_ESTABLISHED
) {
106 skb
= alloc_skb(0, GFP_ATOMIC
);
108 struct llc_conn_state_ev
*ev
= llc_conn_ev(skb
);
110 ev
->type
= LLC_CONN_EV_TYPE_PRIM
;
111 ev
->prim
= LLC_CONN_PRIM
;
112 ev
->prim_type
= LLC_PRIM_TYPE_REQ
;
113 rc
= llc_conn_state_process(sk
, skb
);
121 * llc_send_disc - Called by upper layer to close a connection
122 * @sk: connection to be closed
124 * Upper layer calls this when it wants to close an established LLC
125 * connection with a remote machine. This function packages a proper event
126 * and sends it to connection component state machine. Returns 0 for
127 * success, 1 otherwise.
129 int llc_send_disc(struct sock
*sk
)
132 struct llc_conn_state_ev
*ev
;
136 if (sk
->sk_type
!= SOCK_STREAM
|| sk
->sk_state
!= TCP_ESTABLISHED
||
137 llc_sk(sk
)->state
== LLC_CONN_STATE_ADM
||
138 llc_sk(sk
)->state
== LLC_CONN_OUT_OF_SVC
)
141 * Postpone unassigning the connection from its SAP and returning the
142 * connection until all ACTIONs have been completely executed
144 skb
= alloc_skb(0, GFP_ATOMIC
);
147 sk
->sk_state
= TCP_CLOSING
;
148 ev
= llc_conn_ev(skb
);
149 ev
->type
= LLC_CONN_EV_TYPE_PRIM
;
150 ev
->prim
= LLC_DISC_PRIM
;
151 ev
->prim_type
= LLC_PRIM_TYPE_REQ
;
152 rc
= llc_conn_state_process(sk
, skb
);