├── ISO7816Analyser └── ISO7816Analyser.xcodeproj │ ├── project.pbxproj │ └── project.xcworkspace │ └── contents.xcworkspacedata ├── Licenses.txt ├── README.txt ├── VCProj ├── .gitignore ├── Iso7816.sln ├── Iso7816.vcxproj └── Iso7816.vcxproj.filters └── source ├── ByteBuffer.hpp ├── ByteElement.hpp ├── Convert.cpp ├── Convert.hpp ├── Definitions.hpp ├── ISO7816Pps.cpp ├── ISO7816Pps.hpp ├── Logging.cpp ├── Logging.hpp ├── Makefile ├── SaleaeHelper.cpp ├── SaleaeHelper.hpp ├── iso7816Analyzer.cpp ├── iso7816Analyzer.h ├── iso7816AnalyzerResults.cpp ├── iso7816AnalyzerResults.h ├── iso7816AnalyzerSettings.cpp ├── iso7816AnalyzerSettings.h ├── iso7816SimulationDataGenerator.cpp └── iso7816SimulationDataGenerator.h /ISO7816Analyser/ISO7816Analyser.xcodeproj/project.pbxproj: -------------------------------------------------------------------------------- 1 | // !$*UTF8*$! 2 | { 3 | archiveVersion = 1; 4 | classes = { 5 | }; 6 | objectVersion = 46; 7 | objects = { 8 | 9 | /* Begin PBXBuildFile section */ 10 | 3255678B17DEF2840067F677 /* iso7816AnalyzerResults.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 3255678317DEF2840067F677 /* iso7816AnalyzerResults.cpp */; }; 11 | 3255678C17DEF2840067F677 /* iso7816Analyzer.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 3255678417DEF2840067F677 /* iso7816Analyzer.cpp */; }; 12 | 3255678D17DEF2840067F677 /* iso7816Analyzer.h in Headers */ = {isa = PBXBuildFile; fileRef = 3255678517DEF2840067F677 /* iso7816Analyzer.h */; }; 13 | 3255678E17DEF2840067F677 /* iso7816SimulationDataGenerator.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 3255678617DEF2840067F677 /* iso7816SimulationDataGenerator.cpp */; }; 14 | 3255678F17DEF2840067F677 /* iso7816AnalyzerSettings.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 3255678717DEF2840067F677 /* iso7816AnalyzerSettings.cpp */; }; 15 | 3255679017DEF2840067F677 /* iso7816AnalyzerSettings.h in Headers */ = {isa = PBXBuildFile; fileRef = 3255678817DEF2840067F677 /* iso7816AnalyzerSettings.h */; }; 16 | 3255679117DEF2840067F677 /* iso7816AnalyzerResults.h in Headers */ = {isa = PBXBuildFile; fileRef = 3255678917DEF2840067F677 /* iso7816AnalyzerResults.h */; }; 17 | 3255679217DEF2840067F677 /* iso7816SimulationDataGenerator.h in Headers */ = {isa = PBXBuildFile; fileRef = 3255678A17DEF2840067F677 /* iso7816SimulationDataGenerator.h */; }; 18 | 3255679517DEF2F00067F677 /* libAnalyzer.dylib in Frameworks */ = {isa = PBXBuildFile; fileRef = 3255679417DEF2F00067F677 /* libAnalyzer.dylib */; }; 19 | 3255679817DEF48D0067F677 /* libISO7816Analyser.dylib in CopyFiles */ = {isa = PBXBuildFile; fileRef = 3255677C17DEF2440067F677 /* libISO7816Analyser.dylib */; }; 20 | /* End PBXBuildFile section */ 21 | 22 | /* Begin PBXCopyFilesBuildPhase section */ 23 | 3255679717DEF47D0067F677 /* CopyFiles */ = { 24 | isa = PBXCopyFilesBuildPhase; 25 | buildActionMask = 2147483647; 26 | dstPath = "$(PROJECT_DIR)/../source"; 27 | dstSubfolderSpec = 0; 28 | files = ( 29 | 3255679817DEF48D0067F677 /* libISO7816Analyser.dylib in CopyFiles */, 30 | ); 31 | runOnlyForDeploymentPostprocessing = 0; 32 | }; 33 | /* End PBXCopyFilesBuildPhase section */ 34 | 35 | /* Begin PBXFileReference section */ 36 | 3255677C17DEF2440067F677 /* libISO7816Analyser.dylib */ = {isa = PBXFileReference; explicitFileType = "compiled.mach-o.dylib"; includeInIndex = 0; path = libISO7816Analyser.dylib; sourceTree = BUILT_PRODUCTS_DIR; }; 37 | 3255678317DEF2840067F677 /* iso7816AnalyzerResults.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = iso7816AnalyzerResults.cpp; path = ../source/iso7816AnalyzerResults.cpp; sourceTree = ""; }; 38 | 3255678417DEF2840067F677 /* iso7816Analyzer.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = iso7816Analyzer.cpp; path = ../source/iso7816Analyzer.cpp; sourceTree = ""; }; 39 | 3255678517DEF2840067F677 /* iso7816Analyzer.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = iso7816Analyzer.h; path = ../source/iso7816Analyzer.h; sourceTree = ""; }; 40 | 3255678617DEF2840067F677 /* iso7816SimulationDataGenerator.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = iso7816SimulationDataGenerator.cpp; path = ../source/iso7816SimulationDataGenerator.cpp; sourceTree = ""; }; 41 | 3255678717DEF2840067F677 /* iso7816AnalyzerSettings.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = iso7816AnalyzerSettings.cpp; path = ../source/iso7816AnalyzerSettings.cpp; sourceTree = ""; }; 42 | 3255678817DEF2840067F677 /* iso7816AnalyzerSettings.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = iso7816AnalyzerSettings.h; path = ../source/iso7816AnalyzerSettings.h; sourceTree = ""; }; 43 | 3255678917DEF2840067F677 /* iso7816AnalyzerResults.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = iso7816AnalyzerResults.h; path = ../source/iso7816AnalyzerResults.h; sourceTree = ""; }; 44 | 3255678A17DEF2840067F677 /* iso7816SimulationDataGenerator.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = iso7816SimulationDataGenerator.h; path = ../source/iso7816SimulationDataGenerator.h; sourceTree = ""; }; 45 | 3255679417DEF2F00067F677 /* libAnalyzer.dylib */ = {isa = PBXFileReference; lastKnownFileType = "compiled.mach-o.dylib"; name = libAnalyzer.dylib; path = /Applications/Logic.app/Contents/MacOS/libAnalyzer.dylib; sourceTree = ""; }; 46 | 3255679A17DEF91C0067F677 /* Licenses.txt */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = Licenses.txt; sourceTree = ""; }; 47 | /* End PBXFileReference section */ 48 | 49 | /* Begin PBXFrameworksBuildPhase section */ 50 | 3255677917DEF2440067F677 /* Frameworks */ = { 51 | isa = PBXFrameworksBuildPhase; 52 | buildActionMask = 2147483647; 53 | files = ( 54 | 3255679517DEF2F00067F677 /* libAnalyzer.dylib in Frameworks */, 55 | ); 56 | runOnlyForDeploymentPostprocessing = 0; 57 | }; 58 | /* End PBXFrameworksBuildPhase section */ 59 | 60 | /* Begin PBXGroup section */ 61 | 3255677317DEF2440067F677 = { 62 | isa = PBXGroup; 63 | children = ( 64 | 3255679A17DEF91C0067F677 /* Licenses.txt */, 65 | 3255679617DEF4550067F677 /* Frameworks */, 66 | 3255679317DEF2890067F677 /* sources */, 67 | 3255677D17DEF2440067F677 /* Products */, 68 | ); 69 | sourceTree = ""; 70 | }; 71 | 3255677D17DEF2440067F677 /* Products */ = { 72 | isa = PBXGroup; 73 | children = ( 74 | 3255677C17DEF2440067F677 /* libISO7816Analyser.dylib */, 75 | ); 76 | name = Products; 77 | sourceTree = ""; 78 | }; 79 | 3255679317DEF2890067F677 /* sources */ = { 80 | isa = PBXGroup; 81 | children = ( 82 | 3255678517DEF2840067F677 /* iso7816Analyzer.h */, 83 | 3255678417DEF2840067F677 /* iso7816Analyzer.cpp */, 84 | 3255678A17DEF2840067F677 /* iso7816SimulationDataGenerator.h */, 85 | 3255678617DEF2840067F677 /* iso7816SimulationDataGenerator.cpp */, 86 | 3255678817DEF2840067F677 /* iso7816AnalyzerSettings.h */, 87 | 3255678717DEF2840067F677 /* iso7816AnalyzerSettings.cpp */, 88 | 3255678917DEF2840067F677 /* iso7816AnalyzerResults.h */, 89 | 3255678317DEF2840067F677 /* iso7816AnalyzerResults.cpp */, 90 | ); 91 | name = sources; 92 | sourceTree = ""; 93 | }; 94 | 3255679617DEF4550067F677 /* Frameworks */ = { 95 | isa = PBXGroup; 96 | children = ( 97 | 3255679417DEF2F00067F677 /* libAnalyzer.dylib */, 98 | ); 99 | name = Frameworks; 100 | sourceTree = ""; 101 | }; 102 | /* End PBXGroup section */ 103 | 104 | /* Begin PBXHeadersBuildPhase section */ 105 | 3255677A17DEF2440067F677 /* Headers */ = { 106 | isa = PBXHeadersBuildPhase; 107 | buildActionMask = 2147483647; 108 | files = ( 109 | 3255678D17DEF2840067F677 /* iso7816Analyzer.h in Headers */, 110 | 3255679017DEF2840067F677 /* iso7816AnalyzerSettings.h in Headers */, 111 | 3255679117DEF2840067F677 /* iso7816AnalyzerResults.h in Headers */, 112 | 3255679217DEF2840067F677 /* iso7816SimulationDataGenerator.h in Headers */, 113 | ); 114 | runOnlyForDeploymentPostprocessing = 0; 115 | }; 116 | /* End PBXHeadersBuildPhase section */ 117 | 118 | /* Begin PBXNativeTarget section */ 119 | 3255677B17DEF2440067F677 /* ISO7816Analyser */ = { 120 | isa = PBXNativeTarget; 121 | buildConfigurationList = 3255678017DEF2440067F677 /* Build configuration list for PBXNativeTarget "ISO7816Analyser" */; 122 | buildPhases = ( 123 | 3255677817DEF2440067F677 /* Sources */, 124 | 3255677917DEF2440067F677 /* Frameworks */, 125 | 3255677A17DEF2440067F677 /* Headers */, 126 | 3255679917DEF5B90067F677 /* ShellScript */, 127 | 3255679717DEF47D0067F677 /* CopyFiles */, 128 | ); 129 | buildRules = ( 130 | ); 131 | dependencies = ( 132 | ); 133 | name = ISO7816Analyser; 134 | productName = ISO7816Analyser; 135 | productReference = 3255677C17DEF2440067F677 /* libISO7816Analyser.dylib */; 136 | productType = "com.apple.product-type.library.dynamic"; 137 | }; 138 | /* End PBXNativeTarget section */ 139 | 140 | /* Begin PBXProject section */ 141 | 3255677417DEF2440067F677 /* Project object */ = { 142 | isa = PBXProject; 143 | attributes = { 144 | LastUpgradeCheck = 0460; 145 | ORGANIZATIONNAME = "Dirk-Willem van Gulik"; 146 | }; 147 | buildConfigurationList = 3255677717DEF2440067F677 /* Build configuration list for PBXProject "ISO7816Analyser" */; 148 | compatibilityVersion = "Xcode 3.2"; 149 | developmentRegion = English; 150 | hasScannedForEncodings = 0; 151 | knownRegions = ( 152 | en, 153 | ); 154 | mainGroup = 3255677317DEF2440067F677; 155 | productRefGroup = 3255677D17DEF2440067F677 /* Products */; 156 | projectDirPath = ""; 157 | projectRoot = ""; 158 | targets = ( 159 | 3255677B17DEF2440067F677 /* ISO7816Analyser */, 160 | ); 161 | }; 162 | /* End PBXProject section */ 163 | 164 | /* Begin PBXShellScriptBuildPhase section */ 165 | 3255679917DEF5B90067F677 /* ShellScript */ = { 166 | isa = PBXShellScriptBuildPhase; 167 | buildActionMask = 2147483647; 168 | files = ( 169 | ); 170 | inputPaths = ( 171 | ); 172 | outputPaths = ( 173 | ); 174 | runOnlyForDeploymentPostprocessing = 0; 175 | shellPath = /bin/sh; 176 | shellScript = "true 177 | "; 178 | }; 179 | /* End PBXShellScriptBuildPhase section */ 180 | 181 | /* Begin PBXSourcesBuildPhase section */ 182 | 3255677817DEF2440067F677 /* Sources */ = { 183 | isa = PBXSourcesBuildPhase; 184 | buildActionMask = 2147483647; 185 | files = ( 186 | 3255678B17DEF2840067F677 /* iso7816AnalyzerResults.cpp in Sources */, 187 | 3255678C17DEF2840067F677 /* iso7816Analyzer.cpp in Sources */, 188 | 3255678E17DEF2840067F677 /* iso7816SimulationDataGenerator.cpp in Sources */, 189 | 3255678F17DEF2840067F677 /* iso7816AnalyzerSettings.cpp in Sources */, 190 | ); 191 | runOnlyForDeploymentPostprocessing = 0; 192 | }; 193 | /* End PBXSourcesBuildPhase section */ 194 | 195 | /* Begin XCBuildConfiguration section */ 196 | 3255677E17DEF2440067F677 /* Debug */ = { 197 | isa = XCBuildConfiguration; 198 | buildSettings = { 199 | ALWAYS_SEARCH_USER_PATHS = NO; 200 | ARCHS = "$(ARCHS_STANDARD_64_BIT)"; 201 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; 202 | CLANG_CXX_LIBRARY = "libc++"; 203 | CLANG_WARN_CONSTANT_CONVERSION = YES; 204 | CLANG_WARN_EMPTY_BODY = YES; 205 | CLANG_WARN_ENUM_CONVERSION = YES; 206 | CLANG_WARN_INT_CONVERSION = YES; 207 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 208 | COPY_PHASE_STRIP = NO; 209 | GCC_C_LANGUAGE_STANDARD = gnu99; 210 | GCC_DYNAMIC_NO_PIC = NO; 211 | GCC_ENABLE_OBJC_EXCEPTIONS = YES; 212 | GCC_OPTIMIZATION_LEVEL = 0; 213 | GCC_PREPROCESSOR_DEFINITIONS = ( 214 | "DEBUG=1", 215 | "$(inherited)", 216 | ); 217 | GCC_SYMBOLS_PRIVATE_EXTERN = NO; 218 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 219 | GCC_WARN_ABOUT_RETURN_TYPE = YES; 220 | GCC_WARN_UNINITIALIZED_AUTOS = YES; 221 | GCC_WARN_UNUSED_VARIABLE = YES; 222 | MACOSX_DEPLOYMENT_TARGET = 10.8; 223 | ONLY_ACTIVE_ARCH = YES; 224 | SDKROOT = macosx; 225 | }; 226 | name = Debug; 227 | }; 228 | 3255677F17DEF2440067F677 /* Release */ = { 229 | isa = XCBuildConfiguration; 230 | buildSettings = { 231 | ALWAYS_SEARCH_USER_PATHS = NO; 232 | ARCHS = "$(ARCHS_STANDARD_64_BIT)"; 233 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; 234 | CLANG_CXX_LIBRARY = "libc++"; 235 | CLANG_WARN_CONSTANT_CONVERSION = YES; 236 | CLANG_WARN_EMPTY_BODY = YES; 237 | CLANG_WARN_ENUM_CONVERSION = YES; 238 | CLANG_WARN_INT_CONVERSION = YES; 239 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 240 | COPY_PHASE_STRIP = YES; 241 | DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; 242 | GCC_C_LANGUAGE_STANDARD = gnu99; 243 | GCC_ENABLE_OBJC_EXCEPTIONS = YES; 244 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 245 | GCC_WARN_ABOUT_RETURN_TYPE = YES; 246 | GCC_WARN_UNINITIALIZED_AUTOS = YES; 247 | GCC_WARN_UNUSED_VARIABLE = YES; 248 | MACOSX_DEPLOYMENT_TARGET = 10.8; 249 | SDKROOT = macosx; 250 | }; 251 | name = Release; 252 | }; 253 | 3255678117DEF2440067F677 /* Debug */ = { 254 | isa = XCBuildConfiguration; 255 | buildSettings = { 256 | ARCHS = "$(ARCHS_STANDARD_32_BIT)"; 257 | EXECUTABLE_PREFIX = lib; 258 | HEADER_SEARCH_PATHS = "../SaleaeAnalyzerSdk-1.1.9/include"; 259 | LIBRARY_SEARCH_PATHS = ( 260 | "$(inherited)", 261 | "\"$(SYSTEM_APPS_DIR)/Logic.app/Contents/MacOS\"", 262 | ); 263 | PRODUCT_NAME = "$(TARGET_NAME)"; 264 | }; 265 | name = Debug; 266 | }; 267 | 3255678217DEF2440067F677 /* Release */ = { 268 | isa = XCBuildConfiguration; 269 | buildSettings = { 270 | ARCHS = "$(ARCHS_STANDARD_32_BIT)"; 271 | EXECUTABLE_PREFIX = lib; 272 | HEADER_SEARCH_PATHS = "../SaleaeAnalyzerSdk-1.1.9/include"; 273 | LIBRARY_SEARCH_PATHS = ( 274 | "$(inherited)", 275 | "\"$(SYSTEM_APPS_DIR)/Logic.app/Contents/MacOS\"", 276 | ); 277 | PRODUCT_NAME = "$(TARGET_NAME)"; 278 | }; 279 | name = Release; 280 | }; 281 | /* End XCBuildConfiguration section */ 282 | 283 | /* Begin XCConfigurationList section */ 284 | 3255677717DEF2440067F677 /* Build configuration list for PBXProject "ISO7816Analyser" */ = { 285 | isa = XCConfigurationList; 286 | buildConfigurations = ( 287 | 3255677E17DEF2440067F677 /* Debug */, 288 | 3255677F17DEF2440067F677 /* Release */, 289 | ); 290 | defaultConfigurationIsVisible = 0; 291 | defaultConfigurationName = Release; 292 | }; 293 | 3255678017DEF2440067F677 /* Build configuration list for PBXNativeTarget "ISO7816Analyser" */ = { 294 | isa = XCConfigurationList; 295 | buildConfigurations = ( 296 | 3255678117DEF2440067F677 /* Debug */, 297 | 3255678217DEF2440067F677 /* Release */, 298 | ); 299 | defaultConfigurationIsVisible = 0; 300 | }; 301 | /* End XCConfigurationList section */ 302 | }; 303 | rootObject = 3255677417DEF2440067F677 /* Project object */; 304 | } 305 | -------------------------------------------------------------------------------- /ISO7816Analyser/ISO7816Analyser.xcodeproj/project.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /Licenses.txt: -------------------------------------------------------------------------------- 1 | Licenses and Credits 2 | 3 | This application is largely open source. This document details the various licenses and gives credit where credit is due. 4 | 5 | This analyser is based on the SaleaeAnalyzerSdk-1.1.9 in general; and the Serial example in particular. 6 | 7 | -- Main Library -- 8 | 9 | Copyright © 2013 Dirk-Willem van Gulik , all rights reserved. 10 | 11 | Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at: 12 | 13 | http://www.apache.org/licenses/LICENSE-2.0 14 | 15 | Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. 16 | 17 | 18 | -- Third party libraries -- 19 | 20 | 21 | -------------------------------------------------------------------------------- /README.txt: -------------------------------------------------------------------------------- 1 | This build assumes the SDK to be located in this directory and to be called 2 | 3 | SaleaeAnalyzerSdk-1.1.23 4 | 5 | Unzipping the SaleaeAnalyzerSdk-1.1.23.zip distribution in this directory 6 | should do the trick. I norder to compile Windows version unzip the SDK into 7 | the following directories: 8 | - ../sdk/include - for headers (*.hpp) 9 | - ../sdk/lib - for libraris 10 | 11 | Files and Directories: 12 | 13 | source 14 | Actual source code; including a simple Makefile. 15 | 16 | ISO7816Analyser 17 | XCode build environment for above source. 18 | 19 | VCProj 20 | VC2015 build environment for above source. 21 | 22 | Licenses.txt 23 | License information. 24 | 25 | README.txt 26 | This file 27 | 28 | SaleaeAnalyzerSdk-1.1.25 29 | Not distrubuted; but expected name and location of the SDK. The makefile 30 | and X-Code build files have hardcoded paths to the include. 31 | Please download it from: http://support.saleae.com/hc/en-us/categories/200077184-sdks-automation-betas 32 | -------------------------------------------------------------------------------- /VCProj/.gitignore: -------------------------------------------------------------------------------- 1 | /x64/ 2 | /.vs/ 3 | *.vcxproj.user 4 | -------------------------------------------------------------------------------- /VCProj/Iso7816.sln: -------------------------------------------------------------------------------- 1 |  2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio 14 4 | VisualStudioVersion = 14.0.24720.0 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "Iso7816", "Iso7816.vcxproj", "{B233CF02-B0A7-46D8-B7B0-4B9FC2B67306}" 7 | EndProject 8 | Global 9 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 10 | Debug|x64 = Debug|x64 11 | Debug|x86 = Debug|x86 12 | Release|x64 = Release|x64 13 | Release|x86 = Release|x86 14 | EndGlobalSection 15 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 16 | {B233CF02-B0A7-46D8-B7B0-4B9FC2B67306}.Debug|x64.ActiveCfg = Debug|x64 17 | {B233CF02-B0A7-46D8-B7B0-4B9FC2B67306}.Debug|x64.Build.0 = Debug|x64 18 | {B233CF02-B0A7-46D8-B7B0-4B9FC2B67306}.Debug|x86.ActiveCfg = Debug|Win32 19 | {B233CF02-B0A7-46D8-B7B0-4B9FC2B67306}.Debug|x86.Build.0 = Debug|Win32 20 | {B233CF02-B0A7-46D8-B7B0-4B9FC2B67306}.Release|x64.ActiveCfg = Release|x64 21 | {B233CF02-B0A7-46D8-B7B0-4B9FC2B67306}.Release|x64.Build.0 = Release|x64 22 | {B233CF02-B0A7-46D8-B7B0-4B9FC2B67306}.Release|x86.ActiveCfg = Release|Win32 23 | {B233CF02-B0A7-46D8-B7B0-4B9FC2B67306}.Release|x86.Build.0 = Release|Win32 24 | EndGlobalSection 25 | GlobalSection(SolutionProperties) = preSolution 26 | HideSolutionNode = FALSE 27 | EndGlobalSection 28 | EndGlobal 29 | -------------------------------------------------------------------------------- /VCProj/Iso7816.vcxproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | Debug 6 | Win32 7 | 8 | 9 | Release 10 | Win32 11 | 12 | 13 | Debug 14 | x64 15 | 16 | 17 | Release 18 | x64 19 | 20 | 21 | 22 | {B233CF02-B0A7-46D8-B7B0-4B9FC2B67306} 23 | Win32Proj 24 | Iso7816 25 | 8.1 26 | 27 | 28 | 29 | DynamicLibrary 30 | true 31 | v140 32 | Unicode 33 | 34 | 35 | DynamicLibrary 36 | false 37 | v140 38 | true 39 | Unicode 40 | 41 | 42 | DynamicLibrary 43 | true 44 | v140 45 | Unicode 46 | 47 | 48 | DynamicLibrary 49 | false 50 | v140 51 | true 52 | Unicode 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | true 74 | C:\projects\Saleae\sdk\include;$(IncludePath) 75 | C:\projects\Saleae\sdk\lib;$(LibraryPath) 76 | 77 | 78 | true 79 | C:\projects\Saleae\sdk\include;$(IncludePath) 80 | C:\projects\Saleae\sdk\lib;$(LibraryPath) 81 | 82 | 83 | false 84 | 85 | 86 | false 87 | 88 | 89 | 90 | 91 | 92 | Level3 93 | Disabled 94 | WIN32;_DEBUG;_WINDOWS;_USRDLL;ISO7816_EXPORTS;%(PreprocessorDefinitions) 95 | 96 | 97 | Windows 98 | true 99 | kernel32.lib;user32.lib;gdi32.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;odbc32.lib;odbccp32.lib;%(AdditionalDependencies) Analyzer.lib 100 | 101 | 102 | 103 | 104 | 105 | 106 | Level3 107 | Disabled 108 | _DEBUG;_WINDOWS;_USRDLL;ISO7816_EXPORTS;%(PreprocessorDefinitions) 109 | MultiThreadedDebug 110 | 111 | 112 | Windows 113 | true 114 | kernel32.lib;user32.lib;gdi32.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;odbc32.lib;odbccp32.lib;%(AdditionalDependencies) Analyzer64.lib 115 | 116 | 117 | 118 | 119 | Level3 120 | 121 | 122 | MaxSpeed 123 | true 124 | true 125 | WIN32;NDEBUG;_WINDOWS;_USRDLL;ISO7816_EXPORTS;%(PreprocessorDefinitions) 126 | 127 | 128 | Windows 129 | true 130 | true 131 | true 132 | 133 | 134 | 135 | 136 | Level3 137 | 138 | 139 | MaxSpeed 140 | true 141 | true 142 | NDEBUG;_WINDOWS;_USRDLL;ISO7816_EXPORTS;%(PreprocessorDefinitions) 143 | 144 | 145 | Windows 146 | true 147 | true 148 | true 149 | 150 | 151 | 152 | 153 | 154 | 155 | 156 | 157 | 158 | 159 | 160 | 161 | 162 | 163 | 164 | 165 | 166 | 167 | 168 | 169 | 170 | 171 | 172 | 173 | 174 | 175 | 176 | 177 | -------------------------------------------------------------------------------- /VCProj/Iso7816.vcxproj.filters: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | {4FC737F1-C7A5-4376-A066-2A32D752A2FF} 6 | cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx 7 | 8 | 9 | {93995380-89BD-4b04-88EB-625FBE52EBFB} 10 | h;hh;hpp;hxx;hm;inl;inc;xsd 11 | 12 | 13 | {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} 14 | rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms 15 | 16 | 17 | {40152526-b753-437a-b4c1-3a4fab829fe5} 18 | 19 | 20 | 21 | 22 | Header Files 23 | 24 | 25 | Header Files 26 | 27 | 28 | Header Files 29 | 30 | 31 | Header Files 32 | 33 | 34 | Util 35 | 36 | 37 | Util 38 | 39 | 40 | Util 41 | 42 | 43 | Util 44 | 45 | 46 | Util 47 | 48 | 49 | Util 50 | 51 | 52 | Util 53 | 54 | 55 | 56 | 57 | Source Files 58 | 59 | 60 | Source Files 61 | 62 | 63 | Source Files 64 | 65 | 66 | Source Files 67 | 68 | 69 | Util 70 | 71 | 72 | Util 73 | 74 | 75 | Util 76 | 77 | 78 | Util 79 | 80 | 81 | -------------------------------------------------------------------------------- /source/ByteBuffer.hpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dirkx/saleae-logic-ISO7816-smartcard-Analyser/71f8c64ef8e8837992db3a3d1f3d83f6b14fac6a/source/ByteBuffer.hpp -------------------------------------------------------------------------------- /source/ByteElement.hpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dirkx/saleae-logic-ISO7816-smartcard-Analyser/71f8c64ef8e8837992db3a3d1f3d83f6b14fac6a/source/ByteElement.hpp -------------------------------------------------------------------------------- /source/Convert.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dirkx/saleae-logic-ISO7816-smartcard-Analyser/71f8c64ef8e8837992db3a3d1f3d83f6b14fac6a/source/Convert.cpp -------------------------------------------------------------------------------- /source/Convert.hpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dirkx/saleae-logic-ISO7816-smartcard-Analyser/71f8c64ef8e8837992db3a3d1f3d83f6b14fac6a/source/Convert.hpp -------------------------------------------------------------------------------- /source/Definitions.hpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dirkx/saleae-logic-ISO7816-smartcard-Analyser/71f8c64ef8e8837992db3a3d1f3d83f6b14fac6a/source/Definitions.hpp -------------------------------------------------------------------------------- /source/ISO7816Pps.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dirkx/saleae-logic-ISO7816-smartcard-Analyser/71f8c64ef8e8837992db3a3d1f3d83f6b14fac6a/source/ISO7816Pps.cpp -------------------------------------------------------------------------------- /source/ISO7816Pps.hpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dirkx/saleae-logic-ISO7816-smartcard-Analyser/71f8c64ef8e8837992db3a3d1f3d83f6b14fac6a/source/ISO7816Pps.hpp -------------------------------------------------------------------------------- /source/Logging.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dirkx/saleae-logic-ISO7816-smartcard-Analyser/71f8c64ef8e8837992db3a3d1f3d83f6b14fac6a/source/Logging.cpp -------------------------------------------------------------------------------- /source/Logging.hpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dirkx/saleae-logic-ISO7816-smartcard-Analyser/71f8c64ef8e8837992db3a3d1f3d83f6b14fac6a/source/Logging.hpp -------------------------------------------------------------------------------- /source/Makefile: -------------------------------------------------------------------------------- 1 | SDK=../SaleaeAnalyzerSdk-1.1.9 2 | DYLIB=libISO7816Analyzer.dylib 3 | 4 | SRCS=iso7816Analyzer.cpp iso7816AnalyzerResults.cpp iso7816AnalyzerSettings.cpp iso7816SimulationDataGenerator.cpp 5 | GDB=-g -ggdb 6 | 7 | CFLAGS=-I"$(SDK)/include" -I. -O3 -w -c -fpic -Wall $(GDB) -m32 8 | LDFLAGS=-L/Applications/Logic.app/Contents/MacOS -lAnalyzer -dynamiclib $(GDB) -m32 9 | OBJECTS=$(SRCS:.cpp=.o) 10 | CC=g++ 11 | 12 | all: clean $(OBJECTS) $(DYLIB) Makefile 13 | 14 | clean: 15 | rm -f $(OBJECTS) $(DYLIB) 16 | 17 | .cpp.o: 18 | $(CC) $(CFLAGS) $< -o $@ 19 | 20 | $(DYLIB): $(OBJECTS) 21 | $(CC) $(LDFLAGS) -o $(DYLIB) $(OBJECTS) 22 | -------------------------------------------------------------------------------- /source/SaleaeHelper.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dirkx/saleae-logic-ISO7816-smartcard-Analyser/71f8c64ef8e8837992db3a3d1f3d83f6b14fac6a/source/SaleaeHelper.cpp -------------------------------------------------------------------------------- /source/SaleaeHelper.hpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dirkx/saleae-logic-ISO7816-smartcard-Analyser/71f8c64ef8e8837992db3a3d1f3d83f6b14fac6a/source/SaleaeHelper.hpp -------------------------------------------------------------------------------- /source/iso7816Analyzer.cpp: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright © 2013 Dirk-Willem van Gulik , all rights reserved. 3 | // Copyright © 2016 Adam Augustyn , all rights reserved. 4 | // 5 | // Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at: 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. 10 | // 11 | 12 | 13 | #include "iso7816Analyzer.h" 14 | #include "iso7816AnalyzerSettings.h" 15 | 16 | #include 17 | #include 18 | #include 19 | #include "Logging.hpp" 20 | #include "Convert.hpp" 21 | #include "SaleaeHelper.hpp" 22 | #include "Definitions.hpp" 23 | #include "ISO7816Pps.hpp" 24 | 25 | static const unsigned char msb2lsb[] = 26 | { 27 | 0x00, 0x80, 0x40, 0xC0, 0x20, 0xA0, 0x60, 0xE0, 0x10, 0x90, 0x50, 0xD0, 0x30, 0xB0, 0x70, 0xF0, 28 | 0x08, 0x88, 0x48, 0xC8, 0x28, 0xA8, 0x68, 0xE8, 0x18, 0x98, 0x58, 0xD8, 0x38, 0xB8, 0x78, 0xF8, 29 | 0x04, 0x84, 0x44, 0xC4, 0x24, 0xA4, 0x64, 0xE4, 0x14, 0x94, 0x54, 0xD4, 0x34, 0xB4, 0x74, 0xF4, 30 | 0x0C, 0x8C, 0x4C, 0xCC, 0x2C, 0xAC, 0x6C, 0xEC, 0x1C, 0x9C, 0x5C, 0xDC, 0x3C, 0xBC, 0x7C, 0xFC, 31 | 0x02, 0x82, 0x42, 0xC2, 0x22, 0xA2, 0x62, 0xE2, 0x12, 0x92, 0x52, 0xD2, 0x32, 0xB2, 0x72, 0xF2, 32 | 0x0A, 0x8A, 0x4A, 0xCA, 0x2A, 0xAA, 0x6A, 0xEA, 0x1A, 0x9A, 0x5A, 0xDA, 0x3A, 0xBA, 0x7A, 0xFA, 33 | 0x06, 0x86, 0x46, 0xC6, 0x26, 0xA6, 0x66, 0xE6, 0x16, 0x96, 0x56, 0xD6, 0x36, 0xB6, 0x76, 0xF6, 34 | 0x0E, 0x8E, 0x4E, 0xCE, 0x2E, 0xAE, 0x6E, 0xEE, 0x1E, 0x9E, 0x5E, 0xDE, 0x3E, 0xBE, 0x7E, 0xFE, 35 | 0x01, 0x81, 0x41, 0xC1, 0x21, 0xA1, 0x61, 0xE1, 0x11, 0x91, 0x51, 0xD1, 0x31, 0xB1, 0x71, 0xF1, 36 | 0x09, 0x89, 0x49, 0xC9, 0x29, 0xA9, 0x69, 0xE9, 0x19, 0x99, 0x59, 0xD9, 0x39, 0xB9, 0x79, 0xF9, 37 | 0x05, 0x85, 0x45, 0xC5, 0x25, 0xA5, 0x65, 0xE5, 0x15, 0x95, 0x55, 0xD5, 0x35, 0xB5, 0x75, 0xF5, 38 | 0x0D, 0x8D, 0x4D, 0xCD, 0x2D, 0xAD, 0x6D, 0xED, 0x1D, 0x9D, 0x5D, 0xDD, 0x3D, 0xBD, 0x7D, 0xFD, 39 | 0x03, 0x83, 0x43, 0xC3, 0x23, 0xA3, 0x63, 0xE3, 0x13, 0x93, 0x53, 0xD3, 0x33, 0xB3, 0x73, 0xF3, 40 | 0x0B, 0x8B, 0x4B, 0xCB, 0x2B, 0xAB, 0x6B, 0xEB, 0x1B, 0x9B, 0x5B, 0xDB, 0x3B, 0xBB, 0x7B, 0xFB, 41 | 0x07, 0x87, 0x47, 0xC7, 0x27, 0xA7, 0x67, 0xE7, 0x17, 0x97, 0x57, 0xD7, 0x37, 0xB7, 0x77, 0xF7, 42 | 0x0F, 0x8F, 0x4F, 0xCF, 0x2F, 0xAF, 0x6F, 0xEF, 0x1F, 0x9F, 0x5F, 0xDF, 0x3F, 0xBF, 0x7F, 0xFF 43 | }; 44 | 45 | static const bool parity[256] = 46 | { 47 | # define P2(n) n, n^1, n^1, n 48 | # define P4(n) P2(n), P2(n^1), P2(n^1), P2(n) 49 | # define P6(n) P4(n), P4(n^1), P4(n^1), P4(n) 50 | P6(0), P6(1), P6(1), P6(0) 51 | }; 52 | 53 | iso7816Analyzer::iso7816Analyzer() 54 | : Analyzer2(), 55 | mSettings( new iso7816AnalyzerSettings() ), 56 | mSimulationInitilized( false ) 57 | { 58 | SetAnalyzerSettings( mSettings.get() ); 59 | } 60 | 61 | iso7816Analyzer::~iso7816Analyzer() 62 | { 63 | KillThread(); 64 | } 65 | 66 | void iso7816Analyzer::WorkerThread() 67 | { 68 | try 69 | { 70 | Logging::Write("Start"); 71 | _WorkerThread(); 72 | Logging::Write("Stop"); 73 | } 74 | catch (std::exception &e) 75 | { 76 | Logging::Write(std::string("[Exception] ") + e.what()); 77 | } 78 | catch (...) 79 | { 80 | Logging::Write("[Exception] Unknown error"); 81 | } 82 | } 83 | 84 | void iso7816Analyzer::SetupResults() 85 | { 86 | mResults.reset(new iso7816AnalyzerResults(this, mSettings.get())); 87 | SetAnalyzerResults(mResults.get()); 88 | mResults->AddChannelBubblesWillAppearOn(mSettings->mIoChannel); 89 | mResults->AddChannelBubblesWillAppearOn(mSettings->mResetChannel); 90 | 91 | Logging::Write(std::string("SimulationSampleRate: ") + Convert::ToDec(GetSimulationSampleRate())); 92 | Logging::Write(std::string("SampleRate: ") + Convert::ToDec(GetSampleRate())); 93 | Logging::Write(std::string("TriggerSample: ") + Convert::ToDec(GetTriggerSample())); 94 | } 95 | 96 | void iso7816Analyzer::_WorkerThread() 97 | { 98 | iso7816_mode_t mode; 99 | 100 | mIo = GetAnalyzerChannelData( mSettings->mIoChannel ); 101 | mReset = GetAnalyzerChannelData( mSettings->mResetChannel ); 102 | mVcc = GetAnalyzerChannelData(mSettings->mVccChannel); 103 | mClk = GetAnalyzerChannelData(mSettings->mClkChannel); 104 | 105 | for( ; ; ) { 106 | // seek for a RESET going high. 107 | // 108 | mReset->AdvanceToNextEdge(); 109 | 110 | if (mReset->GetBitState() != BIT_HIGH ) 111 | continue; 112 | 113 | // discard all serial data until now. 114 | U64 reset = mReset->GetSampleNumber(); 115 | Logging::Write(std::string("Reset detected: ") + Convert::ToDec(reset)); 116 | mIo->AdvanceToAbsPosition(reset); 117 | 118 | // mark the start in pretty much all channels. 119 | // 120 | // mResults->AddMarker(mReset->GetSampleNumber(), AnalyzerResults::UpArrow, mSettings->mResetChannel); 121 | // mResults->AddMarker(mIo->GetSampleNumber(), AnalyzerResults::UpArrow, mSettings->mIoChannel); 122 | 123 | // We know expect a TS (After some 400 to 40k clock cycles of idleness XX). 124 | // We can use the first up/down dip to measure the baud rate. 125 | // 126 | // S01234567P S01234567P 127 | // HLHHLLLLLLH or HLHHLHHHLLH 128 | // 11000000 1 11011100 1 129 | // xC0 xDC 130 | // inverse direct convention 131 | // 132 | // search for first stop bit. 133 | // 134 | 135 | U64 etu = 0; 136 | U64 a0 = 0; 137 | while (true) 138 | { 139 | mClk->AdvanceToAbsPosition(mIo->GetSampleNumber()); 140 | U64 startBit = SaleaeHelper::AdvanceClkCycles(mClk, 400); 141 | Logging::Write(std::string("Start bit seeking: ") + Convert::ToDec(startBit)); 142 | mIo->AdvanceToAbsPosition(startBit); 143 | mResults->AddMarker(reset, AnalyzerResults::UpArrow, mSettings->mResetChannel); 144 | 145 | // seeking for falling edge 146 | while (mIo->GetBitState() != BIT_HIGH) 147 | { 148 | mIo->AdvanceToNextEdge(); 149 | } 150 | 151 | mIo->AdvanceToNextEdge(); 152 | a0 = mIo->GetSampleNumber(); 153 | mIo->AdvanceToNextEdge(); 154 | U64 a1 = mIo->GetSampleNumber(); 155 | 156 | mClk->AdvanceToAbsPosition(a0); 157 | U64 clocks = mClk->AdvanceToAbsPosition(a1) / 2; 158 | 159 | // default ETU shoud be 372 160 | if (!IsValidETU(clocks)) 161 | { 162 | Logging::Write(std::string("This is not a valid start bit: ") + Convert::ToDec(clocks) + std::string(" clocks...")); 163 | mIo->AdvanceToNextEdge(); 164 | continue; 165 | } 166 | etu = clocks; 167 | 168 | mResults->AddMarker(a0, AnalyzerResults::DownArrow, mSettings->mIoChannel); 169 | mResults->AddMarker(a0 + (a1 - a0) / 2, AnalyzerResults::Start, mSettings->mIoChannel); 170 | mResults->AddMarker(a1, AnalyzerResults::UpArrow, mSettings->mIoChannel); 171 | Logging::Write(std::string("Found the start bit, initial ETU: ") + Convert::ToDec(clocks) + std::string(" clocks...")); 172 | break; 173 | } 174 | 175 | if (!IsValidETU(etu)) 176 | { 177 | Logging::Write("Valid start bit not found, skipinng analysis..."); 178 | mIo->AdvanceToNextEdge(); 179 | continue; 180 | } 181 | 182 | if (mIo->GetBitState() != BIT_HIGH) { 183 | mResults->AddMarker(mIo->GetSampleNumber(), AnalyzerResults::ErrorDot, mSettings->mIoChannel); 184 | mResults->CommitResults(); 185 | Logging::Write("Start bit end error"); 186 | continue; 187 | } 188 | 189 | 190 | U16 data = 0; 191 | 192 | // move to the center of first data bit 193 | U64 bitPos = SaleaeHelper::AdvanceClkCycles(mClk, etu / 2); 194 | U64 pausePos = 0; 195 | for (U32 i = 0; i <= 8; i++) { 196 | // move to the center of what we're guessing as best as we can 197 | mIo->AdvanceToAbsPosition(bitPos); 198 | U8 bit = mIo->GetBitState() ? 1 : 0; 199 | mResults->AddMarker(mIo->GetSampleNumber(), bit ? AnalyzerResults::One : AnalyzerResults::Zero, mSettings->mIoChannel); 200 | data = (data <<1) | bit; 201 | if (i == 8) 202 | { 203 | pausePos = SaleaeHelper::AdvanceClkCycles(mClk, etu); 204 | } 205 | else 206 | { 207 | bitPos = SaleaeHelper::AdvanceClkCycles(mClk, etu); 208 | } 209 | }; 210 | bool p = 1 == (data & 1); 211 | data >>= 1; 212 | 213 | if (parity[data] != p) { 214 | mResults->AddMarker(bitPos, AnalyzerResults::ErrorDot, mSettings->mIoChannel); 215 | mResults->CommitResults(); 216 | Logging::Write("Parity error"); 217 | continue; 218 | }; 219 | 220 | mResults->AddMarker(bitPos, AnalyzerResults::Stop, mSettings->mIoChannel); 221 | if (mIo->GetBitState() != BIT_HIGH) { 222 | Logging::Write("Stop bit not high."); 223 | mResults->AddMarker(pausePos, AnalyzerResults::ErrorDot, mSettings->mIoChannel); 224 | mResults->CommitResults(); 225 | continue; 226 | }; 227 | 228 | switch(data & 0xFF) { 229 | case 0xC0: 230 | mode = INVERSE; 231 | Logging::Write("Inverse mode msb first trransmitted"); 232 | break; 233 | case 0xDC: 234 | mode = DIRECT; 235 | Logging::Write("Direct mode lsb first transmitted"); 236 | break; 237 | default: 238 | { 239 | Logging::Write(std::string("Unknown mode: ") + Convert::ToHex(data)); 240 | mResults->AddMarker(mIo->GetSampleNumber(), 241 | AnalyzerResults::ErrorDot, mSettings->mIoChannel); 242 | mResults->CommitResults(); 243 | continue; 244 | } 245 | } 246 | 247 | if (mode == INVERSE) { 248 | data = ~data; 249 | if (data != 0x3F) 250 | AnalyzerHelpers::Assert("Internal calculation issue or something similarly odd. Expected 0x3F for INVERSE mode."); 251 | }; 252 | if (mode == DIRECT) { 253 | data = msb2lsb[data & 0xFF]; 254 | if (data != 0x3B) 255 | AnalyzerHelpers::Assert("Internal calculation issue or something similarly odd. Expected 0x3B for DIRECT mode."); 256 | }; 257 | 258 | ppsFound = false; 259 | details.clear(); 260 | { 261 | Frame frame; 262 | frame.mData1 = 0; 263 | frame.mFlags = ATR; 264 | frame.mStartingSampleInclusive = reset; 265 | frame.mEndingSampleInclusive = mIo->GetSampleNumber(); 266 | 267 | mResults->AddFrame(frame); 268 | mResults->CommitResults(); 269 | } 270 | 271 | { 272 | Frame frame; 273 | frame.mData1 = 0; 274 | frame.mFlags = mode; 275 | frame.mStartingSampleInclusive = a0; 276 | frame.mEndingSampleInclusive = mIo->GetSampleNumber(); 277 | 278 | mResults->AddFrame( frame ); 279 | mResults->CommitResults(); 280 | } 281 | 282 | // now we keep waiting for the next 'down'; start bit 283 | // and then read our 10 bits, etc, etc. 284 | for(;;) { 285 | mIo->AdvanceToNextEdge(); //falling edge -- beginning of the start bit 286 | if (mIo->GetBitState() != BIT_LOW) { 287 | mResults->AddMarker(mIo->GetSampleNumber(), 288 | AnalyzerResults::ErrorDot, mSettings->mIoChannel); 289 | mResults->CommitResults(); 290 | Logging::Write(std::string("Out of sync with start bit.")); 291 | continue; 292 | }; 293 | 294 | U64 starting_sample = mIo->GetSampleNumber(); 295 | // synchronise CLK position 296 | mClk->AdvanceToAbsPosition(starting_sample); 297 | 298 | U64 bitPos = SaleaeHelper::AdvanceClkCycles(mClk, etu / 2); 299 | mIo->AdvanceToAbsPosition(bitPos); 300 | mResults->AddMarker(mIo->GetSampleNumber(), AnalyzerResults::Start, mSettings->mIoChannel); 301 | 302 | U16 data = 0; 303 | for(U32 i = 0; i <= 8; i++) { 304 | 305 | bitPos = SaleaeHelper::AdvanceClkCycles(mClk, etu); 306 | mIo->AdvanceToAbsPosition(bitPos); 307 | 308 | U8 bit = mIo->GetBitState() ? 1 : 0; 309 | mResults->AddMarker(mIo->GetSampleNumber(), bit ? AnalyzerResults::One : AnalyzerResults::Zero, mSettings->mIoChannel); 310 | 311 | data = (data <<1) | bit; 312 | }; 313 | 314 | bool p = 1 == (data & 1); 315 | data >>= 1; 316 | 317 | if (parity[ data ] != p) { 318 | mResults->AddMarker(mIo->GetSampleNumber(),AnalyzerResults::ErrorDot, mSettings->mIoChannel); 319 | mResults->CommitResults(); 320 | Logging::Write(std::string("Parity error")); 321 | break; 322 | }; 323 | 324 | bitPos = SaleaeHelper::AdvanceClkCycles(mClk, etu); 325 | mIo->AdvanceToAbsPosition(bitPos); 326 | if (mIo->GetBitState() != BIT_HIGH) { 327 | Logging::Write(std::string("Stop bit not high.")); 328 | mResults->AddMarker(mIo->GetSampleNumber(), AnalyzerResults::ErrorDot, mSettings->mIoChannel); 329 | mResults->CommitResults(); 330 | break; 331 | }; 332 | 333 | mResults->AddMarker(mIo->GetSampleNumber(), AnalyzerResults::Stop, mSettings->mIoChannel); 334 | 335 | if (mode == INVERSE) 336 | data = static_cast(!data) & 0xFF; 337 | else 338 | data = msb2lsb[data & 0xFF]; 339 | 340 | Logging::Write(std::string("data: ") + Convert::ToHex((unsigned char)data)); 341 | 342 | Frame frame; 343 | frame.mData1 = data; 344 | frame.mFlags = 0; 345 | frame.mStartingSampleInclusive = starting_sample; 346 | frame.mEndingSampleInclusive = mIo->GetSampleNumber(); 347 | 348 | mResults->AddFrame( frame ); 349 | mResults->CommitResults(); 350 | ReportProgress( frame.mEndingSampleInclusive ); 351 | 352 | 353 | size_t exchLen = 0; 354 | ISO7816Pps::ptr ppsData = SeekPPS(starting_sample, mIo->GetSampleNumber(), data, exchLen); 355 | if (ppsData) 356 | { 357 | Logging::Write(std::string("The new ETU value is: ") + Convert::ToDec(ppsData->GetEtu())); 358 | Logging::Write(std::string("PPS Exchange length is: ") + Convert::ToDec(exchLen) + std::string(" bytes")); 359 | etu = static_cast(ppsData->GetEtu()); 360 | 361 | { 362 | details.push_back(ppsData->ToString()); 363 | Frame frame; 364 | frame.mData1 = details.size() - 1; 365 | frame.mFlags = PPS; 366 | frame.mStartingSampleInclusive = pps[0].GetStartPos(); 367 | frame.mEndingSampleInclusive = pps[exchLen - 1].GetEndPos(); 368 | 369 | mResults->AddFrame(frame); 370 | mResults->CommitResults(); 371 | } 372 | pps.clear(); 373 | } 374 | } 375 | } 376 | } 377 | 378 | bool iso7816Analyzer::IsValidETU(U64 ea) 379 | { 380 | return ea > DEF_ETU_MIN && ea < DEF_ETU_MAX; 381 | } 382 | 383 | ISO7816Pps::ptr iso7816Analyzer::SeekPPS(U64 startPos, U64 endPos, U16 data, size_t& exchLen) 384 | { 385 | if (ppsFound) return ISO7816Pps::ptr(); 386 | 387 | pps.push_back(ByteElement(static_cast(data), startPos, endPos)); 388 | if (pps.size() >= 8 && pps[0].GetValue() != 0xff && pps[4].GetValue() != 0xff) 389 | { 390 | pps.erase(pps.begin()); 391 | } 392 | if (pps[0].GetValue() != 0xff) 393 | { 394 | pps.erase(pps.begin()); 395 | } 396 | 397 | //std::string tmp; 398 | //for (std::vector::iterator iter = pps.begin(); iter != pps.end(); iter++) 399 | //{ 400 | // tmp += Convert::ToHex((unsigned char)*iter); 401 | //} 402 | //if (!tmp.empty()) 403 | //{ 404 | // Logging::Write(tmp); 405 | //} 406 | 407 | int res = ISO7816Pps::IsPpsFrame(pps.ToBytes(), 0); 408 | //Logging::Write(std::string("ISO7816Pps::IsPpsFrame: ") + Convert::ToDec(res)); 409 | if (res > 0) 410 | { 411 | ISO7816Pps::ptr frm1 = ISO7816Pps::DecodeFrame(pps.ToBytes(), 0); 412 | int res2 = ISO7816Pps::IsPpsFrame(pps.ToBytes(), res); 413 | if (res2 > 0) 414 | { 415 | ISO7816Pps::ptr frm2 = ISO7816Pps::DecodeFrame(pps.ToBytes(), res); 416 | 417 | // we are not able to decode frame 2 - not enough data? 418 | if (!frm2) return ISO7816Pps::ptr(); 419 | 420 | // check if the frames are equal 421 | if (!frm1->Equal(frm2)) 422 | { 423 | // remove first byte from the buffer and... fail 424 | pps.erase(pps.begin()); 425 | return ISO7816Pps::ptr(); 426 | } 427 | // they are the same 428 | Logging::Write(std::string("PPS detected, fi: ") + Convert::ToDec(frm1->GetFi()) + std::string(", di: ") + Convert::ToDec(frm1->GetDi())); 429 | int _etu = ISO7816Pps::CalculateETU(frm1->GetFi(), frm1->GetDi()); 430 | Logging::Write(std::string("New ETU: ") + Convert::ToDec(_etu)); 431 | 432 | if (_etu > 0) 433 | { 434 | exchLen = (size_t)res2; 435 | ppsFound = true; 436 | return frm2; 437 | } 438 | return ISO7816Pps::ptr(); 439 | } 440 | } 441 | return ISO7816Pps::ptr(); 442 | } 443 | 444 | bool iso7816Analyzer::NeedsRerun() 445 | { 446 | return false; 447 | } 448 | 449 | U32 iso7816Analyzer::GenerateSimulationData( U64 minimum_sample_index, U32 device_sample_rate, SimulationChannelDescriptor** simulation_channels ) 450 | { 451 | if( mSimulationInitilized == false ) 452 | { 453 | mSimulationDataGenerator.Initialize( GetSimulationSampleRate(), mSettings.get() ); 454 | mSimulationInitilized = true; 455 | } 456 | 457 | return mSimulationDataGenerator.GenerateSimulationData( minimum_sample_index, device_sample_rate, simulation_channels ); 458 | } 459 | 460 | U32 iso7816Analyzer::GetMinimumSampleRateHz() 461 | { 462 | return 0; 463 | } 464 | 465 | const char* iso7816Analyzer::GetAnalyzerName() const 466 | { 467 | return "ISO 7816 SmartCard"; 468 | } 469 | 470 | const char* GetAnalyzerName() 471 | { 472 | return "ISO 7816 SmartCard"; 473 | } 474 | 475 | Analyzer* CreateAnalyzer() 476 | { 477 | return new iso7816Analyzer(); 478 | } 479 | 480 | void DestroyAnalyzer( Analyzer* analyzer ) 481 | { 482 | delete analyzer; 483 | } 484 | -------------------------------------------------------------------------------- /source/iso7816Analyzer.h: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright © 2013 Dirk-Willem van Gulik , all rights reserved. 3 | // Copyright © 2016 Adam Augustyn , all rights reserved. 4 | // 5 | // Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at: 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. 10 | // 11 | 12 | #ifndef ISO7816_ANALYZER_H 13 | #define ISO7816_ANALYZER_H 14 | 15 | #include 16 | 17 | #include 18 | #include 19 | #include 20 | 21 | #include "iso7816AnalyzerResults.h" 22 | #include "iso7816SimulationDataGenerator.h" 23 | #include "ByteBuffer.hpp" 24 | #include "ISO7816Pps.hpp" 25 | 26 | typedef enum { 27 | UNK = 0x01, 28 | DIRECT = 0x02, 29 | INVERSE = 0x04, 30 | ATR = 0x10, 31 | PPS = 0x20 32 | } iso7816_mode_t; 33 | 34 | class iso7816AnalyzerSettings; 35 | class ANALYZER_EXPORT iso7816Analyzer : public Analyzer2 36 | { 37 | public: 38 | iso7816Analyzer(); 39 | virtual ~iso7816Analyzer(); 40 | virtual void SetupResults(); 41 | virtual void WorkerThread(); 42 | 43 | virtual U32 GenerateSimulationData( U64 newest_sample_requested, U32 sample_rate, SimulationChannelDescriptor** simulation_channels ); 44 | virtual U32 GetMinimumSampleRateHz(); 45 | 46 | virtual const char* GetAnalyzerName() const; 47 | virtual bool NeedsRerun(); 48 | 49 | std::string GetDetails(int idx) 50 | { 51 | if (idx < 0) return std::string(); 52 | if (idx >= details.size()) return std::string(); 53 | return details[idx]; 54 | } 55 | 56 | protected: 57 | virtual void _WorkerThread(); 58 | bool IsValidETU(U64 ea); 59 | ISO7816Pps::ptr SeekPPS(U64 startPos, U64 endPos, U16 data, size_t& exchLen); 60 | 61 | int CountClockPulses(U64 from, U64 to); 62 | 63 | 64 | protected: //vars 65 | std::auto_ptr< iso7816AnalyzerSettings > mSettings; 66 | std::auto_ptr< iso7816AnalyzerResults > mResults; 67 | 68 | bool ppsFound; 69 | ByteBuffer pps; 70 | std::vector details; 71 | 72 | AnalyzerChannelData* mIo; 73 | AnalyzerChannelData* mReset; 74 | AnalyzerChannelData* mVcc; 75 | AnalyzerChannelData* mClk; 76 | 77 | iso7816SimulationDataGenerator mSimulationDataGenerator; 78 | bool mSimulationInitilized; 79 | }; 80 | 81 | extern "C" ANALYZER_EXPORT const char* __cdecl GetAnalyzerName(); 82 | extern "C" ANALYZER_EXPORT Analyzer* __cdecl CreateAnalyzer( ); 83 | extern "C" ANALYZER_EXPORT void __cdecl DestroyAnalyzer( Analyzer* analyzer ); 84 | 85 | #endif //ISO7816_ANALYZER_H 86 | -------------------------------------------------------------------------------- /source/iso7816AnalyzerResults.cpp: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright © 2013 Dirk-Willem van Gulik , all rights reserved. 3 | // Copyright © 2016 Adam Augustyn , all rights reserved. 4 | // 5 | // Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at: 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. 10 | // 11 | 12 | #include "iso7816AnalyzerResults.h" 13 | #include 14 | #include "iso7816Analyzer.h" 15 | #include "iso7816AnalyzerSettings.h" 16 | #include 17 | #include 18 | 19 | iso7816AnalyzerResults::iso7816AnalyzerResults( iso7816Analyzer* analyzer, iso7816AnalyzerSettings* settings ) 20 | : AnalyzerResults(), 21 | mSettings( settings ), 22 | mAnalyzer( analyzer ) 23 | { 24 | } 25 | 26 | iso7816AnalyzerResults::~iso7816AnalyzerResults() 27 | { 28 | } 29 | #if 0 30 | void iso7816AnalyzerResults::GenerateBubbleText( U64 frame_index, Channel& channel, DisplayBase display_base ) 31 | { 32 | ClearResultStrings(); 33 | Frame frame = GetFrame( frame_index ); 34 | 35 | char number_str[128]; 36 | AnalyzerHelpers::GetNumberString( frame.mData1, display_base, 8, number_str, 128 ); 37 | AddResultString( number_str ); 38 | } 39 | #endif 40 | 41 | void iso7816AnalyzerResults::GenerateBubbleText(U64 frame_index, Channel& channel, DisplayBase display_base) //unrefereced vars commented out to remove warnings. 42 | { 43 | char number_str[128]; 44 | //we only need to pay attention to 'channel' if we're making bubbles for more than one channel (as set by AddChannelBubblesWillAppearOn) 45 | ClearResultStrings(); 46 | Frame frame = GetFrame(frame_index); 47 | 48 | if (channel == mSettings->mResetChannel) 49 | { 50 | switch (frame.mFlags) 51 | { 52 | case ATR: 53 | AddResultString("A"); 54 | AddResultString("ATR"); 55 | AddResultString("ATR"); 56 | break; 57 | 58 | case PPS: 59 | AddResultString("P"); 60 | AddResultString("PPS"); 61 | AddResultString("PPS: ", ((iso7816Analyzer*)mAnalyzer)->GetDetails(static_cast(frame.mData1)).c_str()); 62 | break; 63 | 64 | default: 65 | break; 66 | } 67 | } 68 | else 69 | { 70 | switch (frame.mFlags) 71 | { 72 | case 0: 73 | AnalyzerHelpers::GetNumberString(frame.mData1, display_base, 8, number_str, sizeof(number_str)); 74 | AddResultString(number_str); 75 | break; 76 | 77 | case INVERSE: 78 | AddResultString("I"); 79 | AddResultString("INV"); 80 | AddResultString("Hdr(INVERSE)"); 81 | break; 82 | 83 | case DIRECT: 84 | AddResultString("D"); 85 | AddResultString("DIR"); 86 | AddResultString("Hdr(DIRECT)"); 87 | break; 88 | 89 | case ATR: 90 | break; 91 | 92 | case PPS: 93 | break; 94 | 95 | default: 96 | AddResultString("?"); 97 | AnalyzerHelpers::GetNumberString(frame.mFlags, display_base, 8, number_str, sizeof(number_str)); 98 | AddResultString(number_str); 99 | break; 100 | } 101 | } 102 | } 103 | 104 | void iso7816AnalyzerResults::GenerateExportFile( const char* file, DisplayBase display_base, U32 export_type_user_id ) 105 | { 106 | std::ofstream file_stream( file, std::ios::out ); 107 | 108 | U64 trigger_sample = mAnalyzer->GetTriggerSample(); 109 | U32 sample_rate = mAnalyzer->GetSampleRate(); 110 | 111 | file_stream << "Time [s],Value" << std::endl; 112 | 113 | U64 num_frames = GetNumFrames(); 114 | for( U32 i=0; i < num_frames; i++ ) 115 | { 116 | Frame frame = GetFrame( i ); 117 | 118 | char time_str[128]; 119 | AnalyzerHelpers::GetTimeString( frame.mStartingSampleInclusive, trigger_sample, sample_rate, time_str, 128 ); 120 | 121 | char number_str[128]; 122 | AnalyzerHelpers::GetNumberString( frame.mData1, display_base, 8, number_str, 128 ); 123 | 124 | file_stream << time_str << "," << number_str << std::endl; 125 | 126 | if( UpdateExportProgressAndCheckForCancel( i, num_frames ) == true ) 127 | { 128 | file_stream.close(); 129 | return; 130 | } 131 | } 132 | 133 | file_stream.close(); 134 | } 135 | 136 | void iso7816AnalyzerResults::GenerateFrameTabularText( U64 frame_index, DisplayBase display_base ) 137 | { 138 | Frame frame = GetFrame( frame_index ); 139 | ClearResultStrings(); 140 | 141 | char number_str[128]; 142 | AnalyzerHelpers::GetNumberString( frame.mData1, display_base, 8, number_str, 128 ); 143 | AddResultString( number_str ); 144 | } 145 | 146 | void iso7816AnalyzerResults::GeneratePacketTabularText( U64 packet_id, DisplayBase display_base ) 147 | { 148 | ClearResultStrings(); 149 | AddResultString( "not supported" ); 150 | } 151 | 152 | void iso7816AnalyzerResults::GenerateTransactionTabularText( U64 transaction_id, DisplayBase display_base ) 153 | { 154 | ClearResultStrings(); 155 | AddResultString( "not supported" ); 156 | } 157 | -------------------------------------------------------------------------------- /source/iso7816AnalyzerResults.h: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright © 2013 Dirk-Willem van Gulik , all rights reserved. 3 | // Copyright © 2016 Adam Augustyn , all rights reserved. 4 | // 5 | // Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at: 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. 10 | // 11 | 12 | #ifndef ISO7816_ANALYZER_RESULTS 13 | #define ISO7816_ANALYZER_RESULTS 14 | 15 | #include 16 | 17 | class iso7816Analyzer; 18 | class iso7816AnalyzerSettings; 19 | 20 | class iso7816AnalyzerResults : public AnalyzerResults 21 | { 22 | public: 23 | iso7816AnalyzerResults( iso7816Analyzer* analyzer, iso7816AnalyzerSettings* settings ); 24 | virtual ~iso7816AnalyzerResults(); 25 | 26 | virtual void GenerateBubbleText( U64 frame_index, Channel& channel, DisplayBase display_base ); 27 | virtual void GenerateExportFile( const char* file, DisplayBase display_base, U32 export_type_user_id ); 28 | 29 | virtual void GenerateFrameTabularText(U64 frame_index, DisplayBase display_base ); 30 | virtual void GeneratePacketTabularText( U64 packet_id, DisplayBase display_base ); 31 | virtual void GenerateTransactionTabularText( U64 transaction_id, DisplayBase display_base ); 32 | 33 | protected: //functions 34 | 35 | protected: //vars 36 | iso7816AnalyzerSettings* mSettings; 37 | iso7816Analyzer* mAnalyzer; 38 | }; 39 | 40 | #endif //ISO7816_ANALYZER_RESULTS 41 | -------------------------------------------------------------------------------- /source/iso7816AnalyzerSettings.cpp: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright © 2013 Dirk-Willem van Gulik , all rights reserved. 3 | // Copyright © 2016 Adam Augustyn , all rights reserved. 4 | // 5 | // Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at: 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. 10 | // 11 | 12 | #include "iso7816AnalyzerSettings.h" 13 | #include 14 | 15 | iso7816AnalyzerSettings::iso7816AnalyzerSettings() 16 | : mVccChannel( UNDEFINED_CHANNEL ), 17 | mResetChannel( UNDEFINED_CHANNEL ), 18 | mClkChannel( UNDEFINED_CHANNEL ), 19 | mIoChannel( UNDEFINED_CHANNEL ) 20 | { 21 | mVccChannelInterface.reset( new AnalyzerSettingInterfaceChannel() ); 22 | mClkChannelInterface.reset( new AnalyzerSettingInterfaceChannel() ); 23 | mResetChannelInterface.reset( new AnalyzerSettingInterfaceChannel() ); 24 | mIoChannelInterface.reset( new AnalyzerSettingInterfaceChannel() ); 25 | 26 | mVccChannelInterface->SetTitleAndTooltip( "VCC/C1", "C1" ); 27 | mResetChannelInterface->SetTitleAndTooltip( "RST/C2", "C2 - Reset" ); 28 | mClkChannelInterface->SetTitleAndTooltip( "CLK/C3", "C3 - SCL or CLK" ); 29 | mIoChannelInterface->SetTitleAndTooltip( "IO/C7", "C7 - SDA or IO" ); 30 | 31 | mVccChannelInterface->SetChannel( mVccChannel ); 32 | mResetChannelInterface->SetChannel( mResetChannel ); 33 | mClkChannelInterface->SetChannel( mClkChannel ); 34 | mIoChannelInterface->SetChannel( mIoChannel ); 35 | 36 | AddInterface( mVccChannelInterface.get() ); 37 | AddInterface( mResetChannelInterface.get() ); 38 | AddInterface( mClkChannelInterface.get() ); 39 | AddInterface( mIoChannelInterface.get() ); 40 | 41 | AddExportOption( 0, "Export as text/csv file" ); 42 | AddExportExtension( 0, "text", "txt" ); 43 | 44 | ClearChannels(); 45 | AddChannel( mVccChannel, "VCC", false ); 46 | AddChannel( mResetChannel, "RST", false ); 47 | AddChannel( mClkChannel, "SCL/CLK", false ); 48 | AddChannel( mIoChannel, "SDA/IO", false ); 49 | } 50 | 51 | iso7816AnalyzerSettings::~iso7816AnalyzerSettings() 52 | { 53 | } 54 | 55 | bool iso7816AnalyzerSettings::SetSettingsFromInterfaces() 56 | { 57 | mVccChannel = mVccChannelInterface->GetChannel(); 58 | mResetChannel = mResetChannelInterface->GetChannel(); 59 | mClkChannel = mClkChannelInterface->GetChannel(); 60 | mIoChannel = mIoChannelInterface->GetChannel(); 61 | 62 | ClearChannels(); 63 | AddChannel( mVccChannel, "VCC", true ); 64 | AddChannel( mResetChannel, "RST", true ); 65 | AddChannel( mClkChannel, "SCL/CLK", true ); 66 | AddChannel( mIoChannel, "SDA/IO", true ); 67 | 68 | return true; 69 | } 70 | 71 | void iso7816AnalyzerSettings::UpdateInterfacesFromSettings() 72 | { 73 | mVccChannelInterface->SetChannel( mVccChannel ); 74 | mResetChannelInterface->SetChannel( mResetChannel ); 75 | mClkChannelInterface->SetChannel( mClkChannel ); 76 | mIoChannelInterface->SetChannel( mIoChannel ); 77 | } 78 | 79 | void iso7816AnalyzerSettings::LoadSettings( const char* settings ) 80 | { 81 | SimpleArchive text_archive; 82 | text_archive.SetString( settings ); 83 | 84 | text_archive >> mVccChannel; 85 | text_archive >> mResetChannel; 86 | text_archive >> mClkChannel; 87 | text_archive >> mIoChannel; 88 | 89 | ClearChannels(); 90 | AddChannel( mVccChannel, "VCC", true); 91 | AddChannel( mResetChannel, "RST", true); 92 | AddChannel( mClkChannel, "SCL/CLK", true); 93 | AddChannel( mIoChannel, "SDA/IO", true); 94 | 95 | UpdateInterfacesFromSettings(); 96 | } 97 | 98 | const char* iso7816AnalyzerSettings::SaveSettings() 99 | { 100 | SimpleArchive text_archive; 101 | 102 | text_archive << mVccChannel; 103 | text_archive << mResetChannel; 104 | text_archive << mClkChannel; 105 | text_archive << mIoChannel; 106 | 107 | return SetReturnString( text_archive.GetString() ); 108 | } 109 | -------------------------------------------------------------------------------- /source/iso7816AnalyzerSettings.h: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright © 2013 Dirk-Willem van Gulik , all rights reserved. 3 | // Copyright © 2016 Adam Augustyn , all rights reserved. 4 | // 5 | // Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at: 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. 10 | // 11 | 12 | #ifndef ISO7816_ANALYZER_SETTINGS 13 | #define ISO7816_ANALYZER_SETTINGS 14 | 15 | #include 16 | #include 17 | 18 | class iso7816AnalyzerSettings : public AnalyzerSettings 19 | { 20 | public: 21 | iso7816AnalyzerSettings(); 22 | virtual ~iso7816AnalyzerSettings(); 23 | 24 | virtual bool SetSettingsFromInterfaces(); 25 | void UpdateInterfacesFromSettings(); 26 | virtual void LoadSettings( const char* settings ); 27 | virtual const char* SaveSettings(); 28 | 29 | Channel mVccChannel, mResetChannel, mClkChannel, mIoChannel; 30 | 31 | protected: 32 | std::auto_ptr< AnalyzerSettingInterfaceChannel > mVccChannelInterface; 33 | std::auto_ptr< AnalyzerSettingInterfaceChannel > mResetChannelInterface; 34 | std::auto_ptr< AnalyzerSettingInterfaceChannel > mClkChannelInterface; 35 | std::auto_ptr< AnalyzerSettingInterfaceChannel > mIoChannelInterface; 36 | }; 37 | 38 | #endif //ISO7816_ANALYZER_SETTINGS 39 | -------------------------------------------------------------------------------- /source/iso7816SimulationDataGenerator.cpp: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright © 2013 Dirk-Willem van Gulik , all rights reserved. 3 | // Copyright © 2016 Adam Augustyn , all rights reserved. 4 | // 5 | // Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at: 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. 10 | // 11 | 12 | #include "iso7816SimulationDataGenerator.h" 13 | #include "iso7816AnalyzerSettings.h" 14 | 15 | #include 16 | #include 17 | #include 18 | 19 | iso7816SimulationDataGenerator::iso7816SimulationDataGenerator() 20 | { 21 | } 22 | 23 | iso7816SimulationDataGenerator::~iso7816SimulationDataGenerator() 24 | { 25 | } 26 | 27 | void iso7816SimulationDataGenerator::Initialize( U32 simulation_sample_rate, iso7816AnalyzerSettings* settings ) 28 | { 29 | mSimulationSampleRateHz = simulation_sample_rate; 30 | mSettings = settings; 31 | srand(rand() ^ static_cast(time(NULL))); 32 | 33 | mSerialSimulationData.SetInitialBitState( BIT_HIGH ); 34 | } 35 | 36 | U32 iso7816SimulationDataGenerator::GenerateSimulationData( U64 largest_sample_requested, U32 sample_rate, SimulationChannelDescriptor** simulation_channel ) 37 | { 38 | U64 adjusted_largest_sample_requested = AnalyzerHelpers::AdjustSimulationTargetSample( largest_sample_requested, sample_rate, mSimulationSampleRateHz ); 39 | 40 | while( mSerialSimulationData.GetCurrentSampleNumber() < adjusted_largest_sample_requested ) 41 | { 42 | U32 samples_per_bit = 100; // mSimulationSampleRateHz / mSettings->mBitRate; 43 | 44 | U8 byte = rand() & 0xFF; 45 | 46 | mSerialSimulationData.Advance( samples_per_bit * 20 ); 47 | 48 | mSerialSimulationData.Transition(); //low-going edge for start bit 49 | mSerialSimulationData.Advance( samples_per_bit ); //add start bit time 50 | mSerialSimulationData.Transition(); // end of start bit. 51 | mSerialSimulationData.Advance( samples_per_bit ); //add start bit time 52 | 53 | U8 mask = 0x1 << 7; 54 | for( U32 i=0; i<8; i++ ) 55 | { 56 | if( ( byte & mask ) != 0 ) 57 | mSerialSimulationData.TransitionIfNeeded( BIT_HIGH ); 58 | else 59 | mSerialSimulationData.TransitionIfNeeded( BIT_LOW ); 60 | 61 | mSerialSimulationData.Advance( samples_per_bit ); 62 | mask = mask >> 1; 63 | } 64 | 65 | mSerialSimulationData.TransitionIfNeeded( BIT_HIGH ); //we need to end high 66 | mSerialSimulationData.Advance( samples_per_bit ); 67 | 68 | } 69 | 70 | *simulation_channel = &mSerialSimulationData; 71 | return 1; 72 | } 73 | 74 | -------------------------------------------------------------------------------- /source/iso7816SimulationDataGenerator.h: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright © 2013 Dirk-Willem van Gulik , all rights reserved. 3 | // Copyright © 2016 Adam Augustyn , all rights reserved. 4 | // 5 | // Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at: 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. 10 | // 11 | 12 | #ifndef ISO7816_SIMULATION_DATA_GENERATOR 13 | #define ISO7816_SIMULATION_DATA_GENERATOR 14 | 15 | #include 16 | #include 17 | class iso7816AnalyzerSettings; 18 | 19 | class iso7816SimulationDataGenerator 20 | { 21 | public: 22 | iso7816SimulationDataGenerator(); 23 | ~iso7816SimulationDataGenerator(); 24 | 25 | void Initialize( U32 simulation_sample_rate, iso7816AnalyzerSettings* settings ); 26 | U32 GenerateSimulationData( U64 newest_sample_requested, U32 sample_rate, SimulationChannelDescriptor** simulation_channel ); 27 | 28 | protected: 29 | iso7816AnalyzerSettings* mSettings; 30 | U32 mSimulationSampleRateHz; 31 | 32 | protected: 33 | SimulationChannelDescriptor mSerialSimulationData; 34 | 35 | }; 36 | #endif //ISO7816_SIMULATION_DATA_GENERATOR --------------------------------------------------------------------------------