nuclear@0: /************************************************************************************ nuclear@0: nuclear@0: PublicHeader: n/a nuclear@0: Filename : OVR_SerialFormat.h nuclear@0: Content : Serial Number format tools nuclear@0: Created : June 12, 2014 nuclear@0: nuclear@0: Copyright : Copyright 2014 Oculus VR, LLC All Rights reserved. nuclear@0: nuclear@0: Licensed under the Oculus VR Rift SDK License Version 3.2 (the "License"); nuclear@0: you may not use the Oculus VR Rift SDK except in compliance with the License, nuclear@0: which is provided at the time of installation or download, or which nuclear@0: otherwise accompanies this software in either electronic or hard copy form. nuclear@0: nuclear@0: You may obtain a copy of the License at nuclear@0: nuclear@0: http://www.oculusvr.com/licenses/LICENSE-3.2 nuclear@0: nuclear@0: Unless required by applicable law or agreed to in writing, the Oculus VR SDK nuclear@0: distributed under the License is distributed on an "AS IS" BASIS, nuclear@0: WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. nuclear@0: See the License for the specific language governing permissions and nuclear@0: limitations under the License. nuclear@0: nuclear@0: ************************************************************************************/ nuclear@0: nuclear@0: #ifndef OVR_SerialFormat_h nuclear@0: #define OVR_SerialFormat_h nuclear@0: nuclear@0: #include "Kernel/OVR_Types.h" nuclear@0: #include "Kernel/OVR_String.h" nuclear@0: nuclear@0: namespace OVR { nuclear@0: nuclear@0: nuclear@0: //----------------------------------------------------------------------------- nuclear@0: // SerialFormatType enumeration nuclear@0: nuclear@0: enum SerialFormatType nuclear@0: { nuclear@0: SerialFormatType_Invalid = -1, // Invalid format nuclear@0: SerialFormatType_DK2 = 0, // Format used for DK2 nuclear@0: }; nuclear@0: nuclear@0: // Returns the expected serial format based on the first byte of the buffer nuclear@0: SerialFormatType DetectBufferFormat(uint8_t firstByte, int sizeInBytes); nuclear@0: nuclear@0: nuclear@0: //----------------------------------------------------------------------------- nuclear@0: // DK2 Serial Format nuclear@0: nuclear@0: enum DK2ProductId nuclear@0: { nuclear@0: DK2ProductId_DK1 = 1, // DK1 nuclear@0: DK2ProductId_DK2 = 2, // Product Id used for initial DK2 launch nuclear@0: DK2ProductId_Refurb = 3, // Refurbished DK2 nuclear@0: }; nuclear@0: nuclear@0: enum DK2PartId nuclear@0: { nuclear@0: DK2PartId_HMD = 0, // HMD nuclear@0: DK2PartId_PTC = 1, // PTC(camera) nuclear@0: DK2PartId_Carton = 2, // Carton: An HMD + PTC combo (should not be stamped on a component) AKA Overpack nuclear@0: }; nuclear@0: nuclear@0: typedef DK2PartId DK2LabelType; // Printed Serial Number version nuclear@0: nuclear@0: nuclear@0: // DK2 tool for reading/writing the binary serial format nuclear@0: class DK2BinarySerialFormat nuclear@0: { nuclear@0: public: nuclear@0: static const SerialFormatType FormatType = SerialFormatType_DK2; // first byte nuclear@0: nuclear@0: DK2ProductId ProductId; // [4 bits] 2 = DK2 nuclear@0: DK2PartId PartId; // [4 bits] 0 means HMD, 1 means PTC(camera) nuclear@0: int MinutesSinceEpoch; // [3 bytes] Number of minutes that have elapsed since the epoch: May 1st, 2014 nuclear@0: // [0] = high byte, [1] = middle byte, [2] = low byte nuclear@0: int UnitNumber; // [2 bytes] Value that increments each time a new serial number is created. Resets to zero each day nuclear@0: // [0] = high byte, [1] = low byte nuclear@0: uint8_t MacHash[5]; // [5 bytes] 5 most significant bytes of MD5 hash from first ethernet adapter mac address nuclear@0: nuclear@0: bool operator==(const DK2BinarySerialFormat& rhs); nuclear@0: nuclear@0: public: nuclear@0: // Returns false if the input is invalid in some way nuclear@0: bool FromBuffer(const uint8_t buffer[12], bool allowUnknownTypes = false); nuclear@0: nuclear@0: // Fills the provided buffer with 12 bytes nuclear@0: void ToBuffer(uint8_t buffer[12]); nuclear@0: }; nuclear@0: nuclear@0: nuclear@0: // DK2 tool for reading/writing the printed serial format nuclear@0: class DK2PrintedSerialFormat nuclear@0: { nuclear@0: public: nuclear@0: DK2ProductId ProductId; // [1 char] 2 = DK2, 3 = Reconditioned bundle nuclear@0: DK2LabelType LabelType; // [1 char] 0 means HMD, 1 means PTC(camera), 2 means Overpack(bundle) nuclear@0: int MinutesSinceEpoch; // [4 char] Number of minutes that have elapsed since the epoch: May 1st, 2014 nuclear@0: int UnitNumber; // [3 char] Value that increments each time a new serial number is created. Resets to zero each day nuclear@0: uint8_t MacHashLow[3]; // [3 char] 3 least significant bytes of mac hash nuclear@0: nuclear@0: bool operator==(const DK2PrintedSerialFormat& rhs); nuclear@0: bool operator==(const DK2BinarySerialFormat& rhs); nuclear@0: nuclear@0: public: nuclear@0: // Convert from binary to printed nuclear@0: void FromBinary(const DK2BinarySerialFormat& bin); nuclear@0: nuclear@0: // Returns false if the input is invalid in some way nuclear@0: // Convert from a 12 character printed serial number nuclear@0: bool FromBase32(const char* str, bool allowUnknownTypes = false); nuclear@0: nuclear@0: // Returns a long human-readable base32 string (20 characters), NOT a printed serial number nuclear@0: String ToBase32(); nuclear@0: }; nuclear@0: nuclear@0: nuclear@0: //#define SERIAL_FORMAT_UNIT_TEST nuclear@0: #ifdef SERIAL_FORMAT_UNIT_TEST nuclear@0: void TestSerialFormatStuff(); nuclear@0: #endif nuclear@0: nuclear@0: nuclear@0: } // OVR nuclear@0: nuclear@0: #endif // OVR_SerialFormat_h