Skip to content

Commit

Permalink
Merge pull request #4 from CodyJung/garmin-send-fix
Browse files Browse the repository at this point in the history
Fix failing to send data to Garmin devices
  • Loading branch information
ganeshrvel committed Nov 4, 2022
2 parents 78f11ba + c0045d5 commit 0d40588
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions mtp/mtp.go
Original file line number Diff line number Diff line change
Expand Up @@ -442,6 +442,20 @@ func (d *Device) runTransaction(req *Container, rep *Container,
dest.Write(rest)

if len(rest)+usbHdrLen == fetchPacketSize || uint32(n) < h.Length {
// Special case: From appendix H in the MTP 1.1 spec, the
// device can send a 12-byte packet followed by the rest of the
// data in a separate packet. After that point, both parties must
// follow the same rule.
// To detect this, if this is the first packet of a larger container
// data packet AND it's 12 bytes, set SeparateHeader to TRUE so we
// correctly send data back to the receiver.
if n == usbHdrLen && len(rest) == 0 && uint32(n) < h.Length {
d.SeparateHeader = true
if d.MTPDebug {
log.Printf("Device appears to have split header/data. Switched to separate header mode.")
}
}

// If this was a full packet, or if the packet wasn't full but
// the device said it was sending more data than we received,
// continue reading until we have a read less than a full packet.
Expand Down

0 comments on commit 0d40588

Please sign in to comment.