Skip to content

Telink MAC to Access Code Algorithm Update Guide


Update Overview

The Telink team has optimised the Access Code generation algorithm to avoid non-conforming Access Code that could affect the success of the product's wireless communications.

The updated algorithm ensures that the Access Code generated by each MAC complies with the BLE spec and increases the total number of Access Code, reducing the probability of collisions.

The following is a user guide for updating the Access Code generation algorithm in 2.4GHz low latency related SDKs and projects.

Update Steps

Add the New Access Code to Project

Copy mac2ac.c into the vendor/common directory as shown below.

mac2ac.c path

Replace the Old Algorithm

The algorithm function of old MAC generating access code is: tsync_get_ac_chn_from_mac, located in the application/tws directory, its function is to generate Access Code for communication and the re-connecting channel from the mac address through the algorithm.

The prototype of this function is:

int tsync_get_ac_chn_from_mac (unsigned char *mac, unsigned char *ac, unsigned char *chn)
{
   int c = tsync_crc16 (0xffff, mac, 6)
   c = tsync_access_code_16to32 (c);
   tmemcpy (ac, &c, 4);
   *chn = tsync_crc16 (0x0, mac, 6) % 37;
   if (*chn == 2)
   {
        (*chn)++;
    }
    return 1;
}

Modify it to:

int tsync_get_ac_chn_from_mac (unsigned char *mac, unsigned char *ac, unsigned char *chn)
{
#if MAC2AC_NEW_ALGORITHM
    extern u32 mac2ac(u8* mac);
    u32 c = mac2ac(mac);
#else
    int c = tsync_crc16 (0xffff, mac, 6);
    c = tsync_access_code_16to32 (c);
#endif
    tmemcpy (ac, &c, 4);
    *chn = tsync_crc16 (0x0, mac, 6) % 37;
    if (*chn == 2)
    {
        (*chn)++;
    }
    return 1;
}

Then add the following macro definition to app_config.h.

#define         MAC2AC_NEW_ALGORITHM                    1

Verify the Algorithm of New MAC to Access Code (Method 1)

Step 1 Burn the MAC address: 0xA4C138000000, burn it via the BDT tool shown as below:

Burn the MAC address

Step 2 Add the following two lines of print to the async_init function.

    my_dump_str_data(1, "MAC", mac, 6);
    my_dump_str_data(1, "AC", &ac, 4);

Step 3 Compile & burn & run, and when ported correctly, you can see the MAC and AC results printed as

MAC: a4 c1 38 00 00 00 
AC:  b1 4d 6c a2 

Verify the Algorithm of New MAC to Access Code (Method 2)

Step 1 Add the following function to the code and call it in the initialization function (user_init):

void verify_mac2ac_algorithm()
{
    u8 mac[6] = {0xA4, 0xC1, 0x38, 0x00, 0x00, 0x00};
    u32 ac = 0;
    u8 chn = 0;
    tsync_get_ac_chn_from_mac(mac, (u8 *)&ac, &chn);
    my_dump_str_data(1, "MAC", mac, 6);
    my_dump_str_data(1, "AC", &ac, 4);
}

Step 2 Compile & burn & run, and when ported correctly, you can see the MAC and AC results printed as:

MAC: a4 c1 38 00 00 00 
AC:  b1 4d 6c a2