From: short <> Date: Mon, 25 Feb 2002 02:49:24 +0000 (+0000) Subject: First version, development moved to 5110-connected machine X-Git-Tag: uc_works1~39 X-Git-Url: https://git.jankratochvil.net/?p=gnokii.git;a=commitdiff_plain;h=c7dcdfd34d2bed9cc64c5c9603e51ef8c8271951 First version, development moved to 5110-connected machine --- diff --git a/Makefile b/Makefile index 1feaf9c..18a138b 100644 --- a/Makefile +++ b/Makefile @@ -18,9 +18,9 @@ include ${TOPDIR}/Makefile.global BIN_DIRS = gnokii ifndef WIN32 -BIN_DIRS += gnokiid -BIN_DIRS += mgnetd -BIN_DIRS += mgnetd/mg_demo_client +###BIN_DIRS += gnokiid +###BIN_DIRS += mgnetd +###BIN_DIRS += mgnetd/mg_demo_client endif DIRS = common \ @@ -38,6 +38,8 @@ endif GTK_DIRS = xgnokii \ xlogos +#uClinux: +GTK_LIBS= PO_DIR = po DOCS_DIR = Docs diff --git a/Makefile.global.in b/Makefile.global.in index 23fa672..b00c902 100644 --- a/Makefile.global.in +++ b/Makefile.global.in @@ -46,6 +46,7 @@ CFLAGS = @CFLAGS@ CPPFLAGS = @CPPFLAGS@ LIBS = @LIBS@ LEX = @LEX@ +AR = @AR@ GTK_CFLAGS = @GTK_CFLAGS@ GTK_LIBS = @GTK_LIBS@ diff --git a/acconfig.h b/acconfig.h index a5dae23..dfd6d99 100644 --- a/acconfig.h +++ b/acconfig.h @@ -10,14 +10,11 @@ */ -/* DO NOT EDIT MANUALLY !!! */ - #ifndef __CONFIG_H__ #define __CONFIG_H__ -#define VERSION "@VERSION@" -#define XVERSION "@XVERSION@" -#define XGNOKIIDIR "@XGNOKIIDIR@/@XPACKAGE@" +@TOP@ + /* Define if you have timersub() */ #undef HAVE_TIMEOPS @@ -54,4 +51,33 @@ /* Define if you compile for M$ Windows */ #undef WIN32 +/* Missing symbols */ +#undef VERSION +#undef XVERSION +#undef DEBUG +#undef HAVE_CFSETISPEED +#undef HAVE_CFSETOSPEED +#undef HAVE_CFSETSPEED +#undef HAVE_LIBINTL +#undef HAVE_LIBINTL_H +#undef HAVE_TERMIOS_CSPEED +#undef HAVE_TIMEOPS +#undef HAVE_TM_GMTON +#undef RLP_DEBUG +#undef SECURITY +#undef USE_NLS +#undef USE_UNIX98PTYS +#undef WIN32 +#undef XDEBUG +#undef XPM +#undef CONFIG_CFG_INITLENGTH +#undef CONFIG_CFG_MODEL +#undef CONFIG_CFG_PORT + + +@BOTTOM@ + +#include "uccompat.h" + + #endif /* __CONFIG_H__ */ diff --git a/bigfunc b/bigfunc new file mode 100755 index 0000000..231e964 --- /dev/null +++ b/bigfunc @@ -0,0 +1,28 @@ +#! /usr/bin/perl + +use strict; +use warnings; + +open NM,"-|",'m68k-pic-coff-nm gnokii/gnokii.coff|sort' + or die "nm: $!"; +my(%big,$prevhex,$prevsym,$tot); +while () { + chomp; + /^([0-9a-f]+) (\w) (.*)$/ or die "parse: $_"; + my $hex=hex $1; + my $type=$2; + my $sym=$3; + next if $type!~/[tT]/ || $sym=~/^\./ || $sym=~/^L\d+$/ || $sym eq "__gnu_compiled_c" || $sym eq "gcc2_compiled."; + if ($prevhex) { + warn "dup: $prevsym" if exists $big{$prevsym}; + $big{$prevsym}=$hex-$prevhex; + $tot+=$hex-$prevhex; + } + $prevhex=$hex; + $prevsym=$sym; + } +close NM; +$big{"_TOTAL"}=$tot; +for (sort { $big{$b} <=> $big{$a} } keys %big) { + printf "%4u %s\n",$big{$_},$_; + } diff --git a/common/Makefile b/common/Makefile index e396803..570b19a 100644 --- a/common/Makefile +++ b/common/Makefile @@ -18,30 +18,31 @@ DIRS = protocol \ oldmodules \ newmodules +# files/midifile.o \ +# gsm-ringtones.o \ +# gsm-wap.o \ +# gsm-calendar.o \ +# gsm-bitmaps.o \ +# protocol/fbusirda.o \ +# protocol/mbus.o \ +# protocol/at.o \ +# newmodules/n7110.o +# newmodules/sniff/sniff.o \ +# newmodules/newat.o \ + OBJS = devices/device.o \ data/rlp-common.o \ data/rlp-crc24.o \ - files/midifile.o \ - gsm-ringtones.o \ - gsm-coding.o \ gsm-datetime.o \ - gsm-wap.o \ gsm-api.o \ + gsm-sms.o \ + gsm-coding.o \ gsm-phonebook.o \ - gsm-calendar.o \ gsm-networks.o \ - gsm-bitmaps.o \ - gsm-sms.o \ files/cfgreader.o \ misc.o \ protocol/fbus.o \ - protocol/fbusirda.o \ - protocol/mbus.o \ - protocol/at.o \ - newmodules/sniff/sniff.o \ - newmodules/newat.o \ - newmodules/n6110.o \ - newmodules/n7110.o + newmodules/n6110.o DATA_OBJS = data/virtmodem.o \ data/at-emulator.o \ @@ -50,22 +51,22 @@ DATA_OBJS = data/virtmodem.o \ ifdef WIN32 OBJS += $(TOPDIR)/win32/winserial.o else - OBJS += devices/unixserial.o \ - devices/unixirda.o \ - devices/tekram.o + OBJS += devices/unixserial.o +# devices/unixirda.o \ +# devices/tekram.o endif ifdef XPM_CFLAGS CFLAGS += $(XPM_CFLAGS) endif -all: COMMON.o DATA.o gsm-filetypes.o +all: common.a data.a ##gsm-filetypes.o -COMMON.o: $(OBJS) - $(LD) $(LDREL) $(LDOUT) COMMON.o $(OBJS) +common.a: $(OBJS) + $(AR) rcs $@ $^ -DATA.o: $(DATA_OBJS) - $(LD) $(LDREL) $(LDOUT) DATA.o $(DATA_OBJS) +data.a: $(DATA_OBJS) + $(AR) rcs $@ $^ gsm-filetypes.o: files/gsm-filetypes.c $(CC) $(CFLAGS) -c files/gsm-filetypes.c diff --git a/common/data/at-emulator.c b/common/data/at-emulator.c index 41445c8..5f84b0b 100644 --- a/common/data/at-emulator.c +++ b/common/data/at-emulator.c @@ -14,6 +14,8 @@ */ +#include "config.h" + #define __data_at_emulator_c @@ -50,28 +52,32 @@ bool ATEM_Initialised = false; /* Set to true once initialised */ extern bool CommandMode; extern int ConnectCount; -char ModelName[80]; /* This seems to be needed to avoid seg-faults */ -char PortName[80]; +static char ModelName[80]; /* This seems to be needed to avoid seg-faults */ +static char PortName[80]; /* Local variables */ -int PtyRDFD; /* File descriptor for reading and writing to/from */ -int PtyWRFD; /* pty interface - only different in debug mode. */ +extern int PtyRDFD; /* File descriptor for reading and writing to/from */ +extern int PtyWRFD; /* pty interface - only different in debug mode. */ + +static u8 ModemRegisters[MAX_MODEM_REGISTERS]; +static char CmdBuffer[MAX_CMD_BUFFERS][CMD_BUFFER_LENGTH]; +static int CurrentCmdBuffer; +static int CurrentCmdBufferIndex; +static bool VerboseResponse; /* Switch betweek numeric (4) and text responses (ERROR) */ +static char IncomingCallNo; +static int MessageFormat; /* Message Format (text or pdu) */ -u8 ModemRegisters[MAX_MODEM_REGISTERS]; -char CmdBuffer[MAX_CMD_BUFFERS][CMD_BUFFER_LENGTH]; -int CurrentCmdBuffer; -int CurrentCmdBufferIndex; -bool VerboseResponse; /* Switch betweek numeric (4) and text responses (ERROR) */ -char IncomingCallNo; -int MessageFormat; /* Message Format (text or pdu) */ +static void ATEM_ParseAT(char *cmd_buffer); /* Current command parser */ -void (*Parser)(char *); +static void (*Parser)(char *); //void (*Parser)(char *) = ATEM_ParseAT; /* Current command parser */ -GSM_MemoryType SMSType; -int SMSNumber; +static GSM_MemoryType SMSType; +static int SMSNumber; + +static void ATEM_InitRegisters(void); /* If initialised in debug mode, stdin/out is used instead of ptys for interface. */ @@ -112,7 +118,7 @@ bool ATEM_Initialise(int read_fd, int write_fd, char *model, char *port) } /* Initialise the "registers" used by the virtual modem. */ -void ATEM_InitRegisters(void) +static void ATEM_InitRegisters(void) { ModemRegisters[REG_RINGATA] = 0; @@ -137,6 +143,7 @@ void ATEM_CallPassup(char c) } } +static void ATEM_StringOut(char *buffer); /* Handler called when characters received from serial port. calls state machine code to process it. */ @@ -177,9 +184,13 @@ void ATEM_HandleIncomingData(char *buffer, int length) } } +static bool ATEM_CommandPlusC(char **buf); +static bool ATEM_CommandPlusG(char **buf); +static int ATEM_GetNum(char **p); +static void ATEM_ParseSMS(char *cmd_buffer); /* Parser for standard AT commands. cmd_buffer must be null terminated. */ -void ATEM_ParseAT(char *cmd_buffer) +static void ATEM_ParseAT(char *cmd_buffer) { char *buf; char number[30]; @@ -365,8 +376,10 @@ static void ATEM_HandleSMS() return; } +static void ATEM_ParseDIR(char *cmd_buffer); + /* Parser for SMS interactive mode */ -void ATEM_ParseSMS(char *buff) +static void ATEM_ParseSMS(char *buff) { if (!strcasecmp(buff, "HELP")) { ATEM_StringOut(_("\n\rThe following commands work...\n\r")); @@ -391,7 +404,7 @@ void ATEM_ParseSMS(char *buff) } /* Parser for DIR sub mode of SMS interactive mode. */ -void ATEM_ParseDIR(char *buff) +static void ATEM_ParseDIR(char *buff) { switch (toupper(*buff)) { case 'P': @@ -415,7 +428,7 @@ void ATEM_ParseDIR(char *buff) /* Handle AT+C commands, this is a quick hack together at this stage. */ -bool ATEM_CommandPlusC(char **buf) +static bool ATEM_CommandPlusC(char **buf) { float rflevel; GSM_RFUnits rfunits = GRF_CSQ; @@ -515,7 +528,7 @@ bool ATEM_CommandPlusC(char **buf) switch (**buf) { case '=': buf[0]++; - sscanf(*buf, "%d", &index); + index = atoi(*buf); buf[0] += strlen(*buf); error = ATEM_ReadSMS(index, SMSType, &message); @@ -599,7 +612,7 @@ bool ATEM_CommandPlusC(char **buf) } /* AT+G commands. Some of these responses are a bit tongue in cheek... */ -bool ATEM_CommandPlusG(char **buf) +static bool ATEM_CommandPlusG(char **buf) { char buffer[MAX_LINE_LENGTH]; @@ -685,7 +698,7 @@ void ATEM_ModemResult(int code) /* Get integer from char-pointer, set pointer to end of number stolen basically verbatim from ISDN code. */ -int ATEM_GetNum(char **p) +static int ATEM_GetNum(char **p) { int v = -1; @@ -699,7 +712,7 @@ int ATEM_GetNum(char **p) /* Write string to virtual modem port, either pty or STDOUT as appropriate. This function is only used during command mode - data pump is used when connected. */ -void ATEM_StringOut(char *buffer) +static void ATEM_StringOut(char *buffer) { int count = 0; char out_char; diff --git a/common/data/datapump.c b/common/data/datapump.c index 4eede53..adb201d 100644 --- a/common/data/datapump.c +++ b/common/data/datapump.c @@ -14,6 +14,8 @@ */ +#include "config.h" + #define __data_datapump_c @@ -27,7 +29,9 @@ #include #include #include +#ifndef UCLINUX #include +#endif #include @@ -43,18 +47,17 @@ extern bool CommandMode; /* Local variables */ -int PtyRDFD; /* File descriptor for reading and writing to/from */ -int PtyWRFD; /* pty interface - only different in debug mode. */ -struct pollfd ufds; -u8 pluscount; -bool connected; +extern int PtyRDFD; /* File descriptor for reading and writing to/from */ +extern int PtyWRFD; /* pty interface - only different in debug mode. */ +static u8 pluscount; +static bool connected; + +static int DP_CallBack(RLP_UserInds ind, u8 *buffer, int length); bool DP_Initialise(int read_fd, int write_fd) { PtyRDFD = read_fd; PtyWRFD = write_fd; - ufds.fd=PtyRDFD; - ufds.events=POLLIN; RLP_Initialise(GSM->SendRLPFrame, DP_CallBack); RLP_SetUserRequest(Attach_Req,true); pluscount=0; @@ -63,7 +66,7 @@ bool DP_Initialise(int read_fd, int write_fd) } -int DP_CallBack(RLP_UserInds ind, u8 *buffer, int length) +static int DP_CallBack(RLP_UserInds ind, u8 *buffer, int length) { int temp; @@ -91,15 +94,23 @@ int DP_CallBack(RLP_UserInds ind, u8 *buffer, int length) case Reset_Ind: RLP_SetUserRequest(Reset_Resp,true); break; - case GetData: - if (poll(&ufds,1,0)) { + case GetData: { + fd_set readfds; + struct timeval timeout; + + FD_ZERO(&readfds); + FD_SET(PtyRDFD,&readfds); + timeout.tv_sec=0; + timeout.tv_usec=0; + + if (select(PtyRDFD+1,&readfds,NULL/*writefds*/,NULL/*exceptfds*/,&timeout)) { /* Check if the program has closed */ /* Return to command mode */ /* Note that the call will still be in progress, */ /* as with a normal modem (I think) */ - if (ufds.revents!=POLLIN) { + if (!FD_ISSET(PtyRDFD,&readfds)) { CommandMode=true; /* Set the call passup back to the at emulator */ GSM->DialData(NULL,-1,&ATEM_CallPassup); @@ -137,7 +148,7 @@ int DP_CallBack(RLP_UserInds ind, u8 *buffer, int length) return temp; } return 0; - break; + } break; default: diff --git a/common/data/rlp-common.c b/common/data/rlp-common.c index 9c46e0d..509faa7 100644 --- a/common/data/rlp-common.c +++ b/common/data/rlp-common.c @@ -16,6 +16,8 @@ */ +#include "config.h" + #include #include #include @@ -34,59 +36,64 @@ /* Our state machine which handles all of nine possible states of RLP machine. */ -void MAIN_STATE_MACHINE(RLP_F96Frame *frame, RLP_F96Header *header); +static void MAIN_STATE_MACHINE(RLP_F96Frame *frame, RLP_F96Header *header); /* This is the type we are just handling. */ -RLP_FrameTypes CurrentFrameType; +static RLP_FrameTypes CurrentFrameType; /* Current state of RLP state machine. */ -RLP_State CurrentState=RLP_S0; /* We start at ADM and Detached */ +static RLP_State CurrentState=RLP_S0; /* We start at ADM and Detached */ /* Next state of RLP state machine. */ -RLP_State NextState; +static RLP_State NextState; /* Pointer to Send function that sends frame to phone. */ -bool (*RLPSendFunction)(RLP_F96Frame *frame, bool out_dtx); +static bool (*RLPSendFunction)(RLP_F96Frame *frame, bool out_dtx); /* Pointer to Passup function which returns data/inds */ -int (*RLP_Passup)(RLP_UserInds ind, u8 *buffer, int length); +static int (*RLP_Passup)(RLP_UserInds ind, u8 *buffer, int length); /* State variables - see GSM 04.22, Annex A, section A.1.2 */ -RLP_StateVariable UA_State; -RLP_StateVariable UI_State; -RLP_StateVariable Ackn_State; -RLP_StateVariable Poll_State; -RLP_StateVariable Poll_xchg; -RLP_StateVariable SABM_State; -RLP_StateVariable DISC_State; -RLP_StateVariable DM_State; /* FIXME - not handled */ -RLP_StateVariable XI_R_State; -RLP_StateVariable XID_C_State; -RLP_StateVariable XID_R_State; -RLP_StateVariable TEST_R_State; - -u8 VR=0; -u8 VA=0; -u8 VS=0; -u8 VD=0; -u8 DISC_Count; - -u8 DTX_VR; -RLP_FrameTypes DTX_SF; +static RLP_StateVariable UA_State; +/* +static RLP_StateVariable UI_State; +*/ +static RLP_StateVariable Ackn_State; +static RLP_StateVariable Poll_State; +static RLP_StateVariable Poll_xchg; +static RLP_StateVariable SABM_State; +static RLP_StateVariable DISC_State; +static RLP_StateVariable DM_State; /* FIXME - not handled */ +/* +static RLP_StateVariable XID_C_State; +*/ +static RLP_StateVariable XID_R_State; +/* +static RLP_StateVariable TEST_R_State; +*/ + +static u8 VR=0; +static u8 VA=0; +static u8 VS=0; +static u8 VD=0; +static u8 DISC_Count; + +static u8 DTX_VR; +static RLP_FrameTypes DTX_SF; #define RLP_M 62 -RLP_Data R[RLP_M]; -RLP_Data S[RLP_M]; +static RLP_Data R[RLP_M]; +static RLP_Data S[RLP_M]; -RLP_StateVariable SABM_State; -int SABM_Count; +static RLP_StateVariable SABM_State; +static int SABM_Count; -RLP_UserRequestStore UserRequests; +static RLP_UserRequestStore UserRequests; -u8 Poll_Count=0; +static u8 Poll_Count=0; /* For now timing is done based on a frame reception rate of 20ms */ /* Serge has measured it as 18.4ms */ @@ -96,28 +103,28 @@ u8 Poll_Count=0; /* To set, timer is loaded with RLP_Timeout1_Limit/RLP_T_Scaling. */ /* Each received frame (including NULLS / errors) any >0 timer is decrease */ -int T; -int T_RCVS[RLP_M]; +static int T; +static int T_RCVS[RLP_M]; -bool UA_FBit=true; -bool Ackn_FBit=false; -bool DM_FBit=false; /* FIXME - not handled */ -bool RRReady=false; -bool LRReady=true; /* FIXME - not handled (as if we couldn't keep up with 9600bps :-) */ -bool DISC_PBit=false; +static bool UA_FBit=true; +static bool Ackn_FBit=false; +static bool DM_FBit=false; /* FIXME - not handled */ +static bool RRReady=false; +static bool LRReady=true; /* FIXME - not handled (as if we couldn't keep up with 9600bps :-) */ +static bool DISC_PBit=false; -u8 LastStatus=0xff; /* Last Status byte */ +static u8 LastStatus=0xff; /* Last Status byte */ /* RLP Parameters. FIXME: Reset these - e.g. when entering state 0 */ -u8 RLP_SEND_WS = RLP_M-1; -u8 RLP_RCV_WS = RLP_M-1; -u8 RLP_Timeout1_Limit = 55; -u8 RLP_N2 = 15; /* Maximum number of retransmisions. GSM spec says 6 here, but - Nokia will XID this. */ -u8 RLP_T2=0; -u8 RLP_VersionNumber=0; +static u8 RLP_SEND_WS = RLP_M-1; +static u8 RLP_RCV_WS = RLP_M-1; +static u8 RLP_Timeout1_Limit = 55; +static u8 RLP_N2 = 15; /* Maximum number of retransmisions. GSM spec says 6 here, but + Nokia will XID this. */ +static u8 RLP_T2=0; +static u8 RLP_VersionNumber=0; @@ -197,7 +204,7 @@ void RLP_SetUserRequest(RLP_UserRequests type, bool value) { /* Check whether a user event is set */ -bool RLP_GetUserRequest(RLP_UserRequests type) { +static bool RLP_GetUserRequest(RLP_UserRequests type) { bool result=false, *x; @@ -230,7 +237,7 @@ bool RLP_GetUserRequest(RLP_UserRequests type) { return result; } -void RLP_SetTimer(int *timer) +static void RLP_SetTimer(int *timer) { *timer=(int)(RLP_Timeout1_Limit/RLP_T_Scaling); } @@ -280,7 +287,7 @@ static bool InWindow(u8 val, u8 lower, u8 upper) return (val <= upper) || (val >= lower); } -void RLP_Init_link_vars(void) +static void RLP_Init_link_vars(void) { int i; @@ -305,7 +312,7 @@ void RLP_Init_link_vars(void) } -void RLP_AddRingBufferDataToSlots(void) +static void RLP_AddRingBufferDataToSlots(void) { u8 buffer[24]; int size; @@ -329,9 +336,11 @@ void RLP_AddRingBufferDataToSlots(void) } +#ifndef UCLINUX + /* FIXME: Remove this after finishing. */ -void X(RLP_F96Frame *frame) { +static void X(RLP_F96Frame *frame) { int i; @@ -340,9 +349,10 @@ void X(RLP_F96Frame *frame) { } +#endif /* UCLINUX */ -void ResetAllT_RCVS(void) +static void ResetAllT_RCVS(void) { int i; @@ -353,7 +363,7 @@ void ResetAllT_RCVS(void) /* This function is used for sending RLP frames to the phone. */ -void RLP_SendF96Frame(RLP_FrameTypes FrameType, +static void RLP_SendF96Frame(RLP_FrameTypes FrameType, bool OutCR, bool OutPF, u8 OutNR, u8 OutNS, u8 *OutData, u8 OutDTX) @@ -594,6 +604,8 @@ void RLP_SendF96Frame(RLP_FrameTypes FrameType, } +static void RLP_DecodeF96Header(RLP_F96Frame *frame, RLP_F96Header *header); + /* Check_input_PDU in Serge's code. */ void RLP_DisplayF96Frame(RLP_F96Frame *frame) @@ -930,14 +942,14 @@ void RLP_DisplayF96Frame(RLP_F96Frame *frame) /* FIXME: real TEST_Handling - we do not handle TEST yet. */ -void TEST_Handling() { +static void TEST_Handling() { } /* FIXME: better XID_handling - but this will answer a XID command. */ -bool XID_Handling (RLP_F96Frame *frame, RLP_F96Header *header) { +static bool XID_Handling (RLP_F96Frame *frame, RLP_F96Header *header) { u8 count; u8 type; @@ -1026,7 +1038,7 @@ bool XID_Handling (RLP_F96Frame *frame, RLP_F96Header *header) { } -bool Send_TXU(RLP_F96Frame *frame, RLP_F96Header *header) { +static bool Send_TXU(RLP_F96Frame *frame, RLP_F96Header *header) { #ifdef DEBUG // fprintf(stdout, _("Send_TXU()\n")); @@ -1070,7 +1082,7 @@ bool Send_TXU(RLP_F96Frame *frame, RLP_F96Header *header) { /* Deliver data */ -void RLP_DeliverAllInSeqIF() +static void RLP_DeliverAllInSeqIF() { int i,j; @@ -1098,7 +1110,7 @@ void RLP_DeliverAllInSeqIF() /* Mark any missing information frames between VR and Ns*/ -void RLP_MarkMissingIF(u8 Ns) +static void RLP_MarkMissingIF(u8 Ns) { u8 i; for (i=VR; i!=Ns; i=Incr(i)) { @@ -1109,7 +1121,7 @@ void RLP_MarkMissingIF(u8 Ns) /* Information frame handler */ -bool RLP_I_Handler(RLP_F96Frame *frame, RLP_F96Header *header) +static bool RLP_I_Handler(RLP_F96Frame *frame, RLP_F96Header *header) { if ((header->CR) && (header->PF)) @@ -1142,7 +1154,7 @@ bool RLP_I_Handler(RLP_F96Frame *frame, RLP_F96Header *header) /* Mark acknowledged send frames */ -void RLP_AdvanceVA(u8 Nr) +static void RLP_AdvanceVA(u8 Nr) { while (VA!=Nr) { S[VA].State=_idle; @@ -1153,7 +1165,7 @@ void RLP_AdvanceVA(u8 Nr) /* Decrease VS back down to Nr since these have not been acknowledged */ -void RLP_DecreaseVS(u8 Nr) +static void RLP_DecreaseVS(u8 Nr) { while (VS!=Nr) { VS=Decr(VS); @@ -1163,7 +1175,7 @@ void RLP_DecreaseVS(u8 Nr) /* Supervisory frame handling */ -void RLP_S_Handler(RLP_F96Frame *frame, RLP_F96Header *header) +static void RLP_S_Handler(RLP_F96Frame *frame, RLP_F96Header *header) { u8 i; @@ -1219,7 +1231,7 @@ void RLP_S_Handler(RLP_F96Frame *frame, RLP_F96Header *header) /* Find the first SREJ frame */ -bool RLP_SREJSlot(u8 *x) +static bool RLP_SREJSlot(u8 *x) { u8 i; @@ -1235,7 +1247,7 @@ bool RLP_SREJSlot(u8 *x) /* Check if any SREJ frames need sending, if not send the next in line */ -bool RLP_PrepareDataToTransmit(u8 *p) +static bool RLP_PrepareDataToTransmit(u8 *p) { u8 i; @@ -1258,7 +1270,7 @@ bool RLP_PrepareDataToTransmit(u8 *p) /* Send a SREJ command */ -void RLP_SendSREJ(u8 x) +static void RLP_SendSREJ(u8 x) { u8 k; @@ -1298,7 +1310,7 @@ void RLP_SendSREJ(u8 x) /* Send a command */ -void RLP_Send_XX_Cmd(RLP_FrameTypes type) +static void RLP_Send_XX_Cmd(RLP_FrameTypes type) { u8 k; @@ -1336,7 +1348,7 @@ void RLP_Send_XX_Cmd(RLP_FrameTypes type) /* Send a Response */ -void RLP_Send_XX_Resp(RLP_FrameTypes type) +static void RLP_Send_XX_Resp(RLP_FrameTypes type) { u8 k; @@ -1362,7 +1374,7 @@ void RLP_Send_XX_Resp(RLP_FrameTypes type) /* Decide which frame to use and send it - currently only used in state 4 */ -void RLP_SendData() +static void RLP_SendData() { u8 x; @@ -1382,7 +1394,7 @@ void RLP_SendData() else RLP_Send_XX_Cmd(RLPFT_S_RNR); } -void MAIN_STATE_MACHINE(RLP_F96Frame *frame, RLP_F96Header *header) { +static void MAIN_STATE_MACHINE(RLP_F96Frame *frame, RLP_F96Header *header) { int i; switch (CurrentState) { @@ -1743,7 +1755,6 @@ void MAIN_STATE_MACHINE(RLP_F96Frame *frame, RLP_F96Header *header) { if(SABM_State!=_idle) printf("[SABM_State %d]",SABM_State); if(DISC_State!=_idle) printf("[DISC_State %d]",DISC_State); if(DM_State!=_idle) printf("[DM_State %d]",DM_State); - if(XI_R_State!=_idle) printf("[XI_R_State %d]",XI_R_State); if(XID_C_State!=_idle) printf("[XID_C_State %d]",XID_C_State); if(XID_R_State!=_idle) printf("[XID_R_State %d]",XID_R_State); if(TEST_R_State!=_idle) printf("[TEST_R_State %d]",TEST_R_State); @@ -1925,7 +1936,9 @@ void MAIN_STATE_MACHINE(RLP_F96Frame *frame, RLP_F96Header *header) { exact implementation of section 5.2.2.6, Exchange Identification, XID of the GSM specification 04.22. */ -void RLP_DisplayXID(u8 *frame) +#ifdef RLP_DEBUG + +static void RLP_DisplayXID(u8 *frame) { int count = 25; /* Sanity check */ @@ -2005,10 +2018,12 @@ void RLP_DisplayXID(u8 *frame) return; } +#endif /* RLP_DEBUG */ + /* Given a pointer to an F9.6 Frame, split data out into component parts of header and determine frame type. */ -void RLP_DecodeF96Header(RLP_F96Frame *frame, RLP_F96Header *header) +static void RLP_DecodeF96Header(RLP_F96Frame *frame, RLP_F96Header *header) { /* Poll/Final bit. */ diff --git a/common/data/rlp-crc24.c b/common/data/rlp-crc24.c index cc8af90..7f29c68 100644 --- a/common/data/rlp-crc24.c +++ b/common/data/rlp-crc24.c @@ -16,7 +16,7 @@ /* CRC-24 table is used for computation of RLP checksum. */ -const u32 CRC24_Table[256] = { +static const u32 CRC24_Table[256] = { 0x00000000, 0x00D6A776, 0x00F64557, 0x0020E221, 0x00B78115, 0x00612663, 0x0041C442, 0x00976334, 0x00340991, 0x00E2AEE7, 0x00C24CC6, 0x0014EBB0, 0x00838884, 0x00552FF2, 0x0075CDD3, 0x00A36AA5, 0x00681322, 0x00BEB454, @@ -62,7 +62,7 @@ const u32 CRC24_Table[256] = { 0x006D7F0C, 0x00BBD87A, 0x009B3A5B, 0x004D9D2D }; -void RLP_CalculateCRC24Polinomial(u8 *data, int length, u32 *polinomial) +static void RLP_CalculateCRC24Polinomial(u8 *data, int length, u32 *polinomial) { int i; diff --git a/common/data/virtmodem.c b/common/data/virtmodem.c index 7c7f4e2..664127f 100644 --- a/common/data/virtmodem.c +++ b/common/data/virtmodem.c @@ -35,8 +35,10 @@ #include #include #include +#ifndef UCLINUX #include #include +#endif /* UCLINUX */ #include #include "misc.h" @@ -50,30 +52,25 @@ /* Global variables */ //extern bool TerminateThread; -int ConnectCount; /* Local variables */ int PtyRDFD; /* File descriptor for reading and writing to/from */ int PtyWRFD; /* pty interface - only different in debug mode. */ -bool UseSTDIO; /* Use STDIO for debugging purposes instead of pty */ +static bool UseSTDIO; /* Use STDIO for debugging purposes instead of pty */ bool CommandMode; -pthread_t Thread; -bool RequestTerminate; - +static bool VM_ThreadLoop(void); +static GSM_Error VM_GSMInitialise(char *model, char *port, char *initlength, GSM_ConnectionType connection, char *synchronizetime); +static int VM_PtySetup(char *bindir); /* If initialised in debug mode, stdin/out is used instead of ptys for interface. */ -bool VM_Initialise(char *model,char *port, char *initlength, GSM_ConnectionType connection, char *bindir, bool debug_mode, bool GSMInit,char *synchronizetime) +bool VM_Initialise(char *model,char *port, char *initlength, GSM_ConnectionType connection, char *bindir, bool debug_mode, bool GSMInit,char *synchronizetime) { - int rtn; - CommandMode = true; - RequestTerminate = false; - if (debug_mode == true) { UseSTDIO = true; } @@ -108,34 +105,34 @@ bool VM_Initialise(char *model,char *port, char *initlength, GSM_ConnectionType return (false); } - /* Create and start thread, */ - rtn = pthread_create(&Thread, NULL, (void *) VM_ThreadLoop, (void *)NULL); - - if (rtn == EAGAIN || rtn == EINVAL) { - return (false); - } - return (true); + /* Create and start thread, */ + return VM_ThreadLoop(); } -void VM_ThreadLoop(void) +static void VM_CharHandler(void); + +static bool VM_ThreadLoop(void) { int res; - struct pollfd ufds; + fd_set readfds; + struct timeval timeout; /* Note we can't use signals here as they are already used in the FBUS code. This may warrant changing the FBUS code around sometime to use select instead to free up the SIGIO handler for mainline code. */ - ufds.fd=PtyRDFD; - ufds.events=POLLIN; - - while (!RequestTerminate) { + for (;;) { if (!CommandMode) { sleep(1); } else { /* If we are in data mode, leave it to datapump to get the data */ - res=poll(&ufds,1,500); + FD_ZERO(&readfds); + FD_SET(PtyRDFD,&readfds); + timeout.tv_sec=0; + timeout.tv_usec=500*1000; + + res = select(PtyRDFD+1,&readfds,NULL/*writefds*/,NULL/*exceptfds*/,&timeout); switch (res) { case 0: /* Timeout */ @@ -143,10 +140,10 @@ void VM_ThreadLoop(void) case -1: perror("VM_ThreadLoop - select"); - exit (-1); + return (false); default: - if (ufds.revents==POLLIN) { + if (FD_ISSET(PtyRDFD,&readfds)) { VM_CharHandler(); } else usleep(500); /* Probably the file has been closed */ break; @@ -160,34 +157,35 @@ void VM_ThreadLoop(void) the virtual modem thread */ void VM_Terminate(void) { - - /* Request termination of thread */ - RequestTerminate = true; - - /* Now wait for thread to terminate. */ - pthread_join(Thread, NULL); - if (!UseSTDIO) { close (PtyRDFD); close (PtyWRFD); } } +static int VM_GetMasterPty(char **name); + /* Open pseudo tty interface and (in due course create a symlink to be /dev/gnokii etc. ) */ -int VM_PtySetup(char *bindir) +static int VM_PtySetup(char *bindir) { int err; +#ifndef UCLINUX char mgnokiidev[200]; +#endif /* UCLINUX */ char *slave_name; +#ifndef UCLINUX char cmdline[200]; +#endif /* UCLINUX */ +#ifndef UCLINUX if (bindir) { strncpy(mgnokiidev, bindir, 200); strcat(mgnokiidev, "/"); } strncat(mgnokiidev, "mgnokiidev", 200 - strlen(bindir)); +#endif /* UCLINUX */ if (UseSTDIO) { PtyRDFD = STDIN_FILENO; @@ -202,22 +200,40 @@ int VM_PtySetup(char *bindir) } PtyWRFD = PtyRDFD; +#ifndef UCLINUX /* Check we haven't been installed setuid root for some reason if so, don't create /dev/gnokii */ if (getuid() != geteuid()) { fprintf(stderr, _("gnokiid should not be installed setuid root!\n")); return (0); } +#endif #ifdef DEBUG - fprintf (stderr, _("Slave pty is %s, calling %s to create /dev/gnokii.\n"), slave_name, mgnokiidev); + fprintf (stderr, _("Slave pty is %s, calling %s to create /dev/gnokii.\n"), slave_name, +#ifndef UCLINUX + mgnokiidev +#else /* UCLINUX */ + "" +#endif /* UCLINUX */ + ); #endif /* DEBUG */ +#ifndef UCLINUX /* Create command line, something line ./mkgnokiidev ttyp0 */ sprintf(cmdline, "%s %s", mgnokiidev, slave_name); /* And use system to call it. */ err = system (cmdline); +#else /* UCLINUX */ + + /* Remove symlink in case it already exists. Don't care if it fails. */ + unlink ("/dev/gnokii"); + + /* Create symlink */ + err = symlink(slave_name, "/dev/gnokii"); + +#endif /* UCLINUX */ return (err); @@ -225,7 +241,7 @@ int VM_PtySetup(char *bindir) /* Handler called when characters received from serial port. calls state machine code to process it. */ -void VM_CharHandler(void) +static void VM_CharHandler(void) { unsigned char buffer[255]; int res; @@ -250,7 +266,7 @@ void VM_CharHandler(void) } /* Initialise GSM interface, returning GSM_Error as appropriate */ -GSM_Error VM_GSMInitialise(char *model, char *port, char *initlength, GSM_ConnectionType connection, char *synchronizetime) +static GSM_Error VM_GSMInitialise(char *model, char *port, char *initlength, GSM_ConnectionType connection, char *synchronizetime) { int count=0; GSM_Error error; @@ -289,7 +305,7 @@ GSM_Error VM_GSMInitialise(char *model, char *port, char *initlength, GSM_Conne Applications by Troan and Johnson */ -int VM_GetMasterPty(char **name) { +static int VM_GetMasterPty(char **name) { #ifdef USE_UNIX98PTYS int master, err; diff --git a/common/devices/device.c b/common/devices/device.c index 45330c2..eb81b25 100644 --- a/common/devices/device.c +++ b/common/devices/device.c @@ -8,12 +8,11 @@ */ +#include "config.h" + #ifndef WIN32 #include "devices/unixserial.h" - #include "devices/unixirda.h" - #include "devices/tekram.h" #include - #include #include #include #include @@ -32,9 +31,9 @@ #include "mversion.h" #endif -char PortDevice[GSM_MAX_DEVICE_NAME_LENGTH]={0x00}; +static char PortDevice[GSM_MAX_DEVICE_NAME_LENGTH]={0x00}; -bool duringwrite; +static bool duringwrite; #ifndef WIN32 @@ -43,26 +42,22 @@ bool duringwrite; pthread_t selThread; #endif -int device_portfd = -1; +static int device_portfd = -1; /* * Structure to store the filedescriptor we use. * */ -int device_getfd(void) +#ifdef DEBUG +static int device_getfd(void) { return device_portfd; } +#endif /* DEBUG */ -int device_open(__const char *__file, int __with_odd_parity) { +static int device_open(__const char *__file, int __with_odd_parity) { switch (CurrentConnectionType) { - case GCT_Tekram: - device_portfd = tekram_open(__file); - break; - case GCT_Irda: - device_portfd = irda_open(); - break; default: device_portfd = serial_opendevice(__file, __with_odd_parity, true, false); break; @@ -79,23 +74,26 @@ void device_close(void) //pthread_join(Thread, NULL); switch (CurrentConnectionType) { - case GCT_Tekram: tekram_close(device_portfd); break; - case GCT_Irda : irda_close(device_portfd); break; default : serial_close(device_portfd); break; } PortDevice[0]=0x00; } +#ifndef UCLINUX + void device_reset(void) { } +#endif /* UCLINUX */ + +#ifdef DEBUG +static void device_dumpserial(void); +#endif /* DEBUG */ + void device_setdtrrts(int __dtr, int __rts) { switch (CurrentConnectionType) { - case GCT_Tekram: - case GCT_Irda: - break; default: serial_setdtrrts(device_portfd, __dtr, __rts); #ifdef DEBUG @@ -108,11 +106,6 @@ void device_setdtrrts(int __dtr, int __rts) void device_changespeed(int __speed) { switch (CurrentConnectionType) { - case GCT_Irda: - break; - case GCT_Tekram: - tekram_changespeed(device_portfd, __speed); - break; default: serial_changespeed(device_portfd, __speed); #ifdef DEBUG @@ -122,11 +115,9 @@ void device_changespeed(int __speed) } } -size_t device_read(__ptr_t __buf, size_t __nbytes) +static size_t device_read(__ptr_t __buf, size_t __nbytes) { switch (CurrentConnectionType) { - case GCT_Tekram: return (tekram_read(device_portfd, __buf, __nbytes)); break; - case GCT_Irda : return ( irda_read(device_portfd, __buf, __nbytes)); break; default : return (serial_read(device_portfd, __buf, __nbytes)); break; } } @@ -142,8 +133,6 @@ size_t device_write(__const __ptr_t __buf, size_t __n) { duringwrite=true; switch (CurrentConnectionType) { - case GCT_Irda : mysize = irda_write(device_portfd, __buf, __n); break; - case GCT_Tekram: mysize = tekram_write(device_portfd, __buf, __n); break; default : mysize = serial_write(device_portfd, __buf, __n); break; } duringwrite=false; @@ -151,7 +140,7 @@ size_t device_write(__const __ptr_t __buf, size_t __n) { } #ifdef DEBUG -void device_dumpserial(void) +static void device_dumpserial(void) { int PortFD; unsigned int Flags=0; @@ -168,7 +157,7 @@ void device_dumpserial(void) } #endif /* DEBUG */ -void SigHandler(int status) +static void SigHandler(int status) { unsigned char buffer[2048]; @@ -223,6 +212,7 @@ bool StartConnection (char *port_device, bool with_odd_parity, GSM_ConnectionTyp struct sigaction sig_io; #endif +#ifndef UCLINUX #ifdef DEBUG if ((strstr(GSM_Info->IrdaModels,"decode")!=NULL) && (CurrentConnectionType == GCT_Irda)) { @@ -230,6 +220,7 @@ bool StartConnection (char *port_device, bool with_odd_parity, GSM_ConnectionTyp return true; } #endif +#endif /* UCLINUX */ if (PortDevice[0]!=0x00) return true; @@ -254,13 +245,12 @@ bool StartConnection (char *port_device, bool with_odd_parity, GSM_ConnectionTyp strcpy(text,"Connection "); switch (con) { case GCT_FBUS :strcpy(text+strlen(text),"FBUS");break; - case GCT_Infrared:strcpy(text+strlen(text),"infrared");break; - case GCT_Irda :strcpy(text+strlen(text),"irda sockets");break; +#ifndef UCLINUX case GCT_MBUS :strcpy(text+strlen(text),"MBUS");break; case GCT_DLR3 :strcpy(text+strlen(text),"DLR3");break; - case GCT_Tekram :strcpy(text+strlen(text),"Tekram");break; case GCT_AT :strcpy(text+strlen(text),"AT");break; default :strcpy(text+strlen(text),"unknown");break; +#endif /* UCLINUX */ } strcpy(text+strlen(text),"\n"); AppendLogText(text,false); @@ -415,11 +405,8 @@ bool StartConnection (char *port_device, bool with_odd_parity, GSM_ConnectionTyp strcpy(text,"Connection "); switch (con) { case GCT_FBUS :strcpy(text+strlen(text),"FBUS");break; - case GCT_Infrared:strcpy(text+strlen(text),"infrared");break; - case GCT_Irda :strcpy(text+strlen(text),"irda sockets");break; case GCT_MBUS :strcpy(text+strlen(text),"MBUS");break; case GCT_DLR3 :strcpy(text+strlen(text),"DLR3");break; - case GCT_Tekram :strcpy(text+strlen(text),"Tekram");break; case GCT_AT :strcpy(text+strlen(text),"AT");break; default :strcpy(text+strlen(text),"unknown");break; } diff --git a/common/devices/unixserial.c b/common/devices/unixserial.c index bc7e37e..ba66941 100644 --- a/common/devices/unixserial.c +++ b/common/devices/unixserial.c @@ -62,10 +62,13 @@ /* Structure to backup the setting of the terminal. */ -struct termios serial_termios; +static struct termios serial_termios; /* Open the serial port and store the settings. */ +#ifdef UCLINUX +static +#endif /* UCLINUX */ int serial_open(__const char *__file, int __oflag) { int __fd; @@ -193,6 +196,8 @@ void serial_setdtrrts(int __fd, int __dtr, int __rts) { } +#ifndef UCLINUX + int serial_select(int fd, struct timeval *timeout) { fd_set readfds; @@ -204,6 +209,8 @@ int serial_select(int fd, struct timeval *timeout) { } +#endif /* UCLINUX */ + /* Change the speed of the serial device. */ @@ -235,7 +242,7 @@ void serial_changespeed(int __fd, int __speed) { if (cfsetspeed(&t, speed) == -1) fprintf(stdout,_("Serial port speed setting failed\n")); #else - cfsetspeed(&t, speed); + (void)cfsetspeed(&t, speed); #endif tcsetattr(__fd, TCSADRAIN, &t); diff --git a/common/files/cfgreader.c b/common/files/cfgreader.c index 9908cc1..ad25708 100644 --- a/common/files/cfgreader.c +++ b/common/files/cfgreader.c @@ -27,8 +27,10 @@ #include "files/cfgreader.h" +#ifndef UCLINUX + /* Read configuration information from a ".INI" style file */ -struct CFG_Header *CFG_ReadFile(char *filename) +static struct CFG_Header *CFG_ReadFile(char *filename) { FILE *handle; char *line; @@ -169,7 +171,7 @@ struct CFG_Header *CFG_ReadFile(char *filename) /* Write configuration information to a config file */ -int CFG_WriteFile(struct CFG_Header *cfg, char *filename) +static int CFG_WriteFile(struct CFG_Header *cfg, char *filename) { /* Not implemented - tricky to do and preserve comments */ @@ -209,7 +211,7 @@ char *CFG_Get(struct CFG_Header *cfg, char *section, char *key) /* Set the value of a key in a config file. Return the new value if the section/key can be found, else return NULL. */ -char *CFG_Set(struct CFG_Header *cfg, char *section, char *key, +static char *CFG_Set(struct CFG_Header *cfg, char *section, char *key, char *value) { struct CFG_Header *h; @@ -287,10 +289,21 @@ struct CFG_Header *CFG_FindGnokiirc() return cfg_info; } +#endif /* UCLINUX */ + int CFG_ReadConfig(char **model, char **port, char **initlength, - char **connection, char **bindir, char **synchronizetime, + char **connection, char **bindir, bool isgnokiid) { +#ifdef UCLINUX + + *model=strdup(CONFIG_CFG_MODEL); + *port=strdup(CONFIG_CFG_PORT); + *initlength=strdup(CONFIG_CFG_INITLENGTH); + *connection=strdup("fbus"); + *bindir=NULL; + +#else /* UCLINUX */ struct CFG_Header *cfg_info; #ifdef WIN32 char *DefaultPort = "com2:"; @@ -300,7 +313,6 @@ int CFG_ReadConfig(char **model, char **port, char **initlength, char *DefaultModel = "auto"; char *DefaultConnection = "fbus"; char *DefaultBindir = "/usr/local/sbin/"; - char *DefaultSynchronizeTime = "yes"; char *DefaultInitLength = "30"; char *section = "global"; @@ -309,7 +321,6 @@ int CFG_ReadConfig(char **model, char **port, char **initlength, (char *)*port = DefaultPort; (char *)*connection = DefaultConnection; (char *)*bindir = DefaultBindir; - (char *)*synchronizetime = DefaultSynchronizeTime; (char *)*initlength = DefaultInitLength; cfg_info=CFG_FindGnokiirc(); @@ -329,11 +340,9 @@ int CFG_ReadConfig(char **model, char **port, char **initlength, (char *)*bindir = CFG_Get(cfg_info, section, "bindir"); if (!*bindir) (char *)*bindir = DefaultBindir; - (char *)*synchronizetime = CFG_Get(cfg_info, section, "synchronizetime"); - if (!*synchronizetime) (char *)*synchronizetime = DefaultSynchronizeTime; - (char *)*initlength = CFG_Get(cfg_info, section, "initlength"); if (!*initlength) (char *)*initlength = "default"; +#endif /* UCLINUX */ return 0; } diff --git a/common/files/midifile.c b/common/files/midifile.c index 9e55249..9b3997a 100644 --- a/common/files/midifile.c +++ b/common/files/midifile.c @@ -2,6 +2,8 @@ /* embedding modified midifile.h and midifile.c into this file */ +#include "config.h" + /***** midifile.h ******/ struct MF { diff --git a/common/gsm-api.c b/common/gsm-api.c index 99b73d7..4546e14 100644 --- a/common/gsm-api.c +++ b/common/gsm-api.c @@ -18,6 +18,8 @@ */ +#include "config.h" + #include #include #include @@ -30,6 +32,7 @@ #include "gsm-api.h" +#ifndef UCLINUX #include "newmodules/n6110.h" #include "newmodules/n7110.h" #include "newmodules/newat.h" @@ -37,9 +40,12 @@ #include "newmodules/sniff/sniff.h" #endif #include "protocol/fbusirda.h" +#endif /* UCLINUX */ #include "protocol/fbus.h" +#ifndef UCLINUX #include "protocol/mbus.h" #include "protocol/at.h" +#endif /* UCLINUX */ #include "files/cfgreader.h" #ifndef WIN32 @@ -81,13 +87,16 @@ GSM_Protocol *Protocol; GSM_PhonebookEntry *CurrentPhonebookEntry; GSM_Error CurrentPhonebookError; +#ifndef UCLINUX GSM_SpeedDial *CurrentSpeedDialEntry; GSM_Error CurrentSpeedDialError; +#endif /* UCLINUX */ unsigned char Current_IMEI[GSM_MAX_IMEI_LENGTH]; unsigned char Current_Revision[GSM_MAX_REVISION_LENGTH]; unsigned char Current_Model[GSM_MAX_MODEL_LENGTH]; +#ifndef UCLINUX GSM_SMSMessage *CurrentSMSMessage; GSM_Error CurrentSMSMessageError; int CurrentSMSPointer; @@ -99,10 +108,12 @@ int CurrentSMSFoldersCount; GSM_OneSMSFolder CurrentSMSFolder; GSM_Error CurrentSMSFolderError; int CurrentSMSFolderID; +#endif /* UCLINUX */ GSM_MemoryStatus *CurrentMemoryStatus; GSM_Error CurrentMemoryStatusError; +#ifndef UCLINUX GSM_NetworkInfo *CurrentNetworkInfo; GSM_Error CurrentNetworkInfoError; @@ -119,6 +130,8 @@ GSM_SecurityCode *CurrentSecurityCode; GSM_DateTime *CurrentDateTime; GSM_Error CurrentDateTimeError; +GSM_Error CurrentResetPhoneSettingsError; + GSM_DateTime *CurrentAlarm; GSM_Error CurrentAlarmError; @@ -131,17 +144,20 @@ GSM_Error CurrentCalendarNotesInfoError; GSM_Error CurrentSetDateTimeError; GSM_Error CurrentSetAlarmError; +int *CurrentFirstCalendarFreePos; +GSM_Error CurrentFirstCalendarFreePosError; +#endif /* UCLINUX */ + GSM_Error CurrentEnableExtendedCommandsError; int CurrentRFLevel, CurrentBatteryLevel, CurrentPowerSource; +#ifndef UCLINUX int CurrentDisplayStatus; GSM_Error CurrentDisplayStatusError; -GSM_Error CurrentResetPhoneSettingsError; - char *CurrentNetmonitor; GSM_Error CurrentNetmonitorError; @@ -164,17 +180,21 @@ int CurrentPressKeyEvent; GSM_Error CurrentPressKeyError; GSM_Error CurrentPlayToneError=GE_UNKNOWN; +#endif /* UCLINUX */ GSM_Error CurrentDialVoiceError; +#ifndef UCLINUX GSM_Error CurrentGetOperatorNameError; GSM_Network *CurrentGetOperatorNameNetwork; GSM_Error CurrentSetOperatorNameError; +#endif /* UCLINUX */ GSM_Error CurrentGetIMEIError; GSM_Error CurrentGetHWError; +#ifndef UCLINUX unsigned char CurrentPPS[4]; GSM_Error CurrentProductProfileSettingsError; @@ -184,9 +204,11 @@ GSM_Error CurrentBinRingtoneError; GSM_BinRingtone *CurrentGetBinRingtone=NULL; GSM_Error CurrentRingtoneError; +#endif /* UCLINUX */ GSM_Error CurrentMagicError; +#ifndef UCLINUX GSM_Error CurrentSimlockInfoError; GSM_AllSimlocks *CurrentSimLock; @@ -201,6 +223,7 @@ GSM_Error CurrentCallDivertError; GSM_CallDivert *CurrentCallDivert; char *CurrentManufacturer; +#endif /* UCLINUX */ /* This is the connection type used in gnokii. */ GSM_ConnectionType CurrentConnectionType; @@ -220,8 +243,13 @@ bool CurrentLinkOK; bool CurrentRequestTerminate; +#ifndef UCLINUX bool CurrentDisableKeepAlive; +#endif /* UCLINUX */ +#ifdef UCLINUX +static +#endif /* UCLINUX */ bool CheckModel (GSM_Information InfoToCheck, char *model, GSM_ConnectionType connection) { bool found_match=false; @@ -229,6 +257,7 @@ bool CheckModel (GSM_Information InfoToCheck, char *model, GSM_ConnectionType co if (strstr(InfoToCheck.FBUSModels, model) != NULL) { if (connection==GCT_FBUS) found_match=true; } +#ifndef UCLINUX if (strstr(InfoToCheck.MBUSModels, model) != NULL) { if (connection==GCT_MBUS) found_match=true; } @@ -247,10 +276,13 @@ bool CheckModel (GSM_Information InfoToCheck, char *model, GSM_ConnectionType co if (strstr(InfoToCheck.TekramModels, model) != NULL) { if (connection==GCT_Tekram) found_match=true; } +#endif /* UCLINUX */ return found_match; } +#ifndef UCLINUX + GSM_Error TryNewNokia(char *model, char *device, char *initlength, GSM_ConnectionType connection, void (*rlp_callback)(RLP_F96Frame *frame)) { int InitLength; int count; @@ -298,6 +330,7 @@ GSM_Error TryNewNokia(char *model, char *device, char *initlength, GSM_Connectio while (N6110_GetModel(phonemodel) != GE_NONE) sleep(1); +#ifndef UCLINUX if (!strcmp(phonemodel,"NPE-3") || !strcmp(phonemodel,"NSE-5")) { GSM->Terminate(); @@ -308,9 +341,14 @@ GSM_Error TryNewNokia(char *model, char *device, char *initlength, GSM_Connectio GSM_LinkOK = &CurrentLinkOK; return GE_NONE; } +#endif /* UCLINUX */ return GE_NONE; } +#endif /* UCLINUX */ + +extern GSM_Information N6110_Information; +extern GSM_Functions N6110_Functions; GSM_Error GSM_Initialise(char *model, char *device, char *initlength, GSM_ConnectionType connection, void (*rlp_callback)(RLP_F96Frame *frame), char* SynchronizeTime) { @@ -318,9 +356,11 @@ GSM_Error GSM_Initialise(char *model, char *device, char *initlength, GSM_Connec GSM_ConnectionType connection2; +#ifndef UCLINUX struct tm *now; time_t nowh; GSM_DateTime Date; +#endif /* UCLINUX */ GSM_Error error; connection2=connection; @@ -328,17 +368,22 @@ GSM_Error GSM_Initialise(char *model, char *device, char *initlength, GSM_Connec CurrentRLP_RXCallback = rlp_callback; CurrentCallPassup=NULL; CurrentPhonebookEntry=NULL; +#ifndef UCLINUX CurrentNetworkInfo = NULL; CurrentGetBitmap=NULL; CurrentPlayToneError=GE_UNKNOWN; strcpy(CurrentIncomingCall," "); CurrentGetBinRingtone=NULL; CurrentNetworkInfo=NULL; +#endif /* UCLINUX */ CurrentRequestTerminate=false; +#ifndef UCLINUX CurrentDisableKeepAlive=false; CurrentCalendarNotesInfo.HowMany=2000; +#endif /* UCLINUX */ CurrentMagicError = GE_BUSY; +#ifndef UCLINUX if (!strcmp(model,"auto")) { /* For now */ @@ -395,10 +440,13 @@ GSM_Error GSM_Initialise(char *model, char *device, char *initlength, GSM_Connec Protocol = &MBUS_Functions; CurrentConnectionType=GCT_MBUS; connection2=GCT_MBUS; +#ifndef UCLINUX if (TryNewNokia(model,device,initlength,CurrentConnectionType,rlp_callback)==GE_NONE) { found_match=true; - } else { + } else +#endif /* UCLINUX */ + { GSM->Terminate(); } } @@ -407,7 +455,10 @@ GSM_Error GSM_Initialise(char *model, char *device, char *initlength, GSM_Connec usleep(50); - } else { + } else +#endif /* UCLINUX */ + { +#ifndef UCLINUX #ifdef DEBUG if (CheckModel (Nsniff_Information, model, connection)) { /* Set pointers to relevant addresses */ @@ -417,6 +468,7 @@ GSM_Error GSM_Initialise(char *model, char *device, char *initlength, GSM_Connec found_match=true; } #endif +#endif /* UCLINUX */ if (CheckModel (N6110_Information, model, connection)) { /* Set pointers to relevant addresses */ @@ -425,6 +477,7 @@ GSM_Error GSM_Initialise(char *model, char *device, char *initlength, GSM_Connec GSM_LinkOK = &CurrentLinkOK; found_match=true; } +#ifndef UCLINUX if (CheckModel (N7110_Information, model, connection)) { /* Set pointers to relevant addresses */ GSM = &N7110_Functions; @@ -439,10 +492,12 @@ GSM_Error GSM_Initialise(char *model, char *device, char *initlength, GSM_Connec GSM_LinkOK = &CurrentLinkOK; found_match=true; } +#endif /* UCLINUX */ if (found_match) { switch (connection) { case GCT_FBUS : Protocol = &FBUS_Functions; break; +#ifndef UCLINUX case GCT_Infrared: Protocol = &FBUS_Functions; break; case GCT_Tekram : Protocol = &FBUS_Functions; break; case GCT_DLR3 : Protocol = &FBUS_Functions; break; @@ -450,6 +505,7 @@ GSM_Error GSM_Initialise(char *model, char *device, char *initlength, GSM_Connec case GCT_Irda : Protocol = &FBUSIRDA_Functions;break; case GCT_AT : Protocol = &AT_Functions; break; case GCT_Default : Protocol = NULL; break; +#endif /* UCLINUX */ } } else return GE_NOTSUPPORTED; @@ -459,6 +515,7 @@ GSM_Error GSM_Initialise(char *model, char *device, char *initlength, GSM_Connec /* Now call model specific initialisation code. */ error=(GSM->Initialise(device, initlength, connection2, rlp_callback)); +#ifndef UCLINUX /* RTH: FIXME: second try for Irda (6210 only?)*/ if ( error!=GE_NONE && connection == GCT_Irda) { @@ -468,7 +525,9 @@ GSM_Error GSM_Initialise(char *model, char *device, char *initlength, GSM_Connec device_close(); error=(GSM->Initialise(device, initlength, connection2, rlp_callback)); } +#endif /* UCLINUX */ +#ifndef UCLINUX if (error==GE_NONE && !strcmp(SynchronizeTime,"yes")) { nowh=time(NULL); @@ -499,10 +558,13 @@ GSM_Error GSM_Initialise(char *model, char *device, char *initlength, GSM_Connec /* FIXME: Error checking should be here. */ GSM->SetDateTime(&Date); } +#endif /* UCLINUX */ return error; } +#ifndef UCLINUX + GSM_Error Unimplemented(void) { return GE_NOTIMPLEMENTED; @@ -513,6 +575,8 @@ GSM_Error NotSupported(void) return GE_NOTSUPPORTED; } +#endif /* UCLINUX */ + /* Applications should call N6110_Terminate to shut down the N6110 thread and close the serial port. */ void NULL_Terminate(void) @@ -578,12 +642,14 @@ GSM_ConnectionType GetConnectionTypeFromString(char *Connection) { GSM_ConnectionType connection=GCT_FBUS; +#ifndef UCLINUX if (!strcmp(Connection, "irda")) connection=GCT_Irda; if (!strcmp(Connection, "infrared")) connection=GCT_Infrared; if (!strcmp(Connection, "mbus")) connection=GCT_MBUS; if (!strcmp(Connection, "dlr3")) connection=GCT_DLR3; if (!strcmp(Connection, "at")) connection=GCT_AT; if (!strcmp(Connection, "tekram210"))connection=GCT_Tekram; +#endif /* UCLINUX */ return connection; } @@ -694,7 +760,7 @@ static OnePhoneModel allmodels[] = { {"" ,"" ,{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}} }; -OnePhoneModel *GetPhoneModelData (const char *num) +static OnePhoneModel *GetPhoneModelData (const char *num) { register int i = 0; @@ -726,6 +792,7 @@ int GetModelFeature (featnum_index num) return (GetPhoneModelData(model)->features[num]); } +#ifndef UCLINUX int LogAvailable=-1; //-1 not checked earlier, 0 not, 1 yes char *logfilename; @@ -790,3 +857,4 @@ bool AppendLogText(u8 *buffer,bool format) { return AppendLog(buffer,strlen(buffer),format); } +#endif /* UCLINUX */ diff --git a/common/gsm-bitmaps.c b/common/gsm-bitmaps.c index 1e96f8b..3dae76c 100644 --- a/common/gsm-bitmaps.c +++ b/common/gsm-bitmaps.c @@ -10,6 +10,8 @@ */ +#include "config.h" + #include #include #include diff --git a/common/gsm-calendar.c b/common/gsm-calendar.c index eadaff6..7bef750 100644 --- a/common/gsm-calendar.c +++ b/common/gsm-calendar.c @@ -10,6 +10,8 @@ */ +#include "config.h" + #include #include #include diff --git a/common/gsm-coding.c b/common/gsm-coding.c index 7baaaa9..26c1e67 100644 --- a/common/gsm-coding.c +++ b/common/gsm-coding.c @@ -8,6 +8,8 @@ */ +#include "config.h" + #include #include @@ -24,6 +26,9 @@ #define NUMBER_OF_7_BIT_ALPHABET_ELEMENTS 128 #ifndef USE_NLS + +#ifndef UCLINUX + static unsigned char GSM_DefaultAlphabet[NUMBER_OF_7_BIT_ALPHABET_ELEMENTS] = { /* ETSI GSM 03.38, version 6.0.1, section 6.2.1; Default alphabet */ @@ -53,13 +58,15 @@ 'x', 'y', 'z', 0xe4, 0xf6, 0xf1, 0xfc, 0xe0 }; +#endif /* UCLINUX */ + #ifndef WIN32 /*Simple UNICODE decoding and encoding from/to iso-8859-2 First version prepared by Martin Kacer Following table contains triplets: first unicode byte, second unicode byte, iso-8859-2 character*/ - unsigned char unicode_table[][3] = + static unsigned char unicode_table[][3] = { /* C< D< E< N< R< S< T< Uo Z< */ {0x01, 0x0C, 0xC8}, {0x01, 0x0E, 0xCF}, {0x01, 0x1A, 0xCC}, @@ -119,6 +126,8 @@ }; #endif +#ifndef UCLINUX + unsigned char EncodeWithDefaultAlphabet(unsigned char value) { unsigned char i; @@ -137,6 +146,11 @@ unsigned char DecodeWithDefaultAlphabet(unsigned char value) return GSM_DefaultAlphabet[value]; } +#endif /* UCLINUX */ + +#ifdef UCLINUX +static +#endif /* UCLINUX */ wchar_t EncodeWithUnicodeAlphabet(unsigned char value) { wchar_t retval; @@ -157,6 +171,9 @@ wchar_t EncodeWithUnicodeAlphabet(unsigned char value) return retval; } +#ifdef UCLINUX +static +#endif /* UCLINUX */ unsigned char DecodeWithUnicodeAlphabet(wchar_t value) { unsigned char retval; @@ -177,6 +194,8 @@ unsigned char DecodeWithUnicodeAlphabet(wchar_t value) #else +#ifndef UCLINUX + /* ETSI GSM 03.38, version 6.0.1, section 6.2.1; Default alphabet */ unsigned char GSM_DefaultAlphabetUnicode[NUMBER_OF_7_BIT_ALPHABET_ELEMENTS+1][2] = { @@ -259,8 +278,12 @@ unsigned char DecodeWithUnicodeAlphabet(wchar_t value) else return retval; } +#endif /* UCLINUX */ + #endif +#ifndef UCLINUX + void DecodeDefault (unsigned char* dest, const unsigned char* src, int len) { int i; @@ -279,6 +302,8 @@ void EncodeDefault (unsigned char* dest, const unsigned char* src, int len) return; } +#endif /* UCLINUX */ + void DecodeUnicode (unsigned char* dest, const unsigned char* src, int len) { int i; @@ -304,6 +329,9 @@ void EncodeUnicode (unsigned char* dest, const unsigned char* src, int len) } } +#ifdef UCLINUX +static +#endif /* UCLINUX */ bool EncodeWithUTF8Alphabet(u8 mychar, u8 *ret1, u8 *ret2) { u8 mychar1,mychar2,mychar3,mychar4; @@ -334,6 +362,8 @@ bool EncodeWithUTF8Alphabet(u8 mychar, u8 *ret1, u8 *ret2) return false; } +#ifndef UCLINUX + void DecodeWithUTF8Alphabet(u8 mychar3, u8 mychar4, u8 *ret) { u8 mychar1, mychar2; @@ -356,6 +386,8 @@ void DecodeWithUTF8Alphabet(u8 mychar3, u8 mychar4, u8 *ret) j=-1; } +#endif /* UCLINUX */ + void EncodeUTF8 (unsigned char* dest, const unsigned char* src, int len) { int i,j=0,z; @@ -373,6 +405,8 @@ void EncodeUTF8 (unsigned char* dest, const unsigned char* src, int len) dest[j++]=0; } +#ifndef UCLINUX + void DecodeUTF8 (unsigned char* dest, const unsigned char* src, int len) { int i=0,j=0; @@ -471,13 +505,12 @@ void EncodeBCD (unsigned char* dest, const unsigned char* src, int len, bool fil unsigned char EncodeWithBCDAlphabet(int value) { - div_t division; - - division=div(value,10); - return ( ( (value-division.quot*10) & 0x0f) << 4) | (division.quot & 0xf); + return ((value%10) << 4) | ((value/10) & 0xf); } int DecodeWithBCDAlphabet(unsigned char value) { return 10*(value & 0x0f)+(value >> 4); } + +#endif /* UCLINUX */ diff --git a/common/gsm-datetime.c b/common/gsm-datetime.c index 589dcb3..13756b0 100644 --- a/common/gsm-datetime.c +++ b/common/gsm-datetime.c @@ -8,14 +8,16 @@ */ -#include -#include - -#include "misc.h" -#include "gsm-datetime.h" -#include "gsm-common.h" +#include "config.h" -char DayOfWeekChar; +#include +#include + +#include "misc.h" +#include "gsm-datetime.h" +#include "gsm-common.h" + +static char DayOfWeekChar; /* Based on article in Polish PC-Kurier 8/1998 page 104 */ /* Archive on http://www.pckurier.pl */ @@ -37,7 +39,9 @@ char *DayOfWeek (int year, int month, int day) { case 6: strcpy(&DayOfWeekChar,"Sat"); break; } return &DayOfWeekChar; -} +} + +#ifndef UCLINUX /* GetMachineDateTime ---------------------------------------------------------- Purpose: Gets system date and time. @@ -47,42 +51,44 @@ Output: date - System date in the format "aaaa-mm-gg". time - System time in the format "hh:mm:ss". Return: - ----------------------------------------------------------------------------- */ -void GetMachineDateTime( char nowdate[], char nowtime[] ) -{ - struct tm *now; - time_t nowh; - - nowh=time(NULL); - now=localtime(&nowh); - - /* I have 100 (for 2000) Year now :-) */ - if (now->tm_year>99 && now->tm_year<1900) { - now->tm_year=now->tm_year+1900; - } - +static void GetMachineDateTime( char nowdate[], char nowtime[] ) +{ + struct tm *now; + time_t nowh; + + nowh=time(NULL); + now=localtime(&nowh); + + /* I have 100 (for 2000) Year now :-) */ + if (now->tm_year>99 && now->tm_year<1900) { + now->tm_year=now->tm_year+1900; + } + sprintf(nowdate,"%04d-%02d-%02d",now->tm_year,now->tm_mon+1,now->tm_mday); - sprintf(nowtime, "%02d:%02d:%02d",now->tm_hour,now->tm_min,now->tm_sec); - -} - -void EncodeDateTime(unsigned char* buffer, GSM_DateTime *datetime) -{ - buffer[0] = datetime->Year / 256; - buffer[1] = datetime->Year % 256; - buffer[2] = datetime->Month; - buffer[3] = datetime->Day; - - buffer[4] = datetime->Hour; - buffer[5] = datetime->Minute; -} - -void DecodeDateTime(unsigned char* buffer, GSM_DateTime *datetime) -{ - datetime->Year = buffer[0] * 256 + buffer[1]; - datetime->Month = buffer[2]; - datetime->Day = buffer[3]; - - datetime->Hour = buffer[4]; - datetime->Minute = buffer[5]; - datetime->Second = buffer[6]; -} + sprintf(nowtime, "%02d:%02d:%02d",now->tm_hour,now->tm_min,now->tm_sec); + +} + +void EncodeDateTime(unsigned char* buffer, GSM_DateTime *datetime) +{ + buffer[0] = datetime->Year / 256; + buffer[1] = datetime->Year % 256; + buffer[2] = datetime->Month; + buffer[3] = datetime->Day; + + buffer[4] = datetime->Hour; + buffer[5] = datetime->Minute; +} + +#endif /* UCLINUX */ + +void DecodeDateTime(unsigned char* buffer, GSM_DateTime *datetime) +{ + datetime->Year = buffer[0] * 256 + buffer[1]; + datetime->Month = buffer[2]; + datetime->Day = buffer[3]; + + datetime->Hour = buffer[4]; + datetime->Minute = buffer[5]; + datetime->Second = buffer[6]; +} diff --git a/common/gsm-networks.c b/common/gsm-networks.c index b36bcf5..f0379f5 100644 --- a/common/gsm-networks.c +++ b/common/gsm-networks.c @@ -10,13 +10,17 @@ */ +#include "config.h" + #include #include "gsm-common.h" #include "gsm-networks.h" #include "gsm-coding.h" -GSM_Country GSM_Countries[] = +#ifndef UCLINUX + +static GSM_Country GSM_Countries[] = { { "202", "Greece" }, { "204", "Netherlands" }, @@ -454,7 +458,7 @@ char *GSM_GetCountryName(char *CountryCode) return GSM_Countries[index].Name; } -char *GSM_GetCountryCode(char *CountryName) +static char *GSM_GetCountryCode(char *CountryName) { int index=0; @@ -480,3 +484,5 @@ void DecodeNetworkCode(unsigned char* buffer, unsigned char* output) output[4]=output[3]; output[3]=' '; } + +#endif /* UCLINUX */ diff --git a/common/gsm-phonebook.c b/common/gsm-phonebook.c index bf0fdd3..d3be5bc 100644 --- a/common/gsm-phonebook.c +++ b/common/gsm-phonebook.c @@ -10,6 +10,8 @@ */ +#include "config.h" + #include #include #include diff --git a/common/gsm-sms.c b/common/gsm-sms.c index 5a35034..cfc0061 100644 --- a/common/gsm-sms.c +++ b/common/gsm-sms.c @@ -8,6 +8,8 @@ */ +#include "config.h" + #include #include #include @@ -18,7 +20,7 @@ #include "gsm-coding.h" /* User data headers */ -GSM_UDHHeader UDHHeaders[] = { +static GSM_UDHHeader UDHHeaders[] = { { GSM_ConcatenatedMessages, 0x05, "\x00\x03\x01\x00\x00" }, /* See GSM 03.40 section 9.2.3.24.1 */ { GSM_DisableVoice, 0x04, "\x01\x02\x00\x00" }, @@ -67,7 +69,8 @@ GSM_UDHHeader UDHHeaders[] = { #define ByteMask ((1 << Bits) - 1) -int GSM_PackSevenBitsToEight(int offset, unsigned char *input, unsigned char *output) +#ifndef UCLINUX +static int GSM_PackSevenBitsToEight(int offset, unsigned char *input, unsigned char *output) { unsigned char *OUT = output; /* Current pointer to the output buffer */ unsigned char *IN = input; /* Current pointer to the input buffer */ @@ -259,7 +262,7 @@ GSM_Error GSM_EncodeSMSDateTime(GSM_DateTime *DT, unsigned char *req) } /* See GSM 03.40 section 9.2.3.11 */ -GSM_Error GSM_DecodeSMSDateTime(GSM_DateTime *DT, unsigned char *req) +static GSM_Error GSM_DecodeSMSDateTime(GSM_DateTime *DT, unsigned char *req) { DT->Year = DecodeWithBCDAlphabet(req[0]); DT->Month = DecodeWithBCDAlphabet(req[1]); @@ -292,7 +295,7 @@ GSM_Error GSM_DecodeSMSDateTime(GSM_DateTime *DT, unsigned char *req) return GE_NONE; } -int GSM_EncodeETSISMSSubmitData(GSM_SMSMessage *SMS, GSM_ETSISMSMessage *ETSI) +static int GSM_EncodeETSISMSSubmitData(GSM_SMSMessage *SMS, GSM_ETSISMSMessage *ETSI) { int off,size=0,size2=0,w,i; @@ -347,7 +350,7 @@ int GSM_EncodeETSISMSSubmitData(GSM_SMSMessage *SMS, GSM_ETSISMSMessage *ETSI) ETSI->TPDCS |= 0x08; #ifdef DEBUG - fprintf(stdout,_("SMS Length is %i\n"),strlen(SMS->MessageText)); + fprintf(stdout,_("SMS Length is %ld\n"),(long)strlen(SMS->MessageText)); #endif EncodeUnicode (ETSI->MessageText+off,SMS->MessageText,strlen(SMS->MessageText)); @@ -821,8 +824,9 @@ GSM_Error GSM_DecodeETSISMS(GSM_SMSMessage *SMS, GSM_ETSISMSMessage *ETSI) return GE_NONE; } +#endif /* UCLINUX */ -void GSM_SetDefaultSMSData (GSM_SMSMessage *SMS) +static void GSM_SetDefaultSMSData (GSM_SMSMessage *SMS) { struct tm *now; time_t nowh; @@ -887,6 +891,9 @@ void GSM_SetDefaultSMSData (GSM_SMSMessage *SMS) - GSM 03.40 version 6.1.0 Release 1997, section 9.2.3.24 - Smart Messaging Specification, Revision 1.0.0, September 15, 1997 */ +#ifdef UCLINUX +static +#endif /* UCLINUX */ GSM_Error EncodeUDHHeader(char *text, GSM_UDH UDHType) { int i=0; @@ -910,7 +917,7 @@ GSM_Error EncodeUDHHeader(char *text, GSM_UDH UDHType) return GE_NONE; } -int GSM_MakeSinglePartSMS2(GSM_SMSMessage *SMS, +static int GSM_MakeSinglePartSMS2(GSM_SMSMessage *SMS, unsigned char *MessageBuffer,int cur, GSM_UDH UDHType, GSM_Coding_Type Coding){ int j; diff --git a/common/gsm-wap.c b/common/gsm-wap.c index 0ef16cc..fb9d3d5 100644 --- a/common/gsm-wap.c +++ b/common/gsm-wap.c @@ -10,6 +10,8 @@ */ +#include "config.h" + #include #include #include diff --git a/common/misc.c b/common/misc.c index 34d81b7..b355232 100644 --- a/common/misc.c +++ b/common/misc.c @@ -8,6 +8,8 @@ */ +#include "config.h" + #include #include #include @@ -57,6 +59,8 @@ int GetLine(FILE *File, char *Line, int count) { } else return -1; } +#ifndef UCLINUX + /* * like atoi, but of a non-null-terminated string of a specified portion */ @@ -69,6 +73,8 @@ int mem_to_int(const char str[], int len) return( atoi(aux) ); } +#endif /* UCLINUX */ + /* * make hexdump of Message */ @@ -156,6 +162,8 @@ void txhexdump(u16 MessageLength, u8 *MessageBuffer) #ifndef WIN32 +#ifndef UCLINUX + #define max_buf_len 128 #define lock_path "/var/lock/LCK.." @@ -225,7 +233,7 @@ char *lock_device(const char* port) } /* Removes lock and frees memory */ -bool unlock_device(char *lock_file) +static bool unlock_device(char *lock_file) { int err; @@ -237,4 +245,7 @@ bool unlock_device(char *lock_file) free(lock_file); return (err + 1); } + +#endif /* UCLINUX */ + #endif /* WIN32 */ diff --git a/common/newmodules/n6110.c b/common/newmodules/n6110.c index d067fed..481c92e 100644 --- a/common/newmodules/n6110.c +++ b/common/newmodules/n6110.c @@ -1,112 +1,166 @@ -/* - - G N O K I I - - A Linux/Unix toolset and driver for Nokia mobile phones. - - Released under the terms of the GNU GPL, see file COPYING for more details. - - This file provides an API for accessing functions on the 6110 and similar - phones. - -*/ - -/* "Turn on" prototypes in n-6110.h */ - -#define __n_6110_c - -/* System header files */ -#include -#include -#include - -#ifdef WIN32 - #include "misc_win32.h" -#endif - -/* Various header file */ -#ifndef VC6 - #include "config.h" -#endif - -#include "gsm-api.h" -#include "gsm-coding.h" -#include "newmodules/n6110.h" -#include "newmodules/n7110.h" -#include "protocol/fbus.h" -#include "devices/device.h" - /* Global variables used by code in gsm-api.c to expose the functions - supported by this model of phone. */ - - - - - - - -/* Here we initialise model specific functions. */ -GSM_Functions N6110_Functions = { - N6110_Initialise, - N6110_DispatchMessage, - NULL_Terminate, - NULL_KeepAlive, - N6110_GetMemoryLocation, - N6110_WritePhonebookLocation, - N6110_GetSpeedDial, - N6110_SetSpeedDial, - N6110_GetMemoryStatus, - N6110_GetSMSStatus, - N6110_GetSMSCenter, - N6110_SetSMSCenter, - N6110_GetSMSMessage, - N6110_DeleteSMSMessage, - N6110_SendSMSMessage, - N6110_SaveSMSMessage, - N6110_GetRFLevel, - N6110_GetBatteryLevel, - N6110_GetPowerSource, - N6110_GetDisplayStatus, - N6110_EnterSecurityCode, - N6110_GetSecurityCodeStatus, - N6110_GetSecurityCode, - N6110_GetIMEI, - N6110_GetRevision, - N6110_GetModel, - N6110_GetDateTime, - N6110_SetDateTime, - N6110_GetAlarm, - N6110_SetAlarm, - N6110_DialVoice, - N6110_DialData, - N6110_GetIncomingCallNr, - N6110_GetNetworkInfo, - N6110_GetCalendarNote, - N6110_WriteCalendarNote, - N6110_DeleteCalendarNote, - N6110_NetMonitor, - N6110_SendDTMF, - N6110_GetBitmap, - N6110_SetBitmap, - N6110_SetRingTone, - N6110_SetBinRingTone, - N6110_GetBinRingTone, - N6110_Reset, - N6110_GetProfile, - N6110_SetProfile, - N6110_SendRLPFrame, - N6110_CancelCall, - N6110_PressKey, - N6110_EnableDisplayOutput, - N6110_DisableDisplayOutput, - N6110_EnableCellBroadcast, - N6110_DisableCellBroadcast, - N6110_ReadCellBroadcast, - N6110_PlayTone, - N6110_GetProductProfileSetting, - N6110_SetProductProfileSetting, - N6110_GetOperatorName, - N6110_SetOperatorName, - N6110_GetVoiceMailbox, N6110_Tests, +/* + + G N O K I I + + A Linux/Unix toolset and driver for Nokia mobile phones. + + Released under the terms of the GNU GPL, see file COPYING for more details. + + This file provides an API for accessing functions on the 6110 and similar + phones. + +*/ + +#include "config.h" + +/* "Turn on" prototypes in n-6110.h */ + +#define __n_6110_c + +/* System header files */ +#include +#include +#include + +#ifdef WIN32 + #include "misc_win32.h" +#endif + +/* Various header file */ +#ifndef VC6 + #include "config.h" +#endif + +#include "gsm-api.h" +#include "gsm-coding.h" +#include "newmodules/n6110.h" +#include "newmodules/n7110.h" +#include "protocol/fbus.h" +#include "devices/device.h" +/* Global variables used by code in gsm-api.c to expose the functions + supported by this model of phone. */ + + + + + + + +/* Here we initialise model specific functions. */ +GSM_Functions N6110_Functions = { + N6110_Initialise, + N6110_DispatchMessage, + NULL_Terminate, + NULL_KeepAlive, + N6110_GetMemoryLocation, + N6110_WritePhonebookLocation, +#ifndef UCLINUX + N6110_GetSpeedDial, + N6110_SetSpeedDial, +#else /* UCLINUX */ + NULL, + NULL, +#endif /* UCLINUX */ + N6110_GetMemoryStatus, +#ifndef UCLINUX + N6110_GetSMSStatus, + N6110_GetSMSCenter, + N6110_SetSMSCenter, + N6110_GetSMSMessage, + N6110_DeleteSMSMessage, + N6110_SendSMSMessage, + N6110_SaveSMSMessage, +#else /* UCLINUX */ + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, +#endif /* UCLINUX */ + N6110_GetRFLevel, + N6110_GetBatteryLevel, + N6110_GetPowerSource, +#ifndef UCLINUX + N6110_GetDisplayStatus, + N6110_EnterSecurityCode, + N6110_GetSecurityCodeStatus, + N6110_GetSecurityCode, + N6110_GetIMEI, + N6110_GetRevision, + N6110_GetModel, + N6110_GetDateTime, + N6110_SetDateTime, + N6110_GetAlarm, + N6110_SetAlarm, + N6110_DialVoice, +#else /* UCLINUX */ + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, +#endif /* UCLINUX */ + N6110_DialData, +#ifndef UCLINUX + N6110_GetIncomingCallNr, + N6110_GetNetworkInfo, + N6110_GetCalendarNote, + N6110_WriteCalendarNote, + N6110_DeleteCalendarNote, + N6110_NetMonitor, + N6110_SendDTMF, + N6110_GetBitmap, + N6110_SetBitmap, + N6110_SetRingTone, + N6110_SetBinRingTone, + N6110_GetBinRingTone, +#else /* UCLINUX */ + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, +#endif /* UCLINUX */ + N6110_Reset, +#ifndef UCLINUX + N6110_GetProfile, + N6110_SetProfile, + N6110_SendRLPFrame, +#else /* UCLINUX */ + NULL, + NULL, + NULL, +#endif /* UCLINUX */ + N6110_CancelCall, +#ifndef UCLINUX + N6110_PressKey, + N6110_EnableDisplayOutput, + N6110_DisableDisplayOutput, + N6110_EnableCellBroadcast, + N6110_DisableCellBroadcast, + N6110_ReadCellBroadcast, + N6110_PlayTone, + N6110_GetProductProfileSetting, + N6110_SetProductProfileSetting, + N6110_GetOperatorName, + N6110_SetOperatorName, + N6110_GetVoiceMailbox, N6110_Tests, N6110_SimlockInfo, UNIMPLEMENTED, //GetCalendarNotesInfo N6110_GetSMSFolders, @@ -116,568 +170,612 @@ GSM_Functions N6110_Functions = { N7110_GetWAPSettings, N6110_CallDivert, N6110_AnswerCall, +#else /* UCLINUX */ + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, NULL, + NULL, + NULL, //GetCalendarNotesInfo + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, +#endif /* UCLINUX */ N6110_GetManufacturer -}; - -/* Mobile phone information */ - -GSM_Information N6110_Information = { - "3210|3310|3330|5110|5130|5190|6110|6130|6150|6190|8210|8850", - /* Supported models in FBUS */ - "3210|3310|3330|5110|5130|5190|6110|6130|6150|6190|8210|8850", - /* Supported models in MBUS */ - "6110|6130|6150|8210|8850", - /* Supported models in FBUS over infrared */ - "", - /* Supported models in FBUS over DLR3 */ +}; + +/* Mobile phone information */ + +GSM_Information N6110_Information = { + "3210|3310|3330|5110|5130|5190|6110|6130|6150|6190|8210|8850", + /* Supported models in FBUS */ + "3210|3310|3330|5110|5130|5190|6110|6130|6150|6190|8210|8850", + /* Supported models in MBUS */ + "6110|6130|6150|8210|8850", + /* Supported models in FBUS over infrared */ + "", + /* Supported models in FBUS over DLR3 */ "", /* AT commands */ "8210|8850", /* infrared sockets */ "6110|6130|6150|8210|8850", - /* Supported models in FBUS over infrared with Tekram device */ - 4, /* Max RF Level */ - 0, /* Min RF Level */ - GRF_Arbitrary, /* RF level units */ - 4, /* Max Battery Level */ - 0, /* Min Battery Level */ - GBU_Arbitrary, /* Battery level units */ - GDT_DateTime, /* Have date/time support */ - GDT_TimeOnly, /* Alarm supports time only */ - 1 /* Only one alarm available */ -}; - -const char *N6110_MemoryType_String [] = { - "", /* 0x00 */ - "MT", /* 0x01 */ - "ME", /* 0x02 */ - "SM", /* 0x03 */ - "FD", /* 0x04 */ - "ON", /* 0x05 */ - "EN", /* 0x06 */ - "DC", /* 0x07 */ - "RC", /* 0x08 */ - "MC", /* 0x09 */ -}; - -/* Magic bytes from the phone. */ -unsigned char MagicBytes[4] = { 0x00, 0x00, 0x00, 0x00 }; - -/* For DisplayOutput */ -char PhoneScreen[5+1][27+1]; -int OldX=1000,OldY=0,NewX=0,NewY=0; - -void N6110_ReplyEnableExtendedCommands(u16 MessageLength, u8 *MessageBuffer, u8 MessageType) { - -#ifdef DEBUG - fprintf(stdout, _("Message: Answer for EnableExtendedSecurityCommands frame, meaning not known :-(\n")); -#endif /* DEBUG */ - - CurrentEnableExtendedCommandsError=GE_NONE; -} - -/* If you set make some things (for example, - change Security Code from phone's menu, disable and enable - phone), it won't answer for 0x40 frame - you won't be able - to play tones, get netmonitor, etc. - - This function do thing called "Enabling extended security commands" - - it enables 0x40 frame functions. - - This frame can also some other things - see below */ -GSM_Error N6110_EnableExtendedCommands (unsigned char status) -{ - unsigned char req[4] = { 0x00, - 0x01,0x64, /* Enable extended commands request */ - 0x01 }; /* 0x01 - on, 0x00 - off, - 0x03 & 0x04 - soft & hard reset, - 0x06 - CONTACT SERVICE */ - - /* 0x06 MAKES CONTACT SERVICE! BE CAREFULL! */ + /* Supported models in FBUS over infrared with Tekram device */ + 4, /* Max RF Level */ + 0, /* Min RF Level */ + GRF_Arbitrary, /* RF level units */ + 4, /* Max Battery Level */ + 0, /* Min Battery Level */ + GBU_Arbitrary, /* Battery level units */ + GDT_DateTime, /* Have date/time support */ + GDT_TimeOnly, /* Alarm supports time only */ + 1 /* Only one alarm available */ +}; + +#ifdef DEBUG +static const char *N6110_MemoryType_String [] = { + "", /* 0x00 */ + "MT", /* 0x01 */ + "ME", /* 0x02 */ + "SM", /* 0x03 */ + "FD", /* 0x04 */ + "ON", /* 0x05 */ + "EN", /* 0x06 */ + "DC", /* 0x07 */ + "RC", /* 0x08 */ + "MC", /* 0x09 */ +}; +#endif /* DEBUG */ + +/* Magic bytes from the phone. */ +static unsigned char MagicBytes[4] = { 0x00, 0x00, 0x00, 0x00 }; + +/* For DisplayOutput */ +#ifndef UCLINUX +static char PhoneScreen[5+1][27+1]; +static int OldX=1000,OldY=0,NewX=0,NewY=0; +#endif /* UCLINUX */ + +void N6110_ReplyEnableExtendedCommands(u16 MessageLength, u8 *MessageBuffer, u8 MessageType) { + +#ifdef DEBUG + fprintf(stdout, _("Message: Answer for EnableExtendedSecurityCommands frame, meaning not known :-(\n")); +#endif /* DEBUG */ + + CurrentEnableExtendedCommandsError=GE_NONE; +} + +/* If you set make some things (for example, + change Security Code from phone's menu, disable and enable + phone), it won't answer for 0x40 frame - you won't be able + to play tones, get netmonitor, etc. + + This function do thing called "Enabling extended security commands" - + it enables 0x40 frame functions. + + This frame can also some other things - see below */ +GSM_Error N6110_EnableExtendedCommands (unsigned char status) +{ + unsigned char req[4] = { 0x00, + 0x01,0x64, /* Enable extended commands request */ + 0x01 }; /* 0x01 - on, 0x00 - off, + 0x03 & 0x04 - soft & hard reset, + 0x06 - CONTACT SERVICE */ + + /* 0x06 MAKES CONTACT SERVICE! BE CAREFULL! */ /* When use 0x03 and had during session changed time & date some phones (like 6150 or 6210) can ask for time & date after reset or disable clock on the screen */ - if (status!=0x06) req[3] = status; - - return NULL_SendMessageSequence - (50, &CurrentEnableExtendedCommandsError, 4, 0x40, req); -} - -void N6110_ReplyIMEI(u16 MessageLength, u8 *MessageBuffer, u8 MessageType) { - -#if defined WIN32 || !defined HAVE_SNPRINTF - sprintf(Current_IMEI, "%s", MessageBuffer+4); -#else - snprintf(Current_IMEI, GSM_MAX_IMEI_LENGTH, "%s", MessageBuffer+4); -#endif - -#ifdef DEBUG - fprintf(stdout, _("Message: IMEI %s received\n"),Current_IMEI); -#endif - - CurrentGetIMEIError=GE_NONE; -} - -GSM_Error N6110_SendIMEIFrame() -{ - unsigned char req[4] = {0x00, 0x01, 0x66, 0x00}; - - GSM_Error error; - - error=N6110_EnableExtendedCommands(0x01); - if (error!=GE_NONE) return error; - - return NULL_SendMessageSequence (20, &CurrentGetIMEIError, 4, 0x40, req); -} - -void N6110_ReplyHW(u16 MessageLength, u8 *MessageBuffer, u8 MessageType) { - - int i, j; - - if (MessageBuffer[3]==0x05) { - -#ifdef DEBUG - fprintf(stdout,_("Message: Hardware version received: ")); -#endif - - j=strlen(Current_Revision); - Current_Revision[j++]=','; - Current_Revision[j++]=' '; - Current_Revision[j++]='H'; - Current_Revision[j++]='W'; - - for (i=5;i<9;i++) { -#ifdef DEBUG - fprintf(stdout,_("%c"), MessageBuffer[i]); -#endif - Current_Revision[j++]=MessageBuffer[i]; - } - -#ifdef DEBUG - fprintf(stdout,_("\n")); -#endif - - CurrentGetHWError=GE_NONE; - } -} - -GSM_Error N6110_SendHWFrame() -{ - unsigned char req[4] = {0x00, 0x01, 0xc8, 0x05}; - - GSM_Error error; - - error=N6110_EnableExtendedCommands(0x01); - if (error!=GE_NONE) return error; - - return NULL_SendMessageSequence (20, &CurrentGetHWError, 4, 0x40, req); -} - -void N6110_ReplyID(u16 MessageLength, u8 *MessageBuffer, u8 MessageType) { - - int i, j; - -#ifdef DEBUG - fprintf(stdout, _("Message: Mobile phone model identification received:\n")); - fprintf(stdout, _(" Firmware: ")); -#endif - - strcpy(Current_Revision,"SW"); - - i=6;j=2; - while (MessageBuffer[i]!=0x0a) { - Current_Revision[j]=MessageBuffer[i]; -#ifdef DEBUG - fprintf(stdout, _("%c"),MessageBuffer[i]); -#endif - if (j==GSM_MAX_REVISION_LENGTH-1) { -#ifdef DEBUG - fprintf(stderr,_("ERROR: increase GSM_MAX_REVISION_LENGTH!\n")); -#endif - break; - } - j++; - i++; - } - Current_Revision[j+1]=0; - -#ifdef DEBUG - fprintf(stdout, _("\n Firmware date: ")); -#endif - - i++; - while (MessageBuffer[i]!=0x0a) { -#ifdef DEBUG - fprintf(stdout, _("%c"),MessageBuffer[i]); -#endif - i++; - } - -#ifdef DEBUG - fprintf(stdout, _("\n Model: ")); -#endif /* DEBUG */ - - i++;j=0; - while (MessageBuffer[i]!=0x0a) { - Current_Model[j]=MessageBuffer[i]; -#ifdef DEBUG - fprintf(stdout, _("%c"),MessageBuffer[i]); -#endif - if (j==GSM_MAX_MODEL_LENGTH-1) { -#ifdef DEBUG - fprintf(stderr,_("ERROR: increase GSM_MAX_MODEL_LENGTH!\n")); -#endif - break; - } - j++; - i++; - } - Current_Model[j+1]=0; - -#ifdef DEBUG - fprintf(stdout, _("\n")); -#endif /* DEBUG */ - - CurrentMagicError=GE_NONE; -} - -GSM_Error N6110_SendIDFrame() -{ - unsigned char req[5] = {N6110_FRAME_HEADER, 0x03, 0x00}; - - return NULL_SendMessageSequence (50, &CurrentMagicError, 5, 0xd1, req); -} - -/* This function send the status request to the phone. */ -/* Seems to be ignored in N3210 */ -GSM_Error N6110_SendStatusRequest(void) -{ - unsigned char req[] = {N6110_FRAME_HEADER, 0x01}; - - Protocol->SendMessage(4, 0x04, req); - - return (GE_NONE); -} - -void N6110_ReplyGetAuthentication(u16 MessageLength, u8 *MessageBuffer, u8 MessageType) { - -#if defined WIN32 || !defined HAVE_SNPRINTF - sprintf(Current_IMEI, "%s", MessageBuffer+9); - sprintf(Current_Model, "%s", MessageBuffer+25); - sprintf(Current_Revision, "SW%s, HW%s", MessageBuffer+44, MessageBuffer+39); -#else - snprintf(Current_IMEI, GSM_MAX_IMEI_LENGTH, "%s", MessageBuffer+9); - snprintf(Current_Model, GSM_MAX_MODEL_LENGTH, "%s", MessageBuffer+25); - snprintf(Current_Revision, GSM_MAX_REVISION_LENGTH, "SW%s, HW%s", MessageBuffer+44, MessageBuffer+39); -#endif - -#ifdef DEBUG - fprintf(stdout, _("Message: Mobile phone identification received:\n")); - fprintf(stdout, _(" IMEI: %s\n"), Current_IMEI); - fprintf(stdout, _(" Model: %s\n"), Current_Model); - fprintf(stdout, _(" Production Code: %s\n"), MessageBuffer+31); - fprintf(stdout, _(" HW: %s\n"), MessageBuffer+39); - fprintf(stdout, _(" Firmware: %s\n"), MessageBuffer+44); - - /* These bytes are probably the source of the "Accessory not connected" - messages on the phone when trying to emulate NCDS... I hope.... - UPDATE: of course, now we have the authentication algorithm. */ - fprintf(stdout, _(" Magic bytes: %02x %02x %02x %02x\n"), MessageBuffer[50], MessageBuffer[51], MessageBuffer[52], MessageBuffer[53]); -#endif /* DEBUG */ - - MagicBytes[0]=MessageBuffer[50]; - MagicBytes[1]=MessageBuffer[51]; - MagicBytes[2]=MessageBuffer[52]; - MagicBytes[3]=MessageBuffer[53]; - - CurrentMagicError=GE_NONE; -} - -/* This function provides Nokia authentication protocol. - - This code is written specially for gnokii project by Odinokov Serge. - If you have some special requests for Serge just write him to - apskaita@post.omnitel.net or serge@takas.lt - - Reimplemented in C by Pavel Janík ml. - - Nokia authentication protocol is used in the communication between Nokia - mobile phones (e.g. Nokia 6110) and Nokia Cellular Data Suite software, - commercially sold by Nokia Corp. - - The authentication scheme is based on the token send by the phone to the - software. The software does it's magic (see the function - FB61_GetNokiaAuth()) and returns the result back to the phone. If the - result is correct the phone responds with the message "Accessory - connected!" displayed on the LCD. Otherwise it will display "Accessory not - supported" and some functions will not be available for use. - - The specification of the protocol is not publicly available, no comment. */ -void N6110_GetNokiaAuth(unsigned char *Imei, unsigned char *MagicBytes, unsigned char *MagicResponse) -{ - - int i, j, CRC=0; - - /* This is our temporary working area. */ - - unsigned char Temp[16]; - - /* Here we put FAC (Final Assembly Code) and serial number into our area. */ - - Temp[0] = Imei[6]; - Temp[1] = Imei[7]; - Temp[2] = Imei[8]; - Temp[3] = Imei[9]; - Temp[4] = Imei[10]; - Temp[5] = Imei[11]; - Temp[6] = Imei[12]; - Temp[7] = Imei[13]; - - /* And now the TAC (Type Approval Code). */ - - Temp[8] = Imei[2]; - Temp[9] = Imei[3]; - Temp[10] = Imei[4]; - Temp[11] = Imei[5]; - - /* And now we pack magic bytes from the phone. */ - - Temp[12] = MagicBytes[0]; - Temp[13] = MagicBytes[1]; - Temp[14] = MagicBytes[2]; - Temp[15] = MagicBytes[3]; - - for (i=0; i<=11; i++) - if (Temp[i + 1]& 1) - Temp[i]<<=1; - - switch (Temp[15] & 0x03) { - - case 1: - case 2: - j = Temp[13] & 0x07; - - for (i=0; i<=3; i++) - Temp[i+j] ^= Temp[i+12]; - - break; - - default: - j = Temp[14] & 0x07; - - for (i=0; i<=3; i++) - Temp[i + j] |= Temp[i + 12]; - } - - for (i=0; i<=15; i++) - CRC ^= Temp[i]; - - for (i=0; i<=15; i++) { - - switch (Temp[15 - i] & 0x06) { - - case 0: - j = Temp[i] | CRC; - break; - - case 2: - case 4: - j = Temp[i] ^ CRC; - break; - - case 6: - j = Temp[i] & CRC; - break; - } - - if (j == CRC) - j = 0x2c; - - if (Temp[i] == 0) - j = 0; - - MagicResponse[i] = j; - - } -} - -GSM_Error N6110_Authentication() -{ - unsigned char connect1[] = {N6110_FRAME_HEADER, 0x0d, 0x00, 0x00, 0x02}; - unsigned char connect2[] = {N6110_FRAME_HEADER, 0x20, 0x02}; - unsigned char connect3[] = {N6110_FRAME_HEADER, 0x0d, 0x01, 0x00, 0x02}; - unsigned char connect4[] = {N6110_FRAME_HEADER, 0x10}; - - unsigned char magic_connect[] = {N6110_FRAME_HEADER, - 0x12, - - /* The real magic goes here ... These bytes are filled in with the - function N6110_GetNokiaAuth(). */ - - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - - /* NOKIA&GNOKII Accessory */ - - 0x4e, 0x4f, 0x4b, 0x49, 0x41, 0x26, 0x4e, 0x4f, 0x4b, 0x49, 0x41, 0x20, - 0x61, 0x63, 0x63, 0x65, 0x73, 0x73, 0x6f, 0x72, 0x79, - - 0x00, 0x00, 0x00, 0x00}; - -#ifdef DEBUG - fprintf(stdout,_("Making authentication!\n")); -#endif - - usleep(100); Protocol->SendMessage(7, 0x02, connect1); - usleep(100); Protocol->SendMessage(5, 0x02, connect2); - usleep(100); Protocol->SendMessage(7, 0x02, connect3); - - CurrentMagicError = GE_BUSY; - - usleep(100); Protocol->SendMessage(4, 0x64, connect4); - if (NULL_WaitUntil(50,&CurrentMagicError)!=GE_NONE) return GE_TIMEOUT; - - N6110_GetNokiaAuth(Current_IMEI, MagicBytes, magic_connect+4); - - Protocol->SendMessage(45, 0x64, magic_connect); - -#ifdef DEBUG - fprintf(stdout,_("End of authentication!\n")); -#endif - - return GE_NONE; -} - -/* Initialise variables and state machine. */ -GSM_Error N6110_Initialise(char *port_device, char *initlength, - GSM_ConnectionType connection, - void (*rlp_callback)(RLP_F96Frame *frame)) -{ - unsigned char init_char = N6110_SYNC_BYTE; - unsigned char end_init_char = N6110_IR_END_SYNC_BYTE; - - int count; - int InitLength; - - if (Protocol->Initialise(port_device,initlength,connection,rlp_callback)!=GE_NONE) - { - return GE_NOTSUPPORTED; - } + if (status!=0x06) req[3] = status; + + return NULL_SendMessageSequence + (50, &CurrentEnableExtendedCommandsError, 4, 0x40, req); +} + +void N6110_ReplyIMEI(u16 MessageLength, u8 *MessageBuffer, u8 MessageType) { + +#if defined WIN32 || !defined HAVE_SNPRINTF + sprintf(Current_IMEI, "%s", MessageBuffer+4); +#else + snprintf(Current_IMEI, GSM_MAX_IMEI_LENGTH, "%s", MessageBuffer+4); +#endif + +#ifdef DEBUG + fprintf(stdout, _("Message: IMEI %s received\n"),Current_IMEI); +#endif + + CurrentGetIMEIError=GE_NONE; +} + +GSM_Error N6110_SendIMEIFrame() +{ + unsigned char req[4] = {0x00, 0x01, 0x66, 0x00}; + + GSM_Error error; + + error=N6110_EnableExtendedCommands(0x01); + if (error!=GE_NONE) return error; + + return NULL_SendMessageSequence (20, &CurrentGetIMEIError, 4, 0x40, req); +} + +void N6110_ReplyHW(u16 MessageLength, u8 *MessageBuffer, u8 MessageType) { + + int i, j; + + if (MessageBuffer[3]==0x05) { + +#ifdef DEBUG + fprintf(stdout,_("Message: Hardware version received: ")); +#endif + + j=strlen(Current_Revision); + Current_Revision[j++]=','; + Current_Revision[j++]=' '; + Current_Revision[j++]='H'; + Current_Revision[j++]='W'; + + for (i=5;i<9;i++) { +#ifdef DEBUG + fprintf(stdout,_("%c"), MessageBuffer[i]); +#endif + Current_Revision[j++]=MessageBuffer[i]; + } + +#ifdef DEBUG + fprintf(stdout,_("\n")); +#endif + + CurrentGetHWError=GE_NONE; + } +} + +GSM_Error N6110_SendHWFrame() +{ + unsigned char req[4] = {0x00, 0x01, 0xc8, 0x05}; + + GSM_Error error; + + error=N6110_EnableExtendedCommands(0x01); + if (error!=GE_NONE) return error; + + return NULL_SendMessageSequence (20, &CurrentGetHWError, 4, 0x40, req); +} + +void N6110_ReplyID(u16 MessageLength, u8 *MessageBuffer, u8 MessageType) { + + int i, j; + +#ifdef DEBUG + fprintf(stdout, _("Message: Mobile phone model identification received:\n")); + fprintf(stdout, _(" Firmware: ")); +#endif + + strcpy(Current_Revision,"SW"); + + i=6;j=2; + while (MessageBuffer[i]!=0x0a) { + Current_Revision[j]=MessageBuffer[i]; +#ifdef DEBUG + fprintf(stdout, _("%c"),MessageBuffer[i]); +#endif + if (j==GSM_MAX_REVISION_LENGTH-1) { +#ifdef DEBUG + fprintf(stderr,_("ERROR: increase GSM_MAX_REVISION_LENGTH!\n")); +#endif + break; + } + j++; + i++; + } + Current_Revision[j+1]=0; + +#ifdef DEBUG + fprintf(stdout, _("\n Firmware date: ")); +#endif + + i++; + while (MessageBuffer[i]!=0x0a) { +#ifdef DEBUG + fprintf(stdout, _("%c"),MessageBuffer[i]); +#endif + i++; + } + +#ifdef DEBUG + fprintf(stdout, _("\n Model: ")); +#endif /* DEBUG */ + + i++;j=0; + while (MessageBuffer[i]!=0x0a) { + Current_Model[j]=MessageBuffer[i]; +#ifdef DEBUG + fprintf(stdout, _("%c"),MessageBuffer[i]); +#endif + if (j==GSM_MAX_MODEL_LENGTH-1) { +#ifdef DEBUG + fprintf(stderr,_("ERROR: increase GSM_MAX_MODEL_LENGTH!\n")); +#endif + break; + } + j++; + i++; + } + Current_Model[j+1]=0; + +#ifdef DEBUG + fprintf(stdout, _("\n")); +#endif /* DEBUG */ + + CurrentMagicError=GE_NONE; +} + +GSM_Error N6110_SendIDFrame() +{ + unsigned char req[5] = {N6110_FRAME_HEADER, 0x03, 0x00}; + + return NULL_SendMessageSequence (50, &CurrentMagicError, 5, 0xd1, req); +} + +/* This function send the status request to the phone. */ +/* Seems to be ignored in N3210 */ +GSM_Error N6110_SendStatusRequest(void) +{ + unsigned char req[] = {N6110_FRAME_HEADER, 0x01}; + + Protocol->SendMessage(4, 0x04, req); + + return (GE_NONE); +} + +static void N6110_ReplyGetAuthentication(u16 MessageLength, u8 *MessageBuffer, u8 MessageType) { + +#if defined WIN32 || !defined HAVE_SNPRINTF + sprintf(Current_IMEI, "%s", MessageBuffer+9); + sprintf(Current_Model, "%s", MessageBuffer+25); + sprintf(Current_Revision, "SW%s, HW%s", MessageBuffer+44, MessageBuffer+39); +#else + snprintf(Current_IMEI, GSM_MAX_IMEI_LENGTH, "%s", MessageBuffer+9); + snprintf(Current_Model, GSM_MAX_MODEL_LENGTH, "%s", MessageBuffer+25); + snprintf(Current_Revision, GSM_MAX_REVISION_LENGTH, "SW%s, HW%s", MessageBuffer+44, MessageBuffer+39); +#endif + +#ifdef DEBUG + fprintf(stdout, _("Message: Mobile phone identification received:\n")); + fprintf(stdout, _(" IMEI: %s\n"), Current_IMEI); + fprintf(stdout, _(" Model: %s\n"), Current_Model); + fprintf(stdout, _(" Production Code: %s\n"), MessageBuffer+31); + fprintf(stdout, _(" HW: %s\n"), MessageBuffer+39); + fprintf(stdout, _(" Firmware: %s\n"), MessageBuffer+44); + + /* These bytes are probably the source of the "Accessory not connected" + messages on the phone when trying to emulate NCDS... I hope.... + UPDATE: of course, now we have the authentication algorithm. */ + fprintf(stdout, _(" Magic bytes: %02x %02x %02x %02x\n"), MessageBuffer[50], MessageBuffer[51], MessageBuffer[52], MessageBuffer[53]); +#endif /* DEBUG */ + + MagicBytes[0]=MessageBuffer[50]; + MagicBytes[1]=MessageBuffer[51]; + MagicBytes[2]=MessageBuffer[52]; + MagicBytes[3]=MessageBuffer[53]; + + CurrentMagicError=GE_NONE; +} + +/* This function provides Nokia authentication protocol. + + This code is written specially for gnokii project by Odinokov Serge. + If you have some special requests for Serge just write him to + apskaita@post.omnitel.net or serge@takas.lt + + Reimplemented in C by Pavel Janík ml. + + Nokia authentication protocol is used in the communication between Nokia + mobile phones (e.g. Nokia 6110) and Nokia Cellular Data Suite software, + commercially sold by Nokia Corp. + + The authentication scheme is based on the token send by the phone to the + software. The software does it's magic (see the function + FB61_GetNokiaAuth()) and returns the result back to the phone. If the + result is correct the phone responds with the message "Accessory + connected!" displayed on the LCD. Otherwise it will display "Accessory not + supported" and some functions will not be available for use. + + The specification of the protocol is not publicly available, no comment. */ +static void N6110_GetNokiaAuth(unsigned char *Imei, unsigned char *MagicBytes, unsigned char *MagicResponse) +{ + + int i, j, CRC=0; + + /* This is our temporary working area. */ + + unsigned char Temp[16]; + + /* Here we put FAC (Final Assembly Code) and serial number into our area. */ + + Temp[0] = Imei[6]; + Temp[1] = Imei[7]; + Temp[2] = Imei[8]; + Temp[3] = Imei[9]; + Temp[4] = Imei[10]; + Temp[5] = Imei[11]; + Temp[6] = Imei[12]; + Temp[7] = Imei[13]; + + /* And now the TAC (Type Approval Code). */ + + Temp[8] = Imei[2]; + Temp[9] = Imei[3]; + Temp[10] = Imei[4]; + Temp[11] = Imei[5]; + + /* And now we pack magic bytes from the phone. */ + + Temp[12] = MagicBytes[0]; + Temp[13] = MagicBytes[1]; + Temp[14] = MagicBytes[2]; + Temp[15] = MagicBytes[3]; + + for (i=0; i<=11; i++) + if (Temp[i + 1]& 1) + Temp[i]<<=1; + + switch (Temp[15] & 0x03) { + + case 1: + case 2: + j = Temp[13] & 0x07; + + for (i=0; i<=3; i++) + Temp[i+j] ^= Temp[i+12]; + + break; + + default: + j = Temp[14] & 0x07; + + for (i=0; i<=3; i++) + Temp[i + j] |= Temp[i + 12]; + } + + for (i=0; i<=15; i++) + CRC ^= Temp[i]; + + for (i=0; i<=15; i++) { + + switch (Temp[15 - i] & 0x06) { + + case 0: + j = Temp[i] | CRC; + break; + + case 2: + case 4: + j = Temp[i] ^ CRC; + break; + + case 6: + j = Temp[i] & CRC; + break; + } + + if (j == CRC) + j = 0x2c; + + if (Temp[i] == 0) + j = 0; + + MagicResponse[i] = j; + + } +} + +static GSM_Error N6110_Authentication() +{ + unsigned char connect1[] = {N6110_FRAME_HEADER, 0x0d, 0x00, 0x00, 0x02}; + unsigned char connect2[] = {N6110_FRAME_HEADER, 0x20, 0x02}; + unsigned char connect3[] = {N6110_FRAME_HEADER, 0x0d, 0x01, 0x00, 0x02}; + unsigned char connect4[] = {N6110_FRAME_HEADER, 0x10}; + + unsigned char magic_connect[] = {N6110_FRAME_HEADER, + 0x12, + + /* The real magic goes here ... These bytes are filled in with the + function N6110_GetNokiaAuth(). */ + + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + + /* NOKIA&GNOKII Accessory */ + + 0x4e, 0x4f, 0x4b, 0x49, 0x41, 0x26, 0x4e, 0x4f, 0x4b, 0x49, 0x41, 0x20, + 0x61, 0x63, 0x63, 0x65, 0x73, 0x73, 0x6f, 0x72, 0x79, + + 0x00, 0x00, 0x00, 0x00}; + +#ifdef DEBUG + fprintf(stdout,_("Making authentication!\n")); +#endif + + usleep(100); Protocol->SendMessage(7, 0x02, connect1); + usleep(100); Protocol->SendMessage(5, 0x02, connect2); + usleep(100); Protocol->SendMessage(7, 0x02, connect3); + + CurrentMagicError = GE_BUSY; + + usleep(100); Protocol->SendMessage(4, 0x64, connect4); + if (NULL_WaitUntil(50,&CurrentMagicError)!=GE_NONE) return GE_TIMEOUT; + + N6110_GetNokiaAuth(Current_IMEI, MagicBytes, magic_connect+4); + + Protocol->SendMessage(45, 0x64, magic_connect); + +#ifdef DEBUG + fprintf(stdout,_("End of authentication!\n")); +#endif + + return GE_NONE; +} + +/* Initialise variables and state machine. */ +GSM_Error N6110_Initialise(char *port_device, char *initlength, + GSM_ConnectionType connection, + void (*rlp_callback)(RLP_F96Frame *frame)) +{ + unsigned char init_char = N6110_SYNC_BYTE; +#ifndef UCLINUX + unsigned char end_init_char = N6110_IR_END_SYNC_BYTE; +#endif /* UCLINUX */ + + int count; + int InitLength; + + if (Protocol->Initialise(port_device,initlength,connection,rlp_callback)!=GE_NONE) + { + return GE_NOTSUPPORTED; + } switch (CurrentConnectionType) { +#ifndef UCLINUX case GCT_Irda: case GCT_MBUS: /* We don't think about authentication in Irda, because AFAIK there are no phones working over sockets and having authentication. In MBUS it doesn't work */ - usleep(100); - - if (N6110_SendIDFrame()!=GE_NONE) return GE_TIMEOUT; - - if (N6110_SendIMEIFrame()!=GE_NONE) return GE_TIMEOUT; - - if (N6110_SendHWFrame()!=GE_NONE) return GE_TIMEOUT; - - CurrentLinkOK = true; + usleep(100); + + if (N6110_SendIDFrame()!=GE_NONE) return GE_TIMEOUT; + + if (N6110_SendIMEIFrame()!=GE_NONE) return GE_TIMEOUT; + + if (N6110_SendHWFrame()!=GE_NONE) return GE_TIMEOUT; + + CurrentLinkOK = true; break; +#endif /* UCLINUX */ case GCT_FBUS: +#ifndef UCLINUX case GCT_Infrared: case GCT_Tekram: - InitLength = atoi(initlength); - - if ((strcmp(initlength, "default") == 0) || (InitLength == 0)) { - InitLength = 250; /* This is the usual value, lower may work. */ - } - +#endif /* UCLINUX */ + InitLength = atoi(initlength); + + if ((strcmp(initlength, "default") == 0) || (InitLength == 0)) { + InitLength = 250; /* This is the usual value, lower may work. */ + } + +#ifndef UCLINUX if (CurrentConnectionType==GCT_Infrared || - CurrentConnectionType==GCT_Tekram) { -#ifdef DEBUG - fprintf(stdout,_("Setting infrared for FBUS communication...\n")); -#endif - device_changespeed(9600); - } - -#ifdef DEBUG - fprintf(stdout,_("Writing init chars....")); -#endif - - /* Initialise link with phone or what have you */ - /* Send init string to phone, this is a bunch of 0x55 characters. Timing is - empirical. */ - for (count = 0; count < InitLength; count ++) { + CurrentConnectionType==GCT_Tekram) { +#ifdef DEBUG + fprintf(stdout,_("Setting infrared for FBUS communication...\n")); +#endif + device_changespeed(9600); + } +#endif /* UCLINUX */ + +#ifdef DEBUG + fprintf(stdout,_("Writing init chars....")); +#endif + + /* Initialise link with phone or what have you */ + /* Send init string to phone, this is a bunch of 0x55 characters. Timing is + empirical. */ + for (count = 0; count < InitLength; count ++) { +#ifndef UCLINUX if (CurrentConnectionType!=GCT_Infrared && - CurrentConnectionType!=GCT_Tekram) usleep(100); - Protocol->WritePhone(1,&init_char); - } - + CurrentConnectionType!=GCT_Tekram) +#endif /* UCLINUX */ + usleep(100); + Protocol->WritePhone(1,&init_char); + } + +#ifndef UCLINUX if (CurrentConnectionType==GCT_Infrared || - CurrentConnectionType==GCT_Tekram) { - Protocol->WritePhone(1,&end_init_char); + CurrentConnectionType==GCT_Tekram) { + Protocol->WritePhone(1,&end_init_char); usleep(200000); } +#endif /* UCLINUX */ -#ifdef DEBUG - fprintf(stdout,_("Done\n")); -#endif +#ifdef DEBUG + fprintf(stdout,_("Done\n")); +#endif +#ifndef UCLINUX if (CurrentConnectionType==GCT_Infrared || - CurrentConnectionType==GCT_Tekram) { - device_changespeed(115200); + CurrentConnectionType==GCT_Tekram) { + device_changespeed(115200); } +#endif /* UCLINUX */ + + N6110_SendStatusRequest(); + + usleep(100); + + if (N6110_SendIDFrame()!=GE_NONE) return GE_TIMEOUT; + + /* N51xx/61xx have something called authentication. + After making it phone display "Accessory connected" + and probably give access to some function (I'm not too sure about it !) + Anyway, I make it now for N51xx/61xx */ + if (GetModelFeature (FN_AUTHENTICATION)!=0) { + if (N6110_Authentication()!=GE_NONE) return GE_TIMEOUT; + } else { /* No authentication */ + if (N6110_SendIMEIFrame()!=GE_NONE) return GE_TIMEOUT; - N6110_SendStatusRequest(); - - usleep(100); - - if (N6110_SendIDFrame()!=GE_NONE) return GE_TIMEOUT; - - /* N51xx/61xx have something called authentication. - After making it phone display "Accessory connected" - and probably give access to some function (I'm not too sure about it !) - Anyway, I make it now for N51xx/61xx */ - if (GetModelFeature (FN_AUTHENTICATION)!=0) { - if (N6110_Authentication()!=GE_NONE) return GE_TIMEOUT; - } else { /* No authentication */ - if (N6110_SendIMEIFrame()!=GE_NONE) return GE_TIMEOUT; - - if (N6110_SendHWFrame()!=GE_NONE) return GE_TIMEOUT; - } + if (N6110_SendHWFrame()!=GE_NONE) return GE_TIMEOUT; + } break; default: -#ifdef DEBUG - fprintf(stdout,_("Unknown connection type in n6110.c!\n")); -#endif +#ifdef DEBUG + fprintf(stdout,_("Unknown connection type in n6110.c!\n")); +#endif break; } - return (GE_NONE); -} - -/* This function translates GMT_MemoryType to N6110_MEMORY_xx */ -int N6110_GetMemoryType(GSM_MemoryType memory_type) -{ - - int result; - - switch (memory_type) { - - case GMT_MT: result = N6110_MEMORY_MT; break; - case GMT_ME: result = N6110_MEMORY_ME; break; - case GMT_SM: result = N6110_MEMORY_SM; break; - case GMT_FD: result = N6110_MEMORY_FD; break; - case GMT_ON: result = N6110_MEMORY_ON; break; - case GMT_EN: result = N6110_MEMORY_EN; break; - case GMT_DC: result = N6110_MEMORY_DC; break; - case GMT_RC: result = N6110_MEMORY_RC; break; - case GMT_MC: result = N6110_MEMORY_MC; break; - default : result = N6110_MEMORY_XX; - - } - - return (result); -} + return (GE_NONE); +} + +/* This function translates GMT_MemoryType to N6110_MEMORY_xx */ +int N6110_GetMemoryType(GSM_MemoryType memory_type) +{ + + int result; + + switch (memory_type) { + + case GMT_MT: result = N6110_MEMORY_MT; break; + case GMT_ME: result = N6110_MEMORY_ME; break; + case GMT_SM: result = N6110_MEMORY_SM; break; + case GMT_FD: result = N6110_MEMORY_FD; break; + case GMT_ON: result = N6110_MEMORY_ON; break; + case GMT_EN: result = N6110_MEMORY_EN; break; + case GMT_DC: result = N6110_MEMORY_DC; break; + case GMT_RC: result = N6110_MEMORY_RC; break; + case GMT_MC: result = N6110_MEMORY_MC; break; + default : result = N6110_MEMORY_XX; + + } + + return (result); +} + +#ifndef UCLINUX void N6110_ReplyCallDivert(u16 MessageLength, u8 *MessageBuffer, u8 MessageType) { @@ -743,14 +841,14 @@ void N6110_ReplyCallDivert(u16 MessageLength, u8 *MessageBuffer, u8 MessageType) CurrentCallDivert->Enabled=false; } - CurrentCallDivertError=GE_NONE; + CurrentCallDivertError=GE_NONE; break; - case 0x03: + case 0x03: #ifdef DEBUG fprintf(stdout, _("Message: Call divert status receiving error ?\n")); -#endif - CurrentCallDivertError=GE_UNKNOWN; +#endif + CurrentCallDivertError=GE_UNKNOWN; break; } } @@ -768,8 +866,8 @@ GSM_Error N6110_CallDivert(GSM_CallDivert *cd) int length = 0x09; switch (cd->Operation) { - case GSM_CDV_Register: - case GSM_CDV_Enable: + case GSM_CDV_Register: + case GSM_CDV_Enable: req[4] = 0x03; req[8] = 0x01; req[29]= GSM_PackSemiOctetNumber(cd->Number, req + 9, false); @@ -816,96 +914,96 @@ GSM_Error N6110_CallDivert(GSM_CallDivert *cd) return error; } - -GSM_Error N6110_Tests() -{ - unsigned char buffer[3]={0x00,0x01,0xcf}; - unsigned char buffer3[8]={0x00,0x01,0xce,0x1d,0xfe,0x23,0x00,0x00}; + +GSM_Error N6110_Tests() +{ + unsigned char buffer[3]={0x00,0x01,0xcf}; + unsigned char buffer3[8]={0x00,0x01,0xce,0x1d,0xfe,0x23,0x00,0x00}; GSM_Error error; - - error=N6110_EnableExtendedCommands(0x01); + + error=N6110_EnableExtendedCommands(0x01); if (error!=GE_NONE) return error; - - //make almost all tests - Protocol->SendMessage(8, 0x40, buffer3); - - while (GSM->Initialise(PortDevice, "50", CurrentConnectionType, CurrentRLP_RXCallback)!=GE_NONE) {}; - - sleep(2); - - return NULL_SendMessageSequence - (200, &CurrentNetworkInfoError, 3, 0x40, buffer); -} - -void N6110_DisplayTestsInfo(u8 *MessageBuffer) { - - int i; - - CurrentNetworkInfoError=GE_NONE; - - for (i=0;iSendMessage(8, 0x40, buffer3); - int i, j; - - char uni[100]; - -#ifdef DEBUG - fprintf(stdout, _("Message: Simlock info received\n")); - - j=0; - for (i=0; i < 12; i++) - { - if (j<24) { - fprintf(stdout,_("%c"), ('0' + (MessageBuffer[9+i] >> 4))); - j++; - } - if (j==5 || j==15) fprintf(stdout, _("\n")); - if (j!=15) { - if (j<24) { - fprintf(stdout,_("%c"), ('0' + (MessageBuffer[9+i] & 0x0f))); - j++; - } - } else j++; - if (j==20 || j==24) fprintf(stdout, _("\n")); - } + while (GSM->Initialise(PortDevice, "50", CurrentConnectionType, CurrentRLP_RXCallback)!=GE_NONE) {}; + + sleep(2); + + return NULL_SendMessageSequence + (200, &CurrentNetworkInfoError, 3, 0x40, buffer); +} + +void N6110_DisplayTestsInfo(u8 *MessageBuffer) { + + int i; + + CurrentNetworkInfoError=GE_NONE; + + for (i=0;i> 4))); + j++; + } + if (j==5 || j==15) fprintf(stdout, _("\n")); + if (j!=15) { + if (j<24) { + fprintf(stdout,_("%c"), ('0' + (MessageBuffer[9+i] & 0x0f))); + j++; + } + } else j++; + if (j==20 || j==24) fprintf(stdout, _("\n")); + } if ((MessageBuffer[6] & 1) == 1) fprintf(stdout,_("lock 1 closed\n")); if ((MessageBuffer[6] & 2) == 2) fprintf(stdout,_("lock 2 closed\n")); @@ -967,17 +1065,17 @@ void N6110_ReplySimlockInfo(u16 MessageLength, u8 *MessageBuffer, u8 MessageType CurrentSimlockInfoError=GE_NONE; } -GSM_Error N6110_SimlockInfo(GSM_AllSimlocks *siml) -{ - GSM_Error error; - unsigned char req[] = {0x00,0x01,0x8a,0x00}; - error=N6110_EnableExtendedCommands(0x01); +GSM_Error N6110_SimlockInfo(GSM_AllSimlocks *siml) +{ + GSM_Error error; + unsigned char req[] = {0x00,0x01,0x8a,0x00}; + error=N6110_EnableExtendedCommands(0x01); if (error!=GE_NONE) return error; CurrentSimLock=siml; - return NULL_SendMessageSequence (50, &CurrentSimlockInfoError, 4, 0x40, req); -} + return NULL_SendMessageSequence (50, &CurrentSimlockInfoError, 4, 0x40, req); +} void N6110_ReplyResetPhoneSettings(u16 MessageLength, u8 *MessageBuffer, u8 MessageType) { @@ -988,4646 +1086,4728 @@ void N6110_ReplyResetPhoneSettings(u16 MessageLength, u8 *MessageBuffer, u8 Mess CurrentResetPhoneSettingsError=GE_NONE; } -GSM_Error N6110_ResetPhoneSettings() -{ - GSM_Error error; - unsigned char req[] = {0x00,0x01,0x65,0x08,0x00}; - error=N6110_EnableExtendedCommands(0x01); +GSM_Error N6110_ResetPhoneSettings() +{ + GSM_Error error; + unsigned char req[] = {0x00,0x01,0x65,0x08,0x00}; + error=N6110_EnableExtendedCommands(0x01); if (error!=GE_NONE) return error; - return NULL_SendMessageSequence - (50, &CurrentResetPhoneSettingsError, 5, 0x40, req); -} + return NULL_SendMessageSequence + (50, &CurrentResetPhoneSettingsError, 5, 0x40, req); +} + +#endif /* UCLINUX */ + GSM_Error N6110_GetManufacturer(char *manufacturer) { strcpy (manufacturer, "Nokia"); return (GE_NONE); } -GSM_Error N6110_GetVoiceMailbox ( GSM_PhonebookEntry *entry) -{ - unsigned char req[] = {N6110_FRAME_HEADER, 0x01, 0x00, 0x00, 0x00}; - - GSM_Error error; - - CurrentPhonebookEntry = entry; - - req[4] = N6110_MEMORY_VOICE; - req[5] = 0x00; /* Location - isn't important, but... */ - - error=NULL_SendMessageSequence - (20, &CurrentPhonebookError, 7, 0x03, req); - - CurrentPhonebookEntry = NULL; - - return error; -} - -void N6110_ReplyGetOperatorName(u16 MessageLength, u8 *MessageBuffer, u8 MessageType) { - - int i, count; - - GSM_Bitmap NullBitmap; - - DecodeNetworkCode(MessageBuffer+5, NullBitmap.netcode); - - count=8; - -#ifdef DEBUG - fprintf(stdout, _("Message: Info about downloaded operator name received: %s network (for gnokii \"%s\", for phone \""), - NullBitmap.netcode, - GSM_GetNetworkName(NullBitmap.netcode)); -#endif - - i=count; - while (MessageBuffer[count]!=0) { -#ifdef DEBUG - fprintf(stdout,_("%c"),MessageBuffer[count]); -#endif - count++; - } - - strcpy(CurrentGetOperatorNameNetwork->Code, NullBitmap.netcode); - strncpy(CurrentGetOperatorNameNetwork->Name, MessageBuffer+i,count-i+1); - -#ifdef DEBUG - fprintf(stdout,_("\")\n")); -#endif - - CurrentGetOperatorNameError=GE_NONE; -} - -GSM_Error N6110_GetOperatorName (GSM_Network *operator) -{ - unsigned char req[] = { 0x00,0x01,0x8c,0x00}; - - GSM_Error error; - - error=N6110_EnableExtendedCommands(0x01); - if (error!=GE_NONE) return error; - - CurrentGetOperatorNameNetwork = operator; - - error=NULL_SendMessageSequence - (20, &CurrentGetOperatorNameError, 4, 0x40, req); - - CurrentGetOperatorNameNetwork = NULL; - - return error; -} - -void N6110_ReplySetOperatorName(u16 MessageLength, u8 *MessageBuffer, u8 MessageType) { - -#ifdef DEBUG - fprintf(stdout, _("Message: Downloaded operator name changed\n")); -#endif - - CurrentSetOperatorNameError=GE_NONE; -} - -GSM_Error N6110_SetOperatorName (GSM_Network *operator) -{ - unsigned char req[256] = { 0x00,0x01,0x8b,0x00, - 0x00,0x00, /* MCC */ - 0x00}; /* MNC */ - - GSM_Error error; - - error=N6110_EnableExtendedCommands(0x01); - if (error!=GE_NONE) return error; - - EncodeNetworkCode(req+4,operator->Code); - - strncpy(req+7,operator->Name,200); - - return NULL_SendMessageSequence - (20, &CurrentSetOperatorNameError, 8+strlen(operator->Name), 0x40, req); -} - -void N6110_ReplyGetMemoryStatus(u16 MessageLength, u8 *MessageBuffer, u8 MessageType) { - - switch (MessageBuffer[3]) { - - case 0x08: - -#ifdef DEBUG - fprintf(stdout, _("Message: Memory status received:\n")); - - fprintf(stdout, _(" Memory Type: %s\n"), N6110_MemoryType_String[MessageBuffer[4]]); - fprintf(stdout, _(" Used: %d\n"), MessageBuffer[6]); - fprintf(stdout, _(" Free: %d\n"), MessageBuffer[5]); -#endif /* DEBUG */ - - CurrentMemoryStatus->Used = MessageBuffer[6]; - CurrentMemoryStatus->Free = MessageBuffer[5]; - CurrentMemoryStatusError = GE_NONE; - - break; - - case 0x09: - -#ifdef DEBUG - switch (MessageBuffer[4]) { - case 0x6f: - fprintf(stdout, _("Message: Memory status error, phone is probably powered off.\n"));break; - case 0x7d: - fprintf(stdout, _("Message: Memory status error, memory type not supported by phone model.\n"));break; - case 0x8d: - fprintf(stdout, _("Message: Memory status error, waiting for security code.\n"));break; - default: - fprintf(stdout, _("Message: Unknown Memory status error, subtype (MessageBuffer[4]) = %02x\n"),MessageBuffer[4]);break; - } -#endif - - switch (MessageBuffer[4]) { - case 0x6f:CurrentMemoryStatusError = GE_TIMEOUT;break; - case 0x7d:CurrentMemoryStatusError = GE_INTERNALERROR;break; - case 0x8d:CurrentMemoryStatusError = GE_INVALIDSECURITYCODE;break; - default:break; - } - - break; - - } -} - -/* This function is used to get storage status from the phone. It currently - supports two different memory areas - internal and SIM. */ -GSM_Error N6110_GetMemoryStatus(GSM_MemoryStatus *Status) -{ - unsigned char req[] = { N6110_FRAME_HEADER, - 0x07, /* MemoryStatus request */ - 0x00 /* MemoryType */ - }; - - GSM_Error error; - - CurrentMemoryStatus = Status; - - req[4] = N6110_GetMemoryType(Status->MemoryType); - - error=NULL_SendMessageSequence - (20, &CurrentMemoryStatusError, 5, 0x03, req); - - CurrentMemoryStatus = NULL; - - return error; -} - -void N6110_ReplyGetNetworkInfo(u16 MessageLength, u8 *MessageBuffer, u8 MessageType) { - - GSM_NetworkInfo NullNetworkInfo; - - /* Make sure we are expecting NetworkInfo frame */ - if (CurrentNetworkInfo && CurrentNetworkInfoError == GE_BUSY) { -#ifdef DEBUG - fprintf(stdout, _("Message: Network informations:\n")); -#endif - } else { -#ifdef DEBUG - fprintf(stdout, _("Message: Network informations not requested, but received:\n")); -#endif - } - - sprintf(NullNetworkInfo.NetworkCode, "%x%x%x %x%x", MessageBuffer[14] & 0x0f, MessageBuffer[14] >>4, MessageBuffer[15] & 0x0f, MessageBuffer[16] & 0x0f, MessageBuffer[16] >>4); - - sprintf(NullNetworkInfo.CellID, "%02x%02x", MessageBuffer[10], MessageBuffer[11]); - - sprintf(NullNetworkInfo.LAC, "%02x%02x", MessageBuffer[12], MessageBuffer[13]); - -#ifdef DEBUG - fprintf(stdout, _(" CellID: %s\n"), NullNetworkInfo.CellID); - fprintf(stdout, _(" LAC: %s\n"), NullNetworkInfo.LAC); - fprintf(stdout, _(" Network code: %s\n"), NullNetworkInfo.NetworkCode); - fprintf(stdout, _(" Network name: %s (%s)\n"), - GSM_GetNetworkName(NullNetworkInfo.NetworkCode), - GSM_GetCountryName(NullNetworkInfo.NetworkCode)); - fprintf(stdout, _(" Status: ")); - - switch (MessageBuffer[8]) { - case 0x01: fprintf(stdout, _("home network selected")); break; - case 0x02: fprintf(stdout, _("roaming network")); break; - case 0x03: fprintf(stdout, _("requesting network")); break; - case 0x04: fprintf(stdout, _("not registered in the network")); break; - default: fprintf(stdout, _("unknown")); - } - - fprintf(stdout, "\n"); - - fprintf(stdout, _(" Network selection: %s\n"), MessageBuffer[9]==1?_("manual"):_("automatic")); -#endif /* DEBUG */ - - /* Make sure we are expecting NetworkInfo frame */ - if (CurrentNetworkInfo && CurrentNetworkInfoError == GE_BUSY) - *CurrentNetworkInfo=NullNetworkInfo; - - CurrentNetworkInfoError = GE_NONE; -} - -GSM_Error N6110_GetNetworkInfo(GSM_NetworkInfo *NetworkInfo) -{ - unsigned char req[] = { N6110_FRAME_HEADER, - 0x70 - }; - - GSM_Error error; - - CurrentNetworkInfo = NetworkInfo; - - error=NULL_SendMessageSequence - (20, &CurrentNetworkInfoError, 4, 0x0a, req); - - CurrentNetworkInfo = NULL; - - return error; -} - -void N6110_ReplyGetProductProfileSetting(u16 MessageLength, u8 *MessageBuffer, u8 MessageType) { - - int i; - -#ifdef DEBUG - fprintf(stdout, _("Message: Product Profile Settings received -")); - for (i=0;i<4;i++) fprintf(stdout, _(" %02x"),MessageBuffer[3+i]); - fprintf(stdout, _("\n")); -#endif - - for (i=0;i<4;i++) CurrentPPS[i]=MessageBuffer[3+i]; - - CurrentProductProfileSettingsError=GE_NONE; -} - -GSM_Error N6110_GetProductProfileSetting (GSM_PPS *PPS) -{ - unsigned char req[] = { 0x00, 0x01,0x6a }; - - int i,j; - - GSM_Error error; - - error=N6110_EnableExtendedCommands(0x01); - if (error!=GE_NONE) return error; - - error=NULL_SendMessageSequence - (20, &CurrentProductProfileSettingsError, 3, 0x40, req); - if (error!=GE_NONE) return error; - - switch (PPS->Name) { - case PPS_ALS : PPS->bool_value=(CurrentPPS[1]&32); break; - case PPS_GamesMenu: PPS->bool_value=(CurrentPPS[3]&64); break; - case PPS_HRData : PPS->bool_value=(CurrentPPS[0]&64); break; - case PPS_14400Data: PPS->bool_value=(CurrentPPS[0]&128);break; - case PPS_EFR : PPS->int_value =(CurrentPPS[0]&1) +(CurrentPPS[0]&2); break; - case PPS_FR : PPS->int_value =(CurrentPPS[0]&16)/16+(CurrentPPS[0]&32)/16;break; - case PPS_HR : PPS->int_value =(CurrentPPS[0]&4)/4 +(CurrentPPS[0]&8)/4; break; - case PPS_VibraMenu: PPS->bool_value=(CurrentPPS[4]&64); break; - case PPS_LCDContrast: - PPS->int_value=0; - j=1; - for (i=0;i<5;i++) { - if (CurrentPPS[3]&j) PPS->int_value=PPS->int_value+j; - j=j*2; - } - PPS->int_value=PPS->int_value*100/32; - break; - - } - - return (GE_NONE); -} - -void N6110_ReplySetProductProfileSetting(u16 MessageLength, u8 *MessageBuffer, u8 MessageType) { - -#ifdef DEBUG - int i; - - fprintf(stdout, _("Message: Product Profile Settings set to")); - for (i=0;i<4;i++) fprintf(stdout, _(" %02x"),CurrentPPS[i]); - fprintf(stdout, _("\n")); -#endif - - CurrentProductProfileSettingsError=GE_NONE; -} - -GSM_Error N6110_SetProductProfileSetting (GSM_PPS *PPS) -{ - unsigned char req[] = { 0x00, 0x01,0x6b, - 0x00, 0x00, 0x00, 0x00 }; /* bytes with Product Profile Setings */ - unsigned char settings[32]; - - GSM_PPS OldPPS; - - int i,j,z; - - GSM_Error error; - - error=N6110_EnableExtendedCommands(0x01); - if (error!=GE_NONE) return error; - - OldPPS.Name=PPS_ALS; - error=N6110_GetProductProfileSetting(&OldPPS); - if (error!=GE_NONE) return error; - - j=128;z=0; - for (i=0;i<32;i++) { - if (CurrentPPS[z]&j) - settings[i]='1'; - else - settings[i]='0'; - if (j==1) { - j=128; - z++; - } else j=j/2; - } - -#ifdef DEBUG - fprintf(stdout,_("Current settings: ")); - for (i=0;i<32;i++) { - fprintf(stdout,_("%c"),settings[i]); - } - fprintf(stdout,_("\n")); -#endif - - switch (PPS->Name) { - case PPS_ALS :settings[10]=PPS->bool_value?'1':'0';break; - case PPS_HRData :settings[ 5]=PPS->bool_value?'1':'0';break; - case PPS_14400Data:settings[ 6]=PPS->bool_value?'1':'0';break; - default :break; - } - - j=128;z=0; - for (i=0;i<32;i++) { - if (settings[i]=='1') req[z+3]=req[z+3]+j; - if (j==1) { - j=128; - z++; - } else j=j/2; - } - -#ifdef DEBUG - fprintf(stdout,_("Current settings: ")); - for (i=0;i<4;i++) { - fprintf(stdout,_("%i "),req[i+3]); - } - fprintf(stdout,_("\n")); -#endif - - for (i=0;i<4;i++) { - CurrentPPS[i]=req[i+3]; - } - - return NULL_SendMessageSequence - (20, &CurrentProductProfileSettingsError, 7, 0x40, req); -} - -void N6110_ReplyPressKey(u16 MessageLength, u8 *MessageBuffer, u8 MessageType) { - - if (MessageBuffer[4]==CurrentPressKeyEvent) CurrentPressKeyError=GE_NONE; - else CurrentPressKeyError=GE_UNKNOWN; /* MessageBuffer[4] = 0x05 */ -#ifdef DEBUG - fprintf(stdout, _("Message: Result of key ")); - switch (MessageBuffer[4]) - { - case PRESSPHONEKEY: fprintf(stdout, _("press OK\n"));break; - case RELEASEPHONEKEY: fprintf(stdout, _("release OK\n"));break; - default: fprintf(stdout, _("press or release - error\n"));break; - } -#endif /* DEBUG */ -} - -GSM_Error N6110_PressKey(int key, int event) -{ - unsigned char req[] = {N6110_FRAME_HEADER, 0x42, 0x01, 0x00, 0x01}; - - req[4]=event; /* if we press or release key */ - req[5]=key; - - CurrentPressKeyEvent=event; - - return NULL_SendMessageSequence - (10, &CurrentPressKeyError, 7, 0x0c, req); -} - -void N6110_ReplyDisplayOutput(u16 MessageLength, u8 *MessageBuffer, u8 MessageType) { - - /* Hopefully is 64 larger as FB38_MAX* / N6110_MAX* */ - char model[64]; - - int i, j; - - char uni[100]; - - switch(MessageBuffer[3]) { - - /* Phone sends displayed texts */ - case 0x50: - NewX=MessageBuffer[6]; - NewY=MessageBuffer[5]; - - DecodeUnicode (uni, MessageBuffer+8, MessageBuffer[7]); - -#ifdef DEBUG - fprintf(stdout, _("New displayed text (%i %i): \"%s\"\n"),NewX,NewY,uni); -#endif /* DEBUG */ - - while (N6110_GetModel(model) != GE_NONE) - sleep(1); - - /* With these rules it works almost excellent with my N5110 */ - /* I don't have general rule :-(, that's why you must experiment */ - /* with your phone. Nokia could make it better. MW */ - /* It's almost OK for N5110*/ - /* FIX ME: it will be the same for N5130 and 3210 too*/ - if (!strcmp(model,"NSE-1")) - { - /* OldX==1000 means - it's first time */ - if (OldX==1000) { - - /* Clean table */ - for (i=0;i<5+1;i++) { - for (j=0;j<27+1;j++) {PhoneScreen[i][j]=' ';} - } - OldX=0; - } - - if ((OldX==0 && OldY==31 && NewX==29 && NewY==46) || - (OldX==0 && OldY==13 && NewX==23 && NewY==46)) { - /* Clean the line with current text */ - for (j=0;j<27+1;j++) {PhoneScreen[NewY/(47/5)][j]=' ';} - - /* Inserts text into table */ - for (i=0; iSendMessage(sizeof(req0), 0x01, req0); - sleep(1); - - return NULL_SendMessageSequence - (20, &CurrentMagicError, sizeof(req) , 0x01, req); -} - -void N6110_ReplyGetProfile(u16 MessageLength, u8 *MessageBuffer, u8 MessageType) { - - switch (MessageBuffer[3]) { - - /* Profile feature */ - case 0x14: - - switch(GetModelFeature (FN_PROFILES)) { - case F_PROF33: - switch (MessageBuffer[6]) { - case 0x00: CurrentProfile->KeypadTone = MessageBuffer[8]; break; - case 0x01: CurrentProfile->CallAlert = MessageBuffer[8]; break; - case 0x02: CurrentProfile->Ringtone = MessageBuffer[8]; break; - case 0x03: CurrentProfile->Volume = MessageBuffer[8]; break; - case 0x04: CurrentProfile->MessageTone = MessageBuffer[8]; break; - case 0x05: CurrentProfile->Vibration = MessageBuffer[8]; break; - case 0x06: CurrentProfile->WarningTone = MessageBuffer[8]; break; - case 0x07: CurrentProfile->ScreenSaver = MessageBuffer[8]; break; - default: -#ifdef DEBUG - fprintf(stdout,_("feature %i = value %i\n\n"),MessageBuffer[6],MessageBuffer[8]); -#endif - break; - } - break; - default: - switch (MessageBuffer[6]) { - case 0x00: CurrentProfile->KeypadTone = MessageBuffer[8];break; - case 0x01: CurrentProfile->Lights = MessageBuffer[8];break; - case 0x02: CurrentProfile->CallAlert = MessageBuffer[8];break; - case 0x03: CurrentProfile->Ringtone = MessageBuffer[8];break; - case 0x04: CurrentProfile->Volume = MessageBuffer[8];break; - case 0x05: CurrentProfile->MessageTone = MessageBuffer[8];break; - case 0x06: CurrentProfile->Vibration = MessageBuffer[8];break; - case 0x07: CurrentProfile->WarningTone = MessageBuffer[8];break; - case 0x08: CurrentProfile->CallerGroups = MessageBuffer[8];break; - case 0x09: CurrentProfile->AutomaticAnswer = MessageBuffer[8];break; - default: -#ifdef DEBUG - fprintf(stdout,_("feature %i = value %i\n\n"),MessageBuffer[6],MessageBuffer[8]); -#endif - break; - } - break; - } - - CurrentProfileError = GE_NONE; - break; - - /* Incoming profile name */ - case 0x1b: - - if (MessageBuffer[9] == 0x00) { - CurrentProfile->DefaultName=MessageBuffer[8]; - } else { - CurrentProfile->DefaultName=-1; - - /* Here name is in Unicode */ - if (GetModelFeature (FN_PROFILES)==F_PROF33) { - DecodeUnicode (CurrentProfile->Name, MessageBuffer+10, MessageBuffer[9]/2); - } else { - /* ...here not */ - sprintf(CurrentProfile->Name, MessageBuffer + 10, MessageBuffer[9]); - CurrentProfile->Name[MessageBuffer[9]] = '\0'; - } - } - - CurrentProfileError = GE_NONE; - break; - - } -} - -/* Needs SIM card with PIN in phone */ -GSM_Error N6110_GetProfile(GSM_Profile *Profile) -{ - int i; - - unsigned char name_req[] = { N6110_FRAME_HEADER, 0x1a, 0x00}; - unsigned char feat_req[] = { N6110_FRAME_HEADER, 0x13, 0x01, 0x00, 0x00}; - - GSM_Error error; - - CurrentProfile = Profile; - - /* When after sending all frames feature==253, it means, that it is not - supported */ - CurrentProfile->KeypadTone=253; - CurrentProfile->Lights=253; - CurrentProfile->CallAlert=253; - CurrentProfile->Ringtone=253; - CurrentProfile->Volume=253; - CurrentProfile->MessageTone=253; - CurrentProfile->WarningTone=253; - CurrentProfile->Vibration=253; - CurrentProfile->CallerGroups=253; - CurrentProfile->ScreenSaver=253; - CurrentProfile->AutomaticAnswer=253; - - name_req[4] = Profile->Number; - - error=NULL_SendMessageSequence - (20, &CurrentProfileError, 5, 0x05, name_req); - if (error!=GE_NONE) return error; - - for (i = 0x00; i <= 0x09; i++) { - - feat_req[5] = Profile->Number; - - feat_req[6] = i; - - error=NULL_SendMessageSequence - (20, &CurrentProfileError, 7, 0x05, feat_req); - if (error!=GE_NONE) return error; - } - - if (Profile->DefaultName > -1) - { - switch(GetModelFeature (FN_PROFILES)) { - case F_PROF33: - switch (Profile->DefaultName) { - case 0x00: sprintf(Profile->Name, "General");break; - case 0x01: sprintf(Profile->Name, "Silent");break; - case 0x02: sprintf(Profile->Name, "Descreet");break; - case 0x03: sprintf(Profile->Name, "Loud");break; - case 0x04: sprintf(Profile->Name, "My style");break; - case 0x05: Profile->Name[0]=0;break; - default : sprintf(Profile->Name, "Unknown (%i)", Profile->DefaultName);break; - } - break; - case F_PROF51: - switch (Profile->DefaultName) { - case 0x00: sprintf(Profile->Name, "Personal");break; - case 0x01: sprintf(Profile->Name, "Car");break; - case 0x02: sprintf(Profile->Name, "Headset");break; - default : sprintf(Profile->Name, "Unknown (%i)", Profile->DefaultName);break; - } - break; - case F_PROF61: - switch (Profile->DefaultName) { - case 0x00: sprintf(Profile->Name, "General");break; - case 0x01: sprintf(Profile->Name, "Silent");break; - case 0x02: sprintf(Profile->Name, "Meeting");break; - case 0x03: sprintf(Profile->Name, "Outdoor");break; - case 0x04: sprintf(Profile->Name, "Pager");break; - case 0x05: sprintf(Profile->Name, "Car");break; - case 0x06: sprintf(Profile->Name, "Headset");break; - default : sprintf(Profile->Name, "Unknown (%i)", Profile->DefaultName);break; - } - break; - } - } - - return (GE_NONE); - -} - -void N6110_ReplySetProfile(u16 MessageLength, u8 *MessageBuffer, u8 MessageType) { - - switch (MessageBuffer[3]) { - - /* Profile feature change result */ - case 0x11: -#ifdef DEBUG - fprintf(stdout, _("Message: Profile feature change result.\n")); -#endif /* DEBUG */ - CurrentProfileError = GE_NONE; - break; - - /* Profile name set result */ - case 0x1d: -#ifdef DEBUG - fprintf(stdout, _("Message: Profile name change result.\n")); -#endif /* DEBUG */ - CurrentProfileError = GE_NONE; - break; - - } -} - -GSM_Error N6110_SetProfileFeature(u8 profile, u8 feature, u8 value) -{ - unsigned char feat_req[] = { N6110_FRAME_HEADER, 0x10, 0x01, - 0x00, 0x00, 0x00}; - - feat_req[5]=profile; - feat_req[6]=feature; - feat_req[7]=value; - - return NULL_SendMessageSequence - (20, &CurrentProfileError, 8, 0x05, feat_req); -} - -GSM_Error N6110_SetProfile(GSM_Profile *Profile) -{ - int i,value; - - unsigned char name_req[40] = { N6110_FRAME_HEADER, 0x1c, 0x01, 0x03, - 0x00, 0x00, 0x00}; - - GSM_Error error; - - name_req[7] = Profile->Number; - name_req[8] = strlen(Profile->Name); - name_req[6] = name_req[8] + 2; - - for (i = 0; i < name_req[8]; i++) - name_req[9 + i] = Profile->Name[i]; - - error=NULL_SendMessageSequence - (20, &CurrentProfileError, name_req[8] + 9, 0x05, name_req); - if (error!=GE_NONE) return error; - - for (i = 0x00; i <= 0x09; i++) { - - switch (i) { - case 0x00: value = Profile->KeypadTone; break; - case 0x01: value = Profile->Lights; break; - case 0x02: value = Profile->CallAlert; break; - case 0x03: value = Profile->Ringtone; break; - case 0x04: value = Profile->Volume; break; - case 0x05: value = Profile->MessageTone; break; - case 0x06: value = Profile->Vibration; break; - case 0x07: value = Profile->WarningTone; break; - case 0x08: value = Profile->CallerGroups; break; - case 0x09: value = Profile->AutomaticAnswer; break; - default : value = 0; break; - } - - error=N6110_SetProfileFeature(Profile->Number,i,value); - if (error!=GE_NONE) return error; - } - - return (GE_NONE); -} - -bool N6110_SendRLPFrame(RLP_F96Frame *frame, bool out_dtx) -{ - u8 req[60] = { 0x00, 0xd9 }; - - /* Discontinuos transmission (DTX). See section 5.6 of GSM 04.22 version - 7.0.1. */ - - if (out_dtx) - req[1]=0x01; - - memcpy(req+2, (u8 *) frame, 32); - - return (Protocol->SendFrame(32, 0xf0, req)); -} - -void N6110_ReplyGetCalendarNote(u16 MessageLength, u8 *MessageBuffer, u8 MessageType) { - - int i, j; - - u8 mychar1; - - wchar_t wc; - - switch (MessageBuffer[4]) { - - case 0x01: - - CurrentCalendarNote->Type=MessageBuffer[8]; - - DecodeDateTime(MessageBuffer+9, &CurrentCalendarNote->Time); - - DecodeDateTime(MessageBuffer+16, &CurrentCalendarNote->Alarm); - - CurrentCalendarNote->Text[0]=0; - - if (GetModelFeature (FN_CALENDAR)==F_CAL33) { - i=0; - if (CurrentCalendarNote->Type == GCN_REMINDER) i=1; //first char is subset - switch (MessageBuffer[24]) { - case 3: -#ifdef DEBUG - fprintf(stdout,_("Subset 3 in reminder note !\n")); -#endif - while (i!=MessageBuffer[23]) { - j=0; - if (i!=MessageBuffer[23]-1) { - if (MessageBuffer[24+i]>=0xc2) { - DecodeWithUTF8Alphabet(MessageBuffer[24+i], MessageBuffer[24+i+1], &mychar1); - CurrentCalendarNote->Text[strlen(CurrentCalendarNote->Text)+1]=0; - CurrentCalendarNote->Text[strlen(CurrentCalendarNote->Text)]=mychar1; - j=-1; - i++; - } - } - if (j!=-1) { - CurrentCalendarNote->Text[strlen(CurrentCalendarNote->Text)+1]=0; - CurrentCalendarNote->Text[strlen(CurrentCalendarNote->Text)]=MessageBuffer[24+i]; - } - i++; - } - break; - case 2: -#ifdef DEBUG - fprintf(stdout,_("Subset 2 in reminder note !\n")); -#endif - while (i!=MessageBuffer[23]) { - wc = MessageBuffer[24+i] | (0x00 << 8); - CurrentCalendarNote->Text[strlen(CurrentCalendarNote->Text)+1]=0; - CurrentCalendarNote->Text[strlen(CurrentCalendarNote->Text)]= - DecodeWithUnicodeAlphabet(wc); - i++; - } - break; - case 1: -#ifdef DEBUG - fprintf(stdout,_("Subset 1 in reminder note !\n")); -#endif - memcpy(CurrentCalendarNote->Text,MessageBuffer+24+i,MessageBuffer[23]-i); - CurrentCalendarNote->Text[MessageBuffer[23]-i]=0; - break; - default: -#ifdef DEBUG - fprintf(stdout,_("Unknown subset in reminder note !\n")); -#endif - memcpy(CurrentCalendarNote->Text,MessageBuffer+24+i,MessageBuffer[23]-i); - CurrentCalendarNote->Text[MessageBuffer[23]-i]=0; - break; - } - } else { - memcpy(CurrentCalendarNote->Text,MessageBuffer+24,MessageBuffer[23]); - CurrentCalendarNote->Text[MessageBuffer[23]]=0; - } - - if (CurrentCalendarNote->Type == GCN_CALL) { - memcpy(CurrentCalendarNote->Phone,MessageBuffer+24+MessageBuffer[23]+1,MessageBuffer[24+MessageBuffer[23]]); - CurrentCalendarNote->Phone[MessageBuffer[24+MessageBuffer[23]]]=0; - } - - CurrentCalendarNote->Recurrance=0; - - CurrentCalendarNote->AlarmType=0; - -#ifdef DEBUG - fprintf(stdout, _("Message: Calendar note received.\n")); - - fprintf(stdout, _(" Date: %d-%02d-%02d\n"), CurrentCalendarNote->Time.Year, - CurrentCalendarNote->Time.Month, - CurrentCalendarNote->Time.Day); - - fprintf(stdout, _(" Time: %02d:%02d:%02d\n"), CurrentCalendarNote->Time.Hour, - CurrentCalendarNote->Time.Minute, - CurrentCalendarNote->Time.Second); - - /* Some messages do not have alarm set up */ - if (CurrentCalendarNote->Alarm.Year != 0) { - fprintf(stdout, _(" Alarm date: %d-%02d-%02d\n"), CurrentCalendarNote->Alarm.Year, - CurrentCalendarNote->Alarm.Month, - CurrentCalendarNote->Alarm.Day); - - fprintf(stdout, _(" Alarm time: %02d:%02d:%02d\n"), CurrentCalendarNote->Alarm.Hour, - CurrentCalendarNote->Alarm.Minute, - CurrentCalendarNote->Alarm.Second); - } - - fprintf(stdout, _(" Type: %d\n"), CurrentCalendarNote->Type); - fprintf(stdout, _(" Text: %s\n"), CurrentCalendarNote->Text); - - if (CurrentCalendarNote->Type == GCN_CALL) - fprintf(stdout, _(" Phone: %s\n"), CurrentCalendarNote->Phone); -#endif /* DEBUG */ - - CurrentCalendarNoteError=GE_NONE; - break; - - case 0x93: - -#ifdef DEBUG - fprintf(stdout, _("Message: Calendar note not available\n")); -#endif /* DEBUG */ - - CurrentCalendarNoteError=GE_INVALIDCALNOTELOCATION; - break; - - default: - -#ifdef DEBUG - fprintf(stdout, _("Message: Calendar note error\n")); -#endif /* DEBUG */ - - CurrentCalendarNoteError=GE_INTERNALERROR; - break; - - } -} - -GSM_Error N6110_GetCalendarNote(GSM_CalendarNote *CalendarNote) -{ - - unsigned char req[] = { N6110_FRAME_HEADER, - 0x66, 0x00 - }; - GSM_Error error; - - req[4]=CalendarNote->Location; - - CurrentCalendarNote = CalendarNote; - - error=NULL_SendMessageSequence - (20, &CurrentCalendarNoteError, 5, 0x13, req); - - CurrentCalendarNote = NULL; - - return error; -} - -void N6110_ReplyWriteCalendarNote(u16 MessageLength, u8 *MessageBuffer, u8 MessageType) { - -#ifdef DEBUG - switch(MessageBuffer[4]) { - /* This message is also sent when the user enters the new entry on keypad */ - case 0x01: - fprintf(stdout, _("Message: Calendar note write succesfull!\n"));break; - case 0x73: - fprintf(stdout, _("Message: Calendar note write failed!\n"));break; - case 0x7d: - fprintf(stdout, _("Message: Calendar note write failed!\n"));break; - default: - fprintf(stdout, _("Unknown message of type 0x13 and subtype 0x65\n"));break; - } -#endif - - switch(MessageBuffer[4]) { - case 0x01: CurrentCalendarNoteError=GE_NONE; break; - case 0x73: CurrentCalendarNoteError=GE_INTERNALERROR; break; - case 0x7d: CurrentCalendarNoteError=GE_INTERNALERROR; break; - default : AppendLogText("Unknown msg\n",false); break; - } -} - -GSM_Error N6110_WriteCalendarNote(GSM_CalendarNote *CalendarNote) -{ - - unsigned char req[200] = { N6110_FRAME_HEADER, - 0x64, 0x01, 0x10, - 0x00, /* Length of the rest of the frame. */ - 0x00, /* The type of calendar note */ - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 - }; - - typedef struct { - char *model; - unsigned char call; - unsigned char meeting; - unsigned char birthday; - unsigned char reminder; - } calendar_model_length; - - /* Length of entries */ - calendar_model_length calendar_lengths[] = - { - /*model,CallTo,Meeting,Birthday,Reminder*/ - {"NHM-5",0x24,0x24,0x24,0x24}, //Reminder from phone, other quesses - {"NHM-6",0x24,0x24,0x24,0x24}, //Reminder from phone, other quesses - {"NSE-3",0x1e,0x14,0x14,0x1e}, //from NCDS3 [HKEY_LOCAL_MACHINE\Software\Nokia\Data Suite\3.0\Calendar] - {"NSM-1",0x1e,0x18,0x18,0x24}, //from NCDS3 - {"NSK-3",0x1e,0x14,0x14,0x1e}, //from NCDS3 - {"NSB-3",0x20,0x14,0x14,0x1e}, //from NCDS3 - {"", 0, 0, 0, 0 } //end of table - }; - - int i, j, current; - - u8 mychar; - - u8 mychar1,mychar2; - - GSM_Error error; - - /* Hopefully is 64 larger as FB38_MAX* / N6110_MAX* */ - char model[64]; - - req[7]=CalendarNote->Type; - - EncodeDateTime(req+8, &CalendarNote->Time); - req[14] = CalendarNote->Time.Timezone; - - if (CalendarNote->Alarm.Year) { - EncodeDateTime(req+15, &CalendarNote->Alarm); - req[21] = CalendarNote->Alarm.Timezone; - } - - req[22]=strlen(CalendarNote->Text); - - current=23; - - if (GetModelFeature (FN_CALENDAR)==F_CAL33 && CalendarNote->Type==GCN_REMINDER) { - req[22]++; // one additional char - req[current++]=0x01; //we use now subset 1 - } - - for (i=0; iText); i++) { - j=0; - mychar=CalendarNote->Text[i]; - if (GetModelFeature (FN_CALENDAR)==F_CAL33 && CalendarNote->Type==GCN_REMINDER) { - if (EncodeWithUTF8Alphabet(mychar,&mychar1,&mychar2)) { - req[current++]=mychar1; - req[current++]=mychar2; - req[23]=0x03; //use subset 3 - req[22]++; // one additional char - j=-1; - } - } - if (j!=-1) { - /* Enables/disables blinking */ - if (mychar=='~') req[current++]=0x01; - else req[current++]=mychar; - } - } - - req[current++]=strlen(CalendarNote->Phone); - - for (i=0; iPhone); i++) - req[current++]=CalendarNote->Phone[i]; - - while (N6110_GetModel(model) != GE_NONE) - sleep(1); - - /* Checking maximal length */ - i=0; - while (strcmp(calendar_lengths[i].model,"")) { - if (!strcmp(calendar_lengths[i].model,model)) { - switch (CalendarNote->Type) { - case GCN_REMINDER:if (req[22]>calendar_lengths[i].reminder) return GE_TOOLONG;break; - case GCN_MEETING :if (req[22]>calendar_lengths[i].meeting) return GE_TOOLONG;break; - case GCN_BIRTHDAY:if (req[22]>calendar_lengths[i].birthday) return GE_TOOLONG;break; - case GCN_CALL :if (strlen(CalendarNote->Phone)>calendar_lengths[i].call) return GE_TOOLONG;break; - } - break; - } - i++; - } - - CurrentCalendarNote = CalendarNote; - - error=NULL_SendMessageSequence - (20, &CurrentCalendarNoteError, current, 0x13, req); - - CurrentCalendarNote = NULL; - - return error; -} - -void N6110_ReplyDeleteCalendarNote(u16 MessageLength, u8 *MessageBuffer, u8 MessageType) { - -#ifdef DEBUG - switch (MessageBuffer[4]) { - /* This message is also sent when the user deletes an old entry on - keypad or moves an old entry somewhere (there is also `write' - message). */ - case 0x01:fprintf(stdout, _("Message: Calendar note deleted\n"));break; - case 0x93:fprintf(stdout, _("Message: Calendar note can't be deleted\n"));break; - default :fprintf(stdout, _("Message: Calendar note deleting error\n"));break; - } -#endif - - switch (MessageBuffer[4]) { - case 0x01:CurrentCalendarNoteError=GE_NONE;break; - case 0x93:CurrentCalendarNoteError=GE_INVALIDCALNOTELOCATION;break; - default :CurrentCalendarNoteError=GE_INTERNALERROR;break; - } -} - -GSM_Error N6110_DeleteCalendarNote(GSM_CalendarNote *CalendarNote) -{ - - unsigned char req[] = { N6110_FRAME_HEADER, - 0x68, 0x00 - }; - - req[4]=CalendarNote->Location; - - return NULL_SendMessageSequence (20, &CurrentCalendarNoteError, 5, 0x13, req); -} - -void N6110_ReplyRFBatteryLevel(u16 MessageLength, u8 *MessageBuffer, u8 MessageType) { - -#ifdef DEBUG - fprintf(stdout, _("Message: Phone status received:\n")); - fprintf(stdout, _(" Mode: ")); - - switch (MessageBuffer[4]) { - - case 0x01: - - fprintf(stdout, _("registered within the network\n")); - break; - - /* I was really amazing why is there a hole in the type of 0x02, now I - know... */ - case 0x02: fprintf(stdout, _("call in progress\n")); break; /* ringing or already answered call */ - case 0x03: fprintf(stdout, _("waiting for security code\n")); break; - case 0x04: fprintf(stdout, _("powered off\n")); break; - default : fprintf(stdout, _("unknown\n")); - - } - - fprintf(stdout, _(" Power source: ")); - - switch (MessageBuffer[7]) { - - case 0x01: fprintf(stdout, _("AC/DC\n")); break; - case 0x02: fprintf(stdout, _("battery\n")); break; - default : fprintf(stdout, _("unknown\n")); - - } - - fprintf(stdout, _(" Battery Level: %d\n"), MessageBuffer[8]); - fprintf(stdout, _(" Signal strength: %d\n"), MessageBuffer[5]); -#endif /* DEBUG */ - - CurrentRFLevel=MessageBuffer[5]; - CurrentBatteryLevel=MessageBuffer[8]; - CurrentPowerSource=MessageBuffer[7]; -} - - -GSM_Error N6110_GetRFLevel(GSM_RFUnits *units, float *level) -{ - - /* FIXME - these values are from 3810 code, may be incorrect. Map from - values returned in status packet to the the values returned by the AT+CSQ - command. */ - float csq_map[5] = {0, 8, 16, 24, 31}; - - int timeout=10; - int rf_level; - - char screen[NM_MAX_SCREEN_WIDTH]; - - CurrentRFLevel=-1; - - if (GetModelFeature (FN_NOPOWERFRAME)==F_NOPOWER) { - - if (N6110_NetMonitor(1, screen)!=GE_NONE) - return GE_INTERNALERROR; - - rf_level=4; - - if (screen[4]!='-') { - if (screen[5]=='9' && screen[6]>'4') rf_level=1; - if (screen[5]=='9' && screen[6]<'5') rf_level=2; - if (screen[5]=='8' && screen[6]>'4') rf_level=3; - } else rf_level=0; - - /* Arbitrary units. */ - if (*units == GRF_Arbitrary) { - *level = rf_level; - return (GE_NONE); - } - - } else { - N6110_SendStatusRequest(); - - /* Wait for timeout or other error. */ - while (timeout != 0 && CurrentRFLevel == -1 ) { - - if (--timeout == 0) - return (GE_TIMEOUT); - - usleep (100000); - } - - /* Make copy in case it changes. */ - rf_level = CurrentRFLevel; - - if (rf_level == -1) - return (GE_NOLINK); - - /* Now convert between the different units we support. */ - - /* Arbitrary units. */ - if (*units == GRF_Arbitrary) { - *level = rf_level; - return (GE_NONE); - } - - /* CSQ units. */ - if (*units == GRF_CSQ) { - - if (rf_level <=4) - *level = csq_map[rf_level]; - else - *level = 99; /* Unknown/undefined */ - - return (GE_NONE); - } - } - - /* Unit type is one we don't handle so return error */ - return (GE_INTERNALERROR); -} - - -GSM_Error N6110_GetBatteryLevel(GSM_BatteryUnits *units, float *level) -{ - int timeout=10; - int batt_level; - - char screen[NM_MAX_SCREEN_WIDTH]; - - CurrentBatteryLevel=-1; - - if (GetModelFeature (FN_NOPOWERFRAME)==F_NOPOWER) { - - if (N6110_NetMonitor(23, screen)!=GE_NONE) - return GE_NOLINK; - - batt_level=4; - - if (screen[29]=='7') batt_level=3; - if (screen[29]=='5') batt_level=2; - if (screen[29]=='2') batt_level=1; - - /* Only units we handle at present are GBU_Arbitrary */ - if (*units == GBU_Arbitrary) { - *level = batt_level; - return (GE_NONE); - } - - return (GE_INTERNALERROR); - - } else { - N6110_SendStatusRequest(); - - /* Wait for timeout or other error. */ - while (timeout != 0 && CurrentBatteryLevel == -1 ) { - - if (--timeout == 0) - return (GE_TIMEOUT); - - usleep (100000); - } - - /* Take copy in case it changes. */ - batt_level = CurrentBatteryLevel; - - if (batt_level != -1) { - - /* Only units we handle at present are GBU_Arbitrary */ - if (*units == GBU_Arbitrary) { - *level = batt_level; - return (GE_NONE); - } - - return (GE_INTERNALERROR); - } - else - return (GE_NOLINK); - } -} - -GSM_Error N6110_GetPowerSource(GSM_PowerSource *source) -{ - - int timeout=10; - - char screen[NM_MAX_SCREEN_WIDTH]; - - CurrentPowerSource=-1; - - if (GetModelFeature (FN_NOPOWERFRAME)==F_NOPOWER) { - - if (N6110_NetMonitor(20, screen)!=GE_NONE) - return GE_NOLINK; - - CurrentPowerSource=GPS_ACDC; - - if (screen[6]=='x') CurrentPowerSource=GPS_BATTERY; - - *source=CurrentPowerSource; - - return GE_NONE; - } else { - N6110_SendStatusRequest(); - - /* Wait for timeout or other error. */ - while (timeout != 0 && CurrentPowerSource == -1 ) { - - if (--timeout == 0) - return (GE_TIMEOUT); - - usleep (100000); - } - - if (CurrentPowerSource != -1) { - *source=CurrentPowerSource; - return (GE_NONE); - } - else - return (GE_NOLINK); - } -} - -void N6110_ReplyGetDisplayStatus(u16 MessageLength, u8 *MessageBuffer, u8 MessageType) { - - int i; - - for (i=0; iSendMessage(sizeof(req3), 0x01, req3); - Protocol->SendMessage(sizeof(req4), 0x01, req4); - req_end = req_end1; - size = sizeof(req_end1); - break; - case -1: /* Just used to set the call passup */ - return GE_NONE; - break; - default: - req_end = req_end0; - size = sizeof(req_end0); - break; - } + error=NULL_SendMessageSequence + (20, &CurrentPhonebookError, 7, 0x03, req); + + CurrentPhonebookEntry = NULL; + + return error; +} - req[4] = strlen(Number); +void N6110_ReplyGetOperatorName(u16 MessageLength, u8 *MessageBuffer, u8 MessageType) { - for(i = 0; i < strlen(Number) ; i++) - req[5+i] = Number[i]; + int i, count; + + GSM_Bitmap NullBitmap; - memcpy(req + 5 + strlen(Number), req_end, size); + DecodeNetworkCode(MessageBuffer+5, NullBitmap.netcode); + + count=8; - Protocol->SendMessage(5 + size + strlen(Number), 0x01, req); - if (type != 1) Protocol->SendMessage(26, 0x01, req2); +#ifdef DEBUG + fprintf(stdout, _("Message: Info about downloaded operator name received: %s network (for gnokii \"%s\", for phone \""), + NullBitmap.netcode, + GSM_GetNetworkName(NullBitmap.netcode)); +#endif + + i=count; + while (MessageBuffer[count]!=0) { +#ifdef DEBUG + fprintf(stdout,_("%c"),MessageBuffer[count]); +#endif + count++; + } + + strcpy(CurrentGetOperatorNameNetwork->Code, NullBitmap.netcode); + strncpy(CurrentGetOperatorNameNetwork->Name, MessageBuffer+i,count-i+1); - return (GE_NONE); +#ifdef DEBUG + fprintf(stdout,_("\")\n")); +#endif + + CurrentGetOperatorNameError=GE_NONE; } -GSM_Error N6110_GetIncomingCallNr(char *Number) -{ - - if (*CurrentIncomingCall != ' ') { - strcpy(Number, CurrentIncomingCall); - return GE_NONE; - } - else - return GE_BUSY; -} - -GSM_Error N6110_CancelCall(void) +GSM_Error N6110_GetOperatorName (GSM_Network *operator) { -// This frame & method works only on 61xx/51xx -// unsigned char req[] = { N6110_FRAME_HEADER, 0x08, 0x00, 0x85}; -// req[4]=CurrentCallSequenceNumber; -// Protocol->SendMessage(6, 0x01, req); -// return GE_NONE; - + unsigned char req[] = { 0x00,0x01,0x8c,0x00}; + GSM_Error error; - unsigned char req[]={0x00,0x01,0x7c,0x03}; - - /* Checking */ error=N6110_EnableExtendedCommands(0x01); if (error!=GE_NONE) return error; - return NULL_SendMessageSequence (20, &CurrentDialVoiceError, 4, 0x40, req); -} - -void N6110_ReplyEnterSecurityCode(u16 MessageLength, u8 *MessageBuffer, u8 MessageType) { - - switch(MessageBuffer[3]) { - - case 0x0b: -#ifdef DEBUG - fprintf(stdout, _("Message: Security code accepted.\n")); -#endif /* DEBUG */ - CurrentSecurityCodeError = GE_NONE; - break; - - default: -#ifdef DEBUG - fprintf(stdout, _("Message: Security code is wrong. You're not my big owner :-)\n")); -#endif /* DEBUG */ - CurrentSecurityCodeError = GE_INVALIDSECURITYCODE; - } -} - -GSM_Error N6110_EnterSecurityCode(GSM_SecurityCode SecurityCode) -{ - - unsigned char req[15] = { N6110_FRAME_HEADER, - 0x0a, /* Enter code request. */ - 0x00 /* Type of the entered code. */ - }; - int i=0; - - req[4]=SecurityCode.Type; - - for (i=0; iType==MessageBuffer[3] /* We wanted this code */ - && MessageBuffer[4]==1) { /* It's allowed */ - if (MessageBuffer[3]==GSCT_SecurityCode) { - for (i=0;i<5;i++) {CurrentSecurityCode->Code[i]=MessageBuffer[5+i];} - CurrentSecurityCode->Code[5]=0; - } - if (MessageBuffer[3]==GSCT_Pin || MessageBuffer[3]==GSCT_Pin2 || - MessageBuffer[3]==GSCT_Puk || MessageBuffer[3]==GSCT_Puk2) { - for (i=0;i<4;i++) {CurrentSecurityCode->Code[i]=MessageBuffer[5+i];} - CurrentSecurityCode->Code[4]=0; - } - CurrentSecurityCodeError=GE_NONE; - } else - CurrentSecurityCodeError=GE_INVALIDSECURITYCODE; -} - -GSM_Error N6110_GetSecurityCode(GSM_SecurityCode *SecurityCode) -{ - - unsigned char req[4] = { 0x00, - 0x01,0x6e, /* Get code request. */ - 0x00 }; /* Type of the requested code. */ - - GSM_Error error; - - error=N6110_EnableExtendedCommands(0x01); - if (error!=GE_NONE) return error; - - req[3]=SecurityCode->Type; - - CurrentSecurityCode=SecurityCode; - - return NULL_SendMessageSequence - (20, &CurrentSecurityCodeError, 4, 0x40, req); -} - -void N6110_ReplyPlayTone(u16 MessageLength, u8 *MessageBuffer, u8 MessageType) { - -#ifdef DEBUG - fprintf(stdout, _("Message: answer for PlayTone frame\n")); -#endif - - CurrentPlayToneError=GE_NONE; -} - -GSM_Error N6110_PlayTone(int Herz, u8 Volume) -{ - unsigned char req[6] = { 0x00,0x01,0x8f, - 0x00, /* Volume */ - 0x00, /* HerzLo */ - 0x00 }; /* HerzHi */ - - GSM_Error error; - - /* PlayTone wasn't used earlier */ - if (CurrentPlayToneError==GE_UNKNOWN) { - if (CurrentConnectionType!=GCT_MBUS) - CurrentDisableKeepAlive=true; - - error=N6110_EnableExtendedCommands(0x01); - if (error!=GE_NONE) return error; - } - - /* For Herz==255*255 we have silent */ - if (Herz!=255*255) { - req[3]=Volume; - - req[5]=Herz%256; - req[4]=Herz/256; - } else { - req[3]=0; - - req[5]=0; - req[4]=0; - } - -#ifdef WIN32 - /* For Herz==255*255 we have silent and additionaly - we wait for phone answer - it's important for MBUS */ - if (Herz==255*255) { - error=NULL_SendMessageSequence - (20, &CurrentPlayToneError, 6, 0x40, req); - - CurrentPlayToneError=GE_UNKNOWN; - CurrentDisableKeepAlive=false; - - if (error!=GE_NONE) return error; - } else { - Protocol->SendMessage(6,0x40,req); - } -#else - error=NULL_SendMessageSequence - (20, &CurrentPlayToneError, 6, 0x40, req); - - /* For Herz==255*255 we wait for phone answer - it's important for MBUS */ - if (Herz==255*255) { - CurrentPlayToneError=GE_UNKNOWN; - CurrentDisableKeepAlive=false; - } - - if (error!=GE_NONE) return error; - -#endif - - return(GE_NONE); -} - -void N6110_ReplyGetDateTime(u16 MessageLength, u8 *MessageBuffer, u8 MessageType) { - - if (MessageBuffer[4]==0x01) { - DecodeDateTime(MessageBuffer+8, CurrentDateTime); - -#ifdef DEBUG - fprintf(stdout, _("Message: Date and time\n")); - fprintf(stdout, _(" Time: %02d:%02d:%02d\n"), CurrentDateTime->Hour, CurrentDateTime->Minute, CurrentDateTime->Second); - fprintf(stdout, _(" Date: %4d/%02d/%02d\n"), CurrentDateTime->Year, CurrentDateTime->Month, CurrentDateTime->Day); -#endif /* DEBUG */ - - CurrentDateTime->IsSet=true; - } else { - -#ifdef DEBUG - fprintf(stdout, _("Message: Date and time not set in phone\n")); -#endif - - CurrentDateTime->IsSet=false; - } - - CurrentDateTimeError=GE_NONE; -} - -GSM_Error N6110_GetDateTime(GSM_DateTime *date_time) -{ - return N6110_PrivGetDateTime(date_time,0x11); -} - -GSM_Error N6110_PrivGetDateTime(GSM_DateTime *date_time, int msgtype) -{ - unsigned char req[] = {N6110_FRAME_HEADER, 0x62}; - - CurrentDateTime=date_time; - - return NULL_SendMessageSequence - (50, &CurrentDateTimeError, 4, msgtype, req); -} - -void N6110_ReplyGetAlarm(u16 MessageLength, u8 *MessageBuffer, u8 MessageType) { - -#ifdef DEBUG - fprintf(stdout, _("Message: Alarm\n")); - fprintf(stdout, _(" Alarm: %02d:%02d\n"), MessageBuffer[9], MessageBuffer[10]); - fprintf(stdout, _(" Alarm is %s\n"), (MessageBuffer[8]==2) ? _("on"):_("off")); -#endif /* DEBUG */ - - CurrentAlarm->Hour=MessageBuffer[9]; - CurrentAlarm->Minute=MessageBuffer[10]; - CurrentAlarm->Second=0; - - CurrentAlarm->IsSet=(MessageBuffer[8]==2); - - CurrentAlarmError=GE_NONE; -} - -GSM_Error N6110_GetAlarm(int alarm_number, GSM_DateTime *date_time) -{ - return N6110_PrivGetAlarm(alarm_number,date_time,0x11); -} - -GSM_Error N6110_PrivGetAlarm(int alarm_number, GSM_DateTime *date_time, int msgtype) -{ - unsigned char req[] = {N6110_FRAME_HEADER, 0x6d}; - - CurrentAlarm=date_time; - - return NULL_SendMessageSequence - (50, &CurrentAlarmError, 4, msgtype, req); -} - -void N6110_ReplyGetSMSCenter(u16 MessageLength, u8 *MessageBuffer, u8 MessageType) { - - switch (MessageBuffer[3]) { - - case 0x34: - - CurrentMessageCenter->No=MessageBuffer[4]; - CurrentMessageCenter->Format=MessageBuffer[6]; - CurrentMessageCenter->Validity=MessageBuffer[8]; - sprintf(CurrentMessageCenter->Name, "%s", MessageBuffer+33); - - sprintf(CurrentMessageCenter->DefaultRecipient, "%s", GSM_UnpackSemiOctetNumber(MessageBuffer+9,false)); - - sprintf(CurrentMessageCenter->Number, "%s", GSM_UnpackSemiOctetNumber(MessageBuffer+21,false)); - -#ifdef DEBUG - fprintf(stdout, _("Message: SMS Center received:\n")); - fprintf(stdout, _(" %d. SMS Center name is %s\n"), CurrentMessageCenter->No, CurrentMessageCenter->Name); - fprintf(stdout, _(" SMS Center number is %s\n"), CurrentMessageCenter->Number); - fprintf(stdout, _(" Default recipient number is %s\n"), CurrentMessageCenter->DefaultRecipient); - - fprintf(stdout, _(" SMS Center message format is ")); - - switch (CurrentMessageCenter->Format) { - - case GSMF_Text : fprintf(stdout, _("Text")); break; - case GSMF_Paging: fprintf(stdout, _("Paging")); break; - case GSMF_Fax : fprintf(stdout, _("Fax")); break; - case GSMF_Email : fprintf(stdout, _("Email")); break; - default : fprintf(stdout, _("Unknown")); - } - - fprintf(stdout, "\n"); - - fprintf(stdout, _(" SMS Center message validity is ")); - - switch (CurrentMessageCenter->Validity) { - - case GSMV_1_Hour : fprintf(stdout, _("1 hour")); break; - case GSMV_6_Hours : fprintf(stdout, _("6 hours")); break; - case GSMV_24_Hours: fprintf(stdout, _("24 hours")); break; - case GSMV_72_Hours: fprintf(stdout, _("72 hours")); break; - case GSMV_1_Week : fprintf(stdout, _("1 week")); break; - case GSMV_Max_Time: fprintf(stdout, _("Maximum time"));break; - default : fprintf(stdout, _("Unknown")); - } - - fprintf(stdout, "\n"); - -#endif /* DEBUG */ - - CurrentMessageCenterError=GE_NONE; - - break; - - case 0x35: - - /* Number of entries depends on SIM card */ - -#ifdef DEBUG - fprintf(stdout, _("Message: SMS Center error received:\n")); - fprintf(stdout, _(" The request for SMS Center failed.\n")); -#endif /* DEBUG */ - - /* FIXME: appropriate error. */ - CurrentMessageCenterError=GE_INTERNALERROR; - - break; - - } -} - -/* This function sends to the mobile phone a request for the SMS Center */ -GSM_Error N6110_GetSMSCenter(GSM_MessageCenter *MessageCenter) -{ - unsigned char req[] = { N6110_FRAME_HEADER, 0x33, 0x64, - 0x00 /* SMS Center Number. */ - }; - - req[5]=MessageCenter->No; - - CurrentMessageCenter=MessageCenter; - - return NULL_SendMessageSequence - (50, &CurrentMessageCenterError, 6, 0x02, req); -} - -void N6110_ReplySetSMSCenter(u16 MessageLength, u8 *MessageBuffer, u8 MessageType) { - -#ifdef DEBUG - fprintf(stdout, _("Message: SMS Center correctly set.\n")); -#endif - CurrentMessageCenterError=GE_NONE; -} - -/* This function set the SMS Center profile on the phone. */ -GSM_Error N6110_SetSMSCenter(GSM_MessageCenter *MessageCenter) -{ - unsigned char req[64] = { N6110_FRAME_HEADER, 0x30, 0x64, - 0x00, /* SMS Center Number. */ - 0x00, /* Unknown. */ - 0x00, /* SMS Message Format. */ - 0x00, /* Unknown. */ - 0x00, /* Validity. */ - 0,0,0,0,0,0,0,0,0,0,0,0, /* Default recipient number */ - 0,0,0,0,0,0,0,0,0,0,0,0 /* Message Center Number. */ - /* Message Center Name. */ - }; - - req[5]=MessageCenter->No; - req[7]=MessageCenter->Format; - req[9]=MessageCenter->Validity; - - req[10]=GSM_PackSemiOctetNumber(MessageCenter->DefaultRecipient, req+11, false); - - req[22]=GSM_PackSemiOctetNumber(MessageCenter->Number, req+23, false); - - sprintf(req+34, "%s", MessageCenter->Name); - - CurrentMessageCenter=MessageCenter; - - return NULL_SendMessageSequence - (50, &CurrentMessageCenterError, 35+strlen(MessageCenter->Name), 0x02, req); -} - -void N6110_ReplyGetSMSStatus(u16 MessageLength, u8 *MessageBuffer, u8 MessageType) { - - switch (MessageBuffer[3]) { - - case 0x37: - -#ifdef DEBUG - fprintf(stdout, _("Message: SMS Status Received\n")); - fprintf(stdout, _(" The number of messages: %d\n"), MessageBuffer[10]); - fprintf(stdout, _(" Unread messages: %d\n"), MessageBuffer[11]); -#endif /* DEBUG */ - - CurrentSMSStatus->UnRead = MessageBuffer[11]; - CurrentSMSStatus->Number = MessageBuffer[10]; - - CurrentSMSStatusError = GE_NONE; - break; - - case 0x38: - -#ifdef DEBUG - fprintf(stdout, _("Message: SMS Status error, probably not authorized by PIN\n")); -#endif /* DEBUG */ - - CurrentSMSStatusError = GE_INTERNALERROR; - break; - - } -} - -GSM_Error N6110_GetSMSStatus(GSM_SMSStatus *Status) -{ - unsigned char req[] = {N6110_FRAME_HEADER, 0x36, 0x64}; - - CurrentSMSStatus = Status; - - return NULL_SendMessageSequence - (10, &CurrentSMSStatusError, 5, 0x14, req); -} + CurrentGetOperatorNameNetwork = operator; -GSM_Error N6110_GetSMSFolders ( GSM_SMSFolders *folders) -{ - folders->number=2; + error=NULL_SendMessageSequence + (20, &CurrentGetOperatorNameError, 4, 0x40, req); - strcpy(folders->Folder[0].Name,"Inbox"); - strcpy(folders->Folder[1].Name,"Outbox"); + CurrentGetOperatorNameNetwork = NULL; - return GE_NONE; + return error; } - -GSM_Error N6110_GetIMEI(char *imei) -{ - if (strlen(Current_IMEI)>0) { - strncpy (imei, Current_IMEI, GSM_MAX_IMEI_LENGTH); - return (GE_NONE); - } - else - return (GE_TRYAGAIN); -} - -GSM_Error N6110_GetRevision(char *revision) -{ - - if (strlen(Current_Revision)>0) { - strncpy (revision, Current_Revision, GSM_MAX_REVISION_LENGTH); - return (GE_NONE); - } - else - return (GE_TRYAGAIN); -} - -GSM_Error N6110_GetModel(char *model) -{ - if (strlen(Current_Model)>0) { - strncpy (model, Current_Model, GSM_MAX_MODEL_LENGTH); - return (GE_NONE); - } - else - return (GE_TRYAGAIN); -} - -void N6110_ReplySetDateTime(u16 MessageLength, u8 *MessageBuffer, u8 MessageType) { - - switch (MessageBuffer[4]) { - - case 0x01: -#ifdef DEBUG - fprintf(stdout, _("Message: Date and time set correctly\n")); -#endif /* DEBUG */ - CurrentSetDateTimeError=GE_NONE; - break; - - default: -#ifdef DEBUG - fprintf(stdout, _("Message: Date and time setting error\n")); -#endif /* DEBUG */ - CurrentSetDateTimeError=GE_INVALIDDATETIME; - - } -} - -/* Needs SIM card with PIN in phone */ -GSM_Error N6110_SetDateTime(GSM_DateTime *date_time) -{ - return N6110_PrivSetDateTime(date_time,0x11); -} - -/* Needs SIM card with PIN in phone */ -GSM_Error N6110_PrivSetDateTime(GSM_DateTime *date_time, int msgtype) -{ - - unsigned char req[] = { N6110_FRAME_HEADER, - 0x60, /* set-time subtype */ - 0x01, 0x01, 0x07, /* unknown */ - 0x00, 0x00, /* Year (0x07cf = 1999) */ - 0x00, 0x00, /* Month Day */ - 0x00, 0x00, /* Hours Minutes */ - 0x00 /* Unknown, but not seconds - try 59 and wait 1 sec. */ - }; - - EncodeDateTime(req+7, date_time); - - return NULL_SendMessageSequence - (20, &CurrentSetDateTimeError, 14, msgtype, req); -} - -void N6110_ReplySetAlarm(u16 MessageLength, u8 *MessageBuffer, u8 MessageType) { - - switch (MessageBuffer[4]) { - - case 0x01: -#ifdef DEBUG - fprintf(stdout, _("Message: Alarm set correctly\n")); -#endif /* DEBUG */ - CurrentSetAlarmError=GE_NONE; - break; - - default: -#ifdef DEBUG - fprintf(stdout, _("Message: Alarm setting error\n")); -#endif /* DEBUG */ - CurrentSetAlarmError=GE_INVALIDDATETIME; - - } -} - -/* FIXME: we should also allow to set the alarm off :-) */ -GSM_Error N6110_SetAlarm(int alarm_number, GSM_DateTime *date_time) -{ - return N6110_PrivSetAlarm(alarm_number,date_time, 0x11); -} - -/* FIXME: we should also allow to set the alarm off :-) */ -GSM_Error N6110_PrivSetAlarm(int alarm_number, GSM_DateTime *date_time, int msgtype) -{ - - unsigned char req[] = { N6110_FRAME_HEADER, - 0x6b, /* set-alarm subtype */ - 0x01, 0x20, 0x03, /* unknown */ - 0x02, /* should be alarm on/off, but it don't works */ - 0x00, 0x00, /* Hours Minutes */ - 0x00 /* Unknown, but not seconds - try 59 and wait 1 sec. */ - }; - - req[8] = date_time->Hour; - req[9] = date_time->Minute; - - return NULL_SendMessageSequence - (50, &CurrentSetAlarmError, 11, msgtype, req); -} - -void N6110_ReplyGetMemoryLocation(u16 MessageLength, u8 *MessageBuffer, u8 MessageType) { - - /* Hopefully is 64 larger as FB38_MAX* / N6110_MAX* */ - char model[64]; - - int i, tmp, count; - - switch (MessageBuffer[3]) { - - case 0x02: - - CurrentPhonebookEntry->Empty = true; - - count=MessageBuffer[5]; - -#ifdef DEBUG - fprintf(stdout, _("Message: Phonebook entry received:\n")); - fprintf(stdout, _(" Name: ")); - - for (tmp=0; tmp Name, MessageBuffer+6, count/2); - CurrentPhonebookEntry->Name[count/2] = 0x00; - } else { - memcpy(CurrentPhonebookEntry->Name, MessageBuffer + 6, count); - CurrentPhonebookEntry->Name[count] = 0x00; - } - - CurrentPhonebookEntry->Empty = false; - - for (tmp=0; tmp Name[tmp/2]='~'; //enables/disables blinking - if (tmp%2!=0 && MessageBuffer[6+tmp]==0) CurrentPhonebookEntry->Name[tmp/2]='`'; //hides rest ot contents - } else { - if (MessageBuffer[6+tmp]==1) CurrentPhonebookEntry->Name[tmp]='~'; //enables/disables blinking - if (MessageBuffer[6+tmp]==0) CurrentPhonebookEntry->Name[tmp]='`'; //hides rest ot contents - } - } - - i=7+count; - count=MessageBuffer[6+count]; - -#ifdef DEBUG - fprintf(stdout, _(" Number: ")); - - for (tmp=0; tmp Number, MessageBuffer + i, count); - CurrentPhonebookEntry->Number[count] = 0x00; - CurrentPhonebookEntry->Group = MessageBuffer[i+count]; - - /* Phone doesn't have entended phonebook */ - CurrentPhonebookEntry->SubEntriesCount = 0; - - /* But for these memories data is saved and we can save it using 7110/6210 style */ - if (CurrentPhonebookEntry->MemoryType==GMT_DC || - CurrentPhonebookEntry->MemoryType==GMT_RC || - CurrentPhonebookEntry->MemoryType==GMT_MC) { - CurrentPhonebookEntry->SubEntriesCount = 1; - CurrentPhonebookEntry->SubEntries[0].EntryType=N7110_ENTRYTYPE_DATE; - CurrentPhonebookEntry->SubEntries[0].NumberType=0; - CurrentPhonebookEntry->SubEntries[0].BlockNumber=1; - DecodeDateTime(MessageBuffer+(i+count+2),&CurrentPhonebookEntry->SubEntries[0].data.Date); - -#ifdef DEBUG - fprintf(stdout, _(" Date: ")); - fprintf(stdout, "%02u.%02u.%04u\n", - CurrentPhonebookEntry->SubEntries[0].data.Date.Day, - CurrentPhonebookEntry->SubEntries[0].data.Date.Month, - CurrentPhonebookEntry->SubEntries[0].data.Date.Year); - fprintf(stdout, _(" Time: ")); - fprintf(stdout, "%02u:%02u:%02u\n", - CurrentPhonebookEntry->SubEntries[0].data.Date.Hour, - CurrentPhonebookEntry->SubEntries[0].data.Date.Minute, - CurrentPhonebookEntry->SubEntries[0].data.Date.Second); -#endif /* DEBUG */ - - /* These values are set, when date and time unavailable in phone. - Values from 3310 - in other can be different */ - if (CurrentPhonebookEntry->SubEntries[0].data.Date.Day==20 && - CurrentPhonebookEntry->SubEntries[0].data.Date.Month==1 && - CurrentPhonebookEntry->SubEntries[0].data.Date.Year==2118 && - CurrentPhonebookEntry->SubEntries[0].data.Date.Hour==3 && - CurrentPhonebookEntry->SubEntries[0].data.Date.Minute==14 && - CurrentPhonebookEntry->SubEntries[0].data.Date.Second==7) - CurrentPhonebookEntry->SubEntriesCount = 0; - } - - /* Signal no error to calling code. */ - CurrentPhonebookError = GE_NONE; - - break; - - case 0x03: - -#ifdef DEBUG - fprintf(stdout, _("Message: Phonebook read entry error received:\n")); -#endif /* DEBUG */ - - switch (MessageBuffer[4]) { - - case 0x7d: -#ifdef DEBUG - fprintf(stdout, _(" Invalid memory type!\n")); -#endif /* DEBUG */ - CurrentPhonebookError = GE_INVALIDMEMORYTYPE; - break; - - default: -#ifdef DEBUG - fprintf(stdout, _(" Unknown error!\n")); -#endif /* DEBUG */ - CurrentPhonebookError = GE_INTERNALERROR; - } - - break; - - } -} - -/* Routine to get specifed phone book location. Designed to be called by - application. Will block until location is retrieved or a timeout/error - occurs. */ -GSM_Error N6110_GetMemoryLocation(GSM_PhonebookEntry *entry) -{ - unsigned char req[] = {N6110_FRAME_HEADER, 0x01, 0x00, 0x00, 0x00}; - - CurrentPhonebookEntry = entry; - - req[4] = N6110_GetMemoryType(entry->MemoryType); - req[5] = entry->Location; - - return NULL_SendMessageSequence - (50, &CurrentPhonebookError, 7, 0x03, req); -} - -void N6110_ReplyWritePhonebookLocation(u16 MessageLength, u8 *MessageBuffer, u8 MessageType) { - - switch (MessageBuffer[3]) { - - case 0x05: - -#ifdef DEBUG - fprintf(stdout, _("Message: Phonebook written correctly.\n")); -#endif /* DEBUG */ - CurrentPhonebookError = GE_NONE; - break; - - case 0x06: - - switch (MessageBuffer[4]) { - /* FIXME: other errors? When I send the phonebook with index of 350 it - still report error 0x7d :-( */ - case 0x7d: -#ifdef DEBUG - fprintf(stdout, _("Message: Phonebook not written - name is too long.\n")); -#endif /* DEBUG */ - CurrentPhonebookError = GE_PHBOOKNAMETOOLONG; - break; - - default: -#ifdef DEBUG - fprintf(stdout, _(" Unknown error!\n")); -#endif /* DEBUG */ - CurrentPhonebookError = GE_INTERNALERROR; - } - } -} - -/* Routine to write phonebook location in phone. Designed to be called by - application code. Will block until location is written or timeout - occurs. */ -GSM_Error N6110_WritePhonebookLocation(GSM_PhonebookEntry *entry) -{ - unsigned char req[128] = { N6110_FRAME_HEADER, 0x04, 0x00, 0x00 }; - int i=0, current=0; - - req[4] = N6110_GetMemoryType(entry->MemoryType); - req[5] = entry->Location; - - current=7; - - if (GetModelFeature (FN_PHONEBOOK)==F_PBK33) { - - req[6] = strlen(entry->Name)*2; - - EncodeUnicode (req+current,entry->Name ,strlen(entry->Name)); - - for (i=0; iName); i++) - { - /* here we encode "special" chars */ - if (entry->Name[i]=='~') req[current+i*2]=1; //enables/disables blinking - if (entry->Name[i]=='`') req[current+i*2]=0; //hides rest ot contents - } - - current+=strlen(entry->Name)*2; - } else { - - req[6] = strlen(entry->Name); - - for (i=0; iName); i++) - { - req[current+i] = entry->Name[i]; - - /* here we encode "special" chars */ - if (entry->Name[i]=='~') req[current+i]=1; //enables/disables blinking - if (entry->Name[i]=='`') req[current+i]=0; //hides rest ot contents - } - - current+=strlen(entry->Name); - } - - req[current++]=strlen(entry->Number); - - for (i=0; iNumber); i++) - req[current+i] = entry->Number[i]; - - current+=strlen(entry->Number); - - /* Jano: This allow to save 14 characters name into SIM memory, when - No Group is selected. */ - if (entry->Group == 5) - req[current++]=0xff; - else - req[current++]=entry->Group; - - return NULL_SendMessageSequence - (50, &CurrentPhonebookError, current, 0x03, req); -} - -void N6110_ReplyNetmonitor(u16 MessageLength, u8 *MessageBuffer, u8 MessageType) { - - switch(MessageBuffer[3]) { - - case 0x00: -#ifdef DEBUG - fprintf(stdout, _("Message: Netmonitor correctly set.\n")); -#endif /* DEBUG */ - CurrentNetmonitorError=GE_NONE; - break; - - default: -#ifdef DEBUG - fprintf(stdout, _("Message: Netmonitor menu %d received:\n"), MessageBuffer[3]); - fprintf(stdout, "%s\n", MessageBuffer+4); -#endif /* DEBUG */ - - strcpy(CurrentNetmonitor, MessageBuffer+4); - - CurrentNetmonitorError=GE_NONE; - } -} - -GSM_Error N6110_NetMonitor(unsigned char mode, char *Screen) -{ - unsigned char req[] = { 0x00, 0x01, 0x7e, 0x00 }; - - GSM_Error error; - - error=N6110_EnableExtendedCommands(0x01); - if (error!=GE_NONE) return error; - - CurrentNetmonitor=Screen; - - req[3]=mode; - - return NULL_SendMessageSequence - (20, &CurrentNetmonitorError, 4, 0x40, req); -} - -/* Doesn't work in N3210. */ -/* In other allow to access phone menu without SIM card (just send any sequence) */ -GSM_Error N6110_SendDTMF(char *String) -{ - unsigned char req[64] = { N6110_FRAME_HEADER, 0x50, - 0x00 /* Length of DTMF string. */ - }; - - u8 length=strlen(String); - - if (length>59) length=59; - - req[4] = length; - - memcpy(req+5,String,length); - - return NULL_SendMessageSequence - (20, &CurrentSendDTMFError, 5+length, 0x01, req); -} - -void N6110_ReplyGetSpeedDial(u16 MessageLength, u8 *MessageBuffer, u8 MessageType) { - - switch (MessageBuffer[3]) { - - case 0x17: - - switch (MessageBuffer[4]) { - case 0x02: CurrentSpeedDialEntry->MemoryType = GMT_ME; - default : CurrentSpeedDialEntry->MemoryType = GMT_SM; - } - - CurrentSpeedDialEntry->Location = MessageBuffer[5]; - -#ifdef DEBUG - fprintf(stdout, _("Message: Speed dial entry received:\n")); - fprintf(stdout, _(" Location: %d\n"), CurrentSpeedDialEntry->Location); - fprintf(stdout, _(" MemoryType: %s\n"), N6110_MemoryType_String[CurrentSpeedDialEntry->MemoryType]); - fprintf(stdout, _(" Number: %d\n"), CurrentSpeedDialEntry->Number); -#endif /* DEBUG */ - - CurrentSpeedDialError=GE_NONE; - break; - - case 0x18: - -#ifdef DEBUG - fprintf(stdout, _("Message: Speed dial entry error\n")); -#endif /* DEBUG */ - CurrentSpeedDialError=GE_INVALIDSPEEDDIALLOCATION; - break; - - } -} - -GSM_Error N6110_GetSpeedDial(GSM_SpeedDial *entry) -{ - - unsigned char req[] = { N6110_FRAME_HEADER, - 0x16, - 0x00 /* The number of speed dial. */ - }; - - CurrentSpeedDialEntry = entry; - - req[4] = entry->Number; - - return NULL_SendMessageSequence - (20, &CurrentSpeedDialError, 5, 0x03, req); -} - -void N6110_ReplySetSpeedDial(u16 MessageLength, u8 *MessageBuffer, u8 MessageType) { - - switch (MessageBuffer[3]) { - - case 0x1a: - -#ifdef DEBUG - fprintf(stdout, _("Message: Speed dial entry set.\n")); -#endif /* DEBUG */ - CurrentSpeedDialError=GE_NONE; - break; - - case 0x1b: - -#ifdef DEBUG - fprintf(stdout, _("Message: Speed dial entry setting error.\n")); -#endif /* DEBUG */ - CurrentSpeedDialError=GE_INVALIDSPEEDDIALLOCATION; - break; - - } -} - -GSM_Error N6110_SetSpeedDial(GSM_SpeedDial *entry) -{ - - unsigned char req[] = { N6110_FRAME_HEADER, - 0x19, - 0x00, /* Number */ - 0x00, /* Memory Type */ - 0x00 /* Location */ - }; - - req[4] = entry->Number; - - switch (entry->MemoryType) { - case GMT_ME: req[5] = 0x02; - default : req[5] = 0x03; - } - - req[6] = entry->Location; - - return NULL_SendMessageSequence - (20, &CurrentSpeedDialError, 7, 0x03, req); -} - -/* This function finds parts of SMS in frame used in new Nokia phones - in internal protocols (they're coded according to GSM 03.40), copies them - to GSM_ETSISMSMessage and calls GSM_DecodeETSISMS to decode - GSM_ETSISMSMessage to GSM_SMSMessage structure */ -GSM_Error GSM_DecodeNokiaSMSFrame(GSM_SMSMessage *SMS, unsigned char *req, int length) -{ - SMS_MessageType PDU=SMS_Deliver; - GSM_ETSISMSMessage ETSI; - int offset=0,i; - - ETSI.firstbyte=req[12]; - - /* See GSM 03.40 section 9.2.3.1 */ - if ((ETSI.firstbyte & 0x03) == 0x01) PDU=SMS_Submit; - if ((ETSI.firstbyte & 0x03) == 0x02) PDU=SMS_Status_Report; - - switch (PDU) { - case SMS_Submit : offset=5;break; - case SMS_Deliver : offset=4;break; - case SMS_Status_Report: offset=3;break; - default: break; - } - - for (i=0;iName[0]=0; - - return GE_NONE; -} - -void N6110_ReplyGetSMSMessage(u16 MessageLength, u8 *MessageBuffer, u8 MessageType) { - - int offset; - - switch (MessageBuffer[3]) { - - case 0x08: - - switch (MessageBuffer[7]) { - - case 0x00: - CurrentSMSMessage->Type = GST_SMS; - CurrentSMSMessage->folder=GST_INBOX; - offset=4; - break; - - case 0x01: - CurrentSMSMessage->Type = GST_DR; - CurrentSMSMessage->folder=GST_INBOX; - offset=3; - break; - - case 0x02: - CurrentSMSMessage->Type = GST_SMS; - CurrentSMSMessage->folder=GST_OUTBOX; - offset=5; - break; - - default: - CurrentSMSMessage->Type = GST_UN; - offset=4; - break; - - } - - /* Field Short Message Status - MessageBuffer[4] seems not to be - compliant with GSM 07.05 spec. - Meaning Nokia protocol GMS spec - ---------------------------------------------------- - MO Sent 0x05 0x07 or 0x01 - MO Not sent 0x07 0x06 or 0x00 - MT Read 0x01 0x05 or 0x01 - MT Not read 0x03 0x04 or 0x00 - ---------------------------------------------------- - See GSM 07.05 section 2.5.2.6 and correct me if I'm wrong. - - Pawel Kot */ - - if (MessageBuffer[4] & 0x02) CurrentSMSMessage->Status = GSS_NOTSENTREAD; - else CurrentSMSMessage->Status = GSS_SENTREAD; - -#ifdef DEBUG - fprintf(stdout, _("Number: %d\n"), MessageBuffer[6]); - - if (CurrentSMSMessage->folder!=1) { //GST_OUTBOX - fprintf(stdout, _("Message: Received SMS (mobile terminated)\n")); - } else { - fprintf(stdout, _("Message: Outbox message (mobile originated)\n")); - } - - if (CurrentSMSMessage->Type == GST_DR) fprintf(stdout, _(" Delivery Report\n")); - if (CurrentSMSMessage->Type == GST_UN) fprintf(stdout, _(" Unknown type\n")); - - if (CurrentSMSMessage->folder==1) { //GST_OUTBOX - if (CurrentSMSMessage->Status) fprintf(stdout, _(" Sent\n")); - else fprintf(stdout, _(" Not sent\n")); - } else { - if (CurrentSMSMessage->Status) fprintf(stdout, _(" Read\n")); - else fprintf(stdout, _(" Not read\n")); - } -#endif - - CurrentSMSPointer=GSM_DecodeNokiaSMSFrame(CurrentSMSMessage, MessageBuffer+8, MessageLength-8); - - CurrentSMSMessage->MemoryType = MessageBuffer[5]; - CurrentSMSMessage->MessageNumber = MessageBuffer[6]; - - /* Signal no error to calling code. */ - CurrentSMSMessageError = GE_NONE; - -#ifdef DEBUG - fprintf(stdout, "\n"); -#endif - - break; - - case 0x09: - - /* We have requested invalid or empty location. */ - -#ifdef DEBUG - fprintf(stdout, _("Message: SMS reading failed\n")); - - switch (MessageBuffer[4]) { - case 0x02: - fprintf(stdout, _(" Invalid location!\n"));break; - case 0x07: - fprintf(stdout, _(" Empty SMS location.\n"));break; - case 0x0c: - fprintf(stdout, _(" No access to memory (no PIN on card ?)\n"));break; - default: - fprintf(stdout, _(" Error code %i - please report it \n"),MessageBuffer[4]);break; - } -#endif /* DEBUG */ - - switch (MessageBuffer[4]) { - case 0x02:CurrentSMSMessageError = GE_INVALIDSMSLOCATION;break; - case 0x07:CurrentSMSMessageError = GE_EMPTYSMSLOCATION;break; - case 0x0c:CurrentSMSMessageError = GE_NOACCESS;break; - default :CurrentSMSMessageError = GE_UNKNOWN;break; - } - - break; - - } -} - -GSM_Error N6110_GetSMSMessage(GSM_SMSMessage *message) -{ - - unsigned char req[] = { N6110_FRAME_HEADER, - 0x07, - 0x02, /* Unknown */ - 0x00, /* Location */ - 0x01, 0x64}; - - int timeout = 60; - - /* State machine code writes data to these variables when it comes in. */ - - CurrentSMSMessage = message; - CurrentSMSMessageError = GE_BUSY; - - req[5] = message->Location; - - /* Send request */ - Protocol->SendMessage(8, 0x02, req); - - /* Wait for timeout or other error. */ - while (timeout != 0 && (CurrentSMSMessageError == GE_BUSY || CurrentSMSMessageError == GE_SMSWAITING)) { - - if (--timeout == 0) - return (GE_TIMEOUT); - - usleep (100000); - } - - return (CurrentSMSMessageError); -} - -void N6110_ReplyDeleteSMSMessage(u16 MessageLength, u8 *MessageBuffer, u8 MessageType) { - -#ifdef DEBUG - fprintf(stdout, _("Message: SMS deleted successfully.\n")); -#endif /* DEBUG */ - - CurrentSMSMessageError = GE_NONE; -} - -GSM_Error N6110_DeleteSMSMessage(GSM_SMSMessage *message) -{ - unsigned char req[] = {N6110_FRAME_HEADER, 0x0a, 0x02, 0x00}; - - req[5] = message->Location; - - return NULL_SendMessageSequence - (50, &CurrentSMSMessageError, 6, 0x14, req); -} -/* FIXME: do we need more than SMS_Submit and SMS_Deliver ? */ -GSM_Error GSM_EncodeNokiaSMSFrame(GSM_SMSMessage *SMS, unsigned char *req, int *length, SMS_MessageType PDU) -{ - GSM_ETSISMSMessage ETSI; - int i,offset=0; +void N6110_ReplySetOperatorName(u16 MessageLength, u8 *MessageBuffer, u8 MessageType) { + +#ifdef DEBUG + fprintf(stdout, _("Message: Downloaded operator name changed\n")); +#endif - GSM_EncodeETSISMS(SMS, &ETSI, PDU, length); + CurrentSetOperatorNameError=GE_NONE; +} - /* Cleaning */ - for (i=0;i<36;i++) req[i]=0; +GSM_Error N6110_SetOperatorName (GSM_Network *operator) +{ + unsigned char req[256] = { 0x00,0x01,0x8b,0x00, + 0x00,0x00, /* MCC */ + 0x00}; /* MNC */ - req[12]=ETSI.firstbyte; + GSM_Error error; - for (i=0;iCode); - case SMS_Deliver: - offset=4; - for (i=0;i<((ETSI.Number[0]+1)/2+1)+1;i++) - req[i+12+offset]=ETSI.Number[i]; - req[10+offset]=ETSI.TPDCS; - req[11+offset]=ETSI.TPUDL; -// req[]=ETSI.TPPID; - for(i=0;i<*length;i++) - req[i+31+offset]=ETSI.MessageText[i]; - for (i=0;i<7;i++) - req[24+offset+i]=ETSI.DeliveryDateTime[i]; - break; - default: - break; - } - - *length=*length+offset; - - return GE_NONE; + strncpy(req+7,operator->Name,200); + + return NULL_SendMessageSequence + (20, &CurrentSetOperatorNameError, 8+strlen(operator->Name), 0x40, req); } - -void N6110_ReplySendSMSMessage(u16 MessageLength, u8 *MessageBuffer, u8 MessageType) { - - switch (MessageBuffer[3]) { - - /* SMS message correctly sent to the network */ - case 0x02: -#ifdef DEBUG - fprintf(stdout, _("Message: SMS Message correctly sent.\n")); -#endif /* DEBUG */ - CurrentSMSMessageError = GE_SMSSENDOK; - break; - - /* SMS message send to the network failed */ - case 0x03: - -#ifdef DEBUG - fprintf(stdout, _("Message: Sending SMS Message failed, error: %i"),MessageBuffer[6]); - - switch (MessageBuffer[6]) { - case 1: fprintf(stdout,_(" (info \"Number not in use\")"));break; - case 21: fprintf(stdout,_(" (info \"Message not sent this time\")"));break; - case 28: fprintf(stdout,_(" (info \"Number not in use\")"));break; - case 38: fprintf(stdout,_(" (info \"Message not sent this time\")"));break; case 50: fprintf(stdout,_(" (info \"Check operator services\")"));break; - case 96: fprintf(stdout,_(" (info \"Message sending failed\")"));break; - case 111: fprintf(stdout,_(" (info \"Message sending failed\")"));break; - case 166: fprintf(stdout,_(" (info \"Message sending failed\")"));break; - case 178: fprintf(stdout,_(" (info \"Message sending failed\")"));break; - case 252: fprintf(stdout,_(" (info \"Message sending failed\")"));break; case 253: fprintf(stdout,_(" (info \"Message sending failed\")"));break; - } - - fprintf(stdout,_("\n For more details with errors see netmonitor manual (test 65) on www.marcin-wiacek.topnet.pl")); - fprintf(stdout,_("\n If know their meaning, GSM specs decribing them, contact with me on marcin-wiacek@topnet.pl. THX\n")); -#endif /* DEBUG */ - - CurrentSMSMessageError = GE_SMSSENDFAILED; - break; - - } -} - -GSM_Error N6110_SendSMSMessage(GSM_SMSMessage *SMS) -{ - GSM_Error error; - - unsigned char req[256] = { - N6110_FRAME_HEADER, - 0x01, 0x02, 0x00, /* SMS send request*/ - }; - - int length; - - error=GSM_EncodeNokiaSMSFrame(SMS, req+6, &length, SMS_Submit); - if (error != GE_NONE) return error; - - return NULL_SendMessageSequence - (200, &CurrentSMSMessageError, 42+length, 0x02, req); -} - -void N6110_ReplySaveSMSMessage(u16 MessageLength, u8 *MessageBuffer, u8 MessageType) { - - switch (MessageBuffer[3]) { - - case 0x05: - -#ifdef DEBUG - fprintf(stdout, _("SMS Message stored at %d\n"), MessageBuffer[5]); -#endif - - CurrentSMSMessage->MessageNumber=MessageBuffer[5]; - - CurrentSMSMessageError = GE_NONE; - break; - - case 0x06: -#ifdef DEBUG - fprintf(stdout, _("SMS saving failed\n")); - switch (MessageBuffer[4]) { - case 0x02:fprintf(stdout, _(" All locations busy.\n"));break; - case 0x03:fprintf(stdout, _(" Invalid location!\n"));break; - default :fprintf(stdout, _(" Unknown error.\n"));break; - } -#endif - - switch (MessageBuffer[4]) { - case 0x02:CurrentSMSMessageError = GE_MEMORYFULL;break; - case 0x03:CurrentSMSMessageError = GE_INVALIDSMSLOCATION;break; - default :CurrentSMSMessageError = GE_UNKNOWN;break; - } - } -} - -/* GST_DR and GST_UN not supported ! */ -GSM_Error N6110_SaveSMSMessage(GSM_SMSMessage *SMS) -{ - unsigned char req[256] = { - N6110_FRAME_HEADER, 0x04, /* SMS save request*/ - 0x00, /* SMS Status. Different for Inbox and Outbox */ - 0x02, /* ?? */ - 0x00, /* SMS Location */ - 0x02, /* SMS Type */ - }; - - int length; - SMS_MessageType PDU; - GSM_Error error; - - if (SMS->Location) req[6] = SMS->Location; - - if (SMS->folder==0) { /*Inbox*/ - req[4]=1; /* SMS Status */ - req[7] = 0x00; /* SMS Type */ - PDU=SMS_Deliver; - } else { - req[4]=5; /* SMS Status */ - req[7] = 0x02; /* SMS Type */ - PDU=SMS_Submit; - } - - if (SMS->Status == GSS_NOTSENTREAD) req[4] |= 0x02; - - error=GSM_EncodeNokiaSMSFrame(SMS, req+8, &length, PDU); - if (error != GE_NONE) return error; - - CurrentSMSMessage = SMS; - - return NULL_SendMessageSequence - (70, &CurrentSMSMessageError, 39+length, 0x14, req); -} - -void N6110_ReplySetCellBroadcast(u16 MessageLength, u8 *MessageBuffer, u8 MessageType) { - -#ifdef DEBUG - fprintf(stdout, _("Message: Cell Broadcast enabled/disabled successfully.\n")); fflush (stdout); -#endif - - CurrentCBError = GE_NONE; -} - -/* Enable and disable Cell Broadcasting */ -GSM_Error N6110_EnableCellBroadcast(void) -{ - unsigned char req[] = {N6110_FRAME_HEADER, 0x20, - 0x01, 0x01, 0x00, 0x00, 0x01, 0x01}; - -#ifdef DEBUG - fprintf (stdout,"Enabling CB\n"); -#endif - - CurrentCBMessage = (GSM_CBMessage *)malloc(sizeof (GSM_CBMessage)); - CurrentCBMessage->Channel = 0; - CurrentCBMessage->New = false; - strcpy (CurrentCBMessage->Message,""); - - return NULL_SendMessageSequence - (10, &CurrentCBError, 10, 0x02, req); -} - - -GSM_Error N6110_DisableCellBroadcast(void) -{ - /* Should work, but not tested fully */ - - unsigned char req[] = {N6110_FRAME_HEADER, 0x20, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}; /*VERIFY*/ - - return NULL_SendMessageSequence - (10, &CurrentCBError, 10, 0x02, req); -} - -void N6110_ReplyReadCellBroadcast(u16 MessageLength, u8 *MessageBuffer, u8 MessageType) { - - int i, tmp; - unsigned char output[160]; - - CurrentCBMessage->Channel = MessageBuffer[7]; - CurrentCBMessage->New = true; - tmp=GSM_UnpackEightBitsToSeven(0, MessageBuffer[9], MessageBuffer[9], MessageBuffer+10, output); - -#ifdef DEBUG - fprintf(stdout, _("Message: CB received.\n")); fflush (stdout); - - fprintf(stdout, _("Message: channel number %i\n"),MessageBuffer[7]); - - fflush (stdout); - - for (i=0; iMessage[i] = DecodeWithDefaultAlphabet(output[i]); - } - CurrentCBMessage->Message[i]=0; -} - -GSM_Error N6110_ReadCellBroadcast(GSM_CBMessage *Message) -{ -#ifdef DEBUG - fprintf(stdout,"Reading CB\n"); -#endif - - if (CurrentCBMessage != NULL) - { - if (CurrentCBMessage->New == true) - { -#ifdef DEBUG - fprintf(stdout,"New CB received\n"); -#endif - Message->Channel = CurrentCBMessage->Channel; - strcpy(Message->Message,CurrentCBMessage->Message); - CurrentCBMessage->New = false; - return (GE_NONE); - } - } - return (GE_NONEWCBRECEIVED); -} - -int N6110_MakeCallerGroupFrame(unsigned char *req,GSM_Bitmap Bitmap) -{ - int count=0; - - req[count++]=Bitmap.number; - req[count++]=strlen(Bitmap.text); - memcpy(req+count,Bitmap.text,req[count-1]); - count+=req[count-1]; - req[count++]=Bitmap.ringtone; - - /* Setting for graphic: - 0x00 - Off - 0x01 - On - 0x02 - View Graphics - 0x03 - Send Graphics - 0x04 - Send via IR - You can even set it higher but Nokia phones (my - 6110 at least) will not show you the name of this - item in menu ;-)) Nokia is really joking here. */ - if (Bitmap.enabled) req[count++]=0x01; - else req[count++]=0x00; - - req[count++]=(Bitmap.size+4)>>8; - req[count++]=(Bitmap.size+4)%0xff; - req[count++]=0x00; /* Future extensions! */ - req[count++]=Bitmap.width; - req[count++]=Bitmap.height; - req[count++]=0x01; /* Just BW */ - memcpy(req+count,Bitmap.bitmap,Bitmap.size); - - return count+Bitmap.size; -} - -int N6110_MakeOperatorLogoFrame(unsigned char *req,GSM_Bitmap Bitmap) -{ - int count=0; - - EncodeNetworkCode(req+count, Bitmap.netcode); - count=count+3; - - req[count++]=(Bitmap.size+4)>>8; - req[count++]=(Bitmap.size+4)%0xff; - req[count++]=0x00; /* Infofield */ - req[count++]=Bitmap.width; - req[count++]=Bitmap.height; - req[count++]=0x01; /* Just BW */ - memcpy(req+count,Bitmap.bitmap,Bitmap.size); - - return count+Bitmap.size; -} - -int N6110_MakeStartupLogoFrame(unsigned char *req,GSM_Bitmap Bitmap) -{ - int count=0; - - req[count++]=0x01; - req[count++]=Bitmap.height; - req[count++]=Bitmap.width; - memcpy(req+count,Bitmap.bitmap,Bitmap.size); - - return count+Bitmap.size; -} - -/* Set a bitmap or welcome-note */ -GSM_Error N6110_SetBitmap(GSM_Bitmap *Bitmap) { - - unsigned char req[600] = { N6110_FRAME_HEADER }; - u16 count=3; - u8 textlen; - - int timeout=50; - /* Direct uploading variables */ - GSM_MultiSMSMessage SMS; - unsigned char buffer[1000] = {0x0c,0x01}; - GSM_NetworkInfo NetworkInfo; +#endif /* UCLINUX */ - GSM_Error error; - - /* Uploading with preview */ - if (Bitmap->number==255 && - (Bitmap->type==GSM_OperatorLogo || Bitmap->type==GSM_CallerLogo)) { - GSM_SaveBitmapToSMS(&SMS,Bitmap,false,false); - memcpy(buffer+2,SMS.SMS[0].UDH,SMS.SMS[0].UDH[0]+1); +static void N6110_ReplyGetMemoryStatus(u16 MessageLength, u8 *MessageBuffer, u8 MessageType) { - memcpy(buffer+2+SMS.SMS[0].UDH[0]+1,SMS.SMS[0].MessageText,SMS.SMS[0].Length); + switch (MessageBuffer[3]) { - buffer[2+SMS.SMS[0].UDH[0]+1+SMS.SMS[0].Length]=0x00; + case 0x08: - Protocol->SendMessage(2+SMS.SMS[0].UDH[0]+1+SMS.SMS[0].Length+1, 0x12, buffer); +#ifdef DEBUG + fprintf(stdout, _("Message: Memory status received:\n")); - GSM->GetNetworkInfo(&NetworkInfo); //need to make something - return GE_NONE; //no answer from phone - } - - CurrentSetBitmapError = GE_BUSY; - - switch (Bitmap->type) { - case GSM_WelcomeNoteText: - case GSM_DealerNoteText: - req[count++]=0x18; - req[count++]=0x01; /* Only one block */ - - if (Bitmap->type==GSM_WelcomeNoteText) - req[count++]=0x02; /* Welcome text */ - else - req[count++]=0x03; /* Dealer Welcome Note */ - - textlen=strlen(Bitmap->text); - req[count++]=textlen; - memcpy(req+count,Bitmap->text,textlen); - - count+=textlen; - - Protocol->SendMessage(count, 0x05, req); - - break; - - case GSM_StartupLogo: - if (Bitmap->number==0) { - - /* For 33xx we first set animated logo to default */ - if (GetModelFeature (FN_STARTUP)==F_STANIM) { - error=N6110_SetProfileFeature(0, 0x29, Bitmap->number); - if (error!=GE_NONE) return error; - } - - req[count++]=0x18; - req[count++]=0x01; /* Only one block */ - count=count+N6110_MakeStartupLogoFrame(req+5,*Bitmap); - Protocol->SendMessage(count, 0x05, req); - } else { - return N6110_SetProfileFeature(0, 0x29, Bitmap->number); - } - break; - - case GSM_OperatorLogo: - req[count++]=0x30; /* Store Op Logo */ - req[count++]=0x01; /* Location */ - count=count+N6110_MakeOperatorLogoFrame(req+5,*Bitmap); - Protocol->SendMessage(count, 0x05, req); - break; - - case GSM_CallerLogo: - req[count++]=0x13; - count=count+N6110_MakeCallerGroupFrame(req+4,*Bitmap); - Protocol->SendMessage(count, 0x03, req); - break; - - case GSM_PictureImage: - req[count++]=0x03; - req[count++]=Bitmap->number; - if (strcmp(Bitmap->Sender,"")) { - req[count]=GSM_PackSemiOctetNumber(Bitmap->Sender, req+count+1,true); - - /* Convert number of semioctets to number of chars and add count */ - textlen=req[count]; - if (textlen % 2) textlen++; - count+=textlen / 2 + 1; - - count++; - } else { - req[count++]=0x00; - req[count++]=0x00; - } - req[count++]=0x00; - req[count++]=strlen(Bitmap->text); - memcpy(req+count,Bitmap->text,strlen(Bitmap->text)); - count+=strlen(Bitmap->text); - req[count++]=0x00; - req[count++]=Bitmap->width; - req[count++]=Bitmap->height; - req[count++]=0x01; - memcpy(req+count,Bitmap->bitmap,Bitmap->size); - Protocol->SendMessage(count+Bitmap->size, 0x47, req); - break; - - case GSM_7110OperatorLogo: - case GSM_7110StartupLogo: - case GSM_6210StartupLogo: - return GE_NOTSUPPORTED; - - case GSM_None: - return GE_NONE; - } - - /* Wait for timeout or other error. */ - while (timeout != 0 && CurrentSetBitmapError == GE_BUSY ) { - - if (--timeout == 0) - return (GE_TIMEOUT); - - usleep (100000); - } - - return CurrentSetBitmapError; -} - -/* Get a bitmap from the phone */ -GSM_Error N6110_GetBitmap(GSM_Bitmap *Bitmap) { - - unsigned char req[10] = { N6110_FRAME_HEADER }; - u8 count=3; - - int timeout=100; - - CurrentGetBitmap=Bitmap; - CurrentGetBitmapError = GE_BUSY; - - switch (CurrentGetBitmap->type) { - case GSM_StartupLogo: - case GSM_WelcomeNoteText: - case GSM_DealerNoteText: - req[count++]=0x16; - Protocol->SendMessage(count, 0x05, req); - break; - case GSM_OperatorLogo: - req[count++]=0x33; - req[count++]=0x01; /* Location 1 */ - Protocol->SendMessage(count, 0x05, req); - break; - case GSM_CallerLogo: - req[count++]=0x10; - req[count++]=Bitmap->number; - Protocol->SendMessage(count, 0x03, req); - break; - case GSM_PictureImage: - req[count++]=0x01; - req[count++]=Bitmap->number; - Protocol->SendMessage(count, 0x47, req); - break; - case GSM_7110OperatorLogo: - case GSM_7110StartupLogo: - case GSM_6210StartupLogo: - default: - return GE_NOTSUPPORTED; - } - - /* Wait for timeout or other error. */ - while (timeout != 0 && CurrentGetBitmapError == GE_BUSY ) { - - if (--timeout == 0) - return (GE_TIMEOUT); - - usleep (100000); - } - - CurrentGetBitmap=NULL; - - return CurrentGetBitmapError; -} - -void N6110_ReplySetRingtone(u16 MessageLength, u8 *MessageBuffer, u8 MessageType) { - - switch (MessageBuffer[3]) { - - /* Set ringtone OK */ - case 0x37: -#ifdef DEBUG - fprintf(stdout, _("Message: Ringtone set OK!\n")); -#endif - CurrentRingtoneError=GE_NONE; - break; - - /* Set ringtone error */ - case 0x38: -#ifdef DEBUG - fprintf(stdout, _("Message: Ringtone setting error !\n")); -#endif - CurrentRingtoneError=GE_NOTSUPPORTED; - break; - } -} - -GSM_Error N6110_SetRingTone(GSM_Ringtone *ringtone, int *maxlength) -{ - - char req[FB61_MAX_RINGTONE_FRAME_LENGTH+10] = - {N6110_FRAME_HEADER, - 0x36, - 0x00, /* Location */ - 0x00,0x78}; - - int size=FB61_MAX_RINGTONE_FRAME_LENGTH; - - /* Variables for preview uploading */ - unsigned char buffer[FB61_MAX_RINGTONE_FRAME_LENGTH+50]; - unsigned char buffer2[20]; - GSM_NetworkInfo NetworkInfo; + fprintf(stdout, _(" Memory Type: %s\n"), N6110_MemoryType_String[MessageBuffer[4]]); + fprintf(stdout, _(" Used: %d\n"), MessageBuffer[6]); + fprintf(stdout, _(" Free: %d\n"), MessageBuffer[5]); +#endif /* DEBUG */ - /* Setting ringtone with preview */ - if (ringtone->location==255) { - buffer[0]=0x0c; - buffer[1]=0x01; - EncodeUDHHeader(buffer2, GSM_RingtoneUDH); - memcpy(buffer+2,buffer2,buffer2[0]+1); //copying UDH - *maxlength=GSM_PackRingtone(ringtone, buffer+2+buffer2[0]+1, &size); //packing ringtone - Protocol->SendMessage(2+buffer2[0]+1+size, 0x12, buffer); //sending frame - GSM->GetNetworkInfo(&NetworkInfo); //need to make something - sleep(1); - return GE_NONE; //no answer from phone - } - - *maxlength=GSM_PackRingtone(ringtone, req+7, &size); - - req[4]=ringtone->location-1; - - return NULL_SendMessageSequence - (50, &CurrentRingtoneError, (size+7), 0x05, req); -} - -void N6110_ReplyGetBinRingtone(u16 MessageLength, u8 *MessageBuffer, u8 MessageType) { - - int i; - - switch (MessageBuffer[4]) { - case 0x00: /* location supported. We have ringtone */ - - /* Binary format used in N6150 */ - if (MessageBuffer[5]==0x0c && MessageBuffer[6]==0x01 && MessageBuffer[7]==0x2c) { -#ifdef DEBUG - fprintf(stdout,_("Message: ringtone \"")); -#endif - - /* Copying name */ - i=8; - while (true) { -#ifdef DEBUG - if (MessageBuffer[i]!=0) - fprintf(stdout,_("%c"),MessageBuffer[i]); -#endif - CurrentGetBinRingtone->name[i-8]=MessageBuffer[i]; - if (MessageBuffer[i]==0) break; - i++; - } - -#ifdef DEBUG - fprintf(stdout,_("\" received from location %i\n"),MessageBuffer[3]+1); -#endif - - /* Looking for end */ - i=0; - while (true) { - if (MessageBuffer[i]==0x07 && MessageBuffer[i+1]==0x0b) { - i=i+2;break; - } - if (MessageBuffer[i]==0x0e && MessageBuffer[i+1]==0x0b) { - i=i+2;break; - } - i++; - if (i==MessageLength) break; - } - - /* Copying frame */ - memcpy(CurrentGetBinRingtone->frame,MessageBuffer+3,i-3); - CurrentGetBinRingtone->length=i-3; - - CurrentBinRingtoneError=GE_NONE; - break; - } - - /* Binary format used in N3210 */ - if (MessageBuffer[5]==0x10 && MessageBuffer[6]==0x01 && MessageBuffer[7]==0x2c) { - -#ifdef DEBUG - fprintf(stdout,_("Message: ringtone \"")); -#endif - - /* Copying name */ - i=8; - while (true) { -#ifdef DEBUG - if (MessageBuffer[i]!=0) - fprintf(stdout,_("%c"),MessageBuffer[i]); -#endif - CurrentGetBinRingtone->name[i-8]=MessageBuffer[i]; - if (MessageBuffer[i]==0) break; - i++; - } - -#ifdef DEBUG - fprintf(stdout,_("\" received from location %i\n"),MessageBuffer[3]+1); -#endif - - /* Here changes to get full compatibility with binary format used in N6150 */ - MessageBuffer[3]=0; - MessageBuffer[4]=0; - MessageBuffer[5]=0x0c; - MessageBuffer[6]=0x01; - MessageBuffer[7]=0x2c; - - /* Looking for end */ - i=0; - while (true) { - if (MessageBuffer[i]==0x07 && MessageBuffer[i+1]==0x0b) { - i=i+2;break; - } - if (MessageBuffer[i]==0x0e && MessageBuffer[i+1]==0x0b) { - i=i+2;break; - } - i++; - if (i==MessageLength) break; - } - - /* Copying frame */ - memcpy(CurrentGetBinRingtone->frame,MessageBuffer+3,i-3); - - CurrentGetBinRingtone->length=i-3; - - CurrentBinRingtoneError=GE_NONE; - break; - } - - /* Copying frame */ - memcpy(CurrentGetBinRingtone->frame,MessageBuffer,MessageLength); - - CurrentGetBinRingtone->length=MessageLength; - -#ifdef DEBUG - fprintf(stdout,_("Message: unknown binary format for ringtone received from location %i\n"),MessageBuffer[3]+1); -#endif - CurrentBinRingtoneError=GE_UNKNOWNMODEL; - break; - - default: - -#ifdef DEBUG - fprintf(stdout,_("Message: Phone doesn't support downloaded ringtones at location %i\n"),MessageBuffer[3]+1); -#endif - - CurrentBinRingtoneError=GE_INVALIDRINGLOCATION; - } -} - -GSM_Error N6110_GetBinRingTone(GSM_BinRingtone *ringtone) -{ - unsigned char req[] = { 0x00,0x01,0x9e, - 0x00 }; //location - - GSM_Error error; - - CurrentGetBinRingtone=ringtone; - - error=N6110_EnableExtendedCommands(0x01); - if (error!=GE_NONE) return error; - - req[3]=ringtone->location-1; - - return NULL_SendMessageSequence - (50, &CurrentBinRingtoneError, 4, 0x40, req); -} - -void N6110_ReplySetBinRingtone(u16 MessageLength, u8 *MessageBuffer, u8 MessageType) { - - switch (MessageBuffer[4]) { - case 0x00: /* location supported. We set ringtone */ -#ifdef DEBUG - fprintf(stdout,_("Message: downloaded ringtone set at location %i\n"),MessageBuffer[3]+1); -#endif - CurrentBinRingtoneError=GE_NONE; - break; - - default: -#ifdef DEBUG - fprintf(stdout,_("Message: Phone doesn't support downloaded ringtones at location %i\n"),MessageBuffer[3]+1); -#endif - CurrentBinRingtoneError=GE_NOTSUPPORTED; - break; - } -} - -GSM_Error N6110_SetBinRingTone(GSM_BinRingtone *ringtone) -{ - unsigned char req[1000] = { 0x00,0x01,0xa0}; - - GSM_Error error; - - GSM_BinRingtone ring; - - /* Must be sure, that can upload ringtone to this phone */ - ring.location=ringtone->location; - error=N6110_GetBinRingTone(&ring); - if (error!=GE_NONE) return error; - - error=N6110_EnableExtendedCommands(0x01); - if (error!=GE_NONE) return error; - - memcpy(req+3,ringtone->frame,ringtone->length); - - req[3]=ringtone->location-1; - - return NULL_SendMessageSequence - (50, &CurrentBinRingtoneError, ringtone->length+3, 0x40, req); -} - -GSM_Error N6110_Reset(unsigned char type) -{ - return N6110_EnableExtendedCommands(type); -} - -void N6110_Dispatch0x01Message(u16 MessageLength, u8 *MessageBuffer, u8 MessageType) { - - int tmp, count; - - switch (MessageBuffer[3]) { - - /* Unknown message - it has been seen after the 0x07 message (call - answered). Probably it has similar meaning. If you can solve - this - just mail me. Pavel Janík ml. - - The message looks like this: - - Msg Destination: PC - Msg Source: Phone - Msg Type: 01 - Msg Unknown: 00 - Msg Len: 0e - - Phone: [01 ][08 ][00 ] is the header of the frame - - [03 ] is the call message subtype - - [05 ] is the call sequence number - - [05 ] unknown - - [00 ][01 ][03 ][02 ][91][00] are unknown but has been - seen in the Incoming call message (just after the - caller's name from the phonebook). But never change - between phone calls :-( - */ - - /* This may mean sequence number of 'just made' call - CK */ - case 0x02: - -#ifdef DEBUG - fprintf(stdout, _("Message: Call message, type 0x02:")); - fprintf(stdout, _(" Exact meaning not known yet, sorry :-(\n")); -#endif /* DEBUG */ - - break; - - /* Possibly call OK */ - /* JD: I think that this means "call in progress" (incomming or outgoing) */ - case 0x03: - -#ifdef DEBUG - fprintf(stdout, _("Message: Call message, type 0x03:")); - fprintf(stdout, _(" Sequence nr. of the call: %d\n"), MessageBuffer[4]); - fprintf(stdout, _(" Exact meaning not known yet, sorry :-(\n")); -#endif /* DEBUG */ - - CurrentCallSequenceNumber=MessageBuffer[4]; - CurrentIncomingCall[0]='D'; - if (CurrentCallPassup) CurrentCallPassup('D'); - - break; - - /* Remote end has gone away before you answer the call. Probably your - mother-in-law or banker (which is worse?) ... */ - case 0x04: - -#ifdef DEBUG - fprintf(stdout, _("Message: Remote end hang up.\n")); - fprintf(stdout, _(" Sequence nr. of the call: %d, error: %i"), MessageBuffer[4],MessageBuffer[6]); - - switch (MessageBuffer[6]) { - case 28: fprintf(stdout,_(" (info \"Invalid phone number\")"));break; - case 34: fprintf(stdout,_(" (info \"Network busy\")"));break; - case 42: fprintf(stdout,_(" (info \"Network busy\")"));break; - case 47: fprintf(stdout,_(" (info \"Error in connection\")"));break; - case 50: fprintf(stdout,_(" (info \"Check operator services\")"));break; case 76: fprintf(stdout,_(" (info \"Check operator services\")"));break; - case 111: fprintf(stdout,_(" (info \"Error in connection\")"));break; - } - - fprintf(stdout,_("\n For more details with errors see netmonitor manual (test 39) on www.marcin-wiacek.topnet.pl")); - fprintf(stdout,_("\n If know their meaning, GSM specs decribing them, contact with me on marcin-wiacek@topnet.pl. THX\n")); -#endif /* DEBUG */ - - CurrentIncomingCall[0] = ' '; - if (CurrentCallPassup) CurrentCallPassup(' '); - - break; - - /* Incoming call alert */ - case 0x05: - -#ifdef DEBUG - fprintf(stdout, _("Message: Incoming call alert:\n")); - - /* We can have more then one call ringing - we can distinguish between - them */ - - fprintf(stdout, _(" Sequence nr. of the call: %d\n"), MessageBuffer[4]); - fprintf(stdout, _(" Number: ")); - - count=MessageBuffer[6]; - - for (tmp=0; tmp SendMessage(4, 0x04, connect5); */ - - /* Marcin-Wiacek@TopNet.PL */ - -#ifdef WIN32 - sprintf(Current_IMEI, "%s", MessageBuffer+5); - sprintf(Current_Model, "%s", MessageBuffer+21); - sprintf(Current_Revision, "SW%s, HW%s", MessageBuffer+41, MessageBuffer+35); -#else - snprintf(Current_IMEI, GSM_MAX_IMEI_LENGTH, "%s", MessageBuffer+5); - snprintf(Current_Model, GSM_MAX_MODEL_LENGTH, "%s", MessageBuffer+21); - snprintf(Current_Revision, GSM_MAX_REVISION_LENGTH, "SW%s, HW%s", MessageBuffer+41, MessageBuffer+35); -#endif - -#ifdef DEBUG - fprintf(stdout, _("Message: Mobile phone identification received:\n")); - fprintf(stdout, _(" IMEI: %s\n"), Current_IMEI); - fprintf(stdout, _(" Model: %s\n"), Current_Model); - fprintf(stdout, _(" Production Code: %s\n"), MessageBuffer+27); - fprintf(stdout, _(" HW: %s\n"), MessageBuffer+35); - fprintf(stdout, _(" Firmware: %s\n"), MessageBuffer+41); -#endif /* DEBUG */ - - break; - - /* Get group data */ - /* [ID],[name_len],[name].,[ringtone],[graphicon],[lenhi],[lenlo],[bitmap] */ - case 0x11: - - if (CurrentGetBitmap!=NULL) { - if (CurrentGetBitmap->number==MessageBuffer[4]) { - count=MessageBuffer[5]; - memcpy(CurrentGetBitmap->text,MessageBuffer+6,count); - CurrentGetBitmap->text[count]=0; - -#ifdef DEBUG - fprintf(stdout, _("Message: Caller group datas\n")); - fprintf(stdout, _("Caller group name: %s\n"),CurrentGetBitmap->text); -#endif /* DEBUG */ - - count+=6; - - CurrentGetBitmap->ringtone=MessageBuffer[count++]; -#ifdef DEBUG - fprintf(stdout, _("Caller group ringtone ID: %i"),CurrentGetBitmap->ringtone); - if (CurrentGetBitmap->ringtone==16) fprintf(stdout,_(" (default)")); - fprintf(stdout,_("\n")); -#endif /* DEBUG */ - - CurrentGetBitmap->enabled=(MessageBuffer[count++]==1); -#ifdef DEBUG - fprintf(stdout, _("Caller group logo ")); - if (CurrentGetBitmap->enabled) - fprintf(stdout, _("enabled \n")); - else - fprintf(stdout, _("disabled \n")); -#endif /* DEBUG */ - - CurrentGetBitmap->size=MessageBuffer[count++]<<8; - CurrentGetBitmap->size+=MessageBuffer[count++]; -#ifdef DEBUG - fprintf(stdout, _("Bitmap size=%i\n"),CurrentGetBitmap->size); -#endif /* DEBUG */ - - count++; - CurrentGetBitmap->width=MessageBuffer[count++]; - CurrentGetBitmap->height=MessageBuffer[count++]; - count++; - tmp=CurrentGetBitmap->height*CurrentGetBitmap->width/8; - if (CurrentGetBitmap->size>tmp) CurrentGetBitmap->size=tmp; - memcpy(CurrentGetBitmap->bitmap,MessageBuffer+count,CurrentGetBitmap->size); - CurrentGetBitmapError=GE_NONE; - } else { -#ifdef DEBUG - fprintf(stdout, _("Message: Caller group datas received, but group number does not match (%i is not %i)\n"),MessageBuffer[4],CurrentGetBitmap->number); -#endif - } - } else { -#ifdef DEBUG - fprintf(stdout, _("Message: Caller group data received but not requested!\n")); -#endif - } - break; - - /* Get group data error */ - case 0x12: - - CurrentGetBitmapError=GE_UNKNOWN; -#ifdef DEBUG - fprintf(stdout, _("Message: Error attempting to get caller group data.\n")); -#endif - break; - - /* Set group data OK */ - case 0x14: - - CurrentSetBitmapError=GE_NONE; -#ifdef DEBUG - fprintf(stdout, _("Message: Caller group data set correctly.\n")); -#endif - break; - - /* Set group data error */ - case 0x15: - - CurrentSetBitmapError=GE_UNKNOWN; -#ifdef DEBUG - fprintf(stdout, _("Message: Error attempting to set caller group data\n")); -#endif - break; - - default: - -#ifdef DEBUG - fprintf(stdout, _("Message: Unknown message of type 0x03\n")); -#endif /* DEBUG */ - AppendLogText("Unknown msg\n",false); - - break; /* Visual C Don't like empty cases */ - } -} - -void N6110_Dispatch0x05Message(u16 MessageLength, u8 *MessageBuffer, u8 MessageType) { - - int tmp, count, length; - bool issupported; + CurrentMemoryStatus->Used = MessageBuffer[6]; + CurrentMemoryStatus->Free = MessageBuffer[5]; + CurrentMemoryStatusError = GE_NONE; -#ifdef DEBUG - int i; -#endif + break; - switch (MessageBuffer[3]) { - - /* Startup Logo */ - case 0x17: - -#ifdef DEBUG - fprintf(stdout, _("Message: Startup Logo, welcome note and dealer welcome note received.\n")); -#endif - - if (CurrentGetBitmap!=NULL) { - - issupported=false; - - count=5; - - for (tmp=0;tmptype==GSM_StartupLogo) { - CurrentGetBitmap->height=MessageBuffer[count++]; - CurrentGetBitmap->width=MessageBuffer[count++]; - CurrentGetBitmap->size=CurrentGetBitmap->height*CurrentGetBitmap->width/8; - length=CurrentGetBitmap->size; - memcpy(CurrentGetBitmap->bitmap,MessageBuffer+count,length); - } else { - length=MessageBuffer[count++]; - length=length*MessageBuffer[count++]/8; - } - count+=length; -#ifdef DEBUG - fprintf(stdout, _("Startup logo supported - ")); - if (length!=0) { fprintf(stdout, _("currently set\n")); } - else { fprintf(stdout, _("currently empty\n")); } -#endif - if (CurrentGetBitmap->type==GSM_StartupLogo) issupported=true; - break; - case 0x02: - length=MessageBuffer[count]; - if (CurrentGetBitmap->type==GSM_WelcomeNoteText) { - memcpy(CurrentGetBitmap->text,MessageBuffer+count+1,length); - CurrentGetBitmap->text[length]=0; - } -#ifdef DEBUG - fprintf(stdout, _("Startup Text supported - ")); - if (length!=0) - { - fprintf(stdout, _("currently set to \"")); - for (i=0;itype==GSM_WelcomeNoteText) issupported=true; - break; - case 0x03: - length=MessageBuffer[count]; - if (CurrentGetBitmap->type==GSM_DealerNoteText) { - memcpy(CurrentGetBitmap->text,MessageBuffer+count+1,length); - CurrentGetBitmap->text[length]=0; - } -#ifdef DEBUG - fprintf(stdout, _("Dealer Welcome supported - ")); - if (length!=0) - { - fprintf(stdout, _("currently set to \"")); - for (i=0;itype==GSM_DealerNoteText) issupported=true; - break; - } - } - if (issupported) CurrentGetBitmapError=GE_NONE; - else CurrentGetBitmapError=GE_NOTSUPPORTED; - } else { -#ifdef DEBUG - fprintf(stdout, _("Message: Startup logo received but not requested!\n")); -#endif - } - break; - - /* Set startup OK */ - case 0x19: - - CurrentSetBitmapError=GE_NONE; -#ifdef DEBUG - fprintf(stdout, _("Message: Startup logo, welcome note or dealer welcome note correctly set.\n")); -#endif - break; - - /* Set Operator Logo OK */ - case 0x31: - -#ifdef DEBUG - fprintf(stdout, _("Message: Operator logo correctly set.\n")); -#endif - - CurrentSetBitmapError=GE_NONE; - break; - - /* Set Operator Logo Error */ - case 0x32: - -#ifdef DEBUG - fprintf(stdout, _("Message: Error setting operator logo!\n")); -#endif - - CurrentSetBitmapError=GE_UNKNOWN; - break; - - /* Operator Logo */ - /* [location],[netcode x 3],[lenhi],[lenlo],[bitmap] */ - case 0x34: - - if (CurrentGetBitmap!=NULL) { - - count=5; /* Location ignored. */ - - DecodeNetworkCode(MessageBuffer+count, CurrentGetBitmap->netcode); - count=count+3; - -#ifdef DEBUG - fprintf(stdout, _("Message: Operator Logo for %s (%s) network received.\n"), - CurrentGetBitmap->netcode, - GSM_GetNetworkName(CurrentGetBitmap->netcode)); -#endif - - CurrentGetBitmap->size=MessageBuffer[count++]<<8; - CurrentGetBitmap->size+=MessageBuffer[count++]; - count++; - CurrentGetBitmap->width=MessageBuffer[count++]; - CurrentGetBitmap->height=MessageBuffer[count++]; - count++; - tmp=CurrentGetBitmap->height*CurrentGetBitmap->width/8; - if (CurrentGetBitmap->size>tmp) CurrentGetBitmap->size=tmp; - memcpy(CurrentGetBitmap->bitmap,MessageBuffer+count,CurrentGetBitmap->size); - CurrentGetBitmapError=GE_NONE; - } else { -#ifdef DEBUG - fprintf(stdout, _("Message: Operator logo received but not requested!\n")); -#endif - } - - break; - - /* Get op logo error */ - case 0x35: - -#ifdef DEBUG - fprintf(stdout, _("Message: Error getting operator logo!\n")); -#endif - CurrentGetBitmapError=GE_UNKNOWN; - break; - - default: - -#ifdef DEBUG - fprintf(stdout, _("Message: Unknown message of type 0x05\n")); -#endif /* DEBUG */ - AppendLogText("Unknown msg\n",false); - - break; - } -} - -void N6110_Dispatch0x06Message(u16 MessageLength, u8 *MessageBuffer, u8 MessageType) { - - int tmp; - unsigned char output[160]; + case 0x09: #ifdef DEBUG - int i; + switch (MessageBuffer[4]) { + case 0x6f: + fprintf(stdout, _("Message: Memory status error, phone is probably powered off.\n"));break; + case 0x7d: + fprintf(stdout, _("Message: Memory status error, memory type not supported by phone model.\n"));break; + case 0x8d: + fprintf(stdout, _("Message: Memory status error, waiting for security code.\n"));break; + default: + fprintf(stdout, _("Message: Unknown Memory status error, subtype (MessageBuffer[4]) = %02x\n"),MessageBuffer[4]);break; + } #endif - - switch (MessageBuffer[3]) { - - case 0x05: - - /* MessageBuffer[3] = 0x05 - MessageBuffer[4] = 0x00 - MessageBuffer[5] = 0x0f - MessageBuffer[6] = 0x03 - MessageBuffer[7] = length of packed message - - This is all I have seen - Gerry Anderson */ - - tmp=GSM_UnpackEightBitsToSeven(0, 82, 82, MessageBuffer+8, output); - -#ifdef DEBUG - - fprintf(stdout, _("Message from Network operator: ")); - - for (i=0; iSender,GSM_UnpackSemiOctetNumber(MessageBuffer+5,true)); - - while (MessageBuffer[count]!=0) { - count++; - } - - count++; - } else { - strcpy(CurrentGetBitmap->Sender,"\0"); - - count+=3; - } - - memcpy(CurrentGetBitmap->text,MessageBuffer+count+1,MessageBuffer[count]); - CurrentGetBitmap->text[MessageBuffer[count]]=0; - - if (MessageBuffer[count]!=0) - count+=MessageBuffer[count]; - - count++; - -#ifdef DEBUG - fprintf(stdout,_("Picture Image received, text \"%s\", sender %s\n"),CurrentGetBitmap->text,CurrentGetBitmap->Sender); -#endif - - CurrentGetBitmap->width=MessageBuffer[count+1]; - CurrentGetBitmap->height=MessageBuffer[count+2]; - CurrentGetBitmap->size=CurrentGetBitmap->height*CurrentGetBitmap->width/8; - - memcpy(CurrentGetBitmap->bitmap,MessageBuffer+count+4,CurrentGetBitmap->size); - - CurrentGetBitmapError=GE_NONE; - break; - - case 0x04: - -#ifdef DEBUG - fprintf(stdout,_("Getting or setting Picture Image - OK\n")); -#endif - CurrentSetBitmapError=GE_NONE; - CurrentGetBitmapError=GE_NONE; - break; - - case 0x05: - -#ifdef DEBUG - fprintf(stdout,_("Setting Picture Image - invalid location or other error\n")); -#endif - CurrentSetBitmapError=GE_UNKNOWN; - break; - - case 0x06: - -#ifdef DEBUG - fprintf(stdout,_("Getting Picture Image - invalid location or other error\n")); -#endif - CurrentGetBitmapError=GE_UNKNOWN; - break; - - default: - -#ifdef DEBUG - fprintf(stdout, _("Unknown message of type 0x47.\n")); -#endif /* DEBUG */ - AppendLogText("Unknown msg\n",false); - break; /* Visual C Don't like empty cases */ - } -} - -void N6110_DispatchACKMessage(u16 MessageLength, u8 *MessageBuffer, u8 MessageType) { - char buffer[50]; - - sprintf(buffer,"Received ACK %02x %02x\n",MessageBuffer[0],MessageBuffer[1]); - AppendLog(buffer,strlen(buffer),false); - -#ifdef DEBUG - fprintf(stdout, _("[Received Ack of type %02x, seq: %2x]\n"), MessageBuffer[0], - MessageBuffer[1]); -#endif /* DEBUG */ - - CurrentLinkOK = true; -} - -void N6110_Dispatch0xD0Message(u16 MessageLength, u8 *MessageBuffer, u8 MessageType) { - -#ifdef DEBUG - fprintf(stdout, _("Message: The phone is powered on - seq 1.\n")); -#endif /* DEBUG */ - -} - -/* This function is used for parsing the RLP frame into fields. */ -void N6110_RX_HandleRLPMessage(u8 *MessageBuffer) -{ - - RLP_F96Frame frame; - int count; - int valid = true; - - /* We do not need RLP frame parsing to be done when we do not have callback - specified. */ - if (CurrentRLP_RXCallback == NULL) - exit; - - /* Anybody know the official meaning of the first two bytes? - Nokia 6150 sends junk frames starting D9 01, and real frames starting - D9 00. We'd drop the junk frames anyway because the FCS is bad, but - it's tidier to do it here. We still need to call the callback function - to give it a chance to handle timeouts and/or transmit a frame */ - if (MessageBuffer[0] == 0xd9 && MessageBuffer[1] == 0x01) - valid = false; - - /* Nokia uses 240 bit frame size of RLP frames as per GSM 04.22 - specification, so Header consists of 16 bits (2 bytes). See section 4.1 - of the specification. */ - - frame.Header[0] = MessageBuffer[2]; - frame.Header[1] = MessageBuffer[3]; - - /* Next 200 bits (25 bytes) contain the Information. We store the - information in the Data array. */ - - for (count = 0; count < 25; count ++) - frame.Data[count] = MessageBuffer[4 + count]; - - /* The last 24 bits (3 bytes) contain FCS. */ - - frame.FCS[0] = MessageBuffer[29]; - frame.FCS[1] = MessageBuffer[30]; - frame.FCS[2] = MessageBuffer[31]; - - /* Here we pass the frame down in the input stream. */ - CurrentRLP_RXCallback(valid ? &frame : NULL); -} - -void N6110_Dispatch0xF4Message(u16 MessageLength, u8 *MessageBuffer, u8 MessageType) { - -#ifdef DEBUG - fprintf(stdout, _("Message: The phone is powered on - seq 2.\n")); -#endif /* DEBUG */ - -} - -void N6110_ReplyIncomingSMS(u16 MessageLength, u8 *MessageBuffer, u8 MessageType) { - - GSM_SMSMessage NullSMS; - - switch (MessageBuffer[6]) { - - case 0x00: NullSMS.Type = GST_SMS; NullSMS.folder = GST_INBOX; break; - case 0x01: NullSMS.Type = GST_DR; NullSMS.folder = GST_INBOX; break; - - /* Is it possible ? */ - case 0x02: NullSMS.Type = GST_SMS; NullSMS.folder = GST_OUTBOX; break; - default: NullSMS.Type = GST_UN; break; - } - -#ifdef DEBUG - if (NullSMS.Type == GST_DR) - fprintf(stdout, _("Message: SMS Message (Report) Received\n")); - else - fprintf(stdout, _("Message: SMS Message Received\n")); -#endif /* DEBUG */ - - GSM_DecodeNokiaSMSFrame(&NullSMS, MessageBuffer+7, MessageLength-7); - -#ifdef DEBUG - fprintf(stdout, _("\n")); -#endif /* DEBUG */ -} - -void N6110_DispatchMessage(u16 MessageLength, u8 *MessageBuffer, u8 MessageType) { - bool unknown=false; + switch (MessageBuffer[4]) { + case 0x6f:CurrentMemoryStatusError = GE_TIMEOUT;break; + case 0x7d:CurrentMemoryStatusError = GE_INTERNALERROR;break; + case 0x8d:CurrentMemoryStatusError = GE_INVALIDSECURITYCODE;break; + default:break; + } - /* Switch on the basis of the message type byte */ - switch (MessageType) { - - /* Call information */ - case 0x01: - - N6110_Dispatch0x01Message(MessageLength, MessageBuffer, MessageType); - break; - - /* SMS handling */ - case 0x02: - switch (MessageBuffer[3]) { - case 0x02: - case 0x03:N6110_ReplySendSMSMessage(MessageLength,MessageBuffer,MessageType);break; - case 0x10:N6110_ReplyIncomingSMS(MessageLength,MessageBuffer,MessageType);break; - case 0x21:N6110_ReplySetCellBroadcast(MessageLength, MessageBuffer, MessageType);break; - case 0x23:N6110_ReplyReadCellBroadcast(MessageLength, MessageBuffer, MessageType);break; - case 0x31:N6110_ReplySetSMSCenter(MessageLength,MessageBuffer,MessageType);break; - case 0x34: - case 0x35:N6110_ReplyGetSMSCenter(MessageLength,MessageBuffer,MessageType);break; - default :unknown=true;break; - } - break; - - /* Phonebook handling */ - case 0x03: - switch (MessageBuffer[3]) { - case 0x02: - case 0x03:N6110_ReplyGetMemoryLocation(MessageLength,MessageBuffer,MessageType);break; - case 0x05: - case 0x06:N6110_ReplyWritePhonebookLocation(MessageLength,MessageBuffer,MessageType);break; - case 0x08: - case 0x09:N6110_ReplyGetMemoryStatus(MessageLength,MessageBuffer,MessageType);break; - case 0x17: - case 0x18:N6110_ReplyGetSpeedDial(MessageLength,MessageBuffer,MessageType);break; - case 0x1a: - case 0x1b:N6110_ReplySetSpeedDial(MessageLength,MessageBuffer,MessageType);break; - default :N6110_Dispatch0x03Message(MessageLength,MessageBuffer,MessageType);break; - } - break; - - /* Phone status */ - case 0x04: - switch (MessageBuffer[3]) { - case 0x02:N6110_ReplyRFBatteryLevel(MessageLength,MessageBuffer,MessageType);break; - default :unknown=true;break; - } - break; - - /* Startup Logo, Operator Logo and Profiles. */ - case 0x05: - switch (MessageBuffer[3]) { - case 0x11:N6110_ReplySetProfile (MessageLength,MessageBuffer,MessageType);break; - case 0x14:N6110_ReplyGetProfile (MessageLength,MessageBuffer,MessageType);break; - case 0x1b:N6110_ReplyGetProfile (MessageLength,MessageBuffer,MessageType);break; - case 0x1d:N6110_ReplySetProfile (MessageLength,MessageBuffer,MessageType);break; - case 0x37:N6110_ReplySetRingtone (MessageLength,MessageBuffer,MessageType);break; - case 0x38:N6110_ReplySetRingtone (MessageLength,MessageBuffer,MessageType);break; - default :N6110_Dispatch0x05Message(MessageLength,MessageBuffer,MessageType);break; - } - break; - - /* Network Operator Message to handset -> Gerry Anderson & prepaid info */ - /* Call diverts */ - case 0x06: - switch (MessageBuffer[3]) { - case 0x02: - case 0x03:N6110_ReplyCallDivert (MessageLength,MessageBuffer,MessageType);break; - default :N6110_Dispatch0x06Message(MessageLength,MessageBuffer,MessageType);break; - } - break; - - /* Security code requests */ - case 0x08: - switch (MessageBuffer[3]) { - case 0x08:N6110_ReplyGetSecurityCodeStatus(MessageLength,MessageBuffer,MessageType);break; - case 0x0b:N6110_ReplyEnterSecurityCode (MessageLength,MessageBuffer,MessageType);break; - default :N6110_ReplyEnterSecurityCode (MessageLength,MessageBuffer,MessageType);break; - } - break; - - /* SIM login */ - case 0x09: - - N6110_Dispatch0x09Message(MessageLength, MessageBuffer, MessageType); - break; - - /* Network info */ - case 0x0a: - switch (MessageBuffer[3]) { - case 0x71:N6110_ReplyGetNetworkInfo(MessageLength,MessageBuffer,MessageType);break; - default :unknown=true;break; - } - break; - - /* Simulating key pressing */ - case 0x0c: - switch (MessageBuffer[3]) { - case 0x43:N6110_ReplyPressKey(MessageLength,MessageBuffer,MessageType);break; - default :unknown=true;break; - } - break; - - /* Display */ - case 0x0d: - switch (MessageBuffer[3]) { - case 0x50:N6110_ReplyDisplayOutput (MessageLength,MessageBuffer,MessageType);break; - case 0x52:N6110_ReplyGetDisplayStatus(MessageLength,MessageBuffer,MessageType);break; - case 0x54:N6110_ReplyDisplayOutput (MessageLength,MessageBuffer,MessageType);break; - default :unknown=true;break; - } - break; - - /* Phone Clock and Alarm */ - case 0x11: - switch (MessageBuffer[3]) { - case 0x61:N6110_ReplySetDateTime(MessageLength,MessageBuffer,MessageType);break; - case 0x63:N6110_ReplyGetDateTime(MessageLength,MessageBuffer,MessageType);break; - case 0x6c:N6110_ReplySetAlarm (MessageLength,MessageBuffer,MessageType);break; - case 0x6e:N6110_ReplyGetAlarm (MessageLength,MessageBuffer,MessageType);break; - default :unknown=true;break; - } - break; - - /* Calendar notes handling */ - case 0x13: - switch (MessageBuffer[3]) { - case 0x65:N6110_ReplyWriteCalendarNote (MessageLength,MessageBuffer,MessageType);break; - case 0x67:N6110_ReplyGetCalendarNote (MessageLength,MessageBuffer,MessageType);break; - case 0x69:N6110_ReplyDeleteCalendarNote(MessageLength,MessageBuffer,MessageType);break; - default :N6110_Dispatch0x13Message (MessageLength,MessageBuffer,MessageType);break; - } - break; - - /* SMS Messages */ - case 0x14: - switch (MessageBuffer[3]) { - case 0x05: - case 0x06:N6110_ReplySaveSMSMessage (MessageLength,MessageBuffer,MessageType);break; - case 0x08: - case 0x09:N6110_ReplyGetSMSMessage (MessageLength,MessageBuffer,MessageType);break; - case 0x0b:N6110_ReplyDeleteSMSMessage(MessageLength,MessageBuffer,MessageType);break; - case 0x37: - case 0x38:N6110_ReplyGetSMSStatus (MessageLength,MessageBuffer,MessageType);break; - default :unknown=true;break; - } - break; - - /* WAP */ - case 0x3f: - switch (MessageBuffer[3]) { - case 0x01: - case 0x02:N7110_ReplyEnableWAPCommands(MessageLength,MessageBuffer,MessageType);break; - case 0x07: - case 0x08:N7110_ReplyGetWAPBookmark (MessageLength,MessageBuffer,MessageType);break; - case 0x0a: - case 0x0b:N7110_ReplySetWAPBookmark (MessageLength,MessageBuffer,MessageType);break; - case 0x16: - case 0x17: - case 0x1c:N7110_ReplyGetWAPSettings (MessageLength,MessageBuffer,MessageType);break; - default :unknown=true;break; - } - break; - - /* Internal phone functions? */ - case 0x40: - switch (MessageBuffer[2]) { - case 0x64:N6110_ReplyEnableExtendedCommands (MessageLength,MessageBuffer,MessageType);break; - case 0x65:N6110_ReplyResetPhoneSettings (MessageLength,MessageBuffer,MessageType);break; - case 0x66:N6110_ReplyIMEI (MessageLength,MessageBuffer,MessageType);break; - case 0x6a:N6110_ReplyGetProductProfileSetting(MessageLength,MessageBuffer,MessageType);break; - case 0x6b:N6110_ReplySetProductProfileSetting(MessageLength,MessageBuffer,MessageType);break; - case 0x6e:N6110_ReplyGetSecurityCode (MessageLength,MessageBuffer,MessageType);break; - case 0x7e:N6110_ReplyNetmonitor (MessageLength,MessageBuffer,MessageType);break; - case 0x8a:N6110_ReplySimlockInfo (MessageLength,MessageBuffer,MessageType);break; - case 0x8b:N6110_ReplySetOperatorName (MessageLength,MessageBuffer,MessageType);break; - case 0x8c:N6110_ReplyGetOperatorName (MessageLength,MessageBuffer,MessageType);break; - case 0x8f:N6110_ReplyPlayTone (MessageLength,MessageBuffer,MessageType);break; - case 0x9e:N6110_ReplyGetBinRingtone (MessageLength,MessageBuffer,MessageType);break; - case 0xa0:N6110_ReplySetBinRingtone (MessageLength,MessageBuffer,MessageType);break; - case 0xc8:N6110_ReplyHW (MessageLength,MessageBuffer,MessageType);break; - default :N6110_Dispatch0x40Message (MessageLength,MessageBuffer,MessageType);break; - } - break; - - /* Picture Images */ - case 0x47: - - N6110_Dispatch0x47Message(MessageLength, MessageBuffer, MessageType); - break; - - /* Mobile phone identification */ - case 0x64: - - N6110_ReplyGetAuthentication(MessageLength, MessageBuffer, MessageType); - break; - - /***** Acknowlegment of our frames. *****/ - case FBUS_FRTYPE_ACK: - - N6110_DispatchACKMessage(MessageLength, MessageBuffer, MessageType); - break; - - /***** Power on message. *****/ - case 0xd0: - - N6110_Dispatch0xD0Message(MessageLength, MessageBuffer, MessageType); - break; - - case 0xd2: - - N6110_ReplyID(MessageLength, MessageBuffer, MessageType); - break; - - /***** RLP frame received. *****/ - case 0xf1: - - N6110_RX_HandleRLPMessage(MessageBuffer); - break; - - /***** Power on message. *****/ - case 0xf4: - - N6110_Dispatch0xF4Message(MessageLength, MessageBuffer, MessageType); - break; - - /***** Unknown message *****/ - /* If you think that you know the exact meaning of other messages - please - let us know. */ - default: - -#ifdef DEBUG - fprintf(stdout, _("Message: Unknown message type.\n")); -#endif /* DEBUG */ - AppendLogText("Unknown msg type\n",false); - - unknown=false; - break; - - } - - if (unknown) { -#ifdef DEBUG - fprintf(stdout, _("Unknown message of type %02x.\n"),MessageType); -#endif - AppendLogText("Unknown msg\n",false); - } -} + break; + + } +} + +/* This function is used to get storage status from the phone. It currently + supports two different memory areas - internal and SIM. */ +GSM_Error N6110_GetMemoryStatus(GSM_MemoryStatus *Status) +{ + unsigned char req[] = { N6110_FRAME_HEADER, + 0x07, /* MemoryStatus request */ + 0x00 /* MemoryType */ + }; + + GSM_Error error; + + CurrentMemoryStatus = Status; + + req[4] = N6110_GetMemoryType(Status->MemoryType); + + error=NULL_SendMessageSequence + (20, &CurrentMemoryStatusError, 5, 0x03, req); + + CurrentMemoryStatus = NULL; + + return error; +} + +#ifndef UCLINUX + +void N6110_ReplyGetNetworkInfo(u16 MessageLength, u8 *MessageBuffer, u8 MessageType) { + + GSM_NetworkInfo NullNetworkInfo; + + /* Make sure we are expecting NetworkInfo frame */ + if (CurrentNetworkInfo && CurrentNetworkInfoError == GE_BUSY) { +#ifdef DEBUG + fprintf(stdout, _("Message: Network informations:\n")); +#endif + } else { +#ifdef DEBUG + fprintf(stdout, _("Message: Network informations not requested, but received:\n")); +#endif + } + + sprintf(NullNetworkInfo.NetworkCode, "%x%x%x %x%x", MessageBuffer[14] & 0x0f, MessageBuffer[14] >>4, MessageBuffer[15] & 0x0f, MessageBuffer[16] & 0x0f, MessageBuffer[16] >>4); + + sprintf(NullNetworkInfo.CellID, "%02x%02x", MessageBuffer[10], MessageBuffer[11]); + + sprintf(NullNetworkInfo.LAC, "%02x%02x", MessageBuffer[12], MessageBuffer[13]); + +#ifdef DEBUG + fprintf(stdout, _(" CellID: %s\n"), NullNetworkInfo.CellID); + fprintf(stdout, _(" LAC: %s\n"), NullNetworkInfo.LAC); + fprintf(stdout, _(" Network code: %s\n"), NullNetworkInfo.NetworkCode); + fprintf(stdout, _(" Network name: %s (%s)\n"), + GSM_GetNetworkName(NullNetworkInfo.NetworkCode), + GSM_GetCountryName(NullNetworkInfo.NetworkCode)); + fprintf(stdout, _(" Status: ")); + + switch (MessageBuffer[8]) { + case 0x01: fprintf(stdout, _("home network selected")); break; + case 0x02: fprintf(stdout, _("roaming network")); break; + case 0x03: fprintf(stdout, _("requesting network")); break; + case 0x04: fprintf(stdout, _("not registered in the network")); break; + default: fprintf(stdout, _("unknown")); + } + + fprintf(stdout, "\n"); + + fprintf(stdout, _(" Network selection: %s\n"), MessageBuffer[9]==1?_("manual"):_("automatic")); +#endif /* DEBUG */ + + /* Make sure we are expecting NetworkInfo frame */ + if (CurrentNetworkInfo && CurrentNetworkInfoError == GE_BUSY) + *CurrentNetworkInfo=NullNetworkInfo; + + CurrentNetworkInfoError = GE_NONE; +} + +GSM_Error N6110_GetNetworkInfo(GSM_NetworkInfo *NetworkInfo) +{ + unsigned char req[] = { N6110_FRAME_HEADER, + 0x70 + }; + + GSM_Error error; + + CurrentNetworkInfo = NetworkInfo; + + error=NULL_SendMessageSequence + (20, &CurrentNetworkInfoError, 4, 0x0a, req); + + CurrentNetworkInfo = NULL; + + return error; +} + +void N6110_ReplyGetProductProfileSetting(u16 MessageLength, u8 *MessageBuffer, u8 MessageType) { + + int i; + +#ifdef DEBUG + fprintf(stdout, _("Message: Product Profile Settings received -")); + for (i=0;i<4;i++) fprintf(stdout, _(" %02x"),MessageBuffer[3+i]); + fprintf(stdout, _("\n")); +#endif + + for (i=0;i<4;i++) CurrentPPS[i]=MessageBuffer[3+i]; + + CurrentProductProfileSettingsError=GE_NONE; +} + +GSM_Error N6110_GetProductProfileSetting (GSM_PPS *PPS) +{ + unsigned char req[] = { 0x00, 0x01,0x6a }; + + int i,j; + + GSM_Error error; + + error=N6110_EnableExtendedCommands(0x01); + if (error!=GE_NONE) return error; + + error=NULL_SendMessageSequence + (20, &CurrentProductProfileSettingsError, 3, 0x40, req); + if (error!=GE_NONE) return error; + + switch (PPS->Name) { + case PPS_ALS : PPS->bool_value=(CurrentPPS[1]&32); break; + case PPS_GamesMenu: PPS->bool_value=(CurrentPPS[3]&64); break; + case PPS_HRData : PPS->bool_value=(CurrentPPS[0]&64); break; + case PPS_14400Data: PPS->bool_value=(CurrentPPS[0]&128);break; + case PPS_EFR : PPS->int_value =(CurrentPPS[0]&1) +(CurrentPPS[0]&2); break; + case PPS_FR : PPS->int_value =(CurrentPPS[0]&16)/16+(CurrentPPS[0]&32)/16;break; + case PPS_HR : PPS->int_value =(CurrentPPS[0]&4)/4 +(CurrentPPS[0]&8)/4; break; + case PPS_VibraMenu: PPS->bool_value=(CurrentPPS[4]&64); break; + case PPS_LCDContrast: + PPS->int_value=0; + j=1; + for (i=0;i<5;i++) { + if (CurrentPPS[3]&j) PPS->int_value=PPS->int_value+j; + j=j*2; + } + PPS->int_value=PPS->int_value*100/32; + break; + + } + + return (GE_NONE); +} + +void N6110_ReplySetProductProfileSetting(u16 MessageLength, u8 *MessageBuffer, u8 MessageType) { + +#ifdef DEBUG + int i; + + fprintf(stdout, _("Message: Product Profile Settings set to")); + for (i=0;i<4;i++) fprintf(stdout, _(" %02x"),CurrentPPS[i]); + fprintf(stdout, _("\n")); +#endif + + CurrentProductProfileSettingsError=GE_NONE; +} + +GSM_Error N6110_SetProductProfileSetting (GSM_PPS *PPS) +{ + unsigned char req[] = { 0x00, 0x01,0x6b, + 0x00, 0x00, 0x00, 0x00 }; /* bytes with Product Profile Setings */ + unsigned char settings[32]; + + GSM_PPS OldPPS; + + int i,j,z; + + GSM_Error error; + + error=N6110_EnableExtendedCommands(0x01); + if (error!=GE_NONE) return error; + + OldPPS.Name=PPS_ALS; + error=N6110_GetProductProfileSetting(&OldPPS); + if (error!=GE_NONE) return error; + + j=128;z=0; + for (i=0;i<32;i++) { + if (CurrentPPS[z]&j) + settings[i]='1'; + else + settings[i]='0'; + if (j==1) { + j=128; + z++; + } else j=j/2; + } + +#ifdef DEBUG + fprintf(stdout,_("Current settings: ")); + for (i=0;i<32;i++) { + fprintf(stdout,_("%c"),settings[i]); + } + fprintf(stdout,_("\n")); +#endif + + switch (PPS->Name) { + case PPS_ALS :settings[10]=PPS->bool_value?'1':'0';break; + case PPS_HRData :settings[ 5]=PPS->bool_value?'1':'0';break; + case PPS_14400Data:settings[ 6]=PPS->bool_value?'1':'0';break; + default :break; + } + + j=128;z=0; + for (i=0;i<32;i++) { + if (settings[i]=='1') req[z+3]=req[z+3]+j; + if (j==1) { + j=128; + z++; + } else j=j/2; + } + +#ifdef DEBUG + fprintf(stdout,_("Current settings: ")); + for (i=0;i<4;i++) { + fprintf(stdout,_("%i "),req[i+3]); + } + fprintf(stdout,_("\n")); +#endif + + for (i=0;i<4;i++) { + CurrentPPS[i]=req[i+3]; + } + + return NULL_SendMessageSequence + (20, &CurrentProductProfileSettingsError, 7, 0x40, req); +} + +void N6110_ReplyPressKey(u16 MessageLength, u8 *MessageBuffer, u8 MessageType) { + + if (MessageBuffer[4]==CurrentPressKeyEvent) CurrentPressKeyError=GE_NONE; + else CurrentPressKeyError=GE_UNKNOWN; /* MessageBuffer[4] = 0x05 */ +#ifdef DEBUG + fprintf(stdout, _("Message: Result of key ")); + switch (MessageBuffer[4]) + { + case PRESSPHONEKEY: fprintf(stdout, _("press OK\n"));break; + case RELEASEPHONEKEY: fprintf(stdout, _("release OK\n"));break; + default: fprintf(stdout, _("press or release - error\n"));break; + } +#endif /* DEBUG */ +} + +GSM_Error N6110_PressKey(int key, int event) +{ + unsigned char req[] = {N6110_FRAME_HEADER, 0x42, 0x01, 0x00, 0x01}; + + req[4]=event; /* if we press or release key */ + req[5]=key; + + CurrentPressKeyEvent=event; + + return NULL_SendMessageSequence + (10, &CurrentPressKeyError, 7, 0x0c, req); +} + +void N6110_ReplyDisplayOutput(u16 MessageLength, u8 *MessageBuffer, u8 MessageType) { + + /* Hopefully is 64 larger as FB38_MAX* / N6110_MAX* */ + char model[64]; + + int i, j; + + char uni[100]; + + switch(MessageBuffer[3]) { + + /* Phone sends displayed texts */ + case 0x50: + NewX=MessageBuffer[6]; + NewY=MessageBuffer[5]; + + DecodeUnicode (uni, MessageBuffer+8, MessageBuffer[7]); + +#ifdef DEBUG + fprintf(stdout, _("New displayed text (%i %i): \"%s\"\n"),NewX,NewY,uni); +#endif /* DEBUG */ + + while (N6110_GetModel(model) != GE_NONE) + sleep(1); + + /* With these rules it works almost excellent with my N5110 */ + /* I don't have general rule :-(, that's why you must experiment */ + /* with your phone. Nokia could make it better. MW */ + /* It's almost OK for N5110*/ + /* FIX ME: it will be the same for N5130 and 3210 too*/ + if (!strcmp(model,"NSE-1")) + { + /* OldX==1000 means - it's first time */ + if (OldX==1000) { + + /* Clean table */ + for (i=0;i<5+1;i++) { + for (j=0;j<27+1;j++) {PhoneScreen[i][j]=' ';} + } + OldX=0; + } + + if ((OldX==0 && OldY==31 && NewX==29 && NewY==46) || + (OldX==0 && OldY==13 && NewX==23 && NewY==46)) { + /* Clean the line with current text */ + for (j=0;j<27+1;j++) {PhoneScreen[NewY/(47/5)][j]=' ';} + + /* Inserts text into table */ + for (i=0; iSendMessage(sizeof(req0), 0x01, req0); + sleep(1); + + return NULL_SendMessageSequence + (20, &CurrentMagicError, sizeof(req) , 0x01, req); +} + +void N6110_ReplyGetProfile(u16 MessageLength, u8 *MessageBuffer, u8 MessageType) { + + switch (MessageBuffer[3]) { + + /* Profile feature */ + case 0x14: + + switch(GetModelFeature (FN_PROFILES)) { + case F_PROF33: + switch (MessageBuffer[6]) { + case 0x00: CurrentProfile->KeypadTone = MessageBuffer[8]; break; + case 0x01: CurrentProfile->CallAlert = MessageBuffer[8]; break; + case 0x02: CurrentProfile->Ringtone = MessageBuffer[8]; break; + case 0x03: CurrentProfile->Volume = MessageBuffer[8]; break; + case 0x04: CurrentProfile->MessageTone = MessageBuffer[8]; break; + case 0x05: CurrentProfile->Vibration = MessageBuffer[8]; break; + case 0x06: CurrentProfile->WarningTone = MessageBuffer[8]; break; + case 0x07: CurrentProfile->ScreenSaver = MessageBuffer[8]; break; + default: +#ifdef DEBUG + fprintf(stdout,_("feature %i = value %i\n\n"),MessageBuffer[6],MessageBuffer[8]); +#endif + break; + } + break; + default: + switch (MessageBuffer[6]) { + case 0x00: CurrentProfile->KeypadTone = MessageBuffer[8];break; + case 0x01: CurrentProfile->Lights = MessageBuffer[8];break; + case 0x02: CurrentProfile->CallAlert = MessageBuffer[8];break; + case 0x03: CurrentProfile->Ringtone = MessageBuffer[8];break; + case 0x04: CurrentProfile->Volume = MessageBuffer[8];break; + case 0x05: CurrentProfile->MessageTone = MessageBuffer[8];break; + case 0x06: CurrentProfile->Vibration = MessageBuffer[8];break; + case 0x07: CurrentProfile->WarningTone = MessageBuffer[8];break; + case 0x08: CurrentProfile->CallerGroups = MessageBuffer[8];break; + case 0x09: CurrentProfile->AutomaticAnswer = MessageBuffer[8];break; + default: +#ifdef DEBUG + fprintf(stdout,_("feature %i = value %i\n\n"),MessageBuffer[6],MessageBuffer[8]); +#endif + break; + } + break; + } + + CurrentProfileError = GE_NONE; + break; + + /* Incoming profile name */ + case 0x1b: + + if (MessageBuffer[9] == 0x00) { + CurrentProfile->DefaultName=MessageBuffer[8]; + } else { + CurrentProfile->DefaultName=-1; + + /* Here name is in Unicode */ + if (GetModelFeature (FN_PROFILES)==F_PROF33) { + DecodeUnicode (CurrentProfile->Name, MessageBuffer+10, MessageBuffer[9]/2); + } else { + /* ...here not */ + sprintf(CurrentProfile->Name, MessageBuffer + 10, MessageBuffer[9]); + CurrentProfile->Name[MessageBuffer[9]] = '\0'; + } + } + + CurrentProfileError = GE_NONE; + break; + + } +} + +/* Needs SIM card with PIN in phone */ +GSM_Error N6110_GetProfile(GSM_Profile *Profile) +{ + int i; + + unsigned char name_req[] = { N6110_FRAME_HEADER, 0x1a, 0x00}; + unsigned char feat_req[] = { N6110_FRAME_HEADER, 0x13, 0x01, 0x00, 0x00}; + + GSM_Error error; + + CurrentProfile = Profile; + + /* When after sending all frames feature==253, it means, that it is not + supported */ + CurrentProfile->KeypadTone=253; + CurrentProfile->Lights=253; + CurrentProfile->CallAlert=253; + CurrentProfile->Ringtone=253; + CurrentProfile->Volume=253; + CurrentProfile->MessageTone=253; + CurrentProfile->WarningTone=253; + CurrentProfile->Vibration=253; + CurrentProfile->CallerGroups=253; + CurrentProfile->ScreenSaver=253; + CurrentProfile->AutomaticAnswer=253; + + name_req[4] = Profile->Number; + + error=NULL_SendMessageSequence + (20, &CurrentProfileError, 5, 0x05, name_req); + if (error!=GE_NONE) return error; + + for (i = 0x00; i <= 0x09; i++) { + + feat_req[5] = Profile->Number; + + feat_req[6] = i; + + error=NULL_SendMessageSequence + (20, &CurrentProfileError, 7, 0x05, feat_req); + if (error!=GE_NONE) return error; + } + + if (Profile->DefaultName > -1) + { + switch(GetModelFeature (FN_PROFILES)) { + case F_PROF33: + switch (Profile->DefaultName) { + case 0x00: sprintf(Profile->Name, "General");break; + case 0x01: sprintf(Profile->Name, "Silent");break; + case 0x02: sprintf(Profile->Name, "Descreet");break; + case 0x03: sprintf(Profile->Name, "Loud");break; + case 0x04: sprintf(Profile->Name, "My style");break; + case 0x05: Profile->Name[0]=0;break; + default : sprintf(Profile->Name, "Unknown (%i)", Profile->DefaultName);break; + } + break; + case F_PROF51: + switch (Profile->DefaultName) { + case 0x00: sprintf(Profile->Name, "Personal");break; + case 0x01: sprintf(Profile->Name, "Car");break; + case 0x02: sprintf(Profile->Name, "Headset");break; + default : sprintf(Profile->Name, "Unknown (%i)", Profile->DefaultName);break; + } + break; + case F_PROF61: + switch (Profile->DefaultName) { + case 0x00: sprintf(Profile->Name, "General");break; + case 0x01: sprintf(Profile->Name, "Silent");break; + case 0x02: sprintf(Profile->Name, "Meeting");break; + case 0x03: sprintf(Profile->Name, "Outdoor");break; + case 0x04: sprintf(Profile->Name, "Pager");break; + case 0x05: sprintf(Profile->Name, "Car");break; + case 0x06: sprintf(Profile->Name, "Headset");break; + default : sprintf(Profile->Name, "Unknown (%i)", Profile->DefaultName);break; + } + break; + } + } + + return (GE_NONE); + +} + +void N6110_ReplySetProfile(u16 MessageLength, u8 *MessageBuffer, u8 MessageType) { + + switch (MessageBuffer[3]) { + + /* Profile feature change result */ + case 0x11: +#ifdef DEBUG + fprintf(stdout, _("Message: Profile feature change result.\n")); +#endif /* DEBUG */ + CurrentProfileError = GE_NONE; + break; + + /* Profile name set result */ + case 0x1d: +#ifdef DEBUG + fprintf(stdout, _("Message: Profile name change result.\n")); +#endif /* DEBUG */ + CurrentProfileError = GE_NONE; + break; + + } +} + +GSM_Error N6110_SetProfileFeature(u8 profile, u8 feature, u8 value) +{ + unsigned char feat_req[] = { N6110_FRAME_HEADER, 0x10, 0x01, + 0x00, 0x00, 0x00}; + + feat_req[5]=profile; + feat_req[6]=feature; + feat_req[7]=value; + + return NULL_SendMessageSequence + (20, &CurrentProfileError, 8, 0x05, feat_req); +} + +GSM_Error N6110_SetProfile(GSM_Profile *Profile) +{ + int i,value; + + unsigned char name_req[40] = { N6110_FRAME_HEADER, 0x1c, 0x01, 0x03, + 0x00, 0x00, 0x00}; + + GSM_Error error; + + name_req[7] = Profile->Number; + name_req[8] = strlen(Profile->Name); + name_req[6] = name_req[8] + 2; + + for (i = 0; i < name_req[8]; i++) + name_req[9 + i] = Profile->Name[i]; + + error=NULL_SendMessageSequence + (20, &CurrentProfileError, name_req[8] + 9, 0x05, name_req); + if (error!=GE_NONE) return error; + + for (i = 0x00; i <= 0x09; i++) { + + switch (i) { + case 0x00: value = Profile->KeypadTone; break; + case 0x01: value = Profile->Lights; break; + case 0x02: value = Profile->CallAlert; break; + case 0x03: value = Profile->Ringtone; break; + case 0x04: value = Profile->Volume; break; + case 0x05: value = Profile->MessageTone; break; + case 0x06: value = Profile->Vibration; break; + case 0x07: value = Profile->WarningTone; break; + case 0x08: value = Profile->CallerGroups; break; + case 0x09: value = Profile->AutomaticAnswer; break; + default : value = 0; break; + } + + error=N6110_SetProfileFeature(Profile->Number,i,value); + if (error!=GE_NONE) return error; + } + + return (GE_NONE); +} + +bool N6110_SendRLPFrame(RLP_F96Frame *frame, bool out_dtx) +{ + u8 req[60] = { 0x00, 0xd9 }; + + /* Discontinuos transmission (DTX). See section 5.6 of GSM 04.22 version + 7.0.1. */ + + if (out_dtx) + req[1]=0x01; + + memcpy(req+2, (u8 *) frame, 32); + + return (Protocol->SendFrame(32, 0xf0, req)); +} + +void N6110_ReplyGetCalendarNote(u16 MessageLength, u8 *MessageBuffer, u8 MessageType) { + + int i, j; + + u8 mychar1; + + wchar_t wc; + + switch (MessageBuffer[4]) { + + case 0x01: + + CurrentCalendarNote->Type=MessageBuffer[8]; + + DecodeDateTime(MessageBuffer+9, &CurrentCalendarNote->Time); + + DecodeDateTime(MessageBuffer+16, &CurrentCalendarNote->Alarm); + + CurrentCalendarNote->Text[0]=0; + + if (GetModelFeature (FN_CALENDAR)==F_CAL33) { + i=0; + if (CurrentCalendarNote->Type == GCN_REMINDER) i=1; //first char is subset + switch (MessageBuffer[24]) { + case 3: +#ifdef DEBUG + fprintf(stdout,_("Subset 3 in reminder note !\n")); +#endif + while (i!=MessageBuffer[23]) { + j=0; + if (i!=MessageBuffer[23]-1) { + if (MessageBuffer[24+i]>=0xc2) { + DecodeWithUTF8Alphabet(MessageBuffer[24+i], MessageBuffer[24+i+1], &mychar1); + CurrentCalendarNote->Text[strlen(CurrentCalendarNote->Text)+1]=0; + CurrentCalendarNote->Text[strlen(CurrentCalendarNote->Text)]=mychar1; + j=-1; + i++; + } + } + if (j!=-1) { + CurrentCalendarNote->Text[strlen(CurrentCalendarNote->Text)+1]=0; + CurrentCalendarNote->Text[strlen(CurrentCalendarNote->Text)]=MessageBuffer[24+i]; + } + i++; + } + break; + case 2: +#ifdef DEBUG + fprintf(stdout,_("Subset 2 in reminder note !\n")); +#endif + while (i!=MessageBuffer[23]) { + wc = MessageBuffer[24+i] | (0x00 << 8); + CurrentCalendarNote->Text[strlen(CurrentCalendarNote->Text)+1]=0; + CurrentCalendarNote->Text[strlen(CurrentCalendarNote->Text)]= + DecodeWithUnicodeAlphabet(wc); + i++; + } + break; + case 1: +#ifdef DEBUG + fprintf(stdout,_("Subset 1 in reminder note !\n")); +#endif + memcpy(CurrentCalendarNote->Text,MessageBuffer+24+i,MessageBuffer[23]-i); + CurrentCalendarNote->Text[MessageBuffer[23]-i]=0; + break; + default: +#ifdef DEBUG + fprintf(stdout,_("Unknown subset in reminder note !\n")); +#endif + memcpy(CurrentCalendarNote->Text,MessageBuffer+24+i,MessageBuffer[23]-i); + CurrentCalendarNote->Text[MessageBuffer[23]-i]=0; + break; + } + } else { + memcpy(CurrentCalendarNote->Text,MessageBuffer+24,MessageBuffer[23]); + CurrentCalendarNote->Text[MessageBuffer[23]]=0; + } + + if (CurrentCalendarNote->Type == GCN_CALL) { + memcpy(CurrentCalendarNote->Phone,MessageBuffer+24+MessageBuffer[23]+1,MessageBuffer[24+MessageBuffer[23]]); + CurrentCalendarNote->Phone[MessageBuffer[24+MessageBuffer[23]]]=0; + } + + CurrentCalendarNote->Recurrance=0; + + CurrentCalendarNote->AlarmType=0; + +#ifdef DEBUG + fprintf(stdout, _("Message: Calendar note received.\n")); + + fprintf(stdout, _(" Date: %d-%02d-%02d\n"), CurrentCalendarNote->Time.Year, + CurrentCalendarNote->Time.Month, + CurrentCalendarNote->Time.Day); + + fprintf(stdout, _(" Time: %02d:%02d:%02d\n"), CurrentCalendarNote->Time.Hour, + CurrentCalendarNote->Time.Minute, + CurrentCalendarNote->Time.Second); + + /* Some messages do not have alarm set up */ + if (CurrentCalendarNote->Alarm.Year != 0) { + fprintf(stdout, _(" Alarm date: %d-%02d-%02d\n"), CurrentCalendarNote->Alarm.Year, + CurrentCalendarNote->Alarm.Month, + CurrentCalendarNote->Alarm.Day); + + fprintf(stdout, _(" Alarm time: %02d:%02d:%02d\n"), CurrentCalendarNote->Alarm.Hour, + CurrentCalendarNote->Alarm.Minute, + CurrentCalendarNote->Alarm.Second); + } + + fprintf(stdout, _(" Type: %d\n"), CurrentCalendarNote->Type); + fprintf(stdout, _(" Text: %s\n"), CurrentCalendarNote->Text); + + if (CurrentCalendarNote->Type == GCN_CALL) + fprintf(stdout, _(" Phone: %s\n"), CurrentCalendarNote->Phone); +#endif /* DEBUG */ + + CurrentCalendarNoteError=GE_NONE; + break; + + case 0x93: + +#ifdef DEBUG + fprintf(stdout, _("Message: Calendar note not available\n")); +#endif /* DEBUG */ + + CurrentCalendarNoteError=GE_INVALIDCALNOTELOCATION; + break; + + default: + +#ifdef DEBUG + fprintf(stdout, _("Message: Calendar note error\n")); +#endif /* DEBUG */ + + CurrentCalendarNoteError=GE_INTERNALERROR; + break; + + } +} + +GSM_Error N6110_GetCalendarNote(GSM_CalendarNote *CalendarNote) +{ + + unsigned char req[] = { N6110_FRAME_HEADER, + 0x66, 0x00 + }; + GSM_Error error; + + req[4]=CalendarNote->Location; + + CurrentCalendarNote = CalendarNote; + + error=NULL_SendMessageSequence + (20, &CurrentCalendarNoteError, 5, 0x13, req); + + CurrentCalendarNote = NULL; + + return error; +} + +void N6110_ReplyWriteCalendarNote(u16 MessageLength, u8 *MessageBuffer, u8 MessageType) { + +#ifdef DEBUG + switch(MessageBuffer[4]) { + /* This message is also sent when the user enters the new entry on keypad */ + case 0x01: + fprintf(stdout, _("Message: Calendar note write succesfull!\n"));break; + case 0x73: + fprintf(stdout, _("Message: Calendar note write failed!\n"));break; + case 0x7d: + fprintf(stdout, _("Message: Calendar note write failed!\n"));break; + default: + fprintf(stdout, _("Unknown message of type 0x13 and subtype 0x65\n"));break; + } +#endif + + switch(MessageBuffer[4]) { + case 0x01: CurrentCalendarNoteError=GE_NONE; break; + case 0x73: CurrentCalendarNoteError=GE_INTERNALERROR; break; + case 0x7d: CurrentCalendarNoteError=GE_INTERNALERROR; break; + default : AppendLogText("Unknown msg\n",false); break; + } +} + +GSM_Error N6110_WriteCalendarNote(GSM_CalendarNote *CalendarNote) +{ + + unsigned char req[200] = { N6110_FRAME_HEADER, + 0x64, 0x01, 0x10, + 0x00, /* Length of the rest of the frame. */ + 0x00, /* The type of calendar note */ + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 + }; + + typedef struct { + char *model; + unsigned char call; + unsigned char meeting; + unsigned char birthday; + unsigned char reminder; + } calendar_model_length; + + /* Length of entries */ + calendar_model_length calendar_lengths[] = + { + /*model,CallTo,Meeting,Birthday,Reminder*/ + {"NHM-5",0x24,0x24,0x24,0x24}, //Reminder from phone, other quesses + {"NHM-6",0x24,0x24,0x24,0x24}, //Reminder from phone, other quesses + {"NSE-3",0x1e,0x14,0x14,0x1e}, //from NCDS3 [HKEY_LOCAL_MACHINE\Software\Nokia\Data Suite\3.0\Calendar] + {"NSM-1",0x1e,0x18,0x18,0x24}, //from NCDS3 + {"NSK-3",0x1e,0x14,0x14,0x1e}, //from NCDS3 + {"NSB-3",0x20,0x14,0x14,0x1e}, //from NCDS3 + {"", 0, 0, 0, 0 } //end of table + }; + + int i, j, current; + + u8 mychar; + + u8 mychar1,mychar2; + + GSM_Error error; + + /* Hopefully is 64 larger as FB38_MAX* / N6110_MAX* */ + char model[64]; + + req[7]=CalendarNote->Type; + + EncodeDateTime(req+8, &CalendarNote->Time); + req[14] = CalendarNote->Time.Timezone; + + if (CalendarNote->Alarm.Year) { + EncodeDateTime(req+15, &CalendarNote->Alarm); + req[21] = CalendarNote->Alarm.Timezone; + } + + req[22]=strlen(CalendarNote->Text); + + current=23; + + if (GetModelFeature (FN_CALENDAR)==F_CAL33 && CalendarNote->Type==GCN_REMINDER) { + req[22]++; // one additional char + req[current++]=0x01; //we use now subset 1 + } + + for (i=0; iText); i++) { + j=0; + mychar=CalendarNote->Text[i]; + if (GetModelFeature (FN_CALENDAR)==F_CAL33 && CalendarNote->Type==GCN_REMINDER) { + if (EncodeWithUTF8Alphabet(mychar,&mychar1,&mychar2)) { + req[current++]=mychar1; + req[current++]=mychar2; + req[23]=0x03; //use subset 3 + req[22]++; // one additional char + j=-1; + } + } + if (j!=-1) { + /* Enables/disables blinking */ + if (mychar=='~') req[current++]=0x01; + else req[current++]=mychar; + } + } + + req[current++]=strlen(CalendarNote->Phone); + + for (i=0; iPhone); i++) + req[current++]=CalendarNote->Phone[i]; + + while (N6110_GetModel(model) != GE_NONE) + sleep(1); + + /* Checking maximal length */ + i=0; + while (strcmp(calendar_lengths[i].model,"")) { + if (!strcmp(calendar_lengths[i].model,model)) { + switch (CalendarNote->Type) { + case GCN_REMINDER:if (req[22]>calendar_lengths[i].reminder) return GE_TOOLONG;break; + case GCN_MEETING :if (req[22]>calendar_lengths[i].meeting) return GE_TOOLONG;break; + case GCN_BIRTHDAY:if (req[22]>calendar_lengths[i].birthday) return GE_TOOLONG;break; + case GCN_CALL :if (strlen(CalendarNote->Phone)>calendar_lengths[i].call) return GE_TOOLONG;break; + } + break; + } + i++; + } + + CurrentCalendarNote = CalendarNote; + + error=NULL_SendMessageSequence + (20, &CurrentCalendarNoteError, current, 0x13, req); + + CurrentCalendarNote = NULL; + + return error; +} + +void N6110_ReplyDeleteCalendarNote(u16 MessageLength, u8 *MessageBuffer, u8 MessageType) { + +#ifdef DEBUG + switch (MessageBuffer[4]) { + /* This message is also sent when the user deletes an old entry on + keypad or moves an old entry somewhere (there is also `write' + message). */ + case 0x01:fprintf(stdout, _("Message: Calendar note deleted\n"));break; + case 0x93:fprintf(stdout, _("Message: Calendar note can't be deleted\n"));break; + default :fprintf(stdout, _("Message: Calendar note deleting error\n"));break; + } +#endif + + switch (MessageBuffer[4]) { + case 0x01:CurrentCalendarNoteError=GE_NONE;break; + case 0x93:CurrentCalendarNoteError=GE_INVALIDCALNOTELOCATION;break; + default :CurrentCalendarNoteError=GE_INTERNALERROR;break; + } +} + +GSM_Error N6110_DeleteCalendarNote(GSM_CalendarNote *CalendarNote) +{ + + unsigned char req[] = { N6110_FRAME_HEADER, + 0x68, 0x00 + }; + + req[4]=CalendarNote->Location; + + return NULL_SendMessageSequence (20, &CurrentCalendarNoteError, 5, 0x13, req); +} + +#endif /* UCLINUX */ + +static void N6110_ReplyRFBatteryLevel(u16 MessageLength, u8 *MessageBuffer, u8 MessageType) { + +#ifdef DEBUG + fprintf(stdout, _("Message: Phone status received:\n")); + fprintf(stdout, _(" Mode: ")); + + switch (MessageBuffer[4]) { + + case 0x01: + + fprintf(stdout, _("registered within the network\n")); + break; + + /* I was really amazing why is there a hole in the type of 0x02, now I + know... */ + case 0x02: fprintf(stdout, _("call in progress\n")); break; /* ringing or already answered call */ + case 0x03: fprintf(stdout, _("waiting for security code\n")); break; + case 0x04: fprintf(stdout, _("powered off\n")); break; + default : fprintf(stdout, _("unknown\n")); + + } + + fprintf(stdout, _(" Power source: ")); + + switch (MessageBuffer[7]) { + + case 0x01: fprintf(stdout, _("AC/DC\n")); break; + case 0x02: fprintf(stdout, _("battery\n")); break; + default : fprintf(stdout, _("unknown\n")); + + } + + fprintf(stdout, _(" Battery Level: %d\n"), MessageBuffer[8]); + fprintf(stdout, _(" Signal strength: %d\n"), MessageBuffer[5]); +#endif /* DEBUG */ + + CurrentRFLevel=MessageBuffer[5]; + CurrentBatteryLevel=MessageBuffer[8]; + CurrentPowerSource=MessageBuffer[7]; +} + + +GSM_Error N6110_GetRFLevel(GSM_RFUnits *units, float *level) +{ + + /* FIXME - these values are from 3810 code, may be incorrect. Map from + values returned in status packet to the the values returned by the AT+CSQ + command. */ + float csq_map[5] = {0, 8, 16, 24, 31}; + + int timeout=10; + int rf_level; + + char screen[NM_MAX_SCREEN_WIDTH]; + + CurrentRFLevel=-1; + + if (GetModelFeature (FN_NOPOWERFRAME)==F_NOPOWER) { + +#ifndef UCLINUX + if (N6110_NetMonitor(1, screen)!=GE_NONE) + return GE_INTERNALERROR; +#endif /* UCLINUX */ + + rf_level=4; + + if (screen[4]!='-') { + if (screen[5]=='9' && screen[6]>'4') rf_level=1; + if (screen[5]=='9' && screen[6]<'5') rf_level=2; + if (screen[5]=='8' && screen[6]>'4') rf_level=3; + } else rf_level=0; + + /* Arbitrary units. */ + if (*units == GRF_Arbitrary) { + *level = rf_level; + return (GE_NONE); + } + + } else { + N6110_SendStatusRequest(); + + /* Wait for timeout or other error. */ + while (timeout != 0 && CurrentRFLevel == -1 ) { + + if (--timeout == 0) + return (GE_TIMEOUT); + + usleep (100000); + } + + /* Make copy in case it changes. */ + rf_level = CurrentRFLevel; + + if (rf_level == -1) + return (GE_NOLINK); + + /* Now convert between the different units we support. */ + + /* Arbitrary units. */ + if (*units == GRF_Arbitrary) { + *level = rf_level; + return (GE_NONE); + } + + /* CSQ units. */ + if (*units == GRF_CSQ) { + + if (rf_level <=4) + *level = csq_map[rf_level]; + else + *level = 99; /* Unknown/undefined */ + + return (GE_NONE); + } + } + + /* Unit type is one we don't handle so return error */ + return (GE_INTERNALERROR); +} + + +GSM_Error N6110_GetBatteryLevel(GSM_BatteryUnits *units, float *level) +{ + int timeout=10; + int batt_level; + + char screen[NM_MAX_SCREEN_WIDTH]; + + CurrentBatteryLevel=-1; + + if (GetModelFeature (FN_NOPOWERFRAME)==F_NOPOWER) { + +#ifndef UCLINUX + if (N6110_NetMonitor(23, screen)!=GE_NONE) + return GE_NOLINK; +#endif /* UCLINUX */ + + batt_level=4; + + if (screen[29]=='7') batt_level=3; + if (screen[29]=='5') batt_level=2; + if (screen[29]=='2') batt_level=1; + + /* Only units we handle at present are GBU_Arbitrary */ + if (*units == GBU_Arbitrary) { + *level = batt_level; + return (GE_NONE); + } + + return (GE_INTERNALERROR); + + } else { + N6110_SendStatusRequest(); + + /* Wait for timeout or other error. */ + while (timeout != 0 && CurrentBatteryLevel == -1 ) { + + if (--timeout == 0) + return (GE_TIMEOUT); + + usleep (100000); + } + + /* Take copy in case it changes. */ + batt_level = CurrentBatteryLevel; + + if (batt_level != -1) { + + /* Only units we handle at present are GBU_Arbitrary */ + if (*units == GBU_Arbitrary) { + *level = batt_level; + return (GE_NONE); + } + + return (GE_INTERNALERROR); + } + else + return (GE_NOLINK); + } +} + +GSM_Error N6110_GetPowerSource(GSM_PowerSource *source) +{ + + int timeout=10; + + char screen[NM_MAX_SCREEN_WIDTH]; + + CurrentPowerSource=-1; + + if (GetModelFeature (FN_NOPOWERFRAME)==F_NOPOWER) { + +#ifndef UCLINUX + if (N6110_NetMonitor(20, screen)!=GE_NONE) + return GE_NOLINK; +#endif /* UCLINUX */ + + CurrentPowerSource=GPS_ACDC; + + if (screen[6]=='x') CurrentPowerSource=GPS_BATTERY; + + *source=CurrentPowerSource; + + return GE_NONE; + } else { + N6110_SendStatusRequest(); + + /* Wait for timeout or other error. */ + while (timeout != 0 && CurrentPowerSource == -1 ) { + + if (--timeout == 0) + return (GE_TIMEOUT); + + usleep (100000); + } + + if (CurrentPowerSource != -1) { + *source=CurrentPowerSource; + return (GE_NONE); + } + else + return (GE_NOLINK); + } +} + +#ifndef UCLINUX + +static void N6110_ReplyGetDisplayStatus(u16 MessageLength, u8 *MessageBuffer, u8 MessageType) { + + int i; + + for (i=0; iSendMessage(sizeof(req3), 0x01, req3); + Protocol->SendMessage(sizeof(req4), 0x01, req4); + req_end = req_end1; + size = sizeof(req_end1); + break; + case -1: /* Just used to set the call passup */ + return GE_NONE; + break; + default: + req_end = req_end0; + size = sizeof(req_end0); + break; + } + + req[4] = strlen(Number); + + for(i = 0; i < strlen(Number) ; i++) + req[5+i] = Number[i]; + + memcpy(req + 5 + strlen(Number), req_end, size); + + Protocol->SendMessage(5 + size + strlen(Number), 0x01, req); + if (type != 1) Protocol->SendMessage(26, 0x01, req2); + + return (GE_NONE); +} + +#ifndef UCLINUX + +GSM_Error N6110_GetIncomingCallNr(char *Number) +{ + + if (*CurrentIncomingCall != ' ') { + strcpy(Number, CurrentIncomingCall); + return GE_NONE; + } + else + return GE_BUSY; +} + +#endif /* UCLINUX */ + +GSM_Error N6110_CancelCall(void) +{ +// This frame & method works only on 61xx/51xx +// unsigned char req[] = { N6110_FRAME_HEADER, 0x08, 0x00, 0x85}; +// req[4]=CurrentCallSequenceNumber; +// Protocol->SendMessage(6, 0x01, req); +// return GE_NONE; + + GSM_Error error; + + unsigned char req[]={0x00,0x01,0x7c,0x03}; + + /* Checking */ + error=N6110_EnableExtendedCommands(0x01); + if (error!=GE_NONE) return error; + + return NULL_SendMessageSequence (20, &CurrentDialVoiceError, 4, 0x40, req); +} + +#ifndef UCLINUX + +void N6110_ReplyEnterSecurityCode(u16 MessageLength, u8 *MessageBuffer, u8 MessageType) { + + switch(MessageBuffer[3]) { + + case 0x0b: +#ifdef DEBUG + fprintf(stdout, _("Message: Security code accepted.\n")); +#endif /* DEBUG */ + CurrentSecurityCodeError = GE_NONE; + break; + + default: +#ifdef DEBUG + fprintf(stdout, _("Message: Security code is wrong. You're not my big owner :-)\n")); +#endif /* DEBUG */ + CurrentSecurityCodeError = GE_INVALIDSECURITYCODE; + } +} + +GSM_Error N6110_EnterSecurityCode(GSM_SecurityCode SecurityCode) +{ + + unsigned char req[15] = { N6110_FRAME_HEADER, + 0x0a, /* Enter code request. */ + 0x00 /* Type of the entered code. */ + }; + int i=0; + + req[4]=SecurityCode.Type; + + for (i=0; iType==MessageBuffer[3] /* We wanted this code */ + && MessageBuffer[4]==1) { /* It's allowed */ + if (MessageBuffer[3]==GSCT_SecurityCode) { + for (i=0;i<5;i++) {CurrentSecurityCode->Code[i]=MessageBuffer[5+i];} + CurrentSecurityCode->Code[5]=0; + } + if (MessageBuffer[3]==GSCT_Pin || MessageBuffer[3]==GSCT_Pin2 || + MessageBuffer[3]==GSCT_Puk || MessageBuffer[3]==GSCT_Puk2) { + for (i=0;i<4;i++) {CurrentSecurityCode->Code[i]=MessageBuffer[5+i];} + CurrentSecurityCode->Code[4]=0; + } + CurrentSecurityCodeError=GE_NONE; + } else + CurrentSecurityCodeError=GE_INVALIDSECURITYCODE; +} + +GSM_Error N6110_GetSecurityCode(GSM_SecurityCode *SecurityCode) +{ + + unsigned char req[4] = { 0x00, + 0x01,0x6e, /* Get code request. */ + 0x00 }; /* Type of the requested code. */ + + GSM_Error error; + + error=N6110_EnableExtendedCommands(0x01); + if (error!=GE_NONE) return error; + + req[3]=SecurityCode->Type; + + CurrentSecurityCode=SecurityCode; + + return NULL_SendMessageSequence + (20, &CurrentSecurityCodeError, 4, 0x40, req); +} + +void N6110_ReplyPlayTone(u16 MessageLength, u8 *MessageBuffer, u8 MessageType) { + +#ifdef DEBUG + fprintf(stdout, _("Message: answer for PlayTone frame\n")); +#endif + + CurrentPlayToneError=GE_NONE; +} + +GSM_Error N6110_PlayTone(int Herz, u8 Volume) +{ + unsigned char req[6] = { 0x00,0x01,0x8f, + 0x00, /* Volume */ + 0x00, /* HerzLo */ + 0x00 }; /* HerzHi */ + + GSM_Error error; + + /* PlayTone wasn't used earlier */ + if (CurrentPlayToneError==GE_UNKNOWN) { + if (CurrentConnectionType!=GCT_MBUS) + CurrentDisableKeepAlive=true; + + error=N6110_EnableExtendedCommands(0x01); + if (error!=GE_NONE) return error; + } + + /* For Herz==255*255 we have silent */ + if (Herz!=255*255) { + req[3]=Volume; + + req[5]=Herz%256; + req[4]=Herz/256; + } else { + req[3]=0; + + req[5]=0; + req[4]=0; + } + +#ifdef WIN32 + /* For Herz==255*255 we have silent and additionaly + we wait for phone answer - it's important for MBUS */ + if (Herz==255*255) { + error=NULL_SendMessageSequence + (20, &CurrentPlayToneError, 6, 0x40, req); + + CurrentPlayToneError=GE_UNKNOWN; + CurrentDisableKeepAlive=false; + + if (error!=GE_NONE) return error; + } else { + Protocol->SendMessage(6,0x40,req); + } +#else + error=NULL_SendMessageSequence + (20, &CurrentPlayToneError, 6, 0x40, req); + + /* For Herz==255*255 we wait for phone answer - it's important for MBUS */ + if (Herz==255*255) { + CurrentPlayToneError=GE_UNKNOWN; + CurrentDisableKeepAlive=false; + } + + if (error!=GE_NONE) return error; + +#endif + + return(GE_NONE); +} + +void N6110_ReplyGetDateTime(u16 MessageLength, u8 *MessageBuffer, u8 MessageType) { + + if (MessageBuffer[4]==0x01) { + DecodeDateTime(MessageBuffer+8, CurrentDateTime); + +#ifdef DEBUG + fprintf(stdout, _("Message: Date and time\n")); + fprintf(stdout, _(" Time: %02d:%02d:%02d\n"), CurrentDateTime->Hour, CurrentDateTime->Minute, CurrentDateTime->Second); + fprintf(stdout, _(" Date: %4d/%02d/%02d\n"), CurrentDateTime->Year, CurrentDateTime->Month, CurrentDateTime->Day); +#endif /* DEBUG */ + + CurrentDateTime->IsSet=true; + } else { + +#ifdef DEBUG + fprintf(stdout, _("Message: Date and time not set in phone\n")); +#endif + + CurrentDateTime->IsSet=false; + } + + CurrentDateTimeError=GE_NONE; +} + +GSM_Error N6110_GetDateTime(GSM_DateTime *date_time) +{ + return N6110_PrivGetDateTime(date_time,0x11); +} + +GSM_Error N6110_PrivGetDateTime(GSM_DateTime *date_time, int msgtype) +{ + unsigned char req[] = {N6110_FRAME_HEADER, 0x62}; + + CurrentDateTime=date_time; + + return NULL_SendMessageSequence + (50, &CurrentDateTimeError, 4, msgtype, req); +} + +void N6110_ReplyGetAlarm(u16 MessageLength, u8 *MessageBuffer, u8 MessageType) { + +#ifdef DEBUG + fprintf(stdout, _("Message: Alarm\n")); + fprintf(stdout, _(" Alarm: %02d:%02d\n"), MessageBuffer[9], MessageBuffer[10]); + fprintf(stdout, _(" Alarm is %s\n"), (MessageBuffer[8]==2) ? _("on"):_("off")); +#endif /* DEBUG */ + + CurrentAlarm->Hour=MessageBuffer[9]; + CurrentAlarm->Minute=MessageBuffer[10]; + CurrentAlarm->Second=0; + + CurrentAlarm->IsSet=(MessageBuffer[8]==2); + + CurrentAlarmError=GE_NONE; +} + +GSM_Error N6110_GetAlarm(int alarm_number, GSM_DateTime *date_time) +{ + return N6110_PrivGetAlarm(alarm_number,date_time,0x11); +} + +GSM_Error N6110_PrivGetAlarm(int alarm_number, GSM_DateTime *date_time, int msgtype) +{ + unsigned char req[] = {N6110_FRAME_HEADER, 0x6d}; + + CurrentAlarm=date_time; + + return NULL_SendMessageSequence + (50, &CurrentAlarmError, 4, msgtype, req); +} + +void N6110_ReplyGetSMSCenter(u16 MessageLength, u8 *MessageBuffer, u8 MessageType) { + + switch (MessageBuffer[3]) { + + case 0x34: + + CurrentMessageCenter->No=MessageBuffer[4]; + CurrentMessageCenter->Format=MessageBuffer[6]; + CurrentMessageCenter->Validity=MessageBuffer[8]; + sprintf(CurrentMessageCenter->Name, "%s", MessageBuffer+33); + + sprintf(CurrentMessageCenter->DefaultRecipient, "%s", GSM_UnpackSemiOctetNumber(MessageBuffer+9,false)); + + sprintf(CurrentMessageCenter->Number, "%s", GSM_UnpackSemiOctetNumber(MessageBuffer+21,false)); + +#ifdef DEBUG + fprintf(stdout, _("Message: SMS Center received:\n")); + fprintf(stdout, _(" %d. SMS Center name is %s\n"), CurrentMessageCenter->No, CurrentMessageCenter->Name); + fprintf(stdout, _(" SMS Center number is %s\n"), CurrentMessageCenter->Number); + fprintf(stdout, _(" Default recipient number is %s\n"), CurrentMessageCenter->DefaultRecipient); + + fprintf(stdout, _(" SMS Center message format is ")); + + switch (CurrentMessageCenter->Format) { + + case GSMF_Text : fprintf(stdout, _("Text")); break; + case GSMF_Paging: fprintf(stdout, _("Paging")); break; + case GSMF_Fax : fprintf(stdout, _("Fax")); break; + case GSMF_Email : fprintf(stdout, _("Email")); break; + default : fprintf(stdout, _("Unknown")); + } + + fprintf(stdout, "\n"); + + fprintf(stdout, _(" SMS Center message validity is ")); + + switch (CurrentMessageCenter->Validity) { + + case GSMV_1_Hour : fprintf(stdout, _("1 hour")); break; + case GSMV_6_Hours : fprintf(stdout, _("6 hours")); break; + case GSMV_24_Hours: fprintf(stdout, _("24 hours")); break; + case GSMV_72_Hours: fprintf(stdout, _("72 hours")); break; + case GSMV_1_Week : fprintf(stdout, _("1 week")); break; + case GSMV_Max_Time: fprintf(stdout, _("Maximum time"));break; + default : fprintf(stdout, _("Unknown")); + } + + fprintf(stdout, "\n"); + +#endif /* DEBUG */ + + CurrentMessageCenterError=GE_NONE; + + break; + + case 0x35: + + /* Number of entries depends on SIM card */ + +#ifdef DEBUG + fprintf(stdout, _("Message: SMS Center error received:\n")); + fprintf(stdout, _(" The request for SMS Center failed.\n")); +#endif /* DEBUG */ + + /* FIXME: appropriate error. */ + CurrentMessageCenterError=GE_INTERNALERROR; + + break; + + } +} + +/* This function sends to the mobile phone a request for the SMS Center */ +GSM_Error N6110_GetSMSCenter(GSM_MessageCenter *MessageCenter) +{ + unsigned char req[] = { N6110_FRAME_HEADER, 0x33, 0x64, + 0x00 /* SMS Center Number. */ + }; + + req[5]=MessageCenter->No; + + CurrentMessageCenter=MessageCenter; + + return NULL_SendMessageSequence + (50, &CurrentMessageCenterError, 6, 0x02, req); +} + +void N6110_ReplySetSMSCenter(u16 MessageLength, u8 *MessageBuffer, u8 MessageType) { + +#ifdef DEBUG + fprintf(stdout, _("Message: SMS Center correctly set.\n")); +#endif + CurrentMessageCenterError=GE_NONE; +} + +/* This function set the SMS Center profile on the phone. */ +GSM_Error N6110_SetSMSCenter(GSM_MessageCenter *MessageCenter) +{ + unsigned char req[64] = { N6110_FRAME_HEADER, 0x30, 0x64, + 0x00, /* SMS Center Number. */ + 0x00, /* Unknown. */ + 0x00, /* SMS Message Format. */ + 0x00, /* Unknown. */ + 0x00, /* Validity. */ + 0,0,0,0,0,0,0,0,0,0,0,0, /* Default recipient number */ + 0,0,0,0,0,0,0,0,0,0,0,0 /* Message Center Number. */ + /* Message Center Name. */ + }; + + req[5]=MessageCenter->No; + req[7]=MessageCenter->Format; + req[9]=MessageCenter->Validity; + + req[10]=GSM_PackSemiOctetNumber(MessageCenter->DefaultRecipient, req+11, false); + + req[22]=GSM_PackSemiOctetNumber(MessageCenter->Number, req+23, false); + + sprintf(req+34, "%s", MessageCenter->Name); + + CurrentMessageCenter=MessageCenter; + + return NULL_SendMessageSequence + (50, &CurrentMessageCenterError, 35+strlen(MessageCenter->Name), 0x02, req); +} + +void N6110_ReplyGetSMSStatus(u16 MessageLength, u8 *MessageBuffer, u8 MessageType) { + + switch (MessageBuffer[3]) { + + case 0x37: + +#ifdef DEBUG + fprintf(stdout, _("Message: SMS Status Received\n")); + fprintf(stdout, _(" The number of messages: %d\n"), MessageBuffer[10]); + fprintf(stdout, _(" Unread messages: %d\n"), MessageBuffer[11]); +#endif /* DEBUG */ + + CurrentSMSStatus->UnRead = MessageBuffer[11]; + CurrentSMSStatus->Number = MessageBuffer[10]; + + CurrentSMSStatusError = GE_NONE; + break; + + case 0x38: + +#ifdef DEBUG + fprintf(stdout, _("Message: SMS Status error, probably not authorized by PIN\n")); +#endif /* DEBUG */ + + CurrentSMSStatusError = GE_INTERNALERROR; + break; + + } +} + +GSM_Error N6110_GetSMSStatus(GSM_SMSStatus *Status) +{ + unsigned char req[] = {N6110_FRAME_HEADER, 0x36, 0x64}; + + CurrentSMSStatus = Status; + + return NULL_SendMessageSequence + (10, &CurrentSMSStatusError, 5, 0x14, req); +} + +GSM_Error N6110_GetSMSFolders ( GSM_SMSFolders *folders) +{ + folders->number=2; + + strcpy(folders->Folder[0].Name,"Inbox"); + strcpy(folders->Folder[1].Name,"Outbox"); + + return GE_NONE; +} + +GSM_Error N6110_GetIMEI(char *imei) +{ + if (strlen(Current_IMEI)>0) { + strncpy (imei, Current_IMEI, GSM_MAX_IMEI_LENGTH); + return (GE_NONE); + } + else + return (GE_TRYAGAIN); +} + +GSM_Error N6110_GetRevision(char *revision) +{ + + if (strlen(Current_Revision)>0) { + strncpy (revision, Current_Revision, GSM_MAX_REVISION_LENGTH); + return (GE_NONE); + } + else + return (GE_TRYAGAIN); +} + +#endif /* UCLINUX */ + +static GSM_Error N6110_GetModel(char *model) +{ + if (strlen(Current_Model)>0) { + strncpy (model, Current_Model, GSM_MAX_MODEL_LENGTH); + return (GE_NONE); + } + else + return (GE_TRYAGAIN); +} + +#ifndef UCLINUX + +void N6110_ReplySetDateTime(u16 MessageLength, u8 *MessageBuffer, u8 MessageType) { + + switch (MessageBuffer[4]) { + + case 0x01: +#ifdef DEBUG + fprintf(stdout, _("Message: Date and time set correctly\n")); +#endif /* DEBUG */ + CurrentSetDateTimeError=GE_NONE; + break; + + default: +#ifdef DEBUG + fprintf(stdout, _("Message: Date and time setting error\n")); +#endif /* DEBUG */ + CurrentSetDateTimeError=GE_INVALIDDATETIME; + + } +} + +/* Needs SIM card with PIN in phone */ +GSM_Error N6110_SetDateTime(GSM_DateTime *date_time) +{ + return N6110_PrivSetDateTime(date_time,0x11); +} + +/* Needs SIM card with PIN in phone */ +GSM_Error N6110_PrivSetDateTime(GSM_DateTime *date_time, int msgtype) +{ + + unsigned char req[] = { N6110_FRAME_HEADER, + 0x60, /* set-time subtype */ + 0x01, 0x01, 0x07, /* unknown */ + 0x00, 0x00, /* Year (0x07cf = 1999) */ + 0x00, 0x00, /* Month Day */ + 0x00, 0x00, /* Hours Minutes */ + 0x00 /* Unknown, but not seconds - try 59 and wait 1 sec. */ + }; + + EncodeDateTime(req+7, date_time); + + return NULL_SendMessageSequence + (20, &CurrentSetDateTimeError, 14, msgtype, req); +} + +void N6110_ReplySetAlarm(u16 MessageLength, u8 *MessageBuffer, u8 MessageType) { + + switch (MessageBuffer[4]) { + + case 0x01: +#ifdef DEBUG + fprintf(stdout, _("Message: Alarm set correctly\n")); +#endif /* DEBUG */ + CurrentSetAlarmError=GE_NONE; + break; + + default: +#ifdef DEBUG + fprintf(stdout, _("Message: Alarm setting error\n")); +#endif /* DEBUG */ + CurrentSetAlarmError=GE_INVALIDDATETIME; + + } +} + +/* FIXME: we should also allow to set the alarm off :-) */ +GSM_Error N6110_SetAlarm(int alarm_number, GSM_DateTime *date_time) +{ + return N6110_PrivSetAlarm(alarm_number,date_time, 0x11); +} + +/* FIXME: we should also allow to set the alarm off :-) */ +GSM_Error N6110_PrivSetAlarm(int alarm_number, GSM_DateTime *date_time, int msgtype) +{ + + unsigned char req[] = { N6110_FRAME_HEADER, + 0x6b, /* set-alarm subtype */ + 0x01, 0x20, 0x03, /* unknown */ + 0x02, /* should be alarm on/off, but it don't works */ + 0x00, 0x00, /* Hours Minutes */ + 0x00 /* Unknown, but not seconds - try 59 and wait 1 sec. */ + }; + + req[8] = date_time->Hour; + req[9] = date_time->Minute; + + return NULL_SendMessageSequence + (50, &CurrentSetAlarmError, 11, msgtype, req); +} + +#endif /* UCLINUX */ + +static void N6110_ReplyGetMemoryLocation(u16 MessageLength, u8 *MessageBuffer, u8 MessageType) { + + /* Hopefully is 64 larger as FB38_MAX* / N6110_MAX* */ + char model[64]; + + int i, tmp, count; + + switch (MessageBuffer[3]) { + + case 0x02: + + CurrentPhonebookEntry->Empty = true; + + count=MessageBuffer[5]; + +#ifdef DEBUG + fprintf(stdout, _("Message: Phonebook entry received:\n")); + fprintf(stdout, _(" Name: ")); + + for (tmp=0; tmp Name, MessageBuffer+6, count/2); + CurrentPhonebookEntry->Name[count/2] = 0x00; + } else { + memcpy(CurrentPhonebookEntry->Name, MessageBuffer + 6, count); + CurrentPhonebookEntry->Name[count] = 0x00; + } + + CurrentPhonebookEntry->Empty = false; + + for (tmp=0; tmp Name[tmp/2]='~'; //enables/disables blinking + if (tmp%2!=0 && MessageBuffer[6+tmp]==0) CurrentPhonebookEntry->Name[tmp/2]='`'; //hides rest ot contents + } else { + if (MessageBuffer[6+tmp]==1) CurrentPhonebookEntry->Name[tmp]='~'; //enables/disables blinking + if (MessageBuffer[6+tmp]==0) CurrentPhonebookEntry->Name[tmp]='`'; //hides rest ot contents + } + } + + i=7+count; + count=MessageBuffer[6+count]; + +#ifdef DEBUG + fprintf(stdout, _(" Number: ")); + + for (tmp=0; tmp Number, MessageBuffer + i, count); + CurrentPhonebookEntry->Number[count] = 0x00; + CurrentPhonebookEntry->Group = MessageBuffer[i+count]; + + /* Phone doesn't have entended phonebook */ + CurrentPhonebookEntry->SubEntriesCount = 0; + + /* But for these memories data is saved and we can save it using 7110/6210 style */ + if (CurrentPhonebookEntry->MemoryType==GMT_DC || + CurrentPhonebookEntry->MemoryType==GMT_RC || + CurrentPhonebookEntry->MemoryType==GMT_MC) { + CurrentPhonebookEntry->SubEntriesCount = 1; + CurrentPhonebookEntry->SubEntries[0].EntryType=N7110_ENTRYTYPE_DATE; + CurrentPhonebookEntry->SubEntries[0].NumberType=0; + CurrentPhonebookEntry->SubEntries[0].BlockNumber=1; + DecodeDateTime(MessageBuffer+(i+count+2),&CurrentPhonebookEntry->SubEntries[0].data.Date); + +#ifdef DEBUG + fprintf(stdout, _(" Date: ")); + fprintf(stdout, "%02u.%02u.%04u\n", + CurrentPhonebookEntry->SubEntries[0].data.Date.Day, + CurrentPhonebookEntry->SubEntries[0].data.Date.Month, + CurrentPhonebookEntry->SubEntries[0].data.Date.Year); + fprintf(stdout, _(" Time: ")); + fprintf(stdout, "%02u:%02u:%02u\n", + CurrentPhonebookEntry->SubEntries[0].data.Date.Hour, + CurrentPhonebookEntry->SubEntries[0].data.Date.Minute, + CurrentPhonebookEntry->SubEntries[0].data.Date.Second); +#endif /* DEBUG */ + + /* These values are set, when date and time unavailable in phone. + Values from 3310 - in other can be different */ + if (CurrentPhonebookEntry->SubEntries[0].data.Date.Day==20 && + CurrentPhonebookEntry->SubEntries[0].data.Date.Month==1 && + CurrentPhonebookEntry->SubEntries[0].data.Date.Year==2118 && + CurrentPhonebookEntry->SubEntries[0].data.Date.Hour==3 && + CurrentPhonebookEntry->SubEntries[0].data.Date.Minute==14 && + CurrentPhonebookEntry->SubEntries[0].data.Date.Second==7) + CurrentPhonebookEntry->SubEntriesCount = 0; + } + + /* Signal no error to calling code. */ + CurrentPhonebookError = GE_NONE; + + break; + + case 0x03: + +#ifdef DEBUG + fprintf(stdout, _("Message: Phonebook read entry error received:\n")); +#endif /* DEBUG */ + + switch (MessageBuffer[4]) { + + case 0x7d: +#ifdef DEBUG + fprintf(stdout, _(" Invalid memory type!\n")); +#endif /* DEBUG */ + CurrentPhonebookError = GE_INVALIDMEMORYTYPE; + break; + + default: +#ifdef DEBUG + fprintf(stdout, _(" Unknown error!\n")); +#endif /* DEBUG */ + CurrentPhonebookError = GE_INTERNALERROR; + } + + break; + + } +} + +/* Routine to get specifed phone book location. Designed to be called by + application. Will block until location is retrieved or a timeout/error + occurs. */ +GSM_Error N6110_GetMemoryLocation(GSM_PhonebookEntry *entry) +{ + unsigned char req[] = {N6110_FRAME_HEADER, 0x01, 0x00, 0x00, 0x00}; + + CurrentPhonebookEntry = entry; + + req[4] = N6110_GetMemoryType(entry->MemoryType); + req[5] = entry->Location; + + return NULL_SendMessageSequence + (50, &CurrentPhonebookError, 7, 0x03, req); +} + +static void N6110_ReplyWritePhonebookLocation(u16 MessageLength, u8 *MessageBuffer, u8 MessageType) { + + switch (MessageBuffer[3]) { + + case 0x05: + +#ifdef DEBUG + fprintf(stdout, _("Message: Phonebook written correctly.\n")); +#endif /* DEBUG */ + CurrentPhonebookError = GE_NONE; + break; + + case 0x06: + + switch (MessageBuffer[4]) { + /* FIXME: other errors? When I send the phonebook with index of 350 it + still report error 0x7d :-( */ + case 0x7d: +#ifdef DEBUG + fprintf(stdout, _("Message: Phonebook not written - name is too long.\n")); +#endif /* DEBUG */ + CurrentPhonebookError = GE_PHBOOKNAMETOOLONG; + break; + + default: +#ifdef DEBUG + fprintf(stdout, _(" Unknown error!\n")); +#endif /* DEBUG */ + CurrentPhonebookError = GE_INTERNALERROR; + } + } +} + +/* Routine to write phonebook location in phone. Designed to be called by + application code. Will block until location is written or timeout + occurs. */ +GSM_Error N6110_WritePhonebookLocation(GSM_PhonebookEntry *entry) +{ + unsigned char req[128] = { N6110_FRAME_HEADER, 0x04, 0x00, 0x00 }; + int i=0, current=0; + + req[4] = N6110_GetMemoryType(entry->MemoryType); + req[5] = entry->Location; + + current=7; + + if (GetModelFeature (FN_PHONEBOOK)==F_PBK33) { + + req[6] = strlen(entry->Name)*2; + + EncodeUnicode (req+current,entry->Name ,strlen(entry->Name)); + + for (i=0; iName); i++) + { + /* here we encode "special" chars */ + if (entry->Name[i]=='~') req[current+i*2]=1; //enables/disables blinking + if (entry->Name[i]=='`') req[current+i*2]=0; //hides rest ot contents + } + + current+=strlen(entry->Name)*2; + } else { + + req[6] = strlen(entry->Name); + + for (i=0; iName); i++) + { + req[current+i] = entry->Name[i]; + + /* here we encode "special" chars */ + if (entry->Name[i]=='~') req[current+i]=1; //enables/disables blinking + if (entry->Name[i]=='`') req[current+i]=0; //hides rest ot contents + } + + current+=strlen(entry->Name); + } + + req[current++]=strlen(entry->Number); + + for (i=0; iNumber); i++) + req[current+i] = entry->Number[i]; + + current+=strlen(entry->Number); + + /* Jano: This allow to save 14 characters name into SIM memory, when + No Group is selected. */ + if (entry->Group == 5) + req[current++]=0xff; + else + req[current++]=entry->Group; + + return NULL_SendMessageSequence + (50, &CurrentPhonebookError, current, 0x03, req); +} + +#ifndef UCLINUX + +void N6110_ReplyNetmonitor(u16 MessageLength, u8 *MessageBuffer, u8 MessageType) { + + switch(MessageBuffer[3]) { + + case 0x00: +#ifdef DEBUG + fprintf(stdout, _("Message: Netmonitor correctly set.\n")); +#endif /* DEBUG */ + CurrentNetmonitorError=GE_NONE; + break; + + default: +#ifdef DEBUG + fprintf(stdout, _("Message: Netmonitor menu %d received:\n"), MessageBuffer[3]); + fprintf(stdout, "%s\n", MessageBuffer+4); +#endif /* DEBUG */ + + strcpy(CurrentNetmonitor, MessageBuffer+4); + + CurrentNetmonitorError=GE_NONE; + } +} + +GSM_Error N6110_NetMonitor(unsigned char mode, char *Screen) +{ + unsigned char req[] = { 0x00, 0x01, 0x7e, 0x00 }; + + GSM_Error error; + + error=N6110_EnableExtendedCommands(0x01); + if (error!=GE_NONE) return error; + + CurrentNetmonitor=Screen; + + req[3]=mode; + + return NULL_SendMessageSequence + (20, &CurrentNetmonitorError, 4, 0x40, req); +} + +/* Doesn't work in N3210. */ +/* In other allow to access phone menu without SIM card (just send any sequence) */ +GSM_Error N6110_SendDTMF(char *String) +{ + unsigned char req[64] = { N6110_FRAME_HEADER, 0x50, + 0x00 /* Length of DTMF string. */ + }; + + u8 length=strlen(String); + + if (length>59) length=59; + + req[4] = length; + + memcpy(req+5,String,length); + + return NULL_SendMessageSequence + (20, &CurrentSendDTMFError, 5+length, 0x01, req); +} + +void N6110_ReplyGetSpeedDial(u16 MessageLength, u8 *MessageBuffer, u8 MessageType) { + + switch (MessageBuffer[3]) { + + case 0x17: + + switch (MessageBuffer[4]) { + case 0x02: CurrentSpeedDialEntry->MemoryType = GMT_ME; + default : CurrentSpeedDialEntry->MemoryType = GMT_SM; + } + + CurrentSpeedDialEntry->Location = MessageBuffer[5]; + +#ifdef DEBUG + fprintf(stdout, _("Message: Speed dial entry received:\n")); + fprintf(stdout, _(" Location: %d\n"), CurrentSpeedDialEntry->Location); + fprintf(stdout, _(" MemoryType: %s\n"), N6110_MemoryType_String[CurrentSpeedDialEntry->MemoryType]); + fprintf(stdout, _(" Number: %d\n"), CurrentSpeedDialEntry->Number); +#endif /* DEBUG */ + + CurrentSpeedDialError=GE_NONE; + break; + + case 0x18: + +#ifdef DEBUG + fprintf(stdout, _("Message: Speed dial entry error\n")); +#endif /* DEBUG */ + CurrentSpeedDialError=GE_INVALIDSPEEDDIALLOCATION; + break; + + } +} + +GSM_Error N6110_GetSpeedDial(GSM_SpeedDial *entry) +{ + + unsigned char req[] = { N6110_FRAME_HEADER, + 0x16, + 0x00 /* The number of speed dial. */ + }; + + CurrentSpeedDialEntry = entry; + + req[4] = entry->Number; + + return NULL_SendMessageSequence + (20, &CurrentSpeedDialError, 5, 0x03, req); +} + +void N6110_ReplySetSpeedDial(u16 MessageLength, u8 *MessageBuffer, u8 MessageType) { + + switch (MessageBuffer[3]) { + + case 0x1a: + +#ifdef DEBUG + fprintf(stdout, _("Message: Speed dial entry set.\n")); +#endif /* DEBUG */ + CurrentSpeedDialError=GE_NONE; + break; + + case 0x1b: + +#ifdef DEBUG + fprintf(stdout, _("Message: Speed dial entry setting error.\n")); +#endif /* DEBUG */ + CurrentSpeedDialError=GE_INVALIDSPEEDDIALLOCATION; + break; + + } +} + +GSM_Error N6110_SetSpeedDial(GSM_SpeedDial *entry) +{ + + unsigned char req[] = { N6110_FRAME_HEADER, + 0x19, + 0x00, /* Number */ + 0x00, /* Memory Type */ + 0x00 /* Location */ + }; + + req[4] = entry->Number; + + switch (entry->MemoryType) { + case GMT_ME: req[5] = 0x02; + default : req[5] = 0x03; + } + + req[6] = entry->Location; + + return NULL_SendMessageSequence + (20, &CurrentSpeedDialError, 7, 0x03, req); +} + +/* This function finds parts of SMS in frame used in new Nokia phones + in internal protocols (they're coded according to GSM 03.40), copies them + to GSM_ETSISMSMessage and calls GSM_DecodeETSISMS to decode + GSM_ETSISMSMessage to GSM_SMSMessage structure */ +GSM_Error GSM_DecodeNokiaSMSFrame(GSM_SMSMessage *SMS, unsigned char *req, int length) +{ + SMS_MessageType PDU=SMS_Deliver; + GSM_ETSISMSMessage ETSI; + int offset=0,i; + + ETSI.firstbyte=req[12]; + + /* See GSM 03.40 section 9.2.3.1 */ + if ((ETSI.firstbyte & 0x03) == 0x01) PDU=SMS_Submit; + if ((ETSI.firstbyte & 0x03) == 0x02) PDU=SMS_Status_Report; + + switch (PDU) { + case SMS_Submit : offset=5;break; + case SMS_Deliver : offset=4;break; + case SMS_Status_Report: offset=3;break; + default: break; + } + + for (i=0;iName[0]=0; + + return GE_NONE; +} + +void N6110_ReplyGetSMSMessage(u16 MessageLength, u8 *MessageBuffer, u8 MessageType) { + + int offset; + + switch (MessageBuffer[3]) { + + case 0x08: + + switch (MessageBuffer[7]) { + + case 0x00: + CurrentSMSMessage->Type = GST_SMS; + CurrentSMSMessage->folder=GST_INBOX; + offset=4; + break; + + case 0x01: + CurrentSMSMessage->Type = GST_DR; + CurrentSMSMessage->folder=GST_INBOX; + offset=3; + break; + + case 0x02: + CurrentSMSMessage->Type = GST_SMS; + CurrentSMSMessage->folder=GST_OUTBOX; + offset=5; + break; + + default: + CurrentSMSMessage->Type = GST_UN; + offset=4; + break; + + } + + /* Field Short Message Status - MessageBuffer[4] seems not to be + compliant with GSM 07.05 spec. + Meaning Nokia protocol GMS spec + ---------------------------------------------------- + MO Sent 0x05 0x07 or 0x01 + MO Not sent 0x07 0x06 or 0x00 + MT Read 0x01 0x05 or 0x01 + MT Not read 0x03 0x04 or 0x00 + ---------------------------------------------------- + See GSM 07.05 section 2.5.2.6 and correct me if I'm wrong. + + Pawel Kot */ + + if (MessageBuffer[4] & 0x02) CurrentSMSMessage->Status = GSS_NOTSENTREAD; + else CurrentSMSMessage->Status = GSS_SENTREAD; + +#ifdef DEBUG + fprintf(stdout, _("Number: %d\n"), MessageBuffer[6]); + + if (CurrentSMSMessage->folder!=1) { //GST_OUTBOX + fprintf(stdout, _("Message: Received SMS (mobile terminated)\n")); + } else { + fprintf(stdout, _("Message: Outbox message (mobile originated)\n")); + } + + if (CurrentSMSMessage->Type == GST_DR) fprintf(stdout, _(" Delivery Report\n")); + if (CurrentSMSMessage->Type == GST_UN) fprintf(stdout, _(" Unknown type\n")); + + if (CurrentSMSMessage->folder==1) { //GST_OUTBOX + if (CurrentSMSMessage->Status) fprintf(stdout, _(" Sent\n")); + else fprintf(stdout, _(" Not sent\n")); + } else { + if (CurrentSMSMessage->Status) fprintf(stdout, _(" Read\n")); + else fprintf(stdout, _(" Not read\n")); + } +#endif + + CurrentSMSPointer=GSM_DecodeNokiaSMSFrame(CurrentSMSMessage, MessageBuffer+8, MessageLength-8); + + CurrentSMSMessage->MemoryType = MessageBuffer[5]; + CurrentSMSMessage->MessageNumber = MessageBuffer[6]; + + /* Signal no error to calling code. */ + CurrentSMSMessageError = GE_NONE; + +#ifdef DEBUG + fprintf(stdout, "\n"); +#endif + + break; + + case 0x09: + + /* We have requested invalid or empty location. */ + +#ifdef DEBUG + fprintf(stdout, _("Message: SMS reading failed\n")); + + switch (MessageBuffer[4]) { + case 0x02: + fprintf(stdout, _(" Invalid location!\n"));break; + case 0x07: + fprintf(stdout, _(" Empty SMS location.\n"));break; + case 0x0c: + fprintf(stdout, _(" No access to memory (no PIN on card ?)\n"));break; + default: + fprintf(stdout, _(" Error code %i - please report it \n"),MessageBuffer[4]);break; + } +#endif /* DEBUG */ + + switch (MessageBuffer[4]) { + case 0x02:CurrentSMSMessageError = GE_INVALIDSMSLOCATION;break; + case 0x07:CurrentSMSMessageError = GE_EMPTYSMSLOCATION;break; + case 0x0c:CurrentSMSMessageError = GE_NOACCESS;break; + default :CurrentSMSMessageError = GE_UNKNOWN;break; + } + + break; + + } +} + +GSM_Error N6110_GetSMSMessage(GSM_SMSMessage *message) +{ + + unsigned char req[] = { N6110_FRAME_HEADER, + 0x07, + 0x02, /* Unknown */ + 0x00, /* Location */ + 0x01, 0x64}; + + int timeout = 60; + + /* State machine code writes data to these variables when it comes in. */ + + CurrentSMSMessage = message; + CurrentSMSMessageError = GE_BUSY; + + req[5] = message->Location; + + /* Send request */ + Protocol->SendMessage(8, 0x02, req); + + /* Wait for timeout or other error. */ + while (timeout != 0 && (CurrentSMSMessageError == GE_BUSY || CurrentSMSMessageError == GE_SMSWAITING)) { + + if (--timeout == 0) + return (GE_TIMEOUT); + + usleep (100000); + } + + return (CurrentSMSMessageError); +} + +void N6110_ReplyDeleteSMSMessage(u16 MessageLength, u8 *MessageBuffer, u8 MessageType) { + +#ifdef DEBUG + fprintf(stdout, _("Message: SMS deleted successfully.\n")); +#endif /* DEBUG */ + + CurrentSMSMessageError = GE_NONE; +} + +GSM_Error N6110_DeleteSMSMessage(GSM_SMSMessage *message) +{ + unsigned char req[] = {N6110_FRAME_HEADER, 0x0a, 0x02, 0x00}; + + req[5] = message->Location; + + return NULL_SendMessageSequence + (50, &CurrentSMSMessageError, 6, 0x14, req); +} + +/* FIXME: do we need more than SMS_Submit and SMS_Deliver ? */ +GSM_Error GSM_EncodeNokiaSMSFrame(GSM_SMSMessage *SMS, unsigned char *req, int *length, SMS_MessageType PDU) +{ + GSM_ETSISMSMessage ETSI; + int i,offset=0; + + GSM_EncodeETSISMS(SMS, &ETSI, PDU, length); + + /* Cleaning */ + for (i=0;i<36;i++) req[i]=0; + + req[12]=ETSI.firstbyte; + + for (i=0;iMessageNumber=MessageBuffer[5]; + + CurrentSMSMessageError = GE_NONE; + break; + + case 0x06: +#ifdef DEBUG + fprintf(stdout, _("SMS saving failed\n")); + switch (MessageBuffer[4]) { + case 0x02:fprintf(stdout, _(" All locations busy.\n"));break; + case 0x03:fprintf(stdout, _(" Invalid location!\n"));break; + default :fprintf(stdout, _(" Unknown error.\n"));break; + } +#endif + + switch (MessageBuffer[4]) { + case 0x02:CurrentSMSMessageError = GE_MEMORYFULL;break; + case 0x03:CurrentSMSMessageError = GE_INVALIDSMSLOCATION;break; + default :CurrentSMSMessageError = GE_UNKNOWN;break; + } + } +} + +/* GST_DR and GST_UN not supported ! */ +GSM_Error N6110_SaveSMSMessage(GSM_SMSMessage *SMS) +{ + unsigned char req[256] = { + N6110_FRAME_HEADER, 0x04, /* SMS save request*/ + 0x00, /* SMS Status. Different for Inbox and Outbox */ + 0x02, /* ?? */ + 0x00, /* SMS Location */ + 0x02, /* SMS Type */ + }; + + int length; + SMS_MessageType PDU; + GSM_Error error; + + if (SMS->Location) req[6] = SMS->Location; + + if (SMS->folder==0) { /*Inbox*/ + req[4]=1; /* SMS Status */ + req[7] = 0x00; /* SMS Type */ + PDU=SMS_Deliver; + } else { + req[4]=5; /* SMS Status */ + req[7] = 0x02; /* SMS Type */ + PDU=SMS_Submit; + } + + if (SMS->Status == GSS_NOTSENTREAD) req[4] |= 0x02; + + error=GSM_EncodeNokiaSMSFrame(SMS, req+8, &length, PDU); + if (error != GE_NONE) return error; + + CurrentSMSMessage = SMS; + + return NULL_SendMessageSequence + (70, &CurrentSMSMessageError, 39+length, 0x14, req); +} + +void N6110_ReplySetCellBroadcast(u16 MessageLength, u8 *MessageBuffer, u8 MessageType) { + +#ifdef DEBUG + fprintf(stdout, _("Message: Cell Broadcast enabled/disabled successfully.\n")); fflush (stdout); +#endif + + CurrentCBError = GE_NONE; +} + +/* Enable and disable Cell Broadcasting */ +GSM_Error N6110_EnableCellBroadcast(void) +{ + unsigned char req[] = {N6110_FRAME_HEADER, 0x20, + 0x01, 0x01, 0x00, 0x00, 0x01, 0x01}; + +#ifdef DEBUG + fprintf (stdout,"Enabling CB\n"); +#endif + + CurrentCBMessage = (GSM_CBMessage *)malloc(sizeof (GSM_CBMessage)); + CurrentCBMessage->Channel = 0; + CurrentCBMessage->New = false; + strcpy (CurrentCBMessage->Message,""); + + return NULL_SendMessageSequence + (10, &CurrentCBError, 10, 0x02, req); +} + + +GSM_Error N6110_DisableCellBroadcast(void) +{ + /* Should work, but not tested fully */ + + unsigned char req[] = {N6110_FRAME_HEADER, 0x20, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}; /*VERIFY*/ + + return NULL_SendMessageSequence + (10, &CurrentCBError, 10, 0x02, req); +} + +void N6110_ReplyReadCellBroadcast(u16 MessageLength, u8 *MessageBuffer, u8 MessageType) { + + int i, tmp; + unsigned char output[160]; + + CurrentCBMessage->Channel = MessageBuffer[7]; + CurrentCBMessage->New = true; + tmp=GSM_UnpackEightBitsToSeven(0, MessageBuffer[9], MessageBuffer[9], MessageBuffer+10, output); + +#ifdef DEBUG + fprintf(stdout, _("Message: CB received.\n")); fflush (stdout); + + fprintf(stdout, _("Message: channel number %i\n"),MessageBuffer[7]); + + fflush (stdout); + + for (i=0; iMessage[i] = DecodeWithDefaultAlphabet(output[i]); + } + CurrentCBMessage->Message[i]=0; +} + +GSM_Error N6110_ReadCellBroadcast(GSM_CBMessage *Message) +{ +#ifdef DEBUG + fprintf(stdout,"Reading CB\n"); +#endif + + if (CurrentCBMessage != NULL) + { + if (CurrentCBMessage->New == true) + { +#ifdef DEBUG + fprintf(stdout,"New CB received\n"); +#endif + Message->Channel = CurrentCBMessage->Channel; + strcpy(Message->Message,CurrentCBMessage->Message); + CurrentCBMessage->New = false; + return (GE_NONE); + } + } + return (GE_NONEWCBRECEIVED); +} + +int N6110_MakeCallerGroupFrame(unsigned char *req,GSM_Bitmap Bitmap) +{ + int count=0; + + req[count++]=Bitmap.number; + req[count++]=strlen(Bitmap.text); + memcpy(req+count,Bitmap.text,req[count-1]); + count+=req[count-1]; + req[count++]=Bitmap.ringtone; + + /* Setting for graphic: + 0x00 - Off + 0x01 - On + 0x02 - View Graphics + 0x03 - Send Graphics + 0x04 - Send via IR + You can even set it higher but Nokia phones (my + 6110 at least) will not show you the name of this + item in menu ;-)) Nokia is really joking here. */ + if (Bitmap.enabled) req[count++]=0x01; + else req[count++]=0x00; + + req[count++]=(Bitmap.size+4)>>8; + req[count++]=(Bitmap.size+4)%0xff; + req[count++]=0x00; /* Future extensions! */ + req[count++]=Bitmap.width; + req[count++]=Bitmap.height; + req[count++]=0x01; /* Just BW */ + memcpy(req+count,Bitmap.bitmap,Bitmap.size); + + return count+Bitmap.size; +} + +int N6110_MakeOperatorLogoFrame(unsigned char *req,GSM_Bitmap Bitmap) +{ + int count=0; + + EncodeNetworkCode(req+count, Bitmap.netcode); + count=count+3; + + req[count++]=(Bitmap.size+4)>>8; + req[count++]=(Bitmap.size+4)%0xff; + req[count++]=0x00; /* Infofield */ + req[count++]=Bitmap.width; + req[count++]=Bitmap.height; + req[count++]=0x01; /* Just BW */ + memcpy(req+count,Bitmap.bitmap,Bitmap.size); + + return count+Bitmap.size; +} + +int N6110_MakeStartupLogoFrame(unsigned char *req,GSM_Bitmap Bitmap) +{ + int count=0; + + req[count++]=0x01; + req[count++]=Bitmap.height; + req[count++]=Bitmap.width; + memcpy(req+count,Bitmap.bitmap,Bitmap.size); + + return count+Bitmap.size; +} + +/* Set a bitmap or welcome-note */ +GSM_Error N6110_SetBitmap(GSM_Bitmap *Bitmap) { + + unsigned char req[600] = { N6110_FRAME_HEADER }; + u16 count=3; + u8 textlen; + + int timeout=50; + + /* Direct uploading variables */ + GSM_MultiSMSMessage SMS; + unsigned char buffer[1000] = {0x0c,0x01}; + GSM_NetworkInfo NetworkInfo; + + GSM_Error error; + + /* Uploading with preview */ + if (Bitmap->number==255 && + (Bitmap->type==GSM_OperatorLogo || Bitmap->type==GSM_CallerLogo)) { + GSM_SaveBitmapToSMS(&SMS,Bitmap,false,false); + memcpy(buffer+2,SMS.SMS[0].UDH,SMS.SMS[0].UDH[0]+1); + + memcpy(buffer+2+SMS.SMS[0].UDH[0]+1,SMS.SMS[0].MessageText,SMS.SMS[0].Length); + + buffer[2+SMS.SMS[0].UDH[0]+1+SMS.SMS[0].Length]=0x00; + + Protocol->SendMessage(2+SMS.SMS[0].UDH[0]+1+SMS.SMS[0].Length+1, 0x12, buffer); + + GSM->GetNetworkInfo(&NetworkInfo); //need to make something + return GE_NONE; //no answer from phone + } + + CurrentSetBitmapError = GE_BUSY; + + switch (Bitmap->type) { + case GSM_WelcomeNoteText: + case GSM_DealerNoteText: + req[count++]=0x18; + req[count++]=0x01; /* Only one block */ + + if (Bitmap->type==GSM_WelcomeNoteText) + req[count++]=0x02; /* Welcome text */ + else + req[count++]=0x03; /* Dealer Welcome Note */ + + textlen=strlen(Bitmap->text); + req[count++]=textlen; + memcpy(req+count,Bitmap->text,textlen); + + count+=textlen; + + Protocol->SendMessage(count, 0x05, req); + + break; + + case GSM_StartupLogo: + if (Bitmap->number==0) { + + /* For 33xx we first set animated logo to default */ + if (GetModelFeature (FN_STARTUP)==F_STANIM) { + error=N6110_SetProfileFeature(0, 0x29, Bitmap->number); + if (error!=GE_NONE) return error; + } + + req[count++]=0x18; + req[count++]=0x01; /* Only one block */ + count=count+N6110_MakeStartupLogoFrame(req+5,*Bitmap); + Protocol->SendMessage(count, 0x05, req); + } else { + return N6110_SetProfileFeature(0, 0x29, Bitmap->number); + } + break; + + case GSM_OperatorLogo: + req[count++]=0x30; /* Store Op Logo */ + req[count++]=0x01; /* Location */ + count=count+N6110_MakeOperatorLogoFrame(req+5,*Bitmap); + Protocol->SendMessage(count, 0x05, req); + break; + + case GSM_CallerLogo: + req[count++]=0x13; + count=count+N6110_MakeCallerGroupFrame(req+4,*Bitmap); + Protocol->SendMessage(count, 0x03, req); + break; + + case GSM_PictureImage: + req[count++]=0x03; + req[count++]=Bitmap->number; + if (strcmp(Bitmap->Sender,"")) { + req[count]=GSM_PackSemiOctetNumber(Bitmap->Sender, req+count+1,true); + + /* Convert number of semioctets to number of chars and add count */ + textlen=req[count]; + if (textlen % 2) textlen++; + count+=textlen / 2 + 1; + + count++; + } else { + req[count++]=0x00; + req[count++]=0x00; + } + req[count++]=0x00; + req[count++]=strlen(Bitmap->text); + memcpy(req+count,Bitmap->text,strlen(Bitmap->text)); + count+=strlen(Bitmap->text); + req[count++]=0x00; + req[count++]=Bitmap->width; + req[count++]=Bitmap->height; + req[count++]=0x01; + memcpy(req+count,Bitmap->bitmap,Bitmap->size); + Protocol->SendMessage(count+Bitmap->size, 0x47, req); + break; + + case GSM_7110OperatorLogo: + case GSM_7110StartupLogo: + case GSM_6210StartupLogo: + return GE_NOTSUPPORTED; + + case GSM_None: + return GE_NONE; + } + + /* Wait for timeout or other error. */ + while (timeout != 0 && CurrentSetBitmapError == GE_BUSY ) { + + if (--timeout == 0) + return (GE_TIMEOUT); + + usleep (100000); + } + + return CurrentSetBitmapError; +} + +/* Get a bitmap from the phone */ +GSM_Error N6110_GetBitmap(GSM_Bitmap *Bitmap) { + + unsigned char req[10] = { N6110_FRAME_HEADER }; + u8 count=3; + + int timeout=100; + + CurrentGetBitmap=Bitmap; + CurrentGetBitmapError = GE_BUSY; + + switch (CurrentGetBitmap->type) { + case GSM_StartupLogo: + case GSM_WelcomeNoteText: + case GSM_DealerNoteText: + req[count++]=0x16; + Protocol->SendMessage(count, 0x05, req); + break; + case GSM_OperatorLogo: + req[count++]=0x33; + req[count++]=0x01; /* Location 1 */ + Protocol->SendMessage(count, 0x05, req); + break; + case GSM_CallerLogo: + req[count++]=0x10; + req[count++]=Bitmap->number; + Protocol->SendMessage(count, 0x03, req); + break; + case GSM_PictureImage: + req[count++]=0x01; + req[count++]=Bitmap->number; + Protocol->SendMessage(count, 0x47, req); + break; + case GSM_7110OperatorLogo: + case GSM_7110StartupLogo: + case GSM_6210StartupLogo: + default: + return GE_NOTSUPPORTED; + } + + /* Wait for timeout or other error. */ + while (timeout != 0 && CurrentGetBitmapError == GE_BUSY ) { + + if (--timeout == 0) + return (GE_TIMEOUT); + + usleep (100000); + } + + CurrentGetBitmap=NULL; + + return CurrentGetBitmapError; +} + +void N6110_ReplySetRingtone(u16 MessageLength, u8 *MessageBuffer, u8 MessageType) { + + switch (MessageBuffer[3]) { + + /* Set ringtone OK */ + case 0x37: +#ifdef DEBUG + fprintf(stdout, _("Message: Ringtone set OK!\n")); +#endif + CurrentRingtoneError=GE_NONE; + break; + + /* Set ringtone error */ + case 0x38: +#ifdef DEBUG + fprintf(stdout, _("Message: Ringtone setting error !\n")); +#endif + CurrentRingtoneError=GE_NOTSUPPORTED; + break; + } +} + +GSM_Error N6110_SetRingTone(GSM_Ringtone *ringtone, int *maxlength) +{ + + char req[FB61_MAX_RINGTONE_FRAME_LENGTH+10] = + {N6110_FRAME_HEADER, + 0x36, + 0x00, /* Location */ + 0x00,0x78}; + + int size=FB61_MAX_RINGTONE_FRAME_LENGTH; + + /* Variables for preview uploading */ + unsigned char buffer[FB61_MAX_RINGTONE_FRAME_LENGTH+50]; + unsigned char buffer2[20]; + GSM_NetworkInfo NetworkInfo; + + /* Setting ringtone with preview */ + if (ringtone->location==255) { + buffer[0]=0x0c; + buffer[1]=0x01; + EncodeUDHHeader(buffer2, GSM_RingtoneUDH); + memcpy(buffer+2,buffer2,buffer2[0]+1); //copying UDH + *maxlength=GSM_PackRingtone(ringtone, buffer+2+buffer2[0]+1, &size); //packing ringtone + Protocol->SendMessage(2+buffer2[0]+1+size, 0x12, buffer); //sending frame + GSM->GetNetworkInfo(&NetworkInfo); //need to make something + sleep(1); + return GE_NONE; //no answer from phone + } + + *maxlength=GSM_PackRingtone(ringtone, req+7, &size); + + req[4]=ringtone->location-1; + + return NULL_SendMessageSequence + (50, &CurrentRingtoneError, (size+7), 0x05, req); +} + +void N6110_ReplyGetBinRingtone(u16 MessageLength, u8 *MessageBuffer, u8 MessageType) { + + int i; + + switch (MessageBuffer[4]) { + case 0x00: /* location supported. We have ringtone */ + + /* Binary format used in N6150 */ + if (MessageBuffer[5]==0x0c && MessageBuffer[6]==0x01 && MessageBuffer[7]==0x2c) { +#ifdef DEBUG + fprintf(stdout,_("Message: ringtone \"")); +#endif + + /* Copying name */ + i=8; + while (true) { +#ifdef DEBUG + if (MessageBuffer[i]!=0) + fprintf(stdout,_("%c"),MessageBuffer[i]); +#endif + CurrentGetBinRingtone->name[i-8]=MessageBuffer[i]; + if (MessageBuffer[i]==0) break; + i++; + } + +#ifdef DEBUG + fprintf(stdout,_("\" received from location %i\n"),MessageBuffer[3]+1); +#endif + + /* Looking for end */ + i=0; + while (true) { + if (MessageBuffer[i]==0x07 && MessageBuffer[i+1]==0x0b) { + i=i+2;break; + } + if (MessageBuffer[i]==0x0e && MessageBuffer[i+1]==0x0b) { + i=i+2;break; + } + i++; + if (i==MessageLength) break; + } + + /* Copying frame */ + memcpy(CurrentGetBinRingtone->frame,MessageBuffer+3,i-3); + CurrentGetBinRingtone->length=i-3; + + CurrentBinRingtoneError=GE_NONE; + break; + } + + /* Binary format used in N3210 */ + if (MessageBuffer[5]==0x10 && MessageBuffer[6]==0x01 && MessageBuffer[7]==0x2c) { + +#ifdef DEBUG + fprintf(stdout,_("Message: ringtone \"")); +#endif + + /* Copying name */ + i=8; + while (true) { +#ifdef DEBUG + if (MessageBuffer[i]!=0) + fprintf(stdout,_("%c"),MessageBuffer[i]); +#endif + CurrentGetBinRingtone->name[i-8]=MessageBuffer[i]; + if (MessageBuffer[i]==0) break; + i++; + } + +#ifdef DEBUG + fprintf(stdout,_("\" received from location %i\n"),MessageBuffer[3]+1); +#endif + + /* Here changes to get full compatibility with binary format used in N6150 */ + MessageBuffer[3]=0; + MessageBuffer[4]=0; + MessageBuffer[5]=0x0c; + MessageBuffer[6]=0x01; + MessageBuffer[7]=0x2c; + + /* Looking for end */ + i=0; + while (true) { + if (MessageBuffer[i]==0x07 && MessageBuffer[i+1]==0x0b) { + i=i+2;break; + } + if (MessageBuffer[i]==0x0e && MessageBuffer[i+1]==0x0b) { + i=i+2;break; + } + i++; + if (i==MessageLength) break; + } + + /* Copying frame */ + memcpy(CurrentGetBinRingtone->frame,MessageBuffer+3,i-3); + + CurrentGetBinRingtone->length=i-3; + + CurrentBinRingtoneError=GE_NONE; + break; + } + + /* Copying frame */ + memcpy(CurrentGetBinRingtone->frame,MessageBuffer,MessageLength); + + CurrentGetBinRingtone->length=MessageLength; + +#ifdef DEBUG + fprintf(stdout,_("Message: unknown binary format for ringtone received from location %i\n"),MessageBuffer[3]+1); +#endif + CurrentBinRingtoneError=GE_UNKNOWNMODEL; + break; + + default: + +#ifdef DEBUG + fprintf(stdout,_("Message: Phone doesn't support downloaded ringtones at location %i\n"),MessageBuffer[3]+1); +#endif + + CurrentBinRingtoneError=GE_INVALIDRINGLOCATION; + } +} + +GSM_Error N6110_GetBinRingTone(GSM_BinRingtone *ringtone) +{ + unsigned char req[] = { 0x00,0x01,0x9e, + 0x00 }; //location + + GSM_Error error; + + CurrentGetBinRingtone=ringtone; + + error=N6110_EnableExtendedCommands(0x01); + if (error!=GE_NONE) return error; + + req[3]=ringtone->location-1; + + return NULL_SendMessageSequence + (50, &CurrentBinRingtoneError, 4, 0x40, req); +} + +void N6110_ReplySetBinRingtone(u16 MessageLength, u8 *MessageBuffer, u8 MessageType) { + + switch (MessageBuffer[4]) { + case 0x00: /* location supported. We set ringtone */ +#ifdef DEBUG + fprintf(stdout,_("Message: downloaded ringtone set at location %i\n"),MessageBuffer[3]+1); +#endif + CurrentBinRingtoneError=GE_NONE; + break; + + default: +#ifdef DEBUG + fprintf(stdout,_("Message: Phone doesn't support downloaded ringtones at location %i\n"),MessageBuffer[3]+1); +#endif + CurrentBinRingtoneError=GE_NOTSUPPORTED; + break; + } +} + +GSM_Error N6110_SetBinRingTone(GSM_BinRingtone *ringtone) +{ + unsigned char req[1000] = { 0x00,0x01,0xa0}; + + GSM_Error error; + + GSM_BinRingtone ring; + + /* Must be sure, that can upload ringtone to this phone */ + ring.location=ringtone->location; + error=N6110_GetBinRingTone(&ring); + if (error!=GE_NONE) return error; + + error=N6110_EnableExtendedCommands(0x01); + if (error!=GE_NONE) return error; + + memcpy(req+3,ringtone->frame,ringtone->length); + + req[3]=ringtone->location-1; + + return NULL_SendMessageSequence + (50, &CurrentBinRingtoneError, ringtone->length+3, 0x40, req); +} + +#endif /* UCLINUX */ + +GSM_Error N6110_Reset(unsigned char type) +{ + return N6110_EnableExtendedCommands(type); +} + +void N6110_Dispatch0x01Message(u16 MessageLength, u8 *MessageBuffer, u8 MessageType) { + + int count; +#ifdef DEBUG + int tmp; +#endif + + switch (MessageBuffer[3]) { + + /* Unknown message - it has been seen after the 0x07 message (call + answered). Probably it has similar meaning. If you can solve + this - just mail me. Pavel Janík ml. + + The message looks like this: + + Msg Destination: PC + Msg Source: Phone + Msg Type: 01 + Msg Unknown: 00 + Msg Len: 0e + + Phone: [01 ][08 ][00 ] is the header of the frame + + [03 ] is the call message subtype + + [05 ] is the call sequence number + + [05 ] unknown + + [00 ][01 ][03 ][02 ][91][00] are unknown but has been + seen in the Incoming call message (just after the + caller's name from the phonebook). But never change + between phone calls :-( + */ + + /* This may mean sequence number of 'just made' call - CK */ + case 0x02: + +#ifdef DEBUG + fprintf(stdout, _("Message: Call message, type 0x02:")); + fprintf(stdout, _(" Exact meaning not known yet, sorry :-(\n")); +#endif /* DEBUG */ + + break; + + /* Possibly call OK */ + /* JD: I think that this means "call in progress" (incomming or outgoing) */ + case 0x03: + +#ifdef DEBUG + fprintf(stdout, _("Message: Call message, type 0x03:")); + fprintf(stdout, _(" Sequence nr. of the call: %d\n"), MessageBuffer[4]); + fprintf(stdout, _(" Exact meaning not known yet, sorry :-(\n")); +#endif /* DEBUG */ + + CurrentCallSequenceNumber=MessageBuffer[4]; +#ifndef UCLINUX + CurrentIncomingCall[0]='D'; +#endif /* UCLINUX */ + if (CurrentCallPassup) CurrentCallPassup('D'); + + break; + + /* Remote end has gone away before you answer the call. Probably your + mother-in-law or banker (which is worse?) ... */ + case 0x04: + +#ifdef DEBUG + fprintf(stdout, _("Message: Remote end hang up.\n")); + fprintf(stdout, _(" Sequence nr. of the call: %d, error: %i"), MessageBuffer[4],MessageBuffer[6]); + + switch (MessageBuffer[6]) { + case 28: fprintf(stdout,_(" (info \"Invalid phone number\")"));break; + case 34: fprintf(stdout,_(" (info \"Network busy\")"));break; + case 42: fprintf(stdout,_(" (info \"Network busy\")"));break; + case 47: fprintf(stdout,_(" (info \"Error in connection\")"));break; + case 50: fprintf(stdout,_(" (info \"Check operator services\")"));break; case 76: fprintf(stdout,_(" (info \"Check operator services\")"));break; + case 111: fprintf(stdout,_(" (info \"Error in connection\")"));break; + } + + fprintf(stdout,_("\n For more details with errors see netmonitor manual (test 39) on www.marcin-wiacek.topnet.pl")); + fprintf(stdout,_("\n If know their meaning, GSM specs decribing them, contact with me on marcin-wiacek@topnet.pl. THX\n")); +#endif /* DEBUG */ + +#ifndef UCLINUX + CurrentIncomingCall[0] = ' '; +#endif /* UCLINUX */ + if (CurrentCallPassup) CurrentCallPassup(' '); + + break; + + /* Incoming call alert */ + case 0x05: + +#ifdef DEBUG + fprintf(stdout, _("Message: Incoming call alert:\n")); + + /* We can have more then one call ringing - we can distinguish between + them */ + + fprintf(stdout, _(" Sequence nr. of the call: %d\n"), MessageBuffer[4]); + fprintf(stdout, _(" Number: ")); + + count=MessageBuffer[6]; + + for (tmp=0; tmp SendMessage(4, 0x04, connect5); */ + + /* Marcin-Wiacek@TopNet.PL */ + +#if defined(WIN32) || defined(UCLINUX) + sprintf(Current_IMEI, "%s", MessageBuffer+5); + sprintf(Current_Model, "%s", MessageBuffer+21); + sprintf(Current_Revision, "SW%s, HW%s", MessageBuffer+41, MessageBuffer+35); +#else + snprintf(Current_IMEI, GSM_MAX_IMEI_LENGTH, "%s", MessageBuffer+5); + snprintf(Current_Model, GSM_MAX_MODEL_LENGTH, "%s", MessageBuffer+21); + snprintf(Current_Revision, GSM_MAX_REVISION_LENGTH, "SW%s, HW%s", MessageBuffer+41, MessageBuffer+35); +#endif + +#ifdef DEBUG + fprintf(stdout, _("Message: Mobile phone identification received:\n")); + fprintf(stdout, _(" IMEI: %s\n"), Current_IMEI); + fprintf(stdout, _(" Model: %s\n"), Current_Model); + fprintf(stdout, _(" Production Code: %s\n"), MessageBuffer+27); + fprintf(stdout, _(" HW: %s\n"), MessageBuffer+35); + fprintf(stdout, _(" Firmware: %s\n"), MessageBuffer+41); +#endif /* DEBUG */ + + break; + + /* Get group data */ + /* [ID],[name_len],[name].,[ringtone],[graphicon],[lenhi],[lenlo],[bitmap] */ + case 0x11: + + if (CurrentGetBitmap!=NULL) { + if (CurrentGetBitmap->number==MessageBuffer[4]) { + count=MessageBuffer[5]; + memcpy(CurrentGetBitmap->text,MessageBuffer+6,count); + CurrentGetBitmap->text[count]=0; + +#ifdef DEBUG + fprintf(stdout, _("Message: Caller group datas\n")); + fprintf(stdout, _("Caller group name: %s\n"),CurrentGetBitmap->text); +#endif /* DEBUG */ + + count+=6; + + CurrentGetBitmap->ringtone=MessageBuffer[count++]; +#ifdef DEBUG + fprintf(stdout, _("Caller group ringtone ID: %i"),CurrentGetBitmap->ringtone); + if (CurrentGetBitmap->ringtone==16) fprintf(stdout,_(" (default)")); + fprintf(stdout,_("\n")); +#endif /* DEBUG */ + + CurrentGetBitmap->enabled=(MessageBuffer[count++]==1); +#ifdef DEBUG + fprintf(stdout, _("Caller group logo ")); + if (CurrentGetBitmap->enabled) + fprintf(stdout, _("enabled \n")); + else + fprintf(stdout, _("disabled \n")); +#endif /* DEBUG */ + + CurrentGetBitmap->size=MessageBuffer[count++]<<8; + CurrentGetBitmap->size+=MessageBuffer[count++]; +#ifdef DEBUG + fprintf(stdout, _("Bitmap size=%i\n"),CurrentGetBitmap->size); +#endif /* DEBUG */ + + count++; + CurrentGetBitmap->width=MessageBuffer[count++]; + CurrentGetBitmap->height=MessageBuffer[count++]; + count++; + tmp=CurrentGetBitmap->height*CurrentGetBitmap->width/8; + if (CurrentGetBitmap->size>tmp) CurrentGetBitmap->size=tmp; + memcpy(CurrentGetBitmap->bitmap,MessageBuffer+count,CurrentGetBitmap->size); + CurrentGetBitmapError=GE_NONE; + } else { +#ifdef DEBUG + fprintf(stdout, _("Message: Caller group datas received, but group number does not match (%i is not %i)\n"),MessageBuffer[4],CurrentGetBitmap->number); +#endif + } + } else { +#ifdef DEBUG + fprintf(stdout, _("Message: Caller group data received but not requested!\n")); +#endif + } + break; + + /* Get group data error */ + case 0x12: + + CurrentGetBitmapError=GE_UNKNOWN; +#ifdef DEBUG + fprintf(stdout, _("Message: Error attempting to get caller group data.\n")); +#endif + break; + + /* Set group data OK */ + case 0x14: + + CurrentSetBitmapError=GE_NONE; +#ifdef DEBUG + fprintf(stdout, _("Message: Caller group data set correctly.\n")); +#endif + break; + + /* Set group data error */ + case 0x15: + + CurrentSetBitmapError=GE_UNKNOWN; +#ifdef DEBUG + fprintf(stdout, _("Message: Error attempting to set caller group data\n")); +#endif + break; + + default: + +#ifdef DEBUG + fprintf(stdout, _("Message: Unknown message of type 0x03\n")); +#endif /* DEBUG */ + AppendLogText("Unknown msg\n",false); + + break; /* Visual C Don't like empty cases */ + } +} + +static void N6110_Dispatch0x05Message(u16 MessageLength, u8 *MessageBuffer, u8 MessageType) { + + int tmp, count, length; + bool issupported; + +#ifdef DEBUG + int i; +#endif + + switch (MessageBuffer[3]) { + + /* Startup Logo */ + case 0x17: + +#ifdef DEBUG + fprintf(stdout, _("Message: Startup Logo, welcome note and dealer welcome note received.\n")); +#endif + + if (CurrentGetBitmap!=NULL) { + + issupported=false; + + count=5; + + for (tmp=0;tmptype==GSM_StartupLogo) { + CurrentGetBitmap->height=MessageBuffer[count++]; + CurrentGetBitmap->width=MessageBuffer[count++]; + CurrentGetBitmap->size=CurrentGetBitmap->height*CurrentGetBitmap->width/8; + length=CurrentGetBitmap->size; + memcpy(CurrentGetBitmap->bitmap,MessageBuffer+count,length); + } else { + length=MessageBuffer[count++]; + length=length*MessageBuffer[count++]/8; + } + count+=length; +#ifdef DEBUG + fprintf(stdout, _("Startup logo supported - ")); + if (length!=0) { fprintf(stdout, _("currently set\n")); } + else { fprintf(stdout, _("currently empty\n")); } +#endif + if (CurrentGetBitmap->type==GSM_StartupLogo) issupported=true; + break; + case 0x02: + length=MessageBuffer[count]; + if (CurrentGetBitmap->type==GSM_WelcomeNoteText) { + memcpy(CurrentGetBitmap->text,MessageBuffer+count+1,length); + CurrentGetBitmap->text[length]=0; + } +#ifdef DEBUG + fprintf(stdout, _("Startup Text supported - ")); + if (length!=0) + { + fprintf(stdout, _("currently set to \"")); + for (i=0;itype==GSM_WelcomeNoteText) issupported=true; + break; + case 0x03: + length=MessageBuffer[count]; + if (CurrentGetBitmap->type==GSM_DealerNoteText) { + memcpy(CurrentGetBitmap->text,MessageBuffer+count+1,length); + CurrentGetBitmap->text[length]=0; + } +#ifdef DEBUG + fprintf(stdout, _("Dealer Welcome supported - ")); + if (length!=0) + { + fprintf(stdout, _("currently set to \"")); + for (i=0;itype==GSM_DealerNoteText) issupported=true; + break; + } + } + if (issupported) CurrentGetBitmapError=GE_NONE; + else CurrentGetBitmapError=GE_NOTSUPPORTED; + } else { +#ifdef DEBUG + fprintf(stdout, _("Message: Startup logo received but not requested!\n")); +#endif + } + break; + + /* Set startup OK */ + case 0x19: + + CurrentSetBitmapError=GE_NONE; +#ifdef DEBUG + fprintf(stdout, _("Message: Startup logo, welcome note or dealer welcome note correctly set.\n")); +#endif + break; + + /* Set Operator Logo OK */ + case 0x31: + +#ifdef DEBUG + fprintf(stdout, _("Message: Operator logo correctly set.\n")); +#endif + + CurrentSetBitmapError=GE_NONE; + break; + + /* Set Operator Logo Error */ + case 0x32: + +#ifdef DEBUG + fprintf(stdout, _("Message: Error setting operator logo!\n")); +#endif + + CurrentSetBitmapError=GE_UNKNOWN; + break; + + /* Operator Logo */ + /* [location],[netcode x 3],[lenhi],[lenlo],[bitmap] */ + case 0x34: + + if (CurrentGetBitmap!=NULL) { + + count=5; /* Location ignored. */ + + DecodeNetworkCode(MessageBuffer+count, CurrentGetBitmap->netcode); + count=count+3; + +#ifdef DEBUG + fprintf(stdout, _("Message: Operator Logo for %s (%s) network received.\n"), + CurrentGetBitmap->netcode, + GSM_GetNetworkName(CurrentGetBitmap->netcode)); +#endif + + CurrentGetBitmap->size=MessageBuffer[count++]<<8; + CurrentGetBitmap->size+=MessageBuffer[count++]; + count++; + CurrentGetBitmap->width=MessageBuffer[count++]; + CurrentGetBitmap->height=MessageBuffer[count++]; + count++; + tmp=CurrentGetBitmap->height*CurrentGetBitmap->width/8; + if (CurrentGetBitmap->size>tmp) CurrentGetBitmap->size=tmp; + memcpy(CurrentGetBitmap->bitmap,MessageBuffer+count,CurrentGetBitmap->size); + CurrentGetBitmapError=GE_NONE; + } else { +#ifdef DEBUG + fprintf(stdout, _("Message: Operator logo received but not requested!\n")); +#endif + } + + break; + + /* Get op logo error */ + case 0x35: + +#ifdef DEBUG + fprintf(stdout, _("Message: Error getting operator logo!\n")); +#endif + CurrentGetBitmapError=GE_UNKNOWN; + break; + + default: + +#ifdef DEBUG + fprintf(stdout, _("Message: Unknown message of type 0x05\n")); +#endif /* DEBUG */ + AppendLogText("Unknown msg\n",false); + + break; + } +} + +static void N6110_Dispatch0x06Message(u16 MessageLength, u8 *MessageBuffer, u8 MessageType) { + + int tmp; + unsigned char output[160]; + +#ifdef DEBUG + int i; +#endif + + switch (MessageBuffer[3]) { + + case 0x05: + + /* MessageBuffer[3] = 0x05 + MessageBuffer[4] = 0x00 + MessageBuffer[5] = 0x0f + MessageBuffer[6] = 0x03 + MessageBuffer[7] = length of packed message + + This is all I have seen - Gerry Anderson */ + + tmp=GSM_UnpackEightBitsToSeven(0, 82, 82, MessageBuffer+8, output); + +#ifdef DEBUG + + fprintf(stdout, _("Message from Network operator: ")); + + for (i=0; iSender,GSM_UnpackSemiOctetNumber(MessageBuffer+5,true)); + + while (MessageBuffer[count]!=0) { + count++; + } + + count++; + } else { + strcpy(CurrentGetBitmap->Sender,"\0"); + + count+=3; + } + + memcpy(CurrentGetBitmap->text,MessageBuffer+count+1,MessageBuffer[count]); + CurrentGetBitmap->text[MessageBuffer[count]]=0; + + if (MessageBuffer[count]!=0) + count+=MessageBuffer[count]; + + count++; + +#ifdef DEBUG + fprintf(stdout,_("Picture Image received, text \"%s\", sender %s\n"),CurrentGetBitmap->text,CurrentGetBitmap->Sender); +#endif + + CurrentGetBitmap->width=MessageBuffer[count+1]; + CurrentGetBitmap->height=MessageBuffer[count+2]; + CurrentGetBitmap->size=CurrentGetBitmap->height*CurrentGetBitmap->width/8; + + memcpy(CurrentGetBitmap->bitmap,MessageBuffer+count+4,CurrentGetBitmap->size); + + CurrentGetBitmapError=GE_NONE; + break; + + case 0x04: + +#ifdef DEBUG + fprintf(stdout,_("Getting or setting Picture Image - OK\n")); +#endif + CurrentSetBitmapError=GE_NONE; + CurrentGetBitmapError=GE_NONE; + break; + + case 0x05: + +#ifdef DEBUG + fprintf(stdout,_("Setting Picture Image - invalid location or other error\n")); +#endif + CurrentSetBitmapError=GE_UNKNOWN; + break; + + case 0x06: + +#ifdef DEBUG + fprintf(stdout,_("Getting Picture Image - invalid location or other error\n")); +#endif + CurrentGetBitmapError=GE_UNKNOWN; + break; + + default: + +#ifdef DEBUG + fprintf(stdout, _("Unknown message of type 0x47.\n")); +#endif /* DEBUG */ + AppendLogText("Unknown msg\n",false); + break; /* Visual C Don't like empty cases */ + } +} + +#endif /* UCLINUX */ + +void N6110_DispatchACKMessage(u16 MessageLength, u8 *MessageBuffer, u8 MessageType) { + char buffer[50]; + + sprintf(buffer,"Received ACK %02x %02x\n",MessageBuffer[0],MessageBuffer[1]); + AppendLog(buffer,strlen(buffer),false); + +#ifdef DEBUG + fprintf(stdout, _("[Received Ack of type %02x, seq: %2x]\n"), MessageBuffer[0], + MessageBuffer[1]); +#endif /* DEBUG */ + + CurrentLinkOK = true; +} + +static void N6110_Dispatch0xD0Message(u16 MessageLength, u8 *MessageBuffer, u8 MessageType) { + +#ifdef DEBUG + fprintf(stdout, _("Message: The phone is powered on - seq 1.\n")); +#endif /* DEBUG */ + +} + +/* This function is used for parsing the RLP frame into fields. */ +void N6110_RX_HandleRLPMessage(u8 *MessageBuffer) +{ + + RLP_F96Frame frame; + int count; + int valid = true; + + /* We do not need RLP frame parsing to be done when we do not have callback + specified. */ + if (CurrentRLP_RXCallback == NULL) + return; + + /* Anybody know the official meaning of the first two bytes? + Nokia 6150 sends junk frames starting D9 01, and real frames starting + D9 00. We'd drop the junk frames anyway because the FCS is bad, but + it's tidier to do it here. We still need to call the callback function + to give it a chance to handle timeouts and/or transmit a frame */ + if (MessageBuffer[0] == 0xd9 && MessageBuffer[1] == 0x01) + valid = false; + + /* Nokia uses 240 bit frame size of RLP frames as per GSM 04.22 + specification, so Header consists of 16 bits (2 bytes). See section 4.1 + of the specification. */ + + frame.Header[0] = MessageBuffer[2]; + frame.Header[1] = MessageBuffer[3]; + + /* Next 200 bits (25 bytes) contain the Information. We store the + information in the Data array. */ + + for (count = 0; count < 25; count ++) + frame.Data[count] = MessageBuffer[4 + count]; + + /* The last 24 bits (3 bytes) contain FCS. */ + + frame.FCS[0] = MessageBuffer[29]; + frame.FCS[1] = MessageBuffer[30]; + frame.FCS[2] = MessageBuffer[31]; + + /* Here we pass the frame down in the input stream. */ + CurrentRLP_RXCallback(valid ? &frame : NULL); +} + +static void N6110_Dispatch0xF4Message(u16 MessageLength, u8 *MessageBuffer, u8 MessageType) { + +#ifdef DEBUG + fprintf(stdout, _("Message: The phone is powered on - seq 2.\n")); +#endif /* DEBUG */ + +} + +#ifndef UCLINUX + +void N6110_ReplyIncomingSMS(u16 MessageLength, u8 *MessageBuffer, u8 MessageType) { + + GSM_SMSMessage NullSMS; + + switch (MessageBuffer[6]) { + + case 0x00: NullSMS.Type = GST_SMS; NullSMS.folder = GST_INBOX; break; + case 0x01: NullSMS.Type = GST_DR; NullSMS.folder = GST_INBOX; break; + + /* Is it possible ? */ + case 0x02: NullSMS.Type = GST_SMS; NullSMS.folder = GST_OUTBOX; break; + default: NullSMS.Type = GST_UN; break; + } + +#ifdef DEBUG + if (NullSMS.Type == GST_DR) + fprintf(stdout, _("Message: SMS Message (Report) Received\n")); + else + fprintf(stdout, _("Message: SMS Message Received\n")); +#endif /* DEBUG */ + + GSM_DecodeNokiaSMSFrame(&NullSMS, MessageBuffer+7, MessageLength-7); + +#ifdef DEBUG + fprintf(stdout, _("\n")); +#endif /* DEBUG */ +} + +#endif /* UCLINUX */ + +void N6110_DispatchMessage(u16 MessageLength, u8 *MessageBuffer, u8 MessageType) { + + bool unknown=false; + + /* Switch on the basis of the message type byte */ + switch (MessageType) { + + /* Call information */ + case 0x01: + + N6110_Dispatch0x01Message(MessageLength, MessageBuffer, MessageType); + break; + +#ifndef UCLINUX + /* SMS handling */ + case 0x02: + switch (MessageBuffer[3]) { + case 0x02: + case 0x03:N6110_ReplySendSMSMessage(MessageLength,MessageBuffer,MessageType);break; + case 0x10:N6110_ReplyIncomingSMS(MessageLength,MessageBuffer,MessageType);break; + case 0x21:N6110_ReplySetCellBroadcast(MessageLength, MessageBuffer, MessageType);break; + case 0x23:N6110_ReplyReadCellBroadcast(MessageLength, MessageBuffer, MessageType);break; + case 0x31:N6110_ReplySetSMSCenter(MessageLength,MessageBuffer,MessageType);break; + case 0x34: + case 0x35:N6110_ReplyGetSMSCenter(MessageLength,MessageBuffer,MessageType);break; + default :unknown=true;break; + } + break; +#endif /* UCLINUX */ + + /* Phonebook handling */ + case 0x03: + switch (MessageBuffer[3]) { + case 0x02: + case 0x03:N6110_ReplyGetMemoryLocation(MessageLength,MessageBuffer,MessageType);break; + case 0x05: + case 0x06:N6110_ReplyWritePhonebookLocation(MessageLength,MessageBuffer,MessageType);break; + case 0x08: + case 0x09:N6110_ReplyGetMemoryStatus(MessageLength,MessageBuffer,MessageType);break; +#ifndef UCLINUX + case 0x17: + case 0x18:N6110_ReplyGetSpeedDial(MessageLength,MessageBuffer,MessageType);break; + case 0x1a: + case 0x1b:N6110_ReplySetSpeedDial(MessageLength,MessageBuffer,MessageType);break; + default :N6110_Dispatch0x03Message(MessageLength,MessageBuffer,MessageType);break; +#endif /* UCLINUX */ + } + break; + + /* Phone status */ + case 0x04: + switch (MessageBuffer[3]) { + case 0x02:N6110_ReplyRFBatteryLevel(MessageLength,MessageBuffer,MessageType);break; + default :unknown=true;break; + } + break; + +#ifndef UCLINUX + /* Startup Logo, Operator Logo and Profiles. */ + case 0x05: + switch (MessageBuffer[3]) { + case 0x11:N6110_ReplySetProfile (MessageLength,MessageBuffer,MessageType);break; + case 0x14:N6110_ReplyGetProfile (MessageLength,MessageBuffer,MessageType);break; + case 0x1b:N6110_ReplyGetProfile (MessageLength,MessageBuffer,MessageType);break; + case 0x1d:N6110_ReplySetProfile (MessageLength,MessageBuffer,MessageType);break; + case 0x37:N6110_ReplySetRingtone (MessageLength,MessageBuffer,MessageType);break; + case 0x38:N6110_ReplySetRingtone (MessageLength,MessageBuffer,MessageType);break; + default :N6110_Dispatch0x05Message(MessageLength,MessageBuffer,MessageType);break; + } + break; + + /* Network Operator Message to handset -> Gerry Anderson & prepaid info */ + /* Call diverts */ + case 0x06: + switch (MessageBuffer[3]) { + case 0x02: + case 0x03:N6110_ReplyCallDivert (MessageLength,MessageBuffer,MessageType);break; + default :N6110_Dispatch0x06Message(MessageLength,MessageBuffer,MessageType);break; + } + break; + + /* Security code requests */ + case 0x08: + switch (MessageBuffer[3]) { + case 0x08:N6110_ReplyGetSecurityCodeStatus(MessageLength,MessageBuffer,MessageType);break; + case 0x0b:N6110_ReplyEnterSecurityCode (MessageLength,MessageBuffer,MessageType);break; + default :N6110_ReplyEnterSecurityCode (MessageLength,MessageBuffer,MessageType);break; + } + break; +#endif /* UCLINUX */ + + /* SIM login */ + case 0x09: + + N6110_Dispatch0x09Message(MessageLength, MessageBuffer, MessageType); + break; + +#ifndef UCLINUX + /* Network info */ + case 0x0a: + switch (MessageBuffer[3]) { + case 0x71:N6110_ReplyGetNetworkInfo(MessageLength,MessageBuffer,MessageType);break; + default :unknown=true;break; + } + break; + + /* Simulating key pressing */ + case 0x0c: + switch (MessageBuffer[3]) { + case 0x43:N6110_ReplyPressKey(MessageLength,MessageBuffer,MessageType);break; + default :unknown=true;break; + } + break; + + /* Display */ + case 0x0d: + switch (MessageBuffer[3]) { + case 0x50:N6110_ReplyDisplayOutput (MessageLength,MessageBuffer,MessageType);break; + case 0x52:N6110_ReplyGetDisplayStatus(MessageLength,MessageBuffer,MessageType);break; + case 0x54:N6110_ReplyDisplayOutput (MessageLength,MessageBuffer,MessageType);break; + default :unknown=true;break; + } + break; + + /* Phone Clock and Alarm */ + case 0x11: + switch (MessageBuffer[3]) { + case 0x61:N6110_ReplySetDateTime(MessageLength,MessageBuffer,MessageType);break; + case 0x63:N6110_ReplyGetDateTime(MessageLength,MessageBuffer,MessageType);break; + case 0x6c:N6110_ReplySetAlarm (MessageLength,MessageBuffer,MessageType);break; + case 0x6e:N6110_ReplyGetAlarm (MessageLength,MessageBuffer,MessageType);break; + default :unknown=true;break; + } + break; + + /* Calendar notes handling */ + case 0x13: + switch (MessageBuffer[3]) { + case 0x65:N6110_ReplyWriteCalendarNote (MessageLength,MessageBuffer,MessageType);break; + case 0x67:N6110_ReplyGetCalendarNote (MessageLength,MessageBuffer,MessageType);break; + case 0x69:N6110_ReplyDeleteCalendarNote(MessageLength,MessageBuffer,MessageType);break; + default :N6110_Dispatch0x13Message (MessageLength,MessageBuffer,MessageType);break; + } + break; + + /* SMS Messages */ + case 0x14: + switch (MessageBuffer[3]) { + case 0x05: + case 0x06:N6110_ReplySaveSMSMessage (MessageLength,MessageBuffer,MessageType);break; + case 0x08: + case 0x09:N6110_ReplyGetSMSMessage (MessageLength,MessageBuffer,MessageType);break; + case 0x0b:N6110_ReplyDeleteSMSMessage(MessageLength,MessageBuffer,MessageType);break; + case 0x37: + case 0x38:N6110_ReplyGetSMSStatus (MessageLength,MessageBuffer,MessageType);break; + default :unknown=true;break; + } + break; + + /* WAP */ + case 0x3f: + switch (MessageBuffer[3]) { + case 0x01: + case 0x02:N7110_ReplyEnableWAPCommands(MessageLength,MessageBuffer,MessageType);break; + case 0x07: + case 0x08:N7110_ReplyGetWAPBookmark (MessageLength,MessageBuffer,MessageType);break; + case 0x0a: + case 0x0b:N7110_ReplySetWAPBookmark (MessageLength,MessageBuffer,MessageType);break; + case 0x16: + case 0x17: + case 0x1c:N7110_ReplyGetWAPSettings (MessageLength,MessageBuffer,MessageType);break; + default :unknown=true;break; + } + break; +#endif /* UCLINUX */ + + /* Internal phone functions? */ + case 0x40: + switch (MessageBuffer[2]) { + case 0x64:N6110_ReplyEnableExtendedCommands (MessageLength,MessageBuffer,MessageType);break; +#ifndef UCLINUX + case 0x65:N6110_ReplyResetPhoneSettings (MessageLength,MessageBuffer,MessageType);break; +#endif /* UCLINUX */ + case 0x66:N6110_ReplyIMEI (MessageLength,MessageBuffer,MessageType);break; +#ifndef UCLINUX + case 0x6a:N6110_ReplyGetProductProfileSetting(MessageLength,MessageBuffer,MessageType);break; + case 0x6b:N6110_ReplySetProductProfileSetting(MessageLength,MessageBuffer,MessageType);break; + case 0x6e:N6110_ReplyGetSecurityCode (MessageLength,MessageBuffer,MessageType);break; + case 0x7e:N6110_ReplyNetmonitor (MessageLength,MessageBuffer,MessageType);break; + case 0x8a:N6110_ReplySimlockInfo (MessageLength,MessageBuffer,MessageType);break; + case 0x8b:N6110_ReplySetOperatorName (MessageLength,MessageBuffer,MessageType);break; + case 0x8c:N6110_ReplyGetOperatorName (MessageLength,MessageBuffer,MessageType);break; + case 0x8f:N6110_ReplyPlayTone (MessageLength,MessageBuffer,MessageType);break; + case 0x9e:N6110_ReplyGetBinRingtone (MessageLength,MessageBuffer,MessageType);break; + case 0xa0:N6110_ReplySetBinRingtone (MessageLength,MessageBuffer,MessageType);break; +#endif /* UCLINUX */ + case 0xc8:N6110_ReplyHW (MessageLength,MessageBuffer,MessageType);break; + default :N6110_Dispatch0x40Message (MessageLength,MessageBuffer,MessageType);break; + } + break; + +#ifndef UCLINUX + /* Picture Images */ + case 0x47: + + N6110_Dispatch0x47Message(MessageLength, MessageBuffer, MessageType); + break; +#endif /* UCLINUX */ + + /* Mobile phone identification */ + case 0x64: + + N6110_ReplyGetAuthentication(MessageLength, MessageBuffer, MessageType); + break; + + /***** Acknowlegment of our frames. *****/ + case FBUS_FRTYPE_ACK: + + N6110_DispatchACKMessage(MessageLength, MessageBuffer, MessageType); + break; + + /***** Power on message. *****/ + case 0xd0: + + N6110_Dispatch0xD0Message(MessageLength, MessageBuffer, MessageType); + break; + + case 0xd2: + + N6110_ReplyID(MessageLength, MessageBuffer, MessageType); + break; + + /***** RLP frame received. *****/ + case 0xf1: + + N6110_RX_HandleRLPMessage(MessageBuffer); + break; + + /***** Power on message. *****/ + case 0xf4: + + N6110_Dispatch0xF4Message(MessageLength, MessageBuffer, MessageType); + break; + + /***** Unknown message *****/ + /* If you think that you know the exact meaning of other messages - please + let us know. */ + default: + +#ifdef DEBUG + fprintf(stdout, _("Message: Unknown message type.\n")); +#endif /* DEBUG */ + AppendLogText("Unknown msg type\n",false); + + unknown=false; + break; + + } + + if (unknown) { +#ifdef DEBUG + fprintf(stdout, _("Unknown message of type %02x.\n"),MessageType); +#endif + AppendLogText("Unknown msg\n",false); + } +} diff --git a/common/newmodules/newat.c b/common/newmodules/newat.c index 392837e..127dd0e 100644 --- a/common/newmodules/newat.c +++ b/common/newmodules/newat.c @@ -11,6 +11,8 @@ */ +#include "config.h" + /* "Turn on" prototypes in n-at.h */ #define __n_at_c diff --git a/common/newmodules/sniff/sniff.c b/common/newmodules/sniff/sniff.c index 7536d61..d76c4b0 100644 --- a/common/newmodules/sniff/sniff.c +++ b/common/newmodules/sniff/sniff.c @@ -10,6 +10,8 @@ phones. */ + +#include "config.h" /* "Turn on" prototypes in n-sniff.h */ diff --git a/common/protocol/at.c b/common/protocol/at.c index 6afbb18..8a6ce21 100644 --- a/common/protocol/at.c +++ b/common/protocol/at.c @@ -10,6 +10,8 @@ */ +#include "config.h" + /* "Turn on" prototypes in AT.h */ #define __AT_c @@ -42,7 +44,7 @@ GSM_Protocol AT_Functions = { /* Local variables */ u16 BufferCount; -u16 MessageLength; +static u16 MessageLength; u8 MessageBuffer[AT_MAX_RECEIVE_LENGTH * 6]; diff --git a/common/protocol/fbus.c b/common/protocol/fbus.c index 46a6e8f..2cc8aae 100644 --- a/common/protocol/fbus.c +++ b/common/protocol/fbus.c @@ -10,6 +10,8 @@ */ +#include "config.h" + /* "Turn on" prototypes in fbus.h */ #define __fbus_c @@ -31,9 +33,20 @@ #include "protocol/fbus.h" #include "protocol/at.h" #include "newmodules/newat.h" +#ifndef UCLINUX #include "newmodules/n6110.h" +#endif /* UCLINUX */ #include "misc.h" +static GSM_Error FBUS_Initialise(char *port_device, char *initlength, + GSM_ConnectionType connection, + void (*rlp_callback)(RLP_F96Frame *frame)); + +static int FBUS_SendMessage(u16 message_length, u8 message_type, u8 *buffer); +static int FBUS_SendFrame(u16 message_length, u8 message_type, u8 *buffer); +static void FBUS_Terminate(void); +static void FBUS_RX_StateMachine(unsigned char rx_byte); + GSM_Protocol FBUS_Functions = { FBUS_Initialise, FBUS_SendMessage, @@ -44,24 +57,24 @@ GSM_Protocol FBUS_Functions = { }; /* Local variables */ -enum FBUS_RX_States RX_State; +static enum FBUS_RX_States RX_State; -u8 MessageDestination, MessageSource; +static u8 MessageDestination, MessageSource; -u16 BufferCount, MultiBufferCount; +static u16 BufferCount; -u16 MessageLength, MultiMessageLength; +static u16 MessageLength, MultiMessageLength; -bool RX_Multiple = false; +static bool RX_Multiple = false; -u8 MessageType,MultiMessageType; +static u8 MessageType,MultiMessageType; -u8 MessageBuffer[FBUS_MAX_RECEIVE_LENGTH * 6],MultiMessageBuffer[FBUS_MAX_RECEIVE_LENGTH * 6]; +static u8 MessageBuffer[FBUS_MAX_RECEIVE_LENGTH * 6],MultiMessageBuffer[FBUS_MAX_RECEIVE_LENGTH * 6]; -u8 RequestSequenceNumber = 0x00; +static u8 RequestSequenceNumber = 0x00; #ifdef DEBUG -char *N61_PrintDevice(int Device) +static char *N61_PrintDevice(int Device) { switch (Device) { @@ -75,7 +88,7 @@ char *N61_PrintDevice(int Device) /* N61_RX_DisplayMessage is called when a message we don't know about is received so that the user can see what is going back and forth, and perhaps shed some more light/explain another message type! */ -void N61_RX_DisplayMessage() +static void N61_RX_DisplayMessage() { #ifdef DEBUG fprintf(stdout, _("Msg Dest: %s\n"), N61_PrintDevice(MessageDestination)); @@ -203,7 +216,7 @@ int FBUS_SendMessage(u16 message_length, u8 message_type, u8 *buffer) { return (true); } -int FBUS_SendAck(u8 message_type, u8 message_seq) { +static int FBUS_SendAck(u8 message_type, u8 message_seq) { unsigned char request[6]; @@ -276,8 +289,8 @@ void FBUS_RX_StateMachine(unsigned char rx_byte) { case FBUS_RX_Sync: if ((CurrentConnectionType==GCT_FBUS && rx_byte == FBUS_FRAME_ID) || - ((CurrentConnectionType==GCT_Infrared || - CurrentConnectionType==GCT_Tekram) && rx_byte == FBUS_IR_FRAME_ID)) { + 0/*((CurrentConnectionType==GCT_Infrared || + CurrentConnectionType==GCT_Tekram) && rx_byte == FBUS_IR_FRAME_ID)*/) { BufferCount = 0; @@ -511,7 +524,7 @@ void FBUS_RX_StateMachine(unsigned char rx_byte) { } /* Called by initialisation code to open comm port in asynchronous mode. */ -bool FBUS_OpenSerial(void) +static bool FBUS_OpenSerial(void) { /* Uncomment, if want to test first method for DLR3 */ // unsigned char req[3] = {"AT\r"}; @@ -547,6 +560,7 @@ bool FBUS_OpenSerial(void) device_setdtrrts(1, 0); break; +#ifndef UCLINUX case GCT_DLR3: #ifdef DEBUG @@ -627,6 +641,7 @@ bool FBUS_OpenSerial(void) /* It's more complicated and not done here */ break; +#endif /* UCLINUX */ default: #ifdef DEBUG fprintf(stdout,_("Wrong connection type for fbus module. Inform marcin-wiacek@topnet.pl about it\n")); @@ -638,7 +653,7 @@ bool FBUS_OpenSerial(void) } /* Initialise variables and state machine. */ -GSM_Error FBUS_Initialise(char *port_device, char *initlength, +static GSM_Error FBUS_Initialise(char *port_device, char *initlength, GSM_ConnectionType connection, void (*rlp_callback)(RLP_F96Frame *frame)) { diff --git a/common/protocol/fbusirda.c b/common/protocol/fbusirda.c index b84ae9d..d2180af 100644 --- a/common/protocol/fbusirda.c +++ b/common/protocol/fbusirda.c @@ -10,6 +10,8 @@ */ +#include "config.h" + /* "Turn on" prototypes in fbusirda.h */ #define __fbusirda_c diff --git a/common/protocol/mbus.c b/common/protocol/mbus.c index b7cd0ba..a81cd4d 100644 --- a/common/protocol/mbus.c +++ b/common/protocol/mbus.c @@ -10,6 +10,8 @@ */ +#include "config.h" + /* "Turn on" prototypes in MBUS.h */ #define __MBUS_c diff --git a/configure.in b/configure.in index 87ea315..21b3fa6 100644 --- a/configure.in +++ b/configure.in @@ -15,13 +15,17 @@ AC_CANONICAL_SYSTEM AC_PREFIX_DEFAULT("/usr/local") dnl ======================== Default setting -CFLAGS="-O2 -Wall" +test -n "$CFLAGS" || export CFLAGS="-O2 -Wall" ALL_LINGUAS="cs de et fi nl sk pl it" dnl ======================== Checks for programs. AC_PROG_CC +AC_LANG_C AC_PROG_CPP AC_PROG_LEX +if test -z "$AR";then + AC_PATH_PROG(AR, ar, no) +fi AC_PATH_PROG(RM, rm, no) AC_PATH_PROG(FIND, find, no) AC_CHECK_PROGS(MAKE, gmake make) @@ -30,9 +34,22 @@ AC_PROG_INSTALL dnl Let us have $prefix variable aviable here test x"$prefix" = xNONE && prefix="$ac_default_prefix" +AC_ARG_WITH(cfg_model, + [ --with-cfg-model=5110 specifies the mobile phone model],, + [ with_cfg_model="5110" ]) +AC_DEFINE_UNQUOTED(CONFIG_CFG_MODEL, "$with_cfg_model") +AC_ARG_WITH(cfg_port, + [ --with-cfg-port=/dev/ttyS0 specifies the mobile phone port],, + [ with_cfg_port="/dev/ttyS0" ]) +AC_DEFINE_UNQUOTED(CONFIG_CFG_PORT, "$with_cfg_port") +AC_ARG_WITH(cfg_initlength, + [ --with-cfg-initlength=default specifies the mobile phone initlength],, + [ with_cfg_initlength="default" ]) +AC_DEFINE_UNQUOTED(CONFIG_CFG_INITLENGTH, "$with_cfg_initlength") + AC_ARG_ENABLE(debug, [ --enable-debug compile with debug code], - [ CFLAGS="-g -Wall" + [ #CFLAGS="-g -Wall" AC_DEFINE(DEBUG) debug="yes" ], [ debug="no" ] @@ -70,9 +87,9 @@ AC_ARG_WITH(libintl, ) AC_ARG_ENABLE(nls, - [ --disable-nls do not use NLS], + [ --enable-nls force use of NLS], [ USE_NLS=$enableval ], - [ USE_NLS=yes ] + [ USE_NLS=no ] ) if test "$USE_NLS" = "yes"; then @@ -222,7 +239,7 @@ if test "x$PTHREAD_LIBS" = xerror; then fi dnl FIXME: do we really test here if libc contains this function? -if test "x$PTHREAD_LIBS" = xerror; then +if test "x$PTHREAD_LIBS" = xerror -a "x$cross_compiling" = xno; then AC_CHECK_FUNC(pthread_attr_init, PTHREAD_LIBS="", AC_MSG_ERROR(not found library: pthread !!!)) fi @@ -444,8 +461,8 @@ LIBS="$LIBS $NLS_LIBS" PACKAGE=gnokii XPACKAGE=xgnokii -VERSION=`cat VERSION` -XVERSION=`cat xgnokii/VERSION` +AC_DEFINE_UNQUOTED(VERSION, "`cat VERSION`") +AC_DEFINE_UNQUOTED(XVERSION, "`cat xgnokii/VERSION`") HAVE_XGNOKII=$x_support case "$INSTALL" in @@ -465,6 +482,7 @@ AC_CONFIG_HEADER(include/config.h) AC_SUBST(PACKAGE) AC_SUBST(VERSION) +AC_SUBST(AR) AC_SUBST(XVERSION) AC_SUBST(XPACKAGE) AC_SUBST(XGNOKIIDIR) @@ -482,7 +500,6 @@ AC_SUBST(USE_UNIX98PTYS) AC_SUBST(HAVE_XGNOKII) AC_OUTPUT( - include/config.h.in Makefile.global po/Makefile.in packaging/RedHat/gnokii.spec diff --git a/do b/do new file mode 100755 index 0000000..ec3e051 --- /dev/null +++ b/do @@ -0,0 +1,24 @@ +#! /bin/sh + +#target_m68k=1 +enable_debug=1 +cfg_port="ttyS0" + +exec 2>&1 +set -ex +rm -f config.cache +autoheader +autoconf +# rm -f config.cache +if [ -n "$target_m68k" ];then + test -n "$CC" || export CC="m68k-pic-coff-gcc" + test -n "$AR" || export AR="m68k-pic-coff-ar" + test -n "$CFLAGS" || export CFLAGS="-O2 -Wall -fPIC" + test -n "$CPPFLAGS" || export CPPFLAGS="-DUCCOMPAT=1 $CPPFLAGS" + test -n "$LDFLAGS" || export LDFLAGS="gnokii/cleanup.c" +fi +export CPPFLAGS="-DUCLINUX=1 $CPPFLAGS" +./configure --with-cfg-model=5110 --with-cfg-port=/dev/"$cfg_port" --without-x \ + `if [ -n "$enable_debug" ];then echo "--enable-debug --enable-xdebug";fi` +make clean +make diff --git a/getopt/getopt.c b/getopt/getopt.c index 7b4f938..01a8184 100644 --- a/getopt/getopt.c +++ b/getopt/getopt.c @@ -121,6 +121,9 @@ int opterr = 1; This must be initialized on some systems to avoid linking in the system's own getopt implementation. */ +#ifdef UCLINUX +static +#endif /* UCLINUX */ int optopt = '?'; /* Describe how to deal with options that follow non-option ARGV-elements. @@ -666,6 +669,8 @@ _getopt_internal (argc, argv, optstring, longopts, longind, long_only) } } +#ifndef UCLINUX + int getopt (argc, argv, optstring) int argc; @@ -678,6 +683,8 @@ getopt (argc, argv, optstring) 0); } +#endif /* UCLINUX */ + #endif /* _LIBC or not __GNU_LIBRARY__. */ #ifdef TEST diff --git a/getopt/getopt1.c b/getopt/getopt1.c index de8e2ad..a78fbf4 100644 --- a/getopt/getopt1.c +++ b/getopt/getopt1.c @@ -75,6 +75,8 @@ getopt_long (argc, argv, options, long_options, opt_index) but does match a short option, it is parsed as a short option instead. */ +#ifndef UCLINUX + int getopt_long_only (argc, argv, options, long_options, opt_index) int argc; @@ -86,6 +88,8 @@ getopt_long_only (argc, argv, options, long_options, opt_index) return _getopt_internal (argc, argv, options, long_options, opt_index, 1); } +#endif /* UCLINUX */ + #endif /* _LIBC or not __GNU_LIBRARY__. */ diff --git a/gnokii/Makefile b/gnokii/Makefile index 2018e7d..9783b42 100644 --- a/gnokii/Makefile +++ b/gnokii/Makefile @@ -22,11 +22,15 @@ endif all: gnokii -gnokii: $(OBJS) $(TOPDIR)/common/COMMON.o $(TOPDIR)/common/gsm-filetypes.o - $(CC) $(LDFLAGS) $(TARGET_ARCH) $^ $(LOADLIBES) $(LDLIBS) -o $@ +gnokii: $(OBJS) $(TOPDIR)/common/data.a $(TOPDIR)/common/common.a cleanup.o # $(TOPDIR)/common/gsm-filetypes.o + $(CC) $(LDFLAGS) $(TARGET_ARCH) $^ -o $@ +#-L../common -lcommon ##$(LOADLIBES) $(LDLIBS) -$(TOPDIR)/common/COMMON.o: - $(MAKE) -C $(TOPDIR)/common COMMON.o +$(TOPDIR)/common/common.a: + $(MAKE) -C $(TOPDIR)/common common.a + +$(TOPDIR)/common/data.a: + $(MAKE) -C $(TOPDIR)/common data.a $(TOPDIR)/common/gsm-filetypes.o: $(MAKE) -C $(TOPDIR)/common gsm-filetypes.o @@ -43,7 +47,7 @@ gnokiilib: $(OBJS) $(TOPDIR)/common/libmygnokii.so makelib: gnokiilib clean: - $(RM) $(OBJS) *~ depend gnokii gnokiilib *.exe core *.bak + $(RM) $(OBJS) cleanup.o *~ depend gnokii gnokiilib *.exe core *.bak install: all $(INSTALL) -d $(bindir) diff --git a/gnokii/gnokii.c b/gnokii/gnokii.c index 9daceb9..82b2b8b 100644 --- a/gnokii/gnokii.c +++ b/gnokii/gnokii.c @@ -11,6 +11,8 @@ */ +#include "config.h" + #include #include #include @@ -19,6 +21,11 @@ #include #include +#ifdef UCLINUX +/* or "getopt.h" would include insufficient getopt.h from uClinux */ +#include "../getopt/getopt.h" +#endif /* UCLINUX */ + #ifndef VC6 #if defined(__svr4__) || defined(__FreeBSD__) # include /* for bzero */ @@ -53,32 +60,49 @@ #include "gsm-common.h" #include "gsm-api.h" #include "gsm-networks.h" +#ifndef UCLINUX #include "gsm-ringtones.h" #include "gsm-bitmaps.h" #include "gsm-wap.h" #include "gsm-sms.h" #include "gsm-datetime.h" +#endif /* UCLINUX */ #include "gsm-phonebook.h" +#ifndef UCLINUX #include "gsm-calendar.h" +#endif /* UCLINUX */ #include "gsm-coding.h" +#ifndef UCLINUX #include "newmodules/n6110.h" +#endif #include "files/cfgreader.h" +#ifndef UCLINUX #include "files/gsm-filetypes.h" +#endif /* UCLINUX */ #include "gnokii.h" +#ifdef UCLINUX +#include "data/virtmodem.h" +#endif /* UCLINUX */ #ifdef USE_NLS #include #endif -char *model; /* Model from .gnokiirc file. */ -char *Port; /* Port from .gnokiirc file */ -char *Initlength; /* Init length from .gnokiirc file */ -char *Connection; /* Connection type from .gnokiirc file */ +static char *model; /* Model from .gnokiirc file. */ +static char *Port; /* Port from .gnokiirc file */ +static char *Initlength; /* Init length from .gnokiirc file */ +static char *Connection; /* Connection type from .gnokiirc file */ +#ifndef UCLINUX char *SynchronizeTime; /* If we set date and time from computer to phone (from .gnokiirc file) */ -char *BinDir; /* Binaries directory from .gnokiirc file - not used here yet */ +#endif /* UCLINUX */ +static char *BinDir; /* Binaries directory from .gnokiirc file - not used here yet */ -GSM_SMSMessage SMS[4]; +#ifdef DEBUG +static GSM_SMSMessage SMS[4]; +#endif +#ifndef UCLINUX + char *GetProfileCallAlertString(int code) { switch (code) { @@ -214,7 +238,7 @@ char *GetProfileCallerGroups(int code) return BufferProfileGroups; } -char *print_error(GSM_Error e) +static char *print_error(GSM_Error e) { // case GE_DEVICEOPENFAILED: return "Couldn't open specified serial device."; @@ -264,7 +288,6 @@ char *print_error(GSM_Error e) } } - GSM_Error GSM_ReadRingtoneFileOnConsole(char *FileName, GSM_Ringtone *ringtone) { GSM_Error error; @@ -537,7 +560,9 @@ int GSM_SendMultiPartSMSOnConsole(GSM_MultiSMSMessage *MultiSMS, int argnum, int return 0; } -int GSM_SaveMultiPartSMSOnConsole(GSM_MultiSMSMessage *MultiSMS, int argnum, int argc, char *argv[], +#endif /* UCLINUX */ + +static int GSM_SaveMultiPartSMSOnConsole(GSM_MultiSMSMessage *MultiSMS, int argnum, int argc, char *argv[], bool inter, bool unicode, bool profile, bool scale) { int w,i; @@ -663,6 +688,8 @@ int GSM_SaveMultiPartSMSOnConsole(GSM_MultiSMSMessage *MultiSMS, int argnum, int return 0; } +#ifndef UCLINUX + void GSM_PlayRingtoneOnConsole(GSM_Ringtone *ringtone) { int i; @@ -682,9 +709,11 @@ void GSM_PlayRingtoneOnConsole(GSM_Ringtone *ringtone) GSM->PlayTone(255*255,0); } +#endif /* UCLINUX */ + /* This function shows the copyright and some informations usefull for debugging. */ -int version(void) +static int version(void) { fprintf(stdout, _("GNOKII Version %s\n" @@ -698,22 +727,48 @@ int version(void) /* The function usage is only informative - it prints this program's usage and command-line options. */ -int usage(void) +static int usage(void) { - fprintf(stdout, _(" usage: gnokii [--help|--monitor [-noloop|-nl]|--version]\n" + fprintf(stdout, _(" usage: gnokii [--help] [--version]\n" + )); +#ifndef UCLINUX +" gnokii --monitor [-noloop|-nl]\n" + )); +#endif /* UCLINUX */ + + fprintf(stdout, _( " gnokii --getmemory memory_type [start [end]] [-short|-v30|-v21|-v]\n" " gnokii --writephonebook [-i]\n" + )); + +#ifndef UCLINUX + fprintf(stdout, _( " gnokii --sendphonebookentry destination memory_type location\n" " [--smsc message_center_number] [--smscno message_center_index]\n" " [-s] [-v n] [-d]\n" + )); +#endif /* UCLINUX */ + + fprintf(stdout, _( " gnokii --savephonebookentry memory_type location\n" " [--smsc message_center_number] [--smscno message_center_index]\n" " [-r] [-i] [-s] [-a] [--name name]\n" + )); + +#ifndef UCLINUX + fprintf(stdout, _( " gnokii --getvoicemailbox\n" + )); +#endif /* UCLINUX */ + + fprintf(stdout, _( " gnokii --getspeeddial number\n" " gnokii --setspeeddial number memory_type location\n\n" + )); +#ifndef UCLINUX + fprintf(stdout, _( " gnokii --getsms memory_type start [end] [-f file]\n" " gnokii --getsmsstatus\n" " gnokii --getsmsfolders\n" @@ -814,10 +869,25 @@ int usage(void) " gnokii --sendprofile destination profile_name ringtonefile\n" " picturefile [--smsc message_center_number]\n" " [--smscno message_center_index] [-s] [-v n] [-d] [--scale]\n\n" + )); +#endif /* UCLINUX */ + fprintf(stdout, _( " gnokii --reset [soft|hard]\n" + )); + +#ifndef UCLINUX + fprintf(stdout, _( " gnokii --dialvoice number\n" + )); +#endif /* UCLINUX */ + + fprintf(stdout, _( " gnokii --cancelcall\n" + )); + +#ifndef UCLINUX + fprintf(stdout, _( " gnokii --displayoutput\n" " gnokii --presskeysequence sequence\n" " gnokii --backupsettings file\n" @@ -834,8 +904,15 @@ int usage(void) " gnokii --phonetests\n" " gnokii --simlock\n" " gnokii --getdisplaystatus\n" + )); +#endif /* UCLINUX */ + + fprintf(stdout, _( " gnokii --identify\n\n" + )); +#ifndef UCLINUX + fprintf(stdout, _( " gnokii --getwapbookmark location\n" " gnokii --setwapbookmark title url [location]\n" " gnokii --sendwapbookmark location destination\n" @@ -870,13 +947,21 @@ int usage(void) )); #endif +#endif /* UCLINUX */ + +#ifdef UCLINUX + fprintf(stdout, _( +" gnokii --gnokiid [--debug]\n" + )); +#endif + return 0; } /* fbusinit is the generic function which waits for the FBUS link. The limit is 10 seconds. After 10 seconds we quit. */ -void fbusinit(void (*rlp_handler)(RLP_F96Frame *frame)) +static void fbusinit(void (*rlp_handler)(RLP_F96Frame *frame)) { int count=0; @@ -888,7 +973,7 @@ void fbusinit(void (*rlp_handler)(RLP_F96Frame *frame)) #endif /* Initialise the code for the GSM interface. */ - error = GSM_Initialise(model, Port, Initlength, GetConnectionTypeFromString(Connection), rlp_handler, SynchronizeTime); + error = GSM_Initialise(model, Port, Initlength, GetConnectionTypeFromString(Connection), rlp_handler, ""/*SynchronizeTime*/); if (error != GE_NONE) { fprintf(stderr, _("GSM/FBUS init failed! (Unknown model ?). Quitting.\n")); @@ -909,7 +994,7 @@ void fbusinit(void (*rlp_handler)(RLP_F96Frame *frame)) /* This function checks that the argument count for a given options is withing an allowed range. */ -int checkargs(int opt, struct gnokii_arg_len gals[], int argc) +static int checkargs(int opt, struct gnokii_arg_len gals[], int argc) { int i; @@ -943,6 +1028,8 @@ int checkargs(int opt, struct gnokii_arg_len gals[], int argc) else return 1; } +static int gnokiid(int argc, char *argv[]); + /* Main function - handles command line arguments, passes them to separate functions accordingly. */ @@ -960,14 +1047,19 @@ int main(int argc, char *argv[]) { "help", no_argument, NULL, OPT_HELP },// Display usage. { "version", no_argument, NULL, OPT_VERSION },// Display version and build information. +#ifndef UCLINUX { "getsmsfolders", no_argument, NULL, OPT_GETSMSFOLDERS },// Gets SMS folders { "getsmsstatus", no_argument, NULL, OPT_GETSMSSTATUS },// Get SMS Folder Status +#endif /* UCLINUX */ { "identify", no_argument, NULL, OPT_IDENTIFY },// Identify +#ifndef UCLINUX { "pmon", no_argument, NULL, OPT_PMON },// For development purposes: run in passive monitoring mode { "foogle", no_argument, NULL, OPT_FOOGLE },// For development purposes: insert you function calls here { "getdatetime", no_argument, NULL, OPT_GETDATETIME },// Get date and time mode { "getalarm", no_argument, NULL, OPT_GETALARM },// Get alarm +#endif /* UCLINUX */ { "cancelcall", no_argument, NULL, OPT_CANCELCALL },// Cancel Call +#ifndef UCLINUX { "getdisplaystatus", no_argument, NULL, OPT_GETDISPLAYSTATUS },// Get display status mode { "allringtones", no_argument, NULL, OPT_ALLRINGTONES },/* Displays names of available ringtones */ { "displayoutput", no_argument, NULL, OPT_DISPLAYOUTPUT },/* Show texts from phone's display */ @@ -979,8 +1071,10 @@ int main(int argc, char *argv[]) { "receivesms", no_argument, NULL, OPT_RECEIVESMS }, { "setoperatorname", optional_argument, NULL, OPT_SETOPERATORNAME },/* Set downloaded operator name */ { "setdatetime", optional_argument, NULL, OPT_SETDATETIME },// Set date and time +#endif /* UCLINUX */ { "writephonebook", optional_argument, NULL, OPT_WRITEPHONEBOOK },// Write phonebook (memory) mode { "reset", optional_argument, NULL, OPT_RESET },// Resets the phone +#ifndef UCLINUX { "monitor", optional_argument, NULL, OPT_MONITOR },// Monitor mode { "setlogo", optional_argument, NULL, OPT_SETLOGO },// Set logo { "getprofile", optional_argument, NULL, OPT_GETPROFILE },// Show profile @@ -991,11 +1085,15 @@ int main(int argc, char *argv[]) { "sendcalendarnote", required_argument, NULL, OPT_SENDCALENDARNOTE }, { "savecalendarnote", required_argument, NULL, OPT_SAVECALENDARNOTE }, { "sendphonebookentry", required_argument, NULL, OPT_SENDPHONEBOOKENTRY}, +#endif /* UCLINUX */ { "savephonebookentry", required_argument, NULL, OPT_SAVEPHONEBOOKENTRY}, +#ifndef UCLINUX { "deletecalendarnote", required_argument, NULL, OPT_DELCALENDARNOTE },// Delete calendar note mode +#endif /* UCLINUX */ { "getmemory", required_argument, NULL, OPT_GETMEMORY },// Get memory mode { "getspeeddial", required_argument, NULL, OPT_GETSPEEDDIAL },// Get speed dial mode { "setspeeddial", required_argument, NULL, OPT_SETSPEEDDIAL },// Set speed dial mode +#ifndef UCLINUX { "getsms", required_argument, NULL, OPT_GETSMS },// Get SMS message mode { "deletesms", required_argument, NULL, OPT_DELETESMS },// Delete SMS message mode { "sendsms", required_argument, NULL, OPT_SENDSMS },// Send SMS message mode @@ -1047,6 +1145,11 @@ int main(int argc, char *argv[]) { "sniff", optional_argument, NULL, OPT_SNIFFER },// Will show datas from port { "decodefile", required_argument, NULL, OPT_DECODEFILE },//decode input file #endif +#endif /* UCLINUX */ + +#ifdef UCLINUX + { "gnokiid", optional_argument, NULL, OPT_GNOKIID },// gnokiid mode +#endif /* UCLINUX */ { 0, 0, 0, 0}, }; @@ -1057,6 +1160,7 @@ int main(int argc, char *argv[]) struct gnokii_arg_len gals[] = { +#ifndef UCLINUX { OPT_MONITOR, 0, 1, 0 }, #ifdef SECURITY @@ -1081,9 +1185,11 @@ int main(int argc, char *argv[]) { OPT_SAVEPHONEBOOKENTRY,2, 9, 0 }, { OPT_SENDPHONEBOOKENTRY,3, 9, 0 }, { OPT_DELCALENDARNOTE, 1, 1, 0 }, +#endif /* UCLINUX */ { OPT_GETMEMORY, 2, 4, 0 }, { OPT_GETSPEEDDIAL, 1, 1, 0 }, { OPT_SETSPEEDDIAL, 3, 3, 0 }, +#ifndef UCLINUX { OPT_GETSMS, 2, 5, 0 }, { OPT_DELETESMS, 2, 3, 0 }, { OPT_SENDSMS, 1,10, 0 }, @@ -1101,11 +1207,15 @@ int main(int argc, char *argv[]) { OPT_SETRINGTONE, 1, 3, 0 }, { OPT_GETRINGTONE, 1, 2, 0 }, { OPT_PRESSKEYSEQUENCE, 1, 1, 0 }, +#endif /* UCLINUX */ { OPT_RESET, 0, 1, 0 }, +#ifndef UCLINUX { OPT_GETPROFILE, 0, 1, 0 }, { OPT_SETPROFILE, 3, 3, 0 }, { OPT_SENDPROFILE, 4,10, 0 }, +#endif /* UCLINUX */ { OPT_WRITEPHONEBOOK, 0, 1, 0 }, +#ifndef UCLINUX { OPT_PLAYRINGTONE, 1, 1, 0 }, { OPT_COMPOSER, 1, 1, 0 }, { OPT_RINGTONECONVERT, 2, 2, 0 }, @@ -1124,6 +1234,11 @@ int main(int argc, char *argv[]) { OPT_SAVEWAPSETTINGS, 1, 9, 0 }, { OPT_SENDWAPSETTINGS, 2, 9, 0 }, { OPT_DIVERT, 3, 5, 0 }, +#endif /* UCLINUX */ + +#ifdef UCLINUX + { OPT_GNOKIID, 0, 1, 0 }, +#endif /* UCLINUX */ { 0, 0, 0, 0 }, }; @@ -1143,7 +1258,7 @@ int main(int argc, char *argv[]) #endif /* Read config file */ - if (CFG_ReadConfig(&model, &Port, &Initlength, &Connection, &BinDir, &SynchronizeTime,false) < 0) { + if (CFG_ReadConfig(&model, &Port, &Initlength, &Connection, &BinDir, false) < 0) { exit(-1); } @@ -1195,14 +1310,17 @@ int main(int argc, char *argv[]) // Then, options with no arguments case OPT_HELP: rc = usage(); break; case OPT_VERSION: rc = version(); break; +#ifndef UCLINUX case OPT_MONITOR: rc = monitormode(nargc, nargv); break; case OPT_GETSMSFOLDERS: rc = getsmsfolders(); break; case OPT_GETDATETIME: rc = getdatetime(); break; case OPT_GETALARM: rc = getalarm(); break; case OPT_GETDISPLAYSTATUS: rc = getdisplaystatus(); break; case OPT_PMON: rc = pmon(); break; +#endif /* UCLINUX */ case OPT_WRITEPHONEBOOK: rc = writephonebook(nargc, nargv);break; +#ifndef UCLINUX #ifdef SECURITY case OPT_ENTERSECURITYCODE: rc = entersecuritycode(optarg); break; case OPT_GETSECURITYCODESTATUS: rc = getsecuritycodestatus(); break; @@ -1221,17 +1339,23 @@ int main(int argc, char *argv[]) case OPT_SETDATETIME: rc = setdatetime(nargc, nargv); break; case OPT_SETALARM: rc = setalarm(nargv); break; case OPT_DIALVOICE: rc = dialvoice(optarg); break; +#endif /* UCLINUX */ case OPT_CANCELCALL: rc = cancelcall(); break; +#ifndef UCLINUX case OPT_GETCALENDARNOTE: rc = getcalendarnote(nargc, nargv);break; case OPT_DELCALENDARNOTE: rc = deletecalendarnote(optarg);break; case OPT_SAVECALENDARNOTE: rc = savecalendarnote(nargc, nargv);break; case OPT_SENDCALENDARNOTE: rc = sendcalendarnote(nargc, nargv);break; +#endif /* UCLINUX */ case OPT_SAVEPHONEBOOKENTRY: rc = savephonebookentry(nargc, nargv);break; +#ifndef UCLINUX case OPT_SENDPHONEBOOKENTRY: rc = sendphonebookentry(nargc, nargv);break; case OPT_WRITECALENDARNOTE: rc = writecalendarnote(nargv); break; +#endif /* UCLINUX */ case OPT_GETMEMORY: rc = getmemory(nargc, nargv); break; case OPT_GETSPEEDDIAL: rc = getspeeddial(optarg); break; case OPT_SETSPEEDDIAL: rc = setspeeddial(nargv); break; +#ifndef UCLINUX case OPT_GETSMS: rc = getsms(argc, argv); break; case OPT_GETSMSSTATUS: rc = getsmsstatus(argc, argv); break; case OPT_DELETESMS: rc = deletesms(nargc, nargv); break; @@ -1243,7 +1367,9 @@ int main(int argc, char *argv[]) case OPT_GETSMSC: rc = getsmsc(optarg); break; case OPT_RENAMESMSC: rc = renamesmsc(nargc,nargv); break; case OPT_NETMONITOR: rc = netmonitor(optarg); break; +#endif /* UCLINUX */ case OPT_IDENTIFY: rc = identify(); break; +#ifndef UCLINUX case OPT_SETLOGO: rc = setlogo(nargc, nargv); break; case OPT_GETLOGO: rc = getlogo(nargc, nargv); break; case OPT_RECEIVESMS: rc = receivesms(nargc, nargv); break; @@ -1268,7 +1394,9 @@ int main(int argc, char *argv[]) case OPT_PHONETESTS: rc = phonetests(); break; case OPT_SIMLOCKINFO: rc = simlockinfo(); break; case OPT_SENDDTMF: rc = senddtmf(optarg); break; +#endif /* UCLINUX */ case OPT_RESET: rc = reset(nargc,nargv); break; +#ifndef UCLINUX case OPT_GETOPERATORNAME: rc = getoperatorname(); break; case OPT_SETOPERATORNAME: rc = setoperatorname(nargc,nargv);break; case OPT_GETWAPBOOKMARK: rc = getwapbookmark(nargc,nargv);break; @@ -1284,7 +1412,11 @@ int main(int argc, char *argv[]) case OPT_GETVOICEMAILBOX: rc = getvoicemailbox(); break; case OPT_NM_COLLECT: rc = nm_collect(nargc, nargv); break; case OPT_NETMONITORDATA: rc = netmonitordata(nargc, nargv);break; +#endif /* UCLINUX */ +#ifdef UCLINUX + case OPT_GNOKIID: rc = gnokiid(nargc, nargv); break; +#endif /* UCLINUX */ default: fprintf(stderr, _("Unknown option: %d\n"), c); break; } @@ -1299,6 +1431,8 @@ int main(int argc, char *argv[]) exit(-1); } +#ifndef UCLINUX + /* Restores various phone settings from one file */ int restoresettings(char *argv[]) { @@ -1651,7 +1785,7 @@ int sendsms(int argc, char *argv[]) case GSM_DisableFax: case GSM_EnableEmail: case GSM_DisableEmail: - fprintf(stdout,_("Warning: saving %i chars\n"),strlen(MultiSMS.SMS[0].MessageText)); + fprintf(stdout,_("Warning: saving %ld chars\n"),(long)strlen(MultiSMS.SMS[0].MessageText)); msgnum=1; break; default: @@ -1856,7 +1990,7 @@ int savesms(int argc, char *argv[]) case GSM_DisableFax: case GSM_EnableEmail: case GSM_DisableEmail: - fprintf(stdout,_("Warning: saving %i chars\n"),strlen(MultiSMS.SMS[0].MessageText)); + fprintf(stdout,_("Warning: saving %ld chars\n"),(long)strlen(MultiSMS.SMS[0].MessageText)); msgnum=1; break; default: @@ -2705,8 +2839,10 @@ int dialvoice(char *Number) return 0; } +#endif /* UCLINUX */ + /* Cancel a call */ -int cancelcall(void) +static int cancelcall(void) { fbusinit(NULL); @@ -2717,6 +2853,8 @@ int cancelcall(void) return 0; } +#ifndef UCLINUX + int savelogo(int argc, char *argv[]) { GSM_Bitmap bitmap; @@ -3325,7 +3463,7 @@ int setlogo(int argc, char *argv[]) } else { GSM->SetBitmap(&bitmap); GSM->GetBitmap(&oldbit); - fprintf(stderr, _("too long, truncated to \"%s\" (length %i)\n"),oldbit.text,strlen(oldbit.text)); + fprintf(stderr, _("too long, truncated to \"%s\" (length %ld)\n"),oldbit.text,(long)strlen(oldbit.text)); } ok=false; } @@ -3977,6 +4115,53 @@ int monitormode(int argc, char *argv[]) return 0; } +#endif /* UCLINUX */ + +/* Emulation of separate gnokiid binary for uClinux */ + +#ifdef UCLINUX + +static int gnokiid(int argc, char *argv[]) +{ + bool DebugMode; /* When true, run in debug mode */ + char *Model; /* Model from .gnokiirc file. */ + char *Port; /* Port from .gnokiirc file */ + char *Initlength; /* Init length from .gnokiirc file */ + char *Connection; /* Connection type from .gnokiirc file */ + char *BinDir; /* Directory of the mgnokiidev command */ + + /* evaluate for presence of "--debug" argument in parameter */ + DebugMode = false; + if(argc>0) + { + if( strcmp(argv[0],"--debug" )) + { + usage(); + return -1; + } + else + DebugMode = true; + } + +#ifdef DEBUG + fprintf (stderr, _("Entering gnokiid mode...\n")); +#endif + + if (CFG_ReadConfig(&Model, &Port, &Initlength, &Connection, &BinDir, true) < 0) + return(-1); + + if (VM_Initialise(Model, Port, Initlength, GCT_FBUS, BinDir, DebugMode, true, ""/*SynchronizeTime*/) == false) + return (-1); + + VM_Terminate(); + + return 0; +} + +#endif /* UCLINUX */ + +#ifndef UCLINUX + /* Shows texts from phone's display */ int displayoutput() @@ -4461,10 +4646,12 @@ int setprofile(int argc, char *argv[]) } +#endif /* UCLINUX */ + /* Get requested range of memory storage entries and output to stdout in easy-to-parse format */ -int getmemory(int argc, char *argv[]) +static int getmemory(int argc, char *argv[]) { GSM_PhonebookEntry entry; @@ -4696,7 +4883,7 @@ int getmemory(int argc, char *argv[]) /* Read data from stdin, parse and write to phone. The parsing is relatively crude and doesn't allow for much variation from the stipulated format. */ -int writephonebook(int argc, char *args[]) +static int writephonebook(int argc, char *args[]) { GSM_PhonebookEntry entry; @@ -4912,7 +5099,7 @@ int writephonebook(int argc, char *args[]) /* Getting speed dials. */ -int getspeeddial(char *Number) { +static int getspeeddial(char *Number) { GSM_SpeedDial entry; GSM_Error error; @@ -4945,7 +5132,7 @@ int getspeeddial(char *Number) { /* Setting speed dials. */ -int setspeeddial(char *argv[]) { +static int setspeeddial(char *argv[]) { GSM_SpeedDial entry; @@ -4981,6 +5168,8 @@ int setspeeddial(char *argv[]) { return 0; } +#ifndef UCLINUX + /* Getting the status of the display. */ int getdisplaystatus() @@ -5040,7 +5229,9 @@ int netmonitor(char *Mode) return 0; } -int identify( void ) +#endif /* UCLINUX */ + +static int identify( void ) { /* Hopefully is 64 larger as FB38_MAX* / FB61_MAX* */ char imei[64], model[64], rev[64], manufacturer[64]; @@ -5063,6 +5254,8 @@ int identify( void ) return 0; } +#ifndef UCLINUX + int senddtmf(char *String) { @@ -5075,8 +5268,10 @@ int senddtmf(char *String) return 0; } +#endif /* UCLINUX */ + /* Resets the phone */ -int reset(int argc, char *argv[]) +static int reset(int argc, char *argv[]) { unsigned char _type=0x03; @@ -5104,6 +5299,8 @@ int reset(int argc, char *argv[]) return 0; } +#ifndef UCLINUX + /* This is a "convenience" function to allow quick test of new API stuff which doesn't warrant a "proper" command line function. */ @@ -5147,7 +5344,7 @@ int pmon() /* Initialise the code for the GSM interface. */ - error = GSM_Initialise(model, Port, Initlength, connection, RLP_DisplayF96Frame, SynchronizeTime); + error = GSM_Initialise(model, Port, Initlength, connection, RLP_DisplayF96Frame, ""/*SynchronizeTime*/); if (error != GE_NONE) { fprintf(stderr, _("GSM/FBUS init failed! (Unknown model ?). Quitting.\n")); @@ -7643,11 +7840,13 @@ int renamesmsc(int argc, char *argv[]) return 0; } +#endif /* UCLINUX */ + /* * Returns number of sostituited characters. * ... may be useful one day ?? */ -int semicolon_pipe_substitution( GSM_PhonebookEntry *pentry, unsigned int direction ) +static int semicolon_pipe_substitution( GSM_PhonebookEntry *pentry, unsigned int direction ) /* direction = 0 : after reading phone memory ( * 1 : writing phone memory */ @@ -7683,6 +7882,10 @@ int str_substch( char *str, const char toric, const char sost ) return( i_sost ); } +#ifndef UCLINUX + +extern GSM_Error N6110_EnableExtendedCommands (unsigned char status); + /* Allows to set simlock state. With older phone (older 51xx, 61xx) can open them, with older and newer should be able to close them */ @@ -8656,7 +8859,9 @@ int divert(int argc, char *argv[]) return 0; } -int savephonebookentry(int argc, char *argv[]) +#endif /* UCLINUX */ + +static int savephonebookentry(int argc, char *argv[]) { GSM_MultiSMSMessage MultiSMS; GSM_PhonebookEntry entry; @@ -8682,9 +8887,12 @@ int savephonebookentry(int argc, char *argv[]) case GE_NONE: /* Put entry into SMS structure */ +#ifndef UCLINUX if (GetModelFeature(FN_PHONEBOOK)==F_PBK71) { GSM_SavePhonebookEntryToSMS(&MultiSMS,&entry,21); - } else { + } else +#endif /* UCLINUX */ + { GSM_SavePhonebookEntryToSMS(&MultiSMS,&entry,10); } @@ -8701,6 +8909,8 @@ int savephonebookentry(int argc, char *argv[]) return 0; } +#ifndef UCLINUX + int sendphonebookentry(int argc, char *argv[]) { GSM_MultiSMSMessage MultiSMS; @@ -8746,3 +8956,5 @@ int sendphonebookentry(int argc, char *argv[]) return 0; } + +#endif /* UCLINUX */ diff --git a/gnokii/gnokii.h b/gnokii/gnokii.h index dbcf972..2c0e921 100644 --- a/gnokii/gnokii.h +++ b/gnokii/gnokii.h @@ -12,6 +12,8 @@ /* Prototypes */ +#ifndef UCLINUX + int monitormode(int argc, char *argv[]); #ifdef SECURITY @@ -25,10 +27,13 @@ int monitormode(int argc, char *argv[]); int decodefile(int nargc, char *nargv[]); #endif -int getmemory(int argc, char *argv[]); -int writephonebook(int argc, char *argv[]); -int getspeeddial(char *number); -int setspeeddial(char *argv[]); +#endif /* UCLINUX */ + +static int getmemory(int argc, char *argv[]); +static int writephonebook(int argc, char *argv[]); +static int getspeeddial(char *number); +static int setspeeddial(char *argv[]); +#ifndef UCLINUX int getsms(int argc, char *argv[]); int renamesmsc(int argc, char *argv[]); int deletesms(int argc, char *argv[]); @@ -44,13 +49,17 @@ int getdatetime(void); int setalarm(char *argv[]); int getalarm(void); int dialvoice(char *number); -int cancelcall(void); +#endif /* UCLINUX */ +static int cancelcall(void); +#ifndef UCLINUX int getcalendarnote(int argc, char *argv[]); int writecalendarnote(char *argv[]); int deletecalendarnote(char *index); int getdisplaystatus(); int netmonitor(char *_mode); -int identify(void); +#endif /* UCLINUX */ +static int identify(void); +#ifndef UCLINUX int senddtmf(char *String); int foogle(char *argv[]); int pmon(void); @@ -59,7 +68,9 @@ int getlogo(int argc, char *argv[]); int binringtoneconvert(int argc, char *argv[]); int setringtone(int argc, char *argv[]); int getringtone(int argc, char *argv[]); -int reset(int argc, char *argv[]); +#endif /* UCLINUX */ +static int reset(int argc, char *argv[]); +#ifndef UCLINUX int getprofile(int argc, char *argv[]); int setprofile(int argc, char *argv[]); int allringtones(); @@ -98,8 +109,11 @@ int sendcalendarnote(int argc, char *argv[]); int receivesms(int argc, char *argv[]); int getsmsstatus(int argc, char *argv[]); int divert(int argc, char *argv[]); -int savephonebookentry(int argc, char *argv[]); +#endif /* UCLINUX */ +static int savephonebookentry(int argc, char *argv[]); +#ifndef UCLINUX int sendphonebookentry(int argc, char *argv[]); +#endif /* UCLINUX */ typedef enum { OPT_HELP, @@ -184,7 +198,8 @@ typedef enum { OPT_GETSMSSTATUS=145, OPT_DIVERT=146, OPT_SENDWAPSETTINGS=147, - OPT_SETWAPBOOKMARK=148 + OPT_SETWAPBOOKMARK=148, + OPT_GNOKIID=149, } opt_index; struct gnokii_arg_len { @@ -206,8 +221,10 @@ struct keys_table_position { int whatcode; }; +#ifndef UCLINUX + /* for --presskeysequence */ -struct keys_table_position Keys[] = { +static struct keys_table_position Keys[] = { {'m',PHONEKEY_MENU}, {'M',PHONEKEY_MENU}, {'n',PHONEKEY_NAMES}, @@ -239,6 +256,8 @@ struct keys_table_position Keys[] = { {' ',0} }; +#endif /* UCLINUX */ + /* for NETMONITOR */ //maximal number of screens for --nm_collect @@ -274,5 +293,5 @@ typedef struct { unsigned char req_screen[NM_MAX_SCREEN]; } OUT_INFO_MON; -int semicolon_pipe_substitution( GSM_PhonebookEntry *pentry, unsigned int direction ); -int str_substch( char *str, const char toric, const char sost ); +static int semicolon_pipe_substitution( GSM_PhonebookEntry *pentry, unsigned int direction ); +static int str_substch( char *str, const char toric, const char sost ); diff --git a/include/data/at-emulator.h b/include/data/at-emulator.h index 3f95297..2edfb23 100644 --- a/include/data/at-emulator.h +++ b/include/data/at-emulator.h @@ -18,19 +18,11 @@ /* Prototypes */ bool ATEM_Initialise(int read_fd, int write_fd, char *model, char *port); void ATEM_HandleIncomingData(char *buffer, int length); -void ATEM_InitRegisters(void); -void ATEM_StringOut(char *buffer); -void ATEM_ParseAT(char *cmd_buffer); -void ATEM_ParseSMS(char *cmd_buffer); -void ATEM_ParseDIR(char *cmd_buffer); -bool ATEM_CommandPlusC(char **buf); -bool ATEM_CommandPlusG(char **buf); -int ATEM_GetNum(char **p); void ATEM_ModemResult(int code); void ATEM_CallPassup(char c); /* Global variables */ -bool ATEM_Initialised; +extern bool ATEM_Initialised; /* Definition of modem result codes - these are returned to "terminal" numerically or as a string depending on the setting of S12 */ diff --git a/include/data/datapump.h b/include/data/datapump.h index c1e48d1..921610d 100644 --- a/include/data/datapump.h +++ b/include/data/datapump.h @@ -19,7 +19,6 @@ void DP_CallFinished(void); bool DP_Initialise(int read_fd, int write_fd); -int DP_CallBack(RLP_UserInds ind, u8 *buffer, int length); void DP_CallPassup(char c); /* All defines and prototypes from here down are specific to diff --git a/include/data/rlp-common.h b/include/data/rlp-common.h index a03a497..db0dc0f 100644 --- a/include/data/rlp-common.h +++ b/include/data/rlp-common.h @@ -172,10 +172,7 @@ typedef struct { /* Prototypes for functions. */ void RLP_DisplayF96Frame(RLP_F96Frame *frame); -void RLP_DecodeF96Header(RLP_F96Frame *frame, RLP_F96Header *header); -void RLP_DisplayXID(u8 *frame); void RLP_Initialise(bool (*rlp_send_function)(RLP_F96Frame *frame, bool out_dtx), int (*rlp_passup)(RLP_UserInds ind, u8 *buffer, int length)); -void RLP_Init_link_vars(void); void RLP_SetUserRequest(RLP_UserRequests type, bool value); void RLP_Send(char *buffer, int length); diff --git a/include/data/virtmodem.h b/include/data/virtmodem.h index 6fe838d..a619e54 100644 --- a/include/data/virtmodem.h +++ b/include/data/virtmodem.h @@ -15,7 +15,7 @@ /* Prototypes */ -bool VM_Initialise(char *model, +extern bool VM_Initialise(char *model, char *port, char *initlength, GSM_ConnectionType connection, @@ -23,15 +23,6 @@ bool VM_Initialise(char *model, bool debug_mode, bool GSM_Init, char *synchronizetime); -int VM_PtySetup(char *bindir); -void VM_ThreadLoop(void); -void VM_CharHandler(void); -int VM_GetMasterPty(char **name); -void VM_Terminate(void); -GSM_Error VM_GSMInitialise(char *model, - char *port, - char *initlength, - GSM_ConnectionType connection, - char *synchronizetime); +extern void VM_Terminate(void); #endif /* __virtmodem_h */ diff --git a/include/devices/device.h b/include/devices/device.h index 5ad2dd3..fabe975 100644 --- a/include/devices/device.h +++ b/include/devices/device.h @@ -22,6 +22,7 @@ IR (only with 61x0 models) and MBUS (61x0, 640, 6160) */ typedef enum { GCT_FBUS, /* FBUS connection. */ +#ifndef UCLINUX GCT_Infrared, /* FBUS over direct infrared connection - 61xx. */ GCT_Irda, /* FBUS over Irda sockets - 7110, 6210, etc. */ GCT_MBUS, /* MBUS */ @@ -29,23 +30,14 @@ typedef enum { GCT_Tekram, /* FBUS over direct infrared connection (Tekram device) - 61xx. */ GCT_AT, /* AT commands */ GCT_Default /* Old style module */ +#endif /* UCLINUX */ } GSM_ConnectionType; #ifndef WIN32 #include #include "misc.h" - int device_getfd(void); - - int device_open(__const char *__file, int __with_odd_parity); - void device_reset(void); - - size_t device_read(__ptr_t __buf, size_t __nbytes); size_t device_write(__const __ptr_t __buf, size_t __n); - - #ifdef DEBUG - void device_dumpserial(void); - #endif #else size_t device_write(const __ptr_t __buf, size_t __n); #endif diff --git a/include/devices/unixserial.h b/include/devices/unixserial.h index b044d43..c9be583 100644 --- a/include/devices/unixserial.h +++ b/include/devices/unixserial.h @@ -24,18 +24,20 @@ #include "misc.h" -int serial_open(__const char *__file, int __oflag); -int serial_close(int __fd); +#ifndef UCLINUX +extern int serial_open(__const char *__file, int __oflag); +#endif /* UCLINUX */ +extern int serial_close(int __fd); -int serial_opendevice(__const char *__file, int __with_odd_parity, int __with_async, int __with_hw_handshake); +extern int serial_opendevice(__const char *__file, int __with_odd_parity, int __with_async, int __with_hw_handshake); -void serial_setdtrrts(int __fd, int __dtr, int __rts); -void serial_changespeed(int __fd, int __speed); +extern void serial_setdtrrts(int __fd, int __dtr, int __rts); +extern void serial_changespeed(int __fd, int __speed); -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); +extern size_t serial_read(int __fd, __ptr_t __buf, size_t __nbytes); +extern size_t serial_write(int __fd, __const __ptr_t __buf, size_t __n); -int serial_select(int fd, struct timeval *timeout); +extern int serial_select(int fd, struct timeval *timeout); #endif /* __devices_unixserial_h */ diff --git a/include/files/cfgreader.h b/include/files/cfgreader.h index 15513d7..7c0ebba 100644 --- a/include/files/cfgreader.h +++ b/include/files/cfgreader.h @@ -35,6 +35,8 @@ struct CFG_Header { char *section; }; +#ifndef UCLINUX + /* Function prototypes */ struct CFG_Header *CFG_ReadFile(char *filename); @@ -43,10 +45,16 @@ char *CFG_Set(struct CFG_Header *cfg, char *section, char *key, char *value); int CFG_WriteFile(struct CFG_Header *cfg, char *filename); +#endif /* UCLINUX */ + int CFG_ReadConfig(char **model, char **port, char **initlength, - char **connection, char **bindir, char **synchronizetime, + char **connection, char **bindir, bool isgnokiid); +#ifndef UCLINUX + struct CFG_Header *CFG_FindGnokiirc(); +#endif /* UCLINUX */ + #endif /* _CFGREADER_H */ diff --git a/include/gsm-api.h b/include/gsm-api.h index 0ab7718..10cb4b0 100644 --- a/include/gsm-api.h +++ b/include/gsm-api.h @@ -27,12 +27,16 @@ #include "gsm-ringtones.h" #include "gsm-wap.h" +#ifndef UCLINUX + /* Undefined functions in fbus/mbus files */ extern GSM_Error Unimplemented(void); #define UNIMPLEMENTED (void *) Unimplemented extern GSM_Error NotSupported(void); #define NOTSUPPORTED (void *) NotSupported +#endif /* UCLINUX */ + /* Define the structure used to hold pointers to the various API functions. This is in effect the master list of functions provided by the gnokii API. Modules containing the model specific code each contain one of these @@ -288,160 +292,178 @@ extern GSM_Information *GSM_Info; extern GSM_Functions *GSM; extern GSM_Protocol *Protocol; -GSM_PhonebookEntry *CurrentPhonebookEntry; -GSM_Error CurrentPhonebookError; +extern GSM_PhonebookEntry *CurrentPhonebookEntry; +extern GSM_Error CurrentPhonebookError; -GSM_SpeedDial *CurrentSpeedDialEntry; -GSM_Error CurrentSpeedDialError; +#ifndef UCLINUX +extern GSM_SpeedDial *CurrentSpeedDialEntry; +extern GSM_Error CurrentSpeedDialError; +#endif /* UCLINUX */ -unsigned char Current_IMEI[GSM_MAX_IMEI_LENGTH]; -unsigned char Current_Revision[GSM_MAX_REVISION_LENGTH]; -unsigned char Current_Model[GSM_MAX_MODEL_LENGTH]; +extern unsigned char Current_IMEI[GSM_MAX_IMEI_LENGTH]; +extern unsigned char Current_Revision[GSM_MAX_REVISION_LENGTH]; +extern unsigned char Current_Model[GSM_MAX_MODEL_LENGTH]; -GSM_SMSMessage *CurrentSMSMessage; -GSM_Error CurrentSMSMessageError; -int CurrentSMSPointer; +#ifndef UCLINUX +extern GSM_SMSMessage *CurrentSMSMessage; +extern GSM_Error CurrentSMSMessageError; +extern int CurrentSMSPointer; -GSM_SMSFolders *CurrentSMSFolders; -GSM_Error CurrentSMSFoldersError; -int CurrentSMSFoldersCount; +extern GSM_SMSFolders *CurrentSMSFolders; +extern GSM_Error CurrentSMSFoldersError; +extern int CurrentSMSFoldersCount; -GSM_OneSMSFolder CurrentSMSFolder; -GSM_Error CurrentSMSFolderError; -int CurrentSMSFolderID; +extern GSM_OneSMSFolder CurrentSMSFolder; +extern GSM_Error CurrentSMSFolderError; +extern int CurrentSMSFolderID; +#endif /* UCLINUX */ -GSM_MemoryStatus *CurrentMemoryStatus; -GSM_Error CurrentMemoryStatusError; +extern GSM_MemoryStatus *CurrentMemoryStatus; +extern GSM_Error CurrentMemoryStatusError; -GSM_NetworkInfo *CurrentNetworkInfo; -GSM_Error CurrentNetworkInfoError; +#ifndef UCLINUX +extern GSM_NetworkInfo *CurrentNetworkInfo; +extern GSM_Error CurrentNetworkInfoError; -GSM_SMSStatus *CurrentSMSStatus; -GSM_Error CurrentSMSStatusError; +extern GSM_SMSStatus *CurrentSMSStatus; +extern GSM_Error CurrentSMSStatusError; -GSM_MessageCenter *CurrentMessageCenter; -GSM_Error CurrentMessageCenterError; +extern GSM_MessageCenter *CurrentMessageCenter; +extern GSM_Error CurrentMessageCenterError; -int *CurrentSecurityCodeStatus; -GSM_Error CurrentSecurityCodeError; -GSM_SecurityCode *CurrentSecurityCode; +extern int *CurrentSecurityCodeStatus; +extern GSM_Error CurrentSecurityCodeError; +extern GSM_SecurityCode *CurrentSecurityCode; -GSM_DateTime *CurrentDateTime; -GSM_Error CurrentDateTimeError; +extern GSM_DateTime *CurrentDateTime; +extern GSM_Error CurrentDateTimeError; -GSM_Error CurrentResetPhoneSettingsError; +extern GSM_Error CurrentResetPhoneSettingsError; -GSM_DateTime *CurrentAlarm; -GSM_Error CurrentAlarmError; +extern GSM_DateTime *CurrentAlarm; +extern GSM_Error CurrentAlarmError; -GSM_CalendarNote *CurrentCalendarNote; -GSM_Error CurrentCalendarNoteError; +extern GSM_CalendarNote *CurrentCalendarNote; +extern GSM_Error CurrentCalendarNoteError; -GSM_NotesInfo CurrentCalendarNotesInfo,*CurrentCalendarNotesInfo2; -GSM_Error CurrentCalendarNotesInfoError; +extern GSM_NotesInfo CurrentCalendarNotesInfo,*CurrentCalendarNotesInfo2; +extern GSM_Error CurrentCalendarNotesInfoError; -int *CurrentFirstCalendarFreePos; -GSM_Error CurrentFirstCalendarFreePosError; +extern GSM_Error CurrentSetDateTimeError; +extern GSM_Error CurrentSetAlarmError; -GSM_Error CurrentSetDateTimeError; -GSM_Error CurrentSetAlarmError; +extern int *CurrentFirstCalendarFreePos; +extern GSM_Error CurrentFirstCalendarFreePosError; +#endif /* UCLINUX */ -GSM_Error CurrentEnableExtendedCommandsError; +extern GSM_Error CurrentEnableExtendedCommandsError; -int CurrentRFLevel, +extern int CurrentRFLevel, CurrentBatteryLevel, CurrentPowerSource; -int CurrentDisplayStatus; -GSM_Error CurrentDisplayStatusError; +#ifndef UCLINUX +extern int CurrentDisplayStatus; +extern GSM_Error CurrentDisplayStatusError; -char *CurrentNetmonitor; -GSM_Error CurrentNetmonitorError; +extern char *CurrentNetmonitor; +extern GSM_Error CurrentNetmonitorError; -GSM_Bitmap *CurrentGetBitmap; -GSM_Error CurrentGetBitmapError; +extern GSM_Bitmap *CurrentGetBitmap; +extern GSM_Error CurrentGetBitmapError; -GSM_Error CurrentSetBitmapError; +extern GSM_Error CurrentSetBitmapError; -GSM_Error CurrentSendDTMFError; +extern GSM_Error CurrentSendDTMFError; -GSM_Profile *CurrentProfile; -GSM_Error CurrentProfileError; +extern GSM_Profile *CurrentProfile; +extern GSM_Error CurrentProfileError; -GSM_Error CurrentDisplayOutputError; +extern GSM_Error CurrentDisplayOutputError; -GSM_CBMessage *CurrentCBMessage; -GSM_Error CurrentCBError; +extern GSM_CBMessage *CurrentCBMessage; +extern GSM_Error CurrentCBError; -int CurrentPressKeyEvent; -GSM_Error CurrentPressKeyError; +extern int CurrentPressKeyEvent; +extern GSM_Error CurrentPressKeyError; -GSM_Error CurrentPlayToneError; +extern GSM_Error CurrentPlayToneError; +#endif /* UCLINUX */ -GSM_Error CurrentDialVoiceError; +extern GSM_Error CurrentDialVoiceError; -GSM_Error CurrentGetOperatorNameError; -GSM_Network *CurrentGetOperatorNameNetwork; -GSM_Error CurrentSetOperatorNameError; +#ifndef UCLINUX +extern GSM_Error CurrentGetOperatorNameError; +extern GSM_Network *CurrentGetOperatorNameNetwork; +extern GSM_Error CurrentSetOperatorNameError; +#endif /* UCLINUX */ -GSM_Error CurrentGetIMEIError; +extern GSM_Error CurrentGetIMEIError; -GSM_Error CurrentGetHWError; +extern GSM_Error CurrentGetHWError; -unsigned char CurrentPPS[4]; -GSM_Error CurrentProductProfileSettingsError; +#ifndef UCLINUX +extern unsigned char CurrentPPS[4]; +extern GSM_Error CurrentProductProfileSettingsError; -char CurrentIncomingCall[20]; +extern char CurrentIncomingCall[20]; -GSM_Error CurrentBinRingtoneError; -GSM_BinRingtone *CurrentGetBinRingtone; +extern GSM_Error CurrentBinRingtoneError; +extern GSM_BinRingtone *CurrentGetBinRingtone; -GSM_Error CurrentRingtoneError; +extern GSM_Error CurrentRingtoneError; +#endif /* UCLINUX */ -GSM_Error CurrentMagicError; +extern GSM_Error CurrentMagicError; -GSM_Error CurrentSimlockInfoError; -GSM_AllSimlocks *CurrentSimLock; +#ifndef UCLINUX +extern GSM_Error CurrentSimlockInfoError; +extern GSM_AllSimlocks *CurrentSimLock; -GSM_Error CurrentGetWAPBookmarkError; -GSM_Error CurrentSetWAPBookmarkError; -GSM_WAPBookmark *WAPBookmark; +extern GSM_Error CurrentGetWAPBookmarkError; +extern GSM_Error CurrentSetWAPBookmarkError; +extern GSM_WAPBookmark *WAPBookmark; -GSM_Error CurrentGetWAPSettingsError; -GSM_WAPSettings *WAPSettings; +extern GSM_Error CurrentGetWAPSettingsError; +extern GSM_WAPSettings *WAPSettings; -GSM_Error CurrentCallDivertError; -GSM_CallDivert *CurrentCallDivert; +extern GSM_Error CurrentCallDivertError; +extern GSM_CallDivert *CurrentCallDivert; -char *CurrentManufacturer; +extern char *CurrentManufacturer; +#endif /* UCLINUX */ /* This is the connection type used in gnokii. */ -GSM_ConnectionType CurrentConnectionType; +extern GSM_ConnectionType CurrentConnectionType; /* Pointer to a callback function used to return changes to a calls status */ /* This saves unreliable polling */ -void (*CurrentCallPassup)(char c); +extern void (*CurrentCallPassup)(char c); /* Pointer to callback function in user code to be called when RLP frames are received. */ -void (*CurrentRLP_RXCallback)(RLP_F96Frame *frame); +extern void (*CurrentRLP_RXCallback)(RLP_F96Frame *frame); /* Used to disconnect the call */ -u8 CurrentCallSequenceNumber; +extern u8 CurrentCallSequenceNumber; -bool CurrentLinkOK; +extern bool CurrentLinkOK; -bool CurrentRequestTerminate; +extern bool CurrentRequestTerminate; -bool CurrentDisableKeepAlive; +#ifndef UCLINUX +extern bool CurrentDisableKeepAlive; +#endif /* UCLINUX */ /* Prototype for the functions actually provided by gsm-api.c. */ -GSM_Error GSM_Initialise(char *model, char *device, char *initlength, GSM_ConnectionType connection, void (*rlp_callback)(RLP_F96Frame *frame), char* SynchronizeTime); +extern GSM_Error GSM_Initialise(char *model, char *device, char *initlength, GSM_ConnectionType connection, void (*rlp_callback)(RLP_F96Frame *frame), char* SynchronizeTime); -bool CheckModel (GSM_Information InfoToCheck, char *model, GSM_ConnectionType connection); +#ifndef UCLINUX +extern bool CheckModel (GSM_Information InfoToCheck, char *model, GSM_ConnectionType connection); +#endif /* UCLINUX */ -char *GetMygnokiiVersion(); +extern char *GetMygnokiiVersion(); typedef enum { F_CAL61=0,/*Calendar in 6110 style - 4 types,...*/ @@ -510,10 +532,15 @@ typedef struct { } OnePhoneModel; extern char *GetModelName (); -int GetModelFeature (featnum_index num); +extern int GetModelFeature (featnum_index num); +#ifndef UCLINUX extern bool AppendLog(u8 *buffer, int length,bool format); extern bool AppendLogText(u8 *buffer,bool format); +#else /* UCLINUX */ +#define AppendLog(buffer,length,format) +#define AppendLogText(buffer,format) +#endif /* UCLINUX */ typedef struct { int SIMPhonebookUsed; diff --git a/include/gsm-coding.h b/include/gsm-coding.h index 3414f1f..6b802e6 100644 --- a/include/gsm-coding.h +++ b/include/gsm-coding.h @@ -11,11 +11,14 @@ #ifndef __gsm_coding_h #define __gsm_coding_h +#ifndef UCLINUX extern void EncodeDefault (unsigned char* dest, const unsigned char* src, int len); extern void DecodeDefault (unsigned char* dest, const unsigned char* src, int len); +#endif /* UCLINUX */ extern void EncodeUnicode (unsigned char* dest, const unsigned char* src, int len); extern void DecodeUnicode (unsigned char* dest, const unsigned char* src, int len); extern void EncodeUTF8 (unsigned char* dest, const unsigned char* src, int len); +#ifndef UCLINUX extern void DecodeUTF8 (unsigned char* dest, const unsigned char* src, int len); extern void DecodeHexBin (unsigned char* dest, const unsigned char* src, int len); extern void EncodeHexBin (unsigned char* dest, const unsigned char* src, int len); @@ -32,5 +35,6 @@ extern int DecodeWithHexBinAlphabet (unsigned char mychar); extern unsigned char EncodeWithHexBinAlphabet (int digit); extern unsigned char EncodeWithBCDAlphabet (int value); extern int DecodeWithBCDAlphabet (unsigned char value); +#endif /* UCLINUX */ #endif diff --git a/include/gsm-networks.h b/include/gsm-networks.h index 367a964..177dd67 100644 --- a/include/gsm-networks.h +++ b/include/gsm-networks.h @@ -48,10 +48,12 @@ typedef struct { /* These functions are used to search the structure defined above.*/ char *GSM_GetNetworkName(char *NetworkCode); +#ifndef UCLINUX char *GSM_GetNetworkCode(char *NetworkName); char *GSM_GetCountryName(char *CountryCode); char *GSM_GetCountryCode(char *CountryName); +#endif /* UCLINUX */ void EncodeNetworkCode(unsigned char* buffer, unsigned char* output); void DecodeNetworkCode(unsigned char* buffer, unsigned char* output); diff --git a/include/gsm-sms.h b/include/gsm-sms.h index fac18b9..6870150 100644 --- a/include/gsm-sms.h +++ b/include/gsm-sms.h @@ -266,27 +266,35 @@ typedef struct { TP-Status-Report-Request (1 bit). See GSM 03.40 section 9.2.3.5 */ } GSM_ETSISMSMessage; -int GSM_PackSemiOctetNumber (u8 *Number, u8 *Output, bool semioctet); -char *GSM_UnpackSemiOctetNumber(u8 *Number, bool semioctet); +#ifndef UCLINUX +extern int GSM_PackSemiOctetNumber (u8 *Number, u8 *Output, bool semioctet); +extern char *GSM_UnpackSemiOctetNumber(u8 *Number, bool semioctet); -int GSM_UnpackEightBitsToSeven(int fillbits, int in_length, int out_length, unsigned char *input, unsigned char *output); -int GSM_PackSevenBitsToEight (int offset, unsigned char *input, unsigned char *output); +extern int GSM_UnpackEightBitsToSeven(int fillbits, int in_length, int out_length, unsigned char *input, unsigned char *output); +extern int GSM_PackSevenBitsToEight (int offset, unsigned char *input, unsigned char *output); +#endif /* UCLINUX */ -GSM_Error GSM_EncodeETSISMS(GSM_SMSMessage *SMS, GSM_ETSISMSMessage *ETSI, SMS_MessageType PDU, int *length); -GSM_Error GSM_DecodeETSISMS(GSM_SMSMessage *SMS, GSM_ETSISMSMessage *ETSI); +extern GSM_Error GSM_EncodeETSISMS(GSM_SMSMessage *SMS, GSM_ETSISMSMessage *ETSI, SMS_MessageType PDU, int *length); +extern GSM_Error GSM_DecodeETSISMS(GSM_SMSMessage *SMS, GSM_ETSISMSMessage *ETSI); -GSM_Error GSM_EncodeSMSDateTime(GSM_DateTime *DT, unsigned char *req); +#ifndef UCLINUX +extern GSM_Error GSM_EncodeSMSDateTime(GSM_DateTime *DT, unsigned char *req); +#endif /* UCLINUX */ -GSM_Error GSM_DecodeETSISMSSubmitData(GSM_SMSMessage *SMS, GSM_ETSISMSMessage *ETSI); +extern GSM_Error GSM_DecodeETSISMSSubmitData(GSM_SMSMessage *SMS, GSM_ETSISMSMessage *ETSI); -GSM_Error GSM_DecodeETSISMSStatusReportData(GSM_SMSMessage *SMS, GSM_ETSISMSMessage *ETSI); +extern GSM_Error GSM_DecodeETSISMSStatusReportData(GSM_SMSMessage *SMS, GSM_ETSISMSMessage *ETSI); -void GSM_SetDefaultSMSData(GSM_SMSMessage *SMS); -GSM_Error EncodeUDHHeader(char *text, GSM_UDH UDHType); +#ifndef UCLINUX +extern void GSM_SetDefaultSMSData(GSM_SMSMessage *SMS); +extern GSM_Error EncodeUDHHeader(char *text, GSM_UDH UDHType); +#endif /* UCLINUX */ -int GSM_MakeSinglePartSMS2(GSM_SMSMessage *SMS, +#ifndef UCLINUX +extern int GSM_MakeSinglePartSMS2(GSM_SMSMessage *SMS, unsigned char *MessageBuffer,int cur, GSM_UDH UDHType, GSM_Coding_Type Coding); -void GSM_MakeMultiPartSMS2(GSM_MultiSMSMessage *SMS, +#endif /* UCLINUX */ +extern void GSM_MakeMultiPartSMS2(GSM_MultiSMSMessage *SMS, unsigned char *MessageBuffer,int MessageLength, GSM_UDH UDHType, GSM_Coding_Type Coding); #endif /* __gsm_sms_h */ diff --git a/include/newmodules/n6110.h b/include/newmodules/n6110.h index 34a3988..cbce246 100644 --- a/include/newmodules/n6110.h +++ b/include/newmodules/n6110.h @@ -51,168 +51,194 @@ extern GSM_Functions N6110_Functions; extern GSM_Information N6110_Information; /* Prototypes for the functions designed to be used externally. */ -GSM_Error N6110_Initialise(char *port_device, char *initlength, +static GSM_Error N6110_Initialise(char *port_device, char *initlength, GSM_ConnectionType connection, void (*rlp_callback)(RLP_F96Frame *frame)); -void N6110_DispatchMessage(u16 MessageLength, u8 *MessageBuffer, +static void N6110_DispatchMessage(u16 MessageLength, u8 *MessageBuffer, u8 MessageType); -GSM_Error N6110_SendStatusRequest(void); +static GSM_Error N6110_SendStatusRequest(void); -int N6110_GetMemoryType(GSM_MemoryType memory_type); +static int N6110_GetMemoryType(GSM_MemoryType memory_type); -GSM_Error N6110_GetVoiceMailbox ( GSM_PhonebookEntry *entry); +#ifndef UCLINUX +static GSM_Error N6110_GetVoiceMailbox ( GSM_PhonebookEntry *entry); -GSM_Error N6110_GetOperatorName ( GSM_Network *operator); -GSM_Error N6110_SetOperatorName ( GSM_Network *operator); +static GSM_Error N6110_GetOperatorName ( GSM_Network *operator); +static GSM_Error N6110_SetOperatorName ( GSM_Network *operator); +#endif /* UCLINUX */ -GSM_Error N6110_GetMemoryLocation(GSM_PhonebookEntry *entry); -GSM_Error N6110_WritePhonebookLocation(GSM_PhonebookEntry *entry); +static GSM_Error N6110_GetMemoryLocation(GSM_PhonebookEntry *entry); +static GSM_Error N6110_WritePhonebookLocation(GSM_PhonebookEntry *entry); -GSM_Error N6110_GetSpeedDial(GSM_SpeedDial *entry); -GSM_Error N6110_SetSpeedDial(GSM_SpeedDial *entry); +#ifndef UCLINUX +static GSM_Error N6110_GetSpeedDial(GSM_SpeedDial *entry); +static GSM_Error N6110_SetSpeedDial(GSM_SpeedDial *entry); +#endif /* UCLINUX */ -GSM_Error N6110_GetMemoryStatus(GSM_MemoryStatus *Status); -GSM_Error N6110_GetSMSStatus(GSM_SMSStatus *Status); -GSM_Error N6110_GetSMSCenter(GSM_MessageCenter *MessageCenter); +static GSM_Error N6110_GetMemoryStatus(GSM_MemoryStatus *Status); +#ifndef UCLINUX +static GSM_Error N6110_GetSMSStatus(GSM_SMSStatus *Status); +static GSM_Error N6110_GetSMSCenter(GSM_MessageCenter *MessageCenter); -GSM_Error N6110_GetSMSMessage(GSM_SMSMessage *Message); -GSM_Error N6110_DeleteSMSMessage(GSM_SMSMessage *Message); -GSM_Error N6110_SendSMSMessage(GSM_SMSMessage *Message); -GSM_Error N6110_SaveSMSMessage(GSM_SMSMessage *Message); +static GSM_Error N6110_GetSMSMessage(GSM_SMSMessage *Message); +static GSM_Error N6110_DeleteSMSMessage(GSM_SMSMessage *Message); +static GSM_Error N6110_SendSMSMessage(GSM_SMSMessage *Message); +static GSM_Error N6110_SaveSMSMessage(GSM_SMSMessage *Message); +#endif /* UCLINUX */ -GSM_Error N6110_GetRFLevel(GSM_RFUnits *units, float *level); -GSM_Error N6110_GetBatteryLevel(GSM_BatteryUnits *units, float *level); -GSM_Error N6110_GetPowerSource(GSM_PowerSource *source); -GSM_Error N6110_GetDisplayStatus(int *Status); +static GSM_Error N6110_GetRFLevel(GSM_RFUnits *units, float *level); +static GSM_Error N6110_GetBatteryLevel(GSM_BatteryUnits *units, float *level); +static GSM_Error N6110_GetPowerSource(GSM_PowerSource *source); +#ifndef UCLINUX +static GSM_Error N6110_GetDisplayStatus(int *Status); -GSM_Error N6110_EnterSecurityCode(GSM_SecurityCode SecurityCode); -GSM_Error N6110_GetSecurityCodeStatus(int *Status); -GSM_Error N6110_GetSecurityCode(GSM_SecurityCode *SecurityCode); +static GSM_Error N6110_EnterSecurityCode(GSM_SecurityCode SecurityCode); +static GSM_Error N6110_GetSecurityCodeStatus(int *Status); +static GSM_Error N6110_GetSecurityCode(GSM_SecurityCode *SecurityCode); -GSM_Error N6110_GetSMSCenter(GSM_MessageCenter *MessageCenter); -GSM_Error N6110_SetSMSCenter(GSM_MessageCenter *MessageCenter); +static GSM_Error N6110_GetSMSCenter(GSM_MessageCenter *MessageCenter); +static GSM_Error N6110_SetSMSCenter(GSM_MessageCenter *MessageCenter); -GSM_Error N6110_GetIMEI(char *imei); -GSM_Error N6110_GetRevision(char *revision); -GSM_Error N6110_GetModel(char *model); -GSM_Error N6110_GetManufacturer(char *manufacturer); +static GSM_Error N6110_GetIMEI(char *imei); +static GSM_Error N6110_GetRevision(char *revision); +static GSM_Error N6110_GetModel(char *model); +#endif /* UCLINUX */ +static GSM_Error N6110_GetManufacturer(char *manufacturer); -GSM_Error N6110_GetDateTime(GSM_DateTime *date_time); -GSM_Error N6110_SetDateTime(GSM_DateTime *date_time); +#ifndef UCLINUX +static GSM_Error N6110_GetDateTime(GSM_DateTime *date_time); +static GSM_Error N6110_SetDateTime(GSM_DateTime *date_time); -GSM_Error N6110_PrivGetDateTime(GSM_DateTime *date_time, int msgtype); -GSM_Error N6110_PrivSetDateTime(GSM_DateTime *date_time, int msgtype); +static GSM_Error N6110_PrivGetDateTime(GSM_DateTime *date_time, int msgtype); +static GSM_Error N6110_PrivSetDateTime(GSM_DateTime *date_time, int msgtype); -GSM_Error N6110_GetAlarm(int alarm_number, GSM_DateTime *date_time); -GSM_Error N6110_SetAlarm(int alarm_number, GSM_DateTime *date_time); +static GSM_Error N6110_GetAlarm(int alarm_number, GSM_DateTime *date_time); +static GSM_Error N6110_SetAlarm(int alarm_number, GSM_DateTime *date_time); -GSM_Error N6110_PrivGetAlarm(int alarm_number, GSM_DateTime *date_time, int msgtype); -GSM_Error N6110_PrivSetAlarm(int alarm_number, GSM_DateTime *date_time, int msgtype); +static GSM_Error N6110_PrivGetAlarm(int alarm_number, GSM_DateTime *date_time, int msgtype); +static GSM_Error N6110_PrivSetAlarm(int alarm_number, GSM_DateTime *date_time, int msgtype); -GSM_Error N6110_DialVoice(char *Number); -GSM_Error N6110_DialData(char *Number, char type, void (* callpassup)(char c)); -GSM_Error N6110_AnswerCall(char s); +static GSM_Error N6110_DialVoice(char *Number); +#endif /* UCLINUX */ +static GSM_Error N6110_DialData(char *Number, char type, void (* callpassup)(char c)); +#ifndef UCLINUX +static GSM_Error N6110_AnswerCall(char s); -GSM_Error N6110_GetIncomingCallNr(char *Number); +static GSM_Error N6110_GetIncomingCallNr(char *Number); -GSM_Error N6110_SendBitmap(char *NetworkCode, int width, int height, - unsigned char *bitmap); -GSM_Error N6110_GetNetworkInfo(GSM_NetworkInfo *NetworkInfo); +static GSM_Error N6110_GetNetworkInfo(GSM_NetworkInfo *NetworkInfo); -GSM_Error N6110_GetCalendarNote(GSM_CalendarNote *CalendarNote); -GSM_Error N6110_WriteCalendarNote(GSM_CalendarNote *CalendarNote); -GSM_Error N6110_DeleteCalendarNote(GSM_CalendarNote *CalendarNote); +static GSM_Error N6110_GetCalendarNote(GSM_CalendarNote *CalendarNote); +static GSM_Error N6110_WriteCalendarNote(GSM_CalendarNote *CalendarNote); +static GSM_Error N6110_DeleteCalendarNote(GSM_CalendarNote *CalendarNote); -GSM_Error N6110_NetMonitor(unsigned char mode, char *Screen); +static GSM_Error N6110_NetMonitor(unsigned char mode, char *Screen); -GSM_Error N6110_PlayTone(int Herz, u8 Volume); +static GSM_Error N6110_PlayTone(int Herz, u8 Volume); -GSM_Error N6110_SetBitmap( GSM_Bitmap *Bitmap ); -GSM_Error N6110_GetBitmap( GSM_Bitmap *Bitmap ); +static GSM_Error N6110_SetBitmap( GSM_Bitmap *Bitmap ); +static GSM_Error N6110_GetBitmap( GSM_Bitmap *Bitmap ); -GSM_Error N6110_SetRingTone(GSM_Ringtone *ringtone, int *maxlength); -GSM_Error N6110_SetBinRingTone(GSM_BinRingtone *ringtone); -GSM_Error N6110_GetBinRingTone(GSM_BinRingtone *ringtone); +static GSM_Error N6110_SetRingTone(GSM_Ringtone *ringtone, int *maxlength); +static GSM_Error N6110_SetBinRingTone(GSM_BinRingtone *ringtone); +static GSM_Error N6110_GetBinRingTone(GSM_BinRingtone *ringtone); -GSM_Error N6110_EnableDisplayOutput(); -GSM_Error N6110_DisableDisplayOutput(); +static GSM_Error N6110_EnableDisplayOutput(); +static GSM_Error N6110_DisableDisplayOutput(); -GSM_Error N6110_EnableCellBroadcast (); -GSM_Error N6110_DisableCellBroadcast(void); -GSM_Error N6110_ReadCellBroadcast (GSM_CBMessage *Message); +static GSM_Error N6110_EnableCellBroadcast (); +static GSM_Error N6110_DisableCellBroadcast(void); +static GSM_Error N6110_ReadCellBroadcast (GSM_CBMessage *Message); -GSM_Error N6110_SendDTMF(char *String); +static GSM_Error N6110_SendDTMF(char *String); +#endif /* UCLINUX */ -GSM_Error N6110_Reset(unsigned char type); +static GSM_Error N6110_Reset(unsigned char type); -GSM_Error N6110_GetProfile(GSM_Profile *Profile); -GSM_Error N6110_SetProfile(GSM_Profile *Profile); -bool N6110_SendRLPFrame(RLP_F96Frame *frame, bool out_dtx); +#ifndef UCLINUX +static GSM_Error N6110_GetProfile(GSM_Profile *Profile); +static GSM_Error N6110_SetProfile(GSM_Profile *Profile); +static bool N6110_SendRLPFrame(RLP_F96Frame *frame, bool out_dtx); +#endif /* UCLINUX */ -GSM_Error N6110_CancelCall(void); +static GSM_Error N6110_CancelCall(void); -GSM_Error N6110_PressKey(int key, int event); +#ifndef UCLINUX +static GSM_Error N6110_PressKey(int key, int event); -GSM_Error N6110_GetProductProfileSetting (GSM_PPS *PPS); -GSM_Error N6110_SetProductProfileSetting (GSM_PPS *PPS); +static GSM_Error N6110_GetProductProfileSetting (GSM_PPS *PPS); +static GSM_Error N6110_SetProductProfileSetting (GSM_PPS *PPS); -GSM_Error N6110_CallDivert(GSM_CallDivert *cd); +static GSM_Error N6110_CallDivert(GSM_CallDivert *cd); +#endif /* UCLINUX */ -void N6110_RX_HandleRLPMessage(u8 *MessageBuffer); +static void N6110_RX_HandleRLPMessage(u8 *MessageBuffer); -GSM_Error N6110_SendIMEIFrame(); -GSM_Error N6110_SendIDFrame(); -GSM_Error N6110_SendHWFrame(); +static GSM_Error N6110_SendIMEIFrame(); +static GSM_Error N6110_SendIDFrame(); +static GSM_Error N6110_SendHWFrame(); -GSM_Error N6110_EnableExtendedCommands (unsigned char status); +static GSM_Error N6110_EnableExtendedCommands (unsigned char status); -GSM_Error N6110_Tests(); +#ifndef UCLINUX +static GSM_Error N6110_Tests(); -void N6110_DisplayTestsInfo(u8 *MessageBuffer); +static void N6110_DisplayTestsInfo(u8 *MessageBuffer); -GSM_Error N6110_SimlockInfo(GSM_AllSimlocks *siml); -GSM_Error N6110_GetSMSFolders ( GSM_SMSFolders *folders); +static GSM_Error N6110_SimlockInfo(GSM_AllSimlocks *siml); +static GSM_Error N6110_GetSMSFolders ( GSM_SMSFolders *folders); -GSM_Error N6110_ResetPhoneSettings(); +static GSM_Error N6110_ResetPhoneSettings(); +#endif /* UCLINUX */ -void N6110_Dispatch0x01Message(u16 MessageLength, u8 *MessageBuffer, u8 MessageType); +static void N6110_Dispatch0x01Message(u16 MessageLength, u8 *MessageBuffer, u8 MessageType); -void N6110_ReplySendSMSMessage(u16 MessageLength, u8 *MessageBuffer, u8 MessageType); -void N6110_ReplySetSMSCenter (u16 MessageLength, u8 *MessageBuffer, u8 MessageType); -void N6110_ReplyGetSMSCenter (u16 MessageLength, u8 *MessageBuffer, u8 MessageType); -void N6110_Dispatch0x02Message(u16 MessageLength, u8 *MessageBuffer, u8 MessageType); -void N6110_ReplySetCellBroadcast (u16 MessageLength, u8 *MessageBuffer, u8 MessageType); -void N6110_ReplyReadCellBroadcast(u16 MessageLength, u8 *MessageBuffer, u8 MessageType); +#ifndef UCLINUX +static void N6110_ReplySendSMSMessage(u16 MessageLength, u8 *MessageBuffer, u8 MessageType); +static void N6110_ReplySetSMSCenter (u16 MessageLength, u8 *MessageBuffer, u8 MessageType); +static void N6110_ReplyGetSMSCenter (u16 MessageLength, u8 *MessageBuffer, u8 MessageType); +static void N6110_Dispatch0x02Message(u16 MessageLength, u8 *MessageBuffer, u8 MessageType); +static void N6110_ReplySetCellBroadcast (u16 MessageLength, u8 *MessageBuffer, u8 MessageType); +static void N6110_ReplyReadCellBroadcast(u16 MessageLength, u8 *MessageBuffer, u8 MessageType); -void N6110_ReplyCallDivert (u16 MessageLength, u8 *MessageBuffer, u8 MessageType); -void N6110_Dispatch0x06Message(u16 MessageLength, u8 *MessageBuffer, u8 MessageType); +static void N6110_ReplyCallDivert (u16 MessageLength, u8 *MessageBuffer, u8 MessageType); +static void N6110_Dispatch0x06Message(u16 MessageLength, u8 *MessageBuffer, u8 MessageType); +#endif /* UCLINUX */ -void N6110_ReplySetDateTime(u16 MessageLength,u8 *MessageBuffer, u8 MessageType); -void N6110_ReplyGetDateTime(u16 MessageLength,u8 *MessageBuffer, u8 MessageType); -void N6110_ReplySetAlarm (u16 MessageLength,u8 *MessageBuffer, u8 MessageType); -void N6110_ReplyGetAlarm (u16 MessageLength,u8 *MessageBuffer, u8 MessageType); +#ifndef UCLINUX +static void N6110_ReplySetDateTime(u16 MessageLength,u8 *MessageBuffer, u8 MessageType); +static void N6110_ReplyGetDateTime(u16 MessageLength,u8 *MessageBuffer, u8 MessageType); +static void N6110_ReplySetAlarm (u16 MessageLength,u8 *MessageBuffer, u8 MessageType); +static void N6110_ReplyGetAlarm (u16 MessageLength,u8 *MessageBuffer, u8 MessageType); +#endif /* UCLINUX */ -void N6110_ReplyEnableExtendedCommands (u16 MessageLength,u8 *MessageBuffer,u8 MessageType); -void N6110_ReplyResetPhoneSettings (u16 MessageLength,u8 *MessageBuffer,u8 MessageType); -void N6110_ReplyIMEI (u16 MessageLength,u8 *MessageBuffer,u8 MessageType); -void N6110_ReplyGetProductProfileSetting(u16 MessageLength,u8 *MessageBuffer,u8 MessageType); -void N6110_ReplySetProductProfileSetting(u16 MessageLength,u8 *MessageBuffer,u8 MessageType); -void N6110_ReplyNetmonitor (u16 MessageLength,u8 *MessageBuffer,u8 MessageType); -void N6110_ReplySimlockInfo (u16 MessageLength,u8 *MessageBuffer,u8 MessageType); -void N6110_ReplyPlayTone (u16 MessageLength,u8 *MessageBuffer,u8 MessageType); -void N6110_ReplyHW (u16 MessageLength,u8 *MessageBuffer,u8 MessageType); -void N6110_Dispatch0x40Message (u16 MessageLength,u8 *MessageBuffer,u8 MessageType); +static void N6110_ReplyEnableExtendedCommands (u16 MessageLength,u8 *MessageBuffer,u8 MessageType); +#ifndef UCLINUX +static void N6110_ReplyResetPhoneSettings (u16 MessageLength,u8 *MessageBuffer,u8 MessageType); +#endif /* UCLINUX */ +static void N6110_ReplyIMEI (u16 MessageLength,u8 *MessageBuffer,u8 MessageType); +#ifndef UCLINUX +static void N6110_ReplyGetProductProfileSetting(u16 MessageLength,u8 *MessageBuffer,u8 MessageType); +static void N6110_ReplySetProductProfileSetting(u16 MessageLength,u8 *MessageBuffer,u8 MessageType); +static void N6110_ReplyNetmonitor (u16 MessageLength,u8 *MessageBuffer,u8 MessageType); +static void N6110_ReplySimlockInfo (u16 MessageLength,u8 *MessageBuffer,u8 MessageType); +static void N6110_ReplyPlayTone (u16 MessageLength,u8 *MessageBuffer,u8 MessageType); +#endif /* UCLINUX */ +static void N6110_ReplyHW (u16 MessageLength,u8 *MessageBuffer,u8 MessageType); +static void N6110_Dispatch0x40Message (u16 MessageLength,u8 *MessageBuffer,u8 MessageType); -void N6110_DispatchACKMessage (u16 MessageLength, u8 *MessageBuffer, u8 MessageType); -void N6110_ReplyID(u16 MessageLength, u8 *MessageBuffer, u8 MessageType); +static void N6110_DispatchACKMessage (u16 MessageLength, u8 *MessageBuffer, u8 MessageType); +static void N6110_ReplyID(u16 MessageLength, u8 *MessageBuffer, u8 MessageType); -GSM_Error GSM_EncodeNokiaSMSFrame(GSM_SMSMessage *SMS, unsigned char *req, int *length, SMS_MessageType PDU); -GSM_Error GSM_DecodeNokiaSMSFrame(GSM_SMSMessage *SMS, unsigned char *req, int length); +#ifndef UCLINUX +static GSM_Error GSM_EncodeNokiaSMSFrame(GSM_SMSMessage *SMS, unsigned char *req, int *length, SMS_MessageType PDU); +static GSM_Error GSM_DecodeNokiaSMSFrame(GSM_SMSMessage *SMS, unsigned char *req, int length); -int N6110_MakeCallerGroupFrame (unsigned char *req,GSM_Bitmap Bitmap); -int N6110_MakeOperatorLogoFrame(unsigned char *req,GSM_Bitmap Bitmap); -int N6110_MakeStartupLogoFrame (unsigned char *req,GSM_Bitmap Bitmap); +static int N6110_MakeCallerGroupFrame (unsigned char *req,GSM_Bitmap Bitmap); +static int N6110_MakeOperatorLogoFrame(unsigned char *req,GSM_Bitmap Bitmap); +static int N6110_MakeStartupLogoFrame (unsigned char *req,GSM_Bitmap Bitmap); +#endif /* UCLINUX */ #endif /* __n_6110_h */ diff --git a/include/protocol/fbus.h b/include/protocol/fbus.h index 1340262..a42a7fa 100644 --- a/include/protocol/fbus.h +++ b/include/protocol/fbus.h @@ -49,13 +49,4 @@ enum FBUS_RX_States { FBUS_RX_GetMessage }; -GSM_Error FBUS_Initialise(char *port_device, char *initlength, - GSM_ConnectionType connection, - void (*rlp_callback)(RLP_F96Frame *frame)); - -int FBUS_SendMessage(u16 message_length, u8 message_type, u8 *buffer); -int FBUS_SendFrame(u16 message_length, u8 message_type, u8 *buffer); -void FBUS_Terminate(void); -void FBUS_RX_StateMachine(unsigned char rx_byte); - #endif /* __fbus_h */ diff --git a/include/uccompat.h b/include/uccompat.h new file mode 100644 index 0000000..807e74f --- /dev/null +++ b/include/uccompat.h @@ -0,0 +1,41 @@ +/* + + $Id$ + + G N O K I I + + A Linux/Unix toolset and driver for Nokia mobile phones. + + Released under the terms of the GNU GPL, see file COPYING for more details. + +*/ + +#ifndef __UCCOMPAT_H__ +#define __UCCOMPAT_H__ + +#ifdef UCCOMPAT + + +/* Handle non-existing atoi() */ +#include +#define atoi(s) ({ \ + long _atoi_l=strtol((s), (char **)NULL, 10); \ + /**/ if (_atoi_lINT_MAX) _atoi_l=INT_MAX; \ + _atoi_l; \ + }) + +#define strchr _Xstrchr +#define strrchr _Xstrrchr +#include +#undef strchr +#undef strrchr +extern char * strchr __P ((const char *, int)); +extern char * strrchr __P ((const char *, int)); + +#define getpid() (2) + + +#endif /* UCCOMPAT */ + +#endif /* __UCCOMPAT_H__ */ diff --git a/utils/Makefile b/utils/Makefile index 04af119..e724eac 100644 --- a/utils/Makefile +++ b/utils/Makefile @@ -11,7 +11,7 @@ include $(TOPDIR)/Makefile.global OBJS = mgnokiidev.o -all: mgnokiidev +all: #mgnokiidev mgnokiidev: $(OBJS)