From a8deded66bdd19e49d80fc00ad2ff5c5d4fb3b71 Mon Sep 17 00:00:00 2001 From: Chris Manton Date: Fri, 6 Nov 2020 09:30:39 -0800 Subject: [PATCH] Enum-ify stack/smp/smp_int::SMP_MODEL_ Towards readable code Bug: 163134718 Tag: #refactor Test: gd/cert/run --host Change-Id: I5ba9e3743a9d2374304caa10a24fca625d137bcf --- stack/smp/smp_int.h | 31 ++++++++++++++++--------------- stack/smp/smp_utils.cc | 6 +++--- 2 files changed, 19 insertions(+), 18 deletions(-) diff --git a/stack/smp/smp_int.h b/stack/smp/smp_int.h index 59d7881aa..9181cea06 100644 --- a/stack/smp/smp_int.h +++ b/stack/smp/smp_int.h @@ -30,21 +30,22 @@ #include "smp_api.h" #include "stack/crypto_toolbox/crypto_toolbox.h" -/* Legacy mode */ -#define SMP_MODEL_ENCRYPTION_ONLY 0 /* Just Works model */ -#define SMP_MODEL_PASSKEY 1 /* Passkey Entry model, input the key */ -#define SMP_MODEL_OOB 2 /* OOB model */ -#define SMP_MODEL_KEY_NOTIF 3 /* Passkey Entry model, display the key */ -/* Secure connections mode */ -#define SMP_MODEL_SEC_CONN_JUSTWORKS 4 /* Just Works model */ -#define SMP_MODEL_SEC_CONN_NUM_COMP 5 /* Numeric Comparison model */ -#define SMP_MODEL_SEC_CONN_PASSKEY_ENT 6 /* Passkey Entry model, */ - /* this side inputs the key */ -#define SMP_MODEL_SEC_CONN_PASSKEY_DISP 7 /* Passkey Entry model, */ - /* this side displays the key */ -#define SMP_MODEL_SEC_CONN_OOB 8 /* Secure Connections mode, OOB model */ -#define SMP_MODEL_OUT_OF_RANGE 9 -typedef uint8_t tSMP_ASSO_MODEL; +typedef enum : uint8_t { + /* Legacy mode */ + SMP_MODEL_ENCRYPTION_ONLY = 0, /* Just Works model */ + SMP_MODEL_PASSKEY = 1, /* Passkey Entry model, input the key */ + SMP_MODEL_OOB = 2, /* OOB model */ + SMP_MODEL_KEY_NOTIF = 3, /* Passkey Entry model, display the key */ + /* Secure connections mode */ + SMP_MODEL_SEC_CONN_JUSTWORKS = 4, /* Just Works model */ + SMP_MODEL_SEC_CONN_NUM_COMP = 5, /* Numeric Comparison model */ + SMP_MODEL_SEC_CONN_PASSKEY_ENT = 6, /* Passkey Entry model, */ + /* this side inputs the key */ + SMP_MODEL_SEC_CONN_PASSKEY_DISP = 7, /* Passkey Entry model, */ + /* this side displays the key */ + SMP_MODEL_SEC_CONN_OOB = 8, /* Secure Connections mode, OOB model */ + SMP_MODEL_OUT_OF_RANGE = 9, +} tSMP_ASSO_MODEL; #ifndef SMP_MAX_CONN #define SMP_MAX_CONN 2 diff --git a/stack/smp/smp_utils.cc b/stack/smp/smp_utils.cc index 95b83c8d2..093d020aa 100644 --- a/stack/smp/smp_utils.cc +++ b/stack/smp/smp_utils.cc @@ -181,8 +181,8 @@ static const tSMP_CMD_ACT smp_cmd_build_act[] = { smp_build_pairing_commitment_cmd /* 0x0F: pairing commitment */ }; -static const uint8_t smp_association_table[2][SMP_IO_CAP_MAX][SMP_IO_CAP_MAX] = - { +static const tSMP_ASSO_MODEL + smp_association_table[2][SMP_IO_CAP_MAX][SMP_IO_CAP_MAX] = { /* display only */ /* Display Yes/No */ /* keyboard only */ /* No Input/Output */ /* keyboard display */ @@ -232,7 +232,7 @@ static const uint8_t smp_association_table[2][SMP_IO_CAP_MAX][SMP_IO_CAP_MAX] = {SMP_MODEL_PASSKEY, SMP_MODEL_PASSKEY, SMP_MODEL_KEY_NOTIF, SMP_MODEL_ENCRYPTION_ONLY, SMP_MODEL_PASSKEY}}}; -static const uint8_t +static const tSMP_ASSO_MODEL smp_association_table_sc[2][SMP_IO_CAP_MAX][SMP_IO_CAP_MAX] = { /* display only */ /* Display Yes/No */ /* keyboard only */ /* No InputOutput */ /* keyboard display */ -- 2.11.0