Skip to content

Sysfs intf.c

Function is_valid_iq_number(int c)

is_valid_iq_number: The function of is_valid_iq_number is to determine if a given integer corresponds to a valid IQ number based on specific criteria.

parameters: The parameters of this Function. · parameter1: int c - This parameter represents the integer value that is being evaluated to check if it is a valid IQ number.

Code Description: The is_valid_iq_number function checks if the input integer 'c' meets certain conditions to be classified as a valid IQ number. The function first evaluates if 'c' is equal to 32, which corresponds to the space character in ASCII. If this condition is met, the function returns 1, indicating that it is a valid IQ number. If 'c' does not equal 32, the function then checks if 'c' falls within the range of 44 to 57, which corresponds to the ASCII values for certain punctuation marks and digits. If 'c' is within this range, the function again returns 1, confirming it as a valid IQ number. If neither condition is satisfied, the function returns 0, indicating that 'c' is not a valid IQ number.

Note: It is important to ensure that the input to this function is an integer, as the function does not handle non-integer inputs. The function is designed to return only two possible outputs: 1 for valid IQ numbers and 0 for invalid ones.

Output Example: - If the input is 32, the function will return 1. - If the input is 45, the function will return 1. - If the input is 30, the function will return 0.

graph TD
    A[Start] --> B[Receive input c]
    B --> C{Is c equal to 32?}
    C -- Yes --> D[Return 1]
    C -- No --> E{Is c between 44 and 57?}
    E -- Yes --> D
    E -- No --> F[Return 0]
    D --> G[End]
    F --> G

Function openwifi_tx_intf_bin_iq_write(struct file filp, struct kobject kobj,

           struct bin_attribute *bin_attr, 
           char *buf,  loff_t off,  size_t count)

openwifi_tx_intf_bin_iq_write: The function of openwifi_tx_intf_bin_iq_write is to handle the writing of binary IQ (In-phase and Quadrature) data to a device's interface.

parameters: The parameters of this Function. · parameter1: struct file filp - A pointer to the file structure representing the open file. · parameter2: struct kobject kobj - A pointer to the kernel object associated with the device. · parameter3: struct bin_attribute bin_attr - A pointer to the binary attribute structure. · parameter4: char buf - A pointer to the buffer containing the data to be written. · parameter5: loff_t off - The offset in the file where the write operation starts. · parameter6: size_t count - The number of bytes to write from the buffer.

Code Description: The openwifi_tx_intf_bin_iq_write function is designed to process incoming binary data that represents IQ values for a wireless device. It begins by retrieving the platform device associated with the kobject and obtaining the device's private data structure. The function then initializes a counter for the number of IQ pairs processed and prepares to read from the provided buffer.

The function uses a loop to read pairs of integers (representing I and Q values) from the input buffer. It employs the sscanf function to parse the data, expecting a format of "i,q" for each line. If the parsing fails or does not return exactly two values, an error is logged, and the function returns -EINVAL, indicating an invalid argument.

The valid IQ pairs are stored in the device's private structure, specifically in the tx_intf_arbitrary_iq array, where each IQ pair is combined into a single integer. The function continues to read until either 512 pairs are processed or the end of the input buffer is reached. It also includes checks to skip invalid characters and move to the next line of input.

After processing the input, the function updates the count of valid IQ pairs and logs the results for debugging purposes. Finally, it returns the number of bytes written, which corresponds to the count parameter.

Note: It is important to ensure that the input data adheres to the expected format to avoid errors. The function is limited to processing a maximum of 512 IQ pairs, and any input exceeding this limit will be truncated.

Output Example: A successful execution of the function with a valid input buffer containing "1,2\n3,4\n" would result in a return value of 12, indicating that 12 bytes were processed, and the internal structure would be updated with the corresponding IQ values.

graph TD
    A[Start openwifi_tx_intf_bin_iq_write] --> B[Get platform device from kobject]
    B --> C[Get ieee80211_hw from platform device]
    C --> D[Get openwifi_priv from ieee80211_hw]
    D --> E[Log count value]
    E --> F[Initialize num_iq to 0]
    F --> G[Set line to ptr]
    G --> H[Start while loop]
    H --> I[Read i and q from line using sscanf]
    I --> J{Check sscanf return value}
    J -->|0| K[Log sscanf ret 0 and break]
    J -->|2| L[Store (q<<16)|(i&0xFFFF) in tx_intf_arbitrary_iq[num_iq]]
    L --> M[Increment num_iq]
    M --> N{Check if num_iq equals 512}
    N -->|Yes| O[Log num_iq reach 512 and break]
    N -->|No| P[Move to next line]
    P --> Q[Skip valid iq numbers in ptr]
    Q --> R[Skip invalid iq numbers in ptr]
    R --> S{Check if ptr[0] equals 0}
    S -->|Yes| T[Log ptr[0] equals 0 and break]
    S -->|No| U[Set line to ptr]
    U --> H
    H --> V[Set tx_intf_arbitrary_iq_num to num_iq]
    V --> W[Log num_iq value]
    W --> X[Print i/q values]
    X --> Y[Return count]
    Y --> Z[End openwifi_tx_intf_bin_iq_write]

Function openwifi_tx_intf_bin_iq_write(struct file filp, struct kobject kobj,

           struct bin_attribute *bin_attr, 
           char *buf,  loff_t off,  size_t count)

openwifi_tx_intf_bin_iq_write: The function of openwifi_tx_intf_bin_iq_write is to handle writing binary data to a specific interface for IQ (In-phase and Quadrature) samples in the OpenWiFi driver.

parameters: The parameters of this Function. · parameter1: struct file filp - A pointer to the file structure representing the opened file. · parameter2: struct kobject kobj - A pointer to the kernel object associated with the device. · parameter3: struct bin_attribute bin_attr - A pointer to the binary attribute structure. · parameter4: char buf - A pointer to the buffer containing the data to be written. · parameter5: loff_t off - The offset in the file where the write operation should start. · parameter6: size_t count - The number of bytes to write from the buffer.

Code Description: The openwifi_tx_intf_bin_iq_write function is designed to write IQ sample data to a device's interface. It begins by obtaining the platform device associated with the provided kobject and retrieves the driver data for the device. The function then checks if the count of bytes to be written is a multiple of 4, as each IQ sample is represented by a 32-bit integer (4 bytes). If the count is not a multiple of 4, an error is logged, and the function returns -EINVAL, indicating an invalid argument.

If the count is valid, the function calculates the number of IQ samples (num_iq) by dividing the count by 4. It then updates the private structure associated with the device to store the number of IQ samples and proceeds to copy the IQ data from the provided buffer into the device's private data structure. Each 32-bit integer from the buffer is interpreted as an IQ sample and stored accordingly.

Finally, the function returns the total number of bytes written, which is equal to the count parameter, indicating successful completion of the write operation.

Note: It is important to ensure that the count parameter is a multiple of 4 before calling this function to avoid errors. Additionally, the caller should ensure that the buffer contains valid IQ sample data formatted correctly as 32-bit integers.

Output Example: If the function is called with a count of 8 and a buffer containing two 32-bit integers, it will return 8, indicating that 8 bytes have been successfully written.

graph TD
    A[Start openwifi_tx_intf_bin_iq_write] --> B[Get platform device from kobject]
    B --> C[Get ieee80211_hw from platform device]
    C --> D[Get openwifi_priv from ieee80211_hw]
    D --> E[Log count value]
    E --> F{Is count a multiple of 4?}
    F -- Yes --> G[Calculate num_iq as count divided by 4]
    F -- No --> H[Log error message and return -EINVAL]
    H --> Z[End]
    G --> I[Set tx_intf_arbitrary_iq_num in openwifi_priv]
    I --> J[Loop from 0 to num_iq]
    J --> K[Set tx_intf_arbitrary_iq[i] from buffer]
    K --> L{Is i less than num_iq?}
    L -- Yes --> J
    L -- No --> M[Return count]
    M --> Z[End]

Function openwifi_tx_intf_bin_iq_read(struct file filp, struct kobject kobj,

           struct bin_attribute *bin_attr, 
           char *buf,  loff_t off,  size_t count)

openwifi_tx_intf_bin_iq_read: The function of openwifi_tx_intf_bin_iq_read is to read the IQ (In-phase and Quadrature) data from the OpenWiFi transmission interface and return it in a binary format.

parameters: The parameters of this Function. · filp: A pointer to the file structure representing the open file. · kobj: A pointer to the kobject associated with the device. · bin_attr: A pointer to the bin_attribute structure that defines the binary attribute. · buf: A pointer to the buffer where the read data will be stored. · off: The offset in the buffer from which to start reading. · count: The maximum number of bytes to read.

Code Description: The function begins by obtaining the platform device associated with the kobject and retrieves the device driver data, which includes a pointer to the private structure (openwifi_priv). It checks if the offset (off) is non-zero; if so, it returns 0, indicating that there is no data to read beyond the initial offset. The variable num_iq is then assigned the number of IQ samples available, which is stored in the private structure.

The function prepares to write the number of IQ samples to the buffer. If num_iq is zero or exceeds 512, it appends an error message to the buffer indicating that the number of IQ samples is incorrect. If the number of IQ samples is valid, the function proceeds to write the IQ data into the buffer. It first writes the I (In-phase) components of the IQ samples, followed by the Q (Quadrature) components. Each component is formatted as a short integer and separated by spaces. The total number of bytes written to the buffer is returned as the function's result.

Note: It is important to ensure that the buffer provided is large enough to hold the output data. The function assumes that the caller will handle any necessary memory allocation for the buffer. Additionally, the function is designed to be called only when the offset is zero, as it does not support reading beyond the initial position.

Output Example: A possible appearance of the code's return value when num_iq is 3 and the IQ data is as follows:

3
100 200 150 
50 75 25 
This output indicates that there are three IQ samples, with the I components being 100, 200, and 150, and the Q components being 50, 75, and 25, respectively.

graph TD
    A[Start openwifi_tx_intf_bin_iq_read] --> B[Get platform device from kobject]
    B --> C[Get ieee80211_hw from platform device]
    C --> D[Get openwifi_priv from ieee80211_hw]
    D --> E[Check if offset is non-zero]
    E -->|Yes| F[Return 0]
    E -->|No| G[Get num_iq from openwifi_priv]
    G --> H[Format num_iq into buffer]
    H --> I[Check if num_iq is 0 or greater than 512]
    I -->|Yes| J[Format error message into buffer]
    I -->|No| K[Print I values into buffer]
    K --> L[Print Q values into buffer]
    J --> M[Return ret_size]
    L --> M[Return ret_size]
    M --> N[End openwifi_tx_intf_bin_iq_read]

Function tx_intf_iq_ctl_show(struct device input_dev, struct device_attribute attr, char *buf)

tx_intf_iq_ctl_show: The function of tx_intf_iq_ctl_show is to retrieve and display the value of the tx_intf_iq_ctl attribute from the device's private data structure.

parameters: The parameters of this Function. · input_dev: A pointer to the device structure representing the input device. · attr: A pointer to the device attribute structure associated with the attribute being accessed. · buf: A pointer to the buffer where the output string will be written.

Code Description: The tx_intf_iq_ctl_show function is designed to be called when the system needs to read the value of the tx_intf_iq_ctl attribute from a device. It takes three parameters: a pointer to the device structure (input_dev), a pointer to the device attribute structure (attr), and a buffer (buf) where the output will be stored.

The function begins by converting the input device pointer to a platform device pointer using the to_platform_device macro. This is necessary because the function is specifically designed to work with platform devices. Next, it retrieves the hardware structure associated with the platform device by calling platform_get_drvdata, which returns a pointer to the ieee80211_hw structure. This structure contains a pointer to the private data (openwifi_priv) of the device, which holds various device-specific information.

The function then accesses the tx_intf_iq_ctl field from the private data structure and writes its value to the provided buffer using the sprintf function. The value is formatted as an unsigned integer followed by a newline character. The function returns the number of bytes written to the buffer, which is the standard behavior for functions of this type in the Linux kernel.

Note: It is important to ensure that the device is properly initialized and that the private data structure is correctly populated before calling this function. Additionally, the buffer provided must be large enough to hold the formatted output to avoid buffer overflows.

Output Example: An example of the output that might be returned by this function could be "1\n" if the value of priv->tx_intf_iq_ctl is set to 1.

graph TD
    A[Start] --> B[Receive input device and attribute]
    B --> C[Convert input device to platform device]
    C --> D[Retrieve driver data from platform device]
    D --> E[Access private structure from device]
    E --> F[Format output string with tx_intf_iq_ctl value]
    F --> G[Return formatted string]
    G --> H[End]

Function tx_intf_iq_ctl_store(struct device input_dev, struct device_attribute attr, const char *buf, size_t len)

tx_intf_iq_ctl_store: The function of tx_intf_iq_ctl_store is to handle the storage of I/Q control settings for a transmission interface.

parameters: The parameters of this Function. · input_dev: A pointer to the device structure representing the input device. · attr: A pointer to the device attribute structure associated with the attribute being set. · buf: A pointer to a buffer containing the input data to be processed. · len: The length of the input data in the buffer.

Code Description: The tx_intf_iq_ctl_store function is designed to process input data that configures the transmission interface's I/Q control settings. It begins by converting the input device structure into a platform device structure using the to_platform_device function. This allows access to the driver data associated with the device through the platform_get_drvdata function, which retrieves the ieee80211_hw structure. The ieee80211_hw structure contains a pointer to the openwifi_priv structure, which holds private data related to the device.

The function then attempts to convert the input string from the buf parameter into a long integer using the kstrtol function. If successful, this value is stored in the tx_intf_iq_ctl member of the openwifi_priv structure. The function subsequently invokes the TX_INTF_REG_ARBITRARY_IQ_CTL_write method to switch the transmission interface to I/Q mode.

A printk statement is executed to log the number of I/Q samples that will be sent, which is stored in the tx_intf_arbitrary_iq_num member of the openwifi_priv structure. A loop iterates over the number of I/Q samples, writing each sample to the transmission interface using the TX_INTF_REG_ARBITRARY_IQ_write method.

Finally, the function signals the start of the transmission by calling TX_INTF_REG_ARBITRARY_IQ_CTL_write with a value of 3, and then resets the control register to 0 after the transmission is initiated. The function returns the length of the input data if the conversion was successful, or an error code if the conversion failed.

Note: It is important to ensure that the input data in the buf parameter is in a valid format that can be converted to a long integer. Failure to do so may result in an error during the kstrtol conversion process.

Output Example: If the input buffer contains the string "5" and the conversion is successful, the function will return the length of the input string, which is 1. If the conversion fails, it may return a negative error code indicating the failure.

graph TD
    A[Start] --> B[Receive input parameters]
    B --> C[Convert input device to platform device]
    C --> D[Get driver data from platform device]
    D --> E[Access private structure from device]
    E --> F[Convert input buffer to long integer]
    F --> G[Store value in tx_intf_iq_ctl]
    G --> H[Switch to IQ mode]
    H --> I[Log message with arbitrary IQ number]
    I --> J[Loop through arbitrary IQ number]
    J --> K[Write arbitrary IQ value to register]
    K --> J
    J --> L[Write to start send register]
    L --> M[Write to stop send register]
    M --> N[Return result]
    N --> O[End]

Function stat_enable_show(struct device input_dev, struct device_attribute attr, char *buf)

stat_enable_show: The function of stat_enable_show is to retrieve and display the status of the statistical enable flag from the device's private data structure.

parameters: The parameters of this Function. · parameter1: struct device input_dev - A pointer to the device structure representing the input device from which the statistics are being requested. · parameter2: struct device_attribute attr - A pointer to the device attribute structure that contains information about the attribute being accessed. · parameter3: char *buf - A pointer to a buffer where the output string will be stored.

Code Description: The stat_enable_show function is designed to be called when the system needs to read the current status of the statistical enable flag for a specific device. The function begins by converting the input device pointer (input_dev) to a platform device pointer (pdev) using the to_platform_device macro. This conversion is essential as it allows access to platform-specific data associated with the device.

Next, the function retrieves the hardware structure (dev) associated with the platform device by calling platform_get_drvdata, which returns a pointer to the driver data. This driver data contains a pointer to the private data structure (priv) of the device, which holds various operational parameters, including the statistical settings.

The function then accesses the stat_enable field within the priv structure, which indicates whether the statistics collection is enabled or disabled. Finally, the function formats this value as an unsigned integer and writes it to the provided buffer (buf) using the sprintf function, appending a newline character for proper formatting.

The return value of the function is the number of bytes written to the buffer, which is useful for the caller to know how much data was successfully written.

Note: It is important to ensure that the buffer provided to the function is large enough to hold the formatted output. The expected output is a single unsigned integer followed by a newline character, representing the current state of the statistical enable flag.

Output Example: An example of the possible return value when calling stat_enable_show might be "1\n" if the statistical collection is enabled, or "0\n" if it is disabled.

graph TD
    A[Start] --> B[Receive input device and attribute]
    B --> C[Convert input device to platform device]
    C --> D[Retrieve driver data from platform device]
    D --> E[Access private structure from hardware device]
    E --> F[Format output string with stat_enable value]
    F --> G[Return formatted string to buffer]
    G --> H[End]

Function stat_enable_store(struct device input_dev, struct device_attribute attr, const char *buf, size_t len)

stat_enable_store: The function of stat_enable_store is to store the status enable value for a specific device.

parameters: The parameters of this Function. · parameter1: struct device input_dev - A pointer to the device structure representing the device for which the status enable is being set. · parameter2: struct device_attribute attr - A pointer to the device attribute structure that represents the attribute being modified. · parameter3: const char *buf - A pointer to a buffer containing the string representation of the value to be stored. · parameter4: size_t len - The length of the string in the buffer.

Code Description: The stat_enable_store function is a static function that handles the storage of a status enable value for a device. It takes four parameters: a device pointer, a device attribute pointer, a buffer containing the value to be stored, and the length of that buffer.

The function begins by converting the input device pointer to a platform device pointer using the to_platform_device macro. This allows access to platform-specific data associated with the device. Next, it retrieves the hardware structure associated with the device by calling platform_get_drvdata, which returns a pointer to the ieee80211_hw structure. This structure contains a pointer to the private data of the device, represented by the openwifi_priv structure.

The function then declares a variable named readin of type long, which will hold the converted value from the input buffer. It uses the kstrtol function to convert the string in the buffer (buf) to a long integer, storing the result in readin. The kstrtol function also returns a status code, which is stored in the variable ret. If the conversion is successful, ret will be zero; otherwise, it will contain an error code.

After successfully converting the input string to a long integer, the function assigns this value to the stat_enable member of the priv structure, which is part of the openwifi_priv data. This effectively updates the status enable value for the device.

Finally, the function returns either the error code (if the conversion failed) or the length of the input buffer (if the conversion was successful). This return value indicates the outcome of the operation, allowing the caller to determine if the operation was successful or if an error occurred.

Note: It is important to ensure that the input buffer contains a valid string representation of a number before calling this function, as invalid input may lead to conversion errors.

Output Example: If the input buffer contains the string "1" and the length is 1, the function will return 1, indicating the length of the input buffer. If the input buffer contains an invalid string, such as "abc", the function will return a non-zero error code.

graph TD
    A[Start stat_enable_store function] --> B[Convert input_dev to platform_device]
    B --> C[Get ieee80211_hw from platform_device]
    C --> D[Access private data from ieee80211_hw]
    D --> E[Convert input buffer to long integer]
    E --> F[Update stat_enable in private data]
    F --> G[Check if conversion was successful]
    G -->|Success| H[Return length of input buffer]
    G -->|Failure| I[Return conversion error code]
    H --> J[End stat_enable_store function]
    I --> J

Function tx_prio_queue_show(struct device input_dev, struct device_attribute attr, char *buf)

tx_prio_queue_show: The function of tx_prio_queue_show is to retrieve and format transmission priority queue statistics for a specific device.

parameters: The parameters of this Function. · parameter1: struct device input_dev - A pointer to the device structure representing the device for which the statistics are being retrieved. · parameter2: struct device_attribute attr - A pointer to the device attribute structure, which is not used in this function but is required for the function signature. · parameter3: char *buf - A pointer to a buffer where the formatted statistics will be stored.

Code Description: The tx_prio_queue_show function is designed to collect and display various statistics related to the transmission priority queues of a network device. It begins by converting the input device pointer to a platform device structure using the to_platform_device function. This allows access to the device-specific data. The function then retrieves the hardware structure associated with the device using platform_get_drvdata, which provides access to the private data structure openwifi_priv that contains the statistics.

The function initializes a loop that iterates over a predefined maximum number of software queues, MAX_NUM_SW_QUEUE. For each queue, it formats and appends a series of statistics to the provided buffer. These statistics include the number of transmission priorities, interrupt counts, stop counts (both fake and real), and wakeup counts for both the transmission priority and the transmission queue. The sprintf function is used to format these statistics into a human-readable string, which is accumulated in the buffer.

The total number of bytes written to the buffer is tracked by the ret_size variable, which is updated during each iteration of the loop. Finally, the function returns the total size of the formatted string, allowing the caller to know how much data was written to the buffer.

Note: It is important to ensure that the buffer passed to this function is large enough to hold all the formatted statistics to prevent buffer overflows. The function assumes that the statistics are correctly initialized and populated in the openwifi_priv structure.

Output Example: A possible appearance of the code's return value could be:

10 5 2 1 3 4 8 1 0 0 2 1
9 4 1 0 2 3 7 0 1 1 1 0
...
This output represents the formatted statistics for each transmission priority queue, with each line corresponding to a different queue's statistics.

activityDiagram
    start
    :Receive input device and attribute;
    :Convert input device to platform device;
    :Get driver data from platform device;
    :Access private structure from device;

    :Initialize ret_size to 0;
    :Loop from i = 0 to MAX_NUM_SW_QUEUE;
        :Format and append statistics to buffer;
        :Update ret_size with the length of formatted string;
    end

    :Return ret_size;
    end

Function tx_prio_queue_store(struct device input_dev, struct device_attribute attr, const char *buf, size_t len)

tx_prio_queue_store: The function of tx_prio_queue_store is to handle the storage of transmission priority queue settings for a device.

parameters: The parameters of this Function. · input_dev: A pointer to the device structure representing the input device. · attr: A pointer to the device attribute structure that contains information about the attribute being accessed. · buf: A pointer to a character buffer that contains the data to be stored. · len: The length of the data in the buffer.

Code Description: The tx_prio_queue_store function is designed to process input data related to transmission priority queues for a specific device. It begins by converting the input device structure to a platform device structure using the to_platform_device function. Subsequently, it retrieves the hardware structure associated with the device by calling platform_get_drvdata, which provides access to the private data of the device.

The function then initializes several statistics related to transmission priorities and queues. It first sets all elements of the tx_prio_num, tx_prio_interrupt_num, tx_prio_stop0_fake_num, tx_prio_stop0_real_num, tx_prio_stop1_num, and tx_prio_wakeup_num arrays to zero for each software queue, iterating through the MAX_NUM_SW_QUEUE constant. Following this, it performs a similar initialization for the hardware queue statistics, resetting the tx_queue_num, tx_queue_interrupt_num, tx_queue_stop0_fake_num, tx_queue_stop0_real_num, tx_queue_stop1_num, and tx_queue_wakeup_num arrays for each hardware queue, iterating through the MAX_NUM_HW_QUEUE constant.

The function concludes by returning the result of the kstrtol function call, which converts the input buffer (buf) to a long integer and stores it in the readin variable. If the conversion is successful (indicated by ret being zero), the function returns the length of the input data (len); otherwise, it returns the error code (ret).

Note: It is important to ensure that the input buffer contains valid data that can be converted to a long integer. Any invalid input may result in an error code being returned.

Output Example: A possible return value of the function could be the length of the input data, such as 10, if the input buffer contained valid data and was successfully processed. If an error occurred during the conversion, the function might return a negative error code, such as -EINVAL.

graph TD
    A[Start tx_prio_queue_store function] --> B[Convert input_dev to platform_device]
    B --> C[Get ieee80211_hw from platform_device]
    C --> D[Access private data from ieee80211_hw]
    D --> E[Convert buf to long value]
    E --> F[Initialize tx_prio_num array to 0]
    F --> G[Initialize tx_prio_interrupt_num array to 0]
    G --> H[Initialize tx_prio_stop0_fake_num array to 0]
    H --> I[Initialize tx_prio_stop0_real_num array to 0]
    I --> J[Initialize tx_prio_stop1_num array to 0]
    J --> K[Initialize tx_prio_wakeup_num array to 0]
    K --> L[Initialize tx_queue_num array to 0]
    L --> M[Initialize tx_queue_interrupt_num array to 0]
    M --> N[Initialize tx_queue_stop0_fake_num array to 0]
    N --> O[Initialize tx_queue_stop0_real_num array to 0]
    O --> P[Initialize tx_queue_stop1_num array to 0]
    P --> Q[Initialize tx_queue_wakeup_num array to 0]
    Q --> R[Return ret or len]
    R --> S[End tx_prio_queue_store function]

