|
From: Mattias A. <mat...@us...> - 2001-03-30 12:31:47
|
The following file was modified in apps/bluetooth/experimental:
Name Old version New version Comment
---- ----------- ----------- -------
bt_if.c 1.4 1.5=20=20=20=20=20=20=20=20=20=20=20=20=20
The accompanying log:
ignore bt_openctrl calls when running usermode stack
fixed usermode stack related problems
moved around some functions
added sleep after setting baudrate in usermode stack
fixed some return values
minor changes
The diff of the modified file(s):
--- bt_if.c 2001/03/26 15:33:13 1.4
+++ bt_if.c 2001/03/30 12:31:46 1.5
@@ -61,57 +61,7 @@
#include "bt_vendor.h"
#include "bt_misc.h"
#include "bt_conf.h"
-
-int bt_send_raw_hci(int bt_cfd, unsigned char *data, char len)
-{
- unsigned char buf[261];
-
- buf[0] =3D len;
-=20=20
- memcpy(buf+1, data, len);
-
- print_data("data :",(char*) buf,(int) len+1);
-
-#ifndef BT_USERSTACK=20
- if (ioctl(bt_cfd, HCISENDRAWDATA, buf) < 0)
- {
- perror("bt_send_raw_hci");
- }
-#else
- printf("not yet for usermode stack...\n");
- //hci_send_raw_data(data, 16);
-#endif
- return 0;
-}
-
-int bt_ping(int bt_cfd, unsigned char bd[6],=20
- unsigned char *data, unsigned short len)
-{
- unsigned char buf[264];
- int ret_val;
-=20=20
- printf("bt_ping\n");
-
- memcpy(buf, bd, 6);
- buf[6] =3D len>>8;
- buf[7] =3D len&0xff;
- memcpy(buf, data, len);
-
-#ifndef BT_USERSTACK=20
- if ((ret_val =3D ioctl(bt_cfd, BTPING, buf)) < 0)
- {
- printf("Error : %s\n", error_msg(ret_val));
- }
- else
- printf("Success!\n");
-
-#else
- printf("not yet for usermode stack...\n");
-#endif
- return 0;=20=20
-
-}
-
+#include "bt_user.h"
=20
/* =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D */
/* Functions common for kernel and usermode stack */
@@ -213,11 +163,16 @@
{
int bt_cfd;
printf("Now opening BT Ctrl TTY [%s]\n", BT_CTRL_TTY);
+#ifdef BT_USERSTACK
+ printf("bt_openctrl : ignored in userstack\n");
+ return FD_BTUSERCTRL;
+#else=20
if ((bt_cfd =3D open(BT_CTRL_TTY, O_RDWR | O_NOCTTY)) < 0)
{
printf("could not open %s\n", BT_CTRL_TTY);
exit(1);
}
+#endif
return bt_cfd;
}
=20
@@ -255,7 +210,7 @@
=20=20
if (line !=3D 0) {
printf("Use line 0 instead ! (usermode only)\n");
- return;
+ return -1;
}
=20
printf("Connecting srv ch %d on line %d\n", srv_ch, line);
@@ -268,7 +223,7 @@
int
bt_disconnect(int bt_fd, unsigned int con_id)
{
- int ret_val;
+ int ret_val =3D 0;
=20=20=20
#ifndef BT_USERSTACK=20=20
if ((ret_val =3D ioctl(bt_fd, BTDISCONNECT, &con_id)))
@@ -284,10 +239,10 @@
=20=20=20
if (line !=3D 0) {
printf("Use line 0 instead ! (usermode only)\n");
- return;
+ return -1;
}
=20=20=20
- ret_val =3D rfcomm_disconnect_req(GET_RFCOMMLINE(con_id));
+ rfcomm_disconnect_req(GET_RFCOMMLINE(con_id));
#endif
=20
return ret_val;
@@ -408,11 +363,9 @@
void
bt_waitnewconnections(int bt_fd)
{
- int result;
-=20=20
syslog(LOG_INFO, "bt_waitnewconnections\n");
#ifndef BT_USERSTACK
- if ((result =3D ioctl(bt_fd, BTWAITNEWCONNECTIONS)) < 0)
+ if (ioctl(bt_fd, BTWAITNEWCONNECTIONS) < 0)
{
perror("bt_waitnewconnections");
exit(1);
@@ -443,6 +396,113 @@
#endif
}
=20
+int bt_send_raw_hci(int bt_cfd, unsigned char *data, char len)
+{
+ unsigned char buf[261];
+
+ buf[0] =3D len;
+=20=20
+ memcpy(buf+1, data, len);
+
+ print_data("data :",(char*) buf,(int) len+1);
+
+#ifndef BT_USERSTACK=20
+ if (ioctl(bt_cfd, HCISENDRAWDATA, buf) < 0)
+ {
+ perror("bt_send_raw_hci");
+ }
+#else
+ printf("not yet for usermode stack...\n");
+ //hci_send_raw_data(data, 16);
+#endif
+ return 0;
+}
+
+int bt_ping(int bt_cfd, unsigned char bd[6],=20
+ unsigned char *data, unsigned short len)
+{
+ int ret_val;
+ struct ping_struct ping;
+=20=20
+ print_data("bt_ping BD : ", bd, 6);
+ memcpy(ping.bd, bd, 6);
+ ping.len =3D len;=20=20
+ memcpy(ping.data, data, len);
+=20=20
+#ifndef BT_USERSTACK=20
+ if ((ret_val =3D ioctl(bt_cfd, BTPING, &ping)) !=3D 0)
+ {
+ printf("Error : %s\n", error_msg(ret_val));
+ }
+ else
+ printf("Success!\n");
+
+#else
+ ret_val =3D l2ca_ping(bd, data, len);
+#endif
+ return ret_val;
+}
+
+
+int=20
+bt_getinfo(int bt_cfd, unsigned char bd[6], unsigned short type)
+{
+ int ret_val;
+ unsigned char msg[8];
+=20=20
+ memcpy(msg, bd, 6);
+ msg[6] =3D (unsigned char)(type>>8);
+ msg[7] =3D (unsigned char)(type&0xff);
+
+#ifndef BT_USERSTACK=20
+ if ((ret_val =3D ioctl(bt_cfd, BTGETINFO, &msg)) !=3D 0)
+ {
+ printf("Error : %s\n", error_msg(ret_val));
+ }
+ else
+ printf("Success!\n");
+#else
+ ret_val =3D l2ca_getinfo(bd, type);
+#endif
+ return ret_val;
+}
+
+
+int bt_testcmd(int bt_cfd, unsigned char *cmd)
+{
+ int ret_val;
+=20=20
+ printf("bt_testcmd\n");
+ print_data("cmd ", cmd, strlen(cmd));
+
+#ifndef BT_USERSTACK=20
+ if ((ret_val =3D ioctl(bt_cfd, BTTESTCOMMAND, cmd)) !=3D 0)
+ {
+ printf("Error : %s\n", error_msg(ret_val));
+ }
+ else
+ printf("Success!\n");
+#else
+ printf("bt_testcmd mpt for usermode stack yet\n");
+#endif
+ return ret_val;
+}
+
+int bt_force_msswitch_as_server(int bt_cfd, int enable)
+{
+ int ret_val;
+ syslog(LOG_INFO, "bt_force_msswitch_as_server : % d\n"), enable;
+#ifndef BT_USERSTACK=20
+ if ((ret_val =3D ioctl(bt_cfd, BTSETMSSWITCH, &enable)) !=3D 0)
+ {
+ printf("Error : %s\n", error_msg(ret_val));
+ }
+#else
+ hci_force_msswitch(enable);
+#endif
+ return ret_val;
+}
+
=20
/* =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D */
/* HCI functions */
@@ -512,7 +572,8 @@
syslog(LOG_INFO, "bt_set_baudrate %d baud", spd);
#ifdef BT_USERSTACK
tcflush(phys_fd, TCIOFLUSH);
- hci_set_baudrate(spd);
+ result =3D hci_set_baudrate(spd);
+ usleep(10000);
#else
if ((result =3D ioctl(bt_cfd, HCISETBAUDRATE, &spd)) < 0)
{
@@ -532,6 +593,7 @@
perror("Read bd addr");
}
#else
+ int i;
BD_ADDR rev_bd;
hci_read_local_bd(rev_bd);
=20
@@ -558,7 +620,6 @@
printf("done.\n");
}
=20=20
-
/* fixme<1> -- add "line" parameter to differentiate between the=20
remote devices */
void
@@ -584,28 +645,53 @@
}
=20
/* fixme<3> - get flags from somewhere */
-int bt_set_writescanenable(int bt_cfd, int flags)
+int bt_write_scan_enable(int bt_cfd, unsigned int flags)
{
unsigned int wrscan =3D (PAGE_SCAN_ENABLE | INQUIRY_SCAN_ENABLE);
int result;
=20=20=20
- printf("Setting write_scan_enable [0x%x]\n", wrscan);
+ syslog(LOG_INFO, "Setting write_scan_enable [0x%x]\n", wrscan);
=20
#ifdef BT_USERSTACK
- hci_write_scan_enable(wrscan);
+ result =3D hci_write_scan_enable(wrscan);
#else
=20
if ((result =3D ioctl(bt_cfd, HCIWRITESCANENABLE, &wrscan)) < 0)
{=20
- perror("HCIWRITESCANENABLE");
+ perror("bt_set_writescanenable");
exit(1);
}
#endif=09
return result;
}
=20
-/* fixme<3> get filter from somwhere */
-int bt_set_event_filter(int bt_cfd, int filter)
+void
+bt_write_pagescan_activity(int bt_cfd, unsigned int interval,=20
+ unsigned int wind)
+{
+ /* improves reliability when doing a connect */
+ syslog(LOG_INFO, "Setting write_pagescan_activity in CSR module!\n");
+
+#ifdef BT_USERSTACK
+
+ hci_write_pagescan_activity(interval, wind);
+#else
+ {
+ unsigned int tmp [2];=20=20
+ tmp[0] =3D interval;
+ tmp[1] =3D wind;
+=20=20=20=20
+ if (ioctl(bt_cfd, HCIWRITEPAGESCANACTIVITY, &tmp) < 0)
+ {=20
+ perror("bt_write_pagescan_activity");
+ exit(1);
+ }
+ }
+#endif
+}
+
+/* fixme<3> get filter from somewhere */
+int bt_set_event_filter(int bt_cfd, unsigned int filter)
{
unsigned char evfilter[3];
int result;
@@ -614,11 +700,11 @@
evfilter[1] =3D 0x00; /* All devices */
evfilter[2] =3D 0x01; /* No auto accept */=20=20
=20
- printf("Setting event filter [0x%1x 0x%1x 0x%1x]\n",=20
+ syslog(LOG_INFO, "Setting event filter [0x%1x 0x%1x 0x%1x]\n",=20
evfilter[0], evfilter[1], evfilter[2]);
=20
#ifdef BT_USERSTACK
- result =3D hci_set_event_filter(&evfilter);
+ result =3D hci_set_event_filter((u8*)&evfilter);
#else
=20
if ((result =3D ioctl(bt_cfd, HCISET_EVENT_FILTER, &evfilter)) < 0)
@@ -637,6 +723,7 @@
{
unsigned char class_of_device[3];=20
=20=20=20
+ syslog(LOG_INFO, "bt_set_classofdevice : srv class 0x%x, maj class 0x%x,=
min class 0x%x, format 0x%x", service_class, major_class, minor_class, for=
mat);
switch (format)
{
case 0:
@@ -655,13 +742,14 @@
#endif
break;
case 1:
- printf("bt_set_classofdevice, Unsupported format 0x%02x\n", format);
+ syslog(LOG_INFO, "bt_set_classofdevice, Unsupported format 0x%02x\n",=
=20
+ format);
break;
case 2:
- printf("bt_set_classofdevice, Unsupported format 0x%02x\n", format);
+ syslog(LOG_INFO, "bt_set_classofdevice, Unsupported format 0x%02x\n", =
format);
break;
default:
- printf("bt_set_classofdevice, Unsupported format 0x%02x\n", format);
+ syslog(LOG_INFO, "bt_set_classofdevice, Unsupported format 0x%02x\n", =
format);
break;
}
}
@@ -672,7 +760,7 @@
int i;
unsigned char tmp[7];
=20=09
- printf("Performing role switch to peer: %02X:%02X:%02X:%02X:%02X:%02X\n",
+ syslog(LOG_INFO, "Performing role switch to peer: %02X:%02X:%02X:%02X:%02=
X:%02X\n",
bd_addr[0], bd_addr[1], bd_addr[2],
bd_addr[3], bd_addr[4], bd_addr[5]);
=20=09
@@ -689,7 +777,7 @@
perror("role_switch");
}
#else
- role_switch(bd_addr, role);
+ hci_switch_role(bd_addr, role);
#endif
}
=20
@@ -700,15 +788,14 @@
if (ioctl(phys_fd, TIOCSETD, &bt_disc) < 0)
{
perror("Set bt line disc");
- printf("Forgot to insmod bt.o ? [bt_disc %d]\n", bt_disc);
+ syslog(LOG_INFO, "Forgot to insmod bt.o ? [bt_disc %d]\n", bt_disc);
exit(1);
}
-#else
- printf("ERROR : No line disciplines in usermode stack\n");
- exit(1);
-#endif
syslog(LOG_INFO, "Registered bluetooth line discipline on %s\n", physdev=
);
printf("Registered bluetooth line discipline on %s\n", physdev);
+#else
+ printf("set_bt_line_disc, ignored in usermode stack\n");
+#endif
}
=20
void set_local_name(int bt_cfd, const char *local_name)
@@ -771,7 +858,6 @@
/* =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D */
/* Misc functions */
=20
-
/* See spec p 769 error codes for HCI */
const char *error_msg(int err)
{
@@ -853,14 +939,15 @@
=20
#ifdef BT_USERSTACK=20=20
/* if opening bt dev or control dev simply discard and return fake fd */
- if ((strcmp(dev, btdev) =3D=3D 0) || (strcmp(dev, BT_CTRL_TTY) =3D=3D 0))
+ if ((strncmp(dev, "/dev/ttyBT", 11) =3D=3D 0) || (strcmp(dev, BT_CTRL_TT=
Y) =3D=3D 0))
return 0xb055e;
-
+#if 0 /* fixme */
if (use_local_socket)
return open_socket(dev, role);
else if (use_tcp_socket)
return open_tcpsocket(dev, role);
#endif=20=20
+#endif=20=20
=20
syslog(LOG_INFO, "Opening dev %s\n", dev);
if ((fd =3D open(dev, flags | O_NOCTTY)) < 0)
@@ -892,13 +979,14 @@
int sdpsrv_pid;
char *args[] =3D { SDPSRV_CMD, SDPSRV_CONF, SDPSRV_PROC, NULL };
=20=20=20
- syslog(LOG_INFO, "Starting SDP server\n");
+ syslog(LOG_INFO, "Starting SDP server [%s]\n", SDPSRV_CMD);=20=20
=20=20=20
if (!(sdpsrv_pid =3D vfork()))
{
execvp(SDPSRV_CMD, args);
=20
fprintf(stderr, "%s: no such file or directory\n", SDPSRV_CMD);
+ syslog(LOG_INFO, "%s not found", SDPSRV_CMD);
=20
_exit(0);
}
@@ -920,6 +1008,25 @@
=20
#ifdef BT_USERSTACK
=20
+
+#if BT_DATADUMP_DEBUG
+#define BT_DATADUMP(str, data, len) print_data(str, data, len)
+#else
+#define BT_DATADUMP(str, data, len)
+#endif
+
+#if BT_DATA_DEBUG
+#if BT_USE_TIMESTAMPS
+#define BT_DATA(fmt...) do {print_time(1);printk(BT_DBG_STR"DATA " fmt);} =
while (0)
+#else
+#define BT_DATA(fmt...) printk(BT_DBG_STR"DATA " fmt)
+#endif
+
+#else /* BT_DATA_DEBUG */
+#define BT_DATA(fmt...)
+#endif /* BT_DATA_DEBUG */
+
+
int init_read_thread(void)
{
printf("Initiating read thread\n");
@@ -949,13 +1056,21 @@
if (len > 0)
{
BT_DATA("-->|X| %3d\n", len);
- PRINTPKT("data rec : ", databuf, len);
+ BT_DATADUMP("-->|X|", databuf, len);
hci_receive_data(databuf, len);
}
}
}
}
=20
+void
+init_upper_pty(void)
+{
+ printf("init_upper_pty");
+ //open_pty();
+ //init_pty_thread();=20=20
+}
+
=20
void init_userstack()
{=20=20
@@ -969,7 +1084,7 @@
hci_init();
l2cap_init();
rfcomm_init();
- sdp_init();
+ sdp_init(SERVER);
tcs_init();
test_init();
btmem_init();
@@ -990,7 +1105,7 @@
=20
BT_DATA("<--|X| %3d\n", len);
=20
- PRINTPKT("bt_write_lower_driver ", data, len);
+ BT_DATADUMP("<--|X|", data, len);
i =3D write(phys_fd, data, len);
return i;
}
@@ -1004,6 +1119,7 @@
int bytes_sent =3D 0;
=20
BT_DATA(" |X|<-- %3d [%d]\n", count, line);
+ BT_DATADUMP("|X|<--", buf, count);
=20=20=20
while (bytes_sent!=3Dcount)
{
@@ -1030,10 +1146,13 @@
=20
int bt_receive_top(rfcomm_con *rfcomm, unsigned char *data, int len)
{
- int n;
+ int n =3D 0;
=20
BT_DATA(" |X|--> %3d [%d]\n", len, rfcomm->line);
+ BT_DATADUMP("|X|-->", data, len);
=20
+#if 0 /* fixme */
+
if (modem_emulation && !modem_connected)
{
modem_emulator(0xb055e, data, len);
@@ -1054,6 +1173,7 @@
BT_DATA("bt_receive_top: tried to write %d bytes, wrote %d\n",
len, n);
}
+#endif
=20
bt_stat.bytes_received+=3Dn;
=20
@@ -1063,7 +1183,11 @@
void
bt_connect_ind(unsigned int con_id)=20
{
- DSYS("Got connect indication on PSM %d\n", GET_PSM(con_id));
+ if (GET_PSM(con_id) =3D=3D RFCOMM_LAYER)
+ printf("bt_connect_ind : RFCOMM dlci : %d\n",=20
+ GET_RFCOMMDLCI(con_id));
+ else
+ printf("bt_connect_ind : psm %d\n", GET_PSM(con_id));
}
=20
void
@@ -1112,16 +1236,30 @@
void
bt_disconnect_ind(unsigned int con_id)=20
{
- DSYS("Got disconnect indication on PSM %d\n", GET_PSM(con_id));
+ if (GET_PSM(con_id) =3D=3D RFCOMM_LAYER)
+ printf("bt_disconnect_ind : RFCOMM dlci : %d\n",=20
+ GET_RFCOMMDLCI(con_id));
+ else
+ printf("bt_disconnect_ind : psm %d\n", GET_PSM(con_id));
}
=20
-
int
bt_register_rfcomm(struct rfcomm_con *rfcomm, u8 dlci)
{
test_rfcomm =3D rfcomm;
- test_dlci =3D dlci;
+ testdlci =3D dlci;
return 0;
+}
+
+s32
+bt_register_sdp(u8 line, u8 sdpID)
+{
+ printf("bt_register_sdp\n");
+}
+
+s32 bt_unregister_sdp(s32 line)
+{
+ printf("bt_unregister_sdp\n");
}
=20
int bt_initiated(void)
|