Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion hal/network/ncp/cellular/cellular_ncp_client.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,14 @@ namespace particle {

#if PLATFORM_ID != PLATFORM_GCC

const size_t MAX_APDU_SIZE = 261; // 4 (header) + 1 (Lc) + 255 (data) + 1 (Le)
const size_t MAX_APDU_COMMAND_SIZE = 261; // 4 (header) + 1 (Lc) + 255 (data) + 1 (Le)
const size_t MAX_APDU_RESPONSE_SIZE = 258; // 256 (data) + 2 (status)

// XXX: Set to a higher value than MAX_APDU_COMMAND_SIZE or MAX_APDU_RESPONSE_SIZE to work around
// EG916Q incorrectly returning too large responses
const size_t APDU_BUFFER_SIZE = 400;

static_assert(APDU_BUFFER_SIZE >= MAX_APDU_COMMAND_SIZE && APDU_BUFFER_SIZE >= MAX_APDU_RESPONSE_SIZE);

struct CellularNcpEvent: NcpEvent {
enum Type {
Expand Down
4 changes: 2 additions & 2 deletions hal/network/ncp_client/quectel/quectel_ncp_client.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2131,7 +2131,7 @@ int QuectelNcpClient::startNcpFwUpdate(bool update) {
}

int QuectelNcpClient::sendApdu(const char* cmdBuf, size_t cmdSize, char* respBuf, size_t& respSize, bool autoClose) {
if (cmdSize > MAX_APDU_SIZE) {
if (cmdSize > MAX_APDU_COMMAND_SIZE) {
return SYSTEM_ERROR_INVALID_ARGUMENT;
}

Expand Down Expand Up @@ -2170,7 +2170,7 @@ int QuectelNcpClient::sendApdu(const char* cmdBuf, size_t cmdSize, char* respBuf
auto cmd = parser_.command();
cmd.printf("AT+CSIM=%d,\"", (int)(cmdSize * 2));

char strBuf[MAX_APDU_SIZE * 2 + 50]; // Add some room for AT command framing
char strBuf[APDU_BUFFER_SIZE * 2 + 20]; // Add some room for AT command framing
toHex(cmdBuf, cmdSize, strBuf, sizeof(strBuf));
cmd.print(strBuf);
cmd.print("\"");
Expand Down
4 changes: 2 additions & 2 deletions system/src/control/cellular.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ int sendApdu(ctrl_request* req) {
CHECK(client->on());

struct Context {
char apdu[MAX_APDU_SIZE];
char apdu[APDU_BUFFER_SIZE];
size_t apduSize;
int error;
};
Expand All @@ -149,7 +149,7 @@ int sendApdu(ctrl_request* req) {
pbReq.data.funcs.decode = [](pb_istream_t* stream, const pb_field_iter_t* /* field */, void** arg) {
auto ctx = (Context*)*arg;
ctx->apduSize = stream->bytes_left;
if (ctx->apduSize > MAX_APDU_SIZE) {
if (ctx->apduSize > MAX_APDU_COMMAND_SIZE) {
ctx->error = SYSTEM_ERROR_TOO_LARGE;
return false;
}
Expand Down