public void NcHandler() { BLUETOOTH_AUTHENTICATION_CALLBACK_PARAMS cbParams = new BLUETOOTH_AUTHENTICATION_CALLBACK_PARAMS(); cbParams.authenticationMethod = BluetoothAuthenticationMethod.NumericComparison; cbParams.authenticationRequirements = BluetoothAuthenticationRequirements.MITMProtectionRequired; cbParams.Numeric_Value_Passkey = 0; // BluetoothWin32AuthenticationEventArgs e; // cbParams.Numeric_Value_Passkey = 123456; e = Create_EA(cbParams); Assert.AreEqual(123456, e.NumberOrPasskey, "Num 123456"); Assert.AreEqual("123 456", e.NumberOrPasskeyAsString, "NumToS6 123456"); // cbParams.Numeric_Value_Passkey = 987654; e = Create_EA(cbParams); Assert.AreEqual(987654, e.NumberOrPasskey, "Num 987654"); Assert.AreEqual("987 654", e.NumberOrPasskeyAsString, "NumToS6 987654"); // cbParams.Numeric_Value_Passkey = 0; e = Create_EA(cbParams); Assert.AreEqual(0, e.NumberOrPasskey, "Num 0"); Assert.AreEqual("000 000", e.NumberOrPasskeyAsString, "NumToS6 0"); // // e = new BluetoothWin32AuthenticationEventArgs(); Assert.IsNull(e.NumberOrPasskey, "Num ea..ctor()"); Assert.IsNull(e.NumberOrPasskeyAsString, "NumToS6 ea..ctor()"); }
/// <summary> /// ペアリングリクエストが発生した際に呼び出される。 /// </summary> private void Win32AuthCallbackHandler(Object sender, BluetoothWin32AuthenticationEventArgs e) { // pinの設定。デバイスによっては必須。 e.Pin = "0000"; // ペアリングの了承・拒否を設定できる。trueにしてメソッドを返すとペアリング了承にできる。 e.Confirm = true; }
private void handleRequests(Object thing, BluetoothWin32AuthenticationEventArgs args) { System.Console.WriteLine("BluetoothWin32AuthenticationEventArgs ( AuthenticationMethod : {0}, AuthenticationRequirements : {1}, NumberOrPasskey : {2}, COD : {3:X} )", args.AuthenticationMethod, args.AuthenticationRequirements, args.NumberOrPasskey, args.Device.ClassOfDevice.Value); DeviceClass = args.Device.ClassOfDevice.Value; DeviceName = args.Device.DeviceName; //args.Confirm = true; }
private BluetoothWin32AuthenticationEventArgs Create_EA(BLUETOOTH_AUTHENTICATION_CALLBACK_PARAMS cbParams) { BLUETOOTH_AUTHENTICATION_CALLBACK_PARAMS?cbParamsRef = cbParams; var dev = new BLUETOOTH_DEVICE_INFO(addr1); var e = new BluetoothWin32AuthenticationEventArgs(dev, ref cbParamsRef); return(e); }
//[MenuItem] //public void BtWin32AuthEx() //{ // using (BluetoothWin32AuthenticationEx ar = new BluetoothWin32AuthenticationEx(Hndlr)) { // console.Write("Hit return to break>"); // Console.ReadLine(); // } //} void HndlrNoRespond(object sender, BluetoothWin32AuthenticationEventArgs e) { console.WriteLine("Win32Auth hndlr, peer: {0} {1}, m: {2}, req: {3}, io: {4}, n_pk: {5}." + " Attempt# {6}, PrevErr: {7}", e.Device.DeviceAddress, e.Device.DeviceName, e.AuthenticationMethod, e.AuthenticationRequirements, e.IoCapability, e.NumberOrPasskey, e.AttemptNumber, e.PreviousNativeErrorCode); }
public static void HandleRequests(object that, BluetoothWin32AuthenticationEventArgs e) { int?passKey = e.NumberOrPasskey; if (passKey != null) { string msg = String.Format("Pairing Request : {0}", passKey); var response = MessageBox.Show(msg, "Request", MessageBoxButton.YesNo, MessageBoxImage.Information); if (response == MessageBoxResult.Yes) { e.Confirm = true; } } }
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", MessageBoxButton.YesNo) == MessageBoxResult.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; } }
static private void handleAuthRequests(object sender, BluetoothWin32AuthenticationEventArgs e) { switch (e.AuthenticationMethod) { case BluetoothAuthenticationMethod.Legacy: break; case BluetoothAuthenticationMethod.OutOfBand: MessageBox.Show("Autentykacja poza pasmem"); break; case BluetoothAuthenticationMethod.NumericComparison: if (e.JustWorksNumericComparison == true) { MessageBox.Show("Porównanie numerów"); } else { if (MessageBox.Show(e.NumberOrPasskeyAsString, "Sprawdz parowane urządzenie", MessageBoxButtons.YesNo) == DialogResult.Yes) { e.Confirm = true; } else { e.Confirm = false; } } break; case BluetoothAuthenticationMethod.PasskeyNotification: MessageBox.Show("Notyfikacja o kluczu"); break; case BluetoothAuthenticationMethod.Passkey: MessageBox.Show("Klucz"); break; default: MessageBox.Show("Nieznany sposób obsługi parowania"); break; } }
void HndlrWithMsgBox(object sender, BluetoothWin32AuthenticationEventArgs e) { HndlrNoRespond(sender, e); var msg = string.Format( "Auth {0} {1} {2} {6} jw: {3}, n/pk: {4:G6} (default confirm: {5})", e.Device.DeviceAddress, e.Device.DeviceName, e.AuthenticationMethod, e.JustWorksNumericComparison, e.NumberOrPasskey, e.Confirm, e.AuthenticationRequirements); if (e.AuthenticationMethod == BluetoothAuthenticationMethod.Legacy) { e.Pin = console.ReadLine(msg + "\r\n" + "PIN?"); console.WriteLine("Using Pin: {0}", ToStringQuotedOrNull(e.Pin)); } else { var rsp = console.ReadYesNoCancel(msg, null); e.Confirm = rsp; } }
private void Handler(object sender, BluetoothWin32AuthenticationEventArgs e) { e.Confirm = true; }
private void HandleBluetoothAuthenticationRequests(object sender, BluetoothWin32AuthenticationEventArgs e) { Debug.WriteLine("Thread ID: {0}", Thread.CurrentThread.ManagedThreadId); 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 { Debug.WriteLine("Show User Numeric Comparison.\n"); var message = string.Format("Would you like to pair your device with \"{0}\"?\r\nMake sure that the pairing code \"{1}\" is displayed on \"{0}\".", new BluetoothDeviceInfoEx(e.Device).ToString(), e.NumberOrPasskeyAsString); if (MessageBox.Show(message, "Bluetooth pairing request", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes) { e.Confirm = true; if (InvokeRequired) { // In `pairToolStripButton__Click`, a pairing request is issued via: // Task.Run(() => BluetoothSecurity.PairRequest(address, null)); // In this case, HandleBluetoothAuthenticationRequests will be handled // from a different thread and we can not call `PopulateDevicesList(false);` // here directly to update the device list. Instead, we should use // `BeginInvoke` to dispatch it to the main thread. // But since `PopulateDevicesList` will be called later in // `pairToolStripButton__Click` after the paring request is handled, // we will not call: // BeginInvoke(new Action<bool>(PopulateDevicesList), true); // here again. Debug.WriteLine("Invoke Required.\n"); } else { PopulateDevicesList(); } } 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; } }
void HandleWin32Auth(object sender, BluetoothWin32AuthenticationEventArgs e) { Console.WriteLine("AuthMeth: " + e.AuthenticationMethod); e.Confirm = true; }
private void HandleRequests(object that, BluetoothWin32AuthenticationEventArgs e) { e.Confirm = true; }