| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /********************************************************************* | 
| YOSHIFUJI Hideaki | 6819bc2 | 2007-02-09 23:24:53 +0900 | [diff] [blame] | 2 |  * | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3 |  * Filename:      ircomm_lmp.c | 
 | 4 |  * Version:       1.0 | 
 | 5 |  * Description:   Interface between IrCOMM and IrLMP | 
 | 6 |  * Status:        Stable | 
 | 7 |  * Author:        Dag Brattli <dagb@cs.uit.no> | 
 | 8 |  * Created at:    Sun Jun  6 20:48:27 1999 | 
 | 9 |  * Modified at:   Sun Dec 12 13:44:17 1999 | 
 | 10 |  * Modified by:   Dag Brattli <dagb@cs.uit.no> | 
 | 11 |  * Sources:       Previous IrLPT work by Thomas Davis | 
| YOSHIFUJI Hideaki | 6819bc2 | 2007-02-09 23:24:53 +0900 | [diff] [blame] | 12 |  * | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 13 |  *     Copyright (c) 1999 Dag Brattli, All Rights Reserved. | 
 | 14 |  *     Copyright (c) 2000-2003 Jean Tourrilhes <jt@hpl.hp.com> | 
| YOSHIFUJI Hideaki | 6819bc2 | 2007-02-09 23:24:53 +0900 | [diff] [blame] | 15 |  * | 
 | 16 |  *     This program is free software; you can redistribute it and/or | 
 | 17 |  *     modify it under the terms of the GNU General Public License as | 
 | 18 |  *     published by the Free Software Foundation; either version 2 of | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 19 |  *     the License, or (at your option) any later version. | 
| YOSHIFUJI Hideaki | 6819bc2 | 2007-02-09 23:24:53 +0900 | [diff] [blame] | 20 |  * | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 21 |  *     This program is distributed in the hope that it will be useful, | 
 | 22 |  *     but WITHOUT ANY WARRANTY; without even the implied warranty of | 
 | 23 |  *     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | 
 | 24 |  *     GNU General Public License for more details. | 
| YOSHIFUJI Hideaki | 6819bc2 | 2007-02-09 23:24:53 +0900 | [diff] [blame] | 25 |  * | 
 | 26 |  *     You should have received a copy of the GNU General Public License | 
 | 27 |  *     along with this program; if not, write to the Free Software | 
 | 28 |  *     Foundation, Inc., 59 Temple Place, Suite 330, Boston, | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 29 |  *     MA 02111-1307 USA | 
| YOSHIFUJI Hideaki | 6819bc2 | 2007-02-09 23:24:53 +0900 | [diff] [blame] | 30 |  * | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 31 |  ********************************************************************/ | 
 | 32 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 33 | #include <linux/init.h> | 
 | 34 |  | 
 | 35 | #include <net/irda/irda.h> | 
 | 36 | #include <net/irda/irlmp.h> | 
 | 37 | #include <net/irda/iriap.h> | 
 | 38 | #include <net/irda/irda_device.h>	/* struct irda_skb_cb */ | 
 | 39 |  | 
 | 40 | #include <net/irda/ircomm_event.h> | 
 | 41 | #include <net/irda/ircomm_lmp.h> | 
 | 42 |  | 
 | 43 |  | 
 | 44 | /* | 
 | 45 |  * Function ircomm_lmp_connect_request (self, userdata) | 
 | 46 |  * | 
| YOSHIFUJI Hideaki | 6819bc2 | 2007-02-09 23:24:53 +0900 | [diff] [blame] | 47 |  * | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 48 |  * | 
 | 49 |  */ | 
