mirror of
https://github.com/kavishdevar/librepods.git
synced 2026-03-10 16:23:00 +00:00
linux-rust: store irk and enc keys
This commit is contained in:
2
linux-rust/Cargo.lock
generated
2
linux-rust/Cargo.lock
generated
@@ -1105,6 +1105,8 @@ dependencies = [
|
|||||||
"ksni",
|
"ksni",
|
||||||
"libpulse-binding",
|
"libpulse-binding",
|
||||||
"log",
|
"log",
|
||||||
|
"serde",
|
||||||
|
"serde_json",
|
||||||
"tokio",
|
"tokio",
|
||||||
"uuid",
|
"uuid",
|
||||||
]
|
]
|
||||||
|
|||||||
@@ -18,6 +18,8 @@ image = "0.25.8"
|
|||||||
imageproc = "0.25.0"
|
imageproc = "0.25.0"
|
||||||
ab_glyph = "0.2.32"
|
ab_glyph = "0.2.32"
|
||||||
clap = { version = "4.5.50", features = ["derive"] }
|
clap = { version = "4.5.50", features = ["derive"] }
|
||||||
|
serde = { version = "1.0", features = ["derive"] }
|
||||||
|
serde_json = "1.0"
|
||||||
|
|
||||||
[profile.release]
|
[profile.release]
|
||||||
opt-level = "s"
|
opt-level = "s"
|
||||||
|
|||||||
@@ -6,6 +6,8 @@ use tokio::sync::{Mutex, mpsc};
|
|||||||
use tokio::task::JoinSet;
|
use tokio::task::JoinSet;
|
||||||
use tokio::time::{sleep, Instant};
|
use tokio::time::{sleep, Instant};
|
||||||
use std::collections::HashMap;
|
use std::collections::HashMap;
|
||||||
|
use serde::{Deserialize, Serialize};
|
||||||
|
use serde_json;
|
||||||
|
|
||||||
const PSM: u16 = 0x1001;
|
const PSM: u16 = 0x1001;
|
||||||
const CONNECT_TIMEOUT: Duration = Duration::from_secs(10);
|
const CONNECT_TIMEOUT: Duration = Duration::from_secs(10);
|
||||||
@@ -124,12 +126,22 @@ impl ControlCommandIdentifiers {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[repr(u8)]
|
#[repr(u8)]
|
||||||
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
|
#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize, Hash)]
|
||||||
pub enum ProximityKeyType {
|
pub enum ProximityKeyType {
|
||||||
Irk = 0x01,
|
Irk = 0x01,
|
||||||
EncKey = 0x04,
|
EncKey = 0x04,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl ProximityKeyType {
|
||||||
|
fn from_u8(value: u8) -> Option<Self> {
|
||||||
|
match value {
|
||||||
|
0x01 => Some(Self::Irk),
|
||||||
|
0x04 => Some(Self::EncKey),
|
||||||
|
_ => None,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#[repr(u8)]
|
#[repr(u8)]
|
||||||
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
|
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
|
||||||
pub enum StemPressType {
|
pub enum StemPressType {
|
||||||
@@ -236,10 +248,15 @@ struct AACPManagerState {
|
|||||||
old_ear_detection_status: Vec<EarDetectionStatus>,
|
old_ear_detection_status: Vec<EarDetectionStatus>,
|
||||||
ear_detection_status: Vec<EarDetectionStatus>,
|
ear_detection_status: Vec<EarDetectionStatus>,
|
||||||
event_tx: Option<mpsc::UnboundedSender<AACPEvent>>,
|
event_tx: Option<mpsc::UnboundedSender<AACPEvent>>,
|
||||||
|
proximity_keys: HashMap<ProximityKeyType, Vec<u8>>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl AACPManagerState {
|
impl AACPManagerState {
|
||||||
fn new() -> Self {
|
fn new() -> Self {
|
||||||
|
let proximity_keys = std::fs::read_to_string("proximity_keys.json")
|
||||||
|
.ok()
|
||||||
|
.and_then(|s| serde_json::from_str(&s).ok())
|
||||||
|
.unwrap_or_default();
|
||||||
AACPManagerState {
|
AACPManagerState {
|
||||||
sender: None,
|
sender: None,
|
||||||
control_command_status_list: Vec::new(),
|
control_command_status_list: Vec::new(),
|
||||||
@@ -253,13 +270,14 @@ impl AACPManagerState {
|
|||||||
old_ear_detection_status: Vec::new(),
|
old_ear_detection_status: Vec::new(),
|
||||||
ear_detection_status: Vec::new(),
|
ear_detection_status: Vec::new(),
|
||||||
event_tx: None,
|
event_tx: None,
|
||||||
|
proximity_keys,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Clone)]
|
#[derive(Clone)]
|
||||||
pub struct AACPManager {
|
pub struct AACPManager {
|
||||||
state: Arc<Mutex<AACPManagerState>>,
|
pub state: Arc<Mutex<AACPManagerState>>,
|
||||||
tasks: Arc<Mutex<JoinSet<()>>>,
|
tasks: Arc<Mutex<JoinSet<()>>>,
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -541,7 +559,17 @@ impl AACPManager {
|
|||||||
offset += key_length;
|
offset += key_length;
|
||||||
}
|
}
|
||||||
info!("Received Proximity Keys Response: {:?}", keys.iter().map(|(kt, kd)| (kt, hex::encode(kd))).collect::<Vec<_>>());
|
info!("Received Proximity Keys Response: {:?}", keys.iter().map(|(kt, kd)| (kt, hex::encode(kd))).collect::<Vec<_>>());
|
||||||
let state = self.state.lock().await;
|
let mut state = self.state.lock().await;
|
||||||
|
for (key_type, key_data) in &keys {
|
||||||
|
if let Some(kt) = ProximityKeyType::from_u8(*key_type) {
|
||||||
|
state.proximity_keys.insert(kt, key_data.clone());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// Persist to file
|
||||||
|
let json = serde_json::to_string(&state.proximity_keys).unwrap();
|
||||||
|
if let Err(e) = tokio::fs::write("proximity_keys.json", json).await {
|
||||||
|
error!("Failed to save proximity keys: {}", e);
|
||||||
|
}
|
||||||
if let Some(ref tx) = state.event_tx {
|
if let Some(ref tx) = state.event_tx {
|
||||||
let _ = tx.send(AACPEvent::ProximityKeys(keys));
|
let _ = tx.send(AACPEvent::ProximityKeys(keys));
|
||||||
}
|
}
|
||||||
@@ -688,7 +716,7 @@ impl AACPManager {
|
|||||||
buffer.push(0x46);
|
buffer.push(0x46);
|
||||||
buffer.extend_from_slice(b"btName");
|
buffer.extend_from_slice(b"btName");
|
||||||
buffer.push(0x43);
|
buffer.push(0x43);
|
||||||
buffer.extend_from_slice(b"Mac");;
|
buffer.extend_from_slice(b"Mac");
|
||||||
buffer.push(0x58);
|
buffer.push(0x58);
|
||||||
buffer.extend_from_slice(b"otherDevice");
|
buffer.extend_from_slice(b"otherDevice");
|
||||||
buffer.extend_from_slice(b"AudioCategory");
|
buffer.extend_from_slice(b"AudioCategory");
|
||||||
|
|||||||
0
linux-rust/src/bluetooth/le.rs
Normal file
0
linux-rust/src/bluetooth/le.rs
Normal file
@@ -1,3 +1,4 @@
|
|||||||
pub(crate) mod discovery;
|
pub(crate) mod discovery;
|
||||||
pub mod aacp;
|
pub mod aacp;
|
||||||
// pub mod att;
|
// pub mod att;
|
||||||
|
pub mod le;
|
||||||
Reference in New Issue
Block a user