3
0
mirror of https://git.kernel.org/pub/scm/network/wireless/iwd.git synced 2024-11-16 17:09:24 +01:00

defs: Add defs.h to hold certain global definitions

This will help to get rid of magic number use throughout the project.
The definitions should be limited to global magic numbers that are used
throughout the project, for example SSID length, MAC address length,
etc.
This commit is contained in:
Denis Kenzior 2024-08-01 12:44:08 -05:00
parent db9c0480ef
commit e565b75032
22 changed files with 57 additions and 28 deletions

View File

@ -214,7 +214,8 @@ eap_sources = src/eap.c src/eap.h src/eap-private.h \
if DAEMON
libexec_PROGRAMS += src/iwd
src_iwd_SOURCES = src/main.c linux/nl80211.h src/iwd.h src/missing.h \
src_iwd_SOURCES = src/main.c linux/nl80211.h src/iwd.h \
src/missing.h src/defs.h \
src/netdev.h src/netdev.c \
src/wiphy.h src/wiphy.c \
src/device.c \

View File

@ -67,7 +67,7 @@ struct ap_state {
ap_stopped_func_t stopped_func;
void *user_data;
char ssid[33];
char ssid[SSID_MAX_SIZE + 1];
char passphrase[64];
uint8_t psk[32];
enum band_freq band;
@ -153,7 +153,7 @@ struct ap_wsc_pbc_probe_record {
};
struct ap_network {
char ssid[33];
char ssid[SSID_MAX_SIZE + 1];
int16_t signal;
enum security security;
};
@ -181,7 +181,7 @@ static int network_signal_compare(const void *a, const void *b, void *user)
static struct ap_network *ap_network_find(struct ap_state *ap,
struct scan_bss *bss)
{
char ssid[33];
char ssid[SSID_MAX_SIZE + 1];
memcpy(ssid, bss->ssid, bss->ssid_len);
ssid[bss->ssid_len] = '\0';
@ -3629,7 +3629,7 @@ static int ap_load_config(struct ap_state *ap, const struct l_settings *config,
return -ENOMSG;
len = strlen(strval);
if (len < 1 || len > 32) {
if (len < 1 || len > SSID_MAX_SIZE) {
l_error("AP SSID length outside the [1, 32] range");
return -EINVAL;
}

View File

@ -35,6 +35,7 @@
#include "ell/useful.h"
#include "src/missing.h"
#include "src/defs.h"
#include "src/crypto.h"
#define ARC4_MIN_KEY_SIZE 1
@ -567,7 +568,7 @@ int crypto_psk_from_passphrase(const char *passphrase,
if (!crypto_passphrase_is_valid(passphrase))
return -ERANGE;
if (ssid_len == 0 || ssid_len > 32)
if (ssid_len == 0 || ssid_len > SSID_MAX_SIZE)
return -ERANGE;
result = l_cert_pkcs5_pbkdf2(L_CHECKSUM_SHA1, passphrase,

13
src/defs.h Normal file
View File

@ -0,0 +1,13 @@
/*
* Wireless daemon for Linux
* Copyright (C) 2024 Cruise, LLC
*
* SPDX-License-Identifier: LGPL-2.1-or-later
*/
#ifndef __DEFS_H__
#define __DEFS_H__
#define SSID_MAX_SIZE 32
#endif

View File

@ -19,6 +19,9 @@
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*
*/
#include "src/defs.h"
struct l_ecc_point;
struct l_ecc_scalar;
enum ie_rsn_akm_suite;
@ -112,7 +115,7 @@ enum dpp_attribute_type {
};
struct dpp_configuration {
char ssid[33];
char ssid[SSID_MAX_SIZE + 1];
size_t ssid_len;
uint32_t akm_suites;
char *passphrase;

View File

@ -2067,7 +2067,7 @@ static bool eap_wsc_r_load_settings(struct eap_state *eap,
str = l_settings_get_string(settings, "WSC", "WPA2-SSID");
if (str) {
if (strlen(str) > 32)
if (strlen(str) > SSID_MAX_SIZE)
goto bad_string;
wsc->m2->auth_type_flags |=
@ -2113,7 +2113,7 @@ static bool eap_wsc_r_load_settings(struct eap_state *eap,
str = l_settings_get_string(settings, "WSC", "Open-SSID");
if (str) {
if (strlen(str) > 32)
if (strlen(str) > SSID_MAX_SIZE)
goto bad_string;
wsc->m2->auth_type_flags |= WSC_AUTHENTICATION_TYPE_OPEN;

View File

@ -141,7 +141,7 @@ struct handshake_state {
bool supplicant_ocvc : 1;
bool ext_key_id_capable : 1;
bool force_default_ecc_group : 1;
uint8_t ssid[32];
uint8_t ssid[SSID_MAX_SIZE];
size_t ssid_len;
char *passphrase;
char *password_identifier;

View File

@ -2642,7 +2642,7 @@ int ie_parse_owe_transition(const void *data, size_t len,
return -ENOMSG;
slen = l_get_u8(ie + 12);
if (slen > 32)
if (slen > SSID_MAX_SIZE)
return -ENOMSG;
/*

View File

@ -23,6 +23,7 @@
#include <stdbool.h>
#include <stddef.h>
#include <unistd.h>
#include "src/defs.h"
/*
* Information elements, IEEE Std 802.11-2012 ch. 8.4.2 and
@ -565,7 +566,7 @@ struct ie_fils_ip_addr_response_info {
struct ie_owe_transition_info {
uint8_t bssid[6];
uint8_t ssid[32];
uint8_t ssid[SSID_MAX_SIZE];
size_t ssid_len;
uint8_t oper_class;
uint8_t channel;

View File

@ -20,6 +20,8 @@
*
*/
#include "src/defs.h"
#define SETTINGS "Settings"
#define NET_HIDDEN SETTINGS, "Hidden"
#define NET_AUTOCONNECT SETTINGS, "AutoConnect"
@ -84,7 +86,7 @@ struct network_config {
struct network_info {
const struct network_info_ops *ops;
char ssid[33];
char ssid[SSID_MAX_SIZE + 1];
enum security type;
struct l_queue *known_frequencies;
int seen_count; /* Ref count for network.info */

View File

@ -63,7 +63,7 @@ static uint32_t known_networks_watch;
static uint32_t event_watch;
struct network {
char ssid[33];
char ssid[SSID_MAX_SIZE + 1];
enum security security;
char *object_path;
struct station *station;

View File

@ -22,6 +22,7 @@
#include <stdint.h>
#include "src/defs.h"
#include "src/wscutil.h"
struct l_queue;
@ -285,7 +286,7 @@ struct p2p_client_info_descriptor {
struct p2p_group_id_attr {
uint8_t device_addr[6];
char ssid[33];
char ssid[SSID_MAX_SIZE + 1];
};
struct p2p_interface_attr {

View File

@ -109,7 +109,7 @@ struct rrm_beacon_req_info {
uint8_t channel; /* The single channel provided in request */
uint16_t duration;
uint8_t bssid[6]; /* Request filtered by BSSID */
char ssid[33]; /* Request filtered by SSID */
char ssid[SSID_MAX_SIZE + 1]; /* Request filtered by SSID */
bool has_ssid;
uint32_t scan_id;
uint64_t scan_start_time;

View File

@ -1325,7 +1325,7 @@ static bool scan_parse_bss_information_elements(struct scan_bss *bss,
switch (tag) {
case IE_TYPE_SSID:
if (iter.len > 32)
if (iter.len > SSID_MAX_SIZE)
return false;
memcpy(bss->ssid, iter.data, iter.len);

View File

@ -20,6 +20,8 @@
*
*/
#include "src/defs.h"
struct scan_freq_set;
struct ie_rsn_info;
struct ie_owe_transition_info;
@ -62,7 +64,7 @@ struct scan_bss {
};
struct ie_owe_transition_info *owe_trans;
uint8_t mde[3];
uint8_t ssid[32];
uint8_t ssid[SSID_MAX_SIZE];
uint8_t ssid_len;
uint8_t utilization;
uint8_t cc[3];

View File

@ -498,7 +498,7 @@ static struct network *station_add_seen_bss(struct station *station,
struct network *network;
enum security security;
const char *path;
char ssid[33];
char ssid[SSID_MAX_SIZE + 1];
station_print_scan_bss(bss);
@ -3916,7 +3916,7 @@ static struct l_dbus_message *station_dbus_connect_hidden_network(
if (!l_dbus_message_get_arguments(message, "s", &ssid))
return dbus_error_invalid_args(message);
if (strlen(ssid) > 32)
if (strlen(ssid) > SSID_MAX_SIZE)
return dbus_error_invalid_args(message);
if (known_networks_find(ssid, SECURITY_PSK) ||

View File

@ -45,6 +45,7 @@
#include "ell/useful.h"
#include "src/missing.h"
#include "src/defs.h"
#include "src/common.h"
#include "src/storage.h"
#include "src/crypto.h"
@ -315,7 +316,7 @@ const char *storage_network_ssid_from_path(const char *path,
return NULL;
if (filename[0] != '=') {
if (end == filename || end - filename > 32)
if (end == filename || end - filename > SSID_MAX_SIZE)
return NULL;
for (c = filename; c < end; c++)

View File

@ -34,6 +34,7 @@
#include <ell/ell.h>
#include "ell/useful.h"
#include "src/defs.h"
#include "src/util.h"
#include "src/band.h"
@ -45,7 +46,7 @@ const char *util_ssid_to_utf8(size_t len, const uint8_t *ssid)
memset(buf, 0, sizeof(buf));
if (len > 32)
if (len > SSID_MAX_SIZE)
goto no_ssid;
while (i < len && !ssid[i])
@ -84,7 +85,7 @@ no_ssid:
bool util_ssid_is_utf8(size_t len, const uint8_t *ssid)
{
if (len > 32)
if (len > SSID_MAX_SIZE)
return false;
return l_utf8_validate((const char *)ssid, len, NULL);

View File

@ -21,7 +21,7 @@
*/
struct wsc_credentials_info {
char ssid[33];
char ssid[SSID_MAX_SIZE + 1];
enum security security;
union {
uint8_t psk[32];

View File

@ -500,7 +500,7 @@ static bool extract_ssid(struct wsc_attr_iter *iter, void *data)
unsigned int len;
len = wsc_attr_iter_get_length(iter);
if (len > 32)
if (len > SSID_MAX_SIZE)
return false;
ssid->iov_len = len;

View File

@ -20,6 +20,8 @@
*
*/
#include "src/defs.h"
struct iovec;
/* Wi-Fi Simple Configuration Technical Specification v2.0.5, Section 12 */
@ -330,7 +332,7 @@ static inline unsigned int wsc_attr_iter_get_pos(struct wsc_attr_iter *iter)
}
struct wsc_credential {
uint8_t ssid[32];
uint8_t ssid[SSID_MAX_SIZE];
uint8_t ssid_len;
uint16_t auth_type;
uint16_t encryption_type;

View File

@ -31,11 +31,12 @@
#include <arpa/inet.h>
#include <ell/ell.h>
#include "src/defs.h"
#include "src/util.h"
struct ssid_test_data {
size_t len;
uint8_t ssid[32];
uint8_t ssid[SSID_MAX_SIZE];
const char *string;
bool result;
};