Loading system/gd/rust/linux/client/src/bt_gatt.rs +17 −9 Original line number Diff line number Diff line use bitflags::bitflags; use bt_topshim::btif::BtTransport; use bt_topshim::profiles::gatt::LePhy; bitflags! { pub(crate) struct AuthReq: i32 { #[repr(i32)] #[derive(Debug, Copy, Clone)] pub enum AuthReq { // reference to system/stack/include/gatt_api.h const MITM = 0x01; const SIGNED = 0x10; NONE = 0, EncNoMitm = 1, EncMitm = 2, SignedNoMitm = 3, SignedMitm = 4, } impl From<AuthReq> for i32 { fn from(auth_req: AuthReq) -> Self { auth_req as i32 } } Loading @@ -30,7 +38,7 @@ impl GattClientContext { pub(crate) fn new() -> Self { GattClientContext { client_id: None, auth_req: AuthReq::empty(), auth_req: AuthReq::NONE, is_connect_direct: false, connect_transport: BtTransport::Le, connect_opportunistic: false, Loading @@ -38,7 +46,7 @@ impl GattClientContext { } } pub(crate) fn get_auth_req_bits(&self) -> i32 { self.auth_req.bits() pub(crate) fn get_auth_req(&self) -> AuthReq { self.auth_req } } system/gd/rust/linux/client/src/command_handler.rs +10 −15 Original line number Diff line number Diff line Loading @@ -184,7 +184,7 @@ fn build_commands() -> HashMap<String, CommandOption> { String::from("gatt set-connect-transport <Bredr|LE|Auto>"), String::from("gatt set-connect-opportunistic <true|false>"), String::from("gatt set-connect-phy <Phy1m|Phy2m|PhyCoded>"), String::from("gatt set-auth-req <MITM|SIGNED> <enable|disable>"), String::from("gatt set-auth-req <NONE|EncNoMitm|EncMitm|SignedNoMitm|SignedMitm>"), String::from( "gatt write-characteristic <address> <handle> <NoRsp|Write|Prepare> <value>", ), Loading Loading @@ -1003,23 +1003,18 @@ impl CommandHandler { } "set-auth-req" => { let flag = match &get_arg(args, 1)?[..] { "MITM" => AuthReq::MITM, "SIGNED" => AuthReq::SIGNED, "NONE" => AuthReq::NONE, "EncNoMitm" => AuthReq::EncNoMitm, "EncMitm" => AuthReq::EncMitm, "SignedNoMitm" => AuthReq::SignedNoMitm, "SignedMitm" => AuthReq::SignedMitm, _ => { return Err("Failed to parse auth-req".into()); } }; let enable = match &get_arg(args, 2)?[..] { "enable" => true, "disable" => false, _ => { return Err("Failed to parse enable".into()); } }; self.lock_context().gatt_client_context.auth_req.set(flag, enable); println!("AuthReq: {:?}", self.lock_context().gatt_client_context.auth_req); self.lock_context().gatt_client_context.auth_req = flag; println!("AuthReq: {:?}", self.lock_context().gatt_client_context.get_auth_req()); } "write-characteristic" => { let addr = String::from(get_arg(args, 1)?); Loading @@ -1044,7 +1039,7 @@ impl CommandHandler { .client_id .ok_or("GATT client is not yet registered.")?; let auth_req = self.lock_context().gatt_client_context.get_auth_req_bits(); let auth_req = self.lock_context().gatt_client_context.get_auth_req().into(); self.lock_context() .gatt_dbus Loading @@ -1063,7 +1058,7 @@ impl CommandHandler { .client_id .ok_or("GATT client is not yet registered.")?; let auth_req = self.lock_context().gatt_client_context.get_auth_req_bits(); let auth_req = self.lock_context().gatt_client_context.get_auth_req().into(); self.lock_context() .gatt_dbus Loading Loading
system/gd/rust/linux/client/src/bt_gatt.rs +17 −9 Original line number Diff line number Diff line use bitflags::bitflags; use bt_topshim::btif::BtTransport; use bt_topshim::profiles::gatt::LePhy; bitflags! { pub(crate) struct AuthReq: i32 { #[repr(i32)] #[derive(Debug, Copy, Clone)] pub enum AuthReq { // reference to system/stack/include/gatt_api.h const MITM = 0x01; const SIGNED = 0x10; NONE = 0, EncNoMitm = 1, EncMitm = 2, SignedNoMitm = 3, SignedMitm = 4, } impl From<AuthReq> for i32 { fn from(auth_req: AuthReq) -> Self { auth_req as i32 } } Loading @@ -30,7 +38,7 @@ impl GattClientContext { pub(crate) fn new() -> Self { GattClientContext { client_id: None, auth_req: AuthReq::empty(), auth_req: AuthReq::NONE, is_connect_direct: false, connect_transport: BtTransport::Le, connect_opportunistic: false, Loading @@ -38,7 +46,7 @@ impl GattClientContext { } } pub(crate) fn get_auth_req_bits(&self) -> i32 { self.auth_req.bits() pub(crate) fn get_auth_req(&self) -> AuthReq { self.auth_req } }
system/gd/rust/linux/client/src/command_handler.rs +10 −15 Original line number Diff line number Diff line Loading @@ -184,7 +184,7 @@ fn build_commands() -> HashMap<String, CommandOption> { String::from("gatt set-connect-transport <Bredr|LE|Auto>"), String::from("gatt set-connect-opportunistic <true|false>"), String::from("gatt set-connect-phy <Phy1m|Phy2m|PhyCoded>"), String::from("gatt set-auth-req <MITM|SIGNED> <enable|disable>"), String::from("gatt set-auth-req <NONE|EncNoMitm|EncMitm|SignedNoMitm|SignedMitm>"), String::from( "gatt write-characteristic <address> <handle> <NoRsp|Write|Prepare> <value>", ), Loading Loading @@ -1003,23 +1003,18 @@ impl CommandHandler { } "set-auth-req" => { let flag = match &get_arg(args, 1)?[..] { "MITM" => AuthReq::MITM, "SIGNED" => AuthReq::SIGNED, "NONE" => AuthReq::NONE, "EncNoMitm" => AuthReq::EncNoMitm, "EncMitm" => AuthReq::EncMitm, "SignedNoMitm" => AuthReq::SignedNoMitm, "SignedMitm" => AuthReq::SignedMitm, _ => { return Err("Failed to parse auth-req".into()); } }; let enable = match &get_arg(args, 2)?[..] { "enable" => true, "disable" => false, _ => { return Err("Failed to parse enable".into()); } }; self.lock_context().gatt_client_context.auth_req.set(flag, enable); println!("AuthReq: {:?}", self.lock_context().gatt_client_context.auth_req); self.lock_context().gatt_client_context.auth_req = flag; println!("AuthReq: {:?}", self.lock_context().gatt_client_context.get_auth_req()); } "write-characteristic" => { let addr = String::from(get_arg(args, 1)?); Loading @@ -1044,7 +1039,7 @@ impl CommandHandler { .client_id .ok_or("GATT client is not yet registered.")?; let auth_req = self.lock_context().gatt_client_context.get_auth_req_bits(); let auth_req = self.lock_context().gatt_client_context.get_auth_req().into(); self.lock_context() .gatt_dbus Loading @@ -1063,7 +1058,7 @@ impl CommandHandler { .client_id .ok_or("GATT client is not yet registered.")?; let auth_req = self.lock_context().gatt_client_context.get_auth_req_bits(); let auth_req = self.lock_context().gatt_client_context.get_auth_req().into(); self.lock_context() .gatt_dbus Loading