static const int HAS_FRACTIONAL_SECS = 1 << 3;
static const int HAS_TRAILER = 1 << 4;
-#include "expanded_header_cw_tables.h"
-
static int
compute_codeword(const expanded_header &h)
{
const uint32_t **payload, // out
size_t *n32_bit_words_payload) // out
{
+ size_t n32_bit_words_header = 0;
+ size_t n32_bit_words_trailer = 0;
size_t len = n32_bit_words_packet;
const uint32_t *p = packet;
len = h->pkt_size(); // valid length of packet
int cw = compute_codeword(*h);
- if (cw_header_len(cw) + cw_trailer_len(cw) > len)
- return false; // negative payload len
-
- *payload = p + cw_header_len(cw);
- *n32_bit_words_payload = len - (cw_header_len(cw) + cw_trailer_len(cw));
-
- // printf("parse: hdr = 0x%08x, cw = 0x%02x, cw_header_len(cw) = %d, cw_trailer_len(cw) = %d\n",
- // h->header, cw, cw_header_len(cw), cw_trailer_len(cw));
-
switch (cw & 0x1f){
#include "expanded_header_parse_switch_body.h"
}
+ if (n32_bit_words_header + n32_bit_words_trailer > len)
+ return false; // negative payload len
+
+ *payload = p + n32_bit_words_header;
+ *n32_bit_words_payload = len - (n32_bit_words_header + n32_bit_words_trailer);
+
+ // printf("parse: hdr = 0x%08x, cw = 0x%02x, n32_bit_words_header = %d, n32_bit_words_trailer = %d\n",
+ // h->header, cw, n32_bit_words_header, n32_bit_words_trailer);
+
return true;
}
+++ /dev/null
-inline static size_t cw_header_len(int cw){
- static const size_t s_cw_header_len[32] = {
- 1, 2, 3, 4, 2, 3, 4, 5, 3, 4, 5, 6, 4, 5, 6, 7, 1, 2, 3, 4, 2, 3, 4, 5, 3, 4, 5, 6, 4, 5, 6, 7,
- };
- return s_cw_header_len[cw];
-}
-
-inline static size_t cw_trailer_len(int cw){
- static const size_t s_cw_trailer_len[32] = {
- 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
- };
- return s_cw_trailer_len[cw];
-}
-
h->class_id = 0;
h->integer_secs = 0;
h->fractional_secs = 0;
+ n32_bit_words_header = 1;
h->trailer = 0;
+ n32_bit_words_trailer = 0;
break;
case 1:
h->class_id = 0;
h->integer_secs = 0;
h->fractional_secs = 0;
+ n32_bit_words_header = 2;
h->trailer = 0;
+ n32_bit_words_trailer = 0;
break;
case 2:
h->class_id = ((uint64_t)(ntohl(p[1])) << 32) | ntohl(p[2]);
h->integer_secs = 0;
h->fractional_secs = 0;
+ n32_bit_words_header = 3;
h->trailer = 0;
+ n32_bit_words_trailer = 0;
break;
case 3:
h->class_id = ((uint64_t)(ntohl(p[2])) << 32) | ntohl(p[3]);
h->integer_secs = 0;
h->fractional_secs = 0;
+ n32_bit_words_header = 4;
h->trailer = 0;
+ n32_bit_words_trailer = 0;
break;
case 4:
h->class_id = 0;
h->integer_secs = ntohl(p[1]);
h->fractional_secs = 0;
+ n32_bit_words_header = 2;
h->trailer = 0;
+ n32_bit_words_trailer = 0;
break;
case 5:
h->class_id = 0;
h->integer_secs = ntohl(p[2]);
h->fractional_secs = 0;
+ n32_bit_words_header = 3;
h->trailer = 0;
+ n32_bit_words_trailer = 0;
break;
case 6:
h->class_id = ((uint64_t)(ntohl(p[1])) << 32) | ntohl(p[2]);
h->integer_secs = ntohl(p[3]);
h->fractional_secs = 0;
+ n32_bit_words_header = 4;
h->trailer = 0;
+ n32_bit_words_trailer = 0;
break;
case 7:
h->class_id = ((uint64_t)(ntohl(p[2])) << 32) | ntohl(p[3]);
h->integer_secs = ntohl(p[4]);
h->fractional_secs = 0;
+ n32_bit_words_header = 5;
h->trailer = 0;
+ n32_bit_words_trailer = 0;
break;
case 8:
h->class_id = 0;
h->integer_secs = 0;
h->fractional_secs = ((uint64_t)(ntohl(p[1])) << 32) | ntohl(p[2]);
+ n32_bit_words_header = 3;
h->trailer = 0;
+ n32_bit_words_trailer = 0;
break;
case 9:
h->class_id = 0;
h->integer_secs = 0;
h->fractional_secs = ((uint64_t)(ntohl(p[2])) << 32) | ntohl(p[3]);
+ n32_bit_words_header = 4;
h->trailer = 0;
+ n32_bit_words_trailer = 0;
break;
case 10:
h->class_id = ((uint64_t)(ntohl(p[1])) << 32) | ntohl(p[2]);
h->integer_secs = 0;
h->fractional_secs = ((uint64_t)(ntohl(p[3])) << 32) | ntohl(p[4]);
+ n32_bit_words_header = 5;
h->trailer = 0;
+ n32_bit_words_trailer = 0;
break;
case 11:
h->class_id = ((uint64_t)(ntohl(p[2])) << 32) | ntohl(p[3]);
h->integer_secs = 0;
h->fractional_secs = ((uint64_t)(ntohl(p[4])) << 32) | ntohl(p[5]);
+ n32_bit_words_header = 6;
h->trailer = 0;
+ n32_bit_words_trailer = 0;
break;
case 12:
h->class_id = 0;
h->integer_secs = ntohl(p[1]);
h->fractional_secs = ((uint64_t)(ntohl(p[2])) << 32) | ntohl(p[3]);
+ n32_bit_words_header = 4;
h->trailer = 0;
+ n32_bit_words_trailer = 0;
break;
case 13:
h->class_id = 0;
h->integer_secs = ntohl(p[2]);
h->fractional_secs = ((uint64_t)(ntohl(p[3])) << 32) | ntohl(p[4]);
+ n32_bit_words_header = 5;
h->trailer = 0;
+ n32_bit_words_trailer = 0;
break;
case 14:
h->class_id = ((uint64_t)(ntohl(p[1])) << 32) | ntohl(p[2]);
h->integer_secs = ntohl(p[3]);
h->fractional_secs = ((uint64_t)(ntohl(p[4])) << 32) | ntohl(p[5]);
+ n32_bit_words_header = 6;
h->trailer = 0;
+ n32_bit_words_trailer = 0;
break;
case 15:
h->class_id = ((uint64_t)(ntohl(p[2])) << 32) | ntohl(p[3]);
h->integer_secs = ntohl(p[4]);
h->fractional_secs = ((uint64_t)(ntohl(p[5])) << 32) | ntohl(p[6]);
+ n32_bit_words_header = 7;
h->trailer = 0;
+ n32_bit_words_trailer = 0;
break;
case 16:
h->class_id = 0;
h->integer_secs = 0;
h->fractional_secs = 0;
+ n32_bit_words_header = 1;
h->trailer = ntohl(p[len-1]);
+ n32_bit_words_trailer = 1;
break;
case 17:
h->class_id = 0;
h->integer_secs = 0;
h->fractional_secs = 0;
+ n32_bit_words_header = 2;
h->trailer = ntohl(p[len-1]);
+ n32_bit_words_trailer = 1;
break;
case 18:
h->class_id = ((uint64_t)(ntohl(p[1])) << 32) | ntohl(p[2]);
h->integer_secs = 0;
h->fractional_secs = 0;
+ n32_bit_words_header = 3;
h->trailer = ntohl(p[len-1]);
+ n32_bit_words_trailer = 1;
break;
case 19:
h->class_id = ((uint64_t)(ntohl(p[2])) << 32) | ntohl(p[3]);
h->integer_secs = 0;
h->fractional_secs = 0;
+ n32_bit_words_header = 4;
h->trailer = ntohl(p[len-1]);
+ n32_bit_words_trailer = 1;
break;
case 20:
h->class_id = 0;
h->integer_secs = ntohl(p[1]);
h->fractional_secs = 0;
+ n32_bit_words_header = 2;
h->trailer = ntohl(p[len-1]);
+ n32_bit_words_trailer = 1;
break;
case 21:
h->class_id = 0;
h->integer_secs = ntohl(p[2]);
h->fractional_secs = 0;
+ n32_bit_words_header = 3;
h->trailer = ntohl(p[len-1]);
+ n32_bit_words_trailer = 1;
break;
case 22:
h->class_id = ((uint64_t)(ntohl(p[1])) << 32) | ntohl(p[2]);
h->integer_secs = ntohl(p[3]);
h->fractional_secs = 0;
+ n32_bit_words_header = 4;
h->trailer = ntohl(p[len-1]);
+ n32_bit_words_trailer = 1;
break;
case 23:
h->class_id = ((uint64_t)(ntohl(p[2])) << 32) | ntohl(p[3]);
h->integer_secs = ntohl(p[4]);
h->fractional_secs = 0;
+ n32_bit_words_header = 5;
h->trailer = ntohl(p[len-1]);
+ n32_bit_words_trailer = 1;
break;
case 24:
h->class_id = 0;
h->integer_secs = 0;
h->fractional_secs = ((uint64_t)(ntohl(p[1])) << 32) | ntohl(p[2]);
+ n32_bit_words_header = 3;
h->trailer = ntohl(p[len-1]);
+ n32_bit_words_trailer = 1;
break;
case 25:
h->class_id = 0;
h->integer_secs = 0;
h->fractional_secs = ((uint64_t)(ntohl(p[2])) << 32) | ntohl(p[3]);
+ n32_bit_words_header = 4;
h->trailer = ntohl(p[len-1]);
+ n32_bit_words_trailer = 1;
break;
case 26:
h->class_id = ((uint64_t)(ntohl(p[1])) << 32) | ntohl(p[2]);
h->integer_secs = 0;
h->fractional_secs = ((uint64_t)(ntohl(p[3])) << 32) | ntohl(p[4]);
+ n32_bit_words_header = 5;
h->trailer = ntohl(p[len-1]);
+ n32_bit_words_trailer = 1;
break;
case 27:
h->class_id = ((uint64_t)(ntohl(p[2])) << 32) | ntohl(p[3]);
h->integer_secs = 0;
h->fractional_secs = ((uint64_t)(ntohl(p[4])) << 32) | ntohl(p[5]);
+ n32_bit_words_header = 6;
h->trailer = ntohl(p[len-1]);
+ n32_bit_words_trailer = 1;
break;
case 28:
h->class_id = 0;
h->integer_secs = ntohl(p[1]);
h->fractional_secs = ((uint64_t)(ntohl(p[2])) << 32) | ntohl(p[3]);
+ n32_bit_words_header = 4;
h->trailer = ntohl(p[len-1]);
+ n32_bit_words_trailer = 1;
break;
case 29:
h->class_id = 0;
h->integer_secs = ntohl(p[2]);
h->fractional_secs = ((uint64_t)(ntohl(p[3])) << 32) | ntohl(p[4]);
+ n32_bit_words_header = 5;
h->trailer = ntohl(p[len-1]);
+ n32_bit_words_trailer = 1;
break;
case 30:
h->class_id = ((uint64_t)(ntohl(p[1])) << 32) | ntohl(p[2]);
h->integer_secs = ntohl(p[3]);
h->fractional_secs = ((uint64_t)(ntohl(p[4])) << 32) | ntohl(p[5]);
+ n32_bit_words_header = 6;
h->trailer = ntohl(p[len-1]);
+ n32_bit_words_trailer = 1;
break;
case 31:
h->class_id = ((uint64_t)(ntohl(p[2])) << 32) | ntohl(p[3]);
h->integer_secs = ntohl(p[4]);
h->fractional_secs = ((uint64_t)(ntohl(p[5])) << 32) | ntohl(p[6]);
+ n32_bit_words_header = 7;
h->trailer = ntohl(p[len-1]);
+ n32_bit_words_trailer = 1;
break;
+++ /dev/null
-#!/usr/bin/env python
-#
-# Copyright 2009 Free Software Foundation, Inc.
-#
-# This file is part of GNU Radio
-#
-# GNU Radio 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 3, or (at your option)
-# any later version.
-#
-# GNU Radio 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 Foundation, Inc.,
-# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
-#
-
-import sys
-
-# dispatch codeword bits
-HAS_STREAM_ID = 1 << 0;
-HAS_CLASS_ID = 1 << 1;
-HAS_INTEGER_SECS = 1 << 2;
-HAS_FRACTIONAL_SECS = 1 << 3;
-HAS_TRAILER = 1 << 4;
-
-def main():
- f = sys.stdout
- header_len = 32 * [0]
- trailer_len = 32 * [0]
-
- for cw in range(32):
- t = 0
- if cw & HAS_TRAILER: t += 1
- trailer_len[cw] = t
-
- t = 1
- if cw & HAS_STREAM_ID: t += 1
- if cw & HAS_CLASS_ID: t += 2
- if cw & HAS_INTEGER_SECS: t += 1
- if cw & HAS_FRACTIONAL_SECS: t += 2
- header_len[cw] = t
-
- write_table(f, "cw_header_len", header_len)
- write_table(f, "cw_trailer_len", trailer_len)
-
-def write_table(f, name, table):
- f.write("inline static size_t ")
- f.write(name)
- f.write("(int cw){\n")
-
- f.write(" static const size_t s_")
- f.write(name)
- f.write("[32] = {\n ")
- for t in table:
- f.write("%d, " % (t,))
- f.write("\n };\n")
-
- f.write(" return s_")
- f.write(name)
- f.write("[cw];\n}\n\n")
-
-
-if __name__ == '__main__':
- main()