2005-04-17 06:20:36 +08:00
|
|
|
/*********************************************************************
|
2007-02-09 22:24:53 +08:00
|
|
|
*
|
2005-04-17 06:20:36 +08:00
|
|
|
* Filename: ircomm_lmp.c
|
|
|
|
* Version: 1.0
|
|
|
|
* Description: Interface between IrCOMM and IrLMP
|
|
|
|
* Status: Stable
|
|
|
|
* Author: Dag Brattli <dagb@cs.uit.no>
|
|
|
|
* Created at: Sun Jun 6 20:48:27 1999
|
|
|
|
* Modified at: Sun Dec 12 13:44:17 1999
|
|
|
|
* Modified by: Dag Brattli <dagb@cs.uit.no>
|
|
|
|
* Sources: Previous IrLPT work by Thomas Davis
|
2007-02-09 22:24:53 +08:00
|
|
|
*
|
2005-04-17 06:20:36 +08:00
|
|
|
* Copyright (c) 1999 Dag Brattli, All Rights Reserved.
|
|
|
|
* Copyright (c) 2000-2003 Jean Tourrilhes <jt@hpl.hp.com>
|
2007-02-09 22:24:53 +08:00
|
|
|
*
|
|
|
|
* 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
|
2005-04-17 06:20:36 +08:00
|
|
|
* the License, or (at your option) any later version.
|
2007-02-09 22:24:53 +08:00
|
|
|
*
|
2005-04-17 06:20:36 +08:00
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
2007-02-09 22:24:53 +08:00
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 59 Temple Place, Suite 330, Boston,
|
2005-04-17 06:20:36 +08:00
|
|
|
* MA 02111-1307 USA
|
2007-02-09 22:24:53 +08:00
|
|
|
*
|
2005-04-17 06:20:36 +08:00
|
|
|
********************************************************************/
|
|
|
|
|
|
|
|
#include <linux/init.h>
|
|
|
|
|
|
|
|
#include <net/irda/irda.h>
|
|
|
|
#include <net/irda/irlmp.h>
|
|
|
|
#include <net/irda/iriap.h>
|
|
|
|
#include <net/irda/irda_device.h> /* struct irda_skb_cb */
|
|
|
|
|
|
|
|
#include <net/irda/ircomm_event.h>
|
|
|
|
#include <net/irda/ircomm_lmp.h>
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Function ircomm_lmp_connect_request (self, userdata)
|
|
|
|
*
|
2007-02-09 22:24:53 +08:00
|
|
|
*
|
2005-04-17 06:20:36 +08:00
|
|
|
*
|
|
|
|
*/
|
2007-02-09 22:24:53 +08:00
|
|
|
static int ircomm_lmp_connect_request(struct ircomm_cb *self,
|
|
|
|
struct sk_buff *userdata,
|
2005-04-17 06:20:36 +08:00
|
|
|
struct ircomm_info *info)
|
|
|
|
{
|
|
|
|
int ret = 0;
|
|
|
|
|
2008-03-06 12:47:47 +08:00
|
|
|
IRDA_DEBUG(0, "%s()\n", __func__ );
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
/* Don't forget to refcount it - should be NULL anyway */
|
|
|
|
if(userdata)
|
|
|
|
skb_get(userdata);
|
|
|
|
|
|
|
|
ret = irlmp_connect_request(self->lsap, info->dlsap_sel,
|
2007-02-09 22:24:53 +08:00
|
|
|
info->saddr, info->daddr, NULL, userdata);
|
2005-04-17 06:20:36 +08:00
|
|
|
return ret;
|
2007-02-09 22:24:53 +08:00
|
|
|
}
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Function ircomm_lmp_connect_response (self, skb)
|
|
|
|
*
|
2007-02-09 22:24:53 +08:00
|
|
|
*
|
2005-04-17 06:20:36 +08:00
|
|
|
*
|
|
|
|
*/
|
|
|
|
static int ircomm_lmp_connect_response(struct ircomm_cb *self,
|
|
|
|
struct sk_buff *userdata)
|
|
|
|
{
|
|
|
|
struct sk_buff *tx_skb;
|
|
|
|
int ret;
|
|
|
|
|
2008-03-06 12:47:47 +08:00
|
|
|
IRDA_DEBUG(0, "%s()\n", __func__ );
|
2007-02-09 22:24:53 +08:00
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
/* Any userdata supplied? */
|
|
|
|
if (userdata == NULL) {
|
2006-09-28 11:06:44 +08:00
|
|
|
tx_skb = alloc_skb(LMP_MAX_HEADER, GFP_ATOMIC);
|
2005-04-17 06:20:36 +08:00
|
|
|
if (!tx_skb)
|
|
|
|
return -ENOMEM;
|
|
|
|
|
|
|
|
/* Reserve space for MUX and LAP header */
|
|
|
|
skb_reserve(tx_skb, LMP_MAX_HEADER);
|
|
|
|
} else {
|
2007-02-09 22:24:53 +08:00
|
|
|
/*
|
|
|
|
* Check that the client has reserved enough space for
|
2005-04-17 06:20:36 +08:00
|
|
|
* headers
|
|
|
|
*/
|
|
|
|
IRDA_ASSERT(skb_headroom(userdata) >= LMP_MAX_HEADER,
|
|
|
|
return -1;);
|
|
|
|
|
|
|
|
/* Don't forget to refcount it - should be NULL anyway */
|
|
|
|
skb_get(userdata);
|
|
|
|
tx_skb = userdata;
|
|
|
|
}
|
|
|
|
|
|
|
|
ret = irlmp_connect_response(self->lsap, tx_skb);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2007-02-09 22:24:53 +08:00
|
|
|
static int ircomm_lmp_disconnect_request(struct ircomm_cb *self,
|
|
|
|
struct sk_buff *userdata,
|
2005-04-17 06:20:36 +08:00
|
|
|
struct ircomm_info *info)
|
|
|
|
{
|
2007-02-09 22:24:53 +08:00
|
|
|
struct sk_buff *tx_skb;
|
2005-04-17 06:20:36 +08:00
|
|
|
int ret;
|
|
|
|
|
2008-03-06 12:47:47 +08:00
|
|
|
IRDA_DEBUG(0, "%s()\n", __func__ );
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2007-02-09 22:24:53 +08:00
|
|
|
if (!userdata) {
|
2006-09-28 11:06:44 +08:00
|
|
|
tx_skb = alloc_skb(LMP_MAX_HEADER, GFP_ATOMIC);
|
2005-04-17 06:20:36 +08:00
|
|
|
if (!tx_skb)
|
|
|
|
return -ENOMEM;
|
2007-02-09 22:24:53 +08:00
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
/* Reserve space for MUX and LAP header */
|
2007-02-09 22:24:53 +08:00
|
|
|
skb_reserve(tx_skb, LMP_MAX_HEADER);
|
2005-04-17 06:20:36 +08:00
|
|
|
userdata = tx_skb;
|
|
|
|
} else {
|
|
|
|
/* Don't forget to refcount it - should be NULL anyway */
|
|
|
|
skb_get(userdata);
|
|
|
|
}
|
|
|
|
|
|
|
|
ret = irlmp_disconnect_request(self->lsap, userdata);
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Function ircomm_lmp_flow_control (skb)
|
|
|
|
*
|
|
|
|
* This function is called when a data frame we have sent to IrLAP has
|
2007-02-09 22:24:53 +08:00
|
|
|
* been deallocated. We do this to make sure we don't flood IrLAP with
|
2005-04-17 06:20:36 +08:00
|
|
|
* frames, since we are not using the IrTTP flow control mechanism
|
|
|
|
*/
|
|
|
|
static void ircomm_lmp_flow_control(struct sk_buff *skb)
|
|
|
|
{
|
|
|
|
struct irda_skb_cb *cb;
|
|
|
|
struct ircomm_cb *self;
|
|
|
|
int line;
|
|
|
|
|
|
|
|
IRDA_ASSERT(skb != NULL, return;);
|
|
|
|
|
|
|
|
cb = (struct irda_skb_cb *) skb->cb;
|
|
|
|
|
2008-03-06 12:47:47 +08:00
|
|
|
IRDA_DEBUG(2, "%s()\n", __func__ );
|
2007-02-09 22:24:53 +08:00
|
|
|
|
|
|
|
line = cb->line;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
self = (struct ircomm_cb *) hashbin_lock_find(ircomm, line, NULL);
|
2007-02-09 22:24:53 +08:00
|
|
|
if (!self) {
|
2008-03-06 12:47:47 +08:00
|
|
|
IRDA_DEBUG(2, "%s(), didn't find myself\n", __func__ );
|
2007-02-09 22:24:53 +08:00
|
|
|
return;
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
2007-02-09 22:24:53 +08:00
|
|
|
IRDA_ASSERT(self != NULL, return;);
|
2005-04-17 06:20:36 +08:00
|
|
|
IRDA_ASSERT(self->magic == IRCOMM_MAGIC, return;);
|
|
|
|
|
|
|
|
self->pkt_count--;
|
|
|
|
|
2007-02-09 22:24:53 +08:00
|
|
|
if ((self->pkt_count < 2) && (self->flow_status == FLOW_STOP)) {
|
2008-03-06 12:47:47 +08:00
|
|
|
IRDA_DEBUG(2, "%s(), asking TTY to start again!\n", __func__ );
|
2007-02-09 22:24:53 +08:00
|
|
|
self->flow_status = FLOW_START;
|
|
|
|
if (self->notify.flow_indication)
|
|
|
|
self->notify.flow_indication(self->notify.instance,
|
2005-04-17 06:20:36 +08:00
|
|
|
self, FLOW_START);
|
2007-02-09 22:24:53 +08:00
|
|
|
}
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
2007-02-09 22:24:53 +08:00
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
/*
|
|
|
|
* Function ircomm_lmp_data_request (self, userdata)
|
|
|
|
*
|
|
|
|
* Send data frame to peer device
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
static int ircomm_lmp_data_request(struct ircomm_cb *self,
|
2007-02-09 22:24:53 +08:00
|
|
|
struct sk_buff *skb,
|
2005-04-17 06:20:36 +08:00
|
|
|
int not_used)
|
|
|
|
{
|
|
|
|
struct irda_skb_cb *cb;
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
IRDA_ASSERT(skb != NULL, return -1;);
|
|
|
|
|
|
|
|
cb = (struct irda_skb_cb *) skb->cb;
|
2007-02-09 22:24:53 +08:00
|
|
|
|
|
|
|
cb->line = self->line;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2008-03-06 12:47:47 +08:00
|
|
|
IRDA_DEBUG(4, "%s(), sending frame\n", __func__ );
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
/* Don't forget to refcount it - see ircomm_tty_do_softint() */
|
|
|
|
skb_get(skb);
|
|
|
|
|
2009-06-22 10:25:25 +08:00
|
|
|
skb_orphan(skb);
|
2005-04-17 06:20:36 +08:00
|
|
|
skb->destructor = ircomm_lmp_flow_control;
|
|
|
|
|
2007-02-09 22:24:53 +08:00
|
|
|
if ((self->pkt_count++ > 7) && (self->flow_status == FLOW_START)) {
|
2008-03-06 12:47:47 +08:00
|
|
|
IRDA_DEBUG(2, "%s(), asking TTY to slow down!\n", __func__ );
|
2007-02-09 22:24:53 +08:00
|
|
|
self->flow_status = FLOW_STOP;
|
|
|
|
if (self->notify.flow_indication)
|
|
|
|
self->notify.flow_indication(self->notify.instance,
|
|
|
|
self, FLOW_STOP);
|
|
|
|
}
|
2005-04-17 06:20:36 +08:00
|
|
|
ret = irlmp_data_request(self->lsap, skb);
|
|
|
|
if (ret) {
|
2008-03-06 12:47:47 +08:00
|
|
|
IRDA_ERROR("%s(), failed\n", __func__);
|
2005-04-17 06:20:36 +08:00
|
|
|
/* irlmp_data_request already free the packet */
|
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Function ircomm_lmp_data_indication (instance, sap, skb)
|
|
|
|
*
|
|
|
|
* Incoming data which we must deliver to the state machine, to check
|
|
|
|
* we are still connected.
|
|
|
|
*/
|
|
|
|
static int ircomm_lmp_data_indication(void *instance, void *sap,
|
|
|
|
struct sk_buff *skb)
|
|
|
|
{
|
|
|
|
struct ircomm_cb *self = (struct ircomm_cb *) instance;
|
|
|
|
|
2008-03-06 12:47:47 +08:00
|
|
|
IRDA_DEBUG(4, "%s()\n", __func__ );
|
2007-02-09 22:24:53 +08:00
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
IRDA_ASSERT(self != NULL, return -1;);
|
|
|
|
IRDA_ASSERT(self->magic == IRCOMM_MAGIC, return -1;);
|
|
|
|
IRDA_ASSERT(skb != NULL, return -1;);
|
2007-02-09 22:24:53 +08:00
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
ircomm_do_event(self, IRCOMM_LMP_DATA_INDICATION, skb, NULL);
|
|
|
|
|
|
|
|
/* Drop reference count - see ircomm_tty_data_indication(). */
|
|
|
|
dev_kfree_skb(skb);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2007-02-09 22:24:53 +08:00
|
|
|
* Function ircomm_lmp_connect_confirm (instance, sap, qos, max_sdu_size,
|
2005-04-17 06:20:36 +08:00
|
|
|
* max_header_size, skb)
|
|
|
|
*
|
|
|
|
* Connection has been confirmed by peer device
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
static void ircomm_lmp_connect_confirm(void *instance, void *sap,
|
2007-02-09 22:24:53 +08:00
|
|
|
struct qos_info *qos,
|
|
|
|
__u32 max_seg_size,
|
2005-04-17 06:20:36 +08:00
|
|
|
__u8 max_header_size,
|
|
|
|
struct sk_buff *skb)
|
|
|
|
{
|
|
|
|
struct ircomm_cb *self = (struct ircomm_cb *) instance;
|
|
|
|
struct ircomm_info info;
|
|
|
|
|
2008-03-06 12:47:47 +08:00
|
|
|
IRDA_DEBUG(0, "%s()\n", __func__ );
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
IRDA_ASSERT(self != NULL, return;);
|
|
|
|
IRDA_ASSERT(self->magic == IRCOMM_MAGIC, return;);
|
|
|
|
IRDA_ASSERT(skb != NULL, return;);
|
|
|
|
IRDA_ASSERT(qos != NULL, return;);
|
|
|
|
|
|
|
|
info.max_data_size = max_seg_size;
|
|
|
|
info.max_header_size = max_header_size;
|
|
|
|
info.qos = qos;
|
|
|
|
|
|
|
|
ircomm_do_event(self, IRCOMM_LMP_CONNECT_CONFIRM, skb, &info);
|
|
|
|
|
|
|
|
/* Drop reference count - see ircomm_tty_connect_confirm(). */
|
|
|
|
dev_kfree_skb(skb);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Function ircomm_lmp_connect_indication (instance, sap, qos, max_sdu_size,
|
|
|
|
* max_header_size, skb)
|
|
|
|
*
|
|
|
|
* Peer device wants to make a connection with us
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
static void ircomm_lmp_connect_indication(void *instance, void *sap,
|
|
|
|
struct qos_info *qos,
|
|
|
|
__u32 max_seg_size,
|
|
|
|
__u8 max_header_size,
|
|
|
|
struct sk_buff *skb)
|
|
|
|
{
|
|
|
|
struct ircomm_cb *self = (struct ircomm_cb *)instance;
|
|
|
|
struct ircomm_info info;
|
|
|
|
|
2008-03-06 12:47:47 +08:00
|
|
|
IRDA_DEBUG(0, "%s()\n", __func__ );
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
IRDA_ASSERT(self != NULL, return;);
|
|
|
|
IRDA_ASSERT(self->magic == IRCOMM_MAGIC, return;);
|
|
|
|
IRDA_ASSERT(skb != NULL, return;);
|
|
|
|
IRDA_ASSERT(qos != NULL, return;);
|
|
|
|
|
|
|
|
info.max_data_size = max_seg_size;
|
|
|
|
info.max_header_size = max_header_size;
|
|
|
|
info.qos = qos;
|
|
|
|
|
|
|
|
ircomm_do_event(self, IRCOMM_LMP_CONNECT_INDICATION, skb, &info);
|
|
|
|
|
|
|
|
/* Drop reference count - see ircomm_tty_connect_indication(). */
|
|
|
|
dev_kfree_skb(skb);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Function ircomm_lmp_disconnect_indication (instance, sap, reason, skb)
|
|
|
|
*
|
|
|
|
* Peer device has closed the connection, or the link went down for some
|
|
|
|
* other reason
|
|
|
|
*/
|
2007-02-09 22:24:53 +08:00
|
|
|
static void ircomm_lmp_disconnect_indication(void *instance, void *sap,
|
2005-04-17 06:20:36 +08:00
|
|
|
LM_REASON reason,
|
|
|
|
struct sk_buff *skb)
|
|
|
|
{
|
|
|
|
struct ircomm_cb *self = (struct ircomm_cb *) instance;
|
|
|
|
struct ircomm_info info;
|
|
|
|
|
2008-03-06 12:47:47 +08:00
|
|
|
IRDA_DEBUG(0, "%s()\n", __func__ );
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
IRDA_ASSERT(self != NULL, return;);
|
|
|
|
IRDA_ASSERT(self->magic == IRCOMM_MAGIC, return;);
|
|
|
|
|
|
|
|
info.reason = reason;
|
|
|
|
|
|
|
|
ircomm_do_event(self, IRCOMM_LMP_DISCONNECT_INDICATION, skb, &info);
|
|
|
|
|
|
|
|
/* Drop reference count - see ircomm_tty_disconnect_indication(). */
|
|
|
|
if(skb)
|
|
|
|
dev_kfree_skb(skb);
|
|
|
|
}
|
|
|
|
/*
|
|
|
|
* Function ircomm_open_lsap (self)
|
|
|
|
*
|
|
|
|
* Open LSAP. This function will only be used when using "raw" services
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
int ircomm_open_lsap(struct ircomm_cb *self)
|
|
|
|
{
|
|
|
|
notify_t notify;
|
|
|
|
|
2008-03-06 12:47:47 +08:00
|
|
|
IRDA_DEBUG(0, "%s()\n", __func__ );
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
/* Register callbacks */
|
|
|
|
irda_notify_init(¬ify);
|
|
|
|
notify.data_indication = ircomm_lmp_data_indication;
|
|
|
|
notify.connect_confirm = ircomm_lmp_connect_confirm;
|
|
|
|
notify.connect_indication = ircomm_lmp_connect_indication;
|
|
|
|
notify.disconnect_indication = ircomm_lmp_disconnect_indication;
|
|
|
|
notify.instance = self;
|
|
|
|
strlcpy(notify.name, "IrCOMM", sizeof(notify.name));
|
|
|
|
|
|
|
|
self->lsap = irlmp_open_lsap(LSAP_ANY, ¬ify, 0);
|
|
|
|
if (!self->lsap) {
|
2008-03-06 12:47:47 +08:00
|
|
|
IRDA_DEBUG(0,"%sfailed to allocate tsap\n", __func__ );
|
2005-04-17 06:20:36 +08:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
self->slsap_sel = self->lsap->slsap_sel;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Initialize the call-table for issuing commands
|
|
|
|
*/
|
|
|
|
self->issue.data_request = ircomm_lmp_data_request;
|
|
|
|
self->issue.connect_request = ircomm_lmp_connect_request;
|
|
|
|
self->issue.connect_response = ircomm_lmp_connect_response;
|
|
|
|
self->issue.disconnect_request = ircomm_lmp_disconnect_request;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|