Cmd.c
Function cb_reg_handler(struct nl_msg msg, void arg)
cb_reg_handler: The function of cb_reg_handler is to handle registration messages by parsing attributes from a netlink message.
parameters: The parameters of this Function. · parameter1: struct nl_msg msg - A pointer to the netlink message that contains the data to be processed. · parameter2: void arg - A pointer to additional user-defined data that may be needed for processing (not used in this function).
Code Description: The cb_reg_handler function is designed to process incoming netlink messages related to registration. It begins by declaring two arrays of netlink attributes: attrs
for standard attributes defined by the NL80211 protocol, and tb
for attributes specific to the OpenWiFi implementation. The function retrieves the generic netlink message header from the provided netlink message pointer msg
.
The function then uses nla_parse
to parse the attributes from the netlink message. It checks if the NL80211_ATTR_TESTDATA
attribute is present in the parsed attributes. If this attribute is not found, the function returns NL_SKIP
, indicating that it will not process this message further.
If the NL80211_ATTR_TESTDATA
attribute is present, the function proceeds to parse its data into the tb
array using another call to nla_parse
. This allows the function to extract specific information from the TESTDATA
attribute.
The function retrieves the value of the REG_ATTR_VAL
attribute from the tb
array and prints it to the console in hexadecimal format. This value represents a registration value that is likely of interest for debugging or logging purposes. Finally, the function returns NL_SKIP
, signaling that no further processing of this message is required.
Note: It is important to ensure that the netlink message being processed contains the expected attributes to avoid unexpected behavior. The function currently does not handle cases where the expected attributes are missing beyond simply skipping the message.
Output Example: A possible appearance of the code's return value when the registration value is processed could be:
reg val: 0x1a2b3c4d
graph TD
A[Start cb_reg_handler] --> B[Extract header from message]
B --> C[Parse attributes from message]
C --> D{Check if TESTDATA attribute exists}
D -- Yes --> E[Parse OPENWIFI attributes from TESTDATA]
D -- No --> F[Return NL_SKIP]
E --> G[Log register value]
G --> H[Return NL_SKIP]
F --> H
Function handle_set_reg(struct nl80211_state *state,
struct nl_cb *cb,
struct nl_msg *msg,
int argc, char **argv,
enum id_input id)
handle_set_reg: The function of handle_set_reg is to handle the setting of a register based on input parameters and to prepare a message for communication.
parameters: The parameters of this Function. · state: A pointer to the nl80211_state structure that holds the state information for the nl80211 interface. · cb: A pointer to the nl_cb structure that contains callback information for netlink messages. · msg: A pointer to the nl_msg structure that represents the netlink message to be sent. · argc: An integer representing the number of command-line arguments provided. · argv: An array of strings containing the command-line arguments. · id: An enumeration value representing the input ID type.
Code Description: The handle_set_reg function begins by initializing a nested attribute in the netlink message using nla_nest_start. If this initialization fails, the function returns 1, indicating an error. The function then processes the first command-line argument (argv[0]) to determine the category of the register to be set. It uses strcasecmp to compare the input string against predefined categories (e.g., "rf", "rx_intf", "tx_intf", etc.) and assigns a corresponding numerical value to reg_cat. If the input does not match any valid category, an error message is printed, and the function returns 1.
Next, the function converts the second command-line argument (argv[1]) to an unsigned integer using strtoul, shifting the value left by 2 bits to convert from an index to an address format. The register address is then constructed by combining the category and the address into a single value. The third argument (argv[2]) is similarly converted to an unsigned integer to represent the register value.
The function then adds attributes to the netlink message using NLA_PUT_U32 for the command type, register address, and register value. After successfully adding these attributes, the nested attribute is closed with nla_nest_end. The function prints the category, address, and value of the register for debugging purposes.
If any part of the attribute addition fails, the function will jump to the nla_put_failure label, returning -ENOBUFS to indicate a buffer issue.
Note: It is important to ensure that the command-line arguments are valid and correctly formatted before calling this function. The first argument must match one of the predefined categories, and the second and third arguments must be valid integers.
Output Example: If the function is called with valid arguments such as "rf", "4", and "255", the output might include:
reg cat: 1
reg addr: 00000004
reg val: 000000ff
graph TD
A[Start handle_set_reg] --> B[Start nesting test data]
B --> C{Check if tmdata is null}
C -- Yes --> D[Return 1]
C -- No --> E[Determine reg_cat based on argv[0]]
E --> F{Is argv[0] rf?}
F -- Yes --> G[Set reg_cat to 1]
F -- No --> H{Is argv[0] rx_intf?}
H -- Yes --> I[Set reg_cat to 2]
H -- No --> J{Is argv[0] tx_intf?}
J -- Yes --> K[Set reg_cat to 3]
J -- No --> L{Is argv[0] rx?}
L -- Yes --> M[Set reg_cat to 4]
L -- No --> N{Is argv[0] tx?}
N -- Yes --> O[Set reg_cat to 5]
N -- No --> P{Is argv[0] xpu?}
P -- Yes --> Q[Set reg_cat to 6]
P -- No --> R{Is argv[0] drv_rx?}
R -- Yes --> S[Set reg_cat to 7]
R -- No --> T{Is argv[0] drv_tx?}
T -- Yes --> U[Set reg_cat to 8]
T -- No --> V{Is argv[0] drv_xpu?}
V -- Yes --> W[Set reg_cat to 9]
V -- No --> X[Print error message and return 1]
G --> Y[Convert argv[1] to reg_addr]
I --> Y
K --> Y
M --> Y
O --> Y
Q --> Y
S --> Y
U --> Y
W --> Y
X --> D
Y --> Z{Check if conversion is valid}
Z -- No --> D[Return 1]
Z -- Yes --> AA[Shift reg_addr left by 2]
AA --> AB[Combine reg_cat and reg_addr]
AB --> AC[Convert argv[2] to reg_val]
AC --> AD{Check if conversion is valid}
AD -- No --> D[Return 1]
AD -- Yes --> AE[Put values into msg]
AE --> AF[End nesting test data]
AF --> AG[Print reg_cat, reg_addr, and reg_val]
AG --> AH[Return 0]
AH --> AI[nla_put_failure]
AI --> AJ[Return -ENOBUFS]
Function handle_get_reg(struct nl80211_state *state,
struct nl_cb *cb,
struct nl_msg *msg,
int argc, char **argv,
enum id_input id)
handle_get_reg: The function of handle_get_reg is to handle the retrieval of register values based on specified categories and addresses.
parameters: The parameters of this Function. · parameter1: struct nl80211_state state - A pointer to the nl80211 state structure that holds the state of the nl80211 subsystem. · parameter2: struct nl_cb cb - A pointer to the netlink callback structure used for handling responses. · parameter3: struct nl_msg msg - A pointer to the netlink message structure that will be populated with the request data. · parameter4: int argc - The count of arguments passed to the function. · parameter5: char *argv - An array of argument strings provided to the function. · parameter6: enum id_input id - An enumeration value representing the input identifier.
Code Description: The handle_get_reg function begins by initializing a nested attribute in the netlink message using nla_nest_start. If this initialization fails, the function returns 1, indicating an error. The function then checks the first argument (argv[0]) to determine the category of the register being accessed. It uses strcasecmp to compare the argument against predefined strings representing different register categories (e.g., "rf", "rx_intf", "tx_intf", etc.). Based on the match, it assigns a corresponding value to the reg_cat variable. If the argument does not match any of the expected categories, an error message is printed, and the function returns 1.
Next, the function processes the second argument (argv[1]) to obtain the register address. It converts this argument from a string to an unsigned long integer using strtoul. If the conversion fails (indicated by the presence of non-numeric characters in the string), the function returns 1. The register address is then adjusted by shifting it left by two bits (to convert from index to address) and combined with the category value to form a complete address.
The function then prints the computed address in hexadecimal format. Following this, it populates the netlink message with two attributes: the command to get the register (REG_CMD_GET) and the computed register address. After completing the nested attribute, it ends the nesting with nla_nest_end.
Finally, the function sets a callback for handling the response using nl_cb_set, specifying that the cb_reg_handler function should be called when a valid response is received. The function returns 0 to indicate successful execution. If there is a failure in adding attributes to the message, it jumps to the nla_put_failure label and returns -ENOBUFS, indicating a buffer issue.
Note: It is important to ensure that the first argument corresponds to one of the predefined categories; otherwise, the function will not proceed with the register retrieval. Additionally, the second argument must be a valid numeric string to avoid conversion errors.
Output Example: If the function is called with valid arguments, such as "rf" and "10", the output might include a printed line: "SENDaddr: 0000000A", indicating that the computed register address is 0x0000000A.
graph TD
A[Start handle_get_reg] --> B[Start nesting testdata]
B --> C{Check first argument}
C -->|rf| D[Set reg_cat to 1]
C -->|rx_intf| E[Set reg_cat to 2]
C -->|tx_intf| F[Set reg_cat to 3]
C -->|rx| G[Set reg_cat to 4]
C -->|tx| H[Set reg_cat to 5]
C -->|xpu| I[Set reg_cat to 6]
C -->|drv_rx| J[Set reg_cat to 7]
C -->|drv_tx| K[Set reg_cat to 8]
C -->|drv_xpu| L[Set reg_cat to 9]
C -->|else| M[Print error message and return 1]
D --> N[Convert second argument to reg_addr]
E --> N
F --> N
G --> N
H --> N
I --> N
J --> N
K --> N
L --> N
N --> O[Shift reg_addr left by 2]
O --> P[Combine reg_cat and reg_addr]
P --> Q[Print SENDaddr]
Q --> R[Put REG_CMD_GET into msg]
R --> S[Put reg_addr into msg]
S --> T[End nesting testdata]
T --> U[Set callback for cb_reg_handler]
U --> V[Return 0]
M --> V
Function cb_openwifi_rssi_th_handler(struct nl_msg msg, void arg)
cb_openwifi_rssi_th_handler: The function of cb_openwifi_rssi_th_handler is to handle the reception of messages related to the OpenWiFi RSSI threshold.
parameters: The parameters of this Function. · msg: A pointer to a struct nl_msg that contains the message data received. · arg: A pointer to additional arguments that may be passed to the handler (not used in this function).
Code Description: The cb_openwifi_rssi_th_handler function processes a Netlink message to extract and print the OpenWiFi RSSI threshold value. It begins by declaring two arrays of struct nlattr pointers: attrs
for standard Netlink attributes and tb
for OpenWiFi-specific attributes. The function retrieves the generic Netlink message header using nlmsg_data
and nlmsg_hdr
.
The function then parses the attributes from the message using nla_parse
, checking for the presence of the NL80211_ATTR_TESTDATA
attribute. If this attribute is not present, the function returns NL_SKIP
, indicating that it should skip further processing.
If the NL80211_ATTR_TESTDATA
attribute is found, the function proceeds to parse the OpenWiFi-specific attributes from the data contained within this attribute. It uses nla_parse
again to fill the tb
array with the relevant attributes.
Finally, the function retrieves the RSSI threshold value using nla_get_u32
on the OPENWIFI_ATTR_RSSI_TH
attribute and prints it to the standard output. The function concludes by returning NL_SKIP
, signaling that no further action is required.
Note: It is important to ensure that the message being processed contains the necessary attributes; otherwise, the function will terminate early without performing any actions. This function is typically used in the context of handling Netlink messages related to wireless networking.
Output Example: An example output when the RSSI threshold is set to -70 would be: openwifi rssi_th: -70
graph TD
A[Start cb_openwifi_rssi_th_handler] --> B[Receive nl_msg msg and void arg]
B --> C[Initialize attrs and tb arrays]
C --> D[Get genlmsghdr from msg]
D --> E[Parse attrs using nla_parse]
E --> F{Check if attrs[NL80211_ATTR_TESTDATA] exists}
F -- Yes --> G[Parse tb using nla_parse]
F -- No --> H[Return NL_SKIP]
G --> I[Print openwifi rssi_th value]
I --> J[Return NL_SKIP]
H --> J
J --> K[End cb_openwifi_rssi_th_handler]
Function handle_set_rssi_th(struct nl80211_state *state,
struct nl_cb *cb,
struct nl_msg *msg,
int argc, char **argv,
enum id_input id)
handle_set_rssi_th: The function of handle_set_rssi_th is to handle the setting of the RSSI threshold in the OpenWiFi system.
parameters: The parameters of this Function. · parameter1: struct nl80211_state state - Represents the state of the nl80211 protocol, which is used for communication with the wireless subsystem. · parameter2: struct nl_cb cb - A callback structure used for handling asynchronous events. · parameter3: struct nl_msg msg - A message structure that holds the data to be sent over the netlink socket. · parameter4: int argc - The count of command-line arguments provided to the function. · parameter5: char *argv - An array of command-line arguments. · parameter6: enum id_input id - An enumeration value that identifies the type of input being processed.
Code Description: The handle_set_rssi_th function begins by initializing a nested attribute in the netlink message using nla_nest_start. If this initialization fails, the function returns 1 to indicate an error. The function then attempts to convert the first command-line argument (argv[0]) into an unsigned integer using strtoul. If the conversion fails (indicated by the presence of non-numeric characters in the input), the function again returns 1.
Next, the function populates the netlink message with two attributes: OPENWIFI_ATTR_CMD, which is set to OPENWIFI_CMD_SET_RSSI_TH, and OPENWIFI_ATTR_RSSI_TH, which is set to the converted RSSI threshold value (tmp). After adding these attributes, the function closes the nested attribute structure with nla_nest_end.
A message is printed to the console displaying the RSSI threshold that has been set. Finally, the function returns 0 to indicate success. If there is a failure during the attribute addition (nla_put_failure), the function returns -ENOBUFS to indicate that there is insufficient buffer space.
Note: It is important to ensure that the command-line argument provided for the RSSI threshold is a valid numeric value. Failure to do so will result in an error return from the function. Additionally, the function assumes that the netlink message has been properly initialized before being passed to it.
Output Example: If the function is called with valid arguments and the RSSI threshold is set to 30, the console output would be: "openwifi rssi_th: 30". If an invalid argument is provided, the function would return 1, indicating an error.
graph TD
A[Start handle_set_rssi_th] --> B[Start nesting attribute in msg]
B --> C{Check if tmdata is NULL}
C -- Yes --> D[Return 1]
C -- No --> E[Convert argv[0] to unsigned int]
E --> F{Check if conversion was successful}
F -- No --> D
F -- Yes --> G[Put OPENWIFI_CMD_SET_RSSI_TH in msg]
G --> H[Put OPENWIFI_ATTR_RSSI_TH in msg]
H --> I[End nesting attribute in msg]
I --> J[Print openwifi rssi_th value]
J --> K[Return 0]
K --> L[End handle_set_rssi_th]
L --> M{Check for nla_put_failure}
M -- Yes --> N[Return -ENOBUFS]
M -- No --> O[End]
Function handle_set_tsf(struct nl80211_state *state,
struct nl_cb *cb,
struct nl_msg *msg,
int argc, char **argv,
enum id_input id)
handle_set_tsf: The function of handle_set_tsf is to handle the setting of the TSF (Timestamp Field) values in a network message.
parameters: The parameters of this Function. · parameter1: struct nl80211_state state - A pointer to the nl80211 state structure, which holds the state of the nl80211 protocol. · parameter2: struct nl_cb cb - A pointer to the netlink callback structure used for handling responses. · parameter3: struct nl_msg msg - A pointer to the netlink message structure that will be populated with the TSF values. · parameter4: int argc - The count of command-line arguments provided. · parameter5: char *argv - An array of command-line arguments. · parameter6: enum id_input id - An enumeration value representing the input ID.
Code Description: The handle_set_tsf function begins by initializing a nested attribute in the netlink message using nla_nest_start. If this initialization fails, the function returns 1, indicating an error. The function then attempts to convert the first two command-line arguments (argv[0] and argv[1]) from strings to unsigned integers using strtoul. If the conversion fails (i.e., if there are non-numeric characters in the input), the function returns 1.
Upon successful conversion, the function populates the netlink message with the command and the high and low TSF values using the NLA_PUT_U32 macro. After adding the necessary attributes, it closes the nested attribute with nla_nest_end. The function then prints the high and low TSF values in hexadecimal format to the standard output. Finally, it returns 0 to indicate successful execution.
In case of failure during the attribute addition (indicated by the nla_put_failure label), the function returns -ENOBUFS, which signifies that there is not enough buffer space to add the requested attributes.
Note: It is important to ensure that the command-line arguments provided to this function are valid integers, as invalid inputs will lead to early termination of the function with an error return value. Additionally, the function assumes that at least two arguments are provided; otherwise, it may lead to undefined behavior.
Output Example: If the function is called with argv containing "12345678" and "87654321", the output would be: high_tsf val: 00bc614e low_tsf val: 00d2c6f1
graph TD
A[Start handle_set_tsf function] --> B[Start nesting attribute in message]
B --> C{Check if nesting successful}
C -- Yes --> D[Convert first argument to high_tsf]
C -- No --> E[Return error code 1]
D --> F{Check if conversion successful}
F -- Yes --> G[Convert second argument to low_tsf]
F -- No --> E
G --> H{Check if conversion successful}
H -- Yes --> I[Add command attribute to message]
H -- No --> E
I --> J[Add high_tsf attribute to message]
J --> K[Add low_tsf attribute to message]
K --> L[End nesting attribute in message]
L --> M[Print high_tsf value]
M --> N[Print low_tsf value]
N --> O[Return success code 0]
E --> P[Return error code 1]
Function handle_get_rssi_th(struct nl80211_state *state,
struct nl_cb *cb,
struct nl_msg *msg,
int argc, char **argv,
enum id_input id)
handle_get_rssi_th: The function of handle_get_rssi_th is to prepare and send a request to retrieve the RSSI threshold in a wireless networking context.
parameters: The parameters of this Function. · state: A pointer to the nl80211_state structure that holds the state of the nl80211 interface. · cb: A pointer to the nl_cb structure that contains callback functions for netlink messages. · msg: A pointer to the nl_msg structure that represents the netlink message to be sent. · argc: An integer representing the count of command-line arguments. · argv: An array of strings representing the command-line arguments. · id: An enumeration value indicating the type of input.
Code Description: The handle_get_rssi_th function is designed to handle the process of preparing a netlink message to request the RSSI (Received Signal Strength Indicator) threshold from a wireless device. The function begins by creating a nested attribute in the netlink message using nla_nest_start, which is associated with the NL80211_ATTR_TESTDATA attribute. If the nesting fails, the function returns 1, indicating an error.
Next, the function uses the NLA_PUT_U32 macro to add a 32-bit unsigned integer attribute to the message, specifically setting the OPENWIFI_ATTR_CMD attribute to the value OPENWIFI_CMD_GET_RSSI_TH. This indicates that the command being sent is to get the RSSI threshold.
After adding the necessary attributes, the function concludes the nested attribute structure with nla_nest_end. It then sets a callback function (cb_openwifi_rssi_th_handler) to be invoked when a valid response is received for this message, using the nl_cb_set function. The function finally returns 0 to indicate successful execution.
In the event of a failure during the attribute addition (nla_put_failure), the function returns -ENOBUFS, which signifies that there is not enough buffer space to complete the operation.
Note: It is important to ensure that the netlink message and callback structures are properly initialized before calling this function. Additionally, the function assumes that the necessary constants and macros (such as OPENWIFI_ATTR_CMD and OPENWIFI_CMD_GET_RSSI_TH) are defined elsewhere in the codebase.
Output Example: A successful execution of this function would result in a netlink message being prepared and sent, which may look like the following in a serialized format:
{
"cmd": "GET_RSSI_TH",
"data": {
"attribute": "NL80211_ATTR_TESTDATA"
}
}
graph TD
A[Start handle_get_rssi_th] --> B[Start nesting test data in message]
B --> C[Check if nesting is successful]
C -->|Yes| D[Add command to message]
C -->|No| E[Return error code 1]
D --> F[End nesting test data in message]
F --> G[Set callback for valid response]
G --> H[Return success code 0]
E --> I[Return error code -ENOBUFS]
H --> J[End handle_get_rssi_th]
I --> J
Function cb_openwifi_slice_total_handler(struct nl_msg msg, void arg)
cb_openwifi_slice_total_handler: The function of cb_openwifi_slice_total_handler is to handle the total slice duration data received from an OpenWiFi message.
parameters: The parameters of this Function. · msg: A pointer to a struct nl_msg that contains the netlink message data. · arg: A pointer to additional user-defined data that can be passed to the handler.
Code Description: The cb_openwifi_slice_total_handler function processes a netlink message to extract and print the total duration of a slice from the OpenWiFi attributes. It begins by declaring arrays for netlink attributes and OpenWiFi attributes, as well as a pointer to the generic netlink message header. The function then parses the netlink message to retrieve the attributes using nla_parse. If the required NL80211_ATTR_TESTDATA attribute is not present, the function returns NL_SKIP, indicating that it should skip further processing.
Next, it parses the OpenWiFi attributes from the NL80211_ATTR_TESTDATA attribute. The total slice duration is extracted from the parsed attributes using nla_get_u32, which retrieves a 32-bit unsigned integer. The function then prints the total duration of the slice in microseconds and the slice index by applying bitwise operations to the retrieved value. Finally, the function returns NL_SKIP to indicate that no further processing is needed.
Note: It is important to ensure that the netlink message contains the NL80211_ATTR_TESTDATA attribute; otherwise, the function will exit early without performing any operations. Additionally, the function assumes that the slice total attribute is present and correctly formatted within the message.
Output Example: A possible appearance of the code's return value when executed could be: "openwifi slice_total (duration) 123456us of slice 5" This indicates that the total duration of the slice is 123456 microseconds and corresponds to slice index 5.
graph TD
A[Start cb_openwifi_slice_total_handler] --> B[Parse message attributes]
B --> C{Check if NL80211_ATTR_TESTDATA exists}
C -- Yes --> D[Parse OPENWIFI attributes]
C -- No --> E[Return NL_SKIP]
D --> F[Get slice_total value]
F --> G[Print openwifi slice_total duration and slice]
G --> H[Return NL_SKIP]
E --> H
Function handle_set_slice_total(struct nl80211_state *state,
struct nl_cb *cb,
struct nl_msg *msg,
int argc, char **argv,
enum id_input id)
handle_set_slice_total: The function of handle_set_slice_total is to handle the setting of the total duration for a slice in the OpenWiFi system.
parameters: The parameters of this Function. · parameter1: struct nl80211_state state - A pointer to the nl80211 state structure that holds the state of the nl80211 protocol. · parameter2: struct nl_cb cb - A pointer to the callback structure used for handling netlink messages. · parameter3: struct nl_msg msg - A pointer to the netlink message structure that will be populated with the slice total data. · parameter4: int argc - The argument count, representing the number of command-line arguments provided. · parameter5: char *argv - An array of strings containing the command-line arguments. · parameter6: enum id_input id - An enumeration value representing the input identifier.
Code Description: The handle_set_slice_total function begins by creating a nested attribute in the netlink message using nla_nest_start. If this operation fails, the function returns 1, indicating an error. The function then attempts to convert the first command-line argument (argv[0]) from a string to an unsigned integer using strtoul. If the conversion fails (i.e., if there are any non-numeric characters in the input), the function again returns 1.
Assuming the conversion is successful, the function proceeds to add two attributes to the netlink message: OPENWIFI_ATTR_CMD, which is set to OPENWIFI_CMD_SET_SLICE_TOTAL, and OPENWIFI_ATTR_SLICE_TOTAL, which is set to the converted total duration (tmp). After adding these attributes, the nested attribute is closed with nla_nest_end.
The function then prints a message to the standard output indicating the total duration that has been set. If any part of the attribute addition fails, the function will jump to the nla_put_failure label and return -ENOBUFS, indicating that there was insufficient buffer space to complete the operation.
Note: It is important to ensure that the input provided in argv[0] is a valid numeric string, as any invalid input will result in an error return value. Additionally, the function assumes that the netlink message and its attributes are properly initialized before calling this function.
Output Example: If the function is called with argv containing "3000", the output would be: openwifi slice_total (duration): 3000us
graph TD
A[Start handle_set_slice_total] --> B[Start nesting attributes in message]
B --> C{Check if nesting started}
C -- Yes --> D[Convert argv[0] to unsigned int]
C -- No --> E[Return 1]
D --> F{Check if conversion was successful}
F -- Yes --> G[Add OPENWIFI_CMD to message]
F -- No --> E
G --> H[Add OPENWIFI_ATTR_SLICE_TOTAL to message]
H --> I[End nesting attributes in message]
I --> J[Print slice_total duration]
J --> K[Return 0]
E --> L[Return 1]
K --> M[End handle_set_slice_total]
L --> M
Function handle_get_slice_total(struct nl80211_state *state,
struct nl_cb *cb,
struct nl_msg *msg,
int argc, char **argv,
enum id_input id)
handle_get_slice_total: The function of handle_get_slice_total is to prepare and send a request to retrieve the total number of slices in the OpenWiFi system.
parameters: The parameters of this Function. · state: A pointer to the nl80211_state structure that holds the state information for the netlink communication. · cb: A pointer to the nl_cb structure that contains callback functions for netlink messages. · msg: A pointer to the nl_msg structure that represents the netlink message being constructed. · argc: An integer representing the number of command-line arguments. · argv: An array of strings containing the command-line arguments. · id: An enumeration value indicating the type of input being processed.
Code Description: The handle_get_slice_total function initiates the process of obtaining the total number of slices from the OpenWiFi system. It begins by creating a nested attribute in the netlink message using nla_nest_start, which is associated with the NL80211_ATTR_TESTDATA attribute. If the nesting fails, the function returns 1, indicating an error.
Next, the function adds a specific command to the message using NLA_PUT_U32, setting the OPENWIFI_ATTR_CMD attribute to OPENWIFI_CMD_GET_SLICE_TOTAL. This command indicates that the request is to retrieve the total number of slices.
After adding the command, the function concludes the nested attribute with nla_nest_end. It then sets a callback function, cb_openwifi_slice_total_handler, to handle the response for this request when it is received. This is done using nl_cb_set, specifying that the callback should be invoked when a valid response is received.
If the function encounters a failure while adding attributes (indicated by the nla_put_failure label), it returns -ENOBUFS, which signifies that there is insufficient buffer space to complete the operation.
Note: It is important to ensure that the nl_msg structure is properly initialized before calling this function, and that the callback function is capable of handling the response appropriately.
Output Example: A successful execution of this function would not return a value directly, but it would prepare a netlink message that, when sent, would lead to a response containing the total number of slices, which could be processed by the specified callback function.
graph TD
A[Start handle_get_slice_total] --> B[Start nesting attribute in message]
B --> C{Check if nesting is successful}
C -->|Yes| D[Put command in message]
C -->|No| E[Return error code 1]
D --> F[End nesting attribute in message]
F --> G[Set callback for valid response]
G --> H[Return success code 0]
E --> I[Return error code -ENOBUFS]
Function cb_openwifi_slice_start_handler(struct nl_msg msg, void arg)
cb_openwifi_slice_start_handler: The function of cb_openwifi_slice_start_handler is to handle the start of an OpenWiFi slice by processing a Netlink message.
parameters: The parameters of this Function. · msg: A pointer to the Netlink message structure that contains the data to be processed. · arg: A pointer to additional arguments that may be passed to the handler (not used in this function).
Code Description: The cb_openwifi_slice_start_handler function begins by defining two arrays of Netlink attributes: attrs
and tb
. The attrs
array is used to store attributes related to the NL80211 protocol, while the tb
array is for attributes specific to the OpenWiFi protocol. The function retrieves the generic Netlink message header from the provided message pointer msg
and extracts the attributes using the nla_parse
function.
The function checks if the NL80211_ATTR_TESTDATA
attribute is present in the attrs
array. If this attribute is not found, the function returns NL_SKIP
, indicating that no further processing should occur. If the attribute is present, the function proceeds to parse the data contained within NL80211_ATTR_TESTDATA
into the tb
array.
Next, the function retrieves the value of the OPENWIFI_ATTR_SLICE_START
attribute from the tb
array. This value is expected to be a 32-bit unsigned integer, which is then used to extract two pieces of information: the duration of the slice (the lower 20 bits) and the slice identifier (the upper 12 bits). The duration is printed to the console in microseconds, along with the slice identifier.
Finally, the function returns NL_SKIP
, indicating that no further action is required after processing the message.
Note: It is important to ensure that the Netlink message being processed contains the expected attributes to avoid unexpected behavior. The function assumes that the data structure is correctly formatted and that the necessary attributes are present.
Output Example: A possible output of the function when processing a valid message might look like:
openwifi slice_start (duration) 500us of slice 2
graph TD
A[Start cb_openwifi_slice_start_handler] --> B[Parse attributes from message]
B --> C{Check if NL80211_ATTR_TESTDATA exists}
C -- Yes --> D[Parse OPENWIFI attributes]
C -- No --> E[Return NL_SKIP]
D --> F[Get slice start duration from attributes]
F --> G[Print slice start duration and slice number]
G --> H[Return NL_SKIP]
E --> H
Function handle_set_slice_start(struct nl80211_state *state,
struct nl_cb *cb,
struct nl_msg *msg,
int argc, char **argv,
enum id_input id)
handle_set_slice_start: The function of handle_set_slice_start is to handle the setting of the slice start parameter in the OpenWiFi system.
parameters: The parameters of this Function. · parameter1: struct nl80211_state state - A pointer to the nl80211 state structure that holds the state of the nl80211 subsystem. · parameter2: struct nl_cb cb - A pointer to the callback structure used for handling netlink messages. · parameter3: struct nl_msg msg - A pointer to the netlink message that is being constructed. · parameter4: int argc - The argument count, representing the number of command-line arguments passed. · parameter5: char *argv - An array of strings containing the command-line arguments. · parameter6: enum id_input id - An enumeration value representing the input ID.
Code Description: The handle_set_slice_start function begins by creating a nested attribute in the netlink message using nla_nest_start, specifically for the NL80211_ATTR_TESTDATA attribute. If the nesting fails, the function returns 1, indicating an error. The function then attempts to convert the first command-line argument (argv[0]) to an unsigned integer using strtoul. If the conversion fails (i.e., if there are any non-numeric characters in the input), it also returns 1.
If the conversion is successful, the function proceeds to add two attributes to the netlink message: OPENWIFI_ATTR_CMD, which is set to OPENWIFI_CMD_SET_SLICE_START, and OPENWIFI_ATTR_SLICE_START, which is set to the converted value (tmp). After adding these attributes, the function closes the nested attribute structure with nla_nest_end.
The function then prints a message to the console indicating the value of slice_start in microseconds. Finally, it returns 0 to indicate success. If there is a failure in adding attributes (nla_put_failure), the function returns -ENOBUFS, signaling that there is not enough buffer space.
Note: It is important to ensure that the command-line argument provided is a valid unsigned integer, as any invalid input will result in an error. Additionally, the function assumes that the netlink message is properly initialized before being passed to it.
Output Example: If the function is called with argv[0] set to "5000", the output would be: "openwifi slice_start (duration): 5000us" and the function would return 0. If an invalid input is provided, such as "abc", the function would return 1.
graph TD
A[Start handle_set_slice_start] --> B[Start nesting nlattr]
B --> C{Check if tmdata is NULL}
C -- Yes --> D[Return 1]
C -- No --> E[Convert argv[0] to unsigned int]
E --> F{Check if conversion is valid}
F -- No --> D
F -- Yes --> G[Put OPENWIFI_CMD_SET_SLICE_START in msg]
G --> H[Put OPENWIFI_ATTR_SLICE_START in msg]
H --> I[End nesting nlattr]
I --> J[Print slice_start duration]
J --> K[Return 0]
K --> L[nla_put_failure]
L --> M[Return -ENOBUFS]
Function handle_get_slice_start(struct nl80211_state *state,
struct nl_cb *cb,
struct nl_msg *msg,
int argc, char **argv,
enum id_input id)
handle_get_slice_start: The function of handle_get_slice_start is to prepare and send a request message to retrieve the starting point of a data slice in a wireless context.
parameters: The parameters of this Function. · state: A pointer to the nl80211_state structure that holds the state of the nl80211 subsystem. · cb: A pointer to the nl_cb structure that contains callback functions for handling netlink messages. · msg: A pointer to the nl_msg structure that represents the netlink message to be sent. · argc: An integer representing the number of command-line arguments. · argv: An array of strings containing the command-line arguments. · id: An enumeration value representing the input identifier for the command.
Code Description: The handle_get_slice_start function begins by creating a nested attribute in the netlink message using nla_nest_start. This is done to encapsulate the test data attribute, identified by NL80211_ATTR_TESTDATA. If the nesting fails, the function returns 1, indicating an error. Next, the function adds a 32-bit unsigned integer attribute to the message using NLA_PUT_U32, which specifies the command to be executed, in this case, OPENWIFI_CMD_GET_SLICE_START. After successfully adding the attribute, the function closes the nested attribute with nla_nest_end.
The function then sets a callback for handling the response to the netlink message using nl_cb_set. The callback function cb_openwifi_slice_start_handler will be invoked when a valid response is received. Finally, the function returns 0 to indicate success. If there is a failure in adding the attribute, the code will jump to the nla_put_failure label, which returns -ENOBUFS, signaling that there is insufficient buffer space to complete the operation.
Note: It is important to ensure that the netlink message is properly initialized before calling this function, and that the callback function is capable of handling the expected response format.
Output Example: A successful execution of this function would result in a netlink message being sent, and upon receiving a valid response, the cb_openwifi_slice_start_handler would be called to process the data related to the slice start. The return value of the function would be 0, indicating that the operation was successful.
graph TD
A[Start handle_get_slice_start] --> B[Start nesting attribute in message]
B --> C{Check if nesting started}
C -- Yes --> D[Put command in message]
C -- No --> E[Return error code 1]
D --> F[End nesting attribute in message]
F --> G[Set callback for valid response]
G --> H[Return success code 0]
E --> I[Return error code -ENOBUFS]
Function cb_openwifi_slice_end_handler(struct nl_msg msg, void arg)
cb_openwifi_slice_end_handler: The function of cb_openwifi_slice_end_handler is to handle the end of an OpenWiFi slice by processing a Netlink message and extracting relevant attributes.
parameters: The parameters of this Function. · msg: A pointer to a struct nl_msg that contains the Netlink message to be processed. · arg: A pointer to additional user-defined data that can be passed to the handler (not used in this implementation).
Code Description: The cb_openwifi_slice_end_handler function is defined as a static function that processes a Netlink message related to the end of an OpenWiFi slice. It begins by declaring two arrays of struct nlattr pointers: attrs
for standard Netlink attributes and tb
for OpenWiFi-specific attributes. The function retrieves the generic Netlink message header using nlmsg_data
and nlmsg_hdr
.
The function then parses the attributes from the message using nla_parse
, which populates the attrs
array with the attributes present in the message. It checks if the NL80211_ATTR_TESTDATA
attribute is present; if it is not, the function returns NL_SKIP
, indicating that it should skip further processing.
If the NL80211_ATTR_TESTDATA
attribute is found, the function proceeds to parse the OpenWiFi-specific attributes from this attribute using another call to nla_parse
, filling the tb
array. The function retrieves the value of the OPENWIFI_ATTR_SLICE_END
attribute from the tb
array and stores it in the variable tmp
.
Finally, the function prints the duration of the slice end and the slice ID by formatting the tmp
variable. The duration is extracted using a bitwise AND operation with 0xFFFFF
, while the slice ID is obtained by right-shifting tmp
by 20 bits. The function concludes by returning NL_SKIP
.
Note: It is important to ensure that the Netlink message being processed contains the expected attributes, as the absence of NL80211_ATTR_TESTDATA
will result in early termination of the function.
Output Example: An example output of the function when processing a valid message might look like:
openwifi slice_end (duration) 12345us of slice 2
graph TD
A[Start cb_openwifi_slice_end_handler] --> B[Parse attributes from message]
B --> C{Check if NL80211_ATTR_TESTDATA exists}
C -- Yes --> D[Parse OPENWIFI attributes]
C -- No --> E[Return NL_SKIP]
D --> F[Get slice end duration from attributes]
F --> G[Print slice end duration and slice number]
G --> H[Return NL_SKIP]
E --> H
Function handle_set_slice_end(struct nl80211_state *state,
struct nl_cb *cb,
struct nl_msg *msg,
int argc, char **argv,
enum id_input id)
handle_set_slice_end: The function of handle_set_slice_end is to handle the setting of the slice end duration in the OpenWiFi system.
parameters: The parameters of this Function. · parameter1: struct nl80211_state state - A pointer to the nl80211 state structure that holds the state of the nl80211 subsystem. · parameter2: struct nl_cb cb - A pointer to the netlink callback structure used for handling responses. · parameter3: struct nl_msg msg - A pointer to the netlink message structure that will be populated with the command data. · parameter4: int argc - The count of command-line arguments passed to the function. · parameter5: char *argv - An array of command-line arguments. · parameter6: enum id_input id - An enumeration value representing the input identifier.
Code Description: The handle_set_slice_end function begins by creating a nested attribute in the netlink message using nla_nest_start. If this operation fails, the function returns 1, indicating an error. The function then attempts to convert the first command-line argument (argv[0]) into an unsigned integer using strtoul. If the conversion is unsuccessful (i.e., if there are any non-numeric characters in the input), the function again returns 1.
Next, the function populates the netlink message with two attributes: OPENWIFI_ATTR_CMD, which is set to OPENWIFI_CMD_SET_SLICE_END, and OPENWIFI_ATTR_SLICE_END, which is set to the converted duration value (tmp). After adding these attributes, the nested attribute is closed with nla_nest_end. The function then prints the duration of the slice end in microseconds to the standard output. If all operations are successful, the function returns 0. If there is a failure in adding attributes to the message, it will jump to the nla_put_failure label and return -ENOBUFS, indicating that the buffer is insufficient.
Note: It is important to ensure that the input provided in argv[0] is a valid numeric string to avoid conversion errors. The function expects at least one argument to be passed; otherwise, it may lead to undefined behavior.
Output Example: If the function is called with argv containing "5000", the output would be: openwifi slice_end (duration): 5000us
activityDiagram
start
:Start handle_set_slice_end;
:Initialize tmdata;
:Start nesting attribute in msg;
if (tmdata is NULL?) then (yes)
:Return 1;
else (no)
:Convert argv[0] to unsigned int tmp;
if (end is not NULL?) then (yes)
:Return 1;
else (no)
:Add OPENWIFI_CMD_SET_SLICE_END to msg;
:Add OPENWIFI_ATTR_SLICE_END with tmp to msg;
:End nesting attribute in msg;
:Print slice_end duration;
:Return 0;
endif
endif
:Handle nla_put_failure;
:Return -ENOBUFS;
end
Function handle_get_slice_end(struct nl80211_state *state,
struct nl_cb *cb,
struct nl_msg *msg,
int argc, char **argv,
enum id_input id)
handle_get_slice_end: The function of handle_get_slice_end is to prepare and send a request to retrieve the end of a data slice in the OpenWiFi system.
parameters: The parameters of this Function. · parameter1: struct nl80211_state state - A pointer to the nl80211 state structure that holds the current state of the nl80211 subsystem. · parameter2: struct nl_cb cb - A pointer to the netlink callback structure used to handle responses from the netlink socket. · parameter3: struct nl_msg msg - A pointer to the netlink message structure that will be populated and sent. · parameter4: int argc - The argument count, representing the number of command-line arguments passed to the function. · parameter5: char *argv - An array of strings containing the command-line arguments. · parameter6: enum id_input id - An enumeration value indicating the type of input ID being processed.
Code Description: The handle_get_slice_end function initiates the process of sending a netlink message to request the end of a data slice. It begins by creating a nested attribute in the netlink message using nla_nest_start, specifically for the NL80211_ATTR_TESTDATA attribute. If the nesting fails, the function returns 1, indicating an error. Next, it adds a 32-bit unsigned integer attribute to the message, specifying the command OPENWIFI_CMD_GET_SLICE_END, which indicates the specific operation being requested. After populating the message, the function closes the nested attribute with nla_nest_end.
Furthermore, it sets a callback function, cb_openwifi_slice_end_handler, to handle the response when the netlink message is processed. This is done using nl_cb_set, which associates the callback with the NL_CB_VALID event. If all operations are successful, the function returns 0, indicating success. In the event of a failure during the attribute addition, the function will return -ENOBUFS, signaling that there was insufficient buffer space.
Note: It is important to ensure that the netlink message and callback structures are properly initialized before calling this function. Additionally, the function assumes that the necessary attributes and commands are defined and available in the context of the OpenWiFi system.
Output Example: A successful execution of this function would result in a netlink message being sent that requests the end of a data slice, and upon receiving a valid response, the callback function cb_openwifi_slice_end_handler would be invoked to process the response data.
graph TD
A[Start handle_get_slice_end] --> B[Start nesting attribute in message]
B --> C{Check if tmdata is valid}
C -->|Yes| D[Put command in message]
C -->|No| E[Return 1]
D --> F[End nesting attribute in message]
F --> G[Set callback for valid response]
G --> H[Return 0]
E --> I[Return -ENOBUFS]
Function cb_openwifi_slice_idx_handler(struct nl_msg msg, void arg)
cb_openwifi_slice_idx_handler: The function of cb_openwifi_slice_idx_handler is to handle messages related to the OpenWiFi slice index by parsing attributes from a Netlink message.
parameters: The parameters of this Function. · msg: A pointer to a struct nl_msg that contains the Netlink message to be processed. · arg: A pointer to additional arguments that may be passed to the handler (not used in this function).
Code Description: The cb_openwifi_slice_idx_handler function begins by declaring two arrays of nlattr pointers, attrs
and tb
, which are used to store parsed attributes from the Netlink message. It retrieves the generic Netlink message header using the nlmsg_data function. The function then attempts to parse the attributes from the message using nla_parse, specifically looking for attributes defined in the NL80211 protocol.
If the attribute NL80211_ATTR_TESTDATA is not present in the parsed attributes, the function returns NL_SKIP, indicating that it should skip further processing. If the attribute is present, the function proceeds to parse the OpenWiFi-specific attributes from the test data attribute. It uses nla_parse again to fill the tb
array with attributes defined in the OpenWiFi protocol.
Once the attributes are parsed, the function retrieves the slice index from the parsed attributes using nla_get_u32 and prints it in hexadecimal format. Finally, the function returns NL_SKIP, indicating that no further processing is needed for this message.
Note: It is important to ensure that the message being processed contains the expected attributes; otherwise, the function will terminate early without performing any actions. The function is designed to handle specific Netlink messages related to OpenWiFi and may not be applicable for other types of messages.
Output Example: A possible output of the function when the slice index is 12345678 would be: openwifi slice_idx in hex: 00bc614e
graph TD
A[Start cb_openwifi_slice_idx_handler] --> B[Parse message attributes]
B --> C{Check if NL80211_ATTR_TESTDATA exists}
C -- Yes --> D[Parse OPENWIFI attributes]
C -- No --> E[Return NL_SKIP]
D --> F[Print openwifi slice_idx in hex]
F --> G[Return NL_SKIP]
E --> G
G[End cb_openwifi_slice_idx_handler]
Function handle_set_slice_idx(struct nl80211_state *state,
struct nl_cb *cb,
struct nl_msg *msg,
int argc, char **argv,
enum id_input id)
handle_set_slice_idx: The function of handle_set_slice_idx is to handle the setting of a slice index in a network message.
parameters: The parameters of this Function. · parameter1: struct nl80211_state state - A pointer to the nl80211 state structure, which holds the state of the nl80211 subsystem. · parameter2: struct nl_cb cb - A pointer to the callback structure used for handling netlink messages. · parameter3: struct nl_msg msg - A pointer to the netlink message that will be constructed and sent. · parameter4: int argc - The argument count, representing the number of command-line arguments passed. · parameter5: char *argv - An array of command-line arguments, where the first argument is expected to be the slice index in hexadecimal format. · parameter6: enum id_input id - An enumeration value representing the type of input being processed.
Code Description: The handle_set_slice_idx function begins by declaring a variable for a nested attribute and a variable for parsing the slice index from the command-line arguments. It attempts to start a nested attribute in the netlink message using nla_nest_start. If this operation fails, the function returns 1, indicating an error.
Next, the function converts the first command-line argument (expected to be the slice index) from a hexadecimal string to an unsigned integer using strtoul. If the conversion fails (indicated by the presence of non-numeric characters in the string), the function again returns 1.
If the conversion is successful, the function proceeds to add two attributes to the netlink message: OPENWIFI_ATTR_CMD, which is set to OPENWIFI_CMD_SET_SLICE_IDX, and OPENWIFI_ATTR_SLICE_IDX, which is set to the parsed slice index. After adding these attributes, the function ends the nested attribute with nla_nest_end.
Finally, the function prints the slice index in hexadecimal format for debugging purposes and returns 0 to indicate success. If there is a failure in adding attributes to the message, it will return -ENOBUFS, indicating that there was not enough buffer space.
Note: It is important to ensure that the first command-line argument passed to this function is a valid hexadecimal string representing the slice index. Additionally, the function assumes that the netlink message is properly initialized before being passed to it.
Output Example: If the function is called with a valid slice index of "1A", the output might look like:
openwifi slice_idx in hex: 0000001a
activityDiagram
start
:Initialize variables;
:Start nesting attribute in message;
if (Nesting successful?) then (yes)
:Convert argument to unsigned integer;
if (Conversion successful?) then (yes)
:Add command attribute to message;
:Add slice index attribute to message;
:End nesting attribute in message;
:Print slice index in hex;
:Return success;
else (no)
:Return error for invalid conversion;
endif
else (no)
:Return error for nesting failure;
endif
stop
Function handle_get_slice_idx(struct nl80211_state *state,
struct nl_cb *cb,
struct nl_msg *msg,
int argc, char **argv,
enum id_input id)
handle_get_slice_idx: The function of handle_get_slice_idx is to prepare and send a request message to retrieve the slice index in the OpenWiFi system.
parameters: The parameters of this Function. · parameter1: struct nl80211_state state - A pointer to the nl80211 state structure that holds the state of the nl80211 subsystem. · parameter2: struct nl_cb cb - A pointer to the callback structure used for handling responses to the message. · parameter3: struct nl_msg msg - A pointer to the netlink message that will be constructed and sent. · parameter4: int argc - The argument count that indicates the number of command-line arguments. · parameter5: char *argv - An array of command-line arguments. · parameter6: enum id_input id - An enumeration value that specifies the input identifier.
Code Description: The handle_get_slice_idx function begins by creating a nested attribute in the netlink message using nla_nest_start. This nested attribute is associated with the NL80211_ATTR_TESTDATA attribute. If the nesting fails (i.e., tmdata is NULL), the function returns 1, indicating an error.
Next, the function adds a 32-bit unsigned integer attribute to the message using NLA_PUT_U32, specifically setting the OPENWIFI_ATTR_CMD attribute to the value OPENWIFI_CMD_GET_SLICE_IDX. This indicates that the command being sent is to get the slice index.
After adding the necessary attributes, the function closes the nested attribute with nla_nest_end. It then sets a callback function using nl_cb_set, which specifies that when a valid response is received, the cb_openwifi_slice_idx_handler function should be called to handle the response. The function finally returns 0 to indicate success.
If there is a failure in adding the attribute (which is indicated by the nla_put_failure label), the function will return -ENOBUFS, signaling that there was not enough buffer space to add the requested attribute.
Note: It is important to ensure that the netlink message is properly initialized before calling this function, and that the callback handler is capable of processing the response correctly.
Output Example: A successful execution of this function would result in a netlink message being sent that requests the slice index, and upon receiving a valid response, the cb_openwifi_slice_idx_handler would be invoked to process the slice index data.
graph TD
A[Start handle_get_slice_idx] --> B[Start nesting attribute in message]
B --> C{Check if tmdata is valid}
C -- Yes --> D[Put command in message]
C -- No --> E[Return error code 1]
D --> F[End nesting attribute in message]
F --> G[Set callback for valid message]
G --> H[Return success code 0]
E --> I[Return error code -ENOBUFS]
H --> J[End handle_get_slice_idx]
I --> J
Function cb_openwifi_slice_target_mac_addr_handler(struct nl_msg msg, void arg)
cb_openwifi_slice_target_mac_addr_handler: The function of cb_openwifi_slice_target_mac_addr_handler is to handle messages related to the OpenWiFi slice target MAC address.
parameters: The parameters of this Function. · msg: A pointer to the nl_msg structure that contains the message data. · arg: A pointer to additional arguments that may be used in the handler.
Code Description: The cb_openwifi_slice_target_mac_addr_handler function processes a Netlink message to extract and print the OpenWiFi slice target MAC address. It begins by declaring two arrays of nlattr pointers, attrs
and tb
, which are used to hold parsed attributes from the message. The function retrieves the generic Netlink message header using nlmsg_data
and nlmsg_hdr
, and then it parses the attributes from the message using nla_parse
.
The function checks if the NL80211_ATTR_TESTDATA
attribute is present in the parsed attributes. If this attribute is not found, the function returns NL_SKIP
, indicating that it should skip further processing. If the attribute is present, it proceeds to parse the OPENWIFI_ATTR_MAX
attributes from the NL80211_ATTR_TESTDATA
data.
Once the attributes are parsed, the function retrieves the MAC address from the OPENWIFI_ATTR_ADDR
attribute and prints it in hexadecimal format using printf
. Finally, the function returns NL_SKIP
, signaling that no further action is required.
Note: It is important to ensure that the message being processed contains the required attributes, as the absence of NL80211_ATTR_TESTDATA
will result in the function terminating early without performing any actions.
Output Example: A possible output of the function when the MAC address is successfully retrieved could be: openwifi slice_target_mac_addr(low32) in hex: 00aabbcc
graph TD
A[Start] --> B[Receive nl_msg and arg]
B --> C[Initialize attrs and tb arrays]
C --> D[Extract genlmsghdr from nl_msg]
D --> E[Parse attrs using nla_parse]
E --> F{Check if attrs[NL80211_ATTR_TESTDATA] is NULL}
F -- Yes --> G[Return NL_SKIP]
F -- No --> H[Parse tb using nla_parse]
H --> I[Print openwifi slice_target_mac_addr in hex]
I --> J[Return NL_SKIP]
J --> K[End]
Function handle_set_slice_target_mac_addr(struct nl80211_state *state,
struct nl_cb *cb,
struct nl_msg *msg,
int argc, char **argv,
enum id_input id)
handle_set_slice_target_mac_addr: The function of handle_set_slice_target_mac_addr is to handle the setting of a target MAC address for a specific slice in the OpenWiFi system.
parameters: The parameters of this Function. · parameter1: struct nl80211_state state - A pointer to the nl80211 state structure, which holds the state information for the nl80211 subsystem. · parameter2: struct nl_cb cb - A pointer to the netlink callback structure, used for handling responses from netlink messages. · parameter3: struct nl_msg msg - A pointer to the netlink message structure that will be populated with the command data. · parameter4: int argc - The argument count, representing the number of command-line arguments passed to the function. · parameter5: char *argv - An array of strings containing the command-line arguments. · parameter6: enum id_input id - An enumeration value representing the input identifier.
Code Description: The handle_set_slice_target_mac_addr function begins by creating a nested attribute in the netlink message using nla_nest_start. This is necessary for organizing the data being sent. If the nesting fails, the function returns 1, indicating an error.
Next, the function attempts to convert the first command-line argument (argv[0]) from a hexadecimal string to an unsigned integer using strtoul. The conversion is stored in the variable slice_target_mac_addr. If the conversion fails (indicated by the presence of non-numeric characters in the string), the function again returns 1.
The function then populates the netlink message with two attributes: OPENWIFI_ATTR_CMD, which is set to OPENWIFI_CMD_SET_ADDR, and OPENWIFI_ATTR_ADDR, which is set to the converted slice_target_mac_addr. These attributes are crucial for informing the recipient of the message about the command being executed and the target MAC address.
After adding the attributes, the function closes the nested attribute structure with nla_nest_end. It then prints the slice_target_mac_addr in hexadecimal format for debugging purposes.
If any part of the netlink message population fails (indicated by the nla_put_failure label), the function returns -ENOBUFS, which signifies that there was insufficient buffer space to complete the operation.
Note: It is important to ensure that the input provided in argv[0] is a valid hexadecimal string representing a MAC address. Improper input will lead to an error return value. Additionally, the function assumes that the netlink message structure is properly initialized before being passed to it.
Output Example: A successful execution of the function might result in the following output: "openwifi slice_target_mac_addr(low32) in hex: 00aabbcc". If an error occurs due to invalid input, the function will return 1, indicating failure.
graph TD
A[Start handle_set_slice_target_mac_addr] --> B[Start nesting attribute in message]
B --> C{Check if nesting started}
C -- Yes --> D[Convert argv[0] to unsigned int]
C -- No --> E[Return 1]
D --> F{Check if conversion was successful}
F -- Yes --> G[Put command attribute in message]
F -- No --> E
G --> H[Put address attribute in message]
H --> I[End nesting attribute in message]
I --> J[Print slice_target_mac_addr in hex]
J --> K[Return 0]
K --> L[End handle_set_slice_target_mac_addr]
E --> L
Function handle_get_slice_target_mac_addr(struct nl80211_state *state,
struct nl_cb *cb,
struct nl_msg *msg,
int argc, char **argv,
enum id_input id)
handle_get_slice_target_mac_addr: The function of handle_get_slice_target_mac_addr is to prepare a message for retrieving the MAC address of a target slice in the OpenWiFi system.
parameters: The parameters of this Function. · state: A pointer to the nl80211_state structure that holds the state of the nl80211 protocol. · cb: A pointer to the nl_cb structure that manages callback functions for netlink messages. · msg: A pointer to the nl_msg structure that represents the netlink message being constructed. · argc: An integer representing the count of command-line arguments. · argv: An array of strings representing the command-line arguments. · id: An enumeration value representing the input identifier.
Code Description: The handle_get_slice_target_mac_addr function begins by initiating a nested attribute in the netlink message using nla_nest_start. This is done with the attribute type NL80211_ATTR_TESTDATA. If the nesting fails (i.e., tmdata is NULL), the function returns 1 to indicate an error.
Next, the function adds a 32-bit unsigned integer attribute to the message using NLA_PUT_U32, specifying the command to be OPENWIFI_CMD_GET_ADDR. This command is used to request the MAC address of the target slice.
After adding the attribute, the function concludes the nested attribute section with nla_nest_end. It then sets a callback function for handling the response of the netlink message using nl_cb_set. The callback function specified is cb_openwifi_slice_target_mac_addr_handler, which will be invoked when a valid response is received.
If any part of the message construction fails, the function will jump to the nla_put_failure label, which returns -ENOBUFS, indicating that there is not enough buffer space to complete the operation.
Note: It is important to ensure that the netlink message is properly constructed and that the callback function is correctly set to handle the response. The function assumes that the necessary structures and attributes are defined and available in the context where it is called.
Output Example: A successful execution of this function would result in a netlink message being prepared to request the MAC address, and upon receiving a valid response, the specified callback function would be triggered to process the result. The return value of the function would be 0, indicating success.
graph TD
A[Start handle_get_slice_target_mac_addr] --> B[Start nesting attribute in message]
B --> C[Check if nesting is successful]
C -->|Yes| D[Add command to message]
C -->|No| E[Return error code 1]
D --> F[End nesting attribute in message]
F --> G[Set callback for valid response]
G --> H[Return success code 0]
E --> I[Return error code -ENOBUFS]
H --> J[End handle_get_slice_target_mac_addr]
I --> J
Function cb_openwifi_gap_handler(struct nl_msg msg, void arg)
cb_openwifi_gap_handler: The function of cb_openwifi_gap_handler is to handle messages related to the OpenWiFi GAP (Generalized Access Protocol) by parsing the message attributes and printing the gap value.
parameters: The parameters of this Function. · msg: A pointer to a struct nl_msg, which represents the netlink message received. · arg: A pointer to additional arguments that may be passed to the handler (not used in this function).
Code Description: The cb_openwifi_gap_handler function begins by declaring two arrays of struct nlattr pointers, attrs
and tb
, which are used to hold parsed attributes from the netlink message. It retrieves the generic netlink message header using the nlmsg_data and nlmsg_hdr functions. The function then attempts to parse the attributes from the message using nla_parse, specifically looking for attributes defined in the NL80211 protocol.
The function checks if the attribute NL80211_ATTR_TESTDATA is present. If this attribute is not found, the function returns NL_SKIP, indicating that it should skip further processing of this message. If the attribute is present, it proceeds to parse the nested attributes contained within NL80211_ATTR_TESTDATA into the tb
array.
Finally, the function retrieves the gap value from the parsed attributes using nla_get_u32 and prints it to the standard output in microseconds format. The function concludes by returning NL_SKIP, signaling that no further action is required for this message.
Note: It is important to ensure that the message being processed contains the expected attributes, as the absence of NL80211_ATTR_TESTDATA will result in the function terminating early without any output.
Output Example: A possible output of the function when the gap value is 1500 would be: openwifi GAP (usec): 1500
graph TD
A[Start cb_openwifi_gap_handler] --> B[Receive message and argument]
B --> C[Parse attributes from message]
C --> D{Check if NL80211_ATTR_TESTDATA exists}
D -- Yes --> E[Parse OPENWIFI attributes]
D -- No --> F[Return NL_SKIP]
E --> G[Print openwifi GAP value]
G --> H[Return NL_SKIP]
F --> H
H --> I[End cb_openwifi_gap_handler]
Function handle_set_gap(struct nl80211_state *state,
struct nl_cb *cb,
struct nl_msg *msg,
int argc, char **argv,
enum id_input id)
handle_set_gap: The function of handle_set_gap is to handle the setting of a gap value in microseconds for a specific command message.
parameters: The parameters of this Function. · parameter1: struct nl80211_state state - A pointer to the nl80211 state structure that holds the state of the nl80211 subsystem. · parameter2: struct nl_cb cb - A pointer to the callback structure used for handling netlink messages. · parameter3: struct nl_msg msg - A pointer to the netlink message that will be constructed and sent. · parameter4: int argc - The count of command-line arguments provided. · parameter5: char *argv - An array of command-line arguments. · parameter6: enum id_input id - An enumeration value representing the input ID.
Code Description: The handle_set_gap function begins by declaring local variables, including a netlink attribute pointer (tmdata), a character pointer (end), and an unsigned integer (gap_us). The function initiates a nested attribute in the netlink message using nla_nest_start, which prepares to add attributes under the NL80211_ATTR_TESTDATA attribute. If this operation fails, the function returns 1, indicating an error.
Next, the function attempts to convert the first command-line argument (argv[0]) into an unsigned long integer using strtoul. The conversion checks if the conversion was successful by examining the end pointer; if the conversion fails (i.e., if *end is not null), the function returns 1 to indicate an error.
If the conversion is successful, the function proceeds to add two attributes to the netlink message: OPENWIFI_ATTR_CMD, which is set to OPENWIFI_CMD_SET_GAP, and OPENWIFI_ATTR_GAP, which is set to the converted gap value (gap_us). After adding these attributes, the function closes the nested attribute structure with nla_nest_end.
If any operation fails during the attribute addition (indicated by the nla_put_failure label), the function returns -ENOBUFS, signaling that there is insufficient buffer space to complete the operation. If all operations are successful, the function returns 0, indicating success.
Note: It is important to ensure that the command-line arguments passed to this function are valid and that the netlink message is properly initialized before calling handle_set_gap. Additionally, the function assumes that the first argument is always intended to be the gap value.
Output Example: If the function is called with valid arguments and the gap value is set to 1000, the netlink message will contain attributes indicating the command to set the gap and the specified gap value in microseconds. The return value will be 0, indicating success.
graph TD
A[Start handle_set_gap function] --> B[Start nesting test data in message]
B --> C{Check if nesting successful}
C -- Yes --> D[Convert first argument to unsigned integer]
C -- No --> E[Return 1]
D --> F{Check if conversion was successful}
F -- Yes --> G[Add command to message]
F -- No --> E
G --> H[Add gap to message]
H --> I[End nesting of message]
I --> J[Return 0]
J --> K[End handle_set_gap function]
E --> L[Return -ENOBUFS]
L --> K
Function handle_get_gap(struct nl80211_state *state,
struct nl_cb *cb,
struct nl_msg *msg,
int argc, char **argv,
enum id_input id)
handle_get_gap: The function of handle_get_gap is to prepare and send a request to retrieve the gap information in the OpenWiFi context.
parameters: The parameters of this Function. · state: A pointer to the nl80211_state structure that holds the state of the nl80211 subsystem. · cb: A pointer to the nl_cb structure that contains callback functions for handling netlink messages. · msg: A pointer to the nl_msg structure that represents the netlink message to be sent. · argc: An integer representing the number of command-line arguments. · argv: An array of strings representing the command-line arguments. · id: An enumeration value indicating the type of input being processed.
Code Description: The handle_get_gap function initiates the process of sending a netlink message to request gap information. It begins by creating a nested attribute in the message using nla_nest_start, specifically for the NL80211_ATTR_TESTDATA attribute. If the nesting fails, the function returns 1, indicating an error in starting the nested attribute.
Next, the function adds a 32-bit unsigned integer attribute to the message using NLA_PUT_U32, setting the OPENWIFI_ATTR_CMD attribute to OPENWIFI_CMD_GET_GAP. This indicates the specific command being requested.
After adding the necessary attributes, the function concludes the nested attribute with nla_nest_end. It then sets a callback function using nl_cb_set, which will be invoked when a valid response is received for this request. The callback function specified is cb_openwifi_gap_handler, which will handle the response appropriately.
If the function completes successfully, it returns 0. In the event of a failure during the attribute addition (indicated by the nla_put_failure label), it returns -ENOBUFS, signaling that there was not enough buffer space to add the requested attribute.
Note: It is important to ensure that the nl_msg structure is properly initialized before calling this function. Additionally, the callback function should be implemented to handle the response from the netlink message appropriately.
Output Example: A successful execution of handle_get_gap may result in a netlink message being sent to the kernel, and upon receiving a valid response, the cb_openwifi_gap_handler function will be invoked to process the gap information. The return value of the function will be 0, indicating success.
graph TD
A[Start handle_get_gap function] --> B[Start nesting attribute in message]
B --> C{Check if nesting is successful}
C -- Yes --> D[Add command to message]
C -- No --> E[Return error code 1]
D --> F[End nesting attribute in message]
F --> G[Set callback for valid response]
G --> H[Return success code 0]
E --> I[Return error code -ENOBUFS]
H --> J[End handle_get_gap function]
I --> J