-
Notifications
You must be signed in to change notification settings - Fork 4
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Interesting packet from FMC880 (firmware bug in FMC880?) #4
Comments
The test code looks like this: package server
import (
"encoding/binary"
"encoding/hex"
"fmt"
"testing"
"time"
"github.com/alim-zanibekov/teltonika"
"github.com/davecgh/go-spew/spew"
"github.com/lab5e/tracker/pkg/bufreader"
"github.com/stretchr/testify/require"
)
const (
data = "00000000000003c68e04000001909d6417c801062c583a25ce28b9004f004530000000ef0011000500ef0000f00100150300c800004501000a00b5000800b60004004234a90018000000430ef700440052001100900012fc4c0013fb77000f03e8000200f100005e89001000003f9a00000000000001909d606e5201062bc70c25ccd6d50096010032000000ef0011000500ef0100f00100150500c800004501000a00b5000800b60005004237780018000000430ed500440000001100da0012fd0e0013f9ef000f03e8000200f100005e89001000003a6400000000000001909d4f2c5001062bc70c25ccd6d5009601002c000000ef0011000500ef0000f00100150500c800004501000a00b5000800b60005004234b10018000000430f0300440041001100db0012fd0d0013f9e9000f0047000200f100005e89001000003a6400000000000001909d4e03d501062c0f5025cdd1170068008130004800f700030002013d0100f70500000000000000010101025801dffe02f95d01c2fdc4f97001b1fde2f96f0193fdd2f97001a1fe01f95f0171fdfff95001b1fdf3f97e01a1fe01f95f0200fdd5f97d01eefe12f95c01affe31f96d01d0fe33f9aa01cffe62f9a901b1fe43f9ba01a0fe51f99b0200fe05f99b01d0fe33f99b0170fe6ff99b0161fe6ff9ab0164fe22f9cd0192fe22f99d0183fe32f9cc0170fe6ff99b0142fe4ff99d0133fe6ef9bc0172fe30f99d01c2fe15f9cb019ffe70f99a0182fe11f97e0183fdf2f99f0152fe2ff98e0163fe21f9ae0181fe2ff96e0152fe2ff98e0162fe30f98e0191fe11f97e01c0fe12f97d019ffe20f94e0180fe2ff95e0192fde1f96001a1fdf1f95f01d1fdc4f96f01a2fdc2f95101bffdf0f9300182fde1f96101d1fdb3f94101a1fdd0f93201c2fda3f95101b1fdd1f94101b1fdd1f94101effde3f94e01b0fdf1f94001c0fde1f94001c1fdd2f9500171fdeef92201b0fde1f94001a1fdc1f93201a0fdc0f9130171fdcff92301dffdb2f9120190fdfff9300191fde0f9410191fe00f95f0172fdd0f94201cffde1f92001bdfdeef8e201affdd0f91201c0fdc2f93101a1fdb1f93301bffde0f92101f1fd74f92301a1fd80f8f601d1fd83f91401a0fdaff8f401a0fde0f92101affdc0f90301bffdd0f90201dffdb1f90201cefdbff8e301eefda2f8f3019ffdaef8c501f0fd94f932019ffddff90201b0fe01f94f01ddfdfff90001bbfe4cf8ee01befe30f94d01cdfe1ff90f01cffdf2f94f019ffe1ff93f01b1fdd2f9600191fe00f95f0184fdc3f9910192fe12f99d01a0fe10f95e0180fe4ff97c01a1fe31f98c01a0fe21f96e0193fdf2f98f0191fe21f98d0400006a960000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000"
)
func TestBuggyPacket(t *testing.T) {
packet, err := hex.DecodeString(data)
require.NoError(t, err)
b := bufreader.New(packet, binary.BigEndian)
preamble, err := b.Uint32()
require.NoError(t, err)
fmt.Printf("preamble = %d\n", preamble)
length, err := b.Uint32()
require.NoError(t, err)
fmt.Printf("length = %d\n", length)
codec, err := b.Uint8()
require.NoError(t, err)
fmt.Printf("codec = 0x%02x\n", codec)
numdata1, err := b.Uint8()
require.NoError(t, err)
fmt.Printf("numdata = %d\n", numdata1)
for i := 0; i < 4; i++ {
println("element ", i)
timestamp, err := b.Int64()
require.NoError(t, err)
fmt.Printf(" timestamp = %d (%s)\n", timestamp, time.UnixMilli(timestamp).Format(time.RFC3339))
priority, err := b.Uint8()
require.NoError(t, err)
fmt.Printf(" priority = %d\n", priority)
lon, err := b.Int32()
require.NoError(t, err)
fmt.Printf(" lon = %d\n", lon)
lat, err := b.Int32()
require.NoError(t, err)
fmt.Printf(" lat = %d\n", lat)
alt, err := b.Int16()
require.NoError(t, err)
fmt.Printf(" alt = %d\n", alt)
angle, err := b.Int16()
require.NoError(t, err)
fmt.Printf(" angle = %d\n", angle)
sat, err := b.Uint8()
require.NoError(t, err)
fmt.Printf(" sat = %d\n", sat)
speed, err := b.Int16()
require.NoError(t, err)
fmt.Printf(" speed = %d\n", speed)
eventID, err := b.Uint16()
require.NoError(t, err)
fmt.Printf(" eventID = %d\n", eventID)
ioCount, err := b.Uint16()
require.NoError(t, err)
k := 0
for i := 1; i <= 8; i *= 2 {
n, err := b.Uint16()
require.NoError(t, err)
for j := 0; j < int(n); j++ {
id, err := b.Uint16()
require.NoError(t, err)
value, err := b.ReadBytes(i)
require.NoError(t, err)
if k >= int(ioCount) {
require.Fail(t, fmt.Errorf("too many i/o elements, expected at most %d, found %d", ioCount, k).Error())
}
fmt.Printf(" - ioelement id=%d = data=%s\n", id, hex.EncodeToString(value))
k++
}
}
ioCountNX, err := b.Uint16()
require.NoError(t, err)
fmt.Printf(" ioCountNX = %d\n", ioCountNX)
fmt.Printf(" k = %d\n", k)
for i := k; i < int(ioCountNX); i++ {
id, err := b.Uint16()
require.NoError(t, err)
length, err := b.Uint16()
require.NoError(t, err)
value, err := b.ReadBytes(int(length))
require.NoError(t, err)
if i >= int(ioCount) {
require.Fail(t, fmt.Errorf("too many i/o elements, expected at most %d, found %d", ioCount, i).Error())
}
fmt.Printf(" - ionx id=%d = data=%s\n", id, hex.EncodeToString(value))
}
}
numdata2, err := b.Uint8()
require.NoError(t, err)
fmt.Printf("numdata = %d\n", numdata2)
checksum, err := b.Uint32()
require.NoError(t, err)
fmt.Printf("checksum = %d\n", checksum)
remain := b.Remaining()
rest, err := b.ReadBytes(remain)
require.NoError(t, err)
fmt.Printf("REMAIN: %d\n", remain)
fmt.Printf("rest = %s\n", hex.EncodeToString(rest))
fmt.Println("--------------------------------------------------------------------")
// require.NoError(t, err)
n, pkt, err := teltonika.DecodeTCPFromSlice(packet)
fmt.Printf("err=%v\n", err)
fmt.Printf("n = %d\n", n)
fmt.Printf("pkt = %+v\n", pkt)
spew.Dump(packet)
} and the output it generated looks like this:
|
Hi @borud, thank you for the feedback! It seems we both made a mistake in the code :) "Number of Data 1" and "Number of Data 2" in your packet
I made a mistake in the 8E codec I/O elements decoding logic, specifically in the variable length I/O element read loop, I fixed the problem and now everything is working fine package main
import (
"encoding/hex"
"fmt"
"github.com/alim-zanibekov/teltonika"
"github.com/alim-zanibekov/teltonika/ioelements"
)
func main() {
packetHex := "00000000000003c68e04000001909d6417c801062c583a25ce28b9004f004530000000ef0011000500ef0000f0010015030" +
"0c800004501000a00b5000800b60004004234a90018000000430ef700440052001100900012fc4c0013fb77000f03e8000200f100005" +
"e89001000003f9a00000000000001909d606e5201062bc70c25ccd6d50096010032000000ef0011000500ef0100f00100150500c8000" +
"04501000a00b5000800b60005004237780018000000430ed500440000001100da0012fd0e0013f9ef000f03e8000200f100005e89001" +
"000003a6400000000000001909d4f2c5001062bc70c25ccd6d5009601002c000000ef0011000500ef0000f00100150500c8000045010" +
"00a00b5000800b60005004234b10018000000430f0300440041001100db0012fd0d0013f9e9000f0047000200f100005e89001000003" +
"a6400000000000001909d4e03d501062c0f5025cdd1170068008130004800f700030002013d0100f7050000000000000001010102580" +
"1dffe02f95d01c2fdc4f97001b1fde2f96f0193fdd2f97001a1fe01f95f0171fdfff95001b1fdf3f97e01a1fe01f95f0200fdd5f97d0" +
"1eefe12f95c01affe31f96d01d0fe33f9aa01cffe62f9a901b1fe43f9ba01a0fe51f99b0200fe05f99b01d0fe33f99b0170fe6ff99b0" +
"161fe6ff9ab0164fe22f9cd0192fe22f99d0183fe32f9cc0170fe6ff99b0142fe4ff99d0133fe6ef9bc0172fe30f99d01c2fe15f9cb0" +
"19ffe70f99a0182fe11f97e0183fdf2f99f0152fe2ff98e0163fe21f9ae0181fe2ff96e0152fe2ff98e0162fe30f98e0191fe11f97e0" +
"1c0fe12f97d019ffe20f94e0180fe2ff95e0192fde1f96001a1fdf1f95f01d1fdc4f96f01a2fdc2f95101bffdf0f9300182fde1f9610" +
"1d1fdb3f94101a1fdd0f93201c2fda3f95101b1fdd1f94101b1fdd1f94101effde3f94e01b0fdf1f94001c0fde1f94001c1fdd2f9500" +
"171fdeef92201b0fde1f94001a1fdc1f93201a0fdc0f9130171fdcff92301dffdb2f9120190fdfff9300191fde0f9410191fe00f95f0" +
"172fdd0f94201cffde1f92001bdfdeef8e201affdd0f91201c0fdc2f93101a1fdb1f93301bffde0f92101f1fd74f92301a1fd80f8f60" +
"1d1fd83f91401a0fdaff8f401a0fde0f92101affdc0f90301bffdd0f90201dffdb1f90201cefdbff8e301eefda2f8f3019ffdaef8c50" +
"1f0fd94f932019ffddff90201b0fe01f94f01ddfdfff90001bbfe4cf8ee01befe30f94d01cdfe1ff90f01cffdf2f94f019ffe1ff93f0" +
"1b1fdd2f9600191fe00f95f0184fdc3f9910192fe12f99d01a0fe10f95e0180fe4ff97c01a1fe31f98c01a0fe21f96e0193fdf2f98f0" +
"191fe21f98d0400006a96"
packet, _ := hex.DecodeString(packetHex)
_, decoded, err := teltonika.DecodeTCPFromSlice(packet)
if err != nil {
panic(err)
}
decoder := ioelements.DefaultDecoder()
elements := make([][]*ioelements.IOElement, len(decoded.Packet.Data))
for i, data := range decoded.Packet.Data {
elements[i] = make([]*ioelements.IOElement, len(data.Elements))
for j, element := range data.Elements {
elements[i][j], err = decoder.Decode("*", element.Id, element.Value)
if err != nil {
panic(err)
}
}
}
for i, items := range elements {
fmt.Printf("\nFrame #%d\n", i)
d := decoded.Packet.Data[i]
fmt.Printf(" timestamp: %v\n", d.TimestampMs)
fmt.Printf(" priority: %v\n", d.Priority)
fmt.Printf(" lng: %v\n", d.Lng)
fmt.Printf(" lat: %v\n", d.Lat)
fmt.Printf(" alt: %v\n", d.Altitude)
fmt.Printf(" angle: %v\n", d.Angle)
fmt.Printf(" speed: %v\n", d.Speed)
fmt.Printf(" satellites: %v\n", d.Satellites)
fmt.Printf(" I/O elements\n")
for _, element := range items {
fmt.Printf(" %s\n", element)
}
}
} Output
|
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
hi,
Thanks for a great library. I started using it and things seem to work pretty well. Today I came across a packet from an FMC880 that the device keeps trying to send to the server over and over again.
The packet is sent over TCP and this is the hex encoding of it (this is just a dump of the entire buffer, so the stuff at the end is just zeroes from the zeroed buffer):
00000000000003c68e04000001909d6417c801062c583a25ce28b9004f004530000000ef0011000500ef0000f00100150300c800004501000a00b5000800b60004004234a90018000000430ef700440052001100900012fc4c0013fb77000f03e8000200f100005e89001000003f9a00000000000001909d606e5201062bc70c25ccd6d50096010032000000ef0011000500ef0100f00100150500c800004501000a00b5000800b60005004237780018000000430ed500440000001100da0012fd0e0013f9ef000f03e8000200f100005e89001000003a6400000000000001909d4f2c5001062bc70c25ccd6d5009601002c000000ef0011000500ef0000f00100150500c800004501000a00b5000800b60005004234b10018000000430f0300440041001100db0012fd0d0013f9e9000f0047000200f100005e89001000003a6400000000000001909d4e03d501062c0f5025cdd1170068008130004800f700030002013d0100f70500000000000000010101025801dffe02f95d01c2fdc4f97001b1fde2f96f0193fdd2f97001a1fe01f95f0171fdfff95001b1fdf3f97e01a1fe01f95f0200fdd5f97d01eefe12f95c01affe31f96d01d0fe33f9aa01cffe62f9a901b1fe43f9ba01a0fe51f99b0200fe05f99b01d0fe33f99b0170fe6ff99b0161fe6ff9ab0164fe22f9cd0192fe22f99d0183fe32f9cc0170fe6ff99b0142fe4ff99d0133fe6ef9bc0172fe30f99d01c2fe15f9cb019ffe70f99a0182fe11f97e0183fdf2f99f0152fe2ff98e0163fe21f9ae0181fe2ff96e0152fe2ff98e0162fe30f98e0191fe11f97e01c0fe12f97d019ffe20f94e0180fe2ff95e0192fde1f96001a1fdf1f95f01d1fdc4f96f01a2fdc2f95101bffdf0f9300182fde1f96101d1fdb3f94101a1fdd0f93201c2fda3f95101b1fdd1f94101b1fdd1f94101effde3f94e01b0fdf1f94001c0fde1f94001c1fdd2f9500171fdeef92201b0fde1f94001a1fdc1f93201a0fdc0f9130171fdcff92301dffdb2f9120190fdfff9300191fde0f9410191fe00f95f0172fdd0f94201cffde1f92001bdfdeef8e201affdd0f91201c0fdc2f93101a1fdb1f93301bffde0f92101f1fd74f92301a1fd80f8f601d1fd83f91401a0fdaff8f401a0fde0f92101affdc0f90301bffdd0f90201dffdb1f90201cefdbff8e301eefda2f8f3019ffdaef8c501f0fd94f932019ffddff90201b0fe01f94f01ddfdfff90001bbfe4cf8ee01befe30f94d01cdfe1ff90f01cffdf2f94f019ffe1ff93f01b1fdd2f9600191fe00f95f0184fdc3f9910192fe12f99d01a0fe10f95e0180fe4ff97c01a1fe31f98c01a0fe21f96e0193fdf2f98f0191fe21f98d0400006a960000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
I wrote my own parser for the packet and IO elements and it seems to confirm that your code is correct. The packet looks corrupt since NumberOfData1 equals 4 and NumberOfData2 equals 1. And your
teltonika.DecodeTCPFromSlice
function returns the error'Number of Data 1' is not equal to 'Number of Data 2'. 4 != 1"
.I thought I'd give you a copy of the packet in case you see something that is off here. But I think both your code and mine parses it correctly and correctly concludes it is buggy. Right?
The text was updated successfully, but these errors were encountered: