mirror of
https://github.com/AetherDroid/android_kernel_samsung_on5xelte.git
synced 2025-09-07 08:48:05 -04:00
Fixed MTP to work with TWRP
This commit is contained in:
commit
f6dfaef42e
50820 changed files with 20846062 additions and 0 deletions
14
net/irda/irlan/Kconfig
Normal file
14
net/irda/irlan/Kconfig
Normal file
|
@ -0,0 +1,14 @@
|
|||
config IRLAN
|
||||
tristate "IrLAN protocol"
|
||||
depends on IRDA
|
||||
help
|
||||
Say Y here if you want to build support for the IrLAN protocol.
|
||||
To compile it as a module, choose M here: the module will be called
|
||||
irlan. IrLAN emulates an Ethernet and makes it possible to put up
|
||||
a wireless LAN using infrared beams.
|
||||
|
||||
The IrLAN protocol can be used to talk with infrared access points
|
||||
like the HP NetbeamIR, or the ESI JetEye NET. You can also connect
|
||||
to another Linux machine running the IrLAN protocol for ad-hoc
|
||||
networking!
|
||||
|
7
net/irda/irlan/Makefile
Normal file
7
net/irda/irlan/Makefile
Normal file
|
@ -0,0 +1,7 @@
|
|||
#
|
||||
# Makefile for the Linux IrDA IrLAN protocol layer.
|
||||
#
|
||||
|
||||
obj-$(CONFIG_IRLAN) += irlan.o
|
||||
|
||||
irlan-y := irlan_common.o irlan_eth.o irlan_event.o irlan_client.o irlan_provider.o irlan_filter.o irlan_provider_event.o irlan_client_event.o
|
575
net/irda/irlan/irlan_client.c
Normal file
575
net/irda/irlan/irlan_client.c
Normal file
|
@ -0,0 +1,575 @@
|
|||
/*********************************************************************
|
||||
*
|
||||
* Filename: irlan_client.c
|
||||
* Version: 0.9
|
||||
* Description: IrDA LAN Access Protocol (IrLAN) Client
|
||||
* Status: Experimental.
|
||||
* Author: Dag Brattli <dagb@cs.uit.no>
|
||||
* Created at: Sun Aug 31 20:14:37 1997
|
||||
* Modified at: Tue Dec 14 15:47:02 1999
|
||||
* Modified by: Dag Brattli <dagb@cs.uit.no>
|
||||
* Sources: skeleton.c by Donald Becker <becker@CESDIS.gsfc.nasa.gov>
|
||||
* slip.c by Laurence Culhane, <loz@holmes.demon.co.uk>
|
||||
* Fred N. van Kempen, <waltje@uwalt.nl.mugnet.org>
|
||||
*
|
||||
* Copyright (c) 1998-1999 Dag Brattli <dagb@cs.uit.no>,
|
||||
* All Rights Reserved.
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License as
|
||||
* published by the Free Software Foundation; either version 2 of
|
||||
* the License, or (at your option) any later version.
|
||||
*
|
||||
* Neither Dag Brattli nor University of Tromsø admit liability nor
|
||||
* provide warranty for any of this software. This material is
|
||||
* provided "AS-IS" and at no charge.
|
||||
*
|
||||
********************************************************************/
|
||||
|
||||
#include <linux/kernel.h>
|
||||
#include <linux/string.h>
|
||||
#include <linux/slab.h>
|
||||
#include <linux/errno.h>
|
||||
#include <linux/init.h>
|
||||
#include <linux/netdevice.h>
|
||||
#include <linux/etherdevice.h>
|
||||
#include <linux/if_arp.h>
|
||||
#include <linux/bitops.h>
|
||||
#include <net/arp.h>
|
||||
|
||||
#include <asm/byteorder.h>
|
||||
|
||||
#include <net/irda/irda.h>
|
||||
#include <net/irda/irttp.h>
|
||||
#include <net/irda/irlmp.h>
|
||||
#include <net/irda/irias_object.h>
|
||||
#include <net/irda/iriap.h>
|
||||
#include <net/irda/timer.h>
|
||||
|
||||
#include <net/irda/irlan_common.h>
|
||||
#include <net/irda/irlan_event.h>
|
||||
#include <net/irda/irlan_eth.h>
|
||||
#include <net/irda/irlan_provider.h>
|
||||
#include <net/irda/irlan_client.h>
|
||||
|
||||
#undef CONFIG_IRLAN_GRATUITOUS_ARP
|
||||
|
||||
static void irlan_client_ctrl_disconnect_indication(void *instance, void *sap,
|
||||
LM_REASON reason,
|
||||
struct sk_buff *);
|
||||
static int irlan_client_ctrl_data_indication(void *instance, void *sap,
|
||||
struct sk_buff *skb);
|
||||
static void irlan_client_ctrl_connect_confirm(void *instance, void *sap,
|
||||
struct qos_info *qos,
|
||||
__u32 max_sdu_size,
|
||||
__u8 max_header_size,
|
||||
struct sk_buff *);
|
||||
static void irlan_check_response_param(struct irlan_cb *self, char *param,
|
||||
char *value, int val_len);
|
||||
static void irlan_client_open_ctrl_tsap(struct irlan_cb *self);
|
||||
|
||||
static void irlan_client_kick_timer_expired(void *data)
|
||||
{
|
||||
struct irlan_cb *self = (struct irlan_cb *) data;
|
||||
|
||||
IRDA_DEBUG(2, "%s()\n", __func__ );
|
||||
|
||||
IRDA_ASSERT(self != NULL, return;);
|
||||
IRDA_ASSERT(self->magic == IRLAN_MAGIC, return;);
|
||||
|
||||
/*
|
||||
* If we are in peer mode, the client may not have got the discovery
|
||||
* indication it needs to make progress. If the client is still in
|
||||
* IDLE state, we must kick it to, but only if the provider is not IDLE
|
||||
*/
|
||||
if ((self->provider.access_type == ACCESS_PEER) &&
|
||||
(self->client.state == IRLAN_IDLE) &&
|
||||
(self->provider.state != IRLAN_IDLE)) {
|
||||
irlan_client_wakeup(self, self->saddr, self->daddr);
|
||||
}
|
||||
}
|
||||
|
||||
static void irlan_client_start_kick_timer(struct irlan_cb *self, int timeout)
|
||||
{
|
||||
IRDA_DEBUG(4, "%s()\n", __func__ );
|
||||
|
||||
irda_start_timer(&self->client.kick_timer, timeout, (void *) self,
|
||||
irlan_client_kick_timer_expired);
|
||||
}
|
||||
|
||||
/*
|
||||
* Function irlan_client_wakeup (self, saddr, daddr)
|
||||
*
|
||||
* Wake up client
|
||||
*
|
||||
*/
|
||||
void irlan_client_wakeup(struct irlan_cb *self, __u32 saddr, __u32 daddr)
|
||||
{
|
||||
IRDA_DEBUG(1, "%s()\n", __func__ );
|
||||
|
||||
IRDA_ASSERT(self != NULL, return;);
|
||||
IRDA_ASSERT(self->magic == IRLAN_MAGIC, return;);
|
||||
|
||||
/*
|
||||
* Check if we are already awake, or if we are a provider in direct
|
||||
* mode (in that case we must leave the client idle
|
||||
*/
|
||||
if ((self->client.state != IRLAN_IDLE) ||
|
||||
(self->provider.access_type == ACCESS_DIRECT))
|
||||
{
|
||||
IRDA_DEBUG(0, "%s(), already awake!\n", __func__ );
|
||||
return;
|
||||
}
|
||||
|
||||
/* Addresses may have changed! */
|
||||
self->saddr = saddr;
|
||||
self->daddr = daddr;
|
||||
|
||||
if (self->disconnect_reason == LM_USER_REQUEST) {
|
||||
IRDA_DEBUG(0, "%s(), still stopped by user\n", __func__ );
|
||||
return;
|
||||
}
|
||||
|
||||
/* Open TSAPs */
|
||||
irlan_client_open_ctrl_tsap(self);
|
||||
irlan_open_data_tsap(self);
|
||||
|
||||
irlan_do_client_event(self, IRLAN_DISCOVERY_INDICATION, NULL);
|
||||
|
||||
/* Start kick timer */
|
||||
irlan_client_start_kick_timer(self, 2*HZ);
|
||||
}
|
||||
|
||||
/*
|
||||
* Function irlan_discovery_indication (daddr)
|
||||
*
|
||||
* Remote device with IrLAN server support discovered
|
||||
*
|
||||
*/
|
||||
void irlan_client_discovery_indication(discinfo_t *discovery,
|
||||
DISCOVERY_MODE mode,
|
||||
void *priv)
|
||||
{
|
||||
struct irlan_cb *self;
|
||||
__u32 saddr, daddr;
|
||||
|
||||
IRDA_DEBUG(1, "%s()\n", __func__ );
|
||||
|
||||
IRDA_ASSERT(discovery != NULL, return;);
|
||||
|
||||
/*
|
||||
* I didn't check it, but I bet that IrLAN suffer from the same
|
||||
* deficiency as IrComm and doesn't handle two instances
|
||||
* simultaneously connecting to each other.
|
||||
* Same workaround, drop passive discoveries.
|
||||
* Jean II */
|
||||
if(mode == DISCOVERY_PASSIVE)
|
||||
return;
|
||||
|
||||
saddr = discovery->saddr;
|
||||
daddr = discovery->daddr;
|
||||
|
||||
/* Find instance */
|
||||
rcu_read_lock();
|
||||
self = irlan_get_any();
|
||||
if (self) {
|
||||
IRDA_ASSERT(self->magic == IRLAN_MAGIC, goto out;);
|
||||
|
||||
IRDA_DEBUG(1, "%s(), Found instance (%08x)!\n", __func__ ,
|
||||
daddr);
|
||||
|
||||
irlan_client_wakeup(self, saddr, daddr);
|
||||
}
|
||||
IRDA_ASSERT_LABEL(out:)
|
||||
rcu_read_unlock();
|
||||
}
|
||||
|
||||
/*
|
||||
* Function irlan_client_data_indication (handle, skb)
|
||||
*
|
||||
* This function gets the data that is received on the control channel
|
||||
*
|
||||
*/
|
||||
static int irlan_client_ctrl_data_indication(void *instance, void *sap,
|
||||
struct sk_buff *skb)
|
||||
{
|
||||
struct irlan_cb *self;
|
||||
|
||||
IRDA_DEBUG(2, "%s()\n", __func__ );
|
||||
|
||||
self = instance;
|
||||
|
||||
IRDA_ASSERT(self != NULL, return -1;);
|
||||
IRDA_ASSERT(self->magic == IRLAN_MAGIC, return -1;);
|
||||
IRDA_ASSERT(skb != NULL, return -1;);
|
||||
|
||||
irlan_do_client_event(self, IRLAN_DATA_INDICATION, skb);
|
||||
|
||||
/* Ready for a new command */
|
||||
IRDA_DEBUG(2, "%s(), clearing tx_busy\n", __func__ );
|
||||
self->client.tx_busy = FALSE;
|
||||
|
||||
/* Check if we have some queued commands waiting to be sent */
|
||||
irlan_run_ctrl_tx_queue(self);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void irlan_client_ctrl_disconnect_indication(void *instance, void *sap,
|
||||
LM_REASON reason,
|
||||
struct sk_buff *userdata)
|
||||
{
|
||||
struct irlan_cb *self;
|
||||
struct tsap_cb *tsap;
|
||||
struct sk_buff *skb;
|
||||
|
||||
IRDA_DEBUG(4, "%s(), reason=%d\n", __func__ , reason);
|
||||
|
||||
self = instance;
|
||||
tsap = sap;
|
||||
|
||||
IRDA_ASSERT(self != NULL, return;);
|
||||
IRDA_ASSERT(self->magic == IRLAN_MAGIC, return;);
|
||||
IRDA_ASSERT(tsap != NULL, return;);
|
||||
IRDA_ASSERT(tsap->magic == TTP_TSAP_MAGIC, return;);
|
||||
|
||||
IRDA_ASSERT(tsap == self->client.tsap_ctrl, return;);
|
||||
|
||||
/* Remove frames queued on the control channel */
|
||||
while ((skb = skb_dequeue(&self->client.txq)) != NULL) {
|
||||
dev_kfree_skb(skb);
|
||||
}
|
||||
self->client.tx_busy = FALSE;
|
||||
|
||||
irlan_do_client_event(self, IRLAN_LMP_DISCONNECT, NULL);
|
||||
}
|
||||
|
||||
/*
|
||||
* Function irlan_client_open_tsaps (self)
|
||||
*
|
||||
* Initialize callbacks and open IrTTP TSAPs
|
||||
*
|
||||
*/
|
||||
static void irlan_client_open_ctrl_tsap(struct irlan_cb *self)
|
||||
{
|
||||
struct tsap_cb *tsap;
|
||||
notify_t notify;
|
||||
|
||||
IRDA_DEBUG(4, "%s()\n", __func__ );
|
||||
|
||||
IRDA_ASSERT(self != NULL, return;);
|
||||
IRDA_ASSERT(self->magic == IRLAN_MAGIC, return;);
|
||||
|
||||
/* Check if already open */
|
||||
if (self->client.tsap_ctrl)
|
||||
return;
|
||||
|
||||
irda_notify_init(¬ify);
|
||||
|
||||
/* Set up callbacks */
|
||||
notify.data_indication = irlan_client_ctrl_data_indication;
|
||||
notify.connect_confirm = irlan_client_ctrl_connect_confirm;
|
||||
notify.disconnect_indication = irlan_client_ctrl_disconnect_indication;
|
||||
notify.instance = self;
|
||||
strlcpy(notify.name, "IrLAN ctrl (c)", sizeof(notify.name));
|
||||
|
||||
tsap = irttp_open_tsap(LSAP_ANY, DEFAULT_INITIAL_CREDIT, ¬ify);
|
||||
if (!tsap) {
|
||||
IRDA_DEBUG(2, "%s(), Got no tsap!\n", __func__ );
|
||||
return;
|
||||
}
|
||||
self->client.tsap_ctrl = tsap;
|
||||
}
|
||||
|
||||
/*
|
||||
* Function irlan_client_connect_confirm (handle, skb)
|
||||
*
|
||||
* Connection to peer IrLAN laye confirmed
|
||||
*
|
||||
*/
|
||||
static void irlan_client_ctrl_connect_confirm(void *instance, void *sap,
|
||||
struct qos_info *qos,
|
||||
__u32 max_sdu_size,
|
||||
__u8 max_header_size,
|
||||
struct sk_buff *skb)
|
||||
{
|
||||
struct irlan_cb *self;
|
||||
|
||||
IRDA_DEBUG(4, "%s()\n", __func__ );
|
||||
|
||||
self = instance;
|
||||
|
||||
IRDA_ASSERT(self != NULL, return;);
|
||||
IRDA_ASSERT(self->magic == IRLAN_MAGIC, return;);
|
||||
|
||||
self->client.max_sdu_size = max_sdu_size;
|
||||
self->client.max_header_size = max_header_size;
|
||||
|
||||
/* TODO: we could set the MTU depending on the max_sdu_size */
|
||||
|
||||
irlan_do_client_event(self, IRLAN_CONNECT_COMPLETE, NULL);
|
||||
}
|
||||
|
||||
/*
|
||||
* Function print_ret_code (code)
|
||||
*
|
||||
* Print return code of request to peer IrLAN layer.
|
||||
*
|
||||
*/
|
||||
static void print_ret_code(__u8 code)
|
||||
{
|
||||
switch(code) {
|
||||
case 0:
|
||||
printk(KERN_INFO "Success\n");
|
||||
break;
|
||||
case 1:
|
||||
IRDA_WARNING("IrLAN: Insufficient resources\n");
|
||||
break;
|
||||
case 2:
|
||||
IRDA_WARNING("IrLAN: Invalid command format\n");
|
||||
break;
|
||||
case 3:
|
||||
IRDA_WARNING("IrLAN: Command not supported\n");
|
||||
break;
|
||||
case 4:
|
||||
IRDA_WARNING("IrLAN: Parameter not supported\n");
|
||||
break;
|
||||
case 5:
|
||||
IRDA_WARNING("IrLAN: Value not supported\n");
|
||||
break;
|
||||
case 6:
|
||||
IRDA_WARNING("IrLAN: Not open\n");
|
||||
break;
|
||||
case 7:
|
||||
IRDA_WARNING("IrLAN: Authentication required\n");
|
||||
break;
|
||||
case 8:
|
||||
IRDA_WARNING("IrLAN: Invalid password\n");
|
||||
break;
|
||||
case 9:
|
||||
IRDA_WARNING("IrLAN: Protocol error\n");
|
||||
break;
|
||||
case 255:
|
||||
IRDA_WARNING("IrLAN: Asynchronous status\n");
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Function irlan_client_parse_response (self, skb)
|
||||
*
|
||||
* Extract all parameters from received buffer, then feed them to
|
||||
* check_params for parsing
|
||||
*/
|
||||
void irlan_client_parse_response(struct irlan_cb *self, struct sk_buff *skb)
|
||||
{
|
||||
__u8 *frame;
|
||||
__u8 *ptr;
|
||||
int count;
|
||||
int ret;
|
||||
__u16 val_len;
|
||||
int i;
|
||||
char *name;
|
||||
char *value;
|
||||
|
||||
IRDA_ASSERT(skb != NULL, return;);
|
||||
|
||||
IRDA_DEBUG(4, "%s() skb->len=%d\n", __func__ , (int) skb->len);
|
||||
|
||||
IRDA_ASSERT(self != NULL, return;);
|
||||
IRDA_ASSERT(self->magic == IRLAN_MAGIC, return;);
|
||||
|
||||
if (!skb) {
|
||||
IRDA_ERROR("%s(), Got NULL skb!\n", __func__);
|
||||
return;
|
||||
}
|
||||
frame = skb->data;
|
||||
|
||||
/*
|
||||
* Check return code and print it if not success
|
||||
*/
|
||||
if (frame[0]) {
|
||||
print_ret_code(frame[0]);
|
||||
return;
|
||||
}
|
||||
|
||||
name = kmalloc(255, GFP_ATOMIC);
|
||||
if (!name)
|
||||
return;
|
||||
value = kmalloc(1016, GFP_ATOMIC);
|
||||
if (!value) {
|
||||
kfree(name);
|
||||
return;
|
||||
}
|
||||
|
||||
/* How many parameters? */
|
||||
count = frame[1];
|
||||
|
||||
IRDA_DEBUG(4, "%s(), got %d parameters\n", __func__ , count);
|
||||
|
||||
ptr = frame+2;
|
||||
|
||||
/* For all parameters */
|
||||
for (i=0; i<count;i++) {
|
||||
ret = irlan_extract_param(ptr, name, value, &val_len);
|
||||
if (ret < 0) {
|
||||
IRDA_DEBUG(2, "%s(), IrLAN, Error!\n", __func__ );
|
||||
break;
|
||||
}
|
||||
ptr += ret;
|
||||
irlan_check_response_param(self, name, value, val_len);
|
||||
}
|
||||
/* Cleanup */
|
||||
kfree(name);
|
||||
kfree(value);
|
||||
}
|
||||
|
||||
/*
|
||||
* Function irlan_check_response_param (self, param, value, val_len)
|
||||
*
|
||||
* Check which parameter is received and update local variables
|
||||
*
|
||||
*/
|
||||
static void irlan_check_response_param(struct irlan_cb *self, char *param,
|
||||
char *value, int val_len)
|
||||
{
|
||||
__u16 tmp_cpu; /* Temporary value in host order */
|
||||
__u8 *bytes;
|
||||
int i;
|
||||
|
||||
IRDA_DEBUG(4, "%s(), parm=%s\n", __func__ , param);
|
||||
|
||||
IRDA_ASSERT(self != NULL, return;);
|
||||
IRDA_ASSERT(self->magic == IRLAN_MAGIC, return;);
|
||||
|
||||
/* Media type */
|
||||
if (strcmp(param, "MEDIA") == 0) {
|
||||
if (strcmp(value, "802.3") == 0)
|
||||
self->media = MEDIA_802_3;
|
||||
else
|
||||
self->media = MEDIA_802_5;
|
||||
return;
|
||||
}
|
||||
if (strcmp(param, "FILTER_TYPE") == 0) {
|
||||
if (strcmp(value, "DIRECTED") == 0)
|
||||
self->client.filter_type |= IRLAN_DIRECTED;
|
||||
else if (strcmp(value, "FUNCTIONAL") == 0)
|
||||
self->client.filter_type |= IRLAN_FUNCTIONAL;
|
||||
else if (strcmp(value, "GROUP") == 0)
|
||||
self->client.filter_type |= IRLAN_GROUP;
|
||||
else if (strcmp(value, "MAC_FRAME") == 0)
|
||||
self->client.filter_type |= IRLAN_MAC_FRAME;
|
||||
else if (strcmp(value, "MULTICAST") == 0)
|
||||
self->client.filter_type |= IRLAN_MULTICAST;
|
||||
else if (strcmp(value, "BROADCAST") == 0)
|
||||
self->client.filter_type |= IRLAN_BROADCAST;
|
||||
else if (strcmp(value, "IPX_SOCKET") == 0)
|
||||
self->client.filter_type |= IRLAN_IPX_SOCKET;
|
||||
|
||||
}
|
||||
if (strcmp(param, "ACCESS_TYPE") == 0) {
|
||||
if (strcmp(value, "DIRECT") == 0)
|
||||
self->client.access_type = ACCESS_DIRECT;
|
||||
else if (strcmp(value, "PEER") == 0)
|
||||
self->client.access_type = ACCESS_PEER;
|
||||
else if (strcmp(value, "HOSTED") == 0)
|
||||
self->client.access_type = ACCESS_HOSTED;
|
||||
else {
|
||||
IRDA_DEBUG(2, "%s(), unknown access type!\n", __func__ );
|
||||
}
|
||||
}
|
||||
/* IRLAN version */
|
||||
if (strcmp(param, "IRLAN_VER") == 0) {
|
||||
IRDA_DEBUG(4, "IrLAN version %d.%d\n", (__u8) value[0],
|
||||
(__u8) value[1]);
|
||||
|
||||
self->version[0] = value[0];
|
||||
self->version[1] = value[1];
|
||||
return;
|
||||
}
|
||||
/* Which remote TSAP to use for data channel */
|
||||
if (strcmp(param, "DATA_CHAN") == 0) {
|
||||
self->dtsap_sel_data = value[0];
|
||||
IRDA_DEBUG(4, "Data TSAP = %02x\n", self->dtsap_sel_data);
|
||||
return;
|
||||
}
|
||||
if (strcmp(param, "CON_ARB") == 0) {
|
||||
memcpy(&tmp_cpu, value, 2); /* Align value */
|
||||
le16_to_cpus(&tmp_cpu); /* Convert to host order */
|
||||
self->client.recv_arb_val = tmp_cpu;
|
||||
IRDA_DEBUG(2, "%s(), receive arb val=%d\n", __func__ ,
|
||||
self->client.recv_arb_val);
|
||||
}
|
||||
if (strcmp(param, "MAX_FRAME") == 0) {
|
||||
memcpy(&tmp_cpu, value, 2); /* Align value */
|
||||
le16_to_cpus(&tmp_cpu); /* Convert to host order */
|
||||
self->client.max_frame = tmp_cpu;
|
||||
IRDA_DEBUG(4, "%s(), max frame=%d\n", __func__ ,
|
||||
self->client.max_frame);
|
||||
}
|
||||
|
||||
/* RECONNECT_KEY, in case the link goes down! */
|
||||
if (strcmp(param, "RECONNECT_KEY") == 0) {
|
||||
IRDA_DEBUG(4, "Got reconnect key: ");
|
||||
/* for (i = 0; i < val_len; i++) */
|
||||
/* printk("%02x", value[i]); */
|
||||
memcpy(self->client.reconnect_key, value, val_len);
|
||||
self->client.key_len = val_len;
|
||||
IRDA_DEBUG(4, "\n");
|
||||
}
|
||||
/* FILTER_ENTRY, have we got an ethernet address? */
|
||||
if (strcmp(param, "FILTER_ENTRY") == 0) {
|
||||
bytes = value;
|
||||
IRDA_DEBUG(4, "Ethernet address = %pM\n", bytes);
|
||||
for (i = 0; i < 6; i++)
|
||||
self->dev->dev_addr[i] = bytes[i];
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Function irlan_client_get_value_confirm (obj_id, value)
|
||||
*
|
||||
* Got results from remote LM-IAS
|
||||
*
|
||||
*/
|
||||
void irlan_client_get_value_confirm(int result, __u16 obj_id,
|
||||
struct ias_value *value, void *priv)
|
||||
{
|
||||
struct irlan_cb *self;
|
||||
|
||||
IRDA_DEBUG(4, "%s()\n", __func__ );
|
||||
|
||||
IRDA_ASSERT(priv != NULL, return;);
|
||||
|
||||
self = priv;
|
||||
IRDA_ASSERT(self->magic == IRLAN_MAGIC, return;);
|
||||
|
||||
/* We probably don't need to make any more queries */
|
||||
iriap_close(self->client.iriap);
|
||||
self->client.iriap = NULL;
|
||||
|
||||
/* Check if request succeeded */
|
||||
if (result != IAS_SUCCESS) {
|
||||
IRDA_DEBUG(2, "%s(), got NULL value!\n", __func__ );
|
||||
irlan_do_client_event(self, IRLAN_IAS_PROVIDER_NOT_AVAIL,
|
||||
NULL);
|
||||
return;
|
||||
}
|
||||
|
||||
switch (value->type) {
|
||||
case IAS_INTEGER:
|
||||
self->dtsap_sel_ctrl = value->t.integer;
|
||||
|
||||
if (value->t.integer != -1) {
|
||||
irlan_do_client_event(self, IRLAN_IAS_PROVIDER_AVAIL,
|
||||
NULL);
|
||||
return;
|
||||
}
|
||||
irias_delete_value(value);
|
||||
break;
|
||||
default:
|
||||
IRDA_DEBUG(2, "%s(), unknown type!\n", __func__ );
|
||||
break;
|
||||
}
|
||||
irlan_do_client_event(self, IRLAN_IAS_PROVIDER_NOT_AVAIL, NULL);
|
||||
}
|
533
net/irda/irlan/irlan_client_event.c
Normal file
533
net/irda/irlan/irlan_client_event.c
Normal file
|
@ -0,0 +1,533 @@
|
|||
/*********************************************************************
|
||||
*
|
||||
* Filename: irlan_client_event.c
|
||||
* Version: 0.9
|
||||
* Description: IrLAN client state machine
|
||||
* Status: Experimental.
|
||||
* Author: Dag Brattli <dagb@cs.uit.no>
|
||||
* Created at: Sun Aug 31 20:14:37 1997
|
||||
* Modified at: Sun Dec 26 21:52:24 1999
|
||||
* Modified by: Dag Brattli <dagb@cs.uit.no>
|
||||
*
|
||||
* Copyright (c) 1998-1999 Dag Brattli <dagb@cs.uit.no>,
|
||||
* All Rights Reserved.
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License as
|
||||
* published by the Free Software Foundation; either version 2 of
|
||||
* the License, or (at your option) any later version.
|
||||
*
|
||||
* Neither Dag Brattli nor University of Tromsø admit liability nor
|
||||
* provide warranty for any of this software. This material is
|
||||
* provided "AS-IS" and at no charge.
|
||||
*
|
||||
********************************************************************/
|
||||
|
||||
#include <linux/skbuff.h>
|
||||
|
||||
#include <net/irda/irda.h>
|
||||
#include <net/irda/timer.h>
|
||||
#include <net/irda/irmod.h>
|
||||
#include <net/irda/iriap.h>
|
||||
#include <net/irda/irlmp.h>
|
||||
#include <net/irda/irttp.h>
|
||||
|
||||
#include <net/irda/irlan_common.h>
|
||||
#include <net/irda/irlan_client.h>
|
||||
#include <net/irda/irlan_event.h>
|
||||
|
||||
static int irlan_client_state_idle (struct irlan_cb *self, IRLAN_EVENT event,
|
||||
struct sk_buff *skb);
|
||||
static int irlan_client_state_query(struct irlan_cb *self, IRLAN_EVENT event,
|
||||
struct sk_buff *skb);
|
||||
static int irlan_client_state_conn (struct irlan_cb *self, IRLAN_EVENT event,
|
||||
struct sk_buff *skb);
|
||||
static int irlan_client_state_info (struct irlan_cb *self, IRLAN_EVENT event,
|
||||
struct sk_buff *skb);
|
||||
static int irlan_client_state_media(struct irlan_cb *self, IRLAN_EVENT event,
|
||||
struct sk_buff *skb);
|
||||
static int irlan_client_state_open (struct irlan_cb *self, IRLAN_EVENT event,
|
||||
struct sk_buff *skb);
|
||||
static int irlan_client_state_wait (struct irlan_cb *self, IRLAN_EVENT event,
|
||||
struct sk_buff *skb);
|
||||
static int irlan_client_state_arb (struct irlan_cb *self, IRLAN_EVENT event,
|
||||
struct sk_buff *skb);
|
||||
static int irlan_client_state_data (struct irlan_cb *self, IRLAN_EVENT event,
|
||||
struct sk_buff *skb);
|
||||
static int irlan_client_state_close(struct irlan_cb *self, IRLAN_EVENT event,
|
||||
struct sk_buff *skb);
|
||||
static int irlan_client_state_sync (struct irlan_cb *self, IRLAN_EVENT event,
|
||||
struct sk_buff *skb);
|
||||
|
||||
static int (*state[])(struct irlan_cb *, IRLAN_EVENT event, struct sk_buff *) =
|
||||
{
|
||||
irlan_client_state_idle,
|
||||
irlan_client_state_query,
|
||||
irlan_client_state_conn,
|
||||
irlan_client_state_info,
|
||||
irlan_client_state_media,
|
||||
irlan_client_state_open,
|
||||
irlan_client_state_wait,
|
||||
irlan_client_state_arb,
|
||||
irlan_client_state_data,
|
||||
irlan_client_state_close,
|
||||
irlan_client_state_sync
|
||||
};
|
||||
|
||||
void irlan_do_client_event(struct irlan_cb *self, IRLAN_EVENT event,
|
||||
struct sk_buff *skb)
|
||||
{
|
||||
IRDA_ASSERT(self != NULL, return;);
|
||||
IRDA_ASSERT(self->magic == IRLAN_MAGIC, return;);
|
||||
|
||||
(*state[ self->client.state]) (self, event, skb);
|
||||
}
|
||||
|
||||
/*
|
||||
* Function irlan_client_state_idle (event, skb, info)
|
||||
*
|
||||
* IDLE, We are waiting for an indication that there is a provider
|
||||
* available.
|
||||
*/
|
||||
static int irlan_client_state_idle(struct irlan_cb *self, IRLAN_EVENT event,
|
||||
struct sk_buff *skb)
|
||||
{
|
||||
IRDA_DEBUG(4, "%s()\n", __func__ );
|
||||
|
||||
IRDA_ASSERT(self != NULL, return -1;);
|
||||
IRDA_ASSERT(self->magic == IRLAN_MAGIC, return -1;);
|
||||
|
||||
switch (event) {
|
||||
case IRLAN_DISCOVERY_INDICATION:
|
||||
if (self->client.iriap) {
|
||||
IRDA_WARNING("%s(), busy with a previous query\n",
|
||||
__func__);
|
||||
return -EBUSY;
|
||||
}
|
||||
|
||||
self->client.iriap = iriap_open(LSAP_ANY, IAS_CLIENT, self,
|
||||
irlan_client_get_value_confirm);
|
||||
/* Get some values from peer IAS */
|
||||
irlan_next_client_state(self, IRLAN_QUERY);
|
||||
iriap_getvaluebyclass_request(self->client.iriap,
|
||||
self->saddr, self->daddr,
|
||||
"IrLAN", "IrDA:TinyTP:LsapSel");
|
||||
break;
|
||||
case IRLAN_WATCHDOG_TIMEOUT:
|
||||
IRDA_DEBUG(2, "%s(), IRLAN_WATCHDOG_TIMEOUT\n", __func__ );
|
||||
break;
|
||||
default:
|
||||
IRDA_DEBUG(4, "%s(), Unknown event %d\n", __func__ , event);
|
||||
break;
|
||||
}
|
||||
if (skb)
|
||||
dev_kfree_skb(skb);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*
|
||||
* Function irlan_client_state_query (event, skb, info)
|
||||
*
|
||||
* QUERY, We have queryed the remote IAS and is ready to connect
|
||||
* to provider, just waiting for the confirm.
|
||||
*
|
||||
*/
|
||||
static int irlan_client_state_query(struct irlan_cb *self, IRLAN_EVENT event,
|
||||
struct sk_buff *skb)
|
||||
{
|
||||
IRDA_DEBUG(4, "%s()\n", __func__ );
|
||||
|
||||
IRDA_ASSERT(self != NULL, return -1;);
|
||||
IRDA_ASSERT(self->magic == IRLAN_MAGIC, return -1;);
|
||||
|
||||
switch(event) {
|
||||
case IRLAN_IAS_PROVIDER_AVAIL:
|
||||
IRDA_ASSERT(self->dtsap_sel_ctrl != 0, return -1;);
|
||||
|
||||
self->client.open_retries = 0;
|
||||
|
||||
irttp_connect_request(self->client.tsap_ctrl,
|
||||
self->dtsap_sel_ctrl,
|
||||
self->saddr, self->daddr, NULL,
|
||||
IRLAN_MTU, NULL);
|
||||
irlan_next_client_state(self, IRLAN_CONN);
|
||||
break;
|
||||
case IRLAN_IAS_PROVIDER_NOT_AVAIL:
|
||||
IRDA_DEBUG(2, "%s(), IAS_PROVIDER_NOT_AVAIL\n", __func__ );
|
||||
irlan_next_client_state(self, IRLAN_IDLE);
|
||||
|
||||
/* Give the client a kick! */
|
||||
if ((self->provider.access_type == ACCESS_PEER) &&
|
||||
(self->provider.state != IRLAN_IDLE))
|
||||
irlan_client_wakeup(self, self->saddr, self->daddr);
|
||||
break;
|
||||
case IRLAN_LMP_DISCONNECT:
|
||||
case IRLAN_LAP_DISCONNECT:
|
||||
irlan_next_client_state(self, IRLAN_IDLE);
|
||||
break;
|
||||
case IRLAN_WATCHDOG_TIMEOUT:
|
||||
IRDA_DEBUG(2, "%s(), IRLAN_WATCHDOG_TIMEOUT\n", __func__ );
|
||||
break;
|
||||
default:
|
||||
IRDA_DEBUG(2, "%s(), Unknown event %d\n", __func__ , event);
|
||||
break;
|
||||
}
|
||||
if (skb)
|
||||
dev_kfree_skb(skb);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*
|
||||
* Function irlan_client_state_conn (event, skb, info)
|
||||
*
|
||||
* CONN, We have connected to a provider but has not issued any
|
||||
* commands yet.
|
||||
*
|
||||
*/
|
||||
static int irlan_client_state_conn(struct irlan_cb *self, IRLAN_EVENT event,
|
||||
struct sk_buff *skb)
|
||||
{
|
||||
IRDA_DEBUG(4, "%s()\n", __func__ );
|
||||
|
||||
IRDA_ASSERT(self != NULL, return -1;);
|
||||
|
||||
switch (event) {
|
||||
case IRLAN_CONNECT_COMPLETE:
|
||||
/* Send getinfo cmd */
|
||||
irlan_get_provider_info(self);
|
||||
irlan_next_client_state(self, IRLAN_INFO);
|
||||
break;
|
||||
case IRLAN_LMP_DISCONNECT:
|
||||
case IRLAN_LAP_DISCONNECT:
|
||||
irlan_next_client_state(self, IRLAN_IDLE);
|
||||
break;
|
||||
case IRLAN_WATCHDOG_TIMEOUT:
|
||||
IRDA_DEBUG(2, "%s(), IRLAN_WATCHDOG_TIMEOUT\n", __func__ );
|
||||
break;
|
||||
default:
|
||||
IRDA_DEBUG(2, "%s(), Unknown event %d\n", __func__ , event);
|
||||
break;
|
||||
}
|
||||
if (skb)
|
||||
dev_kfree_skb(skb);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*
|
||||
* Function irlan_client_state_info (self, event, skb, info)
|
||||
*
|
||||
* INFO, We have issued a GetInfo command and is awaiting a reply.
|
||||
*/
|
||||
static int irlan_client_state_info(struct irlan_cb *self, IRLAN_EVENT event,
|
||||
struct sk_buff *skb)
|
||||
{
|
||||
IRDA_DEBUG(4, "%s()\n", __func__ );
|
||||
|
||||
IRDA_ASSERT(self != NULL, return -1;);
|
||||
|
||||
switch (event) {
|
||||
case IRLAN_DATA_INDICATION:
|
||||
IRDA_ASSERT(skb != NULL, return -1;);
|
||||
|
||||
irlan_client_parse_response(self, skb);
|
||||
|
||||
irlan_next_client_state(self, IRLAN_MEDIA);
|
||||
|
||||
irlan_get_media_char(self);
|
||||
break;
|
||||
|
||||
case IRLAN_LMP_DISCONNECT:
|
||||
case IRLAN_LAP_DISCONNECT:
|
||||
irlan_next_client_state(self, IRLAN_IDLE);
|
||||
break;
|
||||
case IRLAN_WATCHDOG_TIMEOUT:
|
||||
IRDA_DEBUG(2, "%s(), IRLAN_WATCHDOG_TIMEOUT\n", __func__ );
|
||||
break;
|
||||
default:
|
||||
IRDA_DEBUG(2, "%s(), Unknown event %d\n", __func__ , event);
|
||||
break;
|
||||
}
|
||||
if (skb)
|
||||
dev_kfree_skb(skb);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*
|
||||
* Function irlan_client_state_media (self, event, skb, info)
|
||||
*
|
||||
* MEDIA, The irlan_client has issued a GetMedia command and is awaiting a
|
||||
* reply.
|
||||
*
|
||||
*/
|
||||
static int irlan_client_state_media(struct irlan_cb *self, IRLAN_EVENT event,
|
||||
struct sk_buff *skb)
|
||||
{
|
||||
IRDA_DEBUG(4, "%s()\n", __func__ );
|
||||
|
||||
IRDA_ASSERT(self != NULL, return -1;);
|
||||
|
||||
switch(event) {
|
||||
case IRLAN_DATA_INDICATION:
|
||||
irlan_client_parse_response(self, skb);
|
||||
irlan_open_data_channel(self);
|
||||
irlan_next_client_state(self, IRLAN_OPEN);
|
||||
break;
|
||||
case IRLAN_LMP_DISCONNECT:
|
||||
case IRLAN_LAP_DISCONNECT:
|
||||
irlan_next_client_state(self, IRLAN_IDLE);
|
||||
break;
|
||||
case IRLAN_WATCHDOG_TIMEOUT:
|
||||
IRDA_DEBUG(2, "%s(), IRLAN_WATCHDOG_TIMEOUT\n", __func__ );
|
||||
break;
|
||||
default:
|
||||
IRDA_DEBUG(2, "%s(), Unknown event %d\n", __func__ , event);
|
||||
break;
|
||||
}
|
||||
if (skb)
|
||||
dev_kfree_skb(skb);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*
|
||||
* Function irlan_client_state_open (self, event, skb, info)
|
||||
*
|
||||
* OPEN, The irlan_client has issued a OpenData command and is awaiting a
|
||||
* reply
|
||||
*
|
||||
*/
|
||||
static int irlan_client_state_open(struct irlan_cb *self, IRLAN_EVENT event,
|
||||
struct sk_buff *skb)
|
||||
{
|
||||
struct qos_info qos;
|
||||
|
||||
IRDA_DEBUG(4, "%s()\n", __func__ );
|
||||
|
||||
IRDA_ASSERT(self != NULL, return -1;);
|
||||
|
||||
switch(event) {
|
||||
case IRLAN_DATA_INDICATION:
|
||||
irlan_client_parse_response(self, skb);
|
||||
|
||||
/*
|
||||
* Check if we have got the remote TSAP for data
|
||||
* communications
|
||||
*/
|
||||
IRDA_ASSERT(self->dtsap_sel_data != 0, return -1;);
|
||||
|
||||
/* Check which access type we are dealing with */
|
||||
switch (self->client.access_type) {
|
||||
case ACCESS_PEER:
|
||||
if (self->provider.state == IRLAN_OPEN) {
|
||||
|
||||
irlan_next_client_state(self, IRLAN_ARB);
|
||||
irlan_do_client_event(self, IRLAN_CHECK_CON_ARB,
|
||||
NULL);
|
||||
} else {
|
||||
|
||||
irlan_next_client_state(self, IRLAN_WAIT);
|
||||
}
|
||||
break;
|
||||
case ACCESS_DIRECT:
|
||||
case ACCESS_HOSTED:
|
||||
qos.link_disc_time.bits = 0x01; /* 3 secs */
|
||||
|
||||
irttp_connect_request(self->tsap_data,
|
||||
self->dtsap_sel_data,
|
||||
self->saddr, self->daddr, &qos,
|
||||
IRLAN_MTU, NULL);
|
||||
|
||||
irlan_next_client_state(self, IRLAN_DATA);
|
||||
break;
|
||||
default:
|
||||
IRDA_DEBUG(2, "%s(), unknown access type!\n", __func__ );
|
||||
break;
|
||||
}
|
||||
break;
|
||||
case IRLAN_LMP_DISCONNECT:
|
||||
case IRLAN_LAP_DISCONNECT:
|
||||
irlan_next_client_state(self, IRLAN_IDLE);
|
||||
break;
|
||||
case IRLAN_WATCHDOG_TIMEOUT:
|
||||
IRDA_DEBUG(2, "%s(), IRLAN_WATCHDOG_TIMEOUT\n", __func__ );
|
||||
break;
|
||||
default:
|
||||
IRDA_DEBUG(2, "%s(), Unknown event %d\n", __func__ , event);
|
||||
break;
|
||||
}
|
||||
|
||||
if (skb)
|
||||
dev_kfree_skb(skb);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*
|
||||
* Function irlan_client_state_wait (self, event, skb, info)
|
||||
*
|
||||
* WAIT, The irlan_client is waiting for the local provider to enter the
|
||||
* provider OPEN state.
|
||||
*
|
||||
*/
|
||||
static int irlan_client_state_wait(struct irlan_cb *self, IRLAN_EVENT event,
|
||||
struct sk_buff *skb)
|
||||
{
|
||||
IRDA_DEBUG(4, "%s()\n", __func__ );
|
||||
|
||||
IRDA_ASSERT(self != NULL, return -1;);
|
||||
|
||||
switch(event) {
|
||||
case IRLAN_PROVIDER_SIGNAL:
|
||||
irlan_next_client_state(self, IRLAN_ARB);
|
||||
irlan_do_client_event(self, IRLAN_CHECK_CON_ARB, NULL);
|
||||
break;
|
||||
case IRLAN_LMP_DISCONNECT:
|
||||
case IRLAN_LAP_DISCONNECT:
|
||||
irlan_next_client_state(self, IRLAN_IDLE);
|
||||
break;
|
||||
case IRLAN_WATCHDOG_TIMEOUT:
|
||||
IRDA_DEBUG(2, "%s(), IRLAN_WATCHDOG_TIMEOUT\n", __func__ );
|
||||
break;
|
||||
default:
|
||||
IRDA_DEBUG(2, "%s(), Unknown event %d\n", __func__ , event);
|
||||
break;
|
||||
}
|
||||
if (skb)
|
||||
dev_kfree_skb(skb);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int irlan_client_state_arb(struct irlan_cb *self, IRLAN_EVENT event,
|
||||
struct sk_buff *skb)
|
||||
{
|
||||
struct qos_info qos;
|
||||
|
||||
IRDA_DEBUG(2, "%s()\n", __func__ );
|
||||
|
||||
IRDA_ASSERT(self != NULL, return -1;);
|
||||
|
||||
switch(event) {
|
||||
case IRLAN_CHECK_CON_ARB:
|
||||
if (self->client.recv_arb_val == self->provider.send_arb_val) {
|
||||
irlan_next_client_state(self, IRLAN_CLOSE);
|
||||
irlan_close_data_channel(self);
|
||||
} else if (self->client.recv_arb_val <
|
||||
self->provider.send_arb_val)
|
||||
{
|
||||
qos.link_disc_time.bits = 0x01; /* 3 secs */
|
||||
|
||||
irlan_next_client_state(self, IRLAN_DATA);
|
||||
irttp_connect_request(self->tsap_data,
|
||||
self->dtsap_sel_data,
|
||||
self->saddr, self->daddr, &qos,
|
||||
IRLAN_MTU, NULL);
|
||||
} else if (self->client.recv_arb_val >
|
||||
self->provider.send_arb_val)
|
||||
{
|
||||
IRDA_DEBUG(2, "%s(), lost the battle :-(\n", __func__ );
|
||||
}
|
||||
break;
|
||||
case IRLAN_DATA_CONNECT_INDICATION:
|
||||
irlan_next_client_state(self, IRLAN_DATA);
|
||||
break;
|
||||
case IRLAN_LMP_DISCONNECT:
|
||||
case IRLAN_LAP_DISCONNECT:
|
||||
irlan_next_client_state(self, IRLAN_IDLE);
|
||||
break;
|
||||
case IRLAN_WATCHDOG_TIMEOUT:
|
||||
IRDA_DEBUG(2, "%s(), IRLAN_WATCHDOG_TIMEOUT\n", __func__ );
|
||||
break;
|
||||
default:
|
||||
IRDA_DEBUG(2, "%s(), Unknown event %d\n", __func__ , event);
|
||||
break;
|
||||
}
|
||||
if (skb)
|
||||
dev_kfree_skb(skb);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*
|
||||
* Function irlan_client_state_data (self, event, skb, info)
|
||||
*
|
||||
* DATA, The data channel is connected, allowing data transfers between
|
||||
* the local and remote machines.
|
||||
*
|
||||
*/
|
||||
static int irlan_client_state_data(struct irlan_cb *self, IRLAN_EVENT event,
|
||||
struct sk_buff *skb)
|
||||
{
|
||||
IRDA_DEBUG(4, "%s()\n", __func__ );
|
||||
|
||||
IRDA_ASSERT(self != NULL, return -1;);
|
||||
IRDA_ASSERT(self->magic == IRLAN_MAGIC, return -1;);
|
||||
|
||||
switch(event) {
|
||||
case IRLAN_DATA_INDICATION:
|
||||
irlan_client_parse_response(self, skb);
|
||||
break;
|
||||
case IRLAN_LMP_DISCONNECT: /* FALLTHROUGH */
|
||||
case IRLAN_LAP_DISCONNECT:
|
||||
irlan_next_client_state(self, IRLAN_IDLE);
|
||||
break;
|
||||
default:
|
||||
IRDA_DEBUG(2, "%s(), Unknown event %d\n", __func__ , event);
|
||||
break;
|
||||
}
|
||||
if (skb)
|
||||
dev_kfree_skb(skb);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*
|
||||
* Function irlan_client_state_close (self, event, skb, info)
|
||||
*
|
||||
*
|
||||
*
|
||||
*/
|
||||
static int irlan_client_state_close(struct irlan_cb *self, IRLAN_EVENT event,
|
||||
struct sk_buff *skb)
|
||||
{
|
||||
IRDA_DEBUG(2, "%s()\n", __func__ );
|
||||
|
||||
if (skb)
|
||||
dev_kfree_skb(skb);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*
|
||||
* Function irlan_client_state_sync (self, event, skb, info)
|
||||
*
|
||||
*
|
||||
*
|
||||
*/
|
||||
static int irlan_client_state_sync(struct irlan_cb *self, IRLAN_EVENT event,
|
||||
struct sk_buff *skb)
|
||||
{
|
||||
IRDA_DEBUG(2, "%s()\n", __func__ );
|
||||
|
||||
if (skb)
|
||||
dev_kfree_skb(skb);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
1212
net/irda/irlan/irlan_common.c
Normal file
1212
net/irda/irlan/irlan_common.c
Normal file
File diff suppressed because it is too large
Load diff
346
net/irda/irlan/irlan_eth.c
Normal file
346
net/irda/irlan/irlan_eth.c
Normal file
|
@ -0,0 +1,346 @@
|
|||
/*********************************************************************
|
||||
*
|
||||
* Filename: irlan_eth.c
|
||||
* Version:
|
||||
* Description:
|
||||
* Status: Experimental.
|
||||
* Author: Dag Brattli <dagb@cs.uit.no>
|
||||
* Created at: Thu Oct 15 08:37:58 1998
|
||||
* Modified at: Tue Mar 21 09:06:41 2000
|
||||
* Modified by: Dag Brattli <dagb@cs.uit.no>
|
||||
* Sources: skeleton.c by Donald Becker <becker@CESDIS.gsfc.nasa.gov>
|
||||
* slip.c by Laurence Culhane, <loz@holmes.demon.co.uk>
|
||||
* Fred N. van Kempen, <waltje@uwalt.nl.mugnet.org>
|
||||
*
|
||||
* Copyright (c) 1998-2000 Dag Brattli, All Rights Reserved.
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License as
|
||||
* published by the Free Software Foundation; either version 2 of
|
||||
* the License, or (at your option) any later version.
|
||||
*
|
||||
* Neither Dag Brattli nor University of Tromsø admit liability nor
|
||||
* provide warranty for any of this software. This material is
|
||||
* provided "AS-IS" and at no charge.
|
||||
*
|
||||
********************************************************************/
|
||||
|
||||
#include <linux/netdevice.h>
|
||||
#include <linux/etherdevice.h>
|
||||
#include <linux/inetdevice.h>
|
||||
#include <linux/if_arp.h>
|
||||
#include <linux/module.h>
|
||||
#include <linux/sched.h>
|
||||
#include <net/arp.h>
|
||||
|
||||
#include <net/irda/irda.h>
|
||||
#include <net/irda/irmod.h>
|
||||
#include <net/irda/irlan_common.h>
|
||||
#include <net/irda/irlan_client.h>
|
||||
#include <net/irda/irlan_event.h>
|
||||
#include <net/irda/irlan_eth.h>
|
||||
|
||||
static int irlan_eth_open(struct net_device *dev);
|
||||
static int irlan_eth_close(struct net_device *dev);
|
||||
static netdev_tx_t irlan_eth_xmit(struct sk_buff *skb,
|
||||
struct net_device *dev);
|
||||
static void irlan_eth_set_multicast_list(struct net_device *dev);
|
||||
|
||||
static const struct net_device_ops irlan_eth_netdev_ops = {
|
||||
.ndo_open = irlan_eth_open,
|
||||
.ndo_stop = irlan_eth_close,
|
||||
.ndo_start_xmit = irlan_eth_xmit,
|
||||
.ndo_set_rx_mode = irlan_eth_set_multicast_list,
|
||||
.ndo_change_mtu = eth_change_mtu,
|
||||
.ndo_validate_addr = eth_validate_addr,
|
||||
};
|
||||
|
||||
/*
|
||||
* Function irlan_eth_setup (dev)
|
||||
*
|
||||
* The network device initialization function.
|
||||
*
|
||||
*/
|
||||
static void irlan_eth_setup(struct net_device *dev)
|
||||
{
|
||||
ether_setup(dev);
|
||||
|
||||
dev->netdev_ops = &irlan_eth_netdev_ops;
|
||||
dev->destructor = free_netdev;
|
||||
|
||||
|
||||
/*
|
||||
* Lets do all queueing in IrTTP instead of this device driver.
|
||||
* Queueing here as well can introduce some strange latency
|
||||
* problems, which we will avoid by setting the queue size to 0.
|
||||
*/
|
||||
/*
|
||||
* The bugs in IrTTP and IrLAN that created this latency issue
|
||||
* have now been fixed, and we can propagate flow control properly
|
||||
* to the network layer. However, this requires a minimal queue of
|
||||
* packets for the device.
|
||||
* Without flow control, the Tx Queue is 14 (ttp) + 0 (dev) = 14
|
||||
* With flow control, the Tx Queue is 7 (ttp) + 4 (dev) = 11
|
||||
* See irlan_eth_flow_indication()...
|
||||
* Note : this number was randomly selected and would need to
|
||||
* be adjusted.
|
||||
* Jean II */
|
||||
dev->tx_queue_len = 4;
|
||||
}
|
||||
|
||||
/*
|
||||
* Function alloc_irlandev
|
||||
*
|
||||
* Allocate network device and control block
|
||||
*
|
||||
*/
|
||||
struct net_device *alloc_irlandev(const char *name)
|
||||
{
|
||||
return alloc_netdev(sizeof(struct irlan_cb), name, NET_NAME_UNKNOWN,
|
||||
irlan_eth_setup);
|
||||
}
|
||||
|
||||
/*
|
||||
* Function irlan_eth_open (dev)
|
||||
*
|
||||
* Network device has been opened by user
|
||||
*
|
||||
*/
|
||||
static int irlan_eth_open(struct net_device *dev)
|
||||
{
|
||||
struct irlan_cb *self = netdev_priv(dev);
|
||||
|
||||
IRDA_DEBUG(2, "%s()\n", __func__);
|
||||
|
||||
/* Ready to play! */
|
||||
netif_stop_queue(dev); /* Wait until data link is ready */
|
||||
|
||||
/* We are now open, so time to do some work */
|
||||
self->disconnect_reason = 0;
|
||||
irlan_client_wakeup(self, self->saddr, self->daddr);
|
||||
|
||||
/* Make sure we have a hardware address before we return,
|
||||
so DHCP clients gets happy */
|
||||
return wait_event_interruptible(self->open_wait,
|
||||
!self->tsap_data->connected);
|
||||
}
|
||||
|
||||
/*
|
||||
* Function irlan_eth_close (dev)
|
||||
*
|
||||
* Stop the ether network device, his function will usually be called by
|
||||
* ifconfig down. We should now disconnect the link, We start the
|
||||
* close timer, so that the instance will be removed if we are unable
|
||||
* to discover the remote device after the disconnect.
|
||||
*/
|
||||
static int irlan_eth_close(struct net_device *dev)
|
||||
{
|
||||
struct irlan_cb *self = netdev_priv(dev);
|
||||
|
||||
IRDA_DEBUG(2, "%s()\n", __func__);
|
||||
|
||||
/* Stop device */
|
||||
netif_stop_queue(dev);
|
||||
|
||||
irlan_close_data_channel(self);
|
||||
irlan_close_tsaps(self);
|
||||
|
||||
irlan_do_client_event(self, IRLAN_LMP_DISCONNECT, NULL);
|
||||
irlan_do_provider_event(self, IRLAN_LMP_DISCONNECT, NULL);
|
||||
|
||||
/* Remove frames queued on the control channel */
|
||||
skb_queue_purge(&self->client.txq);
|
||||
|
||||
self->client.tx_busy = 0;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*
|
||||
* Function irlan_eth_tx (skb)
|
||||
*
|
||||
* Transmits ethernet frames over IrDA link.
|
||||
*
|
||||
*/
|
||||
static netdev_tx_t irlan_eth_xmit(struct sk_buff *skb,
|
||||
struct net_device *dev)
|
||||
{
|
||||
struct irlan_cb *self = netdev_priv(dev);
|
||||
int ret;
|
||||
unsigned int len;
|
||||
|
||||
/* skb headroom large enough to contain all IrDA-headers? */
|
||||
if ((skb_headroom(skb) < self->max_header_size) || (skb_shared(skb))) {
|
||||
struct sk_buff *new_skb =
|
||||
skb_realloc_headroom(skb, self->max_header_size);
|
||||
|
||||
/* We have to free the original skb anyway */
|
||||
dev_kfree_skb(skb);
|
||||
|
||||
/* Did the realloc succeed? */
|
||||
if (new_skb == NULL)
|
||||
return NETDEV_TX_OK;
|
||||
|
||||
/* Use the new skb instead */
|
||||
skb = new_skb;
|
||||
}
|
||||
|
||||
dev->trans_start = jiffies;
|
||||
|
||||
len = skb->len;
|
||||
/* Now queue the packet in the transport layer */
|
||||
if (self->use_udata)
|
||||
ret = irttp_udata_request(self->tsap_data, skb);
|
||||
else
|
||||
ret = irttp_data_request(self->tsap_data, skb);
|
||||
|
||||
if (ret < 0) {
|
||||
/*
|
||||
* IrTTPs tx queue is full, so we just have to
|
||||
* drop the frame! You might think that we should
|
||||
* just return -1 and don't deallocate the frame,
|
||||
* but that is dangerous since it's possible that
|
||||
* we have replaced the original skb with a new
|
||||
* one with larger headroom, and that would really
|
||||
* confuse do_dev_queue_xmit() in dev.c! I have
|
||||
* tried :-) DB
|
||||
*/
|
||||
/* irttp_data_request already free the packet */
|
||||
dev->stats.tx_dropped++;
|
||||
} else {
|
||||
dev->stats.tx_packets++;
|
||||
dev->stats.tx_bytes += len;
|
||||
}
|
||||
|
||||
return NETDEV_TX_OK;
|
||||
}
|
||||
|
||||
/*
|
||||
* Function irlan_eth_receive (handle, skb)
|
||||
*
|
||||
* This function gets the data that is received on the data channel
|
||||
*
|
||||
*/
|
||||
int irlan_eth_receive(void *instance, void *sap, struct sk_buff *skb)
|
||||
{
|
||||
struct irlan_cb *self = instance;
|
||||
struct net_device *dev = self->dev;
|
||||
|
||||
if (skb == NULL) {
|
||||
dev->stats.rx_dropped++;
|
||||
return 0;
|
||||
}
|
||||
if (skb->len < ETH_HLEN) {
|
||||
IRDA_DEBUG(0, "%s() : IrLAN frame too short (%d)\n",
|
||||
__func__, skb->len);
|
||||
dev->stats.rx_dropped++;
|
||||
dev_kfree_skb(skb);
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*
|
||||
* Adopt this frame! Important to set all these fields since they
|
||||
* might have been previously set by the low level IrDA network
|
||||
* device driver
|
||||
*/
|
||||
skb->protocol = eth_type_trans(skb, dev); /* Remove eth header */
|
||||
|
||||
dev->stats.rx_packets++;
|
||||
dev->stats.rx_bytes += skb->len;
|
||||
|
||||
netif_rx(skb); /* Eat it! */
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*
|
||||
* Function irlan_eth_flow (status)
|
||||
*
|
||||
* Do flow control between IP/Ethernet and IrLAN/IrTTP. This is done by
|
||||
* controlling the queue stop/start.
|
||||
*
|
||||
* The IrDA link layer has the advantage to have flow control, and
|
||||
* IrTTP now properly handles that. Flow controlling the higher layers
|
||||
* prevent us to drop Tx packets in here (up to 15% for a TCP socket,
|
||||
* more for UDP socket).
|
||||
* Also, this allow us to reduce the overall transmit queue, which means
|
||||
* less latency in case of mixed traffic.
|
||||
* Jean II
|
||||
*/
|
||||
void irlan_eth_flow_indication(void *instance, void *sap, LOCAL_FLOW flow)
|
||||
{
|
||||
struct irlan_cb *self;
|
||||
struct net_device *dev;
|
||||
|
||||
self = instance;
|
||||
|
||||
IRDA_ASSERT(self != NULL, return;);
|
||||
IRDA_ASSERT(self->magic == IRLAN_MAGIC, return;);
|
||||
|
||||
dev = self->dev;
|
||||
|
||||
IRDA_ASSERT(dev != NULL, return;);
|
||||
|
||||
IRDA_DEBUG(0, "%s() : flow %s ; running %d\n", __func__,
|
||||
flow == FLOW_STOP ? "FLOW_STOP" : "FLOW_START",
|
||||
netif_running(dev));
|
||||
|
||||
switch (flow) {
|
||||
case FLOW_STOP:
|
||||
/* IrTTP is full, stop higher layers */
|
||||
netif_stop_queue(dev);
|
||||
break;
|
||||
case FLOW_START:
|
||||
default:
|
||||
/* Tell upper layers that its time to transmit frames again */
|
||||
/* Schedule network layer */
|
||||
netif_wake_queue(dev);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Function set_multicast_list (dev)
|
||||
*
|
||||
* Configure the filtering of the device
|
||||
*
|
||||
*/
|
||||
#define HW_MAX_ADDRS 4 /* Must query to get it! */
|
||||
static void irlan_eth_set_multicast_list(struct net_device *dev)
|
||||
{
|
||||
struct irlan_cb *self = netdev_priv(dev);
|
||||
|
||||
IRDA_DEBUG(2, "%s()\n", __func__);
|
||||
|
||||
/* Check if data channel has been connected yet */
|
||||
if (self->client.state != IRLAN_DATA) {
|
||||
IRDA_DEBUG(1, "%s(), delaying!\n", __func__);
|
||||
return;
|
||||
}
|
||||
|
||||
if (dev->flags & IFF_PROMISC) {
|
||||
/* Enable promiscuous mode */
|
||||
IRDA_WARNING("Promiscuous mode not implemented by IrLAN!\n");
|
||||
} else if ((dev->flags & IFF_ALLMULTI) ||
|
||||
netdev_mc_count(dev) > HW_MAX_ADDRS) {
|
||||
/* Disable promiscuous mode, use normal mode. */
|
||||
IRDA_DEBUG(4, "%s(), Setting multicast filter\n", __func__);
|
||||
/* hardware_set_filter(NULL); */
|
||||
|
||||
irlan_set_multicast_filter(self, TRUE);
|
||||
} else if (!netdev_mc_empty(dev)) {
|
||||
IRDA_DEBUG(4, "%s(), Setting multicast filter\n", __func__);
|
||||
/* Walk the address list, and load the filter */
|
||||
/* hardware_set_filter(dev->mc_list); */
|
||||
|
||||
irlan_set_multicast_filter(self, TRUE);
|
||||
} else {
|
||||
IRDA_DEBUG(4, "%s(), Clearing multicast filter\n", __func__);
|
||||
irlan_set_multicast_filter(self, FALSE);
|
||||
}
|
||||
|
||||
if (dev->flags & IFF_BROADCAST)
|
||||
irlan_set_broadcast_filter(self, TRUE);
|
||||
else
|
||||
irlan_set_broadcast_filter(self, FALSE);
|
||||
}
|
60
net/irda/irlan/irlan_event.c
Normal file
60
net/irda/irlan/irlan_event.c
Normal file
|
@ -0,0 +1,60 @@
|
|||
/*********************************************************************
|
||||
*
|
||||
* Filename: irlan_event.c
|
||||
* Version:
|
||||
* Description:
|
||||
* Status: Experimental.
|
||||
* Author: Dag Brattli <dagb@cs.uit.no>
|
||||
* Created at: Tue Oct 20 09:10:16 1998
|
||||
* Modified at: Sat Oct 30 12:59:01 1999
|
||||
* Modified by: Dag Brattli <dagb@cs.uit.no>
|
||||
*
|
||||
* Copyright (c) 1998-1999 Dag Brattli, All Rights Reserved.
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License as
|
||||
* published by the Free Software Foundation; either version 2 of
|
||||
* the License, or (at your option) any later version.
|
||||
*
|
||||
* Neither Dag Brattli nor University of Tromsø admit liability nor
|
||||
* provide warranty for any of this software. This material is
|
||||
* provided "AS-IS" and at no charge.
|
||||
*
|
||||
********************************************************************/
|
||||
|
||||
#include <net/irda/irlan_event.h>
|
||||
|
||||
const char * const irlan_state[] = {
|
||||
"IRLAN_IDLE",
|
||||
"IRLAN_QUERY",
|
||||
"IRLAN_CONN",
|
||||
"IRLAN_INFO",
|
||||
"IRLAN_MEDIA",
|
||||
"IRLAN_OPEN",
|
||||
"IRLAN_WAIT",
|
||||
"IRLAN_ARB",
|
||||
"IRLAN_DATA",
|
||||
"IRLAN_CLOSE",
|
||||
"IRLAN_SYNC",
|
||||
};
|
||||
|
||||
void irlan_next_client_state(struct irlan_cb *self, IRLAN_STATE state)
|
||||
{
|
||||
IRDA_DEBUG(2, "%s(), %s\n", __func__ , irlan_state[state]);
|
||||
|
||||
IRDA_ASSERT(self != NULL, return;);
|
||||
IRDA_ASSERT(self->magic == IRLAN_MAGIC, return;);
|
||||
|
||||
self->client.state = state;
|
||||
}
|
||||
|
||||
void irlan_next_provider_state(struct irlan_cb *self, IRLAN_STATE state)
|
||||
{
|
||||
IRDA_DEBUG(2, "%s(), %s\n", __func__ , irlan_state[state]);
|
||||
|
||||
IRDA_ASSERT(self != NULL, return;);
|
||||
IRDA_ASSERT(self->magic == IRLAN_MAGIC, return;);
|
||||
|
||||
self->provider.state = state;
|
||||
}
|
||||
|
243
net/irda/irlan/irlan_filter.c
Normal file
243
net/irda/irlan/irlan_filter.c
Normal file
|
@ -0,0 +1,243 @@
|
|||
/*********************************************************************
|
||||
*
|
||||
* Filename: irlan_filter.c
|
||||
* Version:
|
||||
* Description:
|
||||
* Status: Experimental.
|
||||
* Author: Dag Brattli <dagb@cs.uit.no>
|
||||
* Created at: Fri Jan 29 11:16:38 1999
|
||||
* Modified at: Sat Oct 30 12:58:45 1999
|
||||
* Modified by: Dag Brattli <dagb@cs.uit.no>
|
||||
*
|
||||
* Copyright (c) 1998-1999 Dag Brattli, All Rights Reserved.
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License as
|
||||
* published by the Free Software Foundation; either version 2 of
|
||||
* the License, or (at your option) any later version.
|
||||
*
|
||||
* Neither Dag Brattli nor University of Tromsø admit liability nor
|
||||
* provide warranty for any of this software. This material is
|
||||
* provided "AS-IS" and at no charge.
|
||||
*
|
||||
********************************************************************/
|
||||
|
||||
#include <linux/skbuff.h>
|
||||
#include <linux/random.h>
|
||||
#include <linux/seq_file.h>
|
||||
|
||||
#include <net/irda/irlan_common.h>
|
||||
#include <net/irda/irlan_filter.h>
|
||||
|
||||
/*
|
||||
* Function irlan_filter_request (self, skb)
|
||||
*
|
||||
* Handle filter request from client peer device
|
||||
*
|
||||
*/
|
||||
void irlan_filter_request(struct irlan_cb *self, struct sk_buff *skb)
|
||||
{
|
||||
IRDA_ASSERT(self != NULL, return;);
|
||||
IRDA_ASSERT(self->magic == IRLAN_MAGIC, return;);
|
||||
|
||||
if ((self->provider.filter_type == IRLAN_DIRECTED) &&
|
||||
(self->provider.filter_operation == DYNAMIC))
|
||||
{
|
||||
IRDA_DEBUG(0, "Giving peer a dynamic Ethernet address\n");
|
||||
self->provider.mac_address[0] = 0x40;
|
||||
self->provider.mac_address[1] = 0x00;
|
||||
self->provider.mac_address[2] = 0x00;
|
||||
self->provider.mac_address[3] = 0x00;
|
||||
|
||||
/* Use arbitration value to generate MAC address */
|
||||
if (self->provider.access_type == ACCESS_PEER) {
|
||||
self->provider.mac_address[4] =
|
||||
self->provider.send_arb_val & 0xff;
|
||||
self->provider.mac_address[5] =
|
||||
(self->provider.send_arb_val >> 8) & 0xff;
|
||||
} else {
|
||||
/* Just generate something for now */
|
||||
get_random_bytes(self->provider.mac_address+4, 1);
|
||||
get_random_bytes(self->provider.mac_address+5, 1);
|
||||
}
|
||||
|
||||
skb->data[0] = 0x00; /* Success */
|
||||
skb->data[1] = 0x03;
|
||||
irlan_insert_string_param(skb, "FILTER_MODE", "NONE");
|
||||
irlan_insert_short_param(skb, "MAX_ENTRY", 0x0001);
|
||||
irlan_insert_array_param(skb, "FILTER_ENTRY",
|
||||
self->provider.mac_address, 6);
|
||||
return;
|
||||
}
|
||||
|
||||
if ((self->provider.filter_type == IRLAN_DIRECTED) &&
|
||||
(self->provider.filter_mode == FILTER))
|
||||
{
|
||||
IRDA_DEBUG(0, "Directed filter on\n");
|
||||
skb->data[0] = 0x00; /* Success */
|
||||
skb->data[1] = 0x00;
|
||||
return;
|
||||
}
|
||||
if ((self->provider.filter_type == IRLAN_DIRECTED) &&
|
||||
(self->provider.filter_mode == NONE))
|
||||
{
|
||||
IRDA_DEBUG(0, "Directed filter off\n");
|
||||
skb->data[0] = 0x00; /* Success */
|
||||
skb->data[1] = 0x00;
|
||||
return;
|
||||
}
|
||||
|
||||
if ((self->provider.filter_type == IRLAN_BROADCAST) &&
|
||||
(self->provider.filter_mode == FILTER))
|
||||
{
|
||||
IRDA_DEBUG(0, "Broadcast filter on\n");
|
||||
skb->data[0] = 0x00; /* Success */
|
||||
skb->data[1] = 0x00;
|
||||
return;
|
||||
}
|
||||
if ((self->provider.filter_type == IRLAN_BROADCAST) &&
|
||||
(self->provider.filter_mode == NONE))
|
||||
{
|
||||
IRDA_DEBUG(0, "Broadcast filter off\n");
|
||||
skb->data[0] = 0x00; /* Success */
|
||||
skb->data[1] = 0x00;
|
||||
return;
|
||||
}
|
||||
if ((self->provider.filter_type == IRLAN_MULTICAST) &&
|
||||
(self->provider.filter_mode == FILTER))
|
||||
{
|
||||
IRDA_DEBUG(0, "Multicast filter on\n");
|
||||
skb->data[0] = 0x00; /* Success */
|
||||
skb->data[1] = 0x00;
|
||||
return;
|
||||
}
|
||||
if ((self->provider.filter_type == IRLAN_MULTICAST) &&
|
||||
(self->provider.filter_mode == NONE))
|
||||
{
|
||||
IRDA_DEBUG(0, "Multicast filter off\n");
|
||||
skb->data[0] = 0x00; /* Success */
|
||||
skb->data[1] = 0x00;
|
||||
return;
|
||||
}
|
||||
if ((self->provider.filter_type == IRLAN_MULTICAST) &&
|
||||
(self->provider.filter_operation == GET))
|
||||
{
|
||||
IRDA_DEBUG(0, "Multicast filter get\n");
|
||||
skb->data[0] = 0x00; /* Success? */
|
||||
skb->data[1] = 0x02;
|
||||
irlan_insert_string_param(skb, "FILTER_MODE", "NONE");
|
||||
irlan_insert_short_param(skb, "MAX_ENTRY", 16);
|
||||
return;
|
||||
}
|
||||
skb->data[0] = 0x00; /* Command not supported */
|
||||
skb->data[1] = 0x00;
|
||||
|
||||
IRDA_DEBUG(0, "Not implemented!\n");
|
||||
}
|
||||
|
||||
/*
|
||||
* Function check_request_param (self, param, value)
|
||||
*
|
||||
* Check parameters in request from peer device
|
||||
*
|
||||
*/
|
||||
void irlan_check_command_param(struct irlan_cb *self, char *param, char *value)
|
||||
{
|
||||
IRDA_DEBUG(4, "%s()\n", __func__ );
|
||||
|
||||
IRDA_ASSERT(self != NULL, return;);
|
||||
IRDA_ASSERT(self->magic == IRLAN_MAGIC, return;);
|
||||
|
||||
IRDA_DEBUG(4, "%s, %s\n", param, value);
|
||||
|
||||
/*
|
||||
* This is experimental!! DB.
|
||||
*/
|
||||
if (strcmp(param, "MODE") == 0) {
|
||||
IRDA_DEBUG(0, "%s()\n", __func__ );
|
||||
self->use_udata = TRUE;
|
||||
return;
|
||||
}
|
||||
|
||||
/*
|
||||
* FILTER_TYPE
|
||||
*/
|
||||
if (strcmp(param, "FILTER_TYPE") == 0) {
|
||||
if (strcmp(value, "DIRECTED") == 0) {
|
||||
self->provider.filter_type = IRLAN_DIRECTED;
|
||||
return;
|
||||
}
|
||||
if (strcmp(value, "MULTICAST") == 0) {
|
||||
self->provider.filter_type = IRLAN_MULTICAST;
|
||||
return;
|
||||
}
|
||||
if (strcmp(value, "BROADCAST") == 0) {
|
||||
self->provider.filter_type = IRLAN_BROADCAST;
|
||||
return;
|
||||
}
|
||||
}
|
||||
/*
|
||||
* FILTER_MODE
|
||||
*/
|
||||
if (strcmp(param, "FILTER_MODE") == 0) {
|
||||
if (strcmp(value, "ALL") == 0) {
|
||||
self->provider.filter_mode = ALL;
|
||||
return;
|
||||
}
|
||||
if (strcmp(value, "FILTER") == 0) {
|
||||
self->provider.filter_mode = FILTER;
|
||||
return;
|
||||
}
|
||||
if (strcmp(value, "NONE") == 0) {
|
||||
self->provider.filter_mode = FILTER;
|
||||
return;
|
||||
}
|
||||
}
|
||||
/*
|
||||
* FILTER_OPERATION
|
||||
*/
|
||||
if (strcmp(param, "FILTER_OPERATION") == 0) {
|
||||
if (strcmp(value, "DYNAMIC") == 0) {
|
||||
self->provider.filter_operation = DYNAMIC;
|
||||
return;
|
||||
}
|
||||
if (strcmp(value, "GET") == 0) {
|
||||
self->provider.filter_operation = GET;
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Function irlan_print_filter (filter_type, buf)
|
||||
*
|
||||
* Print status of filter. Used by /proc file system
|
||||
*
|
||||
*/
|
||||
#ifdef CONFIG_PROC_FS
|
||||
#define MASK2STR(m,s) { .mask = m, .str = s }
|
||||
|
||||
void irlan_print_filter(struct seq_file *seq, int filter_type)
|
||||
{
|
||||
static struct {
|
||||
int mask;
|
||||
const char *str;
|
||||
} filter_mask2str[] = {
|
||||
MASK2STR(IRLAN_DIRECTED, "DIRECTED"),
|
||||
MASK2STR(IRLAN_FUNCTIONAL, "FUNCTIONAL"),
|
||||
MASK2STR(IRLAN_GROUP, "GROUP"),
|
||||
MASK2STR(IRLAN_MAC_FRAME, "MAC_FRAME"),
|
||||
MASK2STR(IRLAN_MULTICAST, "MULTICAST"),
|
||||
MASK2STR(IRLAN_BROADCAST, "BROADCAST"),
|
||||
MASK2STR(IRLAN_IPX_SOCKET, "IPX_SOCKET"),
|
||||
MASK2STR(0, NULL)
|
||||
}, *p;
|
||||
|
||||
for (p = filter_mask2str; p->str; p++) {
|
||||
if (filter_type & p->mask)
|
||||
seq_printf(seq, "%s ", p->str);
|
||||
}
|
||||
seq_putc(seq, '\n');
|
||||
}
|
||||
#undef MASK2STR
|
||||
#endif
|
416
net/irda/irlan/irlan_provider.c
Normal file
416
net/irda/irlan/irlan_provider.c
Normal file
|
@ -0,0 +1,416 @@
|
|||
/*********************************************************************
|
||||
*
|
||||
* Filename: irlan_provider.c
|
||||
* Version: 0.9
|
||||
* Description: IrDA LAN Access Protocol Implementation
|
||||
* Status: Experimental.
|
||||
* Author: Dag Brattli <dagb@cs.uit.no>
|
||||
* Created at: Sun Aug 31 20:14:37 1997
|
||||
* Modified at: Sat Oct 30 12:52:10 1999
|
||||
* Modified by: Dag Brattli <dagb@cs.uit.no>
|
||||
* Sources: skeleton.c by Donald Becker <becker@CESDIS.gsfc.nasa.gov>
|
||||
* slip.c by Laurence Culhane, <loz@holmes.demon.co.uk>
|
||||
* Fred N. van Kempen, <waltje@uwalt.nl.mugnet.org>
|
||||
*
|
||||
* Copyright (c) 1998-1999 Dag Brattli <dagb@cs.uit.no>,
|
||||
* All Rights Reserved.
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License as
|
||||
* published by the Free Software Foundation; either version 2 of
|
||||
* the License, or (at your option) any later version.
|
||||
*
|
||||
* Neither Dag Brattli nor University of Tromsø admit liability nor
|
||||
* provide warranty for any of this software. This material is
|
||||
* provided "AS-IS" and at no charge.
|
||||
*
|
||||
********************************************************************/
|
||||
|
||||
#include <linux/kernel.h>
|
||||
#include <linux/string.h>
|
||||
#include <linux/errno.h>
|
||||
#include <linux/netdevice.h>
|
||||
#include <linux/etherdevice.h>
|
||||
#include <linux/init.h>
|
||||
#include <linux/random.h>
|
||||
#include <linux/bitops.h>
|
||||
#include <linux/slab.h>
|
||||
|
||||
#include <asm/byteorder.h>
|
||||
|
||||
#include <net/irda/irda.h>
|
||||
#include <net/irda/irttp.h>
|
||||
#include <net/irda/irlmp.h>
|
||||
#include <net/irda/irias_object.h>
|
||||
#include <net/irda/iriap.h>
|
||||
#include <net/irda/timer.h>
|
||||
|
||||
#include <net/irda/irlan_common.h>
|
||||
#include <net/irda/irlan_eth.h>
|
||||
#include <net/irda/irlan_event.h>
|
||||
#include <net/irda/irlan_provider.h>
|
||||
#include <net/irda/irlan_filter.h>
|
||||
#include <net/irda/irlan_client.h>
|
||||
|
||||
static void irlan_provider_connect_indication(void *instance, void *sap,
|
||||
struct qos_info *qos,
|
||||
__u32 max_sdu_size,
|
||||
__u8 max_header_size,
|
||||
struct sk_buff *skb);
|
||||
|
||||
/*
|
||||
* Function irlan_provider_control_data_indication (handle, skb)
|
||||
*
|
||||
* This function gets the data that is received on the control channel
|
||||
*
|
||||
*/
|
||||
static int irlan_provider_data_indication(void *instance, void *sap,
|
||||
struct sk_buff *skb)
|
||||
{
|
||||
struct irlan_cb *self;
|
||||
__u8 code;
|
||||
|
||||
IRDA_DEBUG(4, "%s()\n", __func__ );
|
||||
|
||||
self = instance;
|
||||
|
||||
IRDA_ASSERT(self != NULL, return -1;);
|
||||
IRDA_ASSERT(self->magic == IRLAN_MAGIC, return -1;);
|
||||
|
||||
IRDA_ASSERT(skb != NULL, return -1;);
|
||||
|
||||
code = skb->data[0];
|
||||
switch(code) {
|
||||
case CMD_GET_PROVIDER_INFO:
|
||||
IRDA_DEBUG(4, "Got GET_PROVIDER_INFO command!\n");
|
||||
irlan_do_provider_event(self, IRLAN_GET_INFO_CMD, skb);
|
||||
break;
|
||||
|
||||
case CMD_GET_MEDIA_CHAR:
|
||||
IRDA_DEBUG(4, "Got GET_MEDIA_CHAR command!\n");
|
||||
irlan_do_provider_event(self, IRLAN_GET_MEDIA_CMD, skb);
|
||||
break;
|
||||
case CMD_OPEN_DATA_CHANNEL:
|
||||
IRDA_DEBUG(4, "Got OPEN_DATA_CHANNEL command!\n");
|
||||
irlan_do_provider_event(self, IRLAN_OPEN_DATA_CMD, skb);
|
||||
break;
|
||||
case CMD_FILTER_OPERATION:
|
||||
IRDA_DEBUG(4, "Got FILTER_OPERATION command!\n");
|
||||
irlan_do_provider_event(self, IRLAN_FILTER_CONFIG_CMD, skb);
|
||||
break;
|
||||
case CMD_RECONNECT_DATA_CHAN:
|
||||
IRDA_DEBUG(2, "%s(), Got RECONNECT_DATA_CHAN command\n", __func__ );
|
||||
IRDA_DEBUG(2, "%s(), NOT IMPLEMENTED\n", __func__ );
|
||||
break;
|
||||
case CMD_CLOSE_DATA_CHAN:
|
||||
IRDA_DEBUG(2, "Got CLOSE_DATA_CHAN command!\n");
|
||||
IRDA_DEBUG(2, "%s(), NOT IMPLEMENTED\n", __func__ );
|
||||
break;
|
||||
default:
|
||||
IRDA_DEBUG(2, "%s(), Unknown command!\n", __func__ );
|
||||
break;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*
|
||||
* Function irlan_provider_connect_indication (handle, skb, priv)
|
||||
*
|
||||
* Got connection from peer IrLAN client
|
||||
*
|
||||
*/
|
||||
static void irlan_provider_connect_indication(void *instance, void *sap,
|
||||
struct qos_info *qos,
|
||||
__u32 max_sdu_size,
|
||||
__u8 max_header_size,
|
||||
struct sk_buff *skb)
|
||||
{
|
||||
struct irlan_cb *self;
|
||||
struct tsap_cb *tsap;
|
||||
|
||||
IRDA_DEBUG(0, "%s()\n", __func__ );
|
||||
|
||||
self = instance;
|
||||
tsap = sap;
|
||||
|
||||
IRDA_ASSERT(self != NULL, return;);
|
||||
IRDA_ASSERT(self->magic == IRLAN_MAGIC, return;);
|
||||
|
||||
IRDA_ASSERT(tsap == self->provider.tsap_ctrl,return;);
|
||||
IRDA_ASSERT(self->provider.state == IRLAN_IDLE, return;);
|
||||
|
||||
self->provider.max_sdu_size = max_sdu_size;
|
||||
self->provider.max_header_size = max_header_size;
|
||||
|
||||
irlan_do_provider_event(self, IRLAN_CONNECT_INDICATION, NULL);
|
||||
|
||||
/*
|
||||
* If we are in peer mode, the client may not have got the discovery
|
||||
* indication it needs to make progress. If the client is still in
|
||||
* IDLE state, we must kick it.
|
||||
*/
|
||||
if ((self->provider.access_type == ACCESS_PEER) &&
|
||||
(self->client.state == IRLAN_IDLE))
|
||||
{
|
||||
irlan_client_wakeup(self, self->saddr, self->daddr);
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Function irlan_provider_connect_response (handle)
|
||||
*
|
||||
* Accept incoming connection
|
||||
*
|
||||
*/
|
||||
void irlan_provider_connect_response(struct irlan_cb *self,
|
||||
struct tsap_cb *tsap)
|
||||
{
|
||||
IRDA_ASSERT(self != NULL, return;);
|
||||
IRDA_ASSERT(self->magic == IRLAN_MAGIC, return;);
|
||||
|
||||
/* Just accept */
|
||||
irttp_connect_response(tsap, IRLAN_MTU, NULL);
|
||||
}
|
||||
|
||||
static void irlan_provider_disconnect_indication(void *instance, void *sap,
|
||||
LM_REASON reason,
|
||||
struct sk_buff *userdata)
|
||||
{
|
||||
struct irlan_cb *self;
|
||||
struct tsap_cb *tsap;
|
||||
|
||||
IRDA_DEBUG(4, "%s(), reason=%d\n", __func__ , reason);
|
||||
|
||||
self = instance;
|
||||
tsap = sap;
|
||||
|
||||
IRDA_ASSERT(self != NULL, return;);
|
||||
IRDA_ASSERT(self->magic == IRLAN_MAGIC, return;);
|
||||
IRDA_ASSERT(tsap != NULL, return;);
|
||||
IRDA_ASSERT(tsap->magic == TTP_TSAP_MAGIC, return;);
|
||||
|
||||
IRDA_ASSERT(tsap == self->provider.tsap_ctrl, return;);
|
||||
|
||||
irlan_do_provider_event(self, IRLAN_LMP_DISCONNECT, NULL);
|
||||
}
|
||||
|
||||
/*
|
||||
* Function irlan_parse_open_data_cmd (self, skb)
|
||||
*
|
||||
*
|
||||
*
|
||||
*/
|
||||
int irlan_parse_open_data_cmd(struct irlan_cb *self, struct sk_buff *skb)
|
||||
{
|
||||
int ret;
|
||||
|
||||
ret = irlan_provider_parse_command(self, CMD_OPEN_DATA_CHANNEL, skb);
|
||||
|
||||
/* Open data channel */
|
||||
irlan_open_data_tsap(self);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
/*
|
||||
* Function parse_command (skb)
|
||||
*
|
||||
* Extract all parameters from received buffer, then feed them to
|
||||
* check_params for parsing
|
||||
*
|
||||
*/
|
||||
int irlan_provider_parse_command(struct irlan_cb *self, int cmd,
|
||||
struct sk_buff *skb)
|
||||
{
|
||||
__u8 *frame;
|
||||
__u8 *ptr;
|
||||
int count;
|
||||
__u16 val_len;
|
||||
int i;
|
||||
char *name;
|
||||
char *value;
|
||||
int ret = RSP_SUCCESS;
|
||||
|
||||
IRDA_ASSERT(skb != NULL, return -RSP_PROTOCOL_ERROR;);
|
||||
|
||||
IRDA_DEBUG(4, "%s(), skb->len=%d\n", __func__ , (int)skb->len);
|
||||
|
||||
IRDA_ASSERT(self != NULL, return -RSP_PROTOCOL_ERROR;);
|
||||
IRDA_ASSERT(self->magic == IRLAN_MAGIC, return -RSP_PROTOCOL_ERROR;);
|
||||
|
||||
if (!skb)
|
||||
return -RSP_PROTOCOL_ERROR;
|
||||
|
||||
frame = skb->data;
|
||||
|
||||
name = kmalloc(255, GFP_ATOMIC);
|
||||
if (!name)
|
||||
return -RSP_INSUFFICIENT_RESOURCES;
|
||||
value = kmalloc(1016, GFP_ATOMIC);
|
||||
if (!value) {
|
||||
kfree(name);
|
||||
return -RSP_INSUFFICIENT_RESOURCES;
|
||||
}
|
||||
|
||||
/* How many parameters? */
|
||||
count = frame[1];
|
||||
|
||||
IRDA_DEBUG(4, "Got %d parameters\n", count);
|
||||
|
||||
ptr = frame+2;
|
||||
|
||||
/* For all parameters */
|
||||
for (i=0; i<count;i++) {
|
||||
ret = irlan_extract_param(ptr, name, value, &val_len);
|
||||
if (ret < 0) {
|
||||
IRDA_DEBUG(2, "%s(), IrLAN, Error!\n", __func__ );
|
||||
break;
|
||||
}
|
||||
ptr+=ret;
|
||||
ret = RSP_SUCCESS;
|
||||
irlan_check_command_param(self, name, value);
|
||||
}
|
||||
/* Cleanup */
|
||||
kfree(name);
|
||||
kfree(value);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
/*
|
||||
* Function irlan_provider_send_reply (self, info)
|
||||
*
|
||||
* Send reply to query to peer IrLAN layer
|
||||
*
|
||||
*/
|
||||
void irlan_provider_send_reply(struct irlan_cb *self, int command,
|
||||
int ret_code)
|
||||
{
|
||||
struct sk_buff *skb;
|
||||
|
||||
IRDA_DEBUG(4, "%s()\n", __func__ );
|
||||
|
||||
IRDA_ASSERT(self != NULL, return;);
|
||||
IRDA_ASSERT(self->magic == IRLAN_MAGIC, return;);
|
||||
|
||||
skb = alloc_skb(IRLAN_MAX_HEADER + IRLAN_CMD_HEADER +
|
||||
/* Bigger param length comes from CMD_GET_MEDIA_CHAR */
|
||||
IRLAN_STRING_PARAMETER_LEN("FILTER_TYPE", "DIRECTED") +
|
||||
IRLAN_STRING_PARAMETER_LEN("FILTER_TYPE", "BROADCAST") +
|
||||
IRLAN_STRING_PARAMETER_LEN("FILTER_TYPE", "MULTICAST") +
|
||||
IRLAN_STRING_PARAMETER_LEN("ACCESS_TYPE", "HOSTED"),
|
||||
GFP_ATOMIC);
|
||||
|
||||
if (!skb)
|
||||
return;
|
||||
|
||||
/* Reserve space for TTP, LMP, and LAP header */
|
||||
skb_reserve(skb, self->provider.max_header_size);
|
||||
skb_put(skb, 2);
|
||||
|
||||
switch (command) {
|
||||
case CMD_GET_PROVIDER_INFO:
|
||||
skb->data[0] = 0x00; /* Success */
|
||||
skb->data[1] = 0x02; /* 2 parameters */
|
||||
switch (self->media) {
|
||||
case MEDIA_802_3:
|
||||
irlan_insert_string_param(skb, "MEDIA", "802.3");
|
||||
break;
|
||||
case MEDIA_802_5:
|
||||
irlan_insert_string_param(skb, "MEDIA", "802.5");
|
||||
break;
|
||||
default:
|
||||
IRDA_DEBUG(2, "%s(), unknown media type!\n", __func__ );
|
||||
break;
|
||||
}
|
||||
irlan_insert_short_param(skb, "IRLAN_VER", 0x0101);
|
||||
break;
|
||||
|
||||
case CMD_GET_MEDIA_CHAR:
|
||||
skb->data[0] = 0x00; /* Success */
|
||||
skb->data[1] = 0x05; /* 5 parameters */
|
||||
irlan_insert_string_param(skb, "FILTER_TYPE", "DIRECTED");
|
||||
irlan_insert_string_param(skb, "FILTER_TYPE", "BROADCAST");
|
||||
irlan_insert_string_param(skb, "FILTER_TYPE", "MULTICAST");
|
||||
|
||||
switch (self->provider.access_type) {
|
||||
case ACCESS_DIRECT:
|
||||
irlan_insert_string_param(skb, "ACCESS_TYPE", "DIRECT");
|
||||
break;
|
||||
case ACCESS_PEER:
|
||||
irlan_insert_string_param(skb, "ACCESS_TYPE", "PEER");
|
||||
break;
|
||||
case ACCESS_HOSTED:
|
||||
irlan_insert_string_param(skb, "ACCESS_TYPE", "HOSTED");
|
||||
break;
|
||||
default:
|
||||
IRDA_DEBUG(2, "%s(), Unknown access type\n", __func__ );
|
||||
break;
|
||||
}
|
||||
irlan_insert_short_param(skb, "MAX_FRAME", 0x05ee);
|
||||
break;
|
||||
case CMD_OPEN_DATA_CHANNEL:
|
||||
skb->data[0] = 0x00; /* Success */
|
||||
if (self->provider.send_arb_val) {
|
||||
skb->data[1] = 0x03; /* 3 parameters */
|
||||
irlan_insert_short_param(skb, "CON_ARB",
|
||||
self->provider.send_arb_val);
|
||||
} else
|
||||
skb->data[1] = 0x02; /* 2 parameters */
|
||||
irlan_insert_byte_param(skb, "DATA_CHAN", self->stsap_sel_data);
|
||||
irlan_insert_string_param(skb, "RECONNECT_KEY", "LINUX RULES!");
|
||||
break;
|
||||
case CMD_FILTER_OPERATION:
|
||||
irlan_filter_request(self, skb);
|
||||
break;
|
||||
default:
|
||||
IRDA_DEBUG(2, "%s(), Unknown command!\n", __func__ );
|
||||
break;
|
||||
}
|
||||
|
||||
irttp_data_request(self->provider.tsap_ctrl, skb);
|
||||
}
|
||||
|
||||
/*
|
||||
* Function irlan_provider_register(void)
|
||||
*
|
||||
* Register provider support so we can accept incoming connections.
|
||||
*
|
||||
*/
|
||||
int irlan_provider_open_ctrl_tsap(struct irlan_cb *self)
|
||||
{
|
||||
struct tsap_cb *tsap;
|
||||
notify_t notify;
|
||||
|
||||
IRDA_DEBUG(4, "%s()\n", __func__ );
|
||||
|
||||
IRDA_ASSERT(self != NULL, return -1;);
|
||||
IRDA_ASSERT(self->magic == IRLAN_MAGIC, return -1;);
|
||||
|
||||
/* Check if already open */
|
||||
if (self->provider.tsap_ctrl)
|
||||
return -1;
|
||||
|
||||
/*
|
||||
* First register well known control TSAP
|
||||
*/
|
||||
irda_notify_init(¬ify);
|
||||
notify.data_indication = irlan_provider_data_indication;
|
||||
notify.connect_indication = irlan_provider_connect_indication;
|
||||
notify.disconnect_indication = irlan_provider_disconnect_indication;
|
||||
notify.instance = self;
|
||||
strlcpy(notify.name, "IrLAN ctrl (p)", sizeof(notify.name));
|
||||
|
||||
tsap = irttp_open_tsap(LSAP_ANY, 1, ¬ify);
|
||||
if (!tsap) {
|
||||
IRDA_DEBUG(2, "%s(), Got no tsap!\n", __func__ );
|
||||
return -1;
|
||||
}
|
||||
self->provider.tsap_ctrl = tsap;
|
||||
|
||||
/* Register with LM-IAS */
|
||||
irlan_ias_register(self, tsap->stsap_sel);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
241
net/irda/irlan/irlan_provider_event.c
Normal file
241
net/irda/irlan/irlan_provider_event.c
Normal file
|
@ -0,0 +1,241 @@
|
|||
/*********************************************************************
|
||||
*
|
||||
* Filename: irlan_provider_event.c
|
||||
* Version: 0.9
|
||||
* Description: IrLAN provider state machine)
|
||||
* Status: Experimental.
|
||||
* Author: Dag Brattli <dagb@cs.uit.no>
|
||||
* Created at: Sun Aug 31 20:14:37 1997
|
||||
* Modified at: Sat Oct 30 12:52:41 1999
|
||||
* Modified by: Dag Brattli <dagb@cs.uit.no>
|
||||
*
|
||||
* Copyright (c) 1998-1999 Dag Brattli <dagb@cs.uit.no>, All Rights Reserved.
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License as
|
||||
* published by the Free Software Foundation; either version 2 of
|
||||
* the License, or (at your option) any later version.
|
||||
*
|
||||
* Neither Dag Brattli nor University of Tromsø admit liability nor
|
||||
* provide warranty for any of this software. This material is
|
||||
* provided "AS-IS" and at no charge.
|
||||
*
|
||||
********************************************************************/
|
||||
|
||||
#include <net/irda/irda.h>
|
||||
#include <net/irda/iriap.h>
|
||||
#include <net/irda/irlmp.h>
|
||||
#include <net/irda/irttp.h>
|
||||
|
||||
#include <net/irda/irlan_provider.h>
|
||||
#include <net/irda/irlan_event.h>
|
||||
|
||||
static int irlan_provider_state_idle(struct irlan_cb *self, IRLAN_EVENT event,
|
||||
struct sk_buff *skb);
|
||||
static int irlan_provider_state_info(struct irlan_cb *self, IRLAN_EVENT event,
|
||||
struct sk_buff *skb);
|
||||
static int irlan_provider_state_open(struct irlan_cb *self, IRLAN_EVENT event,
|
||||
struct sk_buff *skb);
|
||||
static int irlan_provider_state_data(struct irlan_cb *self, IRLAN_EVENT event,
|
||||
struct sk_buff *skb);
|
||||
|
||||
static int (*state[])(struct irlan_cb *self, IRLAN_EVENT event,
|
||||
struct sk_buff *skb) =
|
||||
{
|
||||
irlan_provider_state_idle,
|
||||
NULL, /* Query */
|
||||
NULL, /* Info */
|
||||
irlan_provider_state_info,
|
||||
NULL, /* Media */
|
||||
irlan_provider_state_open,
|
||||
NULL, /* Wait */
|
||||
NULL, /* Arb */
|
||||
irlan_provider_state_data,
|
||||
NULL, /* Close */
|
||||
NULL, /* Sync */
|
||||
};
|
||||
|
||||
void irlan_do_provider_event(struct irlan_cb *self, IRLAN_EVENT event,
|
||||
struct sk_buff *skb)
|
||||
{
|
||||
IRDA_ASSERT(*state[ self->provider.state] != NULL, return;);
|
||||
|
||||
(*state[self->provider.state]) (self, event, skb);
|
||||
}
|
||||
|
||||
/*
|
||||
* Function irlan_provider_state_idle (event, skb, info)
|
||||
*
|
||||
* IDLE, We are waiting for an indication that there is a provider
|
||||
* available.
|
||||
*/
|
||||
static int irlan_provider_state_idle(struct irlan_cb *self, IRLAN_EVENT event,
|
||||
struct sk_buff *skb)
|
||||
{
|
||||
IRDA_DEBUG(4, "%s()\n", __func__ );
|
||||
|
||||
IRDA_ASSERT(self != NULL, return -1;);
|
||||
|
||||
switch(event) {
|
||||
case IRLAN_CONNECT_INDICATION:
|
||||
irlan_provider_connect_response( self, self->provider.tsap_ctrl);
|
||||
irlan_next_provider_state( self, IRLAN_INFO);
|
||||
break;
|
||||
default:
|
||||
IRDA_DEBUG(4, "%s(), Unknown event %d\n", __func__ , event);
|
||||
break;
|
||||
}
|
||||
if (skb)
|
||||
dev_kfree_skb(skb);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*
|
||||
* Function irlan_provider_state_info (self, event, skb, info)
|
||||
*
|
||||
* INFO, We have issued a GetInfo command and is awaiting a reply.
|
||||
*/
|
||||
static int irlan_provider_state_info(struct irlan_cb *self, IRLAN_EVENT event,
|
||||
struct sk_buff *skb)
|
||||
{
|
||||
int ret;
|
||||
|
||||
IRDA_DEBUG(4, "%s()\n", __func__ );
|
||||
|
||||
IRDA_ASSERT(self != NULL, return -1;);
|
||||
|
||||
switch(event) {
|
||||
case IRLAN_GET_INFO_CMD:
|
||||
/* Be sure to use 802.3 in case of peer mode */
|
||||
if (self->provider.access_type == ACCESS_PEER) {
|
||||
self->media = MEDIA_802_3;
|
||||
|
||||
/* Check if client has started yet */
|
||||
if (self->client.state == IRLAN_IDLE) {
|
||||
/* This should get the client going */
|
||||
irlmp_discovery_request(8);
|
||||
}
|
||||
}
|
||||
|
||||
irlan_provider_send_reply(self, CMD_GET_PROVIDER_INFO,
|
||||
RSP_SUCCESS);
|
||||
/* Keep state */
|
||||
break;
|
||||
case IRLAN_GET_MEDIA_CMD:
|
||||
irlan_provider_send_reply(self, CMD_GET_MEDIA_CHAR,
|
||||
RSP_SUCCESS);
|
||||
/* Keep state */
|
||||
break;
|
||||
case IRLAN_OPEN_DATA_CMD:
|
||||
ret = irlan_parse_open_data_cmd(self, skb);
|
||||
if (self->provider.access_type == ACCESS_PEER) {
|
||||
/* FIXME: make use of random functions! */
|
||||
self->provider.send_arb_val = (jiffies & 0xffff);
|
||||
}
|
||||
irlan_provider_send_reply(self, CMD_OPEN_DATA_CHANNEL, ret);
|
||||
|
||||
if (ret == RSP_SUCCESS) {
|
||||
irlan_next_provider_state(self, IRLAN_OPEN);
|
||||
|
||||
/* Signal client that we are now open */
|
||||
irlan_do_client_event(self, IRLAN_PROVIDER_SIGNAL, NULL);
|
||||
}
|
||||
break;
|
||||
case IRLAN_LMP_DISCONNECT: /* FALLTHROUGH */
|
||||
case IRLAN_LAP_DISCONNECT:
|
||||
irlan_next_provider_state(self, IRLAN_IDLE);
|
||||
break;
|
||||
default:
|
||||
IRDA_DEBUG( 0, "%s(), Unknown event %d\n", __func__ , event);
|
||||
break;
|
||||
}
|
||||
if (skb)
|
||||
dev_kfree_skb(skb);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*
|
||||
* Function irlan_provider_state_open (self, event, skb, info)
|
||||
*
|
||||
* OPEN, The client has issued a OpenData command and is awaiting a
|
||||
* reply
|
||||
*
|
||||
*/
|
||||
static int irlan_provider_state_open(struct irlan_cb *self, IRLAN_EVENT event,
|
||||
struct sk_buff *skb)
|
||||
{
|
||||
IRDA_DEBUG(4, "%s()\n", __func__ );
|
||||
|
||||
IRDA_ASSERT(self != NULL, return -1;);
|
||||
|
||||
switch(event) {
|
||||
case IRLAN_FILTER_CONFIG_CMD:
|
||||
irlan_provider_parse_command(self, CMD_FILTER_OPERATION, skb);
|
||||
irlan_provider_send_reply(self, CMD_FILTER_OPERATION,
|
||||
RSP_SUCCESS);
|
||||
/* Keep state */
|
||||
break;
|
||||
case IRLAN_DATA_CONNECT_INDICATION:
|
||||
irlan_next_provider_state(self, IRLAN_DATA);
|
||||
irlan_provider_connect_response(self, self->tsap_data);
|
||||
break;
|
||||
case IRLAN_LMP_DISCONNECT: /* FALLTHROUGH */
|
||||
case IRLAN_LAP_DISCONNECT:
|
||||
irlan_next_provider_state(self, IRLAN_IDLE);
|
||||
break;
|
||||
default:
|
||||
IRDA_DEBUG(2, "%s(), Unknown event %d\n", __func__ , event);
|
||||
break;
|
||||
}
|
||||
if (skb)
|
||||
dev_kfree_skb(skb);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*
|
||||
* Function irlan_provider_state_data (self, event, skb, info)
|
||||
*
|
||||
* DATA, The data channel is connected, allowing data transfers between
|
||||
* the local and remote machines.
|
||||
*
|
||||
*/
|
||||
static int irlan_provider_state_data(struct irlan_cb *self, IRLAN_EVENT event,
|
||||
struct sk_buff *skb)
|
||||
{
|
||||
IRDA_DEBUG(4, "%s()\n", __func__ );
|
||||
|
||||
IRDA_ASSERT(self != NULL, return -1;);
|
||||
IRDA_ASSERT(self->magic == IRLAN_MAGIC, return -1;);
|
||||
|
||||
switch(event) {
|
||||
case IRLAN_FILTER_CONFIG_CMD:
|
||||
irlan_provider_parse_command(self, CMD_FILTER_OPERATION, skb);
|
||||
irlan_provider_send_reply(self, CMD_FILTER_OPERATION,
|
||||
RSP_SUCCESS);
|
||||
break;
|
||||
case IRLAN_LMP_DISCONNECT: /* FALLTHROUGH */
|
||||
case IRLAN_LAP_DISCONNECT:
|
||||
irlan_next_provider_state(self, IRLAN_IDLE);
|
||||
break;
|
||||
default:
|
||||
IRDA_DEBUG( 0, "%s(), Unknown event %d\n", __func__ , event);
|
||||
break;
|
||||
}
|
||||
if (skb)
|
||||
dev_kfree_skb(skb);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
Loading…
Add table
Add a link
Reference in a new issue