Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependents: modem_ref_helper_for_v5_3_217
Diff: src/modem_ref.cpp
- Revision:
- 41:6f83174ffed4
- Parent:
- 39:bc4fccf2d84b
- Child:
- 44:656cbcc7843b
- Child:
- 48:37bf104b3a39
diff -r 62b7f6d25772 -r 6f83174ffed4 src/modem_ref.cpp
--- a/src/modem_ref.cpp Fri Oct 12 12:37:16 2018 +0000
+++ b/src/modem_ref.cpp Mon Nov 26 16:42:16 2018 +0000
@@ -3,6 +3,7 @@
#include "modem_ref.h"
#include "kal_crypto.h"
+#include "kal_codec.h"
#if 0
#define REF_PRINT(...) PRINT(__VA_ARGS__)
@@ -31,6 +32,7 @@
modem_istatus_t istatus;
u8 state;
u8 tx_sequ;
+ s32 action;
} modem_ctx_t;
static modem_ctx_t g_modem;
@@ -75,7 +77,10 @@
s8 err = ALP_ERR_NONE;
u8 eop;
uint32_t parsed;
- REF_PRINT("input 0x%x/%d Bytes\n",flowid,size);
+
+ g_modem.action = -1;
+
+ //REF_PRINT("input 0x%x/%d Bytes\n",flowid,size);
switch (flowid)
{
case WC_FLOW_ALP_UNS:
@@ -84,15 +89,19 @@
if (!parsed)
{
// Discard the payload in case of parsing error.
- REF_PRINT("Parsing error in %s:%d!\r\n", __FILE__, __LINE__);
+ REF_PRINT("Parsing error line %d!\r\n", __LINE__);
break;
}
rem -= parsed;
- REF_PRINT("Rem %d Bytes\n", rem);
+ g_modem.action++;
+ //REF_PRINT("Rem %d Bytes\n", rem);
// This should always be a TAG'ed request in case of FS access...
if (r.type == ALP_OPCODE_TAG)
{
+ REF_PRINT("ACT %d: TAG[%d]\n", g_modem.action, r.meta.tag.id);
+
id = r.meta.tag.id;
+
while(rem>0)
{
// Parse File Operation
@@ -100,45 +109,51 @@
if (!parsed)
{
// Discard the payload in case of parsing error.
- REF_PRINT("Parsing error in %s:%d!\r\n", __FILE__, __LINE__);
+ REF_PRINT("Parsing error line %d!\r\n", __LINE__);
break;
}
rem -= parsed;
+ g_modem.action++;
//REF_PRINT("ALP OP[%d]\n",r.type);
switch (r.type)
{
case ALP_OPCODE_F_RD_DATA:
+ REF_PRINT("ACT %d: F_RD_DATA[%d] @%d %d bytes\n", g_modem.action, r.meta.f_data.fid, r.meta.f_data.offset, r.meta.f_data.length);
if (g_modem.cb->read)
{
- g_modem.cb->read(r.meta.f_data.fid,r.meta.f_data.offset,r.meta.f_data.length,id);
+ g_modem.cb->read(r.meta.f_data.fid, r.meta.f_data.offset, r.meta.f_data.length, id);
}
break;
case ALP_OPCODE_F_WR_DATA:
+ REF_PRINT("ACT %d: F_WR_DATA[%d] @%d %d bytes\n", g_modem.action, r.meta.f_data.fid, r.meta.f_data.offset, r.meta.f_data.length);
if (g_modem.cb->write)
{
- g_modem.cb->write(r.meta.f_data.fid,r.data,r.meta.f_data.offset,r.meta.f_data.length,id);
+ g_modem.cb->write(r.meta.f_data.fid, r.data, r.meta.f_data.offset, r.meta.f_data.length, id);
}
break;
case ALP_OPCODE_F_RD_PROP:
+ REF_PRINT("ACT %d: F_RD_PROP[%d]\n", g_modem.action, r.meta.f_data.fid);
if (g_modem.cb->read_fprop)
{
- g_modem.cb->read_fprop(r.meta.f_data.fid,id);
+ g_modem.cb->read_fprop(r.meta.f_data.fid, id);
}
break;
case ALP_OPCODE_F_DELETE:
+ REF_PRINT("ACT %d: F_DELETE[%d]\n", g_modem.action, r.meta.f_data.fid);
if (g_modem.cb->remove)
{
- g_modem.cb->remove(r.meta.f_data.fid,id);
+ g_modem.cb->remove(r.meta.f_data.fid, id);
}
break;
case ALP_OPCODE_F_FLUSH:
+ REF_PRINT("ACT %d: F_FLUSH[%d]\n", g_modem.action, r.meta.f_data.fid);
if (g_modem.cb->flush)
{
- g_modem.cb->flush(r.meta.f_data.fid,id);
+ g_modem.cb->flush(r.meta.f_data.fid, id);
}
break;
default:
- ASSERT(false,"ASSERT: Unsupported ALP File Operation: %d\n",r.type);
+ ASSERT(false,"ASSERT: Unsupported ALP File Operation: %d\n", r.type);
break;
}
//REF_PRINT("ALP Parsing done. rem %d\n", rem);
@@ -155,13 +170,41 @@
{
case ALP_OPCODE_RSP_URC:
if (ALP_URC_TYPE_LQUAL == r.meta.urc.type)
- g_modem.cb->lqual(r.meta.urc.ifid,r.meta.urc.per);
+ {
+ REF_PRINT("ACT %d: RSP_URC: LQUAL[%d] %d\n", g_modem.action, r.meta.urc.ifid, r.meta.urc.per);
+ if (g_modem.cb->lqual)
+ {
+ g_modem.cb->lqual(r.meta.urc.ifid, r.meta.urc.per);
+ }
+ }
else if (ALP_URC_TYPE_LDOWN == r.meta.urc.type)
- g_modem.cb->ldown(r.meta.urc.ifid);
+ {
+ REF_PRINT("ACT %d: RSP_URC: LDOWN[%d]\n", g_modem.action, r.meta.urc.ifid);
+ if (g_modem.cb->ldown)
+ {
+ g_modem.cb->ldown(r.meta.urc.ifid);
+ }
+ }
else if (ALP_URC_TYPE_BUSY == r.meta.urc.type)
- g_modem.cb->busy(r.meta.urc.ifid);
+ {
+ REF_PRINT("ACT %d: RSP_URC: BUSY[%d]\n", g_modem.action, r.meta.urc.ifid);
+ if (g_modem.cb->busy)
+ {
+ g_modem.cb->busy(r.meta.urc.ifid);
+ }
+ }
+ else if (ALP_URC_TYPE_ITF_BUSY == r.meta.urc.type)
+ {
+ REF_PRINT("ACT %d: RSP_URC: ITF_BUSY[%d] for %d seconds\n", g_modem.action, r.meta.urc.ifid, r.meta.urc.per);
+ if (g_modem.cb->itf_busy)
+ {
+ g_modem.cb->itf_busy(r.meta.urc.ifid, r.meta.urc.per);
+ }
+ }
else
- ASSERT(false,"ASSERT: Unsupported ALP URC: %d\n",r.meta.urc.type);
+ {
+ ASSERT(false, "ASSERT: Unsupported ALP URC: %d\n", r.meta.urc.type);
+ }
break;
default:
// This could be anything
@@ -189,13 +232,15 @@
if (!parsed)
{
// Discard the payload in case of parsing error.
- REF_PRINT("Parsing error in %s:%d!\r\n", __FILE__, __LINE__);
+ REF_PRINT("Parsing error line %d!\r\n", __LINE__);
break;
}
rem -= parsed;
- REF_PRINT("Rem %d Bytes\n", rem);
+ g_modem.action++;
+ //REF_PRINT("Rem %d Bytes\n", rem);
ASSERT((r.type == ALP_OPCODE_RSP_TAG),"ASSERT: expecting RESP_TAG got %d\n",r.type);
+ REF_PRINT("ACT %d: TAG[%d]\n", g_modem.action, r.meta.tag.id);
id = r.meta.tag.id;
eop = r.meta.tag.eop;
ASSERT(g_modem.user[id].cb != NULL,"ASSERT: NULL Callback for ID %d\n",id);
@@ -203,8 +248,17 @@
if (rem <= 0)
{
// TODO: still no info on error...
- REF_PRINT("ERROR\n");
err = r.meta.tag.err ? ALP_ERR_UNKNOWN : ALP_ERR_NONE;
+
+ if (ALP_ERR_NONE != err)
+ {
+ REF_PRINT("NO INFO ON ERROR.\n");
+ }
+ else if (eop)
+ {
+ REF_PRINT("EOP.\n");
+ }
+
g_modem.user[id].cb(eop,err,id);
return;
}
@@ -216,38 +270,39 @@
if (!parsed)
{
// Discard the payload in case of parsing error.
- REF_PRINT("Parsing error in %s:%d!\r\n", __FILE__, __LINE__);
+ REF_PRINT("Parsing error line %d!\r\n", __LINE__);
break;
}
rem -= parsed;
- REF_PRINT("Rem %d Bytes\n", rem);
+ g_modem.action++;
+ //REF_PRINT("Rem %d Bytes\n", rem);
switch (r.type)
{
case ALP_OPCODE_RSP_TAG:
- REF_PRINT("RSP_TAG[%d]\n", r.meta.tag.id);
+ REF_PRINT("ACT %d: RSP_TAG[%d]\n", g_modem.action, r.meta.tag.id);
break;
case ALP_OPCODE_RSP_F_DATA:
- REF_PRINT("RSP_F_DATA[%d]\n", r.meta.f_data.length);
+ REF_PRINT("ACT %d: RSP_F_DATA[%d]\n", g_modem.action, r.meta.f_data.length);
ASSERT(g_modem.user[id].data != NULL,"ASSERT: NULL Data Buffer for RD on ID %d\n",id);
- memcpy(g_modem.user[id].data,r.data,r.meta.f_data.length);
+ memcpy(g_modem.user[id].data, r.data, r.meta.f_data.length);
break;
case ALP_OPCODE_RSP_F_PROP:
- REF_PRINT("RSP_F_PROP[%d]\n", r.meta.f_data.length);
+ REF_PRINT("ACT %d: RSP_F_PROP[%d]\n", g_modem.action, r.meta.f_data.length);
ASSERT(g_modem.user[id].data != NULL,"ASSERT: NULL Data Buffer for RD on ID %d\n",id);
- memcpy(g_modem.user[id].data,r.data,r.meta.f_data.length);
+ memcpy(g_modem.user[id].data, r.data, r.meta.f_data.length);
break;
case ALP_OPCODE_RSP_STATUS:
- REF_PRINT("RSP_STATUS[%d]\n", r.meta.status.code);
+ REF_PRINT("ACT %d: RSP_STATUS[%d]\n", g_modem.action, r.meta.status.code);
err = r.meta.status.code;
break;
case ALP_OPCODE_RSP_ISTATUS:
- REF_PRINT("RSP_ISTATUS[%d]\n", r.meta.itf.length);
+ REF_PRINT("ACT %d: RSP_ISTATUS[%d]\n", g_modem.action, r.meta.itf.length);
ASSERT(g_modem.user[id].istatus != NULL,"ASSERT: NULL ISTAT Buffer for RD on ID %d\n",id);
- memcpy(g_modem.user[id].istatus,r.data,r.meta.itf.length);
+ memcpy(g_modem.user[id].istatus, r.data, r.meta.itf.length);
break;
case ALP_OPCODE_RSP_EOPISTATUS:
- REF_PRINT("RSP_EOPISTATUS[%02X]\n", r.meta.istatus.itf);
+ REF_PRINT("ACT %d: RSP_EOPISTATUS[%02X]\n", g_modem.action, r.meta.istatus.itf);
err = r.meta.istatus.err ? ALP_ERR_ITF_START + r.meta.istatus.err : ALP_ERR_NONE;
break;
default:
@@ -544,6 +599,24 @@
SERIAL_SEND(WC_FLOW_ALP_UNS,tmp, (u8)(p-tmp));
}
+public void modem_delete_file_root(u8 fid, u8* root_key, u8 id)
+{
+ u8 tmp[ALP_ACTION_TAG_SIZE + ALP_ACTION_PERM_REQ_SIZE(ALP_ACTION_F_DELETE_SIZE)];
+ u8* p = tmp;
+ u8* lastp;
+
+ REF_PRINT("DELETE ROOT[%d]\n",fid);
+ ALP_ACTION_TAG(p,id,true);
+ // Actual Operation will take place after PERM_REQ
+ p = &tmp[ALP_ACTION_TAG_SIZE + ALP_ACTION_PERM_REQ_OFFSET];
+ ALP_ACTION_F_DELETE(p,true,fid);
+ lastp = p;
+ modem_add_root_permission(&tmp[ALP_ACTION_TAG_SIZE], root_key,
+ &tmp[ALP_ACTION_TAG_SIZE + ALP_ACTION_PERM_REQ_OFFSET],
+ ALP_ACTION_F_DELETE_SIZE);
+ SERIAL_SEND(WC_FLOW_ALP_UNS,tmp, (u8)(lastp-tmp));
+}
+
public void modem_send_raw_alp(u8* payload, u32 length, u8 id)
{
ALLOC_BUFFER(u8,tmp,ALP_ACTION_TAG_SIZE + length);
@@ -635,14 +708,14 @@
SERIAL_SEND(WC_FLOW_ALP_UNS,tmp, (u8)(p-tmp));
}
-public void modem_respond(u8 action, s8 status, int id)
+public void modem_respond(s8 status, int id)
{
u8 tmp[ALP_ACTION_RSP_TAG_SIZE + ALP_ACTION_RSP_STATUS_SIZE];
u8* p = tmp;
- REF_PRINT("RESP[%d]:%d\n",action,status);
+ REF_PRINT("RESP[%d]:%d\n",g_modem.action,status);
if (id>=0) { ALP_ACTION_RSP_TAG(p,id,true,(status<0)?true:false); }
- ALP_ACTION_RSP_STATUS(p,action,status);
+ ALP_ACTION_RSP_STATUS(p, g_modem.action, status);
SERIAL_SEND(WC_FLOW_ALP_RESP,tmp, (u8)(p-tmp));
}