feat: push locker experiment

This commit is contained in:
jane400 2024-09-16 10:36:26 +02:00 committed by jane400
parent 4a14488496
commit 0bcc953e72
3 changed files with 104 additions and 14 deletions

View file

@ -24,6 +24,10 @@ pub use advices::AdviceClient;
#[cfg(feature = "unstable")] #[cfg(feature = "unstable")]
pub mod tracking; pub mod tracking;
#[cfg(feature = "unstable")]
#[cfg(feature = "locker_ble")]
pub use locker::LockerClient;
/*#[cfg(test)] /*#[cfg(test)]
pub(crate) mod private;*/ pub(crate) mod private;*/

View file

@ -1,14 +1,27 @@
use reqwest::{header::HeaderMap, Request, RequestBuilder}; use std::collections::HashMap;
use crate::constants::{app_version, web_user_agent}; use reqwest::header::HeaderMap;
pub struct Client { use crate::{
constants::{app_version, web_user_agent},
locker::LockerServiceUUID,
};
use super::{crypto::CustomerKeySeed, LockerDevice};
use serde::{self, Deserialize, Serialize};
pub struct LockerClient {
client: reqwest::Client, client: reqwest::Client,
} }
impl Client { pub struct LockerSession {
pub fn new() -> Self { api_client: reqwest::Client,
Client { }
impl LockerClient {
pub async fn new() -> Self {
LockerClient {
client: reqwest::ClientBuilder::new() client: reqwest::ClientBuilder::new()
.default_headers(headers()) .default_headers(headers())
.user_agent(user_agent()) .user_agent(user_agent())
@ -16,6 +29,21 @@ impl Client {
.unwrap(), .unwrap(),
} }
} }
pub async fn open_session(
&self,
device: LockerDevice,
seed: &CustomerKeySeed,
) -> LockerSession {
let request = LoginCustomerRequest {
device_id: seed.device_id.as_ref().unwrap().clone(),
firmware_version: todo!(),
postnumber: seed.postnumber.clone(),
signature: todo!(),
tlv_message: todo!(),
uuid: todo!(),
};
}
} }
fn user_agent() -> String { fn user_agent() -> String {
@ -36,4 +64,66 @@ fn headers() -> HeaderMap {
} }
map map
} }
fn endpoint_auth_login_customer() -> &'static str {
"https://packstation.de/lpsAuth/auth/loginCustomer"
}
fn endpoint_service_session(locker_uuid: &str) -> String {
format!(
"https://packstation.de/lpsService/customer/v31/locker/{}/session",
locker_uuid
)
}
#[derive(Deserialize, Serialize)]
#[serde(rename_all = "camelCase")]
struct LoginCustomerRequest {
device_id: String,
firmware_version: String,
postnumber: String,
signature: String,
tlv_message: String,
uuid: String,
}
#[derive(Deserialize, Serialize)]
#[serde(rename_all = "camelCase")]
struct LoginCustomerResponse {
access_token: String,
refresh_token: String,
}
#[derive(Deserialize, Serialize)]
#[serde(rename_all = "camelCase")]
struct LockerMetadata {
firmware_version: String,
}
#[derive(Deserialize, Serialize)]
#[serde(rename_all = "camelCase")]
struct Command {
lps_command_string: String,
}
#[derive(Deserialize, Serialize)]
#[serde(rename_all = "camelCase")]
struct SessionRequest {
locker: LockerMetadata,
}
#[derive(Deserialize, Serialize)]
#[serde(rename_all = "camelCase")]
struct LpsState {
open_compartments: Vec<u32>,
opened_compartments: Vec<u32>,
}
#[derive(Deserialize, Serialize)]
#[serde(rename_all = "camelCase")]
struct SessionResponse {
lps_command_string: String,
lps_state: LpsState,
response_required: bool,
}

View file

@ -1,10 +1,9 @@
use btleplug::platform::PeripheralId;
use super::utils::PrimitiveReader; use super::utils::PrimitiveReader;
use crate::{LibraryError, LibraryResult}; use crate::{LibraryError, LibraryResult};
// 601e7028-0565- // 601e7028-0565-
pub static LOCKER_SERVICE_UUID_PREFIX: (u32, u16) = (0x601e7028, 0x0565); pub static LOCKER_SERVICE_UUID_PREFIX: (u32, u16) = (0x601e7028, 0x0565);
pub static LOCKER_SERVICE_UUID: uuid::Uuid = uuid::Builder::from_fields(LOCKER_SERVICE_UUID_PREFIX.0, LOCKER_SERVICE_UUID_PREFIX.1, 0, &[0;8]).into_uuid();
pub enum LockerVendor { pub enum LockerVendor {
Keba, Keba,
@ -34,14 +33,12 @@ pub struct LockerVersion {
#[derive(Debug)] #[derive(Debug)]
pub struct LockerDevice { pub struct LockerDevice {
pub id: PeripheralId,
pub service_uuid: LockerServiceUUID, pub service_uuid: LockerServiceUUID,
pub version: LockerVersion, pub version: LockerVersion,
} }
impl LockerDevice { impl LockerDevice {
pub(crate) fn new( pub fn new(
id: PeripheralId,
service_uuid: LockerServiceUUID, service_uuid: LockerServiceUUID,
service_data: &Vec<u8>, service_data: &Vec<u8>,
) -> LibraryResult<Self> { ) -> LibraryResult<Self> {
@ -70,14 +67,13 @@ impl LockerDevice {
println!("expected: {:?}", service_uuid); println!("expected: {:?}", service_uuid);
Ok(LockerDevice { Ok(LockerDevice {
id,
service_uuid, service_uuid,
version, version,
}) })
} }
} }
#[derive(Debug)] #[derive(Debug, Clone, Copy)]
pub struct LockerServiceUUID { pub struct LockerServiceUUID {
service_uuid: uuid::Uuid, service_uuid: uuid::Uuid,
} }