| YOSHIFUJI Hideaki | 6819bc2 | 2007-02-09 23:24:53 +0900 | [diff] [blame] | 50 | static int ircomm_lmp_connect_request(struct ircomm_cb *self, | 
 | 51 | 				      struct sk_buff *userdata, | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 52 | 				      struct ircomm_info *info) | 
 | 53 | { | 
 | 54 | 	int ret = 0; | 
 | 55 |  | 
 | 56 | 	IRDA_DEBUG(0, "%s()\n", __FUNCTION__ ); | 
 | 57 |  | 
 | 58 | 	/* Don't forget to refcount it - should be NULL anyway */ | 
 | 59 | 	if(userdata) | 
 | 60 | 		skb_get(userdata); | 
 | 61 |  | 
 | 62 | 	ret = irlmp_connect_request(self->lsap, info->dlsap_sel, | 
| YOSHIFUJI Hideaki | 6819bc2 | 2007-02-09 23:24:53 +0900 | [diff] [blame] | 63 | 				    info->saddr, info->daddr, NULL, userdata); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 64 | 	return ret; | 
| YOSHIFUJI Hideaki | 6819bc2 | 2007-02-09 23:24:53 +0900 | [diff] [blame] | 65 | } | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 66 |  | 
 | 67 | /* | 
 | 68 |  * Function ircomm_lmp_connect_response (self, skb) | 
 | 69 |  * | 
| YOSHIFUJI Hideaki | 6819bc2 | 2007-02-09 23:24:53 +0900 | [diff] [blame] | 70 |  * | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 71 |  * | 
 | 72 |  */ | 
 | 73 | static int ircomm_lmp_connect_response(struct ircomm_cb *self, | 
 | 74 | 				       struct sk_buff *userdata) | 
 | 75 | { | 
 | 76 | 	struct sk_buff *tx_skb; | 
 | 77 | 	int ret; | 
 | 78 |  | 
 | 79 | 	IRDA_DEBUG(0, "%s()\n", __FUNCTION__ ); | 
| YOSHIFUJI Hideaki | 6819bc2 | 2007-02-09 23:24:53 +0900 | [diff] [blame] | 80 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 81 | 	/* Any userdata supplied? */ | 
 | 82 | 	if (userdata == NULL) { | 
| Samuel Ortiz | 1b0fee7 | 2006-09-27 20:06:44 -0700 | [diff] [blame] | 83 | 		tx_skb = alloc_skb(LMP_MAX_HEADER, GFP_ATOMIC); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 84 | 		if (!tx_skb) | 
 | 85 | 			return -ENOMEM; | 
 | 86 |  | 
 | 87 | 		/* Reserve space for MUX and LAP header */ | 
 | 88 | 		skb_reserve(tx_skb, LMP_MAX_HEADER); | 
 | 89 | 	} else { | 
| YOSHIFUJI Hideaki | 6819bc2 | 2007-02-09 23:24:53 +0900 | [diff] [blame] | 90 | 		/* | 
 | 91 | 		 *  Check that the client has reserved enough space for | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 92 | 		 *  headers | 
 | 93 | 		 */ | 
 | 94 | 		IRDA_ASSERT(skb_headroom(userdata) >= LMP_MAX_HEADER, | 
 | 95 | 			    return -1;); | 
 | 96 |  | 
 | 97 | 		/* Don't forget to refcount it - should be NULL anyway */ | 
 | 98 | 		skb_get(userdata); | 
 | 99 | 		tx_skb = userdata; | 
 | 100 | 	} | 
 | 101 |  | 
 | 102 | 	ret = irlmp_connect_response(self->lsap, tx_skb); | 
 | 103 |  | 
 | 104 | 	return 0; | 
 | 105 | } | 
 | 106 |  | 
