|
From: Mattias ?g. <mat...@us...> - 2001-03-05 11:15:48
|
The following file was modified in apps/bluetooth/experimental:
Name Old version New version Comment
---- ----------- ----------- -------
modememul.c 1.1 1.2=20=20=20=20=20=20=20=20=20=20=20=20=20
The accompanying log:
Only reply CONNECT (without OK) when receiving ATD... in modem emulator
The diff of the modified file(s):
--- modememul.c 2001/03/02 10:59:57 1.1
+++ modememul.c 2001/03/05 11:17:24 1.2
@@ -198,8 +198,6 @@
#ifdef PALM_FIX
sleep(2); /* wait for client */
#endif
- syslog(LOG_INFO, "Write : %s", ok);
- write(bt_fd, ok, strlen(ok));=20
syslog(LOG_INFO, "Write : %s", connect);
write(bt_fd, connect, strlen(connect));=20=20=20
syslog(LOG_INFO, "Modem connected !");
|
|
From: Mattias A. <mat...@us...> - 2001-04-17 15:42:52
|
The following file was modified in apps/bluetooth/experimental:
Name Old version New version Comment
---- ----------- ----------- -------
modememul.c 1.3 1.4=20=20=20=20=20=20=20=20=20=20=20=20=20
The accompanying log:
*=A0added more parsing of ppp frame to distinguish PPP connect from disconn=
ect
* removed palm fix (unused)
* added debug macro to turn off/on syslog
* minor changes & cleanup
The diff of the modified file(s):
--- modememul.c 2001/03/13 22:21:17 1.3
+++ modememul.c 2001/04/17 15:42:51 1.4
@@ -60,18 +60,20 @@
#include "btd.h"
#include "bt_misc.h"
=20
-#define PPPDCMD "pppd"
+#define D(x) //x
=20
-//#define PALM_FIX
+#define PPPDCMD "pppd"
=20
/* Modem emulator stuff */
=20
-
#define RESTART 0
#define START_PPP 1
=20
-#define PPP_DELIMITER 0x7e
+#define PPP_FLAGSEQUENCE 0x7e
+#define PPP_CONTROL_ESCAPE 0x7d
+#define PPP_CONF_REQ 0x1
#define PPP_TERM_REQ 0x5
+#define PROT_LCP 0xc021
=20
int modem_emulator(int bt_fd);
int parse_modem_data(int bt_fd, char *data, int len);
@@ -79,7 +81,6 @@
=20
/* add sig handler which traps SIGHUP */
=20
-
void
sighandler(int sig)
{
@@ -91,7 +92,6 @@
}
}
=20
-
void
init_sighandler(void)
{
@@ -125,7 +125,9 @@
exit(1);
}
=20=20=20=20=20
+ /* not necessary for BT devices... */
fd_setup(btfd, speed, USE_NO_FLOW);
+
syslog(LOG_INFO, "done.");
done =3D modem_emulator(btfd);
syslog(LOG_INFO, "Exit modem emulator");
@@ -145,8 +147,7 @@
=20
int modem_emulator(int bt_fd)
{=20
- /* FIXME -- adjust this to real speed */
- char *connect =3D "CONNECT 115200\r\n";
+ char *connect =3D "CONNECT\r\n";
char *client_server =3D "CLIENTSERVER\r\n";
char *ok =3D "OK\r\n";
char data[128];
@@ -165,39 +166,73 @@
int len =3D read(bt_fd, &data, 128);=20=20=20=20=20=20
data[len] =3D 0;
=20
+ D(syslog(LOG_INFO, "Modem emulator got %d bytes\n", len));
+=20=20=20=20=20=20
if (len <=3D 0)
return RESTART;
-
=20=20=20=20=20=20=20
- /* Check if data is a ppp frame, if so start pppd right away=20
- and hope we catch a retransmission */
+ /* Check if data is a ppp frame, if so start pppd right away */
=20=20=20=20=20=20=20
for (i =3D 0; i < len; i++)
{
- if (data[i] =3D=3D PPP_DELIMITER)
- {
- /* fixme<3> -- check prot field + LCP code for conf req aswell */
=20=09=20=20
+ if ((data[i] =3D=3D PPP_FLAGSEQUENCE))
+ {
if ((len - i) >=3D 7)
{
- if (((data[i+7]^0x20) =3D=3D PPP_TERM_REQ))
+ unsigned short prot;
+ unsigned short type;
+
+ /* check for escaped chars */=20=20=20=20=20=20=20=20=20=20=20=
=20
+ if (data[i+2] =3D=3D PPP_CONTROL_ESCAPE)=20
+ {=20
+ D(syslog(LOG_INFO, "Found ctrl esc\n"));
+ prot =3D ((data[i+4]<<8) | (data[i+5]));
+ }
+ else
+ {
+ prot =3D ((data[i+3]<<8) | (data[i+4]));
+ }
+=20=20=20=20=20=20=20=20=20=20=20=20
+ D(syslog(LOG_INFO, "prot : %x", prot));
+=20=20=20=20=20=20=20=20=20=20=20=20
+ D(print_data("ppp packet : ", data, len));
+=20=20=20=20=20=20=20=20=20=20=20=20
+ if (prot =3D=3D PROT_LCP)
+ {
+ type =3D (data[i+7]^0x20);
+=20=20=20=20=20=20=20=20=20=20=20=20=20=20
+ if (type =3D=3D PPP_TERM_REQ)
{
syslog(LOG_INFO, "Found PPP Terminate, restart modem emulator");
return RESTART;
- }
}
- syslog(LOG_INFO, "Found PPP Frame, start pppd");
+ else if (type =3D=3D PPP_CONF_REQ)
+ {=20=20
+ syslog(LOG_INFO, "Found PPP Connect, start pppd");
return START_PPP;
}
+ else
+ {
+ syslog(LOG_INFO, "Unknown PPP LCP type [%d]", type);
+ return START_PPP; /* start pppd anyway */
+ }=20
+ }
+ else
+ {
+ syslog(LOG_INFO, "Unknown PPP prot type [%d]", prot);
+ return RESTART;=20
}=20=20=20=20=20=20
+ }
+ }=20=20=20=20=20=20
+ }
=20=20=20=20=20=20=20
+ /* AT commands */
+
if(!strncasecmp(data, "ATD", 3)) /* windows standard modem */
{
syslog(LOG_INFO, "got ATD");
=20=09
-#ifdef PALM_FIX
- sleep(2); /* wait for client */
-#endif
syslog(LOG_INFO, "Write : %s", connect);
write(bt_fd, connect, strlen(connect));=20=20=20
syslog(LOG_INFO, "Modem connected !");
@@ -210,13 +245,6 @@
syslog(LOG_INFO, "Nullmodem connected !");
return START_PPP;
}
-#ifdef PALM_FIX
- else if (search_str(data, "DT")) /* palm */
- {
- syslog(LOG_INFO, "found DT");
- return START_PPP;
- }
-#endif=20=20=20=20=20=20
else
{
syslog(LOG_INFO, "Modem emulator replies OK");
@@ -226,27 +254,3 @@
}
return done;
}
-
-#ifdef PALM_FIX
-int=20
-search_str(char *data, const char *searchstr)=09
-{
- int cur =3D 0;
- int len =3D strlen(data);
-
- if (len < 0)
- return 0;
-
- while (cur < (len-strlen(searchstr)))
- {
- if(!strncasecmp(data+cur, searchstr, strlen(searchstr)))
- {
- /* found searchstr */
- //printf("search_str : found %s!\n", (char*)search_str);
- return 1;
- }
- cur++;
- }
- return 0;
-}
-#endif
|
|
From: Mats F. <ma...@us...> - 2001-05-17 10:24:04
|
The following file was modified in apps/bluetooth/experimental:
Name Old version New version Comment
---- ----------- ----------- -------
modememul.c 1.5 1.6=20=20=20=20=20=20=20=20=20=20=20=20=20
The accompanying log:
Changed function call to fd_setup(), according to changes for BCSP
The diff of the modified file(s):
--- modememul.c 2001/05/14 11:29:36 1.5
+++ modememul.c 2001/05/17 10:24:04 1.6
@@ -125,7 +125,7 @@
}
=20
/* not necessary for BT devices... */
- fd_setup(btfd, speed, USE_NO_FLOW);
+ fd_setup(btfd, speed, USE_NO_FLOW, 0);
=20
syslog(LOG_INFO, "done.");
done =3D modem_emulator(btfd);
|
|
From: Mattias A. <mat...@us...> - 2001-06-06 15:06:00
|
The following file was modified in apps/bluetooth/experimental:
Name Old version New version Comment
---- ----------- ----------- -------
modememul.c 1.7 1.8=20=20=20=20=20=20=20=20=20=20=20=20=20
The accompanying log:
* Added call to setsid =3D> become session leader to catch SIGHUPS
* Removed O_NOCTTY flag when opening ttyBTx
The diff of the modified file(s):
--- modememul.c 2001/05/17 10:36:36 1.7
+++ modememul.c 2001/06/06 15:06:00 1.8
@@ -83,8 +83,8 @@
void
sighandler(int sig)
{
- syslog(LOG_INFO, "got signal %d\n", sig);
- if (sig =3D=3D SIGQUIT)
+ syslog(LOG_INFO, "got signal %d", sig);
+ if ((sig =3D=3D SIGQUIT) || (sig =3D=3D SIGTERM || (sig =3D=3D SIGHUP)))
{
syslog(LOG_INFO, "Modem emulator exiting\n");
exit(0);
@@ -100,7 +100,9 @@
act.sa_handler =3D sighandler;
sigemptyset(&act.sa_mask);
act.sa_flags =3D 0;
+ sigaction(SIGHUP, &act, 0);
sigaction(SIGQUIT, &act, 0);
+ sigaction(SIGTERM, &act, 0); /* Received when kill cmd is used */
}
=20
int
@@ -110,15 +112,16 @@
int speed =3D 0;
int done =3D 0;
=20
- speed =3D atoi(argv[2]);
+ setsid(); /* become session leader (to catch SIGHUPS) */=20=20
+ init_sighandler();
=20
- syslog(LOG_INFO, "Opening %s (%d baud) for modem emulation\n",
- argv[1], speed);
+ speed =3D atoi(argv[2]);
=20
while (done !=3D START_PPP)
{
- syslog(LOG_INFO, "Open %s", argv[1]);
- if ((btfd =3D open(argv[1], O_RDWR | O_NOCTTY)) < 0)
+ syslog(LOG_INFO, "Starting modem emulator on %s\n", argv[1]);
+
+ if ((btfd =3D open(argv[1], O_RDWR, 0)) < 0)
{
perror("open");
exit(1);
@@ -126,11 +129,9 @@
=20
/* not necessary for BT devices... */
fd_setup(btfd, speed, USE_NO_FLOW, DONT_USE_BCSP);
-
- syslog(LOG_INFO, "done.");
done =3D modem_emulator(btfd);
- syslog(LOG_INFO, "Exit modem emulator");
close(btfd);
+ syslog(LOG_INFO, "Closing %s", argv[1], speed);=20=20
}
=20
/* replace first arg with pppd instead of modem emulator=20
@@ -154,6 +155,7 @@
fd_set rfd;
=20
syslog(LOG_INFO, "Modem emulator starting\n");
+
while (!done)
{=20=20
FD_ZERO(&rfd);=20
@@ -165,7 +167,7 @@
int len =3D read(bt_fd, &data, 128);=20=20=20=20=20=20
data[len] =3D 0;
=20=20=20=20=20=20=20
- D(syslog(LOG_INFO, "Modem emulator got %d bytes\n", len));
+ syslog(LOG_INFO, "Modem emulator got %d bytes\n", len);
=20=20=20=20=20=20=20
if (len <=3D 0)
return RESTART;=20=20=20=20=20=20
@@ -174,7 +176,6 @@
=20
for (i =3D 0; i < len; i++)
{
-
if ((data[i] =3D=3D PPP_FLAGSEQUENCE))
{
if ((len - i) >=3D 7)
|
|
From: Anders J. <and...@us...> - 2001-10-16 16:37:48
|
The following file was modified in apps/bluetooth/experimental:
Name Old version New version Comment
---- ----------- ----------- -------
modememul.c 1.13 1.14=20=20=20=20=20=20=20=20=20=20=20=20
The accompanying log:
* Made the emulator check if we got any BT-connection to prevent it from=20
starting on a disconnected line.
The diff of the modified file(s):
--- modememul.c 2001/10/03 17:48:50 1.13
+++ modememul.c 2001/10/16 16:18:49 1.14
@@ -58,6 +58,7 @@
=20
#include "btd.h"
#include "bt_misc.h"
+#include "bt_if.h"
=20
#define D(x) //x
=20
@@ -111,15 +112,28 @@
int btfd;
char *speedstr;
int done =3D 0;
+ int line =3D -1;
=20=20=20
setsid(); /* become session leader (to catch SIGHUPS) */=20=20
init_sighandler();
=20
speedstr =3D argv[2];
+ if(sscanf(argv[1], "/dev/ttyBT%d", &line) !=3D 1)
+ {
+ syslog(LOG_INFO, "Invalid arguments to modememulator\n");
+ exit(0);
+ }=20=20=20=20
=20
while (done !=3D START_PPP)
{
syslog(LOG_INFO, "Starting modem emulator on %s", argv[1]);
+
+ if(!bt_isconnected(-1, line))
+ {
+ D(syslog(LOG_INFO, "No BT connection, stopping modememulator\n"));
+ close(btfd);
+ _exit(0);
+ }
=20
if ((btfd =3D open(argv[1], O_RDWR, 0)) < 0)
{
|
|
From: Peter K. <pk...@us...> - 2001-10-16 16:56:26
|
The following file was modified in apps/bluetooth/experimental:
Name Old version New version Comment
---- ----------- ----------- -------
modememul.c 1.14 1.15=20=20=20=20=20=20=20=20=20=20=20=20
The accompanying log:
* Do not close btfd if bt_isconnected() returns false, as it is
not open at that point.
* Corrected exit values.
The diff of the modified file(s):
--- modememul.c 2001/10/16 16:18:49 1.14
+++ modememul.c 2001/10/16 16:56:25 1.15
@@ -120,8 +120,8 @@
speedstr =3D argv[2];
if(sscanf(argv[1], "/dev/ttyBT%d", &line) !=3D 1)
{
- syslog(LOG_INFO, "Invalid arguments to modememulator\n");
- exit(0);
+ fprintf(stderr, "Invalid arguments to modememulator\n");
+ exit(1);
}=20=20=20=20
=20
while (done !=3D START_PPP)
@@ -130,9 +130,8 @@
=20
if(!bt_isconnected(-1, line))
{
- D(syslog(LOG_INFO, "No BT connection, stopping modememulator\n"));
- close(btfd);
- _exit(0);
+ D(syslog(LOG_INFO, "No BT connection, stopping modememulator"));
+ exit(0);
}
=20
if ((btfd =3D open(argv[1], O_RDWR, 0)) < 0)
@@ -156,7 +155,7 @@
execvp(PPPDCMD, argv /*pppd_options*/);
=20=20=20
fprintf(stderr, "%s: no such file or directory\n", PPPDCMD);
- _exit(0);
+ exit(1);
}
=20
int modem_emulator(int bt_fd)
|
|
From: Fredrik S. <fre...@us...> - 2002-01-22 11:23:48
|
The following file was modified in apps/bluetooth/experimental:
Name Old version New version Comment
---- ----------- ----------- -------
modememul.c 1.15 1.15.2.1=20=20=20=20=20=20=20=20
The accompanying log:
Fix for weird Widcomm client used in Mercator project.
The diff of the modified file(s):
--- modememul.c 2001/10/16 16:56:25 1.15
+++ modememul.c 2002/01/22 11:23:47 1.15.2.1
@@ -60,7 +60,7 @@
#include "bt_misc.h"
#include "bt_if.h"
=20
-#define D(x) //x
+#define D(x) x
=20
#define PPPDCMD "pppd"
=20
@@ -168,6 +168,7 @@
fd_set rfd;
=20
D(syslog(LOG_INFO, "Modem emulator starting"));
+ write(bt_fd, client_server, strlen(client_server));
=20
while (!done)
{=20=20
|
|
From: Anders J. <and...@us...> - 2003-08-25 11:34:41
|
The following file was modified in apps/bluetooth/experimental:
Name Old version New version Tag Comment
---- ----------- ----------- --- -------
modememul.c 1.15 1.16=20=20=20=20=20=20=20=20=20=20=20=20=20=20
The accompanying log:
The emulator now handles packet segmented in any size, no need to receive
a whole ppp-packet in one read anymore. Some implementations insert a delay
between the first frame start byte and the rest of the data in PPP.=20
The diff of the modified file(s):
--- modememul.c 2001/10/16 16:56:25 1.15
+++ modememul.c 2003/08/25 09:03:20 1.16
@@ -65,6 +65,7 @@
#define PPPDCMD "pppd"
=20
/* Modem emulator stuff */
+#define BUFSIZE 128
=20
#define RESTART 0
#define START_PPP 1
@@ -163,8 +164,9 @@ int modem_emulator(int bt_fd)
char *connect =3D "CONNECT\r\n";
char *client_server =3D "CLIENTSERVER\r\n";
char *ok =3D "OK\r\n";
- char data[128];
- int done =3D 0, i;
+ char data[BUFSIZE + 1];
+ int done =3D 0, i, counter =3D 0;
+ int ppp_detected =3D 0;
fd_set rfd;
=20
D(syslog(LOG_INFO, "Modem emulator starting"));
@@ -177,21 +179,32 @@ int modem_emulator(int bt_fd)
=20=20=20=20=20
if (FD_ISSET(bt_fd, &rfd))
{=20
- int len =3D read(bt_fd, &data, 128);=20=20=20=20=20=20
- data[len] =3D 0;
+ int len;
=20=20=20=20=20=20=20
+ if(BUFSIZE - counter <=3D 0)
+ {
+ /* Still nothing detected after reading 128 bytes, restart the
+ modememulator and try again */
+ return RESTART;
+ }
+=20=20=20=20=20=20
+ len =3D read(bt_fd, data + counter, BUFSIZE - counter);
D(syslog(LOG_INFO, "Modem emulator got %d bytes", len));
=20=20=20=20=20=20=20
if (len <=3D 0)
return RESTART;=20=20=20=20=20=20
=20
- /* Check if data is a ppp frame, if so start pppd right away */
+ counter +=3D len;
+ data[counter] =3D 0;
=20
- for (i =3D 0; i < len; i++)
+ /* Check if data is a ppp frame, if so start pppd right away */
+ /* PPP frame detection */
+ for (i =3D 0; i < counter; i++)
{
if ((data[i] =3D=3D PPP_FLAGSEQUENCE))
{
- if ((len - i) >=3D 7)
+ ppp_detected =3D 1;
+ if ((counter - i) >=3D 7)
{
unsigned short prot;
unsigned short type;
@@ -209,7 +222,7 @@ int modem_emulator(int bt_fd)
=20=20=20=20=20=20=20=20=20=20=20=20=20
D(syslog(LOG_INFO, "prot : %x", prot));
=20=20=20=20=20=20=20=20=20=20=20=20=20
- D(print_data("ppp packet : ", data, len));
+ D(print_data("ppp packet : ", data, counter));
=20=20=20=20=20=20=20=20=20=20=20=20=20
if (prot =3D=3D PROT_LCP)
{
@@ -237,6 +250,10 @@ int modem_emulator(int bt_fd)
return RESTART;=20
}
}
+ else
+ {
+ D(syslog(LOG_INFO, "PPP frame detected but need more bytes"));
+ }
}=20=20=20=20=20=20
}
=20=20=20=20=20=20=20
@@ -260,8 +277,13 @@ int modem_emulator(int bt_fd)
}
else
{
+ /* Don't reply if PPP is detected, it's probably
+ not what the other side wants :). */
+ if(!ppp_detected)
+ {
syslog(LOG_INFO, "Modem emulator replies OK");
write(bt_fd, ok, strlen(ok));=20
+ }
}
}
}
|