|
From: Gordon M. <gm...@us...> - 2001-03-24 21:12:09
|
The following files were modified in apps/bluetooth/experimental:
Name Old version New version Comment
---- ----------- ----------- -------
Makefile 1.2 1.2.2.1=20=20=20=20=20=20=20=20=20
bt_if.c 1.2 1.2.2.1=20=20=20=20=20=20=20=20=20
bt_if.h 1.1 1.1.2.1=20=20=20=20=20=20=20=20=20
bt_ipa.c 1.1 1.1.2.1=20=20=20=20=20=20=20=20=20
bt_ipa.h 1.1 1.1.2.1=20=20=20=20=20=20=20=20=20
bt_misc.c 1.2 1.2.2.1=20=20=20=20=20=20=20=20=20
bt_misc.h 1.1 1.1.2.1=20=20=20=20=20=20=20=20=20
bt_vendor.c 1.3 1.3.2.1=20=20=20=20=20=20=20=20=20
btcon.c 1.1 1.1.2.1=20=20=20=20=20=20=20=20=20
btd.c 1.4 1.4.2.1=20=20=20=20=20=20=20=20=20
btdisc.c 1.1 1.1.2.1=20=20=20=20=20=20=20=20=20
btinit.c 1.2 1.2.2.1=20=20=20=20=20=20=20=20=20
bttest.c 1.2 1.2.2.1=20=20=20=20=20=20=20=20=20
The accompanying log:
Merged from trunk
The diff of the modified file(s):
--- Makefile 2001/03/10 12:49:32 1.2
+++ Makefile 2001/03/24 21:11:38 1.2.2.1
@@ -5,12 +5,13 @@
include $(APPS)/Rules.elinux
endif
=20
-PROGS =3D btdm memul bti btinq btcon btsend btdisc
+PROGS =3D btdm memul bti btinq bttest btcon btsend btdisc
=20
# Define HAVE_READLINE_READLINE if you have readline support, with the inc=
lude
# files in $(include_dir)/readline. Define HAVE_READLINE if you have the
# include files in $(include_dir). Define neither if you do not want to use
# readline.
+
HAVE_READLINE_READLINE =3D 1
#HAVE_READLINE =3D 1
=20
@@ -19,13 +20,14 @@
INSTOWNER =3D root
INSTGROUP =3D root
=20
-BTDOBJS =3D btd.o bttest.o bt_ipa.o bt_vendor.o bt_if.o bt_misc.o
+BTDOBJS =3D btd.o bt_ipa.o bt_vendor.o bt_if.o bt_misc.o
MEMULOBJS =3D modememul.o bt_misc.o
BTINITOBJS =3D btinit.o bt_vendor.o bt_if.o bt_misc.o
BTCONOBJS =3D btcon.o bt_if.o bt_misc.o
BTSENDOBJS =3D btsend.o bt_if.o bt_misc.o
-BTDISCOBJS =3D btdisc.o bt_if.o
-BTINQOBJS =3D btinq.o bt_if.o
+BTDISCOBJS =3D btdisc.o bt_if.o bt_misc.o
+BTINQOBJS =3D btinq.o bt_if.o bt_misc.o
+BTTESTOBJS =3D bttest.o bt_misc.o bt_vendor.o bt_if.o
=20
ifdef HAVE_READLINE_READLINE
LDLIBS +=3D -lreadline -ltermcap
@@ -63,6 +65,9 @@
$(CC) $(LDFLAGS) $^ $(LDLIBS) -o $@=09
=20
btinq: $(BTINQOBJS)
+ $(CC) $(LDFLAGS) $^ $(LDLIBS) -o $@
+
+bttest: $(BTTESTOBJS)
$(CC) $(LDFLAGS) $^ $(LDLIBS) -o $@
=20
install: $(PROGS)
--- bt_if.c 2001/03/13 22:21:17 1.2
+++ bt_if.c 2001/03/24 21:11:38 1.2.2.1
@@ -62,6 +62,29 @@
#include "bt_misc.h"
#include "bt_conf.h"
=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("ecs_testctrl");
+ }
+#else
+ printf("not yet for usermode stack...\n");
+ //hci_send_raw_data(data, 16);
+#endif
+ return 0;
+}
+
/* =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 */
/* =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 */
@@ -214,16 +237,16 @@
return result;
}
=20
-void
+int
bt_disconnect(int bt_fd, unsigned int con_id)
{
-#ifndef BT_USERSTACK
+ int ret_val;
=20
- if (ioctl(bt_fd, BTDISCONNECT, &con_id) < 0)
- {
- perror("Disconnect");
- exit(1);
- }
+#ifndef BT_USERSTACK=20=20
+ if ((ret_val =3D ioctl(bt_fd, BTDISCONNECT, &con_id)))
+ printf("Disconnect failed, %s [%d]\n", error_msg(ret_val), ret_val);
+ else
+ printf("Disconnected.\n");
#else
/* fixme<3> -- only works for rfcomm */
u8 line;=09=09=09=09
@@ -236,9 +259,10 @@
return;
}
=20=20=20
- rfcomm_disconnect_req(GET_RFCOMMLINE(con_id));
+ ret_val =3D rfcomm_disconnect_req(GET_RFCOMMLINE(con_id));
#endif
- printf("Disconnected!\n");
+
+ return ret_val;
}
=20
/* Check whether this line is lower connected in stack (rfcomm ready) */
@@ -258,6 +282,21 @@
return ret;
}
=20
+void bt_showstatus(void)
+{
+#ifdef BT_USERSTACK
+
+ char tmp[4096];
+ int len;
+ len =3D bt_read_internal(tmp);
+ tmp[len] =3D 0;
+ printf("%s", tmp);
+#else
+ /*FIXME -- read /proc/bt_internal and print it on the console */
+ printf("not yet...\n");
+#endif=20
+}
+
=20
/* fixme<1> -- add usermode stack version */
int
@@ -319,6 +358,8 @@
return 0;
}
=20
+
+
void
bt_waitline(int bt_fd, int line)
{
@@ -417,29 +458,20 @@
}
=20
void
-bt_set_bd_addr(int bt_cfd, int* bd)
-{
- int i;
- unsigned char new_bd[6];
-=20=20=20=20
- for (i =3D 0; i < 6; i++)
+bt_set_bd_addr(int bt_cfd, unsigned char *bd)
{
- new_bd[i] =3D (unsigned char) *bd++;
- }
-
printf("Setting BD address to: %02X:%02X:%02X:%02X:%02X:%02X\n",
- new_bd[0], new_bd[1], new_bd[2],
- new_bd[3], new_bd[4], new_bd[5]);
+ bd[0], bd[1], bd[2],
+ bd[3], bd[4], bd[5]);
=20=20=20=20=20
#ifndef BT_USERSTACK
- if (ioctl(bt_cfd, HCIWRITEBDADDR, new_bd) < 0)
+ if (ioctl(bt_cfd, HCIWRITEBDADDR, bd) < 0)
{
perror("Set bd addr");
}
#else
- hci_set_bd_addr(new_bd);
+ hci_set_bd_addr(bd);
#endif=20=20=20=20
-=20
printf("Please reset HW to activate bd change\n");
}
=20
@@ -449,7 +481,7 @@
int bt_set_baudrate(int bt_cfd, int spd)
{
int result;
-=20=20
+ syslog(LOG_INFO, "bt_set_baudrate %d baud", spd);
#ifdef BT_USERSTACK
tcflush(phys_fd, TCIOFLUSH);
hci_set_baudrate(spd);
@@ -473,15 +505,12 @@
}
#else
BD_ADDR rev_bd;
- int i;
-=20=20
hci_read_local_bd(rev_bd);
=20
/* return as big endian */
for (i =3D 0; i < 6; i++) {
bd_addr[i] =3D rev_bd[5-i];
}
-
#endif
}
=20
@@ -755,12 +784,15 @@
{
switch(code)
{=20
- case RES_PSMNEG:
+ case L2CAP_PSMNEG:
return "L2CAP - PSM not valid";
- case RES_SECNEG:
+ case L2CAP_SECNEG:
return "L2CAP - Security block";
- case RES_NOSRC:
+ case L2CAP_NOSRC:
return "L2CAP - Remote side has no resources";
+ case L2CAP_CON_UNRESPONSIVE:
+ return "L2CAP - Unresponsive link";
+
default:
return "L2CAP - unknown reason";
}
@@ -768,7 +800,7 @@
break;
=20=20=20=20=20
default:
- return "Unknown layer - unknown reason";
+ return "General failure";
}
}
=20
--- bt_if.h 2001/03/02 10:59:57 1.1
+++ bt_if.h 2001/03/24 21:11:38 1.1.2.1
@@ -92,10 +92,12 @@
#define MSG_LAYER_TCS 8
=20
/* Result in responses in L2CAP */
-#define RES_PSMNEG 0x02
-#define RES_SECNEG 0x03
-#define RES_NOSRC 0x04
+#define L2CAP_PSMNEG 0x02
+#define L2CAP_SECNEG 0x03
+#define L2CAP_NOSRC 0x04
=20
+#define L2CAP_CON_UNRESPONSIVE 0xf1
+
/* =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=3D */
/* IF Macros */
=20
@@ -185,8 +187,10 @@
=20
#define HCISETBAUDRATE _IOW(BT_IOC_MAGIC, 0x70, int)
#define HCIWRITEBDADDR _IOW(BT_IOC_MAGIC, 0x71, unsigned char[6])
-#define HCISENDRAWDATA _IOW(BT_IOC_MAGIC, 0x72, unsigned char[256])
=20
+/* | len 1 byte | 4 bytes hci header | data (max 256) | */
+#define HCISENDRAWDATA _IOW(BT_IOC_MAGIC, 0x72, unsigned char[261])
+
/* Used to calculate opcode for HCI commands using raw interface */
#define OPCODE_MSB(ocf, ogf) ((ocf) & 0xff)
#define OPCODE_LSB(ocf, ogf) (((ocf) >> 8) | (((ogf) & 0x3f) << 2))
@@ -245,21 +249,23 @@
*/
=20
int bt_connect(int bt_fd, unsigned char *bd, unsigned int con_id);
-void bt_disconnect(int bt_fd, unsigned int con_id);
+int bt_disconnect(int bt_fd, unsigned int con_id);
=20
void bt_waitline(int bt_fd, int line);
void bt_waitconnection(int bt_fd, int line);
void bt_waitnewconnections(int bt_fd);
int bt_isconnected(int bt_cfd, int line);
int bt_send(int fd, int len, int repeat);
+void bt_showstatus(void);
=20
/*=20
* HCI command functions=20
*/
=20
+int bt_send_raw_hci(int bt_cfd, unsigned char *data, char len);
void bt_inquiry(int bt_cfd, int nbr_rsp, int t);
int bt_set_baudrate(int bt_cfd, int spd);
-void bt_set_bd_addr(int bt_cfd, int* bd);
+void bt_set_bd_addr(int bt_cfd, unsigned char *bd);
void read_local_bd(int bt_cfd, unsigned char *bd_addr);
void read_remote_bd(int bt_cfd, unsigned char *bd_addr);
void role_switch(int bt_cfd, unsigned char *bd_addr, int role);
@@ -270,6 +276,9 @@
unsigned char major_class,=20
unsigned char minor_class,=20
unsigned char format);
+
+void enable_dut(int bt_cfd);
+
=20
/* Sets friendly name in HW to hostname */
void set_local_name(int bt_cfd, const char *local_name);
--- bt_ipa.c 2001/03/02 10:59:57 1.1
+++ bt_ipa.c 2001/03/24 21:11:38 1.1.2.1
@@ -46,6 +46,7 @@
#include <syslog.h>
#include <sys/types.h>
#include <sys/stat.h>
+#include <string.h>
=20
/* print in_addr */
#include <sys/socket.h>
@@ -81,7 +82,9 @@
/* Sends msg to IPA socket */
int ipa_write(int ipa_fd, ipa_msg *msg)
{
- syslog(LOG_INFO, "ipa_send : sending ipa request (type : %d)\n", msg->ty=
pe);
+ syslog(LOG_INFO, "ipa_send : sending ipa request (type : %d) len %d \n",
+ msg->type, msg->len);
+=20=20
return write(ipa_fd, msg, msg->len + sizeof(struct ipa_msg));
}
=20
@@ -99,6 +102,8 @@
{
c =3D read(ipa_fd, &ipa_buf+offset, 256-offset);=20=20
=20
+ syslog(LOG_INFO, "ipa_receive : got %d bytes", c);=20=20
+
if (c < 0)
return c;
=20
@@ -117,25 +122,36 @@
=20=20=20
memcpy(msg, ipa_buf, offset);
=20
+ syslog(LOG_INFO, "Got %d bytes", offset);
+
return msg_len;=20=20
}
=20
void show_ipset(struct ip_set* set, int line)
{
- printf("IP set [line:%d]\n", line);
- printf(" ip : %s\n", inet_ntoa(set->ip));
+ syslog(LOG_INFO, "IP set [line:%d]\n", line);
+
+ if (set)
+ {=20=20=20=20
+ syslog(LOG_INFO, " ip : %s\n", inet_ntoa(set->ip));
+
if (set->nbr_of_dns >=3D 1)
- printf(" dns1 : %s\n", inet_ntoa(set->dns[1]));
+ syslog(LOG_INFO, " dns1 : %s\n", inet_ntoa(set->dns[0]));
+
if (set->nbr_of_dns =3D=3D 2)
- printf(" dns2 : %s\n", inet_ntoa(set->dns[2]));
+ syslog(LOG_INFO, " dns2 : %s\n", inet_ntoa(set->dns[1]));
+
if (set->nbr_of_wins >=3D 1)
- printf(" wins 1 : %s\n", inet_ntoa(set->wins[1]));
- if (set->nbr_of_dns =3D=3D 2)
- printf(" wins2 : %s\n", inet_ntoa(set->wins[2]));
- printf(" netmask : %s\n", inet_ntoa(set->netmask));
- printf("useradius : %d\n", set->useradius);
- printf("useradiusip : %d\n", set->useradiusip);
- printf("usingmasq : %d\n", set->usingmasq);
+ syslog(LOG_INFO, " wins 1 : %s\n", inet_ntoa(set->wins[0]));
+
+ if (set->nbr_of_wins =3D=3D 2)
+ syslog(LOG_INFO, " wins2 : %s\n", inet_ntoa(set->wins[1]));
+
+ syslog(LOG_INFO, " netmask : %s\n", inet_ntoa(set->netmask));
+ syslog(LOG_INFO, "useradius : %d\n", set->useradius);
+ syslog(LOG_INFO, "useradiusip : %d\n", set->useradiusip);
+ syslog(LOG_INFO, "usingmasq : %d\n", set->usingmasq);
+ }
}
=20
#endif /* USE_IPASSIGN */
--- bt_ipa.h 2001/03/02 10:59:57 1.1
+++ bt_ipa.h 2001/03/24 21:11:38 1.1.2.1
@@ -63,8 +63,8 @@
#define IPARSP_PEERSETTINGS 11
=20
/* Status codes */
-#define IPA_STATUSFAILED 0
-#define IPA_STATUSSUCCESS 1
+#define IPA_STATUSSUCCESS 0
+#define IPA_STATUSFAILED 1
=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=3D=3D=3D*/
/* IPA Client struct */
--- bt_misc.c 2001/03/02 14:30:32 1.2
+++ bt_misc.c 2001/03/24 21:11:38 1.2.2.1
@@ -136,7 +136,7 @@
(struct sockaddr *)&server_address,=20
server_len) < 0) {
syslog(LOG_ERR, "open_socket %s failed", name);
- return 0;
+ return -1;
}
=20
=20
@@ -234,7 +234,7 @@
* Set server_name to the numerical IP of eth0 instead of using DNS or
* relying on /etc/hosts being correct. for now.
*/
-char* get_local_addr(void)
+void get_local_addr(char *str)
{
char *local_address =3D NULL;
int fd =3D socket(AF_INET, SOCK_DGRAM, 0);
@@ -249,7 +249,10 @@
{
syslog(LOG_INFO, "could not determine local IP address!\n");
}
- return local_address;
+
+ strcpy(str, local_address);
+
+ free(local_address);
}
=20
int=20
@@ -339,7 +342,7 @@
}
=20
void=20
-print_data(const char *message, char *buf, int len)
+print_data(const char *message, unsigned char *buf, int len)
{=20
int t;
printf("\n%s (%d)", message, len);
@@ -347,7 +350,7 @@
{
if((t%16)=3D=3D0)
printf("\n ");
- printf("0x%x ", buf[t]);
+ printf("0x%02x ", (uint)(buf[t]));
}
printf("\n");
}
@@ -362,14 +365,13 @@
if (strncmp(pin, "disable", 7) =3D=3D 0)
{
printf("Disable PIN usage\n");
- system("/bin/parhandclient -nosync set root.Security.UseLANSecurity ye=
s");
+ system("/bin/parhandclient -nosync set root.Security.UseLANSecurity no=
");
system("/bin/parhandclient sync");
return;
}
=20
- sprintf(exec_pinstr, "/bin/parhandclient -nosync set root.Security.PINCo=
de %s", (char*) pin);
-=20=20
/* Set pin in stack */
+ sprintf(exec_pinstr, "/bin/parhandclient -nosync set root.Security.PINCo=
de %s", (char*) pin);=20=20
=20=20=20
system("/bin/parhandclient -nosync set root.Security.UseLANSecurity yes"=
);
system(exec_pinstr);
--- bt_misc.h 2001/03/02 10:59:57 1.1
+++ bt_misc.h 2001/03/24 21:11:38 1.1.2.1
@@ -58,9 +58,9 @@
int open_tcpsocket(char *addrstr, int role);
=20
int write_pidfile(char *pidname);
-char* get_local_addr(void);
+void get_local_addr(char *str);
void print_bd_addr(char* str, unsigned char *bd);
-void print_data(const char *message, char *buf, int len);
+void print_data(const char *message, unsigned char *buf, int len);
void set_pin_code(char *pin);
=20
#endif /* __BT_MISC_H__*/
--- bt_vendor.c 2001/03/10 12:47:09 1.3
+++ bt_vendor.c 2001/03/24 21:11:38 1.3.2.1
@@ -318,7 +318,7 @@
/* Set the phys device to CSR default, 115200 */=20
void init_phys(int fd)
{
- syslog(LOG_INFO, "Setting default baud 115200");
+ syslog(LOG_INFO, "Setting default speed 115200");
fd_setup(fd, 115200, USE_FLOW_CTRL);
}
=20
@@ -365,15 +365,6 @@
hci_write_pagescan_activity(0x50, 0x20); /* more reliable connection pro=
cess */
sleep(1); /* wait for HW */
#endif
-
-#if 0
- /* fixme -- don't know how to change baudrate yet !*/=20
- /* Now set phys device speed to whatever HW was set to use */
- fd_setup(phys_fd, spd, USE_FLOW_CTRL);=20=20
-
- tcflush(phys_fd, TCIOFLUSH);
-#endif
-
}
=20
#elif HW_USED(HW_GENERIC)
--- btcon.c 2001/03/02 10:59:57 1.1
+++ btcon.c 2001/03/24 21:11:38 1.1.2.1
@@ -100,21 +100,45 @@
{
switch(opt)
{
+=20=20=20=20=20=20
case 'a':
{
- int tmp[6];
+ int tmp[6], all_read =3D 0;
bd_str =3D optarg;
- printf("Connecting to bd : %s\n", bd_str);
- if (sscanf(optarg, "%x:%x:%x:%x:%x:%x",
+ if (sscanf(optarg, "%2x%2x%2x%2x%2x%2x",
+ &tmp[0], &tmp[1], &tmp[2],
+ &tmp[3], &tmp[4], &tmp[5]) =3D=3D 6)
+ {=20=20
+ all_read =3D 1;
+ }
+ else if (sscanf(optarg, "%x:%x:%x:%x:%x:%x",
+ &tmp[0], &tmp[1], &tmp[2],
+ &tmp[3], &tmp[4], &tmp[5]) =3D=3D 6)
+ {=20=20
+ all_read =3D 1;
+ }
+ else if (sscanf(optarg, "%x-%x-%x-%x-%x-%x",
&tmp[0], &tmp[1], &tmp[2],
&tmp[3], &tmp[4], &tmp[5]) =3D=3D 6)
{
+ all_read =3D 1;
+ }
+=20=20=20=20=20=20=20=20
+ /* now convert to real bd format if syntax was correct */
+ if(all_read)
+ {
for (i =3D 0; i < 6; i++)
{
bd[i] =3D (unsigned char)tmp[i];=20
}
+ printf("Connecting to bd : %2x:%2x:%2x:%2x:%2x:%2x\n",
+ bd[0], bd[1], bd[2], bd[3], bd[4], bd[5]);
}
-=20=20=20=20=20=20=20=20
+ else
+ {
+ printf("Invalid syntax : %s\n", bd_str);
+ exit(1);
+ }
}
break;
=20
--- btd.c 2001/03/13 22:21:17 1.4
+++ btd.c 2001/03/24 21:11:38 1.4.2.1
@@ -50,6 +50,10 @@
=20=09=20=20=20=20=20
options:=20
=20=20=20
+ -i, --hwinit=20
+=09
+ default: ttyS0
+=20=20
-u, --physdev <uart device>
Sets which uart device that will be used by the stack
default: ttyS0
@@ -106,6 +110,8 @@
#include "bt_if.h"
#include "bt_ipa.h"
=20
+#define D(x) //x
+
/* =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 */
/* PPPD stuff */
=20
@@ -129,13 +135,22 @@
struct peer_struct peerlist[BT_NBR_DATAPORTS];
struct ip_set ipsetlist[BT_NBR_DATAPORTS];
=20
+static unsigned char dev[20];
+static unsigned char ip_addresses[35];
+static unsigned char ms_dns1[35];
+static unsigned char ms_dns2[35];
+static unsigned char ms_wins1[35];
+static unsigned char ms_wins2[35];
+static unsigned char netmask[35];
+
static fd_set rfd;
static struct timeval tv;
=20
#define PEER(line) (peerlist[line])
+#define IPSET(line) (ipsetlist[line])
#define STATE(line) (peerlist[line].state)
=20
-char *pppd_options[32];
+static unsigned char *pppd_options[32];
=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 */
/* IPA stuff */
@@ -145,7 +160,7 @@
static struct ipa_msg *msg;
static unsigned char ipa_buf[256];
static int parse_ipa_response(struct ipa_msg *msg);
-static int ipa_sendrequest(int line, unsigned char bd[6],
+static int ipa_sendrequest(int line, unsigned char *bd,
unsigned short type);
#endif
=20
@@ -165,6 +180,7 @@
static char local_name[LOCAL_NAME_LENGTH+1]; /* 'friendly' name in HW modu=
le */
static int do_hwinit =3D 1; /* do vendor specific initialization */
static int do_reset =3D 0; /* reset hw using I/O pins */
+static int init_hw_speed =3D 0; /* not set */
static int modem_emul =3D 1; /* default modem emulation is enabled */
static int phys_fd =3D -1; /* physical device e.g ttyS0 */
static jmp_buf jmpbuffer; /* used to jump back in program after doing rese=
t */
@@ -189,7 +205,7 @@
static void btd_killchilds(void);
static void sighandler(int sig);
=20
-static void handle_new_connections(int bt_cfd);
+static void discover_connections(int bt_cfd);
static void build_pppdopts(int line, char **opts);
static int start_pppd(int line, char *speedstr, char **opts);
=20
@@ -210,13 +226,19 @@
}
=20=20=20
/* now parse options */
-#define OPTIONS_STRING "mnRs:u:"
+#define OPTIONS_STRING "i:m:nRs:u:"
=20=20=20
while ((opt =3D getopt_long(argc, argv, OPTIONS_STRING,
long_options, &option_index)) !=3D -1)
{
switch(opt)
{
+ case 'i':
+ /* uart device */
+ init_hw_speed =3D atoi(optarg);
+ syslog(LOG_INFO, "init_hw_speed %d baud\n", init_hw_speed);
+ break;
+
case 'm':
/* uart device */
modem_emul =3D atoi(optarg);
@@ -270,12 +292,16 @@
exit(1);
}
=20=20=20
+ /* Sets initial HW baudrate */
+ if (init_hw_speed !=3D 0)
+ fd_setup(phys_fd, init_hw_speed, 1);
+ else
init_phys(phys_fd);
=20=20=20
/* Set the current tty to the bluetooth discpline */
set_bt_line_disc(phys_fd, bt_disc, physdev);
=20=20=20
- bt_cfd =3D open(BT_CTRL_TTY, O_RDWR | O_NOCTTY);
+ bt_cfd =3D bt_openctrl();
=20=20=20
init_stack(bt_cfd, atoi(speedstr));
=20=20=20
@@ -284,24 +310,22 @@
=20=20=20
/* All initialized and ready to accept connections */
=20=20=20
- bt_waitnewconnections(bt_cfd);
- syslog(LOG_INFO, "handle_new_connections");
- handle_new_connections(bt_cfd);
+ while (1)
+ {
+ int i, waiting_iparsp =3D 0;
+ tv.tv_sec =3D 1;
+ tv.tv_usec =3D 0;
=20=20=20
FD_ZERO(&rfd);=20=20
FD_SET(ipa_fd, &rfd);
FD_SET(0, &rfd);
=20=20=20
- while (1)
- {
- int i;
- tv.tv_sec =3D 2;
- tv.tv_usec =3D 0;
result =3D select(FD_SETSIZE, &rfd, (fd_set*)0,=20
(fd_set*)0, &tv);
switch (result)
{
case 0:
+ {
/* Timeout, check for new rfcomm cons */
=20=20=20=20=20=20=20
/* Check for outstanding IPA requests */
@@ -310,38 +334,42 @@
{
if ((STATE(i) =3D=3D WAITING_PPPCONF) ||
(STATE(i) =3D=3D WAITING_RETURN_PPPCONF))
- break;=20=20
+ {
+ D(syslog(LOG_INFO, "Waiting for IPA response\n"));
+ waiting_iparsp =3D 1;
+ }
i++;
}
-=20=20=20=20=20=20
- /* If no outstanding IPA req, simply wait for new rfcomm */
- if (i =3D=3D BT_NBR_DATAPORTS)
- bt_waitnewconnections(bt_cfd);=20=20=20=20=20
=20=20=20=20=20=20=20
- handle_new_connections(bt_cfd);
+ if (waiting_iparsp)
+ break;
=20=20=20=20=20=20=20
+ discover_connections(bt_cfd);
+ }
break;
=20=20=20=20=20=20=20
case -1:
+ {=20=20
/* Error */
perror("select");
+
+ /* FIXME -- e.g if ipa server restarts !!! */
+ }
break;
=20=20=20=20=20=20=20
default:
{
/* Got data on some fd */
int i;=20=20=20=20=20=20=20=20
+=20
for (i=3D0; i < result; i++)=20
{
-=20
#ifdef USE_IPASSIGN
/* IPA response */
if (FD_ISSET(ipa_fd, &rfd))
{
msg =3D (struct ipa_msg*) ipa_buf;
-=20=20=20=20=20=20=20=20=20=20=20=20
/* Got response from IPA, if ok then start pppd or modem emul =
*/
- syslog(LOG_INFO, "IPA data\n");=20=20=20=20=20=20=20=20=20=20=
=20=20
ipa_read(ipa_fd, msg);
parse_ipa_response(msg);
}
@@ -357,41 +385,44 @@
} /* main */
=20=20
/* Checks for new connections and starts pppd/modememulator */
-static void handle_new_connections(int bt_cfd)
+static void discover_connections(int bt_cfd)
{
int line;
=20=20=20
- syslog(LOG_INFO, "handle_new_connections");
+ D(syslog(LOG_INFO, "discover_connections"));
for (line =3D 0; line < BT_NBR_DATAPORTS; line++)
{
-
if ((STATE(line) =3D=3D NOCONNECTION) &&=20
bt_isconnected(bt_cfd, line))
{
- syslog(LOG_INFO, "We got a new connection on line : %d !\n", line);
+ syslog(LOG_INFO, "Found connection on line : %d !\n", line);
STATE(line) =3D CONNECTED;
=20=20=20=20=20=20=20
read_remote_bd(bt_cfd, PEER(line).remote_bd);
print_bd_addr("remote bd ", PEER(line).remote_bd);
=20=20=20=20=20=20=20
#ifdef USE_IPASSIGN
- syslog(LOG_INFO, "Sending IPA request\n");
+ D(syslog(LOG_INFO, "Sending IPA request\n"));
+=20=20=20=20=20=20
+ PEER(line).ipset =3D &IPSET(line);
+
STATE(line) =3D WAITING_PPPCONF;
- if (ipa_sendrequest(line, PEER(line).remote_bd, IPAREQ_GETIPSET) < 0)
+ if (ipa_sendrequest(line, (unsigned char *)&PEER(line).remote_bd,=20
+ IPAREQ_GETIPSET) < 0)
{
syslog(LOG_INFO, "IPA request failed or no IPA server");
=20
/* Build without IPA anyway */
STATE(line) =3D PPPCONF_DONE;
- build_pppdopts(line, pppd_options);=20=20=20=20=20=20
- start_pppd(line, speedstr, pppd_options);=20=20=20=20=20
+ build_pppdopts(line, (char**)pppd_options);=20=20=20=20=20=20
+ start_pppd(line, speedstr, (char**)pppd_options);=20=20=20=20=20
}
else
- syslog(LOG_INFO, "IPA request sent");
+ D(syslog(LOG_INFO, "IPA request sent"));
#else
STATE(line) =3D PPPCONF_DONE;
- build_pppdopts(line, pppd_options);=20=20=20=20=20=20
- start_pppd(line, speedstr, pppd_options);=20=20=20=20=20
+ build_pppdopts(line, (char**)pppd_options);=20=20=20=20=20=20
+ start_pppd(line, speedstr, (char**)pppd_options);=20=20=20=20=20
#endif=20=20
}
}
@@ -400,35 +431,28 @@
/* only server */
void build_pppdopts(int line, char **opts)
{
-=20=20
int i=3D0;
- char dev[20];
- char ip_addresses[35];
- char ms_dns1[35];
- char ms_dns2[35];
- char ms_wins1[35];
- char ms_wins2[35];
- char netmask[35];
struct ip_set *ipset =3D PEER(line).ipset;
+ char local_ip[20];
=20=20=20
#ifdef USE_IPASSIGN
show_ipset(ipset, line);
#endif
=20=20=20
- syslog(LOG_INFO, "build_pppdopts\n");
+ D(syslog(LOG_INFO, "build_pppdopts\n"));
=20=20=20
sprintf(dev, "/dev/ttyBT%d",line);
=20=20=20
/* general options */
- pppd_options[i++] =3D (char*)PPPDCMD;
- pppd_options[i++] =3D dev;
- pppd_options[i++] =3D speedstr;
+ opts[i++] =3D (char*)PPPDCMD;
+ opts[i++] =3D dev;
+ opts[i++] =3D speedstr;
=20=20=20
/* move these to options file ? */
- pppd_options[i++] =3D "crtscts";
- pppd_options[i++] =3D "nopersist";
- pppd_options[i++] =3D "silent";
- pppd_options[i++] =3D "passive";
+ opts[i++] =3D "crtscts";
+ opts[i++] =3D "nopersist";
+ opts[i++] =3D "silent";
+ opts[i++] =3D "passive";
=20=20=20
/* check if we have used IPA */
if (ipset)
@@ -439,75 +463,80 @@
/* Use radius ? */
if (ipset->useradius)
{
- pppd_options[i++] =3D "useradius";
- pppd_options[i++] =3D "auth";
- pppd_options[i++] =3D "login";
+ opts[i++] =3D "useradius";
+ opts[i++] =3D "auth";
+ opts[i++] =3D "login";
=20=20=20=20=20=20=20
if (ipset->useradiusip)
{
- pppd_options[i++] =3D "useautoip";
+ opts[i++] =3D "useautoip";
}=20=20=20
}=20=20
else=20
{
- pppd_options[i++] =3D "noauth";
+ opts[i++] =3D "noauth";
}=20=20
=20=20=20=20=20
if (ipset->proxyarp)
{
- pppd_options[i++] =3D "proxyarp";
+ opts[i++] =3D "proxyarp";
/* ktune only works on pppd version > 2.3.10 */
/* similar as doing ' echo 1 > /proc/sys/net/ipv4/ip_forward */
- pppd_options[i++] =3D "ktune"; /* enables ip_forwarding */
+ opts[i++] =3D "ktune"; /* enables ip_forwarding */
}=20=20
=20
+ get_local_addr(local_ip);
/* local/remote ip */
- sprintf(ip_addresses, "%s:%s", get_local_addr(),=20
+ sprintf(ip_addresses, "%s:%s", local_ip,=20
inet_ntoa(ipset->ip));
=20=20=20=20=20
printf("IP used : %s\n", ip_addresses);
=20=20=20=20=20
+ opts[i++] =3D ip_addresses;
+=20=20=20=20
/* DNS */
if (ipset->nbr_of_dns > 0)
{
- /* at lease one... */
- pppd_options[i++] =3D "ms-dns";
+ /* at least one... */
+ opts[i++] =3D "ms-dns";
sprintf(ms_dns1, "%s", inet_ntoa(ipset->dns[0]));
- pppd_options[i++] =3D ms_dns1;
+ opts[i++] =3D ms_dns1;
=20=20=20=20=20=20=20
if (ipset->nbr_of_dns > 1)
{
- pppd_options[i++] =3D "ms-dns";
+ opts[i++] =3D "ms-dns";
sprintf(ms_dns2, "%s", inet_ntoa(ipset->dns[1]));
- pppd_options[i++] =3D ms_dns2;
+ opts[i++] =3D ms_dns2;
}
}
=20=20=20=20=20
/* WINS */
if (ipset->nbr_of_wins > 0)
{
- /* at lease one... */
- pppd_options[i++] =3D "ms-wins";
+ /* at least one... */
+ opts[i++] =3D "ms-wins";
sprintf(ms_wins1, "%s", inet_ntoa(ipset->wins[0]));
- pppd_options[i++] =3D ms_wins1;
+ opts[i++] =3D ms_wins1;
=20=20=20=20=20=20=20
if (ipset->nbr_of_wins > 1)
{
- pppd_options[i++] =3D "ms-wins";
- sprintf(ms_dns2, "%s", inet_ntoa(ipset->wins[1]));
- pppd_options[i++] =3D ms_wins2;
+ opts[i++] =3D "ms-wins";
+ sprintf(ms_wins2, "%s", inet_ntoa(ipset->wins[1]));
+ opts[i++] =3D ms_wins2;
}
}
=20=20=20=20=20
/* Netmask */=20=20=20=20=20=20
- pppd_options[i++] =3D "netmask";
+ opts[i++] =3D "netmask";
sprintf(netmask, "%s", inet_ntoa(ipset->netmask));
- pppd_options[i++] =3D netmask;
+ opts[i++] =3D netmask;
}
else
{
- /* local ip */
- sprintf(ip_addresses, "%s:", get_local_addr());
+ get_local_addr(local_ip);
+=20=20=20=20
+ /* local IP */
+ sprintf(ip_addresses, "%s:", local_ip);
=20=20=20=20=20
/* Use /etc/ppp/options file for remote ppp settings.
IPA is needed for correct multipoint setting or use a=20
@@ -515,26 +544,28 @@
options.ttyBT1 which contains the remote IP address,=20
dns, wins etc*/
=20=20=20=20=20
- syslog(LOG_INFO, "WARNING NO REMOTE IP SET, only local %s\n",=20
+ syslog(LOG_INFO, "WARNING No remote ip addr set, only local %s",=20
ip_addresses);
- printf("WARNING NO REMOTE IP SET, only local %s\n", ip_addresses);
=20
+ opts[i++] =3D ip_addresses;
+
/* always do proxyarp */=20
- pppd_options[i++] =3D "proxyarp";
+ opts[i++] =3D "proxyarp";
=20
/* ktune only works on pppd version > 2.3.10 */
/* similar as doing ' echo 1 > /proc/sys/net/ipv4/ip_forward */
- pppd_options[i++] =3D "ktune"; /* enables ip_forwarding */
- }
+ opts[i++] =3D "ktune"; /* enables ip_forwarding */
=20=20=20
- pppd_options[i] =3D NULL;
+ } /* end -- no ipa */
=20=20=20
-#if 1
+ opts[i] =3D NULL;
+=20=20
+#if 0
/* print pppd_options */
i =3D 0;
syslog(LOG_INFO, "pppd options used :");
- while (pppd_options[i])
- syslog(LOG_INFO, "%s", pppd_options[i++]);
+ while (opts[i])
+ syslog(LOG_INFO, "%s", opts[i++]);
#endif
}
=20
@@ -543,18 +574,16 @@
char dev[20];
=20=20=20
sprintf(dev, "/dev/ttyBT%d",line);
- printf("start_pppd on %s at %s baud\n", dev, speedstr);
=20=20=20
/* check state */
if (STATE(line) !=3D PPPCONF_DONE)
{
- syslog(LOG_INFO, "Warning : ppp config not done!!!\n");
+ syslog(LOG_INFO, "Warning : ppp config not done (%d)\n", STATE(line));
return -1;
}
=20=20=20
if (PEER(line).do_modememul)=20
{
- printf("Starting modem emulator...\n");
STATE(line) =3D MODEM_STARTED;
=20=20=20=20=20
/* run modem emulator in a child */
@@ -565,9 +594,9 @@
/* replace first arg with MODEMEMULCMD (is handled by=20
modem emulator) */
=20=20=20=20=20=20=20
- pppd_options[0]=3D (char*)MODEMEMULCMD;=20=20=20=20=20=20
+ opts[0]=3D (char*)MODEMEMULCMD;
=20=20=20=20=20=20=20
- execvp(MODEMEMULCMD, pppd_options);
+ execvp(MODEMEMULCMD, opts);
=20=20=20=20=20=20=20
fprintf(stderr, "%s: no such file or directory\n", MODEMEMULCMD);
=20=20=20=20=20=20=20
@@ -578,14 +607,13 @@
}
else
{
- printf("Starting pppd...\n");
STATE(line) =3D PPPD_STARTED;
if (!(PEER(line).pppd_pid =3D vfork()))
{
syslog(LOG_INFO, "Starting pppd on %s", dev);
=20=20=20=20=20=20=20
- /* FIXME -- use opts inparam and not static pppd_options */
- execvp(PPPDCMD, pppd_options);
+ /* FIXME -- use opts inparam and not static opts */
+ execvp(PPPDCMD, opts);
=20=20=20=20=20=20=20
fprintf(stderr, "%s: no such file or directory\n", PPPDCMD);
=20=20=20=20=20=20=20
@@ -617,7 +645,7 @@
static void
sighandler(int sig)
{
- printf("Sighandler : %d\n", sig);
+ syslog(LOG_INFO, "Sighandler got signal : %d\n", sig);
=20=20=20
if (sig =3D=3D SIGUSR1)
{
@@ -629,9 +657,16 @@
{=20=20=20=20
/* Close down phys dev, run hw_upgrade and restart btd */
btd_cleanup();
- /* execvp(hw_upgrade_prog) */
+=20
+ /* FIXME -- execvp(hw_upgrade_prog) */
+=20=20=20=20
longjmp(jmpbuffer, 1);
}
+ else if (sig =3D=3D SIGTERM) /* ? */
+ {=20
+ syslog(LOG_INFO, "Got SIGTERM, now exiting");
+ exit(0);
+ }
else if (sig =3D=3D SIGCHLD)=20=20
{
int line =3D 0, pid, status;
@@ -665,18 +700,21 @@
syslog(LOG_INFO, "PPP line %d was shutdown\n", line);
=20=20=20=20=20
#ifdef USE_IPASSIGN
- /* FIXME -- Now release IPA settings */
- if (ipa_sendrequest(line, PEER(line).remote_bd, IPAREQ_RELEASEIPSET) <=
0)
+ STATE(line) =3D WAITING_RETURN_PPPCONF;
+
+ if (ipa_sendrequest(line, (unsigned char *)&PEER(line).remote_bd,=20
+ IPAREQ_RELEASEIPSET) < 0)
{
syslog(LOG_INFO, "IPA request failed or no IPA server");
- /* check if still connected first ? */
+ /* put peer into state NOCONNECTION, if still connected this
+ will be discovered in timout */
STATE(line) =3D NOCONNECTION;=20=20=20=20
}=20=20=20=20
#else
- /* check if still connected first ? */
STATE(line) =3D NOCONNECTION;=20=20=20=20
#endif
=20=20=20=20=20
+ PEER(line).ipset =3D NULL;
PEER(line).pppd_pid =3D -1;
=20=20=20=20=20
return;
@@ -691,6 +729,7 @@
static void init()
{=20
int i;
+
btd_pid =3D write_pidfile(PID_FILE);=20=20
init_sighandler();
=20=20=20
@@ -714,6 +753,7 @@
if (ipa_fd < 0)
{
printf("Found no IPA server\n");
+ exit(1);=20
}
#endif
=20=20=20
@@ -762,7 +802,6 @@
printf("btd_killchilds\n");
if (sdpsrv_pid > 0)
{
- printf("btd_killchilds SDP server\n");
syslog(LOG_INFO, "Killing SDP server\n");
kill(sdpsrv_pid, SIGTERM);
=20=20=20=20=20
@@ -777,7 +816,6 @@
{
if (STATE(line) =3D=3D PPPD_STARTED)
{
- printf("btd_killchilds PPP server on line %d\n", line);
syslog(LOG_INFO, "Killing pppd on line %d\n", line);
kill(PEER(line).pppd_pid, SIGTERM);
if (waitpid(PEER(line).pppd_pid, NULL, 0) < 0)
@@ -792,20 +830,20 @@
=20
#ifdef USE_IPASSIGN
=20
-static int ipa_sendrequest(int line, unsigned char bd[6], unsigned short t=
ype)
+static int ipa_sendrequest(int line, unsigned char *bd, unsigned short typ=
e)
{
unsigned char buf[IPA_MSG_MAXSIZE];
struct ipa_msg *msg;
struct ipa_request *req;
=20=20=20
- printf("ipa_request : type %d\n", type);
+ D(syslog(LOG_INFO, "ipa_request : type %d\n", type));
=20=20=20
msg =3D (struct ipa_msg*)buf;
msg->type =3D type;
msg->len =3D sizeof(struct ipa_request);
req =3D (struct ipa_request*)msg->msg;
req->id =3D line;
- memcpy(&req->remote_bd, &bd, 6);=20
+ memcpy(&req->remote_bd, bd, 6);=20
return ipa_write(ipa_fd, msg);
}
=20
@@ -816,20 +854,28 @@
case IPARSP_STATUS:
{
ipa_status *rsp =3D (struct ipa_status*)(msg->msg);
- syslog(LOG_INFO, "ipa_parse_msg : got status %d on line\n",=20
- rsp->status, rsp->id);=20=20
+ D(syslog(LOG_INFO, "ipa_parse_msg : got status %d on line\n",=20
+ rsp->status, rsp->id));
=20=20=20=20=20=20=20
/* Check status */
if (rsp->status =3D=3D IPA_STATUSFAILED)
- printf("parse_ipa_response : request failed [line:%d]\n", rsp->id);
+ syslog(LOG_INFO, "parse_ipa_response : request failed [line:%d]\n"=
,=20
+ rsp->id);
+ else
+ D(syslog(LOG_INFO, "parse_ipa_response : request succeeded [line:%d]\n", =
rsp->id));
=20=20=20=20=20=20=20
+ /* put peer into NOCONNECTION, if still connected this will=20
+ be discovered from timeout */
+
+ STATE(rsp->id) =3D NOCONNECTION;
+
return rsp->status;
}
=20=20=20=20=20
case IPARSP_PEERSETTINGS:
{
ipa_response* rsp =3D (struct ipa_response*)(msg->msg);
- syslog(LOG_INFO, "ipa_parse_msg : got client settings\n");=20=20=20=
=20=20=20
+ D(syslog(LOG_INFO, "ipa_parse_msg : got client settings\n"));
=20=20=20=20=20=20=20
/* Check status */
if (rsp->status =3D=3D IPA_STATUSFAILED)
@@ -842,12 +888,17 @@
/* Store ipa settings in peer struct */
memcpy(PEER(rsp->id).ipset, &rsp->set, msg->len);
=20=20=20=20=20=20=20
- /* print settings ! */
- show_ipset(PEER(rsp->id).ipset, rsp->id);
+ /* Now proceed to next state */
+ if (PEER(rsp->id).state =3D=3D WAITING_PPPCONF)
+ {
+ PEER(rsp->id).state =3D PPPCONF_DONE;
+ }=20=20=20=20=20=20
+ else
+ syslog(LOG_INFO, "Warning : Wrong state on line %d, should have been WAIT=
ING_PPPCONF", rsp->id);
=20=20=20=20=20=20=20
/* Build options and start ppp */
- build_pppdopts(rsp->id, pppd_options);
- start_pppd(rsp->id, speedstr, pppd_options);
+ build_pppdopts(rsp->id, (char**)pppd_options);
+ start_pppd(rsp->id, speedstr, (char**)pppd_options);
return 0;
}=20
=20=20=20=20=20
--- btdisc.c 2001/03/02 10:59:57 1.1
+++ btdisc.c 2001/03/24 21:11:38 1.1.2.1
@@ -71,6 +71,7 @@
{
int con_id, bt_cfd, dlci=3D-1, line, opt;
char *btdev =3D "/dev/ttyBT0"; /* default */=20=20
+ int ret_val;
=20
#ifdef __CRIS__
/* Print header if called via http */
@@ -128,8 +129,8 @@
=20
con_id =3D CREATE_RFCOMM_ID(line, dlci);
=20
- bt_disconnect(bt_cfd, con_id);
+ ret_val =3D bt_disconnect(bt_cfd, con_id);
=20=20
close(bt_cfd);
- exit(0);
+ exit(ret_val);
}
--- btinit.c 2001/03/13 22:21:17 1.2
+++ btinit.c 2001/03/24 21:11:38 1.2.2.1
@@ -107,6 +107,7 @@
=20
static int btd_pid;
static char local_name[LOCAL_NAME_LENGTH+1]; /* 'friendly' name in HW modu=
le */
+static int init_hw_speed =3D 0; /* not set */
static int do_hwinit =3D 1; /* do vendor specific initialization */
static int do_reset =3D 0; /* reset hw using I/O pins */
static int phys_fd =3D -1; /* physical device e.g ttyS0 */
@@ -155,6 +156,11 @@
{
switch(opt)
{
+ case 'i':
+ /* uart device */
+ init_hw_speed =3D atoi(optarg);
+ syslog(LOG_INFO, "init_hw_speed %d baud\n", init_hw_speed);
+ break;
=20
case 'n':
printf("setting local name to %s\n", optarg);
@@ -205,12 +211,16 @@
}
=20
/* Set default speed */
+
+ if (init_hw_speed !=3D 0)
+ fd_setup(phys_fd, init_hw_speed, 1);
+ else
init_phys(phys_fd);
=20
/* Set the current tty to the bluetooth discpline */
set_bt_line_disc(phys_fd, bt_disc, physdev);
=20=20=20
- bt_cfd =3D open(BT_CTRL_TTY, O_RDWR | O_NOCTTY);
+ bt_cfd =3D bt_openctrl();
=20
init_stack(bt_cfd, atoi(speedstr));
=20
@@ -237,6 +247,7 @@
sigemptyset(&act.sa_mask);
act.sa_flags =3D 0;
sigaction(SIGUSR1, &act, 0);
+ sigaction(SIGTERM, &act, 0);
/* other sigs ? */
}
=20
@@ -253,6 +264,10 @@
btd_cleanup();
=20=20
longjmp(jmpbuffer, 1);
+ }
+ if (sig =3D=3D SIGTERM)
+ {
+ exit(0);
}
return;
}
--- bttest.c 2001/03/10 12:49:32 1.2
+++ bttest.c 2001/03/24 21:11:38 1.2.2.1
@@ -39,12 +39,6 @@
*
*/
=20
-/*=20
- * FIXME !!!
- * THIS FILE HAS NOT BEEN TESTED AFTER SPLIT UP OF BTD=20
- * AND SHOULD NOT BE USED AS IS
- */
-
#include <sys/time.h>
#include <sys/types.h>
#include <sys/ioctl.h>
@@ -76,12 +70,10 @@
#include "bt_if.h"
#include "bt_misc.h"
#include "bt_conf.h"
+#include "bt_vendor.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=3D */
=20
-#define START_PPP 1
-#define QUIT_BTD 2
-
#define BTD_HISTORY_FILE "/tmp/btd_history"
=20
char* menu[] =3D
@@ -97,9 +89,7 @@
" readbd", /* read module bd address */
" reset", /* reset board */
" role_switch <xx:xx:xx:xx:xx:xx> <role> (0=3Dmaster, 1=3Dslave)",
-#ifdef BT_USERSTACK
" stat ", /* similar to reading the /proc/bt */
-#endif
#ifdef ECS_TEST_FUNCTIONS
" ecs_entertest <handle> (hex)",
" ecs_testctrl <par1,par2,...,par9> (hex)",
@@ -107,7 +97,6 @@
" ecs_testcon <xx:xx:xx:xx:xx:xx> (hex)",=20=20
" enable_dut", /* enable device under test mode */
#endif
- " ppp",
" quit",
#ifdef BT_USERSTACK
"",
@@ -150,27 +139,21 @@
}=20=20=20=20=20=20=20=20=20
}
=20
-void=20
-testmain(void)
+int
+main(void)
{
- int start_ppp =3D 0;
int bt_cfd;=20=20
=20
- if ((bt_cfd =3D open_device(BT_CTRL_TTY, O_RDWR, 0)) < 0)
+ /* First of all check that stack is running */
+ if (!bt_isinitiated())
{
- perror("Could not open BT control TTY\n");
+ printf("Stack not initiated, exit\n");
exit(1);
}
-
-// if (enter_cmd_mode)
- {
- read_history(BTD_HISTORY_FILE);
=20
-#ifdef BT_USERSTACK
- sleep(2); /* temp fix - wait for last command response to be returned =
*/
-#endif
+ bt_cfd =3D bt_openctrl();
=20
- printf("Now entering cmd line mode\n");
+ read_history(BTD_HISTORY_FILE);=20=20
=20
show_menu();
=20=20=20=20=20
@@ -178,62 +161,37 @@
{
int tmp;
char *line =3D (char*) readline("> ");
-
- if (!line)
- {
- start_ppp =3D 0;
- break;
- }
-
add_history(line);
=20=20=20=20=20=20=20
tmp =3D process_cmd(line, bt_cfd);
=20
- if (tmp =3D=3D START_PPP)
- {
- start_ppp =3D 1;
- break;
- }
- else if (tmp =3D=3D QUIT_BTD)
+ if (tmp =3D=3D QUIT_BTD)
{
- start_ppp =3D 0;
break;
}
free(line);
}
write_history(BTD_HISTORY_FILE);
- }=20=20
+ exit(0);
}
=20
int
process_cmd(char *buf, int bt_cfd)
{
- int bd[6];
- unsigned char my_bd_addr[6];
unsigned int tmp[11];
int repeat;
int i, line;
-#ifdef BT_USERSTACK
- unsigned char tmp_bd[6]; /* used for byte swapping */
- int server_channel, profile;
-#endif
=20=20
if (!strncmp(buf, "quit", 4))
{
return QUIT_BTD;
}
- else if (!strncmp(buf, "ppp", 3))
- {
- return START_PPP;
- }
-
- if (sscanf(buf, "rf_conn %x:%x:%x:%x:%x:%x %d %d",
+ else if (sscanf(buf, "rf_conn %x:%x:%x:%x:%x:%x %d %d",
&tmp[0], &tmp[1], &tmp[2],
&tmp[3], &tmp[4], &tmp[5],
&tmp[6], &tmp[7]) =3D=3D 8)
{
- int i;
- unsigned int con_id;
+ unsigned int con_id, i;
unsigned short srv_ch, line;
unsigned char tmp_bd[6];
=20
@@ -268,118 +226,33 @@
}
else if (sscanf(buf, "rf_send %d %d %d", &i, &repeat, &line) =3D=3D 3)
{
-#define MAXSIZE (4096*2)
- struct timeval start_t, stop_t;
- int bytes_tot =3D i*repeat;
- int avg_speed =3D 0; /* bps */
- unsigned int ms;
- char tmp[MAXSIZE];
+ int btfd;
char dev[20];
- int fd;
- int j;
-
sprintf(dev, "/dev/ttyBT%d",line);
-
-#ifndef BT_USERSTACK=20=20=20=20
- printf("Opening %s\n", dev);
- if ((fd =3D open_device(dev, O_RDWR, CLIENT)) < 0)
- {
- perror("open_device");
- return 0;
- }=20=20=20=20
- printf("Done.\n");
-
- bt_waitconnection(fd, line);
-
-#else
- /* FIXME -- currently only uses line 0 */
- if (line !=3D 0) {
- printf("No support for sending data on line %d, use line 0 instead !=
(userstack only)\n", line);
- fd=3D-1;
- return 0;
- }
-#endif
-
- if (i > MAXSIZE)
- {
- printf("Max 8192 bytes per write!\n");
- i =3D MAXSIZE;
- bytes_tot =3D i*repeat; /* update this aswell */
- }
-
- /* fill them with letters... */
- for(j =3D 0; j < i; j++)
- {
- tmp[j] =3D (j % 25) + 65;
+ btfd =3D open(dev, O_RDWR | O_NOCTTY);
+ bt_send(bt_cfd, i, repeat);
+ close(btfd);
}
-=20=20=20=20
- printf("\nNow sending %d %d-bytes packet (%d kB) on line %d\n",=20
- repeat, i, bytes_tot/1000, line);
-
- gettimeofday(&start_t, NULL);
-=20
- while (repeat)
+ else if (sscanf(buf, "setbd %x:%x:%x:%x:%x:%x",
+ &tmp[0], &tmp[1], &tmp[2], &tmp[3], &tmp[4], &tmp[5]) =
=3D=3D 6)
{
- int n =3D 0;
-#ifndef BT_USERSTACK
- n =3D write(fd, tmp, i);=20=20=20
-#else
- n =3D bt_write_top(tmp, i, line);
-#endif
+ unsigned char tmp_bd[6];
=20=20=20=20=20=20=20
- if (n <=3D0)
+ for (i =3D 0; i < 6; i++)
{
- printf("couldn't write any more data...\n\n");
- bytes_tot =3D bytes_tot-repeat*i;
- break;
- }
-
- repeat--;
- printf("%6d kB left to send... \r",
- ((repeat*i)/1000));
- fflush(stdout);
+ tmp_bd[i] =3D (unsigned char)tmp[i];
}
- gettimeofday(&stop_t, NULL);
- printf("\ndone.\n");
=20
- ms =3D (stop_t.tv_sec-start_t.tv_sec)*1000 +=20
- (stop_t.tv_usec-start_t.tv_usec)/1000;
- if (ms)
- avg_speed =3D ((8*bytes_tot)/ms);
- printf("Average TX rate : %d kbps (%d kB/s)\n", avg_speed, avg_speed/8=
);
-#ifndef BT_USERSTACK
- printf("Closing %s\n", dev);
- close_device(fd);
-#endif
- }
- else if (sscanf(buf, "setbd %x:%x:%x:%x:%x:%x",
- &bd[0], &bd[1], &bd[2], &bd[3], &bd[4], &bd[5]) =3D=3D 6)
- {
- bt_set_bd_addr(bt_cfd, &bd[0]);
+ bt_set_bd_addr(bt_cfd, &tmp_bd[0]);
}
else if (strncmp(buf, "readbd", 6) =3D=3D 0)
{
+ unsigned char my_bd_addr[6];=20=20
read_local_bd(bt_cfd, my_bd_addr);
}
- else if (strncmp(buf, "reset", 5) =3D=3D 0)
- {
- /* FIXME */
-#if 0
-
- close_device(bt_cfd);
- close_device(phys_fd);
- bt_cfd =3D -1;
- phys_fd =3D -1;
- reset_hw();
-#ifdef RESTART_ENABLED
- /* must set baud rate to default for hw again... */
- siglongjmp(jmpbuffer, 1);
-#endif
-
-#endif
- }
else if(sscanf(buf, "role_switch %x:%x:%x:%x:%x:%x %d ",
- &tmp[0], &tmp[1], &tmp[2], &tmp[3], &tmp[4], &tmp[5], &tmp[6]) =3D=3D 7)
+ &tmp[0], &tmp[1], &tmp[2], &tmp[3], &tmp[4],=20
+ &tmp[5], &tmp[6])=3D=3D 7)
{
unsigned char tmp_bd[6];
=20
@@ -422,22 +295,16 @@
ericsson_tx_test(&tmp[0]);
}
#endif
-
-/*
- * Non usermode stack functions for the stuff=20
- * below will be added later on
- */
-
-#ifdef BT_USERSTACK
else if (strncmp(buf, "stat", 4) =3D=3D 0)
{
-
- char tmp[4096];
- int len;
- len =3D bt_read_internal(tmp);
- tmp[len] =3D 0;
- printf("%s", tmp);
+ bt_showstatus();
}
+/* =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=3D=3D */
+/* FIXME !!! -- make this work for both kernel / usermode stack */
+/* =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=3D=3D */
+
+
+#ifdef BT_USERSTACK
else if (sscanf(buf, "ping %x:%x:%x:%x:%x:%x",
&bd[0], &bd[1], &bd[2], &bd[3], &bd[4], &bd[5]) =3D=3D 6)
{
@@ -575,7 +442,6 @@
printf("> error: command not recognized or wrong syntax\n");
show_menu();
}
-
return 0;
}
=20
|