Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /********************************************************************* |
YOSHIFUJI Hideaki | 6819bc2 | 2007-02-09 23:24:53 +0900 | [diff] [blame] | 2 | * |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3 | * Filename: irlan_provider.c |
| 4 | * Version: 0.9 |
| 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> |
YOSHIFUJI Hideaki | 6819bc2 | 2007-02-09 23:24:53 +0900 | [diff] [blame] | 14 | * |
| 15 | * Copyright (c) 1998-1999 Dag Brattli <dagb@cs.uit.no>, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 16 | * All Rights Reserved. |
YOSHIFUJI Hideaki | 6819bc2 | 2007-02-09 23:24:53 +0900 | [diff] [blame] | 17 | * |
| 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 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 21 | * the License, or (at your option) any later version. |
| 22 | * |
Jan Engelhardt | 96de0e2 | 2007-10-19 23:21:04 +0200 | [diff] [blame] | 23 | * Neither Dag Brattli nor University of Tromsø admit liability nor |
YOSHIFUJI Hideaki | 6819bc2 | 2007-02-09 23:24:53 +0900 | [diff] [blame] | 24 | * provide warranty for any of this software. This material is |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 25 | * provided "AS-IS" and at no charge. |
| 26 | * |
| 27 | ********************************************************************/ |
| 28 | |
| 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 | |
| 38 | #include <asm/system.h> |
| 39 | #include <asm/byteorder.h> |
| 40 | |
| 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> |
| 47 | |
| 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> |
| 54 | |
YOSHIFUJI Hideaki | 6819bc2 | 2007-02-09 23:24:53 +0900 | [diff] [blame] | 55 | static void irlan_provider_connect_indication(void *instance, void *sap, |
| 56 | struct qos_info *qos, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 57 | __u32 max_sdu_size, |
| 58 | __u8 max_header_size, |
| 59 | struct sk_buff *skb); |
| 60 | |
| 61 | /* |
| 62 | * Function irlan_provider_control_data_indication (handle, skb) |
| 63 | * |
| 64 | * This function gets the data that is received on the control channel |
| 65 | * |
| 66 | */ |
YOSHIFUJI Hideaki | 6819bc2 | 2007-02-09 23:24:53 +0900 | [diff] [blame] | 67 | static int irlan_provider_data_indication(void *instance, void *sap, |
| 68 | struct sk_buff *skb) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 69 | { |
| 70 | struct irlan_cb *self; |
| 71 | __u8 code; |
YOSHIFUJI Hideaki | 6819bc2 | 2007-02-09 23:24:53 +0900 | [diff] [blame] | 72 | |
Harvey Harrison | 0dc4787 | 2008-03-05 20:47:47 -0800 | [diff] [blame] | 73 | IRDA_DEBUG(4, "%s()\n", __func__ ); |
YOSHIFUJI Hideaki | 6819bc2 | 2007-02-09 23:24:53 +0900 | [diff] [blame] | 74 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 75 | self = (struct irlan_cb *) instance; |
| 76 | |
| 77 | IRDA_ASSERT(self != NULL, return -1;); |
| 78 | IRDA_ASSERT(self->magic == IRLAN_MAGIC, return -1;); |
| 79 | |
| 80 | IRDA_ASSERT(skb != NULL, return -1;); |
| 81 | |
| 82 | code = skb->data[0]; |
| 83 | switch(code) { |
| 84 | case CMD_GET_PROVIDER_INFO: |
| 85 | IRDA_DEBUG(4, "Got GET_PROVIDER_INFO command!\n"); |
YOSHIFUJI Hideaki | 6819bc2 | 2007-02-09 23:24:53 +0900 | [diff] [blame] | 86 | irlan_do_provider_event(self, IRLAN_GET_INFO_CMD, skb); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 87 | break; |
| 88 | |
| 89 | case CMD_GET_MEDIA_CHAR: |
| 90 | IRDA_DEBUG(4, "Got GET_MEDIA_CHAR command!\n"); |
YOSHIFUJI Hideaki | 6819bc2 | 2007-02-09 23:24:53 +0900 | [diff] [blame] | 91 | irlan_do_provider_event(self, IRLAN_GET_MEDIA_CMD, skb); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 92 | break; |
| 93 | case CMD_OPEN_DATA_CHANNEL: |
| 94 | IRDA_DEBUG(4, "Got OPEN_DATA_CHANNEL command!\n"); |
YOSHIFUJI Hideaki | 6819bc2 | 2007-02-09 23:24:53 +0900 | [diff] [blame] | 95 | irlan_do_provider_event(self, IRLAN_OPEN_DATA_CMD, skb); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 96 | break; |
| 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); |
| 100 | break; |
| 101 | case CMD_RECONNECT_DATA_CHAN: |
Harvey Harrison | 0dc4787 | 2008-03-05 20:47:47 -0800 | [diff] [blame] | 102 | IRDA_DEBUG(2, "%s(), Got RECONNECT_DATA_CHAN command\n", __func__ ); |
| 103 | IRDA_DEBUG(2, "%s(), NOT IMPLEMENTED\n", __func__ ); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 104 | break; |
| 105 | case CMD_CLOSE_DATA_CHAN: |
| 106 | IRDA_DEBUG(2, "Got CLOSE_DATA_CHAN command!\n"); |
Harvey Harrison | 0dc4787 | 2008-03-05 20:47:47 -0800 | [diff] [blame] | 107 | IRDA_DEBUG(2, "%s(), NOT IMPLEMENTED\n", __func__ ); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 108 | break; |
| 109 | default: |
Harvey Harrison | 0dc4787 | 2008-03-05 20:47:47 -0800 | [diff] [blame] | 110 | IRDA_DEBUG(2, "%s(), Unknown command!\n", __func__ ); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 111 | break; |
| 112 | } |
| 113 | return 0; |
| 114 | } |
| 115 | |
| 116 | /* |
| 117 | * Function irlan_provider_connect_indication (handle, skb, priv) |
| 118 | * |
| 119 | * Got connection from peer IrLAN client |
| 120 | * |
| 121 | */ |
YOSHIFUJI Hideaki | 6819bc2 | 2007-02-09 23:24:53 +0900 | [diff] [blame] | 122 | static void irlan_provider_connect_indication(void *instance, void *sap, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 123 | struct qos_info *qos, |
YOSHIFUJI Hideaki | 6819bc2 | 2007-02-09 23:24:53 +0900 | [diff] [blame] | 124 | __u32 max_sdu_size, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 125 | __u8 max_header_size, |
| 126 | struct sk_buff *skb) |
| 127 | { |
| 128 | struct irlan_cb *self; |
| 129 | struct tsap_cb *tsap; |
| 130 | __u32 saddr, daddr; |
| 131 | |
Harvey Harrison | 0dc4787 | 2008-03-05 20:47:47 -0800 | [diff] [blame] | 132 | IRDA_DEBUG(0, "%s()\n", __func__ ); |
YOSHIFUJI Hideaki | 6819bc2 | 2007-02-09 23:24:53 +0900 | [diff] [blame] | 133 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 134 | self = (struct irlan_cb *) instance; |
| 135 | tsap = (struct tsap_cb *) sap; |
YOSHIFUJI Hideaki | 6819bc2 | 2007-02-09 23:24:53 +0900 | [diff] [blame] | 136 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 137 | IRDA_ASSERT(self != NULL, return;); |
| 138 | IRDA_ASSERT(self->magic == IRLAN_MAGIC, return;); |
YOSHIFUJI Hideaki | 6819bc2 | 2007-02-09 23:24:53 +0900 | [diff] [blame] | 139 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 140 | IRDA_ASSERT(tsap == self->provider.tsap_ctrl,return;); |
| 141 | IRDA_ASSERT(self->provider.state == IRLAN_IDLE, return;); |
| 142 | |
| 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; |
| 147 | |
| 148 | irlan_do_provider_event(self, IRLAN_CONNECT_INDICATION, NULL); |
| 149 | |
YOSHIFUJI Hideaki | 6819bc2 | 2007-02-09 23:24:53 +0900 | [diff] [blame] | 150 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 151 | * If we are in peer mode, the client may not have got the discovery |
YOSHIFUJI Hideaki | 6819bc2 | 2007-02-09 23:24:53 +0900 | [diff] [blame] | 152 | * indication it needs to make progress. If the client is still in |
| 153 | * IDLE state, we must kick it. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 154 | */ |
YOSHIFUJI Hideaki | 6819bc2 | 2007-02-09 23:24:53 +0900 | [diff] [blame] | 155 | if ((self->provider.access_type == ACCESS_PEER) && |
| 156 | (self->client.state == IRLAN_IDLE)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 157 | { |
| 158 | irlan_client_wakeup(self, self->saddr, self->daddr); |
| 159 | } |
| 160 | } |
| 161 | |
| 162 | /* |
| 163 | * Function irlan_provider_connect_response (handle) |
| 164 | * |
| 165 | * Accept incoming connection |
| 166 | * |
| 167 | */ |
| 168 | void irlan_provider_connect_response(struct irlan_cb *self, |
| 169 | struct tsap_cb *tsap) |
| 170 | { |
| 171 | IRDA_ASSERT(self != NULL, return;); |
| 172 | IRDA_ASSERT(self->magic == IRLAN_MAGIC, return;); |
| 173 | |
| 174 | /* Just accept */ |
| 175 | irttp_connect_response(tsap, IRLAN_MTU, NULL); |
| 176 | } |
| 177 | |
YOSHIFUJI Hideaki | 6819bc2 | 2007-02-09 23:24:53 +0900 | [diff] [blame] | 178 | static void irlan_provider_disconnect_indication(void *instance, void *sap, |
| 179 | LM_REASON reason, |
| 180 | struct sk_buff *userdata) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 181 | { |
| 182 | struct irlan_cb *self; |
| 183 | struct tsap_cb *tsap; |
| 184 | |
Harvey Harrison | 0dc4787 | 2008-03-05 20:47:47 -0800 | [diff] [blame] | 185 | IRDA_DEBUG(4, "%s(), reason=%d\n", __func__ , reason); |
YOSHIFUJI Hideaki | 6819bc2 | 2007-02-09 23:24:53 +0900 | [diff] [blame] | 186 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 187 | self = (struct irlan_cb *) instance; |
| 188 | tsap = (struct tsap_cb *) sap; |
| 189 | |
| 190 | IRDA_ASSERT(self != NULL, return;); |
YOSHIFUJI Hideaki | 6819bc2 | 2007-02-09 23:24:53 +0900 | [diff] [blame] | 191 | IRDA_ASSERT(self->magic == IRLAN_MAGIC, return;); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 192 | IRDA_ASSERT(tsap != NULL, return;); |
| 193 | IRDA_ASSERT(tsap->magic == TTP_TSAP_MAGIC, return;); |
YOSHIFUJI Hideaki | 6819bc2 | 2007-02-09 23:24:53 +0900 | [diff] [blame] | 194 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 195 | IRDA_ASSERT(tsap == self->provider.tsap_ctrl, return;); |
YOSHIFUJI Hideaki | 6819bc2 | 2007-02-09 23:24:53 +0900 | [diff] [blame] | 196 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 197 | irlan_do_provider_event(self, IRLAN_LMP_DISCONNECT, NULL); |
| 198 | } |
| 199 | |
| 200 | /* |
| 201 | * Function irlan_parse_open_data_cmd (self, skb) |
| 202 | * |
YOSHIFUJI Hideaki | 6819bc2 | 2007-02-09 23:24:53 +0900 | [diff] [blame] | 203 | * |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 204 | * |
| 205 | */ |
| 206 | int irlan_parse_open_data_cmd(struct irlan_cb *self, struct sk_buff *skb) |
| 207 | { |
| 208 | int ret; |
YOSHIFUJI Hideaki | 6819bc2 | 2007-02-09 23:24:53 +0900 | [diff] [blame] | 209 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 210 | ret = irlan_provider_parse_command(self, CMD_OPEN_DATA_CHANNEL, skb); |
| 211 | |
| 212 | /* Open data channel */ |
| 213 | irlan_open_data_tsap(self); |
| 214 | |
| 215 | return ret; |
| 216 | } |
| 217 | |
| 218 | /* |
| 219 | * Function parse_command (skb) |
| 220 | * |
YOSHIFUJI Hideaki | 6819bc2 | 2007-02-09 23:24:53 +0900 | [diff] [blame] | 221 | * Extract all parameters from received buffer, then feed them to |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 222 | * check_params for parsing |
| 223 | * |
| 224 | */ |
| 225 | int irlan_provider_parse_command(struct irlan_cb *self, int cmd, |
YOSHIFUJI Hideaki | 6819bc2 | 2007-02-09 23:24:53 +0900 | [diff] [blame] | 226 | struct sk_buff *skb) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 227 | { |
| 228 | __u8 *frame; |
| 229 | __u8 *ptr; |
| 230 | int count; |
| 231 | __u16 val_len; |
| 232 | int i; |
| 233 | char *name; |
YOSHIFUJI Hideaki | 6819bc2 | 2007-02-09 23:24:53 +0900 | [diff] [blame] | 234 | char *value; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 235 | int ret = RSP_SUCCESS; |
YOSHIFUJI Hideaki | 6819bc2 | 2007-02-09 23:24:53 +0900 | [diff] [blame] | 236 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 237 | IRDA_ASSERT(skb != NULL, return -RSP_PROTOCOL_ERROR;); |
YOSHIFUJI Hideaki | 6819bc2 | 2007-02-09 23:24:53 +0900 | [diff] [blame] | 238 | |
Harvey Harrison | 0dc4787 | 2008-03-05 20:47:47 -0800 | [diff] [blame] | 239 | IRDA_DEBUG(4, "%s(), skb->len=%d\n", __func__ , (int)skb->len); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 240 | |
| 241 | IRDA_ASSERT(self != NULL, return -RSP_PROTOCOL_ERROR;); |
| 242 | IRDA_ASSERT(self->magic == IRLAN_MAGIC, return -RSP_PROTOCOL_ERROR;); |
YOSHIFUJI Hideaki | 6819bc2 | 2007-02-09 23:24:53 +0900 | [diff] [blame] | 243 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 244 | if (!skb) |
| 245 | return -RSP_PROTOCOL_ERROR; |
| 246 | |
| 247 | frame = skb->data; |
| 248 | |
| 249 | name = kmalloc(255, GFP_ATOMIC); |
| 250 | if (!name) |
| 251 | return -RSP_INSUFFICIENT_RESOURCES; |
| 252 | value = kmalloc(1016, GFP_ATOMIC); |
| 253 | if (!value) { |
| 254 | kfree(name); |
| 255 | return -RSP_INSUFFICIENT_RESOURCES; |
| 256 | } |
| 257 | |
| 258 | /* How many parameters? */ |
| 259 | count = frame[1]; |
| 260 | |
| 261 | IRDA_DEBUG(4, "Got %d parameters\n", count); |
YOSHIFUJI Hideaki | 6819bc2 | 2007-02-09 23:24:53 +0900 | [diff] [blame] | 262 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 263 | ptr = frame+2; |
YOSHIFUJI Hideaki | 6819bc2 | 2007-02-09 23:24:53 +0900 | [diff] [blame] | 264 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 265 | /* For all parameters */ |
YOSHIFUJI Hideaki | 6819bc2 | 2007-02-09 23:24:53 +0900 | [diff] [blame] | 266 | for (i=0; i<count;i++) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 267 | ret = irlan_extract_param(ptr, name, value, &val_len); |
| 268 | if (ret < 0) { |
Harvey Harrison | 0dc4787 | 2008-03-05 20:47:47 -0800 | [diff] [blame] | 269 | IRDA_DEBUG(2, "%s(), IrLAN, Error!\n", __func__ ); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 270 | break; |
| 271 | } |
| 272 | ptr+=ret; |
| 273 | ret = RSP_SUCCESS; |
| 274 | irlan_check_command_param(self, name, value); |
| 275 | } |
| 276 | /* Cleanup */ |
| 277 | kfree(name); |
| 278 | kfree(value); |
| 279 | |
| 280 | return ret; |
| 281 | } |
| 282 | |
| 283 | /* |
| 284 | * Function irlan_provider_send_reply (self, info) |
| 285 | * |
| 286 | * Send reply to query to peer IrLAN layer |
| 287 | * |
| 288 | */ |
YOSHIFUJI Hideaki | 6819bc2 | 2007-02-09 23:24:53 +0900 | [diff] [blame] | 289 | void irlan_provider_send_reply(struct irlan_cb *self, int command, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 290 | int ret_code) |
| 291 | { |
| 292 | struct sk_buff *skb; |
| 293 | |
Harvey Harrison | 0dc4787 | 2008-03-05 20:47:47 -0800 | [diff] [blame] | 294 | IRDA_DEBUG(4, "%s()\n", __func__ ); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 295 | |
| 296 | IRDA_ASSERT(self != NULL, return;); |
| 297 | IRDA_ASSERT(self->magic == IRLAN_MAGIC, return;); |
| 298 | |
Samuel Ortiz | 1b0fee7 | 2006-09-27 20:06:44 -0700 | [diff] [blame] | 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"), |
| 305 | GFP_ATOMIC); |
| 306 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 307 | if (!skb) |
| 308 | return; |
| 309 | |
| 310 | /* Reserve space for TTP, LMP, and LAP header */ |
| 311 | skb_reserve(skb, self->provider.max_header_size); |
| 312 | skb_put(skb, 2); |
YOSHIFUJI Hideaki | 6819bc2 | 2007-02-09 23:24:53 +0900 | [diff] [blame] | 313 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 314 | switch (command) { |
| 315 | case CMD_GET_PROVIDER_INFO: |
| 316 | skb->data[0] = 0x00; /* Success */ |
| 317 | skb->data[1] = 0x02; /* 2 parameters */ |
| 318 | switch (self->media) { |
| 319 | case MEDIA_802_3: |
| 320 | irlan_insert_string_param(skb, "MEDIA", "802.3"); |
| 321 | break; |
| 322 | case MEDIA_802_5: |
| 323 | irlan_insert_string_param(skb, "MEDIA", "802.5"); |
| 324 | break; |
| 325 | default: |
Harvey Harrison | 0dc4787 | 2008-03-05 20:47:47 -0800 | [diff] [blame] | 326 | IRDA_DEBUG(2, "%s(), unknown media type!\n", __func__ ); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 327 | break; |
| 328 | } |
| 329 | irlan_insert_short_param(skb, "IRLAN_VER", 0x0101); |
| 330 | break; |
| 331 | |
| 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"); |
| 338 | |
| 339 | switch (self->provider.access_type) { |
| 340 | case ACCESS_DIRECT: |
| 341 | irlan_insert_string_param(skb, "ACCESS_TYPE", "DIRECT"); |
| 342 | break; |
| 343 | case ACCESS_PEER: |
| 344 | irlan_insert_string_param(skb, "ACCESS_TYPE", "PEER"); |
| 345 | break; |
| 346 | case ACCESS_HOSTED: |
| 347 | irlan_insert_string_param(skb, "ACCESS_TYPE", "HOSTED"); |
| 348 | break; |
| 349 | default: |
Harvey Harrison | 0dc4787 | 2008-03-05 20:47:47 -0800 | [diff] [blame] | 350 | IRDA_DEBUG(2, "%s(), Unknown access type\n", __func__ ); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 351 | break; |
| 352 | } |
| 353 | irlan_insert_short_param(skb, "MAX_FRAME", 0x05ee); |
| 354 | break; |
| 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 */ |
YOSHIFUJI Hideaki | 6819bc2 | 2007-02-09 23:24:53 +0900 | [diff] [blame] | 359 | irlan_insert_short_param(skb, "CON_ARB", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 360 | self->provider.send_arb_val); |
| 361 | } else |
| 362 | skb->data[1] = 0x02; /* 2 parameters */ |
| 363 | irlan_insert_byte_param(skb, "DATA_CHAN", self->stsap_sel_data); |
Samuel Ortiz | 1b0fee7 | 2006-09-27 20:06:44 -0700 | [diff] [blame] | 364 | irlan_insert_string_param(skb, "RECONNECT_KEY", "LINUX RULES!"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 365 | break; |
| 366 | case CMD_FILTER_OPERATION: |
| 367 | irlan_filter_request(self, skb); |
| 368 | break; |
| 369 | default: |
Harvey Harrison | 0dc4787 | 2008-03-05 20:47:47 -0800 | [diff] [blame] | 370 | IRDA_DEBUG(2, "%s(), Unknown command!\n", __func__ ); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 371 | break; |
| 372 | } |
| 373 | |
| 374 | irttp_data_request(self->provider.tsap_ctrl, skb); |
| 375 | } |
| 376 | |
| 377 | /* |
| 378 | * Function irlan_provider_register(void) |
| 379 | * |
| 380 | * Register provider support so we can accept incoming connections. |
YOSHIFUJI Hideaki | 6819bc2 | 2007-02-09 23:24:53 +0900 | [diff] [blame] | 381 | * |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 382 | */ |
| 383 | int irlan_provider_open_ctrl_tsap(struct irlan_cb *self) |
| 384 | { |
| 385 | struct tsap_cb *tsap; |
| 386 | notify_t notify; |
YOSHIFUJI Hideaki | 6819bc2 | 2007-02-09 23:24:53 +0900 | [diff] [blame] | 387 | |
Harvey Harrison | 0dc4787 | 2008-03-05 20:47:47 -0800 | [diff] [blame] | 388 | IRDA_DEBUG(4, "%s()\n", __func__ ); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 389 | |
| 390 | IRDA_ASSERT(self != NULL, return -1;); |
| 391 | IRDA_ASSERT(self->magic == IRLAN_MAGIC, return -1;); |
| 392 | |
| 393 | /* Check if already open */ |
| 394 | if (self->provider.tsap_ctrl) |
| 395 | return -1; |
YOSHIFUJI Hideaki | 6819bc2 | 2007-02-09 23:24:53 +0900 | [diff] [blame] | 396 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 397 | /* |
| 398 | * First register well known control TSAP |
| 399 | */ |
| 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)); |
| 406 | |
| 407 | tsap = irttp_open_tsap(LSAP_ANY, 1, ¬ify); |
| 408 | if (!tsap) { |
Harvey Harrison | 0dc4787 | 2008-03-05 20:47:47 -0800 | [diff] [blame] | 409 | IRDA_DEBUG(2, "%s(), Got no tsap!\n", __func__ ); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 410 | return -1; |
| 411 | } |
| 412 | self->provider.tsap_ctrl = tsap; |
| 413 | |
| 414 | /* Register with LM-IAS */ |
| 415 | irlan_ias_register(self, tsap->stsap_sel); |
| 416 | |
| 417 | return 0; |
| 418 | } |
| 419 | |