Function tx_data_pkt_need_ack_num_total_fail_show(struct device input_dev, struct device_attribute attr, char *buf)

tx_data_pkt_need_ack_num_total_fail_show: The function of tx_data_pkt_need_ack_num_total_fail_show is to retrieve and display the total number of failed transmission attempts for data packets that require acknowledgment.

parameters: The parameters of this Function. · input_dev: A pointer to the device structure representing the input device. · attr: A pointer to the device attribute structure associated with the device. · buf: A pointer to a character buffer where the output string will be stored.

Code Description: The function tx_data_pkt_need_ack_num_total_fail_show is defined as a static function that returns a ssize_t value. It takes three parameters: a pointer to a device structure (input_dev), a pointer to a device attribute structure (attr), and a character buffer (buf) for output.

Inside the function, the input device is first cast to a platform device using the to_platform_device macro. This allows access to platform-specific data associated with the device. The function then retrieves the hardware structure (ieee80211_hw) linked to the platform device by calling platform_get_drvdata, which returns a pointer to the driver data.

Next, the function accesses the private data structure (openwifi_priv) associated with the hardware structure through the priv member. This private structure contains various statistics, including the total number of failed transmission attempts for data packets that require acknowledgment, which is stored in the stat member as tx_data_pkt_need_ack_num_total_fail.

Finally, the function formats this value as an unsigned integer and writes it to the provided buffer (buf) followed by a newline character. The return value of the function is the number of bytes written to the buffer, which is the result of the sprintf function.

Note: It is important to ensure that the buffer provided to the function is large enough to hold the formatted output to avoid buffer overflows. The function is typically used in the context of sysfs, allowing user-space applications to read the statistics through the filesystem interface.

Output Example: A possible appearance of the code's return value could be:

5
This indicates that there have been 5 total failed transmission attempts for data packets that require acknowledgment.

graph TD
    A[Start] --> B[Get platform device from input device]
    B --> C[Get driver data from platform device]
    C --> D[Access private structure from driver data]
    D --> E[Prepare output string with total fail count]
    E --> F[Return output string]
    F --> G[End]

Function tx_data_pkt_need_ack_num_total_fail_store(struct device input_dev, struct device_attribute attr, const char *buf, size_t len)

tx_data_pkt_need_ack_num_total_fail_store: The function of tx_data_pkt_need_ack_num_total_fail_store is to store the total number of failed acknowledgment packets for transmitted data.

parameters: The parameters of this Function. · input_dev: A pointer to the device structure representing the input device. · attr: A pointer to the device attribute structure associated with the input device. · buf: A pointer to a character buffer containing the string representation of the number to be stored. · len: The length of the string in the buffer.

Code Description: The function tx_data_pkt_need_ack_num_total_fail_store is designed to handle the storage of the total number of failed acknowledgment packets for transmitted data in a specific device context. It begins by converting the input device pointer, input_dev, to a platform device structure using the to_platform_device macro. This allows the function to access platform-specific data associated with the device.

Next, the function retrieves the hardware structure dev associated with the platform device by calling platform_get_drvdata, which returns a pointer to the driver data. This driver data is expected to contain a pointer to the openwifi_priv structure, which holds various statistics and state information for the device.

The function then attempts to convert the string input from the buf parameter into a long integer using kstrtol. The result of this conversion is stored in the variable readin. The return value of kstrtol is captured in the variable ret, which indicates whether the conversion was successful (0) or if an error occurred (non-zero).

If the conversion is successful, the function updates the tx_data_pkt_need_ack_num_total_fail field of the priv structure with the value of readin, effectively storing the new total number of failed acknowledgment packets. Finally, the function returns the length of the input string if the conversion was successful, or the error code if the conversion failed.

Note: It is important to ensure that the input string in buf is a valid representation of a long integer before calling this function, as invalid input can lead to unexpected behavior or errors.

Output Example: If the input buffer buf contains the string "5" and the conversion is successful, the function will update the tx_data_pkt_need_ack_num_total_fail to 5 and return the length of the string, which is 1. If the input buffer contains an invalid string, such as "abc", the function will return an error code indicating the failure of the conversion.

graph TD
    A[Start] --> B[Get platform device from input_dev]
    B --> C[Get ieee80211_hw from platform device]
    C --> D[Get openwifi_priv from ieee80211_hw]
    D --> E[Convert buf to long using kstrtol]
    E --> F[Store readin in priv->stat.tx_data_pkt_need_ack_num_total_fail]
    F --> G[Check if ret is non-zero]
    G -->|Yes| H[Return ret]
    G -->|No| I[Return len]
    H --> J[End]
    I --> J

Function tx_data_pkt_need_ack_num_total_show(struct device input_dev, struct device_attribute attr, char *buf)

tx_data_pkt_need_ack_num_total_show: The function of tx_data_pkt_need_ack_num_total_show is to retrieve and display the total number of transmitted data packets that require acknowledgment.

parameters: The parameters of this Function. · input_dev: A pointer to the device structure representing the input device from which data is being retrieved.
· attr: A pointer to the device attribute structure that represents the specific attribute being accessed.
· buf: A pointer to a character buffer where the output string will be stored.

Code Description: The tx_data_pkt_need_ack_num_total_show function is a static function designed to be used within the context of a device driver in the Linux kernel. It is responsible for gathering statistics related to transmitted data packets that require acknowledgment.

The function begins by converting the input device pointer (input_dev) to a platform device pointer (pdev) using the to_platform_device macro. This conversion is essential as it allows access to platform-specific data associated with the device. Next, the function retrieves the driver data associated with the platform device by calling platform_get_drvdata, which returns a pointer to the ieee80211_hw structure (dev). This structure contains hardware-specific information and is crucial for accessing the private data of the device.

The private data is accessed through the dev structure, specifically the openwifi_priv structure (priv), which holds various statistics related to the device's operation. The function then retrieves the total number of transmitted data packets that require acknowledgment from the priv structure using priv->stat.tx_data_pkt_need_ack_num_total.

Finally, the function formats this value as an unsigned integer and writes it to the provided buffer (buf) using the sprintf function, appending a newline character at the end. The function returns the number of bytes written to the buffer, which is the standard return value for functions that output data in this manner.

Note: It is important to ensure that the buffer provided to the function is large enough to hold the formatted output to avoid buffer overflows. Additionally, this function is typically called in response to a read operation on a sysfs entry, allowing user-space applications to access the statistics.

Output Example: A possible appearance of the code's return value could be: "42\n", indicating that there have been 42 transmitted data packets that require acknowledgment.

graph TD
    A[Start] --> B[Receive input device and attribute]
    B --> C[Convert input device to platform device]
    C --> D[Get driver data from platform device]
    D --> E[Access private structure from driver data]
    E --> F[Prepare output buffer]
    F --> G[Format output with total acknowledgment number]
    G --> H[Return formatted output]
    H --> I[End]

Function tx_data_pkt_need_ack_num_total_store(struct device input_dev, struct device_attribute attr, const char *buf, size_t len)

tx_data_pkt_need_ack_num_total_store: The function of tx_data_pkt_need_ack_num_total_store is to store the total number of transmission data packets that require acknowledgment.

parameters: The parameters of this Function. · input_dev: A pointer to the device structure representing the input device. · attr: A pointer to the device attribute structure associated with the device. · buf: A pointer to a character buffer containing the data to be stored. · len: The length of the data in the buffer.

Code Description: The tx_data_pkt_need_ack_num_total_store function is a static function that handles the storage of the total number of transmission data packets that require acknowledgment. It takes four parameters: a device pointer (input_dev), a device attribute pointer (attr), a character buffer (buf), and the length of the buffer (len).

The function begins by converting the input device pointer to a platform device pointer using the to_platform_device macro. This allows access to platform-specific data associated with the device. Next, it retrieves the driver data associated with the platform device by calling platform_get_drvdata, which returns a pointer to the ieee80211_hw structure. This structure contains hardware-specific information, including a pointer to the private data structure (openwifi_priv).

The function then attempts to convert the string in the buffer (buf) to a long integer using the kstrtol function. The result is stored in the variable readin, and the return value of kstrtol is stored in the variable ret. If the conversion is successful, the total number of transmission data packets that require acknowledgment is updated in the private structure (priv->stat.tx_data_pkt_need_ack_num_total) with the value of readin.

Finally, the function returns the result of the conversion. If ret is non-zero, it indicates an error occurred during the conversion, and ret is returned. If the conversion is successful, the function returns the length of the input data (len).

Note: It is important to ensure that the input data in the buffer is a valid integer string before calling this function to avoid conversion errors. The function assumes that the caller has validated the input data format.

Output Example: If the input buffer contains the string "5" and the conversion is successful, the function will update the total acknowledgment packets to 5 and return the length of the input string, which is 1. If the input buffer contains an invalid string, such as "abc", the function will return an error code indicating the failure of the conversion.

graph TD
    A[Start] --> B[Get platform device from input device]
    B --> C[Get ieee80211 hardware from platform device]
    C --> D[Get private data from ieee80211 hardware]
    D --> E[Convert input buffer to long]
    E --> F[Store converted value in private data structure]
    F --> G[Check conversion result]
    G -->|Success| H[Return length of input buffer]
    G -->|Failure| I[Return conversion error code]
    H --> J[End]
    I --> J

Function tx_mgmt_pkt_need_ack_num_total_show(struct device input_dev, struct device_attribute attr, char *buf)

tx_mgmt_pkt_need_ack_num_total_show: The function of tx_mgmt_pkt_need_ack_num_total_show is to retrieve and display the total number of transmitted management packets that require acknowledgment.

parameters: The parameters of this Function. · input_dev: A pointer to the device structure representing the input device. · attr: A pointer to the device attribute structure. · buf: A pointer to a character buffer where the output will be written.

Code Description: The tx_mgmt_pkt_need_ack_num_total_show function is a static function that is designed to be used in the context of a device's sysfs interface. It takes three parameters: a pointer to the device structure (input_dev), a pointer to the device attribute structure (attr), and a character buffer (buf) where the output will be stored.

The function begins by converting the input device pointer to a platform device pointer using the to_platform_device macro. This is necessary because the function is intended to work with platform devices, which are a specific type of device in the Linux kernel.

Next, the function retrieves the hardware structure associated with the platform device by calling platform_get_drvdata, which returns a pointer to the ieee80211_hw structure. This structure contains various data related to the IEEE 802.11 wireless hardware.

From the ieee80211_hw structure, the function accesses the private data structure (openwifi_priv) associated with the device through the priv member. This private structure holds statistics and other information specific to the device.

Finally, the function uses the sprintf function to format the total number of transmitted management packets that require acknowledgment (priv->stat.tx_mgmt_pkt_need_ack_num_total) into the provided buffer (buf). The total is formatted as an unsigned integer followed by a newline character. The function returns the number of bytes written to the buffer, which is the return value of sprintf.

Note: It is important to ensure that the buffer provided to this function is large enough to hold the formatted output. The function assumes that the private data structure has been properly initialized and that the statistics are being maintained accurately.

Output Example: An example of the possible appearance of the code's return value could be "42\n", indicating that there have been 42 transmitted management packets that require acknowledgment.

graph TD
    A[Start function tx_mgmt_pkt_need_ack_num_total_show] --> B[Get platform device from input device]
    B --> C[Retrieve driver data from platform device]
    C --> D[Access private structure from driver data]
    D --> E[Prepare to return total number of management packets needing acknowledgment]
    E --> F[Format the output string with total number]
    F --> G[Return formatted string to buffer]
    G --> H[End function]

Function tx_mgmt_pkt_need_ack_num_total_store(struct device input_dev, struct device_attribute attr, const char *buf, size_t len)

tx_mgmt_pkt_need_ack_num_total_store: The function of tx_mgmt_pkt_need_ack_num_total_store is to store the total number of management packets that require acknowledgment.

parameters: The parameters of this Function. · parameter1: struct device input_dev - A pointer to the device structure representing the input device. · parameter2: struct device_attribute attr - A pointer to the device attribute structure. · parameter3: const char *buf - A pointer to a buffer containing the string representation of the number to be stored. · parameter4: size_t len - The length of the buffer.

Code Description: The tx_mgmt_pkt_need_ack_num_total_store function is a static function that handles the storage of a specific value related to the transmission of management packets that require acknowledgment. It takes four parameters: a device pointer, a device attribute pointer, a buffer containing the input data, and the length of that buffer.

The function begins by converting the input device pointer to a platform device pointer using the to_platform_device macro. This allows access to platform-specific data associated with the device. Next, it retrieves the hardware structure associated with the device by calling platform_get_drvdata, which returns a pointer to the ieee80211_hw structure. This structure contains the private data for the device, which is accessed through the priv member.

The function then attempts to convert the string input from the buffer (buf) into a long integer using the kstrtol function. The conversion is based on base 10, and the result is stored in the variable readin. The return value of kstrtol is stored in the variable ret, which indicates whether the conversion was successful or not.

If the conversion is successful, the function assigns the value of readin to the tx_mgmt_pkt_need_ack_num_total member of the openwifi_priv structure, which is part of the private data associated with the device. This effectively updates the total count of management packets that need acknowledgment.

Finally, the function returns either the result of the conversion (if it failed) or the length of the input buffer (if it succeeded), thus indicating the outcome of the operation.

Note: It is important to ensure that the input buffer contains a valid string representation of a number before calling this function, as invalid input may lead to conversion errors. The function is designed to handle such errors gracefully by returning the appropriate error code.

Output Example: If the input buffer contains the string "10" and the conversion is successful, the function will return 2 (the length of the input string), and the value of tx_mgmt_pkt_need_ack_num_total will be updated to 10. If the input buffer contains an invalid string, the function may return a negative error code.

graph TD
    A[Start function tx_mgmt_pkt_need_ack_num_total_store] --> B[Convert input_dev to platform_device]
    B --> C[Get ieee80211_hw from platform_device]
    C --> D[Access private data from ieee80211_hw]
    D --> E[Convert buf to long using kstrtol]
    E --> F[Store readin in tx_mgmt_pkt_need_ack_num_total]
    F --> G[Check if ret is non-zero]
    G -->|Yes| H[Return ret]
    G -->|No| I[Return len]
    H --> J[End function]
    I --> J

Function tx_mgmt_pkt_need_ack_num_total_fail_show(struct device input_dev, struct device_attribute attr, char *buf)

tx_mgmt_pkt_need_ack_num_total_fail_show: The function of tx_mgmt_pkt_need_ack_num_total_fail_show is to retrieve and display the total number of failed transmission management packets that require acknowledgment.

parameters: The parameters of this Function. · input_dev: A pointer to the device structure representing the input device from which the data is being retrieved.
· attr: A pointer to the device attribute structure that contains information about the attribute being accessed.
· buf: A pointer to a character buffer where the output string will be written.

Code Description: The tx_mgmt_pkt_need_ack_num_total_fail_show function is a static function that is designed to be used in the context of a device's sysfs interface. It retrieves the total number of failed transmission management packets that require acknowledgment from the device's private data structure and formats this information as a string for display.

  1. The function begins by converting the input device pointer (input_dev) to a platform device pointer (pdev) using the to_platform_device macro. This is necessary because the function needs to access platform-specific data associated with the device.
  2. Next, it retrieves the hardware structure (dev) associated with the platform device by calling platform_get_drvdata, which returns a pointer to the device's driver data.
  3. The function then accesses the private data structure (priv) of the device, which contains various statistics, including the number of failed transmission management packets.
  4. Finally, the function uses sprintf to write the total number of failed packets (priv->stat.tx_mgmt_pkt_need_ack_num_total_fail) into the provided buffer (buf), appending a newline character at the end. The function returns the number of bytes written to the buffer.

Note: It is important to ensure that the buffer provided to the function is large enough to hold the formatted string, including the newline character. The function is typically called in response to a read operation on the corresponding sysfs attribute, allowing users to query the status of the device.

Output Example: An example of the output from this function could be "5\n", indicating that there have been a total of 5 failed transmission management packets that required acknowledgment.

graph TD
    A[Start function tx_mgmt_pkt_need_ack_num_total_fail_show] --> B[Get platform device from input_dev]
    B --> C[Retrieve ieee80211_hw from platform device]
    C --> D[Access private data from ieee80211_hw]
    D --> E[Format output string with tx_mgmt_pkt_need_ack_num_total_fail value]
    E --> F[Return formatted string to buffer]
    F --> G[End function]

Function tx_mgmt_pkt_need_ack_num_total_fail_store(struct device input_dev, struct device_attribute attr, const char *buf, size_t len)

tx_mgmt_pkt_need_ack_num_total_fail_store: The function of tx_mgmt_pkt_need_ack_num_total_fail_store is to store the total number of failed transmission management packets that require acknowledgment.

parameters: The parameters of this Function. · parameter1: struct device input_dev - A pointer to the device structure representing the device for which the attribute is being set. · parameter2: struct device_attribute attr - A pointer to the device attribute structure that contains the attribute being set. · parameter3: const char *buf - A pointer to a buffer containing the input string that represents the value to be stored. · parameter4: size_t len - The length of the input string in the buffer.

Code Description: The tx_mgmt_pkt_need_ack_num_total_fail_store function is a static function that handles the storage of the total number of failed transmission management packets that require acknowledgment. It takes four parameters: a pointer to the device structure, a pointer to the device attribute structure, a buffer containing the input string, and the length of that string.

The function begins by converting the input device pointer to a platform device pointer using the to_platform_device macro. It then retrieves the hardware structure associated with the device by calling platform_get_drvdata, which returns a pointer to the ieee80211_hw structure. This structure contains a private data pointer, priv, which points to the openwifi_priv structure that holds various statistics.

Next, the function attempts to convert the input string (buf) to a long integer using the kstrtol function. The conversion result is stored in the variable readin, and the return value of kstrtol is stored in ret. If the conversion is successful, the total number of failed acknowledgment-required transmission management packets is updated in the priv structure by assigning the value of readin to priv->stat.tx_mgmt_pkt_need_ack_num_total_fail.

Finally, the function returns the length of the input string if the conversion was successful (ret is 0), or the error code returned by kstrtol if the conversion failed.

Note: It is important to ensure that the input string is a valid representation of a long integer before calling this function, as invalid input can lead to unexpected behavior or errors. The function is designed to be used in a context where it is invoked as part of a sysfs interface, allowing user-space applications to modify the statistics of the device.

Output Example: If the input buffer contains the string "5" and the length is 1, the function will update the total fail count to 5 and return 1, indicating the length of the input string processed.

graph TD
    A[Start] --> B[Get platform device from input device]
    B --> C[Get ieee80211_hw from platform device]
    C --> D[Get openwifi_priv from ieee80211_hw]
    D --> E[Convert input buffer to long]
    E --> F[Store value in tx_mgmt_pkt_need_ack_num_total_fail]
    F --> G[Return result based on conversion success]
    G --> H[End]

Function tx_data_pkt_need_ack_num_retx_show(struct device input_dev, struct device_attribute attr, char *buf)

tx_data_pkt_need_ack_num_retx_show: The function of tx_data_pkt_need_ack_num_retx_show is to retrieve and display the number of data packets that require acknowledgment and have been retransmitted.

parameters: The parameters of this Function. · parameter1: struct device input_dev - A pointer to the device structure representing the input device. · parameter2: struct device_attribute attr - A pointer to the device attribute structure associated with the device. · parameter3: char *buf - A pointer to a buffer where the output string will be stored.

Code Description: The tx_data_pkt_need_ack_num_retx_show function is a static function that is designed to be used in the context of a device's sysfs interface. It takes three parameters: a pointer to the device structure, a pointer to the device attribute structure, and a buffer for output.

The function begins by converting the input device pointer to a platform device pointer using the to_platform_device macro. This allows access to platform-specific data associated with the device. Next, it retrieves the hardware structure (ieee80211_hw) associated with the platform device by calling platform_get_drvdata, which returns a pointer to the driver data stored in the platform device.

From the ieee80211_hw structure, the function accesses the private data structure (openwifi_priv) that contains various statistics related to the device's operation. Specifically, it focuses on the tx_data_pkt_need_ack_num_retx array, which holds the count of transmitted data packets that require acknowledgment and have been retransmitted.

The function then formats this data into a string using sprintf, which writes the values from the tx_data_pkt_need_ack_num_retx array into the provided buffer. The output consists of six unsigned integers, each representing the count of retransmissions for different categories of packets, followed by a newline character.

Finally, the function returns the number of bytes written to the buffer, which is the length of the formatted string.

Note: It is important to ensure that the buffer provided to the function is large enough to hold the formatted output to avoid buffer overflow. The function is intended to be used in a read operation within the sysfs interface, allowing users to query the retransmission statistics of the device.

Output Example: A possible appearance of the code's return value could be: "10 5 3 2 1 0\n" This output indicates that there have been 10, 5, 3, 2, 1, and 0 retransmissions for the respective categories of data packets.

graph TD
    A[Start function tx_data_pkt_need_ack_num_retx_show] --> B[Get platform device from input device]
    B --> C[Get ieee80211 hardware data from platform device]
    C --> D[Get private data from ieee80211 hardware]
    D --> E[Format output string with tx_data_pkt_need_ack_num_retx values]
    E --> F[Return formatted string]
    F --> G[End function tx_data_pkt_need_ack_num_retx_show]

Function tx_data_pkt_need_ack_num_retx_store(struct device input_dev, struct device_attribute attr, const char *buf, size_t len)

tx_data_pkt_need_ack_num_retx_store: The function of tx_data_pkt_need_ack_num_retx_store is to store the number of retransmissions needed for acknowledgment of transmitted data packets.

parameters: The parameters of this Function. · input_dev: A pointer to the device structure representing the input device. · attr: A pointer to the device attribute structure associated with the input device. · buf: A pointer to a character buffer containing the input data to be processed. · len: The length of the input data in the buffer.

Code Description: The tx_data_pkt_need_ack_num_retx_store function is a static function that handles the storage of the number of retransmissions required for acknowledgment of transmitted data packets. It takes in several parameters, including a device structure, a device attribute structure, a character buffer containing input data, and the length of that data.

The function begins by converting the input device pointer to a platform device pointer using the to_platform_device macro. It then retrieves the associated ieee80211_hw structure by calling platform_get_drvdata with the platform device pointer. The ieee80211_hw structure contains a pointer to the private data structure openwifi_priv, which holds various statistics related to the device.

The function then attempts to convert the input string in the buffer (buf) to a long integer using the kstrtol function. This conversion is stored in the variable readin, and the return value of kstrtol is stored in the variable ret. The function iterates six times, assigning the value of readin to the tx_data_pkt_need_ack_num_retx array within the openwifi_priv structure. This array is presumably used to track the number of retransmissions needed for acknowledgment for different scenarios or configurations.

Finally, the function returns either the result of the kstrtol conversion (if it failed) or the length of the input data (len) if the conversion was successful.

Note: It is important to ensure that the input data in buf is a valid string representation of a number before calling this function, as invalid input may lead to unexpected behavior or errors during the conversion process.

Output Example: If the input buffer contains the string "3" and the length is 1, the function will set the first six elements of the tx_data_pkt_need_ack_num_retx array to 3 and return 1, indicating the length of the input data processed.

graph TD
    A[Start] --> B[Get platform device from input_dev]
    B --> C[Get ieee80211_hw from platform device]
    C --> D[Get openwifi_priv from ieee80211_hw]
    D --> E[Convert buf to long value]
    E --> F[Check conversion result]
    F -->|Success| G[Store readin in tx_data_pkt_need_ack_num_retx array]
    F -->|Failure| H[Return conversion error]
    G --> I[Return length or conversion result]
    H --> I
    I --> J[End]

Function tx_mgmt_pkt_need_ack_num_retx_show(struct device input_dev, struct device_attribute attr, char *buf)

tx_mgmt_pkt_need_ack_num_retx_show: The function of tx_mgmt_pkt_need_ack_num_retx_show is to retrieve and display the number of management packets that require acknowledgment and have been retransmitted.

parameters: The parameters of this Function. · parameter1: struct device input_dev - A pointer to the device structure representing the device from which the data is being retrieved. · parameter2: struct device_attribute attr - A pointer to the device attribute structure that represents the attribute being accessed. · parameter3: char *buf - A pointer to a buffer where the output string will be stored.

