Commit d6bf498f authored by Luis R. Rodriguez's avatar Luis R. Rodriguez

crda: use stdint.h instead of linux/types.h

Given that we may need to make a library out of some
routines here to share with the regulatory simulator.
Signed-off-by: 's avatarLuis R. Rodriguez <mcgrof@qca.qualcomm.com>
parent 8cbde045
......@@ -23,7 +23,7 @@
static int is_valid_reg_rule(const struct ieee80211_reg_rule *rule)
{
const struct ieee80211_freq_range *freq_range = &rule->freq_range;
__u32 freq_diff;
uint32_t freq_diff;
if (freq_range->start_freq_khz == 0 || freq_range->end_freq_khz == 0)
return 0;
......@@ -48,7 +48,7 @@ static int reg_rules_intersect(
{
struct ieee80211_freq_range *freq_range1, *freq_range2, *freq_range;
struct ieee80211_power_rule *power_rule1, *power_rule2, *power_rule;
__u32 freq_diff;
uint32_t freq_diff;
freq_range1 = &rule1->freq_range;
freq_range2 = &rule2->freq_range;
......@@ -184,7 +184,7 @@ int main(int argc, char **argv)
{
int fd;
struct stat stat;
__u8 *db;
uint8_t *db;
struct regdb_file_header *header;
struct regdb_file_reg_country *countries;
int dblen, siglen, num_countries, i, r = 0;
......
......@@ -4,8 +4,8 @@
#include <arpa/inet.h>
#include "reglib.h"
static void reg_rule2rd(__u8 *db, int dblen,
__be32 ruleptr, struct ieee80211_reg_rule *rd_reg_rule)
static void reg_rule2rd(uint8_t *db, int dblen,
uint32_t ruleptr, struct ieee80211_reg_rule *rd_reg_rule)
{
struct regdb_file_reg_rule *rule;
struct regdb_file_freq_range *freq;
......@@ -29,7 +29,7 @@ static void reg_rule2rd(__u8 *db, int dblen,
}
/* Converts a file regdomain to ieee80211_regdomain, easier to manage */
struct ieee80211_regdomain *country2rd(__u8 *db, int dblen,
struct ieee80211_regdomain *country2rd(uint8_t *db, int dblen,
struct regdb_file_reg_country *country)
{
struct regdb_file_reg_rules_collection *rcoll;
......@@ -41,7 +41,7 @@ struct ieee80211_regdomain *country2rd(__u8 *db, int dblen,
num_rules = ntohl(rcoll->reg_rule_num);
/* re-get pointer with sanity checking for num_rules */
rcoll = crda_get_file_ptr(db, dblen,
sizeof(*rcoll) + num_rules * sizeof(__be32),
sizeof(*rcoll) + num_rules * sizeof(uint32_t),
country->reg_collection_ptr);
size_of_rd = sizeof(struct ieee80211_regdomain) +
......
#ifndef REG_DB_H
#define REG_DB_H
#include <linux/types.h>
#include <stdint.h>
/*
* WARNING: This file needs to be kept in sync with
......@@ -28,9 +28,9 @@
struct regdb_file_header {
/* must be REGDB_MAGIC */
__be32 magic;
uint32_t magic;
/* must be REGDB_VERSION */
__be32 version;
uint32_t version;
/*
* Pointer (offset) into file where country list starts
* and number of countries. The country list is sorted
......@@ -38,14 +38,14 @@ struct regdb_file_header {
* become really huge). Each country is described by a
* struct regdb_file_reg_country.
*/
__be32 reg_country_ptr;
__be32 reg_country_num;
uint32_t reg_country_ptr;
uint32_t reg_country_num;
/* length (in bytes) of the signature at the end of the file */
__be32 signature_length;
uint32_t signature_length;
};
struct regdb_file_freq_range {
__be32 start_freq, /* in kHz */
uint32_t start_freq, /* in kHz */
end_freq, /* in kHz */
max_bandwidth; /* in kHz */
};
......@@ -56,9 +56,9 @@ struct regdb_file_freq_range {
*/
struct regdb_file_power_rule {
/* antenna gain is in mBi (100 * dBi) */
__be32 max_antenna_gain;
uint32_t max_antenna_gain;
/* this is in mBm (100 * dBm) */
__be32 max_eirp;
uint32_t max_eirp;
};
/* must match <linux/nl80211.h> enum nl80211_reg_rule_flags */
......@@ -80,27 +80,27 @@ enum reg_rule_flags {
struct regdb_file_reg_rule {
/* pointers (offsets) into the file */
__be32 freq_range_ptr; /* pointer to a struct regdb_file_freq_range */
__be32 power_rule_ptr; /* pointer to a struct regdb_file_power_rule */
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 */
__be32 flags;
uint32_t flags;
};
struct regdb_file_reg_rules_collection {
__be32 reg_rule_num;
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 */
__be32 reg_rule_ptrs[];
uint32_t reg_rule_ptrs[];
};
struct regdb_file_reg_country {
__u8 alpha2[2];
__u8 PAD;
__u8 creqs; /* first two bits define DFS region */
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 */
__be32 reg_collection_ptr;
uint32_t reg_collection_ptr;
};
......
......@@ -13,7 +13,7 @@ int main(int argc, char **argv)
{
int fd;
struct stat stat;
__u8 *db;
uint8_t *db;
struct regdb_file_header *header;
struct regdb_file_reg_country *countries;
int dblen, siglen, num_countries, i, r = 0;
......
......@@ -26,9 +26,9 @@
#include "keys-gcrypt.c"
#endif
void *crda_get_file_ptr(__u8 *db, int dblen, int structlen, __be32 ptr)
void *crda_get_file_ptr(uint8_t *db, int dblen, int structlen, uint32_t ptr)
{
__u32 p = ntohl(ptr);
uint32_t p = ntohl(ptr);
if (p > dblen - structlen) {
fprintf(stderr, "Invalid database file, bad pointer!\n");
......@@ -44,11 +44,11 @@ void *crda_get_file_ptr(__u8 *db, int dblen, int structlen, __be32 ptr)
* at least one key in the array such that the signature is valid
* against that key; 0 otherwise.
*/
int crda_verify_db_signature(__u8 *db, int dblen, int siglen)
int crda_verify_db_signature(uint8_t *db, int dblen, int siglen)
{
#ifdef USE_OPENSSL
RSA *rsa;
__u8 hash[SHA_DIGEST_LENGTH];
uint8_t hash[SHA_DIGEST_LENGTH];
unsigned int i;
int ok = 0;
DIR *pubkey_dir;
......@@ -99,7 +99,7 @@ int crda_verify_db_signature(__u8 *db, int dblen, int siglen)
#ifdef USE_GCRYPT
gcry_mpi_t mpi_e, mpi_n;
gcry_sexp_t rsa, signature, data;
__u8 hash[20];
uint8_t hash[20];
unsigned int i;
int ok = 0;
......
......@@ -2,7 +2,7 @@
#define REG_LIB_H
#include <stdlib.h>
#include <linux/types.h>
#include <stdint.h>
#include "regdb.h"
......@@ -10,24 +10,24 @@
/* This matches the kernel's data structures */
struct ieee80211_freq_range {
__u32 start_freq_khz;
__u32 end_freq_khz;
__u32 max_bandwidth_khz;
uint32_t start_freq_khz;
uint32_t end_freq_khz;
uint32_t max_bandwidth_khz;
};
struct ieee80211_power_rule {
__u32 max_antenna_gain;
__u32 max_eirp;
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;
__u32 flags;
uint32_t flags;
};
struct ieee80211_regdomain {
__u32 n_reg_rules;
uint32_t n_reg_rules;
char alpha2[2];
struct ieee80211_reg_rule reg_rules[];
};
......@@ -61,21 +61,21 @@ static inline int is_valid_regdom(const char *alpha2)
return 1;
}
static inline __u32 max(__u32 a, __u32 b)
static inline uint32_t max(uint32_t a, uint32_t b)
{
return (a > b) ? a : b;
}
static inline __u32 min(__u32 a, __u32 b)
static inline uint32_t min(uint32_t a, uint32_t b)
{
return (a > b) ? b : a;
}
void *crda_get_file_ptr(__u8 *db, int dblen, int structlen, __be32 ptr);
int crda_verify_db_signature(__u8 *db, int dblen, int siglen);
void *crda_get_file_ptr(uint8_t *db, int dblen, int structlen, uint32_t ptr);
int crda_verify_db_signature(uint8_t *db, int dblen, int siglen);
/* File reg db entry -> rd converstion utilities */
struct ieee80211_regdomain *country2rd(__u8 *db, int dblen,
struct ieee80211_regdomain *country2rd(uint8_t *db, int dblen,
struct regdb_file_reg_country *country);
/* reg helpers */
......
......@@ -87,7 +87,7 @@ static struct pubkey keys[] = {
def print_gcrypt(output, name, val):
while val[0] == '\0':
val = val[1:]
output.write('static const __u8 %s[%d] = {\n' % (name, len(val)))
output.write('static const uint8_t %s[%d] = {\n' % (name, len(val)))
idx = 0
for v in val:
if not idx:
......@@ -104,8 +104,8 @@ def print_gcrypt(output, name, val):
def print_gcrypt_keys(output, n):
output.write(r'''
struct key_params {
const __u8 *e, *n;
__u32 len_e, len_n;
const uint8_t *e, *n;
uint32_t len_e, len_n;
};
#define KEYS(_e, _n) { \
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment