[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [bluetooth-dev] Connection management problem : modifications + bug corrected



Le Mercredi 01 Août 2001 09:51, Mattias Ågren a écrit :
> uh oh, didn't see that the code wasn't _in_ bt_disconnect_ind...
> my mistake !. See why a diff is better ? ;)
> /Mattias

You want it ? you have it.
See how many fixes the dirty casts of openbt causes !

By the way it looks like you have changed a little bit the credit flow 
control... What have you changed exactly ?

David.

>
> > -----Original Message-----
> > From: Mattias Ågren [mailto:mattias@xxxxxxx.com]
> > Sent: den 1 augusti 2001 09:39
> > To: 'david LIBAULT'
> > Cc: bluetooth-dev@xxxxxxx.com
> > Subject: RE: [bluetooth-dev] Connection management problem :
> > modifications + bug corrected
> >
> > > Le Mardi 31 Juillet 2001 16:49, Mattias Ågren a écrit :
> > > > Hi,
> > > > can you please make a 'cvs diff -udw rfcomm.c' instead ?
> > > > It is easier to see your changes.
> > > >
> > > > > bt_disconnect_ind(CREATE_RFCOMM_ID(rfcomm->line,
> >
> >    tmp_dlci));
> >
> > > > > //dli
> > > > > #ifdef __KERNEL__
> > > > > 			bt_unregister_rfcomm(rfcomm->line);
> > > > > #endif
> > > > > 		}
> > > > > 		D_CTRL(FNC"DISC, sending back UA\n");
> > > > >
> > > > > 		break;
> > > >
> > > > Isn't it nicer if rfcomm.c handles the call for
> > >
> > > bt_unregister_rfcomm ?
> > >
> > > What do you mean ? bt_unregister_rfcomm is in bluetooth.c it
> > > is called in
> > > rfcomm.c (your design)...
> >
> > Yes, bt_unregister_rfcomm is called in rfcomm.c as it is now, but your
> > proposal was too put the bt_unregister_rfcomm call in
> > bt_disconnect_ind,
> > right ?
> >
> > By the way, we will change the bt_register/unregister so that
> > it will be
> > general for any layer, not only rfcomm...  it will be something like
> >
> > bt_register_ch(line, protocol type, prototocol specific
> > struct) / bt_unregister_ch(...).
> >
> > Comments ?
> >
> > Still, I would be great with a diff of your code to see what you
> > wanted to change.
> >
> > brgds
> > Mattias
> > -
> > To unsubscribe from this list: send the line "unsubscribe
> > bluetooth-dev" in
> > the body of a message to majordomo@xxxxxxx.com
>
> -
> To unsubscribe from this list: send the line "unsubscribe bluetooth-dev" in
> the body of a message to majordomo@xxxxxxx.com
--- /home/dli/btcvs_orig/linux/drivers/char/bluetooth/rfcomm.c	Mon Jul  9 11:48:37 2001
+++ /home/dli/btcvs_multipoint/linux/drivers/char/bluetooth/rfcomm.c	Tue Jul 31 14:20:39 2001
@@ -36,7 +36,7 @@
  * the executable file might be covered by the provisions of the GNU
  * General Public License.
  *
- * $Id: rfcomm.c,v 1.116 2001/07/09 09:48:37 matsf Exp $
+ * $Id: rfcomm.c,v 1.114 2001/06/19 06:13:01 matsf Exp $
  *
  */
 
@@ -132,9 +132,8 @@
 
 #define RFCOMM_MAX_HDR_SIZE 5
 
-#define MAX_CREDITS 30
-#define START_CREDITS 7
-#define MIN_CREDITS 15
+#define MAX_CREDITS 6
+#define MIN_CREDITS 3
 
 #define DEF_RFCOMM_MTU 127
 
@@ -412,7 +411,7 @@
 	u8 control;
 	long_length length;
 	u8 data[0];