Code Description: The function tx_mgmt_pkt_need_ack_num_retx_show is defined as a static function that returns a ssize_t value. It takes three parameters: a pointer to a device structure, a pointer to a device attribute structure, and a character buffer for output.

The function begins by converting the input device pointer to a platform device structure using the to_platform_device macro. This allows access to platform-specific data associated with the device. Next, it retrieves the hardware structure associated with the device by calling platform_get_drvdata, which returns a pointer to the ieee80211_hw structure. This structure contains a pointer to the private data of the device, which is accessed through the priv member.

The function then formats the output string using sprintf, which writes the number of management packets that require acknowledgment and have been retransmitted into the provided buffer. Specifically, it accesses the tx_mgmt_pkt_need_ack_num_retx array within the priv->stat structure, retrieving three values corresponding to different states or counters. Finally, the function returns the number of bytes written to the buffer, which is the result of the sprintf call.

Note: It is important to ensure that the buffer provided to the function is large enough to hold the formatted output, including the newline character. The function is typically used in a sysfs context, allowing user-space applications to read the number of retransmitted management packets through the sysfs filesystem.

Output Example: An example of the possible appearance of the code's return value could be: "5 3 2\n", where "5" represents the count of the first state, "3" represents the second state, and "2" represents the third state of retransmitted management packets requiring acknowledgment.

graph TD
    A[Start function tx_mgmt_pkt_need_ack_num_retx_show] --> B[Get platform device from input_dev]
    B --> C[Get ieee80211_hw from platform device]
    C --> D[Get openwifi_priv from ieee80211_hw]
    D --> E[Prepare to return formatted string]
    E --> F[Return formatted string with tx_mgmt_pkt_need_ack_num_retx values]
    F --> G[End function]

Function tx_mgmt_pkt_need_ack_num_retx_store(struct device input_dev, struct device_attribute attr, const char *buf, size_t len)

tx_mgmt_pkt_need_ack_num_retx_store: The function of tx_mgmt_pkt_need_ack_num_retx_store is to store the number of retransmissions needed for management packets that require acknowledgment.

parameters: The parameters of this Function. · parameter1: struct device input_dev - A pointer to the device structure representing the input device. · parameter2: struct device_attribute attr - A pointer to the device attribute structure. · parameter3: const char *buf - A pointer to the buffer containing the input data as a string. · parameter4: size_t len - The length of the input data in the buffer.

Code Description: The tx_mgmt_pkt_need_ack_num_retx_store function is a static function that handles the storage of the number of retransmissions for management packets that require acknowledgment. It takes four parameters: a pointer to the input device, a pointer to the device attribute, a buffer containing the input data, and the length of that data.

The function begins by converting the input device pointer to a platform device structure using the to_platform_device macro. It then retrieves the driver data associated with the platform device, which is expected to be of type ieee80211_hw. This structure contains a pointer to the private data structure openwifi_priv, which holds various statistics related to the device.

Next, the function attempts to convert the input string (buf) into a long integer using the kstrtol function. The result of this conversion is stored in the variable readin, and the return value of kstrtol is stored in the variable ret. The function then enters a loop that iterates three times, during which it assigns the value of readin to the tx_mgmt_pkt_need_ack_num_retx array within the priv structure. This effectively sets the same retransmission count for three different indices in the array.

Finally, the function returns the result of the conversion (ret) if it is non-zero, indicating an error during the conversion process. If the conversion is successful, it returns the length of the input data (len), indicating that the operation was completed successfully.

Note: It is important to ensure that the input data is a valid integer string, as invalid input may lead to unexpected behavior or errors during the conversion process.

Output Example: If the input buffer contains the string "5" and the length is 1, the function will store the value 5 in all three indices of the tx_mgmt_pkt_need_ack_num_retx array and return 1, indicating the length of the input data.

graph TD
    A[Start] --> B[Convert input_dev to platform_device]
    B --> C[Get ieee80211_hw from platform_device]
    C --> D[Access private data from ieee80211_hw]
    D --> E[Convert buf to long value]
    E --> F[Initialize loop variable i]
    F --> G{Is i < 3?}
    G -- Yes --> H[Store readin in tx_mgmt_pkt_need_ack_num_retx[i]]
    H --> I[Increment i]
    I --> F
    G -- No --> J{Is ret non-zero?}
    J -- Yes --> K[Return ret]
    J -- No --> L[Return len]
    K --> M[End]
    L --> M

Function tx_data_pkt_need_ack_num_retx_fail_show(struct device input_dev, struct device_attribute attr, char *buf)

tx_data_pkt_need_ack_num_retx_fail_show: The function of tx_data_pkt_need_ack_num_retx_fail_show is to retrieve and display the number of transmission data packets that required acknowledgment but failed to be retransmitted.

parameters: The parameters of this Function. · parameter1: struct device input_dev - A pointer to the device structure representing the input device. · parameter2: struct device_attribute attr - A pointer to the device attribute structure, which contains information about the attribute being accessed. · parameter3: char *buf - A pointer to a buffer where the output string will be stored.

Code Description: The tx_data_pkt_need_ack_num_retx_fail_show function is a static function that returns the number of transmission data packets that required acknowledgment but failed to be retransmitted. It takes three parameters: a pointer to the device structure, a pointer to the device attribute structure, and a buffer to store the output.

The function begins by converting the input device pointer to a platform device pointer using the to_platform_device macro. This allows access to platform-specific data associated with the device. Next, it retrieves the hardware structure associated with the device using the platform_get_drvdata function, which returns a pointer to the ieee80211_hw structure. This structure contains a pointer to the openwifi_priv structure, which holds the private data for the device.

The function then formats the output string using the sprintf function, which writes the number of failed acknowledgment retransmissions into the provided buffer. Specifically, it accesses the tx_data_pkt_need_ack_num_retx_fail array within the priv->stat structure to retrieve the relevant statistics. The function returns the number of bytes written to the buffer, which is the length of the formatted string.

Note: It is important to ensure that the buffer provided to the function is large enough to hold the formatted output to prevent buffer overflow. The function is typically called in the context of a sysfs interface, allowing user-space applications to read the statistics.

Output Example: A possible appearance of the code's return value could be: "5 3 2 0 1 4" This output indicates that there were 5, 3, 2, 0, 1, and 4 failed retransmissions for the respective indices of the tx_data_pkt_need_ack_num_retx_fail array.

graph TD
    A[Start] --> B[Get platform device from input device]
    B --> C[Get hardware data from platform device]
    C --> D[Access private structure from hardware data]
    D --> E[Format output string with acknowledgment statistics]
    E --> F[Return formatted string]
    F --> G[End]

Function tx_data_pkt_need_ack_num_retx_fail_store(struct device input_dev, struct device_attribute attr, const char *buf, size_t len)

tx_data_pkt_need_ack_num_retx_fail_store: The function of tx_data_pkt_need_ack_num_retx_fail_store is to store the number of retransmission failures for data packets that require acknowledgment.

parameters: The parameters of this Function. · input_dev: A pointer to the device structure representing the input device. · attr: A pointer to the device attribute structure associated with the attribute being written to. · buf: A pointer to a buffer containing the input data as a string. · len: The length of the input data in the buffer.

Code Description: The tx_data_pkt_need_ack_num_retx_fail_store function is a static function that handles the storage of a specific configuration value related to data packet transmission in a wireless device. It takes four parameters: a device pointer (input_dev), a device attribute pointer (attr), a buffer containing the input data (buf), and the length of that data (len).

The function begins by converting the input device pointer to a platform device pointer using the to_platform_device macro. It then retrieves the associated hardware structure (ieee80211_hw) by calling platform_get_drvdata with the platform device pointer. The private data structure (openwifi_priv) is accessed through the ieee80211_hw structure.

The function then declares a variable named readin to hold the converted input value and uses kstrtol to convert the string in buf to a long integer. This conversion also checks for any errors during the process, storing the result in the variable ret. A loop iterates six times, assigning the value of readin to the tx_data_pkt_need_ack_num_retx_fail array within the private data structure. This effectively sets the same retransmission failure count for six different entries in the array.

Finally, the function returns the result of the conversion if an error occurred (non-zero ret), or the length of the input data (len) if the operation was successful.

Note: It is important to ensure that the input data in buf is a valid string representation of a number, as improper input may lead to conversion errors. The function is designed to handle specific configurations related to packet transmission and should be used in the context of managing wireless device settings.

Output Example: If the input buffer contains the string "3" and the length is 1, the function will store the value 3 in each of the six entries of the tx_data_pkt_need_ack_num_retx_fail array, and it will return the length of the input data, which is 1.

graph TD
    A[Start function tx_data_pkt_need_ack_num_retx_fail_store] --> B[Get platform device from input_dev]
    B --> C[Get ieee80211_hw from platform device]
    C --> D[Get openwifi_priv from ieee80211_hw]
    D --> E[Convert buf to long value]
    E --> F[Check conversion result]
    F -->|Success| G[Store readin in priv->stat.tx_data_pkt_need_ack_num_retx_fail for 6 iterations]
    F -->|Failure| H[Return conversion error]
    G --> I[Return ret or len]
    H --> I
    I[End function]

Function tx_mgmt_pkt_need_ack_num_retx_fail_show(struct device input_dev, struct device_attribute attr, char *buf)

tx_mgmt_pkt_need_ack_num_retx_fail_show: The function of tx_mgmt_pkt_need_ack_num_retx_fail_show is to retrieve and display the number of transmission management packets that require acknowledgment but have failed to be retransmitted.

parameters: The parameters of this Function. · parameter1: struct device input_dev - A pointer to the device structure representing the input device from which the data is being retrieved. · parameter2: struct device_attribute attr - A pointer to the device attribute structure that represents the specific attribute being accessed. · parameter3: char *buf - A pointer to a buffer where the output string will be written.

Code Description: The function tx_mgmt_pkt_need_ack_num_retx_fail_show is defined as a static function that returns a ssize_t value. It takes three parameters: a device pointer, a device attribute pointer, and a buffer pointer.

The function begins by converting the input device pointer to a platform device pointer using the to_platform_device macro. This is necessary because the function is designed to work with platform devices. Next, it retrieves the hardware structure associated with the platform device by calling platform_get_drvdata, which returns a pointer to the ieee80211_hw structure. This structure contains a private data pointer, which is accessed through the priv member.

The function then accesses the stat member of the private data structure, specifically the tx_mgmt_pkt_need_ack_num_retx_fail array, which holds the count of management packets that need acknowledgment but have failed retransmission. The function formats these three values into the provided buffer using sprintf, ensuring that they are separated by spaces and followed by a newline character. Finally, the function returns the number of bytes written to the buffer.

Note: It is important to ensure that the buffer passed to this function is large enough to hold the formatted string, including the newline character, to prevent buffer overflows. The function is typically used in the context of sysfs, allowing user-space applications to read the statistics of the device.

Output Example: A possible appearance of the code's return value could be: "5 3 2\n" This output indicates that there have been 5 failed retransmissions for the first type of management packet, 3 for the second type, and 2 for the third type.

graph TD
    A[Start function tx_mgmt_pkt_need_ack_num_retx_fail_show] --> B[Get platform device from input device]
    B --> C[Get ieee80211 hardware data from platform device]
    C --> D[Access private data structure from ieee80211 hardware]
    D --> E[Prepare output string with tx_mgmt_pkt_need_ack_num_retx_fail statistics]
    E --> F[Return formatted output string]
    F --> G[End function]

Function tx_mgmt_pkt_need_ack_num_retx_fail_store(struct device input_dev, struct device_attribute attr, const char *buf, size_t len)

tx_mgmt_pkt_need_ack_num_retx_fail_store: The function of tx_mgmt_pkt_need_ack_num_retx_fail_store is to store the number of retransmission failures for management packets that require acknowledgment.

parameters: The parameters of this Function. · input_dev: A pointer to the device structure representing the input device. · attr: A pointer to the device attribute structure. · buf: A pointer to a buffer containing the input data as a string. · len: The length of the input data in the buffer.

Code Description: The tx_mgmt_pkt_need_ack_num_retx_fail_store function is a static function that handles the storage of a specific configuration related to the number of retransmission failures for management packets that require acknowledgment.

The function begins by converting the input device pointer (input_dev) to a platform device structure (pdev) using the to_platform_device macro. It then retrieves the associated hardware structure (dev) using platform_get_drvdata, which provides access to the driver data linked to the platform device. The private data structure (priv) of type openwifi_priv is accessed through the hardware structure, allowing the function to manipulate driver-specific data.

The function reads an integer value from the input buffer (buf) using kstrtol, which converts the string representation of the number into a long integer (readin). The return value of kstrtol is stored in the variable ret, which indicates whether the conversion was successful or not.

A loop iterates three times, and during each iteration, the value of readin is assigned to the tx_mgmt_pkt_need_ack_num_retx_fail array within the priv structure. This effectively sets the same retransmission failure count for three different indices in the array.

Finally, the function returns either the conversion result (ret) if it is non-zero, indicating an error, or the length of the input data (len) if the operation was successful.

Note: It is important to ensure that the input data in buf is a valid string representation of a number before calling this function, as invalid input may lead to unexpected behavior or errors.

Output Example: If the input buffer contains the string "5" and the conversion is successful, the function will store the value 5 in all three indices of the tx_mgmt_pkt_need_ack_num_retx_fail array, and the return value will be the length of the input string, which is 1.

graph TD
    A[Start function tx_mgmt_pkt_need_ack_num_retx_fail_store] --> B[Convert input_dev to platform_device]
    B --> C[Get ieee80211_hw from platform_device]
    C --> D[Access private data from ieee80211_hw]
    D --> E[Convert buf to long value]
    E --> F[Check conversion result]
    F -->|Success| G[Loop through 3 iterations]
    G --> H[Store readin in tx_mgmt_pkt_need_ack_num_retx_fail array]
    H --> G
    G -->|End of loop| I[Return ret or len]
    F -->|Failure| I
    I --> J[End function]

Function tx_data_pkt_mcs_realtime_show(struct device input_dev, struct device_attribute attr, char *buf)

tx_data_pkt_mcs_realtime_show: The function of tx_data_pkt_mcs_realtime_show is to retrieve and format the current transmission data packet MCS (Modulation and Coding Scheme) rate for display.

parameters: The parameters of this Function. · input_dev: A pointer to the device structure representing the input device. · attr: A pointer to the device attribute structure that represents the attribute being accessed. · buf: A pointer to a character buffer where the formatted output will be stored.

Code Description: The tx_data_pkt_mcs_realtime_show function is designed to provide real-time information about the transmission data packet MCS rate of a wireless device. It begins by converting the input device pointer into a platform device pointer using the to_platform_device function. This allows the function to access device-specific data.

Next, it retrieves the hardware structure associated with the device by calling platform_get_drvdata, which returns a pointer to the ieee80211_hw structure. This structure contains a private data field, priv, which holds various statistics and configurations related to the wireless device.

The function then checks if the high-throughput (HT) rate is being used by examining the most significant bit of the tx_data_pkt_mcs_realtime value stored in priv->stat. If this bit is set (indicating the use of HT rates), the variable use_ht_rate is set to true; otherwise, it is set to false. The actual rate hardware value is extracted by masking the tx_data_pkt_mcs_realtime value with 0x7fffffff.

Finally, the function formats the output string using sprintf, where it writes the corresponding MCS rate into the provided buffer. If use_ht_rate is false, it retrieves the rate from the wifi_rate_all array using the rate_hw_value as an index. If use_ht_rate is true, it adds 12 to the rate_hw_value to access the appropriate HT rate in the wifi_rate_all array. The formatted output includes the rate followed by an "M" to denote megabits per second, and a newline character is appended.

Note: It is important to ensure that the buffer provided to the function is large enough to hold the formatted output to avoid buffer overflows. The function assumes that the wifi_rate_all array is properly initialized and populated with valid rate values.

Output Example: A possible appearance of the code's return value could be "54M\n" if the transmission data packet MCS rate corresponds to a value of 54 megabits per second.

graph TD
    A[Start] --> B[Get platform device from input_dev]
    B --> C[Get ieee80211_hw from platform device]
    C --> D[Get openwifi_priv from ieee80211_hw]
    D --> E[Check if use_ht_rate is true]
    E -->|Yes| F[Calculate rate_hw_value with HT rate adjustment]
    E -->|No| G[Calculate rate_hw_value without HT rate adjustment]
    F --> H[Format output string with rate_hw_value]
    G --> H
    H --> I[Return formatted string]
    I --> J[End]

Function tx_data_pkt_mcs_realtime_store(struct device input_dev, struct device_attribute attr, const char *buf, size_t len)

tx_data_pkt_mcs_realtime_store: The function of tx_data_pkt_mcs_realtime_store is to store the real-time transmission data packet MCS (Modulation and Coding Scheme) value into the device's private structure.

parameters: The parameters of this Function. · input_dev: A pointer to the device structure representing the input device. · attr: A pointer to the device attribute structure associated with the input device. · buf: A pointer to a character buffer containing the data to be stored. · len: The length of the data in the buffer.

Code Description: The tx_data_pkt_mcs_realtime_store function is a static function that handles the storage of real-time transmission data packet MCS values for a specific device. It takes four parameters: a device pointer (input_dev), a device attribute pointer (attr), a buffer containing the data (buf), and the length of the buffer (len).

  1. The function begins by converting the input device pointer to a platform device pointer using the to_platform_device macro. This allows access to platform-specific data associated with the device.
  2. Next, it retrieves the hardware structure (ieee80211_hw) associated with the platform device by calling platform_get_drvdata. This structure contains the private data for the device, which is accessed through the priv member.
  3. The function then declares a long variable named readin and attempts to convert the string in the buffer (buf) to a long integer using kstrtol. The conversion is based on base 10, and the result is stored in readin. The return value of kstrtol is stored in the variable ret, which indicates whether the conversion was successful.
  4. The converted value (readin) is then assigned to the tx_data_pkt_mcs_realtime member of the private structure (priv->stat). This effectively updates the real-time MCS value for the device.
  5. Finally, the function returns either the value of ret (indicating an error if the conversion failed) or the length of the input data (len) if the operation was successful.

Note: It is important to ensure that the input data in the buffer is a valid representation of a long integer before calling this function, as invalid data can lead to conversion errors. The function is designed to handle such errors gracefully by returning the appropriate error code.

Output Example: If the input buffer contains the string "5" and the conversion is successful, the function will return the length of the input data, which is 1. If the input buffer contains an invalid string, such as "abc", the function will return a non-zero error code indicating the failure of the conversion.

graph TD
    A[Start function tx_data_pkt_mcs_realtime_store] --> B[Get platform device from input_dev]
    B --> C[Get ieee80211_hw from platform device]
    C --> D[Get openwifi_priv from ieee80211_hw]
    D --> E[Convert buf to long using kstrtol]
    E --> F[Store readin in priv->stat.tx_data_pkt_mcs_realtime]
    F --> G[Check if ret is non-zero]
    G -->|Yes| H[Return ret]
    G -->|No| I[Return len]
    H --> J[End function]
    I --> J

Function tx_mgmt_pkt_mcs_realtime_show(struct device input_dev, struct device_attribute attr, char *buf)

tx_mgmt_pkt_mcs_realtime_show: The function of tx_mgmt_pkt_mcs_realtime_show is to retrieve and format the real-time transmission rate of management packets in a specific format for display.

parameters: The parameters of this Function. · input_dev: A pointer to the device structure representing the input device from which the function is called. · attr: A pointer to the device attribute structure that represents the attribute being accessed. · buf: A pointer to a character buffer where the formatted output will be stored.

Code Description: The tx_mgmt_pkt_mcs_realtime_show function is designed to provide the real-time transmission rate of management packets for a specific device. It begins by converting the input device pointer to a platform_device structure, which allows access to device-specific data. The function then retrieves the hardware data associated with the device using platform_get_drvdata, which returns a pointer to the ieee80211_hw structure. This structure contains a pointer to the openwifi_priv structure, which holds various statistics related to the device's operation.

The function checks if the transmission rate is using HT (High Throughput) rates by examining the most significant bit of the tx_mgmt_pkt_mcs_realtime field in the priv->stat structure. If this bit is set, it indicates that HT rates are in use. The actual rate value is extracted by masking the tx_mgmt_pkt_mcs_realtime field with 0x7fffffff, which effectively removes the HT indicator bit.

Finally, the function formats the output string using sprintf, where it writes the transmission rate in megabits per second (M) to the provided buffer. If HT rates are not in use, it retrieves the rate from the wifi_rate_all array using the rate_hw_value as an index. If HT rates are in use, it adds 12 to the index to access the appropriate value in the wifi_rate_all array.

Note: It is important to ensure that the buffer provided to the function is large enough to hold the formatted output to prevent buffer overflows. Additionally, the function assumes that the wifi_rate_all array is properly populated with valid rate values.

Output Example: A possible appearance of the code's return value could be "54M\n", indicating a transmission rate of 54 megabits per second.

graph TD
    A[Start] --> B[Get platform device from input device]
    B --> C[Get driver data from platform device]
    C --> D[Get private data from driver]
    D --> E[Check if using HT rate]
    E --> F{Is use HT rate true?}
    F -- Yes --> G[Get rate hardware value with offset]
    F -- No --> H[Get rate hardware value without offset]
    G --> I[Format output string with rate]
    H --> I
    I --> J[Return formatted output string]
    J --> K[End]

Function tx_mgmt_pkt_mcs_realtime_store(struct device input_dev, struct device_attribute attr, const char *buf, size_t len)

tx_mgmt_pkt_mcs_realtime_store: The function of tx_mgmt_pkt_mcs_realtime_store is to store the real-time transmission statistics of management packets in the device's private data structure.

parameters: The parameters of this Function. · input_dev: A pointer to the device structure representing the input device. · attr: A pointer to the device attribute structure associated with the attribute being written to. · buf: A pointer to the buffer containing the data to be written. · len: The length of the data in the buffer.

Code Description: The tx_mgmt_pkt_mcs_realtime_store function is a static function designed to handle the storage of real-time transmission statistics for management packets in a specific device. It takes in several parameters, including a device pointer, an attribute pointer, a buffer containing the data to be stored, and the length of that data.

The function begins by converting the input device pointer to a platform device pointer using the to_platform_device macro. This allows access to platform-specific data associated with the device. Next, it retrieves the hardware structure associated with the device by calling platform_get_drvdata, which provides access to the device's driver data.

The function then accesses the private data structure of the device, which contains various statistics, including the transmission statistics for management packets. It reads the input data from the buffer (buf) and attempts to convert it from a string to a long integer using the kstrtol function. The conversion result is stored in the variable readin, and the return value of kstrtol is stored in ret, indicating whether the conversion was successful.

If the conversion is successful (ret is 0), the function updates the tx_mgmt_pkt_mcs_realtime field in the private structure with the value of readin. Finally, the function returns the length of the data written (len) if the conversion was successful; otherwise, it returns the error code stored in ret.

Note: It is important to ensure that the input data in the buffer is a valid string representation of a long integer to avoid conversion errors. The function assumes that the caller has handled any necessary synchronization when accessing the private data structure.

Output Example: If the input buffer contains the string "42" and the conversion is successful, the function will update the tx_mgmt_pkt_mcs_realtime field to 42 and return the length of the input string, which is 2. If the input buffer contains an invalid string, the function will return an error code indicating the failure of the conversion.

graph TD
    A[Start function tx_mgmt_pkt_mcs_realtime_store] --> B[Convert input_dev to platform_device]
    B --> C[Get ieee80211_hw from platform_device]
    C --> D[Access private data from ieee80211_hw]
    D --> E[Convert input buffer to long value]
    E --> F[Store converted value in priv->stat.tx_mgmt_pkt_mcs_realtime]
    F --> G[Check if conversion was successful]
    G -->|Success| H[Return length of input buffer]
    G -->|Failure| I[Return conversion error code]
    H --> J[End function]
    I --> J

Function tx_mgmt_pkt_fail_mcs_realtime_show(struct device input_dev, struct device_attribute attr, char *buf)

tx_mgmt_pkt_fail_mcs_realtime_show: The function of tx_mgmt_pkt_fail_mcs_realtime_show is to retrieve and format the real-time statistics of transmission management packet failures based on the modulation and coding scheme (MCS).

parameters: The parameters of this Function. · input_dev: A pointer to the device structure representing the input device for which the statistics are being retrieved. · attr: A pointer to the device attribute structure associated with the device. · buf: A pointer to a character buffer where the formatted output will be stored.