| YOSHIFUJI Hideaki | 6819bc2 | 2007-02-09 23:24:53 +0900 | [diff] [blame] | 107 | static int ircomm_lmp_disconnect_request(struct ircomm_cb *self, | 
 | 108 | 					 struct sk_buff *userdata, | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 109 | 					 struct ircomm_info *info) | 
 | 110 | { | 
| YOSHIFUJI Hideaki | 6819bc2 | 2007-02-09 23:24:53 +0900 | [diff] [blame] | 111 | 	struct sk_buff *tx_skb; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 112 | 	int ret; | 
 | 113 |  | 
 | 114 | 	IRDA_DEBUG(0, "%s()\n", __FUNCTION__ ); | 
 | 115 |  | 
| YOSHIFUJI Hideaki | 6819bc2 | 2007-02-09 23:24:53 +0900 | [diff] [blame] | 116 | 	if (!userdata) { | 
| Samuel Ortiz | 1b0fee7 | 2006-09-27 20:06:44 -0700 | [diff] [blame] | 117 | 		tx_skb = alloc_skb(LMP_MAX_HEADER, GFP_ATOMIC); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 118 | 		if (!tx_skb) | 
 | 119 | 			return -ENOMEM; | 
| YOSHIFUJI Hideaki | 6819bc2 | 2007-02-09 23:24:53 +0900 | [diff] [blame] | 120 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 121 | 		/*  Reserve space for MUX and LAP header */ | 
| YOSHIFUJI Hideaki | 6819bc2 | 2007-02-09 23:24:53 +0900 | [diff] [blame] | 122 | 		skb_reserve(tx_skb, LMP_MAX_HEADER); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 123 | 		userdata = tx_skb; | 
 | 124 | 	} else { | 
 | 125 | 		/* Don't forget to refcount it - should be NULL anyway */ | 
 | 126 | 		skb_get(userdata); | 
 | 127 | 	} | 
 | 128 |  | 
 | 129 | 	ret = irlmp_disconnect_request(self->lsap, userdata); | 
 | 130 |  | 
 | 131 | 	return ret; | 
 | 132 | } | 
 | 133 |  | 
 | 134 | /* | 
 | 135 |  * Function ircomm_lmp_flow_control (skb) | 
 | 136 |  * | 
 | 137 |  *    This function is called when a data frame we have sent to IrLAP has | 
| YOSHIFUJI Hideaki | 6819bc2 | 2007-02-09 23:24:53 +0900 | [diff] [blame] | 138 |  *    been deallocated. We do this to make sure we don't flood IrLAP with | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 139 |  *    frames, since we are not using the IrTTP flow control mechanism | 
 | 140 |  */ | 
 | 141 | static void ircomm_lmp_flow_control(struct sk_buff *skb) | 
 | 142 | { | 
 | 143 | 	struct irda_skb_cb *cb; | 
 | 144 | 	struct ircomm_cb *self; | 
 | 145 | 	int line; | 
 | 146 |  | 
 | 147 | 	IRDA_ASSERT(skb != NULL, return;); | 
 | 148 |  | 
 | 149 | 	cb = (struct irda_skb_cb *) skb->cb; | 
 | 150 |  | 
 | 151 | 	IRDA_DEBUG(2, "%s()\n", __FUNCTION__ ); | 
| YOSHIFUJI Hideaki | 6819bc2 | 2007-02-09 23:24:53 +0900 | [diff] [blame] | 152 |  | 
 | 153 | 	line = cb->line; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 154 |  | 
 | 155 | 	self = (struct ircomm_cb *) hashbin_lock_find(ircomm, line, NULL); | 
| YOSHIFUJI Hideaki | 6819bc2 | 2007-02-09 23:24:53 +0900 | [diff] [blame] | 156 | 	if (!self) { | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 157 | 		IRDA_DEBUG(2, "%s(), didn't find myself\n", __FUNCTION__ ); | 
| YOSHIFUJI Hideaki | 6819bc2 | 2007-02-09 23:24:53 +0900 | [diff] [blame] | 158 | 		return; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 159 | 	} | 
 | 160 |  | 
| YOSHIFUJI Hideaki | 6819bc2 | 2007-02-09 23:24:53 +0900 | [diff] [blame] | 161 | 	IRDA_ASSERT(self != NULL, return;); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 162 | 	IRDA_ASSERT(self->magic == IRCOMM_MAGIC, return;); | 
 | 163 |  | 
 | 164 | 	self->pkt_count--; | 
 | 165 |  | 
| YOSHIFUJI Hideaki | 6819bc2 | 2007-02-09 23:24:53 +0900 | [diff] [blame] | 166 | 	if ((self->pkt_count < 2) && (self->flow_status == FLOW_STOP)) { | 
 | 167 | 		IRDA_DEBUG(2, "%s(), asking TTY to start again!\n", __FUNCTION__ ); | 
 | 168 | 		self->flow_status = FLOW_START; | 
 | 169 | 		if (self->notify.flow_indication) | 
 | 170 | 			self->notify.flow_indication(self->notify.instance, | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 171 | 						     self, FLOW_START); | 
| YOSHIFUJI Hideaki | 6819bc2 | 2007-02-09 23:24:53 +0900 | [diff] [blame] | 172 | 	} | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 173 | } | 
| YOSHIFUJI Hideaki | 6819bc2 | 2007-02-09 23:24:53 +0900 | [diff] [blame] | 174 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 175 | /* | 
 | 176 |  * Function ircomm_lmp_data_request (self, userdata) | 
 | 177 |  * | 
 | 178 |  *    Send data frame to peer device | 
 | 179 |  * | 
 | 180 |  */ | 
 | 181 | static int ircomm_lmp_data_request(struct ircomm_cb *self, | 
| YOSHIFUJI Hideaki | 6819bc2 | 2007-02-09 23:24:53 +0900 | [diff] [blame] | 182 | 				   struct sk_buff *skb, | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 183 | 				   int not_used) | 
 | 184 | { | 
 | 185 | 	struct irda_skb_cb *cb; | 
 | 186 | 	int ret; | 
 | 187 |  | 
 | 188 | 	IRDA_ASSERT(skb != NULL, return -1;); | 
 | 189 |  | 
 | 190 | 	cb = (struct irda_skb_cb *) skb->cb; | 
| YOSHIFUJI Hideaki | 6819bc2 | 2007-02-09 23:24:53 +0900 | [diff] [blame] | 191 |  | 
 | 192 | 	cb->line = self->line; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 193 |  | 
 | 194 | 	IRDA_DEBUG(4, "%s(), sending frame\n", __FUNCTION__ ); | 
 | 195 |  | 
 | 196 | 	/* Don't forget to refcount it - see ircomm_tty_do_softint() */ | 
 | 197 | 	skb_get(skb); | 
 | 198 |  | 
 | 199 | 	skb->destructor = ircomm_lmp_flow_control; | 
 | 200 |  | 
| YOSHIFUJI Hideaki | 6819bc2 | 2007-02-09 23:24:53 +0900 | [diff] [blame] | 201 | 	if ((self->pkt_count++ > 7) && (self->flow_status == FLOW_START)) { | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 202 | 		IRDA_DEBUG(2, "%s(), asking TTY to slow down!\n", __FUNCTION__ ); | 
| YOSHIFUJI Hideaki | 6819bc2 | 2007-02-09 23:24:53 +0900 | [diff] [blame] | 203 | 		self->flow_status = FLOW_STOP; | 
 | 204 | 		if (self->notify.flow_indication) | 
 | 205 | 			self->notify.flow_indication(self->notify.instance, | 
 | 206 | 						     self, FLOW_STOP); | 
 | 207 | 	} | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 208 | 	ret = irlmp_data_request(self->lsap, skb); | 
 | 209 | 	if (ret) { | 
 | 210 | 		IRDA_ERROR("%s(), failed\n", __FUNCTION__); | 
 | 211 | 		/* irlmp_data_request already free the packet */ | 
 | 212 | 	} | 
 | 213 |  | 
 | 214 | 	return ret; | 
 | 215 | } | 
 | 216 |  | 
 | 217 | /* | 
 | 218 |  * Function ircomm_lmp_data_indication (instance, sap, skb) | 
 | 219 |  * | 
 | 220 |  *    Incoming data which we must deliver to the state machine, to check | 
 | 221 |  *    we are still connected. | 
 | 222 |  */ | 
 | 223 | static int ircomm_lmp_data_indication(void *instance, void *sap, | 
 | 224 | 				      struct sk_buff *skb) | 
 | 225 | { | 
 | 226 | 	struct ircomm_cb *self = (struct ircomm_cb *) instance; | 
 | 227 |  | 
 | 228 | 	IRDA_DEBUG(4, "%s()\n", __FUNCTION__ ); | 
| YOSHIFUJI Hideaki | 6819bc2 | 2007-02-09 23:24:53 +0900 | [diff] [blame] | 229 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 230 | 	IRDA_ASSERT(self != NULL, return -1;); | 
 | 231 | 	IRDA_ASSERT(self->magic == IRCOMM_MAGIC, return -1;); | 
 | 232 | 	IRDA_ASSERT(skb != NULL, return -1;); | 
| YOSHIFUJI Hideaki | 6819bc2 | 2007-02-09 23:24:53 +0900 | [diff] [blame] | 233 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 234 | 	ircomm_do_event(self, IRCOMM_LMP_DATA_INDICATION, skb, NULL); | 
 | 235 |  | 
 | 236 | 	/* Drop reference count - see ircomm_tty_data_indication(). */ | 
 | 237 | 	dev_kfree_skb(skb); | 
 | 238 |  | 
 | 239 | 	return 0; | 
 | 240 | } | 
 | 241 |  | 
 | 242 | /* | 
| YOSHIFUJI Hideaki | 6819bc2 | 2007-02-09 23:24:53 +0900 | [diff] [blame] | 243 |  * Function ircomm_lmp_connect_confirm (instance, sap, qos, max_sdu_size, | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 244 |  *                                       max_header_size, skb) | 
 | 245 |  * | 
 | 246 |  *    Connection has been confirmed by peer device | 
 | 247 |  * | 
 | 248 |  */ | 
 | 249 | static void ircomm_lmp_connect_confirm(void *instance, void *sap, | 
| YOSHIFUJI Hideaki | 6819bc2 | 2007-02-09 23:24:53 +0900 | [diff] [blame] | 250 | 				       struct qos_info *qos, | 
 | 251 | 				       __u32 max_seg_size, | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 252 | 				       __u8 max_header_size, | 
 | 253 | 				       struct sk_buff *skb) | 
 | 254 | { | 
 | 255 | 	struct ircomm_cb *self = (struct ircomm_cb *) instance; | 
 | 256 | 	struct ircomm_info info; | 
 | 257 |  | 
 | 258 | 	IRDA_DEBUG(0, "%s()\n", __FUNCTION__ ); | 
 | 259 |  | 
 | 260 | 	IRDA_ASSERT(self != NULL, return;); | 
 | 261 | 	IRDA_ASSERT(self->magic == IRCOMM_MAGIC, return;); | 
 | 262 | 	IRDA_ASSERT(skb != NULL, return;); | 
 | 263 | 	IRDA_ASSERT(qos != NULL, return;); | 
 | 264 |  | 
 | 265 | 	info.max_data_size = max_seg_size; | 
 | 266 | 	info.max_header_size = max_header_size; | 
 | 267 | 	info.qos = qos; | 
 | 268 |  | 
 | 269 | 	ircomm_do_event(self, IRCOMM_LMP_CONNECT_CONFIRM, skb, &info); | 
 | 270 |  | 
 | 271 | 	/* Drop reference count - see ircomm_tty_connect_confirm(). */ | 
 | 272 | 	dev_kfree_skb(skb); | 
 | 273 | } | 
 | 274 |  | 
 | 275 | /* | 
 | 276 |  * Function ircomm_lmp_connect_indication (instance, sap, qos, max_sdu_size, | 
 | 277 |  *                                         max_header_size, skb) | 
 | 278 |  * | 
 | 279 |  *    Peer device wants to make a connection with us | 
 | 280 |  * | 
 | 281 |  */ | 
 | 282 | static void ircomm_lmp_connect_indication(void *instance, void *sap, | 
 | 283 | 					  struct qos_info *qos, | 
 | 284 | 					  __u32 max_seg_size, | 
 | 285 | 					  __u8 max_header_size, | 
 | 286 | 					  struct sk_buff *skb) | 
 | 287 | { | 
 | 288 | 	struct ircomm_cb *self = (struct ircomm_cb *)instance; | 
 | 289 | 	struct ircomm_info info; | 
 | 290 |  | 
 | 291 | 	IRDA_DEBUG(0, "%s()\n", __FUNCTION__ ); | 
 | 292 |  | 
 | 293 | 	IRDA_ASSERT(self != NULL, return;); | 
 | 294 | 	IRDA_ASSERT(self->magic == IRCOMM_MAGIC, return;); | 
 | 295 | 	IRDA_ASSERT(skb != NULL, return;); | 
 | 296 | 	IRDA_ASSERT(qos != NULL, return;); | 
 | 297 |  | 
 | 298 | 	info.max_data_size = max_seg_size; | 
 | 299 | 	info.max_header_size = max_header_size; | 
 | 300 | 	info.qos = qos; | 
 | 301 |  | 
 | 302 | 	ircomm_do_event(self, IRCOMM_LMP_CONNECT_INDICATION, skb, &info); | 
 | 303 |  | 
 | 304 | 	/* Drop reference count - see ircomm_tty_connect_indication(). */ | 
 | 305 | 	dev_kfree_skb(skb); | 
 | 306 | } | 
 | 307 |  | 
 | 308 | /* | 
 | 309 |  * Function ircomm_lmp_disconnect_indication (instance, sap, reason, skb) | 
 | 310 |  * | 
 | 311 |  *    Peer device has closed the connection, or the link went down for some | 
 | 312 |  *    other reason | 
 | 313 |  */ | 
