Hello everyone,
After some work I was able to patch some bugs in the obexftp tool.
In our company we update the part of the firmware of our devices over Bluetooth, using the ObexFTP protocol. OpenObex is well designed enough to distinguish and use any of the hci devices (bluetooth dongles, registered with BlueZ) that are currently in service. But obexftp was assuming that only hci0 was going to be registered with BlueZ, and furthermore it will be available. This patch not only lets the user select the hci device to use (new argument for obexftp), but also in case the user didn't passed any argument, obexftp is now intelligent enough to use any of those available (usefull when hci0 is down). The patch is divided into two files. One patch bt_discovery.c.patch only applies to the file apps/bt_discovery.c it was very bad formated and I had to ident it before starting to code (obviously I used a formatter :D ident to be more accurate). The other patch is for the rest of the tools, actually I'm not making lots of modifications, but having reidented the file made diff crazy. The patch file was made following the "SubmittingPatches" doc from the Linux Kernel project.
Thanks,
Manuel Naranjo

diff -uprN obexftp-0.20.orig/apps/obexftp.c obexftp-0.20/apps/obexftp.c
--- obexftp-0.20.orig/apps/obexftp.c	2006-05-16 11:41:49.000000000 -0300
+++ obexftp-0.20/apps/obexftp.c	2007-04-28 14:55:34.000000000 -0300
@@ -176,6 +176,7 @@ static int parse_uuid(char *name, const 
 /[EMAIL PROTECTED]@*/ /[EMAIL PROTECTED]@*/ static obexftp_client_t *cli = NULL;
 #ifdef HAVE_BLUETOOTH
 static int transport = OBEX_TRANS_BLUETOOTH;
+static int hciID = -1;
 #else
 static int transport = OBEX_TRANS_IRDA;
 #endif /* HAVE_BLUETOOTH */
@@ -186,7 +187,6 @@ static int use_uuid_len = sizeof(UUID_FB
 static int use_conn=1;
 static int use_path=1;
 
-
 /* connect with given uuid. re-connect every time */
 static int cli_connect_uuid(const char *uuid, int uuid_len)
 {
@@ -207,6 +207,10 @@ static int cli_connect_uuid(const char *
 		if (!use_path) {
 			cli->quirks &= ~OBEXFTP_SPLIT_SETPATH;
 		}
+		
+#ifdef HAVE_BLUETOOTH
+		cli->hciID=hciID;
+#endif
 	}	
 	for (retry = 0; retry < 3; retry++) {
 
@@ -421,8 +425,9 @@ int main(int argc, char *argv[])
 			{"irda",	no_argument, NULL, 'i'},
 #ifdef HAVE_BLUETOOTH
 			{"bluetooth",	optional_argument, NULL, 'b'},
-#endif
 			{"channel",	required_argument, NULL, 'B'},
+			{"hci", 	required_argument, NULL, 'd'},
+#endif
 #ifdef HAVE_USB
 			{"usb",		optional_argument, NULL, 'u'},
 #endif
@@ -451,7 +456,7 @@ int main(int argc, char *argv[])
 			{0, 0, 0, 0}
 		};
 		
-		c = getopt_long (argc, argv, "-ib::B:u::t:n:U::HSL::l::c:C:f:o:g:G:p:k:XYxm:VvhN:FP",
+		c = getopt_long (argc, argv, "-ib::B:d:u::t:n:U::HSL::l::c:C:f:o:g:G:p:k:XYxm:VvhN:FP",
 				 long_options, &option_index);
 		if (c == -1)
 			break;
@@ -487,6 +492,10 @@ int main(int argc, char *argv[])
 		case 'B':
 			channel = atoi(optarg);
 			break;
+		
+		case 'd':		
+			hciID = atoi(optarg);
+			break;
 #endif /* HAVE_BLUETOOTH */
 
 #ifdef HAVE_USB
@@ -713,6 +722,7 @@ int main(int argc, char *argv[])
 #ifdef HAVE_BLUETOOTH
 				" -b, --bluetooth [<device>]  use or search a bluetooth device\n"
 				" [ -B, --channel <number> ]  use this bluetooth channel when connecting\n"
+				" [ -d --hci <device> ]       use this bluetooth dongle instead of first available\n"
 #endif
 #ifdef HAVE_USB
 				" -u, --usb [<intf>]          connect to a usb interface or list interfaces\n"
diff -uprN obexftp-0.20.orig/obexftp/client.c obexftp-0.20/obexftp/client.c
--- obexftp-0.20.orig/obexftp/client.c	2006-03-25 17:16:32.000000000 -0300
+++ obexftp-0.20/obexftp/client.c	2007-04-28 14:41:14.000000000 -0300
@@ -498,7 +498,7 @@ int obexftp_connect_uuid(obexftp_client_
 	struct sockaddr_in peer;
 #ifdef HAVE_BLUETOOTH
 	char *devicedup, *devicep;
-	bdaddr_t bdaddr;
+	bdaddr_t bdaddr, selfaddr;
 #endif
 #ifdef HAVE_USB
 	int obex_intf_cnt;
@@ -546,7 +546,7 @@ int obexftp_connect_uuid(obexftp_client_
 		break;
 
 #ifdef HAVE_BLUETOOTH
-	case OBEX_TRANS_BLUETOOTH:
+	case OBEX_TRANS_BLUETOOTH:		
 		if (!device) {
 			ret = -EINVAL;
 			break;
@@ -557,10 +557,15 @@ int obexftp_connect_uuid(obexftp_client_
 			if (*devicep == '-') *devicep = ':';
 			if (*devicep == '_') *devicep = ':';
 			if (*devicep == '/') *devicep = ':';
-		}
-		(void) str2ba(devicedup, &bdaddr); /* what is the meaning of the return code? */
+		}		
+		str2ba(devicedup, &bdaddr); /* what is the meaning of the return code? */
 		free(devicedup);
-		ret = BtOBEX_TransportConnect(cli->obexhandle, BDADDR_ANY, &bdaddr, (uint8_t)port);
+		if (cli->hciID<0)
+			ret = BtOBEX_TransportConnect(cli->obexhandle, NULL, &bdaddr, (uint8_t)port);
+		else {
+			hci_devba(cli->hciID, &selfaddr);
+			ret = BtOBEX_TransportConnect(cli->obexhandle, &selfaddr, &bdaddr, (uint8_t)port);
+		}
 		DEBUG(3, "%s() BT %d\n", __func__, ret);
 		break;
 #endif /* HAVE_BLUETOOTH */
diff -uprN obexftp-0.20.orig/obexftp/client.h obexftp-0.20/obexftp/client.h
--- obexftp-0.20.orig/obexftp/client.h	2006-01-11 12:22:51.000000000 -0300
+++ obexftp-0.20/obexftp/client.h	2007-04-28 14:06:11.000000000 -0300
@@ -109,6 +109,7 @@ typedef struct obexftp_client
 	cache_object_t *cache;
 	int cache_timeout;
 	int cache_maxsize;
+	int hciID;
 } obexftp_client_t;
 
diff -uprN obexftp-0.20.orig/apps/bt_discovery.c obexftp-0.20/apps/bt_discovery.c
--- obexftp-0.20.orig/apps/bt_discovery.c	2006-01-11 14:27:35.000000000 -0300
+++ obexftp-0.20/apps/bt_discovery.c	2007-04-28 15:06:17.000000000 -0300
@@ -21,146 +21,145 @@
 
 int discover_bt(char *addr, char **res_bdaddr, int *res_channel)
 {
-  inquiry_info *info = NULL;
-  bdaddr_t bdaddr, bdswap;
-  char name[248];
-  int dev_id = 0;
-  int num_rsp = 10;
-  int flags = 0;
-  int length = 8;
-  int dd, i;
-
-  sdp_list_t *attrid, *search, *seq, *loop;
-  uint32_t range = SDP_ATTR_PROTO_DESC_LIST;
-  /* 0x0000ffff for SDP_ATTR_REQ_RANGE */
-  sdp_session_t *sess;
-  struct hci_dev_info di;
-  uuid_t root_uuid;
-
-  if (addr && strlen(addr) == 17)
-    {
-      str2ba(addr, &bdaddr);
-    } else {
-  fprintf(stderr, "Scanning ...\n");
-  num_rsp = hci_inquiry(dev_id, length, num_rsp, NULL, &info, flags);
-
-  if(num_rsp < 0) 
-    {
-      perror("Inquiry failed.");
-      exit(1);
-    }
-
-  if ((dd = hci_open_dev(dev_id)) < 0) 
-    {
-      perror("HCI device open failed");
-      free(info);
-      exit(1);
-    }
-  
-  for(i = 0; i < num_rsp; i++) 
-    {
-      memset(name, 0, sizeof(name));
-
-      if(hci_read_remote_name(dd, &(info+i)->bdaddr, sizeof(name), name, 100000) < 0)
-	{
-	  strcpy(name, "n/a");
-	}
-
-      bacpy(&bdaddr, &(info+i)->bdaddr);
-      baswap(&bdswap, &(info+i)->bdaddr);
-
-      if (!addr || !strncasecmp(addr, name, strlen(addr)))
-        {
-          fprintf(stderr, "Using\t%s\t%s\n", batostr(&bdswap), name);
-	  break;
-	}
-      else
-        {
-          fprintf(stderr, "\t%s\t%s\n", batostr(&bdswap), name);
-	}
-  }
-  
-  close(dd);
-  free(info);
-  
-  // return 0;
-    }
-
-  // Get local bluetooth address
-  if(hci_devinfo(0, &di) < 0) 
-    {
-      perror("HCI device info failed");
-      exit(1);
-    }
-
-  // Connect to remote SDP server
-  sess = sdp_connect(&di.bdaddr, &bdaddr, SDP_RETRY_IF_BUSY);
-
-  if(!sess) 
-    {
-      perror("Failed to connect to SDP server");
-      exit(1);
-    }
-
-  baswap(&bdswap, &bdaddr);
-  *res_bdaddr = batostr(&bdswap);
-  fprintf(stderr, "Browsing %s ...\n", *res_bdaddr);
-
-  // Build linked lists
-  sdp_uuid16_create(&root_uuid, OBEX_FILETRANS_SVCLASS_ID);
-  /* or OBEX_FILETRANS_PROFILE_ID? */
-  attrid = sdp_list_append(0, &range);
-  search = sdp_list_append(0, &root_uuid);
-
-  // Get a linked list of services
-  if(sdp_service_search_attr_req(sess, search, SDP_ATTR_REQ_INDIVIDUAL, attrid, &seq) < 0)
-    {
-      perror("SDP service search");
-      sdp_close(sess);
-      exit(1);
-    }
-
-  sdp_list_free(attrid, 0);
-  sdp_list_free(search, 0);
-
-  // Loop through the list of services
-  for(loop = seq; loop; loop = loop->next)
-    {
-      sdp_record_t *rec = (sdp_record_t *) loop->data;
-      sdp_list_t *access = NULL;
-      int channel;
-
-      // Print the RFCOMM channel
-      sdp_get_access_protos(rec, &access);
-
-      if(access)
-	{
-	  channel = sdp_get_proto_port(access, RFCOMM_UUID);
-	  fprintf(stderr, "Channel: %d\n", channel);
-	  *res_channel = channel;
+	inquiry_info *info = NULL;
+	bdaddr_t bdaddr, bdswap;
+	char name[248];
+	int dev_id = 0;
+	int num_rsp = 10;
+	int flags = 0;
+	int length = 8;
+	int dd, i;
+
+	sdp_list_t *attrid, *search, *seq, *loop;
+	uint32_t range = SDP_ATTR_PROTO_DESC_LIST;
+
+	/* 0x0000ffff for SDP_ATTR_REQ_RANGE */
+	sdp_session_t *sess;
+	struct hci_dev_info di;
+	uuid_t root_uuid;
+
+	dev_id = hci_get_route(NULL);
+
+	if (dev_id < 0) {
+		perror("No HCI device was found sorry");
+		exit(1);
 	}
-    }
 
-    sdp_list_free(seq, 0);
-    sdp_close(sess);
+	if (addr && strlen(addr) == 17) {
+		str2ba(addr, &bdaddr);
+	}
+	else {
+		fprintf(stderr, "Scanning ...\n");
+		num_rsp = hci_inquiry(dev_id, length, num_rsp, NULL, &info, flags);
+
+		if (num_rsp < 0) {
+			perror("Inquiry failed.");
+			exit(1);
+		}
+
+
+		dd = hci_open_dev(dev_id);
+		if (dd < 0) {
+			perror("HCI device open failed");
+			free(info);
+			exit(1);
+		}
+
+		for (i = 0; i < num_rsp; i++) {
+			memset(name, 0, sizeof (name));
+
+			if (hci_read_remote_name(dd, &(info + i)->bdaddr, sizeof (name), name, 100000) < 0) {
+				strcpy(name, "n/a");
+			}
+
+			bacpy(&bdaddr, &(info + i)->bdaddr);
+			baswap(&bdswap, &(info + i)->bdaddr);
+
+			if (!addr || !strncasecmp(addr, name, strlen(addr))) {
+				fprintf(stderr, "Using\t%s\t%s\n", batostr(&bdswap), name);
+				break;
+			}
+			else {
+				fprintf(stderr, "\t%s\t%s\n", batostr(&bdswap), name);
+			}
+		}
+
+		close(dd);
+		free(info);
+
+		// return 0;
+	}
+
+	// Get local bluetooth address
+	if (hci_devinfo(dev_id, &di) < 0) {
+		perror("HCI device info failed");
+		exit(1);
+	}
+
+	// Connect to remote SDP server
+	sess = sdp_connect(BDADDR_ANY, &bdaddr, SDP_RETRY_IF_BUSY);
+
+	if (!sess) {
+		perror("Failed to connect to SDP server");
+		exit(1);
+	}
+
+	baswap(&bdswap, &bdaddr);
+	*res_bdaddr = batostr(&bdswap);
+	fprintf(stderr, "Browsing %s ...\n", *res_bdaddr);
+
+	// Build linked lists
+	sdp_uuid16_create(&root_uuid, OBEX_FILETRANS_SVCLASS_ID);
+	/* or OBEX_FILETRANS_PROFILE_ID? */
+	attrid = sdp_list_append(0, &range);
+	search = sdp_list_append(0, &root_uuid);
+
+	// Get a linked list of services
+	if (sdp_service_search_attr_req(sess, search, SDP_ATTR_REQ_INDIVIDUAL, attrid, &seq) < 0) {
+		perror("SDP service search");
+		sdp_close(sess);
+		exit(1);
+	}
+
+	sdp_list_free(attrid, 0);
+	sdp_list_free(search, 0);
+
+	// Loop through the list of services
+	for (loop = seq; loop; loop = loop->next) {
+		sdp_record_t *rec = (sdp_record_t *) loop->data;
+		sdp_list_t *access = NULL;
+		int channel;
+
+		// Print the RFCOMM channel
+		sdp_get_access_protos(rec, &access);
+
+		if (access) {
+			channel = sdp_get_proto_port(access, RFCOMM_UUID);
+			fprintf(stderr, "Channel: %d\n", channel);
+			*res_channel = channel;
+		}
+	}
+
+	sdp_list_free(seq, 0);
+	sdp_close(sess);
 
-    return 0;
+	return 0;
 }
 
 #else
 #include "bt_discovery.h"
 int discover_bt(char *UNUSED(addr), char **UNUSED(res_bdaddr), int *UNUSED(res_channel))
 {
-    return -1;
+	return -1;
 }
 
-#endif /* HAVE_SDPLIB */
+#endif						/* HAVE_SDPLIB */
 
 #else
 #include "bt_discovery.h"
 int discover_bt(char *UNUSED(addr), char **UNUSED(res_bdaddr), int *UNUSED(res_channel))
 {
-    return -1;
+	return -1;
 }
 
-#endif /* HAVE_BLUETOOTH */
+#endif							/* HAVE_BLUETOOTH */
-------------------------------------------------------------------------
This SF.net email is sponsored by DB2 Express
Download DB2 Express C - the FREE version of DB2 express and take
control of your XML. No limits. Just data. Click to get it now.
http://sourceforge.net/powerbar/db2/
_______________________________________________
Openobex-users mailing list
[email protected]
http://lists.sourceforge.net/lists/listinfo/openobex-users

Reply via email to