From a51604573a1dfaaad4304ffbf918e91617acf468 Mon Sep 17 00:00:00 2001 From: short <> Date: Sat, 9 Mar 2002 22:51:58 +0000 Subject: [PATCH] datacalls decoding patches --- common/devices/unixserial.c | 15 ++++++++++- common/files/cfgreader.c | 2 +- common/misc.c | 2 ++ common/newmodules/n6110.c | 2 +- common/protocol/fbus.c | 62 ++++++++++++++++++++++++++++++++++++++------- gnokii/gnokii.c | 15 ++++++++++- include/config.h.in.in | 10 ++++++++ include/protocol/fbus.h | 2 ++ 8 files changed, 97 insertions(+), 13 deletions(-) diff --git a/common/devices/unixserial.c b/common/devices/unixserial.c index bc7e37e..7ad6128 100644 --- a/common/devices/unixserial.c +++ b/common/devices/unixserial.c @@ -81,8 +81,10 @@ int serial_open(__const char *__file, int __oflag) { if(retcode==-1) { perror("Gnokii serial_open:tcgetattr"); /* Don't call serial_close since serial_termios is not valid */ +#if 0 close(__fd); return(-1); +#endif } return __fd; @@ -108,7 +110,7 @@ int serial_opendevice(__const char *__file, int __with_odd_parity, int __with_as /* Open device */ - fd = serial_open(__file, O_RDWR | O_NOCTTY | O_NONBLOCK); + fd = serial_open(__file, O_RDONLY | O_NOCTTY | O_NONBLOCK); if (fd < 0) return fd; @@ -119,8 +121,10 @@ int serial_opendevice(__const char *__file, int __with_odd_parity, int __with_as retcode = fcntl(fd, F_SETOWN, getpid()); if (retcode == -1){ perror("Gnokii serial_opendevice: fnctl(F_SETOWN)"); +#if 0 serial_close(fd); return(-1); +#endif } #endif @@ -130,8 +134,10 @@ int serial_opendevice(__const char *__file, int __with_odd_parity, int __with_as retcode=fcntl(fd, F_SETFL, FASYNC); if (retcode == -1){ perror("Gnokii serial_opendevice: fnctl(F_SETFL)"); +#if 0 serial_close(fd); return(-1); +#endif } } @@ -161,15 +167,19 @@ int serial_opendevice(__const char *__file, int __with_odd_parity, int __with_as retcode=tcflush(fd, TCIFLUSH); if (retcode == -1) { perror("Gnokii serial_opendevice: tcflush"); +#if 0 serial_close(fd); return(-1); +#endif } retcode=tcsetattr(fd, TCSANOW, &tp); if (retcode == -1){ perror("Gnokii serial_opendevice: tcsetattr"); +#if 0 serial_close(fd); return(-1); +#endif } return fd; @@ -260,7 +270,10 @@ size_t serial_read(int __fd, __ptr_t __buf, size_t __nbytes) { size_t serial_write(int __fd, __const __ptr_t __buf, size_t __n) { +#if 0 return (write(__fd, __buf, __n)); +#endif + return __n; } #endif /* WIN32 */ diff --git a/common/files/cfgreader.c b/common/files/cfgreader.c index 9908cc1..fc087f6 100644 --- a/common/files/cfgreader.c +++ b/common/files/cfgreader.c @@ -254,7 +254,7 @@ struct CFG_Header *CFG_FindGnokiirc() #else homedir = getenv("HOME"); if (homedir) strncpy(rcfile, homedir, 200); - strncat(rcfile, "/.gnokiirc", 200); + strncat(rcfile, "/.mygnokiirc", 200); #endif /* Try opening .gnokirc from users home directory first */ diff --git a/common/misc.c b/common/misc.c index b17a93e..53306bc 100644 --- a/common/misc.c +++ b/common/misc.c @@ -83,6 +83,8 @@ void hexdump(u16 MessageLength, u8 *MessageBuffer) char hex1[10]; char hex2[10]; +printf("NK: "); + for (count = 0; count < MessageLength; count ++) { n++; diff --git a/common/newmodules/n6110.c b/common/newmodules/n6110.c index 324b401..bd70285 100644 --- a/common/newmodules/n6110.c +++ b/common/newmodules/n6110.c @@ -5322,7 +5322,7 @@ void N6110_RX_HandleRLPMessage(u8 *MessageBuffer) /* We do not need RLP frame parsing to be done when we do not have callback specified. */ if (CurrentRLP_RXCallback == NULL) - exit; + return; /* Anybody know the official meaning of the first two bytes? Nokia 6150 sends junk frames starting D9 01, and real frames starting diff --git a/common/protocol/fbus.c b/common/protocol/fbus.c index 87e98fe..34c0507 100644 --- a/common/protocol/fbus.c +++ b/common/protocol/fbus.c @@ -60,6 +60,8 @@ u8 MessageBuffer[FBUS_MAX_RECEIVE_LENGTH * 6],MultiMessageBuffer[FBUS_MAX_RECEIV u8 RequestSequenceNumber = 0x00; +int fbus_decoding=0; + #ifdef DEBUG char *N61_PrintDevice(int Device) { @@ -78,11 +80,12 @@ char *N61_PrintDevice(int Device) void N61_RX_DisplayMessage() { #ifdef DEBUG + hexdump(MessageLength-2,MessageBuffer); + fprintf(stdout, _("Msg Dest: %s\n"), N61_PrintDevice(MessageDestination)); fprintf(stdout, _("Msg Source: %s\n"), N61_PrintDevice(MessageSource)); fprintf(stdout, _("Msg Type: %02x\n"), MessageType); - - hexdump(MessageLength-2,MessageBuffer); + fprintf(stdout, _("Msg Seq: %d\n"), MessageBuffer[MessageLength-1] & 0x0f); #endif AppendLog(MessageBuffer,MessageLength-2,true); @@ -207,6 +210,9 @@ int FBUS_SendAck(u8 message_type, u8 message_seq) { unsigned char request[6]; + if (fbus_decoding) + return 0; + request[0] = message_type; request[1] = message_seq; @@ -233,7 +239,9 @@ void FBUS_Terminate(void) void FBUS_RX_StateMachine(unsigned char rx_byte) { +#if 0 static struct timeval time_now, time_last, time_diff; +#endif static int checksum[2]; @@ -263,6 +271,7 @@ void FBUS_RX_StateMachine(unsigned char rx_byte) { case FBUS_RX_Discarding: +#if 0 #ifndef VC6 gettimeofday(&time_now, NULL); timersub(&time_now, &time_last, &time_diff); @@ -272,13 +281,21 @@ void FBUS_RX_StateMachine(unsigned char rx_byte) { } /* else fall through to... */ #endif +#endif - case FBUS_RX_Sync: + case FBUS_RX_Sync: { +static int discarded=0,discarded55=0; if ((CurrentConnectionType==GCT_FBUS && rx_byte == FBUS_FRAME_ID) || ((CurrentConnectionType==GCT_Infrared || CurrentConnectionType==GCT_Tekram) && rx_byte == FBUS_IR_FRAME_ID)) { + if (discarded) { + printf("[discarded %d bytes, %d were NOT 0x55]\n",discarded,discarded-discarded55); + discarded=0; + discarded55=0; + } + BufferCount = 0; RX_State = FBUS_RX_GetDestination; @@ -289,11 +306,16 @@ void FBUS_RX_StateMachine(unsigned char rx_byte) { } else { /* Lost frame sync */ RX_State = FBUS_RX_Discarding; +#if 0 #ifndef VC6 gettimeofday(&time_last, NULL); #endif +#endif + discarded++; + if (rx_byte == 0x55) + discarded55++; } - break; + } break; case FBUS_RX_GetDestination: @@ -385,6 +407,7 @@ void FBUS_RX_StateMachine(unsigned char rx_byte) { /* Is the checksum correct? */ if (checksum[0] == checksum[1]) { +u8 msgseq; if (RX_Multiple) { @@ -406,7 +429,7 @@ void FBUS_RX_StateMachine(unsigned char rx_byte) { } MultiMessageLength=MultiMessageLength+MessageLength-2; - FBUS_SendAck(MessageType, MessageBuffer[MessageLength-1] & 0x0f); + msgseq=MessageBuffer[MessageLength-1] & 0x0f; if ((MessageLength > 1) && (MessageBuffer[MessageLength-2] != 0x01)) { @@ -420,15 +443,22 @@ void FBUS_RX_StateMachine(unsigned char rx_byte) { /* Do not debug Ack and RLP frames to detail. */ if (MessageType != FBUS_FRTYPE_ACK && MessageType != 0xf1) N61_RX_DisplayMessage(); + else { + if (MessageType == FBUS_FRTYPE_ACK) + puts("[ignoring print of ACK]"); + else + puts("[ignoring print of RLP]"); + } GSM->DispatchMessage(MessageLength-2, MessageBuffer, MessageType); } + FBUS_SendAck(MessageType, msgseq); + } else { /* We do not want to send ACK of ACKs and ACK of RLP frames. */ if (MessageType != FBUS_FRTYPE_ACK && MessageType != 0xf1) { - FBUS_SendAck(MessageType, MessageBuffer[MessageLength-1] & 0x0f); if ((MessageLength > 1) && (MessageBuffer[MessageLength-2] != 0x01)) { @@ -438,13 +468,16 @@ void FBUS_RX_StateMachine(unsigned char rx_byte) { #endif RX_State = FBUS_RX_Sync; } + + msgseq=MessageBuffer[MessageLength-1] & 0x0f; + FBUS_SendAck(MessageType, msgseq); } } } else { + msgseq=MessageBuffer[MessageLength-1] & 0x0f; /* We do not want to send ACK of ACKs and ACK of RLP frames. */ if (MessageType != FBUS_FRTYPE_ACK && MessageType != 0xf1) { - FBUS_SendAck(MessageType, MessageBuffer[MessageLength-1] & 0x0f); if ((MessageLength > 1) && (MessageBuffer[MessageLength-2] != 0x01)) { @@ -458,17 +491,23 @@ void FBUS_RX_StateMachine(unsigned char rx_byte) { } } - if (!RX_Multiple && MessageDestination!=FBUS_DEVICE_PHONE ) { + if (!RX_Multiple /* && MessageDestination!=FBUS_DEVICE_PHONE */ ) { /* Do not debug Ack and RLP frames to detail. */ if (MessageType != FBUS_FRTYPE_ACK && MessageType != 0xf1) N61_RX_DisplayMessage(); + else { + if (MessageType == FBUS_FRTYPE_ACK) + puts("[ignoring print of ACK]"); + else + puts("[ignoring print of RLP]"); + } GSM->DispatchMessage(MessageLength-2, MessageBuffer, MessageType); } #ifdef DEBUG /* When make debug and message is to phone display it */ - if (MessageDestination==FBUS_DEVICE_PHONE) { + if (MessageDestination==FBUS_DEVICE_PHONE && !fbus_decoding) { for (i=MessageLength;i>=0;i--) MessageBuffer[i+6]=MessageBuffer[i]; MessageBuffer[0]=FBUS_FRAME_ID; @@ -482,7 +521,12 @@ void FBUS_RX_StateMachine(unsigned char rx_byte) { NULL_TX_DisplayMessage(MessageLength, MessageBuffer); } #endif + if (MessageType != FBUS_FRTYPE_ACK && MessageType != 0xf1) + FBUS_SendAck(MessageType, msgseq); } +#ifdef DEBUG + putchar('\n'); +#endif } else { #ifdef DEBUG fprintf(stdout, _("Bad checksum %02x (should be %02x), msg len=%i !\n"),checksum[0],checksum[1],MessageLength); diff --git a/gnokii/gnokii.c b/gnokii/gnokii.c index c8db700..4da6169 100644 --- a/gnokii/gnokii.c +++ b/gnokii/gnokii.c @@ -66,6 +66,8 @@ #include "files/gsm-filetypes.h" #include "gnokii.h" +#include "protocol/fbus.h" + #ifdef USE_NLS #include #endif @@ -7513,20 +7515,31 @@ int decodefile(int argc, char *argv[]) int i = 0; /* base model comes from gnokiirc */ +#if 0 strcat(model,"decode"); +#else + strcpy(model,"5190sniff"); + fbus_decoding=1; +#endif /* Initialise the GSM interface. */ fbusinit(NULL); - printf ("open InPutFile: %s\n", argv[0]); + printf ("open InPutFile: %s\n\n\n", argv[0]); if ( (infile = fopen( argv[0], "rb")) == NULL ) { printf ("Failed to open InPutFile: %s\n", argv[0]); exit (1); } while ( (nr_read = fread(in_buffer, 1, 16, infile)) > 0 ) { +static int last=0; + if (ftell(infile)>last+1000) { + last=ftell(infile); + printf("ftell=%d\n",last); + } for (i=0; i < nr_read; i++) Protocol->StateMachine(in_buffer[i]); } + puts("gnokii/decodefile() done"); return 0; } diff --git a/include/config.h.in.in b/include/config.h.in.in index a5dae23..e9310a6 100644 --- a/include/config.h.in.in +++ b/include/config.h.in.in @@ -54,4 +54,14 @@ /* Define if you compile for M$ Windows */ #undef WIN32 + +/* "decode" brach hacks: + */ +#define _XOPEN_SOURCE 1 + +#include +#undef usleep +#define usleep(x) + + #endif /* __CONFIG_H__ */ diff --git a/include/protocol/fbus.h b/include/protocol/fbus.h index 1340262..a8d3c97 100644 --- a/include/protocol/fbus.h +++ b/include/protocol/fbus.h @@ -49,6 +49,8 @@ enum FBUS_RX_States { FBUS_RX_GetMessage }; +extern int fbus_decoding; + GSM_Error FBUS_Initialise(char *port_device, char *initlength, GSM_ConnectionType connection, void (*rlp_callback)(RLP_F96Frame *frame)); -- 1.8.3.1