VPN_ERROR_SECURITY_RESTRICTED = TIZEN_ERROR_NETWORK_CLASS|0x0309, /**< Restricted by security system policy */
} vpn_error_e;
+/**
+* @brief Enumeration for general VPN state.
+*/
+typedef enum {
+ VPN_STATE_IDLE, /**< VPN state idle */
+ VPN_STATE_READY, /**< VPN state ready */
+ VPN_STATE_CONFIGURATION, /**< VPN state configuration */
+ VPN_STATE_DISCONNECT, /**< VPN state disconnect */
+ VPN_STATE_FAILURE, /**< VPN state failure */
+ VPN_STATE_UNKNOWN, /**< VPN state unknown */
+} vpn_state_e;
+
/**
* @}
*/
* @see vpn_disconnect()
*/
typedef void(*vpn_disconnect_cb)(vpn_error_e result, void *user_data);
+
+/**
+* @brief Called when the state of VPN is changed.
+* @param[in] handle The vpn for which state is reported;
+* the handle to the same object for which the callback was set
+* @param[in] state The vpn connection state
+* @param[in] user_data The user data passed from the callback registration function
+* @pre The callback must be registered using vpn_set_state_callback()
+* @see vpn_set_state_callback()
+*/
+typedef void(*vpn_state_cb)(const vpn_h handle, vpn_state_e state, void *user_data);
/**
* @}
*/
*/
int vpn_get_vpn_info_domain(const vpn_h handle, const char **domain);
+/**
+* @brief Registers the callback called when the state of the vpn is changed.
+* @param[in] handle The VPN handle for the Request
+* @param[in] cb The callback function to invoke
+* @param[in] user_data The user data passed from the callback registration function
+* @return 0 on success, otherwise negative error value.
+* @retval #VPN_ERROR_NONE Successful
+* @retval #VPN_ERROR_INVALID_OPERATION Invalid operation
+* @retval #VPN_ERROR_INVALID_PARAMETER Operation failed
+* @see vpn_initialize()
+* @see vpn_unset_state_callback()
+*/
+int vpn_set_state_callback(const vpn_h handle, vpn_state_cb cb, void *user_data);
+
+/**
+* @brief Unregisters the callback called when the state of the vpn is changed.
+* @param[in] handle The VPN handle for the Request
+* @return 0 on success, otherwise negative error value.
+* @retval #VPN_ERROR_NONE Successful
+* @retval #VPN_ERROR_INVALID_OPERATION Invalid operation
+* @retval #VPN_ERROR_INVALID_PARAMETER Operation failed
+* @see vpn_initialize()
+* @see vpn_set_state_callback()
+*/
+int vpn_unset_state_callback(const vpn_h handle);
/**
* @}
*/
int _vpn_get_vpn_info_type(vpn_h handle, const char **type);
int _vpn_get_vpn_info_host(vpn_h handle, const char **host);
int _vpn_get_vpn_info_domain(vpn_h handle, const char **domain);
+int _vpn_set_state_callback(const vpn_h handle, vpn_state_cb cb, void *user_data);
+int _vpn_unset_state_callback(const vpn_h handle);
#ifdef __cplusplus
}
#endif /* __cplusplus */
void *connect_user_data;
vpn_disconnect_cb disconnect_cb;
void *disconnect_user_data;
+ GHashTable *state_cb_datas;
};
static struct _vpn_cb_s vpn_callbacks = {0,};
if (rv != 0)
return false;
+ vpn_callbacks.state_cb_datas = g_hash_table_new_full(g_direct_hash,
+ g_direct_equal,
+ NULL,
+ NULL);
return true;
}
bool _vpn_deinit(void)
{
dvpnlib_vpn_deinit();
+
+ g_hash_table_remove_all(vpn_callbacks.state_cb_datas);
+
return true;
}
*domain = vpn_connection_get_domain(handle);
return VPN_ERROR_NONE;
}
+
+/*
+ *State Callbacks
+ */
+
+static void __vpn_state_cb(struct vpn_connection *connection, void *user_data)
+{
+ vpn_state_cb cb = NULL;
+ cb = (vpn_state_cb)g_hash_table_lookup(vpn_callbacks.state_cb_datas, connection);
+ if (cb)
+ cb(connection, vpn_connection_get_state(connection), user_data);
+}
+
+static void vpn_manager_state_cb(struct vpn_connection *connection, void *user_data)
+{
+ VPN_LOG(VPN_INFO, "connection: %p user_data: %p\n", connection, user_data);
+
+ __vpn_state_cb(connection, user_data);
+}
+
+/*
+ *Set state changed callback to VPN handle
+ */
+
+int _vpn_set_state_callback(const vpn_h handle, vpn_state_cb cb, void *user_data)
+{
+ enum dvpnlib_err err = DVPNLIB_ERR_NONE;
+
+ VPN_LOG(VPN_INFO, "");
+
+ GList *connections = vpn_get_connections();
+ if (NULL == g_list_find(connections, handle)) {
+ VPN_LOG(VPN_ERROR, "No Connections with the %p Handle", handle);
+ return VPN_ERROR_INVALID_PARAMETER;
+ }
+
+ g_hash_table_replace(vpn_callbacks.state_cb_datas, handle, cb);
+ err = vpn_connection_set_property_changed_cb(handle, VPN_CONN_PROP_STATE, vpn_manager_state_cb, (void *)user_data);
+ if (err != DVPNLIB_ERR_NONE)
+ return _dvpnlib_error2vpn_error(err);
+
+ return VPN_ERROR_NONE;
+}
+
+/*
+ *Unset state changed callback to VPN handle
+ */
+
+int _vpn_unset_state_callback(const vpn_h handle)
+{
+ enum dvpnlib_err err = DVPNLIB_ERR_NONE;
+
+ VPN_LOG(VPN_INFO, "");
+
+ GList *connections = vpn_get_connections();
+ if (NULL == g_list_find(connections, handle)) {
+ VPN_LOG(VPN_ERROR, "No Connections with the %p Handle", handle);
+ return VPN_ERROR_INVALID_PARAMETER;
+ }
+
+ err = vpn_connection_unset_property_changed_cb(handle, VPN_CONN_PROP_STATE);
+ if (err != DVPNLIB_ERR_NONE)
+ return _dvpnlib_error2vpn_error(err);
+
+ return VPN_ERROR_NONE;
+}
return rv;
}
+EXPORT_API
+int vpn_set_state_callback(const vpn_h handle, vpn_state_cb cb, void *user_data)
+{
+ int rv;
+
+ if (is_init == false) {
+ VPN_LOG(VPN_ERROR, "Not initialized\n");
+ return VPN_ERROR_INVALID_OPERATION;
+ }
+
+ if (handle == NULL || cb == NULL)
+ return VPN_ERROR_INVALID_PARAMETER;
+
+ rv = _vpn_set_state_callback(handle, cb, user_data);
+
+ if (rv != VPN_ERROR_NONE)
+ VPN_LOG(VPN_ERROR, "Error!! VPN Set state callback failed.\n");
+
+ return rv;
+}
+
+EXPORT_API
+int vpn_unset_state_callback(const vpn_h handle)
+{
+ int rv;
+
+ if (is_init == false) {
+ VPN_LOG(VPN_ERROR, "Not initialized\n");
+ return VPN_ERROR_INVALID_OPERATION;
+ }
+
+ if (handle == NULL)
+ return VPN_ERROR_INVALID_PARAMETER;
+
+ rv = _vpn_unset_state_callback(handle);
+
+ if (rv != VPN_ERROR_NONE)
+ VPN_LOG(VPN_ERROR, "Error!! VPN Unset state callback failed.\n");
+
+ return rv;
+}
return "UNKNOWN";
}
+
+static const char *__test_convert_state_to_string(vpn_state_e state_type)
+{
+ switch (state_type) {
+ case VPN_STATE_IDLE:
+ return "IDLE";
+ case VPN_STATE_READY:
+ return "READY";
+ case VPN_STATE_CONFIGURATION:
+ return "CONFIGURATION";
+ case VPN_STATE_DISCONNECT:
+ return "DISCONNECT";
+ case VPN_STATE_FAILURE:
+ return "FAILURE";
+ case VPN_STATE_UNKNOWN:
+ return "UNKNOWN";
+ }
+
+ return "UNKNOWN";
+}
+
#if defined(IPSEC_TEST)
typedef enum {
IPSEC_HYBRID_RSA,
__test_convert_error_to_string(result));
}
+static void __test_state_callback(vpn_h handle_ptr, vpn_state_e state, void *user_data)
+{
+ const char *name = NULL;
+ const char *type = NULL;
+ const char *host = NULL;
+ const char *domain = NULL;
+
+ printf("\n Handle = %p\n", handle_ptr);
+ vpn_get_vpn_info_name(handle_ptr, &name);
+ vpn_get_vpn_info_type(handle_ptr, &type);
+ vpn_get_vpn_info_host(handle_ptr, &host);
+ vpn_get_vpn_info_domain(handle_ptr, &domain);
+ printf(" Name[%p] - %s\n", handle_ptr, name);
+ printf(" Type[%p] - %s\n", handle_ptr, type);
+ printf(" Host[%p] - %s\n", handle_ptr, host);
+ printf(" Domain[%p] - %s\n", handle_ptr, domain);
+ printf("VPN state changed! : %s",
+ __test_convert_state_to_string(state));
+}
+
static void _test_get_vpn_handle(vpn_h *handle_ptr)
{
assert(handle_ptr != NULL);
int test_vpn_remove(void)
{
int rv = 0;
+ vpn_h handle = NULL;
- /*TODO: Get the List of VPN Profiles Identifiers
- * Prompt user to which one to be deleted */
+ _test_get_vpn_handle(&handle);
- rv = vpn_remove(NULL, __test_removed_callback, NULL);
+ rv = vpn_remove(handle, __test_removed_callback, NULL);
if (rv != VPN_ERROR_NONE) {
printf("Fail to Remove VPN Profile [%s]\n",
return 1;
}
+int test_vpn_set_state_callback(void)
+{
+ int rv = 0;
+ vpn_h handle = NULL;
+
+ _test_get_vpn_handle(&handle);
+
+ rv = vpn_set_state_callback(handle, __test_state_callback, NULL);
+
+ if (rv != VPN_ERROR_NONE) {
+ printf("Fail to Set VPN state callback [%s]\n",
+ __test_convert_error_to_string(rv));
+ return -1;
+ }
+
+ printf("Success to Set VPN state callback\n");
+
+ return 1;
+}
+
+int test_vpn_unset_state_callback(void)
+{
+ int rv = 0;
+ vpn_h handle = NULL;
+
+ _test_get_vpn_handle(&handle);
+
+ rv = vpn_unset_state_callback(handle);
+
+ if (rv != VPN_ERROR_NONE) {
+ printf("Fail to Unset VPN state callback [%s]\n",
+ __test_convert_error_to_string(rv));
+ return -1;
+ }
+
+ printf("Success to Unset VPN state callback\n");
+
+ return 1;
+}
+
int test_vpn_connect(void)
{
int rv = 0;
static int __test_deinit()
{
int rv = 0;
+ int i = 0;
+
+ for (i = 0; i < IPSEC_KVS_MAX; i++)
+ g_free(ipsec_setting_kvs[i].value)
rv = vpn_settings_deinit();
if (rv != VPN_ERROR_NONE) {
printf("e\t- VPN Test Create IPSec IKEv2 PSK - Create IPSec IKEv2 PSK\n");
printf("f\t- VPN Test Create IPSec IKEv2 RSA - Create IPSec IKEv2 RSA\n");
#endif
+ printf("g\t- VPN Set state callback - Set the VPN state callback\n");
+ printf("h\t- VPN Unset state callback - Unset the VPN state callback\n");
printf("0\t- Exit\n");
printf("ENTER - Show options menu.......\n");
rv = test_create_ipsec(data, IPSEC_IKEV2_RSA);
break;
#endif
+ case 'g':
+ rv = test_vpn_set_state_callback();
+ break;
+ case 'h':
+ rv = test_vpn_unset_state_callback();
+ break;
default:
break;
}