/* * File: ble_hci.c * Author: Red Bear Labs * modified by Brandon and Nick * Comments: Sends passed values out to UART to interface with HCI Bluetooth LE chip * * Revision history: Last Updated 12/13/15 * Changed to C file and updated dependecies * Code originally written for Arduinio, modified all code to * be able to write out using PIC32 and protothreads */ //#define _ALLOW_KEYWORD_MACROS #include "typedef.h" #include "ble_hci.h" #include #include #include #if defined(__AVR_ATmega328P__) #include AltSoftSerial *TX; uint8 ble_hci_init(AltSoftSerial *ser) { TX = ser; } #else uint8 ble_hci_init() { } #endif bStatus_t GAP_DeviceInit( uint8 taskID, uint8 profileRole, uint8 maxScanResponses, uint8 *pIRK, uint8 *pSRK, uint32 *pSignCounter ) { uint8 buf[42]; uint8 len = 0; buf[len++] = 0x01; // -Type : 0x01 (Command) buf[len++] = 0x00; // -Opcode : 0xFE00 (GAP_DeviceInit) buf[len++] = 0xFE; buf[len++] = 0x26; // -Data Length buf[len++] = profileRole; // Profile Role buf[len++] = maxScanResponses; // MaxScanRsps memcpy(&buf[len], pIRK, 16); // IRK len += 16; memcpy(&buf[len], pSRK, 16); // SRK len += 16; memcpy(&buf[len], pSignCounter, 4); // SignCounter len += 4; #if defined(__AVR_ATmega328P__) (*TX).write(buf, len); #else //modified write out function uint8 i; //for the entire string for (i=0; imode; // Mode buf[len++] = pParams->activeScan; // ActiveScan buf[len++] = pParams->whiteList; // WhiteList // hci_tl_write(buf, len); // hci_tl_wait_for_response(); #if defined(__AVR_ATmega328P__) (*TX).write(buf, len); #else //modified write out function uint8 i; //for the entire string for (i=0; ihighDutyCycle; buf[len++] = pParams->whiteList; buf[len++] = pParams->addrTypePeer; //0x01; memcpy(&buf[len], pParams->peerAddr, B_ADDR_LEN); len+=B_ADDR_LEN; #if defined(__AVR_ATmega328P__) (*TX).write(buf, len); #else //modified write out function uint8 i; //for the entire string for (i=0; ilen; memcpy(&buf[len], &connHandle, 2); len += 2; memcpy(&buf[len], &pReq->handle, 2); len += 2; memcpy(&buf[len], pReq->value, pReq->len); len += pReq->len; #if defined(__AVR_ATmega328P__) (*TX).write(buf, len); #else //modified write out function uint8 i; //for the entire string for (i=0; ilen; memcpy(&buf[len], &connHandle, 2); len += 2; memcpy(&buf[len], &pReq->handle, 2); len += 2; memcpy(&buf[len], pReq->value, pReq->len); len += pReq->len; #if defined(__AVR_ATmega328P__) (*TX).write(buf, len); #else //modified write out function uint8 i; //for the entire string for (i=0; i