-} __attribute__ ((packed)) long_frame_head;
+} __attribute__ ((packed))8 long_frame_head;
 
 typedef struct long_frame { 
 	long_frame_head h;
@@ -748,7 +747,7 @@
 
 		/* we have an l2cap channel (server ch) */
 		D_CTRL(FNC"we already have an l2cap channel)\n");
-
+		
 		if (rfcomm->dlci[0].state != DISCONNECTED) {
 			D_ERR(FNC"DLCI:0 neither CONNECTED nor DISCONNECTED\n");
 			return 0;
@@ -1076,7 +1075,7 @@
 {
 	rfcomm_con *rfcomm;
 	short_frame *short_pkt; 
-	long_frame *long_pkt;
+//	long_frame *long_pkt;
 	u8* uih_data_start;
 	u32 uih_len;
 	u8 tmp_dlci;
@@ -1244,8 +1243,13 @@
 			rfcomm->dlci[tmp_dlci].state = DISCONNECTED;
 			send_ua(rfcomm, tmp_dlci);
 			D_CTRL("dlci %d was disconnected\n", tmp_dlci);
+//dli bt_disconnect_ind is useless then !!!
 			bt_disconnect_ind(CREATE_RFCOMM_ID(rfcomm->line, 
 							   tmp_dlci));
+//dli
+#ifdef __KERNEL__
+			bt_unregister_rfcomm(rfcomm->line);
+#endif
 		}
 		D_CTRL(FNC"DISC, sending back UA\n");
     
@@ -1254,32 +1258,53 @@
 	case UIH:
    
 		rfcomm = ((rfcomm_con*) l2cap->upper_con);
-
-		if ((short_pkt->h.length.ea) == 0) {
+//dli : NEVER use bit fields...
+//		if ((short_pkt->h.length.ea) == 0) {
 			/* Then we cast the rfcomm packet to a long rfcomm
 			   packet */ 
-			D_REC(FNC"Long UIH packet received\n");
-			long_pkt = (long_frame*) data;
-			swap_long_frame(long_pkt);
-			uih_len = long_pkt->h.length.bits.len;
-			uih_data_start = long_pkt->h.data;
-			D_REC(FNC"long packet length %d\n",
-			      uih_len);
-			if (uih_len > (len - 5)) {
-				D_WARN(FNC", Long packet length doesn't match, setting length to l2cap len - 5\n");
-				uih_len = len - 5;
-			}
+//			D_REC(FNC"Long UIH packet received\n");
+//			long_pkt = (long_frame*) data;
+//			swap_long_frame(long_pkt);
+//			uih_len = long_pkt->h.length.bits.len;
+//			uih_data_start = long_pkt->h.data;
+//			D_REC(FNC"long packet length %d\n",
+//			      uih_len);
+//			if (uih_len > (len - 5)) {
+//				D_WARN(FNC", Long packet length doesn't match, setting length to l2cap len - 5\n");
+//				uih_len = len - 5;
+//			}
 			
-		} else {
-			D_REC(FNC"Short UIH pkt received\n");
-			uih_len = short_pkt->h.length.len;
-			uih_data_start = short_pkt->data;
-			if (uih_len > (len - 4)) {
-				D_WARN(FNC", Short packet length doesn't match, setting length to l2cap len - 4\n");
-				uih_len = len - 4;
-			}
-		}
-
+//		} else {
+//			D_REC(FNC"Short UIH pkt received\n");
+//			uih_len = short_pkt->h.length.len;
+//			uih_data_start = short_pkt->data;
+//			if (uih_len > (len - 4)) {
+//				D_WARN(FNC", Short packet length doesn't match, setting length to l2cap len - 4\n");
+//				uih_len = len - 4;
+//			}
+//		}
+    if ((data[2] & 0x01) == 0) //ea bit
+    {
+//      printk("Long packet\n") ;
+      uih_len = ((data[2] & 0xFE) >> 1) + (((unsigned short) data[3]) << 7) ;
+      if (uih_len > (len - 5)) {
+        D_ERR(__FUNCTION__", Long packet length doesn't match\n") ;
+        uih_len = len - 5 ;
+      }
+      uih_data_start = data + 4 ;
+    }
+    else
+    {
+//      printk("Short packet\n") ;
+      uih_len = (data[2] & 0xFE) >> 1;
+      if (uih_len > (len - 4))
+      {
+        D_ERR(__FUNCTION__", Short packet length doesn't match\n") ;
+        uih_len = len - 4 ;
+      }
+      uih_data_start = data + 3 ;
+    }
+    
 		if (GET_PF(short_pkt->h.control)) {
 			D_REC(FNC" %d more credits on dlci:%d...\n", 
 			       *uih_data_start, tmp_dlci);
@@ -1609,11 +1634,11 @@
 			credit = pn_pkt->credit_flow;
 			nbrof_credits = pn_pkt->credits;			
 			if (credit) {
-				DSYS(FNC"Using credit flow control, initiating credits are %d on dlci %d\n", nbrof_credits, tmp_dlci);
+				D_CTRL(FNC"Using credit flow control, initiating credits are %d on dlci %d\n", nbrof_credits, tmp_dlci);
 				rfcomm->credit_flow = TRUE;
 				rfcomm->dlci[tmp_dlci].local_credits = nbrof_credits;
 				D_CTRL(FNC"Local credits:%d\n", rfcomm->dlci[tmp_dlci].local_credits); 
-				rfcomm->dlci[tmp_dlci].remote_credits = START_CREDITS;
+				rfcomm->dlci[tmp_dlci].remote_credits = MAX_CREDITS;
 				D_CTRL(FNC"Remote credits: %d\n",rfcomm->dlci[tmp_dlci].remote_credits);
 				send_pn_msg(rfcomm, pn_pkt->prior, frame_size
 					    , credit ^ 1, MAX_CREDITS, 
@@ -1839,8 +1864,9 @@
 	bt_tx_buf *tx_buf;
 	u32 rfcomm_frame_size;
 	u8  send_credit = 0;
+  u8* tmp_data ;
 		
-	D_CTRL(FNC"Creating UIH packet with %d bytes data to DLCI %d\n",
+	D_SND(FNC"Creating UIH packet with %d bytes data to DLCI %d\n",
 	       len, dlci);
 
 	if (!rfcomm->l2cap->link_up) {
@@ -1860,13 +1886,14 @@
 	if (len > SHORT_PAYLOAD_SIZE) {
 		long_frame *l_pkt;
     
-		rfcomm_frame_size = sizeof(long_frame) + len + FCS_SIZE + send_credit;
-
+//dli : dirty and not working
+//		rfcomm_frame_size = sizeof(long_frame) + len + FCS_SIZE + send_credit;
+    rfcomm_frame_size = 4 + len + FCS_SIZE + send_credit ;
 		/* Check for space in buffer, don't forget the size of the
 		   L2CAP and HCI headers */
 		if (buf_write_room() < (rfcomm_frame_size
 					+ sizeof(rfcomm_tx_buf))) {
-			return 0;
+      return 0;
 		}
 
 		tx_buf = subscribe_bt_buf(sizeof(rfcomm_tx_buf)
@@ -1885,11 +1912,18 @@
 					  rfcomm->dlci[dlci].remote_credits);
 			rfcomm->dlci[dlci].remote_credits = MAX_CREDITS;
 			D_SND(FNC": Remote credits: %d\n",rfcomm->dlci[dlci].remote_credits);
-			memcpy(l_pkt->data + 1, data, len);
-		} else {
-			memcpy(l_pkt->data, data, len);
-		}
-		l_pkt->data[len + send_credit] = crc_calc((u8*) l_pkt, SHORT_CRC_CHECK);
+//dli			memcpy(l_pkt->data + 1, data, len);
+//		} 
+//    else 
+//    {
+//			memcpy(l_pkt->data, data, len);
+// 
+		}
+//		l_pkt->data[len + send_credit] = crc_calc((u8*) l_pkt, SHORT_CRC_CHECK);
+    tmp_data = (u8*) l_pkt ;
+    memcpy(tmp_data + 4 + send_credit, data, len) ;      
+    tmp_data[len+4+send_credit] = crc_calc(tmp_data, SHORT_CRC_CHECK) ;    
+//end of fix
 		swap_long_frame(l_pkt);
 	} else {
 		short_frame *s_pkt;
@@ -2378,6 +2412,9 @@
 void
 set_uih_hdr(short_frame *uih_pkt, u8 dlci, u32 len, u8 cr)
 {
+//dli dirty fix
+  u8 *data ;
+
 	uih_pkt->h.addr.ea = 1;
 	uih_pkt->h.addr.cr = cr;
 	uih_pkt->h.addr.d = dlci & 0x1;
@@ -2385,8 +2422,12 @@
 	uih_pkt->h.control = CLR_PF(UIH);
 	
 	if (len > SHORT_PAYLOAD_SIZE) {
-		((long_frame*) uih_pkt)->h.length.bits.ea = 0;
-		((long_frame*) uih_pkt)->h.length.bits.len = len;  
+//dli Never use bit fields...
+//		((long_frame*) uih_pkt)->h.length.bits.ea = 0;
+//		((long_frame*) uih_pkt)->h.length.bits.len = len;  
+    data = (u8 *) uih_pkt ;
+    data[2] = ((u8) (len << 1)) & 0xFE ;
+    data[3] = (u8) (len >> 7) ;    
 	} else {
 		uih_pkt->h.length.ea = 1;
 		uih_pkt->h.length.len = len;