2015-03-14 21:41:50 +01:00
|
|
|
/*
|
|
|
|
This file is part of libcapwap.
|
|
|
|
|
|
|
|
libcapwap is free software: you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU General Public License as published by
|
|
|
|
the Free Software Foundation, either version 3 of the License, or
|
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
libcapwap is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with Foobar. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
2015-03-15 20:53:21 +01:00
|
|
|
/**
|
|
|
|
* @file
|
|
|
|
* @brief Definitions for bstr functions
|
2015-10-17 22:44:25 +02:00
|
|
|
* @defgroup Bstr BSTR
|
|
|
|
* @brief BSTR is used to store binary strings.
|
|
|
|
* We can see them anywhere.
|
2015-05-02 10:45:16 +02:00
|
|
|
* @{
|
2015-03-15 20:53:21 +01:00
|
|
|
*/
|
|
|
|
|
2015-03-14 10:15:12 +01:00
|
|
|
#ifndef __BSTR_H
|
|
|
|
#define __BSTR_H
|
|
|
|
|
2015-04-07 07:42:36 +02:00
|
|
|
#include <stdlib.h>
|
2015-04-05 02:07:59 +02:00
|
|
|
#include <string.h>
|
2015-01-31 10:17:34 +01:00
|
|
|
#include <stdint.h>
|
|
|
|
|
2016-03-04 20:20:28 +01:00
|
|
|
/**
|
|
|
|
* @defgroup BSTRTypes Types
|
|
|
|
* @{
|
|
|
|
*/
|
|
|
|
|
2015-03-15 20:53:21 +01:00
|
|
|
/**
|
2015-05-02 10:45:16 +02:00
|
|
|
* bstr type
|
2015-03-15 20:53:21 +01:00
|
|
|
*
|
2016-03-04 20:20:28 +01:00
|
|
|
* bstr_t serves as binary string, where the first byte contains
|
2015-03-15 20:53:21 +01:00
|
|
|
* the length of the string.
|
|
|
|
*/
|
2015-03-14 10:15:12 +01:00
|
|
|
typedef uint8_t* bstr_t;
|
2015-01-31 10:17:34 +01:00
|
|
|
|
2016-03-04 20:20:28 +01:00
|
|
|
/**
|
|
|
|
*@}
|
|
|
|
*/
|
|
|
|
|
2015-01-31 10:17:34 +01:00
|
|
|
extern uint8_t * bstr_create(uint8_t *data, uint8_t len);
|
2015-01-31 12:29:27 +01:00
|
|
|
extern uint8_t * bstr_create_from_cfgstr(const char * s);
|
2015-03-15 20:53:21 +01:00
|
|
|
extern uint8_t * bstr_replace( bstr_t * dst, uint8_t * bstr);
|
2015-01-31 12:29:27 +01:00
|
|
|
|
2015-03-14 21:41:50 +01:00
|
|
|
extern int bstr_to_str(char *dst, bstr_t str,char * def);
|
|
|
|
|
2015-01-31 10:17:34 +01:00
|
|
|
|
2015-04-05 02:07:59 +02:00
|
|
|
|
2015-03-15 20:53:21 +01:00
|
|
|
/**
|
|
|
|
* Return the length of a bstr_t string.
|
|
|
|
*/
|
2015-04-07 07:42:36 +02:00
|
|
|
#define bstr_len(s) (*((uint8_t*)(s)))
|
2015-03-15 20:53:21 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Return the data of a bstr_t string.
|
|
|
|
*/
|
2015-04-05 02:07:59 +02:00
|
|
|
#define bstr_data(s) ((s)+1)
|
2015-03-15 20:53:21 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Return the actual size in memory a bstr_t string needs.
|
|
|
|
*/
|
2015-03-14 21:41:50 +01:00
|
|
|
#define bstr_size(len) (len+1)
|
|
|
|
|
2015-03-15 20:53:21 +01:00
|
|
|
/**
|
2016-03-04 20:20:28 +01:00
|
|
|
*@defgroup BSTRConstants Constants
|
2015-10-17 22:44:25 +02:00
|
|
|
*@{
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Maximum length of a bstr_t string.
|
2015-03-15 20:53:21 +01:00
|
|
|
*/
|
2015-03-14 21:41:50 +01:00
|
|
|
#define BSTR_MAX_LEN 254
|
2015-03-14 10:15:12 +01:00
|
|
|
|
2016-03-04 20:20:28 +01:00
|
|
|
/**@}*/
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
*@addtogroup BSTRTypes
|
|
|
|
*@{
|
|
|
|
*/
|
2015-10-17 22:44:25 +02:00
|
|
|
|
2015-05-02 10:45:16 +02:00
|
|
|
/**
|
|
|
|
* The same as #bstr_t, but there are two bytes used
|
|
|
|
* to describe the length of the string.
|
|
|
|
*/
|
2015-04-05 02:07:59 +02:00
|
|
|
typedef uint8_t *bstr16_t;
|
2015-05-02 10:45:16 +02:00
|
|
|
|
2016-03-04 20:20:28 +01:00
|
|
|
/**
|
|
|
|
*@}
|
|
|
|
*/
|
2015-10-17 22:44:25 +02:00
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Return the length of a bstr16_t string.
|
|
|
|
*/
|
2015-04-05 02:07:59 +02:00
|
|
|
#define bstr16_len(s) ( *((uint16_t*)(s)) )
|
2015-10-17 22:44:25 +02:00
|
|
|
/**
|
|
|
|
* Return a pointer to the data of a bstr16_t string.
|
|
|
|
*/
|
2015-04-30 19:46:03 +02:00
|
|
|
#define bstr16_data(s) (((uint8_t*)s)+2)
|
2015-10-17 22:44:25 +02:00
|
|
|
|
|
|
|
/**
|
2016-03-04 22:32:01 +01:00
|
|
|
* Return the actual size of a bstr16_t string. That's the
|
|
|
|
* size this objects needs in memory to be stored.
|
2015-10-17 22:44:25 +02:00
|
|
|
*/
|
2015-04-05 02:07:59 +02:00
|
|
|
#define bstr16_size(l) (l+2)
|
2015-10-17 22:44:25 +02:00
|
|
|
/**
|
|
|
|
Maximum length of a #bstr16_t string
|
|
|
|
*/
|
2015-04-05 02:07:59 +02:00
|
|
|
#define BSTR16_MAX_LEN (0xffff-2)
|
|
|
|
|
2015-05-02 10:45:16 +02:00
|
|
|
/*
|
2015-04-05 02:07:59 +02:00
|
|
|
static inline int bstr16_ncpy(uint8_t *dst,uint8_t*src,uint16_t len)
|
|
|
|
{
|
|
|
|
*((uint16_t*)dst)=len;
|
|
|
|
memcpy(dst+2,src,len);
|
|
|
|
return len+2;
|
|
|
|
}
|
2015-05-02 10:45:16 +02:00
|
|
|
*/
|
|
|
|
|
2015-04-05 02:07:59 +02:00
|
|
|
|
2018-02-28 09:05:45 +01:00
|
|
|
extern uint8_t * bstr16_create(const uint8_t *data, uint16_t len);
|
2015-05-04 07:34:52 +02:00
|
|
|
uint8_t * bstr16_create_from_str(const char *s);
|
2016-03-04 22:47:49 +01:00
|
|
|
extern uint8_t * bstr16_create_from_cfgstr(const char * s);
|
2015-05-04 07:34:52 +02:00
|
|
|
|
2016-03-04 22:32:01 +01:00
|
|
|
#define bstr16_replace bstr_replace
|
|
|
|
|
2015-04-07 07:42:36 +02:00
|
|
|
|
2016-03-04 20:20:28 +01:00
|
|
|
/**
|
|
|
|
*@addtogroup BSTRTypes
|
|
|
|
*@{
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The bstrv_t type is basicly a #bstr16_t and can be
|
|
|
|
* handeld like a bstr16_t.
|
|
|
|
* The difference is, that the first four bytes of the
|
|
|
|
* string data containing a vendor id.
|
|
|
|
*/
|
|
|
|
typedef uint8_t * bstrv_t;
|
|
|
|
|
|
|
|
/**
|
|
|
|
*@}
|
|
|
|
*/
|
2015-04-07 07:42:36 +02:00
|
|
|
|
2016-03-04 20:20:28 +01:00
|
|
|
#define bstrv_get_vendor_id(str)\
|
2015-04-07 07:42:36 +02:00
|
|
|
( *((uint32_t*)((str)+2)))
|
|
|
|
|
2016-03-04 20:20:28 +01:00
|
|
|
#define bstrv_set_vendor_id(str,id)\
|
2015-04-07 07:42:36 +02:00
|
|
|
( *((uint32_t*)((str)+2)) = id)
|
|
|
|
|
2016-03-04 20:20:28 +01:00
|
|
|
#define bstrv_len(str)\
|
2015-04-07 07:42:36 +02:00
|
|
|
(*((uint16_t*)((str)+0)))
|
|
|
|
|
2016-03-04 20:20:28 +01:00
|
|
|
#define bstrv_set_len(str,len)\
|
2015-04-07 07:42:36 +02:00
|
|
|
(*((uint16_t*)((str)+0))=len)
|
|
|
|
|
2016-03-04 20:20:28 +01:00
|
|
|
#define bstrv_data(str)\
|
2015-04-07 07:42:36 +02:00
|
|
|
(((uint8_t*)(str))+6)
|
|
|
|
|
2016-03-04 20:20:28 +01:00
|
|
|
#define bstrv_size(n)\
|
2015-05-04 07:34:52 +02:00
|
|
|
(1+6+(n)*sizeof(uint8_t))
|
2015-04-07 07:42:36 +02:00
|
|
|
|
|
|
|
|
2016-03-04 20:20:28 +01:00
|
|
|
uint8_t * bstrv_create_from_str(uint32_t vendor_id,const char *s);
|
2018-02-28 09:05:45 +01:00
|
|
|
uint8_t * bstrv_create(uint32_t vendor_id, uint8_t *data, uint8_t len);
|
2015-05-04 07:34:52 +02:00
|
|
|
|
|
|
|
|
2015-04-05 02:07:59 +02:00
|
|
|
|
2015-03-14 10:15:12 +01:00
|
|
|
#endif
|
|
|
|
|
2015-05-02 10:45:16 +02:00
|
|
|
/**@}*/
|
|
|
|
|