136
136
from pcapkit .utilities .exceptions import ProtocolError , UnsupportedCall
137
137
from pcapkit .utilities .warnings import ProtocolWarning , warn
138
138
139
+ from pcapkit .protocols .schema .internet .mh import BindingRefreshRequestMessage as Schema_BindingRefreshRequestMessage
140
+ from pcapkit .protocols .data .internet .mh import BindingRefreshRequestMessage as Data_BindingRefreshRequestMessage
141
+ from pcapkit .protocols .schema .internet .mh import HomeTestInitMessage as Schema_HomeTestInitMessage
142
+ from pcapkit .protocols .data .internet .mh import HomeTestInitMessage as Data_HomeTestInitMessage
143
+
139
144
if TYPE_CHECKING :
140
145
from datetime import datetime as dt_type
141
146
from enum import IntEnum as StdlibEnum
@@ -191,7 +196,8 @@ class MH(Internet[Data_MH, Schema_MH],
191
196
__message__ = collections .defaultdict (
192
197
lambda : 'unknown' ,
193
198
{
194
-
199
+ Enum_Packet .Binding_Refresh_Request : 'brr' ,
200
+ Enum_Packet .Home_Test_Init : 'hoti' ,
195
201
},
196
202
) # type: DefaultDict[Enum_Packet | int, str | tuple[PacketParser, PacketConstructor]]
197
203
@@ -494,6 +500,82 @@ def _read_msg_unknown(self, schema: 'Schema_UnknownMessage', *,
494
500
)
495
501
return data
496
502
503
+ def _read_msg_brr (self , schema : 'Schema_BindingRefreshRequestMessage' , * ,
504
+ header : 'Schema_MH' ) -> 'Data_BindingRefreshRequestMessage' :
505
+ """Read MH binding refresh request (BRR) message type.
506
+
507
+ Structure of MH Binding Refresh Request Message [:rfc:`6275`]:
508
+
509
+ .. code-block:: text
510
+
511
+ +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
512
+ | Reserved |
513
+ +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
514
+ | |
515
+ . .
516
+ . Mobility Options .
517
+ . .
518
+ | |
519
+ +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
520
+
521
+ Args:
522
+ schema: Parsed message type schema.
523
+ header: Parsed MH header schema.
524
+
525
+ Returns:
526
+ Parsed message type data.
527
+
528
+ """
529
+ data = Data_BindingRefreshRequestMessage (
530
+ next = header .next ,
531
+ length = (header .length + 1 ) * 8 ,
532
+ type = header .type ,
533
+ chksum = header .chksum ,
534
+ options = self ._read_mh_options (schema .options )
535
+ )
536
+ return data
537
+
538
+ def _read_msg_hoti (self , schema : 'Schema_HomeTestInitMessage' , * ,
539
+ header : 'Schema_MH' ) -> 'Data_HomeTestInitMessage' :
540
+ """Read MH home test initiation (HoTI) message type.
541
+
542
+ Structure of MH Home Test Initiation Message [:rfc:`6275`]:
543
+
544
+ .. code-block:: text
545
+
546
+ +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
547
+ | Reserved |
548
+ +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
549
+ | |
550
+ + Home Init Cookie +
551
+ | |
552
+ +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
553
+ | |
554
+ . .
555
+ . Mobility Options .
556
+ . .
557
+ | |
558
+ +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
559
+
560
+ Args:
561
+ schema: Parsed message type schema.
562
+ header: Parsed MH header schema.
563
+
564
+ Returns:
565
+ Parsed message type data.
566
+
567
+ """
568
+ data = Data_HomeTestInitMessage (
569
+ next = header .next ,
570
+ length = (header .length + 1 ) * 8 ,
571
+ type = header .type ,
572
+ chksum = header .chksum ,
573
+ cookie = schema .cookie ,
574
+ options = self ._read_mh_options (schema .options )
575
+ )
576
+ return data
577
+
578
+
497
579
498
580
499
581
@@ -1158,6 +1240,8 @@ def _read_opt_ct(self, schema: 'Schema_CareofTestOption', *,
1158
1240
1159
1241
1160
1242
1243
+
1244
+
1161
1245
def _read_cga_extensions (self , extensions_schema : 'list[Schema_CGAExtension]' ) -> 'Extension' :
1162
1246
"""Read CGA extensions.
1163
1247
@@ -1270,7 +1354,6 @@ def _read_ext_multiprefix(self, schema: 'Schema_MultiPrefixExtension', *,
1270
1354
1271
1355
1272
1356
1273
-
1274
1357
def _make_msg_unknown (self , message : 'Optional[Data_UnknownMessage]' , * ,
1275
1358
data : 'bytes' = b'' ,
1276
1359
** kwargs : 'Any' ) -> 'Schema_UnknownMessage' :
@@ -1292,30 +1375,80 @@ def _make_msg_unknown(self, message: 'Optional[Data_UnknownMessage]', *,
1292
1375
data = data ,
1293
1376
)
1294
1377
1378
+ def _make_msg_brr (self , message : 'Optional[Data_BindingRefreshRequestMessage]' , * ,
1379
+ options : 'Optional[Option | list[Schema_Option | tuple[Enum_Option, dict[str, Any]] | bytes]]' = None ,
1380
+ ** kwargs : 'Any' ) -> 'Schema_BindingRefreshRequestMessage' :
1381
+ """Make MH binding refresh request (BRR) message type.
1382
+
1383
+ Args:
1384
+ message: Message data model.
1385
+ options: Mobility options.
1386
+ **kwargs: Arbitrary keyword arguments.
1387
+
1388
+ Returns:
1389
+ Constructed message type.
1390
+
1391
+ """
1392
+ if message is not None :
1393
+ options = message .options
1394
+ else :
1395
+ options = options or []
1396
+
1397
+ return Schema_BindingRefreshRequestMessage (
1398
+ options = self ._make_mh_options (options ),
1399
+ )
1400
+
1401
+ def _make_msg_hoti (self , message : 'Optional[Data_HomeTestInitMessage]' , * ,
1402
+ cookie : 'bytes' = b'\x00 \x00 \x00 \x00 \x00 \x00 \x00 \x00 ' ,
1403
+ options : 'Optional[Option | list[Schema_Option | tuple[Enum_Option, dict[str, Any]] | bytes]]' = None ,
1404
+ ** kwargs : 'Any' ) -> 'Schema_HomeTestInitMessage' :
1405
+ """Make MH home test init (HoTI) message type.
1406
+
1407
+ Args:
1408
+ message: Message data model.
1409
+ cookie: Home test cookie.
1410
+ options: Mobility options.
1411
+ **kwargs: Arbitrary keyword arguments.
1412
+
1413
+ Returns:
1414
+ Constructed message type.
1415
+
1416
+ """
1417
+ if message is not None :
1418
+ cookie = message .cookie
1419
+ options = message .options
1420
+ else :
1421
+ options = options or []
1422
+
1423
+ return Schema_HomeTestInitMessage (
1424
+ cookie = cookie ,
1425
+ options = self ._make_mh_options (options ),
1426
+ )
1427
+
1295
1428
1296
1429
1297
- def _make_mh_options (self , options : 'Option | list[Schema_Option | tuple[Enum_Option, dict[str, Any]] | bytes]' ) -> 'tuple[list[Schema_Option | bytes], int]' :
1430
+
1431
+
1432
+
1433
+ def _make_mh_options (self , options : 'Option | list[Schema_Option | tuple[Enum_Option, dict[str, Any]] | bytes]' ) -> 'list[Schema_Option | bytes]' :
1298
1434
"""Make options for MH.
1299
1435
1300
1436
Args:
1301
1437
options: MH options.
1302
1438
1303
1439
Returns:
1304
- Tuple of options and total length of options .
1440
+ Mobility options list .
1305
1441
1306
1442
"""
1307
- total_length = 0
1308
1443
if isinstance (options , list ):
1309
1444
options_list = [] # type: list[Schema_Option | bytes]
1310
1445
for schema in options :
1311
1446
if isinstance (schema , bytes ):
1312
1447
code = Enum_Option .get (int .from_bytes (schema [0 :1 ], 'big' , signed = False ))
1313
1448
1314
1449
data = schema # type: Schema_Option | bytes
1315
- data_len = len (data )
1316
1450
elif isinstance (schema , Schema ):
1317
1451
data = schema
1318
- data_len = len (schema .pack ())
1319
1452
else :
1320
1453
code , args = cast ('tuple[Enum_Option, dict[str, Any]]' , schema )
1321
1454
name = self .__option__ [code ]
@@ -1325,13 +1458,10 @@ def _make_mh_options(self, options: 'Option | list[Schema_Option | tuple[Enum_Op
1325
1458
getattr (self , meth_name , self ._make_opt_none ))
1326
1459
else :
1327
1460
meth = name [1 ]
1328
-
1329
1461
data = meth (code , ** args )
1330
- data_len = len (data .pack ())
1331
1462
1332
1463
options_list .append (data )
1333
- total_length += data_len
1334
- return options_list , total_length
1464
+ return options_list
1335
1465
1336
1466
options_list = []
1337
1467
for code , option in options .items (multi = True ):
@@ -1344,11 +1474,8 @@ def _make_mh_options(self, options: 'Option | list[Schema_Option | tuple[Enum_Op
1344
1474
meth = name [1 ]
1345
1475
1346
1476
data = meth (code , option )
1347
- data_len = len (data .pack ())
1348
-
1349
1477
options_list .append (data )
1350
- total_length += data_len
1351
- return options_list , total_length
1478
+ return options_list
1352
1479
1353
1480
def _make_opt_none (self , type : 'Enum_Option' , option : 'Optional[Data_UnassignedOption]' = None , * ,
1354
1481
data : 'bytes' = b'' ,
@@ -1853,6 +1980,7 @@ def _make_opt_ct(self, type: 'Enum_Option', option: 'Optional[Data_CareofTestOpt
1853
1980
1854
1981
1855
1982
1983
+
1856
1984
def _make_cga_extensions (self , extensions : 'Extension | list[Schema_CGAExtension | tuple[Enum_CGAExtension, dict[str, Any]] | bytes]' ) -> 'tuple[list[Schema_CGAExtension | bytes], int]' :
1857
1985
"""Make CGA extensions for MH.
1858
1986
0 commit comments