示例#1
0
int hci_remove_key(BD_ADDR *bda)
{
	int		err = 0;
	int		fd;
	__u16		deleted;
	int		i, num, flags;
	int		devs[HCI_MAX_DEVS];

	num = hci_get_devs(devs);
	for (i = 0; i < num; i++) {
		hci_get_flags_id(devs[i], &flags);
		if (!(flags & HCI_FLAGS_UP))
			continue;
		fd = hci_open_id(devs[i]);
		if (fd < 0) {
			err = fd;
			break;
		}
		err = HCI_DeleteStoredLinkKey(fd, bda, (!bda) ? 1 : 0, &deleted);
		hci_close(fd);
		if (err < 0)
			return err;
	}
	return hci_ioctl(BTIOC_REMOVELINKKEY, bda);
}
示例#2
0
int link_key_request(struct Link_Key_Request_Event *evt, int devnum)
{
	int		fd, err, ok = 0;
	struct btdev	*btdev;

	DBFENTER;

	if (affix_ctl_mode & AFFIX_FLAGS_KEY)
		return 0;	// somebody takes care about pin

	fd = hci_open_id(devnum);
	if (fd < 0)
		return fd;

	btdev = btdev_lookup_bda(&evt->bda);
	if (btdev && (btdev->flags & NBT_KEY))
		ok = 1;

	if (ok) {
		err = HCI_LinkKeyRequestReply(fd, &evt->bda, btdev->Link_Key);
	} else {
		err = HCI_LinkKeyRequestNegativeReply(fd, &evt->bda);
	}
	if (btdev)
		btdev_put(btdev);
	hci_close(fd);

	DBFEXIT;
	return err;
}
示例#3
0
文件: main.c 项目: AubrCool/btstack
static void sigint_handler(int param){

#ifndef _WIN32
    // reset anyway
    btstack_stdin_reset();
#endif

    log_info(" <= SIGINT received, shutting down..\n");   
    hci_power_control(HCI_POWER_OFF);
    hci_close();
    log_info("Good bye, see you.\n");    
    exit(0);
}
示例#4
0
文件: main.c 项目: notmikeb/btstack
static void sigint_handler(int param){
    UNUSED(param);

    printf("CTRL-C - SIGINT received, shutting down..\n");   
    log_info("sigint_handler: shutting down");

    // reset anyway
    btstack_stdin_reset();

    // power down
    hci_power_control(HCI_POWER_OFF);
    hci_close();
    log_info("Good bye, see you.\n");    
    exit(0);
}
示例#5
0
文件: daemon.c 项目: sristi194/uubt
static void daemon_sigint_handler(int param){
    
#ifdef USE_BLUETOOL
    // notify daemons
    notify_post("ch.ringwald.btstack.stopped");
#endif
    
    log_info(" <= SIGINT received, shutting down..\n");    

    hci_power_control( HCI_POWER_OFF);
    hci_close();
    
    log_info("Good bye, see you.\n");    
    
    exit(0);
}
示例#6
0
int pin_code_request(struct PIN_Code_Request_Event *evt, int devnum)
{
	int		fd, err;
	struct btdev	*btdev = NULL;
	hci_struct	*hci;
	__u8		length = 0;
	__u8		*pin = NULL;

	DBFENTER;
	if (affix_ctl_mode & AFFIX_FLAGS_PIN)
		return 0;	// somebody takes care about pin
	hci = hci_lookup_devnum(devnum);
	if (!hci)
		return 0;
	fd = hci_open_id(devnum);
	if (fd < 0) {
		hci_put(hci);
		return fd;
	}
	if (hci->flags & HCI_SECURITY_PAIRABLE) {
		btdev = btdev_lookup_bda(&evt->bda);
		if (btdev && (btdev->flags & NBT_PIN)) {
			pin = btdev->PIN_Code;
			length = btdev->PIN_Code_Length;
		} else {
			if (affix_pin_code.Length) {
				pin = affix_pin_code.Code;
				length = affix_pin_code.Length;
			}
		}
	}
	if (pin)
		err = HCI_PINCodeRequestReply(fd, &btdev->bda, length, pin);
	else
		err = HCI_PINCodeRequestNegativeReply(fd, &evt->bda);
	if (btdev)
		btdev_put(btdev);
	hci_close(fd);
	hci_put(hci);
	DBFEXIT;
	return err;
}
示例#7
0
/*
 * HCI events processing
 */
