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")]
pub mod tracking;
#[cfg(feature = "unstable")]
#[cfg(feature = "locker_ble")]
pub use locker::LockerClient;
/*#[cfg(test)]
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,
}
impl Client {
pub fn new() -> Self {
Client {
pub struct LockerSession {
api_client: reqwest::Client,
}
impl LockerClient {
pub async fn new() -> Self {
LockerClient {
client: reqwest::ClientBuilder::new()
.default_headers(headers())
.user_agent(user_agent())
@ -16,6 +29,21 @@ impl Client {
.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 {
@ -36,4 +64,66 @@ fn headers() -> HeaderMap {
}
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 crate::{LibraryError, LibraryResult};
// 601e7028-0565-
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 {
Keba,
@ -34,14 +33,12 @@ pub struct LockerVersion {
#[derive(Debug)]
pub struct LockerDevice {
pub id: PeripheralId,
pub service_uuid: LockerServiceUUID,
pub version: LockerVersion,
}
impl LockerDevice {
pub(crate) fn new(
id: PeripheralId,
pub fn new(
service_uuid: LockerServiceUUID,
service_data: &Vec<u8>,
) -> LibraryResult<Self> {
@ -70,14 +67,13 @@ impl LockerDevice {
println!("expected: {:?}", service_uuid);
Ok(LockerDevice {
id,
service_uuid,
version,
})
}
}
#[derive(Debug)]
#[derive(Debug, Clone, Copy)]
pub struct LockerServiceUUID {
service_uuid: uuid::Uuid,
}