xref: /btstack/src/classic/obex_iterator.h (revision 2fca4dad957cd7b88f4657ed51e89c12615dda72)
1f1b34e8dSMatthias Ringwald /*
2f1b34e8dSMatthias Ringwald  * Copyright (C) 2014 BlueKitchen GmbH
3f1b34e8dSMatthias Ringwald  *
4f1b34e8dSMatthias Ringwald  * Redistribution and use in source and binary forms, with or without
5f1b34e8dSMatthias Ringwald  * modification, are permitted provided that the following conditions
6f1b34e8dSMatthias Ringwald  * are met:
7f1b34e8dSMatthias Ringwald  *
8f1b34e8dSMatthias Ringwald  * 1. Redistributions of source code must retain the above copyright
9f1b34e8dSMatthias Ringwald  *    notice, this list of conditions and the following disclaimer.
10f1b34e8dSMatthias Ringwald  * 2. Redistributions in binary form must reproduce the above copyright
11f1b34e8dSMatthias Ringwald  *    notice, this list of conditions and the following disclaimer in the
12f1b34e8dSMatthias Ringwald  *    documentation and/or other materials provided with the distribution.
13f1b34e8dSMatthias Ringwald  * 3. Neither the name of the copyright holders nor the names of
14f1b34e8dSMatthias Ringwald  *    contributors may be used to endorse or promote products derived
15f1b34e8dSMatthias Ringwald  *    from this software without specific prior written permission.
16f1b34e8dSMatthias Ringwald  * 4. Any redistribution, use, or modification is done solely for
17f1b34e8dSMatthias Ringwald  *    personal benefit and not for any commercial purpose or for
18f1b34e8dSMatthias Ringwald  *    monetary gain.
19f1b34e8dSMatthias Ringwald  *
20f1b34e8dSMatthias Ringwald  * THIS SOFTWARE IS PROVIDED BY BLUEKITCHEN GMBH AND CONTRIBUTORS
21f1b34e8dSMatthias Ringwald  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
22f1b34e8dSMatthias Ringwald  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
23*2fca4dadSMilanka Ringwald  * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL BLUEKITCHEN
24*2fca4dadSMilanka Ringwald  * GMBH OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
25f1b34e8dSMatthias Ringwald  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
26f1b34e8dSMatthias Ringwald  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
27f1b34e8dSMatthias Ringwald  * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
28f1b34e8dSMatthias Ringwald  * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
29f1b34e8dSMatthias Ringwald  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
30f1b34e8dSMatthias Ringwald  * THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
31f1b34e8dSMatthias Ringwald  * SUCH DAMAGE.
32f1b34e8dSMatthias Ringwald  *
33f1b34e8dSMatthias Ringwald  * Please inquire about commercial licensing options at
34f1b34e8dSMatthias Ringwald  * [email protected]
35f1b34e8dSMatthias Ringwald  *
36f1b34e8dSMatthias Ringwald  */
37f1b34e8dSMatthias Ringwald 
38fe5a6c4eSMilanka Ringwald /**
39fe5a6c4eSMilanka Ringwald  * OBEX Iterator
40fe5a6c4eSMilanka Ringwald  *
41fe5a6c4eSMilanka Ringwald  */
42fe5a6c4eSMilanka Ringwald 
4380e33422SMatthias Ringwald #ifndef OBEX_ITERATOR_H
4480e33422SMatthias Ringwald #define OBEX_ITERATOR_H
45f1b34e8dSMatthias Ringwald 
46f1b34e8dSMatthias Ringwald #if defined __cplusplus
47f1b34e8dSMatthias Ringwald extern "C" {
48f1b34e8dSMatthias Ringwald #endif
49f1b34e8dSMatthias Ringwald 
50f1b34e8dSMatthias Ringwald #include <stdint.h>
51d1769b9fSMatthias Ringwald #include "btstack_bool.h"
52f1b34e8dSMatthias Ringwald 
53fe5a6c4eSMilanka Ringwald 
54f1b34e8dSMatthias Ringwald /* API_START */
55f1b34e8dSMatthias Ringwald 
56f1b34e8dSMatthias Ringwald typedef struct obex_iterator {
57f1b34e8dSMatthias Ringwald     const uint8_t * data;
58820092f9SMatthias Ringwald     uint16_t  offset;
59820092f9SMatthias Ringwald     uint16_t  length;
60d1769b9fSMatthias Ringwald     uint16_t  header_size;
61d1769b9fSMatthias Ringwald     uint16_t  data_size;
62d1769b9fSMatthias Ringwald     bool valid;
63f1b34e8dSMatthias Ringwald } obex_iterator_t;
64f1b34e8dSMatthias Ringwald 
65f1b34e8dSMatthias Ringwald // OBEX packet header iterator
66f1b34e8dSMatthias Ringwald void obex_iterator_init_with_request_packet(obex_iterator_t *context, const uint8_t * packet_data, uint16_t packet_len);
67f1b34e8dSMatthias Ringwald void obex_iterator_init_with_response_packet(obex_iterator_t *context, uint8_t request_opcode, const uint8_t * packet_data, uint16_t packet_len);
68f1b34e8dSMatthias Ringwald int  obex_iterator_has_more(const obex_iterator_t * context);
69f1b34e8dSMatthias Ringwald void obex_iterator_next(obex_iterator_t * context);
70f1b34e8dSMatthias Ringwald 
71f1b34e8dSMatthias Ringwald // OBEX packet header access functions
72f1b34e8dSMatthias Ringwald // @note BODY/END-OF-BODY headers might be incomplete
73f1b34e8dSMatthias Ringwald uint8_t         obex_iterator_get_hi(const obex_iterator_t * context);
74f1b34e8dSMatthias Ringwald uint8_t         obex_iterator_get_data_8(const obex_iterator_t * context);
75f1b34e8dSMatthias Ringwald uint32_t        obex_iterator_get_data_32(const obex_iterator_t * context);
76f1b34e8dSMatthias Ringwald uint32_t        obex_iterator_get_data_len(const obex_iterator_t * context);
77f1b34e8dSMatthias Ringwald const uint8_t * obex_iterator_get_data(const obex_iterator_t * context);
78f1b34e8dSMatthias Ringwald 
79f1b34e8dSMatthias Ringwald /* API_END */
80f1b34e8dSMatthias Ringwald 
81f1b34e8dSMatthias Ringwald // debug
82f1b34e8dSMatthias Ringwald void            obex_dump_packet(uint8_t request_opcode, uint8_t * packet, uint16_t size);
83f1b34e8dSMatthias Ringwald 
84f1b34e8dSMatthias Ringwald #if defined __cplusplus
85f1b34e8dSMatthias Ringwald }
86f1b34e8dSMatthias Ringwald #endif
87f1b34e8dSMatthias Ringwald #endif
88