int
imgr_file_download(struct nmgr_jbuf *njb)
{
    long long unsigned int off = UINT_MAX;
    char tmp_str[IMGMGR_NMGR_MAX_NAME + 1];
    char img_data[BASE64_ENCODE_SIZE(IMGMGR_NMGR_MAX_MSG)];
    const struct json_attr_t dload_attr[3] = {
        [0] = {
            .attribute = "off",
            .type = t_uinteger,
            .addr.uinteger = &off
        },
Beispiel #2
0
static int
imgr_upload(struct nmgr_jbuf *njb)
{
    char img_data[BASE64_ENCODE_SIZE(IMGMGR_NMGR_MAX_MSG)];
    unsigned int off = UINT_MAX;
    unsigned int size = UINT_MAX;
    const struct json_attr_t off_attr[4] = {
        [0] = {
            .attribute = "off",
            .type = t_uinteger,
            .addr.uinteger = &off,
            .nodefault = true
        },
int
imgr_core_load(struct nmgr_jbuf *njb)
{
    unsigned long long off = UINT_MAX;
    const struct json_attr_t dload_attr[2] = {
        [0] = {
            .attribute = "off",
            .type = t_uinteger,
            .addr.uinteger = &off
        }
    };
    int rc;
    int sz;
    const struct flash_area *fa;
    char data[IMGMGR_NMGR_MAX_MSG];
    char encoded[BASE64_ENCODE_SIZE(IMGMGR_NMGR_MAX_MSG)];
    struct coredump_header *hdr;
    struct json_encoder *enc;
    struct json_value jv;

    hdr = (struct coredump_header *)data;

    rc = json_read_object(&njb->njb_buf, dload_attr);
    if (rc || off == UINT_MAX) {
        rc = NMGR_ERR_EINVAL;
        goto err;
    }

    rc = flash_area_open(FLASH_AREA_CORE, &fa);
    if (rc) {
        rc = NMGR_ERR_EINVAL;
Beispiel #4
0
#define STAMP_STR(s) STAMP_STR1(s)
#define STAMP_STR1(str) #str

#ifdef BSP_NAME
static const char *bsp_str = STAMP_STR(BSP_NAME);
static const char *app_str = STAMP_STR(APP_NAME);
#else
static const char *bsp_str = "";
static const char *app_str = "";
#endif

static char serial[ID_SERIAL_MAX_LEN];

/** Base64-encoded null-terminated manufacturing hash. */
static char id_mfghash[BASE64_ENCODE_SIZE(MFG_HASH_SZ) + 1];

struct conf_handler id_conf = {
    .ch_name = "id",
    .ch_get = id_conf_get,
    .ch_set = id_conf_set,
    .ch_export = id_conf_export
};

static char *
id_conf_get(int argc, char **argv, char *val, int val_len_max)
{
    uint8_t src_buf[HAL_BSP_MAX_ID_LEN];
    int len;

    if (argc == 1) {
/*
 * Called by mgmt to queue packet out to UART.
 */
static int
nmgr_uart_out(struct nmgr_transport *nt, struct os_mbuf *m)
{
    struct nmgr_uart_state *nus = (struct nmgr_uart_state *)nt;
    struct os_mbuf_pkthdr *mpkt;
    struct os_mbuf *n;
    char tmp_buf[12];
    uint16_t crc;
    char *dst;
    int off;
    int boff;
    int slen;
    int sr;
    int rc;
    int last;
    int tx_sz;

    assert(OS_MBUF_IS_PKTHDR(m));
    mpkt = OS_MBUF_PKTHDR(m);

    off = 0;
    crc = CRC16_INITIAL_CRC;
    for (n = m; n; n = SLIST_NEXT(n, om_next)) {
        crc = crc16_ccitt(crc, n->om_data, n->om_len);
    }
    crc = htons(crc);
    dst = os_mbuf_extend(m, sizeof(crc));
    if (!dst) {
        goto err;
    }
    memcpy(dst, &crc, sizeof(crc));

    n = os_msys_get(SHELL_NLIP_MAX_FRAME, 0);
    if (!n || OS_MBUF_TRAILINGSPACE(n) < 32) {
        goto err;
    }

    while (off < mpkt->omp_len) {
        tx_sz = 2;
        dst = os_mbuf_extend(n, 2);
        if (off == 0) {
            *(uint16_t *)dst = htons(SHELL_NLIP_PKT);
            *(uint16_t *)tmp_buf = htons(mpkt->omp_len);
            boff = 2;
        } else {
            *(uint16_t *)dst = htons(SHELL_NLIP_DATA);
            boff = 0;
        }

        while (off < mpkt->omp_len) {
            slen = mpkt->omp_len - off;
            last = 1;
            if (slen > sizeof(tmp_buf) + boff) {
                slen = sizeof(tmp_buf) - boff;
                last = 0;
            }
            if (tx_sz + BASE64_ENCODE_SIZE(slen + boff) >= 124) {
                break;
            }
            rc = os_mbuf_copydata(m, off, slen, tmp_buf + boff);
            assert(rc == 0);

            off += slen;
            slen += boff;

            dst = os_mbuf_extend(n, BASE64_ENCODE_SIZE(slen));
            if (!dst) {
                goto err;
            }
            tx_sz += base64_encode(tmp_buf, slen, dst, last);
            boff = 0;
        }

        if (os_mbuf_append(n, "\n", 1)) {
            goto err;
        }
    }

    os_mbuf_free_chain(m);
    OS_ENTER_CRITICAL(sr);
    if (!nus->nus_tx) {
        nus->nus_tx = n;
        uart_start_tx(nus->nus_dev);
    } else {
        os_mbuf_concat(nus->nus_tx, n);
    }
    OS_EXIT_CRITICAL(sr);

    return 0;
err:
    os_mbuf_free_chain(m);
    os_mbuf_free_chain(n);
    return -1;
}