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")))
27 NET_NFC_EXPORT_API net_nfc_error_e net_nfc_create_data_only(data_h *data)
29 return net_nfc_create_data(data, NULL, 0);
32 NET_NFC_EXPORT_API net_nfc_error_e net_nfc_create_data(data_h *data,
33 const uint8_t *bytes, size_t length)
35 data_s *tmp_data = NULL;
39 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)
50 memcpy(tmp_data->buffer, bytes, length);
53 *data = (data_h)tmp_data;
58 NET_NFC_EXPORT_API net_nfc_error_e net_nfc_get_data(const data_h data,
59 uint8_t **bytes, size_t *length)
61 data_s *tmp_data = (data_s *)data;
63 if (bytes == NULL || length == NULL)
64 return NET_NFC_NULL_PARAMETER;
71 return NET_NFC_NULL_PARAMETER;
74 *bytes = tmp_data->buffer;
75 *length = tmp_data->length;
80 NET_NFC_EXPORT_API net_nfc_error_e net_nfc_set_data(data_h data,
81 const uint8_t *bytes, size_t length)
83 data_s *tmp_data = (data_s *)data;
87 return NET_NFC_NULL_PARAMETER;
90 if (tmp_data->buffer == bytes && tmp_data->length == length)
95 net_nfc_util_clear_data(tmp_data);
99 net_nfc_util_init_data(tmp_data, length);
103 memcpy(tmp_data->buffer, bytes, length);
110 NET_NFC_EXPORT_API size_t net_nfc_get_data_length(const data_h data)
112 data_s *tmp_data = (data_s *)data;
119 return tmp_data->length;
122 NET_NFC_EXPORT_API uint8_t *net_nfc_get_data_buffer(const data_h data)
124 data_s *tmp_data = (data_s *)data;
131 return tmp_data->buffer;
134 NET_NFC_EXPORT_API net_nfc_error_e net_nfc_free_data(data_h data)
136 data_s *tmp_data = (data_s *)data;
140 return NET_NFC_NULL_PARAMETER;
143 if (tmp_data->buffer != NULL)
145 _net_nfc_util_free_mem(tmp_data->buffer);
147 _net_nfc_util_free_mem(tmp_data);