Code Description: The tx_mgmt_pkt_fail_mcs_realtime_show function is a static function that is designed to be called when the system needs to display the real-time statistics of transmission management packet failures for a specific device.

  1. The function begins by converting the input device pointer (input_dev) to a platform device structure (pdev) using the to_platform_device function. This allows access to platform-specific data associated with the device.
  2. Next, it retrieves the hardware structure (dev) associated with the platform device by calling platform_get_drvdata, which returns a pointer to the driver data.
  3. The function then accesses the private data structure (priv) from the hardware structure, which contains various statistics and configurations.
  4. It checks if the high-throughput (HT) rate is being used by examining the most significant bit of the tx_mgmt_pkt_fail_mcs_realtime field in the statistics structure. If this bit is set, it indicates that HT rates are in use.
  5. The function extracts the hardware rate value by masking the tx_mgmt_pkt_fail_mcs_realtime field to obtain the lower 31 bits.
  6. Finally, the function formats the output string into the provided buffer (buf) using sprintf. It returns the formatted transmission rate in megabits per second (M) based on whether HT rates are used or not. If HT rates are not used, it retrieves the rate from the wifi_rate_all array directly; if HT rates are used, it offsets the rate by 12 to access the appropriate value in the array.

Note: It is important to ensure that the buffer provided to the function is large enough to hold the formatted output to avoid buffer overflows. The function assumes that the wifi_rate_all array is properly populated with valid rate values.

Output Example: A possible appearance of the code's return value could be "54M\n" if the transmission rate corresponds to 54 megabits per second.

graph TD
    A[Start function tx_mgmt_pkt_fail_mcs_realtime_show] --> B[Get platform device from input_dev]
    B --> C[Get ieee80211_hw from platform device]
    C --> D[Get openwifi_priv from ieee80211_hw]
    D --> E[Check if use_ht_rate is true]
    E -->|True| F[Calculate rate_hw_value with HT rate adjustment]
    E -->|False| G[Calculate rate_hw_value without HT rate adjustment]
    F --> H[Return formatted string with HT rate]
    G --> H[Return formatted string without HT rate]
    H --> I[End function]

Function tx_mgmt_pkt_fail_mcs_realtime_store(struct device input_dev, struct device_attribute attr, const char *buf, size_t len)

tx_mgmt_pkt_fail_mcs_realtime_store: The function of tx_mgmt_pkt_fail_mcs_realtime_store is to store the real-time count of failed management packets at a specific MCS (Modulation and Coding Scheme) level.

parameters: The parameters of this Function. · input_dev: A pointer to the device structure representing the input device.
· attr: A pointer to the device attribute structure associated with the input device.
· buf: A pointer to a character buffer that contains the data to be stored, typically a string representation of a number.
· len: The length of the data in the buffer.

Code Description: The function tx_mgmt_pkt_fail_mcs_realtime_store is designed to handle the storage of real-time statistics related to the failure of transmission management packets at a specific MCS level.

  1. The function begins by converting the input device pointer input_dev to a platform device pointer pdev using the to_platform_device macro. This is essential for accessing platform-specific data associated with the device.

  2. Next, it retrieves the hardware structure dev associated with the platform device by calling platform_get_drvdata(pdev). This structure contains various driver-specific data, including a pointer to the private data structure priv.

  3. The private data structure priv is accessed through the dev structure, which holds the statistics for the device.

  4. The function then declares a variable readin of type long to store the converted value from the input buffer. It uses the kstrtol function to convert the string in buf to a long integer. The conversion is performed in base 10, and the result is stored in readin. The return value of kstrtol is stored in ret, which indicates whether the conversion was successful.

  5. If the conversion is successful, the function assigns the value of readin to priv->stat.tx_mgmt_pkt_fail_mcs_realtime, effectively updating the real-time count of failed management packets.

  6. Finally, the function returns the result of the conversion. If the conversion was successful (ret is 0), it returns the length of the input data len. If there was an error during conversion, it returns the error code stored in ret.

Note: It is important to ensure that the input buffer buf contains a valid string representation of a number before calling this function to avoid conversion errors. The function is expected to be called in a context where the device is properly initialized and the private data structure is correctly set up.

Output Example: If the input buffer buf contains the string "5" and the conversion is successful, the function will update the real-time count of failed management packets to 5 and return the length of the input string, which is 1. If the input buffer contains an invalid string, the function will return an error code indicating the failure of the conversion.

graph TD
    A[Start function tx_mgmt_pkt_fail_mcs_realtime_store] --> B[Convert input_dev to platform_device]
    B --> C[Get ieee80211_hw from platform_device]
    C --> D[Access private data from ieee80211_hw]
    D --> E[Convert buf to long integer]
    E --> F[Store readin in tx_mgmt_pkt_fail_mcs_realtime]
    F --> G[Check if conversion was successful]
    G -->|Success| H[Return length of input]
    G -->|Failure| I[Return error code]
    H --> J[End function]
    I --> J

Function tx_data_pkt_fail_mcs_realtime_show(struct device input_dev, struct device_attribute attr, char *buf)

tx_data_pkt_fail_mcs_realtime_show: The function of tx_data_pkt_fail_mcs_realtime_show is to retrieve and format the real-time statistics of transmission data packet failures based on the modulation and coding scheme (MCS).

parameters: The parameters of this Function. · input_dev: A pointer to the device structure representing the input device for which the statistics are being retrieved. · attr: A pointer to the device attribute structure, which is not used in this function but is required for the function signature. · buf: A pointer to a character buffer where the formatted output will be stored.

Code Description: The tx_data_pkt_fail_mcs_realtime_show function is a static function that returns the number of transmission data packet failures based on the modulation and coding scheme in a formatted string. It first converts the input device pointer to a platform device structure using the to_platform_device function. Then, it retrieves the hardware structure associated with the platform device using platform_get_drvdata. The function accesses the private data structure of the device, which contains the statistics of transmission data packet failures.

The function checks if the high-order bit of the tx_data_pkt_fail_mcs_realtime field is set, indicating whether to use high-throughput (HT) rates. It extracts the hardware rate value by masking the high-order bit. The function then formats the output string based on whether HT rates are used or not. If HT rates are not used, it retrieves the corresponding rate from the wifi_rate_all array using the hardware value as an index. If HT rates are used, it adds 12 to the hardware value to access the appropriate index in the wifi_rate_all array. Finally, the formatted string is returned, which includes the rate followed by an "M" character and a newline.

Note: It is important to ensure that the wifi_rate_all array is properly defined and populated with valid rate values to avoid incorrect output. Additionally, this function is intended to be used in a context where it is called to display statistics, typically in a sysfs interface.

Output Example: An example of the possible appearance of the code's return value could be "54M\n", indicating that the transmission data packet failure rate corresponds to a value of 54 Mbps.

graph TD
    A[Start] --> B[Get platform device from input_dev]
    B --> C[Get ieee80211_hw from platform device]
    C --> D[Get openwifi_priv from ieee80211_hw]
    D --> E[Check if use_ht_rate is true]
    E -->|True| F[Calculate rate_hw_value with offset]
    E -->|False| G[Calculate rate_hw_value without offset]
    F --> H[Return formatted string with rate_hw_value + 12]
    G --> H[Return formatted string with rate_hw_value]
    H --> I[End]

Function tx_data_pkt_fail_mcs_realtime_store(struct device input_dev, struct device_attribute attr, const char *buf, size_t len)

tx_data_pkt_fail_mcs_realtime_store: The function of tx_data_pkt_fail_mcs_realtime_store is to store the real-time failure count of transmitted data packets at the MCS (Modulation and Coding Scheme) level.

parameters: The parameters of this Function. · parameter1: struct device input_dev - A pointer to the device structure representing the input device. · parameter2: struct device_attribute attr - A pointer to the device attribute structure that represents the attribute being accessed. · parameter3: const char *buf - A pointer to a buffer containing the data to be stored, typically a string representation of a number. · parameter4: size_t len - The length of the data in the buffer.

Code Description: The tx_data_pkt_fail_mcs_realtime_store function is defined as a static function that takes four parameters. It begins by converting the input device pointer to a platform device pointer using the to_platform_device macro. This allows access to platform-specific data associated with the device. Next, it retrieves the hardware structure associated with the device using the platform_get_drvdata function, which provides access to the device's driver data.

The function then accesses the private data structure associated with the hardware, which is expected to contain various statistics, including the transmission failure count. It declares a variable named readin to hold the converted value from the input buffer. The kstrtol function is used to convert the string in buf to a long integer, storing the result in readin and returning an error code in ret if the conversion fails.

Subsequently, the function updates the tx_data_pkt_fail_mcs_realtime field of the private structure with the value stored in readin, effectively recording the real-time failure count of transmitted data packets.

Finally, the function returns either the error code (if ret is non-zero) or the length of the input data (len) if the operation was successful. This return value indicates the outcome of the operation, allowing the caller to handle any errors appropriately.

Note: It is important to ensure that the input buffer contains a valid string representation of a number before calling this function to avoid conversion errors. The function assumes that the private data structure has been properly initialized and that the tx_data_pkt_fail_mcs_realtime field is accessible.

Output Example: If the input buffer contains the string "5" and the conversion is successful, the function will update the tx_data_pkt_fail_mcs_realtime field to 5 and return the length of the input string, which would be 1 in this case. If the input buffer contains an invalid string, the function will return an error code indicating the failure of the conversion.

graph TD
    A[Start] --> B[Get platform device from input device]
    B --> C[Get driver data from platform device]
    C --> D[Get private data from hardware structure]
    D --> E[Convert input buffer to long integer]
    E --> F[Store value in tx_data_pkt_fail_mcs_realtime]
    F --> G[Return result based on conversion success]
    G --> H[End]

Function rx_target_sender_mac_addr_show(struct device input_dev, struct device_attribute attr, char *buf)

rx_target_sender_mac_addr_show: The function of rx_target_sender_mac_addr_show is to retrieve and display the reversed MAC address of the target sender in a formatted string.

parameters: The parameters of this Function. · input_dev: A pointer to the device structure representing the input device. · attr: A pointer to the device attribute structure associated with the device. · buf: A pointer to a character buffer where the output string will be stored.

Code Description: The rx_target_sender_mac_addr_show function is a static function designed to be used in the context of a device attribute show operation. It takes three parameters: a pointer to the input device (input_dev), a pointer to the device attribute (attr), and a character buffer (buf) where the output will be written.

The function begins by converting the input device pointer to a platform device pointer using the to_platform_device macro. This is necessary because the function is intended to work with platform devices specifically. Next, it retrieves the driver data associated with the platform device by calling platform_get_drvdata, which returns a pointer to the ieee80211_hw structure. This structure contains a private data pointer (priv) that points to an instance of openwifi_priv, which holds various statistics and configuration data related to the device.

The function then accesses the rx_target_sender_mac_addr field from the priv structure, which contains the MAC address of the target sender. Before returning this address, the function applies the reverse32 function to the MAC address, which presumably reverses the byte order of the address. Finally, the function formats the reversed MAC address as an eight-digit hexadecimal string and writes it to the provided buffer (buf) using the sprintf function, appending a newline character at the end.

The return value of the function is the number of bytes written to the buffer, which is the length of the formatted string.

Note: It is important to ensure that the buffer provided to the function is large enough to hold the formatted string, including the newline character. The function assumes that the reverse32 function is correctly implemented and that the priv structure is properly initialized before this function is called.

Output Example: An example of the output returned by this function could be "1a2b3c4d\n", where "1a2b3c4d" represents the reversed MAC address in hexadecimal format.

graph TD
    A[Start] --> B[Receive input device and attribute]
    B --> C[Convert input device to platform device]
    C --> D[Get driver data from platform device]
    D --> E[Access private data structure]
    E --> F[Reverse MAC address]
    F --> G[Format MAC address into buffer]
    G --> H[Return formatted MAC address]
    H --> I[End]

Function rx_target_sender_mac_addr_store(struct device input_dev, struct device_attribute attr, const char *buf, size_t len)

rx_target_sender_mac_addr_store: The function of rx_target_sender_mac_addr_store is to store the MAC address of the target sender in a specific format after converting it from a string input.

parameters: The parameters of this Function. · parameter1: struct device input_dev - A pointer to the device structure representing the input device. · parameter2: struct device_attribute attr - A pointer to the device attribute structure associated with the input device. · parameter3: const char *buf - A pointer to the input buffer containing the MAC address in string format. · parameter4: size_t len - The length of the input buffer.

Code Description: The rx_target_sender_mac_addr_store function is designed to handle the storage of a MAC address for a specific target sender. It begins by converting the input device pointer to a platform device pointer using the to_platform_device function. This allows access to the platform-specific data associated with the device. Next, it retrieves the hardware structure (ieee80211_hw) linked to the platform device using platform_get_drvdata, which provides access to the driver data.

The function then accesses the private data structure (openwifi_priv) associated with the hardware structure. This private structure contains various statistics and configurations, including the target sender MAC address.

The input buffer (buf) is expected to contain a hexadecimal representation of a MAC address. The function uses kstrtouint to convert this string into an unsigned integer (readin) in base 16. The conversion result is stored in the variable ret, which indicates whether the conversion was successful (0) or not (non-zero).

If the conversion is successful, the function calls reverse32 to reverse the byte order of the readin value, which is then stored in the rx_target_sender_mac_addr field of the private structure. Finally, the function returns the length of the input buffer if the conversion was successful; otherwise, it returns the error code from the conversion.

Note: It is important to ensure that the input buffer contains a valid hexadecimal representation of a MAC address. If the input is invalid, the function will return an error code, and the MAC address will not be updated.

Output Example: If the input buffer contains the string "AABBCCDDEE", the function will convert this to an unsigned integer, reverse the byte order, and store it in the rx_target_sender_mac_addr field. If the conversion is successful, the function will return the length of the input buffer, which is 10 in this case.

graph TD
    A[Start] --> B[Get platform device from input_dev]
    B --> C[Get ieee80211_hw from platform device]
    C --> D[Get openwifi_priv from ieee80211_hw]
    D --> E[Convert input buffer to unsigned integer]
    E --> F{Conversion successful?}
    F -->|Yes| G[Reverse the 32-bit integer]
    F -->|No| H[Return conversion error code]
    G --> I[Store reversed value in rx_target_sender_mac_addr]
    I --> J[Return length of input buffer]
    H --> J
    J --> K[End]

Function rx_data_ok_agc_gain_value_realtime_show(struct device input_dev, struct device_attribute attr, char *buf)

rx_data_ok_agc_gain_value_realtime_show: The function of rx_data_ok_agc_gain_value_realtime_show is to retrieve and display the real-time AGC gain value for received data packets.

parameters: The parameters of this Function. · input_dev: A pointer to the device structure representing the input device from which data is being retrieved. · attr: A pointer to the device attribute structure that represents the specific attribute being accessed. · buf: A pointer to a character buffer where the output string will be stored.

Code Description: The function rx_data_ok_agc_gain_value_realtime_show is defined as a static function that returns a ssize_t value, which is typically used for representing the size of data being written or read. The function takes three parameters: a pointer to a device structure (input_dev), a pointer to a device attribute structure (attr), and a character buffer (buf) for output.

Inside the function, the first step is to convert the input device pointer (input_dev) to a platform device pointer (pdev) using the helper function to_platform_device. This conversion is necessary because the function needs to access platform-specific data associated with the device.

Next, the function retrieves the hardware structure (dev) associated with the platform device by calling platform_get_drvdata, which returns a pointer to the driver data stored in the platform device. This driver data is expected to contain a pointer to the private data structure (priv) of type openwifi_priv, which holds various statistics and configuration parameters for the device.

The function then accesses the real-time AGC gain value for received data packets from the private data structure using priv->stat.rx_data_ok_agc_gain_value_realtime. This value is then formatted as an unsigned integer and written into the provided buffer (buf) using the sprintf function, followed by a newline character.

Finally, the function returns the number of bytes written to the buffer, which is the return value of sprintf.

Note: It is important to ensure that the buffer provided to the function is large enough to hold the formatted string, including the newline character, to avoid buffer overflows. Additionally, this function is typically called in the context of a sysfs interface, allowing user-space applications to read the real-time AGC gain value through the appropriate sysfs entry.

Output Example: A possible appearance of the code's return value could be "42\n", where "42" represents the real-time AGC gain value for received data packets.

graph TD
    A[Start function rx_data_ok_agc_gain_value_realtime_show] --> B[Get platform device from input device]
    B --> C[Get ieee80211 hardware from platform device]
    C --> D[Get openwifi_priv structure from ieee80211 hardware]
    D --> E[Retrieve rx_data_ok_agc_gain_value_realtime from priv structure]
    E --> F[Format value into buffer]
    F --> G[Return formatted buffer]
    G --> H[End function]

Function rx_data_ok_agc_gain_value_realtime_store(struct device input_dev, struct device_attribute attr, const char *buf, size_t len)

rx_data_ok_agc_gain_value_realtime_store: The function of rx_data_ok_agc_gain_value_realtime_store is to store the real-time AGC gain value received from user input into the device's private data structure.

parameters: The parameters of this Function. · input_dev: A pointer to the device structure representing the input device. · attr: A pointer to the device attribute structure associated with the input device. · buf: A pointer to a character buffer containing the input data to be processed. · len: The length of the input data in the buffer.

Code Description: The rx_data_ok_agc_gain_value_realtime_store function is a static function that handles the storage of a real-time AGC (Automatic Gain Control) gain value for a device. It begins by converting the input device pointer (input_dev) to a platform device pointer (pdev) using the to_platform_device function. This is necessary to access the platform-specific data associated with the device.

Next, the function retrieves the hardware structure (dev) associated with the platform device by calling platform_get_drvdata, which allows access to the device's driver data. The private data structure (priv) of the device is then accessed through the ieee80211_hw structure, which contains various statistics and parameters related to the device's operation.

The function reads the input data from the buf parameter, which is expected to be a string representation of a long integer. The kstrtol function is used to convert this string to a long integer (readin). The conversion also returns a status code (ret) that indicates whether the conversion was successful or not.

If the conversion is successful, the real-time AGC gain value is stored in the priv structure's stat member, specifically in the rx_data_ok_agc_gain_value_realtime field. This effectively updates the device's statistics with the new AGC gain value.

Finally, the function returns the length of the input data (len) if the conversion was successful (ret is zero). If there was an error during conversion, it returns the error code (ret) instead.

Note: It is important to ensure that the input data provided in buf is a valid string representation of a long integer. Invalid input may lead to an unsuccessful conversion and an error return value.

Output Example: If the input buffer (buf) contains the string "25" and the length (len) is 2, the function will successfully convert this to a long integer and store the value 25 in the device's private data structure. The return value will be 2, indicating the length of the input data processed.

graph TD
    A[Start function rx_data_ok_agc_gain_value_realtime_store] --> B[Convert input device to platform device]
    B --> C[Get driver data from platform device]
    C --> D[Access private data structure from hardware]
    D --> E[Convert input buffer to long integer]
    E --> F[Store read value in private structure]
    F --> G[Check if conversion was successful]
    G -->|Success| H[Return length of input buffer]
    G -->|Failure| I[Return conversion error code]
    H --> J[End function]
    I --> J

Function rx_mgmt_ok_agc_gain_value_realtime_show(struct device input_dev, struct device_attribute attr, char *buf)

rx_mgmt_ok_agc_gain_value_realtime_show: The function of rx_mgmt_ok_agc_gain_value_realtime_show is to retrieve and display the real-time value of the received management OK AGC gain.

parameters: The parameters of this Function. · input_dev: A pointer to the device structure representing the input device. · attr: A pointer to the device attribute structure associated with the device. · buf: A pointer to the buffer where the output string will be stored.

Code Description: The function rx_mgmt_ok_agc_gain_value_realtime_show is defined as a static function that returns a ssize_t value. It takes three parameters: a pointer to a device structure (input_dev), a pointer to a device attribute structure (attr), and a character pointer (buf) that serves as a buffer for the output.

Inside the function, the input device is first converted to a platform device using the to_platform_device macro. This allows access to platform-specific data associated with the device. The function then retrieves the driver data associated with the platform device by calling platform_get_drvdata, which returns a pointer to the ieee80211_hw structure. This structure contains a pointer to the openwifi_priv structure, which holds various private data for the driver.

The function then accesses the real-time value of the received management OK AGC gain from the priv structure, specifically from the stat member, and formats this value as an unsigned integer into the provided buffer (buf) using the sprintf function. The formatted string is followed by a newline character. Finally, the function returns the number of bytes written to the buffer, which is the return value of sprintf.

Note: It is important to ensure that the buffer provided to this function is large enough to hold the formatted output to avoid buffer overflows. The function is designed to be used in the context of a sysfs interface, allowing users to read the AGC gain value through the filesystem.

Output Example: A possible appearance of the code's return value could be:

42
This indicates that the real-time value of the received management OK AGC gain is 42.

graph TD
    A[Start] --> B[Receive input device and attribute]
    B --> C[Convert input device to platform device]
    C --> D[Get driver data from platform device]
    D --> E[Access private structure from driver data]
    E --> F[Retrieve rx_mgmt_ok_agc_gain_value_realtime]
    F --> G[Format value into buffer]
    G --> H[Return formatted buffer]
    H --> I[End]

Function rx_mgmt_ok_agc_gain_value_realtime_store(struct device input_dev, struct device_attribute attr, const char *buf, size_t len)

rx_mgmt_ok_agc_gain_value_realtime_store: The function of rx_mgmt_ok_agc_gain_value_realtime_store is to store the real-time AGC gain value for received management frames.

parameters: The parameters of this Function. · input_dev: A pointer to the device structure representing the input device. · attr: A pointer to the device attribute structure associated with the input device. · buf: A pointer to a character buffer containing the input data to be processed. · len: The length of the input data in the buffer.

Code Description: The rx_mgmt_ok_agc_gain_value_realtime_store function is a static function that handles the storage of a real-time AGC (Automatic Gain Control) gain value for received management frames in a wireless device. The function takes four parameters: a device pointer (input_dev), a device attribute pointer (attr), a character buffer (buf) containing the input data, and the length of that data (len).

The function begins by converting the input device pointer to a platform device pointer using the to_platform_device macro. This allows access to platform-specific data associated with the device. Next, it retrieves the ieee80211_hw structure associated with the platform device by calling platform_get_drvdata, which provides access to the device's private data.

The function then declares a long variable named readin to store the converted input value. It uses the kstrtol function to convert the string in the buf parameter to a long integer, storing the result in readin. The conversion is done in base 10, and the return value of kstrtol is stored in the u32 variable ret, which indicates whether the conversion was successful.

If the conversion is successful (ret is 0), the function updates the rx_mgmt_ok_agc_gain_value_realtime field of the openwifi_priv structure (priv) with the newly read value. This field is presumably used to keep track of the current AGC gain value for received management frames.

Finally, the function returns either the result of the conversion (ret) if it indicates an error, or the length of the input data (len) if the operation was successful. This return value is important for the sysfs interface, as it indicates to the user space how much data was processed.

Note: It is important to ensure that the input data in buf is a valid representation of a long integer to avoid conversion errors. The function assumes that the input will be in a valid format; otherwise, it will return an error code.

Output Example: If the input buffer contains the string "15" and the conversion is successful, the function will update the AGC gain value and return the length of the input data, which would be 2 in this case. If the input buffer contains an invalid string, such as "abc", the function will return a non-zero error code indicating the failure of the conversion.

graph TD
    A[Start] --> B[Get platform device from input device]
    B --> C[Get driver data from platform device]
    C --> D[Get private data from device]
    D --> E[Convert input buffer to long value]
    E --> F[Store value in rx_mgmt_ok_agc_gain_value_realtime]
    F --> G[Return result based on conversion status]
    G --> H[End]

Function rx_data_fail_agc_gain_value_realtime_show(struct device input_dev, struct device_attribute attr, char *buf)

rx_data_fail_agc_gain_value_realtime_show: The function of rx_data_fail_agc_gain_value_realtime_show is to retrieve and display the real-time value of the AGC gain associated with failed received data packets.

parameters: The parameters of this Function. · input_dev: A pointer to the device structure representing the input device from which the data is being retrieved. · attr: A pointer to the device attribute structure that represents the specific attribute being accessed. · buf: A pointer to a character buffer where the output string will be stored.

Code Description: The rx_data_fail_agc_gain_value_realtime_show function is designed to provide a way to read the real-time AGC (Automatic Gain Control) gain value for received data packets that have failed. The function is defined as a static function, meaning it is only accessible within the file it is declared in.

