Skip to content

This issue was moved to a discussion.

You can continue the conversation there. Go to discussion →

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How do I avoid os: error 111 (connection refused). #24

Closed
StratusFearMe21 opened this issue Feb 16, 2022 · 2 comments
Closed

How do I avoid os: error 111 (connection refused). #24

StratusFearMe21 opened this issue Feb 16, 2022 · 2 comments

Comments

@StratusFearMe21
Copy link

StratusFearMe21 commented Feb 16, 2022

Hello, I am attempting to make a lightweight device driver for the LG Magic Remote. However, when I try to connect to it through l2cap it errors out with an os error 111. This is my code so far. It just tries to connect to the Magic Remote and it begins to receive packets.

use bluer::{
    l2cap::{SocketAddr, Stream, PSM_LE_DYN_START},
    Address,
};
use tokio::io::AsyncReadExt;

#[tokio::main]
async fn main() -> bluer::Result<()> {
    let addr: Address = "7C:02:BC:C5:14:3B".parse().unwrap();
    let socket_addr = SocketAddr::new(addr, bluer::AddressType::LePublic, PSM_LE_DYN_START + 5);
    println!("Connecting to magic remote");
    let mut stream = Stream::connect(socket_addr).await?;
    println!("Local address: {:?}", stream.as_ref().local_addr()?);
    println!("Remote address: {:?}", stream.peer_addr()?);
    println!("Recv MTU: {}", stream.as_ref().recv_mtu()?);
    println!("Security: {:?}", stream.as_ref().security()?);

    loop {
        let mut hello_buf = [0u8; 30];
        stream
            .read_exact(&mut hello_buf)
            .await
            .expect("read failed");
        println!("Received: {:?}", hello_buf);
    }
}

This is what it prints out

Connecting to magic remote
Local address: SocketAddr { addr: E0:D4:E8:38:4D:65, addr_type: LePublic, psm: 133, cid: 64 }
Remote address: SocketAddr { addr: 7C:02:BC:C5:14:3B, addr_type: LePublic, psm: 133, cid: 0 }
Recv MTU: 672
Security: Security { level: Medium, key_size: 0 }
thread 'main' panicked at 'read failed: Os { code: 111, kind: ConnectionRefused, message: "Connection refused" }', src/main.rs:23:14
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace

Any ideas? Thanks!

@StratusFearMe21
Copy link
Author

P.S there's no evidence of errors caused by app when I run it and then run sudo systemctl status bluetooth

@StratusFearMe21 StratusFearMe21 changed the title How do I avoid os: error 11 (connection refused). How do I avoid os: error 111 (connection refused). Feb 16, 2022
@surban
Copy link
Collaborator

surban commented Feb 16, 2022

  1. Are you sure that the LG Magic Remote is accepting L2CAP connections?
  2. Are you sure that the port number is correct (PSM_LE_DYN_START + 5 in your case)?

@bluez bluez locked and limited conversation to collaborators Feb 16, 2022
@surban surban converted this issue into discussion #25 Feb 16, 2022

This issue was moved to a discussion.

You can continue the conversation there. Go to discussion →

Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants