1 /* Test for encoding SMS using AT driver */
7 #include "../libgammu/protocol/protocol.h" /* Needed for GSM_Protocol_Message */
8 #include "../libgammu/gsmstate.h" /* Needed for state machine internals */
9 #include "../libgammu/gsmphones.h" /* Phone data */
13 extern GSM_Error
ATGEN_MakeSMSFrame(GSM_StateMachine
* s
, GSM_SMSMessage
* message
, unsigned char *hexreq
, int *current
, int *length2
);
15 #define BUFFER_SIZE 16384
17 int main(int argc
, char **argv
)
19 GSM_Debug_Info
*debug_info
;
20 GSM_Phone_ATGENData
*Priv
;
22 unsigned char dumpbuffer
[BUFFER_SIZE
];
27 int current
, current2
;
28 unsigned char hexreq
[1000];
29 GSM_SMS_Backup Backup
;
30 gboolean generate
= FALSE
;
32 /* Enable debugging */
33 debug_info
= GSM_GetGlobalDebug();
34 GSM_SetDebugFileDescriptor(stderr
, FALSE
, debug_info
);
35 GSM_SetDebugLevel("textall", debug_info
);
37 /* Check parameters */
38 if (argc
!= 3 && argc
!= 4) {
39 printf("Not enough parameters!\nUsage: sms-at-encode message.backup message.dump\n");
43 /* Check for generating option */
44 if (argc
== 4 && strcmp(argv
[3], "generate") == 0) {
49 error
= GSM_ReadSMSBackupFile(argv
[1], &Backup
);
50 gammu_test_result(error
, "GSM_ReadSMSBackupFile");
54 f
= fopen(argv
[2], "r");
56 printf("Could not open %s\n", argv
[2]);
61 len
= fread(dumpbuffer
, 1, sizeof(dumpbuffer
) - 1, f
);
63 printf("Could not read whole file %s\n", argv
[2]);
68 /* Zero terminate data */
75 /* Allocates state machine */
76 s
= GSM_AllocStateMachine();
78 printf("Could not allocate state machine!\n");
81 debug_info
= GSM_GetDebug(s
);
82 GSM_SetDebugGlobal(TRUE
, debug_info
);
83 GSM_SetDebugFileDescriptor(stderr
, FALSE
, debug_info
);
84 GSM_SetDebugLevel("textall", debug_info
);
86 /* Initialize AT engine */
87 Data
= &s
->Phone
.Data
;
88 Data
->ModelInfo
= GetModelData(NULL
, NULL
, "unknown", NULL
);
89 Priv
= &s
->Phone
.Data
.Priv
.ATGEN
;
90 Priv
->ReplyState
= AT_Reply_OK
;
91 Priv
->SMSMode
= SMS_AT_PDU
;
92 Priv
->PhoneSMSMemory
= AT_AVAILABLE
;
93 Priv
->SIMSMSMemory
= AT_AVAILABLE
;
95 /* Format SMS frame */
96 error
= ATGEN_MakeSMSFrame(s
, Backup
.SMS
[0], hexreq
, ¤t
, ¤t2
);
97 gammu_test_result(error
, "ATGEN_MakeSMSFrame");
99 /* We don't need this anymore */
100 GSM_FreeSMSBackup(&Backup
);
102 /* Display message */
105 f
= fopen(argv
[2], "w");
107 printf("Could not open %s\n", argv
[2]);
112 len
= fwrite(hexreq
, 1, strlen(hexreq
), f
);
113 if (len
!= strlen(hexreq
)) {
114 printf("Could not save %s\n", argv
[2]);
121 if (strcmp(hexreq
, dumpbuffer
) != 0) {
122 printf("Encoded does not match with template!\n");
123 printf("Encoded: %s\n", hexreq
);
124 printf("Template: %s\n", dumpbuffer
);
129 /* Free state machine */
130 GSM_FreeStateMachine(s
);
135 /* Editor configuration
136 * vim: noexpandtab sw=8 ts=8 sts=8 tw=72: