Esempio n. 1
0
int WINAPI WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance,
					PSTR szCmdLine, int iCmdShow)
{
 HWND         hwnd ;
 MSG          msg ;
 WNDCLASS     wc ;

 if (!start())
  goto startup_was_not_finished;

 hInst = hInstance ;

 wc.style         = 0 ;
 wc.lpfnWndProc   = WndProc ;
 wc.cbClsExtra    = 0 ;
 wc.cbWndExtra    = 0 ;
 wc.hInstance     = hInst ;
 wc.hIcon         = LoadIcon (hInstance, "#1") ;
 wc.hCursor       = LoadCursor (NULL, IDC_ARROW) ;
 wc.hbrBackground = (HBRUSH) (COLOR_BTNFACE + 1) ;
 wc.lpszMenuName  = 0 ;
 wc.lpszClassName = "BounceThisTray" ;

 if (!RegisterClass (&wc))
 {
  bt_error("Error registering window class.");
  goto startup_was_not_finished;
 }

 hwnd = CreateWindow ("BounceThisTray","BounceThis",0,0,0,0,0,NULL,0,hInstance,0);

 if (!hwnd)
 {
  bt_error ("Couldn't create tray icon.");
  goto startup_was_not_finished;
 }

 while (GetMessage (&msg, NULL, 0, 0))
 {
  TranslateMessage (&msg) ;
  DispatchMessage (&msg) ;
 }

 return (int)msg.wParam ;

startup_was_not_finished:

 DeleteCriticalSection(&server.clientcs);
 if (server.use_logging)
 {
  logevent("Logging could not commense because of a critical error.");
  logend();
 }
 return 0;

}
Esempio n. 2
0
static void encrypt_completed(uint8_t status, gpointer user_data)
{
	struct hidp_connadd_req *req = user_data;
	int err;

	if (status) {
		error("Encryption failed: %s(0x%x)",
				strerror(bt_error(status)), status);
		goto failed;
	}

	err = ioctl_connadd(req);
	if (err == 0)
		goto cleanup;

	error("ioctl_connadd(): %s(%d)", strerror(-err), -err);
failed:
	close(req->intr_sock);
	close(req->ctrl_sock);

cleanup:
	free(req->rd_data);

	g_free(req);
}
Esempio n. 3
0
/**
 * Called by run_scan when we receive a complete EVT_INQUIRY_COMPLETE message.
 *
 * Writes a byte with value EVT_INQUIRY_COMPLETE and then a
 * bluetrax_inquiry_complete_t structure (in binary format) to out_file.
 *
 * Reference: [BTSPEC, volume 2, section 7.7.1, page 715]
 *
 * @param out_file to write record to
 *
 * @param time that the message was received
 *
 * @param hdr the event header
 *
 * @param data all data after the header; length is at least hdr->plen 
 *
 * @return EXIT_SUCCESS if no errors
 */
static int handle_inquiry_complete(FILE *out_file,
    struct timeval time, hci_event_hdr *hdr, unsigned char *data)
{
  int rc;
  bluetrax_inquiry_complete_t record;

  syslog(LOG_DEBUG, "inquiry complete");

  /* sanity check */
  if (hdr->plen != 1) {
    syslog(LOG_ERR, "handle_inquiry_complete: bad plen: plen=%hhd", hdr->plen);
    return EXIT_FAILURE;
  }

  /* check for errors; abort the scan if we get one */
  errno = bt_error(data[0]);
  if (errno != 0) {
    syslog(LOG_ERR, "handle_inquiry_complete: error: %m");
    return EXIT_FAILURE;
  }

  record.time = time;

  rc = write_inquiry_complete(out_file, record);

