mirror of
https://github.com/tinygo-org/drivers.git
synced 2026-07-26 10:38:41 +00:00
wifinina: implement ConnectModeAP
Signed-off-by: deadprogram <ron@hybridgroup.com>
This commit is contained in:
+83
-7
@@ -47,6 +47,9 @@ const (
|
|||||||
statusConnectFailed connectionStatus = 4
|
statusConnectFailed connectionStatus = 4
|
||||||
statusConnectionLost connectionStatus = 5
|
statusConnectionLost connectionStatus = 5
|
||||||
statusDisconnected connectionStatus = 6
|
statusDisconnected connectionStatus = 6
|
||||||
|
statusAPListening connectionStatus = 7
|
||||||
|
statusAPConnected connectionStatus = 8
|
||||||
|
statusAPFailed connectionStatus = 9
|
||||||
|
|
||||||
encTypeTKIP encryptionType = 2
|
encTypeTKIP encryptionType = 2
|
||||||
encTypeCCMP encryptionType = 4
|
encTypeCCMP encryptionType = 4
|
||||||
@@ -299,6 +302,61 @@ func (w *wifinina) connectToAP() error {
|
|||||||
return netlink.ErrConnectTimeout
|
return netlink.ErrConnectTimeout
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (w *wifinina) startAP() error {
|
||||||
|
timeout := w.params.ConnectTimeout
|
||||||
|
if timeout == 0 {
|
||||||
|
timeout = netlink.DefaultConnectTimeout
|
||||||
|
}
|
||||||
|
|
||||||
|
if len(w.params.Ssid) == 0 {
|
||||||
|
return netlink.ErrMissingSSID
|
||||||
|
}
|
||||||
|
|
||||||
|
if debugging(debugBasic) {
|
||||||
|
fmt.Printf("Starting Wifi AP as SSID '%s'...", w.params.Ssid)
|
||||||
|
}
|
||||||
|
|
||||||
|
start := time.Now()
|
||||||
|
|
||||||
|
// Start the connection process
|
||||||
|
switch {
|
||||||
|
case w.params.Passphrase != "":
|
||||||
|
w.setPassphraseForAP(w.params.Ssid, w.params.Passphrase)
|
||||||
|
default:
|
||||||
|
w.setNetworkForAP(w.params.Ssid)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Check if we are listening
|
||||||
|
for {
|
||||||
|
status := w.getConnectionStatus()
|
||||||
|
switch status {
|
||||||
|
case statusAPListening:
|
||||||
|
if debugging(debugBasic) {
|
||||||
|
fmt.Printf("LISTENING\r\n")
|
||||||
|
}
|
||||||
|
if w.notifyCb != nil {
|
||||||
|
w.notifyCb(netlink.EventNetUp)
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
case statusAPFailed:
|
||||||
|
if debugging(debugBasic) {
|
||||||
|
fmt.Printf("FAILED (%s)\r\n", w.reason())
|
||||||
|
}
|
||||||
|
return netlink.ErrConnectFailed
|
||||||
|
}
|
||||||
|
if time.Since(start) > timeout {
|
||||||
|
break
|
||||||
|
}
|
||||||
|
time.Sleep(1 * time.Second)
|
||||||
|
}
|
||||||
|
|
||||||
|
if debugging(debugBasic) {
|
||||||
|
fmt.Printf("FAILED (timed out)\r\n")
|
||||||
|
}
|
||||||
|
|
||||||
|
return netlink.ErrConnectTimeout
|
||||||
|
}
|
||||||
|
|
||||||
func (w *wifinina) netDisconnect() {
|
func (w *wifinina) netDisconnect() {
|
||||||
w.disconnect()
|
w.disconnect()
|
||||||
}
|
}
|
||||||
@@ -380,7 +438,12 @@ func (w *wifinina) showIP() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (w *wifinina) networkDown() bool {
|
func (w *wifinina) networkDown() bool {
|
||||||
return w.getConnectionStatus() != statusConnected
|
switch w.getConnectionStatus() {
|
||||||
|
case statusConnected, statusAPListening, statusAPConnected:
|
||||||
|
return false
|
||||||
|
default:
|
||||||
|
return true
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (w *wifinina) watchdog() {
|
func (w *wifinina) watchdog() {
|
||||||
@@ -418,15 +481,28 @@ func (w *wifinina) netConnect(reset bool) error {
|
|||||||
}
|
}
|
||||||
w.showDevice()
|
w.showDevice()
|
||||||
|
|
||||||
|
retry:
|
||||||
for i := 0; w.params.Retries == 0 || i < w.params.Retries; i++ {
|
for i := 0; w.params.Retries == 0 || i < w.params.Retries; i++ {
|
||||||
if err := w.connectToAP(); err != nil {
|
switch w.params.ConnectMode {
|
||||||
switch err {
|
case netlink.ConnectModeAP:
|
||||||
case netlink.ErrConnectTimeout, netlink.ErrConnectFailed:
|
if err := w.startAP(); err != nil {
|
||||||
continue
|
switch err {
|
||||||
|
case netlink.ErrConnectTimeout, netlink.ErrConnectFailed:
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
return err
|
||||||
}
|
}
|
||||||
return err
|
break retry
|
||||||
|
default:
|
||||||
|
if err := w.connectToAP(); err != nil {
|
||||||
|
switch err {
|
||||||
|
case netlink.ErrConnectTimeout, netlink.ErrConnectFailed:
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
break retry
|
||||||
}
|
}
|
||||||
break
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if w.networkDown() {
|
if w.networkDown() {
|
||||||
|
|||||||
Reference in New Issue
Block a user