2016-04-28 71 views
25

私は、Windows 10タブレットを別のBluetoothデバイスとペアリングする必要があるプロジェクトを開始しました。Windows 10と32feet.NETのBluetoothペアリング(SSP)

私は、プロセスに慣れ親しむために簡単なWindowsフォームアプリケーションから始めることに決めました。 32feet.NET NuGetパッケージを自分のソリューションに追加し、すぐにデバイスの検索とリストボックスの作成に成功しました。

client = new BluetoothClient(); 
devices = client.DiscoverDevices(); 
if (devices.Length > 0) 
{ 
    foreach (var device in devices) 
    { 
     lstBTDevices.Items.Add(device.DeviceName); 
    } 
} 
else 
{ 
    MessageBox.Show("Unable to detect any bluetooth devices"); 
} 

次に、検出されたデバイスを選択してペアにしようとするイベントハンドラを追加しました。

private void LstBTDevices_SelectedIndexChanged(object sender, EventArgs e) 
    { 
     BluetoothDeviceInfo selectedDevice = devices[lstBTDevices.SelectedIndex]; 
     if (MessageBox.Show(String.Format("Would you like to attempt to pair with {0}?", selectedDevice.DeviceName), "Pair Device", MessageBoxButtons.YesNo) == DialogResult.Yes) 
     { 
      if (BluetoothSecurity.PairRequest(selectedDevice.DeviceAddress, "123456")) 
      { 
       MessageBox.Show("We paired!"); 
      } 
      else 
      { 
       MessageBox.Show("Failed to pair!"); 
      } 
     } 
    } 

安価なBluetooth 2.0アダプタを搭載したWindows7デスクトップPCでは、私の電話にポンカードを入力するようにポップアップが表示されます。 「123456」と入力すると、ペアリングは成功します。

ただし、これが問題の開始場所です。私はその後、私のアプリケーションを取って、私のWindows10のタブレットでそれを実行し、私は私の携帯電話をランダムに6桁のピンコードと、それは私のタブレットの画面に表示されると一致する必要がありますオプションとしてペア/キャンセルボタンが付いています。いずれかのボタンを押すと失敗します。

私は間違っているのですか? 32feet.NETでサポートされていないドライバ?

アドバイスをいただければ幸いです。

UPDATE:

EventHandler<BluetoothWin32AuthenticationEventArgs> authHandler = new EventHandler<BluetoothWin32AuthenticationEventArgs>(handleAuthRequests); 
BluetoothWin32Authentication authenticator = new BluetoothWin32Authentication(authHandler); 

    private void btnPairSSP_Click(object sender, EventArgs e) 
    { 
     BluetoothDeviceInfo selectedDevice = devices[lstBTDevices.SelectedIndex]; 
     if (MessageBox.Show(String.Format("Would you like to attempt to pair with {0}?", selectedDevice.DeviceName), "Pair Device", MessageBoxButtons.YesNo) == DialogResult.Yes) 
     { 
      Task t = new Task(PairBluetoothTask); 
      t.Start(); 
     } 
    } 

    private void PairBluetoothTask() 
    { 
     BluetoothDeviceInfo selectedDevice = devices[lstBTDevices.SelectedIndex]; 
     if (BluetoothSecurity.PairRequest(selectedDevice.DeviceAddress, null)) 
     { 
      MessageBox.Show("We paired!"); 
     } 
     else 
     { 
      MessageBox.Show("Failed to pair!"); 
     } 

    } 

    private void handleAuthRequests(object sender, BluetoothWin32AuthenticationEventArgs e) 
    { 
     switch (e.AuthenticationMethod) 
     { 
      case BluetoothAuthenticationMethod.Legacy: 
       MessageBox.Show("Legacy Authentication"); 
       break; 

      case BluetoothAuthenticationMethod.OutOfBand: 
       MessageBox.Show("Out of Band Authentication"); 
       break; 

      case BluetoothAuthenticationMethod.NumericComparison: 
       if(e.JustWorksNumericComparison == true) 
       { 
        MessageBox.Show("Just Works Numeric Comparison"); 
       } 
       else 
       { 
        MessageBox.Show("Show User Numeric Comparison"); 
        if (MessageBox.Show(e.NumberOrPasskeyAsString, "Pair Device", MessageBoxButtons.YesNo) == DialogResult.Yes) 
        { 
         e.Confirm = true; 
        } 
        else 
        { 
         e.Confirm = false; 
        }       
       } 
       break; 

      case BluetoothAuthenticationMethod.PasskeyNotification: 
       MessageBox.Show("Passkey Notification"); 
       break; 

      case BluetoothAuthenticationMethod.Passkey: 
       MessageBox.Show("Passkey"); 
       break; 

      default: 
       MessageBox.Show("Event handled in some unknown way"); 
       break; 

     } 
    } 

私はペアリングを開始すると:bare_metalからのコメントは、私はBluetoothWin32Authenticationイベントハンドラを追加し、SSPのペアリングを開始するためのボタンを追加しました私は

ビットさらに取得支援してきました私の電話から、これは正常に動作し、イベントが発生し、メッセージボックスがポップアップしてペアリングが成功しました。

しかし、私がタブレットからペアリングを開始すると、イベントハンドラは決して起動されないため、ペアリングは失敗します。

+1

PINコードの最初のペアリングは、従来のペアリングと呼ばれ、ランダムな6桁の数字を有するものは、セキュアシンプルペアリングされています。 SSPでイニシエータとレスポンダを認証するには、ペア/受諾ボタンを両側で押す必要があります。 Windows10でも受け入れ/拒否ボタンが表示されますか?両方のデバイスから同意した場合、ペアリング失敗(20秒)にどれくらいの時間がかかりますか? –

+0

いいえ、Windows10タブレットに受け入れ/拒否オプションやピンコードが表示されません。アプローチの変更を試して、32feet.NETではなくWindows.Devices.Bluetooth名前空間を見てみましょう。 –

+0

私は同じ問題、任意のヘルプを持っている! –

答えて

4

ここでの問題は、32feetライブラリがレガシーペアリングを中心に構築されているため、接続するデバイスのピンを知る必要があるか、またはポップアップウィンドウを取得するためにnullを指定する必要があることです。ピンを入力してください。このダイアログは、新しいバージョンのウィンドウには反映されていないかもしれません。 これについてはわかりませんが、32feetライブラリがラップするネイティブ関数のドキュメントは、Vistaよりも新しいものを開発する場合は別のメソッドを呼び出します。 32フィートの逆コンパイル源を通じて私の研究の閲覧から

https://msdn.microsoft.com/en-us/library/windows/desktop/aa362770(v=vs.85).aspx

、それは32フィートのように見えるかもしれSSPをサポートしていない、ただ他の人 - それは必ず付属のBluetoothスタックの実装は、更新が必要なことかもしれ - か自分自身を作成する必要があります - 私は確信していません。

このサードパーティ製ではなく、Microsoftが提供するライブラリを調べることができます。Githubの例を使用して、すべてのデバイスと正常に接続してペア設定することができました。

https://msdn.microsoft.com/en-us/library/windows/apps/mt168401.aspx

https://github.com/Microsoft/Windows-universal-samples/tree/master/Samples/DeviceEnumerationAndPairing/cs

関連する問題