  return rc;
}
Esempio n. 4
0
/* リモートSlave機との接続 */
int bt_init(char *mac){
    printf("Bluetooth Remote\n");               // タイトル文字を表示
    if(open_rfcomm(mac) < 0){                   // Bluetooth SPP RFCOMM 接続の開始
        bt_error("Bluetooth Open ERROR");       // エラー表示後に異常終了
        return -1;                              // 異常終了
    }
    return 0;                                   // 正常終了
}
Esempio n. 5
0
/* ローカルMaster機の設定用 */
void bt_init_local(void){
    printf("Config BT \n"); 
    if( !bt_cmd_mode('$') ){                    // ローカルコマンドモードへの移行を実行
        bt_error("Config FAILED");
    }
    bt_cmd("SF,1");                             // 工場出荷時の設定に戻す
    bt_cmd("SM,1");                             // BluetoothのMasterデバイスに設定する
    bt_cmd("SA,4");                             // PINペアリング方式に変更する。
    bt_cmd("SO,%");                             // 接続・切断時にメッセージを表示する
    bt_cmd("ST,255");                           // コマンドモードの時間制限を解除する
    bt_cmd("R,1");                              // 再起動
    printf("DONE\n");
    sleep(1);                                   // 再起動待ち

    /* デバイス探索の実行 */
    if( !bt_cmd_mode('$') ){                    // ローカルコマンドモードへの移行を実行
        bt_error("FAILED to open");
    }
    printf("Inquiry \n");
    bt_repeat_cmd("I","Found",5);               // デバイスが見つかるまで探索を繰り返す
    printf("Found\n");
    while( bt_rx()==0 );                        // アドレスの取得待ち
    
    /* ペアリングの実行 */
    printf("Pairing \n");
    bt_cmd("SR,I");                             // 発見したデバイスのアドレスを保存
    bt_repeat_cmd("C","%CONNECT",8);            // 接続するまで接続コマンドを繰り返す
    printf("DONE\n");
    sleep(1);                                   // 接続後の待ち時間
    
    /* リモート機の設定 */
    printf("RemoteCnf \n");
    if( !bt_cmd_mode('$') ){                    // ローカルコマンドモードへの移行
        bt_error("RemoteCnf Failed");
    }
    bt_cmd("ST,255");                           // コマンドモードの時間制限を解除する
    bt_cmd("R,1");                              // 再起動
    printf("DONE\n");
    sleep(1);                                   // 再起動待ち
}
Esempio n. 6
0
void logerror (char *event, ...)
{
 char loc_buf [128] = { 0 };

 va_list l ;

 va_start (l, event);

 _vsnprintf (loc_buf, 128, event, l);

 bt_error (loc_buf);
 logevent (loc_buf);
}
Esempio n. 7
0
static int l2cap_bluez_set_flush_timeout(int channel, int timeout_ms)
{
    int result = 0, dd;
    struct hci_request rq = { 0 };

    write_link_supervision_timeout_cp cmd_param;

    write_link_supervision_timeout_rp cmd_response;

    if ((dd = hci_open_dev(channels.channels[channel].devid)) < 0)
    {
        perror("hci_open_dev");
        return -1;
    }

    // build a command packet to send to the bluetooth microcontroller
    cmd_param.handle = channels.channels[channel].handle;
    cmd_param.timeout = htobs(timeout_ms/BT_SLOT);
    rq.ogf = OGF_HOST_CTL;
    rq.ocf = OCF_WRITE_AUTOMATIC_FLUSH_TIMEOUT;
    rq.cparam = &cmd_param;
    rq.clen = sizeof(cmd_param);
    rq.rparam = &cmd_response;
    rq.rlen = sizeof(cmd_response);
    rq.event = EVT_CMD_COMPLETE;

    // send the command and wait for the response
    if( hci_send_req( dd, &rq, 0 ) < 0)
    {
        perror("hci_send_req");
        result = -1;
    }
    else if( cmd_response.status )
    {
        errno = bt_error(cmd_response.status);
        perror("failed to set flush timeout");
        result = -1;
    }

    hci_close_dev(dd);

    return result;
}
Esempio n. 8
0
Error::Error( u16 code )
: Dbg::Error( strerror( bt_error( code ) ) )
{}
Esempio n. 9
0
BOOL CALLBACK ConnProc (HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
 switch (msg)
 {
 case WM_INITDIALOG:
  server.conn_open = 1;
  return TRUE;
 case WM_COMMAND:
  if (HIWORD(wParam) == BN_CLICKED)
  {
   switch (LOWORD(wParam))
   {
   case 4:
	{
	 int curitem ;
	 LVITEM lvi = { 0 };

	 curitem = (int)SendDlgItemMessage(hwnd,1,LVM_GETSELECTIONMARK,0,0);

	 if (curitem == -1)
	 {
	  bt_error ("You must select a connection to kill") ;
	  break;
	 }

	 lvi.mask = LVIF_PARAM ;
	 lvi.iItem = curitem ;

	 SendDlgItemMessage(hwnd,1,LVM_GETITEM,0,(LPARAM)&lvi) ;

	 kill(((BT_CLIENT*)lvi.lParam)->ip) ;

	 break;
	}

   case 5:
	{
	 int curitem ;
	 LVITEM lvi = { 0 };

	 curitem = (int)SendDlgItemMessage(hwnd,1,LVM_GETSELECTIONMARK,0,0);

	 if (curitem == -1)
	 {
	  bt_error ("You must select a connection to filter") ;
	  break;
	 }

	 lvi.mask = LVIF_PARAM ;
	 lvi.iItem = curitem ;

	 SendDlgItemMessage(hwnd,1,LVM_GETITEM,0,(LPARAM)&lvi) ;

	 tempfilter(((BT_CLIENT*)lvi.lParam)->ip) ;

	 break;
	}

   case 7:
	{
	 char ip[16] ;
	 if (!GetDlgItemText(hwnd,6,ip,16))
	 {
	  bt_error ("You must enter an IP/BT-style filter.") ;
	  break;
	 }

	 kill(ip) ;
	 break;
	}

   case 8:
	{
	 char ip[16] ;
	 if (!GetDlgItemText(hwnd,6,ip,16))
	 {
	  bt_error ("You must enter an IP/BT-style filter.") ;
	  break;
	 }

	 tempfilter(ip) ;
	 break;
	}

   case 9:
	{
	 char msg[128] ;
	 if (!GetDlgItemText(hwnd,6,msg,128))
	 {
	  bt_error ("You must enter some text to broadcast.") ;
	  break;
	 }

	 broadcast(msg) ;
	 break;
	}
   }
  }
  return TRUE;

 case WM_CLOSE:
  server.conn_open = 0;
  DestroyWindow(hwnd);
  return TRUE;
 }

 return FALSE;
}