aboutsummaryrefslogtreecommitdiff
path: root/embassy-stm32-wpan/src/wb55/mac/opcodes.rs
blob: fd70118731bc1a7dcc1f87fe1d4c9d92171527af (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
const ST_VENDOR_OGF: u16 = 0x3F;
const MAC_802_15_4_CMD_OPCODE_OFFSET: u16 = 0x280;

const fn opcode(ocf: u16) -> isize {
    ((ST_VENDOR_OGF << 9) | (MAC_802_15_4_CMD_OPCODE_OFFSET + ocf)) as isize
}

#[cfg_attr(feature = "defmt", derive(defmt::Format))]
pub enum OpcodeM4ToM0 {
    MlmeAssociateReq = opcode(0x00),
    MlmeAssociateRes = opcode(0x01),
    MlmeDisassociateReq = opcode(0x02),
    MlmeGetReq = opcode(0x03),
    MlmeGtsReq = opcode(0x04),
    MlmeOrphanRes = opcode(0x05),
    MlmeResetReq = opcode(0x06),
    MlmeRxEnableReq = opcode(0x07),
    MlmeScanReq = opcode(0x08),
    MlmeSetReq = opcode(0x09),
    MlmeStartReq = opcode(0x0A),
    MlmeSyncReq = opcode(0x0B),
    MlmePollReq = opcode(0x0C),
    MlmeDpsReq = opcode(0x0D),
    MlmeSoundingReq = opcode(0x0E),
    MlmeCalibrateReq = opcode(0x0F),
    McpsDataReq = opcode(0x10),
    McpsPurgeReq = opcode(0x11),
}

#[cfg_attr(feature = "defmt", derive(defmt::Format))]
pub enum OpcodeM0ToM4 {
    MlmeAssociateCnf = 0x00,
    MlmeDisassociateCnf,
    MlmeGetCnf,
    MlmeGtsCnf,
    MlmeResetCnf,
    MlmeRxEnableCnf,
    MlmeScanCnf,
    MlmeSetCnf,
    MlmeStartCnf,
    MlmePollCnf,
    MlmeDpsCnf,
    MlmeSoundingCnf,
    MlmeCalibrateCnf,
    McpsDataCnf,
    McpsPurgeCnf,
    MlmeAssociateInd,
    MlmeDisassociateInd,
    MlmeBeaconNotifyInd,
    MlmeCommStatusInd,
    MlmeGtsInd,
    MlmeOrphanInd,
    MlmeSyncLossInd,
    MlmeDpsInd,
    McpsDataInd,
    MlmePollInd,
}

impl TryFrom<u16> for OpcodeM0ToM4 {
    type Error = ();

    fn try_from(value: u16) -> Result<Self, Self::Error> {
        match value {
            0 => Ok(Self::MlmeAssociateCnf),
            1 => Ok(Self::MlmeDisassociateCnf),
            2 => Ok(Self::MlmeGetCnf),
            3 => Ok(Self::MlmeGtsCnf),
            4 => Ok(Self::MlmeResetCnf),
            5 => Ok(Self::MlmeRxEnableCnf),
            6 => Ok(Self::MlmeScanCnf),
            7 => Ok(Self::MlmeSetCnf),
            8 => Ok(Self::MlmeStartCnf),
            9 => Ok(Self::MlmePollCnf),
            10 => Ok(Self::MlmeDpsCnf),
            11 => Ok(Self::MlmeSoundingCnf),
            12 => Ok(Self::MlmeCalibrateCnf),
            13 => Ok(Self::McpsDataCnf),
            14 => Ok(Self::McpsPurgeCnf),
            15 => Ok(Self::MlmeAssociateInd),
            16 => Ok(Self::MlmeDisassociateInd),
            17 => Ok(Self::MlmeBeaconNotifyInd),
            18 => Ok(Self::MlmeCommStatusInd),
            19 => Ok(Self::MlmeGtsInd),
            20 => Ok(Self::MlmeOrphanInd),
            21 => Ok(Self::MlmeSyncLossInd),
            22 => Ok(Self::MlmeDpsInd),
            23 => Ok(Self::McpsDataInd),
            24 => Ok(Self::MlmePollInd),
            _ => Err(()),
        }
    }
}