summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJoel Fischer <joeljfischer@gmail.com>2017-09-13 15:44:52 -0400
committerJoel Fischer <joeljfischer@gmail.com>2017-09-13 15:44:52 -0400
commitf8fdcfacb6204c83b2d5d61d1f5cefcc71d06557 (patch)
tree31ff658aa02b7dadfcfeeeed0e29cd66904b3e55
parent5c090288cad8f29fd3355801b1566c45b8967ab6 (diff)
downloadsdl_ios-bugfix/issue_661_end_service_with_hash_id.tar.gz
Store and send the hash Id in end service packetsbugfix/issue_661_end_service_with_hash_id
* Centralize setting a protocol header’s bytesInPayload when assembling the message, remove the scattered sets all over the place
-rw-r--r--SmartDeviceLink/SDLProtocol.m55
-rw-r--r--SmartDeviceLink/SDLProtocolMessageAssembler.m1
-rw-r--r--SmartDeviceLink/SDLProtocolMessageDisassembler.m3
-rw-r--r--SmartDeviceLink/SDLV1ProtocolMessage.m2
-rw-r--r--SmartDeviceLink/SDLV2ProtocolMessage.m2
5 files changed, 36 insertions, 27 deletions
diff --git a/SmartDeviceLink/SDLProtocol.m b/SmartDeviceLink/SDLProtocol.m
index 9d22fa602..1adef65f0 100644
--- a/SmartDeviceLink/SDLProtocol.m
+++ b/SmartDeviceLink/SDLProtocol.m
@@ -6,6 +6,7 @@
#import "SDLAbstractTransport.h"
#import "SDLControlFramePayloadConstants.h"
+#import "SDLControlFramePayloadEndService.h"
#import "SDLControlFramePayloadNak.h"
#import "SDLControlFramePayloadRPCStartService.h"
#import "SDLControlFramePayloadRPCStartServiceAck.h"
@@ -44,6 +45,8 @@ NS_ASSUME_NONNULL_BEGIN
@property (strong, nonatomic) NSMutableData *receiveBuffer;
@property (nullable, strong, nonatomic) SDLProtocolReceivedMessageRouter *messageRouter;
@property (strong, nonatomic) NSMutableDictionary<SDLServiceTypeBox *, SDLProtocolHeader *> *serviceHeaders;
+@property (assign, nonatomic) int32_t hashId;
+
@end
@@ -56,6 +59,7 @@ NS_ASSUME_NONNULL_BEGIN
- (instancetype)init {
if (self = [super init]) {
_messageID = 0;
+ _hashId = SDLControlFrameInt32NotFound;
_receiveQueue = dispatch_queue_create("com.sdl.protocol.receive", DISPATCH_QUEUE_SERIAL);
_sendQueue = dispatch_queue_create("com.sdl.protocol.transmit", DISPATCH_QUEUE_SERIAL);
_prioritizedCollection = [[SDLPrioritizedObjectCollection alloc] init];
@@ -104,7 +108,7 @@ NS_ASSUME_NONNULL_BEGIN
if (!success) {
// We can't start the service because we don't have encryption, return the error
completionHandler(success, error);
- return; // from block
+ BLOCK_RETURN;
}
// TLS initialization succeeded. Build and send the message.
@@ -137,7 +141,6 @@ NS_ASSUME_NONNULL_BEGIN
header.frameType = SDLFrameTypeControl;
header.serviceType = serviceType;
header.frameData = SDLFrameInfoStartService;
- header.bytesInPayload = (UInt32)payload.length;
// Sending a StartSession with the encrypted bit set causes module to initiate SSL Handshake with a ClientHello message, which should be handled by the 'processControlService' method.
header.encrypted = encryption;
@@ -156,20 +159,19 @@ NS_ASSUME_NONNULL_BEGIN
return;
}
- [self.securityManager initializeWithAppId:self.appId
- completionHandler:^(NSError *_Nullable error) {
- if (error) {
- SDLLogE(@"Security Manager failed to initialize with error: %@", error);
+ [self.securityManager initializeWithAppId:self.appId completionHandler:^(NSError *_Nullable error) {
+ if (error) {
+ SDLLogE(@"Security Manager failed to initialize with error: %@", error);
- if (completionHandler != nil) {
- completionHandler(NO, error);
- }
- } else {
- if (completionHandler != nil) {
- completionHandler(YES, nil);
- }
- }
- }];
+ if (completionHandler != nil) {
+ completionHandler(NO, error);
+ }
+ } else {
+ if (completionHandler != nil) {
+ completionHandler(YES, nil);
+ }
+ }
+ }];
}
@@ -186,7 +188,18 @@ NS_ASSUME_NONNULL_BEGIN
header.frameData = SDLFrameInfoEndService;
header.sessionID = [self sdl_retrieveSessionIDforServiceType:serviceType];
- SDLProtocolMessage *message = [SDLProtocolMessage messageWithHeader:header andPayload:nil];
+ // Assemble the payload, it's a full control frame if we're on 5.0+, it's just the hash id if we are not
+ NSData *payload = nil;
+ if (self.hashId != SDLControlFrameInt32NotFound) {
+ if([SDLGlobals sharedGlobals].majorProtocolVersion > 4) {
+ SDLControlFramePayloadEndService *endServicePayload = [[SDLControlFramePayloadEndService alloc] initWithHashId:self.hashId];
+ payload = endServicePayload.data;
+ } else {
+ payload = [NSData dataWithBytes:&_hashId length:sizeof(_hashId)];
+ }
+ }
+
+ SDLProtocolMessage *message = [SDLProtocolMessage messageWithHeader:header andPayload:payload];
[self sdl_sendDataToTransport:message.data onService:serviceType];
}
@@ -259,14 +272,12 @@ NS_ASSUME_NONNULL_BEGIN
header.serviceType = (message.bulkData.length <= 0) ? SDLServiceTypeRPC : SDLServiceTypeBulkData;
header.frameData = SDLFrameInfoSingleFrame;
header.sessionID = [self sdl_retrieveSessionIDforServiceType:SDLServiceTypeRPC];
- header.bytesInPayload = (UInt32)messagePayload.length;
// V2+ messages need to have message ID property set.
if ([SDLGlobals sharedGlobals].majorProtocolVersion >= 2) {
[((SDLV2ProtocolHeader *)header) setMessageID:++_messageID];
}
-
SDLProtocolMessage *protocolMessage = [SDLProtocolMessage messageWithHeader:header andPayload:messagePayload];
// See if the message is small enough to send in one transmission. If not, break it up into smaller messages and send.
@@ -327,8 +338,6 @@ NS_ASSUME_NONNULL_BEGIN
}
}
- header.bytesInPayload = (UInt32)data.length;
-
SDLProtocolMessage *message = [SDLProtocolMessage messageWithHeader:header andPayload:data];
if (message.size < [[SDLGlobals sharedGlobals] mtuSizeForServiceType:SDLServiceTypeRPC]) {
@@ -420,11 +429,13 @@ NS_ASSUME_NONNULL_BEGIN
switch (startServiceACK.header.serviceType) {
case SDLServiceTypeRPC: {
SDLControlFramePayloadRPCStartServiceAck *startServiceACKPayload = [[SDLControlFramePayloadRPCStartServiceAck alloc] initWithData:startServiceACK.payload];
-// NSLog(@"ServiceAckPayload: %@", startServiceACKPayload);
if (startServiceACKPayload.mtu != SDLControlFrameInt64NotFound) {
[[SDLGlobals sharedGlobals] setDynamicMTUSize:startServiceACKPayload.mtu forServiceType:startServiceACK.header.serviceType];
}
+ if (startServiceACKPayload.hashId != SDLControlFrameInt32NotFound) {
+ self.hashId = startServiceACKPayload.hashId;
+ }
[SDLGlobals sharedGlobals].maxHeadUnitVersion = (startServiceACKPayload.protocolVersion != nil) ? startServiceACKPayload.protocolVersion : [NSString stringWithFormat:@"%u.0.0", startServiceACK.header.version];
// TODO: Hash id?
} break;
@@ -646,7 +657,6 @@ NS_ASSUME_NONNULL_BEGIN
serverTLSPayload.binaryData = data;
NSData *binaryData = serverTLSPayload.data;
- serverMessageHeader.bytesInPayload = (UInt32)binaryData.length;
return [SDLProtocolMessage messageWithHeader:serverMessageHeader andPayload:binaryData];
}
@@ -668,7 +678,6 @@ NS_ASSUME_NONNULL_BEGIN
serverTLSPayload.correlationID = 0x00;
NSData *binaryData = serverTLSPayload.data;
- serverMessageHeader.bytesInPayload = (UInt32)binaryData.length;
// TODO: (Joel F.)[2016-02-15] This is supposed to have some JSON data and json data size
return [SDLProtocolMessage messageWithHeader:serverMessageHeader andPayload:binaryData];
diff --git a/SmartDeviceLink/SDLProtocolMessageAssembler.m b/SmartDeviceLink/SDLProtocolMessageAssembler.m
index d563f9b77..3aa53347a 100644
--- a/SmartDeviceLink/SDLProtocolMessageAssembler.m
+++ b/SmartDeviceLink/SDLProtocolMessageAssembler.m
@@ -75,7 +75,6 @@ NS_ASSUME_NONNULL_BEGIN
[payload appendData:dataToAppend];
// Validation
- header.bytesInPayload = (UInt32)payload.length;
if (payload.length != self.expectedBytes) {
SDLLogW(@"Collected bytes size of %lu not equal to expected size of %i.", (unsigned long)payload.length, (unsigned int)self.expectedBytes);
}
diff --git a/SmartDeviceLink/SDLProtocolMessageDisassembler.m b/SmartDeviceLink/SDLProtocolMessageDisassembler.m
index 250a03c72..6ab4d32af 100644
--- a/SmartDeviceLink/SDLProtocolMessageDisassembler.m
+++ b/SmartDeviceLink/SDLProtocolMessageDisassembler.m
@@ -44,7 +44,6 @@ NS_ASSUME_NONNULL_BEGIN
payloadData[0] = CFSwapInt32HostToBig((UInt32)incomingMessage.payload.length);
payloadData[1] = CFSwapInt32HostToBig((UInt32)numberOfMessagesRequired);
NSMutableData *firstFramePayload = [NSMutableData dataWithBytes:payloadData length:sizeof(payloadData)];
- firstFrameHeader.bytesInPayload = (UInt32)firstFramePayload.length;
SDLProtocolMessage *firstMessage = [SDLProtocolMessage messageWithHeader:firstFrameHeader andPayload:firstFramePayload];
outgoingMessages[0] = firstMessage;
@@ -62,7 +61,6 @@ NS_ASSUME_NONNULL_BEGIN
NSUInteger offsetOfDataForThisFrame = headerSize + (n * numberOfDataBytesPerMessage);
NSData *nextFramePayload = [incomingMessage.data subdataWithRange:NSMakeRange(offsetOfDataForThisFrame, numberOfDataBytesPerMessage)];
- nextFrameHeader.bytesInPayload = (UInt32)nextFramePayload.length;
SDLProtocolMessage *nextMessage = [SDLProtocolMessage messageWithHeader:nextFrameHeader andPayload:nextFramePayload];
outgoingMessages[n + 1] = nextMessage;
@@ -79,7 +77,6 @@ NS_ASSUME_NONNULL_BEGIN
NSUInteger numberOfDataBytesInLastMessage = incomingPayloadSize - numberOfDataBytesSentSoFar;
NSUInteger offsetOfDataForLastFrame = headerSize + numberOfDataBytesSentSoFar;
NSData *lastFramePayload = [incomingMessage.data subdataWithRange:NSMakeRange(offsetOfDataForLastFrame, numberOfDataBytesInLastMessage)];
- lastFrameHeader.bytesInPayload = (UInt32)lastFramePayload.length;
SDLProtocolMessage *lastMessage = [SDLProtocolMessage messageWithHeader:lastFrameHeader andPayload:lastFramePayload];
outgoingMessages[numberOfMessagesRequired] = lastMessage;
diff --git a/SmartDeviceLink/SDLV1ProtocolMessage.m b/SmartDeviceLink/SDLV1ProtocolMessage.m
index 5e42de98c..3d1e90342 100644
--- a/SmartDeviceLink/SDLV1ProtocolMessage.m
+++ b/SmartDeviceLink/SDLV1ProtocolMessage.m
@@ -13,6 +13,8 @@ NS_ASSUME_NONNULL_BEGIN
if (self = [self init]) {
self.header = header;
self.payload = payload;
+
+ self.header.bytesInPayload = (UInt32)self.payload.length;
}
return self;
}
diff --git a/SmartDeviceLink/SDLV2ProtocolMessage.m b/SmartDeviceLink/SDLV2ProtocolMessage.m
index 0760d45c7..54c4675d8 100644
--- a/SmartDeviceLink/SDLV2ProtocolMessage.m
+++ b/SmartDeviceLink/SDLV2ProtocolMessage.m
@@ -15,6 +15,8 @@ NS_ASSUME_NONNULL_BEGIN
if (self = [self init]) {
self.header = header;
self.payload = payload;
+
+ self.header.bytesInPayload = (UInt32)self.payload.length;
}
return self;
}