diff options
| author | Kevin Wallace <kevin@pentabarf.net> | 2026-04-26 10:29:08 -0700 |
|---|---|---|
| committer | Kevin Wallace <kevin@pentabarf.net> | 2026-04-26 10:43:21 -0700 |
| commit | eb13241672e34b7d982f0644aa9bced34edcf493 (patch) | |
| tree | 8646d45d5ea6dbae51b6f43b0d1ed9b3d3d4f633 /ipp/ipp.go | |
| parent | cvend wip (diff) | |
Diffstat (limited to 'ipp/ipp.go')
| -rw-r--r-- | ipp/ipp.go | 22 |
1 files changed, 12 insertions, 10 deletions
@@ -13,6 +13,7 @@ import ( ) var Trace = flag.Bool("ipp-trace", false, "log IPP protocol traces") +var Seq = flag.Int("ipp-seq", 0, "IPP sequence counter start value") var crc8table = [256]byte{ 0x00, 0x5e, 0xbc, 0xe2, 0x61, 0x3f, 0xdd, 0x83, 0xc2, 0x9c, 0x7e, 0x20, 0xa3, 0xfd, 0x1f, 0x41, @@ -40,12 +41,12 @@ func crc8(bs ...byte) (x byte) { return } -type Handler func(byte, []byte) +type Handler func(seq, replyTo byte, msgType byte, msgData []byte) type Session interface { io.Closer io.Writer - SendIPP(ippType byte, ippData []byte) error + SendIPP(ippType byte, replyTo byte, ippData []byte) error } type session struct { @@ -81,9 +82,10 @@ func Open(path string, handler Handler) (Session, error) { } s := &session{ - path: path, - fd: fd, - handler: handler, + path: path, + fd: fd, + handler: handler, + nextSeqOut: byte(*Seq), } go s.readTask() return s, nil @@ -128,8 +130,8 @@ func (s *session) handleMsg(bs []byte) (nConsumed int) { if len(bs) < expectedLen { return } - _ = bs[1] // seq - _ = bs[2] // unknown + seq := bs[1] // seq + replyTo := bs[2] ippType := bs[3] ippLen := int(bs[4])<<8 + int(bs[5]) hdrCRC := bs[6] @@ -165,7 +167,7 @@ func (s *session) handleMsg(bs []byte) (nConsumed int) { log.Printf("%s < %s%s%s", s.path, hex.EncodeToString(bs[:7]), ellipsis, hex.EncodeToString(bs[7+ippLen:expectedLen])) } if s.handler != nil { - s.handler(ippType, ippData) + s.handler(seq, replyTo, ippType, ippData) } return } @@ -186,7 +188,7 @@ func (s *session) Write(bs []byte) (int, error) { return unix.Write(s.fd, bs) } -func (s *session) SendIPP(ippType byte, ippData []byte) error { +func (s *session) SendIPP(ippType byte, replyTo byte, ippData []byte) error { s.mu.Lock() s.nextSeqOut++ if s.nextSeqOut == 0 { @@ -195,7 +197,7 @@ func (s *session) SendIPP(ippType byte, ippData []byte) error { seq := s.nextSeqOut s.mu.Unlock() ippLen := len(ippData) - ippHdr := []byte{0xbc, seq, 0, ippType, byte(ippLen >> 8), byte(ippLen), 0} + ippHdr := []byte{0xbc, seq, replyTo, ippType, byte(ippLen >> 8), byte(ippLen), 0} ippHdr[6] = crc8(ippHdr[:6]...) var msgCRC []byte if ippType&0x80 != 0 { |