64d5be767b9f75941e636fc8aa9970ad64a4c00d
[platform/core/connectivity/nfc-manager-neard.git] / client / net_nfc_client.c
1 /*
2  * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd.
3  *
4  * Licensed under the Flora License, Version 1.1 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *     http://floralicense.org/license/
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16
17 #include <glib.h>
18
19 #ifdef SECURITY_SERVER
20 #include "security-server.h"
21 #endif
22
23 #include "net_nfc_typedef.h"
24 #include "net_nfc_util_gdbus_internal.h"
25 #include "net_nfc_client_se.h"
26 #include "net_nfc_client.h"
27 #include "net_nfc_client_manager.h"
28 #include "net_nfc_client_tag.h"
29 #include "net_nfc_client_ndef.h"
30 #include "net_nfc_client_transceive.h"
31 #include "net_nfc_client_llcp.h"
32 #include "net_nfc_client_snep.h"
33 #include "net_nfc_client_p2p.h"
34 #include "net_nfc_client_system_handler.h"
35 #include "net_nfc_client_handover.h"
36
37 #ifdef SECURITY_SERVER
38 static uint8_t *cookie;
39 static size_t cookie_len;
40
41 static void _init_smack()
42 {
43         if (cookie == NULL) {
44                 cookie_len = security_server_get_cookie_size();
45                 if (cookie_len > 0) {
46                         cookie = g_new0(uint8_t, cookie_len);
47                         if (cookie != NULL) {
48                                 if (security_server_request_cookie((char*)cookie, cookie_len) < 0) {
49                                         g_free(cookie);
50                                         cookie = NULL;
51                                 }
52                         }
53                 }
54         }
55 }
56
57 static void _deinit_smack()
58 {
59         if (cookie != NULL) {
60                 g_free(cookie);
61                 cookie = NULL;
62         }
63 }
64 #endif
65
66 GVariant *net_nfc_client_gdbus_get_privilege()
67 {
68 #ifdef SECURITY_SERVER
69         return net_nfc_util_gdbus_buffer_to_variant(cookie, cookie_len);
70 #else
71         return net_nfc_util_gdbus_buffer_to_variant(NULL, 0);
72 #endif
73 }
74
75 void net_nfc_client_gdbus_init(void)
76 {
77 #ifdef SECURITY_SERVER
78         _init_smack();
79 #endif
80         if (net_nfc_client_manager_init() != NET_NFC_OK)
81                 return;
82         if (net_nfc_client_tag_init() != NET_NFC_OK)
83                 return;
84         if (net_nfc_client_ndef_init() != NET_NFC_OK)
85                 return;
86         if (net_nfc_client_transceive_init() != NET_NFC_OK)
87                 return;
88         if (net_nfc_client_llcp_init() != NET_NFC_OK)
89                 return;
90         if (net_nfc_client_snep_init() != NET_NFC_OK)
91                 return;
92         if (net_nfc_client_p2p_init() != NET_NFC_OK)
93                 return;
94         if (net_nfc_client_sys_handler_init() != NET_NFC_OK)
95                 return;
96         if (net_nfc_client_se_init() != NET_NFC_OK)
97                 return;
98         if(net_nfc_client_handover_init() != NET_NFC_OK)
99                 return;
100 }
101
102 void net_nfc_client_gdbus_deinit(void)
103 {
104         net_nfc_client_handover_deinit();
105         net_nfc_client_se_deinit();
106         net_nfc_client_sys_handler_deinit();
107         net_nfc_client_p2p_deinit();
108         net_nfc_client_snep_deinit();
109         net_nfc_client_llcp_deinit();
110         net_nfc_client_transceive_deinit();
111         net_nfc_client_ndef_deinit();
112         net_nfc_client_tag_deinit();
113         net_nfc_client_manager_deinit();
114 #ifdef SECURITY_SERVER
115         _deinit_smack();
116 #endif
117 }