Skip to content

Commit 5883405

Browse files
committed
Correct parsing of Unconnected Send; chain target state after decide
1 parent 0480f1a commit 5883405

File tree

3 files changed

+19
-18
lines changed

3 files changed

+19
-18
lines changed

automata.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -465,12 +465,16 @@ def encode( self, inp ):
465465
here, for use in setting up the parser tables.
466466
467467
"""
468-
if inp is True or inp is None:
469-
return self.ANY if inp else self.NON
468+
if inp is True:
469+
return self.ANY
470+
if inp is None:
471+
return self.NON
470472
if self.encoder is None:
471473
return inp
472474
enc = tuple( self.encoder( inp ))
473-
return enc if len( enc ) > 1 else enc[0]
475+
if len( enc ) > 1:
476+
return enc
477+
return enc[0]
474478

475479
def __setitem__( self, inp, target ):
476480
"""After ensuring that target is a state or a callable (that should return a state), remember a

server/enip/client_test.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -386,7 +386,7 @@ def clitest( n, address ):
386386
svrkwds = dict(
387387
argv = [
388388
'-a', 'localhost:0', '-A',
389-
'-vvv',
389+
'-v',
390390
'Int@0x99/1/1=INT[%d]' % ( taglen ),
391391
'Real@0x99/1/2=REAL[%d]' % ( taglen ),
392392
'DInt@0x99/1/3=DINT[%d]' % ( taglen ),
@@ -406,6 +406,5 @@ def clitest( n, address ):
406406
client_count= clicount,
407407
client_max = clipool,
408408
address_delay= 5.0,
409-
#address_via_stdout=True,
410409
)
411410
assert failed == 0

server/enip/parser.py

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1232,11 +1232,10 @@ def __init__( self, name=None, **kwds ):
12321232
mesg[None] = rout
12331233

12341234
# Parser for an Unconnected Send error response (only seen if Unconnected Send itself fails, eg.
1235-
# was sent to a Non-Routing (simple) CIP device, or was otherwise malformed. From
1235+
# was sent to a Non-Routing (simple) CIP device, or was otherwise malformed.
12361236
uerr = USINT( context='service' )
12371237
uerr[True] = uers = octets_drop( 'reserved', repeat=1 )
1238-
uers[True] = uest = status()
1239-
uest[None] = octets_noop( terminal=True )
1238+
uers[True] = status( terminal=True )
12401239

12411240
# So; 0x52 Unconnected Send parses a request with a Route Path, and 0x52|0x80 *with a length
12421241
# of exactly 4 bytes* (ie. carrying no other data) is an Unconnected Send response carrying
@@ -1245,10 +1244,10 @@ def __init__( self, name=None, **kwds ):
12451244
# single enecapsulated C*Logix Read Tag Fragmented response (0x52/0xD2) carrying an error
12461245
# status. In fact, it is impossible to distinguish -- they are exactly the same size and
12471246
# carry the same server == 0xD2 and status coded.
1248-
def u_s_err( path=None, data=None, source=None, **kwds ):
1247+
def is_uerr( path=None, data=None, source=None, **kwds ):
12491248
log.isEnabledFor( logging.INFO ) and log.info(
1250-
"%s -- checking data[%r] (kwds %r) for unconnected_send error: %s",
1251-
self, path, kwds, enip_format( data )
1249+
"%s -- checking data[%r] (kwds %r) for unconnected_send error (%5s): %s",
1250+
self, path, kwds, data[path+'..length'] <= 6, enip_format( data ),
12521251
)
12531252
if data[path+'..length'] > 6:
12541253
return False
@@ -1276,15 +1275,14 @@ def u_s_err( path=None, data=None, source=None, **kwds ):
12761275
)
12771276
return sts < 0x10 and ext_siz == 0
12781277

1278+
othr = octets( context='request', terminal=True )
1279+
othr[True] = othr
12791280

12801281
slct[b'\x52'[0]] = usnd
1281-
slct[b'\xD2'[0]] = decide(
1282-
'u_s_err',
1283-
predicate = u_s_err,
1284-
state = uerr
1285-
)
1286-
slct[True] = othr = octets( context='request', terminal=True )
1287-
othr[True] = othr
1282+
slct[b'\xD2'[0]] = decide( 'uerr', predicate=is_uerr,
1283+
state=uerr )
1284+
slct[b'\xD2'[0]] = othr
1285+
slct[True] = othr
12881286

12891287
super( unconnected_send, self ).__init__( name=name, initial=slct, **kwds )
12901288

0 commit comments

Comments
 (0)