GNU Radio's GSM Package
bitvec.h
Go to the documentation of this file.
1 /* (C) 2009 by Harald Welte <laforge@gnumonks.org>
2  * (C) 2012 Ivan Klyuchnikov
3  * (C) 2015 sysmocom - s.f.m.c. GmbH
4  *
5  * All Rights Reserved
6  *
7  * This program is free software; you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License as published by
9  * the Free Software Foundation; either version 2 of the License, or
10  * (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License along
18  * with this program; if not, write to the Free Software Foundation, Inc.,
19  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
20  *
21  */
22 
23 #pragma once
24 
25 /*! \defgroup bitvec Bit vectors
26  * @{
27  * \file bitvec.h */
28 
29 #include <stdint.h>
30 //#include <osmocom/core/talloc.h>
31 #include <osmocom/core/defs.h>
32 #include <stdbool.h>
33 
34 /*! A single GSM bit
35  *
36  * In GSM mac blocks, every bit can be 0 or 1, or L or H. L/H are
37  * defined relative to the 0x2b padding pattern */
38 enum bit_value {
39  ZERO = 0, /*!< A zero (0) bit */
40  ONE = 1, /*!< A one (1) bit */
41  L = 2, /*!< A CSN.1 "L" bit */
42  H = 3, /*!< A CSN.1 "H" bit */
43 };
44 
45 /*! structure describing a bit vector */
46 struct bitvec {
47  unsigned int cur_bit; /*!< cursor to the next unused bit */
48  unsigned int data_len; /*!< length of data array in bytes */
49  uint8_t *data; /*!< pointer to data array */
50 };
51 
52 enum bit_value bitvec_get_bit_pos(const struct bitvec *bv, unsigned int bitnr);
53 enum bit_value bitvec_get_bit_pos_high(const struct bitvec *bv,
54  unsigned int bitnr);
55 unsigned int bitvec_get_nth_set_bit(const struct bitvec *bv, unsigned int n);
56 int bitvec_set_bit_pos(struct bitvec *bv, unsigned int bitnum,
57  enum bit_value bit);
58 int bitvec_set_bit(struct bitvec *bv, enum bit_value bit);
59 int bitvec_get_bit_high(struct bitvec *bv);
60 int bitvec_set_bits(struct bitvec *bv, const enum bit_value *bits, unsigned int count);
61 int bitvec_set_u64(struct bitvec *bv, uint64_t v, uint8_t num_bits, bool use_lh);
62 int bitvec_set_uint(struct bitvec *bv, unsigned int in, unsigned int count);
63 int bitvec_get_uint(struct bitvec *bv, unsigned int num_bits);
64 int bitvec_find_bit_pos(const struct bitvec *bv, unsigned int n, enum bit_value val);
65 int bitvec_spare_padding(struct bitvec *bv, unsigned int up_to_bit);
66 int bitvec_get_bytes(struct bitvec *bv, uint8_t *bytes, unsigned int count);
67 int bitvec_set_bytes(struct bitvec *bv, const uint8_t *bytes, unsigned int count);
68 /*struct bitvec *bitvec_alloc(unsigned int size, TALLOC_CTX *bvctx);*/
69 /*void bitvec_free(struct bitvec *bv);*/
70 int bitvec_unhex(struct bitvec *bv, const char *src);
71 unsigned int bitvec_pack(const struct bitvec *bv, uint8_t *buffer);
72 unsigned int bitvec_unpack(struct bitvec *bv, const uint8_t *buffer);
73 uint64_t bitvec_read_field(struct bitvec *bv, unsigned int *read_index, unsigned int len);
74 int bitvec_write_field(struct bitvec *bv, unsigned int *write_index, uint64_t val, unsigned int len);
75 int bitvec_fill(struct bitvec *bv, unsigned int num_bits, enum bit_value fill);
76 char bit_value_to_char(enum bit_value v);
77 void bitvec_to_string_r(const struct bitvec *bv, char *str);
78 void bitvec_zero(struct bitvec *bv);
79 unsigned bitvec_rl(const struct bitvec *bv, bool b);
80 unsigned bitvec_rl_curbit(struct bitvec *bv, bool b, int max_bits);
81 void bitvec_shiftl(struct bitvec *bv, unsigned int n);
82 int16_t bitvec_get_int16_msb(const struct bitvec *bv, unsigned int num_bits);
83 unsigned int bitvec_add_array(struct bitvec *bv, const uint32_t *array,
84  unsigned int array_len, bool dry_run,
85  unsigned int num_bits);
86 
87 /*! @} */
bitvec_read_field
uint64_t bitvec_read_field(struct bitvec *bv, unsigned int *read_index, unsigned int len)
bitvec::data
uint8_t * data
Definition: bitvec.h:49
bitvec_get_int16_msb
int16_t bitvec_get_int16_msb(const struct bitvec *bv, unsigned int num_bits)
bitvec_get_bytes
int bitvec_get_bytes(struct bitvec *bv, uint8_t *bytes, unsigned int count)
bitvec_get_bit_high
int bitvec_get_bit_high(struct bitvec *bv)
bitvec_get_bit_pos
enum bit_value bitvec_get_bit_pos(const struct bitvec *bv, unsigned int bitnr)
bitvec_pack
unsigned int bitvec_pack(const struct bitvec *bv, uint8_t *buffer)
ZERO
@ ZERO
Definition: bitvec.h:39
bitvec_set_bit
int bitvec_set_bit(struct bitvec *bv, enum bit_value bit)
bitvec_find_bit_pos
int bitvec_find_bit_pos(const struct bitvec *bv, unsigned int n, enum bit_value val)
bitvec_set_bits
int bitvec_set_bits(struct bitvec *bv, const enum bit_value *bits, unsigned int count)
bitvec::data_len
unsigned int data_len
Definition: bitvec.h:48
bit_value
bit_value
Definition: bitvec.h:38
bitvec_rl_curbit
unsigned bitvec_rl_curbit(struct bitvec *bv, bool b, int max_bits)
bitvec_add_array
unsigned int bitvec_add_array(struct bitvec *bv, const uint32_t *array, unsigned int array_len, bool dry_run, unsigned int num_bits)
bitvec_set_u64
int bitvec_set_u64(struct bitvec *bv, uint64_t v, uint8_t num_bits, bool use_lh)
bitvec_write_field
int bitvec_write_field(struct bitvec *bv, unsigned int *write_index, uint64_t val, unsigned int len)
bitvec
Definition: bitvec.h:46
bitvec_to_string_r
void bitvec_to_string_r(const struct bitvec *bv, char *str)
bitvec_set_bit_pos
int bitvec_set_bit_pos(struct bitvec *bv, unsigned int bitnum, enum bit_value bit)
bitvec_shiftl
void bitvec_shiftl(struct bitvec *bv, unsigned int n)
ONE
@ ONE
Definition: bitvec.h:40
bitvec_set_bytes
int bitvec_set_bytes(struct bitvec *bv, const uint8_t *bytes, unsigned int count)
bitvec_zero
void bitvec_zero(struct bitvec *bv)
H
@ H
Definition: bitvec.h:42
bitvec_rl
unsigned bitvec_rl(const struct bitvec *bv, bool b)
defs.h
bitvec_get_bit_pos_high
enum bit_value bitvec_get_bit_pos_high(const struct bitvec *bv, unsigned int bitnr)
bitvec_spare_padding
int bitvec_spare_padding(struct bitvec *bv, unsigned int up_to_bit)
bit_value_to_char
char bit_value_to_char(enum bit_value v)
bitvec::cur_bit
unsigned int cur_bit
Definition: bitvec.h:47
bitvec_set_uint
int bitvec_set_uint(struct bitvec *bv, unsigned int in, unsigned int count)
bitvec_get_uint
int bitvec_get_uint(struct bitvec *bv, unsigned int num_bits)
bitvec_fill
int bitvec_fill(struct bitvec *bv, unsigned int num_bits, enum bit_value fill)
bitvec_unhex
int bitvec_unhex(struct bitvec *bv, const char *src)
bitvec_unpack
unsigned int bitvec_unpack(struct bitvec *bv, const uint8_t *buffer)
bitvec_get_nth_set_bit
unsigned int bitvec_get_nth_set_bit(const struct bitvec *bv, unsigned int n)
L
@ L
Definition: bitvec.h:41