Esempio n. 1
0
BtStatus RADIO_Init(RadioCallback Callback)
{
    BtStatus status;

    radioCallback = Callback;
    radioState = RADIO_STATE_INIT;

#if defined(BTMTK_ON_WISE)
    switch(getRadioType())
    {
#if defined (__BTMODULE_MT6601__) || defined (__BTMODULE_MT6611__) || defined (__BTMODULE_MT6612__) || defined (__BTMODULE_MT6616__) || defined (__BTMODULE_MT6236__) || defined (__BTMODULE_MT6255__) || defined (__BTMODULE_MT6276__) || defined (__BT_BTWIFI_COMBO_CHIP__) 
        case RADIO_TYPE_MTKBT_UART:
            status = GORM_Init();
            break;
#endif
        default:
            status = RADIO_Init_Default();
            break;
    }
#elif defined(BTMTK_ON_LINUX)
    #ifdef __BT_TRANSPORT_DRV__
    #else /* __BT_TRANSPORT_DRV__ */
    switch(getRadioType())
    {
    #if defined (__BTMODULE_MT6601__) || defined (__BTMODULE_MT6611__) || defined (__BTMODULE_MT6612__) || defined (__BTMODULE_MT6616__) || defined (__BTMODULE_MT6236__) || defined (__BTMODULE_MT6255__) || defined (__BTMODULE_MT6276__) || defined (__BT_BTWIFI_COMBO_CHIP__) 
        case RADIO_TYPE_MTKBT_UART:
        status = GORM_Init();
        if(status != BT_STATUS_SUCCESS)
            return status;
        break;
    #endif
    default:
        break;
    }
    #endif /* __BT_TRANSPORT_DRV__ */
    status = RADIO_Init_Default();
#else
    status = RADIO_Init_Default();
#endif  /* BTMTK_ON_WISE */
    return status;
}
Esempio n. 2
0
BOOL BT_InitDevice(
    HANDLE  hComPortFile,
    PBYTE   ucNvRamData,
    DWORD   dwBaud,
    DWORD   dwHostBaud,
    DWORD   dwUseFlowControl,
    SETUP_UART_PARAM  setup_uart_param
    )
{
    DWORD   dwStatus;
    LPBYTE  pbPatchExtBin = NULL;
    DWORD   dwPatchExtLen = 0;
    FILE*   pPatchExtFile = NULL;
    LPBYTE  pbPatchBin = NULL;
    DWORD   dwPatchLen = 0;
    FILE*   pPatchFile = NULL;
    
    printf("BT_InitDevice\r\n");

#ifndef MTK_COMBO_SUPPORT
    tcflush(hComPortFile, TCIOFLUSH);
    
    pSetup_uart_param = setup_uart_param;
    if(pSetup_uart_param == NULL){
        printf("UART setup callback is null\r\n");
        return FALSE;
    }
    
    printf("BT load firmware patch\r\n");

#if BT_PATCH_EXT_ENABLE
    pPatchExtFile = fopen(BT_UPDATE_PATCH_EXT_FILE_NAME, "rb"); 
    
    /* if there is no adhoc file, use built-in patch file under system etc firmware */
    if(pPatchExtFile == NULL){
        pPatchExtFile = fopen(BT_BUILT_IN_PATCH_EXT_FILE_NAME, "rb");
        if(pPatchExtFile != NULL) {
            printf("Open %s\r\n", BT_BUILT_IN_PATCH_EXT_FILE_NAME);
        }
        else {
            printf("Can't get valid patch ext file\r\n");
        }
    }
    else {
        printf("Open %s\r\n", BT_UPDATE_PATCH_EXT_FILE_NAME);       
    }
    
    /* file exists */
    if(pPatchExtFile != NULL){
        if(fseek(pPatchExtFile, 0, SEEK_END) != 0){
            printf("fseek patch ext file fails errno: %d\n", errno);
        }
        else{
            long lFileLen = 0;
            
            lFileLen = ftell(pPatchExtFile);
            if (lFileLen > 0){
                printf("Patch ext file size %d\n", (int)lFileLen);
                rewind(pPatchExtFile);
                
                pbPatchExtBin = (unsigned char*)malloc(lFileLen);
                if (pbPatchExtBin){
                    size_t szReadLen = fread(pbPatchExtBin, 1, lFileLen, pPatchExtFile);
                
                    dwPatchExtLen = szReadLen;
                    if(szReadLen != (size_t)lFileLen){
                        printf("fread patch ext len error, file len: %d, read len: %d\n", (int)lFileLen, (int)szReadLen);
                        free(pbPatchExtBin);
                        pbPatchExtBin = NULL;
                        dwPatchExtLen = 0;
                    }
                }else{
                    printf("Allocate patch ext memory fails\n");
                }
            }else{
                printf("Patch ext error len %d\n", (int)lFileLen);
            }
        }
    }
#endif

    /* Use data directory first. for future update test convinience */
    pPatchFile = fopen(BT_UPDATE_PATCH_FILE_NAME, "rb"); 

    /* if there is no adhoc file, use built-in patch file under system etc firmware */
    if(pPatchFile == NULL){
        pPatchFile = fopen(BT_BUILT_IN_PATCH_FILE_NAME, "rb");
        if(pPatchFile != NULL) {
            printf("Open %s\r\n", BT_BUILT_IN_PATCH_FILE_NAME);
        }
        else {
            printf("Can't get valid patch file\r\n");
        }
    }
    else {
        printf("Open %s\r\n", BT_UPDATE_PATCH_FILE_NAME);       
    }
    
    /* file exists */
    if(pPatchFile != NULL){
        if(fseek(pPatchFile, 0, SEEK_END) != 0){
            printf("fseek patch file fails errno: %d\n", errno);
        }
        else{
            long lFileLen = 0;
            
            lFileLen = ftell(pPatchFile);
            if (lFileLen > 0){
                printf("Patch file size %d\n", (int)lFileLen);
                /* back to file beginning */
                rewind(pPatchFile);
               printf ("Rewinded\n"); 
                pbPatchBin = (unsigned char*)malloc(lFileLen);
                if(pbPatchBin){
                    size_t szReadLen = 0;
                    szReadLen = fread(pbPatchBin, 1, lFileLen, pPatchFile);
                
                    dwPatchLen = szReadLen;
                    if(szReadLen != (size_t)lFileLen){
                        printf("fread patch len error, file len: %d, read len: %d\n", (int)lFileLen, (int)szReadLen);
                        free(pbPatchBin);
                        pbPatchBin = NULL;
                        dwPatchLen = 0;
                    }
                }else{
                    printf("Allocate patch memory fails\n");
                }                
            }else{
                printf("Patch error len %d\n", (int)lFileLen);
            }
        }
    }
#endif


               printf ("GORM_INIT\n"); 
    /* Invoke HCI transport entrance */
    dwStatus = GORM_Init(
        hComPortFile,
        pbPatchExtBin,   //patch ext 
        dwPatchExtLen,   
        pbPatchBin,      //patch
        dwPatchLen,
        ucNvRamData,
        dwBaud,
        dwHostBaud,
        dwUseFlowControl
        );


#ifndef MTK_COMBO_SUPPORT
    if(pbPatchExtBin){
        free(pbPatchExtBin);
        pbPatchExtBin = NULL;
    }  
    
    if(pPatchExtFile){
        fclose(pPatchExtFile);
        pPatchExtFile = NULL;
    }
    
    if(pbPatchBin){
        free(pbPatchBin);
        pbPatchBin = NULL;
    }
    
    if(pPatchFile){
        fclose(pPatchFile);
        pPatchFile = NULL;
    }
#endif
    
    if(dwStatus != 0 ){
        printf("GORM fails return code %d\r\n", (int)dwStatus);
        return FALSE;
    }
    
    return TRUE;
}