# DL_SUBS_BIND_REQ and DL_SUBS_UNBIND_REQ tests (for Ethernet)
# Tested:
# DL_SUBS_BIND_REQ
#	OK
#	PEER/HIERARCHICAL
#	DL_OUTSTATE
#	DL_UNSUPPORTED
#	DL_BOUND (two LLC1 streams to same SAP)
# DL_SUBS_UNBIND_REQ
#	OK
#	DL_OUTSTATE

open 1

# Attempt to peer subs-bind when out of state (not attached)
subs_bind $1 0:0:0:0:0:0,20,01 1 	dl_error_ack dl_outstate

# Attempt to hier subs-bind when out of state (not attached)
subs_bind $1 0:0:0:0:0:0,20,01 2 	dl_error_ack dl_outstate

attach $1 43

check_state $1		dl_unbound

# Attempt to peer subs-bind when out of state (not bound)
subs_bind $1 0:0:0:0:0:0,20,01 1 	dl_error_ack dl_outstate

# Attempt to hier subs-bind when out of state (not bound)
subs_bind $1 0:0:0:0:0:0,20,01 2 	dl_error_ack dl_outstate

# Perform a valid bind
bind $1 2000 1 0 0 0

# Attempt to peer subs-bind to same value as the bind
subs_bind $1 0:0:0:0:0:0,20,00 1 	dl_error_ack dl_bound

# Attempt to hier subs-bind to same value as the bind
subs_bind $1 0:0:0:0:0:0,20,00 2 	dl_error_ack dl_bound

# Perform a valid peer subs-bind
subs_bind $1 0:0:0:0:0:0,20,01 1

# Attempt an invalid peer subs-bind (address too long)
subs_bind $1 0:0:0:0:0:0,20,01,11 1	dl_error_ack dl_badaddr

# Attempt to hier subs-bind to same value as the peer subs-bind
subs_bind $1 0:0:0:0:0:0,20,00 2 	dl_error_ack dl_bound

# Perform a valid hier subs-bind
subs_bind $1 0:0:0:0:0:0,20,02 2

# Perform another valid hier subs-bind
subs_bind $1 0:0:0:0:0:0,20,02,01,02 2

# Perform another valid hier subs-bind
subs_bind $1 0:0:0:0:0:0,20,02,01,02,11,11 2

# Perform another valid hier subs-bind
subs_bind $1 0:0:0:0:0:0,20,02,01,03 2

# Attempt to hier subs-bind to same value as another hier subs-bind
subs_bind $1 0:0:0:0:0:0,20,02,01,02,11,11 2 	dl_error_ack dl_bound

open 2
attach $2 43

# Attempt to bind a second stream to the same as a subs-bind
bind $2 2001 1 0 0 0	dl_error_ack dl_bound

# Attempt to bind a second stream successfully
bind $2 2002 1 0 0 0

# Attempt to subs-bind a second stream to same value as a subs-bind
subs_bind $2 0:0:0:0:0:0,20,02,01,03 2	dl_error_ack dl_bound

# Perform a valid hier subs-bind
subs_bind $2 0:0:0:0:0:0,20,02,01,04 2

# Successful unbind (should be able to re-bind afterwards)
unbind $1

check_state $1		dl_unbound

# Attempt to subs-bind a second stream to a value that is no longer bound
subs_bind $2 0:0:0:0:0:0,20,02,01,03 2

# Perform a valid peer subs-bind
subs_bind $2 0:0:0:0:0:0,20,01 1

# Attempt to rebind to a SAP in use
bind $1 2001 1 0 0 0	dl_error_ack dl_bound

# Attempt to peer subs-bind when out of state (not attached)
subs_bind $1 0:0:0:0:0:0,20,05 1 	dl_error_ack dl_outstate

# Attempt to bind to a valid SAP
bind $1 2003 1 0 0 0

# Perform a valid subs-unbind
subs_unbind $2 0:0:0:0:0:0,20,02,01,04

# Attempt a subs-unbind for an address not bound to
subs_unbind $2 0:0:0:0:0:0,20,02,01,04	dl_error_ack dl_badaddr

# Attempt a subs-unbind for the bound address
subs_unbind $2 0:0:0:0:0:0,20,02	dl_error_ack dl_badaddr

unbind $2

# Attempt a subs-unbind when out of state
subs_unbind $2 0:0:0:0:0:0,20,02	dl_error_ack dl_outstate

detach $2

# Attempt a subs-unbind when out of state
subs_unbind $2 0:0:0:0:0:0,20,02	dl_error_ack dl_outstate

unbind $1
detach $1