The function begins by converting the input device pointer (input_dev) to a platform device pointer (pdev) using the to_platform_device macro. This conversion is necessary because the function needs to access platform-specific data associated with the device.

Next, the function retrieves the hardware structure (dev) associated with the platform device by calling platform_get_drvdata, which returns a pointer to the driver data stored in the platform device. This driver data is expected to contain a pointer to the private data structure (priv) of type openwifi_priv.

Within the openwifi_priv structure, the function accesses the stat member, which contains statistics related to the device's operation. Specifically, it retrieves the real-time value of the AGC gain for failed received data packets through the rx_data_fail_agc_gain_value_realtime member.

Finally, the function formats this value as an unsigned integer and writes it to the provided buffer (buf) using the sprintf function, appending a newline character at the end. The function returns the number of bytes written to the buffer, which is the return value of sprintf.

Note: It is important to ensure that the buffer provided to the function is large enough to hold the formatted string, including the newline character. The function is typically used in conjunction with sysfs, allowing user-space applications to read the AGC gain value through the filesystem interface.

Output Example: A possible appearance of the code's return value could be:

42
This indicates that the real-time AGC gain value for failed received data packets is 42.

graph TD
    A[Start] --> B[Receive input device and attribute]
    B --> C[Convert input device to platform device]
    C --> D[Get driver data from platform device]
    D --> E[Access private structure from device]
    E --> F[Retrieve rx_data_fail_agc_gain_value_realtime]
    F --> G[Format value into buffer]
    G --> H[Return formatted buffer]
    H --> I[End]

Function rx_data_fail_agc_gain_value_realtime_store(struct device input_dev, struct device_attribute attr, const char *buf, size_t len)

rx_data_fail_agc_gain_value_realtime_store: The function of rx_data_fail_agc_gain_value_realtime_store is to store the real-time value of the received data failure AGC gain from user input.

parameters: The parameters of this function. · input_dev: A pointer to the device structure representing the input device. · attr: A pointer to the device attribute structure associated with the input device. · buf: A pointer to a character buffer containing the input data to be processed. · len: The length of the input data in the buffer.

Code Description: The rx_data_fail_agc_gain_value_realtime_store function is a static function that handles the storage of a real-time AGC (Automatic Gain Control) gain value related to received data failures. It takes four parameters: a device pointer (input_dev), a device attribute pointer (attr), a character buffer (buf) containing the input data, and the length of that data (len).

The function begins by converting the input device pointer to a platform device pointer using the to_platform_device macro. This allows access to platform-specific data associated with the device. Next, it retrieves the hardware structure (ieee80211_hw) associated with the platform device by calling platform_get_drvdata, which provides access to the driver data.

The function then accesses the private data structure (openwifi_priv) associated with the hardware structure. This private structure contains various statistics, including the real-time AGC gain value for received data failures.

The input data from the buffer (buf) is converted from a string to a long integer using the kstrtol function. This function attempts to parse the string as a base-10 integer and stores the result in the variable readin. The return value of kstrtol is stored in the variable ret, which indicates whether the conversion was successful.

If the conversion is successful, the real-time AGC gain value is updated in the private structure (priv->stat.rx_data_fail_agc_gain_value_realtime) with the value stored in readin. Finally, the function returns the result of the conversion (ret) if it indicates an error; otherwise, it returns the length of the input data (len).

Note: It is important to ensure that the input data in the buffer is a valid string representation of a number before calling this function, as invalid input may lead to unexpected behavior or errors.

Output Example: If the input buffer contains the string "10" and the conversion is successful, the function will return 2 (the length of the input string) and update the real-time AGC gain value to 10. If the input buffer contains an invalid string, such as "abc", the function will return an error code indicating the failure of the conversion.

graph TD
    A[Start] --> B[Receive input parameters]
    B --> C[Convert input device to platform device]
    C --> D[Get driver data from platform device]
    D --> E[Access private structure from driver data]
    E --> F[Convert buffer to long value]
    F --> G[Store value in private structure]
    G --> H[Check conversion result]
    H -->|Success| I[Return length of input]
    H -->|Failure| J[Return conversion error]
    I --> K[End]
    J --> K

Function rx_mgmt_fail_agc_gain_value_realtime_show(struct device input_dev, struct device_attribute attr, char *buf)

rx_mgmt_fail_agc_gain_value_realtime_show: The function of rx_mgmt_fail_agc_gain_value_realtime_show is to retrieve and display the real-time value of the AGC gain associated with RX management failures.

parameters: The parameters of this Function. · input_dev: A pointer to the device structure representing the input device. · attr: A pointer to the device attribute structure associated with the attribute being accessed. · buf: A pointer to a character buffer where the output string will be written.

Code Description: The function rx_mgmt_fail_agc_gain_value_realtime_show is defined as a static function that returns a ssize_t value, which is typically used for representing the size of data written to or read from a buffer. The function takes three parameters: a pointer to the input device, a pointer to the device attribute, and a character buffer for output.

  1. The function begins by converting the input device pointer (input_dev) to a platform device pointer (pdev) using the helper function to_platform_device. This is necessary because the function needs to access platform-specific data associated with the device.

  2. Next, it retrieves the hardware structure (dev) associated with the platform device by calling platform_get_drvdata, which returns a pointer to the driver data stored in the platform device.

  3. The function then accesses the private data structure (priv) of the hardware device, which contains various statistics and configurations related to the device's operation.

  4. Finally, the function uses sprintf to format the real-time value of the RX management failure AGC gain, which is stored in priv->stat.rx_mgmt_fail_agc_gain_value_realtime, and writes this value to the provided buffer (buf). The value is formatted as an unsigned integer followed by a newline character.

The return value of the function is the number of bytes written to the buffer, which is the length of the formatted string.

Note: It is important to ensure that the buffer provided to the function is large enough to hold the output string, including the newline character. The function assumes that the private data structure has been properly initialized and that the RX management failure AGC gain value is valid.

Output Example: An example of the return value when the function is called could be "42\n", indicating that the real-time AGC gain value for RX management failures is 42. The function would return the number of bytes written, which in this case would be 3.

graph TD
    A[Start] --> B[Receive input device and attribute]
    B --> C[Convert input device to platform device]
    C --> D[Get driver data from platform device]
    D --> E[Access private structure from hardware device]
    E --> F[Retrieve realtime AGC gain value from private structure]
    F --> G[Format AGC gain value into buffer]
    G --> H[Return formatted buffer]
    H --> I[End]

Function rx_mgmt_fail_agc_gain_value_realtime_store(struct device input_dev, struct device_attribute attr, const char *buf, size_t len)

rx_mgmt_fail_agc_gain_value_realtime_store: The function of rx_mgmt_fail_agc_gain_value_realtime_store is to store the real-time value of the AGC gain for received management frames.

parameters: The parameters of this Function. · input_dev: A pointer to the device structure representing the input device. · attr: A pointer to the device attribute structure associated with the input device. · buf: A pointer to a buffer containing the string representation of the value to be stored. · len: The length of the buffer.

Code Description: The rx_mgmt_fail_agc_gain_value_realtime_store function is a static function that handles the storage of a real-time AGC (Automatic Gain Control) gain value for received management frames in a wireless device. The function takes four parameters: a pointer to the device structure (input_dev), a pointer to the device attribute structure (attr), a buffer containing the value to be stored (buf), and the length of that buffer (len).

The function begins by converting the input device pointer to a platform device pointer using the to_platform_device macro. It then retrieves the driver data associated with the platform device, which is a pointer to the ieee80211_hw structure. This structure contains a pointer to the private data structure (openwifi_priv) that holds various statistics and state information for the device.

Next, the function attempts to convert the string in the buffer (buf) to a long integer using the kstrtol function. The conversion is performed with a base of 10, and the result is stored in the variable readin. The return value of kstrtol is stored in the variable ret, which indicates whether the conversion was successful or not.

If the conversion is successful (ret is 0), the function assigns the converted value (readin) to the rx_mgmt_fail_agc_gain_value_realtime field of the private data structure (priv). This field is used to keep track of the real-time AGC gain value for received management frames.

Finally, the function returns either the result of the conversion (ret) if it was unsuccessful, or the length of the input buffer (len) if the conversion was successful. This return value is used to indicate the outcome of the operation to the caller.

Note: It is important to ensure that the input buffer contains a valid string representation of a number before calling this function, as invalid input may lead to conversion errors.

Output Example: If the input buffer contains the string "15" and the conversion is successful, the function will return 2 (the length of the input string) and the real-time AGC gain value will be updated to 15. If the input buffer contains an invalid string, such as "abc", the function will return a non-zero error code.

graph TD
    A[Start] --> B[Get platform device from input device]
    B --> C[Get driver data from platform device]
    C --> D[Get private data from device]
    D --> E[Convert input buffer to long value]
    E --> F[Store value in rx_mgmt_fail_agc_gain_value_realtime]
    F --> G[Return result based on conversion status]
    G --> H[End]

Function rx_ack_ok_agc_gain_value_realtime_show(struct device input_dev, struct device_attribute attr, char *buf)

rx_ack_ok_agc_gain_value_realtime_show: The function of rx_ack_ok_agc_gain_value_realtime_show is to retrieve and display the real-time AGC gain value for successfully acknowledged received packets.

parameters: The parameters of this Function. · input_dev: A pointer to the device structure representing the input device. · attr: A pointer to the device attribute structure associated with the device. · buf: A pointer to the buffer where the output string will be written.

Code Description: The function rx_ack_ok_agc_gain_value_realtime_show is defined as a static function that returns a ssize_t value. It takes three parameters: a pointer to a device structure (input_dev), a pointer to a device attribute structure (attr), and a character buffer (buf) where the output will be stored.

Inside the function, the input device is first converted to a platform device using the to_platform_device macro. This allows access to platform-specific data associated with the device. Next, the function retrieves the hardware structure (ieee80211_hw) associated with the platform device by calling platform_get_drvdata, which returns a pointer to the driver data.

From the ieee80211_hw structure, the function accesses the private data structure (openwifi_priv) through the priv member. The real-time AGC gain value for successfully acknowledged received packets is then obtained from the priv structure, specifically from the stat member, which contains the rx_ack_ok_agc_gain_value_realtime field.

Finally, the function writes this value into the provided buffer (buf) using sprintf, formatting it as an unsigned integer followed by a newline character. The return value of the function is the number of bytes written to the buffer.

Note: It is important to ensure that the buffer provided to this function is large enough to hold the formatted output to avoid buffer overflows. The function is intended to be used in a context where the device's attributes can be read, typically in a sysfs interface.

Output Example: A possible appearance of the code's return value could be "42\n", where "42" represents the real-time AGC gain value for successfully acknowledged received packets.

graph TD
    A[Start function rx_ack_ok_agc_gain_value_realtime_show] --> B[Get platform device from input_dev]
    B --> C[Retrieve driver data from platform device]
    C --> D[Access private structure from ieee80211_hw]
    D --> E[Get rx_ack_ok_agc_gain_value_realtime from private structure]
    E --> F[Format value into buffer]
    F --> G[Return formatted buffer]
    G --> H[End function]

Function rx_ack_ok_agc_gain_value_realtime_store(struct device input_dev, struct device_attribute attr, const char *buf, size_t len)

rx_ack_ok_agc_gain_value_realtime_store: The function of rx_ack_ok_agc_gain_value_realtime_store is to store the real-time value of the received acknowledgment (ACK) automatic gain control (AGC) gain.

parameters: The parameters of this Function. · input_dev: A pointer to the device structure representing the input device. · attr: A pointer to the device attribute structure associated with the device. · buf: A pointer to a character buffer containing the input data to be processed. · len: The length of the input data in the buffer.

Code Description: The rx_ack_ok_agc_gain_value_realtime_store function is a static function that handles the storage of a real-time AGC gain value for received ACKs. It takes four parameters: a device pointer (input_dev), a device attribute pointer (attr), a buffer containing the input data (buf), and the length of that data (len).

The function begins by converting the input device pointer to a platform device structure using the to_platform_device macro. This allows access to platform-specific data associated with the device. Next, it retrieves the driver data associated with the platform device, which is expected to be a pointer to an ieee80211_hw structure. This structure contains a pointer to the private data (openwifi_priv) that holds various statistics and configurations for the device.

The function then declares a long variable named readin, which will store the converted value from the input buffer. The kstrtol function is called to convert the string in buf to a long integer, storing the result in readin. The conversion is done using base 10, and the return value of kstrtol is stored in the variable ret, which indicates whether the conversion was successful.

If the conversion is successful (ret is 0), the function updates the rx_ack_ok_agc_gain_value_realtime field in the priv structure with the newly read value. Finally, the function returns either the result of the conversion (if it failed) or the length of the input data (if it succeeded). This return value is important for the sysfs interface, as it indicates the outcome of the write operation.

Note: It is important to ensure that the input data in buf is a valid string representation of a long integer. If the conversion fails, the function will return an error code, which should be handled appropriately by the caller.

Output Example: If the input buffer contains the string "25" and the conversion is successful, the function will update the corresponding field in the priv structure and return the length of the input data, which would be 2 in this case.

graph TD
    A[Start function rx_ack_ok_agc_gain_value_realtime_store] --> B[Convert input_dev to platform_device]
    B --> C[Get ieee80211_hw from platform_device]
    C --> D[Access private data from ieee80211_hw]
    D --> E[Convert buf to long using kstrtol]
    E --> F[Store readin value in rx_ack_ok_agc_gain_value_realtime]
    F --> G[Check if ret is non-zero]
    G -->|Yes| H[Return ret]
    G -->|No| I[Return len]
    H --> J[End function]
    I --> J

Function rx_monitor_all_show(struct device input_dev, struct device_attribute attr, char *buf)

rx_monitor_all_show: The function of rx_monitor_all_show is to retrieve and display the total count of received packets monitored by the device.

parameters: The parameters of this Function. · input_dev: A pointer to the device structure representing the input device for which the RX monitor statistics are being requested. · attr: A pointer to the device attribute structure that represents the attribute being accessed. · buf: A pointer to a character buffer where the output string will be written.

Code Description: The rx_monitor_all_show function is a static function that is designed to be used in the context of a device's sysfs interface. It takes three parameters: a pointer to the input device (input_dev), a pointer to the device attribute (attr), and a pointer to a buffer (buf) where the output will be stored.

  1. The function begins by converting the input device pointer (input_dev) to a platform_device structure using the to_platform_device macro. This is necessary because the function needs to access platform-specific data associated with the device.

  2. Next, it retrieves the hardware structure (ieee80211_hw) associated with the platform device by calling platform_get_drvdata, which returns a pointer to the driver data stored in the platform device. This structure contains the private data for the device.

  3. The private data structure (openwifi_priv) is then accessed through the ieee80211_hw structure. This private structure holds various statistics and settings related to the device.

  4. Finally, the function uses sprintf to format the output string, writing the value of the rx_monitor_all statistic from the private structure into the provided buffer (buf). The value is formatted as an unsigned integer followed by a newline character.

The function returns the number of bytes written to the buffer, which is the length of the formatted string.

Note: It is important to ensure that the buffer provided to the function is large enough to hold the output string, including the newline character. The function is intended to be called in the context of a sysfs read operation, where the kernel will handle the appropriate memory management.

Output Example: A possible appearance of the code's return value could be:

42
This indicates that the total count of received packets monitored by the device is 42.

graph TD
    A[Start] --> B[Receive input device and attribute]
    B --> C[Convert input device to platform device]
    C --> D[Get driver data from platform device]
    D --> E[Access private structure from device]
    E --> F[Prepare output string with rx_monitor_all value]
    F --> G[Return output string]
    G --> H[End]

Function rx_monitor_all_store(struct device input_dev, struct device_attribute attr, const char *buf, size_t len)

rx_monitor_all_store: The function of rx_monitor_all_store is to store the value of a monitoring flag for receiving packets in a device's private structure and update the corresponding filter flag in the hardware.

parameters: The parameters of this Function. · parameter1: struct device input_dev - A pointer to the device structure representing the input device. · parameter2: struct device_attribute attr - A pointer to the device attribute structure associated with the device. · parameter3: const char *buf - A pointer to the buffer containing the input data as a string. · parameter4: size_t len - The length of the input data in the buffer.

Code Description: The rx_monitor_all_store function is a static function that handles the storage of a monitoring flag for an input device. It begins by converting the input device pointer to a platform device pointer using the to_platform_device function. This allows access to the platform-specific data associated with the device. The function then retrieves the hardware structure pointer (ieee80211_hw) using platform_get_drvdata, which provides access to the device's private data structure (openwifi_priv).

The function reads an integer value from the input buffer (buf) using kstrtol, which converts the string representation of the number into a long integer. This value is stored in the rx_monitor_all field of the private structure. The function then reads the current filter flag from the hardware using xpu_api->XPU_REG_FILTER_FLAG_read().

Based on the value read from the input buffer, the function updates the filter flag. If the read value is greater than zero, the MONITOR_ALL flag is set in the filter flag using a bitwise OR operation. If the read value is zero or less, the MONITOR_ALL flag is cleared using a bitwise AND operation with the negation of MONITOR_ALL. The updated filter flag is then written back to the hardware using xpu_api->XPU_REG_FILTER_FLAG_write().

Finally, the function returns the result of the conversion operation. If the conversion was successful (ret is zero), it returns the length of the input data (len). If there was an error during conversion, it returns the error code.

Note: It is important to ensure that the input buffer contains a valid integer representation before calling this function, as invalid input may lead to unexpected behavior or errors during conversion.

Output Example: If the input buffer contains the string "1" and the conversion is successful, the function will return the length of the input string, which is 1. If the input buffer contains an invalid string, such as "abc", the function will return a negative error code indicating the failure of the conversion.

graph TD
    A[Start] --> B[Get platform device from input device]
    B --> C[Get ieee80211 hardware from platform device]
    C --> D[Get private data from ieee80211 hardware]
    D --> E[Convert input buffer to long]
    E --> F[Update rx_monitor_all in private data]
    F --> G[Read current filter flag from XPU]
    G --> H{Check if readin is greater than 0}
    H -->|Yes| I[Set filter flag to include MONITOR_ALL]
    H -->|No| J[Clear MONITOR_ALL from filter flag]
    I --> K[Write updated filter flag to XPU]
    J --> K
    K --> L[Return result or length]
    L --> M[End]

Function rx_data_pkt_num_total_show(struct device input_dev, struct device_attribute attr, char *buf)

rx_data_pkt_num_total_show: The function of rx_data_pkt_num_total_show is to retrieve and display the total number of received data packets.

parameters: The parameters of this Function. · input_dev: A pointer to the device structure representing the input device from which the data is being retrieved.
· attr: A pointer to the device attribute structure that contains information about the attribute being accessed.
· buf: A pointer to a character buffer where the output string will be written.

Code Description: The rx_data_pkt_num_total_show function is a static function that is designed to be used in the context of a device's sysfs interface. It takes three parameters: a pointer to the input device, a pointer to the device attribute, and a character buffer for output.

The function begins by converting the input device pointer (input_dev) to a platform device pointer (pdev) using the to_platform_device macro. This conversion is necessary because the function needs to interact with platform-specific data structures.

Next, the function retrieves the hardware structure (dev) associated with the platform device by calling platform_get_drvdata, which returns a pointer to the driver data stored in the platform device. This driver data is expected to be of type ieee80211_hw, which is a structure that contains information about the IEEE 802.11 wireless hardware.

From the ieee80211_hw structure, the function accesses the private data structure (priv) that holds specific information about the OpenWiFi driver. The total number of received data packets is stored in the priv->stat.rx_data_pkt_num_total field.

Finally, the function uses the sprintf function to format the total number of received data packets as an unsigned integer followed by a newline character, and writes this formatted string into the provided buffer (buf). The function returns the number of bytes written to the buffer, which is the length of the string that was generated.

Note: It is important to ensure that the buffer provided to this function is large enough to hold the output string. The function does not perform any bounds checking on the buffer size, which could lead to buffer overflows if the buffer is insufficiently sized.

Output Example: An example of the possible appearance of the code's return value could be: "12345\n" This output indicates that a total of 12,345 data packets have been received.

graph TD
    A[Start] --> B[Receive input device and attribute]
    B --> C[Convert input device to platform device]
    C --> D[Get driver data from platform device]
    D --> E[Access private structure from device]
    E --> F[Retrieve total received data packet number]
    F --> G[Format the total packet number into buffer]
    G --> H[Return formatted buffer]
    H --> I[End]

Function rx_data_pkt_num_total_store(struct device input_dev, struct device_attribute attr, const char *buf, size_t len)

rx_data_pkt_num_total_store: The function of rx_data_pkt_num_total_store is to store the total number of received data packets in the device's private structure.

parameters: The parameters of this Function. · input_dev: A pointer to the device structure representing the input device. · attr: A pointer to the device attribute structure associated with the attribute being set. · buf: A pointer to a buffer containing the string representation of the number of packets to be stored. · len: The length of the buffer.

Code Description: The rx_data_pkt_num_total_store function is designed to handle the storage of the total number of received data packets for a specific device. It takes in several parameters, including a pointer to the device structure, a pointer to the device attribute, a buffer containing the new value, and the length of that buffer.

The function begins by converting the input device pointer to a platform device pointer using the to_platform_device macro. This allows the function to access platform-specific data associated with the device. Next, it retrieves the hardware structure associated with the device by calling platform_get_drvdata, which returns a pointer to the ieee80211_hw structure. This structure contains a private member, priv, which points to the openwifi_priv structure that holds various statistics, including the total number of received data packets.

The function then attempts to convert the string in the buf parameter to a long integer using kstrtol. The result is stored in the variable readin. The conversion function returns a status code, which is stored in the variable ret. If the conversion is successful (ret is zero), the readin value is assigned to the rx_data_pkt_num_total member of the priv structure, effectively updating the total number of received data packets.

Finally, the function returns either the status code from the conversion (if there was an error) or the length of the input buffer (indicating success).

Note: It is important to ensure that the input provided in the buf parameter is a valid string representation of a number. If the conversion fails, the function will return an error code, and the total number of received data packets will not be updated.

Output Example: If the input buffer contains the string "100", and the conversion is successful, the function will return the value 3 (the length of the input string), and the total number of received data packets will be updated to 100 in the priv structure. If the input buffer contains an invalid string, such as "abc", the function will return a negative error code indicating the failure of the conversion.

graph TD
    A[Start function rx_data_pkt_num_total_store] --> B[Convert input_dev to platform_device]
    B --> C[Get ieee80211_hw from platform_device]
    C --> D[Access private data structure from ieee80211_hw]
    D --> E[Convert input buffer to long integer]
    E --> F[Store read value in rx_data_pkt_num_total]
    F --> G[Check conversion result]
    G -->|Success| H[Return length of input buffer]
    G -->|Failure| I[Return conversion error]
    H --> J[End function]
    I --> J

Function rx_data_pkt_num_fail_show(struct device input_dev, struct device_attribute attr, char *buf)

rx_data_pkt_num_fail_show: The function of rx_data_pkt_num_fail_show is to retrieve and display the number of failed received data packets.

parameters: The parameters of this Function. · input_dev: A pointer to the device structure representing the input device. · attr: A pointer to the device attribute structure associated with the device. · buf: A pointer to a buffer where the output string will be written.

Code Description: The rx_data_pkt_num_fail_show function is a static function designed to be used in the context of a device's sysfs interface. It takes three parameters: a pointer to the device structure (input_dev), a pointer to the device attribute structure (attr), and a character buffer (buf) where the output will be stored.

  1. The function begins by converting the input device pointer (input_dev) to a platform device pointer (pdev) using the to_platform_device macro. This is necessary because the function is intended to work with platform devices specifically.

  2. Next, it retrieves the hardware structure (dev) associated with the platform device by calling platform_get_drvdata, which returns a pointer to the device's driver data. This driver data is expected to be of type ieee80211_hw.

  3. The function then accesses the private data structure (priv) associated with the ieee80211_hw structure. This private data structure is expected to contain various statistics related to the device's operation.

  4. Finally, the function uses the sprintf function to format the number of failed received data packets (priv->stat.rx_data_pkt_num_fail) into the provided buffer (buf). The output is formatted as an unsigned integer followed by a newline character.

The return value of the function is the number of bytes written to the buffer, which is the length of the formatted string.

Note: It is important to ensure that the buffer provided to the function is large enough to hold the formatted output, including the newline character. The function is intended to be called in a context where the sysfs interface is accessed, typically by user-space applications or scripts.

Output Example: A possible appearance of the code's return value could be: "5\n" This indicates that there have been 5 failed received data packets.