| YOSHIFUJI Hideaki | 6819bc2 | 2007-02-09 23:24:53 +0900 | [diff] [blame] | 314 | static void ircomm_lmp_disconnect_indication(void *instance, void *sap, | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 315 | 					     LM_REASON reason, | 
 | 316 | 					     struct sk_buff *skb) | 
 | 317 | { | 
 | 318 | 	struct ircomm_cb *self = (struct ircomm_cb *) instance; | 
 | 319 | 	struct ircomm_info info; | 
 | 320 |  | 
 | 321 | 	IRDA_DEBUG(0, "%s()\n", __FUNCTION__ ); | 
 | 322 |  | 
 | 323 | 	IRDA_ASSERT(self != NULL, return;); | 
 | 324 | 	IRDA_ASSERT(self->magic == IRCOMM_MAGIC, return;); | 
 | 325 |  | 
 | 326 | 	info.reason = reason; | 
 | 327 |  | 
 | 328 | 	ircomm_do_event(self, IRCOMM_LMP_DISCONNECT_INDICATION, skb, &info); | 
 | 329 |  | 
 | 330 | 	/* Drop reference count - see ircomm_tty_disconnect_indication(). */ | 
 | 331 | 	if(skb) | 
 | 332 | 		dev_kfree_skb(skb); | 
 | 333 | } | 
 | 334 | /* | 
 | 335 |  * Function ircomm_open_lsap (self) | 
 | 336 |  * | 
 | 337 |  *    Open LSAP. This function will only be used when using "raw" services | 
 | 338 |  * | 
 | 339 |  */ | 
 | 340 | int ircomm_open_lsap(struct ircomm_cb *self) | 
 | 341 | { | 
 | 342 | 	notify_t notify; | 
 | 343 |  | 
 | 344 | 	IRDA_DEBUG(0, "%s()\n", __FUNCTION__ ); | 
 | 345 |  | 
 | 346 | 	/* Register callbacks */ | 
 | 347 | 	irda_notify_init(¬ify); | 
 | 348 | 	notify.data_indication       = ircomm_lmp_data_indication; | 
 | 349 | 	notify.connect_confirm       = ircomm_lmp_connect_confirm; | 
 | 350 | 	notify.connect_indication    = ircomm_lmp_connect_indication; | 
 | 351 | 	notify.disconnect_indication = ircomm_lmp_disconnect_indication; | 
 | 352 | 	notify.instance = self; | 
 | 353 | 	strlcpy(notify.name, "IrCOMM", sizeof(notify.name)); | 
 | 354 |  | 
 | 355 | 	self->lsap = irlmp_open_lsap(LSAP_ANY, ¬ify, 0); | 
 | 356 | 	if (!self->lsap) { | 
 | 357 | 		IRDA_DEBUG(0,"%sfailed to allocate tsap\n", __FUNCTION__ ); | 
 | 358 | 		return -1; | 
 | 359 | 	} | 
 | 360 | 	self->slsap_sel = self->lsap->slsap_sel; | 
 | 361 |  | 
 | 362 | 	/* | 
 | 363 | 	 *  Initialize the call-table for issuing commands | 
 | 364 | 	 */ | 
 | 365 | 	self->issue.data_request       = ircomm_lmp_data_request; | 
 | 366 | 	self->issue.connect_request    = ircomm_lmp_connect_request; | 
 | 367 | 	self->issue.connect_response   = ircomm_lmp_connect_response; | 
 | 368 | 	self->issue.disconnect_request = ircomm_lmp_disconnect_request; | 
 | 369 |  | 
 | 370 | 	return 0; | 
 | 371 | } |