openbox lab initialized
This commit is contained in:
3685
openflow/usr/include/reglib/nl80211.h
Normal file
3685
openflow/usr/include/reglib/nl80211.h
Normal file
File diff suppressed because it is too large
Load Diff
150
openflow/usr/include/reglib/regdb.h
Normal file
150
openflow/usr/include/reglib/regdb.h
Normal file
@@ -0,0 +1,150 @@
|
||||
#ifndef REG_DB_H
|
||||
#define REG_DB_H
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
/*
|
||||
* WARNING: This file needs to be kept in sync with
|
||||
* - the parser (dbparse.py)
|
||||
* - the generator code (db2bin.py)
|
||||
*
|
||||
* As it is only Linux is using these so we have a direct one to
|
||||
* one map for flags. Each respective OS flag is listed where
|
||||
* appropriate.
|
||||
*/
|
||||
|
||||
/* spells "RGDB" */
|
||||
#define REGDB_MAGIC 0x52474442
|
||||
|
||||
/*
|
||||
* Only supported version now, start at arbitrary number
|
||||
* to have some more magic. We still consider this to be
|
||||
* "Version 1" of the file.
|
||||
*/
|
||||
#define REGDB_VERSION 19
|
||||
|
||||
/*
|
||||
* The signature at the end of the file is an RSA-signed
|
||||
* SHA-1 hash of the file.
|
||||
*/
|
||||
|
||||
/* db file starts with a struct regdb_file_header */
|
||||
|
||||
struct regdb_file_header {
|
||||
/* must be REGDB_MAGIC */
|
||||
uint32_t magic;
|
||||
/* must be REGDB_VERSION */
|
||||
uint32_t version;
|
||||
/*
|
||||
* Pointer (offset) into file where country list starts
|
||||
* and number of countries. The country list is sorted
|
||||
* alphabetically to allow binary searching (should it
|
||||
* become really huge). Each country is described by a
|
||||
* struct regdb_file_reg_country.
|
||||
*/
|
||||
uint32_t reg_country_ptr;
|
||||
uint32_t reg_country_num;
|
||||
/* length (in bytes) of the signature at the end of the file */
|
||||
uint32_t signature_length;
|
||||
};
|
||||
|
||||
struct regdb_file_freq_range {
|
||||
uint32_t start_freq, /* in kHz */
|
||||
end_freq, /* in kHz */
|
||||
max_bandwidth; /* in kHz */
|
||||
};
|
||||
|
||||
/*
|
||||
* Values of zero mean "not applicable", i.e. the regulatory
|
||||
* does not limit a certain value.
|
||||
*/
|
||||
struct regdb_file_power_rule {
|
||||
/* antenna gain is in mBi (100 * dBi) */
|
||||
uint32_t max_antenna_gain;
|
||||
/* this is in mBm (100 * dBm) */
|
||||
uint32_t max_eirp;
|
||||
};
|
||||
|
||||
/*
|
||||
* The Linux map defined in <linux/uapi/nl80211.h> enum nl80211_reg_rule_flags
|
||||
*/
|
||||
enum reg_rule_flags {
|
||||
RRF_NO_OFDM = 1<<0, /* OFDM modulation not allowed */
|
||||
RRF_NO_CCK = 1<<1, /* CCK modulation not allowed */
|
||||
RRF_NO_INDOOR = 1<<2, /* indoor operation not allowed */
|
||||
RRF_NO_OUTDOOR = 1<<3, /* outdoor operation not allowed */
|
||||
RRF_DFS = 1<<4, /* DFS support is required to be
|
||||
* used */
|
||||
RRF_PTP_ONLY = 1<<5, /* this is only for Point To Point
|
||||
* links */
|
||||
RRF_PTMP_ONLY = 1<<6, /* this is only for Point To Multi
|
||||
* Point links */
|
||||
RRF_NO_IR = 1<<7, /* do not initiate radiation */
|
||||
__RRF_NO_IBSS = 1<<8, /* old no-IBSS rule, maps to no-ir */
|
||||
};
|
||||
|
||||
#define RRF_NO_IR_ALL (RRF_NO_IR | __RRF_NO_IBSS)
|
||||
|
||||
/**
|
||||
* enum regdb_dfs_regions - regulatory DFS regions
|
||||
*
|
||||
* @REGDB_DFS_UNSET: Country has no DFS master region specified
|
||||
* @REGDB_DFS_FCC: Country follows DFS master rules from FCC
|
||||
* @REGDB_DFS_ETSI: Country follows DFS master rules from ETSI
|
||||
* @REGDB_DFS_JP: Country follows DFS master rules from JP/MKK/Telec
|
||||
*/
|
||||
enum regdb_dfs_regions {
|
||||
REGDB_DFS_UNSET = 0,
|
||||
REGDB_DFS_FCC = 1,
|
||||
REGDB_DFS_ETSI = 2,
|
||||
REGDB_DFS_JP = 3,
|
||||
};
|
||||
|
||||
struct regdb_file_reg_rule {
|
||||
/* pointers (offsets) into the file */
|
||||
uint32_t freq_range_ptr; /* pointer to a struct regdb_file_freq_range */
|
||||
uint32_t power_rule_ptr; /* pointer to a struct regdb_file_power_rule */
|
||||
/* rule flags using enum reg_rule_flags */
|
||||
uint32_t flags;
|
||||
};
|
||||
|
||||
struct regdb_file_reg_rules_collection {
|
||||
uint32_t reg_rule_num;
|
||||
/* pointers (offsets) into the file. There are reg_rule_num elements
|
||||
* in the reg_rule_ptrs array pointing to struct
|
||||
* regdb_file_reg_rule */
|
||||
uint32_t reg_rule_ptrs[];
|
||||
};
|
||||
|
||||
struct regdb_file_reg_country {
|
||||
uint8_t alpha2[2];
|
||||
uint8_t PAD;
|
||||
uint8_t creqs; /* first two bits define DFS region */
|
||||
/* pointer (offset) into the file to a struct
|
||||
* regdb_file_reg_rules_collection */
|
||||
uint32_t reg_collection_ptr;
|
||||
};
|
||||
|
||||
|
||||
/*
|
||||
* Verify that no unexpected padding is added to structures
|
||||
* for some reason.
|
||||
*/
|
||||
|
||||
#define ERROR_ON(cond) \
|
||||
((void)sizeof(char[1 - 2*!!(cond)]))
|
||||
|
||||
#define CHECK_STRUCT(name, size) \
|
||||
ERROR_ON(sizeof(struct name) != size)
|
||||
|
||||
static inline void check_db_binary_structs(void)
|
||||
{
|
||||
CHECK_STRUCT(regdb_file_header, 20);
|
||||
CHECK_STRUCT(regdb_file_freq_range, 12);
|
||||
CHECK_STRUCT(regdb_file_power_rule, 8);
|
||||
CHECK_STRUCT(regdb_file_reg_rule, 12);
|
||||
CHECK_STRUCT(regdb_file_reg_rules_collection, 4);
|
||||
CHECK_STRUCT(regdb_file_reg_country, 8);
|
||||
}
|
||||
|
||||
#endif
|
||||
243
openflow/usr/include/reglib/reglib.h
Normal file
243
openflow/usr/include/reglib/reglib.h
Normal file
@@ -0,0 +1,243 @@
|
||||
#ifndef REG_LIB_H
|
||||
#define REG_LIB_H
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <stdint.h>
|
||||
#include <stdbool.h>
|
||||
#include <sys/stat.h>
|
||||
#include <math.h>
|
||||
|
||||
#include "regdb.h"
|
||||
|
||||
/* Common regulatory structures, functions and helpers */
|
||||
|
||||
/* This matches the kernel's data structures */
|
||||
struct ieee80211_freq_range {
|
||||
uint32_t start_freq_khz;
|
||||
uint32_t end_freq_khz;
|
||||
uint32_t max_bandwidth_khz;
|
||||
};
|
||||
|
||||
struct ieee80211_power_rule {
|
||||
uint32_t max_antenna_gain;
|
||||
uint32_t max_eirp;
|
||||
};
|
||||
|
||||
struct ieee80211_reg_rule {
|
||||
struct ieee80211_freq_range freq_range;
|
||||
struct ieee80211_power_rule power_rule;
|
||||
uint32_t flags;
|
||||
};
|
||||
|
||||
struct ieee80211_regdomain {
|
||||
uint32_t n_reg_rules;
|
||||
char alpha2[2];
|
||||
uint8_t dfs_region;
|
||||
struct ieee80211_reg_rule reg_rules[];
|
||||
};
|
||||
|
||||
/* Remove this once upstream nl80211.h gets this */
|
||||
#define NL80211_RRF_NO_IR (1<<7)
|
||||
|
||||
#define REGLIB_MHZ_TO_KHZ(freq) ((freq) * 1000)
|
||||
#define REGLIB_KHZ_TO_MHZ(freq) ((freq) / 1000)
|
||||
#define REGLIB_DBI_TO_MBI(gain) ((gain) * 100)
|
||||
#define REGLIB_MBI_TO_DBI(gain) ((gain) / 100)
|
||||
#define REGLIB_DBM_TO_MBM(gain) ((gain) * 100)
|
||||
#define REGLIB_MBM_TO_DBM(gain) ((gain) / 100)
|
||||
|
||||
#define REGLIB_MW_TO_DBM(gain) (10 * log10(gain))
|
||||
#define REGLIB_MW_TO_MBM(gain) (REGLIB_DBM_TO_MBM(REGLIB_MW_TO_DBM(gain)))
|
||||
|
||||
/**
|
||||
* struct reglib_regdb_ctx - reglib regdb context
|
||||
*
|
||||
* This can be used to interat with reglib without
|
||||
* having to open() / close() / mmap() / munmap()
|
||||
* and check the regdb binary file for integrity and
|
||||
* authorship.
|
||||
*
|
||||
* @fd: file descriptor of the db
|
||||
* @stat: @fd fstat()
|
||||
* @db: mmap() of the db of @real_dblen
|
||||
* @real_dblen: file size in bytes of @fd
|
||||
* @siglen: size in bytes of the signature at the end of the file
|
||||
* @dblen: database lenghth, this is the @real_dblen - @siglen
|
||||
* @verified: whether or not this regdb has been RSA verified.
|
||||
* This value is dependent on whether or not you enabled
|
||||
* signature verification with gcrypt, openssl, or none
|
||||
* at all. If no signature verification was not compiled
|
||||
* in then this will always be true otherwise this will
|
||||
* only be true if the RSA digital signature of the SHA1
|
||||
* sum of the regulatory database at the end of the
|
||||
* regulatory database can be verified with the one of
|
||||
* the trusted public keys.
|
||||
*/
|
||||
struct reglib_regdb_ctx {
|
||||
int fd;
|
||||
struct stat stat;
|
||||
uint8_t *db;
|
||||
uint32_t real_dblen;
|
||||
uint32_t siglen;
|
||||
uint32_t dblen;
|
||||
bool verified;
|
||||
|
||||
struct regdb_file_header *header;
|
||||
uint32_t num_countries;
|
||||
struct regdb_file_reg_country *countries;
|
||||
};
|
||||
|
||||
static inline int reglib_is_world_regdom(const char *alpha2)
|
||||
{
|
||||
if (alpha2[0] == '0' && alpha2[1] == '0')
|
||||
return 1;
|
||||
return 0;
|
||||
}
|
||||
|
||||
static inline int reglib_isalpha_upper(char letter)
|
||||
{
|
||||
if (letter >= 'A' && letter <= 'Z')
|
||||
return 1;
|
||||
return 0;
|
||||
}
|
||||
|
||||
static inline int reglib_is_alpha2(const char *alpha2)
|
||||
{
|
||||
if (reglib_isalpha_upper(alpha2[0]) && reglib_isalpha_upper(alpha2[1]))
|
||||
return 1;
|
||||
return 0;
|
||||
}
|
||||
|
||||
static inline int reglib_is_valid_regdom(const char *alpha2)
|
||||
{
|
||||
if (!reglib_is_alpha2(alpha2) && !reglib_is_world_regdom(alpha2))
|
||||
return 0;
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
static inline uint32_t reglib_max(uint32_t a, uint32_t b)
|
||||
{
|
||||
return (a > b) ? a : b;
|
||||
}
|
||||
|
||||
static inline uint32_t reglib_min(uint32_t a, uint32_t b)
|
||||
{
|
||||
return (a > b) ? b : a;
|
||||
}
|
||||
|
||||
void *
|
||||
reglib_get_file_ptr(uint8_t *db, size_t dblen, size_t structlen, uint32_t ptr);
|
||||
int reglib_verify_db_signature(uint8_t *db, size_t dblen, size_t siglen);
|
||||
|
||||
/**
|
||||
* reglib_malloc_regdb_ctx - create a regdb context for usage with reglib
|
||||
*
|
||||
* @regdb_file: file name
|
||||
*
|
||||
* Most operations on reglib iterate over the database somehow and prior
|
||||
* to iterating over it it must check the signature. Use this context helper
|
||||
* to let you query the db within different contexts in your program and
|
||||
* just be sure to call reglib_free_regdb_ctx() when done. This helper will
|
||||
* open the file passed and mmap() it.
|
||||
*/
|
||||
const struct reglib_regdb_ctx *reglib_malloc_regdb_ctx(const char *regdb_file);
|
||||
|
||||
/**
|
||||
* reglib_free_regdb_ctx - free a regdb context used with reglib
|
||||
*
|
||||
* @regdb_ctx: the reglib regdb context created with reglib_malloc_regdb_ctx()
|
||||
*
|
||||
* This will do all the handy work to close up, munmap, and free the
|
||||
* reglib regdb context passed.
|
||||
*/
|
||||
void reglib_free_regdb_ctx(const struct reglib_regdb_ctx *regdb_ctx);
|
||||
|
||||
const struct ieee80211_regdomain *
|
||||
reglib_get_rd_idx(unsigned int idx, const struct reglib_regdb_ctx *ctx);
|
||||
|
||||
#define reglib_for_each_country(__rd, __idx, __ctx) \
|
||||
for (__rd = reglib_get_rd_idx(__idx, __ctx); \
|
||||
__rd != NULL; \
|
||||
__rd = reglib_get_rd_idx(++__idx, __ctx)) \
|
||||
|
||||
const struct ieee80211_regdomain *
|
||||
reglib_get_rd_alpha2(const char *alpha2, const char *file);
|
||||
|
||||
/**
|
||||
* reglib_is_valid_rd - validate regulatory domain data structure
|
||||
*
|
||||
* @rd: regulatory domain data structure to validate
|
||||
*
|
||||
* You can use this to validate regulatory domain data structures
|
||||
* for possible inconsistencies.
|
||||
*/
|
||||
int reglib_is_valid_rd(const struct ieee80211_regdomain *rd);
|
||||
|
||||
/* reg helpers */
|
||||
void reglib_print_regdom(const struct ieee80211_regdomain *rd);
|
||||
struct ieee80211_regdomain *
|
||||
reglib_intersect_rds(const struct ieee80211_regdomain *rd1,
|
||||
const struct ieee80211_regdomain *rd2);
|
||||
|
||||
/**
|
||||
* reglib_intersect_regdb - intersects a regulatory database
|
||||
*
|
||||
* @regdb_file: the regulatory database to intersect
|
||||
*
|
||||
* Goes through an entire regulatory database and intersects all regulatory
|
||||
* domains. This will skip any regulatory marked with an alpha2 of '00', which
|
||||
* is used to indicate a world regulatory domain. If intersection is able
|
||||
* to find rules that fit all regulatory domains it return a regulatory
|
||||
* domain with such rules otherwise it returns NULL.
|
||||
*/
|
||||
const struct ieee80211_regdomain *
|
||||
reglib_intersect_regdb(const struct reglib_regdb_ctx *ctx);
|
||||
|
||||
/**
|
||||
* @reglib_create_parse_stream - provide a clean new stream for processing
|
||||
*
|
||||
* @fp: FILE stream, could be stdin, or a stream from an open file.
|
||||
*
|
||||
* In order to parse a stream we recommend to create a new stream
|
||||
* using this helper. A new stream is preferred in order to work
|
||||
* with stdin, as otherwise we cannot rewind() and move around
|
||||
* the stream. This helper will create new stream using tmpfile()
|
||||
* and also remove all comments. It will be closed and the file
|
||||
* deleted when the process terminates.
|
||||
*/
|
||||
FILE *reglib_create_parse_stream(FILE *fp);
|
||||
|
||||
/**
|
||||
* @reglib_parse_country - parse stream to build a regulatory domain
|
||||
*
|
||||
* @fp: FILE stream, could be stdin, or a stream from an open file.
|
||||
*
|
||||
* Parse stream and return back a built regulatory domain. Returns
|
||||
* NULL if one could not be built.
|
||||
*/
|
||||
struct ieee80211_regdomain *reglib_parse_country(FILE *fp);
|
||||
|
||||
/**
|
||||
* @reglib_optimize_regdom - optimize a regulatory domain
|
||||
*
|
||||
* @rd: a regulatory domain to be optimized
|
||||
*
|
||||
* A regulatory domain may exist without optimal expressions
|
||||
* over its rules. This will look for regulatory rules that can
|
||||
* be combined together to reduce the size of the regulatory
|
||||
* domain and its expression.
|
||||
*
|
||||
* Regulatory rules will be combined if their max allowed
|
||||
* bandwidth, max EIRP, and flags all match.
|
||||
*/
|
||||
struct ieee80211_regdomain *
|
||||
reglib_optimize_regdom(struct ieee80211_regdomain *rd);
|
||||
|
||||
#define reglib_for_each_country_stream(__fp, __rd) \
|
||||
for (__rd = reglib_parse_country(__fp); \
|
||||
__rd != NULL; \
|
||||
__rd = reglib_parse_country(__fp)) \
|
||||
|
||||
#endif
|
||||
Reference in New Issue
Block a user