libcs compiles with -ansi option now

FossilOrigin-Name: afeca48ac2e33dace533047329ea48224ee5e4bfd4e83449f335d0a022a67215
This commit is contained in:
7u83@mail.ru 2018-03-02 12:36:03 +00:00
parent 8f12f61dbd
commit 14de235c5c
22 changed files with 980 additions and 760 deletions

View File

@ -71,4 +71,14 @@ cw_acprio_t * cw_acpriolist_add(cw_acpriolist_t l, const char *name,int name_len
}
int cw_acpriolist_get(cw_acpriolist_t l, char * acname){
cw_acprio_t ps,*pf;
ps.name=acname;
pf=mavl_get(l,&ps);
if (!pf)
return 256;
return pf->prio;
}

View File

@ -34,15 +34,9 @@ typedef struct mavl * cw_acpriolist_t;
extern cw_acpriolist_t cw_acpriolist_create();
cw_acprio_t * cw_acpriolist_add(cw_acpriolist_t l, const char *name,int name_len, uint8_t prio);
static inline int cw_acpriolist_get(cw_acpriolist_t l, char * acname){
cw_acprio_t ps,*pf;
ps.name=acname;
pf=mavl_get(l,&ps);
if (!pf)
return 256;
return pf->prio;
}
int cw_acpriolist_get(cw_acpriolist_t l, char * acname);
#define cw_acpriolist_del(l,s) mavl_del(l,s)
#define cw_acpriolist_set(l,n,nl,p) cw_acpriolist_add(l,n,nl,p)

View File

