Skip to content

Commit 2d5ffdc

Browse files
committed
bluetooth: extract send_params from aa_handshake
1 parent 021042e commit 2d5ffdc

File tree

1 file changed

+24
-19
lines changed

1 file changed

+24
-19
lines changed

src/bluetooth.rs

Lines changed: 24 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -514,25 +514,12 @@ impl Bluetooth {
514514
Ok(())
515515
}
516516

517-
pub async fn aa_handshake(
518-
&mut self,
519-
dongle_mode: bool,
520-
connect: BluetoothAddressList,
521-
wifi_config: WifiConfig,
522-
tcp_start: Arc<Notify>,
523-
bt_timeout: Duration,
524-
stopped: bool,
525-
) -> Result<()> {
517+
async fn send_params(wifi_config: WifiConfig, stream: &mut Stream) -> Result<()> {
526518
use WifiInfoResponse::WifiInfoResponse;
527519
use WifiStartRequest::WifiStartRequest;
528520
let mut stage = 1;
529521
let mut started;
530522

531-
// Use the provided session and adapter instead of creating new ones
532-
let (address, mut stream) = self
533-
.get_aa_profile_connection(dongle_mode, connect, bt_timeout, stopped)
534-
.await?;
535-
536523
info!("{} 📲 Sending parameters via bluetooth to phone...", NAME);
537524
let mut start_req = WifiStartRequest::new();
538525
info!(
@@ -541,10 +528,10 @@ impl Bluetooth {
541528
);
542529
start_req.set_ip_address(wifi_config.ip_addr);
543530
start_req.set_port(wifi_config.port);
544-
send_message(&mut stream, stage, MessageId::WifiStartRequest, start_req).await?;
531+
send_message(stream, stage, MessageId::WifiStartRequest, start_req).await?;
545532
stage += 1;
546533
started = Instant::now();
547-
read_message(&mut stream, stage, MessageId::WifiInfoRequest, started).await?;
534+
read_message(stream, stage, MessageId::WifiInfoRequest, started).await?;
548535

549536
let mut info = WifiInfoResponse::new();
550537
info!(
@@ -557,13 +544,31 @@ impl Bluetooth {
557544
info.set_security_mode(SecurityMode::WPA2_PERSONAL);
558545
info.set_access_point_type(AccessPointType::DYNAMIC);
559546
stage += 1;
560-
send_message(&mut stream, stage, MessageId::WifiInfoResponse, info).await?;
547+
send_message(stream, stage, MessageId::WifiInfoResponse, info).await?;
561548
stage += 1;
562549
started = Instant::now();
563-
read_message(&mut stream, stage, MessageId::WifiStartResponse, started).await?;
550+
read_message(stream, stage, MessageId::WifiStartResponse, started).await?;
564551
stage += 1;
565552
started = Instant::now();
566-
read_message(&mut stream, stage, MessageId::WifiConnectStatus, started).await?;
553+
read_message(stream, stage, MessageId::WifiConnectStatus, started).await?;
554+
555+
Ok(())
556+
}
557+
558+
pub async fn aa_handshake(
559+
&mut self,
560+
dongle_mode: bool,
561+
connect: BluetoothAddressList,
562+
wifi_config: WifiConfig,
563+
tcp_start: Arc<Notify>,
564+
bt_timeout: Duration,
565+
stopped: bool,
566+
) -> Result<()> {
567+
// Use the provided session and adapter instead of creating new ones
568+
let (address, mut stream) = self
569+
.get_aa_profile_connection(dongle_mode, connect, bt_timeout, stopped)
570+
.await?;
571+
Self::send_params(wifi_config.clone(), &mut stream).await?;
567572
tcp_start.notify_one();
568573

569574
// handshake complete, now disconnect the device so it should

0 commit comments

Comments
 (0)