int readAddr(struct sockaddr_l2* addr){ FILE* flux; char buff[256]; char c; int i=0; if((flux =fopen(CONFIG_FILE,"r"))== NULL){ perror("Config file don't exists"); return; } while((c=fgetc(flux))!=EOF){ if(c!=EOF){ buff[i]=c; i++; } } buff[i]='\0'; printf("Adresse serveur : %s\n",buff); fclose(flux); bacpy(&(addr->l2_bdaddr),strtoba(buff)); addr->l2_family = AF_BLUETOOTH; addr->l2_psm = htobs(PORT); fclose(flux); return; }
static void do_kill(char *dst) { if (dst) bnep_kill_connection((void *) strtoba(dst)); else bnep_kill_all_connections(); }
static void parse_bdaddr(xmlTextReaderPtr reader) { const char *value; value = (char *)xmlTextReaderConstValue(reader); if (value != NULL) { printf(" %s\n", value); } addr = strtoba(value); }
/** * processNode: * @reader: the xmlReader * * Dump information about the current node */ static void processNode(xmlTextReaderPtr reader) { int depth, type; type = xmlTextReaderNodeType(reader); if ((type == XML_ELEMENT_DECL) || (type == XML_DTD_NODE)) return; depth = xmlTextReaderDepth(reader); if ((type == XML_ELEMENT_NODE) && (depth == 2)) printf("\n"); if (2 == depth) printf("\t"); else if (3 == depth) printf("\t\t"); xmlNodePtr node = xmlTextReaderCurrentNode(reader); if (xmlTextReaderNodeType(reader) == XML_ELEMENT_NODE && node && node->properties) { xmlAttr *attribute = node->properties; while (attribute && attribute->name && attribute->children) { tag = xmlNodeListGetString(node->doc, attribute->children, 1); printf ("%s%c", tag, (depth == 2) ? '\n' : ':'); bdaddr = strtoba((const char *)tag); if (bdaddr) add_remote_device(bdaddr); attribute = attribute->next; /* tag name is what we need */ break; } } if (xmlTextReaderNodeType(reader) == XML_TEXT_NODE) { if (xmlStrstr((xmlChar *)"Service", tag)) parse_services(reader); else if (xmlStrstr((xmlChar *)"HidDescriptor", tag)) parse_hid_descriptor(reader); else if (xmlStrstr((xmlChar *)"HogpRpt", tag)) parse_hogp(reader); else if (xmlStrstr((xmlChar *)"GattAttrs", tag)) parse_gatt_attribute(reader); else if (xmlStrstr((xmlChar *)"DevClass", tag)) parse_dev_class(reader); else if (xmlStrstr((xmlChar *)"Timestamp", tag)) parse_timestamp(reader); else if (xmlStrstr((xmlChar *)"Address", tag)) parse_bdaddr(reader); else parse_text_node(reader); } }
int synchroServeur(char* addr){ struct sockaddr_l2 addrCarte = {0}; char* buff = "Synchro"; int sock; baswap(&addrCarte.l2_bdaddr,strtoba(addr)); addrCarte.l2_family = AF_BLUETOOTH; addrCarte.l2_psm = htobs(PORT); if ((sock = socket(AF_BLUETOOTH, SOCK_SEQPACKET, BTPROTO_L2CAP)) < 0) { perror("Synchro socket create"); return; } if(connect(sock, (struct sockaddr*)&addrCarte, sizeof(addrCarte))<0){ perror("Synchro connect"); return; } write (sock, buff, sizeof(buff)); close(sock); }
static int getbdaddrbyname(char *str, bdaddr_t *ba) { int i, n, len; len = strlen(str); /* Check address format */ for (i = 0, n = 0; i < len; i++) if (str[i] == ':') n++; if (n == 5) { /* BD address */ baswap(ba, strtoba(str)); return 0; } if (n == 1) { /* IP address + port */ struct hostent *hent; bdaddr_t b; char *ptr; ptr = strchr(str, ':'); *ptr++ = 0; if (!(hent = gethostbyname(str))) { fprintf(stderr, "Can't resolve %s\n", str); return -2; } memcpy(&b, hent->h_addr, 4); *(uint16_t *) (&b.b[4]) = htons(atoi(ptr)); baswap(ba, &b); return 0; } fprintf(stderr, "Invalid address format\n"); return -1; }
bool K2sendPlayer::blueOpen () { struct sockaddr_l2 rem_addr, loc_addr; struct l2cap_options opts; //bdaddr_t bdaddr; int opt; char buffer[128]; QString msg; kdDebug (200010) << "K2sendPlayer::blueOpen called" << endl; is_connected = FALSE; if (baddr.isEmpty ()) { msg = QString ("No address"); K2sendStatusEvent *se = new K2sendStatusEvent (K2sendStatusEvent::EventMessage, msg, 2000); //kdDebug(200010) << "post 3" << endl; QApplication::postEvent (m_parent, se); se = new K2sendStatusEvent (K2sendStatusEvent::EventError, msg); //kdDebug(200010) << "post 4" << endl; QApplication::postEvent (m_parent, se); return FALSE; } msg = QString ("Try to connect " + baddr); K2sendStatusEvent *se = new K2sendStatusEvent (K2sendStatusEvent::EventMessage, msg, 30000); //kdDebug(200010) << "post 5" << endl; QApplication::postEvent (m_parent, se); /* create a bluetooth socket */ if ((blue_sock = socket (PF_BLUETOOTH, SOCK_SEQPACKET, BTPROTO_L2CAP)) < 0) { msg = QString ("Can't create socket"); K2sendStatusEvent *se = new K2sendStatusEvent (K2sendStatusEvent::EventMessage, msg, 2000); //kdDebug(200010) << "post 6" << endl; QApplication::postEvent (m_parent, se); se = new K2sendStatusEvent (K2sendStatusEvent::EventError, msg); //kdDebug(200010) << "post 7" << endl; QApplication::postEvent (m_parent, se); return FALSE; } kdDebug (200010) << "K2sendPlayer::blueOpen got socket" << endl; /* setup control structures */ memset (&loc_addr, 0, sizeof (loc_addr)); loc_addr.l2_family = AF_BLUETOOTH; loc_addr.l2_psm = htobs (MP3_PSM); if (bind (blue_sock, (struct sockaddr *) &loc_addr, sizeof (loc_addr)) < 0) { msg = QString ("Can't bind socket"); K2sendStatusEvent *se = new K2sendStatusEvent (K2sendStatusEvent::EventMessage, msg, 2000); QApplication::postEvent (m_parent, se); //kdDebug(200010) << "post 8" << endl; se = new K2sendStatusEvent (K2sendStatusEvent::EventError, msg); //kdDebug(200010) << "post 9" << endl; QApplication::postEvent (m_parent, se); return FALSE; } kdDebug (200010) << "K2sendPlayer::blueOpen bind done" << endl; memset (&rem_addr, 0, sizeof (rem_addr)); rem_addr.l2_family = AF_BLUETOOTH; baswap (&rem_addr.l2_bdaddr, strtoba (baddr.latin1 ())); rem_addr.l2_psm = htobs (MP3_PSM); if (connect (blue_sock, (struct sockaddr *) &rem_addr, sizeof (rem_addr)) < 0) { msg = QString ("Can't connect."); close (blue_sock); K2sendStatusEvent *se = new K2sendStatusEvent (K2sendStatusEvent::EventMessage, msg, 2000); //kdDebug(200010) << "post 10" << endl; QApplication::postEvent (m_parent, se); se = new K2sendStatusEvent (K2sendStatusEvent::EventError, msg); //kdDebug(200010) << "post 11" << endl; QApplication::postEvent (m_parent, se); return FALSE; } kdDebug (200010) << "K2sendPlayer::blueOpen connect ok" << endl; opt = sizeof (opts); if (getsockopt (blue_sock, SOL_L2CAP, L2CAP_OPTIONS, &opts, (socklen_t *) & opt) < 0) { msg = QString ("Can't get L2CAP options. "); close (blue_sock); K2sendStatusEvent *se = new K2sendStatusEvent (K2sendStatusEvent::EventMessage, msg, 2000); //kdDebug(200010) << "post 12" << endl; QApplication::postEvent (m_parent, se); se = new K2sendStatusEvent (K2sendStatusEvent::EventError, msg); //kdDebug(200010) << "post 13" << endl; QApplication::postEvent (m_parent, se); return FALSE; } /* use omtu for output buffer size */ buffer_size = opts.omtu; /* ask for firmware version */ buffer[0] = K2sendPlayerCommand::Fwrev; if (write (blue_sock, buffer, 1) != 1) { msg = QString ("Failed to write firmware request"); close (blue_sock); K2sendStatusEvent *se = new K2sendStatusEvent (K2sendStatusEvent::EventMessage, msg, 2000); //kdDebug(200010) << "post 14" << endl; QApplication::postEvent (m_parent, se); se = new K2sendStatusEvent (K2sendStatusEvent::EventError, msg); //kdDebug(200010) << "post 15" << endl; QApplication::postEvent (m_parent, se); return FALSE; } kdDebug (200010) << "K2sendPlayer::blueOpen req fw done" << endl; if (read (blue_sock, buffer, sizeof (buffer)) < 0) { msg = QString ("Failed to read firmware reply"); close (blue_sock); K2sendStatusEvent *se = new K2sendStatusEvent (K2sendStatusEvent::EventMessage, msg, 2000); //kdDebug(200010) << "post 16" << endl; QApplication::postEvent (m_parent, se); se = new K2sendStatusEvent (K2sendStatusEvent::EventError, msg); //kdDebug(200010) << "post 17" << endl; QApplication::postEvent (m_parent, se); return FALSE; } kdDebug (200010) << "K2sendPlayer::blueOpen got response" << endl; if (buffer[0] != K2sendPlayerCommand::Fwrev) { msg = QString ("Unexpected firware reply"); K2sendStatusEvent *se = new K2sendStatusEvent (K2sendStatusEvent::EventMessage, msg, 2000); //kdDebug(200010) << "post 17" << endl; QApplication::postEvent (m_parent, se); se = new K2sendStatusEvent (K2sendStatusEvent::EventError, msg); //kdDebug(200010) << "post 18" << endl; QApplication::postEvent (m_parent, se); return FALSE; } is_connected = TRUE; msg = QString ("Connected"); se = new K2sendStatusEvent (K2sendStatusEvent::EventMessage, msg, 2000); //kdDebug(200010) << "post 19" << endl; QApplication::postEvent (m_parent, se); se = new K2sendStatusEvent (K2sendStatusEvent::EventAddr, baddr); //kdDebug(200010) << "post 20" << endl; QApplication::postEvent (m_parent, se); return TRUE; }
int main(int argc, char *argv[]) { int opt; char *arg_kim_path = NULL, *arg_bd_addr = NULL, *temp_path = KIM_SYSFS_BASE; int st_fd, err; unsigned char install; struct pollfd p; UIM_START_FUNC(); err = 0; /* Parse the user input */ while ((opt = getopt (argc, argv, "f:b:")) != -1) { switch (opt) { case 'f': arg_kim_path = optarg; break; case 'b': arg_bd_addr = optarg; break; default: usage(); return -1; } } if (arg_kim_path != NULL) { temp_path = arg_kim_path; if( strlen(temp_path) > (sizeof(install_sysfs_entry)-10) ) { UIM_ERR("Path to sysfs node too long"); return -1; } } strcpy(install_sysfs_entry, temp_path); strcpy(dev_name_sysfs, temp_path); strcpy(baud_rate_sysfs, temp_path); strcpy(flow_cntrl_sysfs, temp_path); strcat(install_sysfs_entry, "/install"); strcat(dev_name_sysfs, "/dev_name"); strcat(baud_rate_sysfs, "/baud_rate"); strcat(flow_cntrl_sysfs, "/flow_cntrl"); UIM_DBG("install = %s", install_sysfs_entry); UIM_DBG("dev_name = %s", dev_name_sysfs); UIM_DBG("baud_rate = %s", baud_rate_sysfs); UIM_DBG("flow_cntrl = %s", flow_cntrl_sysfs); if (arg_bd_addr != NULL) { if (strlen(arg_bd_addr) != BD_ADDR_LEN) { usage(); return -1; } UIM_DBG("Address = %s", arg_bd_addr); /* BD address passed as string in xx:xx:xx:xx:xx:xx format */ strncpy(uim_bd_address, arg_bd_addr, sizeof(uim_bd_address)); bd_addr = strtoba(uim_bd_address); } line_discipline = N_TI_WL; st_fd = open(INSTALL_SYSFS_ENTRY, O_RDONLY); if (st_fd < 0) { UIM_DBG("unable to open %s(%s)", INSTALL_SYSFS_ENTRY, strerror(errno)); return -1; } RE_POLL: /* read to start proper poll */ err = read(st_fd, &install, 1); /* special case where bluetoothd starts before the UIM, and UIM * needs to turn on bluetooth because of that. */ if ((err > 0) && install == '1') { UIM_DBG("install set previously..."); st_uart_config(install); } UIM_DBG("begin polling..."); memset(&p, 0, sizeof(p)); p.fd = st_fd; p.events = POLLERR | POLLPRI; while (!exiting) { p.revents = 0; err = poll(&p, 1, -1); UIM_DBG("poll broke due to event %d(PRI:%d/ERR:%d)\n", p.revents, POLLPRI, POLLERR); if (err < 0 && errno == EINTR) continue; if (err) break; } close(st_fd); st_fd = open(INSTALL_SYSFS_ENTRY, O_RDONLY); if (st_fd < 0) { UIM_DBG("unable to open %s (%s)", INSTALL_SYSFS_ENTRY, strerror(errno)); return -1; } if (!exiting) { err = read(st_fd, &install, 1); UIM_DBG("read %c from install \n", install); if (err > 0) st_uart_config(install); goto RE_POLL; } close(st_fd); return 0; }
static void cmd_hunt(int dev_id, int argc, char **argv) { bdaddr_t bdaddr; char name[248]; int opt, dd, num=0, num2=0, num3=0, num4=0, num5=0, num6=0; int btout=50000; unsigned char lame[16][2] = {"0","1","2","3","4","5","6","7","8","9","A","B","C","D","E","F", }; char addtobrute[248]; printf("redfang - the bluetooth hunter ver 1.00.alpha\n"); printf("(c)2003 \@stake Inc\n"); printf("author: Ollie Whitehouse ([email protected])\n"); argc -= optind; argv += optind; if (argc < 2) { printf(hunt_help); exit(1); } if (argc >= 1) { btout=atoi(argv[1]); } printf("timeout: %d\n", btout); printf("starting...\n"); while (num <= 15) { while(num2 <= 15) { while(num3 <= 15) { while(num4 <= 15) { while(num5 <= 15) { while(num6 <= 15) { strcpy(addtobrute,"00:80:98:"); strcat(addtobrute,lame[num]); strcat(addtobrute,lame[num2]); strcat(addtobrute,":"); strcat(addtobrute,lame[num3]); strcat(addtobrute,lame[num4]); strcat(addtobrute,":"); strcat(addtobrute,lame[num5]); strcat(addtobrute,lame[num6]); /* debug purposes */ printf("%s\n",addtobrute); baswap(&bdaddr, strtoba(addtobrute)); dev_id = hci_get_route(&bdaddr); if (dev_id < 0) { fprintf(stderr,"Device not availible"); exit(1); } dd = hci_open_dev(dev_id); if (dd < 0) { fprintf(stderr,"HCI device open failed"); exit(1); } /* try to get name of remote device - timeout is the int) */ if (hci_read_remote_name(dd,&bdaddr,sizeof(name), name, btout) == 0) printf("\n.start--->\naddress :- %s\nname :- %s\n<.end-----\n",batostr(&bdaddr),name); close(dd); num6++; } num6=0; num5++; } num5=0; num4++; } num4=0; num3++; } num3=0; num2++; } num2=0; num++; } }