tizen 2.3 release
[kernel/api/system-resource.git] / src / network / protocol-info.c
1 /*
2  * resourced
3  *
4  * Copyright (c) 2000 - 2013 Samsung Electronics Co., Ltd. All rights reserved.
5  *
6  * Licensed under the Apache License, Version 2.0 (the "License");
7  * you may not use this file except in compliance with the License.
8  * You may obtain a copy of the License at
9  *
10  * http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing, software
13  * distributed under the License is distributed on an "AS IS" BASIS,
14  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  * See the License for the specific language governing permissions and
16  * limitations under the License.
17  *
18  */
19
20 /*
21  * @file protocol-info.c
22  *
23  * @desc Network protocol entity: now it's only for
24  * datacall network interface type
25  *
26  * Copyright (c) 2013 Samsung Electronics Co., Ltd. All rights reserved.
27  *
28  */
29
30 #include <vconf/vconf.h>
31
32 #include "macro.h"
33 #include "protocol-info.h"
34 #include "resourced.h"
35 #include "trace.h"
36
37 static resourced_hw_net_protocol_type datacall_prot_t = RESOURCED_PROTOCOL_NONE;
38
39 static resourced_hw_net_protocol_type _convert_to_resourced_protocol(
40         const int prot_type)
41 {
42         switch (prot_type) {
43         case VCONFKEY_TELEPHONY_SVCTYPE_NOSVC:
44                 return RESOURCED_PROTOCOL_DATACALL_NOSVC;
45         case VCONFKEY_TELEPHONY_SVCTYPE_EMERGENCY:
46                 return RESOURCED_PROTOCOL_DATACALL_EMERGENCY;
47         case VCONFKEY_TELEPHONY_SVCTYPE_SEARCH:
48                 return RESOURCED_PROTOCOL_DATACALL_SEARCH;
49         case VCONFKEY_TELEPHONY_SVCTYPE_2G:
50                 return RESOURCED_PROTOCOL_DATACALL_2G;
51         case VCONFKEY_TELEPHONY_SVCTYPE_2_5G:
52                 return RESOURCED_PROTOCOL_DATACALL_2_5G;
53         case VCONFKEY_TELEPHONY_SVCTYPE_2_5G_EDGE:
54                 return RESOURCED_PROTOCOL_DATACALL_2_5G_EDGE;
55         case VCONFKEY_TELEPHONY_SVCTYPE_3G:
56                 return RESOURCED_PROTOCOL_DATACALL_3G;
57         case VCONFKEY_TELEPHONY_SVCTYPE_HSDPA:
58                 return RESOURCED_PROTOCOL_DATACALL_HSDPA;
59         case VCONFKEY_TELEPHONY_SVCTYPE_LTE:
60                 return RESOURCED_PROTOCOL_DATACALL_LTE;
61         case VCONFKEY_TELEPHONY_SVCTYPE_NONE:
62         default:
63                 return RESOURCED_PROTOCOL_NONE;
64         }
65 }
66
67 static resourced_ret_c _get_protocol_type(
68         resourced_hw_net_protocol_type *prot_type)
69 {
70         int ret, status;
71
72         ret = vconf_get_int(VCONFKEY_TELEPHONY_SVCTYPE, &status);
73         ret_value_msg_if(ret != 0, RESOURCED_ERROR_FAIL,
74                          "vconf get failed(VCONFKEY_TELEPHONY_SVCTYPE)\n");
75         *prot_type = _convert_to_resourced_protocol(status);
76         return RESOURCED_ERROR_NONE;
77 }
78
79 static void _datacall_protocol_type_change_cb(keynode_t *key, void *data)
80 {
81         int val = vconf_keynode_get_int(key);
82
83         _D("key = %s, value = %d(int)\n", vconf_keynode_get_name(key), val);
84         datacall_prot_t = _convert_to_resourced_protocol(val);
85 }
86
87 void init_hw_net_protocol_type(void)
88 {
89         vconf_notify_key_changed(VCONFKEY_TELEPHONY_SVCTYPE,
90                                  _datacall_protocol_type_change_cb, NULL);
91         if (_get_protocol_type(&datacall_prot_t) != RESOURCED_ERROR_NONE)
92                 _E("_get_protocol_type failed\n");
93 }
94
95 void finalize_hw_net_protocol_type(void)
96 {
97         vconf_ignore_key_changed(VCONFKEY_TELEPHONY_SVCTYPE,
98                                  _datacall_protocol_type_change_cb);
99         datacall_prot_t = RESOURCED_PROTOCOL_NONE;
100 }
101
102 resourced_hw_net_protocol_type get_hw_net_protocol_type(
103         const resourced_iface_type iftype)
104 {
105         if (iftype == RESOURCED_IFACE_DATACALL)
106                 return datacall_prot_t;
107
108         return RESOURCED_PROTOCOL_NONE;
109 }