Diffstat (limited to 'gammu/emb/common/protocol/nokia') (more/less context) (show whitespace changes)
-rw-r--r-- | gammu/emb/common/protocol/nokia/fbus2.c | 6 | ||||
-rw-r--r-- | gammu/emb/common/protocol/nokia/fbus2.h | 6 | ||||
-rw-r--r-- | gammu/emb/common/protocol/nokia/mbus2.c | 2 | ||||
-rw-r--r-- | gammu/emb/common/protocol/nokia/mbus2.h | 2 | ||||
-rw-r--r-- | gammu/emb/common/protocol/nokia/phonet.c | 5 | ||||
-rw-r--r-- | gammu/emb/common/protocol/nokia/phonet.h | 5 |
6 files changed, 20 insertions, 6 deletions
diff --git a/gammu/emb/common/protocol/nokia/fbus2.c b/gammu/emb/common/protocol/nokia/fbus2.c index 8b3e024..2b41f8b 100644 --- a/gammu/emb/common/protocol/nokia/fbus2.c +++ b/gammu/emb/common/protocol/nokia/fbus2.c @@ -1,98 +1,102 @@ /* (c) 2002-2003 by Marcin Wiacek */ -/* based on some work from Gnokii and MyGnokii */ +/* based on some work from MyGnokii (www.mwiacek.com) */ +/* Based on some work from Gnokii (www.gnokii.org) + * (C) 1999-2000 Hugh Blemings & Pavel Janik ml. (C) 2001-2004 Pawel Kot + * GNU GPL version 2 or later + */ #include "../../gsmstate.h" #if defined(GSM_ENABLE_FBUS2) || defined(GSM_ENABLE_FBUS2IRDA) || defined(GSM_ENABLE_FBUS2DLR3) || defined(GSM_ENABLE_FBUS2BLUE) || defined(GSM_ENABLE_BLUEFBUS2) || defined(GSM_ENABLE_FBUS2DKU5) || defined(GSM_ENABLE_FBUS2PL2303) #include <stdio.h> #include <string.h> #include "../../gsmcomon.h" #include "fbus2.h" static GSM_Error FBUS2_WriteFrame(GSM_StateMachine *s, unsigned char *MsgBuffer, int MsgLength, unsigned char MsgType) { unsigned char buffer2[FBUS2_MAX_TRANSMIT_LENGTH + 10]; unsigned char checksum=0; int i, len, sent; buffer2[0] = FBUS2_FRAME_ID; if (s->ConnectionType==GCT_FBUS2IRDA) buffer2[0] = FBUS2_IRDA_FRAME_ID; buffer2[1] = FBUS2_DEVICE_PHONE; //destination buffer2[2] = FBUS2_DEVICE_PC; //source buffer2[3] = MsgType; buffer2[4] = MsgLength / 256; buffer2[5] = MsgLength % 256; memcpy(buffer2 + 6, MsgBuffer, MsgLength); len = MsgLength + 6; /* Odd messages require additional 0x00 byte */ if (MsgLength % 2) buffer2[len++] = 0x00; checksum = 0; for (i = 0; i < len; i+=2) checksum ^= buffer2[i]; buffer2[len++] = checksum; checksum = 0; for (i = 1; i < len; i+=2) checksum ^= buffer2[i]; buffer2[len++] = checksum; /* Sending to phone */ sent=s->Device.Functions->WriteDevice(s,buffer2,len); if (sent!=len) return ERR_DEVICEWRITEERROR; return ERR_NONE; } static GSM_Error FBUS2_WriteMessage (GSM_StateMachine *s, unsigned char *MsgBuffer, int MsgLength, unsigned char MsgType) { int i, nom, togo, thislength; /* number of messages, ... */ unsigned char buffer2[FBUS2_MAX_TRANSMIT_LENGTH + 2], seqnum; GSM_Protocol_FBUS2Data *d = &s->Protocol.Data.FBUS2; GSM_Error error; GSM_DumpMessageLevel3(s, MsgBuffer, MsgLength, MsgType); nom = (MsgLength + FBUS2_MAX_TRANSMIT_LENGTH - 1) / FBUS2_MAX_TRANSMIT_LENGTH; togo = MsgLength; for (i = 0; i < nom; i++) { seqnum = d->MsgSequenceNumber; if (i==0) seqnum = seqnum + 0x40; d->MsgSequenceNumber = (d->MsgSequenceNumber + 1) & 0x07; thislength = togo; if (togo > FBUS2_MAX_TRANSMIT_LENGTH) thislength = FBUS2_MAX_TRANSMIT_LENGTH; memcpy(buffer2, MsgBuffer + (MsgLength - togo), thislength); buffer2[thislength] = nom - i; buffer2[thislength + 1] = seqnum; togo = togo - thislength; GSM_DumpMessageLevel2(s, buffer2, thislength, MsgType); error=FBUS2_WriteFrame(s, buffer2, thislength + 2, MsgType); if (error!=ERR_NONE) return error; } return ERR_NONE; } static GSM_Error FBUS2_SendAck(GSM_StateMachine *s, unsigned char MsgType, unsigned char MsgSequence) { unsigned char buffer2[2]; buffer2[0] = MsgType; buffer2[1] = MsgSequence; if (s->di.dl==DL_TEXT || s->di.dl==DL_TEXTALL || diff --git a/gammu/emb/common/protocol/nokia/fbus2.h b/gammu/emb/common/protocol/nokia/fbus2.h index 5dd45d7..8dbcb07 100644 --- a/gammu/emb/common/protocol/nokia/fbus2.h +++ b/gammu/emb/common/protocol/nokia/fbus2.h @@ -1,38 +1,42 @@ /* (c) 2002-2003 by Marcin Wiacek */ -/* based on some work from Gnokii and MyGnokii */ +/* based on some work from MyGnokii (www.mwiacek.com) */ +/* Based on some work from Gnokii (www.gnokii.org) + * (C) 1999-2000 Hugh Blemings & Pavel Janik ml. (C) 2001-2004 Pawel Kot + * GNU GPL version 2 or later + */ #ifndef fbus2_h #define fbus2_h #include "../protocol.h" #define FBUS2_FRAME_ID 0x1e #define FBUS2_IRDA_FRAME_ID 0x1c #define FBUS2_DEVICE_PHONE 0x00 /* Nokia mobile phone */ #define FBUS2_DEVICE_PC 0x0c /* Our PC */ #define FBUS2_ACK_BYTE 0x7f /* Acknowledge of the received frame */ #define FBUS2_MAX_TRANSMIT_LENGTH 120 typedef struct { int MsgSequenceNumber; int MsgRXState; int FramesToGo; GSM_Protocol_Message MultiMsg; GSM_Protocol_Message Msg; } GSM_Protocol_FBUS2Data; #ifndef GSM_USED_SERIALDEVICE # define GSM_USED_SERIALDEVICE #endif #if defined(GSM_ENABLE_BLUEFBUS2) # ifndef GSM_USED_BLUETOOTHDEVICE # define GSM_USED_BLUETOOTHDEVICE # endif #endif #endif /* How should editor hadle tabs in this file? Add editor commands here. * vim: noexpandtab sw=8 ts=8 sts=8: */ diff --git a/gammu/emb/common/protocol/nokia/mbus2.c b/gammu/emb/common/protocol/nokia/mbus2.c index f07d6c5..8353b46 100644 --- a/gammu/emb/common/protocol/nokia/mbus2.c +++ b/gammu/emb/common/protocol/nokia/mbus2.c @@ -1,98 +1,98 @@ /* (c) 2001-2003 by Marcin Wiacek */ -/* based on some work from MyGnokii */ +/* based on some work from MyGnokii (www.mwiacek.com) */ #include "../../gsmstate.h" #ifdef GSM_ENABLE_MBUS2 #include <stdio.h> #include <string.h> #include "../../gsmcomon.h" #include "mbus2.h" static GSM_Error MBUS2_WriteMessage (GSM_StateMachine *s, unsigned char *MsgBuffer, int MsgLength, unsigned char MsgType) { unsigned char *buffer2, checksum = 0; GSM_Protocol_MBUS2Data *d = &s->Protocol.Data.MBUS2; int i, sent, len; GSM_DumpMessageLevel3(s, MsgBuffer, MsgLength, MsgType); buffer2 = (unsigned char *)malloc(MsgLength + 8); buffer2[0] = MBUS2_FRAME_ID; buffer2[1] = MBUS2_DEVICE_PHONE; // destination buffer2[2] = MBUS2_DEVICE_PC; // source buffer2[3] = MsgType; buffer2[4] = MsgLength / 256; buffer2[5] = MsgLength % 256; memcpy(buffer2 + 6, MsgBuffer, MsgLength); len = 6 + MsgLength; /* According to http://www.flosys.com/tdma/n5160.html some phones * can have problems with checksum equal 0x1F. Phones can recognize * received frame, but won't send ACK for it. When checksum is 0x1F, * we increment the sequence number */ do { d->MsgSequenceNumber++; buffer2[len] = d->MsgSequenceNumber; /* Calculating checksum */ checksum = 0; for (i = 0; i < len + 1; i++) checksum ^= buffer2[i]; } while (checksum == 0x1f); buffer2[len++] = d->MsgSequenceNumber; buffer2[len++] = checksum; GSM_DumpMessageLevel2(s, buffer2+6, MsgLength, MsgType); /* Sending to phone */ my_sleep(10); sent=s->Device.Functions->WriteDevice(s,buffer2,len); free(buffer2); if (sent!=len) return ERR_DEVICEWRITEERROR; return ERR_NONE; } static GSM_Error MBUS2_SendAck(GSM_StateMachine *s, unsigned char type, unsigned char sequence) { GSM_Device_Functions *Device = s->Device.Functions; unsigned char buffer2[6]; int i; buffer2[0] = MBUS2_FRAME_ID; buffer2[1] = MBUS2_DEVICE_PHONE; //destination buffer2[2] = MBUS2_DEVICE_PC; //source buffer2[3] = MBUS2_ACK_BYTE; buffer2[4] = sequence; buffer2[5] = 0; /* Calculating checksum */ for (i = 0; i < 5; i++) buffer2[5] ^= buffer2[i]; if (s->di.dl==DL_TEXT || s->di.dl==DL_TEXTALL || s->di.dl==DL_TEXTDATE || s->di.dl==DL_TEXTALLDATE) { smprintf(s,"[Sending Ack of type %02x, seq: %x]\n",type,sequence); } /* Sending to phone */ my_sleep(10); if (Device->WriteDevice(s,buffer2,6)!=6) return ERR_DEVICEWRITEERROR; return ERR_NONE; } static GSM_Error MBUS2_StateMachine(GSM_StateMachine *s, unsigned char rx_char) { diff --git a/gammu/emb/common/protocol/nokia/mbus2.h b/gammu/emb/common/protocol/nokia/mbus2.h index 86fcab6..5dbd8cb 100644 --- a/gammu/emb/common/protocol/nokia/mbus2.h +++ b/gammu/emb/common/protocol/nokia/mbus2.h @@ -1,28 +1,28 @@ /* (c) 2001-2003 by Marcin Wiacek */ -/* based on some work from MyGnokii */ +/* based on some work from MyGnokii (www.mwiacek.com) */ #ifndef mbus2_h #define mbus2_h #include "../protocol.h" #define MBUS2_FRAME_ID 0x1f #define MBUS2_DEVICE_PHONE 0x00 /* Nokia mobile phone */ #define MBUS2_DEVICE_PC 0x10 /* Our PC (MBUS) */ #define MBUS2_ACK_BYTE 0x7f /* Acknowledge of the received frame */ typedef struct { int MsgSequenceNumber; int MsgRXState; GSM_Protocol_Message Msg; } GSM_Protocol_MBUS2Data; #ifndef GSM_USED_SERIALDEVICE # define GSM_USED_SERIALDEVICE #endif #endif /* How should editor hadle tabs in this file? Add editor commands here. * vim: noexpandtab sw=8 ts=8 sts=8: */ diff --git a/gammu/emb/common/protocol/nokia/phonet.c b/gammu/emb/common/protocol/nokia/phonet.c index bc5717d..db5bd72 100644 --- a/gammu/emb/common/protocol/nokia/phonet.c +++ b/gammu/emb/common/protocol/nokia/phonet.c @@ -1,98 +1,101 @@ /* (c) 2002-2003 by Marcin Wiacek */ -/* based on some work from Gnokii */ +/* Based on some work from Gnokii (www.gnokii.org) + * (C) 1999-2000 Hugh Blemings & Pavel Janik ml. (C) 2001-2004 Pawel Kot + * GNU GPL version 2 or later + */ #include "../../gsmstate.h" #if defined(GSM_ENABLE_IRDA) || defined(GSM_ENABLE_PHONETBLUE) || defined(GSM_ENABLE_BLUEPHONET) #include <stdio.h> #include <string.h> #include "../../gsmcomon.h" #include "phonet.h" static GSM_Error PHONET_WriteMessage (GSM_StateMachine *s, unsigned char *MsgBuffer, int MsgLength, unsigned char MsgType) { unsigned char *buffer2; int sent; GSM_DumpMessageLevel3(s, MsgBuffer, MsgLength, MsgType); buffer2 = (unsigned char *)malloc(MsgLength + 6); buffer2[0] = PHONET_FRAME_ID, buffer2[1] = PHONET_DEVICE_PHONE; //destination buffer2[2] = PHONET_DEVICE_PC; //source if (s->ConnectionType==GCT_PHONETBLUE || s->ConnectionType==GCT_BLUEPHONET) { buffer2[0] = PHONET_BLUE_FRAME_ID; buffer2[1] = PHONET_DEVICE_PHONE; //destination buffer2[2] = PHONET_BLUE_DEVICE_PC; //source } buffer2[3] = MsgType; buffer2[4] = MsgLength / 256; buffer2[5] = MsgLength % 256; memcpy(buffer2 + 6, MsgBuffer, MsgLength); GSM_DumpMessageLevel2(s, buffer2+6, MsgLength, MsgType); /* Sending to phone */ sent = s->Device.Functions->WriteDevice(s,buffer2,MsgLength+6); free(buffer2); if (sent!=MsgLength+6) return ERR_DEVICEWRITEERROR; return ERR_NONE; } static GSM_Error PHONET_StateMachine(GSM_StateMachine *s, unsigned char rx_char) { GSM_Protocol_PHONETData *d = &s->Protocol.Data.PHONET; bool correct = false; if (d->MsgRXState==RX_GetMessage) { d->Msg.Buffer[d->Msg.Count] = rx_char; d->Msg.Count++; /* This is not last byte in frame */ if (d->Msg.Count != d->Msg.Length) return ERR_NONE; s->Phone.Data.RequestMsg = &d->Msg; s->Phone.Data.DispatchError = s->Phone.Functions->DispatchMessage(s); free(d->Msg.Buffer); d->Msg.Length = 0; d->Msg.Buffer = NULL; d->MsgRXState = RX_Sync; return ERR_NONE; } if (d->MsgRXState==RX_GetLength2) { d->Msg.Length = d->Msg.Length + rx_char; d->Msg.Buffer = (unsigned char *)malloc(d->Msg.Length); d->MsgRXState = RX_GetMessage; return ERR_NONE; } if (d->MsgRXState==RX_GetLength1) { d->Msg.Length = rx_char * 256; d->MsgRXState = RX_GetLength2; return ERR_NONE; } if (d->MsgRXState==RX_GetType) { d->Msg.Type = rx_char; d->MsgRXState = RX_GetLength1; return ERR_NONE; } if (d->MsgRXState==RX_GetSource) { if (rx_char != PHONET_DEVICE_PHONE) { if (s->di.dl==DL_TEXT || s->di.dl==DL_TEXTALL || s->di.dl==DL_TEXTERROR || s->di.dl==DL_TEXTDATE || s->di.dl==DL_TEXTALLDATE || s->di.dl==DL_TEXTERRORDATE) { smprintf(s,"[ERROR: incorrect char - %02x, not %02x]\n", rx_char, PHONET_DEVICE_PHONE); diff --git a/gammu/emb/common/protocol/nokia/phonet.h b/gammu/emb/common/protocol/nokia/phonet.h index 2f6e836..e750bbd 100644 --- a/gammu/emb/common/protocol/nokia/phonet.h +++ b/gammu/emb/common/protocol/nokia/phonet.h @@ -1,35 +1,38 @@ /* (c) 2002-2003 by Marcin Wiacek */ -/* based on some work from Gnokii */ +/* Based on some work from Gnokii (www.gnokii.org) + * (C) 1999-2000 Hugh Blemings & Pavel Janik ml. (C) 2001-2004 Pawel Kot + * GNU GPL version 2 or later + */ #ifndef PHONET_h #define PHONET_h #include "../protocol.h" #define PHONET_FRAME_ID 0x14 #define PHONET_BLUE_FRAME_ID 0x19 #define PHONET_DEVICE_PHONE 0x00 /* Nokia mobile phone */ #define PHONET_DEVICE_PC 0x0c /* Our PC */ #define PHONET_BLUE_DEVICE_PC 0x10 /* Our PC */ typedef struct { int MsgRXState; GSM_Protocol_Message Msg; } GSM_Protocol_PHONETData; #if defined(GSM_ENABLE_IRDAPHONET) # ifndef GSM_USED_IRDADEVICE # define GSM_USED_IRDADEVICE # endif #endif #if defined(GSM_ENABLE_BLUEPHONET) # ifndef GSM_USED_BLUETOOTHDEVICE # define GSM_USED_BLUETOOTHDEVICE # endif #endif #endif /* How should editor hadle tabs in this file? Add editor commands here. * vim: noexpandtab sw=8 ts=8 sts=8: */ |