Tizen 2.0 Release
[framework/system/oma-dm-agent.git] / src / agent / dm-engine / cp / dm_cp_processor.c
1 /*
2  * oma-dm-agent
3  * Copyright (c) 2012 Samsung Electronics Co., Ltd.
4  *
5  * Licensed under the Apache License, Version 2.0 (the License);
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  *     http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  */
17
18 /*lib*/
19 #include <sys/socket.h>
20 #include <sys/un.h>
21 #include <fcntl.h>
22 #include <unistd.h>
23 #include <glib.h>
24 #include <glib/gprintf.h>
25
26 /*sync-agent*/
27 #include <sync_agent.h>
28 #include <plugin/plugin_slp_sysnoti_wap_push.h>
29
30 /*dm-agent*/
31 #include "common/dm_common_def.h"
32 #include "common/util/util.h"
33 #include "mo-handler/dm_mo_common_internal.h"
34 #include "mo-handler/dm_mo_common.h"
35 #include "dm-engine/cp/dm_cp_parser.h"
36 #include "dm-engine/cp/dm_cp_security.h"
37 #include "dm-engine/cp/dm_cp_processor.h"
38
39 #ifndef OMADM_AGENT_LOG
40 #undef LOG_TAG
41 #define LOG_TAG "OMA_DM_CP"
42 #endif
43
44 #define IMSI_VALUE      "310260487447094"
45
46 #define MSG_SIZE        300
47
48 #define W2      "Browser"
49 #define W4      "MMS"
50 #define W5      "SyncML DS"
51 #define W7      "SyncML DM"
52 #define WA      "IM & PS"
53
54 #define DELIMITER                       " : "
55 #define L_BRACKET               " ["
56 #define R_BRACKET               "] "
57 #define LB                                              "\n"
58 #define APPLICATION             "Application : "
59 #define URL                                     "URL : "
60 #define PROXY                           "Proxy : "
61 #define PORT                                    "Port : "
62 #define BOOKMARK                "Bookmark : "   /* not used */
63 #define NO_DATA                 "No data "
64 #define DEFAULT_NAP_TYPE        "APN : "
65
66 static int g_msgId;
67
68 typedef struct {
69         int ext_id;
70         DM_CP *dm_cp;
71 } CP_Data;
72
73 static GList *dm_cp_list = NULL;
74
75 static CP_ERROR _process_receieved_cp_stream(CP_TYPE cp_type, const char *msgBody, unsigned int msgSize, int ext_id);
76 static CP_ERROR __send_msg2mf(SENDMSG_TYPE send_type, void *send_msg);
77 static CP_ERROR _process_setting_oma_ds(DM_CP * dm_cp);
78 static CP_ERROR _process_setting_oma_dm(DM_CP * dm_cp);
79
80 static char __char2hex(char ch);
81 static char *_get_netpin_key(int *key_len);
82 static int __make_view_message(char **msgData, DM_CP * dm_cp);
83
84 CP_ERROR process_Recieved_CP_WBXML(const char *msgBody, unsigned int msgSize, int ext_id)
85 {
86         _EXTERN_FUNC_ENTER;
87
88         retvm_if((msgBody) == NULL, CP_ERROR_FAIL, "msgBody is NULL!!");
89
90         CP_ERROR ret = CP_ERROR_SUCCESS;
91
92         unsigned int wsp_header_size = (unsigned char)msgBody[2];
93         wsp_header_size += 3;
94         _DEBUG_INFO("wsp_header_size : %u", wsp_header_size);
95
96         unsigned int wbxml_size = msgSize - wsp_header_size;
97         _DEBUG_INFO("msgSize : %d, wbxml_size : %u", msgSize, wbxml_size);
98
99         /*
100          * Register PIN CODE to File
101          */
102         char file_buffer[50] = { 0, };
103         snprintf(file_buffer, sizeof(file_buffer), "%s/%d/%s", CP_DATA_REPOSITORY_PATH, ext_id, CP_SEC_FILE_NAME);
104         _DEBUG_INFO("file name : %s", file_buffer);
105
106 //      int file_ret = sync_agent_write_file(CP_SEC_REPOSITORY_PATH, msgBody, wsp_header_size, 1, 1);
107 //      int file_ret = sync_agent_write_whole_file(CP_SEC_REPOSITORY_PATH, msgBody, wsp_header_size, 1);
108         int file_ret = sync_agent_write_whole_file(file_buffer, msgBody, wsp_header_size, 1);
109         if (file_ret != 1) {
110                 _DEBUG_INFO("Failed to repository CP PIN Info");
111         }
112
113         /*
114          * Division CP WBXML to WSP Header
115          */
116         char *wbxml_body = (char *)calloc(wbxml_size, sizeof(char));
117         if (wbxml_body == NULL) {
118                 _DEBUG_INFO("alloc fail");
119                 return 0;
120         }
121         memcpy(wbxml_body, msgBody + wsp_header_size, wbxml_size);
122
123         ret = _process_receieved_cp_stream(CP_TYPE_WBXML, wbxml_body, wbxml_size, ext_id);
124         _DEBUG_INFO("precess receive result : %d", ret);
125
126         free(wbxml_body);
127         wbxml_body = NULL;
128
129         return ret;
130 }
131
132 CP_ERROR process_Recieved_CP_XML(const char *msgBody, unsigned int msgSize, int ext_id)
133 {
134         _EXTERN_FUNC_ENTER;
135
136         retvm_if((msgBody) == NULL, CP_ERROR_FAIL, "msgBody is NULL!!");
137
138         _EXTERN_FUNC_EXIT;
139         return _process_receieved_cp_stream(CP_TYPE_XML, msgBody, msgSize, ext_id);
140 }
141
142 CP_ERROR process_Check_Pincode(int is_initial, char *user_data, int *is_correct, int ext_id)
143 {
144         _EXTERN_FUNC_ENTER;
145
146         CP_ERROR ret = CP_ERROR_SUCCESS;
147
148         /*
149          * 1. get CP header info in repository(file)
150          */
151         /*unsigned long required_length = 50;
152            bool isFinal = 0; */
153         unsigned long size_return = 0;
154         char *cp_pin_info = 0;
155         char *wbxml_body = 0;
156         unsigned long wbxml_size = 0;
157         char *key = 0;
158         int key_len = 0;
159         int i = 0;
160
161         char sec_file_name[50] = { 0, };
162         snprintf(sec_file_name, sizeof(sec_file_name), "%s/%d/%s", CP_DATA_REPOSITORY_PATH, ext_id, CP_SEC_FILE_NAME);
163         _DEBUG_INFO("sec file name : %s", sec_file_name);
164
165 //      int read_ret = sync_agent_read_file(CP_SEC_REPOSITORY_PATH, &cp_pin_info, required_length, &size_return, &isFinal);
166 //      int read_ret = sync_agent_read_whole_file(CP_SEC_REPOSITORY_PATH, &cp_pin_info, &size_return);
167         int read_ret = sync_agent_read_whole_file(sec_file_name, &cp_pin_info, &size_return);
168         if (read_ret == 0) {
169                 _DEBUG_INFO("Failed to sync_agent_read_file( CP_SEC_REPOSITORY_PATH ) !!");
170                 return CP_ERROR_FAIL;
171         }
172
173         char wbxml_file_name[50] = { 0, };
174         snprintf(wbxml_file_name, sizeof(wbxml_file_name), "%s/%d/%s", CP_DATA_REPOSITORY_PATH, ext_id, CP_WBXML_FILE_NAME);
175         _DEBUG_INFO("wbxml file name : %s", wbxml_file_name);
176 //      read_ret = sync_agent_read_whole_file(CP_WBXML_REPOSITORY_PATH, &wbxml_body, &wbxml_size);
177         read_ret = sync_agent_read_whole_file(wbxml_file_name, &wbxml_body, &wbxml_size);
178         if (read_ret == 0) {
179                 _DEBUG_INFO("Failed to sync_agent_read_file ( CP_WBXML_REPOSITORY_PATH ) !!");
180                 return CP_ERROR_FAIL;
181         }
182
183         /*
184          * Check SEC TYPE
185          */
186         char sec = cp_pin_info[6];
187         char sec_type = 0;
188         if (sec == CP_SEC) {
189                 sec_type = cp_pin_info[7];
190         }
191         _DEBUG_INFO("SEC : %u, %x, SEC_TYPE : %u, %x, %c", sec, sec, sec_type, sec_type, sec_type);
192
193         /*
194          * Check Is Exist MAC in wbxml stream
195          */
196         int is_exist_mac = 0;
197         if (cp_pin_info[8] == CP_IS_EXIST_MAC) {
198                 is_exist_mac = 1;
199         }
200
201         char mac[CP_MAC_LEN] = { 0, };
202         if (is_exist_mac != 0) {
203                 i = 0;
204                 for (; i < CP_MAC_LEN; i++) {
205                         mac[i] = cp_pin_info[9 + i];
206                 }
207         }
208
209         switch ((unsigned char)sec_type) {
210         case CP_SEC_TYPE_NETWPIN:
211                 {
212                         _DEBUG_INFO("SEC TYPE : NETWPIN");
213
214                         char *temp = 0;
215                         temp = _get_netpin_key(&key_len);
216                         if (temp == NULL) {
217                                 _DEBUG_INFO("__get_NetPIN_key() failed !!");
218                                 ret = CP_ERROR_FAIL;
219                                 goto return_part;
220                         }
221
222                         key = (char *)calloc(key_len, sizeof(char));
223                         if (key == NULL) {
224                                 _DEBUG_INFO("calloc failed !!");
225
226                                 if (temp != NULL)
227                                         free(temp);
228                                 ret = CP_ERROR_FAIL;
229                                 goto return_part;
230                         }
231
232                         memcpy(key, temp, key_len);
233
234                         for (i = 0; i < key_len; i++) {
235                                 _DEBUG_INFO("key[%d] : 0x%02X", i, key[i]);
236                         }
237
238                         if (temp != NULL)
239                                 free(temp);
240                 }
241                 break;
242         case CP_SEC_TYPE_USERPIN:
243                 {
244                         _DEBUG_INFO("SEC TYPE : USERPIN");
245
246                         int res = 0;
247                         if (is_initial != 0) {
248                                 res = launch_oma_dm_cp_ui(1, ext_id);
249                                 if (res < 0) {
250                                         _DEBUG_INFO("launch_oma_dm_cp_ui() fail !!");
251                                         ret = CP_ERROR_FAIL;
252                                 } else {
253                                         _DEBUG_INFO("launch_oma_dm_cp_ui() success !!");
254                                 }
255
256                                 goto return_part;
257                         } else {
258                                 if (user_data != NULL) {
259                                         key_len = strlen(user_data);
260
261                                         key = (char *)calloc(key_len, sizeof(char));
262                                         if (key == NULL) {
263                                                 _DEBUG_INFO("calloc failed !!");
264                                                 ret = CP_ERROR_FAIL;
265                                                 goto return_part;
266                                         }
267
268                                         strncpy(key, user_data, key_len);
269                                         _DEBUG_INFO("key : %s ( %d )", user_data, key_len);
270                                 } else {
271                                         _DEBUG_INFO("launch_oma_dm_cp_ui() fail !!");
272                                         ret = CP_ERROR_FAIL;
273                                         goto return_part;
274                                 }
275                         }
276                 }
277                 break;
278         case CP_SEC_TYPE_USERNETWPIN:
279                 {
280                         _DEBUG_INFO("SEC TYPE : USERNETWPIN");
281
282                         int res = 0;
283                         if (is_initial != 0) {
284                                 res = launch_oma_dm_cp_ui(2, ext_id);
285                                 if (res < 0) {
286                                         _DEBUG_INFO("launch_oma_dm_cp_ui() fail !!");
287                                         ret = CP_ERROR_FAIL;
288                                 } else {
289                                         _DEBUG_INFO("launch_oma_dm_cp_ui() success !!");
290                                 }
291
292                                 goto return_part;
293                         } else {
294                                 /* USERNETWPIN checking logic */
295                                 int net_temp_len = 0;
296                                 char *net_temp = 0;
297                                 net_temp = _get_netpin_key(&net_temp_len);
298                                 if (net_temp == NULL) {
299                                         ret = CP_ERROR_FAIL;
300                                         _DEBUG_INFO("__get_NetPIN_key() failed !!");
301                                         goto return_part;
302                                 }
303
304                                 for (i = 0; i < net_temp_len; i++) {
305                                         _DEBUG_INFO("net_temp[%d] : 0x%02X", i, net_temp[i]);
306                                 }
307
308                                 int user_data_len = strlen(user_data);
309                                 char *temp_user_data = (char *)calloc(user_data_len, sizeof(char));
310                                 if (temp_user_data == NULL) {
311                                         _DEBUG_INFO("calloc failed !!");
312
313                                         if (net_temp != NULL)
314                                                 free(net_temp);
315                                         ret = CP_ERROR_FAIL;
316                                         goto return_part;
317                                 }
318
319                                 strncpy(temp_user_data, user_data, user_data_len);
320                                 _DEBUG_INFO("temp user data : %s", temp_user_data);
321
322                                 key_len = net_temp_len + user_data_len;
323                                 _DEBUG_INFO("key length : %d", key_len);
324
325                                 key = (char *)calloc(key_len, sizeof(char));
326                                 if (key == NULL) {
327                                         _DEBUG_INFO("calloc failed !!");
328                                         ret = CP_ERROR_FAIL;
329                                         goto return_part;
330                                 }
331                                 memcpy(key, net_temp, net_temp_len);
332                                 memcpy(key + net_temp_len, temp_user_data, user_data_len);
333
334                                 for (i = 0; i < key_len; i++) {
335                                         _DEBUG_INFO("key[%d] : 0x%02X", i, key[i]);
336                                 }
337
338                                 if (net_temp != NULL)
339                                         free(net_temp);
340
341                                 if (temp_user_data != NULL)
342                                         free(temp_user_data);
343                         }
344                 }
345                 break;
346         default:
347                 break;
348         }
349
350         _DEBUG_INFO("start PIN checking logic !!");
351
352         unsigned char *hmac = sync_agent_encrypt_cryptograhic_hash_with_flags(SYNC_AGENT_SA_CRYPTOGRAHIC_HASH_FUNTION_SHA1,
353                                                                               wbxml_body, wbxml_size,
354                                                                               key, key_len,
355                                                                               SYNC_AGENT_SA_CRYPTOGRAHIC_HASH_FUN_HMAC);
356
357         *is_correct = 1;
358
359         i = 0;
360         for (; i < 20; i++) {
361                 char compare[3] = { 0, };
362                 char *mac_cursor = mac + (i * 2);
363                 strncpy(compare, mac_cursor, 2);
364                 _DEBUG_INFO("hmac[%d] : %02X \t  mac[%d, %d] : %s", i, hmac[i], i * 2, i * 2 + 1, compare);
365         }
366
367         i = 0;
368         for (; i < 20; i++) {
369                 char data[3] = { 0, };
370                 snprintf(data, 3, "%02X", hmac[i]);
371
372                 char compare[3] = { 0, };
373                 char *mac_cursor = mac + (i * 2);
374                 strncpy(compare, mac_cursor, 2);
375
376                 _DEBUG_INFO("data : %s, compare : %s ( cnt : %d )", data, compare, i);
377
378                 if (strcasecmp(data, compare) != 0) {
379                         _DEBUG_INFO("failed to compare data !!");
380                         *is_correct = 0;
381                         break;
382                 }
383         }
384
385         _DEBUG_INFO("end PIN checking logic !!");
386
387  return_part:
388         if (key != NULL)
389                 free(key);
390
391         sync_agent_free_file(&cp_pin_info);
392
393         if (wbxml_body != NULL)
394                 sync_agent_free_file(&wbxml_body);
395
396         _DEBUG_INFO("End !!");
397
398         return ret;
399 }
400
401 CP_ERROR process_Invalid_Pincode(int ext_id)
402 {
403         _EXTERN_FUNC_ENTER;
404
405         CP_ERROR ret = CP_ERROR_SUCCESS;
406
407         /*
408          *      1. delete CP data
409          */
410         ret = process_Delete_CP_Data(ext_id);
411         if (ret != CP_ERROR_SUCCESS) {
412                 _DEBUG_INFO("process_Delete_CP_Data() fail !!");
413                 /* todo : exception handling */
414         } else {
415                 _DEBUG_INFO("process_Delete_CP_Data() success !!");
416         }
417
418         /*
419          *      2. send remove message to MF
420          */
421         if (g_msgId != -1) {
422                 ret = __send_msg2mf(REMOVE_MESSAGE, NULL);
423         }
424
425         _DEBUG_INFO("End !!");
426
427         return ret;
428 }
429
430 CP_ERROR process_Setting_CP(int ext_id)
431 {
432         _DEBUG_INFO("Start !!");
433
434         CP_ERROR ret = CP_ERROR_SUCCESS;
435
436         unsigned long size_return = 0;
437
438         CP_TYPE cp_type = CP_TYPE_WBXML;
439
440         char type_file_name[50] = { 0, };
441         snprintf(type_file_name, sizeof(type_file_name), "%s/%d/%s", CP_DATA_REPOSITORY_PATH, ext_id, CP_TYPE_FILE_NAME);
442         _DEBUG_INFO("type file name : %s", type_file_name);
443
444         char *type = 0;
445 //      int read_ret = sync_agent_read_whole_file(CP_TYPE_REPOSITORY_PATH, &type, &size_return);
446         int read_ret = sync_agent_read_whole_file(type_file_name, &type, &size_return);
447         if (read_ret == 0) {
448                 _DEBUG_INFO("Failed to sync_agent_read_file() : %s", type_file_name);
449                 return CP_ERROR_FAIL;
450         }
451
452         if (strcmp("1", type) == 0) {
453                 cp_type = CP_TYPE_XML;
454         } else if (strcmp("2", type) == 0) {
455                 cp_type = CP_TYPE_WBXML;
456         } else {
457                 cp_type = CP_TYPE_NONE;
458         }
459
460         char wbxml_file_name[50] = { 0, };
461         snprintf(wbxml_file_name, sizeof(wbxml_file_name), "%s/%d/%s", CP_DATA_REPOSITORY_PATH, ext_id, CP_WBXML_FILE_NAME);
462         _DEBUG_INFO("wbxml file name : %s", wbxml_file_name);
463
464         char *cp_body = 0;
465 //      read_ret = sync_agent_read_whole_file(CP_WBXML_REPOSITORY_PATH, &cp_body, &size_return);
466         read_ret = sync_agent_read_whole_file(wbxml_file_name, &cp_body, &size_return);
467         if (read_ret == 0) {
468                 _DEBUG_INFO("Failed to sync_agent_read_file() : %s", wbxml_file_name);
469                 return CP_ERROR_FAIL;
470         }
471 //      /*
472 //       * Parse recieved CP to sturct DM_CP
473 //       */
474 //      dm_cp = parsing_cp_stream(cp_type, cp_body, size_return);
475
476         GList *iter = NULL;
477         DM_CP *dm_cp;
478         for (iter = dm_cp_list; iter != 0; iter = g_list_next(iter)) {
479                 dm_cp = 0;
480                 if (iter->data != 0) {
481                         if (((CP_Data *) (iter->data))->ext_id == ext_id) {
482                                 dm_cp = ((CP_Data *) (iter->data))->dm_cp;
483                                 break;
484                         }
485                 }
486         }
487
488         if (dm_cp != 0) {
489                 /* checking app id for multiple app's */
490                 if (dm_cp->applications->app_ID != NULL) {
491                         if (strcmp(dm_cp->applications->app_ID, "w2") == 0) {
492                                 _DEBUG_INFO("app id : %s", W2);
493                                 /*
494                                  *      todo
495                                  *              ret = __process_Setting_Browser(dm_cp);
496                                  */
497                         } else if (strcmp(dm_cp->applications->app_ID, "w4") == 0) {
498                                 _DEBUG_INFO("app id : %s", W4);
499                                 /*
500                                  *      todo
501                                  *              ret = __process_Setting_MMS(dm_cp);
502                                  */
503                         } else if (strcmp(dm_cp->applications->app_ID, "w5") == 0) {
504                                 _DEBUG_INFO("app id : %s", W5);
505                                 ret = _process_setting_oma_ds(dm_cp);
506                                 if (ret != CP_ERROR_SUCCESS) {
507                                         _DEBUG_INFO("__process_Setting_OMA_DS() failed !!");
508                                         return CP_ERROR_FAIL;
509                                 } else {
510                                         _DEBUG_INFO("__process_Setting_OMA_DS() success !!");
511                                 }
512                         } else if (strcmp(dm_cp->applications->app_ID, "w7") == 0) {
513                                 _DEBUG_INFO("app id : %s", W7);
514                                 ret = _process_setting_oma_dm(dm_cp);
515                                 if (ret != CP_ERROR_SUCCESS) {
516                                         _DEBUG_INFO("__process_Setting_OMA_DM() failed !!");
517                                         return CP_ERROR_FAIL;
518                                 } else {
519                                         _DEBUG_INFO("__process_Setting_OMA_DM() success !!");
520                                 }
521                         } else if (strcmp(dm_cp->applications->app_ID, "wA") == 0) {
522                                 _DEBUG_INFO("app id : %s", WA);
523                                 /*
524                                  *      todo
525                                  *              ret = __process_Setting_IM_N_PS(dm_cp);
526                                  */
527                         } else {
528                                 _DEBUG_INFO("app id : undefined !!");
529                         }
530                 }
531         } else {
532                 _DEBUG_INFO("not exist 'CP_Data' for ext_id : %d", ext_id);
533                 return CP_ERROR_FAIL;
534         }
535
536         _DEBUG_INFO("End !!");
537
538         return ret;
539 }
540
541 CP_ERROR process_Delete_All_CP_Data()
542 {
543         _DEBUG_INFO("Start !!");
544
545         CP_ERROR ret = CP_ERROR_SUCCESS;
546
547         /* delete registered all CP data */
548         GList *iter = NULL;
549         for (iter = dm_cp_list; iter != 0;) {
550                 if (iter->data != 0) {
551                         CP_Data *temp = (CP_Data *) (iter->data);
552                         char folder_name[50] = { 0, };
553                         snprintf(folder_name, sizeof(folder_name), "%s/%d", CP_DATA_REPOSITORY_PATH, ((CP_Data *) (iter->data))->ext_id);
554                         _DEBUG_INFO("folder name : %s", folder_name);
555
556                         int file_ret = sync_agent_delete_directory(folder_name, TRUE);
557                         if (file_ret != 1) {
558                                 _DEBUG_INFO("sync_agent_delete_directory( folder : %s ) failed !!", folder_name);
559                                 return CP_ERROR_FAIL;
560                         }
561
562                         dm_cp_list = g_list_remove(dm_cp_list, iter->data);
563                         iter = g_list_next(iter);
564
565                         if (temp->dm_cp != 0)
566                                 free(temp->dm_cp);
567                         free(temp);
568                 }
569         }
570
571         if (g_list_length(dm_cp_list) == 0) {
572                 _DEBUG_INFO("dm_cp_list length : 0 !!");
573                 g_list_free(dm_cp_list);
574                 dm_cp_list = NULL;
575         }
576
577         _DEBUG_INFO("End !!");
578
579         return ret;
580 }
581
582 CP_ERROR process_Delete_CP_Data(int ext_id)
583 {
584         _DEBUG_INFO("Start !!");
585
586         CP_ERROR ret = CP_ERROR_SUCCESS;
587
588         GList *iter = NULL;
589         CP_Data *temp = 0;
590         for (iter = dm_cp_list; iter != 0; iter = g_list_next(iter)) {
591                 if (iter->data != 0) {
592                         if (((CP_Data *) (iter->data))->ext_id == ext_id) {
593                                 temp = (CP_Data *) (iter->data);
594                                 dm_cp_list = g_list_remove(dm_cp_list, iter->data);
595                                 if (temp->dm_cp != 0)
596                                         free(temp->dm_cp);
597                                 free(temp);
598                                 break;
599                         }
600                 }
601         }
602
603         if (g_list_length(dm_cp_list) == 0) {
604                 g_list_free(dm_cp_list);
605                 dm_cp_list = NULL;
606         }
607
608         char folder_name[50] = { 0, };
609         snprintf(folder_name, sizeof(folder_name), "%s/%d", CP_DATA_REPOSITORY_PATH, ext_id);
610         _DEBUG_INFO("folder name : %s", folder_name);
611
612         int file_ret = sync_agent_delete_directory(folder_name, TRUE);
613         if (file_ret != 1) {
614                 _DEBUG_INFO("sync_agent_delete_directory( folder : %s ) failed !!", folder_name);
615                 return CP_ERROR_FAIL;
616         }
617
618         _DEBUG_INFO("End !!");
619
620         return ret;
621 }
622
623 void process_Set_msgId(int msgId)
624 {
625         _DEBUG_INFO("Start !!");
626
627         g_msgId = msgId;
628         _DEBUG_INFO("g_msgId : %d", g_msgId);
629
630         _DEBUG_INFO("End !!");
631 }
632
633 /**************************** Impl static function *************************/
634
635 static CP_ERROR _process_receieved_cp_stream(CP_TYPE cp_type, const char *msgBody, unsigned int msgSize, int ext_id)
636 {
637         _INNER_FUNC_ENTER;
638         CP_ERROR ret = CP_ERROR_SUCCESS;
639
640         retvm_if((msgBody) == NULL, CP_ERROR_FAIL, "msgBody is NULL!!");
641
642         char type[1];
643         if (cp_type == CP_TYPE_XML) {
644                 type[0] = '1';
645         } else if (cp_type == CP_TYPE_WBXML) {
646                 type[0] = '2';
647         }
648
649         char type_file_name[50] = { 0, };
650         snprintf(type_file_name, sizeof(type_file_name), "%s/%d/%s", CP_DATA_REPOSITORY_PATH, ext_id, CP_TYPE_FILE_NAME);
651         _DEBUG_TRACE("type file name : %s", type_file_name);
652
653 //      int file_ret = sync_agent_write_file(CP_TYPE_REPOSITORY_PATH, type, 1, 1, 1);
654 //      int file_ret = sync_agent_write_whole_file(CP_TYPE_REPOSITORY_PATH, type, 1, 1);
655         int file_ret = sync_agent_write_whole_file(type_file_name, type, 1, 1);
656         if (file_ret != 1) {
657                 _DEBUG_TRACE("Failed to repository CP Type");
658                 _INNER_FUNC_EXIT;
659                 return CP_ERROR_FAIL;
660         }
661
662         /*
663          * 3. Registry (DM_CP) to storage
664          */
665         char wbxml_file_name[50] = { 0, };
666         snprintf(wbxml_file_name, sizeof(wbxml_file_name), "%s/%d/%s", CP_DATA_REPOSITORY_PATH, ext_id, CP_WBXML_FILE_NAME);
667         _DEBUG_TRACE("wbxml file name : %s", wbxml_file_name);
668 //      file_ret = sync_agent_write_file(CP_WBXML_REPOSITORY_PATH, msgBody, msgSize, 1, 1);
669 //      file_ret = sync_agent_write_whole_file(CP_WBXML_REPOSITORY_PATH, msgBody, msgSize, 1);
670         file_ret = sync_agent_write_whole_file(wbxml_file_name, msgBody, msgSize, 1);
671         if (file_ret != 1) {
672                 _DEBUG_TRACE("Failed to repository CP Body");
673                 _INNER_FUNC_EXIT;
674                 return CP_ERROR_FAIL;
675         }
676
677         /*
678          * 3. Handling Overwrite
679          */
680         CP_Data *dm_cp_data = (CP_Data *) calloc(1, sizeof(CP_Data));
681         if (dm_cp_data == NULL) {
682                 _DEBUG_TRACE("CP_Data calloc failed !!");
683                 _INNER_FUNC_EXIT;
684                 return CP_ERROR_FAIL;
685         }
686
687         dm_cp_data->ext_id = ext_id;
688         /*
689          * Parse recieved CP to sturct DM_CP
690          */
691 //      dm_cp = parsing_cp_stream(cp_type, msgBody, msgSize);
692 //      if (dm_cp == 0) {
693 //              _DEBUG_TRACE("parsing_cp_stream() failed !!");
694 //              /* todo : exception handling */
695 //              return CP_ERROR_FAIL;
696 //      }
697
698         dm_cp_data->dm_cp = parsing_cp_stream(cp_type, msgBody, msgSize);
699         if (dm_cp_data->dm_cp == 0) {
700                 _DEBUG_TRACE("parsing_cp_stream() failed !!");
701                 /* todo : exception handling */
702                 _INNER_FUNC_EXIT;
703                 return CP_ERROR_FAIL;
704         }
705
706         dm_cp_list = g_list_append(dm_cp_list, dm_cp_data);
707
708         /*
709          * 4. Interact Msg F/W
710          */
711         // create message
712         pmci_san_message_s *send_msg = (pmci_san_message_s *) calloc(1, sizeof(pmci_san_message_s));
713         if (send_msg == NULL) {
714                 _DEBUG_TRACE("calloc fail !!");
715                 _INNER_FUNC_EXIT;
716                 return CP_ERROR_FAIL;
717         }
718
719         send_msg->ext_id = ext_id;
720 //      send_msg->ext_id = 11;                                  // ?? : temp setting value? unique management (id_provider available?) todo??
721 //      send_msg->pin_code = pin_code;          // PIN code
722 //      char *msgData = "SYNCML";
723         char *msgData = NULL;
724         msgData = (char *)calloc(MSG_SIZE, sizeof(char));
725
726         if (msgData == NULL) {
727                 _DEBUG_TRACE("calloc failed !!");
728                 _INNER_FUNC_EXIT;
729                 return CP_ERROR_FAIL;
730         }
731
732         int err = __make_view_message(&msgData, dm_cp_data->dm_cp);
733         if (err != 1) {
734                 _DEBUG_TRACE("__make_view_message() failed !!");
735
736                 if (msgData != NULL)
737                         free(msgData);
738
739                 _INNER_FUNC_EXIT;
740                 return CP_ERROR_FAIL;
741         } else {
742
743                 _DEBUG_TRACE("__make_view_message() success !!");
744                 _DEBUG_TRACE("msgData : %s", msgData);
745         }
746
747 //      char *msgData = "Configuration message \n Application : Browser \n Proxy : wap_proxy \n Port : 9201 \n Received date : 17/04/2012";
748         if (msgData != NULL)
749                 send_msg->msg_data = strdup(msgData);   // message that will be sent to MF
750
751         ret = __send_msg2mf(ADD_MESSAGE, (void *)send_msg);
752         if (ret != CP_ERROR_SUCCESS) {
753                 _DEBUG_TRACE("__sendMsg2MF() failed !!");
754         } else {
755                 _DEBUG_TRACE("__sendMsg2MF() success !!");
756         }
757
758         _INNER_FUNC_EXIT;
759         return ret;
760 }
761
762 static CP_ERROR __send_msg2mf(SENDMSG_TYPE send_type, void *send_msg)
763 {
764         _INNER_FUNC_ENTER;
765
766         CP_ERROR res = CP_ERROR_SUCCESS;
767         sync_agent_pm_return_e err_sendMsg = SYNC_AGENT_PM_SUCCESS;
768
769         switch (send_type) {
770         case ADD_MESSAGE:
771                 {
772                         int out_add_item_id = 0;        // meaningless value
773
774                         /* send message (add) */
775                         err_sendMsg = sync_agent_add_service_data(6, (void *)send_msg, &out_add_item_id);
776                         if (err_sendMsg != SYNC_AGENT_PM_SUCCESS) {
777                                 _DEBUG_VERBOSE("send msg ( ADD_MESSAGE ) to MF fail !!");
778                                 res = CP_ERROR_FAIL;
779                                 goto return_part;
780                                 /* todo : exception handling */
781                         } else {
782                                 _DEBUG_VERBOSE("send msg ( ADD_MESSAGE ) to MF success !!");
783                         }
784                         _DEBUG_VERBOSE("---------------------------------------");
785                         _DEBUG_VERBOSE("OUT ADD ITEM %d", out_add_item_id);
786                         _DEBUG_VERBOSE("---------------------------------------");
787                 }
788                 break;
789         case REMOVE_MESSAGE:
790                 {
791                         /* send message (remove) */
792                         err_sendMsg = sync_agent_remove_service_data(6, g_msgId);
793                         if (err_sendMsg != SYNC_AGENT_PM_SUCCESS) {
794                                 _DEBUG_VERBOSE("send msg ( REMOVE_MESSAGE ) to MF fail !!");
795                                 res = CP_ERROR_FAIL;
796                                 goto return_part;
797                                 /* todo : exception handling */
798                         } else {
799                                 _DEBUG_VERBOSE("send msg ( REMOVE_MESSAGE ) to MF success !!");
800                         }
801                 }
802                 break;
803         default:
804                 break;
805         }
806
807  return_part:
808         if (send_msg != NULL) {
809                 if (((pmci_san_message_s *) send_msg)->msg_data != NULL)
810                         free(((pmci_san_message_s *) send_msg)->msg_data);
811                 free(send_msg);
812         }
813
814         _INNER_FUNC_EXIT;
815         return res;
816 }
817
818 static CP_ERROR _process_setting_oma_ds(DM_CP * dm_cp)
819 {
820         _INNER_FUNC_ENTER;
821         CP_ERROR ret = CP_ERROR_SUCCESS;
822
823         retvm_if((dm_cp) == NULL, CP_ERROR_FAIL, "dm_cp is NULL!!");
824
825         int event_type = 8;
826         /*sync_agent_event_error_e error; */
827
828         sync_agent_event_data_s *event = sync_agent_create_event(event_type);
829         if (event == NULL) {
830                 _DEBUG_TRACE("event is NULL");
831                 _INNER_FUNC_EXIT;
832                 return 0;
833         }
834
835         DM_CP_Application *cp_application = dm_cp->applications;
836
837         _DEBUG_TRACE("cp_application->name : %s", cp_application->name);
838         sync_agent_append_event_data_param(event, SYNC_AGENT_EVENT_PARAM_TYPE_STRING, cp_application->name);    /* profileName */
839
840         String_Node *addr = cp_application->addr;
841         if (addr != NULL) {
842                 _DEBUG_TRACE("cp_application->addr : %s", addr->data);
843                 sync_agent_append_event_data_param(event, SYNC_AGENT_EVENT_PARAM_TYPE_STRING, addr->data);      /* addr */
844         } else {
845                 sync_agent_append_event_data_param(event, SYNC_AGENT_EVENT_PARAM_TYPE_STRING, "");      /* addr */
846         }
847
848         DM_CP_Application_AppAuth *cp_auth = cp_application->appAuth;
849         if (cp_auth != NULL) {
850                 sync_agent_append_event_data_param(event, SYNC_AGENT_EVENT_PARAM_TYPE_STRING, cp_auth->auth_name);      /* id */
851                 _DEBUG_TRACE("cp_application->auth_name : %s", cp_auth->auth_name);
852                 sync_agent_append_event_data_param(event, SYNC_AGENT_EVENT_PARAM_TYPE_STRING, cp_auth->auth_secret);    /* password */
853                 _DEBUG_TRACE("cp_application->auth_secret : %s", cp_auth->auth_secret);
854         } else {
855                 sync_agent_append_event_data_param(event, SYNC_AGENT_EVENT_PARAM_TYPE_STRING, "");      /* id */
856                 sync_agent_append_event_data_param(event, SYNC_AGENT_EVENT_PARAM_TYPE_STRING, "");      /* password */
857         }
858
859         int categoryCount = 0;
860         DM_CP_Application_Resource *cp_resource = cp_application->resource;
861         while (cp_resource != 0) {
862                 categoryCount++;
863                 cp_resource = cp_resource->next;
864         }
865         sync_agent_append_event_data_param(event, SYNC_AGENT_EVENT_PARAM_TYPE_INTEGER, &categoryCount); /* categoryCount */
866
867         cp_resource = cp_application->resource;
868
869         while (cp_resource != 0) {
870                 sync_agent_append_event_data_param(event, SYNC_AGENT_EVENT_PARAM_TYPE_STRING, cp_resource->name);       /* name */
871                 sync_agent_append_event_data_param(event, SYNC_AGENT_EVENT_PARAM_TYPE_STRING, cp_resource->accept);     /* accept */
872                 sync_agent_append_event_data_param(event, SYNC_AGENT_EVENT_PARAM_TYPE_STRING, cp_resource->auth_name);  /* id */
873                 sync_agent_append_event_data_param(event, SYNC_AGENT_EVENT_PARAM_TYPE_STRING, cp_resource->auth_secret);        /* password */
874                 sync_agent_append_event_data_param(event, SYNC_AGENT_EVENT_PARAM_TYPE_STRING, cp_resource->auth_type);  /* auth_type */
875                 sync_agent_append_event_data_param(event, SYNC_AGENT_EVENT_PARAM_TYPE_STRING, cp_resource->auth_data);  /* auth_data */
876
877                 cp_resource = cp_resource->next;
878         }
879
880         /*
881          * IPC ( send msg to OMA DS Agent )
882          * Below rutine is made by Hard Coding?! If that, So Terrible.. I should consider this situation. - RJW
883          */
884
885         int client_len;
886         int client_sockfd;
887         struct sockaddr_un clientaddr;
888
889         client_sockfd = socket(AF_UNIX, SOCK_STREAM, 0);
890         if (client_sockfd == -1) {
891                 _DEBUG_TRACE("socket create Error!!");
892                 sync_agent_free_event(event);
893                 _INNER_FUNC_EXIT;
894                 return CP_ERROR_FAIL;
895         }
896
897         bzero(&clientaddr, sizeof(clientaddr));
898         clientaddr.sun_family = AF_UNIX;
899
900         int str_len = 0;
901
902         str_len = g_strlcpy(clientaddr.sun_path, IPC_DS, (int)sizeof(clientaddr.sun_path));
903         if (str_len >= sizeof(clientaddr.sun_path)) {
904                 _DEBUG_TRACE("buffer overflow");
905                 sync_agent_free_event(event);
906                 close(client_sockfd);
907                 _INNER_FUNC_EXIT;
908                 return CP_ERROR_FAIL;
909         }
910         client_len = sizeof(clientaddr);
911
912         if (connect(client_sockfd, (struct sockaddr *)&clientaddr, client_len) < 0) {
913                 _DEBUG_TRACE("socket connect error");
914                 sync_agent_free_event(event);
915                 close(client_sockfd);
916                 _INNER_FUNC_EXIT;
917                 return CP_ERROR_FAIL;
918         }
919
920         int send_data_size = (event->data - event->size) + 1;
921         int write_ret = write(client_sockfd, (void *)(event->size), send_data_size);
922         _DEBUG_TRACE("write ret : %d", write_ret);
923         close(client_sockfd);
924         sync_agent_free_event(event);
925
926         _INNER_FUNC_EXIT;
927
928         return ret;
929 }
930
931 static CP_ERROR _process_setting_oma_dm(DM_CP * dm_cp)
932 {
933         _INNER_FUNC_ENTER;
934
935         CP_ERROR ret = CP_ERROR_SUCCESS;
936         DM_ERROR dm_ret = DM_OK;
937
938         retvm_if((dm_cp) == NULL, CP_ERROR_FAIL, "dm_cp is NULL!!");
939
940         DM_CP_Application *applications = dm_cp->applications;
941         dm_acc *dmaccount = NULL;
942         if (applications != NULL) {
943                 if (applications->provider_ID != NULL) {
944                         dmaccount = (dm_acc *) calloc(1, sizeof(dm_acc));
945                         if (dmaccount == NULL) {
946                                 _DEBUG_TRACE("alloc fail");
947                                 _INNER_FUNC_EXIT;
948                                 return 0;
949                         }
950                         char *server_id = NULL;
951                         server_id = strdup(applications->provider_ID);
952                         /*get_Serverid(SAMSUNG_FUMO_TYPE , &server_id); */
953                         _DEBUG_TRACE("server id : %s", server_id);
954
955                         dmaccount->server_id = strdup(applications->provider_ID);
956                         _DEBUG_TRACE("server id : %s", dmaccount->server_id);
957
958                         if (applications->addr != NULL) {
959                                 dmaccount->server_url = strdup(applications->addr->data);
960                                 _DEBUG_TRACE("server url : %s", dmaccount->server_url);
961                         }
962
963                         DM_CP_Application_AppAuth *appAuth = applications->appAuth;
964
965                         if (appAuth != NULL) {
966                                 while (1) {
967                                         if (appAuth->auth_level != NULL) {
968                                                 if (strcmp("APPSRV", appAuth->auth_level) == 0) {
969                                                         if (appAuth->auth_secret != NULL) {
970                                                                 dmaccount->server_pw = strdup(appAuth->auth_secret);
971                                                                 _DEBUG_TRACE("server_pw : %s", dmaccount->server_pw);
972                                                         }
973                                                         if (appAuth->auth_type != NULL) {
974                                                                 if (strstr(appAuth->auth_type, "DIGEST") != NULL) {
975                                                                         dmaccount->server_auth_type = strdup("DIGEST");
976                                                                         _DEBUG_TRACE("server_auth_type : %s", dmaccount->server_auth_type);
977                                                                 } else if (strstr(appAuth->auth_type, "HMAC") != NULL) {
978                                                                         dmaccount->server_auth_type = strdup("HMAC");
979                                                                         _DEBUG_TRACE("server_auth_type : %s", dmaccount->server_auth_type);
980                                                                 } else if (strstr(appAuth->auth_type, "BASIC") != NULL) {
981                                                                         dmaccount->server_auth_type = strdup("BASIC");
982                                                                         _DEBUG_TRACE("server_auth_type : %s", dmaccount->server_auth_type);
983                                                                 } else {
984                                                                         _DEBUG_TRACE("server_auth_type: %s", appAuth->auth_type);
985                                                                         dmaccount->server_auth_type = strdup("DIGEST");
986                                                                         _DEBUG_TRACE("server_nextNonce : %s", dmaccount->server_auth_type);
987                                                                 }
988                                                         } else if (appAuth->auth_type == NULL && dmaccount->server_auth_type == NULL) {
989                                                                 dmaccount->server_auth_type = strdup("DIGEST");
990                                                                 _DEBUG_TRACE("user_auth_type : %s", dmaccount->server_auth_type);
991                                                         }
992
993                                                         if (appAuth->auth_data != NULL) {
994                                                                 dmaccount->server_nextNonce = strdup(appAuth->auth_data);
995                                                                 _DEBUG_TRACE("server_nextNonce : %s", dmaccount->server_nextNonce);
996                                                         }
997                                                 } else if (!strcmp("CLIENT", appAuth->auth_level)) {
998                                                         if (appAuth->auth_secret != NULL) {
999                                                                 dmaccount->user_pw = strdup(appAuth->auth_secret);
1000                                                                 _DEBUG_TRACE("user_pw : %s", dmaccount->user_pw);
1001                                                         }
1002
1003                                                         if (appAuth->auth_type != NULL) {
1004                                                                 if (strstr(appAuth->auth_type, "DIGEST") != NULL) {
1005                                                                         dmaccount->user_auth_type = strdup("DIGEST");
1006                                                                         _DEBUG_TRACE("user_auth_type : %s", dmaccount->user_auth_type);
1007                                                                 } else if (strstr(appAuth->auth_type, "HMAC") != NULL) {
1008                                                                         dmaccount->user_auth_type = strdup("HMAC");
1009                                                                         _DEBUG_TRACE("user_auth_type : %s", dmaccount->user_auth_type);
1010                                                                 } else if (strstr(appAuth->auth_type, "BASIC") != NULL) {
1011                                                                         dmaccount->user_auth_type = strdup("BASIC");
1012                                                                         _DEBUG_TRACE("user_auth_type : %s", dmaccount->user_auth_type);
1013                                                                 } else {
1014                                                                         _DEBUG_TRACE("user_auth_type : %s", appAuth->auth_type);
1015                                                                         dmaccount->user_auth_type = strdup("DIGEST");
1016                                                                         _DEBUG_TRACE("user_auth_type : %s", dmaccount->user_auth_type);
1017                                                                 }
1018                                                         } else if (appAuth->auth_type == NULL && dmaccount->user_auth_type == NULL) {
1019                                                                 dmaccount->user_auth_type = strdup("DIGEST");
1020                                                                 _DEBUG_TRACE("user_auth_type : %s", dmaccount->user_auth_type);
1021                                                         }
1022
1023                                                         if (appAuth->auth_name != NULL) {
1024                                                                 dmaccount->user_id = strdup(appAuth->auth_name);
1025                                                                 _DEBUG_TRACE("user_id : %s", dmaccount->user_id);
1026                                                         }
1027                                                         if (appAuth->auth_data != NULL) {
1028                                                                 dmaccount->user_nextNonce = strdup(appAuth->auth_data);
1029                                                                 _DEBUG_TRACE("user_auth_type: %s", dmaccount->user_nextNonce);
1030                                                         }
1031                                                 }
1032                                         } else {
1033                                                 ret = CP_ERROR_FAIL;
1034                                                 free_dm_acc(dmaccount);
1035                                                 goto error;
1036                                         }
1037
1038                                         if (appAuth->next != NULL) {
1039                                                 appAuth = appAuth->next;
1040                                         } else {
1041                                                 break;
1042                                         }
1043                                 }
1044                         }
1045
1046                         if (server_id != NULL) {
1047                                 int is_exist = 0;
1048                                 SERVICE_SERVER_TYPE dmacc_type = NO_ENGINE_TYPE;
1049
1050                                 dmacc_type = get_engine_type_by_serverid(server_id);
1051                                 _DEBUG_TRACE(" dm acc type : %d", dmacc_type);
1052
1053                                 if (dmacc_type != NO_ENGINE_TYPE) {
1054                                         dm_ret = is_exist_dmacc(dmacc_type, &is_exist);
1055                                         if (dm_ret != DM_OK) {
1056                                                 _DEBUG_TRACE("error is exist dm acc ");
1057                                                 ret = CP_ERROR_FAIL;
1058                                                 goto error;
1059                                         }
1060
1061                                         if (is_exist == 1) {
1062                                                 _DEBUG_TRACE("exist dm acc ");
1063                                                 ret = update_dmacc(server_id, dmaccount);
1064                                                 _DEBUG_TRACE("update dm acc %d", ret);
1065                                                 if (ret == 1) {
1066                                                         first_server_bootstrap(server_id);
1067                                                         ret = CP_ERROR_SUCCESS;
1068                                                 } else {
1069                                                         ret = CP_ERROR_FAIL;
1070                                                         goto error;
1071                                                 }
1072                                         } else {
1073                                                 _DEBUG_TRACE("not exist dm acc ");
1074                                                 ret = CP_ERROR_FAIL;
1075                                         }
1076                                 } else {
1077                                         _DEBUG_TRACE("dmacc type is none");
1078                                         ret = CP_ERROR_FAIL;
1079                                 }
1080                         } else {
1081                                 _DEBUG_TRACE("server id is null");
1082                                 ret = CP_ERROR_FAIL;
1083                         }
1084
1085                         _DEBUG_TRACE("update dm acc : %d", ret);
1086                         free_dm_acc(dmaccount);
1087                 }
1088         } else {
1089                 ret = CP_ERROR_FAIL;
1090                 goto error;
1091         }
1092
1093         _INNER_FUNC_EXIT;
1094         return ret;
1095
1096  error:
1097         _DEBUG_TRACE("error : %d", ret);
1098         _INNER_FUNC_EXIT;
1099         return ret;
1100
1101 }
1102
1103 static char __char2hex(char ch)
1104 {
1105         _INNER_FUNC_ENTER;
1106
1107         char ret = 0x00;
1108         switch (ch) {
1109         case '0':
1110                 ret = 0x00;
1111                 break;
1112         case '1':
1113                 ret = 0x01;
1114                 break;
1115         case '2':
1116                 ret = 0x02;
1117                 break;
1118         case '3':
1119                 ret = 0x03;
1120                 break;
1121         case '4':
1122                 ret = 0x04;
1123                 break;
1124         case '5':
1125                 ret = 0x05;
1126                 break;
1127         case '6':
1128                 ret = 0x06;
1129                 break;
1130         case '7':
1131                 ret = 0x07;
1132                 break;
1133         case '8':
1134                 ret = 0x08;
1135                 break;
1136         case '9':
1137                 ret = 0x09;
1138                 break;
1139         default:
1140                 break;
1141         }
1142
1143         _DEBUG_VERBOSE("ch : %c ( 0x%02X )", ch, ret);
1144         _INNER_FUNC_EXIT;
1145         return ret;
1146 }
1147
1148 static char *_get_netpin_key(int *key_len)
1149 {
1150         _INNER_FUNC_ENTER;
1151
1152         sync_agent_dev_return_e err = SYNC_AGENT_DEV_RETURN_SUCCESS;
1153         char *imsi_value = 0;
1154         char *trans_imsi_value = 0;
1155         int imsi_len = 0;
1156
1157 //      char key[8] = {0, };
1158         char *key = NULL;
1159         char temp1, temp2;
1160         int i = 0;
1161
1162         int flag = 0;
1163
1164         err = sync_agent_get_devinfo(2, "IMSI", &imsi_value);
1165         if (err != SYNC_AGENT_DEV_RETURN_SUCCESS) {
1166                 _DEBUG_TRACE("imsi value is error !!");
1167                 goto return_part;
1168         } else {
1169                 flag = 1;
1170                 _DEBUG_TRACE("sync_agent_get_devinfo( IMSI ) success !!");
1171         }
1172
1173         _DEBUG_TRACE("IMSI value : %s", imsi_value);
1174         int len = 0;
1175
1176         imsi_len = strlen(imsi_value);
1177         if ((imsi_len % 2) == 1) {
1178                 imsi_len += 2;
1179                 trans_imsi_value = (char *)calloc(imsi_len, sizeof(char));
1180
1181                 if (trans_imsi_value == NULL) {
1182                         _DEBUG_TRACE("calloc failed !!");
1183                         goto return_part;
1184                 }
1185
1186                 len = g_strlcat(trans_imsi_value, "9", imsi_len);
1187                 len = g_strlcat(trans_imsi_value, imsi_value, imsi_len);
1188
1189                 if (len >= imsi_len) {
1190                         _DEBUG_TRACE(" buffer overflow !!");
1191                         /* todo : exception handling */
1192                 }
1193
1194         } else {
1195                 imsi_len += 3;
1196                 trans_imsi_value = (char *)calloc(imsi_len, sizeof(char));
1197
1198                 if (trans_imsi_value == NULL) {
1199                         _DEBUG_TRACE("calloc failed !!");
1200                         goto return_part;
1201                 }
1202
1203                 len = g_strlcat(trans_imsi_value, "1", imsi_len);
1204                 len = g_strlcat(trans_imsi_value, imsi_value, imsi_len);
1205                 len = g_strlcat(trans_imsi_value, "F", imsi_len);
1206
1207                 if (len >= imsi_len) {
1208                         _DEBUG_TRACE(" buffer overflow !!");
1209                         /* todo : exception handling */
1210                 }
1211
1212         }
1213
1214         *key_len = imsi_len / 2;
1215         _DEBUG_TRACE("imsi value len : %d", *key_len);
1216
1217         key = (char *)calloc(*key_len, sizeof(char));
1218         if (key == NULL) {
1219                 _DEBUG_TRACE("calloc failed !!");
1220                 goto return_part;
1221         }
1222
1223         for (; i < *key_len; i++) {
1224                 temp1 = __char2hex(trans_imsi_value[i * 2 + 1]);
1225                 temp2 = __char2hex(trans_imsi_value[i * 2]);
1226                 key[i] = (temp1 << 4) | temp2;
1227                 temp1 = 0;
1228                 temp2 = 0;
1229                 _DEBUG_TRACE("key[%d] : 0x%02X", i, key[i]);
1230         }
1231
1232  return_part:
1233         if ((imsi_value != NULL) && (flag == 1))
1234                 free(imsi_value);
1235
1236         if (trans_imsi_value != NULL)
1237                 free(trans_imsi_value);
1238
1239         _INNER_FUNC_EXIT;
1240         return key;
1241 }
1242
1243 static int __make_view_message(char **msgData, DM_CP * dm_cp)
1244 {
1245         _INNER_FUNC_ENTER;
1246
1247         int res = 1;
1248         int len = 0;
1249
1250         /* Application */
1251         retvm_if((dm_cp) == NULL, 0, "dm_cp is NULL!!");
1252
1253         len = g_strlcat(*msgData, APPLICATION, MSG_SIZE);
1254         if (dm_cp->applications->app_ID != NULL) {
1255                 if (dm_cp->applications->name != NULL) {
1256                         _DEBUG_VERBOSE("name : %s", dm_cp->applications->name);
1257
1258                         len = g_strlcat(*msgData, dm_cp->applications->name, MSG_SIZE);
1259                 }
1260
1261                 len = g_strlcat(*msgData, L_BRACKET, MSG_SIZE);
1262                 if (strcmp(dm_cp->applications->app_ID, "w2") == 0) {
1263                         _DEBUG_VERBOSE("app id : %s", W2);
1264
1265                         len = g_strlcat(*msgData, W2, MSG_SIZE);
1266                 } else if (strcmp(dm_cp->applications->app_ID, "w4") == 0) {
1267                         _DEBUG_VERBOSE("app id : %s", W4);
1268
1269                         len = g_strlcat(*msgData, W4, MSG_SIZE);
1270                 } else if (strcmp(dm_cp->applications->app_ID, "w5") == 0) {
1271                         _DEBUG_VERBOSE("app id : %s", W5);
1272
1273                         len = g_strlcat(*msgData, W5, MSG_SIZE);
1274                 } else if (strcmp(dm_cp->applications->app_ID, "w7") == 0) {
1275                         _DEBUG_VERBOSE("app id : %s", W7);
1276
1277                         len = g_strlcat(*msgData, W7, MSG_SIZE);
1278                 } else if (strcmp(dm_cp->applications->app_ID, "wA") == 0) {
1279                         _DEBUG_VERBOSE("app id : %s", WA);
1280
1281                         len = g_strlcat(*msgData, WA, MSG_SIZE);
1282                 } else {
1283                         _DEBUG_VERBOSE("app id : undefined !!");
1284                         len = g_strlcat(*msgData, "Undefined ", MSG_SIZE);
1285                 }
1286
1287                 len = g_strlcat(*msgData, R_BRACKET, MSG_SIZE);
1288         } else {
1289                 _DEBUG_VERBOSE("Application ID is not existed - Invalid format !!");
1290                 _INNER_FUNC_EXIT;
1291                 return 0;
1292         }
1293
1294         len = g_strlcat(*msgData, LB, MSG_SIZE);
1295 //      _DEBUG_VERBOSE("msg data : %s", *msgData);
1296
1297         /* URL */
1298
1299         len = g_strlcat(*msgData, URL, MSG_SIZE);
1300         if (dm_cp->applications->addr != NULL) {
1301                 if (dm_cp->applications->addr->data != NULL) {
1302                         _DEBUG_VERBOSE("url : %s", dm_cp->applications->addr->data);
1303
1304                         len = g_strlcat(*msgData, dm_cp->applications->addr->data, MSG_SIZE);
1305                 } else {
1306
1307                         len = g_strlcat(*msgData, NO_DATA, MSG_SIZE);
1308                 }
1309         } else {
1310
1311                 len = g_strlcat(*msgData, NO_DATA, MSG_SIZE);
1312
1313         }
1314
1315         len = g_strlcat(*msgData, LB, MSG_SIZE);
1316 //      _DEBUG_VERBOSE("msg data : %s", *msgData);
1317
1318         /* NAP Addr type */
1319         if (dm_cp->napdefs != NULL) {
1320                 if (dm_cp->napdefs->nap_addr_type != NULL) {
1321                         _DEBUG_VERBOSE("nap addr type : %s", dm_cp->napdefs->nap_addr_type);
1322
1323                         len = g_strlcat(*msgData, dm_cp->napdefs->nap_addr_type, MSG_SIZE);
1324                         len = g_strlcat(*msgData, DELIMITER, MSG_SIZE);
1325                         if (dm_cp->napdefs->nap_address != NULL) {
1326                                 _DEBUG_VERBOSE("nap addr : %s", dm_cp->napdefs->nap_address);
1327                                 len = g_strlcat(*msgData, dm_cp->napdefs->nap_address, MSG_SIZE);
1328
1329                         }
1330                 } else {
1331
1332                         len = g_strlcat(*msgData, DEFAULT_NAP_TYPE, MSG_SIZE);
1333                         len = g_strlcat(*msgData, NO_DATA, MSG_SIZE);
1334                 }
1335         } else {
1336
1337                 len = g_strlcat(*msgData, DEFAULT_NAP_TYPE, MSG_SIZE);
1338                 len = g_strlcat(*msgData, NO_DATA, MSG_SIZE);
1339         }
1340
1341         len = g_strlcat(*msgData, LB, MSG_SIZE);
1342
1343 //      _DEBUG_VERBOSE("msg data : %s", *msgData);
1344
1345         /* Proxy */
1346
1347         len = g_strlcat(*msgData, PROXY, MSG_SIZE);
1348
1349         if (dm_cp->applications->to_proxy != NULL) {
1350                 if (dm_cp->applications->to_proxy->data != NULL) {
1351                         _DEBUG_VERBOSE("proxy : %s", dm_cp->applications->to_proxy->data);
1352
1353                         len = g_strlcat(*msgData, dm_cp->applications->to_proxy->data, MSG_SIZE);
1354                 } else {
1355
1356                         len = g_strlcat(*msgData, NO_DATA, MSG_SIZE);
1357
1358                 }
1359         } else {
1360
1361                 len = g_strlcat(*msgData, NO_DATA, MSG_SIZE);
1362         }
1363
1364         len = g_strlcat(*msgData, LB, MSG_SIZE);
1365 //      _DEBUG_VERBOSE("msg data : %s", *msgData);
1366
1367         /* Port */
1368
1369         len = g_strlcat(*msgData, PORT, MSG_SIZE);
1370         if (dm_cp->pxLogical != NULL) {
1371                 if (dm_cp->pxLogical->port != NULL) {
1372                         if (dm_cp->pxLogical->port->portnbr != NULL) {
1373                                 _DEBUG_VERBOSE("port : %s", dm_cp->pxLogical->port->portnbr);
1374
1375                                 len = g_strlcat(*msgData, dm_cp->pxLogical->port->portnbr, MSG_SIZE);
1376                         } else {
1377
1378                                 len = g_strlcat(*msgData, NO_DATA, MSG_SIZE);
1379                         }
1380                 } else {
1381
1382                         len = g_strlcat(*msgData, NO_DATA, MSG_SIZE);
1383                 }
1384         } else {
1385
1386                 len = g_strlcat(*msgData, NO_DATA, MSG_SIZE);
1387         }
1388
1389         len = g_strlcat(*msgData, LB, MSG_SIZE);
1390 //      _DEBUG_VERBOSE("msg data : %s", *msgData);
1391
1392         if (len >= MSG_SIZE) {
1393                 _DEBUG_VERBOSE("over flow error");
1394                 res = -1;
1395         }
1396
1397         _INNER_FUNC_EXIT;
1398         return res;
1399 }
1400
1401 void free_cp_application(DM_CP_Application * app)
1402 {
1403         retm_if((app) == NULL, "dm_cp application is NULL!!");
1404
1405         if (app->accept != NULL) {
1406                 str_free(&(app->accept));
1407                 app->accept = NULL;
1408         }
1409         if (app->addr != NULL) {
1410                 free_string_node(app->addr);
1411                 app->addr = NULL;
1412         }
1413         if (app->appAddr != NULL) {
1414                 free_cp_application_app_addr(app->appAddr);
1415                 app->appAddr = NULL;
1416         }
1417         if (app->appAuth != NULL) {
1418                 free_cp_application_app_auth(app->appAuth);
1419                 app->appAuth = NULL;
1420         }
1421         if (app->app_ID != NULL) {
1422                 str_free(&(app->app_ID));
1423                 app->app_ID = NULL;
1424         }
1425         if (app->name != NULL) {
1426                 str_free(&(app->name));
1427                 app->name = NULL;
1428         }
1429         if (app->protocol != NULL) {
1430                 str_free(&(app->protocol));
1431                 app->protocol = NULL;
1432         }
1433         if (app->provider_ID != NULL) {
1434                 str_free(&(app->provider_ID));
1435                 app->provider_ID = NULL;
1436         }
1437         if (app->resource != NULL) {
1438                 free_cp_application_resource(app->resource);
1439                 app->resource = NULL;
1440         }
1441         if (app->to_napid != NULL) {
1442                 free_string_node(app->to_napid);
1443                 app->to_napid = NULL;
1444         }
1445         if (app->to_proxy != NULL) {
1446                 free_string_node(app->to_proxy);
1447                 app->to_proxy = NULL;
1448         }
1449         if (app->next != NULL) {
1450                 free_cp_application(app->next);
1451                 app->next = NULL;
1452         }
1453         free(app);
1454         app = NULL;
1455 }
1456
1457 void free_cp_application_app_addr(DM_CP_Application_AppAddr * app_addr)
1458 {
1459         retm_if((app_addr) == NULL, "dm_cp is NULL!!");
1460
1461         if (app_addr->addr != NULL) {
1462                 str_free(&(app_addr->addr));
1463                 app_addr->addr = NULL;
1464         }
1465
1466         if (app_addr->addr_type != NULL) {
1467                 str_free(&(app_addr->addr_type));
1468                 app_addr->addr_type = NULL;
1469         }
1470
1471         if (app_addr->port != NULL) {
1472                 free_cp_port(app_addr->port);
1473                 app_addr->port = NULL;
1474         }
1475
1476         if (app_addr->next != NULL) {
1477                 free_cp_application_app_addr(app_addr->next);
1478                 app_addr->next = NULL;
1479         }
1480
1481         free(app_addr);
1482         app_addr = NULL;
1483 }
1484
1485 void free_cp_application_app_auth(DM_CP_Application_AppAuth * appAuth)
1486 {
1487         retm_if((appAuth) == NULL, "dm_cp appAuth is NULL!!");
1488
1489         if (appAuth->auth_data != NULL) {
1490                 str_free(&(appAuth->auth_data));
1491                 appAuth->auth_data = NULL;
1492         }
1493         if (appAuth->auth_level != NULL) {
1494                 str_free(&(appAuth->auth_level));
1495                 appAuth->auth_level = NULL;
1496         }
1497         if (appAuth->auth_name != NULL) {
1498                 str_free(&(appAuth->auth_name));
1499                 appAuth->auth_name = NULL;
1500         }
1501         if (appAuth->auth_secret != NULL) {
1502                 str_free(&(appAuth->auth_secret));
1503                 appAuth->auth_secret = NULL;
1504         }
1505
1506         if (appAuth->auth_type != NULL) {
1507                 str_free(&(appAuth->auth_type));
1508                 appAuth->auth_type = NULL;
1509         }
1510         if (appAuth->next != NULL) {
1511                 free_cp_application_app_auth(appAuth->next);
1512                 appAuth->next = NULL;
1513         }
1514
1515         free(appAuth);
1516         appAuth = NULL;
1517 }
1518
1519 void free_cp_application_resource(DM_CP_Application_Resource * resource)
1520 {
1521         retm_if((resource) == NULL, "dm_cp port is NULL!!");
1522
1523         if (resource->accept != NULL) {
1524                 str_free(&(resource->accept));
1525                 resource->accept = NULL;
1526         }
1527         if (resource->auth_data != NULL) {
1528                 str_free(&(resource->auth_data));
1529                 resource->auth_data = NULL;
1530         }
1531         if (resource->auth_name != NULL) {
1532                 str_free(&(resource->auth_name));
1533                 resource->auth_name = NULL;
1534         }
1535         if (resource->auth_secret != NULL) {
1536                 str_free(&(resource->auth_secret));
1537                 resource->auth_secret = NULL;
1538         }
1539         if (resource->auth_type != NULL) {
1540                 str_free(&(resource->auth_type));
1541                 resource->auth_type = NULL;
1542         }
1543         if (resource->name != NULL) {
1544                 str_free(&(resource->name));
1545                 resource->name = NULL;
1546         }
1547         if (resource->start_page != NULL) {
1548                 str_free(&(resource->start_page));
1549                 resource->start_page = NULL;
1550         }
1551         if (resource->uri != NULL) {
1552                 str_free(&(resource->uri));
1553                 resource->uri = NULL;
1554         }
1555         if (resource->next != NULL) {
1556                 free_cp_application_resource(resource->next);
1557                 resource->next = NULL;
1558         }
1559
1560         free(resource);
1561         resource = NULL;
1562 }
1563
1564 void free_cp_port(DM_CP_Port * port)
1565 {
1566         retm_if((port) == NULL, "dm_cp port is NULL!!");
1567
1568         if (port->portnbr != NULL) {
1569                 str_free(&(port->portnbr));
1570                 port->portnbr = NULL;
1571         }
1572         if (port->service != NULL) {
1573                 free_string_node(port->service);
1574                 port->service = NULL;
1575         }
1576         if (port->next != NULL) {
1577                 free_cp_port(port->next);
1578                 port->next = NULL;
1579         }
1580
1581         free(port);
1582         port = NULL;
1583 }
1584
1585 void free_string_node(String_Node * service)
1586 {
1587         retm_if((service) == NULL, "dm_cp string node is NULL!!");
1588
1589         if (service->data != NULL) {
1590                 str_free(&(service->data));
1591                 service->data = NULL;
1592         }
1593         if (service->next != NULL) {
1594                 free_string_node(service->next);
1595                 service->next = NULL;
1596         }
1597
1598         free(service);
1599         service = NULL;
1600 }
1601
1602 void free_cp_napdef(DM_CP_Napdef * napdef)
1603 {
1604         retm_if((napdef) == NULL, "dm_cp napdef is NULL!!");
1605
1606         if (napdef->auth_info != NULL) {
1607                 free_cp_napdef_authinfo(napdef->auth_info);
1608                 napdef->auth_info = NULL;
1609         }
1610         if (napdef->bearer != NULL) {
1611                 free_string_node(napdef->bearer);
1612                 napdef->bearer = NULL;
1613         }
1614         if (napdef->call_type != NULL) {
1615                 str_free(&(napdef->call_type));
1616                 napdef->call_type = NULL;
1617         }
1618         if (napdef->delivery_err_sdu != NULL) {
1619                 str_free(&(napdef->delivery_err_sdu));
1620                 napdef->delivery_err_sdu = NULL;
1621         }
1622         if (napdef->delivery_order != NULL) {
1623                 str_free(&(napdef->delivery_order));
1624                 napdef->delivery_order = NULL;
1625         }
1626         if (napdef->dn_link_speed != NULL) {
1627                 str_free(&(napdef->dn_link_speed));
1628                 napdef->dn_link_speed = NULL;
1629         }
1630         if (napdef->dns_addr != NULL) {
1631                 free_string_node(napdef->dns_addr);
1632                 napdef->dns_addr = NULL;
1633         }
1634         if (napdef->first_retry_timeout != NULL) {
1635                 str_free(&(napdef->first_retry_timeout));
1636                 napdef->first_retry_timeout = NULL;
1637         }
1638         if (napdef->guaranteed_bitrate_dnlink != NULL) {
1639                 str_free(&(napdef->guaranteed_bitrate_dnlink));
1640                 napdef->guaranteed_bitrate_dnlink = NULL;
1641         }
1642         if (napdef->guaranteed_bitrate_uplink != NULL) {
1643                 str_free(&(napdef->guaranteed_bitrate_uplink));
1644                 napdef->guaranteed_bitrate_uplink = NULL;
1645         }
1646         if (napdef->internet != NULL) {
1647                 str_free(&(napdef->internet));
1648                 napdef->internet = NULL;
1649         }
1650         if (napdef->linger != NULL) {
1651                 str_free(&(napdef->linger));
1652                 napdef->linger = NULL;
1653         }
1654         if (napdef->link_speed != NULL) {
1655                 str_free(&(napdef->link_speed));
1656                 napdef->link_speed = NULL;
1657         }
1658         if (napdef->local_addr != NULL) {
1659                 str_free(&(napdef->local_addr));
1660                 napdef->local_addr = NULL;
1661         }
1662         if (napdef->local_addr_type != NULL) {
1663                 str_free(&(napdef->local_addr_type));
1664                 napdef->local_addr_type = NULL;
1665         }
1666         if (napdef->max_bitrate_dnlink != NULL) {
1667                 str_free(&(napdef->max_bitrate_dnlink));
1668                 napdef->max_bitrate_dnlink = NULL;
1669         }
1670         if (napdef->max_bitrate_uplink != NULL) {
1671                 str_free(&(napdef->max_bitrate_uplink));
1672                 napdef->max_bitrate_uplink = NULL;
1673         }
1674         if (napdef->max_num_retry != NULL) {
1675                 str_free(&(napdef->max_num_retry));
1676                 napdef->max_num_retry = NULL;
1677         }
1678         if (napdef->max_sdu_size != NULL) {
1679                 str_free(&(napdef->max_sdu_size));
1680                 napdef->max_sdu_size = NULL;
1681         }
1682         if (napdef->name != NULL) {
1683                 str_free(&(napdef->name));
1684                 napdef->name = NULL;
1685         }
1686         if (napdef->nap_ID != NULL) {
1687                 str_free(&(napdef->nap_ID));
1688                 napdef->nap_ID = NULL;
1689         }
1690         if (napdef->nap_addr_type != NULL) {
1691                 str_free(&(napdef->nap_addr_type));
1692                 napdef->nap_addr_type = NULL;
1693         }
1694         if (napdef->nap_address != NULL) {
1695                 str_free(&(napdef->nap_address));
1696                 napdef->nap_address = NULL;
1697         }
1698         if (napdef->rereg_threshold != NULL) {
1699                 str_free(&(napdef->rereg_threshold));
1700                 napdef->rereg_threshold = NULL;
1701         }
1702         if (napdef->residual_ber != NULL) {
1703                 str_free(&(napdef->residual_ber));
1704                 napdef->residual_ber = NULL;
1705         }
1706         if (napdef->sdu_error_ratio != NULL) {
1707                 str_free(&(napdef->sdu_error_ratio));
1708                 napdef->sdu_error_ratio = NULL;
1709         }
1710         if (napdef->t_bit != NULL) {
1711                 str_free(&(napdef->t_bit));
1712                 napdef->t_bit = NULL;
1713         }
1714         if (napdef->traffic_class != NULL) {
1715                 str_free(&(napdef->traffic_class));
1716                 napdef->traffic_class = NULL;
1717         }
1718         if (napdef->traffic_handl_prio != NULL) {
1719                 str_free(&(napdef->traffic_handl_prio));
1720                 napdef->traffic_handl_prio = NULL;
1721         }
1722         if (napdef->transfer_delay != NULL) {
1723                 str_free(&(napdef->transfer_delay));
1724                 napdef->transfer_delay = NULL;
1725         }
1726         if (napdef->validity != NULL) {
1727                 free_cp_napdef_validity(napdef->validity);
1728                 napdef->validity = NULL;
1729         }
1730         if (napdef->next != NULL) {
1731                 free_cp_napdef(napdef->next);
1732                 napdef->next = NULL;
1733         }
1734
1735         free(napdef);
1736         napdef = NULL;
1737
1738 }
1739
1740 void free_cp_napdef_authinfo(DM_CP_Napdef_AuthInfo * auth_info)
1741 {
1742         retm_if((auth_info) == NULL, "dm_cp napdef auth info is NULL!!");
1743
1744         if (auth_info->auth_entity != NULL) {
1745                 free_string_node(auth_info->auth_entity);
1746                 auth_info->auth_entity = NULL;
1747         }
1748         if (auth_info->auth_name != NULL) {
1749                 str_free(&(auth_info->auth_name));
1750                 auth_info->auth_name = NULL;
1751         }
1752         if (auth_info->auth_secret != NULL) {
1753                 str_free(&(auth_info->auth_secret));
1754                 auth_info->auth_secret = NULL;
1755         }
1756         if (auth_info->auth_type != NULL) {
1757                 str_free(&(auth_info->auth_type));
1758                 auth_info->auth_type = NULL;
1759         }
1760         if (auth_info->spi != NULL) {
1761                 str_free(&(auth_info->spi));
1762                 auth_info->spi = NULL;
1763         }
1764         if (auth_info->next != NULL) {
1765                 free_cp_napdef_authinfo(auth_info->next);
1766                 auth_info->next = NULL;
1767         }
1768
1769         free(auth_info);
1770         auth_info = NULL;
1771 }
1772
1773 void free_cp_napdef_validity(DM_CP_Napdef_validity * validity)
1774 {
1775         retm_if((validity) == NULL, "dm_cp napdef validity is NULL!!");
1776
1777         if (validity->country != NULL) {
1778                 str_free(&(validity->country));
1779                 validity->country = NULL;
1780         }
1781         if (validity->network != NULL) {
1782                 str_free(&(validity->network));
1783                 validity->network = NULL;
1784         }
1785         if (validity->sid != NULL) {
1786                 str_free(&(validity->sid));
1787                 validity->sid = NULL;
1788         }
1789         if (validity->soc != NULL) {
1790                 str_free(&(validity->soc));
1791                 validity->soc = NULL;
1792         }
1793         if (validity->validuntil != NULL) {
1794                 str_free(&(validity->validuntil));
1795                 validity->validuntil = NULL;
1796         }
1797         if (validity->next != NULL) {
1798                 free_cp_napdef_validity(validity->next);
1799                 validity->next = NULL;
1800         }
1801
1802         free(validity);
1803         validity = NULL;
1804 }
1805
1806 void free_cp_bootstrap(DM_CP_Bootstrap * bootstraps)
1807 {
1808         retm_if((bootstraps) == NULL, "dm_cp bootstraps is NULL!!");
1809
1810         if (bootstraps->context_allow != NULL) {
1811                 str_free(&(bootstraps->context_allow));
1812                 bootstraps->context_allow = NULL;
1813         }
1814         if (bootstraps->country != NULL) {
1815                 str_free(&(bootstraps->country));
1816                 bootstraps->country = NULL;
1817         }
1818         if (bootstraps->name != NULL) {
1819                 str_free(&(bootstraps->name));
1820                 bootstraps->name = NULL;
1821         }
1822         if (bootstraps->provurl != NULL) {
1823                 str_free(&(bootstraps->provurl));
1824                 bootstraps->provurl = NULL;
1825         }
1826         if (bootstraps->network != NULL) {
1827                 free_string_node(bootstraps->network);
1828                 bootstraps->network = NULL;
1829         }
1830         if (bootstraps->proxy_id != NULL) {
1831                 free_string_node(bootstraps->proxy_id);
1832                 bootstraps->proxy_id = NULL;
1833         }
1834         if (bootstraps->next != NULL) {
1835                 free_cp_bootstrap(bootstraps->next);
1836                 bootstraps->next = NULL;
1837         }
1838
1839         free(bootstraps);
1840         bootstraps = NULL;
1841 }
1842
1843 void free_cp_pxlogical(DM_CP_PxLogical * pxLogical)
1844 {
1845         retm_if((pxLogical) == NULL, "dm_cp pxlogical is NULL!!");
1846
1847         if (pxLogical->bas_auth_id != NULL) {
1848                 str_free(&(pxLogical->bas_auth_id));
1849                 pxLogical->bas_auth_id = NULL;
1850         }
1851         if (pxLogical->bas_auth_pw != NULL) {
1852                 str_free(&(pxLogical->bas_auth_pw));
1853                 pxLogical->bas_auth_pw = NULL;
1854         }
1855         if (pxLogical->domain != NULL) {
1856                 free_string_node(pxLogical->domain);
1857                 pxLogical->domain = NULL;
1858         }
1859         if (pxLogical->master != NULL) {
1860                 str_free(&(pxLogical->master));
1861                 pxLogical->master = NULL;
1862         }
1863         if (pxLogical->name != NULL) {
1864                 str_free(&(pxLogical->name));
1865                 pxLogical->name = NULL;
1866         }
1867         if (pxLogical->port != NULL) {
1868                 free_cp_port(pxLogical->port);
1869                 pxLogical->port = NULL;
1870         }
1871         if (pxLogical->ppg_auth_type != NULL) {
1872                 str_free(&(pxLogical->ppg_auth_type));
1873                 pxLogical->ppg_auth_type = NULL;
1874         }
1875         if (pxLogical->proxy_id != NULL) {
1876                 str_free(&(pxLogical->proxy_id));
1877                 pxLogical->proxy_id = NULL;
1878         }
1879         if (pxLogical->proxy_provider_id != NULL) {
1880                 str_free(&(pxLogical->proxy_provider_id));
1881                 pxLogical->proxy_provider_id = NULL;
1882         }
1883         if (pxLogical->proxy_pw != NULL) {
1884                 str_free(&(pxLogical->proxy_pw));
1885                 pxLogical->proxy_pw = NULL;
1886         }
1887         if (pxLogical->pull_enabled != NULL) {
1888                 str_free(&(pxLogical->pull_enabled));
1889                 pxLogical->pull_enabled = NULL;
1890         }
1891         if (pxLogical->pxAuthInfo != NULL) {
1892                 free_cp_pxlogical_pxauthinfo(pxLogical->pxAuthInfo);
1893                 pxLogical->pxAuthInfo = NULL;
1894         }
1895         if (pxLogical->pxPhysical != NULL) {
1896                 free_cp_pxLogical_pxphsical(pxLogical->pxPhysical);
1897                 pxLogical->pxPhysical = NULL;
1898         }
1899         if (pxLogical->start_page != NULL) {
1900                 str_free(&(pxLogical->start_page));
1901                 pxLogical->start_page = NULL;
1902         }
1903         if (pxLogical->trust != NULL) {
1904                 str_free(&(pxLogical->trust));
1905                 pxLogical->trust = NULL;
1906         }
1907         if (pxLogical->wsp_version != NULL) {
1908                 str_free(&(pxLogical->wsp_version));
1909                 pxLogical->wsp_version = NULL;
1910         }
1911         if (pxLogical->next != NULL) {
1912                 free_cp_pxlogical(pxLogical->next);
1913                 pxLogical->next = NULL;
1914         }
1915
1916         free(pxLogical);
1917         pxLogical = NULL;
1918 }
1919
1920 void free_cp_pxlogical_pxauthinfo(DM_CP_PxLogical_PxAuthInfo * pxAuthInfo)
1921 {
1922         retm_if((pxAuthInfo) == NULL, "dm_cp pxAuthInfo is NULL!!");
1923
1924         if (pxAuthInfo->pxAuth_id != NULL) {
1925                 str_free(&(pxAuthInfo->pxAuth_id));
1926                 pxAuthInfo->pxAuth_id = NULL;
1927         }
1928         if (pxAuthInfo->pxAuth_pw != NULL) {
1929                 str_free(&(pxAuthInfo->pxAuth_pw));
1930                 pxAuthInfo->pxAuth_pw = NULL;
1931         }
1932         if (pxAuthInfo->pxAuth_type != NULL) {
1933                 str_free(&(pxAuthInfo->pxAuth_type));
1934                 pxAuthInfo->pxAuth_type = NULL;
1935         }
1936         if (pxAuthInfo->next != NULL) {
1937                 free_cp_pxlogical_pxauthinfo(pxAuthInfo->next);
1938                 pxAuthInfo->next = NULL;
1939         }
1940
1941         free(pxAuthInfo);
1942         pxAuthInfo = NULL;
1943
1944 }
1945
1946 void free_cp_pxLogical_pxphsical(DM_CP_PxLogical_PxPhysical * pxPhysical)
1947 {
1948         retm_if((pxPhysical) == NULL, "dm_cp pxPhysical is NULL!!");
1949
1950         if (pxPhysical->domain != NULL) {
1951                 free_string_node(pxPhysical->domain);
1952                 pxPhysical->domain = NULL;
1953         }
1954         if (pxPhysical->physical_proxy_id != NULL) {
1955                 str_free(&(pxPhysical->physical_proxy_id));
1956                 pxPhysical->physical_proxy_id = NULL;
1957         }
1958         if (pxPhysical->port != NULL) {
1959                 free_cp_port(pxPhysical->port);
1960                 pxPhysical->port = NULL;
1961         }
1962         if (pxPhysical->pull_enabled != NULL) {
1963                 str_free(&(pxPhysical->pull_enabled));
1964                 pxPhysical->pull_enabled = NULL;
1965         }
1966         if (pxPhysical->push_enabled != NULL) {
1967                 str_free(&(pxPhysical->push_enabled));
1968                 pxPhysical->push_enabled = NULL;
1969         }
1970
1971         if (pxPhysical->pxAddr != NULL) {
1972                 str_free(&(pxPhysical->pxAddr));
1973                 pxPhysical->pxAddr = NULL;
1974         }
1975         if (pxPhysical->pxAddrType != NULL) {
1976                 str_free(&(pxPhysical->pxAddrType));
1977                 pxPhysical->pxAddrType = NULL;
1978         }
1979         if (pxPhysical->pxAddr_FQDN != NULL) {
1980                 str_free(&(pxPhysical->pxAddr_FQDN));
1981                 pxPhysical->pxAddr_FQDN = NULL;
1982         }
1983         if (pxPhysical->to_napid != NULL) {
1984                 free_string_node(pxPhysical->to_napid);
1985                 pxPhysical->to_napid = NULL;
1986         }
1987
1988         if (pxPhysical->wsp_version != NULL) {
1989                 str_free(&(pxPhysical->wsp_version));
1990                 pxPhysical->wsp_version = NULL;
1991         }
1992         if (pxPhysical->next != NULL) {
1993                 free_cp_pxLogical_pxphsical(pxPhysical->next);
1994                 pxPhysical->next = NULL;
1995         }
1996
1997         free(pxPhysical);
1998         pxPhysical = NULL;
1999
2000 }