diff options
| author | Kevin Wallace <kevin@pentabarf.net> | 2026-03-05 20:17:40 -0800 |
|---|---|---|
| committer | Kevin Wallace <kevin@pentabarf.net> | 2026-03-05 20:17:40 -0800 |
| commit | 5330acd5616184b91bd89cff56c63a5a4342de29 (patch) | |
| tree | 6e56518a8d3c0af43fa9e230c5e657ec48681178 /ipp | |
| parent | add ISOCardReleased (diff) | |
make protocol trace logging optional, default off
Diffstat (limited to 'ipp')
| -rw-r--r-- | ipp/ipp.go | 19 |
1 files changed, 15 insertions, 4 deletions
@@ -3,6 +3,7 @@ package ipp import ( "encoding/binary" "encoding/hex" + "flag" "hash/crc32" "io" "log" @@ -11,6 +12,8 @@ import ( "golang.org/x/sys/unix" ) +var Trace = flag.Bool("ipp-trace", false, "log IPP protocol traces") + var crc8table = [256]byte{ 0x00, 0x5e, 0xbc, 0xe2, 0x61, 0x3f, 0xdd, 0x83, 0xc2, 0x9c, 0x7e, 0x20, 0xa3, 0xfd, 0x1f, 0x41, 0x9d, 0xc3, 0x21, 0x7f, 0xfc, 0xa2, 0x40, 0x1e, 0x5f, 0x01, 0xe3, 0xbd, 0x3e, 0x60, 0x82, 0xdc, @@ -107,7 +110,9 @@ func (s *session) handleMsg(bs []byte) (nRead int) { } msgType := bs[0] if msgType != 0xbc { - log.Printf("skipping non-IPP message %s", hex.EncodeToString(bs)) + if *Trace { + log.Printf("skipping non-IPP message %s", hex.EncodeToString(bs)) + } nRead = len(bs) return } @@ -148,7 +153,9 @@ func (s *session) handleMsg(bs []byte) (nRead int) { if ippLen > 0 { ellipsis = "..." } - log.Printf("%s < %s%s%s", s.path, hex.EncodeToString(bs[:7]), ellipsis, hex.EncodeToString(bs[7+ippLen:expectedLen])) + if *Trace { + 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) } @@ -163,7 +170,9 @@ func (s *session) Close() error { } func (s *session) Write(bs []byte) (int, error) { - log.Printf("%s > %s", s.path, hex.EncodeToString(bs)) + if *Trace { + log.Printf("%s > %s", s.path, hex.EncodeToString(bs)) + } return unix.Write(s.fd, bs) } @@ -183,7 +192,9 @@ func (s *session) SendIPP(ippType byte, ippData []byte) error { msgCRC = make([]byte, 4) binary.LittleEndian.PutUint32(msgCRC, ^crc32.ChecksumIEEE(ippData)) } - log.Printf("%s > %s%s%s", s.path, hex.EncodeToString(ippHdr), hex.EncodeToString(ippData), hex.EncodeToString(msgCRC)) + if *Trace { + log.Printf("%s > %s%s%s", s.path, hex.EncodeToString(ippHdr), hex.EncodeToString(ippData), hex.EncodeToString(msgCRC)) + } if _, err := unix.Writev(s.fd, [][]byte{ippHdr, ippData, msgCRC}); err != nil { return err } |