|
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
+ }
}
}
}
|