blob: 215adc18b3d397b734b038c2ba2793380a45c252 [file] [log] [blame]
lh9ed821d2023-04-07 01:36:19 -07001/******************************************************************
2* Description: provide functions about the ussd management
3* Modify Date Version Author Modification
4* 2012/04/06 V1.0 chenyi create
5******************************************************************/
6
7//header file
8#include "zte_web_interface.h"
9//#include "zte_topsw_ussd.h"
10//#include "libzte_ussd.h"
11//constant
12
13#define USSD_ACTION "ussd_action"
14#define USSD_DCS "ussd_dcs"
15#define USSD_DATA "ussd_data"
16
17#define ZTE_WEB_USSD_SEND "ussd_send"
18#define ZTE_WEB_USSD_CANCEL "ussd_cancel"
19#define ZTE_WEB_USSD_REPLY "ussd_reply"
20#define ZTE_WEB_USSD_FIRST "ussd"
21#define ZTE_WEB_USSD_OVER "ussd_over"
22
23#ifndef ZTE_USSD_NV
24#define ZTE_USSD_NV "ussd_write_flag"
25#endif
26
27#ifndef ZTE_MAX_USSD_CHAR
28#define ZTE_MAX_USSD_CHAR 160
29#endif
30
31#define USSD_OPERATING "15"
32#define USSD_FIRST_CANCEL "17"
33#define USSD_OVER ""
34
35typedef struct {
36 int ussd_action;
37 int ussd_dcs;
38 unsigned char ussd_data[ZTE_USSD_DATA_TO_WEB_LEN];
39} zte_ussd_data_to_web_type;
40static void zte_web_ussd_cancel(webs_t wp);
41static void zte_web_ussd_send(webs_t wp);
42static void zte_web_ussd_reply(webs_t wp);
43void zte_web_ussd(webs_t wp);
44static void zte_web_ussd_over(webs_t wp);
45
46//functions
47
48/**********************************************************************
49* Function: zte_goform_ussd_process
50* Description:
51* Input: web para
52* Output:
53* Return:
54* Others:
55* Modify Date Version Author Modification
56* -----------------------------------------------
57* 20120406 V1.0 chenyi first version
58**********************************************************************/
59void zte_goform_ussd_process(webs_t wp)
60{
61 char_t *ussd_operator = NULL;
62
63 if (NULL == wp) {
xf.libdd93d52023-05-12 07:10:14 -070064 slog(MISC_PRINT, SLOG_ERR, "web_ussd-> invalid input..\n"); /*lint !e26*/
lh9ed821d2023-04-07 01:36:19 -070065 return;
66 }
67
68 ussd_operator = websGetVar(wp, T("USSD_operator"), T(""));
69 slog(MISC_PRINT, SLOG_DEBUG, "ussd_operator is [%s].\n", ussd_operator); /*lint !e26*/
70
71 if (0 == strcmp(ussd_operator, ZTE_WEB_USSD_SEND)) {
72 zte_web_ussd_send(wp);
73 } else if (0 == strcmp(ussd_operator, ZTE_WEB_USSD_CANCEL)) {
74 zte_web_ussd_cancel(wp);
75 } else if (0 == strcmp(ussd_operator, ZTE_WEB_USSD_REPLY)) {
76 zte_web_ussd_reply(wp);
77 } else if (0 == strcmp(ussd_operator, ZTE_WEB_USSD_FIRST)) {
78 zte_web_ussd(wp);
79 } else if (0 == strcmp(ussd_operator, ZTE_WEB_USSD_OVER)) {
80 zte_web_ussd_over(wp);
81 } else {
82 slog(MISC_PRINT, SLOG_DEBUG, "invalid ussd_operator[%s].\n", ussd_operator); /*lint !e26*/
83 zte_write_result_to_web(wp, FAILURE);
84 }
85}
86/**********************************************************************
87* Function: zte_web_ussd_send(webs_t wp)
88* Description:
89* Input: web para
90* Output:
91* Return:
92* Others:
93* Modify Date Version Author Modification
94* -----------------------------------------------
95* 20120406 V1.0 chenyi first version
96**********************************************************************/
97static void zte_web_ussd_send(webs_t wp)
98{
99 unsigned char ussd_data[ZTE_MAX_USSD_CHAR] = {0};
100 unsigned char *ussd_send_number = NULL;
101
102 if (NULL == wp) {
xf.libdd93d52023-05-12 07:10:14 -0700103 slog(MISC_PRINT, SLOG_ERR, "web_ussd_send: invalid input..\n"); /*lint !e26*/
lh9ed821d2023-04-07 01:36:19 -0700104 return;
105 }
106
107 ussd_send_number = websGetVar(wp, T("USSD_send_number"), T(""));
108 slog(MISC_PRINT, SLOG_DEBUG, "ussd_send_number is [%s].\n", ussd_send_number); /*lint !e26*/
109
110 if (0 == strcmp(ussd_send_number, "")) {
111 slog(MISC_PRINT, SLOG_ERR, "ussd number is empty.\n"); /*lint !e26*/
112 zte_write_result_to_web(wp, FAILURE);
113 return;
114 }
115
116 strncpy(ussd_data, ussd_send_number, sizeof(ussd_data) - 1);
117 slog(MISC_PRINT, SLOG_DEBUG, "ussd_data is [%s].\n", ussd_data); /*lint !e26*/
118
119 //update the current state
120 (void)zte_web_write(ZTE_USSD_NV, USSD_OPERATING);
121 (void)zte_web_write("ussd_operater", "send");
122 (void)zte_web_write("ussd_string", ussd_data);
123
124 /*handler to mc*/
125 if (0 == ipc_send_message(MODULE_ID_WEB_CGI, MODULE_ID_AT_CTL, MSG_CMD_USSD_SET_REQ, 0, NULL, 0)) {
xf.libdd93d52023-05-12 07:10:14 -0700126 slog(MISC_PRINT, SLOG_NORMAL, "web_ussd_send: successful.\n"); /*lint !e26*/
lh9ed821d2023-04-07 01:36:19 -0700127 } else {
xf.libdd93d52023-05-12 07:10:14 -0700128 slog(MISC_PRINT, SLOG_ERR, "web_ussd_send: failed.\n"); /*lint !e26*/
lh9ed821d2023-04-07 01:36:19 -0700129 }
130
131 zte_write_result_to_web(wp, SUCCESS);
132}
133/**********************************************************************
134* Function: zte_web_ussd_cancel(webs_t wp)
135* Description: to cancel the ussd operation
136* Input: web para
137* Output:
138* Return:
139* Others:
140* Modify Date Version Author Modification
141* -----------------------------------------------
142* 20120406 V1.0 chenyi first version
143**********************************************************************/
144static void zte_web_ussd_cancel(webs_t wp)
145{
146 /*check input*/
147 if (NULL == wp) {
xf.libdd93d52023-05-12 07:10:14 -0700148 slog(MISC_PRINT, SLOG_ERR, "web_ussd_cancel invalid input..\n"); /*lint !e26*/
lh9ed821d2023-04-07 01:36:19 -0700149 return;
150 }
151
152 (void)zte_web_write(ZTE_USSD_NV, USSD_OPERATING);
153
154 (void)zte_web_write("ussd_operater", "cancel");
155
156 /*handler to mc*/
157 if (0 == ipc_send_message(MODULE_ID_WEB_CGI, MODULE_ID_AT_CTL, MSG_CMD_USSD_CANCEL_REQ, 0, NULL, 0)) {
xf.libdd93d52023-05-12 07:10:14 -0700158 slog(MISC_PRINT, SLOG_NORMAL, "web_ussd_cancel: topsw_mc_ussd_send successful.\n"); /*lint !e26*/
lh9ed821d2023-04-07 01:36:19 -0700159 } else {
xf.libdd93d52023-05-12 07:10:14 -0700160 slog(MISC_PRINT, SLOG_ERR, "web_ussd_cancel: topsw_mc_ussd_send failed.\n"); /*lint !e26*/
lh9ed821d2023-04-07 01:36:19 -0700161 }
162
163 zte_write_result_to_web(wp, SUCCESS);
164}
165/**********************************************************************
166* Function: zte_web_ussd_over(webs_t wp)
167* Description: to reset the ussd_write_flag
168* Input: web para
169* Output:
170* Return:
171* Others:
172* Modify Date Version Author Modification
173* -----------------------------------------------
174* 20120406 V1.0 chenyi first version
175**********************************************************************/
176static void zte_web_ussd_over(webs_t wp)
177{
178 /*check input*/
179 if (NULL == wp) {
xf.libdd93d52023-05-12 07:10:14 -0700180 slog(MISC_PRINT, SLOG_ERR, "web_ussd_over invalid input..\n"); /*lint !e26*/
lh9ed821d2023-04-07 01:36:19 -0700181 return;
182 }
183
184 (void)zte_web_write(ZTE_USSD_NV, USSD_OVER);
185 zte_write_result_to_web(wp, SUCCESS);
186}
187/**********************************************************************
188* Function: zte_web_ussd_reply(webs_t wp)
189* Description: to reply(send) the ussd cmd
190* Input:
191* Output:
192* Return:
193* Others:
194* Modify Date Version Author Modification
195* -----------------------------------------------
196* 20120406 V1.0 chenyi first version
197**********************************************************************/
198static void zte_web_ussd_reply(webs_t wp)
199{
200 /*data get from page*/
201 unsigned char ussd_data_reply[ZTE_MAX_USSD_CHAR] = {0};
202
203 /*check input*/
204 if (NULL == wp) {
xf.libdd93d52023-05-12 07:10:14 -0700205 slog(MISC_PRINT, SLOG_ERR, "web_ussd_reply: invalid input..\n"); /*lint !e26*/
lh9ed821d2023-04-07 01:36:19 -0700206 return;
207 }
208
209 /*set data */
210 strncpy(ussd_data_reply, websGetVar(wp, T("USSD_reply_number"), T("")), sizeof(ussd_data_reply) - 1);
211
212 /*handler to mc*/
213 (void)zte_web_write(ZTE_USSD_NV, USSD_OPERATING);
214 (void)zte_web_write("ussd_string", ussd_data_reply);
215
216 (void)zte_web_write("ussd_operater", "send");
217
218 if (0 == ipc_send_message(MODULE_ID_WEB_CGI, MODULE_ID_AT_CTL, MSG_CMD_USSD_SET_REQ, 0, NULL, 0)) {
xf.libdd93d52023-05-12 07:10:14 -0700219 slog(MISC_PRINT, SLOG_NORMAL, "web_ussd_reply: successful.\n"); /*lint !e26*/
lh9ed821d2023-04-07 01:36:19 -0700220 } else {
xf.libdd93d52023-05-12 07:10:14 -0700221 slog(MISC_PRINT, SLOG_ERR, "web_ussd_reply: failed.\n"); /*lint !e26*/
lh9ed821d2023-04-07 01:36:19 -0700222 }
223 zte_write_result_to_web(wp, SUCCESS);
224}
225/**********************************************************************
226* Function: zte_web_ussd(webs_t wp)
227* Description: to cancel the ussd cmd
228* Input: web para
229* Output:
230* Return:
231* Others:
232* Modify Date Version Author Modification
233* -----------------------------------------------
234* 20120406 V1.0 chenyi first version
235**********************************************************************/
236
237void zte_web_ussd(webs_t wp)
238{
239 if (NULL == wp) {
xf.libdd93d52023-05-12 07:10:14 -0700240 slog(MISC_PRINT, SLOG_ERR, "web_ussd: invalid input..\n"); /*lint !e26*/
lh9ed821d2023-04-07 01:36:19 -0700241 return;
242 }
xf.libdd93d52023-05-12 07:10:14 -0700243 slog(MISC_PRINT, SLOG_DEBUG, "web_ussd: ok\n"); /*lint !e26*/
lh9ed821d2023-04-07 01:36:19 -0700244
245 (void)zte_web_write(ZTE_USSD_NV, USSD_FIRST_CANCEL);
246 zte_write_result_to_web(wp, SUCCESS);
247}
248int zte_ussd_get_to_web_data(zte_ussd_data_to_web_type *para)
249{
250 char buf[NV_ITEM_STRING_LEN_20] = {0};
251
252 if (NULL == para) {
253 slog(MISC_PRINT, SLOG_DEBUG, "para is null\n"); /*lint !e26*/
254 return -1;
255 }
256
257 sc_cfg_get("ussd_mode", buf, sizeof(buf));
258 para->ussd_action = atoi(buf);
259 slog(MISC_PRINT, SLOG_DEBUG, "ussd_operater is %d\n", para->ussd_action); /*lint !e26*/
260
261 memset(&buf, 0, sizeof(buf));
262 sc_cfg_get("ussd_dcs", buf, sizeof(buf));
263 para->ussd_dcs = atoi(buf);
264 slog(MISC_PRINT, SLOG_DEBUG, "ussd_dcs is %d\n", para->ussd_dcs); /*lint !e26*/
265
266 sc_cfg_get("ussd_content", (para->ussd_data), sizeof(para->ussd_data));
267
268 slog(MISC_PRINT, SLOG_DEBUG, "ussd_data is %s\n", para->ussd_data); /*lint !e26*/
269
270 return 0;
271
272}
273/**********************************************************************
274* Function: zte_get_ussd_data_info
275* Description: to get the ussd data info
276* Input: the web para
277* Output:
278* Return:
279* Others:
280* Modify Date Version Author Modification
281* -----------------------------------------------
282* 2012/04/16 V1.0 chenyi first version
283**********************************************************************/
284void zte_get_ussd_data_info(webs_t wp)
285{
286 zte_ussd_data_to_web_type ussd_data_info;
287 int result = 0;
288
289 memset(&ussd_data_info, 0, sizeof(zte_ussd_data_to_web_type));
290 result = zte_ussd_get_to_web_data(&ussd_data_info);
291#if 0 // kw 3 return -1 branch is unreachable
292 if (-1 == result) {
xf.libdd93d52023-05-12 07:10:14 -0700293 slog(MISC_PRINT, SLOG_ERR, "call ussd_get_to_web_data fail.\n"); /*lint !e26*/
lh9ed821d2023-04-07 01:36:19 -0700294 web_feedback_header(wp);
295 (void)websWrite(wp, T("[]"));
296 return ;
297 }
298#endif
299
300 web_feedback_header(wp);
301 (void)websWrite(wp, T("{\"%s\":\"%d\",\"%s\":\"%d\",\"%s\":\"%s\"}"), USSD_ACTION, ussd_data_info.ussd_action, USSD_DCS, ussd_data_info.ussd_dcs, \
302 USSD_DATA, ussd_data_info.ussd_data);
303}