@ -32,7 +32,7 @@
*/
static inline int cw_action_in_cmp(const void *elem1, const void *elem2)
static int cw_action_in_cmp(const void *elem1, const void *elem2)
{
struct cw_action_in *e1 = (struct cw_action_in *) elem1;
struct cw_action_in *e2 = (struct cw_action_in *) elem2;

View File

@ -581,40 +581,15 @@ extern struct cw_strlist_elem mbag_item_strings[];
#define cw_strerror(rc) cw_strrc(rc)
*/
static inline const char * cw_strerror(int rc) {
if (rc<0){
if (errno==EAGAIN)
return "Timed out";
return strerror(errno);
}
return cw_strresult(rc);
}
const char * cw_strerror(int rc);
int cw_rcok(int rc);
const char *cw_strelemp_(cw_strheap_t h, int msg_id);
#define cw_strrc cw_strerror
static inline int cw_rcok(int rc)
{
if (rc==0 || rc==2){
return 1;
}
return 0;
}
/**
*@defgroup CW CW
*@{
*/
static inline const char *cw_strelemp_(cw_strheap_t h, int msg_id)
{
const char *rc = cw_strheap_get(h, msg_id);
if (rc)
return rc;
return cw_strheap_get(h, CW_STR_STOP);
}
/**@}*/
#define cw_strelemp(p,id) cw_strelemp_((p)->strelem,id)

View File

@ -113,36 +113,16 @@
/**
* Add a Cisco AP Timesync message element to a buffer
* @param dst destination buffer
* @param time a unix timestamp
* @param type of time
* @return number of bytes put (5)
*/
static inline int cw_put_cisco_ap_timesync(uint8_t * dst, time_t time, uint8_t type)
{
cw_put_dword(dst , time);
cw_put_byte(dst + 4, type);
return 5;
int cw_put_cisco_ap_timesync(uint8_t * dst, time_t time, uint8_t type);
}
int cw_out_cisco_ap_timesync(struct conn *conn,struct cw_action_out * a,uint8_t *dst);
static inline int cw_addelem_cisco_ap_regulatory_domain(uint8_t *dst, struct radioinfo * ri){
uint8_t *d=dst+10;
d+=cw_put_byte(d,ri->rid); /* Band ID */
d+=cw_put_byte(d,1); /* Set True/False */
d+=cw_put_byte(d,ri->rid); /* Slot ID */
d+=cw_put_word(d,ri->regDomain);
return 5 + cw_put_elem_vendor_hdr(dst, CW_VENDOR_ID_CISCO, CW_CISCO_AP_REGULATORY_DOMAIN, 5);
}
int cw_addelem_cisco_ap_regulatory_domain(uint8_t *dst, struct radioinfo * ri);
/**
@ -162,33 +142,10 @@ static inline int cw_addelem_cisco_mwar(uint8_t *dst, struct ac_info *acinfo){
}
*/
/**
* Add a Cisco Certificate payload message element
* @param dst destination buffer
* @param src pointer to DER certificate
* @param len length of certificate
* @return number of bytes put
*/
static inline int cw_addelem_cisco_certificate(uint8_t*dst,uint8_t*src,int len){
int l = lw_put_certificate(dst+10,src,len);
return l+cw_put_elem_vendor_hdr(dst,CW_VENDOR_ID_CISCO,CW_CISCO_CERTIFICATE,l);
}
int cw_readelem_cisco_station_cfg(uint8_t *src,int len);
int cw_addelem_cisco_certificate(uint8_t*dst,uint8_t*src,int len);
/*
static inline int cw_addelem_cisco_wtp_radio_cfg(uint8_t * dst,struct radioinfo *ri){
int l = lw_put_80211_wtp_wlan_radio_configuration(dst+10,ri);
return l+cw_put_elem_vendor_hdr(dst,CW_VENDOR_ID_CISCO,CW_CISCO_STATION_CFG,l);
}
*/
static inline int cw_readelem_cisco_station_cfg(uint8_t *src,int len){
// lw_readelem_
return 0;
}
extern const char * cw_cisco_id_to_str(int elem_id);
int cw_readelem_cisco_wtp_radio_cfg(int elem_id,uint8_t *elem, int len,struct radioinfo *ri);

39
src/cw/capwap_inline.c Normal file
View File

@ -0,0 +1,39 @@
#include "capwap.h"
const char * cw_strerror(int rc) {
if (rc<0){
if (errno==EAGAIN)
return "Timed out";
return strerror(errno);
}
return cw_strresult(rc);
}
int cw_rcok(int rc)
{
if (rc==0 || rc==2){
return 1;
}
return 0;
}
/**
*@defgroup CW CW
*@{
*/
const char *cw_strelemp_(cw_strheap_t h, int msg_id)
{
const char *rc = cw_strheap_get(h, msg_id);
if (rc)
return rc;
return cw_strheap_get(h, CW_STR_STOP);
}
/**@}*/

View File

@ -141,43 +141,16 @@ struct cw_MsgDef{
};
typedef struct cw_MsgDef cw_msgdef_t;
/**
* Get length wireless specific data
* @param th Pointer to packet
* @return length of wireless specific data
*
* Call this function only if the W flag is set
*/
static inline int cw_get_hdr_ws_len(uint8_t * th)
{
if (!cw_get_hdr_flag_m(th)){
return *(th + 8);
}
return *(th + 9 + cw_get_hdr_rmac_len(th));
}
/**
* Get pointer to wireless specific data
* @param th Pointer to packet
* @return Pointer to data
*
* Call this function only if the W flag is set
*/
static inline uint8_t *cw_get_hdr_ws_data(uint8_t * th)
{
if (!cw_get_hdr_flag_m(th))
return th + 9;
return (th + 10 + cw_get_hdr_rmac_len(th));
}
int cw_get_hdr_ws_len(uint8_t * th);
uint8_t *cw_get_hdr_ws_data(uint8_t * th);
#define cw_get_hdr_msg_offset(th) (4*cw_get_hdr_hlen(th))
static inline uint8_t * cw_get_hdr_payload_ptr(uint8_t *th)
{
return th+cw_get_hdr_msg_offset(th);
}
uint8_t * cw_get_hdr_payload_ptr(uint8_t *th);
#define cw_get_hdr_msg_elems_offset(th) (cw_get_hdr_msg_offset(th)+8)
@ -185,46 +158,9 @@ static inline uint8_t * cw_get_hdr_payload_ptr(uint8_t *th)
/**
* Set the HLEN field of a CAWAP Header
* @param th pointer to the header
* @param hlen value to set (Header Length)
*/
static inline void cw_set_hdr_hlen(uint8_t * th, int hlen)
{
uint32_t d = cw_get_dword(th);
d &= (0x1f << 19) ^ 0xffffffff;
d |= ((hlen) & 0x1f) << 19;
cw_set_dword(th, d);
}
/**
* Set the WBID field of a CAWAP Header
* @param th pointer to the header
* @param wbid value to set (Wireless ID)
*/
static inline void cw_set_hdr_wbid(uint8_t * th, int wbid)
{
uint32_t d = cw_get_dword(th);
d &= (0x1f << 9) ^ 0xffffffff;
d |= ((wbid) & 0x1f) << 9;
cw_set_dword(th, d);
}
/**
* Set the RID field of a CAWAP Header
* @param th pointer to the header
* @param rid value to set (Radio ID)
*/
static inline void cw_set_hdr_rid(uint8_t * th, int rid)
{
uint32_t d = cw_get_dword(th);
d &= (0x1f << 14) ^ 0xffffffff;
d |= ((rid) & 0x1f) << 14;
cw_set_dword(th, d);
}
void cw_set_hdr_hlen(uint8_t * th, int hlen);
void cw_set_hdr_wbid(uint8_t * th, int wbid);
void cw_set_hdr_rid(uint8_t * th, int rid);
@ -282,49 +218,17 @@ static inline void cw_set_hdr_rid(uint8_t * th, int rid)
#define cw_is_response(msg_id) (!is_response(msg_id))
static inline uint8_t *cw_get_hdr_msg_elems_ptr(uint8_t * m)
{
return cw_get_msg_elems_ptr(m + cw_get_hdr_msg_offset(m));
}
uint8_t *cw_get_hdr_msg_elems_ptr(uint8_t * m);
uint8_t *cw_get_hdr_msg_ptr(uint8_t * rawmsg);
static inline uint8_t *cw_get_hdr_msg_ptr(uint8_t * rawmsg)
{
return rawmsg + cw_get_hdr_msg_offset(rawmsg);
}
#define cw_get_hdr_msg_id(ptr)\
cw_get_msg_id(cw_get_hdr_msg_ptr(ptr))
#define cw_get_hdr_msg_type cw_get_hdr_msg_id
static inline int cw_get_hdr_msg_total_len(uint8_t * rawmsg)
{
int offset = cw_get_hdr_msg_offset(rawmsg);
return offset + cw_get_msg_elems_len(rawmsg + offset) + 8;
}
static inline int cw_set_hdr_rmac(uint8_t * th, bstr_t rmac)
{
if (!rmac) {
cw_set_hdr_flags(th, CAPWAP_FLAG_HDR_M, 0);
cw_set_hdr_hlen(th, 2);
return 0;
}
int rmac_len = bstr_len(rmac);
memcpy(cw_get_hdr_rmac(th), rmac, rmac_len + 1);
cw_set_hdr_flags(th, CAPWAP_FLAG_HDR_M, 1);
int hlen = 4 + rmac_len / 4;
if (rmac_len % 4 != 0) {
hlen++;
}
cw_set_hdr_hlen(th, hlen);
return 1;
}
int cw_get_hdr_msg_total_len(uint8_t * rawmsg);
int cw_set_hdr_rmac(uint8_t * th, bstr_t rmac);
@ -384,24 +288,8 @@ static inline int cw_set_hdr_rmac(uint8_t * th, bstr_t rmac)
(cw_put_dword(dst, (((uint32_t)type)<<16) | (len)),4)
/**
* Put a message element header for a message to contain a vendor specific payload
* @param dst pointer to destination buffer
* @param vendorid vendorid
* @param elemid element id of vendor specific data
* @len length of vendor specific data
* @return the number of bytes put (always 10)
*/
static inline int cw_put_elem_vendor_hdr(uint8_t * dst, uint32_t vendorid,
uint16_t elemid, uint16_t len)
{
cw_put_elem_hdr(dst, CAPWAP_ELEM_VENDOR_SPECIFIC_PAYLOAD, len + 6);
cw_put_dword(dst + 4, vendorid);
cw_put_word(dst + 8, elemid);
return 10;
}
int cw_put_elem_vendor_hdr(uint8_t * dst, uint32_t vendorid,
uint16_t elemid, uint16_t len);
@ -422,48 +310,15 @@ extern int cw_put_mbag_item(uint8_t * dst, struct mbag_item *item);
#define cw_put_encryption_capabilities_7(dst,cap) cw_put_word(dst,cap)
/**
* Add a message element to a buffer
* @param dst pointer to buffer
* @type message element type
* @data pointer to data
* @length of message element
* @return the number of bytes put
*/
static inline int cw_addelem(uint8_t * dst, uint16_t type, uint8_t * data, uint16_t len)
{
int l = cw_put_elem_hdr(dst, type, len);
return l + cw_put_data(dst + l, data, len);
}
static inline int cw_addelem_bstr(uint8_t * dst, uint16_t type, const bstr_t bstr)
{
return cw_addelem(dst, type, bstr_data(bstr), bstr_len(bstr));
}
static inline int cw_put_elem_result_code(uint8_t * dst, uint32_t code)
{
cw_put_dword(dst + 4, code);
return 4 + cw_put_elem_hdr(dst, CW_ELEM_RESULT_CODE, 4);
}
int cw_addelem(uint8_t * dst, uint16_t type, uint8_t * data, uint16_t len);
int cw_addelem_bstr(uint8_t * dst, uint16_t type, const bstr_t bstr);
int cw_put_elem_result_code(uint8_t * dst, uint32_t code);
int cw_put_version(uint8_t * dst, uint16_t subelem_id, bstrv_t v);
static inline int cw_put_version(uint8_t * dst, uint16_t subelem_id, bstrv_t v)
{
uint8_t *d = dst;
d += cw_put_dword(d, bstrv_get_vendor_id(v));
d += cw_put_dword(d, (subelem_id << 16) | bstrv_len(v));
d += cw_put_data(d, bstrv_data(v), bstrv_len(v));
return d - dst;
}
extern int cw_put_ac_status(uint8_t * dst, struct cw_ac_status *s, struct conn *conn);
@ -598,28 +453,15 @@ extern int cw_radio_set_admin_state(mbag_t radios,int rid, int state, int cause)
//extern int cw_put_elem_radio_operational_state(uint8_t * dst, int rid, int os, int d7mode);
static inline int cw_put_elem_radio_operational_state(uint8_t * dst, int rid, int state, int cause) {
cw_put_byte(dst+4,rid);
cw_put_byte(dst+5,state);
cw_put_byte(dst+6,cause);
return 3+cw_put_elem_hdr(dst,CW_ELEM_RADIO_OPERATIONAL_STATE,3);
}
int cw_put_elem_radio_operational_state(uint8_t * dst, int rid, int state, int cause);
int cw_put_elem_radio_administrative_state(uint8_t * dst, int rid, int state);
static inline int cw_put_elem_radio_administrative_state(uint8_t * dst, int rid, int state) {
cw_put_byte(dst+4,rid);
cw_put_byte(dst+5,state);
return 2+cw_put_elem_hdr(dst,CW_ELEM_RADIO_ADMINISTRATIVE_STATE,2);
}
uint8_t *cw_init_data_keep_alive_msg(uint8_t * buffer,uint8_t *rmac);
static inline int cw_put_elem_session_id(uint8_t *dst, uint8_t *session_id, int len){
memcpy(dst+4,session_id,len);
return len+cw_put_elem_hdr(dst,CW_ELEM_SESSION_ID,len);
}
int cw_out_radio_generic(struct conn *conn, struct cw_action_out *a, uint8_t * dst);
int cw_put_elem_session_id(uint8_t *dst, uint8_t *session_id, int len);
/**

203
src/cw/cw_inline.c Normal file
View File

@ -0,0 +1,203 @@
#include "cw.h"
/**
* Get length wireless specific data
* @param th Pointer to packet
* @return length of wireless specific data
*
* Call this function only if the W flag is set
*/
int cw_get_hdr_ws_len(uint8_t * th)
{
if (!cw_get_hdr_flag_m(th)){
return *(th + 8);
}
return *(th + 9 + cw_get_hdr_rmac_len(th));
}
/**
* Get pointer to wireless specific data
* @param th Pointer to packet
* @return Pointer to data
*
* Call this function only if the W flag is set
*/
uint8_t *cw_get_hdr_ws_data(uint8_t * th)
{
if (!cw_get_hdr_flag_m(th))
return th + 9;
return (th + 10 + cw_get_hdr_rmac_len(th));
}
uint8_t * cw_get_hdr_payload_ptr(uint8_t *th)
{
return th+cw_get_hdr_msg_offset(th);
}
/**
* Set the HLEN field of a CAWAP Header
* @param th pointer to the header
* @param hlen value to set (Header Length)
*/
void cw_set_hdr_hlen(uint8_t * th, int hlen)
{
uint32_t d = cw_get_dword(th);
d &= (0x1f << 19) ^ 0xffffffff;
d |= ((hlen) & 0x1f) << 19;
cw_set_dword(th, d);
}
/**
* Set the WBID field of a CAWAP Header
* @param th pointer to the header
* @param wbid value to set (Wireless ID)
*/
void cw_set_hdr_wbid(uint8_t * th, int wbid)
{
uint32_t d = cw_get_dword(th);
d &= (0x1f << 9) ^ 0xffffffff;
d |= ((wbid) & 0x1f) << 9;
cw_set_dword(th, d);
}
/**
* Set the RID field of a CAWAP Header
* @param th pointer to the header
* @param rid value to set (Radio ID)
*/
void cw_set_hdr_rid(uint8_t * th, int rid)
{
uint32_t d = cw_get_dword(th);
d &= (0x1f << 14) ^ 0xffffffff;
d |= ((rid) & 0x1f) << 14;
cw_set_dword(th, d);
}
uint8_t *cw_get_hdr_msg_elems_ptr(uint8_t * m)
{
return cw_get_msg_elems_ptr(m + cw_get_hdr_msg_offset(m));
}
uint8_t *cw_get_hdr_msg_ptr(uint8_t * rawmsg)
{
return rawmsg + cw_get_hdr_msg_offset(rawmsg);
}
int cw_get_hdr_msg_total_len(uint8_t * rawmsg)
{
int offset = cw_get_hdr_msg_offset(rawmsg);
return offset + cw_get_msg_elems_len(rawmsg + offset) + 8;
}
int cw_set_hdr_rmac(uint8_t * th, bstr_t rmac)
{
if (!rmac) {
cw_set_hdr_flags(th, CAPWAP_FLAG_HDR_M, 0);
cw_set_hdr_hlen(th, 2);
return 0;
}
int rmac_len = bstr_len(rmac);
memcpy(cw_get_hdr_rmac(th), rmac, rmac_len + 1);
cw_set_hdr_flags(th, CAPWAP_FLAG_HDR_M, 1);
int hlen = 4 + rmac_len / 4;
if (rmac_len % 4 != 0) {
hlen++;
}
cw_set_hdr_hlen(th, hlen);
return 1;
}
/**
* Put a message element header for a message to contain a vendor specific payload
* @param dst pointer to destination buffer
* @param vendorid vendorid
* @param elemid element id of vendor specific data
* @len length of vendor specific data
* @return the number of bytes put (always 10)
*/
int cw_put_elem_vendor_hdr(uint8_t * dst, uint32_t vendorid,
uint16_t elemid, uint16_t len)
{
cw_put_elem_hdr(dst, CAPWAP_ELEM_VENDOR_SPECIFIC_PAYLOAD, len + 6);
cw_put_dword(dst + 4, vendorid);
cw_put_word(dst + 8, elemid);
return 10;
}
/**
* Add a message element to a buffer
* @param dst pointer to buffer
* @type message element type
* @data pointer to data
* @length of message element
* @return the number of bytes put
*/
int cw_addelem(uint8_t * dst, uint16_t type, uint8_t * data, uint16_t len)
{
int l = cw_put_elem_hdr(dst, type, len);
return l + cw_put_data(dst + l, data, len);
}
int cw_addelem_bstr(uint8_t * dst, uint16_t type, const bstr_t bstr)
{
return cw_addelem(dst, type, bstr_data(bstr), bstr_len(bstr));
}
int cw_put_elem_result_code(uint8_t * dst, uint32_t code)
{
cw_put_dword(dst + 4, code);
return 4 + cw_put_elem_hdr(dst, CW_ELEM_RESULT_CODE, 4);
}
int cw_put_version(uint8_t * dst, uint16_t subelem_id, bstrv_t v)
{
uint8_t *d = dst;
d += cw_put_dword(d, bstrv_get_vendor_id(v));
d += cw_put_dword(d, (subelem_id << 16) | bstrv_len(v));
d += cw_put_data(d, bstrv_data(v), bstrv_len(v));
return d - dst;
}
int cw_put_elem_radio_operational_state(uint8_t * dst, int rid, int state, int cause) {
cw_put_byte(dst+4,rid);
cw_put_byte(dst+5,state);
cw_put_byte(dst+6,cause);
return 3+cw_put_elem_hdr(dst,CW_ELEM_RADIO_OPERATIONAL_STATE,3);
}
int cw_put_elem_radio_administrative_state(uint8_t * dst, int rid, int state) {
cw_put_byte(dst+4,rid);
cw_put_byte(dst+5,state);
return 2+cw_put_elem_hdr(dst,CW_ELEM_RADIO_ADMINISTRATIVE_STATE,2);
}
int cw_put_elem_session_id(uint8_t *dst, uint8_t *session_id, int len){
memcpy(dst+4,session_id,len);
return len+cw_put_elem_hdr(dst,CW_ELEM_SESSION_ID,len);
}

View File

@ -131,14 +131,7 @@ extern const uint8_t dot11_tab_br[256];
#define dot11_put_qword(dst,v) ((*((uint64_t*)(dst))=htobe64(v)),8)
static inline uint16_t dot11_get_word(uint8_t * ptr)
{
uint16_t w;
w = dot11_get_byte(ptr + 1);
w |= dot11_get_byte(ptr) << 8;
return w;
}
uint16_t dot11_get_word(uint8_t * ptr);
@ -154,10 +147,9 @@ static inline uint16_t dot11_get_word(uint8_t * ptr)
#define dot11_get_duration(frame) dot11_get_word(frame+2)
static inline void dot11_get_address(uint8_t * dst, uint8_t * frame)
{
memcpy(dst, frame, 6);
}
void dot11_get_address(uint8_t * dst, uint8_t * frame);
#define dot11_get_address1(dst,frame) dot11_get_address(dst,frame+4)
#define dot11_get_address2(dst,frame) dot11_get_address(dst,frame+4+1*6)
@ -180,12 +172,7 @@ static inline void dot11_get_address(uint8_t * dst, uint8_t * frame)
#define dot11_fc_put_frame_control(dst,fc) dot11_put_word(dst,fc)
static inline int dot11_put_frame_control(uint8_t * dst, int fctype, int flags)
{
uint16_t fc = fctype | flags;
return dot11_fc_put_frame_control(dst, fc);
}
int dot11_put_frame_control(uint8_t * dst, int fctype, int flags);
/**
* @defgroup DOT11_TIMER Timer
@ -193,26 +180,10 @@ static inline int dot11_put_frame_control(uint8_t * dst, int fctype, int flags)
*/
extern uint64_t dot11_timer_offset;
/**
* Get the current timestamp
* @return current timestamp in microseconds
*/
static inline uint64_t dot11_timer_get()
{
struct timeval tv;
gettimeofday(&tv, NULL);
return 1000000 * tv.tv_sec + tv.tv_usec - dot11_timer_offset;
}
uint64_t dot11_timer_get();
void dot11_timer_set(uint64_t val);
static inline void dot11_timer_set(uint64_t val)
{
struct timeval tv;
gettimeofday(&tv, NULL);
dot11_timer_offset = 1000000 * tv.tv_sec + tv.tv_usec - val;
}
/**
* @}
*/
@ -230,13 +201,10 @@ static inline void dot11_timer_set(uint64_t val)
#define dot11_put_address(dst,addr) (memcpy(dst,addr,6),6)
#define dot11_put_sequence_control(dst,v) (dot11_put_word(dst,v))
#define dot11_put_capability(dst,v) dot11_put_word(dst,v)
static inline int dot11_put_ssid(uint8_t *dst,uint8_t * ssid,int len){
dot11_put_byte(dst,DOT11_ELEM_SSID);
dot11_put_byte(dst+1,len);
memcpy(dst+2,ssid,len);
return len;
int dot11_put_ssid(uint8_t *dst,uint8_t * ssid,int len);
}
/**
* Convert a rate, specified as float to an inzteger, used
@ -253,30 +221,11 @@ static inline int dot11_put_ssid(uint8_t *dst,uint8_t * ssid,int len){
*/
#define dot11_rate2float(rate) (((float)(rate))/2.0)
static inline int dot11_put_supported_rates(uint8_t *dst, float *basic, float *rates){
uint8_t *d = dst+2;
while(*basic != 0.0){
*d++ = 0x80 | dot11_float2rate(*basic);
basic++;
}
while(*rates != 0.0){
*d++ = dot11_float2rate(*rates);
rates++;
}
*(dst)=DOT11_ELEM_SUPPORTED_RATES;
*(dst+1) = d-(dst+2);
return d-dst;
}
int dot11_put_supported_rates(uint8_t *dst, float *basic, float *rates);
int dot11_put_dsss_param_set(uint8_t *dst,int ch);
static inline int dot11_put_dsss_param_set(uint8_t *dst,int ch) {
dot11_put_byte(dst,DOT11_ELEM_DSSS_PARAM_SET);
dot11_put_byte(dst+1,1);
dot11_put_byte(dst+2,ch);
return 3;
}
extern int dot11_create_beacon(uint8_t *dst);

76
src/cw/dot11_inline.c Normal file
View File

@ -0,0 +1,76 @@
#include "dot11.h"
uint16_t dot11_get_word(uint8_t * ptr)
{
uint16_t w;
w = dot11_get_byte(ptr + 1);
w |= dot11_get_byte(ptr) << 8;
return w;
}
void dot11_get_address(uint8_t * dst, uint8_t * frame)
{
memcpy(dst, frame, 6);
}
int dot11_put_frame_control(uint8_t * dst, int fctype, int flags)
{
uint16_t fc = fctype | flags;
return dot11_fc_put_frame_control(dst, fc);
}
/**
* Get the current timestamp
* @return current timestamp in microseconds
*/
uint64_t dot11_timer_get()
{
struct timeval tv;
gettimeofday(&tv, NULL);
return 1000000 * tv.tv_sec + tv.tv_usec - dot11_timer_offset;
}
void dot11_timer_set(uint64_t val)
{
struct timeval tv;
gettimeofday(&tv, NULL);
dot11_timer_offset = 1000000 * tv.tv_sec + tv.tv_usec - val;
}
int dot11_put_ssid(uint8_t *dst,uint8_t * ssid,int len){
dot11_put_byte(dst,DOT11_ELEM_SSID);
dot11_put_byte(dst+1,len);
memcpy(dst+2,ssid,len);
return len;
}
int dot11_put_supported_rates(uint8_t *dst, float *basic, float *rates){
uint8_t *d = dst+2;
while(*basic != 0.0){
*d++ = 0x80 | dot11_float2rate(*basic);
basic++;
}
while(*rates != 0.0){
*d++ = dot11_float2rate(*rates);
rates++;
}
*(dst)=DOT11_ELEM_SUPPORTED_RATES;
*(dst+1) = d-(dst+2);
return d-dst;
}
int dot11_put_dsss_param_set(uint8_t *dst,int ch) {
dot11_put_byte(dst,DOT11_ELEM_DSSS_PARAM_SET);
dot11_put_byte(dst+1,1);
dot11_put_byte(dst+2,ch);
return 3;
}

View File

@ -110,4 +110,28 @@ int format_scan_hex_bytes(uint8_t *dst,const char *s, int len)
return err;
}
char *format_s_hex_bytes(char *dst, const char *format, const char *delim,
const uint8_t * src, int len)
{
format_hex_bytes(dst, format, delim, src, len);
return dst;
}
int format_hdr_flags(char *dst, uint8_t * th)
{
char *s = dst;
s += sprintf(s, "%s", "(");
s += sprintf(s, "%s", cw_get_hdr_flag_t(th) ? "T" : "");
s += sprintf(s, "%s", cw_get_hdr_flag_f(th) ? "F" : "");
s += sprintf(s, "%s", cw_get_hdr_flag_l(th) ? "L" : "");
s += sprintf(s, "%s", cw_get_hdr_flag_w(th) ? "W" : "");
s += sprintf(s, "%s", cw_get_hdr_flag_m(th) ? "M" : "");
s += sprintf(s, "%s", cw_get_hdr_flag_k(th) ? "K" : "");
s += sprintf(s, "%s", ")");
return s - dst;
}

