Skip to content

Commit a067a64

Browse files
author
Christian Svensson
committed
fix(core): Handle drives without SessionTimeout
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 <[email protected]>
1 parent 1ab9ced commit a067a64

File tree

2 files changed

+13
-0
lines changed

2 files changed

+13
-0
lines changed

pkg/core/method.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,13 @@ func NewMethodCall(iid InvokingID, mid MethodID, flags MethodFlag) *MethodCall {
8585
return m
8686
}
8787

88+
// Copy the current state of a method call into a new independent copy
89+
func (m *MethodCall) Clone() *MethodCall {
90+
mn := &MethodCall{bytes.Buffer{},m.depth, m.flags}
91+
mn.buf.Write(m.buf.Bytes())
92+
return mn
93+
}
94+
8895
func (m *MethodCall) StartList() {
8996
m.depth++
9097
m.buf.Write(stream.Token(stream.StartList))

pkg/core/session.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -359,6 +359,7 @@ func (cs *ControlSession) NewSession(spid SPID, opts ...SessionOpt) (*Session, e
359359
// Thus, we do not specify any authority here and let the users call ThisSP_Authenticate
360360
// to elevate the session.
361361

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

372+
// Try with the method call with the optional parameters first,
373+
// and if that fails fall back to the basic method call (basemc).
371374
resp, err := cs.ExecuteMethod(mc)
375+
if err == ErrMethodStatusInvalidParameter {
376+
resp, err = cs.ExecuteMethod(basemc)
377+
}
372378
if err != nil {
373379
return nil, err
374380
}

0 commit comments

Comments
 (0)