2 * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd.
4 * Licensed under the Flora License, Version 1.1 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://floralicense.org/license/
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
19 #include "net_nfc_data.h"
20 #include "net_nfc_typedef_internal.h"
21 #include "net_nfc_util_internal.h"
23 #ifndef NET_NFC_EXPORT_API
24 #define NET_NFC_EXPORT_API __attribute__((visibility("default")))
29 NET_NFC_EXPORT_API net_nfc_error_e net_nfc_create_data_only(data_h *data)
31 return net_nfc_create_data(data, NULL, 0);
34 NET_NFC_EXPORT_API net_nfc_error_e net_nfc_create_data(data_h *data,
35 const uint8_t *bytes, size_t length)
37 data_s *tmp_data = NULL;
40 return NET_NFC_NULL_PARAMETER;
44 tmp_data = net_nfc_util_create_data(length);
46 return NET_NFC_ALLOC_FAIL;
48 if (length > 0 && bytes != NULL)
49 memcpy(tmp_data->buffer, bytes, length);
51 *data = (data_h)tmp_data;
56 NET_NFC_EXPORT_API net_nfc_error_e net_nfc_get_data(const data_h data,
57 uint8_t **bytes, size_t *length)
59 data_s *tmp_data = (data_s *)data;
61 if (bytes == NULL || length == NULL)
62 return NET_NFC_NULL_PARAMETER;
68 return NET_NFC_NULL_PARAMETER;
70 *bytes = tmp_data->buffer;
71 *length = tmp_data->length;
76 NET_NFC_EXPORT_API net_nfc_error_e net_nfc_set_data(data_h data,
77 const uint8_t *bytes, size_t length)
79 data_s *tmp_data = (data_s *)data;
82 return NET_NFC_NULL_PARAMETER;
84 if (tmp_data->buffer == bytes && tmp_data->length == length)
87 net_nfc_util_clear_data(tmp_data);
90 net_nfc_util_init_data(tmp_data, length);
93 memcpy(tmp_data->buffer, bytes, length);
99 NET_NFC_EXPORT_API size_t net_nfc_get_data_length(const data_h data)
101 data_s *tmp_data = (data_s *)data;
106 return tmp_data->length;
109 NET_NFC_EXPORT_API uint8_t *net_nfc_get_data_buffer(const data_h data)
111 data_s *tmp_data = (data_s *)data;
116 return tmp_data->buffer;
119 NET_NFC_EXPORT_API net_nfc_error_e net_nfc_free_data(data_h data)
121 data_s *tmp_data = (data_s *)data;
124 return NET_NFC_NULL_PARAMETER;
126 if (tmp_data->buffer != NULL)
127 _net_nfc_util_free_mem(tmp_data->buffer);
129 _net_nfc_util_free_mem(tmp_data);