ad_parser.c (ab2c6ae4b737d5e801d3defe4117331eb244ebb7) ad_parser.c (88949f844376f979826afad7a30727a235ee4f0c)
1/*
2 * Copyright (C) 2014 BlueKitchen GmbH
3 *
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
6 * are met:
7 *
8 * 1. Redistributions of source code must retain the above copyright

--- 50 unchanged lines hidden (view full) ---

59
60void ad_iterator_init(ad_context_t *context, uint8_t ad_len, const uint8_t * ad_data){
61 context->data = ad_data;
62 context->length = ad_len;
63 context->offset = 0;
64}
65
66int ad_iterator_has_more(const ad_context_t * context){
1/*
2 * Copyright (C) 2014 BlueKitchen GmbH
3 *
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
6 * are met:
7 *
8 * 1. Redistributions of source code must retain the above copyright

--- 50 unchanged lines hidden (view full) ---

59
60void ad_iterator_init(ad_context_t *context, uint8_t ad_len, const uint8_t * ad_data){
61 context->data = ad_data;
62 context->length = ad_len;
63 context->offset = 0;
64}
65
66int ad_iterator_has_more(const ad_context_t * context){
67 return context->offset < context->length;
67 // assert chunk_len and chunk_type are withing buffer
68 if ((context->offset+1) >= context->length) return 0;
69
70 // assert chunk_len > 0
71 int chunk_len = context->data[context->offset];
72 if (chunk_len == 0) return 0;
73
74 // assert complete chunk fits into buffer
75 if (context->offset + 1 + chunk_len > context->length) return 0;
76
77 return 1;
68}
69
78}
79
80// pre: ad_iterator_has_more() == 1
70void ad_iterator_next(ad_context_t * context){
71 int chunk_len = context->data[context->offset];
81void ad_iterator_next(ad_context_t * context){
82 int chunk_len = context->data[context->offset];
72 int new_offset = context->offset + 1 + chunk_len;
73 // avoid uint8_t overrun
74 if (new_offset > 0xff){
75 new_offset = 0xff;
76 }
77 context->offset = new_offset;
83 context->offset += 1 + chunk_len;
78}
79
80uint8_t ad_iterator_get_data_len(const ad_context_t * context){
81 return context->data[context->offset] - 1;
82}
83
84uint8_t ad_iterator_get_data_type(const ad_context_t * context){
85 return context->data[context->offset + 1];

--- 78 unchanged lines hidden ---
84}
85
86uint8_t ad_iterator_get_data_len(const ad_context_t * context){
87 return context->data[context->offset] - 1;
88}
89
90uint8_t ad_iterator_get_data_type(const ad_context_t * context){
91 return context->data[context->offset + 1];

--- 78 unchanged lines hidden ---