Skip to content
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

x/sys/unix: Possible to create an RFCOMM socket? #22211

Closed
aka-mj opened this issue Oct 11, 2017 · 6 comments
Closed

x/sys/unix: Possible to create an RFCOMM socket? #22211

aka-mj opened this issue Oct 11, 2017 · 6 comments

Comments

@aka-mj
Copy link

aka-mj commented Oct 11, 2017

Hello,

What version of Go are you using (go version)?

$ go version
go version go1.9.1 linux/386

What operating system and processor architecture are you using (go env)?

$ go env
GOARCH="386"
GOBIN=""
GOEXE=""
GOHOSTARCH="386"
GOHOSTOS="linux"
GOOS="linux"
GOPATH="/home/mjohn/workspaces/goprojects"
GORACE=""
GOROOT="/home/mjohn/software/go"
GOTOOLDIR="/home/mjohn/software/go/pkg/tool/linux_386"
GCCGO="gccgo"
GO386="sse2"
CC="gcc"
GOGCCFLAGS="-fPIC -m32 -pthread -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build394932560=/tmp/go-build -gno-record-gcc-switches"
CXX="g++"
CGO_ENABLED="1"
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
PKG_CONFIG="pkg-config"

I'm trying to create an RFCOMM socket but not able to find a socket address type which works. Theres the Sockaddr... types available but none appear to support a Bluetooth RFCOMM socket. I'm assuming its possible because unix.AF_BLUETOOTH and unix.BTPROTO_RFCOMM are defined.
What am I missing?

package main

import (
	"fmt"
	"log"
	"strconv"
	"strings"
	"syscall"

	"golang.org/x/sys/unix"
)

// Bluetooth address string to byte array
func str2ba(addr string) [6]byte {
	a := strings.Split(addr, ":")
	var b [6]byte
	for i, tmp := range a {
		u, _ := strconv.ParseUint(tmp, 16, 8)
		b[i] = byte(u)
	}
	return b
}

func main() {
	fd, err := unix.Socket(syscall.AF_BLUETOOTH, syscall.SOCK_STREAM, unix.BTPROTO_RFCOMM)
	if err != nil {
		log.Fatalf("%v\n", err)
	}
	//addr := &unix.RawSockaddr?
       //addr := &unix.Sockaddr..?
	unix.Bind(fd, addr)
	unix.Write(fd, []byte("Hello"))
	var data []byte
	unix.Read(fd, data)
	fmt.Printf("Received: %v\n", string(data))
}

Thanks for your help!

@gopherbot gopherbot added this to the Unreleased milestone Oct 11, 2017
@mdlayher
Copy link
Member

You'd most likely have to implement a new sockaddr type, as I did here: golang/sys@d67a327.

I don't have time to immediately dig in, but perhaps this can lead you in the right direction.

@aka-mj
Copy link
Author

aka-mj commented Oct 12, 2017

Thanks Matt, with that I was able to create a functioning socket.
I'll submit a PR after a few days of testing.

@aka-mj aka-mj closed this as completed Oct 12, 2017
@simonswine
Copy link

@dangerousHobo how did you manage to get that working? Can't see something submitted in gerrit...

@mdlayher
Copy link
Member

mdlayher commented Nov 3, 2017

I'll reopen this for tracking, until a CL closes it.

@mdlayher mdlayher reopened this Nov 3, 2017
@gopherbot
Copy link

Change https://golang.org/cl/75971 mentions this issue: unix: implement Linux AF_BLUETOOTH RFCOMM sockets

simonswine added a commit to simonswine/golang-x-sys that referenced this issue Nov 5, 2017
Adds the required SockaddrRFCOMM type for working with Linux's bluetooth
rfcomm sockets.

Fixes golang/go#22211

Change-Id: I5d4a253c7a691066e10b751ee10c35eec00e388f
simonswine added a commit to simonswine/golang-x-sys that referenced this issue Nov 9, 2017
Adds the required SockaddrRFCOMM type for working with Linux's bluetooth
rfcomm sockets.

Fixes golang/go#22211

Change-Id: I5d4a253c7a691066e10b751ee10c35eec00e388f
simonswine added a commit to simonswine/golang-x-sys that referenced this issue Nov 9, 2017
Adds the required SockaddrRFCOMM type for working with Linux's bluetooth
rfcomm sockets.

Fixes golang/go#22211

Change-Id: I5d4a253c7a691066e10b751ee10c35eec00e388f
@tklauser tklauser changed the title x/sys: Possible to create an RFCOMM socket? x/sys/unix: Possible to create an RFCOMM socket? Nov 29, 2017
@tklauser tklauser modified the milestones: Unreleased, Unplanned Nov 29, 2017
@gopherbot
Copy link

Change https://golang.org/cl/122457 mentions this issue: x/sys/unix: implement RFCOMM sockets

@golang golang locked and limited conversation to collaborators Jul 9, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

5 participants