├── .gitignore ├── Arduino └── bb_ble │ └── bb_ble.ino ├── LICENSE ├── README.md └── node.js ├── nrf.js └── package.json /.gitignore: -------------------------------------------------------------------------------- 1 | node.js/node_modules/ 2 | 3 | -------------------------------------------------------------------------------- /Arduino/bb_ble/bb_ble.ino: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | // based off of: http://dmitry.gr/index.php?r=05.Projects&proj=11.%20Bluetooth%20LE%20fakery 4 | 5 | //#include 6 | //#include 7 | //#include 8 | //#include 9 | //#define F_CPU 8000000 10 | //#include 11 | // 12 | //#include 13 | 14 | #define PIN_CE 8 //Output 15 | #define PIN_nCS 7 //Output 16 | 17 | 18 | #define MY_MAC_0 0xEF 19 | #define MY_MAC_1 0xFF 20 | #define MY_MAC_2 0xC0 21 | #define MY_MAC_3 0xAA 22 | #define MY_MAC_4 0x18 23 | #define MY_MAC_5 0x00 24 | 25 | #define DHTPIN 2 26 | #define DHTTYPE DHT22 27 | 28 | //ISR(PCINT0_vect) 29 | //{ 30 | // //useless 31 | //} 32 | 33 | void btLeCrc(const uint8_t* data, uint8_t len, uint8_t* dst){ 34 | 35 | uint8_t v, t, d; 36 | 37 | while(len--){ 38 | 39 | d = *data++; 40 | for(v = 0; v < 8; v++, d >>= 1){ 41 | 42 | t = dst[0] >> 7; 43 | 44 | dst[0] <<= 1; 45 | if(dst[1] & 0x80) dst[0] |= 1; 46 | dst[1] <<= 1; 47 | if(dst[2] & 0x80) dst[1] |= 1; 48 | dst[2] <<= 1; 49 | 50 | 51 | if(t != (d & 1)){ 52 | 53 | dst[2] ^= 0x5B; 54 | dst[1] ^= 0x06; 55 | } 56 | } 57 | } 58 | } 59 | 60 | uint8_t swapbits(uint8_t a){ 61 | 62 | uint8_t v = 0; 63 | 64 | if(a & 0x80) v |= 0x01; 65 | if(a & 0x40) v |= 0x02; 66 | if(a & 0x20) v |= 0x04; 67 | if(a & 0x10) v |= 0x08; 68 | if(a & 0x08) v |= 0x10; 69 | if(a & 0x04) v |= 0x20; 70 | if(a & 0x02) v |= 0x40; 71 | if(a & 0x01) v |= 0x80; 72 | 73 | return v; 74 | } 75 | 76 | void btLeWhiten(uint8_t* data, uint8_t len, uint8_t whitenCoeff){ 77 | 78 | uint8_t m; 79 | 80 | while(len--){ 81 | 82 | for(m = 1; m; m <<= 1){ 83 | 84 | if(whitenCoeff & 0x80){ 85 | 86 | whitenCoeff ^= 0x11; 87 | (*data) ^= m; 88 | } 89 | whitenCoeff <<= 1; 90 | } 91 | data++; 92 | } 93 | } 94 | 95 | static inline uint8_t btLeWhitenStart(uint8_t chan){ 96 | //the value we actually use is what BT'd use left shifted one...makes our life easier 97 | 98 | return swapbits(chan) | 2; 99 | } 100 | 101 | void btLePacketEncode(uint8_t* packet, uint8_t len, uint8_t chan){ 102 | //length is of packet, including crc. pre-populate crc in packet with initial crc value! 103 | 104 | uint8_t i, dataLen = len - 3; 105 | 106 | btLeCrc(packet, dataLen, packet + dataLen); 107 | for(i = 0; i < 3; i++, dataLen++) packet[dataLen] = swapbits(packet[dataLen]); 108 | btLeWhiten(packet, len, btLeWhitenStart(chan)); 109 | for(i = 0; i < len; i++) packet[i] = swapbits(packet[i]); 110 | 111 | } 112 | 113 | uint8_t spi_byte(uint8_t byte){ 114 | 115 | // uint8_t i = 0; 116 | // 117 | // do{ 118 | // digitalWrite(11, LOW); //PORTB &=~ (uint8_t)(1 << 6); 119 | // if(byte & 0x80) digitalWrite(11, HIGH); //PORTB |= (uint8_t)(1 << 6); 120 | // digitalWrite(13, HIGH); //CLK |= (uint8_t)(1 << 4); 121 | // byte <<= 1; 122 | //// if(PINA & (uint8_t)32) byte++; 123 | //// delay(10); 124 | // digitalWrite(13, LOW);//CLK &=~ (uint8_t)(1 << 4); 125 | // 126 | // }while(--i); 127 | 128 | 129 | // Serial.println("SPI BYTE"); 130 | shiftOut(11, 13, MSBFIRST, byte); 131 | 132 | return byte; 133 | } 134 | 135 | void nrf_cmd(uint8_t cmd, uint8_t data) 136 | { 137 | digitalWrite(PIN_nCS, LOW); //cbi(PORTB, PIN_nCS); 138 | spi_byte(cmd); 139 | spi_byte(data); 140 | digitalWrite(PIN_nCS, HIGH); // sbi(PORTB, PIN_nCS); //Deselect chip 141 | } 142 | 143 | void nrf_simplebyte(uint8_t cmd) 144 | { 145 | digitalWrite(PIN_nCS, LOW); //cbi(PORTB, PIN_nCS); 146 | spi_byte(cmd); 147 | digitalWrite(PIN_nCS, HIGH); //sbi(PORTB, PIN_nCS); 148 | } 149 | 150 | void nrf_manybytes(uint8_t* data, uint8_t len){ 151 | 152 | digitalWrite(PIN_nCS, LOW); // cbi(PORTB, PIN_nCS); 153 | do{ 154 | 155 | spi_byte(*data++); 156 | 157 | }while(--len); 158 | digitalWrite(PIN_nCS, HIGH); // sbi(PORTB, PIN_nCS); 159 | } 160 | 161 | //void fob_init (void) 162 | //{ 163 | // DDRA = (uint8_t)~(1<<5); 164 | // DDRB = 0b00000110; 165 | // PORTA = 0b10001111; 166 | // cbi(PORTB, PIN_CE); 167 | // TCCR0B = (1<