修复mico-sdk错误

This commit is contained in:
nhkefus
2025-03-11 15:54:45 +08:00
parent 3422912129
commit 2ccb892a1c
2152 changed files with 664341 additions and 702636 deletions

File diff suppressed because it is too large Load Diff

View File

@@ -1,130 +1,130 @@
/**
******************************************************************************
* @file mico_mdns.h
* @author William Xu
* @version V1.0.0
* @date 05-May-2014
* @brief This header contains function prototypes called by mdns protocol
* operations
******************************************************************************
* UNPUBLISHED PROPRIETARY SOURCE CODE
* Copyright (c) 2016 MXCHIP Inc.
*
* The contents of this file may not be disclosed to third parties, copied or
* duplicated in any form, in whole or in part, without the prior written
* permission of MXCHIP Corporation.
******************************************************************************
*/
#ifndef __MDNS_H
#define __MDNS_H
#include "mico.h"
/**************************************************************************************************************
* INCLUDES
**************************************************************************************************************/
#define MAX_RECORD_COUNT 4
#define DNS_MESSAGE_IS_A_RESPONSE 0x8000
#define DNS_MESSAGE_OPCODE 0x7800
#define DNS_MESSAGE_AUTHORITATIVE 0x0400
#define DNS_MESSAGE_TRUNCATION 0x0200
#define DNS_MESSAGE_RECURSION_DESIRED 0x0100
#define DNS_MESSAGE_RECURSION_AVAILABLE 0x0080
#define DNS_MESSAGE_RESPONSE_CODE 0x000F
typedef enum
{
DNS_NO_ERROR = 0,
DNS_FORMAT_ERROR = 1,
DNS_SERVER_FAILURE = 2,
DNS_NAME_ERROR = 3,
DNS_NOT_IMPLEMENTED = 4,
DNS_REFUSED = 5
} dns_message_response_code_t;
typedef enum
{
RR_TYPE_A = 1, // A - Host Address
RR_TYPE_NS = 2,
RR_TYPE_MD = 3,
RR_TYPE_MF = 4,
RR_TYPE_CNAME = 5,
RR_TYPE_SOA = 6,
RR_TYPE_MB = 7,
RR_TYPE_MG = 8,
RR_TYPE_MR = 9,
RR_TYPE_NULL = 10,
RR_TYPE_WKS = 11,
RR_TYPE_PTR = 12, // PTR - Domain Name pointer
RR_TYPE_HINFO = 13, // HINFO - Host Information
RR_TYPE_MINFO = 14,
RR_TYPE_MX = 15,
RR_TYPE_TXT = 16,
RR_TYPE_SRV = 33, // SRV - Service Location Record
RR_QTYPE_AXFR = 252,
RR_QTYPE_MAILB = 253,
RR_QTYPE_AILA = 254,
RR_QTYPE_ANY = 255
} dns_resource_record_type_t;
typedef enum
{
RR_CLASS_IN = 1,
RR_CLASS_CS = 2,
RR_CLASS_CH = 3,
RR_CLASS_HS = 4,
RR_CLASS_ALL = 255
} dns_resource_record_class_t;
#define RR_CACHE_FLUSH 0x8000
/**************************************************************************************************************
* STRUCTURES
**************************************************************************************************************/
typedef struct
{
uint8_t* start_of_name;
uint8_t* start_of_packet; // Used for compressed names;
} dns_name_t;
typedef struct
{
uint16_t id;
uint16_t flags;
uint16_t question_count;
uint16_t answer_count;
uint16_t name_server_count;
uint16_t additional_record_count;
} dns_message_header_t;
typedef struct
{
dns_message_header_t* header; // Also used as start of packet for compressed names
uint8_t* iter;
uint8_t* end;
} dns_message_iterator_t;
typedef struct
{
uint16_t question_type;
uint16_t question_class;
} dns_question_t;
typedef struct
{
uint16_t record_type;
uint16_t record_class;
uint32_t ttl;
uint16_t rd_length;
dns_message_iterator_t rdata;
} dns_record_t;
#endif
/**
******************************************************************************
* @file mico_mdns.h
* @author William Xu
* @version V1.0.0
* @date 05-May-2014
* @brief This header contains function prototypes called by mdns protocol
* operations
******************************************************************************
* UNPUBLISHED PROPRIETARY SOURCE CODE
* Copyright (c) 2016 MXCHIP Inc.
*
* The contents of this file may not be disclosed to third parties, copied or
* duplicated in any form, in whole or in part, without the prior written
* permission of MXCHIP Corporation.
******************************************************************************
*/
#ifndef __MDNS_H
#define __MDNS_H
#include "mico.h"
/**************************************************************************************************************
* INCLUDES
**************************************************************************************************************/
#define MAX_RECORD_COUNT 4
#define DNS_MESSAGE_IS_A_RESPONSE 0x8000
#define DNS_MESSAGE_OPCODE 0x7800
#define DNS_MESSAGE_AUTHORITATIVE 0x0400
#define DNS_MESSAGE_TRUNCATION 0x0200
#define DNS_MESSAGE_RECURSION_DESIRED 0x0100
#define DNS_MESSAGE_RECURSION_AVAILABLE 0x0080
#define DNS_MESSAGE_RESPONSE_CODE 0x000F
typedef enum
{
DNS_NO_ERROR = 0,
DNS_FORMAT_ERROR = 1,
DNS_SERVER_FAILURE = 2,
DNS_NAME_ERROR = 3,
DNS_NOT_IMPLEMENTED = 4,
DNS_REFUSED = 5
} dns_message_response_code_t;
typedef enum
{
RR_TYPE_A = 1, // A - Host Address
RR_TYPE_NS = 2,
RR_TYPE_MD = 3,
RR_TYPE_MF = 4,
RR_TYPE_CNAME = 5,
RR_TYPE_SOA = 6,
RR_TYPE_MB = 7,
RR_TYPE_MG = 8,
RR_TYPE_MR = 9,
RR_TYPE_NULL = 10,
RR_TYPE_WKS = 11,
RR_TYPE_PTR = 12, // PTR - Domain Name pointer
RR_TYPE_HINFO = 13, // HINFO - Host Information
RR_TYPE_MINFO = 14,
RR_TYPE_MX = 15,
RR_TYPE_TXT = 16,
RR_TYPE_SRV = 33, // SRV - Service Location Record
RR_QTYPE_AXFR = 252,
RR_QTYPE_MAILB = 253,
RR_QTYPE_AILA = 254,
RR_QTYPE_ANY = 255
} dns_resource_record_type_t;
typedef enum
{
RR_CLASS_IN = 1,
RR_CLASS_CS = 2,
RR_CLASS_CH = 3,
RR_CLASS_HS = 4,
RR_CLASS_ALL = 255
} dns_resource_record_class_t;
#define RR_CACHE_FLUSH 0x8000
/**************************************************************************************************************
* STRUCTURES
**************************************************************************************************************/
typedef struct
{
uint8_t* start_of_name;
uint8_t* start_of_packet; // Used for compressed names;
} dns_name_t;
typedef struct
{
uint16_t id;
uint16_t flags;
uint16_t question_count;
uint16_t answer_count;
uint16_t name_server_count;
uint16_t additional_record_count;
} dns_message_header_t;
typedef struct
{
dns_message_header_t* header; // Also used as start of packet for compressed names
uint8_t* iter;
uint8_t* end;
} dns_message_iterator_t;
typedef struct
{
uint16_t question_type;
uint16_t question_class;
} dns_question_t;
typedef struct
{
uint16_t record_type;
uint16_t record_class;
uint32_t ttl;
uint16_t rd_length;
dns_message_iterator_t rdata;
} dns_record_t;
#endif

