1 /* (c) 2002-2003 by Marcin Wiacek */
2 
3 #include <string.h>
4 #include <time.h>
5 
6 #include <gammu-config.h>
7 
8 #include "../../../misc/coding/coding.h"
9 #include "../../../service/gsmlogo.h"
10 #include "../nfunc.h"
11 #include "../nfuncold.h"
12 #include "../../pfunc.h"
13 #include "dct4func.h"
14 
15 #ifdef GSM_ENABLE_NOKIA_DCT4
16 
DCT4_ReplyGetPhoneMode(GSM_Protocol_Message * msg,GSM_StateMachine * s)17 GSM_Error DCT4_ReplyGetPhoneMode(GSM_Protocol_Message *msg, GSM_StateMachine *s)
18 {
19 	s->Phone.Data.PhoneString[0] = msg->Buffer[4];
20 	return ERR_NONE;
21 }
22 
DCT4_GetPhoneMode(GSM_StateMachine * s)23 GSM_Error DCT4_GetPhoneMode(GSM_StateMachine *s)
24 {
25 	unsigned char req[] = {N6110_FRAME_HEADER, 0x02, 0x00, 0x00};
26 
27 	smprintf(s,"Getting phone mode\n");
28 
29 	return GSM_WaitFor (s, req, 6, 0x15, 4, ID_Reset);
30 }
31 
DCT4_ReplySetPhoneMode(GSM_Protocol_Message * msg UNUSED,GSM_StateMachine * s UNUSED)32 GSM_Error DCT4_ReplySetPhoneMode(GSM_Protocol_Message *msg UNUSED, GSM_StateMachine *s UNUSED)
33 {
34 	return ERR_NONE;
35 }
36 
DCT4_SetPhoneMode(GSM_StateMachine * s,DCT4_PHONE_MODE mode)37 GSM_Error DCT4_SetPhoneMode(GSM_StateMachine *s, DCT4_PHONE_MODE mode)
38 {
39 	unsigned char PhoneMode[10];
40 	int	      i;
41 	GSM_Error     error;
42 	unsigned char req[] = {N6110_FRAME_HEADER, 0x01,
43 			       0x04,		/* phone mode */
44 			       0x00};
45 
46 	if (s->ConnectionType != GCT_FBUS2) return ERR_OTHERCONNECTIONREQUIRED;
47 
48 	s->Phone.Data.PhoneString 	= PhoneMode;
49 	req[4] 				= mode;
50 
51 	smprintf(s,"Going to phone mode %i\n",mode);
52 	error = GSM_WaitFor (s, req, 6, 0x15, 4, ID_Reset);
53 	if (error != ERR_NONE) return error;
54 	for (i=0;i<20;i++) {
55 		error=DCT4_GetPhoneMode(s);
56 		if (error != ERR_NONE) return error;
57 		if (PhoneMode[0] == mode) break;
58 		usleep(500000);
59 	}
60 
61 	return ERR_NONE;
62 }
63 
DCT4_ReplyGetIMEI(GSM_Protocol_Message * msg,GSM_StateMachine * s)64 GSM_Error DCT4_ReplyGetIMEI(GSM_Protocol_Message *msg, GSM_StateMachine *s)
65 {
66 	memcpy(s->Phone.Data.IMEI,msg->Buffer + 10, 16);
67 	smprintf(s, "Received IMEI %s\n",s->Phone.Data.IMEI);
68 	return ERR_NONE;
69 }
70 
DCT4_GetIMEI(GSM_StateMachine * s)71 GSM_Error DCT4_GetIMEI (GSM_StateMachine *s)
72 {
73 	unsigned char req[5] = {N6110_FRAME_HEADER, 0x00, 0x41};
74 
75 	smprintf(s, "Getting IMEI\n");
76 	return GSM_WaitFor (s, req, 5, 0x1B, 2, ID_GetIMEI);
77 }
78 
DCT4_GetHardware(GSM_StateMachine * s,char * value)79 GSM_Error DCT4_GetHardware(GSM_StateMachine *s, char *value)
80 {
81 	return NOKIA_GetPhoneString(s,"\x00\x03\x02\x07\x00\x02",6,0x1b,value,ID_GetHardware,10);
82 }
83 
DCT4_GetProductCode(GSM_StateMachine * s,char * value)84 GSM_Error DCT4_GetProductCode(GSM_StateMachine *s, char *value)
85 {
86 	return NOKIA_GetPhoneString(s,"\x00\x03\x04\x0b\x00\x02",6,0x1b,value,ID_GetProductCode,10);
87 }
88 
DCT4_Reset(GSM_StateMachine * s,gboolean hard)89 GSM_Error DCT4_Reset(GSM_StateMachine *s, gboolean hard)
90 {
91 	unsigned char req[] = {N6110_FRAME_HEADER, 0x05,
92 			       0x80,		/* 0x80 - reset, 0x00 - off */
93 			       0x00};
94 /* 	unsigned char TimeReq[] = {N6110_FRAME_HEADER, 0x0E, 0x00, 0x00}; */
95 
96 	if (hard) return ERR_NOTSUPPORTED;
97 
98 /* 	error = DCT4_SetPhoneMode(s, DCT4_MODE_TEST); */
99 /* 	if (error != ERR_NONE) return error; */
100 /* 	error = DCT4_SetPhoneMode(s, DCT4_MODE_NORMAL); */
101 /* 	if (error != ERR_NONE) return error; */
102 
103 	s->Phone.Data.EnableIncomingSMS = FALSE;
104 	s->Phone.Data.EnableIncomingCB  = FALSE;
105 
106 	return GSM_WaitFor (s, req, 6, 0x15, 2, ID_Reset);
107 }
108 
109 #endif
110 
111 /* How should editor hadle tabs in this file? Add editor commands here.
112  * vim: noexpandtab sw=8 ts=8 sts=8:
113  */
114