/* fix to support with rssi */ void reporter_add_with_rssi(inquiry_info_with_rssi* newthingy) { char ieeeaddr[18]; int i; inquiry_info_with_rssi *rstore; debug && printf("\n\n --- BEFORE BACMP \n"); for (i = 0; i < entries1; i++) { debug && printf("\n\n ------ COMPARE ITERATION: %d \n",i); if (0 == bacmp(&((storeR1+i)->bdaddr),&(newthingy->bdaddr))) { if (debug) { ba2str(&(newthingy->bdaddr), ieeeaddr); printf("= %s %02x %04x ", ieeeaddr, newthingy->pscan_rep_mode, newthingy->clock_offset); classinfo(newthingy->dev_class); printf("\n"); } return; } } debug && printf("\n\n --- BEFORE REALLOCING STORER1 \n"); entries1++; if ((entries1 * INQUIRY_INFO_WITH_RSSI_SIZE) > capacity1) { capacity1 = entries1 * INQUIRY_INFO_WITH_RSSI_SIZE; rstore = realloc(storeR1, capacity1); if (rstore == NULL) { perror("I cannot allocate any more memory for new device, but continuing anyways... :-/"); return; } storeR1 = rstore; } debug && printf("\n\n --- BEFORE STORING IN ARRAY \n"); /* store in the array */ *(storeR1+(entries1-1)) = *newthingy; debug && printf("\n\n --- BEFORE BACMP2 \n"); /* find out if new object is in the old array... C cannot compare structures on its own... */ for (i = 0; i < entries2; i++) { if (0 == bacmp(&((store2+i)->bdaddr),&(newthingy->bdaddr))) { if (debug) { ba2str(&(newthingy->bdaddr), ieeeaddr); printf("= %s %02x %04x ", ieeeaddr, newthingy->pscan_rep_mode, newthingy->clock_offset); classinfo(newthingy->dev_class); printf("\n"); } return; } } //reporter_add(&template); }
/* * Add entry to the new inq. If it is not also * in the old inq, report adds. */ void reporter_add(inquiry_info* newthingy) { char ieeeaddr[18]; int i; inquiry_info *rstore; /* make storage bigger for bluetooth object if needed */ entries1++; if ((entries1 * INQUIRY_INFO_SIZE) > capacity1) { capacity1 = entries1 * INQUIRY_INFO_SIZE; rstore = realloc(store1, capacity1); if (rstore == NULL) { perror("I cannot allocate any more memory for new device, but continuing anyways... :-/"); return; } store1 = rstore; } /* store in the array */ *(store1+(entries1-1)) = *newthingy; /* find out if new object is in the old array... C cannot compare structures on its own... */ for (i = 0; i < entries2; i++) { if (0 == bacmp(&((store2+i)->bdaddr),&(newthingy->bdaddr))) { if (debug) { ba2str(&(newthingy->bdaddr), ieeeaddr); printf("= %s %02x %02x %04x ", ieeeaddr, newthingy->pscan_rep_mode, newthingy->pscan_mode, newthingy->clock_offset); classinfo(newthingy->dev_class); printf("\n"); } return; } } /* it isn't ... report it to chatbot... * we report the clock offset as it is used to quickly home in on the radio frequency (in the channel hopping sequence) * that the target is operating on, when we want to send a command to a device. * * just for fun when you are running this program in debug mode, you may see the clock offset drift up and down * slightly, maybe due to doppler effect, interference, etc. * * Time ---> (clock offset) * +---+---+---+---+---+---+---+---+ * R |\ | |/---\ | | /---\ | * F | \ | / | \---\ | /| |\--| * | \---/| | | \--/ | | | * +---+---+---+---+---+---+---+---+ * */ ba2str(&(newthingy->bdaddr), ieeeaddr); printf("+ %s %02x %02x %04x ", ieeeaddr, newthingy->pscan_rep_mode, newthingy->pscan_mode, newthingy->clock_offset); classinfo(newthingy->dev_class); printf("\n"); }
int main () { classinfo(); menu(); return 0; }
/* * Add entry to the new inq. If it is not also * in the old inq, report adds. */ void reporter_add(inquiry_info* newthingy) { char ieeeaddr[18]; int i; inquiry_info *rstore; ba2str(&(newthingy->bdaddr), ieeeaddr); bson_append_string( &b, "machine_addr", ieeeaddr ); bson_finish( &b ); //insert bson object to Mongo database if( mongo_insert( &conn, "BT.BTSignalRecords", &b) != MONGO_OK){ printf( "FAIL: Failed to insert document with error %d\n", conn.err); exit(1); } bson_destroy( &b ); /* find out if new object is already be found in this inquiry window */ for (i = 0; i < entries1; i++) { //entries1 - 1 is because we already put newthingy into store1, if we use entries1 // then bacmp will always find a bdaddr with the same bdaddr if (0 == bacmp(&((store1+i)->bdaddr),&(newthingy->bdaddr))) { if (debug) { ba2str(&(newthingy->bdaddr), ieeeaddr); printf("= %s %02x %02x ", ieeeaddr, newthingy->pscan_rep_mode, newthingy->pscan_mode); classinfo(newthingy->dev_class); printf("\n"); } return; } } /*only when we find a newthingy that is not in store1, we insert it into store1 */ /* make storage bigger for bluetooth object if needed */ entries1++; if ((entries1 * INQUIRY_INFO_SIZE) > capacity1) { capacity1 = entries1 * INQUIRY_INFO_SIZE; rstore = realloc(store1, capacity1); if (rstore == NULL) { perror("I cannot allocate any more memory for new device, but continuing anyways... :-/"); return; } store1 = rstore; } /* store in the array */ *(store1+(entries1-1)) = *newthingy; /* find out if new object is in the old array... C cannot compare structures on its own... */ for (i = 0; i < entries2; i++) { if (0 == bacmp(&((store2+i)->bdaddr),&(newthingy->bdaddr))) { if (debug) { ba2str(&(newthingy->bdaddr), ieeeaddr); printf("= %s %02x %02x ", ieeeaddr, newthingy->pscan_rep_mode, newthingy->pscan_mode); classinfo(newthingy->dev_class); printf("\n"); } return; } } /* it isn't ... report it to chatbot... * we report the clock offset as it is used to quickly home in on the radio frequency (in the channel hopping sequence) * that the target is operating on, when we want to send a command to a device. * * just for fun when you are running this program in debug mode, you may see the clock offset drift up and down * slightly, maybe due to doppler effect, interference, etc. * * Time ---> (clock offset) * +---+---+---+---+---+---+---+---+ * R |\ | |/---\ | | /---\ | * F | \ | / | \---\ | /| |\--| * | \---/| | | \--/ | | | * +---+---+---+---+---+---+---+---+ * */ ba2str(&(newthingy->bdaddr), ieeeaddr); printf(" %s %02x %02x ", ieeeaddr, newthingy->pscan_rep_mode, newthingy->pscan_mode); classinfo(newthingy->dev_class); printf("\n"); }