Search code examples
cnetworkingmacrosdriverwireless

how to disable fast frames in ath5k wireless driver


By default, fast frames are enabled in ath5k. (http://wireless.kernel.org/en/users/Drivers/ath5k) I have found the macro which disables it

#define AR5K_EEPROM_FF_DIS(_v)      (((_v) >> 2) & 0x1

The question is what do I do with it? Do I replace the above line with

#define AR5K_EEPROM_FF_DIS(_v)  1

?

Do I compile it passing some parameter?

The bit-shift expression confuses me. Is _v a variable?

The question is more general as to how to deal with such macros in drivers. I've seen them in other codes too and always got confused.


Solution

  • Ok, I try to explain with a simplified example

    #include <stdio.h>
    
    /* Just for print in binary mode */
    char *chartobin(unsigned char c)
    {
        static char a[9];
        int i;
    
        for (i = 0; i < 8; i++)
              a[7 - i] = (c & (1 << i)) == (1 << i) ? '1' : '0';
        a[8] = '\0';
        return a;
    }
    
    int main(void)
    {
        unsigned char u = 0xf;
    
        printf("%s\n", chartobin(u)); 
        u >>= 2; // Shift bits 2 positions (to the right)
        printf("%s\n", chartobin(u));       
        printf("%s\n", chartobin(u & 0x1)); // Check if the last bit is on
    
        return 0;
    }
    

    Output:

    00001111
    00000011
    00000001
    

    Do I replace the above line with #define AR5K_EEPROM_FF_DIS(_v) 1?

    Nooooo!!

    If you initialize u with 0xb instead of 0xf you get:

    00001011
    00000010
    00000000
    

    As you can see (((_v) >> 2) & 0x1 != 1