Harald Welte | 615bd54 | 2017-07-14 18:28:55 +0200 | [diff] [blame] | 1 | module Osmocom_Types { |
Harald Welte | c7adaa7 | 2018-02-15 20:40:36 +0100 | [diff] [blame] | 2 | |
| 3 | import from General_Types all; |
| 4 | |
Harald Welte | ddeaa57 | 2017-07-14 18:58:07 +0200 | [diff] [blame] | 5 | type integer uint8_t (0..255) with { variant "unsigned 8 bit" }; |
Harald Welte | 615bd54 | 2017-07-14 18:28:55 +0200 | [diff] [blame] | 6 | type integer uint16_t (0..65535) with { variant "unsigned 16 bit" }; |
Harald Welte | 484160b | 2017-07-28 13:30:24 +0200 | [diff] [blame] | 7 | type integer uint24_t (0..16777215) with { variant "unsigned 24 bit" }; |
Harald Welte | ddeaa57 | 2017-07-14 18:58:07 +0200 | [diff] [blame] | 8 | type integer uint32_t (0..4294967295) with { variant "unsigned 32 bit" }; |
| 9 | |
| 10 | type integer int8_t (-128..127) with { variant "8 bit" }; |
| 11 | type integer int16_t (-32768..32767) with { variant "16 bit" }; |
| 12 | |
Harald Welte | f654332 | 2017-07-16 07:35:10 +0200 | [diff] [blame] | 13 | type integer uint1_t (0..1) with { variant "unsigned 1 bit" }; |
Harald Welte | 615bd54 | 2017-07-14 18:28:55 +0200 | [diff] [blame] | 14 | type integer uint2_t (0..3) with { variant "unsigned 2 bit" }; |
| 15 | type integer uint3_t (0..7) with { variant "unsigned 3 bit" }; |
| 16 | type integer uint4_t (0..15) with { variant "unsigned 4 bit" }; |
| 17 | type integer uint5_t (0..31) with { variant "unsigned 5 bit" }; |
| 18 | type integer uint6_t (0..63) with { variant "unsigned 6 bit" }; |
| 19 | type integer uint7_t (0..127) with { variant "unsigned 7 bit" }; |
Harald Welte | 615bd54 | 2017-07-14 18:28:55 +0200 | [diff] [blame] | 20 | type integer uint9_t (0..511) with { variant "unsigned 9 bit" }; |
| 21 | type integer uint10_t (0..1023) with { variant "unsigned 10 bit" }; |
| 22 | type integer uint11_t (0..2047) with { variant "unsigned 11 bit" }; |
| 23 | type integer uint12_t (0..4095) with { variant "unsigned 12 bit" }; |
Harald Welte | ddeaa57 | 2017-07-14 18:58:07 +0200 | [diff] [blame] | 24 | type integer uint13_t (0..8191) with { variant "unsigned 13 bit" }; |
| 25 | type integer uint14_t (0..16383) with { variant "unsigned 14 bit" }; |
| 26 | type integer uint15_t (0..32767) with { variant "unsigned 15 bit" }; |
| 27 | |
Harald Welte | 0236980 | 2018-02-25 12:39:05 +0100 | [diff] [blame] | 28 | |
| 29 | const uint16_t c_UINT16_MAX := 65535; |
| 30 | const uint32_t c_UINT32_MAX := 4294967295; |
| 31 | |
Harald Welte | ddeaa57 | 2017-07-14 18:58:07 +0200 | [diff] [blame] | 32 | type record Arfcn { |
| 33 | boolean pcs, |
| 34 | uint15_t arfcn |
| 35 | } with { variant "" }; |
| 36 | |
Harald Welte | 9182704 | 2018-01-25 09:20:04 +0100 | [diff] [blame] | 37 | /* return random integer between 0 and max */ |
| 38 | function f_rnd_int(integer max) return integer { |
| 39 | return float2int(rnd()*int2float(max)); |
| 40 | } |
| 41 | |
| 42 | /* return hexstring composed of random digits */ |
| 43 | function f_rnd_hexstring(in integer len, in integer max := 15) return hexstring { |
| 44 | var integer i; |
| 45 | var hexstring ret := ''H; |
| 46 | for (i := 0; i < len; i := i + 1) { |
| 47 | ret := ret & int2hex(f_rnd_int(max), 1); |
| 48 | } |
| 49 | return ret; |
| 50 | } |
| 51 | |
| 52 | /* return octetstring composed of random bytes */ |
| 53 | function f_rnd_octstring(in integer len) return octetstring { |
| 54 | var integer i; |
| 55 | var octetstring ret := ''O; |
| 56 | for (i := 0; i < len; i := i + 1) { |
| 57 | ret := ret & int2oct(f_rnd_int(255), 1); |
| 58 | } |
| 59 | return ret; |
| 60 | } |
| 61 | |
| 62 | function f_rnd_imsi(in hexstring prefix) return hexstring { |
| 63 | return prefix & f_rnd_hexstring(15 - lengthof(prefix), 9); |
| 64 | } |
| 65 | |
| 66 | function f_rnd_msisdn(in octetstring prefix, integer len := 6) return octetstring { |
| 67 | return prefix & f_rnd_octstring(len - lengthof(prefix)); |
| 68 | } |
| 69 | |
Harald Welte | c2461d6 | 2018-01-26 18:55:00 +0100 | [diff] [blame] | 70 | function f_sleep(float seconds) { |
| 71 | timer T := seconds; |
| 72 | T.start; |
| 73 | T.timeout; |
| 74 | } |
| 75 | |
Harald Welte | c7adaa7 | 2018-02-15 20:40:36 +0100 | [diff] [blame] | 76 | function bool2bit(boolean inp) return BIT1 { |
| 77 | if (inp) { |
| 78 | return '1'B; |
| 79 | } else { |
| 80 | return '0'B; |
| 81 | } |
| 82 | } |
| 83 | |
| 84 | function bool2bit_tmpl(template boolean inp) return template BIT1 { |
| 85 | if (istemplatekind(inp, "omit")) { |
| 86 | return omit; |
| 87 | } else if (istemplatekind(inp, "*")) { |
| 88 | return *; |
| 89 | } else if (istemplatekind(inp, "?")) { |
Harald Welte | b596c18 | 2018-02-16 18:12:59 +0100 | [diff] [blame] | 90 | return ?; |
Harald Welte | c7adaa7 | 2018-02-15 20:40:36 +0100 | [diff] [blame] | 91 | } else { |
| 92 | if (valueof(inp)) { |
| 93 | return '1'B; |
| 94 | } else { |
| 95 | return '0'B; |
| 96 | } |
| 97 | } |
Harald Welte | ccda45e | 2018-02-16 18:13:16 +0100 | [diff] [blame] | 98 | setverdict(fail, "Unsupported template", inp); |
Harald Welte | c7adaa7 | 2018-02-15 20:40:36 +0100 | [diff] [blame] | 99 | self.stop; |
| 100 | } |
| 101 | |
| 102 | |
Harald Welte | 615bd54 | 2017-07-14 18:28:55 +0200 | [diff] [blame] | 103 | } with { encode "RAW"; variant "FIELDORDER(msb)" } |