Skip to content
This repository was archived by the owner on Apr 13, 2021. It is now read-only.

Update to new file_io messages #452

Merged
merged 5 commits into from
Jul 6, 2015
Merged

Conversation

mfine
Copy link
Contributor

@mfine mfine commented Jun 24, 2015

Update sbp and move to new file_io messages. See swift-nav/libsbp#183.

/cc @fnoble @denniszollo @mookerji

@swiftnav-jenkins
Copy link

Test PASSed.
Refer to this link for build results (access rights to CI server needed):
http://zazu.ci.swiftnav.com/job/piksi_firmware_Pull_Requests/396/
Test PASSed.

@@ -81,16 +81,16 @@ static void read_cb(u16 sender_id, u8 len, u8 msg[], void* context)
len += cfs_read(f, buf + len, readlen);
cfs_close(f);

sbp_send_msg(SBP_MSG_FILEIO_READ, len, buf);
sbp_send_msg(SBP_MSG_FILEIO_READ_RESPONSE, len, buf);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

above here (line 77), we need a check that len + readlen < 256, otherwise the you could easily overrun buffer[256]. I don't think we can trust the sender of the message took into account that readlen needs to be correct.

I had the check:
if (len + readlen > 256) {
log_error("Error in read_cb, requested length too long. Length was %d, filename is %s", readlen, &msg[5]);
}

When I was working on it

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

len is an 8-bit value, so you can't overrun the buffer - it'll just wrap. If you try and in a check for this, the compiler is warning:

sbp_fileio.c:86:3: error: comparison is always false due to limited range of data type

@mfine
Copy link
Contributor Author

mfine commented Jun 24, 2015

Something else to consider is whether we also want to do sender_id checks to ensure these messages are not coming from other piksi's:

  if (sender_id != 0x42)
    return;

@cbeighley
Copy link
Member

If we are changing the IDs so there's no ambiguity as to whether a particular message is a Request or a Response, is the sender_id check necessary?

@mfine
Copy link
Contributor Author

mfine commented Jun 24, 2015

Shouldn't be - just extra protection

extra protection

@cbeighley
Copy link
Member

Sounds good - I'm all about it.

@fnoble
Copy link
Contributor

fnoble commented Jun 24, 2015

Would Piksis ever want to program each other or read each other's files? Probably not but worth considering...

@cbeighley
Copy link
Member

Dennis suggested a general purpose wrapper message that could contain another message within itself. The wrapper message could also have flags for what was to be done with the wrapped message (forwarded, consumed, etc).

@mookerji
Copy link
Contributor

Not sure we want Piksi's playing with each other that way. We don't have quite the right protection in place,...

@denniszollo
Copy link
Contributor

The nice thing about the wrapper message is that the complexity of forwarded messages goes away in the protocol.

@cbeighley
Copy link
Member

image

Here's my pecker.

@mookerji
Copy link
Contributor

I think the Piksi's should cough cough abstain from sending each other any such file messages, wrapped in anything, much less brown paper packet frames (tied up in streams). Would you want to unwrap forwarded messages from strange units?

@mfine
Copy link
Contributor Author

mfine commented Jun 24, 2015

I don't think we have any demonstrated need for encapsulation or piksi-to-piksi file_io, flash, or settings operations. If there's a well-defined specification and application for encapsulation, we could approach the idea then; otherwise, seems premature. For going out in 1.0, seems like a good idea to lock these things down a little and remove inadvertent updates.

@mfine
Copy link
Contributor Author

mfine commented Jun 24, 2015

Added the sender_id checks.

@swiftnav-jenkins
Copy link

Test PASSed.
Refer to this link for build results (access rights to CI server needed):
http://zazu.ci.swiftnav.com/job/piksi_firmware_Pull_Requests/400/
Test PASSed.

@@ -81,25 +83,27 @@ static void read_cb(u16 sender_id, u8 len, u8 msg[], void* context)
len += cfs_read(f, buf + len, readlen);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's say the original message is 16 bits long as sent (len=16). Lets say the readlen field of the message is its max value (256). the cfs_read operation just overran buf.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, the u8 len + the u8 readlen in the call to cfs_read could overwrite buf 256 bytes. Added MIN(readlen, 255-len) to determine how much to read into the buffer. Thanks!

@swiftnav-jenkins
Copy link

Test PASSed.
Refer to this link for build results (access rights to CI server needed):
http://zazu.ci.swiftnav.com/job/piksi_firmware_Pull_Requests/402/
Test PASSed.

(void)context;

if (sender_id != 0x42)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I may have missed this earlier, but sender ID 42 is used by those host computer writing to the flash? This would useful to have defined in a constant (and comment) somewhere in the header.

@mfine
Copy link
Contributor Author

mfine commented Jul 6, 2015

@henryhallam @gsmcmullin minor changes here around the file io messaging paths - could use a brief review.

@mfine
Copy link
Contributor Author

mfine commented Jul 6, 2015

Rebased.

@swiftnav-jenkins
Copy link

Test PASSed.
Refer to this link for build results (access rights to CI server needed):
http://zazu.ci.swiftnav.com/job/piksi_firmware_Pull_Requests/475/
Test PASSed.

@swiftnav-jenkins
Copy link

Test PASSed.
Refer to this link for build results (access rights to CI server needed):
http://zazu.ci.swiftnav.com/job/piksi_firmware_Pull_Requests/476/
Test PASSed.

@mfine
Copy link
Contributor Author

mfine commented Jul 6, 2015

Bringing this in.

mfine added a commit that referenced this pull request Jul 6, 2015
Update to new file_io messages
@mfine mfine merged commit 0002c0b into swift-nav:master Jul 6, 2015
@mfine mfine deleted the mfine-file-io branch July 6, 2015 20:47
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants