wifi: Add support for autoscan request
[framework/connectivity/connman.git] / plugins / iwmx.h
1 /*
2  *
3  *  Connection Manager
4  *
5  *  Copyright (C) 2007-2012  Intel Corporation. All rights reserved.
6  *
7  *  This program is free software; you can redistribute it and/or modify
8  *  it under the terms of the GNU General Public License version 2 as
9  *  published by the Free Software Foundation.
10  *
11  *  This program is distributed in the hope that it will be useful,
12  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
13  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  *  GNU General Public License for more details.
15  *
16  *  You should have received a copy of the GNU General Public License
17  *  along with this program; if not, write to the Free Software
18  *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
19  *
20  */
21
22 /* Fix source compat brakage from 1.4 to 1.5...*/
23 #ifndef HAVE_WIMAX_API_DEVICE_ID
24 typedef struct WIMAX_API_DEVICE_ID WIMAX_API_DEVICE_ID;
25 #endif
26
27 #ifndef HAVE_WIMAX_API_CONNECTED_NSP_INFO
28 typedef struct WIMAX_API_CONNECTED_NSP_INFO WIMAX_API_CONNECTED_NSP_INFO;
29 #endif
30
31 #ifndef HAVE_WIMAX_API_NSP_INFO_EX
32 typedef struct WIMAX_API_NSP_INFO_EX WIMAX_API_NSP_INFO_EX;
33 #endif
34
35 #ifndef HAVE_WIMAX_API_HW_DEVICE_ID
36 typedef struct WIMAX_API_HW_DEVICE_ID WIMAX_API_HW_DEVICE_ID;
37 #endif
38
39
40 /*
41  *
42  * The plugin is broken in two main parts: the glue to connman
43  * (iwmx_cm_*() functions) and the glue to the libiWmxSdk (iwmx_sdk_*()
44  * functions). They connect using a well defined interface.
45  *
46  * The plugin is state based and operates reactively to state
47  * transtitions on the WiMAX device or to user requests, even from
48  * external control tools that are not aware of connman.
49  *
50  * When the user requests connman to do something, it goes into a call
51  * implemented by the 'struct connman_driver iwmx_cm_driver' (or
52  * iwmx_cm_network_driver) that will instruct libiWmxSDK to change the
53  * device's state.
54  *
55  * When the device changes state, a state change callback is sent back
56  * by libiWmxSDK, which gets fed to iwmx_cm_state_change(), which
57  * evaluates the state change and updates connman's internal state in
58  * response.
59  *
60  * This allows the device to be also controlled by external tools
61  * without driving connman out of state.
62  *
63  * Device's state changes can be caused through:
64  *
65  *  - connman (by user request)
66  *
67  *  - any other external utility (eg: WmxSDK's wimaxcu)
68  *
69  *  - external stimuli: network connection broken when going out of
70  *    range
71  *
72  * Functions named __*() normally indicate that require locking. See
73  * their doc header.
74  *
75  * ENUMERATION
76  *
77  * When we receive a normal probe request [iwmx_cm_probe()] from
78  * connman, we ignore it (we can tell based on the connman device
79  * having NULL data).
80  *
81  * The plugin has registered with the WiMAX Network Service and it
82  * will listen to its device add/rm messages [iwmx_sdk_addremove_cb()]
83  * and use that to create a  device [iwmx_sdk_dev_add()] which will be
84  * registered with connman. [iwmx_cm_dev_add()]. Then connman will
85  * enumerate the device, call again iwmx_cm_probe() and at this time,
86  * we'll recognize it, pass through iwmx_sdk_setup() and complete the
87  * probe process.
88  *
89  * If the daemon dies, in theory the plugin will realize and remove
90  * the WiMAX device.
91  */
92
93 struct wmxsdk {
94         WIMAX_API_DEVICE_ID device_id;
95         struct connman_device *dev;
96
97         GStaticMutex network_mutex;
98
99         WIMAX_API_DEVICE_STATUS status;
100         GMutex *status_mutex;
101
102         /*
103          * nw points to the network we are connected to. connecting_nw
104          * points to the network we have requested to connect.
105          */
106         GMutex *connect_mutex;
107         struct connman_network *connecting_nw, *nw;
108
109         char name[100];
110         char ifname[16];
111 };
112
113 /* Initialize a [zeroed] struct wmxsdk */
114 static inline void wmxsdk_init(struct wmxsdk *wmxsdk)
115 {
116         g_static_mutex_init(&wmxsdk->network_mutex);
117
118         wmxsdk->status = WIMAX_API_DEVICE_STATUS_UnInitialized;
119         wmxsdk->status_mutex = g_mutex_new();
120         g_assert(wmxsdk->status_mutex);
121
122         wmxsdk->connect_mutex = g_mutex_new();
123         g_assert(wmxsdk->connect_mutex);
124 }
125
126 /* Misc utilities */
127 #define ARRAY_SIZE(a) (sizeof(a)/sizeof(a[0]))
128 #define container_of(pointer, type, member)                             \
129 ({                                                                      \
130         type *object = NULL;                                            \
131         size_t offset = (void *) &object->member - (void *) object;     \
132         (type *) ((void *) pointer - offset);                           \
133 })
134
135 /* Misc values */
136 enum {
137         /**
138          * Time we wait for callbacks: 5s
139          *
140          * I know, it is huge, but L4 and the device sometimes take
141          * some time, especially when there is crypto involved.
142          */
143         IWMX_SDK_L4_TIMEOUT_US = 5 * 1000 * 1000,
144
145         /*
146          * WARNING!!!!!
147          *
148          * ONLY ONE DEVICE SUPPORTED
149          *
150          * - on removal, there is no way to know which device was
151          *   removed (the removed device is removed from the list and
152          *   the callback doesn't have any more information than the
153          *   index in the list that getlistdevice would return -- racy
154          *   as hell).
155          *
156          * - on insertion, there is not enough information provided.
157          */
158         IWMX_SDK_DEV_MAX = 1,
159 };
160
161 struct connman_network *__iwmx_cm_network_available(
162                         struct wmxsdk *wmxsdk, const char *station_name,
163                         const void *sdk_nspname, size_t sdk_nspname_size,
164                                                                 int strength);
165
166 struct connman_network *iwmx_cm_network_available(
167                         struct wmxsdk *wmxsdk, const char *station_name,
168                         const void *sdk_nspname, size_t sdk_nspname_size,
169                                                                 int strength);
170
171 WIMAX_API_DEVICE_STATUS iwmx_cm_status_get(struct wmxsdk *wmxsdk);
172 void __iwmx_cm_state_change(struct wmxsdk *wmxsdk,
173                                         WIMAX_API_DEVICE_STATUS __new_status);
174 void iwmx_cm_state_change(struct wmxsdk *wmxsdk,
175                                         WIMAX_API_DEVICE_STATUS __new_status);
176
177 int iwmx_sdk_connect(struct wmxsdk *wmxsdk, struct connman_network *nw);
178 int iwmx_sdk_disconnect(struct wmxsdk *wmxsdk);
179 struct connman_network *__iwmx_sdk_get_connected_network(struct wmxsdk *wmxsdk);
180 const char *iwmx_sdk_dev_status_to_str(WIMAX_API_DEVICE_STATUS status);
181 int iwmx_sdk_rf_state_set(struct wmxsdk *wmxsdk, WIMAX_API_RF_STATE rf_state);
182 WIMAX_API_DEVICE_STATUS iwmx_sdk_get_device_status(struct wmxsdk *wmxsdk);
183 int iwmx_sdk_setup(struct wmxsdk *wmxsdk);
184 void iwmx_sdk_remove(struct wmxsdk *wmxsdk);
185 int iwmx_sdk_scan(struct wmxsdk *wmxsdk);
186 int iwmx_sdk_api_init(void);
187 void iwmx_sdk_api_exit(void);