graph TD
    A[Start function rx_data_pkt_num_fail_show] --> B[Get platform device from input_dev]
    B --> C[Get ieee80211_hw from platform device]
    C --> D[Get openwifi_priv from ieee80211_hw]
    D --> E[Format rx_data_pkt_num_fail into buffer]
    E --> F[Return formatted buffer]
    F --> G[End function rx_data_pkt_num_fail_show]

Function rx_data_pkt_num_fail_store(struct device input_dev, struct device_attribute attr, const char *buf, size_t len)

rx_data_pkt_num_fail_store: The function of rx_data_pkt_num_fail_store is to store the number of failed received data packets in the device's private structure.

parameters: The parameters of this Function. · input_dev: A pointer to the device structure representing the input device. · attr: A pointer to the device attribute structure. · buf: A pointer to a character buffer containing the input data to be processed. · len: The length of the input data in the buffer.

Code Description: The rx_data_pkt_num_fail_store function is designed to handle the storage of the number of failed received data packets for a specific device. It takes in several parameters, including a device pointer, an attribute pointer, a buffer containing the input data, and the length of that data.

The function begins by converting the input device pointer to a platform device pointer using the to_platform_device macro. This allows access to platform-specific data associated with the device. Next, it retrieves the hardware structure associated with the device by calling platform_get_drvdata, which provides a pointer to the ieee80211_hw structure. This structure contains a private pointer (priv) that points to the openwifi_priv structure, where the statistics for the device are stored.

The function then attempts to convert the string input from the buffer (buf) into a long integer using the kstrtol function. This conversion is crucial as it allows the function to interpret the input data correctly. The result of this conversion is stored in the variable readin. The return value of kstrtol is stored in the variable ret, which indicates whether the conversion was successful or not.

Subsequently, the function updates the rx_data_pkt_num_fail field within the priv structure with the value of readin, effectively storing the number of failed received data packets.

Finally, the function returns either the length of the input data (len) if the conversion was successful (ret is zero) or the error code (ret) if the conversion failed.

Note: It is important to ensure that the input data in the buffer is a valid string representation of a number. If the input is invalid, the function will return an error code instead of the expected length.

Output Example: If the input buffer contains the string "5" and the conversion is successful, the function will store the value 5 in priv->stat.rx_data_pkt_num_fail and return the length of the input, which would be 1 (the length of the string "5"). If the input buffer contains an invalid string, such as "abc", the function will return an error code indicating the failure of the conversion.

graph TD
    A[Start function rx_data_pkt_num_fail_store] --> B[Convert input_dev to platform_device]
    B --> C[Get ieee80211_hw from platform_device]
    C --> D[Access private data structure from ieee80211_hw]
    D --> E[Convert input buffer to long value]
    E --> F[Store readin value in rx_data_pkt_num_fail]
    F --> G[Check if conversion was successful]
    G -->|Success| H[Return length of input buffer]
    G -->|Failure| I[Return conversion error code]
    H --> J[End function]
    I --> J

Function rx_mgmt_pkt_num_total_show(struct device input_dev, struct device_attribute attr, char *buf)

rx_mgmt_pkt_num_total_show: The function of rx_mgmt_pkt_num_total_show is to retrieve and display the total number of received management packets.

parameters: The parameters of this Function. · input_dev: A pointer to the device structure representing the input device.
· attr: A pointer to the device attribute structure associated with the device.
· buf: A pointer to the character buffer where the output string will be stored.

Code Description: The rx_mgmt_pkt_num_total_show function is a static function designed to be used in the context of a device attribute in the Linux kernel. It takes three parameters: a pointer to the device structure (input_dev), a pointer to the device attribute structure (attr), and a character buffer (buf) where the output will be formatted.

The function begins by converting the input device pointer to a platform device pointer using the to_platform_device macro. This is necessary because the function is intended to work with platform devices, which are a specific type of device in the Linux kernel.

Next, the function retrieves the hardware structure associated with the platform device by calling platform_get_drvdata, which returns a pointer to the ieee80211_hw structure. This structure contains various fields related to the IEEE 802.11 wireless hardware.

From the ieee80211_hw structure, the function accesses the private data structure (openwifi_priv) associated with the device through the priv field. This private structure holds statistics and other information specific to the device's operation.

Finally, the function uses the sprintf function to format the total number of received management packets (priv->stat.rx_mgmt_pkt_num_total) into the provided buffer (buf), appending a newline character at the end. The return value of the function is the number of bytes written to the buffer, which is of type ssize_t.

Note: It is important to ensure that the buffer provided to this function is large enough to hold the formatted output. The function assumes that the private data structure has been properly initialized and that the statistics are being accurately maintained.

Output Example: An example of the output that this function might produce when called could be:
"12345\n"
This indicates that a total of 12,345 management packets have been received.

graph TD
    A[Start] --> B[Receive input device and attribute]
    B --> C[Convert input device to platform device]
    C --> D[Retrieve driver data from platform device]
    D --> E[Access private structure from driver data]
    E --> F[Format total received management packet number into buffer]
    F --> G[Return formatted buffer]
    G --> H[End]

Function rx_mgmt_pkt_num_total_store(struct device input_dev, struct device_attribute attr, const char *buf, size_t len)

rx_mgmt_pkt_num_total_store: The function of rx_mgmt_pkt_num_total_store is to store the total number of received management packets.

parameters: The parameters of this Function. · parameter1: struct device input_dev - A pointer to the device structure representing the input device. · parameter2: struct device_attribute attr - A pointer to the device attribute structure associated with the input device. · parameter3: const char *buf - A pointer to a buffer containing the data to be stored, typically a string representation of a number. · parameter4: size_t len - The length of the data in the buffer.

Code Description: The rx_mgmt_pkt_num_total_store function is a static function that is designed to handle the storage of the total number of received management packets for a specific device. It takes four parameters: a pointer to the device structure, a pointer to the device attribute structure, a buffer containing the data to be stored, and the length of that data.

The function begins by converting the input device pointer to a platform device pointer using the to_platform_device macro. This allows access to platform-specific data associated with the device. Next, it retrieves the hardware structure associated with the device by calling platform_get_drvdata, which returns a pointer to the ieee80211_hw structure. This structure contains a pointer to the private data structure, openwifi_priv, which holds various statistics, including the total number of received management packets.

The function then declares a variable of type long named readin, which will be used to store the converted value from the input buffer. The kstrtol function is called to convert the string in the buffer (buf) to a long integer. The base for the conversion is set to 10, and the result is stored in the readin variable. The return value of kstrtol is stored in the variable ret, which indicates whether the conversion was successful.

If the conversion is successful (ret is 0), the function assigns the value of readin to the rx_mgmt_pkt_num_total field of the priv structure, effectively updating the total number of received management packets. Finally, the function returns the length of the input data (len) if the conversion was successful; otherwise, it returns the error code stored in ret.

Note: It is important to ensure that the input buffer contains a valid string representation of a number before calling this function, as invalid input may lead to unexpected behavior or errors.

Output Example: If the input buffer contains the string "100", the function will successfully convert this to a long integer and update the total received management packets to 100, returning the length of the input string, which is 3. If the input buffer contains an invalid string, such as "abc", the function will return an error code indicating the failure of the conversion.

graph TD
    A[Start function rx_mgmt_pkt_num_total_store] --> B[Convert input_dev to platform_device]
    B --> C[Get ieee80211_hw from platform_device]
    C --> D[Access private data from ieee80211_hw]
    D --> E[Convert buf to long using kstrtol]
    E --> F[Store readin value in rx_mgmt_pkt_num_total]
    F --> G[Check if ret is non-zero]
    G -->|Yes| H[Return ret]
    G -->|No| I[Return len]
    H --> J[End function]
    I --> J

Function rx_mgmt_pkt_num_fail_show(struct device input_dev, struct device_attribute attr, char *buf)

rx_mgmt_pkt_num_fail_show: The function of rx_mgmt_pkt_num_fail_show is to retrieve and display the number of failed received management packets.

parameters: The parameters of this Function. · input_dev: A pointer to the device structure representing the input device. · attr: A pointer to the device attribute structure associated with the device. · buf: A pointer to a character buffer where the output string will be stored.

Code Description: The rx_mgmt_pkt_num_fail_show function is a static function that is designed to be used as a show method for a sysfs entry. It takes three parameters: a pointer to the input device (input_dev), a pointer to the device attribute (attr), and a buffer (buf) where the output will be written.

The function begins by converting the input device pointer to a platform device pointer using the to_platform_device macro. This is necessary because the function needs to access platform-specific data associated with the device. Next, it retrieves the hardware structure (ieee80211_hw) associated with the platform device by calling platform_get_drvdata, which returns a pointer to the driver data stored in the platform device.

From the ieee80211_hw structure, the function accesses the private data structure (openwifi_priv) through the priv member. This private structure contains various statistics related to the device's operation. Specifically, the function retrieves the number of failed received management packets from the stat member of the openwifi_priv structure.

Finally, the function formats this number as an unsigned integer and writes it to the provided buffer (buf) using the sprintf function, appending a newline character at the end. The function returns the number of bytes written to the buffer, which is the standard behavior for show functions in the sysfs interface.

Note: It is important to ensure that the buffer provided to the function is large enough to hold the formatted output, including the newline character. Additionally, this function should be called in the context of a sysfs read operation to ensure proper access to the device's statistics.

Output Example: An example of the output from this function might look like the following when the number of failed received management packets is 5:

5

graph TD
    A[Start] --> B[Get platform device from input device]
    B --> C[Get driver data from platform device]
    C --> D[Access private structure from device]
    D --> E[Retrieve number of failed management packets]
    E --> F[Format the output string]
    F --> G[Return formatted string]
    G --> H[End]

Function rx_mgmt_pkt_num_fail_store(struct device input_dev, struct device_attribute attr, const char *buf, size_t len)

rx_mgmt_pkt_num_fail_store: The function of rx_mgmt_pkt_num_fail_store is to store the number of failed received management packets into the device's private statistics.

parameters: The parameters of this Function. · input_dev: A pointer to the device structure representing the input device.
· attr: A pointer to the device attribute structure associated with the attribute being modified.
· buf: A pointer to a buffer containing the string representation of the number to be stored.
· len: The length of the buffer.

Code Description: The rx_mgmt_pkt_num_fail_store function is a static function that is designed to handle the storage of the number of failed received management packets for a specific device. It takes four parameters: a pointer to the input device, a pointer to the device attribute, a buffer containing the new value, and the length of that buffer.

The function begins by converting the input device pointer to a platform device pointer using the to_platform_device macro. This allows access to platform-specific data associated with the device. Next, it retrieves the hardware structure associated with the device by calling platform_get_drvdata, which returns a pointer to the ieee80211_hw structure.

From the ieee80211_hw structure, the function accesses the private data structure (openwifi_priv) that holds various statistics, including the number of failed received management packets. The function then attempts to convert the string in the buffer (buf) to a long integer using the kstrtol function. The conversion result is stored in the variable readin, and the return value of kstrtol is stored in ret.

If the conversion is successful (ret is zero), the function updates the rx_mgmt_pkt_num_fail field in the private statistics structure with the value readin. Finally, the function returns either the result of the conversion (if it failed) or the length of the buffer (indicating success).

Note: It is important to ensure that the input provided in the buffer is a valid string representation of a number. If the conversion fails, the function will return an error code, which should be handled appropriately by the caller.

Output Example: If the input buffer contains the string "5" and the conversion is successful, the function will update the rx_mgmt_pkt_num_fail to 5 and return the length of the buffer, which would be 1 in this case. If the input buffer contains an invalid string, the function will return a non-zero error code indicating the failure of the conversion.

graph TD
    A[Start function rx_mgmt_pkt_num_fail_store] --> B[Convert input_dev to platform_device]
    B --> C[Get ieee80211_hw from platform_device]
    C --> D[Access private data from ieee80211_hw]
    D --> E[Convert buf to long using kstrtol]
    E --> F[Store readin value in priv->stat.rx_mgmt_pkt_num_fail]
    F --> G[Check if ret is non-zero]
    G -->|Yes| H[Return ret]
    G -->|No| I[Return len]
    H --> J[End function]
    I --> J

Function rx_ack_pkt_num_total_show(struct device input_dev, struct device_attribute attr, char *buf)

rx_ack_pkt_num_total_show: The function of rx_ack_pkt_num_total_show is to retrieve and display the total number of received acknowledgment packets.

parameters: The parameters of this Function. · input_dev: A pointer to the device structure representing the input device from which data is being retrieved. · attr: A pointer to the device attribute structure that represents the specific attribute being accessed. · buf: A pointer to a character buffer where the output string will be stored.

Code Description: The rx_ack_pkt_num_total_show function is a static function designed to be used in the context of a device's sysfs interface. It takes three parameters: a pointer to the device structure (input_dev), a pointer to the device attribute structure (attr), and a character buffer (buf) where the output will be written.

The function begins by converting the input device pointer to a platform device pointer using the to_platform_device macro. This conversion is necessary because the function needs to access platform-specific data associated with the device. Next, it retrieves the hardware structure (ieee80211_hw) associated with the platform device by calling platform_get_drvdata, which returns a pointer to the driver data stored in the platform device.

Once the ieee80211_hw structure is obtained, the function accesses the private data structure (openwifi_priv) associated with the hardware. This private structure contains various statistics related to the device's operation, including the total number of received acknowledgment packets.

Finally, the function uses the sprintf function to format the total number of received acknowledgment packets (priv->stat.rx_ack_pkt_num_total) as an unsigned integer and writes it to the provided buffer (buf), followed by a newline character. The function returns the number of bytes written to the buffer, which is the return value of the sprintf function.

Note: It is important to ensure that the buffer provided to this function is large enough to hold the formatted output. The function assumes that the private data structure has been properly initialized and that the statistics are being updated correctly elsewhere in the driver.

Output Example: An example of the output returned by this function could be "12345\n", indicating that a total of 12,345 acknowledgment packets have been received.

graph TD
    A[Start function rx_ack_pkt_num_total_show] --> B[Get platform device from input_dev]
    B --> C[Retrieve driver data from platform device]
    C --> D[Access private structure from driver data]
    D --> E[Format total received acknowledgment packet number into buffer]
    E --> F[Return formatted buffer]
    F --> G[End function]

Function rx_ack_pkt_num_total_store(struct device input_dev, struct device_attribute attr, const char *buf, size_t len)

rx_ack_pkt_num_total_store: The function of rx_ack_pkt_num_total_store is to store the total number of received acknowledgment packets.

parameters: The parameters of this Function. · parameter1: struct device input_dev - A pointer to the device structure representing the input device. · parameter2: struct device_attribute attr - A pointer to the device attribute structure. · parameter3: const char *buf - A pointer to a buffer containing the data to be stored. · parameter4: size_t len - The length of the data in the buffer.

Code Description: The rx_ack_pkt_num_total_store function is a static function that handles the storage of the total number of received acknowledgment packets for a specific device. It takes four parameters: a pointer to the input device, a pointer to the device attribute, a buffer containing the data to be stored, and the length of that data.

The function begins by converting the input device pointer to a platform device pointer using the to_platform_device macro. It then retrieves the associated ieee80211_hw structure by calling platform_get_drvdata with the platform device pointer. This structure contains a pointer to the private data structure openwifi_priv, which holds various statistics related to the device.

Next, the function attempts to convert the string data in the buffer (buf) to a long integer using the kstrtol function. The result is stored in the variable readin. If the conversion is successful, the total number of received acknowledgment packets is updated in the private structure by assigning the value of readin to the stat.rx_ack_pkt_num_total field.

Finally, the function returns the result of the conversion. If the conversion was successful (ret equals 0), it returns the length of the data written (len). If there was an error during the conversion, it returns the error code stored in ret.

Note: It is important to ensure that the input buffer contains a valid string representation of a number before calling this function, as invalid input may lead to unexpected behavior or errors during conversion.

Output Example: If the input buffer contains the string "100", the function will update the total number of received acknowledgment packets to 100 and return the length of the input string, which is 3. If the input buffer contains an invalid string, such as "abc", the function will return an error code indicating the failure of the conversion.

graph TD
    A[Start function rx_ack_pkt_num_total_store] --> B[Convert input_dev to platform_device]
    B --> C[Get ieee80211_hw from platform_device]
    C --> D[Access private data from ieee80211_hw]
    D --> E[Convert buf to long using kstrtol]
    E --> F[Store readin value in priv->stat.rx_ack_pkt_num_total]
    F --> G[Check if ret is non-zero]
    G -->|Yes| H[Return ret]
    G -->|No| I[Return len]
    H --> J[End function]
    I --> J

Function rx_ack_pkt_num_fail_show(struct device input_dev, struct device_attribute attr, char *buf)

rx_ack_pkt_num_fail_show: The function of rx_ack_pkt_num_fail_show is to retrieve and display the number of failed acknowledgment packets received.

parameters: The parameters of this Function. · input_dev: A pointer to the device structure representing the input device. · attr: A pointer to the device attribute structure associated with the device. · buf: A pointer to a character buffer where the output will be written.

Code Description: The rx_ack_pkt_num_fail_show function is a static function that is designed to be used in the context of a device's sysfs interface. It takes three parameters: a pointer to the device structure (input_dev), a pointer to the device attribute structure (attr), and a character buffer (buf) where the output will be formatted and stored.

  1. The function begins by converting the input device pointer (input_dev) to a platform device pointer (pdev) using the to_platform_device macro. This conversion is necessary because the function is intended to work specifically with platform devices.

  2. Next, it retrieves the hardware structure (dev) associated with the platform device by calling platform_get_drvdata(pdev). This function returns a pointer to the driver data that was previously registered with the platform device.

  3. The function then accesses the private data structure (priv) associated with the hardware structure (dev). This private structure contains various statistics and settings related to the device's operation.

  4. Finally, the function uses the sprintf function to format the number of failed acknowledgment packets (priv->stat.rx_ack_pkt_num_fail) into the provided buffer (buf). The output is formatted as an unsigned integer followed by a newline character.

The return value of the function is the number of bytes written to the buffer, which is the length of the formatted string.

Note: It is important to ensure that the buffer provided to the function is large enough to hold the formatted output. The function does not perform any bounds checking on the buffer size.

Output Example: An example of the possible appearance of the code's return value could be "5\n", indicating that there have been 5 failed acknowledgment packets received.

graph TD
    A[Start] --> B[Get platform device from input device]
    B --> C[Get hardware data from platform device]
    C --> D[Access private data structure from hardware data]
    D --> E[Prepare to return failure count]
    E --> F[Format failure count into buffer]
    F --> G[Return formatted buffer]
    G --> H[End]

Function rx_ack_pkt_num_fail_store(struct device input_dev, struct device_attribute attr, const char *buf, size_t len)

rx_ack_pkt_num_fail_store: The function of rx_ack_pkt_num_fail_store is to store the number of failed acknowledgment packets received.

parameters: The parameters of this Function. · input_dev: A pointer to the device structure representing the input device. · attr: A pointer to the device attribute structure associated with the input device. · buf: A pointer to a buffer containing the string representation of the number to be stored. · len: The length of the buffer.

Code Description: The rx_ack_pkt_num_fail_store function is a static function that handles the storage of the number of failed acknowledgment packets in the context of a device driver. It takes four parameters: a pointer to the device structure (input_dev), a pointer to the device attribute structure (attr), a buffer containing the input string (buf), and the length of that buffer (len).

The function begins by converting the input device pointer to a platform device pointer using the to_platform_device macro. This is necessary to access platform-specific data associated with the device. Next, it retrieves the hardware structure (ieee80211_hw) associated with the platform device by calling platform_get_drvdata, which allows access to the driver-specific data.

The function then accesses the private data structure (openwifi_priv) associated with the hardware structure. This private structure contains various statistics, including the number of failed acknowledgment packets.

The input string from the buffer is converted to a long integer using the kstrtol function, which also checks for conversion errors. The result is stored in the variable readin. If the conversion is successful, the value of readin is assigned to the rx_ack_pkt_num_fail field of the private structure, effectively updating the count of failed acknowledgment packets.

Finally, the function returns the length of the input buffer if the conversion was successful; otherwise, it returns an error code. This return value indicates the success or failure of the operation.

Note: It is important to ensure that the input string in the buffer is a valid representation of a long integer to avoid conversion errors. The function assumes that the caller has provided a properly formatted string.

Output Example: If the input buffer contains the string "5" and the conversion is successful, the function will update the rx_ack_pkt_num_fail field to 5 and return the length of the input string, which is 1 in this case. If the input buffer contains an invalid string, the function will return an error code indicating the failure of the conversion.

graph TD
    A[Start function rx_ack_pkt_num_fail_store] --> B[Convert input_dev to platform_device]
    B --> C[Get ieee80211_hw from platform_device]
    C --> D[Access private data from ieee80211_hw]
    D --> E[Convert buf to long using kstrtol]
    E --> F[Store readin value in priv->stat.rx_ack_pkt_num_fail]
    F --> G[Check if ret is non-zero]
    G -->|Yes| H[Return ret]
    G -->|No| I[Return len]
    H --> J[End function]
    I --> J

Function rx_data_pkt_mcs_realtime_show(struct device input_dev, struct device_attribute attr, char *buf)

rx_data_pkt_mcs_realtime_show: The function of rx_data_pkt_mcs_realtime_show is to retrieve and display the real-time MCS (Modulation and Coding Scheme) value of received data packets.

parameters: The parameters of this Function. · input_dev: A pointer to the device structure representing the input device from which data is being retrieved. · attr: A pointer to the device attribute structure that represents the specific attribute being accessed. · buf: A character buffer where the output string will be stored.

Code Description: The rx_data_pkt_mcs_realtime_show function is a static function designed to be used in the context of a device's sysfs interface. It takes three parameters: a pointer to the input device structure, a pointer to the device attribute structure, and a character buffer for output.

The function begins by converting the input device pointer to a platform device pointer using the to_platform_device macro. This conversion is essential as it allows access to platform-specific data associated with the device. Next, it retrieves the hardware structure associated with the device by calling platform_get_drvdata, which returns a pointer to the ieee80211_hw structure. This structure contains various fields related to the wireless hardware, including a private data pointer.

The private data pointer, priv, is then used to access the openwifi_priv structure, which holds the state and statistics of the wireless device. Specifically, the function accesses the rx_data_pkt_mcs_realtime field of the priv structure, which indicates the current MCS value for received data packets.

Finally, the function formats this MCS value into the provided buffer (buf) using sprintf, appending "M" to denote the unit of measurement. The function returns the number of bytes written to the buffer, which is the standard return value for functions that write to a buffer in the sysfs interface.

Note: It is important to ensure that the buffer provided to the function is large enough to hold the formatted string. The function assumes that the MCS value is within the bounds of the wifi_rate_table array, and any out-of-bounds access could lead to undefined behavior.

Output Example: An example of the output generated by this function could be "5M\n", indicating that the current MCS value for received data packets corresponds to a rate of 5 Mbps.

graph TD
    A[Start] --> B[Get platform device from input device]
    B --> C[Get driver data from platform device]
    C --> D[Get private data from ieee80211 hardware]
    D --> E[Retrieve rx_data_pkt_mcs_realtime from private data]
    E --> F[Format data using wifi rate table]
    F --> G[Return formatted data to buffer]
    G --> H[End]

Function rx_data_pkt_mcs_realtime_store(struct device input_dev, struct device_attribute attr, const char *buf, size_t len)

rx_data_pkt_mcs_realtime_store: The function of rx_data_pkt_mcs_realtime_store is to store the real-time received data packet MCS (Modulation and Coding Scheme) value into the device's private structure.

parameters: The parameters of this Function. · input_dev: A pointer to the device structure representing the input device. · attr: A pointer to the device attribute structure associated with the input device. · buf: A pointer to a character buffer containing the data to be stored. · len: The length of the data in the buffer.

Code Description: The rx_data_pkt_mcs_realtime_store function is a static function that handles the storage of real-time received data packet MCS values for a specific device. It takes four parameters: a pointer to the input device, a pointer to the device attribute, a buffer containing the data to be stored, and the length of that data.

The function begins by converting the input device pointer to a platform device pointer using the to_platform_device macro. This allows the function to access platform-specific data associated with the device. Next, it retrieves the hardware structure associated with the device by calling platform_get_drvdata, which returns a pointer to the ieee80211_hw structure. This structure contains information about the wireless device.

The function then accesses the private data structure associated with the device through the priv member of the ieee80211_hw structure. This private structure, openwifi_priv, contains various statistics and configurations for the device.

