blob: 11cb01ea579226935d80fce5a996d5c73c7c870c [file] [log] [blame]
Harald Weltea43f7892009-12-01 18:04:30 +05301#ifndef _BITVEC_H
2#define _BITVEC_H
3
4/* bit vector utility routines */
5
6/* (C) 2009 by Harald Welte <laforge@gnumonks.org>
7 *
8 * All Rights Reserved
9 *
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or
13 * (at your option) any later version.
14 *
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
19 *
20 * You should have received a copy of the GNU General Public License along
21 * with this program; if not, write to the Free Software Foundation, Inc.,
22 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
23 *
24 */
25
26
27/* In GSM mac blocks, every bit can be 0 or 1, or L or H. L/H are
28 * defined relative to the 0x2b padding pattern */
29enum bit_value {
30 ZERO = 0,
31 ONE = 1,
32 L = 2,
33 H = 3,
34};
35
36struct bitvec {
37 unsigned int cur_bit; /* curser to the next unused bit */
38 unsigned int data_len; /* length of data array in bytes */
Harald Weltea3d55142010-02-20 19:10:44 +010039 uint8_t *data; /* pointer to data array */
Harald Weltea43f7892009-12-01 18:04:30 +053040};
41
Harald Welted57f1632009-12-14 22:04:31 +010042/* check if the bit is 0 or 1 for a given position inside a bitvec */
43enum bit_value bitvec_get_bit_pos(struct bitvec *bv, unsigned int bitnr);
44
Harald Welte7f73a1a2009-12-14 22:23:27 +010045/* get the Nth set bit inside the bit vector */
46unsigned int bitvec_get_nth_set_bit(struct bitvec *bv, unsigned int n);
47
Harald Weltea43f7892009-12-01 18:04:30 +053048/* Set a bit at given position */
49int bitvec_set_bit_pos(struct bitvec *bv, unsigned int bitnum,
50 enum bit_value bit);
51
52/* Set the next bit in the vector */
53int bitvec_set_bit(struct bitvec *bv, enum bit_value bit);
54
55/* Set multiple bits at the current position */
56int bitvec_set_bits(struct bitvec *bv, enum bit_value *bits, int count);
57
58/* Add an unsigned integer (of length count bits) to current position */
59int bitvec_set_uint(struct bitvec *bv, unsigned int in, int count);
60
61
62/* Pad the bit vector up to a certain bit position */
63int bitvec_spare_padding(struct bitvec *bv, unsigned int up_to_bit);
64
65#endif /* _BITVEC_H */