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