示例#1
0
void t_parse_pdu4(void)
{
    /* illegal token length */
    char teststr[] =
    { 0x59, 0x69, 0x12, 0x34, 't', 'o', 'k', 'e', 'n', '1', '2', '3', '4' };
    int result;

    result = coap_pdu_parse((unsigned char *) teststr, sizeof(teststr), pdu);
    CU_ASSERT(result == 0);

    teststr[0] = 0x5f;

    result = coap_pdu_parse((unsigned char *) teststr, sizeof(teststr), pdu);
    CU_ASSERT(result == 0);
}
coap_pdu_t* CAParsePDU(const char* data, uint32_t* outCode)
{
    coap_pdu_t* outpdu = coap_new_pdu();
    coap_pdu_parse((unsigned char *) data, strlen(data), outpdu);
    (*outCode) = (uint32_t) outpdu->hdr->code;

    return outpdu;
}
示例#3
0
void t_parse_pdu3(void)
{
    char teststr[] =
    { 0x53, 0x69, 0x12, 0x34, 't', 'o', 'k', 'e', 'n' };
    int result;

    result = coap_pdu_parse((unsigned char *) teststr, sizeof(teststr), pdu);
    CU_ASSERT(result == 0);
}
示例#4
0
void t_parse_pdu14(void)
{
    /* ACK with content */
    char teststr[] =
    { 0x60, 0x00, 0x12, 0x34, 0xff, 'c', 'o', 'n', 't', 'e', 'n', 't' };
    int result;

    result = coap_pdu_parse((unsigned char *) teststr, sizeof(teststr), pdu);
    CU_ASSERT(result == 0);
}
示例#5
0
void t_parse_pdu10(void)
{
    /* PDU without payload but with options and payload start marker */
    char teststr[] =
    { 0x53, 0x73, 0x12, 0x34, 't', 'o', 'k', 0x30, 0xc1, 0x00, 0xff };
    int result;

    result = coap_pdu_parse((unsigned char *) teststr, sizeof(teststr), pdu);
    CU_ASSERT(result == 0);
}
示例#6
0
void t_parse_pdu6(void)
{
    /* PDU with options that exceed the PDU */
    char teststr[] =
    { 0x55, 0x73, 0x12, 0x34, 't', 'o', 'k', 'e', 'n', 0x00, 0xc1, 0x00, 0xae, 0xf0, 0x03 };
    int result;

    result = coap_pdu_parse((unsigned char *) teststr, sizeof(teststr), pdu);
    CU_ASSERT(result == 0);
}
coap_pdu_t *CAParsePDU(const char *data, uint32_t length, uint32_t *outCode)
{
    OIC_LOG(DEBUG, TAG, "IN");

    if (NULL == data)
    {
        OIC_LOG(ERROR, TAG, "data is null");
        return NULL;
    }

    coap_pdu_t *outpdu = coap_new_pdu();
    if (NULL == outpdu)
    {
        OIC_LOG(ERROR, TAG, "outpdu is null");
        return NULL;
    }

    if (0 >= coap_pdu_parse((unsigned char *) data, length, outpdu))
    {
        OIC_LOG(ERROR, TAG, "pdu parse failed");
        coap_delete_pdu(outpdu);
        return NULL;
    }

    if (outpdu->hdr->version != COAP_DEFAULT_VERSION)
    {
        OIC_LOG_V(ERROR, TAG, "coap version is not available : %d",
                  outpdu->hdr->version);
        coap_delete_pdu(outpdu);
        return NULL;
    }

    if (outpdu->hdr->token_length > CA_MAX_TOKEN_LEN)
    {
        OIC_LOG_V(ERROR, TAG, "token length has been exceed : %d",
                  outpdu->hdr->token_length);
        coap_delete_pdu(outpdu);
        return NULL;
    }

    if (outCode)
    {
        (*outCode) = (uint32_t) CA_RESPONSE_CODE(outpdu->hdr->code);
    }

    OIC_LOG(DEBUG, TAG, "OUT");
    return outpdu;
}
示例#8
0
void t_parse_pdu11(void)
{
    char teststr[] =
    { 0x60, 0x00, 0x12, 0x34 };
    int result;

    result = coap_pdu_parse((unsigned char *) teststr, sizeof(teststr), pdu);
    CU_ASSERT(result > 0);

    CU_ASSERT(pdu->length == sizeof(teststr));
    CU_ASSERT(pdu->hdr->version == 1);
    CU_ASSERT(pdu->hdr->type == COAP_MESSAGE_ACK);
    CU_ASSERT(pdu->hdr->token_length == 0);
    CU_ASSERT(pdu->hdr->code == 0);
    CU_ASSERT(memcmp(&pdu->hdr->id, teststr + 2, 2) == 0);
}
示例#9
0
void t_parse_pdu1(void)
{
    char teststr[] =
    { 0x40, 0x01, 0x93, 0x34 };
    int result;

    result = coap_pdu_parse((unsigned char *) teststr, sizeof(teststr), pdu);
    CU_ASSERT(result > 0);

    CU_ASSERT(pdu->length == sizeof(teststr));
    CU_ASSERT(pdu->hdr->version == 1);
    CU_ASSERT(pdu->hdr->type == COAP_MESSAGE_CON);
    CU_ASSERT(pdu->hdr->token_length == 0);
    CU_ASSERT(pdu->hdr->code == COAP_REQUEST_GET);
    CU_ASSERT(memcmp(&pdu->hdr->id, teststr + 2, 2) == 0);
    CU_ASSERT_PTR_NULL(pdu->data);
}
示例#10
0
void t_parse_pdu2(void)
{
    char teststr[] =
    { 0x55, 0x69, 0x12, 0x34, 't', 'o', 'k', 'e', 'n' };
    int result;

    result = coap_pdu_parse((unsigned char *) teststr, sizeof(teststr), pdu);
    CU_ASSERT(result > 0);

    CU_ASSERT(pdu->length == sizeof(teststr));
    CU_ASSERT(pdu->hdr->version == 1);
    CU_ASSERT(pdu->hdr->type == COAP_MESSAGE_NON);
    CU_ASSERT(pdu->hdr->token_length == 5);
    CU_ASSERT(pdu->hdr->code == 0x69);
    CU_ASSERT(memcmp(&pdu->hdr->id, teststr + 2, 2) == 0);
    CU_ASSERT(memcmp(pdu->hdr->token, teststr + 4, 5) == 0);
    CU_ASSERT_PTR_NULL(pdu->data);
}
示例#11
0
void t_parse_pdu5(void)
{
    /* PDU with options */
    char teststr[] =
    { 0x55, 0x73, 0x12, 0x34, 't', 'o', 'k', 'e', 'n', 0x00, 0xc1, 0x00 };
    int result;

    result = coap_pdu_parse((unsigned char *) teststr, sizeof(teststr), pdu);
    CU_ASSERT(result > 0);

    CU_ASSERT(pdu->length == sizeof(teststr));
    CU_ASSERT(pdu->hdr->version == 1);
    CU_ASSERT(pdu->hdr->type == COAP_MESSAGE_NON);
    CU_ASSERT(pdu->hdr->token_length == 5);
    CU_ASSERT(pdu->hdr->code == 0x73);
    CU_ASSERT(memcmp(&pdu->hdr->id, teststr + 2, 2) == 0);
    CU_ASSERT(memcmp(pdu->hdr->token, teststr + 4, 5) == 0);
    CU_ASSERT_PTR_NULL(pdu->data);

    /* FIXME: check options */
}
示例#12
0
void t_parse_pdu8(void)
{
    /* PDU without options but with payload */
    char teststr[] =
    { 0x50, 0x73, 0x12, 0x34, 0xff, 'p', 'a', 'y', 'l', 'o', 'a', 'd' };
    int result;

    result = coap_pdu_parse((unsigned char *) teststr, sizeof(teststr), pdu);
    CU_ASSERT(result > 0);

    CU_ASSERT(pdu->length == sizeof(teststr));
    CU_ASSERT(pdu->hdr->version == 1);
    CU_ASSERT(pdu->hdr->type == COAP_MESSAGE_NON);
    CU_ASSERT(pdu->hdr->token_length == 0);
    CU_ASSERT(pdu->hdr->code == 0x73);
    CU_ASSERT(memcmp(&pdu->hdr->id, teststr + 2, 2) == 0);

    /* FIXME: check options */

    CU_ASSERT(pdu->data == (unsigned char *) pdu->hdr + 5);
    CU_ASSERT(memcmp(pdu->data, teststr + 5, 7) == 0);
}
/*
 * Function:    _wilddog_recvCoap
 * Description: Verify the receive the coap 
 * Input:       p_buf: The pointer of the buffer
 *              buflen: The length of the buffer 
 * Output:      N/A
 * Return:      If there's coap packet, return the pointer of the coap pdu, 
 *              else return NULL
*/
STATIC coap_pdu_t * WD_SYSTEM _wilddog_recvCoap
    (
    u8 *p_buf,
    u32 buflen
    )
{
    coap_pdu_t* p_resp = NULL;

    p_resp = coap_new_pdu();
    if(!p_resp)
        return NULL;

    /*  is coap packet */
    if( coap_pdu_parse(p_buf,buflen, p_resp) && 
        (p_resp->hdr->version == COAP_DEFAULT_VERSION)) 
            return p_resp;
    else
    {
        coap_delete_pdu(p_resp);
        return NULL;
    }
}