int connection_request(struct Connection_Request_Event *evt, int devnum)
{
	int		err = 0, fd;
	hci_struct	*hci;
	
	DBFENTER;

	hci = hci_lookup_devnum(devnum);
	if (!hci) {
		return -ENODEV;
	}
	fd = hci_open_id(devnum);
	if (fd < 0) {
		hci_put(hci);
		return fd;
	}
	err = __HCI_AcceptConnectionRequest(fd, &evt->bda, !(hci->flags & HCI_ROLE_BECOME_MASTER));
	hci_close(fd);
	hci_put(hci);

	DBFEXIT;
	return err;
}
示例#8
0
int message_handler(struct hci_msg_hdr *hdr)
{
	int	err = 0, fd;

	DBFENTER;

	DBPRT("Manager Command: %d\n", hdr->opcode);
	switch (hdr->opcode) {
		case HCICTL_CONNECT_REQ: 
			{
				struct hci_connect_req	*cmd = (void*)hdr;
				INQUIRY_ITEM	dev;
				hci_con		*con;

				con = hcc_lookup_id(cmd->id);
				if (!con)
					break;

				if (con->hci == NULL) {
					hci_struct	*hci;

					/* select device */
					hci = hci_select();
					if (hci == NULL)
						goto fail;
					hcc_bind(con, hci);
					hci_put(hci);
				}
				if (STATE(con) != CON_W4_LCONREQ)
					goto fail;
				ENTERSTATE(con, CON_W4_CONRSP);

				DBPRT("attempt... %d\n", con->attempt);

				if (__is_acl(con)) {
					struct btdev	*btdev;
					
					fd = hci_open_id(con->hci->devnum);
					if (fd < 0)
						goto fail;
					/* get device from the cache */
					btdev = btdev_lookup_bda(&con->bda);
						
					if (btdev && (jiffies - btdev->stamp) < (HZ << 12)) {// 1.13 hour
						dev.PS_Repetition_Mode = btdev->PS_Repetition_Mode;
						dev.PS_Mode = btdev->PS_Mode;
						dev.Clock_Offset = btdev->Clock_Offset | 0x8000;
					} else {
						dev.PS_Repetition_Mode = 0x00;
						dev.PS_Mode = 0x00;
						dev.Clock_Offset = 0x00;
					}
					dev.bda = con->bda;
					err = __HCI_CreateConnection(fd, &dev, con->hci->pkt_type & HCI_PT_ACL, 
							!(con->hci->flags & HCI_ROLE_DENY_SWITCH));
					if (btdev)
						btdev_put(btdev);
					hci_close(fd);
				} else {
					hci_con		*acl;

					acl = hcc_lookup_acl(con->hci, &con->bda);
					if (!acl) {
						/* not connected FIXME:*/
						goto fail;
					}
					fd = hci_open_id(acl->hci->devnum);
					if (fd < 0) {
						hcc_put(acl);
						goto fail;
					}

					err = __HCI_AddSCOConnection(fd, acl->chandle, acl->hci->pkt_type & HCI_PT_SCO);
					hci_close(fd);
					hcc_put(acl);
				}
				if (err)
					goto fail;
				hcc_put(con);
				break;
fail:
				hcc_stop_timer(con);
				ENTERSTATE(con, DEAD);
				hpf_connect_cfm(con, (err < 0) ? HCI_ERR_HARDWARE_FAILURE : err);
				hcc_put(con);
			}
			break;

		case HCICTL_DISCONNECT_REQ: 
			{
				struct hci_disconnect_req	*cmd = (void*)hdr;
				hci_con		*con;

				con = hcc_lookup_id(cmd->id);
				if (!con)
					break;

				if (STATE(con) != CON_W4_LDISCREQ) {
					hcc_put(con);
					break;
				}
				hcc_stop_timer(con);
				ENTERSTATE(con, CON_W4_DISCRSP);
				fd = hci_open_id(con->hci->devnum);
				if (fd < 0) {
					hcc_put(con);
					break;

				}
#if 0
				err = __HCI_Disconnect(fd, con->chandle, cmd->reason);
#else
				/* do it exclusively */
				hci_lock(fd, 1);
				err = HCI_Disconnect(fd, con->chandle, cmd->reason);
				hci_lock(fd, 0);
#endif
				hci_close(fd);
				hcc_put(con);
			}
			break;

		case HCICTL_AUTH_REQ: 
			{
				struct hci_auth_req	*cmd = (void*)hdr;
				hci_con		*con;

				con = hcc_lookup_id(cmd->id);
				if (!con)
					break;

				fd = hci_open_id(con->hci->devnum);
				if (fd < 0) {
					hcc_put(con);
					break;

				}
				err = __HCI_AuthenticationRequested(fd, con->chandle);
				hci_close(fd);
				hcc_put(con);
			}
			break;

#ifdef CONFIG_AFFIX_UPDATE_CLOCKOFFSET
		case HCICTL_UPDATECLOCKOFFSET_REQ:
			{
				struct hci_updateclockoffset_req *cmd = (void*)hdr;
				hci_con		*con;

				con = hcc_lookup_id(cmd->id);
				if (!con)
					break;

				fd = hci_open_id(con->hci->devnum);
				if (fd < 0) {
					hcc_put(con);
					break;

				}
				
				err = __HCI_ReadClockOffset(fd, con->chandle);
				if (err) {
					DBPRT("\nError Reading Clock Offset\n");
				}
				hci_close(fd);
				hcc_put(con);
			}
			break;
#endif

		default:
			break;
	}
	return err;
}
示例#9
0
int affixd_thread(void *startup)
{
	int			ret = 0;
	struct pollfd		fds[2];
	__u8			msg[HCI_MAX_MSG_SIZE];
	__u8			event[HCI_MAX_EVENT_SIZE];

	DBFENTER;
	daemonize("affixd");
	allow_signal(SIGTERM);
	allow_signal(SIGUSR1);

	/*  Open HCI manager */
	fds[0].fd = hci_open_mgr();
	if (fds[0].fd < 0) {
		ret = fds[0].fd;
		fds[1].fd = -1;
		goto exit;
	}
	fds[0].events = POLLIN;
	
	fds[1].fd = hci_open_event();
	if (fds[1].fd < 0) {
		ret = fds[1].fd;
		goto exit;
	}
	fds[1].events = POLLIN;

	up(&exit_sema);
	
	hci_event_mask(fds[1].fd, ALL_EVENTS_MASK &
			~(COMMAND_COMPLETE_MASK | COMMAND_STATUS_MASK |
			  NUMBER_OF_COMPLETE_PACKETS_MASK | FLUSH_OCCURRED_MASK));
	module_put(THIS_MODULE);
	module_put(THIS_MODULE);
	module_put(THIS_MODULE);
	module_put(THIS_MODULE);
	for (;;) {
		ret = hci_poll(fds, 2, -1);
		if (ret > 0) {/* we have something */
			if ((fds[0].revents | fds[1].revents) & (POLLERR | POLLHUP | POLLNVAL))
				break;
			if (fds[1].revents) {
				if (fds[1].revents & POLLIN) { /* HCI event */
					int	devnum;
					hci_recv_event_any(fds[1].fd, &devnum, event, sizeof(event));
					event_handler((void*)event, devnum);
				}
			}
			if (fds[0].revents) {
				if (fds[0].revents & POLLIN) {/* MSG */
					btsys_recv(fds[0].fd, msg, sizeof(msg), 0);
					message_handler((void*)(msg+1));
				}
			}
		}
		if (signal_pending(current)) {
			DBPRT("Got a signal!!!\n");
//			if (sigismember(&current->pending.signal, SIGUSR1)) {
//				sigdelset(&current->pending.signal, SIGUSR1);
//			}
			flush_signals(current);	// flush pending signals
			spin_lock_irq(&current->sighand->siglock);
			recalc_sigpending();
			spin_unlock_irq(&current->sighand->siglock);
			if (mgr_exit)
				break;
		}
	}
	//try_module_get(THIS_MODULE);
	//try_module_get(THIS_MODULE);
	//try_module_get(THIS_MODULE);
	//try_module_get(THIS_MODULE);
exit:
	if (fds[0].fd >= 0)
		hci_close(fds[0].fd);
	if (fds[1].fd >= 0)
		hci_close(fds[1].fd);
	mgr_exit = ret;
	up(&exit_sema);
	DBFEXIT;
	return ret;
}
示例#10
0
void BTShutdown() {
  hci_close();
}