VOL-3808: Bugfix for Download Section Request 1 & 2

Change-Id: I93710ecfe111a1f89408fd7e461ce735bd5fc4f3
diff --git a/VERSION b/VERSION
index a551051..e815b86 100644
--- a/VERSION
+++ b/VERSION
@@ -1 +1 @@
-0.15.0
+0.15.1
diff --git a/layers.go b/layers.go
index f05c34b..6eb09a9 100644
--- a/layers.go
+++ b/layers.go
@@ -154,6 +154,7 @@
 	nextLayerMapping[TestRequestType] = LayerTypeTestRequest
 	nextLayerMapping[StartSoftwareDownloadRequestType] = LayerTypeStartSoftwareDownloadRequest
 	nextLayerMapping[DownloadSectionRequestType] = LayerTypeDownloadSectionRequest
+	nextLayerMapping[DownloadSectionRequestWithResponseType] = LayerTypeDownloadSectionRequest
 	nextLayerMapping[EndSoftwareDownloadRequestType] = LayerTypeEndSoftwareDownloadRequest
 	nextLayerMapping[ActivateSoftwareRequestType] = LayerTypeActivateSoftwareRequest
 	nextLayerMapping[CommitSoftwareRequestType] = LayerTypeCommitSoftwareRequest
diff --git a/messagetypes.go b/messagetypes.go
index 8cca403..c237e72 100644
--- a/messagetypes.go
+++ b/messagetypes.go
@@ -29,46 +29,47 @@
 type MessageType byte
 
 const (
-	CreateRequestType                 = MessageType(byte(me.Create) | me.AR)
-	CreateResponseType                = MessageType(byte(me.Create) | me.AK)
-	DeleteRequestType                 = MessageType(byte(me.Delete) | me.AR)
-	DeleteResponseType                = MessageType(byte(me.Delete) | me.AK)
-	SetRequestType                    = MessageType(byte(me.Set) | me.AR)
-	SetResponseType                   = MessageType(byte(me.Set) | me.AK)
-	GetRequestType                    = MessageType(byte(me.Get) | me.AR)
-	GetResponseType                   = MessageType(byte(me.Get) | me.AK)
-	GetAllAlarmsRequestType           = MessageType(byte(me.GetAllAlarms) | me.AR)
-	GetAllAlarmsResponseType          = MessageType(byte(me.GetAllAlarms) | me.AK)
-	GetAllAlarmsNextRequestType       = MessageType(byte(me.GetAllAlarmsNext) | me.AR)
-	GetAllAlarmsNextResponseType      = MessageType(byte(me.GetAllAlarmsNext) | me.AK)
-	MibUploadRequestType              = MessageType(byte(me.MibUpload) | me.AR)
-	MibUploadResponseType             = MessageType(byte(me.MibUpload) | me.AK)
-	MibUploadNextRequestType          = MessageType(byte(me.MibUploadNext) | me.AR)
-	MibUploadNextResponseType         = MessageType(byte(me.MibUploadNext) | me.AK)
-	MibResetRequestType               = MessageType(byte(me.MibReset) | me.AR)
-	MibResetResponseType              = MessageType(byte(me.MibReset) | me.AK)
-	TestRequestType                   = MessageType(byte(me.Test) | me.AR)
-	TestResponseType                  = MessageType(byte(me.Test) | me.AK)
-	StartSoftwareDownloadRequestType  = MessageType(byte(me.StartSoftwareDownload) | me.AR)
-	StartSoftwareDownloadResponseType = MessageType(byte(me.StartSoftwareDownload) | me.AK)
-	DownloadSectionRequestType        = MessageType(byte(me.DownloadSection) | me.AR)
-	DownloadSectionResponseType       = MessageType(byte(me.DownloadSection) | me.AK)
-	EndSoftwareDownloadRequestType    = MessageType(byte(me.EndSoftwareDownload) | me.AR)
-	EndSoftwareDownloadResponseType   = MessageType(byte(me.EndSoftwareDownload) | me.AK)
-	ActivateSoftwareRequestType       = MessageType(byte(me.ActivateSoftware) | me.AR)
-	ActivateSoftwareResponseType      = MessageType(byte(me.ActivateSoftware) | me.AK)
-	CommitSoftwareRequestType         = MessageType(byte(me.CommitSoftware) | me.AR)
-	CommitSoftwareResponseType        = MessageType(byte(me.CommitSoftware) | me.AK)
-	SynchronizeTimeRequestType        = MessageType(byte(me.SynchronizeTime) | me.AR)
-	SynchronizeTimeResponseType       = MessageType(byte(me.SynchronizeTime) | me.AK)
-	RebootRequestType                 = MessageType(byte(me.Reboot) | me.AR)
-	RebootResponseType                = MessageType(byte(me.Reboot) | me.AK)
-	GetNextRequestType                = MessageType(byte(me.GetNext) | me.AR)
-	GetNextResponseType               = MessageType(byte(me.GetNext) | me.AK)
-	GetCurrentDataRequestType         = MessageType(byte(me.GetCurrentData) | me.AR)
-	GetCurrentDataResponseType        = MessageType(byte(me.GetCurrentData) | me.AK)
-	SetTableRequestType               = MessageType(byte(me.SetTable) | me.AR)
-	SetTableResponseType              = MessageType(byte(me.SetTable) | me.AK)
+	CreateRequestType                      = MessageType(byte(me.Create) | me.AR)
+	CreateResponseType                     = MessageType(byte(me.Create) | me.AK)
+	DeleteRequestType                      = MessageType(byte(me.Delete) | me.AR)
+	DeleteResponseType                     = MessageType(byte(me.Delete) | me.AK)
+	SetRequestType                         = MessageType(byte(me.Set) | me.AR)
+	SetResponseType                        = MessageType(byte(me.Set) | me.AK)
+	GetRequestType                         = MessageType(byte(me.Get) | me.AR)
+	GetResponseType                        = MessageType(byte(me.Get) | me.AK)
+	GetAllAlarmsRequestType                = MessageType(byte(me.GetAllAlarms) | me.AR)
+	GetAllAlarmsResponseType               = MessageType(byte(me.GetAllAlarms) | me.AK)
+	GetAllAlarmsNextRequestType            = MessageType(byte(me.GetAllAlarmsNext) | me.AR)
+	GetAllAlarmsNextResponseType           = MessageType(byte(me.GetAllAlarmsNext) | me.AK)
+	MibUploadRequestType                   = MessageType(byte(me.MibUpload) | me.AR)
+	MibUploadResponseType                  = MessageType(byte(me.MibUpload) | me.AK)
+	MibUploadNextRequestType               = MessageType(byte(me.MibUploadNext) | me.AR)
+	MibUploadNextResponseType              = MessageType(byte(me.MibUploadNext) | me.AK)
+	MibResetRequestType                    = MessageType(byte(me.MibReset) | me.AR)
+	MibResetResponseType                   = MessageType(byte(me.MibReset) | me.AK)
+	TestRequestType                        = MessageType(byte(me.Test) | me.AR)
+	TestResponseType                       = MessageType(byte(me.Test) | me.AK)
+	StartSoftwareDownloadRequestType       = MessageType(byte(me.StartSoftwareDownload) | me.AR)
+	StartSoftwareDownloadResponseType      = MessageType(byte(me.StartSoftwareDownload) | me.AK)
+	DownloadSectionRequestType             = MessageType(me.DownloadSection) // me.AR is optional
+	DownloadSectionRequestWithResponseType = MessageType(byte(me.DownloadSection) | me.AR)
+	DownloadSectionResponseType            = MessageType(byte(me.DownloadSection) | me.AK)
+	EndSoftwareDownloadRequestType         = MessageType(byte(me.EndSoftwareDownload) | me.AR)
+	EndSoftwareDownloadResponseType        = MessageType(byte(me.EndSoftwareDownload) | me.AK)
+	ActivateSoftwareRequestType            = MessageType(byte(me.ActivateSoftware) | me.AR)
+	ActivateSoftwareResponseType           = MessageType(byte(me.ActivateSoftware) | me.AK)
+	CommitSoftwareRequestType              = MessageType(byte(me.CommitSoftware) | me.AR)
+	CommitSoftwareResponseType             = MessageType(byte(me.CommitSoftware) | me.AK)
+	SynchronizeTimeRequestType             = MessageType(byte(me.SynchronizeTime) | me.AR)
+	SynchronizeTimeResponseType            = MessageType(byte(me.SynchronizeTime) | me.AK)
+	RebootRequestType                      = MessageType(byte(me.Reboot) | me.AR)
+	RebootResponseType                     = MessageType(byte(me.Reboot) | me.AK)
+	GetNextRequestType                     = MessageType(byte(me.GetNext) | me.AR)
+	GetNextResponseType                    = MessageType(byte(me.GetNext) | me.AK)
+	GetCurrentDataRequestType              = MessageType(byte(me.GetCurrentData) | me.AR)
+	GetCurrentDataResponseType             = MessageType(byte(me.GetCurrentData) | me.AK)
+	SetTableRequestType                    = MessageType(byte(me.SetTable) | me.AR)
+	SetTableResponseType                   = MessageType(byte(me.SetTable) | me.AK)
 	// Autonomous ONU messages
 	AlarmNotificationType    = MessageType(byte(me.AlarmNotification))
 	AttributeValueChangeType = MessageType(byte(me.AttributeValueChange))
@@ -2143,7 +2144,7 @@
 type DownloadSectionRequest struct {
 	MeBasePacket  // Note: EntityInstance for software download is two specific values
 	SectionNumber byte
-	SectionData   [29]byte // 0 padding if final transfer requires only a partial block
+	SectionData   [31]byte // 0 padding if final transfer requires only a partial block
 }
 
 func (omci *DownloadSectionRequest) String() string {
@@ -2202,7 +2203,7 @@
 	if omci.EntityClass != me.SoftwareImageClassID {
 		return me.NewProcessingError("invalid Entity Class for Download Section response")
 	}
-	bytes, err := b.AppendBytes(1 + 29)
+	bytes, err := b.AppendBytes(1 + len(omci.SectionData))
 	if err != nil {
 		return err
 	}
diff --git a/messagetypes_test.go b/messagetypes_test.go
index 4e29cc6..4814703 100644
--- a/messagetypes_test.go
+++ b/messagetypes_test.go
@@ -1483,36 +1483,46 @@
 
 // TODO: Create request/response tests for all of the following types
 //Test,
-
+//                    1                   2                   3                   4
+//  1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4
+// 0004530a00070001ff000f424001000100000000000000000000000000000000000000000000000000000028
+// 0004530a
+//         00070001             - ONU-G instance 0001
+//                 ff           - window size - 1
+//                   000f4240   - image size
+//                           01
+//                             000100000000000000000000000000000000000000000000000000000028
 func TestStartSoftwareDownloadRequestDecode(t *testing.T) {
-	// TODO: Need to complete implementation & debug this
-	//goodMessage := "0000530a0007000113000f424001000100000000000000000000000000000000000000000000000000000028"
-	//data, err := stringToPacket(goodMessage)
-	//assert.NoError(t, err)
-	//
-	//packet := gopacket.NewPacket(data, LayerTypeOMCI, gopacket.NoCopy)
-	//assert.NotNil(t, packet)
-	//
-	//omciLayer := packet.Layer(LayerTypeOMCI)
-	//assert.NotNil(t, packet)
-	//
-	//omciMsg, ok := omciLayer.(*OMCI)
-	//assert.True(t, ok)
-	//assert.Equal(t, omciMsg.TransactionID, uint16(0x0))
-	//assert.Equal(t, omciMsg.MessageType, StartSoftwareDownloadRequestType)
-	//assert.Equal(t, omciMsg.DeviceIdentifier, BaselineIdent)
-	//assert.Equal(t, omciMsg.Length, uint16(40))
-	//
-	//msgLayer := packet.Layer(LayerTypeStartSoftwareDownloadRequest)
-	//assert.NotNil(t, msgLayer)
-	//
-	//request, ok2 := msgLayer.(*StartSoftwareDownloadRequest)
-	//assert.True(t, ok2)
-	//assert.NotNil(t, request)
-	//
-	//// Verify string output for message
-	//packetString := packet.String()
-	//assert.NotZero(t, len(packetString))
+	goodMessage := "0004530a00070001ff000f424001000100000000000000000000000000000000000000000000000000000028"
+	data, err := stringToPacket(goodMessage)
+	assert.NoError(t, err)
+
+	packet := gopacket.NewPacket(data, LayerTypeOMCI, gopacket.NoCopy)
+	assert.NotNil(t, packet)
+
+	omciLayer := packet.Layer(LayerTypeOMCI)
+	assert.NotNil(t, packet)
+
+	omciMsg, ok := omciLayer.(*OMCI)
+	assert.True(t, ok)
+	assert.Equal(t, uint16(0x0004), omciMsg.TransactionID)
+	assert.Equal(t, StartSoftwareDownloadRequestType, omciMsg.MessageType)
+	assert.True(t, omciMsg.ResponseExpected)
+	assert.Equal(t, BaselineIdent, omciMsg.DeviceIdentifier)
+	assert.Equal(t, uint16(40), omciMsg.Length)
+
+	msgLayer := packet.Layer(LayerTypeStartSoftwareDownloadRequest)
+	assert.NotNil(t, msgLayer)
+
+	request, ok2 := msgLayer.(*StartSoftwareDownloadRequest)
+	assert.True(t, ok2)
+	assert.NotNil(t, request)
+	assert.Equal(t, uint8(0xff), request.WindowSize)
+	assert.Equal(t, uint32(0x000f4240), request.ImageSize)
+
+	// Verify string output for message
+	packetString := packet.String()
+	assert.NotZero(t, len(packetString))
 }
 
 func TestStartSoftwareDownloadRequestSerialize(t *testing.T) {
@@ -1605,64 +1615,199 @@
 	//assert.Equal(t, strings.ToLower(goodMessage), reconstituted)
 }
 
-func TestDownloadSectionRequestDecode(t *testing.T) {
-	// TODO: Need to complete implementation & debug this
-	//goodMessage := "0000140a00070001083534363836393733323036393733323036313230373436353733373400000000000028"
-	//data, err := stringToPacket(goodMessage)
-	//assert.NoError(t, err)
-	//
-	//packet := gopacket.NewPacket(data, LayerTypeOMCI, gopacket.NoCopy)
-	//assert.NotNil(t, packet)
-	//
-	//omciLayer := packet.Layer(LayerTypeOMCI)
-	//assert.NotNil(t, packet)
-	//
-	//omciMsg, ok := omciLayer.(*OMCI)
-	//assert.True(t, ok)
-	//assert.Equal(t, omciMsg.TransactionID, uint16(0x0))
-	//assert.Equal(t, omciMsg.MessageType, DownloadSectionRequestType)
-	//assert.Equal(t, omciMsg.DeviceIdentifier, BaselineIdent)
-	//assert.Equal(t, omciMsg.Length, uint16(40))
-	//
-	//msgLayer := packet.Layer(LayerTypeDownloadSectionRequest)
-	//assert.NotNil(t, msgLayer)
-	//
-	//request, ok2 := msgLayer.(*DownloadSectionRequest)
-	//assert.True(t, ok2)
-	//assert.NotNil(t, request)
-	//
-	//// Verify string output for message
-	//packetString := packet.String()
-	//assert.NotZero(t, len(packetString))
+//                    1                   2                   3                   4
+//  1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4
+// 0008140a00070001		    - Download section, AR=0
+//                 cc       - Section 0xcc
+//                   01020304050607080910111213141516171819202122232425262728293031
+//                                                                                 00000028
+
+func TestDownloadSectionRequestDecodeNoResponseExpected(t *testing.T) {
+	goodMessage := "0008140a00070001cc0102030405060708091011121314151617181920212223242526272829303100000028"
+	data, err := stringToPacket(goodMessage)
+	assert.NoError(t, err)
+
+	packet := gopacket.NewPacket(data, LayerTypeOMCI, gopacket.NoCopy)
+	assert.NotNil(t, packet)
+
+	omciLayer := packet.Layer(LayerTypeOMCI)
+	assert.NotNil(t, packet)
+
+	omciMsg, ok := omciLayer.(*OMCI)
+	assert.True(t, ok)
+	assert.Equal(t, uint16(0x0008), omciMsg.TransactionID)
+	assert.Equal(t, DownloadSectionRequestType, omciMsg.MessageType)
+	assert.False(t, omciMsg.ResponseExpected)
+	assert.Equal(t, BaselineIdent, omciMsg.DeviceIdentifier)
+	assert.Equal(t, uint16(40), omciMsg.Length)
+
+	msgLayer := packet.Layer(LayerTypeDownloadSectionRequest)
+	assert.NotNil(t, msgLayer)
+
+	request, ok2 := msgLayer.(*DownloadSectionRequest)
+	assert.True(t, ok2)
+	assert.NotNil(t, request)
+	assert.Equal(t, uint8(0xcc), request.SectionNumber)
+	assert.Equal(t, 31, len(request.SectionData))
+
+	sectionData, genErr := stringToPacket("01020304050607080910111213141516171819202122232425262728293031")
+	assert.Nil(t, genErr)
+	assert.NotNil(t, sectionData)
+	assert.Equal(t, 31, len(sectionData))
+	assert.Equal(t, sectionData, request.SectionData[:])
+
+	// Verify string output for message
+	packetString := packet.String()
+	assert.NotZero(t, len(packetString))
 }
 
-func TestDownloadSectionRequestSerialize(t *testing.T) {
-	// TODO: Need to complete implementation & debug this
-	//goodMessage := "0000140a00070001083534363836393733323036393733323036313230373436353733373400000000000028"
-	//
-	//omciLayer := &OMCI{
-	//	TransactionID: 0x01,
-	//	MessageType:   DownloadSectionRequestType,
-	//	// DeviceIdentifier: omci.BaselineIdent,		// Optional, defaults to Baseline
-	//	// Length:           0x28,						// Optional, defaults to 40 octets
-	//}
-	//request := &DownloadSectionRequest{
-	//	MeBasePacket: MeBasePacket{
-	//		EntityClass: OnuDataClassID,
-	//		// Default Instance ID is 0
-	//	},
-	//}
-	//// Test serialization back to former string
-	//var options gopacket.SerializeOptions
-	//options.FixLengths = true
-	//
-	//buffer := gopacket.NewSerializeBuffer()
-	//err := gopacket.SerializeLayers(buffer, options, omciLayer, request)
-	//assert.NoError(t, err)
-	//
-	//outgoingPacket := buffer.Bytes()
-	//reconstituted := packetToString(outgoingPacket)
-	//assert.Equal(t, strings.ToLower(goodMessage), reconstituted)
+func TestDownloadSectionRequestDecodeResponseExpected(t *testing.T) {
+	goodMessage := "0008540a00070001cc0102030405060708091011121314151617181920212223242526272829303100000028"
+	data, err := stringToPacket(goodMessage)
+	assert.NoError(t, err)
+
+	packet := gopacket.NewPacket(data, LayerTypeOMCI, gopacket.NoCopy)
+	assert.NotNil(t, packet)
+
+	omciLayer := packet.Layer(LayerTypeOMCI)
+	assert.NotNil(t, packet)
+
+	omciMsg, ok := omciLayer.(*OMCI)
+	assert.True(t, ok)
+	assert.Equal(t, uint16(0x0008), omciMsg.TransactionID)
+	assert.Equal(t, DownloadSectionRequestWithResponseType, omciMsg.MessageType)
+	assert.True(t, omciMsg.ResponseExpected)
+	assert.Equal(t, BaselineIdent, omciMsg.DeviceIdentifier)
+	assert.Equal(t, uint16(40), omciMsg.Length)
+
+	msgLayer := packet.Layer(LayerTypeDownloadSectionRequest)
+	assert.NotNil(t, msgLayer)
+
+	request, ok2 := msgLayer.(*DownloadSectionRequest)
+	assert.True(t, ok2)
+	assert.NotNil(t, request)
+	assert.Equal(t, uint8(0xcc), request.SectionNumber)
+	assert.Equal(t, 31, len(request.SectionData))
+
+	sectionData, genErr := stringToPacket("01020304050607080910111213141516171819202122232425262728293031")
+	assert.Nil(t, genErr)
+	assert.NotNil(t, sectionData)
+	assert.Equal(t, 31, len(sectionData))
+	assert.Equal(t, sectionData, request.SectionData[:])
+
+	// Verify string output for message
+	packetString := packet.String()
+	assert.NotZero(t, len(packetString))
+}
+
+func TestDownloadSectionRequestSerializeNoResponseExpected(t *testing.T) {
+	goodMessage := "0123140a00070000cc0102030405060708091011121314151617181920212223242526272829303100000028"
+
+	omciLayer := &OMCI{
+		TransactionID: 0x0123,
+		MessageType:   DownloadSectionRequestType,
+		// DeviceIdentifier: omci.BaselineIdent,		// Optional, defaults to Baseline
+		// Length:           0x28,						// Optional, defaults to 40 octets
+	}
+	sectionData, genErr := stringToPacket("01020304050607080910111213141516171819202122232425262728293031")
+	assert.Nil(t, genErr)
+	assert.NotNil(t, sectionData)
+	assert.Equal(t, 31, len(sectionData))
+
+	request := &DownloadSectionRequest{
+		MeBasePacket: MeBasePacket{
+			EntityClass: me.SoftwareImageClassID,
+			// Default Instance ID is 0
+		},
+		SectionNumber: 0xcc,
+	}
+	copy(request.SectionData[:], sectionData)
+
+	// Test serialization back to former string
+	var options gopacket.SerializeOptions
+	options.FixLengths = true
+
+	buffer := gopacket.NewSerializeBuffer()
+	err := gopacket.SerializeLayers(buffer, options, omciLayer, request)
+	assert.NoError(t, err)
+
+	outgoingPacket := buffer.Bytes()
+	reconstituted := packetToString(outgoingPacket)
+	assert.Equal(t, strings.ToLower(goodMessage), reconstituted)
+}
+
+func TestDownloadSectionRequestSerializeResponseExpectedMethod1(t *testing.T) {
+	goodMessage := "2468540a00070000cc0102030405060708091011121314151617181920212223242526272829303100000028"
+
+	omciLayer := &OMCI{
+		TransactionID: 0x2468,
+		MessageType:   DownloadSectionRequestType,		// or DownloadSectionRequestWithResponseType
+		ResponseExpected: true,
+		// DeviceIdentifier: omci.BaselineIdent,		// Optional, defaults to Baseline
+		// Length:           0x28,						// Optional, defaults to 40 octets
+	}
+	sectionData, genErr := stringToPacket("01020304050607080910111213141516171819202122232425262728293031")
+	assert.Nil(t, genErr)
+	assert.NotNil(t, sectionData)
+	assert.Equal(t, 31, len(sectionData))
+
+	request := &DownloadSectionRequest{
+		MeBasePacket: MeBasePacket{
+			EntityClass: me.SoftwareImageClassID,
+			// Default Instance ID is 0
+		},
+		SectionNumber: 0xcc,
+	}
+	copy(request.SectionData[:], sectionData)
+
+	// Test serialization back to former string
+	var options gopacket.SerializeOptions
+	options.FixLengths = true
+
+	buffer := gopacket.NewSerializeBuffer()
+	err := gopacket.SerializeLayers(buffer, options, omciLayer, request)
+	assert.NoError(t, err)
+
+	outgoingPacket := buffer.Bytes()
+	reconstituted := packetToString(outgoingPacket)
+	assert.Equal(t, strings.ToLower(goodMessage), reconstituted)
+}
+
+func TestDownloadSectionRequestSerializeResponseExpectedMethod2(t *testing.T) {
+	goodMessage := "2468540a00070001cc0102030405060708091011121314151617181920212223242526272829303100000028"
+
+	// In this case, just use the request type with AR response requested already encoded
+	omciLayer := &OMCI{
+		TransactionID: 0x2468,
+		MessageType:   DownloadSectionRequestWithResponseType,
+		// DeviceIdentifier: omci.BaselineIdent,		// Optional, defaults to Baseline
+		// Length:           0x28,						// Optional, defaults to 40 octets
+	}
+	sectionData, genErr := stringToPacket("01020304050607080910111213141516171819202122232425262728293031")
+	assert.Nil(t, genErr)
+	assert.NotNil(t, sectionData)
+	assert.Equal(t, 31, len(sectionData))
+
+	request := &DownloadSectionRequest{
+		MeBasePacket: MeBasePacket{
+			EntityClass: me.SoftwareImageClassID,
+			EntityInstance: 0x0001,					// Default is zero, here we want image 1
+		},
+		SectionNumber: 0xcc,
+	}
+	copy(request.SectionData[:], sectionData)
+
+	// Test serialization back to former string
+	var options gopacket.SerializeOptions
+	options.FixLengths = true
+
+	buffer := gopacket.NewSerializeBuffer()
+	err := gopacket.SerializeLayers(buffer, options, omciLayer, request)
+	assert.NoError(t, err)
+
+	outgoingPacket := buffer.Bytes()
+	reconstituted := packetToString(outgoingPacket)
+	assert.Equal(t, strings.ToLower(goodMessage), reconstituted)
 }
 
 func TestDownloadSectionResponseDecode(t *testing.T) {
@@ -1709,7 +1854,7 @@
 	//}
 	//request := &DownloadSectionResponse{
 	//	MeBasePacket: MeBasePacket{
-	//		EntityClass: OnuDataClassID,
+	//		EntityClass: me.OnuDataClassID,
 	//		// Default Instance ID is 0
 	//	},
 	//}
diff --git a/omci.go b/omci.go
index 7a162d6..3904352 100644
--- a/omci.go
+++ b/omci.go
@@ -112,6 +112,7 @@
 	TransactionID    uint16
 	MessageType      MessageType
 	DeviceIdentifier DeviceIdent
+	ResponseExpected bool // Significant for Download Section Request only
 	Payload          []byte
 	padding          []byte
 	Length           uint16
@@ -206,6 +207,7 @@
 	omci.TransactionID = binary.BigEndian.Uint16(data[0:])
 	omci.MessageType = MessageType(data[2])
 	omci.DeviceIdentifier = DeviceIdent(data[3])
+	omci.ResponseExpected = byte(omci.MessageType)&me.AR == me.AR
 
 	isNotification := (int(omci.MessageType) & ^me.MsgTypeMask) == 0
 	if omci.TransactionID == 0 && !isNotification {
@@ -298,7 +300,13 @@
 		return errors.New(msg)
 	}
 	binary.BigEndian.PutUint16(bytes, omci.TransactionID)
-	bytes[2] = byte(omci.MessageType)
+	// Download section request can optionally have the AR bit set or cleared.  If user passes in this
+	// message type and sets download requested, fix up the message type for them.
+	if omci.MessageType == DownloadSectionRequestType && omci.ResponseExpected {
+		bytes[2] = byte(DownloadSectionRequestWithResponseType)
+	} else {
+		bytes[2] = byte(omci.MessageType)
+	}
 	bytes[3] = byte(omci.DeviceIdentifier)
 	b.PushLayer(LayerTypeOMCI)