View File

@ -31,12 +31,10 @@
extern int format_hex_bytes(char *dst, const char *format, const char *delim,
const uint8_t * src, int len);
static inline char *format_s_hex_bytes(char *dst, const char *format, const char *delim,
const uint8_t * src, int len)
{
format_hex_bytes(dst, format, delim, src, len);
return dst;
}
char *format_s_hex_bytes(char *dst, const char *format, const char *delim,
const uint8_t * src, int len);
#define format_bin2hex(src,len) (format_s_hex_bytes((char[(len) * 2 + 1]) {0}, "%02X", "", src, len))
@ -77,21 +75,7 @@ extern int format_scan_hex_bytes(uint8_t * dst, const char *s, int len);
#define format_mac(dst,src,len)\
format_hex_bytes(dst,"%02x",":",src,len)
static inline int format_hdr_flags(char *dst, uint8_t * th)
{
char *s = dst;
s += sprintf(s, "%s", "(");
s += sprintf(s, "%s", cw_get_hdr_flag_t(th) ? "T" : "");
s += sprintf(s, "%s", cw_get_hdr_flag_f(th) ? "F" : "");
s += sprintf(s, "%s", cw_get_hdr_flag_l(th) ? "L" : "");
s += sprintf(s, "%s", cw_get_hdr_flag_w(th) ? "W" : "");
s += sprintf(s, "%s", cw_get_hdr_flag_m(th) ? "M" : "");
s += sprintf(s, "%s", cw_get_hdr_flag_k(th) ? "K" : "");
s += sprintf(s, "%s", ")");
return s - dst;
}
int format_hdr_flags(char *dst, uint8_t * th);
int format_is_utf8(unsigned char *str, size_t len);

