Sdrctl intf.c
Function openwifi_testmode_cmd(struct ieee80211_hw hw, struct ieee80211_vif vif, void *data, int len)
openwifi_testmode_cmd: The function of openwifi_testmode_cmd is to handle various commands related to the OpenWiFi test mode, processing input data and interacting with hardware registers.
parameters: The parameters of this Function. · hw: A pointer to the ieee80211_hw structure representing the hardware interface. · vif: A pointer to the ieee80211_vif structure representing the virtual interface. · data: A pointer to the data buffer containing command attributes. · len: An integer representing the length of the data buffer.
Code Description: The openwifi_testmode_cmd function processes commands sent to the OpenWiFi device in test mode. It begins by parsing the input data using the nla_parse function, which populates an array of netlink attributes (tb). If parsing fails or if the required command attribute is missing, it returns an error.
The function then switches on the command type extracted from the input data. Each case in the switch statement corresponds to a specific command, such as setting or getting configuration parameters like gap, slice index, MAC address, and slice timings. For each command, the function performs the necessary operations, which may include reading from or writing to hardware registers via the xpu_api interface, allocating response buffers, and sending replies back to the caller using cfg80211_testmode_reply.
For example, when handling the OPENWIFI_CMD_SET_GAP command, the function retrieves the gap value from the input data and writes it to the appropriate hardware register. Similarly, for commands like OPENWIFI_CMD_GET_GAP, it reads the current gap value from the hardware and prepares it for response.
The function also includes error handling for invalid parameters and unsupported commands, ensuring robust operation. It utilizes printk for logging important actions and warnings, which aids in debugging and monitoring the command execution flow.
Note: It is important to ensure that the input data conforms to the expected structure and that the commands are supported by the hardware. The function is designed to handle specific commands, and any unsupported command will result in an error response.
Output Example: For a successful execution of the OPENWIFI_CMD_GET_GAP command, the function may return a response containing the current gap value, such as:
Response: { OPENWIFI_ATTR_GAP: 100 }
```mermaid graph TD A[Start] --> B[Parse attributes from data] B --> C{Parsing error?} C -- Yes --> D[Return error] C -- No --> E{Command attribute present?} E -- No --> D E -- Yes --> F[Get command value]
F --> G{Command type}
G -->|OPENWIFI_CMD_SET_GAP| H[Check gap attribute]
H --> I{Gap attribute present?}
I -- No --> D
I -- Yes --> J[Get gap value]
J --> K[Write gap value to CSMA_CFG]
K --> L[Return success]
G -->|OPENWIFI_CMD_GET_GAP| M[Allocate reply skb]
M --> N{Allocation success?}
N -- No --> D
N -- Yes --> O[Read gap value from CSMA_CFG]
O --> P[Put gap value in skb]
P --> L
G -->|OPENWIFI_CMD_SET_SLICE_IDX| Q[Check slice index attribute]
Q --> R{Slice index attribute present?}
R -- No --> D
R -- Yes --> S[Get slice index value]
S --> T{Slice index valid?}
T -- No --> D
T -- Yes --> U[Set slice index]
U --> L
G -->|OPENWIFI_CMD_GET_SLICE_IDX| V[Allocate reply skb]
V --> W{Allocation success?}
W -- No --> D
W -- Yes --> X[Get slice index value]
X --> Y[Put slice index value in skb]
Y --> L
G -->|OPENWIFI_CMD_SET_ADDR| Z[Check address attribute]
Z --> AA{Address attribute present?}
AA -- No --> D
AA -- Yes --> AB[Get address value]
AB --> AC{Slice index valid?}
AC -- No --> D
AC -- Yes --> AD[Set address value in map]
AD --> L
G -->|OPENWIFI_CMD_GET_ADDR| AE[Allocate reply skb]
AE --> AF{Allocation success?}
AF -- No --> D
AF -- Yes --> AG[Get address value from map]
AG --> AH[Put address value in skb]
AH --> L
G -->|OPENWIFI_CMD_SET_SLICE_TOTAL| AI[Check slice total attribute]
AI --> AJ{Slice total attribute present?}
AJ -- No --> D
AJ -- Yes --> AK[Get slice total value]
AK --> AL{Slice index valid?}
AL -- No --> D
AL -- Yes --> AM[Write slice total value]
AM --> L
G -->|OPENWIFI_CMD_GET_SLICE_TOTAL| AN[Allocate reply skb]
AN --> AO{Allocation success?}
AO -- No --> D
AO -- Yes --> AP[Read slice total value]
AP --> AQ[Put slice total value in skb]
AQ --> L
G -->|OPENWIFI_CMD_SET_SLICE_START| AR[Check slice start attribute]
AR --> AS{Slice start attribute present?}
AS -- No --> D
AS -- Yes --> AT[Get slice start value]
AT --> AU{Slice index valid?}
AU -- No --> D
AU -- Yes --> AV[Write slice start value]
AV --> L
G -->|OPENWIFI_CMD_GET_SLICE_START| AW[Allocate reply skb]
AW --> AX{Allocation success?}
AX -- No --> D
AX -- Yes --> AY[Read slice start value]
AY --> AZ[Put slice start value in skb]
AZ --> L
G -->|OPENWIFI_CMD_SET_SLICE_END| BA[Check slice end attribute]
BA --> BB{Slice end attribute present?}
BB -- No --> D
BB -- Yes --> BC[Get slice end value]
BC --> BD{Slice index valid?}
BD -- No --> D
BD -- Yes --> BE[Write slice end value]
BE --> L
G -->|OPENWIFI_CMD_GET_SLICE_END| BF[Allocate reply skb]
BF --> BG{Allocation success?}
BG -- No --> D
BG -- Yes --> BH[Read slice end value]
BH --> BI[Put slice end value in skb]
BI --> L
G -->|OPENWIFI_CMD_SET_RSSI_TH| BJ[Check RSSI threshold attribute]
BJ --> BK{RSSI threshold attribute present?}
BK -- No --> D
BK -- Yes --> BL[Get RSSI threshold value]
BL --> BM[Return warning]
G -->|OPENWIFI_CMD_GET_RSSI_TH| BN[Allocate reply skb]