Set CSR Bluecore MAC Address using Microsoft Bluetooth Stack

Topics: Bluetooth - Microsoft
Apr 18, 2013 at 10:42 AM
I am using Microsoft Bluetooth Stack sending HCI IOCTL_BTH_HCI_VENDOR_COMMAND, but got ERROR_INVALID_PARAMETER return.

My function listed below:

DWORD SetMacAddress(HANDLE hRadio, PUSHORT macaddr, WORD wMfg, UCHAR lmpVersion)
{
PBTH_VENDOR_SPECIFIC_COMMAND pVendorSpecificCommand;
DWORD dwSize = sizeof(BTH_VENDOR_SPECIFIC_COMMAND) + 253;
unsigned char rp[254];
unsigned char cmd[] = { 0x02, 0x00, 0x0c, 0x00, 0x11, 0x47, 0x03, 0x70,
        0x00, 0x00, 0x01, 0x00, 0x04, 0x00, 0x00, 0x00,
        0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };


pVendorSpecificCommand = (PBTH_VENDOR_SPECIFIC_COMMAND)::LocalAlloc(LPTR, dwSize);
if (NULL == pVendorSpecificCommand)
    return GetLastError();

pVendorSpecificCommand->ManufacturerId = wMfg;
pVendorSpecificCommand->LmpVersion = lmpVersion;
pVendorSpecificCommand->MatchAnySinglePattern = FALSE;
pVendorSpecificCommand->HciHeader.OpCode = 0x3F;
pVendorSpecificCommand->HciHeader.TotalParameterLength = 27;

PUSHORT psData = (PUSHORT)pVendorSpecificCommand->Data;
PBYTE pMacAddr = (PBYTE)macaddr;
PBTH_VENDOR_PATTERN pPattern = (PBTH_VENDOR_PATTERN)pVendorSpecificCommand->Data;
pPattern->Offset = 2;
pPattern->Size = 25;

cmd[16] = pMacAddr[0];
cmd[17] = pMacAddr[1];
cmd[18] = pMacAddr[2];
cmd[19] = pMacAddr[3];
cmd[20] = pMacAddr[4];
cmd[21] = pMacAddr[5];
cmd[22] = pMacAddr[6];
cmd[23] = pMacAddr[7];

pPattern->Pattern[0] = 0xC2;
memcpy(&pPattern->Pattern[1], cmd, sizeof(cmd));

DWORD dwErrCode = DeviceIoControl(hRadio, IOCTL_BTH_HCI_VENDOR_COMMAND, pVendorSpecificCommand, dwSize, rp, 254,  0, NULL); //fail
if (!dwErrCode)
{
    dwErrCode = GetLastError();
    PrintErrorMessage(_T("IOCTL_BTH_HCI_VENDOR_COMMAND)\r\n"), dwErrCode);
}

::LocalFree(pVendorSpecificCommand);
return dwErrCode;
}

I have in doubt in pVendorSpecificCommand->HciHeader.OpCode = 0x3F, I don't know whether I all the parameter setup correctly.

Regards
BK
Apr 19, 2013 at 10:44 AM
After OpCode change to 0xFC00, now return error (0x79) The semaphore timeout period has expired.

DWORD SetBthMacAddress(HANDLE hRadio, PBYTE pMacAddr, PBTH_LOCAL_RADIO_INFO pLocalRadioInfo)
{
PBTH_VENDOR_SPECIFIC_COMMAND pVendorSpecificCommand;
DWORD dwSize = sizeof(BTH_VENDOR_SPECIFIC_COMMAND) + 24 + 2 + 3;
BYTE resp[254];
BYTE cmd[] = { 0x02, 0x00, 0x0c, 0x00, 0x23, 0x01, 0x03, 0x70,
               0x00, 0x00, 0x01, 0x00, 0x04, 0x00, 0x00, 0x00,
               0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };

pVendorSpecificCommand = (PBTH_VENDOR_SPECIFIC_COMMAND)::LocalAlloc(LPTR, dwSize);
if (NULL == pVendorSpecificCommand)
    return GetLastError();
pVendorSpecificCommand->ManufacturerId = pLocalRadioInfo->radioInfo.mfg;
pVendorSpecificCommand->LmpVersion = pLocalRadioInfo->radioInfo.lmpVersion;
pVendorSpecificCommand->MatchAnySinglePattern = TRUE;
pVendorSpecificCommand->HciHeader.OpCode = 0xFC00;
pVendorSpecificCommand->HciHeader.TotalParameterLength = 27 + 3;

PBTH_VENDOR_PATTERN pPattern = (PBTH_VENDOR_PATTERN)pVendorSpecificCommand->Data;
pPattern->Offset = 2;
pPattern->Size = 25 + 3;

cmd[16] = pMacAddr[3];
cmd[17] = 0;
cmd[18] = pMacAddr[5];
cmd[19] = pMacAddr[4];
cmd[20] = pMacAddr[2];
cmd[21] = 0;
cmd[22] = pMacAddr[1];
cmd[23] = pMacAddr[0];

pPattern->Pattern[0] = 0x00;
pPattern->Pattern[1] = 0xFC;
pPattern->Pattern[2] = 25;
pPattern->Pattern[3] = 0xC2;
memcpy(&pPattern->Pattern[4], cmd, sizeof(cmd));
//pPattern->Pattern[0] = 0xC2;
//memcpy(&pPattern->Pattern[1], cmd, sizeof(cmd));

DWORD dwErrCode = DeviceIoControl(hRadio, IOCTL_BTH_HCI_VENDOR_COMMAND, pVendorSpecificCommand, dwSize, resp, 254,  0, NULL); //fail
if (!dwErrCode)
{
    dwErrCode = GetLastError();
    _tprintf(_T("IOCTL_BTH_HCI_VENDOR_COMMAND) return error (%#X) %s\n"), dwErrCode, getWinErrorMessage(dwErrCode));
}

::LocalFree(pVendorSpecificCommand);
return dwErrCode ? ERROR_SUCCESS : dwErrCode;
}

Anyone familiar with Microsoft Bluetooth Stack with CSR bluecore chip Vendor Specific command?