View File

@ -2,7 +2,7 @@
#include "format.h"
static inline int add_flag(char *dst,int fc, int flag, char *name,char **delim)
static int add_flag(char *dst,int fc, int flag, char *name,char **delim)
{
if (! (fc&flag) )
return 0;

View File

@ -97,77 +97,14 @@
macro to avoid any side effects */
/**
* Put some bytes to an output buffer
* @param dst Destination
* @param data Data to put
* @len length of data (iini bytes)
* @return The number of bytes put
*/
static inline int lw_put_data(uint8_t*dst,const uint8_t*data,uint16_t len)
{
memcpy(dst,data,len);
return len;
}
int lw_put_data(uint8_t*dst,const uint8_t*data,uint16_t len);
int lw_put_bstr(uint8_t * dst, const bstr_t b);
int lw_put_bstr16(uint8_t * dst, const bstr16_t b);
int lw_put_str(uint8_t*dst,const uint8_t *str);
int lw_put_elem_hdr(uint8_t *dst,uint8_t type,uint16_t len);
int lw_put_vendor(uint8_t * dst, uint32_t vendorid,
uint16_t elemid, uint16_t len);
/**
* Put a #bstr_t to an output buffer
* @param dst Destination
* @param b bstr to put
* @return The number of bytes put
*/
static inline int lw_put_bstr(uint8_t * dst, const bstr_t b){
lw_put_data(dst,bstr_data(b),bstr_len(b));
return bstr_len(b);
}
/**
* Put a #bstr16_t to an output buffer
* @param dst Destination
* @param b bstr16 to put
* @return The number of bytes put
*/
static inline int lw_put_bstr16(uint8_t * dst, const bstr16_t b){
lw_put_data(dst,bstr16_data(b),bstr16_len(b));
return bstr16_len(b);
}
/**
* Put a string to an output buffer
* @param dst Output buffer
* @param str zero-terminated string to put
* @return number of bytes put
*/
static inline int lw_put_str(uint8_t*dst,const uint8_t *str) {
return lw_put_data(dst,str,strlen((char*)str));
}
static inline int lw_put_elem_hdr(uint8_t *dst,uint8_t type,uint16_t len)
{
*dst=type;
*((uint16_t*)(dst+1)) = htons(len);
return 3;
}
/**
* Put a message element header for a message to contain a vendor specific payload
* @param dst pointer to destination buffer
* @param vendorid vendorid
* @param elemid element id of vendor specific data
* @len length of vendor specific data
* @return the number of bytes put (always 10)
*/
static inline int lw_put_vendor(uint8_t * dst, uint32_t vendorid,
uint16_t elemid, uint16_t len)
{
lw_put_dword(dst + 0, vendorid);
lw_put_word(dst + 4, elemid);
return 6;
}

77
src/cw/lw_inline.c Normal file
View File

@ -0,0 +1,77 @@
#include "lw.h"
/**
* Put some bytes to an output buffer
* @param dst Destination
* @param data Data to put
* @len length of data (iini bytes)
* @return The number of bytes put
*/
int lw_put_data(uint8_t*dst,const uint8_t*data,uint16_t len)
{
memcpy(dst,data,len);
return len;
}
/**
* Put a #bstr_t to an output buffer
* @param dst Destination
* @param b bstr to put
* @return The number of bytes put
*/
int lw_put_bstr(uint8_t * dst, const bstr_t b){
lw_put_data(dst,bstr_data(b),bstr_len(b));
return bstr_len(b);
}
/**
* Put a #bstr16_t to an output buffer
* @param dst Destination
* @param b bstr16 to put
* @return The number of bytes put
*/
int lw_put_bstr16(uint8_t * dst, const bstr16_t b){
lw_put_data(dst,bstr16_data(b),bstr16_len(b));
return bstr16_len(b);
}
/**
* Put a string to an output buffer
* @param dst Output buffer
* @param str zero-terminated string to put
* @return number of bytes put
*/
int lw_put_str(uint8_t*dst,const uint8_t *str) {
return lw_put_data(dst,str,strlen((char*)str));
}
int lw_put_elem_hdr(uint8_t *dst,uint8_t type,uint16_t len)
{
*dst=type;
*((uint16_t*)(dst+1)) = htons(len);
return 3;
}
/**
* Put a message element header for a message to contain a vendor specific payload
* @param dst pointer to destination buffer
* @param vendorid vendorid
* @param elemid element id of vendor specific data
* @len length of vendor specific data
* @return the number of bytes put (always 10)
*/
int lw_put_vendor(uint8_t * dst, uint32_t vendorid,
uint16_t elemid, uint16_t len)
{
lw_put_dword(dst + 0, vendorid);
lw_put_word(dst + 4, elemid);
return 6;
}

View File

@ -395,3 +395,417 @@ void * mbag_get_data(mbag_t s, const char *id, const struct mbag_typedef * type,
}
/***************************************************/
void * mbag_get_raw(mbag_t s, const char *id, void * def)
{
struct mbag_item *i = mbag_get(s, id);
if (!i)
return def;
return i->data;
}
uint8_t mbag_get_byte(mbag_t s, const char *id, uint8_t def)
{
struct mbag_item *i = mbag_get(s, id);
if (!i)
return def;
if (i->type != MBAG_BYTE)
return def;
return i->byte;
}
uint16_t mbag_get_word(mbag_t s, const char *id, uint16_t def)
{
struct mbag_item *i = mbag_get(s, id);
if (!i)
return def;
if (i->type != MBAG_WORD)
return def;
return i->word;
}
uint32_t mbag_get_dword(mbag_t s, const char *id, uint32_t def)
{
struct mbag_item *i = mbag_get(s, id);
if (!i)
return def;
if (i->type != MTYPE_DWORD)
return def;
return i->dword;
}
mbag_t mbag_i_get_mbag(mbag_t s, uint32_t id, mbag_t def)
{
struct mbag_item *i = mbag_i_get(s, id);
if (!i)
return def;
if (i->type != MBAG_MBAG)
return def;
return i->data;
}
mbag_t mbag_get_mbag(mbag_t s, const char *id, mbag_t def)
{
struct mbag_item *i = mbag_get(s, id);
if (!i)
return def;
if (i->type != MBAG_MBAG)
return def;
return i->data;
}
mbag_item_t * mbag_set_bstrn(mbag_t s, const char *id, uint8_t * data, int len)
{
struct mbag_item *i = mbag_item_create(s, id);
if (!i)
return NULL;
i->type = MBAG_BSTR;
i->data = bstr_create(data, len);
return i;
}
struct mavl *mbag_get_mavl(mbag_t s, const char *id)
{
struct mbag_item *i = mbag_get(s, id);
if (!i)
return NULL;
if (i->type != MBAG_AVLTREE)
return NULL;
return i->data;
}
int mbag_i_set_mavl(mbag_t s, uint32_t id, mavl_t t)
{
struct mbag_item *i = mbag_i_item_create(s, id);
if (!i)
return 0;
i->type = MBAG_AVLTREE;
i->data = t;
return 1;
}
int mbag_set_mavl(mbag_t s, const char *id, mavl_t t)
{
struct mbag_item *i = mbag_item_create(s, id);
if (!i)
return 0;
i->type = MBAG_AVLTREE;
i->data = t;
return 1;
}
/*
struct mavl *mbag_get_avltree_c(mbag_t s, const char *id,
struct mavl *(creator) ())
{
struct mavl * avltree = mbag_get_mavl(s, id);
if (avltree){
return avltree;
}
avltree = creator();
if (!avltree)
return NULL;
mbag_set_mavl(s, id, avltree);
return avltree;
}
*/
mavl_t mbag_get_mavl_c(mbag_t s, const char *id,
mavl_t (creator) ())
{
struct mbag_item *i = mbag_get(s, id);
if (i)
return i->data;
if (!creator)
return NULL;
mavl_t avltree = creator();
if (!avltree)
return NULL;
mbag_set_mavl(s, id, avltree);
return avltree;
}
mavl_t mbag_get_mbag_c(mbag_t s, const char *id,
mavl_t (creator) ())
{
struct mbag_item *i = mbag_get(s, id);
if (i)
return i->data;
if (!creator)
return NULL;
mavl_t avltree = creator();
if (!avltree)
return NULL;
mbag_set_mbag(s, id, avltree);
return avltree;
}
int mbag_inc_word(mbag_t s, const char * id,int n)
{
uint16_t w = mbag_get_word(s,id,0);
mbag_set_word(s,id,w+n);
return 1;
}
mavl_t mbag_i_get_mbag_c(mbag_t s, uint32_t iid,
mavl_t (creator) ())
{
struct mbag_item *i = mbag_i_get(s, iid);
if (i)
return i->data;
if (!creator)
return NULL;
mavl_t avltree = creator();
if (!avltree)
return NULL;
mbag_i_set_mbag(s, iid, avltree);
return avltree;
}
mavl_t mbag_i_get_mavl(mbag_t s, uint32_t id,
mavl_t (creator) ())
{
struct mbag_item *i = mbag_i_get(s, id);
if (i)
return i->data;
if (!creator)
return NULL;
mavl_t avltree = creator();
if (!avltree)
return NULL;
mbag_i_set_mavl(s, id, avltree);
return avltree;
}
char *mbag_get_str(mbag_t s, const char *id, char *def)
{
struct mbag_item *i = mbag_get(s, id);
if (!i)
return def;
return i->data;
};
int mbag_set_str(mbag_t s, const char *id, const char *str)
{
struct mbag_item *i = mbag_item_create(s, id);
if (!i)
return 0;
i->type = MBAG_STR;
i->data = strdup(str);
return 1;
}
int mbag_set_sockaddr(mbag_t s, const char *id, const struct sockaddr * sa)
{
struct mbag_item *i = mbag_item_create(s, id);
if (!i)
return 0;
struct sockaddr_storage * sad = malloc(sizeof(struct sockaddr_storage));
if (!sad){
free(i);
return 0;
}
sock_copyaddr(sad,sa);
i->type = MBAG_SOCKADDR;
i->data = sad;
return 1;
}
/*******/
void *mbag_item_get_data_ptr(struct mbag_item *item)
{
if (item->type == MBAG_FUN )
{
struct mbag_item_fundef *fundef =