3 * neard - Near Field Communication manager
5 * Copyright (C) 2011 Intel Corporation. All rights reserved.
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License version 2 as
9 * published by the Free Software Foundation.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
28 uint16_t near_tlv_length(uint8_t *tlv)
32 if (tlv[0] == TLV_NULL || tlv[0] == TLV_END)
34 else if (tlv[1] == 0xff)
35 length = g_ntohs(*(uint16_t *)(tlv + 2));
42 uint8_t *near_tlv_next(uint8_t *tlv)
47 length = near_tlv_length(tlv);
55 /* T (1 byte) + L (1 or 3 bytes) + V */
56 return tlv + 1 + l_length + length;
59 uint8_t *near_tlv_data(uint8_t *tlv)
64 length = near_tlv_length(tlv);
72 /* T (1 byte) + L (1 or 3 bytes) */
73 return tlv + 1 + l_length;
76 GList *near_tlv_parse(uint8_t *tlv, size_t tlv_length)
89 DBG("tlv 0x%x", tlv[0]);
93 DBG("NDEF found %d bytes long", near_tlv_length(tlv));
95 records = near_ndef_parse(near_tlv_data(tlv),
96 near_tlv_length(tlv));
106 tlv = near_tlv_next(tlv);
108 if (tlv - data >= (uint16_t) tlv_length)