static void llcp_error(NetNfcGDbusLlcp *object,
guint arg_handle,
guint client_socket,
- guint oal_socket,
gint error,
gpointer user_data);
+static void llcp_incoming(NetNfcGDbusLlcp *object,
+ guint arg_handle,
+ guint client_socket,
+ guint incoming_socket,
+ gpointer user_data);
void llcp_socket_data_append(net_nfc_llcp_internal_socket_s *socket_data)
{
GAsyncResult *res,
gpointer user_data)
{
- LlcpFuncData *func_data;
-
- net_nfc_error_e result = NET_NFC_OK;
+ LlcpFuncData *func_data = user_data;
+ net_nfc_error_e result;
GError *error = NULL;
- net_nfc_client_llcp_config_completed callback;
+ g_assert(func_data != NULL);
if (net_nfc_gdbus_llcp_call_config_finish(
NET_NFC_GDBUS_LLCP(source_object),
+ &result,
res,
&error) == FALSE)
{
- result = NET_NFC_UNKNOWN_ERROR;
-
DEBUG_ERR_MSG("Can not finish config: %s",
error->message);
+
g_error_free(error);
- }
- func_data = user_data;
- if (func_data == NULL)
- {
- DEBUG_ERR_MSG("can not get LlcpFuncData");
- return;
+ result = NET_NFC_IPC_FAIL;
}
- if (func_data->callback == NULL)
+ if (func_data->callback != NULL)
{
- DEBUG_CLIENT_MSG("callback function is not available");
- g_free(func_data);
- return;
+ net_nfc_client_llcp_config_completed callback =
+ (net_nfc_client_llcp_config_completed)func_data->callback;
+
+ callback(result, func_data->user_data);
}
- callback = (net_nfc_client_llcp_config_completed)func_data->callback;
- callback(result, func_data->user_data);
+ g_free(func_data);
}
static void llcp_call_listen(GObject *source_object,
GAsyncResult *res,
gpointer user_data)
{
- LlcpFuncData *func_data;
-
- net_nfc_error_e result = NET_NFC_OK;
+ LlcpFuncData *func_data = user_data;
+ net_nfc_error_e result;
+ guint32 out_client_socket;
GError *error = NULL;
- guint32 out_client_socket;
guint32 out_oal_socket;
net_nfc_llcp_internal_socket_s *socket_data = NULL;
- net_nfc_client_llcp_listen_completed callback;
+ g_assert(func_data != NULL);
if (net_nfc_gdbus_llcp_call_listen_finish(
NET_NFC_GDBUS_LLCP(source_object),
+ &result,
&out_client_socket,
- &out_oal_socket,
res,
&error) == FALSE)
{
- result = NET_NFC_UNKNOWN_ERROR;
-
DEBUG_ERR_MSG("Can not finish listen: %s",
error->message);
+
g_error_free(error);
+
+ result = NET_NFC_IPC_FAIL;
}
socket_data = llcp_socket_data_find(out_client_socket);
socket_data->oal_socket = out_oal_socket;
- func_data = user_data;
- if (func_data == NULL)
+ if (func_data->callback != NULL)
{
- DEBUG_ERR_MSG("can not get LlcpFuncData");
- return;
+ net_nfc_client_llcp_listen_completed callback =
+ (net_nfc_client_llcp_listen_completed)func_data->callback;
+
+ callback(result, out_client_socket, func_data->user_data);
}
- if (func_data->callback == NULL)
+ /* TODO : release resource when socket is closed */
+ // g_free(func_data);
+}
+
+static void llcp_call_accept(GObject *source_object,
+ GAsyncResult *res,
+ gpointer user_data)
+{
+ LlcpFuncData *func_data = user_data;
+ net_nfc_error_e result;
+ GError *error = NULL;
+
+ g_assert(func_data != NULL);
+
+ if (net_nfc_gdbus_llcp_call_accept_finish(
+ NET_NFC_GDBUS_LLCP(source_object),
+ &result,
+ res,
+ &error) == FALSE)
{
- DEBUG_CLIENT_MSG("callback function is not available");
- g_free(func_data);
- return;
+ DEBUG_ERR_MSG("Can not finish accept: %s",
+ error->message);
+
+ g_error_free(error);
+
+ result = NET_NFC_IPC_FAIL;
}
- callback = (net_nfc_client_llcp_listen_completed)func_data->callback;
- callback(result, out_client_socket, func_data->user_data);
+ if (func_data->callback != NULL)
+ {
+ net_nfc_client_llcp_accept_completed callback =
+ (net_nfc_client_llcp_accept_completed)func_data->callback;
+
+ callback(result, func_data->user_data);
+ }
+
+ g_free(func_data);
}
-static void llcp_call_connect(GObject *source_object,
+static void llcp_call_reject(GObject *source_object,
GAsyncResult *res,
gpointer user_data)
{
- LlcpFuncData *func_data;
-
- net_nfc_error_e result = NET_NFC_OK;
+ LlcpFuncData *func_data = user_data;
+ net_nfc_error_e result;
GError *error = NULL;
+ g_assert(func_data != NULL);
+
+ if (net_nfc_gdbus_llcp_call_reject_finish(
+ NET_NFC_GDBUS_LLCP(source_object),
+ &result,
+ res,
+ &error) == FALSE)
+ {
+ DEBUG_ERR_MSG("Can not finish reject: %s",
+ error->message);
+
+ g_error_free(error);
+
+ result = NET_NFC_IPC_FAIL;
+ }
+
+ if (func_data->callback != NULL)
+ {
+ net_nfc_client_llcp_reject_completed callback =
+ (net_nfc_client_llcp_reject_completed)func_data->callback;
+
+ callback(result, func_data->user_data);
+ }
+
+ g_free(func_data);
+}
+
+static void llcp_call_connect(GObject *source_object,
+ GAsyncResult *res,
+ gpointer user_data)
+{
+ LlcpFuncData *func_data = user_data;
+ net_nfc_error_e result;
guint32 out_client_socket;
+ GError *error = NULL;
+
guint32 out_oal_socket;
net_nfc_llcp_internal_socket_s *socket_data = NULL;
- net_nfc_client_llcp_connect_completed callback;
+ g_assert(func_data != NULL);
if (net_nfc_gdbus_llcp_call_connect_finish(
NET_NFC_GDBUS_LLCP(source_object),
+ &result,
&out_client_socket,
- &out_oal_socket,
res,
&error) == FALSE)
{
- result = NET_NFC_UNKNOWN_ERROR;
+ DEBUG_ERR_MSG("Can not finish connect: %s", error->message);
- DEBUG_ERR_MSG("Can not finish connect: %s",
- error->message);
g_error_free(error);
+
+ result = NET_NFC_IPC_FAIL;
}
socket_data = llcp_socket_data_find(out_client_socket);
socket_data->oal_socket = out_oal_socket;
- func_data = user_data;
- if (func_data == NULL)
+ if (func_data->callback != NULL)
{
- DEBUG_ERR_MSG("can not get LlcpFuncData");
- return;
- }
+ net_nfc_client_llcp_connect_completed callback =
+ (net_nfc_client_llcp_connect_completed)func_data->callback;
- if (func_data->callback == NULL)
- {
- DEBUG_CLIENT_MSG("callback function is not available");
- g_free(func_data);
- return;
+ callback(result, out_client_socket, func_data->user_data);
}
- callback = (net_nfc_client_llcp_connect_completed)func_data->callback;
- callback(result, out_client_socket, func_data->user_data);
+ /* TODO : release resource when socket is closed */
+ // g_free(func_data);
}
static void llcp_call_connect_sap(GObject *source_object,
GAsyncResult *res,
gpointer user_data)
{
- LlcpFuncData *func_data;
-
- net_nfc_error_e result = NET_NFC_OK;
+ LlcpFuncData *func_data = user_data;
+ net_nfc_error_e result;
+ guint32 out_client_socket;
GError *error = NULL;
- guint32 out_client_socket;
guint32 out_oal_socket;
net_nfc_llcp_internal_socket_s *socket_data = NULL;
- net_nfc_client_llcp_connect_sap_completed callback;
+ g_assert(func_data != NULL);
if (net_nfc_gdbus_llcp_call_connect_sap_finish(
NET_NFC_GDBUS_LLCP(source_object),
+ &result,
&out_client_socket,
- &out_oal_socket,
res,
&error) == FALSE)
{
- result = NET_NFC_UNKNOWN_ERROR;
-
- DEBUG_ERR_MSG("Can not finish connect sap: %s",
- error->message);
+ DEBUG_ERR_MSG("Can not finish connect sap: %s", error->message);
g_error_free(error);
+
+ result = NET_NFC_IPC_FAIL;
}
socket_data = llcp_socket_data_find(out_client_socket);
socket_data->oal_socket = out_oal_socket;
- func_data = user_data;
- if (func_data == NULL)
+ if (func_data->callback != NULL)
{
- DEBUG_ERR_MSG("can not get LlcpFuncData");
- return;
- }
+ net_nfc_client_llcp_connect_sap_completed callback =
+ (net_nfc_client_llcp_connect_sap_completed)func_data->callback;
- if (func_data->callback == NULL)
- {
- DEBUG_CLIENT_MSG("callback function is not available");
- g_free(func_data);
- return;
+ callback(result, out_client_socket, func_data->user_data);
}
- callback = (net_nfc_client_llcp_connect_sap_completed)
- func_data->callback;
- callback(result, out_client_socket, func_data->user_data);
+ /* TODO : release resource when socket is closed */
+ // g_free(func_data);
}
-
static void llcp_call_send(GObject *source_object,
GAsyncResult *res,
gpointer user_data)
{
- LlcpFuncData *func_data;
-
+ LlcpFuncData *func_data = user_data;
+ net_nfc_error_e result;
guint32 out_client_socket;
-
- net_nfc_error_e result = NET_NFC_OK;
GError *error = NULL;
- net_nfc_client_llcp_send_completed callback;
+ g_assert(func_data != NULL);
if (net_nfc_gdbus_llcp_call_send_finish(
NET_NFC_GDBUS_LLCP(source_object),
+ &result,
&out_client_socket,
res,
&error) == FALSE)
{
- result = NET_NFC_UNKNOWN_ERROR;
-
DEBUG_ERR_MSG("Can not finish send: %s",
error->message);
g_error_free(error);
- }
- func_data = user_data;
- if (func_data == NULL)
- {
- DEBUG_ERR_MSG("can not get LlcpFuncData");
- return;
+ result = NET_NFC_IPC_FAIL;
}
- if (func_data->callback == NULL)
+ if (func_data->callback != NULL)
{
- DEBUG_CLIENT_MSG("callback function is not available");
- g_free(func_data);
- return;
+ net_nfc_client_llcp_send_completed callback =
+ (net_nfc_client_llcp_send_completed)func_data->callback;
+
+ callback(result, func_data->user_data);
}
- callback = (net_nfc_client_llcp_send_completed)func_data->callback;
- callback(result, out_client_socket, func_data->user_data);
+ g_free(func_data);
}
static void llcp_call_send_to(GObject *source_object,
GAsyncResult *res,
gpointer user_data)
{
- LlcpFuncData *func_data;
-
+ LlcpFuncData *func_data = user_data;
+ net_nfc_error_e result;
guint32 out_client_socket;
-
- net_nfc_error_e result = NET_NFC_OK;
GError *error = NULL;
- net_nfc_client_llcp_send_to_completed callback;
+ g_assert(func_data != NULL);
if (net_nfc_gdbus_llcp_call_send_to_finish(
NET_NFC_GDBUS_LLCP(source_object),
+ &result,
&out_client_socket,
res,
&error) == FALSE)
{
- result = NET_NFC_UNKNOWN_ERROR;
-
- DEBUG_ERR_MSG("Can not finish send to: %s",
- error->message);
+ DEBUG_ERR_MSG("Can not finish send to: %s", error->message);
g_error_free(error);
- }
- func_data = user_data;
- if (func_data == NULL)
- {
- DEBUG_ERR_MSG("can not get LlcpFuncData");
- return;
+
+ result = NET_NFC_IPC_FAIL;
}
- if (func_data->callback == NULL)
+ if (func_data->callback != NULL)
{
- DEBUG_CLIENT_MSG("callback function is not available");
- g_free(func_data);
- return;
+ net_nfc_client_llcp_send_to_completed callback =
+ (net_nfc_client_llcp_send_to_completed)func_data->callback;
+
+ callback(result, func_data->user_data);
}
- callback = (net_nfc_client_llcp_send_to_completed)func_data->callback;
- callback(result, out_client_socket, func_data->user_data);
+ g_free(func_data);
}
static void llcp_call_receive(GObject *source_object,
GAsyncResult *res,
gpointer user_data)
{
- LlcpFuncData *func_data;
-
- GVariant *variant = NULL;
- data_s data;
-
- net_nfc_error_e result = NET_NFC_OK;
+ LlcpFuncData *func_data = user_data;
+ net_nfc_error_e result;
+ GVariant *variant;
GError *error = NULL;
- net_nfc_client_llcp_receive_completed callback;
+ g_assert(func_data != NULL);
if (net_nfc_gdbus_llcp_call_receive_finish(
NET_NFC_GDBUS_LLCP(source_object),
+ &result,
&variant,
res,
&error) == FALSE)
{
- result = NET_NFC_UNKNOWN_ERROR;
-
- DEBUG_ERR_MSG("Can not finish receive: %s",
- error->message);
+ DEBUG_ERR_MSG("Can not finish receive: %s", error->message);
g_error_free(error);
- }
- func_data = user_data;
- if (func_data == NULL)
- {
- DEBUG_ERR_MSG("can not get LlcpFuncData");
- return;
+ result = NET_NFC_IPC_FAIL;
}
- if (func_data->callback == NULL)
+ if (func_data->callback != NULL)
{
- DEBUG_CLIENT_MSG("callback function is not available");
- g_free(func_data);
- return;
- }
+ net_nfc_client_llcp_receive_completed callback =
+ (net_nfc_client_llcp_receive_completed)func_data->callback;
+ data_s data = { NULL, 0 };
- net_nfc_util_gdbus_variant_to_data_s(variant, &data);
+ net_nfc_util_gdbus_variant_to_data_s(variant, &data);
- callback = (net_nfc_client_llcp_receive_completed)func_data->callback;
- callback(result, &data, func_data->user_data);
+ callback(result, &data, func_data->user_data);
- net_nfc_util_free_data(&data);
+ net_nfc_util_free_data(&data);
+ }
g_free(func_data);
}
GAsyncResult *res,
gpointer user_data)
{
- LlcpFuncData *func_data;
-
- GVariant *variant = NULL;
-
+ LlcpFuncData *func_data = user_data;
+ net_nfc_error_e result;
sap_t sap;
- data_s data;
-
- net_nfc_error_e result = NET_NFC_OK;
+ GVariant *variant;
GError *error = NULL;
- net_nfc_client_llcp_receive_from_completed callback;
+ g_assert(func_data != NULL);
if (net_nfc_gdbus_llcp_call_receive_from_finish(
NET_NFC_GDBUS_LLCP(source_object),
+ &result,
&sap,
&variant,
res,
&error) == FALSE)
{
- result = NET_NFC_UNKNOWN_ERROR;
-
DEBUG_ERR_MSG("Can not finish receive from: %s",
error->message);
g_error_free(error);
- }
- func_data = user_data;
- if (func_data == NULL)
- {
- DEBUG_ERR_MSG("can not get LlcpFuncData");
- return;
+ result = NET_NFC_IPC_FAIL;
}
- if (func_data->callback == NULL)
+ if (func_data->callback != NULL)
{
- DEBUG_CLIENT_MSG("callback function is not available");
- g_free(func_data);
- return;
- }
+ net_nfc_client_llcp_receive_from_completed callback =
+ (net_nfc_client_llcp_receive_from_completed)func_data->callback;
+ data_s data = { NULL, 0 };
- net_nfc_util_gdbus_variant_to_data_s(variant, &data);
+ net_nfc_util_gdbus_variant_to_data_s(variant, &data);
- callback = (net_nfc_client_llcp_receive_from_completed)
- func_data->callback;
- callback(result, sap, &data, func_data->user_data);
+ callback(result, sap, &data, func_data->user_data);
- net_nfc_util_free_data(&data);
+ net_nfc_util_free_data(&data);
+ }
g_free(func_data);
}
GAsyncResult *res,
gpointer user_data)
{
- LlcpFuncData *func_data;
-
- net_nfc_error_e result = NET_NFC_OK;
- GError *error = NULL;
-
+ LlcpFuncData *func_data = user_data;
+ net_nfc_error_e result;
guint32 out_client_socket;
+ GError *error = NULL;
net_nfc_llcp_internal_socket_s *socket_data = NULL;
- net_nfc_client_llcp_close_completed callback;
+ g_assert(func_data != NULL);
if (net_nfc_gdbus_llcp_call_close_finish(
NET_NFC_GDBUS_LLCP(source_object),
+ &result,
&out_client_socket,
res,
&error) == FALSE)
{
- result = NET_NFC_UNKNOWN_ERROR;
+ DEBUG_ERR_MSG("Can not finish close: %s", error->message);
- DEBUG_ERR_MSG("Can not finish close: %s",
- error->message);
g_error_free(error);
+
+ result = NET_NFC_IPC_FAIL;
}
socket_data = llcp_socket_data_find(out_client_socket);
return;
}
- func_data = user_data;
- if (func_data == NULL)
+ if (func_data->callback != NULL)
{
- DEBUG_ERR_MSG("can not get LlcpFuncData");
- return;
- }
+ net_nfc_client_llcp_close_completed callback =
+ (net_nfc_client_llcp_close_completed)func_data->callback;
- if (func_data->callback == NULL)
- {
- DEBUG_CLIENT_MSG("callback function is not available");
- g_free(func_data);
- return;
+ callback(result, func_data->user_data);
}
- callback = (net_nfc_client_llcp_close_completed)func_data->callback;
- callback(result, out_client_socket, func_data->user_data);
+ g_free(func_data);
}
static void llcp_call_disconnect(GObject *source_object,
GAsyncResult *res,
gpointer user_data)
{
- LlcpFuncData *func_data;
-
- net_nfc_error_e result = NET_NFC_OK;
- GError *error = NULL;
-
+ LlcpFuncData *func_data = user_data;
+ net_nfc_error_e result;
guint32 out_client_socket;
+ GError *error = NULL;
net_nfc_llcp_internal_socket_s *socket_data = NULL;
- net_nfc_client_llcp_disconnect_completed callback;
+ g_assert(func_data != NULL);
if (net_nfc_gdbus_llcp_call_disconnect_finish(
NET_NFC_GDBUS_LLCP(source_object),
+ &result,
&out_client_socket,
res,
&error) == FALSE)
{
- result = NET_NFC_UNKNOWN_ERROR;
+ DEBUG_ERR_MSG("Can not finish disconnect: %s", error->message);
- DEBUG_ERR_MSG("Can not finish disconnect: %s",
- error->message);
g_error_free(error);
+
+ result = NET_NFC_IPC_FAIL;
}
socket_data = llcp_socket_data_find(out_client_socket);
return;
}
- func_data = user_data;
- if (func_data == NULL)
- {
- DEBUG_ERR_MSG("can not get LlcpFuncData");
- return;
- }
+ if (func_data->callback != NULL) {
+ net_nfc_client_llcp_disconnect_completed callback =
+ (net_nfc_client_llcp_disconnect_completed)func_data->callback;
- if (func_data->callback == NULL)
- {
- DEBUG_CLIENT_MSG("callback function is not available");
- g_free(func_data);
- return;
+ callback(result, func_data->user_data);
}
- callback = (net_nfc_client_llcp_disconnect_completed)
- func_data->callback;
- callback(result, out_client_socket, func_data->user_data);
+ g_free(func_data);
}
-
static void llcp_error(NetNfcGDbusLlcp *object,
guint arg_handle,
guint client_socket,
- guint oal_socket,
gint error,
gpointer user_data)
{
INFO_MSG(">>> SIGNAL arrived");
}
+static void llcp_incoming(NetNfcGDbusLlcp *object,
+ guint arg_handle,
+ guint client_socket,
+ guint incoming_socket,
+ gpointer user_data)
+{
+ INFO_MSG(">>> SIGNAL arrived");
+}
+
/* Public APIs */
API net_nfc_error_e net_nfc_client_llcp_config(net_nfc_llcp_config_info_h config,
net_nfc_client_llcp_config_completed callback,
void *user_data)
{
LlcpFuncData *func_data;
- GVariant *variant = NULL;
+ GVariant *variant;
+
+ if (config == NULL) {
+ return NET_NFC_NULL_PARAMETER;
+ }
if (llcp_proxy == NULL)
{
DEBUG_ERR_MSG("Can not get LlcpProxy");
- return NET_NFC_UNKNOWN_ERROR;
- }
- if (config == NULL)
- {
- DEBUG_ERR_MSG("Config is empty");
- return NET_NFC_UNKNOWN_ERROR;
+ return NET_NFC_NOT_INITIALIZED;
}
/* prevent executing daemon when nfc is off */
}
func_data = g_new0(LlcpFuncData, 1);
+ if (func_data == NULL) {
+ DEBUG_ERR_MSG("g_new0 failed");
+
+ return NET_NFC_ALLOC_FAIL;
+ }
+
func_data->callback = (gpointer)callback;
func_data->user_data = user_data;
API net_nfc_error_e net_nfc_client_llcp_config_sync(
net_nfc_llcp_config_info_h config)
{
+ net_nfc_error_e result;
GVariant *variant = NULL;
GError *error = NULL;
if (llcp_proxy == NULL)
{
DEBUG_ERR_MSG("Can not get LlcpProxy");
- return NET_NFC_UNKNOWN_ERROR;
+
+ return NET_NFC_NOT_INITIALIZED;
}
/* prevent executing daemon when nfc is off */
if (net_nfc_gdbus_llcp_call_config_sync(llcp_proxy,
variant,
net_nfc_client_gdbus_get_privilege(),
+ &result,
NULL,
&error) == FALSE)
{
DEBUG_ERR_MSG("can not config: %s", error->message);
+
g_error_free(error);
- return NET_NFC_UNKNOWN_ERROR;
+
+ result = NET_NFC_IPC_FAIL;
}
- return NET_NFC_OK;
+ return result;
}
API net_nfc_error_e net_nfc_client_llcp_get_config(
if (llcp_proxy == NULL)
{
DEBUG_ERR_MSG("Can not get LlcpProxy");
- return NET_NFC_UNKNOWN_ERROR;
- }
- if (service_name == NULL)
- {
- DEBUG_ERR_MSG("service_name is empty");
- return NET_NFC_UNKNOWN_ERROR;
+ return NET_NFC_NOT_INITIALIZED;
}
socket_data = llcp_socket_data_find(socket);
}
func_data = g_new0(LlcpFuncData, 1);
+ if (func_data == NULL) {
+ DEBUG_ERR_MSG("g_new0 failed");
+
+ return NET_NFC_ALLOC_FAIL;
+ }
+
func_data->callback = (gpointer)callback;
func_data->user_data = user_data;
net_nfc_gdbus_llcp_call_listen(llcp_proxy,
GPOINTER_TO_UINT(llcp_handle),
socket_data->client_socket,
- socket_data->oal_socket,
socket_data->miu,
socket_data->rw,
socket_data->type,
sap_t sap,
net_nfc_llcp_socket_t *out_socket)
{
+ net_nfc_error_e result;
GError *error = NULL;
guint32 out_client_socket;
- guint32 out_oal_socket;
net_nfc_llcp_internal_socket_s *socket_data = NULL;
net_nfc_llcp_internal_socket_s *out_socket_data = NULL;
+ if (out_socket == NULL) {
+ return NET_NFC_NULL_PARAMETER;
+ }
+
if (llcp_proxy == NULL)
{
DEBUG_ERR_MSG("Can not get LlcpProxy");
- return NET_NFC_UNKNOWN_ERROR;
+
+ return NET_NFC_NOT_INITIALIZED;
}
if (service_name == NULL)
if (net_nfc_gdbus_llcp_call_listen_sync(llcp_proxy,
GPOINTER_TO_UINT(llcp_handle),
socket_data->client_socket,
- socket_data->oal_socket,
socket_data->miu,
socket_data->rw,
socket_data->type,
socket_data->sap,
service_name,
net_nfc_client_gdbus_get_privilege(),
+ &result,
&out_client_socket,
- &out_oal_socket,
NULL,
- &error) == FALSE)
+ &error) == true) {
+ out_socket_data = llcp_socket_data_find(out_client_socket);
+ if (out_socket_data == NULL || out_socket_data != socket_data)
+ {
+ DEBUG_ERR_MSG("Wrong client socket is returned");
+ return NET_NFC_UNKNOWN_ERROR;
+ }
+
+ // out_socket_data->oal_socket = out_oal_socket;
+
+ if (out_socket)
+ *out_socket = out_client_socket;
+ } else {
+ DEBUG_ERR_MSG("can not listen: %s", error->message);
+
+ g_error_free(error);
+
+ result = NET_NFC_IPC_FAIL;
+ }
+
+ return result;
+}
+
+API net_nfc_error_e net_nfc_client_llcp_accept(net_nfc_llcp_socket_t socket,
+ net_nfc_client_llcp_accept_completed callback, void *user_data)
+{
+ LlcpFuncData *func_data;
+
+ if (llcp_proxy == NULL)
{
- DEBUG_ERR_MSG("can not listen: %s",
- error->message);
+ DEBUG_ERR_MSG("Can not get LlcpProxy");
+
+ return NET_NFC_NOT_INITIALIZED;
+ }
+
+ /* prevent executing daemon when nfc is off */
+ if (net_nfc_client_manager_is_activated() == false) {
+ return NET_NFC_INVALID_STATE;
+ }
+
+ func_data = g_new0(LlcpFuncData, 1);
+ if (func_data == NULL) {
+ DEBUG_ERR_MSG("g_new0 failed");
+
+ return NET_NFC_ALLOC_FAIL;
+ }
+
+ func_data->callback = (gpointer)callback;
+ func_data->user_data = user_data;
+
+ net_nfc_gdbus_llcp_call_accept(llcp_proxy,
+ GPOINTER_TO_UINT(llcp_handle),
+ socket,
+ net_nfc_client_gdbus_get_privilege(),
+ NULL,
+ llcp_call_accept,
+ func_data);
+
+ return NET_NFC_OK;
+}
+
+API net_nfc_error_e net_nfc_client_llcp_accept_sync(net_nfc_llcp_socket_t socket)
+{
+ net_nfc_error_e result;
+ GError *error = NULL;
+
+ if (llcp_proxy == NULL)
+ {
+ DEBUG_ERR_MSG("Can not get LlcpProxy");
+
+ return NET_NFC_NOT_INITIALIZED;
+ }
+
+ /* prevent executing daemon when nfc is off */
+ if (net_nfc_client_manager_is_activated() == false) {
+ return NET_NFC_INVALID_STATE;
+ }
+
+ if (net_nfc_gdbus_llcp_call_accept_sync(llcp_proxy,
+ GPOINTER_TO_UINT(llcp_handle),
+ socket,
+ net_nfc_client_gdbus_get_privilege(),
+ &result,
+ NULL,
+ &error) == false) {
+ DEBUG_ERR_MSG("can not connect: %s", error->message);
+
g_error_free(error);
- return NET_NFC_UNKNOWN_ERROR;
+
+ result = NET_NFC_IPC_FAIL;
}
- out_socket_data = llcp_socket_data_find(out_client_socket);
- if (out_socket_data == NULL || out_socket_data != socket_data)
+ return result;
+}
+
+API net_nfc_error_e net_nfc_client_llcp_reject(net_nfc_llcp_socket_t socket,
+ net_nfc_client_llcp_reject_completed callback,
+ void *user_data)
+{
+ LlcpFuncData *func_data;
+
+ if (llcp_proxy == NULL)
{
- DEBUG_ERR_MSG("Wrong client socket is returned");
- return NET_NFC_UNKNOWN_ERROR;
+ DEBUG_ERR_MSG("Can not get LlcpProxy");
+
+ return NET_NFC_NOT_INITIALIZED;
}
- out_socket_data->oal_socket = out_oal_socket;
+ /* prevent executing daemon when nfc is off */
+ if (net_nfc_client_manager_is_activated() == false) {
+ return NET_NFC_INVALID_STATE;
+ }
- if (out_socket)
- *out_socket = out_client_socket;
+ func_data = g_new0(LlcpFuncData, 1);
+ if (func_data == NULL) {
+ DEBUG_ERR_MSG("g_new0 failed");
+
+ return NET_NFC_ALLOC_FAIL;
+ }
+
+ func_data->callback = (gpointer)callback;
+ func_data->user_data = user_data;
+
+ net_nfc_gdbus_llcp_call_reject(llcp_proxy,
+ GPOINTER_TO_UINT(llcp_handle),
+ socket,
+ net_nfc_client_gdbus_get_privilege(),
+ NULL,
+ llcp_call_reject,
+ func_data);
return NET_NFC_OK;
}
+API net_nfc_error_e net_nfc_client_llcp_reject_sync(net_nfc_llcp_socket_t socket)
+{
+ net_nfc_error_e result;
+ GError *error = NULL;
+
+ if (llcp_proxy == NULL)
+ {
+ DEBUG_ERR_MSG("Can not get LlcpProxy");
+
+ return NET_NFC_NOT_INITIALIZED;
+ }
+
+ /* prevent executing daemon when nfc is off */
+ if (net_nfc_client_manager_is_activated() == false) {
+ return NET_NFC_INVALID_STATE;
+ }
+
+ if (net_nfc_gdbus_llcp_call_reject_sync(llcp_proxy,
+ GPOINTER_TO_UINT(llcp_handle),
+ socket,
+ net_nfc_client_gdbus_get_privilege(),
+ &result,
+ NULL,
+ &error) == false) {
+ DEBUG_ERR_MSG("can not connect: %s", error->message);
+
+ g_error_free(error);
+
+ result = NET_NFC_IPC_FAIL;
+ }
+
+ return result;
+}
+
API net_nfc_error_e net_nfc_client_llcp_connect(net_nfc_llcp_socket_t socket,
const char *service_name,
net_nfc_client_llcp_connect_completed callback,
LlcpFuncData *func_data;
net_nfc_llcp_internal_socket_s *socket_data = NULL;
+ if (service_name == NULL) {
+ return NET_NFC_NULL_PARAMETER;
+ }
+
if (llcp_proxy == NULL)
{
DEBUG_ERR_MSG("Can not get LlcpProxy");
- return NET_NFC_UNKNOWN_ERROR;
- }
- if (service_name == NULL)
- {
- DEBUG_ERR_MSG("service_name is empty");
- return NET_NFC_UNKNOWN_ERROR;
+ return NET_NFC_NOT_INITIALIZED;
}
socket_data = llcp_socket_data_find(socket);
}
func_data = g_new0(LlcpFuncData, 1);
+ if (func_data == NULL) {
+ DEBUG_ERR_MSG("g_new0 failed");
+
+ return NET_NFC_ALLOC_FAIL;
+ }
+
func_data->callback = (gpointer)callback;
func_data->user_data = user_data;
net_nfc_gdbus_llcp_call_connect(llcp_proxy,
GPOINTER_TO_UINT(llcp_handle),
socket_data->client_socket,
- socket_data->oal_socket,
socket_data->miu,
socket_data->rw,
socket_data->type,
const char *service_name,
net_nfc_llcp_socket_t *out_socket)
{
+ net_nfc_error_e result;
GError *error = NULL;
guint32 out_client_socket;
- guint32 out_oal_socket;
net_nfc_llcp_internal_socket_s *socket_data = NULL;
net_nfc_llcp_internal_socket_s *out_socket_data = NULL;
+ if (service_name == NULL || out_socket == NULL) {
+ return NET_NFC_NULL_PARAMETER;
+ }
+
if (llcp_proxy == NULL)
{
DEBUG_ERR_MSG("Can not get LlcpProxy");
- return NET_NFC_UNKNOWN_ERROR;
- }
- if (service_name == NULL)
- {
- DEBUG_ERR_MSG("service_name is empty");
- return NET_NFC_UNKNOWN_ERROR;
+ return NET_NFC_NOT_INITIALIZED;
}
socket_data = llcp_socket_data_find(socket);
if (net_nfc_gdbus_llcp_call_connect_sync(llcp_proxy,
GPOINTER_TO_UINT(llcp_handle),
socket_data->client_socket,
- socket_data->oal_socket,
socket_data->miu,
socket_data->rw,
socket_data->type,
service_name,
net_nfc_client_gdbus_get_privilege(),
+ &result,
&out_client_socket,
- &out_oal_socket,
NULL,
- &error) == FALSE)
- {
- DEBUG_ERR_MSG("can not connect: %s",
- error->message);
- g_error_free(error);
- return NET_NFC_UNKNOWN_ERROR;
- }
+ &error) == true) {
+ out_socket_data = llcp_socket_data_find(out_client_socket);
+ if (out_socket_data == NULL || out_socket_data != socket_data)
+ {
+ DEBUG_ERR_MSG("Wrong client socket is returned");
+ return NET_NFC_UNKNOWN_ERROR;
+ }
- out_socket_data = llcp_socket_data_find(out_client_socket);
- if (out_socket_data == NULL || out_socket_data != socket_data)
- {
- DEBUG_ERR_MSG("Wrong client socket is returned");
- return NET_NFC_UNKNOWN_ERROR;
- }
+ // out_socket_data->oal_socket = out_oal_socket;
- out_socket_data->oal_socket = out_oal_socket;
+ if (out_socket)
+ *out_socket = out_client_socket;
+ } else {
+ DEBUG_ERR_MSG("can not connect: %s", error->message);
- if (out_socket)
- *out_socket = out_client_socket;
+ g_error_free(error);
- return NET_NFC_OK;
+ result = NET_NFC_IPC_FAIL;
+ }
+
+ return result;
}
API net_nfc_error_e net_nfc_client_llcp_connect_sap(net_nfc_llcp_socket_t socket,
LlcpFuncData *func_data;
net_nfc_llcp_internal_socket_s *socket_data = NULL;
+ if (sap == 0) {
+ return NET_NFC_INVALID_PARAM;
+ }
+
if (llcp_proxy == NULL)
{
DEBUG_ERR_MSG("Can not get LlcpProxy");
- return NET_NFC_UNKNOWN_ERROR;
+
+ return NET_NFC_NOT_INITIALIZED;
}
socket_data = llcp_socket_data_find(socket);
}
func_data = g_new0(LlcpFuncData, 1);
+ if (func_data == NULL) {
+ DEBUG_ERR_MSG("g_new0 failed");
+
+ return NET_NFC_ALLOC_FAIL;
+ }
+
func_data->callback = (gpointer)callback;
func_data->user_data = user_data;
net_nfc_gdbus_llcp_call_connect_sap(llcp_proxy,
GPOINTER_TO_UINT(llcp_handle),
socket_data->client_socket,
- socket_data->oal_socket,
socket_data->miu,
socket_data->rw,
socket_data->type,
sap_t sap,
net_nfc_llcp_socket_t *out_socket)
{
+ net_nfc_error_e result;
GError *error = NULL;
guint32 out_client_socket;
- guint32 out_oal_socket;
net_nfc_llcp_internal_socket_s *socket_data = NULL;
net_nfc_llcp_internal_socket_s *out_socket_data = NULL;
+ if (out_socket == NULL) {
+ return NET_NFC_NULL_PARAMETER;
+ }
+
+ if (sap == 0) {
+ return NET_NFC_INVALID_PARAM;
+ }
+
if (llcp_proxy == NULL)
{
DEBUG_ERR_MSG("Can not get LlcpProxy");
- return NET_NFC_UNKNOWN_ERROR;
+
+ return NET_NFC_NOT_INITIALIZED;
}
socket_data = llcp_socket_data_find(socket);
if (net_nfc_gdbus_llcp_call_connect_sap_sync(llcp_proxy,
GPOINTER_TO_UINT(llcp_handle),
socket_data->client_socket,
- socket_data->oal_socket,
socket_data->miu,
socket_data->rw,
socket_data->type,
sap,
net_nfc_client_gdbus_get_privilege(),
+ &result,
&out_client_socket,
- &out_oal_socket,
NULL,
- &error) == FALSE)
- {
- DEBUG_ERR_MSG("can not connect: %s",
- error->message);
- g_error_free(error);
- return NET_NFC_UNKNOWN_ERROR;
- }
+ &error) == true) {
+ out_socket_data = llcp_socket_data_find(out_client_socket);
+ if (out_socket_data == NULL || out_socket_data != socket_data)
+ {
+ DEBUG_ERR_MSG("Wrong client socket is returned");
+ return NET_NFC_UNKNOWN_ERROR;
+ }
- out_socket_data = llcp_socket_data_find(out_client_socket);
- if (out_socket_data == NULL || out_socket_data != socket_data)
- {
- DEBUG_ERR_MSG("Wrong client socket is returned");
- return NET_NFC_UNKNOWN_ERROR;
- }
+ // out_socket_data->oal_socket = out_oal_socket;
- out_socket_data->oal_socket = out_oal_socket;
+ if (out_socket)
+ *out_socket = out_client_socket;
+ } else {
+ DEBUG_ERR_MSG("can not connect: %s", error->message);
- if (out_socket)
- *out_socket = out_client_socket;
+ g_error_free(error);
- return NET_NFC_OK;
+ result = NET_NFC_IPC_FAIL;
+ }
+
+ return result;
}
API net_nfc_error_e net_nfc_client_llcp_send(net_nfc_llcp_socket_t socket,
void *user_data)
{
LlcpFuncData *func_data;
- GVariant *variant = NULL;
+ GVariant *variant;
net_nfc_llcp_internal_socket_s *socket_data = NULL;
+ if (data == NULL) {
+ return NET_NFC_NULL_PARAMETER;
+ }
+
+ if (socket <= 0) {
+ return NET_NFC_INVALID_PARAM;
+ }
+
if (llcp_proxy == NULL)
{
DEBUG_ERR_MSG("Can not get LlcpProxy");
- return NET_NFC_UNKNOWN_ERROR;
+
+ return NET_NFC_NOT_INITIALIZED;
}
/* prevent executing daemon when nfc is off */
return NET_NFC_LLCP_INVALID_SOCKET;
}
- if (data == NULL)
- {
- DEBUG_ERR_MSG("data is empty");
- return NET_NFC_INVALID_PARAM;
- }
+ func_data = g_new0(LlcpFuncData, 1);
+ if (func_data == NULL) {
+ DEBUG_ERR_MSG("g_new0 failed");
- variant = net_nfc_util_gdbus_data_to_variant(data);
- if (variant == NULL)
- {
- DEBUG_ERR_MSG("Can not convert to variant");
- return NET_NFC_INVALID_PARAM;
+ return NET_NFC_ALLOC_FAIL;
}
-
- func_data = g_new0(LlcpFuncData, 1);
func_data->callback = (gpointer)callback;
func_data->user_data = user_data;
+ variant = net_nfc_util_gdbus_data_to_variant(data);
+
net_nfc_gdbus_llcp_call_send(llcp_proxy,
GPOINTER_TO_UINT(llcp_handle),
socket_data->client_socket,
- socket_data->oal_socket,
variant,
net_nfc_client_gdbus_get_privilege(),
NULL,
}
API net_nfc_error_e net_nfc_client_llcp_send_sync(net_nfc_llcp_socket_t socket,
- data_h data,
- net_nfc_llcp_socket_t *out_socket)
+ data_h data)
{
+ net_nfc_error_e result;
GVariant *variant;
GError *error = NULL;
guint32 out_client_socket;
net_nfc_llcp_internal_socket_s *socket_data;
net_nfc_llcp_internal_socket_s *out_socket_data;
+ if (data == NULL) {
+ return NET_NFC_NULL_PARAMETER;
+ }
+
+ if (socket <= 0) {
+ return NET_NFC_INVALID_PARAM;
+ }
+
if (llcp_proxy == NULL)
{
DEBUG_ERR_MSG("Can not get LlcpProxy");
- return NET_NFC_UNKNOWN_ERROR;
+
+ return NET_NFC_NOT_INITIALIZED;
}
socket_data = llcp_socket_data_find(socket);
}
variant = net_nfc_util_gdbus_data_to_variant(data);
- if (variant == NULL)
- {
- DEBUG_ERR_MSG("Can not convert to variant");
- return NET_NFC_INVALID_PARAM;
- }
if (net_nfc_gdbus_llcp_call_send_sync(llcp_proxy,
GPOINTER_TO_UINT(llcp_handle),
socket_data->client_socket,
- socket_data->oal_socket,
variant,
net_nfc_client_gdbus_get_privilege(),
+ &result,
&out_client_socket,
NULL,
- &error) == FALSE)
- {
- DEBUG_ERR_MSG("can not call send: %s",
- error->message);
+ &error) == true) {
+ out_socket_data = llcp_socket_data_find(out_client_socket);
+ if (out_socket_data == NULL)
+ {
+ DEBUG_ERR_MSG("can not find socket_data");
+ return NET_NFC_UNKNOWN_ERROR;
+ }
+ } else {
+ DEBUG_ERR_MSG("can not call send: %s", error->message);
+
g_error_free(error);
- return NET_NFC_UNKNOWN_ERROR;
- }
- out_socket_data = llcp_socket_data_find(out_client_socket);
- if (out_socket_data == NULL)
- {
- DEBUG_ERR_MSG("can not find socket_data");
- return NET_NFC_UNKNOWN_ERROR;
+ result = NET_NFC_IPC_FAIL;
}
- if (out_socket)
- *out_socket = out_client_socket;
-
- return NET_NFC_OK;
+ return result;
}
-
API net_nfc_error_e net_nfc_client_llcp_send_to(net_nfc_llcp_socket_t socket,
sap_t sap,
data_h data,
void *user_data)
{
LlcpFuncData *func_data;
- GVariant *variant = NULL;
+ GVariant *variant;
net_nfc_llcp_internal_socket_s *socket_data = NULL;
+ if (data == NULL) {
+ return NET_NFC_NULL_PARAMETER;
+ }
+
+ if (socket <= 0 || sap == 0) {
+ return NET_NFC_INVALID_PARAM;
+ }
+
if (llcp_proxy == NULL)
{
DEBUG_ERR_MSG("Can not get LlcpProxy");
- return NET_NFC_UNKNOWN_ERROR;
+
+ return NET_NFC_NOT_INITIALIZED;
}
socket_data = llcp_socket_data_find(socket);
return NET_NFC_LLCP_INVALID_SOCKET;
}
- if (data == NULL)
- {
- DEBUG_ERR_MSG("data is empty");
- return NET_NFC_INVALID_PARAM;
- }
-
- variant = net_nfc_util_gdbus_data_to_variant(data);
- if (variant == NULL)
- {
- DEBUG_ERR_MSG("Can not convert to variant");
- return NET_NFC_INVALID_PARAM;
- }
-
/* prevent executing daemon when nfc is off */
if (net_nfc_client_manager_is_activated() == false) {
return NET_NFC_INVALID_STATE;
}
func_data = g_new0(LlcpFuncData, 1);
+ if (func_data == NULL) {
+ DEBUG_ERR_MSG("g_new0 failed");
+
+ return NET_NFC_ALLOC_FAIL;
+ }
+
func_data->callback = (gpointer)callback;
func_data->user_data = user_data;
+ variant = net_nfc_util_gdbus_data_to_variant(data);
+
net_nfc_gdbus_llcp_call_send_to(llcp_proxy,
GPOINTER_TO_UINT(llcp_handle),
socket_data->client_socket,
- socket_data->oal_socket,
sap,
variant,
net_nfc_client_gdbus_get_privilege(),
}
API net_nfc_error_e net_nfc_client_llcp_send_to_sync(net_nfc_llcp_socket_t socket,
- sap_t sap,
- data_h data,
- net_nfc_llcp_socket_t *out_socket)
+ sap_t sap, data_h data)
{
+ net_nfc_error_e result;
GVariant *variant;
GError *error = NULL;
guint32 out_client_socket;
net_nfc_llcp_internal_socket_s *socket_data;
net_nfc_llcp_internal_socket_s *out_socket_data;
+ if (data == NULL) {
+ return NET_NFC_NULL_PARAMETER;
+ }
+
+ if (socket <= 0 || sap == 0) {
+ return NET_NFC_INVALID_PARAM;
+ }
+
if (llcp_proxy == NULL)
{
DEBUG_ERR_MSG("Can not get LlcpProxy");
- return NET_NFC_UNKNOWN_ERROR;
+
+ return NET_NFC_NOT_INITIALIZED;
}
socket_data = llcp_socket_data_find(socket);
return NET_NFC_LLCP_INVALID_SOCKET;
}
- if (data == NULL)
- {
- DEBUG_ERR_MSG("data is empty");
- return NET_NFC_INVALID_PARAM;
- }
-
/* prevent executing daemon when nfc is off */
if (net_nfc_client_manager_is_activated() == false) {
return NET_NFC_INVALID_STATE;
}
variant = net_nfc_util_gdbus_data_to_variant(data);
- if (variant == NULL)
- {
- DEBUG_ERR_MSG("Can not convert to variant");
- return NET_NFC_INVALID_PARAM;
- }
if (net_nfc_gdbus_llcp_call_send_to_sync(llcp_proxy,
GPOINTER_TO_UINT(llcp_handle),
socket_data->client_socket,
- socket_data->oal_socket,
sap,
variant,
net_nfc_client_gdbus_get_privilege(),
+ &result,
&out_client_socket,
NULL,
- &error) == FALSE)
- {
- DEBUG_ERR_MSG("can not call send to: %s",
- error->message);
+ &error) == true) {
+ out_socket_data = llcp_socket_data_find(out_client_socket);
+ if (out_socket_data == NULL)
+ {
+ DEBUG_ERR_MSG("can not find socket_data");
+ return NET_NFC_UNKNOWN_ERROR;
+ }
+ } else {
+ DEBUG_ERR_MSG("can not call send to: %s", error->message);
+
g_error_free(error);
- return NET_NFC_UNKNOWN_ERROR;
- }
- out_socket_data = llcp_socket_data_find(out_client_socket);
- if (out_socket_data == NULL)
- {
- DEBUG_ERR_MSG("can not find socket_data");
- return NET_NFC_UNKNOWN_ERROR;
+ result = NET_NFC_IPC_FAIL;
}
- if (out_socket)
- *out_socket = out_client_socket;
-
- return NET_NFC_OK;
+ return result;
}
API net_nfc_error_e net_nfc_client_llcp_receive(net_nfc_llcp_socket_t socket,
LlcpFuncData *func_data;
net_nfc_llcp_internal_socket_s *socket_data = NULL;
+ if (socket <= 0 || request_length == 0) {
+ return NET_NFC_INVALID_PARAM;
+ }
+
if (llcp_proxy == NULL)
{
DEBUG_ERR_MSG("Can not get LlcpProxy");
- return NET_NFC_UNKNOWN_ERROR;
+
+ return NET_NFC_NOT_INITIALIZED;
}
socket_data = llcp_socket_data_find(socket);
}
func_data = g_new0(LlcpFuncData, 1);
+ if (func_data == NULL) {
+ DEBUG_ERR_MSG("g_new0 failed");
+
+ return NET_NFC_ALLOC_FAIL;
+ }
+
func_data->callback = (gpointer)callback;
func_data->user_data = user_data;
net_nfc_gdbus_llcp_call_receive(llcp_proxy,
GPOINTER_TO_UINT(llcp_handle),
socket_data->client_socket,
- socket_data->oal_socket,
request_length,
net_nfc_client_gdbus_get_privilege(),
NULL,
size_t request_length,
data_h *out_data)
{
- GVariant *variant = NULL;
+ net_nfc_error_e result;
+ GVariant *variant;
GError *error = NULL;
net_nfc_llcp_internal_socket_s *socket_data;
+ if (out_data == NULL) {
+ return NET_NFC_NULL_PARAMETER;
+ }
+
+ *out_data = NULL;
+
+ if (socket <= 0 || request_length == 0) {
+ return NET_NFC_INVALID_PARAM;
+ }
+
if (llcp_proxy == NULL)
{
DEBUG_ERR_MSG("Can not get LlcpProxy");
- return NET_NFC_UNKNOWN_ERROR;
+
+ return NET_NFC_NOT_INITIALIZED;
}
socket_data = llcp_socket_data_find(socket);
if (net_nfc_gdbus_llcp_call_receive_sync(llcp_proxy,
GPOINTER_TO_UINT(llcp_handle),
socket_data->client_socket,
- socket_data->oal_socket,
request_length,
net_nfc_client_gdbus_get_privilege(),
+ &result,
&variant,
NULL,
- &error) == FALSE)
- {
- DEBUG_ERR_MSG("can not call receive: %s",
- error->message);
+ &error) == true) {
+ *out_data = net_nfc_util_gdbus_variant_to_data(variant);
+ } else {
+ DEBUG_ERR_MSG("can not call receive: %s", error->message);
+
g_error_free(error);
- return NET_NFC_UNKNOWN_ERROR;
- }
- if (out_data)
- {
- *out_data = net_nfc_util_gdbus_variant_to_data(variant);
+ result = NET_NFC_IPC_FAIL;
}
- return NET_NFC_OK;
+ return result;
}
API net_nfc_error_e net_nfc_client_llcp_receive_from(net_nfc_llcp_socket_t socket,
LlcpFuncData *func_data;
net_nfc_llcp_internal_socket_s *socket_data = NULL;
+ if (socket <= 0 || request_length == 0) {
+ return NET_NFC_INVALID_PARAM;
+ }
+
if (llcp_proxy == NULL)
{
DEBUG_ERR_MSG("Can not get LlcpProxy");
- return NET_NFC_UNKNOWN_ERROR;
+
+ return NET_NFC_NOT_INITIALIZED;
}
socket_data = llcp_socket_data_find(socket);
}
func_data = g_new0(LlcpFuncData, 1);
+ if (func_data == NULL) {
+ DEBUG_ERR_MSG("g_new0 failed");
+
+ return NET_NFC_ALLOC_FAIL;
+ }
+
func_data->callback = (gpointer)callback;
func_data->user_data = user_data;
net_nfc_gdbus_llcp_call_receive_from(llcp_proxy,
GPOINTER_TO_UINT(llcp_handle),
socket_data->client_socket,
- socket_data->oal_socket,
request_length,
net_nfc_client_gdbus_get_privilege(),
NULL,
sap_t *out_sap,
data_h *out_data)
{
- GVariant *variant = NULL;
+ net_nfc_error_e result;
GError *error = NULL;
+ GVariant *variant;
sap_t sap;
net_nfc_llcp_internal_socket_s *socket_data;
+ if (out_sap == NULL || out_data == NULL) {
+ return NET_NFC_NULL_PARAMETER;
+ }
+
+ *out_data = NULL;
+ *out_sap = 0;
+
+ if (socket <= 0 || request_length == 0) {
+ return NET_NFC_INVALID_PARAM;
+ }
+
if (llcp_proxy == NULL)
{
DEBUG_ERR_MSG("Can not get LlcpProxy");
- return NET_NFC_UNKNOWN_ERROR;
+
+ return NET_NFC_NOT_INITIALIZED;
}
socket_data = llcp_socket_data_find(socket);
if (net_nfc_gdbus_llcp_call_receive_from_sync(llcp_proxy,
GPOINTER_TO_UINT(llcp_handle),
socket_data->client_socket,
- socket_data->oal_socket,
request_length,
net_nfc_client_gdbus_get_privilege(),
+ &result,
&sap,
&variant,
NULL,
- &error) == FALSE)
- {
- DEBUG_ERR_MSG("can not call receive from: %s",
- error->message);
- g_error_free(error);
- return NET_NFC_UNKNOWN_ERROR;
- }
-
- if (*out_sap)
+ &error) == true) {
*out_sap = sap;
-
- if (out_data)
- {
*out_data = net_nfc_util_gdbus_variant_to_data(variant);
+ } else {
+ DEBUG_ERR_MSG("can not call receive from: %s", error->message);
+
+ g_error_free(error);
+
+ result = NET_NFC_IPC_FAIL;
}
- return NET_NFC_OK;
+ return result;
}
API net_nfc_error_e net_nfc_client_llcp_close(net_nfc_llcp_socket_t socket,
LlcpFuncData *func_data;
net_nfc_llcp_internal_socket_s *socket_data = NULL;
+ if (socket <= 0) {
+ return NET_NFC_INVALID_PARAM;
+ }
+
if (llcp_proxy == NULL)
{
DEBUG_ERR_MSG("Can not get LlcpProxy");
- return NET_NFC_UNKNOWN_ERROR;
+
+ return NET_NFC_NOT_INITIALIZED;
}
socket_data = llcp_socket_data_find(socket);
}
func_data = g_new0(LlcpFuncData, 1);
+ if (func_data == NULL) {
+ DEBUG_ERR_MSG("g_new0 failed");
+
+ return NET_NFC_ALLOC_FAIL;
+ }
+
func_data->callback = (gpointer)callback;
func_data->user_data = user_data;
net_nfc_gdbus_llcp_call_close(llcp_proxy,
GPOINTER_TO_UINT(llcp_handle),
socket_data->client_socket,
- socket_data->oal_socket,
net_nfc_client_gdbus_get_privilege(),
NULL,
llcp_call_close,
return NET_NFC_OK;
}
-API net_nfc_error_e net_nfc_client_llcp_close_sync(net_nfc_llcp_socket_t socket,
- net_nfc_llcp_socket_t *out_socket)
+API net_nfc_error_e net_nfc_client_llcp_close_sync(net_nfc_llcp_socket_t socket)
{
+ net_nfc_error_e result;
GError *error = NULL;
guint32 out_client_socket;
net_nfc_llcp_internal_socket_s *socket_data = NULL;
net_nfc_llcp_internal_socket_s *out_socket_data = NULL;
+ if (socket <= 0) {
+ return NET_NFC_INVALID_PARAM;
+ }
+
if (llcp_proxy == NULL)
{
DEBUG_ERR_MSG("Can not get LlcpProxy");
- return NET_NFC_UNKNOWN_ERROR;
+
+ return NET_NFC_NOT_INITIALIZED;
}
socket_data = llcp_socket_data_find(socket);
if (net_nfc_gdbus_llcp_call_close_sync(llcp_proxy,
GPOINTER_TO_UINT(llcp_handle),
socket_data->client_socket,
- socket_data->oal_socket,
net_nfc_client_gdbus_get_privilege(),
+ &result,
&out_client_socket,
NULL,
- &error) == FALSE)
- {
- DEBUG_ERR_MSG("can not close: %s",
- error->message);
+ &error) == true) {
+ out_socket_data = llcp_socket_data_find(out_client_socket);
+ if (out_socket_data == NULL || out_socket_data != socket_data)
+ {
+ DEBUG_ERR_MSG("Wrong client socket is returned");
+ return NET_NFC_UNKNOWN_ERROR;
+ }
+ } else {
+ DEBUG_ERR_MSG("can not close: %s", error->message);
+
g_error_free(error);
- return NET_NFC_UNKNOWN_ERROR;
- }
- out_socket_data = llcp_socket_data_find(out_client_socket);
- if (out_socket_data == NULL || out_socket_data != socket_data)
- {
- DEBUG_ERR_MSG("Wrong client socket is returned");
- return NET_NFC_UNKNOWN_ERROR;
+ result = NET_NFC_IPC_FAIL;
}
- if (out_socket)
- *out_socket = out_client_socket;
-
- return NET_NFC_OK;
+ return result;
}
API net_nfc_error_e net_nfc_client_llcp_disconnect(net_nfc_llcp_socket_t socket,
LlcpFuncData *func_data;
net_nfc_llcp_internal_socket_s *socket_data = NULL;
+ if (socket <= 0) {
+ return NET_NFC_INVALID_PARAM;
+ }
+
if (llcp_proxy == NULL)
{
DEBUG_ERR_MSG("Can not get LlcpProxy");
- return NET_NFC_UNKNOWN_ERROR;
+
+ return NET_NFC_NOT_INITIALIZED;
}
socket_data = llcp_socket_data_find(socket);
}
func_data = g_new0(LlcpFuncData, 1);
+ if (func_data == NULL) {
+ DEBUG_ERR_MSG("g_new0 failed");
+
+ return NET_NFC_ALLOC_FAIL;
+ }
+
func_data->callback = (gpointer)callback;
func_data->user_data = user_data;
net_nfc_gdbus_llcp_call_disconnect(llcp_proxy,
GPOINTER_TO_UINT(llcp_handle),
socket_data->client_socket,
- socket_data->oal_socket,
net_nfc_client_gdbus_get_privilege(),
NULL,
llcp_call_disconnect,
}
API net_nfc_error_e net_nfc_client_llcp_disconnect_sync(
- net_nfc_llcp_socket_t socket,
- net_nfc_llcp_socket_t *out_socket)
+ net_nfc_llcp_socket_t socket)
{
+ net_nfc_error_e result;
GError *error = NULL;
guint32 out_client_socket;
net_nfc_llcp_internal_socket_s *socket_data = NULL;
net_nfc_llcp_internal_socket_s *out_socket_data = NULL;
+ if (socket <= 0) {
+ return NET_NFC_INVALID_PARAM;
+ }
+
if (llcp_proxy == NULL)
{
DEBUG_ERR_MSG("Can not get LlcpProxy");
- return NET_NFC_UNKNOWN_ERROR;
+
+ return NET_NFC_NOT_INITIALIZED;
}
socket_data = llcp_socket_data_find(socket);
if (net_nfc_gdbus_llcp_call_disconnect_sync(llcp_proxy,
GPOINTER_TO_UINT(llcp_handle),
socket_data->client_socket,
- socket_data->oal_socket,
net_nfc_client_gdbus_get_privilege(),
+ &result,
&out_client_socket,
NULL,
- &error) == FALSE)
- {
- DEBUG_ERR_MSG("can not disconnect: %s",
- error->message);
+ &error) == true) {
+ out_socket_data = llcp_socket_data_find(out_client_socket);
+ if (out_socket_data == NULL || out_socket_data != socket_data)
+ {
+ DEBUG_ERR_MSG("Wrong client socket is returned");
+ return NET_NFC_UNKNOWN_ERROR;
+ }
+ } else {
+ DEBUG_ERR_MSG("can not disconnect: %s", error->message);
+
g_error_free(error);
- return NET_NFC_UNKNOWN_ERROR;
- }
- out_socket_data = llcp_socket_data_find(out_client_socket);
- if (out_socket_data == NULL || out_socket_data != socket_data)
- {
- DEBUG_ERR_MSG("Wrong client socket is returned");
- return NET_NFC_UNKNOWN_ERROR;
+ result = NET_NFC_IPC_FAIL;
}
- if (out_socket)
- *out_socket = out_client_socket;
-
- return NET_NFC_OK;
+ return result;
}
API void net_nfc_client_llcp_create_socket(net_nfc_llcp_socket_t *socket,
net_nfc_llcp_socket_option_h option,
uint16_t *miu)
{
+ net_nfc_llcp_socket_option_s *struct_option =
+ (net_nfc_llcp_socket_option_s *)option;
+
if (option == NULL || miu == NULL)
{
return NET_NFC_NULL_PARAMETER;
}
- net_nfc_llcp_socket_option_s *struct_option = (net_nfc_llcp_socket_option_s *)option;
*miu = struct_option->miu;
+
return NET_NFC_OK;
}
net_nfc_llcp_socket_option_h option,
uint16_t miu)
{
+ net_nfc_llcp_socket_option_s *struct_option =
+ (net_nfc_llcp_socket_option_s *)option;
+
if (option == NULL)
{
return NET_NFC_NULL_PARAMETER;
}
- net_nfc_llcp_socket_option_s *struct_option = (net_nfc_llcp_socket_option_s *)option;
struct_option->miu = miu;
+
return NET_NFC_OK;
}
return NET_NFC_UNKNOWN_ERROR;
}
- g_signal_connect(llcp_proxy, "error", G_CALLBACK(llcp_error), NULL);
+ g_signal_connect(llcp_proxy, "error",
+ G_CALLBACK(llcp_error), NULL);
+
+ g_signal_connect(llcp_proxy, "incoming",
+ G_CALLBACK(llcp_incoming), NULL);
return NET_NFC_OK;
}
*/
#include <pmapi.h>/*for pm lock*/
+#include "net_nfc_debug_internal.h"
+#include "net_nfc_util_internal.h"
+#include "net_nfc_util_gdbus_internal.h"
#include "net_nfc_gdbus.h"
+
+#include "net_nfc_server_controller.h"
#include "net_nfc_server_common.h"
-#include "net_nfc_server_p2p.h"
+#include "net_nfc_server_context.h"
+#include "net_nfc_server_tag.h"
#include "net_nfc_server_llcp.h"
-
+#include "net_nfc_server_p2p.h"
#include "net_nfc_server_process_snep.h"
#include "net_nfc_server_process_npp.h"
#include "net_nfc_server_process_handover.h"
-#include "net_nfc_server_tag.h"
-
-#include "net_nfc_debug_internal.h"
-#include "net_nfc_server_controller.h"
-#include "net_nfc_util_gdbus_internal.h"
-#include "net_nfc_server_context.h"
/* default llcp configurations */
#define NET_NFC_LLCP_MIU 128
NET_NFC_LLCP_OPT,
};
+
+typedef struct _llcp_client_data
+{
+ GDBusConnection *connection;
+ char *id;
+ net_nfc_target_handle_h handle;
+ net_nfc_llcp_socket_t socket;
+ void *user_data;
+}
+llcp_client_data;
+
+
typedef struct _LlcpData LlcpData;
struct _LlcpData
guint32 handle;
guint32 client_socket;
- guint32 oal_socket;
guint16 miu;
guint8 rw;
guint type;
gchar *service_name;
};
+typedef struct _LlcpAcceptData LlcpAcceptData;
+
+struct _LlcpAcceptData
+{
+ NetNfcGDbusLlcp *llcp;
+ GDBusMethodInvocation *invocation;
+
+ guint handle;
+ guint client_socket;
+};
+
typedef struct _LlcpConnectData LlcpConnectData;
struct _LlcpConnectData
guint32 handle;
guint32 client_socket;
- guint32 oal_socket;
guint16 miu;
guint8 rw;
guint type;
guint32 handle;
guint32 client_socket;
- guint32 oal_socket;
guint16 miu;
guint8 rw;
guint type;
guint32 handle;
guint32 client_socket;
- guint32 oal_socket;
- data_s *data;
+ data_s data;
};
typedef struct _LlcpSendToData LlcpSendToData;
guint32 handle;
guint32 client_socket;
- guint32 oal_socket;
guint8 sap;
- data_s *data;
+ data_s data;
};
typedef struct _LlcpReceiveData LlcpReceiveData;
guint32 handle;
guint32 client_socket;
- guint32 oal_socket;
guint32 req_length;
};
guint32 handle;
guint32 client_socket;
- guint32 oal_socket;
};
typedef struct _LlcpDisconnectData LlcpDisconnectData;
guint32 handle;
guint32 client_socket;
- guint32 oal_socket;
-};
-
-/* server_side */
-typedef struct _ServerLlcpData ServerLlcpData;
-
-struct _ServerLlcpData
-{
- NetNfcGDbusLlcp *llcp;
- net_nfc_request_msg_t *req_msg;
};
typedef struct _LlcpSimpleData LlcpSimpleData;
gpointer user_data;
};
-
-static void llcp_add_async_queue(net_nfc_request_msg_t *req_msg,
- net_nfc_server_controller_func func);
-
static void llcp_socket_error_cb(net_nfc_llcp_socket_t socket,
net_nfc_error_e result,
data_s *data,
void *extra,
void *user_param);
-static void llcp_listen_cb(net_nfc_llcp_socket_t socket,
+static void llcp_incoming_cb(net_nfc_llcp_socket_t socket,
net_nfc_error_e result,
data_s *data,
void *extra,
void *extra,
void *user_param);
+static void llcp_send_to_cb(net_nfc_llcp_socket_t socket,
+ net_nfc_error_e result,
+ data_s *data,
+ void *extra,
+ void *user_param);
+
static void llcp_receive_cb(net_nfc_llcp_socket_t socket,
net_nfc_error_e result,
data_s *data,
static void llcp_handle_listen_thread_func(gpointer user_data);
+static void llcp_handle_accept_thread_func(gpointer user_data);
+
+static void llcp_handle_reject_thread_func(gpointer user_data);
+
static void llcp_handle_connect_thread_func(gpointer user_data);
static void llcp_handle_connect_sap_thread_func(gpointer user_data);
GDBusMethodInvocation *invocation,
guint32 arg_handle,
guint32 arg_client_socket,
- guint32 arg_oal_socket,
guint16 arg_miu,
guint8 arg_rw,
gint32 arg_type,
GDBusMethodInvocation *invocation,
guint32 arg_handle,
guint32 arg_client_socket,
- guint32 arg_oal_socket,
guint16 arg_miu,
guint8 arg_rw,
gint32 arg_type,
GDBusMethodInvocation *invocation,
guint32 arg_handle,
guint32 arg_client_socket,
- guint32 arg_oal_socket,
guint16 arg_miu,
guint8 arg_rw,
gint32 arg_type,
GDBusMethodInvocation *invocation,
guint32 arg_handle,
guint32 arg_client_socket,
- guint32 arg_oal_socket,
GVariant *arg_data,
GVariant *smack_privilege,
gpointer user_data);
GDBusMethodInvocation *invocation,
guint32 arg_handle,
guint32 arg_client_socket,
- guint32 arg_oal_socket,
guint8 arg_sap,
GVariant *arg_data,
GVariant *smack_privilege,
GDBusMethodInvocation *invocation,
guint32 arg_handle,
guint32 arg_client_socket,
- guint32 arg_oal_socket,
guint32 arg_req_length,
GVariant *smack_privilege,
gpointer user_data);
GDBusMethodInvocation *invocation,
guint32 arg_handle,
guint32 arg_client_socket,
- guint32 arg_oal_socket,
guint32 arg_req_length,
GVariant *smack_privilege,
gpointer user_data);
GDBusMethodInvocation *invocation,
guint32 arg_handle,
guint32 arg_client_socket,
- guint32 arg_oal_socket,
GVariant *smack_privilege,
gpointer user_data);
GDBusMethodInvocation *invocation,
guint32 arg_handle,
guint32 arg_client_socket,
- guint32 arg_oal_socket,
GVariant *smack_privilege,
gpointer user_data);
-/* server side */
-static void llcp_deactivated_thread_func(gpointer user_data);
-
-static void llcp_listen_thread_func(gpointer user_data);
-
-static void llcp_socket_error_thread_func(gpointer user_data);
-
-static void llcp_send_thread_func(gpointer user_data);
-
-static void llcp_receive_thread_func(gpointer user_data);
-
-static void llcp_receive_from_thread_func(gpointer user_data);
-
-static void llcp_connect_thread_func(gpointer user_data);
-
-static void llcp_disconnect_thread_func(gpointer user_data);
-
/* simple */
static void llcp_simple_socket_error_cb(net_nfc_llcp_socket_t socket,
net_nfc_error_e result,
void *extra,
void *user_param);
-static void llcp_simple_server_error_cb(net_nfc_llcp_socket_t socket,
- net_nfc_error_e result,
- data_s *data,
- void *extra,
- void *user_param);
-
static void llcp_simple_send_cb(net_nfc_llcp_socket_t socket,
net_nfc_error_e result,
data_s *data,
void *user_param);
-static void llcp_add_async_queue(net_nfc_request_msg_t *req_msg,
- net_nfc_server_controller_func func)
+static void llcp_socket_error_cb(net_nfc_llcp_socket_t socket,
+ net_nfc_error_e result,
+ data_s *data,
+ void *extra,
+ void *user_param)
{
- ServerLlcpData *data = NULL;
-
- if (llcp_skeleton == NULL)
- {
- DEBUG_ERR_MSG("%s is not initialized",
- "net_nfc_server_llcp");
- return;
- }
-
- if (req_msg == NULL)
- {
- DEBUG_ERR_MSG("req msg is null");
- }
-
- data = g_new0(ServerLlcpData, 1);
- if(data == NULL)
- {
- DEBUG_ERR_MSG("Memory allocation failed");
- return;
- }
- data->llcp = g_object_ref(llcp_skeleton);
- data->req_msg = req_msg;
-
- if (net_nfc_server_controller_async_queue_push(func, data) == FALSE)
- {
- DEBUG_ERR_MSG("can not push to controller thread");
+ llcp_client_data *client_data = (llcp_client_data *)user_param;
+ GError *error = NULL;
- if (data)
- {
- g_object_unref(data->llcp);
- g_free(data->req_msg);
- g_free(data);
+ if (g_dbus_connection_emit_signal(
+ client_data->connection,
+ client_data->id,
+ "/org/tizen/NetNfcService/Llcp",
+ "org.tizen.NetNfcService.Llcp",
+ "Error",
+ g_variant_new("(uui)",
+ GPOINTER_TO_UINT(client_data->handle),
+ socket,
+ result),
+ &error) == false) {
+ if (error != NULL && error->message != NULL) {
+ DEBUG_ERR_MSG("g_dbus_connection_emit_signal failed : %s", error->message);
+ } else {
+ DEBUG_ERR_MSG("g_dbus_connection_emit_signal failed");
}
}
}
-static void llcp_socket_error_cb(net_nfc_llcp_socket_t socket,
+static void llcp_incoming_cb(net_nfc_llcp_socket_t socket,
net_nfc_error_e result,
data_s *data,
void *extra,
void *user_param)
{
- LlcpData *llcp_data;
-
- llcp_data = (LlcpData *)user_param;
-
- if (llcp_data->invocation)
- {
- g_dbus_method_invocation_return_dbus_error(
- llcp_data->invocation,
- "org.tizen.NetNfcService.SocketError",
- "socket error");
+ llcp_client_data *client_data = (llcp_client_data *)user_param;
+ GError *error = NULL;
- g_object_unref(llcp_data->invocation);
+ if (g_dbus_connection_emit_signal(
+ client_data->connection,
+ client_data->id,
+ "/org/tizen/NetNfcService/Llcp",
+ "org.tizen.NetNfcService.Llcp",
+ "Incoming",
+ g_variant_new("(uuu)",
+ GPOINTER_TO_UINT(client_data->handle),
+ client_data->socket,
+ socket),
+ &error) == false) {
+ if (error != NULL && error->message != NULL) {
+ DEBUG_ERR_MSG("g_dbus_connection_emit_signal failed : %s", error->message);
+ } else {
+ DEBUG_ERR_MSG("g_dbus_connection_emit_signal failed");
+ }
}
-
- if (llcp_data->llcp)
- g_object_unref(llcp_data->llcp);
-
- g_free(llcp_data);
}
-static void llcp_listen_cb(net_nfc_llcp_socket_t socket,
+static void llcp_connect_by_url_cb(net_nfc_llcp_socket_t socket,
net_nfc_error_e result,
data_s *data,
void *extra,
void *user_param)
{
- LlcpListenData *llcp_data;
+ LlcpConnectData *llcp_data = (LlcpConnectData *)user_param;
- llcp_data = (LlcpListenData *)user_param;
+ g_assert(llcp_data != NULL);
+ g_assert(llcp_data->llcp != NULL);
+ g_assert(llcp_data->invocation != NULL);
- if (llcp_data == NULL)
- return;
-
- if (llcp_data->llcp)
- {
+ net_nfc_gdbus_llcp_complete_connect(llcp_data->llcp,
+ llcp_data->invocation,
+ result,
+ socket);
- if (llcp_data->invocation)
- {
- net_nfc_gdbus_llcp_complete_listen(llcp_data->llcp,
- llcp_data->invocation,
- llcp_data->client_socket,
- socket);
- g_object_unref(llcp_data->invocation);
- }
+ g_free(llcp_data->service_name);
- g_object_unref(llcp_data->llcp);
- }
+ g_object_unref(llcp_data->invocation);
+ g_object_unref(llcp_data->llcp);
- g_free(llcp_data->service_name);
g_free(llcp_data);
}
-static void llcp_connect_by_url_cb(net_nfc_llcp_socket_t socket,
+static void llcp_connect_cb(net_nfc_llcp_socket_t socket,
net_nfc_error_e result,
data_s *data,
void *extra,
void *user_param)
{
- LlcpConnectData *llcp_data;
-
- llcp_data = (LlcpConnectData *)user_param;
-
- if (llcp_data == NULL)
- return;
+ LlcpConnectSapData *llcp_data = (LlcpConnectSapData *)user_param;
- if (llcp_data->llcp)
- {
+ g_assert(llcp_data != NULL);
+ g_assert(llcp_data->llcp != NULL);
+ g_assert(llcp_data->invocation != NULL);
- if (llcp_data->invocation)
- {
- net_nfc_gdbus_llcp_complete_connect(llcp_data->llcp,
- llcp_data->invocation,
- llcp_data->client_socket,
- socket);
- g_object_unref(llcp_data->invocation);
- }
+ net_nfc_gdbus_llcp_complete_connect_sap(
+ llcp_data->llcp,
+ llcp_data->invocation,
+ result,
+ socket);
- g_object_unref(llcp_data->llcp);
- }
+ g_object_unref(llcp_data->invocation);
+ g_object_unref(llcp_data->llcp);
- g_free(llcp_data->service_name);
g_free(llcp_data);
}
-static void llcp_connect_cb(net_nfc_llcp_socket_t socket,
+static void llcp_send_cb(net_nfc_llcp_socket_t socket,
net_nfc_error_e result,
data_s *data,
void *extra,
void *user_param)
{
- LlcpConnectSapData *llcp_data;
+ LlcpSendData *llcp_data = (LlcpSendData *)user_param;
- llcp_data = (LlcpConnectSapData *)user_param;
+ g_assert(llcp_data != NULL);
+ g_assert(llcp_data->llcp != NULL);
+ g_assert(llcp_data->invocation != NULL);
- if (llcp_data == NULL)
- return;
-
- if (llcp_data->llcp)
- {
+ net_nfc_gdbus_llcp_complete_send(
+ llcp_data->llcp,
+ llcp_data->invocation,
+ result,
+ socket);
- if (llcp_data->invocation)
- {
- net_nfc_gdbus_llcp_complete_connect_sap(
- llcp_data->llcp,
- llcp_data->invocation,
- llcp_data->client_socket,
- socket);
- g_object_unref(llcp_data->invocation);
- }
+ net_nfc_util_free_data(&llcp_data->data);
- g_object_unref(llcp_data->llcp);
- }
+ g_object_unref(llcp_data->invocation);
+ g_object_unref(llcp_data->llcp);
g_free(llcp_data);
}
-static void llcp_send_cb(net_nfc_llcp_socket_t socket,
+static void llcp_send_to_cb(net_nfc_llcp_socket_t socket,
net_nfc_error_e result,
data_s *data,
void *extra,
void *user_param)
{
- LlcpData *llcp_data;
-
- llcp_data = (LlcpData *)user_param;
+ LlcpSendToData *llcp_data = (LlcpSendToData *)user_param;
- if (llcp_data == NULL)
- return;
+ g_assert(llcp_data != NULL);
+ g_assert(llcp_data->llcp != NULL);
+ g_assert(llcp_data->invocation != NULL);
- if (llcp_data->llcp)
- {
+ net_nfc_gdbus_llcp_complete_send_to(
+ llcp_data->llcp,
+ llcp_data->invocation,
+ result,
+ socket);
- if (llcp_data->invocation)
- {
- net_nfc_gdbus_llcp_complete_send(
- llcp_data->llcp,
- llcp_data->invocation,
- socket);
- g_object_unref(llcp_data->invocation);
- }
+ net_nfc_util_free_data(&llcp_data->data);
- g_object_unref(llcp_data->llcp);
- }
+ g_object_unref(llcp_data->invocation);
+ g_object_unref(llcp_data->llcp);
g_free(llcp_data);
}
void *extra,
void *user_param)
{
- LlcpData *llcp_data;
-
- llcp_data = (LlcpData *)user_param;
-
- if (llcp_data == NULL)
- return;
+ LlcpReceiveData *llcp_data = (LlcpReceiveData *)user_param;
+ GVariant *variant;
- if (llcp_data->llcp)
- {
- if (llcp_data->invocation)
- {
- GVariant *variant;
+ g_assert(llcp_data != NULL);
+ g_assert(llcp_data->llcp != NULL);
+ g_assert(llcp_data->invocation != NULL);
- variant = net_nfc_util_gdbus_data_to_variant(data);
- net_nfc_gdbus_llcp_complete_receive(
- llcp_data->llcp,
- llcp_data->invocation,
- variant);
-
- g_object_unref(llcp_data->invocation);
- }
+ variant = net_nfc_util_gdbus_data_to_variant(data);
+ net_nfc_gdbus_llcp_complete_receive(
+ llcp_data->llcp,
+ llcp_data->invocation,
+ result,
+ variant);
- g_object_unref(llcp_data->llcp);
- }
+ g_object_unref(llcp_data->invocation);
+ g_object_unref(llcp_data->llcp);
g_free(llcp_data);
}
void *extra,
void *user_param)
{
- LlcpData *llcp_data;
-
- llcp_data = (LlcpData *)user_param;
-
- if (llcp_data == NULL)
- return;
+ LlcpReceiveData *llcp_data = (LlcpReceiveData *)user_param;
+ GVariant *variant;
- if (llcp_data->llcp)
- {
-
- if (llcp_data->invocation)
- {
- GVariant *variant;
-
- variant = net_nfc_util_gdbus_data_to_variant(data);
- net_nfc_gdbus_llcp_complete_receive_from(
- llcp_data->llcp,
- llcp_data->invocation,
- (guint8) (int)extra,
- variant);
+ g_assert(llcp_data != NULL);
+ g_assert(llcp_data->llcp != NULL);
+ g_assert(llcp_data->invocation != NULL);
- g_object_unref(llcp_data->invocation);
- }
+ variant = net_nfc_util_gdbus_data_to_variant(data);
+ net_nfc_gdbus_llcp_complete_receive_from(
+ llcp_data->llcp,
+ llcp_data->invocation,
+ result,
+ (guint8) (int)extra,
+ variant);
- g_object_unref(llcp_data->llcp);
- }
+ g_object_unref(llcp_data->invocation);
+ g_object_unref(llcp_data->llcp);
g_free(llcp_data);
}
void *extra,
void *user_param)
{
- LlcpData *llcp_data;
-
- llcp_data = (LlcpData *)user_param;
-
- if (llcp_data == NULL)
- return;
-
- if (llcp_data->llcp)
- {
+ LlcpDisconnectData *llcp_data = (LlcpDisconnectData *)user_param;
- if (llcp_data->invocation)
- {
- net_nfc_gdbus_llcp_complete_disconnect(
- llcp_data->llcp,
- llcp_data->invocation,
- socket);
+ g_assert(llcp_data != NULL);
+ g_assert(llcp_data->llcp != NULL);
+ g_assert(llcp_data->invocation != NULL);
- g_object_unref(llcp_data->invocation);
- }
+ net_nfc_gdbus_llcp_complete_disconnect(
+ llcp_data->llcp,
+ llcp_data->invocation,
+ result,
+ socket);
- g_object_unref(llcp_data->llcp);
- }
+ g_object_unref(llcp_data->invocation);
+ g_object_unref(llcp_data->llcp);
g_free(llcp_data);
}
static void llcp_handle_config_thread_func(gpointer user_data)
{
+ LlcpConfigData *data = (LlcpConfigData *)user_data;
+ net_nfc_error_e result;
net_nfc_llcp_config_info_s config;
- LlcpConfigData *data = user_data;
-
- if (data == NULL)
- {
- DEBUG_ERR_MSG("can not get LlcpConfigData");
- return;
- }
-
- if (data->llcp == NULL)
- {
- DEBUG_ERR_MSG("can not get llcp");
- if (data->invocation)
- {
- g_dbus_method_invocation_return_dbus_error(
- data->invocation,
- "org.tizen.NetNfcService.ConfigError",
- "can not get llcp");
-
- g_object_unref(data->invocation);
- }
- g_free(data);
- return;
- }
+ g_assert(data != NULL);
+ g_assert(data->llcp != NULL);
+ g_assert(data->invocation != NULL);
config.miu = data->miu;
config.wks = data->wks;
config.lto = data->lto;
config.option = data->option;
- if (net_nfc_server_llcp_set_config(&config) != NET_NFC_OK)
- {
- if (data->invocation)
- {
- g_dbus_method_invocation_return_dbus_error(
- data->invocation,
- "org.tizen.NetNfcService.ConfigError",
- "can not get llcp");
-
- g_object_unref(data->invocation);
- }
-
- g_object_unref(data->llcp);
- g_free(data);
- return;
- }
+ result = net_nfc_server_llcp_set_config(&config);
- if (data->invocation)
- {
- net_nfc_gdbus_llcp_complete_config(data->llcp,
- data->invocation);
-
- g_object_unref(data->invocation);
- }
+ net_nfc_gdbus_llcp_complete_config(data->llcp,
+ data->invocation,
+ result);
+ g_object_unref(data->invocation);
g_object_unref(data->llcp);
- g_free(data);
- return;
+ g_free(data);
}
static void llcp_handle_listen_thread_func(gpointer user_data)
{
- LlcpListenData *data;
- LlcpData *error_data;
+ LlcpListenData *data = (LlcpListenData *)user_data;
+ llcp_client_data *client_data;
net_nfc_llcp_socket_t socket = -1;
- net_nfc_error_e result = NET_NFC_OK;
-
- data = (LlcpListenData *)user_data;
-
- if (data == NULL)
- {
- DEBUG_ERR_MSG("can not get LlcpListenData");
- return;
- }
-
- if (data->llcp == NULL)
- {
- DEBUG_ERR_MSG("can not get llcp");
- if (data->invocation)
- {
- g_dbus_method_invocation_return_dbus_error(
- data->invocation,
- "org.tizen.NetNfcService.ListenError",
- "can not get llcp");
+ net_nfc_error_e result;
- g_object_unref(data->invocation);
- }
+ g_assert(data != NULL);
+ g_assert(data->llcp != NULL);
+ g_assert(data->invocation != NULL);
- g_free(data->service_name);
- g_free(data);
+ client_data = g_try_new0(llcp_client_data, 1);
+ if (client_data == NULL) {
+ result = NET_NFC_ALLOC_FAIL;
- return;
+ goto ERROR;
}
- error_data = g_new0(LlcpData, 1);
- if(error_data == NULL)
- {
- DEBUG_ERR_MSG("Memory allocation failed");
- g_dbus_method_invocation_return_dbus_error(data->invocation,
- "org.tizen.NetNfcService.AllocationError",
- "Can not allocate memory");
- return;
- }
- error_data->llcp = g_object_ref(data->llcp);
- error_data->invocation = g_object_ref(data->invocation);
+ client_data->connection = g_dbus_method_invocation_get_connection(
+ data->invocation);
+ client_data->id = g_strdup(
+ g_dbus_method_invocation_get_sender(data->invocation));
+ client_data->handle = (net_nfc_target_handle_h)data->handle;
if (net_nfc_controller_llcp_create_socket(&socket,
data->type,
data->rw,
&result,
llcp_socket_error_cb,
- error_data) == false)
+ client_data) == false)
{
- DEBUG_ERR_MSG("%s fiailed [%d]",
- "net_nfc_controller_llcp_create_socket" ,result);
-
- if (data->invocation)
- {
- g_dbus_method_invocation_return_dbus_error(
- data->invocation,
- "org.tizen.NetNfcService.ListenError",
- "can not create socket");
-
- g_object_unref(data->invocation);
- }
-
- g_object_unref(data->llcp);
-
- g_free(data->service_name);
- g_free(data);
+ DEBUG_ERR_MSG("net_nfc_controller_llcp_create_socket failed [%d]", result);
- g_free(error_data);
-
- return;
+ goto ERROR;
}
+ client_data->socket = socket;
+
if (net_nfc_controller_llcp_bind(socket,
data->sap,
&result) == false)
{
- DEBUG_ERR_MSG("%s fiailed [%d]",
- "net_nfc_controller_llcp_create_socket" ,result);
-
- if (data->invocation)
- {
- g_dbus_method_invocation_return_dbus_error(
- data->invocation,
- "org.tizen.NetNfcService.ListenError",
- "can not bind socket");
-
- g_object_unref(data->invocation);
- }
-
- g_object_unref(data->llcp);
-
- g_free(data->service_name);
- g_free(data);
-
- g_free(error_data);
-
- if (socket != -1)
- net_nfc_controller_llcp_socket_close(socket, &result);
+ DEBUG_ERR_MSG("net_nfc_controller_llcp_bind failed [%d]", result);
- return;
+ goto ERROR;
}
- DEBUG_SERVER_MSG("OAL socket in Listen : %d\n", socket);
-
if (net_nfc_controller_llcp_listen(GUINT_TO_POINTER(data->handle),
(uint8_t *)data->service_name,
socket,
&result,
- llcp_listen_cb,
- data) == false)
+ llcp_incoming_cb,
+ client_data) == false)
{
- DEBUG_ERR_MSG("%s failed [%d]",
- "net_nfc_controller_llcp_listen",
- result);
+ DEBUG_ERR_MSG("net_nfc_controller_llcp_listen failed [%d]", result);
- if (data->invocation)
- {
- g_dbus_method_invocation_return_dbus_error(
- data->invocation,
- "org.tizen.NetNfcService.ListenError",
- "can not listen socket");
+ goto ERROR;
+ }
- g_object_unref(data->invocation);
- }
+ net_nfc_gdbus_llcp_complete_listen(data->llcp, data->invocation,
+ result,
+ GPOINTER_TO_UINT(socket));
- g_object_unref(data->llcp);
+ g_object_unref(data->invocation);
+ g_object_unref(data->llcp);
- g_free(data->service_name);
- g_free(data);
+ g_free(data);
+
+ return;
- g_free(error_data);
+ERROR :
+ net_nfc_gdbus_llcp_complete_listen(data->llcp, data->invocation,
+ result,
+ -1);
- if (socket != -1)
- net_nfc_controller_llcp_socket_close(socket, &result);
- }
+ if (socket != -1)
+ net_nfc_controller_llcp_socket_close(socket, &result);
+
+ g_free(client_data);
+
+ g_free(data->service_name);
+
+ g_object_unref(data->invocation);
+ g_object_unref(data->llcp);
+
+ g_free(data);
}
-static void llcp_handle_connect_thread_func(gpointer user_data)
+static void llcp_handle_accept_thread_func(gpointer user_data)
{
- LlcpConnectData *data;
- LlcpData *error_data;
+ LlcpAcceptData *data = (LlcpAcceptData *)user_data;
+ llcp_client_data *client_data;
+ net_nfc_error_e result;
- net_nfc_llcp_socket_t socket = -1;
- net_nfc_error_e result = NET_NFC_OK;
+ g_assert(data != NULL);
+ g_assert(data->llcp != NULL);
+ g_assert(data->invocation != NULL);
- data = (LlcpConnectData *)user_data;
+ client_data = g_try_new0(llcp_client_data, 1);
+ if (client_data == NULL) {
+ result = NET_NFC_ALLOC_FAIL;
- if (data == NULL)
- {
- DEBUG_ERR_MSG("can not get LlcpListenData");
- return;
+ goto ERROR;
}
- if (data->llcp == NULL)
- {
- DEBUG_ERR_MSG("can not get llcp");
- if (data->invocation)
- {
- g_dbus_method_invocation_return_dbus_error(
- data->invocation,
- "org.tizen.NetNfcService.ConnectError",
- "can not get llcp");
+ client_data->connection = g_dbus_method_invocation_get_connection(
+ data->invocation);
+ client_data->id = g_strdup(
+ g_dbus_method_invocation_get_sender(data->invocation));
+ client_data->handle = (net_nfc_target_handle_h)data->handle;
+ client_data->socket = data->client_socket;
- g_object_unref(data->invocation);
- }
+ if (net_nfc_controller_llcp_accept(data->client_socket, &result,
+ llcp_socket_error_cb,
+ client_data) == false) {
+ DEBUG_ERR_MSG("net_nfc_controller_llcp_accept failed [%d]", result);
- g_free(data->service_name);
- g_free(data);
+ goto ERROR;
+ }
- return;
+ net_nfc_gdbus_llcp_complete_accept(data->llcp, data->invocation,
+ result);
+
+ g_object_unref(data->invocation);
+ g_object_unref(data->llcp);
+
+ g_free(data);
+
+ return;
+
+ERROR :
+ net_nfc_gdbus_llcp_complete_accept(data->llcp, data->invocation,
+ result);
+
+ g_free(client_data);
+
+ g_object_unref(data->invocation);
+ g_object_unref(data->llcp);
+
+ g_free(data);
+}
+
+static void llcp_handle_reject_thread_func(gpointer user_data)
+{
+ LlcpAcceptData *data = (LlcpAcceptData *)user_data;
+ net_nfc_error_e result;
+
+ g_assert(data != NULL);
+ g_assert(data->llcp != NULL);
+ g_assert(data->invocation != NULL);
+
+ if (net_nfc_controller_llcp_reject(GUINT_TO_POINTER(data->handle),
+ data->client_socket,
+ &result) == false) {
+ DEBUG_ERR_MSG("net_nfc_controller_llcp_reject failed [%d]", result);
}
- error_data = g_new0(LlcpData, 1);
- if(error_data == NULL)
- {
- DEBUG_ERR_MSG("Memory allocation failed");
- g_dbus_method_invocation_return_dbus_error(data->invocation,
- "org.tizen.NetNfcService.AllocationError",
- "Can not allocate memory");
- return;
+ net_nfc_gdbus_llcp_complete_reject(data->llcp, data->invocation,
+ result);
+
+ g_object_unref(data->invocation);
+ g_object_unref(data->llcp);
+
+ g_free(data);
+}
+
+
+static void llcp_handle_connect_thread_func(gpointer user_data)
+{
+ LlcpConnectData *data = (LlcpConnectData *)user_data;
+ llcp_client_data *client_data;
+ net_nfc_llcp_socket_t socket = -1;
+ net_nfc_error_e result;
+
+ g_assert(data != NULL);
+ g_assert(data->llcp != NULL);
+ g_assert(data->invocation != NULL);
+
+ client_data = g_try_new0(llcp_client_data, 1);
+ if (client_data == NULL) {
+ result = NET_NFC_ALLOC_FAIL;
+
+ goto ERROR;
}
- error_data->llcp = g_object_ref(data->llcp);
- error_data->invocation = g_object_ref(data->invocation);
+
+ client_data->connection = g_dbus_method_invocation_get_connection(
+ data->invocation);
+ client_data->id = g_strdup(
+ g_dbus_method_invocation_get_sender(data->invocation));
+ client_data->handle = (net_nfc_target_handle_h)data->handle;
if (net_nfc_controller_llcp_create_socket(&socket,
data->type,
data->rw,
&result,
llcp_socket_error_cb,
- error_data) == false)
+ client_data) == false)
{
- DEBUG_ERR_MSG("%s fiailed [%d]",
- "net_nfc_controller_llcp_create_socket" ,result);
-
- if (data->invocation)
- {
- g_dbus_method_invocation_return_dbus_error(
- data->invocation,
- "org.tizen.NetNfcService.ConnectError",
- "can not create socket");
+ DEBUG_ERR_MSG("net_nfc_controller_llcp_create_socket failed [%d]", result);
- g_object_unref(data->invocation);
- }
-
- g_object_unref(data->llcp);
-
- g_free(data->service_name);
- g_free(data);
-
- g_free(error_data);
-
- return;
+ goto ERROR;
}
- DEBUG_SERVER_MSG("OAL socket in Listen :%d", socket);
+ client_data->socket = socket;
if (net_nfc_controller_llcp_connect_by_url(
GUINT_TO_POINTER(data->handle),
llcp_connect_by_url_cb,
data) == false)
{
- DEBUG_ERR_MSG("%s failed, [%d]",
- "net_nfc_controller_llcp_connect_by_url",
- result);
+ DEBUG_ERR_MSG("net_nfc_controller_llcp_listen failed [%d]", result);
- if (data->invocation)
- {
- g_dbus_method_invocation_return_dbus_error(
- data->invocation,
- "org.tizen.NetNfcService.ConnectError",
- "can not listen socket");
+ goto ERROR;
+ }
- g_object_unref(data->invocation);
- }
+ g_object_unref(data->invocation);
+ g_object_unref(data->llcp);
- g_object_unref(data->llcp);
+ g_free(data);
- g_free(data->service_name);
- g_free(data);
+ return;
- g_free(error_data);
+ERROR :
+ net_nfc_gdbus_llcp_complete_connect(data->llcp, data->invocation,
+ result,
+ -1);
- if (socket != -1)
- net_nfc_controller_llcp_socket_close(socket, &result);
- }
+ if (socket != -1)
+ net_nfc_controller_llcp_socket_close(socket, &result);
+
+ g_free(client_data);
+
+ g_free(data->service_name);
+
+ g_object_unref(data->invocation);
+ g_object_unref(data->llcp);
+
+ g_free(data);
}
static void llcp_handle_connect_sap_thread_func(gpointer user_data)
{
- LlcpConnectSapData *data;
- LlcpData *error_data;
+ LlcpConnectSapData *data = (LlcpConnectSapData *)user_data;
+ llcp_client_data *client_data;
net_nfc_llcp_socket_t socket = -1;
net_nfc_error_e result = NET_NFC_OK;
- data = (LlcpConnectSapData *)user_data;
-
- if (data == NULL)
- {
- DEBUG_ERR_MSG("can not get LlcpConnectSapData");
- return;
- }
-
- if (data->llcp == NULL)
- {
- DEBUG_ERR_MSG("can not get llcp");
- if (data->invocation)
- {
- g_dbus_method_invocation_return_dbus_error(
- data->invocation,
- "org.tizen.NetNfcService.ConnectSapError",
- "can not get llcp");
-
- g_object_unref(data->invocation);
- }
+ g_assert(data != NULL);
+ g_assert(data->llcp != NULL);
+ g_assert(data->invocation != NULL);
- g_free(data);
+ client_data = g_try_new0(llcp_client_data, 1);
+ if (client_data == NULL) {
+ result = NET_NFC_ALLOC_FAIL;
- return;
+ goto ERROR;
}
- error_data = g_new0(LlcpData, 1);
- if(error_data == NULL)
- {
- DEBUG_ERR_MSG("Memory allocation failed");
- g_dbus_method_invocation_return_dbus_error(data->invocation,
- "org.tizen.NetNfcService.AllocationError",
- "Can not allocate memory");
- return;
- }
- error_data->llcp = g_object_ref(data->llcp);
- error_data->invocation = g_object_ref(data->invocation);
+ client_data->connection = g_dbus_method_invocation_get_connection(
+ data->invocation);
+ client_data->id = g_strdup(
+ g_dbus_method_invocation_get_sender(data->invocation));
+ client_data->handle = (net_nfc_target_handle_h)data->handle;
if (net_nfc_controller_llcp_create_socket(&socket,
data->type,
data->rw,
&result,
llcp_socket_error_cb,
- error_data) == false)
+ client_data) == false)
{
- DEBUG_ERR_MSG("%s fiailed [%d]",
- "net_nfc_controller_llcp_create_socket" ,result);
-
- if (data->invocation)
- {
- g_dbus_method_invocation_return_dbus_error(
- data->invocation,
- "org.tizen.NetNfcService.ConnectSapError",
- "can not create socket");
-
- g_object_unref(data->invocation);
- }
-
- g_object_unref(data->llcp);
-
- g_free(data);
-
- g_free(error_data);
+ DEBUG_ERR_MSG("net_nfc_controller_llcp_create_socket failed [%d]", result);
- return;
+ goto ERROR;
}
- DEBUG_SERVER_MSG("OAL socket in Listen :%d", socket);
+ client_data->socket = socket;
if (net_nfc_controller_llcp_connect(GUINT_TO_POINTER(data->handle),
socket,
llcp_connect_cb,
data) == false)
{
- DEBUG_ERR_MSG("%s failed, [%d]",
- "net_nfc_controller_llcp_connect",
- result);
+ DEBUG_ERR_MSG("net_nfc_controller_llcp_listen failed [%d]", result);
- if (data->invocation)
- {
- g_dbus_method_invocation_return_dbus_error(
- data->invocation,
- "org.tizen.NetNfcService.ConnectSapError",
- "can not connect socket");
+ goto ERROR;
+ }
- g_object_unref(data->invocation);
- }
+ g_object_unref(data->invocation);
+ g_object_unref(data->llcp);
- g_object_unref(data->llcp);
+ g_free(data);
- g_free(data);
+ return;
- g_free(error_data);
+ERROR :
+ net_nfc_gdbus_llcp_complete_connect_sap(data->llcp, data->invocation,
+ result,
+ -1);
- if (socket != -1)
- net_nfc_controller_llcp_socket_close(socket, &result);
+ if (socket != -1)
+ net_nfc_controller_llcp_socket_close(socket, &result);
- }
+ g_free(client_data);
+
+ g_object_unref(data->invocation);
+ g_object_unref(data->llcp);
+
+ g_free(data);
}
static void llcp_handle_send_thread_func(gpointer user_data)
{
- LlcpSendData *data;
- LlcpData *llcp_data;
-
- net_nfc_error_e result = NET_NFC_OK;
+ LlcpSendData *data = (LlcpSendData *)user_data;
+ net_nfc_error_e result;
- data = (LlcpSendData *)user_data;
+ g_assert(data != NULL);
+ g_assert(data->llcp != NULL);
+ g_assert(data->invocation != NULL);
- if (data == NULL)
+ if (net_nfc_controller_llcp_send(GUINT_TO_POINTER(data->handle),
+ data->client_socket,
+ &data->data,
+ &result,
+ llcp_send_cb,
+ data) == false)
{
- DEBUG_ERR_MSG("can not get LlcpSendData");
- return;
- }
+ DEBUG_ERR_MSG("net_nfc_controller_llcp_send failed [%d]", result);
- if (data->llcp == NULL)
- {
- DEBUG_ERR_MSG("can not get llcp");
- if (data->invocation)
- {
- g_dbus_method_invocation_return_dbus_error(
- data->invocation,
- "org.tizen.NetNfcService.SendError",
- "can not get llcp");
+ net_nfc_gdbus_llcp_complete_send(data->llcp,
+ data->invocation,
+ result,
+ data->client_socket);
- g_object_unref(data->invocation);
- }
+ net_nfc_util_free_data(&data->data);
- if (data->data)
- {
- g_free(data->data->buffer);
- g_free(data->data);
- }
+ g_object_unref(data->invocation);
+ g_object_unref(data->llcp);
g_free(data);
-
- return;
}
+}
- llcp_data = g_new0(LlcpData, 1);
- if(llcp_data == NULL)
- {
- DEBUG_ERR_MSG("Memory allocation failed");
- g_dbus_method_invocation_return_dbus_error(data->invocation,
- "org.tizen.NetNfcService.AllocationError",
- "Can not allocate memory");
- return;
- }
- llcp_data->llcp = g_object_ref(data->llcp);
- llcp_data->invocation = g_object_ref(data->invocation);
+static void llcp_handle_send_to_thread_func(gpointer user_data)
+{
+ LlcpSendToData *data = (LlcpSendToData *)user_data;
+ net_nfc_error_e result;
- if (net_nfc_controller_llcp_send(GUINT_TO_POINTER(data->handle),
- data->oal_socket,
- data->data,
+ g_assert(data != NULL);
+ g_assert(data->llcp != NULL);
+ g_assert(data->invocation != NULL);
+
+ if (net_nfc_controller_llcp_send_to(GUINT_TO_POINTER(data->handle),
+ data->client_socket,
+ &data->data,
+ data->sap,
&result,
- llcp_send_cb,
- llcp_data) == false)
+ llcp_send_to_cb,
+ data) == false)
{
- DEBUG_ERR_MSG("%s failed, [%d]",
- "net_nfc_controller_llcp_send",
- result);
+ DEBUG_ERR_MSG("net_nfc_controller_llcp_send_to failed [%d]", result);
- if (data->invocation)
- {
- g_dbus_method_invocation_return_dbus_error(
- data->invocation,
- "org.tizen.NetNfcService.SendError",
- "can not send socket");
+ net_nfc_gdbus_llcp_complete_send_to(data->llcp,
+ data->invocation,
+ result,
+ data->client_socket);
- g_object_unref(data->invocation);
- }
+ net_nfc_util_free_data(&data->data);
+ g_object_unref(data->invocation);
g_object_unref(data->llcp);
- if (data->data)
- {
- g_free(data->data->buffer);
- g_free(data->data);
- }
-
g_free(data);
-
- g_free(llcp_data);
-
- return;
- }
-
- g_object_unref(data->llcp);
- g_object_unref(data->invocation);
-
- if (data->data)
- {
- g_free(data->data->buffer);
- g_free(data->data);
}
-
- g_free(data);
-
- g_free(llcp_data);
}
-static void llcp_handle_send_to_thread_func(gpointer user_data)
+static void llcp_handle_receive_thread_func(gpointer user_data)
{
- LlcpSendToData *data;
- LlcpData *llcp_data;
-
- net_nfc_error_e result = NET_NFC_OK;
-
- data = (LlcpSendToData *)user_data;
+ LlcpReceiveData *data = (LlcpReceiveData *)user_data;
+ net_nfc_error_e result;
- if (data == NULL)
- {
- DEBUG_ERR_MSG("can not get LlcpSendToData");
- return;
- }
+ g_assert(data != NULL);
+ g_assert(data->llcp != NULL);
+ g_assert(data->invocation != NULL);
- if (data->llcp == NULL)
+ if (net_nfc_controller_llcp_recv(GUINT_TO_POINTER(data->handle),
+ data->client_socket,
+ data->req_length,
+ &result,
+ llcp_receive_cb,
+ data) == false)
{
- DEBUG_ERR_MSG("can not get llcp");
- if (data->invocation)
- {
- g_dbus_method_invocation_return_dbus_error(
- data->invocation,
- "org.tizen.NetNfcService.SendToError",
- "can not get llcp");
+ DEBUG_ERR_MSG("net_nfc_controller_llcp_recv failed [%d]", result);
- g_object_unref(data->invocation);
- }
+ net_nfc_gdbus_llcp_complete_receive(data->llcp,
+ data->invocation,
+ result,
+ net_nfc_util_gdbus_buffer_to_variant(NULL, 0));
- if (data->data)
- {
- g_free(data->data->buffer);
- g_free(data->data);
- }
+ g_object_unref(data->invocation);
+ g_object_unref(data->llcp);
g_free(data);
-
- return;
}
+}
- llcp_data = g_new0(LlcpData, 1);
- if(llcp_data == NULL)
- {
- DEBUG_ERR_MSG("Memory allocation failed");
- g_dbus_method_invocation_return_dbus_error(data->invocation,
- "org.tizen.NetNfcService.AllocationError",
- "Can not allocate memory");
- return;
- }
- llcp_data->llcp = g_object_ref(data->llcp);
- llcp_data->invocation = g_object_ref(data->invocation);
+static void llcp_handle_receive_from_thread_func(gpointer user_data)
+{
+ LlcpReceiveData *data = (LlcpReceiveData *)user_data;
+ net_nfc_error_e result;
- if (net_nfc_controller_llcp_send_to(GUINT_TO_POINTER(data->handle),
- data->oal_socket,
- data->data,
- data->sap,
+ g_assert(data != NULL);
+ g_assert(data->llcp != NULL);
+ g_assert(data->invocation != NULL);
+
+ if (net_nfc_controller_llcp_recv_from(GUINT_TO_POINTER(data->handle),
+ data->client_socket,
+ data->req_length,
&result,
- llcp_send_cb,
- llcp_data) == false)
+ llcp_receive_from_cb,
+ data) == false)
{
- DEBUG_ERR_MSG("%s failed, [%d]",
- "net_nfc_controller_llcp_send_to",
- result);
-
- if (data->invocation)
- {
- g_dbus_method_invocation_return_dbus_error(
- data->invocation,
- "org.tizen.NetNfcService.SendToError",
- "can not send socket");
+ DEBUG_ERR_MSG("net_nfc_controller_llcp_recv_from failed [%d]", result);
- g_object_unref(data->invocation);
- }
+ net_nfc_gdbus_llcp_complete_receive_from(data->llcp,
+ data->invocation,
+ result,
+ -1,
+ net_nfc_util_gdbus_buffer_to_variant(NULL, 0));
+ g_object_unref(data->invocation);
g_object_unref(data->llcp);
- if (data->data)
- {
- g_free(data->data->buffer);
- g_free(data->data);
- }
-
g_free(data);
-
- g_free(llcp_data);
-
- return;
}
+}
- g_object_unref(data->llcp);
- g_object_unref(data->invocation);
+static void llcp_handle_close_thread_func(gpointer user_data)
+{
+ LlcpCloseData *data = (LlcpCloseData *)user_data;
+ net_nfc_error_e result;
- if (data->data)
- {
- g_free(data->data->buffer);
- g_free(data->data);
- }
+ g_assert(data != NULL);
+ g_assert(data->llcp != NULL);
+ g_assert(data->invocation != NULL);
- g_free(data);
+ net_nfc_controller_llcp_socket_close(data->client_socket, &result);
- g_free(llcp_data);
+ net_nfc_gdbus_llcp_complete_close(data->llcp,
+ data->invocation,
+ result,
+ data->client_socket);
}
-static void llcp_handle_receive_thread_func(gpointer user_data)
+static void llcp_handle_disconnect_thread_func(gpointer user_data)
{
- LlcpReceiveData *data;
- LlcpData *llcp_data;
-
- net_nfc_error_e result = NET_NFC_OK;
+ LlcpDisconnectData *data = (LlcpDisconnectData *)user_data;
+ net_nfc_error_e result;
- data = (LlcpReceiveData *)user_data;
+ g_assert(data != NULL);
+ g_assert(data->llcp != NULL);
+ g_assert(data->invocation != NULL);
- if (data == NULL)
+ if (GUINT_TO_POINTER(data->handle) == 0)
{
- DEBUG_ERR_MSG("can not get LlcpReceiveData");
- return;
+ int ret_val;
+
+ net_nfc_server_free_target_info();
+ ret_val = pm_unlock_state(LCD_NORMAL, PM_RESET_TIMER);
+ DEBUG_SERVER_MSG("net_nfc_controller_disconnect pm_unlock_state"
+ "[%d]!!", ret_val);
}
- if (data->llcp == NULL)
+ if (net_nfc_controller_llcp_disconnect(GUINT_TO_POINTER(data->handle),
+ data->client_socket,
+ &result,
+ llcp_disconnect_cb,
+ data) == false)
{
- DEBUG_ERR_MSG("can not get llcp");
- if (data->invocation)
- {
- g_dbus_method_invocation_return_dbus_error(
- data->invocation,
- "org.tizen.NetNfcService.ReceiveError",
- "can not get llcp");
+ DEBUG_ERR_MSG("net_nfc_controller_llcp_disconnect failed [%d]", result);
- g_object_unref(data->invocation);
- }
-
- g_free(data);
-
- return;
- }
-
- llcp_data = g_new0(LlcpData, 1);
- if(llcp_data == NULL)
- {
- DEBUG_ERR_MSG("Memory allocation failed");
- g_dbus_method_invocation_return_dbus_error(data->invocation,
- "org.tizen.NetNfcService.AllocationError",
- "Can not allocate memory");
- return;
- }
- llcp_data->llcp = g_object_ref(data->llcp);
- llcp_data->invocation = g_object_ref(data->invocation);
-
- if (net_nfc_controller_llcp_recv(GUINT_TO_POINTER(data->handle),
- data->oal_socket,
- data->req_length,
- &result,
- llcp_receive_cb,
- llcp_data) == false)
- {
- DEBUG_ERR_MSG("%s failed, [%d]",
- "net_nfc_controller_llcp_receive",
- result);
-
- if (data->invocation)
- {
- g_dbus_method_invocation_return_dbus_error(
- data->invocation,
- "org.tizen.NetNfcService.ReceiveError",
- "can not receive");
-
- g_object_unref(data->invocation);
- }
-
- g_object_unref(data->llcp);
- g_free(data);
-
- g_free(llcp_data);
-
- return;
- }
-
- g_object_unref(data->llcp);
- g_object_unref(data->invocation);
-
- g_free(data);
-
- g_free(llcp_data);
-}
-
-static void llcp_handle_receive_from_thread_func(gpointer user_data)
-{
- LlcpReceiveData *data;
- LlcpData *llcp_data;
-
- net_nfc_error_e result = NET_NFC_OK;
-
- data = (LlcpReceiveData *)user_data;
-
- if (data == NULL)
- {
- DEBUG_ERR_MSG("can not get LlcpReceiveData");
- return;
- }
-
- if (data->llcp == NULL)
- {
- DEBUG_ERR_MSG("can not get llcp");
- if (data->invocation)
- {
- g_dbus_method_invocation_return_dbus_error(
- data->invocation,
- "org.tizen.NetNfcService.ReceiveFromError",
- "can not get llcp");
-
- g_object_unref(data->invocation);
- }
-
- g_free(data);
-
- return;
- }
-
- llcp_data = g_new0(LlcpData, 1);
- if(llcp_data == NULL)
- {
- DEBUG_ERR_MSG("Memory allocation failed");
- g_dbus_method_invocation_return_dbus_error(data->invocation,
- "org.tizen.NetNfcService.AllocationError",
- "Can not allocate memory");
- return;
- }
- llcp_data->llcp = g_object_ref(data->llcp);
- llcp_data->invocation = g_object_ref(data->invocation);
-
- if (net_nfc_controller_llcp_recv_from(GUINT_TO_POINTER(data->handle),
- data->oal_socket,
- data->req_length,
- &result,
- llcp_receive_from_cb,
- llcp_data) == false)
- {
- DEBUG_ERR_MSG("%s failed, [%d]",
- "net_nfc_controller_llcp_receive",
- result);
-
- if (data->invocation)
- {
- g_dbus_method_invocation_return_dbus_error(
- data->invocation,
- "org.tizen.NetNfcService.ReceiveFromError",
- "can not receive");
-
- g_object_unref(data->invocation);
- }
+ net_nfc_gdbus_llcp_complete_disconnect(data->llcp,
+ data->invocation,
+ result,
+ data->client_socket);
+ g_object_unref(data->invocation);
g_object_unref(data->llcp);
- g_free(data);
-
- g_free(llcp_data);
-
- return;
- }
-
- g_object_unref(data->llcp);
- g_object_unref(data->invocation);
-
- g_free(data);
-
- g_free(llcp_data);
-}
-
-static void llcp_handle_close_thread_func(gpointer user_data)
-{
- LlcpCloseData *data;
-
- net_nfc_error_e result = NET_NFC_OK;
-
- data = (LlcpCloseData *)user_data;
-
- if (data == NULL)
- {
- DEBUG_ERR_MSG("can not get LlcpCloseData");
- return;
- }
-
- if (data->llcp == NULL)
- {
- DEBUG_ERR_MSG("can not get llcp");
- if (data->invocation)
- {
- g_dbus_method_invocation_return_dbus_error(
- data->invocation,
- "org.tizen.NetNfcService.CloseError",
- "can not get llcp");
-
- g_object_unref(data->invocation);
- }
-
- g_free(data);
-
- return;
- }
-
- net_nfc_controller_llcp_socket_close(data->oal_socket,
- &result);
-
- net_nfc_gdbus_llcp_complete_close(data->llcp,
- data->invocation,
- data->client_socket);
-}
-
-static void llcp_handle_disconnect_thread_func(gpointer user_data)
-{
- LlcpDisconnectData *data;
- LlcpData *llcp_data;
- int ret_val = 0;
-
- net_nfc_error_e result = NET_NFC_OK;
-
- data = (LlcpDisconnectData *)user_data;
-
- if (data == NULL)
- {
- DEBUG_ERR_MSG("can not get LlcpDisconnectData");
- return;
- }
-
- if (data->llcp == NULL)
- {
- DEBUG_ERR_MSG("can not get llcp");
- if (data->invocation)
- {
- g_dbus_method_invocation_return_dbus_error(
- data->invocation,
- "org.tizen.NetNfcService.DisconnectError",
- "can not get llcp");
-
- g_object_unref(data->invocation);
- }
-
- g_free(data);
-
- return;
- }
-
- if(GUINT_TO_POINTER(data->handle) == 0)
- {
- net_nfc_server_free_target_info();
- ret_val = pm_unlock_state(LCD_NORMAL, PM_RESET_TIMER);
- DEBUG_SERVER_MSG("net_nfc_controller_disconnect pm_unlock_state"
- "[%d]!!", ret_val);
- }
-
- llcp_data = g_new0(LlcpData, 1);
- if(llcp_data == NULL)
- {
- DEBUG_ERR_MSG("Memory allocation failed");
- return;
- }
- llcp_data->llcp = g_object_ref(data->llcp);
- llcp_data->invocation = g_object_ref(data->invocation);
-
- if (net_nfc_controller_llcp_disconnect(GUINT_TO_POINTER(data->handle),
- data->oal_socket,
- &result,
- llcp_disconnect_cb,
- llcp_data) == false)
- {
- DEBUG_ERR_MSG("%s failed, [%d]",
- "net_nfc_controller_llcp_receive",
- result);
-
- if (data->invocation)
- {
- g_dbus_method_invocation_return_dbus_error(
- data->invocation,
- "org.tizen.NetNfcService.DisconnectError",
- "can not disconnect socket");
-
- g_object_unref(data->invocation);
- }
- g_object_unref(data->llcp);
g_free(data);
-
- g_free(llcp_data);
-
- return;
}
-
- g_object_unref(data->llcp);
- g_object_unref(data->invocation);
-
- g_free(data);
-
- g_free(llcp_data);
}
GVariant *smack_privilege,
gpointer user_data)
{
+ gboolean result;
LlcpConfigData *data;
INFO_MSG(">>> REQUEST from [%s]",
"w") == false) {
DEBUG_ERR_MSG("permission denied, and finished request");
- return TRUE;
+ return FALSE;
}
- data = g_new0(LlcpConfigData, 1);
- if(data == NULL)
- {
- DEBUG_ERR_MSG("Memory allocation failed");
+ data = g_try_new0(LlcpConfigData, 1);
+ if (data == NULL) {
g_dbus_method_invocation_return_dbus_error(invocation,
"org.tizen.NetNfcService.AllocationError",
"Can not allocate memory");
+
return FALSE;
}
+
data->llcp = g_object_ref(llcp);
data->invocation = g_object_ref(invocation);
&data->lto,
&data->option);
- if (net_nfc_server_controller_async_queue_push(
- llcp_handle_config_thread_func,
- data) == FALSE)
+ result = net_nfc_server_controller_async_queue_push(
+ llcp_handle_config_thread_func,
+ data);
+ if (result == FALSE)
{
g_dbus_method_invocation_return_dbus_error(invocation,
- "org.tizen.NetNfcService.ThreadError",
+ "org.tizen.NetNfcService.Llcp.ThreadError",
"can not push to controller thread");
- g_object_unref(data->llcp);
+
g_object_unref(data->invocation);
+ g_object_unref(data->llcp);
g_free(data);
-
- return FALSE;
}
- return TRUE;
+ return result;
}
static gboolean llcp_handle_listen(NetNfcGDbusLlcp *llcp,
GDBusMethodInvocation *invocation,
guint32 arg_handle,
guint32 arg_client_socket,
- guint32 arg_oal_socket,
guint16 arg_miu,
guint8 arg_rw,
gint32 arg_type,
GVariant *smack_privilege,
gpointer user_data)
{
+ gboolean result;
LlcpListenData *data;
INFO_MSG(">>> REQUEST from [%s]",
"rw") == false) {
DEBUG_ERR_MSG("permission denied, and finished request");
- return TRUE;
+ return FALSE;
}
- data = g_new0(LlcpListenData, 1);
- if(data == NULL)
- {
- DEBUG_ERR_MSG("Memory allocation failed");
+ data = g_try_new0(LlcpListenData, 1);
+ if (data == NULL) {
g_dbus_method_invocation_return_dbus_error(invocation,
"org.tizen.NetNfcService.AllocationError",
"Can not allocate memory");
+
return FALSE;
}
+
data->llcp = g_object_ref(llcp);
data->invocation = g_object_ref(invocation);
data->handle = arg_handle;
data->client_socket = arg_client_socket;
- data->oal_socket = arg_oal_socket;
data->miu = arg_miu;
data->rw = arg_rw;
data->type = arg_type;
data->sap = arg_sap;
data->service_name = g_strdup(arg_service_name);
- if (net_nfc_server_controller_async_queue_push(
- llcp_handle_listen_thread_func,
- data) == FALSE)
+ result = net_nfc_server_controller_async_queue_push(
+ llcp_handle_listen_thread_func,
+ data);
+ if (result == FALSE)
{
g_dbus_method_invocation_return_dbus_error(invocation,
- "org.tizen.NetNfcService.ThreadError",
+ "org.tizen.NetNfcService.Llcp.ThreadError",
"can not push to controller thread");
- g_object_unref(data->llcp);
+ g_free(data->service_name);
+
g_object_unref(data->invocation);
+ g_object_unref(data->llcp);
- g_free(data->service_name);
g_free(data);
-
- return FALSE;
}
- return TRUE;
+ return result;
}
-static gboolean llcp_handle_connect(NetNfcGDbusLlcp *llcp,
+static gboolean llcp_handle_accept(NetNfcGDbusLlcp *llcp,
GDBusMethodInvocation *invocation,
guint32 arg_handle,
guint32 arg_client_socket,
- guint32 arg_oal_socket,
- guint16 arg_miu,
- guint8 arg_rw,
- gint32 arg_type,
- const gchar *arg_service_name,
GVariant *smack_privilege,
gpointer user_data)
{
- LlcpConnectData *data;
+ gboolean result;
+ LlcpAcceptData *data;
INFO_MSG(">>> REQUEST from [%s]",
g_dbus_method_invocation_get_sender(invocation));
"rw") == false) {
DEBUG_ERR_MSG("permission denied, and finished request");
- return TRUE;
+ return FALSE;
}
- data = g_new0(LlcpConnectData, 1);
- if(data == NULL)
- {
- DEBUG_ERR_MSG("Memory allocation failed");
+ data = g_try_new0(LlcpAcceptData, 1);
+ if (data == NULL) {
g_dbus_method_invocation_return_dbus_error(invocation,
- "org.tizen.NetNfcService.AllocationError",
- "Can not allocate memory");
+ "org.tizen.NetNfcService.Llcp.MemoryError",
+ "Out of memory");
+
return FALSE;
}
+
data->llcp = g_object_ref(llcp);
data->invocation = g_object_ref(invocation);
data->handle = arg_handle;
data->client_socket = arg_client_socket;
- data->oal_socket = arg_oal_socket;
- data->miu = arg_miu;
- data->rw = arg_rw;
- data->type = arg_type;
- data->service_name = g_strdup(arg_service_name);
- if (net_nfc_server_controller_async_queue_push(
- llcp_handle_connect_thread_func,
- data) == FALSE)
+ result = net_nfc_server_controller_async_queue_push(
+ llcp_handle_accept_thread_func,
+ data);
+ if (result == FALSE)
{
g_dbus_method_invocation_return_dbus_error(invocation,
- "org.tizen.NetNfcService.ThreadError",
+ "org.tizen.NetNfcService.Llcp.ThreadError",
"can not push to controller thread");
- g_object_unref(data->llcp);
g_object_unref(data->invocation);
+ g_object_unref(data->llcp);
- g_free(data->service_name);
g_free(data);
-
- return FALSE;
}
- return TRUE;
+ return result;
}
-static gboolean llcp_handle_connect_sap(NetNfcGDbusLlcp *llcp,
+static gboolean llcp_handle_reject(NetNfcGDbusLlcp *llcp,
GDBusMethodInvocation *invocation,
guint32 arg_handle,
guint32 arg_client_socket,
- guint32 arg_oal_socket,
- guint16 arg_miu,
- guint8 arg_rw,
- gint32 arg_type,
- guint8 arg_sap,
GVariant *smack_privilege,
gpointer user_data)
{
- LlcpConnectSapData *data;
+ gboolean result;
+ LlcpAcceptData *data;
INFO_MSG(">>> REQUEST from [%s]",
g_dbus_method_invocation_get_sender(invocation));
"rw") == false) {
DEBUG_ERR_MSG("permission denied, and finished request");
- return TRUE;
+ return FALSE;
}
- data = g_new0(LlcpConnectSapData, 1);
- if(data == NULL)
- {
- DEBUG_ERR_MSG("Memory allocation failed");
+ data = g_try_new0(LlcpAcceptData, 1);
+ if (data == NULL) {
g_dbus_method_invocation_return_dbus_error(invocation,
- "org.tizen.NetNfcService.AllocationError",
- "Can not allocate memory");
+ "org.tizen.NetNfcService.Llcp.MemoryError",
+ "Out of memory");
+
return FALSE;
}
+
data->llcp = g_object_ref(llcp);
data->invocation = g_object_ref(invocation);
data->handle = arg_handle;
data->client_socket = arg_client_socket;
- data->oal_socket = arg_oal_socket;
- data->miu = arg_miu;
- data->rw = arg_rw;
- data->type = arg_type;
- data->sap = arg_sap;
- if(net_nfc_server_controller_async_queue_push(
- llcp_handle_connect_sap_thread_func,
- data) == FALSE)
+ result = net_nfc_server_controller_async_queue_push(
+ llcp_handle_reject_thread_func,
+ data);
+ if (result == FALSE)
{
g_dbus_method_invocation_return_dbus_error(invocation,
- "org.tizen.NetNfcService.ThreadError",
+ "org.tizen.NetNfcService.Llcp.ThreadError",
"can not push to controller thread");
- g_object_unref(data->llcp);
g_object_unref(data->invocation);
+ g_object_unref(data->llcp);
g_free(data);
-
- return FALSE;
}
- return TRUE;
+ return result;
}
-static gboolean llcp_handle_send(NetNfcGDbusLlcp *llcp,
+static gboolean llcp_handle_connect(NetNfcGDbusLlcp *llcp,
GDBusMethodInvocation *invocation,
guint32 arg_handle,
guint32 arg_client_socket,
- guint32 arg_oal_socket,
- GVariant *arg_data,
+ guint16 arg_miu,
+ guint8 arg_rw,
+ gint32 arg_type,
+ const gchar *arg_service_name,
GVariant *smack_privilege,
gpointer user_data)
{
- LlcpSendData *data;
+ gboolean result;
+ LlcpConnectData *data;
INFO_MSG(">>> REQUEST from [%s]",
g_dbus_method_invocation_get_sender(invocation));
if (net_nfc_server_gdbus_check_privilege(invocation,
smack_privilege,
"nfc-manager::p2p",
- "w") == false) {
+ "rw") == false) {
DEBUG_ERR_MSG("permission denied, and finished request");
- return TRUE;
+ return FALSE;
}
- data = g_new0(LlcpSendData, 1);
- if(data == NULL)
- {
- DEBUG_ERR_MSG("Memory allocation failed");
+ data = g_try_new0(LlcpConnectData, 1);
+ if (data == NULL) {
g_dbus_method_invocation_return_dbus_error(invocation,
"org.tizen.NetNfcService.AllocationError",
"Can not allocate memory");
+
return FALSE;
}
+
data->llcp = g_object_ref(llcp);
data->invocation = g_object_ref(invocation);
data->handle = arg_handle;
data->client_socket = arg_client_socket;
- data->oal_socket = arg_oal_socket;
-
- data->data = net_nfc_util_gdbus_variant_to_data(arg_data);
+ data->miu = arg_miu;
+ data->rw = arg_rw;
+ data->type = arg_type;
+ data->service_name = g_strdup(arg_service_name);
- if (net_nfc_server_controller_async_queue_push(
- llcp_handle_send_thread_func,
- data) == FALSE)
+ result = net_nfc_server_controller_async_queue_push(
+ llcp_handle_connect_thread_func,
+ data);
+ if (result == FALSE)
{
g_dbus_method_invocation_return_dbus_error(invocation,
- "org.tizen.NetNfcService.ThreadError",
+ "org.tizen.NetNfcService.Llcp.ThreadError",
"can not push to controller thread");
- g_object_unref(data->llcp);
- g_object_unref(data->invocation);
+ g_free(data->service_name);
- if (data->data != NULL)
- {
- g_free(data->data->buffer);
- g_free(data->data);
- }
+ g_object_unref(data->invocation);
+ g_object_unref(data->llcp);
g_free(data);
-
- return FALSE;
}
- return TRUE;
+ return result;
}
-static gboolean llcp_handle_send_to(NetNfcGDbusLlcp *llcp,
+static gboolean llcp_handle_connect_sap(NetNfcGDbusLlcp *llcp,
GDBusMethodInvocation *invocation,
guint32 arg_handle,
guint32 arg_client_socket,
- guint32 arg_oal_socket,
+ guint16 arg_miu,
+ guint8 arg_rw,
+ gint32 arg_type,
guint8 arg_sap,
- GVariant *arg_data,
GVariant *smack_privilege,
gpointer user_data)
{
- LlcpSendToData *data;
+ gboolean result;
+ LlcpConnectSapData *data;
INFO_MSG(">>> REQUEST from [%s]",
g_dbus_method_invocation_get_sender(invocation));
"rw") == false) {
DEBUG_ERR_MSG("permission denied, and finished request");
- return TRUE;
+ return FALSE;
}
- data = g_new0(LlcpSendToData, 1);
- if(data == NULL)
- {
- DEBUG_ERR_MSG("Memory allocation failed");
+ data = g_try_new0(LlcpConnectSapData, 1);
+ if (data == NULL) {
g_dbus_method_invocation_return_dbus_error(invocation,
"org.tizen.NetNfcService.AllocationError",
"Can not allocate memory");
+
return FALSE;
}
+
data->llcp = g_object_ref(llcp);
data->invocation = g_object_ref(invocation);
data->handle = arg_handle;
data->client_socket = arg_client_socket;
- data->oal_socket = arg_oal_socket;
+ data->miu = arg_miu;
+ data->rw = arg_rw;
+ data->type = arg_type;
data->sap = arg_sap;
- data->data = net_nfc_util_gdbus_variant_to_data(arg_data);
-
- if(net_nfc_server_controller_async_queue_push(
- llcp_handle_send_to_thread_func,
- data) == FALSE)
+ result = net_nfc_server_controller_async_queue_push(
+ llcp_handle_connect_sap_thread_func,
+ data);
+ if (result == FALSE)
{
g_dbus_method_invocation_return_dbus_error(invocation,
- "org.tizen.NetNfcService.ThreadError",
+ "org.tizen.NetNfcService.Llcp.ThreadError",
"can not push to controller thread");
- g_object_unref(data->llcp);
g_object_unref(data->invocation);
-
- if (data->data != NULL)
- {
- g_free(data->data->buffer);
- g_free(data->data);
- }
+ g_object_unref(data->llcp);
g_free(data);
-
- return FALSE;
}
- return TRUE;
+ return result;
}
-static gboolean llcp_handle_receive(NetNfcGDbusLlcp *llcp,
+static gboolean llcp_handle_send(NetNfcGDbusLlcp *llcp,
GDBusMethodInvocation *invocation,
guint32 arg_handle,
guint32 arg_client_socket,
- guint32 arg_oal_socket,
- guint32 arg_req_length,
+ GVariant *arg_data,
GVariant *smack_privilege,
gpointer user_data)
{
- LlcpReceiveData *data;
+ gboolean result;
+ LlcpSendData *data;
INFO_MSG(">>> REQUEST from [%s]",
g_dbus_method_invocation_get_sender(invocation));
"w") == false) {
DEBUG_ERR_MSG("permission denied, and finished request");
- return TRUE;
+ return FALSE;
}
- data = g_new0(LlcpReceiveData, 1);
- if(data == NULL)
- {
- DEBUG_ERR_MSG("Memory allocation failed");
+ data = g_try_new0(LlcpSendData, 1);
+ if (data == NULL) {
g_dbus_method_invocation_return_dbus_error(invocation,
"org.tizen.NetNfcService.AllocationError",
"Can not allocate memory");
+
return FALSE;
}
+
data->llcp = g_object_ref(llcp);
data->invocation = g_object_ref(invocation);
data->handle = arg_handle;
data->client_socket = arg_client_socket;
- data->oal_socket = arg_oal_socket;
- data->req_length = arg_req_length;
- if(net_nfc_server_controller_async_queue_push(
- llcp_handle_receive_thread_func,
- data) == FALSE)
+ net_nfc_util_gdbus_variant_to_data_s(arg_data, &data->data);
+
+ result = net_nfc_server_controller_async_queue_push(
+ llcp_handle_send_thread_func,
+ data);
+ if (result == FALSE)
{
g_dbus_method_invocation_return_dbus_error(invocation,
- "org.tizen.NetNfcService.ThreadError",
+ "org.tizen.NetNfcService.Llcp.ThreadError",
"can not push to controller thread");
- g_object_unref(data->llcp);
+ net_nfc_util_free_data(&data->data);
+
g_object_unref(data->invocation);
+ g_object_unref(data->llcp);
g_free(data);
-
- return FALSE;
}
- return TRUE;
+ return result;
}
-static gboolean llcp_handle_receive_from(NetNfcGDbusLlcp *llcp,
+static gboolean llcp_handle_send_to(NetNfcGDbusLlcp *llcp,
GDBusMethodInvocation *invocation,
guint32 arg_handle,
guint32 arg_client_socket,
- guint32 arg_oal_socket,
- guint32 arg_req_length,
+ guint8 arg_sap,
+ GVariant *arg_data,
GVariant *smack_privilege,
gpointer user_data)
{
- LlcpReceiveData *data;
+ gboolean result;
+ LlcpSendToData *data;
INFO_MSG(">>> REQUEST from [%s]",
g_dbus_method_invocation_get_sender(invocation));
if (net_nfc_server_gdbus_check_privilege(invocation,
smack_privilege,
"nfc-manager::p2p",
- "w") == false) {
+ "rw") == false) {
DEBUG_ERR_MSG("permission denied, and finished request");
- return TRUE;
+ return FALSE;
}
- data = g_new0(LlcpReceiveData, 1);
- if(data == NULL)
- {
- DEBUG_ERR_MSG("Memory allocation failed");
+ data = g_try_new0(LlcpSendToData, 1);
+ if (data == NULL) {
g_dbus_method_invocation_return_dbus_error(invocation,
"org.tizen.NetNfcService.AllocationError",
"Can not allocate memory");
+
return FALSE;
}
+
data->llcp = g_object_ref(llcp);
data->invocation = g_object_ref(invocation);
data->handle = arg_handle;
data->client_socket = arg_client_socket;
- data->oal_socket = arg_oal_socket;
- data->req_length = arg_req_length;
+ data->sap = arg_sap;
+
+ net_nfc_util_gdbus_variant_to_data_s(arg_data, &data->data);
- if(net_nfc_server_controller_async_queue_push(
- llcp_handle_receive_from_thread_func,
- data) == FALSE)
+ result = net_nfc_server_controller_async_queue_push(
+ llcp_handle_send_to_thread_func,
+ data);
+ if (result == FALSE)
{
g_dbus_method_invocation_return_dbus_error(invocation,
- "org.tizen.NetNfcService.ThreadError",
+ "org.tizen.NetNfcService.Llcp.ThreadError",
"can not push to controller thread");
- g_object_unref(data->llcp);
+ net_nfc_util_free_data(&data->data);
+
g_object_unref(data->invocation);
+ g_object_unref(data->llcp);
g_free(data);
-
- return FALSE;
}
- return TRUE;
+ return result;
}
-static gboolean llcp_handle_close(NetNfcGDbusLlcp *llcp,
+static gboolean llcp_handle_receive(NetNfcGDbusLlcp *llcp,
GDBusMethodInvocation *invocation,
guint32 arg_handle,
guint32 arg_client_socket,
- guint32 arg_oal_socket,
+ guint32 arg_req_length,
GVariant *smack_privilege,
gpointer user_data)
{
- LlcpCloseData *data;
+ gboolean result;
+ LlcpReceiveData *data;
INFO_MSG(">>> REQUEST from [%s]",
g_dbus_method_invocation_get_sender(invocation));
"w") == false) {
DEBUG_ERR_MSG("permission denied, and finished request");
- return TRUE;
+ return FALSE;
}
- data = g_new0(LlcpCloseData, 1);
- if(data == NULL)
- {
- DEBUG_ERR_MSG("Memory allocation failed");
+ data = g_try_new0(LlcpReceiveData, 1);
+ if (data == NULL) {
g_dbus_method_invocation_return_dbus_error(invocation,
"org.tizen.NetNfcService.AllocationError",
"Can not allocate memory");
+
return FALSE;
}
+
data->llcp = g_object_ref(llcp);
data->invocation = g_object_ref(invocation);
data->handle = arg_handle;
data->client_socket = arg_client_socket;
- data->oal_socket = arg_oal_socket;
+ data->req_length = arg_req_length;
- if (net_nfc_server_controller_async_queue_push(
- llcp_handle_close_thread_func,
- data) == FALSE)
+ result = net_nfc_server_controller_async_queue_push(
+ llcp_handle_receive_thread_func,
+ data);
+ if (result == FALSE)
{
g_dbus_method_invocation_return_dbus_error(invocation,
- "org.tizen.NetNfcService.ThreadError",
+ "org.tizen.NetNfcService.Llcp.ThreadError",
"can not push to controller thread");
- g_object_unref(data->llcp);
g_object_unref(data->invocation);
+ g_object_unref(data->llcp);
g_free(data);
-
- return FALSE;
}
- return TRUE;
+ return result;
}
-static gboolean llcp_handle_disconnect(NetNfcGDbusLlcp *llcp,
+static gboolean llcp_handle_receive_from(NetNfcGDbusLlcp *llcp,
GDBusMethodInvocation *invocation,
guint32 arg_handle,
guint32 arg_client_socket,
- guint32 arg_oal_socket,
+ guint32 arg_req_length,
GVariant *smack_privilege,
gpointer user_data)
{
- LlcpDisconnectData *data;
+ gboolean result;
+ LlcpReceiveData *data;
INFO_MSG(">>> REQUEST from [%s]",
g_dbus_method_invocation_get_sender(invocation));
"w") == false) {
DEBUG_ERR_MSG("permission denied, and finished request");
- return TRUE;
+ return FALSE;
}
- data = g_new0(LlcpDisconnectData, 1);
- if(data == NULL)
- {
- DEBUG_ERR_MSG("Memory allocation failed");
+ data = g_try_new0(LlcpReceiveData, 1);
+ if (data == NULL) {
g_dbus_method_invocation_return_dbus_error(invocation,
"org.tizen.NetNfcService.AllocationError",
"Can not allocate memory");
+
return FALSE;
}
+
data->llcp = g_object_ref(llcp);
data->invocation = g_object_ref(invocation);
data->handle = arg_handle;
data->client_socket = arg_client_socket;
- data->oal_socket = arg_oal_socket;
+ data->req_length = arg_req_length;
- if (net_nfc_server_controller_async_queue_push(
- llcp_handle_disconnect_thread_func,
- data) == FALSE)
+ result = net_nfc_server_controller_async_queue_push(
+ llcp_handle_receive_from_thread_func,
+ data);
+ if (result == FALSE)
{
g_dbus_method_invocation_return_dbus_error(invocation,
- "org.tizen.NetNfcService.ThreadError",
+ "org.tizen.NetNfcService.Llcp.ThreadError",
"can not push to controller thread");
- g_object_unref(data->llcp);
g_object_unref(data->invocation);
-
- g_free(data);
-
- return FALSE;
- }
-
- return TRUE;
-}
-
-
-static void llcp_deactivated_thread_func(gpointer user_data)
-{
- ServerLlcpData *data;
-
- net_nfc_request_llcp_msg_t *req_llcp_msg;
- net_nfc_target_handle_s *handle;
-
- data = (ServerLlcpData *)user_data;
-
- if (data == NULL)
- {
- DEBUG_ERR_MSG("can not get ServerLlcpData");
-
- return;
- }
-
- if (data->llcp == NULL)
- {
- DEBUG_ERR_MSG("can not get llcp");
-
- g_free(data->req_msg);
- g_free(data);
-
- return;
- }
-
- if (data->req_msg == NULL)
- {
- DEBUG_ERR_MSG("can not get request msg");
-
- g_object_unref(data->llcp);
- g_free(data);
-
- return;
- }
-
- req_llcp_msg = (net_nfc_request_llcp_msg_t *)data->req_msg;
-
- handle = (net_nfc_target_handle_s*)req_llcp_msg->user_param;
- if (handle == NULL)
- {
- DEBUG_SERVER_MSG(
- "the target ID = [0x%p] was not connected before."
- "current device may be a TARGET", handle);
- }
- else
- {
- net_nfc_error_e result = NET_NFC_OK;
-
- if (net_nfc_controller_disconnect(handle, &result) == false)
- {
- if (result != NET_NFC_NOT_CONNECTED)
- {
- net_nfc_controller_exception_handler();
- }
- else
- {
- DEBUG_SERVER_MSG("target was not connected.");
- }
- }
-
- net_nfc_server_set_state(NET_NFC_SERVER_IDLE);
- }
-
- /* send p2p detatch */
- net_nfc_server_p2p_detached();
-
- g_object_unref(data->llcp);
-
- g_free(data->req_msg);
- g_free(data);
-}
-
-static void llcp_listen_thread_func(gpointer user_data)
-{
- ServerLlcpData *data;
-
- socket_info_t *info = NULL;
- net_nfc_request_listen_socket_t *listen_socket;
-
- data = (ServerLlcpData *)user_data;
-
- if (data == NULL)
- {
- DEBUG_ERR_MSG("can not get ServerLlcpData");
- return;
- }
-
- if (data->llcp == NULL)
- {
- DEBUG_ERR_MSG("can not get llcp");
-
- g_free(data->req_msg);
- g_free(data);
-
- return;
- }
-
- if (data->req_msg == NULL)
- {
- DEBUG_ERR_MSG("can not get request msg");
-
- g_object_unref(data->llcp);
- g_free(data);
-
- return;
- }
-
- listen_socket = (net_nfc_request_listen_socket_t *)data->req_msg;
-
- info = (socket_info_t *)listen_socket->user_param;
- info = _get_socket_info(info->socket);
-
- if (info != NULL)
- {
- if (_add_socket_info(listen_socket->client_socket) != NULL)
- {
- if (info->work_cb != NULL)
- {
- info->work_cb(listen_socket->client_socket,
- listen_socket->result, NULL, NULL,info->work_param);
- }
- }
- else
- {
- DEBUG_ERR_MSG("_net_nfc_util_alloc_mem failed");
- }
- }
-
- g_object_unref(data->llcp);
-
- g_free(data->req_msg);
- g_free(data);
-}
-
-static void llcp_socket_error_thread_func(gpointer user_data)
-{
- ServerLlcpData *data;
-
- net_nfc_request_llcp_msg_t *req_llcp_msg;
- net_nfc_llcp_param_t *param;
-
- data = (ServerLlcpData *)user_data;
-
- if (data == NULL)
- {
- DEBUG_ERR_MSG("can not get ServerLlcpData");
- return;
- }
-
- if (data->llcp == NULL)
- {
- DEBUG_ERR_MSG("can not get llcp");
-
- g_free(data->req_msg);
- g_free(data);
-
- return;
- }
-
- if (data->req_msg == NULL)
- {
- DEBUG_ERR_MSG("can not get request msg");
-
g_object_unref(data->llcp);
- g_free(data);
- return;
- }
-
- req_llcp_msg = (net_nfc_request_llcp_msg_t *)data->req_msg;
- param = (net_nfc_llcp_param_t *)req_llcp_msg->user_param;
-
- if (param)
- {
- if (param->cb)
- {
- param->cb(req_llcp_msg->llcp_socket,
- req_llcp_msg->result,
- NULL,
- NULL,
- param->user_param);
- }
-
- g_free(param);
- }
-
- g_object_unref(data->llcp);
-
- g_free(data->req_msg);
- g_free(data);
-}
-
-static void llcp_send_thread_func(gpointer user_data)
-{
- ServerLlcpData *data;
-
- net_nfc_request_llcp_msg_t *req_llcp_msg;
- net_nfc_llcp_param_t *param;
-
- data = (ServerLlcpData *)user_data;
-
- if (data == NULL)
- {
- DEBUG_ERR_MSG("can not get ServerLlcpData");
-
- return;
- }
-
- if (data->llcp == NULL)
- {
- DEBUG_ERR_MSG("can not get llcp");
-
- g_free(data->req_msg);
g_free(data);
-
- return;
- }
-
- if (data->req_msg == NULL)
- {
- DEBUG_ERR_MSG("can not get request msg");
-
- g_object_unref(data->llcp);
- g_free(data);
-
- return;
}
- req_llcp_msg = (net_nfc_request_llcp_msg_t *)data->req_msg;
- param = (net_nfc_llcp_param_t *)req_llcp_msg->user_param;
-
- if (param)
- {
- if (param->cb)
- {
- param->cb(param->socket,
- req_llcp_msg->result,
- NULL,
- NULL,
- param->user_param);
- }
-
- g_free(param);
- }
-
- g_object_unref(data->llcp);
-
- g_free(data->req_msg);
- g_free(data);
+ return result;
}
-static void llcp_receive_thread_func(gpointer user_data)
+static gboolean llcp_handle_close(NetNfcGDbusLlcp *llcp,
+ GDBusMethodInvocation *invocation,
+ guint32 arg_handle,
+ guint32 arg_client_socket,
+ GVariant *smack_privilege,
+ gpointer user_data)
{
- ServerLlcpData *data;
-
- net_nfc_request_receive_socket_t *req_receive_socket;
- net_nfc_llcp_param_t *param;
-
- data = (ServerLlcpData *)user_data;
-
- if (data == NULL)
- {
- DEBUG_ERR_MSG("can not get ServerLlcpData");
-
- return;
- }
-
- if (data->llcp == NULL)
- {
- DEBUG_ERR_MSG("can not get llcp");
-
- g_free(data->req_msg);
- g_free(data);
-
- return;
- }
-
- if (data->req_msg == NULL)
- {
- DEBUG_ERR_MSG("can not get request msg");
-
- g_object_unref(data->llcp);
- g_free(data);
-
- return;
- }
-
- req_receive_socket = (net_nfc_request_receive_socket_t *)data->req_msg;
- param = (net_nfc_llcp_param_t *)req_receive_socket->user_param;
+ gboolean result;
+ LlcpCloseData *data;
- if (param)
- {
- if (param->cb)
- {
- param->cb(param->socket,
- req_receive_socket->result,
- ¶m->data,
- NULL,
- param->user_param);
- }
+ INFO_MSG(">>> REQUEST from [%s]",
+ g_dbus_method_invocation_get_sender(invocation));
- if (param->data.buffer)
- g_free(param->data.buffer);
+ /* check privilege and update client context */
+ if (net_nfc_server_gdbus_check_privilege(invocation,
+ smack_privilege,
+ "nfc-manager::p2p",
+ "w") == false) {
+ DEBUG_ERR_MSG("permission denied, and finished request");
- g_free(param);
+ return FALSE;
}
- g_object_unref(data->llcp);
-
- g_free(data->req_msg);
- g_free(data);
-}
-
-static void llcp_receive_from_thread_func(gpointer user_data)
-{
- ServerLlcpData *data;
-
- net_nfc_request_receive_from_socket_t *req_receive_from_socket;
- net_nfc_llcp_param_t *param;
-
- data = (ServerLlcpData *)user_data;
-
- if (data == NULL)
- {
- DEBUG_ERR_MSG("can not get ServerLlcpData");
+ data = g_try_new0(LlcpCloseData, 1);
+ if (data == NULL) {
+ g_dbus_method_invocation_return_dbus_error(invocation,
+ "org.tizen.NetNfcService.AllocationError",
+ "Can not allocate memory");
- return;
+ return FALSE;
}
- if (data->llcp == NULL)
- {
- DEBUG_ERR_MSG("can not get llcp");
-
- g_free(data->req_msg);
- g_free(data);
-
- return;
- }
+ data->llcp = g_object_ref(llcp);
+ data->invocation = g_object_ref(invocation);
+ data->handle = arg_handle;
+ data->client_socket = arg_client_socket;
- if (data->req_msg == NULL)
+ result = net_nfc_server_controller_async_queue_push(
+ llcp_handle_close_thread_func,
+ data);
+ if (result == FALSE)
{
- DEBUG_ERR_MSG("can not get request msg");
+ g_dbus_method_invocation_return_dbus_error(invocation,
+ "org.tizen.NetNfcService.Llcp.ThreadError",
+ "can not push to controller thread");
g_object_unref(data->llcp);
- g_free(data);
-
- return;
- }
-
- req_receive_from_socket = (net_nfc_request_receive_from_socket_t *)
- data->req_msg;
- param = (net_nfc_llcp_param_t *)req_receive_from_socket->user_param;
-
- if (param)
- {
- if (param->cb)
- {
- param->cb(param->socket,
- req_receive_from_socket->result,
- ¶m->data,
- (void *)(int)req_receive_from_socket->sap,
- param->user_param);
- }
-
- if (param->data.buffer)
- g_free(param->data.buffer);
-
- g_free(param);
- }
-
- g_object_unref(data->llcp);
-
- g_free(data->req_msg);
- g_free(data);
-}
-
-static void llcp_connect_thread_func(gpointer user_data)
-{
- ServerLlcpData *data;
-
- net_nfc_request_llcp_msg_t *req_llcp_msg;
- net_nfc_llcp_param_t *param;
-
- data = (ServerLlcpData *)user_data;
-
- if (data == NULL)
- {
- DEBUG_ERR_MSG("can not get ServerLlcpData");
-
- return;
- }
-
- if (data->llcp == NULL)
- {
- DEBUG_ERR_MSG("can not get llcp");
-
- g_free(data->req_msg);
- g_free(data);
-
- return;
- }
-
- if (data->req_msg == NULL)
- {
- DEBUG_ERR_MSG("can not get request msg");
+ g_object_unref(data->invocation);
- g_object_unref(data->llcp);
g_free(data);
-
- return;
- }
-
- req_llcp_msg = (net_nfc_request_llcp_msg_t *)data->req_msg;
- param = (net_nfc_llcp_param_t *)req_llcp_msg->user_param;
-
- if (param)
- {
- if (param->cb)
- {
- param->cb(param->socket,
- req_llcp_msg->result,
- NULL,
- NULL,
- param->user_param);
- }
-
- g_free(param);
}
- g_object_unref(data->llcp);
-
- g_free(data->req_msg);
- g_free(data);
+ return result;
}
-static void llcp_disconnect_thread_func(gpointer user_data)
+static gboolean llcp_handle_disconnect(NetNfcGDbusLlcp *llcp,
+ GDBusMethodInvocation *invocation,
+ guint32 arg_handle,
+ guint32 arg_client_socket,
+ GVariant *smack_privilege,
+ gpointer user_data)
{
- ServerLlcpData *data;
-
- net_nfc_request_llcp_msg_t *req_llcp_msg;
- net_nfc_llcp_param_t *param;
+ gboolean result;
+ LlcpDisconnectData *data;
- data = (ServerLlcpData *)user_data;
+ INFO_MSG(">>> REQUEST from [%s]",
+ g_dbus_method_invocation_get_sender(invocation));
- if (data == NULL)
- {
- DEBUG_ERR_MSG("can not get ServerLlcpData");
+ /* check privilege and update client context */
+ if (net_nfc_server_gdbus_check_privilege(invocation,
+ smack_privilege,
+ "nfc-manager::p2p",
+ "w") == false) {
+ DEBUG_ERR_MSG("permission denied, and finished request");
- return;
+ return FALSE;
}
- if (data->llcp == NULL)
- {
- DEBUG_ERR_MSG("can not get llcp");
-
- g_free(data->req_msg);
- g_free(data);
+ data = g_try_new0(LlcpDisconnectData, 1);
+ if (data == NULL) {
+ g_dbus_method_invocation_return_dbus_error(invocation,
+ "org.tizen.NetNfcService.AllocationError",
+ "Can not allocate memory");
- return;
+ return FALSE;
}
- if (data->req_msg == NULL)
+ data->llcp = g_object_ref(llcp);
+ data->invocation = g_object_ref(invocation);
+ data->handle = arg_handle;
+ data->client_socket = arg_client_socket;
+
+ result = net_nfc_server_controller_async_queue_push(
+ llcp_handle_disconnect_thread_func,
+ data);
+ if (result == FALSE)
{
- DEBUG_ERR_MSG("can not get request msg");
+ g_dbus_method_invocation_return_dbus_error(invocation,
+ "org.tizen.NetNfcService.Llcp.ThreadError",
+ "can not push to controller thread");
+ g_object_unref(data->invocation);
g_object_unref(data->llcp);
- g_free(data);
- return;
+ g_free(data);
}
- req_llcp_msg = (net_nfc_request_llcp_msg_t *)data->req_msg;
- param = (net_nfc_llcp_param_t *)req_llcp_msg->user_param;
+ return result;
+}
+
+void net_nfc_server_llcp_deactivated(gpointer user_data)
+{
+ net_nfc_target_handle_s *handle = (net_nfc_target_handle_s *)user_data;
- if (param)
+ if (handle != NULL)
{
- if (param->cb)
+ net_nfc_error_e result = NET_NFC_OK;
+
+ if (net_nfc_controller_disconnect(handle, &result) == false)
{
- param->cb(param->socket,
- req_llcp_msg->result,
- NULL,
- NULL,
- param->user_param);
+ if (result != NET_NFC_NOT_CONNECTED)
+ {
+ net_nfc_controller_exception_handler();
+ }
+ else
+ {
+ DEBUG_SERVER_MSG("target was not connected.");
+ }
}
- g_free(param);
+ net_nfc_server_set_state(NET_NFC_SERVER_IDLE);
+ }
+ else
+ {
+ DEBUG_SERVER_MSG("the target was disconnected");
}
- g_object_unref(data->llcp);
-
- g_free(data->req_msg);
- g_free(data);
+ /* send p2p detatch */
+ net_nfc_server_p2p_detached();
}
static void llcp_simple_socket_error_cb(net_nfc_llcp_socket_t socket,
void *extra,
void *user_param)
{
- LlcpSimpleData *simple_data;
+ LlcpSimpleData *simple_data = (LlcpSimpleData *)user_param;
- simple_data = (LlcpSimpleData *)user_param;
+ g_assert(simple_data != NULL);
if (simple_data->error_callback)
{
void *extra,
void *user_param)
{
- LlcpSimpleData *simple_data;
+ LlcpSimpleData *simple_data = (LlcpSimpleData *)user_param;
- simple_data = (LlcpSimpleData *)user_param;
+ g_assert(simple_data != NULL);
if (result != NET_NFC_OK) {
DEBUG_ERR_MSG("listen socket failed, [%d]", result);
void *extra,
void *user_param)
{
- LlcpSimpleData *simple_data;
+ LlcpSimpleData *simple_data = (LlcpSimpleData *)user_param;
- simple_data = (LlcpSimpleData *)user_param;
+ g_assert(simple_data != NULL);
if (result != NET_NFC_OK) {
DEBUG_ERR_MSG("connect socket failed, [%d]", result);
/* 'simple_data' will be freed in socket error callback */
}
-static void llcp_simple_server_error_cb(net_nfc_llcp_socket_t socket,
- net_nfc_error_e result,
- data_s *data,
- void *extra,
- void *user_param)
-{
- LlcpSimpleData *simple_data;
-
- simple_data = (LlcpSimpleData *)user_param;
-
- if (simple_data->error_callback)
- {
- simple_data->error_callback(result,
- simple_data->handle,
- socket,
- data,
- simple_data->user_data);
- }
-
- g_free(simple_data);
-}
-
static void llcp_simple_send_cb(net_nfc_llcp_socket_t socket,
net_nfc_error_e result,
data_s *data,
void *extra,
void *user_param)
{
- LlcpSimpleData *simple_data;
+ LlcpSimpleData *simple_data = (LlcpSimpleData *)user_param;
- simple_data = (LlcpSimpleData *)user_param;
+ g_assert(simple_data != NULL);
if (simple_data->callback)
{
void *extra,
void *user_param)
{
- LlcpSimpleData *simple_data;
+ LlcpSimpleData *simple_data = (LlcpSimpleData *)user_param;
- simple_data = (LlcpSimpleData *)user_param;
+ g_assert(simple_data != NULL);
if (simple_data->callback)
{
/* Public Function */
gboolean net_nfc_server_llcp_init(GDBusConnection *connection)
{
+ gboolean result;
GError *error = NULL;
if (llcp_skeleton)
NULL);
g_signal_connect(llcp_skeleton,
+ "handle-accept",
+ G_CALLBACK(llcp_handle_accept),
+ NULL);
+
+ g_signal_connect(llcp_skeleton,
+ "handle-reject",
+ G_CALLBACK(llcp_handle_reject),
+ NULL);
+
+ g_signal_connect(llcp_skeleton,
"handle-connect",
G_CALLBACK(llcp_handle_connect),
NULL);
G_CALLBACK(llcp_handle_disconnect),
NULL);
- if(g_dbus_interface_skeleton_export(
- G_DBUS_INTERFACE_SKELETON(llcp_skeleton),
- connection,
- "/org/tizen/NetNfcService/Llcp",
- &error) == FALSE)
+ result = g_dbus_interface_skeleton_export(
+ G_DBUS_INTERFACE_SKELETON(llcp_skeleton),
+ connection,
+ "/org/tizen/NetNfcService/Llcp",
+ &error);
+ if (result == FALSE)
{
g_error_free(error);
- g_object_unref(llcp_skeleton);
- llcp_skeleton = NULL;
- return FALSE;
+ net_nfc_server_llcp_deinit();
}
- return TRUE;
+ return result;
}
void net_nfc_server_llcp_deinit(void)
}
}
-void net_nfc_server_llcp_deactivated(net_nfc_request_msg_t *req_msg)
-{
- llcp_add_async_queue(req_msg, llcp_deactivated_thread_func);
-}
-
-void net_nfc_server_llcp_listen(net_nfc_request_msg_t *req_msg)
-{
- llcp_add_async_queue(req_msg, llcp_listen_thread_func);
-}
-
-void net_nfc_server_llcp_socket_error(net_nfc_request_msg_t *req_msg)
-{
- llcp_add_async_queue(req_msg, llcp_socket_error_thread_func);
-}
-
-void net_nfc_server_llcp_send(net_nfc_request_msg_t *req_msg)
-{
- llcp_add_async_queue(req_msg, llcp_send_thread_func);
-}
-
-void net_nfc_server_llcp_receive(net_nfc_request_msg_t *req_msg)
-{
- llcp_add_async_queue(req_msg, llcp_receive_thread_func);
-}
-
-void net_nfc_server_llcp_receive_from(net_nfc_request_msg_t *req_msg)
-{
- llcp_add_async_queue(req_msg, llcp_receive_from_thread_func);
-}
-
-void net_nfc_server_llcp_connect(net_nfc_request_msg_t *req_msg)
-{
- llcp_add_async_queue(req_msg, llcp_connect_thread_func);
-}
-
-void net_nfc_server_llcp_disconnect(net_nfc_request_msg_t *req_msg)
-{
- llcp_add_async_queue(req_msg, llcp_disconnect_thread_func);
-}
-
-net_nfc_error_e net_nfc_server_llcp_set_config(net_nfc_llcp_config_info_s *config)
+net_nfc_error_e net_nfc_server_llcp_set_config(
+ net_nfc_llcp_config_info_s *config)
{
net_nfc_error_e result;
gpointer user_data)
{
net_nfc_error_e result = NET_NFC_OK;
-
+ LlcpSimpleData *simple_data = NULL;
net_nfc_llcp_socket_t socket = -1;
net_nfc_llcp_config_info_s config;
- LlcpSimpleData *simple_data = NULL;
-
if (handle == NULL)
return NET_NFC_NULL_PARAMETER;
- if (san == NULL)
- return NET_NFC_NULL_PARAMETER;
-
if (net_nfc_controller_llcp_get_remote_config(handle,
&config,
&result) == false)
{
- DEBUG_ERR_MSG("%s failed [%d]",
- "net_nfc_controller_llcp_get_remote_config",
- result);
- return result;
+ DEBUG_ERR_MSG("net_nfc_controller_llcp_get_remote_config failed [%d]", result);
+
+ goto ERROR;
}
- simple_data = g_new0(LlcpSimpleData, 1);
- if(simple_data == NULL)
- {
- DEBUG_ERR_MSG("Memory allocation failed");
+ simple_data = g_try_new0(LlcpSimpleData, 1);
+ if (simple_data == NULL) {
+ DEBUG_ERR_MSG("g_try_new0 failed");
- return NET_NFC_ALLOC_FAIL;
+ result = NET_NFC_ALLOC_FAIL;
+
+ goto ERROR;
}
+
simple_data->handle = handle;
simple_data->callback = callback;
simple_data->error_callback = error_callback;
llcp_simple_socket_error_cb,
simple_data) == false)
{
- DEBUG_ERR_MSG("%s failed [%d]",
- "net_nfc_controller_llcp_create_socket",
- result);
+ DEBUG_ERR_MSG("net_nfc_controller_llcp_create_socket failed [%d]", result);
- g_free(simple_data);
- return result;
+ goto ERROR;
}
simple_data->socket = socket;
sap,
&result) == false)
{
- DEBUG_ERR_MSG("%s failed [%d]",
- "nte_nfc_controller_llcp_bind",
- result);
-
- if (simple_data->socket != 1)
- net_nfc_controller_llcp_socket_close(socket, &result);
-
- g_free(simple_data);
+ DEBUG_ERR_MSG("net_nfc_controller_llcp_bind failed [%d]", result);
- return result;
+ goto ERROR;
}
if (net_nfc_controller_llcp_listen(handle,
llcp_simple_listen_cb,
simple_data) == false)
{
- DEBUG_ERR_MSG("%s failed [%d]",
- "net_nfc_controller_llcp_listen",
- result);
-
- if (simple_data->socket != 1)
- {
- net_nfc_controller_llcp_socket_close(
- simple_data->socket,
- &result);
- }
-
- g_free(simple_data);
-
- return result;
+ DEBUG_ERR_MSG("net_nfc_controller_llcp_listen failed [%d]", result);
+ goto ERROR;
}
DEBUG_SERVER_MSG("result [%d]", result);
result = NET_NFC_OK;
return result;
+
+ERROR :
+ if (socket != -1) {
+ net_nfc_error_e temp;
+
+ net_nfc_controller_llcp_socket_close(socket, &temp);
+ }
+
+ if (simple_data != NULL) {
+ g_free(simple_data);
+ }
+
+ return result;
}
net_nfc_error_e net_nfc_server_llcp_simple_client(
net_nfc_server_llcp_callback error_callback,
gpointer user_data)
{
- net_nfc_error_e result = NET_NFC_OK;
-
+ net_nfc_error_e result;
+ LlcpSimpleData *simple_data = NULL;
net_nfc_llcp_socket_t socket = -1;
net_nfc_llcp_config_info_s config;
- LlcpSimpleData *simple_data = NULL;
-
if (handle == NULL)
return NET_NFC_NULL_PARAMETER;
&config,
&result) == false)
{
- DEBUG_ERR_MSG("%s failed [%d]",
- "net_nfc_controller_llcp_get_remote_config",
- result);
- return result;
+ DEBUG_ERR_MSG("net_nfc_controller_llcp_get_remote_config failed [%d]", result);
+
+ goto ERROR;
}
- simple_data = g_new0(LlcpSimpleData, 1);
+ simple_data = g_try_new0(LlcpSimpleData, 1);
+ if (simple_data == NULL) {
+ DEBUG_ERR_MSG("g_try_new0 failed");
+
+ result = NET_NFC_ALLOC_FAIL;
+
+ goto ERROR;
+ }
simple_data->handle = handle;
simple_data->callback = callback;
llcp_simple_socket_error_cb,
simple_data) == false)
{
- DEBUG_ERR_MSG("%s failed [%d]",
- "net_nfc_controller_llcp_create_socket",
- result);
+ DEBUG_ERR_MSG("net_nfc_controller_llcp_create_socket failed [%d]", result);
- g_free(simple_data);
- return result;
+ goto ERROR;
}
simple_data->socket = socket;
llcp_simple_connect_cb,
simple_data) == false)
{
- DEBUG_ERR_MSG("%s failed [%d]",
- "net_nfc_controller_llcp_connect",
- result);
-
- if (simple_data->socket != -1)
- {
- net_nfc_controller_llcp_socket_close(
- simple_data->socket,
- &result);
- }
-
- g_free(simple_data);
+ DEBUG_ERR_MSG("net_nfc_controller_llcp_connect failed [%d]", result);
- return result;
+ goto ERROR;
}
-
}
else
{
llcp_simple_connect_cb,
simple_data) == false)
{
- DEBUG_ERR_MSG("%s failed [%d]",
- "net_nfc_controller_llcp_connect_by_url",
- result);
-
- if (simple_data->socket != -1)
- {
- net_nfc_controller_llcp_socket_close(
- simple_data->socket,
- &result);
- }
-
- g_free(simple_data);
+ DEBUG_ERR_MSG("net_nfc_controller_llcp_connect_by_url failed [%d]", result);
- return result;
+ goto ERROR;
}
}
result = NET_NFC_OK;
return result;
+
+ERROR :
+ if (socket != -1) {
+ net_nfc_error_e temp;
+
+ net_nfc_controller_llcp_socket_close(socket, &temp);
+ }
+
+ if (simple_data != NULL) {
+ g_free(simple_data);
+ }
+
+ return result;
}
net_nfc_error_e net_nfc_server_llcp_simple_accept(
net_nfc_server_llcp_callback error_callback,
gpointer user_data)
{
- net_nfc_error_e result = NET_NFC_OK;
-
+ net_nfc_error_e result;
LlcpSimpleData *simple_data;
- simple_data = g_new0(LlcpSimpleData, 1);
- if(simple_data == NULL)
- {
- DEBUG_ERR_MSG("Memory allocation failed");
+ simple_data = g_try_new0(LlcpSimpleData, 1);
+ if (simple_data != NULL) {
+ simple_data->handle = handle;
+ simple_data->socket = socket;
+ simple_data->error_callback = error_callback;
+ simple_data->user_data = user_data;
- return NET_NFC_ALLOC_FAIL;
- }
- simple_data->handle = handle;
- simple_data->socket = socket;
- simple_data->error_callback = error_callback;
- simple_data->user_data = user_data;
+ if (net_nfc_controller_llcp_accept(socket,
+ &result,
+ llcp_simple_socket_error_cb,
+ simple_data) == false)
+ {
+ DEBUG_ERR_MSG("net_nfc_controller_llcp_accept failed [%d]", result);
+ }
+ } else {
+ DEBUG_ERR_MSG("g_try_new0 failed");
- if (net_nfc_controller_llcp_accept(socket,
- &result,
- llcp_simple_server_error_cb,
- simple_data) == false)
- {
- DEBUG_ERR_MSG("%s failed [%d]",
- "net_nfc_controller_llcp_accept",
- result);
+ result = NET_NFC_ALLOC_FAIL;
}
if (result == NET_NFC_BUSY)
net_nfc_server_llcp_callback callback,
gpointer user_data)
{
- net_nfc_error_e result = NET_NFC_OK;
-
+ net_nfc_error_e result;
LlcpSimpleData *simple_data;
- simple_data = g_new0(LlcpSimpleData, 1);
- if(simple_data == NULL)
- {
- DEBUG_ERR_MSG("Memory allocation failed");
+ simple_data = g_try_new0(LlcpSimpleData, 1);
+ if (simple_data != NULL) {
+ simple_data->handle = handle;
+ simple_data->socket = socket;
+ simple_data->callback = callback;
+ simple_data->user_data = user_data;
- return NET_NFC_ALLOC_FAIL;
- }
- simple_data->handle = handle;
- simple_data->socket = socket;
- simple_data->callback = callback;
- simple_data->user_data = user_data;
+ if (net_nfc_controller_llcp_send(handle,
+ socket,
+ data,
+ &result,
+ llcp_simple_send_cb,
+ simple_data) == false)
+ {
+ DEBUG_ERR_MSG("net_nfc_controller_llcp_send failed [%d]",
+ result);
+ }
+ } else {
+ DEBUG_ERR_MSG("g_try_new0 failed");
- if (net_nfc_controller_llcp_send(handle,
- socket,
- data,
- &result,
- llcp_simple_send_cb,
- simple_data) == false)
- {
- DEBUG_ERR_MSG("%s failed [%d]",
- "net_nfc_controller_llcp_send",
- result);
+ result = NET_NFC_ALLOC_FAIL;
}
if (result == NET_NFC_BUSY)
net_nfc_server_llcp_callback callback,
gpointer user_data)
{
- net_nfc_error_e result = NET_NFC_OK;
-
+ net_nfc_error_e result;
LlcpSimpleData *simple_data;
- simple_data = g_new0(LlcpSimpleData, 1);
- if(simple_data == NULL)
- {
- DEBUG_ERR_MSG("Memory allocation failed");
+ simple_data = g_try_new0(LlcpSimpleData, 1);
+ if (simple_data != NULL) {
+ simple_data->handle = handle;
+ simple_data->socket = socket;
+ simple_data->callback = callback;
+ simple_data->user_data = user_data;
- return NET_NFC_ALLOC_FAIL;
- }
- simple_data->handle = handle;
- simple_data->socket = socket;
- simple_data->callback = callback;
- simple_data->user_data = user_data;
+ if (net_nfc_controller_llcp_recv(handle,
+ socket,
+ net_nfc_server_llcp_get_miu(),
+ &result,
+ llcp_simple_receive_cb,
+ simple_data) == false)
+ {
+ DEBUG_ERR_MSG("net_nfc_controller_llcp_recv failed [%d]", result);
- if (net_nfc_controller_llcp_recv(handle,
- socket,
- net_nfc_server_llcp_get_miu(),
- &result,
- llcp_simple_receive_cb,
- simple_data) == false)
- {
- DEBUG_ERR_MSG("%s failed [%d]",
- "net_nfc_controller_llcp_send",
- result);
+ g_free(simple_data);
+ }
+ } else {
+ DEBUG_ERR_MSG("g_try_new0 failed");
+
+ result = NET_NFC_ALLOC_FAIL;
}
if (result == NET_NFC_BUSY)
if (_llcp_find_service(sap) == NULL) {
DEBUG_SERVER_MSG("new service, sap [%d]", sap);
- service = g_new0(service_t, 1);
+ service = g_try_new0(service_t, 1);
if (service != NULL) {
service->sap = sap;
if (san != NULL && strlen(san) > 0) {
static void net_nfc_server_llcp_process(gpointer user_data)
{
net_nfc_current_target_info_s *target;
+#if 0
+ net_nfc_error_e result;
+#endif
net_nfc_target_handle_s *handle;
+ net_nfc_target_type_e dev_type;
target = net_nfc_server_get_target_info();
g_assert(target != NULL); /* raise exception!!! what;s wrong?? */
handle = target->handle;
+ dev_type = target->devType;
+
DEBUG_SERVER_MSG("connection type = [%d]", handle->connection_type);
#if 0
- net_nfc_target_type_e dev_type = target->devType;
-
if (dev_type == NET_NFC_NFCIP1_TARGET)
{
DEBUG_SERVER_MSG("LLCP : target, try to connect");