mirror of
https://github.com/PX4/PX4-Autopilot.git
synced 2026-06-08 10:50:19 +08:00
FTP: Remove CRC32 from protocol.
Extra crc not needed because mavlink already has crc16.
This commit is contained in:
@@ -34,7 +34,6 @@
|
||||
/// @file mavlink_ftp.cpp
|
||||
/// @author px4dev, Don Gagne <don@thegagnes.com>
|
||||
|
||||
#include <crc32.h>
|
||||
#include <unistd.h>
|
||||
#include <stdio.h>
|
||||
#include <fcntl.h>
|
||||
@@ -161,13 +160,6 @@ MavlinkFTP::_process_request(Request *req)
|
||||
goto out;
|
||||
}
|
||||
|
||||
// check request CRC to make sure this is one of ours
|
||||
if (_payload_crc32(payload) != payload->crc32) {
|
||||
errorCode = kErrCrc;
|
||||
goto out;
|
||||
warnx("ftp: bad crc");
|
||||
}
|
||||
|
||||
#ifdef MAVLINK_FTP_DEBUG
|
||||
printf("ftp: channel %u opc %u size %u offset %u\n", req->serverChannel, payload->opcode, payload->size, payload->offset);
|
||||
#endif
|
||||
@@ -255,8 +247,9 @@ MavlinkFTP::_reply(Request *req)
|
||||
PayloadHeader *payload = reinterpret_cast<PayloadHeader *>(&req->message.payload[0]);
|
||||
|
||||
payload->seqNumber = payload->seqNumber + 1;
|
||||
|
||||
payload->crc32 = _payload_crc32(payload);
|
||||
payload->reserved[0] = 0;
|
||||
payload->reserved[1] = 0;
|
||||
payload->reserved[2] = 0;
|
||||
|
||||
mavlink_message_t msg;
|
||||
msg.checksum = 0;
|
||||
@@ -647,17 +640,3 @@ MavlinkFTP::_return_request(Request *req)
|
||||
_unlock_request_queue();
|
||||
}
|
||||
|
||||
/// @brief Returns the 32 bit CRC for the payload, crc32 and padding members are set to 0 for calculation.
|
||||
uint32_t
|
||||
MavlinkFTP::_payload_crc32(PayloadHeader *payload)
|
||||
{
|
||||
// We calculate CRC with crc and padding set to 0.
|
||||
uint32_t saveCRC = payload->crc32;
|
||||
payload->crc32 = 0;
|
||||
payload->padding[0] = 0;
|
||||
payload->padding[1] = 0;
|
||||
uint32_t retCRC = crc32((const uint8_t*)payload, payload->size + sizeof(PayloadHeader));
|
||||
payload->crc32 = saveCRC;
|
||||
|
||||
return retCRC;
|
||||
}
|
||||
|
||||
@@ -77,8 +77,7 @@ public:
|
||||
uint8_t opcode; ///< Command opcode
|
||||
uint8_t size; ///< Size of data
|
||||
uint8_t req_opcode; ///< Request opcode returned in kRspAck, kRspNak message
|
||||
uint8_t padding[2]; ///< 32 bit aligment padding
|
||||
uint32_t crc32; ///< CRC for entire Request structure, with crc32 and padding set to 0
|
||||
uint16_t reserved[3]; ///< reserved area
|
||||
uint32_t offset; ///< Offsets for List and Read commands
|
||||
uint8_t data[]; ///< command data, varies by Opcode
|
||||
};
|
||||
@@ -112,8 +111,7 @@ public:
|
||||
kErrInvalidSession, ///< Session is not currently open
|
||||
kErrNoSessionsAvailable, ///< All available Sessions in use
|
||||
kErrEOF, ///< Offset past end of file for List and Read commands
|
||||
kErrUnknownCommand, ///< Unknown command opcode
|
||||
kErrCrc ///< CRC on Payload is incorrect
|
||||
kErrUnknownCommand ///< Unknown command opcode
|
||||
};
|
||||
|
||||
private:
|
||||
@@ -135,8 +133,6 @@ private:
|
||||
void _lock_request_queue(void);
|
||||
void _unlock_request_queue(void);
|
||||
|
||||
uint32_t _payload_crc32(PayloadHeader *hdr);
|
||||
|
||||
char *_data_as_cstring(PayloadHeader* payload);
|
||||
|
||||
static void _worker_trampoline(void *arg);
|
||||
|
||||
Reference in New Issue
Block a user