The function attempts to convert the string data in the buf parameter to a long integer using the kstrtol function. The conversion result is stored in the variable readin, and the return value of kstrtol is stored in the variable ret. If the conversion is successful, readin will contain the parsed integer value.

The real-time received data packet MCS value is then updated in the priv structure by assigning the value of readin to priv->stat.rx_data_pkt_mcs_realtime.

Finally, the function returns the length of the input data if the conversion was successful (indicated by ret being zero). If the conversion failed, it returns the error code stored in ret.

Note: It is important to ensure that the input buffer contains valid numeric data that can be converted to a long integer. Invalid data may result in an error code being returned.

Output Example: If the input buffer contains the string "5" and the conversion is successful, the function will return 1 (the length of the input string) and store the value 5 in priv->stat.rx_data_pkt_mcs_realtime. If the input buffer contains invalid data, such as "abc", the function will return an error code indicating the failure of the conversion.

graph TD
    A[Start] --> B[Get platform device from input device]
    B --> C[Get ieee80211 hardware from platform device]
    C --> D[Get private data from ieee80211 hardware]
    D --> E[Convert input buffer to long]
    E --> F[Update rx_data_pkt_mcs_realtime in private data]
    F --> G[Return result or length]
    G --> H[End]

Function rx_data_pkt_fail_mcs_realtime_show(struct device input_dev, struct device_attribute attr, char *buf)

rx_data_pkt_fail_mcs_realtime_show: The function of rx_data_pkt_fail_mcs_realtime_show is to retrieve and display the real-time count of failed data packets based on the Modulation and Coding Scheme (MCS) in a formatted string.

parameters: The parameters of this Function. · input_dev: A pointer to the device structure representing the input device. · attr: A pointer to the device attribute structure associated with the device. · buf: A pointer to a character buffer where the output string will be stored.

Code Description: The rx_data_pkt_fail_mcs_realtime_show function is a static function that is designed to be used in the context of a device's sysfs interface. It takes three parameters: a pointer to the device structure (input_dev), a pointer to the device attribute structure (attr), and a character buffer (buf) to hold the output string.

The function begins by converting the input device pointer to a platform device pointer using the to_platform_device macro. This allows access to platform-specific data associated with the device. Next, it retrieves the hardware structure (ieee80211_hw) associated with the platform device by calling platform_get_drvdata, which returns a pointer to the driver data stored in the platform device.

From the ieee80211_hw structure, the function accesses the private data structure (openwifi_priv) that contains various statistics related to the device's operation. Specifically, it retrieves the real-time count of failed data packets that are categorized by MCS from the priv structure.

Finally, the function formats this count into a string and writes it to the provided buffer (buf) using the sprintf function. The output is formatted as an unsigned integer followed by the letter "M" and a newline character, indicating the measurement unit. The function returns the number of bytes written to the buffer.

Note: It is important to ensure that the buffer provided to the function is large enough to hold the formatted output to prevent buffer overflows. The function is intended to be called in a context where the sysfs interface is accessed, typically from user space.

Output Example: An example of the possible return value when calling this function could be "5M\n", indicating that there have been 5 failed data packets based on the MCS in real-time.

graph TD
    A[Start] --> B[Receive input device and attribute]
    B --> C[Convert input device to platform device]
    C --> D[Get driver data from platform device]
    D --> E[Access private structure from driver data]
    E --> F[Retrieve rx_data_pkt_fail_mcs_realtime from private structure]
    F --> G[Format output string with wifi rate table]
    G --> H[Return formatted string]
    H --> I[End]

Function rx_data_pkt_fail_mcs_realtime_store(struct device input_dev, struct device_attribute attr, const char *buf, size_t len)

rx_data_pkt_fail_mcs_realtime_store: The function of rx_data_pkt_fail_mcs_realtime_store is to store the real-time count of failed MCS (Modulation and Coding Scheme) data packets received by the device.

parameters: The parameters of this Function. · parameter1: struct device input_dev - A pointer to the device structure representing the input device. · parameter2: struct device_attribute attr - A pointer to the device attribute structure. · parameter3: const char *buf - A pointer to a buffer containing the string representation of the value to be stored. · parameter4: size_t len - The length of the string in the buffer.

Code Description: The rx_data_pkt_fail_mcs_realtime_store function is a static function designed to handle the storage of real-time statistics related to the failure of received data packets based on their MCS. The function begins by converting the input device pointer (input_dev) to a platform device pointer (pdev) using the to_platform_device macro. This is essential as it allows access to platform-specific data associated with the device.

Next, the function retrieves the hardware structure (dev) associated with the platform device using the platform_get_drvdata function. This hardware structure contains a pointer to the private data structure (priv) of type openwifi_priv, which holds various statistics and configurations for the device.

The function then declares a variable named readin of type long to store the converted value from the input buffer. It uses the kstrtol function to convert the string in buf to a long integer, storing the result in readin. The kstrtol function also returns an error code, which is captured in the variable ret.

Once the conversion is successful, the function updates the real-time count of failed MCS data packets by assigning the value of readin to the corresponding field in the priv structure (priv->stat.rx_data_pkt_fail_mcs_realtime).

Finally, the function returns either the error code (ret) if the conversion failed, or the length of the input string (len) if the operation was successful. This return value indicates the outcome of the operation, allowing the caller to handle any errors appropriately.

Note: It is important to ensure that the input buffer contains a valid string representation of a long integer before calling this function, as invalid input may lead to unexpected behavior or errors.

Output Example: If the input buffer contains the string "5" and the conversion is successful, the function will update the real-time count of failed MCS data packets to 5 and return the length of the input string, which is 1. If the input buffer contains an invalid string, the function will return an error code indicating the failure of the conversion.

graph TD
    A[Start] --> B[Receive input device, attribute, buffer, and length]
    B --> C[Convert input device to platform device]
    C --> D[Get driver data from platform device]
    D --> E[Access private structure from driver data]
    E --> F[Convert buffer to long integer]
    F --> G[Update rx_data_pkt_fail_mcs_realtime in private structure]
    G --> H[Check if conversion was successful]
    H -->|Success| I[Return length]
    H -->|Failure| J[Return error code]
    I --> K[End]
    J --> K

Function rx_mgmt_pkt_mcs_realtime_show(struct device input_dev, struct device_attribute attr, char *buf)

rx_mgmt_pkt_mcs_realtime_show: The function of rx_mgmt_pkt_mcs_realtime_show is to retrieve and display the current MCS (Modulation and Coding Scheme) rate of received management packets in real-time.

parameters: The parameters of this Function. · input_dev: A pointer to the device structure representing the input device from which the data is being retrieved. · attr: A pointer to the device attribute structure that represents the attribute associated with the device. · buf: A pointer to a character buffer where the output string will be stored.

Code Description: The function rx_mgmt_pkt_mcs_realtime_show is defined as a static function that returns a ssize_t value. It takes three parameters: a pointer to a device structure (input_dev), a pointer to a device attribute structure (attr), and a character buffer (buf) for output.

Inside the function, the input device is first converted to a platform device using the to_platform_device macro. This allows access to platform-specific data associated with the device. The function then retrieves the hardware structure (ieee80211_hw) associated with the platform device by calling platform_get_drvdata, which returns a pointer to the driver data stored in the platform device.

Next, the function accesses the private data structure (openwifi_priv) associated with the hardware structure. This private structure contains various statistics and state information, including the real-time MCS rate of received management packets.

The function then formats the output string using sprintf, which writes the current MCS rate (retrieved from the priv structure) into the provided buffer (buf). The MCS rate is accessed from the wifi_rate_table array using the index priv->stat.rx_mgmt_pkt_mcs_realtime. The formatted output includes the MCS rate followed by the character 'M' and a newline character.

Finally, the function returns the number of bytes written to the buffer, which is the length of the formatted string.

Note: It is important to ensure that the buffer provided to the function is large enough to hold the formatted output to prevent buffer overflow. The function is intended to be used in a context where the device attribute is being read, such as through a sysfs interface.

Output Example: An example of the output that may be returned by this function could be "5M\n", indicating that the current MCS rate of received management packets is 5.

graph TD
    A[Start] --> B[Receive input device and attribute]
    B --> C[Convert input device to platform device]
    C --> D[Retrieve driver data from platform device]
    D --> E[Access private data structure from device]
    E --> F[Get real-time MCS value from statistics]
    F --> G[Format MCS value into buffer]
    G --> H[Return formatted buffer]
    H --> I[End]

Function rx_mgmt_pkt_mcs_realtime_store(struct device input_dev, struct device_attribute attr, const char *buf, size_t len)

rx_mgmt_pkt_mcs_realtime_store: The function of rx_mgmt_pkt_mcs_realtime_store is to store the received management packet MCS (Modulation and Coding Scheme) value in the device's private structure.

parameters: The parameters of this Function. · input_dev: A pointer to the device structure representing the input device. · attr: A pointer to the device attribute structure. · buf: A pointer to a character buffer containing the input data to be processed. · len: The length of the input data in the buffer.

Code Description: The rx_mgmt_pkt_mcs_realtime_store function is designed to handle the storage of a specific value related to received management packets in a wireless device. It begins by converting the input device pointer (input_dev) to a platform device pointer (pdev) using the to_platform_device function. This conversion allows access to the platform-specific data associated with the device.

Next, the function retrieves the hardware structure (dev) associated with the platform device by calling platform_get_drvdata, which fetches the driver data stored in the platform device. The private data structure (priv) of the device is then accessed through the dev structure, allowing the function to manipulate device-specific statistics.

The function then attempts to convert the input string (buf) into a long integer using kstrtol. The conversion result is stored in the variable readin, and the return value of kstrtol is stored in ret. If the conversion is successful (ret equals zero), the function assigns the converted value (readin) to the rx_mgmt_pkt_mcs_realtime field of the priv structure.

Finally, the function returns the length of the input data (len) if the conversion was successful; otherwise, it returns the error code stored in ret. This return value indicates whether the operation was successful or if an error occurred during the conversion process.

Note: It is important to ensure that the input data in the buffer (buf) is a valid string representation of a long integer before calling this function, as invalid input may lead to conversion errors.

Output Example: If the input buffer contains the string "5" and the conversion is successful, the function will return the length of the input string, which is 1, and the rx_mgmt_pkt_mcs_realtime field will be updated to 5. If the input buffer contains an invalid string, such as "abc", the function will return an error code indicating the failure of the conversion.

graph TD
    A[Start] --> B[Get platform device from input device]
    B --> C[Get ieee80211 hardware from platform device]
    C --> D[Get private data from ieee80211 hardware]
    D --> E[Convert input buffer to long]
    E --> F[Store converted value in private data]
    F --> G[Check conversion result]
    G -->|Success| H[Return length]
    G -->|Failure| I[Return conversion result]
    H --> J[End]
    I --> J

Function rx_mgmt_pkt_fail_mcs_realtime_show(struct device input_dev, struct device_attribute attr, char *buf)

rx_mgmt_pkt_fail_mcs_realtime_show: The function of rx_mgmt_pkt_fail_mcs_realtime_show is to retrieve and display the real-time count of failed management packets at a specific MCS (Modulation and Coding Scheme) rate.

parameters: The parameters of this Function. · input_dev: A pointer to the device structure representing the input device from which the data is being retrieved. · attr: A pointer to the device attribute structure that represents the specific attribute being accessed. · buf: A pointer to a character buffer where the output string will be written.

Code Description: The rx_mgmt_pkt_fail_mcs_realtime_show function is a static function that is designed to be called when the corresponding sysfs attribute is accessed. It takes three parameters: a pointer to the input device, a pointer to the device attribute, and a buffer where the output will be stored.

  1. The function begins by converting the input device pointer (input_dev) to a platform device pointer (pdev) using the to_platform_device macro. This is necessary because the function operates on platform devices, which are a specific type of device in the Linux kernel.

  2. Next, it retrieves the hardware structure (dev) associated with the platform device by calling platform_get_drvdata(pdev). This structure contains various information about the device, including its private data.

  3. The private data structure (priv) is then accessed from the hardware structure. This structure holds the statistics and state information relevant to the device's operation.

  4. The function then retrieves the count of failed management packets at the current MCS rate from the private structure (priv->stat.rx_mgmt_pkt_fail_mcs_realtime). This count is used as an index to access the corresponding value in the wifi_rate_table array.

  5. Finally, the function formats the retrieved value into the provided buffer (buf) using sprintf, appending "M" to indicate the unit of measurement, and returns the number of bytes written to the buffer.

Note: It is important to ensure that the wifi_rate_table is properly initialized and populated with valid data corresponding to the MCS rates. Additionally, the function should be called in a context where the input device is valid and the private data structure is correctly set up.

Output Example: A possible appearance of the code's return value could be "5M", indicating that there have been 5 failed management packets at the current MCS rate.

activityDiagram
    start
    :Receive input device and attribute;
    :Convert input device to platform device;
    :Get driver data from platform device;
    :Access private data from hardware structure;
    :Retrieve rx_mgmt_pkt_fail_mcs_realtime value;
    :Format value into buffer;
    :Return formatted buffer;
    end

Function rx_mgmt_pkt_fail_mcs_realtime_store(struct device input_dev, struct device_attribute attr, const char *buf, size_t len)

rx_mgmt_pkt_fail_mcs_realtime_store: The function of rx_mgmt_pkt_fail_mcs_realtime_store is to store the real-time count of received management packet failures at a specific MCS (Modulation and Coding Scheme) level.

parameters: The parameters of this Function. · input_dev: A pointer to the device structure representing the input device. · attr: A pointer to the device attribute structure associated with the input device. · buf: A pointer to a buffer containing the string representation of the value to be stored. · len: The length of the buffer.

Code Description: The rx_mgmt_pkt_fail_mcs_realtime_store function is designed to handle the storage of real-time statistics related to the failure of received management packets in a wireless communication context. The function begins by converting the input device pointer (input_dev) to a platform device pointer (pdev) using the to_platform_device macro. This allows access to platform-specific data associated with the device.

Next, the function retrieves the driver data associated with the platform device by calling platform_get_drvdata, which returns a pointer to the ieee80211_hw structure (dev). This structure contains various hardware-related information, including a pointer to the private data structure (priv) of type openwifi_priv.

The function then declares a variable named readin of type long, which will hold the converted value from the input buffer. It uses the kstrtol function to convert the string in buf to a long integer, storing the result in readin. The kstrtol function also returns a status code in ret, which indicates whether the conversion was successful or not.

If the conversion is successful (ret is 0), the function updates the rx_mgmt_pkt_fail_mcs_realtime field of the priv structure with the value stored in readin. This effectively updates the real-time statistics for management packet failures.

Finally, the function returns either the conversion result (ret) if there was an error during the conversion process or the length of the input buffer (len) if the operation was successful. This return value can be used by the caller to determine the outcome of the store operation.

Note: It is important to ensure that the input buffer contains a valid string representation of a long integer before calling this function to avoid conversion errors. Additionally, the function assumes that the priv structure has been properly initialized and that the rx_mgmt_pkt_fail_mcs_realtime field is accessible.

Output Example: If the input buffer contains the string "5" and the conversion is successful, the function will update the rx_mgmt_pkt_fail_mcs_realtime field to 5 and return the length of the input buffer, which would be 1 in this case. If the input buffer contains an invalid string, the function will return a non-zero error code indicating the failure of the conversion.

graph TD
    A[Start] --> B[Get platform device from input device]
    B --> C[Get ieee80211 hardware data from platform device]
    C --> D[Get private data from ieee80211 hardware]
    D --> E[Convert input buffer to long value]
    E --> F[Store value in rx_mgmt_pkt_fail_mcs_realtime]
    F --> G[Return result based on conversion success]
    G --> H[End]

Function rx_ack_pkt_mcs_realtime_show(struct device input_dev, struct device_attribute attr, char *buf)

rx_ack_pkt_mcs_realtime_show: The function of rx_ack_pkt_mcs_realtime_show is to retrieve and display the real-time MCS (Modulation and Coding Scheme) value of received acknowledgment packets.

parameters: The parameters of this Function. · input_dev: A pointer to the device structure representing the input device. · attr: A pointer to the device attribute structure. · buf: A pointer to a character buffer where the output string will be stored.

Code Description: The rx_ack_pkt_mcs_realtime_show function is a static function that is designed to be used in the context of a device's sysfs interface. It takes three parameters: a pointer to the input device, a pointer to the device attribute, and a buffer for output.

The function begins by converting the input device pointer to a platform device pointer using the to_platform_device macro. This allows access to platform-specific data associated with the device. Next, it retrieves the hardware structure (ieee80211_hw) associated with the platform device by calling platform_get_drvdata, which returns a pointer to the driver data stored in the platform device.

From the ieee80211_hw structure, the function accesses the private data structure (openwifi_priv) that contains various statistics and state information related to the device. Specifically, it focuses on the real-time MCS value of received acknowledgment packets, which is stored in the priv->stat.rx_ack_pkt_mcs_realtime field.

Finally, the function formats this MCS value into a string and writes it to the provided buffer using sprintf. The output string includes the MCS value followed by the character 'M' and a newline character, indicating the unit of measurement. The function returns the number of bytes written to the buffer.

Note: It is important to ensure that the buffer passed to this function is large enough to hold the formatted string to avoid buffer overflows. The function is intended to be called in a context where the sysfs interface is accessed, typically by user-space applications querying device statistics.

Output Example: A possible appearance of the code's return value could be "5M\n", indicating that the real-time MCS value of received acknowledgment packets is 5.

graph TD
    A[Start] --> B[Receive input device and attribute]
    B --> C[Convert input device to platform device]
    C --> D[Get driver data from platform device]
    D --> E[Access private data structure]
    E --> F[Retrieve real-time MCS value from statistics]
    F --> G[Format MCS value into buffer]
    G --> H[Return formatted buffer]
    H --> I[End]

Function rx_ack_pkt_mcs_realtime_store(struct device input_dev, struct device_attribute attr, const char *buf, size_t len)

rx_ack_pkt_mcs_realtime_store: The function of rx_ack_pkt_mcs_realtime_store is to store the real-time count of received acknowledgment packets in the MCS (Modulation and Coding Scheme) statistics.

parameters: The parameters of this Function. · input_dev: A pointer to the device structure representing the input device. · attr: A pointer to the device attribute structure associated with the input device. · buf: A pointer to a buffer containing the data to be stored, represented as a string. · len: The length of the data in the buffer.

Code Description: The rx_ack_pkt_mcs_realtime_store function is designed to handle the storage of real-time statistics related to received acknowledgment packets for a specific device. It begins by converting the input device pointer to a platform device structure using the to_platform_device function. This allows access to platform-specific data associated with the device.

Next, the function retrieves the hardware structure associated with the device by calling platform_get_drvdata, which returns a pointer to the ieee80211_hw structure. This structure contains various fields related to the wireless hardware, including a pointer to the private data structure, openwifi_priv, which holds the statistics.

The function then attempts to convert the input string (buf) into a long integer using kstrtol. This conversion is crucial as it allows the function to interpret the string data as a numerical value. The result of this conversion is stored in the variable readin, and the return value of kstrtol is stored in ret. If the conversion is successful (ret equals 0), the function updates the rx_ack_pkt_mcs_realtime field in the priv structure with the new value of readin.

Finally, the function returns the result of the conversion. If the conversion was successful, it returns the length of the input data (len). If there was an error during conversion, it returns the error code stored in ret.

Note: It is important to ensure that the input data in buf is a valid string representation of a long integer. Invalid input may lead to an error during conversion, which will be reflected in the return value.

Output Example: If the input buffer contains the string "42" and the conversion is successful, the function will return the length of the input string, which is 2. The rx_ack_pkt_mcs_realtime field in the priv structure will be updated to 42.

graph TD
    A[Start function rx_ack_pkt_mcs_realtime_store] --> B[Get platform device from input_dev]
    B --> C[Get ieee80211_hw from platform device]
    C --> D[Get openwifi_priv from ieee80211_hw]
    D --> E[Convert buf to long using kstrtol]
    E --> F[Store readin in priv->stat.rx_ack_pkt_mcs_realtime]
    F --> G[Check if ret is non-zero]
    G -->|Yes| H[Return ret]
    G -->|No| I[Return len]
    H --> J[End function]
    I --> J

Function restrict_freq_mhz_show(struct device input_dev, struct device_attribute attr, char *buf)

restrict_freq_mhz_show: The function of restrict_freq_mhz_show is to retrieve and display the restricted frequency in megahertz for a given device.

parameters: The parameters of this Function. · input_dev: A pointer to the device structure representing the input device for which the frequency is being queried.
· attr: A pointer to the device attribute structure that represents the attribute being accessed.
· buf: A pointer to a buffer where the output string will be written.

Code Description: The restrict_freq_mhz_show function is a static function that is designed to be used in the context of a device attribute in a Linux kernel module. It takes three parameters: a pointer to the device structure (input_dev), a pointer to the device attribute structure (attr), and a character buffer (buf) where the output will be stored.

  1. The function begins by converting the input device pointer (input_dev) to a platform device pointer (pdev) using the to_platform_device macro. This is necessary because the function is intended to work with platform devices specifically.

  2. Next, it retrieves the hardware structure associated with the platform device by calling platform_get_drvdata(pdev). This function returns a pointer to the ieee80211_hw structure, which contains information about the wireless hardware.

  3. The function then accesses the private data structure (openwifi_priv) associated with the ieee80211_hw structure through the priv member. This private structure holds various statistics and configuration parameters for the device.

  4. Finally, the function uses the sprintf function to format the restricted frequency in megahertz (stored in priv->stat.restrict_freq_mhz) into the provided buffer (buf), appending a newline character at the end. The return value of the function is the number of bytes written to the buffer.

This function is typically called when a user space application requests the value of the restrict_freq_mhz attribute, allowing users to read the current restricted frequency setting of the device.

Note: It is important to ensure that the buffer provided to this function is large enough to hold the formatted output, including the newline character. The function assumes that the private data structure has been properly initialized and that the restrict_freq_mhz value is valid.

Output Example: A possible appearance of the code's return value could be: "2400\n", indicating that the restricted frequency is 2400 MHz.

graph TD
    A[Start] --> B[Receive input device and attribute]
    B --> C[Convert input device to platform device]
    C --> D[Get driver data from platform device]
    D --> E[Access private structure from driver data]
    E --> F[Format restrict frequency in MHz]
    F --> G[Return formatted frequency to buffer]
    G --> H[End]

Function restrict_freq_mhz_store(struct device input_dev, struct device_attribute attr, const char *buf, size_t len)

restrict_freq_mhz_store: The function of restrict_freq_mhz_store is to store a frequency value in megahertz for the device's configuration.

parameters: The parameters of this Function. · parameter1: struct device input_dev - A pointer to the device structure representing the device for which the frequency is being set.
· parameter2: struct device_attribute
attr - A pointer to the device attribute structure that represents the attribute being modified.
· parameter3: const char *buf - A pointer to a character buffer containing the string representation of the frequency value to be stored.
· parameter4: size_t len - The length of the string in the buffer.

Code Description: The restrict_freq_mhz_store function is a static function that handles the storage of a frequency value in megahertz for a specific device. It takes in a device structure, a device attribute structure, a buffer containing the frequency value as a string, and the length of that string.

The function begins by converting the input device pointer to a platform device pointer using the to_platform_device macro. This allows access to platform-specific data associated with the device. Next, it retrieves the driver data associated with the platform device by calling platform_get_drvdata, which returns a pointer to the ieee80211_hw structure. This structure contains a pointer to the openwifi_priv structure, which holds private data for the device.

The function then attempts to convert the string in the buffer (buf) to a long integer using kstrtol. The conversion result is stored in the variable readin, and the return value of kstrtol is stored in ret. If the conversion is successful (ret is 0), the value of readin is assigned to the restrict_freq_mhz field of the priv->stat structure, effectively updating the frequency setting for the device.

Finally, the function returns either the result of the conversion (ret) if it is non-zero, indicating an error, or the length of the input string (len) if the operation was successful.

Note: It is important to ensure that the input string in buf is a valid representation of a long integer before calling this function to avoid conversion errors. The function assumes that the caller has validated the input format.

Output Example: If the input buffer contains the string "2400" and the conversion is successful, the function will return the length of the string, which is 4. If the input buffer contains an invalid string, such as "invalid", the function will return a non-zero error code indicating the failure of the conversion.

graph TD
    A[Start] --> B[Receive input device, attribute, buffer, and length]
    B --> C[Convert input device to platform device]
    C --> D[Get driver data from platform device]
    D --> E[Access private data structure from device]
    E --> F[Convert buffer to long integer]
    F --> G[Store converted value in restrict_freq_mhz]
    G --> H[Return result based on conversion success]
    H --> I[End]

