├── .cproject
├── .gitignore
├── .mxproject
├── .project
├── .settings
├── language.settings.xml
└── org.eclipse.cdt.codan.core.prefs
├── Core
├── Inc
│ ├── main.h
│ ├── stm32f1xx_hal_conf.h
│ └── stm32f1xx_it.h
├── Src
│ ├── main.c
│ ├── stm32f1xx_hal_msp.c
│ ├── stm32f1xx_it.c
│ ├── syscalls.c
│ ├── sysmem.c
│ └── system_stm32f1xx.c
└── Startup
│ └── startup_stm32f103rctx.s
├── Drivers
├── CMSIS
│ ├── Device
│ │ └── ST
│ │ │ └── STM32F1xx
│ │ │ └── Include
│ │ │ ├── stm32f103xe.h
│ │ │ ├── stm32f1xx.h
│ │ │ └── system_stm32f1xx.h
│ └── Include
│ │ ├── cmsis_armcc.h
│ │ ├── cmsis_armclang.h
│ │ ├── cmsis_compiler.h
│ │ ├── cmsis_gcc.h
│ │ ├── cmsis_iccarm.h
│ │ ├── cmsis_version.h
│ │ ├── core_armv8mbl.h
│ │ ├── core_armv8mml.h
│ │ ├── core_cm0.h
│ │ ├── core_cm0plus.h
│ │ ├── core_cm1.h
│ │ ├── core_cm23.h
│ │ ├── core_cm3.h
│ │ ├── core_cm33.h
│ │ ├── core_cm4.h
│ │ ├── core_cm7.h
│ │ ├── core_sc000.h
│ │ ├── core_sc300.h
│ │ ├── mpu_armv7.h
│ │ ├── mpu_armv8.h
│ │ └── tz_context.h
├── STM32F1xx_HAL_Driver
│ ├── Inc
│ │ ├── Legacy
│ │ │ └── stm32_hal_legacy.h
│ │ ├── stm32f1xx_hal.h
│ │ ├── stm32f1xx_hal_cortex.h
│ │ ├── stm32f1xx_hal_def.h
│ │ ├── stm32f1xx_hal_dma.h
│ │ ├── stm32f1xx_hal_dma_ex.h
│ │ ├── stm32f1xx_hal_exti.h
│ │ ├── stm32f1xx_hal_flash.h
│ │ ├── stm32f1xx_hal_flash_ex.h
│ │ ├── stm32f1xx_hal_gpio.h
│ │ ├── stm32f1xx_hal_gpio_ex.h
│ │ ├── stm32f1xx_hal_pwr.h
│ │ ├── stm32f1xx_hal_rcc.h
│ │ ├── stm32f1xx_hal_rcc_ex.h
│ │ ├── stm32f1xx_hal_spi.h
│ │ ├── stm32f1xx_hal_tim.h
│ │ ├── stm32f1xx_hal_tim_ex.h
│ │ └── stm32f1xx_hal_uart.h
│ └── Src
│ │ ├── stm32f1xx_hal.c
│ │ ├── stm32f1xx_hal_cortex.c
│ │ ├── stm32f1xx_hal_dma.c
│ │ ├── stm32f1xx_hal_exti.c
│ │ ├── stm32f1xx_hal_flash.c
│ │ ├── stm32f1xx_hal_flash_ex.c
│ │ ├── stm32f1xx_hal_gpio.c
│ │ ├── stm32f1xx_hal_gpio_ex.c
│ │ ├── stm32f1xx_hal_pwr.c
│ │ ├── stm32f1xx_hal_rcc.c
│ │ ├── stm32f1xx_hal_rcc_ex.c
│ │ ├── stm32f1xx_hal_spi.c
│ │ ├── stm32f1xx_hal_tim.c
│ │ ├── stm32f1xx_hal_tim_ex.c
│ │ └── stm32f1xx_hal_uart.c
├── ioLibrary_Driver
│ ├── .gitattributes
│ ├── .gitignore
│ ├── Application
│ │ ├── loopback
│ │ │ ├── loopback.c
│ │ │ └── loopback.h
│ │ └── multicast
│ │ │ ├── multicast.c
│ │ │ └── multicast.h
│ ├── Ethernet
│ │ ├── Socket_APIs_V3.0.3.chm
│ │ ├── W5100
│ │ │ ├── w5100.c
│ │ │ └── w5100.h
│ │ ├── W5100S
│ │ │ ├── w5100s.c
│ │ │ └── w5100s.h
│ │ ├── W5200
│ │ │ ├── w5200.c
│ │ │ └── w5200.h
│ │ ├── W5300
│ │ │ ├── w5300.c
│ │ │ └── w5300.h
│ │ ├── W5500
│ │ │ ├── w5500.c
│ │ │ └── w5500.h
│ │ ├── socket.c
│ │ ├── socket.h
│ │ ├── wizchip_conf.c
│ │ └── wizchip_conf.h
│ ├── Internet
│ │ ├── DHCP
│ │ │ ├── dhcp.c
│ │ │ └── dhcp.h
│ │ ├── DNS
│ │ │ ├── dns.c
│ │ │ └── dns.h
│ │ ├── FTPClient
│ │ │ ├── ftpc.c
│ │ │ ├── ftpc.h
│ │ │ └── stdio_private.h
│ │ ├── FTPServer
│ │ │ ├── ftpd.c
│ │ │ ├── ftpd.h
│ │ │ └── stdio_private.h
│ │ ├── MQTT
│ │ │ ├── MQTTClient.c
│ │ │ ├── MQTTClient.h
│ │ │ ├── MQTTPacket
│ │ │ │ └── src
│ │ │ │ │ ├── MQTTConnect.h
│ │ │ │ │ ├── MQTTConnectClient.c
│ │ │ │ │ ├── MQTTConnectServer.c
│ │ │ │ │ ├── MQTTDeserializePublish.c
│ │ │ │ │ ├── MQTTFormat.c
│ │ │ │ │ ├── MQTTFormat.h
│ │ │ │ │ ├── MQTTPacket.c
│ │ │ │ │ ├── MQTTPacket.h
│ │ │ │ │ ├── MQTTPublish.h
│ │ │ │ │ ├── MQTTSerializePublish.c
│ │ │ │ │ ├── MQTTSubscribe.h
│ │ │ │ │ ├── MQTTSubscribeClient.c
│ │ │ │ │ ├── MQTTSubscribeServer.c
│ │ │ │ │ ├── MQTTUnsubscribe.h
│ │ │ │ │ ├── MQTTUnsubscribeClient.c
│ │ │ │ │ ├── MQTTUnsubscribeServer.c
│ │ │ │ │ └── StackTrace.h
│ │ │ ├── mqtt_interface.c
│ │ │ └── mqtt_interface.h
│ │ ├── SNMP
│ │ │ ├── snmp.c
│ │ │ ├── snmp.h
│ │ │ ├── snmp_custom.c
│ │ │ ├── snmp_custom.h
│ │ │ └── tools
│ │ │ │ ├── OID_Converter
│ │ │ │ └── Readme.txt
│ │ │ │ └── net-snmp-5.7(win32-bin)
│ │ │ │ └── snmptrapd.conf
│ │ ├── SNTP
│ │ │ ├── sntp.c
│ │ │ └── sntp.h
│ │ ├── TFTP
│ │ │ ├── netutil.c
│ │ │ ├── netutil.h
│ │ │ ├── tftp.c
│ │ │ └── tftp.h
│ │ └── httpServer
│ │ │ ├── httpParser.c
│ │ │ ├── httpParser.h
│ │ │ ├── httpServer.c
│ │ │ ├── httpServer.h
│ │ │ ├── httpUtil.c
│ │ │ └── httpUtil.h
│ ├── README.md
│ ├── iolibrary.chm
│ └── license.txt
└── uart_printf
│ ├── uart_printf.c
│ └── uart_printf.h
├── README.md
├── STM32F103RCTX_FLASH.ld
├── Test
└── test_result.PNG
└── W5500_STM32_HAL.ioc
/.gitignore:
--------------------------------------------------------------------------------
1 | /Debug/
2 | /*.launch
3 | /.vscode/
--------------------------------------------------------------------------------
/.mxproject:
--------------------------------------------------------------------------------
1 | [PreviousGenFiles]
2 | AdvancedFolderStructure=true
3 | HeaderFileListSize=3
4 | HeaderFiles#0=D:/STM32CubeIDE/workspace_1.2.0/W5500_STM32_HAL/Core/Inc/stm32f1xx_it.h
5 | HeaderFiles#1=D:/STM32CubeIDE/workspace_1.2.0/W5500_STM32_HAL/Core/Inc/stm32f1xx_hal_conf.h
6 | HeaderFiles#2=D:/STM32CubeIDE/workspace_1.2.0/W5500_STM32_HAL/Core/Inc/main.h
7 | HeaderFolderListSize=1
8 | HeaderPath#0=D:/STM32CubeIDE/workspace_1.2.0/W5500_STM32_HAL/Core/Inc
9 | SourceFileListSize=3
10 | SourceFiles#0=D:/STM32CubeIDE/workspace_1.2.0/W5500_STM32_HAL/Core/Src/stm32f1xx_it.c
11 | SourceFiles#1=D:/STM32CubeIDE/workspace_1.2.0/W5500_STM32_HAL/Core/Src/stm32f1xx_hal_msp.c
12 | SourceFiles#2=D:/STM32CubeIDE/workspace_1.2.0/W5500_STM32_HAL/Core/Src/main.c
13 | SourceFolderListSize=1
14 | SourcePath#0=D:/STM32CubeIDE/workspace_1.2.0/W5500_STM32_HAL/Core/Src
15 | HeaderFiles=;
16 | SourceFiles=;
17 |
18 | [PreviousLibFiles]
19 | LibFiles=Drivers/STM32F1xx_HAL_Driver/Inc/stm32f1xx_hal_spi.h;Drivers/STM32F1xx_HAL_Driver/Inc/Legacy/stm32_hal_legacy.h;Drivers/STM32F1xx_HAL_Driver/Inc/stm32f1xx_hal.h;Drivers/STM32F1xx_HAL_Driver/Inc/stm32f1xx_hal_def.h;Drivers/STM32F1xx_HAL_Driver/Inc/stm32f1xx_hal_rcc.h;Drivers/STM32F1xx_HAL_Driver/Inc/stm32f1xx_hal_rcc_ex.h;Drivers/STM32F1xx_HAL_Driver/Inc/stm32f1xx_hal_gpio.h;Drivers/STM32F1xx_HAL_Driver/Inc/stm32f1xx_hal_gpio_ex.h;Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_gpio_ex.c;Drivers/STM32F1xx_HAL_Driver/Inc/stm32f1xx_hal_dma_ex.h;Drivers/STM32F1xx_HAL_Driver/Inc/stm32f1xx_hal_dma.h;Drivers/STM32F1xx_HAL_Driver/Inc/stm32f1xx_hal_cortex.h;Drivers/STM32F1xx_HAL_Driver/Inc/stm32f1xx_hal_pwr.h;Drivers/STM32F1xx_HAL_Driver/Inc/stm32f1xx_hal_flash.h;Drivers/STM32F1xx_HAL_Driver/Inc/stm32f1xx_hal_flash_ex.h;Drivers/STM32F1xx_HAL_Driver/Inc/stm32f1xx_hal_exti.h;Drivers/STM32F1xx_HAL_Driver/Inc/stm32f1xx_hal_tim.h;Drivers/STM32F1xx_HAL_Driver/Inc/stm32f1xx_hal_tim_ex.h;Drivers/STM32F1xx_HAL_Driver/Inc/stm32f1xx_hal_uart.h;Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_spi.c;Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal.c;Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_rcc.c;Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_rcc_ex.c;Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_gpio.c;Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_dma.c;Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_cortex.c;Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_pwr.c;Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_flash.c;Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_flash_ex.c;Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_exti.c;Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_tim.c;Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_tim_ex.c;Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_uart.c;Drivers/STM32F1xx_HAL_Driver/Inc/stm32f1xx_hal_spi.h;Drivers/STM32F1xx_HAL_Driver/Inc/Legacy/stm32_hal_legacy.h;Drivers/STM32F1xx_HAL_Driver/Inc/stm32f1xx_hal.h;Drivers/STM32F1xx_HAL_Driver/Inc/stm32f1xx_hal_def.h;Drivers/STM32F1xx_HAL_Driver/Inc/stm32f1xx_hal_rcc.h;Drivers/STM32F1xx_HAL_Driver/Inc/stm32f1xx_hal_rcc_ex.h;Drivers/STM32F1xx_HAL_Driver/Inc/stm32f1xx_hal_gpio.h;Drivers/STM32F1xx_HAL_Driver/Inc/stm32f1xx_hal_gpio_ex.h;Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_gpio_ex.c;Drivers/STM32F1xx_HAL_Driver/Inc/stm32f1xx_hal_dma_ex.h;Drivers/STM32F1xx_HAL_Driver/Inc/stm32f1xx_hal_dma.h;Drivers/STM32F1xx_HAL_Driver/Inc/stm32f1xx_hal_cortex.h;Drivers/STM32F1xx_HAL_Driver/Inc/stm32f1xx_hal_pwr.h;Drivers/STM32F1xx_HAL_Driver/Inc/stm32f1xx_hal_flash.h;Drivers/STM32F1xx_HAL_Driver/Inc/stm32f1xx_hal_flash_ex.h;Drivers/STM32F1xx_HAL_Driver/Inc/stm32f1xx_hal_exti.h;Drivers/STM32F1xx_HAL_Driver/Inc/stm32f1xx_hal_tim.h;Drivers/STM32F1xx_HAL_Driver/Inc/stm32f1xx_hal_tim_ex.h;Drivers/STM32F1xx_HAL_Driver/Inc/stm32f1xx_hal_uart.h;Drivers/CMSIS/Device/ST/STM32F1xx/Include/stm32f103xe.h;Drivers/CMSIS/Device/ST/STM32F1xx/Include/stm32f1xx.h;Drivers/CMSIS/Device/ST/STM32F1xx/Include/system_stm32f1xx.h;Drivers/CMSIS/Device/ST/STM32F1xx/Source/Templates/system_stm32f1xx.c;Drivers/CMSIS/Include/cmsis_armcc.h;Drivers/CMSIS/Include/cmsis_armclang.h;Drivers/CMSIS/Include/cmsis_compiler.h;Drivers/CMSIS/Include/cmsis_gcc.h;Drivers/CMSIS/Include/cmsis_iccarm.h;Drivers/CMSIS/Include/cmsis_version.h;Drivers/CMSIS/Include/core_armv8mbl.h;Drivers/CMSIS/Include/core_armv8mml.h;Drivers/CMSIS/Include/core_cm0.h;Drivers/CMSIS/Include/core_cm0plus.h;Drivers/CMSIS/Include/core_cm1.h;Drivers/CMSIS/Include/core_cm23.h;Drivers/CMSIS/Include/core_cm3.h;Drivers/CMSIS/Include/core_cm33.h;Drivers/CMSIS/Include/core_cm4.h;Drivers/CMSIS/Include/core_cm7.h;Drivers/CMSIS/Include/core_sc000.h;Drivers/CMSIS/Include/core_sc300.h;Drivers/CMSIS/Include/mpu_armv7.h;Drivers/CMSIS/Include/mpu_armv8.h;Drivers/CMSIS/Include/tz_context.h;
20 |
21 | [PreviousUsedCubeIDEFiles]
22 | SourceFiles=Core\Src\main.c;Core\Src\stm32f1xx_it.c;Core\Src\stm32f1xx_hal_msp.c;Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_gpio_ex.c;Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_spi.c;Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal.c;Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_rcc.c;Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_rcc_ex.c;Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_gpio.c;Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_dma.c;Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_cortex.c;Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_pwr.c;Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_flash.c;Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_flash_ex.c;Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_exti.c;Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_tim.c;Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_tim_ex.c;Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_uart.c;Core\Src/system_stm32f1xx.c;Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_gpio_ex.c;Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_spi.c;Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal.c;Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_rcc.c;Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_rcc_ex.c;Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_gpio.c;Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_dma.c;Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_cortex.c;Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_pwr.c;Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_flash.c;Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_flash_ex.c;Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_exti.c;Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_tim.c;Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_tim_ex.c;Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_uart.c;Core\Src/system_stm32f1xx.c;Drivers/CMSIS/Device/ST/STM32F1xx/Source/Templates/system_stm32f1xx.c;;
23 | HeaderPath=Drivers\STM32F1xx_HAL_Driver\Inc;Drivers\STM32F1xx_HAL_Driver\Inc\Legacy;Drivers\CMSIS\Device\ST\STM32F1xx\Include;Drivers\CMSIS\Include;Core\Inc;
24 | CDefines=USE_HAL_DRIVER;STM32F103xE;USE_HAL_DRIVER;USE_HAL_DRIVER;
25 |
26 |
--------------------------------------------------------------------------------
/.project:
--------------------------------------------------------------------------------
1 |
2 |
3 | W5500_STM32_HAL
4 |
5 |
6 |
7 |
8 |
9 | org.eclipse.cdt.managedbuilder.core.genmakebuilder
10 | clean,full,incremental,
11 |
12 |
13 |
14 |
15 | org.eclipse.cdt.managedbuilder.core.ScannerConfigBuilder
16 | full,incremental,
17 |
18 |
19 |
20 |
21 |
22 | com.st.stm32cube.ide.mcu.MCUProjectNature
23 | com.st.stm32cube.ide.mcu.MCUCubeProjectNature
24 | org.eclipse.cdt.core.cnature
25 | com.st.stm32cube.ide.mcu.MCUCubeIdeServicesRevAProjectNature
26 | com.st.stm32cube.ide.mcu.MCUAdvancedStructureProjectNature
27 | com.st.stm32cube.ide.mcu.MCUEndUserDisabledTrustZoneProjectNature
28 | com.st.stm32cube.ide.mcu.MCUSingleCpuProjectNature
29 | com.st.stm32cube.ide.mcu.MCURootProjectNature
30 | org.eclipse.cdt.managedbuilder.core.managedBuildNature
31 | org.eclipse.cdt.managedbuilder.core.ScannerConfigNature
32 |
33 |
34 |
--------------------------------------------------------------------------------
/.settings/language.settings.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
--------------------------------------------------------------------------------
/Core/Inc/main.h:
--------------------------------------------------------------------------------
1 | /* USER CODE BEGIN Header */
2 | /**
3 | ******************************************************************************
4 | * @file : main.h
5 | * @brief : Header for main.c file.
6 | * This file contains the common defines of the application.
7 | ******************************************************************************
8 | * @attention
9 | *
10 | *
© Copyright (c) 2020 STMicroelectronics.
11 | * All rights reserved.
12 | *
13 | * This software component is licensed by ST under BSD 3-Clause license,
14 | * the "License"; You may not use this file except in compliance with the
15 | * License. You may obtain a copy of the License at:
16 | * opensource.org/licenses/BSD-3-Clause
17 | *
18 | ******************************************************************************
19 | */
20 | /* USER CODE END Header */
21 |
22 | /* Define to prevent recursive inclusion -------------------------------------*/
23 | #ifndef __MAIN_H
24 | #define __MAIN_H
25 |
26 | #ifdef __cplusplus
27 | extern "C" {
28 | #endif
29 |
30 | /* Includes ------------------------------------------------------------------*/
31 | #include "stm32f1xx_hal.h"
32 |
33 | /* Private includes ----------------------------------------------------------*/
34 | /* USER CODE BEGIN Includes */
35 |
36 | /* USER CODE END Includes */
37 |
38 | /* Exported types ------------------------------------------------------------*/
39 | /* USER CODE BEGIN ET */
40 |
41 | /* USER CODE END ET */
42 |
43 | /* Exported constants --------------------------------------------------------*/
44 | /* USER CODE BEGIN EC */
45 |
46 | /* USER CODE END EC */
47 |
48 | /* Exported macro ------------------------------------------------------------*/
49 | /* USER CODE BEGIN EM */
50 |
51 | /* USER CODE END EM */
52 |
53 | /* Exported functions prototypes ---------------------------------------------*/
54 | void Error_Handler(void);
55 |
56 | /* USER CODE BEGIN EFP */
57 |
58 | /* USER CODE END EFP */
59 |
60 | /* Private defines -----------------------------------------------------------*/
61 | #define W5500_CS_Pin GPIO_PIN_4
62 | #define W5500_CS_GPIO_Port GPIOA
63 | #define W5500_INT_Pin GPIO_PIN_4
64 | #define W5500_INT_GPIO_Port GPIOC
65 | #define W5500_RST_Pin GPIO_PIN_5
66 | #define W5500_RST_GPIO_Port GPIOC
67 | /* USER CODE BEGIN Private defines */
68 |
69 | /* USER CODE END Private defines */
70 |
71 | #ifdef __cplusplus
72 | }
73 | #endif
74 |
75 | #endif /* __MAIN_H */
76 |
77 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
78 |
--------------------------------------------------------------------------------
/Core/Inc/stm32f1xx_it.h:
--------------------------------------------------------------------------------
1 | /* USER CODE BEGIN Header */
2 | /**
3 | ******************************************************************************
4 | * @file stm32f1xx_it.h
5 | * @brief This file contains the headers of the interrupt handlers.
6 | ******************************************************************************
7 | * @attention
8 | *
9 | * © Copyright (c) 2020 STMicroelectronics.
10 | * All rights reserved.
11 | *
12 | * This software component is licensed by ST under BSD 3-Clause license,
13 | * the "License"; You may not use this file except in compliance with the
14 | * License. You may obtain a copy of the License at:
15 | * opensource.org/licenses/BSD-3-Clause
16 | *
17 | ******************************************************************************
18 | */
19 | /* USER CODE END Header */
20 |
21 | /* Define to prevent recursive inclusion -------------------------------------*/
22 | #ifndef __STM32F1xx_IT_H
23 | #define __STM32F1xx_IT_H
24 |
25 | #ifdef __cplusplus
26 | extern "C" {
27 | #endif
28 |
29 | /* Private includes ----------------------------------------------------------*/
30 | /* USER CODE BEGIN Includes */
31 |
32 | /* USER CODE END Includes */
33 |
34 | /* Exported types ------------------------------------------------------------*/
35 | /* USER CODE BEGIN ET */
36 |
37 | /* USER CODE END ET */
38 |
39 | /* Exported constants --------------------------------------------------------*/
40 | /* USER CODE BEGIN EC */
41 |
42 | /* USER CODE END EC */
43 |
44 | /* Exported macro ------------------------------------------------------------*/
45 | /* USER CODE BEGIN EM */
46 |
47 | /* USER CODE END EM */
48 |
49 | /* Exported functions prototypes ---------------------------------------------*/
50 | void NMI_Handler(void);
51 | void HardFault_Handler(void);
52 | void MemManage_Handler(void);
53 | void BusFault_Handler(void);
54 | void UsageFault_Handler(void);
55 | void SVC_Handler(void);
56 | void DebugMon_Handler(void);
57 | void PendSV_Handler(void);
58 | void SysTick_Handler(void);
59 | /* USER CODE BEGIN EFP */
60 |
61 | /* USER CODE END EFP */
62 |
63 | #ifdef __cplusplus
64 | }
65 | #endif
66 |
67 | #endif /* __STM32F1xx_IT_H */
68 |
69 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
70 |
--------------------------------------------------------------------------------
/Core/Src/stm32f1xx_hal_msp.c:
--------------------------------------------------------------------------------
1 | /* USER CODE BEGIN Header */
2 | /**
3 | ******************************************************************************
4 | * File Name : stm32f1xx_hal_msp.c
5 | * Description : This file provides code for the MSP Initialization
6 | * and de-Initialization codes.
7 | ******************************************************************************
8 | * @attention
9 | *
10 | * © Copyright (c) 2020 STMicroelectronics.
11 | * All rights reserved.
12 | *
13 | * This software component is licensed by ST under BSD 3-Clause license,
14 | * the "License"; You may not use this file except in compliance with the
15 | * License. You may obtain a copy of the License at:
16 | * opensource.org/licenses/BSD-3-Clause
17 | *
18 | ******************************************************************************
19 | */
20 | /* USER CODE END Header */
21 |
22 | /* Includes ------------------------------------------------------------------*/
23 | #include "main.h"
24 | /* USER CODE BEGIN Includes */
25 |
26 | /* USER CODE END Includes */
27 |
28 | /* Private typedef -----------------------------------------------------------*/
29 | /* USER CODE BEGIN TD */
30 |
31 | /* USER CODE END TD */
32 |
33 | /* Private define ------------------------------------------------------------*/
34 | /* USER CODE BEGIN Define */
35 |
36 | /* USER CODE END Define */
37 |
38 | /* Private macro -------------------------------------------------------------*/
39 | /* USER CODE BEGIN Macro */
40 |
41 | /* USER CODE END Macro */
42 |
43 | /* Private variables ---------------------------------------------------------*/
44 | /* USER CODE BEGIN PV */
45 |
46 | /* USER CODE END PV */
47 |
48 | /* Private function prototypes -----------------------------------------------*/
49 | /* USER CODE BEGIN PFP */
50 |
51 | /* USER CODE END PFP */
52 |
53 | /* External functions --------------------------------------------------------*/
54 | /* USER CODE BEGIN ExternalFunctions */
55 |
56 | /* USER CODE END ExternalFunctions */
57 |
58 | /* USER CODE BEGIN 0 */
59 |
60 | /* USER CODE END 0 */
61 | /**
62 | * Initializes the Global MSP.
63 | */
64 | void HAL_MspInit(void)
65 | {
66 | /* USER CODE BEGIN MspInit 0 */
67 |
68 | /* USER CODE END MspInit 0 */
69 |
70 | __HAL_RCC_AFIO_CLK_ENABLE();
71 | __HAL_RCC_PWR_CLK_ENABLE();
72 |
73 | /* System interrupt init*/
74 |
75 | /** NOJTAG: JTAG-DP Disabled and SW-DP Enabled
76 | */
77 | __HAL_AFIO_REMAP_SWJ_NOJTAG();
78 |
79 | /* USER CODE BEGIN MspInit 1 */
80 |
81 | /* USER CODE END MspInit 1 */
82 | }
83 |
84 | /**
85 | * @brief SPI MSP Initialization
86 | * This function configures the hardware resources used in this example
87 | * @param hspi: SPI handle pointer
88 | * @retval None
89 | */
90 | void HAL_SPI_MspInit(SPI_HandleTypeDef* hspi)
91 | {
92 | GPIO_InitTypeDef GPIO_InitStruct = {0};
93 | if(hspi->Instance==SPI1)
94 | {
95 | /* USER CODE BEGIN SPI1_MspInit 0 */
96 |
97 | /* USER CODE END SPI1_MspInit 0 */
98 | /* Peripheral clock enable */
99 | __HAL_RCC_SPI1_CLK_ENABLE();
100 |
101 | __HAL_RCC_GPIOA_CLK_ENABLE();
102 | /**SPI1 GPIO Configuration
103 | PA5 ------> SPI1_SCK
104 | PA6 ------> SPI1_MISO
105 | PA7 ------> SPI1_MOSI
106 | */
107 | GPIO_InitStruct.Pin = GPIO_PIN_5|GPIO_PIN_7;
108 | GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
109 | GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_HIGH;
110 | HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
111 |
112 | GPIO_InitStruct.Pin = GPIO_PIN_6;
113 | GPIO_InitStruct.Mode = GPIO_MODE_INPUT;
114 | GPIO_InitStruct.Pull = GPIO_NOPULL;
115 | HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
116 |
117 | /* USER CODE BEGIN SPI1_MspInit 1 */
118 |
119 | /* USER CODE END SPI1_MspInit 1 */
120 | }
121 |
122 | }
123 |
124 | /**
125 | * @brief SPI MSP De-Initialization
126 | * This function freeze the hardware resources used in this example
127 | * @param hspi: SPI handle pointer
128 | * @retval None
129 | */
130 | void HAL_SPI_MspDeInit(SPI_HandleTypeDef* hspi)
131 | {
132 | if(hspi->Instance==SPI1)
133 | {
134 | /* USER CODE BEGIN SPI1_MspDeInit 0 */
135 |
136 | /* USER CODE END SPI1_MspDeInit 0 */
137 | /* Peripheral clock disable */
138 | __HAL_RCC_SPI1_CLK_DISABLE();
139 |
140 | /**SPI1 GPIO Configuration
141 | PA5 ------> SPI1_SCK
142 | PA6 ------> SPI1_MISO
143 | PA7 ------> SPI1_MOSI
144 | */
145 | HAL_GPIO_DeInit(GPIOA, GPIO_PIN_5|GPIO_PIN_6|GPIO_PIN_7);
146 |
147 | /* USER CODE BEGIN SPI1_MspDeInit 1 */
148 |
149 | /* USER CODE END SPI1_MspDeInit 1 */
150 | }
151 |
152 | }
153 |
154 | /**
155 | * @brief UART MSP Initialization
156 | * This function configures the hardware resources used in this example
157 | * @param huart: UART handle pointer
158 | * @retval None
159 | */
160 | void HAL_UART_MspInit(UART_HandleTypeDef* huart)
161 | {
162 | GPIO_InitTypeDef GPIO_InitStruct = {0};
163 | if(huart->Instance==USART1)
164 | {
165 | /* USER CODE BEGIN USART1_MspInit 0 */
166 |
167 | /* USER CODE END USART1_MspInit 0 */
168 | /* Peripheral clock enable */
169 | __HAL_RCC_USART1_CLK_ENABLE();
170 |
171 | __HAL_RCC_GPIOA_CLK_ENABLE();
172 | /**USART1 GPIO Configuration
173 | PA9 ------> USART1_TX
174 | PA10 ------> USART1_RX
175 | */
176 | GPIO_InitStruct.Pin = GPIO_PIN_9;
177 | GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
178 | GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_HIGH;
179 | HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
180 |
181 | GPIO_InitStruct.Pin = GPIO_PIN_10;
182 | GPIO_InitStruct.Mode = GPIO_MODE_INPUT;
183 | GPIO_InitStruct.Pull = GPIO_NOPULL;
184 | HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
185 |
186 | /* USER CODE BEGIN USART1_MspInit 1 */
187 |
188 | /* USER CODE END USART1_MspInit 1 */
189 | }
190 |
191 | }
192 |
193 | /**
194 | * @brief UART MSP De-Initialization
195 | * This function freeze the hardware resources used in this example
196 | * @param huart: UART handle pointer
197 | * @retval None
198 | */
199 | void HAL_UART_MspDeInit(UART_HandleTypeDef* huart)
200 | {
201 | if(huart->Instance==USART1)
202 | {
203 | /* USER CODE BEGIN USART1_MspDeInit 0 */
204 |
205 | /* USER CODE END USART1_MspDeInit 0 */
206 | /* Peripheral clock disable */
207 | __HAL_RCC_USART1_CLK_DISABLE();
208 |
209 | /**USART1 GPIO Configuration
210 | PA9 ------> USART1_TX
211 | PA10 ------> USART1_RX
212 | */
213 | HAL_GPIO_DeInit(GPIOA, GPIO_PIN_9|GPIO_PIN_10);
214 |
215 | /* USER CODE BEGIN USART1_MspDeInit 1 */
216 |
217 | /* USER CODE END USART1_MspDeInit 1 */
218 | }
219 |
220 | }
221 |
222 | /* USER CODE BEGIN 1 */
223 |
224 | /* USER CODE END 1 */
225 |
226 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
227 |
--------------------------------------------------------------------------------
/Core/Src/stm32f1xx_it.c:
--------------------------------------------------------------------------------
1 | /* USER CODE BEGIN Header */
2 | /**
3 | ******************************************************************************
4 | * @file stm32f1xx_it.c
5 | * @brief Interrupt Service Routines.
6 | ******************************************************************************
7 | * @attention
8 | *
9 | * © Copyright (c) 2020 STMicroelectronics.
10 | * All rights reserved.
11 | *
12 | * This software component is licensed by ST under BSD 3-Clause license,
13 | * the "License"; You may not use this file except in compliance with the
14 | * License. You may obtain a copy of the License at:
15 | * opensource.org/licenses/BSD-3-Clause
16 | *
17 | ******************************************************************************
18 | */
19 | /* USER CODE END Header */
20 |
21 | /* Includes ------------------------------------------------------------------*/
22 | #include "main.h"
23 | #include "stm32f1xx_it.h"
24 | /* Private includes ----------------------------------------------------------*/
25 | /* USER CODE BEGIN Includes */
26 | /* USER CODE END Includes */
27 |
28 | /* Private typedef -----------------------------------------------------------*/
29 | /* USER CODE BEGIN TD */
30 |
31 | /* USER CODE END TD */
32 |
33 | /* Private define ------------------------------------------------------------*/
34 | /* USER CODE BEGIN PD */
35 |
36 | /* USER CODE END PD */
37 |
38 | /* Private macro -------------------------------------------------------------*/
39 | /* USER CODE BEGIN PM */
40 |
41 | /* USER CODE END PM */
42 |
43 | /* Private variables ---------------------------------------------------------*/
44 | /* USER CODE BEGIN PV */
45 |
46 | /* USER CODE END PV */
47 |
48 | /* Private function prototypes -----------------------------------------------*/
49 | /* USER CODE BEGIN PFP */
50 |
51 | /* USER CODE END PFP */
52 |
53 | /* Private user code ---------------------------------------------------------*/
54 | /* USER CODE BEGIN 0 */
55 |
56 | /* USER CODE END 0 */
57 |
58 | /* External variables --------------------------------------------------------*/
59 |
60 | /* USER CODE BEGIN EV */
61 |
62 | /* USER CODE END EV */
63 |
64 | /******************************************************************************/
65 | /* Cortex-M3 Processor Interruption and Exception Handlers */
66 | /******************************************************************************/
67 | /**
68 | * @brief This function handles Non maskable interrupt.
69 | */
70 | void NMI_Handler(void)
71 | {
72 | /* USER CODE BEGIN NonMaskableInt_IRQn 0 */
73 |
74 | /* USER CODE END NonMaskableInt_IRQn 0 */
75 | /* USER CODE BEGIN NonMaskableInt_IRQn 1 */
76 |
77 | /* USER CODE END NonMaskableInt_IRQn 1 */
78 | }
79 |
80 | /**
81 | * @brief This function handles Hard fault interrupt.
82 | */
83 | void HardFault_Handler(void)
84 | {
85 | /* USER CODE BEGIN HardFault_IRQn 0 */
86 |
87 | /* USER CODE END HardFault_IRQn 0 */
88 | while (1)
89 | {
90 | /* USER CODE BEGIN W1_HardFault_IRQn 0 */
91 | /* USER CODE END W1_HardFault_IRQn 0 */
92 | }
93 | }
94 |
95 | /**
96 | * @brief This function handles Memory management fault.
97 | */
98 | void MemManage_Handler(void)
99 | {
100 | /* USER CODE BEGIN MemoryManagement_IRQn 0 */
101 |
102 | /* USER CODE END MemoryManagement_IRQn 0 */
103 | while (1)
104 | {
105 | /* USER CODE BEGIN W1_MemoryManagement_IRQn 0 */
106 | /* USER CODE END W1_MemoryManagement_IRQn 0 */
107 | }
108 | }
109 |
110 | /**
111 | * @brief This function handles Prefetch fault, memory access fault.
112 | */
113 | void BusFault_Handler(void)
114 | {
115 | /* USER CODE BEGIN BusFault_IRQn 0 */
116 |
117 | /* USER CODE END BusFault_IRQn 0 */
118 | while (1)
119 | {
120 | /* USER CODE BEGIN W1_BusFault_IRQn 0 */
121 | /* USER CODE END W1_BusFault_IRQn 0 */
122 | }
123 | }
124 |
125 | /**
126 | * @brief This function handles Undefined instruction or illegal state.
127 | */
128 | void UsageFault_Handler(void)
129 | {
130 | /* USER CODE BEGIN UsageFault_IRQn 0 */
131 |
132 | /* USER CODE END UsageFault_IRQn 0 */
133 | while (1)
134 | {
135 | /* USER CODE BEGIN W1_UsageFault_IRQn 0 */
136 | /* USER CODE END W1_UsageFault_IRQn 0 */
137 | }
138 | }
139 |
140 | /**
141 | * @brief This function handles System service call via SWI instruction.
142 | */
143 | void SVC_Handler(void)
144 | {
145 | /* USER CODE BEGIN SVCall_IRQn 0 */
146 |
147 | /* USER CODE END SVCall_IRQn 0 */
148 | /* USER CODE BEGIN SVCall_IRQn 1 */
149 |
150 | /* USER CODE END SVCall_IRQn 1 */
151 | }
152 |
153 | /**
154 | * @brief This function handles Debug monitor.
155 | */
156 | void DebugMon_Handler(void)
157 | {
158 | /* USER CODE BEGIN DebugMonitor_IRQn 0 */
159 |
160 | /* USER CODE END DebugMonitor_IRQn 0 */
161 | /* USER CODE BEGIN DebugMonitor_IRQn 1 */
162 |
163 | /* USER CODE END DebugMonitor_IRQn 1 */
164 | }
165 |
166 | /**
167 | * @brief This function handles Pendable request for system service.
168 | */
169 | void PendSV_Handler(void)
170 | {
171 | /* USER CODE BEGIN PendSV_IRQn 0 */
172 |
173 | /* USER CODE END PendSV_IRQn 0 */
174 | /* USER CODE BEGIN PendSV_IRQn 1 */
175 |
176 | /* USER CODE END PendSV_IRQn 1 */
177 | }
178 |
179 | /**
180 | * @brief This function handles System tick timer.
181 | */
182 | void SysTick_Handler(void)
183 | {
184 | /* USER CODE BEGIN SysTick_IRQn 0 */
185 |
186 | /* USER CODE END SysTick_IRQn 0 */
187 | HAL_IncTick();
188 | /* USER CODE BEGIN SysTick_IRQn 1 */
189 |
190 | /* USER CODE END SysTick_IRQn 1 */
191 | }
192 |
193 | /******************************************************************************/
194 | /* STM32F1xx Peripheral Interrupt Handlers */
195 | /* Add here the Interrupt Handlers for the used peripherals. */
196 | /* For the available peripheral interrupt handler names, */
197 | /* please refer to the startup file (startup_stm32f1xx.s). */
198 | /******************************************************************************/
199 |
200 | /* USER CODE BEGIN 1 */
201 |
202 | /* USER CODE END 1 */
203 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
204 |
--------------------------------------------------------------------------------
/Core/Src/syscalls.c:
--------------------------------------------------------------------------------
1 | /**
2 | *****************************************************************************
3 | **
4 | ** File : syscalls.c
5 | **
6 | ** Author : Auto-generated by STM32CubeIDE
7 | **
8 | ** Abstract : STM32CubeIDE Minimal System calls file
9 | **
10 | ** For more information about which c-functions
11 | ** need which of these lowlevel functions
12 | ** please consult the Newlib libc-manual
13 | **
14 | ** Environment : STM32CubeIDE MCU
15 | **
16 | ** Distribution: The file is distributed as is, without any warranty
17 | ** of any kind.
18 | **
19 | *****************************************************************************
20 | **
21 | ** © COPYRIGHT(c) 2018 STMicroelectronics
22 | **
23 | ** Redistribution and use in source and binary forms, with or without modification,
24 | ** are permitted provided that the following conditions are met:
25 | ** 1. Redistributions of source code must retain the above copyright notice,
26 | ** this list of conditions and the following disclaimer.
27 | ** 2. Redistributions in binary form must reproduce the above copyright notice,
28 | ** this list of conditions and the following disclaimer in the documentation
29 | ** and/or other materials provided with the distribution.
30 | ** 3. Neither the name of STMicroelectronics nor the names of its contributors
31 | ** may be used to endorse or promote products derived from this software
32 | ** without specific prior written permission.
33 | **
34 | ** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
35 | ** AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
36 | ** IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
37 | ** DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
38 | ** FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
39 | ** DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
40 | ** SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
41 | ** CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
42 | ** OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
43 | ** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
44 | **
45 | **
46 | *****************************************************************************
47 | */
48 |
49 | /* Includes */
50 | #include
51 | #include
52 | #include
53 | #include
54 | #include
55 | #include
56 | #include
57 | #include
58 |
59 |
60 | /* Variables */
61 | //#undef errno
62 | extern int errno;
63 | extern int __io_putchar(int ch) __attribute__((weak));
64 | extern int __io_getchar(void) __attribute__((weak));
65 |
66 | register char * stack_ptr asm("sp");
67 |
68 | char *__env[1] = { 0 };
69 | char **environ = __env;
70 |
71 |
72 | /* Functions */
73 | void initialise_monitor_handles()
74 | {
75 | }
76 |
77 | int _getpid(void)
78 | {
79 | return 1;
80 | }
81 |
82 | int _kill(int pid, int sig)
83 | {
84 | errno = EINVAL;
85 | return -1;
86 | }
87 |
88 | void _exit (int status)
89 | {
90 | _kill(status, -1);
91 | while (1) {} /* Make sure we hang here */
92 | }
93 |
94 | __attribute__((weak)) int _read(int file, char *ptr, int len)
95 | {
96 | int DataIdx;
97 |
98 | for (DataIdx = 0; DataIdx < len; DataIdx++)
99 | {
100 | *ptr++ = __io_getchar();
101 | }
102 |
103 | return len;
104 | }
105 |
106 | __attribute__((weak)) int _write(int file, char *ptr, int len)
107 | {
108 | int DataIdx;
109 |
110 | for (DataIdx = 0; DataIdx < len; DataIdx++)
111 | {
112 | __io_putchar(*ptr++);
113 | }
114 | return len;
115 | }
116 |
117 | int _close(int file)
118 | {
119 | return -1;
120 | }
121 |
122 |
123 | int _fstat(int file, struct stat *st)
124 | {
125 | st->st_mode = S_IFCHR;
126 | return 0;
127 | }
128 |
129 | int _isatty(int file)
130 | {
131 | return 1;
132 | }
133 |
134 | int _lseek(int file, int ptr, int dir)
135 | {
136 | return 0;
137 | }
138 |
139 | int _open(char *path, int flags, ...)
140 | {
141 | /* Pretend like we always fail */
142 | return -1;
143 | }
144 |
145 | int _wait(int *status)
146 | {
147 | errno = ECHILD;
148 | return -1;
149 | }
150 |
151 | int _unlink(char *name)
152 | {
153 | errno = ENOENT;
154 | return -1;
155 | }
156 |
157 | int _times(struct tms *buf)
158 | {
159 | return -1;
160 | }
161 |
162 | int _stat(char *file, struct stat *st)
163 | {
164 | st->st_mode = S_IFCHR;
165 | return 0;
166 | }
167 |
168 | int _link(char *old, char *new)
169 | {
170 | errno = EMLINK;
171 | return -1;
172 | }
173 |
174 | int _fork(void)
175 | {
176 | errno = EAGAIN;
177 | return -1;
178 | }
179 |
180 | int _execve(char *name, char **argv, char **env)
181 | {
182 | errno = ENOMEM;
183 | return -1;
184 | }
185 |
--------------------------------------------------------------------------------
/Core/Src/sysmem.c:
--------------------------------------------------------------------------------
1 | /**
2 | *****************************************************************************
3 | **
4 | ** File : sysmem.c
5 | **
6 | ** Author : Auto-generated by STM32CubeIDE
7 | **
8 | ** Abstract : STM32CubeIDE Minimal System Memory calls file
9 | **
10 | ** For more information about which c-functions
11 | ** need which of these lowlevel functions
12 | ** please consult the Newlib libc-manual
13 | **
14 | ** Environment : STM32CubeIDE MCU
15 | **
16 | ** Distribution: The file is distributed as is, without any warranty
17 | ** of any kind.
18 | **
19 | *****************************************************************************
20 | **
21 | ** © COPYRIGHT(c) 2018 STMicroelectronics
22 | **
23 | ** Redistribution and use in source and binary forms, with or without modification,
24 | ** are permitted provided that the following conditions are met:
25 | ** 1. Redistributions of source code must retain the above copyright notice,
26 | ** this list of conditions and the following disclaimer.
27 | ** 2. Redistributions in binary form must reproduce the above copyright notice,
28 | ** this list of conditions and the following disclaimer in the documentation
29 | ** and/or other materials provided with the distribution.
30 | ** 3. Neither the name of STMicroelectronics nor the names of its contributors
31 | ** may be used to endorse or promote products derived from this software
32 | ** without specific prior written permission.
33 | **
34 | ** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
35 | ** AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
36 | ** IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
37 | ** DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
38 | ** FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
39 | ** DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
40 | ** SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
41 | ** CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
42 | ** OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
43 | ** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
44 | **
45 | **
46 | *****************************************************************************
47 | */
48 |
49 | /* Includes */
50 | #include
51 | #include
52 |
53 | /* Variables */
54 | extern int errno;
55 | register char * stack_ptr asm("sp");
56 |
57 | /* Functions */
58 |
59 | /**
60 | _sbrk
61 | Increase program data space. Malloc and related functions depend on this
62 | **/
63 | caddr_t _sbrk(int incr)
64 | {
65 | extern char end asm("end");
66 | static char *heap_end;
67 | char *prev_heap_end;
68 |
69 | if (heap_end == 0)
70 | heap_end = &end;
71 |
72 | prev_heap_end = heap_end;
73 | if (heap_end + incr > stack_ptr)
74 | {
75 | errno = ENOMEM;
76 | return (caddr_t) -1;
77 | }
78 |
79 | heap_end += incr;
80 |
81 | return (caddr_t) prev_heap_end;
82 | }
83 |
84 |
--------------------------------------------------------------------------------
/Drivers/CMSIS/Device/ST/STM32F1xx/Include/stm32f103xe.h:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/JustForFunOk/W5500_STM32_HAL/418c98979f3f053e8df5afad984749725af42133/Drivers/CMSIS/Device/ST/STM32F1xx/Include/stm32f103xe.h
--------------------------------------------------------------------------------
/Drivers/CMSIS/Device/ST/STM32F1xx/Include/stm32f1xx.h:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/JustForFunOk/W5500_STM32_HAL/418c98979f3f053e8df5afad984749725af42133/Drivers/CMSIS/Device/ST/STM32F1xx/Include/stm32f1xx.h
--------------------------------------------------------------------------------
/Drivers/CMSIS/Device/ST/STM32F1xx/Include/system_stm32f1xx.h:
--------------------------------------------------------------------------------
1 | /**
2 | ******************************************************************************
3 | * @file system_stm32f10x.h
4 | * @author MCD Application Team
5 | * @brief CMSIS Cortex-M3 Device Peripheral Access Layer System Header File.
6 | ******************************************************************************
7 | * @attention
8 | *
9 | * © Copyright (c) 2017 STMicroelectronics.
10 | * All rights reserved.
11 | *
12 | * This software component is licensed by ST under BSD 3-Clause license,
13 | * the "License"; You may not use this file except in compliance with the
14 | * License. You may obtain a copy of the License at:
15 | * opensource.org/licenses/BSD-3-Clause
16 | *
17 | ******************************************************************************
18 | */
19 |
20 | /** @addtogroup CMSIS
21 | * @{
22 | */
23 |
24 | /** @addtogroup stm32f10x_system
25 | * @{
26 | */
27 |
28 | /**
29 | * @brief Define to prevent recursive inclusion
30 | */
31 | #ifndef __SYSTEM_STM32F10X_H
32 | #define __SYSTEM_STM32F10X_H
33 |
34 | #ifdef __cplusplus
35 | extern "C" {
36 | #endif
37 |
38 | /** @addtogroup STM32F10x_System_Includes
39 | * @{
40 | */
41 |
42 | /**
43 | * @}
44 | */
45 |
46 |
47 | /** @addtogroup STM32F10x_System_Exported_types
48 | * @{
49 | */
50 |
51 | extern uint32_t SystemCoreClock; /*!< System Clock Frequency (Core Clock) */
52 | extern const uint8_t AHBPrescTable[16U]; /*!< AHB prescalers table values */
53 | extern const uint8_t APBPrescTable[8U]; /*!< APB prescalers table values */
54 |
55 | /**
56 | * @}
57 | */
58 |
59 | /** @addtogroup STM32F10x_System_Exported_Constants
60 | * @{
61 | */
62 |
63 | /**
64 | * @}
65 | */
66 |
67 | /** @addtogroup STM32F10x_System_Exported_Macros
68 | * @{
69 | */
70 |
71 | /**
72 | * @}
73 | */
74 |
75 | /** @addtogroup STM32F10x_System_Exported_Functions
76 | * @{
77 | */
78 |
79 | extern void SystemInit(void);
80 | extern void SystemCoreClockUpdate(void);
81 | /**
82 | * @}
83 | */
84 |
85 | #ifdef __cplusplus
86 | }
87 | #endif
88 |
89 | #endif /*__SYSTEM_STM32F10X_H */
90 |
91 | /**
92 | * @}
93 | */
94 |
95 | /**
96 | * @}
97 | */
98 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
99 |
--------------------------------------------------------------------------------
/Drivers/CMSIS/Include/cmsis_version.h:
--------------------------------------------------------------------------------
1 | /**************************************************************************//**
2 | * @file cmsis_version.h
3 | * @brief CMSIS Core(M) Version definitions
4 | * @version V5.0.2
5 | * @date 19. April 2017
6 | ******************************************************************************/
7 | /*
8 | * Copyright (c) 2009-2017 ARM Limited. All rights reserved.
9 | *
10 | * SPDX-License-Identifier: Apache-2.0
11 | *
12 | * Licensed under the Apache License, Version 2.0 (the License); you may
13 | * not use this file except in compliance with the License.
14 | * You may obtain a copy of the License at
15 | *
16 | * www.apache.org/licenses/LICENSE-2.0
17 | *
18 | * Unless required by applicable law or agreed to in writing, software
19 | * distributed under the License is distributed on an AS IS BASIS, WITHOUT
20 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
21 | * See the License for the specific language governing permissions and
22 | * limitations under the License.
23 | */
24 |
25 | #if defined ( __ICCARM__ )
26 | #pragma system_include /* treat file as system include file for MISRA check */
27 | #elif defined (__clang__)
28 | #pragma clang system_header /* treat file as system include file */
29 | #endif
30 |
31 | #ifndef __CMSIS_VERSION_H
32 | #define __CMSIS_VERSION_H
33 |
34 | /* CMSIS Version definitions */
35 | #define __CM_CMSIS_VERSION_MAIN ( 5U) /*!< [31:16] CMSIS Core(M) main version */
36 | #define __CM_CMSIS_VERSION_SUB ( 1U) /*!< [15:0] CMSIS Core(M) sub version */
37 | #define __CM_CMSIS_VERSION ((__CM_CMSIS_VERSION_MAIN << 16U) | \
38 | __CM_CMSIS_VERSION_SUB ) /*!< CMSIS Core(M) version number */
39 | #endif
40 |
--------------------------------------------------------------------------------
/Drivers/CMSIS/Include/tz_context.h:
--------------------------------------------------------------------------------
1 | /******************************************************************************
2 | * @file tz_context.h
3 | * @brief Context Management for Armv8-M TrustZone
4 | * @version V1.0.1
5 | * @date 10. January 2018
6 | ******************************************************************************/
7 | /*
8 | * Copyright (c) 2017-2018 Arm Limited. All rights reserved.
9 | *
10 | * SPDX-License-Identifier: Apache-2.0
11 | *
12 | * Licensed under the Apache License, Version 2.0 (the License); you may
13 | * not use this file except in compliance with the License.
14 | * You may obtain a copy of the License at
15 | *
16 | * www.apache.org/licenses/LICENSE-2.0
17 | *
18 | * Unless required by applicable law or agreed to in writing, software
19 | * distributed under the License is distributed on an AS IS BASIS, WITHOUT
20 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
21 | * See the License for the specific language governing permissions and
22 | * limitations under the License.
23 | */
24 |
25 | #if defined ( __ICCARM__ )
26 | #pragma system_include /* treat file as system include file for MISRA check */
27 | #elif defined (__clang__)
28 | #pragma clang system_header /* treat file as system include file */
29 | #endif
30 |
31 | #ifndef TZ_CONTEXT_H
32 | #define TZ_CONTEXT_H
33 |
34 | #include
35 |
36 | #ifndef TZ_MODULEID_T
37 | #define TZ_MODULEID_T
38 | /// \details Data type that identifies secure software modules called by a process.
39 | typedef uint32_t TZ_ModuleId_t;
40 | #endif
41 |
42 | /// \details TZ Memory ID identifies an allocated memory slot.
43 | typedef uint32_t TZ_MemoryId_t;
44 |
45 | /// Initialize secure context memory system
46 | /// \return execution status (1: success, 0: error)
47 | uint32_t TZ_InitContextSystem_S (void);
48 |
49 | /// Allocate context memory for calling secure software modules in TrustZone
50 | /// \param[in] module identifies software modules called from non-secure mode
51 | /// \return value != 0 id TrustZone memory slot identifier
52 | /// \return value 0 no memory available or internal error
53 | TZ_MemoryId_t TZ_AllocModuleContext_S (TZ_ModuleId_t module);
54 |
55 | /// Free context memory that was previously allocated with \ref TZ_AllocModuleContext_S
56 | /// \param[in] id TrustZone memory slot identifier
57 | /// \return execution status (1: success, 0: error)
58 | uint32_t TZ_FreeModuleContext_S (TZ_MemoryId_t id);
59 |
60 | /// Load secure context (called on RTOS thread context switch)
61 | /// \param[in] id TrustZone memory slot identifier
62 | /// \return execution status (1: success, 0: error)
63 | uint32_t TZ_LoadContext_S (TZ_MemoryId_t id);
64 |
65 | /// Store secure context (called on RTOS thread context switch)
66 | /// \param[in] id TrustZone memory slot identifier
67 | /// \return execution status (1: success, 0: error)
68 | uint32_t TZ_StoreContext_S (TZ_MemoryId_t id);
69 |
70 | #endif // TZ_CONTEXT_H
71 |
--------------------------------------------------------------------------------
/Drivers/STM32F1xx_HAL_Driver/Inc/stm32f1xx_hal_def.h:
--------------------------------------------------------------------------------
1 | /**
2 | ******************************************************************************
3 | * @file stm32f1xx_hal_def.h
4 | * @author MCD Application Team
5 | * @brief This file contains HAL common defines, enumeration, macros and
6 | * structures definitions.
7 | ******************************************************************************
8 | * @attention
9 | *
10 | * © Copyright (c) 2017 STMicroelectronics.
11 | * All rights reserved.
12 | *
13 | * This software component is licensed by ST under BSD 3-Clause license,
14 | * the "License"; You may not use this file except in compliance with the
15 | * License. You may obtain a copy of the License at:
16 | * opensource.org/licenses/BSD-3-Clause
17 | *
18 | ******************************************************************************
19 | */
20 |
21 | /* Define to prevent recursive inclusion -------------------------------------*/
22 | #ifndef __STM32F1xx_HAL_DEF
23 | #define __STM32F1xx_HAL_DEF
24 |
25 | #ifdef __cplusplus
26 | extern "C" {
27 | #endif
28 |
29 | /* Includes ------------------------------------------------------------------*/
30 | #include "stm32f1xx.h"
31 | #if defined(USE_HAL_LEGACY)
32 | #include "Legacy/stm32_hal_legacy.h"
33 | #endif
34 | #include
35 |
36 | /* Exported types ------------------------------------------------------------*/
37 |
38 | /**
39 | * @brief HAL Status structures definition
40 | */
41 | typedef enum
42 | {
43 | HAL_OK = 0x00U,
44 | HAL_ERROR = 0x01U,
45 | HAL_BUSY = 0x02U,
46 | HAL_TIMEOUT = 0x03U
47 | } HAL_StatusTypeDef;
48 |
49 | /**
50 | * @brief HAL Lock structures definition
51 | */
52 | typedef enum
53 | {
54 | HAL_UNLOCKED = 0x00U,
55 | HAL_LOCKED = 0x01U
56 | } HAL_LockTypeDef;
57 |
58 | /* Exported macro ------------------------------------------------------------*/
59 | #define HAL_MAX_DELAY 0xFFFFFFFFU
60 |
61 | #define HAL_IS_BIT_SET(REG, BIT) (((REG) & (BIT)) != 0U)
62 | #define HAL_IS_BIT_CLR(REG, BIT) (((REG) & (BIT)) == 0U)
63 |
64 | #define __HAL_LINKDMA(__HANDLE__, __PPP_DMA_FIELD__, __DMA_HANDLE__) \
65 | do{ \
66 | (__HANDLE__)->__PPP_DMA_FIELD__ = &(__DMA_HANDLE__); \
67 | (__DMA_HANDLE__).Parent = (__HANDLE__); \
68 | } while(0U)
69 |
70 | #define UNUSED(X) (void)X /* To avoid gcc/g++ warnings */
71 |
72 | /** @brief Reset the Handle's State field.
73 | * @param __HANDLE__ specifies the Peripheral Handle.
74 | * @note This macro can be used for the following purpose:
75 | * - When the Handle is declared as local variable; before passing it as parameter
76 | * to HAL_PPP_Init() for the first time, it is mandatory to use this macro
77 | * to set to 0 the Handle's "State" field.
78 | * Otherwise, "State" field may have any random value and the first time the function
79 | * HAL_PPP_Init() is called, the low level hardware initialization will be missed
80 | * (i.e. HAL_PPP_MspInit() will not be executed).
81 | * - When there is a need to reconfigure the low level hardware: instead of calling
82 | * HAL_PPP_DeInit() then HAL_PPP_Init(), user can make a call to this macro then HAL_PPP_Init().
83 | * In this later function, when the Handle's "State" field is set to 0, it will execute the function
84 | * HAL_PPP_MspInit() which will reconfigure the low level hardware.
85 | * @retval None
86 | */
87 | #define __HAL_RESET_HANDLE_STATE(__HANDLE__) ((__HANDLE__)->State = 0U)
88 |
89 | #if (USE_RTOS == 1U)
90 | /* Reserved for future use */
91 | #error "USE_RTOS should be 0 in the current HAL release"
92 | #else
93 | #define __HAL_LOCK(__HANDLE__) \
94 | do{ \
95 | if((__HANDLE__)->Lock == HAL_LOCKED) \
96 | { \
97 | return HAL_BUSY; \
98 | } \
99 | else \
100 | { \
101 | (__HANDLE__)->Lock = HAL_LOCKED; \
102 | } \
103 | }while (0U)
104 |
105 | #define __HAL_UNLOCK(__HANDLE__) \
106 | do{ \
107 | (__HANDLE__)->Lock = HAL_UNLOCKED; \
108 | }while (0U)
109 | #endif /* USE_RTOS */
110 |
111 | #if defined ( __GNUC__ ) && !defined (__CC_ARM) /* GNU Compiler */
112 | #ifndef __weak
113 | #define __weak __attribute__((weak))
114 | #endif /* __weak */
115 | #ifndef __packed
116 | #define __packed __attribute__((__packed__))
117 | #endif /* __packed */
118 | #endif /* __GNUC__ */
119 |
120 |
121 | /* Macro to get variable aligned on 4-bytes, for __ICCARM__ the directive "#pragma data_alignment=4" must be used instead */
122 | #if defined ( __GNUC__ ) && !defined (__CC_ARM) /* GNU Compiler */
123 | #ifndef __ALIGN_END
124 | #define __ALIGN_END __attribute__ ((aligned (4)))
125 | #endif /* __ALIGN_END */
126 | #ifndef __ALIGN_BEGIN
127 | #define __ALIGN_BEGIN
128 | #endif /* __ALIGN_BEGIN */
129 | #else
130 | #ifndef __ALIGN_END
131 | #define __ALIGN_END
132 | #endif /* __ALIGN_END */
133 | #ifndef __ALIGN_BEGIN
134 | #if defined (__CC_ARM) /* ARM Compiler */
135 | #define __ALIGN_BEGIN __align(4)
136 | #elif defined (__ICCARM__) /* IAR Compiler */
137 | #define __ALIGN_BEGIN
138 | #endif /* __CC_ARM */
139 | #endif /* __ALIGN_BEGIN */
140 | #endif /* __GNUC__ */
141 |
142 |
143 | /**
144 | * @brief __RAM_FUNC definition
145 | */
146 | #if defined ( __CC_ARM )
147 | /* ARM Compiler
148 | ------------
149 | RAM functions are defined using the toolchain options.
150 | Functions that are executed in RAM should reside in a separate source module.
151 | Using the 'Options for File' dialog you can simply change the 'Code / Const'
152 | area of a module to a memory space in physical RAM.
153 | Available memory areas are declared in the 'Target' tab of the 'Options for Target'
154 | dialog.
155 | */
156 | #define __RAM_FUNC
157 |
158 | #elif defined ( __ICCARM__ )
159 | /* ICCARM Compiler
160 | ---------------
161 | RAM functions are defined using a specific toolchain keyword "__ramfunc".
162 | */
163 | #define __RAM_FUNC __ramfunc
164 |
165 | #elif defined ( __GNUC__ )
166 | /* GNU Compiler
167 | ------------
168 | RAM functions are defined using a specific toolchain attribute
169 | "__attribute__((section(".RamFunc")))".
170 | */
171 | #define __RAM_FUNC __attribute__((section(".RamFunc")))
172 |
173 | #endif
174 |
175 | /**
176 | * @brief __NOINLINE definition
177 | */
178 | #if defined ( __CC_ARM ) || defined ( __GNUC__ )
179 | /* ARM & GNUCompiler
180 | ----------------
181 | */
182 | #define __NOINLINE __attribute__ ( (noinline) )
183 |
184 | #elif defined ( __ICCARM__ )
185 | /* ICCARM Compiler
186 | ---------------
187 | */
188 | #define __NOINLINE _Pragma("optimize = no_inline")
189 |
190 | #endif
191 |
192 | #ifdef __cplusplus
193 | }
194 | #endif
195 |
196 | #endif /* ___STM32F1xx_HAL_DEF */
197 |
198 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
199 |
--------------------------------------------------------------------------------
/Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_gpio_ex.c:
--------------------------------------------------------------------------------
1 | /**
2 | ******************************************************************************
3 | * @file stm32f1xx_hal_gpio_ex.c
4 | * @author MCD Application Team
5 | * @brief GPIO Extension HAL module driver.
6 | * This file provides firmware functions to manage the following
7 | * functionalities of the General Purpose Input/Output (GPIO) extension peripheral.
8 | * + Extended features functions
9 | *
10 | @verbatim
11 | ==============================================================================
12 | ##### GPIO Peripheral extension features #####
13 | ==============================================================================
14 | [..] GPIO module on STM32F1 family, manage also the AFIO register:
15 | (+) Possibility to use the EVENTOUT Cortex feature
16 |
17 | ##### How to use this driver #####
18 | ==============================================================================
19 | [..] This driver provides functions to use EVENTOUT Cortex feature
20 | (#) Configure EVENTOUT Cortex feature using the function HAL_GPIOEx_ConfigEventout()
21 | (#) Activate EVENTOUT Cortex feature using the HAL_GPIOEx_EnableEventout()
22 | (#) Deactivate EVENTOUT Cortex feature using the HAL_GPIOEx_DisableEventout()
23 |
24 | @endverbatim
25 | ******************************************************************************
26 | * @attention
27 | *
28 | * © Copyright (c) 2016 STMicroelectronics.
29 | * All rights reserved.
30 | *
31 | * This software component is licensed by ST under BSD 3-Clause license,
32 | * the "License"; You may not use this file except in compliance with the
33 | * License. You may obtain a copy of the License at:
34 | * opensource.org/licenses/BSD-3-Clause
35 | *
36 | ******************************************************************************
37 | */
38 |
39 | /* Includes ------------------------------------------------------------------*/
40 | #include "stm32f1xx_hal.h"
41 |
42 | /** @addtogroup STM32F1xx_HAL_Driver
43 | * @{
44 | */
45 |
46 | /** @defgroup GPIOEx GPIOEx
47 | * @brief GPIO HAL module driver
48 | * @{
49 | */
50 |
51 | #ifdef HAL_GPIO_MODULE_ENABLED
52 |
53 | /** @defgroup GPIOEx_Exported_Functions GPIOEx Exported Functions
54 | * @{
55 | */
56 |
57 | /** @defgroup GPIOEx_Exported_Functions_Group1 Extended features functions
58 | * @brief Extended features functions
59 | *
60 | @verbatim
61 | ==============================================================================
62 | ##### Extended features functions #####
63 | ==============================================================================
64 | [..] This section provides functions allowing to:
65 | (+) Configure EVENTOUT Cortex feature using the function HAL_GPIOEx_ConfigEventout()
66 | (+) Activate EVENTOUT Cortex feature using the HAL_GPIOEx_EnableEventout()
67 | (+) Deactivate EVENTOUT Cortex feature using the HAL_GPIOEx_DisableEventout()
68 |
69 | @endverbatim
70 | * @{
71 | */
72 |
73 | /**
74 | * @brief Configures the port and pin on which the EVENTOUT Cortex signal will be connected.
75 | * @param GPIO_PortSource Select the port used to output the Cortex EVENTOUT signal.
76 | * This parameter can be a value of @ref GPIOEx_EVENTOUT_PORT.
77 | * @param GPIO_PinSource Select the pin used to output the Cortex EVENTOUT signal.
78 | * This parameter can be a value of @ref GPIOEx_EVENTOUT_PIN.
79 | * @retval None
80 | */
81 | void HAL_GPIOEx_ConfigEventout(uint32_t GPIO_PortSource, uint32_t GPIO_PinSource)
82 | {
83 | /* Verify the parameters */
84 | assert_param(IS_AFIO_EVENTOUT_PORT(GPIO_PortSource));
85 | assert_param(IS_AFIO_EVENTOUT_PIN(GPIO_PinSource));
86 |
87 | /* Apply the new configuration */
88 | MODIFY_REG(AFIO->EVCR, (AFIO_EVCR_PORT) | (AFIO_EVCR_PIN), (GPIO_PortSource) | (GPIO_PinSource));
89 | }
90 |
91 | /**
92 | * @brief Enables the Event Output.
93 | * @retval None
94 | */
95 | void HAL_GPIOEx_EnableEventout(void)
96 | {
97 | SET_BIT(AFIO->EVCR, AFIO_EVCR_EVOE);
98 | }
99 |
100 | /**
101 | * @brief Disables the Event Output.
102 | * @retval None
103 | */
104 | void HAL_GPIOEx_DisableEventout(void)
105 | {
106 | CLEAR_BIT(AFIO->EVCR, AFIO_EVCR_EVOE);
107 | }
108 |
109 | /**
110 | * @}
111 | */
112 |
113 | /**
114 | * @}
115 | */
116 |
117 | #endif /* HAL_GPIO_MODULE_ENABLED */
118 |
119 | /**
120 | * @}
121 | */
122 |
123 | /**
124 | * @}
125 | */
126 |
127 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
128 |
--------------------------------------------------------------------------------
/Drivers/ioLibrary_Driver/.gitattributes:
--------------------------------------------------------------------------------
1 | # Auto detect text files and perform LF normalization
2 | * text=auto
3 |
4 | # Custom for Visual Studio
5 | *.cs diff=csharp
6 | *.sln merge=union
7 | *.csproj merge=union
8 | *.vbproj merge=union
9 | *.fsproj merge=union
10 | *.dbproj merge=union
11 |
12 | # Standard to msysgit
13 | *.doc diff=astextplain
14 | *.DOC diff=astextplain
15 | *.docx diff=astextplain
16 | *.DOCX diff=astextplain
17 | *.dot diff=astextplain
18 | *.DOT diff=astextplain
19 | *.pdf diff=astextplain
20 | *.PDF diff=astextplain
21 | *.rtf diff=astextplain
22 | *.RTF diff=astextplain
23 |
--------------------------------------------------------------------------------
/Drivers/ioLibrary_Driver/Application/loopback/loopback.c:
--------------------------------------------------------------------------------
1 | #include
2 | #include "loopback.h"
3 | #include "socket.h"
4 | #include "wizchip_conf.h"
5 |
6 | #if LOOPBACK_MODE == LOOPBACK_MAIN_NOBLCOK
7 |
8 | int32_t loopback_tcps(uint8_t sn, uint8_t* buf, uint16_t port)
9 | {
10 | int32_t ret;
11 | uint16_t size = 0, sentsize=0;
12 |
13 | #ifdef _LOOPBACK_DEBUG_
14 | uint8_t destip[4];
15 | uint16_t destport;
16 | #endif
17 |
18 | switch(getSn_SR(sn))
19 | {
20 | case SOCK_ESTABLISHED :
21 | if(getSn_IR(sn) & Sn_IR_CON)
22 | {
23 | #ifdef _LOOPBACK_DEBUG_
24 | getSn_DIPR(sn, destip);
25 | destport = getSn_DPORT(sn);
26 |
27 | printf("%d:Connected - %d.%d.%d.%d : %d\r\n",sn, destip[0], destip[1], destip[2], destip[3], destport);
28 | #endif
29 | setSn_IR(sn,Sn_IR_CON);
30 | }
31 | if((size = getSn_RX_RSR(sn)) > 0) // Don't need to check SOCKERR_BUSY because it doesn't not occur.
32 | {
33 | if(size > DATA_BUF_SIZE) size = DATA_BUF_SIZE;
34 | ret = recv(sn, buf, size);
35 |
36 | if(ret <= 0) return ret; // check SOCKERR_BUSY & SOCKERR_XXX. For showing the occurrence of SOCKERR_BUSY.
37 | size = (uint16_t) ret;
38 | sentsize = 0;
39 |
40 | while(size != sentsize)
41 | {
42 | ret = send(sn, buf+sentsize, size-sentsize);
43 | if(ret < 0)
44 | {
45 | close(sn);
46 | return ret;
47 | }
48 | sentsize += ret; // Don't care SOCKERR_BUSY, because it is zero.
49 | }
50 | }
51 | break;
52 | case SOCK_CLOSE_WAIT :
53 | #ifdef _LOOPBACK_DEBUG_
54 | //printf("%d:CloseWait\r\n",sn);
55 | #endif
56 | if((ret = disconnect(sn)) != SOCK_OK) return ret;
57 | #ifdef _LOOPBACK_DEBUG_
58 | printf("%d:Socket Closed\r\n", sn);
59 | #endif
60 | break;
61 | case SOCK_INIT :
62 | #ifdef _LOOPBACK_DEBUG_
63 | printf("%d:Listen, TCP server loopback, port [%d]\r\n", sn, port);
64 | #endif
65 | if( (ret = listen(sn)) != SOCK_OK) return ret;
66 | break;
67 | case SOCK_CLOSED:
68 | #ifdef _LOOPBACK_DEBUG_
69 | //printf("%d:TCP server loopback start\r\n",sn);
70 | #endif
71 | if((ret = socket(sn, Sn_MR_TCP, port, 0x00)) != sn) return ret;
72 | #ifdef _LOOPBACK_DEBUG_
73 | //printf("%d:Socket opened\r\n",sn);
74 | #endif
75 | break;
76 | default:
77 | break;
78 | }
79 | return 1;
80 | }
81 |
82 |
83 | int32_t loopback_tcpc(uint8_t sn, uint8_t* buf, uint8_t* destip, uint16_t destport)
84 | {
85 | int32_t ret; // return value for SOCK_ERRORs
86 | uint16_t size = 0, sentsize=0;
87 |
88 | // Destination (TCP Server) IP info (will be connected)
89 | // >> loopback_tcpc() function parameter
90 | // >> Ex)
91 | // uint8_t destip[4] = {192, 168, 0, 214};
92 | // uint16_t destport = 5000;
93 |
94 | // Port number for TCP client (will be increased)
95 | static uint16_t any_port = 50000;
96 |
97 | // Socket Status Transitions
98 | // Check the W5500 Socket n status register (Sn_SR, The 'Sn_SR' controlled by Sn_CR command or Packet send/recv status)
99 | switch(getSn_SR(sn))
100 | {
101 | case SOCK_ESTABLISHED :
102 | if(getSn_IR(sn) & Sn_IR_CON) // Socket n interrupt register mask; TCP CON interrupt = connection with peer is successful
103 | {
104 | #ifdef _LOOPBACK_DEBUG_
105 | printf("%d:Connected to - %d.%d.%d.%d : %d\r\n",sn, destip[0], destip[1], destip[2], destip[3], destport);
106 | #endif
107 | setSn_IR(sn, Sn_IR_CON); // this interrupt should be write the bit cleared to '1'
108 | }
109 |
110 | //////////////////////////////////////////////////////////////////////////////////////////////
111 | // Data Transaction Parts; Handle the [data receive and send] process
112 | //////////////////////////////////////////////////////////////////////////////////////////////
113 | if((size = getSn_RX_RSR(sn)) > 0) // Sn_RX_RSR: Socket n Received Size Register, Receiving data length
114 | {
115 | if(size > DATA_BUF_SIZE) size = DATA_BUF_SIZE; // DATA_BUF_SIZE means user defined buffer size (array)
116 | ret = recv(sn, buf, size); // Data Receive process (H/W Rx socket buffer -> User's buffer)
117 |
118 | if(ret <= 0) return ret; // If the received data length <= 0, receive failed and process end
119 | size = (uint16_t) ret;
120 | sentsize = 0;
121 |
122 | // Data sentsize control
123 | while(size != sentsize)
124 | {
125 | ret = send(sn, buf+sentsize, size-sentsize); // Data send process (User's buffer -> Destination through H/W Tx socket buffer)
126 | if(ret < 0) // Send Error occurred (sent data length < 0)
127 | {
128 | close(sn); // socket close
129 | return ret;
130 | }
131 | sentsize += ret; // Don't care SOCKERR_BUSY, because it is zero.
132 | }
133 | }
134 | //////////////////////////////////////////////////////////////////////////////////////////////
135 | break;
136 |
137 | case SOCK_CLOSE_WAIT :
138 | #ifdef _LOOPBACK_DEBUG_
139 | //printf("%d:CloseWait\r\n",sn);
140 | #endif
141 | if((ret=disconnect(sn)) != SOCK_OK) return ret;
142 | #ifdef _LOOPBACK_DEBUG_
143 | printf("%d:Socket Closed\r\n", sn);
144 | #endif
145 | break;
146 |
147 | case SOCK_INIT :
148 | #ifdef _LOOPBACK_DEBUG_
149 | printf("%d:Try to connect to the %d.%d.%d.%d : %d\r\n", sn, destip[0], destip[1], destip[2], destip[3], destport);
150 | #endif
151 | if( (ret = connect(sn, destip, destport)) != SOCK_OK) return ret; // Try to TCP connect to the TCP server (destination)
152 | break;
153 |
154 | case SOCK_CLOSED:
155 | close(sn);
156 | if((ret=socket(sn, Sn_MR_TCP, any_port++, 0x00)) != sn){
157 | if(any_port == 0xffff) any_port = 50000;
158 | return ret; // TCP socket open with 'any_port' port number
159 | }
160 | #ifdef _LOOPBACK_DEBUG_
161 | //printf("%d:TCP client loopback start\r\n",sn);
162 | //printf("%d:Socket opened\r\n",sn);
163 | #endif
164 | break;
165 | default:
166 | break;
167 | }
168 | return 1;
169 | }
170 |
171 |
172 | int32_t loopback_udps(uint8_t sn, uint8_t* buf, uint16_t port)
173 | {
174 | int32_t ret;
175 | uint16_t size, sentsize;
176 | uint8_t destip[4];
177 | uint16_t destport;
178 |
179 | switch(getSn_SR(sn))
180 | {
181 | case SOCK_UDP :
182 | if((size = getSn_RX_RSR(sn)) > 0)
183 | {
184 | if(size > DATA_BUF_SIZE) size = DATA_BUF_SIZE;
185 | ret = recvfrom(sn, buf, size, destip, (uint16_t*)&destport);
186 | if(ret <= 0)
187 | {
188 | #ifdef _LOOPBACK_DEBUG_
189 | printf("%d: recvfrom error. %ld\r\n",sn,ret);
190 | #endif
191 | return ret;
192 | }
193 | size = (uint16_t) ret;
194 | sentsize = 0;
195 | while(sentsize != size)
196 | {
197 | ret = sendto(sn, buf+sentsize, size-sentsize, destip, destport);
198 | if(ret < 0)
199 | {
200 | #ifdef _LOOPBACK_DEBUG_
201 | printf("%d: sendto error. %ld\r\n",sn,ret);
202 | #endif
203 | return ret;
204 | }
205 | sentsize += ret; // Don't care SOCKERR_BUSY, because it is zero.
206 | }
207 | }
208 | break;
209 | case SOCK_CLOSED:
210 | #ifdef _LOOPBACK_DEBUG_
211 | //printf("%d:UDP loopback start\r\n",sn);
212 | #endif
213 | if((ret = socket(sn, Sn_MR_UDP, port, 0x00)) != sn)
214 | return ret;
215 | #ifdef _LOOPBACK_DEBUG_
216 | printf("%d:Opened, UDP loopback, port [%d]\r\n", sn, port);
217 | #endif
218 | break;
219 | default :
220 | break;
221 | }
222 | return 1;
223 | }
224 |
225 | #endif
226 |
--------------------------------------------------------------------------------
/Drivers/ioLibrary_Driver/Application/loopback/loopback.h:
--------------------------------------------------------------------------------
1 | #ifndef _LOOPBACK_H_
2 | #define _LOOPBACK_H_
3 |
4 | #ifdef __cplusplus
5 | extern "C" {
6 | #endif
7 |
8 | #include
9 |
10 | /* Loopback test debug message printout enable */
11 | #define _LOOPBACK_DEBUG_
12 |
13 | /* DATA_BUF_SIZE define for Loopback example */
14 | #ifndef DATA_BUF_SIZE
15 | #define DATA_BUF_SIZE 2048
16 | #endif
17 |
18 | /************************/
19 | /* Select LOOPBACK_MODE */
20 | /************************/
21 | #define LOOPBACK_MAIN_NOBLOCK 0
22 | #define LOOPBACK_MODE LOOPBACK_MAIN_NOBLOCK
23 |
24 |
25 | /* TCP server Loopback test example */
26 | int32_t loopback_tcps(uint8_t sn, uint8_t* buf, uint16_t port);
27 |
28 | /* TCP client Loopback test example */
29 | int32_t loopback_tcpc(uint8_t sn, uint8_t* buf, uint8_t* destip, uint16_t destport);
30 |
31 | /* UDP Loopback test example */
32 | int32_t loopback_udps(uint8_t sn, uint8_t* buf, uint16_t port);
33 |
34 | #ifdef __cplusplus
35 | }
36 | #endif
37 |
38 | #endif
39 |
--------------------------------------------------------------------------------
/Drivers/ioLibrary_Driver/Application/multicast/multicast.c:
--------------------------------------------------------------------------------
1 | #include "multicast.h"
2 | #include
3 | #include "socket.h"
4 | #include "wizchip_conf.h"
5 |
6 |
7 | int32_t multicast_loopback(uint8_t sn, uint8_t* buf, uint8_t* multicast_ip, uint16_t multicast_port)
8 | {
9 | int32_t ret;
10 | uint16_t size, sentsize;
11 | uint8_t destip[4];
12 | uint16_t destport, port=3000;
13 |
14 | switch(getSn_SR(sn))
15 | {
16 | case SOCK_UDP :
17 | if((size = getSn_RX_RSR(sn)) > 0)
18 | {
19 | if(size > DATA_BUF_SIZE) size = DATA_BUF_SIZE;
20 | ret = recvfrom(sn, buf, size, destip, (uint16_t*)&destport);
21 | if(ret <= 0)
22 | {
23 | #ifdef _MULTICAST_DEBUG_
24 | printf("%d: recvfrom error. %ld\r\n",sn,ret);
25 | #endif
26 | return ret;
27 | }
28 | size = (uint16_t) ret;
29 | sentsize = 0;
30 | while(sentsize != size)
31 | {
32 | ret = sendto(sn, buf+sentsize, size-sentsize, destip, destport);
33 | if(ret < 0)
34 | {
35 | #ifdef _MULTICAST_DEBUG_
36 | printf("%d: sendto error. %ld\r\n",sn,ret);
37 | #endif
38 | return ret;
39 | }
40 | sentsize += ret; // Don't care SOCKERR_BUSY, because it is zero.
41 | }
42 | }
43 |
44 | break;
45 | case SOCK_CLOSED:
46 | #ifdef _MULTICAST_DEBUG_
47 | printf("%d:Multicast Loopback start\r\n",sn);
48 | #endif
49 | setSn_DIPR(0, multicast_ip);
50 | setSn_DPORT(0, multicast_port);
51 | if((ret = socket(sn, Sn_MR_UDP, port, Sn_MR_MULTI)) != sn)
52 | return ret;
53 | #ifdef _MULTICAST_DEBUG_
54 | printf("%d:Opened, UDP Multicast Socket\r\n", sn);
55 | printf("%d:Multicast Group IP - %d.%d.%d.%d\r\n", sn, multicast_ip[0], multicast_ip[1], multicast_ip[2], multicast_ip[3]);
56 | printf("%d:Multicast Group Port - %d\r\n", sn, multicast_port);
57 | #endif
58 | break;
59 | default :
60 | break;
61 | }
62 | return 1;
63 | }
64 |
65 | int32_t multicast_recv(uint8_t sn, uint8_t* buf, uint8_t* multicast_ip, uint16_t multicast_port)
66 | {
67 | int32_t ret;
68 | uint16_t size, port=3000;
69 | uint8_t destip[4];
70 | uint16_t destport;
71 |
72 | switch(getSn_SR(sn))
73 | {
74 | case SOCK_UDP :
75 | if((size = getSn_RX_RSR(sn)) > 0)
76 | {
77 | if(size > DATA_BUF_SIZE) size = DATA_BUF_SIZE;
78 | ret = recvfrom(sn, buf, size, destip, (uint16_t*)&destport);
79 | if(ret <= 0)
80 | {
81 | #ifdef _MULTICAST_DEBUG_
82 | printf("%d: recvfrom error. %ld\r\n",sn,ret);
83 | #endif
84 | return ret;
85 | }
86 | size = (uint16_t) ret;
87 | #ifdef _MULTICAST_DEBUG_
88 | printf("\r\nrecv size : %d\r\n", size);
89 | for(int i=0; i
9 |
10 | /* Multicast test debug message printout enable */
11 | #define _MULTICAST_DEBUG_
12 |
13 | #ifndef DATA_BUF_SIZE
14 | #define DATA_BUF_SIZE 2048
15 | #endif
16 |
17 | /* UDP Multicast Loopback test example */
18 | int32_t multicast_loopback(uint8_t sn, uint8_t* buf, uint8_t* multicast_ip, uint16_t multicast_port);
19 |
20 | /* UDP Multicast Recv test example */
21 | int32_t multicast_recv(uint8_t sn, uint8_t* buf, uint8_t* multicast_ip, uint16_t multicast_port);
22 |
23 |
24 | #ifdef __cplusplus
25 | }
26 | #endif
27 |
28 | #endif
29 |
--------------------------------------------------------------------------------
/Drivers/ioLibrary_Driver/Ethernet/Socket_APIs_V3.0.3.chm:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/JustForFunOk/W5500_STM32_HAL/418c98979f3f053e8df5afad984749725af42133/Drivers/ioLibrary_Driver/Ethernet/Socket_APIs_V3.0.3.chm
--------------------------------------------------------------------------------
/Drivers/ioLibrary_Driver/Internet/DHCP/dhcp.h:
--------------------------------------------------------------------------------
1 | //*****************************************************************************
2 | //
3 | //! \file dhcp.h
4 | //! \brief DHCP APIs Header file.
5 | //! \details Processig DHCP protocol as DISCOVER, OFFER, REQUEST, ACK, NACK and DECLINE.
6 | //! \version 1.1.1
7 | //! \date 2019/10/08
8 | //! \par Revision history
9 | //! <2019/10/08> compare DHCP server ip address
10 | //! <2013/11/18> 1st Release
11 | //! <2012/12/20> V1.1.0
12 | //! 1. Move unreferenced DEFINE to dhcp.c
13 | //! <2012/12/26> V1.1.1
14 | //! \author Eric Jung & MidnightCow
15 | //! \copyright
16 | //!
17 | //! Copyright (c) 2013, WIZnet Co., LTD.
18 | //! All rights reserved.
19 | //!
20 | //! Redistribution and use in source and binary forms, with or without
21 | //! modification, are permitted provided that the following conditions
22 | //! are met:
23 | //!
24 | //! * Redistributions of source code must retain the above copyright
25 | //! notice, this list of conditions and the following disclaimer.
26 | //! * Redistributions in binary form must reproduce the above copyright
27 | //! notice, this list of conditions and the following disclaimer in the
28 | //! documentation and/or other materials provided with the distribution.
29 | //! * Neither the name of the nor the names of its
30 | //! contributors may be used to endorse or promote products derived
31 | //! from this software without specific prior written permission.
32 | //!
33 | //! THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
34 | //! AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
35 | //! IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
36 | //! ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
37 | //! LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
38 | //! CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
39 | //! SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
40 | //! INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
41 | //! CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
42 | //! ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
43 | //! THE POSSIBILITY OF SUCH DAMAGE.
44 | //
45 | //*****************************************************************************
46 | #ifndef _DHCP_H_
47 | #define _DHCP_H_
48 |
49 | #ifdef __cplusplus
50 | extern "C" {
51 | #endif
52 |
53 | /*
54 | * @brief
55 | * @details If you want to display debug & processing message, Define _DHCP_DEBUG_
56 | * @note If defined, it depends on
57 | */
58 | //#define _DHCP_DEBUG_
59 |
60 |
61 | /* Retry to processing DHCP */
62 | #define MAX_DHCP_RETRY 2 ///< Maximum retry count
63 | #define DHCP_WAIT_TIME 10 ///< Wait Time 10s
64 |
65 |
66 | /* UDP port numbers for DHCP */
67 | #define DHCP_SERVER_PORT 67 ///< DHCP server port number
68 | #define DHCP_CLIENT_PORT 68 ///< DHCP client port number
69 |
70 |
71 | #define MAGIC_COOKIE 0x63825363 ///< You should not modify it number.
72 |
73 | #define DCHP_HOST_NAME "WIZnet\0"
74 |
75 | /*
76 | * @brief return value of @ref DHCP_run()
77 | */
78 | enum
79 | {
80 | DHCP_FAILED = 0, ///< Processing Fail
81 | DHCP_RUNNING, ///< Processing DHCP protocol
82 | DHCP_IP_ASSIGN, ///< First Occupy IP from DHPC server (if cbfunc == null, act as default default_ip_assign)
83 | DHCP_IP_CHANGED, ///< Change IP address by new ip from DHCP (if cbfunc == null, act as default default_ip_update)
84 | DHCP_IP_LEASED, ///< Stand by
85 | DHCP_STOPPED ///< Stop processing DHCP protocol
86 | };
87 |
88 | /*
89 | * @brief DHCP client initialization (outside of the main loop)
90 | * @param s - socket number
91 | * @param buf - buffer for processing DHCP message
92 | */
93 | void DHCP_init(uint8_t s, uint8_t * buf);
94 |
95 | /*
96 | * @brief DHCP 1s Tick Timer handler
97 | * @note SHOULD BE register to your system 1s Tick timer handler
98 | */
99 | void DHCP_time_handler(void);
100 |
101 | /*
102 | * @brief Register call back function
103 | * @param ip_assign - callback func when IP is assigned from DHCP server first
104 | * @param ip_update - callback func when IP is changed
105 | * @param ip_conflict - callback func when the assigned IP is conflict with others.
106 | */
107 | void reg_dhcp_cbfunc(void(*ip_assign)(void), void(*ip_update)(void), void(*ip_conflict)(void));
108 |
109 | /*
110 | * @brief DHCP client in the main loop
111 | * @return The value is as the follow \n
112 | * @ref DHCP_FAILED \n
113 | * @ref DHCP_RUNNING \n
114 | * @ref DHCP_IP_ASSIGN \n
115 | * @ref DHCP_IP_CHANGED \n
116 | * @ref DHCP_IP_LEASED \n
117 | * @ref DHCP_STOPPED \n
118 | *
119 | * @note This function is always called by you main task.
120 | */
121 | uint8_t DHCP_run(void);
122 |
123 | /*
124 | * @brief Stop DHCP processing
125 | * @note If you want to restart. call DHCP_init() and DHCP_run()
126 | */
127 | void DHCP_stop(void);
128 |
129 | /* Get Network information assigned from DHCP server */
130 | /*
131 | * @brief Get IP address
132 | * @param ip - IP address to be returned
133 | */
134 | void getIPfromDHCP(uint8_t* ip);
135 | /*
136 | * @brief Get Gateway address
137 | * @param ip - Gateway address to be returned
138 | */
139 | void getGWfromDHCP(uint8_t* ip);
140 | /*
141 | * @brief Get Subnet mask value
142 | * @param ip - Subnet mask to be returned
143 | */
144 | void getSNfromDHCP(uint8_t* ip);
145 | /*
146 | * @brief Get DNS address
147 | * @param ip - DNS address to be returned
148 | */
149 | void getDNSfromDHCP(uint8_t* ip);
150 |
151 | /*
152 | * @brief Get the leased time by DHCP sever
153 | * @return unit 1s
154 | */
155 | uint32_t getDHCPLeasetime(void);
156 |
157 | #ifdef __cplusplus
158 | }
159 | #endif
160 |
161 | #endif /* _DHCP_H_ */
162 |
--------------------------------------------------------------------------------
/Drivers/ioLibrary_Driver/Internet/DNS/dns.h:
--------------------------------------------------------------------------------
1 | //*****************************************************************************
2 | //
3 | //! \file dns.h
4 | //! \brief DNS APIs Header file.
5 | //! \details Send DNS query & Receive DNS reponse.
6 | //! \version 1.1.0
7 | //! \date 2013/11/18
8 | //! \par Revision history
9 | //! <2013/10/21> 1st Release
10 | //! <2013/12/20> V1.1.0
11 | //! 1. Remove secondary DNS server in DNS_run
12 | //! If 1st DNS_run failed, call DNS_run with 2nd DNS again
13 | //! 2. DNS_timerHandler -> DNS_time_handler
14 | //! 3. Move the no reference define to dns.c
15 | //! 4. Integrated dns.h dns.c & dns_parse.h dns_parse.c into dns.h & dns.c
16 | //! <2013/12/20> V1.1.0
17 | //!
18 | //! \author Eric Jung & MidnightCow
19 | //! \copyright
20 | //!
21 | //! Copyright (c) 2013, WIZnet Co., LTD.
22 | //! All rights reserved.
23 | //!
24 | //! Redistribution and use in source and binary forms, with or without
25 | //! modification, are permitted provided that the following conditions
26 | //! are met:
27 | //!
28 | //! * Redistributions of source code must retain the above copyright
29 | //! notice, this list of conditions and the following disclaimer.
30 | //! * Redistributions in binary form must reproduce the above copyright
31 | //! notice, this list of conditions and the following disclaimer in the
32 | //! documentation and/or other materials provided with the distribution.
33 | //! * Neither the name of the nor the names of its
34 | //! contributors may be used to endorse or promote products derived
35 | //! from this software without specific prior written permission.
36 | //!
37 | //! THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
38 | //! AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
39 | //! IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
40 | //! ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
41 | //! LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
42 | //! CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
43 | //! SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
44 | //! INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
45 | //! CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
46 | //! ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
47 | //! THE POSSIBILITY OF SUCH DAMAGE.
48 | //
49 | //*****************************************************************************
50 |
51 | #ifndef _DNS_H_
52 | #define _DNS_H_
53 |
54 | #ifdef __cplusplus
55 | extern "C" {
56 | #endif
57 |
58 | #include
59 | /*
60 | * @brief Define it for Debug & Monitor DNS processing.
61 | * @note If defined, it dependens on
62 | */
63 | //#define _DNS_DEBUG_
64 |
65 | #define MAX_DNS_BUF_SIZE 256 ///< maximum size of DNS buffer. */
66 | /*
67 | * @brief Maxium length of your queried Domain name
68 | * @todo SHOULD BE defined it equal as or greater than your Domain name lenght + null character(1)
69 | * @note SHOULD BE careful to stack overflow because it is allocated 1.5 times as MAX_DOMAIN_NAME in stack.
70 | */
71 | #define MAX_DOMAIN_NAME 16 // for example "www.google.com"
72 |
73 | #define MAX_DNS_RETRY 2 ///< Requery Count
74 | #define DNS_WAIT_TIME 3 ///< Wait response time. unit 1s.
75 |
76 | #define IPPORT_DOMAIN 53 ///< DNS server port number
77 |
78 | #define DNS_MSG_ID 0x1122 ///< ID for DNS message. You can be modifyed it any number
79 | /*
80 | * @brief DNS process initialize
81 | * @param s : Socket number for DNS
82 | * @param buf : Buffer for DNS message
83 | */
84 | void DNS_init(uint8_t s, uint8_t * buf);
85 |
86 | /*
87 | * @brief DNS process
88 | * @details Send DNS query and receive DNS response
89 | * @param dns_ip : DNS server ip
90 | * @param name : Domain name to be queryed
91 | * @param ip_from_dns : IP address from DNS server
92 | * @return -1 : failed. @ref MAX_DOMIN_NAME is too small \n
93 | * 0 : failed (Timeout or Parse error)\n
94 | * 1 : success
95 | * @note This funtion blocks until success or fail. max time = @ref MAX_DNS_RETRY * @ref DNS_WAIT_TIME
96 | */
97 | int8_t DNS_run(uint8_t * dns_ip, uint8_t * name, uint8_t * ip_from_dns);
98 |
99 | /*
100 | * @brief DNS 1s Tick Timer handler
101 | * @note SHOULD BE register to your system 1s Tick timer handler
102 | */
103 | void DNS_time_handler(void);
104 |
105 | #ifdef __cplusplus
106 | }
107 | #endif
108 |
109 | #endif /* _DNS_H_ */
110 |
--------------------------------------------------------------------------------
/Drivers/ioLibrary_Driver/Internet/FTPClient/ftpc.h:
--------------------------------------------------------------------------------
1 | #ifndef _FTPC_H_
2 | #define _FTPC_H_
3 |
4 | #ifdef __cplusplus
5 | extern "C" {
6 | #endif
7 |
8 | #include
9 | #include
10 | #include
11 | #include
12 | #include
13 | #include
14 | #include "stdio_private.h"
15 | #include "socket.h"
16 |
17 | #define F_APP_FTPC
18 |
19 | /* If your target support a file system, you have to activate this feature and implement. */
20 | //#define F_FILESYSTEM
21 |
22 | /* Change to your Chipset Uart function, you have to activate this feature and implement.
23 | * Change!! -> Board_UARTGetCharBlocking()
24 | * Below is an example of a function of lpc_chip library. */
25 | //#define ftp_getc() Board_UARTGetCharBlocking()
26 |
27 | #ifdef F_FILESYSTEM
28 | #include "ff.h"
29 | #endif
30 |
31 | #ifndef ftp_getc()
32 | #define Need_UARTGetCharBlocking_func
33 | #else
34 | /* Change library
35 | * Change!! -> board_api.h,
36 | * Below is an example of a function of lpc_chip library. */
37 | #include "board_api.h"
38 | #endif
39 |
40 |
41 | #define LINELEN 100
42 | #ifndef F_FILESYSTEM
43 | #define _MAX_SS 512
44 | #endif
45 |
46 | #define CTRL_SOCK 2
47 | #define DATA_SOCK 3
48 |
49 | /* FTP Responses */
50 | #define R_150 150 /* File status ok; opening data conn */
51 | #define R_200 200 /* 'Generic' command ok */
52 | #define R_220 220 /* Service ready for new user. */
53 | #define R_226 226 /* Closing data connection. File transfer/abort successful */
54 | #define R_227 227 /* Entering passive mode (h1,h2,h3,h4,p1,p2) */
55 | #define R_230 230 /* User logged in, proceed */
56 | #define R_331 331 /* User name okay, need password. */
57 |
58 | #define TransferAscii 'A'
59 | #define TransferBinary 'I'
60 |
61 | enum ftpc_type {
62 | ASCII_TYPE,
63 | IMAGE_TYPE,
64 | };
65 |
66 | enum ftpc_datasock_state{
67 | DATASOCK_IDLE,
68 | DATASOCK_READY,
69 | DATASOCK_START
70 | };
71 |
72 | enum ftpc_datasock_mode{
73 | PASSIVE_MODE,
74 | ACTIVE_MODE
75 | };
76 | enum CommandFirst {
77 | f_nocmd,
78 | f_dir,
79 | f_put,
80 | f_get,
81 | };
82 | enum CommandSecond {
83 | s_nocmd,
84 | s_dir,
85 | s_put,
86 | s_get,
87 | };
88 | struct Command {
89 | enum CommandFirst First;
90 | enum CommandSecond Second;
91 | };
92 | struct ftpc {
93 | uint8_t control; /* Control stream */
94 | uint8_t data; /* Data stream */
95 |
96 | enum ftpc_type type; /* Transfer type */
97 |
98 | enum ftpc_datasock_state dsock_state;
99 | enum ftpc_datasock_mode dsock_mode;
100 |
101 | char workingdir[LINELEN];
102 | char filename[LINELEN];
103 |
104 | #ifdef F_FILESYSTEM
105 | FIL fil; // FatFs File objects
106 | FRESULT fr; // FatFs function common result code
107 | #endif
108 | };
109 |
110 | #ifndef un_I2cval
111 | typedef union _un_l2cval {
112 | uint32_t lVal;
113 | uint8_t cVal[4];
114 | }un_l2cval;
115 | #endif
116 |
117 | void ftpc_init(uint8_t * src_ip);
118 | uint8_t ftpc_run(uint8_t * dbuf);
119 | char proc_ftpc(char * buf);
120 | int pportc(char * arg);
121 | uint8_t* User_Keyboard_MSG();
122 |
123 | #ifdef __cplusplus
124 | }
125 | #endif
126 |
127 | #endif // _FTPC_H_
128 |
--------------------------------------------------------------------------------
/Drivers/ioLibrary_Driver/Internet/FTPClient/stdio_private.h:
--------------------------------------------------------------------------------
1 | /* Copyright (c) 2002, Joerg Wunsch
2 | All rights reserved.
3 |
4 | Redistribution and use in source and binary forms, with or without
5 | modification, are permitted provided that the following conditions are met:
6 |
7 | * Redistributions of source code must retain the above copyright
8 | notice, this list of conditions and the following disclaimer.
9 | * Redistributions in binary form must reproduce the above copyright
10 | notice, this list of conditions and the following disclaimer in
11 | the documentation and/or other materials provided with the
12 | distribution.
13 | * Neither the name of the copyright holders nor the names of
14 | contributors may be used to endorse or promote products derived
15 | from 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 | /* $Id: stdio_private.h,v 1.6 2003/01/07 22:17:24 joerg_wunsch Exp $ */
31 |
32 | #ifdef __cplusplus
33 | extern "C" {
34 | #endif
35 |
36 | #include
37 | #include
38 |
39 | struct __file {
40 | char *buf; /* buffer pointer */
41 | unsigned char unget; /* ungetc() buffer */
42 | uint8_t flags; /* flags, see below */
43 | #define __SRD 0x0001 /* OK to read */
44 | #define __SWR 0x0002 /* OK to write */
45 | #define __SSTR 0x0004 /* this is an sprintf/snprintf string */
46 | #define __SPGM 0x0008 /* fmt string is in progmem */
47 | #define __SERR 0x0010 /* found error */
48 | #define __SEOF 0x0020 /* found EOF */
49 | #define __SUNGET 0x040 /* ungetc() happened */
50 | #if 0
51 | /* possible future extensions, will require uint16_t flags */
52 | #define __SRW 0x0080 /* open for reading & writing */
53 | #define __SLBF 0x0100 /* line buffered */
54 | #define __SNBF 0x0200 /* unbuffered */
55 | #define __SMBF 0x0400 /* buf is from malloc */
56 | #endif
57 | int size; /* size of buffer */
58 | int len; /* characters read or written so far */
59 | int (*put)(char); /* function to write one char to device */
60 | int (*get)(void); /* function to read one char from device */
61 | };
62 |
63 | /* values for PRINTF_LEVEL */
64 | #define PRINTF_MIN 1
65 | #define PRINTF_STD 2
66 | #define PRINTF_FLT 3
67 |
68 | /* values for SCANF_LEVEL */
69 | #define SCANF_MIN 1
70 | #define SCANF_STD 2
71 | #define SCANF_FLT 3
72 |
73 | #ifdef __cplusplus
74 | }
75 | #endif
76 |
--------------------------------------------------------------------------------
/Drivers/ioLibrary_Driver/Internet/FTPServer/ftpd.h:
--------------------------------------------------------------------------------
1 | #ifndef _FTPD_H_
2 | #define _FTPD_H_
3 |
4 | #ifdef __cplusplus
5 | extern "C" {
6 | #endif
7 |
8 | /*
9 | * Wiznet.
10 | * (c) Copyright 2002, Wiznet.
11 | *
12 | * Filename : ftpd.h
13 | * Version : 1.0
14 | * Programmer(s) :
15 | * Created : 2003/01/28
16 | * Description : Header file of FTP daemon. (AVR-GCC Compiler)
17 | */
18 |
19 | #include
20 |
21 | //#define F_FILESYSTEM // If your target support a file system, you have to activate this feature and implement.
22 |
23 | #if defined(F_FILESYSTEM)
24 | #include "ff.h"
25 | #endif
26 |
27 | #define F_APP_FTP
28 | #define _FTP_DEBUG_
29 |
30 |
31 | #define LINELEN 100
32 | //#define DATA_BUF_SIZE 100
33 | #if !defined(F_FILESYSTEM)
34 | #define _MAX_SS 512
35 | #endif
36 |
37 | #define CTRL_SOCK 2
38 | #define DATA_SOCK 3
39 |
40 | #define IPPORT_FTPD 20 /* FTP Data port */
41 | #define IPPORT_FTP 21 /* FTP Control port */
42 |
43 | #define HOSTNAME "iinChip"
44 | #define VERSION "1.0"
45 |
46 | #define FILENAME "a.txt"
47 |
48 | /* FTP commands */
49 | enum ftp_cmd {
50 | USER_CMD,
51 | ACCT_CMD,
52 | PASS_CMD,
53 | TYPE_CMD,
54 | LIST_CMD,
55 | CWD_CMD,
56 | DELE_CMD,
57 | NAME_CMD,
58 | QUIT_CMD,
59 | RETR_CMD,
60 | STOR_CMD,
61 | PORT_CMD,
62 | NLST_CMD,
63 | PWD_CMD,
64 | XPWD_CMD,
65 | MKD_CMD,
66 | XMKD_CMD,
67 | XRMD_CMD,
68 | RMD_CMD,
69 | STRU_CMD,
70 | MODE_CMD,
71 | SYST_CMD,
72 | XMD5_CMD,
73 | XCWD_CMD,
74 | FEAT_CMD,
75 | PASV_CMD,
76 | SIZE_CMD,
77 | MLSD_CMD,
78 | APPE_CMD,
79 | NO_CMD,
80 | };
81 |
82 | enum ftp_type {
83 | ASCII_TYPE,
84 | IMAGE_TYPE,
85 | LOGICAL_TYPE
86 | };
87 |
88 | enum ftp_state {
89 | FTPS_NOT_LOGIN,
90 | FTPS_LOGIN
91 | };
92 |
93 | enum datasock_state{
94 | DATASOCK_IDLE,
95 | DATASOCK_READY,
96 | DATASOCK_START
97 | };
98 |
99 | enum datasock_mode{
100 | PASSIVE_MODE,
101 | ACTIVE_MODE
102 | };
103 |
104 | struct ftpd {
105 | uint8_t control; /* Control stream */
106 | uint8_t data; /* Data stream */
107 |
108 | enum ftp_type type; /* Transfer type */
109 | enum ftp_state state;
110 |
111 | enum ftp_cmd current_cmd;
112 |
113 | enum datasock_state dsock_state;
114 | enum datasock_mode dsock_mode;
115 |
116 | char username[LINELEN]; /* Arg to USER command */
117 | char workingdir[LINELEN];
118 | char filename[LINELEN];
119 |
120 | #if defined(F_FILESYSTEM)
121 | FIL fil; // FatFs File objects
122 | FRESULT fr; // FatFs function common result code
123 | #endif
124 |
125 | };
126 |
127 | #ifndef un_I2cval
128 | typedef union _un_l2cval {
129 | uint32_t lVal;
130 | uint8_t cVal[4];
131 | }un_l2cval;
132 | #endif
133 |
134 | void ftpd_init(uint8_t * src_ip);
135 | uint8_t ftpd_run(uint8_t * dbuf);
136 | char proc_ftpd(char * buf);
137 | char ftplogin(char * pass);
138 | int pport(char * arg);
139 |
140 | int sendit(char * command);
141 | int recvit(char * command);
142 |
143 | long sendfile(uint8_t s, char * command);
144 | long recvfile(uint8_t s);
145 |
146 | #if defined(F_FILESYSTEM)
147 | void print_filedsc(FIL *fil);
148 | #endif
149 |
150 | #ifdef __cplusplus
151 | }
152 | #endif
153 |
154 | #endif // _FTPD_H_
155 |
--------------------------------------------------------------------------------
/Drivers/ioLibrary_Driver/Internet/FTPServer/stdio_private.h:
--------------------------------------------------------------------------------
1 | /* Copyright (c) 2002, Joerg Wunsch
2 | All rights reserved.
3 |
4 | Redistribution and use in source and binary forms, with or without
5 | modification, are permitted provided that the following conditions are met:
6 |
7 | * Redistributions of source code must retain the above copyright
8 | notice, this list of conditions and the following disclaimer.
9 | * Redistributions in binary form must reproduce the above copyright
10 | notice, this list of conditions and the following disclaimer in
11 | the documentation and/or other materials provided with the
12 | distribution.
13 | * Neither the name of the copyright holders nor the names of
14 | contributors may be used to endorse or promote products derived
15 | from 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 | /* $Id: stdio_private.h,v 1.6 2003/01/07 22:17:24 joerg_wunsch Exp $ */
31 | #ifdef __cplusplus
32 | extern "C" {
33 | #endif
34 |
35 | #include
36 | #include
37 |
38 | struct __file {
39 | char *buf; /* buffer pointer */
40 | unsigned char unget; /* ungetc() buffer */
41 | uint8_t flags; /* flags, see below */
42 | #define __SRD 0x0001 /* OK to read */
43 | #define __SWR 0x0002 /* OK to write */
44 | #define __SSTR 0x0004 /* this is an sprintf/snprintf string */
45 | #define __SPGM 0x0008 /* fmt string is in progmem */
46 | #define __SERR 0x0010 /* found error */
47 | #define __SEOF 0x0020 /* found EOF */
48 | #define __SUNGET 0x040 /* ungetc() happened */
49 | #if 0
50 | /* possible future extensions, will require uint16_t flags */
51 | #define __SRW 0x0080 /* open for reading & writing */
52 | #define __SLBF 0x0100 /* line buffered */
53 | #define __SNBF 0x0200 /* unbuffered */
54 | #define __SMBF 0x0400 /* buf is from malloc */
55 | #endif
56 | int size; /* size of buffer */
57 | int len; /* characters read or written so far */
58 | int (*put)(char); /* function to write one char to device */
59 | int (*get)(void); /* function to read one char from device */
60 | };
61 |
62 | /* values for PRINTF_LEVEL */
63 | #define PRINTF_MIN 1
64 | #define PRINTF_STD 2
65 | #define PRINTF_FLT 3
66 |
67 | /* values for SCANF_LEVEL */
68 | #define SCANF_MIN 1
69 | #define SCANF_STD 2
70 | #define SCANF_FLT 3
71 |
72 | #ifdef __cplusplus
73 | }
74 | #endif
75 |
--------------------------------------------------------------------------------
/Drivers/ioLibrary_Driver/Internet/MQTT/MQTTClient.h:
--------------------------------------------------------------------------------
1 | /*******************************************************************************
2 | * Copyright (c) 2014, 2015 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/Ian Craggs - initial API and implementation and/or initial documentation
15 | * Ian Craggs - documentation and platform specific header
16 | *******************************************************************************/
17 |
18 | #if !defined(__MQTT_CLIENT_C_)
19 | #define __MQTT_CLIENT_C_
20 |
21 | #if defined(__cplusplus)
22 | extern "C" {
23 | #endif
24 |
25 | #if defined(WIN32_DLL) || defined(WIN64_DLL)
26 | #define DLLImport __declspec(dllimport)
27 | #define DLLExport __declspec(dllexport)
28 | #elif defined(LINUX_SO)
29 | #define DLLImport extern
30 | #define DLLExport __attribute__ ((visibility ("default")))
31 | #else
32 | #define DLLImport
33 | #define DLLExport
34 | #endif
35 |
36 | #include "./MQTTPacket/src/MQTTPacket.h"
37 | #include "stdio.h"
38 | #include "mqtt_interface.h"
39 |
40 | #define MAX_PACKET_ID 65535 /* according to the MQTT specification - do not change! */
41 |
42 | #if !defined(MAX_MESSAGE_HANDLERS)
43 | #define MAX_MESSAGE_HANDLERS 5 /* redefinable - how many subscriptions do you want? */
44 | #endif
45 |
46 | enum QoS { QOS0, QOS1, QOS2 };
47 |
48 | /* all failure return codes must be negative */
49 | enum returnCode { BUFFER_OVERFLOW = -2, FAILURE = -1, SUCCESSS = 0 };
50 |
51 | /* The Platform specific header must define the Network and Timer structures and functions
52 | * which operate on them.
53 | *
54 | typedef struct Network
55 | {
56 | int (*mqttread)(Network*, unsigned char* read_buffer, int, int);
57 | int (*mqttwrite)(Network*, unsigned char* send_buffer, int, int);
58 | } Network;*/
59 |
60 | /* The Timer structure must be defined in the platform specific header,
61 | * and have the following functions to operate on it. */
62 | extern void TimerInit(Timer*);
63 | extern char TimerIsExpired(Timer*);
64 | extern void TimerCountdownMS(Timer*, unsigned int);
65 | extern void TimerCountdown(Timer*, unsigned int);
66 | extern int TimerLeftMS(Timer*);
67 |
68 | typedef struct MQTTMessage
69 | {
70 | enum QoS qos;
71 | unsigned char retained;
72 | unsigned char dup;
73 | unsigned short id;
74 | void *payload;
75 | size_t payloadlen;
76 | } MQTTMessage;
77 |
78 | typedef struct MessageData
79 | {
80 | MQTTMessage* message;
81 | MQTTString* topicName;
82 | } MessageData;
83 |
84 | typedef void (*messageHandler)(MessageData*);
85 |
86 | typedef struct MQTTClient
87 | {
88 | unsigned int next_packetid,
89 | command_timeout_ms;
90 | size_t buf_size,
91 | readbuf_size;
92 | unsigned char *buf,
93 | *readbuf;
94 | unsigned int keepAliveInterval;
95 | char ping_outstanding;
96 | int isconnected;
97 |
98 | struct MessageHandlers
99 | {
100 | const char* topicFilter;
101 | void (*fp) (MessageData*);
102 | } messageHandlers[MAX_MESSAGE_HANDLERS]; /* Message handlers are indexed by subscription topic */
103 |
104 | void (*defaultMessageHandler) (MessageData*);
105 |
106 | Network* ipstack;
107 | Timer ping_timer;
108 | #if defined(MQTT_TASK)
109 | Mutex mutex;
110 | Thread thread;
111 | #endif
112 | } MQTTClient;
113 |
114 | #define DefaultClient {0, 0, 0, 0, NULL, NULL, 0, 0, 0}
115 |
116 |
117 | /**
118 | * Create an MQTT client object
119 | * @param client
120 | * @param network
121 | * @param command_timeout_ms
122 | * @param
123 | */
124 | DLLExport void MQTTClientInit(MQTTClient* client, Network* network, unsigned int command_timeout_ms,
125 | unsigned char* sendbuf, size_t sendbuf_size, unsigned char* readbuf, size_t readbuf_size);
126 |
127 | /** MQTT Connect - send an MQTT connect packet down the network and wait for a Connack
128 | * The nework object must be connected to the network endpoint before calling this
129 | * @param options - connect options
130 | * @return success code
131 | */
132 | DLLExport int MQTTConnect(MQTTClient* client, MQTTPacket_connectData* options);
133 |
134 | /** MQTT Publish - send an MQTT publish packet and wait for all acks to complete for all QoSs
135 | * @param client - the client object to use
136 | * @param topic - the topic to publish to
137 | * @param message - the message to send
138 | * @return success code
139 | */
140 | DLLExport int MQTTPublish(MQTTClient* client, const char*, MQTTMessage*);
141 |
142 | /** MQTT Subscribe - send an MQTT subscribe packet and wait for suback before returning.
143 | * @param client - the client object to use
144 | * @param topicFilter - the topic filter to subscribe to
145 | * @param message - the message to send
146 | * @return success code
147 | */
148 | DLLExport int MQTTSubscribe(MQTTClient* client, const char* topicFilter, enum QoS, messageHandler);
149 |
150 | /** MQTT Subscribe - send an MQTT unsubscribe packet and wait for unsuback before returning.
151 | * @param client - the client object to use
152 | * @param topicFilter - the topic filter to unsubscribe from
153 | * @return success code
154 | */
155 | DLLExport int MQTTUnsubscribe(MQTTClient* client, const char* topicFilter);
156 |
157 | /** MQTT Disconnect - send an MQTT disconnect packet and close the connection
158 | * @param client - the client object to use
159 | * @return success code
160 | */
161 | DLLExport int MQTTDisconnect(MQTTClient* client);
162 |
163 | /** MQTT Yield - MQTT background
164 | * @param client - the client object to use
165 | * @param time - the time, in milliseconds, to yield for
166 | * @return success code
167 | */
168 | DLLExport int MQTTYield(MQTTClient* client, int time);
169 |
170 | #if defined(MQTT_TASK)
171 | /** MQTT start background thread for a client. After this, MQTTYield should not be called.
172 | * @param client - the client object to use
173 | * @return success code
174 | */
175 | DLLExport int MQTTStartTask(MQTTClient* client);
176 | #endif
177 |
178 | #if defined(__cplusplus)
179 | }
180 | #endif
181 |
182 | #endif
183 |
--------------------------------------------------------------------------------
/Drivers/ioLibrary_Driver/Internet/MQTT/MQTTPacket/src/MQTTConnect.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 | * Ian Craggs - initial API and implementation and/or initial documentation
15 | * Xiang Rong - 442039 Add makefile to Embedded C client
16 | *******************************************************************************/
17 |
18 | #ifndef MQTTCONNECT_H_
19 | #define MQTTCONNECT_H_
20 |
21 | #if !defined(DLLImport)
22 | #define DLLImport
23 | #endif
24 | #if !defined(DLLExport)
25 | #define DLLExport
26 | #endif
27 |
28 |
29 | typedef union
30 | {
31 | unsigned char all; /**< all connect flags */
32 | #if defined(REVERSED)
33 | struct
34 | {
35 | unsigned int username : 1; /**< 3.1 user name */
36 | unsigned int password : 1; /**< 3.1 password */
37 | unsigned int willRetain : 1; /**< will retain setting */
38 | unsigned int willQoS : 2; /**< will QoS value */
39 | unsigned int will : 1; /**< will flag */
40 | unsigned int cleansession : 1; /**< clean session flag */
41 | unsigned int : 1; /**< unused */
42 | } bits;
43 | #else
44 | struct
45 | {
46 | unsigned int : 1; /**< unused */
47 | unsigned int cleansession : 1; /**< cleansession flag */
48 | unsigned int will : 1; /**< will flag */
49 | unsigned int willQoS : 2; /**< will QoS value */
50 | unsigned int willRetain : 1; /**< will retain setting */
51 | unsigned int password : 1; /**< 3.1 password */
52 | unsigned int username : 1; /**< 3.1 user name */
53 | } bits;
54 | #endif
55 | } MQTTConnectFlags; /**< connect flags byte */
56 |
57 |
58 |
59 | /**
60 | * Defines the MQTT "Last Will and Testament" (LWT) settings for
61 | * the connect packet.
62 | */
63 | typedef struct
64 | {
65 | /** The eyecatcher for this structure. must be MQTW. */
66 | char struct_id[4];
67 | /** The version number of this structure. Must be 0 */
68 | int struct_version;
69 | /** The LWT topic to which the LWT message will be published. */
70 | MQTTString topicName;
71 | /** The LWT payload. */
72 | MQTTString message;
73 | /**
74 | * The retained flag for the LWT message (see MQTTAsync_message.retained).
75 | */
76 | unsigned char retained;
77 | /**
78 | * The quality of service setting for the LWT message (see
79 | * MQTTAsync_message.qos and @ref qos).
80 | */
81 | char qos;
82 | } MQTTPacket_willOptions;
83 |
84 |
85 | #define MQTTPacket_willOptions_initializer { {'M', 'Q', 'T', 'W'}, 0, {NULL, {0, NULL}}, {NULL, {0, NULL}}, 0, 0 }
86 |
87 |
88 | typedef struct
89 | {
90 | /** The eyecatcher for this structure. must be MQTC. */
91 | char struct_id[4];
92 | /** The version number of this structure. Must be 0 */
93 | int struct_version;
94 | /** Version of MQTT to be used. 3 = 3.1 4 = 3.1.1
95 | */
96 | unsigned char MQTTVersion;
97 | MQTTString clientID;
98 | unsigned short keepAliveInterval;
99 | unsigned char cleansession;
100 | unsigned char willFlag;
101 | MQTTPacket_willOptions will;
102 | MQTTString username;
103 | MQTTString password;
104 | } MQTTPacket_connectData;
105 |
106 | typedef union
107 | {
108 | unsigned char all; /**< all connack flags */
109 | #if defined(REVERSED)
110 | struct
111 | {
112 | unsigned int sessionpresent : 1; /**< session present flag */
113 | unsigned int : 7; /**< unused */
114 | } bits;
115 | #else
116 | struct
117 | {
118 | unsigned int : 7; /**< unused */
119 | unsigned int sessionpresent : 1; /**< session present flag */
120 | } bits;
121 | #endif
122 | } MQTTConnackFlags; /**< connack flags byte */
123 |
124 | #define MQTTPacket_connectData_initializer { {'M', 'Q', 'T', 'C'}, 0, 4, {NULL, {0, NULL}}, 60, 1, 0, \
125 | MQTTPacket_willOptions_initializer, {NULL, {0, NULL}}, {NULL, {0, NULL}} }
126 |
127 | DLLExport int MQTTSerialize_connect(unsigned char* buf, int buflen, MQTTPacket_connectData* options);
128 | DLLExport int MQTTDeserialize_connect(MQTTPacket_connectData* data, unsigned char* buf, int len);
129 |
130 | DLLExport int MQTTSerialize_connack(unsigned char* buf, int buflen, unsigned char connack_rc, unsigned char sessionPresent);
131 | DLLExport int MQTTDeserialize_connack(unsigned char* sessionPresent, unsigned char* connack_rc, unsigned char* buf, int buflen);
132 |
133 | DLLExport int MQTTSerialize_disconnect(unsigned char* buf, int buflen);
134 | DLLExport int MQTTSerialize_pingreq(unsigned char* buf, int buflen);
135 |
136 | #endif /* MQTTCONNECT_H_ */
137 |
--------------------------------------------------------------------------------
/Drivers/ioLibrary_Driver/Internet/MQTT/MQTTPacket/src/MQTTConnectClient.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 | * Ian Craggs - initial API and implementation and/or initial documentation
15 | *******************************************************************************/
16 |
17 | #include "MQTTPacket.h"
18 | #include "StackTrace.h"
19 |
20 | #include
21 |
22 | /**
23 | * Determines the length of the MQTT connect packet that would be produced using the supplied connect options.
24 | * @param options the options to be used to build the connect packet
25 | * @return the length of buffer needed to contain the serialized version of the packet
26 | */
27 | int MQTTSerialize_connectLength(MQTTPacket_connectData* options)
28 | {
29 | int len = 0;
30 |
31 | FUNC_ENTRY;
32 |
33 | if (options->MQTTVersion == 3)
34 | len = 12; /* variable depending on MQTT or MQIsdp */
35 | else if (options->MQTTVersion == 4)
36 | len = 10;
37 |
38 | len += MQTTstrlen(options->clientID)+2;
39 | if (options->willFlag)
40 | len += MQTTstrlen(options->will.topicName)+2 + MQTTstrlen(options->will.message)+2;
41 | if (options->username.cstring || options->username.lenstring.data)
42 | len += MQTTstrlen(options->username)+2;
43 | if (options->password.cstring || options->password.lenstring.data)
44 | len += MQTTstrlen(options->password)+2;
45 |
46 | FUNC_EXIT_RC(len);
47 | return len;
48 | }
49 |
50 |
51 | /**
52 | * Serializes the connect options into the buffer.
53 | * @param buf the buffer into which the packet will be serialized
54 | * @param len the length in bytes of the supplied buffer
55 | * @param options the options to be used to build the connect packet
56 | * @return serialized length, or error if 0
57 | */
58 | int MQTTSerialize_connect(unsigned char* buf, int buflen, MQTTPacket_connectData* options)
59 | {
60 | unsigned char *ptr = buf;
61 | MQTTHeader header = {0};
62 | MQTTConnectFlags flags = {0};
63 | int len = 0;
64 | int rc = -1;
65 |
66 | FUNC_ENTRY;
67 | if (MQTTPacket_len(len = MQTTSerialize_connectLength(options)) > buflen)
68 | {
69 | rc = MQTTPACKET_BUFFER_TOO_SHORT;
70 | goto exit;
71 | }
72 |
73 | header.byte = 0;
74 | header.bits.type = CONNECT;
75 | writeChar(&ptr, header.byte); /* write header */
76 |
77 | ptr += MQTTPacket_encode(ptr, len); /* write remaining length */
78 |
79 | if (options->MQTTVersion == 4)
80 | {
81 | writeCString(&ptr, "MQTT");
82 | writeChar(&ptr, (char) 4);
83 | }
84 | else
85 | {
86 | writeCString(&ptr, "MQIsdp");
87 | writeChar(&ptr, (char) 3);
88 | }
89 |
90 | flags.all = 0;
91 | flags.bits.cleansession = options->cleansession;
92 | flags.bits.will = (options->willFlag) ? 1 : 0;
93 | if (flags.bits.will)
94 | {
95 | flags.bits.willQoS = options->will.qos;
96 | flags.bits.willRetain = options->will.retained;
97 | }
98 |
99 | if (options->username.cstring || options->username.lenstring.data)
100 | flags.bits.username = 1;
101 | if (options->password.cstring || options->password.lenstring.data)
102 | flags.bits.password = 1;
103 |
104 | writeChar(&ptr, flags.all);
105 | writeInt(&ptr, options->keepAliveInterval);
106 | writeMQTTString(&ptr, options->clientID);
107 | if (options->willFlag)
108 | {
109 | writeMQTTString(&ptr, options->will.topicName);
110 | writeMQTTString(&ptr, options->will.message);
111 | }
112 | if (flags.bits.username)
113 | writeMQTTString(&ptr, options->username);
114 | if (flags.bits.password)
115 | writeMQTTString(&ptr, options->password);
116 |
117 | rc = ptr - buf;
118 |
119 | exit: FUNC_EXIT_RC(rc);
120 | return rc;
121 | }
122 |
123 |
124 | /**
125 | * Deserializes the supplied (wire) buffer into connack data - return code
126 | * @param sessionPresent the session present flag returned (only for MQTT 3.1.1)
127 | * @param connack_rc returned integer value of the connack return code
128 | * @param buf the raw buffer data, of the correct length determined by the remaining length field
129 | * @param len the length in bytes of the data in the supplied buffer
130 | * @return error code. 1 is success, 0 is failure
131 | */
132 | int MQTTDeserialize_connack(unsigned char* sessionPresent, unsigned char* connack_rc, unsigned char* buf, int buflen)
133 | {
134 | MQTTHeader header = {0};
135 | unsigned char* curdata = buf;
136 | unsigned char* enddata = NULL;
137 | int rc = 0;
138 | int mylen;
139 | MQTTConnackFlags flags = {0};
140 |
141 | FUNC_ENTRY;
142 | header.byte = readChar(&curdata);
143 | if (header.bits.type != CONNACK)
144 | goto exit;
145 |
146 | curdata += (rc = MQTTPacket_decodeBuf(curdata, &mylen)); /* read remaining length */
147 | enddata = curdata + mylen;
148 | if (enddata - curdata < 2)
149 | goto exit;
150 |
151 | flags.all = readChar(&curdata);
152 | *sessionPresent = flags.bits.sessionpresent;
153 | *connack_rc = readChar(&curdata);
154 |
155 | rc = 1;
156 | exit:
157 | FUNC_EXIT_RC(rc);
158 | return rc;
159 | }
160 |
161 |
162 | /**
163 | * Serializes a 0-length packet into the supplied buffer, ready for writing to a socket
164 | * @param buf the buffer into which the packet will be serialized
165 | * @param buflen the length in bytes of the supplied buffer, to avoid overruns
166 | * @param packettype the message type
167 | * @return serialized length, or error if 0
168 | */
169 | int MQTTSerialize_zero(unsigned char* buf, int buflen, unsigned char packettype)
170 | {
171 | MQTTHeader header = {0};
172 | int rc = -1;
173 | unsigned char *ptr = buf;
174 |
175 | FUNC_ENTRY;
176 | if (buflen < 2)
177 | {
178 | rc = MQTTPACKET_BUFFER_TOO_SHORT;
179 | goto exit;
180 | }
181 | header.byte = 0;
182 | header.bits.type = packettype;
183 | writeChar(&ptr, header.byte); /* write header */
184 |
185 | ptr += MQTTPacket_encode(ptr, 0); /* write remaining length */
186 | rc = ptr - buf;
187 | exit:
188 | FUNC_EXIT_RC(rc);
189 | return rc;
190 | }
191 |
192 |
193 | /**
194 | * Serializes a disconnect packet into the supplied buffer, ready for writing to a socket
195 | * @param buf the buffer into which the packet will be serialized
196 | * @param buflen the length in bytes of the supplied buffer, to avoid overruns
197 | * @return serialized length, or error if 0
198 | */
199 | int MQTTSerialize_disconnect(unsigned char* buf, int buflen)
200 | {
201 | return MQTTSerialize_zero(buf, buflen, DISCONNECT);
202 | }
203 |
204 |
205 | /**
206 | * Serializes a disconnect packet into the supplied buffer, ready for writing to a socket
207 | * @param buf the buffer into which the packet will be serialized
208 | * @param buflen the length in bytes of the supplied buffer, to avoid overruns
209 | * @return serialized length, or error if 0
210 | */
211 | int MQTTSerialize_pingreq(unsigned char* buf, int buflen)
212 | {
213 | return MQTTSerialize_zero(buf, buflen, PINGREQ);
214 | }
215 |
--------------------------------------------------------------------------------
/Drivers/ioLibrary_Driver/Internet/MQTT/MQTTPacket/src/MQTTConnectServer.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 | * Ian Craggs - initial API and implementation and/or initial documentation
15 | *******************************************************************************/
16 |
17 | #include "StackTrace.h"
18 | #include "MQTTPacket.h"
19 | #include
20 |
21 | #define min(a, b) ((a < b) ? a : b)
22 |
23 |
24 | /**
25 | * Validates MQTT protocol name and version combinations
26 | * @param protocol the MQTT protocol name as an MQTTString
27 | * @param version the MQTT protocol version number, as in the connect packet
28 | * @return correct MQTT combination? 1 is true, 0 is false
29 | */
30 | int MQTTPacket_checkVersion(MQTTString* protocol, int version)
31 | {
32 | int rc = 0;
33 |
34 | if (version == 3 && memcmp(protocol->lenstring.data, "MQIsdp",
35 | min(6, protocol->lenstring.len)) == 0)
36 | rc = 1;
37 | else if (version == 4 && memcmp(protocol->lenstring.data, "MQTT",
38 | min(4, protocol->lenstring.len)) == 0)
39 | rc = 1;
40 | return rc;
41 | }
42 |
43 |
44 | /**
45 | * Deserializes the supplied (wire) buffer into connect data structure
46 | * @param data the connect data structure to be filled out
47 | * @param buf the raw buffer data, of the correct length determined by the remaining length field
48 | * @param len the length in bytes of the data in the supplied buffer
49 | * @return error code. 1 is success, 0 is failure
50 | */
51 | int MQTTDeserialize_connect(MQTTPacket_connectData* data, unsigned char* buf, int len)
52 | {
53 | MQTTHeader header = {0};
54 | MQTTConnectFlags flags = {0};
55 | unsigned char* curdata = buf;
56 | unsigned char* enddata = &buf[len];
57 | int rc = 0;
58 | MQTTString Protocol;
59 | int version;
60 | int mylen = 0;
61 |
62 | FUNC_ENTRY;
63 | header.byte = readChar(&curdata);
64 | if (header.bits.type != CONNECT)
65 | goto exit;
66 |
67 | curdata += MQTTPacket_decodeBuf(curdata, &mylen); /* read remaining length */
68 |
69 | if (!readMQTTLenString(&Protocol, &curdata, enddata) ||
70 | enddata - curdata < 0) /* do we have enough data to read the protocol version byte? */
71 | goto exit;
72 |
73 | version = (int)readChar(&curdata); /* Protocol version */
74 | /* If we don't recognize the protocol version, we don't parse the connect packet on the
75 | * basis that we don't know what the format will be.
76 | */
77 | if (MQTTPacket_checkVersion(&Protocol, version))
78 | {
79 | flags.all = readChar(&curdata);
80 | data->cleansession = flags.bits.cleansession;
81 | data->keepAliveInterval = readInt(&curdata);
82 | if (!readMQTTLenString(&data->clientID, &curdata, enddata))
83 | goto exit;
84 | data->willFlag = flags.bits.will;
85 | if (flags.bits.will)
86 | {
87 | data->will.qos = flags.bits.willQoS;
88 | data->will.retained = flags.bits.willRetain;
89 | if (!readMQTTLenString(&data->will.topicName, &curdata, enddata) ||
90 | !readMQTTLenString(&data->will.message, &curdata, enddata))
91 | goto exit;
92 | }
93 | if (flags.bits.username)
94 | {
95 | if (enddata - curdata < 3 || !readMQTTLenString(&data->username, &curdata, enddata))
96 | goto exit; /* username flag set, but no username supplied - invalid */
97 | if (flags.bits.password &&
98 | (enddata - curdata < 3 || !readMQTTLenString(&data->password, &curdata, enddata)))
99 | goto exit; /* password flag set, but no password supplied - invalid */
100 | }
101 | else if (flags.bits.password)
102 | goto exit; /* password flag set without username - invalid */
103 | rc = 1;
104 | }
105 | exit:
106 | FUNC_EXIT_RC(rc);
107 | return rc;
108 | }
109 |
110 |
111 | /**
112 | * Serializes the connack packet into the supplied buffer.
113 | * @param buf the buffer into which the packet will be serialized
114 | * @param buflen the length in bytes of the supplied buffer
115 | * @param connack_rc the integer connack return code to be used
116 | * @param sessionPresent the MQTT 3.1.1 sessionPresent flag
117 | * @return serialized length, or error if 0
118 | */
119 | int MQTTSerialize_connack(unsigned char* buf, int buflen, unsigned char connack_rc, unsigned char sessionPresent)
120 | {
121 | MQTTHeader header = {0};
122 | int rc = 0;
123 | unsigned char *ptr = buf;
124 | MQTTConnackFlags flags = {0};
125 |
126 | FUNC_ENTRY;
127 | if (buflen < 2)
128 | {
129 | rc = MQTTPACKET_BUFFER_TOO_SHORT;
130 | goto exit;
131 | }
132 | header.byte = 0;
133 | header.bits.type = CONNACK;
134 | writeChar(&ptr, header.byte); /* write header */
135 |
136 | ptr += MQTTPacket_encode(ptr, 2); /* write remaining length */
137 |
138 | flags.all = 0;
139 | flags.bits.sessionpresent = sessionPresent;
140 | writeChar(&ptr, flags.all);
141 | writeChar(&ptr, connack_rc);
142 |
143 | rc = ptr - buf;
144 | exit:
145 | FUNC_EXIT_RC(rc);
146 | return rc;
147 | }
148 |
149 |
--------------------------------------------------------------------------------
/Drivers/ioLibrary_Driver/Internet/MQTT/MQTTPacket/src/MQTTDeserializePublish.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 | * Ian Craggs - initial API and implementation and/or initial documentation
15 | *******************************************************************************/
16 |
17 | #include "StackTrace.h"
18 | #include "MQTTPacket.h"
19 | #include
20 |
21 | #define min(a, b) ((a < b) ? 1 : 0)
22 |
23 | /**
24 | * Deserializes the supplied (wire) buffer into publish data
25 | * @param dup returned integer - the MQTT dup flag
26 | * @param qos returned integer - the MQTT QoS value
27 | * @param retained returned integer - the MQTT retained flag
28 | * @param packetid returned integer - the MQTT packet identifier
29 | * @param topicName returned MQTTString - the MQTT topic in the publish
30 | * @param payload returned byte buffer - the MQTT publish payload
31 | * @param payloadlen returned integer - the length of the MQTT payload
32 | * @param buf the raw buffer data, of the correct length determined by the remaining length field
33 | * @param buflen the length in bytes of the data in the supplied buffer
34 | * @return error code. 1 is success
35 | */
36 | int MQTTDeserialize_publish(unsigned char* dup, int* qos, unsigned char* retained, unsigned short* packetid, MQTTString* topicName,
37 | unsigned char** payload, int* payloadlen, unsigned char* buf, int buflen)
38 | {
39 | MQTTHeader header = {0};
40 | unsigned char* curdata = buf;
41 | unsigned char* enddata = NULL;
42 | int rc = 0;
43 | int mylen = 0;
44 |
45 | FUNC_ENTRY;
46 | header.byte = readChar(&curdata);
47 | if (header.bits.type != PUBLISH)
48 | goto exit;
49 | *dup = header.bits.dup;
50 | *qos = header.bits.qos;
51 | *retained = header.bits.retain;
52 |
53 | curdata += (rc = MQTTPacket_decodeBuf(curdata, &mylen)); /* read remaining length */
54 | enddata = curdata + mylen;
55 |
56 | if (!readMQTTLenString(topicName, &curdata, enddata) ||
57 | enddata - curdata < 0) /* do we have enough data to read the protocol version byte? */
58 | goto exit;
59 |
60 | if (*qos > 0)
61 | *packetid = readInt(&curdata);
62 |
63 | *payloadlen = enddata - curdata;
64 | *payload = curdata;
65 | rc = 1;
66 | exit:
67 | FUNC_EXIT_RC(rc);
68 | return rc;
69 | }
70 |
71 |
72 |
73 | /**
74 | * Deserializes the supplied (wire) buffer into an ack
75 | * @param packettype returned integer - the MQTT packet type
76 | * @param dup returned integer - the MQTT dup flag
77 | * @param packetid returned integer - the MQTT packet identifier
78 | * @param buf the raw buffer data, of the correct length determined by the remaining length field
79 | * @param buflen the length in bytes of the data in the supplied buffer
80 | * @return error code. 1 is success, 0 is failure
81 | */
82 | int MQTTDeserialize_ack(unsigned char* packettype, unsigned char* dup, unsigned short* packetid, unsigned char* buf, int buflen)
83 | {
84 | MQTTHeader header = {0};
85 | unsigned char* curdata = buf;
86 | unsigned char* enddata = NULL;
87 | int rc = 0;
88 | int mylen;
89 |
90 | FUNC_ENTRY;
91 | header.byte = readChar(&curdata);
92 | *dup = header.bits.dup;
93 | *packettype = header.bits.type;
94 |
95 | curdata += (rc = MQTTPacket_decodeBuf(curdata, &mylen)); /* read remaining length */
96 | enddata = curdata + mylen;
97 |
98 | if (enddata - curdata < 2)
99 | goto exit;
100 | *packetid = readInt(&curdata);
101 |
102 | rc = 1;
103 | exit:
104 | FUNC_EXIT_RC(rc);
105 | return rc;
106 | }
107 |
108 |
--------------------------------------------------------------------------------
/Drivers/ioLibrary_Driver/Internet/MQTT/MQTTPacket/src/MQTTFormat.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 | * Ian Craggs - initial API and implementation and/or initial documentation
15 | *******************************************************************************/
16 |
17 | #if !defined(MQTTFORMAT_H)
18 | #define MQTTFORMAT_H
19 |
20 | #include "StackTrace.h"
21 | #include "MQTTPacket.h"
22 |
23 | const char* MQTTPacket_getName(unsigned short packetid);
24 | int MQTTStringFormat_connect(char* strbuf, int strbuflen, MQTTPacket_connectData* data);
25 | int MQTTStringFormat_connack(char* strbuf, int strbuflen, unsigned char connack_rc, unsigned char sessionPresent);
26 | int MQTTStringFormat_publish(char* strbuf, int strbuflen, unsigned char dup, int qos, unsigned char retained,
27 | unsigned short packetid, MQTTString topicName, unsigned char* payload, int payloadlen);
28 | int MQTTStringFormat_ack(char* strbuf, int strbuflen, unsigned char packettype, unsigned char dup, unsigned short packetid);
29 | int MQTTStringFormat_subscribe(char* strbuf, int strbuflen, unsigned char dup, unsigned short packetid, int count,
30 | MQTTString topicFilters[], int requestedQoSs[]);
31 | int MQTTStringFormat_suback(char* strbuf, int strbuflen, unsigned short packetid, int count, int* grantedQoSs);
32 | int MQTTStringFormat_unsubscribe(char* strbuf, int strbuflen, unsigned char dup, unsigned short packetid,
33 | int count, MQTTString topicFilters[]);
34 | char* MQTTFormat_toClientString(char* strbuf, int strbuflen, unsigned char* buf, int buflen);
35 | char* MQTTFormat_toServerString(char* strbuf, int strbuflen, unsigned char* buf, int buflen);
36 |
37 | #endif
38 |
--------------------------------------------------------------------------------
/Drivers/ioLibrary_Driver/Internet/MQTT/MQTTPacket/src/MQTTPacket.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 | * Ian Craggs - initial API and implementation and/or initial documentation
15 | * Xiang Rong - 442039 Add makefile to Embedded C client
16 | *******************************************************************************/
17 |
18 | #ifndef MQTTPACKET_H_
19 | #define MQTTPACKET_H_
20 |
21 | #if defined(__cplusplus) /* If this is a C++ compiler, use C linkage */
22 | extern "C" {
23 | #endif
24 |
25 | #if defined(WIN32_DLL) || defined(WIN64_DLL)
26 | #define DLLImport __declspec(dllimport)
27 | #define DLLExport __declspec(dllexport)
28 | #elif defined(LINUX_SO)
29 | #define DLLImport extern
30 | #define DLLExport __attribute__ ((visibility ("default")))
31 | #else
32 | #define DLLImport
33 | #define DLLExport
34 | #endif
35 |
36 | enum errors
37 | {
38 | MQTTPACKET_BUFFER_TOO_SHORT = -2,
39 | MQTTPACKET_READ_ERROR = -1,
40 | MQTTPACKET_READ_COMPLETE
41 | };
42 |
43 | enum msgTypes
44 | {
45 | CONNECT = 1, CONNACK, PUBLISH, PUBACK, PUBREC, PUBREL,
46 | PUBCOMP, SUBSCRIBE, SUBACK, UNSUBSCRIBE, UNSUBACK,
47 | PINGREQ, PINGRESP, DISCONNECT
48 | };
49 |
50 | /**
51 | * Bitfields for the MQTT header byte.
52 | */
53 | typedef union
54 | {
55 | unsigned char byte; /**< the whole byte */
56 | #if defined(REVERSED)
57 | struct
58 | {
59 | unsigned int type : 4; /**< message type nibble */
60 | unsigned int dup : 1; /**< DUP flag bit */
61 | unsigned int qos : 2; /**< QoS value, 0, 1 or 2 */
62 | unsigned int retain : 1; /**< retained flag bit */
63 | } bits;
64 | #else
65 | struct
66 | {
67 | unsigned int retain : 1; /**< retained flag bit */
68 | unsigned int qos : 2; /**< QoS value, 0, 1 or 2 */
69 | unsigned int dup : 1; /**< DUP flag bit */
70 | unsigned int type : 4; /**< message type nibble */
71 | } bits;
72 | #endif
73 | } MQTTHeader;
74 |
75 | typedef struct
76 | {
77 | int len;
78 | char* data;
79 | } MQTTLenString;
80 |
81 | typedef struct
82 | {
83 | char* cstring;
84 | MQTTLenString lenstring;
85 | } MQTTString;
86 |
87 | #define MQTTString_initializer {NULL, {0, NULL}}
88 |
89 | int MQTTstrlen(MQTTString mqttstring);
90 |
91 | #include "MQTTConnect.h"
92 | #include "MQTTPublish.h"
93 | #include "MQTTSubscribe.h"
94 | #include "MQTTUnsubscribe.h"
95 | #include "MQTTFormat.h"
96 |
97 | int MQTTSerialize_ack(unsigned char* buf, int buflen, unsigned char type, unsigned char dup, unsigned short packetid);
98 | int MQTTDeserialize_ack(unsigned char* packettype, unsigned char* dup, unsigned short* packetid, unsigned char* buf, int buflen);
99 |
100 | int MQTTPacket_len(int rem_len);
101 | int MQTTPacket_equals(MQTTString* a, char* b);
102 |
103 | int MQTTPacket_encode(unsigned char* buf, int length);
104 | int MQTTPacket_decode(int (*getcharfn)(unsigned char*, int), int* value);
105 | int MQTTPacket_decodeBuf(unsigned char* buf, int* value);
106 |
107 | int readInt(unsigned char** pptr);
108 | char readChar(unsigned char** pptr);
109 | void writeChar(unsigned char** pptr, char c);
110 | void writeInt(unsigned char** pptr, int anInt);
111 | int readMQTTLenString(MQTTString* mqttstring, unsigned char** pptr, unsigned char* enddata);
112 | void writeCString(unsigned char** pptr, const char* string);
113 | void writeMQTTString(unsigned char** pptr, MQTTString mqttstring);
114 |
115 | DLLExport int MQTTPacket_read(unsigned char* buf, int buflen, int (*getfn)(unsigned char*, int));
116 |
117 | typedef struct {
118 | int (*getfn)(void *, unsigned char*, int); /* must return -1 for error, 0 for call again, or the number of bytes read */
119 | void *sck; /* pointer to whatever the system may use to identify the transport */
120 | int multiplier;
121 | int rem_len;
122 | int len;
123 | char state;
124 | }MQTTTransport;
125 |
126 | int MQTTPacket_readnb(unsigned char* buf, int buflen, MQTTTransport *trp);
127 |
128 | #ifdef __cplusplus /* If this is a C++ compiler, use C linkage */
129 | }
130 | #endif
131 |
132 |
133 | #endif /* MQTTPACKET_H_ */
134 |
--------------------------------------------------------------------------------
/Drivers/ioLibrary_Driver/Internet/MQTT/MQTTPacket/src/MQTTPublish.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 | * Ian Craggs - initial API and implementation and/or initial documentation
15 | * Xiang Rong - 442039 Add makefile to Embedded C client
16 | *******************************************************************************/
17 |
18 | #ifndef MQTTPUBLISH_H_
19 | #define MQTTPUBLISH_H_
20 |
21 | #if !defined(DLLImport)
22 | #define DLLImport
23 | #endif
24 | #if !defined(DLLExport)
25 | #define DLLExport
26 | #endif
27 |
28 | DLLExport int MQTTSerialize_publish(unsigned char* buf, int buflen, unsigned char dup, int qos, unsigned char retained, unsigned short packetid,
29 | MQTTString topicName, unsigned char* payload, int payloadlen);
30 |
31 | DLLExport int MQTTDeserialize_publish(unsigned char* dup, int* qos, unsigned char* retained, unsigned short* packetid, MQTTString* topicName,
32 | unsigned char** payload, int* payloadlen, unsigned char* buf, int len);
33 |
34 | DLLExport int MQTTSerialize_puback(unsigned char* buf, int buflen, unsigned short packetid);
35 | DLLExport int MQTTSerialize_pubrel(unsigned char* buf, int buflen, unsigned char dup, unsigned short packetid);
36 | DLLExport int MQTTSerialize_pubcomp(unsigned char* buf, int buflen, unsigned short packetid);
37 |
38 | #endif /* MQTTPUBLISH_H_ */
39 |
--------------------------------------------------------------------------------
/Drivers/ioLibrary_Driver/Internet/MQTT/MQTTPacket/src/MQTTSerializePublish.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 | * Ian Craggs - initial API and implementation and/or initial documentation
15 | * Ian Craggs - fix for https://bugs.eclipse.org/bugs/show_bug.cgi?id=453144
16 | *******************************************************************************/
17 |
18 | #include "MQTTPacket.h"
19 | #include "StackTrace.h"
20 |
21 | #include
22 |
23 |
24 | /**
25 | * Determines the length of the MQTT publish packet that would be produced using the supplied parameters
26 | * @param qos the MQTT QoS of the publish (packetid is omitted for QoS 0)
27 | * @param topicName the topic name to be used in the publish
28 | * @param payloadlen the length of the payload to be sent
29 | * @return the length of buffer needed to contain the serialized version of the packet
30 | */
31 | int MQTTSerialize_publishLength(int qos, MQTTString topicName, int payloadlen)
32 | {
33 | int len = 0;
34 |
35 | len += 2 + MQTTstrlen(topicName) + payloadlen;
36 | if (qos > 0)
37 | len += 2; /* packetid */
38 | return len;
39 | }
40 |
41 |
42 | /**
43 | * Serializes the supplied publish data into the supplied buffer, ready for sending
44 | * @param buf the buffer into which the packet will be serialized
45 | * @param buflen the length in bytes of the supplied buffer
46 | * @param dup integer - the MQTT dup flag
47 | * @param qos integer - the MQTT QoS value
48 | * @param retained integer - the MQTT retained flag
49 | * @param packetid integer - the MQTT packet identifier
50 | * @param topicName MQTTString - the MQTT topic in the publish
51 | * @param payload byte buffer - the MQTT publish payload
52 | * @param payloadlen integer - the length of the MQTT payload
53 | * @return the length of the serialized data. <= 0 indicates error
54 | */
55 | int MQTTSerialize_publish(unsigned char* buf, int buflen, unsigned char dup, int qos, unsigned char retained, unsigned short packetid,
56 | MQTTString topicName, unsigned char* payload, int payloadlen)
57 | {
58 | unsigned char *ptr = buf;
59 | MQTTHeader header = {0};
60 | int rem_len = 0;
61 | int rc = 0;
62 |
63 | FUNC_ENTRY;
64 | if (MQTTPacket_len(rem_len = MQTTSerialize_publishLength(qos, topicName, payloadlen)) > buflen)
65 | {
66 | rc = MQTTPACKET_BUFFER_TOO_SHORT;
67 | goto exit;
68 | }
69 |
70 | header.bits.type = PUBLISH;
71 | header.bits.dup = dup;
72 | header.bits.qos = qos;
73 | header.bits.retain = retained;
74 | writeChar(&ptr, header.byte); /* write header */
75 |
76 | ptr += MQTTPacket_encode(ptr, rem_len); /* write remaining length */;
77 |
78 | writeMQTTString(&ptr, topicName);
79 |
80 | if (qos > 0)
81 | writeInt(&ptr, packetid);
82 |
83 | memcpy(ptr, payload, payloadlen);
84 | ptr += payloadlen;
85 |
86 | rc = ptr - buf;
87 |
88 | exit:
89 | FUNC_EXIT_RC(rc);
90 | return rc;
91 | }
92 |
93 |
94 |
95 | /**
96 | * Serializes the ack packet into the supplied buffer.
97 | * @param buf the buffer into which the packet will be serialized
98 | * @param buflen the length in bytes of the supplied buffer
99 | * @param type the MQTT packet type
100 | * @param dup the MQTT dup flag
101 | * @param packetid the MQTT packet identifier
102 | * @return serialized length, or error if 0
103 | */
104 | int MQTTSerialize_ack(unsigned char* buf, int buflen, unsigned char packettype, unsigned char dup, unsigned short packetid)
105 | {
106 | MQTTHeader header = {0};
107 | int rc = 0;
108 | unsigned char *ptr = buf;
109 |
110 | FUNC_ENTRY;
111 | if (buflen < 4)
112 | {
113 | rc = MQTTPACKET_BUFFER_TOO_SHORT;
114 | goto exit;
115 | }
116 | header.bits.type = packettype;
117 | header.bits.dup = dup;
118 | header.bits.qos = (packettype == PUBREL) ? 1 : 0;
119 | writeChar(&ptr, header.byte); /* write header */
120 |
121 | ptr += MQTTPacket_encode(ptr, 2); /* write remaining length */
122 | writeInt(&ptr, packetid);
123 | rc = ptr - buf;
124 | exit:
125 | FUNC_EXIT_RC(rc);
126 | return rc;
127 | }
128 |
129 |
130 | /**
131 | * Serializes a puback packet into the supplied buffer.
132 | * @param buf the buffer into which the packet will be serialized
133 | * @param buflen the length in bytes of the supplied buffer
134 | * @param packetid integer - the MQTT packet identifier
135 | * @return serialized length, or error if 0
136 | */
137 | int MQTTSerialize_puback(unsigned char* buf, int buflen, unsigned short packetid)
138 | {
139 | return MQTTSerialize_ack(buf, buflen, PUBACK, 0, packetid);
140 | }
141 |
142 |
143 | /**
144 | * Serializes a pubrel packet into the supplied buffer.
145 | * @param buf the buffer into which the packet will be serialized
146 | * @param buflen the length in bytes of the supplied buffer
147 | * @param dup integer - the MQTT dup flag
148 | * @param packetid integer - the MQTT packet identifier
149 | * @return serialized length, or error if 0
150 | */
151 | int MQTTSerialize_pubrel(unsigned char* buf, int buflen, unsigned char dup, unsigned short packetid)
152 | {
153 | return MQTTSerialize_ack(buf, buflen, PUBREL, dup, packetid);
154 | }
155 |
156 |
157 | /**
158 | * Serializes a pubrel packet into the supplied buffer.
159 | * @param buf the buffer into which the packet will be serialized
160 | * @param buflen the length in bytes of the supplied buffer
161 | * @param packetid integer - the MQTT packet identifier
162 | * @return serialized length, or error if 0
163 | */
164 | int MQTTSerialize_pubcomp(unsigned char* buf, int buflen, unsigned short packetid)
165 | {
166 | return MQTTSerialize_ack(buf, buflen, PUBCOMP, 0, packetid);
167 | }
168 |
169 |
170 |
--------------------------------------------------------------------------------
/Drivers/ioLibrary_Driver/Internet/MQTT/MQTTPacket/src/MQTTSubscribe.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 | * Ian Craggs - initial API and implementation and/or initial documentation
15 | * Xiang Rong - 442039 Add makefile to Embedded C client
16 | *******************************************************************************/
17 |
18 | #ifndef MQTTSUBSCRIBE_H_
19 | #define MQTTSUBSCRIBE_H_
20 |
21 | #if !defined(DLLImport)
22 | #define DLLImport
23 | #endif
24 | #if !defined(DLLExport)
25 | #define DLLExport
26 | #endif
27 |
28 | DLLExport int MQTTSerialize_subscribe(unsigned char* buf, int buflen, unsigned char dup, unsigned short packetid,
29 | int count, MQTTString topicFilters[], char requestedQoSs[]);
30 |
31 | DLLExport int MQTTDeserialize_subscribe(unsigned char* dup, unsigned short* packetid,
32 | int maxcount, int* count, MQTTString topicFilters[], int requestedQoSs[], unsigned char* buf, int len);
33 |
34 | DLLExport int MQTTSerialize_suback(unsigned char* buf, int buflen, unsigned short packetid, int count, int* grantedQoSs);
35 |
36 | DLLExport int MQTTDeserialize_suback(unsigned short* packetid, int maxcount, int* count, int grantedQoSs[], unsigned char* buf, int len);
37 |
38 |
39 | #endif /* MQTTSUBSCRIBE_H_ */
40 |
--------------------------------------------------------------------------------
/Drivers/ioLibrary_Driver/Internet/MQTT/MQTTPacket/src/MQTTSubscribeClient.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 | * Ian Craggs - initial API and implementation and/or initial documentation
15 | *******************************************************************************/
16 |
17 | #include "MQTTPacket.h"
18 | #include "StackTrace.h"
19 |
20 | #include
21 |
22 | /**
23 | * Determines the length of the MQTT subscribe packet that would be produced using the supplied parameters
24 | * @param count the number of topic filter strings in topicFilters
25 | * @param topicFilters the array of topic filter strings to be used in the publish
26 | * @return the length of buffer needed to contain the serialized version of the packet
27 | */
28 | int MQTTSerialize_subscribeLength(int count, MQTTString topicFilters[])
29 | {
30 | int i;
31 | int len = 2; /* packetid */
32 |
33 | for (i = 0; i < count; ++i)
34 | len += 2 + MQTTstrlen(topicFilters[i]) + 1; /* length + topic + req_qos */
35 | return len;
36 | }
37 |
38 |
39 | /**
40 | * Serializes the supplied subscribe data into the supplied buffer, ready for sending
41 | * @param buf the buffer into which the packet will be serialized
42 | * @param buflen the length in bytes of the supplied bufferr
43 | * @param dup integer - the MQTT dup flag
44 | * @param packetid integer - the MQTT packet identifier
45 | * @param count - number of members in the topicFilters and reqQos arrays
46 | * @param topicFilters - array of topic filter names
47 | * @param requestedQoSs - array of requested QoS
48 | * @return the length of the serialized data. <= 0 indicates error
49 | */
50 | int MQTTSerialize_subscribe(unsigned char* buf, int buflen, unsigned char dup, unsigned short packetid, int count,
51 | MQTTString topicFilters[], char requestedQoSs[])
52 | {
53 | unsigned char *ptr = buf;
54 | MQTTHeader header = {0};
55 | int rem_len = 0;
56 | int rc = 0;
57 | int i = 0;
58 |
59 | FUNC_ENTRY;
60 | if (MQTTPacket_len(rem_len = MQTTSerialize_subscribeLength(count, topicFilters)) > buflen)
61 | {
62 | rc = MQTTPACKET_BUFFER_TOO_SHORT;
63 | goto exit;
64 | }
65 |
66 | header.byte = 0;
67 | header.bits.type = SUBSCRIBE;
68 | header.bits.dup = dup;
69 | header.bits.qos = 1;
70 | writeChar(&ptr, header.byte); /* write header */
71 |
72 | ptr += MQTTPacket_encode(ptr, rem_len); /* write remaining length */;
73 |
74 | writeInt(&ptr, packetid);
75 |
76 | for (i = 0; i < count; ++i)
77 | {
78 | writeMQTTString(&ptr, topicFilters[i]);
79 | writeChar(&ptr, requestedQoSs[i]);
80 | }
81 |
82 | rc = ptr - buf;
83 | exit:
84 | FUNC_EXIT_RC(rc);
85 | return rc;
86 | }
87 |
88 |
89 |
90 | /**
91 | * Deserializes the supplied (wire) buffer into suback data
92 | * @param packetid returned integer - the MQTT packet identifier
93 | * @param maxcount - the maximum number of members allowed in the grantedQoSs array
94 | * @param count returned integer - number of members in the grantedQoSs array
95 | * @param grantedQoSs returned array of integers - the granted qualities of service
96 | * @param buf the raw buffer data, of the correct length determined by the remaining length field
97 | * @param buflen the length in bytes of the data in the supplied buffer
98 | * @return error code. 1 is success, 0 is failure
99 | */
100 | int MQTTDeserialize_suback(unsigned short* packetid, int maxcount, int* count, int grantedQoSs[], unsigned char* buf, int buflen)
101 | {
102 | MQTTHeader header = {0};
103 | unsigned char* curdata = buf;
104 | unsigned char* enddata = NULL;
105 | int rc = 0;
106 | int mylen;
107 |
108 | FUNC_ENTRY;
109 | header.byte = readChar(&curdata);
110 | if (header.bits.type != SUBACK)
111 | goto exit;
112 |
113 | curdata += (rc = MQTTPacket_decodeBuf(curdata, &mylen)); /* read remaining length */
114 | enddata = curdata + mylen;
115 | if (enddata - curdata < 2)
116 | goto exit;
117 |
118 | *packetid = readInt(&curdata);
119 |
120 | *count = 0;
121 | while (curdata < enddata)
122 | {
123 | if (*count > maxcount)
124 | {
125 | rc = -1;
126 | goto exit;
127 | }
128 | grantedQoSs[(*count)++] = readChar(&curdata);
129 | }
130 |
131 | rc = 1;
132 | exit:
133 | FUNC_EXIT_RC(rc);
134 | return rc;
135 | }
136 |
137 |
138 |
--------------------------------------------------------------------------------
/Drivers/ioLibrary_Driver/Internet/MQTT/MQTTPacket/src/MQTTSubscribeServer.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 | * Ian Craggs - initial API and implementation and/or initial documentation
15 | *******************************************************************************/
16 |
17 | #include "MQTTPacket.h"
18 | #include "StackTrace.h"
19 |
20 | #include
21 |
22 |
23 | /**
24 | * Deserializes the supplied (wire) buffer into subscribe data
25 | * @param dup integer returned - the MQTT dup flag
26 | * @param packetid integer returned - the MQTT packet identifier
27 | * @param maxcount - the maximum number of members allowed in the topicFilters and requestedQoSs arrays
28 | * @param count - number of members in the topicFilters and requestedQoSs arrays
29 | * @param topicFilters - array of topic filter names
30 | * @param requestedQoSs - array of requested QoS
31 | * @param buf the raw buffer data, of the correct length determined by the remaining length field
32 | * @param buflen the length in bytes of the data in the supplied buffer
33 | * @return the length of the serialized data. <= 0 indicates error
34 | */
35 | int MQTTDeserialize_subscribe(unsigned char* dup, unsigned short* packetid, int maxcount, int* count, MQTTString topicFilters[],
36 | int requestedQoSs[], unsigned char* buf, int buflen)
37 | {
38 | MQTTHeader header = {0};
39 | unsigned char* curdata = buf;
40 | unsigned char* enddata = NULL;
41 | int rc = -1;
42 | int mylen = 0;
43 |
44 | FUNC_ENTRY;
45 | header.byte = readChar(&curdata);
46 | if (header.bits.type != SUBSCRIBE)
47 | goto exit;
48 | *dup = header.bits.dup;
49 |
50 | curdata += (rc = MQTTPacket_decodeBuf(curdata, &mylen)); /* read remaining length */
51 | enddata = curdata + mylen;
52 |
53 | *packetid = readInt(&curdata);
54 |
55 | *count = 0;
56 | while (curdata < enddata)
57 | {
58 | if (!readMQTTLenString(&topicFilters[*count], &curdata, enddata))
59 | goto exit;
60 | if (curdata >= enddata) /* do we have enough data to read the req_qos version byte? */
61 | goto exit;
62 | requestedQoSs[*count] = readChar(&curdata);
63 | (*count)++;
64 | }
65 |
66 | rc = 1;
67 | exit:
68 | FUNC_EXIT_RC(rc);
69 | return rc;
70 | }
71 |
72 |
73 | /**
74 | * Serializes the supplied suback data into the supplied buffer, ready for sending
75 | * @param buf the buffer into which the packet will be serialized
76 | * @param buflen the length in bytes of the supplied buffer
77 | * @param packetid integer - the MQTT packet identifier
78 | * @param count - number of members in the grantedQoSs array
79 | * @param grantedQoSs - array of granted QoS
80 | * @return the length of the serialized data. <= 0 indicates error
81 | */
82 | int MQTTSerialize_suback(unsigned char* buf, int buflen, unsigned short packetid, int count, int* grantedQoSs)
83 | {
84 | MQTTHeader header = {0};
85 | int rc = -1;
86 | unsigned char *ptr = buf;
87 | int i;
88 |
89 | FUNC_ENTRY;
90 | if (buflen < 2 + count)
91 | {
92 | rc = MQTTPACKET_BUFFER_TOO_SHORT;
93 | goto exit;
94 | }
95 | header.byte = 0;
96 | header.bits.type = SUBACK;
97 | writeChar(&ptr, header.byte); /* write header */
98 |
99 | ptr += MQTTPacket_encode(ptr, 2 + count); /* write remaining length */
100 |
101 | writeInt(&ptr, packetid);
102 |
103 | for (i = 0; i < count; ++i)
104 | writeChar(&ptr, grantedQoSs[i]);
105 |
106 | rc = ptr - buf;
107 | exit:
108 | FUNC_EXIT_RC(rc);
109 | return rc;
110 | }
111 |
112 |
113 |
--------------------------------------------------------------------------------
/Drivers/ioLibrary_Driver/Internet/MQTT/MQTTPacket/src/MQTTUnsubscribe.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 | * Ian Craggs - initial API and implementation and/or initial documentation
15 | * Xiang Rong - 442039 Add makefile to Embedded C client
16 | *******************************************************************************/
17 |
18 | #ifndef MQTTUNSUBSCRIBE_H_
19 | #define MQTTUNSUBSCRIBE_H_
20 |
21 | #if !defined(DLLImport)
22 | #define DLLImport
23 | #endif
24 | #if !defined(DLLExport)
25 | #define DLLExport
26 | #endif
27 |
28 | DLLExport int MQTTSerialize_unsubscribe(unsigned char* buf, int buflen, unsigned char dup, unsigned short packetid,
29 | int count, MQTTString topicFilters[]);
30 |
31 | DLLExport int MQTTDeserialize_unsubscribe(unsigned char* dup, unsigned short* packetid, int max_count, int* count, MQTTString topicFilters[],
32 | unsigned char* buf, int len);
33 |
34 | DLLExport int MQTTSerialize_unsuback(unsigned char* buf, int buflen, unsigned short packetid);
35 |
36 | DLLExport int MQTTDeserialize_unsuback(unsigned short* packetid, unsigned char* buf, int len);
37 |
38 | #endif /* MQTTUNSUBSCRIBE_H_ */
39 |
--------------------------------------------------------------------------------
/Drivers/ioLibrary_Driver/Internet/MQTT/MQTTPacket/src/MQTTUnsubscribeClient.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 | * Ian Craggs - initial API and implementation and/or initial documentation
15 | *******************************************************************************/
16 |
17 | #include "MQTTPacket.h"
18 | #include "StackTrace.h"
19 |
20 | #include
21 |
22 | /**
23 | * Determines the length of the MQTT unsubscribe packet that would be produced using the supplied parameters
24 | * @param count the number of topic filter strings in topicFilters
25 | * @param topicFilters the array of topic filter strings to be used in the publish
26 | * @return the length of buffer needed to contain the serialized version of the packet
27 | */
28 | int MQTTSerialize_unsubscribeLength(int count, MQTTString topicFilters[])
29 | {
30 | int i;
31 | int len = 2; /* packetid */
32 |
33 | for (i = 0; i < count; ++i)
34 | len += 2 + MQTTstrlen(topicFilters[i]); /* length + topic*/
35 | return len;
36 | }
37 |
38 |
39 | /**
40 | * Serializes the supplied unsubscribe data into the supplied buffer, ready for sending
41 | * @param buf the raw buffer data, of the correct length determined by the remaining length field
42 | * @param buflen the length in bytes of the data in the supplied buffer
43 | * @param dup integer - the MQTT dup flag
44 | * @param packetid integer - the MQTT packet identifier
45 | * @param count - number of members in the topicFilters array
46 | * @param topicFilters - array of topic filter names
47 | * @return the length of the serialized data. <= 0 indicates error
48 | */
49 | int MQTTSerialize_unsubscribe(unsigned char* buf, int buflen, unsigned char dup, unsigned short packetid,
50 | int count, MQTTString topicFilters[])
51 | {
52 | unsigned char *ptr = buf;
53 | MQTTHeader header = {0};
54 | int rem_len = 0;
55 | int rc = -1;
56 | int i = 0;
57 |
58 | FUNC_ENTRY;
59 | if (MQTTPacket_len(rem_len = MQTTSerialize_unsubscribeLength(count, topicFilters)) > buflen)
60 | {
61 | rc = MQTTPACKET_BUFFER_TOO_SHORT;
62 | goto exit;
63 | }
64 |
65 | header.byte = 0;
66 | header.bits.type = UNSUBSCRIBE;
67 | header.bits.dup = dup;
68 | header.bits.qos = 1;
69 | writeChar(&ptr, header.byte); /* write header */
70 |
71 | ptr += MQTTPacket_encode(ptr, rem_len); /* write remaining length */;
72 |
73 | writeInt(&ptr, packetid);
74 |
75 | for (i = 0; i < count; ++i)
76 | writeMQTTString(&ptr, topicFilters[i]);
77 |
78 | rc = ptr - buf;
79 | exit:
80 | FUNC_EXIT_RC(rc);
81 | return rc;
82 | }
83 |
84 |
85 | /**
86 | * Deserializes the supplied (wire) buffer into unsuback data
87 | * @param packetid returned integer - the MQTT packet identifier
88 | * @param buf the raw buffer data, of the correct length determined by the remaining length field
89 | * @param buflen the length in bytes of the data in the supplied buffer
90 | * @return error code. 1 is success, 0 is failure
91 | */
92 | int MQTTDeserialize_unsuback(unsigned short* packetid, unsigned char* buf, int buflen)
93 | {
94 | unsigned char type = 0;
95 | unsigned char dup = 0;
96 | int rc = 0;
97 |
98 | FUNC_ENTRY;
99 | rc = MQTTDeserialize_ack(&type, &dup, packetid, buf, buflen);
100 | if (type == UNSUBACK)
101 | rc = 1;
102 | FUNC_EXIT_RC(rc);
103 | return rc;
104 | }
105 |
106 |
107 |
--------------------------------------------------------------------------------
/Drivers/ioLibrary_Driver/Internet/MQTT/MQTTPacket/src/MQTTUnsubscribeServer.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 | * Ian Craggs - initial API and implementation and/or initial documentation
15 | *******************************************************************************/
16 |
17 | #include "MQTTPacket.h"
18 | #include "StackTrace.h"
19 |
20 | #include
21 |
22 |
23 | /**
24 | * Deserializes the supplied (wire) buffer into unsubscribe data
25 | * @param dup integer returned - the MQTT dup flag
26 | * @param packetid integer returned - the MQTT packet identifier
27 | * @param maxcount - the maximum number of members allowed in the topicFilters and requestedQoSs arrays
28 | * @param count - number of members in the topicFilters and requestedQoSs arrays
29 | * @param topicFilters - array of topic filter names
30 | * @param buf the raw buffer data, of the correct length determined by the remaining length field
31 | * @param buflen the length in bytes of the data in the supplied buffer
32 | * @return the length of the serialized data. <= 0 indicates error
33 | */
34 | int MQTTDeserialize_unsubscribe(unsigned char* dup, unsigned short* packetid, int maxcount, int* count, MQTTString topicFilters[],
35 | unsigned char* buf, int len)
36 | {
37 | MQTTHeader header = {0};
38 | unsigned char* curdata = buf;
39 | unsigned char* enddata = NULL;
40 | int rc = 0;
41 | int mylen = 0;
42 |
43 | FUNC_ENTRY;
44 | header.byte = readChar(&curdata);
45 | if (header.bits.type != UNSUBSCRIBE)
46 | goto exit;
47 | *dup = header.bits.dup;
48 |
49 | curdata += (rc = MQTTPacket_decodeBuf(curdata, &mylen)); /* read remaining length */
50 | enddata = curdata + mylen;
51 |
52 | *packetid = readInt(&curdata);
53 |
54 | *count = 0;
55 | while (curdata < enddata)
56 | {
57 | if (!readMQTTLenString(&topicFilters[*count], &curdata, enddata))
58 | goto exit;
59 | (*count)++;
60 | }
61 |
62 | rc = 1;
63 | exit:
64 | FUNC_EXIT_RC(rc);
65 | return rc;
66 | }
67 |
68 |
69 | /**
70 | * Serializes the supplied unsuback data into the supplied buffer, ready for sending
71 | * @param buf the buffer into which the packet will be serialized
72 | * @param buflen the length in bytes of the supplied buffer
73 | * @param packetid integer - the MQTT packet identifier
74 | * @return the length of the serialized data. <= 0 indicates error
75 | */
76 | int MQTTSerialize_unsuback(unsigned char* buf, int buflen, unsigned short packetid)
77 | {
78 | MQTTHeader header = {0};
79 | int rc = 0;
80 | unsigned char *ptr = buf;
81 |
82 | FUNC_ENTRY;
83 | if (buflen < 2)
84 | {
85 | rc = MQTTPACKET_BUFFER_TOO_SHORT;
86 | goto exit;
87 | }
88 | header.byte = 0;
89 | header.bits.type = UNSUBACK;
90 | writeChar(&ptr, header.byte); /* write header */
91 |
92 | ptr += MQTTPacket_encode(ptr, 2); /* write remaining length */
93 |
94 | writeInt(&ptr, packetid);
95 |
96 | rc = ptr - buf;
97 | exit:
98 | FUNC_EXIT_RC(rc);
99 | return rc;
100 | }
101 |
102 |
103 |
--------------------------------------------------------------------------------
/Drivers/ioLibrary_Driver/Internet/MQTT/MQTTPacket/src/StackTrace.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 | * Ian Craggs - initial API and implementation and/or initial documentation
15 | * Ian Craggs - fix for bug #434081
16 | *******************************************************************************/
17 |
18 | #ifndef STACKTRACE_H_
19 | #define STACKTRACE_H_
20 |
21 | #include
22 | #define NOSTACKTRACE 1
23 |
24 | #if defined(NOSTACKTRACE)
25 | #define FUNC_ENTRY
26 | #define FUNC_ENTRY_NOLOG
27 | #define FUNC_ENTRY_MED
28 | #define FUNC_ENTRY_MAX
29 | #define FUNC_EXIT
30 | #define FUNC_EXIT_NOLOG
31 | #define FUNC_EXIT_MED
32 | #define FUNC_EXIT_MAX
33 | #define FUNC_EXIT_RC(x)
34 | #define FUNC_EXIT_MED_RC(x)
35 | #define FUNC_EXIT_MAX_RC(x)
36 |
37 | #else
38 |
39 | #if defined(WIN32)
40 | #define inline __inline
41 | #define FUNC_ENTRY StackTrace_entry(__FUNCTION__, __LINE__, TRACE_MINIMUM)
42 | #define FUNC_ENTRY_NOLOG StackTrace_entry(__FUNCTION__, __LINE__, -1)
43 | #define FUNC_ENTRY_MED StackTrace_entry(__FUNCTION__, __LINE__, TRACE_MEDIUM)
44 | #define FUNC_ENTRY_MAX StackTrace_entry(__FUNCTION__, __LINE__, TRACE_MAXIMUM)
45 | #define FUNC_EXIT StackTrace_exit(__FUNCTION__, __LINE__, NULL, TRACE_MINIMUM)
46 | #define FUNC_EXIT_NOLOG StackTrace_exit(__FUNCTION__, __LINE__, -1)
47 | #define FUNC_EXIT_MED StackTrace_exit(__FUNCTION__, __LINE__, NULL, TRACE_MEDIUM)
48 | #define FUNC_EXIT_MAX StackTrace_exit(__FUNCTION__, __LINE__, NULL, TRACE_MAXIMUM)
49 | #define FUNC_EXIT_RC(x) StackTrace_exit(__FUNCTION__, __LINE__, &x, TRACE_MINIMUM)
50 | #define FUNC_EXIT_MED_RC(x) StackTrace_exit(__FUNCTION__, __LINE__, &x, TRACE_MEDIUM)
51 | #define FUNC_EXIT_MAX_RC(x) StackTrace_exit(__FUNCTION__, __LINE__, &x, TRACE_MAXIMUM)
52 | #else
53 | #define FUNC_ENTRY StackTrace_entry(__func__, __LINE__, TRACE_MINIMUM)
54 | #define FUNC_ENTRY_NOLOG StackTrace_entry(__func__, __LINE__, -1)
55 | #define FUNC_ENTRY_MED StackTrace_entry(__func__, __LINE__, TRACE_MEDIUM)
56 | #define FUNC_ENTRY_MAX StackTrace_entry(__func__, __LINE__, TRACE_MAXIMUM)
57 | #define FUNC_EXIT StackTrace_exit(__func__, __LINE__, NULL, TRACE_MINIMUM)
58 | #define FUNC_EXIT_NOLOG StackTrace_exit(__func__, __LINE__, NULL, -1)
59 | #define FUNC_EXIT_MED StackTrace_exit(__func__, __LINE__, NULL, TRACE_MEDIUM)
60 | #define FUNC_EXIT_MAX StackTrace_exit(__func__, __LINE__, NULL, TRACE_MAXIMUM)
61 | #define FUNC_EXIT_RC(x) StackTrace_exit(__func__, __LINE__, &x, TRACE_MINIMUM)
62 | #define FUNC_EXIT_MED_RC(x) StackTrace_exit(__func__, __LINE__, &x, TRACE_MEDIUM)
63 | #define FUNC_EXIT_MAX_RC(x) StackTrace_exit(__func__, __LINE__, &x, TRACE_MAXIMUM)
64 |
65 | void StackTrace_entry(const char* name, int line, int trace);
66 | void StackTrace_exit(const char* name, int line, void* return_value, int trace);
67 |
68 | void StackTrace_printStack(FILE* dest);
69 | char* StackTrace_get(unsigned long);
70 |
71 | #endif
72 |
73 | #endif
74 |
75 |
76 |
77 |
78 | #endif /* STACKTRACE_H_ */
79 |
--------------------------------------------------------------------------------
/Drivers/ioLibrary_Driver/Internet/MQTT/mqtt_interface.c:
--------------------------------------------------------------------------------
1 | //*****************************************************************************
2 | //! \file mqtt_interface.c
3 | //! \brief Paho MQTT to WIZnet Chip interface implement file.
4 | //! \details The process of porting an interface to use paho MQTT.
5 | //! \version 1.0.0
6 | //! \date 2016/12/06
7 | //! \par Revision history
8 | //! <2016/12/06> 1st Release
9 | //!
10 | //! \author Peter Bang & Justin Kim
11 | //! \copyright
12 | //!
13 | //! Copyright (c) 2016, WIZnet Co., LTD.
14 | //! All rights reserved.
15 | //!
16 | //! Redistribution and use in source and binary forms, with or without
17 | //! modification, are permitted provided that the following conditions
18 | //! are met:
19 | //!
20 | //! * Redistributions of source code must retain the above copyright
21 | //! notice, this list of conditions and the following disclaimer.
22 | //! * Redistributions in binary form must reproduce the above copyright
23 | //! notice, this list of conditions and the following disclaimer in the
24 | //! documentation and/or other materials provided with the distribution.
25 | //! * Neither the name of the nor the names of its
26 | //! contributors may be used to endorse or promote products derived
27 | //! from this software without specific prior written permission.
28 | //!
29 | //! THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
30 | //! AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
31 | //! IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
32 | //! ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
33 | //! LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
34 | //! CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
35 | //! SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
36 | //! INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
37 | //! CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
38 | //! ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
39 | //! THE POSSIBILITY OF SUCH DAMAGE.
40 | //
41 | //*****************************************************************************
42 |
43 | #include "mqtt_interface.h"
44 | #include "wizchip_conf.h"
45 | #include "socket.h"
46 |
47 | unsigned long MilliTimer;
48 |
49 | /*
50 | * @brief MQTT MilliTimer handler
51 | * @note MUST BE register to your system 1m Tick timer handler.
52 | */
53 | void MilliTimer_Handler(void) {
54 | MilliTimer++;
55 | }
56 |
57 | /*
58 | * @brief Timer Initialize
59 | * @param timer : pointer to a Timer structure
60 | * that contains the configuration information for the Timer.
61 | */
62 | void TimerInit(Timer* timer) {
63 | timer->end_time = 0;
64 | }
65 |
66 | /*
67 | * @brief expired Timer
68 | * @param timer : pointer to a Timer structure
69 | * that contains the configuration information for the Timer.
70 | */
71 | char TimerIsExpired(Timer* timer) {
72 | long left = timer->end_time - MilliTimer;
73 | return (left < 0);
74 | }
75 |
76 | /*
77 | * @brief Countdown millisecond Timer
78 | * @param timer : pointer to a Timer structure
79 | * that contains the configuration information for the Timer.
80 | * timeout : setting timeout millisecond.
81 | */
82 | void TimerCountdownMS(Timer* timer, unsigned int timeout) {
83 | timer->end_time = MilliTimer + timeout;
84 | }
85 |
86 | /*
87 | * @brief Countdown second Timer
88 | * @param timer : pointer to a Timer structure
89 | * that contains the configuration information for the Timer.
90 | * timeout : setting timeout millisecond.
91 | */
92 | void TimerCountdown(Timer* timer, unsigned int timeout) {
93 | timer->end_time = MilliTimer + (timeout * 1000);
94 | }
95 |
96 | /*
97 | * @brief left millisecond Timer
98 | * @param timer : pointer to a Timer structure
99 | * that contains the configuration information for the Timer.
100 | */
101 | int TimerLeftMS(Timer* timer) {
102 | long left = timer->end_time - MilliTimer;
103 | return (left < 0) ? 0 : left;
104 | }
105 |
106 | /*
107 | * @brief New network setting
108 | * @param n : pointer to a Network structure
109 | * that contains the configuration information for the Network.
110 | * sn : socket number where x can be (0..7).
111 | * @retval None
112 | */
113 | void NewNetwork(Network* n, int sn) {
114 | n->my_socket = sn;
115 | n->mqttread = w5x00_read;
116 | n->mqttwrite = w5x00_write;
117 | n->disconnect = w5x00_disconnect;
118 | }
119 |
120 | /*
121 | * @brief read function
122 | * @param n : pointer to a Network structure
123 | * that contains the configuration information for the Network.
124 | * buffer : pointer to a read buffer.
125 | * len : buffer length.
126 | * @retval received data length or SOCKERR code
127 | */
128 | int w5x00_read(Network* n, unsigned char* buffer, int len, long time)
129 | {
130 |
131 | if((getSn_SR(n->my_socket) == SOCK_ESTABLISHED) && (getSn_RX_RSR(n->my_socket)>0))
132 | return recv(n->my_socket, buffer, len);
133 |
134 | return SOCK_ERROR;
135 | }
136 |
137 | /*
138 | * @brief write function
139 | * @param n : pointer to a Network structure
140 | * that contains the configuration information for the Network.
141 | * buffer : pointer to a read buffer.
142 | * len : buffer length.
143 | * @retval length of data sent or SOCKERR code
144 | */
145 | int w5x00_write(Network* n, unsigned char* buffer, int len, long time)
146 | {
147 | if(getSn_SR(n->my_socket) == SOCK_ESTABLISHED)
148 | return send(n->my_socket, buffer, len);
149 |
150 | return SOCK_ERROR;
151 | }
152 |
153 | /*
154 | * @brief disconnect function
155 | * @param n : pointer to a Network structure
156 | * that contains the configuration information for the Network.
157 | */
158 | void w5x00_disconnect(Network* n)
159 | {
160 | disconnect(n->my_socket);
161 | }
162 |
163 | /*
164 | * @brief connect network function
165 | * @param n : pointer to a Network structure
166 | * that contains the configuration information for the Network.
167 | * ip : server iP.
168 | * port : server port.
169 | */
170 | void ConnectNetwork(Network* n, uint8_t* ip, uint16_t port)
171 | {
172 | uint16_t myport = 12345;
173 |
174 | socket(n->my_socket,Sn_MR_TCP,myport,0);
175 | connect(n->my_socket,ip,port);
176 | }
177 |
--------------------------------------------------------------------------------
/Drivers/ioLibrary_Driver/Internet/SNMP/snmp.h:
--------------------------------------------------------------------------------
1 | #ifndef _SNMP_H_
2 | #define _SNMP_H_
3 |
4 | #ifdef __cplusplus
5 | extern "C" {
6 | #endif
7 |
8 | // SNMP Debug Message (dump) Enable
9 | #define _SNMP_DEBUG_
10 |
11 | #define PORT_SNMP_AGENT 161
12 | #define PORT_SNMP_TRAP 162
13 |
14 | #define SNMP_V1 0
15 |
16 | #define MAX_OID 12
17 | #define MAX_STRING 64
18 | #define MAX_SNMPMSG_LEN 512
19 | #define MAX_TRAPMSG_LEN 512
20 |
21 | // SNMP Error code
22 | #define SNMP_SUCCESS 0
23 | #define OID_NOT_FOUND -1
24 | #define TABLE_FULL -2
25 | #define ILLEGAL_LENGTH -3
26 | #define INVALID_ENTRY_ID -4
27 | #define INVALID_DATA_TYPE -5
28 |
29 | #define NO_SUCH_NAME 2
30 | #define BAD_VALUE 3
31 |
32 | // SNMPv1 Commands
33 | #define GET_REQUEST 0xa0
34 | #define GET_NEXT_REQUEST 0xa1
35 | #define GET_RESPONSE 0xa2
36 | #define SET_REQUEST 0xa3
37 |
38 | // Macros: SNMPv1 request validation checker
39 | #define VALID_REQUEST(x) ((x == GET_REQUEST) || (x == GET_NEXT_REQUEST) || (x == SET_REQUEST))
40 |
41 | // SNMPv1 Return Types
42 | #define SNMPDTYPE_INTEGER 0x02
43 | #define SNMPDTYPE_OCTET_STRING 0x04
44 | #define SNMPDTYPE_NULL_ITEM 0x05
45 | #define SNMPDTYPE_OBJ_ID 0x06
46 | #define SNMPDTYPE_SEQUENCE 0x30
47 | #define SNMPDTYPE_SEQUENCE_OF SNMPDTYPE_SEQUENCE
48 |
49 | #define SNMPDTYPE_COUNTER 0x41
50 | #define SNMPDTYPE_GAUGE 0x42
51 | #define SNMPDTYPE_TIME_TICKS 0x43
52 | #define SNMPDTYPE_OPAQUE 0x44
53 |
54 | // SNMP Trap: Standard Trap Types (Generic)
55 | #define SNMPTRAP_COLDSTART 0x00 // Generic trap-type 0: Cold Start
56 | #define SNMPTRAP_WARMSTART 0x01 // Generic trap-type 1: Warm Start
57 | #define SNMPTRAP_LINKDOWN 0x02 // Generic trap-type 2: Link Down
58 | #define SNMPTRAP_LINKUP 0x03 // Generic trap-type 3: Link Up
59 | #define SNMPTRAP_AUTHENTICATION 0x04 // Generic trap-type 4: Authentication Failure
60 | #define SNMPTRAP_EGPNEIGHBORLOSS 0x05 // Generic trap-type 5: EGP Neighbor Loss
61 |
62 | // Macros
63 | #define COPY_SEGMENT(x) \
64 | { \
65 | request_msg.index += seglen; \
66 | memcpy(&response_msg.buffer[response_msg.index], &request_msg.buffer[x.start], seglen ); \
67 | response_msg.index += seglen; \
68 | }
69 |
70 | #ifndef HTONL
71 | #define HTONL(x) \
72 | ((((x) >> 24) & 0x000000ff) | \
73 | (((x) >> 8) & 0x0000ff00) | \
74 | (((x) << 8) & 0x00ff0000) | \
75 | (((x) << 24) & 0xff000000))
76 | #endif
77 |
78 | typedef struct {
79 | uint8_t oidlen;
80 | uint8_t oid[MAX_OID];
81 | uint8_t dataType;
82 | uint8_t dataLen;
83 | union {
84 | uint8_t octetstring[MAX_STRING];
85 | uint32_t intval;
86 | } u;
87 | void (*getfunction)(void *, uint8_t *);
88 | void (*setfunction)(int32_t);
89 | } dataEntryType;
90 |
91 | struct messageStruct {
92 | uint8_t buffer[MAX_SNMPMSG_LEN];
93 | int32_t len;
94 | int32_t index;
95 | };
96 |
97 | typedef struct {
98 | int32_t start; /* Absolute Index of the TLV */
99 | int32_t len; /* The L value of the TLV */
100 | int32_t vstart; /* Absolute Index of this TLV's Value */
101 | int32_t nstart; /* Absolute Index of the next TLV */
102 | } tlvStructType;
103 |
104 |
105 | /********************************************************************************************/
106 | /* SNMP : Functions */
107 | /********************************************************************************************/
108 | // SNMP Main functions
109 | void snmpd_init(uint8_t * managerIP, uint8_t * agentIP, uint8_t sn_agent, uint8_t sn_trap);
110 | int32_t snmpd_run(void);
111 | int32_t snmp_sendTrap(uint8_t * managerIP, uint8_t * agentIP, int8_t* community, dataEntryType enterprise_oid, uint32_t genericTrap, uint32_t specificTrap, uint32_t va_count, ...);
112 |
113 | // SNMP Time handler functions
114 | void SNMP_time_handler(void);
115 | uint32_t getSNMPTimeTick(void);
116 | void currentUptime(void *ptr, uint8_t *len);
117 |
118 | #ifdef __cplusplus
119 | }
120 | #endif
121 |
122 | #endif
123 |
--------------------------------------------------------------------------------
/Drivers/ioLibrary_Driver/Internet/SNMP/snmp_custom.c:
--------------------------------------------------------------------------------
1 |
2 | /********************************************************************************************
3 | * SNMP : User Customization Part
4 | * - OID Registration
5 | * - User defined functions for OID related
6 | * + Integer value, String
7 | * + I/O control / Chip registers
8 | * + Network Informations
9 | * + Etc.
10 | *
11 | *********************************************************************************************/
12 | #include "snmp_custom.h"
13 |
14 | #ifdef _USE_WIZNET_W5500_EVB_
15 | #include "board.h"
16 | #endif
17 |
18 | dataEntryType snmpData[] =
19 | {
20 | // System MIB
21 | // SysDescr Entry
22 | {8, {0x2b, 6, 1, 2, 1, 1, 1, 0},
23 | SNMPDTYPE_OCTET_STRING, 30, {"WIZnet Embedded SNMP Agent"},
24 | NULL, NULL},
25 |
26 | // SysObjectID Entry
27 | {8, {0x2b, 6, 1, 2, 1, 1, 2, 0},
28 | SNMPDTYPE_OBJ_ID, 8, {"\x2b\x06\x01\x02\x01\x01\x02\x00"},
29 | NULL, NULL},
30 |
31 | // SysUptime Entry
32 | {8, {0x2b, 6, 1, 2, 1, 1, 3, 0},
33 | SNMPDTYPE_TIME_TICKS, 0, {""},
34 | currentUptime, NULL},
35 |
36 | // sysContact Entry
37 | {8, {0x2b, 6, 1, 2, 1, 1, 4, 0},
38 | SNMPDTYPE_OCTET_STRING, 30, {"http://www.wizwiki.net/forum"},
39 | NULL, NULL},
40 |
41 | // sysName Entry
42 | {8, {0x2b, 6, 1, 2, 1, 1, 5, 0},
43 | SNMPDTYPE_OCTET_STRING, 30, {"http://www.wiznet.co.kr"},
44 | NULL, NULL},
45 |
46 | // Location Entry
47 | {8, {0x2b, 6, 1, 2, 1, 1, 6, 0},
48 | SNMPDTYPE_OCTET_STRING, 30, {"4F Humax Village"},
49 | NULL, NULL},
50 |
51 | // SysServices
52 | {8, {0x2b, 6, 1, 2, 1, 1, 7, 0},
53 | SNMPDTYPE_INTEGER, 4, {""},
54 | NULL, NULL},
55 |
56 | #ifdef _USE_WIZNET_W5500_EVB_
57 | // Get the WIZnet W5500-EVB LED Status
58 | {8, {0x2b, 6, 1, 4, 1, 6, 1, 0},
59 | SNMPDTYPE_OCTET_STRING, 40, {""},
60 | get_LEDStatus_all, NULL},
61 |
62 | // Set the LED_R (RGB LED)
63 | {8, {0x2b, 6, 1, 4, 1, 6, 1, 1},
64 | SNMPDTYPE_INTEGER, 4, {""},
65 | NULL, set_LEDStatus_R},
66 |
67 | // Set the LED_G (RGB LED)
68 | {8, {0x2b, 6, 1, 4, 1, 6, 1, 2},
69 | SNMPDTYPE_INTEGER, 4, {""},
70 | NULL, set_LEDStatus_G},
71 |
72 | // Set the LED_B (RGB LED)
73 | {8, {0x2b, 6, 1, 4, 1, 6, 1, 3},
74 | SNMPDTYPE_INTEGER, 4, {""},
75 | NULL, set_LEDStatus_B},
76 | #endif
77 |
78 | // OID Test #1 (long-length OID example, 19865)
79 | {0x0a, {0x2b, 0x06, 0x01, 0x04, 0x01, 0x81, 0x9b, 0x19, 0x01, 0x00},
80 | SNMPDTYPE_OCTET_STRING, 30, {"long-length OID Test #1"},
81 | NULL, NULL},
82 |
83 | // OID Test #2 (long-length OID example, 22210)
84 | {0x0a, {0x2b, 0x06, 0x01, 0x04, 0x01, 0x81, 0xad, 0x42, 0x01, 0x00},
85 | SNMPDTYPE_OCTET_STRING, 35, {"long-length OID Test #2"},
86 | NULL, NULL},
87 |
88 | // OID Test #2: SysObjectID Entry
89 | {0x0a, {0x2b, 0x06, 0x01, 0x04, 0x01, 0x81, 0xad, 0x42, 0x02, 0x00},
90 | SNMPDTYPE_OBJ_ID, 0x0a, {"\x2b\x06\x01\x04\x01\x81\xad\x42\x02\x00"},
91 | NULL, NULL},
92 | };
93 |
94 | const int32_t maxData = (sizeof(snmpData) / sizeof(dataEntryType));
95 |
96 | void initTable()
97 | {
98 | // Example integer value for [OID 1.3.6.1.2.1.1.7.0]
99 | snmpData[6].u.intval = -5;
100 |
101 | }
102 |
103 |
104 | // W5500-EVB: LED Control ///////////////////////////////////////////////////////////////////////////
105 | #ifdef _USE_WIZNET_W5500_EVB_
106 | void get_LEDStatus_all(void *ptr, uint8_t *len)
107 | {
108 | uint8_t led_status[3] = {0, };
109 |
110 | led_status[LED_R] = (uint8_t)Board_LED_Test(LED_R);
111 | led_status[LED_G] = (uint8_t)Board_LED_Test(LED_G);
112 | led_status[LED_B] = (uint8_t)Board_LED_Test(LED_B);
113 |
114 | *len = sprintf((char *)ptr, "LED R [%s] / G [%s] / B [%s]", led_status[LED_R]?"On":"Off", led_status[LED_G]?"On":"Off", led_status[LED_B]?"On":"Off");
115 | }
116 |
117 | void set_LEDStatus_R(int32_t val)
118 | {
119 | if(val == 0) Board_LED_Set(LED_R, false);
120 | else Board_LED_Set(LED_R, true);
121 | }
122 |
123 | void set_LEDStatus_G(int32_t val)
124 | {
125 | if(val == 0) Board_LED_Set(LED_G, false);
126 | else Board_LED_Set(LED_G, true);
127 | }
128 |
129 | void set_LEDStatus_B(int32_t val)
130 | {
131 | if(val == 0) Board_LED_Set(LED_B, false);
132 | else Board_LED_Set(LED_B, true);
133 | }
134 | #endif
135 | /////////////////////////////////////////////////////////////////////////////////////////////////////
136 |
137 | void initial_Trap(uint8_t * managerIP, uint8_t * agentIP)
138 | {
139 | // SNMP Trap: WarmStart(1) Trap
140 | {
141 | dataEntryType enterprise_oid = {0x0a, {0x2b, 0x06, 0x01, 0x04, 0x01, 0x81, 0x9b, 0x19, 0x01, 0x00},
142 | SNMPDTYPE_OBJ_ID, 0x0a, {"\x2b\x06\x01\x04\x01\x81\x9b\x19\x10\x00"}, NULL, NULL};
143 | // Generic Trap: warmStart COMMUNITY
144 | snmp_sendTrap(managerIP, agentIP, (void *)COMMUNITY, enterprise_oid, SNMPTRAP_WARMSTART, 0, 0);
145 | }
146 |
147 | }
148 |
--------------------------------------------------------------------------------
/Drivers/ioLibrary_Driver/Internet/SNMP/snmp_custom.h:
--------------------------------------------------------------------------------
1 | #ifndef _SNMP_CUSTOM_H_
2 | #define _SNMP_CUSTOM_H_
3 |
4 | #ifdef __cplusplus
5 | extern "C" {
6 | #endif
7 |
8 | #include
9 | #include
10 | #include
11 | #include
12 |
13 | #include "snmp.h"
14 |
15 | extern dataEntryType snmpData[];
16 | extern const int32_t maxData;
17 |
18 | // Define for using W5500-EVB: H/W Dependency (e.g., LEDs...)
19 | //#define _USE_WIZNET_W5500_EVB_
20 |
21 | #define COMMUNITY "public\0"
22 | #define COMMUNITY_SIZE (strlen(COMMUNITY))
23 |
24 | /* Predefined function: Response value control */
25 | void initTable();
26 |
27 | /* User defined functions: LED control examples */
28 | #ifdef _USE_WIZNET_W5500_EVB_
29 | void get_LEDStatus_all(void *ptr, uint8_t *len);
30 | void set_LEDStatus_R(int32_t val);
31 | void set_LEDStatus_G(int32_t val);
32 | void set_LEDStatus_B(int32_t val);
33 | #endif
34 | /* SNMP Trap: warmStart(1) */
35 | void initial_Trap(uint8_t * managerIP, uint8_t * agentIP);
36 |
37 | #ifdef __cplusplus
38 | }
39 | #endif
40 |
41 | #endif
42 |
--------------------------------------------------------------------------------
/Drivers/ioLibrary_Driver/Internet/SNMP/tools/OID_Converter/Readme.txt:
--------------------------------------------------------------------------------
1 | ============================================================
2 |
3 | ============================================================
4 |
5 | + Example OID for convert
6 | 1.3.6.1.4.1.19865.1.0
7 |
8 | (1) Convert Usage
9 | CMD>>oid 1.3.6.1.4.1.19865.1.0
10 | => 06 0A 2B 06 01 04 01 81 9B 19 01 00
11 |
12 | >> TLV(tag-length-value) Example OID
13 | (06) Tag
14 | (0A) Length
15 | [2B] 1(iso).3(identified-organization) (in ASN.1 BER encoding, i.e. 1*40+3 = 0x2b)
16 | [06] 6(dod)
17 | [01] 1(internet)
18 | [04] 4(private)
19 | [01] 1(enterprise)
20 | [81 9B 19] 19865(Vendor-Specific)
21 | ...
22 |
23 | (2) Add the entry to OID table in source code (DataEntryType, put the converted value to array)
24 | {0x0a, {0x2b, 0x06, 0x01, 0x04, 0x01, 0x81, 0x9b, 0x19, 0x01, 0x00},
25 | SNMPDTYPE_OCTET_STRING, 30, {"long-length OID Test"},
26 | NULL, NULL},
27 |
28 | ============================================================
29 | OID Converter: OID encoder/decoder
30 | v1.3 - Matthias Gaertner 1999/2001 - Freeware
31 | ============================================================
32 |
33 | The OID converter is a handy little tool to convert ASN.1 OIDs from readable dotted decimal notation to binary hexadecimal Distinguished Encoding Rules (DER) representation and vice versa.
34 | If you're into x.509 certificates, this may be useful to you, too.
35 |
36 | Usage:
37 | OID [-c|-C] [-o] {-i|1.2.3.4}
38 | converts dotted form to ASCII HEX DER output.
39 | OID -x [-o] {-i|hex-digits}
40 | decodes ASCII HEX DER and gives dotted form.
41 |
42 | If you need more information, please refer to Matthias Gaertner's page,
43 | http://www.rtner.de/software/oid.html
44 |
45 | ===============================================================================================
--------------------------------------------------------------------------------
/Drivers/ioLibrary_Driver/Internet/SNMP/tools/net-snmp-5.7(win32-bin)/snmptrapd.conf:
--------------------------------------------------------------------------------
1 | #
2 | # net-snmp (or ucd-snmp) persistent data file.
3 | #
4 | ############################################################################
5 | # STOP STOP STOP STOP STOP STOP STOP STOP STOP
6 | #
7 | # **** DO NOT EDIT THIS FILE ****
8 | #
9 | # STOP STOP STOP STOP STOP STOP STOP STOP STOP
10 | ############################################################################
11 | #
12 | # DO NOT STORE CONFIGURATION ENTRIES HERE.
13 | # Please save normal configuration tokens for snmptrapd in SNMPCONFPATH/snmptrapd.conf.
14 | # Only "createUser" tokens should be placed here by snmptrapd administrators.
15 | # (Did I mention: do not edit this file?)
16 | #
17 |
18 |
19 | authCommunity log,execute,net public
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 | engineBoots 1
33 | oldEngineID 0x80001f88803d6f00001ba7934e00000000
34 |
--------------------------------------------------------------------------------
/Drivers/ioLibrary_Driver/Internet/SNTP/sntp.c:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/JustForFunOk/W5500_STM32_HAL/418c98979f3f053e8df5afad984749725af42133/Drivers/ioLibrary_Driver/Internet/SNTP/sntp.c
--------------------------------------------------------------------------------
/Drivers/ioLibrary_Driver/Internet/SNTP/sntp.h:
--------------------------------------------------------------------------------
1 | /*
2 | * sntp.h
3 | *
4 | * Created on: 2014. 12. 15.
5 | * Author: Administrator
6 | */
7 |
8 | #ifndef SNTP_H_
9 | #define SNTP_H_
10 |
11 | #ifdef __cplusplus
12 | extern "C" {
13 | #endif
14 |
15 | #include
16 |
17 | /*
18 | * @brief Define it for Debug & Monitor DNS processing.
19 | * @note If defined, it dependens on
20 | */
21 | //#define _SNTP_DEBUG_
22 |
23 | #define MAX_SNTP_BUF_SIZE sizeof(ntpformat) ///< maximum size of DNS buffer. */
24 |
25 | /* for ntpclient */
26 | typedef signed char s_char;
27 | typedef unsigned long long tstamp;
28 | typedef unsigned int tdist;
29 |
30 | typedef struct _ntpformat
31 | {
32 |
33 | uint8_t dstaddr[4]; /* destination (local) address */
34 | char version; /* version number */
35 | char leap; /* leap indicator */
36 | char mode; /* mode */
37 | char stratum; /* stratum */
38 | char poll; /* poll interval */
39 | s_char precision; /* precision */
40 | tdist rootdelay; /* root delay */
41 | tdist rootdisp; /* root dispersion */
42 | char refid; /* reference ID */
43 | tstamp reftime; /* reference time */
44 | tstamp org; /* origin timestamp */
45 | tstamp rec; /* receive timestamp */
46 | tstamp xmt; /* transmit timestamp */
47 |
48 |
49 | } ntpformat;
50 |
51 | typedef struct _datetime
52 | {
53 | uint16_t yy;
54 | uint8_t mo;
55 | uint8_t dd;
56 | uint8_t hh;
57 | uint8_t mm;
58 | uint8_t ss;
59 | } datetime;
60 |
61 | #define ntp_port 123 //ntp server port number
62 | #define SECS_PERDAY 86400UL // seconds in a day = 60*60*24
63 | #define UTC_ADJ_HRS 9 // SEOUL : GMT+9
64 | #define EPOCH 1900 // NTP start year
65 |
66 | void get_seconds_from_ntp_server(uint8_t *buf, uint16_t idx);
67 | void SNTP_init(uint8_t s, uint8_t *ntp_server, uint8_t tz, uint8_t *buf);
68 | int8_t SNTP_run(datetime *time);
69 | tstamp changedatetime_to_seconds(void);
70 | void calcdatetime(tstamp seconds);
71 |
72 | #ifdef __cplusplus
73 | }
74 | #endif
75 |
76 | #endif /* SNTP_H_ */
77 |
--------------------------------------------------------------------------------
/Drivers/ioLibrary_Driver/Internet/TFTP/netutil.c:
--------------------------------------------------------------------------------
1 | #include
2 | #include
3 | #include
4 | #include "netutil.h"
5 |
6 | /**
7 | * Convert a 32bit Address into a Dotted Decimal Format string.
8 | *
9 | * @param addr 32bit address.
10 | * @return Dotted Decimal Format string.
11 | */
12 | int8_t* inet_ntoa(uint32_t addr)
13 | {
14 | static int8_t addr_str[16];
15 | memset(addr_str,0,16);
16 | sprintf((char*)addr_str,"%d.%d.%d.%d",(int32_t)(addr>>24 & 0xFF),(int32_t)(addr>>16 & 0xFF),(int32_t)(addr>>8 & 0xFF),(int32_t)(addr & 0xFF));
17 | return addr_str;
18 | }
19 |
20 | /**
21 | * Convert a 32bit Address into a Dotted Decimal Format string.
22 | * This is differ from inet_ntoa in fixed length.
23 | *
24 | * @param addr 32bit address.
25 | * @return Dotted Decimal Format string.
26 | */
27 | int8_t* inet_ntoa_pad(uint32_t addr)
28 | {
29 | static int8_t addr_str[16];
30 | memset(addr_str,0,16);
31 | sprintf((char*)addr_str,"%03d.%03d.%03d.%03d",(int32_t)(addr>>24 & 0xFF),(int32_t)(addr>>16 & 0xFF),(int32_t)(addr>>8 & 0xFF),(int32_t)(addr & 0xFF));
32 | return addr_str;
33 | }
34 |
35 | /**
36 | * Converts a string containing an (Ipv4) Internet Protocol decimal dotted address into a 32bit address.
37 | *
38 | * @param addr Dotted Decimal Format string.
39 | * @return 32bit address.
40 | */
41 | uint32_t inet_addr(uint8_t* addr)
42 | {
43 | int8_t i;
44 | uint32_t inetaddr = 0;
45 | int8_t taddr[30];
46 | int8_t * nexttok;
47 | int32_t num;
48 | strcpy((char*)taddr,(char*)addr);
49 |
50 | nexttok = taddr;
51 | for(i = 0; i < 4 ; i++)
52 | {
53 | nexttok = (int8_t*)strtok((char*)nexttok,".");
54 | if(nexttok[0] == '0' && nexttok[1] == 'x') num = strtol((char*)nexttok+2, NULL, 16);
55 | else num = strtol((char*)nexttok, NULL, 10);
56 | inetaddr = inetaddr << 8;
57 | inetaddr |= (num & 0xFF);
58 | nexttok = NULL;
59 | }
60 | return inetaddr;
61 | }
62 |
63 | /**
64 | * Swap the byte order of 16bit(short) wide variable.
65 | *
66 | * @param i 16bit value to swap
67 | * @return Swapped value
68 | */
69 | uint16_t swaps(uint16_t i)
70 | {
71 | uint16_t ret=0;
72 | ret = (i & 0xFF) << 8;
73 | ret |= ((i >> 8)& 0xFF);
74 | return ret;
75 | }
76 |
77 | /**
78 | * Swap the byte order of 32bit(long) wide variable.
79 | *
80 | * @param l 32bit value to convert
81 | * @return Swapped value
82 | */
83 | uint32_t swapl(uint32_t l)
84 | {
85 | uint32_t ret=0;
86 | ret = (l & 0xFF) << 24;
87 | ret |= ((l >> 8) & 0xFF) << 16;
88 | ret |= ((l >> 16) & 0xFF) << 8;
89 | ret |= ((l >> 24) & 0xFF);
90 | return ret;
91 | }
92 |
93 | /**
94 | * htons function converts a unsigned short from host to TCP/IP network byte order (which is big-endian).
95 | *
96 | * @param hostshort The value to convert.
97 | * @return The value in TCP/IP network byte order.
98 | */
99 | uint16_t htons(uint16_t hostshort)
100 | {
101 | #ifdef SYSTEM_LITTLE_ENDIAN
102 | return swaps(hostshort);
103 | #else
104 | return hostshort;
105 | #endif
106 | }
107 |
108 |
109 | /**
110 | * htonl function converts a unsigned long from host to TCP/IP network byte order (which is big-endian).
111 | *
112 | * @param hostlong The value to convert.
113 | * @return The value in TCP/IP network byte order.
114 | */
115 | uint32_t htonl(uint32_t hostlong)
116 | {
117 | #ifdef SYSTEM_LITTLE_ENDIAN
118 | return swapl(hostlong);
119 | #else
120 | return hostlong;
121 | #endif
122 | }
123 |
124 |
125 | /**
126 | * ntohs function converts a unsigned short from TCP/IP network byte order
127 | * to host byte order (which is little-endian on Intel processors).
128 | *
129 | * @param netshort The value to convert.
130 | * @return A 16-bit number in host byte order
131 | */
132 | uint32_t ntohs(uint16_t netshort)
133 | {
134 | #ifdef SYSTEM_LITTLE_ENDIAN
135 | return htons(netshort);
136 | #else
137 | return netshort;
138 | #endif
139 | }
140 |
141 | /**
142 | * converts a unsigned long from TCP/IP network byte order to host byte order
143 | * (which is little-endian on Intel processors).
144 | *
145 | * @param netlong The value to convert.
146 | * @return A 16-bit number in host byte order
147 | */
148 | uint32_t ntohl(uint32_t netlong)
149 | {
150 | #ifdef SYSTEM_LITTLE_ENDIAN
151 | return swapl(netlong);
152 | #else
153 | return netlong;
154 | #endif
155 | }
156 | /**
157 | * @}
158 | */
159 |
--------------------------------------------------------------------------------
/Drivers/ioLibrary_Driver/Internet/TFTP/netutil.h:
--------------------------------------------------------------------------------
1 |
2 | #ifndef __NETUTIL_H__
3 | #define __NETUTIL_H__
4 |
5 | #ifdef __cplusplus
6 | extern "C" {
7 | #endif
8 |
9 | #include
10 |
11 | #define SYSTEM_LITTLE_ENDIAN
12 |
13 | int8_t* inet_ntoa(uint32_t addr);
14 | int8_t* inet_ntoa_pad(uint32_t addr);
15 | uint32_t inet_addr(uint8_t* addr);
16 | uint16_t swaps(uint16_t i);
17 | uint32_t swapl(uint32_t l);
18 | uint16_t htons(uint16_t hostshort);
19 | uint32_t htonl(uint32_t hostlong);
20 | uint32_t ntohs(uint16_t netshort);
21 | uint32_t ntohl(uint32_t netlong);
22 |
23 | #ifdef __cplusplus
24 | }
25 | #endif
26 |
27 | #endif
28 |
--------------------------------------------------------------------------------
/Drivers/ioLibrary_Driver/Internet/TFTP/tftp.h:
--------------------------------------------------------------------------------
1 | /**
2 | * @file tftp.h
3 | * @brief TFTP Header File.
4 | * @version 0.1.0
5 | * @author Sang-sik Kim
6 | */
7 | #ifndef __TFTP_H__
8 | #define __TFTP_H__
9 |
10 | #ifdef __cplusplus
11 | extern "C" {
12 | #endif
13 |
14 | #include
15 |
16 | #define F_APP_TFTP
17 | #define __TFTP_DEBUG__
18 |
19 | #define F_STORAGE // If your target support a storage, you have to activate this feature and implement.
20 |
21 | #define SOCK_TFTP 1
22 |
23 | #define INFO_DBG 0x01
24 | #define ERROR_DBG 0x02
25 | #define DEBUG_DBG 0x04
26 | #define IPC_DBG 0x08
27 |
28 | #define DBG_PRINT(level, format, args...) { \
29 | if(dbg_level & level) \
30 | printf(format, ##args); \
31 | }
32 |
33 | #define NORMAL_MODE 0
34 | #define TFTP_MODE 1
35 |
36 | extern int dbg_level;
37 |
38 | /* tftp message */
39 | #define TFTP_RRQ 1
40 | #define TFTP_WRQ 2
41 | #define TFTP_DATA 3
42 | #define TFTP_ACK 4
43 | #define TFTP_ERROR 5
44 | #define TFTP_OACK 6
45 |
46 | /* tftp state */
47 | #define STATE_NONE 0
48 | #define STATE_RRQ 1
49 | #define STATE_WRQ 2
50 | #define STATE_DATA 3
51 | #define STATE_ACK 4
52 | #define STATE_OACK 5
53 |
54 | /* tftp transfer mode */
55 | #define TRANS_ASCII "netascii"
56 | #define TRANS_BINARY "octet"
57 |
58 | /* tftp progress state */
59 | #define TFTP_PROGRESS 0
60 | #define TFTP_FAIL 1
61 | #define TFTP_SUCCESS 2
62 |
63 | /* define */
64 | #define TFTP_SERVER_PORT 69
65 | #define TFTP_TEMP_PORT 51000
66 | #define TFTP_BLK_SIZE 512
67 | #define MAX_MTU_SIZE 1514
68 | #define FILE_NAME_SIZE 20
69 |
70 | //#define __TFTP_DEBUG__
71 |
72 | /* typedef */
73 | typedef struct tftp_data {
74 | uint16_t opcode;
75 | uint16_t block_num;
76 | uint8_t data[0];
77 | } TFTP_DATA_T;
78 |
79 | typedef struct tftp_error {
80 | uint16_t opcode;
81 | uint16_t error_code;
82 | uint8_t error_msg[0];
83 | } TFTP_ERROR_T;
84 |
85 | typedef struct tftp_option {
86 | uint8_t *code;
87 | uint8_t *value;
88 | } TFTP_OPTION;
89 |
90 | /* Functions */
91 | void TFTP_init(uint8_t socket, uint8_t *buf);
92 | void TFTP_exit(void);
93 | int TFTP_run(void);
94 | void TFTP_read_request(uint32_t server_ip, uint8_t *filename);
95 | void tftp_timeout_handler(void);
96 |
97 | #ifdef __cplusplus
98 | }
99 | #endif
100 |
101 | #endif /*__TFTP_H__ */
102 |
--------------------------------------------------------------------------------
/Drivers/ioLibrary_Driver/Internet/httpServer/httpParser.h:
--------------------------------------------------------------------------------
1 | /**
2 | @file httpd.h
3 | @brief Define Constants and fucntions associated with HTTP protocol.
4 | */
5 |
6 | #include
7 |
8 | #ifndef __HTTPPARSER_H__
9 | #define __HTTPPARSER_H__
10 |
11 | #ifdef __cplusplus
12 | extern "C" {
13 | #endif
14 |
15 | //#define _HTTPPARSER_DEBUG_
16 |
17 | #define HTTP_SERVER_PORT 80 /**< HTTP server well-known port number */
18 |
19 | /* HTTP Method */
20 | #define METHOD_ERR 0 /**< Error Method. */
21 | #define METHOD_GET 1 /**< GET Method. */
22 | #define METHOD_HEAD 2 /**< HEAD Method. */
23 | #define METHOD_POST 3 /**< POST Method. */
24 |
25 | /* HTTP GET Method */
26 | #define PTYPE_ERR 0 /**< Error file. */
27 | #define PTYPE_HTML 1 /**< HTML file. */
28 | #define PTYPE_GIF 2 /**< GIF file. */
29 | #define PTYPE_TEXT 3 /**< TEXT file. */
30 | #define PTYPE_JPEG 4 /**< JPEG file. */
31 | #define PTYPE_FLASH 5 /**< FLASH file. */
32 | #define PTYPE_MPEG 6 /**< MPEG file. */
33 | #define PTYPE_PDF 7 /**< PDF file. */
34 | #define PTYPE_CGI 8 /**< CGI file. */
35 | #define PTYPE_XML 9 /**< XML file. */
36 | #define PTYPE_CSS 10 /**< CSS file. */
37 | #define PTYPE_JS 11 /**< JavaScript file. */
38 | #define PTYPE_JSON 12 /**< JSON (JavaScript Standard Object Notation) file. */
39 | #define PTYPE_PNG 13 /**< PNG file. */
40 | #define PTYPE_ICO 14 /**< ICON file. */
41 |
42 | #define PTYPE_TTF 20 /**< Font type: TTF file. */
43 | #define PTYPE_OTF 21 /**< Font type: OTF file. */
44 | #define PTYPE_WOFF 22 /**< Font type: WOFF file. */
45 | #define PTYPE_EOT 23 /**< Font type: EOT file. */
46 | #define PTYPE_SVG 24 /**< Font type: SVG file. */
47 |
48 |
49 | /* HTTP response */
50 | #define STATUS_OK 200
51 | #define STATUS_CREATED 201
52 | #define STATUS_ACCEPTED 202
53 | #define STATUS_NO_CONTENT 204
54 | #define STATUS_MV_PERM 301
55 | #define STATUS_MV_TEMP 302
56 | #define STATUS_NOT_MODIF 304
57 | #define STATUS_BAD_REQ 400
58 | #define STATUS_UNAUTH 401
59 | #define STATUS_FORBIDDEN 403
60 | #define STATUS_NOT_FOUND 404
61 | #define STATUS_INT_SERR 500
62 | #define STATUS_NOT_IMPL 501
63 | #define STATUS_BAD_GATEWAY 502
64 | #define STATUS_SERV_UNAVAIL 503
65 |
66 | /* HTML Doc. for ERROR */
67 | static const char ERROR_HTML_PAGE[] = "HTTP/1.1 404 Not Found\r\nContent-Type: text/html\r\nContent-Length: 78\r\n\r\n\r\n\r\nSorry, the page you requested was not found.\r\n\r\n\r\n\0";
68 | static const char ERROR_REQUEST_PAGE[] = "HTTP/1.1 400 OK\r\nContent-Type: text/html\r\nContent-Length: 50\r\n\r\n\r\n\r\nInvalid request.\r\n\r\n\r\n\0";
69 |
70 | /* HTML Doc. for CGI result */
71 | #define HTML_HEADER "HTTP/1.1 200 OK\r\nContent-Type: text/html\r\nContent-Length: "
72 |
73 | /* Response header for HTML*/
74 | #define RES_HTMLHEAD_OK "HTTP/1.1 200 OK\r\nContent-Type: text/html\r\nConnection: keep-alive\r\nContent-Length: "
75 |
76 | /* Response head for TEXT */
77 | #define RES_TEXTHEAD_OK "HTTP/1.1 200 OK\r\nContent-Type: text/plain\r\nContent-Length: "
78 |
79 | /* Response head for GIF */
80 | #define RES_GIFHEAD_OK "HTTP/1.1 200 OK\r\nContent-Type: image/gif\r\nContent-Length: "
81 |
82 | /* Response head for JPEG */
83 | #define RES_JPEGHEAD_OK "HTTP/1.1 200 OK\r\nContent-Type: image/jpeg\r\nContent-Length: "
84 |
85 | /* Response head for PNG */
86 | #define RES_PNGHEAD_OK "HTTP/1.1 200 OK\r\nContent-Type: image/png\r\nContent-Length: "
87 |
88 | /* Response head for FLASH */
89 | #define RES_FLASHHEAD_OK "HTTP/1.1 200 OK\r\nContent-Type: application/x-shockwave-flash\r\nContent-Length: "
90 |
91 | /* Response head for XML */
92 | #define RES_XMLHEAD_OK "HTTP/1.1 200 OK\r\nContent-Type: text/xml\r\nConnection: keep-alive\r\nContent-Length: "
93 |
94 | /* Response head for CSS */
95 | #define RES_CSSHEAD_OK "HTTP/1.1 200 OK\r\nContent-Type: text/css\r\nContent-Length: "
96 |
97 | /* Response head for JavaScript */
98 | #define RES_JSHEAD_OK "HTTP/1.1 200 OK\r\nContent-Type: application/javascript\r\nContent-Length: "
99 |
100 | /* Response head for JSON */
101 | #define RES_JSONHEAD_OK "HTTP/1.1 200 OK\r\nContent-Type: application/json\r\nContent-Length: "
102 |
103 | /* Response head for ICO */
104 | #define RES_ICOHEAD_OK "HTTP/1.1 200 OK\r\nContent-Type: image/x-icon\r\nContent-Length: "
105 |
106 | /* Response head for CGI */
107 | #define RES_CGIHEAD_OK "HTTP/1.1 200 OK\r\nContent-Type: text/html\r\nContent-Length: "
108 |
109 | /* Response head for TTF, Font */
110 | #define RES_TTFHEAD_OK "HTTP/1.1 200 OK\r\nContent-Type: application/x-font-truetype\r\nContent-Length: "
111 |
112 | /* Response head for OTF, Font */
113 | #define RES_OTFHEAD_OK "HTTP/1.1 200 OK\r\nContent-Type: application/x-font-opentype\r\nContent-Length: "
114 |
115 | /* Response head for WOFF, Font */
116 | #define RES_WOFFHEAD_OK "HTTP/1.1 200 OK\r\nContent-Type: application/font-woff\r\nContent-Length: "
117 |
118 | /* Response head for EOT, Font */
119 | #define RES_EOTHEAD_OK "HTTP/1.1 200 OK\r\nContent-Type: application/vnd.ms-fontobject\r\nContent-Length: "
120 |
121 | /* Response head for SVG, Font */
122 | #define RES_SVGHEAD_OK "HTTP/1.1 200 OK\r\nContent-Type: image/svg+xml\r\nContent-Length: "
123 |
124 | /**
125 | @brief Structure of HTTP REQUEST
126 | */
127 |
128 | //#define MAX_URI_SIZE 1461
129 | #define MAX_URI_SIZE 512
130 |
131 | typedef struct _st_http_request
132 | {
133 | uint8_t METHOD; /**< request method(METHOD_GET...). */
134 | uint8_t TYPE; /**< request type(PTYPE_HTML...). */
135 | uint8_t URI[MAX_URI_SIZE]; /**< request file name. */
136 | }st_http_request;
137 |
138 | // HTTP Parsing functions
139 | void unescape_http_url(char * url); /* convert escape character to ascii */
140 | void parse_http_request(st_http_request *, uint8_t *); /* parse request from peer */
141 | void find_http_uri_type(uint8_t *, uint8_t *); /* find MIME type of a file */
142 | void make_http_response_head(char *, char, uint32_t); /* make response header */
143 | uint8_t * get_http_param_value(char* uri, char* param_name); /* get the user-specific parameter value */
144 | uint8_t get_http_uri_name(uint8_t * uri, uint8_t * uri_buf); /* get the requested URI name */
145 | #ifdef _OLD_
146 | uint8_t * get_http_uri_name(uint8_t * uri);
147 | #endif
148 |
149 | // Utility functions
150 | uint16_t ATOI(uint8_t * str, uint8_t base);
151 | void mid(char* src, char* s1, char* s2, char* sub);
152 | void inet_addr_(uint8_t * addr, uint8_t * ip);
153 |
154 | #ifdef __cplusplus
155 | }
156 | #endif
157 |
158 | #endif /* end of __HTTPPARSER_H__ */
159 |
--------------------------------------------------------------------------------
/Drivers/ioLibrary_Driver/Internet/httpServer/httpServer.h:
--------------------------------------------------------------------------------
1 | /**
2 | @file httpServer.h
3 | @brief Define constants and functions related HTTP Web server.
4 | */
5 |
6 | #include
7 |
8 | #ifndef __HTTPSERVER_H__
9 | #define __HTTPSERVER_H__
10 |
11 | #ifdef __cplusplus
12 | extern "C" {
13 | #endif
14 |
15 | // HTTP Server debug message enable
16 | #define _HTTPSERVER_DEBUG_
17 |
18 | #define INITIAL_WEBPAGE "index.html"
19 | #define M_INITIAL_WEBPAGE "m/index.html"
20 | #define MOBILE_INITIAL_WEBPAGE "mobile/index.html"
21 |
22 | /* Web Server Content Storage Select */
23 | //#define _USE_SDCARD_
24 | #ifndef _USE_SDCARD_
25 | //#define _USE_FLASH_
26 | #endif
27 |
28 | #if !defined(_USE_SDCARD_) && !defined(_USE_FLASH_)
29 | #define _NOTUSED_STORAGE_
30 | #endif
31 |
32 |
33 | /* Watchdog timer */
34 | //#define _USE_WATCHDOG_
35 |
36 | /*********************************************
37 | * HTTP Process states list
38 | *********************************************/
39 | #define STATE_HTTP_IDLE 0 /* IDLE, Waiting for data received (TCP established) */
40 | #define STATE_HTTP_REQ_INPROC 1 /* Received HTTP request from HTTP client */
41 | #define STATE_HTTP_REQ_DONE 2 /* The end of HTTP request parse */
42 | #define STATE_HTTP_RES_INPROC 3 /* Sending the HTTP response to HTTP client (in progress) */
43 | #define STATE_HTTP_RES_DONE 4 /* The end of HTTP response send (HTTP transaction ended) */
44 |
45 | /*********************************************
46 | * HTTP Simple Return Value
47 | *********************************************/
48 | #define HTTP_FAILED 0
49 | #define HTTP_OK 1
50 | #define HTTP_RESET 2
51 |
52 | /*********************************************
53 | * HTTP Content NAME length
54 | *********************************************/
55 | #define MAX_CONTENT_NAME_LEN 128
56 |
57 | /*********************************************
58 | * HTTP Timeout
59 | *********************************************/
60 | #define HTTP_MAX_TIMEOUT_SEC 3 // Sec.
61 |
62 | typedef enum
63 | {
64 | NONE, ///< Web storage none
65 | CODEFLASH, ///< Code flash memory
66 | SDCARD, ///< SD card
67 | DATAFLASH ///< External data flash memory
68 | }StorageType;
69 |
70 | typedef struct _st_http_socket
71 | {
72 | uint8_t sock_status;
73 | uint8_t file_name[MAX_CONTENT_NAME_LEN];
74 | uint32_t file_start;
75 | uint32_t file_len;
76 | uint32_t file_offset; // (start addr + sent size...)
77 | uint8_t storage_type; // Storage type; Code flash, SDcard, Data flash ...
78 | }st_http_socket;
79 |
80 | // Web content structure for file in code flash memory
81 | #define MAX_CONTENT_CALLBACK 20
82 |
83 | typedef struct _httpServer_webContent
84 | {
85 | uint8_t * content_name;
86 | uint32_t content_len;
87 | uint8_t * content;
88 | }httpServer_webContent;
89 |
90 |
91 | void httpServer_init(uint8_t * tx_buf, uint8_t * rx_buf, uint8_t cnt, uint8_t * socklist);
92 | void reg_httpServer_cbfunc(void(*mcu_reset)(void), void(*wdt_reset)(void));
93 | void httpServer_run(uint8_t seqnum);
94 |
95 | void reg_httpServer_webContent(uint8_t * content_name, uint8_t * content);
96 | uint8_t find_userReg_webContent(uint8_t * content_name, uint16_t * content_num, uint32_t * file_len);
97 | uint16_t read_userReg_webContent(uint16_t content_num, uint8_t * buf, uint32_t offset, uint16_t size);
98 | uint8_t display_reg_webContent_list(void);
99 |
100 | /*
101 | * @brief HTTP Server 1sec Tick Timer handler
102 | * @note SHOULD BE register to your system 1s Tick timer handler
103 | */
104 | void httpServer_time_handler(void);
105 | uint32_t get_httpServer_timecount(void);
106 |
107 | #ifdef __cplusplus
108 | }
109 | #endif
110 |
111 | #endif
112 |
--------------------------------------------------------------------------------
/Drivers/ioLibrary_Driver/Internet/httpServer/httpUtil.c:
--------------------------------------------------------------------------------
1 | /**
2 | * @file httpUtil.c
3 | * @brief HTTP Server Utilities
4 | * @version 1.0
5 | * @date 2014/07/15
6 | * @par Revision
7 | * 2014/07/15 - 1.0 Release
8 | * @author
9 | * \n\n @par Copyright (C) 1998 - 2014 WIZnet. All rights reserved.
10 | */
11 |
12 | #include
13 | #include
14 | #include
15 | #include "httpUtil.h"
16 |
17 | uint8_t http_get_cgi_handler(uint8_t * uri_name, uint8_t * buf, uint32_t * file_len)
18 | {
19 | uint8_t ret = HTTP_OK;
20 | uint16_t len = 0;
21 |
22 | if(predefined_get_cgi_processor(uri_name, buf, &len))
23 | {
24 | ;
25 | }
26 | else if(strcmp((const char *)uri_name, "example.cgi") == 0)
27 | {
28 | // To do
29 | ;
30 | }
31 | else
32 | {
33 | // CGI file not found
34 | ret = HTTP_FAILED;
35 | }
36 |
37 | if(ret) *file_len = len;
38 | return ret;
39 | }
40 |
41 | uint8_t http_post_cgi_handler(uint8_t * uri_name, st_http_request * p_http_request, uint8_t * buf, uint32_t * file_len)
42 | {
43 | uint8_t ret = HTTP_OK;
44 | uint16_t len = 0;
45 | uint8_t val = 0;
46 |
47 | if(predefined_set_cgi_processor(uri_name, p_http_request->URI, buf, &len))
48 | {
49 | ;
50 | }
51 | else if(strcmp((const char *)uri_name, "example.cgi") == 0)
52 | {
53 | // To do
54 | val = 1;
55 | len = sprintf((char *)buf, "%d", val);
56 | }
57 | else
58 | {
59 | // CGI file not found
60 | ret = HTTP_FAILED;
61 | }
62 |
63 | if(ret) *file_len = len;
64 | return ret;
65 | }
66 |
--------------------------------------------------------------------------------
/Drivers/ioLibrary_Driver/Internet/httpServer/httpUtil.h:
--------------------------------------------------------------------------------
1 | /**
2 | * @file httpUtil.h
3 | * @brief Header File for HTTP Server Utilities
4 | * @version 1.0
5 | * @date 2014/07/15
6 | * @par Revision
7 | * 2014/07/15 - 1.0 Release
8 | * @author
9 | * \n\n @par Copyright (C) 1998 - 2014 WIZnet. All rights reserved.
10 | */
11 |
12 | #ifndef __HTTPUTIL_H__
13 | #define __HTTPUTIL_H__
14 |
15 | #ifdef __cplusplus
16 | extern "C" {
17 | #endif
18 |
19 | #include "httpServer.h"
20 | #include "httpParser.h"
21 |
22 | uint8_t http_get_cgi_handler(uint8_t * uri_name, uint8_t * buf, uint32_t * file_len);
23 | uint8_t http_post_cgi_handler(uint8_t * uri_name, st_http_request * p_http_request, uint8_t * buf, uint32_t * file_len);
24 |
25 | uint8_t predefined_get_cgi_processor(uint8_t * uri_name, uint8_t * buf, uint16_t * len);
26 | uint8_t predefined_set_cgi_processor(uint8_t * uri_name, uint8_t * uri, uint8_t * buf, uint16_t * len);
27 |
28 | #ifdef __cplusplus
29 | }
30 | #endif
31 |
32 | #endif
33 |
--------------------------------------------------------------------------------
/Drivers/ioLibrary_Driver/README.md:
--------------------------------------------------------------------------------
1 | # ioLibrary Driver
2 | The ioLibrary means “Internet Offload Library” for WIZnet chip. It includes drivers and application protocols.
3 | The driver (ioLibrary) can be used for the application design of WIZnet TCP/IP chips as [W5500](http://wizwiki.net/wiki/doku.php?id=products:w5500:start), W5300, W5200, W5100 [W5100S](http://wizwiki.net/wiki/doku.php?id=products:w5100s:start).
4 |
5 | ## ioLibrary
6 | This driver provides the Berkeley Socket type APIs.
7 | - Directory Structure
8 |
9 | 
10 |
11 | - Ethernet : SOCKET APIs like BSD & WIZCHIP([W5500](http://wizwiki.net/wiki/doku.php?id=products:w5500:start) / W5300 / W5200 / W5100 / [W5100S](http://wizwiki.net/wiki/doku.php?id=products:w5100s:start)) Driver
12 | - Internet :
13 | - DHCP client
14 | - DNS client
15 | - FTP client
16 | - FTP server
17 | - SNMP agent/trap
18 | - SNTP client
19 | - TFTP client
20 | - HTTP server
21 | - MQTT Client
22 | - Others will be added.
23 |
24 | ## How to add an ioLibrary in project through github site.
25 | - Example, refer to https://www.youtube.com/watch?v=mt815RBGdsA
26 | - [ioLibrary Doxygen doument](https://github.com/Wiznet/ioLibrary_Driver/blob/master/Ethernet/Socket_APIs_V3.0.3.chm) : Refer to **TODO** in this document
27 | - Define what chip is used in **wizchip_conf.h**
28 | - Define what Host I/F mode is used in **wizchip_conf.h**
29 |
30 | ## Revision History
31 | * ioLibrary V4.0.0 Released : 29, MAR, 2018
32 | * New features added: Library for W5100S added.
33 | * ioLibrary V3.1.1 Released : 14, Dec, 2016
34 | * Bug fixed : In Socket.c Fixed MACraw & IPraw sendto function.
35 | * ioLibrary V3.1.0 Released : 05, Dec, 2016
36 | * Internet application protocol add to MQTT Client (using paho MQTT 3.11)
37 | * ioLibrary V3.0.3 Released : 03, May, 2016
38 | * In W5300, Fixed some compile errors in close(). Refer to M20160503
39 | * In close(), replace socket() with some command sequences.
40 | * ioLibrary V3.0.2 Released : 26, April, 2016
41 | * Applied the erratum #1 in close() of socket.c (Refer to A20160426)
42 | * ioLibrary V3.0.1 Released : 15, July, 2015
43 | * Bug fixed : In W5100, Fixed CS control problem in read/write buffer with SPI. Refer to M20150715.
44 | * ioLibrary V3.0 Released : 01, June, 2015
45 | * Add to W5300
46 | * Typing Error in comments
47 | * Refer to 20150601 in sources.
48 |
49 | * Type casting error Fixed : 09, April. 2015
50 | In socket.c, send() : Refer to M20150409
51 |
52 | * ioLibrary V2.0 released : April. 2015
53 | * Added to W5100, W5200
54 | * Correct to some typing error
55 | * Fixed the warning of type casting.
56 |
57 | * Last release : Nov. 2014
58 |
59 |
--------------------------------------------------------------------------------
/Drivers/ioLibrary_Driver/iolibrary.chm:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/JustForFunOk/W5500_STM32_HAL/418c98979f3f053e8df5afad984749725af42133/Drivers/ioLibrary_Driver/iolibrary.chm
--------------------------------------------------------------------------------
/Drivers/ioLibrary_Driver/license.txt:
--------------------------------------------------------------------------------
1 |
2 | Copyright (c) 2014 WIZnet Co.,Ltd.
3 | Copyright (c) WIZnet ioLibrary Project.
4 | All rights reserved.
5 |
6 | Permission is hereby granted, free of charge, to any person obtaining a copy
7 | of this software and associated documentation files (the "Software"), to deal
8 | in the Software without restriction, including without limitation the rights
9 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 | copies of the Software, and to permit persons to whom the Software is
11 | furnished to do so, subject to the following conditions:
12 |
13 | The above copyright notice and this permission notice shall be included in all
14 | copies or substantial portions of the Software.
15 |
16 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22 | SOFTWARE.
23 |
--------------------------------------------------------------------------------
/Drivers/uart_printf/uart_printf.c:
--------------------------------------------------------------------------------
1 | #include "uart_printf.h"
2 |
3 | #include "stm32f1xx_hal.h"
4 |
5 | #include // va_list va_start va_end
6 | #include // sprintf
7 | #include // strlen
8 |
9 | extern UART_HandleTypeDef huart1;
10 |
11 | void UART_Printf(const char* fmt, ...) {
12 | char buff[64];
13 | va_list args;
14 | va_start(args, fmt);
15 | vsnprintf(buff, sizeof(buff), fmt, args);
16 | HAL_UART_Transmit(&huart1, (uint8_t*)buff, strlen(buff), HAL_MAX_DELAY);
17 | va_end(args);
18 | }
19 |
--------------------------------------------------------------------------------
/Drivers/uart_printf/uart_printf.h:
--------------------------------------------------------------------------------
1 | #ifndef _UART_PRINTF_H_
2 | #define _UART_PRINTF_H_
3 |
4 | void UART_Printf(const char* fmt, ...);
5 |
6 | #endif
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # W5500_STM32_HAL
2 |
3 | ## Info
4 |
5 | STM32: STM32F103RCT6
6 |
7 | IDE: STM32CubeIDE
8 |
9 | ## Demo
10 |
11 | 
12 |
--------------------------------------------------------------------------------
/STM32F103RCTX_FLASH.ld:
--------------------------------------------------------------------------------
1 | /*
2 | ******************************************************************************
3 | **
4 | ** File : LinkerScript.ld
5 | **
6 | ** Author : Auto-generated by STM32CubeIDE
7 | **
8 | ** Abstract : Linker script for STM32F103RCTx Device from stm32f1 series
9 | ** 256Kbytes FLASH
10 | ** 48Kbytes RAM
11 | **
12 | ** Set heap size, stack size and stack location according
13 | ** to application requirements.
14 | **
15 | ** Set memory bank area and size if external memory is used.
16 | **
17 | ** Target : STMicroelectronics STM32
18 | **
19 | ** Distribution: The file is distributed as is without any warranty
20 | ** of any kind.
21 | **
22 | *****************************************************************************
23 | ** @attention
24 | **
25 | ** © COPYRIGHT(c) 2020 STMicroelectronics
26 | **
27 | ** Redistribution and use in source and binary forms, with or without modification,
28 | ** are permitted provided that the following conditions are met:
29 | ** 1. Redistributions of source code must retain the above copyright notice,
30 | ** this list of conditions and the following disclaimer.
31 | ** 2. Redistributions in binary form must reproduce the above copyright notice,
32 | ** this list of conditions and the following disclaimer in the documentation
33 | ** and/or other materials provided with the distribution.
34 | ** 3. Neither the name of STMicroelectronics nor the names of its contributors
35 | ** may be used to endorse or promote products derived from this software
36 | ** without specific prior written permission.
37 | **
38 | ** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
39 | ** AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
40 | ** IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
41 | ** DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
42 | ** FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
43 | ** DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
44 | ** SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
45 | ** CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
46 | ** OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
47 | ** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
48 | **
49 | *****************************************************************************
50 | */
51 |
52 | /* Entry Point */
53 | ENTRY(Reset_Handler)
54 |
55 | /* Highest address of the user mode stack */
56 | _estack = ORIGIN(RAM) + LENGTH(RAM); /* end of "RAM" Ram type memory */
57 |
58 | _Min_Heap_Size = 0x200 ; /* required amount of heap */
59 | _Min_Stack_Size = 0x400 ; /* required amount of stack */
60 |
61 | /* Memories definition */
62 | MEMORY
63 | {
64 | RAM (xrw) : ORIGIN = 0x20000000, LENGTH = 48K
65 | FLASH (rx) : ORIGIN = 0x8000000, LENGTH = 256K
66 | }
67 |
68 | /* Sections */
69 | SECTIONS
70 | {
71 | /* The startup code into "FLASH" Rom type memory */
72 | .isr_vector :
73 | {
74 | . = ALIGN(4);
75 | KEEP(*(.isr_vector)) /* Startup code */
76 | . = ALIGN(4);
77 | } >FLASH
78 |
79 | /* The program code and other data into "FLASH" Rom type memory */
80 | .text :
81 | {
82 | . = ALIGN(4);
83 | *(.text) /* .text sections (code) */
84 | *(.text*) /* .text* sections (code) */
85 | *(.glue_7) /* glue arm to thumb code */
86 | *(.glue_7t) /* glue thumb to arm code */
87 | *(.eh_frame)
88 |
89 | KEEP (*(.init))
90 | KEEP (*(.fini))
91 |
92 | . = ALIGN(4);
93 | _etext = .; /* define a global symbols at end of code */
94 | } >FLASH
95 |
96 | /* Constant data into "FLASH" Rom type memory */
97 | .rodata :
98 | {
99 | . = ALIGN(4);
100 | *(.rodata) /* .rodata sections (constants, strings, etc.) */
101 | *(.rodata*) /* .rodata* sections (constants, strings, etc.) */
102 | . = ALIGN(4);
103 | } >FLASH
104 |
105 | .ARM.extab : {
106 | . = ALIGN(4);
107 | *(.ARM.extab* .gnu.linkonce.armextab.*)
108 | . = ALIGN(4);
109 | } >FLASH
110 |
111 | .ARM : {
112 | . = ALIGN(4);
113 | __exidx_start = .;
114 | *(.ARM.exidx*)
115 | __exidx_end = .;
116 | . = ALIGN(4);
117 | } >FLASH
118 |
119 | .preinit_array :
120 | {
121 | . = ALIGN(4);
122 | PROVIDE_HIDDEN (__preinit_array_start = .);
123 | KEEP (*(.preinit_array*))
124 | PROVIDE_HIDDEN (__preinit_array_end = .);
125 | . = ALIGN(4);
126 | } >FLASH
127 |
128 | .init_array :
129 | {
130 | . = ALIGN(4);
131 | PROVIDE_HIDDEN (__init_array_start = .);
132 | KEEP (*(SORT(.init_array.*)))
133 | KEEP (*(.init_array*))
134 | PROVIDE_HIDDEN (__init_array_end = .);
135 | . = ALIGN(4);
136 | } >FLASH
137 |
138 | .fini_array :
139 | {
140 | . = ALIGN(4);
141 | PROVIDE_HIDDEN (__fini_array_start = .);
142 | KEEP (*(SORT(.fini_array.*)))
143 | KEEP (*(.fini_array*))
144 | PROVIDE_HIDDEN (__fini_array_end = .);
145 | . = ALIGN(4);
146 | } >FLASH
147 |
148 | /* Used by the startup to initialize data */
149 | _sidata = LOADADDR(.data);
150 |
151 | /* Initialized data sections into "RAM" Ram type memory */
152 | .data :
153 | {
154 | . = ALIGN(4);
155 | _sdata = .; /* create a global symbol at data start */
156 | *(.data) /* .data sections */
157 | *(.data*) /* .data* sections */
158 |
159 | . = ALIGN(4);
160 | _edata = .; /* define a global symbol at data end */
161 |
162 | } >RAM AT> FLASH
163 |
164 | /* Uninitialized data section into "RAM" Ram type memory */
165 | . = ALIGN(4);
166 | .bss :
167 | {
168 | /* This is used by the startup in order to initialize the .bss section */
169 | _sbss = .; /* define a global symbol at bss start */
170 | __bss_start__ = _sbss;
171 | *(.bss)
172 | *(.bss*)
173 | *(COMMON)
174 |
175 | . = ALIGN(4);
176 | _ebss = .; /* define a global symbol at bss end */
177 | __bss_end__ = _ebss;
178 | } >RAM
179 |
180 | /* User_heap_stack section, used to check that there is enough "RAM" Ram type memory left */
181 | ._user_heap_stack :
182 | {
183 | . = ALIGN(8);
184 | PROVIDE ( end = . );
185 | PROVIDE ( _end = . );
186 | . = . + _Min_Heap_Size;
187 | . = . + _Min_Stack_Size;
188 | . = ALIGN(8);
189 | } >RAM
190 |
191 | /* Remove information from the compiler libraries */
192 | /DISCARD/ :
193 | {
194 | libc.a ( * )
195 | libm.a ( * )
196 | libgcc.a ( * )
197 | }
198 |
199 | .ARM.attributes 0 : { *(.ARM.attributes) }
200 | }
201 |
--------------------------------------------------------------------------------
/Test/test_result.PNG:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/JustForFunOk/W5500_STM32_HAL/418c98979f3f053e8df5afad984749725af42133/Test/test_result.PNG
--------------------------------------------------------------------------------
/W5500_STM32_HAL.ioc:
--------------------------------------------------------------------------------
1 | #MicroXplorer Configuration settings - do not modify
2 | File.Version=6
3 | KeepUserPlacement=false
4 | Mcu.Family=STM32F1
5 | Mcu.IP0=NVIC
6 | Mcu.IP1=RCC
7 | Mcu.IP2=SPI1
8 | Mcu.IP3=SYS
9 | Mcu.IP4=USART1
10 | Mcu.IPNb=5
11 | Mcu.Name=STM32F103R(C-D-E)Tx
12 | Mcu.Package=LQFP64
13 | Mcu.Pin0=PD0-OSC_IN
14 | Mcu.Pin1=PD1-OSC_OUT
15 | Mcu.Pin10=PA13
16 | Mcu.Pin11=PA14
17 | Mcu.Pin12=VP_SYS_VS_Systick
18 | Mcu.Pin2=PA4
19 | Mcu.Pin3=PA5
20 | Mcu.Pin4=PA6
21 | Mcu.Pin5=PA7
22 | Mcu.Pin6=PC4
23 | Mcu.Pin7=PC5
24 | Mcu.Pin8=PA9
25 | Mcu.Pin9=PA10
26 | Mcu.PinsNb=13
27 | Mcu.ThirdPartyNb=0
28 | Mcu.UserConstants=
29 | Mcu.UserName=STM32F103RCTx
30 | MxCube.Version=5.5.0
31 | MxDb.Version=DB.5.0.50
32 | NVIC.BusFault_IRQn=true\:0\:0\:false\:false\:true\:false\:false
33 | NVIC.DebugMonitor_IRQn=true\:0\:0\:false\:false\:true\:false\:false
34 | NVIC.ForceEnableDMAVector=true
35 | NVIC.HardFault_IRQn=true\:0\:0\:false\:false\:true\:false\:false
36 | NVIC.MemoryManagement_IRQn=true\:0\:0\:false\:false\:true\:false\:false
37 | NVIC.NonMaskableInt_IRQn=true\:0\:0\:false\:false\:true\:false\:false
38 | NVIC.PendSV_IRQn=true\:0\:0\:false\:false\:true\:false\:false
39 | NVIC.PriorityGroup=NVIC_PRIORITYGROUP_4
40 | NVIC.SVCall_IRQn=true\:0\:0\:false\:false\:true\:false\:false
41 | NVIC.SysTick_IRQn=true\:0\:0\:false\:false\:true\:false\:true
42 | NVIC.UsageFault_IRQn=true\:0\:0\:false\:false\:true\:false\:false
43 | PA10.Mode=Asynchronous
44 | PA10.Signal=USART1_RX
45 | PA13.Mode=Serial_Wire
46 | PA13.Signal=SYS_JTMS-SWDIO
47 | PA14.Mode=Serial_Wire
48 | PA14.Signal=SYS_JTCK-SWCLK
49 | PA4.GPIOParameters=GPIO_PuPd,GPIO_Label
50 | PA4.GPIO_Label=W5500_CS
51 | PA4.GPIO_PuPd=GPIO_PULLDOWN
52 | PA4.Locked=true
53 | PA4.Signal=GPIO_Output
54 | PA5.Mode=Full_Duplex_Master
55 | PA5.Signal=SPI1_SCK
56 | PA6.Mode=Full_Duplex_Master
57 | PA6.Signal=SPI1_MISO
58 | PA7.Mode=Full_Duplex_Master
59 | PA7.Signal=SPI1_MOSI
60 | PA9.Mode=Asynchronous
61 | PA9.Signal=USART1_TX
62 | PC4.GPIOParameters=GPIO_PuPd,GPIO_Label
63 | PC4.GPIO_Label=W5500_INT
64 | PC4.GPIO_PuPd=GPIO_PULLUP
65 | PC4.Locked=true
66 | PC4.Signal=GPIO_Input
67 | PC5.GPIOParameters=GPIO_PuPd,GPIO_Label
68 | PC5.GPIO_Label=W5500_RST
69 | PC5.GPIO_PuPd=GPIO_PULLUP
70 | PC5.Locked=true
71 | PC5.Signal=GPIO_Output
72 | PCC.Checker=false
73 | PCC.Line=STM32F103
74 | PCC.MCU=STM32F103R(C-D-E)Tx
75 | PCC.PartNumber=STM32F103RCTx
76 | PCC.Seq0=0
77 | PCC.Series=STM32F1
78 | PCC.Temperature=25
79 | PCC.Vdd=3.3
80 | PD0-OSC_IN.Mode=HSE-External-Oscillator
81 | PD0-OSC_IN.Signal=RCC_OSC_IN
82 | PD1-OSC_OUT.Mode=HSE-External-Oscillator
83 | PD1-OSC_OUT.Signal=RCC_OSC_OUT
84 | PinOutPanel.RotationAngle=0
85 | ProjectManager.AskForMigrate=true
86 | ProjectManager.BackupPrevious=false
87 | ProjectManager.CompilerOptimize=6
88 | ProjectManager.ComputerToolchain=false
89 | ProjectManager.CoupleFile=false
90 | ProjectManager.CustomerFirmwarePackage=
91 | ProjectManager.DefaultFWLocation=true
92 | ProjectManager.DeletePrevious=true
93 | ProjectManager.DeviceId=STM32F103RCTx
94 | ProjectManager.FirmwarePackage=STM32Cube FW_F1 V1.8.0
95 | ProjectManager.FreePins=false
96 | ProjectManager.HalAssertFull=false
97 | ProjectManager.HeapSize=0x200
98 | ProjectManager.KeepUserCode=true
99 | ProjectManager.LastFirmware=true
100 | ProjectManager.LibraryCopy=1
101 | ProjectManager.MainLocation=Core/Src
102 | ProjectManager.NoMain=false
103 | ProjectManager.PreviousToolchain=
104 | ProjectManager.ProjectBuild=false
105 | ProjectManager.ProjectFileName=W5500_STM32_HAL.ioc
106 | ProjectManager.ProjectName=W5500_STM32_HAL
107 | ProjectManager.StackSize=0x400
108 | ProjectManager.TargetToolchain=STM32CubeIDE
109 | ProjectManager.ToolChainLocation=
110 | ProjectManager.UnderRoot=true
111 | ProjectManager.functionlistsort=1-SystemClock_Config-RCC-false-HAL-false
112 | RCC.ADCFreqValue=36000000
113 | RCC.AHBFreq_Value=72000000
114 | RCC.APB1CLKDivider=RCC_HCLK_DIV2
115 | RCC.APB1Freq_Value=36000000
116 | RCC.APB1TimFreq_Value=72000000
117 | RCC.APB2Freq_Value=72000000
118 | RCC.APB2TimFreq_Value=72000000
119 | RCC.FCLKCortexFreq_Value=72000000
120 | RCC.FamilyName=M
121 | RCC.HCLKFreq_Value=72000000
122 | RCC.I2S2Freq_Value=72000000
123 | RCC.I2S3Freq_Value=72000000
124 | RCC.IPParameters=ADCFreqValue,AHBFreq_Value,APB1CLKDivider,APB1Freq_Value,APB1TimFreq_Value,APB2Freq_Value,APB2TimFreq_Value,FCLKCortexFreq_Value,FamilyName,HCLKFreq_Value,I2S2Freq_Value,I2S3Freq_Value,MCOFreq_Value,PLLCLKFreq_Value,PLLMCOFreq_Value,PLLMUL,PLLSourceVirtual,SDIOFreq_Value,SDIOHCLKDiv2FreqValue,SYSCLKFreq_VALUE,SYSCLKSource,TimSysFreq_Value,USBFreq_Value,VCOOutput2Freq_Value
125 | RCC.MCOFreq_Value=72000000
126 | RCC.PLLCLKFreq_Value=72000000
127 | RCC.PLLMCOFreq_Value=36000000
128 | RCC.PLLMUL=RCC_PLL_MUL9
129 | RCC.PLLSourceVirtual=RCC_PLLSOURCE_HSE
130 | RCC.SDIOFreq_Value=72000000
131 | RCC.SDIOHCLKDiv2FreqValue=36000000
132 | RCC.SYSCLKFreq_VALUE=72000000
133 | RCC.SYSCLKSource=RCC_SYSCLKSOURCE_PLLCLK
134 | RCC.TimSysFreq_Value=72000000
135 | RCC.USBFreq_Value=72000000
136 | RCC.VCOOutput2Freq_Value=8000000
137 | SPI1.BaudRatePrescaler=SPI_BAUDRATEPRESCALER_4
138 | SPI1.CalculateBaudRate=18.0 MBits/s
139 | SPI1.Direction=SPI_DIRECTION_2LINES
140 | SPI1.IPParameters=VirtualType,Mode,Direction,CalculateBaudRate,BaudRatePrescaler
141 | SPI1.Mode=SPI_MODE_MASTER
142 | SPI1.VirtualType=VM_MASTER
143 | USART1.IPParameters=VirtualMode
144 | USART1.VirtualMode=VM_ASYNC
145 | VP_SYS_VS_Systick.Mode=SysTick
146 | VP_SYS_VS_Systick.Signal=SYS_VS_Systick
147 | board=custom
148 | isbadioc=false
149 |
--------------------------------------------------------------------------------