Skip to content

Commit

Permalink
Merge pull request #3376 from embassy-rs/nrf91-sim-pin
Browse files Browse the repository at this point in the history
Add config option for setting SIM pin
  • Loading branch information
lulf authored Sep 26, 2024
2 parents 8a5d145 + f19718b commit eb91089
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
12 changes: 12 additions & 0 deletions embassy-net-nrf91/src/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ pub struct Config<'a> {
pub auth_prot: AuthProt,
/// Credentials.
pub auth: Option<(&'a [u8], &'a [u8])>,
/// SIM pin
pub pin: Option<&'a [u8]>,
}

/// Authentication protocol.
Expand Down Expand Up @@ -133,6 +135,16 @@ impl<'a> Control<'a> {
// info!("RES2: {}", unsafe { core::str::from_utf8_unchecked(&buf[..n]) });
CommandParser::parse(&buf[..n]).expect_identifier(b"OK").finish()?;

if let Some(pin) = config.pin {
let op = CommandBuilder::create_set(&mut cmd, true)
.named("+CPIN")
.with_string_parameter(pin)
.finish()
.map_err(|_| Error::BufferTooSmall)?;
let _ = self.control.at_command(op, &mut buf).await;
// Ignore ERROR which means no pin required
}

Ok(())
}

Expand Down
1 change: 1 addition & 0 deletions examples/nrf9160/src/bin/modem_tcp_client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,7 @@ async fn main(spawner: Spawner) {
apn: b"iot.nat.es",
auth_prot: context::AuthProt::Pap,
auth: Some((b"orange", b"orange")),
pin: None,
},
stack
)));
Expand Down

0 comments on commit eb91089

Please sign in to comment.