├── .gitignore ├── LICENSE ├── README.md ├── docs └── cn │ └── main.md ├── example └── sdk-example │ ├── sdk-example.xcodeproj │ ├── project.pbxproj │ └── project.xcworkspace │ │ └── contents.xcworkspacedata │ ├── sdk-example │ ├── AppDelegate.h │ ├── AppDelegate.m │ ├── Base.lproj │ │ ├── LaunchScreen.xib │ │ └── Main.storyboard │ ├── Images.xcassets │ │ └── AppIcon.appiconset │ │ │ └── Contents.json │ ├── Info.plist │ ├── MBProgressHUD.h │ ├── MBProgressHUD.m │ ├── PandoSdk.framework │ │ ├── Headers │ │ │ └── PandoSdk.h │ │ ├── Info.plist │ │ ├── Modules │ │ │ └── module.modulemap │ │ ├── PandoSdk │ │ └── _CodeSignature │ │ │ └── CodeResources │ ├── ViewController.h │ ├── ViewController.m │ └── main.m │ └── sdk-exampleTests │ ├── Info.plist │ └── sdk_exampleTests.m ├── sdk ├── PandoSdk.framework │ ├── Headers │ │ └── PandoSdk.h │ ├── Info.plist │ ├── Modules │ │ └── module.modulemap │ ├── PandoSdk │ └── _CodeSignature │ │ └── CodeResources └── PandoSdk_simulator.framework │ ├── Headers │ └── PandoSdk.h │ ├── Info.plist │ ├── Modules │ └── module.modulemap │ └── PandoSdk_simulator └── src ├── PandoSdk.xcodeproj ├── project.pbxproj └── project.xcworkspace │ └── contents.xcworkspacedata ├── PandoSdk ├── CHKeychain.h ├── CHKeychain.m ├── GCDAsyncSocket.h ├── GCDAsyncSocket.m ├── GCDAsyncUdpSocket.h ├── GCDAsyncUdpSocket.m ├── HttpClient │ ├── HttpClient.h │ └── HttpClient.m ├── Info.plist ├── MQTTKit │ ├── MQTTKit.h │ ├── MQTTKit.m │ └── libmosquitto │ │ ├── config.h │ │ ├── dummypthread.h │ │ ├── logging_mosq.c │ │ ├── logging_mosq.h │ │ ├── memory_mosq.c │ │ ├── memory_mosq.h │ │ ├── messages_mosq.c │ │ ├── messages_mosq.h │ │ ├── mosquitto.c │ │ ├── mosquitto.h │ │ ├── mosquitto_internal.h │ │ ├── mqtt3_protocol.h │ │ ├── net_mosq.c │ │ ├── net_mosq.h │ │ ├── read_handle.c │ │ ├── read_handle.h │ │ ├── read_handle_client.c │ │ ├── read_handle_shared.c │ │ ├── send_client_mosq.c │ │ ├── send_mosq.c │ │ ├── send_mosq.h │ │ ├── thread_mosq.c │ │ ├── time_mosq.c │ │ ├── time_mosq.h │ │ ├── tls_mosq.c │ │ ├── tls_mosq.h │ │ ├── util_mosq.c │ │ ├── util_mosq.h │ │ ├── will_mosq.c │ │ └── will_mosq.h ├── PandoPayload │ ├── pando_endian.c │ ├── pando_endian.h │ ├── pando_protocol_tool.c │ ├── pando_protocol_tool.h │ ├── pd_machine.c │ ├── pd_machine.h │ ├── platform.c │ ├── platform.h │ ├── platform_functions.c │ ├── platform_functions.h │ ├── sub_device_protocol_tool.c │ └── sub_device_protocol_tool.h ├── PandoSdk.h ├── PandoSdk.m └── esptouch │ ├── ESPDataCode.h │ ├── ESPDataCode.m │ ├── ESPDatumCode.h │ ├── ESPDatumCode.m │ ├── ESPGuideCode.h │ ├── ESPGuideCode.m │ ├── ESPTouchGenerator.h │ ├── ESPTouchGenerator.m │ ├── ESPTouchResult.h │ ├── ESPTouchResult.m │ ├── ESPTouchTask.h │ ├── ESPTouchTask.m │ ├── ESPTouchTaskParameter.h │ ├── ESPTouchTaskParameter.m │ ├── ESPUDPSocketClient.h │ ├── ESPUDPSocketClient.m │ ├── ESPUDPSocketServer.h │ ├── ESPUDPSocketServer.m │ ├── ESP_ByteUtil.h │ ├── ESP_ByteUtil.m │ ├── ESP_CRC8.h │ ├── ESP_CRC8.m │ ├── ESP_NetUtil.h │ ├── ESP_NetUtil.m │ ├── IPAddress.c │ └── IPAddress.h └── Products ├── PandoSdk.framework ├── Headers │ └── PandoSdk.h ├── Info.plist ├── Modules │ └── module.modulemap ├── PandoSdk └── _CodeSignature │ └── CodeResources └── PandoSdk_simulator.framework ├── Headers └── PandoSdk.h ├── Info.plist ├── Modules └── module.modulemap └── PandoSdk_simulator /.gitignore: -------------------------------------------------------------------------------- 1 | # Xcode 2 | # 3 | build/ 4 | *.pbxuser 5 | !default.pbxuser 6 | *.mode1v3 7 | !default.mode1v3 8 | *.mode2v3 9 | !default.mode2v3 10 | *.perspectivev3 11 | !default.perspectivev3 12 | xcuserdata 13 | *.xccheckout 14 | *.moved-aside 15 | DerivedData 16 | *.hmap 17 | *.ipa 18 | *.xcuserstate 19 | 20 | # CocoaPods 21 | # 22 | # We recommend against adding the Pods directory to your .gitignore. However 23 | # you should judge for yourself, the pros and cons are mentioned at: 24 | # http://guides.cocoapods.org/using/using-cocoapods.html#should-i-ignore-the-pods-directory-in-source-control 25 | # 26 | #Pods/ 27 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2015 PandoCloud 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | 23 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # pando-ios-sdk 2 | ios sdk to build ios app which interact with IOT devices. 3 | 4 | #### document: 5 | 6 | * [中文](docs/cn/main.md) 7 | * [English](docs/en/main.md) -------------------------------------------------------------------------------- /docs/cn/main.md: -------------------------------------------------------------------------------- 1 | ### 目录 2 | 1. [sdk介绍](#sdk介绍) 3 | 2. [准备工作](#准备工作) 4 | 3. [wifi设备配置](#wifi设备配置) 5 | 4. [工具方法](#工具方法) 6 | 7 | ### sdk介绍 8 | pando手机sdk是pandocloud物联网云平台针对手机终端提供的物联网开发工具。拥有以下功能: 9 | 10 | * **设备配置**:配置设备上网,目前该功能主要针对wifi设备 11 | * **设备发现**:发现周围的设备并获取其信息 12 | * **设备代理**:将连接在手机上的设备(如蓝牙设备)通过sdk和连接上互联网,和其他设备或用户进行交互 13 | 14 | ### 准备工作 15 | sdk使用步骤如下: 16 | 17 | 1.下载最新的sdk的framework文件,将其拖入工程目录,并在 “Targets->General->Embedded Binaries” 中添加;其中PandoSdk.framework用于真机环境和提交到app store,PandoSdk_simulator.framework用于模拟器环境; 18 | 2.在需要使用sdk的代码中引入头文件即可。 19 | ``` objc 20 | #include 21 | ``` 22 | 23 | 24 | ### wifi设备配置 25 | 在wifi环境下,app可以利用sdk将当前wifi的ssid和密码发送给wifi设备,如果ssid和密码正确,wifi设备就能成功联网。目前根据设备类型不同,支持两种配置模式: 26 | 27 | * **热点模式**(hotspot):该方法基本原理是设备启动配置模式后,会开启一个wifi热点,用户将手机连接上该wifi(无密码)后,将ssid和密码发送给设备。 28 | * **智能模式**(smartlink):该方法基本原理是app直接将ssid名和密码广播到当前局域网,wifi设备通过抓取探测路由器的包长变化解码出密码信息。该方法不需要用户有额外的操作,体验较好,如果设备支持的情况下,推荐采用该模式。 29 | 30 | ##### 接口说明: 31 | wifi设备配置由接口PandoSdk提供,相关接口: 32 | 33 | ###### 1. 初始化 34 | 初始化PandoSdk实例 35 | ``` objc 36 | /*! 37 | * @method initWithDelegate: 38 | * 39 | * @param delegate The delegate that will receive PandoSdk events. 40 | * 41 | * @discussion The initialization call. 42 | */ 43 | - (instancetype)initWithDelegate:(id)delegate; 44 | ``` 45 | 46 | ###### 2. 开始配置 47 | app调用PandoSdk的configDeviceToWiFi方法启动配置: 48 | 49 | ``` objc 50 | /*! 51 | * @method configDeviceToWiFi:password:byMode: 52 | * 53 | * @param ssid The WiFi ssid you want you device to connect to. 54 | * @param password The password of the specified WiFi. 55 | * @param mode The different config method. 56 | * 57 | * @discussion Configure device with the specified WiFi ssid & password by different mode. 58 | */ 59 | - (void)configDeviceToWiFi:(NSString *)ssid password:(NSString *)password byMode:(NSString *)mode; 60 | ``` 61 | > 注意: 62 | 参数mode在目前版本的sdk中可以使用的值为“hotspot”或者“smartlink”字符串;如果是hotspot模式,app需保证用户在过程中始终连接设备发出的wifi热点,直至委托方法被调用,app可以提示用户连接或者采用程序自动连接wifi热点。 63 | 64 | 委托方法: 65 | 配置成功或者失败后会调用此方法,配置成功后,会获取到devicekey,devicekey是设备操作的唯一凭证。若error不为nil,则表示失败 66 | ``` objc 67 | /*! 68 | * @method pandoSdk:didConfigDeviceToWiFi:deviceKey:error: 69 | * 70 | * @param pandoSdk The pandoSdk object providing configDeviceToWiFi method. 71 | * @param ssid The WiFi ssid the method configure to. 72 | * @param deviceKey The device key returned from device. 73 | * @param error If an error occurred, the cause of the failure. 74 | * 75 | * @discussion This method is invoked when a pandoSdk object ended configDeviceToWifi method. 76 | */ 77 | - (void)pandoSdk:(PandoSdk *)pandoSdk didConfigDeviceToWiFi:(NSString *)ssid deviceKey:(NSString *)deviceKey error:(NSError *)error; 78 | ``` 79 | 80 | ###### 3. 结束配置 81 | 当用户主动取消配置或者配置出错时,app可以调用stopConfig方法结束配置: 82 | 83 | ``` objc 84 | /*! 85 | * @method stopConfig 86 | * 87 | * @discussion Stop to configure device while configuring. 88 | */ 89 | - (void)stopConfig; 90 | ``` 91 | > 注意:如果是hotspot模式,wifi配置成功后app如果需要获取设备信息(devicekey),则需要继续保持手机连接在设备ap上,等获取设备信息成功后,再调用stopConfig结束配置并断开和热点的连接 92 | 93 | 委托方法: 94 | ``` objc 95 | /*! 96 | * @method pandoSdk:didStopConfig:error: 97 | * 98 | * @param pandoSdk The pandoSdk object providing stopConfig method. 99 | * @param isStoped 100 | * @param error If an error occurred, the cause of the failure. 101 | * 102 | * @discussion This method is invoked when a pandoSdk object ended stopConfig method. 103 | */ 104 | - (void)pandoSdk:(PandoSdk *)pandoSdk didStopConfig:(BOOL)isStoped error:(NSError *)error; 105 | ``` 106 | 107 | ###### 4. 示例代码 108 | 该示例用于展示如何使用PandoSdk配置设备联网 109 | https://github.com/PandoCloud/pando-ios-sdk/tree/master/example/ 110 | 111 | ### 工具方法 112 | TODO 113 | -------------------------------------------------------------------------------- /example/sdk-example/sdk-example.xcodeproj/project.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /example/sdk-example/sdk-example/AppDelegate.h: -------------------------------------------------------------------------------- 1 | // 2 | // AppDelegate.h 3 | // sdk-example 4 | // 5 | // Created by liming_llm on 15/7/22. 6 | // Copyright (c) 2015年 PandoCloud. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface AppDelegate : UIResponder 12 | 13 | @property (strong, nonatomic) UIWindow *window; 14 | 15 | 16 | @end 17 | 18 | -------------------------------------------------------------------------------- /example/sdk-example/sdk-example/AppDelegate.m: -------------------------------------------------------------------------------- 1 | // 2 | // AppDelegate.m 3 | // sdk-example 4 | // 5 | // Created by liming_llm on 15/7/22. 6 | // Copyright (c) 2015年 PandoCloud. All rights reserved. 7 | // 8 | 9 | #import "AppDelegate.h" 10 | 11 | @interface AppDelegate () 12 | 13 | @end 14 | 15 | @implementation AppDelegate 16 | 17 | 18 | - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { 19 | // Override point for customization after application launch. 20 | return YES; 21 | } 22 | 23 | - (void)applicationWillResignActive:(UIApplication *)application { 24 | // Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state. 25 | // Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game. 26 | } 27 | 28 | - (void)applicationDidEnterBackground:(UIApplication *)application { 29 | // Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later. 30 | // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits. 31 | } 32 | 33 | - (void)applicationWillEnterForeground:(UIApplication *)application { 34 | // Called as part of the transition from the background to the inactive state; here you can undo many of the changes made on entering the background. 35 | } 36 | 37 | - (void)applicationDidBecomeActive:(UIApplication *)application { 38 | // Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface. 39 | } 40 | 41 | - (void)applicationWillTerminate:(UIApplication *)application { 42 | // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:. 43 | } 44 | 45 | @end 46 | -------------------------------------------------------------------------------- /example/sdk-example/sdk-example/Base.lproj/LaunchScreen.xib: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 20 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | -------------------------------------------------------------------------------- /example/sdk-example/sdk-example/Images.xcassets/AppIcon.appiconset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "idiom" : "iphone", 5 | "size" : "29x29", 6 | "scale" : "2x" 7 | }, 8 | { 9 | "idiom" : "iphone", 10 | "size" : "29x29", 11 | "scale" : "3x" 12 | }, 13 | { 14 | "idiom" : "iphone", 15 | "size" : "40x40", 16 | "scale" : "2x" 17 | }, 18 | { 19 | "idiom" : "iphone", 20 | "size" : "40x40", 21 | "scale" : "3x" 22 | }, 23 | { 24 | "idiom" : "iphone", 25 | "size" : "60x60", 26 | "scale" : "2x" 27 | }, 28 | { 29 | "idiom" : "iphone", 30 | "size" : "60x60", 31 | "scale" : "3x" 32 | }, 33 | { 34 | "idiom" : "ipad", 35 | "size" : "29x29", 36 | "scale" : "1x" 37 | }, 38 | { 39 | "idiom" : "ipad", 40 | "size" : "29x29", 41 | "scale" : "2x" 42 | }, 43 | { 44 | "idiom" : "ipad", 45 | "size" : "40x40", 46 | "scale" : "1x" 47 | }, 48 | { 49 | "idiom" : "ipad", 50 | "size" : "40x40", 51 | "scale" : "2x" 52 | }, 53 | { 54 | "idiom" : "ipad", 55 | "size" : "76x76", 56 | "scale" : "1x" 57 | }, 58 | { 59 | "idiom" : "ipad", 60 | "size" : "76x76", 61 | "scale" : "2x" 62 | } 63 | ], 64 | "info" : { 65 | "version" : 1, 66 | "author" : "xcode" 67 | } 68 | } -------------------------------------------------------------------------------- /example/sdk-example/sdk-example/Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | en 7 | CFBundleExecutable 8 | $(EXECUTABLE_NAME) 9 | CFBundleIdentifier 10 | com.PandoCloud.$(PRODUCT_NAME:rfc1034identifier) 11 | CFBundleInfoDictionaryVersion 12 | 6.0 13 | CFBundleName 14 | $(PRODUCT_NAME) 15 | CFBundlePackageType 16 | APPL 17 | CFBundleShortVersionString 18 | 1.0 19 | CFBundleSignature 20 | ???? 21 | CFBundleVersion 22 | 1 23 | LSRequiresIPhoneOS 24 | 25 | UILaunchStoryboardName 26 | LaunchScreen 27 | UIMainStoryboardFile 28 | Main 29 | UIRequiredDeviceCapabilities 30 | 31 | armv7 32 | 33 | UISupportedInterfaceOrientations 34 | 35 | UIInterfaceOrientationPortrait 36 | UIInterfaceOrientationLandscapeLeft 37 | UIInterfaceOrientationLandscapeRight 38 | 39 | UISupportedInterfaceOrientations~ipad 40 | 41 | UIInterfaceOrientationPortrait 42 | UIInterfaceOrientationPortraitUpsideDown 43 | UIInterfaceOrientationLandscapeLeft 44 | UIInterfaceOrientationLandscapeRight 45 | 46 | 47 | 48 | -------------------------------------------------------------------------------- /example/sdk-example/sdk-example/PandoSdk.framework/Headers/PandoSdk.h: -------------------------------------------------------------------------------- 1 | // 2 | // PandoSdk.h 3 | // PandoSdk version 0.1.0 4 | // 5 | // Created by liming_llm on 15/3/26. 6 | // Copyright (c) 2015年 liming_llm. All rights reserved. 7 | // 8 | #import 9 | 10 | @protocol PandoSdkDelegate; 11 | 12 | @interface PandoSdk : NSObject 13 | 14 | 15 | /*! 16 | * @method initWithDelegate: 17 | * 18 | * @param delegate The delegate that will receive PandoSdk events. 19 | * 20 | * @discussion The initialization call. 21 | */ 22 | - (instancetype)initWithDelegate:(id)delegate; 23 | 24 | /*! 25 | * @method configDeviceToWiFi:password:byMode: 26 | * 27 | * @param ssid The WiFi ssid you want you device to connect to. 28 | * @param password The password of the specified WiFi. 29 | * @param mode The different config method. 30 | * 31 | * @discussion Configure device with the specified WiFi ssid & password by different mode. 32 | */ 33 | - (void)configDeviceToWiFi:(NSString *)ssid password:(NSString *)password byMode:(NSString *)mode; 34 | 35 | /*! 36 | * @method stopConfig 37 | * 38 | * @discussion Stop to configure device while configuring. 39 | */ 40 | - (void)stopConfig; 41 | 42 | @end 43 | 44 | 45 | 46 | /*! 47 | * @protocol PandoSdkDelegate 48 | * 49 | * @discussion The delegate of a PandoSdk object must adopt the PandoSdkDelegate protocol. The optional methods provide information about PandoSdk method. 50 | * 51 | */ 52 | @protocol PandoSdkDelegate 53 | 54 | @optional 55 | 56 | /*! 57 | * @method pandoSdk:didConfigDeviceToWiFi:deviceKey:error: 58 | * 59 | * @param pandoSdk The pandoSdk object providing configDeviceToWiFi method. 60 | * @param ssid The WiFi ssid the method configure to. 61 | * @param deviceKey The device key returned from device. 62 | * @param error If an error occurred, the cause of the failure. 63 | * 64 | * @discussion This method is invoked when a pandoSdk object ended configDeviceToWifi method. 65 | */ 66 | - (void)pandoSdk:(PandoSdk *)pandoSdk didConfigDeviceToWiFi:(NSString *)ssid deviceKey:(NSString *)deviceKey error:(NSError *)error; 67 | 68 | /*! 69 | * @method pandoSdk:didStopConfig:error: 70 | * 71 | * @param pandoSdk The pandoSdk object providing stopConfig method. 72 | * @param isStoped 73 | * @param error If an error occurred, the cause of the failure. 74 | * 75 | * @discussion This method is invoked when a pandoSdk object ended stopConfig method. 76 | */ 77 | - (void)pandoSdk:(PandoSdk *)pandoSdk didStopConfig:(BOOL)isStoped error:(NSError *)error; 78 | 79 | 80 | @end 81 | 82 | 83 | 84 | 85 | 86 | -------------------------------------------------------------------------------- /example/sdk-example/sdk-example/PandoSdk.framework/Info.plist: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PandoCloud/pando-ios-sdk/ff00598f25cdb20531070fb54118303d95696b84/example/sdk-example/sdk-example/PandoSdk.framework/Info.plist -------------------------------------------------------------------------------- /example/sdk-example/sdk-example/PandoSdk.framework/Modules/module.modulemap: -------------------------------------------------------------------------------- 1 | framework module PandoSdk { 2 | umbrella header "PandoSdk.h" 3 | 4 | export * 5 | module * { export * } 6 | } 7 | -------------------------------------------------------------------------------- /example/sdk-example/sdk-example/PandoSdk.framework/PandoSdk: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PandoCloud/pando-ios-sdk/ff00598f25cdb20531070fb54118303d95696b84/example/sdk-example/sdk-example/PandoSdk.framework/PandoSdk -------------------------------------------------------------------------------- /example/sdk-example/sdk-example/PandoSdk.framework/_CodeSignature/CodeResources: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | files 6 | 7 | Headers/PandoSdk.h 8 | 9 | I9+sG7j60yG74w9kqYBdUQWBOiQ= 10 | 11 | Info.plist 12 | 13 | TcepPBTnXV3M83QC2k+s0ZQgCL8= 14 | 15 | Modules/module.modulemap 16 | 17 | 4/QcOovdOYzssKiWeFiMa2JtnVw= 18 | 19 | 20 | files2 21 | 22 | Headers/PandoSdk.h 23 | 24 | I9+sG7j60yG74w9kqYBdUQWBOiQ= 25 | 26 | Modules/module.modulemap 27 | 28 | 4/QcOovdOYzssKiWeFiMa2JtnVw= 29 | 30 | 31 | rules 32 | 33 | ^ 34 | 35 | ^.*\.lproj/ 36 | 37 | optional 38 | 39 | weight 40 | 1000 41 | 42 | ^.*\.lproj/locversion.plist$ 43 | 44 | omit 45 | 46 | weight 47 | 1100 48 | 49 | ^version.plist$ 50 | 51 | 52 | rules2 53 | 54 | .*\.dSYM($|/) 55 | 56 | weight 57 | 11 58 | 59 | ^ 60 | 61 | weight 62 | 20 63 | 64 | ^(.*/)?\.DS_Store$ 65 | 66 | omit 67 | 68 | weight 69 | 2000 70 | 71 | ^(Frameworks|SharedFrameworks|PlugIns|Plug-ins|XPCServices|Helpers|MacOS|Library/(Automator|Spotlight|LoginItems))/ 72 | 73 | nested 74 | 75 | weight 76 | 10 77 | 78 | ^.* 79 | 80 | ^.*\.lproj/ 81 | 82 | optional 83 | 84 | weight 85 | 1000 86 | 87 | ^.*\.lproj/locversion.plist$ 88 | 89 | omit 90 | 91 | weight 92 | 1100 93 | 94 | ^Info\.plist$ 95 | 96 | omit 97 | 98 | weight 99 | 20 100 | 101 | ^PkgInfo$ 102 | 103 | omit 104 | 105 | weight 106 | 20 107 | 108 | ^[^/]+$ 109 | 110 | nested 111 | 112 | weight 113 | 10 114 | 115 | ^embedded\.provisionprofile$ 116 | 117 | weight 118 | 20 119 | 120 | ^version\.plist$ 121 | 122 | weight 123 | 20 124 | 125 | 126 | 127 | 128 | -------------------------------------------------------------------------------- /example/sdk-example/sdk-example/ViewController.h: -------------------------------------------------------------------------------- 1 | // 2 | // ViewController.h 3 | // sdk-example 4 | // 5 | // Created by liming_llm on 15/7/22. 6 | // Copyright (c) 2015年 PandoCloud. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface ViewController : UIViewController 12 | 13 | 14 | @property (weak, nonatomic) IBOutlet UIPickerView *modePicker; 15 | @property (weak, nonatomic) IBOutlet UIToolbar *pickerBar; 16 | @property (weak, nonatomic) IBOutlet UITextField *ssidText; 17 | @property (weak, nonatomic) IBOutlet UITextField *passText; 18 | @property (weak, nonatomic) IBOutlet UITextField *modeText; 19 | @property (weak, nonatomic) IBOutlet UIButton *configButton; 20 | 21 | 22 | @end 23 | 24 | -------------------------------------------------------------------------------- /example/sdk-example/sdk-example/ViewController.m: -------------------------------------------------------------------------------- 1 | // 2 | // ViewController.m 3 | // sdk-example 4 | // 5 | // Created by liming_llm on 15/7/22. 6 | // Copyright (c) 2015年 PandoCloud. All rights reserved. 7 | // 8 | 9 | #import 10 | #import 11 | #import 12 | 13 | #import 14 | 15 | #import "ViewController.h" 16 | #import "MBProgressHUD.h" 17 | 18 | #define DEVICE_SSID @"love-letter" 19 | 20 | 21 | @interface ViewController () { 22 | NSArray *_pickerArray; 23 | UIAlertView *_ssidEmptyAlert; 24 | PandoSdk *_psdk; 25 | MBProgressHUD *_HUD; 26 | NSTimer *checkSSIDTimer; 27 | } 28 | 29 | @end 30 | 31 | @implementation ViewController 32 | 33 | - (void)viewDidLoad { 34 | [super viewDidLoad]; 35 | // Do any additional setup after loading the view, typically from a nib. 36 | 37 | _pickerArray = [[NSArray alloc]initWithObjects:@"hotspot", @"smartlink", nil]; 38 | 39 | _modeText.inputView = _modePicker; 40 | _modeText.inputAccessoryView = _pickerBar; 41 | _modeText.delegate = self; 42 | 43 | _modePicker.delegate = self; 44 | _modePicker.dataSource = self; 45 | 46 | [_modeText setText:@"hotspot"]; 47 | 48 | NSString *ssid = [self getCurrentSSID]; 49 | 50 | if (ssid == nil) { 51 | [[[UIAlertView alloc]initWithTitle:@"" 52 | message:@"当前手机没有连接到任何WiFi网络,请连接到WiFi网络" 53 | delegate:self 54 | cancelButtonTitle:@"知道了" 55 | otherButtonTitles:nil] show]; 56 | } 57 | else { 58 | _ssidText.text = [ssid copy]; 59 | } 60 | } 61 | 62 | #pragma mark - pickerView delegate 63 | -(NSInteger)numberOfComponentsInPickerView:(UIPickerView *)pickerView { 64 | return 1; 65 | } 66 | 67 | -(NSInteger) pickerView:(UIPickerView *)pickerView numberOfRowsInComponent:(NSInteger)component { 68 | return [_pickerArray count]; 69 | } 70 | 71 | -(NSString*) pickerView:(UIPickerView *)pickerView titleForRow:(NSInteger)row forComponent:(NSInteger)component { 72 | return [_pickerArray objectAtIndex:row]; 73 | } 74 | 75 | 76 | #pragma mark - textField delegate 77 | -(void)textFieldDidEndEditing:(UITextField *)textField { 78 | if (textField == _modeText) { 79 | NSInteger row = [_modePicker selectedRowInComponent:0]; 80 | _modeText.text = [_pickerArray objectAtIndex:row]; 81 | } 82 | } 83 | 84 | #pragma mark - alertView delegate 85 | - (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex { 86 | NSString *ssid = [self getCurrentSSID]; 87 | 88 | if (ssid == nil) { 89 | [[[UIAlertView alloc]initWithTitle:@"" 90 | message:@"当前手机没有连接到任何WiFi网络,请连接到WiFi网络" 91 | delegate:self 92 | cancelButtonTitle:@"知道了" 93 | otherButtonTitles:nil] show]; 94 | } 95 | else { 96 | _ssidText.text = [ssid copy]; 97 | } 98 | } 99 | 100 | #pragma maek - pandosdk delegate 101 | - (void)pandoSdk:(PandoSdk *)pandoSdk didConfigDeviceToWiFi:(NSString *)ssid deviceKey:(NSString *)deviceKey error:(NSError *)error { 102 | 103 | if (checkSSIDTimer != nil) { 104 | [checkSSIDTimer invalidate]; 105 | } 106 | 107 | [_HUD hide:YES]; 108 | 109 | if (error != nil) { 110 | [[[UIAlertView alloc]initWithTitle:@"error" 111 | message:[error localizedDescription] 112 | delegate:nil 113 | cancelButtonTitle:@"知道了" 114 | otherButtonTitles:nil] show]; 115 | } 116 | else { 117 | [[[UIAlertView alloc]initWithTitle:@"success" 118 | message:[NSString stringWithFormat:@"device key = %@", deviceKey] 119 | delegate:nil 120 | cancelButtonTitle:@"知道了" 121 | otherButtonTitles:nil] show]; 122 | } 123 | } 124 | 125 | #pragma mark - IBAction 126 | 127 | - (IBAction)pickerDonePressed:(id)sender { 128 | [_modeText endEditing:YES]; 129 | } 130 | 131 | - (IBAction)viewTouchDown:(id)sender { 132 | [[UIApplication sharedApplication] sendAction:@selector(resignFirstResponder) to:nil from:nil forEvent:nil]; 133 | } 134 | 135 | - (IBAction)configButtonTouchUpInside:(id)sender { 136 | [[UIApplication sharedApplication] sendAction:@selector(resignFirstResponder) to:nil from:nil forEvent:nil]; 137 | 138 | _psdk = [[PandoSdk alloc]initWithDelegate:self]; 139 | 140 | if ([[_modeText text] isEqual:@"hotspot"]) { 141 | checkSSIDTimer = [NSTimer scheduledTimerWithTimeInterval:1.0 142 | target:self 143 | selector:@selector(checkSSID) 144 | userInfo:nil 145 | repeats:YES]; 146 | } 147 | 148 | [_psdk configDeviceToWiFi:[_ssidText text] password:[_passText text] byMode:[_modeText text]]; 149 | 150 | _HUD = [MBProgressHUD showHUDAddedTo:self.view animated:YES]; 151 | _HUD.dimBackground = YES; 152 | 153 | //_HUD.delegate = self; 154 | } 155 | 156 | #pragma mark - local 157 | 158 | - (NSString *)getCurrentSSID { 159 | NSArray *ifs = (__bridge_transfer id)CNCopySupportedInterfaces(); 160 | //NSLog(@"Supported interfaces: %@", ifs); 161 | id info = nil; 162 | NSString *ssid = nil; 163 | for (NSString *ifname in ifs) { 164 | info = (__bridge_transfer id)CNCopyCurrentNetworkInfo((__bridge CFStringRef)ifname); 165 | //NSLog(@"%@ => %@", ifnam, info); 166 | 167 | if (info == nil) { 168 | continue; 169 | } 170 | 171 | if (info[@"SSID"]) { 172 | ssid = info[@"SSID"]; 173 | } 174 | 175 | if (info && [info count]) { 176 | break; 177 | } 178 | } 179 | return ssid; 180 | } 181 | 182 | - (void)checkSSID { 183 | if (![[self getCurrentSSID] isEqualToString:DEVICE_SSID]) { 184 | //dispatch_time_t popTime = dispatch_time(DISPATCH_TIME_NOW, 0.01 * NSEC_PER_SEC); 185 | //dispatch_after(popTime, dispatch_get_main_queue(), ^(void){ 186 | 187 | [[[UIAlertView alloc]initWithTitle:@"" 188 | message:@"当前手机没有连接到"DEVICE_SSID",请连接,否则无法配置成功" 189 | delegate:nil 190 | cancelButtonTitle:@"知道了" 191 | otherButtonTitles:nil] show]; 192 | //}); 193 | } 194 | } 195 | 196 | @end 197 | -------------------------------------------------------------------------------- /example/sdk-example/sdk-example/main.m: -------------------------------------------------------------------------------- 1 | // 2 | // main.m 3 | // sdk-example 4 | // 5 | // Created by liming_llm on 15/7/22. 6 | // Copyright (c) 2015年 PandoCloud. All rights reserved. 7 | // 8 | 9 | #import 10 | #import "AppDelegate.h" 11 | 12 | int main(int argc, char * argv[]) { 13 | @autoreleasepool { 14 | return UIApplicationMain(argc, argv, nil, NSStringFromClass([AppDelegate class])); 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /example/sdk-example/sdk-exampleTests/Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | en 7 | CFBundleExecutable 8 | $(EXECUTABLE_NAME) 9 | CFBundleIdentifier 10 | com.PandoCloud.$(PRODUCT_NAME:rfc1034identifier) 11 | CFBundleInfoDictionaryVersion 12 | 6.0 13 | CFBundleName 14 | $(PRODUCT_NAME) 15 | CFBundlePackageType 16 | BNDL 17 | CFBundleShortVersionString 18 | 1.0 19 | CFBundleSignature 20 | ???? 21 | CFBundleVersion 22 | 1 23 | 24 | 25 | -------------------------------------------------------------------------------- /example/sdk-example/sdk-exampleTests/sdk_exampleTests.m: -------------------------------------------------------------------------------- 1 | // 2 | // sdk_exampleTests.m 3 | // sdk-exampleTests 4 | // 5 | // Created by liming_llm on 15/7/22. 6 | // Copyright (c) 2015年 PandoCloud. All rights reserved. 7 | // 8 | 9 | #import 10 | #import 11 | 12 | @interface sdk_exampleTests : XCTestCase 13 | 14 | @end 15 | 16 | @implementation sdk_exampleTests 17 | 18 | - (void)setUp { 19 | [super setUp]; 20 | // Put setup code here. This method is called before the invocation of each test method in the class. 21 | } 22 | 23 | - (void)tearDown { 24 | // Put teardown code here. This method is called after the invocation of each test method in the class. 25 | [super tearDown]; 26 | } 27 | 28 | - (void)testExample { 29 | // This is an example of a functional test case. 30 | XCTAssert(YES, @"Pass"); 31 | } 32 | 33 | - (void)testPerformanceExample { 34 | // This is an example of a performance test case. 35 | [self measureBlock:^{ 36 | // Put the code you want to measure the time of here. 37 | }]; 38 | } 39 | 40 | @end 41 | -------------------------------------------------------------------------------- /sdk/PandoSdk.framework/Headers/PandoSdk.h: -------------------------------------------------------------------------------- 1 | // 2 | // PandoSdk.h 3 | // PandoSdk version 0.1.0 4 | // 5 | // Created by liming_llm on 15/3/26. 6 | // Copyright (c) 2015年 liming_llm. All rights reserved. 7 | // 8 | #import 9 | 10 | @protocol PandoSdkDelegate; 11 | 12 | @interface PandoSdk : NSObject 13 | 14 | 15 | /*! 16 | * @method initWithDelegate: 17 | * 18 | * @param delegate The delegate that will receive PandoSdk events. 19 | * 20 | * @discussion The initialization call. 21 | */ 22 | - (instancetype)initWithDelegate:(id)delegate; 23 | 24 | /*! 25 | * @method configDeviceToWiFi:password:byMode: 26 | * 27 | * @param ssid The WiFi ssid you want you device to connect to. 28 | * @param password The password of the specified WiFi. 29 | * @param mode The different config method. 30 | * 31 | * @discussion Configure device with the specified WiFi ssid & password by different mode. 32 | */ 33 | - (void)configDeviceToWiFi:(NSString *)ssid password:(NSString *)password byMode:(NSString *)mode; 34 | 35 | /*! 36 | * @method stopConfig 37 | * 38 | * @discussion Stop to configure device while configuring. 39 | */ 40 | - (void)stopConfig; 41 | 42 | 43 | /*! 44 | * @method isDebugOn: 45 | * 46 | * @param isDebugOn Set YES to print debug info. 47 | * 48 | * @discussion Set YES to print debug info. 49 | */ 50 | - (void)isDebugOn:(BOOL)isDebugOn; 51 | 52 | @end 53 | 54 | 55 | 56 | /*! 57 | * @protocol PandoSdkDelegate 58 | * 59 | * @discussion The delegate of a PandoSdk object must adopt the PandoSdkDelegate protocol. The optional methods provide information about PandoSdk method. 60 | * 61 | */ 62 | @protocol PandoSdkDelegate 63 | 64 | @optional 65 | 66 | /*! 67 | * @method pandoSdk:didConfigDeviceToWiFi:deviceKey:error: 68 | * 69 | * @param pandoSdk The pandoSdk object providing configDeviceToWiFi method. 70 | * @param ssid The WiFi ssid the method configure to. 71 | * @param deviceKey The device key returned from device. 72 | * @param error If an error occurred, the cause of the failure. 73 | * 74 | * @discussion This method is invoked when a pandoSdk object ended configDeviceToWifi method. 75 | */ 76 | - (void)pandoSdk:(PandoSdk *)pandoSdk didConfigDeviceToWiFi:(NSString *)ssid deviceKey:(NSString *)deviceKey error:(NSError *)error; 77 | 78 | /*! 79 | * @method pandoSdk:didStopConfig:error: 80 | * 81 | * @param pandoSdk The pandoSdk object providing stopConfig method. 82 | * @param isStoped 83 | * @param error If an error occurred, the cause of the failure. 84 | * 85 | * @discussion This method is invoked when a pandoSdk object ended stopConfig method. 86 | */ 87 | - (void)pandoSdk:(PandoSdk *)pandoSdk didStopConfig:(BOOL)isStoped error:(NSError *)error; 88 | 89 | 90 | @end 91 | 92 | 93 | 94 | 95 | 96 | -------------------------------------------------------------------------------- /sdk/PandoSdk.framework/Info.plist: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PandoCloud/pando-ios-sdk/ff00598f25cdb20531070fb54118303d95696b84/sdk/PandoSdk.framework/Info.plist -------------------------------------------------------------------------------- /sdk/PandoSdk.framework/Modules/module.modulemap: -------------------------------------------------------------------------------- 1 | framework module PandoSdk { 2 | umbrella header "PandoSdk.h" 3 | 4 | export * 5 | module * { export * } 6 | } 7 | -------------------------------------------------------------------------------- /sdk/PandoSdk.framework/PandoSdk: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PandoCloud/pando-ios-sdk/ff00598f25cdb20531070fb54118303d95696b84/sdk/PandoSdk.framework/PandoSdk -------------------------------------------------------------------------------- /sdk/PandoSdk.framework/_CodeSignature/CodeResources: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | files 6 | 7 | Headers/PandoSdk.h 8 | 9 | NXd2hUfa21saobef48sG6+f5iMA= 10 | 11 | Info.plist 12 | 13 | TcepPBTnXV3M83QC2k+s0ZQgCL8= 14 | 15 | Modules/module.modulemap 16 | 17 | 4/QcOovdOYzssKiWeFiMa2JtnVw= 18 | 19 | 20 | files2 21 | 22 | Headers/PandoSdk.h 23 | 24 | NXd2hUfa21saobef48sG6+f5iMA= 25 | 26 | Modules/module.modulemap 27 | 28 | 4/QcOovdOYzssKiWeFiMa2JtnVw= 29 | 30 | 31 | rules 32 | 33 | ^ 34 | 35 | ^.*\.lproj/ 36 | 37 | optional 38 | 39 | weight 40 | 1000 41 | 42 | ^.*\.lproj/locversion.plist$ 43 | 44 | omit 45 | 46 | weight 47 | 1100 48 | 49 | ^version.plist$ 50 | 51 | 52 | rules2 53 | 54 | .*\.dSYM($|/) 55 | 56 | weight 57 | 11 58 | 59 | ^ 60 | 61 | weight 62 | 20 63 | 64 | ^(.*/)?\.DS_Store$ 65 | 66 | omit 67 | 68 | weight 69 | 2000 70 | 71 | ^(Frameworks|SharedFrameworks|PlugIns|Plug-ins|XPCServices|Helpers|MacOS|Library/(Automator|Spotlight|LoginItems))/ 72 | 73 | nested 74 | 75 | weight 76 | 10 77 | 78 | ^.* 79 | 80 | ^.*\.lproj/ 81 | 82 | optional 83 | 84 | weight 85 | 1000 86 | 87 | ^.*\.lproj/locversion.plist$ 88 | 89 | omit 90 | 91 | weight 92 | 1100 93 | 94 | ^Info\.plist$ 95 | 96 | omit 97 | 98 | weight 99 | 20 100 | 101 | ^PkgInfo$ 102 | 103 | omit 104 | 105 | weight 106 | 20 107 | 108 | ^[^/]+$ 109 | 110 | nested 111 | 112 | weight 113 | 10 114 | 115 | ^embedded\.provisionprofile$ 116 | 117 | weight 118 | 20 119 | 120 | ^version\.plist$ 121 | 122 | weight 123 | 20 124 | 125 | 126 | 127 | 128 | -------------------------------------------------------------------------------- /sdk/PandoSdk_simulator.framework/Headers/PandoSdk.h: -------------------------------------------------------------------------------- 1 | // 2 | // PandoSdk.h 3 | // PandoSdk version 0.1.0 4 | // 5 | // Created by liming_llm on 15/3/26. 6 | // Copyright (c) 2015年 liming_llm. All rights reserved. 7 | // 8 | #import 9 | 10 | @protocol PandoSdkDelegate; 11 | 12 | @interface PandoSdk : NSObject 13 | 14 | 15 | /*! 16 | * @method initWithDelegate: 17 | * 18 | * @param delegate The delegate that will receive PandoSdk events. 19 | * 20 | * @discussion The initialization call. 21 | */ 22 | - (instancetype)initWithDelegate:(id)delegate; 23 | 24 | /*! 25 | * @method configDeviceToWiFi:password:byMode: 26 | * 27 | * @param ssid The WiFi ssid you want you device to connect to. 28 | * @param password The password of the specified WiFi. 29 | * @param mode The different config method. 30 | * 31 | * @discussion Configure device with the specified WiFi ssid & password by different mode. 32 | */ 33 | - (void)configDeviceToWiFi:(NSString *)ssid password:(NSString *)password byMode:(NSString *)mode; 34 | 35 | /*! 36 | * @method stopConfig 37 | * 38 | * @discussion Stop to configure device while configuring. 39 | */ 40 | - (void)stopConfig; 41 | 42 | 43 | /*! 44 | * @method isDebugOn: 45 | * 46 | * @param isDebugOn Set YES to print debug info. 47 | * 48 | * @discussion Set YES to print debug info. 49 | */ 50 | - (void)isDebugOn:(BOOL)isDebugOn; 51 | 52 | @end 53 | 54 | 55 | 56 | /*! 57 | * @protocol PandoSdkDelegate 58 | * 59 | * @discussion The delegate of a PandoSdk object must adopt the PandoSdkDelegate protocol. The optional methods provide information about PandoSdk method. 60 | * 61 | */ 62 | @protocol PandoSdkDelegate 63 | 64 | @optional 65 | 66 | /*! 67 | * @method pandoSdk:didConfigDeviceToWiFi:deviceKey:error: 68 | * 69 | * @param pandoSdk The pandoSdk object providing configDeviceToWiFi method. 70 | * @param ssid The WiFi ssid the method configure to. 71 | * @param deviceKey The device key returned from device. 72 | * @param error If an error occurred, the cause of the failure. 73 | * 74 | * @discussion This method is invoked when a pandoSdk object ended configDeviceToWifi method. 75 | */ 76 | - (void)pandoSdk:(PandoSdk *)pandoSdk didConfigDeviceToWiFi:(NSString *)ssid deviceKey:(NSString *)deviceKey error:(NSError *)error; 77 | 78 | /*! 79 | * @method pandoSdk:didStopConfig:error: 80 | * 81 | * @param pandoSdk The pandoSdk object providing stopConfig method. 82 | * @param isStoped 83 | * @param error If an error occurred, the cause of the failure. 84 | * 85 | * @discussion This method is invoked when a pandoSdk object ended stopConfig method. 86 | */ 87 | - (void)pandoSdk:(PandoSdk *)pandoSdk didStopConfig:(BOOL)isStoped error:(NSError *)error; 88 | 89 | 90 | @end 91 | 92 | 93 | 94 | 95 | 96 | -------------------------------------------------------------------------------- /sdk/PandoSdk_simulator.framework/Info.plist: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PandoCloud/pando-ios-sdk/ff00598f25cdb20531070fb54118303d95696b84/sdk/PandoSdk_simulator.framework/Info.plist -------------------------------------------------------------------------------- /sdk/PandoSdk_simulator.framework/Modules/module.modulemap: -------------------------------------------------------------------------------- 1 | framework module PandoSdk { 2 | umbrella header "PandoSdk.h" 3 | 4 | export * 5 | module * { export * } 6 | } 7 | -------------------------------------------------------------------------------- /sdk/PandoSdk_simulator.framework/PandoSdk_simulator: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PandoCloud/pando-ios-sdk/ff00598f25cdb20531070fb54118303d95696b84/sdk/PandoSdk_simulator.framework/PandoSdk_simulator -------------------------------------------------------------------------------- /src/PandoSdk.xcodeproj/project.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /src/PandoSdk/CHKeychain.h: -------------------------------------------------------------------------------- 1 | // 2 | // CHKeychain.h 3 | // OutletApp 4 | // 5 | // Created by liming_llm on 15/3/21. 6 | // Copyright (c) 2015年 liming_llm. All rights reserved. 7 | // 8 | 9 | #ifndef OutletApp_CHKeychain_h 10 | #define OutletApp_CHKeychain_h 11 | 12 | #import 13 | 14 | @interface CHKeychain : NSObject 15 | 16 | + (void)save:(NSString *)service data:(id)data; 17 | + (id)load:(NSString *)service; 18 | + (void)delete:(NSString *)service; 19 | 20 | @end 21 | 22 | #endif 23 | -------------------------------------------------------------------------------- /src/PandoSdk/CHKeychain.m: -------------------------------------------------------------------------------- 1 | // 2 | // CHKeychain.m 3 | // OutletApp 4 | // 5 | // Created by liming_llm on 15/3/21. 6 | // Copyright (c) 2015年 liming_llm. All rights reserved. 7 | // 8 | 9 | #import "CHKeychain.h" 10 | 11 | @implementation CHKeychain 12 | 13 | + (NSMutableDictionary *)getKeychainQuery:(NSString *)service { 14 | return [NSMutableDictionary dictionaryWithObjectsAndKeys: 15 | (__bridge id)kSecClassGenericPassword,(__bridge id)kSecClass, 16 | service, (__bridge id)kSecAttrService, 17 | service, (__bridge id)kSecAttrAccount, 18 | (__bridge id)kSecAttrAccessibleAfterFirstUnlock,(__bridge id)kSecAttrAccessible, 19 | nil]; 20 | } 21 | 22 | + (void)save:(NSString *)service data:(id)data { 23 | //Get search dictionary 24 | NSMutableDictionary *keychainQuery = [self getKeychainQuery:service]; 25 | //Delete old item before add new item 26 | SecItemDelete((__bridge CFDictionaryRef)keychainQuery); 27 | //Add new object to search dictionary(Attention:the data format) 28 | [keychainQuery setObject:[NSKeyedArchiver archivedDataWithRootObject:data] forKey:(__bridge id)kSecValueData]; 29 | //Add item to keychain with the search dictionary 30 | SecItemAdd((__bridge CFDictionaryRef)keychainQuery, NULL); 31 | } 32 | 33 | + (id)load:(NSString *)service { 34 | id ret = nil; 35 | NSMutableDictionary *keychainQuery = [self getKeychainQuery:service]; 36 | //Configure the search setting 37 | //Since in our simple case we are expecting only a single attribute to be returned (the password) we can set the attribute kSecReturnData to kCFBooleanTrue 38 | [keychainQuery setObject:(id)kCFBooleanTrue forKey:(__bridge id)kSecReturnData]; 39 | [keychainQuery setObject:(__bridge id)kSecMatchLimitOne forKey:(__bridge id)kSecMatchLimit]; 40 | CFDataRef keyData = NULL; 41 | if (SecItemCopyMatching((__bridge CFDictionaryRef)keychainQuery, (CFTypeRef *)&keyData) == noErr) { 42 | @try { 43 | ret = [NSKeyedUnarchiver unarchiveObjectWithData:(__bridge NSData *)keyData]; 44 | } @catch (NSException *e) { 45 | NSLog(@"Unarchive of %@ failed: %@", service, e); 46 | } @finally { 47 | } 48 | } 49 | if (keyData) 50 | CFRelease(keyData); 51 | return ret; 52 | } 53 | 54 | + (void)delete:(NSString *)service { 55 | NSMutableDictionary *keychainQuery = [self getKeychainQuery:service]; 56 | SecItemDelete((__bridge CFDictionaryRef)keychainQuery); 57 | } 58 | @end 59 | -------------------------------------------------------------------------------- /src/PandoSdk/HttpClient/HttpClient.h: -------------------------------------------------------------------------------- 1 | // 2 | // HttpClient.h 3 | // PandoSdk 4 | // 5 | // Created by liming_llm on 15/9/6. 6 | // Copyright (c) 2015年 liming_llm. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | #import 12 | 13 | @protocol HttpDelegate; 14 | 15 | @interface HttpClient : NSObject 16 | 17 | @property (readonly, nonatomic) NSData *recvData; 18 | 19 | - (instancetype)initWithDelegate:(id)delegate; 20 | 21 | @end 22 | 23 | @protocol HttpDelegate 24 | 25 | @required 26 | 27 | @end 28 | -------------------------------------------------------------------------------- /src/PandoSdk/HttpClient/HttpClient.m: -------------------------------------------------------------------------------- 1 | // 2 | // HttpClient.m 3 | // PandoSdk 4 | // 5 | // Created by liming_llm on 15/9/6. 6 | // Copyright (c) 2015年 liming_llm. All rights reserved. 7 | // 8 | 9 | 10 | #import "HttpClient.h" -------------------------------------------------------------------------------- /src/PandoSdk/Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | en 7 | CFBundleExecutable 8 | $(EXECUTABLE_NAME) 9 | CFBundleIdentifier 10 | com.PandoCloud.$(PRODUCT_NAME:rfc1034identifier) 11 | CFBundleInfoDictionaryVersion 12 | 6.0 13 | CFBundleName 14 | $(PRODUCT_NAME) 15 | CFBundlePackageType 16 | FMWK 17 | CFBundleShortVersionString 18 | 1.0 19 | CFBundleSignature 20 | ???? 21 | CFBundleVersion 22 | $(CURRENT_PROJECT_VERSION) 23 | NSPrincipalClass 24 | 25 | 26 | 27 | -------------------------------------------------------------------------------- /src/PandoSdk/MQTTKit/MQTTKit.h: -------------------------------------------------------------------------------- 1 | // 2 | // MQTTKit.h 3 | // MQTTKit 4 | // 5 | // Created by Jeff Mesnil on 22/10/2013. 6 | // Copyright (c) 2013 Jeff Mesnil. All rights reserved. 7 | // Copyright 2012 Nicholas Humfrey. All rights reserved. 8 | // 9 | #import 10 | 11 | typedef enum MQTTConnectionReturnCode : NSUInteger { 12 | ConnectionAccepted, 13 | ConnectionRefusedUnacceptableProtocolVersion, 14 | ConnectionRefusedIdentiferRejected, 15 | ConnectionRefusedServerUnavailable, 16 | ConnectionRefusedBadUserNameOrPassword, 17 | ConnectionRefusedNotAuthorized 18 | } MQTTConnectionReturnCode; 19 | 20 | typedef enum MQTTQualityOfService : NSUInteger { 21 | AtMostOnce, 22 | AtLeastOnce, 23 | ExactlyOnce 24 | } MQTTQualityOfService; 25 | 26 | #pragma mark - MQTT Message 27 | 28 | @interface MQTTMessage : NSObject 29 | 30 | @property (readonly, assign) unsigned short mid; 31 | @property (readonly, copy) NSString *topic; 32 | @property (readonly, copy) NSData *payload; 33 | @property (readonly, assign) BOOL retained; 34 | 35 | - (NSString *)payloadString; 36 | 37 | @end 38 | 39 | typedef void (^MQTTSubscriptionCompletionHandler)(NSArray *grantedQos); 40 | typedef void (^MQTTMessageHandler)(MQTTMessage *message); 41 | typedef void (^MQTTDisconnectionHandler)(NSUInteger code); 42 | 43 | #pragma mark - MQTT Client 44 | 45 | @class MQTTClient; 46 | 47 | @interface MQTTClient : NSObject { 48 | struct mosquitto *mosq; 49 | } 50 | 51 | @property (readwrite, copy) NSString *clientID; 52 | @property (readwrite, copy) NSString *host; 53 | @property (readwrite, assign) unsigned short port; 54 | @property (readwrite, copy) NSString *username; 55 | @property (readwrite, copy) NSString *password; 56 | @property (readwrite, assign) unsigned short keepAlive; 57 | @property (readwrite, assign) unsigned int reconnectDelay; // in seconds (default is 1) 58 | @property (readwrite, assign) unsigned int reconnectDelayMax; // in seconds (default is 1) 59 | @property (readwrite, assign) BOOL reconnectExponentialBackoff; // wheter to backoff exponentially the reconnect attempts (default is NO) 60 | @property (readwrite, assign) BOOL cleanSession; 61 | @property (readonly, assign) BOOL connected; 62 | @property (nonatomic, copy) MQTTMessageHandler messageHandler; 63 | @property (nonatomic, copy) MQTTDisconnectionHandler disconnectionHandler; 64 | 65 | + (void) initialize; 66 | + (NSString*) version; 67 | 68 | - (MQTTClient*) initWithClientId: (NSString *)clientId; 69 | - (MQTTClient*) initWithClientId: (NSString *)clientId 70 | cleanSession: (BOOL )cleanSession; 71 | - (void) setMessageRetry: (NSUInteger)seconds; 72 | 73 | #pragma mark - Connection 74 | 75 | - (void) connectWithCompletionHandler:(void (^)(MQTTConnectionReturnCode code))completionHandler; 76 | - (void) connectToHost: (NSString*)host 77 | completionHandler:(void (^)(MQTTConnectionReturnCode code))completionHandler; 78 | - (void) disconnectWithCompletionHandler:(MQTTDisconnectionHandler)completionHandler; 79 | - (void) reconnect; 80 | - (void)setWillData:(NSData *)payload 81 | toTopic:(NSString *)willTopic 82 | withQos:(MQTTQualityOfService)willQos 83 | retain:(BOOL)retain; 84 | - (void)setWill:(NSString *)payload 85 | toTopic:(NSString *)willTopic 86 | withQos:(MQTTQualityOfService)willQos 87 | retain:(BOOL)retain; 88 | - (void)clearWill; 89 | 90 | #pragma mark - Publish 91 | 92 | - (void)publishData:(NSData *)payload 93 | toTopic:(NSString *)topic 94 | withQos:(MQTTQualityOfService)qos 95 | retain:(BOOL)retain 96 | completionHandler:(void (^)(int mid))completionHandler; 97 | - (void)publishString:(NSString *)payload 98 | toTopic:(NSString *)topic 99 | withQos:(MQTTQualityOfService)qos 100 | retain:(BOOL)retain 101 | completionHandler:(void (^)(int mid))completionHandler; 102 | 103 | #pragma mark - Subscribe 104 | 105 | - (void)subscribe:(NSString *)topic 106 | withCompletionHandler:(MQTTSubscriptionCompletionHandler)completionHandler; 107 | - (void)subscribe:(NSString *)topic 108 | withQos:(MQTTQualityOfService)qos 109 | completionHandler:(MQTTSubscriptionCompletionHandler)completionHandler; 110 | - (void)unsubscribe: (NSString *)topic 111 | withCompletionHandler:(void (^)(void))completionHandler; 112 | 113 | @end 114 | -------------------------------------------------------------------------------- /src/PandoSdk/MQTTKit/libmosquitto/config.h: -------------------------------------------------------------------------------- 1 | /* ============================================================ 2 | * Control compile time options. 3 | * ============================================================ 4 | * 5 | * Compile time options have moved to config.mk. 6 | */ 7 | 8 | 9 | /* ============================================================ 10 | * Compatibility defines 11 | * 12 | * Generally for Windows native support. 13 | * ============================================================ */ 14 | #ifdef WIN32 15 | #define snprintf sprintf_s 16 | #define strcasecmp strcmpi 17 | #define strtok_r strtok_s 18 | #define strerror_r(e, b, l) strerror_s(b, l, e) 19 | #endif 20 | -------------------------------------------------------------------------------- /src/PandoSdk/MQTTKit/libmosquitto/dummypthread.h: -------------------------------------------------------------------------------- 1 | #ifndef _DUMMYPTHREAD_H_ 2 | #define _DUMMYPTHREAD_H_ 3 | 4 | #define pthread_create(A, B, C, D) 5 | #define pthread_join(A, B) 6 | #define pthread_cancel(A) 7 | 8 | #define pthread_mutex_init(A, B) 9 | #define pthread_mutex_destroy(A) 10 | #define pthread_mutex_lock(A) 11 | #define pthread_mutex_unlock(A) 12 | 13 | #endif 14 | -------------------------------------------------------------------------------- /src/PandoSdk/MQTTKit/libmosquitto/logging_mosq.c: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2009-2013 Roger Light 3 | All rights reserved. 4 | 5 | Redistribution and use in source and binary forms, with or without 6 | modification, are permitted provided that the following conditions are met: 7 | 8 | 1. Redistributions of source code must retain the above copyright notice, 9 | this list of conditions and the following disclaimer. 10 | 2. Redistributions in binary form must reproduce the above copyright 11 | notice, this list of conditions and the following disclaimer in the 12 | documentation and/or other materials provided with the distribution. 13 | 3. Neither the name of mosquitto nor the names of its 14 | contributors may be used to endorse or promote products derived from 15 | this software without specific prior written permission. 16 | 17 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 18 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 19 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 20 | ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 21 | LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 22 | CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 23 | SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 24 | INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 25 | CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 26 | ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 27 | POSSIBILITY OF SUCH DAMAGE. 28 | */ 29 | #include 30 | #include 31 | #include 32 | #include 33 | 34 | #include "mosquitto_internal.h" 35 | #include "mosquitto.h" 36 | #include "memory_mosq.h" 37 | 38 | int _mosquitto_log_printf(struct mosquitto *mosq, int priority, const char *fmt, ...) 39 | { 40 | va_list va; 41 | char *s; 42 | int len; 43 | 44 | assert(mosq); 45 | assert(fmt); 46 | 47 | pthread_mutex_lock(&mosq->log_callback_mutex); 48 | if(mosq->on_log){ 49 | len = (int)strlen(fmt) + 500; 50 | s = _mosquitto_malloc(len*sizeof(char)); 51 | if(!s){ 52 | pthread_mutex_unlock(&mosq->log_callback_mutex); 53 | return MOSQ_ERR_NOMEM; 54 | } 55 | 56 | va_start(va, fmt); 57 | vsnprintf(s, len, fmt, va); 58 | va_end(va); 59 | s[len-1] = '\0'; /* Ensure string is null terminated. */ 60 | 61 | mosq->on_log(mosq, mosq->userdata, priority, s); 62 | 63 | _mosquitto_free(s); 64 | } 65 | pthread_mutex_unlock(&mosq->log_callback_mutex); 66 | 67 | return MOSQ_ERR_SUCCESS; 68 | } 69 | 70 | -------------------------------------------------------------------------------- /src/PandoSdk/MQTTKit/libmosquitto/logging_mosq.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2009-2013 Roger Light 3 | All rights reserved. 4 | 5 | Redistribution and use in source and binary forms, with or without 6 | modification, are permitted provided that the following conditions are met: 7 | 8 | 1. Redistributions of source code must retain the above copyright notice, 9 | this list of conditions and the following disclaimer. 10 | 2. Redistributions in binary form must reproduce the above copyright 11 | notice, this list of conditions and the following disclaimer in the 12 | documentation and/or other materials provided with the distribution. 13 | 3. Neither the name of mosquitto nor the names of its 14 | contributors may be used to endorse or promote products derived from 15 | this software without specific prior written permission. 16 | 17 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 18 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 19 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 20 | ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 21 | LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 22 | CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 23 | SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 24 | INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 25 | CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 26 | ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 27 | POSSIBILITY OF SUCH DAMAGE. 28 | */ 29 | #ifndef _LOGGING_MOSQ_H_ 30 | #define _LOGGING_MOSQ_H_ 31 | 32 | #include "mosquitto.h" 33 | 34 | int _mosquitto_log_printf(struct mosquitto *mosq, int priority, const char *fmt, ...); 35 | 36 | #endif 37 | -------------------------------------------------------------------------------- /src/PandoSdk/MQTTKit/libmosquitto/memory_mosq.c: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2009-2013 Roger Light 3 | All rights reserved. 4 | 5 | Redistribution and use in source and binary forms, with or without 6 | modification, are permitted provided that the following conditions are met: 7 | 8 | 1. Redistributions of source code must retain the above copyright notice, 9 | this list of conditions and the following disclaimer. 10 | 2. Redistributions in binary form must reproduce the above copyright 11 | notice, this list of conditions and the following disclaimer in the 12 | documentation and/or other materials provided with the distribution. 13 | 3. Neither the name of mosquitto nor the names of its 14 | contributors may be used to endorse or promote products derived from 15 | this software without specific prior written permission. 16 | 17 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 18 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 19 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 20 | ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 21 | LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 22 | CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 23 | SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 24 | INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 25 | CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 26 | ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 27 | POSSIBILITY OF SUCH DAMAGE. 28 | */ 29 | 30 | #include "config.h" 31 | 32 | #include 33 | #include 34 | 35 | #include "memory_mosq.h" 36 | 37 | #ifdef REAL_WITH_MEMORY_TRACKING 38 | # if defined(__APPLE__) 39 | # include 40 | # define malloc_usable_size malloc_size 41 | # elif defined(__FreeBSD__) 42 | # include 43 | # else 44 | # include 45 | # endif 46 | #endif 47 | 48 | #ifdef REAL_WITH_MEMORY_TRACKING 49 | static unsigned long memcount = 0; 50 | static unsigned long max_memcount = 0; 51 | #endif 52 | 53 | void *_mosquitto_calloc(size_t nmemb, size_t size) 54 | { 55 | void *mem = calloc(nmemb, size); 56 | 57 | #ifdef REAL_WITH_MEMORY_TRACKING 58 | memcount += malloc_usable_size(mem); 59 | if(memcount > max_memcount){ 60 | max_memcount = memcount; 61 | } 62 | #endif 63 | 64 | return mem; 65 | } 66 | 67 | void _mosquitto_free(void *mem) 68 | { 69 | #ifdef REAL_WITH_MEMORY_TRACKING 70 | memcount -= malloc_usable_size(mem); 71 | #endif 72 | free(mem); 73 | } 74 | 75 | void *_mosquitto_malloc(size_t size) 76 | { 77 | void *mem = malloc(size); 78 | 79 | #ifdef REAL_WITH_MEMORY_TRACKING 80 | memcount += malloc_usable_size(mem); 81 | if(memcount > max_memcount){ 82 | max_memcount = memcount; 83 | } 84 | #endif 85 | 86 | return mem; 87 | } 88 | 89 | #ifdef REAL_WITH_MEMORY_TRACKING 90 | unsigned long _mosquitto_memory_used(void) 91 | { 92 | return memcount; 93 | } 94 | 95 | unsigned long _mosquitto_max_memory_used(void) 96 | { 97 | return max_memcount; 98 | } 99 | #endif 100 | 101 | void *_mosquitto_realloc(void *ptr, size_t size) 102 | { 103 | void *mem; 104 | #ifdef REAL_WITH_MEMORY_TRACKING 105 | if(ptr){ 106 | memcount -= malloc_usable_size(ptr); 107 | } 108 | #endif 109 | mem = realloc(ptr, size); 110 | 111 | #ifdef REAL_WITH_MEMORY_TRACKING 112 | memcount += malloc_usable_size(mem); 113 | if(memcount > max_memcount){ 114 | max_memcount = memcount; 115 | } 116 | #endif 117 | 118 | return mem; 119 | } 120 | 121 | char *_mosquitto_strdup(const char *s) 122 | { 123 | char *str = strdup(s); 124 | 125 | #ifdef REAL_WITH_MEMORY_TRACKING 126 | memcount += malloc_usable_size(str); 127 | if(memcount > max_memcount){ 128 | max_memcount = memcount; 129 | } 130 | #endif 131 | 132 | return str; 133 | } 134 | 135 | -------------------------------------------------------------------------------- /src/PandoSdk/MQTTKit/libmosquitto/memory_mosq.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2010-2013 Roger Light 3 | All rights reserved. 4 | 5 | Redistribution and use in source and binary forms, with or without 6 | modification, are permitted provided that the following conditions are met: 7 | 8 | 1. Redistributions of source code must retain the above copyright notice, 9 | this list of conditions and the following disclaimer. 10 | 2. Redistributions in binary form must reproduce the above copyright 11 | notice, this list of conditions and the following disclaimer in the 12 | documentation and/or other materials provided with the distribution. 13 | 3. Neither the name of mosquitto nor the names of its 14 | contributors may be used to endorse or promote products derived from 15 | this software without specific prior written permission. 16 | 17 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 18 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 19 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 20 | ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 21 | LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 22 | CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 23 | SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 24 | INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 25 | CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 26 | ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 27 | POSSIBILITY OF SUCH DAMAGE. 28 | */ 29 | 30 | #ifndef _MEMORY_MOSQ_H_ 31 | #define _MEMORY_MOSQ_H_ 32 | 33 | #include 34 | 35 | #if defined(WITH_MEMORY_TRACKING) && defined(WITH_BROKER) && !defined(WIN32) && !defined(__SYMBIAN32__) && !defined(__ANDROID__) 36 | #define REAL_WITH_MEMORY_TRACKING 37 | #endif 38 | 39 | void *_mosquitto_calloc(size_t nmemb, size_t size); 40 | void _mosquitto_free(void *mem); 41 | void *_mosquitto_malloc(size_t size); 42 | #ifdef REAL_WITH_MEMORY_TRACKING 43 | unsigned long _mosquitto_memory_used(void); 44 | unsigned long _mosquitto_max_memory_used(void); 45 | #endif 46 | void *_mosquitto_realloc(void *ptr, size_t size); 47 | char *_mosquitto_strdup(const char *s); 48 | 49 | #endif 50 | -------------------------------------------------------------------------------- /src/PandoSdk/MQTTKit/libmosquitto/messages_mosq.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2010-2013 Roger Light 3 | All rights reserved. 4 | 5 | Redistribution and use in source and binary forms, with or without 6 | modification, are permitted provided that the following conditions are met: 7 | 8 | 1. Redistributions of source code must retain the above copyright notice, 9 | this list of conditions and the following disclaimer. 10 | 2. Redistributions in binary form must reproduce the above copyright 11 | notice, this list of conditions and the following disclaimer in the 12 | documentation and/or other materials provided with the distribution. 13 | 3. Neither the name of mosquitto nor the names of its 14 | contributors may be used to endorse or promote products derived from 15 | this software without specific prior written permission. 16 | 17 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 18 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 19 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 20 | ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 21 | LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 22 | CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 23 | SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 24 | INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 25 | CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 26 | ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 27 | POSSIBILITY OF SUCH DAMAGE. 28 | */ 29 | #ifndef _MESSAGES_MOSQ_H_ 30 | #define _MESSAGES_MOSQ_H_ 31 | 32 | #include "mosquitto_internal.h" 33 | #include "mosquitto.h" 34 | 35 | void _mosquitto_message_cleanup_all(struct mosquitto *mosq); 36 | void _mosquitto_message_cleanup(struct mosquitto_message_all **message); 37 | int _mosquitto_message_delete(struct mosquitto *mosq, uint16_t mid, enum mosquitto_msg_direction dir); 38 | void _mosquitto_message_queue(struct mosquitto *mosq, struct mosquitto_message_all *message, bool doinc); 39 | void _mosquitto_messages_reconnect_reset(struct mosquitto *mosq); 40 | int _mosquitto_message_remove(struct mosquitto *mosq, uint16_t mid, enum mosquitto_msg_direction dir, struct mosquitto_message_all **message); 41 | void _mosquitto_message_retry_check(struct mosquitto *mosq); 42 | int _mosquitto_message_update(struct mosquitto *mosq, uint16_t mid, enum mosquitto_msg_direction dir, enum mosquitto_msg_state state); 43 | 44 | #endif 45 | -------------------------------------------------------------------------------- /src/PandoSdk/MQTTKit/libmosquitto/mosquitto_internal.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2010,2011,2013 Roger Light 3 | All rights reserved. 4 | 5 | Redistribution and use in source and binary forms, with or without 6 | modification, are permitted provided that the following conditions are met: 7 | 8 | 1. Redistributions of source code must retain the above copyright notice, 9 | this list of conditions and the following disclaimer. 10 | 2. Redistributions in binary form must reproduce the above copyright 11 | notice, this list of conditions and the following disclaimer in the 12 | documentation and/or other materials provided with the distribution. 13 | 3. Neither the name of mosquitto nor the names of its 14 | contributors may be used to endorse or promote products derived from 15 | this software without specific prior written permission. 16 | 17 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 18 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 19 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 20 | ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 21 | LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 22 | CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 23 | SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 24 | INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 25 | CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 26 | ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 27 | POSSIBILITY OF SUCH DAMAGE. 28 | */ 29 | 30 | #ifndef _MOSQUITTO_INTERNAL_H_ 31 | #define _MOSQUITTO_INTERNAL_H_ 32 | 33 | #include "config.h" 34 | 35 | #ifdef WIN32 36 | # include 37 | #endif 38 | 39 | #ifdef WITH_TLS 40 | #include 41 | #endif 42 | #include 43 | 44 | #if defined(WITH_THREADING) && !defined(WITH_BROKER) 45 | # include 46 | #else 47 | # include 48 | #endif 49 | 50 | #ifdef WIN32 51 | # if _MSC_VER < 1600 52 | typedef unsigned char uint8_t; 53 | typedef unsigned short uint16_t; 54 | typedef unsigned int uint32_t; 55 | typedef unsigned long long uint64_t; 56 | # else 57 | # include 58 | # endif 59 | #else 60 | # include 61 | #endif 62 | 63 | #include "mosquitto.h" 64 | #include "time_mosq.h" 65 | #ifdef WITH_BROKER 66 | struct mosquitto_client_msg; 67 | #endif 68 | 69 | enum mosquitto_msg_direction { 70 | mosq_md_in = 0, 71 | mosq_md_out = 1 72 | }; 73 | 74 | enum mosquitto_msg_state { 75 | mosq_ms_invalid = 0, 76 | mosq_ms_publish_qos0 = 1, 77 | mosq_ms_publish_qos1 = 2, 78 | mosq_ms_wait_for_puback = 3, 79 | mosq_ms_publish_qos2 = 4, 80 | mosq_ms_wait_for_pubrec = 5, 81 | mosq_ms_resend_pubrel = 6, 82 | mosq_ms_wait_for_pubrel = 7, 83 | mosq_ms_resend_pubcomp = 8, 84 | mosq_ms_wait_for_pubcomp = 9, 85 | mosq_ms_send_pubrec = 10, 86 | mosq_ms_queued = 11 87 | }; 88 | 89 | enum mosquitto_client_state { 90 | mosq_cs_new = 0, 91 | mosq_cs_connected = 1, 92 | mosq_cs_disconnecting = 2, 93 | mosq_cs_connect_async = 3, 94 | mosq_cs_connect_pending = 4 95 | }; 96 | 97 | struct _mosquitto_packet{ 98 | uint8_t command; 99 | uint8_t have_remaining; 100 | uint8_t remaining_count; 101 | uint16_t mid; 102 | uint32_t remaining_mult; 103 | uint32_t remaining_length; 104 | uint32_t packet_length; 105 | uint32_t to_process; 106 | uint32_t pos; 107 | uint8_t *payload; 108 | struct _mosquitto_packet *next; 109 | }; 110 | 111 | struct mosquitto_message_all{ 112 | struct mosquitto_message_all *next; 113 | time_t timestamp; 114 | enum mosquitto_msg_direction direction; 115 | enum mosquitto_msg_state state; 116 | bool dup; 117 | struct mosquitto_message msg; 118 | }; 119 | 120 | struct mosquitto { 121 | #ifndef WIN32 122 | int sock; 123 | #else 124 | SOCKET sock; 125 | #endif 126 | char *address; 127 | char *id; 128 | char *username; 129 | char *password; 130 | uint16_t keepalive; 131 | bool clean_session; 132 | enum mosquitto_client_state state; 133 | time_t last_msg_in; 134 | time_t last_msg_out; 135 | time_t ping_t; 136 | uint16_t last_mid; 137 | struct _mosquitto_packet in_packet; 138 | struct _mosquitto_packet *current_out_packet; 139 | struct _mosquitto_packet *out_packet; 140 | struct mosquitto_message *will; 141 | #ifdef WITH_TLS 142 | SSL *ssl; 143 | SSL_CTX *ssl_ctx; 144 | char *tls_cafile; 145 | char *tls_capath; 146 | char *tls_certfile; 147 | char *tls_keyfile; 148 | int (*tls_pw_callback)(char *buf, int size, int rwflag, void *userdata); 149 | int tls_cert_reqs; 150 | char *tls_version; 151 | char *tls_ciphers; 152 | char *tls_psk; 153 | char *tls_psk_identity; 154 | bool tls_insecure; 155 | #endif 156 | bool want_write; 157 | #if defined(WITH_THREADING) && !defined(WITH_BROKER) 158 | pthread_mutex_t callback_mutex; 159 | pthread_mutex_t log_callback_mutex; 160 | pthread_mutex_t msgtime_mutex; 161 | pthread_mutex_t out_packet_mutex; 162 | pthread_mutex_t current_out_packet_mutex; 163 | pthread_mutex_t state_mutex; 164 | pthread_mutex_t message_mutex; 165 | pthread_t thread_id; 166 | #endif 167 | #ifdef WITH_BROKER 168 | bool is_bridge; 169 | struct _mqtt3_bridge *bridge; 170 | struct mosquitto_client_msg *msgs; 171 | struct _mosquitto_acl_user *acl_list; 172 | struct _mqtt3_listener *listener; 173 | time_t disconnect_t; 174 | int pollfd_index; 175 | int db_index; 176 | struct _mosquitto_packet *out_packet_last; 177 | #else 178 | void *userdata; 179 | bool in_callback; 180 | unsigned int message_retry; 181 | time_t last_retry_check; 182 | struct mosquitto_message_all *messages; 183 | void (*on_connect)(struct mosquitto *, void *userdata, int rc); 184 | void (*on_disconnect)(struct mosquitto *, void *userdata, int rc); 185 | void (*on_publish)(struct mosquitto *, void *userdata, int mid); 186 | void (*on_message)(struct mosquitto *, void *userdata, const struct mosquitto_message *message); 187 | void (*on_subscribe)(struct mosquitto *, void *userdata, int mid, int qos_count, const int *granted_qos); 188 | void (*on_unsubscribe)(struct mosquitto *, void *userdata, int mid); 189 | void (*on_log)(struct mosquitto *, void *userdata, int level, const char *str); 190 | //void (*on_error)(); 191 | char *host; 192 | int port; 193 | int queue_len; 194 | char *bind_address; 195 | unsigned int reconnect_delay; 196 | unsigned int reconnect_delay_max; 197 | bool reconnect_exponential_backoff; 198 | bool threaded; 199 | struct _mosquitto_packet *out_packet_last; 200 | struct mosquitto_message_all *messages_last; 201 | int inflight_messages; 202 | int max_inflight_messages; 203 | #endif 204 | }; 205 | 206 | #endif 207 | -------------------------------------------------------------------------------- /src/PandoSdk/MQTTKit/libmosquitto/mqtt3_protocol.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2009-2013 Roger Light 3 | All rights reserved. 4 | 5 | Redistribution and use in source and binary forms, with or without 6 | modification, are permitted provided that the following conditions are met: 7 | 8 | 1. Redistributions of source code must retain the above copyright notice, 9 | this list of conditions and the following disclaimer. 10 | 2. Redistributions in binary form must reproduce the above copyright 11 | notice, this list of conditions and the following disclaimer in the 12 | documentation and/or other materials provided with the distribution. 13 | 3. Neither the name of mosquitto nor the names of its 14 | contributors may be used to endorse or promote products derived from 15 | this software without specific prior written permission. 16 | 17 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 18 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 19 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 20 | ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 21 | LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 22 | CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 23 | SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 24 | INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 25 | CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 26 | ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 27 | POSSIBILITY OF SUCH DAMAGE. 28 | */ 29 | 30 | #ifndef _MQTT3_PROTOCOL_H_ 31 | #define _MQTT3_PROTOCOL_H_ 32 | 33 | /* For version 3 of the MQTT protocol */ 34 | 35 | #define PROTOCOL_NAME "MQIsdp" 36 | #define PROTOCOL_VERSION 3 37 | 38 | /* Message types */ 39 | #define CONNECT 0x10 40 | #define CONNACK 0x20 41 | #define PUBLISH 0x30 42 | #define PUBACK 0x40 43 | #define PUBREC 0x50 44 | #define PUBREL 0x60 45 | #define PUBCOMP 0x70 46 | #define SUBSCRIBE 0x80 47 | #define SUBACK 0x90 48 | #define UNSUBSCRIBE 0xA0 49 | #define UNSUBACK 0xB0 50 | #define PINGREQ 0xC0 51 | #define PINGRESP 0xD0 52 | #define DISCONNECT 0xE0 53 | 54 | #define CONNACK_ACCEPTED 0 55 | #define CONNACK_REFUSED_PROTOCOL_VERSION 1 56 | #define CONNACK_REFUSED_IDENTIFIER_REJECTED 2 57 | #define CONNACK_REFUSED_SERVER_UNAVAILABLE 3 58 | #define CONNACK_REFUSED_BAD_USERNAME_PASSWORD 4 59 | #define CONNACK_REFUSED_NOT_AUTHORIZED 5 60 | 61 | #define MQTT_MAX_PAYLOAD 268435455 62 | 63 | #endif 64 | -------------------------------------------------------------------------------- /src/PandoSdk/MQTTKit/libmosquitto/net_mosq.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2010,2011,2013 Roger Light 3 | All rights reserved. 4 | 5 | Redistribution and use in source and binary forms, with or without 6 | modification, are permitted provided that the following conditions are met: 7 | 8 | 1. Redistributions of source code must retain the above copyright notice, 9 | this list of conditions and the following disclaimer. 10 | 2. Redistributions in binary form must reproduce the above copyright 11 | notice, this list of conditions and the following disclaimer in the 12 | documentation and/or other materials provided with the distribution. 13 | 3. Neither the name of mosquitto nor the names of its 14 | contributors may be used to endorse or promote products derived from 15 | this software without specific prior written permission. 16 | 17 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 18 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 19 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 20 | ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 21 | LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 22 | CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 23 | SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 24 | INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 25 | CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 26 | ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 27 | POSSIBILITY OF SUCH DAMAGE. 28 | */ 29 | #ifndef _NET_MOSQ_H_ 30 | #define _NET_MOSQ_H_ 31 | 32 | #ifndef WIN32 33 | #include 34 | #else 35 | #include 36 | typedef int ssize_t; 37 | #endif 38 | 39 | #include "mosquitto_internal.h" 40 | #include "mosquitto.h" 41 | 42 | #ifdef WITH_BROKER 43 | struct mosquitto_db; 44 | #endif 45 | 46 | #ifdef WIN32 47 | # define COMPAT_CLOSE(a) closesocket(a) 48 | # define COMPAT_ECONNRESET WSAECONNRESET 49 | # define COMPAT_EWOULDBLOCK WSAEWOULDBLOCK 50 | #else 51 | # define COMPAT_CLOSE(a) close(a) 52 | # define COMPAT_ECONNRESET ECONNRESET 53 | # define COMPAT_EWOULDBLOCK EWOULDBLOCK 54 | #endif 55 | 56 | #ifndef WIN32 57 | #else 58 | #endif 59 | 60 | /* For when not using winsock libraries. */ 61 | #ifndef INVALID_SOCKET 62 | #define INVALID_SOCKET -1 63 | #endif 64 | 65 | /* Macros for accessing the MSB and LSB of a uint16_t */ 66 | #define MOSQ_MSB(A) (uint8_t)((A & 0xFF00) >> 8) 67 | #define MOSQ_LSB(A) (uint8_t)(A & 0x00FF) 68 | 69 | void _mosquitto_net_init(void); 70 | void _mosquitto_net_cleanup(void); 71 | 72 | void _mosquitto_packet_cleanup(struct _mosquitto_packet *packet); 73 | int _mosquitto_packet_queue(struct mosquitto *mosq, struct _mosquitto_packet *packet); 74 | int _mosquitto_socket_connect(struct mosquitto *mosq, const char *host, uint16_t port, const char *bind_address, bool blocking); 75 | int _mosquitto_socket_close(struct mosquitto *mosq); 76 | int _mosquitto_try_connect(const char *host, uint16_t port, int *sock, const char *bind_address, bool blocking); 77 | 78 | int _mosquitto_read_byte(struct _mosquitto_packet *packet, uint8_t *byte); 79 | int _mosquitto_read_bytes(struct _mosquitto_packet *packet, void *bytes, uint32_t count); 80 | int _mosquitto_read_string(struct _mosquitto_packet *packet, char **str); 81 | int _mosquitto_read_uint16(struct _mosquitto_packet *packet, uint16_t *word); 82 | 83 | void _mosquitto_write_byte(struct _mosquitto_packet *packet, uint8_t byte); 84 | void _mosquitto_write_bytes(struct _mosquitto_packet *packet, const void *bytes, uint32_t count); 85 | void _mosquitto_write_string(struct _mosquitto_packet *packet, const char *str, uint16_t length); 86 | void _mosquitto_write_uint16(struct _mosquitto_packet *packet, uint16_t word); 87 | 88 | ssize_t _mosquitto_net_read(struct mosquitto *mosq, void *buf, size_t count); 89 | ssize_t _mosquitto_net_write(struct mosquitto *mosq, void *buf, size_t count); 90 | 91 | int _mosquitto_packet_write(struct mosquitto *mosq); 92 | #ifdef WITH_BROKER 93 | int _mosquitto_packet_read(struct mosquitto_db *db, struct mosquitto *mosq); 94 | #else 95 | int _mosquitto_packet_read(struct mosquitto *mosq); 96 | #endif 97 | 98 | #ifdef WITH_TLS 99 | int _mosquitto_socket_apply_tls(struct mosquitto *mosq); 100 | #endif 101 | 102 | #endif 103 | -------------------------------------------------------------------------------- /src/PandoSdk/MQTTKit/libmosquitto/read_handle.c: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2009-2013 Roger Light 3 | All rights reserved. 4 | 5 | Redistribution and use in source and binary forms, with or without 6 | modification, are permitted provided that the following conditions are met: 7 | 8 | 1. Redistributions of source code must retain the above copyright notice, 9 | this list of conditions and the following disclaimer. 10 | 2. Redistributions in binary form must reproduce the above copyright 11 | notice, this list of conditions and the following disclaimer in the 12 | documentation and/or other materials provided with the distribution. 13 | 3. Neither the name of mosquitto nor the names of its 14 | contributors may be used to endorse or promote products derived from 15 | this software without specific prior written permission. 16 | 17 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 18 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 19 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 20 | ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 21 | LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 22 | CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 23 | SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 24 | INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 25 | CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 26 | ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 27 | POSSIBILITY OF SUCH DAMAGE. 28 | */ 29 | 30 | #include 31 | #include 32 | #include 33 | 34 | #include "mosquitto.h" 35 | #include "logging_mosq.h" 36 | #include "memory_mosq.h" 37 | #include "messages_mosq.h" 38 | #include "mqtt3_protocol.h" 39 | #include "net_mosq.h" 40 | #include "read_handle.h" 41 | #include "send_mosq.h" 42 | #include "time_mosq.h" 43 | #include "util_mosq.h" 44 | 45 | int _mosquitto_packet_handle(struct mosquitto *mosq) 46 | { 47 | assert(mosq); 48 | 49 | switch((mosq->in_packet.command)&0xF0){ 50 | case PINGREQ: 51 | return _mosquitto_handle_pingreq(mosq); 52 | case PINGRESP: 53 | return _mosquitto_handle_pingresp(mosq); 54 | case PUBACK: 55 | return _mosquitto_handle_pubackcomp(mosq, "PUBACK"); 56 | case PUBCOMP: 57 | return _mosquitto_handle_pubackcomp(mosq, "PUBCOMP"); 58 | case PUBLISH: 59 | return _mosquitto_handle_publish(mosq); 60 | case PUBREC: 61 | return _mosquitto_handle_pubrec(mosq); 62 | case PUBREL: 63 | return _mosquitto_handle_pubrel(NULL, mosq); 64 | case CONNACK: 65 | return _mosquitto_handle_connack(mosq); 66 | case SUBACK: 67 | return _mosquitto_handle_suback(mosq); 68 | case UNSUBACK: 69 | return _mosquitto_handle_unsuback(mosq); 70 | default: 71 | /* If we don't recognise the command, return an error straight away. */ 72 | _mosquitto_log_printf(mosq, MOSQ_LOG_ERR, "Error: Unrecognised command %d\n", (mosq->in_packet.command)&0xF0); 73 | return MOSQ_ERR_PROTOCOL; 74 | } 75 | } 76 | 77 | int _mosquitto_handle_publish(struct mosquitto *mosq) 78 | { 79 | uint8_t header; 80 | struct mosquitto_message_all *message; 81 | int rc = 0; 82 | uint16_t mid; 83 | 84 | assert(mosq); 85 | 86 | message = _mosquitto_calloc(1, sizeof(struct mosquitto_message_all)); 87 | if(!message) return MOSQ_ERR_NOMEM; 88 | 89 | header = mosq->in_packet.command; 90 | 91 | message->direction = mosq_md_in; 92 | message->dup = (header & 0x08)>>3; 93 | message->msg.qos = (header & 0x06)>>1; 94 | message->msg.retain = (header & 0x01); 95 | 96 | rc = _mosquitto_read_string(&mosq->in_packet, &message->msg.topic); 97 | if(rc){ 98 | _mosquitto_message_cleanup(&message); 99 | return rc; 100 | } 101 | rc = _mosquitto_fix_sub_topic(&message->msg.topic); 102 | if(rc){ 103 | _mosquitto_message_cleanup(&message); 104 | return rc; 105 | } 106 | if(!strlen(message->msg.topic)){ 107 | _mosquitto_message_cleanup(&message); 108 | return MOSQ_ERR_PROTOCOL; 109 | } 110 | 111 | if(message->msg.qos > 0){ 112 | rc = _mosquitto_read_uint16(&mosq->in_packet, &mid); 113 | if(rc){ 114 | _mosquitto_message_cleanup(&message); 115 | return rc; 116 | } 117 | message->msg.mid = (int)mid; 118 | } 119 | 120 | message->msg.payloadlen = mosq->in_packet.remaining_length - mosq->in_packet.pos; 121 | if(message->msg.payloadlen){ 122 | message->msg.payload = _mosquitto_calloc(message->msg.payloadlen+1, sizeof(uint8_t)); 123 | if(!message->msg.payload){ 124 | _mosquitto_message_cleanup(&message); 125 | return MOSQ_ERR_NOMEM; 126 | } 127 | rc = _mosquitto_read_bytes(&mosq->in_packet, message->msg.payload, message->msg.payloadlen); 128 | if(rc){ 129 | _mosquitto_message_cleanup(&message); 130 | return rc; 131 | } 132 | } 133 | _mosquitto_log_printf(mosq, MOSQ_LOG_DEBUG, 134 | "Client %s received PUBLISH (d%d, q%d, r%d, m%d, '%s', ... (%ld bytes))", 135 | mosq->id, message->dup, message->msg.qos, message->msg.retain, 136 | message->msg.mid, message->msg.topic, 137 | (long)message->msg.payloadlen); 138 | 139 | message->timestamp = mosquitto_time(); 140 | switch(message->msg.qos){ 141 | case 0: 142 | pthread_mutex_lock(&mosq->callback_mutex); 143 | if(mosq->on_message){ 144 | mosq->in_callback = true; 145 | mosq->on_message(mosq, mosq->userdata, &message->msg); 146 | mosq->in_callback = false; 147 | } 148 | pthread_mutex_unlock(&mosq->callback_mutex); 149 | _mosquitto_message_cleanup(&message); 150 | return MOSQ_ERR_SUCCESS; 151 | case 1: 152 | rc = _mosquitto_send_puback(mosq, message->msg.mid); 153 | pthread_mutex_lock(&mosq->callback_mutex); 154 | if(mosq->on_message){ 155 | mosq->in_callback = true; 156 | mosq->on_message(mosq, mosq->userdata, &message->msg); 157 | mosq->in_callback = false; 158 | } 159 | pthread_mutex_unlock(&mosq->callback_mutex); 160 | _mosquitto_message_cleanup(&message); 161 | return rc; 162 | case 2: 163 | rc = _mosquitto_send_pubrec(mosq, message->msg.mid); 164 | pthread_mutex_lock(&mosq->message_mutex); 165 | message->state = mosq_ms_wait_for_pubrel; 166 | _mosquitto_message_queue(mosq, message, true); 167 | pthread_mutex_unlock(&mosq->message_mutex); 168 | return rc; 169 | default: 170 | _mosquitto_message_cleanup(&message); 171 | return MOSQ_ERR_PROTOCOL; 172 | } 173 | } 174 | 175 | -------------------------------------------------------------------------------- /src/PandoSdk/MQTTKit/libmosquitto/read_handle.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2010-2013 Roger Light 3 | All rights reserved. 4 | 5 | Redistribution and use in source and binary forms, with or without 6 | modification, are permitted provided that the following conditions are met: 7 | 8 | 1. Redistributions of source code must retain the above copyright notice, 9 | this list of conditions and the following disclaimer. 10 | 2. Redistributions in binary form must reproduce the above copyright 11 | notice, this list of conditions and the following disclaimer in the 12 | documentation and/or other materials provided with the distribution. 13 | 3. Neither the name of mosquitto nor the names of its 14 | contributors may be used to endorse or promote products derived from 15 | this software without specific prior written permission. 16 | 17 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 18 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 19 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 20 | ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 21 | LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 22 | CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 23 | SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 24 | INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 25 | CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 26 | ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 27 | POSSIBILITY OF SUCH DAMAGE. 28 | */ 29 | #ifndef _READ_HANDLE_H_ 30 | #define _READ_HANDLE_H_ 31 | 32 | #include "mosquitto.h" 33 | struct mosquitto_db; 34 | 35 | int _mosquitto_packet_handle(struct mosquitto *mosq); 36 | int _mosquitto_handle_connack(struct mosquitto *mosq); 37 | int _mosquitto_handle_pingreq(struct mosquitto *mosq); 38 | int _mosquitto_handle_pingresp(struct mosquitto *mosq); 39 | int _mosquitto_handle_pubackcomp(struct mosquitto *mosq, const char *type); 40 | int _mosquitto_handle_publish(struct mosquitto *mosq); 41 | int _mosquitto_handle_pubrec(struct mosquitto *mosq); 42 | int _mosquitto_handle_pubrel(struct mosquitto_db *db, struct mosquitto *mosq); 43 | int _mosquitto_handle_suback(struct mosquitto *mosq); 44 | int _mosquitto_handle_unsuback(struct mosquitto *mosq); 45 | 46 | 47 | #endif 48 | -------------------------------------------------------------------------------- /src/PandoSdk/MQTTKit/libmosquitto/read_handle_client.c: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2009-2013 Roger Light 3 | All rights reserved. 4 | 5 | Redistribution and use in source and binary forms, with or without 6 | modification, are permitted provided that the following conditions are met: 7 | 8 | 1. Redistributions of source code must retain the above copyright notice, 9 | this list of conditions and the following disclaimer. 10 | 2. Redistributions in binary form must reproduce the above copyright 11 | notice, this list of conditions and the following disclaimer in the 12 | documentation and/or other materials provided with the distribution. 13 | 3. Neither the name of mosquitto nor the names of its 14 | contributors may be used to endorse or promote products derived from 15 | this software without specific prior written permission. 16 | 17 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 18 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 19 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 20 | ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 21 | LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 22 | CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 23 | SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 24 | INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 25 | CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 26 | ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 27 | POSSIBILITY OF SUCH DAMAGE. 28 | */ 29 | 30 | #include 31 | 32 | #include "mosquitto.h" 33 | #include "logging_mosq.h" 34 | #include "memory_mosq.h" 35 | #include "net_mosq.h" 36 | #include "read_handle.h" 37 | 38 | int _mosquitto_handle_connack(struct mosquitto *mosq) 39 | { 40 | uint8_t byte; 41 | uint8_t result; 42 | int rc; 43 | 44 | assert(mosq); 45 | #ifdef WITH_STRICT_PROTOCOL 46 | if(mosq->in_packet.remaining_length != 2){ 47 | return MOSQ_ERR_PROTOCOL; 48 | } 49 | #endif 50 | _mosquitto_log_printf(mosq, MOSQ_LOG_DEBUG, "Client %s received CONNACK", mosq->id); 51 | rc = _mosquitto_read_byte(&mosq->in_packet, &byte); // Reserved byte, not used 52 | if(rc) return rc; 53 | rc = _mosquitto_read_byte(&mosq->in_packet, &result); 54 | if(rc) return rc; 55 | pthread_mutex_lock(&mosq->callback_mutex); 56 | if(mosq->on_connect){ 57 | mosq->in_callback = true; 58 | mosq->on_connect(mosq, mosq->userdata, result); 59 | mosq->in_callback = false; 60 | } 61 | pthread_mutex_unlock(&mosq->callback_mutex); 62 | switch(result){ 63 | case 0: 64 | mosq->state = mosq_cs_connected; 65 | return MOSQ_ERR_SUCCESS; 66 | case 1: 67 | case 2: 68 | case 3: 69 | case 4: 70 | case 5: 71 | return MOSQ_ERR_CONN_REFUSED; 72 | default: 73 | return MOSQ_ERR_PROTOCOL; 74 | } 75 | } 76 | 77 | -------------------------------------------------------------------------------- /src/PandoSdk/MQTTKit/libmosquitto/send_mosq.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2010-2013 Roger Light 3 | All rights reserved. 4 | 5 | Redistribution and use in source and binary forms, with or without 6 | modification, are permitted provided that the following conditions are met: 7 | 8 | 1. Redistributions of source code must retain the above copyright notice, 9 | this list of conditions and the following disclaimer. 10 | 2. Redistributions in binary form must reproduce the above copyright 11 | notice, this list of conditions and the following disclaimer in the 12 | documentation and/or other materials provided with the distribution. 13 | 3. Neither the name of mosquitto nor the names of its 14 | contributors may be used to endorse or promote products derived from 15 | this software without specific prior written permission. 16 | 17 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 18 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 19 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 20 | ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 21 | LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 22 | CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 23 | SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 24 | INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 25 | CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 26 | ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 27 | POSSIBILITY OF SUCH DAMAGE. 28 | */ 29 | #ifndef _SEND_MOSQ_H_ 30 | #define _SEND_MOSQ_H_ 31 | 32 | #include "mosquitto.h" 33 | 34 | int _mosquitto_send_simple_command(struct mosquitto *mosq, uint8_t command); 35 | int _mosquitto_send_command_with_mid(struct mosquitto *mosq, uint8_t command, uint16_t mid, bool dup); 36 | int _mosquitto_send_real_publish(struct mosquitto *mosq, uint16_t mid, const char *topic, uint32_t payloadlen, const void *payload, int qos, bool retain, bool dup); 37 | 38 | int _mosquitto_send_connect(struct mosquitto *mosq, uint16_t keepalive, bool clean_session); 39 | int _mosquitto_send_disconnect(struct mosquitto *mosq); 40 | int _mosquitto_send_pingreq(struct mosquitto *mosq); 41 | int _mosquitto_send_pingresp(struct mosquitto *mosq); 42 | int _mosquitto_send_puback(struct mosquitto *mosq, uint16_t mid); 43 | int _mosquitto_send_pubcomp(struct mosquitto *mosq, uint16_t mid); 44 | int _mosquitto_send_publish(struct mosquitto *mosq, uint16_t mid, const char *topic, uint32_t payloadlen, const void *payload, int qos, bool retain, bool dup); 45 | int _mosquitto_send_pubrec(struct mosquitto *mosq, uint16_t mid); 46 | int _mosquitto_send_pubrel(struct mosquitto *mosq, uint16_t mid, bool dup); 47 | int _mosquitto_send_subscribe(struct mosquitto *mosq, int *mid, bool dup, const char *topic, uint8_t topic_qos); 48 | int _mosquitto_send_unsubscribe(struct mosquitto *mosq, int *mid, bool dup, const char *topic); 49 | 50 | #endif 51 | -------------------------------------------------------------------------------- /src/PandoSdk/MQTTKit/libmosquitto/thread_mosq.c: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2011-2013 Roger Light 3 | All rights reserved. 4 | 5 | Redistribution and use in source and binary forms, with or without 6 | modification, are permitted provided that the following conditions are met: 7 | 8 | 1. Redistributions of source code must retain the above copyright notice, 9 | this list of conditions and the following disclaimer. 10 | 2. Redistributions in binary form must reproduce the above copyright 11 | notice, this list of conditions and the following disclaimer in the 12 | documentation and/or other materials provided with the distribution. 13 | 3. Neither the name of mosquitto nor the names of its 14 | contributors may be used to endorse or promote products derived from 15 | this software without specific prior written permission. 16 | 17 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 18 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 19 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 20 | ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 21 | LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 22 | CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 23 | SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 24 | INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 25 | CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 26 | ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 27 | POSSIBILITY OF SUCH DAMAGE. 28 | */ 29 | 30 | #include "config.h" 31 | 32 | #ifndef WIN32 33 | #include 34 | #endif 35 | 36 | #include "mosquitto_internal.h" 37 | 38 | void *_mosquitto_thread_main(void *obj); 39 | 40 | int mosquitto_loop_start(struct mosquitto *mosq) 41 | { 42 | #ifdef WITH_THREADING 43 | if(!mosq) return MOSQ_ERR_INVAL; 44 | 45 | pthread_create(&mosq->thread_id, NULL, _mosquitto_thread_main, mosq); 46 | return MOSQ_ERR_SUCCESS; 47 | #else 48 | return MOSQ_ERR_NOT_SUPPORTED; 49 | #endif 50 | } 51 | 52 | int mosquitto_loop_stop(struct mosquitto *mosq, bool force) 53 | { 54 | #ifdef WITH_THREADING 55 | if(!mosq) return MOSQ_ERR_INVAL; 56 | 57 | if(force){ 58 | pthread_cancel(mosq->thread_id); 59 | } 60 | pthread_join(mosq->thread_id, NULL); 61 | mosq->thread_id = pthread_self(); 62 | 63 | return MOSQ_ERR_SUCCESS; 64 | #else 65 | return MOSQ_ERR_NOT_SUPPORTED; 66 | #endif 67 | } 68 | 69 | #ifdef WITH_THREADING 70 | void *_mosquitto_thread_main(void *obj) 71 | { 72 | struct mosquitto *mosq = obj; 73 | 74 | if(!mosq) return NULL; 75 | 76 | mosq->threaded = true; 77 | pthread_mutex_lock(&mosq->state_mutex); 78 | if(mosq->state == mosq_cs_connect_async){ 79 | pthread_mutex_unlock(&mosq->state_mutex); 80 | mosquitto_reconnect(mosq); 81 | }else{ 82 | pthread_mutex_unlock(&mosq->state_mutex); 83 | } 84 | 85 | mosquitto_loop_forever(mosq, -1, 1); 86 | 87 | mosq->threaded = false; 88 | return obj; 89 | } 90 | #endif 91 | 92 | -------------------------------------------------------------------------------- /src/PandoSdk/MQTTKit/libmosquitto/time_mosq.c: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2013 Roger Light 3 | All rights reserved. 4 | 5 | Redistribution and use in source and binary forms, with or without 6 | modification, are permitted provided that the following conditions are met: 7 | 8 | 1. Redistributions of source code must retain the above copyright notice, 9 | this list of conditions and the following disclaimer. 10 | 2. Redistributions in binary form must reproduce the above copyright 11 | notice, this list of conditions and the following disclaimer in the 12 | documentation and/or other materials provided with the distribution. 13 | 3. Neither the name of mosquitto nor the names of its 14 | contributors may be used to endorse or promote products derived from 15 | this software without specific prior written permission. 16 | 17 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 18 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 19 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 20 | ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 21 | LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 22 | CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 23 | SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 24 | INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 25 | CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 26 | ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 27 | POSSIBILITY OF SUCH DAMAGE. 28 | */ 29 | 30 | #ifdef __APPLE__ 31 | #include 32 | #include 33 | #endif 34 | 35 | #ifdef WIN32 36 | # define _WIN32_WINNT _WIN32_WINNT_VISTA 37 | # include 38 | #else 39 | # include 40 | #endif 41 | #include 42 | 43 | #include "mosquitto.h" 44 | #include "time_mosq.h" 45 | 46 | #ifdef WIN32 47 | static bool tick64 = false; 48 | 49 | void _windows_time_version_check(void) 50 | { 51 | OSVERSIONINFO vi; 52 | 53 | tick64 = false; 54 | 55 | memset(&vi, 0, sizeof(OSVERSIONINFO)); 56 | vi.dwOSVersionInfoSize = sizeof(OSVERSIONINFO); 57 | if(GetVersionEx(&vi)){ 58 | if(vi.dwMajorVersion > 5){ 59 | tick64 = true; 60 | } 61 | } 62 | } 63 | #endif 64 | 65 | time_t mosquitto_time(void) 66 | { 67 | #ifdef WIN32 68 | if(tick64){ 69 | return GetTickCount64()/1000; 70 | }else{ 71 | return GetTickCount()/1000; /* FIXME - need to deal with overflow. */ 72 | } 73 | #elif _POSIX_TIMERS>0 && defined(_POSIX_MONOTONIC_CLOCK) 74 | struct timespec tp; 75 | 76 | clock_gettime(CLOCK_MONOTONIC, &tp); 77 | return tp.tv_sec; 78 | #elif defined(__APPLE__) 79 | static mach_timebase_info_data_t tb; 80 | uint64_t ticks; 81 | uint64_t sec; 82 | 83 | ticks = mach_absolute_time(); 84 | 85 | if(tb.denom == 0){ 86 | mach_timebase_info(&tb); 87 | } 88 | sec = (ticks/1000000000)*(tb.numer/tb.denom); 89 | 90 | return (time_t)sec; 91 | #else 92 | return time(NULL); 93 | #endif 94 | } 95 | 96 | -------------------------------------------------------------------------------- /src/PandoSdk/MQTTKit/libmosquitto/time_mosq.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2013 Roger Light 3 | All rights reserved. 4 | 5 | Redistribution and use in source and binary forms, with or without 6 | modification, are permitted provided that the following conditions are met: 7 | 8 | 1. Redistributions of source code must retain the above copyright notice, 9 | this list of conditions and the following disclaimer. 10 | 2. Redistributions in binary form must reproduce the above copyright 11 | notice, this list of conditions and the following disclaimer in the 12 | documentation and/or other materials provided with the distribution. 13 | 3. Neither the name of mosquitto nor the names of its 14 | contributors may be used to endorse or promote products derived from 15 | this software without specific prior written permission. 16 | 17 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 18 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 19 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 20 | ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 21 | LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 22 | CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 23 | SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 24 | INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 25 | CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 26 | ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 27 | POSSIBILITY OF SUCH DAMAGE. 28 | */ 29 | 30 | #ifndef _TIME_MOSQ_H_ 31 | #define _TIME_MOSQ_H_ 32 | 33 | time_t mosquitto_time(void); 34 | 35 | #endif 36 | -------------------------------------------------------------------------------- /src/PandoSdk/MQTTKit/libmosquitto/tls_mosq.c: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2013 Roger Light 3 | All rights reserved. 4 | 5 | Redistribution and use in source and binary forms, with or without 6 | modification, are permitted provided that the following conditions are met: 7 | 8 | 1. Redistributions of source code must retain the above copyright notice, 9 | this list of conditions and the following disclaimer. 10 | 2. Redistributions in binary form must reproduce the above copyright 11 | notice, this list of conditions and the following disclaimer in the 12 | documentation and/or other materials provided with the distribution. 13 | 3. Neither the name of mosquitto nor the names of its 14 | contributors may be used to endorse or promote products derived from 15 | this software without specific prior written permission. 16 | 17 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 18 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 19 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 20 | ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 21 | LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 22 | CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 23 | SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 24 | INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 25 | CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 26 | ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 27 | POSSIBILITY OF SUCH DAMAGE. 28 | */ 29 | 30 | #ifdef WITH_TLS 31 | 32 | #ifdef WIN32 33 | # include 34 | # include 35 | #else 36 | # include 37 | #endif 38 | 39 | #include 40 | #include 41 | #include 42 | #include 43 | 44 | #ifdef WITH_BROKER 45 | # include "mosquitto_broker.h" 46 | #endif 47 | #include "mosquitto_internal.h" 48 | #include "tls_mosq.h" 49 | 50 | extern int tls_ex_index_mosq; 51 | 52 | int _mosquitto_server_certificate_verify(int preverify_ok, X509_STORE_CTX *ctx) 53 | { 54 | /* Preverify should have already checked expiry, revocation. 55 | * We need to verify the hostname. */ 56 | struct mosquitto *mosq; 57 | SSL *ssl; 58 | X509 *cert; 59 | 60 | /* Always reject if preverify_ok has failed. */ 61 | if(!preverify_ok) return 0; 62 | 63 | ssl = X509_STORE_CTX_get_ex_data(ctx, SSL_get_ex_data_X509_STORE_CTX_idx()); 64 | mosq = SSL_get_ex_data(ssl, tls_ex_index_mosq); 65 | if(!mosq) return 0; 66 | 67 | if(mosq->tls_insecure == false){ 68 | if(X509_STORE_CTX_get_error_depth(ctx) == 0){ 69 | /* FIXME - use X509_check_host() etc. for sufficiently new openssl (>=1.1.x) */ 70 | cert = X509_STORE_CTX_get_current_cert(ctx); 71 | /* This is the peer certificate, all others are upwards in the chain. */ 72 | #if defined(WITH_BROKER) 73 | return _mosquitto_verify_certificate_hostname(cert, mosq->bridge->addresses[mosq->bridge->cur_address].address); 74 | #else 75 | return _mosquitto_verify_certificate_hostname(cert, mosq->host); 76 | #endif 77 | }else{ 78 | return preverify_ok; 79 | } 80 | }else{ 81 | return preverify_ok; 82 | } 83 | } 84 | 85 | /* This code is based heavily on the example provided in "Secure Programming 86 | * Cookbook for C and C++". 87 | */ 88 | int _mosquitto_verify_certificate_hostname(X509 *cert, const char *hostname) 89 | { 90 | int i; 91 | char name[256]; 92 | X509_NAME *subj; 93 | bool have_san_dns = false; 94 | STACK_OF(GENERAL_NAME) *san; 95 | const GENERAL_NAME *nval; 96 | const unsigned char *data; 97 | unsigned char ipv6_addr[16]; 98 | unsigned char ipv4_addr[4]; 99 | int ipv6_ok; 100 | int ipv4_ok; 101 | 102 | #ifdef WIN32 103 | ipv6_ok = InetPton(AF_INET6, hostname, &ipv6_addr); 104 | ipv4_ok = InetPton(AF_INET, hostname, &ipv4_addr); 105 | #else 106 | ipv6_ok = inet_pton(AF_INET6, hostname, &ipv6_addr); 107 | ipv4_ok = inet_pton(AF_INET, hostname, &ipv4_addr); 108 | #endif 109 | 110 | san = X509_get_ext_d2i(cert, NID_subject_alt_name, NULL, NULL); 111 | if(san){ 112 | for(i=0; itype == GEN_DNS){ 115 | data = ASN1_STRING_data(nval->d.dNSName); 116 | if(data && !strcasecmp((char *)data, hostname)){ 117 | return 1; 118 | } 119 | have_san_dns = true; 120 | }else if(nval->type == GEN_IPADD){ 121 | data = ASN1_STRING_data(nval->d.iPAddress); 122 | if(nval->d.iPAddress->length == 4 && ipv4_ok){ 123 | if(!memcmp(ipv4_addr, data, 4)){ 124 | return 1; 125 | } 126 | }else if(nval->d.iPAddress->length == 16 && ipv6_ok){ 127 | if(!memcmp(ipv6_addr, data, 16)){ 128 | return 1; 129 | } 130 | } 131 | } 132 | } 133 | if(have_san_dns){ 134 | /* Only check CN if subjectAltName DNS entry does not exist. */ 135 | return 0; 136 | } 137 | } 138 | subj = X509_get_subject_name(cert); 139 | if(X509_NAME_get_text_by_NID(subj, NID_commonName, name, sizeof(name)) > 0){ 140 | name[sizeof(name) - 1] = '\0'; 141 | if (!strcasecmp(name, hostname)) return 1; 142 | } 143 | return 0; 144 | } 145 | 146 | #endif 147 | 148 | -------------------------------------------------------------------------------- /src/PandoSdk/MQTTKit/libmosquitto/tls_mosq.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2013 Roger Light 3 | All rights reserved. 4 | 5 | Redistribution and use in source and binary forms, with or without 6 | modification, are permitted provided that the following conditions are met: 7 | 8 | 1. Redistributions of source code must retain the above copyright notice, 9 | this list of conditions and the following disclaimer. 10 | 2. Redistributions in binary form must reproduce the above copyright 11 | notice, this list of conditions and the following disclaimer in the 12 | documentation and/or other materials provided with the distribution. 13 | 3. Neither the name of mosquitto nor the names of its 14 | contributors may be used to endorse or promote products derived from 15 | this software without specific prior written permission. 16 | 17 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 18 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 19 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 20 | ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 21 | LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 22 | CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 23 | SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 24 | INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 25 | CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 26 | ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 27 | POSSIBILITY OF SUCH DAMAGE. 28 | */ 29 | 30 | #ifndef _TLS_MOSQ_H_ 31 | #define _TLS_MOSQ_H_ 32 | 33 | #ifdef WITH_TLS 34 | 35 | #include 36 | #ifdef WITH_TLS_PSK 37 | # if OPENSSL_VERSION_NUMBER >= 0x10000000 38 | # define REAL_WITH_TLS_PSK 39 | # else 40 | # warning "TLS-PSK not supported, openssl too old." 41 | # endif 42 | #endif 43 | 44 | int _mosquitto_server_certificate_verify(int preverify_ok, X509_STORE_CTX *ctx); 45 | int _mosquitto_verify_certificate_hostname(X509 *cert, const char *hostname); 46 | 47 | #endif /* WITH_TLS */ 48 | 49 | #endif 50 | -------------------------------------------------------------------------------- /src/PandoSdk/MQTTKit/libmosquitto/util_mosq.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2009-2013 Roger Light 3 | All rights reserved. 4 | 5 | Redistribution and use in source and binary forms, with or without 6 | modification, are permitted provided that the following conditions are met: 7 | 8 | 1. Redistributions of source code must retain the above copyright notice, 9 | this list of conditions and the following disclaimer. 10 | 2. Redistributions in binary form must reproduce the above copyright 11 | notice, this list of conditions and the following disclaimer in the 12 | documentation and/or other materials provided with the distribution. 13 | 3. Neither the name of mosquitto nor the names of its 14 | contributors may be used to endorse or promote products derived from 15 | this software without specific prior written permission. 16 | 17 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 18 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 19 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 20 | ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 21 | LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 22 | CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 23 | SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 24 | INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 25 | CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 26 | ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 27 | POSSIBILITY OF SUCH DAMAGE. 28 | */ 29 | #ifndef _UTIL_MOSQ_H_ 30 | #define _UTIL_MOSQ_H_ 31 | 32 | #include 33 | 34 | #include "tls_mosq.h" 35 | #include "mosquitto.h" 36 | 37 | int _mosquitto_packet_alloc(struct _mosquitto_packet *packet); 38 | void _mosquitto_check_keepalive(struct mosquitto *mosq); 39 | int _mosquitto_fix_sub_topic(char **subtopic); 40 | uint16_t _mosquitto_mid_generate(struct mosquitto *mosq); 41 | int _mosquitto_topic_wildcard_len_check(const char *str); 42 | FILE *_mosquitto_fopen(const char *path, const char *mode); 43 | 44 | #ifdef REAL_WITH_TLS_PSK 45 | int _mosquitto_hex2bin(const char *hex, unsigned char *bin, int bin_max_len); 46 | #endif 47 | 48 | #endif 49 | -------------------------------------------------------------------------------- /src/PandoSdk/MQTTKit/libmosquitto/will_mosq.c: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2010-2013 Roger Light 3 | All rights reserved. 4 | 5 | Redistribution and use in source and binary forms, with or without 6 | modification, are permitted provided that the following conditions are met: 7 | 8 | 1. Redistributions of source code must retain the above copyright notice, 9 | this list of conditions and the following disclaimer. 10 | 2. Redistributions in binary form must reproduce the above copyright 11 | notice, this list of conditions and the following disclaimer in the 12 | documentation and/or other materials provided with the distribution. 13 | 3. Neither the name of mosquitto nor the names of its 14 | contributors may be used to endorse or promote products derived from 15 | this software without specific prior written permission. 16 | 17 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 18 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 19 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 20 | ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 21 | LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 22 | CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 23 | SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 24 | INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 25 | CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 26 | ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 27 | POSSIBILITY OF SUCH DAMAGE. 28 | */ 29 | 30 | #include 31 | #include 32 | #include 33 | #include 34 | #ifndef WIN32 35 | #include 36 | #include 37 | #else 38 | #include 39 | typedef int ssize_t; 40 | #endif 41 | 42 | #include "mosquitto.h" 43 | #include "mosquitto_internal.h" 44 | #include "logging_mosq.h" 45 | #include "messages_mosq.h" 46 | #include "memory_mosq.h" 47 | #include "mqtt3_protocol.h" 48 | #include "net_mosq.h" 49 | #include "read_handle.h" 50 | #include "send_mosq.h" 51 | #include "util_mosq.h" 52 | 53 | int _mosquitto_will_set(struct mosquitto *mosq, const char *topic, int payloadlen, const void *payload, int qos, bool retain) 54 | { 55 | int rc = MOSQ_ERR_SUCCESS; 56 | 57 | if(!mosq || !topic) return MOSQ_ERR_INVAL; 58 | if(payloadlen < 0 || payloadlen > MQTT_MAX_PAYLOAD) return MOSQ_ERR_PAYLOAD_SIZE; 59 | if(payloadlen > 0 && !payload) return MOSQ_ERR_INVAL; 60 | 61 | if(mosq->will){ 62 | if(mosq->will->topic){ 63 | _mosquitto_free(mosq->will->topic); 64 | mosq->will->topic = NULL; 65 | } 66 | if(mosq->will->payload){ 67 | _mosquitto_free(mosq->will->payload); 68 | mosq->will->payload = NULL; 69 | } 70 | _mosquitto_free(mosq->will); 71 | mosq->will = NULL; 72 | } 73 | 74 | mosq->will = _mosquitto_calloc(1, sizeof(struct mosquitto_message)); 75 | if(!mosq->will) return MOSQ_ERR_NOMEM; 76 | mosq->will->topic = _mosquitto_strdup(topic); 77 | if(!mosq->will->topic){ 78 | rc = MOSQ_ERR_NOMEM; 79 | goto cleanup; 80 | } 81 | mosq->will->payloadlen = payloadlen; 82 | if(mosq->will->payloadlen > 0){ 83 | if(!payload){ 84 | rc = MOSQ_ERR_INVAL; 85 | goto cleanup; 86 | } 87 | mosq->will->payload = _mosquitto_malloc(sizeof(char)*mosq->will->payloadlen); 88 | if(!mosq->will->payload){ 89 | rc = MOSQ_ERR_NOMEM; 90 | goto cleanup; 91 | } 92 | 93 | memcpy(mosq->will->payload, payload, payloadlen); 94 | } 95 | mosq->will->qos = qos; 96 | mosq->will->retain = retain; 97 | 98 | return MOSQ_ERR_SUCCESS; 99 | 100 | cleanup: 101 | if(mosq->will){ 102 | if(mosq->will->topic) _mosquitto_free(mosq->will->topic); 103 | if(mosq->will->payload) _mosquitto_free(mosq->will->payload); 104 | } 105 | _mosquitto_free(mosq->will); 106 | mosq->will = NULL; 107 | 108 | return rc; 109 | } 110 | 111 | int _mosquitto_will_clear(struct mosquitto *mosq) 112 | { 113 | if(!mosq->will) return MOSQ_ERR_SUCCESS; 114 | 115 | if(mosq->will->topic){ 116 | _mosquitto_free(mosq->will->topic); 117 | mosq->will->topic = NULL; 118 | } 119 | if(mosq->will->payload){ 120 | _mosquitto_free(mosq->will->payload); 121 | mosq->will->payload = NULL; 122 | } 123 | _mosquitto_free(mosq->will); 124 | mosq->will = NULL; 125 | 126 | return MOSQ_ERR_SUCCESS; 127 | } 128 | 129 | -------------------------------------------------------------------------------- /src/PandoSdk/MQTTKit/libmosquitto/will_mosq.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2010-2013 Roger Light 3 | All rights reserved. 4 | 5 | Redistribution and use in source and binary forms, with or without 6 | modification, are permitted provided that the following conditions are met: 7 | 8 | 1. Redistributions of source code must retain the above copyright notice, 9 | this list of conditions and the following disclaimer. 10 | 2. Redistributions in binary form must reproduce the above copyright 11 | notice, this list of conditions and the following disclaimer in the 12 | documentation and/or other materials provided with the distribution. 13 | 3. Neither the name of mosquitto nor the names of its 14 | contributors may be used to endorse or promote products derived from 15 | this software without specific prior written permission. 16 | 17 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 18 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 19 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 20 | ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 21 | LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 22 | CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 23 | SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 24 | INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 25 | CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 26 | ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 27 | POSSIBILITY OF SUCH DAMAGE. 28 | */ 29 | 30 | #ifndef _WILL_MOSQ_H_ 31 | #define _WILL_MOSQ_H_ 32 | 33 | #include "mosquitto.h" 34 | #include "mosquitto_internal.h" 35 | 36 | int _mosquitto_will_set(struct mosquitto *mosq, const char *topic, int payloadlen, const void *payload, int qos, bool retain); 37 | int _mosquitto_will_clear(struct mosquitto *mosq); 38 | 39 | #endif 40 | -------------------------------------------------------------------------------- /src/PandoSdk/PandoPayload/pando_endian.c: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2015 Pando. All rights reserved. 2 | // PtotoBuf: ProtocolBuffer.h 3 | // 4 | // Create By ZhaoWenwu On 15/01/24. 5 | 6 | #include "pando_endian.h" 7 | 8 | int little_endian = -1; 9 | 10 | int FUNCTION_ATTRIBUTE is_little_endian() 11 | { 12 | if(little_endian == -1) 13 | { 14 | union int_char 15 | { 16 | int i; 17 | char c; 18 | }x; 19 | x.i = 1; 20 | little_endian = x.c; 21 | } 22 | 23 | return little_endian; 24 | } 25 | 26 | uint16_t FUNCTION_ATTRIBUTE net16_to_host(uint16_t A) 27 | { 28 | if(is_little_endian()) 29 | { 30 | return ((((A) & 0xff00) >> 8) | (((A) & 0x00ff) << 8)); 31 | } 32 | else 33 | { 34 | return A; 35 | } 36 | } 37 | 38 | uint32_t FUNCTION_ATTRIBUTE net32_to_host(uint32_t A) 39 | { 40 | if(is_little_endian()) 41 | { 42 | return ((((A) & 0xff000000) >> 24) | \ 43 | (((A) & 0x00ff0000) >> 8 ) | \ 44 | (((A) & 0x0000ff00) << 8 ) | \ 45 | (((A) & 0x000000ff) << 24)); 46 | } 47 | else 48 | { 49 | return A; 50 | } 51 | } 52 | 53 | uint64_t FUNCTION_ATTRIBUTE net64_to_host(uint64_t A) 54 | { 55 | uint64_t mask = 0xff; 56 | if(is_little_endian()) 57 | { 58 | return ((((A) & (mask << 56)) >> 56) | \ 59 | (((A) & (mask << 48)) >> 40) | \ 60 | (((A) & (mask << 40)) >> 24) | \ 61 | (((A) & (mask << 32)) >> 8) | \ 62 | (((A) & (mask << 24)) << 8) | \ 63 | (((A) & (mask << 16)) << 24) | \ 64 | (((A) & (mask << 8)) << 40) | \ 65 | (((A) & (mask)) << 56)); 66 | } 67 | else 68 | { 69 | return A; 70 | } 71 | } 72 | 73 | 74 | float FUNCTION_ATTRIBUTE net32f_to_host(float A) 75 | { 76 | if(is_little_endian()) 77 | { 78 | union float_int 79 | { 80 | float f; 81 | uint32_t i; 82 | }x; 83 | x.f = A; 84 | x.i = net32_to_host(x.i); 85 | return x.f; 86 | } 87 | else 88 | { 89 | return A; 90 | } 91 | } 92 | 93 | double FUNCTION_ATTRIBUTE net64f_to_host(double A) 94 | { 95 | if(is_little_endian()) 96 | { 97 | union double_uint64 98 | { 99 | double d; 100 | uint64_t i; 101 | }x; 102 | x.d = A; 103 | x.i = net64_to_host(x.i); 104 | return x.d; 105 | } 106 | else 107 | { 108 | return A; 109 | } 110 | } 111 | 112 | 113 | -------------------------------------------------------------------------------- /src/PandoSdk/PandoPayload/pando_endian.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2015 Pando. All rights reserved. 2 | // PtotoBuf: ProtocolBuffer.h 3 | // 4 | // Create By ZhaoWenwu On 15/01/24. 5 | 6 | #ifndef PANDO_ENDIAN_H 7 | #define PANDO_ENDIAN_H 8 | 9 | #ifdef __cplusplus 10 | extern "C" 11 | { 12 | #endif 13 | 14 | #include "platform_functions.h" 15 | 16 | //大小端转换函数 17 | uint16_t net16_to_host(uint16_t A); 18 | uint32_t net32_to_host(uint32_t A); 19 | uint64_t net64_to_host(uint64_t A); 20 | float net32f_to_host(float A); 21 | double net64f_to_host(double A); 22 | 23 | #define host16_to_net net16_to_host 24 | #define host32_to_net net32_to_host 25 | #define host64_to_net net64_to_host 26 | #define host32f_to_net net32f_to_host 27 | #define host64f_to_net net64f_to_host 28 | 29 | #ifdef __cplusplus 30 | } 31 | #endif 32 | #endif 33 | 34 | 35 | 36 | -------------------------------------------------------------------------------- /src/PandoSdk/PandoPayload/pando_protocol_tool.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2014 Pando. All rights reserved. 2 | // PtotoBuf: ProtocolBuffer.h 3 | // 4 | // Brief: 5 | // 6 | // Create By TangWenhan On 14/12/24. 7 | 8 | #ifndef PANDP_PROTOCOL_TOOL_H 9 | #define PANDP_PROTOCOL_TOOL_H 10 | 11 | #ifdef __cplusplus 12 | extern "C" 13 | { 14 | #endif 15 | 16 | #include "platform_functions.h" 17 | #include "sub_device_protocol_tool.h" 18 | #include "pando_endian.h" 19 | 20 | #define MAX_PANDO_TOKEN_SIZE 16 21 | 22 | #define MAGIC_HEAD_PANDO 0x7064 23 | #define BIN_PANDO_TAG 0x0001 24 | #define EMPTY_HEART_BEAT 0xffff 25 | #define FLAG_TCP_XXX //是否现在就要定义具体的flag 26 | 27 | #define GATE_HEADER_LEN (sizeof(struct mqtt_bin_header)) 28 | 29 | #pragma pack(1) 30 | 31 | struct mqtt_bin_header 32 | { 33 | uint8_t flags; 34 | uint64_t timestamp; 35 | uint8_t token[MAX_PANDO_TOKEN_SIZE]; 36 | }; 37 | 38 | 39 | /*载荷数据的开头,必须有子设备ID,以供Gateway转发和聚合*/ 40 | struct pando_payload 41 | { 42 | uint16_t sub_device_id; 43 | }; 44 | 45 | 46 | /* 缓存结构,用于在网关程序内部流转 47 | * buffer总是从pando_header开始的。 48 | * buffer + offset到buffer + buff_len之间的数据,就是decode或者encode要处理的 49 | */ 50 | struct pando_buffer 51 | { 52 | uint16_t buff_len; /* 缓冲区长度 */ 53 | uint16_t offset; /* 有效数据的偏移量 */ 54 | uint8_t *buffer; /* 缓冲区 */ 55 | }; 56 | 57 | /*protocol模块基本数据的结构*/ 58 | struct protocol_base 59 | { 60 | uint64_t device_id; /* 设备ID */ 61 | uint64_t event_sequence; /* 网关的事件序列 */ 62 | uint64_t data_sequence; /* 网关的数据序列 */ 63 | uint64_t command_sequence; /* 网关收到的命令序列 */ 64 | uint32_t sub_device_cmd_seq; /* 保存与子设备交互命令时的序列 */ 65 | uint8_t token[MAX_PANDO_TOKEN_SIZE]; /* token */ 66 | }; 67 | #pragma pack() 68 | 69 | 70 | /*面向网关的接口*/ 71 | 72 | /* 初始化协议基本参数 73 | * 成功返回0,错误返回 -1 */ 74 | int pando_protocol_init(struct protocol_base init_params); 75 | 76 | /* 动态新建一个空的缓冲区。length为缓冲区长度,offset进行简单地赋值。 77 | * 成功则返回缓冲区,错误则返回NULL。*/ 78 | struct pando_buffer* pando_buffer_create(int length, int offset); 79 | 80 | /* 释放缓冲区动态创建的buffer,释放缓冲区本身 */ 81 | void pando_buffer_delete(struct pando_buffer *pdbuf); 82 | 83 | /* 将网关与子设备交互的包,转换成网关与接入服务器交互的包 84 | * 成功返回0,错误返回 -1 */ 85 | int pando_protocol_encode(struct pando_buffer *pdbuf, uint16_t *payload_type); 86 | 87 | /* 将网关与接入服务器交互的包,转换成网关与子设备交互的包 88 | * 通过command传出command id, command目标子设备id, command priority 89 | * 成功返回0,错误返回 -1 */ 90 | int pando_protocol_decode(struct pando_buffer *pdbuf, uint16_t payload_type); 91 | 92 | /* 网关获取command的序列号,用于反馈机制 93 | * 得到的是最近一次decode的command的序列 94 | */ 95 | uint64_t pando_protocol_get_cmd_sequence(); 96 | 97 | /* 获取或设置子设备ID,必须传入payload的起始位置 98 | */ 99 | int pando_protocol_get_sub_device_id(struct pando_buffer *buf, uint16_t *sub_device_id); 100 | 101 | int pando_protocol_set_sub_device_id(struct pando_buffer *buf, uint16_t sub_device_id); 102 | 103 | 104 | //网关发送文件的命令后,保存需要反馈的文件命令的序列号 105 | int is_file_feedback(uint32_t sequence); 106 | void save_file_sequence(); 107 | 108 | /* get command type after gateway completes decoding the command from server. */ 109 | uint16_t pando_protocol_get_payload_type(struct pando_buffer *pdbuf); 110 | 111 | /* */ 112 | int is_pando_file_command(struct pando_buffer *pdbuf); 113 | 114 | char *pando_protocol_get_uri(struct pando_buffer *pdbuf); 115 | 116 | #ifdef __cplusplus 117 | } 118 | #endif 119 | #endif //PANDP_PROTOCOL_TOOL_H 120 | 121 | 122 | 123 | -------------------------------------------------------------------------------- /src/PandoSdk/PandoPayload/pd_machine.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | #include "pd_machine.h" 6 | 7 | uint64_t FUNCTION_ATTRIBUTE pd_get_timestamp() 8 | { 9 | struct timeval now; 10 | gettimeofday(&now, NULL); 11 | return (now.tv_sec * 1000 + now.tv_usec/1000); 12 | } 13 | -------------------------------------------------------------------------------- /src/PandoSdk/PandoPayload/pd_machine.h: -------------------------------------------------------------------------------- 1 | #ifndef PD_MACHINE_H 2 | #define PD_MACHINE_H 3 | 4 | // for #pragma pack(ALIGNED_LENGTH), for example, esp8266 should be 1 5 | #define ALIGNED_LENGTH 6 | 7 | // some platform need this prefix between function name and return type 8 | #define FUNCTION_ATTRIBUTE 9 | 10 | // different platform has its own define of these functions. 11 | #define pd_malloc malloc 12 | #define pd_free free 13 | #define pd_memcpy memcpy 14 | #define pd_printf printf 15 | #define pd_memcmp memcmp 16 | #define pd_memset memset 17 | uint64_t pd_get_timestamp(); 18 | 19 | #endif 20 | 21 | -------------------------------------------------------------------------------- /src/PandoSdk/PandoPayload/platform.c: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (c) 2014 IBM Corp. 3 | * 4 | * All rights reserved. This program and the accompanying materials 5 | * are made available under the terms of the Eclipse Public License v1.0 6 | * and Eclipse Distribution License v1.0 which accompany this distribution. 7 | * 8 | * The Eclipse Public License is available at 9 | * http://www.eclipse.org/legal/epl-v10.html 10 | * and the Eclipse Distribution License is available at 11 | * http://www.eclipse.org/org/documents/edl-v10.php. 12 | * 13 | * Contributors: 14 | * Allan Stockdill-Mander - initial API and implementation and/or initial documentation 15 | *******************************************************************************/ 16 | 17 | #include "platform.h" 18 | 19 | char expired(Timer* timer) 20 | { 21 | struct timeval now, res; 22 | gettimeofday(&now, NULL); 23 | timersub(&timer->end_time, &now, &res); 24 | return res.tv_sec < 0 || (res.tv_sec == 0 && res.tv_usec <= 0); 25 | } 26 | 27 | 28 | void countdown_ms(Timer* timer, unsigned int timeout) 29 | { 30 | struct timeval now; 31 | gettimeofday(&now, NULL); 32 | struct timeval interval = {timeout / 1000, (timeout % 1000) * 1000}; 33 | timeradd(&now, &interval, &timer->end_time); 34 | } 35 | 36 | 37 | void countdown(Timer* timer, unsigned int timeout) 38 | { 39 | struct timeval now; 40 | gettimeofday(&now, NULL); 41 | struct timeval interval = {timeout, 0}; 42 | timeradd(&now, &interval, &timer->end_time); 43 | } 44 | 45 | 46 | int left_ms(Timer* timer) 47 | { 48 | struct timeval now, res; 49 | gettimeofday(&now, NULL); 50 | timersub(&timer->end_time, &now, &res); 51 | //printf("left %d ms\n", (res.tv_sec < 0) ? 0 : res.tv_sec * 1000 + res.tv_usec / 1000); 52 | return (res.tv_sec < 0) ? 0 : res.tv_sec * 1000 + res.tv_usec / 1000; 53 | } 54 | 55 | 56 | void InitTimer(Timer* timer) 57 | { 58 | timer->end_time = (struct timeval){0, 0}; 59 | } 60 | 61 | 62 | int linux_read(Network* n, unsigned char* buffer, int len, int timeout_ms) 63 | { 64 | struct timeval interval = {timeout_ms / 1000, (timeout_ms % 1000) * 1000}; 65 | if (interval.tv_sec < 0 || (interval.tv_sec == 0 && interval.tv_usec <= 0)) 66 | { 67 | interval.tv_sec = 0; 68 | interval.tv_usec = 100; 69 | } 70 | 71 | setsockopt(n->my_socket, SOL_SOCKET, SO_RCVTIMEO, (char *)&interval, sizeof(struct timeval)); 72 | 73 | int bytes = 0; 74 | while (bytes < len) 75 | { 76 | int rc = recv(n->my_socket, &buffer[bytes], (size_t)(len - bytes), 0); 77 | if (rc == -1) 78 | { 79 | if (errno != ENOTCONN && errno != ECONNRESET) 80 | { 81 | bytes = -1; 82 | break; 83 | } 84 | } 85 | else 86 | bytes += rc; 87 | } 88 | return bytes; 89 | } 90 | 91 | 92 | int linux_write(Network* n, unsigned char* buffer, int len, int timeout_ms) 93 | { 94 | struct timeval tv; 95 | 96 | tv.tv_sec = 0; /* 30 Secs Timeout */ 97 | tv.tv_usec = timeout_ms * 1000; // Not init'ing this can cause strange errors 98 | 99 | setsockopt(n->my_socket, SOL_SOCKET, SO_RCVTIMEO, (char *)&tv,sizeof(struct timeval)); 100 | int rc = write(n->my_socket, buffer, len); 101 | return rc; 102 | } 103 | 104 | 105 | void linux_disconnect(Network* n) 106 | { 107 | close(n->my_socket); 108 | } 109 | 110 | 111 | void NewNetwork(Network* n) 112 | { 113 | n->my_socket = 0; 114 | n->mqttread = linux_read; 115 | n->mqttwrite = linux_write; 116 | n->disconnect = linux_disconnect; 117 | } 118 | 119 | 120 | int ConnectNetwork(Network* n, char* addr, int port) 121 | { 122 | int type = SOCK_STREAM; 123 | struct sockaddr_in address; 124 | int rc = -1; 125 | sa_family_t family = AF_INET; 126 | struct addrinfo *result = NULL; 127 | struct addrinfo hints = {0, AF_UNSPEC, SOCK_STREAM, IPPROTO_TCP, 0, NULL, NULL, NULL}; 128 | 129 | printf("addr is :%s\n", addr); 130 | if ((rc = getaddrinfo(addr, NULL, &hints, &result)) == 0) 131 | { 132 | struct addrinfo* res = result; 133 | 134 | /* prefer ip4 addresses */ 135 | while (res) 136 | { 137 | if (res->ai_family == AF_INET) 138 | { 139 | result = res; 140 | break; 141 | } 142 | res = res->ai_next; 143 | } 144 | 145 | if (result->ai_family == AF_INET) 146 | { 147 | address.sin_port = htons(port); 148 | address.sin_family = family = AF_INET; 149 | address.sin_addr = ((struct sockaddr_in*)(result->ai_addr))->sin_addr; 150 | } 151 | else 152 | rc = -1; 153 | 154 | freeaddrinfo(result); 155 | } 156 | 157 | if (rc == 0) 158 | { 159 | n->my_socket = socket(family, type, 0); 160 | if (n->my_socket != -1) 161 | { 162 | int opt = 1; 163 | rc = connect(n->my_socket, (struct sockaddr*)&address, sizeof(address)); 164 | } 165 | } 166 | 167 | return rc; 168 | } -------------------------------------------------------------------------------- /src/PandoSdk/PandoPayload/platform.h: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (c) 2014 IBM Corp. 3 | * 4 | * All rights reserved. This program and the accompanying materials 5 | * are made available under the terms of the Eclipse Public License v1.0 6 | * and Eclipse Distribution License v1.0 which accompany this distribution. 7 | * 8 | * The Eclipse Public License is available at 9 | * http://www.eclipse.org/legal/epl-v10.html 10 | * and the Eclipse Distribution License is available at 11 | * http://www.eclipse.org/org/documents/edl-v10.php. 12 | * 13 | * Contributors: 14 | * Allan Stockdill-Mander - initial API and implementation and/or initial documentation 15 | *******************************************************************************/ 16 | 17 | #ifndef __MQTT_LINUX_ 18 | #define __MQTT_LINUX_ 19 | 20 | #include 21 | #include 22 | #include 23 | #include 24 | #include 25 | #include 26 | #include 27 | #include 28 | #include 29 | #include 30 | #include 31 | #include 32 | #include 33 | 34 | #include 35 | #include 36 | #include 37 | 38 | typedef struct Timer Timer; 39 | 40 | struct Timer { 41 | struct timeval end_time; 42 | }; 43 | 44 | typedef struct Network Network; 45 | 46 | struct Network 47 | { 48 | int my_socket; 49 | int (*mqttread) (Network*, unsigned char*, int, int); 50 | int (*mqttwrite) (Network*, unsigned char*, int, int); 51 | void (*disconnect) (Network*); 52 | }; 53 | 54 | char expired(Timer*); 55 | void countdown_ms(Timer*, unsigned int); 56 | void countdown(Timer*, unsigned int); 57 | int left_ms(Timer*); 58 | 59 | void InitTimer(Timer*); 60 | 61 | int linux_read(Network*, unsigned char*, int, int); 62 | int linux_write(Network*, unsigned char*, int, int); 63 | void linux_disconnect(Network*); 64 | void NewNetwork(Network*); 65 | 66 | int ConnectNetwork(Network*, char*, int); 67 | 68 | #endif -------------------------------------------------------------------------------- /src/PandoSdk/PandoPayload/platform_functions.c: -------------------------------------------------------------------------------- 1 | #include "platform_functions.h" 2 | 3 | void FUNCTION_ATTRIBUTE show_package(uint8_t *buffer, uint16_t length) 4 | { 5 | int i = 0; 6 | pd_printf("Package length: %d\ncontent is: \n", length); 7 | 8 | for (i = 0; i < length; i++) 9 | { 10 | pd_printf("%02x ",(uint8_t)buffer[i]); 11 | } 12 | 13 | pd_printf("\n"); 14 | } 15 | 16 | -------------------------------------------------------------------------------- /src/PandoSdk/PandoPayload/platform_functions.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2014 Pando. All rights reserved. 2 | // Platform: platform_functions.h 3 | // 4 | // Create By ZhaoWenwu On 15/05/17. 5 | 6 | 7 | #ifndef PLATFORM_FUNCTIONS_H 8 | #define PLATFORM_FUNCTIONS_H 9 | 10 | #ifdef __cplusplus 11 | extern "C" 12 | { 13 | #endif 14 | 15 | #include 16 | #include 17 | #include 18 | #include 19 | 20 | #include "pd_machine.h" 21 | 22 | void show_package(uint8_t *buffer, uint16_t length); 23 | 24 | #ifdef __cplusplus 25 | } 26 | #endif 27 | #endif -------------------------------------------------------------------------------- /src/PandoSdk/PandoPayload/sub_device_protocol_tool.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2015 Pando. All rights reserved. 2 | // PtotoBuf: ProtocolBuffer.h 3 | // 4 | // Create By ZhaoWenwu On 15/01/24. 5 | 6 | #ifndef SUB_DEVICE_PROTOCOL_TOOL_H 7 | #define SUB_DEVICE_PROTOCOL_TOOL_H 8 | 9 | #ifdef __cplusplus 10 | extern "C" 11 | { 12 | #endif 13 | 14 | #include "platform_functions.h" 15 | #include "pando_endian.h" 16 | 17 | #define MAGIC_HEAD_SUB_DEVICE 0x34 18 | #define PAYLOAD_TYPE_COMMAND 1 19 | #define PAYLOAD_TYPE_EVENT 2 20 | #define PAYLOAD_TYPE_DATA 3 21 | #define PAYLOAD_TYPE_COMMAND_WITH_FILE 4 22 | 23 | #define TLV_TYPE_FLOAT64 1 24 | #define TLV_TYPE_FLOAT32 2 25 | #define TLV_TYPE_INT8 3 26 | #define TLV_TYPE_INT16 4 27 | #define TLV_TYPE_INT32 5 28 | #define TLV_TYPE_INT64 6 29 | #define TLV_TYPE_UINT8 7 30 | #define TLV_TYPE_UINT16 8 31 | #define TLV_TYPE_UINT32 9 32 | #define TLV_TYPE_UINT64 10 33 | #define TLV_TYPE_BYTES 11 34 | #define TLV_TYPE_URI 12 35 | #define TLV_TYPE_BOOL 13 36 | 37 | #define DEV_HEADER_LEN (sizeof(struct device_header)) 38 | 39 | #pragma pack(1) 40 | 41 | struct device_header 42 | { 43 | uint8_t magic; /* 开始标志 (0x34) */ 44 | uint8_t crc; /* 校验和 */ 45 | uint16_t payload_type; /* 载荷类型 */ 46 | uint16_t payload_len; /* 载荷长度 */ 47 | uint16_t flags; /* 标志位 */ 48 | uint32_t frame_seq; /* 帧序列 */ 49 | }; 50 | 51 | /*TLV信息区,包含count*/ 52 | struct TLV 53 | { 54 | uint16_t type; 55 | uint16_t length; 56 | uint8_t value[]; 57 | }; 58 | 59 | struct TLVs 60 | { 61 | uint16_t count; 62 | //struct TLV tlv[]; 63 | }; 64 | 65 | /*命令,事件和数据具体的数据结构*/ 66 | struct pando_command 67 | { 68 | uint16_t sub_device_id; /* 子设备ID */ 69 | uint16_t command_id; /* 命令ID */ 70 | uint16_t priority; /* 优先级 */ 71 | struct TLVs params[1]; /* 参数 */ 72 | }; 73 | 74 | struct pando_event 75 | { 76 | uint16_t sub_device_id; /* 子设备ID */ 77 | uint16_t event_num; /* 事件ID */ 78 | uint16_t priority; 79 | struct TLVs params[1]; /* 参数 */ 80 | }; 81 | 82 | /*属性的定义*/ 83 | struct pando_property 84 | { 85 | uint16_t sub_device_id; /* 子设备ID */ 86 | uint16_t property_num; /* 属性编号 */ 87 | struct TLVs params[1]; /* 参数 */ 88 | }; 89 | 90 | struct sub_device_buffer 91 | { 92 | uint16_t buffer_length; 93 | uint8_t *buffer; 94 | }; 95 | 96 | struct sub_device_base_params 97 | { 98 | uint32_t event_sequence; 99 | uint32_t data_sequence; 100 | uint32_t command_sequence; 101 | }; 102 | #pragma pack() 103 | 104 | 105 | //初始化子设备模块 106 | int init_sub_device(struct sub_device_base_params base_params); 107 | 108 | //在创建数据包或者事件包前,先创建好参数的信息区, 同时添加第一个参数,待信息区被create_event等函数成功使用后,要将信息区delete 109 | struct TLVs *create_params_block(uint16_t first_type, uint16_t first_length, void *first_value); 110 | 111 | //多次调用直至添加完所有参数 112 | int add_next_param(struct TLVs *params_block, uint16_t next_type, uint16_t next_length, void *next_value); 113 | 114 | //创建事件包,返回缓冲区, 115 | //数据发送完成后,要将返回的缓冲区delete掉 116 | struct sub_device_buffer *create_event_package(uint16_t event_num, uint16_t flags, uint16_t priority, struct TLVs *event_params); 117 | struct sub_device_buffer *create_command_package(uint16_t cmd_num, uint16_t flags, uint16_t priority, struct TLVs *cmd_params); 118 | 119 | struct sub_device_buffer *create_data_package(uint16_t property_num, uint16_t flag, struct TLVs *data_params); 120 | int add_next_property(struct sub_device_buffer *data_package, uint16_t property_num, struct TLVs *next_data_params); 121 | 122 | struct sub_device_buffer *create_feedback_package(); 123 | 124 | //解析命令包,command_body传出command_id、参数个数等信息,返回第一个参数的指针,用于get_tlv_param获取参数 125 | struct TLV *get_sub_device_command(struct sub_device_buffer *device_buffer, struct pando_command *command_body); 126 | 127 | //get data's property id and property num with property_body, return tlv param block 128 | struct TLV *get_sub_device_property(struct sub_device_buffer *device_buffer, struct pando_property *property_body); 129 | 130 | //尚未实现,后续迭代时封装完善 131 | 132 | uint16_t get_tlv_count(struct TLVs *params_block); 133 | 134 | /* if value type is uri or bytes, value point to the start address of data. 135 | else, value will match the type, make sure (void *) has enough space to 136 | memcpy 137 | */ 138 | struct TLV *get_tlv_param(struct TLV *params_in, uint16_t *type, uint16_t *length, void *value); 139 | 140 | //删除子设备缓冲区,如果为参数创建过信息区,还需要删除信息区 141 | void delete_device_package(struct sub_device_buffer *device_buffer); 142 | 143 | void delete_params_block(struct TLVs *params_block); 144 | 145 | uint16_t get_sub_device_payloadtype(struct sub_device_buffer *package); 146 | 147 | int is_device_file_command(struct sub_device_buffer *device_buffer); 148 | 149 | 150 | #ifdef __cplusplus 151 | } 152 | #endif 153 | #endif 154 | 155 | 156 | 157 | -------------------------------------------------------------------------------- /src/PandoSdk/PandoSdk.h: -------------------------------------------------------------------------------- 1 | // 2 | // PandoSdk.h 3 | // PandoSdk version 0.1.0 4 | // 5 | // Created by liming_llm on 15/3/26. 6 | // Copyright (c) 2015年 liming_llm. All rights reserved. 7 | // 8 | #import 9 | 10 | @protocol PandoSdkDelegate; 11 | 12 | @interface PandoSdk : NSObject 13 | 14 | 15 | /*! 16 | * @method initWithDelegate: 17 | * 18 | * @param delegate The delegate that will receive PandoSdk events. 19 | * 20 | * @discussion The initialization call. 21 | */ 22 | - (instancetype)initWithDelegate:(id)delegate; 23 | 24 | /*! 25 | * @method configDeviceToWiFi:password:byMode: 26 | * 27 | * @param ssid The WiFi ssid you want you device to connect to. 28 | * @param password The password of the specified WiFi. 29 | * @param mode The different config method. 30 | * 31 | * @discussion Configure device with the specified WiFi ssid & password by different mode. 32 | */ 33 | - (void)configDeviceToWiFi:(NSString *)ssid password:(NSString *)password byMode:(NSString *)mode; 34 | 35 | /*! 36 | * @method stopConfig 37 | * 38 | * @discussion Stop to configure device while configuring. 39 | */ 40 | - (void)stopConfig; 41 | 42 | 43 | /*! 44 | * @method isDebugOn: 45 | * 46 | * @param isDebugOn Set YES to print debug info. 47 | * 48 | * @discussion Set YES to print debug info. 49 | */ 50 | - (void)isDebugOn:(BOOL)isDebugOn; 51 | 52 | @end 53 | 54 | 55 | 56 | /*! 57 | * @protocol PandoSdkDelegate 58 | * 59 | * @discussion The delegate of a PandoSdk object must adopt the PandoSdkDelegate protocol. The optional methods provide information about PandoSdk method. 60 | * 61 | */ 62 | @protocol PandoSdkDelegate 63 | 64 | @optional 65 | 66 | /*! 67 | * @method pandoSdk:didConfigDeviceToWiFi:deviceKey:error: 68 | * 69 | * @param pandoSdk The pandoSdk object providing configDeviceToWiFi method. 70 | * @param ssid The WiFi ssid the method configure to. 71 | * @param deviceKey The device key returned from device. 72 | * @param error If an error occurred, the cause of the failure. 73 | * 74 | * @discussion This method is invoked when a pandoSdk object ended configDeviceToWifi method. 75 | */ 76 | - (void)pandoSdk:(PandoSdk *)pandoSdk didConfigDeviceToWiFi:(NSString *)ssid deviceKey:(NSString *)deviceKey error:(NSError *)error; 77 | 78 | /*! 79 | * @method pandoSdk:didStopConfig:error: 80 | * 81 | * @param pandoSdk The pandoSdk object providing stopConfig method. 82 | * @param isStoped 83 | * @param error If an error occurred, the cause of the failure. 84 | * 85 | * @discussion This method is invoked when a pandoSdk object ended stopConfig method. 86 | */ 87 | - (void)pandoSdk:(PandoSdk *)pandoSdk didStopConfig:(BOOL)isStoped error:(NSError *)error; 88 | 89 | 90 | @end 91 | 92 | 93 | 94 | 95 | 96 | -------------------------------------------------------------------------------- /src/PandoSdk/esptouch/ESPDataCode.h: -------------------------------------------------------------------------------- 1 | // 2 | // ESPDataCode.h 3 | // EspTouchDemo 4 | // 5 | // Created by 白 桦 on 4/9/15. 6 | // Copyright (c) 2015 白 桦. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | #define DATA_CODE_LEN 6 12 | 13 | /** 14 | * one data format:(data code should have 2 to 65 data) 15 | * 16 | * control byte high 4 bits low 4 bits 17 | * 1st 9bits: 0x0 crc(high) data(high) 18 | * 2nd 9bits: 0x1 sequence header 19 | * 3rd 9bits: 0x0 crc(low) data(low) 20 | * 21 | * sequence header: 0,1,2,... 22 | * 23 | * @author afunx 24 | * 25 | */ 26 | @interface ESPDataCode : NSObject 27 | { 28 | @private 29 | Byte _seqHeader; 30 | @private 31 | Byte _dataHigh; 32 | @private 33 | Byte _dataLow; 34 | @private 35 | Byte _crcHigh; 36 | @private 37 | Byte _crcLow; 38 | } 39 | 40 | - (NSData*) getBytes; 41 | 42 | - (id) initWithU8: (UInt8) u8 andIndex: (int) index; 43 | 44 | @end 45 | -------------------------------------------------------------------------------- /src/PandoSdk/esptouch/ESPDataCode.m: -------------------------------------------------------------------------------- 1 | // 2 | // ESPDataCode.m 3 | // EspTouchDemo 4 | // 5 | // Created by 白 桦 on 4/9/15. 6 | // Copyright (c) 2015 白 桦. All rights reserved. 7 | // 8 | 9 | #import "ESPDataCode.h" 10 | #import "ESP_ByteUtil.h" 11 | #import "ESP_CRC8.h" 12 | 13 | #define INDEX_MAX 127 14 | 15 | @implementation ESPDataCode 16 | 17 | - (id) initWithU8: (UInt8) u8 andIndex: (int) index 18 | { 19 | if (index > INDEX_MAX) 20 | { 21 | perror("index > INDEX_MAX"); 22 | } 23 | self = [super init]; 24 | if (self) 25 | { 26 | NSData* u8Data = [ESP_ByteUtil splitUint8To2Bytes:u8]; 27 | [u8Data getBytes:&_dataHigh range:NSMakeRange(0, 1)]; 28 | [u8Data getBytes:&_dataLow range:NSMakeRange(1, 1)]; 29 | ESP_CRC8 *crc = [[ESP_CRC8 alloc]init]; 30 | [crc updateWithValue:u8]; 31 | [crc updateWithValue:index]; 32 | NSData* crcData = [ESP_ByteUtil splitUint8To2Bytes:[crc getValue]]; 33 | [crcData getBytes:&_crcHigh range:NSMakeRange(0, 1)]; 34 | [crcData getBytes:&_crcLow range:NSMakeRange(1, 1)]; 35 | _seqHeader = index; 36 | } 37 | return self; 38 | } 39 | 40 | - (NSData *) getBytes 41 | { 42 | Byte bytes[DATA_CODE_LEN]; 43 | bytes[0] = 0x00; 44 | bytes[1] = [ESP_ByteUtil combine2bytesToOneWithHigh:_crcHigh andLow:_dataHigh]; 45 | bytes[2] = 0x01; 46 | bytes[3] = _seqHeader; 47 | bytes[4] = 0x00; 48 | bytes[5] = [ESP_ByteUtil combine2bytesToOneWithHigh:_crcLow andLow:_dataLow]; 49 | NSData* data = [[NSData alloc]initWithBytes:bytes length:DATA_CODE_LEN]; 50 | return data; 51 | } 52 | 53 | - (NSString *)description 54 | { 55 | NSData* data = [self getBytes]; 56 | return [ESP_ByteUtil getHexStringByData:data]; 57 | } 58 | 59 | @end 60 | -------------------------------------------------------------------------------- /src/PandoSdk/esptouch/ESPDatumCode.h: -------------------------------------------------------------------------------- 1 | // 2 | // ESPDatumCode.h 3 | // EspTouchDemo 4 | // 5 | // Created by 白 桦 on 4/9/15. 6 | // Copyright (c) 2015 白 桦. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface ESPDatumCode : NSObject 12 | { 13 | @private 14 | NSMutableArray *_dataCodes; 15 | } 16 | 17 | /** 18 | * Constructor of DatumCode 19 | * 20 | * @param apSsid 21 | * the Ap's ssid 22 | * @param apBssid 23 | * the Ap's bssid 24 | * @param apPwd 25 | * the Ap's password ssid 26 | * @param ipAddrData 27 | * the ip address of the phone or pad 28 | * @param isSsidHidden 29 | * whether the Ap's ssid is hidden 30 | * 31 | */ 32 | - (id) initWithSsid: (NSString *) apSsid andApBssid: (NSString *) apBssid andApPwd: (NSString*) apPwd andInetAddrData: (NSData *) ipAddrData andIsSsidHidden: (BOOL) isSsidHidden; 33 | 34 | - (NSData *) getBytes; 35 | 36 | - (NSData *) getU16s; 37 | 38 | @end 39 | -------------------------------------------------------------------------------- /src/PandoSdk/esptouch/ESPDatumCode.m: -------------------------------------------------------------------------------- 1 | // 2 | // ESPDatumCode.m 3 | // EspTouchDemo 4 | // 5 | // Created by 白 桦 on 4/9/15. 6 | // Copyright (c) 2015 白 桦. All rights reserved. 7 | // 8 | 9 | #import "ESPDatumCode.h" 10 | #import "ESPDataCode.h" 11 | #import "ESP_ByteUtil.h" 12 | #import "ESP_CRC8.h" 13 | #import "ESP_NetUtil.h" 14 | #include "ESPTouchTask.h" 15 | 16 | // define by the Esptouch protocol, all of the datum code should add EXTRA_LEN to prevent 0 17 | #define EXTRA_LEN 40 18 | #define EXTRA_HEAD_LEN 5 19 | 20 | @implementation ESPDatumCode 21 | 22 | - (id) initWithSsid: (NSString *) apSsid andApBssid: (NSString *) apBssid andApPwd: (NSString*) apPwd andInetAddrData: (NSData *) ipAddrData andIsSsidHidden: (BOOL) isSsidHidden 23 | { 24 | self = [super init]; 25 | if (self) 26 | { 27 | // Data = total len(1 byte) + apPwd len(1 byte) + SSID CRC(1 byte) + 28 | // BSSID CRC(1 byte) + TOTAL XOR(1 byte) + ipAddress(4 byte) + apPwd + apSsid apPwdLen <= 29 | // 105 at the moment 30 | 31 | // total xor 32 | UInt8 totalXor = 0; 33 | 34 | NSData *apPwdBytesData = [ESP_ByteUtil getBytesByNSString:apPwd]; 35 | NSData *apSsidBytesData = [ESP_ByteUtil getBytesByNSString:apSsid]; 36 | Byte apPwdBytes[[apPwdBytesData length]]; 37 | Byte apSsidBytes[[apSsidBytesData length]]; 38 | [apPwdBytesData getBytes:apPwdBytes length:[apPwdBytesData length]]; 39 | [apSsidBytesData getBytes:apSsidBytes length:[apSsidBytesData length]]; 40 | Byte apPwdLen = [apPwdBytesData length]; 41 | ESP_CRC8 *crc = [[ESP_CRC8 alloc]init]; 42 | [crc updateWithBuf:apSsidBytes Nbytes:(int)sizeof(apSsidBytes)]; 43 | Byte apSsidCrc = [crc getValue]; 44 | 45 | [crc reset]; 46 | NSData *apBssidData = [ESP_NetUtil parseBssid2bytes:apBssid]; 47 | int apBssidDataLen = (int)[apBssidData length]; 48 | Byte apBssidBytes[apBssidDataLen]; 49 | [apBssidData getBytes:apBssidBytes length:[apBssidData length]]; 50 | [crc updateWithBuf:apBssidBytes Nbytes:apBssidDataLen]; 51 | UInt8 apBssidCrc = [crc getValue]; 52 | 53 | UInt8 apSsidLen = sizeof(apSsidBytes); 54 | 55 | // only support ipv4 at the moment 56 | UInt8 ipLen = [ipAddrData length]; 57 | Byte ipAddrUint8s[ipLen]; 58 | [ipAddrData getBytes:ipAddrUint8s length:[ipAddrData length]]; 59 | 60 | UInt8 _totalLen = EXTRA_HEAD_LEN + ipLen + apPwdLen + apSsidLen; 61 | UInt8 totalLen = isSsidHidden ? (EXTRA_HEAD_LEN + ipLen + apPwdLen + apSsidLen):(EXTRA_HEAD_LEN + ipLen + apPwdLen); 62 | 63 | 64 | // build data codes 65 | _dataCodes = [[NSMutableArray alloc]initWithCapacity:totalLen]; 66 | ESPDataCode *dataCode = [[ESPDataCode alloc]initWithU8:_totalLen andIndex:0]; 67 | [_dataCodes addObject:dataCode]; 68 | totalXor ^= _totalLen; 69 | dataCode = [[ESPDataCode alloc]initWithU8:apPwdLen andIndex:1]; 70 | [_dataCodes addObject:dataCode]; 71 | totalXor ^= apPwdLen; 72 | dataCode = [[ESPDataCode alloc]initWithU8:apSsidCrc andIndex:2]; 73 | [_dataCodes addObject:dataCode]; 74 | totalXor ^= apSsidCrc; 75 | dataCode = [[ESPDataCode alloc]initWithU8:apBssidCrc andIndex:3]; 76 | [_dataCodes addObject:dataCode]; 77 | totalXor ^= apBssidCrc; 78 | // ESPDataCode 4 is nil 79 | for (int i = 0; i < ipLen; i++) 80 | { 81 | dataCode = [[ESPDataCode alloc]initWithU8:ipAddrUint8s[i] andIndex:i + EXTRA_HEAD_LEN]; 82 | [_dataCodes addObject:dataCode]; 83 | totalXor ^= ipAddrUint8s[i]; 84 | } 85 | for (int i = 0; i < apPwdLen; i++) 86 | { 87 | dataCode = [[ESPDataCode alloc]initWithU8:apPwdBytes[i] andIndex:i + EXTRA_HEAD_LEN + ipLen]; 88 | [_dataCodes addObject:dataCode]; 89 | totalXor ^= apPwdBytes[i]; 90 | } 91 | 92 | // totalXor will xor apSsidChars no matter whether the ssid is hidden 93 | for (int i = 0; i < apSsidLen; i++) 94 | { 95 | totalXor ^= apSsidBytes[i]; 96 | } 97 | 98 | if (isSsidHidden) 99 | { 100 | for (int i = 0; i < apSsidLen; i++) 101 | { 102 | dataCode = [[ESPDataCode alloc]initWithU8:apSsidBytes[i] andIndex:i + EXTRA_HEAD_LEN + ipLen + apPwdLen]; 103 | [_dataCodes addObject:dataCode]; 104 | } 105 | } 106 | 107 | // add total xor last 108 | dataCode = [[ESPDataCode alloc]initWithU8:totalXor andIndex:4]; 109 | [_dataCodes insertObject:dataCode atIndex:4]; 110 | 111 | if (DEBUG_ON) 112 | { 113 | //NSLog(@"len = %d datacode = %@", _totalLen, _dataCodes); 114 | } 115 | } 116 | return self; 117 | } 118 | 119 | - (NSData *) getBytes 120 | { 121 | Byte datumCode[[_dataCodes count] * DATA_CODE_LEN]; 122 | for (int i = 0; i < [_dataCodes count]; i++) 123 | { 124 | ESPDataCode *dataCode = [_dataCodes objectAtIndex:i]; 125 | NSData *bytesData = [dataCode getBytes]; 126 | Byte bytes[DATA_CODE_LEN]; 127 | [bytesData getBytes:bytes length:DATA_CODE_LEN]; 128 | void *dest = datumCode + i * DATA_CODE_LEN * sizeof(Byte); 129 | void *src = bytes; 130 | memcpy(dest, src, DATA_CODE_LEN); 131 | } 132 | return [[NSData alloc]initWithBytes:datumCode length:sizeof(datumCode)]; 133 | } 134 | 135 | - (NSData *) getU16s 136 | { 137 | NSData *dataBytes = [self getBytes]; 138 | NSInteger totalLen = [dataBytes length]; 139 | Byte bytes[totalLen]; 140 | [dataBytes getBytes:bytes length:totalLen]; 141 | NSInteger len = totalLen / 2; 142 | UInt16 dataU16s[len]; 143 | Byte high, low; 144 | for (int i = 0; i < len; i++) 145 | { 146 | high = bytes[i * 2]; 147 | low = bytes[i * 2 + 1]; 148 | dataU16s[i] = [ESP_ByteUtil combine2bytesToU16WithHigh:high andLow:low] + EXTRA_LEN; 149 | } 150 | return [[NSData alloc]initWithBytes:dataU16s length:totalLen]; 151 | } 152 | 153 | - (NSString *)description 154 | { 155 | NSData* data = [self getBytes]; 156 | return [ESP_ByteUtil getHexStringByData:data]; 157 | } 158 | 159 | 160 | @end 161 | -------------------------------------------------------------------------------- /src/PandoSdk/esptouch/ESPGuideCode.h: -------------------------------------------------------------------------------- 1 | // 2 | // ESPGuideCode.h 3 | // EspTouchDemo 4 | // 5 | // Created by 白 桦 on 4/9/15. 6 | // Copyright (c) 2015 白 桦. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface ESPGuideCode : NSObject 12 | 13 | - (NSData *) getU16s; 14 | 15 | @end 16 | -------------------------------------------------------------------------------- /src/PandoSdk/esptouch/ESPGuideCode.m: -------------------------------------------------------------------------------- 1 | // 2 | // ESPGuideCode.m 3 | // EspTouchDemo 4 | // 5 | // Created by 白 桦 on 4/9/15. 6 | // Copyright (c) 2015 白 桦. All rights reserved. 7 | // 8 | 9 | #import "ESPGuideCode.h" 10 | #import "ESP_ByteUtil.h" 11 | 12 | #define GUIDE_CODE_LEN 4 13 | 14 | @implementation ESPGuideCode 15 | 16 | - (NSData *) getU16s 17 | { 18 | UInt16 guideU16s[GUIDE_CODE_LEN]; 19 | guideU16s[0] = 515; 20 | guideU16s[1] = 514; 21 | guideU16s[2] = 513; 22 | guideU16s[3] = 512; 23 | NSData* data = [[NSData alloc]initWithBytes:guideU16s length:GUIDE_CODE_LEN*2]; 24 | 25 | return data; 26 | } 27 | 28 | - (NSString *)description 29 | { 30 | NSData* data = [self getU16s]; 31 | return [ESP_ByteUtil getHexStringByData:data]; 32 | } 33 | 34 | 35 | @end 36 | -------------------------------------------------------------------------------- /src/PandoSdk/esptouch/ESPTouchGenerator.h: -------------------------------------------------------------------------------- 1 | // 2 | // ESPTouchGenerator.h 3 | // EspTouchDemo 4 | // 5 | // Created by 白 桦 on 4/9/15. 6 | // Copyright (c) 2015 白 桦. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface ESPTouchGenerator : NSObject 12 | { 13 | @private 14 | NSMutableArray *_gcBytes2; 15 | @private 16 | NSMutableArray *_dcBytes2; 17 | } 18 | /** 19 | * Constructor of EsptouchGenerator, it will cost some time(maybe a bit much) 20 | * 21 | * @param apSsid 22 | * the Ap's ssid 23 | * @param apBssid 24 | * the Ap's bssid 25 | * @param apPwd 26 | * the Ap's password 27 | * @param ipAddrData 28 | * the ip address of the phone or pad 29 | * @param isSsidHidden 30 | * whether the Ap's ssid is hidden 31 | */ 32 | - (id) initWithSsid: (NSString *) apSsid andApBssid: (NSString *) apBssid andApPassword: (NSString *) apPwd andInetAddrData: (NSData *) ipAddrData andIsSsidHidden: (BOOL) isSsidHidden; 33 | 34 | /** 35 | * Get guide code by the format of byte[][] 36 | * @return guide code by the format of byte[][] 37 | */ 38 | - (NSArray *) getGCBytes2; 39 | 40 | /** 41 | * Get data code by the format of byte[][] 42 | * @return data code by the format of byte[][] 43 | */ 44 | - (NSArray *) getDCBytes2; 45 | 46 | @end 47 | -------------------------------------------------------------------------------- /src/PandoSdk/esptouch/ESPTouchGenerator.m: -------------------------------------------------------------------------------- 1 | // 2 | // ESPTouchGenerator.m 3 | // EspTouchDemo 4 | // 5 | // Created by 白 桦 on 4/9/15. 6 | // Copyright (c) 2015 白 桦. All rights reserved. 7 | // 8 | 9 | #import "ESPTouchGenerator.h" 10 | #import "ESP_ByteUtil.h" 11 | #import "ESPGuideCode.h" 12 | #import "ESPDatumCode.h" 13 | 14 | 15 | @implementation ESPTouchGenerator 16 | 17 | - (id) initWithSsid: (NSString *) apSsid andApBssid: (NSString *) apBssid andApPassword: (NSString *) apPwd andInetAddrData: (NSData *) ipAddrData andIsSsidHidden: (BOOL) isSsidHidden 18 | { 19 | self = [super init]; 20 | if (self) 21 | { 22 | // generate guide code 23 | ESPGuideCode *gc = [[ESPGuideCode alloc]init]; 24 | NSData *gcData1 = [gc getU16s]; 25 | NSUInteger gcData1Len = [gcData1 length]; 26 | UInt16 gcU16_1[gcData1Len/2]; 27 | [gcData1 getBytes:gcU16_1 length:gcData1Len]; 28 | _gcBytes2 = [[NSMutableArray alloc]initWithCapacity:gcData1Len]; 29 | for (int i = 0; i < gcData1Len/2; i++) 30 | { 31 | NSData* data = [ESP_ByteUtil genSpecBytesWithU16:gcU16_1[i]]; 32 | [_gcBytes2 addObject:data]; 33 | } 34 | 35 | // generate data code 36 | ESPDatumCode *dc = [[ESPDatumCode alloc]initWithSsid:apSsid andApBssid:apBssid andApPwd:apPwd andInetAddrData:ipAddrData andIsSsidHidden:isSsidHidden]; 37 | NSData *dcData1 = [dc getU16s]; 38 | NSUInteger dcDataLen = [dcData1 length]; 39 | UInt16 dcU16_1[dcDataLen/2]; 40 | [dcData1 getBytes:dcU16_1 length:dcDataLen]; 41 | _dcBytes2 = [[NSMutableArray alloc]initWithCapacity:dcDataLen]; 42 | for (int i = 0; i < dcDataLen/2; i++) 43 | { 44 | NSData* data = [ESP_ByteUtil genSpecBytesWithU16:dcU16_1[i]]; 45 | [_dcBytes2 addObject:data]; 46 | } 47 | } 48 | return self; 49 | } 50 | 51 | - (NSArray *) getGCBytes2 52 | { 53 | return _gcBytes2; 54 | } 55 | 56 | - (NSArray *) getDCBytes2 57 | { 58 | return _dcBytes2; 59 | } 60 | @end 61 | -------------------------------------------------------------------------------- /src/PandoSdk/esptouch/ESPTouchResult.h: -------------------------------------------------------------------------------- 1 | // 2 | // ESPTouchResult.h 3 | // EspTouchDemo 4 | // 5 | // Created by 白 桦 on 4/14/15. 6 | // Copyright (c) 2015 白 桦. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface ESPTouchResult : NSObject 12 | 13 | // it is used to check whether the esptouch task is executed suc 14 | @property (nonatomic,assign) BOOL isSuc; 15 | 16 | // it is used to store the device's bssid 17 | @property (nonatomic,strong) NSString * bssid; 18 | 19 | // it is used to check whether the esptouch task is cancelled by user 20 | @property (atomic,assign) BOOL isCancelled; 21 | 22 | // it is used to store the device's ip address 23 | @property (atomic) NSData * ipAddrData; 24 | 25 | /** 26 | * Constructor of EsptouchResult 27 | * 28 | * @param isSuc whether the esptouch task is executed suc 29 | * @param bssid the device's bssid 30 | * @param ipAddrData the device's ip address 31 | */ 32 | - (id) initWithIsSuc: (BOOL) isSuc andBssid: (NSString *) bssid andInetAddrData: (NSData *) ipAddrData; 33 | 34 | @end 35 | -------------------------------------------------------------------------------- /src/PandoSdk/esptouch/ESPTouchResult.m: -------------------------------------------------------------------------------- 1 | // 2 | // ESPTouchResult.m 3 | // EspTouchDemo 4 | // 5 | // Created by 白 桦 on 4/14/15. 6 | // Copyright (c) 2015 白 桦. All rights reserved. 7 | // 8 | 9 | #import "ESPTouchResult.h" 10 | #import "ESP_NetUtil.h" 11 | 12 | @implementation ESPTouchResult 13 | 14 | - (id) initWithIsSuc: (BOOL) isSuc andBssid: (NSString *) bssid andInetAddrData: (NSData *) ipAddrData 15 | { 16 | self = [super init]; 17 | if (self) 18 | { 19 | self.isSuc = isSuc; 20 | self.bssid = bssid; 21 | self.isCancelled = NO; 22 | self.ipAddrData = ipAddrData; 23 | } 24 | return self; 25 | } 26 | 27 | - (NSString *)description 28 | { 29 | NSString *ipAddrDataStr = [ESP_NetUtil descriptionInetAddrByData:self.ipAddrData]; 30 | return [[NSString alloc]initWithFormat:@"[isSuc: %@,isCancelled: %@,bssid: %@,inetAddress: %@]",self.isSuc? @"YES":@"NO", 31 | self.isCancelled? @"YES":@"NO" 32 | ,self.bssid 33 | ,ipAddrDataStr]; 34 | } 35 | 36 | @end 37 | -------------------------------------------------------------------------------- /src/PandoSdk/esptouch/ESPTouchTask.h: -------------------------------------------------------------------------------- 1 | // 2 | // ESPTouchTask.h 3 | // EspTouchDemo 4 | // 5 | // Created by 白 桦 on 4/14/15. 6 | // Copyright (c) 2015 白 桦. All rights reserved. 7 | // 8 | 9 | #import 10 | #import "ESPTouchResult.h" 11 | 12 | #define DEBUG_ON NO 13 | 14 | @interface ESPTouchTask : NSObject 15 | 16 | @property (atomic,assign) BOOL isCancelled; 17 | 18 | /** 19 | * Constructor of EsptouchTask 20 | * 21 | * @param apSsid 22 | * the Ap's ssid 23 | * @param apBssid 24 | * the Ap's bssid 25 | * @param apPassword 26 | * the Ap's password 27 | * @param isSsidHidden 28 | * whether the Ap's ssid is hidden 29 | */ 30 | - (id) initWithApSsid: (NSString *)apSsid andApBssid: (NSString *) apBssid andApPwd: (NSString *)apPwd andIsSsidHiden: (BOOL) isSsidHidden; 31 | 32 | /** 33 | * Constructor of EsptouchTask 34 | * 35 | * @param apSsid 36 | * the Ap's ssid 37 | * @param apBssid 38 | * the Ap's bssid 39 | * @param apPassword 40 | * the Ap's password 41 | * @param isSsidHidden 42 | * whether the Ap's ssid is hidden 43 | * @param timeoutMillisecond(it should be >= 10000+8000) 44 | * millisecond of total timeout 45 | * @param context 46 | * the Context of the Application 47 | */ 48 | - (id) initWithApSsid: (NSString *)apSsid andApBssid: (NSString *) apBssid andApPwd: (NSString *)apPwd andIsSsidHiden: (BOOL) isSsidHidden andTimeoutMillisecond: (int) timeoutMillisecond; 49 | 50 | /** 51 | * Interrupt the Esptouch Task when User tap back or close the Application. 52 | */ 53 | - (void) interrupt; 54 | 55 | /** 56 | * Note: !!!Don't call the task at UI Main Thread 57 | * 58 | * Smart Config v2.2 support the API 59 | * 60 | * @return the ESPTouchResult 61 | */ 62 | - (ESPTouchResult*) executeForResult; 63 | 64 | /** 65 | * Note: !!!Don't call the task at UI Main Thread 66 | * 67 | * Smart Config v2.2 support the API 68 | * 69 | * It will be blocked until the client receive result count >= expectTaskResultCount. 70 | * If it fail, it will return one fail result will be returned in the list. 71 | * If it is cancelled while executing, 72 | * if it has received some results, all of them will be returned in the list. 73 | * if it hasn't received any results, one cancel result will be returned in the list. 74 | * 75 | * @param expectTaskResultCount 76 | * the expect result count(if expectTaskResultCount <= 0, 77 | * expectTaskResultCount = INT32_MAX) 78 | * @return the NSArray of EsptouchResult 79 | * @throws RuntimeException 80 | */ 81 | - (NSArray*) executeForResults:(int) expectTaskResultCount; 82 | 83 | @end 84 | -------------------------------------------------------------------------------- /src/PandoSdk/esptouch/ESPTouchTaskParameter.h: -------------------------------------------------------------------------------- 1 | // 2 | // ESPTaskParameter.h 3 | // EspTouchDemo 4 | // 5 | // Created by 白 桦 on 5/20/15. 6 | // Copyright (c) 2015 白 桦. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface ESPTaskParameter : NSObject 12 | 13 | /** 14 | * get interval millisecond for guide code(the time between each guide code sending) 15 | * @return interval millisecond for guide code(the time between each guide code sending) 16 | */ 17 | - (long) getIntervalGuideCodeMillisecond; 18 | 19 | /** 20 | * get interval millisecond for data code(the time between each data code sending) 21 | * @return interval millisecond for data code(the time between each data code sending) 22 | */ 23 | - (long) getIntervalDataCodeMillisecond; 24 | 25 | /** 26 | * get timeout millisecond for guide code(the time how much the guide code sending) 27 | * @return timeout millisecond for guide code(the time how much the guide code sending) 28 | */ 29 | - (long) getTimeoutGuideCodeMillisecond; 30 | 31 | /** 32 | * get timeout millisecond for data code(the time how much the data code sending) 33 | * @return timeout millisecond for data code(the time how much the data code sending) 34 | */ 35 | - (long) getTimeoutDataCodeMillisecond; 36 | 37 | /** 38 | * get timeout millisecond for total code(guide code and data code altogether) 39 | * @return timeout millisecond for total code(guide code and data code altogether) 40 | */ 41 | - (long) getTimeoutTotalCodeMillisecond; 42 | 43 | /** 44 | * get total repeat time for executing esptouch task 45 | * @return total repeat time for executing esptouch task 46 | */ 47 | - (int) getTotalRepeatTime; 48 | 49 | /** 50 | * the length of the Esptouch result 1st byte is the total length of ssid and 51 | * password, the other 6 bytes are the device's bssid 52 | */ 53 | 54 | /** 55 | * get esptouchResult length of one 56 | * @return length of one 57 | */ 58 | - (int) getEsptouchResultOneLen; 59 | 60 | /** 61 | * get esptouchResult length of mac 62 | * @return length of mac 63 | */ 64 | - (int) getEsptouchResultMacLen; 65 | 66 | /** 67 | * get esptouchResult length of ip 68 | * @return length of ip 69 | */ 70 | - (int) getEsptouchResultIpLen; 71 | 72 | /** 73 | * get esptouchResult total length 74 | * @return total length 75 | */ 76 | - (int) getEsptouchResultTotalLen; 77 | 78 | /** 79 | * get port for listening(used by server) 80 | * @return port for listening(used by server) 81 | */ 82 | - (int) getPortListening; 83 | 84 | /** 85 | * get target hostname 86 | * @return target hostame(used by client) 87 | */ 88 | - (NSString *) getTargetHostname; 89 | 90 | /** 91 | * get target port 92 | * @return target port(used by client) 93 | */ 94 | - (int) getTargetPort; 95 | 96 | /** 97 | * get millisecond for waiting udp receiving(receiving without sending) 98 | * @return millisecond for waiting udp receiving(receiving without sending) 99 | */ 100 | - (int) getWaitUdpReceivingMillisecond; 101 | 102 | /** 103 | * get millisecond for waiting udp sending(sending including receiving) 104 | * @return millisecond for waiting udep sending(sending including receiving) 105 | */ 106 | - (int) getWaitUdpSendingMillisecond; 107 | 108 | /** 109 | * get millisecond for waiting udp sending and receiving 110 | * @return millisecond for waiting udp sending and receiving 111 | */ 112 | - (int) getWaitUdpTotalMillisecond; 113 | 114 | /** 115 | * get the threshold for how many correct broadcast should be received 116 | * @return the threshold for how many correct broadcast should be received 117 | */ 118 | - (int) getThresholdSucBroadcastCount; 119 | 120 | /** 121 | * set the millisecond for waiting udp sending and receiving 122 | * @param waitUdpTotalMillisecond the millisecond for waiting udp sending and receiving 123 | */ 124 | - (void) setWaitUdpTotalMillisecond: (int) waitUdpTotalMillisecond; 125 | 126 | 127 | /** 128 | * get the count of expect task results 129 | * @return the count of expect task results 130 | */ 131 | - (int) getExpectTaskResultCount; 132 | 133 | /** 134 | * set the count of expect task results 135 | * @param expectTaskResultCount the count of expect task results 136 | */ 137 | - (void) setExpectTaskResultCount: (int) expectTaskResultCount; 138 | 139 | @end 140 | -------------------------------------------------------------------------------- /src/PandoSdk/esptouch/ESPTouchTaskParameter.m: -------------------------------------------------------------------------------- 1 | // 2 | // ESPTaskParameter.m 3 | // EspTouchDemo 4 | // 5 | // Created by 白 桦 on 5/20/15. 6 | // Copyright (c) 2015 白 桦. All rights reserved. 7 | // 8 | 9 | #import "ESPTouchTaskParameter.h" 10 | 11 | @interface ESPTaskParameter() 12 | @property (nonatomic,assign) long intervalGuideCodeMillisecond; 13 | @property (nonatomic,assign) long intervalDataCodeMillisecond; 14 | @property (nonatomic,assign) long timeoutGuideCodeMillisecond; 15 | @property (nonatomic,assign) long timeoutDataCodeMillisecond; 16 | @property (nonatomic,assign) long timeoutTotalCodeMillisecond; 17 | @property (nonatomic,assign) int totalRepeatTime; 18 | @property (nonatomic,assign) int esptouchResultOneLen; 19 | @property (nonatomic,assign) int esptouchResultMacLen; 20 | @property (nonatomic,assign) int esptouchResultIpLen; 21 | @property (nonatomic,assign) int esptouchResultTotalLen; 22 | @property (nonatomic,assign) int portListening; 23 | @property (nonatomic,strong) NSString* targetHostname; 24 | @property (nonatomic,assign) int targetPort; 25 | @property (nonatomic,assign) int waitUdpReceivingMillisecond; 26 | @property (nonatomic,assign) int waitUdpSendingMillisecond; 27 | @property (nonatomic,assign) int thresholdSucBroadcastCount; 28 | @property (nonatomic,assign) int expectTaskResultCount; 29 | @end 30 | 31 | @implementation ESPTaskParameter 32 | 33 | - (id) init 34 | { 35 | self = [super init]; 36 | if (self) { 37 | self.intervalGuideCodeMillisecond = 10; 38 | self.intervalDataCodeMillisecond = 10; 39 | self.timeoutGuideCodeMillisecond = 2000; 40 | self.timeoutDataCodeMillisecond = 4000; 41 | self.timeoutTotalCodeMillisecond = 2000 + 4000; 42 | self.totalRepeatTime = 1; 43 | self.esptouchResultOneLen = 1; 44 | self.esptouchResultMacLen = 6; 45 | self.esptouchResultIpLen = 4; 46 | self.esptouchResultTotalLen = 1 + 6 + 4; 47 | self.portListening = 18266; 48 | self.targetHostname = @"255.255.255.255"; 49 | self.targetPort = 7001; 50 | self.waitUdpReceivingMillisecond = 10000; 51 | self.waitUdpSendingMillisecond = 48000; 52 | self.thresholdSucBroadcastCount = 1; 53 | self.expectTaskResultCount = 1; 54 | } 55 | return self; 56 | } 57 | 58 | - (long) getIntervalGuideCodeMillisecond 59 | { 60 | return self.intervalGuideCodeMillisecond; 61 | } 62 | 63 | - (long) getIntervalDataCodeMillisecond 64 | { 65 | return self.intervalDataCodeMillisecond; 66 | } 67 | 68 | - (long) getTimeoutGuideCodeMillisecond 69 | { 70 | return self.timeoutGuideCodeMillisecond; 71 | } 72 | 73 | - (long) getTimeoutDataCodeMillisecond 74 | { 75 | return self.timeoutDataCodeMillisecond; 76 | } 77 | 78 | - (long) getTimeoutTotalCodeMillisecond 79 | { 80 | return self.timeoutTotalCodeMillisecond; 81 | } 82 | 83 | - (int) getTotalRepeatTime 84 | { 85 | return self.totalRepeatTime; 86 | } 87 | 88 | - (int) getEsptouchResultOneLen 89 | { 90 | return self.esptouchResultOneLen; 91 | } 92 | 93 | 94 | - (int) getEsptouchResultMacLen 95 | { 96 | return self.esptouchResultMacLen; 97 | } 98 | 99 | 100 | - (int) getEsptouchResultIpLen 101 | { 102 | return self.esptouchResultIpLen; 103 | } 104 | 105 | 106 | - (int) getEsptouchResultTotalLen 107 | { 108 | return self.esptouchResultTotalLen; 109 | } 110 | 111 | - (int) getPortListening 112 | { 113 | return self.portListening; 114 | } 115 | 116 | - (NSString *) getTargetHostname 117 | { 118 | return self.targetHostname; 119 | } 120 | 121 | - (int) getTargetPort 122 | { 123 | return self.targetPort; 124 | } 125 | 126 | - (int) getWaitUdpReceivingMillisecond 127 | { 128 | return self.waitUdpReceivingMillisecond; 129 | } 130 | 131 | - (int) getWaitUdpSendingMillisecond 132 | { 133 | return self.waitUdpSendingMillisecond; 134 | } 135 | 136 | - (int) getWaitUdpTotalMillisecond 137 | { 138 | return self.waitUdpReceivingMillisecond + self.waitUdpSendingMillisecond; 139 | } 140 | 141 | - (int) getThresholdSucBroadcastCount 142 | { 143 | return self.thresholdSucBroadcastCount; 144 | } 145 | 146 | - (void) setWaitUdpTotalMillisecond: (int) waitUdpTotalMillisecond 147 | { 148 | if (waitUdpTotalMillisecond < self.waitUdpSendingMillisecond + [self getTimeoutTotalCodeMillisecond]) 149 | { 150 | // if it happen, even one turn about sending udp broadcast can't be completed 151 | NSLog(@"ESPTouchTaskParameter waitUdpTotalMillisecod is invalid, it is less than mWaitUdpReceivingMilliseond + [self getTimeoutTotalCodeMillisecond]"); 152 | assert(0); 153 | } 154 | self.waitUdpSendingMillisecond = waitUdpTotalMillisecond - self.waitUdpReceivingMillisecond; 155 | } 156 | 157 | - (int) getExpectTaskResultCount 158 | { 159 | return self.expectTaskResultCount; 160 | } 161 | 162 | - (void) setExpectTaskResultCount: (int) expectTaskResultCount 163 | { 164 | _expectTaskResultCount = expectTaskResultCount; 165 | } 166 | @end 167 | -------------------------------------------------------------------------------- /src/PandoSdk/esptouch/ESPUDPSocketClient.h: -------------------------------------------------------------------------------- 1 | // 2 | // ESPUDPSocketClient.h 3 | // EspTouchDemo 4 | // 5 | // Created by 白 桦 on 4/13/15. 6 | // Copyright (c) 2015 白 桦. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface ESPUDPSocketClient : NSObject 12 | 13 | - (void) close; 14 | 15 | - (void) interrupt; 16 | 17 | /** 18 | * send the data by UDP 19 | * 20 | * @param bytes 21 | * the array of datas to be sent 22 | * @param targetHost 23 | * the host name of target, e.g. 192.168.1.101 24 | * @param targetPort 25 | * the port of target 26 | * @param interval 27 | * the milliseconds to between each UDP sent 28 | */ 29 | - (void) sendDataWithBytesArray2: (NSArray *) bytesArray2 ToTargetHostName: (NSString *)targetHostName WithPort: (int) port 30 | andInterval: (long) interval; 31 | 32 | /** 33 | * send the data by UDP 34 | * 35 | * @param data 36 | * the data to be sent 37 | * @param offset 38 | * the offset which data to be sent 39 | * @param count 40 | * the count of the data 41 | * @param targetHost 42 | * the host name of target, e.g. 192.168.1.101 43 | * @param targetPort 44 | * the port of target 45 | * @param interval 46 | * the milliseconds to between each UDP sent 47 | */ 48 | - (void) sendDataWithBytesArray2: (NSArray *) bytesArray2 Offset: (NSUInteger) offset Count: (NSUInteger) count ToTargetHostName: (NSString *)targetHostName WithPort: (int) port 49 | andInterval: (long) interval; 50 | @end 51 | -------------------------------------------------------------------------------- /src/PandoSdk/esptouch/ESPUDPSocketClient.m: -------------------------------------------------------------------------------- 1 | // 2 | // ESPUDPSocketClient.m 3 | // EspTouchDemo 4 | // 5 | // Created by 白 桦 on 4/13/15. 6 | // Copyright (c) 2015 白 桦. All rights reserved. 7 | // 8 | 9 | #import "ESPUDPSocketClient.h" 10 | #include 11 | #include 12 | #include 13 | #include "ESPTouchTask.h" 14 | 15 | @interface ESPUDPSocketClient () 16 | 17 | @property(nonatomic, assign) int _sck_fd; 18 | @property(nonatomic, assign) BOOL _isStop; 19 | // it is used to check whether the socket is closed already to prevent close more than once. 20 | // especially, when you close the socket second time, it is created just now, it will crash. 21 | // 22 | // // suppose fd1 = 4, fd1 belong to obj1 23 | // e.g. int fd1 = socket(AF_INET,SOCK_DRAM,0); 24 | // close(fd1); 25 | // 26 | // // suppose fd2 = 4 as well, fd2 belong to obj2 27 | // int fd2 = socket(AF_INET,SOCK_DRAM,0); 28 | // 29 | // // obj1's dealloc() is called by system, so 30 | // close(fd1); 31 | // 32 | // // Amazing!!! at the moment, fd2 is close by others 33 | // 34 | @property(nonatomic,assign) volatile BOOL _isClosed; 35 | // it is used to lock the close method 36 | @property(nonatomic,strong) volatile NSLock *_lock; 37 | 38 | @end 39 | 40 | @implementation ESPUDPSocketClient 41 | 42 | - (id)init 43 | { 44 | self = [super init]; 45 | if (self) 46 | { 47 | self._isStop = NO; 48 | self._sck_fd = socket(AF_INET,SOCK_DGRAM,0); 49 | if (DEBUG_ON) 50 | { 51 | NSLog(@"##########################client init() _sck_fd=%d",self._sck_fd); 52 | } 53 | if (self._sck_fd < 0) 54 | { 55 | if (DEBUG_ON) 56 | { 57 | perror("client: init() _skd_fd init fail\n"); 58 | } 59 | return nil; 60 | } 61 | } 62 | return self; 63 | } 64 | 65 | // make sure the socket will be closed sometime 66 | - (void)dealloc 67 | { 68 | if (DEBUG_ON) 69 | { 70 | NSLog(@"###################client dealloc()"); 71 | } 72 | [self close]; 73 | } 74 | 75 | - (void) close 76 | { 77 | [self._lock lock]; 78 | if (!self._isClosed) 79 | { 80 | if (DEBUG_ON) 81 | { 82 | NSLog(@"###################client close() fd=%d",self._sck_fd); 83 | } 84 | close(self._sck_fd); 85 | self._isClosed = YES; 86 | } 87 | [self._lock unlock]; 88 | } 89 | 90 | - (void) interrupt 91 | { 92 | self._isStop = YES; 93 | } 94 | 95 | - (void) sendDataWithBytesArray2: (NSArray *) bytesArray2 ToTargetHostName: (NSString *)targetHostName WithPort: (int) port 96 | andInterval: (long) interval 97 | { 98 | return [self sendDataWithBytesArray2:bytesArray2 Offset:0 Count:[bytesArray2 count] ToTargetHostName:targetHostName WithPort:port andInterval:interval]; 99 | } 100 | 101 | - (void) sendDataWithBytesArray2: (NSArray *) bytesArray2 Offset: (NSUInteger) offset Count: (NSUInteger) count ToTargetHostName: (NSString *)targetHostName WithPort: (int) port 102 | andInterval: (long) interval 103 | { 104 | // check data is valid 105 | if (nil == bytesArray2 || 0 == [bytesArray2 count]) 106 | { 107 | if (DEBUG_ON) 108 | { 109 | perror("client: data is null or data's length equals 0, so sendData fail\n"); 110 | } 111 | [self close]; 112 | return; 113 | } 114 | // init socket parameters 115 | bool isBroadcast = [targetHostName isEqualToString:@"255.255.255.255"]; 116 | socklen_t addr_len; 117 | struct sockaddr_in target_addr; 118 | memset(&target_addr, 0, sizeof(target_addr)); 119 | target_addr.sin_family = AF_INET; 120 | target_addr.sin_addr.s_addr = inet_addr([targetHostName cStringUsingEncoding:NSASCIIStringEncoding]); 121 | target_addr.sin_port = htons(port); 122 | addr_len = sizeof(target_addr); 123 | if (isBroadcast) { 124 | const int opt = 1; 125 | // set whether the socket is broadcast or not 126 | if (setsockopt(self._sck_fd,SOL_SOCKET,SO_BROADCAST,(char *)&opt, sizeof(opt)) < 0) 127 | { 128 | if (DEBUG_ON) 129 | { 130 | perror("client: setsockopt SO_BROADCAST fail, but just ignore it\n"); 131 | } 132 | // for the Ap will make some troubles when the phone send too many UDP packets, 133 | // but we don't expect the UDP packet received by others, so just ignore it 134 | } 135 | } 136 | // send data gotten from the array 137 | for (NSUInteger i = offset; !self._isStop && i < offset + count; i++) { 138 | // get data 139 | NSData* data = [bytesArray2 objectAtIndex:i]; 140 | NSUInteger dataLen = [data length]; 141 | if (0 == dataLen) 142 | { 143 | continue; 144 | } 145 | Byte bytes[dataLen]; 146 | [data getBytes:bytes length:dataLen]; 147 | // send data 148 | if (sendto(self._sck_fd, bytes, dataLen, 0, (struct sockaddr*)&target_addr, addr_len) < 0) 149 | { 150 | if (DEBUG_ON) 151 | { 152 | perror("client: sendto fail, but just ignore it\n"); 153 | } 154 | // for the Ap will make some troubles when the phone send too many UDP packets, 155 | // but we don't expect the UDP packet received by others, so just ignore it 156 | } 157 | // sleep interval 158 | usleep((useconds_t)(interval*1000)); 159 | } 160 | // check whether the client is stop 161 | if (self._isStop) { 162 | [self close]; 163 | } 164 | } 165 | 166 | @end 167 | -------------------------------------------------------------------------------- /src/PandoSdk/esptouch/ESPUDPSocketServer.h: -------------------------------------------------------------------------------- 1 | // 2 | // ESPUDPSocketServer.h 3 | // EspTouchDemo 4 | // 5 | // Created by 白 桦 on 4/13/15. 6 | // Copyright (c) 2015 白 桦. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | #define BUFFER_SIZE 64 12 | 13 | @interface ESPUDPSocketServer : NSObject 14 | { 15 | @private 16 | Byte _buffer[BUFFER_SIZE]; 17 | } 18 | 19 | - (void) close; 20 | 21 | - (void) interrupt; 22 | 23 | /** 24 | * Set the socket timeout in milliseconds 25 | * 26 | * @param timeout 27 | * the timeout in milliseconds or 0 for no timeout. 28 | * @return true whether the timeout is set suc 29 | */ 30 | - (void) setSocketTimeout: (int) timeout; 31 | 32 | /** 33 | * Receive one byte from the port 34 | * 35 | * @return one byte receive from the port or UINT8_MAX(it impossible receive it from the socket) 36 | */ 37 | - (Byte) receiveOneByte; 38 | 39 | - (NSData *) receiveSpecLenBytes: (int)len; 40 | 41 | - (id) initWithPort: (int) port AndSocketTimeout: (int) socketTimeout; 42 | 43 | @end 44 | -------------------------------------------------------------------------------- /src/PandoSdk/esptouch/ESPUDPSocketServer.m: -------------------------------------------------------------------------------- 1 | // 2 | // ESPUDPSocketServer.m 3 | // EspTouchDemo 4 | // 5 | // Created by 白 桦 on 4/13/15. 6 | // Copyright (c) 2015 白 桦. All rights reserved. 7 | // 8 | 9 | #import "ESPUDPSocketServer.h" 10 | #include 11 | #include 12 | #include 13 | #include 14 | #include "ESPTouchTask.h" 15 | 16 | @interface ESPUDPSocketServer () 17 | 18 | @property(nonatomic,assign) int _sck_fd; 19 | @property(nonatomic,assign) int _port; 20 | // it is used to check whether the socket is closed already to prevent close more than once. 21 | // especially, when you close the socket second time, it is created just now, it will crash. 22 | // 23 | // // suppose fd1 = 4, fd1 belong to obj1 24 | // e.g. int fd1 = socket(AF_INET,SOCK_DRAM,0); 25 | // close(fd1); 26 | // 27 | // // suppose fd2 = 4 as well, fd2 belong to obj2 28 | // int fd2 = socket(AF_INET,SOCK_DRAM,0); 29 | // 30 | // // obj1's dealloc() is called by system, so 31 | // close(fd1); 32 | // 33 | // // Amazing!!! at the moment, fd2 is close by others 34 | // 35 | @property(nonatomic,assign) volatile bool _isClosed; 36 | // it is used to lock the close method 37 | @property(nonatomic,strong) volatile NSLock *_lock; 38 | 39 | @end 40 | 41 | @implementation ESPUDPSocketServer 42 | 43 | - (id) initWithPort: (int) port AndSocketTimeout: (int) socketTimeout 44 | { 45 | self = [super init]; 46 | if (self) 47 | { 48 | // create locl 49 | self._lock = [[NSLock alloc]init]; 50 | // create socket 51 | self._isClosed = NO; 52 | self._sck_fd = socket(AF_INET,SOCK_DGRAM,0); 53 | if (DEBUG_ON) 54 | { 55 | NSLog(@"##########################server init(): _sck_fd=%d", self._sck_fd); 56 | } 57 | if (self._sck_fd < 0) 58 | { 59 | if (DEBUG_ON) 60 | { 61 | perror("server: _skd_fd init() fail\n"); 62 | } 63 | return nil; 64 | } 65 | // init socket params 66 | struct sockaddr_in server_addr; 67 | socklen_t addr_len; 68 | memset(&server_addr, 0, sizeof(server_addr)); 69 | server_addr.sin_family = AF_INET; 70 | server_addr.sin_port = htons(port); 71 | server_addr.sin_addr.s_addr = INADDR_ANY; 72 | addr_len = sizeof(server_addr); 73 | // set broadcast 74 | const int opt = 1; 75 | if (setsockopt(self._sck_fd,SOL_SOCKET,SO_BROADCAST,(char *)&opt, sizeof(opt)) < 0) 76 | { 77 | if (DEBUG_ON) 78 | { 79 | perror("server init(): setsockopt SO_BROADCAST fail\n"); 80 | } 81 | [self close]; 82 | return nil; 83 | } 84 | // set timeout 85 | [self setSocketTimeout:socketTimeout]; 86 | // bind 87 | if (bind(self._sck_fd, (struct sockaddr*)&server_addr, addr_len) < 0) 88 | { 89 | if (DEBUG_ON) 90 | { 91 | perror("server init(): bind fail\n"); 92 | } 93 | [self close]; 94 | return nil; 95 | } 96 | } 97 | return self; 98 | } 99 | 100 | // make sure the socket will be closed sometime 101 | - (void)dealloc 102 | { 103 | if (DEBUG_ON) 104 | { 105 | NSLog(@"###################server dealloc()"); 106 | } 107 | [self close]; 108 | } 109 | 110 | - (void) close 111 | { 112 | [self._lock lock]; 113 | if (!self._isClosed) 114 | { 115 | if (DEBUG_ON) 116 | { 117 | NSLog(@"###################server close() fd=%d",self._sck_fd); 118 | } 119 | close(self._sck_fd); 120 | self._isClosed = true; 121 | } 122 | [self._lock unlock]; 123 | } 124 | 125 | - (void) interrupt 126 | { 127 | [self close]; 128 | } 129 | 130 | - (void) setSocketTimeout: (int) timeout 131 | { 132 | struct timeval tv; 133 | tv.tv_sec = timeout/1000; 134 | tv.tv_usec = timeout%1000*1000; 135 | if (setsockopt(self._sck_fd,SOL_SOCKET,SO_RCVTIMEO,(char *)&tv, sizeof(tv)) < 0) 136 | { 137 | if (DEBUG_ON) 138 | { 139 | perror("server: setsockopt SO_RCVTIMEO fail\n"); 140 | } 141 | } 142 | } 143 | 144 | - (Byte) receiveOneByte 145 | { 146 | ssize_t recNumber = recv(self._sck_fd, _buffer, BUFFER_SIZE, 0); 147 | if (recNumber > 0) 148 | { 149 | return _buffer[0]; 150 | } 151 | else if(recNumber == 0) 152 | { 153 | if (DEBUG_ON) 154 | { 155 | perror("server: receiveOneByte socket is closed by the other\n"); 156 | } 157 | } 158 | else 159 | { 160 | if (DEBUG_ON) 161 | { 162 | perror("server: receiveOneByte fail\n"); 163 | } 164 | } 165 | return UINT8_MAX; 166 | } 167 | 168 | - (NSData *) receiveSpecLenBytes: (int)len 169 | { 170 | ssize_t recNumber = recv(self._sck_fd, _buffer, BUFFER_SIZE, 0); 171 | if (recNumber==len) 172 | { 173 | NSData *data = [[NSData alloc]initWithBytes:_buffer length:recNumber]; 174 | return data; 175 | } 176 | else if(recNumber==0) 177 | { 178 | if (DEBUG_ON) 179 | { 180 | perror("server: receiveOneByte socket is closed by the other\n"); 181 | } 182 | } 183 | else if(recNumber<0) 184 | { 185 | if (DEBUG_ON) 186 | { 187 | perror("server: receiveOneByte fail\n"); 188 | } 189 | } 190 | else 191 | { 192 | // receive rubbish message, just ignore it 193 | } 194 | return nil; 195 | } 196 | 197 | @end 198 | -------------------------------------------------------------------------------- /src/PandoSdk/esptouch/ESP_ByteUtil.h: -------------------------------------------------------------------------------- 1 | // 2 | // ESP_ByteUtil.h 3 | // EspTouchDemo 4 | // 5 | // Created by 白 桦 on 4/7/15. 6 | // Copyright (c) 2015 白 桦. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface ESP_ByteUtil : NSObject 12 | 13 | #define ESPTOUCH_NSStringEncoding NSUTF8StringEncoding 14 | 15 | /** 16 | * Convert uint8 into char( we treat char as uint8) 17 | * 18 | * @param uint8 19 | * the unit8 to be converted 20 | * @return the byte of the unint8 21 | */ 22 | + (Byte) convertUint8toByte:(char) uint8; 23 | 24 | /** 25 | * Convert char into uint8( we treat char as uint8 ) 26 | * 27 | * @param b 28 | * the byte to be converted 29 | * @return the UInt8(uint8) 30 | */ 31 | + (UInt8) convertByte2Uint8:(Byte) b; 32 | 33 | /** 34 | * Convert byte to Hex String 35 | * 36 | * @param b 37 | * the byte to be converted 38 | * @return the Hex String 39 | */ 40 | + (NSString *) convertByte2HexString:(Byte) b; 41 | 42 | /** 43 | * Split uint8 to 2 bytes of high byte and low byte. e.g. 20 = 0x14 should 44 | * be split to [0x01,0x04] 0x01 is high byte and 0x04 is low byte 45 | * 46 | * @param uint8 47 | * the char(uint8) 48 | * @return the high and low bytes be split, byte[0] is high and byte[1] is 49 | * low 50 | */ 51 | + (NSData *) splitUint8To2Bytes: (UInt8) uint8; 52 | 53 | /** 54 | * Combine 2 bytes (high byte and low byte) to one whole byte 55 | * 56 | * @param high 57 | * the high byte 58 | * @param low 59 | * the low byte 60 | * @return the whole byte 61 | */ 62 | + (Byte) combine2bytesToOneWithHigh: (Byte) high andLow: (Byte) low; 63 | 64 | /** 65 | * Combine 2 bytes (high byte and low byte) to one UInt16 66 | * 67 | * @param high 68 | * the high byte 69 | * @param low 70 | * the low byte 71 | * @return the UInt8 72 | */ 73 | + (UInt16) combine2bytesToU16WithHigh: (Byte) high andLow: (Byte) low; 74 | 75 | /** 76 | * Generate the random byte to be sent 77 | * 78 | * @return the random byte 79 | */ 80 | + (Byte) randomByte; 81 | 82 | /** 83 | * Generate the random byte to be sent 84 | * 85 | * @param len 86 | * the len presented by u8 87 | * @return the byte[] to be sent 88 | */ 89 | + (NSData *) randomBytes: (UInt8) len; 90 | 91 | + (NSData *) genSpecBytesWithU16: (UInt16) len; 92 | 93 | /** 94 | * Generate the specific byte to be sent 95 | * @param len 96 | * the len presented by byte 97 | * @return the byte[] 98 | */ 99 | + (NSData *) genSpecBytesWithU8:(Byte) len; 100 | 101 | + (NSString *) parseBssid:(Byte[]) bssidBytes Offset: (int) offset Count: (int) count; 102 | 103 | /** 104 | * parse "24,-2,52,-102,-93,-60" to "18,fe,34,9a,a3,c4" parse the bssid from 105 | * hex to String 106 | * 107 | * @param bssidBytes 108 | * the hex bytes bssid, e.g. {24,-2,52,-102,-93,-60} 109 | * @param len 110 | * the len of bssidBytes 111 | * @return the String of bssid, e.g. 18fe349aa3c4 112 | */ 113 | + (NSString *) parseBssid:(Byte[]) bssidBytes Len: (int) len; 114 | 115 | /** 116 | * @param string the string to be used 117 | * @return the Byte[] of string according to ESPTOUCH_NSStringEncoding 118 | */ 119 | + (NSData *) getBytesByNSString: (NSString *)string; 120 | 121 | /** 122 | * get hex string transformed by data 123 | * @param data the data to be transformed 124 | * @return the hex String transformed by data 125 | */ 126 | + (NSString *) getHexStringByData: (NSData *)data; 127 | 128 | @end 129 | -------------------------------------------------------------------------------- /src/PandoSdk/esptouch/ESP_ByteUtil.m: -------------------------------------------------------------------------------- 1 | // 2 | // ESP_ByteUtil.m 3 | // EspTouchDemo 4 | // 5 | // Created by 白 桦 on 4/7/15. 6 | // Copyright (c) 2015 白 桦. All rights reserved. 7 | // 8 | 9 | #import "ESP_ByteUtil.h" 10 | 11 | @implementation ESP_ByteUtil 12 | 13 | + (Byte) convertUint8toByte:(char) uint8 14 | { 15 | return (Byte)uint8; 16 | } 17 | 18 | + (UInt8) convertByte2Uint8:(Byte) b 19 | { 20 | return (UInt8) (b & 0xff); 21 | } 22 | 23 | + (NSString *) convertByte2HexString:(Byte) b 24 | { 25 | UInt8 u8 = [self convertByte2Uint8:b]; 26 | return [NSString stringWithFormat:@"%x",u8]; 27 | } 28 | 29 | + (unsigned int)intFromHexString:(NSString *) hexStr 30 | { 31 | unsigned int hexInt = 0; 32 | 33 | // Create scanner 34 | NSScanner *scanner = [NSScanner scannerWithString:hexStr]; 35 | 36 | // Tell scanner to skip the # character 37 | // [scanner setCharactersToBeSkipped:[NSCharacterSet characterSetWithCharactersInString:@"#"]]; 38 | 39 | // Scan hex value 40 | [scanner scanHexInt:&hexInt]; 41 | 42 | return hexInt; 43 | } 44 | 45 | + (NSData *) splitUint8To2Bytes: (UInt8) uint8 46 | { 47 | NSString *hexString = [NSString stringWithFormat:@"%x",uint8]; 48 | Byte low; 49 | Byte high; 50 | if (hexString.length > 1) 51 | { 52 | high = [self intFromHexString:[hexString substringWithRange:NSMakeRange(0, 1)]]; 53 | low =[self intFromHexString:[hexString substringWithRange:NSMakeRange(1, 1)]]; 54 | } 55 | else 56 | { 57 | high = 0; 58 | low = [self intFromHexString:[hexString substringWithRange:NSMakeRange(0, 1)]]; 59 | } 60 | 61 | Byte bytes[] = { high, low }; 62 | NSData *data = [[NSData alloc] initWithBytes:bytes length:2]; 63 | return data; 64 | } 65 | 66 | + (Byte) combine2bytesToOneWithHigh: (Byte) high andLow: (Byte) low 67 | { 68 | return (Byte) (high << 4 | low); 69 | } 70 | 71 | + (UInt16) combine2bytesToU16WithHigh: (Byte) high andLow: (Byte) low 72 | { 73 | UInt8 highU8 = [self convertByte2Uint8:high]; 74 | UInt8 lowU8 = [self convertByte2Uint8:low]; 75 | return (highU8 << 8 | lowU8); 76 | } 77 | 78 | + (Byte) randomByte 79 | { 80 | return arc4random() % 256; 81 | } 82 | 83 | + (NSData *) randomBytes: (UInt8) len 84 | { 85 | Byte bytes[len]; 86 | for (int i = 0; i < len; i++) { 87 | bytes[i] = [self randomByte]; 88 | } 89 | NSData *data = [[NSData alloc]initWithBytes:bytes length:len]; 90 | return data; 91 | } 92 | 93 | + (NSData *) genSpecBytesWithU16:(UInt16)len 94 | { 95 | Byte bytes[len]; 96 | for (int i = 0; i < len; i++) { 97 | bytes[i] = '1'; 98 | } 99 | NSData *data = [[NSData alloc]initWithBytes:bytes length:len]; 100 | return data; 101 | } 102 | 103 | + (NSData *) genSpecBytesWithU8:(Byte) len 104 | { 105 | UInt8 u8 = [self convertByte2Uint8:len]; 106 | return [self genSpecBytesWithU16:u8]; 107 | } 108 | 109 | + (NSString *) parseBssid:(Byte[]) bssidBytes Offset: (int) offset Count: (int) count 110 | { 111 | Byte bytes[count]; 112 | for (int i = 0; i < count; i++ ) 113 | { 114 | bytes[i] = bssidBytes[i + offset]; 115 | } 116 | return [self parseBssid:bytes Len:count]; 117 | } 118 | 119 | + (NSString *) parseBssid:(Byte[]) bssidBytes Len:(int)len 120 | { 121 | NSMutableString *mStr = [[NSMutableString alloc]init]; 122 | int k; 123 | NSString* hexK; 124 | NSString* str; 125 | for (int i = 0; i < len; i++) 126 | { 127 | k = 0xff & bssidBytes[i]; 128 | hexK = [NSString stringWithFormat:@"%x", k]; 129 | str = ((k < 16) ? ([NSString stringWithFormat:@"0%@",hexK ]) : (hexK)); 130 | [mStr appendString:str]; 131 | } 132 | return mStr; 133 | } 134 | 135 | + (NSData *) getBytesByNSString: (NSString *)string 136 | { 137 | NSUInteger numberOfBytes = [string lengthOfBytesUsingEncoding:ESPTOUCH_NSStringEncoding]; 138 | Byte bytes[numberOfBytes]; 139 | NSRange range = NSMakeRange(0, numberOfBytes); 140 | [string getBytes:bytes maxLength:numberOfBytes usedLength:nil encoding:ESPTOUCH_NSStringEncoding options:0 range:range remainingRange:NULL]; 141 | NSData *data = [[NSData alloc]initWithBytes:bytes length:numberOfBytes]; 142 | return data; 143 | } 144 | 145 | + (NSString *) getHexStringByData:(NSData *)data 146 | { 147 | NSMutableString* mStr = [[NSMutableString alloc]init]; 148 | NSUInteger totalLen = [data length]; 149 | Byte bytes[totalLen]; 150 | [data getBytes:&bytes length:totalLen]; 151 | for (int i = 0; i < totalLen; i++) 152 | { 153 | NSString *hexString = [[NSString alloc]initWithFormat:@"0x%.2x ",bytes[i]]; 154 | [mStr appendString:hexString]; 155 | } 156 | return mStr; 157 | } 158 | 159 | @end 160 | -------------------------------------------------------------------------------- /src/PandoSdk/esptouch/ESP_CRC8.h: -------------------------------------------------------------------------------- 1 | // 2 | // ESP_CRC8.h 3 | // EspTouchDemo 4 | // 5 | // Created by 白 桦 on 3/23/15. 6 | // Copyright (c) 2015 白 桦. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | #define CRC_POLYNOM 0x8c 12 | 13 | #define CRC_INITIAL 0x00 14 | 15 | // the interface is copied from the interface Checksum from Java 16 | @interface ESP_CRC8 : NSObject 17 | 18 | /** 19 | * Returns the current calculated checksum value. 20 | * 21 | * @return the checksum. 22 | */ 23 | - (long)getValue; 24 | 25 | /** 26 | * Resets the checksum value applied before beginning calculations on a new 27 | * stream of data. 28 | */ 29 | - (void)reset; 30 | 31 | /** 32 | * Updates the checksum with the given bytes. 33 | * 34 | * @param buf 35 | * the byte array from which to read the bytes. 36 | * @param off 37 | * the initial position in {@code buf} to read the bytes from. 38 | * @param nbytes 39 | * the number of bytes to read from {@code buf}. 40 | */ 41 | - (void)updateWithBuf:(Byte[])buf Off:(int)off Nbytes:(int)nbytes; 42 | 43 | /** 44 | * Updates the checksum with the given bytes. 45 | * 46 | * @param buf 47 | * the byte array from which to read the bytes. 48 | * @param nbytes 49 | * the number of bytes to read from {@code buf}. 50 | */ 51 | - (void)updateWithBuf:(Byte [])buf Nbytes:(int)nbytes; 52 | 53 | /** 54 | * Updates the checksum value with the given byte. 55 | * 56 | * @param val 57 | * the byte to update the checksum with. 58 | */ 59 | - (void)updateWithValue:(int)value; 60 | 61 | @end 62 | -------------------------------------------------------------------------------- /src/PandoSdk/esptouch/ESP_CRC8.m: -------------------------------------------------------------------------------- 1 | // 2 | // ESP_CRC8.m 3 | // EspTouchDemo 4 | // 5 | // Created by 白 桦 on 3/23/15. 6 | // Copyright (c) 2015 白 桦. All rights reserved. 7 | // 8 | 9 | #import "ESP_CRC8.h" 10 | 11 | @implementation ESP_CRC8 12 | 13 | static ushort crcTable[256]; 14 | 15 | NSNumber *_init; 16 | NSNumber *_value; 17 | 18 | +(void) initialize 19 | { 20 | for (ushort dividend=0; dividend < 256; dividend++) 21 | { 22 | ushort remainder = dividend; 23 | for (ushort bit = 0; bit < 8; ++bit) 24 | { 25 | if ((remainder & 0x01) != 0) 26 | { 27 | remainder = (remainder >> 1) ^ CRC_POLYNOM; 28 | } 29 | else 30 | { 31 | remainder >>= 1; 32 | } 33 | crcTable[dividend] = (ushort) remainder; 34 | } 35 | } 36 | } 37 | 38 | -(id) init 39 | { 40 | if(self = [super init]) 41 | { 42 | _init = [[NSNumber alloc]initWithInt:CRC_INITIAL]; 43 | _value = [[NSNumber alloc] initWithInt:CRC_INITIAL]; 44 | } 45 | return self; 46 | } 47 | 48 | - (long)getValue 49 | { 50 | return [_value unsignedShortValue] & 0xff; 51 | } 52 | 53 | - (void)reset 54 | { 55 | _value = _init; 56 | } 57 | 58 | - (void)updateWithBuf:(Byte[])buf Off:(int)off Nbytes:(int)nbytes 59 | { 60 | for (int i = 0; i < nbytes; i++) 61 | { 62 | int data = buf[off + i] ^ _value.intValue; 63 | int value = crcTable[data & 0xff] ^ (_value.intValue << 8); 64 | _value = [NSNumber numberWithInt:value]; 65 | } 66 | } 67 | 68 | - (void)updateWithBuf:(Byte [])buf Nbytes:(int)nbytes 69 | { 70 | [self updateWithBuf:buf Off:0 Nbytes:nbytes]; 71 | } 72 | 73 | 74 | - (void)updateWithValue:(int)value 75 | { 76 | Byte b[1] = { (Byte)value }; 77 | [self updateWithBuf:b Nbytes:1]; 78 | } 79 | 80 | @end 81 | -------------------------------------------------------------------------------- /src/PandoSdk/esptouch/ESP_NetUtil.h: -------------------------------------------------------------------------------- 1 | // 2 | // ESPNetUtil.h 3 | // EspTouchDemo 4 | // 5 | // Created by 白 桦 on 5/15/15. 6 | // Copyright (c) 2015 白 桦. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface ESP_NetUtil : NSObject 12 | 13 | /** 14 | * get the local ip address by IOS System 15 | * 16 | */ 17 | + (NSData *) getLocalInetAddress; 18 | 19 | /** 20 | * parse InetAddress 21 | */ 22 | + (NSData *) parseInetAddrByData: (NSData *) inetAddrData andOffset: (int) offset andCount: (int) count; 23 | 24 | /** 25 | * descrpion inetAddrData for print pretty 26 | */ 27 | + (NSString *) descriptionInetAddrByData: (NSData *) inetAddrData; 28 | 29 | /** 30 | * parse bssid 31 | * 32 | * @param bssid the bssid 33 | * @return byte converted from bssid 34 | */ 35 | + (NSData *) parseBssid2bytes: (NSString *) bssid; 36 | 37 | @end 38 | -------------------------------------------------------------------------------- /src/PandoSdk/esptouch/ESP_NetUtil.m: -------------------------------------------------------------------------------- 1 | // 2 | // ESPNetUtil.m 3 | // EspTouchDemo 4 | // 5 | // Created by 白 桦 on 5/15/15. 6 | // Copyright (c) 2015 白 桦. All rights reserved. 7 | // 8 | 9 | #import "ESP_NetUtil.h" 10 | #include "IPAddress.h" 11 | #include "ESP_ByteUtil.h" 12 | 13 | // only support ipV4 at the moment 14 | #define IP_LEN 4 15 | 16 | @implementation ESP_NetUtil 17 | 18 | + (NSData *) getLocalInetAddress 19 | { 20 | InitAddresses(); 21 | GetIPAddresses(); 22 | GetHWAddresses(); 23 | NSData *localInetAddrData = nil; 24 | Byte localIpBytes[IP_LEN]; 25 | for (int i=0; i> 0; 38 | localIpBytes[1] = (theAddr & 0xff00) >> 8; 39 | localIpBytes[2] = (theAddr & 0xff0000) >> 16; 40 | localIpBytes[3] = (theAddr & 0xff000000) >> 24; 41 | // NSLog(@"ESP_NetUtil:: %d.%d.%d.%d",localIpBytes[0],localIpBytes[1],localIpBytes[2],localIpBytes[3]); 42 | 43 | // if (theAddr != 0) break; 44 | // NSLog(@"ESP_NetUtil:: Name: %s MAC: %s IP: %s\n", if_names[i], hw_addrs[i], ip_names[i]); 45 | } 46 | 47 | localInetAddrData = [[NSData alloc]initWithBytes:localIpBytes length:IP_LEN]; 48 | 49 | FreeAddresses(); 50 | 51 | Byte byte1 = 0; 52 | Byte byte2 = 0; 53 | Byte byte3 = 0; 54 | Byte byte4 = 0; 55 | 56 | [localInetAddrData getBytes:&byte1 range:NSMakeRange(0, 1)]; 57 | [localInetAddrData getBytes:&byte2 range:NSMakeRange(1, 1)]; 58 | [localInetAddrData getBytes:&byte3 range:NSMakeRange(2, 1)]; 59 | [localInetAddrData getBytes:&byte4 range:NSMakeRange(3, 1)]; 60 | 61 | //NSLog(@"ESP_NetUtil:: %d.%d.%d.%d", byte1,byte2,byte3,byte4); 62 | 63 | return localInetAddrData; 64 | } 65 | 66 | + (NSData *) parseInetAddrByData: (NSData *) inetAddrData andOffset: (int) offset andCount: (int) count 67 | { 68 | return [inetAddrData subdataWithRange:NSMakeRange(offset, count)]; 69 | } 70 | 71 | + (NSString *) descriptionInetAddrByData: (NSData *) inetAddrData 72 | { 73 | Byte inetAddrBytes[IP_LEN]; 74 | [inetAddrData getBytes:inetAddrBytes length:IP_LEN]; 75 | // hard coding 76 | return [NSString stringWithFormat:@"%d.%d.%d.%d",inetAddrBytes[0],inetAddrBytes[1],inetAddrBytes[2],inetAddrBytes[3]]; 77 | } 78 | 79 | + (NSData *) parseBssid2bytes: (NSString *) bssid 80 | { 81 | NSArray *bssidArray = [bssid componentsSeparatedByString:@":"]; 82 | NSInteger size = [bssidArray count]; 83 | Byte bssidBytes[size]; 84 | for (NSInteger i = 0; i < size; i++) { 85 | NSString *bssidStr = [bssidArray objectAtIndex:i]; 86 | bssidBytes[i] = strtoul([bssidStr UTF8String], 0, 16); 87 | } 88 | return [[NSData alloc]initWithBytes:bssidBytes length:size]; 89 | } 90 | 91 | @end 92 | -------------------------------------------------------------------------------- /src/PandoSdk/esptouch/IPAddress.c: -------------------------------------------------------------------------------- 1 | // 2 | // IPAddress.c 3 | // LocalIpDemo 4 | // 5 | // Created by 白 桦 on 5/11/15. 6 | // Copyright (c) 2015 白 桦. All rights reserved. 7 | // 8 | #include 9 | #include 10 | #include 11 | #include 12 | #include 13 | #include 14 | #include 15 | #include 16 | #include 17 | #include 18 | #include 19 | #include 20 | #include 21 | #include 22 | #include 23 | #include "IPAddress.h" 24 | 25 | #define min(a,b) ((a) < (b) ? (a) : (b)) 26 | #define max(a,b) ((a) > (b) ? (a) : (b)) 27 | 28 | #define BUFFERSIZE 4000 29 | 30 | char *if_names[MAXADDRS]; 31 | char *ip_names[MAXADDRS]; 32 | char *hw_addrs[MAXADDRS]; 33 | unsigned long ip_addrs[MAXADDRS]; 34 | 35 | static int nextAddr = 0; 36 | 37 | void InitAddresses() 38 | { 39 | int i; 40 | for (i=0; iifr_addr.sa_len); 101 | ptr += sizeof(ifr->ifr_name) + len; // for next one in buffer 102 | 103 | if (ifr->ifr_addr.sa_family != AF_INET) 104 | { 105 | continue; // ignore if not desired address family 106 | } 107 | 108 | if ((cptr = (char *)strchr(ifr->ifr_name, ':')) != NULL) 109 | { 110 | *cptr = 0; // replace colon will null 111 | } 112 | 113 | if (strncmp(lastname, ifr->ifr_name, IFNAMSIZ) == 0) 114 | { 115 | continue; /* already processed this interface */ 116 | } 117 | 118 | memcpy(lastname, ifr->ifr_name, IFNAMSIZ); 119 | 120 | ifrcopy = *ifr; 121 | ioctl(sockfd, SIOCGIFFLAGS, &ifrcopy); 122 | flags = ifrcopy.ifr_flags; 123 | if ((flags & IFF_UP) == 0) 124 | { 125 | continue; // ignore if interface not up 126 | } 127 | 128 | if_names[nextAddr] = (char *)malloc(strlen(ifr->ifr_name)+1); 129 | if (if_names[nextAddr] == NULL) 130 | { 131 | return; 132 | } 133 | strcpy(if_names[nextAddr], ifr->ifr_name); 134 | 135 | sin = (struct sockaddr_in *)&ifr->ifr_addr; 136 | strcpy(temp, inet_ntoa(sin->sin_addr)); 137 | 138 | ip_names[nextAddr] = (char *)malloc(strlen(temp)+1); 139 | if (ip_names[nextAddr] == NULL) 140 | { 141 | return; 142 | } 143 | strcpy(ip_names[nextAddr], temp); 144 | 145 | ip_addrs[nextAddr] = sin->sin_addr.s_addr; 146 | 147 | ++nextAddr; 148 | } 149 | 150 | close(sockfd); 151 | } 152 | 153 | void GetHWAddresses() 154 | { 155 | struct ifconf ifc; 156 | struct ifreq *ifr; 157 | int i, sockfd; 158 | char buffer[BUFFERSIZE], *cp, *cplim; 159 | char temp[80]; 160 | 161 | for (i=0; iifr_addr.sa_family == AF_LINK) 191 | { 192 | struct sockaddr_dl *sdl = (struct sockaddr_dl *)&ifr->ifr_addr; 193 | int a,b,c,d,e,f; 194 | int i; 195 | 196 | strcpy(temp, (char *)ether_ntoa((const struct ether_addr *)LLADDR(sdl))); 197 | sscanf(temp, "%x:%x:%x:%x:%x:%x", &a, &b, &c, &d, &e, &f); 198 | sprintf(temp, "%02X:%02X:%02X:%02X:%02X:%02X",a,b,c,d,e,f); 199 | 200 | for (i=0; iifr_name, if_names[i]) == 0)) 203 | { 204 | if (hw_addrs[i] == NULL) 205 | { 206 | hw_addrs[i] = (char *)malloc(strlen(temp)+1); 207 | strcpy(hw_addrs[i], temp); 208 | break; 209 | } 210 | } 211 | } 212 | } 213 | cp += sizeof(ifr->ifr_name) + max(sizeof(ifr->ifr_addr), ifr->ifr_addr.sa_len); 214 | } 215 | close(sockfd); 216 | } 217 | -------------------------------------------------------------------------------- /src/PandoSdk/esptouch/IPAddress.h: -------------------------------------------------------------------------------- 1 | // 2 | // IPAddress.h 3 | // LocalIpDemo 4 | // 5 | // Created by 白 桦 on 5/11/15. 6 | // Copyright (c) 2015 白 桦. All rights reserved. 7 | // 8 | 9 | #ifndef LocalIpDemo_IPAddress_h 10 | #define LocalIpDemo_IPAddress_h 11 | 12 | #define MAXADDRS 32 13 | 14 | extern char *if_names[MAXADDRS]; 15 | extern char *ip_names[MAXADDRS]; 16 | extern char *hw_addrs[MAXADDRS]; 17 | extern unsigned long ip_addrs[MAXADDRS]; 18 | 19 | // Function prototypes 20 | 21 | void InitAddresses(); 22 | void FreeAddresses(); 23 | void GetIPAddresses(); 24 | void GetHWAddresses(); 25 | 26 | #endif 27 | -------------------------------------------------------------------------------- /src/Products/PandoSdk.framework/Headers/PandoSdk.h: -------------------------------------------------------------------------------- 1 | // 2 | // PandoSdk.h 3 | // PandoSdk version 0.1.0 4 | // 5 | // Created by liming_llm on 15/3/26. 6 | // Copyright (c) 2015年 liming_llm. All rights reserved. 7 | // 8 | #import 9 | 10 | @protocol PandoSdkDelegate; 11 | 12 | @interface PandoSdk : NSObject 13 | 14 | 15 | /*! 16 | * @method initWithDelegate: 17 | * 18 | * @param delegate The delegate that will receive PandoSdk events. 19 | * 20 | * @discussion The initialization call. 21 | */ 22 | - (instancetype)initWithDelegate:(id)delegate; 23 | 24 | /*! 25 | * @method configDeviceToWiFi:password:byMode: 26 | * 27 | * @param ssid The WiFi ssid you want you device to connect to. 28 | * @param password The password of the specified WiFi. 29 | * @param mode The different config method. 30 | * 31 | * @discussion Configure device with the specified WiFi ssid & password by different mode. 32 | */ 33 | - (void)configDeviceToWiFi:(NSString *)ssid password:(NSString *)password byMode:(NSString *)mode; 34 | 35 | /*! 36 | * @method stopConfig 37 | * 38 | * @discussion Stop to configure device while configuring. 39 | */ 40 | - (void)stopConfig; 41 | 42 | 43 | /*! 44 | * @method isDebugOn: 45 | * 46 | * @param isDebugOn Set YES to print debug info. 47 | * 48 | * @discussion Set YES to print debug info. 49 | */ 50 | - (void)isDebugOn:(BOOL)isDebugOn; 51 | 52 | @end 53 | 54 | 55 | 56 | /*! 57 | * @protocol PandoSdkDelegate 58 | * 59 | * @discussion The delegate of a PandoSdk object must adopt the PandoSdkDelegate protocol. The optional methods provide information about PandoSdk method. 60 | * 61 | */ 62 | @protocol PandoSdkDelegate 63 | 64 | @optional 65 | 66 | /*! 67 | * @method pandoSdk:didConfigDeviceToWiFi:deviceKey:error: 68 | * 69 | * @param pandoSdk The pandoSdk object providing configDeviceToWiFi method. 70 | * @param ssid The WiFi ssid the method configure to. 71 | * @param deviceKey The device key returned from device. 72 | * @param error If an error occurred, the cause of the failure. 73 | * 74 | * @discussion This method is invoked when a pandoSdk object ended configDeviceToWifi method. 75 | */ 76 | - (void)pandoSdk:(PandoSdk *)pandoSdk didConfigDeviceToWiFi:(NSString *)ssid deviceKey:(NSString *)deviceKey error:(NSError *)error; 77 | 78 | /*! 79 | * @method pandoSdk:didStopConfig:error: 80 | * 81 | * @param pandoSdk The pandoSdk object providing stopConfig method. 82 | * @param isStoped 83 | * @param error If an error occurred, the cause of the failure. 84 | * 85 | * @discussion This method is invoked when a pandoSdk object ended stopConfig method. 86 | */ 87 | - (void)pandoSdk:(PandoSdk *)pandoSdk didStopConfig:(BOOL)isStoped error:(NSError *)error; 88 | 89 | 90 | @end 91 | 92 | 93 | 94 | 95 | 96 | -------------------------------------------------------------------------------- /src/Products/PandoSdk.framework/Info.plist: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PandoCloud/pando-ios-sdk/ff00598f25cdb20531070fb54118303d95696b84/src/Products/PandoSdk.framework/Info.plist -------------------------------------------------------------------------------- /src/Products/PandoSdk.framework/Modules/module.modulemap: -------------------------------------------------------------------------------- 1 | framework module PandoSdk { 2 | umbrella header "PandoSdk.h" 3 | 4 | export * 5 | module * { export * } 6 | } 7 | -------------------------------------------------------------------------------- /src/Products/PandoSdk.framework/PandoSdk: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PandoCloud/pando-ios-sdk/ff00598f25cdb20531070fb54118303d95696b84/src/Products/PandoSdk.framework/PandoSdk -------------------------------------------------------------------------------- /src/Products/PandoSdk.framework/_CodeSignature/CodeResources: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | files 6 | 7 | Headers/PandoSdk.h 8 | 9 | NXd2hUfa21saobef48sG6+f5iMA= 10 | 11 | Info.plist 12 | 13 | N5r3wRYtmMJj2UdL+8/9FtuYxlQ= 14 | 15 | Modules/module.modulemap 16 | 17 | 4/QcOovdOYzssKiWeFiMa2JtnVw= 18 | 19 | 20 | files2 21 | 22 | Headers/PandoSdk.h 23 | 24 | NXd2hUfa21saobef48sG6+f5iMA= 25 | 26 | Modules/module.modulemap 27 | 28 | 4/QcOovdOYzssKiWeFiMa2JtnVw= 29 | 30 | 31 | rules 32 | 33 | ^ 34 | 35 | ^.*\.lproj/ 36 | 37 | optional 38 | 39 | weight 40 | 1000 41 | 42 | ^.*\.lproj/locversion.plist$ 43 | 44 | omit 45 | 46 | weight 47 | 1100 48 | 49 | ^version.plist$ 50 | 51 | 52 | rules2 53 | 54 | .*\.dSYM($|/) 55 | 56 | weight 57 | 11 58 | 59 | ^ 60 | 61 | weight 62 | 20 63 | 64 | ^(.*/)?\.DS_Store$ 65 | 66 | omit 67 | 68 | weight 69 | 2000 70 | 71 | ^(Frameworks|SharedFrameworks|PlugIns|Plug-ins|XPCServices|Helpers|MacOS|Library/(Automator|Spotlight|LoginItems))/ 72 | 73 | nested 74 | 75 | weight 76 | 10 77 | 78 | ^.* 79 | 80 | ^.*\.lproj/ 81 | 82 | optional 83 | 84 | weight 85 | 1000 86 | 87 | ^.*\.lproj/locversion.plist$ 88 | 89 | omit 90 | 91 | weight 92 | 1100 93 | 94 | ^Info\.plist$ 95 | 96 | omit 97 | 98 | weight 99 | 20 100 | 101 | ^PkgInfo$ 102 | 103 | omit 104 | 105 | weight 106 | 20 107 | 108 | ^[^/]+$ 109 | 110 | nested 111 | 112 | weight 113 | 10 114 | 115 | ^embedded\.provisionprofile$ 116 | 117 | weight 118 | 20 119 | 120 | ^version\.plist$ 121 | 122 | weight 123 | 20 124 | 125 | 126 | 127 | 128 | -------------------------------------------------------------------------------- /src/Products/PandoSdk_simulator.framework/Headers/PandoSdk.h: -------------------------------------------------------------------------------- 1 | // 2 | // PandoSdk.h 3 | // PandoSdk version 0.1.0 4 | // 5 | // Created by liming_llm on 15/3/26. 6 | // Copyright (c) 2015年 liming_llm. All rights reserved. 7 | // 8 | #import 9 | 10 | @protocol PandoSdkDelegate; 11 | 12 | @interface PandoSdk : NSObject 13 | 14 | 15 | /*! 16 | * @method initWithDelegate: 17 | * 18 | * @param delegate The delegate that will receive PandoSdk events. 19 | * 20 | * @discussion The initialization call. 21 | */ 22 | - (instancetype)initWithDelegate:(id)delegate; 23 | 24 | /*! 25 | * @method configDeviceToWiFi:password:byMode: 26 | * 27 | * @param ssid The WiFi ssid you want you device to connect to. 28 | * @param password The password of the specified WiFi. 29 | * @param mode The different config method. 30 | * 31 | * @discussion Configure device with the specified WiFi ssid & password by different mode. 32 | */ 33 | - (void)configDeviceToWiFi:(NSString *)ssid password:(NSString *)password byMode:(NSString *)mode; 34 | 35 | /*! 36 | * @method stopConfig 37 | * 38 | * @discussion Stop to configure device while configuring. 39 | */ 40 | - (void)stopConfig; 41 | 42 | 43 | /*! 44 | * @method isDebugOn: 45 | * 46 | * @param isDebugOn Set YES to print debug info. 47 | * 48 | * @discussion Set YES to print debug info. 49 | */ 50 | - (void)isDebugOn:(BOOL)isDebugOn; 51 | 52 | @end 53 | 54 | 55 | 56 | /*! 57 | * @protocol PandoSdkDelegate 58 | * 59 | * @discussion The delegate of a PandoSdk object must adopt the PandoSdkDelegate protocol. The optional methods provide information about PandoSdk method. 60 | * 61 | */ 62 | @protocol PandoSdkDelegate 63 | 64 | @optional 65 | 66 | /*! 67 | * @method pandoSdk:didConfigDeviceToWiFi:deviceKey:error: 68 | * 69 | * @param pandoSdk The pandoSdk object providing configDeviceToWiFi method. 70 | * @param ssid The WiFi ssid the method configure to. 71 | * @param deviceKey The device key returned from device. 72 | * @param error If an error occurred, the cause of the failure. 73 | * 74 | * @discussion This method is invoked when a pandoSdk object ended configDeviceToWifi method. 75 | */ 76 | - (void)pandoSdk:(PandoSdk *)pandoSdk didConfigDeviceToWiFi:(NSString *)ssid deviceKey:(NSString *)deviceKey error:(NSError *)error; 77 | 78 | /*! 79 | * @method pandoSdk:didStopConfig:error: 80 | * 81 | * @param pandoSdk The pandoSdk object providing stopConfig method. 82 | * @param isStoped 83 | * @param error If an error occurred, the cause of the failure. 84 | * 85 | * @discussion This method is invoked when a pandoSdk object ended stopConfig method. 86 | */ 87 | - (void)pandoSdk:(PandoSdk *)pandoSdk didStopConfig:(BOOL)isStoped error:(NSError *)error; 88 | 89 | 90 | @end 91 | 92 | 93 | 94 | 95 | 96 | -------------------------------------------------------------------------------- /src/Products/PandoSdk_simulator.framework/Info.plist: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PandoCloud/pando-ios-sdk/ff00598f25cdb20531070fb54118303d95696b84/src/Products/PandoSdk_simulator.framework/Info.plist -------------------------------------------------------------------------------- /src/Products/PandoSdk_simulator.framework/Modules/module.modulemap: -------------------------------------------------------------------------------- 1 | framework module PandoSdk { 2 | umbrella header "PandoSdk.h" 3 | 4 | export * 5 | module * { export * } 6 | } 7 | -------------------------------------------------------------------------------- /src/Products/PandoSdk_simulator.framework/PandoSdk_simulator: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PandoCloud/pando-ios-sdk/ff00598f25cdb20531070fb54118303d95696b84/src/Products/PandoSdk_simulator.framework/PandoSdk_simulator --------------------------------------------------------------------------------