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_client.c |
| 4 | * Version: 0.9 |
| 5 | * Description: IrDA LAN Access Protocol (IrLAN) Client |
| 6 | * Status: Experimental. |
| 7 | * Author: Dag Brattli <dagb@cs.uit.no> |
| 8 | * Created at: Sun Aug 31 20:14:37 1997 |
| 9 | * Modified at: Tue Dec 14 15:47:02 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> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 31 | #include <linux/slab.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 32 | #include <linux/errno.h> |
| 33 | #include <linux/init.h> |
| 34 | #include <linux/netdevice.h> |
| 35 | #include <linux/etherdevice.h> |
| 36 | #include <linux/if_arp.h> |
| 37 | #include <linux/bitops.h> |
| 38 | #include <net/arp.h> |
| 39 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 40 | #include <asm/byteorder.h> |
| 41 | |
| 42 | #include <net/irda/irda.h> |
| 43 | #include <net/irda/irttp.h> |
| 44 | #include <net/irda/irlmp.h> |
| 45 | #include <net/irda/irias_object.h> |
| 46 | #include <net/irda/iriap.h> |
| 47 | #include <net/irda/timer.h> |
| 48 | |
| 49 | #include <net/irda/irlan_common.h> |
| 50 | #include <net/irda/irlan_event.h> |
| 51 | #include <net/irda/irlan_eth.h> |
| 52 | #include <net/irda/irlan_provider.h> |
| 53 | #include <net/irda/irlan_client.h> |
| 54 | |
| 55 | #undef CONFIG_IRLAN_GRATUITOUS_ARP |
| 56 | |
YOSHIFUJI Hideaki | 6819bc2 | 2007-02-09 23:24:53 +0900 | [diff] [blame] | 57 | static void irlan_client_ctrl_disconnect_indication(void *instance, void *sap, |
| 58 | LM_REASON reason, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 59 | struct sk_buff *); |
YOSHIFUJI Hideaki | 6819bc2 | 2007-02-09 23:24:53 +0900 | [diff] [blame] | 60 | static int irlan_client_ctrl_data_indication(void *instance, void *sap, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 61 | struct sk_buff *skb); |
YOSHIFUJI Hideaki | 6819bc2 | 2007-02-09 23:24:53 +0900 | [diff] [blame] | 62 | static void irlan_client_ctrl_connect_confirm(void *instance, void *sap, |
| 63 | struct qos_info *qos, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 64 | __u32 max_sdu_size, |
| 65 | __u8 max_header_size, |
| 66 | struct sk_buff *); |
YOSHIFUJI Hideaki | 6819bc2 | 2007-02-09 23:24:53 +0900 | [diff] [blame] | 67 | static void irlan_check_response_param(struct irlan_cb *self, char *param, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 68 | char *value, int val_len); |
| 69 | static void irlan_client_open_ctrl_tsap(struct irlan_cb *self); |
| 70 | |
| 71 | static void irlan_client_kick_timer_expired(void *data) |
| 72 | { |
| 73 | struct irlan_cb *self = (struct irlan_cb *) data; |
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 | IRDA_ASSERT(self != NULL, return;); |
| 76 | IRDA_ASSERT(self->magic == IRLAN_MAGIC, return;); |
YOSHIFUJI Hideaki | 6819bc2 | 2007-02-09 23:24:53 +0900 | [diff] [blame] | 77 | |
| 78 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 79 | * 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] | 80 | * indication it needs to make progress. If the client is still in |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 81 | * IDLE state, we must kick it to, but only if the provider is not IDLE |
YOSHIFUJI Hideaki | 6819bc2 | 2007-02-09 23:24:53 +0900 | [diff] [blame] | 82 | */ |
| 83 | if ((self->provider.access_type == ACCESS_PEER) && |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 84 | (self->client.state == IRLAN_IDLE) && |
| 85 | (self->provider.state != IRLAN_IDLE)) { |
| 86 | irlan_client_wakeup(self, self->saddr, self->daddr); |
| 87 | } |
| 88 | } |
| 89 | |
| 90 | static void irlan_client_start_kick_timer(struct irlan_cb *self, int timeout) |
| 91 | { |
YOSHIFUJI Hideaki | 6819bc2 | 2007-02-09 23:24:53 +0900 | [diff] [blame] | 92 | irda_start_timer(&self->client.kick_timer, timeout, (void *) self, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 93 | irlan_client_kick_timer_expired); |
| 94 | } |
| 95 | |
| 96 | /* |
| 97 | * Function irlan_client_wakeup (self, saddr, daddr) |
| 98 | * |
| 99 | * Wake up client |
| 100 | * |
| 101 | */ |
| 102 | void irlan_client_wakeup(struct irlan_cb *self, __u32 saddr, __u32 daddr) |
| 103 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 104 | IRDA_ASSERT(self != NULL, return;); |
| 105 | IRDA_ASSERT(self->magic == IRLAN_MAGIC, return;); |
| 106 | |
YOSHIFUJI Hideaki | 6819bc2 | 2007-02-09 23:24:53 +0900 | [diff] [blame] | 107 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 108 | * Check if we are already awake, or if we are a provider in direct |
| 109 | * mode (in that case we must leave the client idle |
| 110 | */ |
YOSHIFUJI Hideaki | 6819bc2 | 2007-02-09 23:24:53 +0900 | [diff] [blame] | 111 | if ((self->client.state != IRLAN_IDLE) || |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 112 | (self->provider.access_type == ACCESS_DIRECT)) |
| 113 | { |
Joe Perches | 955a9d20 | 2014-11-11 14:44:57 -0800 | [diff] [blame] | 114 | pr_debug("%s(), already awake!\n", __func__); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 115 | return; |
| 116 | } |
| 117 | |
| 118 | /* Addresses may have changed! */ |
| 119 | self->saddr = saddr; |
| 120 | self->daddr = daddr; |
| 121 | |
| 122 | if (self->disconnect_reason == LM_USER_REQUEST) { |
Joe Perches | 955a9d20 | 2014-11-11 14:44:57 -0800 | [diff] [blame] | 123 | pr_debug("%s(), still stopped by user\n", __func__); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 124 | return; |
| 125 | } |
| 126 | |
| 127 | /* Open TSAPs */ |
| 128 | irlan_client_open_ctrl_tsap(self); |
| 129 | irlan_open_data_tsap(self); |
| 130 | |
| 131 | irlan_do_client_event(self, IRLAN_DISCOVERY_INDICATION, NULL); |
YOSHIFUJI Hideaki | 6819bc2 | 2007-02-09 23:24:53 +0900 | [diff] [blame] | 132 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 133 | /* Start kick timer */ |
| 134 | irlan_client_start_kick_timer(self, 2*HZ); |
| 135 | } |
| 136 | |
| 137 | /* |
| 138 | * Function irlan_discovery_indication (daddr) |
| 139 | * |
| 140 | * Remote device with IrLAN server support discovered |
| 141 | * |
| 142 | */ |
| 143 | void irlan_client_discovery_indication(discinfo_t *discovery, |
| 144 | DISCOVERY_MODE mode, |
YOSHIFUJI Hideaki | 6819bc2 | 2007-02-09 23:24:53 +0900 | [diff] [blame] | 145 | void *priv) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 146 | { |
| 147 | struct irlan_cb *self; |
| 148 | __u32 saddr, daddr; |
YOSHIFUJI Hideaki | 6819bc2 | 2007-02-09 23:24:53 +0900 | [diff] [blame] | 149 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 150 | IRDA_ASSERT(discovery != NULL, return;); |
| 151 | |
| 152 | /* |
| 153 | * I didn't check it, but I bet that IrLAN suffer from the same |
| 154 | * deficiency as IrComm and doesn't handle two instances |
| 155 | * simultaneously connecting to each other. |
| 156 | * Same workaround, drop passive discoveries. |
| 157 | * Jean II */ |
| 158 | if(mode == DISCOVERY_PASSIVE) |
| 159 | return; |
| 160 | |
| 161 | saddr = discovery->saddr; |
| 162 | daddr = discovery->daddr; |
| 163 | |
| 164 | /* Find instance */ |
| 165 | rcu_read_lock(); |
| 166 | self = irlan_get_any(); |
| 167 | if (self) { |
Josh Triplett | 1bc1731 | 2006-06-29 17:02:31 -0700 | [diff] [blame] | 168 | IRDA_ASSERT(self->magic == IRLAN_MAGIC, goto out;); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 169 | |
Joe Perches | 955a9d20 | 2014-11-11 14:44:57 -0800 | [diff] [blame] | 170 | pr_debug("%s(), Found instance (%08x)!\n", __func__ , |
| 171 | daddr); |
YOSHIFUJI Hideaki | 6819bc2 | 2007-02-09 23:24:53 +0900 | [diff] [blame] | 172 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 173 | irlan_client_wakeup(self, saddr, daddr); |
| 174 | } |
Josh Triplett | 1bc1731 | 2006-06-29 17:02:31 -0700 | [diff] [blame] | 175 | IRDA_ASSERT_LABEL(out:) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 176 | rcu_read_unlock(); |
| 177 | } |
YOSHIFUJI Hideaki | 6819bc2 | 2007-02-09 23:24:53 +0900 | [diff] [blame] | 178 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 179 | /* |
| 180 | * Function irlan_client_data_indication (handle, skb) |
| 181 | * |
| 182 | * This function gets the data that is received on the control channel |
| 183 | * |
| 184 | */ |
YOSHIFUJI Hideaki | 6819bc2 | 2007-02-09 23:24:53 +0900 | [diff] [blame] | 185 | static int irlan_client_ctrl_data_indication(void *instance, void *sap, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 186 | struct sk_buff *skb) |
| 187 | { |
| 188 | struct irlan_cb *self; |
YOSHIFUJI Hideaki | 6819bc2 | 2007-02-09 23:24:53 +0900 | [diff] [blame] | 189 | |
Joe Perches | ea11073 | 2011-06-13 16:21:26 +0000 | [diff] [blame] | 190 | self = instance; |
YOSHIFUJI Hideaki | 6819bc2 | 2007-02-09 23:24:53 +0900 | [diff] [blame] | 191 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 192 | IRDA_ASSERT(self != NULL, return -1;); |
| 193 | IRDA_ASSERT(self->magic == IRLAN_MAGIC, return -1;); |
| 194 | IRDA_ASSERT(skb != NULL, return -1;); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 195 | |
YOSHIFUJI Hideaki | 6819bc2 | 2007-02-09 23:24:53 +0900 | [diff] [blame] | 196 | irlan_do_client_event(self, IRLAN_DATA_INDICATION, skb); |
| 197 | |
| 198 | /* Ready for a new command */ |
Joe Perches | 955a9d20 | 2014-11-11 14:44:57 -0800 | [diff] [blame] | 199 | pr_debug("%s(), clearing tx_busy\n", __func__); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 200 | self->client.tx_busy = FALSE; |
| 201 | |
| 202 | /* Check if we have some queued commands waiting to be sent */ |
| 203 | irlan_run_ctrl_tx_queue(self); |
| 204 | |
| 205 | return 0; |
| 206 | } |
| 207 | |
YOSHIFUJI Hideaki | 6819bc2 | 2007-02-09 23:24:53 +0900 | [diff] [blame] | 208 | static void irlan_client_ctrl_disconnect_indication(void *instance, void *sap, |
| 209 | LM_REASON reason, |
| 210 | struct sk_buff *userdata) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 211 | { |
| 212 | struct irlan_cb *self; |
| 213 | struct tsap_cb *tsap; |
| 214 | struct sk_buff *skb; |
| 215 | |
Joe Perches | 955a9d20 | 2014-11-11 14:44:57 -0800 | [diff] [blame] | 216 | pr_debug("%s(), reason=%d\n", __func__ , reason); |
YOSHIFUJI Hideaki | 6819bc2 | 2007-02-09 23:24:53 +0900 | [diff] [blame] | 217 | |
Joe Perches | ea11073 | 2011-06-13 16:21:26 +0000 | [diff] [blame] | 218 | self = instance; |
| 219 | tsap = sap; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 220 | |
| 221 | IRDA_ASSERT(self != NULL, return;); |
YOSHIFUJI Hideaki | 6819bc2 | 2007-02-09 23:24:53 +0900 | [diff] [blame] | 222 | IRDA_ASSERT(self->magic == IRLAN_MAGIC, return;); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 223 | IRDA_ASSERT(tsap != NULL, return;); |
| 224 | IRDA_ASSERT(tsap->magic == TTP_TSAP_MAGIC, return;); |
YOSHIFUJI Hideaki | 6819bc2 | 2007-02-09 23:24:53 +0900 | [diff] [blame] | 225 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 226 | IRDA_ASSERT(tsap == self->client.tsap_ctrl, return;); |
| 227 | |
YOSHIFUJI Hideaki | 6819bc2 | 2007-02-09 23:24:53 +0900 | [diff] [blame] | 228 | /* Remove frames queued on the control channel */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 229 | while ((skb = skb_dequeue(&self->client.txq)) != NULL) { |
| 230 | dev_kfree_skb(skb); |
| 231 | } |
| 232 | self->client.tx_busy = FALSE; |
| 233 | |
| 234 | irlan_do_client_event(self, IRLAN_LMP_DISCONNECT, NULL); |
| 235 | } |
| 236 | |
| 237 | /* |
| 238 | * Function irlan_client_open_tsaps (self) |
| 239 | * |
| 240 | * Initialize callbacks and open IrTTP TSAPs |
| 241 | * |
| 242 | */ |
| 243 | static void irlan_client_open_ctrl_tsap(struct irlan_cb *self) |
| 244 | { |
| 245 | struct tsap_cb *tsap; |
| 246 | notify_t notify; |
| 247 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 248 | IRDA_ASSERT(self != NULL, return;); |
| 249 | IRDA_ASSERT(self->magic == IRLAN_MAGIC, return;); |
| 250 | |
| 251 | /* Check if already open */ |
| 252 | if (self->client.tsap_ctrl) |
| 253 | return; |
| 254 | |
| 255 | irda_notify_init(¬ify); |
| 256 | |
| 257 | /* Set up callbacks */ |
| 258 | notify.data_indication = irlan_client_ctrl_data_indication; |
| 259 | notify.connect_confirm = irlan_client_ctrl_connect_confirm; |
| 260 | notify.disconnect_indication = irlan_client_ctrl_disconnect_indication; |
| 261 | notify.instance = self; |
| 262 | strlcpy(notify.name, "IrLAN ctrl (c)", sizeof(notify.name)); |
YOSHIFUJI Hideaki | 6819bc2 | 2007-02-09 23:24:53 +0900 | [diff] [blame] | 263 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 264 | tsap = irttp_open_tsap(LSAP_ANY, DEFAULT_INITIAL_CREDIT, ¬ify); |
| 265 | if (!tsap) { |
Joe Perches | 955a9d20 | 2014-11-11 14:44:57 -0800 | [diff] [blame] | 266 | pr_debug("%s(), Got no tsap!\n", __func__); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 267 | return; |
| 268 | } |
| 269 | self->client.tsap_ctrl = tsap; |
| 270 | } |
| 271 | |
| 272 | /* |
| 273 | * Function irlan_client_connect_confirm (handle, skb) |
| 274 | * |
| 275 | * Connection to peer IrLAN laye confirmed |
| 276 | * |
| 277 | */ |
YOSHIFUJI Hideaki | 6819bc2 | 2007-02-09 23:24:53 +0900 | [diff] [blame] | 278 | static void irlan_client_ctrl_connect_confirm(void *instance, void *sap, |
| 279 | struct qos_info *qos, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 280 | __u32 max_sdu_size, |
| 281 | __u8 max_header_size, |
YOSHIFUJI Hideaki | 6819bc2 | 2007-02-09 23:24:53 +0900 | [diff] [blame] | 282 | struct sk_buff *skb) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 283 | { |
| 284 | struct irlan_cb *self; |
| 285 | |
Joe Perches | ea11073 | 2011-06-13 16:21:26 +0000 | [diff] [blame] | 286 | self = instance; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 287 | |
| 288 | IRDA_ASSERT(self != NULL, return;); |
| 289 | IRDA_ASSERT(self->magic == IRLAN_MAGIC, return;); |
| 290 | |
| 291 | self->client.max_sdu_size = max_sdu_size; |
| 292 | self->client.max_header_size = max_header_size; |
| 293 | |
| 294 | /* TODO: we could set the MTU depending on the max_sdu_size */ |
| 295 | |
| 296 | irlan_do_client_event(self, IRLAN_CONNECT_COMPLETE, NULL); |
| 297 | } |
| 298 | |
| 299 | /* |
| 300 | * Function print_ret_code (code) |
| 301 | * |
| 302 | * Print return code of request to peer IrLAN layer. |
| 303 | * |
| 304 | */ |
YOSHIFUJI Hideaki | 6819bc2 | 2007-02-09 23:24:53 +0900 | [diff] [blame] | 305 | static void print_ret_code(__u8 code) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 306 | { |
| 307 | switch(code) { |
| 308 | case 0: |
| 309 | printk(KERN_INFO "Success\n"); |
| 310 | break; |
| 311 | case 1: |
Joe Perches | 6c91023 | 2014-11-11 13:37:30 -0800 | [diff] [blame] | 312 | net_warn_ratelimited("IrLAN: Insufficient resources\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 313 | break; |
| 314 | case 2: |
Joe Perches | 6c91023 | 2014-11-11 13:37:30 -0800 | [diff] [blame] | 315 | net_warn_ratelimited("IrLAN: Invalid command format\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 316 | break; |
| 317 | case 3: |
Joe Perches | 6c91023 | 2014-11-11 13:37:30 -0800 | [diff] [blame] | 318 | net_warn_ratelimited("IrLAN: Command not supported\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 319 | break; |
| 320 | case 4: |
Joe Perches | 6c91023 | 2014-11-11 13:37:30 -0800 | [diff] [blame] | 321 | net_warn_ratelimited("IrLAN: Parameter not supported\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 322 | break; |
| 323 | case 5: |
Joe Perches | 6c91023 | 2014-11-11 13:37:30 -0800 | [diff] [blame] | 324 | net_warn_ratelimited("IrLAN: Value not supported\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 325 | break; |
| 326 | case 6: |
Joe Perches | 6c91023 | 2014-11-11 13:37:30 -0800 | [diff] [blame] | 327 | net_warn_ratelimited("IrLAN: Not open\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 328 | break; |
| 329 | case 7: |
Joe Perches | 6c91023 | 2014-11-11 13:37:30 -0800 | [diff] [blame] | 330 | net_warn_ratelimited("IrLAN: Authentication required\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 331 | break; |
| 332 | case 8: |
Joe Perches | 6c91023 | 2014-11-11 13:37:30 -0800 | [diff] [blame] | 333 | net_warn_ratelimited("IrLAN: Invalid password\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 334 | break; |
| 335 | case 9: |
Joe Perches | 6c91023 | 2014-11-11 13:37:30 -0800 | [diff] [blame] | 336 | net_warn_ratelimited("IrLAN: Protocol error\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 337 | break; |
| 338 | case 255: |
Joe Perches | 6c91023 | 2014-11-11 13:37:30 -0800 | [diff] [blame] | 339 | net_warn_ratelimited("IrLAN: Asynchronous status\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 340 | break; |
| 341 | } |
| 342 | } |
| 343 | |
| 344 | /* |
| 345 | * Function irlan_client_parse_response (self, skb) |
| 346 | * |
YOSHIFUJI Hideaki | 6819bc2 | 2007-02-09 23:24:53 +0900 | [diff] [blame] | 347 | * Extract all parameters from received buffer, then feed them to |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 348 | * check_params for parsing |
| 349 | */ |
| 350 | void irlan_client_parse_response(struct irlan_cb *self, struct sk_buff *skb) |
| 351 | { |
| 352 | __u8 *frame; |
| 353 | __u8 *ptr; |
| 354 | int count; |
| 355 | int ret; |
| 356 | __u16 val_len; |
| 357 | int i; |
YOSHIFUJI Hideaki | 6819bc2 | 2007-02-09 23:24:53 +0900 | [diff] [blame] | 358 | char *name; |
| 359 | char *value; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 360 | |
YOSHIFUJI Hideaki | 6819bc2 | 2007-02-09 23:24:53 +0900 | [diff] [blame] | 361 | IRDA_ASSERT(skb != NULL, return;); |
| 362 | |
Joe Perches | 955a9d20 | 2014-11-11 14:44:57 -0800 | [diff] [blame] | 363 | pr_debug("%s() skb->len=%d\n", __func__ , (int)skb->len); |
YOSHIFUJI Hideaki | 6819bc2 | 2007-02-09 23:24:53 +0900 | [diff] [blame] | 364 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 365 | IRDA_ASSERT(self != NULL, return;); |
| 366 | IRDA_ASSERT(self->magic == IRLAN_MAGIC, return;); |
YOSHIFUJI Hideaki | 6819bc2 | 2007-02-09 23:24:53 +0900 | [diff] [blame] | 367 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 368 | if (!skb) { |
Joe Perches | 6c91023 | 2014-11-11 13:37:30 -0800 | [diff] [blame] | 369 | net_err_ratelimited("%s(), Got NULL skb!\n", __func__); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 370 | return; |
| 371 | } |
| 372 | frame = skb->data; |
YOSHIFUJI Hideaki | 6819bc2 | 2007-02-09 23:24:53 +0900 | [diff] [blame] | 373 | |
| 374 | /* |
| 375 | * Check return code and print it if not success |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 376 | */ |
| 377 | if (frame[0]) { |
| 378 | print_ret_code(frame[0]); |
| 379 | return; |
| 380 | } |
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 | name = kmalloc(255, GFP_ATOMIC); |
| 383 | if (!name) |
| 384 | return; |
| 385 | value = kmalloc(1016, GFP_ATOMIC); |
| 386 | if (!value) { |
| 387 | kfree(name); |
| 388 | return; |
| 389 | } |
| 390 | |
| 391 | /* How many parameters? */ |
| 392 | count = frame[1]; |
| 393 | |
Joe Perches | 955a9d20 | 2014-11-11 14:44:57 -0800 | [diff] [blame] | 394 | pr_debug("%s(), got %d parameters\n", __func__ , count); |
YOSHIFUJI Hideaki | 6819bc2 | 2007-02-09 23:24:53 +0900 | [diff] [blame] | 395 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 396 | ptr = frame+2; |
| 397 | |
| 398 | /* For all parameters */ |
YOSHIFUJI Hideaki | 6819bc2 | 2007-02-09 23:24:53 +0900 | [diff] [blame] | 399 | for (i=0; i<count;i++) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 400 | ret = irlan_extract_param(ptr, name, value, &val_len); |
| 401 | if (ret < 0) { |
Joe Perches | 955a9d20 | 2014-11-11 14:44:57 -0800 | [diff] [blame] | 402 | pr_debug("%s(), IrLAN, Error!\n", __func__); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 403 | break; |
| 404 | } |
| 405 | ptr += ret; |
| 406 | irlan_check_response_param(self, name, value, val_len); |
YOSHIFUJI Hideaki | 6819bc2 | 2007-02-09 23:24:53 +0900 | [diff] [blame] | 407 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 408 | /* Cleanup */ |
| 409 | kfree(name); |
| 410 | kfree(value); |
| 411 | } |
| 412 | |
| 413 | /* |
| 414 | * Function irlan_check_response_param (self, param, value, val_len) |
| 415 | * |
| 416 | * Check which parameter is received and update local variables |
| 417 | * |
| 418 | */ |
YOSHIFUJI Hideaki | 6819bc2 | 2007-02-09 23:24:53 +0900 | [diff] [blame] | 419 | static void irlan_check_response_param(struct irlan_cb *self, char *param, |
| 420 | char *value, int val_len) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 421 | { |
| 422 | __u16 tmp_cpu; /* Temporary value in host order */ |
| 423 | __u8 *bytes; |
| 424 | int i; |
| 425 | |
Joe Perches | 955a9d20 | 2014-11-11 14:44:57 -0800 | [diff] [blame] | 426 | pr_debug("%s(), parm=%s\n", __func__ , param); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 427 | |
| 428 | IRDA_ASSERT(self != NULL, return;); |
| 429 | IRDA_ASSERT(self->magic == IRLAN_MAGIC, return;); |
| 430 | |
| 431 | /* Media type */ |
| 432 | if (strcmp(param, "MEDIA") == 0) { |
| 433 | if (strcmp(value, "802.3") == 0) |
| 434 | self->media = MEDIA_802_3; |
| 435 | else |
| 436 | self->media = MEDIA_802_5; |
| 437 | return; |
| 438 | } |
| 439 | if (strcmp(param, "FILTER_TYPE") == 0) { |
| 440 | if (strcmp(value, "DIRECTED") == 0) |
| 441 | self->client.filter_type |= IRLAN_DIRECTED; |
| 442 | else if (strcmp(value, "FUNCTIONAL") == 0) |
| 443 | self->client.filter_type |= IRLAN_FUNCTIONAL; |
| 444 | else if (strcmp(value, "GROUP") == 0) |
| 445 | self->client.filter_type |= IRLAN_GROUP; |
| 446 | else if (strcmp(value, "MAC_FRAME") == 0) |
| 447 | self->client.filter_type |= IRLAN_MAC_FRAME; |
| 448 | else if (strcmp(value, "MULTICAST") == 0) |
| 449 | self->client.filter_type |= IRLAN_MULTICAST; |
| 450 | else if (strcmp(value, "BROADCAST") == 0) |
| 451 | self->client.filter_type |= IRLAN_BROADCAST; |
| 452 | else if (strcmp(value, "IPX_SOCKET") == 0) |
| 453 | self->client.filter_type |= IRLAN_IPX_SOCKET; |
YOSHIFUJI Hideaki | 6819bc2 | 2007-02-09 23:24:53 +0900 | [diff] [blame] | 454 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 455 | } |
| 456 | if (strcmp(param, "ACCESS_TYPE") == 0) { |
| 457 | if (strcmp(value, "DIRECT") == 0) |
| 458 | self->client.access_type = ACCESS_DIRECT; |
| 459 | else if (strcmp(value, "PEER") == 0) |
| 460 | self->client.access_type = ACCESS_PEER; |
| 461 | else if (strcmp(value, "HOSTED") == 0) |
| 462 | self->client.access_type = ACCESS_HOSTED; |
| 463 | else { |
Joe Perches | 955a9d20 | 2014-11-11 14:44:57 -0800 | [diff] [blame] | 464 | pr_debug("%s(), unknown access type!\n", __func__); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 465 | } |
| 466 | } |
| 467 | /* IRLAN version */ |
| 468 | if (strcmp(param, "IRLAN_VER") == 0) { |
Joe Perches | 955a9d20 | 2014-11-11 14:44:57 -0800 | [diff] [blame] | 469 | pr_debug("IrLAN version %d.%d\n", (__u8)value[0], |
| 470 | (__u8)value[1]); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 471 | |
| 472 | self->version[0] = value[0]; |
| 473 | self->version[1] = value[1]; |
| 474 | return; |
| 475 | } |
| 476 | /* Which remote TSAP to use for data channel */ |
| 477 | if (strcmp(param, "DATA_CHAN") == 0) { |
| 478 | self->dtsap_sel_data = value[0]; |
Joe Perches | 955a9d20 | 2014-11-11 14:44:57 -0800 | [diff] [blame] | 479 | pr_debug("Data TSAP = %02x\n", self->dtsap_sel_data); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 480 | return; |
| 481 | } |
| 482 | if (strcmp(param, "CON_ARB") == 0) { |
| 483 | memcpy(&tmp_cpu, value, 2); /* Align value */ |
| 484 | le16_to_cpus(&tmp_cpu); /* Convert to host order */ |
| 485 | self->client.recv_arb_val = tmp_cpu; |
Joe Perches | 955a9d20 | 2014-11-11 14:44:57 -0800 | [diff] [blame] | 486 | pr_debug("%s(), receive arb val=%d\n", __func__ , |
| 487 | self->client.recv_arb_val); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 488 | } |
| 489 | if (strcmp(param, "MAX_FRAME") == 0) { |
| 490 | memcpy(&tmp_cpu, value, 2); /* Align value */ |
| 491 | le16_to_cpus(&tmp_cpu); /* Convert to host order */ |
| 492 | self->client.max_frame = tmp_cpu; |
Joe Perches | 955a9d20 | 2014-11-11 14:44:57 -0800 | [diff] [blame] | 493 | pr_debug("%s(), max frame=%d\n", __func__ , |
| 494 | self->client.max_frame); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 495 | } |
YOSHIFUJI Hideaki | 6819bc2 | 2007-02-09 23:24:53 +0900 | [diff] [blame] | 496 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 497 | /* RECONNECT_KEY, in case the link goes down! */ |
| 498 | if (strcmp(param, "RECONNECT_KEY") == 0) { |
Joe Perches | 955a9d20 | 2014-11-11 14:44:57 -0800 | [diff] [blame] | 499 | pr_debug("Got reconnect key: "); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 500 | /* for (i = 0; i < val_len; i++) */ |
| 501 | /* printk("%02x", value[i]); */ |
| 502 | memcpy(self->client.reconnect_key, value, val_len); |
| 503 | self->client.key_len = val_len; |
Joe Perches | 955a9d20 | 2014-11-11 14:44:57 -0800 | [diff] [blame] | 504 | pr_debug("\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 505 | } |
| 506 | /* FILTER_ENTRY, have we got an ethernet address? */ |
| 507 | if (strcmp(param, "FILTER_ENTRY") == 0) { |
| 508 | bytes = value; |
Joe Perches | 955a9d20 | 2014-11-11 14:44:57 -0800 | [diff] [blame] | 509 | pr_debug("Ethernet address = %pM\n", bytes); |
YOSHIFUJI Hideaki | 6819bc2 | 2007-02-09 23:24:53 +0900 | [diff] [blame] | 510 | for (i = 0; i < 6; i++) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 511 | self->dev->dev_addr[i] = bytes[i]; |
| 512 | } |
| 513 | } |
| 514 | |
| 515 | /* |
| 516 | * Function irlan_client_get_value_confirm (obj_id, value) |
| 517 | * |
| 518 | * Got results from remote LM-IAS |
| 519 | * |
| 520 | */ |
YOSHIFUJI Hideaki | 6819bc2 | 2007-02-09 23:24:53 +0900 | [diff] [blame] | 521 | void irlan_client_get_value_confirm(int result, __u16 obj_id, |
| 522 | struct ias_value *value, void *priv) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 523 | { |
| 524 | struct irlan_cb *self; |
YOSHIFUJI Hideaki | 6819bc2 | 2007-02-09 23:24:53 +0900 | [diff] [blame] | 525 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 526 | IRDA_ASSERT(priv != NULL, return;); |
| 527 | |
Joe Perches | ea11073 | 2011-06-13 16:21:26 +0000 | [diff] [blame] | 528 | self = priv; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 529 | IRDA_ASSERT(self->magic == IRLAN_MAGIC, return;); |
| 530 | |
| 531 | /* We probably don't need to make any more queries */ |
| 532 | iriap_close(self->client.iriap); |
| 533 | self->client.iriap = NULL; |
| 534 | |
| 535 | /* Check if request succeeded */ |
| 536 | if (result != IAS_SUCCESS) { |
Joe Perches | 955a9d20 | 2014-11-11 14:44:57 -0800 | [diff] [blame] | 537 | pr_debug("%s(), got NULL value!\n", __func__); |
YOSHIFUJI Hideaki | 6819bc2 | 2007-02-09 23:24:53 +0900 | [diff] [blame] | 538 | irlan_do_client_event(self, IRLAN_IAS_PROVIDER_NOT_AVAIL, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 539 | NULL); |
| 540 | return; |
| 541 | } |
| 542 | |
| 543 | switch (value->type) { |
| 544 | case IAS_INTEGER: |
| 545 | self->dtsap_sel_ctrl = value->t.integer; |
| 546 | |
| 547 | if (value->t.integer != -1) { |
| 548 | irlan_do_client_event(self, IRLAN_IAS_PROVIDER_AVAIL, |
| 549 | NULL); |
| 550 | return; |
| 551 | } |
| 552 | irias_delete_value(value); |
| 553 | break; |
| 554 | default: |
Joe Perches | 955a9d20 | 2014-11-11 14:44:57 -0800 | [diff] [blame] | 555 | pr_debug("%s(), unknown type!\n", __func__); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 556 | break; |
| 557 | } |
| 558 | irlan_do_client_event(self, IRLAN_IAS_PROVIDER_NOT_AVAIL, NULL); |
| 559 | } |