Fixed ACR issue.
[platform/core/api/zigbee.git] / src / zbl-zdo-dev-disc.c
1 /*
2  * Copyright (c) 2016 Samsung Electronics Co., Ltd All Rights Reserved
3  *
4  * Licensed under the Apache License, Version 2.0 (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
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
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.
15  */
16 #include "zbl.h"
17 #include "zbl-dbus.h"
18 #include "zb-common.h"
19
20 API int zb_zdo_nwk_addr_req(zb_zigbee_h handle, zb_ieee_addr addr64,
21         zb_zdp_req_type_e request_type, unsigned char start_idx, zb_zdo_addr_cb cb,
22         void *user_data)
23 {
24         int ret;
25         CHECK_FEATURE_SUPPORTED(ZIGBEE_FEATURE);
26         RETV_IF(NULL == handle, ZIGBEE_ERROR_INVALID_PARAMETER);
27         RETV_IF(NULL == zbl_dbus_get_object(), ZIGBEE_ERROR_IO_ERROR);
28         RETV_IF(NULL == addr64, ZIGBEE_ERROR_INVALID_PARAMETER);
29         RETV_IF(0 != request_type && 1 != request_type, ZIGBEE_ERROR_INVALID_PARAMETER);
30         RETV_IF(NULL == cb, ZIGBEE_ERROR_INVALID_PARAMETER);
31         ret = zbl_nwk_addr_req(handle, addr64, request_type, start_idx, cb,
32                 user_data);
33         return ret;
34 }
35
36 API int zb_zdo_ieee_addr_req(zb_zigbee_h handle, zb_nwk_addr addr16, zb_zdo_addr_cb cb,
37         void *user_data)
38 {
39         int ret;
40         CHECK_FEATURE_SUPPORTED(ZIGBEE_FEATURE);
41         RETV_IF(NULL == handle, ZIGBEE_ERROR_INVALID_PARAMETER);
42         RETV_IF(NULL == zbl_dbus_get_object(), ZIGBEE_ERROR_IO_ERROR);
43         RETV_IF(NULL == cb, ZIGBEE_ERROR_INVALID_PARAMETER);
44         ret = zbl_ieee_addr_req(handle, addr16, cb, user_data);
45         return ret;
46 }
47
48 API int zb_zdo_active_ep(zb_zigbee_h handle, zb_nwk_addr addr16, zb_zdo_active_ep_cb cb,
49         void *user_data)
50 {
51         int ret;
52         CHECK_FEATURE_SUPPORTED(ZIGBEE_FEATURE);
53         RETV_IF(NULL == handle, ZIGBEE_ERROR_INVALID_PARAMETER);
54         RETV_IF(NULL == zbl_dbus_get_object(), ZIGBEE_ERROR_IO_ERROR);
55         RETV_IF(NULL == cb, ZIGBEE_ERROR_INVALID_PARAMETER);
56         ret = zbl_active_ep(handle, addr16, cb, user_data);
57         return ret;
58 }
59
60 API int zb_zdo_simple_desc_req(zb_zigbee_h handle, zb_nwk_addr addr16, unsigned char ep,
61         zb_zdo_simple_desc_cb cb, void *user_data)
62 {
63         int ret;
64         CHECK_FEATURE_SUPPORTED(ZIGBEE_FEATURE);
65         RETV_IF(NULL == handle, ZIGBEE_ERROR_INVALID_PARAMETER);
66         RETV_IF(NULL == zbl_dbus_get_object(), ZIGBEE_ERROR_IO_ERROR);
67         RETV_IF(0 == ep, ZIGBEE_ERROR_INVALID_ENDPOINT);
68         RETV_IF(NULL == cb, ZIGBEE_ERROR_INVALID_PARAMETER);
69         ret = zbl_simple_desc_req(handle, addr16, ep, cb, user_data);
70         return ret;
71 }
72
73 API int zb_zdo_extended_simple_desc_req(zb_zigbee_h handle, zb_nwk_addr addr16,
74         unsigned char start_idx, zb_zdo_extended_simple_desc_cb cb, void *user_data)
75 {
76         CHECK_FEATURE_SUPPORTED(ZIGBEE_FEATURE);
77         RETV_IF(NULL == handle, ZIGBEE_ERROR_INVALID_PARAMETER);
78         RETV_IF(NULL == zbl_dbus_get_object(), ZIGBEE_ERROR_IO_ERROR);
79         RETV_IF(NULL == cb, ZIGBEE_ERROR_INVALID_PARAMETER);
80         return ZIGBEE_ERROR_NONE;
81 }
82
83 API int zb_zdo_match_desc_req(zb_zigbee_h handle, zb_nwk_addr addr16,
84         unsigned short profileid, unsigned char num_in_clusters,
85         unsigned short *in_clusters, unsigned char num_out_clusters,
86         unsigned short *out_clusters, zb_zdo_match_desc_cb cb, void *user_data)
87 {
88         int ret;
89         CHECK_FEATURE_SUPPORTED(ZIGBEE_FEATURE);
90         RETV_IF(NULL == handle, ZIGBEE_ERROR_INVALID_PARAMETER);
91         RETV_IF(NULL == zbl_dbus_get_object(), ZIGBEE_ERROR_IO_ERROR);
92         RETV_IF(0 == addr16, ZIGBEE_ERROR_INVALID_ADDRESS);
93         RETV_IF(NULL == in_clusters, ZIGBEE_ERROR_INVALID_PARAMETER);
94         RETV_IF(NULL == out_clusters, ZIGBEE_ERROR_INVALID_PARAMETER);
95         RETV_IF(0 == num_in_clusters && 0 == num_out_clusters, ZIGBEE_ERROR_INVALID_PARAMETER);
96         RETV_IF(NULL == cb, ZIGBEE_ERROR_INVALID_PARAMETER);
97         ret = zbl_match_desc_req(handle, addr16, profileid, num_in_clusters,
98                 in_clusters, num_out_clusters, out_clusters, cb, user_data);
99         return ret;
100 }
101
102 API int zb_zdo_node_desc_req(zb_zigbee_h handle, zb_nwk_addr addr16,
103         zb_zdo_node_desc_cb cb, void *user_data)
104 {
105         int ret;
106         CHECK_FEATURE_SUPPORTED(ZIGBEE_FEATURE);
107         RETV_IF(NULL == handle, ZIGBEE_ERROR_INVALID_PARAMETER);
108         RETV_IF(NULL == zbl_dbus_get_object(), ZIGBEE_ERROR_IO_ERROR);
109         RETV_IF(0 == addr16, ZIGBEE_ERROR_INVALID_ADDRESS);
110         RETV_IF(NULL == cb, ZIGBEE_ERROR_INVALID_PARAMETER);
111         ret = zbl_node_desc_req(addr16, cb, user_data);
112         return ret;
113 }
114
115 API int zb_zdo_power_desc_req(zb_zigbee_h handle, zb_nwk_addr addr16,
116         zb_zdo_power_desc_cb cb, void *user_data)
117 {
118         int ret;
119         CHECK_FEATURE_SUPPORTED(ZIGBEE_FEATURE);
120         RETV_IF(NULL == handle, ZIGBEE_ERROR_INVALID_PARAMETER);
121         RETV_IF(NULL == zbl_dbus_get_object(), ZIGBEE_ERROR_IO_ERROR);
122         RETV_IF(0 == addr16, ZIGBEE_ERROR_INVALID_ADDRESS);
123         RETV_IF(NULL == cb, ZIGBEE_ERROR_INVALID_PARAMETER);
124         ret = zbl_power_desc_req(addr16, cb, user_data);
125         return ret;
126 }
127
128 API int zb_zdo_complex_desc_req(zb_zigbee_h handle, zb_nwk_addr addr16,
129         zb_zdo_complex_desc_cb cb, void *user_data)
130 {
131         int ret;
132         CHECK_FEATURE_SUPPORTED(ZIGBEE_FEATURE);
133         RETV_IF(NULL == handle, ZIGBEE_ERROR_INVALID_PARAMETER);
134         RETV_IF(NULL == zbl_dbus_get_object(), ZIGBEE_ERROR_IO_ERROR);
135         RETV_IF(0 == addr16, ZIGBEE_ERROR_INVALID_ADDRESS);
136         RETV_IF(NULL == cb, ZIGBEE_ERROR_INVALID_PARAMETER);
137         ret = zbl_complex_desc_req(addr16, cb, user_data);
138         return ret;
139 }
140
141 API int zb_zdo_user_desc_req(zb_zigbee_h handle, zb_nwk_addr addr16,
142         zb_zdo_user_desc_cb cb, void *user_data)
143 {
144         int ret;
145         CHECK_FEATURE_SUPPORTED(ZIGBEE_FEATURE);
146         RETV_IF(NULL == handle, ZIGBEE_ERROR_INVALID_PARAMETER);
147         RETV_IF(NULL == zbl_dbus_get_object(), ZIGBEE_ERROR_IO_ERROR);
148         RETV_IF(0 == addr16, ZIGBEE_ERROR_INVALID_ADDRESS);
149         RETV_IF(NULL == cb, ZIGBEE_ERROR_INVALID_PARAMETER);
150         ret = zbl_user_desc_req(addr16, cb, user_data);
151         return ret;
152 }
153
154 API int zb_zdo_user_desc_set(zb_zigbee_h handle, zb_nwk_addr addr16, unsigned char len,
155         unsigned char *user_desc, zb_zdo_user_desc_conf_cb cb, void *user_data)
156 {
157         int ret;
158         CHECK_FEATURE_SUPPORTED(ZIGBEE_FEATURE);
159         RETV_IF(NULL == handle, ZIGBEE_ERROR_INVALID_PARAMETER);
160         RETV_IF(NULL == zbl_dbus_get_object(), ZIGBEE_ERROR_IO_ERROR);
161         RETV_IF(0 == addr16, ZIGBEE_ERROR_INVALID_ADDRESS);
162         RETV_IF(NULL == user_desc, ZIGBEE_ERROR_INVALID_PARAMETER);
163         ret = zbl_user_desc_set(handle, addr16, len, user_desc, cb, user_data);
164         return ret;
165 }
166
167 API int zb_zdo_device_annce(zb_zigbee_h handle, zb_nwk_addr addr16, zb_ieee_addr addr64,
168         unsigned char capability)
169 {
170         int ret;
171         CHECK_FEATURE_SUPPORTED(ZIGBEE_FEATURE);
172         RETV_IF(NULL == handle, ZIGBEE_ERROR_INVALID_PARAMETER);
173         RETV_IF(NULL == zbl_dbus_get_object(), ZIGBEE_ERROR_IO_ERROR);
174         RETV_IF(0 == addr16 || 0 == addr64, ZIGBEE_ERROR_INVALID_ADDRESS);
175         ret = zbl_device_annce(handle, addr16, addr64, capability);
176         return ret;
177 }
178
179 API int zb_simple_desc_create(zb_zdo_simple_desc_h *handle)
180 {
181         CHECK_FEATURE_SUPPORTED(ZIGBEE_FEATURE);
182         RETV_IF(NULL == handle, ZIGBEE_ERROR_INVALID_PARAMETER);
183         zb_zdo_simple_desc_h desc = NULL;
184         CHECK_ZIGBEE_PRIVILEGE();
185
186         desc = calloc(1, sizeof(struct zb_zdo_simple_desc_s));
187         RETVM_IF(NULL == desc, ZIGBEE_ERROR_OUT_OF_MEMORY, "calloc() Fail(%d)", errno);
188         *handle = desc;
189         return ZIGBEE_ERROR_NONE;
190 }
191
192 API int zb_simple_desc_clone(zb_zdo_simple_desc_h src, zb_zdo_simple_desc_h *dst)
193 {
194         zb_zdo_simple_desc_h desc = NULL;
195
196         CHECK_FEATURE_SUPPORTED(ZIGBEE_FEATURE);
197         RETV_IF(NULL == src, ZIGBEE_ERROR_INVALID_PARAMETER);
198         RETV_IF(NULL == dst, ZIGBEE_ERROR_INVALID_PARAMETER);
199
200         desc = calloc(1, sizeof(struct zb_zdo_simple_desc_s));
201         RETVM_IF(NULL == desc, ZIGBEE_ERROR_OUT_OF_MEMORY, "calloc() Fail(%d)", errno);
202
203         memcpy(desc, src, sizeof(struct zb_zdo_simple_desc_s));
204         *dst = desc;
205
206         return ZIGBEE_ERROR_NONE;
207 }
208
209 API int zb_simple_desc_destroy(zb_zdo_simple_desc_h handle)
210 {
211         struct zb_zdo_simple_desc_s *h = handle;
212         CHECK_FEATURE_SUPPORTED(ZIGBEE_FEATURE);
213         RETV_IF(NULL == handle, ZIGBEE_ERROR_INVALID_PARAMETER);
214
215         free(h);
216         return ZIGBEE_ERROR_NONE;
217 }
218
219 API int zb_simple_desc_get_ep(zb_zdo_simple_desc_h handle, unsigned char *ep)
220 {
221         struct zb_zdo_simple_desc_s *h = handle;
222         CHECK_FEATURE_SUPPORTED(ZIGBEE_FEATURE);
223         RETV_IF(NULL == handle, ZIGBEE_ERROR_INVALID_PARAMETER);
224         RETV_IF(NULL == ep, ZIGBEE_ERROR_INVALID_PARAMETER);
225
226         *ep = h->ep;
227         return ZIGBEE_ERROR_NONE;
228 }
229
230 API int zb_simple_desc_set_ep(zb_zdo_simple_desc_h handle, unsigned char ep)
231 {
232         struct zb_zdo_simple_desc_s *h = handle;
233         CHECK_FEATURE_SUPPORTED(ZIGBEE_FEATURE);
234         RETV_IF(NULL == handle, ZIGBEE_ERROR_INVALID_PARAMETER);
235
236         h->ep = ep;
237         return ZIGBEE_ERROR_NONE;
238 }
239
240 API int zb_simple_desc_get_profile_id(zb_zdo_simple_desc_h handle,
241         unsigned short *profileid)
242 {
243         struct zb_zdo_simple_desc_s *h = handle;
244         CHECK_FEATURE_SUPPORTED(ZIGBEE_FEATURE);
245         RETV_IF(NULL == handle, ZIGBEE_ERROR_INVALID_PARAMETER);
246         RETV_IF(NULL == profileid, ZIGBEE_ERROR_INVALID_PARAMETER);
247
248         *profileid = h->profileid;
249         return ZIGBEE_ERROR_NONE;
250 }
251
252 API int zb_simple_desc_set_profile_id(zb_zdo_simple_desc_h handle,
253         unsigned short profileid)
254 {
255         struct zb_zdo_simple_desc_s *h = handle;
256         CHECK_FEATURE_SUPPORTED(ZIGBEE_FEATURE);
257         RETV_IF(NULL == handle, ZIGBEE_ERROR_INVALID_PARAMETER);
258
259         h->profileid = profileid;
260         return ZIGBEE_ERROR_NONE;
261 }
262
263
264 API int zb_simple_desc_get_device_id(zb_zdo_simple_desc_h handle,
265         unsigned short *deviceid)
266 {
267         struct zb_zdo_simple_desc_s *h = handle;
268         CHECK_FEATURE_SUPPORTED(ZIGBEE_FEATURE);
269         RETV_IF(NULL == handle, ZIGBEE_ERROR_INVALID_PARAMETER);
270         RETV_IF(NULL == deviceid, ZIGBEE_ERROR_INVALID_PARAMETER);
271
272         *deviceid = h->deviceid;
273         return ZIGBEE_ERROR_NONE;
274 }
275
276 API int zb_simple_desc_set_device_id(zb_zdo_simple_desc_h handle,
277         unsigned short deviceid)
278 {
279         struct zb_zdo_simple_desc_s *h = handle;
280         CHECK_FEATURE_SUPPORTED(ZIGBEE_FEATURE);
281         RETV_IF(NULL == handle, ZIGBEE_ERROR_INVALID_PARAMETER);
282
283         h->deviceid = deviceid;
284         return ZIGBEE_ERROR_NONE;
285 }
286
287 API int zb_simple_desc_get_device_ver(zb_zdo_simple_desc_h handle,
288         unsigned short *device_ver)
289 {
290         struct zb_zdo_simple_desc_s *h = handle;
291         CHECK_FEATURE_SUPPORTED(ZIGBEE_FEATURE);
292         RETV_IF(NULL == handle, ZIGBEE_ERROR_INVALID_PARAMETER);
293         RETV_IF(NULL == device_ver, ZIGBEE_ERROR_INVALID_PARAMETER);
294
295         *device_ver = h->device_ver;
296         return ZIGBEE_ERROR_NONE;
297 }
298
299 API int zb_simple_desc_set_device_ver(zb_zdo_simple_desc_h handle,
300         unsigned short device_ver)
301 {
302         struct zb_zdo_simple_desc_s *h = handle;
303         CHECK_FEATURE_SUPPORTED(ZIGBEE_FEATURE);
304         RETV_IF(NULL == handle, ZIGBEE_ERROR_INVALID_PARAMETER);
305
306         h->device_ver = device_ver;
307         return ZIGBEE_ERROR_NONE;
308 }
309
310 API int zb_simple_desc_get_num_of_in_clusters(zb_zdo_simple_desc_h handle,
311         unsigned char *num_of_in_clusters)
312 {
313         struct zb_zdo_simple_desc_s *h = handle;
314         CHECK_FEATURE_SUPPORTED(ZIGBEE_FEATURE);
315         RETV_IF(NULL == handle, ZIGBEE_ERROR_INVALID_PARAMETER);
316         RETV_IF(NULL == num_of_in_clusters, ZIGBEE_ERROR_INVALID_PARAMETER);
317
318         *num_of_in_clusters = h->num_of_in_clusters;
319         return ZIGBEE_ERROR_NONE;
320 }
321
322 API int zb_simple_desc_set_num_of_in_clusters(zb_zdo_simple_desc_h handle,
323         unsigned char num_of_in_clusters)
324 {
325         struct zb_zdo_simple_desc_s *h = handle;
326         CHECK_FEATURE_SUPPORTED(ZIGBEE_FEATURE);
327         RETV_IF(NULL == handle, ZIGBEE_ERROR_INVALID_PARAMETER);
328
329         h->num_of_in_clusters = num_of_in_clusters;
330         return ZIGBEE_ERROR_NONE;
331 }
332
333 API int zb_simple_desc_get_num_of_out_clusters(zb_zdo_simple_desc_h handle,
334         unsigned char *num_of_out_clusters)
335 {
336         struct zb_zdo_simple_desc_s *h = handle;
337         CHECK_FEATURE_SUPPORTED(ZIGBEE_FEATURE);
338         RETV_IF(NULL == handle, ZIGBEE_ERROR_INVALID_PARAMETER);
339         RETV_IF(NULL == num_of_out_clusters, ZIGBEE_ERROR_INVALID_PARAMETER);
340
341         *num_of_out_clusters = h->num_of_out_clusters;
342         return ZIGBEE_ERROR_NONE;
343 }
344
345 API int zb_simple_desc_set_num_of_out_clusters(zb_zdo_simple_desc_h handle,
346         unsigned char num_of_out_clusters)
347 {
348         struct zb_zdo_simple_desc_s *h = handle;
349         CHECK_FEATURE_SUPPORTED(ZIGBEE_FEATURE);
350         RETV_IF(NULL == handle, ZIGBEE_ERROR_INVALID_PARAMETER);
351
352         h->num_of_out_clusters = num_of_out_clusters;
353         return ZIGBEE_ERROR_NONE;
354 }
355
356 API int zb_simple_desc_get_in_clusters(zb_zdo_simple_desc_h handle,
357         unsigned short **in_clusters)
358 {
359         struct zb_zdo_simple_desc_s *h = handle;
360         CHECK_FEATURE_SUPPORTED(ZIGBEE_FEATURE);
361         RETV_IF(NULL == handle, ZIGBEE_ERROR_INVALID_PARAMETER);
362         RETV_IF(NULL == h->in_clusters, ZIGBEE_ERROR_INVALID_PARAMETER);
363         RETV_IF(NULL == in_clusters, ZIGBEE_ERROR_INVALID_PARAMETER);
364
365         *in_clusters = h->in_clusters;
366         return ZIGBEE_ERROR_NONE;
367 }
368
369 API int zb_simple_desc_set_in_clusters(zb_zdo_simple_desc_h handle,
370         unsigned short *in_clusters, int num)
371 {
372         struct zb_zdo_simple_desc_s *h = handle;
373         CHECK_FEATURE_SUPPORTED(ZIGBEE_FEATURE);
374         RETV_IF(NULL == handle, ZIGBEE_ERROR_INVALID_PARAMETER);
375         RETV_IF(NULL == in_clusters, ZIGBEE_ERROR_INVALID_PARAMETER);
376         RETV_IF(num < 1 || num > MAX_ENDPOINT_CLUSTERS, ZIGBEE_ERROR_INVALID_PARAMETER);
377
378         memcpy(h->in_clusters, in_clusters, 2 * num);
379         return ZIGBEE_ERROR_NONE;
380 }
381
382 API int zb_simple_desc_get_out_clusters(zb_zdo_simple_desc_h handle,
383         unsigned short **out_clusters)
384 {
385         struct zb_zdo_simple_desc_s *h = handle;
386         CHECK_FEATURE_SUPPORTED(ZIGBEE_FEATURE);
387         RETV_IF(NULL == handle, ZIGBEE_ERROR_INVALID_PARAMETER);
388         RETV_IF(NULL == h->out_clusters, ZIGBEE_ERROR_INVALID_PARAMETER);
389         RETV_IF(NULL == out_clusters, ZIGBEE_ERROR_INVALID_PARAMETER);
390
391         *out_clusters = h->out_clusters;
392         return ZIGBEE_ERROR_NONE;
393 }
394
395 API int zb_simple_desc_set_out_clusters(zb_zdo_simple_desc_h handle,
396         unsigned short *out_clusters, int num)
397 {
398         struct zb_zdo_simple_desc_s *h = handle;
399         CHECK_FEATURE_SUPPORTED(ZIGBEE_FEATURE);
400         RETV_IF(NULL == handle, ZIGBEE_ERROR_INVALID_PARAMETER);
401         RETV_IF(NULL == out_clusters, ZIGBEE_ERROR_INVALID_PARAMETER);
402         RETV_IF(num < 1 || num > MAX_ENDPOINT_CLUSTERS, ZIGBEE_ERROR_INVALID_PARAMETER);
403
404         memcpy(h->out_clusters, out_clusters, 2 * num);
405         return ZIGBEE_ERROR_NONE;
406 }
407
408 API int zb_node_power_desc_create(zb_zdo_node_power_descriptor_h *handle)
409 {
410         zb_zdo_node_power_descriptor_h desc = NULL;
411
412         CHECK_ZIGBEE_PRIVILEGE();
413         CHECK_FEATURE_SUPPORTED(ZIGBEE_FEATURE);
414         RETV_IF(NULL == handle, ZIGBEE_ERROR_INVALID_PARAMETER);
415
416         desc = calloc(1, sizeof(struct zb_zdo_node_power_descriptor_s));
417         RETVM_IF(NULL == desc, ZIGBEE_ERROR_OUT_OF_MEMORY, "calloc() Fail(%d)", errno);
418         *handle = desc;
419
420         return ZIGBEE_ERROR_NONE;
421 }
422
423 API int zb_node_power_desc_clone(zb_zdo_node_power_descriptor_h src,
424         zb_zdo_node_power_descriptor_h *dst)
425 {
426         zb_zdo_node_power_descriptor_h desc = NULL;
427
428         CHECK_FEATURE_SUPPORTED(ZIGBEE_FEATURE);
429         RETV_IF(NULL == src, ZIGBEE_ERROR_INVALID_PARAMETER);
430         RETV_IF(NULL == dst, ZIGBEE_ERROR_INVALID_PARAMETER);
431
432         desc = calloc(1, sizeof(struct zb_zdo_node_power_descriptor_s));
433         RETVM_IF(NULL == desc, ZIGBEE_ERROR_OUT_OF_MEMORY, "calloc() Fail(%d)", errno);
434
435         memcpy(desc, src, sizeof(struct zb_zdo_node_power_descriptor_s));
436         *dst = desc;
437
438         return ZIGBEE_ERROR_NONE;
439 }
440
441 API int zb_node_power_desc_destroy(zb_zdo_node_power_descriptor_h handle)
442 {
443         struct zb_zdo_node_power_descriptor_s* h = handle;
444         CHECK_FEATURE_SUPPORTED(ZIGBEE_FEATURE);
445         RETV_IF(NULL == handle, ZIGBEE_ERROR_INVALID_PARAMETER);
446
447         free(h);
448         return ZIGBEE_ERROR_NONE;
449 }
450
451 API int zb_node_power_desc_get_current_power_mode(
452         zb_zdo_node_power_descriptor_h handle, zb_zdp_cur_pwr_mode_e* current_power_mode)
453 {
454         struct zb_zdo_node_power_descriptor_s* h = handle;
455         CHECK_FEATURE_SUPPORTED(ZIGBEE_FEATURE);
456         RETV_IF(NULL == handle, ZIGBEE_ERROR_INVALID_PARAMETER);
457         RETV_IF(NULL == current_power_mode, ZIGBEE_ERROR_INVALID_PARAMETER);
458
459         *current_power_mode = h->current_power_mode;
460         return ZIGBEE_ERROR_NONE;
461 }
462
463 API int zb_node_power_desc_set_current_power_mode(
464         zb_zdo_node_power_descriptor_h handle, zb_zdp_cur_pwr_mode_e current_power_mode)
465 {
466         struct zb_zdo_node_power_descriptor_s* h = handle;
467         CHECK_FEATURE_SUPPORTED(ZIGBEE_FEATURE);
468         RETV_IF(NULL == handle, ZIGBEE_ERROR_INVALID_PARAMETER);
469         RETV_IF(0b11 < current_power_mode, ZIGBEE_ERROR_PARAMETER_OUT_OF_RANGE);
470
471         h->current_power_mode = current_power_mode;
472         return ZIGBEE_ERROR_NONE;
473 }
474
475 API int zb_node_power_desc_get_available_power_sources(
476         zb_zdo_node_power_descriptor_h handle, zb_zdp_pwr_src_type_e* available_power_sources)
477 {
478         struct zb_zdo_node_power_descriptor_s* h = handle;
479         CHECK_FEATURE_SUPPORTED(ZIGBEE_FEATURE);
480         RETV_IF(NULL == handle, ZIGBEE_ERROR_INVALID_PARAMETER);
481         RETV_IF(NULL == available_power_sources, ZIGBEE_ERROR_INVALID_PARAMETER);
482
483         *available_power_sources = h->available_power_sources;
484         return ZIGBEE_ERROR_NONE;
485 }
486
487 API int zb_node_power_desc_set_available_power_sources(
488         zb_zdo_node_power_descriptor_h handle, zb_zdp_pwr_src_type_e available_power_sources)
489 {
490         struct zb_zdo_node_power_descriptor_s* h = handle;
491         CHECK_FEATURE_SUPPORTED(ZIGBEE_FEATURE);
492         RETV_IF(NULL == handle, ZIGBEE_ERROR_INVALID_PARAMETER);
493         RETV_IF(0b111 < available_power_sources, ZIGBEE_ERROR_PARAMETER_OUT_OF_RANGE);
494
495         h->available_power_sources = available_power_sources;
496         return ZIGBEE_ERROR_NONE;
497 }
498
499 API int zb_node_power_desc_get_current_power_source(
500         zb_zdo_node_power_descriptor_h handle, zb_zdp_pwr_src_type_e* current_power_source)
501 {
502         struct zb_zdo_node_power_descriptor_s* h = handle;
503         CHECK_FEATURE_SUPPORTED(ZIGBEE_FEATURE);
504         RETV_IF(NULL == handle, ZIGBEE_ERROR_INVALID_PARAMETER);
505         RETV_IF(NULL == current_power_source, ZIGBEE_ERROR_INVALID_PARAMETER);
506
507         *current_power_source = h->current_power_source;
508         return ZIGBEE_ERROR_NONE;
509 }
510
511 API int zb_node_power_desc_set_current_power_source(
512         zb_zdo_node_power_descriptor_h handle, zb_zdp_pwr_src_type_e current_power_source)
513 {
514         struct zb_zdo_node_power_descriptor_s* h = handle;
515         CHECK_FEATURE_SUPPORTED(ZIGBEE_FEATURE);
516         RETV_IF(NULL == handle, ZIGBEE_ERROR_INVALID_PARAMETER);
517         RETV_IF(0b111 < current_power_source, ZIGBEE_ERROR_PARAMETER_OUT_OF_RANGE);
518
519         h->current_power_source = current_power_source;
520         return ZIGBEE_ERROR_NONE;
521 }
522
523 API int zb_node_power_desc_get_current_power_source_level(
524         zb_zdo_node_power_descriptor_h handle, zb_zdp_pwr_src_level_e* current_power_source_level)
525 {
526         struct zb_zdo_node_power_descriptor_s* h = handle;
527         CHECK_FEATURE_SUPPORTED(ZIGBEE_FEATURE);
528         RETV_IF(NULL == handle, ZIGBEE_ERROR_INVALID_PARAMETER);
529         RETV_IF(NULL == current_power_source_level, ZIGBEE_ERROR_INVALID_PARAMETER);
530
531         *current_power_source_level = h->current_power_source_level;
532         return ZIGBEE_ERROR_NONE;
533 }
534
535 API int zb_node_power_desc_set_current_power_source_level(
536         zb_zdo_node_power_descriptor_h handle, zb_zdp_pwr_src_level_e current_power_source_level)
537 {
538         struct zb_zdo_node_power_descriptor_s* h = handle;
539         CHECK_FEATURE_SUPPORTED(ZIGBEE_FEATURE);
540         RETV_IF(NULL == handle, ZIGBEE_ERROR_INVALID_PARAMETER);
541
542         h->current_power_source_level = current_power_source_level;
543         return ZIGBEE_ERROR_NONE;
544 }
545
546 API int zb_node_desc_create(zb_zdo_node_descriptor_h *handle)
547 {
548         CHECK_FEATURE_SUPPORTED(ZIGBEE_FEATURE);
549         RETV_IF(NULL == handle, ZIGBEE_ERROR_INVALID_PARAMETER);
550         zb_zdo_node_descriptor_h desc = NULL;
551
552         CHECK_ZIGBEE_PRIVILEGE();
553
554         desc = calloc(1, sizeof(struct zb_zdo_node_descriptor_s));
555         RETVM_IF(NULL == desc, ZIGBEE_ERROR_OUT_OF_MEMORY, "calloc() Fail(%d)", errno);
556         *handle = desc;
557         return ZIGBEE_ERROR_NONE;
558 }
559
560 API int zb_node_desc_clone(zb_zdo_node_descriptor_h src,
561         zb_zdo_node_descriptor_h *dst)
562 {
563         struct zb_zdo_node_descriptor_s* desc = NULL;
564
565         CHECK_FEATURE_SUPPORTED(ZIGBEE_FEATURE);
566         RETV_IF(NULL == src, ZIGBEE_ERROR_INVALID_PARAMETER);
567         RETV_IF(NULL == dst, ZIGBEE_ERROR_INVALID_PARAMETER);
568
569         desc = calloc(1, sizeof(struct zb_zdo_node_descriptor_s));
570         RETVM_IF(NULL == desc, ZIGBEE_ERROR_OUT_OF_MEMORY, "calloc() Fail(%d)", errno);
571
572         memcpy(desc, src, sizeof(struct zb_zdo_node_descriptor_s));
573         *dst = desc;
574
575         return ZIGBEE_ERROR_NONE;
576 }
577
578 API int zb_node_desc_destroy(zb_zdo_node_descriptor_h handle)
579 {
580         struct zb_zdo_node_descriptor_s* h = handle;
581         CHECK_FEATURE_SUPPORTED(ZIGBEE_FEATURE);
582         RETV_IF(NULL == handle, ZIGBEE_ERROR_INVALID_PARAMETER);
583
584         free(h);
585         return ZIGBEE_ERROR_NONE;
586 }
587
588 API int zb_node_desc_get_logical_type(zb_zdo_node_descriptor_h handle,
589         unsigned char* logical_type)
590 {
591         struct zb_zdo_node_descriptor_s* h = handle;
592         CHECK_FEATURE_SUPPORTED(ZIGBEE_FEATURE);
593         RETV_IF(NULL == handle, ZIGBEE_ERROR_INVALID_PARAMETER);
594         RETV_IF(NULL == logical_type, ZIGBEE_ERROR_INVALID_PARAMETER);
595
596         *logical_type = h->logical_type;
597         return ZIGBEE_ERROR_NONE;
598 }
599
600 API int zb_node_desc_set_logical_type(zb_zdo_node_descriptor_h handle,
601         unsigned char logical_type)
602 {
603         struct zb_zdo_node_descriptor_s* h = handle;
604         CHECK_FEATURE_SUPPORTED(ZIGBEE_FEATURE);
605         RETV_IF(NULL == handle, ZIGBEE_ERROR_INVALID_PARAMETER);
606         RETV_IF(0b11 < logical_type, ZIGBEE_ERROR_PARAMETER_OUT_OF_RANGE);
607
608         h->logical_type = logical_type;
609         return ZIGBEE_ERROR_NONE;
610 }
611
612 API int zb_node_desc_get_complex_desciptor_available(
613         zb_zdo_node_descriptor_h handle, unsigned char* complex_desciptor_available)
614 {
615         struct zb_zdo_node_descriptor_s* h = handle;
616         CHECK_FEATURE_SUPPORTED(ZIGBEE_FEATURE);
617         RETV_IF(NULL == handle, ZIGBEE_ERROR_INVALID_PARAMETER);
618         RETV_IF(NULL == complex_desciptor_available, ZIGBEE_ERROR_INVALID_PARAMETER);
619
620         *complex_desciptor_available = h->complex_desciptor_available;
621         return ZIGBEE_ERROR_NONE;
622 }
623
624 API int zb_node_desc_set_complex_descriptor_available(
625         zb_zdo_node_descriptor_h handle, unsigned char complex_desciptor_available)
626 {
627         struct zb_zdo_node_descriptor_s* h = handle;
628         CHECK_FEATURE_SUPPORTED(ZIGBEE_FEATURE);
629         RETV_IF(NULL == handle, ZIGBEE_ERROR_INVALID_PARAMETER);
630         RETV_IF(0x01 < complex_desciptor_available, ZIGBEE_ERROR_PARAMETER_OUT_OF_RANGE);
631
632         h->complex_desciptor_available = complex_desciptor_available;
633         return ZIGBEE_ERROR_NONE;
634 }
635
636 API int zb_node_desc_get_user_descriptor_available(
637         zb_zdo_node_descriptor_h handle, unsigned char* user_descriptor_available)
638 {
639         struct zb_zdo_node_descriptor_s* h = handle;
640         CHECK_FEATURE_SUPPORTED(ZIGBEE_FEATURE);
641         RETV_IF(NULL == handle, ZIGBEE_ERROR_INVALID_PARAMETER);
642         RETV_IF(NULL == user_descriptor_available, ZIGBEE_ERROR_INVALID_PARAMETER);
643
644         *user_descriptor_available = h->user_descriptor_available;
645         return ZIGBEE_ERROR_NONE;
646 }
647
648 API int zb_node_desc_set_user_descriptor_available(
649         zb_zdo_node_descriptor_h handle, unsigned char user_descriptor_available)
650 {
651         struct zb_zdo_node_descriptor_s* h = handle;
652         CHECK_FEATURE_SUPPORTED(ZIGBEE_FEATURE);
653         RETV_IF(NULL == handle, ZIGBEE_ERROR_INVALID_PARAMETER);
654         RETV_IF(0x01 < user_descriptor_available, ZIGBEE_ERROR_PARAMETER_OUT_OF_RANGE);
655
656         h->user_descriptor_available = user_descriptor_available;
657         return ZIGBEE_ERROR_NONE;
658 }
659
660 API int zb_node_desc_get_aps_flags(zb_zdo_node_descriptor_h handle,
661         unsigned char* aps_flags)
662 {
663         struct zb_zdo_node_descriptor_s* h = handle;
664         CHECK_FEATURE_SUPPORTED(ZIGBEE_FEATURE);
665         RETV_IF(NULL == handle, ZIGBEE_ERROR_INVALID_PARAMETER);
666         RETV_IF(NULL == aps_flags, ZIGBEE_ERROR_INVALID_PARAMETER);
667
668         *aps_flags = h->aps_flags;
669         return ZIGBEE_ERROR_NONE;
670 }
671
672 API int zb_node_desc_set_aps_flags(zb_zdo_node_descriptor_h handle,
673         unsigned char aps_flags)
674 {
675         struct zb_zdo_node_descriptor_s* h = handle;
676         CHECK_FEATURE_SUPPORTED(ZIGBEE_FEATURE);
677         RETV_IF(NULL == handle, ZIGBEE_ERROR_INVALID_PARAMETER);
678         RETV_IF(0b111 < aps_flags, ZIGBEE_ERROR_PARAMETER_OUT_OF_RANGE);
679
680         h->aps_flags = aps_flags;
681         return ZIGBEE_ERROR_NONE;
682 }
683
684 API int zb_node_desc_get_frequency_band(zb_zdo_node_descriptor_h handle,
685         unsigned char* frequency_band)
686 {
687         struct zb_zdo_node_descriptor_s* h = handle;
688         CHECK_FEATURE_SUPPORTED(ZIGBEE_FEATURE);
689         RETV_IF(NULL == handle, ZIGBEE_ERROR_INVALID_PARAMETER);
690         RETV_IF(NULL == frequency_band, ZIGBEE_ERROR_INVALID_PARAMETER);
691
692         *frequency_band = h->frequency_band;
693         return ZIGBEE_ERROR_NONE;
694 }
695
696 API int zb_node_desc_set_frequency_band(zb_zdo_node_descriptor_h handle,
697         unsigned char frequency_band)
698 {
699         struct zb_zdo_node_descriptor_s* h = handle;
700         CHECK_FEATURE_SUPPORTED(ZIGBEE_FEATURE);
701         RETV_IF(NULL == handle, ZIGBEE_ERROR_INVALID_PARAMETER);
702         RETV_IF(0b1111 < frequency_band, ZIGBEE_ERROR_PARAMETER_OUT_OF_RANGE);
703
704         h->frequency_band = frequency_band;
705         return ZIGBEE_ERROR_NONE;
706 }
707
708
709 API int zb_node_desc_get_mac_capability_flags(zb_zdo_node_descriptor_h handle,
710         unsigned char* mac_capability_flags)
711 {
712         struct zb_zdo_node_descriptor_s* h = handle;
713         CHECK_FEATURE_SUPPORTED(ZIGBEE_FEATURE);
714         RETV_IF(NULL == handle, ZIGBEE_ERROR_INVALID_PARAMETER);
715         RETV_IF(NULL == mac_capability_flags, ZIGBEE_ERROR_INVALID_PARAMETER);
716
717         *mac_capability_flags = h->mac_capability_flags;
718         return ZIGBEE_ERROR_NONE;
719 }
720
721 API int zb_node_desc_set_mac_capability_flags(zb_zdo_node_descriptor_h handle,
722         unsigned char mac_capability_flags)
723 {
724         struct zb_zdo_node_descriptor_s* h = handle;
725         CHECK_FEATURE_SUPPORTED(ZIGBEE_FEATURE);
726         RETV_IF(NULL == handle, ZIGBEE_ERROR_INVALID_PARAMETER);
727
728         h->mac_capability_flags = mac_capability_flags;
729         return ZIGBEE_ERROR_NONE;
730 }
731
732 API int zb_node_desc_get_manufacturer_code(zb_zdo_node_descriptor_h handle,
733         unsigned short* manufacturer_code)
734 {
735         struct zb_zdo_node_descriptor_s* h = handle;
736         CHECK_FEATURE_SUPPORTED(ZIGBEE_FEATURE);
737         RETV_IF(NULL == handle, ZIGBEE_ERROR_INVALID_PARAMETER);
738         RETV_IF(NULL == manufacturer_code, ZIGBEE_ERROR_INVALID_PARAMETER);
739
740         *manufacturer_code = h->manufacturer_code;
741         return ZIGBEE_ERROR_NONE;
742 }
743
744 API int zb_node_desc_set_manufacturer_code(zb_zdo_node_descriptor_h handle,
745         unsigned short manufacturer_code)
746 {
747         struct zb_zdo_node_descriptor_s* h = handle;
748         CHECK_FEATURE_SUPPORTED(ZIGBEE_FEATURE);
749         RETV_IF(NULL == handle, ZIGBEE_ERROR_INVALID_PARAMETER);
750
751         h->manufacturer_code = manufacturer_code;
752         return ZIGBEE_ERROR_NONE;
753 }
754
755 API int zb_node_desc_get_maximum_buffer_size(zb_zdo_node_descriptor_h handle,
756         unsigned char* maximum_buffer_size)
757 {
758         struct zb_zdo_node_descriptor_s* h = handle;
759         CHECK_FEATURE_SUPPORTED(ZIGBEE_FEATURE);
760         RETV_IF(NULL == handle, ZIGBEE_ERROR_INVALID_PARAMETER);
761         RETV_IF(NULL == maximum_buffer_size, ZIGBEE_ERROR_INVALID_PARAMETER);
762
763         *maximum_buffer_size = h->maximum_buffer_size;
764         return ZIGBEE_ERROR_NONE;
765 }
766
767 API int zb_node_desc_set_maximum_buffer_size(zb_zdo_node_descriptor_h handle,
768         unsigned char maximum_buffer_size)
769 {
770         struct zb_zdo_node_descriptor_s* h = handle;
771         CHECK_FEATURE_SUPPORTED(ZIGBEE_FEATURE);
772         RETV_IF(NULL == handle, ZIGBEE_ERROR_INVALID_PARAMETER);
773         RETV_IF(0x7f < maximum_buffer_size, ZIGBEE_ERROR_PARAMETER_OUT_OF_RANGE);
774
775         h->maximum_buffer_size = maximum_buffer_size;
776         return ZIGBEE_ERROR_NONE;
777 }
778
779 API int zb_node_desc_get_maximum_incoming_transfer_size(
780         zb_zdo_node_descriptor_h handle, unsigned short* maximum_incoming_transfer_size)
781 {
782         struct zb_zdo_node_descriptor_s* h = handle;
783         CHECK_FEATURE_SUPPORTED(ZIGBEE_FEATURE);
784         RETV_IF(NULL == handle, ZIGBEE_ERROR_INVALID_PARAMETER);
785         RETV_IF(NULL == maximum_incoming_transfer_size, ZIGBEE_ERROR_INVALID_PARAMETER);
786
787         *maximum_incoming_transfer_size = h->maximum_incoming_transfer_size;
788         return ZIGBEE_ERROR_NONE;
789 }
790
791 API int zb_node_desc_set_maximum_incoming_transfer_size(
792         zb_zdo_node_descriptor_h handle, unsigned short maximum_incoming_transfer_size)
793 {
794         struct zb_zdo_node_descriptor_s* h = handle;
795         CHECK_FEATURE_SUPPORTED(ZIGBEE_FEATURE);
796         RETV_IF(NULL == handle, ZIGBEE_ERROR_INVALID_PARAMETER);
797         RETV_IF(0x7fff < maximum_incoming_transfer_size, ZIGBEE_ERROR_PARAMETER_OUT_OF_RANGE);
798
799         h->maximum_incoming_transfer_size = maximum_incoming_transfer_size;
800         return ZIGBEE_ERROR_NONE;
801 }
802
803 API int zb_node_desc_get_server_mask(zb_zdo_node_descriptor_h handle,
804         unsigned short* server_mask)
805 {
806         struct zb_zdo_node_descriptor_s* h = handle;
807         CHECK_FEATURE_SUPPORTED(ZIGBEE_FEATURE);
808         RETV_IF(NULL == handle, ZIGBEE_ERROR_INVALID_PARAMETER);
809         RETV_IF(NULL == server_mask, ZIGBEE_ERROR_INVALID_PARAMETER);
810
811         *server_mask = h->server_mask;
812         return ZIGBEE_ERROR_NONE;
813 }
814
815 API int zb_node_desc_set_server_mask(zb_zdo_node_descriptor_h handle,
816         unsigned short server_mask)
817 {
818         struct zb_zdo_node_descriptor_s* h = handle;
819         CHECK_FEATURE_SUPPORTED(ZIGBEE_FEATURE);
820         RETV_IF(NULL == handle, ZIGBEE_ERROR_INVALID_PARAMETER);
821         RETV_IF(0x7f < server_mask, ZIGBEE_ERROR_PARAMETER_OUT_OF_RANGE);
822
823         h->server_mask = server_mask;
824         return ZIGBEE_ERROR_NONE;
825 }
826
827 API int zb_node_desc_get_maximum_outgoing_transfer_size(
828         zb_zdo_node_descriptor_h handle, unsigned short* maximum_outgoing_transfer_size)
829 {
830         struct zb_zdo_node_descriptor_s* h = handle;
831         CHECK_FEATURE_SUPPORTED(ZIGBEE_FEATURE);
832         RETV_IF(NULL == handle, ZIGBEE_ERROR_INVALID_PARAMETER);
833         RETV_IF(NULL == maximum_outgoing_transfer_size, ZIGBEE_ERROR_INVALID_PARAMETER);
834
835         *maximum_outgoing_transfer_size = h->maximum_outgoing_transfer_size;
836         return ZIGBEE_ERROR_NONE;
837 }
838
839 API int zb_node_desc_set_maximum_outgoing_transfer_size(
840         zb_zdo_node_descriptor_h handle, unsigned short maximum_outgoing_transfer_size)
841 {
842         struct zb_zdo_node_descriptor_s* h = handle;
843         CHECK_FEATURE_SUPPORTED(ZIGBEE_FEATURE);
844         RETV_IF(NULL == handle, ZIGBEE_ERROR_INVALID_PARAMETER);
845         RETV_IF(0x7fff < maximum_outgoing_transfer_size, ZIGBEE_ERROR_PARAMETER_OUT_OF_RANGE);
846
847         h->maximum_outgoing_transfer_size = maximum_outgoing_transfer_size;
848         return ZIGBEE_ERROR_NONE;
849 }
850
851 API int zb_node_desc_get_descriptor_capability_field(
852         zb_zdo_node_descriptor_h handle, unsigned short* descriptor_capability_field)
853 {
854         struct zb_zdo_node_descriptor_s* h = handle;
855         CHECK_FEATURE_SUPPORTED(ZIGBEE_FEATURE);
856         RETV_IF(NULL == handle, ZIGBEE_ERROR_INVALID_PARAMETER);
857         RETV_IF(NULL == descriptor_capability_field, ZIGBEE_ERROR_INVALID_PARAMETER);
858
859         *descriptor_capability_field = h->descriptor_capability_field;
860         return ZIGBEE_ERROR_NONE;
861 }
862
863 API int zb_node_desc_set_descriptor_capability_field(
864         zb_zdo_node_descriptor_h handle, unsigned short descriptor_capability_field)
865 {
866         struct zb_zdo_node_descriptor_s* h = handle;
867         CHECK_FEATURE_SUPPORTED(ZIGBEE_FEATURE);
868         RETV_IF(NULL == handle, ZIGBEE_ERROR_INVALID_PARAMETER);
869         RETV_IF(0x11 < descriptor_capability_field, ZIGBEE_ERROR_PARAMETER_OUT_OF_RANGE);
870
871         h->descriptor_capability_field = descriptor_capability_field;
872         return ZIGBEE_ERROR_NONE;
873 }
874