Skip to content

Commit

Permalink
fix(core): Handle drives without SessionTimeout
Browse files Browse the repository at this point in the history
If the drive is an Enterprise SSC drive odds are that it supports
setting SessionTimeout. However, I have ran into a drive that does not.
This means we now have to first try to set it, then if that fails fall
back to not setting it.

I believe this is the nicest solution right now.

Signed-off-by: Christian Svensson <christian.svensson@elastx.se>
  • Loading branch information
Christian Svensson committed Jan 24, 2022
1 parent 1ab9ced commit a067a64
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
7 changes: 7 additions & 0 deletions pkg/core/method.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,13 @@ func NewMethodCall(iid InvokingID, mid MethodID, flags MethodFlag) *MethodCall {
return m
}

// Copy the current state of a method call into a new independent copy
func (m *MethodCall) Clone() *MethodCall {
mn := &MethodCall{bytes.Buffer{},m.depth, m.flags}
mn.buf.Write(m.buf.Bytes())
return mn
}

func (m *MethodCall) StartList() {
m.depth++
m.buf.Write(stream.Token(stream.StartList))
Expand Down
6 changes: 6 additions & 0 deletions pkg/core/session.go
Original file line number Diff line number Diff line change
Expand Up @@ -359,6 +359,7 @@ func (cs *ControlSession) NewSession(spid SPID, opts ...SessionOpt) (*Session, e
// Thus, we do not specify any authority here and let the users call ThisSP_Authenticate
// to elevate the session.

basemc := mc.Clone()
if s.ProtocolLevel == ProtocolLevelEnterprise {
// sedutil recommends setting a timeout for session on Enterprise protocol
// level. For normal Core devices I can't get it to work (INVALID_PARAMETER)
Expand All @@ -368,7 +369,12 @@ func (cs *ControlSession) NewSession(spid SPID, opts ...SessionOpt) (*Session, e
mc.EndOptionalParameter()
}

// Try with the method call with the optional parameters first,
// and if that fails fall back to the basic method call (basemc).
resp, err := cs.ExecuteMethod(mc)
if err == ErrMethodStatusInvalidParameter {
resp, err = cs.ExecuteMethod(basemc)
}
if err != nil {
return nil, err
}
Expand Down

0 comments on commit a067a64

Please sign in to comment.