tizen 2.3.1 release
[framework/telephony/tel-plugin-imcmodem.git] / src / vnet.c
1 /*
2  * tel-plugin-imcmodem
3  *
4  * Copyright (c) 2012 Samsung Electronics Co., Ltd. All rights reserved.
5  *
6  * Contact: Kyoungyoup Park <gynaru.park@samsung.com>
7  *
8  * Licensed under the Apache License, Version 2.0 (the "License");
9  * you may not use this file except in compliance with the License.
10  * You may obtain a copy of the License at
11  *
12  * http://www.apache.org/licenses/LICENSE-2.0
13  *
14  * Unless required by applicable law or agreed to in writing, software
15  * distributed under the License is distributed on an "AS IS" BASIS,
16  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17  * See the License for the specific language governing permissions and
18  * limitations under the License.
19  */
20
21
22 #include <stdio.h>
23 #include <stdlib.h>
24 #include <string.h>
25 #include <fcntl.h>
26 #include <unistd.h>
27
28 #include <sys/ioctl.h>
29
30 #include <netinet/in.h>
31 #include <arpa/inet.h>
32 #include <errno.h>
33
34 #include <linux/types.h>
35 #include <sys/types.h>
36 #include <sys/socket.h>
37 #include <linux/netlink.h>
38 #include <net/if.h>
39
40 #include <glib.h>
41
42 #include <log.h>
43
44 #include "vnet.h"
45
46 #ifndef __USE_GNU
47 #define __USE_GNU
48 #endif
49 #define MODEM_IMAGE_PATH                "/opt/modem/modem.bin"
50 #define NV_DIR_PATH                             "/csa/nv"
51 #define NV_FILE_PATH                    NV_DIR_PATH"/nvdata.bin"
52
53 /*
54  * AP-CP comunication devices
55  */
56 /* To track CP bootup */
57 #define VNET_CH_PATH_BOOT0              "/dev/umts_boot0"
58
59 /* Control communication channel */
60 #define VNET_CH_PATH_IPC0               "/dev/umts_ipc0"
61
62 #define IOCTL_MODEM_STATUS              _IO('o', 0x27)
63
64 void vnet_start_cp_ramdump()
65 {
66         int ret;
67         ret = system("/usr/bin/xmm6262-boot -o u &");
68         dbg("system(/usr/bin/xmm6262-boot -o u &) ret[%d]", ret);
69 }
70
71 void vnet_start_cp_reset()
72 {
73         int ret;
74         ret = system("/usr/bin/xmm6262-boot &");
75         dbg("system(/usr/bin/xmm6262-boot &) ret[%d]", ret);
76 }
77
78 enum vnet_cp_state vnet_get_cp_state(int fd)
79 {
80         enum vnet_cp_state state = VNET_CP_STATE_UNKNOWN;
81         dbg("Entry");
82
83         /* Get CP state */
84         state = ioctl(fd, IOCTL_MODEM_STATUS);
85
86         switch (state) {
87         case VNET_CP_STATE_OFFLINE:
88                 dbg("CP State: OFFLINE");
89                 break;
90
91         case VNET_CP_STATE_CRASH_RESET:
92                 dbg("CP State: CRASH RESET");
93                 break;
94
95         case VNET_CP_STATE_CRASH_EXIT:
96                 dbg("CP State: CRASH EXIT");
97                 break;
98
99         case VNET_CP_STATE_BOOTING:
100                 dbg("CP State: BOOT");
101                 break;
102
103         case VNET_CP_STATE_ONLINE:
104                 dbg("CP State: ONLINE");
105                 break;
106
107         case VNET_CP_STATE_NV_REBUILDING:
108                 dbg("CP State: NV REBUILD");
109                 break;
110
111         case VNET_CP_STATE_LOADER_DONE:
112                 dbg("CP State: LOADER DONE");
113                 break;
114
115         case VNET_CP_STATE_UNKNOWN:
116         default:
117                 dbg("CP State: UNKNOWN State - [%d]", state);
118                 break;
119         }
120
121         return state;
122 }
123
124 int vnet_ipc0_open()
125 {
126         enum vnet_cp_state state;
127         int fd;
128         char buf[256];
129         const char * str = NULL;
130
131         dbg("Entry");
132
133         /* Opening device to track CP state */
134         fd = open(VNET_CH_PATH_BOOT0, O_RDWR);
135         if (fd < 0) {
136                 str = strerror_r(errno, buf, 256);
137                 err("Failed to Open [%s] Error: [%s]", VNET_CH_PATH_BOOT0, str);
138                 return -1;
139         }
140
141         /* Track the state of CP */
142         state = vnet_get_cp_state(fd);
143         close (fd);
144
145         dbg("CP State: [%d]", state);
146         if (state != VNET_CP_STATE_ONLINE) {
147                 err("CP is NOT yet Online!!!");
148                 return -1;
149         }
150
151         /* Opening AP-CP Control communication device */
152         fd = open(VNET_CH_PATH_IPC0, O_RDWR);
153         if (fd < 0) {
154                 str = strerror_r(errno, buf, 256);
155                 err("Failed to Open [%s] Error: [%s]", VNET_CH_PATH_IPC0, str);
156                 return -1;
157         }
158
159         return fd;
160 }