1 /*********************************************************************
3 * Filename: irlan_provider.c
5 * Description: IrDA LAN Access Protocol Implementation
6 * Status: Experimental.
7 * Author: Dag Brattli <dagb@cs.uit.no>
8 * Created at: Sun Aug 31 20:14:37 1997
9 * Modified at: Sat Oct 30 12:52:10 1999
10 * Modified by: Dag Brattli <dagb@cs.uit.no>
11 * Sources: skeleton.c by Donald Becker <becker@CESDIS.gsfc.nasa.gov>
12 * slip.c by Laurence Culhane, <loz@holmes.demon.co.uk>
13 * Fred N. van Kempen, <waltje@uwalt.nl.mugnet.org>
15 * Copyright (c) 1998-1999 Dag Brattli <dagb@cs.uit.no>,
16 * All Rights Reserved.
18 * This program is free software; you can redistribute it and/or
19 * modify it under the terms of the GNU General Public License as
20 * published by the Free Software Foundation; either version 2 of
21 * the License, or (at your option) any later version.
23 * Neither Dag Brattli nor University of Tromsø admit liability nor
24 * provide warranty for any of this software. This material is
25 * provided "AS-IS" and at no charge.
27 ********************************************************************/
29 #include <linux/kernel.h>
30 #include <linux/string.h>
31 #include <linux/errno.h>
32 #include <linux/netdevice.h>
33 #include <linux/etherdevice.h>
34 #include <linux/init.h>
35 #include <linux/random.h>
36 #include <linux/bitops.h>
37 #include <linux/slab.h>
39 #include <asm/byteorder.h>
41 #include <net/irda/irda.h>
42 #include <net/irda/irttp.h>
43 #include <net/irda/irlmp.h>
44 #include <net/irda/irias_object.h>
45 #include <net/irda/iriap.h>
46 #include <net/irda/timer.h>
48 #include <net/irda/irlan_common.h>
49 #include <net/irda/irlan_eth.h>
50 #include <net/irda/irlan_event.h>
51 #include <net/irda/irlan_provider.h>
52 #include <net/irda/irlan_filter.h>
53 #include <net/irda/irlan_client.h>
55 static void irlan_provider_connect_indication(void *instance
, void *sap
,
62 * Function irlan_provider_control_data_indication (handle, skb)
64 * This function gets the data that is received on the control channel
67 static int irlan_provider_data_indication(void *instance
, void *sap
,
70 struct irlan_cb
*self
;
75 IRDA_ASSERT(self
!= NULL
, return -1;);
76 IRDA_ASSERT(self
->magic
== IRLAN_MAGIC
, return -1;);
78 IRDA_ASSERT(skb
!= NULL
, return -1;);
82 case CMD_GET_PROVIDER_INFO
:
83 pr_debug("Got GET_PROVIDER_INFO command!\n");
84 irlan_do_provider_event(self
, IRLAN_GET_INFO_CMD
, skb
);
87 case CMD_GET_MEDIA_CHAR
:
88 pr_debug("Got GET_MEDIA_CHAR command!\n");
89 irlan_do_provider_event(self
, IRLAN_GET_MEDIA_CMD
, skb
);
91 case CMD_OPEN_DATA_CHANNEL
:
92 pr_debug("Got OPEN_DATA_CHANNEL command!\n");
93 irlan_do_provider_event(self
, IRLAN_OPEN_DATA_CMD
, skb
);
95 case CMD_FILTER_OPERATION
:
96 pr_debug("Got FILTER_OPERATION command!\n");
97 irlan_do_provider_event(self
, IRLAN_FILTER_CONFIG_CMD
, skb
);
99 case CMD_RECONNECT_DATA_CHAN
:
100 pr_debug("%s(), Got RECONNECT_DATA_CHAN command\n", __func__
);
101 pr_debug("%s(), NOT IMPLEMENTED\n", __func__
);
103 case CMD_CLOSE_DATA_CHAN
:
104 pr_debug("Got CLOSE_DATA_CHAN command!\n");
105 pr_debug("%s(), NOT IMPLEMENTED\n", __func__
);
108 pr_debug("%s(), Unknown command!\n", __func__
);
115 * Function irlan_provider_connect_indication (handle, skb, priv)
117 * Got connection from peer IrLAN client
120 static void irlan_provider_connect_indication(void *instance
, void *sap
,
121 struct qos_info
*qos
,
123 __u8 max_header_size
,
126 struct irlan_cb
*self
;
127 struct tsap_cb
*tsap
;
132 IRDA_ASSERT(self
!= NULL
, return;);
133 IRDA_ASSERT(self
->magic
== IRLAN_MAGIC
, return;);
135 IRDA_ASSERT(tsap
== self
->provider
.tsap_ctrl
,return;);
136 IRDA_ASSERT(self
->provider
.state
== IRLAN_IDLE
, return;);
138 self
->provider
.max_sdu_size
= max_sdu_size
;
139 self
->provider
.max_header_size
= max_header_size
;
141 irlan_do_provider_event(self
, IRLAN_CONNECT_INDICATION
, NULL
);
144 * If we are in peer mode, the client may not have got the discovery
145 * indication it needs to make progress. If the client is still in
146 * IDLE state, we must kick it.
148 if ((self
->provider
.access_type
== ACCESS_PEER
) &&
149 (self
->client
.state
== IRLAN_IDLE
))
151 irlan_client_wakeup(self
, self
->saddr
, self
->daddr
);
156 * Function irlan_provider_connect_response (handle)
158 * Accept incoming connection
161 void irlan_provider_connect_response(struct irlan_cb
*self
,
162 struct tsap_cb
*tsap
)
164 IRDA_ASSERT(self
!= NULL
, return;);
165 IRDA_ASSERT(self
->magic
== IRLAN_MAGIC
, return;);
168 irttp_connect_response(tsap
, IRLAN_MTU
, NULL
);
171 static void irlan_provider_disconnect_indication(void *instance
, void *sap
,
173 struct sk_buff
*userdata
)
175 struct irlan_cb
*self
;
176 struct tsap_cb
*tsap
;
178 pr_debug("%s(), reason=%d\n", __func__
, reason
);
183 IRDA_ASSERT(self
!= NULL
, return;);
184 IRDA_ASSERT(self
->magic
== IRLAN_MAGIC
, return;);
185 IRDA_ASSERT(tsap
!= NULL
, return;);
186 IRDA_ASSERT(tsap
->magic
== TTP_TSAP_MAGIC
, return;);
188 IRDA_ASSERT(tsap
== self
->provider
.tsap_ctrl
, return;);
190 irlan_do_provider_event(self
, IRLAN_LMP_DISCONNECT
, NULL
);
194 * Function irlan_parse_open_data_cmd (self, skb)
199 int irlan_parse_open_data_cmd(struct irlan_cb
*self
, struct sk_buff
*skb
)
203 ret
= irlan_provider_parse_command(self
, CMD_OPEN_DATA_CHANNEL
, skb
);
205 /* Open data channel */
206 irlan_open_data_tsap(self
);
212 * Function parse_command (skb)
214 * Extract all parameters from received buffer, then feed them to
215 * check_params for parsing
218 int irlan_provider_parse_command(struct irlan_cb
*self
, int cmd
,
228 int ret
= RSP_SUCCESS
;
230 IRDA_ASSERT(skb
!= NULL
, return -RSP_PROTOCOL_ERROR
;);
232 pr_debug("%s(), skb->len=%d\n", __func__
, (int)skb
->len
);
234 IRDA_ASSERT(self
!= NULL
, return -RSP_PROTOCOL_ERROR
;);
235 IRDA_ASSERT(self
->magic
== IRLAN_MAGIC
, return -RSP_PROTOCOL_ERROR
;);
238 return -RSP_PROTOCOL_ERROR
;
242 name
= kmalloc(255, GFP_ATOMIC
);
244 return -RSP_INSUFFICIENT_RESOURCES
;
245 value
= kmalloc(1016, GFP_ATOMIC
);
248 return -RSP_INSUFFICIENT_RESOURCES
;
251 /* How many parameters? */
254 pr_debug("Got %d parameters\n", count
);
258 /* For all parameters */
259 for (i
=0; i
<count
;i
++) {
260 ret
= irlan_extract_param(ptr
, name
, value
, &val_len
);
262 pr_debug("%s(), IrLAN, Error!\n", __func__
);
267 irlan_check_command_param(self
, name
, value
);
277 * Function irlan_provider_send_reply (self, info)
279 * Send reply to query to peer IrLAN layer
282 void irlan_provider_send_reply(struct irlan_cb
*self
, int command
,
287 IRDA_ASSERT(self
!= NULL
, return;);
288 IRDA_ASSERT(self
->magic
== IRLAN_MAGIC
, return;);
290 skb
= alloc_skb(IRLAN_MAX_HEADER
+ IRLAN_CMD_HEADER
+
291 /* Bigger param length comes from CMD_GET_MEDIA_CHAR */
292 IRLAN_STRING_PARAMETER_LEN("FILTER_TYPE", "DIRECTED") +
293 IRLAN_STRING_PARAMETER_LEN("FILTER_TYPE", "BROADCAST") +
294 IRLAN_STRING_PARAMETER_LEN("FILTER_TYPE", "MULTICAST") +
295 IRLAN_STRING_PARAMETER_LEN("ACCESS_TYPE", "HOSTED"),
301 /* Reserve space for TTP, LMP, and LAP header */
302 skb_reserve(skb
, self
->provider
.max_header_size
);
306 case CMD_GET_PROVIDER_INFO
:
307 skb
->data
[0] = 0x00; /* Success */
308 skb
->data
[1] = 0x02; /* 2 parameters */
309 switch (self
->media
) {
311 irlan_insert_string_param(skb
, "MEDIA", "802.3");
314 irlan_insert_string_param(skb
, "MEDIA", "802.5");
317 pr_debug("%s(), unknown media type!\n", __func__
);
320 irlan_insert_short_param(skb
, "IRLAN_VER", 0x0101);
323 case CMD_GET_MEDIA_CHAR
:
324 skb
->data
[0] = 0x00; /* Success */
325 skb
->data
[1] = 0x05; /* 5 parameters */
326 irlan_insert_string_param(skb
, "FILTER_TYPE", "DIRECTED");
327 irlan_insert_string_param(skb
, "FILTER_TYPE", "BROADCAST");
328 irlan_insert_string_param(skb
, "FILTER_TYPE", "MULTICAST");
330 switch (self
->provider
.access_type
) {
332 irlan_insert_string_param(skb
, "ACCESS_TYPE", "DIRECT");
335 irlan_insert_string_param(skb
, "ACCESS_TYPE", "PEER");
338 irlan_insert_string_param(skb
, "ACCESS_TYPE", "HOSTED");
341 pr_debug("%s(), Unknown access type\n", __func__
);
344 irlan_insert_short_param(skb
, "MAX_FRAME", 0x05ee);
346 case CMD_OPEN_DATA_CHANNEL
:
347 skb
->data
[0] = 0x00; /* Success */
348 if (self
->provider
.send_arb_val
) {
349 skb
->data
[1] = 0x03; /* 3 parameters */
350 irlan_insert_short_param(skb
, "CON_ARB",
351 self
->provider
.send_arb_val
);
353 skb
->data
[1] = 0x02; /* 2 parameters */
354 irlan_insert_byte_param(skb
, "DATA_CHAN", self
->stsap_sel_data
);
355 irlan_insert_string_param(skb
, "RECONNECT_KEY", "LINUX RULES!");
357 case CMD_FILTER_OPERATION
:
358 irlan_filter_request(self
, skb
);
361 pr_debug("%s(), Unknown command!\n", __func__
);
365 irttp_data_request(self
->provider
.tsap_ctrl
, skb
);
369 * Function irlan_provider_register(void)
371 * Register provider support so we can accept incoming connections.
374 int irlan_provider_open_ctrl_tsap(struct irlan_cb
*self
)
376 struct tsap_cb
*tsap
;
379 IRDA_ASSERT(self
!= NULL
, return -1;);
380 IRDA_ASSERT(self
->magic
== IRLAN_MAGIC
, return -1;);
382 /* Check if already open */
383 if (self
->provider
.tsap_ctrl
)
387 * First register well known control TSAP
389 irda_notify_init(¬ify
);
390 notify
.data_indication
= irlan_provider_data_indication
;
391 notify
.connect_indication
= irlan_provider_connect_indication
;
392 notify
.disconnect_indication
= irlan_provider_disconnect_indication
;
393 notify
.instance
= self
;
394 strlcpy(notify
.name
, "IrLAN ctrl (p)", sizeof(notify
.name
));
396 tsap
= irttp_open_tsap(LSAP_ANY
, 1, ¬ify
);
398 pr_debug("%s(), Got no tsap!\n", __func__
);
401 self
->provider
.tsap_ctrl
= tsap
;
403 /* Register with LM-IAS */
404 irlan_ias_register(self
, tsap
->stsap_sel
);