github.com/la5nta/wl2k-go@v0.11.8/transport/ax25/agwpe/frame_kinds.go (about)

     1  package agwpe
     2  
     3  import (
     4  	"bytes"
     5  )
     6  
     7  type kind byte
     8  
     9  const (
    10  	kindLogin                    kind = 'P'
    11  	kindRegister                 kind = 'X'
    12  	kindUnregister               kind = 'x'
    13  	kindVersionNumber            kind = 'R'
    14  	kindOutstandingFramesForPort kind = 'y' // Direwolf >= 1.2
    15  	kindPortCapabilities         kind = 'g'
    16  
    17  	kindConnect                  kind = 'C'
    18  	kindConnectVia               kind = 'v'
    19  	kindDisconnect               kind = 'd'
    20  	kindConnectedData            kind = 'D'
    21  	kindOutstandingFramesForConn kind = 'Y' // Direwolf >= 1.4
    22  	kindUnprotoInformation       kind = 'M'
    23  )
    24  
    25  func versionNumberFrame() frame {
    26  	return frame{header: header{DataKind: kindVersionNumber}}
    27  }
    28  
    29  func portCapabilitiesFrame(port uint8) frame {
    30  	return frame{
    31  		header: header{
    32  			Port:     port,
    33  			DataKind: kindPortCapabilities,
    34  		},
    35  	}
    36  }
    37  
    38  func connectedDataFrame(port uint8, from, to string, data []byte) frame {
    39  	return frame{
    40  		header: header{
    41  			Port:     port,
    42  			DataKind: kindConnectedData,
    43  			PID:      0xf0,
    44  			From:     callsignFromString(from),
    45  			To:       callsignFromString(to),
    46  			DataLen:  uint32(len(data)),
    47  		},
    48  		Data: data,
    49  	}
    50  }
    51  
    52  func outstandingFramesForConnFrame(port uint8, from, to string) frame {
    53  	return frame{
    54  		header: header{
    55  			Port:     port,
    56  			DataKind: kindOutstandingFramesForConn,
    57  			From:     callsignFromString(from),
    58  			To:       callsignFromString(to),
    59  		},
    60  	}
    61  }
    62  
    63  func outstandingFramesForPortFrame(port uint8) frame {
    64  	return frame{
    65  		header: header{
    66  			Port:     port,
    67  			DataKind: kindOutstandingFramesForPort,
    68  		},
    69  	}
    70  }
    71  
    72  func loginFrame(username, password string) frame {
    73  	data := make([]byte, 255+255)
    74  	copy(data[:255], username)
    75  	copy(data[255:], password)
    76  	return frame{
    77  		header: header{DataKind: kindLogin},
    78  		Data:   data,
    79  	}
    80  }
    81  
    82  func registerCallsignFrame(callsign string, port uint8) frame {
    83  	h := header{DataKind: kindRegister, Port: port}
    84  	copy(h.From[:], callsign)
    85  	return frame{header: h}
    86  }
    87  
    88  func unregisterCallsignFrame(callsign string, port uint8) frame {
    89  	h := header{DataKind: kindUnregister}
    90  	copy(h.From[:], callsign)
    91  	return frame{header: h}
    92  }
    93  
    94  func connectFrame(from, to string, port uint8, digis []string) frame {
    95  	if len(digis) > 0 {
    96  		return connectViaFrame(from, to, port, digis)
    97  	}
    98  	return frame{header: header{
    99  		DataKind: kindConnect,
   100  		From:     callsignFromString(from),
   101  		To:       callsignFromString(to),
   102  	}}
   103  }
   104  
   105  func connectViaFrame(from, to string, port uint8, digis []string) frame {
   106  	h := header{
   107  		DataKind: kindConnectVia,
   108  		From:     callsignFromString(from),
   109  		To:       callsignFromString(to),
   110  	}
   111  	var buf bytes.Buffer
   112  	buf.WriteByte(uint8(len(digis)))
   113  	for _, str := range digis {
   114  		callsign := callsignFromString(str)
   115  		buf.Write([]byte(callsign[:]))
   116  	}
   117  	return frame{header: h, Data: buf.Bytes()}
   118  }
   119  
   120  func unprotoInformationFrame(from, to string, port uint8, data []byte) frame {
   121  	h := header{
   122  		DataKind: kindUnprotoInformation,
   123  		From:     callsignFromString(from),
   124  		To:       callsignFromString(to),
   125  	}
   126  	return frame{header: h, Data: data}
   127  }
   128  
   129  func disconnectFrame(from, to string, port uint8) frame {
   130  	h := header{DataKind: kindDisconnect}
   131  	copy(h.From[:], from)
   132  	copy(h.To[:], to)
   133  	return frame{header: h}
   134  }