diff --git a/libpaket/src/lib.rs b/libpaket/src/lib.rs index 3181520..9455fd4 100644 --- a/libpaket/src/lib.rs +++ b/libpaket/src/lib.rs @@ -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;*/ diff --git a/libpaket/src/locker/api.rs b/libpaket/src/locker/api.rs index 27fd188..1d3fabe 100644 --- a/libpaket/src/locker/api.rs +++ b/libpaket/src/locker/api.rs @@ -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 -} \ No newline at end of file +} + +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, + opened_compartments: Vec, +} + +#[derive(Deserialize, Serialize)] +#[serde(rename_all = "camelCase")] +struct SessionResponse { + lps_command_string: String, + lps_state: LpsState, + response_required: bool, +} diff --git a/libpaket/src/locker/types.rs b/libpaket/src/locker/types.rs index 4a95ba4..615cdae 100644 --- a/libpaket/src/locker/types.rs +++ b/libpaket/src/locker/types.rs @@ -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, ) -> LibraryResult { @@ -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, }