2010-10-17 11:48:40 +00:00
|
|
|
/* packet-coap.c
|
2013-03-22 00:12:44 +00:00
|
|
|
* Routines for CoAP packet disassembly
|
|
|
|
* draft-ietf-core-coap-14.txt
|
|
|
|
* draft-ietf-core-block-10.txt
|
|
|
|
* draft-ietf-core-observe-07.txt
|
2011-08-10 20:54:44 +00:00
|
|
|
* draft-ietf-core-link-format-06.txt
|
2010-10-21 03:04:15 +00:00
|
|
|
* Shoichi Sakane <sakane@tanu.org>
|
|
|
|
*
|
2013-06-11 05:27:47 +00:00
|
|
|
* Changes for draft-ietf-core-coap-17.txt
|
|
|
|
* Hauke Mehrtens <hauke@hauke-m.de>
|
|
|
|
*
|
2010-10-21 03:04:15 +00:00
|
|
|
* $Id$
|
2010-10-17 11:48:40 +00:00
|
|
|
*
|
|
|
|
* Wireshark - Network traffic analyzer
|
|
|
|
* By Gerald Combs <gerald@wireshark.org>
|
|
|
|
* Copyright 1998 Gerald Combs
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
* as published by the Free Software Foundation; either version 2
|
|
|
|
* of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software
|
2012-06-28 22:56:06 +00:00
|
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
2010-10-17 11:48:40 +00:00
|
|
|
*/
|
|
|
|
|
2012-09-20 02:03:38 +00:00
|
|
|
#include "config.h"
|
2010-10-17 11:48:40 +00:00
|
|
|
|
|
|
|
#include <glib.h>
|
|
|
|
|
|
|
|
#include <epan/packet.h>
|
|
|
|
#include <epan/prefs.h>
|
2010-10-30 12:48:29 +00:00
|
|
|
#include <expert.h>
|
2010-10-17 11:48:40 +00:00
|
|
|
|
2013-03-15 06:26:47 +00:00
|
|
|
void proto_register_coap(void);
|
|
|
|
|
2010-10-17 11:48:40 +00:00
|
|
|
static dissector_table_t media_type_dissector_table;
|
|
|
|
|
|
|
|
static int proto_coap = -1;
|
|
|
|
|
|
|
|
static int hf_coap_version = -1;
|
|
|
|
static int hf_coap_ttype = -1;
|
2013-06-11 05:20:33 +00:00
|
|
|
static int hf_coap_token_len = -1;
|
|
|
|
static int hf_coap_token = -1;
|
2010-10-17 11:48:40 +00:00
|
|
|
static int hf_coap_code = -1;
|
2013-06-11 05:23:52 +00:00
|
|
|
static int hf_coap_mid = -1;
|
2013-06-11 05:37:17 +00:00
|
|
|
static int hf_coap_payload = -1;
|
2013-03-22 00:12:44 +00:00
|
|
|
static int hf_coap_payload_desc = -1;
|
|
|
|
static int hf_coap_opt_name = -1;
|
|
|
|
static int hf_coap_opt_desc = -1;
|
2010-10-21 22:41:39 +00:00
|
|
|
static int hf_coap_opt_delta = -1;
|
2013-06-11 05:31:10 +00:00
|
|
|
static int hf_coap_opt_delta_ext = -1;
|
2010-11-19 02:12:19 +00:00
|
|
|
static int hf_coap_opt_length = -1;
|
2013-06-11 05:31:10 +00:00
|
|
|
static int hf_coap_opt_length_ext = -1;
|
|
|
|
static int hf_coap_opt_end_marker = -1;
|
2010-10-17 11:48:40 +00:00
|
|
|
static int hf_coap_opt_ctype = -1;
|
2010-10-21 22:41:39 +00:00
|
|
|
static int hf_coap_opt_max_age = -1;
|
2011-08-10 20:54:44 +00:00
|
|
|
static int hf_coap_opt_proxy_uri = -1;
|
|
|
|
static int hf_coap_opt_etag = -1;
|
|
|
|
static int hf_coap_opt_uri_host = -1;
|
|
|
|
static int hf_coap_opt_location_path = -1;
|
|
|
|
static int hf_coap_opt_uri_port = -1;
|
|
|
|
static int hf_coap_opt_location_query = -1;
|
2010-10-17 11:48:40 +00:00
|
|
|
static int hf_coap_opt_uri_path = -1;
|
2011-08-10 20:54:44 +00:00
|
|
|
static int hf_coap_opt_observe = -1;
|
|
|
|
static int hf_coap_opt_accept = -1;
|
|
|
|
static int hf_coap_opt_if_match = -1;
|
2010-10-21 22:41:39 +00:00
|
|
|
static int hf_coap_opt_block_number = -1;
|
|
|
|
static int hf_coap_opt_block_mflag = -1;
|
|
|
|
static int hf_coap_opt_block_size = -1;
|
2010-11-15 18:01:19 +00:00
|
|
|
static int hf_coap_opt_uri_query = -1;
|
2013-03-22 00:12:44 +00:00
|
|
|
static int hf_coap_opt_unknown = -1;
|
2010-10-17 11:48:40 +00:00
|
|
|
|
|
|
|
static gint ett_coap = -1;
|
2010-10-21 22:41:39 +00:00
|
|
|
static gint ett_coap_option = -1;
|
2010-10-17 11:48:40 +00:00
|
|
|
static gint ett_coap_payload = -1;
|
|
|
|
|
2013-03-22 00:12:44 +00:00
|
|
|
/* CoAP's IANA-assigned port number */
|
2011-08-10 20:54:44 +00:00
|
|
|
#define DEFAULT_COAP_PORT 5683
|
2010-10-17 11:48:40 +00:00
|
|
|
|
2013-03-22 00:12:44 +00:00
|
|
|
/* indicators whether those are to be showed or not */
|
|
|
|
#define DEFAULT_COAP_CTYPE_VALUE ~0
|
|
|
|
#define DEFAULT_COAP_BLOCK_NUMBER ~0
|
2011-08-10 20:54:44 +00:00
|
|
|
|
2013-03-22 00:12:44 +00:00
|
|
|
static const gchar *coap_ctype_str = NULL;
|
|
|
|
static gint coap_ctype_value = DEFAULT_COAP_CTYPE_VALUE;
|
|
|
|
static guint global_coap_port_number = DEFAULT_COAP_PORT;
|
|
|
|
static gint coap_block_number = DEFAULT_COAP_BLOCK_NUMBER;
|
|
|
|
static guint coap_block_mflag = 0;
|
|
|
|
static gchar coap_uri_str[1024]; /* the maximum is 1024 > 510 = Uri-Host:255 + Uri-Path:255 x 2 */
|
|
|
|
static gchar coap_uri_query[1024]; /* the maximum is 1024 > 765 = Uri-Query:255 x 3 */
|
|
|
|
static gchar coap_token_str[128];
|
2010-10-17 11:48:40 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Transaction Type
|
|
|
|
*/
|
|
|
|
static const value_string vals_ttype[] = {
|
|
|
|
{ 0, "Confirmable" },
|
|
|
|
{ 1, "Non-Confirmable" },
|
|
|
|
{ 2, "Acknowledgement" },
|
|
|
|
{ 3, "Reset" },
|
|
|
|
{ 0, NULL },
|
|
|
|
};
|
2013-03-22 00:12:44 +00:00
|
|
|
static const value_string vals_ttype_short[] = {
|
|
|
|
{ 0, "CON" },
|
|
|
|
{ 1, "NON" },
|
|
|
|
{ 2, "ACK" },
|
|
|
|
{ 3, "RST" },
|
|
|
|
{ 0, NULL },
|
|
|
|
};
|
2010-10-17 11:48:40 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Method Code
|
|
|
|
* Response Code
|
|
|
|
*/
|
|
|
|
static const value_string vals_code[] = {
|
2011-08-10 20:54:44 +00:00
|
|
|
{ 0, "Empty Message" },
|
|
|
|
|
2010-10-17 11:48:40 +00:00
|
|
|
/* method code */
|
|
|
|
{ 1, "GET" },
|
|
|
|
{ 2, "POST" },
|
|
|
|
{ 3, "PUT" },
|
|
|
|
{ 4, "DELETE" },
|
|
|
|
|
|
|
|
/* response code */
|
2011-08-10 20:54:44 +00:00
|
|
|
{ 65, "2.01 Created" },
|
|
|
|
{ 66, "2.02 Deleted" },
|
|
|
|
{ 67, "2.03 Valid" },
|
|
|
|
{ 68, "2.04 Changed" },
|
|
|
|
{ 69, "2.05 Content" },
|
|
|
|
{ 128, "4.00 Bad Request" },
|
|
|
|
{ 129, "4.01 Unauthorized" },
|
|
|
|
{ 130, "4.02 Bad Option" },
|
|
|
|
{ 131, "4.03 Forbidden" },
|
|
|
|
{ 132, "4.04 Not Found" },
|
|
|
|
{ 133, "4.05 Method Not Allowed" },
|
2013-03-22 00:12:44 +00:00
|
|
|
{ 134, "4.06 Not Acceptable" },
|
|
|
|
{ 136, "4.08 Request Entity Incomplete" }, /* core-block-10 */
|
2011-08-10 20:54:44 +00:00
|
|
|
{ 140, "4.12 Precondition Failed" },
|
|
|
|
{ 141, "4.13 Request Entity Too Large" },
|
2013-03-22 00:12:44 +00:00
|
|
|
{ 143, "4.15 Unsupported Content-Format" },
|
2011-08-10 20:54:44 +00:00
|
|
|
{ 160, "5.00 Internal Server Error" },
|
|
|
|
{ 161, "5.01 Not Implemented" },
|
|
|
|
{ 162, "5.02 Bad Gateway" },
|
|
|
|
{ 163, "5.03 Service Unavailable" },
|
|
|
|
{ 164, "5.04 Gateway Timeout" },
|
|
|
|
{ 165, "5.05 Proxying Not Supported" },
|
|
|
|
|
2010-10-17 11:48:40 +00:00
|
|
|
{ 0, NULL },
|
|
|
|
};
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Option Headers
|
|
|
|
* No-Option must not be included in this structure, is handled in the function
|
|
|
|
* of the dissector, especially.
|
|
|
|
*/
|
2013-03-22 00:12:44 +00:00
|
|
|
#define COAP_OPT_IF_MATCH 1
|
|
|
|
#define COAP_OPT_URI_HOST 3
|
2012-07-11 20:40:13 +00:00
|
|
|
#define COAP_OPT_ETAG 4
|
2013-03-22 00:12:44 +00:00
|
|
|
#define COAP_OPT_IF_NONE_MATCH 5
|
|
|
|
#define COAP_OPT_OBSERVE 6 /* core-observe-07 */
|
2012-07-11 20:40:13 +00:00
|
|
|
#define COAP_OPT_URI_PORT 7
|
2013-03-22 00:12:44 +00:00
|
|
|
#define COAP_OPT_LOCATION_PATH 8
|
|
|
|
#define COAP_OPT_URI_PATH 11
|
|
|
|
#define COAP_OPT_CONTENT_TYPE 12
|
|
|
|
#define COAP_OPT_MAX_AGE 14
|
2010-11-15 18:01:19 +00:00
|
|
|
#define COAP_OPT_URI_QUERY 15
|
2013-03-22 00:12:44 +00:00
|
|
|
#define COAP_OPT_ACCEPT 16
|
|
|
|
#define COAP_OPT_LOCATION_QUERY 20
|
|
|
|
#define COAP_OPT_BLOCK2 23 /* core-block-10 */
|
|
|
|
#define COAP_OPT_BLOCK_SIZE 28 /* core-block-10 */
|
|
|
|
#define COAP_OPT_BLOCK1 27 /* core-block-10 */
|
|
|
|
#define COAP_OPT_PROXY_URI 35
|
2010-10-17 11:48:40 +00:00
|
|
|
|
|
|
|
static const value_string vals_opt_type[] = {
|
2013-03-22 00:12:44 +00:00
|
|
|
{ COAP_OPT_IF_MATCH, "If-Match" },
|
2012-07-11 20:40:13 +00:00
|
|
|
{ COAP_OPT_URI_HOST, "Uri-Host" },
|
2013-03-22 00:12:44 +00:00
|
|
|
{ COAP_OPT_ETAG, "Etag" },
|
|
|
|
{ COAP_OPT_IF_NONE_MATCH, "If-None-Match" },
|
2012-07-11 20:40:13 +00:00
|
|
|
{ COAP_OPT_URI_PORT, "Uri-Port" },
|
2013-03-22 00:12:44 +00:00
|
|
|
{ COAP_OPT_LOCATION_PATH, "Location-Path" },
|
2012-07-11 20:40:13 +00:00
|
|
|
{ COAP_OPT_URI_PATH, "Uri-Path" },
|
2013-03-22 00:12:44 +00:00
|
|
|
{ COAP_OPT_CONTENT_TYPE, "Content-Format" },
|
|
|
|
{ COAP_OPT_MAX_AGE, "Max-age" },
|
2012-07-11 20:40:13 +00:00
|
|
|
{ COAP_OPT_URI_QUERY, "Uri-Query" },
|
2013-03-22 00:12:44 +00:00
|
|
|
{ COAP_OPT_ACCEPT, "Accept" },
|
|
|
|
{ COAP_OPT_LOCATION_QUERY, "Location-Query" },
|
|
|
|
{ COAP_OPT_PROXY_URI, "Proxy-Uri" },
|
|
|
|
{ COAP_OPT_OBSERVE, "Observe" },
|
2012-07-11 20:40:13 +00:00
|
|
|
{ COAP_OPT_BLOCK2, "Block2" },
|
|
|
|
{ COAP_OPT_BLOCK1, "Block1" },
|
2013-03-22 00:12:44 +00:00
|
|
|
{ COAP_OPT_BLOCK_SIZE, "Block Size" },
|
2010-10-17 11:48:40 +00:00
|
|
|
{ 0, NULL },
|
|
|
|
};
|
|
|
|
|
2013-03-22 00:12:44 +00:00
|
|
|
struct coap_option_range_t {
|
|
|
|
guint type;
|
|
|
|
gint min;
|
|
|
|
gint max;
|
|
|
|
} coi[] = {
|
|
|
|
{ COAP_OPT_IF_MATCH, 0, 8 },
|
|
|
|
{ COAP_OPT_URI_HOST, 1, 255 },
|
|
|
|
{ COAP_OPT_ETAG, 1, 8 },
|
|
|
|
{ COAP_OPT_IF_NONE_MATCH, 0, 0 },
|
|
|
|
{ COAP_OPT_URI_PORT, 0, 2 },
|
|
|
|
{ COAP_OPT_LOCATION_PATH, 0, 255 },
|
|
|
|
{ COAP_OPT_URI_PATH, 0, 255 },
|
|
|
|
{ COAP_OPT_CONTENT_TYPE, 0, 2 },
|
|
|
|
{ COAP_OPT_MAX_AGE, 0, 4 },
|
|
|
|
{ COAP_OPT_URI_QUERY, 1, 255 },
|
|
|
|
{ COAP_OPT_ACCEPT, 0, 2 },
|
|
|
|
{ COAP_OPT_LOCATION_QUERY, 0, 255 },
|
|
|
|
{ COAP_OPT_PROXY_URI, 1,1034 },
|
|
|
|
{ COAP_OPT_OBSERVE, 0, 2 },
|
|
|
|
{ COAP_OPT_BLOCK2, 0, 3 },
|
|
|
|
{ COAP_OPT_BLOCK1, 0, 3 },
|
|
|
|
{ COAP_OPT_BLOCK_SIZE, 0, 4 },
|
|
|
|
{ 0, 0, 0 },
|
|
|
|
};
|
|
|
|
|
2010-10-17 11:48:40 +00:00
|
|
|
static const value_string vals_ctype[] = {
|
2013-03-22 00:12:44 +00:00
|
|
|
{ 0, "text/plain; charset=utf-8" },
|
2010-10-17 11:48:40 +00:00
|
|
|
{ 40, "application/link-format" },
|
|
|
|
{ 41, "application/xml" },
|
|
|
|
{ 42, "application/octet-stream" },
|
|
|
|
{ 47, "application/exi" },
|
2011-08-10 20:54:44 +00:00
|
|
|
{ 50, "application/json" },
|
2010-10-17 11:48:40 +00:00
|
|
|
{ 0, NULL },
|
|
|
|
};
|
|
|
|
|
2013-03-22 00:12:44 +00:00
|
|
|
static const char *nullstr = "(null)";
|
|
|
|
|
2010-10-17 11:48:40 +00:00
|
|
|
void proto_reg_handoff_coap(void);
|
|
|
|
|
2011-08-10 20:54:44 +00:00
|
|
|
static int
|
|
|
|
coap_is_str_ipv6addr(guint8 *str)
|
|
|
|
{
|
2012-07-11 20:40:13 +00:00
|
|
|
size_t len = strlen(str);
|
|
|
|
int colon = 0;
|
2011-08-10 20:54:44 +00:00
|
|
|
|
|
|
|
while (len--) {
|
|
|
|
if (*str++ == ':')
|
|
|
|
colon++;
|
|
|
|
}
|
|
|
|
|
|
|
|
return colon > 1 ? 1 : 0;
|
|
|
|
}
|
|
|
|
|
2013-03-22 00:12:44 +00:00
|
|
|
static gint
|
|
|
|
coap_get_opt_uint(tvbuff_t *tvb, gint offset, gint length)
|
|
|
|
{
|
|
|
|
switch (length) {
|
|
|
|
case 0:
|
|
|
|
return 0;
|
|
|
|
case 1:
|
|
|
|
return (guint)tvb_get_guint8(tvb, offset);
|
|
|
|
case 2:
|
|
|
|
return (guint)tvb_get_ntohs(tvb, offset);
|
|
|
|
case 3:
|
|
|
|
return (guint)tvb_get_ntoh24(tvb, offset);
|
|
|
|
case 4:
|
|
|
|
return (guint)tvb_get_ntohl(tvb, offset);
|
|
|
|
default:
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static gint
|
|
|
|
coap_opt_check(packet_info *pinfo, proto_tree *subtree, guint opt_num, gint opt_length)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
|
|
|
for (i = 0; i < (int)(array_length(coi)); i++) {
|
|
|
|
if (coi[i].type == opt_num)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (i == (int)(array_length(coi))) {
|
|
|
|
expert_add_info_format(pinfo, subtree, PI_MALFORMED, PI_WARN,
|
|
|
|
"Invalid Option Number %d", opt_num);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
if (opt_length < coi[i].min || opt_length > coi[i].max) {
|
|
|
|
expert_add_info_format(pinfo, subtree, PI_MALFORMED,
|
|
|
|
PI_WARN, "Invalid Option Range: %d (%d < x < %d)",
|
|
|
|
opt_length, coi[i].min, coi[i].max);
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2010-10-21 22:41:39 +00:00
|
|
|
static void
|
2013-06-11 05:31:10 +00:00
|
|
|
dissect_coap_opt_hex_string(tvbuff_t *tvb, proto_item *item, proto_tree *subtree, gint offset, gint opt_length, int hf)
|
2010-10-21 22:41:39 +00:00
|
|
|
{
|
2013-03-22 00:12:44 +00:00
|
|
|
const guint8 *str;
|
|
|
|
|
|
|
|
if (opt_length == 0)
|
|
|
|
str = nullstr;
|
|
|
|
else
|
2013-06-11 05:31:10 +00:00
|
|
|
str = tvb_bytes_to_str_punct(tvb, offset, opt_length, ' ');
|
2011-08-10 20:54:44 +00:00
|
|
|
|
2013-06-11 05:34:33 +00:00
|
|
|
proto_tree_add_item(subtree, hf, tvb, offset, opt_length, ENC_NA);
|
2013-03-22 00:12:44 +00:00
|
|
|
|
|
|
|
/* add info to the head of the packet detail */
|
|
|
|
proto_item_append_text(item, ": %s", str);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2013-06-11 05:31:10 +00:00
|
|
|
dissect_coap_opt_uint(tvbuff_t *tvb, proto_item *head_item, proto_tree *subtree, gint offset, gint opt_length, int hf)
|
2013-03-22 00:12:44 +00:00
|
|
|
{
|
|
|
|
guint i = 0;
|
|
|
|
|
2013-06-11 05:31:10 +00:00
|
|
|
if (opt_length != 0) {
|
|
|
|
i = coap_get_opt_uint(tvb, offset, opt_length);
|
2013-03-22 00:12:44 +00:00
|
|
|
}
|
|
|
|
|
2013-06-11 05:31:10 +00:00
|
|
|
proto_tree_add_uint(subtree, hf, tvb, offset, opt_length, i);
|
2013-03-22 00:12:44 +00:00
|
|
|
|
|
|
|
/* add info to the head of the packet detail */
|
|
|
|
proto_item_append_text(head_item, ": %d", i);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2013-06-11 05:31:10 +00:00
|
|
|
dissect_coap_opt_uri_host(tvbuff_t *tvb, proto_item *head_item, proto_tree *subtree, gint offset, gint opt_length)
|
2013-03-22 00:12:44 +00:00
|
|
|
{
|
|
|
|
guint8 *str = NULL;
|
|
|
|
|
2013-06-11 05:31:10 +00:00
|
|
|
str = tvb_get_ephemeral_string(tvb, offset, opt_length);
|
2013-03-22 00:12:44 +00:00
|
|
|
|
2013-06-11 05:31:10 +00:00
|
|
|
proto_tree_add_string(subtree, hf_coap_opt_uri_host, tvb, offset, opt_length, str);
|
2013-03-22 00:12:44 +00:00
|
|
|
|
|
|
|
/* add info to the head of the packet detail */
|
|
|
|
proto_item_append_text(head_item, ": %s", str);
|
2011-08-10 20:54:44 +00:00
|
|
|
|
|
|
|
/* forming a uri-string */
|
2013-03-22 00:12:44 +00:00
|
|
|
g_strlcat(coap_uri_str, "coap://", sizeof(coap_uri_str));
|
|
|
|
/*
|
|
|
|
* if the string looks an IPv6 address, assuming that it has
|
|
|
|
* to be enclosed by brackets.
|
|
|
|
*/
|
|
|
|
if (coap_is_str_ipv6addr(str)) {
|
|
|
|
g_strlcat(coap_uri_str, "[", sizeof(coap_uri_str));
|
|
|
|
g_strlcat(coap_uri_str, str, sizeof(coap_uri_str));
|
|
|
|
g_strlcat(coap_uri_str, "]", sizeof(coap_uri_str));
|
|
|
|
} else
|
|
|
|
g_strlcat(coap_uri_str, str, sizeof(coap_uri_str));
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2013-06-11 05:31:10 +00:00
|
|
|
dissect_coap_opt_uri_path(tvbuff_t *tvb, proto_item *head_item, proto_tree *subtree, gint offset, gint opt_length)
|
2013-03-22 00:12:44 +00:00
|
|
|
{
|
|
|
|
const guint8 *str = NULL;
|
|
|
|
|
|
|
|
g_strlcat(coap_uri_str, "/", sizeof(coap_uri_str));
|
|
|
|
|
|
|
|
if (opt_length == 0) {
|
|
|
|
str = nullstr;
|
|
|
|
} else {
|
2013-06-11 05:31:10 +00:00
|
|
|
str = tvb_get_ephemeral_string(tvb, offset, opt_length);
|
2013-03-22 00:12:44 +00:00
|
|
|
g_strlcat(coap_uri_str, str, sizeof(coap_uri_str));
|
2011-08-10 20:54:44 +00:00
|
|
|
}
|
2013-03-22 00:12:44 +00:00
|
|
|
|
2013-06-11 05:31:10 +00:00
|
|
|
proto_tree_add_string(subtree, hf_coap_opt_uri_path, tvb, offset, opt_length, str);
|
2013-03-22 00:12:44 +00:00
|
|
|
|
|
|
|
/* add info to the head of the packet detail */
|
|
|
|
proto_item_append_text(head_item, ": %s", str);
|
2010-10-21 22:41:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2013-06-11 05:31:10 +00:00
|
|
|
dissect_coap_opt_uri_query(tvbuff_t *tvb, proto_item *head_item,proto_tree *subtree, gint offset, gint opt_length)
|
2010-10-21 22:41:39 +00:00
|
|
|
{
|
2013-03-22 00:12:44 +00:00
|
|
|
const guint8 *str = NULL;
|
|
|
|
|
|
|
|
if (coap_uri_query[0] == '\0')
|
|
|
|
g_strlcat(coap_uri_query, "?", sizeof(coap_uri_str));
|
|
|
|
else
|
|
|
|
g_strlcat(coap_uri_query, "&", sizeof(coap_uri_str));
|
|
|
|
|
|
|
|
if (opt_length == 0) {
|
|
|
|
str = nullstr;
|
|
|
|
} else {
|
2013-06-11 05:31:10 +00:00
|
|
|
str = tvb_get_ephemeral_string(tvb, offset, opt_length);
|
2013-03-22 00:12:44 +00:00
|
|
|
g_strlcat(coap_uri_str, str, sizeof(coap_uri_str));
|
|
|
|
}
|
2011-08-10 20:54:44 +00:00
|
|
|
|
2013-06-11 05:31:10 +00:00
|
|
|
proto_tree_add_string(subtree, hf_coap_opt_uri_query, tvb, offset, opt_length, str);
|
2013-03-22 00:12:44 +00:00
|
|
|
|
|
|
|
/* add info to the head of the packet detail */
|
|
|
|
proto_item_append_text(head_item, ": %s", str);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2013-06-11 05:31:10 +00:00
|
|
|
dissect_coap_opt_location_path(tvbuff_t *tvb, proto_item *head_item, proto_tree *subtree, gint offset, gint opt_length)
|
2013-03-22 00:12:44 +00:00
|
|
|
{
|
|
|
|
const guint8 *str = NULL;
|
|
|
|
|
|
|
|
if (opt_length == 0) {
|
|
|
|
str = nullstr;
|
|
|
|
} else {
|
2013-06-11 05:31:10 +00:00
|
|
|
str = tvb_get_ephemeral_string(tvb, offset, opt_length);
|
2011-08-10 20:54:44 +00:00
|
|
|
}
|
2010-10-21 22:41:39 +00:00
|
|
|
|
2013-06-11 05:31:10 +00:00
|
|
|
proto_tree_add_string(subtree, hf_coap_opt_location_path, tvb, offset, opt_length, str);
|
2011-08-10 20:54:44 +00:00
|
|
|
|
2013-03-22 00:12:44 +00:00
|
|
|
/* add info to the head of the packet detail */
|
|
|
|
proto_item_append_text(head_item, ": %s", str);
|
2010-10-21 22:41:39 +00:00
|
|
|
}
|
|
|
|
|
2010-10-20 20:40:53 +00:00
|
|
|
static void
|
2013-06-11 05:31:10 +00:00
|
|
|
dissect_coap_opt_location_query(tvbuff_t *tvb, proto_item *head_item, proto_tree *subtree, gint offset, gint opt_length)
|
2010-10-20 20:40:53 +00:00
|
|
|
{
|
2013-03-22 00:12:44 +00:00
|
|
|
const guint8 *str = NULL;
|
2010-10-20 20:40:53 +00:00
|
|
|
|
2013-03-22 00:12:44 +00:00
|
|
|
if (opt_length == 0) {
|
|
|
|
str = nullstr;
|
|
|
|
} else {
|
2013-06-11 05:31:10 +00:00
|
|
|
str = tvb_get_ephemeral_string(tvb, offset, opt_length);
|
2013-03-22 00:12:44 +00:00
|
|
|
}
|
|
|
|
|
2013-06-11 05:31:10 +00:00
|
|
|
proto_tree_add_string(subtree, hf_coap_opt_location_query, tvb, offset, opt_length, str);
|
2013-03-22 00:12:44 +00:00
|
|
|
|
|
|
|
/* add info to the head of the packet detail */
|
|
|
|
proto_item_append_text(head_item, ": %s", str);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2013-06-11 05:31:10 +00:00
|
|
|
dissect_coap_opt_proxy_uri(tvbuff_t *tvb, proto_item *head_item, proto_tree *subtree, gint offset, gint opt_length)
|
2013-03-22 00:12:44 +00:00
|
|
|
{
|
|
|
|
const guint8 *str = NULL;
|
|
|
|
|
|
|
|
if (opt_length == 0) {
|
|
|
|
str = nullstr;
|
|
|
|
} else {
|
2013-06-11 05:31:10 +00:00
|
|
|
str = tvb_get_ephemeral_string(tvb, offset, opt_length);
|
2010-10-20 20:40:53 +00:00
|
|
|
}
|
2011-08-10 20:54:44 +00:00
|
|
|
|
2013-06-11 05:31:10 +00:00
|
|
|
proto_tree_add_string(subtree, hf_coap_opt_proxy_uri, tvb, offset, opt_length, str);
|
2010-10-20 20:40:53 +00:00
|
|
|
|
2013-03-22 00:12:44 +00:00
|
|
|
/* add info to the head of the packet detail */
|
|
|
|
proto_item_append_text(head_item, ": %s", str);
|
2010-10-20 20:40:53 +00:00
|
|
|
}
|
|
|
|
|
2013-03-22 00:12:44 +00:00
|
|
|
static void
|
2013-06-11 05:31:10 +00:00
|
|
|
dissect_coap_opt_ctype(tvbuff_t *tvb, proto_item *head_item, proto_tree *subtree, gint offset, gint opt_length, int hf)
|
2013-03-22 00:12:44 +00:00
|
|
|
{
|
|
|
|
if (opt_length == 0) {
|
|
|
|
coap_ctype_value = 0;
|
|
|
|
} else {
|
2013-06-11 05:31:10 +00:00
|
|
|
coap_ctype_value = coap_get_opt_uint(tvb, offset, opt_length);
|
2013-03-22 00:12:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
coap_ctype_str = val_to_str(coap_ctype_value, vals_ctype, "Unknown Type %d");
|
|
|
|
|
2013-06-11 05:31:10 +00:00
|
|
|
proto_tree_add_string(subtree, hf, tvb, offset, opt_length, coap_ctype_str);
|
2013-03-22 00:12:44 +00:00
|
|
|
|
|
|
|
/* add info to the head of the packet detail */
|
|
|
|
proto_item_append_text(head_item, ": %s", coap_ctype_str);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2013-06-11 05:31:10 +00:00
|
|
|
dissect_coap_opt_block(tvbuff_t *tvb, proto_item *head_item, proto_tree *subtree, gint offset, gint opt_length)
|
2010-10-20 20:40:53 +00:00
|
|
|
{
|
2012-07-11 20:40:13 +00:00
|
|
|
guint8 val = 0;
|
|
|
|
guint encoded_block_size = 0;
|
2013-03-22 00:12:44 +00:00
|
|
|
guint block_esize;
|
|
|
|
|
|
|
|
if (opt_length == 0) {
|
|
|
|
coap_block_number = 0;
|
|
|
|
val = 0;
|
|
|
|
} else {
|
2013-06-11 05:31:10 +00:00
|
|
|
coap_block_number = coap_get_opt_uint(tvb, offset, opt_length) >> 4;
|
2013-03-22 00:12:44 +00:00
|
|
|
val = tvb_get_guint8(tvb, offset + opt_length - 1) & 0x0f;
|
2010-10-20 20:40:53 +00:00
|
|
|
}
|
|
|
|
|
2013-03-22 00:12:44 +00:00
|
|
|
proto_tree_add_uint(subtree, hf_coap_opt_block_number,
|
2013-06-11 05:31:10 +00:00
|
|
|
tvb, offset, opt_length, coap_block_number);
|
2013-03-22 00:12:44 +00:00
|
|
|
|
|
|
|
/* More flag in the end of the option */
|
|
|
|
coap_block_mflag = val & 0x08;
|
|
|
|
proto_tree_add_uint(subtree, hf_coap_opt_block_mflag,
|
2013-06-11 05:31:10 +00:00
|
|
|
tvb, offset + opt_length - 1, 1, coap_block_mflag);
|
2010-10-21 22:41:39 +00:00
|
|
|
|
2013-03-22 00:12:44 +00:00
|
|
|
/* block size */
|
|
|
|
encoded_block_size = val & 0x07;
|
|
|
|
block_esize = 1 << (encoded_block_size + 4);
|
|
|
|
proto_tree_add_uint_format(subtree, hf_coap_opt_block_size,
|
2013-06-11 05:31:10 +00:00
|
|
|
tvb, offset + opt_length - 1, 1, encoded_block_size, "Block Size: %d (%d encoded)", block_esize, encoded_block_size);
|
2010-10-20 20:40:53 +00:00
|
|
|
|
2013-03-22 00:12:44 +00:00
|
|
|
/* add info to the head of the packet detail */
|
|
|
|
proto_item_append_text(head_item, ": NUM:%d, M:%d, SZX:%d",
|
|
|
|
coap_block_number, coap_block_mflag, block_esize);
|
2010-10-20 20:40:53 +00:00
|
|
|
}
|
|
|
|
|
2011-08-10 20:54:44 +00:00
|
|
|
static void
|
2013-06-11 05:31:10 +00:00
|
|
|
dissect_coap_opt_uri_port(tvbuff_t *tvb, proto_item *head_item, proto_tree *subtree, gint offset, gint opt_length)
|
2011-08-10 20:54:44 +00:00
|
|
|
{
|
2013-03-22 00:12:44 +00:00
|
|
|
guint port = 0;
|
|
|
|
char portstr[6];
|
2011-08-10 20:54:44 +00:00
|
|
|
|
|
|
|
memset(portstr, '\0', sizeof(portstr));
|
|
|
|
|
2013-06-11 05:31:10 +00:00
|
|
|
if (opt_length != 0) {
|
|
|
|
port = coap_get_opt_uint(tvb, offset, opt_length);
|
2011-08-10 20:54:44 +00:00
|
|
|
}
|
|
|
|
|
2013-06-11 05:31:10 +00:00
|
|
|
proto_tree_add_uint(subtree, hf_coap_opt_uri_port, tvb, offset, opt_length, port);
|
2013-03-22 00:12:44 +00:00
|
|
|
|
|
|
|
proto_item_append_text(head_item, ": %d", port);
|
2011-08-10 20:54:44 +00:00
|
|
|
|
2013-03-22 00:12:44 +00:00
|
|
|
/* forming a uri-string */
|
|
|
|
g_snprintf(portstr, sizeof(portstr), "%u", port);
|
|
|
|
g_strlcat(coap_uri_str, ":", sizeof(coap_uri_str));
|
|
|
|
g_strlcat(coap_uri_str, portstr, sizeof(coap_uri_str));
|
2011-08-10 20:54:44 +00:00
|
|
|
}
|
|
|
|
|
2010-10-17 11:48:40 +00:00
|
|
|
/*
|
2013-03-22 00:12:44 +00:00
|
|
|
* dissector for each option of CoAP.
|
2010-10-17 11:48:40 +00:00
|
|
|
* return the total length of the option including the header (e.g. delta and length).
|
|
|
|
*/
|
|
|
|
static int
|
2013-03-22 00:12:44 +00:00
|
|
|
dissect_coap_options_main(tvbuff_t *tvb, packet_info *pinfo, proto_tree *coap_tree, gint offset, guint8 opt_count, guint *opt_num, gint coap_length)
|
2010-10-17 11:48:40 +00:00
|
|
|
{
|
2013-03-22 00:12:44 +00:00
|
|
|
guint8 opt_jump;
|
2013-06-11 05:31:10 +00:00
|
|
|
gint opt_length, opt_length_ext, opt_delta, opt_delta_ext;
|
|
|
|
gint opt_length_ext_off = 0;
|
|
|
|
gint8 opt_length_ext_len = 0;
|
|
|
|
gint opt_delta_ext_off = 0;
|
|
|
|
gint8 opt_delta_ext_len = 0;
|
|
|
|
gint orig_offset = offset;
|
2012-07-11 20:40:13 +00:00
|
|
|
proto_tree *subtree = NULL;
|
|
|
|
proto_item *item = NULL;
|
2013-03-22 00:12:44 +00:00
|
|
|
char strbuf[56];
|
2010-10-17 11:48:40 +00:00
|
|
|
|
2013-03-22 00:12:44 +00:00
|
|
|
opt_jump = tvb_get_guint8(tvb, offset);
|
2013-06-11 05:31:10 +00:00
|
|
|
offset++;
|
2013-03-22 00:12:44 +00:00
|
|
|
|
|
|
|
/*
|
2013-06-11 05:31:10 +00:00
|
|
|
* seciton 3.1 in coap-17:
|
|
|
|
* Option Delta: 4-bit unsigned integer. A value between 0 and 12
|
|
|
|
* indicates the Option Delta. Three values are reserved for special
|
|
|
|
* constructs:
|
|
|
|
*
|
|
|
|
* 13: An 8-bit unsigned integer follows the initial byte and
|
|
|
|
* indicates the Option Delta minus 13.
|
2013-03-22 00:12:44 +00:00
|
|
|
*
|
2013-06-11 05:31:10 +00:00
|
|
|
* 14: A 16-bit unsigned integer in network byte order follows the
|
|
|
|
* initial byte and indicates the Option Delta minus 269.
|
|
|
|
*
|
|
|
|
* 15: Reserved for the Payload Marker. If the field is set to this
|
|
|
|
* value but the entire byte is not the payload marker, this MUST
|
|
|
|
* be processed as a message format error.
|
2013-03-22 00:12:44 +00:00
|
|
|
*/
|
2013-06-11 05:31:10 +00:00
|
|
|
switch (opt_jump & 0xf0) {
|
|
|
|
case 0xd0:
|
|
|
|
opt_delta_ext = tvb_get_guint8(tvb, offset);
|
|
|
|
opt_delta_ext_off = offset;
|
|
|
|
opt_delta_ext_len = 1;
|
2013-03-22 00:12:44 +00:00
|
|
|
offset++;
|
2013-06-11 05:31:10 +00:00
|
|
|
|
|
|
|
opt_delta = 13;
|
|
|
|
opt_delta += opt_delta_ext;
|
2013-03-22 00:12:44 +00:00
|
|
|
break;
|
2013-06-11 05:31:10 +00:00
|
|
|
case 0xe0:
|
|
|
|
opt_delta_ext = coap_get_opt_uint(tvb, offset, 2);
|
|
|
|
opt_delta_ext_off = offset;
|
|
|
|
opt_delta_ext_len = 2;
|
2013-03-22 00:12:44 +00:00
|
|
|
offset += 2;
|
2013-06-11 05:31:10 +00:00
|
|
|
|
|
|
|
opt_delta = 269;
|
|
|
|
opt_delta += opt_delta_ext;
|
2013-03-22 00:12:44 +00:00
|
|
|
break;
|
2013-06-11 05:31:10 +00:00
|
|
|
case 0xf0:
|
|
|
|
expert_add_info_format(pinfo, coap_tree,
|
|
|
|
PI_MALFORMED, PI_WARN,
|
|
|
|
"end-of-options marker found, but option length isn't 15");
|
|
|
|
return -1;
|
|
|
|
default:
|
|
|
|
opt_delta = ((opt_jump & 0xf0) >> 4);
|
2013-03-22 00:12:44 +00:00
|
|
|
break;
|
|
|
|
}
|
2013-06-11 05:31:10 +00:00
|
|
|
*opt_num += opt_delta;
|
2010-11-19 02:12:19 +00:00
|
|
|
|
|
|
|
/*
|
2013-06-11 05:31:10 +00:00
|
|
|
* seciton 3.1 in coap-17:
|
|
|
|
* Option Length: 4-bit unsigned integer. A value between 0 and 12
|
|
|
|
* indicates the length of the Option Value, in bytes. Three values
|
|
|
|
* are reserved for special constructs:
|
|
|
|
*
|
|
|
|
* 13: An 8-bit unsigned integer precedes the Option Value and
|
|
|
|
* indicates the Option Length minus 13.
|
|
|
|
*
|
|
|
|
* 14: A 16-bit unsigned integer in network byte order precedes the
|
|
|
|
* Option Value and indicates the Option Length minus 269.
|
|
|
|
*
|
|
|
|
* 15: Reserved for future use. If the field is set to this value,
|
|
|
|
* it MUST be processed as a message format error.
|
2010-11-19 02:12:19 +00:00
|
|
|
*/
|
2013-06-11 05:31:10 +00:00
|
|
|
switch (opt_jump & 0x0f) {
|
|
|
|
case 0x0d:
|
|
|
|
opt_length_ext = tvb_get_guint8(tvb, offset);
|
|
|
|
opt_length_ext_off = offset;
|
|
|
|
opt_length_ext_len = 1;
|
|
|
|
offset++;
|
|
|
|
|
|
|
|
opt_length = 13;
|
|
|
|
opt_length += opt_length_ext;
|
|
|
|
break;
|
|
|
|
case 0x0e:
|
|
|
|
opt_length_ext = coap_get_opt_uint(tvb, offset, 2);
|
|
|
|
opt_length_ext_off = offset;
|
|
|
|
opt_length_ext_len = 2;
|
|
|
|
offset += 2;
|
|
|
|
|
|
|
|
opt_length = 269;
|
|
|
|
opt_length += opt_length_ext;
|
|
|
|
break;
|
|
|
|
case 0x0f:
|
|
|
|
expert_add_info_format(pinfo, coap_tree,
|
|
|
|
PI_MALFORMED, PI_WARN,
|
|
|
|
"end-of-options marker found, but option delta isn't 15");
|
2013-03-22 00:12:44 +00:00
|
|
|
return -1;
|
2013-06-11 05:31:10 +00:00
|
|
|
default:
|
|
|
|
opt_length = (opt_jump & 0x0f);
|
|
|
|
break;
|
2010-10-17 11:48:40 +00:00
|
|
|
}
|
2013-06-11 05:31:10 +00:00
|
|
|
if (offset + opt_length > coap_length) {
|
|
|
|
expert_add_info_format(pinfo, coap_tree,
|
|
|
|
PI_MALFORMED, PI_WARN,
|
|
|
|
"option longer than the package");
|
2013-03-22 00:12:44 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2013-06-11 05:31:10 +00:00
|
|
|
coap_opt_check(pinfo, coap_tree, *opt_num, opt_length);
|
2010-10-20 20:40:53 +00:00
|
|
|
|
2013-03-22 00:12:44 +00:00
|
|
|
g_snprintf(strbuf, sizeof(strbuf),
|
|
|
|
"#%u: %s", opt_count, val_to_str_const(*opt_num, vals_opt_type,
|
|
|
|
*opt_num % 14 == 0 ? "No-Op" : "Unknown Option"));
|
|
|
|
item = proto_tree_add_string(coap_tree, hf_coap_opt_name,
|
2013-06-11 05:31:10 +00:00
|
|
|
tvb, orig_offset, offset - orig_offset + opt_length, strbuf);
|
2010-10-21 22:41:39 +00:00
|
|
|
subtree = proto_item_add_subtree(item, ett_coap_option);
|
2013-06-11 05:31:10 +00:00
|
|
|
|
2013-03-22 00:12:44 +00:00
|
|
|
g_snprintf(strbuf, sizeof(strbuf),
|
|
|
|
"Type %u, %s, %s%s", *opt_num,
|
|
|
|
(*opt_num & 1) ? "Critical" : "Elective",
|
|
|
|
(*opt_num & 2) ? "Unsafe" : "Safe",
|
|
|
|
((*opt_num & 0x1e) == 0x1c) ? ", NoCacheKey" : "");
|
|
|
|
proto_tree_add_string(subtree, hf_coap_opt_desc,
|
2013-06-11 05:31:10 +00:00
|
|
|
tvb, orig_offset, offset - orig_offset + opt_length, strbuf);
|
|
|
|
|
|
|
|
proto_tree_add_item(subtree, hf_coap_opt_delta, tvb, orig_offset, 1, ENC_BIG_ENDIAN);
|
|
|
|
proto_tree_add_item(subtree, hf_coap_opt_length, tvb, orig_offset, 1, ENC_BIG_ENDIAN);
|
|
|
|
|
|
|
|
if (opt_delta_ext_off && opt_delta_ext_len)
|
|
|
|
proto_tree_add_item(subtree, hf_coap_opt_delta_ext, tvb, opt_delta_ext_off, opt_delta_ext_len, ENC_BIG_ENDIAN);
|
2010-11-19 02:12:19 +00:00
|
|
|
|
2013-06-11 05:31:10 +00:00
|
|
|
if (opt_length_ext_off && opt_length_ext_len)
|
|
|
|
proto_tree_add_item(subtree, hf_coap_opt_length_ext, tvb, opt_length_ext_off, opt_length_ext_len, ENC_BIG_ENDIAN);
|
2010-10-17 11:48:40 +00:00
|
|
|
|
2013-03-22 00:12:44 +00:00
|
|
|
/* offset points the next to its option header */
|
|
|
|
switch (*opt_num) {
|
2011-08-10 20:54:44 +00:00
|
|
|
case COAP_OPT_CONTENT_TYPE:
|
2013-03-22 00:12:44 +00:00
|
|
|
dissect_coap_opt_ctype(tvb, item, subtree, offset,
|
2013-06-11 05:31:10 +00:00
|
|
|
opt_length, hf_coap_opt_ctype);
|
2011-08-10 20:54:44 +00:00
|
|
|
break;
|
|
|
|
case COAP_OPT_MAX_AGE:
|
2013-03-22 00:12:44 +00:00
|
|
|
dissect_coap_opt_uint(tvb, item, subtree, offset,
|
2013-06-11 05:31:10 +00:00
|
|
|
opt_length, hf_coap_opt_max_age);
|
2011-08-10 20:54:44 +00:00
|
|
|
break;
|
|
|
|
case COAP_OPT_PROXY_URI:
|
2013-03-22 00:12:44 +00:00
|
|
|
dissect_coap_opt_proxy_uri(tvb, item, subtree, offset,
|
2013-06-11 05:31:10 +00:00
|
|
|
opt_length);
|
2011-08-10 20:54:44 +00:00
|
|
|
break;
|
|
|
|
case COAP_OPT_ETAG:
|
2013-03-22 00:12:44 +00:00
|
|
|
dissect_coap_opt_hex_string(tvb, item, subtree, offset,
|
2013-06-11 05:31:10 +00:00
|
|
|
opt_length, hf_coap_opt_etag);
|
2011-08-10 20:54:44 +00:00
|
|
|
break;
|
|
|
|
case COAP_OPT_URI_HOST:
|
2013-03-22 00:12:44 +00:00
|
|
|
dissect_coap_opt_uri_host(tvb, item, subtree, offset,
|
2013-06-11 05:31:10 +00:00
|
|
|
opt_length);
|
2011-08-10 20:54:44 +00:00
|
|
|
break;
|
|
|
|
case COAP_OPT_LOCATION_PATH:
|
2013-03-22 00:12:44 +00:00
|
|
|
dissect_coap_opt_location_path(tvb, item, subtree, offset,
|
2013-06-11 05:31:10 +00:00
|
|
|
opt_length);
|
2011-08-10 20:54:44 +00:00
|
|
|
break;
|
|
|
|
case COAP_OPT_URI_PORT:
|
2013-03-22 00:12:44 +00:00
|
|
|
dissect_coap_opt_uri_port(tvb, item, subtree, offset,
|
2013-06-11 05:31:10 +00:00
|
|
|
opt_length);
|
2011-08-10 20:54:44 +00:00
|
|
|
break;
|
|
|
|
case COAP_OPT_LOCATION_QUERY:
|
2013-03-22 00:12:44 +00:00
|
|
|
dissect_coap_opt_location_query(tvb, item, subtree, offset,
|
2013-06-11 05:31:10 +00:00
|
|
|
opt_length);
|
2011-08-10 20:54:44 +00:00
|
|
|
break;
|
|
|
|
case COAP_OPT_URI_PATH:
|
2013-03-22 00:12:44 +00:00
|
|
|
dissect_coap_opt_uri_path(tvb, item, subtree, offset,
|
2013-06-11 05:31:10 +00:00
|
|
|
opt_length);
|
2011-08-10 20:54:44 +00:00
|
|
|
break;
|
|
|
|
case COAP_OPT_OBSERVE:
|
2013-03-22 00:12:44 +00:00
|
|
|
dissect_coap_opt_uint(tvb, item, subtree, offset,
|
2013-06-11 05:31:10 +00:00
|
|
|
opt_length, hf_coap_opt_observe);
|
2011-08-10 20:54:44 +00:00
|
|
|
break;
|
|
|
|
case COAP_OPT_ACCEPT:
|
2013-03-22 00:12:44 +00:00
|
|
|
dissect_coap_opt_ctype(tvb, item, subtree, offset,
|
2013-06-11 05:31:10 +00:00
|
|
|
opt_length, hf_coap_opt_accept);
|
2011-08-10 20:54:44 +00:00
|
|
|
break;
|
|
|
|
case COAP_OPT_IF_MATCH:
|
2013-03-22 00:12:44 +00:00
|
|
|
dissect_coap_opt_hex_string(tvb, item, subtree, offset,
|
2013-06-11 05:31:10 +00:00
|
|
|
opt_length, hf_coap_opt_if_match);
|
2011-08-10 20:54:44 +00:00
|
|
|
break;
|
|
|
|
case COAP_OPT_URI_QUERY:
|
2013-03-22 00:12:44 +00:00
|
|
|
dissect_coap_opt_uri_query(tvb, item, subtree, offset,
|
2013-06-11 05:31:10 +00:00
|
|
|
opt_length);
|
2011-08-10 20:54:44 +00:00
|
|
|
break;
|
|
|
|
case COAP_OPT_BLOCK2:
|
2013-03-22 00:12:44 +00:00
|
|
|
dissect_coap_opt_block(tvb, item, subtree, offset,
|
2013-06-11 05:31:10 +00:00
|
|
|
opt_length);
|
2011-08-10 20:54:44 +00:00
|
|
|
break;
|
|
|
|
case COAP_OPT_BLOCK1:
|
2013-03-22 00:12:44 +00:00
|
|
|
dissect_coap_opt_block(tvb, item, subtree, offset,
|
2013-06-11 05:31:10 +00:00
|
|
|
opt_length);
|
2011-08-10 20:54:44 +00:00
|
|
|
break;
|
|
|
|
case COAP_OPT_IF_NONE_MATCH:
|
2013-03-22 00:12:44 +00:00
|
|
|
break;
|
|
|
|
case COAP_OPT_BLOCK_SIZE:
|
|
|
|
dissect_coap_opt_uint(tvb, item, subtree, offset,
|
2013-06-11 05:31:10 +00:00
|
|
|
opt_length, hf_coap_opt_block_size);
|
2011-08-10 20:54:44 +00:00
|
|
|
break;
|
|
|
|
default:
|
2013-03-22 00:12:44 +00:00
|
|
|
dissect_coap_opt_hex_string(tvb, item, subtree, offset,
|
2013-06-11 05:31:10 +00:00
|
|
|
opt_length, hf_coap_opt_unknown);
|
2011-08-10 20:54:44 +00:00
|
|
|
break;
|
2010-10-17 11:48:40 +00:00
|
|
|
}
|
2010-10-21 22:41:39 +00:00
|
|
|
|
2013-06-11 05:31:10 +00:00
|
|
|
return offset + opt_length;
|
2013-03-22 00:12:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* options dissector.
|
|
|
|
* return offset pointing the next of options. (i.e. the top of the paylaod
|
|
|
|
* or the end of the data.
|
|
|
|
*/
|
|
|
|
static int
|
2013-06-11 05:27:47 +00:00
|
|
|
dissect_coap_options(tvbuff_t *tvb, packet_info *pinfo, proto_tree *coap_tree, gint offset, gint coap_length)
|
2013-03-22 00:12:44 +00:00
|
|
|
{
|
|
|
|
guint opt_num = 0;
|
|
|
|
int i;
|
2013-06-11 05:27:47 +00:00
|
|
|
guint8 endmarker;
|
2013-03-22 00:12:44 +00:00
|
|
|
|
|
|
|
/* loop for dissecting options */
|
2013-06-11 05:27:47 +00:00
|
|
|
for (i = 1; offset < coap_length; i++) {
|
2013-03-22 00:12:44 +00:00
|
|
|
offset = dissect_coap_options_main(tvb, pinfo, coap_tree,
|
|
|
|
offset, i, &opt_num, coap_length);
|
|
|
|
if (offset == -1)
|
|
|
|
return -1;
|
2013-06-11 05:27:47 +00:00
|
|
|
if (offset >= coap_length)
|
|
|
|
break;
|
|
|
|
endmarker = tvb_get_guint8(tvb, offset);
|
|
|
|
if (endmarker == 0xff) {
|
2013-06-11 05:31:10 +00:00
|
|
|
proto_tree_add_item(coap_tree, hf_coap_opt_end_marker, tvb, offset, 1, ENC_BIG_ENDIAN);
|
2013-06-11 05:27:47 +00:00
|
|
|
offset++;
|
|
|
|
break;
|
|
|
|
}
|
2013-03-22 00:12:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return offset;
|
2010-10-17 11:48:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
dissect_coap(tvbuff_t *tvb, packet_info *pinfo, proto_tree *parent_tree)
|
|
|
|
{
|
2013-03-22 00:12:44 +00:00
|
|
|
gint offset = 0;
|
2012-07-11 20:40:13 +00:00
|
|
|
proto_item *coap_root = NULL;
|
|
|
|
proto_tree *coap_tree = NULL;
|
|
|
|
guint8 ttype = 0;
|
2013-06-11 05:20:33 +00:00
|
|
|
guint8 token_len = 0;
|
2012-07-11 20:40:13 +00:00
|
|
|
guint8 code = 0;
|
2013-06-11 05:23:52 +00:00
|
|
|
guint16 mid = 0;
|
2013-03-22 00:12:44 +00:00
|
|
|
gint coap_length = 0;
|
2010-10-17 11:48:40 +00:00
|
|
|
|
2013-03-22 00:12:44 +00:00
|
|
|
/* initialize the CoAP length and the content-Format */
|
2010-10-20 20:40:53 +00:00
|
|
|
/*
|
2013-03-22 00:12:44 +00:00
|
|
|
* the length of CoAP message is not specified in the CoAP header.
|
2010-10-20 20:40:53 +00:00
|
|
|
* It has to be from the lower layer. the iplen of packet_info is not accurate.
|
|
|
|
* Currently, the length is just copied from the reported length of the tvbuffer.
|
|
|
|
*/
|
|
|
|
coap_length = tvb_reported_length(tvb);
|
2013-03-22 00:12:44 +00:00
|
|
|
coap_ctype_str = "";
|
|
|
|
coap_ctype_value = DEFAULT_COAP_CTYPE_VALUE;
|
2010-10-20 20:40:53 +00:00
|
|
|
|
2011-10-21 02:10:19 +00:00
|
|
|
coap_root = proto_tree_add_item(parent_tree, proto_coap, tvb, offset, -1, ENC_NA);
|
2010-10-17 11:48:40 +00:00
|
|
|
coap_tree = proto_item_add_subtree(coap_root, ett_coap);
|
|
|
|
|
2011-10-06 03:35:44 +00:00
|
|
|
proto_tree_add_item(coap_tree, hf_coap_version, tvb, offset, 1, ENC_BIG_ENDIAN);
|
2010-10-17 11:48:40 +00:00
|
|
|
|
2011-10-06 03:35:44 +00:00
|
|
|
proto_tree_add_item(coap_tree, hf_coap_ttype, tvb, offset, 1, ENC_BIG_ENDIAN);
|
2010-10-17 11:48:40 +00:00
|
|
|
ttype = (tvb_get_guint8(tvb, offset) & 0x30) >> 4;
|
|
|
|
|
2013-06-11 05:20:33 +00:00
|
|
|
proto_tree_add_item(coap_tree, hf_coap_token_len, tvb, offset, 1, ENC_BIG_ENDIAN);
|
|
|
|
token_len = tvb_get_guint8(tvb, offset) & 0x0f;
|
2010-10-17 11:48:40 +00:00
|
|
|
offset += 1;
|
|
|
|
|
2011-10-06 03:35:44 +00:00
|
|
|
proto_tree_add_item(coap_tree, hf_coap_code, tvb, offset, 1, ENC_BIG_ENDIAN);
|
2010-10-17 11:48:40 +00:00
|
|
|
code = tvb_get_guint8(tvb, offset);
|
|
|
|
offset += 1;
|
|
|
|
|
2013-06-11 05:23:52 +00:00
|
|
|
proto_tree_add_item(coap_tree, hf_coap_mid, tvb, offset, 2, ENC_BIG_ENDIAN);
|
|
|
|
mid = tvb_get_ntohs(tvb, offset);
|
2010-10-17 11:48:40 +00:00
|
|
|
offset += 2;
|
|
|
|
|
|
|
|
/* append the header information */
|
2013-06-11 05:23:52 +00:00
|
|
|
proto_item_append_text(coap_tree, ", %s, %s, MID:%u", val_to_str(ttype, vals_ttype, "Unkown %d"), val_to_str(code, vals_code, "Unknown %d"), mid);
|
2010-10-17 11:48:40 +00:00
|
|
|
|
2011-08-10 20:54:44 +00:00
|
|
|
/* initialize the external value */
|
2013-03-22 00:12:44 +00:00
|
|
|
coap_block_number = DEFAULT_COAP_BLOCK_NUMBER;
|
|
|
|
coap_block_mflag = 0;
|
|
|
|
coap_uri_str[0] = '\0';
|
|
|
|
coap_uri_query[0] = '\0';
|
|
|
|
coap_token_str[0] = '\0';
|
|
|
|
|
2013-06-11 05:20:33 +00:00
|
|
|
if (token_len > 0)
|
|
|
|
{
|
|
|
|
g_strlcat(coap_token_str, tvb_bytes_to_str_punct(tvb, offset, token_len, ' '), sizeof(coap_token_str));
|
|
|
|
proto_tree_add_item(coap_tree, hf_coap_token,
|
|
|
|
tvb, offset, token_len, ENC_NA);
|
|
|
|
offset += token_len;
|
|
|
|
}
|
|
|
|
|
2013-03-22 00:12:44 +00:00
|
|
|
/* process options */
|
2013-06-11 05:27:47 +00:00
|
|
|
offset = dissect_coap_options(tvb, pinfo, coap_tree, offset, coap_length);
|
2013-03-22 00:12:44 +00:00
|
|
|
if (offset == -1)
|
|
|
|
return;
|
2010-11-15 18:01:19 +00:00
|
|
|
|
2013-03-22 00:12:44 +00:00
|
|
|
/* add informations to the packet list */
|
|
|
|
col_set_str(pinfo->cinfo, COL_PROTOCOL, "CoAP");
|
|
|
|
col_clear(pinfo->cinfo, COL_INFO);
|
|
|
|
col_add_fstr(pinfo->cinfo, COL_INFO, "%s", val_to_str(ttype, vals_ttype_short, "Unknown %d"));
|
2013-06-11 05:23:52 +00:00
|
|
|
col_append_fstr(pinfo->cinfo, COL_INFO, ", MID:%u", mid);
|
2013-03-22 00:12:44 +00:00
|
|
|
col_append_fstr(pinfo->cinfo, COL_INFO, ", %s", val_to_str(code, vals_code, "Unknown %d"));
|
|
|
|
if (coap_token_str[0] != '\0')
|
|
|
|
col_append_fstr(pinfo->cinfo, COL_INFO, ", TKN:%s", coap_token_str);
|
|
|
|
if (coap_block_number != DEFAULT_COAP_BLOCK_NUMBER)
|
|
|
|
col_append_fstr(pinfo->cinfo, COL_INFO, ", %sBlock #%d", coap_block_mflag ? "" : "End of ", coap_block_number);
|
|
|
|
if (coap_uri_str[0] != '\0')
|
|
|
|
col_append_fstr(pinfo->cinfo, COL_INFO, ", %s", coap_uri_str);
|
|
|
|
if (coap_uri_query[0] != '\0')
|
|
|
|
col_append_fstr(pinfo->cinfo, COL_INFO, "%s", coap_uri_query);
|
2010-10-17 11:48:40 +00:00
|
|
|
|
|
|
|
/* dissect the payload */
|
|
|
|
if (coap_length > offset) {
|
|
|
|
proto_tree *payload_tree = NULL;
|
|
|
|
proto_item *payload_item = NULL;
|
|
|
|
tvbuff_t *payload_tvb;
|
|
|
|
guint payload_length = coap_length - offset;
|
2013-06-11 05:37:17 +00:00
|
|
|
const char *coap_ctype_str_dis;
|
2013-03-22 00:12:44 +00:00
|
|
|
char str_payload[80];
|
2010-10-17 11:48:40 +00:00
|
|
|
|
|
|
|
/*
|
2013-03-22 00:12:44 +00:00
|
|
|
* 5.5.2. Diagnostic Payload
|
|
|
|
*
|
|
|
|
* If no Content-Format option is given, the payload of responses
|
|
|
|
* indicating a client or server error is a brief human-readable
|
|
|
|
* diagnostic message, explaining the error situation. This diagnostic
|
|
|
|
* message MUST be encoded using UTF-8 [RFC3629], more specifically
|
|
|
|
* using Net-Unicode form [RFC5198].
|
2010-10-17 11:48:40 +00:00
|
|
|
*/
|
2013-03-22 00:12:44 +00:00
|
|
|
if (coap_ctype_value == DEFAULT_COAP_CTYPE_VALUE)
|
|
|
|
coap_ctype_str = "text/plain; charset=utf-8";
|
|
|
|
|
|
|
|
g_snprintf(str_payload, sizeof(str_payload),
|
2013-06-11 05:37:17 +00:00
|
|
|
"Payload Content-Format: %s%s, Length: %u",
|
2013-03-22 00:12:44 +00:00
|
|
|
coap_ctype_str, coap_ctype_value == DEFAULT_COAP_CTYPE_VALUE ?
|
2013-06-11 05:37:17 +00:00
|
|
|
" (no Content-Format)" : "", payload_length);
|
|
|
|
|
|
|
|
payload_item = proto_tree_add_string(coap_tree, hf_coap_payload,
|
|
|
|
tvb, offset, payload_length,
|
|
|
|
str_payload);
|
2010-10-17 11:48:40 +00:00
|
|
|
payload_tree = proto_item_add_subtree(payload_item, ett_coap_payload);
|
2013-06-11 05:37:17 +00:00
|
|
|
|
|
|
|
proto_tree_add_string(payload_tree, hf_coap_payload_desc, tvb, offset, -1, coap_ctype_str);
|
2010-10-17 11:48:40 +00:00
|
|
|
payload_tvb = tvb_new_subset(tvb, offset, payload_length, payload_length);
|
|
|
|
|
2013-06-11 05:37:17 +00:00
|
|
|
if (coap_ctype_value == DEFAULT_COAP_CTYPE_VALUE || coap_ctype_value == 0) {
|
|
|
|
coap_ctype_str_dis = "text/plain";
|
|
|
|
} else {
|
|
|
|
coap_ctype_str_dis = coap_ctype_str;
|
|
|
|
}
|
|
|
|
|
|
|
|
dissector_try_string(media_type_dissector_table, coap_ctype_str_dis,
|
|
|
|
payload_tvb, pinfo, payload_tree);
|
2010-10-17 11:48:40 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Protocol initialization
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
proto_register_coap(void)
|
|
|
|
{
|
|
|
|
static hf_register_info hf[] = {
|
2012-07-11 20:40:13 +00:00
|
|
|
{ &hf_coap_version,
|
|
|
|
{ "Version", "coap.version",
|
|
|
|
FT_UINT8, BASE_DEC, NULL, 0xc0,
|
2013-06-11 05:41:51 +00:00
|
|
|
NULL, HFILL }
|
2012-07-11 20:40:13 +00:00
|
|
|
},
|
|
|
|
{ &hf_coap_ttype,
|
|
|
|
{ "Type", "coap.type",
|
|
|
|
FT_UINT8, BASE_DEC, VALS(vals_ttype), 0x30,
|
2013-06-11 05:41:51 +00:00
|
|
|
NULL, HFILL }
|
2012-07-11 20:40:13 +00:00
|
|
|
},
|
2013-06-11 05:20:33 +00:00
|
|
|
{ &hf_coap_token_len,
|
|
|
|
{ "Token Length", "coap.token_len",
|
2012-07-11 20:40:13 +00:00
|
|
|
FT_UINT8, BASE_DEC, NULL, 0x0f,
|
2013-06-11 05:41:51 +00:00
|
|
|
NULL, HFILL }
|
2013-06-11 05:20:33 +00:00
|
|
|
},
|
|
|
|
{ &hf_coap_token,
|
|
|
|
{ "Token", "coap.token",
|
|
|
|
FT_BYTES, BASE_NONE, NULL, 0x0,
|
2013-06-11 05:41:51 +00:00
|
|
|
NULL, HFILL }
|
2012-07-11 20:40:13 +00:00
|
|
|
},
|
|
|
|
{ &hf_coap_code,
|
|
|
|
{ "Code", "coap.code",
|
|
|
|
FT_UINT8, BASE_DEC, VALS(vals_code), 0x0,
|
2013-06-11 05:41:51 +00:00
|
|
|
NULL, HFILL }
|
2012-07-11 20:40:13 +00:00
|
|
|
},
|
2013-06-11 05:23:52 +00:00
|
|
|
{ &hf_coap_mid,
|
|
|
|
{ "Message ID", "coap.mid",
|
2012-07-11 20:40:13 +00:00
|
|
|
FT_UINT16, BASE_DEC, NULL, 0x0,
|
2013-06-11 05:41:51 +00:00
|
|
|
NULL, HFILL }
|
2013-03-22 00:12:44 +00:00
|
|
|
},
|
2013-06-11 05:37:17 +00:00
|
|
|
{ &hf_coap_payload,
|
|
|
|
{ "Payload", "coap.payload",
|
|
|
|
FT_STRING, BASE_NONE, NULL, 0x0,
|
2013-06-11 05:41:51 +00:00
|
|
|
NULL, HFILL }
|
2013-06-11 05:37:17 +00:00
|
|
|
},
|
2013-03-22 00:12:44 +00:00
|
|
|
{ &hf_coap_payload_desc,
|
|
|
|
{ "Payload Desc", "coap.opt.payload_desc",
|
|
|
|
FT_STRING, BASE_NONE, NULL, 0x0,
|
2013-06-11 05:41:51 +00:00
|
|
|
NULL, HFILL }
|
2013-03-22 00:12:44 +00:00
|
|
|
},
|
|
|
|
{ &hf_coap_opt_name,
|
|
|
|
{ "Opt Name", "coap.opt.name",
|
|
|
|
FT_STRING, BASE_NONE, NULL, 0x0,
|
2013-06-11 05:41:51 +00:00
|
|
|
NULL, HFILL }
|
2013-03-22 00:12:44 +00:00
|
|
|
},
|
|
|
|
{ &hf_coap_opt_desc,
|
|
|
|
{ "Opt Desc", "coap.opt.desc",
|
|
|
|
FT_STRING, BASE_NONE, NULL, 0x0,
|
2013-06-11 05:41:51 +00:00
|
|
|
NULL, HFILL }
|
2013-03-22 00:12:44 +00:00
|
|
|
},
|
2012-07-11 20:40:13 +00:00
|
|
|
{ &hf_coap_opt_delta,
|
2013-03-22 00:12:44 +00:00
|
|
|
{ "Opt Delta", "coap.opt.delta",
|
2012-07-11 20:40:13 +00:00
|
|
|
FT_UINT8, BASE_DEC, NULL, 0xf0,
|
2013-06-11 05:41:51 +00:00
|
|
|
NULL, HFILL }
|
2012-07-11 20:40:13 +00:00
|
|
|
},
|
2013-06-11 05:31:10 +00:00
|
|
|
{ &hf_coap_opt_delta_ext,
|
|
|
|
{ "Opt Delta extended", "coap.opt.delta_ext",
|
|
|
|
FT_UINT16, BASE_DEC, NULL, 0x0,
|
2013-06-11 05:41:51 +00:00
|
|
|
NULL, HFILL }
|
2013-06-11 05:31:10 +00:00
|
|
|
},
|
2012-07-11 20:40:13 +00:00
|
|
|
{ &hf_coap_opt_length,
|
2013-03-22 00:12:44 +00:00
|
|
|
{ "Opt Length", "coap.opt.length",
|
2013-06-11 05:31:10 +00:00
|
|
|
FT_UINT8, BASE_DEC, NULL, 0x0f,
|
2013-03-22 00:12:44 +00:00
|
|
|
"CoAP Option Length", HFILL }
|
2012-07-11 20:40:13 +00:00
|
|
|
},
|
2013-06-11 05:31:10 +00:00
|
|
|
{ &hf_coap_opt_length_ext,
|
|
|
|
{ "Opt Length extended", "coap.opt.length_ext",
|
|
|
|
FT_UINT16, BASE_DEC, NULL, 0x0,
|
2013-06-11 05:41:51 +00:00
|
|
|
NULL, HFILL }
|
2013-06-11 05:31:10 +00:00
|
|
|
},
|
|
|
|
{ &hf_coap_opt_end_marker,
|
|
|
|
{ "End of options marker", "coap.opt.end_marker",
|
|
|
|
FT_UINT8, BASE_DEC, NULL, 0x00,
|
2013-06-11 05:41:51 +00:00
|
|
|
NULL, HFILL }
|
2013-06-11 05:31:10 +00:00
|
|
|
},
|
2012-07-11 20:40:13 +00:00
|
|
|
{ &hf_coap_opt_ctype,
|
|
|
|
{ "Content-type", "coap.opt.ctype",
|
2013-03-22 00:12:44 +00:00
|
|
|
FT_STRING, BASE_NONE, NULL, 0x0,
|
2013-06-11 05:41:51 +00:00
|
|
|
NULL, HFILL }
|
2012-07-11 20:40:13 +00:00
|
|
|
},
|
|
|
|
{ &hf_coap_opt_max_age,
|
|
|
|
{ "Max-age", "coap.opt.max_age",
|
|
|
|
FT_UINT32, BASE_DEC, NULL, 0x0,
|
2013-06-11 05:41:51 +00:00
|
|
|
NULL, HFILL }
|
2012-07-11 20:40:13 +00:00
|
|
|
},
|
|
|
|
{ &hf_coap_opt_proxy_uri,
|
|
|
|
{ "Proxy-Uri", "coap.opt.proxy_uri",
|
|
|
|
FT_STRING, BASE_NONE, NULL, 0x0,
|
2013-06-11 05:41:51 +00:00
|
|
|
NULL, HFILL }
|
2012-07-11 20:40:13 +00:00
|
|
|
},
|
|
|
|
{ &hf_coap_opt_etag,
|
|
|
|
{ "Etag", "coap.opt.etag",
|
|
|
|
FT_BYTES, BASE_NONE, NULL, 0x0,
|
2013-03-22 00:12:44 +00:00
|
|
|
"CoAP Option Etag", HFILL }
|
2012-07-11 20:40:13 +00:00
|
|
|
},
|
|
|
|
{ &hf_coap_opt_uri_host,
|
|
|
|
{ "Uri-Host", "coap.opt.uri_host",
|
|
|
|
FT_STRING, BASE_NONE, NULL, 0x0,
|
2013-06-11 05:41:51 +00:00
|
|
|
NULL, HFILL }
|
2012-07-11 20:40:13 +00:00
|
|
|
},
|
|
|
|
{ &hf_coap_opt_location_path,
|
|
|
|
{ "Location-Path", "coap.opt.location_path",
|
|
|
|
FT_STRING, BASE_NONE, NULL, 0x0,
|
2013-06-11 05:41:51 +00:00
|
|
|
NULL, HFILL }
|
2012-07-11 20:40:13 +00:00
|
|
|
},
|
|
|
|
{ &hf_coap_opt_uri_port,
|
|
|
|
{ "Uri-Port", "coap.opt.uri_port",
|
|
|
|
FT_UINT16, BASE_DEC, NULL, 0x0,
|
2013-06-11 05:41:51 +00:00
|
|
|
NULL, HFILL }
|
2012-07-11 20:40:13 +00:00
|
|
|
},
|
|
|
|
{ &hf_coap_opt_location_query,
|
|
|
|
{ "Location-Query", "coap.opt.location_query",
|
|
|
|
FT_STRING, BASE_NONE, NULL, 0x0,
|
2013-06-11 05:41:51 +00:00
|
|
|
NULL, HFILL }
|
2012-07-11 20:40:13 +00:00
|
|
|
},
|
|
|
|
{ &hf_coap_opt_uri_path,
|
|
|
|
{ "Uri-Path", "coap.opt.uri_path",
|
|
|
|
FT_STRING, BASE_NONE, NULL, 0x0,
|
2013-06-11 05:41:51 +00:00
|
|
|
NULL, HFILL }
|
2012-07-11 20:40:13 +00:00
|
|
|
},
|
|
|
|
{ &hf_coap_opt_observe,
|
|
|
|
{ "Lifetime", "coap.opt.subscr_lifetime",
|
2013-06-11 05:31:10 +00:00
|
|
|
FT_UINT32, BASE_DEC, NULL, 0x0,
|
2013-06-11 05:41:51 +00:00
|
|
|
NULL, HFILL }
|
2012-07-11 20:40:13 +00:00
|
|
|
},
|
|
|
|
{ &hf_coap_opt_accept,
|
|
|
|
{ "Accept", "coap.opt.accept",
|
2013-03-22 00:12:44 +00:00
|
|
|
FT_STRING, BASE_NONE, NULL, 0x0,
|
2013-06-11 05:41:51 +00:00
|
|
|
NULL, HFILL }
|
2012-07-11 20:40:13 +00:00
|
|
|
},
|
|
|
|
{ &hf_coap_opt_if_match,
|
|
|
|
{ "If-Match", "coap.opt.if_match",
|
|
|
|
FT_BYTES, BASE_NONE, NULL, 0x0,
|
2013-06-11 05:41:51 +00:00
|
|
|
NULL, HFILL }
|
2012-07-11 20:40:13 +00:00
|
|
|
},
|
|
|
|
{ &hf_coap_opt_block_number,
|
|
|
|
{ "Block Number", "coap.opt.block_number",
|
2013-03-22 00:12:44 +00:00
|
|
|
FT_UINT32, BASE_DEC, NULL, 0x0,
|
2013-06-11 05:41:51 +00:00
|
|
|
NULL, HFILL }
|
2012-07-11 20:40:13 +00:00
|
|
|
},
|
|
|
|
{ &hf_coap_opt_block_mflag,
|
|
|
|
{ "More Flag", "coap.opt.block_mflag",
|
|
|
|
FT_UINT8, BASE_DEC, NULL, 0x08,
|
2013-06-11 05:41:51 +00:00
|
|
|
NULL, HFILL }
|
2012-07-11 20:40:13 +00:00
|
|
|
},
|
|
|
|
{ &hf_coap_opt_block_size,
|
|
|
|
{ "Encoded Block Size", "coap.opt.block_size",
|
|
|
|
FT_UINT8, BASE_DEC, NULL, 0x07,
|
2013-06-11 05:41:51 +00:00
|
|
|
NULL, HFILL }
|
2012-07-11 20:40:13 +00:00
|
|
|
},
|
|
|
|
{ &hf_coap_opt_uri_query,
|
|
|
|
{ "Uri-Query", "coap.opt.uri_query",
|
|
|
|
FT_STRING, BASE_NONE, NULL, 0x0,
|
2013-06-11 05:41:51 +00:00
|
|
|
NULL, HFILL }
|
2012-07-11 20:40:13 +00:00
|
|
|
},
|
2013-03-22 00:12:44 +00:00
|
|
|
{ &hf_coap_opt_unknown,
|
|
|
|
{ "Unknown", "coap.opt.unknown",
|
2013-06-11 05:34:33 +00:00
|
|
|
FT_BYTES, BASE_NONE, NULL, 0x0,
|
2013-06-11 05:41:51 +00:00
|
|
|
NULL, HFILL }
|
2012-07-11 20:40:13 +00:00
|
|
|
},
|
2010-10-17 11:48:40 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
static gint *ett[] = {
|
|
|
|
&ett_coap,
|
2010-10-21 22:41:39 +00:00
|
|
|
&ett_coap_option,
|
2010-10-17 11:48:40 +00:00
|
|
|
&ett_coap_payload,
|
|
|
|
};
|
|
|
|
|
|
|
|
module_t *coap_module;
|
|
|
|
|
2013-03-22 00:12:44 +00:00
|
|
|
proto_coap = proto_register_protocol("Constrained Application Protocol", "CoAP", "coap");
|
2010-10-17 11:48:40 +00:00
|
|
|
proto_register_field_array(proto_coap, hf, array_length(hf));
|
|
|
|
proto_register_subtree_array(ett, array_length(ett));
|
|
|
|
|
|
|
|
register_dissector("coap", dissect_coap, proto_coap);
|
|
|
|
|
|
|
|
/* Register our configuration options */
|
|
|
|
coap_module = prefs_register_protocol (proto_coap, proto_reg_handoff_coap);
|
|
|
|
|
|
|
|
prefs_register_uint_preference (coap_module, "udp_port",
|
2013-03-22 00:12:44 +00:00
|
|
|
"CoAP port number",
|
|
|
|
"Port number used for CoAP traffic",
|
2011-08-10 20:54:44 +00:00
|
|
|
10, &global_coap_port_number);
|
2010-10-17 11:48:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
proto_reg_handoff_coap(void)
|
|
|
|
{
|
2010-10-19 13:30:40 +00:00
|
|
|
static gboolean coap_prefs_initialized = FALSE;
|
2010-10-17 12:20:25 +00:00
|
|
|
static dissector_handle_t coap_handle;
|
2010-10-21 03:04:15 +00:00
|
|
|
static guint coap_port_number;
|
2010-10-17 11:48:40 +00:00
|
|
|
|
|
|
|
if (!coap_prefs_initialized) {
|
|
|
|
coap_handle = find_dissector("coap");
|
|
|
|
media_type_dissector_table = find_dissector_table("media_type");
|
|
|
|
coap_prefs_initialized = TRUE;
|
|
|
|
} else {
|
2010-12-20 05:35:29 +00:00
|
|
|
dissector_delete_uint("udp.port", coap_port_number, coap_handle);
|
|
|
|
dissector_delete_uint("tcp.port", coap_port_number, coap_handle);
|
2010-10-17 11:48:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
coap_port_number = global_coap_port_number;
|
2010-12-20 05:35:29 +00:00
|
|
|
dissector_add_uint("udp.port", coap_port_number, coap_handle);
|
|
|
|
dissector_add_uint("tcp.port", coap_port_number, coap_handle);
|
2010-10-17 11:48:40 +00:00
|
|
|
}
|