View File

@@ -1,97 +1,101 @@
/**
******************************************************************************
* @file MICOBonjour.c
* @author William Xu
* @version V1.0.0
* @date 05-May-2014
* @brief Zero-configuration protocol compatible with Bonjour from Apple
******************************************************************************
* UNPUBLISHED PROPRIETARY SOURCE CODE
* Copyright (c) 2016 MXCHIP Inc.
*
* The contents of this file may not be disclosed to third parties, copied or
* duplicated in any form, in whole or in part, without the prior written
* permission of MXCHIP Corporation.
******************************************************************************
*/
#include "mico.h"
#include "system_internal.h"
#include "platform_config.h"
#include "StringUtils.h"
OSStatus system_discovery_init( system_context_t * const inContext )
{
char *temp_txt= NULL;
char *temp_txt2;
OSStatus err;
net_para_st para;
mdns_init_t init;
temp_txt = malloc(500);
require_action(temp_txt, exit, err = kNoMemoryErr);
memset(&init, 0x0, sizeof(mdns_init_t));
micoWlanGetIPStatus(&para, Station);
init.service_name = "_easylink._tcp.local.";
/* name#xxxxxx.local. */
snprintf( temp_txt, 100, "%s#%c%c%c%c%c%c.local.", inContext->flashContentInRam.micoSystemConfig.name,
inContext->micoStatus.mac[9], inContext->micoStatus.mac[10], \
inContext->micoStatus.mac[12], inContext->micoStatus.mac[13], \
inContext->micoStatus.mac[15], inContext->micoStatus.mac[16] );
init.host_name = (char*)__strdup(temp_txt);
/* name#xxxxxx. */
snprintf( temp_txt, 100, "%s#%c%c%c%c%c%c", inContext->flashContentInRam.micoSystemConfig.name,
inContext->micoStatus.mac[9], inContext->micoStatus.mac[10], \
inContext->micoStatus.mac[12], inContext->micoStatus.mac[13], \
inContext->micoStatus.mac[15], inContext->micoStatus.mac[16] );
init.instance_name = (char*)__strdup(temp_txt);
init.service_port = MICO_CONFIG_SERVER_PORT;
temp_txt2 = __strdup_trans_dot(inContext->micoStatus.mac);
sprintf(temp_txt, "MAC=%s.", temp_txt2);
free(temp_txt2);
temp_txt2 = __strdup_trans_dot(FIRMWARE_REVISION);
sprintf(temp_txt, "%sFirmware Rev=%s.", temp_txt, temp_txt2);
free(temp_txt2);
temp_txt2 = __strdup_trans_dot(HARDWARE_REVISION);
sprintf(temp_txt, "%sHardware Rev=%s.", temp_txt, temp_txt2);
free(temp_txt2);
temp_txt2 = __strdup_trans_dot(MicoGetVer());
sprintf(temp_txt, "%sMICO OS Rev=%s.", temp_txt, temp_txt2);
free(temp_txt2);
temp_txt2 = __strdup_trans_dot(MODEL);
sprintf(temp_txt, "%sModel=%s.", temp_txt, temp_txt2);
free(temp_txt2);
temp_txt2 = __strdup_trans_dot(PROTOCOL);
sprintf(temp_txt, "%sProtocol=%s.", temp_txt, temp_txt2);
free(temp_txt2);
temp_txt2 = __strdup_trans_dot(MANUFACTURER);
sprintf(temp_txt, "%sManufacturer=%s.", temp_txt, temp_txt2);
free(temp_txt2);
sprintf(temp_txt, "%sSeed=%lu.", temp_txt, inContext->flashContentInRam.micoSystemConfig.seed);
init.txt_record = (char*)__strdup(temp_txt);
mdns_add_record( init, Station, 1500);
free(init.host_name);
free(init.instance_name);
free(init.txt_record);
exit:
if(temp_txt) free(temp_txt);
return err;
}
/**
******************************************************************************
* @file MICOBonjour.c
* @author William Xu
* @version V1.0.0
* @date 05-May-2014
* @brief Zero-configuration protocol compatible with Bonjour from Apple
******************************************************************************
* UNPUBLISHED PROPRIETARY SOURCE CODE
* Copyright (c) 2016 MXCHIP Inc.
*
* The contents of this file may not be disclosed to third parties, copied or
* duplicated in any form, in whole or in part, without the prior written
* permission of MXCHIP Corporation.
******************************************************************************
*/
#include "mico.h"
#include "system_internal.h"
#include "platform_config.h"
#include "StringUtils.h"
OSStatus system_discovery_init( system_context_t * const inContext )
{
char *temp_txt= NULL;
char *temp_txt2;
OSStatus err;
net_para_st para;
mdns_init_t init;
temp_txt = malloc(500);
require_action(temp_txt, exit, err = kNoMemoryErr);
memset(&init, 0x0, sizeof(mdns_init_t));
micoWlanGetIPStatus(&para, Station);
init.service_name = "_easylink._tcp.local.";
/* name#xxxxxx.local. */
snprintf( temp_txt, 100, "%s#%c%c%c%c%c%c.local.", inContext->flashContentInRam.micoSystemConfig.name,
inContext->micoStatus.mac[9], inContext->micoStatus.mac[10], \
inContext->micoStatus.mac[12], inContext->micoStatus.mac[13], \
inContext->micoStatus.mac[15], inContext->micoStatus.mac[16] );
init.host_name = (char*)__strdup(temp_txt);
/* name#xxxxxx. */
snprintf( temp_txt, 100, "%s#%c%c%c%c%c%c", inContext->flashContentInRam.micoSystemConfig.name,
inContext->micoStatus.mac[9], inContext->micoStatus.mac[10], \
inContext->micoStatus.mac[12], inContext->micoStatus.mac[13], \
inContext->micoStatus.mac[15], inContext->micoStatus.mac[16] );
init.instance_name = (char*)__strdup(temp_txt);
#ifndef MICO_LOCAL_SERVER_PORT
init.service_port = MICO_CONFIG_SERVER_PORT;
#else
init.service_port = MICO_LOCAL_SERVER_PORT;
#endif
temp_txt2 = __strdup_trans_dot(inContext->micoStatus.mac);
sprintf(temp_txt, "MAC=%s.", temp_txt2);
free(temp_txt2);
temp_txt2 = __strdup_trans_dot(FIRMWARE_REVISION);
sprintf(temp_txt, "%sFirmware Rev=%s.", temp_txt, temp_txt2);
free(temp_txt2);
temp_txt2 = __strdup_trans_dot(HARDWARE_REVISION);
sprintf(temp_txt, "%sHardware Rev=%s.", temp_txt, temp_txt2);
free(temp_txt2);
temp_txt2 = __strdup_trans_dot(MicoGetVer());
sprintf(temp_txt, "%sMICO OS Rev=%s.", temp_txt, temp_txt2);
free(temp_txt2);
temp_txt2 = __strdup_trans_dot(MODEL);
sprintf(temp_txt, "%sModel=%s.", temp_txt, temp_txt2);
free(temp_txt2);
temp_txt2 = __strdup_trans_dot(PROTOCOL);
sprintf(temp_txt, "%sProtocol=%s.", temp_txt, temp_txt2);
free(temp_txt2);
temp_txt2 = __strdup_trans_dot(MANUFACTURER);
sprintf(temp_txt, "%sManufacturer=%s.", temp_txt, temp_txt2);
free(temp_txt2);
sprintf(temp_txt, "%sSeed=%lu.", temp_txt, inContext->flashContentInRam.micoSystemConfig.seed);
init.txt_record = (char*)__strdup(temp_txt);
mdns_add_record( init, Station, 1500);
free(init.host_name);
free(init.instance_name);
free(init.txt_record);
exit:
if(temp_txt) free(temp_txt);
return err;
}