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>
38 #include <asm/system.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
;
73 IRDA_DEBUG(4, "%s()\n", __FUNCTION__
);
75 self
= (struct irlan_cb
*) instance
;
77 IRDA_ASSERT(self
!= NULL
, return -1;);
78 IRDA_ASSERT(self
->magic
== IRLAN_MAGIC
, return -1;);
80 IRDA_ASSERT(skb
!= NULL
, return -1;);
84 case CMD_GET_PROVIDER_INFO
:
85 IRDA_DEBUG(4, "Got GET_PROVIDER_INFO command!\n");
86 irlan_do_provider_event(self
, IRLAN_GET_INFO_CMD
, skb
);
89 case CMD_GET_MEDIA_CHAR
:
90 IRDA_DEBUG(4, "Got GET_MEDIA_CHAR command!\n");
91 irlan_do_provider_event(self
, IRLAN_GET_MEDIA_CMD
, skb
);
93 case CMD_OPEN_DATA_CHANNEL
:
94 IRDA_DEBUG(4, "Got OPEN_DATA_CHANNEL command!\n");
95 irlan_do_provider_event(self
, IRLAN_OPEN_DATA_CMD
, skb
);
97 case CMD_FILTER_OPERATION
:
98 IRDA_DEBUG(4, "Got FILTER_OPERATION command!\n");
99 irlan_do_provider_event(self
, IRLAN_FILTER_CONFIG_CMD
, skb
);
101 case CMD_RECONNECT_DATA_CHAN
:
102 IRDA_DEBUG(2, "%s(), Got RECONNECT_DATA_CHAN command\n", __FUNCTION__
);
103 IRDA_DEBUG(2, "%s(), NOT IMPLEMENTED\n", __FUNCTION__
);
105 case CMD_CLOSE_DATA_CHAN
:
106 IRDA_DEBUG(2, "Got CLOSE_DATA_CHAN command!\n");
107 IRDA_DEBUG(2, "%s(), NOT IMPLEMENTED\n", __FUNCTION__
);
110 IRDA_DEBUG(2, "%s(), Unknown command!\n", __FUNCTION__
);
117 * Function irlan_provider_connect_indication (handle, skb, priv)
119 * Got connection from peer IrLAN client
122 static void irlan_provider_connect_indication(void *instance
, void *sap
,
123 struct qos_info
*qos
,
125 __u8 max_header_size
,
128 struct irlan_cb
*self
;
129 struct tsap_cb
*tsap
;
132 IRDA_DEBUG(0, "%s()\n", __FUNCTION__
);
134 self
= (struct irlan_cb
*) instance
;
135 tsap
= (struct tsap_cb
*) sap
;
137 IRDA_ASSERT(self
!= NULL
, return;);
138 IRDA_ASSERT(self
->magic
== IRLAN_MAGIC
, return;);
140 IRDA_ASSERT(tsap
== self
->provider
.tsap_ctrl
,return;);
141 IRDA_ASSERT(self
->provider
.state
== IRLAN_IDLE
, return;);
143 daddr
= irttp_get_daddr(tsap
);
144 saddr
= irttp_get_saddr(tsap
);
145 self
->provider
.max_sdu_size
= max_sdu_size
;
146 self
->provider
.max_header_size
= max_header_size
;
148 irlan_do_provider_event(self
, IRLAN_CONNECT_INDICATION
, NULL
);
151 * If we are in peer mode, the client may not have got the discovery
152 * indication it needs to make progress. If the client is still in
153 * IDLE state, we must kick it.
155 if ((self
->provider
.access_type
== ACCESS_PEER
) &&
156 (self
->client
.state
== IRLAN_IDLE
))
158 irlan_client_wakeup(self
, self
->saddr
, self
->daddr
);
163 * Function irlan_provider_connect_response (handle)
165 * Accept incoming connection
168 void irlan_provider_connect_response(struct irlan_cb
*self
,
169 struct tsap_cb
*tsap
)
171 IRDA_ASSERT(self
!= NULL
, return;);
172 IRDA_ASSERT(self
->magic
== IRLAN_MAGIC
, return;);
175 irttp_connect_response(tsap
, IRLAN_MTU
, NULL
);
178 static void irlan_provider_disconnect_indication(void *instance
, void *sap
,
180 struct sk_buff
*userdata
)
182 struct irlan_cb
*self
;
183 struct tsap_cb
*tsap
;
185 IRDA_DEBUG(4, "%s(), reason=%d\n", __FUNCTION__
, reason
);
187 self
= (struct irlan_cb
*) instance
;
188 tsap
= (struct tsap_cb
*) sap
;
190 IRDA_ASSERT(self
!= NULL
, return;);
191 IRDA_ASSERT(self
->magic
== IRLAN_MAGIC
, return;);
192 IRDA_ASSERT(tsap
!= NULL
, return;);
193 IRDA_ASSERT(tsap
->magic
== TTP_TSAP_MAGIC
, return;);
195 IRDA_ASSERT(tsap
== self
->provider
.tsap_ctrl
, return;);
197 irlan_do_provider_event(self
, IRLAN_LMP_DISCONNECT
, NULL
);
201 * Function irlan_parse_open_data_cmd (self, skb)
206 int irlan_parse_open_data_cmd(struct irlan_cb
*self
, struct sk_buff
*skb
)
210 ret
= irlan_provider_parse_command(self
, CMD_OPEN_DATA_CHANNEL
, skb
);
212 /* Open data channel */
213 irlan_open_data_tsap(self
);
219 * Function parse_command (skb)
221 * Extract all parameters from received buffer, then feed them to
222 * check_params for parsing
225 int irlan_provider_parse_command(struct irlan_cb
*self
, int cmd
,
235 int ret
= RSP_SUCCESS
;
237 IRDA_ASSERT(skb
!= NULL
, return -RSP_PROTOCOL_ERROR
;);
239 IRDA_DEBUG(4, "%s(), skb->len=%d\n", __FUNCTION__
, (int)skb
->len
);
241 IRDA_ASSERT(self
!= NULL
, return -RSP_PROTOCOL_ERROR
;);
242 IRDA_ASSERT(self
->magic
== IRLAN_MAGIC
, return -RSP_PROTOCOL_ERROR
;);
245 return -RSP_PROTOCOL_ERROR
;
249 name
= kmalloc(255, GFP_ATOMIC
);
251 return -RSP_INSUFFICIENT_RESOURCES
;
252 value
= kmalloc(1016, GFP_ATOMIC
);
255 return -RSP_INSUFFICIENT_RESOURCES
;
258 /* How many parameters? */
261 IRDA_DEBUG(4, "Got %d parameters\n", count
);
265 /* For all parameters */
266 for (i
=0; i
<count
;i
++) {
267 ret
= irlan_extract_param(ptr
, name
, value
, &val_len
);
269 IRDA_DEBUG(2, "%s(), IrLAN, Error!\n", __FUNCTION__
);
274 irlan_check_command_param(self
, name
, value
);
284 * Function irlan_provider_send_reply (self, info)
286 * Send reply to query to peer IrLAN layer
289 void irlan_provider_send_reply(struct irlan_cb
*self
, int command
,
294 IRDA_DEBUG(4, "%s()\n", __FUNCTION__
);
296 IRDA_ASSERT(self
!= NULL
, return;);
297 IRDA_ASSERT(self
->magic
== IRLAN_MAGIC
, return;);
299 skb
= alloc_skb(IRLAN_MAX_HEADER
+ IRLAN_CMD_HEADER
+
300 /* Bigger param length comes from CMD_GET_MEDIA_CHAR */
301 IRLAN_STRING_PARAMETER_LEN("FILTER_TYPE", "DIRECTED") +
302 IRLAN_STRING_PARAMETER_LEN("FILTER_TYPE", "BORADCAST") +
303 IRLAN_STRING_PARAMETER_LEN("FILTER_TYPE", "MULTICAST") +
304 IRLAN_STRING_PARAMETER_LEN("ACCESS_TYPE", "HOSTED"),
310 /* Reserve space for TTP, LMP, and LAP header */
311 skb_reserve(skb
, self
->provider
.max_header_size
);
315 case CMD_GET_PROVIDER_INFO
:
316 skb
->data
[0] = 0x00; /* Success */
317 skb
->data
[1] = 0x02; /* 2 parameters */
318 switch (self
->media
) {
320 irlan_insert_string_param(skb
, "MEDIA", "802.3");
323 irlan_insert_string_param(skb
, "MEDIA", "802.5");
326 IRDA_DEBUG(2, "%s(), unknown media type!\n", __FUNCTION__
);
329 irlan_insert_short_param(skb
, "IRLAN_VER", 0x0101);
332 case CMD_GET_MEDIA_CHAR
:
333 skb
->data
[0] = 0x00; /* Success */
334 skb
->data
[1] = 0x05; /* 5 parameters */
335 irlan_insert_string_param(skb
, "FILTER_TYPE", "DIRECTED");
336 irlan_insert_string_param(skb
, "FILTER_TYPE", "BROADCAST");
337 irlan_insert_string_param(skb
, "FILTER_TYPE", "MULTICAST");
339 switch (self
->provider
.access_type
) {
341 irlan_insert_string_param(skb
, "ACCESS_TYPE", "DIRECT");
344 irlan_insert_string_param(skb
, "ACCESS_TYPE", "PEER");
347 irlan_insert_string_param(skb
, "ACCESS_TYPE", "HOSTED");
350 IRDA_DEBUG(2, "%s(), Unknown access type\n", __FUNCTION__
);
353 irlan_insert_short_param(skb
, "MAX_FRAME", 0x05ee);
355 case CMD_OPEN_DATA_CHANNEL
:
356 skb
->data
[0] = 0x00; /* Success */
357 if (self
->provider
.send_arb_val
) {
358 skb
->data
[1] = 0x03; /* 3 parameters */
359 irlan_insert_short_param(skb
, "CON_ARB",
360 self
->provider
.send_arb_val
);
362 skb
->data
[1] = 0x02; /* 2 parameters */
363 irlan_insert_byte_param(skb
, "DATA_CHAN", self
->stsap_sel_data
);
364 irlan_insert_string_param(skb
, "RECONNECT_KEY", "LINUX RULES!");
366 case CMD_FILTER_OPERATION
:
367 irlan_filter_request(self
, skb
);
370 IRDA_DEBUG(2, "%s(), Unknown command!\n", __FUNCTION__
);
374 irttp_data_request(self
->provider
.tsap_ctrl
, skb
);
378 * Function irlan_provider_register(void)
380 * Register provider support so we can accept incoming connections.
383 int irlan_provider_open_ctrl_tsap(struct irlan_cb
*self
)
385 struct tsap_cb
*tsap
;
388 IRDA_DEBUG(4, "%s()\n", __FUNCTION__
);
390 IRDA_ASSERT(self
!= NULL
, return -1;);
391 IRDA_ASSERT(self
->magic
== IRLAN_MAGIC
, return -1;);
393 /* Check if already open */
394 if (self
->provider
.tsap_ctrl
)
398 * First register well known control TSAP
400 irda_notify_init(¬ify
);
401 notify
.data_indication
= irlan_provider_data_indication
;
402 notify
.connect_indication
= irlan_provider_connect_indication
;
403 notify
.disconnect_indication
= irlan_provider_disconnect_indication
;
404 notify
.instance
= self
;
405 strlcpy(notify
.name
, "IrLAN ctrl (p)", sizeof(notify
.name
));
407 tsap
= irttp_open_tsap(LSAP_ANY
, 1, ¬ify
);
409 IRDA_DEBUG(2, "%s(), Got no tsap!\n", __FUNCTION__
);
412 self
->provider
.tsap_ctrl
= tsap
;
414 /* Register with LM-IAS */
415 irlan_ias_register(self
, tsap
->stsap_sel
);