Function csma_cfg0_show(struct device input_dev, struct device_attribute attr, char *buf)

csma_cfg0_show: The function of csma_cfg0_show is to retrieve and display the configuration settings related to CSMA (Carrier Sense Multiple Access) from the device's registers.

parameters: The parameters of this Function. · parameter1: struct device input_dev - A pointer to the device structure representing the input device from which the configuration is being read. · parameter2: struct device_attribute attr - A pointer to the device attribute structure that represents the specific attribute being accessed. · parameter3: char *buf - A pointer to a buffer where the output string will be stored.

Code Description: The csma_cfg0_show function is designed to read specific configuration values from the device's registers and format them into a human-readable string. The function begins by converting the input device pointer into a platform device pointer using the to_platform_device macro. This allows access to platform-specific data associated with the device.

Next, the function retrieves the driver data associated with the platform device by calling platform_get_drvdata, which returns a pointer to the ieee80211_hw structure. This structure contains a pointer to the openwifi_priv structure, which holds private data for the device.

The function then reads a 32-bit value from the XPU_REG_FORCE_IDLE_MISC register using the xpu_api->XPU_REG_FORCE_IDLE_MISC_read() function. This value is stored in the reg_val variable. The function subsequently updates the csma_cfg0 field of the priv->stat structure with the value read from the register.

Finally, the function formats the output string using sprintf, which includes various configuration settings extracted from the reg_val variable. The specific bits of reg_val are masked and shifted to extract meaningful information, such as nav_disable, difs_disable, eifs_disable, and others. The formatted string is then returned, which can be displayed to the user or logged for debugging purposes.

Note: It is important to ensure that the device is properly initialized before calling this function, as it relies on the device's state and configuration. Additionally, the buffer provided must be large enough to hold the formatted output string to avoid buffer overflows.

Output Example: A possible appearance of the code's return value could be: "nav_disable 1 difs_disable 0 eifs_disable 1 eifs_by_rx_fail_disable 0 eifs_by_tx_fail_disable 1 cw_override 0 cw override val 15 wait_after_decode_top 255"

graph TD
    A[Start csma_cfg0_show function] --> B[Convert input_dev to platform_device]
    B --> C[Retrieve ieee80211_hw from platform_device]
    C --> D[Access private data from ieee80211_hw]
    D --> E[Read register value from XPU_REG_FORCE_IDLE_MISC]
    E --> F[Store register value in csma_cfg0]
    F --> G[Format output string with register values]
    G --> H[Return formatted output string]
    H --> I[End csma_cfg0_show function]

Function csma_cfg0_store(struct device input_dev, struct device_attribute attr, const char *buf, size_t len)

csma_cfg0_store: The function of csma_cfg0_store is to configure the CSMA (Carrier Sense Multiple Access) settings based on the input provided by the user.

parameters: The parameters of this Function. · input_dev: A pointer to the device structure representing the input device. · attr: A pointer to the device attribute structure associated with the input device. · buf: A pointer to a buffer containing the input data as a string. · len: The length of the input data in bytes.

Code Description: The csma_cfg0_store function is designed to handle the storage of configuration settings related to CSMA for a specific device. It begins by converting the input device pointer to a platform device structure using the to_platform_device function. Subsequently, it retrieves the associated hardware structure (ieee80211_hw) using platform_get_drvdata, which provides access to device-specific data.

The function then initializes several variables: disable_flag, idx_from_msb, reg_val, and readin. It uses kstrtouint to convert the input string (buf) into an unsigned integer (readin) in base 16. The first four bits of readin are extracted to determine the disable_flag, while the next four bits (from the fifth to the eighth) are used to set idx_from_msb.

The function reads the current value of a specific register (XPU_REG_FORCE_IDLE_MISC) using the xpu_api->XPU_REG_FORCE_IDLE_MISC_read() function. Based on the value of disable_flag, it modifies reg_val accordingly. If disable_flag is set (non-zero), the function sets the corresponding bit in reg_val to indicate that the CSMA configuration should be disabled. Conversely, if disable_flag is zero, the function clears that bit.

After modifying reg_val, the function writes the updated value back to the register using xpu_api->XPU_REG_FORCE_IDLE_MISC_write(reg_val). Additionally, it updates the private structure (priv) associated with the device to reflect the new CSMA configuration in priv->stat.csma_cfg0.

Finally, the function returns the length of the input data (len) if the conversion to an unsigned integer was successful; otherwise, it returns the error code from kstrtouint.

Note: It is important to ensure that the input data is correctly formatted as a hexadecimal string to avoid conversion errors. The function assumes that the input will always be valid, and any invalid input may lead to unexpected behavior.

Output Example: If the input buffer contains the string "0x1F", the function would interpret this as a hexadecimal value, set the appropriate bits in the register, and return the length of the input string, which would be 4 (the length of "0x1F").

graph TD
    A[Start csma_cfg0_store function] --> B[Convert input_dev to platform_device]
    B --> C[Get ieee80211_hw from platform_device]
    C --> D[Access private data from ieee80211_hw]
    D --> E[Initialize variables disable_flag, idx_from_msb, reg_val, readin]
    E --> F[Convert buf to unsigned integer readin]
    F --> G[Extract disable_flag from readin]
    G --> H[Extract idx_from_msb from readin]
    H --> I[Read current reg_val from XPU_REG_FORCE_IDLE_MISC]
    I --> J{Check disable_flag}
    J -->|True| K[Set bit in reg_val based on idx_from_msb]
    J -->|False| L[Clear bit in reg_val based on idx_from_msb]
    K --> M[Write updated reg_val to XPU_REG_FORCE_IDLE_MISC]
    L --> M
    M --> N[Update csma_cfg0 in private data structure]
    N --> O{Check if ret is non-zero}
    O -->|True| P[Return ret]
    O -->|False| Q[Return len]
    P --> R[End csma_cfg0_store function]
    Q --> R

Function cw_max_min_cfg_show(struct device input_dev, struct device_attribute attr, char *buf)

cw_max_min_cfg_show: The function of cw_max_min_cfg_show is to display the current configuration of the contention window (CW) maximum and minimum values for different queues in the system.

parameters: The parameters of this Function. · parameter1: struct device input_dev - A pointer to the device structure representing the input device. · parameter2: struct device_attribute attr - A pointer to the device attribute structure that represents the attribute being accessed. · parameter3: char *buf - A pointer to the buffer where the output string will be stored.

Code Description: The cw_max_min_cfg_show function retrieves and formats the contention window maximum and minimum configuration values for different queues from the hardware and the software state.

  1. The function begins by converting the input device pointer to a platform device pointer using the to_platform_device macro. This allows access to platform-specific data associated with the device.
  2. It then retrieves the ieee80211_hw structure associated with the platform device using the platform_get_drvdata function. This structure contains hardware-specific information, including a pointer to the private data structure (openwifi_priv).
  3. The function reads the CSMA configuration register value using the xpu_api->XPU_REG_CSMA_CFG_read() function, which returns a 32-bit register value (reg_val).
  4. The function formats the output string to display the maximum and minimum contention window values for queues q3 to q0. It calculates these values by shifting and masking bits from the reg_val, applying a left shift operation to derive the maximum and minimum values.
  5. The formatted string is written to the buffer (buf) using sprintf, which returns the number of characters written (ret_size).
  6. If the private structure's cw_max_min_cfg field is set, the function retrieves this value and formats it similarly, appending the results to the buffer.
  7. Finally, the function returns the total number of characters written to the buffer, which can be used by the caller to determine the length of the output.

Note: It is important to ensure that the buffer provided to the function is large enough to hold the formatted output to avoid buffer overflows. The function assumes that the xpu_api and the private structure are properly initialized before being called.

Output Example: A possible appearance of the code's return value could be: "FPGA cw max min for q3 to q0: 15 15; 15 15; 15 15; 15 15 FPGA cw max min for q3 to q0: 0x12345678 SYSFS cw max min for q3 to q0: 15 15; 15 15; 15 15; 15 15 SYSFS cw max min for q3 to q0: 0x87654321"

graph TD
    A[Start cw_max_min_cfg_show] --> B[Get platform device from input_dev]
    B --> C[Get ieee80211_hw from platform device]
    C --> D[Get openwifi_priv from ieee80211_hw]
    D --> E[Read CSMA_CFG register value]
    E --> F[Format FPGA cw max min values into buf]
    F --> G[Check if cw_max_min_cfg is set in priv]
    G -->|Yes| H[Get cw_max_min_cfg value from priv]
    H --> I[Format SYSFS cw max min values into buf]
    G -->|No| J[Skip SYSFS formatting]
    I --> K[Return total size of formatted data]
    J --> K
    E --> K
    K --> Z[End cw_max_min_cfg_show]

Function cw_max_min_cfg_store(struct device input_dev, struct device_attribute attr, const char *buf, size_t len)

cw_max_min_cfg_store: The function of cw_max_min_cfg_store is to store the configuration value for the contention window maximum and minimum settings in a device.

parameters: The parameters of this Function. · input_dev: A pointer to the device structure representing the input device for which the configuration is being set.
· attr: A pointer to the device attribute structure associated with the configuration.
· buf: A pointer to a character buffer containing the input data to be processed.
· len: The length of the input data in the buffer.

Code Description: The cw_max_min_cfg_store function is a static function that handles the storage of configuration values related to the contention window settings for a wireless device. It takes four parameters: a pointer to the input device, a pointer to the device attribute, a buffer containing the input data, and the length of that data.

  1. The function begins by converting the input device pointer to a platform device pointer using the to_platform_device macro. This allows access to platform-specific data associated with the device.
  2. It retrieves the hardware structure associated with the device by calling platform_get_drvdata, which returns a pointer to the ieee80211_hw structure.
  3. The private data structure openwifi_priv is accessed through the priv member of the ieee80211_hw structure.
  4. The function then declares a variable readin of type u32 to store the parsed configuration value. It uses the kstrtouint function to convert the input string from the buffer buf into an unsigned integer, interpreting it as a hexadecimal value (base 16). The result is stored in readin, and the return value of kstrtouint is stored in ret.
  5. If the conversion is successful, the function updates the cw_max_min_cfg member of the priv->stat structure with the new value of readin.
  6. If readin is non-zero, the function calls xpu_api->XPU_REG_CSMA_CFG_write to write the new configuration value to the hardware register.
  7. Finally, the function returns either the result of the conversion (if it failed) or the length of the input data (len), indicating successful processing.

Note: It is important to ensure that the input data in the buffer is correctly formatted as a hexadecimal string to avoid conversion errors. The function assumes that the caller has validated the input before invoking this function.

Output Example: If the input buffer contains the string "1A", the function will convert this to the integer value 26 (in decimal), update the configuration, and return the length of the input string, which would be 2. If the input buffer contains an invalid string, the function will return an error code indicating the failure of the conversion.

graph TD
    A[Start function cw_max_min_cfg_store] --> B[Convert input_dev to platform_device]
    B --> C[Get drvdata from platform_device]
    C --> D[Access private data from ieee80211_hw]
    D --> E[Convert input buffer to unsigned integer]
    E --> F{Conversion successful?}
    F -->|Yes| G[Store readin in cw_max_min_cfg]
    F -->|No| H[Return conversion error code]
    G --> I{readin is non-zero?}
    I -->|Yes| J[Write readin to XPU_REG_CSMA_CFG]
    I -->|No| K[Skip writing to XPU_REG_CSMA_CFG]
    J --> L[Return length of input buffer]
    K --> L
    H --> L
    L[End function cw_max_min_cfg_store]

Function dbg_ch0_show(struct device input_dev, struct device_attribute attr, char *buf)

dbg_ch0_show: The function of dbg_ch0_show is to retrieve and display the debug channel 0 statistics from the device's private data structure.

parameters: The parameters of this Function. · input_dev: A pointer to the device structure representing the input device from which the statistics are being retrieved.
· attr: A pointer to the device attribute structure that represents the attribute being accessed.
· buf: A pointer to a character buffer where the output string will be written.

Code Description: The dbg_ch0_show function is a static function that returns the debug channel 0 statistics for a specific device. It takes three parameters: a pointer to the input device, a pointer to the device attribute, and a buffer where the output will be stored.

Inside the function, the input device is first converted to a platform device using the to_platform_device macro. This conversion allows access to platform-specific data associated with the device. Next, the function retrieves the hardware structure (ieee80211_hw) associated with the platform device by calling platform_get_drvdata, which returns a pointer to the driver data stored in the platform device.

From the hardware structure, the function accesses the private data structure (openwifi_priv) through the priv member. This private structure contains various statistics, including the debug channel 0 statistics stored in priv->stat.dbg_ch0.

Finally, the function formats the debug channel 0 statistic as an unsigned integer and writes it to the provided buffer using the sprintf function, appending a newline character at the end. The function returns the number of bytes written to the buffer, which is the length of the formatted string.

Note: It is important to ensure that the buffer provided to the function is large enough to hold the formatted output to avoid buffer overflows. The function is typically called in the context of a sysfs interface, allowing users to read the debug statistics through the filesystem.

Output Example: An example of the output that might be returned by this function could be:
"42\n"
This indicates that the debug channel 0 statistic is 42.

graph TD
    A[Start] --> B[Receive input device and attribute]
    B --> C[Convert input device to platform device]
    C --> D[Retrieve driver data from platform device]
    D --> E[Access private data structure from hardware]
    E --> F[Format debug channel 0 value into buffer]
    F --> G[Return formatted buffer content]
    G --> H[End]

Function dbg_ch0_store(struct device input_dev, struct device_attribute attr, const char *buf, size_t len)

dbg_ch0_store: The function of dbg_ch0_store is to store a debug channel value from user input into the device's private structure.

parameters: The parameters of this Function. · parameter1: struct device input_dev - A pointer to the device structure representing the input device. · parameter2: struct device_attribute attr - A pointer to the device attribute structure associated with the device. · parameter3: const char *buf - A pointer to a buffer containing the input data as a string. · parameter4: size_t len - The length of the input data in the buffer.

Code Description: The dbg_ch0_store function is designed to handle the storage of a debug channel value for a specific device. It begins by converting the input device pointer (input_dev) to a platform device pointer (pdev) using the to_platform_device function. This allows access to platform-specific data associated with the device. Next, it retrieves the hardware structure (dev) associated with the platform device using platform_get_drvdata, which provides access to the device's driver data.

The function then accesses the private data structure (priv) of the device, which contains various statistics, including the debug channel value. The input string (buf) is converted to a long integer using the kstrtol function, which also checks for conversion errors and stores the result in the variable readin. The debug channel value is then updated in the private structure by assigning readin to priv->stat.dbg_ch0.

The function contains commented-out lines that suggest additional operations that could be performed with the readin value, such as writing to specific registers related to the device's functionality. Finally, the function returns the length of the input data if the conversion was successful; otherwise, it returns an error code if the conversion failed.

Note: It is important to ensure that the input data provided in the buffer is a valid integer representation. If the input is not valid, the function will return an error code, and the debug channel value will not be updated.

Output Example: If the input buffer contains the string "42" and the length is 2, the function will successfully convert this to the long integer 42, update priv->stat.dbg_ch0 to 42, and return 2, indicating that two bytes were processed.

graph TD
    A[Start dbg_ch0_store function] --> B[Convert input_dev to platform_device]
    B --> C[Get drvdata from platform_device]
    C --> D[Access private data from ieee80211_hw]
    D --> E[Convert buf to long using kstrtol]
    E --> F[Store readin value in priv->stat.dbg_ch0]
    F --> G[Return ret if not zero, else return len]
    G --> H[End dbg_ch0_store function]

Function dbg_ch1_show(struct device input_dev, struct device_attribute attr, char *buf)

dbg_ch1_show: The function of dbg_ch1_show is to retrieve and display the debug channel 1 statistics from the device's private data structure.

parameters: The parameters of this Function. · parameter1: struct device input_dev - A pointer to the device structure representing the input device from which the statistics are being retrieved.
· parameter2: struct device_attribute
attr - A pointer to the device attribute structure that represents the specific attribute being accessed.
· parameter3: char *buf - A pointer to a buffer where the output string will be stored.

Code Description: The dbg_ch1_show function is defined as a static function that returns a ssize_t type, which is typically used for representing the size of data in bytes. The function takes three parameters: a pointer to the device structure (input_dev), a pointer to the device attribute structure (attr), and a character buffer (buf) where the output will be written.

Inside the function, the input device is first converted to a platform device using the to_platform_device macro. This conversion allows access to platform-specific data associated with the device. The function then retrieves the driver data associated with the platform device by calling platform_get_drvdata, which returns a pointer to the ieee80211_hw structure. This structure contains a pointer to the private data structure (openwifi_priv) that holds various statistics and configuration settings for the device.

The function specifically accesses the debug channel 1 statistic from the private data structure using priv->stat.dbg_ch1. It then formats this statistic as an unsigned integer and writes it to the provided buffer (buf) using the sprintf function. The output is followed by a newline character to ensure proper formatting when displayed.

Finally, the function returns the number of bytes written to the buffer, which is the return value of the sprintf function.

Note: It is important to ensure that the buffer provided to the function is large enough to hold the formatted output, including the newline character. Failure to do so may result in buffer overflow and undefined behavior.

Output Example: An example of the possible appearance of the code's return value could be "42\n", where "42" represents the value of priv->stat.dbg_ch1, indicating that the debug channel 1 statistic is 42.

graph TD
    A[Start] --> B[Receive input_dev and attr]
    B --> C[Convert input_dev to platform_device]
    C --> D[Retrieve ieee80211_hw from platform_device]
    D --> E[Access openwifi_priv from ieee80211_hw]
    E --> F[Format output with priv->stat.dbg_ch1]
    F --> G[Return formatted output]
    G --> H[End]

Function dbg_ch1_store(struct device input_dev, struct device_attribute attr, const char *buf, size_t len)

dbg_ch1_store: The function of dbg_ch1_store is to store a debug channel value from user input into the device's private structure.

parameters: The parameters of this Function. · parameter1: struct device input_dev - A pointer to the device structure representing the input device.
· parameter2: struct device_attribute
attr - A pointer to the device attribute structure, which provides context for the attribute being written to.
· parameter3: const char *buf - A pointer to a buffer containing the user input data to be processed.
· parameter4: size_t len - The length of the input data in the buffer.

Code Description: The dbg_ch1_store function is designed to handle the storage of a debug channel value provided by the user through a sysfs interface. The function begins by converting the input device pointer (input_dev) to a platform device pointer (pdev) using the to_platform_device macro. This conversion allows access to platform-specific data associated with the device.

Next, the function retrieves the hardware structure (dev) associated with the platform device by calling platform_get_drvdata, which returns a pointer to the driver data. The driver data contains a pointer to the private structure (priv) of the openwifi driver, which holds various statistics and configuration parameters.

The function then declares a long variable (readin) to store the converted input value. It uses the kstrtol function to convert the string input from the buffer (buf) into a long integer, storing the result in readin. The kstrtol function also returns a status code (ret) indicating whether the conversion was successful or not.

After successfully converting the input, the function assigns the value of readin to the debug channel field (dbg_ch1) within the priv structure. This effectively updates the debug channel value based on user input.

Finally, the function returns the length of the input data (len) if the conversion was successful (ret is 0), or the error code (ret) if the conversion failed. This return value indicates the outcome of the operation to the caller.

Note: It is important to ensure that the input provided in the buffer is a valid integer representation to avoid conversion errors. The function assumes that the input is well-formed and does not perform additional validation on the input data.

Output Example: If the user inputs "42" and the conversion is successful, the function will return 2 (the length of the input string), and the value of priv->stat.dbg_ch1 will be updated to 42. If the input is invalid, such as "abc", the function will return a negative error code indicating the failure of the conversion.

graph TD
    A[Start] --> B[Receive input parameters]
    B --> C[Convert input device to platform device]
    C --> D[Get driver data from platform device]
    D --> E[Access private structure from device]
    E --> F[Convert input buffer to long integer]
    F --> G[Store value in private structure]
    G --> H[Check conversion result]
    H -->|Success| I[Return length]
    H -->|Failure| J[Return error code]
    I --> K[End]
    J --> K

Function dbg_ch2_show(struct device input_dev, struct device_attribute attr, char *buf)

dbg_ch2_show: The function of dbg_ch2_show is to retrieve and display the debug channel 2 statistics from the device's private data structure.

parameters: The parameters of this Function. · input_dev: A pointer to the device structure representing the input device for which the debug information is being requested.
· attr: A pointer to the device attribute structure that represents the specific attribute being accessed.
· buf: A pointer to a character buffer where the output string will be written.

Code Description: The dbg_ch2_show function is a static function that returns the debug channel 2 statistics for a specific device. It takes three parameters: a pointer to the device structure (input_dev), a pointer to the device attribute structure (attr), and a character buffer (buf) where the output will be stored.

The function begins by converting the input device pointer to a platform device pointer using the to_platform_device macro. This is necessary because the function is designed to work with platform devices, which are a specific type of device in the Linux kernel. Next, it retrieves the hardware structure associated with the platform device by calling platform_get_drvdata, which returns a pointer to the ieee80211_hw structure. This structure contains various fields related to the wireless hardware, including a pointer to the private data structure (openwifi_priv).

The private data structure holds the statistics for the device, including the debug channel 2 statistics. The function accesses the dbg_ch2 field within the stat member of the private data structure and writes its value to the provided buffer (buf) using the sprintf function. The value is formatted as an unsigned integer followed by a newline character. Finally, the function returns the number of bytes written to the buffer, which is the return value of sprintf.

Note: It is important to ensure that the buffer provided to the function is large enough to hold the formatted output. The function assumes that the private data structure has been properly initialized and that the dbg_ch2 field contains valid data.

Output Example: An example of the output returned by the function could be "42\n", where "42" represents the value of the debug channel 2 statistics stored in priv->stat.dbg_ch2.

graph TD
    A[Start] --> B[Receive input device and attribute]
    B --> C[Convert input device to platform device]
    C --> D[Get driver data from platform device]
    D --> E[Access private structure from hardware device]
    E --> F[Format debug channel 2 statistics into buffer]
    F --> G[Return formatted buffer]
    G --> H[End]

Function dbg_ch2_store(struct device input_dev, struct device_attribute attr, const char *buf, size_t len)

dbg_ch2_store: The function of dbg_ch2_store is to store a debug channel value from user input into the device's private structure.

parameters: The parameters of this Function. · parameter1: struct device input_dev - A pointer to the device structure representing the input device. · parameter2: struct device_attribute attr - A pointer to the device attribute structure that represents the attribute being accessed. · parameter3: const char *buf - A pointer to a buffer containing the user input data as a string. · parameter4: size_t len - The length of the input data in the buffer.

Code Description: The dbg_ch2_store function is a static function that handles the storage of a debug channel value provided by the user through a sysfs interface. The function begins by converting the input device pointer (input_dev) to a platform device pointer (pdev) using the to_platform_device macro. This allows access to platform-specific data associated with the device.

Next, the function retrieves the hardware structure (dev) associated with the platform device by calling platform_get_drvdata, which returns a pointer to the device's driver data. The private data structure (priv) is then accessed from the hardware structure, which contains various statistics and settings for the device.

The function reads the input string from the buffer (buf) and attempts to convert it to a long integer using the kstrtol function. This function also returns a status code (ret) indicating whether the conversion was successful. The converted value is stored in the variable readin.

The debug channel value (dbg_ch2) within the private structure (priv->stat) is then updated with the value readin. Finally, the function returns either the status code (ret) if there was an error during conversion, or the length of the input data (len) if the operation was successful.

Note: It is important to ensure that the input data provided in the buffer is a valid integer representation to avoid conversion errors. The function assumes that the input is well-formed and does not perform extensive error checking beyond the conversion.

Output Example: If the input buffer contains the string "5" and the conversion is successful, the function would return the length of the input (1 in this case), and the value stored in priv->stat.dbg_ch2 would be updated to 5. If the input buffer contains an invalid integer, the function would return a non-zero error code indicating the failure of the conversion.

graph TD
    A[Start function dbg_ch2_store] --> B[Convert input_dev to platform_device]
    B --> C[Get ieee80211_hw from platform_device]
    C --> D[Access openwifi_priv from ieee80211_hw]
    D --> E[Convert buf to long using kstrtol]
    E --> F[Store readin in priv->stat.dbg_ch2]
    F --> G[Check if ret is non-zero]
    G -->|Yes| H[Return ret]
    G -->|No| I[Return len]
    H --> J[End function]
    I --> J