code
stringlengths 1
1.05M
| repo_name
stringlengths 6
83
| path
stringlengths 3
242
| language
stringclasses 222
values | license
stringclasses 20
values | size
int64 1
1.05M
|
|---|---|---|---|---|---|
/*-------------------------------- Arctic Core ------------------------------
* Copyright (C) 2013, ArcCore AB, Sweden, www.arccore.com.
* Contact: <contact@arccore.com>
*
* You may ONLY use this file:
* 1)if you have a valid commercial ArcCore license and then in accordance with
* the terms contained in the written license agreement between you and ArcCore,
* or alternatively
* 2)if you follow the terms found in GNU General Public License version 2 as
* published by the Free Software Foundation and appearing in the file
* LICENSE.GPL included in the packaging of this file or here
* <http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt>
*-------------------------------- Arctic Core -----------------------------*/
#include "PduR.h"
#if (PDUR_DEV_ERROR_DETECT == STD_ON)
#include "Det.h"
#endif
#include "debug.h"
/* @req PDUR0764 */
#if (PDUR_ZERO_COST_OPERATION == STD_OFF) && (PDUR_SOAD_SUPPORT == STD_ON)
// Autosar4 API
void PduR_SoAdIfRxIndication(PduIdType pduId, const PduInfoType* pduInfoPtr) {
PduR_LoIfRxIndication(pduId, (PduInfoType*)pduInfoPtr, 0x61);
}
void PduR_SoAdIfTxConfirmation(PduIdType pduId) {
PduR_LoIfTxConfirmation(pduId, 0x62);
}
Std_ReturnType PduR_SoAdIfTriggerTransmit(PduIdType pduId, PduInfoType* pduInfoPtr) {
return PduR_LoIfTriggerTransmit(pduId, pduInfoPtr, 0x63);
}
BufReq_ReturnType PduR_SoAdTpCopyRxData(PduIdType id, const PduInfoType* info, PduLengthType* bufferSizePtr) {
return PduR_LoTpCopyRxData(id, (PduInfoType*)info, bufferSizePtr, 0x64);
}
void PduR_SoAdTpRxIndication(PduIdType id, NotifResultType result) {
PduR_LoTpRxIndication(id, result, 0x65);
}
BufReq_ReturnType PduR_SoAdTpStartOfReception(PduIdType id, const PduInfoType* info, PduLengthType TpSduLength, PduLengthType* bufferSizePtr) {
/*To avoid compiler warnings*/
(void)*info;
return PduR_LoTpStartOfReception(id, TpSduLength, bufferSizePtr, 0x66);
}
BufReq_ReturnType PduR_SoAdTpCopyTxData(PduIdType id, PduInfoType* info, RetryInfoType* retry, PduLengthType* availableDataPtr ) {
return PduR_LoTpCopyTxData(id, info, retry, availableDataPtr, 0x67);
}
void PduR_SoAdTpTxConfirmation(PduIdType id, NotifResultType result) {
PduR_ARC_TpTxConfirmation(id, result, 0x68);
}
#endif
|
2301_81045437/classic-platform
|
communication/PduR/src/PduR_SoAd.c
|
C
|
unknown
| 2,338
|
/*-------------------------------- Arctic Core ------------------------------
* Copyright (C) 2013, ArcCore AB, Sweden, www.arccore.com.
* Contact: <contact@arccore.com>
*
* You may ONLY use this file:
* 1)if you have a valid commercial ArcCore license and then in accordance with
* the terms contained in the written license agreement between you and ArcCore,
* or alternatively
* 2)if you follow the terms found in GNU General Public License version 2 as
* published by the Free Software Foundation and appearing in the file
* LICENSE.GPL included in the packaging of this file or here
* <http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt>
*-------------------------------- Arctic Core -----------------------------*/
#include "PduR.h"
#include "PduR_UdpNm.h"
#if (PDUR_ZERO_COST_OPERATION == STD_OFF)
// Autosar4 API
void PduR_UdpNmRxIndication(PduIdType pduId, PduInfoType* pduInfoPtr) {
PduR_LoIfRxIndication(pduId, pduInfoPtr, 0x11);
}
void PduR_UdpNmTxConfirmation(PduIdType pduId) {
PduR_LoIfTxConfirmation(pduId, 0x12);
}
Std_ReturnType PduR_UdpNmTriggerTransmit(PduIdType pduId, PduInfoType* pduInfoPtr) {
return PduR_LoIfTriggerTransmit(pduId, pduInfoPtr, 0x13);
}
#endif
|
2301_81045437/classic-platform
|
communication/PduR/src/PduR_UdpNm.c
|
C
|
unknown
| 1,251
|
# SD
obj-$(USE_SD) += SD_Cfg.o
obj-$(USE_SD) += SD_LCfg.o
obj-$(USE_SD) += SD_PBCfg.o
obj-$(USE_SD) += SD_ClientService.o
obj-$(USE_SD) += SD_ServerService.o
obj-$(USE_SD) += SD_Send_Receive.o
obj-$(USE_SD) += SD_Entries.o
obj-$(USE_SD) += SD_Messages.o
obj-$(USE_SD) += SD.o
inc-$(USE_SD) += $(ROOTDIR)/communication/SD/inc
vpath-$(USE_SD) += $(ROOTDIR)/communication/SD/src
|
2301_81045437/classic-platform
|
communication/SD/SD.mod.mk
|
Makefile
|
unknown
| 390
|
/*-------------------------------- Arctic Core ------------------------------
* Copyright (C) 2013, ArcCore AB, Sweden, www.arccore.com.
* Contact: <contact@arccore.com>
*
* You may ONLY use this file:
* 1)if you have a valid commercial ArcCore license and then in accordance with
* the terms contained in the written license agreement between you and ArcCore,
* or alternatively
* 2)if you follow the terms found in GNU General Public License version 2 as
* published by the Free Software Foundation and appearing in the file
* LICENSE.GPL included in the packaging of this file or here
* <http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt>
*-------------------------------- Arctic Core -----------------------------*/
/** @reqSettings DEFAULT_SPECIFICATION_REVISION=4.2.2 */
#ifndef SD_H
#define SD_H
#include "TcpIp_Types.h"
#include "SoAd.h"
#if defined(USE_DEM)
#include "Dem.h"
#endif
#define SD_VENDOR_ID 60u
#define SD_AR_RELEASE_MAJOR_VERSION 4u
#define SD_AR_RELEASE_MINOR_VERSION 2u
#define SD_AR_RELEASE_REVISION_VERSION 2u
#define SD_MODULE_ID 171u
#define SD_AR_MAJOR_VERSION SD_AR_RELEASE_MAJOR_VERSION
#define SD_AR_MINOR_VERSION SD_AR_RELEASE_MINOR_VERSION
#define SD_AR_PATCH_VERSION SD_AR_RELEASE_REVISION_VERSION
#define SD_SW_MAJOR_VERSION 1u
#define SD_SW_MINOR_VERSION 0u
#define SD_SW_PATCH_VERSION 0u
// Error codes produced by this module defined by Autosar
/** @req SWS_SD_00107 **/
#define SD_E_NOT_INITIALIZED 0x01u
#define SD_E_PARAM_POINTER 0x02u
#define SD_E_INV_MODE 0x03u
#define SD_E_INV_ID 0x04u
#define SD_E_INIT_FAILED 0x05u
// Service IDs in this module defined by Autosar
#define SD_INIT_ID 0x01u
#define SD_GET_VERSION_INFO_ID 0x02u
#define SD_LOCAL_IP_ADDR_ASSIGNMENT_CHG_ID 0x05u
#define SD_MAIN_FUNCTION_ID 0x06u
#define SD_SERVER_SERVICE_SET_STATE_ID 0x07u
#define SD_CLIENT_SERVICE_SET_STATE_ID 0x08u
#define SD_CONSUMED_EVENT_GROUP_SET_STATE_ID 0x09u
#define SD_RX_INDICATION_ID 0x42u
#include "SD_Types.h"
#include "SD_Cfg.h"
/** @req SWS_SD_00119 */
void Sd_Init( const Sd_ConfigType* ConfigPtr );
/** @req SWS_SD_00126 */
#if (SD_VERSION_INFO_API == STD_ON)
/** @req SWS_SD_00124 */
void Sd_GetVersionInfo( Std_VersionInfoType* versioninfo );
#endif
/** @req SWS_SD_00496 */
Std_ReturnType Sd_ServerServiceSetState( uint16 SdServerServiceHandleId, Sd_ServerServiceSetStateType ServerServiceState);
/** @req SWS_SD_00409 */
Std_ReturnType Sd_ClientServiceSetState( uint16 ClientServiceHandleID, Sd_ClientServiceSetStateType ClientServiceState );
/** @req SWS_SD_00560 */
Std_ReturnType Sd_ConsumedEventGroupSetState( uint16 SdConsumedEventGroupHandleId, Sd_ConsumedEventGroupSetStateType ConsumedEventGroupState );
/** @req SWS_SD_00412 */
void Sd_LocalIpAddrAssignmentChg( SoAd_SoConIdType SoConId, TcpIp_IpAddrStateType State );
/** @req SWS_SD_00129 */
void Sd_RxIndication( PduIdType RxPduId, const PduInfoType* PduInfoPtr);
/** @req SWS_SD_00130 */
void Sd_MainFunction( void );
extern const Sd_ConfigType SdConfig;
#endif
|
2301_81045437/classic-platform
|
communication/SD/inc/SD.h
|
C
|
unknown
| 3,204
|
/*-------------------------------- Arctic Core ------------------------------
* Copyright (C) 2013, ArcCore AB, Sweden, www.arccore.com.
* Contact: <contact@arccore.com>
*
* You may ONLY use this file:
* 1)if you have a valid commercial ArcCore license and then in accordance with
* the terms contained in the written license agreement between you and ArcCore,
* or alternatively
* 2)if you follow the terms found in GNU General Public License version 2 as
* published by the Free Software Foundation and appearing in the file
* LICENSE.GPL included in the packaging of this file or here
* <http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt>
*-------------------------------- Arctic Core -----------------------------*/
/** @reqSettings DEFAULT_SPECIFICATION_REVISION=4.2.2 */
/** @file SD_Types.h
* Definitions of configuration types and parameters for the SD module.
*/
#ifndef SD_TYPES_H
#define SD_TYPES_H
#include "SoAd_Types.h"
#if defined(USE_DEM)
#include "Dem.h"
#endif
typedef struct {
uint32 InitialOfferDelayMax_ms;
uint32 InitialOfferDelayMin_ms;
uint32 InitialOfferRepetitionBaseDelay_ms;
uint8 InitialOfferRepetitionsMax;
uint32 OfferCyclicDelay_ms;
uint32 RequestResponseMaxDelay_ms;
uint32 RequestResponseMinDelay_ms;
uint32 TTL;
} Sd_ServerTimerType;
typedef struct {
const uint32 InitialFindDelayMax_ms;
const uint32 InitialFindDelayMin_ms;
const uint32 InitialFindRepetitionBaseDelay_ms;
const uint8 InitialFindRepetitionsMax;
const uint32 RequestResponseMaxDelay_ms;
const uint32 RequestResponseMinDelay_ms;
const uint32 TTL;
} Sd_ClientTimerType;
typedef struct {
char* Key;
char* Value;
} Sd_CapabilityRecordType;
typedef uint16 Sd_SoAdSocketConnectionIndex;
typedef struct {
uint16 EventActivationRef;
const Sd_SoAdSocketConnectionIndex MulticastEventSoConRef;
} Sd_EventHandlerMulticastType;
typedef struct {
uint16 EventActivationRef;
const SoAd_RoutingGroupType* EventTriggeringRef;
} Sd_EventHandlerTcpUdpType;
typedef struct {
uint16 EventGroupId;
uint16 HandleId;
uint16 MulticastThreshold;
const Sd_ServerTimerType* TimerRef;
const Sd_EventHandlerMulticastType* Multicast;
const Sd_EventHandlerTcpUdpType* Tcp;
const Sd_EventHandlerTcpUdpType* Udp;
const Sd_CapabilityRecordType* CapabilityRecord;
const uint32 SdNoOfCapabiltyRecord;
} Sd_EventHandlerType;
typedef uint16 Sd_SoAdSocketConnectionGroupIndex;
#define ACTIVATION_REF_NOT_SET 0xFFFF
typedef struct {
boolean AutoRequire;
uint16 HandleId;
uint16 Id;
uint16 MulticastActivationRef;
const Sd_SoAdSocketConnectionGroupIndex* MulticastGroupRef;
const uint32 NoOfMulticastGroups;
uint16 TcpActivationRef;
const Sd_ClientTimerType* TimerRef;
uint16 UdpActivationRef;
const Sd_CapabilityRecordType* CapabilityRecord;
const uint32 SdNoOfCapabiltyRecord;
} Sd_ConsumedEventGroupType;
typedef struct {
uint32 ClientServiceActivationRef;
} Sd_ConsumedMethodsType;
typedef struct {
uint32 ServerServiceActivationRef;
} Sd_ProvidedMethodsType;
#if defined(USE_DEM)
typedef struct {
Dem_EventParameterType* SD_E_MALFORMED_MSG;
Dem_EventParameterType* SD_E_OUT_OF_RES;
Dem_EventParameterType* SD_E_SUBSCR_NACK_RECV;
} Sd_InstanceDemEventParameterRefsType;
#endif
#define SOCKET_CONNECTION_GROUP_NOT_SET 0xFFFF
typedef struct {
const boolean AutoAvailable;
const uint16 HandleId;
const uint16 Id;
const uint16 InstanceId;
const uint8 MajorVersion;
const uint32 MinorVersion;
const uint16 TcpSocketConnectionGroupId;
const uint16* TcpSocketConnectionGroupSocketConnectionIdsPtr;
const Sd_ServerTimerType* TimerRef;
const uint16 UdpSocketConnectionGroupId;
const uint16* UdpSocketConnectionGroupSocketConnectionIdsPtr;
const Sd_CapabilityRecordType* CapabilityRecord;
const uint32 SdNoOfCapabiltyRecord;
const Sd_EventHandlerType* EventHandler;
const uint32 NoOfEventHandlers;
const Sd_ProvidedMethodsType ProvidedMethods;
} Sd_ServerServiceType;
typedef struct {
const boolean AutoRequire;
const uint16 HandleId;
const uint16 Id;
const uint16 InstanceId;
const uint8 MajorVersion;
const uint32 MinorVersion;
const uint16 TcpSocketConnectionGroupId;
const uint16* TcpSocketConnectionGroupSocketConnectionIdsPtr;
const Sd_ClientTimerType* TimerRef;
const uint16 UdpSocketConnectionGroupId;
const uint16* UdpSocketConnectionGroupSocketConnectionIdsPtr;
const Sd_CapabilityRecordType* CapabilityRecord;
const uint32 SdNoOfCapabiltyRecord;
const Sd_ConsumedEventGroupType* ConsumedEventGroup;
const uint32 NoOfConsumedEventGroups;
const Sd_ConsumedMethodsType ConsumedMethods;
} Sd_ClientServiceType;
/* Sd_InstanceType */
typedef struct {
const char* HostName;
const uint32 SdNoOfClientServices;
const Sd_ClientServiceType* SdClientService;
const Sd_ClientTimerType* SdClientTimer;
#if defined(USE_DEM)
const Sd_InstanceDemEventParameterRefsType* DemEventParameterRefs;
#endif
const PduIdType MulticastRxPduId;
const Sd_SoAdSocketConnectionIndex MulticastRxPduSoConRef;
const PduIdType TxPduId;
const PduIdType UnicastRxPduId;
const Sd_SoAdSocketConnectionIndex UnicastRxPduSoConRef;
const uint32 SdNoOfServerServices;
const Sd_ServerServiceType* SdServerService;
const Sd_ServerTimerType* SdServerTimer;
}Sd_InstanceType;
/** @req SWS_SD_00690 */
/* Sd_Config */
typedef struct{
const Sd_InstanceType* Instance;
}Sd_ConfigType;
/** @req SWS_SD_00118 */
/* Sd_ServerServiceSetStateType */
typedef enum
{
SD_SERVER_SERVICE_DOWN,
SD_SERVER_SERVICE_AVAILABLE
} Sd_ServerServiceSetStateType;
/** @req SWS_SD_00405 */
/* Sd_ClientServiceSetStateType */
typedef enum
{
SD_CLIENT_SERVICE_RELEASED,
SD_CLIENT_SERVICE_REQUESTED
} Sd_ClientServiceSetStateType;
/** @req SWS_SD_00550 */
/* Sd_ConsumedEventGroupSetStateType */
typedef enum
{
SD_CONSUMED_EVENTGROUP_RELEASED,
SD_CONSUMED_EVENTGROUP_REQUESTED
} Sd_ConsumedEventGroupSetStateType;
/** @req SWS_SD_00007 */
/** @req SWS_SD_00551 */
/* Sd_ClientServiceCurrentStateType */
typedef enum
{
SD_CLIENT_SERVICE_DOWN,
SD_CLIENT_SERVICE_AVAILABLE
} Sd_ClientServiceCurrentStateType;
/** @req SWS_SD_00552 */
/* Sd_ConsumedEventGroupCurrentStateType */
typedef enum
{
SD_CONSUMED_EVENTGROUP_DOWN,
SD_CONSUMED_EVENTGROUP_AVAILABLE
} Sd_ConsumedEventGroupCurrentStateType;
/** @req SWS_SD_00553 */
/* Sd_EventHandlerCurrentStateType */
typedef enum
{
SD_EVENT_HANDLER_RELEASED,
SD_EVENT_HANDLER_REQUESTED
} Sd_EventHandlerCurrentStateType;
#endif
|
2301_81045437/classic-platform
|
communication/SD/inc/SD_Types.h
|
C
|
unknown
| 6,968
|
/*-------------------------------- Arctic Core ------------------------------
* Copyright (C) 2013, ArcCore AB, Sweden, www.arccore.com.
* Contact: <contact@arccore.com>
*
* You may ONLY use this file:
* 1)if you have a valid commercial ArcCore license and then in accordance with
* the terms contained in the written license agreement between you and ArcCore,
* or alternatively
* 2)if you follow the terms found in GNU General Public License version 2 as
* published by the Free Software Foundation and appearing in the file
* LICENSE.GPL included in the packaging of this file or here
* <http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt>
*-------------------------------- Arctic Core -----------------------------*/
/** @reqSettings DEFAULT_SPECIFICATION_REVISION=4.2.2 */
/** @req 4.2.2/SWS_SD_00001 Sd_Lcfg.c and Sd_PBcfg.c is generated */
/** @req 4.2.2/SWS_SD_00117 Imported Types */
/** @req 4.2.2/SWS_SD_00026 The Service Discovery module shall be able to reference RoutingGroup(s) per Service Instance/Eventgroup */
/** @req 4.2.2/SWS_SD_00700 The Service Discovery module shall be able to reference SocketConnections and SocketConnectionGroups per Service Instance/Eventgroup. */
/** @req 4.2.2/SWS_SD_00040 The Service Discovery module receives Service Discovery messages via the API Sd_SoAdIfRxIndication()
* and the configuration items SdInstanceUnicastRxPdu and SdInstanceMulticastRxPdu.*/
/** @req 4.2.2/SWS_SD_00135 The Service Discovery module shall support tool based configuration. */
/** @req 4.2.2/SWS_SD_00136 The configuration tool shall check the consistency of the configuration parameters at system configuration time.*/
/** @req 4.2.2/SWS_SD_00303 The Service Instance ID shall not be set to 0xFFFF for any “Instance”. */
/** @req 4.2.2/SWS_SD_00400 It shall be possible to configure the Service Discovery module as an optional AUTOSAR BSW Module. */
/** @req 4.2.2/SWS_SD_00476 Entries for Eventgroups shall not use “any values” as Service ID, Instance ID, Eventgroup ID, and/or MajorVersion. (Validation check)*/
/** @req 4.2.2/SWS_SD_00654 Different service instances of the same service on the same ECU shall use different endpoints (accomplished in SoAd configuration) */
#include "SD.h"
#include "SoAd.h"
#include "BswM.h"
#include "Det.h"
/** @req 4.2.2/SWS_SD_00003 */
#if defined (USE_DEM)
#include "Dem.h"
#endif
#include "MemMap.h"
#include "SchM_SD.h"
#include "SD_Internal.h"
/* ----------------------------[private macro]-------------------------------*/
/** @req 4.2.2/SWS_SD_00109 */
/** @req 4.2.2/SWS_SD_00110 */
/*lint -emacro(904,VALIDATE_NO_RV,VALIDATE_RV,VALIDATE)*/ /*904 PC-Lint exception to MISRA 14.7 (validate DET macros)*/
#if defined(USE_DET) && (SD_DEV_ERROR_DETECT == STD_ON)
#define VALIDATE_RV(_exp,_api,_err,_rv) \
if( !(_exp) ) { \
(void)Det_ReportError(SD_MODULE_ID,0,_api,_err); \
return _rv; \
}
#define VALIDATE(_exp,_api,_err ) \
VALIDATE_RV(_exp,_api,_err, (E_NOT_OK))
#define VALIDATE_NO_RV(_exp,_api,_err ) \
if( !(_exp) ) { \
(void)Det_ReportError(SD_MODULE_ID,0,_api,_err); \
return; \
}
#define DET_REPORTERROR(_x,_y,_z,_q) (void)Det_ReportError(_x, _y, _z, _q)
#else
#define VALIDATE_RV(_exp,_api,_err,_rv)
#define VALIDATE(_exp,_api,_err )
#define VALIDATE_NO_RV(_exp,_api,_err )
#define DET_REPORTERROR(_x,_y,_z,_q)
#endif
const Sd_ConfigType *SdCfgPtr = NULL;
/* Datastructure for dynamic data used by state machine, generated by Sd generator */
extern Sd_DynConfigType Sd_DynConfig;
/* Checks if a serveHandleId is valid or not */
static boolean InvalidHandle (uint16 serviceHandleId){
boolean status;
status = TRUE;
/* Check if serviceHandleId is stored in the service table */
for (uint32 instance=0; ((instance < SD_NUMBER_OF_INSTANCES) && (status == TRUE)); instance++)
{
for (uint32 client=0; client < SdCfgPtr->Instance[instance].SdNoOfClientServices; client++)
{
if (SdCfgPtr->Instance[instance].SdClientService[client].HandleId == serviceHandleId){
status = FALSE;
break;
}
}
}
return status;
}
/* Checks if a an eventgroupHandleId is valid or not */
static boolean InvalidConsumedEventGroupHandle (uint16 eventgroupHandleId){
boolean status;
status = TRUE;
/* Check if serviceHandleId is stored in the client consumed eventgroup table */
for (uint32 instance=0; ((instance < SD_NUMBER_OF_INSTANCES) && (status == TRUE)); instance++)
{
for (uint32 client=0; ((client < SdCfgPtr->Instance[instance].SdNoOfClientServices) && (status == TRUE)); client++)
{
for (uint32 eg=0; eg < SdCfgPtr->Instance[instance].SdClientService[client].NoOfConsumedEventGroups; eg++)
{
if (SdCfgPtr->Instance[instance].SdClientService[client].ConsumedEventGroup[eg].HandleId == eventgroupHandleId){
status = FALSE;
break;
}
}
}
}
return status;
}
/* Checks if a socket connection is valid or not */
static boolean InvalidSoCon (SoAd_SoConIdType soConId){
/* IMPROVEMENT: Check if soConId is valid or not */
(void)soConId;
return FALSE; /* TEMP */
}
/* Checks if a RxPduId is valid or not */
static boolean InvalidRxPduId (PduIdType rxPduId){
/* IMPROVEMENT: Check if rxPduId is valid or not */
(void)rxPduId;
return FALSE; /* TEMP */
}
static Sd_ModuleStateType Sd_ModuleState = SD_UNINITIALIZED;
/* Initialize state machines for all Service instances */
void ClearSdDynConfig(void){
const Ipv4Endpoint null_endpoint = {0,0,0,FALSE};
const Ipv4Multicast null_multicast = {0,0,0,FALSE};
const Sd_SubscriberType null_subscriber = {0, FALSE};
Sd_DynConfig.Instance->TxPduIpAddressAssigned = FALSE;
Sd_DynConfig.Instance->SdInitCalled = FALSE;
Sd_DynConfig.Instance->TxSoCon = 0;
/** @req 4.2.2/SWS_SD_00034 */
Sd_DynConfig.Instance->MulticastSessionID = 1;
for (uint8 i=0; i<Sd_DynConfig.Instance->InstanceCfg->SdNoOfClientServices; i++){
Sd_DynConfig.Instance->SdClientService[i].Phase = SD_DOWN_PHASE;
Sd_DynConfig.Instance->SdClientService[i].CurrentState = SD_CLIENT_SERVICE_DOWN;
Sd_DynConfig.Instance->SdClientService[i].ClientServiceMode = SD_CLIENT_SERVICE_RELEASED;
/** @req 4.2.2/SWS_SD_00021 */
if(Sd_DynConfig.Instance->SdClientService[i].ClientServiceCfg->AutoRequire == TRUE){
Sd_DynConfig.Instance->SdClientService[i].ClientServiceMode = SD_CLIENT_SERVICE_REQUESTED;
}
Sd_DynConfig.Instance->SdClientService[i].SocketConnectionOpened = FALSE;
Sd_DynConfig.Instance->SdClientService[i].TTL_Timer_Value_ms = 0;
Sd_DynConfig.Instance->SdClientService[i].TTL_Timer_Running = FALSE;
Sd_DynConfig.Instance->SdClientService[i].FindDelay_Timer_Value_ms = 0;
Sd_DynConfig.Instance->SdClientService[i].FindRepDelay_Timer_Value_ms = 0;
for (uint8 j=0;j<Sd_DynConfig.Instance->SdClientService[i].ClientServiceCfg->NoOfConsumedEventGroups;j++){
/** @req 4.2.2/SWS_SD_00440 */
if (Sd_DynConfig.Instance->SdClientService[i].ClientServiceCfg->ConsumedEventGroup[j].AutoRequire == TRUE){
Sd_DynConfig.Instance->SdClientService[i].ConsumedEventGroups[j].ConsumedEventGroupMode = SD_CONSUMED_EVENTGROUP_REQUESTED;
}
else {
Sd_DynConfig.Instance->SdClientService[i].ConsumedEventGroups[j].ConsumedEventGroupMode = SD_CONSUMED_EVENTGROUP_RELEASED;
}
Sd_DynConfig.Instance->SdClientService[i].ConsumedEventGroups[j].ConsumedEventGroupState = SD_CONSUMED_EVENTGROUP_DOWN;
Sd_DynConfig.Instance->SdClientService[i].ConsumedEventGroups[j].TTL_Timer_Value_ms = 0;
Sd_DynConfig.Instance->SdClientService[i].ConsumedEventGroups[j].UdpEndpoint = null_endpoint;
Sd_DynConfig.Instance->SdClientService[i].ConsumedEventGroups[j].TcpEndpoint = null_endpoint;
Sd_DynConfig.Instance->SdClientService[i].ConsumedEventGroups[j].MulticastAddress = null_multicast;
}
Sd_DynConfig.Instance->SdClientService[i].OfferActive = FALSE;
Sd_DynConfig.Instance->SdClientService[i].FindDelayTimerOn = FALSE;
Sd_DynConfig.Instance->SdClientService[i].FindRepDelayTimerOn = FALSE;
Sd_DynConfig.Instance->SdClientService[i].RepetitionFactor = 0;
Sd_DynConfig.Instance->SdClientService[i].FindRepetitions = 0;
Sd_DynConfig.Instance->SdClientService[i].TcpSoConOpened = FALSE;
Sd_DynConfig.Instance->SdClientService[i].UdpSoConOpened = FALSE;
Sd_DynConfig.Instance->SdClientService[i].UdpEndpoint = null_endpoint;
Sd_DynConfig.Instance->SdClientService[i].TcpEndpoint = null_endpoint;
/** @req 4.2.2/SWS_SD_00034 */
Sd_DynConfig.Instance->SdClientService[i].UnicastSessionID = 1;
}
for (uint8 i=0; i<Sd_DynConfig.Instance->InstanceCfg->SdNoOfServerServices; i++){
Sd_DynConfig.Instance->SdServerService[i].Phase = SD_DOWN_PHASE;
Sd_DynConfig.Instance->SdServerService[i].ServerServiceMode = SD_SERVER_SERVICE_DOWN;
/** @req 4.2.2/SWS_SD_00020 */
if(Sd_DynConfig.Instance->SdServerService[i].ServerServiceCfg->AutoAvailable == TRUE){
Sd_DynConfig.Instance->SdServerService[i].ServerServiceMode = SD_SERVER_SERVICE_AVAILABLE;
}
Sd_DynConfig.Instance->SdServerService[i].SocketConnectionOpened = FALSE;
Sd_DynConfig.Instance->SdServerService[i].InitialOffer_Timer_Value_ms = 0;
Sd_DynConfig.Instance->SdServerService[i].OfferRepDelay_Timer_Value_ms = 0;
Sd_DynConfig.Instance->SdServerService[i].OfferCyclicDelay_Timer_Value_ms = 0;
Sd_DynConfig.Instance->SdServerService[i].InitialOfferTimerOn = FALSE;
Sd_DynConfig.Instance->SdServerService[i].OfferRepDelayTimerOn = FALSE;
Sd_DynConfig.Instance->SdServerService[i].OfferCyclicDelayTimerOn = FALSE;
Sd_DynConfig.Instance->SdServerService[i].RepetitionFactor = 0;
Sd_DynConfig.Instance->SdServerService[i].OfferRepetitions = 0;
for (uint8 j=0;j<Sd_DynConfig.Instance->SdServerService[i].ServerServiceCfg->NoOfEventHandlers;j++){
Sd_DynConfig.Instance->SdServerService[i].EventHandlers[j].EventHandlerState = SD_EVENT_HANDLER_RELEASED;
Sd_DynConfig.Instance->SdServerService[i].EventHandlers[j].NoOfSubscribers = 0;
for (uint8 k=0; k < MAX_NO_OF_SUBSCRIBERS; k++) {
Sd_DynConfig.Instance->SdServerService[i].EventHandlers[j].FanOut[k] = null_subscriber;
}
}
Sd_DynConfig.Instance->SdServerService[i].TcpSoConOpened = FALSE;
Sd_DynConfig.Instance->SdServerService[i].UdpSoConOpened = FALSE;
/** @req 4.2.2/SWS_SD_00034 */
Sd_DynConfig.Instance->SdServerService[i].UnicastSessionID = 1;
}
}
/** @req 4.2.2/SWS_SD_00119 */
void Sd_Init( const Sd_ConfigType* ConfigPtr ){
/** @req 4.2.2/SWS_SD_00109 */
/** @req 4.2.2/SWS_SD_00110 */
#if defined(USE_DET) && (SD_DEV_ERROR_DETECT == STD_ON)
VALIDATE_NO_RV(ConfigPtr!=NULL, SD_INIT_ID, SD_E_INIT_FAILED)
//IMPROVEMENT Check rest of config, how much do we have to check?
#endif
/** @req 4.2.2/SWS_SD_00121 */
SdCfgPtr = ConfigPtr;
/** @req 4.2.2/SWS_SD_00120 */
/* IMPROVEMENT: Initialize state machines for all Service instances */
ClearSdDynConfig();
InitMessagePool();
/** @req 4.2.2/SWS_SD_00122 */
Sd_ModuleState = SD_INITIALIZED;
/* Indicate for ClientService state machine that SdInit was called since last Sd_MainFunction cycle */
Sd_DynConfig.Instance->SdInitCalled = TRUE;
/* Open Sockets for SD TX and RX messages */
(void)SoAd_GetSoConId(SdCfgPtr->Instance->TxPduId, &Sd_DynConfig.Instance->TxSoCon);
(void)SoAd_OpenSoCon(Sd_DynConfig.Instance->TxSoCon);
if (SdCfgPtr->Instance->MulticastRxPduSoConRef != SOCKET_CONNECTION_GROUP_NOT_SET){
Sd_DynConfig.Instance->MulticastRxSoCon = SdCfgPtr->Instance->MulticastRxPduSoConRef;
(void)SoAd_OpenSoCon(Sd_DynConfig.Instance->MulticastRxSoCon);
}
if (SdCfgPtr->Instance->UnicastRxPduSoConRef != SOCKET_CONNECTION_GROUP_NOT_SET){
Sd_DynConfig.Instance->UnicastRxSoCon = SdCfgPtr->Instance->UnicastRxPduSoConRef;
(void)SoAd_OpenSoCon(Sd_DynConfig.Instance->UnicastRxSoCon);
}
}
/** @req 4.2.2/SWS_SD_00126 */
#if (SD_VERSION_INFO_API == STD_ON)
/** @req 4.2.2/SWS_SD_00124 */
void Sd_GetVersionInfo( Std_VersionInfoType* versioninfo ) {
#if defined(USE_DET) && (SD_DEV_ERROR_DETECT == STD_ON)
/** @req 4.2.2/SWS_SD_00497 */
VALIDATE_NO_RV( ( NULL != versioninfo ), SD_GET_VERSION_INFO_ID, SD_E_PARAM_POINTER);
#endif
#endif
/** @req 4.2.2/SWS_SD_00125 */
versioninfo->vendorID = SD_VENDOR_ID;
versioninfo->moduleID = SD_MODULE_ID;
versioninfo->sw_major_version = SD_SW_MAJOR_VERSION;
versioninfo->sw_minor_version = SD_SW_MINOR_VERSION;
versioninfo->sw_patch_version = SD_SW_PATCH_VERSION;
return;
}
/** @req 4.2.2/SWS_SD_00496 */
Std_ReturnType Sd_ServerServiceSetState( uint16 SdServerServiceHandleId, Sd_ServerServiceSetStateType ServerServiceState) {
Std_ReturnType result = E_OK;
/** @req 4.2.2/SWS_SD_00407 */
#if defined(USE_DET) && (SD_DEV_ERROR_DETECT == STD_ON)
VALIDATE_RV(Sd_ModuleState==SD_INITIALIZED, SD_SERVER_SERVICE_SET_STATE_ID, SD_E_NOT_INITIALIZED, E_NOT_OK);
#endif
/** @req 4.2.2/SWS_SD_00408 */
if ((ServerServiceState != SD_SERVER_SERVICE_DOWN) && (ServerServiceState != SD_SERVER_SERVICE_AVAILABLE)) {
#if defined(USE_DET) && (SD_DEV_ERROR_DETECT == STD_ON)
(void)Det_ReportError(SD_MODULE_ID, 0, SD_SERVER_SERVICE_SET_STATE_ID, SD_E_INV_MODE);
#endif
/*lint -e{904} ARGUMENT CHECK */
return E_NOT_OK;
}
/** @req 4.2.2/SWS_SD_00607 */
if (InvalidHandle(SdServerServiceHandleId)) {
#if defined(USE_DET) && (SD_DEV_ERROR_DETECT == STD_ON)
(void)Det_ReportError(SD_MODULE_ID, 0, SD_SERVER_SERVICE_SET_STATE_ID, SD_E_INV_ID);
#endif
/*lint -e{904} ARGUMENT CHECK */
return E_NOT_OK;
}
/** @req 4.2.2/SWS_SD_00005 */
/* Store ServerServiceState for this Server instance */
for (uint32 instance=0; instance < SD_NUMBER_OF_INSTANCES; instance++)
{
for (uint32 server=0; server < SdCfgPtr->Instance[instance].SdNoOfServerServices; server++)
{
if (SdCfgPtr->Instance[instance].SdServerService[server].HandleId == SdServerServiceHandleId){
Sd_DynConfig.Instance[instance].SdServerService[server].ServerServiceMode = ServerServiceState;
break;
}
}
}
return result;
}
/** @req 4.2.2/SWS_SD_00409 */
Std_ReturnType Sd_ClientServiceSetState( uint16 ClientServiceHandleID, Sd_ClientServiceSetStateType ClientServiceState ) {
Std_ReturnType result = E_OK;
/** @req 4.2.2/SWS_SD_00410 */
#if defined(USE_DET) && (SD_DEV_ERROR_DETECT == STD_ON)
VALIDATE_RV(Sd_ModuleState==SD_INITIALIZED, SD_CLIENT_SERVICE_SET_STATE_ID, SD_E_NOT_INITIALIZED, E_NOT_OK);
#endif
/** @req 4.2.2/SWS_SD_00411 */
if ((ClientServiceState != SD_CLIENT_SERVICE_RELEASED) && (ClientServiceState != SD_CLIENT_SERVICE_REQUESTED)) {
#if defined(USE_DET) && (SD_DEV_ERROR_DETECT == STD_ON)
(void)Det_ReportError(SD_MODULE_ID, 0, SD_CLIENT_SERVICE_SET_STATE_ID, SD_E_INV_MODE);
#endif
/*lint -e{904} ARGUMENT CHECK */
return E_NOT_OK;
}
/** @req 4.2.2/SWS_SD_00608 */
if (InvalidHandle(ClientServiceHandleID)) {
#if defined(USE_DET) && (SD_DEV_ERROR_DETECT == STD_ON)
(void)Det_ReportError(SD_MODULE_ID, 0, SD_CLIENT_SERVICE_SET_STATE_ID, SD_E_INV_ID);
#endif
/*lint -e{904} ARGUMENT CHECK */
return E_NOT_OK;
}
/** @req 4.2.2/SWS_SD_00005 */
/* Store ClientServiceState for this Client instance */
for (uint32 instance=0; instance < SD_NUMBER_OF_INSTANCES; instance++)
{
for (uint32 client=0; client < SdCfgPtr->Instance[instance].SdNoOfClientServices; client++)
{
if (SdCfgPtr->Instance[instance].SdClientService[client].HandleId == ClientServiceHandleID){
Sd_DynConfig.Instance[instance].SdClientService[client].ClientServiceMode = ClientServiceState;
/** @req 4.2.2/SWS_SD_00443 */
if (ClientServiceState == SD_CLIENT_SERVICE_RELEASED) {
for(uint8 event_group_index= 0; \
event_group_index < SdCfgPtr->Instance[instance].SdClientService[client].NoOfConsumedEventGroups; event_group_index++){
Sd_DynConfig.Instance[instance].SdClientService[client].ConsumedEventGroups[event_group_index].ConsumedEventGroupMode =
SD_CONSUMED_EVENTGROUP_RELEASED;
}
}
else
{
/** @req 4.2.2/SWS_SD_00440 */
for(uint8 event_group_index= 0; \
event_group_index < SdCfgPtr->Instance[instance].SdClientService[client].NoOfConsumedEventGroups; event_group_index++){
if(SdCfgPtr->Instance[instance].SdClientService[client].ConsumedEventGroup[event_group_index].AutoRequire == TRUE){
Sd_DynConfig.Instance[instance].SdClientService[client].ConsumedEventGroups[event_group_index].ConsumedEventGroupMode =
SD_CONSUMED_EVENTGROUP_REQUESTED;
}
}
}
break;
}
}
}
return result;
}
/** @req 4.2.2/SWS_SD_00560 */
Std_ReturnType Sd_ConsumedEventGroupSetState( uint16 SdConsumedEventGroupHandleId, Sd_ConsumedEventGroupSetStateType ConsumedEventGroupState ) {
Std_ReturnType result = E_OK;
/** @req 4.2.2/SWS_SD_00469 */
#if defined(USE_DET) && (SD_DEV_ERROR_DETECT == STD_ON)
VALIDATE_RV(Sd_ModuleState==SD_INITIALIZED, SD_CONSUMED_EVENT_GROUP_SET_STATE_ID, SD_E_NOT_INITIALIZED, E_NOT_OK);
#endif
/** @req 4.2.2/SWS_SD_00470 */
if ((ConsumedEventGroupState != SD_CONSUMED_EVENTGROUP_RELEASED) && (ConsumedEventGroupState != SD_CONSUMED_EVENTGROUP_REQUESTED)) {
#if defined(USE_DET) && (SD_DEV_ERROR_DETECT == STD_ON)
(void)Det_ReportError(SD_MODULE_ID, 0, SD_CONSUMED_EVENT_GROUP_SET_STATE_ID, SD_E_INV_MODE);
#endif
/*lint -e{904} ARGUMENT CHECK */
return E_NOT_OK;
}
/** @req 4.2.2/SWS_SD_00609 */
if (InvalidConsumedEventGroupHandle(SdConsumedEventGroupHandleId)) {
#if defined(USE_DET) && (SD_DEV_ERROR_DETECT == STD_ON)
(void)Det_ReportError(SD_MODULE_ID, 0, SD_CONSUMED_EVENT_GROUP_SET_STATE_ID, SD_E_INV_ID);
#endif
/*lint -e{904} ARGUMENT CHECK */
return E_NOT_OK;
}
/** @req 4.2.2/SWS_SD_00005 */
/* Store ConsumedEventGroupState for this EventGroup instance */
for (uint32 instance=0; instance < SD_NUMBER_OF_INSTANCES; instance++)
{
for (uint32 client=0; client < SdCfgPtr->Instance[instance].SdNoOfClientServices; client++)
{
if (SdCfgPtr->Instance[instance].SdClientService[client].ConsumedEventGroup != NULL){
for (uint32 evGrp=0; evGrp < SdCfgPtr->Instance[instance].SdClientService[client].NoOfConsumedEventGroups; evGrp++){
if (SdCfgPtr->Instance[instance].SdClientService[client].ConsumedEventGroup[evGrp].HandleId == SdConsumedEventGroupHandleId){
/** @req 4.2.2/SWS_SD_00442 */
if (Sd_DynConfig.Instance[instance].SdClientService[client].ClientServiceMode == SD_CLIENT_SERVICE_RELEASED) {
return E_NOT_OK;
}
Sd_DynConfig.Instance[instance].SdClientService[client].ConsumedEventGroups[evGrp].ConsumedEventGroupMode = ConsumedEventGroupState;
break;
}
}
}
}
}
return result;
}
/** @req 4.2.2/SWS_SD_00412 */
void Sd_LocalIpAddrAssignmentChg( SoAd_SoConIdType SoConId, TcpIp_IpAddrStateType State ){
/** @req 4.2.2/SWS_SD_00471 */
#if defined(USE_DET) && (SD_DEV_ERROR_DETECT == STD_ON)
VALIDATE_NO_RV(Sd_ModuleState==SD_INITIALIZED, SD_LOCAL_IP_ADDR_ASSIGNMENT_CHG_ID, SD_E_NOT_INITIALIZED);
#endif
/** @req 4.2.2/SWS_SD_00472 */
if ((State != TCPIP_IPADDR_STATE_ASSIGNED) && (State != TCPIP_IPADDR_STATE_ONHOLD) && (State != TCPIP_IPADDR_STATE_UNASSIGNED)) {
#if defined(USE_DET) && (SD_DEV_ERROR_DETECT == STD_ON)
(void)Det_ReportError(SD_MODULE_ID, 0, SD_LOCAL_IP_ADDR_ASSIGNMENT_CHG_ID, SD_E_INV_MODE);
#endif
/*lint -e{904} ARGUMENT CHECK */
return;
}
/** @req 4.2.2/SWS_SD_00610 */
if (InvalidSoCon(SoConId)) {
#if defined(USE_DET) && (SD_DEV_ERROR_DETECT == STD_ON)
(void)Det_ReportError(SD_MODULE_ID, 0, SD_LOCAL_IP_ADDR_ASSIGNMENT_CHG_ID, SD_E_INV_ID);
#endif
/*lint -e{904} ARGUMENT CHECK */
return;
}
/* Assign state of IP address assignment for this socket connection */
for (uint32 instance=0; instance < SD_NUMBER_OF_INSTANCES; instance++)
{
if (Sd_DynConfig.Instance[instance].TxSoCon == SoConId) {
Sd_DynConfig.Instance[instance].TxPduIpAddressAssigned = (State == TCPIP_IPADDR_STATE_ASSIGNED);
break;
}
}
}
/** @req 4.2.2/SWS_SD_00129 */
/*lint -e{818} Pointer parameter 'PduInfoPtr' could be declared as pointing to const */
void Sd_RxIndication( PduIdType RxPduId, const PduInfoType* PduInfoPtr){
/** @req 4.2.2/SWS_SD_00473 */
#if defined(USE_DET) && (SD_DEV_ERROR_DETECT == STD_ON)
VALIDATE_NO_RV(Sd_ModuleState==SD_INITIALIZED, SD_RX_INDICATION_ID, SD_E_NOT_INITIALIZED);
#endif
/** @req 4.2.2/SWS_SD_00474 */
if (InvalidRxPduId(RxPduId)) {
#if defined(USE_DET) && (SD_DEV_ERROR_DETECT == STD_ON)
(void)Det_ReportError(SD_MODULE_ID, 0, SD_RX_INDICATION_ID, SD_E_INV_ID);
#endif
/*lint -e{904} ARGUMENT CHECK */
return;
}
/** @req 4.2.2/SWS_SD_00475 */
#if defined(USE_DET) && (SD_DEV_ERROR_DETECT == STD_ON)
VALIDATE_NO_RV(PduInfoPtr != NULL, SD_RX_INDICATION_ID, SD_E_PARAM_POINTER);
#endif
/* Handle recieved Pdu */
Handle_RxIndication(RxPduId, PduInfoPtr);
}
/** @req 4.2.2/SWS_SD_00130 */
/** @req 4.2.2/SWS_SD_00004 */
void Sd_MainFunction( void ){
/** @req 4.2.2/SWS_SD_00132 */
#if defined(USE_DET) && (SD_DEV_ERROR_DETECT == STD_ON)
VALIDATE_NO_RV(Sd_ModuleState==SD_INITIALIZED, SD_MAIN_FUNCTION_ID, SD_E_NOT_INITIALIZED);
#endif
/** @req 4.2.2/SWS_SD_00131 */
/* Update counters, times, states and phases */
Handle_PendingRespMessages();
for (uint32 instance=0; instance < SD_NUMBER_OF_INSTANCES; instance++)
{
for (uint32 client=0; client < SdCfgPtr->Instance[instance].SdNoOfClientServices; client++)
{
UpdateClientService(SdCfgPtr, instance, client);
}
for (uint32 server=0; server < SdCfgPtr->Instance[instance].SdNoOfServerServices; server++)
{
UpdateServerService(SdCfgPtr, instance, server);
}
}
}
|
2301_81045437/classic-platform
|
communication/SD/src/SD.c
|
C
|
unknown
| 23,965
|
/*-------------------------------- Arctic Core ------------------------------
* Copyright (C) 2013, ArcCore AB, Sweden, www.arccore.com.
* Contact: <contact@arccore.com>
*
* You may ONLY use this file:
* 1)if you have a valid commercial ArcCore license and then in accordance with
* the terms contained in the written license agreement between you and ArcCore,
* or alternatively
* 2)if you follow the terms found in GNU General Public License version 2 as
* published by the Free Software Foundation and appearing in the file
* LICENSE.GPL included in the packaging of this file or here
* <http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt>
*-------------------------------- Arctic Core -----------------------------*/
/** @reqSettings DEFAULT_SPECIFICATION_REVISION=4.2.2 */
/** @req 4.2.2/SWS_SD_00029 The Service Discovery module shall only call SoAd_IfTransmit() if an IP address is assigned */
#include "SD.h"
#include "SD_Internal.h"
#include "BswM_Sd.h"
#include "string.h"
/* Datastructure for dynamic data used by state machine, generated by Sd generator */
extern Sd_DynConfigType Sd_DynConfig;
static const TcpIp_SockAddrType wildcard = {
(TcpIp_DomainType) TCPIP_AF_INET,
TCPIP_PORT_ANY,
{TCPIP_IPADDR_ANY, TCPIP_IPADDR_ANY, TCPIP_IPADDR_ANY, TCPIP_IPADDR_ANY }
};
static Sd_Entry_Type1_Services entry11;
static Sd_Entry_Type2_EventGroups entry22;
static TcpIp_SockAddrType ipaddress;
static Sd_Message msg;
static uint8 *start_of_entries;
/** @req 4.2.2/SWS_SD_00485 */
static void EntryReceived(Sd_DynClientServiceType *client, Sd_Entry_Type1_Services **entry1, Sd_Entry_Type2_EventGroups **entry2, TcpIp_SockAddrType *ipaddress, boolean *is_multicast)
{
Sd_InstanceType *server_svc;
uint8 *option_run1 [MAX_OPTIONS] = {NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL};
uint8 *option_run2 [MAX_OPTIONS] = {NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL};
uint8 no_of_endpoints = 0;
uint8 no_of_multicasts = 0;
uint8 no_of_capabilty_records = 0;
Ipv4Endpoint endpoint[MAX_OPTIONS];
Ipv4Multicast multicast[MAX_OPTIONS];
Sd_CapabilityRecordType capabilty_record[MAX_OPTIONS];
/* First check if there are more entries in the last read message to fetch */
if (msg.ProtocolVersion != 0x01) {
/* Fetch a new message from the queue */
if (!ReceiveSdMessage(&msg, ipaddress, CLIENT_QUEUE, &server_svc, is_multicast)) {
*entry1 = NULL;
*entry2 = NULL;
return;
} else
{
start_of_entries = msg.EntriesArray;
}
}
/* Find out which type of entry */
uint8 type = msg.EntriesArray[0];
if ((type == 0) || (type == 1)) {
/* OFFER_SERVICE or STOP_OFFER_SERVICE */
DecodeType1Entry (msg.EntriesArray, *entry1);
*entry2 = NULL;
if (msg.LengthOfOptionsArray > 0) {
OptionsReceived(msg.OptionsArray, msg.LengthOfOptionsArray, *entry1, NULL, option_run1, option_run2);
}
/* Move entry pointer */
msg.EntriesArray += ENTRY_TYPE_1_SIZE;
}
else if ((type == 6) || (type == 7)) {
/* SUBSCRIBE_EVENTGROUP_ACK or SUBSCRIBE_EVENTGROUP_NACK */
DecodeType2Entry (msg.EntriesArray, *entry2);
*entry1 = NULL;
if (msg.LengthOfOptionsArray > 0) {
OptionsReceived(msg.OptionsArray, msg.LengthOfOptionsArray, NULL, *entry2, option_run1, option_run2);
}
/* Move entry pointer */
msg.EntriesArray += ENTRY_TYPE_2_SIZE;
}else
{
/** @req 4.2.2/SWS_SD_00483 */
*entry1 = NULL;
*entry2 = NULL;
if ((msg.EntriesArray - start_of_entries) >= msg.LengthOfEntriesArray) {
/* All entries are processed in this message.
* Set protocolversion to 0 to indicate that a new message
* should be fetched for the next entry. */
msg.ProtocolVersion = 0x00;
}
return;
}
/* Decode and store the option parameters */
/** @req 4.2.2/SWS_SD_00484 */
DecodeOptionIpv4Endpoint(option_run1, endpoint, &no_of_endpoints);
for (uint8 i=0; i < no_of_endpoints; i++){
if (endpoint[i].Protocol == UDP_PROTO) {
memcpy(&client->UdpEndpoint, &endpoint[i], sizeof(Ipv4Endpoint));
client->UdpEndpoint.valid = TRUE;
}
else if (endpoint[i].Protocol == TCP_PROTO) {
memcpy(&client->TcpEndpoint, &endpoint[i], sizeof(Ipv4Endpoint));
client->TcpEndpoint.valid = TRUE;
}
}
DecodeOptionIpv4Multicast(option_run1, multicast, &no_of_multicasts);
for (uint8 i=0; i < no_of_multicasts; i++){
for (uint8 eg=0; eg < client->ClientServiceCfg->NoOfConsumedEventGroups;eg++) {
memcpy(&client->ConsumedEventGroups[eg].MulticastAddress, &multicast[i], MAX_OPTIONS);
client->ConsumedEventGroups[eg].MulticastAddress.valid = TRUE;
}
}
/* Decode configuration option attribute */
DecodeOptionConfiguration(option_run1,capabilty_record,&no_of_capabilty_records);
/* Check if this message is aimed for this client instance */
if (*entry1 != NULL) {
/** @req 4.2.2/SWS_SD_00487 */
/* Received OfferService or StopOfferService */
if (((*entry1)->ServiceID == client->ClientServiceCfg->Id) &&
((*entry1)->InstanceID == client->ClientServiceCfg->InstanceId) &&
((*entry1)->MajorVersion == client->ClientServiceCfg->MajorVersion) &&
/** @req 4.2.2/SWS_SD_00488 */
/** @req 4.2.2/SWS_SD_00489 */
/** @req 4.2.2/SWS_SD_00482 */
/* NOTE! wildcard for MinorVersion according to 4.2.2/SWS_SD_00488 should be 0xFFFFFF. Since it is 32 bits we assume 0xFFFFFFFF. Correct?*/
((client->ClientServiceCfg->MinorVersion == 0xFFFFFFFF) || ((*entry1)->MinorVersion == client->ClientServiceCfg->MinorVersion))) {
/* This client is the intended one. Retrieve remote ipaddress. If endpoint option is set use this instead */
if (client->TcpEndpoint.valid != FALSE) {
ipaddress->addr[0] = ((client->TcpEndpoint.IPv4Address & 0xFF000000) >> 24);
ipaddress->addr[1] = ((client->TcpEndpoint.IPv4Address & 0x00FF0000) >> 16);
ipaddress->addr[2] = ((client->TcpEndpoint.IPv4Address & 0x0000FF00) >> 8);
ipaddress->addr[3] = (client->TcpEndpoint.IPv4Address & 0x000000FF);
ipaddress->domain = TCPIP_AF_INET;
ipaddress->port = client->TcpEndpoint.PortNumber;
} else if (client->UdpEndpoint.valid != FALSE) {
ipaddress->addr[0] = ((client->UdpEndpoint.IPv4Address & 0xFF000000) >> 24);
ipaddress->addr[1] = ((client->UdpEndpoint.IPv4Address & 0x00FF0000) >> 16);
ipaddress->addr[2] = ((client->UdpEndpoint.IPv4Address & 0x0000FF00) >> 8);
ipaddress->addr[3] = (client->UdpEndpoint.IPv4Address & 0x000000FF);
ipaddress->domain = TCPIP_AF_INET;
ipaddress->port = client->UdpEndpoint.PortNumber;
}
else
{
SoAd_SoConIdType server_socket = Sd_DynConfig.Instance->MulticastRxSoCon;
(void)SoAd_GetRemoteAddr(server_socket, ipaddress);
(void)SoAd_SetRemoteAddr(Sd_DynConfig.Instance->TxSoCon, &wildcard);
}
FreeSdMessage(CLIENT_QUEUE);
}
else
{
*entry1 = NULL;
*entry2 = NULL;
}
} else if (entry2 != NULL) {
/* Received SubscribeEventgroupAck or SubscribeEventgroupNack */
/** @req 4.2.2/SWS_SD_00490 */
boolean EventGroupFound = FALSE;
for (uint8 i=0; i < client->ClientServiceCfg->NoOfConsumedEventGroups; i++){
if (((*entry2)->ServiceID == client->ClientServiceCfg->Id) &&
((*entry2)->InstanceID == client->ClientServiceCfg->InstanceId) &&
((*entry2)->MajorVersion == client->ClientServiceCfg->MajorVersion) &&
((*entry2)->EventgroupID == client->ClientServiceCfg->ConsumedEventGroup[i].Id))
{
/* SoAd_RequestIpAddrAssignment is called in statemachine,
* so here we only check if the entry was aimed for this client instance. */
EventGroupFound = TRUE;
break;
}
}
if (!EventGroupFound)
{
*entry1 = NULL;
*entry2 = NULL;
}else{
FreeSdMessage(CLIENT_QUEUE);
}
}
if ((msg.EntriesArray - start_of_entries) >= msg.LengthOfEntriesArray) {
/* All entries are processed in this message.
* Set protcolversion to 0 to indicate that a new message
* should be fetched for the next entry. */
msg.ProtocolVersion = 0x00;
}
}
/* Returns a socket id defined for this client */
SoAd_SoConIdType GetSocket (Sd_DynClientServiceType const *client)
{
SoAd_SoConIdType socket = 0;
if (client->ClientServiceCfg->TcpSocketConnectionGroupSocketConnectionIdsPtr != NULL) {
socket = client->ClientServiceCfg->TcpSocketConnectionGroupSocketConnectionIdsPtr[0];
}
else if (client->ClientServiceCfg->UdpSocketConnectionGroupSocketConnectionIdsPtr != NULL)
{
socket = client->ClientServiceCfg->UdpSocketConnectionGroupSocketConnectionIdsPtr[0];
}
return socket;
}
/** @req 4.2.2/SWS_SD_00419 */
/* Set the remote address for socket used by the methods, if endpoint options are received */
static void SetMethodsRemoteAddress(Sd_DynClientServiceType *client) {
TcpIp_SockAddrType remote_address;
if (client->ClientServiceCfg->UdpSocketConnectionGroupId != SOCKET_CONNECTION_GROUP_NOT_SET)
{
if (client->UdpEndpoint.valid != FALSE) {
remote_address.addr[0] = ((client->UdpEndpoint.IPv4Address & 0xFF000000) >> 24);
remote_address.addr[1] = ((client->UdpEndpoint.IPv4Address & 0x00FF0000) >> 16);
remote_address.addr[2] = ((client->UdpEndpoint.IPv4Address & 0x0000FF00) >> 8);
remote_address.addr[3] = (client->UdpEndpoint.IPv4Address & 0x000000FF);
remote_address.domain = TCPIP_AF_INET;
remote_address.port = client->UdpEndpoint.PortNumber;
(void)SoAd_SetRemoteAddr(GetSocket(client), &remote_address);
}
} else if (client->ClientServiceCfg->TcpSocketConnectionGroupId != SOCKET_CONNECTION_GROUP_NOT_SET)
{
if (client->TcpEndpoint.valid != FALSE) {
remote_address.addr[0] = ((client->TcpEndpoint.IPv4Address & 0xFF000000) >> 24);
remote_address.addr[1] = ((client->TcpEndpoint.IPv4Address & 0x00FF0000) >> 16);
remote_address.addr[2] = ((client->TcpEndpoint.IPv4Address & 0x0000FF00) >> 8);
remote_address.addr[3] = (client->TcpEndpoint.IPv4Address & 0x000000FF);
remote_address.domain = TCPIP_AF_INET;
remote_address.port = client->TcpEndpoint.PortNumber;
(void)SoAd_SetRemoteAddr(GetSocket(client), &remote_address);
}
}
}
/* Open TCP Connection if TcpRef is configured and was not opened before*/
static void OpenTcpConnection(Sd_DynClientServiceType *client)
{
if ((client->ClientServiceCfg->TcpSocketConnectionGroupId != SOCKET_CONNECTION_GROUP_NOT_SET) && !(client->TcpSoConOpened))
{
/* Open all SoCons in Group */
for (uint16 i=0;i<sizeof(client->ClientServiceCfg->TcpSocketConnectionGroupSocketConnectionIdsPtr)/sizeof(uint16); i++){
(void)SoAd_OpenSoCon(client->ClientServiceCfg->TcpSocketConnectionGroupSocketConnectionIdsPtr[i]);
}
client->TcpSoConOpened = TRUE;
}
}
/* Open Udp Connection if UdpRef is configured and was not opened before*/
static void OpenUdpConnection(Sd_DynClientServiceType *client)
{
if ((client->ClientServiceCfg->UdpSocketConnectionGroupId != SOCKET_CONNECTION_GROUP_NOT_SET) && !(client->UdpSoConOpened))
{
/* Open all SoCons in Group */
for (uint16 i=0;i<sizeof(client->ClientServiceCfg->UdpSocketConnectionGroupSocketConnectionIdsPtr)/sizeof(uint16); i++){
(void)SoAd_OpenSoCon(client->ClientServiceCfg->UdpSocketConnectionGroupSocketConnectionIdsPtr[i]);
}
client->UdpSoConOpened = TRUE;
}
}
static void OpenSocketConnections(Sd_DynClientServiceType *client)
{
OpenTcpConnection(client);
OpenUdpConnection(client);
client->SocketConnectionOpened = TRUE;
}
/* Close TCP Connection if TcpRef is configured and was not opened before*/
static void CloseTcpConnection(Sd_DynClientServiceType *client, boolean do_abort)
{
if ((client->ClientServiceCfg->TcpSocketConnectionGroupId != SOCKET_CONNECTION_GROUP_NOT_SET) && (client->TcpSoConOpened)) {
/* Open all SoCons in Group */
for (uint16 i=0;i<sizeof(client->ClientServiceCfg->TcpSocketConnectionGroupSocketConnectionIdsPtr)/sizeof(uint16); i++) {
(void)SoAd_CloseSoCon(client->ClientServiceCfg->TcpSocketConnectionGroupSocketConnectionIdsPtr[i], do_abort);
}
client->TcpSoConOpened = FALSE;
}
}
/* Close Udp Connection if UdpRef is configured and was not opened before*/
static void CloseUdpConnection(Sd_DynClientServiceType *client, boolean do_abort)
{
if ((client->ClientServiceCfg->UdpSocketConnectionGroupId != SOCKET_CONNECTION_GROUP_NOT_SET) && (client->UdpSoConOpened)) {
for (uint16 i=0;i<sizeof(client->ClientServiceCfg->UdpSocketConnectionGroupSocketConnectionIdsPtr)/sizeof(uint16); i++) {
(void)SoAd_CloseSoCon(client->ClientServiceCfg->UdpSocketConnectionGroupSocketConnectionIdsPtr[i], do_abort);
}
client->UdpSoConOpened = FALSE;
}
}
static void CloseSocketConnections(Sd_DynClientServiceType *client, boolean do_abort)
{
CloseTcpConnection(client, do_abort);
CloseUdpConnection(client, do_abort);
client->SocketConnectionOpened = FALSE;
}
/* ClientService State Machine */
void UpdateClientService(const Sd_ConfigType *cfgPtr, uint32 instanceno, uint32 clientno) {
Sd_DynClientServiceType *client = &Sd_DynConfig.Instance[instanceno].SdClientService[clientno];
Sd_DynInstanceType *sd_instance = &Sd_DynConfig.Instance[instanceno];
Sd_Entry_Type1_Services *entry1 = &entry11;
Sd_Entry_Type2_EventGroups *entry2 = &entry22;
boolean is_multicast = FALSE;
memset(&entry11, 0, sizeof(Sd_Entry_Type1_Services));
memset(&entry22, 0, sizeof(Sd_Entry_Type2_EventGroups));
/* Fetch next entry and options, if any, from the queue */
EntryReceived(client, &entry1, &entry2, &ipaddress,&is_multicast);
switch (client->Phase)
{
case SD_DOWN_PHASE:
#if 0
/* CORE-2261 addresses this */
/** @req 4.2.2/SWS_SD_00350 */
if (client->ClientServiceCfg->AutoRequire) {
client->ClientServiceMode = SD_CLIENT_SERVICE_REQUESTED;
}
#endif
/** @req 4.2.2/SWS_SD_00463 */
if (entry1 != (Sd_Entry_Type1_Services *) NULL) {
if ((entry1->Type == STOP_OFFER_SERVICE_TYPE) && (entry1->TTL == 0)) {
client->OfferActive = FALSE;
}
}
if (client->TTL_Timer_Value_ms > 0) {
if (client->OfferActive) {
client->CurrentState = SD_CLIENT_SERVICE_AVAILABLE;
}
else {
client->CurrentState = SD_CLIENT_SERVICE_DOWN;
if (entry1 != (Sd_Entry_Type1_Services *) NULL) {
if ((entry1->Type == OFFER_SERVICE_TYPE) && (entry1->TTL > 0)) {
/* Reset TTL timer */
client->TTL_Timer_Value_ms = entry1->TTL * 1000u; /* Value in secs */
client->TTL_Timer_Running = TRUE;
client->OfferActive = TRUE;
client->CurrentState = SD_CLIENT_SERVICE_AVAILABLE;
}
}
}
/** @req 4.2.2/SWS_SD_00462 */
/** @req 4.2.2/SWS_SD_00464 */
if (client->ClientServiceMode == SD_CLIENT_SERVICE_REQUESTED) {
/* Open TCP Connection if TcpRef is configured and
* was not opened before*/
OpenTcpConnection(client);
client->TTL_Timer_Value_ms = client->ClientServiceCfg->TimerRef->TTL * 1000u; /* TBD: No req so not sure if it should be done here */
client->TTL_Timer_Running = TRUE;
client->Phase = SD_MAIN_PHASE; /* DOWN -> MAIN */
break;
}
if (client->TTL_Timer_Running) {
client->TTL_Timer_Value_ms -= SD_MAIN_FUNCTION_CYCLE_TIME_MS;
}
}else
{
client->CurrentState = SD_CLIENT_SERVICE_DOWN;
/** @req 4.2.2/SWS_SD_00463 */
if (entry1 != (Sd_Entry_Type1_Services *) NULL){
if ((entry1->Type == OFFER_SERVICE_TYPE) && (entry1->TTL > 0)) {
/* Start TTL timer */
client->TTL_Timer_Value_ms = entry1->TTL * 1000u;
client->TTL_Timer_Running = TRUE;
client->OfferActive = TRUE;
client->CurrentState = SD_CLIENT_SERVICE_AVAILABLE;
/** @req 4.2.2/SWS_SD_00464 */
if (client->ClientServiceMode == SD_CLIENT_SERVICE_REQUESTED) {
/* Open TCP Connection if TcpRef is configured and
* was not opened before*/
OpenTcpConnection(client);
client->Phase = SD_MAIN_PHASE; /* DOWN -> MAIN */
break;
}
}
}
/** @req 4.2.2/SWS_SD_00350 */
if ((client->ClientServiceMode == SD_CLIENT_SERVICE_REQUESTED) && (sd_instance->TxPduIpAddressAssigned)) {
/** @req 4.2.2/SWS_SD_00362 */
/* Call SoAd_EnableSpecificRouting():*/
(void)SoAd_EnableSpecificRouting (client->ClientServiceCfg->ConsumedMethods.ClientServiceActivationRef,
client->ClientServiceCfg->UdpSocketConnectionGroupId);
client->Phase = SD_INITIAL_WAIT_PHASE; /* DOWN -> INITIAL_WAIT */
client->TTL_Timer_Running = FALSE; /* TBD: Don't run TTL Timer in Initial Phase? */
break;
}
}
break;
case SD_INITIAL_WAIT_PHASE:
/** @req 4.2.2/SWS_SD_00355 */
if (client->ClientServiceMode == SD_CLIENT_SERVICE_RELEASED) {
/** @req 4.2.2/SWS_SD_00456 */
client->FindDelay_Timer_Value_ms = 0;
client->FindDelayTimerOn = FALSE;
client->Phase = SD_DOWN_PHASE; /* INITIAL_WAIT -> DOWN */
client->TTL_Timer_Running = FALSE;
/** @req 4.2.2/SWS_SD_00603 */
if (client->SocketConnectionOpened){
/* Call SoAd_CloseSoCon() for all socket connections
* in this client service instance */
CloseSocketConnections(client, TRUE); // IMPROVEMENT: Investigate abort parameter
}
client->CurrentState = SD_CLIENT_SERVICE_DOWN;
break;
}
/** @req 4.2.2/SWS_SD_00357 */
/** @req 4.2.2/SWS_SD_00354 */
if ((!sd_instance->TxPduIpAddressAssigned) || (sd_instance->SdInitCalled)) {
/** @req 4.2.2/SWS_SD_00456 */
client->FindDelay_Timer_Value_ms = 0;
client->FindDelayTimerOn = FALSE;
client->Phase = SD_DOWN_PHASE; /* INITIAL_WAIT -> DOWN */
client->TTL_Timer_Running = FALSE;
/** @req 4.2.2/SWS_SD_00603 */
if (client->SocketConnectionOpened){
/* Call SoAd_CloseSoCon() for all socket connections
* in this client service instance */
CloseSocketConnections(client, TRUE); // IMPROVEMENT: Investigate abort parameter
}
/* Set all ConsumedEventGroupCurrentState to DOWN */
for (uint32 eg = 0; eg < client->ClientServiceCfg->NoOfConsumedEventGroups; eg++){
BswM_Sd_ConsumedEventGroupCurrentState(
client->ClientServiceCfg->ConsumedEventGroup[eg].HandleId,
SD_CONSUMED_EVENTGROUP_DOWN);
}
client->CurrentState = SD_CLIENT_SERVICE_DOWN;
}
if (!client->FindDelayTimerOn) {
/** @req 4.2.2/SWS_SD_00351 */
/* Start random FindDelay Timer */
client->FindDelay_Timer_Value_ms = RandomDelay(client->ClientServiceCfg->TimerRef->InitialFindDelayMin_ms,
client->ClientServiceCfg->TimerRef->InitialFindDelayMax_ms);
client->CurrentState = SD_CLIENT_SERVICE_DOWN;
client->FindDelayTimerOn = TRUE;
}
else
{
/** @req 4.2.2/SWS_SD_00352 */
if (entry1 != (Sd_Entry_Type1_Services *) NULL) {
if ((entry1->Type == OFFER_SERVICE_TYPE) && (entry1->TTL > 0)) {
/** @req 4.2.2/SWS_SD_00604 */
OpenSocketConnections(client);
/** @req 4.2.2/SWS_SD_00456 */
client->FindDelay_Timer_Value_ms = 0;
client->FindDelayTimerOn = FALSE;
client->CurrentState = SD_CLIENT_SERVICE_AVAILABLE;
client->Phase = SD_MAIN_PHASE; /* INITIAL_WAIT -> MAIN */
if (entry1->TTL < TTL_TIMER_MAX) {
client->TTL_Timer_Value_ms = entry1->TTL * 1000u;
}
client->TTL_Timer_Running = TRUE;
/* OpenTCP connection if SdClientServiceTcpRef is configured and was not opened before */
OpenTcpConnection(client);
SetMethodsRemoteAddress(client);
/* Send out SubscribeEventGroup entries for all REQUESTED eventgroups */
for (uint8 event_group_index= 0; event_group_index < client->ClientServiceCfg->NoOfConsumedEventGroups; event_group_index++){
if (client->ConsumedEventGroups[event_group_index].ConsumedEventGroupMode == SD_CONSUMED_EVENTGROUP_REQUESTED) {
TransmitSdMessage(sd_instance, client, NULL, NULL, event_group_index, SD_SUBSCRIBE_EVENTGROUP, &ipaddress, is_multicast);
client->ConsumedEventGroups[event_group_index].Acknowledged = FALSE;
}
}
break;
}
}
/** @req 4.2.2/SWS_SD_00353 */
/* IMPROVEMENT: Check the calculation for the timer step. */
client->FindDelay_Timer_Value_ms -= SD_MAIN_FUNCTION_CYCLE_TIME_MS;
if (client->FindDelay_Timer_Value_ms <= 0) {
/* Send FindService Entry */
TransmitSdMessage(sd_instance, client, NULL, NULL, 0, SD_FIND_SERVICE, &ipaddress,FALSE);
/** @req 4.2.2/SWS_SD_00456 */
client->FindDelayTimerOn = FALSE;
if (client->ClientServiceCfg->TimerRef->InitialFindRepetitionsMax == 0){
client->Phase = SD_MAIN_PHASE; /* INITIAL_WAIT -> MAIN */
client->TTL_Timer_Value_ms = client->ClientServiceCfg->TimerRef->TTL * 1000u; /* TBD: No req so not sure if it should be done here */
client->TTL_Timer_Running = TRUE;
}
else {
client->Phase = SD_REPETITION_PHASE; /* INITIAL_WAIT -> REPETITION */
client->RepetitionFactor = 1;
client->FindRepetitions = 0;
client->TTL_Timer_Running = FALSE;
}
break;
}
}
break;
case SD_REPETITION_PHASE:
/** @req 4.2.2/SWS_SD_00371 */
if (client->ClientServiceMode == SD_CLIENT_SERVICE_RELEASED) {
client->FindRepDelay_Timer_Value_ms = 0;
client->FindRepDelayTimerOn = FALSE;
client->Phase = SD_DOWN_PHASE; /* REPETITION -> DOWN */
client->CurrentState = SD_CLIENT_SERVICE_DOWN;
/** @req 4.2.2/SWS_SD_00374 */
/** @req 4.2.2/SWS_SD_00024 */
/* Call SoAd_DisableSpecificRouting() for all Socket Connections
* referenced by this client service instance. IMPROVEMENT: IS this correct?*/
(void)SoAd_DisableSpecificRouting
(client->ClientServiceCfg->ConsumedMethods.ClientServiceActivationRef,
client->ClientServiceCfg->UdpSocketConnectionGroupId);
/** @req 4.2.2/SWS_SD_00603 */
if (client->SocketConnectionOpened){
/* Call SoAd_CloseSoCon() for all socket connections
* in this client service instance */
CloseSocketConnections(client, TRUE); // IMPROVEMENT: Investigate abort parameter
}
break;
}
/** @req 4.2.2/SWS_SD_00373 */
if ((!sd_instance->TxPduIpAddressAssigned)) {
client->FindRepDelay_Timer_Value_ms = 0;
client->FindRepDelayTimerOn = FALSE;
client->Phase = SD_DOWN_PHASE; /* REPETITION -> DOWN */
/* Set all ConsumedEventGroupCurrentState to DOWN */
for (uint32 eg = 0; eg < client->ClientServiceCfg->NoOfConsumedEventGroups; eg++){
BswM_Sd_ConsumedEventGroupCurrentState(
client->ClientServiceCfg->ConsumedEventGroup[eg].HandleId,
SD_CONSUMED_EVENTGROUP_DOWN);
}
client->CurrentState = SD_CLIENT_SERVICE_DOWN;
/** @req 4.2.2/SWS_SD_00603 */
if (client->SocketConnectionOpened){
/* Call SoAd_CloseSoCon() for all socket connections
* in this client service instance */
CloseSocketConnections(client, TRUE); // IMPROVEMENT: Investigate abort parameter
}
break;
}
if (!client->FindRepDelayTimerOn) {
/** @req 4.2.2/SWS_SD_00358 */
/* Start FindRepDelay Timer */
client->FindRepDelay_Timer_Value_ms = client->RepetitionFactor * client->ClientServiceCfg->TimerRef->InitialFindRepetitionBaseDelay_ms;
client->FindRepDelayTimerOn = TRUE;
}
// else
// {
/** @req 4.2.2/SWS_SD_00365 */
if (entry1 != (Sd_Entry_Type1_Services *) NULL){
if ((entry1->Type == OFFER_SERVICE_TYPE)) {
client->FindRepDelay_Timer_Value_ms = 0;
client->FindRepDelayTimerOn = FALSE;
client->CurrentState = SD_CLIENT_SERVICE_AVAILABLE;
client->Phase = SD_MAIN_PHASE; /* REPETITION -> MAIN */
if (entry1->TTL < TTL_TIMER_MAX) {
client->TTL_Timer_Value_ms = entry1->TTL * 1000u;
}
client->TTL_Timer_Running = TRUE;
/* OpenTCP connection if SdClientServiceTcpRef is configured and was not opened before */
OpenTcpConnection(client);
SetMethodsRemoteAddress(client);
/* Send out SubscribeEventGroup entries for all REQUESTED eventgroups */
for (uint8 event_group_index=0; event_group_index < client->ClientServiceCfg->NoOfConsumedEventGroups; event_group_index++){
if (client->ConsumedEventGroups[event_group_index].ConsumedEventGroupMode == SD_CONSUMED_EVENTGROUP_REQUESTED) {
TransmitSdMessage(sd_instance, client, NULL, NULL, event_group_index, SD_SUBSCRIBE_EVENTGROUP, &ipaddress, is_multicast);
client->ConsumedEventGroups[event_group_index].Acknowledged = FALSE;
}
}
break;
}
}
/** @req 4.2.2/SWS_SD_00363 */
client->FindRepDelay_Timer_Value_ms -= SD_MAIN_FUNCTION_CYCLE_TIME_MS;
/** @req 4.2.2/SWS_SD_00457 */
if (client->FindRepDelay_Timer_Value_ms <= 0) {
/* Send FindService Entry */
TransmitSdMessage(sd_instance, client, NULL, NULL, 0, SD_FIND_SERVICE, &ipaddress, FALSE);
client->FindRepDelayTimerOn = FALSE;
client->FindRepetitions++;
client->RepetitionFactor = client->RepetitionFactor * 2; /* Doubles the interval for next FindService */
/** @req 4.2.2/SWS_SD_00369 */
if (client->FindRepetitions >= client->ClientServiceCfg->TimerRef->InitialFindRepetitionsMax){
client->Phase = SD_MAIN_PHASE; /* REPETITION -> MAIN */
client->TTL_Timer_Value_ms = client->ClientServiceCfg->TimerRef->TTL * 1000u; /* TBD: No req so not sure if it should be done here */
client->TTL_Timer_Running = TRUE;
break;
}
}
// }
break;
case SD_MAIN_PHASE:
/** @req 4.2.2/SWS_SD_00600 */
if (client->TTL_Timer_Running){
client->TTL_Timer_Value_ms -= SD_MAIN_FUNCTION_CYCLE_TIME_MS;
}
/* Check TTL timeout */
if (client->TTL_Timer_Value_ms == 0u){
client->Phase = SD_INITIAL_WAIT_PHASE; /* MAIN -> INITIAL_WAIT */
client->CurrentState = SD_CLIENT_SERVICE_DOWN;
for (uint32 eg = 0; eg < client->ClientServiceCfg->NoOfConsumedEventGroups; eg++){
if (client->ConsumedEventGroups[eg].ConsumedEventGroupMode == SD_CONSUMED_EVENTGROUP_REQUESTED) {
client->ConsumedEventGroups[eg].TTL_Timer_Value_ms = 0u;
client->ConsumedEventGroups[eg].ConsumedEventGroupState = SD_CONSUMED_EVENTGROUP_DOWN;
BswM_Sd_ConsumedEventGroupCurrentState(
client->ClientServiceCfg->ConsumedEventGroup[eg].HandleId,
client->ConsumedEventGroups[eg].ConsumedEventGroupState);
}
}
break;
}
/** @req 4.2.2/SWS_SD_00601 */
for (uint32 eg = 0; eg < client->ClientServiceCfg->NoOfConsumedEventGroups; eg++){
if (client->ConsumedEventGroups[eg].ConsumedEventGroupMode == SD_CONSUMED_EVENTGROUP_REQUESTED) {
client->ConsumedEventGroups[eg].TTL_Timer_Value_ms -= SD_MAIN_FUNCTION_CYCLE_TIME_MS;
if (client->ConsumedEventGroups[eg].TTL_Timer_Value_ms <= 0u) {
client->ConsumedEventGroups[eg].TTL_Timer_Value_ms = 0u;
client->ConsumedEventGroups[eg].ConsumedEventGroupState = SD_CONSUMED_EVENTGROUP_DOWN;
BswM_Sd_ConsumedEventGroupCurrentState(
client->ClientServiceCfg->ConsumedEventGroup[eg].HandleId,
client->ConsumedEventGroups[eg].ConsumedEventGroupState);
}
}
}
/** @req 4.2.2/SWS_SD_00376 */
if (entry1 != (Sd_Entry_Type1_Services *) NULL){
if ((entry1->Type == OFFER_SERVICE_TYPE) && entry1->TTL != 0) {
client->CurrentState = SD_CLIENT_SERVICE_AVAILABLE;
/* OpenTCP connection if SdClientServiceTcpRef is configured and was not opened before */
OpenTcpConnection(client);
SetMethodsRemoteAddress(client);
if (entry1->TTL < TTL_TIMER_MAX) {
client->TTL_Timer_Value_ms = entry1->TTL * 1000u;
}
client->TTL_Timer_Running = TRUE;
for (uint32 eg = 0; eg < client->ClientServiceCfg->NoOfConsumedEventGroups; eg++){
if (client->ConsumedEventGroups[eg].ConsumedEventGroupMode == SD_CONSUMED_EVENTGROUP_REQUESTED) {
/* StopSubscribeEventgroup entry shall be sent out,
* if the last SubscribeEventgroup entry was sent as reaction to an OfferService entry
* received via Multicast, it was never answered with a SubscribeEventgroupAck,
* and the current OfferService entry was received via Multicast. */
if ((client->ConsumedEventGroups[eg].ConsumedEventGroupState == SD_CONSUMED_EVENTGROUP_AVAILABLE) &&
(!client->ConsumedEventGroups[eg].Acknowledged)) {
TransmitSdMessage(sd_instance, client, NULL, NULL, eg, SD_STOP_SUBSCRIBE_EVENTGROUP, &ipaddress, is_multicast);
client->ConsumedEventGroups[eg].ConsumedEventGroupState = SD_CONSUMED_EVENTGROUP_DOWN;
}
if (client->ConsumedEventGroups[eg].ConsumedEventGroupState == SD_CONSUMED_EVENTGROUP_DOWN){
/* Send out SubscribeEventGroup entries */
TransmitSdMessage(sd_instance, client, NULL, NULL, eg, SD_SUBSCRIBE_EVENTGROUP, &ipaddress, is_multicast);
client->ConsumedEventGroups[eg].Acknowledged = FALSE;
}
}
}
break;
}
/** @req 4.2.2/SWS_SD_00367 */
/** @req 4.2.2/SWS_SD_00422 */
else if ((entry1->Type == STOP_OFFER_SERVICE_TYPE) && (entry1->TTL == 0)) {
/* Stop the TTL timers */
client->TTL_Timer_Running = FALSE;
for (uint32 eg = 0; eg < client->ClientServiceCfg->NoOfConsumedEventGroups; eg++){
if (client->ConsumedEventGroups[eg].ConsumedEventGroupMode == SD_CONSUMED_EVENTGROUP_REQUESTED) {
client->ConsumedEventGroups[eg].TTL_Timer_Value_ms = 0u;
}
}
/* Report the client service as DOWN */
if (client->CurrentState == SD_CLIENT_SERVICE_AVAILABLE) {
client->CurrentState = SD_CLIENT_SERVICE_DOWN;
}
/* Report all ConsumedEventGroups as DOWN */
for (uint32 eg = 0; eg < client->ClientServiceCfg->NoOfConsumedEventGroups; eg++){
if (client->ConsumedEventGroups[eg].ConsumedEventGroupState == SD_CONSUMED_EVENTGROUP_AVAILABLE) {
client->ConsumedEventGroups[eg].ConsumedEventGroupState = SD_CONSUMED_EVENTGROUP_DOWN;
BswM_Sd_ConsumedEventGroupCurrentState(
client->ClientServiceCfg->ConsumedEventGroup[eg].HandleId,
SD_CONSUMED_EVENTGROUP_DOWN);
}
}
}
}else if (entry2 != ((Sd_Entry_Type2_EventGroups *) NULL)){
/** @req 4.2.2/SWS_SD_00377 */
if ((entry2->Type == SUBSCRIBE_EVENTGROUP_ACK_TYPE)) {
for (uint8 eh=0; eh < client->ClientServiceCfg->NoOfConsumedEventGroups; eh++) {
if (client->ClientServiceCfg->ConsumedEventGroup[eh].Id == entry2->EventgroupID) {
/* Use the information of the Multicast Option (if existing) to set up relevant Multicast Information in SoAd */
if (client->ConsumedEventGroups[eh].MulticastAddress.valid == TRUE){
for (uint8 grp=0; grp < client->ClientServiceCfg->ConsumedEventGroup[eh].NoOfMulticastGroups; grp++){
if (client->ClientServiceCfg->ConsumedEventGroup[eh].MulticastGroupRef[grp] != SOCKET_CONNECTION_GROUP_NOT_SET) {
TcpIp_SockAddrType LocalAddr;
uint8 netmask;
TcpIp_SockAddrType DefaultRouter;
LocalAddr.domain = TCPIP_AF_INET;
DefaultRouter.domain = TCPIP_AF_INET;
(void)SoAd_GetLocalAddr(client->ClientServiceCfg->ConsumedEventGroup[eh].MulticastGroupRef[grp],
&LocalAddr, &netmask, &DefaultRouter);
LocalAddr.addr[3] = ((client->ConsumedEventGroups[eh].MulticastAddress.IPv4Address & 0xFF000000) >> 24);
LocalAddr.addr[2] = ((client->ConsumedEventGroups[eh].MulticastAddress.IPv4Address & 0x00FF0000) >> 16);
LocalAddr.addr[1] = ((client->ConsumedEventGroups[eh].MulticastAddress.IPv4Address & 0x0000FF00) >> 8);
LocalAddr.addr[0] = (client->ConsumedEventGroups[eh].MulticastAddress.IPv4Address & 0x000000FF);
LocalAddr.domain = TCPIP_AF_INET;
LocalAddr.port = client->ConsumedEventGroups[eh].MulticastAddress.PortNumber;
(void)SoAd_RequestIpAddrAssignment(
client->ClientServiceCfg->ConsumedEventGroup[eh].MulticastGroupRef[grp],
TCPIP_IPADDR_ASSIGNMENT_STATIC, &LocalAddr,
netmask, &DefaultRouter);
/** @req 4.2.2/SWS_SD_00704 */
/* Call SoAd_EnableSpecificRouting() */
(void)SoAd_EnableSpecificRouting(
client->ClientServiceCfg->ConsumedEventGroup[eh].MulticastActivationRef,
client->ClientServiceCfg->ConsumedEventGroup[eh].MulticastGroupRef[grp]);
}
}
}
client->ConsumedEventGroups[eh].Acknowledged = TRUE;
/* Call BswM_Sd_ConsumedEventGroupCurrentState with SD_CONSUMED_EVENTGROUP_AVAILABLE. */
client->ConsumedEventGroups[eh].ConsumedEventGroupState = SD_CONSUMED_EVENTGROUP_AVAILABLE;
BswM_Sd_ConsumedEventGroupCurrentState(client->ClientServiceCfg->ConsumedEventGroup[eh].HandleId, SD_CONSUMED_EVENTGROUP_AVAILABLE);
/* Setup TTL timer with the TTL of the SubscribeEventgroupAck entry. */
client->ConsumedEventGroups[eh].TTL_Timer_Value_ms = entry2->TTL * 1000u;
break;
}
}
}
/** @req 4.2.2/SWS_SD_00465 */
else if ((entry2->Type == SUBSCRIBE_EVENTGROUP_NACK_TYPE)) {
/* IMPROVEMENT: If condition fulfilled according to requirement 4.2.2/SWS_SD_00465:
* Report the DEM error SD_E_SUBSCR_NACK_RECV and restart the TCP connection (if applicable) */
/* Call SoAd_CloseSoCon(abort=TRUE) to close all socket connections for this service instance
* Call SoAd_OpenSoCon() to reopen all socket connections for this service instance
*/
CloseSocketConnections(client, TRUE);
OpenSocketConnections(client);
}
}
/** @req 4.2.2/SWS_SD_00381 */
/** @req 4.2.2/SWS_SD_00380 */
/** @req 4.2.2/SWS_SD_00375 */
if ((client->ClientServiceMode == SD_CLIENT_SERVICE_RELEASED) ||
(!sd_instance->TxPduIpAddressAssigned)) {
client->Phase = SD_DOWN_PHASE; /* MAIN -> DOWN */
client->CurrentState = SD_CLIENT_SERVICE_DOWN;
client->TTL_Timer_Value_ms = 0u;
client->OfferActive = FALSE;
/* Report all ConsumedEventGroups as DOWN */
for (uint32 eg = 0; eg < client->ClientServiceCfg->NoOfConsumedEventGroups; eg++) {
if (client->ConsumedEventGroups[eg].ConsumedEventGroupState == SD_CONSUMED_EVENTGROUP_AVAILABLE) {
/* Send out StopSubscribeEventgroup entry, */
TransmitSdMessage(sd_instance, client, NULL, NULL, eg, SD_STOP_SUBSCRIBE_EVENTGROUP, &ipaddress, FALSE);
/** @req 4.2.2/SWS_SD_00711 */
/* Call SoAd_DisableSpecificRouting() for all socket connections associated with this client service */
if (client->ClientServiceCfg->ConsumedEventGroup[eg].TcpActivationRef != ACTIVATION_REF_NOT_SET) {
(void)SoAd_DisableSpecificRouting
(client->ClientServiceCfg->ConsumedEventGroup[eg].TcpActivationRef,
client->ClientServiceCfg->TcpSocketConnectionGroupId);
}
else if (client->ClientServiceCfg->ConsumedEventGroup[eg].UdpActivationRef != ACTIVATION_REF_NOT_SET) {
(void)SoAd_DisableSpecificRouting
(client->ClientServiceCfg->ConsumedEventGroup[eg].UdpActivationRef,
client->ClientServiceCfg->UdpSocketConnectionGroupId);
}
if (client->ConsumedEventGroups[eg].MulticastAddress.valid == TRUE){
for (uint8 grp=0; grp < client->ClientServiceCfg->ConsumedEventGroup[eg].NoOfMulticastGroups; grp++){
(void)SoAd_DisableSpecificRouting
(client->ClientServiceCfg->ConsumedEventGroup[eg].MulticastActivationRef,
client->ClientServiceCfg->ConsumedEventGroup[eg].MulticastGroupRef[grp]);
}
}
client->ConsumedEventGroups[eg].ConsumedEventGroupState = SD_CONSUMED_EVENTGROUP_DOWN;
/* NOTE! Req. 4.2.2/SWS_SD_00381 says REQUESTED but not compatible type using SD_CONSUMED_EVENTGROUP_DOWN instead */
BswM_Sd_ConsumedEventGroupCurrentState(
client->ClientServiceCfg->ConsumedEventGroup[eg].HandleId,
SD_CONSUMED_EVENTGROUP_DOWN);
}
}
/** @req 4.2.2/SWS_SD_00382 */
/** @req 4.2.2/SWS_SD_00024 */
/* Call SoAd_DisableSpecificRouting() for all socket connections associated with this client service */
(void)SoAd_DisableSpecificRouting
(client->ClientServiceCfg->ConsumedMethods.ClientServiceActivationRef,
client->ClientServiceCfg->UdpSocketConnectionGroupId);
/* Clear set endpoint options for this client */
client->TcpEndpoint.valid = FALSE;
client->UdpEndpoint.valid = FALSE;
}
break;
}
/* Indicate CurrentState to BswM */
BswM_Sd_ClientServiceCurrentState(client->ClientServiceCfg->HandleId,client->CurrentState);
/* Clear flag that indicates that SdInit was called since last Sd_MainFunction cycle */
sd_instance->SdInitCalled = FALSE;
}
|
2301_81045437/classic-platform
|
communication/SD/src/SD_ClientService.c
|
C
|
unknown
| 44,092
|
/*-------------------------------- Arctic Core ------------------------------
* Copyright (C) 2013, ArcCore AB, Sweden, www.arccore.com.
* Contact: <contact@arccore.com>
*
* You may ONLY use this file:
* 1)if you have a valid commercial ArcCore license and then in accordance with
* the terms contained in the written license agreement between you and ArcCore,
* or alternatively
* 2)if you follow the terms found in GNU General Public License version 2 as
* published by the Free Software Foundation and appearing in the file
* LICENSE.GPL included in the packaging of this file or here
* <http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt>
*-------------------------------- Arctic Core -----------------------------*/
/** @reqSettings DEFAULT_SPECIFICATION_REVISION=4.2.2 */
#include "SD_Internal.h"
#include "string.h"
#define SD_CONFIGURATION_OPTION_TYPE 0x01u
#define SD_CONFIGURATION_RESERVED_BYTE 0x00u
#define SD_HOSTNAME_KEY_LEN 0x08u
#define SD_CONFIG_OPTION_HEADER_LEN 0x04u
#define SD_CONFIGURATION_TAIL_BYTE 0x00u
void BuildServiceEntry(Sd_EntryType entry_type, const Sd_DynClientServiceType *client, const Sd_DynServerServiceType *server, uint8 *entry_array, uint8 no_of_options){
Sd_Entry_Type1_Services entry;
/* Fill in entry and msg with data from client or server configuration */
/** @req SWS_SD_0162 */
/** @req SWS_SD_0180 */
switch (entry_type)
{
case SD_FIND_SERVICE:
/** @req SWS_SD_0296 */
/** @req SWS_SD_0240 */
entry.Type = 0x00;
/** @req SWS_SD_0504 */
/** @req SWS_SD_0298 */
/** @req SWS_SD_0506. Validation check guarantees not 0 value. */
entry.TTL = client->ClientServiceCfg->TimerRef->TTL;
/** @req SWS_SD_0444 */
/** @req SWS_SD_0173 **/
entry.ServiceID = client->ClientServiceCfg->Id;
/** @req SWS_SD_0501 */
/** @req SWS_SD_0175 **/
/** @req SWS_SD_0295 **/
entry.InstanceID = client->ClientServiceCfg->InstanceId;
/** @req SWS_SD_0502 */
/** @req SWS_SD_0178 **/
entry.MajorVersion = client->ClientServiceCfg->MajorVersion;
/** @req SWS_SD_0503 */
/** @req SWS_SD_0182 **/
entry.MinorVersion = client->ClientServiceCfg->MinorVersion;
break;
case SD_OFFER_SERVICE:
/** @req SWS_SD_0297 */
/** @req SWS_SD_0254 */
entry.Type = 0x01;
/** @req SWS_SD_0513 */
/** @req SWS_SD_0299 */
/** @req SWS_SD_0515. Validation check guarantees not 0 value. */
entry.TTL = server->ServerServiceCfg->TimerRef->TTL;
/** @req SWS_SD_0509 */
/** @req SWS_SD_0173 **/
entry.ServiceID = server->ServerServiceCfg->Id;
/** @req SWS_SD_0510 */
/** @req SWS_SD_0175 **/
/** @req SWS_SD_0295 **/
entry.InstanceID = server->ServerServiceCfg->InstanceId;
/** @req SWS_SD_0511 */
/** @req SWS_SD_0178 **/
entry.MajorVersion = server->ServerServiceCfg->MajorVersion;
/** @req SWS_SD_0512 */
/** @req SWS_SD_0182 **/
entry.MinorVersion = server->ServerServiceCfg->MinorVersion;
break;
case SD_STOP_OFFER_SERVICE:
/** @req SWS_SD_0297 */
/** @req SWS_SD_0423 */
entry.Type = 0x01;
/** @req SWS_SD_0425 */
/** @req SWS_SD_0253 */
entry.TTL = 0;
/** @req SWS_SD_0424 */
/** @req SWS_SD_0173 **/
entry.ServiceID = server->ServerServiceCfg->Id;
/** @req SWS_SD_0175 **/
/** @req SWS_SD_0295 **/
entry.InstanceID = server->ServerServiceCfg->InstanceId;
/** @req SWS_SD_0178 **/
entry.MajorVersion = server->ServerServiceCfg->MajorVersion;
/** @req SWS_SD_0182 **/
entry.MinorVersion = server->ServerServiceCfg->MinorVersion;
break;
default:
/* Error. IMPROVEMENT: Error handling? */
entry.Type = 0x00;
entry.TTL = 0;
entry.ServiceID = 0;
entry.InstanceID = 0;
entry.MajorVersion = 0;
entry.MinorVersion = 0;
break;
}
/** @req SWS_SD_0267 */
/** @req SWS_SD_0164 */
entry.IndexFirstOptionRun = 0; /* Currently always 0 in one-entry messages */
/** @req SWS_SD_0166 */
entry.IndexSecondOptionRun = 0; /* Currently always 0 in one-entry messages */
/** @req SWS_SD_0168 */
entry.NumberOfOption1 = no_of_options;
/** @req SWS_SD_0170 */
entry.NumberOfOption2 = 0; /* Currently always 0 in one-entry messages */
/* IMPROVEMENT: Handle options for multi-entry messages */
/** @req SWS_SD_0294 */
FillType1Entry(entry, entry_array);
}
void BuildEventGroupsEntry(Sd_EntryType entry_type, const Sd_DynClientServiceType *client, const Sd_Entry_Type2_EventGroups *subscribe_entry, uint8 event_group_index, uint8 *entry_array, uint8 no_of_options){
Sd_Entry_Type2_EventGroups entry;
/* Fill in entry and msg with data from client or server */
/** @req SWS_SD_0385 */
/** @req SWS_SD_0200 */
/** @req SWS_SD_0289 */
switch (entry_type)
{
case SD_SUBSCRIBE_EVENTGROUP:
/** @req SWS_SD_0301 */
/** @req SWS_SD_0312 */
entry.Type = 0x06;
/** @req SWS_SD_0193 **/
entry.ServiceID = client->ClientServiceCfg->Id;
/** @req SWS_SD_0195 **/
entry.InstanceID = client->ClientServiceCfg->InstanceId;
/** @req SWS_SD_0198 **/
entry.MajorVersion = client->ClientServiceCfg->MajorVersion;
entry.Counter = 0; /* IMPROVEMENT: Handle multiple subscriptions. */
if (client->ClientServiceCfg->ConsumedEventGroup != NULL) {
/** @req SWS_SD_0304 */
entry.TTL = client->ClientServiceCfg->ConsumedEventGroup[event_group_index].TimerRef->TTL;
if (client->ConsumedEventGroups[event_group_index].ConsumedEventGroupMode == SD_CONSUMED_EVENTGROUP_REQUESTED) {
/** @req SWS_SD_0204 **/
/** @req SWS_SD_0291 */
entry.EventgroupID = client->ClientServiceCfg->ConsumedEventGroup[event_group_index].Id;
}
else{
/* Should not occur? */
entry.EventgroupID = 0;
}
}
else {
entry.EventgroupID = 0;
}
break;
case SD_STOP_SUBSCRIBE_EVENTGROUP:
/** @req SWS_SD_0301 */
/** @req SWS_SD_0313 */
entry.Type = 0x06;
/** @req SWS_SD_0426 */
/** @req SWS_SD_0306 */
entry.TTL = 0;
/** @req SWS_SD_0427 */
/** @req SWS_SD_0193 **/
entry.ServiceID = client->ClientServiceCfg->Id;
/** @req SWS_SD_0195 **/
entry.InstanceID = client->ClientServiceCfg->InstanceId;
/** @req SWS_SD_0198 **/
entry.MajorVersion = client->ClientServiceCfg->MajorVersion;
entry.Counter = 0; /* IMPROVEMENT: Handle multiple subscriptions. */
if (client->ClientServiceCfg->ConsumedEventGroup != NULL) {
if (client->ConsumedEventGroups[event_group_index].ConsumedEventGroupMode == SD_CONSUMED_EVENTGROUP_REQUESTED) {
/** @req SWS_SD_0204 **/
/** @req SWS_SD_0291 */
entry.EventgroupID = client->ClientServiceCfg->ConsumedEventGroup[event_group_index].Id;
}
else{
/* Should not occur? */
entry.EventgroupID = 0;
}
}
else {
entry.EventgroupID = 0;
}
break;
case SD_SUBSCRIBE_EVENTGROUP_ACK:
/** @req SWS_SD_00314 */
entry.Type = 0x07;
/** @req SWS_SD_00315 */
entry.TTL = subscribe_entry->TTL;
/** @req SWS_SD_00428 */
/** @req SWS_SD_0193 **/
entry.ServiceID = subscribe_entry->ServiceID;
/** @req SWS_SD_0195 **/
entry.InstanceID = subscribe_entry->InstanceID;
/** @req SWS_SD_0198 **/
entry.MajorVersion = subscribe_entry->MajorVersion;
entry.Counter = subscribe_entry->Counter;
/** @req SWS_SD_0204 **/
/** @req SWS_SD_0291 */
entry.EventgroupID = subscribe_entry->EventgroupID;
break;
case SD_SUBSCRIBE_EVENTGROUP_NACK:
/** @req SWS_SD_00316 */
entry.Type = 0x07;
/** @req SWS_SD_00432 */
/** @req SWS_SD_00306 */
entry.TTL = 0;
/** @req SWS_SD_00431 */
/** @req SWS_SD_0193 **/
entry.ServiceID = subscribe_entry->ServiceID;
/** @req SWS_SD_0195 **/
entry.InstanceID = subscribe_entry->InstanceID;
/** @req SWS_SD_0198 **/
entry.MajorVersion = subscribe_entry->MajorVersion;
entry.Counter = subscribe_entry->Counter;
/** @req SWS_SD_0204 **/
/** @req SWS_SD_0291 */
entry.EventgroupID = subscribe_entry->EventgroupID;
break;
default:
/* Error */
entry.Type = 0x00;
entry.TTL = 0;
entry.ServiceID = 0;
entry.InstanceID = 0;
entry.MajorVersion = 0;
break;
}
entry.IndexFirstOptionRun = 0; /* IMPROVEMENT: Handling of Options */
entry.IndexSecondOptionRun = 0;
entry.NumberOfOption1 = 0;
entry.NumberOfOption2 = 0;
/** @req SWS_SD_0386 */
entry.IndexFirstOptionRun = 0; /* Currently always 0 in one-entry messages */
/** @req SWS_SD_0187 */
entry.IndexSecondOptionRun = 0; /* Currently always 0 in one-entry messages */
/** @req SWS_SD_0188 */
entry.NumberOfOption1 = no_of_options;
/** @req SWS_SD_0190 */
entry.NumberOfOption2 = 0; /* Currently always 0 in one-entry messages */
/* IMPROVEMENT: Handle options for multi-entry messages */
/** @req SWS_SD_0290 */
FillType2Entry(entry, entry_array);
}
#define IPV4ENDPOINT_OPTION_LENGTH 12
#define IPV4ENDPOINT_OPTION_TYPE 0x04
#define IPV4MULTICAST_OPTION_LENGTH 12
#define IPV4MULTICAST_OPTION_TYPE 0x14
/* Build an Ipv4 Option from the socket connection group sent as parameter */
void BuildIpv4EndpointOption(const uint16* socket_connection_group, uint8 protocol, uint32* offset, uint8 *options_array, uint32 *options_length) {
TcpIp_SockAddrType LocalAddrPtr;
uint8 NetmaskPtr;
TcpIp_SockAddrType DefaultRouterPtr;
/** @req SWS_SD_0210 */
/** @req SWS_SD_0211 */
/** @req SWS_SD_0213 */
/** @req SWS_SD_0214 */
uint8 endpoint_option[IPV4ENDPOINT_OPTION_LENGTH] = {0x00,0x00,IPV4ENDPOINT_OPTION_TYPE,0x00,0x00,0x00,0x00,0x00,0x00,protocol,0x00,0x00};
LocalAddrPtr.domain = TCPIP_AF_INET;
DefaultRouterPtr.domain = TCPIP_AF_INET;
/* Get local ipaddress data from the first SoCon in the Group */
for (uint16 i=0;i<sizeof(socket_connection_group)/sizeof(uint16); i++){
(void)SoAd_GetLocalAddr(socket_connection_group[i], &LocalAddrPtr, &NetmaskPtr, &DefaultRouterPtr);
if (LocalAddrPtr.domain == TCPIP_AF_INET) {
/* Set option length = always 9 */
/** @req SWS_SD_0209 */
endpoint_option[1] = 0x09;
/* Set ipv4-Address */
/** @req SWS_SD_0212 */
memcpy(&endpoint_option[4],LocalAddrPtr.addr,4);
/* Set port number */
/** @req SWS_SD_0215 */
uint16 port = htonl16(LocalAddrPtr.port);
memcpy(&endpoint_option[10],&port,2);
break;
}
}
if (endpoint_option[1] == 0x09){
/* option data created. Copy it to option array */
memcpy (&options_array[*offset], &endpoint_option[0], IPV4ENDPOINT_OPTION_LENGTH);
*offset += IPV4ENDPOINT_OPTION_LENGTH;
*options_length = *offset;
}
}
/* Build an Ipv4 Multicast Option from the socket connection group sent as parameter */
void BuildIpv4MulticastOption(const uint16 socket_connection, uint32* offset, uint8 *options_array, uint32 *options_length) {
TcpIp_SockAddrType LocalAddrPtr;
uint8 NetmaskPtr;
TcpIp_SockAddrType DefaultRouterPtr;
/** @req SWS_SD_00391 */
/** @req SWS_SD_00392 */
/** @req SWS_SD_00394 */
/** @req SWS_SD_00395 */
uint8 multicast_option[IPV4MULTICAST_OPTION_LENGTH] = {0x00,0x00,IPV4MULTICAST_OPTION_TYPE,0x00,0x00,0x00,0x00,0x00,0x00,UDP_PROTO,0x00,0x00};
LocalAddrPtr.domain = TCPIP_AF_INET;
DefaultRouterPtr.domain = TCPIP_AF_INET;
/* Get local ipaddress data from the first SoCon in the Group */
(void)SoAd_GetLocalAddr(socket_connection, &LocalAddrPtr, &NetmaskPtr, &DefaultRouterPtr);
if (LocalAddrPtr.domain == TCPIP_AF_INET) {
/** @req SWS_SD_00390 */
/* Set option length = always 9 */
multicast_option[1] = 0x09;
/** @req SWS_SD_00393 */
/* Set ipv4-Address */
memcpy(&multicast_option[4],LocalAddrPtr.addr,4);
/** @req SWS_SD_00396 */
/* Set port number */
uint16 port = htonl16(LocalAddrPtr.port);
memcpy(&multicast_option[10],&port,2);
}
if (multicast_option[1] == 0x09){
/* option data created. Copy it to option array */
memcpy (&options_array[*offset], &multicast_option[0], IPV4MULTICAST_OPTION_LENGTH);
*offset += IPV4MULTICAST_OPTION_LENGTH;
*options_length = *offset;
}
}
/* Build hostname configuration option */
void BuildHostNameConfigOption(uint32* offset, uint8 *options_array, uint16* totalConfigLen,const char* hostName ) {
uint16 hostNameValueLen = strlen(hostName);
char hostNameKey[SD_HOSTNAME_KEY_LEN] = {'h','o','s','t','n','a','m','e'};
*offset = *offset + SD_CONFIG_OPTION_HEADER_LEN; /* Leave it configuration header */
options_array[*offset] = SD_HOSTNAME_KEY_LEN + 1 + hostNameValueLen;
memcpy (&options_array[*offset + 1], hostNameKey, SD_HOSTNAME_KEY_LEN);
options_array[*offset + 1 + SD_HOSTNAME_KEY_LEN] = '=';
memcpy (&options_array[*offset + 2 + SD_HOSTNAME_KEY_LEN],hostName,hostNameValueLen);
*totalConfigLen = options_array[*offset] + 1; /* add Length byte of hostname key pair */
*offset = (*offset + 2 + SD_HOSTNAME_KEY_LEN + hostNameValueLen);
}
void BuildClientConfigOption(uint32* offset, uint8 *options_array, uint16* totalConfigLen,Sd_EntryType entry_type, const Sd_DynClientServiceType *client, uint8 event_index){
uint8 keyLen;
uint8 valueLen;
uint8 i;
if(client->ClientServiceCfg->CapabilityRecord != NULL){
if(*totalConfigLen == 0){
*offset = *offset + SD_CONFIG_OPTION_HEADER_LEN; /* Leave it for configuration header */
}
for(i= 0; i < client->ClientServiceCfg->SdNoOfCapabiltyRecord; i++ ){
keyLen = strlen(client->ClientServiceCfg->CapabilityRecord[i].Key);
valueLen = 0;
options_array[*offset] = keyLen;
memcpy(&options_array[*offset+1], client->ClientServiceCfg->CapabilityRecord[i].Key, keyLen);
options_array[*offset + 1 + keyLen] = '=';
options_array[*offset] += 1;
if(client->ClientServiceCfg->CapabilityRecord[i].Value != NULL){
valueLen = strlen(client->ClientServiceCfg->CapabilityRecord[i].Value);
options_array[*offset] += valueLen;
memcpy(&options_array[*offset+2+keyLen], client->ClientServiceCfg->CapabilityRecord[i].Value, valueLen);
}
*totalConfigLen += options_array[*offset] + 1; /* add Length byte of key pair */
*offset = (*offset + 2 + keyLen + valueLen);
}
}
if((entry_type == SD_SUBSCRIBE_EVENTGROUP) ||
(entry_type == SD_STOP_SUBSCRIBE_EVENTGROUP)){
if(client->ClientServiceCfg->ConsumedEventGroup[event_index].CapabilityRecord != NULL){
if(*totalConfigLen == 0){
*offset = *offset + SD_CONFIG_OPTION_HEADER_LEN; /* Leave it for configuration header */
}
for(i= 0; i < client->ClientServiceCfg->ConsumedEventGroup[event_index].SdNoOfCapabiltyRecord; i++ ){
keyLen = strlen(client->ClientServiceCfg->ConsumedEventGroup[event_index].CapabilityRecord[i].Key);
valueLen = 0;
options_array[*offset] = keyLen;
memcpy(&options_array[*offset+1], client->ClientServiceCfg->ConsumedEventGroup[event_index].CapabilityRecord[i].Key, keyLen);
options_array[*offset + 1 + keyLen] = '=';
options_array[*offset] += 1;
if(client->ClientServiceCfg->ConsumedEventGroup[event_index].CapabilityRecord[i].Value != NULL){
valueLen = strlen(client->ClientServiceCfg->ConsumedEventGroup[event_index].CapabilityRecord[i].Value);
options_array[*offset] += valueLen;
memcpy(&options_array[*offset+2+keyLen], client->ClientServiceCfg->ConsumedEventGroup[event_index].CapabilityRecord[i].Value, valueLen);
}
*totalConfigLen += options_array[*offset] + 1; /* add Length byte of key pair */
*offset = (*offset + 2 + keyLen + valueLen);
}
}
}
}
void BuildServerConfigOption(uint32* offset, uint8 *options_array, uint16* totalConfigLen,Sd_EntryType entry_type, const Sd_DynServerServiceType *server, uint8 event_index){
uint8 keyLen;
uint8 valueLen;
uint8 i;
if(server->ServerServiceCfg->CapabilityRecord != NULL){
if(*totalConfigLen == 0){
*offset = *offset + SD_CONFIG_OPTION_HEADER_LEN; /* Leave it for configuration header */
}
for(i= 0; i < server->ServerServiceCfg->SdNoOfCapabiltyRecord; i++ ){
keyLen = strlen(server->ServerServiceCfg->CapabilityRecord[i].Key);
valueLen = 0;
options_array[*offset] = keyLen;
memcpy(&options_array[*offset+1], server->ServerServiceCfg->CapabilityRecord[i].Key, keyLen);
options_array[*offset + 1 + keyLen] = '=';
options_array[*offset] += 1;
if(server->ServerServiceCfg->CapabilityRecord[i].Value != NULL){
valueLen = strlen(server->ServerServiceCfg->CapabilityRecord[i].Value);
options_array[*offset] += valueLen;
memcpy(&options_array[*offset+2+keyLen], server->ServerServiceCfg->CapabilityRecord[i].Value, valueLen);
}
*totalConfigLen += options_array[*offset] + 1; /* add Length byte of hostname key pair */
*offset = (*offset + 2 + keyLen + valueLen);
}
}
if((entry_type == SD_SUBSCRIBE_EVENTGROUP_ACK) ||
(entry_type == SD_SUBSCRIBE_EVENTGROUP_NACK)){
if(server->ServerServiceCfg->EventHandler[event_index].CapabilityRecord != NULL){
if(*totalConfigLen == 0){
*offset = *offset + SD_CONFIG_OPTION_HEADER_LEN; /* Leave it for configuration header */
}
for(i= 0; i < server->ServerServiceCfg->EventHandler[event_index].SdNoOfCapabiltyRecord; i++ ){
keyLen = strlen(server->ServerServiceCfg->EventHandler[event_index].CapabilityRecord[i].Key);
valueLen = 0;
options_array[*offset] = keyLen;
memcpy(&options_array[*offset+1], server->ServerServiceCfg->EventHandler[event_index].CapabilityRecord[i].Key, keyLen);
options_array[*offset + 1 + keyLen] = '=';
options_array[*offset] += 1;
if(server->ServerServiceCfg->EventHandler[event_index].CapabilityRecord[i].Value != NULL){
valueLen = strlen(server->ServerServiceCfg->EventHandler[event_index].CapabilityRecord[i].Value);
options_array[*offset] += valueLen;
memcpy(&options_array[*offset+2+keyLen], server->ServerServiceCfg->EventHandler[event_index].CapabilityRecord[i].Value, valueLen);
}
*totalConfigLen += options_array[*offset] + 1; /* add Length byte of hostname key pair */
*offset = (*offset + 2 + keyLen + valueLen);
}
}
}
}
/** @req SWS_SD_00505 */
/** @req SWS_SD_00205 */
/** @req SWS_SD_00206 */
/** @req SWS_SD_00207 */
/** @req SWS_SD_00208 */
/** @req SWS_SD_00292 */
/** @req SWS_SD_00461 */
/** @req SWS_SD_00467 */
/** @req SWS_SD_00468 */
/** @req SWS_SD_00307 */
/** @req SWS_SD_00281 */
/** @req SWS_SD_00293 */ /* otherserv record needs to be configured from the configurator and built here accorndingly */
/* Create the option array that should be included in the message for this entry */
void BuildOptionsArray(Sd_EntryType entry_type, const Sd_DynClientServiceType *client, const Sd_DynServerServiceType *server, uint8 event_index, uint8 *options_array, uint32 *options_length, uint8 *no_of_options,const char* hostName){
/* Fill in options array with data from client or server */
uint32 offset = 0;
uint32 prev_offset = 0;
*options_length = 0;
*no_of_options = 0;
/** @req SWS_SD_0477 */
switch (entry_type)
{
case SD_FIND_SERVICE:
case SD_SUBSCRIBE_EVENTGROUP_NACK:
/* Only configuration options allowed which is created later. */
break;
case SD_OFFER_SERVICE:
case SD_STOP_OFFER_SERVICE:
/** @req SWS_SD_00416 */
/** @req SWS_SD_00417 */
/** @req SWS_SD_00653 */
/* Build Ipv4Endpoint options from server config */
prev_offset = offset;
/* Build Tcp options if socket connection is configured */
if ((server->ServerServiceCfg->TcpSocketConnectionGroupId != SOCKET_CONNECTION_GROUP_NOT_SET))
{
BuildIpv4EndpointOption(server->ServerServiceCfg->TcpSocketConnectionGroupSocketConnectionIdsPtr, TCP_PROTO, &offset, options_array, options_length);
}
if (offset > prev_offset) {
(*no_of_options)++;
prev_offset = offset;
}
/* Build Udp option if socket connection is configured */
if ((server->ServerServiceCfg->UdpSocketConnectionGroupId != SOCKET_CONNECTION_GROUP_NOT_SET))
{
BuildIpv4EndpointOption(server->ServerServiceCfg->UdpSocketConnectionGroupSocketConnectionIdsPtr, UDP_PROTO, &offset, options_array, options_length);
}
if (offset > prev_offset) {
(*no_of_options)++;
}
break;
case SD_SUBSCRIBE_EVENTGROUP:
case SD_STOP_SUBSCRIBE_EVENTGROUP:
/** @req SWS_SD_00655 */
/* Build Ipv4Endpoint options from client config */
prev_offset = offset;
/* Build Tcp options if socket connection is configured */
if ((client->ClientServiceCfg->TcpSocketConnectionGroupId != SOCKET_CONNECTION_GROUP_NOT_SET))
{
BuildIpv4EndpointOption(client->ClientServiceCfg->TcpSocketConnectionGroupSocketConnectionIdsPtr, TCP_PROTO, &offset, options_array, options_length);
}
if (offset > prev_offset) {
(*no_of_options)++;
prev_offset = offset;
}
/* Build Udp option if socket connection is configured */
if ((client->ClientServiceCfg->UdpSocketConnectionGroupId != SOCKET_CONNECTION_GROUP_NOT_SET))
{
BuildIpv4EndpointOption(client->ClientServiceCfg->UdpSocketConnectionGroupSocketConnectionIdsPtr, UDP_PROTO, &offset, options_array, options_length);
}
if (offset > prev_offset) {
(*no_of_options)++;
}
break;
case SD_SUBSCRIBE_EVENTGROUP_ACK:
/* Build Multicast options from server config */
prev_offset = offset;
/** @req SWS_SD_00659 */
/** @req SWS_SD_00429 */
if ( (server->ServerServiceCfg->EventHandler[event_index].Multicast != NULL) &&
(server->ServerServiceCfg->EventHandler[event_index].Multicast->MulticastEventSoConRef != SOCKET_CONNECTION_GROUP_NOT_SET))
{
BuildIpv4MulticastOption(server->ServerServiceCfg->EventHandler[event_index].Multicast->MulticastEventSoConRef, &offset, options_array, options_length);
}
if (offset > prev_offset) {
(*no_of_options)++;
}
break;
default:
/* Error. Should not occur */
return;
}
/* Build configuration option */
prev_offset = offset;
uint16 totalConfigLen = 0u;
if(hostName != NULL ) {
BuildHostNameConfigOption(&offset, options_array, &totalConfigLen,hostName);
}
if (client != NULL){
BuildClientConfigOption(&offset, options_array,&totalConfigLen,entry_type, client, event_index);
}
else if (server != NULL){
BuildServerConfigOption(&offset, options_array,&totalConfigLen,entry_type, server, event_index);
}else{
/* For Misra */
}
if (offset > prev_offset) {
(*no_of_options)++; /* Zero-terminated Configuration String,number of options is incremented by 1 always ???? */
totalConfigLen += 2u; /* reserved byte + Tail 0x00 byte */
options_array[prev_offset + 0] = (uint8) ((totalConfigLen >> 8u) & 0xFFu);
options_array[prev_offset + 1] = (uint8) (totalConfigLen & 0xFFu);
options_array[prev_offset + 2] = SD_CONFIGURATION_OPTION_TYPE;
options_array[prev_offset + 3] = SD_CONFIGURATION_RESERVED_BYTE;
options_array[offset] = SD_CONFIGURATION_TAIL_BYTE;
*options_length += totalConfigLen+3;
}
}
/* Fills in an array with pointers to each option record in the option array in the message */
void OptionsReceived (uint8 *options_array, uint32 length, Sd_Entry_Type1_Services *entry1, Sd_Entry_Type2_EventGroups *entry2, uint8 **options1, uint8 **options2) {
uint8* opt_address[MAX_OPTIONS];
memset (opt_address, 0, (MAX_OPTIONS * 4));
/* Assign startaddresses of all options in the Options Array */
uint32 offset = 0;
uint8 index = 0;
while (offset < length) {
uint16 current_option_length = (uint16) (options_array[offset] * 16 + options_array[offset+1]);
opt_address[index] = (uint8 *) (options_array + offset);
offset += (current_option_length + 3);
index++;
}
/* Assign the result options array addresses */
/** @req SWS_SD_0223 */
/** @req SWS_SD_0224 */
/** @req SWS_SD_0225 */
/** @req SWS_SD_0226 */
uint8 opt = 0;
if (entry1 != NULL){
for (opt = 0; opt < entry1->NumberOfOption1; opt++) {
options1[opt] = opt_address[entry1->IndexFirstOptionRun + opt];
}
for (opt = 0; opt < entry1->NumberOfOption2; opt++) {
options2[opt] = opt_address[entry1->IndexSecondOptionRun + opt];
}
}
else if (entry2 != NULL){
for (opt = 0; opt < entry2->NumberOfOption1; opt++) {
options1[opt] = opt_address[entry2->IndexFirstOptionRun + opt];
}
for (opt = 0; opt < entry2->NumberOfOption2; opt++) {
options2[opt] = opt_address[entry2->IndexSecondOptionRun + opt];
}
}
}
|
2301_81045437/classic-platform
|
communication/SD/src/SD_Entries.c
|
C
|
unknown
| 27,547
|
/*-------------------------------- Arctic Core ------------------------------
* Copyright (C) 2013, ArcCore AB, Sweden, www.arccore.com.
* Contact: <contact@arccore.com>
*
* You may ONLY use this file:
* 1)if you have a valid commercial ArcCore license and then in accordance with
* the terms contained in the written license agreement between you and ArcCore,
* or alternatively
* 2)if you follow the terms found in GNU General Public License version 2 as
* published by the Free Software Foundation and appearing in the file
* LICENSE.GPL included in the packaging of this file or here
* <http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt>
*-------------------------------- Arctic Core -----------------------------*/
/** @reqSettings DEFAULT_SPECIFICATION_REVISION=4.2.2 */
#ifndef SD_INTERNAL_H_
#define SD_INTERNAL_H_
#include "SD.h"
//lint -w1
/*lint -esym(526,ReceiveSdMessage,FreeMessage,RandomDelay,TransmitSdMessage,DecodeType1Entry,DecodeType2Entry,
Sd_DynConfig,FillMessage,DecodeMessage,BuildServiceEntry,BuildEventGroupsEntry,InitMessagePool,UpdateClientService,
UpdateServerService,Handle_RxIndication,PutBackSdMessage,OptionsReceived, DecodeOptionIpv4Endpoint,Handle_PendingRespMessages) */
/* -----------------------------------------------------------------------*/
#define UDP_PROTO 0x11
#define TCP_PROTO 0x06
/* Types for dynamic data in the client and server service state machines */
typedef enum {
SD_DOWN_PHASE,
SD_INITIAL_WAIT_PHASE,
SD_REPETITION_PHASE,
SD_MAIN_PHASE
} Sd_PhaseType;
typedef struct {
uint32 IPv4Address;
uint8 Protocol;
uint16 PortNumber;
boolean valid;
}Ipv4Endpoint;
typedef struct {
uint32 IPv4Address;
uint8 Protocol;
uint16 PortNumber;
boolean valid;
} Ipv4Multicast;
/* Sd_DynConsumedEventGroupType */
typedef struct {
Sd_ConsumedEventGroupSetStateType ConsumedEventGroupMode;
Sd_ConsumedEventGroupCurrentStateType ConsumedEventGroupState;
uint32 TTL_Timer_Value_ms;
Ipv4Endpoint UdpEndpoint;
Ipv4Endpoint TcpEndpoint;
Ipv4Multicast MulticastAddress;
boolean Acknowledged;
}Sd_DynConsumedEventGroupType;
/* Sd_DynClientServiceType */
typedef struct {
const Sd_ClientServiceType *ClientServiceCfg; /* static config */
Sd_PhaseType Phase;
Sd_ClientServiceCurrentStateType CurrentState;
Sd_ClientServiceSetStateType ClientServiceMode;
boolean SocketConnectionOpened;
uint32 TTL_Timer_Value_ms;
boolean TTL_Timer_Running;
sint32 FindDelay_Timer_Value_ms;
sint32 FindRepDelay_Timer_Value_ms;
Sd_DynConsumedEventGroupType *ConsumedEventGroups;
boolean OfferActive;
boolean FindDelayTimerOn;
boolean FindRepDelayTimerOn;
uint32 RepetitionFactor; /* Factor for interval between FindService calls in Rep Phase */
uint32 FindRepetitions; /* Counter for Repetition Phase */
boolean TcpSoConOpened;
boolean UdpSoConOpened;
Ipv4Endpoint UdpEndpoint;
Ipv4Endpoint TcpEndpoint;
uint16 UnicastSessionID;
} Sd_DynClientServiceType;
#define MAX_NO_OF_SUBSCRIBERS 15 /* TBD */
/* Sd_SubscriberType */
typedef struct {
boolean TTL_Timer_On;
uint32 TTL_Timer_Value_ms;
}Sd_SubscriberType;
/* Sd_DynEventHandlerType */
typedef struct {
Sd_EventHandlerCurrentStateType EventHandlerState;
uint16 NoOfSubscribers;
Sd_SubscriberType FanOut[MAX_NO_OF_SUBSCRIBERS];
Ipv4Endpoint UdpEndpoint;
Ipv4Endpoint TcpEndpoint;
}Sd_DynEventHandlerType;
/* Sd_DynServerServiceType */
typedef struct {
const Sd_ServerServiceType *ServerServiceCfg; /* static config */
Sd_PhaseType Phase;
Sd_ServerServiceSetStateType ServerServiceMode;
boolean SocketConnectionOpened;
sint32 InitialOffer_Timer_Value_ms;
sint32 OfferRepDelay_Timer_Value_ms;
sint32 OfferCyclicDelay_Timer_Value_ms;
boolean InitialOfferTimerOn;
boolean OfferRepDelayTimerOn;
boolean OfferCyclicDelayTimerOn;
uint32 RepetitionFactor; /* Factor for interval between OfferService calls in Repetition Phase */
uint32 OfferRepetitions; /* Counter for Repetition Phase */
Sd_DynEventHandlerType *EventHandlers;
boolean TcpSoConOpened;
boolean UdpSoConOpened;
uint16 UnicastSessionID;
} Sd_DynServerServiceType;
/* Sd_DynInstanceType */
typedef struct {
const Sd_InstanceType* InstanceCfg; /* static config */
Sd_DynClientServiceType* SdClientService;
Sd_DynServerServiceType* SdServerService;
boolean TxPduIpAddressAssigned;
boolean SdInitCalled;
SoAd_SoConIdType TxSoCon;
SoAd_SoConIdType MulticastRxSoCon;
SoAd_SoConIdType UnicastRxSoCon;
uint16 MulticastSessionID;
}Sd_DynInstanceType;
typedef struct{
Sd_DynInstanceType *Instance;
}Sd_DynConfigType;
typedef enum {
SD_UNINITIALIZED,
SD_INITIALIZED
} Sd_ModuleStateType;
/* -----------------------------------------------------------------------*/
/* Message format types */
/** @req SWS_SD_0033 */
#define CLIENT_ID 0x0000
/** @req SWS_SD_0141 */
#define PROTOCOL_VERSION 0x01
/** @req SWS_SD_0143 */
#define INTERFACE_VERSION 0x01
/** @req SWS_SD_0145 */
#define MESSAGE_TYPE 0x02
/** @req SWS_SD_0147 */
#define RETURN_CODE 0x00
/** @req SWS_SD_0160 */
#define ENTRY_TYPE_1_SIZE 16
/** @req SWS_SD_0183 */
#define ENTRY_TYPE_2_SIZE 16
#define TTL_TIMER_MAX 0xFFFFFFu
#define MAX_OPTIONS 15u
typedef struct{
uint32 RequestID;
uint8 ProtocolVersion; /* = 0x01 */
uint8 InterfaceVersion; /* = 0x01; */
uint8 MessageType; /* = 0x02; */
uint8 ReturnCode; /* = 0x00; */
uint8 Flags; /* Only the MSB 8 bits is used, rest should be set to zero */
uint32 Reserved; /* 24 bits = 0 */
uint32 LengthOfEntriesArray; /* Length in bytes */
uint8 *EntriesArray;
uint32 LengthOfOptionsArray; /* Length in bytes */
uint8 *OptionsArray;
}Sd_Message;
typedef enum {
SD_FIND_SERVICE,
SD_OFFER_SERVICE,
SD_STOP_OFFER_SERVICE,
SD_SUBSCRIBE_EVENTGROUP,
SD_STOP_SUBSCRIBE_EVENTGROUP,
SD_SUBSCRIBE_EVENTGROUP_ACK,
SD_SUBSCRIBE_EVENTGROUP_NACK
}Sd_EntryType;
#define FIND_SERVICE_TYPE 0x00
#define OFFER_SERVICE_TYPE 0x01
#define STOP_OFFER_SERVICE_TYPE 0x01
#define SUBSCRIBE_EVENTGROUP_TYPE 0x06
#define STOP_SUBSCRIBE_EVENTGROUP_TYPE 0x06
#define SUBSCRIBE_EVENTGROUP_ACK_TYPE 0x07
#define SUBSCRIBE_EVENTGROUP_NACK_TYPE 0x07
typedef struct {
uint8 Type;
uint8 IndexFirstOptionRun;
uint8 IndexSecondOptionRun;
uint8 NumberOfOption1;
uint8 NumberOfOption2;
uint16 ServiceID;
uint16 InstanceID;
uint8 MajorVersion;
uint32 TTL; /* Only 24 bits used */
uint32 MinorVersion;
}Sd_Entry_Type1_Services;
typedef struct {
uint8 Type;
uint8 IndexFirstOptionRun;
uint8 IndexSecondOptionRun;
uint8 NumberOfOption1; /* Only 4 bits used */
uint8 NumberOfOption2; /* Only 4 bits used */
uint16 ServiceID;
uint16 InstanceID;
uint8 MajorVersion;
uint32 TTL; /* Only 24 bits used */
uint8 Counter;
uint16 EventgroupID;
}Sd_Entry_Type2_EventGroups;
/* -------------------------Sd_Client/ServerServices--------------------*/
void UpdateClientService(const Sd_ConfigType *cfgPtr, uint32 instanceno, uint32 clientno);
void UpdateServerService(const Sd_ConfigType *cfgPtr, uint32 instanceno, uint32 serverno);
/* Currently implemented in ClientService module. IMPROVEMENT: Where is the best place?*/
uint32 RandomDelay(uint32 min, uint32 max); //lint !e526
/* -------------------------Sd_Send_Receiver-----------------------------------*/
/* Index for the different queues*/
#define CLIENT_QUEUE 0u
#define SERVER_QUEUE 1u
#define DELAYRESP_QUEUE 2u
void TransmitSdMessage(Sd_DynInstanceType *instance, Sd_DynClientServiceType *client, Sd_DynServerServiceType *server, Sd_Entry_Type2_EventGroups *subscribe_entry, uint8 event_group_index, Sd_EntryType entry_type, TcpIp_SockAddrType *ipaddress, boolean is_rxmulticast); //lint !e526
boolean ReceiveSdMessage(Sd_Message *msg, TcpIp_SockAddrType *ipaddress, uint8 queue, Sd_InstanceType **server_svc, boolean *is_multicast);
void InitMessagePool(void);
void Handle_RxIndication( PduIdType RxPduId, const PduInfoType* PduInfoPtr);
void FreeSdMessage(uint8 queue);
void Handle_PendingRespMessages(void);
/* -------------------------Sd_Entries-----------------------------------*/
void BuildServiceEntry(Sd_EntryType entry_type, const Sd_DynClientServiceType *client, const Sd_DynServerServiceType *server, uint8 *entry_array, uint8 no_of_options);
void BuildEventGroupsEntry(Sd_EntryType entry_type, const Sd_DynClientServiceType *client, const Sd_Entry_Type2_EventGroups *subscribe_entry, uint8 event_group_index, uint8 *entry_array, uint8 no_of_options);
void OptionsReceived (uint8 *options_array, uint32 length, Sd_Entry_Type1_Services *entry1, Sd_Entry_Type2_EventGroups *entry2, uint8 **options1, uint8 **options2); /*lint !e526 */
void BuildOptionsArray(Sd_EntryType entry_type, const Sd_DynClientServiceType *client, const Sd_DynServerServiceType *server, uint8 event_index, uint8 *options_array, uint32 *options_length, uint8 *no_of_options,const char* hostName);
/* -------------------------Sd_Messages-----------------------------------*/
void FillMessage(Sd_Message msg, uint8* message, uint32 *length);
void FillType1Entry(Sd_Entry_Type1_Services entry, uint8 *entry_array);
void FillType2Entry(Sd_Entry_Type2_EventGroups entry, uint8* entry_array);
void DecodeType1Entry(uint8 *entries_array, Sd_Entry_Type1_Services *entry); //lint !e526
void DecodeType2Entry(uint8 *entries_array, Sd_Entry_Type2_EventGroups *entry); //lint !e526
void DecodeMessage(Sd_Message *msg, uint8* message, uint32 length);
void DecodeOptionIpv4Endpoint (uint8 *options[], Ipv4Endpoint endpoint[], uint8 *no_of_endpoints);
void DecodeOptionIpv4Multicast (uint8 *options[], Ipv4Multicast multicast[], uint8 *no_of_multicasts);
void DecodeOptionConfiguration (uint8 *options[], Sd_CapabilityRecordType capabilty_record[], uint8 *no_of_capabilty_records );
uint32 htonl(uint32 lValue1);
uint16 htonl16(uint16 lValue1);
#endif /* SD_INTERNAL_H_ */
|
2301_81045437/classic-platform
|
communication/SD/src/SD_Internal.h
|
C
|
unknown
| 10,395
|
/*-------------------------------- Arctic Core ------------------------------
* Copyright (C) 2013, ArcCore AB, Sweden, www.arccore.com.
* Contact: <contact@arccore.com>
*
* You may ONLY use this file:
* 1)if you have a valid commercial ArcCore license and then in accordance with
* the terms contained in the written license agreement between you and ArcCore,
* or alternatively
* 2)if you follow the terms found in GNU General Public License version 2 as
* published by the Free Software Foundation and appearing in the file
* LICENSE.GPL included in the packaging of this file or here
* <http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt>
*-------------------------------- Arctic Core -----------------------------*/
/** @reqSettings DEFAULT_SPECIFICATION_REVISION=4.2.2 */
#include "string.h"
#include "SD.h"
#include "SD_Internal.h"
#include "stdlib.h"
#define SD_LITTLE_ENDIAN TRUE /* IMPROVEMENT: Can this be fetched somewhere, or made configurable? */
#define CONFIG_TYPE 0x01
#define IPV4ENDPOINT_TYPE 0x04
#define IPV4MULTICAST_TYPE 0x14
char keypair_pool[500]; /* IMPROVEMENT use dynamic allocation for keys and pairs when it can be freed after use
or create exact sum length from generator */
/* calculates a random max delay time for Initial Wait phase */
uint32 RandomDelay(uint32 min_ms, uint32 max_ms)
{
uint32 r;
r = min_ms + rand() / ( RAND_MAX / (max_ms-min_ms+1) +1);
return r;
}
/* Convert to network byte order */
/** @req 4.2.2/SWS_SD_00037 */
uint32 htonl(uint32 lValue1) {
uint32 lValue2 = 0;
if (SD_LITTLE_ENDIAN){
lValue2 |= (lValue1 & 0xFF000000) >> 24;
lValue2 |= (lValue1 & 0x00FF0000) >> 8;
lValue2 |= (lValue1 & 0x0000FF00) << 8;
lValue2 |= (lValue1 & 0x000000FF) << 24;
}
else
{
lValue2 = lValue1;
}
return (lValue2);
}
/* Convert to network byte order */
uint16 htonl16(uint16 lValue1) {
uint16 lValue2 = 0;
if (SD_LITTLE_ENDIAN){
lValue2 |= (lValue1 & 0xFF00) >> 8;
lValue2 |= (lValue1 & 0x00FF) << 8;
}
else
{
lValue2 = lValue1;
}
return (lValue2);
}
/* Fills the uint8 array with data from the Sd_Message
* according to message format in chapter 7.3 of SD spec.
*
*/
/** @req 4.2.2/SWS_SD_00030 **/
/** @req 4.2.2/SWS_SD_00031 **/
/** @req 4.2.2/SWS_SD_00032 **/
/** @req 4.2.2/SWS_SD_00158 **/
void FillMessage(Sd_Message msg, uint8* message, uint32 *length)
{
/* Header information incl. Entries array length*/
uint32 offset = 0;
uint32 row = 0;
row = htonl(msg.RequestID);
memcpy(&message[offset], &row, 4);
offset += 4;
/** @req 4.2.2/SWS_SD_00140 **/
message[offset] = msg.ProtocolVersion;
/** @req 4.2.2/SWS_SD_00142 **/
message[offset + 1] = msg.InterfaceVersion;
/** @req 4.2.2/SWS_SD_00144 **/
message[offset + 2] = msg.MessageType;
/** @req 4.2.2/SWS_SD_00146 **/
message[offset + 3] = msg.ReturnCode;
offset += 4;
/** @req 4.2.2/SWS_SD_00149 **/
/** @req 4.2.2/SWS_SD_00155 **/
row = (uint32) ((msg.Flags << 24) | msg.Reserved);
row = htonl(row);
memcpy(&message[offset], &row, 4);
/** @req 4.2.2/SWS_SD_00157 **/
offset += 4;
row = htonl(msg.LengthOfEntriesArray);
memcpy(&message[offset], &row, 4);
/* Entries Array */
offset += 4;
memcpy(&message[offset], msg.EntriesArray, msg.LengthOfEntriesArray);
/* Options array length */
offset += msg.LengthOfEntriesArray;
row = htonl(msg.LengthOfOptionsArray);
memcpy(&message[offset], &row, 4);
/* Options array */
offset += 4;
memcpy(&message[offset], msg.OptionsArray, msg.LengthOfOptionsArray);
*length = offset + msg.LengthOfOptionsArray;
}
/* Fills the uint8 array with data from the Sd_Type1Entry
* according to message format in chapter 7.3 of SD spec.
*
*/
/** @req 4.2.2/SWS_SD_00161 */
/** @req 4.2.2/SWS_SD_00159 **/
void FillType1Entry(Sd_Entry_Type1_Services entry, uint8 *entry_array){
uint32 row = 0;
uint16 value = 0;
/** @req 4.2.2/SWS_SD_0163 */
/** @req 4.2.2/SWS_SD_0165 */
/** @req 4.2.2/SWS_SD_0167 */
/** @req 4.2.2/SWS_SD_0169 */
entry_array[0] = entry.Type;
entry_array[1] = entry.IndexFirstOptionRun;
entry_array[2] = entry.IndexSecondOptionRun;
entry_array[3] = (((entry.NumberOfOption1 << 4) & 0xF0) | (entry.NumberOfOption2 & 0x0F));
/** @req 4.2.2/SWS_SD_0172 */
value = htonl16(entry.ServiceID);
memcpy(&entry_array[4], &value, 2);
/** @req 4.2.2/SWS_SD_0174 */
value = htonl16(entry.InstanceID);
memcpy(&entry_array[6], &value, 2);
/** @req 4.2.2/SWS_SD_0177 */
/** @req 4.2.2/SWS_SD_0179 */
row = htonl(entry.TTL);
memcpy (&entry_array[8], &row, 4);
entry_array[8] = entry.MajorVersion;
/** @req 4.2.2/SWS_SD_0181 */
row = htonl(entry.MinorVersion);
memcpy (&entry_array[12], &row, 4);
}
/* Fills the uint8 array with data from the Sd_Type2Entry
* according to message format in chapter 7.3 of SD spec.
*
*/
/** @req 4.2.2/SWS_SD_0184 */
void FillType2Entry(Sd_Entry_Type2_EventGroups entry, uint8 *entry_array){
uint32 row = 0;
uint16 value = 0;
/** @req 4.2.2/SWS_SD_0163 */
/** @req 4.2.2/SWS_SD_0165 */
/** @req 4.2.2/SWS_SD_0167 */
/** @req 4.2.2/SWS_SD_0169 */
entry_array[0] = entry.Type;
/** @req 4.2.2/SWS_SD_0185 **/
entry_array[1] = entry.IndexFirstOptionRun;
/** @req 4.2.2/SWS_SD_0186 **/
entry_array[2] = entry.IndexSecondOptionRun;
/** @req 4.2.2/SWS_SD_0387 **/
/** @req 4.2.2/SWS_SD_0189 **/
entry_array[3] = (((entry.NumberOfOption1 << 4) & 0xF0) | (entry.NumberOfOption2 & 0x0F));
/** @req 4.2.2/SWS_SD_0192 **/
value = htonl16(entry.ServiceID);
memcpy(&entry_array[4], &value, 2);
/** @req 4.2.2/SWS_SD_0194 **/
value = htonl16(entry.InstanceID);
memcpy(&entry_array[6], &value, 2);
/** @req 4.2.2/SWS_SD_0199 **/
row = htonl(entry.TTL);
memcpy (&entry_array[8], &row, 4);
/** @req 4.2.2/SWS_SD_0197 **/
entry_array[8] = entry.MajorVersion;
/** @req 4.2.2/SWS_SD_0201 **/
/** @req 4.2.2/SWS_SD_0202 **/
/** @req 4.2.2/SWS_SD_0300 */
/** @req 4.2.2/SWS_SD_0156 */
row = (uint32)0; /* Assure reserved field is all 0 */
/** @req 4.2.2/SWS_SD_0203 **/
/** @req 4.2.2/SWS_SD_0691 **/
row = (uint32) (((entry.Counter & 0x0F) << 16) | (entry.EventgroupID));
row = htonl(row);
memcpy (&entry_array[12], &row, 4);
}
void DecodeType1Entry(uint8 *entries_array, Sd_Entry_Type1_Services *entry)
{
uint32 row;
entry->Type = entries_array[0];
entry->IndexFirstOptionRun = entries_array[1];
entry->IndexSecondOptionRun = entries_array[2];
entry->NumberOfOption1 = (uint8) ((entries_array[3] & 0xF0) >> 4);
entry->NumberOfOption2 = (uint8) (entries_array[3] & 0xF);
entry->ServiceID = entries_array[4] * 256 + entries_array[5];
entry->InstanceID = entries_array[6] * 256 + entries_array[7];
entry->MajorVersion = entries_array[8];
memcpy(&row, &entries_array[8], 4);
row = htonl(row);
entry->TTL = (uint32) (row & 0x00FFFFFF);
memcpy(&row, &entries_array[12], 4);
entry->MinorVersion = htonl(row);
}
void DecodeType2Entry(uint8 *entries_array, Sd_Entry_Type2_EventGroups *entry)
{
uint32 row;
entry->Type = entries_array[0];
entry->IndexFirstOptionRun = entries_array[1];
entry->IndexSecondOptionRun = entries_array[2];
entry->NumberOfOption1 = (uint8) ((entries_array[3] & 0xF0) >> 4);
entry->NumberOfOption2 = (uint8) (entries_array[3] & 0xF);
entry->ServiceID = entries_array[4] * 256 + entries_array[5];
entry->InstanceID = entries_array[6] * 256 + entries_array[7];
entry->MajorVersion = entries_array[8];
memcpy(&row, &entries_array[8], 4);
row = htonl(row);
entry->TTL = (uint32) (row & 0x00FFFFFF);
memcpy(&row, &entries_array[12], 4);
row = htonl(row);
entry->Counter = (uint8) ((row &0x000F0000) >> 16);
entry->EventgroupID = (uint16) (row & 0x0000FFFF);
}
/** @req 4.2.2/SWS_SD_0479 **/
void DecodeMessage(Sd_Message *msg, uint8* message, uint32 length)
{
uint32 offset = 0;
uint32 row = 0;
memcpy (&row, &message[offset], 4);
msg->RequestID = htonl(row);
offset += 4;
msg->ProtocolVersion = message[offset];
msg->InterfaceVersion = message[offset + 1];
msg->MessageType = message[offset + 2];
msg->ReturnCode = message[offset + 3];
offset += 4;
memcpy (&row, &message[offset], 4);
row = htonl(row);
msg->Flags = (row & 0xFF000000) >> 24;
msg->Reserved = (row & 0x00FFFFFF);
offset += 4;
memcpy (&row, &message[offset], 4);
msg->LengthOfEntriesArray = htonl(row);
offset += 4;
msg->EntriesArray = (uint8 *)&message[offset];
const uint32 OptionsArrayOffset = (msg->LengthOfEntriesArray + 16);
if (length > OptionsArrayOffset){
memcpy (&row, &message[OptionsArrayOffset], 4);
msg->LengthOfOptionsArray = htonl(row);
if (msg->LengthOfOptionsArray > 0) {
msg->OptionsArray = (uint8 *)&message[OptionsArrayOffset + 4];
}
else {
msg->OptionsArray = NULL;
}
}
else
{
msg->LengthOfOptionsArray = 0;
msg->OptionsArray = NULL;
}
}
void DecodeOptionConfiguration (uint8 *options[], Sd_CapabilityRecordType capabilty_record[], uint8 *no_of_capabilty_records )
{
uint8 index = 0;
uint8 len = 0;
uint8 offset = 4u;
uint8 separator_pos = 0;
uint8 i;
uint8 pool_index = 0;
for (uint8 opt=0;opt<MAX_OPTIONS;opt++){
if (options[opt] != NULL){
uint8 type = options[opt][2];
if (type == CONFIG_TYPE){
for(;options[opt][offset] != 0x00;){
len = options[opt][offset];
offset = offset+1;
separator_pos = len;
for (i = 0; i < len; i++){
if( options[opt][offset+i] == '='){
separator_pos = i;
break;
}
}
capabilty_record[index].Key = &keypair_pool[pool_index];
pool_index += separator_pos+1;
memcpy(capabilty_record[index].Key, &options[opt][offset], separator_pos);
capabilty_record[index].Key[separator_pos] = '\0';
if((separator_pos != len) || ((len-separator_pos) != 1)){/* separator may not be there or value may not be there */
capabilty_record[index].Value = &keypair_pool[pool_index];
pool_index += len-separator_pos;
memcpy(capabilty_record[index].Value, &options[opt][offset+separator_pos+1], len-separator_pos-1);
capabilty_record[index].Value[len-separator_pos-1] = '\0';
}
index++;
if(options[opt][len+offset] == 0x00){
break;
}
offset += len;
len = 0;
}
}
}
}
*no_of_capabilty_records = index;
}
void DecodeOptionIpv4Endpoint (uint8 *options[], Ipv4Endpoint endpoint[], uint8 *no_of_endpoints)
{
uint8 index = 0;
uint32 row = 0;
uint16 value = 0;
for (uint8 opt=0;opt<MAX_OPTIONS;opt++){
if (options[opt] != NULL){
uint8 type = options[opt][2];
if (type == IPV4ENDPOINT_TYPE){
memcpy(&row, &options[opt][4], 4);
row = htonl(row);
endpoint[index].IPv4Address = row;
endpoint[index].Protocol = options[opt] [9];
memcpy(&value, &options[opt][10], 2);
value = htonl16(value);
endpoint[index].PortNumber = value;
index++;
}
}
}
*no_of_endpoints = index;
}
void DecodeOptionIpv4Multicast (uint8 *options[], Ipv4Multicast multicast[], uint8 *no_of_multicasts)
{
uint8 index = 0;
uint32 row = 0;
uint16 value = 0;
for (uint8 opt=0;opt<MAX_OPTIONS;opt++){
if (options[opt] != NULL){
uint8 type = options[opt][2];
if (type == IPV4MULTICAST_TYPE){
memcpy(&row, &options[opt][4], 4);
row = htonl(row);
multicast[index].IPv4Address = row;
multicast[index].Protocol = options[opt] [9];
memcpy(&value, &options[opt][10], 2);
value = htonl16(value);
multicast[index].PortNumber = value;
index++;
}
}
}
*no_of_multicasts = index;
}
|
2301_81045437/classic-platform
|
communication/SD/src/SD_Messages.c
|
C
|
unknown
| 13,273
|
/*-------------------------------- Arctic Core ------------------------------
* Copyright (C) 2013, ArcCore AB, Sweden, www.arccore.com.
* Contact: <contact@arccore.com>
*
* You may ONLY use this file:
* 1)if you have a valid commercial ArcCore license and then in accordance with
* the terms contained in the written license agreement between you and ArcCore,
* or alternatively
* 2)if you follow the terms found in GNU General Public License version 2 as
* published by the Free Software Foundation and appearing in the file
* LICENSE.GPL included in the packaging of this file or here
* <http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt>
*-------------------------------- Arctic Core -----------------------------*/
#include "SD.h"
#include "SD_Internal.h"
#include "SoAd.h"
#include "string.h"
#include "cirq_buffer.h"
#include "SchM_SD.h"
#define timerDec(timer) \
if (timer > 0) { \
timer = timer - 1; \
} \
/*lint -e793 Ignore over 31 significant characters in SoAd.h */
extern const Sd_ConfigType *SdCfgPtr; /*lint -e526 */
typedef struct {
TcpIp_SockAddrType ipaddress;
PduInfoType *msg;
Sd_InstanceType *svcInstance;
boolean multicast;
} MsgType;
typedef struct {
Sd_DynInstanceType *sd_instance;
Sd_DynClientServiceType *client;
Sd_DynServerServiceType *server;
Sd_Entry_Type2_EventGroups *subscribe_entry;
TcpIp_SockAddrType *address;
Sd_EntryType entry_type;
uint8 event_index;
uint32 wait_delay_cntr;
} DelayedRespType;
static const TcpIp_SockAddrType wildcard = {
(TcpIp_DomainType) TCPIP_AF_INET,
TCPIP_PORT_ANY,
{TCPIP_IPADDR_ANY, TCPIP_IPADDR_ANY, TCPIP_IPADDR_ANY, TCPIP_IPADDR_ANY }
};
/* -----------------Receive queue (client/server) --------------- */
#define NO_OF_TOTAL_QUEUES 3u /* Client and Server queues + delay response queue */
#define NO_OF_MSG_QUEUES 2u /* Client and Server queues */
#define RECEIVE_MAX 50u /* IMPROVEMENT: Make this configurable */
#define PAYLOAD_MAX 1000 /* IMPROVEMENT: Determine maximum length of an SD_Message, make this configurable */
#define POOL_MAX (RECEIVE_MAX * NO_OF_MSG_QUEUES)
static uint8 message [PAYLOAD_MAX]; /* TBD: Calculate Max length */
static uint8 options[500]; /* TBD: Calculate Max length */
/* Memory pool for MsgType */
static const TcpIp_SockAddrType Empty_TcpIp_SockAddrType = { 0,0,{0,0,0,0}};
static MsgType Message_Pool[POOL_MAX];
static PduInfoType PduInfo_Pool[POOL_MAX];
static uint8 Payload_Pool[POOL_MAX][PAYLOAD_MAX];
static DelayedRespType DelayedResp_Pool[RECEIVE_MAX];
static CirqBufferType cirqBuf[NO_OF_TOTAL_QUEUES];
static MsgType *fetched_message;
static void * rec_insert(uint8 queue)
{
// Sanity check of queue parameter
if (queue > (NO_OF_TOTAL_QUEUES-1)){
return NULL; // quit with an error
}
void *buffer;
buffer = CirqBuff_PushLock(&cirqBuf[queue]);
if(buffer != NULL){
CirqBuff_PushRelease(&cirqBuf[queue]);
}
return buffer;
}
static void * rec_fetch(uint8 queue)
{
// Sanity check of queue parameter
if (queue > (NO_OF_TOTAL_QUEUES-1)){
return NULL; // quit with an error
}
return CirqBuff_Peek(&cirqBuf[queue],0);
}
void FreeSdMessage(uint8 queue)
{
// Sanity check of queue parameter
if (queue > (NO_OF_TOTAL_QUEUES-1)){
return; // quit with an error
}
uint8 *buffer;
buffer = CirqBuff_PopLock(&cirqBuf[queue]);
if(buffer != NULL){
CirqBuff_PopRelease(&cirqBuf[queue]);
}
}
/* Use it for future to service all messages for one client/server and service combination */
static uint32 GetNumofQueueSdMessages(uint8 queue){
return (uint32)CirqBuff_Size(&cirqBuf[queue]);
}
/* Service pending delayed transmit messages upon timeout
* Reduce the timer value by 1 , called from SD main function
*/
void Handle_PendingRespMessages(void)
{
uint32 sdBufferedMsgs = GetNumofQueueSdMessages(DELAYRESP_QUEUE);
for (uint32 i = 0; i < sdBufferedMsgs; i++){
/* Fetch next item in queue */
DelayedRespType *respMsg = (DelayedRespType*)rec_fetch(DELAYRESP_QUEUE);
if(respMsg != NULL){
timerDec(respMsg->wait_delay_cntr);
if(respMsg->wait_delay_cntr == 0u){
FreeSdMessage(DELAYRESP_QUEUE);
TransmitSdMessage(respMsg->sd_instance, \
respMsg->client,respMsg->server,respMsg->subscribe_entry, \
respMsg->event_index,respMsg->entry_type,respMsg->address, FALSE); /* last parameter should be FALSE */
}
}
}
}
void InitMessagePool()
{
for (uint32 i=0; i<POOL_MAX;i++){
for (uint32 j=0; j<PAYLOAD_MAX; j++){
Payload_Pool[i][j] = 0;
}
PduInfo_Pool[i].SduLength = 0;
PduInfo_Pool[i].SduDataPtr = Payload_Pool[i];
Message_Pool[i].ipaddress = Empty_TcpIp_SockAddrType;
Message_Pool[i].msg = &PduInfo_Pool[i];
}
/* Initialize circular buffers */
CirqBuff_Init(&cirqBuf[CLIENT_QUEUE], &Message_Pool[0], RECEIVE_MAX, sizeof(MsgType));
CirqBuff_Init(&cirqBuf[SERVER_QUEUE], &Message_Pool[RECEIVE_MAX], RECEIVE_MAX, sizeof(MsgType));
CirqBuff_Init(&cirqBuf[DELAYRESP_QUEUE], &DelayedResp_Pool[0], RECEIVE_MAX, sizeof(DelayedRespType));
}
void Handle_RxIndication(PduIdType RxPduId, const PduInfoType* PduInfoPtr) {
#define ENTRY_TYPE_INDEX 16u
Sd_InstanceType *svcInstance = NULL;
boolean is_multicast = FALSE;
/** @req 4.2.2/SWS_SD_00482 */
/* Determine service instance. */
for (uint16 i = 0; i <= SD_NUMBER_OF_INSTANCES; i++) {
if (SdCfgPtr != NULL) {
if (SdCfgPtr->Instance[i].MulticastRxPduId == RxPduId) {
is_multicast = TRUE;
svcInstance = (Sd_InstanceType *) &SdCfgPtr->Instance[i];
break;
} else if (SdCfgPtr->Instance[i].UnicastRxPduId == RxPduId) {
is_multicast = FALSE;
svcInstance = (Sd_InstanceType *) &SdCfgPtr->Instance[i];
break;
}
}
}
if (svcInstance == NULL) {
/* No matching service - IMPROVEMENT: Add error handling */
return;
}
/* Peek the type of message */
/* IMPROVEMENT: Currently only supports one entry per message */
uint8 entry_type = PduInfoPtr->SduDataPtr[ENTRY_TYPE_INDEX];
uint8 queue = CLIENT_QUEUE;
if ((entry_type == FIND_SERVICE_TYPE)
|| (entry_type == SUBSCRIBE_EVENTGROUP_TYPE)) {
queue = SERVER_QUEUE;
} else if (entry_type == OFFER_SERVICE_TYPE)
/* || (entry_type == SUBSCRIBE_EVENTGROUP_ACK_TYPE)*/
{
queue = CLIENT_QUEUE;
} else if /*(entry_type == OFFER_SERVICE_TYPE)
|| */ (entry_type == SUBSCRIBE_EVENTGROUP_ACK_TYPE) {
queue = CLIENT_QUEUE;
}
/* save Message and address */
SchM_Enter_SD_EA_0();
MsgType *received_message = (MsgType *)rec_insert(queue);
if (received_message == NULL) {
/* Message Pool empty or Error - IMPROVEMENT: Add error handling */
SchM_Exit_SD_EA_0();
return;
}
received_message->ipaddress = wildcard; // Set at higher level.
received_message->msg->SduLength = PduInfoPtr->SduLength;
received_message->multicast = is_multicast;
received_message->svcInstance = svcInstance;
memcpy(received_message->msg->SduDataPtr, PduInfoPtr->SduDataPtr,
PduInfoPtr->SduLength);
SchM_Exit_SD_EA_0();
/** @req 4.2.2/SWS_SD_00708 */
/* IMPROVEMENT: Check consistency */
}
/* Fetch the next received SD message from the queue
* If the queue is empty FALSE is returned.
* otherwise 0 is returned, and the Sd_Message is found in the msg parameter.
*/
boolean ReceiveSdMessage(Sd_Message *msg, TcpIp_SockAddrType *ipaddress, uint8 queue, Sd_InstanceType **server_svc, boolean *is_multicast)
{
/* Fetch next item in queue */
fetched_message = rec_fetch(queue);
/* Error */
if (fetched_message == NULL) {
return FALSE;
}
else {
*ipaddress = fetched_message->ipaddress;
*server_svc = fetched_message->svcInstance;
*is_multicast = fetched_message->multicast;
DecodeMessage(msg, fetched_message->msg->SduDataPtr, fetched_message->msg->SduLength);
}
return TRUE;
}
/* TransmitSdMessage assembles and transmits one SD message of any type, both client and server messages
* Parameters:
* instance - ref to the current instance
* client - ref to the current client service instance dynamic data structure
* server - ref to the current server service instance dynamic data structure
* subscribe_entry - Used for SD_SUBSCRIBE_EVENTGROUP_ACK/NACK messages. ref to subscribe entry to reply to.
* event_index - Used for SD_SUBSCRIBE_EVENTGROUP/STOP_SUBSCRIBE and SD_SUBSCRIBE_EVENTGROUP_ACK/NACK messages.
* Contains the index of the ConsumedEventGroup that should be subscribed (SUBSCRIBE) or
* the index of the EvvneHandler thit is subscribed (SUBSCRIBE_ACK)
* ipaddress - unicast address to set if applicable
* is_rxmulticast - parameter to identify if the reply message has to be delayed in case message
* is received from multicast address
*/
void TransmitSdMessage(Sd_DynInstanceType *instance,
Sd_DynClientServiceType *client,
Sd_DynServerServiceType *server,
Sd_Entry_Type2_EventGroups *subscribe_entry,
uint8 event_index,
Sd_EntryType entry_type,
TcpIp_SockAddrType *ipaddress,
boolean is_rxmulticast)
{
uint32 delay_ms = 0;
uint32 wait_delay_cntr = 0;
if(is_rxmulticast == TRUE){
/** @req 4.2.2/SWS_SD_00491 */
if(client != NULL){
delay_ms = RandomDelay(client->ClientServiceCfg->TimerRef->RequestResponseMinDelay_ms,client->ClientServiceCfg->TimerRef->RequestResponseMaxDelay_ms);
}else{ /* server */
delay_ms = RandomDelay(server->ServerServiceCfg->TimerRef->RequestResponseMinDelay_ms,server->ServerServiceCfg->TimerRef->RequestResponseMaxDelay_ms);
}
wait_delay_cntr = (delay_ms / SD_MAIN_FUNCTION_CYCLE_TIME_MS);
/** @req 4.2.2/SWS_SD_00494 */
if(wait_delay_cntr != 0){
SchM_Enter_SD_EA_0();
DelayedRespType *respMsg = (DelayedRespType*) rec_insert(DELAYRESP_QUEUE);
if (respMsg == NULL) {
/* IMPROVEMENT: DET ERROR - ticket pending*/
SchM_Exit_SD_EA_0();
return;
}
respMsg->sd_instance = instance;
respMsg->client = client;
respMsg->server = server;
respMsg->entry_type = entry_type;
respMsg->event_index = event_index;
respMsg->subscribe_entry = subscribe_entry;
respMsg->address = ipaddress;
respMsg->wait_delay_cntr = wait_delay_cntr;
SchM_Exit_SD_EA_0();
}
}
if(wait_delay_cntr == 0u){
/** @req 4.2.2/SWS_SD_00480 */
/* IMPROVEMENT: We need to check that parameters are OK, to avoid null pointer reference bugs.
* i.e. server parameters is not null and is used only for server entries etc.
* or maybe divide it for client and server messages. */
Sd_Message sd_msg;
uint8 entry_type1_array[ENTRY_TYPE_1_SIZE];
uint8 entry_type2_array[ENTRY_TYPE_2_SIZE];
boolean send_by_multicast = FALSE;
PduIdType pdu;
PduInfoType pduinfo;
uint32 messagelength;
uint32 optionslength = 0;
uint8 no_of_options = 0;
/* IMPROVEMENT: Handling of flags according to chapter 7.3.6. Reboot_Flag and Unicast_Flag is const until then. */
const uint8 Reboot_Flag = 1u; /* Default value after reboot */
const uint8 Unicast_Flag = 1u; /* Supports Unicast messages */
const uint8 Flags = 0u;
const uint8 NoOfEntries = 1; /* IMPROVEMENT:Change this later.*/
sd_msg.RequestID = (uint32) ((CLIENT_ID << 16)); /* SessionID is filled in later */ /*lint !e835 Want to use CLIENT_ID even though zero as left argument */
sd_msg.ProtocolVersion = (uint8) PROTOCOL_VERSION;
sd_msg.InterfaceVersion = (uint8) INTERFACE_VERSION;
sd_msg.MessageType = (uint8) MESSAGE_TYPE;
sd_msg.ReturnCode = (uint8) RETURN_CODE;
sd_msg.Flags = (uint8) (Flags | (Reboot_Flag << 7u) | (Unicast_Flag << 6u));
sd_msg.Reserved = 0u;
/* Create the options array */
sd_msg.LengthOfOptionsArray = 0;
sd_msg.OptionsArray = NULL;
BuildOptionsArray(entry_type, client, server, event_index, options, &optionslength, &no_of_options,instance->InstanceCfg->HostName);
if (optionslength > 0) {
sd_msg.OptionsArray = &options[0];
sd_msg.LengthOfOptionsArray = optionslength;
} else {
sd_msg.OptionsArray = NULL;
sd_msg.LengthOfOptionsArray = 0;
}
/* Create entries array */
/* NB: Currently only one entry per SD_Message is used.
* IMPROVEMENT: Handle packing of more than one entry in each message. */
switch (entry_type) {
case SD_OFFER_SERVICE: /** @req 4.2.2/SWS_SD_00478 */
case SD_FIND_SERVICE:
case SD_STOP_OFFER_SERVICE:
sd_msg.LengthOfEntriesArray = (uint32) ENTRY_TYPE_1_SIZE * NoOfEntries;
BuildServiceEntry(entry_type, client, server, entry_type1_array, no_of_options);
sd_msg.EntriesArray = entry_type1_array;
break;
case SD_SUBSCRIBE_EVENTGROUP:
case SD_STOP_SUBSCRIBE_EVENTGROUP:
case SD_SUBSCRIBE_EVENTGROUP_ACK:
case SD_SUBSCRIBE_EVENTGROUP_NACK:
sd_msg.LengthOfEntriesArray = (uint32) ENTRY_TYPE_2_SIZE * NoOfEntries;
BuildEventGroupsEntry(entry_type, client, subscribe_entry, event_index, entry_type2_array, no_of_options);
sd_msg.EntriesArray = entry_type2_array;
break;
default:
/* Error */
break;
}
if (client != NULL) {
/* set remote address for client call */
switch (entry_type) {
case SD_FIND_SERVICE:
send_by_multicast = TRUE;
break;
case SD_SUBSCRIBE_EVENTGROUP:
/** @req 4.2.2/SWS_SD_00702 */
if (client->ClientServiceCfg->ConsumedEventGroup[event_index].TcpActivationRef != ACTIVATION_REF_NOT_SET) {
(void)SoAd_EnableSpecificRouting (client->ClientServiceCfg->ConsumedEventGroup[event_index].TcpActivationRef,
client->ClientServiceCfg->TcpSocketConnectionGroupId);
}
/** @req 4.2.2/SWS_SD_00703 */
else if (client->ClientServiceCfg->ConsumedEventGroup[event_index].UdpActivationRef != ACTIVATION_REF_NOT_SET) {
(void)SoAd_EnableSpecificRouting (client->ClientServiceCfg->ConsumedEventGroup[event_index].UdpActivationRef,
client->ClientServiceCfg->UdpSocketConnectionGroupId);
}
send_by_multicast = FALSE;
if ((client->UdpEndpoint.valid != FALSE) || (client->TcpEndpoint.valid != FALSE)) {
/* Use Unicast. Set remote address to address retrieved in incoming option parameter, but use port number from SD multicast socket.
* ipaddress was set to the correct value when receiving OFFER_SERVICE. */
SoAd_SoConIdType tx_socket = instance->TxSoCon;
SoAd_SoConIdType rx_socket = instance->MulticastRxSoCon;
TcpIp_SockAddrType sd_remoteaddress;
sd_remoteaddress.domain = TCPIP_AF_INET;
(void)SoAd_GetRemoteAddr(rx_socket, &sd_remoteaddress);
ipaddress->port = sd_remoteaddress.port;
(void)SoAd_SetRemoteAddr(tx_socket, ipaddress);
/* Assign sessionID for this SD messsage */
sd_msg.RequestID |= client->UnicastSessionID;
/** @req 4.2.2/SWS_SD_00035 */
/** @req 4.2.2/SWS_SD_00036 */
if (client->UnicastSessionID == 0xFFFF){
client->UnicastSessionID = 1u;
}
else {
client->UnicastSessionID++;
}
}
break;
case SD_STOP_SUBSCRIBE_EVENTGROUP:
/** @req 4.2.2/SWS_SD_00701 */
/** @req 4.2.2/SWS_SD_00694 */
send_by_multicast = FALSE;
if ((client->UdpEndpoint.valid != FALSE) || (client->TcpEndpoint.valid != FALSE)) {
/* Use Unicast. Set remote address to address retreived in previous option to OFFER_SERVICE,
* but use port number from SD multicast socket. */
SoAd_SoConIdType tx_socket = instance->TxSoCon;
if (client->TcpEndpoint.valid != FALSE) {
ipaddress->addr[0] = ((client->TcpEndpoint.IPv4Address & 0xFF000000) >> 24);
ipaddress->addr[1] = ((client->TcpEndpoint.IPv4Address & 0x00FF0000) >> 16);
ipaddress->addr[2] = ((client->TcpEndpoint.IPv4Address & 0x0000FF00) >> 8);
ipaddress->addr[3] = (client->TcpEndpoint.IPv4Address & 0x000000FF);
ipaddress->domain = TCPIP_AF_INET;
} else if (client->UdpEndpoint.valid != FALSE) {
ipaddress->addr[0] = ((client->UdpEndpoint.IPv4Address & 0xFF000000) >> 24);
ipaddress->addr[1] = ((client->UdpEndpoint.IPv4Address & 0x00FF0000) >> 16);
ipaddress->addr[2] = ((client->UdpEndpoint.IPv4Address & 0x0000FF00) >> 8);
ipaddress->addr[3] = (client->UdpEndpoint.IPv4Address & 0x000000FF);
ipaddress->domain = TCPIP_AF_INET;
}
/* Fetch port number from SD RX_Multicast socket. */
SoAd_SoConIdType rx_socket = instance->MulticastRxSoCon;
TcpIp_SockAddrType sd_remoteaddress;
sd_remoteaddress.domain = TCPIP_AF_INET;
(void)SoAd_GetRemoteAddr(rx_socket, &sd_remoteaddress);
ipaddress->port = sd_remoteaddress.port;
(void)SoAd_SetRemoteAddr(tx_socket, ipaddress);
/* Assign sessionID for this SD messsage */
sd_msg.RequestID |= client->UnicastSessionID;
/** @req 4.2.2/SWS_SD_00035 */
/** @req 4.2.2/SWS_SD_00036 */
if (client->UnicastSessionID == 0xFFFF){
client->UnicastSessionID = 1u;
}
else {
client->UnicastSessionID++;
}
}
break;
default:
/* Should not occur */
break;
}
}
if (server != NULL) {
/* set remote address for server call */
switch (entry_type) {
case SD_OFFER_SERVICE:
case SD_STOP_OFFER_SERVICE:
send_by_multicast = TRUE;
break;
case SD_SUBSCRIBE_EVENTGROUP_ACK:
case SD_SUBSCRIBE_EVENTGROUP_NACK:
send_by_multicast = FALSE;
/* Set remote address to address retrieved in incoming option parameter.
* ipaddress was not set in this case.
* If no option parameter, use ipaddress as inparameter */
if (server->EventHandlers[event_index].UdpEndpoint.valid != FALSE) {
ipaddress->addr[0] = ((server->EventHandlers[event_index].UdpEndpoint.IPv4Address & 0xFF000000) >> 24);
ipaddress->addr[1] = ((server->EventHandlers[event_index].UdpEndpoint.IPv4Address & 0x00FF0000) >> 16);
ipaddress->addr[2] = ((server->EventHandlers[event_index].UdpEndpoint.IPv4Address & 0x0000FF00) >> 8);
ipaddress->addr[3] = (server->EventHandlers[event_index].UdpEndpoint.IPv4Address & 0x000000FF);
ipaddress->domain = TCPIP_AF_INET;
ipaddress->port = server->EventHandlers[event_index].UdpEndpoint.PortNumber;
} else if (server->EventHandlers[event_index].TcpEndpoint.valid != FALSE) {
ipaddress->addr[0] = ((server->EventHandlers[event_index].TcpEndpoint.IPv4Address & 0xFF000000) >> 24);
ipaddress->addr[1] = ((server->EventHandlers[event_index].TcpEndpoint.IPv4Address & 0x00FF0000) >> 16);
ipaddress->addr[2] = ((server->EventHandlers[event_index].TcpEndpoint.IPv4Address & 0x0000FF00) >> 8);
ipaddress->addr[3] = (server->EventHandlers[event_index].TcpEndpoint.IPv4Address & 0x000000FF);
ipaddress->domain = TCPIP_AF_INET;
ipaddress->port = server->EventHandlers[event_index].TcpEndpoint.PortNumber;
}
/* Use Unicast. Set the remote address before sending */
if (ipaddress != NULL) {
SoAd_SoConIdType tx_socket = instance->TxSoCon;
(void)SoAd_SetRemoteAddr(tx_socket, ipaddress);
/* Assign sessionID for this SD messsage */
sd_msg.RequestID |= server->UnicastSessionID;
/** @req 4.2.2/SWS_SD_00035 */
/** @req 4.2.2/SWS_SD_00036 */
if (server->UnicastSessionID == 0xFFFF){
server->UnicastSessionID = 1u;
}
else {
server->UnicastSessionID++;
}
}
break;
default:
/* Should not occur */
break;
}
}
if (send_by_multicast) {
/* Use Multicast. Retreive multicast address from Multicast RxPdu. */
SoAd_SoConIdType multicast_rx_socket = instance->MulticastRxSoCon;
SoAd_SoConIdType tx_socket = instance->TxSoCon;
TcpIp_SockAddrType destination;
uint8 netmask;
TcpIp_SockAddrType default_router;
destination.domain = TCPIP_AF_INET;
default_router.domain = TCPIP_AF_INET;
(void)SoAd_GetLocalAddr(multicast_rx_socket, &destination, &netmask, &default_router);
/* Set the remote multicast address before sending */
(void)SoAd_SetRemoteAddr(tx_socket, &destination);
/* Assign sessionID for this SD messsage */
sd_msg.RequestID |= instance->MulticastSessionID;
/** @req 4.2.2/SWS_SD_00035 */
/** @req 4.2.2/SWS_SD_00036 */
if (instance->MulticastSessionID == 0xFFFF){
instance->MulticastSessionID = 1u;
}
else {
instance->MulticastSessionID++;
}
}
/* Combine entries and options to sd message */
memset(message,0,PAYLOAD_MAX);
FillMessage(sd_msg, message, &messagelength);
pduinfo.SduDataPtr = message;
pduinfo.SduLength = (uint16) messagelength;
pdu = instance->InstanceCfg->TxPduId;
/** @req 4.2.2/SWS_SD_00039 */
/** @req 4.2.2/SWS_SD_00709 */
(void)SoAd_IfTransmit(pdu,&pduinfo);
/** @req 4.2.2/SWS_SD_00705 */
(void)SoAd_SetRemoteAddr(instance->TxSoCon, &wildcard);
}
}
|
2301_81045437/classic-platform
|
communication/SD/src/SD_Send_Receive.c
|
C
|
unknown
| 24,604
|
/*-------------------------------- Arctic Core ------------------------------
* Copyright (C) 2013, ArcCore AB, Sweden, www.arccore.com.
* Contact: <contact@arccore.com>
*
* You may ONLY use this file:
* 1)if you have a valid commercial ArcCore license and then in accordance with
* the terms contained in the written license agreement between you and ArcCore,
* or alternatively
* 2)if you follow the terms found in GNU General Public License version 2 as
* published by the Free Software Foundation and appearing in the file
* LICENSE.GPL included in the packaging of this file or here
* <http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt>
*-------------------------------- Arctic Core -----------------------------*/
/** @reqSettings DEFAULT_SPECIFICATION_REVISION=4.2.2 */
/** @req 4.2.2/SWS_SD_00029 The Service Discovery module shall only call SoAd_IfTransmit() if an IP address is assigned */
#include "SD.h"
#include "SD_Internal.h"
#include "BswM_Sd.h"
#include "string.h"
static Sd_Entry_Type1_Services entry11;
static Sd_Entry_Type2_EventGroups entry22;
static TcpIp_SockAddrType ipaddress;
/* Datastructure for dynamic data used by state machine, generated by Sd generator */
extern Sd_DynConfigType Sd_DynConfig;
static const TcpIp_SockAddrType wildcard = {
(TcpIp_DomainType) TCPIP_AF_INET,
0 /* TBD Port???? */,
{TCPIP_IPADDR_ANY, TCPIP_IPADDR_ANY, TCPIP_IPADDR_ANY, TCPIP_IPADDR_ANY }
};
Sd_Message msg;
static void EntryReceived(Sd_DynServerServiceType *server, Sd_Entry_Type1_Services **entry1, Sd_Entry_Type2_EventGroups **entry2, TcpIp_SockAddrType *ipaddress, boolean *is_multicast)
{
Sd_InstanceType *server_svc = NULL;
uint8 *option_run1 [MAX_OPTIONS] = {NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL};
uint8 *option_run2 [MAX_OPTIONS] = {NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL};
uint8 no_of_endpoints = 0;
uint8 no_of_capabilty_records = 0;
Ipv4Endpoint endpoint[MAX_OPTIONS];
Sd_CapabilityRecordType capabilty_record[MAX_OPTIONS];
/* First check if there are more entries in the last read message to fetch */
if (msg.ProtocolVersion != 0x01) {
/* Fetch a new message from the queue */
if (!ReceiveSdMessage(&msg, ipaddress, SERVER_QUEUE, &server_svc, is_multicast)) {
*entry1 = NULL;
*entry2 = NULL;
return;
}
/* Check that message type is 0x02 */
/** @req 4.2.2/SWS_SD_00145 */
if (msg.MessageType != 0x02) {
*entry1 = NULL;
*entry2 = NULL;
FreeSdMessage(SERVER_QUEUE);
return;
}
/* Check that interface version is 0x01 */
/** @req 4.2.2/SWS_SD_00143 */
if (msg.InterfaceVersion != 0x01) {
*entry1 = NULL;
*entry2 = NULL;
FreeSdMessage(SERVER_QUEUE);
return;
}
}
/* Find out which type of entry */
uint8 type = msg.EntriesArray[0];
if ((type == 0) || (type == 1)) {
/* FIND_SERVICE */
DecodeType1Entry (msg.EntriesArray, *entry1);
*entry2 = NULL;
if (msg.LengthOfOptionsArray > 0) {
OptionsReceived(msg.OptionsArray, msg.LengthOfOptionsArray, *entry1, NULL, option_run1, option_run2);
}
/* Move entry pointer */
msg.EntriesArray += ENTRY_TYPE_1_SIZE;
}
else if ((type == 6) || (type == 7)) {
/* SUBSCRIBE_EVENTGROUP or STOP_SUBSCRIBE_EVENTGROUP */
DecodeType2Entry (msg.EntriesArray, *entry2);
*entry1 = NULL;
if (msg.LengthOfOptionsArray > 0) {
OptionsReceived(msg.OptionsArray, msg.LengthOfOptionsArray, NULL, *entry2, option_run1, option_run2);
}
/* Move entry pointer */
msg.EntriesArray += ENTRY_TYPE_2_SIZE;
}
/* Decode configuration option attribute */
DecodeOptionConfiguration(option_run1,capabilty_record,&no_of_capabilty_records);
/* Check if this message is aimed for this server instance */
if (*entry1 != NULL) {
/** @req 4.2.2/SWS_SD_00486 */
/* Received FindService */
boolean matchServiceID = (((*entry1)->ServiceID == 0xFFFF) || ((*entry1)->ServiceID == server->ServerServiceCfg->Id));
/** @req 4.2.2/SWS_SD_00295 */
boolean matchInstanceID = (((*entry1)->InstanceID == 0xFFFF) || ((*entry1)->InstanceID == server->ServerServiceCfg->InstanceId));
boolean matchMajorVersion = (((*entry1)->MajorVersion == 0xFF) || ((*entry1)->MajorVersion == server->ServerServiceCfg->MajorVersion));
boolean matchMinorVersion = (((*entry1)->MinorVersion == 0xFFFFFFFF) || ((*entry1)->MinorVersion == server->ServerServiceCfg->MinorVersion));
/* This server is the intended one. No endpoint option need to be analyzed for FindService entries. */
if (!(matchServiceID && matchInstanceID && matchMajorVersion && matchMinorVersion)){
*entry1 = NULL;
*entry2 = NULL;
} else {
/* This server is the intended one. No endpoint option need to be analyzed for FindService entries.
* Fetch remote address from RxPdu */
if (server_svc != NULL) {
SoAd_SoConIdType client_socket;
if (*is_multicast) {
(void)SoAd_Arc_GetSoConIdFromRxPdu(server_svc->MulticastRxPduId, &client_socket);
} else {
(void)SoAd_Arc_GetSoConIdFromRxPdu(server_svc->UnicastRxPduId, &client_socket);
}
(void)SoAd_GetRemoteAddr(client_socket, ipaddress);
(void)SoAd_SetRemoteAddr(Sd_DynConfig.Instance->TxSoCon, &wildcard);
}
FreeSdMessage(SERVER_QUEUE);
}
} else if (entry2 != NULL) {
/* Received SubscribeEventgroup or StopSubscribeEventgroup */
/** @req 4.2.2/SWS_SD_00490 */
boolean EventHandlerFound = FALSE;
uint8 EventHandlerIndex = 0;
for (uint8 i=0; i < server->ServerServiceCfg->NoOfEventHandlers; i++){
if (((*entry2)->ServiceID == server->ServerServiceCfg->Id) &&
((*entry2)->InstanceID == server->ServerServiceCfg->InstanceId) &&
((*entry2)->MajorVersion == server->ServerServiceCfg->MajorVersion) &&
((*entry2)->EventgroupID == server->ServerServiceCfg->EventHandler[i].EventGroupId))
{
/* The entry was aimed for this server instance. */
EventHandlerFound = TRUE;
EventHandlerIndex = i;
break;
}
}
if (!EventHandlerFound)
{
*entry1 = NULL;
*entry2 = NULL;
} else {
/* Decode and store the option parameters */
DecodeOptionIpv4Endpoint(option_run1, endpoint, &no_of_endpoints);
for (uint8 i=0; i < no_of_endpoints; i++){
if (endpoint[i].Protocol == UDP_PROTO) {
memcpy(&server->EventHandlers[EventHandlerIndex].UdpEndpoint, &endpoint[i], sizeof(Ipv4Endpoint));
server->EventHandlers[EventHandlerIndex].UdpEndpoint.valid = TRUE;
}
else if (endpoint[i].Protocol == TCP_PROTO) {
memcpy(&server->EventHandlers[EventHandlerIndex].TcpEndpoint, &endpoint[i], sizeof(Ipv4Endpoint));
server->EventHandlers[EventHandlerIndex].TcpEndpoint.valid = TRUE;
}
}
FreeSdMessage(SERVER_QUEUE);
}
}
if (msg.EntriesArray == (msg.OptionsArray - 4)) {
/* All entries are processed in this message.
* Set protcolversion to 0 to indicate that a new message
* should be fetched for the next entry. */
msg.ProtocolVersion = 0x00;
}
}
#if 0
/* This function is currenly not used, it is kept since it may be used as a part of SD server
* functionality. It should be removed if not used when SD server has been added.
*/
/* Open TCP Connection if TcpRef is configured and was not opened before*/
static void SetRemoteTcpConnection(Sd_DynServerServiceType *server)
{
if ((server->ServerServiceCfg->TcpSocketConnectionGroupId != SOCKET_CONNECTION_GROUP_NOT_SET))
{
/* Open all SoCons in Group */
for (uint16 i=0;i<sizeof(server->ServerServiceCfg->TcpSocketConnectionGroupSocketConnectionIdsPtr)/sizeof(uint16); i++){
(void)SoAd_OpenSoCon(server->ServerServiceCfg->TcpSocketConnectionGroupSocketConnectionIdsPtr[i]);
}
server->TcpSoConOpened = TRUE;
}
}
#endif
/* Open TCP Connection if TcpRef is configured and was not opened before*/
static void OpenTcpConnection(Sd_DynServerServiceType *server)
{
if ((server->ServerServiceCfg->TcpSocketConnectionGroupId != SOCKET_CONNECTION_GROUP_NOT_SET) && !(server->TcpSoConOpened))
{
/* Open all SoCons in Group */
for (uint16 i=0;i<sizeof(server->ServerServiceCfg->TcpSocketConnectionGroupSocketConnectionIdsPtr)/sizeof(uint16); i++){
(void)SoAd_OpenSoCon(server->ServerServiceCfg->TcpSocketConnectionGroupSocketConnectionIdsPtr[i]);
}
server->TcpSoConOpened = TRUE;
}
}
/* Open Udp Connection if UdpRef is configured and was not opened before*/
static void OpenUdpConnection(Sd_DynServerServiceType *server)
{
if ((server->ServerServiceCfg->UdpSocketConnectionGroupId != SOCKET_CONNECTION_GROUP_NOT_SET) && !(server->UdpSoConOpened))
{
/* Open all SoCons in Group */
for (uint16 i=0;i<sizeof(server->ServerServiceCfg->UdpSocketConnectionGroupSocketConnectionIdsPtr)/sizeof(uint16); i++){
(void)SoAd_OpenSoCon(server->ServerServiceCfg->UdpSocketConnectionGroupSocketConnectionIdsPtr[i]);
}
server->UdpSoConOpened = TRUE;
}
}
static void OpenSocketConnections(Sd_DynServerServiceType *server)
{
OpenTcpConnection(server); /** @req 4.2.2/SWS_SD_00421 */
OpenUdpConnection(server);
server->SocketConnectionOpened = TRUE;
}
/* Close TCP Connection if TcpRef is configured and was not opened before*/
static void CloseTcpConnection(Sd_DynServerServiceType *server, boolean abort)
{
if ((server->ServerServiceCfg->TcpSocketConnectionGroupId != SOCKET_CONNECTION_GROUP_NOT_SET) && (server->TcpSoConOpened)) {
/* Open all SoCons in Group */
for (uint16 i=0;i<sizeof(server->ServerServiceCfg->TcpSocketConnectionGroupSocketConnectionIdsPtr)/sizeof(uint16); i++) {
(void)SoAd_CloseSoCon(server->ServerServiceCfg->TcpSocketConnectionGroupSocketConnectionIdsPtr[i], abort);
}
server->TcpSoConOpened = FALSE;
}
}
/* Close Udp Connection if UdpRef is configured and was not opened before*/
static void CloseUdpConnection(Sd_DynServerServiceType *server, boolean abort)
{
if ((server->ServerServiceCfg->UdpSocketConnectionGroupId != SOCKET_CONNECTION_GROUP_NOT_SET) && (server->UdpSoConOpened)) {
for (uint16 i=0;i<sizeof(server->ServerServiceCfg->UdpSocketConnectionGroupSocketConnectionIdsPtr)/sizeof(uint16); i++) {
(void)SoAd_CloseSoCon(server->ServerServiceCfg->UdpSocketConnectionGroupSocketConnectionIdsPtr[i], abort);
}
server->UdpSoConOpened = FALSE;
}
}
static void CloseSocketConnections(Sd_DynServerServiceType *server, boolean abort)
{
CloseTcpConnection(server, abort);
CloseUdpConnection(server, abort);
server->SocketConnectionOpened = FALSE;
}
void UpdateServerService(const Sd_ConfigType *cfgPtr, uint32 instanceno, uint32 serverno){
Sd_DynServerServiceType *server = &Sd_DynConfig.Instance[instanceno].SdServerService[serverno];
Sd_DynInstanceType *sd_instance = &Sd_DynConfig.Instance[instanceno];
Sd_Entry_Type1_Services *entry1 = &entry11;
Sd_Entry_Type2_EventGroups *entry2 = &entry22;
boolean is_multicast = FALSE;
memset(&entry11, 0, sizeof(Sd_Entry_Type1_Services));
memset(&entry22, 0, sizeof(Sd_Entry_Type2_EventGroups));
EntryReceived(server, &entry1, &entry2, &ipaddress, &is_multicast);
switch (server->Phase)
{
case SD_DOWN_PHASE:
/** @req 4.2.2/SWS_SD_00317 */
if ((server->ServerServiceMode == SD_SERVER_SERVICE_AVAILABLE) && sd_instance->TxPduIpAddressAssigned) {
/** @req 4.2.2/SWS_SD_00330 */
/** @req 4.2.2/SWS_SD_00024 */
/* Call SoAd_EnableRouting(): IMPROVEMENT: Is this correct?*/
(void)SoAd_EnableRouting (server->ServerServiceCfg->ProvidedMethods.ServerServiceActivationRef);
server->Phase = SD_INITIAL_WAIT_PHASE; /* DOWN -> INITIAL_WAIT */
/** @req 4.2.2/SWS_SD_00606 */
OpenSocketConnections(server);
}
break;
case SD_INITIAL_WAIT_PHASE:
/** @req 4.2.2/SWS_SD_00319 */
/** @req 4.2.2/SWS_SD_00323 */
if (server->ServerServiceMode != SD_SERVER_SERVICE_AVAILABLE) {
server->InitialOffer_Timer_Value_ms = 0;
server->InitialOfferTimerOn = FALSE;
server->Phase = SD_DOWN_PHASE; /* INITIAL_WAIT -> DOWN */
/* Set all EventHandlersCurrentState to RELEASED */
for (uint8 eh = 0; eh < server->ServerServiceCfg->NoOfEventHandlers; eh++) {
BswM_Sd_EventHandlerCurrentState(
server->ServerServiceCfg->EventHandler[eh].HandleId,
SD_EVENT_HANDLER_RELEASED);
}
/** @req 4.2.2/SWS_SD_00605 */
if (server->SocketConnectionOpened) {
/* Call SoAd_CloseSoCon() for all socket connections
* in this server service instance */
CloseSocketConnections(server, TRUE); // IMPROVEMENT: Investigate abort parameter
}
}
/** @req 4.2.2/SWS_SD_00325 */
if (!sd_instance->TxPduIpAddressAssigned) {
server->InitialOffer_Timer_Value_ms = 0;
server->InitialOfferTimerOn = FALSE;
server->Phase = SD_DOWN_PHASE; /* INITIAL_WAIT -> DOWN */
/** @req 4.2.2/SWS_SD_00605 */
if (server->SocketConnectionOpened) {
/* Call SoAd_CloseSoCon() for all socket connections
* in this server service instance */
CloseSocketConnections(server, TRUE); // IMPROVEMENT: Investigate abort parameter
}
}
if (!server->InitialOfferTimerOn) {
/** @req 4.2.2/SWS_SD_00318 */
/* Start random InitialOffer Timer */
server->InitialOffer_Timer_Value_ms = RandomDelay(server->ServerServiceCfg->TimerRef->InitialOfferDelayMin_ms,
server->ServerServiceCfg->TimerRef->InitialOfferDelayMax_ms);
server->InitialOfferTimerOn = TRUE;
}
else
{
/** @req 4.2.2/SWS_SD_00320 */
/* TBD: How to interpret this req? The same as 4.2.2/SWS_SD_00333,4.2.2/SWS_SD_00334,4.2.2/SWS_SD_00344, 4.2.2/SWS_SD_00345? */
/** @req 4.2.2/SWS_SD_00321 */
server->InitialOffer_Timer_Value_ms -= SD_MAIN_FUNCTION_CYCLE_TIME_MS;
if (server->InitialOffer_Timer_Value_ms <= 0) {
/* Send OfferService Entry */
TransmitSdMessage(sd_instance, (Sd_DynClientServiceType *)NULL, server, NULL, 0, SD_OFFER_SERVICE, NULL, is_multicast); // IMPROVEMENT: Should ipaddress parameter be used
server->InitialOffer_Timer_Value_ms = 0;
server->InitialOfferTimerOn = FALSE;
/** @req 4.2.2/SWS_SD_00434 */
/** @req 4.2.2/SWS_SD_00435 */
if (server->ServerServiceCfg->TimerRef->InitialOfferRepetitionsMax == 0){
server->Phase = SD_MAIN_PHASE; /* INITIAL_WAIT -> MAIN */
}
else {
server->Phase = SD_REPETITION_PHASE; /* INITIAL_WAIT -> REPETITION */
server->RepetitionFactor = 1;
server->OfferRepetitions = 0;
}
break;
}
}
break;
case SD_REPETITION_PHASE:
/* Step the EventHandler TTL timers */
for (uint8 eh=0; eh < server->ServerServiceCfg->NoOfEventHandlers; eh++){
if (server->EventHandlers[eh].EventHandlerState == SD_EVENT_HANDLER_REQUESTED){
for(uint8 sub=0; sub < MAX_NO_OF_SUBSCRIBERS; sub++) {
if (server->EventHandlers[eh].FanOut[sub].TTL_Timer_On){
server->EventHandlers[eh].FanOut[sub].TTL_Timer_Value_ms -= SD_MAIN_FUNCTION_CYCLE_TIME_MS;
/** @req 4.2.2/SWS_SD_00458 */
if (server->EventHandlers[eh].FanOut[sub].TTL_Timer_Value_ms <= 0){
/* Timer expired */
server->EventHandlers[eh].FanOut[sub].TTL_Timer_On = FALSE;
server->EventHandlers[eh].FanOut[sub].TTL_Timer_Value_ms = 0;
server->EventHandlers[eh].NoOfSubscribers--;
if (server->EventHandlers[eh].NoOfSubscribers == 0) {
server->EventHandlers[eh].EventHandlerState = SD_EVENT_HANDLER_RELEASED;
/* Change state for the EventHandler in BswM. */
/* IMPROVEMENT: Do this only if current value is != RELEASED */
BswM_Sd_EventHandlerCurrentState(server->ServerServiceCfg->EventHandler[eh].HandleId, SD_EVENT_HANDLER_RELEASED);
}
}
}
}
}
}
/** @req 4.2.2/SWS_SD_00338 */
if (server->ServerServiceMode != SD_SERVER_SERVICE_AVAILABLE) {
server->Phase = SD_DOWN_PHASE; /* INITIAL_WAIT -> DOWN */
/* Set all EventHandlersCurrentState to RELEASED */
for (uint8 eh = 0; eh < server->ServerServiceCfg->NoOfEventHandlers; eh++){
BswM_Sd_EventHandlerCurrentState(
server->ServerServiceCfg->EventHandler[eh].HandleId,
SD_EVENT_HANDLER_RELEASED);
}
/** @req 4.2.2/SWS_SD_00341 */
/** @req 4.2.2/SWS_SD_00024 */
/* Call SoAd_DisableRouting(): IMPROVEMENT: Is this correct?*/
(void)SoAd_DisableRouting (server->ServerServiceCfg->ProvidedMethods.ServerServiceActivationRef);
/** @req 4.2.2/SWS_SD_00605 */
if (server->SocketConnectionOpened){
/* Call SoAd_CloseSoCon() for all socket connections
* in this server service instance */
CloseSocketConnections(server, TRUE); // IMPROVEMENT: Investigate abort parameter
}
}
/** @req 4.2.2/SWS_SD_00340 */
if (!sd_instance->TxPduIpAddressAssigned) {
server->Phase = SD_DOWN_PHASE; /* INITIAL_WAIT -> DOWN */
/** @req 4.2.2/SWS_SD_00605 */
if (server->SocketConnectionOpened){
/* Call SoAd_CloseSoCon() for all socket connections
* in this server service instance */
CloseSocketConnections(server, TRUE); // IMPROVEMENT: Investigate abort parameter
}
}
if (!server->OfferRepDelayTimerOn) {
/** @req 4.2.2/SWS_SD_00329 */
/* Start OfferRepDelay Timer */
server->OfferRepDelay_Timer_Value_ms = server->RepetitionFactor * server->ServerServiceCfg->TimerRef->InitialOfferRepetitionBaseDelay_ms;
server->OfferRepDelayTimerOn = TRUE;
}
// else
// {
/** @req 4.2.2/SWS_SD_00331 */
/* IMPROVEMENT: Check the calculation for the timer step. */
server->OfferRepDelay_Timer_Value_ms -= SD_MAIN_FUNCTION_CYCLE_TIME_MS;
if (server->OfferRepDelay_Timer_Value_ms <= 0) {
/* Send OfferService Entry */
TransmitSdMessage(sd_instance, NULL, server, NULL, 0, SD_OFFER_SERVICE,NULL,FALSE); // IMPROVEMENT: Should ipaddress parameter be used
server->OfferRepDelayTimerOn = FALSE;
server->OfferRepetitions++;
server->RepetitionFactor = server->RepetitionFactor * 2; /* Doubles the interval for next FindService */
/** @req 4.2.2/SWS_SD_00336 */
if (server->OfferRepetitions >= server->ServerServiceCfg->TimerRef->InitialOfferRepetitionsMax){
server->Phase = SD_MAIN_PHASE; /* REPETITION -> MAIN */
break;
}
}
/** @req 4.2.2/SWS_SD_00332 */
if (entry1 != (Sd_Entry_Type1_Services *) NULL){
if ((entry1->Type == FIND_SERVICE_TYPE)) {
/* Send OfferService Entry */
TransmitSdMessage(sd_instance, NULL, server, NULL, 0, SD_OFFER_SERVICE,NULL,is_multicast); // IMPROVEMENT: Should ipaddress parameter be used
}
}
/** @req 4.2.2/SWS_SD_00333 */
if (entry2 != (Sd_Entry_Type2_EventGroups *) NULL){
if ((entry2->Type == SUBSCRIBE_EVENTGROUP_TYPE) && (entry2->TTL > 0)) {
boolean event_handler_found = FALSE;
uint8 event_handler_index = 0;
/* Find the subscribed event handler. Set it to REQUESTED, and start the TTL Timer for the subscriber
* IMROVEMENT: For now we use the Counter parameter as index. Maybe not correct? */
for (uint8 eh=0; eh < server->ServerServiceCfg->NoOfEventHandlers; eh++){
if (server->ServerServiceCfg->EventHandler[eh].EventGroupId == entry2->EventgroupID) {
// /** @ req 4.2.2/SWS_SD_00454 */
// //IMPROVEMENT: More work is needed.
//
// if (server->ServerServiceCfg->EventHandler[eh].Udp != NULL) {
// if (server->ServerServiceCfg->EventHandler[eh].Udp->EventActivationRef != ACTIVATION_REF_NOT_SET) {
//
// /* Set socket remote address */
// /* IMPROVEMENT: Go through the udp socket connections and compare it with Ipv4EndpointOptionUdp for this eventgroup.
// * If none is found, set the remote address on a wildcard. */
//
// /* Enable routing */
// if (server->EventHandlers[eh].NoOfSubscribers == 0){
// (void)SoAd_EnableSpecificRouting
// (server->ServerServiceCfg->EventHandler[eh].Udp->EventActivationRef,
// server->ServerServiceCfg->UdpSocketConnectionGroupId);
//
//// (void)SoAd_IfSpecificRoutingGroupTransmit
//// (server->ServerServiceCfg->EventHandler[eh].Udp->EventTriggeringRef,
//// server->ServerServiceCfg->UdpSocketConnectionGroupId);
//
// }
// }
// } else {
//
// /** @ req 4.2.2/SWS_SD_00453 */
// if (server->ServerServiceCfg->EventHandler[eh].Tcp != NULL) {
// if (server->ServerServiceCfg->EventHandler[eh].Tcp->EventActivationRef != ACTIVATION_REF_NOT_SET) {
//
// /* Set socket remote address */
// /* IMPROVEMENT: Go through the tcp socket connections and compare it with Ipv4EndpointOptionTcp.
// * If none is found, set the remote address on a wildcard. */
//
// /* Enable routing */
// if (server->EventHandlers[eh].NoOfSubscribers == 0){
// (void)SoAd_EnableSpecificRouting
// (server->ServerServiceCfg->EventHandler[eh].Tcp->EventActivationRef,
// server->ServerServiceCfg->TcpSocketConnectionGroupId);
//
//// (void)SoAd_IfSpecificRoutingGroupTransmit
//// (server->ServerServiceCfg->EventHandler[eh].Tcp->EventTriggeringRef,
//// server->ServerServiceCfg->TcpSocketConnectionGroupId);
//
// }
// }
// }
// }
server->EventHandlers[eh].EventHandlerState = SD_EVENT_HANDLER_REQUESTED;
server->EventHandlers[eh].NoOfSubscribers++;
server->EventHandlers[eh].FanOut [entry2->Counter].TTL_Timer_Value_ms = entry2->TTL * 1000;
server->EventHandlers[eh].FanOut [entry2->Counter].TTL_Timer_On = TRUE;
/* Change state for the EventHandler in BswM. */
if (server->EventHandlers[eh].NoOfSubscribers == 1) {
BswM_Sd_EventHandlerCurrentState(server->ServerServiceCfg->EventHandler[eh].HandleId, SD_EVENT_HANDLER_REQUESTED);
}
event_handler_found = TRUE;
event_handler_index = eh;
break;
}
}
if (event_handler_found) {
/* Send SubscribeEventGroupAck Entry */
TransmitSdMessage(sd_instance, NULL, server, entry2, event_handler_index, SD_SUBSCRIBE_EVENTGROUP_ACK, &ipaddress, is_multicast);
}
}
/** @req 4.2.2/SWS_SD_00334 */
if (entry2 != (Sd_Entry_Type2_EventGroups *) NULL){
if ((entry2->Type == STOP_SUBSCRIBE_EVENTGROUP_TYPE) && (entry2->TTL == 0)) {
/* Find the subscribed event handler. Set it to RELEASED, and stop the TTL Timer.
* IMROVEMENT: For now we use the Counter parameter as index. Maybe not correct? */
for (uint8 eh=0; eh < server->ServerServiceCfg->NoOfEventHandlers; eh++){
if (server->ServerServiceCfg->EventHandler[eh].EventGroupId == entry2->EventgroupID) {
server->EventHandlers[eh].FanOut[entry2->Counter].TTL_Timer_On = FALSE;
server->EventHandlers[eh].FanOut[entry2->Counter].TTL_Timer_Value_ms = 0;
server->EventHandlers[eh].NoOfSubscribers--;
if (server->EventHandlers[eh].NoOfSubscribers == 0) {
// /** @ req 4.2.2/SWS_SD_00454 */
/* IMPROVEMENT: More work is needed */
// if (server->ServerServiceCfg->EventHandler[eh].Udp != NULL) {
// if (server->ServerServiceCfg->EventHandler[eh].Udp->EventActivationRef != ACTIVATION_REF_NOT_SET) {
//
// /* Disable routing */
// (void)SoAd_DisableSpecificRouting
// (server->ServerServiceCfg->EventHandler[eh].Udp->EventActivationRef,
// server->ServerServiceCfg->UdpSocketConnectionGroupId);
//
// }
// } else {
//
// /** @ req 4.2.2/SWS_SD_00453 */
// if (server->ServerServiceCfg->EventHandler[eh].Tcp != NULL) {
// if (server->ServerServiceCfg->EventHandler[eh].Tcp->EventActivationRef != ACTIVATION_REF_NOT_SET) {
//
// /* Disable routing */
// (void)SoAd_DisableSpecificRouting
// (server->ServerServiceCfg->EventHandler[eh].Tcp->EventActivationRef,
// server->ServerServiceCfg->TcpSocketConnectionGroupId);
// }
// }
// }
// }
server->EventHandlers[eh].EventHandlerState = SD_EVENT_HANDLER_RELEASED;
/* Change state for the EventHandler in BswM. */
/* IMPROVEMENT: Do this only if current value is != RELEASED */
BswM_Sd_EventHandlerCurrentState(server->ServerServiceCfg->EventHandler[eh].HandleId, SD_EVENT_HANDLER_RELEASED);
}
break;
}
}
}
}
// }
}
break;
case SD_MAIN_PHASE:
/* Step the EventHandler TTL timers */
for (uint8 eh=0; eh < server->ServerServiceCfg->NoOfEventHandlers; eh++){
if (server->EventHandlers[eh].EventHandlerState == SD_EVENT_HANDLER_REQUESTED){
for(uint8 sub=0; sub < MAX_NO_OF_SUBSCRIBERS; sub++) {
if (server->EventHandlers[eh].FanOut[sub].TTL_Timer_On){
server->EventHandlers[eh].FanOut[sub].TTL_Timer_Value_ms -= SD_MAIN_FUNCTION_CYCLE_TIME_MS;
/** @req 4.2.2/SWS_SD_00403 */
if (server->EventHandlers[eh].FanOut[sub].TTL_Timer_Value_ms <= 0){
/* Timer expired */
server->EventHandlers[eh].FanOut[sub].TTL_Timer_On = FALSE;
server->EventHandlers[eh].FanOut[sub].TTL_Timer_Value_ms = 0;
server->EventHandlers[eh].NoOfSubscribers--;
if (server->EventHandlers[eh].NoOfSubscribers == 0) {
server->EventHandlers[eh].EventHandlerState = SD_EVENT_HANDLER_RELEASED;
/* Change state for the EventHandler in BswM. */
/* IMPROVEMENT: Do this only if current value is != RELEASED */
BswM_Sd_EventHandlerCurrentState(server->ServerServiceCfg->EventHandler[eh].HandleId, SD_EVENT_HANDLER_RELEASED);
}
}
}
}
}
}
/** @req 4.2.2/SWS_SD_00451 */
if (server->ServerServiceCfg->TimerRef->OfferCyclicDelay_ms > 0) {
/** @req 4.2.2/SWS_SD_00449 */
if (!server->OfferCyclicDelayTimerOn) {
/** @req 4.2.2/SWS_SD_00450 */
/* Start OfferCyclicDelay Timer */
server->OfferCyclicDelay_Timer_Value_ms = server->ServerServiceCfg->TimerRef->OfferCyclicDelay_ms;
server->OfferCyclicDelayTimerOn = TRUE;
}
else
{
server->OfferCyclicDelay_Timer_Value_ms -= SD_MAIN_FUNCTION_CYCLE_TIME_MS;
if (server->OfferCyclicDelay_Timer_Value_ms <= 0) {
/* Send OfferService Entry */
TransmitSdMessage(sd_instance, NULL, server, NULL, 0, SD_OFFER_SERVICE,NULL, FALSE); // IMPROVEMENT: Should ipaddress parameter be used
/* Reset Timer */
server->OfferCyclicDelay_Timer_Value_ms = server->ServerServiceCfg->TimerRef->OfferCyclicDelay_ms;
}
}
}
/** @req 4.2.2/SWS_SD_00343 */
if (entry1 != (Sd_Entry_Type1_Services *) NULL){
if ((entry1->Type == FIND_SERVICE_TYPE)) {
/* Send OfferService Entry */
TransmitSdMessage(sd_instance, NULL, server, NULL, 0, SD_OFFER_SERVICE,NULL,is_multicast); // IMPROVEMENT: Should ipaddress parameter be used
}
}
/** @req 4.2.2/SWS_SD_00344 */
if (entry2 != (Sd_Entry_Type2_EventGroups *) NULL){
if ((entry2->Type == SUBSCRIBE_EVENTGROUP_TYPE) && (entry2->TTL > 0)) {
boolean event_handler_found = FALSE;
uint8 event_handler_index = 0;
/* Find the subscribed event handler. Set it to REQUESTED, and start the TTL Timer for the subscriber
* IMROVEMENT: For now we use the Counter parameter as index. Maybe not correct? */
for (uint8 eh=0; eh < server->ServerServiceCfg->NoOfEventHandlers; eh++){
if (server->ServerServiceCfg->EventHandler[eh].EventGroupId == entry2->EventgroupID) {
server->EventHandlers[eh].EventHandlerState = SD_EVENT_HANDLER_REQUESTED;
server->EventHandlers[eh].NoOfSubscribers++;
server->EventHandlers[eh].FanOut [entry2->Counter].TTL_Timer_Value_ms = entry2->TTL * 1000;
server->EventHandlers[eh].FanOut [entry2->Counter].TTL_Timer_On = TRUE;
/* Change state for the EventHandler in BswM. */
if (server->EventHandlers[eh].NoOfSubscribers == 1) {
BswM_Sd_EventHandlerCurrentState(server->ServerServiceCfg->EventHandler[eh].HandleId, SD_EVENT_HANDLER_REQUESTED);
}
event_handler_found = TRUE;
event_handler_index = eh;
break;
}
}
if (event_handler_found) {
/* Send SubscribeEventGroupAck Entry */
TransmitSdMessage(sd_instance, NULL, server, entry2, event_handler_index, SD_SUBSCRIBE_EVENTGROUP_ACK, &ipaddress,is_multicast);
}
}
/** @req 4.2.2/SWS_SD_00345 */
if (entry2 != (Sd_Entry_Type2_EventGroups *) NULL){
if ((entry2->Type == STOP_SUBSCRIBE_EVENTGROUP_TYPE) && (entry2->TTL == 0)) {
/* Find the subscribed event handler. Set it to RELEASED, and stop the TTL Timer.
* IMROVEMENT: For now we use the Counter parameter as index. Maybe not correct? */
for (uint8 eh=0; eh < server->ServerServiceCfg->NoOfEventHandlers; eh++){
if (server->ServerServiceCfg->EventHandler[eh].EventGroupId == entry2->EventgroupID) {
server->EventHandlers[eh].FanOut[entry2->Counter].TTL_Timer_On = FALSE;
server->EventHandlers[eh].FanOut[entry2->Counter].TTL_Timer_Value_ms = 0;
server->EventHandlers[eh].NoOfSubscribers--;
if (server->EventHandlers[eh].NoOfSubscribers <= 0) {
server->EventHandlers[eh].EventHandlerState = SD_EVENT_HANDLER_RELEASED;
/* Change state for the EventHandler in BswM. */
/* IMPROVEMENT: Do this only if current value is != RELEASED */
BswM_Sd_EventHandlerCurrentState(server->ServerServiceCfg->EventHandler[eh].HandleId, SD_EVENT_HANDLER_RELEASED);
}
break;
}
}
}
}
}
/** @req 4.2.2/SWS_SD_00347 */
if (!sd_instance->TxPduIpAddressAssigned) {
server->Phase = SD_DOWN_PHASE; /* INITIAL_WAIT -> DOWN */
/* Set all EventHandlersCurrentState to RELEASED */
for (uint8 eh = 0; eh < server->ServerServiceCfg->NoOfEventHandlers;
eh++) {
for (uint8 sub=0; sub < MAX_NO_OF_SUBSCRIBERS; sub++) {
server->EventHandlers[eh].FanOut[sub].TTL_Timer_On = FALSE;
server->EventHandlers[eh].FanOut[sub].TTL_Timer_Value_ms = 0;
}
server->EventHandlers[eh].NoOfSubscribers = 0;
server->EventHandlers[eh].EventHandlerState = SD_EVENT_HANDLER_RELEASED;
BswM_Sd_EventHandlerCurrentState(
server->ServerServiceCfg->EventHandler[eh].HandleId,
SD_EVENT_HANDLER_RELEASED);
}
/** @req 4.2.2/SWS_SD_00349 */
/* Call SoAd_DisableRouting(): IMPROVEMENT: Is this correct?*/
(void)SoAd_DisableRouting(
server->ServerServiceCfg->ProvidedMethods.ServerServiceActivationRef);
/** @req 4.2.2/SWS_SD_00605 */
if (server->SocketConnectionOpened) {
/* Call SoAd_CloseSoCon() for all socket connections
* in this server service instance */
CloseSocketConnections(server, TRUE); // IMPROVEMENT: Investigate abort parameter
}
break;
}
/** @req 4.2.2/SWS_SD_00342 */
/** @req 4.2.2/SWS_SD_00348 */
if ((server->ServerServiceMode == SD_SERVER_SERVICE_DOWN)
&& sd_instance->TxPduIpAddressAssigned) {
server->Phase = SD_DOWN_PHASE; /* INITIAL_WAIT -> DOWN */
/* Send a StopOffer Message */
TransmitSdMessage(sd_instance, NULL, server, NULL, 0, SD_STOP_OFFER_SERVICE, NULL, FALSE); // IMPROVEMENT: Should ipaddress parameter be used
/* Set all EventHandlersCurrentState to RELEASED */
for (uint8 eh = 0; eh < server->ServerServiceCfg->NoOfEventHandlers;
eh++) {
for (uint8 sub=0; sub < MAX_NO_OF_SUBSCRIBERS; sub++) {
server->EventHandlers[eh].FanOut[sub].TTL_Timer_On = FALSE;
server->EventHandlers[eh].FanOut[sub].TTL_Timer_Value_ms = 0;
}
server->EventHandlers[eh].NoOfSubscribers = 0;
server->EventHandlers[eh].EventHandlerState = SD_EVENT_HANDLER_RELEASED;
BswM_Sd_EventHandlerCurrentState(
server->ServerServiceCfg->EventHandler[eh].HandleId,
SD_EVENT_HANDLER_RELEASED);
}
/** @req 4.2.2/SWS_SD_00349 */
/* Call SoAd_DisableRouting(): IMPROVEMENT: Is this correct?*/
(void)SoAd_DisableRouting(
server->ServerServiceCfg->ProvidedMethods.ServerServiceActivationRef);
/** @req 4.2.2/SWS_SD_00605 */
if (server->SocketConnectionOpened) {
/* Call SoAd_CloseSoCon() for all socket connections
* in this server service instance */
CloseSocketConnections(server, TRUE); // IMPROVEMENT: Investigate abort parameter
}
}
break;
}
}
|
2301_81045437/classic-platform
|
communication/SD/src/SD_ServerService.c
|
C
|
unknown
| 38,676
|
#SecOC
obj-$(USE_SECOC) += SecOC.o
obj-$(USE_SECOC) += SecOC_Cfg.o
inc-$(USE_SECOC) += $(ROOTDIR)/communication/SecOC/inc
vpath-$(USE_SECOC) += $(ROOTDIR)/communication/SecOC/src
|
2301_81045437/classic-platform
|
communication/SecOC/SecOC.mod.mk
|
Makefile
|
unknown
| 184
|
/*-------------------------------- Arctic Core ------------------------------
* Copyright (C) 2013, ArcCore AB, Sweden, www.arccore.com.
* Contact: <contact@arccore.com>
*
* You may ONLY use this file:
* 1)if you have a valid commercial ArcCore license and then in accordance with
* the terms contained in the written license agreement between you and ArcCore,
* or alternatively
* 2)if you follow the terms found in GNU General Public License version 2 as
* published by the Free Software Foundation and appearing in the file
* LICENSE.GPL included in the packaging of this file or here
* <http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt>
*-------------------------------- Arctic Core -----------------------------*/
/** @reqSettings DEFAULT_SPECIFICATION_REVISION=4.1.2 */
/** @tagSettings DEFAULT_ARCHITECTURE=GENERIC */
/* @req SWS_SecOC_00001 General SecOC module definitions shall be defined in SecOC.h */
/* @req SWS_SecOC_00137*/
#ifndef SECOC_H_
#define SECOC_H_
#include "SecOC_Cfg.h"
#define SECOC_MODULE_ID 150u
#define SECOC_VENDOR_ID 60u
#define SECOC_SW_MAJOR_VERSION 1u
#define SECOC_SW_MINOR_VERSION 0u
#define SECOC_SW_PATCH_VERSION 0u
#define SECOC_AR_MAJOR_VERSION 4u
#define SECOC_AR_MINOR_VERSION 2u
#define SECOC_AR_PATCH_VERSION 1u
/* @req SWS_SecOC_00101 */
#if (SecOCDevErrorDetect == STD_ON)
#define SECOC_E_PARAM_POINTER 0x01u
#define SECOC_E_INVALID_REQUEST 0x02u
#define SECOC_E_INVALID_PDU_SDU_ID 0x03u
#define SECOC_E_CRYPTO_FAILURE 0x04u
#define SECOC_E_RESTORE_FAILURE 0x05u
#define SECOC_E_FRESHNESS_VALUE_AT_LIMIT 0x06u
#define SECOC_E_UNINIT 0x20u
#endif
/*
* Service IDs for SecOC function definitions.
*/
#define SERVICE_ID_SECOC_INIT 0x01u
#define SERVICE_ID_SECOC_DEINIT 0x05u
#define SERVICE_ID_SECOC_GET_VERSION_INFO 0x02u
#define SERVICE_ID_SECOC_TRANSMIT 0x03u
#define SERVICE_ID_SECOC_CANCEL_TRANSMIT 0x04u
#define SERVICE_ID_SECOC_ASSOCIATE_KEY 0x07u
#define SERVICE_ID_SECOC_FRESHNESS_VALUE_READ 0x08u
#define SERVICE_ID_SECOC_FRESHNESS_VALUE_WRITE 0x09u
#define SERVICE_ID_SECOC_VERIFY_STATUS_OVERRIDE 0x0bu
#define SERVICE_ID_SECOC_RX_INDICATION 0x42u
#define SERVICE_ID_SECOC_TP_RX_INDICATION 0x45u
#define SERVICE_ID_SECOC_TX_CONFIRMATION 0x40u
#define SERVICE_ID_SECOC_TP_TX_CONFIRMATION 0x48u
#define SERVICE_ID_SECOC_TRIGGER_TRANSMIT 0x41u
#define SERVICE_ID_SECOC_COPY_RX_DATA 0x44u
#define SERVICE_ID_SECOC_COPY_TX_DATA 0x43u
#define SERVICE_ID_SECOC_START_OF_RECEPTION 0x46u
#define SERVICE_ID_SECOC_MAIN_FUNCTION 0x06u
/**
* Initialize the SecOC module
* @param config Pointer to selected configuration structure
*/
/* @req SWS_SecOC_00106 SecOC_Init */
void SecOC_Init( const SecOC_ConfigType* config);
/**
* Stop the SecOC service, empties the vbuffers and set state to SecOC_UNINIT
*/
/* @req SWS_SecOC_00161 SecOC_DeInit */
void SecOC_DeInit( void );
/**
* Return the version information for SecOC
* @param versioninfo pointer to where the version information is to be stored
*/
/* @req SWS_SecOC_00107 SecOC_GetVersionInfo */
void SecOC_GetVersionInfo( Std_VersionInfoType* versioninfo );
/* @req SWS_SecOC_00122*/
//Std_ReturnType SecOC_VerifyStatusOverride(uint16 freshnessValueID, uint8 overrideStatus, uint8 numberOfMessagesToOverride);
/* @req SWS_SecOC_00116*/
Std_ReturnType SecOC_AssociateKey(uint8 keyID, const SecOC_KeyType* keyPtr);
/* @req SWS_SecOC_00117*/
//Std_ReturnType SecOC_FreshnessValueRead(uint16 freshnessValueID, uint64* counterValue);
/* @req SWS_SecOC_00118*/
//Std_ReturnType SecOC_FreshnessValueWrite(uint16 freshnessValueID, uint64 counterValue);
Std_ReturnType SecOC_Transmit( PduIdType id, const PduInfoType* info );
Std_ReturnType SecOC_CancelTransmit( PduIdType id );
void SecOC_RxIndication( PduIdType RxPduId, const PduInfoType* PduInfoPtr );
void SecOC_TxConfirmation( PduIdType TxPduId ); //PduR
//void SecOC_TpRxIndication( PduIdType id, Std_ReturnType result );
//void SecOC_TpTxConfirmation( PduIdType id, Std_ReturnType result );
//Std_ReturnType SecOC_TriggerTransmit( PduIdType TxPduId, PduInfoType* PduInfoPtr );
//BufReq_ReturnType SecOC_CopyRxData( PduIdType id, const PduInfoType* info, PduLengthType* bufferSizePtr );
//BufReq_ReturnType SecOC_CopyTxData( PduIdType id, const PduInfoType* info, RetryInfoType* retry, PduLengthType* availableDataPtr );
//BufReq_ReturnType SecOC_StartOfReception( PduIdType id, const PduInfoType* info, PduLengthType TpSduLength, PduLengthType* bufferSizePtr );
/**
* Main function of SecOC, performs authentication and verification of packets.
*/
/* @req SWS_SecOC_00131 SecOC_MainFunction */
void SecOC_MainFunction( void );
#endif /* SECOC_H_ */
|
2301_81045437/classic-platform
|
communication/SecOC/inc/SecOC.h
|
C
|
unknown
| 5,088
|
/*-------------------------------- Arctic Core ------------------------------
* Copyright (C) 2013, ArcCore AB, Sweden, www.arccore.com.
* Contact: <contact@arccore.com>
*
* You may ONLY use this file:
* 1)if you have a valid commercial ArcCore license and then in accordance with
* the terms contained in the written license agreement between you and ArcCore,
* or alternatively
* 2)if you follow the terms found in GNU General Public License version 2 as
* published by the Free Software Foundation and appearing in the file
* LICENSE.GPL included in the packaging of this file or here
* <http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt>
*-------------------------------- Arctic Core -----------------------------*/
/** @reqSettings DEFAULT_SPECIFICATION_REVISION=4.1.2 */
/** @tagSettings DEFAULT_ARCHITECTURE=GENERIC */
#ifndef SECOC_CBK_H_
#define SECOC_CBK_H_
/* @req SWS_SecOC_00125 */
void SecOC_TpRxIndication( PduIdType id, Std_ReturnType result );
/* @req SWS_SecOC_00152 */
void SecOC_TpTxConfirmation( PduIdType id, Std_ReturnType result );
/* !req SWS_SecOC_00127 */
Std_ReturnType SecOC_TriggerTransmit( PduIdType TxPduId, PduInfoType* PduInfoPtr );
/* @req SWS_SecOC_00128 */
BufReq_ReturnType SecOC_CopyRxData( PduIdType id, const PduInfoType* info, PduLengthType* bufferSizePtr );
/* @req SWS_SecOC_00129 */
BufReq_ReturnType SecOC_CopyTxData( PduIdType id, const PduInfoType* info, RetryInfoType* retry, PduLengthType* availableDataPtr );
/* @req SWS_SecOC_00130 */
BufReq_ReturnType SecOC_StartOfReception( PduIdType id, const PduInfoType* info, PduLengthType TpSduLength, PduLengthType* bufferSizePtr );
#endif /* SECOC_CBK_H_ */
|
2301_81045437/classic-platform
|
communication/SecOC/inc/SecOC_Cbk.h
|
C
|
unknown
| 1,720
|
/*-------------------------------- Arctic Core ------------------------------
* Copyright (C) 2013, ArcCore AB, Sweden, www.arccore.com.
* Contact: <contact@arccore.com>
*
* You may ONLY use this file:
* 1)if you have a valid commercial ArcCore license and then in accordance with
* the terms contained in the written license agreement between you and ArcCore,
* or alternatively
* 2)if you follow the terms found in GNU General Public License version 2 as
* published by the Free Software Foundation and appearing in the file
* LICENSE.GPL included in the packaging of this file or here
* <http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt>
*-------------------------------- Arctic Core -----------------------------*/
/** @reqSettings DEFAULT_SPECIFICATION_REVISION=4.1.2 */
/** @tagSettings DEFAULT_ARCHITECTURE=GENERIC */
/* @req SWS_SecOC_00002 Type definitions of the SecOC module shall be defined in SecOC_Types.h */
/* @req SWS_SecOC_00103 */
#ifndef SECOC_TYPES_H_
#define SECOC_TYPES_H_
#include "ComStack_Types.h"
typedef struct {
uint16 SecOCRxSecuredLayerPduId;
void *SecOCRxSecuredLayerPduRef;
} SecOCRxSecuredPduLayerType;
typedef struct {
uint16 SecOCRxAuthenticLayerPduId;
void *SecOCRxAuthenticLayerPduRef;
} SecOCRxAuthenticPduLayerType;
typedef struct {
uint16 SecOCTxSecuredLayerPduId;
void *SecOCTxSecuredLayerPduRef;
} SecOCTxSecuredPduLayerType;
typedef struct {
uint16 SecOCTxAuthenticLayerPduId;
void *SecOCTxAuthenticLayerPduRef;
} SecOCTxAuthenticPduLayerType;
typedef struct {
uint32 SecOCFreshnessTimestampTimePeriodFactor;
uint16 SecOCAuthInfoRxLength;
uint16 SecOCPduRPduId;
uint16 SecOCDataId;
uint16 SecOCFreshnessCounterSyncAttempts;
uint16 SecOCFreshnessValueId;
uint16 SecOCKeyId;
uint8 SecOCFreshnessValueLength;
uint8 SecOCFreshnessValueRxLength;
float SecOCRxAcceptanceWindow;
/*
uint16 SecOCSecondaryFreshnessValueId;
boolean SecoCUseFreshnessTimestamp;
SecOC_VerificationStatusPropType SecOCVerificationStatusPropagationMode;
void *SecOCRxAuthServiceConfigRef;
void *SecOCSameBufferPduRef;
SecOCRxSecuredPduLayerType SecOCRxSecuredPduLayer;
SecOCRxAuthenticPduLayerType SecOCRxAuthenticPduLayer;
*/
} SecOCRxPduProcessingType;
typedef struct {
uint32 SecOCFreshnessTimestampTimePeriodFactor;
uint16 SecOCPduRPduId;
uint16 SecOCAuthInfoTxLength;
uint16 SecOCAuthenticationRetries;
uint16 SecOCDataId;
uint16 SecOCFreshnessValueId;
uint16 SecOCKeyId;
uint8 SecOCFreshnessValueLength;
uint8 SecOCFreshnessValueTxLength;
boolean SecOCUseFreshnessTimestamp;
/*
void *SecOCTxAuthServiceConfigRef;
void *SecOCSameBufferPduRef;
SecOCTxSecuredPduLayerType SecOCTxSecuredPduLayer;
SecOCTxAuthenticPduLayerType SecOCTxAuthenticPduLayer;
*/
} SecOCTxPduProcessingType;
/* @req SWS_SecOC_00104 */
typedef struct {
uint8 cfgId;
const SecOCTxPduProcessingType* SecOCTxPduProcessing;
const SecOCRxPduProcessingType* SecOCRxPduProcessing;
} SecOC_ConfigType;
/* @req SWS_SecOC_00162 */
typedef enum {
SECOC_UNINIT = 0,
SECOC_INIT = 1
} SecOC_StateType;
/* @req SWS_SecOC_00149 SecOC_VerificationResultType */
typedef enum {
SECOC_VERIFICATIONSUCCESS = 0,
SECOC_VERIFICATIONFAILURE = 1,
SECOC_FRESHNESSFAILURE = 2
} SecOC_VerificationResultType;
/* @req SWS_SecOC_00160 VerificationStatusType */
typedef struct {
uint16 freshnessValueID;
SecOC_VerificationResultType verificationStatus;
} SecOC_VerificationStatusType;
/* @req SWS_SecOC_00146 Separate buffers for the Authentic I-PD*U and the Secured I-PDU */
typedef struct {
PduIdType pduId;
PduInfoType pduInfo;
} AuthenticIPDU_BufType;
typedef struct {
uint16 length;
uint16 secOCDataId;
uint16 freshnessValueID;
PduIdType pduId;
AuthenticIPDU_BufType authenticIPDU;
uint8 auth[32];
} SecuredIPDU_BufType;
#endif /* SECOC_TYPES_H_ */
|
2301_81045437/classic-platform
|
communication/SecOC/inc/SecOC_Types.h
|
C
|
unknown
| 4,161
|
/*-------------------------------- Arctic Core ------------------------------
* Copyright (C) 2013, ArcCore AB, Sweden, www.arccore.com.
* Contact: <contact@arccore.com>
*
* You may ONLY use this file:
* 1)if you have a valid commercial ArcCore license and then in accordance with
* the terms contained in the written license agreement between you and ArcCore,
* or alternatively
* 2)if you follow the terms found in GNU General Public License version 2 as
* published by the Free Software Foundation and appearing in the file
* LICENSE.GPL included in the packaging of this file or here
* <http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt>
*-------------------------------- Arctic Core -----------------------------*/
/** @reqSettings DEFAULT_SPECIFICATION_REVISION=4.1.2 */
/** @tagSettings DEFAULT_ARCHITECTURE=GENERIC */
#include "Std_Types.h"
/* @req SWS_SecOC_00153 SecOC module shall be implemented so that no other module depend on it */
#include "SecOC.h"
#include "SecOC_Cbk.h"
#include "PduR_SecOC.h"
#include <string.h>
#include "Cal.h"
#include "SecOC_Types.h"
//lint -save -e715 -e818
#if (SecOCDevErrorDetect == STD_ON)
#include "Det.h"
#define DET_REPORTERROR(_api, _error) \
do { \
(void)Det_ReportError(SECOC_MODULE_ID, 0, _api, _error); \
} while(false)
#else
#define DET_REPORTERROR(_api, _error)
#endif
typedef struct {
uint32 msgSize;
uint8 Authenticator[32];
uint8 DataToAuthenticator[32];
} VerifyType;
typedef struct {
uint8 Authenticator[32];
uint8 DataToAuthenticator[64];
} AuthType;
/**
* Function prototypes
*/
static Std_ReturnType verifyIPDU(VerifyType data);
static Std_ReturnType authenticateIPDU(uint16 keyId, const uint8 *data, uint16 length, uint8 *result, uint32 *resultLength);
static void freeSecuredIPDUBuffers(uint8 pos);
static void authLoop(void);
static void verifyLoop(void);
/**
* Global variables
*/
SecOC_KeyType keyList[16];
//local variables
const SecOC_ConfigType* secOc_Config;
SecOC_StateType state = SECOC_UNINIT;
SecuredIPDU_BufType securedPduBuffer[64]; /* should be 32 */
uint8 securedPos = 0;
AuthenticIPDU_BufType authenticPduBuffer[64]; /* should be 32 */
uint8 authenticPos = 0;
static void freeSecuredIPDUBuffers(uint8 pos) {
securedPduBuffer[pos].freshnessValueID = 0;
securedPduBuffer[pos].length = 0;
securedPduBuffer[pos].pduId = 0;
}
static Std_ReturnType verifyIPDU(VerifyType data) {
Cal_ConfigIdType cfgId = 0;
Cal_MacVerifyCtxBufType ctxBuffer;
Cal_VerifyResultType result = CAL_E_VER_OK;
Std_ReturnType status;
status = E_NOT_OK;
Cal_SymKeyType key;
key.length = 20;
Cal_AlignType keyData[] = { 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b };
memcpy(key.data, keyData, sizeof(keyData));
uint32 MacLength = 32;
uint32 msgSize = data.msgSize;
if (Cal_MacVerifyStart(cfgId, ctxBuffer, &key) != CAL_E_OK) {
status = E_NOT_OK;
}
else if (Cal_MacVerifyUpdate(cfgId, ctxBuffer, data.DataToAuthenticator, msgSize) != CAL_E_OK) {
status = E_NOT_OK;
}
else if( (Cal_MacVerifyFinish(cfgId, ctxBuffer, data.Authenticator, MacLength, &result) == CAL_E_OK) && (result == CAL_E_VER_OK)) {
status = E_OK;
} else {
status = E_NOT_OK;
}
return status;
}
static Std_ReturnType authenticateIPDU(uint16 keyId, const uint8 *data, uint16 length, uint8 *result, uint32 *resultLength) {
Cal_ReturnType retVal;
Cal_ConfigIdType cfgId = 0;
Cal_MacVerifyCtxBufType ctxBuffer;
Std_ReturnType status;
status = E_OK;
Cal_SymKeyType key;
key.length = keyList[keyId].length;
memcpy(key.data, keyList[keyId].data, key.length);
retVal = Cal_MacGenerateStart(cfgId, ctxBuffer, &key);
if (retVal != CAL_E_OK) {
status = E_NOT_OK;
} else {
retVal = Cal_MacGenerateUpdate(cfgId, ctxBuffer, data, length);
if (retVal != CAL_E_OK ) {
status = E_NOT_OK;
} else {
retVal = Cal_MacGenerateFinish(cfgId, ctxBuffer, result, resultLength, TRUE);
if (retVal != CAL_E_OK) {
status = E_NOT_OK;
}
}
}
return status;
}
/* @req SWS_SecOC_00031 Creation of secured I-PDU should follow the six steps described in spec */
/* @req SWS_SecOC_00033 */
/* @req SWS_SecOC_00034 */
/* @req SWS_SecOC_00035 */
/* @req SWS_SecOC_00062 SecOC shall provide complete Secured I-PDU for further transmission by triggering PduR_SecOCTransmit*/
/* @req SWS_SecOC_00110 The buffer that contains the Authentic I-PDU shall not overwrite Secured I-PDU*/
/* @req SWS_SecOC_00057 SecOC shall provide sufficient buffer capacities to store the Authentic I-PDU*/
/* @req SWS_SecOC_00108 SecOC shall return E_NOT_OK if the transmission of Authentic I-PDU is not able to serve*/
static void authLoop(void) {
AuthType dataToAuthenticator;
PduInfoType pduInfo;
//empty all the buffers
memset(dataToAuthenticator.DataToAuthenticator, 0, sizeof(dataToAuthenticator.DataToAuthenticator));
memset(dataToAuthenticator.Authenticator, 0, sizeof(dataToAuthenticator.Authenticator));
pduInfo.SduDataPtr = dataToAuthenticator.DataToAuthenticator;
pduInfo.SduLength = 0;
// Loop through the PDUs in the buffer
for(uint8 i = 0; i < authenticPos; i++) {
// SecOCDataId | AuthenticIPDU | FreshnessVerifyValue
uint32 resLength = 32;
memcpy(&dataToAuthenticator.DataToAuthenticator[0],
&secOc_Config->SecOCTxPduProcessing[authenticPduBuffer[i].pduId].SecOCDataId,
sizeof(secOc_Config->SecOCTxPduProcessing[authenticPduBuffer[i].pduId].SecOCDataId)); // SecOCDataId
memcpy(&dataToAuthenticator.DataToAuthenticator[sizeof(secOc_Config->SecOCTxPduProcessing[authenticPduBuffer[i].pduId].SecOCDataId)],
authenticPduBuffer[i].pduInfo.SduDataPtr,
authenticPduBuffer[i].pduInfo.SduLength);
Std_ReturnType res;
res = authenticateIPDU(secOc_Config->SecOCTxPduProcessing[authenticPduBuffer[i].pduId].SecOCKeyId,
dataToAuthenticator.DataToAuthenticator,
authenticPduBuffer[i].pduInfo.SduLength + sizeof(secOc_Config->SecOCTxPduProcessing[authenticPduBuffer[i].pduId].SecOCDataId),
dataToAuthenticator.Authenticator,
&resLength);
if (res == E_OK) {
// Add Auth and Freshness to PDU
memcpy(&dataToAuthenticator.DataToAuthenticator[0], authenticPduBuffer[i].pduInfo.SduDataPtr, authenticPduBuffer[i].pduInfo.SduLength);
//dataToAuthenticator.DataToAuthenticator[authenticPduBuffer[i].pduInfo.SduLength] = 1;
memcpy(&dataToAuthenticator.DataToAuthenticator[authenticPduBuffer[i].pduInfo.SduLength], dataToAuthenticator.Authenticator, sizeof(dataToAuthenticator.Authenticator));
pduInfo.SduLength = authenticPduBuffer[i].pduInfo.SduLength + 32;
pduInfo.SduDataPtr = dataToAuthenticator.DataToAuthenticator;
if(PduR_SecOCTransmit(secOc_Config->SecOCTxPduProcessing[authenticPduBuffer[i].pduId].SecOCPduRPduId, &pduInfo) == E_NOT_OK)
{
// IMPROVEMENT: Set det error?
}
}
}
authenticPos = 0;
}
/* @req SWS_SecOC_00040 */
/* @req SWS_SecOC_00046 */
/* @req SWS_SecOC_00047 SecOCUseFreshnessTimestamp set to FALSE, SecOC shall verify the Authenticator by passing DataToAuthenticator*/
/* @req SWS_SecOC_00111 Secured I-PDU shall not overwrite Authentic I-PDU buffer */
/* @req SWS_SecOC_00057 SecOC should provide sufficient buffer capacities to store Secured I-PDU*/
/* @req SWS_SecOC_00109 SecOC shall return E_NOT_OK if the transmission of Secured I-PDU is not able to serve*/
static void verifyLoop(void) {
boolean status;
status = TRUE;
VerifyType dataToAuthenticator;
uint8 attempts = 0;
//FreshnessVerifyValueId = 0;
//SecOC_VerificationResultType verificationResult;
//extern const SecOCRxPduProcessingType SecOCRxPduProcessing[ ];
//reset buffer
memset(dataToAuthenticator.DataToAuthenticator, 0, sizeof(dataToAuthenticator.DataToAuthenticator));
memset(dataToAuthenticator.Authenticator, 0, sizeof(dataToAuthenticator.Authenticator));
//loop through incoming Secured I-PDU from lower layer
for(uint8 i = 0; i < securedPos ; i++) {
attempts = 0;
//repeat
while (attempts <= (secOc_Config->SecOCRxPduProcessing[securedPduBuffer[i].pduId].SecOCFreshnessCounterSyncAttempts) ) {
//The SecOC module copies the Secured I-PDU into its own memory.
//dataToAuthenticator.DataToAuthenticator[0] = securedPduBuffer[i].pduId;
memcpy(&dataToAuthenticator.DataToAuthenticator[0],
&secOc_Config->SecOCRxPduProcessing[securedPduBuffer[i].pduId].SecOCDataId,
sizeof(secOc_Config->SecOCRxPduProcessing[securedPduBuffer[i].pduId].SecOCDataId)); // SecOCDataId
dataToAuthenticator.msgSize = securedPduBuffer[i].authenticIPDU.pduInfo.SduLength +
sizeof(secOc_Config->SecOCRxPduProcessing[securedPduBuffer[i].pduId].SecOCDataId);
//Copy message to DataToAuthenticator
memcpy(&dataToAuthenticator.DataToAuthenticator[sizeof(secOc_Config->SecOCRxPduProcessing[securedPduBuffer[i].pduId].SecOCDataId)],
securedPduBuffer[i].authenticIPDU.pduInfo.SduDataPtr,
securedPduBuffer[i].authenticIPDU.pduInfo.SduLength);
//copy MAC value to Authenticator
memcpy(dataToAuthenticator.Authenticator, securedPduBuffer[i].auth, 32);
//verify the contents of the Secured I-PDU
Std_ReturnType verifyResult = verifyIPDU(dataToAuthenticator);
//If ver success, call PduR_SecOCRxIndication
if(verifyResult == E_OK){
/* @req SWS_SecOC_00050 Pass the Authentic I-PDU to the upper layer using the lower layer interfaces of the PduR*/
//SecOCRxPduProcessing[0].SecOCFreshnessValueId = FreshnessVerifyValueId;
/* @req SWS_SecOC_00080 Call PduR_SecOCRxIndication referencing the Authentic I-PDU in the Secured I-PDU*/
PduR_SecOCRxIndication(secOc_Config->SecOCRxPduProcessing[securedPduBuffer[i].pduId].SecOCPduRPduId,
&securedPduBuffer[i].authenticIPDU.pduInfo);
/* @req SWS_SecOC_00087 free all the buffers related to a Secured I-PDU if authenticated I-PDU has passed via PduR_SecOCRxIndication */
freeSecuredIPDUBuffers(i);
//verificationResult = SECOC_VERIFICATIONSUCCESS;
securedPos = 0;
status = FALSE;
break;
} else if((verifyResult == E_NOT_OK) && (attempts >= secOc_Config->SecOCRxPduProcessing[securedPduBuffer[i].pduId].SecOCFreshnessCounterSyncAttempts)){ //If ver fail, drop the message
/* @req SWS_SecOC_00087 free all the buffers related to a Secured I-PDU if verification failed*/
freeSecuredIPDUBuffers(i);
//verificationResult = SECOC_VERIFICATIONFAILURE;
/*lint -e{9011} break is required to terminate loop */
break;
} else if((verifyResult == E_NOT_OK) && (attempts < secOc_Config->SecOCRxPduProcessing[securedPduBuffer[i].pduId].SecOCFreshnessCounterSyncAttempts)){
attempts++;
//verificationResult = SECOC_VERIFICATIONFAILURE; //ska ej va här
//re-attempt Authentication
//break;
} else {}
}
}
if (status == TRUE) {
securedPos = 0;
}
}
/* @req SWS_SecOC_00054 SecOC_Init shall initialize all internal global variables and the buffers of the SecOC I-PDUs */
/* @req SWS_SecOC_00106 SecOC_Init */
void SecOC_Init( const SecOC_ConfigType* config ) {
secOc_Config = config;
authenticPos = 0;
securedPos = 0;
// Set state to Initialized
state = SECOC_INIT;
}
/* @req SWS_SecOC_00156 SecOC_DeInit shall store all Freshness Values and all key information to NVRAM */
/* @req SWS_SecOC_00157 SecOC_DeInit shall clear all internal global variables and the buffers */
/* @req SWS_SecOC_00161 SecOC_DeInit */
void SecOC_DeInit( void ) {
//clear the buffers
memset(securedPduBuffer[0].authenticIPDU.pduInfo.SduDataPtr, 0, securedPduBuffer[0].authenticIPDU.pduInfo.SduLength);
authenticPduBuffer[0].pduId = 0;
//authenticPduBuffer[0].pduInfo = 0;
//store all Freshness Values and all key to NVRAM
//NvM_ReadBlock( NvM_BlockIdType blockId, void *dstPtr ) ;
//SecOC_Config = NULL;
//NvM_ReadBlock( NvM_BlockIdType blockId, void *dstPtr );
//NvM_WriteBlock( NvM_BlockIdType blockId, void *srcPtr );
//NvM_GetErrorStatus( NvM_BlockIdType blockId, NvM_RequestResultType *requestResultPtr);
//Set state to Uninitialized
state = SECOC_UNINIT;
}
/* @req SWS_SecOC_00107 SecOC_GetVersionInfo */
void SecOC_GetVersionInfo( Std_VersionInfoType* versioninfo ) {
//check the version
versioninfo->sw_major_version = SECOC_SW_MAJOR_VERSION;
versioninfo->sw_minor_version = SECOC_SW_MINOR_VERSION;
versioninfo->sw_patch_version = SECOC_SW_PATCH_VERSION;
versioninfo->moduleID = SECOC_MODULE_ID;
}
/* @req SWS_SecOC_00112 SecOC_Transmit */
Std_ReturnType SecOC_Transmit( PduIdType id, const PduInfoType* info ) {
if (state == SECOC_UNINIT) {
DET_REPORTERROR(SERVICE_ID_SECOC_TRANSMIT, SECOC_E_UNINIT);
/*lint -e{904} Return statement is necessary in case of reporting a DET error */
return E_NOT_OK;
}
if (id >= SECOC_NBR_OF_TXPDUS) {
DET_REPORTERROR(SERVICE_ID_SECOC_TRANSMIT, SECOC_E_INVALID_PDU_SDU_ID);
/*lint -e{904} ARGUMENT CHECK */
return E_NOT_OK;
}
if( (info == NULL) || (authenticPos > 31)) {
/*lint -e{904} Return statement is necessary to avoid multiple if loops and hence increase readability in case of argument check */
return E_NOT_OK;
}
authenticPduBuffer[authenticPos].pduInfo = *info;
authenticPduBuffer[authenticPos].pduId = id;
authenticPos++;
return E_OK;
}
/* @req SWS_SecOC_00113 SecOC_CancelTransmit */
Std_ReturnType SecOC_CancelTransmit( PduIdType id )
{
Std_ReturnType status;
//check if id exist or if function request failed
if((PduR_SecOCCancelTransmit(id) == E_OK)){
status = E_OK;
} else {
status = E_NOT_OK;
}
return status;
}
/* @req SWS_SecOC_00116 SecOC_AssociateKey */
Std_ReturnType SecOC_AssociateKey(uint8 keyID, const SecOC_KeyType* keyPtr) {
Std_ReturnType status;
if (keyID < (sizeof(keyList) / sizeof(keyList[0]))) {
keyList[keyID] = *keyPtr;
status = E_OK;
} else {
status = E_NOT_OK;
}
return status;
}
#if 0
//defined in specification but not supported in this module
Std_ReturnType SecOC_FreshnessValueRead( uint16 freshnessValueID, uint64* counterValue ) {
//overwrite the counter value freshnessValueID with Secondary FreshnessValueID
//freshnessValueID = secondaryFreshnessID
//*counterValue = 1;
return E_OK;
}
#endif
#if 0
//defined in specification but not supported in this module
Std_ReturnType SecOC_FreshnessValueWrite( uint16 freshnessValueID, uint64 counterValue )
{
//overwrite the counter value freshnessValueID with Secondary FreshnessValueID
//freshnessValueID = secondaryFreshnessID
return E_OK;
}
#endif
#if 0
//defined in specification but not supported in this module
Std_ReturnType SecOC_VerifyStatusOverride( uint16 freshnessValueID, uint8 overrideStatus, uint8 numberOfMessagesToOverride ) {
return 0;
}
#endif
/* @req SWS_SecOC_00042 */
/* @req SWS_SecOC_00124 SecOc_RxIndication */
/* @req SWS_SecOC_00078 Copy the complete Secured I-PDU into its own buffer after it returns from SecOc_RxIndication */
void SecOC_RxIndication( PduIdType RxPduId, const PduInfoType* PduInfoPtr )
{
if( (PduInfoPtr == NULL) || (securedPos > 31)) {
/*lint -e{904} Return statement is necessary to avoid multiple if loops and hence increase readability in case of argument check */
return;
}
/* Put secured PDU is buffer */
securedPduBuffer[securedPos].authenticIPDU.pduInfo.SduLength = PduInfoPtr->SduLength - 32;
securedPduBuffer[securedPos].authenticIPDU.pduInfo.SduDataPtr = PduInfoPtr->SduDataPtr;
securedPduBuffer[securedPos].pduId = RxPduId;
memcpy(securedPduBuffer[securedPos].auth, &PduInfoPtr->SduDataPtr[PduInfoPtr->SduLength-32], 32);
securedPos++;
}
#if 0
//defined in specification but not supported in this module
void SecOC_TpRxIndication( PduIdType id, Std_ReturnType result ) {
// Copy the PDU to the buffer
}
#endif
/* @req SWS_SecOC_00126 SecOc_TxConfirmation */
void SecOC_TxConfirmation( PduIdType TxPduId )
{
PduR_SecOCTxConfirmation(TxPduId);
}
#if 0
//defined in specification but not supported in this module
void SecOC_TpTxConfirmation( PduIdType id, Std_ReturnType result ) {
}
#endif
/* !req SWS_SecOC_00068 SecOC_TriggerTransmit shall copy the Secured I-PDU to the lower layer destination module */
/* !req SWS_SecOC_00127 SecOc_TriggerTransmit */
/* !req SWS_SecOC_00150 When no secured I-PDU is avalible, return E_NOT_OK */
Std_ReturnType SecOC_TriggerTransmit( PduIdType TxPduId, PduInfoType* PduInfoPtr )
{
/* NOT IMPLEMENTED */
return E_NOT_OK;
}
#if 0
//defined in specification but not supported in this module
BufReq_ReturnType SecOC_CopyRxData( PduIdType id, const PduInfoType* info, PduLengthType* bufferSizePtr )
{
/**
if(info->SduLength == 0){
//SduDataPtr may be a NULL_PTR
info = NULL_PTR;
}
securedPduBuffer[0].length = info->SduLength;
securedPduBuffer[0].payload = info->SduDataPtr;
//remaining available buffer after copying
//bufferSizePtr = sizeof(securedPduBuffer)
**/
return BUFREQ_OK;
}
#endif
#if 0
//defined in specification but not supported in this module
BufReq_ReturnType SecOC_CopyTxData( PduIdType id, const PduInfoType* info, RetryInfoType* retry, PduLengthType* availableDataPtr )
{
/**
if(availableDataPtr == NULL){
return BUFREQ_E_BUSY;
}
if(info->SduLength == 0){
info = NULL_PTR;
}
if(retry == NULL_PTR){
//remove transmit data from buffer
}
authenticPduBuffer[0].pduId = id;
authenticPduBuffer[0].pduInfo.SduDataPtr = info->SduDataPtr;
authenticPduBuffer[0].pduInfo.SduLength = info->SduLength;
//remaining bytes in Authentic buffer
//availableDataPtr =
**/
return BUFREQ_OK;
}
#endif
#if 0
//defined in specification but not supported in this module
BufReq_ReturnType SecOC_StartOfReception( PduIdType id, const PduInfoType* info, PduLengthType TpSduLength, PduLengthType* bufferSizePtr ) {
return BUFREQ_OK;
}
#endif
/* @req SWS_SecOC_00131 SecOC_MainFunction */
/* @req SWS_SecOC_00132 If SecOC isnt initialized with SecOC_Init, then SecOC_MainFunction return */
/* @req SWS_SecOC_00133 The cycle time of SecOC_MainFunction is configured by the parameter SecOCMainFunctionPeriod */
/* @req SWS_SecOC_00134 If scheduled, SecOC shall check for new Authentic I-PDUs or Secured I-PDUs */
/* @req SWS_SecOC_00135 For each newly authenticated Authentic I-PDU, SecOC shall trigger the transmission of the Secured I-PDUby calling the PduR */
/* @req SWS_SecOC_00136 For each newly verified Secured I-PDU, SecOC shall pass the it along with PduR_SecOCRxIndication */
/* @req SWS_SecOC_00031 */
/* @req SWS_SecOC_00060 Calculate the Authenticator in the main function according to SWS_SecOC_00131*/
/* @req SWS_SecOC_00061 SecOC shall create the Secured I-PDU in the main function*/
/* @req SWS_SecOC_00079 The verification shall be processed in the scheduled main function*/
void SecOC_MainFunction( void ) {
if (state == SECOC_UNINIT) {
#if (SecOCDevErrorDetect == STD_ON)
Std_ReturnType Det_ReportError( uint16 ModuleId, uint8 InstanceId, uint8 ApiId, uint8 ErrorId);
DET_REPORTERROR(SERVICE_ID_SECOC_MAIN_FUNCTION, SECOC_E_UNINIT);
#endif
/*lint -e{904} Return statement is necessary in case of reporting a DET error */
return;
}
//Check if there are new Secured I-PDU
verifyLoop();
//Check if there are new Authentic I-PDU
authLoop();
}
//lint -restore
|
2301_81045437/classic-platform
|
communication/SecOC/src/SecOC.c
|
C
|
unknown
| 21,252
|
# SoAd
obj-$(USE_SOAD) += SoAd_Cfg.o
obj-$(USE_SOAD) += SoAd.o
inc-$(USE_SOAD) += $(ROOTDIR)/communication/SoAd/inc
vpath-$(USE_SOAD) += $(ROOTDIR)/communication/SoAd/src
|
2301_81045437/classic-platform
|
communication/SoAd/SoAd.mod.mk
|
Makefile
|
unknown
| 178
|
/*-------------------------------- Arctic Core ------------------------------
* Copyright (C) 2013, ArcCore AB, Sweden, www.arccore.com.
* Contact: <contact@arccore.com>
*
* You may ONLY use this file:
* 1)if you have a valid commercial ArcCore license and then in accordance with
* the terms contained in the written license agreement between you and ArcCore,
* or alternatively
* 2)if you follow the terms found in GNU General Public License version 2 as
* published by the Free Software Foundation and appearing in the file
* LICENSE.GPL included in the packaging of this file or here
* <http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt>
*-------------------------------- Arctic Core -----------------------------*/
/** @reqSettings DEFAULT_SPECIFICATION_REVISION=4.2.2 */
#ifndef SOAD_H
#define SOAD_H
#include "SoAd_Types.h"
#define SOAD_VENDOR_ID 60u
#define SOAD_AR_RELEASE_MAJOR_VERSION 4u
#define SOAD_AR_RELEASE_MINOR_VERSION 2u
#define SOAD_AR_RELEASE_REVISION_VERSION 2u
#define SOAD_MODULE_ID 56u
#define SOAD_AR_MAJOR_VERSION SOAD_AR_RELEASE_MAJOR_VERSION
#define SOAD_AR_MINOR_VERSION SOAD_AR_RELEASE_MINOR_VERSION
#define SOAD_AR_PATCH_VERSION SOAD_AR_RELEASE_REVISION_VERSION
#define SOAD_SW_MAJOR_VERSION 2u
#define SOAD_SW_MINOR_VERSION 0u
#define SOAD_SW_PATCH_VERSION 0u
/** @req SWS_SOAD_00101 */
#define SOAD_E_NOTINIT 0x01u
#define SOAD_E_PARAM_POINTER 0x02u
#define SOAD_E_INV_ARG 0x03u
#define SOAD_E_NOBUFS 0x04u
#define SOAD_E_INV_PDUHEADER_ID 0x05u
#define SOAD_E_INV_PDUID 0x06u
#define SOAD_E_INV_SOCKETID 0x07u
#define SOAD_E_INIT_FAILED 0x08u
// Service IDs in this module defined by Autosar
#define SOAD_INIT_ID 0x01u
#define SOAD_GET_VERSION_INFO_ID 0x02u
#define SOAD_IF_TRANSMIT_ID 0x03u
#define SOAD_TP_TRANSMIT_ID 0x04u
#define SOAD_TP_CANCEL_TRANSMIT_ID 0x05u
#define SOAD_TP_CANCEL_RECEIVE_ID 0x06u
#define SOAD_GET_SOCON_ID_ID 0x07u
#define SOAD_OPEN_SOCON_ID 0x08u
#define SOAD_CLOSE_SOCON_ID 0x09u
#define SOAD_REQUEST_IP_ADDR_ASSIGNMENT_ID 0x0Au
#define SOAD_RELEASE_IP_ADDR_ASSIGNMENT_ID 0x0Bu
#define SOAD_GET_LOCAL_ADDR_ID 0x0Cu
#define SOAD_GET_PHYS_ADDR_ID 0x0Du
#define SOAD_ENABLE_ROUTING_ID 0x0Eu
#define SOAD_DISABLE_ROUTING_ID 0x0Fu
#define SOAD_SET_REMOTE_ADDRESS_ID 0x10u
#define SOAD_TP_CHANGE_PARAMETER_ID 0x11u
#define SOAD_RX_INDICATION_ID 0x12u
#define SOAD_COPY_TX_DATA_ID 0x13u
#define SOAD_TX_CONFIRMATION_ID 0x14u
#define SOAD_TCP_ACCEPTED_ID 0x15u
#define SOAD_TCP_CONNECTED_ID 0x16u
#define SOAD_TCP_IP_EVENT 0x17u
#define SOAD_LOCAL_IP_ADDR_ASSIGNMENT_CHG_ID 0x18u
#define SOAD_MAIN_FUNCTION_ID 0x19u
#define SOAD_READ_DHCP_HOST_NAME_OPTION_ID 0x1Au
#define SOAD_WRITE_DHCP_HOST_NAME_OPTION_ID 0x1Bu
#define SOAD_GET_REMOTE_ADDR_ID 0x1Cu
#define SOAD_IF_ROUTING_GROUP_TRANSMIT_ID 0x1Du
#define SOAD_SET_UNIQUE_REMOTE_ADDR_ID 0x1Eu
#define SOAD_IF_SPECIFIC_ROUTING_GROUP_TRANSMIT_ID 0x1Fu
#define SOAD_ENABLE_SPECIFIC_ROUTING_ID 0x20u
#define SOAD_DISABLE_SPECIFIC_ROUTING_ID 0x21u
#define SOAD_PDU_HEADER_LENGTH 8
#include "SoAd_Cfg.h"
//----------------------------------------------------
void SoAd_Init( const SoAd_ConfigType* SoAdConfigPtr );
/** @req SWS_SOAD_00510 */
Std_ReturnType SoAd_OpenSoCon( SoAd_SoConIdType SoConId );
/** @req SWS_SOAD_00511 */
Std_ReturnType SoAd_CloseSoCon( SoAd_SoConIdType SoConId, boolean abort );
/** @req SWS_SOAD_00515 */
Std_ReturnType SoAd_SetRemoteAddr( SoAd_SoConIdType SoConId, const TcpIp_SockAddrType* RemoteAddrPtr );
/** @req SWS_SOAD_00121 */
void SoAd_MainFunction( void );
/** @req SWS_SOAD_00091 */
Std_ReturnType SoAd_IfTransmit( PduIdType SoAdSrcPduId, const PduInfoType* SoAdSrcPduInfoPtr );
/** @req SWS_SOAD_00655 */
Std_ReturnType SoAd_GetRemoteAddr( SoAd_SoConIdType SoConId, TcpIp_SockAddrType* IpAddrPtr );
#if ( SOAD_VERSION_INFO_API == STD_ON)
void SoAd_GetVersionInfo( Std_VersionInfoType* versioninfo );
#endif
/** @req SWS_SOAD_00656 */
Std_ReturnType SoAd_IfRoutingGroupTransmit( SoAd_RoutingGroupIdType id );
/** @req SWS_SOAD_00711 */
Std_ReturnType SoAd_IfSpecificRoutingGroupTransmit( SoAd_RoutingGroupIdType id, SoAd_SoConIdType SoConId );
/** @req SWS_SOAD_00105 */
Std_ReturnType SoAd_TpTransmit( PduIdType SoAdSrcPduId, const PduInfoType* SoAdSrcPduInfoPtr );
/** @req SWS_SOAD_00522 */
Std_ReturnType SoAd_TpCancelTransmit( PduIdType PduId );
/** @req SWS_SOAD_00521 */
Std_ReturnType SoAd_TpCancelReceive( PduIdType PduId );
/** @req SWS_SOAD_00509 */
Std_ReturnType SoAd_GetSoConId( PduIdType TxPduId, SoAd_SoConIdType* SoConIdPtr );
/** @req SWS_SOAD_00520 */
Std_ReturnType SoAd_RequestIpAddrAssignment( SoAd_SoConIdType SoConId, TcpIp_IpAddrAssignmentType Type, const TcpIp_SockAddrType* LocalIpAddrPtr, uint8 Netmask, const TcpIp_SockAddrType* DefaultRouterPtr );
/** @req SWS_SOAD_00536 */
Std_ReturnType SoAd_ReleaseIpAddrAssignment( SoAd_SoConIdType SoConId );
/** @req SWS_SOAD_00506 */
Std_ReturnType SoAd_GetLocalAddr( SoAd_SoConIdType SoConId, TcpIp_SockAddrType* LocalAddrPtr, uint8* NetmaskPtr, TcpIp_SockAddrType* DefaultRouterPtr );
/** @req SWS_SOAD_00507 */
Std_ReturnType SoAd_GetPhysAddr( SoAd_SoConIdType SoConId, uint8* PhysAddrPtr );
/** @req SWS_SOAD_00516 */
Std_ReturnType SoAd_EnableRouting( SoAd_RoutingGroupIdType id );
/** @req SWS_SOAD_00714 */
Std_ReturnType SoAd_EnableSpecificRouting( SoAd_RoutingGroupIdType id, SoAd_SoConIdType SoConId );
/** @req SWS_SOAD_00517 */
Std_ReturnType SoAd_DisableRouting( SoAd_RoutingGroupIdType id );
/** @req SWS_SOAD_00717 */
Std_ReturnType SoAd_DisableSpecificRouting( SoAd_RoutingGroupIdType id, SoAd_SoConIdType SoConId );
/** @req SWS_SOAD_00671 */
Std_ReturnType SoAd_SetUniqueRemoteAddr( SoAd_SoConIdType SoConId, const TcpIp_SockAddrType* RemoteAddrPtr, SoAd_SoConIdType* AssignedSoConIdPtr );
/** @req SWS_SOAD_00508 */
Std_ReturnType SoAd_TpChangeParameter( PduIdType id, TPParameterType parameter, uint16 value );
/** @req SWS_SOAD_00681 */
Std_ReturnType SoAd_ReadDhcpHostNameOption( SoAd_SoConIdType SoConId, uint8* length, uint8* data );
/** @req SWS_SOAD_00679 */
Std_ReturnType SoAd_WriteDhcpHostNameOption( SoAd_SoConIdType SoConId, uint8 length, const uint8* data );
/* ArcCore added */
Std_ReturnType SoAd_Arc_GetSoConIdFromRxPdu( PduIdType RxPduId, SoAd_SoConIdType* SoConIdPtr );
#if defined(HOST_TEST)
SoAd_SoConModeType SoAd_Arc_GetMode(SoAd_SoConIdType SoConId);
#endif
#endif
|
2301_81045437/classic-platform
|
communication/SoAd/inc/SoAd.h
|
C
|
unknown
| 6,749
|
/*-------------------------------- Arctic Core ------------------------------
* Copyright (C) 2013, ArcCore AB, Sweden, www.arccore.com.
* Contact: <contact@arccore.com>
*
* You may ONLY use this file:
* 1)if you have a valid commercial ArcCore license and then in accordance with
* the terms contained in the written license agreement between you and ArcCore,
* or alternatively
* 2)if you follow the terms found in GNU General Public License version 2 as
* published by the Free Software Foundation and appearing in the file
* LICENSE.GPL included in the packaging of this file or here
* <http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt>
*-------------------------------- Arctic Core -----------------------------*/
/** @reqSettings DEFAULT_SPECIFICATION_REVISION=4.2.2 */
#ifndef SOAD_CBK_H_
#define SOAD_CBK_H_
/** @req SWS_SOAD_00097 */
void SoAd_RxIndication( TcpIp_SocketIdType SocketId, const TcpIp_SockAddrType* RemoteAddrPtr, uint8* BufPtr, uint16 Length );
/** @req SWS_SOAD_00523 */
BufReq_ReturnType SoAd_CopyTxData( TcpIp_SocketIdType SocketId, uint8* BufPtr, uint16 BufLength );
/** @req SWS_SOAD_00098 */
void SoAd_TxConfirmation( TcpIp_SocketIdType SocketId, uint16 Length );
/** @req SWS_SOAD_00099 */
Std_ReturnType SoAd_TcpAccepted( TcpIp_SocketIdType SocketId, TcpIp_SocketIdType SocketIdConnected, const TcpIp_SockAddrType* RemoteAddrPtr );
/** @req SWS_SOAD_00100 */
void SoAd_TcpConnected( TcpIp_SocketIdType SocketId );
/** @req SWS_SOAD_00146 */
void SoAd_TcpIpEvent( TcpIp_SocketIdType SocketId, TcpIp_EventType Event );
/** @req SWS_SOAD_00209 */
void SoAd_LocalIpAddrAssignmentChg( TcpIp_LocalAddrIdType IpAddrId, TcpIp_IpAddrStateType State );
#endif /* SOAD_CBK_H_ */
|
2301_81045437/classic-platform
|
communication/SoAd/inc/SoAd_Cbk.h
|
C
|
unknown
| 1,767
|
/*-------------------------------- Arctic Core ------------------------------
* Copyright (C) 2013, ArcCore AB, Sweden, www.arccore.com.
* Contact: <contact@arccore.com>
*
* You may ONLY use this file:
* 1)if you have a valid commercial ArcCore license and then in accordance with
* the terms contained in the written license agreement between you and ArcCore,
* or alternatively
* 2)if you follow the terms found in GNU General Public License version 2 as
* published by the Free Software Foundation and appearing in the file
* LICENSE.GPL included in the packaging of this file or here
* <http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt>
*-------------------------------- Arctic Core -----------------------------*/
/** @reqSettings DEFAULT_SPECIFICATION_REVISION=4.2.2 */
#ifndef SOAD_TYPES_H
#define SOAD_TYPES_H
#include "TcpIp_Types.h"
/** @req SWS_SOAD_00512 */
typedef enum{
SOAD_SOCON_ONLINE,
SOAD_SOCON_RECONNECT,
SOAD_SOCON_OFFLINE
}SoAd_SoConModeType;
typedef enum {
SOAD_AF_INET = 0x02, // Use IPv4
SOAD_AF_INET6 = 0x1c // Use IPv6
} SoAd_DomainType;
typedef struct {
uint16 dummy;
} TcpIpLocalAddr;
// IMPROVEMENT: Where shall these enums be defined?
typedef enum{
SOAD_SOCKET_PROT_TCP,
SOAD_SOCKET_PROT_UDP
}SoAd_SocketProtocolType;
/** @req SWS_SOAD_00518 */
typedef uint16 SoAd_SoConIdType; // NOTE: Could be uint16 if SoAdSoConMax is > 256
/* 10.2.11 SoAdSocketRemoteAddress */
typedef struct{
boolean Set; // Does this Socket Connection have a Remote Address Set?
TcpIp_DomainType Domain;
uint8 SocketRemoteIpAddress[4];
uint16 SocketRemotePort;
} SoAd_SocketRemoteAddressType;
/* 10.2.16 SoAdRoutingGroup */
typedef struct{
uint16 RoutingGroupId;
boolean RoutingGroupIsEnabledAtInit;
boolean RoutingGroupTxTriggerable;
} SoAd_RoutingGroupType;
/* 10.2.7 SoAdSocketConnection */
typedef struct{
uint16 SocketId;
SoAd_SocketRemoteAddressType* SoAdSocketRemoteAddress;
uint8* nPduUdpTxBuffer;
uint32 nPduUdpTxBufferSize;
uint8* TcpRxBuffer;
uint32 TcpRxBufferSize;
uint32 GroupNr; // NOTE: Added to keep track of group belonging
uint32 IndexInGroup; // NOTE: Added to keep track of group belonging
}SoAd_SocketConnectionType;
/* 10.2.9 SoAdSocketUdp */
typedef struct{
uint32 UdpAliveSupervisionTimeout;
boolean SocketUdpListenOnly;
boolean SocketUdpStrictHeaderLenCheckEnabled;
uint32 SocketUdpTriggerTimeout;
}SoAd_SocketUdpType;
/* 10.2.10 SoAdSocketTcp */
typedef struct{
boolean SocketTcpImmediateTpTxConfirmation;
boolean SocketTcpInitiate;
boolean SocketTcpKeepAlive;
uint32 SocketTcpKeepAliveInterval;
uint16 SocketTcpKeepAliveProbesMax;
uint32 SocketTcpKeepAliveTime;
boolean SocketTcpNoDelay;
uint32 SocketTcpTxQuota;
}SoAd_SocketTcpType;
typedef enum{
SOAD_GROUPTYPE_LONELY_UDP, // UDP group with only one SoCon. Uses one TCP/IP socket connected to the SoCon
SOAD_GROUPTYPE_MULTI_UDP, // UDP group with multiple SoCons. Uses one TCP/IP socket connected to the SoCon group.
SOAD_GROUPTYPE_LISTEN_TCP, // TCP group with TcpInitiate==false. Uses one TCP/IP socket connected to the SoCon group to listen and then spawns new ones connected to the SoCons as connections are established.
SOAD_GROUPTYPE_INIT_TCP, // TCP group with TcpInitiate==true. Used one TCP/IP socket for each SoSon, connected to the SoCon. No TCP/IP socket connected to the SoCon group.
}SoAd_GroupTypeType;
/* 10.2.6 SoAdSocketConnectionGroup */
typedef struct {
boolean PduHeaderEnable;
boolean ResourceManagementEnable;
boolean SocketAutomaticSoConSetup;
boolean SocketFramePriorityUsed;
uint8 SocketFramePriority;
boolean SocketIpAddrAssignmentChgNotification;
void (*SocketIpAddrAssignmentChgNotificationFunction)(SoAd_SoConIdType SoConId, TcpIp_IpAddrStateType State);
uint16 SocketLocalPort;
boolean SocketMsgAcceptanceFilterEnabled;
boolean SocketSoConModeChgNotification;
void (*SocketSoConModeChgNotificationFunction)(SoAd_SoConIdType SoConId, SoAd_SoConModeType Mode);
uint16 SocketTpRxBufferMin;
uint8 SocketLocalAddressRef;
const SoAd_SocketConnectionType* SoAdSocketConnection;
const SoAd_SocketProtocolType SocketProtocol;
const SoAd_SocketUdpType* SocketProtocolUdp;
const SoAd_SocketTcpType* SocketProtocolTcp;
const SoAd_GroupTypeType GroupType;
uint16 NrOfSocketConnections; // NOTE: Added in implementation
} SoAd_SocketConnectionGroupType;
/** @req SWS_SOAD_00519 */
typedef uint8 SoAd_RoutingGroupIdType; // NOTE: Could be uint16 if SoAdRoutingGroupMax is > 256
/* Used to keep track of the state of sent PDUs */
typedef enum{
SOAD_TX_STATE_INACTIVE,
SOAD_TX_STATE_TCP_SENDING,
SOAD_TX_STATE_UDP_SENDING_DONE,
SOAD_TX_STATE_CONFIRMED,
}TxStateType;
//------------------ SoAd_ConfigTypes.h -----------------
typedef enum {
SOAD_BSW_MOD_REF_PDUR,
SOAD_BSW_MOD_REF_DOIP,
SOAD_BSW_MOD_REF_SD,
SOAD_BSW_MOD_REF_XCP,
SOAD_BSW_MOD_REF_UDPNM
}SoAd_BswModuleRefTypes;
/* 10.2.3 SoAdBswModules */
typedef struct{
boolean If;
boolean IfTriggerTransmit;
boolean IfTxConfirmation;
boolean LocalIpAddrAssigmentChg;
boolean SoConModeChg;
boolean Tp;
boolean UseCallerInfix;
boolean UseTypeInfix;
SoAd_BswModuleRefTypes BswModuleRefType; //NOTE How do we do this????
//HUMMMMMMM BswModuleRefName; //NOTE How do we do this????
}SoAd_BswModulesType;
typedef enum{
SOAD_RX_UPPER_LAYER_IF,
SOAD_RX_UPPER_LAYER_TP,
}SoAd_RxUpperLayerTypeType;
/* 10.2.13 SoAdSocketRouteDest */
typedef struct{
uint32 SocketRouteIndex;
PduIdType RxPduId;
SoAd_RxUpperLayerTypeType RxUpperLayerType;
PduIdType RxPduRef; //NOTE check this
const SoAd_RoutingGroupType** RxRoutingGroupRef;
void (*RxIndicationFunction)( PduIdType RxPduId, const PduInfoType* PduInfoPtr );
BufReq_ReturnType (*SoAdTpCopyRxData)( PduIdType id, const PduInfoType* info, PduLengthType* bufferSizePtr );//DoIP_SoAdTpCopyRxData
BufReq_ReturnType (*SoAdTpStartofReception)( PduIdType id, const PduInfoType* info, PduLengthType TpSduLength, PduLengthType* bufferSizePtr );//DoIP_SoAdTpStartOfReception
void (*TpRxIndicationFunction)( PduIdType RxPduId, Std_ReturnType result );
uint32 NrOfRoutingGroups;
}SoAd_SocketRouteDestType;
/* 10.2.12 SoAdSocketRoute */
typedef struct{
uint32 RxPduHeaderId;
boolean GroupUsed; // Is this SocketRoute referencing a group of connections?
uint16 Index; // Index to use in the SoCon array (SocketId) or SoCon Groups array.
const SoAd_SocketRouteDestType* SocketRouteDest;
}SoAd_SocketRouteType;
typedef enum{
SOAD_TRIGGER_ALWAYS,
SOAD_TRIGGER_NEVER
}SoAd_TxUdpTriggerModeType;
/* 10.2.15 SoAdPduRouteDest */
typedef struct{
uint32 TxPduHeaderId;
SoAd_TxUdpTriggerModeType TxUdpTriggerMode;
uint32 TxUdpTriggerTimeout;
const SoAd_RoutingGroupType** TxRoutingGroupRef;
boolean GroupUsed; // Is this PduRouteDest referencing a group of connections?
uint16 Index; // Index to use in the SoCon array (SocketId) or SoCon Groups array.
uint32 NrOfRoutingGroups;
}SoAd_PduRouteDestType;
/* 10.2.14 SoAdPduRoute */
typedef struct{
SoAd_RxUpperLayerTypeType TxUpperLayerType;
PduIdType TxPduRef;
const SoAd_PduRouteDestType* PduRouteDest;
void (*TxConfirmationFunction)( PduIdType TxPduId );
Std_ReturnType (*TriggerTransmitFunction)( PduIdType TxPduId, PduInfoType* PduInfoPtr );
void (*TpTxConfirmationFunction)( PduIdType TxPduId, Std_ReturnType result);
BufReq_ReturnType (*SoAdTpCopyTxData) (PduIdType id, PduInfoType* info, RetryInfoType* retry, PduLengthType* availableDataPtr);//DoIP_SoAdTpCopyTxData
const uint32 NrOfPduRouteDest;
}SoAd_PduRouteType;
/* 10.2.5 SoAdConfig */
/** @req SWS_SOAD_00210 */
typedef struct{
const SoAd_PduRouteType* PduRoute;
const SoAd_RoutingGroupType* RoutingGroup;
const SoAd_SocketConnectionGroupType* SocketConnectionGroup;
const SoAd_SocketRouteType* SocketRoute;
const uint32 NrOfSocketConnectionGroups;
}SoAd_ConfigType;
#endif
|
2301_81045437/classic-platform
|
communication/SoAd/inc/SoAd_Types.h
|
C
|
unknown
| 9,096
|
/*-------------------------------- Arctic Core ------------------------------
* Copyright (C) 2013, ArcCore AB, Sweden, www.arccore.com.
* Contact: <contact@arccore.com>
*
* You may ONLY use this file:
* 1)if you have a valid commercial ArcCore license and then in accordance with
* the terms contained in the written license agreement between you and ArcCore,
* or alternatively
* 2)if you follow the terms found in GNU General Public License version 2 as
* published by the Free Software Foundation and appearing in the file
* LICENSE.GPL included in the packaging of this file or here
* <http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt>
*-------------------------------- Arctic Core -----------------------------*/
/*lint -w2 */
/*lint -e534 */
/** @reqSettings DEFAULT_SPECIFICATION_REVISION=4.2.2 */
/** @req SWS_SOAD_00001 All configuration items shall be located outside the kernel of the module. */
/** @req SWS_SOAD_00093 SoAd_Init() */
/** @req SWS_SOAD_00096 SoAd_GetVersionInfo() */
/** @req SWS_SOAD_00106 <Up>_[SoAd][If]RxIndication() */
/** @req SWS_SOAD_00107 <Up>_[SoAd][If]TxConfirmation() */
/** @req SWS_SOAD_00505 The SoAd shall provide sufficient buffers for rx. */
/** @req SWS_SOAD_00599 The SoAd shall provide sufficient buffers for tx. */
/** @req SWS_SOAD_00513 <Up>_LocalIpAddrAssignmentChg() */
/** @req SWS_SOAD_00514 <Up>_SoConModeChg() */
/** @req SWS_SOAD_00538 Use SoAdBSWModules to determine upper layer function names */
/** @req SWS_SOAD_00663 <Up>_[SoAd][If]TriggerTransmit() */
/** @req SWS_SOAD_00503 */
#include "SoAd.h"
#include <string.h>
#include "cirq_buffer.h"
#include "ComStack_Types.h"
#include "Platform_Types.h"
#include "Std_Types.h"
#include "TcpIp.h"
#include "TcpIp_Types.h"
#include "SoAd_Cfg.h"
#include "SchM_SoAd.h"
#if defined(USE_DET) && (SOAD_DEV_ERROR_DETECT == STD_ON)
#include "Det.h"
#endif
#include "Os.h"
/* ----------------------------[private macro]-------------------------------*/
/*lint -emacro(904,VALIDATE_NO_RV,VALIDATE_RV)*/ /*904 PC-Lint exception to MISRA 14.7 (validate DET macros)*/
#if defined(USE_DET) && (SOAD_DEV_ERROR_DETECT == STD_ON)
#define VALIDATE_RV(_exp,_api,_err,_rv) \
if( !(_exp) ) { \
(void)Det_ReportError(SOAD_MODULE_ID,0,_api,_err); \
return _rv; \
}
#define VALIDATE(_exp,_api,_err ) \
VALIDATE_RV(_exp,_api,_err, (E_NOT_OK))
#define VALIDATE_NO_RV(_exp,_api,_err ) \
if( !(_exp) ) { \
(void)Det_ReportError(SOAD_MODULE_ID,0,_api,_err); \
return; \
}
#define DET_REPORTERROR(_x,_y,_z,_q) (void)Det_ReportError(_x, _y, _z, _q)
#else
#define VALIDATE_RV(_exp,_api,_err,_rv)
#define VALIDATE(_exp,_api,_err )
#define VALIDATE_NO_RV(_exp,_api,_err )
#define DET_REPORTERROR(_x,_y,_z,_q)
#endif
#define IS_UDP_GRP(_x) ((ConnectionGroupAdminList[_x].SocketConnectionGroupRef->GroupType == SOAD_GROUPTYPE_LONELY_UDP) || (ConnectionGroupAdminList[_x].SocketConnectionGroupRef->GroupType == SOAD_GROUPTYPE_MULTI_UDP))
#define SOAD_PDU_ROUTE_FIRST_DESTINATION_IDX 0u /*Index of the fist PDU route destination */
/* Structure to keep run time paraemeters for TP transmission */
typedef struct {
TcpIp_SocketIdType socketId;
PduLengthType totalLen;
boolean tpTxRequest;
boolean firstCopyCalled;
PduLengthType remainingLength;
}SoadTptransmitType;
/* Structure to keep run time parameters for Tp reception */
typedef struct {
PduLengthType remaingLen;
uint8 socketRouteIndex;
boolean tpRxRequest;
boolean firstCopyCalled;
}SoadTpReceiveType;
typedef struct {
TcpIp_SocketIdType SocketId;
SoAd_SoConModeType mode; // Maybe not needed? Used in one place at the moment
TcpIp_IpAddrStateType IpAddrState;
uint16 localPortUsed;
const SoAd_SocketConnectionGroupType* SocketConnectionGroupRef;
}ConnectionGroupAdminType;
typedef struct {
TcpIp_SocketIdType SocketId;
SoAd_SoConModeType mode;
boolean openRequest;
boolean closeRequest;
boolean abort; // From SoAd_CloseSoCon()
boolean opened;
boolean closedByCloseSoCon; // closed by SoAd_CloseSoCon()?
uint32 bytesInPduUdpBuffer;
CirqBufferType rxBuffer;
/** @req SWS_SOAD_00696 */
uint32 udpBufTimer;
uint32 udpAliveTimer;
SoAd_SocketRemoteAddressType remAddrInUse;
ConnectionGroupAdminType* groupAdminRef;
const SoAd_SocketConnectionType* SocketConnectionRef;
}ConnectionAdminType;
typedef enum {
SOAD_TRIGGERTRANSMITMODE_OFF = 0,
SOAD_TRIGGERTRANSMITMODE_ROUTINGGROUP,
SOAD_TRIGGERTRANSMITMODE_ROUTINGGROUP_AND_SOCON,
} TriggerTransmitMode;
typedef struct {
TriggerTransmitMode mode;
uint32 RoutingGroup;
uint32 SoConId;
}TriggerTransmitInfoType;
typedef struct {
TriggerTransmitInfoType trigger;
TxStateType TxState;
uint32 unconfirmedMessages;
}PduRouteAdminType;
typedef struct {
const SoAd_PduRouteDestType* PduRouteDest;
uint32 RoutingGroup;
uint32 SoConId;
boolean Active;
boolean TriggerTransmit;
}PduRoutingGroupAdminType;
typedef struct {
const SoAd_SocketRouteDestType* SocketRouteDest;
uint32 RoutingGroup;
uint32 SoConId;
boolean Active;
}SocketRoutingGroupAdminType;
typedef struct {
const uint8* TxBufCopy;
uint32 TxPduHeaderId;
/* uint32 TxBufLen; */
SoAd_SoConIdType SoConId;
}SocketTxAdminType;
typedef struct {
boolean SoAd_TpCancelTranStatus;
boolean SoAd_TpCancelReceiveStatus;
}SoAd_TpCancelStatusType;
const SoAd_ConfigType *SoAdCfgPtr = NULL;
typedef enum {
SOAD_UNINITIALIZED = 0,
SOAD_INITIALIZED
} SoadStateType;
#define TCP_TP_RECEIVE_BUFFER_SIZE 1500u
#define SOAD_INVALID_CON_ID 0xFFFFu
#define SOAD_GROUP_INDEX_VALUE_ZERO 0x0u
#define SOCONID_VALUE_ZERO 0x0u
static SoadStateType SoAd_ModuleStatus = SOAD_UNINITIALIZED;
//static SoAd_TpCancelStatusType SoAd_TpCancelStatus;
static SoadTptransmitType SoadTpTransStatus[SOAD_NR_OF_PDU_ROUTES]; /* Array contianing run time parameters for Tp transmit */
static SoadTpReceiveType SoAdTpReceiveStatus[SOAD_NR_OF_SOCKET_CONNECTIONS]; /* Array contianing run time parameters for Tp transmit */
static ConnectionGroupAdminType ConnectionGroupAdminList[SOAD_NR_OF_SOCKET_CONNECTION_GROUPS];
static ConnectionAdminType ConnectionAdminList[SOAD_NR_OF_SOCKET_CONNECTIONS];
static PduRouteAdminType PduRouteAdminList[SOAD_NR_OF_PDU_ROUTES];
#if SOAD_NR_OF_PDU_ROUTING_GROUP_CONNECTIONS > 0
static PduRoutingGroupAdminType PduRoutingGroupAdminList[SOAD_NR_OF_PDU_ROUTING_GROUP_CONNECTIONS];
#endif
static SocketRoutingGroupAdminType SocketRoutingGroupAdminList[SOAD_NR_OF_SOCKET_ROUTING_GROUP_CONNECTIONS];
static SocketTxAdminType SocketCurrentTx[OS_TASK_CNT];
/* ----------------------------[private functions]---------------------------*/
static void changeMode( SoAd_SoConIdType SoConId, SoAd_SoConModeType mode);
static TcpIp_ProtocolType convertSoAdProtType( const SoAd_SocketProtocolType SoAdProtocol );
static void changeParams( SoAd_SoConIdType SoConId, TcpIp_SocketIdType socketId );
static TcpIp_SockAddrType makeTcpIp_SockAddr( SoAd_SoConIdType SoConId );
static boolean hasWildcardsInAddress(SoAd_SoConIdType SoConId);
static boolean getGroupIndexFromSocketId(TcpIp_SocketIdType SocketId, uint32* index);
static boolean getSoConIdFromSocketId(TcpIp_SocketIdType SocketId, SoAd_SoConIdType* SoConId);
static Std_ReturnType openSocket(SoAd_SoConIdType SoConId);
static Std_ReturnType closeSocket(SoAd_SoConIdType SoConId, boolean initiatedBySoConClose);
static boolean runMessageAcceptancePolicy(void);
static boolean runBestMatch(const SoAd_SocketConnectionGroupType* grp, const TcpIp_SockAddrType* RemoteAddrPtr, uint32* ConnIndexInGroup);
static void setRemoteAddress(SoAd_SoConIdType SoConId, const TcpIp_SockAddrType* RemoteAddrPtr);
static Std_ReturnType transmit(uint16 connIndex, uint32 length,uint8 *dataPtr,uint32 pduHeaderId);
#if SOAD_NR_OF_PDU_ROUTING_GROUP_CONNECTIONS > 0
static Std_ReturnType findActiveRoutingGroup(const SoAd_PduRouteDestType* pduRouteDest, uint16 connIndex );
#endif
static void copyPduToBuffer(uint16 connIndex, const PduInfoType* SoAdSrcPduInfoPtr, boolean useHeader, uint32 headerId);
static Std_ReturnType ifTransmitSubFunction(uint16 connIndex, PduIdType SoAdSrcPduId, const SoAd_PduRouteDestType* pduRouteDest, const PduInfoType* SoAdSrcPduInfoPtr, boolean* atLeastOneDestSent);
static void tpTransmitSubFunction(PduIdType SoAdSrcPduId);
static void setBufTimer(uint16 connIndex, const SoAd_PduRouteDestType* pduRouteDest);
static boolean getPduHeader(const uint8* BufPtr, uint32 Length, uint32* headerId, uint32* PduLength);
static boolean soConInSocketRoute(uint16 SoConId, const SoAd_SocketRouteType* SocketRoute);
static boolean routingReceptionNoHeader(uint16 SoConId, PduInfoType* rxPDU);
static boolean routingReceptionPduHeader(uint16 SoConId, uint32 headerId, uint8* pduBuf, PduLengthType pduLength);
static void setRemoteAddressFromCfg(SoAd_SoConIdType SoConId);
static void processTpTcpRxCommunication (TcpIp_SocketIdType SocketId, SoAd_SoConIdType SoConId, uint8* BufPtr, uint16 Length);
/**
* Converts a SoAdProtocolType into a TcpIpProtocolType
* @param SoAdProtocol The variable to convert
* @return The Protocol as an TcpIp_ProtocolType
*/
static TcpIp_ProtocolType convertSoAdProtType(
const SoAd_SocketProtocolType SoAdProtocol) {
TcpIp_ProtocolType TcpIpProt;
if (SoAdProtocol == SOAD_SOCKET_PROT_TCP) {
TcpIpProt = TCPIP_IPPROTO_TCP;
} else if (SoAdProtocol == SOAD_SOCKET_PROT_UDP) {
TcpIpProt = TCPIP_IPPROTO_UDP;
} else {
/* IMPROVEMENT: Add error handling */
TcpIpProt = TCPIP_IPPROTO_UDP;
}
return TcpIpProt;
}
/**
* Changes TCP/IP parameters for TCP/IP socket according to config data in SoAd Socket Connection structs.
*
* @param SoConId Identifies the SoAd socket connection with info about the Tcp/Ip param values.
* @param socketId Which Tcp/Ip socket.
*/
static void changeParams(SoAd_SoConIdType SoConId, TcpIp_SocketIdType socketId){
const SoAd_SocketConnectionGroupType* grp = ConnectionAdminList[SoConId].groupAdminRef->SocketConnectionGroupRef;
uint8 TCP_NAGLE_ON = 1;
/** @req SWS_SOAD_00689 */
if(grp->SocketProtocol == SOAD_SOCKET_PROT_TCP){
TcpIp_ChangeParameter(socketId, TCPIP_PARAMID_TCP_RXWND_MAX, (const uint8*)(&(grp->SocketTpRxBufferMin)) );
if(grp->SocketProtocolTcp->SocketTcpNoDelay == TRUE){
TcpIp_ChangeParameter(socketId, TCPIP_PARAMID_TCP_NAGLE, NULL );
}else{
TcpIp_ChangeParameter(socketId, TCPIP_PARAMID_TCP_NAGLE, (const uint8*)(&TCP_NAGLE_ON) );
}
TcpIp_ChangeParameter(socketId, TCPIP_PARAMID_TCP_KEEPALIVE, (const uint8*)(&(grp->SocketProtocolTcp->SocketTcpKeepAlive)) );
TcpIp_ChangeParameter(socketId, TCPIP_PARAMID_TCP_KEEPALIVE_TIME, (const uint8*)(&(grp->SocketProtocolTcp->SocketTcpKeepAliveTime)) );
TcpIp_ChangeParameter(socketId, TCPIP_PARAMID_TCP_KEEPALIVE_PROBES_MAX, (const uint8*)(&(grp->SocketProtocolTcp->SocketTcpKeepAliveProbesMax)) );
TcpIp_ChangeParameter(socketId, TCPIP_PARAMID_TCP_KEEPALIVE_INTERVAL, (const uint8*)(&(grp->SocketProtocolTcp->SocketTcpKeepAliveInterval)) );
}
if(grp->SocketFramePriorityUsed == TRUE){
TcpIp_ChangeParameter(socketId, TCPIP_PARAMID_FRAMEPRIO, (const uint8*)(&(grp->SocketFramePriority)) );
}
}
/**
* Makes a TCP/IP Socket Address from info in an SoAd Socket Connection struct.
*
* @param SoConId Identifies which SoAd Socket Connection
* @return The TCP/IP socket address
*/
static TcpIp_SockAddrType makeTcpIp_SockAddr(SoAd_SoConIdType SoConId){
//IMPROVEMENT Should be able to signal an error!!!
TcpIp_SockAddrType SockAddr = {
.addr = {TCPIP_IPADDR_ANY, TCPIP_IPADDR_ANY, TCPIP_IPADDR_ANY, TCPIP_IPADDR_ANY},
.port = TCPIP_PORT_ANY,
.domain = TCPIP_AF_INET
};
if(ConnectionAdminList[SoConId].remAddrInUse.Set == FALSE){
/*lint -e{904} Return statement is necessary to avoid multiple if loops and hence increase readability */
return SockAddr;
}
for(uint32 i=0;i<4;i++){
SockAddr.addr[i] = ConnectionAdminList[SoConId].remAddrInUse.SocketRemoteIpAddress[i];
}
SockAddr.port = ConnectionAdminList[SoConId].remAddrInUse.SocketRemotePort;
SockAddr.domain = TCPIP_AF_INET;
return SockAddr;
}
/**
* Checks if a SoAd Socket Connection has wildcards in some part of the address, for example if port==TCPIP_PORT_ANY
* @param soCon The SoCon to test
* @return true if wildcard found
*/
static boolean hasWildcardsInAddress(SoAd_SoConIdType SoConId){
boolean retVal = FALSE;
if( (ConnectionAdminList[SoConId].remAddrInUse.Set == TRUE) &&
( ( (ConnectionAdminList[SoConId].remAddrInUse.SocketRemoteIpAddress[0]==TCPIP_IPADDR_ANY) &&
(ConnectionAdminList[SoConId].remAddrInUse.SocketRemoteIpAddress[1]==TCPIP_IPADDR_ANY) &&
(ConnectionAdminList[SoConId].remAddrInUse.SocketRemoteIpAddress[2]==TCPIP_IPADDR_ANY) &&
(ConnectionAdminList[SoConId].remAddrInUse.SocketRemoteIpAddress[3]==TCPIP_IPADDR_ANY) ) ||
(ConnectionAdminList[SoConId].remAddrInUse.SocketRemotePort==TCPIP_PORT_ANY)) ){
retVal = TRUE;
}
return retVal;
}
/**
* Finds which SoAd Socket Connection Group is connected with the TcpIp Socket, if any, and gives the groupIndex.
*
* @param SocketId The TcpIp socket
* @param index Index to the Socket Connection Group which is connected to the TcpIp socket.
* @return true if group found, false otherwise.
*/
static boolean getGroupIndexFromSocketId(TcpIp_SocketIdType SocketId, uint32* indx){
boolean status;
status = FALSE;
for(uint32 i=0;i<SOAD_NR_OF_SOCKET_CONNECTION_GROUPS;i++){
if( ConnectionGroupAdminList[i].SocketId== SocketId){
*indx = i;
status = TRUE;
break;
}
}
return status;
}
/**
* Finds which SoAd Socket Connection is connected with the TcpIp Socket, if any, and returns the index.
* @param SocketId The TcpIp socket
* @param SoConId Index to the Socket Connection which is connected to the TcpIp socket.
* @return true if Socket Connection found, false otherwise.
*/
static boolean getSoConIdFromSocketId(TcpIp_SocketIdType SocketId, SoAd_SoConIdType* SoConId){
boolean status;
status = FALSE;
for(int i=0;i<SOAD_NR_OF_SOCKET_CONNECTIONS;i++){
if( ConnectionAdminList[i].SocketId == SocketId){
*SoConId = i;
// Finds the first, there might be more.
status = TRUE;
}
}
return status;
}
/**
* Opens a SoAd Socket Connection by opening TcpIp Socket, changing TcpIp parameters, binds the socket and calls TcpConnect() as needed.
*
* @param SoConId The SoAd Socket Connection
* @return E_OK if successful, E_NOT_OK otherwise.
*/
static Std_ReturnType openSocket(SoAd_SoConIdType SoConId){
const SoAd_SocketConnectionGroupType* grp = ConnectionAdminList[SoConId].groupAdminRef->SocketConnectionGroupRef;
if(grp == NULL){
// IMPROVEMENT Dev error
/*lint -e{904} Return statement is necessary to avoid multiple if loops and hence increase readability*/
return E_NOT_OK;
}
/** @req SWS_SOAD_00590 */
if( ((grp->SocketProtocol == SOAD_SOCKET_PROT_UDP) && (grp->NrOfSocketConnections == 1))
|| ((grp->SocketProtocol == SOAD_SOCKET_PROT_TCP) &&
(grp->SocketProtocolTcp->SocketTcpInitiate == TRUE)) ){
// IMPROVEMENT Maybe also IPv6 domains?
TcpIp_SoAdGetSocket(TCPIP_AF_INET, convertSoAdProtType(grp->SocketProtocol), &(ConnectionAdminList[SoConId].SocketId));
changeParams(SoConId, ConnectionAdminList[SoConId].SocketId);
TcpIp_Bind(ConnectionAdminList[SoConId].SocketId, grp->SocketLocalAddressRef, (uint16*)&(ConnectionAdminList[SoConId].groupAdminRef->localPortUsed) );
if( grp->SocketProtocol == SOAD_SOCKET_PROT_TCP ){
TcpIp_SockAddrType remoteAddress = makeTcpIp_SockAddr(SoConId);
TcpIp_TcpConnect(ConnectionAdminList[SoConId].SocketId, &remoteAddress);
}
}
/** @req SWS_SOAD_00638 */
else if(((grp->SocketProtocol == SOAD_SOCKET_PROT_TCP) &&
(grp->SocketProtocolTcp->SocketTcpInitiate == FALSE))){
if(ConnectionAdminList[SoConId].groupAdminRef->SocketId == TCPIP_SOCKETID_INVALID){
// IMPROVEMENT Maybe also IPv6 domains?
TcpIp_SoAdGetSocket(TCPIP_AF_INET, convertSoAdProtType(grp->SocketProtocol), &(ConnectionAdminList[SoConId].groupAdminRef->SocketId));
// IMPROVEMENT Assigned the tcpip group socket to the SoCon as well, is this right?
ConnectionAdminList[SoConId].SocketId = ConnectionAdminList[SoConId].groupAdminRef->SocketId;
changeParams(SoConId, ConnectionAdminList[SoConId].groupAdminRef->SocketId);
TcpIp_Bind(ConnectionAdminList[SoConId].groupAdminRef->SocketId, grp->SocketLocalAddressRef, (uint16*)&(ConnectionAdminList[SoConId].groupAdminRef->localPortUsed) );
// IMPROVEMENT 638 (e)??
TcpIp_TcpListen(ConnectionAdminList[SoConId].groupAdminRef->SocketId, grp->NrOfSocketConnections);
}
else{
//IMPROVEMENT (2)(a) Activate the socket connection to accept connections from remote nodes???
// IMPROVEMENT This indicates "Activate the socket connection to accept..."
ConnectionAdminList[SoConId].SocketId = ConnectionAdminList[SoConId].groupAdminRef->SocketId;
}
}
/** @req SWS_SOAD_00639 */
else if( (grp->SocketProtocol == SOAD_SOCKET_PROT_UDP) && (grp->NrOfSocketConnections > 1) ){
if(ConnectionAdminList[SoConId].groupAdminRef->SocketId == TCPIP_SOCKETID_INVALID){
// IMPROVEMENT Maybe also IPv6 domains?
TcpIp_SoAdGetSocket(TCPIP_AF_INET, convertSoAdProtType(grp->SocketProtocol), &(ConnectionAdminList[SoConId].groupAdminRef->SocketId));
// IMPROVEMENT Assigned the tcpip group socket to the SoCon as well, is this right?
ConnectionAdminList[SoConId].SocketId = ConnectionAdminList[SoConId].groupAdminRef->SocketId;
changeParams(SoConId, ConnectionAdminList[SoConId].groupAdminRef->SocketId);
TcpIp_Bind(ConnectionAdminList[SoConId].groupAdminRef->SocketId, grp->SocketLocalAddressRef, (uint16*)&(ConnectionAdminList[SoConId].groupAdminRef->localPortUsed) );
}
else{
//IMPROVEMENT (2)(a) Activate the socket connection for communication via the shared UDP socket of the socket connection group???
// IMPROVEMENT This indicates "Activate the socket connection for communication..."
ConnectionAdminList[SoConId].SocketId = ConnectionAdminList[SoConId].groupAdminRef->SocketId;
}
}
else{
//Should never end up here. The above alternatives should cover every possibility
}
/** @req SWS_SOAD_00591 */
if((grp->SocketProtocol == SOAD_SOCKET_PROT_UDP) && ((grp->SocketProtocolUdp->SocketUdpListenOnly==TRUE) || (hasWildcardsInAddress(SoConId) == FALSE) )){
changeMode(SoConId, SOAD_SOCON_ONLINE);
}
/** @req SWS_SOAD_00686 */
if( (grp->SocketProtocol == SOAD_SOCKET_PROT_TCP) || (hasWildcardsInAddress(SoConId) == TRUE ) ){
changeMode(SoConId, SOAD_SOCON_RECONNECT);
}
return E_OK;
}
/**
* Closes a SoAd Socket Connection and realted TcpIp socket as needed.
*
* @param SoConId The SoAd Socket Connection to close
* @param initiatedBySoConClose Indicates whether the closing was initiated by SoCon_Close() or not
* @return E_OK if successful, E_NOT_OK otherwise.
*/
static Std_ReturnType closeSocket(SoAd_SoConIdType SoConId, boolean initiatedBySoConClose){
const SoAd_SocketConnectionGroupType* grp = ConnectionAdminList[SoConId].groupAdminRef->SocketConnectionGroupRef;
uint32 nrOfClosedConnections = 0;
if(grp == NULL){
// IMPROVEMENT Dev error
/*lint -e{904} Return statement is necessary to avoid multiple if loops and hence increase readability */
return E_NOT_OK;
}
/** @req SWS_SOAD_00637 */
//(1) only applicable to TP connections
//(2) IMPROVEMENT How to do this?
/** @req SWS_SOAD_00642 */
ConnectionAdminList[SoConId].closedByCloseSoCon = TRUE; // IMPROVEMENT where to set this false again?
// IMPROVEMENT Use SoAd_GroupTypeType instead
if( !((grp->SocketProtocol == SOAD_SOCKET_PROT_UDP) && (grp->NrOfSocketConnections == 1)) && ((grp->SocketProtocol == SOAD_SOCKET_PROT_TCP) && (grp->SocketProtocolTcp->SocketTcpInitiate == FALSE))){
if( (ConnectionAdminList[SoConId].SocketId != TCPIP_SOCKETID_INVALID)&& (ConnectionAdminList[SoConId].SocketId == ConnectionAdminList[SoConId].groupAdminRef->SocketId)){
}
else{
TcpIp_Close( ConnectionAdminList[SoConId].SocketId, (ConnectionAdminList[SoConId].abort && initiatedBySoConClose) );
}
for(int i=0;i<SOAD_NR_OF_SOCKET_CONNECTIONS;i++){
if( (ConnectionAdminList[i].groupAdminRef == ConnectionAdminList[SoConId].groupAdminRef) && (ConnectionAdminList[i].closedByCloseSoCon == TRUE) ){
nrOfClosedConnections++;
}
}
if(nrOfClosedConnections == grp->NrOfSocketConnections){
// Close listen socket as well if there is one
TcpIp_Close( ConnectionAdminList[SoConId].groupAdminRef->SocketId, (ConnectionAdminList[SoConId].abort && initiatedBySoConClose) );
ConnectionAdminList[SoConId].groupAdminRef->SocketId = TCPIP_SOCKETID_INVALID;
ConnectionAdminList[SoConId].groupAdminRef->localPortUsed = ConnectionAdminList[SoConId].groupAdminRef->SocketConnectionGroupRef->SocketLocalPort;
}
}
else{
TcpIp_Close(ConnectionAdminList[SoConId].SocketId, (ConnectionAdminList[SoConId].abort && initiatedBySoConClose) );
ConnectionAdminList[SoConId].groupAdminRef->localPortUsed = ConnectionAdminList[SoConId].groupAdminRef->SocketConnectionGroupRef->SocketLocalPort;
}
SchM_Enter_SoAd_EA_0();
if( initiatedBySoConClose == TRUE ){
changeMode(SoConId, SOAD_SOCON_OFFLINE);
}
else{
changeMode(SoConId, SOAD_SOCON_RECONNECT);
}
ConnectionAdminList[SoConId].SocketId = TCPIP_SOCKETID_INVALID;
SchM_Exit_SoAd_EA_0();
return E_OK;
}
/**
* The Message Acceptance Policy.
*
* @return
*/
static boolean runMessageAcceptancePolicy(void){
//IMPROVEMENT Implement
return TRUE;
}
/**
* Runs the Best Match Algorithm.
*
* @param grp The Socket Connection Group
* @param RemoteAddrPtr Remote Address
* @param ConnIndexInGroup Index in the Socket Connection Group for the best matching Socket Connection
* @return true if a match is found, false otherwise.
*/
static boolean runBestMatch(const SoAd_SocketConnectionGroupType* grp, const TcpIp_SockAddrType* RemoteAddrPtr, uint32* ConnIndexInGroup){
typedef struct{
SoAd_SoConIdType index;
uint8 prio;
} BestMatchType;
BestMatchType BestMatch = {.index =0, .prio = 0};
const SoAd_SocketRemoteAddressType* cfgAddress;
/** @req SWS_SOAD_00680 */
for(SoAd_SoConIdType i=0;i<grp->NrOfSocketConnections;i++){
cfgAddress = &(ConnectionAdminList[grp->SoAdSocketConnection[i].SocketId].remAddrInUse);
if(cfgAddress->Set){
/** @req SWS_SOAD_00525 */
if( (cfgAddress->SocketRemoteIpAddress[0] == RemoteAddrPtr->addr[0]) &&
(cfgAddress->SocketRemoteIpAddress[1] == RemoteAddrPtr->addr[1]) &&
(cfgAddress->SocketRemoteIpAddress[2] == RemoteAddrPtr->addr[2]) &&
(cfgAddress->SocketRemoteIpAddress[3] == RemoteAddrPtr->addr[3]) &&
(cfgAddress->SocketRemotePort == RemoteAddrPtr->port)) {
BestMatch.index = i;
BestMatch.prio = 4;
}
else if( (cfgAddress->SocketRemoteIpAddress[0] == RemoteAddrPtr->addr[0]) &&
(cfgAddress->SocketRemoteIpAddress[1] == RemoteAddrPtr->addr[1]) &&
(cfgAddress->SocketRemoteIpAddress[2] == RemoteAddrPtr->addr[2]) &&
(cfgAddress->SocketRemoteIpAddress[3] == RemoteAddrPtr->addr[3])&&
(cfgAddress->SocketRemotePort == TCPIP_PORT_ANY) &&
(BestMatch.prio < 4) ){
BestMatch.index = i;
BestMatch.prio = 3;
}
else if( (cfgAddress->SocketRemotePort == RemoteAddrPtr->port) &&
(cfgAddress->SocketRemoteIpAddress[0] == TCPIP_IPADDR_ANY) &&
(cfgAddress->SocketRemoteIpAddress[1] == TCPIP_IPADDR_ANY) &&
(cfgAddress->SocketRemoteIpAddress[2] == TCPIP_IPADDR_ANY) &&
(cfgAddress->SocketRemoteIpAddress[3] == TCPIP_IPADDR_ANY) &&
(BestMatch.prio < 3) ){
BestMatch.index = i;
BestMatch.prio = 2;
}
else if( (cfgAddress->SocketRemoteIpAddress[0] == TCPIP_IPADDR_ANY) &&
(cfgAddress->SocketRemoteIpAddress[1] == TCPIP_IPADDR_ANY) &&
(cfgAddress->SocketRemoteIpAddress[2] == TCPIP_IPADDR_ANY) &&
(cfgAddress->SocketRemoteIpAddress[3] == TCPIP_IPADDR_ANY) &&
(cfgAddress->SocketRemotePort == TCPIP_PORT_ANY) &&
(BestMatch.prio < 2) ){
BestMatch.index = i;
BestMatch.prio = 1;
}
else{
//Nothing
}
}
}
*ConnIndexInGroup = BestMatch.index;
return (boolean)(BestMatch.prio>0);
}
/**
* Sets the Remote Address of a Socket Connection according to the supplied TcpIp Address.
*
* @param SocketConnectionRef The socket connection
* @param RemoteAddrPtr Remote address.
*/
static void setRemoteAddress(SoAd_SoConIdType SoConId, const TcpIp_SockAddrType* RemoteAddrPtr) {
//IMPROVEMENT Check if IP4 or IP6?
/** @req SWS_SOAD_00533 */
for (uint32 i = 0; i < 4; i++) {
ConnectionAdminList[SoConId].remAddrInUse.SocketRemoteIpAddress[i] = RemoteAddrPtr->addr[i];
}
ConnectionAdminList[SoConId].remAddrInUse.SocketRemotePort =
RemoteAddrPtr->port;
ConnectionAdminList[SoConId].remAddrInUse.Set = TRUE;
}
/**
* Calls TcpIp_Udp/TcpTransmit() according to group belonging for the SoAd Socket Connection.
* It can be called from other task contexts and allows for context switches
* @param connIndex The SoAd Socket Connection index
* @param length Length of data to be sent.
* @return E_OK if TcpIp accepted the sending.
*/
static Std_ReturnType transmit(uint16 connIndex, uint32 length, uint8 *dataPtr, uint32 pduHeaderId){
Std_ReturnType retVal = E_OK;
#if defined(HOST_TEST)
// Must be word aligned in Intel architecture for host test to pass
TcpIp_SockAddrType remAddress __attribute__ ((aligned (32)));
#else
TcpIp_SockAddrType remAddress;
#endif
TaskType task_id = 0;
// Since we cannot disable interrupts in TcpIp calls, task_id is used as an array index to protect
// SocketCurrentTx from possible task switches occurring between assignment of SocketCurrentTx and the transmission.
// TcpIp_UdpTransmit uses callback SoAd_CopyTxData where the right version of SocketCurrentTx will be used
// even if a context switch has occurred.
retVal = GetTaskID(&task_id);
if ((retVal == E_OK) && (task_id < OS_TASK_CNT)){
SchM_Enter_SoAd_EA_0();
SocketCurrentTx[task_id].SoConId = connIndex;
SocketCurrentTx[task_id].TxBufCopy = dataPtr;
SocketCurrentTx[task_id].TxPduHeaderId = pduHeaderId;
SchM_Exit_SoAd_EA_0();
/** @req SWS_SOAD_00540 */
/** @req SWS_SOAD_00542 */
switch ( ConnectionAdminList[connIndex].groupAdminRef->SocketConnectionGroupRef->GroupType ) {
case SOAD_GROUPTYPE_LONELY_UDP:
remAddress = makeTcpIp_SockAddr(connIndex);
retVal = TcpIp_UdpTransmit(ConnectionAdminList[connIndex].SocketId, NULL, &remAddress, length);
break;
case SOAD_GROUPTYPE_MULTI_UDP:
remAddress = makeTcpIp_SockAddr(connIndex);
retVal = TcpIp_UdpTransmit(ConnectionAdminList[connIndex].groupAdminRef->SocketId, NULL, &remAddress, length);
break;
case SOAD_GROUPTYPE_LISTEN_TCP:// Intentional fall through
case SOAD_GROUPTYPE_INIT_TCP:
retVal = TcpIp_TcpTransmit(ConnectionAdminList[connIndex].SocketId, NULL, length, TRUE);
break;
default:
break;
}
}
return retVal;
}
#if SOAD_NR_OF_PDU_ROUTING_GROUP_CONNECTIONS > 0
/**
* Finds if Pdu Route Dest pduRouteDest should be used to send Pdus. If either
* it has no routing groups or if at least one of its routing groups is active
* for the supplied Socket Connection id it should be ok.
*
* @param pduRouteDest Pdu Route Dest to check
* @param connIndex Socket Connection id
* @return True if it's clear to send
*/
static Std_ReturnType findActiveRoutingGroup(const SoAd_PduRouteDestType* pduRouteDest, uint16 connIndex ){
Std_ReturnType retVal = E_NOT_OK;
/** @req SWS_SOAD_00560 */
// Find if there is at least one routing group active for this PduRouteDest
if(pduRouteDest->NrOfRoutingGroups == 0){
retVal = E_OK;
}
else{
/*lint -save -e845 CONFIGURATION */
for(uint32 k=0;k<SOAD_NR_OF_PDU_ROUTING_GROUP_CONNECTIONS;k++){
if(pduRouteDest == PduRoutingGroupAdminList[k].PduRouteDest ){
if( (PduRoutingGroupAdminList[k].Active == TRUE) && (PduRoutingGroupAdminList[k].SoConId == connIndex) ){
retVal = E_OK;
break;
}
}
}
/*lint -restore */
}
return retVal;
}
#endif
/**
* Copies Pdu data pointed to by SoAdSrcPduInfoPtr for the Socket Connection
* with id connIndex into its nPduUdpTxBuffer taking into account if Pdu Headers
* should be used or not.
*
* @param connIndex Indicates the Socket Connection
* @param SoAdSrcPduInfoPtr Pointer to the Pdu to be copied
* @param useHeader True if PDU header is to be copied as well
* @param headerId What headerId to copy
*/
static void copyPduToBuffer(uint16 connIndex, const PduInfoType* SoAdSrcPduInfoPtr, boolean useHeader, uint32 headerId){
uint32 bufIndex= ConnectionAdminList[connIndex].bytesInPduUdpBuffer;
SchM_Enter_SoAd_EA_0();
if(useHeader==TRUE){
/** @req SWS_SOAD_00197 */
/** @req SWS_SOAD_00198 */
ConnectionAdminList[connIndex].SocketConnectionRef->nPduUdpTxBuffer[bufIndex++] = (uint8)((headerId & 0xFF000000u)>>24);
ConnectionAdminList[connIndex].SocketConnectionRef->nPduUdpTxBuffer[bufIndex++] = (uint8)((headerId & 0x00FF0000u)>>16);
ConnectionAdminList[connIndex].SocketConnectionRef->nPduUdpTxBuffer[bufIndex++] = (uint8)((headerId & 0x0000FF00u)>>8);
ConnectionAdminList[connIndex].SocketConnectionRef->nPduUdpTxBuffer[bufIndex++] = (uint8) (headerId & 0x000000FFu);
ConnectionAdminList[connIndex].SocketConnectionRef->nPduUdpTxBuffer[bufIndex++] = 0;
ConnectionAdminList[connIndex].SocketConnectionRef->nPduUdpTxBuffer[bufIndex++] = 0;
ConnectionAdminList[connIndex].SocketConnectionRef->nPduUdpTxBuffer[bufIndex++] = (uint8)((SoAdSrcPduInfoPtr->SduLength & 0x0000FF00u)>>8);
ConnectionAdminList[connIndex].SocketConnectionRef->nPduUdpTxBuffer[bufIndex++] = (uint8) (SoAdSrcPduInfoPtr->SduLength & 0x000000FFu);
ConnectionAdminList[connIndex].bytesInPduUdpBuffer = bufIndex;
}
uint32 i=0;
for(;bufIndex<ConnectionAdminList[connIndex].bytesInPduUdpBuffer+SoAdSrcPduInfoPtr->SduLength;bufIndex++){
ConnectionAdminList[connIndex].SocketConnectionRef->nPduUdpTxBuffer[bufIndex] = SoAdSrcPduInfoPtr->SduDataPtr[i++];
}
ConnectionAdminList[connIndex].bytesInPduUdpBuffer = bufIndex;
SchM_Exit_SoAd_EA_0();
}
/**
* Sets the Tx Udp Trigger Timeout for the Socket Connection connIndex using
* config data from pduRouteDest. This timer controls the Udp Tx Buffer
* sending.
*
* @param connIndex Indicates which Socket Connection
* @param pduRouteDest Here the timeout values are kept.
*/
static void setBufTimer(uint16 connIndex, const SoAd_PduRouteDestType* pduRouteDest){
if(ConnectionAdminList[connIndex].udpBufTimer==0){ // Timer not running
/** @req SWS_SOAD_00697 */
if( pduRouteDest->TxUdpTriggerTimeout > 0 ){
SchM_Enter_SoAd_EA_0();
ConnectionAdminList[connIndex].udpBufTimer = pduRouteDest->TxUdpTriggerTimeout;
SchM_Exit_SoAd_EA_0();
} /** @req SWS_SOAD_00683 */
else if( ConnectionAdminList[connIndex].groupAdminRef->SocketConnectionGroupRef->SocketProtocolUdp->SocketUdpTriggerTimeout > 0 ){
SchM_Enter_SoAd_EA_0();
ConnectionAdminList[connIndex].udpBufTimer = ConnectionAdminList[connIndex].groupAdminRef->SocketConnectionGroupRef->SocketProtocolUdp->SocketUdpTriggerTimeout;
SchM_Exit_SoAd_EA_0();
}
else{
}
}else{// Timer is already running
/** @req SWS_SOAD_00697 */
if( (pduRouteDest->TxUdpTriggerTimeout > 0) && (ConnectionAdminList[connIndex].udpBufTimer > pduRouteDest->TxUdpTriggerTimeout)){
SchM_Enter_SoAd_EA_0();
ConnectionAdminList[connIndex].udpBufTimer = pduRouteDest->TxUdpTriggerTimeout;
SchM_Exit_SoAd_EA_0();
} /** @req SWS_SOAD_00683 */
else if( (pduRouteDest->TxUdpTriggerTimeout == 0) &&
(ConnectionAdminList[connIndex].groupAdminRef->SocketConnectionGroupRef->SocketProtocolUdp->SocketUdpTriggerTimeout > 0) &&
(ConnectionAdminList[connIndex].udpBufTimer > ConnectionAdminList[connIndex].groupAdminRef->SocketConnectionGroupRef->SocketProtocolUdp->SocketUdpTriggerTimeout) ){
SchM_Enter_SoAd_EA_0();
ConnectionAdminList[connIndex].udpBufTimer = ConnectionAdminList[connIndex].groupAdminRef->SocketConnectionGroupRef->SocketProtocolUdp->SocketUdpTriggerTimeout;
SchM_Exit_SoAd_EA_0();
}
else{
}
}
}
/**
* If routing groups allow Pdu is either sent using transmit() subfunction or
* copied into buffer for later transmission.
*
* @param connIndex SoAd Socket Connection
* @param SoAdSrcPduId To keep track of unconfirmed TCP messages.
* @param pduRouteDest The Pdu Route Dest to match against connIndex
* @param SoAdSrcPduInfoPtr The Pdu to send.
* @param atLeastOneDestSent Outgoing parameter that indicates if at least one transmission was done.
* @return The return value of transmit() subfunction
*/
static Std_ReturnType ifTransmitSubFunction(uint16 connIndex, PduIdType SoAdSrcPduId, const SoAd_PduRouteDestType* pduRouteDest, const PduInfoType* SoAdSrcPduInfoPtr, boolean* atLeastOneDestSent){
Std_ReturnType retVal = E_OK;
boolean activeRoutingFound;
#if SOAD_NR_OF_PDU_ROUTING_GROUP_CONNECTIONS > 0
activeRoutingFound=FALSE;
if( findActiveRoutingGroup(pduRouteDest, connIndex )==E_OK){
activeRoutingFound = TRUE;
*atLeastOneDestSent = TRUE;
}
#else
activeRoutingFound=TRUE;
*atLeastOneDestSent = TRUE;
#endif
if(activeRoutingFound==TRUE){
/* @req SWS_SOAD_00690 */
/* @req SWS_SOAD_00691 */
if(ConnectionAdminList[connIndex].SocketConnectionRef->nPduUdpTxBufferSize>0){
uint32 bufferSpace = ConnectionAdminList[connIndex].SocketConnectionRef->nPduUdpTxBufferSize - ConnectionAdminList[connIndex].bytesInPduUdpBuffer;
if(pduRouteDest->TxUdpTriggerMode == SOAD_TRIGGER_NEVER){
if( bufferSpace >= SoAdSrcPduInfoPtr->SduLength){
/** @req SWS_SOAD_00547 */
copyPduToBuffer(connIndex, SoAdSrcPduInfoPtr, ConnectionAdminList[connIndex].groupAdminRef->SocketConnectionGroupRef->PduHeaderEnable, pduRouteDest->TxPduHeaderId);
}
else{
/** @req SWS_SOAD_00549 */
retVal = transmit(connIndex, ConnectionAdminList[connIndex].bytesInPduUdpBuffer,ConnectionAdminList[connIndex].SocketConnectionRef->nPduUdpTxBuffer,0);
ConnectionAdminList[connIndex].bytesInPduUdpBuffer=0;
copyPduToBuffer(connIndex, SoAdSrcPduInfoPtr, ConnectionAdminList[connIndex].groupAdminRef->SocketConnectionGroupRef->PduHeaderEnable, pduRouteDest->TxPduHeaderId);
}
if(retVal == E_OK){
setBufTimer(connIndex, pduRouteDest);
}
}
else{
if( bufferSpace < SoAdSrcPduInfoPtr->SduLength){
/** @req SWS_SOAD_00685 */
retVal = transmit(connIndex, ConnectionAdminList[connIndex].bytesInPduUdpBuffer,ConnectionAdminList[connIndex].SocketConnectionRef->nPduUdpTxBuffer,0);
ConnectionAdminList[connIndex].bytesInPduUdpBuffer=0;
}
/** @req SWS_SOAD_00548 */
copyPduToBuffer(connIndex, SoAdSrcPduInfoPtr, ConnectionAdminList[connIndex].groupAdminRef->SocketConnectionGroupRef->PduHeaderEnable, pduRouteDest->TxPduHeaderId);
retVal = transmit(connIndex, ConnectionAdminList[connIndex].bytesInPduUdpBuffer,ConnectionAdminList[connIndex].SocketConnectionRef->nPduUdpTxBuffer,0);
ConnectionAdminList[connIndex].bytesInPduUdpBuffer=0;
/** @req SWS_SOAD_00684 */
ConnectionAdminList[connIndex].udpBufTimer=0;
}
}
else{
PduRouteAdminList[SoAdSrcPduId].unconfirmedMessages++;
if(ConnectionAdminList[connIndex].groupAdminRef->SocketConnectionGroupRef->PduHeaderEnable==TRUE){
retVal = transmit(connIndex, (SoAdSrcPduInfoPtr->SduLength+SOAD_PDU_HEADER_LENGTH),SoAdSrcPduInfoPtr->SduDataPtr, pduRouteDest->TxPduHeaderId);
}
else{
retVal = transmit(connIndex, SoAdSrcPduInfoPtr->SduLength,SoAdSrcPduInfoPtr->SduDataPtr, pduRouteDest->TxPduHeaderId);
}
// IMPROVEMENT Must check that we only do this for TCP groups!
if(retVal != E_OK){
PduRouteAdminList[SoAdSrcPduId].unconfirmedMessages--; // This is only for TCP not UDP
}
}
}
return retVal;
}
/**
* @brief Function to start a Tp transmit function by invoking TcpIp_TcpTransmit
* @param SoAdSrcPduId PDU used for transmission
* @return
*/
static void tpTransmitSubFunction(PduIdType SoAdSrcPduId){
const SoAd_PduRouteType* pduRoute;
SoadTptransmitType *tpRunTimeParm;
PduInfoType pduInfo;
uint16 socketIndex;
PduLengthType totalLength;
totalLength = 0u;
BufReq_ReturnType bufAvRetVal;
bufAvRetVal = BUFREQ_OK;
Std_ReturnType retVal;
TcpIp_SockAddrType remAddress;
SoAd_SoConIdType SoConId;
pduRoute = &(SoAdCfgPtr->PduRoute[SoAdSrcPduId]);
tpRunTimeParm = &SoadTpTransStatus[SoAdSrcPduId];
pduInfo.SduDataPtr = &retVal; //Set a valid address. Not used by UL.
pduInfo.SduLength = 0;
retVal = E_OK;
bufAvRetVal = pduRoute->SoAdTpCopyTxData(pduRoute->TxPduRef, &pduInfo, NULL, &totalLength);
/** @req SWS_SoAd_00552 *//* Check what is the total length in bytes to be transmitted */
if (FALSE == tpRunTimeParm->firstCopyCalled){
if ((pduRoute->PduRouteDest[SOAD_PDU_ROUTE_FIRST_DESTINATION_IDX].TxPduHeaderId) != 0) {
/* @req SWS_SoAd_00197 */
totalLength += SOAD_PDU_HEADER_LENGTH;
}
tpRunTimeParm->totalLen = totalLength;
}
if(bufAvRetVal == BUFREQ_OK){
socketIndex = pduRoute->PduRouteDest[SOAD_PDU_ROUTE_FIRST_DESTINATION_IDX].Index;
tpRunTimeParm->socketId = ConnectionAdminList[socketIndex].SocketId; /* Save socket Id needed for later parsing */
if(ConnectionAdminList[socketIndex].groupAdminRef-> \
SocketConnectionGroupRef->SocketProtocol == SOAD_SOCKET_PROT_UDP){
PduRouteAdminList[SoAdSrcPduId].unconfirmedMessages++;
/** @req SWS_SoAd_00553 */
(void)getSoConIdFromSocketId(ConnectionAdminList[socketIndex].SocketId, &SoConId);
remAddress = makeTcpIp_SockAddr(SoConId);
retVal = TcpIp_UdpTransmit(tpRunTimeParm->socketId, NULL, &remAddress, totalLength);
}
else if (ConnectionAdminList[socketIndex].groupAdminRef-> \
SocketConnectionGroupRef->SocketProtocol == SOAD_SOCKET_PROT_TCP){
PduRouteAdminList[SoAdSrcPduId].unconfirmedMessages++;
/** @req SWS_SoAd_00554 */
retVal = TcpIp_TcpTransmit(tpRunTimeParm->socketId, NULL, totalLength, FALSE);
}else{
/*To avoid lint error*/
}
} else {
retVal = E_NOT_OK;
}
if (E_NOT_OK == retVal){
/* Something went wrong in upper/lower layer. Discard transmission */
PduRouteAdminList[SoAdSrcPduId].unconfirmedMessages--;
pduRoute->TpTxConfirmationFunction(pduRoute->TxPduRef, E_NOT_OK);
tpRunTimeParm->tpTxRequest = FALSE;
}
}
/**
* Returns the Pdu Header (headerId) and Pdu Length (PduLength) from data
* in the buffer pointed to by BufPtr. It is assumed that the buffer data
* starts with the Header at the first byte.
*
* @param BufPtr Pointer to data buffer where HeaderId and PduLength are.
* @param Length Length of buffer.
* @param headerId The returned Header Id. The first 4 bytes are
* converted into an uint32 big endian.
* @param PduLength The returned Pdu Length. The first 4 bytes are
* converted into an uint32 big endian.
* @return True as long as Length>SOAD_PDU_HEADER_LENGTH
*/
static boolean getPduHeader(const uint8* BufPtr, uint32 Length, uint32* headerId, uint32* PduLength){
if(Length<SOAD_PDU_HEADER_LENGTH){
return FALSE;
}
*headerId = 0x00000000u;
*headerId = *headerId | (BufPtr[0]<<24);
*headerId = *headerId | (BufPtr[1]<<16);
*headerId = *headerId | (BufPtr[2]<<8);
*headerId = *headerId | (BufPtr[3]);
*PduLength = 0x00000000u;
*PduLength = *PduLength | (BufPtr[4]<<24);
*PduLength = *PduLength | (BufPtr[5]<<16);
*PduLength = *PduLength | (BufPtr[6]<<8);
*PduLength = *PduLength | (BufPtr[7]);
return TRUE;
}
/**
* If Socket Connection with id SoConId is referenced from SocektRoute function
* returns TRUE.
*
* @param SoConId Identifies the SoAd socket connection.
* @param SocketRoute Socket Route
* @return True if SocektRoute references Socket Connection with
* id SoConId.
*/
static boolean soConInSocketRoute(uint16 SoConId, const SoAd_SocketRouteType* SocketRoute){
boolean retVal = FALSE;
if(SocketRoute->GroupUsed==FALSE){
if(SocketRoute->Index == SoConId){
retVal = TRUE;
}
}
else{
for(uint32 i=0;i<ConnectionGroupAdminList[SocketRoute->Index].SocketConnectionGroupRef->NrOfSocketConnections;i++){
if(ConnectionGroupAdminList[SocketRoute->Index].SocketConnectionGroupRef->SoAdSocketConnection[i].SocketId == SoConId){
retVal = TRUE;
break;
}
}
}
return retVal;
}
/**
* If SoConId is referenced from SocketRoute and routing groups allow,
* RxIndication() is called with RxPduId and rxPdu.
*
* @param SoConId Identifies the SoAd socket connection.
* @param rxPDU The Pdu payload to send to upper layer.
* @return True if upper layer was called.
*/
static boolean routingReceptionNoHeader(uint16 SoConId, PduInfoType* rxPDU){
const SoAd_SocketRouteDestType* socketDest;
uint32 j=0;
uint32 SocketRoute;
PduLengthType bufferSizePtr;
BufReq_ReturnType ret;
boolean retVal = FALSE;
for(SocketRoute=0;SocketRoute<SOAD_NR_OF_SOCKET_ROUTES;SocketRoute++){
if(soConInSocketRoute(SoConId, &(SoAdCfgPtr->SocketRoute[SocketRoute])) == TRUE){
socketDest = SoAdCfgPtr->SocketRoute[SocketRoute].SocketRouteDest;
for(j=0;j<SOAD_NR_OF_SOCKET_ROUTING_GROUP_CONNECTIONS;j++){
if( (socketDest->NrOfRoutingGroups==0) || ((socketDest == SocketRoutingGroupAdminList[j].SocketRouteDest) &&
(SocketRoutingGroupAdminList[j].SoConId == SoConId) &&
(SocketRoutingGroupAdminList[j].Active == TRUE))){
if (SOAD_RX_UPPER_LAYER_TP == socketDest->RxUpperLayerType ){
if(ConnectionAdminList[SoConId].groupAdminRef->SocketConnectionGroupRef->SocketProtocol ==SOAD_SOCKET_PROT_UDP){
ret = socketDest->SoAdTpStartofReception(socketDest->RxPduRef ,\
rxPDU,rxPDU->SduLength, &bufferSizePtr);
if(ret == BUFREQ_OK){
ret = socketDest->SoAdTpCopyRxData(socketDest->RxPduRef,rxPDU,&bufferSizePtr);
if(ret == BUFREQ_NOT_OK){
socketDest->TpRxIndicationFunction(socketDest->RxPduRef, E_NOT_OK);
}else {
socketDest->TpRxIndicationFunction(socketDest->RxPduRef, E_OK);
retVal = TRUE;
break;
}
}
}else {
if (FALSE == SoAdTpReceiveStatus[SoConId].tpRxRequest){
ret = socketDest->SoAdTpStartofReception(socketDest->RxPduRef ,\
rxPDU,rxPDU->SduLength, &bufferSizePtr);
SoAdTpReceiveStatus[SoConId].tpRxRequest = TRUE;
if(ret == BUFREQ_OK){
ret = socketDest->SoAdTpCopyRxData(socketDest->RxPduRef,rxPDU,&bufferSizePtr);
if(ret == BUFREQ_NOT_OK){
socketDest->TpRxIndicationFunction(socketDest->RxPduRef, E_NOT_OK);
SoAdTpReceiveStatus[SoConId].tpRxRequest = FALSE;
break;
}else{
retVal = TRUE;
break;
}
}
}else {
ret = socketDest->SoAdTpCopyRxData(socketDest->RxPduRef,rxPDU,&bufferSizePtr);
if(ret == BUFREQ_NOT_OK){
socketDest->TpRxIndicationFunction(socketDest->RxPduRef, E_NOT_OK);
SoAdTpReceiveStatus[SoConId].tpRxRequest = FALSE;
break;
}else{
retVal = TRUE;
break;
}
}
}
}else {
SoAdCfgPtr->SocketRoute[SocketRoute].SocketRouteDest->RxIndicationFunction( socketDest->RxPduRef ,(PduInfoType*)rxPDU);
retVal = TRUE;
break;
}
}
}
}
if (retVal == TRUE){
break;
}
}
return retVal;
}
/**
* This function is called from SoAd_RxIndication().
* Enables Reception through TP-TCP communication
*
*
* @param SocketId The TcpIp socket
* @param SoConId Identifies the SoAd socket connection.
* @param BufPtr Pointer to the received data
* @param Length Data length of the received TCP segment
*/
static void processTpTcpRxCommunication (TcpIp_SocketIdType SocketId, SoAd_SoConIdType SoConId, uint8* BufPtr, uint16 Length) {
const SoAd_SocketRouteDestType* socketDest;
uint32 headerId = 0u;
uint32 pduLength = 0u;
/*lint -e578*/
PduInfoType rxPDU;
PduLengthType availablBufSize;
PduLengthType lenmin;
boolean tcpSegmented;
BufReq_ReturnType retValCopydata;
if (FALSE == SoAdTpReceiveStatus[SoConId].tpRxRequest){
//extract header
if (getPduHeader(BufPtr, Length, &headerId, &pduLength) == TRUE) {
for(uint32 i=0;i<SOAD_NR_OF_SOCKET_ROUTES;i++){
if( (SoAdCfgPtr->SocketRoute[i].RxPduHeaderId == headerId) && (soConInSocketRoute(SoConId, &(SoAdCfgPtr->SocketRoute[i])) == TRUE )){
socketDest = SoAdCfgPtr->SocketRoute[i].SocketRouteDest;
/** @req SWS_SOAD_00600 */
for(uint32 j=0;j<SOAD_NR_OF_SOCKET_ROUTING_GROUP_CONNECTIONS;j++){
if((socketDest->NrOfRoutingGroups==0) || (SocketRoutingGroupAdminList[j].SocketRouteDest==socketDest &&
SocketRoutingGroupAdminList[j].Active == TRUE)){
tcpSegmented = Length < (pduLength + SOAD_PDU_HEADER_LENGTH);
lenmin = (tcpSegmented == TRUE)? (Length-SOAD_PDU_HEADER_LENGTH): pduLength;
rxPDU.SduDataPtr = BufPtr;
rxPDU.SduLength = lenmin;
retValCopydata = socketDest->SoAdTpStartofReception(socketDest->RxPduRef ,\
&rxPDU, pduLength,&availablBufSize); //Call start of reception
//It is assumed that upper layer will reject if it does not have a buffer to hold pduLength
if (BUFREQ_OK == retValCopydata) {
retValCopydata = socketDest->SoAdTpCopyRxData(socketDest->RxPduRef ,\
&rxPDU, &availablBufSize);
if (tcpSegmented == FALSE) {
if (BUFREQ_OK == retValCopydata) {
socketDest->TpRxIndicationFunction(socketDest->RxPduRef, E_OK);
SoAdTpReceiveStatus[SoConId].tpRxRequest = FALSE;
} else {
//Since copying failed we terminate with the indication /* @req SWS_SoAd_00573 */
socketDest->TpRxIndicationFunction(socketDest->RxPduRef, E_NOT_OK);
SoAdTpReceiveStatus[SoConId].tpRxRequest = FALSE;
}
} else {
if (BUFREQ_OK == retValCopydata) {
SoAdTpReceiveStatus[SoConId].tpRxRequest = TRUE;
SoAdTpReceiveStatus[SoConId].remaingLen = pduLength -lenmin;
SoAdTpReceiveStatus[SoConId].socketRouteIndex = i;
SoAdTpReceiveStatus[SoConId].firstCopyCalled = TRUE;
} else {
//Since copying failed we terminate with the indication /* @req SWS_SoAd_00573 */
socketDest->TpRxIndicationFunction(socketDest->RxPduRef, E_NOT_OK);
SoAdTpReceiveStatus[SoConId].tpRxRequest = FALSE;
}
}
}
}
break;
}
}
}
}else {
/*lint -e{904} PERFORMANCE, Return statement is necessary to avoid multiple if loops (less cyclomatic complexity) and hence increase readability */
return;
}
} else {
socketDest = SoAdCfgPtr->SocketRoute[SoAdTpReceiveStatus[SoConId].socketRouteIndex].SocketRouteDest;
lenmin = Length > SoAdTpReceiveStatus[SoConId].remaingLen ? SoAdTpReceiveStatus[SoConId].remaingLen : Length;
rxPDU.SduDataPtr = BufPtr;
rxPDU.SduLength = lenmin;
retValCopydata = socketDest->SoAdTpCopyRxData(socketDest->RxPduRef ,\
&rxPDU, &availablBufSize);
if (BUFREQ_OK == retValCopydata) {
SoAdTpReceiveStatus[SoConId].remaingLen -= lenmin;
if (SoAdTpReceiveStatus[SoConId].remaingLen == 0){
SoAdTpReceiveStatus[SoConId].tpRxRequest = FALSE;
socketDest->TpRxIndicationFunction(socketDest->RxPduRef, E_OK);
}
} else {
SoAdTpReceiveStatus[SoConId].tpRxRequest = FALSE;
SoAdTpReceiveStatus[SoConId].firstCopyCalled = FALSE;
//Since copying failed we terminate with the indication /* @req SWS_SoAd_00573 */
socketDest->TpRxIndicationFunction(socketDest->RxPduRef, E_NOT_OK);
}
}
}
/**
* Check which SocketRoute matches the HeaderId and calls the corresponding
* RxIndication() function with the PDU in pduBuf with length pduLength.
* It also checks that the routing groups connected to this SocketRouteDest
* allows this.
* @param headerId The PDU Header Id of the received PDU.
* @param pduBuf Pointer to the buffer with PDU data.
* @param pduLength Length of the PDU data as indicated by the
* PDU Header length field.
* @return True if something is sent on a SocketRoute.
*/
static boolean routingReceptionPduHeader(uint16 SoConId, uint32 headerId, uint8* pduBuf, PduLengthType pduLength){
const SoAd_SocketRouteDestType* socketDest;
PduInfoType rxPDU;
PduLengthType availablBufSize;
BufReq_ReturnType retValCopydata;
boolean retVal = FALSE;
for(uint32 i=0;i<SOAD_NR_OF_SOCKET_ROUTES;i++){
if( (SoAdCfgPtr->SocketRoute[i].RxPduHeaderId == headerId) && (soConInSocketRoute(SoConId, &(SoAdCfgPtr->SocketRoute[i])) == TRUE )){
socketDest = SoAdCfgPtr->SocketRoute[i].SocketRouteDest;
/** @req SWS_SOAD_00600 */
for(uint32 j=0;j<SOAD_NR_OF_SOCKET_ROUTING_GROUP_CONNECTIONS;j++){
if((socketDest->NrOfRoutingGroups==0) || (SocketRoutingGroupAdminList[j].SocketRouteDest==socketDest &&
SocketRoutingGroupAdminList[j].Active == TRUE)){
rxPDU.SduDataPtr = pduBuf;
rxPDU.SduLength = pduLength;
if (SOAD_RX_UPPER_LAYER_TP == socketDest->RxUpperLayerType ) {
//Check if it is a Tp reception
retValCopydata = socketDest->SoAdTpStartofReception(socketDest->RxPduRef ,\
&rxPDU, pduLength,&availablBufSize); //Call start of reception
//It is assumed that upper layer will reject if it does not have a buffer to hold pduLength
if (BUFREQ_OK == retValCopydata) {
/* In UDP communication we cannot get fragmented messages for the same PDU header
* on different SoAd_RxIndication(). This is because UDP does not ascertain delivery
* in order they have been transmitted.
* i.e A SoAD PDU header indicating 600B cannot be split into two UDP messages
* 1. First meesage = PDU Header + 300 B
* 2. Second message = 300B (remaining bytes)
* We can thus further deduce that this results in only one call <Up>_[SoAd][Tp]CopyTxData()
*/
retValCopydata = socketDest->SoAdTpCopyRxData(socketDest->RxPduRef ,\
&rxPDU, &availablBufSize);
if (BUFREQ_OK == retValCopydata) {
socketDest->TpRxIndicationFunction(socketDest->RxPduRef, E_OK);
} else {
//Since copying failed we terminate with the indication /* @req SWS_SoAd_00573 */
socketDest->TpRxIndicationFunction(socketDest->RxPduRef, E_NOT_OK);
}
retVal = TRUE;
break;
}// @req SWS_SoAd_00572
} else {
socketDest->RxIndicationFunction( socketDest->RxPduRef , &rxPDU);
}
retVal = TRUE;
break;
}
}
}
if (retVal == TRUE) {
break;
}
}
return retVal;
}
/**
* Resets the Remote address from config for the Socket Connection indicated by SoConId
*
* @param SoConId Identifies the SoAd socket connection.
*/
static void setRemoteAddressFromCfg(SoAd_SoConIdType SoConId){
ConnectionAdminList[SoConId].remAddrInUse.Set = ConnectionAdminList[SoConId].groupAdminRef->SocketConnectionGroupRef->SoAdSocketConnection[ConnectionAdminList[SoConId].SocketConnectionRef->IndexInGroup].SoAdSocketRemoteAddress->Set;
for(uint32 j=0;j<4;j++){
ConnectionAdminList[SoConId].remAddrInUse.SocketRemoteIpAddress[j] = ConnectionAdminList[SoConId].groupAdminRef->SocketConnectionGroupRef->SoAdSocketConnection[ConnectionAdminList[SoConId].SocketConnectionRef->IndexInGroup].SoAdSocketRemoteAddress->SocketRemoteIpAddress[j];
}
ConnectionAdminList[SoConId].remAddrInUse.SocketRemotePort = ConnectionAdminList[SoConId].groupAdminRef->SocketConnectionGroupRef->SoAdSocketConnection[ConnectionAdminList[SoConId].SocketConnectionRef->IndexInGroup].SoAdSocketRemoteAddress->SocketRemotePort;
}
/**
* Changes the SoConModeType for the Socket Connection with id SoConId and
* calls the upper layer notofication function if configured.
*
* @param SoConId Identifies the SoAd socket connection.
* @param mode The mode to change to.
*/
static void changeMode( SoAd_SoConIdType SoConId, SoAd_SoConModeType mode){
ConnectionAdminList[SoConId].mode = mode;
if(ConnectionAdminList[SoConId].groupAdminRef->SocketConnectionGroupRef->SocketSoConModeChgNotification == TRUE){
/** @req SWS_SOAD_00597 */
ConnectionAdminList[SoConId].groupAdminRef->SocketConnectionGroupRef->SocketSoConModeChgNotificationFunction(SoConId, mode);
}
}
/**
* Updates the timer and checks if it has expired. Uses the main function period in milliseconds to update the timer.
*
* @param timer Pointer to uint32 downcounting timer.
* @return true if the timer expired this cycle. False otherwise.
*/
static boolean timerExpiredEvent(uint32* timer){
boolean retVal = FALSE;
if( *timer > 0 ){
if( *timer > SOAD_MAIN_FUNCTION_PERIOD_MS ){
*timer = *timer - SOAD_MAIN_FUNCTION_PERIOD_MS;
}else{
*timer = 0;
retVal = TRUE;
}
}
return retVal;
}
/* ----------------------------[public functions]----------------------------*/
void SoAd_Init( const SoAd_ConfigType* SoAdConfigPtr ){
uint32 soCon=0;
uint32 soConGroup=0;
uint32 soConInGroup=0;
uint32 rtGrpConnIdx=0;
uint32 pduCnt=0;
uint32 socketCnt=0;
/** @req SWS_SOAD_00216 */
VALIDATE_NO_RV(SoAdConfigPtr!=NULL, SOAD_INIT_ID, SOAD_E_INIT_FAILED)
VALIDATE_NO_RV(SoAdConfigPtr->PduRoute!=NULL, SOAD_INIT_ID, SOAD_E_INIT_FAILED)
//IMPROVEMENT Check rest of config, how much do we have to check?
SchM_Enter_SoAd_EA_0();
/** @req SWS_SOAD_00211 */
SoAdCfgPtr = SoAdConfigPtr;
/** @req SWS_SOAD_00723 */
for(soConGroup=0;soConGroup<SoAdConfigPtr->NrOfSocketConnectionGroups;soConGroup++){
ConnectionGroupAdminList[soConGroup].SocketId = TCPIP_SOCKETID_INVALID;
ConnectionGroupAdminList[soConGroup].SocketConnectionGroupRef = &(SoAdConfigPtr->SocketConnectionGroup[soConGroup]);
ConnectionGroupAdminList[soConGroup].mode = SOAD_SOCON_OFFLINE;
ConnectionGroupAdminList[soConGroup].IpAddrState = TCPIP_IPADDR_STATE_UNASSIGNED;
ConnectionGroupAdminList[soConGroup].localPortUsed = SoAdConfigPtr->SocketConnectionGroup[soConGroup].SocketLocalPort;
for(soConInGroup=0;soConInGroup<SoAdConfigPtr->SocketConnectionGroup[soConGroup].NrOfSocketConnections;soConInGroup++){
ConnectionAdminList[soCon].SocketId = TCPIP_SOCKETID_INVALID;
ConnectionAdminList[soCon].SocketConnectionRef = &(SoAdConfigPtr->SocketConnectionGroup[soConGroup].SoAdSocketConnection[soConInGroup]);
ConnectionAdminList[soCon].groupAdminRef = &(ConnectionGroupAdminList[soConGroup]);
ConnectionAdminList[soCon].opened = FALSE;
ConnectionAdminList[soCon].openRequest = FALSE;
ConnectionAdminList[soCon].closeRequest = FALSE;
ConnectionAdminList[soCon].closedByCloseSoCon = FALSE;
ConnectionAdminList[soCon].abort = FALSE;
ConnectionAdminList[soCon].mode = SOAD_SOCON_OFFLINE;
for(uint32 bufIndex=0;bufIndex<SoAdConfigPtr->SocketConnectionGroup[soConGroup].SoAdSocketConnection[soConInGroup].nPduUdpTxBufferSize;bufIndex++){
SoAdConfigPtr->SocketConnectionGroup[soConGroup].SoAdSocketConnection[soConInGroup].nPduUdpTxBuffer[bufIndex] = 0;
}
ConnectionAdminList[soCon].bytesInPduUdpBuffer = 0;
ConnectionAdminList[soCon].rxBuffer = CirqBuffStatCreate(SoAdConfigPtr->SocketConnectionGroup[soConGroup].SoAdSocketConnection[soConInGroup].TcpRxBuffer, SoAdConfigPtr->SocketConnectionGroup[soConGroup].SoAdSocketConnection[soConInGroup].TcpRxBufferSize, sizeof(uint8));
ConnectionAdminList[soCon].udpBufTimer = 0;
ConnectionAdminList[soCon].udpAliveTimer = 0;
ConnectionAdminList[soCon].remAddrInUse.Set = SoAdConfigPtr->SocketConnectionGroup[soConGroup].SoAdSocketConnection[soConInGroup].SoAdSocketRemoteAddress->Set;
ConnectionAdminList[soCon].remAddrInUse.Domain = SoAdConfigPtr->SocketConnectionGroup[soConGroup].SoAdSocketConnection[soConInGroup].SoAdSocketRemoteAddress->Domain;
ConnectionAdminList[soCon].remAddrInUse.SocketRemoteIpAddress[0] = SoAdConfigPtr->SocketConnectionGroup[soConGroup].SoAdSocketConnection[soConInGroup].SoAdSocketRemoteAddress->SocketRemoteIpAddress[0];
ConnectionAdminList[soCon].remAddrInUse.SocketRemoteIpAddress[1] = SoAdConfigPtr->SocketConnectionGroup[soConGroup].SoAdSocketConnection[soConInGroup].SoAdSocketRemoteAddress->SocketRemoteIpAddress[1];
ConnectionAdminList[soCon].remAddrInUse.SocketRemoteIpAddress[2] = SoAdConfigPtr->SocketConnectionGroup[soConGroup].SoAdSocketConnection[soConInGroup].SoAdSocketRemoteAddress->SocketRemoteIpAddress[2];
ConnectionAdminList[soCon].remAddrInUse.SocketRemoteIpAddress[3] = SoAdConfigPtr->SocketConnectionGroup[soConGroup].SoAdSocketConnection[soConInGroup].SoAdSocketRemoteAddress->SocketRemoteIpAddress[3];
ConnectionAdminList[soCon].remAddrInUse.SocketRemotePort = SoAdConfigPtr->SocketConnectionGroup[soConGroup].SoAdSocketConnection[soConInGroup].SoAdSocketRemoteAddress->SocketRemotePort;
soCon++;
}
}
for (pduCnt=0; pduCnt < SOAD_NR_OF_PDU_ROUTES; pduCnt++ ){
SoadTpTransStatus[pduCnt].firstCopyCalled = FALSE;
SoadTpTransStatus[pduCnt].tpTxRequest = FALSE;
SoadTpTransStatus[pduCnt].socketId = TCPIP_SOCKETID_INVALID;
SoadTpTransStatus[pduCnt].totalLen = 0;
SoadTpTransStatus[pduCnt].remainingLength = 0;
}
for (socketCnt=0; socketCnt < SOAD_NR_OF_SOCKET_CONNECTIONS; socketCnt++ ){
SoAdTpReceiveStatus[socketCnt].firstCopyCalled = FALSE;
SoAdTpReceiveStatus[socketCnt].tpRxRequest = FALSE;
SoAdTpReceiveStatus[socketCnt].remaingLen = 0;
SoAdTpReceiveStatus[socketCnt].socketRouteIndex = 0;
}
#if SOAD_NR_OF_PDU_ROUTING_GROUP_CONNECTIONS > 0
/** @req SWS_SOAD_00601 */
/** @req SWS_SOAD_00721 */
rtGrpConnIdx=0;
for(uint32 pduRouteIndex=0;pduRouteIndex<SOAD_NR_OF_PDU_ROUTES;pduRouteIndex++){
for(uint32 pduRouteDestIndex=0;pduRouteDestIndex<SoAdCfgPtr->PduRoute[pduRouteIndex].NrOfPduRouteDest;pduRouteDestIndex++){
for(uint32 routingGrpIndex=0;routingGrpIndex<SoAdCfgPtr->PduRoute[pduRouteIndex].PduRouteDest[pduRouteDestIndex].NrOfRoutingGroups;routingGrpIndex++){
if(SoAdCfgPtr->PduRoute[pduRouteIndex].PduRouteDest[pduRouteDestIndex].GroupUsed == TRUE){
for(uint32 indexInGroup=0;indexInGroup<ConnectionGroupAdminList[SoAdCfgPtr->PduRoute[pduRouteIndex].PduRouteDest[pduRouteDestIndex].Index].SocketConnectionGroupRef->NrOfSocketConnections;indexInGroup++){
uint16 SocketId = ConnectionGroupAdminList[SoAdCfgPtr->PduRoute[pduRouteIndex].PduRouteDest[pduRouteDestIndex].Index].SocketConnectionGroupRef->SoAdSocketConnection[indexInGroup].SocketId;
PduRoutingGroupAdminList[rtGrpConnIdx].PduRouteDest = &(SoAdCfgPtr->PduRoute[pduRouteIndex].PduRouteDest[pduRouteDestIndex]);
PduRoutingGroupAdminList[rtGrpConnIdx].RoutingGroup = SoAdCfgPtr->PduRoute[pduRouteIndex].PduRouteDest[pduRouteDestIndex].TxRoutingGroupRef[routingGrpIndex]->RoutingGroupId;
PduRoutingGroupAdminList[rtGrpConnIdx].SoConId = SocketId;
PduRoutingGroupAdminList[rtGrpConnIdx].Active = SoAdCfgPtr->PduRoute[pduRouteIndex].PduRouteDest[pduRouteDestIndex].TxRoutingGroupRef[routingGrpIndex]->RoutingGroupIsEnabledAtInit;
PduRoutingGroupAdminList[rtGrpConnIdx].TriggerTransmit = FALSE;
rtGrpConnIdx++;
}
}
else{
uint16 SocketId = SoAdCfgPtr->PduRoute[pduRouteIndex].PduRouteDest[pduRouteDestIndex].Index;
PduRoutingGroupAdminList[rtGrpConnIdx].PduRouteDest = &(SoAdCfgPtr->PduRoute[pduRouteIndex].PduRouteDest[pduRouteDestIndex]);
PduRoutingGroupAdminList[rtGrpConnIdx].RoutingGroup = SoAdCfgPtr->PduRoute[pduRouteIndex].PduRouteDest[pduRouteDestIndex].TxRoutingGroupRef[routingGrpIndex]->RoutingGroupId;
PduRoutingGroupAdminList[rtGrpConnIdx].SoConId = SocketId;
PduRoutingGroupAdminList[rtGrpConnIdx].Active = SoAdCfgPtr->PduRoute[pduRouteIndex].PduRouteDest[pduRouteDestIndex].TxRoutingGroupRef[routingGrpIndex]->RoutingGroupIsEnabledAtInit;
PduRoutingGroupAdminList[rtGrpConnIdx].TriggerTransmit = FALSE;
rtGrpConnIdx++;
}
}
}
}
#endif
rtGrpConnIdx=0;
for(uint32 socketRouteIndex=0;socketRouteIndex<SOAD_NR_OF_SOCKET_ROUTES;socketRouteIndex++){
if(SoAdConfigPtr->SocketRoute[socketRouteIndex].GroupUsed == TRUE){
for(uint32 indexInGroup=0;indexInGroup<ConnectionGroupAdminList[SoAdConfigPtr->SocketRoute[socketRouteIndex].Index].SocketConnectionGroupRef->NrOfSocketConnections;indexInGroup++){
for(uint32 routingGroupIndex=0;routingGroupIndex<SoAdConfigPtr->SocketRoute[socketRouteIndex].SocketRouteDest->NrOfRoutingGroups;routingGroupIndex++){
uint16 SocketId = ConnectionGroupAdminList[SoAdConfigPtr->SocketRoute[socketRouteIndex].Index].SocketConnectionGroupRef->SoAdSocketConnection[indexInGroup].SocketId;
SocketRoutingGroupAdminList[rtGrpConnIdx].SocketRouteDest = SoAdConfigPtr->SocketRoute[socketRouteIndex].SocketRouteDest;
SocketRoutingGroupAdminList[rtGrpConnIdx].RoutingGroup = SoAdConfigPtr->SocketRoute[socketRouteIndex].SocketRouteDest->RxRoutingGroupRef[routingGroupIndex]->RoutingGroupId;
SocketRoutingGroupAdminList[rtGrpConnIdx].SoConId = SocketId;
SocketRoutingGroupAdminList[rtGrpConnIdx].Active = SoAdConfigPtr->SocketRoute[socketRouteIndex].SocketRouteDest->RxRoutingGroupRef[routingGroupIndex]->RoutingGroupIsEnabledAtInit;
rtGrpConnIdx++;
}
}
}
else{
for(uint32 routingGroupIndex=0;routingGroupIndex<SoAdConfigPtr->SocketRoute[socketRouteIndex].SocketRouteDest->NrOfRoutingGroups;routingGroupIndex++){
uint16 SocketId = SoAdConfigPtr->SocketRoute[socketRouteIndex].Index;
SocketRoutingGroupAdminList[rtGrpConnIdx].SocketRouteDest = SoAdConfigPtr->SocketRoute[socketRouteIndex].SocketRouteDest;
SocketRoutingGroupAdminList[rtGrpConnIdx].RoutingGroup = SoAdConfigPtr->SocketRoute[socketRouteIndex].SocketRouteDest->RxRoutingGroupRef[routingGroupIndex]->RoutingGroupId;
SocketRoutingGroupAdminList[rtGrpConnIdx].SoConId = SocketId;
SocketRoutingGroupAdminList[rtGrpConnIdx].Active = SoAdConfigPtr->SocketRoute[socketRouteIndex].SocketRouteDest->RxRoutingGroupRef[routingGroupIndex]->RoutingGroupIsEnabledAtInit;
rtGrpConnIdx++;
}
}
}
for (TaskType task_id=0;task_id<OS_TASK_CNT;task_id++){
SocketCurrentTx[task_id].SoConId = SOAD_INVALID_CON_ID; /* No transfer going on */
}
SoAd_ModuleStatus = SOAD_INITIALIZED;
SchM_Exit_SoAd_EA_0();
}
Std_ReturnType SoAd_OpenSoCon( SoAd_SoConIdType SoConId ){
/** @req SWS_SOAD_00615 */
VALIDATE_RV(SoAd_ModuleStatus==SOAD_INITIALIZED, SOAD_OPEN_SOCON_ID, SOAD_E_NOTINIT, E_NOT_OK)
/** @req SWS_SOAD_00611 */
VALIDATE_RV(SoConId<SOAD_NR_OF_SOCKET_CONNECTIONS, SOAD_OPEN_SOCON_ID, SOAD_E_INV_ARG, E_NOT_OK)
/** @req SWS_SOAD_00528 */
VALIDATE_RV(ConnectionAdminList[SoConId].groupAdminRef->SocketConnectionGroupRef->SocketAutomaticSoConSetup==FALSE, SOAD_OPEN_SOCON_ID, SOAD_E_INV_ARG, E_NOT_OK)
/** @req SWS_SOAD_00588 */
if( ((ConnectionAdminList[SoConId].opened == TRUE) && (ConnectionAdminList[SoConId].closeRequest == TRUE)) ||
(ConnectionAdminList[SoConId].opened == FALSE)){
ConnectionAdminList[SoConId].openRequest = TRUE;
}
return E_OK;
}
Std_ReturnType SoAd_CloseSoCon( SoAd_SoConIdType SoConId, boolean abort ){
/** @req SWS_SOAD_00616 */
VALIDATE_RV(SoAd_ModuleStatus==SOAD_INITIALIZED, SOAD_CLOSE_SOCON_ID, SOAD_E_NOTINIT, E_NOT_OK)
/** @req SWS_SOAD_00612 */
VALIDATE_RV(SoConId<SOAD_NR_OF_SOCKET_CONNECTIONS, SOAD_CLOSE_SOCON_ID, SOAD_E_INV_ARG, E_NOT_OK)
/** @req SWS_SOAD_00529 */
VALIDATE_RV(ConnectionAdminList[SoConId].groupAdminRef->SocketConnectionGroupRef->SocketAutomaticSoConSetup==FALSE, SOAD_CLOSE_SOCON_ID, SOAD_E_INV_ARG, E_NOT_OK)
uint32 SocketRoute;
SoAd_SocketRouteDestType socketDest1;
const SoAd_SocketRouteDestType* socketDest;
socketDest = &socketDest1;
// IMPROVEMENT Investigate abort
ConnectionAdminList[SoConId].abort = abort;
/** @req SWS_SOAD_00588 */
if( ConnectionAdminList[SoConId].opened == TRUE ){
ConnectionAdminList[SoConId].closeRequest = TRUE;
}else{
ConnectionAdminList[SoConId].openRequest = FALSE;
}
for(SocketRoute=0;SocketRoute<SOAD_NR_OF_SOCKET_ROUTES;SocketRoute++){
if(soConInSocketRoute(SoConId, &(SoAdCfgPtr->SocketRoute[SocketRoute])) == TRUE){
socketDest = SoAdCfgPtr->SocketRoute[SocketRoute].SocketRouteDest;
break;
}
}
/** req This part of code is implemented based on sequence diagram 9.2 Rx TCP message of DoIP SWS */
if ((SOAD_RX_UPPER_LAYER_TP == socketDest->RxUpperLayerType )&& \
(SoAdCfgPtr->SocketRoute[SocketRoute].RxPduHeaderId == 0)&&\
(ConnectionAdminList[SoConId].groupAdminRef->SocketConnectionGroupRef->SocketProtocol == SOAD_SOCKET_PROT_TCP)) {
socketDest->TpRxIndicationFunction(socketDest->RxPduRef, E_OK);
SoAdTpReceiveStatus[SoConId].tpRxRequest = FALSE;
}
return E_OK;
}
void SoAd_LocalIpAddrAssignmentChg( TcpIp_LocalAddrIdType IpAddrId, TcpIp_IpAddrStateType State ){
/** @req SWS_SOAD_00279 */
VALIDATE_NO_RV(SoAd_ModuleStatus==SOAD_INITIALIZED, SOAD_LOCAL_IP_ADDR_ASSIGNMENT_CHG_ID, SOAD_E_NOTINIT)
#if defined(USE_DET) && (SOAD_DEV_ERROR_DETECT == STD_ON)
boolean found = FALSE;
#endif
for(uint32 soConGroup=0;soConGroup<SoAdCfgPtr->NrOfSocketConnectionGroups;soConGroup++){
if(ConnectionGroupAdminList[soConGroup].SocketConnectionGroupRef->SocketLocalAddressRef == IpAddrId){
ConnectionGroupAdminList[soConGroup].IpAddrState = State;
#if defined(USE_DET) && (SOAD_DEV_ERROR_DETECT == STD_ON)
found = TRUE;
#endif
if(ConnectionGroupAdminList[soConGroup].SocketConnectionGroupRef->SocketIpAddrAssignmentChgNotification == TRUE && ConnectionGroupAdminList[soConGroup].SocketConnectionGroupRef->SocketIpAddrAssignmentChgNotificationFunction != NULL){
for(uint32 soConIndex=0;soConIndex<ConnectionGroupAdminList[soConGroup].SocketConnectionGroupRef->NrOfSocketConnections;soConIndex++){
/** @req SWS_SOAD_00598 */
ConnectionGroupAdminList[soConGroup].SocketConnectionGroupRef->SocketIpAddrAssignmentChgNotificationFunction(ConnectionGroupAdminList[soConGroup].SocketConnectionGroupRef->SoAdSocketConnection[soConIndex].SocketId, State);
}
}
}
}
#if defined(USE_DET) && (SOAD_DEV_ERROR_DETECT == STD_ON)
/** @req SWS_SOAD_00280 */
VALIDATE_NO_RV(found==TRUE, SOAD_LOCAL_IP_ADDR_ASSIGNMENT_CHG_ID, SOAD_E_INV_ARG)
#endif
}
Std_ReturnType SoAd_SetRemoteAddr( SoAd_SoConIdType SoConId, const TcpIp_SockAddrType* RemoteAddrPtr ){
Std_ReturnType status;
status = E_OK;
/** @req SWS_SOAD_00628 */
VALIDATE_RV(SoAd_ModuleStatus==SOAD_INITIALIZED, SOAD_SET_REMOTE_ADDRESS_ID, SOAD_E_NOTINIT, E_NOT_OK)
// Should be a req here as for every other public function using SoConId
VALIDATE_RV(SoConId<SOAD_NR_OF_SOCKET_CONNECTIONS, SOAD_SET_REMOTE_ADDRESS_ID, SOAD_E_INV_ARG, E_NOT_OK)
/** @req SWS_SOAD_00531 */
VALIDATE_RV(ConnectionAdminList[SoConId].groupAdminRef->SocketConnectionGroupRef->SocketAutomaticSoConSetup==FALSE, SOAD_SET_REMOTE_ADDRESS_ID, SOAD_E_INV_ARG, E_NOT_OK)
/* ArcCore req */
VALIDATE_RV(RemoteAddrPtr!=NULL, SOAD_SET_REMOTE_ADDRESS_ID, SOAD_E_INV_ARG, E_NOT_OK)
/** @req SWS_SOAD_00532 */ // IMPROVEMENT (2) of req SWS_SOAD_00532
if((ConnectionAdminList[SoConId].mode != SOAD_SOCON_OFFLINE) && (ConnectionAdminList[SoConId].groupAdminRef->SocketConnectionGroupRef->SocketProtocol!=SOAD_SOCKET_PROT_UDP)){
status = E_NOT_OK;
} else {
/** @req SWS_SoAd_00699 */
if(RemoteAddrPtr->domain != ConnectionAdminList[SoConId].remAddrInUse.Domain){
DET_REPORTERROR(SOAD_MODULE_ID, 0, SOAD_SET_REMOTE_ADDRESS_ID, SOAD_E_INV_ARG);
/*lint -e{904} Return statement is necessary in case of reporting a DET error */
return E_NOT_OK;
}
SchM_Enter_SoAd_EA_0();
setRemoteAddress(SoConId, RemoteAddrPtr);
/** @req SWS_SoAd_00687 */
if( (ConnectionAdminList[SoConId].mode == SOAD_SOCON_ONLINE) && (hasWildcardsInAddress(SoConId)) ){
changeMode(SoConId, SOAD_SOCON_RECONNECT);
}
SchM_Exit_SoAd_EA_0();
}
return status;
}
void SoAd_MainFunction( void ){
PduIdType pduCnt;
SoAd_SoConIdType SoConId;
/** @req SWS_SOAD_00283 */
VALIDATE_NO_RV(SoAd_ModuleStatus==SOAD_INITIALIZED, SOAD_MAIN_FUNCTION_ID, SOAD_E_NOTINIT)
for (pduCnt=0; pduCnt < SOAD_NR_OF_PDU_ROUTES; pduCnt++ ){
if(SoadTpTransStatus[pduCnt].tpTxRequest == TRUE){
tpTransmitSubFunction(pduCnt);
}
}
for(uint16 i=0;i<SOAD_NR_OF_SOCKET_CONNECTIONS;i++){
Std_ReturnType socModified = E_NOT_OK;
/** @req SWS_SOAD_00588 */
if( (ConnectionAdminList[i].opened == TRUE) ){
if( (ConnectionAdminList[i].closeRequest == TRUE) && (ConnectionAdminList[i].mode != SOAD_SOCON_OFFLINE) ) {/** @req SWS_SOAD_00604 */
socModified = closeSocket(i, TRUE);
ConnectionAdminList[i].abort = FALSE;
ConnectionAdminList[i].opened = FALSE;
ConnectionAdminList[i].closeRequest = FALSE; // IMPROVEMENT Should this be done even if other criterias aren't fullfilled?
}
}else{
/** @req SWS_SOAD_00589 */
if( (ConnectionAdminList[i].openRequest == TRUE || (ConnectionAdminList[i].groupAdminRef->SocketConnectionGroupRef->SocketAutomaticSoConSetup == TRUE)) && // SWS_SoAd_00589 (2)
(ConnectionAdminList[i].SocketId == TCPIP_SOCKETID_INVALID) && // SWS_SoAd_00589 (1)
((ConnectionAdminList[i].SocketConnectionRef != NULL) && (ConnectionAdminList[i].remAddrInUse.Set == TRUE) ) &&// SWS_SoAd_00589 (3)
(ConnectionAdminList[i].groupAdminRef->IpAddrState == TCPIP_IPADDR_STATE_ASSIGNED ) ){ // SWS_SoAd_00589 (4)
socModified = openSocket(i);
ConnectionAdminList[i].opened = TRUE;
ConnectionAdminList[i].openRequest = FALSE;
}
}
/** @req SWS_SOAD_00586 */
/* "Reestablish" connection. What does that mean???. The SoCon can
* be in state Reconnect with or without a TcpIp Socket. If it has
* no TcpIp Socket it should try to get one, but what if it
* already has one? */
if( (socModified == E_NOT_OK) && (ConnectionAdminList[i].mode == SOAD_SOCON_RECONNECT) ){
switch (ConnectionAdminList[i].groupAdminRef->SocketConnectionGroupRef->GroupType) {
case SOAD_GROUPTYPE_INIT_TCP:
case SOAD_GROUPTYPE_LISTEN_TCP:
case SOAD_GROUPTYPE_LONELY_UDP:
if( ConnectionAdminList[i].SocketId == TCPIP_SOCKETID_INVALID ){
openSocket(i);
}
break;
case SOAD_GROUPTYPE_MULTI_UDP:
if( ConnectionAdminList[i].groupAdminRef->SocketId == TCPIP_SOCKETID_INVALID ){
openSocket(i);
}
break;
default:
break;
}
}
/** @req SWS_SOAD_00695 */
if( timerExpiredEvent( &(ConnectionAdminList[i].udpAliveTimer)) == TRUE ){ /* Cannot control the timer , lock it */
SchM_Enter_SoAd_EA_0();
changeMode(i, SOAD_SOCON_RECONNECT);
ConnectionAdminList[i].remAddrInUse.Set = ConnectionAdminList[i].SocketConnectionRef->SoAdSocketRemoteAddress->Set;
ConnectionAdminList[i].remAddrInUse.Domain = ConnectionAdminList[i].SocketConnectionRef->SoAdSocketRemoteAddress->Domain;
ConnectionAdminList[i].remAddrInUse.SocketRemoteIpAddress[0] = ConnectionAdminList[i].SocketConnectionRef->SoAdSocketRemoteAddress->SocketRemoteIpAddress[0];
ConnectionAdminList[i].remAddrInUse.SocketRemoteIpAddress[1] = ConnectionAdminList[i].SocketConnectionRef->SoAdSocketRemoteAddress->SocketRemoteIpAddress[1];
ConnectionAdminList[i].remAddrInUse.SocketRemoteIpAddress[2] = ConnectionAdminList[i].SocketConnectionRef->SoAdSocketRemoteAddress->SocketRemoteIpAddress[2];
ConnectionAdminList[i].remAddrInUse.SocketRemoteIpAddress[3] = ConnectionAdminList[i].SocketConnectionRef->SoAdSocketRemoteAddress->SocketRemoteIpAddress[3];
ConnectionAdminList[i].remAddrInUse.SocketRemotePort = ConnectionAdminList[i].SocketConnectionRef->SoAdSocketRemoteAddress->SocketRemotePort;
SchM_Exit_SoAd_EA_0();
}
}// end loop
/** @req SWS_SOAD_00544 */
for(uint32 i=0;i<SOAD_NR_OF_PDU_ROUTES;i++){
if(PduRouteAdminList[i].TxState == SOAD_TX_STATE_UDP_SENDING_DONE ){
if(SoAdCfgPtr->PduRoute[i].TxConfirmationFunction!=NULL){
SoAdCfgPtr->PduRoute[i].TxConfirmationFunction(SoAdCfgPtr->PduRoute[i].TxPduRef);
}
PduRouteAdminList[i].TxState = SOAD_TX_STATE_INACTIVE;
}
}
/** @req SWS_SOAD_00550 */
for(uint16 i=0;i<SOAD_NR_OF_SOCKET_CONNECTIONS;i++){
if( timerExpiredEvent( &(ConnectionAdminList[i].udpBufTimer)) == TRUE ){
transmit(i, ConnectionAdminList[i].bytesInPduUdpBuffer, ConnectionAdminList[i].SocketConnectionRef->nPduUdpTxBuffer, 0);
}
}
/** @req SWS_SOAD_00665 */
for(uint16 pduRouteIndex=0;pduRouteIndex<SOAD_NR_OF_PDU_ROUTES;pduRouteIndex++){
if( PduRouteAdminList[pduRouteIndex].trigger.mode != SOAD_TRIGGERTRANSMITMODE_OFF ){
/** @req SWS_SOAD_00728 */
PduInfoType Pdu = {.SduDataPtr=SoAd_triggerTransmitBuffer, .SduLength=TRIGGER_TRANMSIT_BUFFER_SIZE};
if(SoAdCfgPtr->PduRoute[pduRouteIndex].TriggerTransmitFunction!=NULL){
SoAdCfgPtr->PduRoute[pduRouteIndex].TriggerTransmitFunction(pduRouteIndex, &Pdu );
}
for(uint32 pduRouteDestIndex=0;pduRouteDestIndex<SoAdCfgPtr->PduRoute[pduRouteIndex].NrOfPduRouteDest;pduRouteDestIndex++){
for(uint32 routingGrpIndex=0;routingGrpIndex<SoAdCfgPtr->PduRoute[pduRouteIndex].PduRouteDest[pduRouteDestIndex].NrOfRoutingGroups;routingGrpIndex++){
if( PduRouteAdminList[pduRouteIndex].trigger.RoutingGroup == SoAdCfgPtr->PduRoute[pduRouteIndex].PduRouteDest[pduRouteDestIndex].TxRoutingGroupRef[routingGrpIndex]->RoutingGroupId){
if(SoAdCfgPtr->PduRoute[pduRouteIndex].PduRouteDest[pduRouteDestIndex].GroupUsed == TRUE){
for(uint32 indexInGroup=0;indexInGroup<ConnectionGroupAdminList[SoAdCfgPtr->PduRoute[pduRouteIndex].PduRouteDest[pduRouteDestIndex].Index].SocketConnectionGroupRef->NrOfSocketConnections;indexInGroup++){
uint16 SocketId = ConnectionGroupAdminList[SoAdCfgPtr->PduRoute[pduRouteIndex].PduRouteDest[pduRouteDestIndex].Index].SocketConnectionGroupRef->SoAdSocketConnection[indexInGroup].SocketId;
if( (PduRouteAdminList[pduRouteIndex].trigger.mode == SOAD_TRIGGERTRANSMITMODE_ROUTINGGROUP_AND_SOCON && SocketId == PduRouteAdminList[pduRouteIndex].trigger.SoConId) ||
(PduRouteAdminList[pduRouteIndex].trigger.mode == SOAD_TRIGGERTRANSMITMODE_ROUTINGGROUP)){
boolean notUsed;
SoConId = ConnectionGroupAdminList[SoAdCfgPtr->PduRoute[pduRouteIndex].PduRouteDest[pduRouteDestIndex].Index].SocketConnectionGroupRef->SoAdSocketConnection[indexInGroup].SocketId;
if(ifTransmitSubFunction(SoConId, pduRouteIndex, &(SoAdCfgPtr->PduRoute[pduRouteIndex].PduRouteDest[pduRouteDestIndex]), (const PduInfoType*)&Pdu, ¬Used)==E_NOT_OK){
// error
}
PduRouteAdminList[pduRouteIndex].trigger.RoutingGroup = 0;
PduRouteAdminList[pduRouteIndex].trigger.SoConId = 0;
}
}
}
else{
if( (PduRouteAdminList[pduRouteIndex].trigger.mode == SOAD_TRIGGERTRANSMITMODE_ROUTINGGROUP_AND_SOCON && SoAdCfgPtr->PduRoute[pduRouteIndex].PduRouteDest[pduRouteDestIndex].Index == PduRouteAdminList[pduRouteIndex].trigger.SoConId) ||
(PduRouteAdminList[pduRouteIndex].trigger.mode == SOAD_TRIGGERTRANSMITMODE_ROUTINGGROUP) ){
boolean notUsed;
SoConId = SoAdCfgPtr->PduRoute[pduRouteIndex].PduRouteDest[pduRouteDestIndex].Index;
if(ifTransmitSubFunction(SoConId, pduRouteIndex, &(SoAdCfgPtr->PduRoute[pduRouteIndex].PduRouteDest[pduRouteDestIndex]), (const PduInfoType*)&Pdu, ¬Used)==E_NOT_OK){
// error
}
PduRouteAdminList[pduRouteIndex].trigger.RoutingGroup = 0;
PduRouteAdminList[pduRouteIndex].trigger.SoConId = 0;
}
}
}
}
}
PduRouteAdminList[pduRouteIndex].trigger.mode = SOAD_TRIGGERTRANSMITMODE_OFF;
}
}
}
/*lint -e{818} Pointer parameter 'PduInfoPtr' could be declared as pointing to const. */
/* No re-entrancy issue here , since called from TCPIP layer */
/* IMPROVEMENT - reduce the work in this function as much as possible */
void SoAd_RxIndication( TcpIp_SocketIdType SocketId, const TcpIp_SockAddrType* RemoteAddrPtr, uint8* BufPtr, uint16 Length ){
/** @req SWS_SOAD_00264 */
VALIDATE_NO_RV(SoAd_ModuleStatus==SOAD_INITIALIZED, SOAD_RX_INDICATION_ID, SOAD_E_NOTINIT)
/** @req SWS_SOAD_00268 */
VALIDATE_NO_RV(RemoteAddrPtr!=NULL, SOAD_RX_INDICATION_ID, SOAD_E_INV_ARG)
uint32 groupIndex;
uint32 connIndexInGroup;
const SoAd_SocketConnectionGroupType* grp;
SoAd_SoConIdType SoConId = 0;
SoConId = SOCONID_VALUE_ZERO;
boolean groupSocket;
PduInfoType rxPDU;
TcpIp_SockAddrType previousAddr = {.domain = TCPIP_AF_INET, .port = 0, .addr = {0}};
boolean remAddressOverwritten = FALSE;
/** @req SWS_SOAD_00562 */
groupSocket = getGroupIndexFromSocketId(SocketId, &groupIndex);
if(groupSocket == FALSE){
if(getSoConIdFromSocketId(SocketId, &SoConId)==FALSE){
/** @req SWS_SOAD_00267 */
DET_REPORTERROR(SOAD_MODULE_ID, 0, SOAD_RX_INDICATION_ID, SOAD_E_INV_SOCKETID);
}
groupIndex = ConnectionAdminList[SoConId].SocketConnectionRef->GroupNr;
}
else{
SoConId = 0;
}
grp = ConnectionGroupAdminList[groupIndex].SocketConnectionGroupRef;
// IMPROVEMENT IS THIS CORRECT!!! We now run the bestMatch algo first to get only one SoCon.
if(ConnectionGroupAdminList[groupIndex].SocketConnectionGroupRef->GroupType == SOAD_GROUPTYPE_MULTI_UDP){
if(runBestMatch(ConnectionGroupAdminList[groupIndex].SocketConnectionGroupRef, RemoteAddrPtr, &connIndexInGroup) == FALSE){
// IMPROVEMENT Set DET error
/*lint -e{904} PERFORMANCE, Return statement is necessary to avoid multiple if loops (less cyclomatic complexity) and hence increase readability */
return;
}else{
SoConId = ConnectionGroupAdminList[groupIndex].SocketConnectionGroupRef->SoAdSocketConnection[connIndexInGroup].SocketId;
}
}
/**
* Workaround for specification oversight, reported in: https://arccore.atlassian.net/browse/CORE-3115
*
* This workaround will become ineffective if req SWS_SOAD_00582 is implemented.
*/
#if (SOAD_XCP_SUPPORT == STD_ON) // If XCP module is linked in the SoAd module
for(uint32 i = 0; i < SOAD_NR_OF_SOCKET_ROUTES; i++){
// If current message is meant for XCP
if (SoAdCfgPtr->SocketRoute[i].SocketRouteDest->RxIndicationFunction == Xcp_SoAdIfRxIndication) {
if (soConInSocketRoute(SoConId, &(SoAdCfgPtr->SocketRoute[i])) == TRUE) {
// Then reset current remote address to its configured remote address
// if it's an automatic UDP connection configured to accept any remote address.
uint32 grpIdx = ConnectionAdminList[SoConId].SocketConnectionRef->IndexInGroup;
SoAd_SocketRemoteAddressType* setSoAdSocketRemoteAddress = grp->SoAdSocketConnection[grpIdx].SoAdSocketRemoteAddress;
if ((grp->SocketProtocol == SOAD_SOCKET_PROT_UDP) && (grp->SocketAutomaticSoConSetup == TRUE) &&
(((setSoAdSocketRemoteAddress->SocketRemoteIpAddress[0] == TCPIP_IPADDR_ANY) &&
(setSoAdSocketRemoteAddress->SocketRemoteIpAddress[1] == TCPIP_IPADDR_ANY) &&
(setSoAdSocketRemoteAddress->SocketRemoteIpAddress[2] == TCPIP_IPADDR_ANY) &&
(setSoAdSocketRemoteAddress->SocketRemoteIpAddress[3] == TCPIP_IPADDR_ANY)) ||
(setSoAdSocketRemoteAddress->SocketRemotePort == TCPIP_PORT_ANY))) {
SchM_Enter_SoAd_EA_0();
changeMode(SoConId, SOAD_SOCON_RECONNECT);
setRemoteAddressFromCfg(SoConId);
SchM_Exit_SoAd_EA_0();
}
}
}
}
#endif
/** @req SWS_SOAD_00592 */
if( (ConnectionAdminList[SoConId].mode != SOAD_SOCON_ONLINE) &&
(grp->SocketProtocol == SOAD_SOCKET_PROT_UDP) &&
(grp->SocketProtocolUdp->SocketUdpListenOnly == FALSE) &&
(grp->SocketMsgAcceptanceFilterEnabled == TRUE) &&
(hasWildcardsInAddress(SoConId)==TRUE) &&
(runMessageAcceptancePolicy() == TRUE)){
SchM_Enter_SoAd_EA_0();
for(uint32 i=0;i<4;i++){
previousAddr.addr[i] = ConnectionAdminList[SoConId].remAddrInUse.SocketRemoteIpAddress[i];
ConnectionAdminList[SoConId].remAddrInUse.SocketRemoteIpAddress[i] = RemoteAddrPtr->addr[i];
}
previousAddr.port = ConnectionAdminList[SoConId].remAddrInUse.SocketRemotePort;
ConnectionAdminList[SoConId].remAddrInUse.SocketRemotePort = RemoteAddrPtr->port;
changeMode(SoConId, SOAD_SOCON_ONLINE);
SchM_Exit_SoAd_EA_0();
remAddressOverwritten = TRUE;
}
/** @req SWS_SOAD_00694 */
if( (grp->SocketProtocol == SOAD_SOCKET_PROT_UDP) && (grp->SocketProtocolUdp->UdpAliveSupervisionTimeout>0) &&
( (ConnectionAdminList[SoConId].udpAliveTimer > 0) || (remAddressOverwritten == TRUE) ) ){
SchM_Enter_SoAd_EA_0();
ConnectionAdminList[SoConId].udpAliveTimer = grp->SocketProtocolUdp->UdpAliveSupervisionTimeout;
SchM_Exit_SoAd_EA_0();
}
/** @req SWS_SOAD_00657 */
// runMessageAcceptancePolicy();
/** @req SWS_SOAD_00559 */
/** @req SWS_SOAD_00567 */
if( ConnectionGroupAdminList[groupIndex].SocketConnectionGroupRef->PduHeaderEnable == TRUE ){
/*Header Enable */
uint32 headerId = 0u;
uint32 pduLength = 0u;
uint32 indexInBuf = 0u;
/* @req SWS_SOAD_00690 *//* With Header IF - TP : UDP */
if(IS_UDP_GRP(groupIndex)){
/* @req SWS_SOAD_00709 */
if(ConnectionGroupAdminList[groupIndex].SocketConnectionGroupRef->SocketProtocolUdp->SocketUdpStrictHeaderLenCheckEnabled == TRUE){
uint32 tempIndex = indexInBuf;
while( (tempIndex < Length) && (getPduHeader(&BufPtr[tempIndex], Length-tempIndex, &headerId, &pduLength) == TRUE) ){
tempIndex = tempIndex + SOAD_PDU_HEADER_LENGTH + pduLength;
}
if(tempIndex != Length){
/*lint -e{904} PERFORMANCE, Return statement is necessary to avoid multiple if loops (less cyclomatic complexity) and hence increase readability */
return;
}
}
while(indexInBuf<Length){
if( getPduHeader(&BufPtr[indexInBuf], Length-indexInBuf, &headerId, &pduLength) == TRUE ){
indexInBuf+=SOAD_PDU_HEADER_LENGTH;
routingReceptionPduHeader(SoConId, headerId, &(BufPtr[indexInBuf]), pduLength);
indexInBuf += pduLength;
}else{
/*lint -e{904} PERFORMANCE, Return statement is necessary to avoid multiple if loops (less cyclomatic complexity) and hence increase readability */
return;
}
}
} else { /* With Header IF - TP : TCP */
uint8 SocketRoute1;
const SoAd_SocketRouteDestType* socketDest;
socketDest = NULL;
for(SocketRoute1=0; SocketRoute1<SOAD_NR_OF_SOCKET_ROUTES; SocketRoute1++){
if(soConInSocketRoute(SoConId, &(SoAdCfgPtr->SocketRoute[SocketRoute1])) == TRUE ){
socketDest = SoAdCfgPtr->SocketRoute[SocketRoute1].SocketRouteDest;
break;
}
}
if (socketDest != NULL) {
if (SOAD_RX_UPPER_LAYER_TP == socketDest->RxUpperLayerType ) { /* With header TP - TCP*/
processTpTcpRxCommunication(SocketId, SoConId, BufPtr, Length);
} else { /* With header IF - TCP*/
while(indexInBuf < Length && (CirqBuff_Full(&(ConnectionAdminList[SoConId].rxBuffer)) == FALSE)){
// Copy to buffer
/** @req SWS_SOAD_00566 */
while( (indexInBuf < Length) && (CirqBuffPush(&(ConnectionAdminList[SoConId].rxBuffer), (void *)&(BufPtr[indexInBuf])) == 0) ){
indexInBuf++;
}
if( CirqBuff_Size(&(ConnectionAdminList[SoConId].rxBuffer)) > SOAD_PDU_HEADER_LENGTH ){
headerId = 0;
pduLength = 0;
headerId = headerId | (*((uint8*)CirqBuff_Peek(&(ConnectionAdminList[SoConId].rxBuffer), 0 ))<<24);
headerId = headerId | (*((uint8*)CirqBuff_Peek(&(ConnectionAdminList[SoConId].rxBuffer), 1 ))<<16);
headerId = headerId | (*((uint8*)CirqBuff_Peek(&(ConnectionAdminList[SoConId].rxBuffer), 2 ))<<8);
headerId = headerId | (*((uint8*)CirqBuff_Peek(&(ConnectionAdminList[SoConId].rxBuffer), 3 )));
pduLength = pduLength | (*((uint8*)CirqBuff_Peek(&(ConnectionAdminList[SoConId].rxBuffer), 4 ))<<24);
pduLength = pduLength | (*((uint8*)CirqBuff_Peek(&(ConnectionAdminList[SoConId].rxBuffer), 5 ))<<16);
pduLength = pduLength | (*((uint8*)CirqBuff_Peek(&(ConnectionAdminList[SoConId].rxBuffer), 6 ))<<8);
pduLength = pduLength | (*((uint8*)CirqBuff_Peek(&(ConnectionAdminList[SoConId].rxBuffer), 7 )));
if( CirqBuff_Size(&(ConnectionAdminList[SoConId].rxBuffer)) >= (sint32)(SOAD_PDU_HEADER_LENGTH + pduLength) ){
uint8 tempByte;
for(uint32 i=0;i<8;i++){
CirqBuffPop( &(ConnectionAdminList[SoConId].rxBuffer), (void*)&tempByte );
}
for(uint32 i=0;i<pduLength;i++){
if( CirqBuffPop( &(ConnectionAdminList[SoConId].rxBuffer), (void*)(&(SoAd_tmpTcpRxBuf[i])) ) > 0){
// IMPROVEMENT Set DET error
/*lint -e{904} PERFORMANCE, Return statement is necessary to avoid multiple if loops (less cyclomatic complexity) and hence increase readability */
return;
}
}
routingReceptionPduHeader(SoConId, headerId, &(SoAd_tmpTcpRxBuf[0]), pduLength);
}
}
}
if((CirqBuff_Full(&(ConnectionAdminList[SoConId].rxBuffer)) == TRUE) && (indexInBuf < Length)){
/** @req SWS_SOAD_00693 */
DET_REPORTERROR(SOAD_MODULE_ID, 0, SOAD_RX_INDICATION_ID, SOAD_E_NOBUFS);
/*lint -e{904} PERFORMANCE, Return statement is necessary in case of reporting a DET error */
return;
}
}
}
}
}else{ /* Without header IF - TP : UDP & TCP */
/** @req SWS_SOAD_00563 */
rxPDU.SduLength = Length;
rxPDU.SduDataPtr = (uint8* )BufPtr;
if((rxPDU.SduLength == 0) && (ConnectionGroupAdminList[groupIndex].SocketConnectionGroupRef->PduHeaderEnable==FALSE)){
// Skip further processing
/** @req SWS_SOAD_00710 */
if(remAddressOverwritten==TRUE){
SchM_Enter_SoAd_EA_0();
for(uint32 i=0;i<4;i++){
ConnectionAdminList[SoConId].remAddrInUse.SocketRemoteIpAddress[i] = previousAddr.addr[i];
}
ConnectionAdminList[SoConId].remAddrInUse.SocketRemotePort = previousAddr.port;
changeMode(SoConId, SOAD_SOCON_RECONNECT);
SchM_Exit_SoAd_EA_0();
}
/** @req SWS_SOAD_00564 */
if(ConnectionGroupAdminList[groupIndex].SocketConnectionGroupRef->SocketProtocol == SOAD_SOCKET_PROT_TCP){
TcpIp_TcpReceived(SocketId, Length);
}
/*lint -e{904} PERFORMANCE, Return statement is necessary to avoid multiple if loops (less cyclomatic complexity) and hence increase readability */
return;
}
/** @req SWS_SOAD_00600 */
routingReceptionNoHeader(SoConId, &rxPDU);
}
/** @req SWS_SOAD_00564 */
if(!IS_UDP_GRP(groupIndex) ){
TcpIp_TcpReceived(SocketId, Length);
}
}
void SoAd_TcpConnected( TcpIp_SocketIdType SocketId ){
/** @req SWS_SOAD_00274 */
VALIDATE_NO_RV(SoAd_ModuleStatus==SOAD_INITIALIZED, SOAD_TCP_CONNECTED_ID, SOAD_E_NOTINIT)
const SoAd_SocketConnectionGroupType* grp;
SoAd_SoConIdType SoConId;
SoConId = SOCONID_VALUE_ZERO;
if(getSoConIdFromSocketId(SocketId, &SoConId)==FALSE){
/** @req SWS_SOAD_00275 */
DET_REPORTERROR(SOAD_MODULE_ID, 0, SOAD_TCP_CONNECTED_ID, SOAD_E_INV_SOCKETID);
/*lint -e{904} Return statement is necessary in case of reporting a DET error */
return;
}
grp = ConnectionAdminList[SoConId].groupAdminRef->SocketConnectionGroupRef;
/** @req SWS_SOAD_00593 */
if( (ConnectionAdminList[SoConId].mode != SOAD_SOCON_ONLINE) &&
(grp->SocketProtocol == SOAD_SOCKET_PROT_TCP) &&
(grp->SocketProtocolTcp->SocketTcpInitiate == TRUE)){
SchM_Enter_SoAd_EA_0();
changeMode(SoConId, SOAD_SOCON_ONLINE);
SchM_Exit_SoAd_EA_0();
}
}
Std_ReturnType SoAd_TcpAccepted( TcpIp_SocketIdType SocketId, TcpIp_SocketIdType SocketIdConnected, const TcpIp_SockAddrType* RemoteAddrPtr ){
/** @req SWS_SOAD_00272 */
VALIDATE_RV(SoAd_ModuleStatus==SOAD_INITIALIZED, SOAD_TCP_ACCEPTED_ID, SOAD_E_NOTINIT, E_NOT_OK)
boolean retVal = E_NOT_OK;
const SoAd_SocketConnectionGroupType* grp;
SoAd_SoConIdType SoConId;
uint32 GroupIndex;
uint32 ConnIndexInGroup;
//boolean bestMatchFound = FALSE;
if(getGroupIndexFromSocketId(SocketId, &GroupIndex)==FALSE){
/** @req SWS_SOAD_00273 */
DET_REPORTERROR(SOAD_MODULE_ID, 0, SOAD_TCP_ACCEPTED_ID, SOAD_E_INV_SOCKETID);
/*lint -e{904} Return statement is necessary in case of reporting a DET error */
return E_NOT_OK;
}
grp = ConnectionGroupAdminList[GroupIndex].SocketConnectionGroupRef;
/** @req SWS_SOAD_00636 */
if( (grp->SocketProtocolTcp->SocketTcpInitiate == FALSE) ){
if( (grp->SocketMsgAcceptanceFilterEnabled == FALSE) && (ConnectionGroupAdminList[GroupIndex].mode != SOAD_SOCON_ONLINE) ){
// IMPROVEMENT Maybe generate a cross reference from the grouplist to the connectionlist so we don't have to loop
for(SoConId=0;SoConId<SOAD_NR_OF_SOCKET_CONNECTIONS;SoConId++){
// MsgAccepFilter==FALSE implies: One and only one connection in the group
if(&(grp->SoAdSocketConnection[0]) == ConnectionAdminList[SoConId].SocketConnectionRef){
SchM_Enter_SoAd_EA_0();
ConnectionAdminList[SoConId].SocketId = SocketIdConnected;
changeMode(SoConId, SOAD_SOCON_ONLINE);
SchM_Exit_SoAd_EA_0();
retVal = E_OK;
break;
}
}
}
/** @req SWS_SOAD_00594 */
else if(runBestMatch(grp, RemoteAddrPtr, &ConnIndexInGroup) == TRUE){
// IMPROVEMENT Maybe generate a cross reference from the grouplist to the connectionlist so we don't have to loop
for(SoConId=0;SoConId<SOAD_NR_OF_SOCKET_CONNECTIONS;SoConId++){
if(&(grp->SoAdSocketConnection[ConnIndexInGroup]) == ConnectionAdminList[SoConId].SocketConnectionRef){
SchM_Enter_SoAd_EA_0();
setRemoteAddress(SoConId, RemoteAddrPtr);
ConnectionAdminList[SoConId].SocketId = SocketIdConnected;
changeMode(SoConId, SOAD_SOCON_ONLINE);
SchM_Exit_SoAd_EA_0();
retVal = E_OK;
break;
}
}
}
else {
/* MISRA */
}
}
return retVal;
}
void SoAd_TcpIpEvent( TcpIp_SocketIdType SocketId, TcpIp_EventType Event ){
boolean status;
status = TRUE;
/** @req SWS_SOAD_00276 */
VALIDATE_NO_RV(SoAd_ModuleStatus==SOAD_INITIALIZED, SOAD_TCP_IP_EVENT, SOAD_E_NOTINIT)
/** @req SWS_SOAD_00278 */
/*lint -e{645, 685} CONFIGURATION */
VALIDATE_NO_RV(Event<=TCPIP_UDP_CLOSED, SOAD_TCP_IP_EVENT, SOAD_E_INV_ARG)
const SoAd_SocketConnectionGroupType* grp;
SoAd_SoConIdType SoConId;
uint32 GroupIndex;
boolean groupSocketUsed;
SoConId = SOCONID_VALUE_ZERO;
GroupIndex= SOAD_GROUP_INDEX_VALUE_ZERO;
uint32 SocketRoute;
SoAd_SocketRouteDestType socketDest1;
const SoAd_SocketRouteDestType* socketDest;
socketDest = &socketDest1;
if(getSoConIdFromSocketId(SocketId, &SoConId)==FALSE){
/** @req SWS_SOAD_00277 */
DET_REPORTERROR(SOAD_MODULE_ID, 0, SOAD_TCP_IP_EVENT, SOAD_E_INV_SOCKETID);
/*lint -e{904} Return statement is necessary in case of reporting a DET error */
return;
}
groupSocketUsed = getGroupIndexFromSocketId(SocketId, &GroupIndex);
grp = ConnectionAdminList[SoConId].groupAdminRef->SocketConnectionGroupRef;
switch (Event) {
/** @req SWS_SOAD_00643 */
case TCPIP_UDP_CLOSED:
SchM_Enter_SoAd_EA_0();
if( grp->NrOfSocketConnections == 1 ){
ConnectionAdminList[SoConId].SocketId = TCPIP_SOCKETID_INVALID;
// Reset the address. This is not in the SoAd Requirements but it should be!
setRemoteAddressFromCfg(SoConId);
}else{
if(groupSocketUsed == FALSE){
//IMPROVEMENT Det error. An UDP group with more than one connection should use group socket.
status = FALSE;
} else {
ConnectionGroupAdminList[GroupIndex].SocketId = TCPIP_SOCKETID_INVALID;
for(uint16 i=0;i<SOAD_NR_OF_SOCKET_CONNECTIONS;i++){
if( (ConnectionAdminList[i].groupAdminRef == &(ConnectionGroupAdminList[GroupIndex])) && (ConnectionAdminList[i].mode == SOAD_SOCON_ONLINE) ){
//Close this connection
if( ConnectionAdminList[SoConId].closedByCloseSoCon == TRUE ){
changeMode(i, SOAD_SOCON_OFFLINE);
}
else{
changeMode(i, SOAD_SOCON_RECONNECT);
}
// Reset the address. This is not in the SoAd Requirements but it should be!
setRemoteAddressFromCfg(i);
}
}
}
}
if (status == TRUE) {
// Should be able to reset this now.
ConnectionAdminList[SoConId].closedByCloseSoCon = FALSE;
}
SchM_Exit_SoAd_EA_0();
break;
case TCPIP_TCP_CLOSED:
for(SocketRoute=0;SocketRoute<SOAD_NR_OF_SOCKET_ROUTES;SocketRoute++){
if(soConInSocketRoute(SoConId, &(SoAdCfgPtr->SocketRoute[SocketRoute])) == TRUE){
socketDest = SoAdCfgPtr->SocketRoute[SocketRoute].SocketRouteDest;
break;
}
}
/** req This part of code is implemented based on sequence diagram 9.2 Rx TCP message of DoIP SWS */
if ((SOAD_RX_UPPER_LAYER_TP == socketDest->RxUpperLayerType )&& \
(SoAdCfgPtr->SocketRoute[SocketRoute].RxPduHeaderId == 0)&&\
(ConnectionAdminList[SoConId].groupAdminRef->SocketConnectionGroupRef->SocketProtocol == SOAD_SOCKET_PROT_TCP)) {
socketDest->TpRxIndicationFunction(socketDest->RxPduRef, E_OK);
SoAdTpReceiveStatus[SoConId].tpRxRequest = FALSE;
}
break;
case TCPIP_TCP_RESET:
/** @req SWS_SOAD_00645 */
SchM_Enter_SoAd_EA_0();
if(groupSocketUsed==TRUE){
ConnectionGroupAdminList[GroupIndex].SocketId = TCPIP_SOCKETID_INVALID;
}
else{
/** @req SWS_SOAD_00646 */
ConnectionAdminList[SoConId].SocketId = TCPIP_SOCKETID_INVALID;
if(ConnectionAdminList[SoConId].mode == SOAD_SOCON_ONLINE){
if( ConnectionAdminList[SoConId].closedByCloseSoCon == TRUE ){
changeMode(SoConId, SOAD_SOCON_OFFLINE);
}
else{
changeMode(SoConId, SOAD_SOCON_RECONNECT);
}
}
// Reset the address. This is not in the SoAd Requirements but it should be!
setRemoteAddressFromCfg(SoConId);
}
SchM_Exit_SoAd_EA_0();
break;
case TCPIP_TCP_FIN_RECEIVED:
/** @req SWS_SOAD_00688 */
TcpIp_Close(ConnectionAdminList[SoConId].SocketId, FALSE );
break;
default:
break;
}
if (status == TRUE) {
// IMPROVEMENT Should be able to reset this now.
SchM_Enter_SoAd_EA_0();
ConnectionAdminList[SoConId].closedByCloseSoCon = FALSE;
SchM_Exit_SoAd_EA_0();
}
}
Std_ReturnType SoAd_IfTransmit( PduIdType SoAdSrcPduId, const PduInfoType* SoAdSrcPduInfoPtr ){
/** @req SWS_SOAD_00213 */
VALIDATE_RV(SoAd_ModuleStatus==SOAD_INITIALIZED, SOAD_IF_TRANSMIT_ID, SOAD_E_NOTINIT, E_NOT_OK)
/** @req SWS_SOAD_00214 */
VALIDATE_RV(SoAdSrcPduId<SOAD_NR_OF_TX_PDUS, SOAD_IF_TRANSMIT_ID, SOAD_E_INV_PDUID, E_NOT_OK)
boolean atLeastOneDestSent = FALSE;
uint16 connIndex=0;
Std_ReturnType retVal=E_NOT_OK;
const SoAd_PduRouteType* pduRoute;
pduRoute = &(SoAdCfgPtr->PduRoute[SoAdSrcPduId]);
/** @req SWS_SOAD_00602 */
for(uint32 i=0;i<pduRoute->NrOfPduRouteDest;i++){
/** @req SWS_SOAD_00539 */
if(pduRoute->PduRouteDest[i].GroupUsed == FALSE){
if( (SoAdSrcPduInfoPtr->SduLength==0) && (ConnectionAdminList[pduRoute->PduRouteDest[i].Index].groupAdminRef->SocketConnectionGroupRef->PduHeaderEnable == FALSE) ){
/*lint -e{904} Return statement is necessary to avoid multiple if loops (less cyclomatic complexity) and hence increase readability */
return E_NOT_OK;
}
}
else{
if( (SoAdSrcPduInfoPtr->SduLength==0) && (ConnectionGroupAdminList[pduRoute->PduRouteDest[i].Index].SocketConnectionGroupRef->PduHeaderEnable == FALSE) ){
/*lint -e{904} Return statement is necessary to avoid multiple if loops (less cyclomatic complexity) and hence increase readability */
return E_NOT_OK;
}
}
/* @req SWS_SOAD_00648 */
if(pduRoute->PduRouteDest[i].GroupUsed == FALSE){
connIndex = pduRoute->PduRouteDest[i].Index;
if(ifTransmitSubFunction(connIndex, SoAdSrcPduId, &(pduRoute->PduRouteDest[i]), SoAdSrcPduInfoPtr, &atLeastOneDestSent)==E_NOT_OK){
/*lint -e{904} Return statement is necessary to avoid multiple if loops (less cyclomatic complexity) and hence increase readability */
return E_NOT_OK;
}
}
else{
/** @req SWS_SOAD_00722 */
for(uint32 j=0;j<ConnectionGroupAdminList[pduRoute->PduRouteDest[i].Index].SocketConnectionGroupRef->NrOfSocketConnections;j++){
connIndex = ConnectionGroupAdminList[pduRoute->PduRouteDest[i].Index].SocketConnectionGroupRef->SoAdSocketConnection[j].SocketId;
if(ifTransmitSubFunction(connIndex, SoAdSrcPduId, &(pduRoute->PduRouteDest[i]), SoAdSrcPduInfoPtr, &atLeastOneDestSent)==E_NOT_OK){
/*lint -e{904} Return statement is necessary to avoid multiple if loops (less cyclomatic complexity) and hence increase readability */
return E_NOT_OK;
}
}
}
} /* for(i=0;i<pduRoute->NrOfPduRouteDest;i++) */
/* @req SWS_SOAD_00647 */
SchM_Enter_SoAd_EA_0();
if( pduRoute->PduRouteDest[0].GroupUsed == TRUE ){
if(ConnectionGroupAdminList[pduRoute->PduRouteDest[0].Index].SocketConnectionGroupRef->SocketProtocol == SOAD_SOCKET_PROT_UDP){
PduRouteAdminList[SoAdSrcPduId].TxState = SOAD_TX_STATE_UDP_SENDING_DONE;
}
}else{
if(ConnectionAdminList[pduRoute->PduRouteDest[0].Index].groupAdminRef->SocketConnectionGroupRef->SocketProtocol == SOAD_SOCKET_PROT_UDP){
PduRouteAdminList[SoAdSrcPduId].TxState = SOAD_TX_STATE_UDP_SENDING_DONE;
}
}
SchM_Exit_SoAd_EA_0();
/** @req SWS_SOAD_00560 */
if(atLeastOneDestSent == TRUE){
retVal = E_OK;
}
else{
retVal = E_NOT_OK;
}
return retVal;
}
BufReq_ReturnType SoAd_CopyTxData( TcpIp_SocketIdType SocketId, uint8* BufPtr, uint16 BufLength ){
const SoAd_PduRouteType* pduRoute;
SoadTptransmitType *tpRunTimeParm;
uint32 pduHeaderId;
PduInfoType pduInfo;
PduLengthType remaingLength;
PduIdType pduCnt;
TaskType task_id;
uint16 lenNoHeader;
BufReq_ReturnType retValCopydata;
Std_ReturnType retVal;
boolean isTpSocket;
retValCopydata = BUFREQ_NOT_OK;
retVal = E_OK;
isTpSocket = FALSE;
// task_id is used as an array index to protect SocketCurrentTx from possible task switches.
// The instance of SocketCurrentTx for the current task will then be used, even if a context switch has occurred.
retVal = GetTaskID(&task_id);
if ((retVal != E_OK) || (task_id >= OS_TASK_CNT)){
return BUFREQ_NOT_OK;
}
/** @req SWS_SOAD_00632 */
VALIDATE_RV(SoAd_ModuleStatus==SOAD_INITIALIZED, SOAD_COPY_TX_DATA_ID, SOAD_E_NOTINIT, BUFREQ_E_NOT_OK)
/* Check if Socket is used for Tp communication */
for (pduCnt = 0; pduCnt < SOAD_NR_OF_PDU_ROUTES; pduCnt++ ){
tpRunTimeParm = &SoadTpTransStatus[pduCnt];
//There is active Tp transmit request which has locked this socket
if((tpRunTimeParm->socketId == SocketId) && (TRUE == tpRunTimeParm->tpTxRequest)){
pduRoute = &(SoAdCfgPtr->PduRoute[pduCnt]);
pduHeaderId = pduRoute->PduRouteDest[SOAD_PDU_ROUTE_FIRST_DESTINATION_IDX].TxPduHeaderId;
if ((tpRunTimeParm->firstCopyCalled == FALSE) && (pduHeaderId != 0)) {
/* Copy PDU header */
lenNoHeader = (tpRunTimeParm->totalLen - SOAD_PDU_HEADER_LENGTH);
BufPtr[0] =(uint8)((pduHeaderId & 0xFF000000u)>>24);
BufPtr[1] =(uint8)((pduHeaderId & 0x00FF0000u)>>16);
BufPtr[2] = (uint8)((pduHeaderId & 0x0000FF00u)>>8);
BufPtr[3] = (uint8) (pduHeaderId & 0x000000FFu);
BufPtr[4] = 0u;
BufPtr[5] = 0u;
BufPtr[6] = (uint8)((lenNoHeader & 0x0000FF00u)>>8);
BufPtr[7] = (uint8) (lenNoHeader & 0x000000FFu);
pduInfo.SduDataPtr = &BufPtr[SOAD_PDU_HEADER_LENGTH];
pduInfo.SduLength = BufLength - SOAD_PDU_HEADER_LENGTH;
} else {
pduInfo.SduDataPtr = BufPtr;
pduInfo.SduLength = BufLength;
}
retValCopydata = pduRoute->SoAdTpCopyTxData(pduRoute->TxPduRef, &pduInfo, NULL, &remaingLength);
tpRunTimeParm->remainingLength = remaingLength;
if (BUFREQ_OK == retValCopydata) {
tpRunTimeParm->firstCopyCalled = TRUE; //First copy done
}
isTpSocket = TRUE;
break; //Exit loop as we found that socket belongs to Tp type
}
}
if (FALSE == isTpSocket) {
/** @req SWS_SOAD_00633 */
VALIDATE_RV(((SocketCurrentTx[task_id].SoConId != SOAD_INVALID_CON_ID) && (ConnectionAdminList[SocketCurrentTx[task_id].SoConId].SocketId == SocketId)),SOAD_COPY_TX_DATA_ID, SOAD_E_INV_SOCKETID, BUFREQ_E_NOT_OK)
/** @req SWS_SOAD_00543 */
if( (ConnectionAdminList[SocketCurrentTx[task_id].SoConId].SocketConnectionRef->nPduUdpTxBufferSize > 0) ||
(ConnectionAdminList[SocketCurrentTx[task_id].SoConId].groupAdminRef->SocketConnectionGroupRef->PduHeaderEnable == FALSE)){
memcpy(BufPtr,SocketCurrentTx[task_id].TxBufCopy,BufLength);
}
else{
/** @req SWS_SOAD_00197 */
/** @req SWS_SOAD_00198 */
lenNoHeader = (BufLength - SOAD_PDU_HEADER_LENGTH);
BufPtr[0] =(uint8)((SocketCurrentTx[task_id].TxPduHeaderId & 0xFF000000u)>>24);
BufPtr[1] =(uint8)((SocketCurrentTx[task_id].TxPduHeaderId & 0x00FF0000u)>>16);
BufPtr[2]= (uint8)((SocketCurrentTx[task_id].TxPduHeaderId & 0x0000FF00u)>>8);
BufPtr[3]= (uint8) (SocketCurrentTx[task_id].TxPduHeaderId & 0x000000FFu);
BufPtr[4]= 0u;
BufPtr[5]= 0u;
BufPtr[6]= (uint8)((lenNoHeader & 0x0000FF00u)>>8);
BufPtr[7]= (uint8) (lenNoHeader & 0x000000FFu);
memcpy(&BufPtr[SOAD_PDU_HEADER_LENGTH],SocketCurrentTx[task_id].TxBufCopy,lenNoHeader);
}
SchM_Enter_SoAd_EA_0();
SocketCurrentTx[task_id].SoConId = SOAD_INVALID_CON_ID;
SchM_Exit_SoAd_EA_0();
retValCopydata = BUFREQ_OK;
}
return retValCopydata;
}
void SoAd_TxConfirmation( TcpIp_SocketIdType SocketId, uint16 Length ){
/** @req SWS_SOAD_00269 */
VALIDATE_NO_RV(SoAd_ModuleStatus==SOAD_INITIALIZED, SOAD_TX_CONFIRMATION_ID, SOAD_E_NOTINIT)
/** @req SWS_SOAD_00271 */
VALIDATE_NO_RV(Length>0, SOAD_TX_CONFIRMATION_ID, SOAD_E_INV_ARG)
SoAd_SoConIdType SoConId;
SoadTptransmitType *tpRunTimeParm;
if(getSoConIdFromSocketId(SocketId, &SoConId)==FALSE){
/** @req SWS_SOAD_00270 */
DET_REPORTERROR(SOAD_MODULE_ID, 0, SOAD_TX_CONFIRMATION_ID, SOAD_E_INV_SOCKETID);
return;
}
/** @req SWS_SOAD_00545 */
for(uint32 pduRouteIndex=0;pduRouteIndex<SOAD_NR_OF_PDU_ROUTES;pduRouteIndex++){
if(PduRouteAdminList[pduRouteIndex].unconfirmedMessages>0){
for(uint32 pduRouteDestIndex=0;pduRouteDestIndex<SoAdCfgPtr->PduRoute[pduRouteIndex].NrOfPduRouteDest;pduRouteDestIndex++){
if(SoAdCfgPtr->PduRoute[pduRouteIndex].PduRouteDest[pduRouteDestIndex].GroupUsed == TRUE){
for(uint32 indexInGroup=0;indexInGroup<ConnectionGroupAdminList[SoAdCfgPtr->PduRoute[pduRouteIndex].PduRouteDest[pduRouteDestIndex].Index].SocketConnectionGroupRef->NrOfSocketConnections;indexInGroup++){
uint32 TmpSocketId = ConnectionGroupAdminList[SoAdCfgPtr->PduRoute[pduRouteIndex].PduRouteDest[pduRouteDestIndex].Index].SocketConnectionGroupRef->SoAdSocketConnection[indexInGroup].SocketId;
if(ConnectionAdminList[TmpSocketId].SocketId == SocketId ){
PduRouteAdminList[pduRouteIndex].unconfirmedMessages--;
if(PduRouteAdminList[pduRouteIndex].unconfirmedMessages==0){
tpRunTimeParm = &SoadTpTransStatus[pduRouteIndex];
if(SoAdCfgPtr->PduRoute[pduRouteIndex].TxConfirmationFunction!=NULL){
SoAdCfgPtr->PduRoute[pduRouteIndex].TxConfirmationFunction(SoAdCfgPtr->PduRoute[pduRouteIndex].TxPduRef);
}
else if((SoAdCfgPtr->PduRoute[pduRouteIndex].TpTxConfirmationFunction!=NULL)&&(tpRunTimeParm->remainingLength == 0)){
SoAdCfgPtr->PduRoute[pduRouteIndex].TpTxConfirmationFunction(SoAdCfgPtr->PduRoute[pduRouteIndex].TxPduRef, E_OK);
SoadTpTransStatus[pduRouteIndex].tpTxRequest = FALSE; //Reset any Tp request on this route
}
return;
}
}
}
}else{
uint32 TmpSocketId = SoAdCfgPtr->PduRoute[pduRouteIndex].PduRouteDest[pduRouteDestIndex].Index;
if(ConnectionAdminList[TmpSocketId].SocketId == SocketId ){
PduRouteAdminList[pduRouteIndex].unconfirmedMessages--;
if(PduRouteAdminList[pduRouteIndex].unconfirmedMessages==0){
tpRunTimeParm = &SoadTpTransStatus[pduRouteIndex];
if(SoAdCfgPtr->PduRoute[pduRouteIndex].TxConfirmationFunction!=NULL){
SoAdCfgPtr->PduRoute[pduRouteIndex].TxConfirmationFunction(SoAdCfgPtr->PduRoute[pduRouteIndex].TxPduRef);
}
else if((SoAdCfgPtr->PduRoute[pduRouteIndex].TpTxConfirmationFunction!=NULL)&&(tpRunTimeParm->remainingLength == 0)){
SoAdCfgPtr->PduRoute[pduRouteIndex].TpTxConfirmationFunction(SoAdCfgPtr->PduRoute[pduRouteIndex].TxPduRef, E_OK);
SoadTpTransStatus[pduRouteIndex].tpTxRequest = FALSE; //Reset any Tp request on this route
}
return;
}
}
}
}
}
}
}
Std_ReturnType SoAd_GetRemoteAddr( SoAd_SoConIdType SoConId, TcpIp_SockAddrType* IpAddrPtr ){
/** @req SWS_SOAD_00659 */
VALIDATE_RV(SoAd_ModuleStatus==SOAD_INITIALIZED, SOAD_GET_REMOTE_ADDR_ID, SOAD_E_NOTINIT, E_NOT_OK)
/** @req SWS_SOAD_00660 */
VALIDATE_RV(SoConId<SOAD_NR_OF_SOCKET_CONNECTIONS, SOAD_GET_REMOTE_ADDR_ID, SOAD_E_INV_ARG, E_NOT_OK)
/* ArcCore req */
VALIDATE_RV(IpAddrPtr!=NULL, SOAD_GET_REMOTE_ADDR_ID, SOAD_E_INV_ARG, E_NOT_OK)
/** @req SWS_SOAD_00666 */
if(ConnectionAdminList[SoConId].SocketConnectionRef->SoAdSocketRemoteAddress->Set==FALSE){
return E_NOT_OK;
}
/** @req SWS_SoAd_00698 */
if(IpAddrPtr->domain != ConnectionAdminList[SoConId].remAddrInUse.Domain){
DET_REPORTERROR(SOAD_MODULE_ID, 0, SOAD_GET_REMOTE_ADDR_ID, SOAD_E_INV_ARG);
return E_NOT_OK;
}
/** @req SWS_SOAD_00664 */
for (uint32 i = 0; i < 4; i++) {
IpAddrPtr->addr[i] = ConnectionAdminList[SoConId].remAddrInUse.SocketRemoteIpAddress[i];
}
IpAddrPtr->port = ConnectionAdminList[SoConId].remAddrInUse.SocketRemotePort;
return E_OK;
}
#if ( SOAD_VERSION_INFO_API == STD_ON)
void SoAd_GetVersionInfo( Std_VersionInfoType* versioninfo ){
VALIDATE_NO_RV( ( NULL != versioninfo ), SOAD_GET_VERSION_INFO_ID, SOAD_E_PARAM_POINTER);
versioninfo->vendorID = SOAD_VENDOR_ID;
versioninfo->moduleID = SOAD_MODULE_ID;
versioninfo->sw_major_version = SOAD_SW_MAJOR_VERSION;
versioninfo->sw_minor_version = SOAD_SW_MINOR_VERSION;
versioninfo->sw_patch_version = SOAD_SW_PATCH_VERSION;
}
#endif
Std_ReturnType SoAd_EnableRouting( SoAd_RoutingGroupIdType id ){
/** @req SWS_SOAD_00624 */
VALIDATE_RV(SoAd_ModuleStatus==SOAD_INITIALIZED, SOAD_ENABLE_ROUTING_ID, SOAD_E_NOTINIT, E_NOT_OK)
/** @req SWS_SOAD_00625 */
VALIDATE_RV(id<SOAD_NR_OF_ROUTING_GROUPS, SOAD_ENABLE_ROUTING_ID, SOAD_E_INV_ARG, E_NOT_OK)
#if SOAD_NR_OF_PDU_ROUTING_GROUP_CONNECTIONS > 0
/*lint -save -e845 CONFIGURATION */
for(uint32 i=0;i<SOAD_NR_OF_PDU_ROUTING_GROUP_CONNECTIONS;i++){
if(PduRoutingGroupAdminList[i].RoutingGroup == id){
PduRoutingGroupAdminList[i].Active = TRUE;
}
}
/*lint -restore */
#endif
for(uint32 i=0;i<SOAD_NR_OF_SOCKET_ROUTING_GROUP_CONNECTIONS;i++){
if(SocketRoutingGroupAdminList[i].RoutingGroup == id){
SocketRoutingGroupAdminList[i].Active = TRUE;
}
}
return E_OK;
}
Std_ReturnType SoAd_EnableSpecificRouting( SoAd_RoutingGroupIdType id, SoAd_SoConIdType SoConId ){
/** @req SWS_SOAD_00715 */
VALIDATE_RV(SoAd_ModuleStatus==SOAD_INITIALIZED, SOAD_ENABLE_SPECIFIC_ROUTING_ID, SOAD_E_NOTINIT, E_NOT_OK)
/** @req SWS_SOAD_00716 */
VALIDATE_RV(id<SOAD_NR_OF_ROUTING_GROUPS, SOAD_ENABLE_SPECIFIC_ROUTING_ID, SOAD_E_INV_ARG, E_NOT_OK)
/* Added by ArcCore */
VALIDATE_RV(SoConId<SOAD_NR_OF_SOCKET_CONNECTIONS, SOAD_ENABLE_SPECIFIC_ROUTING_ID, SOAD_E_INV_ARG, E_NOT_OK)
#if SOAD_NR_OF_PDU_ROUTING_GROUP_CONNECTIONS > 0
/*lint -save -e845 CONFIGURATION */
for(uint32 i=0;i<SOAD_NR_OF_PDU_ROUTING_GROUP_CONNECTIONS;i++){
if( (PduRoutingGroupAdminList[i].RoutingGroup == id) && (PduRoutingGroupAdminList[i].SoConId == SoConId) ){
PduRoutingGroupAdminList[i].Active = TRUE;
}
}
/*lint -restore */
#endif
for(uint32 i=0;i<SOAD_NR_OF_SOCKET_ROUTING_GROUP_CONNECTIONS;i++){
if( (SocketRoutingGroupAdminList[i].RoutingGroup == id) && (SocketRoutingGroupAdminList[i].SoConId == SoConId)){
SocketRoutingGroupAdminList[i].Active = TRUE;
}
}
return E_OK;
}
Std_ReturnType SoAd_DisableRouting( SoAd_RoutingGroupIdType id ){
/** @req SWS_SOAD_00627 */
VALIDATE_RV(SoAd_ModuleStatus==SOAD_INITIALIZED, SOAD_DISABLE_ROUTING_ID, SOAD_E_NOTINIT, E_NOT_OK)
/** @req SWS_SOAD_00626 */
VALIDATE_RV(id<SOAD_NR_OF_ROUTING_GROUPS, SOAD_DISABLE_ROUTING_ID, SOAD_E_INV_ARG, E_NOT_OK)
#if SOAD_NR_OF_PDU_ROUTING_GROUP_CONNECTIONS > 0
/*lint -save -e845 CONFIGURATION */
for(uint32 i=0;i<SOAD_NR_OF_PDU_ROUTING_GROUP_CONNECTIONS;i++){
if(PduRoutingGroupAdminList[i].RoutingGroup == id){
PduRoutingGroupAdminList[i].Active = FALSE;
}
}
/*lint -restore */
#endif
for(uint32 i=0;i<SOAD_NR_OF_SOCKET_ROUTING_GROUP_CONNECTIONS;i++){
if(SocketRoutingGroupAdminList[i].RoutingGroup == id){
SocketRoutingGroupAdminList[i].Active = FALSE;
}
}
return E_OK;
}
Std_ReturnType SoAd_DisableSpecificRouting( SoAd_RoutingGroupIdType id, SoAd_SoConIdType SoConId ){
/** @req SWS_SOAD_00718 */
VALIDATE_RV(SoAd_ModuleStatus==SOAD_INITIALIZED, SOAD_DISABLE_SPECIFIC_ROUTING_ID, SOAD_E_NOTINIT, E_NOT_OK)
/** @req SWS_SOAD_00719 */
VALIDATE_RV(id<SOAD_NR_OF_ROUTING_GROUPS, SOAD_DISABLE_SPECIFIC_ROUTING_ID, SOAD_E_INV_ARG, E_NOT_OK)
/* Added by ArcCore */
VALIDATE_RV(SoConId<SOAD_NR_OF_SOCKET_CONNECTIONS, SOAD_DISABLE_SPECIFIC_ROUTING_ID, SOAD_E_INV_ARG, E_NOT_OK)
#if SOAD_NR_OF_PDU_ROUTING_GROUP_CONNECTIONS > 0
/*lint -save -e845 CONFIGURATION */
for(uint32 i=0;i<SOAD_NR_OF_PDU_ROUTING_GROUP_CONNECTIONS;i++){
if( (PduRoutingGroupAdminList[i].RoutingGroup == id) && (PduRoutingGroupAdminList[i].SoConId == SoConId) ){
PduRoutingGroupAdminList[i].Active = FALSE;
}
}
/*lint -restore */
#endif
for(uint32 i=0;i<SOAD_NR_OF_SOCKET_ROUTING_GROUP_CONNECTIONS;i++){
if( (SocketRoutingGroupAdminList[i].RoutingGroup == id) && (SocketRoutingGroupAdminList[i].SoConId == SoConId)){
SocketRoutingGroupAdminList[i].Active = FALSE;
}
}
return E_OK;
}
Std_ReturnType SoAd_GetSoConId( PduIdType TxPduId, SoAd_SoConIdType* SoConIdPtr ){
/** @req SWS_SOAD_00609 */
VALIDATE_RV(SoAd_ModuleStatus==SOAD_INITIALIZED, SOAD_GET_SOCON_ID_ID, SOAD_E_NOTINIT, E_NOT_OK)
/** @req SWS_SOAD_00610 */
VALIDATE_RV(TxPduId<SOAD_NR_OF_PDU_ROUTES, SOAD_GET_SOCON_ID_ID, SOAD_E_INV_PDUID, E_NOT_OK)
Std_ReturnType retVal = E_NOT_OK;
const SoAd_PduRouteType* pduRoute = &(SoAdCfgPtr->PduRoute[TxPduId]);
/** @req SWS_SOAD_00724 */
if(pduRoute->NrOfPduRouteDest >1){
return E_NOT_OK;
}
if(pduRoute->PduRouteDest[0].GroupUsed == FALSE){
*SoConIdPtr = ConnectionAdminList[pduRoute->PduRouteDest[0].Index].SocketConnectionRef->SocketId;
retVal = E_OK;
}
else{
//IMPROVEMENT What to do if we have a group?
retVal = E_NOT_OK;
}
return retVal;
}
Std_ReturnType SoAd_Arc_GetSoConIdFromRxPdu( PduIdType RxPduId, SoAd_SoConIdType* SoConIdPtr ){
//Improvement: Guards
Std_ReturnType retVal = E_NOT_OK;
for(uint32 i=0;i<SOAD_NR_OF_SOCKET_ROUTES;i++){
//IMPROVEMENT What to do if we have a group?
if( (SoAdCfgPtr->SocketRoute[i].SocketRouteDest->RxPduRef == RxPduId) && (SoAdCfgPtr->SocketRoute[i].GroupUsed == FALSE)){
retVal = E_OK;
*SoConIdPtr = ConnectionAdminList[SoAdCfgPtr->SocketRoute[i].Index].SocketConnectionRef->SocketId;
break;
}
}
return retVal;
}
/** @req SWS_SOAD_00520 */
Std_ReturnType SoAd_GetLocalAddr( SoAd_SoConIdType SoConId, TcpIp_SockAddrType* LocalAddrPtr, uint8* NetmaskPtr, TcpIp_SockAddrType* DefaultRouterPtr ){
Std_ReturnType result;
/** @req SWS_SOAD_00621 */
VALIDATE_RV(SoAd_ModuleStatus==SOAD_INITIALIZED, SOAD_GET_LOCAL_ADDR_ID, SOAD_E_NOTINIT, E_NOT_OK)
/** @req SWS_SOAD_00620 */
VALIDATE_RV(SoConId<SOAD_NR_OF_SOCKET_CONNECTIONS, SOAD_GET_LOCAL_ADDR_ID, SOAD_E_INV_ARG, E_NOT_OK)
result = TcpIp_GetIpAddr(ConnectionAdminList[SoConId].groupAdminRef->SocketConnectionGroupRef->SocketLocalAddressRef, LocalAddrPtr, NetmaskPtr, DefaultRouterPtr);
LocalAddrPtr->port = ConnectionAdminList[SoConId].groupAdminRef->localPortUsed;
return result;
}
Std_ReturnType SoAd_GetPhysAddr( SoAd_SoConIdType SoConId, uint8* PhysAddrPtr ){
/** @req SWS_SOAD_00623 */
VALIDATE_RV(SoAd_ModuleStatus==SOAD_INITIALIZED, SOAD_GET_PHYS_ADDR_ID, SOAD_E_NOTINIT, E_NOT_OK)
/** @req SWS_SOAD_00622 */
VALIDATE_RV(SoConId<SOAD_NR_OF_SOCKET_CONNECTIONS, SOAD_GET_PHYS_ADDR_ID, SOAD_E_INV_ARG, E_NOT_OK)
return TcpIp_GetPhysAddr(ConnectionAdminList[SoConId].groupAdminRef->SocketConnectionGroupRef->SocketLocalAddressRef, PhysAddrPtr);
}
Std_ReturnType SoAd_RequestIpAddrAssignment( SoAd_SoConIdType SoConId, TcpIp_IpAddrAssignmentType Type, const TcpIp_SockAddrType* LocalIpAddrPtr, uint8 Netmask, const TcpIp_SockAddrType* DefaultRouterPtr ){
/** @req SWS_SOAD_00613 */
VALIDATE_RV(SoAd_ModuleStatus==SOAD_INITIALIZED, SOAD_REQUEST_IP_ADDR_ASSIGNMENT_ID, SOAD_E_NOTINIT, E_NOT_OK)
/** @req SWS_SOAD_00617 */
VALIDATE_RV(SoConId<SOAD_NR_OF_SOCKET_CONNECTIONS, SOAD_REQUEST_IP_ADDR_ASSIGNMENT_ID, SOAD_E_INV_ARG, E_NOT_OK)
return TcpIp_RequestIpAddrAssignment( ConnectionAdminList[SoConId].groupAdminRef->SocketConnectionGroupRef->SocketLocalAddressRef, Type, LocalIpAddrPtr, Netmask, DefaultRouterPtr );
}
Std_ReturnType SoAd_ReleaseIpAddrAssignment( SoAd_SoConIdType SoConId ){
/** @req SWS_SOAD_00618 */
VALIDATE_RV(SoAd_ModuleStatus==SOAD_INITIALIZED, SOAD_RELEASE_IP_ADDR_ASSIGNMENT_ID, SOAD_E_NOTINIT, E_NOT_OK)
/** @req SWS_SOAD_00619 */
VALIDATE_RV(SoConId<SOAD_NR_OF_SOCKET_CONNECTIONS, SOAD_RELEASE_IP_ADDR_ASSIGNMENT_ID, SOAD_E_INV_ARG, E_NOT_OK)
Std_ReturnType retVal = E_NOT_OK;
retVal = TcpIp_ReleaseIpAddrAssignment( ConnectionAdminList[SoConId].groupAdminRef->SocketConnectionGroupRef->SocketLocalAddressRef );
return retVal;
}
Std_ReturnType SoAd_SetUniqueRemoteAddr( SoAd_SoConIdType SoConId, const TcpIp_SockAddrType* RemoteAddrPtr, SoAd_SoConIdType* AssignedSoConIdPtr ){
/** @req SWS_SOAD_00672 */
VALIDATE_RV(SoAd_ModuleStatus==SOAD_INITIALIZED, SOAD_SET_UNIQUE_REMOTE_ADDR_ID, SOAD_E_NOTINIT, E_NOT_OK)
/** @req SWS_SOAD_00673 */
VALIDATE_RV(SoConId<SOAD_NR_OF_SOCKET_CONNECTIONS, SOAD_SET_UNIQUE_REMOTE_ADDR_ID, SOAD_E_INV_ARG, E_NOT_OK)
/** @req SWS_SOAD_00678 */
Std_ReturnType retVal = E_NOT_OK;
/** @req SWS_SoAd_00700 */
if(RemoteAddrPtr->domain != ConnectionAdminList[SoConId].remAddrInUse.Domain){
DET_REPORTERROR(SOAD_MODULE_ID, 0, SOAD_SET_UNIQUE_REMOTE_ADDR_ID, SOAD_E_INV_ARG);
return E_NOT_OK;
}
for(uint16 i=0;i<ConnectionAdminList[SoConId].groupAdminRef->SocketConnectionGroupRef->NrOfSocketConnections;i++){
uint16 connectionIndex = ConnectionAdminList[SoConId].groupAdminRef->SocketConnectionGroupRef->SoAdSocketConnection[i].SocketId;
/** @req SWS_SOAD_00675 */
if( (ConnectionAdminList[connectionIndex].remAddrInUse.Set == TRUE) &&
(ConnectionAdminList[connectionIndex].remAddrInUse.SocketRemoteIpAddress[0] == RemoteAddrPtr->addr[0]) &&
(ConnectionAdminList[connectionIndex].remAddrInUse.SocketRemoteIpAddress[1] == RemoteAddrPtr->addr[1]) &&
(ConnectionAdminList[connectionIndex].remAddrInUse.SocketRemoteIpAddress[2] == RemoteAddrPtr->addr[2]) &&
(ConnectionAdminList[connectionIndex].remAddrInUse.SocketRemoteIpAddress[3] == RemoteAddrPtr->addr[3]) &&
(ConnectionAdminList[connectionIndex].remAddrInUse.SocketRemotePort == RemoteAddrPtr->port)){
*AssignedSoConIdPtr = connectionIndex;
retVal = E_OK;
}
}
if(retVal==E_NOT_OK){ // No SocketConnection found for the RemoteAddr given
uint32 connIndexInGroup=0;
/** @req SWS_SOAD_00676 */
if(TRUE == runBestMatch(ConnectionAdminList[SoConId].groupAdminRef->SocketConnectionGroupRef, RemoteAddrPtr, &connIndexInGroup)){
*AssignedSoConIdPtr = ConnectionAdminList[SoConId].groupAdminRef->SocketConnectionGroupRef->SoAdSocketConnection[connIndexInGroup].SocketId;
// Assign address
SchM_Enter_SoAd_EA_0();
for(uint32 i=0;i<4;i++){
ConnectionAdminList[*AssignedSoConIdPtr].remAddrInUse.SocketRemoteIpAddress[i] = RemoteAddrPtr->addr[i];
}
ConnectionAdminList[*AssignedSoConIdPtr].remAddrInUse.SocketRemotePort = RemoteAddrPtr->port;
SchM_Exit_SoAd_EA_0();
retVal=E_OK;
}
}
return retVal;
}
Std_ReturnType SoAd_IfRoutingGroupTransmit( SoAd_RoutingGroupIdType id ){
/** @req SWS_SOAD_00661 */
VALIDATE_RV(SoAd_ModuleStatus==SOAD_INITIALIZED, SOAD_IF_ROUTING_GROUP_TRANSMIT_ID, SOAD_E_NOTINIT, E_NOT_OK)
/** @req SWS_SOAD_00658 */
VALIDATE_RV( (id < SOAD_NR_OF_ROUTING_GROUPS) && (SoAdCfgPtr->RoutingGroup[id].RoutingGroupTxTriggerable == TRUE), SOAD_IF_ROUTING_GROUP_TRANSMIT_ID, SOAD_E_INV_ARG, E_NOT_OK)
/** @req SWS_SOAD_00662 */
for(uint32 pduRouteIndex=0;pduRouteIndex<SOAD_NR_OF_PDU_ROUTES;pduRouteIndex++){
for(uint32 pduRouteDestIndex=0;pduRouteDestIndex<SoAdCfgPtr->PduRoute[pduRouteIndex].NrOfPduRouteDest;pduRouteDestIndex++){
for(uint32 routingGrpIndex=0;routingGrpIndex<SoAdCfgPtr->PduRoute[pduRouteIndex].PduRouteDest[pduRouteDestIndex].NrOfRoutingGroups;routingGrpIndex++){
if( id == SoAdCfgPtr->PduRoute[pduRouteIndex].PduRouteDest[pduRouteDestIndex].TxRoutingGroupRef[routingGrpIndex]->RoutingGroupId){
PduRouteAdminList[pduRouteIndex].trigger.mode = SOAD_TRIGGERTRANSMITMODE_ROUTINGGROUP;
PduRouteAdminList[pduRouteIndex].trigger.RoutingGroup = id;
}
}
}
}
return E_OK;
}
Std_ReturnType SoAd_IfSpecificRoutingGroupTransmit( SoAd_RoutingGroupIdType id, SoAd_SoConIdType SoConId ){
/** @req SWS_SOAD_00712 */
VALIDATE_RV(SoAd_ModuleStatus==SOAD_INITIALIZED, SOAD_IF_SPECIFIC_ROUTING_GROUP_TRANSMIT_ID, SOAD_E_NOTINIT, E_NOT_OK)
/** @req SWS_SOAD_00713 */
VALIDATE_RV( (id < SOAD_NR_OF_ROUTING_GROUPS) && (SoAdCfgPtr->RoutingGroup[id].RoutingGroupTxTriggerable == TRUE), SOAD_IF_SPECIFIC_ROUTING_GROUP_TRANSMIT_ID, SOAD_E_INV_ARG, E_NOT_OK)
/** @req SWS_SOAD_00720 */
for(uint32 pduRouteIndex=0;pduRouteIndex<SOAD_NR_OF_PDU_ROUTES;pduRouteIndex++){
for(uint32 pduRouteDestIndex=0;pduRouteDestIndex<SoAdCfgPtr->PduRoute[pduRouteIndex].NrOfPduRouteDest;pduRouteDestIndex++){
for(uint32 routingGrpIndex=0;routingGrpIndex<SoAdCfgPtr->PduRoute[pduRouteIndex].PduRouteDest[pduRouteDestIndex].NrOfRoutingGroups;routingGrpIndex++){
if( id == SoAdCfgPtr->PduRoute[pduRouteIndex].PduRouteDest[pduRouteDestIndex].TxRoutingGroupRef[routingGrpIndex]->RoutingGroupId){
if(SoAdCfgPtr->PduRoute[pduRouteIndex].PduRouteDest[pduRouteDestIndex].GroupUsed == TRUE){
for(uint32 indexInGroup=0;indexInGroup<ConnectionGroupAdminList[SoAdCfgPtr->PduRoute[pduRouteIndex].PduRouteDest[pduRouteDestIndex].Index].SocketConnectionGroupRef->NrOfSocketConnections;indexInGroup++){
uint16 SocketId = ConnectionGroupAdminList[SoAdCfgPtr->PduRoute[pduRouteIndex].PduRouteDest[pduRouteDestIndex].Index].SocketConnectionGroupRef->SoAdSocketConnection[indexInGroup].SocketId;
if(SocketId == SoConId){
PduRouteAdminList[pduRouteIndex].trigger.mode = SOAD_TRIGGERTRANSMITMODE_ROUTINGGROUP_AND_SOCON;
PduRouteAdminList[pduRouteIndex].trigger.RoutingGroup = id;
PduRouteAdminList[pduRouteIndex].trigger.SoConId = SoConId;
}
}
}
else{
if(SoAdCfgPtr->PduRoute[pduRouteIndex].PduRouteDest[pduRouteDestIndex].Index == SoConId){
PduRouteAdminList[pduRouteIndex].trigger.mode = SOAD_TRIGGERTRANSMITMODE_ROUTINGGROUP_AND_SOCON;
PduRouteAdminList[pduRouteIndex].trigger.RoutingGroup = id;
PduRouteAdminList[pduRouteIndex].trigger.SoConId = SoConId;
}
}
}
}
}
}
return E_OK;
}
Std_ReturnType SoAd_TpTransmit( PduIdType SoAdSrcPduId, const PduInfoType* SoAdSrcPduInfoPtr ){
SoadTptransmitType *tpRunTimeParm;
Std_ReturnType retVal;
/* @req SWS_SOAD_00224 */
VALIDATE_RV(SoAd_ModuleStatus==SOAD_INITIALIZED, SOAD_TP_TRANSMIT_ID, SOAD_E_NOTINIT, E_NOT_OK)
/* @req SWS_SOAD_00237 */
VALIDATE_RV(SoAdSrcPduId < SOAD_NR_OF_TX_PDUS, SOAD_TP_TRANSMIT_ID, SOAD_E_INV_PDUID, E_NOT_OK)
tpRunTimeParm = &SoadTpTransStatus[SoAdSrcPduId];
/* @req SWS_SOAD_00551 */
if(SoAdSrcPduInfoPtr->SduLength == 0){
retVal = E_NOT_OK;
} else if (SOAD_RX_UPPER_LAYER_TP != SoAdCfgPtr->PduRoute[SoAdSrcPduId].TxUpperLayerType) {
retVal = E_NOT_OK; /* Reject if PDU route is not Tp type */
} else if (TRUE == tpRunTimeParm->tpTxRequest) {
/* Reject request for ongoing Tp transmission case */
/* @req SWS_SOAD_00650 */
retVal = E_NOT_OK;
}
else if ((SoAdCfgPtr->PduRoute[SoAdSrcPduId].NrOfPduRouteDest > 1) ||
(SoAdCfgPtr->PduRoute[SoAdSrcPduId]. \
PduRouteDest[SOAD_PDU_ROUTE_FIRST_DESTINATION_IDX].GroupUsed == TRUE)){
/* Discard Tp transmit on a route which contains multiple destinations. In case
* of only one destination the first destination should map to a socket connection */
retVal = E_NOT_OK;
} else {
tpRunTimeParm->tpTxRequest = TRUE;
tpRunTimeParm->firstCopyCalled = FALSE;
retVal = E_OK;
}
return retVal;
}
// ----------------- UNIMPLEMENTED FUNCTIONS ----------------------------------
Std_ReturnType SoAd_TpCancelTransmit( PduIdType PduId ){
//SoAd_TpCancelStatus.SoAd_TpCancelTranStatus = FALSE;
/** @req SWS_SOAD_00605 */
VALIDATE_RV(SoAd_ModuleStatus==SOAD_INITIALIZED, SOAD_TP_CANCEL_TRANSMIT_ID, SOAD_E_NOTINIT, E_NOT_OK)
return E_OK;
}
Std_ReturnType SoAd_TpCancelReceive( PduIdType PduId ){
/** @req SWS_SOAD_00607 */
VALIDATE_RV(SoAd_ModuleStatus==SOAD_INITIALIZED, SOAD_TP_CANCEL_RECEIVE_ID, SOAD_E_NOTINIT, E_NOT_OK)
return E_OK;
}
Std_ReturnType SoAd_TpChangeParameter( PduIdType id, TPParameterType parameter, uint16 value ){
/** @req SWS_SOAD_00629 */
VALIDATE_RV(SoAd_ModuleStatus==SOAD_INITIALIZED, SOAD_TP_CHANGE_PARAMETER_ID, SOAD_E_NOTINIT, E_NOT_OK)
/** @req SWS_SOAD_00630 */
VALIDATE_RV(parameter<=TP_BC, SOAD_TP_CHANGE_PARAMETER_ID, SOAD_E_INV_ARG, E_NOT_OK)
/** @req SWS_SOAD_00631 */
VALIDATE_RV(id<SOAD_NR_OF_PDU_ROUTES, SOAD_TP_CHANGE_PARAMETER_ID, SOAD_E_INV_ARG, E_NOT_OK)
return E_OK;
}
Std_ReturnType SoAd_ReadDhcpHostNameOption( SoAd_SoConIdType SoConId, uint8* length, uint8* data ){
/** @req SWS_SOAD_00701 */
VALIDATE_RV(SoAd_ModuleStatus==SOAD_INITIALIZED, SOAD_READ_DHCP_HOST_NAME_OPTION_ID, SOAD_E_NOTINIT, E_NOT_OK)
/** @req SWS_SOAD_00702 */
VALIDATE_RV(SoConId<SOAD_NR_OF_SOCKET_CONNECTIONS, SOAD_READ_DHCP_HOST_NAME_OPTION_ID, SOAD_E_INV_ARG, E_NOT_OK)
return E_OK;
}
Std_ReturnType SoAd_WriteDhcpHostNameOption( SoAd_SoConIdType SoConId, uint8 length, const uint8* data ){
/** @req SWS_SOAD_00705 */
VALIDATE_RV(SoAd_ModuleStatus==SOAD_INITIALIZED, SOAD_WRITE_DHCP_HOST_NAME_OPTION_ID, SOAD_E_NOTINIT, E_NOT_OK)
(void)length;
return E_OK;
}
#if defined(HOST_TEST)
/**
* Get the mode for a specific Socket Connection. Only used for testing purposes
*/
SoAd_SoConModeType SoAd_Arc_GetMode(SoAd_SoConIdType SoConId){
return ConnectionAdminList[SoConId].mode;
}
#endif
|
2301_81045437/classic-platform
|
communication/SoAd/src/SoAd.c
|
C
|
unknown
| 140,775
|
/*-------------------------------- Arctic Core ------------------------------
* Copyright (C) 2013, ArcCore AB, Sweden, www.arccore.com.
* Contact: <contact@arccore.com>
*
* You may ONLY use this file:
* 1)if you have a valid commercial ArcCore license and then in accordance with
* the terms contained in the written license agreement between you and ArcCore,
* or alternatively
* 2)if you follow the terms found in GNU General Public License version 2 as
* published by the Free Software Foundation and appearing in the file
* LICENSE.GPL included in the packaging of this file or here
* <http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt>
*-------------------------------- Arctic Core -----------------------------*/
/*
* NB! This file is for SOAD internal use only and may only be included from SOAD C-files!
*/
#ifndef SOAD_INTERNAL_H_
#define SOAD_INTERNAL_H_
#include "SoAd.h"
#include "TcpIp.h"
#if ( SOAD_DEV_ERROR_DETECT == STD_ON )
#include "Det.h"
#define VALIDATE_RV(_exp,_api,_err,_rv ) \
if( !(_exp) ) { \
Det_ReportError(SOAD_MODULE_ID, 0, _api, _err); \
return _rv; \
}
#define VALIDATE_NO_RV(_exp,_api,_err ) \
if( !(_exp) ) { \
Det_ReportError(SOAD_MODULE_ID, 0, _api, _err); \
return; \
}
#define DET_REPORTERROR(_x,_y,_z,_q) Det_ReportError(_x, _y, _z, _q)
#else
#define VALIDATE(_exp,_api,_err )
#define VALIDATE_RV(_exp,_api,_err,_rv )
#define VALIDATE_NO_RV(_exp,_api,_err )
#define DET_REPORTERROR(_x,_y,_z,_q)
#endif
typedef enum {
SOCKET_UNINIT = 0,
SOCKET_DUPLICATE,
SOCKET_INIT,
SOCKET_TCP_LISTENING,
SOCKET_TCP_READY,
SOCKET_UDP_READY
} SocketStateType;
typedef struct {
uint8 SocketNr;
SocketStateType SocketState;
boolean SocketProtocolIsTcp;
const SoAd_SocketConnectionType* SocketConnectionRef;
const SoAd_SocketRouteType* SocketRouteRef;
// const SoAd_PduRouteType* PduRouteRef;
uint32 RemoteIpAddress;
uint16 RemotePort;
int SocketHandle;
int ConnectionHandle;
} ConnectionAdminType;
typedef enum {
PDU_IDLE,
PDU_IF_SENDING,
PDU_TP_REQ_BUFFER,
PDU_TP_SENDING
} PduStatusType;
typedef enum {
SOAD_ARC_DOIP_IDENTIFICATIONREQUEST_ALL,
SOAD_ARC_DOIP_IDENTIFICATIONREQUEST_BY_EID,
SOAD_ARC_DOIP_IDENTIFICATIONREQUEST_BY_VIN,
} SoAd_Arc_DoIp_VehicleIdentificationRequestType;
typedef struct {
PduStatusType PduStatus;
} PduAdminListType;
typedef enum {
DOIP_ARC_CONNECTION_INVALID,
DOIP_ARC_CONNECTION_REGISTERED,
} SoAd_ArcDoIpSocketStateType;
typedef struct {
uint16 sockNr;
uint16 sa;
uint8 activationType;
SoAd_ArcDoIpSocketStateType socketState;
uint32 initialInactivityTimer;
uint32 generalInactivityTimer;
uint32 aliveCheckTimer;
boolean authenticated;
boolean confirmed;
boolean awaitingAliveCheckResponse;
/*
* Index of the last/active routing target in the generated DoIp_Cfg_TargetList
*/
uint16 targetIndex;
/*
* Status of last/active pdu routing request.
*/
PduStatusType pduStatus;
} DoIp_ArcDoIpSocketStatusType;
typedef enum {
DOIP_SOCKET_ASSIGNMENT_FAILED,
DOIP_SOCKET_ASSIGNMENT_SUCCESSFUL,
DOIP_SOCKET_ASSIGNMENT_PENDING,
} DoIp_Arc_SocketAssignmentResultType;
typedef enum {
/* We do not currently have a valid IP */
SOAD_ARC_LINKDOWN = 0,
/* We have a valid IP to send from */
SOAD_ARC_LINKUP,
} SoadArcLinkStatusType;
extern ConnectionAdminType SocketAdminList[SOAD_SOCKET_COUNT];
extern PduAdminListType PduAdminList[SOAD_PDU_ROUTE_COUNT];
boolean SoAd_BufferGet(uint32 size, uint8** buffPtr);
void SoAd_BufferFree(uint8* buffPtr);
void SoAd_SocketClose(uint16 sockNr);
void SoAd_SocketStatusCheck(uint16 sockNr, int sockHandle);
uint16 SoAd_SendIpMessage(uint16 sockNr, uint32 msgLen, uint8* buff);
SoadArcLinkStatusType SoAd_GetLinkStatus(void);
void DoIp_HandleTcpRx(uint16 sockNr);
void DoIp_HandleUdpRx(uint16 sockNr);
Std_ReturnType DoIp_HandleTpTransmit(PduIdType SoAdSrcPduId, const PduInfoType* SoAdSrcPduInfoPtr);
void DoIp_SendVehicleAnnouncement(uint16 sockNr);
void DoIp_LocalIpAddrAssignmentChg(SoAd_SoConIdType linkId, TcpIp_IpAddrStateType state);
uint8 SoAd_GetNofCurrentlyUsedTcpSockets();
#endif /* SOAD_INTERNAL_H_ */
|
2301_81045437/classic-platform
|
communication/SoAd/src/SoAd_Internal.h
|
C
|
unknown
| 4,524
|
/*-------------------------------- Arctic Core ------------------------------
* Copyright (C) 2013, ArcCore AB, Sweden, www.arccore.com.
* Contact: <contact@arccore.com>
*
* You may ONLY use this file:
* 1)if you have a valid commercial ArcCore license and then in accordance with
* the terms contained in the written license agreement between you and ArcCore,
* or alternatively
* 2)if you follow the terms found in GNU General Public License version 2 as
* published by the Free Software Foundation and appearing in the file
* LICENSE.GPL included in the packaging of this file or here
* <http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt>
*-------------------------------- Arctic Core -----------------------------*/
#ifndef TCPIP_H
#define TCPIP_H
#include "ComStack_Types.h"
#define TCPIP_VENDOR_ID 60u
#define TCPIP_MODULE_ID 170u
#define TCPIP_AR_RELEASE_MAJOR_VERSION 4u
#define TCPIP_AR_RELEASE_MINOR_VERSION 2u
#define TCPIP_AR_RELEASE_PATCH_VERSION 2u
#define TCPIP_SW_MAJOR_VERSION 2u
#define TCPIP_SW_MINOR_VERSION 0u
#define TCPIP_SW_PATCH_VERSION 0u
/** @req 4.2.2/SWS_TCPIP_00042 */
#define TCPIP_E_NOTINIT 0x01u
#define TCPIP_E_PARAM_POINTER 0x02u
#define TCPIP_E_INV_ARG 0x03u
#define TCPIP_E_NOBUFS 0x04u
#define TCPIP_E_MSGSIZE 0x07u
#define TCPIP_E_PROTOTYPE 0x08u
#define TCPIP_E_ADDRINUSE 0x09u
#define TCPIP_E_ADDRNOTAVAIL 0x0Au
#define TCPIP_E_ISCONN 0x0Bu
#define TCPIP_E_NOTCONN 0x0Cu
#define TCPIP_E_NOPROTOOPT 0x0Du
#define TCPIP_E_AFNOSUPPORT 0x0Eu
#define TCPIP_E_INIT_FAILED 0x0Fu
#define TCPIP_E_ARC_ILLEGAL_STATE 0x10u
#define TCPIP_E_ARC_ETHIF_INIT_STATE_FAILED 0x11u
#define TCPIP_E_ARC_TRCV_INIT_STATE_FAILED 0x12u
#define TCPIP_E_ARC_GENERAL_FAILURE_TCPIP 0x13u
#define TCPIP_E_ARC_GENERAL_FAILURE_TCPIP_STACK 0x14u
/*Service id's */
#define TCPIP_INIT_SERVICE_ID 0x01u
#define TCPIP_GETVERSIONINFO_SERVICE_ID 0x02u
#define TCPIP_GETSOCKET_SERVICE_ID 0x03u
#define TCPIP_CLOSE_SERVICE_ID 0x04u
#define TCPIP_BIND_SERVICE_ID 0x05u
#define TCPIP_TCPCONNECT_SERVICE_ID 0x06u
#define TCPIP_TCPLISTEN_SERVICE_ID 0x07u
#define TCPIP_TCPRECEIVED_SERVICE_ID 0x08u
#define TCPIP_REQUESTCOMMODE_SERVICE_ID 0x09u
#define TCPIP_REQUESTIPADDRASSIGNMENT_SERVICE_ID 0x0au
#define TCPIP_RELEASEIPADDRASSIGNMENT_SERVICE_ID 0x0bu
#define TCPIP_ICMPTRANSMIT_SERVICE_ID 0x0cu
#define TCPIP_DHCPREADOPTION_SERVICE_ID 0x0du
#define TCPIP_DHCPWRITEOPTION_SERVICE_ID 0x0eu
#define TCPIP_CHANGEPARAMETER_SERVICE_ID 0x0fu
#define TCPIP_GETIPADDR_SERVICE_ID 0x10u
#define TCPIP_GETPHYSADDR_SERVICE_ID 0x11u
#define TCPIP_UDPTRANSMIT_SERVICE_ID 0x12u
#define TCPIP_TCPTRANSMIT_SERVICE_ID 0x13u
#define TCPIP_RXINDICATION_SERVICE_ID 0x14u
#define TCPIP_MAINFUNCTION_SERVICE_ID 0x15u
#define TCPIP_GETREMOTEPHYSADDR_SERVICE_ID 0x16u
#define TCPIP_GETCTRLIDX_SERVICE_ID 0x17u
#define TCPIP_ICMPV6TRANSMIT_SERVICE_ID 0x18u
#define TCPIP_DHCPV6READOPTION_SERVICE_ID 0x19u
#define TCPIP_DHCPV6WRITEOPTION_SERVICE_ID 0x1au
#define TCPIP_RESETIPASSIGNMENT_SERVICE_ID 0x1bu
#include "TcpIp_Types.h"
#include "TcpIp_ConfigTypes.h"
#include "TcpIp_Cfg.h"
#include "Platform_Types.h"
#if (CPU_BYTE_ORDER == HIGH_BYTE_FIRST)
/** Set an IP address given by the four byte-parts */
#define IP4_ADDR_CHR_TO_UINT32(a,b,c,d) ( ((uint32)((a) & 0xff) << 24) | ((uint32)((b) & 0xff) << 16) | ((uint32)((c) & 0xff) << 8) | (uint32)((d) & 0xff) )
#else
#define IP4_ADDR_CHR_TO_UINT32(a,b,c,d) ( ((uint32)((d) & 0xff) << 24) | ((uint32)((c) & 0xff) << 16) | ((uint32)((b) & 0xff) << 8) | (uint32)((a) & 0xff) )
#endif
/* @req 4.2.2/SWS_TCPIP_00006 */
#if ( TCPIP_VERSION_INFO_API == STD_ON)
/**
* Gets the version info
* @param versioninfo - struct holding the version info
*/
/* @req 4.2.2/SWS_TCPIP_00004 */
/* @req 4.2.2/SWS_TCPIP_00005 */
#if ( TCPIP_VERSION_INFO_API == STD_ON )
#define TcpIp_GetVersionInfo(_vi) STD_GET_VERSION_INFO(_vi,TCPIP)
#endif /* TCPIP_VERSION_INFO_API */
#endif
void TcpIp_Init(const TcpIp_ConfigType* ConfigPtr);
Std_ReturnType TcpIp_Close(TcpIp_SocketIdType SocketId, boolean Abort);
Std_ReturnType TcpIp_Bind(TcpIp_SocketIdType SocketId, TcpIp_LocalAddrIdType LocalAddrId, uint16* PortPtr);
Std_ReturnType TcpIp_TcpConnect(TcpIp_SocketIdType SocketId, const TcpIp_SockAddrType* RemoteAddrPtr);
Std_ReturnType TcpIp_TcpListen(TcpIp_SocketIdType SocketId, uint16 MaxChannels);
Std_ReturnType TcpIp_TcpReceived(TcpIp_SocketIdType SocketId, uint32 Length);
Std_ReturnType TcpIp_RequestIpAddrAssignment(TcpIp_LocalAddrIdType LocalAddrId, TcpIp_IpAddrAssignmentType Type,
const TcpIp_SockAddrType* LocalIpAddrPtr, uint8 Netmask, const TcpIp_SockAddrType* DefaultRouterPtr);
Std_ReturnType TcpIp_ReleaseIpAddrAssignment(TcpIp_LocalAddrIdType LocalAddrId);
Std_ReturnType TcpIp_ResetIpAssignment(void);
Std_ReturnType TcpIp_IcmpTransmit(TcpIp_LocalAddrIdType LocalIpAddrId, const TcpIp_SockAddrType* RemoteAddrPtr,
uint8 Ttl, uint8 Type, uint8 Code, uint16 DataLength, const uint8* DataPtr);
Std_ReturnType TcpIp_IcmpV6Transmit(TcpIp_LocalAddrIdType LocalIpAddrId, const TcpIp_SockAddrType* RemoteAddrPtr,
uint8 HopLimit, uint8 Type, uint8 Code, uint16 DataLength, const uint8* DataPtr);
Std_ReturnType TcpIp_DhcpReadOption(TcpIp_LocalAddrIdType LocalIpAddrId, uint8 Option, uint8* DataLength, uint8* DataPtr);
Std_ReturnType TcpIp_DhcpV6ReadOption(TcpIp_LocalAddrIdType LocalIpAddrId, uint16 Option, uint16* DataLength, uint8* DataPtr);
Std_ReturnType TcpIp_DhcpWriteOption(TcpIp_LocalAddrIdType LocalIpAddrId, uint8 Option, uint8 DataLength, const uint8* DataPtr);
Std_ReturnType TcpIp_DhcpV6WriteOption(TcpIp_LocalAddrIdType LocalIpAddrId,uint16 Option,uint16 DataLength,const uint8* DataPtr);
Std_ReturnType TcpIp_ChangeParameter(TcpIp_SocketIdType SocketId, TcpIp_ParamIdType ParameterId, const uint8* ParameterValue);
Std_ReturnType TcpIp_GetIpAddr(TcpIp_LocalAddrIdType LocalAddrId, TcpIp_SockAddrType* IpAddrPtr,
uint8* NetmaskPtr, TcpIp_SockAddrType* DefaultRouterPtr);
Std_ReturnType TcpIp_GetPhysAddr(TcpIp_LocalAddrIdType LocalAddrId, uint8* PhysAddrPtr);
TcpIp_ReturnType TcpIp_GetRemotePhysAddr(uint8 CtrlIdx, const TcpIp_SockAddrType* IpAddrPtr, uint8 *PhysAddrPtr, boolean initRes);
Std_ReturnType TcpIp_GetCtrlIdx(TcpIp_LocalAddrIdType LocalAddrId, uint8* CtrlIdxPtr);
Std_ReturnType TcpIp_UdpTransmit(TcpIp_SocketIdType SocketId, const uint8* DataPtr, const TcpIp_SockAddrType* RemoteAddrPtr, uint16 TotalLength);
Std_ReturnType TcpIp_TcpTransmit(TcpIp_SocketIdType SocketId, const uint8* DataPtr, uint32 AvailableLength, boolean ForceRetrieve);
void TcpIp_MainFunction(void);
/*
* Make the TcpIp_Config visible for others.
*/
extern const TcpIp_ConfigType TcpIp_Config;
#endif /* TCPIP_H */
|
2301_81045437/classic-platform
|
communication/TcpIp/inc/TcpIp.h
|
C
|
unknown
| 7,394
|
/*-------------------------------- Arctic Core ------------------------------
* Copyright (C) 2013, ArcCore AB, Sweden, www.arccore.com.
* Contact: <contact@arccore.com>
*
* You may ONLY use this file:
* 1)if you have a valid commercial ArcCore license and then in accordance with
* the terms contained in the written license agreement between you and ArcCore,
* or alternatively
* 2)if you follow the terms found in GNU General Public License version 2 as
* published by the Free Software Foundation and appearing in the file
* LICENSE.GPL included in the packaging of this file or here
* <http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt>
*-------------------------------- Arctic Core -----------------------------*/
#ifndef TCPIP_CBK_H
#define TCPIP_CBK_H
#include "Eth_GeneralTypes.h"
void TcpIp_RxIndication(uint8 CtrlIdx, Eth_FrameType FrameType, boolean IsBroadcast, const uint8* PhysAddrPtr, uint8* DataPtr, uint16 LenByte);
#endif /* TCPIP_CBK_H */
|
2301_81045437/classic-platform
|
communication/TcpIp/inc/TcpIp_Cbk.h
|
C
|
unknown
| 1,002
|
/*-------------------------------- Arctic Core ------------------------------
* Copyright (C) 2013, ArcCore AB, Sweden, www.arccore.com.
* Contact: <contact@arccore.com>
*
* You may ONLY use this file:
* 1)if you have a valid commercial ArcCore license and then in accordance with
* the terms contained in the written license agreement between you and ArcCore,
* or alternatively
* 2)if you follow the terms found in GNU General Public License version 2 as
* published by the Free Software Foundation and appearing in the file
* LICENSE.GPL included in the packaging of this file or here
* <http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt>
*-------------------------------- Arctic Core -----------------------------*/
/** @reqSettings DEFAULT_SPECIFICATION_REVISION=4.2.2 */
#ifndef TCPIP_CONFIG_TYPES_H_
#define TCPIP_CONFIG_TYPES_H_
#include "TcpIp_Types.h"
#if defined(USE_DEM)
#include "Dem.h"
typedef struct {
const Dem_EventIdType ConnRefused;
const Dem_EventIdType HostUnreach;
const Dem_EventIdType PacketToBig;
const Dem_EventIdType Timedout;
} TcpIp_DemEventReferencesType;
#endif
typedef struct {
const TcpIp_AssignmentLifetimeType AssignmentLifetime; //0..1
const TcpIp_IpAddrAssignmentType AssignmentMethod; //1
const uint8 AssignmentPriority; //1
const TcpIp_AssignmentTriggerType AssignmentTrigger; //1
} TcpIp_AddressAssignmentType;
typedef struct {
boolean ArcValid;
uint32 StaticIpAddress; //1
uint32 DefaultRouter; //0..1
uint8 Netmask; //0..1
} TcpIp_StaticIpAddressConfigType;
typedef struct {
const TcpIp_LocalAddrIdType AddressId; //1
const TcpIp_AddressTypeType AddressType; //1
const TcpIp_DomainType Domain; //1
const uint8 TcpIpCtrlRef; //1
const TcpIp_AddressAssignmentType *AddressAssignment; //1..*
TcpIp_StaticIpAddressConfigType *StaticIpAddrConfig; //0..1
} TcpIp_LocalAddrType;
typedef struct {
const uint16 ArpTableSizeMax;
}TcpIp_ArpConfigType;
typedef struct {
const uint8 Dummy;
}TcpIp_DhcpConfigType;
typedef struct {
const boolean FragmentationRxEnabled;
const uint8 NumFragments;
const uint16 NumReassDgrams;
const uint32 ReassTimeout;
const uint16 ArcMaxReceiveBufferSize;
}TcpIp_FragConfigType;
typedef struct {
const TcpIp_ArpConfigType *ArpConfigRef; //0..1
const TcpIp_DhcpConfigType *DhcpConfigRef; //0..1
const TcpIp_FragConfigType *FragConfigRef; //0..1
}TcpIp_IpV4CtrlType;
typedef struct {
const TcpIp_IpV4CtrlType *IpV4Ctrl; //0..1
//TcpIp_IpV6CtrlType *IpV6Ctrl; //0..1
}TcpIp_IpVXCtrlType;
typedef struct {
const uint8 FramePrioDefault; //0..1
//TcpIpDhcpServerConfigRef; //0..1
const uint8 EthIfCtrlRef; //1
#if defined(USE_DEM)
const TcpIp_DemEventReferencesType CtrlDemEventParameterRefs; //0..1
#endif
//const TcpIp_IpVXCtrlType IpVXCtrl; //1
} TcpIp_TcpIpCtrlType;
typedef struct {
const TcpIp_ArpConfigType *ArpConfigRef; //0..*
const TcpIp_DhcpConfigType *DhcpConfigRef; //0..*
} TcpIp_IpV4ConfigType;
typedef struct {
const TcpIp_IpV4ConfigType *IpV4Config; //0..1
} TcpIp_IpConfigType;
typedef struct {
const char *HeaderFileName;
const char *Name;
}TcpIp_PhysAddrChgHandlerType;
typedef struct {
const TcpIp_PhysAddrChgHandlerType *PhysAddrChgHandler; //0..1
} TcpIp_PhysAddrConfigType;
typedef enum {
TCPIP_CDD,
TCPIP_SOAD,
}TcpIp_SocketOwnerUpperLayerTypeType;
typedef struct {
// const char *SocketOwnerHeaderFileName; //0..1
const TcpIp_Up_CopyTxData SocketOwnerCopyTxDataFncPtr; //0..1
const TcpIp_Up_LocalIpAddrAssignmentChg SocketOwnerLocalIpAddrAssignmentChgFncPtr; //0..1
const TcpIp_Up_RxIndication SocketOwnerRxIndicationFncPtr; //0..1
const TcpIp_Up_TcpAccepted SocketOwnerTcpAcceptedFncPtr; //0..1
const TcpIp_Up_TcpConnected SocketOwnerTcpConnectedFncPtr; //0..1
const TcpIp_Up_TcpIpEvent SocketOwnerTcpIpEventFncPtr; //0..1
const TcpIp_Up_TxConfirmation SocketOwnerTxConfirmationFncPtr; //0..1
const TcpIp_SocketOwnerUpperLayerTypeType SocketOwnerUpperLayerType; //1
} TcpIp_SocketOwnerType;
typedef struct {
const TcpIp_SocketOwnerType *SocketOwnerList; //1..*
} TcpIp_SocketOwnerConfigType;
typedef struct {
const boolean TcpCongestionAvoidanceEnabled;
const boolean TcpFastRecoveryEnabled;
const boolean TcpFastRetransmitEnabled;
const uint32 TcpFinWait2Timeout;
const boolean TcpKeepAliveEnabled;
const uint32 TcpKeepAliveInterval;
const uint16 TcpKeepAliveProbesMax;
const uint32 TcpKeepAliveTime;
const uint8 *TcpMaxRtx;//0..1
const uint32 TcpMsl;
const boolean TcpNagleEnabled;
const uint16 TcpReceiveWindowMax;
const uint32 *TcpRetransmissionTimeout;//0..1
const boolean TcpSlowStartEnabled;
const uint8 TcpSynMaxRtx;
const uint32 TcpSynReceivedTimeout; //convert to milliseconds
const uint8 TcpTtl;
} TcpIp_TcpConfig;
typedef struct {
const uint8 UdpTtl;
} TcpIp_UdpConfig;
typedef struct {
const TcpIp_TcpIpCtrlType *CtrlList; //1..*
//TcpIp_DhcpServerConfig *TcpIpDhcpServerConfig; //0..*
// const TcpIp_IpConfigType *IpConfig; //0..1
const TcpIp_LocalAddrType *LocalAddrList; //1..*
//TcpIp_NvmBlock *NvmBlock; //0..1
const TcpIp_PhysAddrConfigType *PhysAddrConfig; //0..1
const TcpIp_SocketOwnerConfigType SocketOwnerConfig; //1
//const TcpIp_TcpConfig *TcpConfig; //0..1
//TcpIp_UdpConfig *UdpConfig; //0..1
} TcpIp_TcpIpConfigType;
/** @req 4.2.2/SWS_TCPIP_00067 */
typedef struct {
// Containers
const TcpIp_TcpIpConfigType Config; // 1
//TcpIp_TcpIpGeneralType General; // 1
} TcpIp_ConfigType;
#endif /*TCPIP_CONFIG_TYPES_H_*/
|
2301_81045437/classic-platform
|
communication/TcpIp/inc/TcpIp_ConfigTypes.h
|
C
|
unknown
| 5,886
|
/*-------------------------------- Arctic Core ------------------------------
* Copyright (C) 2013, ArcCore AB, Sweden, www.arccore.com.
* Contact: <contact@arccore.com>
*
* You may ONLY use this file:
* 1)if you have a valid commercial ArcCore license and then in accordance with
* the terms contained in the written license agreement between you and ArcCore,
* or alternatively
* 2)if you follow the terms found in GNU General Public License version 2 as
* published by the Free Software Foundation and appearing in the file
* LICENSE.GPL included in the packaging of this file or here
* <http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt>
*-------------------------------- Arctic Core -----------------------------*/
#ifndef TCPIP_ETHSM_H_
#define TCPIP_ETHSM_H_
#include "TcpIp_Types.h"
/* This header file shall shall export the part of the TcpIp API exactly required by EthSM.*/
/* @req SWS_TCPIP_00070 */
Std_ReturnType TcpIp_RequestComMode(uint8 CtrlIdx, TcpIp_StateType State);
#endif /*TCPIP_ETHSM_H_*/
|
2301_81045437/classic-platform
|
communication/TcpIp/inc/TcpIp_EthSM.h
|
C
|
unknown
| 1,065
|
/*-------------------------------- Arctic Core ------------------------------
* Copyright (C) 2013, ArcCore AB, Sweden, www.arccore.com.
* Contact: <contact@arccore.com>
*
* You may ONLY use this file:
* 1)if you have a valid commercial ArcCore license and then in accordance with
* the terms contained in the written license agreement between you and ArcCore,
* or alternatively
* 2)if you follow the terms found in GNU General Public License version 2 as
* published by the Free Software Foundation and appearing in the file
* LICENSE.GPL included in the packaging of this file or here
* <http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt>
*-------------------------------- Arctic Core -----------------------------*/
#ifndef TCPIP_TYPES_H_
#define TCPIP_TYPES_H_
#include "ComStack_Types.h"
/* This header file shall export the part of the TcpIp Types */
#define TCPIP_SA_DATA_SIZE_IPV6 20u /* To cover sockaddr_in and sockaddr_in6. */
#define TCPIP_SA_DATA_SIZE_IPV4 4u
#if (TCPIP_IPV6_ENABLED == STD_ON)
#define TCPIP_SA_DATA_SIZE TCPIP_SA_DATA_SIZE_IPV6 /* To cover sockaddr_in and sockaddr_in6. */
#else
#define TCPIP_SA_DATA_SIZE TCPIP_SA_DATA_SIZE_IPV4
#endif
/** @req 4.2.2/SWS_TCPIP_00009 */
typedef uint16 TcpIp_DomainType;
#define TCPIP_AF_INET 0x02u
#define TCPIP_AF_INET6 0x1Cu
/** @req 4.2.2/SWS_TCPIP_00010 */
typedef enum {
TCPIP_IPPROTO_TCP = 0x06,
TCPIP_IPPROTO_UDP = 0x11,
} TcpIp_ProtocolType;
/** !req 4.2.2/SWS_TCPIP_00012 */
typedef struct {
TcpIp_DomainType domain;
uint16 port;
#if defined(CFG_GNULINUX)
char addr[TCPIP_SA_DATA_SIZE];
#else
uint8 addr[TCPIP_SA_DATA_SIZE];
#endif
}TcpIp_SockAddrType;
/** @req 4.2.2/SWS_TCPIP_00013 */
typedef struct {
TcpIp_DomainType domain;
uint16 port;
uint32 addr[1];
}TcpIp_SockAddrInetType;
/** @req 4.2.2/SWS_TCPIP_00014 */
typedef struct {
TcpIp_DomainType domain;
uint16 port;
uint32 addr[4];
}TcpIp_SockAddrInet6Type;
/** @req 4.2.2/SWS_TCPIP_00030 */
typedef uint8 TcpIp_LocalAddrIdType;
/** @req 4.2.2/SWS_TCPIP_00038 */
typedef uint16 TcpIp_SocketIdType;
#define TCPIP_SOCKETID_INVALID 0xFFFFu
/* Specifies the TcpIp state for a specific EthIf controller */
/** @req 4.2.2/SWS_TCPIP_00073 */
typedef enum {
TCPIP_STATE_ONLINE,
TCPIP_STATE_ONHOLD,
TCPIP_STATE_OFFLINE,
TCPIP_STATE_STARTUP,
TCPIP_STATE_SHUTDOWN,
} TcpIp_StateType;
/** @req 4.2.2/SWS_TCPIP_00082 */
typedef enum {
TCPIP_IPADDR_STATE_ASSIGNED,
TCPIP_IPADDR_STATE_ONHOLD,
TCPIP_IPADDR_STATE_UNASSIGNED,
} TcpIp_IpAddrStateType;
/** @req 4.2.2/SWS_TCPIP_00031 */
typedef enum {
TCPIP_TCP_RESET,
TCPIP_TCP_CLOSED,
TCPIP_TCP_FIN_RECEIVED,
TCPIP_UDP_CLOSED,
}TcpIp_EventType;
/** @req 4.2.2/SWS_TCPIP_00065 */
typedef enum {
TCPIP_IPADDR_ASSIGNMENT_STATIC,
TCPIP_IPADDR_ASSIGNMENT_LINKLOCAL_DOIP,
TCPIP_IPADDR_ASSIGNMENT_DHCP,
TCPIP_IPADDR_ASSIGNMENT_LINKLOCAL,
TCPIP_IPADDR_ASSIGNMENT_IPV6_ROUTER,
}TcpIp_IpAddrAssignmentType;
/* map towards model */
#define TCPIP_STATIC TCPIP_IPADDR_ASSIGNMENT_STATIC
#define TCPIP_LINKLOCAL_DOIP TCPIP_IPADDR_ASSIGNMENT_LINKLOCAL_DOIP
#define TCPIP_DHCP TCPIP_IPADDR_ASSIGNMENT_DHCP
#define TCPIP_LINKLOCAL TCPIP_IPADDR_ASSIGNMENT_LINKLOCAL
#define TCPIP_IPV6_ROUTER TCPIP_IPADDR_ASSIGNMENT_IPV6_ROUTER
/** @req 4.2.2/SWS_TCPIP_00066 */
typedef enum {
TCPIP_OK,
TCPIP_E_NOT_OK,
TCPIP_E_PHYS_ADDR_MISS,
}TcpIp_ReturnType;
/** @req 4.2.2/SWS_TCPIP_00126 */
typedef uint8 TcpIp_ParamIdType;
#define TCPIP_PARAMID_TCP_RXWND_MAX 0x00u
#define TCPIP_PARAMID_FRAMEPRIO 0x01u
#define TCPIP_PARAMID_TCP_NAGLE 0x02u
#define TCPIP_PARAMID_TCP_KEEPALIVE 0x03u
#define TCPIP_PARAMID_TTL 0x04u
#define TCPIP_PARAMID_TCP_KEEPALIVE_TIME 0x05u
#define TCPIP_PARAMID_TCP_KEEPALIVE_PROBES_MAX 0x06u
#define TCPIP_PARAMID_TCP_KEEPALIVE_INTERVAL 0x07u
#define TCPIP_PARAMID_VENDOR_SPECIFIC 0x80u
/** @req 4.2.2/SWS_TCPIP_00133 */
typedef uint32 TcpIp_IpAddrWildcardType;
#define TCPIP_IPADDR_ANY 0x00u
/** @req 4.2.2/SWS_TCPIP_00132 */
typedef uint32 TcpIp_Ip6AddrWildcardType;
#define TCPIP_IP6ADDR_ANY 0x00u
/** @req 4.2.2/SWS_TCPIP_00134 */
typedef uint16 TcpIp_PortWildcardType;
#define TCPIP_PORT_ANY 0x00u
/** @req 4.2.2/SWS_TCPIP_00135 */
typedef uint32 TcpIp_LocalAddrIdWildcardType;
#define TCPIP_LOCALADDRID_ANY 0x00u
typedef enum{
TCPIP_MULTICAST,
TCPIP_UNICAST,
}TcpIp_AddressTypeType;
typedef enum{
TCPIP_FORGET,
TCPIP_STORE,
}TcpIp_AssignmentLifetimeType;
typedef enum{
TCPIP_AUTOMATIC,
TCPIP_MANUAL,
}TcpIp_AssignmentTriggerType;
typedef void (*TcpIp_Up_RxIndication) ( TcpIp_SocketIdType SocketId, const TcpIp_SockAddrType* RemoteAddrPtr, uint8* BufPtr, uint16 Length );
typedef void (*TcpIp_Up_TcpIpEvent)(TcpIp_SocketIdType SocketId,TcpIp_EventType Event);
typedef void (*TcpIp_Up_TxConfirmation)(TcpIp_SocketIdType SocketId, uint16 Length);
typedef Std_ReturnType (*TcpIp_Up_TcpAccepted)(TcpIp_SocketIdType SocketId,TcpIp_SocketIdType SocketIdConnected, const TcpIp_SockAddrType* RemoteAddrPtr);
typedef void (*TcpIp_Up_TcpConnected)(TcpIp_SocketIdType SocketId);
typedef BufReq_ReturnType (*TcpIp_Up_CopyTxData)(TcpIp_SocketIdType SocketId, uint8* BufPtr, uint16 BufLength);
typedef void (*TcpIp_Up_LocalIpAddrAssignmentChg)(TcpIp_LocalAddrIdType IpAddrId, TcpIp_IpAddrStateType State);
#endif /*TCPIP_TYPES_H_*/
|
2301_81045437/classic-platform
|
communication/TcpIp/inc/TcpIp_Types.h
|
C
|
unknown
| 5,568
|
/*-------------------------------- Arctic Core ------------------------------
* Copyright (C) 2013, ArcCore AB, Sweden, www.arccore.com.
* Contact: <contact@arccore.com>
*
* You may ONLY use this file:
* 1)if you have a valid commercial ArcCore license and then in accordance with
* the terms contained in the written license agreement between you and ArcCore,
* or alternatively
* 2)if you follow the terms found in GNU General Public License version 2 as
* published by the Free Software Foundation and appearing in the file
* LICENSE.GPL included in the packaging of this file or here
* <http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt>
*-------------------------------- Arctic Core -----------------------------*/
/** @reqSettings DEFAULT_SPECIFICATION_REVISION=4.2.2 */
/*lint -save -e9045 *//* Note: 9045 PC-lint: non-hidden definition of type -from stack suppressed */
/** @req 4.2.2/SWS_TCPIP_00052 */
/** @req 4.2.2/SWS_TCPIP_00148 */
/** @req 4.2.2/SWS_TCPIP_00053 */
/** @req 4.2.2/SWS_TCPIP_00054 */
/** @req 4.2.2/SWS_TCPIP_00095 */
/** @req 4.2.2/SWS_TCPIP_00096 */
/** @req 4.2.2/SWS_TCPIP_00102 */
/** @req 4.2.2/SWS_TCPIP_00097 */
/** @req 4.2.2/SWS_TCPIP_00098 */
/** !req 4.2.2/SWS_TCPIP_00231 */
/** @req 4.2.2/SWS_TCPIP_00055 */
/** @req 4.2.2/SWS_TCPIP_00056 */
/** !req 4.2.2/SWS_TCPIP_00091 */ /* arp TcpIpArpTableEntryTimeout */
/** @req 4.2.2/SWS_TCPIP_00092 */
/** !req 4.2.2/SWS_TCPIP_00142 */ /* Arp Table change callback */
/** !req 4.2.2/SWS_TCPIP_00093 */ /* partial - TcpIpArpNumGratuitousARPonStartup is not configured */
/** @req 4.2.2/SWS_TCPIP_00151 */
/** @req 4.2.2/SWS_TCPIP_00057 */
/** @req 4.2.2/SWS_TCPIP_00059 */
/** !req 4.2.2/SWS_TCPIP_00099 */
/** @req 4.2.2/SWS_TCPIP_00100 */
/** @req 4.2.2/SWS_TCPIP_00130 */
/** @req 4.2.2/SWS_TCPIP_00060 */
/** @req 4.2.2/SWS_TCPIP_00103 */
/** @req 4.2.2/SWS_TCPIP_00061 */
/** @req 4.2.2/SWS_TCPIP_00104 */
/** @req 4.2.2/SWS_TCPIP_00062 */
/** @req 4.2.2/SWS_TCPIP_00063 */
/** @req 4.2.2/SWS_TCPIP_00064 */
/** @req 4.2.2/SWS_TCPIP_00168 */
/** !req 4.2.2/SWS_TCPIP_00200 */ /* dhcp server */
/** !req 4.2.2/SWS_TCPIP_00201 */ /* dhcp server */
/** !req 4.2.2/SWS_TCPIP_00218 */ /* dhcp server */
/** !req 4.2.2/SWS_TCPIP_00200 */ /* dhcp server */
/** @req 4.2.2/SWS_TCPIP_00058 */
/** @req 4.2.2/SWS_TCPIP_00152 */
/** @req 4.2.2/SWS_TCPIP_00169 */
/** @req 4.2.2/SWS_TCPIP_00170 */
/** @req 4.2.2/SWS_TCPIP_00171 */
/** @req 4.2.2/SWS_TCPIP_00172 */
/** @req 4.2.2/SWS_TCPIP_00173 */
/** @req 4.2.2/SWS_TCPIP_00174 */
/** @req 4.2.2/SWS_TCPIP_00175 */
/** @req 4.2.2/SWS_TCPIP_00176 */
/** @req 4.2.2/SWS_TCPIP_00177 */
/** @req 4.2.2/SWS_TCPIP_00178 */
/** @req 4.2.2/SWS_TCPIP_00179 */
/** @req 4.2.2/SWS_TCPIP_00180 */
/** !req 4.2.2/SWS_TCPIP_00191 *//* Arp handled by lwip */
/** !req 4.2.2/SWS_TCPIP_00192 *//* Arp handled by lwip */
/** @req 4.2.2/SWS_TCPIP_00008 */
/** !req 4.2.2/SWS_TCPIP_00202 *//* TcpIp tiemout handled by lwip */
/** !req 4.2.2/SWS_TCPIP_00203 */ /* hw checksum, no cfg parameter ? Always using hw chk if available*/
/** !req 4.2.2/SWS_TCPIP_00204 */ /* hw checksum, no cfg parameter ? Always using hw chk if available*/
/** !req 4.2.2/SWS_TCPIP_00149 */ /* IPv6*/
/** !req 4.2.2/SWS_TCPIP_00150 */ /* IPv6*/
/** !req 4.2.2/SWS_TCPIP_00153 *//* IPv6*/
/** !req 4.2.2/SWS_TCPIP_00154 */ /* IPv6*/
/** !req 4.2.2/SWS_TCPIP_00156 */ /* IPv6*/
/** !req 4.2.2/SWS_TCPIP_00157 */ /* IPv6*/
/** !req 4.2.2/SWS_TCPIP_00158 */ /* IPv6*/
/** !req 4.2.2/SWS_TCPIP_00149 */ /* IPv6*/
/** !req 4.2.2/SWS_TCPIP_00159 */ /* IPv6*/
/** !req 4.2.2/SWS_TCPIP_00160 */ /* IPv6*/
/** !req 4.2.2/SWS_TCPIP_00161 */ /* IPv6*/
/** !req 4.2.2/SWS_TCPIP_00155 */ /* IPv6*/
/** !req 4.2.2/SWS_TCPIP_00232 */ /* IPv6*/
/** !req 4.2.2/SWS_TCPIP_00162 */ /* IPv6*/
/** !req 4.2.2/SWS_TCPIP_00163 */ /* IPv6*/
/** !req 4.2.2/SWS_TCPIP_00164 */ /* IPv6*/
/** !req 4.2.2/SWS_TCPIP_00165 */ /* IPv6*/
/** !req 4.2.2/SWS_TCPIP_00099 */ /* IPv6*/
/** !req 4.2.2/SWS_TCPIP_00166 */ /* IPv6*/
/** !req 4.2.2/SWS_TCPIP_00167 */ /* IPv6*/
/** !req 4.2.2/SWS_TCPIP_00181 */ /* IPv6*/
/** !req 4.2.2/SWS_TCPIP_00182 */ /* IPv6*/
/** !req 4.2.2/SWS_TCPIP_00183 */ /* IPv6*/
/** !req 4.2.2/SWS_TCPIP_00184 */ /* IPv6*/
/** !req 4.2.2/SWS_TCPIP_00185 */ /* IPv6*/
/** !req 4.2.2/SWS_TCPIP_00193 */ /* IPv6*/
/** !req 4.2.2/SWS_TCPIP_00194 */ /* IPv6*/
/** !req 4.2.2/SWS_TCPIP_00101 */ /* IPv6*/
/** !req 4.2.2/SWS_TCPIP_00230 */ /* IPv6*/
/** !req 4.2.2/SWS_TCPIP_00219 */ /* Nvm store*/
/** @req 4.2.2/SWS_TCPIP_00028 */ /* optional interfaces */
/** !req 4.2.2/SWS_TCPIP_00214 */
/** !req 4.2.2/SWS_TCPIP_00216 */
/** !req 4.2.2/SWS_TCPIP_00217 */
/** !req 4.2.2/SWS_TCPIP_00211 */
/** !req 4.2.2/SWS_TCPIP_00212 */
/** !req 4.2.2/SWS_TCPIP_00213 */
/** !req 4.2.2/SWS_TCPIP_00214 */
/** !req 4.2.2/SWS_TCPIP_00143 */
#include "TcpIp.h"
#include "TcpIp_Cbk.h"
#include "Eth_GeneralTypes.h"
#include "SchM_TcpIp.h"
#include "MemMap.h"
#include "EthSM_Cbk.h"
#include "TcpIp_EthSM.h"
#include "Bsd.h"
#include <string.h>
#include "lwip/def.h"
#include "lwip/opt.h"
#include "lwip/tcp.h"
#include "lwip/udp.h"
#include "lwip/snmp.h"
#include "lwip/mem.h"
#include "lwip/memp.h"
#include "lwip/tcpip.h"
#include "lwip/netif.h"
#include "netif/etharp.h"
#include "lwip/dhcp.h"
#include "lwip/autoip.h"
#include "lwip/ethip6.h"
#include "netbios.h"
#include "Cpu.h"
#if !defined(USE_NO_ETHIF)
#include "EthIf.h"
#else
#include "ethernetif.h" /* for backward compatibility, for non-ASR drivers */
#endif
#if defined(USE_CDDETHTRCV)
#include "CDD_EthTrcv.h"
#endif
/** @req 4.2.2/SWS_TCPIP_00068 */
#if defined(USE_DEM)
#include "Dem.h"
#endif
#if ( TCPIP_DEV_ERROR_DETECT == STD_ON )
#if defined(USE_DET)
#include "Det.h"
#endif
#define TCPIP_DET_REPORTERROR(_api,_err) (void)Det_ReportError(TCPIP_MODULE_ID, 0, (_api), (_err))
#else
#define TCPIP_DET_REPORTERROR(_api,_err)
#endif
/*lint -emacro(904,VALIDATE,VALIDATE_RV) 904 PC-Lint exception to MISRA 14.7 (validate DET macros)*/
#define VALIDATE(_exp,_api,_err ) \
if( !(_exp) ) { \
TCPIP_DET_REPORTERROR(_api, _err); \
return E_NOT_OK; \
}
#define VALIDATE_RV(_exp,_api,_err,_rv ) \
if( !(_exp) ) { \
TCPIP_DET_REPORTERROR(_api, _err); \
return _rv; \
}
#define VALIDATE_NO_RV(_exp,_api,_err ) \
if( !(_exp) ) { \
TCPIP_DET_REPORTERROR(_api, _err); \
return; \
}
#define TCPIP_MTU_SIZE 1500u
#define TCPIP_ETH_HEADER_SIZE 14u
#define TCPIP_ETH_MAC_ADDR_SIZE 6u
#define TCPIP_ETH_FRAMETYPE_SIZE 2u
/* Ethernet types used */
#define TCPIP_FRAME_TYPE_IPV4 0x0800
#define TCPIP_FRAME_TYPE_ARP 0x0806
/*
* Local variables
*/
typedef enum {
TCPIP_SOCKET_INIT,
TCPIP_SOCKET_BIND,
TCPIP_SOCKET_TCP_CONNECT_LISTEN,
TCPIP_SOCKET_TCP_CONNECTING,
TCPIP_SOCKET_TCP_LISTENING,
TCPIP_SOCKET_TCP_READY,
TCPIP_SOCKET_UDP_READY
} TcpIp_SocketStateType;
#define TCPIP_NOF_ERR_BEFORE_RESET 100
/*lint -save -e9027 -e734 */ /* 1.operands to Operators '<<''>>','&','|' are required to use */ /* 2..loss of precision higher to lower->OK
* 3. 9045 -unhidden declarations */
typedef struct {
TcpIp_SocketStateType socketState;
boolean socketProtocolIsTcp;
sint32 socketHandle;
uint8 socketOwnerId;
const TcpIp_LocalAddrType *ptrLocalAddr;
TcpIp_SockAddrType remoteAddr;
uint16 errCnt;
#ifdef CFG_TCPIP_DEBUG
uint16 errCntMax;
uint16 nofCloseSock;
sint32 sockErrorsArr[TCPIP_NOF_ERR_BEFORE_RESET];
#endif
}TcpIp_SocketAdminType;
typedef struct {
const TcpIp_LocalAddrType *ptrLocalUnicastAddr;
TcpIp_StateType tcpipEthIfCtrlState;
TcpIp_StateType tcpipEthIfRequestedCtrlState;
struct netif tcpipNetif;
boolean linkUp; /* Link status */
}TcpIp_CtrlAdminType;
static const TcpIp_ConfigType* Config;
/** @req 4.2.2/SWS_TCPIP_00083 */
static TcpIp_CtrlAdminType TcpIp_CtrlAdmin[TCPIP_NOF_CONTROLLERS];
static TcpIp_SocketAdminType TcpIp_SocketAdmin[TCPIP_MAX_NOF_SOCKETS];
/* static uint8 SocketIdInTransfer; */
boolean tcpip_initialized = FALSE;
#if !defined(USE_NO_ETHIF)
/* Define those to better describe your network interface. */
#define IFNAME0 'A'
#define IFNAME1 'R'
#define TCPIP_ETH_CTRL_INDEX 0 /* Fix this */
static struct netif *netIfPtrActive = NULL;/* Fix this */
#endif
/* Prototypes of static functions *//* Forward Function declarations */
#if LWIP_NETIF_STATUS_CALLBACK
void LwIP_StatusCallback(struct netif *netif);
#endif
#if !defined(USE_NO_ETHIF)
static err_t ethernetif_init(struct netif *netif);
static void LwIp_RxIndication( uint8 CtrlIdx, Eth_FrameType FrameType, boolean IsBroadcast, const uint8* PhysAddrPtr,
const Eth_DataType* DataPtr, uint16 LenByte );
static err_t LwIp_Output(struct netif *netif, struct pbuf *p);
#endif
static Std_ReturnType TcpIp_AutomaticIpAddrAssignment(TcpIp_LocalAddrIdType LocalAddrId, TcpIp_IpAddrAssignmentType Type);
#if LWIP_NETIF_STATUS_CALLBACK
/**
* @brief LWIP status callback after netif setup or down or link change
* @param netif
* @retval None
*/
void LwIP_StatusCallback(struct netif *netif) {
uint8 isLinkUp = netif_is_link_up(netif);
for(uint8 CtrlIdx=0; CtrlIdx < TCPIP_NOF_CONTROLLERS; CtrlIdx++){
if(&TcpIp_CtrlAdmin[CtrlIdx].tcpipNetif == netif){
if(TcpIp_CtrlAdmin[CtrlIdx].ptrLocalUnicastAddr != NULL){
TcpIp_CtrlAdmin[CtrlIdx].ptrLocalUnicastAddr->StaticIpAddrConfig->StaticIpAddress = netif->ip_addr.addr;
TcpIp_CtrlAdmin[CtrlIdx].ptrLocalUnicastAddr->StaticIpAddrConfig->DefaultRouter = netif->gw.addr;
TcpIp_CtrlAdmin[CtrlIdx].ptrLocalUnicastAddr->StaticIpAddrConfig->Netmask = 32 - ilog2((ntohl(netif->netmask.addr)));
TcpIp_CtrlAdmin[CtrlIdx].ptrLocalUnicastAddr->StaticIpAddrConfig->ArcValid = TRUE;
}
TcpIp_CtrlAdmin[CtrlIdx].linkUp = isLinkUp;
}
}
} /*lint !e818 */
#endif
#if !defined(USE_NO_ETHIF)
/**
* @brief LWIP Network interface
* @param netif
* @retval None
*/
static inline void LwIP_EthernetifStart(struct netif *netIf){
netIfPtrActive = netIf;
}
/**
* @brief HW initialisation function (low level init)
* @param netif
* @retval None
*/
static void LwIp_EthernetifInit(struct netif *netif){
uint8 macAddr[TCPIP_ETH_MAC_ADDR_SIZE] = ETH_MAC_ADDR;
/* set MAC hardware address length */
netif->hwaddr_len = TCPIP_ETH_MAC_ADDR_SIZE;
netif->hwaddr[0] = macAddr[0];
netif->hwaddr[1] = macAddr[1];
netif->hwaddr[2] = macAddr[2];
netif->hwaddr[3] = macAddr[3];
netif->hwaddr[4] = macAddr[4];
netif->hwaddr[5] = macAddr[5];
/* maximum transfer unit */
netif->mtu = TCPIP_MTU_SIZE;
/* device capabilities */
/* don't set NETIF_FLAG_ETHARP if this device is not an ethernet one */
netif->flags = NETIF_FLAG_BROADCAST | NETIF_FLAG_ETHARP | NETIF_FLAG_LINK_UP | NETIF_FLAG_IGMP;
}
/**
* @brief Function called at set up netif and subsequently HW initialisation
* This function should be passed as a parameter to netif_add() and hence it has file independent name
* @param netif
* @retval None
*/
static err_t ethernetif_init(struct netif *netif){
err_t ret;
ret = (err_t)ERR_ARG;
if(netif != NULL){
/*
* Initialize the snmp variables and counters inside the struct netif.
* The last argument should be replaced with your link speed, in units
* of bits per second.
*/
NETIF_INIT_SNMP(netif, snmp_ifType_ethernet_csmacd, 100000000);
netif->name[0] = IFNAME0;
netif->name[1] = IFNAME1;
/* We directly use etharp_output() here to save a function call.
* You can instead declare your own function an call etharp_output()
* from it if you have to do some checks before sending (e.g. if link
* is available...) */
netif->output = etharp_output;
netif->linkoutput = LwIp_Output;
#if LWIP_IPV6
netif->output_ip6 = ethip6_output;
#endif /* LWIP_IPV6 */
/* initialize the hardware */
LwIp_EthernetifInit(netif);
LwIP_EthernetifStart(netif);
ret = (err_t)ERR_OK;
}
return ret;
}
/**
* @brief Temporary Low level / OSI layer 2 control
* @retval None
*/
static void LwIp_EthernetifPreTcpIpInit(void){
/* ETHSM in dummy mode, control is here */
#if (ETHSM_DUMMY_MODE == STD_ON)
if(E_OK != EthIf_SetControllerMode(TCPIP_ETH_CTRL_INDEX,ETH_MODE_ACTIVE)){
TCPIP_DET_REPORTERROR(TCPIP_INIT_SERVICE_ID, TCPIP_E_ARC_ETHIF_INIT_STATE_FAILED);
}
#endif
#if ( ETHIF_TRCV_SUPPORT == STD_OFF) && defined(USE_CDDETHTRCV)
/* EthIf does not support Trcv module control, hence from here */
if(E_OK != EthTrcv_TransceiverInit(TCPIP_ETH_CTRL_INDEX)){
TCPIP_DET_REPORTERROR(TCPIP_INIT_SERVICE_ID, TCPIP_E_ARC_TRCV_INIT_STATE_FAILED);
}
#endif
#if defined(CFG_ZYNQ) || defined(CFG_JAC6)
uint8 macAddr[TCPIP_ETH_MAC_ADDR_SIZE] = ETH_MAC_ADDR;
if(E_OK != EthIf_UpdatePhysAddrFilter(TCPIP_ETH_CTRL_INDEX,macAddr,ETH_ADD_TO_FILTER)){
TCPIP_DET_REPORTERROR(TCPIP_INIT_SERVICE_ID, TCPIP_E_ARC_ETHIF_INIT_STATE_FAILED);
}
#endif
}
/**
* @brief Frames reception function
* @param CtrlIdx
* @param FrameType
* @param IsBroadcast
* @param PhysAddrPtr
* @param DataPtr
* @param LenByte
* @retval None
*/
static void LwIp_RxIndication( uint8 CtrlIdx, Eth_FrameType FrameType, boolean IsBroadcast, const uint8* PhysAddrPtr,
const Eth_DataType* DataPtr, uint16 LenByte ){
struct pbuf *p;
uint8 macAdrs[TCPIP_ETH_MAC_ADDR_SIZE];
uint8 macBroadcastAdrs[TCPIP_ETH_MAC_ADDR_SIZE] = {0xFF,0xFF,0xFF,0xFF,0xFF,0xFF};
uint16 AdaptFrameType;
err_t res;
#if ETH_PAD_SIZE
LenByte += ETH_PAD_SIZE; /* allow room for Ethernet padding */
#endif
p = pbuf_alloc(PBUF_RAW, LenByte+TCPIP_ETH_HEADER_SIZE, PBUF_POOL);
if (p != NULL){
#if ETH_PAD_SIZE
pbuf_header(p, -ETH_PAD_SIZE); /* drop the padding word */
#endif
if(IsBroadcast == TRUE){
MEMCPY((uint8*)p->payload,macBroadcastAdrs,TCPIP_ETH_MAC_ADDR_SIZE);
}else{
EthIf_GetPhysAddr(CtrlIdx,macAdrs);
MEMCPY((uint8*)p->payload,macAdrs,TCPIP_ETH_MAC_ADDR_SIZE);
}
MEMCPY((uint8*)p->payload+TCPIP_ETH_MAC_ADDR_SIZE,PhysAddrPtr,TCPIP_ETH_MAC_ADDR_SIZE); /*lint !e9016, array index is not usable */
AdaptFrameType = PP_HTONS(FrameType);
MEMCPY((uint8*)p->payload+(2*TCPIP_ETH_MAC_ADDR_SIZE),(void*)&AdaptFrameType,TCPIP_ETH_FRAMETYPE_SIZE);/*lint !e9016,array index is not usable */
MEMCPY((uint8*)p->payload+TCPIP_ETH_HEADER_SIZE,DataPtr,LenByte); /*lint !e9016,array index is not usable */
if(netIfPtrActive != NULL){ /* only one instance at the moment */
res = tcpip_input(p, netIfPtrActive);
if((err_t)ERR_OK != res){
(void)pbuf_free(p);
}
}else{
(void)pbuf_free(p);
}
}else{
/* Out of memory, Nothing to do but to through away data */
}
}
/**
* @brief Frames Transmission function
* @param netif
* @param p
* @retval err_t
*/
static err_t LwIp_Output(struct netif *netif, struct pbuf *p){ /*lint !e715 unused parameter netif */
const struct pbuf *q;
uint16 l = 0;
uint8 *buffer;
uint8 destMacAdrs[TCPIP_ETH_MAC_ADDR_SIZE];
uint8 frameTypeBuffer[TCPIP_ETH_FRAMETYPE_SIZE];
uint32 baseAddress;
uint32_t cnt;
Eth_BufIdxType bufIndex = 0;
uint16 lenByte;
Eth_FrameType frameType;
BufReq_ReturnType bufRes;
Std_ReturnType txRes;
uint8 ctrlIdx;
uint8 priority = 0;
err_t ret;
ret = E_OK;
#if ETH_PAD_SIZE
pbuf_header(p, -ETH_PAD_SIZE); /* drop the padding word */
#endif
lenByte = (p->tot_len - TCPIP_ETH_HEADER_SIZE);
MEMCPY(frameTypeBuffer, ((uint8*)p->payload + (2*TCPIP_ETH_MAC_ADDR_SIZE)), TCPIP_ETH_FRAMETYPE_SIZE); /*lint !e9016, array index is not usable */
frameType = ((frameTypeBuffer[0] << 8) | frameTypeBuffer[1]); /*lint !e9053 !e9031 */
#if 0
if(frameType != TCPIP_FRAME_TYPE_ARP){
ctrlIdx = TcpIp_SocketAdmin[SocketIdInTransfer].ptrLocalAddr->TcpIpCtrlRef;
}
#endif
ctrlIdx = TCPIP_ETH_CTRL_INDEX;
MEMCPY(destMacAdrs,(uint8*)p->payload,TCPIP_ETH_MAC_ADDR_SIZE);
#if (ETHIF_ENABLE_TX_INTERRUPT == STD_OFF)
EthIf_MainFunctionTx(); // No iterations inside
#endif
/* Note: take care to protect buffer allocation and transmit functionalities depending on the driver ,
* Autosar spec does not say about this, and we will not protect it here */
bufRes = EthIf_ProvideTxBuffer(ctrlIdx,frameType,priority,&bufIndex,(Eth_DataType **) &baseAddress, &lenByte);/*lint !e929 !e740 pointer access No harm */
if((bufRes != BUFREQ_OK)){
/* notify error and return */
/* Try to increase the number of TX buffers in the Lower layer */
ret = (err_t)ERR_MEM;
}
if (ret == E_OK) { /*lint !e737 loss of sign in promotion of ret to unsigned during comparison can be ignored */
buffer = (uint8*)(baseAddress);/*lint !e923 pointer access No harm */
/* Skip Ethernet header, ARP responses includes adding Ethernet header in the stack itself which is not easily
* bypassed from the stack at the moment, response callback other than ARP can be moved to ASR TcpIp layer. */
for(q = p; q != NULL; q = q->next){
if(l == 0u){
MEMCPY(&buffer[l], ((uint8*)q->payload + TCPIP_ETH_HEADER_SIZE), (q->len - TCPIP_ETH_HEADER_SIZE));/*lint !e9031 !e9016 */ /* array index is not usable */
l = (q->len - TCPIP_ETH_HEADER_SIZE);
}else{
MEMCPY(&buffer[l], (uint8*)q->payload, q->len);
l = l + q->len;
}
}
#if defined(ETH_CTRL_TX_FRAME_MIN_SIZE)
if(l < (ETH_CTRL_TX_FRAME_MIN_SIZE - TCPIP_ETH_HEADER_SIZE)){
for(uint8 i = l; i < (ETH_CTRL_TX_FRAME_MIN_SIZE - TCPIP_ETH_HEADER_SIZE); i++){
buffer[i] = 0u;
}
l = (ETH_CTRL_TX_FRAME_MIN_SIZE - TCPIP_ETH_HEADER_SIZE);
}
#endif
/* Try to send */
cnt = 0;
/** !req 4.2.2/SWS_TCPIP_00131 *//* Limitation in some drivers due to buffer getting free immediately when txconf is FALSE */
txRes = EthIf_Transmit(ctrlIdx,bufIndex,frameType,TRUE/*txconf*/,l,destMacAdrs);
// redundant piece of code
while(txRes == E_PENDING){
if((cnt % 500) == 0){
#if (ETHIF_ENABLE_TX_INTERRUPT == STD_OFF)
EthIf_MainFunctionTx();
#endif
txRes = EthIf_Transmit(ctrlIdx,bufIndex,frameType,TRUE,l,destMacAdrs);
}
cnt++;
if(cnt > 1000000){
/* timeout, notify error and return */
ret = (err_t)ERR_TIMEOUT;
break;
}
}
#if ETH_PAD_SIZE
if (E_OK == ret ) {
pbuf_header(p, ETH_PAD_SIZE); /* reclaim the padding word */
/* Return SUCCESS */
}
#endif
}
return ret;
} /*lint !e818 , const parameter is avoided due to callback *//*lint !e715 , netif parameter is not used */
#endif
/**
* @brief Callback function after TcpIp stack initilisation
* @param arg
* @retval none
*/
static void LwIp_TcpIpInitDone(void *arg)
{
tcpip_initialized = TRUE;
}/*lint !e818 , const parameter is avoided due to callback *//*lint !e715 *//* argument is not used */
static void LwIP_Init(void)
{
#if !defined(USE_NO_ETHIF)
LwIp_EthernetifPreTcpIpInit(); /*lint !e522 because of TRCV module */
#endif
#if NO_SYS
#if (MEM_LIBC_MALLOC==0)
mem_init();
#endif
#if (MEMP_MEM_MALLOC==0)
memp_init();
#endif
#else
pre_sys_init();
tcpip_init(LwIp_TcpIpInitDone, NULL);
while(tcpip_initialized == FALSE){
(void)Sleep(1);
};
#endif
}
/**
* @brief Internal function to set up network interface
* @param ..
* @retval E_OK or E_NOT_OK
*/
static boolean LwIP_AddNetIf( const ip_addr_t *ipaddr, const ip_addr_t *netmask, const ip_addr_t *gw,
netif_init_fn initFnc, netif_input_fn inputFnc, struct netif *netif)
{
boolean ret;
ret = TRUE;
/* Add network interface to the netif_list */
if(NULL == netif_add(netif, ipaddr, netmask, gw, NULL, initFnc, inputFnc)){
ret = FALSE;
}
if (TRUE == ret) {
/* Registers the default network interface.*/
netif_set_default(netif);
#if LWIP_NETIF_STATUS_CALLBACK
netif_set_status_callback(netif, LwIP_StatusCallback);
#endif
#if LWIP_NETIF_HOSTNAME
netif_set_hostname(netif, "LWIP"); /*lint !e1778 due to LWIP */ /*lint !e9036 due to LWIP */
#endif
}
return ret;
}
/*
* Local tcpip helper functions
*/
static void TcpIp_IpAddr32To8(uint32 src, uint8 *dest)
{
#if (CPU_BYTE_ORDER == HIGH_BYTE_FIRST)
dest[0] = (uint8)((src & 0xff000000U) >> 24);
dest[1] = (uint8)((src & 0x00ff0000U) >> 16);;
dest[2] = (uint8)((src & 0x0000ff00U) >> 8);;
dest[3] = (uint8)(src & 0x000000ffU);
#else
dest[3] = (uint8)((src & 0xff000000U) >> 24);
dest[2] = (uint8)((src & 0x00ff0000U) >> 16);;
dest[1] = (uint8)((src & 0x0000ff00U) >> 8);;
dest[0] = (uint8)(src & 0x000000ffU);
#endif
}
/*lint -save -e9032 -e9033 */
static void TcpIp_IpAddr8to32(const uint8 *src, uint32 *dest)
{
#if (CPU_BYTE_ORDER == HIGH_BYTE_FIRST)
*dest = ( ((uint32)((src[0]) & 0xff) << 24) | ((uint32)((src[1]) & 0xff) << 16) | ((uint32)((src[2]) & 0xff) << 8) | (uint32)((src[3]) & 0xff) );
#else
*dest = ( ((uint32)((src[3]) & 0xff) << 24) | ((uint32)((src[2]) & 0xff) << 16) | ((uint32)((src[1]) & 0xff) << 8) | (uint32)((src[0]) & 0xff) );
#endif
}
static void IP4NetmaskToIpAddr(ip_addr_t *NetmaskAddr, uint8 Netmask)
{
uint8 addr[4];
if(Netmask >= 24){
addr[0] = 255;
addr[1] = 255;
addr[2] = 255;
addr[3] = (uint8)(0xff00 >> (Netmask-24));
}else if(Netmask >= 16){
addr[0] = 255;
addr[1] = 255;
addr[2] = (uint8)(0xff00 >> (Netmask-16));
addr[3] = 0;
}else if(Netmask >= 8){
addr[0] = 255;
addr[1] = (uint8)(0xff00 >> (Netmask-8));
addr[2] = 0;
addr[3] = 0;
}else{
addr[0] = (uint8)(0xff00 >> Netmask);
addr[1] = 0;
addr[2] = 0;
addr[3] = 0;
}
TcpIp_IpAddr8to32(addr, &NetmaskAddr->addr);
}
/*lint -restore*/ /* end for 9032 9033 */
/* Gets the index of a controller in the global configuration structure. */
static inline uint8 getLocalAddrListConfigIdx(uint8 addressId) {
uint8 ret;
ret = 0;
for (uint8 i = 0; i < TCPIP_NOF_LOCALADDR; i++) {
if (Config->Config.LocalAddrList[i].AddressId == addressId) {
ret = i;
break;
}
}
return ret;
}
static void TcpIp_SwitchEthIfCtrlState(uint8 CtrlIdx, TcpIp_StateType TcpIpState)
{
SchM_Enter_TcpIp_EA_0();
if(TcpIp_CtrlAdmin[CtrlIdx].tcpipEthIfCtrlState != TcpIpState){
TcpIp_CtrlAdmin[CtrlIdx].tcpipEthIfCtrlState = TcpIpState;
/** @req 4.2.2/SWS_TCPIP_00084 */
/* After each transition the TcpIp module shall report the new
state to EthSM via EthSM_TcpIpModeIndication() */
(void)EthSM_TcpIpModeIndication(CtrlIdx, TcpIpState); /* no return check , nothing can do about it */
}
SchM_Exit_TcpIp_EA_0();
}
static Std_ReturnType TcpIp_GetFirstFreeSocket(TcpIp_SocketIdType *SocketIdPtr){
Std_ReturnType result = E_NOT_OK;
SchM_Enter_TcpIp_EA_0();
for(uint32 i=0; i < TCPIP_MAX_NOF_SOCKETS; i++){
if( (TcpIp_SocketAdmin[i].socketState == TCPIP_SOCKET_INIT) &&
(TcpIp_SocketAdmin[i].socketHandle == -1))
{
*SocketIdPtr = i;
result = E_OK;
break;
}
}
SchM_Exit_TcpIp_EA_0();
return result;
}
static void TcpIp_FreeUpSocket(TcpIp_SocketIdType SocketId){
SchM_Enter_TcpIp_EA_0();
TcpIp_SocketAdmin[SocketId].socketState = TCPIP_SOCKET_INIT;
TcpIp_SocketAdmin[SocketId].socketHandle = -1;
TcpIp_SocketAdmin[SocketId].ptrLocalAddr = NULL;
SchM_Exit_TcpIp_EA_0();
}
static void TcpIp_SocketStatusCheck(TcpIp_SocketIdType socketId)
{
sint32 sockErr;
boolean closeSock = FALSE;
TcpIp_EventType event;
/* Dont use getsockopt before better handling in lwip as it render in sleep behaviour
* uint32 sockErrLen = sizeof(sockErr);
* (void)getsockopt(TcpIp_SocketAdmin[socketId].socketHandle, SOL_SOCKET, SO_ERROR, &sockErr, &sockErrLen);
*/
sockErr = lwip_geterr(TcpIp_SocketAdmin[socketId].socketHandle);
switch(sockErr){
/* Close socket on fatal errors */
case ERR_ABRT:/** Connection aborted. */
case ERR_RST: /** Connection reset. */
case ERR_CLSD: /** Connection closed. */
case ERR_ARG: /** Illegal argument. */
closeSock = TRUE;
break;
case 0:/* OK */
case ERR_INPROGRESS:/** Operation in progress */
case ERR_WOULDBLOCK:/** Operation would block. */
break;
case ERR_MEM:/** Out of memory error. */
case ERR_BUF:/** Buffer error. */
case ERR_TIMEOUT:/** Timeout. */
case ERR_RTE:/** Routing problem. */
case ERR_VAL:/** Illegal value. */
case ERR_USE:/** Address in use. */
case ERR_ALREADY:/** Already connecting. */
case ERR_ISCONN:/** Conn already established.*/
case ERR_CONN:/** Not connected. */
case ERR_IF:/** Low-level netif error */
default:
TcpIp_SocketAdmin[socketId].errCnt++;
#ifdef CFG_TCPIP_DEBUG
if(TcpIp_SocketAdmin[socketId].errCnt > TcpIp_SocketAdmin[socketId].errCntMax){
TcpIp_SocketAdmin[socketId].errCntMax = TcpIp_SocketAdmin[socketId].errCnt;
}
TcpIp_SocketAdmin[socketId].sockErrorsArr[TcpIp_SocketAdmin[socketId].errCnt] = sockErr;
#endif
if(TcpIp_SocketAdmin[socketId].errCnt >= TCPIP_NOF_ERR_BEFORE_RESET){
closeSock = TRUE;
TcpIp_SocketAdmin[socketId].errCnt = 0;
}
break;
}
if(closeSock == TRUE){
#ifdef CFG_TCPIP_DEBUG
TcpIp_SocketAdmin[socketId].nofCloseSock++;
#endif
(void)closesocket(TcpIp_SocketAdmin[socketId].socketHandle);
if(TRUE == TcpIp_SocketAdmin[socketId].socketProtocolIsTcp){
event = TCPIP_TCP_CLOSED;
}else{
event = TCPIP_UDP_CLOSED;
}
/** @req 4.2.2/SWS_TCPIP_00144 */
/** @req 4.2.2/SWS_TCPIP_00224 */
/* The TcpIp module shall indicate events related to sockets to
the upper layer module by using the Up_TcpIpEvent API and the following events:
TCPIP_TCP_RESET, TCPIP_TCP_CLOSED, TCPIP_TCP_FIN_RECEIVED and
TCPIP_UDP_CLOSED. */
if(Config->Config.SocketOwnerConfig.SocketOwnerList[TcpIp_SocketAdmin[socketId].socketOwnerId].SocketOwnerTcpIpEventFncPtr != NULL){
Config->Config.SocketOwnerConfig.SocketOwnerList[TcpIp_SocketAdmin[socketId].socketOwnerId].SocketOwnerTcpIpEventFncPtr(socketId, event);
}
TcpIp_FreeUpSocket(socketId);
}
}
static uint16 TcpIp_SendIpMessage(sint32 SocketHandle, const uint8* DataPtr, const TcpIp_SockAddrType* RemoteAddrPtr, uint16 TotalLength)
{
uint16 bytesSent = 0;
sint16 response = 0;
if (RemoteAddrPtr == NULL) {
/* TCP */
response = send(SocketHandle, DataPtr, TotalLength, 0);
} else {
/* UDP */
struct sockaddr_in toAddr;
uint32 toAddrLen = sizeof(toAddr);
toAddr.sin_family = RemoteAddrPtr->domain;
toAddr.sin_len = sizeof(toAddr);
//uint8 length = (RemoteAddrPtr->domain == TCPIP_AF_INET6 ? TCPIP_SA_DATA_SIZE_IPV6:TCPIP_SA_DATA_SIZE_IPV4);
TcpIp_IpAddr8to32(RemoteAddrPtr->addr, &toAddr.sin_addr.s_addr);
toAddr.sin_port = htons(RemoteAddrPtr->port);
response = sendto(SocketHandle, DataPtr, TotalLength, 0, (struct sockaddr *)&toAddr, toAddrLen);/*lint !e929 !e740 LWIP No harm */
}
if(response >= 0){
bytesSent = (uint16)response;
}
return bytesSent;
}
static inline boolean TcpIp_BufferGet(uint32 size, uint8** buffPtr)
{
boolean res;
*buffPtr = mem_malloc(size);
res = (*buffPtr != NULL) ? TRUE : FALSE;
return res;
}
static inline void TcpIp_BufferFree(uint8* buffPtr)
{
mem_free(buffPtr);
}
static Std_ReturnType TcpIp_ChangePhysAddrFilterForMulticast(uint8 CtrlIdx, uint32 ipaddr, Eth_FilterActionType action)
{
uint8 mcastaddr[6];
uint8 mcastipaddr[4];
TcpIp_IpAddr32To8(ipaddr, mcastipaddr);
mcastaddr[0] = 0x01u;
mcastaddr[1] = 0x00u;
mcastaddr[2] = 0x5eu;
mcastaddr[3] = mcastipaddr[1] & 0x7fu;
mcastaddr[4] = mcastipaddr[2];
mcastaddr[5] = mcastipaddr[3];
return EthIf_UpdatePhysAddrFilter(CtrlIdx, mcastaddr, action);
}
static Std_ReturnType verifyLocalAddrId(TcpIp_LocalAddrIdType LocalAddrId){
boolean result = E_NOT_OK;
for(uint8 i = 0; i < TCPIP_NOF_LOCALADDR; i++){
if(Config->Config.LocalAddrList[i].AddressId == LocalAddrId){
/* Id found in the config */
result = E_OK;
break;
}
}
return result;
}
/**
* @brief This API creates/allocates a new socket , needed to be global for TcpIp configuration file to use this
* @param SocketOwnerId - Socket Id identifying the socket owner
* @param Domain - IP address family.
* @param protocol - Socket protocol as sub-family of parameter type.
* @param SocketIdPtr - Pointer to socket identifier representing the requested socket.
* This socket identifier must be provided for all further API calls which requires a SocketId.
* @return E_OK or E_NOT_OK
*/
Std_ReturnType TcpIp_GetSocket(uint8 SocketOwnerId,TcpIp_DomainType Domain, TcpIp_ProtocolType Protocol, TcpIp_SocketIdType* SocketIdPtr)
{
sint32 sockFd;
sint32 sockType;
Std_ReturnType result = E_OK;
/* @req 4.2.2/SWS_TCPIP_00128 */
VALIDATE( ((Domain == TCPIP_AF_INET) || (Domain == TCPIP_AF_INET6)), TCPIP_GETSOCKET_SERVICE_ID, TCPIP_E_AFNOSUPPORT)
// No specified autosar error for protocol check, use TCPIP_E_NOPROTOOPT as it seems most logical
VALIDATE( (TCPIP_IPPROTO_UDP == Protocol) || (TCPIP_IPPROTO_TCP == Protocol), TCPIP_GETSOCKET_SERVICE_ID, TCPIP_E_NOPROTOOPT)
if (TCPIP_IPPROTO_TCP == Protocol) {
sockType = SOCK_STREAM;
} else {
sockType = SOCK_DGRAM;
}
sockFd = socket(Domain, sockType, 0);
if(sockFd < 0){
result = E_NOT_OK;
}else{
TcpIp_SocketIdType socketId;
sint32 on = 1;
if(E_OK == TcpIp_GetFirstFreeSocket(&socketId)){
/* Socket assigned, get first free socket index */
TcpIp_SocketAdmin[socketId].socketHandle = sockFd;
TcpIp_SocketAdmin[socketId].socketOwnerId = SocketOwnerId;
TcpIp_SocketAdmin[socketId].socketState = TCPIP_SOCKET_BIND;
TcpIp_SocketAdmin[socketId].socketProtocolIsTcp = ((TCPIP_IPPROTO_TCP == Protocol) ? TRUE:FALSE );
*SocketIdPtr = socketId;
if((err_t)ERR_OK != ioctlsocket(sockFd, FIONBIO, &on)){ /*lint !e569 !e970 !e9053 LWIP */ // Set socket to non block mode
result = E_NOT_OK;
}
}else{
result = E_NOT_OK;
(void)closesocket(sockFd);
}
}
return result;
}
/**
* @brief This service initializes the TCP/IP Stack
* @param SocketId - Socket handle identifying the local socket resource ConfigPtr - Configuration data ptr
* @return void
*/
/** @req 4.2.2/SWS_TCPIP_00002 */
void TcpIp_Init(const TcpIp_ConfigType* ConfigPtr){ /*lint !e9046 Typographical ambiguity */
if(ConfigPtr != NULL){
Config = ConfigPtr;
for(uint32 i=0; i < TCPIP_NOF_CONTROLLERS; i++){
TcpIp_CtrlAdmin[i].tcpipEthIfCtrlState = TCPIP_STATE_OFFLINE;
TcpIp_CtrlAdmin[i].tcpipEthIfRequestedCtrlState = TCPIP_STATE_OFFLINE;
TcpIp_CtrlAdmin[i].ptrLocalUnicastAddr = NULL;
TcpIp_CtrlAdmin[i].linkUp = FALSE;
}
for(uint32 i=0; i < TCPIP_MAX_NOF_SOCKETS; i++){
TcpIp_SocketAdmin[i].socketState = TCPIP_SOCKET_INIT;
TcpIp_SocketAdmin[i].socketHandle = -1;
TcpIp_SocketAdmin[i].ptrLocalAddr = NULL;
TcpIp_SocketAdmin[i].socketProtocolIsTcp = FALSE;
TcpIp_SocketAdmin[i].errCnt = 0;
}
LwIP_Init();
}
}
/**
* @brief By this API service the TCP/IP stack is requested to close the socket and release
* all related resources.
* @param SocketId - Socket handle identifying the local socket resource
* @param Abort - TRUE: connection will immediately be terminated by sending a
* RST-Segment and releasing all related resources.
* FALSE: connection will be terminated after performing a regular
* connection termination handshake and releasing all related resources.
* @return result of the function.
*/
/** @req 4.2.2/SWS_TCPIP_00017 */
Std_ReturnType TcpIp_Close(TcpIp_SocketIdType SocketId, boolean Abort){
Std_ReturnType result = E_NOT_OK;
TcpIp_EventType event;
(void)Abort;
/** !req 4.2.2/SWS_TCPIP_00109 *//* Using sockets can not handle TCP abort */
/** @req 4.2.2/SWS_TCPIP_00110 */
/* Ignore abort parameter as closesocket always perform a FIN/ACK handshake. Using
* shutdown does not solve this either */
if((err_t)ERR_OK == closesocket(TcpIp_SocketAdmin[SocketId].socketHandle)){
if(TRUE == TcpIp_SocketAdmin[SocketId].socketProtocolIsTcp){
event = TCPIP_TCP_CLOSED;
}else{
event = TCPIP_UDP_CLOSED;
}
if(Config->Config.SocketOwnerConfig.SocketOwnerList[TcpIp_SocketAdmin[SocketId].socketOwnerId].SocketOwnerTcpIpEventFncPtr != NULL){
Config->Config.SocketOwnerConfig.SocketOwnerList[TcpIp_SocketAdmin[SocketId].socketOwnerId].SocketOwnerTcpIpEventFncPtr(SocketId, event);
}
TcpIp_FreeUpSocket(SocketId);
/* Update to upper layer via callback - Pending */
result = E_OK;
}
return result;
}
/**
* @brief By this API service the TCP/IP stack is requested to bind a UDP or TCP socket to
* a local resource.
* @param SocketId - Socket handle identifying the local socket resource
* @param LocalAddrId - IP address identifier representing the local IP address and EthIf
* controller to bind the socket to.
* @param PortPtr - Pointer to memory where the local port to which the socket shall
* be bound is specified. In case the parameter is specified as
* TCPIP_PORT_ANY, the TCP/IP stack shall choose the local port
* automatically from the range 49152 to 65535 and shall update the
* parameter to the chosen value.
* @return result of the function.
*/
/** @req 4.2.2/SWS_TCPIP_00015 */
Std_ReturnType TcpIp_Bind(TcpIp_SocketIdType SocketId, TcpIp_LocalAddrIdType LocalAddrId, uint16* PortPtr){
/* TcpIp_LocalAddrIdType as TCPIP_LOCALADDRID_ANY to bind to any EthIf controller - pending */
const TcpIp_LocalAddrType *ptrLocalAddr;
struct sockaddr_in sLocalAddr; /* only ipv4 */
Std_ReturnType result;
socklen_t addrlen;
result = E_OK;
if(verifyLocalAddrId(LocalAddrId) != E_OK){
result = E_NOT_OK;
}
if (E_OK == result) {
ptrLocalAddr = &Config->Config.LocalAddrList[getLocalAddrListConfigIdx(LocalAddrId)]; /* This could be ANY - to listen to any IP address*/
/** @req 4.2.2/SWS_TCPIP_00111 */
/** @req 4.2.2/SWS_TCPIP_00130 */
/** @req 4.2.2/SWS_TCPIP_00015 */
/** !req 4.2.2/SWS_TCPIP_00146 */
/** !req 4.2.2/SWS_TCPIP_00147 */
memset((uint8 *)&sLocalAddr, 0, sizeof(sLocalAddr));/*lint !e928 pointer to pointer no harm */
/*Source*/
sLocalAddr.sin_family = ptrLocalAddr->Domain;
sLocalAddr.sin_len = sizeof(sLocalAddr);
sLocalAddr.sin_addr.s_addr = ptrLocalAddr->StaticIpAddrConfig->StaticIpAddress;
sLocalAddr.sin_port = htons(*PortPtr);
if(bind(SocketId, (struct sockaddr *)&sLocalAddr, sizeof(sLocalAddr)) < 0) { /*lint !e929 !e740 */ /* pointer to pointer no harm */
result = E_NOT_OK;
}else{
if(ptrLocalAddr->AddressType == TCPIP_MULTICAST){
struct ip_mreq mreq;
mreq.imr_multiaddr.s_addr = sLocalAddr.sin_addr.s_addr;
/** @req 4.2.2/SWS_TCPIP_00178 */
if(TcpIp_CtrlAdmin[ptrLocalAddr->TcpIpCtrlRef].ptrLocalUnicastAddr != NULL){
if(TRUE == TcpIp_CtrlAdmin[ptrLocalAddr->TcpIpCtrlRef].ptrLocalUnicastAddr->StaticIpAddrConfig->ArcValid){
mreq.imr_interface.s_addr = TcpIp_CtrlAdmin[ptrLocalAddr->TcpIpCtrlRef].ptrLocalUnicastAddr->StaticIpAddrConfig->StaticIpAddress;
}
else{
mreq.imr_interface.s_addr = htonl(INADDR_ANY);
}
}
if (setsockopt(SocketId, IPPROTO_IP, IP_ADD_MEMBERSHIP, &mreq, sizeof(mreq)) < 0)
{
result = E_NOT_OK;
/* IMPROVMENT, remove this when know working */
}
}
if(result == E_OK){
/* Find out what port was assigned */
if((err_t)ERR_OK == getsockname(SocketId, (struct sockaddr *)&sLocalAddr, &addrlen)){ /*lint !e929 !e740 */ /* pointer to pointer no harm */
*PortPtr = htons(sLocalAddr.sin_port);
}else{
TCPIP_DET_REPORTERROR(TCPIP_BIND_SERVICE_ID, TCPIP_E_ARC_GENERAL_FAILURE_TCPIP_STACK);
}
TcpIp_SocketAdmin[SocketId].socketHandle = SocketId;
TcpIp_SocketAdmin[SocketId].ptrLocalAddr = ptrLocalAddr;
if(TRUE == TcpIp_SocketAdmin[SocketId].socketProtocolIsTcp){
TcpIp_SocketAdmin[SocketId].socketState = TCPIP_SOCKET_TCP_CONNECT_LISTEN;
}else{
TcpIp_SocketAdmin[SocketId].socketState = TCPIP_SOCKET_UDP_READY;
}
}
}
}
return result;
}
/**
* @brief By this API service the TCP/IP stack is requested to establish a TCP connection to
* the configured peer.
* @param SocketId - Socket handle identifying the local socket resource
* @param RemoteAddrPtr - IP address and port of the remote host to connect to.
* @return result of the function.
*/
/** @req 4.2.2/SWS_TCPIP_00022 */
Std_ReturnType TcpIp_TcpConnect(TcpIp_SocketIdType SocketId, const TcpIp_SockAddrType* RemoteAddrPtr){
Std_ReturnType result = E_OK;
struct sockaddr_in socketAddress;
/** @req 4.2.2/SWS_TCPIP_00129 */
VALIDATE( (NULL != RemoteAddrPtr), TCPIP_TCPCONNECT_SERVICE_ID, TCPIP_E_PARAM_POINTER)
memset((uint8 *)&socketAddress, 0, sizeof(socketAddress));/*lint !e928 pointer to pointer no harm */
socketAddress.sin_family = RemoteAddrPtr->domain;
socketAddress.sin_port = htons(RemoteAddrPtr->port);
//length = (RemoteAddrPtr->domain == TCPIP_AF_INET6 ? TCPIP_SA_DATA_SIZE_IPV6:TCPIP_SA_DATA_SIZE_IPV4);
TcpIp_IpAddr8to32(RemoteAddrPtr->addr, &socketAddress.sin_addr.s_addr);
/** @req 4.2.2/SWS_TCPIP_00112 */
(void)connect(TcpIp_SocketAdmin[SocketId].socketHandle, (struct sockaddr *)&socketAddress, sizeof(struct sockaddr)); /*lint !e929 !e740 */ /* pointer to pointer no harm */
/* Non blocking connect call will always return error so need to check response */
TcpIp_SocketAdmin[SocketId].socketState = TCPIP_SOCKET_TCP_CONNECTING;
return result;
}
/**
* @brief By this API service the TCP/IP stack is requested to listen on the
* TCP socket specified by the socket identifier.
* @param SocketId - Socket handle identifying the local socket resource
* @param MaxChannels - Maximum number of new parallel connections established on
* this listen connection.
* @return result of the function.
*/
/** @req 4.2.2/SWS_TCPIP_00023 */
Std_ReturnType TcpIp_TcpListen(TcpIp_SocketIdType SocketId, uint16 MaxChannels){
Std_ReturnType result = E_NOT_OK;
/** @req 4.2.2/SWS_TCPIP_00113 */
/** @req 4.2.2/SWS_TCPIP_00114 */
if((err_t)ERR_OK == listen(TcpIp_SocketAdmin[SocketId].socketHandle, MaxChannels)){ /* BSD style */
TcpIp_SocketAdmin[SocketId].socketState = TCPIP_SOCKET_TCP_LISTENING;
result = E_OK;
}
return result;
}
/**
* @brief By this API service the reception of socket data is confirmed to the TCP/IP stack.
* @param SocketId - Socket handle identifying the local socket resource
* @param Length - Number of bytes finally consumed by the upper layer.
* @return result of the function.
*/
/** !req 4.2.2/SWS_TCPIP_00024 */
/** !req 4.2.2/SWS_TCPIP_00115 */
Std_ReturnType TcpIp_TcpReceived(TcpIp_SocketIdType SocketId, uint32 Length){
Std_ReturnType result = E_OK;
(void)SocketId;
(void)Length;
// Dont really understand the use...
return result;
}
/**
* @brief By this API service the TCP/IP stack is requested to change the TcpIp state of the
* communication network identified by EthIf controller index.
* @param CtrlIdx - EthIf controller index to identify the communication network
* where the TcpIp state is requested.
* @param State - Requested TcpIp state.
* @return result of the function.
*/
/** @req 4.2.2/SWS_TCPIP_00070 */
Std_ReturnType TcpIp_RequestComMode( uint8 CtrlIdx, TcpIp_StateType State ){
Std_ReturnType result = E_NOT_OK;
VALIDATE(CtrlIdx < TCPIP_NOF_CONTROLLERS, TCPIP_REQUESTCOMMODE_SERVICE_ID, TCPIP_E_INV_ARG);
/** @req 4.2.2/SWS_TCPIP_00089 */
VALIDATE(State != TCPIP_STATE_STARTUP, TCPIP_REQUESTCOMMODE_SERVICE_ID, TCPIP_E_INV_ARG);
VALIDATE(State != TCPIP_STATE_SHUTDOWN, TCPIP_REQUESTCOMMODE_SERVICE_ID, TCPIP_E_INV_ARG);
/** @req 4.2.2/SWS_TCPIP_00136 */
if(State != TcpIp_CtrlAdmin[CtrlIdx].tcpipEthIfCtrlState){
switch (State) {
case TCPIP_STATE_OFFLINE:
/** @req 4.2.2/SWS_TCPIP_00072 */
//initiate deactivation of the TcpIp communication on the related EthIf controller
//(e.g. close all sockets using the specified EthIf controller
result = E_OK;
break;
case TCPIP_STATE_ONLINE:
/** @req 4.2.2/SWS_TCPIP_00071 */
//initiate activation of the TcpIp communication on the related EthIf controller (e.g.
//start IP-Address assignment according to the configured IP address assignment
//policy for the EthIf controller)
result = E_OK;
break;
case TCPIP_STATE_ONHOLD:
/** @req 4.2.2/SWS_TCPIP_00074 */
//set the TcpIp communication to on hold, i.e. new transmit requests shall not be
//accepted, but sockets and assigned IP addresses shall be kept
if(TcpIp_CtrlAdmin[CtrlIdx].tcpipEthIfCtrlState == TCPIP_STATE_ONLINE){
result = E_OK; /* Can only request onhold from online */
}
break;
default:
TCPIP_DET_REPORTERROR(TCPIP_REQUESTCOMMODE_SERVICE_ID, TCPIP_E_INV_ARG);
break;
}
}else{
/* IMPROVMENT shall we respond E_OK when a request for the already active state is made? */
result = E_OK;
}
if(result == E_OK){
TcpIp_CtrlAdmin[CtrlIdx].tcpipEthIfRequestedCtrlState = State;
}
return result;
}
/**
* @brief By this API service the local IP address assignment for the IP address specified by
* LocalAddrId shall be initiated.
* @param LocalAddrId - IP address index specifying the IP address for which an
* assignment shall be initiated.
* @param Type - Type of IP address assignment which shall be initiated
* @param LocalIpAddrPtr - Pointer to structure containing the IP address which shall be
* assigned to the EthIf controller indirectly specified via LocalAddrId.
* @param Netmask - Network mask of IPv4 address or address prefix of IPv6 address in CIDR Notation.
* @param DefaultRouterPtr - Pointer to structure containing the IP address of the default router
* (gateway) which shall be assigned.
* @return result of the function.
*/
/** @req 4.2.2/SWS_TCPIP_00037 */
Std_ReturnType TcpIp_RequestIpAddrAssignment(TcpIp_LocalAddrIdType LocalAddrId, TcpIp_IpAddrAssignmentType Type,
const TcpIp_SockAddrType* LocalIpAddrPtr, uint8 Netmask, const TcpIp_SockAddrType* DefaultRouterPtr){
const TcpIp_LocalAddrType *ptrLocalAddr;
struct netif *netif;
ip_addr_t ipaddr;
ip_addr_t netmask; /*lint !e9046 No Typographical ambiguity */
ip_addr_t gw;
Std_ReturnType result;
ipaddr.addr = 0;
netmask.addr = 0;
gw.addr = 0;
result = E_OK;
if(verifyLocalAddrId(LocalAddrId) != E_OK){
result = E_NOT_OK;
}
if (E_OK == result) {
ptrLocalAddr = &Config->Config.LocalAddrList[getLocalAddrListConfigIdx(LocalAddrId)];
netif = &TcpIp_CtrlAdmin[ptrLocalAddr->TcpIpCtrlRef].tcpipNetif;
/** @req 4.2.2/SWS_TCPIP_00195 */
/** @req 4.2.2/SWS_TCPIP_00198 */
if(TCPIP_AUTOMATIC == ptrLocalAddr->AddressAssignment->AssignmentTrigger){
result = E_NOT_OK;
}
else
{
/** @req 4.2.2/SWS_TCPIP_00116 */
if(Type == TCPIP_IPADDR_ASSIGNMENT_STATIC) { /* this is left to the user , not verified IpAddress table with LocalAddrId */
/** @req 4.2.2/SWS_TCPIP_00079 */
if(TRUE == ptrLocalAddr->StaticIpAddrConfig->ArcValid){
ipaddr.addr = ptrLocalAddr->StaticIpAddrConfig->StaticIpAddress;
gw.addr = ptrLocalAddr->StaticIpAddrConfig->DefaultRouter;
IP4NetmaskToIpAddr(&netmask, ptrLocalAddr->StaticIpAddrConfig->Netmask);
}else{
/** @req 4.2.2/SWS_TCPIP_00100 */
TcpIp_IpAddr8to32(LocalIpAddrPtr->addr,&ipaddr.addr);
// IP4_ADDR(&ipaddr, LocalIpAddrPtr->addr[0],LocalIpAddrPtr->addr[1],LocalIpAddrPtr->addr[2],LocalIpAddrPtr->addr[3]);/*lint !e9032 !e9033 LWIP No harm */
IP4NetmaskToIpAddr(&netmask, Netmask);
// IP4_ADDR(&gw, DefaultRouterPtr->addr[0],DefaultRouterPtr->addr[1],DefaultRouterPtr->addr[2],DefaultRouterPtr->addr[3]);/*lint !e9032 !e9033 LWIP No harm */
TcpIp_IpAddr8to32(DefaultRouterPtr->addr,&gw.addr);
ptrLocalAddr->StaticIpAddrConfig->StaticIpAddress = ipaddr.addr;
ptrLocalAddr->StaticIpAddrConfig->DefaultRouter = gw.addr;
ptrLocalAddr->StaticIpAddrConfig->Netmask = Netmask;
//ptrLocalAddr->StaticIpAddrConfig->ArcValid = TRUE;
}
}
if(ip_addr_ismulticast(&ipaddr)){/* Multicast address */ /*lint !e845 !e778 !e572 LWIP */ /*lint !e644 wrong lint */
/* Join group here or in bind ? How will multicast be added ??? */
/** @req 4.2.2/SWS_TCPIP_00080 */
/* In case a multicast address is assigned, TcpIp shall derive
the related physical address from the multicast IP address and add the derived
address to the Eth MAC address filter by calling EthIf_UpdatePhys-
AddrFilter() with action set to ETH_ADD_TO_FILTER. */
result = TcpIp_ChangePhysAddrFilterForMulticast(ptrLocalAddr->TcpIpCtrlRef, ipaddr.addr, ETH_ADD_TO_FILTER);
}
else{ /* Unicast address */
if( TRUE == LwIP_AddNetIf(&ipaddr, &netmask, &gw, ethernetif_init, tcpip_input, netif)){//IMPROVEMENT Assume there is only one unicast and netif per controller and hardcoded to one here... */
TcpIp_CtrlAdmin[ptrLocalAddr->TcpIpCtrlRef].ptrLocalUnicastAddr = ptrLocalAddr;
if( (Type == TCPIP_IPADDR_ASSIGNMENT_DHCP) || (Type == TCPIP_IPADDR_ASSIGNMENT_LINKLOCAL_DOIP) || (Type == TCPIP_IPADDR_ASSIGNMENT_LINKLOCAL) ){
if(Type == TCPIP_IPADDR_ASSIGNMENT_DHCP){
/* start dhcp search */
#if LWIP_DHCP
if(ERR_OK != dhcp_start(netif)){
result = E_NOT_OK;
}
#endif
}
if ((Type == TCPIP_IPADDR_ASSIGNMENT_LINKLOCAL_DOIP) || (Type == TCPIP_IPADDR_ASSIGNMENT_LINKLOCAL)){
if (LWIP_DHCP_AUTOIP_COOP == 0u){ /* dhcp_start will call autoip_start *//*lint !e774 !e506 use of macro */
/* start autoip configuration */
#if LWIP_AUTOIP
if(ERR_OK != autoip_start(netif)){
result = E_NOT_OK;
}
#endif
}
}
}
else if(Type == TCPIP_IPADDR_ASSIGNMENT_STATIC) {
/* Hardcoded addresses, just bring them up */
netif_set_up(netif);
}
else{
result = E_NOT_OK;
}
}else{
result = E_NOT_OK;
}
}
}
}
return result;
}
static Std_ReturnType TcpIp_AutomaticIpAddrAssignment(TcpIp_LocalAddrIdType LocalAddrId, TcpIp_IpAddrAssignmentType Type){
Std_ReturnType result = E_OK;
const TcpIp_LocalAddrType *ptrLocalAddr = &Config->Config.LocalAddrList[getLocalAddrListConfigIdx(LocalAddrId)];
struct netif *netif = &TcpIp_CtrlAdmin[ptrLocalAddr->TcpIpCtrlRef].tcpipNetif;
ip_addr_t ipaddr;
ip_addr_t netmask;
ip_addr_t gw;
ipaddr.addr = 0;
netmask.addr = 0;
gw.addr = 0;
if(Type == TCPIP_IPADDR_ASSIGNMENT_STATIC) {
if(TRUE == ptrLocalAddr->StaticIpAddrConfig->ArcValid){
ipaddr.addr = ptrLocalAddr->StaticIpAddrConfig->StaticIpAddress;
gw.addr = ptrLocalAddr->StaticIpAddrConfig->DefaultRouter;
IP4NetmaskToIpAddr(&netmask, ptrLocalAddr->StaticIpAddrConfig->Netmask);
}else{
result = E_NOT_OK;
}
}
if(result == E_OK){
if(ip_addr_ismulticast(&ipaddr)){/* Multicast address */ /*lint !e845 !e778 !e572 LWIP */
/* Join group here or in bind ? How will multicast be added ??? */
/** @req 4.2.2/SWS_TCPIP_00080 */
/* In case a multicast address is assigned, TcpIp shall derive
the related physical address from the multicast IP address and add the derived
address to the Eth MAC address filter by calling EthIf_UpdatePhys-
AddrFilter() with action set to ETH_ADD_TO_FILTER. */
result = TcpIp_ChangePhysAddrFilterForMulticast(ptrLocalAddr->TcpIpCtrlRef, ipaddr.addr, ETH_ADD_TO_FILTER);
}
else{ /* Unicast address */
if(TRUE == LwIP_AddNetIf(&ipaddr, &netmask, &gw, ethernetif_init, tcpip_input, netif)){ //IMPROVEMENT Assume there is only one unicast and netif per controller and hardcoded to one here... */
TcpIp_CtrlAdmin[ptrLocalAddr->TcpIpCtrlRef].ptrLocalUnicastAddr = ptrLocalAddr;
if( (Type == TCPIP_IPADDR_ASSIGNMENT_DHCP) || (Type == TCPIP_IPADDR_ASSIGNMENT_LINKLOCAL_DOIP) || (Type == TCPIP_IPADDR_ASSIGNMENT_LINKLOCAL) ){
if(Type == TCPIP_IPADDR_ASSIGNMENT_DHCP){
/* start dhcp search */
#if LWIP_DHCP
if(ERR_OK != dhcp_start(netif)){
result = E_NOT_OK;
}
#endif
}
if ((Type == TCPIP_IPADDR_ASSIGNMENT_LINKLOCAL_DOIP) || (Type == TCPIP_IPADDR_ASSIGNMENT_LINKLOCAL)){
if (LWIP_DHCP_AUTOIP_COOP == 0u){ /* dhcp_start will call autoip_start *//*lint !e774 !e506 use of macro */
/* start autoip configuration */
#if LWIP_AUTOIP
if(ERR_OK != autoip_start(netif)){
result = E_NOT_OK;
}
#endif
}
}
}
else if(Type == TCPIP_IPADDR_ASSIGNMENT_STATIC) {
/* Hardcoded addresses, just bring them up */
netif_set_up(netif);
}
else{
result = E_NOT_OK;
}
}else{
result = E_NOT_OK;
}
}
}
return result;
}
static Std_ReturnType TcpIp_RelIpAddrAssignment(TcpIp_LocalAddrIdType LocalAddrId){
Std_ReturnType result = E_OK;
const TcpIp_LocalAddrType *ptrLocalAddr = &Config->Config.LocalAddrList[getLocalAddrListConfigIdx(LocalAddrId)];
struct netif *netif = &TcpIp_CtrlAdmin[ptrLocalAddr->TcpIpCtrlRef].tcpipNetif;
TcpIp_IpAddrAssignmentType Type = ptrLocalAddr->AddressAssignment->AssignmentMethod;
ip_addr_t ipaddr;
// if(TRUE == ptrLocalAddr->StaticIpAddrConfig->ArcValid){
// ptrLocalAddr->StaticIpAddrConfig->ArcValid = FALSE;
ipaddr.addr = ptrLocalAddr->StaticIpAddrConfig->StaticIpAddress;
if(ip_addr_ismulticast(&ipaddr)){/* Multicast address *//*lint !e845 !e778 !e572 LWIP interface */
/* In case a multicast address is assigned, TcpIp shall derive
the related physical address from the multicast IP address and add the derived
address to the Eth MAC address filter by calling EthIf_UpdatePhys-
AddrFilter() with action set to ETH_REMOVE_FROM_FILTER. */
result = TcpIp_ChangePhysAddrFilterForMulticast(ptrLocalAddr->TcpIpCtrlRef, ipaddr.addr, ETH_REMOVE_FROM_FILTER);
}
else{ /* Unicast address */
if( (Type == TCPIP_IPADDR_ASSIGNMENT_DHCP) || (Type == TCPIP_IPADDR_ASSIGNMENT_LINKLOCAL_DOIP) || (Type == TCPIP_IPADDR_ASSIGNMENT_LINKLOCAL) ){
if(Type == TCPIP_IPADDR_ASSIGNMENT_DHCP){
/* stop dhcp search */
#if LWIP_DHCP
(void)dhcp_release(netif);
dhcp_stop(netif);
#endif
}
if ((Type == TCPIP_IPADDR_ASSIGNMENT_LINKLOCAL_DOIP) || (Type == TCPIP_IPADDR_ASSIGNMENT_LINKLOCAL)){
if (LWIP_DHCP_AUTOIP_COOP == 0u){ /* dhcp_start will call autoip_start *//*lint !e774 !e506 use of macro */
/* stop autoip configuration */
#if LWIP_AUTOIP
(void)autoip_stop(netif);
#endif
}
}
}else if (Type == TCPIP_IPADDR_ASSIGNMENT_STATIC) {
netif_remove(netif); /* netif will be made down before removal */
}else{
result = E_NOT_OK;
}
}
// }else{
// result = E_NOT_OK;
// }
return result;
}
/**
* @brief By this API service the local IP address assignment for the IP address specified by
* LocalAddrId shall be released.
* @param LocalAddrId - IP address index specifying the IP address for which an
* assignment shall be released.
* @return result of the function.
*/
/** @req 4.2.2/SWS_TCPIP_00078 */
/** @req 4.2.2/SWS_TCPIP_00117 */
Std_ReturnType TcpIp_ReleaseIpAddrAssignment(TcpIp_LocalAddrIdType LocalAddrId){
const TcpIp_LocalAddrType *ptrLocalAddr ;
Std_ReturnType result;
result = E_OK;
if(verifyLocalAddrId(LocalAddrId) != E_OK){
result = E_NOT_OK;
}
if (E_OK == result) {
ptrLocalAddr = &Config->Config.LocalAddrList[getLocalAddrListConfigIdx(LocalAddrId)];
/** @req 4.2.2/SWS_TCPIP_000199 */
if(TCPIP_AUTOMATIC == ptrLocalAddr->AddressAssignment->AssignmentTrigger){
result = E_NOT_OK;
}else{
result = TcpIp_RelIpAddrAssignment(LocalAddrId);
}
}
return result;
}
/**
* @brief Resets all learned IP-addresses to invalid values.
* @param void
* @return result of the function.
*/
/** !req 4.2.2/SWS_TCPIP_00215 */
Std_ReturnType TcpIp_ResetIpAssignment(void){
Std_ReturnType result = E_NOT_OK;
return result;
}
/**
* @brief By this API service the TCP/IP stack sends an ICMP message according to the
* specified parameters.
* @param LocalIpAddrId - IP address identifier representing the local IP address and EthIf
* controller which shall be used for transmission of the ICMP message.
* @param RemoteAddrPtr - pointer to struct representing the remote address
* @param Ttl - Time to live value to be used for the ICMP message. If 0 is
* specified the default value shall be used.
* @param Type - type field value to be used in the ICMP message
* @param Code - code field value to be used in the ICMP message
* @param DataLength - length of ICMP message
* @param DataPtr - Pointer to data which shall be sent as ICMP message data
* @return result of the function.
*/
/** !req 4.2.2/SWS_TCPIP_00039 */
Std_ReturnType TcpIp_IcmpTransmit(TcpIp_LocalAddrIdType LocalIpAddrId, const TcpIp_SockAddrType* RemoteAddrPtr,
uint8 Ttl, uint8 Type, uint8 Code, uint16 DataLength, const uint8* DataPtr){
Std_ReturnType result = E_NOT_OK;
/** !req 4.2.2/SWS_TCPIP_00118 */
return result;
}/*lint !e715 unused parameters */
/**
* @brief By this API service the TCP/IP stack sends an ICMPv6 message according to the
* specified parameters.
* @param LocalIpAddrId - IP address identifier representing the local IP address and EthIf
* controller which shall be used for transmission of the ICMPv6 message.
* @param RemoteAddrPtr - pointer to struct representing the remote address
* @param HopLimit - Hop Limit value to be used for the ICMPv6 message. If 0 is
* specified the default value shall be used.
* @param Type - type field value to be used in the ICMPv6 message
* @param Code - code field value to be used in the ICMPv6 message
* @param DataLength - length of ICMPv6 message
* @param DataPtr - Pointer to data which shall be sent as ICMPv6 message data
* @return result of the function.
*/
/** !req 4.2.2/SWS_TCPIP_00187 */
//Std_ReturnType TcpIp_IcmpV6Transmit(TcpIp_LocalAddrIdType LocalIpAddrId, const TcpIp_SockAddrType* RemoteAddrPtr,
// uint8 HopLimit, uint8 Type, uint8 Code, uint16 DataLength, const uint8* DataPtr){}
/**
* @brief By this API service the TCP/IP stack retrieves DHCP option data identified by
* parameter option for already received DHCP options.
* @param LocalIpAddrId - IP address identifier representing the local IP address and EthIf
* controller for which the DHCP option shall be read.
* @param Option - DHCP option according to IEFT RfC 2132, e.g. hostname
* @param DataLength - As input parameter, contains the length of the provided data
* buffer. Will be overwritten with the length of the actual data.
* @param DataPtr - Pointer to memory containing DHCP option data
* @return result of the function.
*/
/** !req 4.2.2/SWS_TCPIP_00040 */
Std_ReturnType TcpIp_DhcpReadOption(TcpIp_LocalAddrIdType LocalIpAddrId, uint8 Option, uint8* DataLength, uint8* DataPtr){
Std_ReturnType result = E_NOT_OK;
/** !req 4.2.2/SWS_TCPIP_00233 */
/** !req 4.2.2/SWS_TCPIP_00234 */
/** !req 4.2.2/SWS_TCPIP_00235 */
/** !req 4.2.2/SWS_TCPIP_00236 */
/** !req 4.2.2/SWS_TCPIP_00237 */
return result;
}/*lint !e715 unused parameters */ /*lint !e818 ASR spec */
/**
* @brief By this API service the TCP/IP stack retrieves DHCPv6 option data identified by
* parameter option for already received DHCPv6 options.
* @param LocalIpAddrId - IP address identifier representing the local IP address and EthIf
* controller for which the DHCPv6 option shall be read.
* @param Option - DHCP option according to IEFT RfC 3315, e.g. hostname
* @param DataLength - As input parameter, contains the length of the provided data
* buffer. Will be overwritten with the length of the actual data.
* @param DataPtr - Pointer to memory containing DHCPv6 option data
* @return result of the function.
*/
/** !req 4.2.2/SWS_TCPIP_00189 */
Std_ReturnType TcpIp_DhcpV6ReadOption(TcpIp_LocalAddrIdType LocalIpAddrId, uint16 Option, uint16* DataLength, uint8* DataPtr){
Std_ReturnType result = E_NOT_OK;
/** !req 4.2.2/SWS_TCPIP_00238 */
/** !req 4.2.2/SWS_TCPIP_00239 */
/** !req 4.2.2/SWS_TCPIP_00240 */
/** !req 4.2.2/SWS_TCPIP_00241 */
/** !req 4.2.2/SWS_TCPIP_00242 */
return result;
}/*lint !e715 unused parameters */ /*lint !e818 ASR spec */
/**
* @brief By this API service the TCP/IP stack writes the DHCP option data identified by
parameter option
* @param LocalIpAddrId - IP address identifier representing the local IP address and EthIf
* controller for which the DHCP option shall be written.
* @param Option - DHCP option according to IEFT RfC 2132, e.g. hostname
* @param DataLength - Length of DHCP option data
* @param DataPtr - Pointer to memory containing DHCP option data
* @return result of the function.
*/
/** !req 4.2.2/SWS_TCPIP_00020 */
Std_ReturnType TcpIp_DhcpWriteOption(TcpIp_LocalAddrIdType LocalIpAddrId, uint8 Option, uint8 DataLength, const uint8* DataPtr){
Std_ReturnType result = E_NOT_OK;
/** !req 4.2.2/SWS_TCPIP_00243 */
/** !req 4.2.2/SWS_TCPIP_00244 */
/** !req 4.2.2/SWS_TCPIP_00245 */
/** !req 4.2.2/SWS_TCPIP_00246 */
/** !req 4.2.2/SWS_TCPIP_00247 */
return result;
}/*lint !e715 unused parameters */
/**
* @brief By this API service the TCP/IP stack writes the DHCPv6 option data identified by
* parameter option.
* @param LocalIpAddrId - IP address identifier representing the local IP address and EthIf
* controller for which the DHCPv6 option shall be written.
* @param Option - DHCP option according to IEFT RfC 3315, e.g. hostname
* @param DataLength - length of DHCPv6 option data.
* @param DataPtr - Pointer to memory containing DHCPv6 option data
* @return result of the function.
*/
/** !req 4.2.2/SWS_TCPIP_00190 */
Std_ReturnType TcpIp_DhcpV6WriteOption(TcpIp_LocalAddrIdType LocalIpAddrId,uint16 Option,uint16 DataLength,const uint8* DataPtr){
Std_ReturnType result = E_NOT_OK;
/** !req 4.2.2/SWS_TCPIP_00248 */
/** !req 4.2.2/SWS_TCPIP_00249 */
/** !req 4.2.2/SWS_TCPIP_00250 */
/** !req 4.2.2/SWS_TCPIP_00251 */
/** !req 4.2.2/SWS_TCPIP_00252 */
return result;
}/*lint !e715 unused parameters */
/**
* @brief By this API service the TCP/IP stack is requested to change a parameter of a socket.
* @param SocketId - Socket handle identifying the local socket resource
* @param ParameterId - Identifier of the parameter to be changed
* @param ParameterValue - Pointer to memory containing the new parameter value.
* @return result of the function.
*/
/** @req 4.2.2/SWS_TCPIP_00016 */
Std_ReturnType TcpIp_ChangeParameter(TcpIp_SocketIdType SocketId, TcpIp_ParamIdType ParameterId, const uint8* ParameterValue){
Std_ReturnType result = E_OK;
/** !req 4.2.2/SWS_TCPIP_00119 */ /* Partial support */
switch (ParameterId)
{
case TCPIP_PARAMID_TCP_RXWND_MAX:
break;
case TCPIP_PARAMID_FRAMEPRIO:
break;
case TCPIP_PARAMID_TCP_NAGLE:
{
sint32 on = 1;
sint32 status;
status = ioctlsocket(TcpIp_SocketAdmin[SocketId].socketHandle, FIONBIO, &on);/*lint !e569 !e970 !e9053 LWIP */
status |= setsockopt(TcpIp_SocketAdmin[SocketId].socketHandle, IPPROTO_TCP, TCP_NODELAY, &on, sizeof(sint32)); // Set socket to no delay
if(status != (err_t)ERR_OK){
result = E_NOT_OK;
}
}
break;
case TCPIP_PARAMID_TCP_KEEPALIVE:
break;
case TCPIP_PARAMID_TTL:
break;
case TCPIP_PARAMID_TCP_KEEPALIVE_TIME:
break;
case TCPIP_PARAMID_TCP_KEEPALIVE_PROBES_MAX:
break;
case TCPIP_PARAMID_TCP_KEEPALIVE_INTERVAL:
break;
case TCPIP_PARAMID_VENDOR_SPECIFIC:
break;
default:
break;
}
return result;
}/*lint !e715 ParamterValue is currently unused */
/**
* @brief Obtains the local IP address actually used by LocalAddrId, the netmask and default router
* @param LocalAddrId - Local address identifier referring to the local IP address which
* shall be obtained.
* @param IpAddrPtr - Pointer to a struct where the IP address shall be stored.
* @param NetmaskPtr - Pointer to memory where Network mask of IPv4 address or
* address prefix of IPv6 address in CIDR Notation is stored
* @param DefaultRouterPtr - Pointer to struct where the IP address of the default router
* (gateway) is stored (struct member "port" is not used and of
* arbitrary value).
* @return result of the function.
*/
/** @req 4.2.2/SWS_TCPIP_00032 */
Std_ReturnType TcpIp_GetIpAddr(TcpIp_LocalAddrIdType LocalAddrId, TcpIp_SockAddrType* IpAddrPtr,
uint8* NetmaskPtr, TcpIp_SockAddrType* DefaultRouterPtr){
const TcpIp_LocalAddrType *ptrLocalAddr;
Std_ReturnType result;
result = E_OK;
if(verifyLocalAddrId(LocalAddrId) != E_OK){
result = E_NOT_OK;
}
if (E_OK == result) {
ptrLocalAddr = &Config->Config.LocalAddrList[getLocalAddrListConfigIdx(LocalAddrId)];
/** @req 4.2.2/SWS_TCPIP_00205 */
VALIDATE(IpAddrPtr->domain == ptrLocalAddr->Domain, TCPIP_GETIPADDR_SERVICE_ID, TCPIP_E_INV_ARG);
/** @req 4.2.2/SWS_TCPIP_00206 */
VALIDATE(DefaultRouterPtr->domain == IpAddrPtr->domain, TCPIP_GETIPADDR_SERVICE_ID, TCPIP_E_INV_ARG);
TcpIp_IpAddr32To8(ptrLocalAddr->StaticIpAddrConfig->StaticIpAddress, IpAddrPtr->addr);
TcpIp_IpAddr32To8(ptrLocalAddr->StaticIpAddrConfig->DefaultRouter, DefaultRouterPtr->addr);
*NetmaskPtr = ptrLocalAddr->StaticIpAddrConfig->Netmask;
}
return result;
}
/**
* @brief Obtains the physical source address used by the EthIf controller implicitly
* specified via LocalAddrId.
* @param LocalAddrId - Local address identifier referring to the local IP address which
* shall be obtained.
* @param PhysAddrPtr - Pointer to the memory where the physical source address (MAC
* address) in network byte order is stored
* @return result of the function.
*/
/** @req 4.2.2/SWS_TCPIP_00033 */
Std_ReturnType TcpIp_GetPhysAddr(TcpIp_LocalAddrIdType LocalAddrId, uint8* PhysAddrPtr){
Std_ReturnType result;
result = verifyLocalAddrId(LocalAddrId);
if(result == E_OK){
const TcpIp_LocalAddrType *ptrLocalAddr = &Config->Config.LocalAddrList[getLocalAddrListConfigIdx(LocalAddrId)];
EthIf_GetPhysAddr(ptrLocalAddr->TcpIpCtrlRef, PhysAddrPtr);
}
return result;
}
/**
* @brief TcpIp_GetRemotePhysAddr queries the IP/physical address translation table
* specified by CtrlIdx and returns the physical address related to the IP address
* specified by IpAddrPtr. In case no physical address can be retrieved and
* parameter initRes is TRUE, address resolution for the specified IP address is
* initiated on the local network.
* @param CtrlIdx - EthIf controller index to identify the related ARP/NDP table.
* @param IpAddrPtr - specifies the IP address for which the physical address shall be retrieved
* @param PhysAddrPtr - Pointer to the memory where the physical address (MAC
* address) related to the specified IP address is stored in
* network byte order.
* @param initRes - specifies if the address resolution shall be initiated (TRUE) or
* not (FALSE) in case the physical address related to the
* specified IP address is currently unknown.
* @return result of the function.
*/
/** @req 4.2.2/SWS_TCPIP_00137 */
TcpIp_ReturnType TcpIp_GetRemotePhysAddr(uint8 CtrlIdx, const TcpIp_SockAddrType* IpAddrPtr, uint8* PhysAddrPtr,
boolean initRes){
TcpIp_ReturnType result = TCPIP_OK;
struct eth_addr* ethaddr_ret;
const ip_addr_t* ipaddr_ret;
ip_addr_t ip;
struct netif *netif;
TcpIp_IpAddr8to32(IpAddrPtr->addr, &ip.addr);
netif = &TcpIp_CtrlAdmin[CtrlIdx].tcpipNetif;
/** !req 4.2.2/SWS_TCPIP_00139 */
/** @req 4.2.2/SWS_TCPIP_00138 */
if (etharp_find_addr(netif, &ip, ðaddr_ret, &ipaddr_ret) > -1)
{
/* If the physical address is already known, PhysAddrPtr shall be set to the related
physical address and the function shall return with TCPIP_E_OK */
memcpy(PhysAddrPtr,ethaddr_ret->addr, ETHARP_HWADDR_LEN);
}
else{
/* Otherwise it shall (a) initiate an address resolution if parameter initRes is set to
TRUE and (b) return with TCPIP_E_PHYS_ADDR_MISS. PhysAddrPtr is not updated in this case. */
result = TCPIP_E_PHYS_ADDR_MISS;
if(TRUE == initRes){
/* Initate address resolution */
if((err_t)ERR_OK != etharp_query(netif, &ip, NULL)){
TCPIP_DET_REPORTERROR(TCPIP_GETREMOTEPHYSADDR_SERVICE_ID, TCPIP_E_ARC_GENERAL_FAILURE_TCPIP_STACK);
}
}
}
return result;
}
/**
* @brief TcpIp_GetCtrlIdx returns the index of the controller related to LocalAddrId.
* @param LocalAddrId - Local address identifier referring to the local IP address which
* shall be obtained.
* @param CtrlIdxPtr - Pointer to the memory where the index of the controller related to
* LocalAddrId is stored
* @return result of the function.
*/
/** @req 4.2.2/SWS_TCPIP_00140 */
Std_ReturnType TcpIp_GetCtrlIdx(TcpIp_LocalAddrIdType LocalAddrId, uint8* CtrlIdxPtr){
Std_ReturnType result;
/** @req 4.2.2/SWS_TCPIP_00141 */
result = verifyLocalAddrId(LocalAddrId);
if(result == E_OK){
const TcpIp_LocalAddrType *ptrLocalAddr = &Config->Config.LocalAddrList[getLocalAddrListConfigIdx(LocalAddrId)];
*CtrlIdxPtr = ptrLocalAddr->TcpIpCtrlRef;
}
return result;
}
/**
* @brief This service transmits data via UDP to a remote node. The transmission of the
* data is immediately performed with this function call by forwarding it to EthIf.
* @param SocketId - Socket handle identifying the local socket resource
* @param DataPtr - Pointer to a linear buffer of TotalLength bytes containing the
* data to be transmitted.
* In case DataPtr is a NULL_PTR, TcpIp shall retrieve data from
* upper layer via callback <Up>_CopyTxData().
* @param RemoteAddrPtr - IP address and port of the remote host to transmit to.
* @param TotalLength - indicates the payload size of the UDP datagram.
* @return result of the function.
*/
/** @req 4.2.2/SWS_TCPIP_00025 */
/** @req 4.2.2/SWS_TCPIP_00225 */
Std_ReturnType TcpIp_UdpTransmit(TcpIp_SocketIdType SocketId, const uint8* DataPtr, const TcpIp_SockAddrType* RemoteAddrPtr, uint16 TotalLength){
Std_ReturnType result = E_OK;
BufReq_ReturnType bufRes;
uint8* bufPtr;
uint8 ctrlIdx;
uint16 len = TotalLength;
uint8 physAddr[TCPIP_ETH_MAC_ADDR_SIZE];
uint16 bytesSent;
#if defined(TCPIP_TX_BUF_SINGLE_COPY)
uint32 baseAddress;
Eth_BufIdxType bufIdx;
uint8 priority = 0;
Eth_FrameType frameType = TCPIP_FRAME_TYPE_IPV4;
uint8 destMacAdrs[TCPIP_ETH_MAC_ADDR_SIZE];
#endif
/* Added some protection even though not specified */
VALIDATE( (SocketId < TCPIP_MAX_NOF_SOCKETS), TCPIP_UDPTRANSMIT_SERVICE_ID, TCPIP_E_INV_ARG)
VALIDATE( (TcpIp_SocketAdmin[SocketId].socketHandle >= 0), TCPIP_UDPTRANSMIT_SERVICE_ID, TCPIP_E_NOTCONN)
VALIDATE( (TcpIp_SocketAdmin[SocketId].socketState == TCPIP_SOCKET_UDP_READY), TCPIP_UDPTRANSMIT_SERVICE_ID, TCPIP_E_ARC_ILLEGAL_STATE);
ctrlIdx = TcpIp_SocketAdmin[SocketId].ptrLocalAddr->TcpIpCtrlRef;
/** @req 4.2.2/SWS_TCPIP_00074 */
VALIDATE( (TcpIp_CtrlAdmin[ctrlIdx].tcpipEthIfCtrlState == TCPIP_STATE_ONLINE), TCPIP_UDPTRANSMIT_SERVICE_ID, TCPIP_E_ARC_ILLEGAL_STATE);
/** !req 4.2.2/SWS_TCPIP_00122 */
/*
if(TcpIp_SocketAdmin[SocketId].socketState == TCPIP_SOCKET_BIND){ */
/* IMPROVEMENT Do we need to do anything here???
* Not been bind to an address, use local ip address and port */
/* } */
/** @req 4.2.2/SWS_TCPIP_00120 */
EthIf_GetPhysAddr(ctrlIdx,physAddr);
#if defined(TCPIP_TX_BUF_SINGLE_COPY)
bufRes = EthIf_ProvideTxBuffer(ctrlIdx,frameType,priority,&bufIdx,(Eth_DataType **) &baseAddress, &len);
if(bufRes == BUFREQ_OK){
bufPtr = (uint8*)(baseAddress);
}
#else
bufRes = BUFREQ_NOT_OK;
if(TRUE == TcpIp_BufferGet(len,&bufPtr)){
bufRes = BUFREQ_OK;
}
#endif
/** @req 4.2.2/SWS_TCPIP_00121 */
if(bufRes == BUFREQ_OK){
if(DataPtr == NULL){
/* Copy data callback to upper layer */
if(Config->Config.SocketOwnerConfig.SocketOwnerList[TcpIp_SocketAdmin[SocketId].socketOwnerId].SocketOwnerCopyTxDataFncPtr != NULL){
if(BUFREQ_OK != Config->Config.SocketOwnerConfig.SocketOwnerList[TcpIp_SocketAdmin[SocketId].socketOwnerId].SocketOwnerCopyTxDataFncPtr(SocketId, bufPtr, len)){ /* no Tp Handling */
TCPIP_DET_REPORTERROR(TCPIP_UDPTRANSMIT_SERVICE_ID, TCPIP_E_ARC_GENERAL_FAILURE_TCPIP);
}
}
}else{
memcpy(bufPtr,DataPtr,len);
}
#if defined(TCPIP_TX_BUF_SINGLE_COPY)
/* Find out how to grab destination MAC address */
/* Add padding bytes if any before dispatch to OSI layer 2 */
/** !req 4.2.2/SWS_TCPIP_00131 */
result = EthIf_Transmit(ctrlIdx,bufIdx,frameType,TRUE/*txconf*/,len,destMacAdrs);
/* SocketIdInTransfer = SocketId; */
#else
bytesSent = TcpIp_SendIpMessage(TcpIp_SocketAdmin[SocketId].socketHandle, bufPtr, RemoteAddrPtr, TotalLength);
TcpIp_BufferFree(bufPtr);
if(bytesSent == 0){
result = E_NOT_OK;
}
#endif
if(Config->Config.SocketOwnerConfig.SocketOwnerList[TcpIp_SocketAdmin[SocketId].socketOwnerId].SocketOwnerTxConfirmationFncPtr != NULL){
Config->Config.SocketOwnerConfig.SocketOwnerList[TcpIp_SocketAdmin[SocketId].socketOwnerId].SocketOwnerTxConfirmationFncPtr(SocketId,bytesSent);
}
}else{
result = E_NOT_OK;
}
return result;
}
/**
* @brief This service requests transmission of data via TCP to a remote node. The
* transmission of the data is decoupled.
* @param SocketId - Socket handle identifying the local socket resource
* @param DataPtr - Pointer to a linear buffer of TotalLength bytes containing the
* data to be transmitted.
* In case DataPtr is a NULL_PTR, TcpIp shall retrieve data from
* upper layer via callback <Up>_CopyTxData().
* @param AvailableLength - Available data for transmission in bytes.
* @param ForceRetrieve - This parameter is only valid if DataPtr is a NULL_PTR.
* Indicates how the TCP/IP stack retrieves data from upper layer if
* DataPtr is a NULL_PTR.
* TRUE: the whole data indicated by availableLength shall be
* retrieved from the upper layer via one or multiple
* <Up>_CopyTxData() calls within the context of this transmit
* function.
* FALSE: The TCP/IP stack may retrieve up to availableLength
* data from the upper layer. It is allowed to retrieve less than
* availableLength bytes. Note: Not retrieved data will be provided
* by upper layer with the next call to TcpIp_TcpTransmit (along with
* new data if available).
* @return result of the function.
*/
/** @req 4.2.2/SWS_TCPIP_00050 */
/** @req 4.2.2/SWS_TCPIP_00123 */
/** @req 4.2.2/SWS_TCPIP_00124 */
/** !req 4.2.2/SWS_TCPIP_00125 */
Std_ReturnType TcpIp_TcpTransmit(TcpIp_SocketIdType SocketId, const uint8* DataPtr, uint32 AvailableLength,
boolean ForceRetrieve){
Std_ReturnType result = E_OK;
BufReq_ReturnType bufRes;
uint8* bufPtr;
uint8 ctrlIdx;
uint16 len = AvailableLength;
uint8 physAddr[TCPIP_ETH_MAC_ADDR_SIZE];
uint16 bytesSent;
(void)ForceRetrieve;
#if defined(TCPIP_TX_BUF_SINGLE_COPY)
uint32 baseAddress;
uint8 priority = 0;
Eth_FrameType frameType = TCPIP_FRAME_TYPE_IPV4;
Eth_BufIdxType bufIdx;
uint8 destMacAdrs[TCPIP_ETH_MAC_ADDR_SIZE];
#endif
/* Added some protection even though not specified */
VALIDATE( (SocketId < TCPIP_MAX_NOF_SOCKETS), TCPIP_TCPTRANSMIT_SERVICE_ID, TCPIP_E_INV_ARG)
VALIDATE( (TcpIp_SocketAdmin[SocketId].socketHandle >= 0), TCPIP_TCPTRANSMIT_SERVICE_ID, TCPIP_E_NOTCONN)
ctrlIdx = TcpIp_SocketAdmin[SocketId].ptrLocalAddr->TcpIpCtrlRef;
/** @req 4.2.2/SWS_TCPIP_00074 */
VALIDATE( (TcpIp_CtrlAdmin[ctrlIdx].tcpipEthIfCtrlState == TCPIP_STATE_ONLINE), TCPIP_TCPTRANSMIT_SERVICE_ID, TCPIP_E_ARC_ILLEGAL_STATE);
/** @req 4.2.2/SWS_TCPIP_00120 */
EthIf_GetPhysAddr(ctrlIdx,physAddr);
#if defined(TCPIP_TX_BUF_SINGLE_COPY)
bufRes = EthIf_ProvideTxBuffer(ctrlIdx,frameType,priority,&bufIdx,(Eth_DataType **) &baseAddress, &len);
if(bufRes == BUFREQ_OK){
bufPtr = (uint8*)(baseAddress);
}
#else
bufRes = BUFREQ_NOT_OK;
if(TcpIp_BufferGet(len,&bufPtr) == TRUE){
bufRes = BUFREQ_OK;
}
#endif
/** @req 4.2.2/SWS_TCPIP_00121 */
/** @req 4.2.2/SWS_TCPIP_00228 */
if(bufRes == BUFREQ_OK){
if(DataPtr == NULL){
/* Copy data callback to upper layer */
if(Config->Config.SocketOwnerConfig.SocketOwnerList[TcpIp_SocketAdmin[SocketId].socketOwnerId].SocketOwnerCopyTxDataFncPtr != NULL){
if(BUFREQ_OK != Config->Config.SocketOwnerConfig.SocketOwnerList[TcpIp_SocketAdmin[SocketId].socketOwnerId].SocketOwnerCopyTxDataFncPtr(SocketId, bufPtr, len)){/* no Tp Handling */
TCPIP_DET_REPORTERROR(TCPIP_TCPTRANSMIT_SERVICE_ID, TCPIP_E_ARC_GENERAL_FAILURE_TCPIP);
}
}
}else{
memcpy(bufPtr,DataPtr,len);
}
#if defined(TCPIP_TX_BUF_SINGLE_COPY)
/* Find out how to grab destination MAC address */
/* Add padding bytes if any before dispatch to OSI layer 2 */
/** !req 4.2.2/SWS_TCPIP_00131 */
result = EthIf_Transmit(ctrlIdx,bufIdx,frameType,TRUE/*txconf*/,len,destMacAdrs);
#else
/* SocketIdInTransfer = SocketId; */
bytesSent = TcpIp_SendIpMessage(TcpIp_SocketAdmin[SocketId].socketHandle, bufPtr, NULL, AvailableLength);
TcpIp_BufferFree(bufPtr);
if(bytesSent == 0){
result = E_NOT_OK;
}
#endif
if(Config->Config.SocketOwnerConfig.SocketOwnerList[TcpIp_SocketAdmin[SocketId].socketOwnerId].SocketOwnerTxConfirmationFncPtr != NULL){
Config->Config.SocketOwnerConfig.SocketOwnerList[TcpIp_SocketAdmin[SocketId].socketOwnerId].SocketOwnerTxConfirmationFncPtr(SocketId,bytesSent);
}
}else{
result = E_NOT_OK;
}
return result;
}
/**
* @brief By this API service the TCP/IP stack gets an indication and the data of a received frame.
* @param CtrlIdx - Index of the EthIf controller.
* @param FrameType - Frame type of received Ethernet frame
* @param IsBroadcast - Parameter to indicate a broadcast frame
* @param PhysAddrPtr - Pointer to Physical source address (MAC address in network byte
* order) of received Ethernet frame
* @param DataPtr - Pointer to payload of the received Ethernet frame (i.e. Ethernet
* header is not provided).
* @param LenByte - Length of received data.
* @return void
*/
/** @req 4.2.2/SWS_TCPIP_00029 */
void TcpIp_RxIndication(uint8 CtrlIdx, Eth_FrameType FrameType, boolean IsBroadcast, const uint8* PhysAddrPtr,
uint8* DataPtr, uint16 LenByte){
if(tcpip_initialized == TRUE)
{
#if !defined(USE_NO_ETHIF)
LwIp_RxIndication(CtrlIdx,FrameType,IsBroadcast,PhysAddrPtr,DataPtr,LenByte);
#endif
}
}/*lint !e818 ASR specification */
static void TcpIp_NotifyLocalIpAddrAssignmentChg(uint8 CtrlIdx, TcpIp_IpAddrStateType ipAddrState)
{
/* Call upper layer */
const TcpIp_LocalAddrType *ptrLocalAddr;
for(uint32 LocalAddrId=0; LocalAddrId < TCPIP_NOF_LOCALADDR; LocalAddrId++){
ptrLocalAddr = &Config->Config.LocalAddrList[getLocalAddrListConfigIdx(LocalAddrId)];
if(ptrLocalAddr->TcpIpCtrlRef == CtrlIdx)
{
for(uint32 Idx=0; Idx < TCPIP_NOF_SOCKETOWNERS; Idx++){
if(Config->Config.SocketOwnerConfig.SocketOwnerList[Idx].SocketOwnerLocalIpAddrAssignmentChgFncPtr != NULL){
Config->Config.SocketOwnerConfig.SocketOwnerList[Idx].SocketOwnerLocalIpAddrAssignmentChgFncPtr(ptrLocalAddr->AddressId, ipAddrState);
}
}
}
}
}
static void TcpIp_EnableAllIpAddrAssignments(uint8 CtrlIdx){
const TcpIp_LocalAddrType *ptrLocalAddr;
/* We initiate all unicast first and then any multicast. We assume there is only one */
for(uint32 i=0; i<TCPIP_NOF_LOCALADDR;i++){
ptrLocalAddr = &Config->Config.LocalAddrList[i];
if((ptrLocalAddr->TcpIpCtrlRef == CtrlIdx) && (ptrLocalAddr->AddressAssignment->AssignmentTrigger == TCPIP_AUTOMATIC) && (ptrLocalAddr->AddressType == TCPIP_UNICAST)){
if(E_NOT_OK == TcpIp_AutomaticIpAddrAssignment(ptrLocalAddr->AddressId, ptrLocalAddr->AddressAssignment->AssignmentMethod)){
TCPIP_DET_REPORTERROR(TCPIP_MAINFUNCTION_SERVICE_ID, TCPIP_E_ARC_ILLEGAL_STATE);
}
}
}
for(uint32 i=0; i<TCPIP_NOF_LOCALADDR;i++){
ptrLocalAddr = &Config->Config.LocalAddrList[i];
if((ptrLocalAddr->TcpIpCtrlRef == CtrlIdx) && (ptrLocalAddr->AddressAssignment->AssignmentTrigger == TCPIP_AUTOMATIC) && (ptrLocalAddr->AddressType == TCPIP_MULTICAST)){
if(E_NOT_OK == TcpIp_AutomaticIpAddrAssignment(ptrLocalAddr->AddressId, ptrLocalAddr->AddressAssignment->AssignmentMethod)){
TCPIP_DET_REPORTERROR(TCPIP_MAINFUNCTION_SERVICE_ID, TCPIP_E_ARC_ILLEGAL_STATE);
}
}
}
}
static void TcpIp_DisableAllIpAddrAssignments(uint8 CtrlIdx){
const TcpIp_LocalAddrType *ptrLocalAddr;
/* We initiate all unicast first and then any multicast. We assume there is only one */
for(uint32 i=0; i<TCPIP_NOF_LOCALADDR;i++){
ptrLocalAddr = &Config->Config.LocalAddrList[i];
if((ptrLocalAddr->TcpIpCtrlRef == CtrlIdx) && (ptrLocalAddr->AddressAssignment->AssignmentTrigger == TCPIP_AUTOMATIC) && (ptrLocalAddr->AddressType == TCPIP_UNICAST)){
if(E_NOT_OK == TcpIp_RelIpAddrAssignment(ptrLocalAddr->AddressId)){
TCPIP_DET_REPORTERROR(TCPIP_MAINFUNCTION_SERVICE_ID, TCPIP_E_ARC_ILLEGAL_STATE);
}
}
}
for(uint32 i=0; i<TCPIP_NOF_LOCALADDR;i++){
ptrLocalAddr = &Config->Config.LocalAddrList[i];
if((ptrLocalAddr->TcpIpCtrlRef == CtrlIdx) && (ptrLocalAddr->AddressAssignment->AssignmentTrigger == TCPIP_AUTOMATIC) && (ptrLocalAddr->AddressType == TCPIP_MULTICAST)){
if(E_NOT_OK == TcpIp_RelIpAddrAssignment(ptrLocalAddr->AddressId)){
TCPIP_DET_REPORTERROR(TCPIP_MAINFUNCTION_SERVICE_ID, TCPIP_E_ARC_ILLEGAL_STATE);
}
}
}
}
static void TcpIp_HandleStateOffline(uint8 CtrlIdx)
{
if(TcpIp_CtrlAdmin[CtrlIdx].tcpipEthIfRequestedCtrlState == TCPIP_STATE_ONLINE){
/** @req 4.2.2/SWS_TCPIP_00075 */
/* If TCPIP_STATE_ONLINE is requested for an EthIf
controller and the current state is TCPIP_STATE_OFFLINE for that EthIf controller,
the TcpIp module shall
(a) enable all IP address assignments according to the configured assignment
methods (TcpIpAssignmentMethod) and triggers (TcpIpAssignmentTrigger) for
that EthIf controller. (Note: If the assignment trigger is configured to
TCPIP_MANUAL no assignment is actually performed but initiation by the upper
layer enabled) and */
TcpIp_EnableAllIpAddrAssignments(CtrlIdx);
/* (b) enter the state TCPIP_STATE_STARTUP for the EthIf controller.⌋ */
TcpIp_SwitchEthIfCtrlState(CtrlIdx, TCPIP_STATE_STARTUP);
}
else if(TcpIp_CtrlAdmin[CtrlIdx].tcpipEthIfRequestedCtrlState == TCPIP_STATE_ONHOLD){
/* Invalid statechange, report error and reset request */
TCPIP_DET_REPORTERROR(TCPIP_MAINFUNCTION_SERVICE_ID, TCPIP_E_ARC_ILLEGAL_STATE);
TcpIp_CtrlAdmin[CtrlIdx].tcpipEthIfRequestedCtrlState = TCPIP_STATE_OFFLINE;
}
else{
/* Do nothing */
}
}
/** @req 4.2.2/SWS_TCPIP_00229 */
static void TcpIp_EnterOfflineState(uint8 CtrlIdx){
/** @req 4.2.2/SWS_TCPIP_00077 */
/* If TCPIP_STATE_OFFLINE is requested or all assigned IP
address have been released for an EthIf controller and the current state is
TCPIP_STATE_ONLINE or TCPIP_STATE_ONHOLD for that EthIf controller, the
TcpIp module shall */
/* (a) call Up_LocalIpAddrAssignmentChg() with State
TCPIP_IPADDR_STATE_UNASSIGNED for all assigned IP addresses of the
related EthIf controller, */
TcpIp_NotifyLocalIpAddrAssignmentChg(CtrlIdx, TCPIP_IPADDR_STATE_UNASSIGNED);
/* (b) deactivate the communication within the TcpIp module for the related EthIf
controller, */
/* (c) release related resources, i.e. any socket using the EthIf controller shall be
closed and thereafter any IP address assigned to the EthIf controller shall be
unassigned,*/
for(uint32 SocketId=0; SocketId < TCPIP_MAX_NOF_SOCKETS; SocketId++){
if((TcpIp_SocketAdmin[SocketId].ptrLocalAddr != NULL) && (TcpIp_SocketAdmin[SocketId].ptrLocalAddr->TcpIpCtrlRef == CtrlIdx))
{
(void)TcpIp_Close(SocketId,FALSE);
}
}
/* (d) in case the no EthIf controller is assigned any more, all unbound sockets shall
be released as well */
boolean otherCtrls = FALSE;
for(uint32 SocketId=0; SocketId < TCPIP_MAX_NOF_SOCKETS; SocketId++){
if(TcpIp_SocketAdmin[SocketId].ptrLocalAddr != NULL){
/* There are sockets assigned to other ctrl's */
otherCtrls = TRUE;
break;
}
}
if(otherCtrls == FALSE){
/* There are no other assigned controllers, release all unbound sockets */
for(uint32 SocketId=0; SocketId < TCPIP_MAX_NOF_SOCKETS; SocketId++){
if(TcpIp_SocketAdmin[SocketId].socketHandle >= 0){
(void)TcpIp_Close(SocketId,FALSE);
}
}
}
TcpIp_DisableAllIpAddrAssignments(CtrlIdx);
/* (e) enter the state TCPIP_STATE_SHUTDOWN for the EthIf controller. */
TcpIp_SwitchEthIfCtrlState(CtrlIdx, TCPIP_STATE_SHUTDOWN);
}
static void TcpIp_HandleStateOnline(uint8 CtrlIdx)
{
if(TcpIp_CtrlAdmin[CtrlIdx].tcpipEthIfRequestedCtrlState == TCPIP_STATE_OFFLINE){
TcpIp_EnterOfflineState(CtrlIdx);
}
else if(TcpIp_CtrlAdmin[CtrlIdx].tcpipEthIfRequestedCtrlState == TCPIP_STATE_ONHOLD){
/** @req 4.2.2/SWS_TCPIP_00076 */
/* If TCPIP_STATE_ONHOLD is requested for an EthIf
controller and the current state is TCPIP_STATE_ONLINE for that EthIf controller,
the TcpIp module shall
(a) notify the upper layer via Up_LocalIpAddrAssignmentChg() with State
TCPIP_IPADDR_STATE_ONHOLD for all assigned IP addresses of the
related EthIf controller, and */
netif_set_down(&TcpIp_CtrlAdmin[CtrlIdx].tcpipNetif);
/* (b) deactivate the communication within the TcpIp module for the related EthIf
controller, and */
TcpIp_NotifyLocalIpAddrAssignmentChg(CtrlIdx, TCPIP_IPADDR_STATE_ONHOLD);
/* (c) enter the state TCPIP_STATE_ONHOLD for the EthIf controller.*/
TcpIp_SwitchEthIfCtrlState(CtrlIdx, TCPIP_STATE_ONHOLD);
}
else{
/* Do nothing */
}
}
static void TcpIp_HandleStateOnhold(uint8 CtrlIdx)
{
if(TcpIp_CtrlAdmin[CtrlIdx].tcpipEthIfRequestedCtrlState == TCPIP_STATE_OFFLINE){
/** @req 4.2.2/SWS_TCPIP_00077 */
TcpIp_EnterOfflineState(CtrlIdx);
}
else if(TcpIp_CtrlAdmin[CtrlIdx].tcpipEthIfRequestedCtrlState == TCPIP_STATE_ONLINE){
/** @req 4.2.2/SWS_TCPIP_00086 */
/* If TCPIP_STATE_ONLINE is requested for an EthIf
controller and the current state is TCPIP_STATE_ONHOLD for that EthIf controller,
the TcpIp module shall
(a) reactivate the communication within the TcpIp module for the related EthIf
controller, */
netif_set_up(&TcpIp_CtrlAdmin[CtrlIdx].tcpipNetif);
/* (b) call Up_LocalIpAddrAssignmentChg() with State
TCPIP_IPADDR_STATE_ASSIGNED for all assigned IP addresses of the
related EthIf controller, and */
TcpIp_NotifyLocalIpAddrAssignmentChg(CtrlIdx, TCPIP_IPADDR_STATE_ASSIGNED);
/* (c) enter the state TCPIP_STATE_ONLINE for the EthIf controller. */
TcpIp_SwitchEthIfCtrlState(CtrlIdx, TCPIP_STATE_ONLINE);
}
else{
/* Do nothing */
}
}
static void TcpIp_HandleStateStartup(uint8 CtrlIdx)
{
/** @req 4.2.2/SWS_TCPIP_00088 */
if(TcpIp_CtrlAdmin[CtrlIdx].tcpipEthIfRequestedCtrlState == TCPIP_STATE_OFFLINE){
/* If TCPIP_STATE_OFFLINE is requested for an EthIf
controller and the current state is TCPIP_STATE_STARTUP for that EthIf controller,
the TcpIp module shall
(a) abort all ongoing IP address assignment actions appropriate and */
#if 0
#if LWIP_AUTOIP
autoip_stop(&TcpIp_CtrlAdmin[CtrlIdx].tcpipNetif);
#endif
#if LWIP_DHCP
dhcp_stop(&TcpIp_CtrlAdmin[CtrlIdx].tcpipNetif);
#endif
netif_set_down(&TcpIp_CtrlAdmin[CtrlIdx].tcpipNetif); /* needs netif_set_up to come back */
#endif
TcpIp_DisableAllIpAddrAssignments(CtrlIdx);
/* (b) enter the state TCPIP_STATE_OFFLINE for the EthIf controller. */
TcpIp_SwitchEthIfCtrlState(CtrlIdx, TCPIP_STATE_OFFLINE);
}
else if(TcpIp_CtrlAdmin[CtrlIdx].tcpipEthIfRequestedCtrlState == TCPIP_STATE_ONLINE){
/** @req 4.2.2/SWS_TCPIP_00085 */
/* If at least one IP address has been successfully assigned to
an EthIf controller and the current state is TCPIP_STATE_STARTUP for that EthIf
controller, the TcpIp module shall enter the state TCPIP_STATE_ONLINE for the
EthIf controller.*/
if(TRUE == TcpIp_CtrlAdmin[CtrlIdx].linkUp){
/* (b) enter the state TCPIP_STATE_OFFLINE for the EthIf controller. */
TcpIp_SwitchEthIfCtrlState(CtrlIdx, TCPIP_STATE_ONLINE);
TcpIp_NotifyLocalIpAddrAssignmentChg(CtrlIdx, TCPIP_IPADDR_STATE_ASSIGNED);
}
}
else{
/* Do nothing */
}
}
static void TcpIp_HandleStateShutdown(uint8 CtrlIdx)
{
/** @req 4.2.2/SWS_TCPIP_00087 */
/* If the current state of an EthIf controller is
TCPIP_STATE_SHUTDOWN and all related resources have been released, the
TcpIp module shall enter the state TCPIP_STATE_OFFLINE for the EthIf controller.*/
// IMPROVEMENT how to find out when done
TcpIp_SwitchEthIfCtrlState(CtrlIdx, TCPIP_STATE_OFFLINE);
}
/** @req 4.2.2/SWS_TCPIP_00226*/
static void TcpIp_HandleSocketStateListening(TcpIp_SocketIdType SocketId)
{
sint32 clientFd;
struct sockaddr_in clientAddr;
uint32 addrlen = sizeof(clientAddr);
clientFd = accept(TcpIp_SocketAdmin[SocketId].socketHandle, (struct sockaddr *)&clientAddr, (uint32 *)&addrlen);/*lint !e929 !e740 */ /* pointer to pointer no harm */
if( clientFd != (-1))
{
Std_ReturnType accepted = E_NOT_OK;
sint32 on = 1;
/** @req 4.2.2/SWS_TCPIP_00114 */
/* Derive a separate socket */
TcpIp_SocketIdType socketIdConn;
if(E_OK == TcpIp_GetFirstFreeSocket(&socketIdConn)){
TcpIp_SocketAdmin[socketIdConn].socketHandle = clientFd;
TcpIp_SocketAdmin[socketIdConn].remoteAddr.domain = clientAddr.sin_family;
TcpIp_SocketAdmin[socketIdConn].remoteAddr.port = ntohs(clientAddr.sin_port);
//uint8 length = (clientAddr.sin_family == TCPIP_AF_INET6 ? TCPIP_SA_DATA_SIZE_IPV6:TCPIP_SA_DATA_SIZE_IPV4);
TcpIp_IpAddr32To8(clientAddr.sin_addr.s_addr, TcpIp_SocketAdmin[socketIdConn].remoteAddr.addr);
TcpIp_SocketAdmin[socketIdConn].socketOwnerId = TcpIp_SocketAdmin[SocketId].socketOwnerId;
/* Call upper layer for acceptance */
if(Config->Config.SocketOwnerConfig.SocketOwnerList[TcpIp_SocketAdmin[socketIdConn].socketOwnerId].SocketOwnerTcpAcceptedFncPtr != NULL){
accepted = Config->Config.SocketOwnerConfig.SocketOwnerList[TcpIp_SocketAdmin[socketIdConn].socketOwnerId].SocketOwnerTcpAcceptedFncPtr(SocketId, socketIdConn, &TcpIp_SocketAdmin[socketIdConn].remoteAddr);
}
if(E_OK == accepted){
TcpIp_SocketAdmin[socketIdConn].socketState = TCPIP_SOCKET_TCP_READY;
TcpIp_SocketAdmin[socketIdConn].socketProtocolIsTcp = TRUE;
/* Get local addr from listening socket */
TcpIp_SocketAdmin[socketIdConn].ptrLocalAddr = TcpIp_SocketAdmin[SocketId].ptrLocalAddr;
if((err_t)ERR_OK != ioctlsocket(clientFd, FIONBIO, &on)){ /*lint !e970 !e569 !e9053 LWIP */ // Set socket to non block mode
TCPIP_DET_REPORTERROR(TCPIP_MAINFUNCTION_SERVICE_ID, TCPIP_E_ARC_GENERAL_FAILURE_TCPIP_STACK);
}
}else{
(void)closesocket(clientFd);
TcpIp_FreeUpSocket(socketIdConn);
}
}
else{
(void)closesocket(clientFd);
}
}
}
static void TcpIp_HandleSocketStateConnecting(TcpIp_SocketIdType SocketId)
{
/* Just wait and check if socket is connected */
boolean connected = FALSE;
boolean closeSock = FALSE;
sint32 sockErr;
sockErr = lwip_geterr(TcpIp_SocketAdmin[SocketId].socketHandle);
switch(sockErr){
case 0:
connected = TRUE;
break;
case ERR_INPROGRESS:
/* Trying to connect*/
break;
case ERR_ABRT:
case ERR_RST:
case ERR_CLSD:
closeSock = TRUE;
break;
default:
break;
}
if(closeSock == TRUE){
(void)closesocket(TcpIp_SocketAdmin[SocketId].socketHandle);
/** @req 4.2.2/SWS_TCPIP_00144 */
/** @req 4.2.2/SWS_TCPIP_00224 */
/* The TcpIp module shall indicate events related to sockets to
the upper layer module by using the Up_TcpIpEvent API and the following events:
TCPIP_TCP_RESET, TCPIP_TCP_CLOSED, TCPIP_TCP_FIN_RECEIVED and
TCPIP_UDP_CLOSED. */
if(Config->Config.SocketOwnerConfig.SocketOwnerList[TcpIp_SocketAdmin[SocketId].socketOwnerId].SocketOwnerTcpIpEventFncPtr != NULL){
Config->Config.SocketOwnerConfig.SocketOwnerList[TcpIp_SocketAdmin[SocketId].socketOwnerId].SocketOwnerTcpIpEventFncPtr(SocketId, TCPIP_TCP_CLOSED);
}
TcpIp_FreeUpSocket(SocketId);
}else if(connected == TRUE){
TcpIp_SocketAdmin[SocketId].socketState = TCPIP_SOCKET_TCP_READY;
/* Call upper layer */
/** @req 4.2.2/SWS_TCPIP_00227 */
if(Config->Config.SocketOwnerConfig.SocketOwnerList[TcpIp_SocketAdmin[SocketId].socketOwnerId].SocketOwnerTcpConnectedFncPtr != NULL){
Config->Config.SocketOwnerConfig.SocketOwnerList[TcpIp_SocketAdmin[SocketId].socketOwnerId].SocketOwnerTcpConnectedFncPtr(SocketId);
}
}else{
/* Do nothing but keep Lint happy */
}
}
static void TcpIp_HandleSocketStateTcpReady(TcpIp_SocketIdType SocketId)
{
sint32 nBytes = 1;
uint8 *dataPtr;
/* Note: Even it is not shown in the sequence diagram of section 9.3, TcpIp may
decouple the data reception if required. E.g. for reassembling of incoming IP
datagrams that are fragmented, TcpIp shall copy the received data to a TcpIp buffer
and decouple TcpIp_RxIndication() from SoAd_RxIndication() */
while(nBytes > 0){
if (TRUE == TcpIp_BufferGet(TCPIP_RX_BUFFER_SIZE, &dataPtr)) {
nBytes = recv(TcpIp_SocketAdmin[SocketId].socketHandle, dataPtr, TCPIP_RX_BUFFER_SIZE, 0);
if (nBytes > 0){
/* Call upper layer */
/** @req 4.2.2/SWS_TCPIP_00223 */
if(Config->Config.SocketOwnerConfig.SocketOwnerList[TcpIp_SocketAdmin[SocketId].socketOwnerId].SocketOwnerRxIndicationFncPtr != NULL){
Config->Config.SocketOwnerConfig.SocketOwnerList[TcpIp_SocketAdmin[SocketId].socketOwnerId].SocketOwnerRxIndicationFncPtr(SocketId, &TcpIp_SocketAdmin[SocketId].remoteAddr, dataPtr, nBytes);
}
}else if(nBytes == 0){
/* connection closed */
(void)closesocket(TcpIp_SocketAdmin[SocketId].socketHandle);
/** @req 4.2.2/SWS_TCPIP_00144 */
/** @req 4.2.2/SWS_TCPIP_00224 */
/* The TcpIp module shall indicate events related to sockets to
the upper layer module by using the Up_TcpIpEvent API and the following events:
TCPIP_TCP_RESET, TCPIP_TCP_CLOSED, TCPIP_TCP_FIN_RECEIVED and
TCPIP_UDP_CLOSED. */
if(Config->Config.SocketOwnerConfig.SocketOwnerList[TcpIp_SocketAdmin[SocketId].socketOwnerId].SocketOwnerTcpIpEventFncPtr != NULL){
Config->Config.SocketOwnerConfig.SocketOwnerList[TcpIp_SocketAdmin[SocketId].socketOwnerId].SocketOwnerTcpIpEventFncPtr(SocketId, TCPIP_TCP_CLOSED);
}
TcpIp_FreeUpSocket(SocketId);
}else{
/* Nothing received */
}
TcpIp_BufferFree(dataPtr);
}else{
TCPIP_DET_REPORTERROR(TCPIP_MAINFUNCTION_SERVICE_ID, TCPIP_E_NOBUFS);
nBytes = 0;
}
}
}
static void TcpIp_HandleSocketStateUdpReady(TcpIp_SocketIdType SocketId)
{
sint32 nBytes = 1;
uint8 *dataPtr;
struct sockaddr_in fromAddr;
uint32 fromAddrLen = sizeof(fromAddr);
TcpIp_SockAddrType remoteAddr;
/* Note: Even it is not shown in the sequence diagram of section 9.3, TcpIp may
decouple the data reception if required. E.g. for reassembling of incoming IP
datagrams that are fragmented, TcpIp shall copy the received data to a TcpIp buffer
and decouple TcpIp_RxIndication() from SoAd_RxIndication() */
while(nBytes > 0){
if (TRUE == TcpIp_BufferGet(TCPIP_RX_BUFFER_SIZE, &dataPtr)) {
nBytes = recvfrom(TcpIp_SocketAdmin[SocketId].socketHandle, dataPtr, TCPIP_RX_BUFFER_SIZE, 0, (struct sockaddr*)&fromAddr, &fromAddrLen);/*lint !e929 !e740 */ /* pointer to pointer no harm */
if (nBytes > 0){
remoteAddr.domain = fromAddr.sin_family;
remoteAddr.port = ntohs(fromAddr.sin_port);
TcpIp_IpAddr32To8(fromAddr.sin_addr.s_addr, remoteAddr.addr);
/* Call upper layer */
/** @req 4.2.2/SWS_TCPIP_00223 */
if(Config->Config.SocketOwnerConfig.SocketOwnerList[TcpIp_SocketAdmin[SocketId].socketOwnerId].SocketOwnerRxIndicationFncPtr != NULL){
Config->Config.SocketOwnerConfig.SocketOwnerList[TcpIp_SocketAdmin[SocketId].socketOwnerId].SocketOwnerRxIndicationFncPtr(SocketId, &remoteAddr, dataPtr, nBytes);
}
}
TcpIp_BufferFree(dataPtr);
}else{
/** @req 4.2.2/SWS_TCPIP_00089 */
TCPIP_DET_REPORTERROR(TCPIP_MAINFUNCTION_SERVICE_ID, TCPIP_E_NOBUFS);
nBytes = 0;
}
}
}
/**
* @brief TcpIp main function.
* @param void
* @return void
*/
/** @req 4.2.2/SWS_TCPIP_00026 */
/** !req 4.2.2/SWS_TCPIP_00094 */
void TcpIp_MainFunction(void){
for(uint32 CtrlIdx=0; CtrlIdx < TCPIP_NOF_CONTROLLERS; CtrlIdx++)
{
/** @req 4.2.2/SWS_TCPIP_00026 */
switch (TcpIp_CtrlAdmin[CtrlIdx].tcpipEthIfCtrlState) {
case TCPIP_STATE_OFFLINE:
TcpIp_HandleStateOffline(CtrlIdx);
break;
case TCPIP_STATE_ONLINE:
TcpIp_HandleStateOnline(CtrlIdx);
break;
case TCPIP_STATE_ONHOLD:
TcpIp_HandleStateOnhold(CtrlIdx);
break;
case TCPIP_STATE_STARTUP:
TcpIp_HandleStateStartup(CtrlIdx);
break;
case TCPIP_STATE_SHUTDOWN:
TcpIp_HandleStateShutdown(CtrlIdx);
break;
default:
/* Should not happen. Let us have an DET error */
TCPIP_DET_REPORTERROR(TCPIP_MAINFUNCTION_SERVICE_ID, TCPIP_E_ARC_ILLEGAL_STATE);
break;
}
}
for (uint32 i = 0; i < TCPIP_MAX_NOF_SOCKETS; i++) {
switch (TcpIp_SocketAdmin[i].socketState) {
case TCPIP_SOCKET_TCP_LISTENING:
TcpIp_HandleSocketStateListening(i);
if(TcpIp_SocketAdmin[i].socketHandle != -1){
TcpIp_SocketStatusCheck(i);
}
break;
case TCPIP_SOCKET_TCP_CONNECTING:
TcpIp_HandleSocketStateConnecting(i);
/* Status is checked withing state */
break;
case TCPIP_SOCKET_TCP_READY:
TcpIp_HandleSocketStateTcpReady(i);
if(TcpIp_SocketAdmin[i].socketHandle != -1){
TcpIp_SocketStatusCheck(i);
}
break;
case TCPIP_SOCKET_UDP_READY:
TcpIp_HandleSocketStateUdpReady(i);
if(TcpIp_SocketAdmin[i].socketHandle != -1){
TcpIp_SocketStatusCheck(i);
}
break;
default:
/* Do nothing */
break;
}
}
}
/*lint -restore*/ /* end for 9027 734 9045 */
|
2301_81045437/classic-platform
|
communication/TcpIp/src/TcpIp.c
|
C
|
unknown
| 105,756
|
/*-------------------------------- Arctic Core ------------------------------
* Copyright (C) 2013, ArcCore AB, Sweden, www.arccore.com.
* Contact: <contact@arccore.com>
*
* You may ONLY use this file:
* 1)if you have a valid commercial ArcCore license and then in accordance with
* the terms contained in the written license agreement between you and ArcCore,
* or alternatively
* 2)if you follow the terms found in GNU General Public License version 2 as
* published by the Free Software Foundation and appearing in the file
* LICENSE.GPL included in the packaging of this file or here
* <http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt>
*-------------------------------- Arctic Core -----------------------------*/
/** @tagSettings DEFAULT_ARCHITECTURE=LINUX */
/** @req 4.2.2/SWS_TCPIP_00052 */
/** @req 4.2.2/SWS_TCPIP_00148 */
/** @req 4.2.2/SWS_TCPIP_00053 */
/** @req 4.2.2/SWS_TCPIP_00095 */
/** @req 4.2.2/SWS_TCPIP_00096 */
/** @req 4.2.2/SWS_TCPIP_00102 */
/** @req 4.2.2/SWS_TCPIP_00097 */
/** @req 4.2.2/SWS_TCPIP_00098 */
/** !req 4.2.2/SWS_TCPIP_00054 */ /* Fragmentation */
/** !req 4.2.2/SWS_TCPIP_00231 */
/** @req 4.2.2/SWS_TCPIP_00055 */
/** @req 4.2.2/SWS_TCPIP_00056 */
/** !req 4.2.2/SWS_TCPIP_00091 */ /* arp TcpIpArpTableEntryTimeout */
/** @req 4.2.2/SWS_TCPIP_00092 */
/** !req 4.2.2/SWS_TCPIP_00142 */ /* Arp Table change callback */
/** @req 4.2.2/SWS_TCPIP_00093 */
/** @req 4.2.2/SWS_TCPIP_00151 */
/** @req 4.2.2/SWS_TCPIP_00057 */
/** @req 4.2.2/SWS_TCPIP_00059 */
/** !req 4.2.2/SWS_TCPIP_00099 */
/** @req 4.2.2/SWS_TCPIP_00100 */
/** @req 4.2.2/SWS_TCPIP_00130 */
/** @req 4.2.2/SWS_TCPIP_00060 */
/** @req 4.2.2/SWS_TCPIP_00103 */
/** @req 4.2.2/SWS_TCPIP_00061 */
/** @req 4.2.2/SWS_TCPIP_00062 */
/** @req 4.2.2/SWS_TCPIP_00063 */
/** @req 4.2.2/SWS_TCPIP_00064 */
/** @req 4.2.2/SWS_TCPIP_00168 */
/** !req 4.2.2/SWS_TCPIP_00200 */ /* dhcp server */
/** !req 4.2.2/SWS_TCPIP_00201 */ /* dhcp server */
/** !req 4.2.2/SWS_TCPIP_00218 */ /* dhcp server */
/** !req 4.2.2/SWS_TCPIP_00200 */ /* dhcp server */
/** @req 4.2.2/SWS_TCPIP_00058 */
/** @req 4.2.2/SWS_TCPIP_00152 */
/** @req 4.2.2/SWS_TCPIP_00169 */
/** @req 4.2.2/SWS_TCPIP_00170 */
/** @req 4.2.2/SWS_TCPIP_00171 */
/** @req 4.2.2/SWS_TCPIP_00172 */
/** @req 4.2.2/SWS_TCPIP_00173 */
/** @req 4.2.2/SWS_TCPIP_00174 */
/** @req 4.2.2/SWS_TCPIP_00175 */
/** @req 4.2.2/SWS_TCPIP_00176 */
/** @req 4.2.2/SWS_TCPIP_00177 */
/** @req 4.2.2/SWS_TCPIP_00178 */
/** @req 4.2.2/SWS_TCPIP_00179 */
/** @req 4.2.2/SWS_TCPIP_00180 */
/** !req 4.2.2/SWS_TCPIP_00191 *//* Arp handled by lwip */
/** !req 4.2.2/SWS_TCPIP_00192 *//* Arp handled by lwip */
/** @req 4.2.2/SWS_TCPIP_00008 */
/** !req 4.2.2/SWS_TCPIP_00202 *//* TcpIp tiemout handled by lwip */
/** !req 4.2.2/SWS_TCPIP_00203 */ /* hw checksum, no cfg parameter ? Always using hw chk if available*/
/** !req 4.2.2/SWS_TCPIP_00204 */ /* hw checksum, no cfg parameter ? Always using hw chk if available*/
/** !req 4.2.2/SWS_TCPIP_00149 */ /* IPv6*/
/** !req 4.2.2/SWS_TCPIP_00150 */ /* IPv6*/
/** !req 4.2.2/SWS_TCPIP_00153 *//* IPv6*/
/** !req 4.2.2/SWS_TCPIP_00154 */ /* IPv6*/
/** !req 4.2.2/SWS_TCPIP_00156 */ /* IPv6*/
/** !req 4.2.2/SWS_TCPIP_00157 */ /* IPv6*/
/** !req 4.2.2/SWS_TCPIP_00158 */ /* IPv6*/
/** !req 4.2.2/SWS_TCPIP_00149 */ /* IPv6*/
/** !req 4.2.2/SWS_TCPIP_00159 */ /* IPv6*/
/** !req 4.2.2/SWS_TCPIP_00160 */ /* IPv6*/
/** !req 4.2.2/SWS_TCPIP_00161 */ /* IPv6*/
/** !req 4.2.2/SWS_TCPIP_00155 */ /* IPv6*/
/** !req 4.2.2/SWS_TCPIP_00232 */ /* IPv6*/
/** !req 4.2.2/SWS_TCPIP_00162 */ /* IPv6*/
/** !req 4.2.2/SWS_TCPIP_00163 */ /* IPv6*/
/** !req 4.2.2/SWS_TCPIP_00164 */ /* IPv6*/
/** !req 4.2.2/SWS_TCPIP_00165 */ /* IPv6*/
/** !req 4.2.2/SWS_TCPIP_00099 */ /* IPv6*/
/** !req 4.2.2/SWS_TCPIP_00166 */ /* IPv6*/
/** !req 4.2.2/SWS_TCPIP_00167 */ /* IPv6*/
/** !req 4.2.2/SWS_TCPIP_00181 */ /* IPv6*/
/** !req 4.2.2/SWS_TCPIP_00182 */ /* IPv6*/
/** !req 4.2.2/SWS_TCPIP_00183 */ /* IPv6*/
/** !req 4.2.2/SWS_TCPIP_00184 */ /* IPv6*/
/** !req 4.2.2/SWS_TCPIP_00185 */ /* IPv6*/
/** !req 4.2.2/SWS_TCPIP_00193 */ /* IPv6*/
/** !req 4.2.2/SWS_TCPIP_00194 */ /* IPv6*/
/** !req 4.2.2/SWS_TCPIP_00101 */ /* IPv6*/
/** !req 4.2.2/SWS_TCPIP_00219 */ /* Nvm store*/
#include "TcpIp.h"
#include "Eth_GeneralTypes.h"
#include "SchM_TcpIp.h"
#include "MemMap.h"
#include <string.h>
#ifndef _WIN32
#include <stdlib.h>
#include <unistd.h> // close()
#include <fcntl.h>
#include <errno.h>
#include <sys/types.h>
#include <netinet/in.h>
#include <netinet/tcp.h>
#include <arpa/inet.h>
#include <linux/netdevice.h>
#include <sys/socket.h>
#else
#include "os_stubs.h"
#endif
#if defined(USE_ETHSM)
#include "EthSM_Cbk.h"
#endif
#if defined(USE_ETHIF)
#include "EthIf.h"
#endif
/** @req 4.2.2/SWS_TCPIP_00068 */
#if defined(USE_DEM)
#include "Dem.h"
#endif
#if defined(USE_SOAD)
#include "SoAd.h"
#endif
#if ( TCPIP_DEV_ERROR_DETECT == STD_ON )
#if defined(USE_DET)
#include "Det.h"
#endif
#include "linos_logger.h" /* Logger functions */
// IMPROVEMENT SimonG
const TcpIp_ConfigType TcpIp_Config;
int gnulinuxTcpBindAny = FALSE;
#define TCPIP_DET_REPORTERROR(_api,_err) \
do { \
(void)Det_ReportError(TCPIP_MODULE_ID, 0, _api, _err); \
} while(0)
#else
#define TCPIP_DET_REPORTERROR(_api,_err)
#endif
#define VALIDATE(_exp,_api,_err ) \
if( !(_exp) ) { \
TCPIP_DET_REPORTERROR(_api, _err); \
return E_NOT_OK; \
}
#define VALIDATE_RV(_exp,_api,_err,_rv ) \
if( !(_exp) ) { \
TCPIP_DET_REPORTERROR(_api, _err); \
return _rv; \
}
#define VALIDATE_NO_RV(_exp,_api,_err ) \
if( !(_exp) ) { \
TCPIP_DET_REPORTERROR(_api, _err); \
return; \
}
/* Largest needed packet size is now defined in Application config */
//#define TCPIP_RX_BUFFER_SIZE 8192u
/*
* Local variables
*/
typedef enum {
TCPIP_SOCKET_INIT,
TCPIP_SOCKET_BIND,
TCPIP_SOCKET_TCP_CONNECT_LISTEN,
TCPIP_SOCKET_TCP_LISTENING,
TCPIP_SOCKET_TCP_READY,
TCPIP_SOCKET_UDP_READY
} TcpIp_SocketStateType;
typedef struct {
TcpIp_SocketStateType socketState;
boolean socketProtocolIsTcp;
int socketHandle;
uint8 socketOwnerId;
const TcpIp_LocalAddrType *ptrLocalAddr;
TcpIp_SockAddrType remoteAddr;
}TcpIp_SocketAdminType;
typedef struct {
boolean linkUp;
const TcpIp_LocalAddrType *ptrLocalUnicastAddr;
TcpIp_StateType tcpipEthIfCtrlState;
TcpIp_StateType tcpipEthIfRequestedCtrlState;
struct ifaddrs *tcpipNetif;
}TcpIp_CtrlAdminType;
//typedef struct {
//}TcpIp_LocalAddrAdminType;
/** @req 4.2.2/SWS_TCPIP_00083 */
static TcpIp_CtrlAdminType TcpIp_CtrlAdmin[TCPIP_NOF_CONTROLLERS];
static TcpIp_SocketAdminType TcpIp_SocketAdmin[TCPIP_MAX_NOF_SOCKETS];
static uint16 TcpIp_NofUsedSockets = 0;
boolean tcpip_initialized = FALSE;
/* External functions */
extern Std_ReturnType Det_ReportError(uint16 ModuleId, uint8 InstanceId, uint8 ApiId, uint8 ErrorId);
/*
* Local tcpip helper functions
*/
static void TcpIp_IpAddr32To8(uint32 src, char *dest)
{
#if (CPU_BYTE_ORDER == HIGH_BYTE_FIRST)
dest[0] = (uint8)((src & 0xff000000) >> 24);
dest[1] = (uint8)((src & 0x00ff0000) >> 16);;
dest[2] = (uint8)((src & 0x0000ff00) >> 8);;
dest[3] = (uint8)(src & 0x000000ff);
#else
dest[3] = (uint8)((src & 0xff000000) >> 24);
dest[2] = (uint8)((src & 0x00ff0000) >> 16);;
dest[1] = (uint8)((src & 0x0000ff00) >> 8);;
dest[0] = (uint8)(src & 0x000000ff);
#endif
}
static void TcpIp_IpAddr8to32(const char *src, uint32 *dest)
{
#if (CPU_BYTE_ORDER == HIGH_BYTE_FIRST)
*dest = ( ((uint32)((src[0]) & 0xff) << 24) | ((uint32)((src[1]) & 0xff) << 16) | ((uint32)((src[2]) & 0xff) << 8) | (uint32)((src[3]) & 0xff) );
#else
*dest = ( ((uint32)((src[3]) & 0xff) << 24) | ((uint32)((src[2]) & 0xff) << 16) | ((uint32)((src[1]) & 0xff) << 8) | (uint32)((src[0]) & 0xff) );
#endif
}
/*
* Simple function to display an IP address.
*
* buffer should be at least INET_ADDRSTRLEN long.
*
*/
void TcpIp_IpAddrToChar(char *buffer, uint32 src)
{
#ifndef _WIN32
char addr[INET_ADDRSTRLEN];
// char buffer[INET_ADDRSTRLEN];
TcpIp_IpAddr32To8(src, addr);
inet_ntop(AF_INET,&addr, buffer, INET_ADDRSTRLEN);
#endif
}
static void TcpIp_SwitchEthIfCtrlState(uint8 CtrlIdx, TcpIp_StateType TcpIpState)
{
/** @req 4.2.2/SWS_TCPIP_00084 */
/* After each transition the TcpIp module shall report the new
* state to EthSM via EthSM_TcpIpModeIndication() */
TcpIp_CtrlAdmin[CtrlIdx].tcpipEthIfCtrlState = TcpIpState;
#if defined(USE_ETHSM)
(void)EthSM_TcpIpModeIndication(CtrlIdx, TcpIpState); /*no return check, nothing can do about it*/
#endif
}
/* Gets the index of a controller in the global configuration structure. */
/* Gets the index of a controller in the global configuration structure. */
static inline uint8 getLocalAddrListConfigIdx(uint8 addressId) {
for (uint8 i = 0; i < TCPIP_NOF_LOCALADDR; i++) {
if (TcpIp_Config.Config.LocalAddrList[i].AddressId == addressId) {
return i;
}
}
return 0;
}
static Std_ReturnType TcpIp_GetFirstFreeSocket(TcpIp_SocketIdType *SocketIdPtr){
Std_ReturnType result = E_NOT_OK;
SchM_Enter_TcpIp_EA_0();
for(int i=0; i < TCPIP_MAX_NOF_SOCKETS; i++){
if( (TcpIp_SocketAdmin[i].socketState == TCPIP_SOCKET_INIT) &&
(TcpIp_SocketAdmin[i].socketHandle == -1))
{
*SocketIdPtr = i;
TcpIp_NofUsedSockets++;
result = E_OK;
break;
}
}
SchM_Exit_TcpIp_EA_0();
return result;
}
static void TcpIp_FreeUpSocket(TcpIp_SocketIdType SocketId){
SchM_Enter_TcpIp_EA_0();
TcpIp_SocketAdmin[SocketId].socketState = TCPIP_SOCKET_INIT;
TcpIp_SocketAdmin[SocketId].socketHandle = -1;
TcpIp_SocketAdmin[SocketId].ptrLocalAddr = NULL;
TcpIp_NofUsedSockets--;
SchM_Exit_TcpIp_EA_0();
}
static void TcpIp_SocketStatusCheck(TcpIp_SocketIdType socketId)
{
#ifndef _WIN32
int sockErr;
uint32 sockErrLen = sizeof(sockErr);
boolean closeSock = FALSE;
TcpIp_EventType event;
getsockopt(TcpIp_SocketAdmin[socketId].socketHandle, SOL_SOCKET, SO_ERROR, &sockErr, &sockErrLen);
switch(sockErr){
case 0:
case EAGAIN:
/* OK */
break;
// case ECONNRESET:
default:
closeSock = TRUE;
break;
}
if(closeSock){
close(TcpIp_SocketAdmin[socketId].socketHandle);
if(TcpIp_SocketAdmin[socketId].socketProtocolIsTcp){
event = TCPIP_TCP_CLOSED;
}else{
event = TCPIP_UDP_CLOSED;
}
/** @req 4.2.2/SWS_TCPIP_00144 */
/* The TcpIp module shall indicate events related to sockets to
the upper layer module by using the Up_TcpIpEvent API and the following events:
TCPIP_TCP_RESET, TCPIP_TCP_CLOSED, TCPIP_TCP_FIN_RECEIVED and
TCPIP_UDP_CLOSED. */
if(TcpIp_Config.Config.SocketOwnerConfig.SocketOwnerList[TcpIp_SocketAdmin[socketId].socketOwnerId].SocketOwnerTcpIpEventFncPtr != NULL){
TcpIp_Config.Config.SocketOwnerConfig.SocketOwnerList[TcpIp_SocketAdmin[socketId].socketOwnerId].SocketOwnerTcpIpEventFncPtr(socketId, event);
}
TcpIp_FreeUpSocket(socketId);
}
#endif
}
#define TEMP_ETHIF_FIX 1
#if defined(TEMP_ETHIF_FIX)
static uint16 TcpIp_SendIpMessage(int SocketHandle, const uint8* DataPtr,
const TcpIp_SockAddrType* RemoteAddrPtr, uint16 TotalLength) {
uint16 bytesSent = 0;
char toAddrString[INET_ADDRSTRLEN];
int sendRet = -1;
int saved_errno;
#ifndef _WIN32
if (RemoteAddrPtr == NULL) {
/* TCP */
sendRet = send(SocketHandle, (uint8*) DataPtr, TotalLength, 0);
if (sendRet == -1) {
/* Saving errno before making any more POSIX system calls. */
saved_errno = errno;
/* Make sure bytesSent is set to zero as done in OSEK TcpIp.c */
bytesSent = 0;
} else {
/* Safe conversion of positive value from signed to unsigned. */
bytesSent = sendRet;
}
/* Logging */
if (sendRet == -1) {
logger_mod((LOGGER_MOD_TCP | LOGGER_SUB_TCP_SEND), LOG_ERR,
"TcpIp_SendIpMessage: Error on send call, SocketHandle %d, errno %d",
SocketHandle, saved_errno);
} else {
logger_mod((LOGGER_MOD_TCP | LOGGER_SUB_TCP_SEND), LOG_INFO,
"TcpIp_SendIpMessage: SocketHandle %d, BytesSent [%d] TotalLength [%d]",
SocketHandle, bytesSent, TotalLength);
}
} else {
/* UDP */
struct sockaddr_in toAddr;
//uint32 toAddrLen = sizeof(toAddr);
toAddr.sin_family = RemoteAddrPtr->domain;
//toAddr.sin_len = sizeof(toAddr);
//uint8 length = (RemoteAddrPtr->domain == TCPIP_AF_INET6 ? TCPIP_SA_DATA_SIZE_IPV6:TCPIP_SA_DATA_SIZE_IPV4);
TcpIp_IpAddr8to32(RemoteAddrPtr->addr, &toAddr.sin_addr.s_addr);
//inet_aton(RemoteAddrPtr->addr, &toAddr.sin_addr);
toAddr.sin_port = htons(RemoteAddrPtr->port);
sendRet = sendto(SocketHandle, (uint8*) DataPtr, TotalLength, 0,
(struct sockaddr *) &toAddr, sizeof(toAddr));
if (sendRet == -1) {
/* Saving errno before making any more POSIX system calls. */
saved_errno = errno;
/* Make sure bytesSent is set to zero as done in OSEK TcpIp.c */
bytesSent = 0;
} else {
/* Safe conversion of positive value from signed to unsigned. */
bytesSent = sendRet;
}
/* Any way, initialize toAddrString. */
TcpIp_IpAddrToChar((char *) &toAddrString, toAddr.sin_addr.s_addr);
/* Logging */
if (sendRet == -1) {
logger_mod((LOGGER_MOD_TCP | LOGGER_SUB_TCP_SEND), LOG_ERR,
"TcpIp_SendIpMessage: Error on sendto call, SocketHandle %d, To %s:%d, errno %d",
SocketHandle, toAddrString, RemoteAddrPtr->port,
saved_errno);
} else {
logger_mod((LOGGER_MOD_TCP | LOGGER_SUB_TCP_SEND), LOG_INFO,
"TcpIp_SendIpMessage: SocketHandle %d, To %s:%d, BytesSent [%d] TotalLength [%d]",
SocketHandle, toAddrString, RemoteAddrPtr->port, bytesSent,
TotalLength);
}
}
#endif
return bytesSent;
}
static boolean TcpIp_BufferGet(uint32 size, uint8** buffPtr)
{
boolean res;
*buffPtr = malloc(size);
res = (*buffPtr != NULL) ? TRUE : FALSE;
return res;
}
static void TcpIp_BufferFree(uint8* buffPtr)
{
free(buffPtr);
}
BufReq_ReturnType EthIf_ProvideTxBuffer( uint8 CtrlIdx, Eth_FrameType FrameType, uint8 Priority,
Eth_BufIdxType* BufIdxPtr, uint8** BufPtr, uint16* LenBytePtr){
BufReq_ReturnType res = BUFREQ_NOT_OK;
if(TcpIp_BufferGet(*LenBytePtr, BufPtr)){
res = BUFREQ_OK;
}
return res;
}
Std_ReturnType EthIf_Transmit(uint8 CtrlIdx,Eth_BufIdxType BufIdx,Eth_FrameType FrameType,
boolean TxConfirmation,uint16 LenByte,const uint8* PhysAddrPtr)
{
return E_OK;
}
void EthIf_GetPhysAddr(uint8 CtrlIdx,uint8* PhysAddrPtr){
PhysAddrPtr[0] = 0x0;
PhysAddrPtr[1] = 0x0;
PhysAddrPtr[2] = 0x0;
PhysAddrPtr[3] = 0x0;
PhysAddrPtr[4] = 0x0;
PhysAddrPtr[5] = 0x2;
}
#endif /* Temporary EthIf replacement */
Std_ReturnType TcpIp_GetSocket(uint8 SocketOwnerId,TcpIp_DomainType Domain, TcpIp_ProtocolType Protocol, TcpIp_SocketIdType* SocketIdPtr)
{
int sockFd;
int sockType;
Std_ReturnType result = E_OK;
#ifndef _WIN32
/* @req 4.2.2/SWS_TCPIP_00128 */
VALIDATE( (Domain == TCPIP_AF_INET), TCPIP_GETSOCKET_SERVICE_ID, TCPIP_E_AFNOSUPPORT)
// No specified autosar error for protocol check, use TCPIP_E_NOPROTOOPT as it seems most logical
VALIDATE( (TCPIP_IPPROTO_UDP == Protocol) || (TCPIP_IPPROTO_TCP == Protocol), TCPIP_GETSOCKET_SERVICE_ID, TCPIP_E_NOPROTOOPT)
if (TCPIP_IPPROTO_TCP == Protocol) {
sockType = SOCK_STREAM;
} else {
sockType = SOCK_DGRAM;
}
#if defined(ANDROID_NDK)
sockFd = socket(Domain, (sockType), 0);
int sockFlags = fcntl(sockFd, F_GETFL, 0);
fcntl(sockFd, F_SETFL, sockFlags | O_NONBLOCK);
#else
sockFd = socket(Domain, (sockType|SOCK_NONBLOCK), 0); // Set socket to non block mode
#endif
if(sockFd < 0){
result = E_NOT_OK;
}else{
TcpIp_SocketIdType socketId;
if(E_OK == TcpIp_GetFirstFreeSocket(&socketId)){
/* Socket assigned, get first free socket index */
TcpIp_SocketAdmin[socketId].socketHandle = sockFd;
TcpIp_SocketAdmin[socketId].socketOwnerId = SocketOwnerId;
TcpIp_SocketAdmin[socketId].socketState = TCPIP_SOCKET_BIND;
TcpIp_SocketAdmin[socketId].socketProtocolIsTcp = TCPIP_IPPROTO_TCP == Protocol ? TRUE:FALSE;
*SocketIdPtr = socketId;
}else{
result = E_NOT_OK;
close(sockFd);
}
}
#endif
return result;
}
/**
* @brief This service initializes the TCP/IP Stack
* @param SocketId - Socket handle identifying the local socket resource ConfigPtr - Configuration data ptr
* @return void
*/
/** @req 4.2.2/SWS_TCPIP_00002 */
void TcpIp_Init(const TcpIp_ConfigType* ConfigPtr){
(void)ConfigPtr; /* not used */
for(int i=0; i < TCPIP_NOF_CONTROLLERS; i++){
TcpIp_CtrlAdmin[i].tcpipEthIfCtrlState = TCPIP_STATE_OFFLINE;
TcpIp_CtrlAdmin[i].tcpipEthIfRequestedCtrlState = TCPIP_STATE_OFFLINE;
TcpIp_CtrlAdmin[i].ptrLocalUnicastAddr = NULL;
}
for(int i=0; i < TCPIP_MAX_NOF_SOCKETS; i++){
TcpIp_SocketAdmin[i].socketState = TCPIP_SOCKET_INIT;
TcpIp_SocketAdmin[i].socketHandle = -1;
TcpIp_SocketAdmin[i].ptrLocalAddr = NULL;
TcpIp_SocketAdmin[i].socketProtocolIsTcp = FALSE;
}
tcpip_initialized = TRUE;
//LwIP_Init();
}
/**
* @brief By this API service the TCP/IP stack is requested to close the socket and release
* all related resources.
* @param SocketId - Socket handle identifying the local socket resource
* @param Abort - TRUE: connection will immediately be terminated by sending a
* RST-Segment and releasing all related resources.
* FALSE: connection will be terminated after performing a regular
* connection termination handshake and releasing all related resources.
* @return result of the function.
*/
/** @req 4.2.2/SWS_TCPIP_00017 */
Std_ReturnType TcpIp_Close(TcpIp_SocketIdType SocketId, boolean Abort){
Std_ReturnType result = E_OK;
/** @req 4.2.2/SWS_TCPIP_00109 *//* Using sockets can not handle abort */
/** @req 4.2.2/SWS_TCPIP_00110 */
/* Ignore abort parameter as close always perform a FIN/ACK handshake. Using
* shutdown does not solve this either */
close(TcpIp_SocketAdmin[SocketId].socketHandle);
TcpIp_FreeUpSocket(SocketId);
return result;
}
/**
* @brief By this API service the TCP/IP stack is requested to bind a UDP or TCP socket to
* a local resource.
* @param SocketId - Socket handle identifying the local socket resource
* @param LocalAddrId - IP address identifier representing the local IP address and EthIf
* controller to bind the socket to.
* @param PortPtr - Pointer to memory where the local port to which the socket shall
* be bound is specified. In case the parameter is specified as
* TCPIP_PORT_ANY, the TCP/IP stack shall choose the local port
* automatically from the range 49152 to 65535 and shall update the
* parameter to the chosen value.
* @return result of the function.
*/
/** @req 4.2.2/SWS_TCPIP_00015 */
Std_ReturnType TcpIp_Bind(TcpIp_SocketIdType SocketId, TcpIp_LocalAddrIdType LocalAddrId, uint16* PortPtr){
Std_ReturnType result = E_OK;
#ifndef _WIN32
struct sockaddr_in sLocalAddr;
const TcpIp_LocalAddrType *ptrLocalAddr = &TcpIp_Config.Config.LocalAddrList[getLocalAddrListConfigIdx(LocalAddrId)];
char strAddr[INET_ADDRSTRLEN];
/** @req 4.2.2/SWS_TCPIP_00111 */
/** @req 4.2.2/SWS_TCPIP_00130 */
/** @req 4.2.2/SWS_TCPIP_00015 */
/** !req 4.2.2/SWS_TCPIP_00146 */
/** !req 4.2.2/SWS_TCPIP_00147 */
memset((char *)&sLocalAddr, 0, sizeof(sLocalAddr));
/*Source*/
sLocalAddr.sin_family = ptrLocalAddr->Domain;
//sLocalAddr.sin_len = sizeof(sLocalAddr);
sLocalAddr.sin_port = htons(*PortPtr);
TcpIp_IpAddrToChar((char *)&strAddr, ptrLocalAddr->StaticIpAddrConfig->StaticIpAddress);
if (gnulinuxTcpBindAny)
{
logger(LOG_INFO, "TcpIp_Bind binding SocketId %d IsTcp %d to INADDR_ANY NOT %s port %d", SocketId,
TcpIp_SocketAdmin[SocketId].socketProtocolIsTcp, (char *) strAddr, *PortPtr);
sLocalAddr.sin_addr.s_addr = htonl(INADDR_ANY);
}
else
{
logger_mod((LOGGER_MOD_TCP|LOGGER_SUB_TCP_BIND), LOG_INFO, "TcpIp_Bind binding SocketId %d IsTcp %d to %s port %d", SocketId,
TcpIp_SocketAdmin[SocketId].socketProtocolIsTcp, (char *) strAddr, *PortPtr);
sLocalAddr.sin_addr.s_addr = ptrLocalAddr->StaticIpAddrConfig->StaticIpAddress;
}
if(bind(TcpIp_SocketAdmin[SocketId].socketHandle, (struct sockaddr *)&sLocalAddr, sizeof(sLocalAddr)) < 0) {
result = E_NOT_OK;
logger(LOG_ERR, "TcpIp_Bind bind failure [%s] ", strerror(errno));
}else{
if(ptrLocalAddr->AddressType == TCPIP_MULTICAST){
struct ip_mreq mreq;
mreq.imr_multiaddr.s_addr = sLocalAddr.sin_addr.s_addr;
/** @req 4.2.2/SWS_TCPIP_00178 */
if( TcpIp_CtrlAdmin[ptrLocalAddr->TcpIpCtrlRef].ptrLocalUnicastAddr != NULL &&
TcpIp_CtrlAdmin[ptrLocalAddr->TcpIpCtrlRef].ptrLocalUnicastAddr->StaticIpAddrConfig->ArcValid){
mreq.imr_interface.s_addr = TcpIp_CtrlAdmin[ptrLocalAddr->TcpIpCtrlRef].ptrLocalUnicastAddr->StaticIpAddrConfig->StaticIpAddress;
}
else{
mreq.imr_interface.s_addr = htonl(INADDR_ANY);
}
if (setsockopt(TcpIp_SocketAdmin[SocketId].socketHandle, IPPROTO_IP, IP_ADD_MEMBERSHIP, &mreq, sizeof(mreq)) < 0)
{
result = E_NOT_OK;
/* IMPROVEMENT, remove this when know working */
}
}
TcpIp_SocketAdmin[SocketId].ptrLocalAddr = ptrLocalAddr;
if(TcpIp_SocketAdmin[SocketId].socketProtocolIsTcp){
TcpIp_SocketAdmin[SocketId].socketState = TCPIP_SOCKET_TCP_CONNECT_LISTEN;
}else{
TcpIp_SocketAdmin[SocketId].socketState = TCPIP_SOCKET_UDP_READY;
}
}
#endif
return result;
}
/**
* @brief By this API service the TCP/IP stack is requested to establish a TCP connection to
* the configured peer.
* @param SocketId - Socket handle identifying the local socket resource
* @param RemoteAddrPtr - IP address and port of the remote host to connect to.
* @return result of the function.
*/
/** @req 4.2.2/SWS_TCPIP_00022 */
Std_ReturnType TcpIp_TcpConnect(TcpIp_SocketIdType SocketId, const TcpIp_SockAddrType* RemoteAddrPtr){
Std_ReturnType result = E_NOT_OK;
#ifndef _WIN32
struct sockaddr_in socketAddress;
//uint16 length;
int conRes;
/** @req 4.2.2/SWS_TCPIP_00129 */
VALIDATE( (NULL != RemoteAddrPtr), TCPIP_TCPCONNECT_SERVICE_ID, TCPIP_E_PARAM_POINTER)
socketAddress.sin_family = RemoteAddrPtr->domain;
socketAddress.sin_port = htons(RemoteAddrPtr->port);
//length = (RemoteAddrPtr->domain == TCPIP_AF_INET6 ? TCPIP_SA_DATA_SIZE_IPV6:TCPIP_SA_DATA_SIZE_IPV4);
//TcpIp_IpAddr8to32(RemoteAddrPtr->addr, &socketAddress.sin_addr.s_addr);
inet_aton(RemoteAddrPtr->addr, &socketAddress.sin_addr);
/** @req 4.2.2/SWS_TCPIP_00112 */
conRes = connect(TcpIp_SocketAdmin[SocketId].socketHandle, (struct sockaddr *)&socketAddress, sizeof(struct sockaddr));
if(0 == conRes){
result = E_OK;
TcpIp_SocketAdmin[SocketId].socketState = TCPIP_SOCKET_TCP_READY;
/* Call upper layer */
if(TcpIp_Config.Config.SocketOwnerConfig.SocketOwnerList[TcpIp_SocketAdmin[SocketId].socketOwnerId].SocketOwnerTcpConnectedFncPtr != NULL){
TcpIp_Config.Config.SocketOwnerConfig.SocketOwnerList[TcpIp_SocketAdmin[SocketId].socketOwnerId].SocketOwnerTcpConnectedFncPtr(SocketId);
}
}
#endif
return result;
}
/**
* @brief By this API service the TCP/IP stack is requested to listen on the
* TCP socket specified by the socket identifier.
* @param SocketId - Socket handle identifying the local socket resource
* @param MaxChannels - Maximum number of new parallel connections established on
* this listen connection.
* @return result of the function.
*/
/** @req 4.2.2/SWS_TCPIP_00023 */
Std_ReturnType TcpIp_TcpListen(TcpIp_SocketIdType SocketId, uint16 MaxChannels){
Std_ReturnType result = E_OK;
/** @req 4.2.2/SWS_TCPIP_00113 */
/** @req 4.2.2/SWS_TCPIP_00114 */
#ifndef _WIN32
listen(TcpIp_SocketAdmin[SocketId].socketHandle, MaxChannels);
#endif
TcpIp_SocketAdmin[SocketId].socketState = TCPIP_SOCKET_TCP_LISTENING;
return result;
}
/**
* @brief By this API service the reception of socket data is confirmed to the TCP/IP stack.
* @param SocketId - Socket handle identifying the local socket resource
* @param Length - Number of bytes finally consumed by the upper layer.
* @return result of the function.
*/
/** !req 4.2.2/SWS_TCPIP_00024 */
Std_ReturnType TcpIp_TcpReceived(TcpIp_SocketIdType SocketId, uint32 Length){
Std_ReturnType result = E_OK;
// Dont really understand the use...
return result;
}
/**
* @brief By this API service the TCP/IP stack is requested to change the TcpIp state of the
* communication network identified by EthIf controller index.
* @param CtrlIdx - EthIf controller index to identify the communication network
* where the TcpIp state is requested.
* @param State - Requested TcpIp state.
* @return result of the function.
*/
/** @req 4.2.2/SWS_TCPIP_00070 */
Std_ReturnType TcpIp_RequestComMode( uint8 CtrlIdx, TcpIp_StateType State ){
Std_ReturnType result = E_NOT_OK;
VALIDATE(CtrlIdx < TCPIP_NOF_CONTROLLERS, TCPIP_REQUESTCOMMODE_SERVICE_ID, TCPIP_E_INV_ARG)
/** @req 4.2.2/SWS_TCPIP_00136 */
if(State != TcpIp_CtrlAdmin[CtrlIdx].tcpipEthIfCtrlState){
switch (State) {
case TCPIP_STATE_OFFLINE:
/** @req 4.2.2/SWS_TCPIP_00072 */
//initiate deactivation of the TcpIp communication on the related EthIf controller
//(e.g. close all sockets using the specified EthIf controller
result = E_OK;
break;
case TCPIP_STATE_ONLINE:
/** @req 4.2.2/SWS_TCPIP_00071 */
//initiate activation of the TcpIp communication on the related EthIf controller (e.g.
//start IP-Address assignment according to the configured IP address assignment
//policy for the EthIf controller)
result = E_OK;
break;
case TCPIP_STATE_ONHOLD:
/** @req 4.2.2/SWS_TCPIP_00074 */
//set the TcpIp communication to on hold, i.e. new transmit requests shall not be
//accepted, but sockets and assigned IP addresses shall be kept
if(TcpIp_CtrlAdmin[CtrlIdx].tcpipEthIfCtrlState == TCPIP_STATE_ONLINE){
result = E_OK; /* Can only request onhold from online */
}
break;
default:
/** @req 4.2.2/SWS_TCPIP_00089 */
TCPIP_DET_REPORTERROR(TCPIP_REQUESTCOMMODE_SERVICE_ID, TCPIP_E_INV_ARG);
break;
}
}else{
/* IMPROVEMENT shall we respond E_OK when a request for the already active state is made? */
result = E_OK;
}
if(result == E_OK){
TcpIp_CtrlAdmin[CtrlIdx].tcpipEthIfRequestedCtrlState = State;
}
return result;
}
Std_ReturnType TcpIp_AutomaticIpAddrAssignment(TcpIp_LocalAddrIdType LocalAddrId, TcpIp_IpAddrAssignmentType Type){
Std_ReturnType result = E_OK;
logger(LOG_INFO, "TcpIp_AutomaticIpAddrAssignment TcpIp_LocalAddrIdType %d", LocalAddrId);
return result;
}
/**
* @brief By this API service the TCP/IP stack is requested to change a parameter of a socket.
* @param SocketId - Socket handle identifying the local socket resource
* @param ParameterId - Identifier of the parameter to be changed
* @param ParameterValue - Pointer to memory containing the new parameter value.
* @return result of the function.
*/
/** @req 4.2.2/SWS_TCPIP_00016 */
Std_ReturnType TcpIp_ChangeParameter(TcpIp_SocketIdType SocketId, TcpIp_ParamIdType ParameterId, const uint8* ParameterValue){
Std_ReturnType result = E_OK;
#ifndef _WIN32
/** @req 4.2.2/SWS_TCPIP_00119 */
switch (ParameterId)
{
case TCPIP_PARAMID_TCP_RXWND_MAX:
break;
case TCPIP_PARAMID_FRAMEPRIO:
break;
case TCPIP_PARAMID_TCP_NAGLE:
{
int on = 1;
setsockopt(TcpIp_SocketAdmin[SocketId].socketHandle, IPPROTO_TCP, TCP_NODELAY, &on, sizeof(int)); // Set socket to no delay
//ioctlsocket(TcpIp_SocketAdmin[SocketId].socketHandle, FIONBIO, &on);
// The POSIX way to do the above
int flags = fcntl(TcpIp_SocketAdmin[SocketId].socketHandle, F_GETFL, 0);
fcntl(TcpIp_SocketAdmin[SocketId].socketHandle, F_SETFL, flags | O_NONBLOCK);
}
break;
case TCPIP_PARAMID_TCP_KEEPALIVE:
break;
case TCPIP_PARAMID_TTL:
break;
case TCPIP_PARAMID_TCP_KEEPALIVE_TIME:
break;
case TCPIP_PARAMID_TCP_KEEPALIVE_PROBES_MAX:
break;
case TCPIP_PARAMID_TCP_KEEPALIVE_INTERVAL:
break;
case TCPIP_PARAMID_VENDOR_SPECIFIC:
break;
default:
break;
}
#endif
return result;
}
/**
* * @brief By this API service the local IP address assignment for the IP address specified by
* * LocalAddrId shall be initiated.
* * @param LocalAddrId - IP address index specifying the IP address for which an
* * assignment shall be initiated.
* * @param Type - Type of IP address assignment which shall be initiated
* * @param LocalIpAddrPtr - Pointer to structure containing the IP address which shall be
* * assigned to the EthIf controller indirectly specified via LocalAddrId.
* * @param Netmask - Network mask of IPv4 address or address prefix of IPv6 address in CIDR Notation.
* * @param DefaultRouterPtr - Pointer to structure containing the IP address of the default router
* * (gateway) which shall be assigned.
* * @return result of the function.
* */
/** @req 4.2.2/SWS_TCPIP_00037 */
Std_ReturnType TcpIp_RequestIpAddrAssignment(TcpIp_LocalAddrIdType LocalAddrId, TcpIp_IpAddrAssignmentType Type,
const TcpIp_SockAddrType* LocalIpAddrPtr, uint8 Netmask, const TcpIp_SockAddrType* DefaultRouterPtr){
Std_ReturnType result = E_OK;
// IMPROVEMENT SimonG
return result;
}
/**
* * @brief By this API service the local IP address assignment for the IP address specified by
* * LocalAddrId shall be released.
* * @param LocalAddrId - IP address index specifying the IP address for which an
* * assignment shall be released.
* * @return result of the function.
* */
/** !req 4.2.2/SWS_TCPIP_00078 */
Std_ReturnType TcpIp_ReleaseIpAddrAssignment(TcpIp_LocalAddrIdType LocalAddrId){
Std_ReturnType result = E_OK;
// IMPROVEMENT SimonG
return result;
}
/**
* @brief Obtains the local IP address actually used by LocalAddrId, the netmask and
default router
* @param LocalAddrId - Local address identifier referring to the local IP address which
* shall be obtained.
* @param IpAddrPtr - Pointer to a struct where the IP address shall be stored.
* @param NetmaskPtr - Pointer to memory where Network mask of IPv4 address or
* address prefix of IPv6 address in CIDR Notation is stored
* @param DefaultRouterPtr - Pointer to struct where the IP address of the default router
* (gateway) is stored (struct member "port" is not used and of
* arbitrary value).
* @return result of the function.
*/
/** @req 4.2.2/SWS_TCPIP_00032 */
Std_ReturnType TcpIp_GetIpAddr(TcpIp_LocalAddrIdType LocalAddrId, TcpIp_SockAddrType* IpAddrPtr,
uint8* NetmaskPtr, TcpIp_SockAddrType* DefaultRouterPtr){
Std_ReturnType result = E_OK;
const TcpIp_LocalAddrType *ptrLocalAddr = &TcpIp_Config.Config.LocalAddrList[getLocalAddrListConfigIdx(LocalAddrId)];
/** @req 4.2.2/SWS_TCPIP_00205 */
VALIDATE(IpAddrPtr->domain == ptrLocalAddr->Domain, TCPIP_GETIPADDR_SERVICE_ID, TCPIP_E_INV_ARG);
/** @req 4.2.2/SWS_TCPIP_00206 */
VALIDATE(DefaultRouterPtr->domain == IpAddrPtr->domain, TCPIP_GETIPADDR_SERVICE_ID, TCPIP_E_INV_ARG);
TcpIp_IpAddr32To8(ptrLocalAddr->StaticIpAddrConfig->StaticIpAddress, IpAddrPtr->addr);
TcpIp_IpAddr32To8(ptrLocalAddr->StaticIpAddrConfig->DefaultRouter, DefaultRouterPtr->addr);
return result;
}
/**
* @brief Obtains the physical source address used by the EthIf controller implicitly
* specified via LocalAddrId.
* @param LocalAddrId - Local address identifier referring to the local IP address which
* shall be obtained.
* @param PhysAddrPtr - Pointer to the memory where the physical source address (MAC
* address) in network byte order is stored
* @return result of the function.
*/
/** @req 4.2.2/SWS_TCPIP_00033 */
Std_ReturnType TcpIp_GetPhysAddr(TcpIp_LocalAddrIdType LocalAddrId, uint8* PhysAddrPtr){
Std_ReturnType result = E_OK;
const TcpIp_LocalAddrType *ptrLocalAddr = &TcpIp_Config.Config.LocalAddrList[getLocalAddrListConfigIdx(LocalAddrId)];
EthIf_GetPhysAddr(ptrLocalAddr->TcpIpCtrlRef, PhysAddrPtr);
return result;
}
/**
* @brief TcpIp_GetCtrlIdx returns the index of the controller related to LocalAddrId.
* @param LocalAddrId - Local address identifier referring to the local IP address which
* shall be obtained.
* @param CtrlIdxPtr - Pointer to the memory where the index of the controller related to
* LocalAddrId is stored
* @return result of the function.
*/
/** @req 4.2.2/SWS_TCPIP_00140 */
Std_ReturnType TcpIp_GetCtrlIdx(TcpIp_LocalAddrIdType LocalAddrId, uint8* CtrlIdxPtr){
Std_ReturnType result = E_OK;
/** @req 4.2.2/SWS_TCPIP_00141 */
const TcpIp_LocalAddrType *ptrLocalAddr = &TcpIp_Config.Config.LocalAddrList[getLocalAddrListConfigIdx(LocalAddrId)];
*CtrlIdxPtr = ptrLocalAddr->TcpIpCtrlRef;
return result;
}
/**
* @brief This service transmits data via UDP to a remote node. The transmission of the
* data is immediately performed with this function call by forwarding it to EthIf.
* @param SocketId - Socket handle identifying the local socket resource
* @param DataPtr - Pointer to a linear buffer of TotalLength bytes containing the
* data to be transmitted.
* In case DataPtr is a NULL_PTR, TcpIp shall retrieve data from
* upper layer via callback <Up>_CopyTxData().
* @param RemoteAddrPtr - IP address and port of the remote host to transmit to.
* @param TotalLength - indicates the payload size of the UDP datagram.
* @return result of the function.
*/
/** @req 4.2.2/SWS_TCPIP_00025 */
Std_ReturnType TcpIp_UdpTransmit(TcpIp_SocketIdType SocketId, const uint8* DataPtr, const TcpIp_SockAddrType* RemoteAddrPtr, uint16 TotalLength){
Std_ReturnType result = E_OK;
BufReq_ReturnType bufres;
Eth_FrameType frameType = 0x0800;
uint8* bufPtr;
Eth_BufIdxType bufIdx;
uint8 priority = 0;
uint8 ctrlIdx;
uint16 len = TotalLength;
/* Added some protection even though not specified */
VALIDATE( (SocketId < TCPIP_MAX_NOF_SOCKETS), TCPIP_UDPTRANSMIT_SERVICE_ID, TCPIP_E_INV_ARG)
VALIDATE( (TcpIp_SocketAdmin[SocketId].socketHandle >= 0), TCPIP_UDPTRANSMIT_SERVICE_ID, TCPIP_E_NOTCONN)
//ctrlIdx = TcpIp_SocketAdmin[SocketId].ptrLocalAddr->TcpIpCtrlRef;
ctrlIdx = 0;
/** @req 4.2.2/SWS_TCPIP_00120 */
//EthIf_GetPhysAddr(ctrlIdx,physAddr);
bufres = EthIf_ProvideTxBuffer( ctrlIdx, frameType, priority, &bufIdx, &bufPtr, &len);
/** @req 4.2.2/SWS_TCPIP_00121 */
if(bufres == BUFREQ_OK){
if(DataPtr == NULL){
/* Copy data callback to upper layer */
if(TcpIp_Config.Config.SocketOwnerConfig.SocketOwnerList[TcpIp_SocketAdmin[SocketId].socketOwnerId].SocketOwnerCopyTxDataFncPtr != NULL){
TcpIp_Config.Config.SocketOwnerConfig.SocketOwnerList[TcpIp_SocketAdmin[SocketId].socketOwnerId].SocketOwnerCopyTxDataFncPtr(SocketId, bufPtr, len);
}
}else{
memcpy(bufPtr,DataPtr,len);
}
/** @req 4.2.2/SWS_TCPIP_00122 */
if(TcpIp_SocketAdmin[SocketId].socketState == TCPIP_SOCKET_BIND){
/* IMPROVEMENT Do we need to do anything here???
* Not been bind to an address, use local ip address and port */
}
uint16 bytesSent = TcpIp_SendIpMessage(TcpIp_SocketAdmin[SocketId].socketHandle, bufPtr, RemoteAddrPtr, TotalLength);
TcpIp_BufferFree(bufPtr);// IMPROVEMENT temp, remove with correct EthIf
/* Same result setting as in OSEK TcpIp.c */
if (bytesSent == 0) {
result = E_NOT_OK;
}
if(TcpIp_Config.Config.SocketOwnerConfig.SocketOwnerList[TcpIp_SocketAdmin[SocketId].socketOwnerId].SocketOwnerTxConfirmationFncPtr != NULL){
TcpIp_Config.Config.SocketOwnerConfig.SocketOwnerList[TcpIp_SocketAdmin[SocketId].socketOwnerId].SocketOwnerTxConfirmationFncPtr(SocketId,bytesSent);
}
}else{
result = E_NOT_OK;
}
return result;
}
/**
* @brief This service requests transmission of data via TCP to a remote node. The
* transmission of the data is decoupled.
* @param SocketId - Socket handle identifying the local socket resource
* @param DataPtr - Pointer to a linear buffer of TotalLength bytes containing the
* data to be transmitted.
* In case DataPtr is a NULL_PTR, TcpIp shall retrieve data from
* upper layer via callback <Up>_CopyTxData().
* @param AvailableLength - Available data for transmission in bytes.
* @param ForceRetrieve - This parameter is only valid if DataPtr is a NULL_PTR.
* Indicates how the TCP/IP stack retrieves data from upper layer if
* DataPtr is a NULL_PTR.
* TRUE: the whole data indicated by availableLength shall be
* retrieved from the upper layer via one or multiple
* <Up>_CopyTxData() calls within the context of this transmit
* function.
* FALSE: The TCP/IP stack may retrieve up to availableLength
* data from the upper layer. It is allowed to retrieve less than
* availableLength bytes. Note: Not retrieved data will be provided
* by upper layer with the next call to TcpIp_TcpTransmit (along with
* new data if available).
* @return result of the function.
*/
/** !req 4.2.2/SWS_TCPIP_00050 */
Std_ReturnType TcpIp_TcpTransmit(TcpIp_SocketIdType SocketId, const uint8* DataPtr, uint32 AvailableLength,
boolean ForceRetrieve){
Std_ReturnType result = E_OK;
BufReq_ReturnType bufres;
Eth_FrameType frameType = 0x0800;
uint8* bufPtr;
Eth_BufIdxType bufIdx;
uint8 priority = 0;
uint8 ctrlIdx;
uint16 len = AvailableLength;
/* Added some protection even though not specified */
VALIDATE( (SocketId < TCPIP_MAX_NOF_SOCKETS), TCPIP_TCPTRANSMIT_SERVICE_ID, TCPIP_E_INV_ARG)
VALIDATE( (TcpIp_SocketAdmin[SocketId].socketHandle >= 0), TCPIP_TCPTRANSMIT_SERVICE_ID, TCPIP_E_NOTCONN)
//ctrlIdx = TcpIp_SocketAdmin[SocketId].ptrLocalAddr->TcpIpCtrlRef;
ctrlIdx = 0;
/** @req 4.2.2/SWS_TCPIP_00120 */
//EthIf_GetPhysAddr(ctrlIdx,physAddr);
bufres = EthIf_ProvideTxBuffer( ctrlIdx, frameType, priority, &bufIdx, &bufPtr, &len);
/** @req 4.2.2/SWS_TCPIP_00121 */
if(bufres == BUFREQ_OK){
if(DataPtr == NULL){
/* Copy data callback to upper layer */
if(TcpIp_Config.Config.SocketOwnerConfig.SocketOwnerList[TcpIp_SocketAdmin[SocketId].socketOwnerId].SocketOwnerCopyTxDataFncPtr != NULL){
TcpIp_Config.Config.SocketOwnerConfig.SocketOwnerList[TcpIp_SocketAdmin[SocketId].socketOwnerId].SocketOwnerCopyTxDataFncPtr(SocketId, bufPtr, len);
}
}else{
memcpy(bufPtr,DataPtr,len);
}
uint16 bytesSent = TcpIp_SendIpMessage(TcpIp_SocketAdmin[SocketId].socketHandle, bufPtr, NULL, AvailableLength);
TcpIp_BufferFree(bufPtr);// IMPROVEMENT temp, remove with correct EthIf
/* Same result setting as in OSEK TcpIp.c */
if (bytesSent == 0) {
result = E_NOT_OK;
}
if(TcpIp_Config.Config.SocketOwnerConfig.SocketOwnerList[TcpIp_SocketAdmin[SocketId].socketOwnerId].SocketOwnerTxConfirmationFncPtr != NULL){
TcpIp_Config.Config.SocketOwnerConfig.SocketOwnerList[TcpIp_SocketAdmin[SocketId].socketOwnerId].SocketOwnerTxConfirmationFncPtr(SocketId,bytesSent);
}
}else{
result = E_NOT_OK;
}
return result;
}
/**
* @brief By this API service the TCP/IP stack gets an indication and the data of a received frame.
* @param CtrlIdx - Index of the EthIf controller.
* @param FrameType - Frame type of received Ethernet frame
* @param IsBroadcast - Parameter to indicate a broadcast frame
* @param PhysAddrPtr - Pointer to Physical source address (MAC address in network byte
* order) of received Ethernet frame
* @param DataPtr - Pointer to payload of the received Ethernet frame (i.e. Ethernet
* header is not provided).
* @param LenByte - Length of received data.
* @return void
*/
/** !req 4.2.2/SWS_TCPIP_00029 */
void TcpIp_RxIndication(uint8 CtrlIdx, Eth_FrameType FrameType, boolean IsBroadcast, const uint8* PhysAddrPtr,
uint8* DataPtr, uint16 LenByte){
}
static void TcpIp_NotifyLocalIpAddrAssignmentChg(uint8 CtrlIdx, TcpIp_IpAddrStateType ipAddrState)
{
/* Call upper layer */
for(int LocalAddrId=0; LocalAddrId < TCPIP_NOF_LOCALADDR; LocalAddrId++){
const TcpIp_LocalAddrType *ptrLocalAddr = &TcpIp_Config.Config.LocalAddrList[getLocalAddrListConfigIdx(LocalAddrId)];
if(ptrLocalAddr->TcpIpCtrlRef == CtrlIdx)
{
for(int Idx=0; Idx < TCPIP_NOF_SOCKETOWNERS; Idx++){
if(TcpIp_Config.Config.SocketOwnerConfig.SocketOwnerList[Idx].SocketOwnerLocalIpAddrAssignmentChgFncPtr != NULL){
TcpIp_Config.Config.SocketOwnerConfig.SocketOwnerList[Idx].SocketOwnerLocalIpAddrAssignmentChgFncPtr(ptrLocalAddr->AddressId, ipAddrState);
}
}
}
}
}
static void TcpIp_EnableAllIpAddrAssignments(uint8 CtrlIdx){
char addr[INET_ADDRSTRLEN];
char route[INET_ADDRSTRLEN];
/* We initiate all unicast first and then any multicast. We assume there is only one */
for(int i=0; i<TCPIP_NOF_LOCALADDR;i++){
const TcpIp_LocalAddrType *ptrLocalAddr = &TcpIp_Config.Config.LocalAddrList[i];
if((ptrLocalAddr->TcpIpCtrlRef == CtrlIdx) && (ptrLocalAddr->AddressAssignment->AssignmentTrigger == TCPIP_AUTOMATIC) && (ptrLocalAddr->AddressType == TCPIP_UNICAST)){
TcpIp_AutomaticIpAddrAssignment(ptrLocalAddr->AddressId, ptrLocalAddr->AddressAssignment->AssignmentMethod);
TcpIp_IpAddrToChar((char *)&addr, ptrLocalAddr->StaticIpAddrConfig->StaticIpAddress);
TcpIp_IpAddrToChar((char *)&route, ptrLocalAddr->StaticIpAddrConfig->DefaultRouter);
logger(LOG_INFO, "TcpIp_EnableAllIpAddrAssignments AUTOMATIC \t\tA[%s/%d]\tR[%s]\tfor AddressId %d",
addr, ptrLocalAddr->StaticIpAddrConfig->Netmask, route,
ptrLocalAddr->AddressId
);
}
}
for(int i=0; i<TCPIP_NOF_LOCALADDR;i++){
const TcpIp_LocalAddrType *ptrLocalAddr = &TcpIp_Config.Config.LocalAddrList[i];
if((ptrLocalAddr->TcpIpCtrlRef == CtrlIdx) && (ptrLocalAddr->AddressAssignment->AssignmentTrigger == TCPIP_AUTOMATIC) && (ptrLocalAddr->AddressType == TCPIP_MULTICAST)){
TcpIp_AutomaticIpAddrAssignment(ptrLocalAddr->AddressId, ptrLocalAddr->AddressAssignment->AssignmentMethod);
TcpIp_IpAddrToChar((char *)&addr, ptrLocalAddr->StaticIpAddrConfig->StaticIpAddress);
TcpIp_IpAddrToChar((char *)&route, ptrLocalAddr->StaticIpAddrConfig->DefaultRouter);
logger(LOG_INFO, "TcpIp_EnableAllIpAddrAssignments Multicast \t\tA[%s/%d]\tR[%s]\tfor AddressId %d",
addr, ptrLocalAddr->StaticIpAddrConfig->Netmask, route,
ptrLocalAddr->AddressId
);
}
}
}
static void TcpIp_HandleStateOffline(uint8 CtrlIdx)
{
/* IMPROVEMENT SimonG use status of ethernet link */
TcpIp_CtrlAdmin[CtrlIdx].tcpipEthIfRequestedCtrlState = TCPIP_STATE_ONLINE;
logger(LOG_INFO, "TcpIp_HandleStateOffline CtrlIdx %d",
CtrlIdx);
if(TcpIp_CtrlAdmin[CtrlIdx].tcpipEthIfRequestedCtrlState == TCPIP_STATE_ONLINE){
/** @req 4.2.2/SWS_TCPIP_00075 */
/* If TCPIP_STATE_ONLINE is requested for an EthIf
controller and the current state is TCPIP_STATE_OFFLINE for that EthIf controller,
the TcpIp module shall
(a) enable all IP address assignments according to the configured assignment
methods (TcpIpAssignmentMethod) and triggers (TcpIpAssignmentTrigger) for
that EthIf controller. (Note: If the assignment trigger is configured to
TCPIP_MANUAL no assignment is actually performed but initiation by the upper
layer enabled) and */
TcpIp_EnableAllIpAddrAssignments(CtrlIdx);
/* (b) enter the state TCPIP_STATE_STARTUP for the EthIf controller.⌋ */
TcpIp_SwitchEthIfCtrlState(CtrlIdx, TCPIP_STATE_STARTUP);
}
else if(TcpIp_CtrlAdmin[CtrlIdx].tcpipEthIfRequestedCtrlState == TCPIP_STATE_ONHOLD){
/* Invalid statechange, report error and reset request */
TCPIP_DET_REPORTERROR(TCPIP_MAINFUNCTION_SERVICE_ID, TCPIP_E_ARC_ILLEGAL_STATE);
TcpIp_CtrlAdmin[CtrlIdx].tcpipEthIfRequestedCtrlState = TCPIP_STATE_OFFLINE;
}
}
static void TcpIp_HandleStateOnline(uint8 CtrlIdx)
{
if(TcpIp_CtrlAdmin[CtrlIdx].tcpipEthIfRequestedCtrlState == TCPIP_STATE_OFFLINE){
/** @req 4.2.2/SWS_TCPIP_00077 */
/* If TCPIP_STATE_OFFLINE is requested or all assigned IP
address have been released for an EthIf controller and the current state is
TCPIP_STATE_ONLINE or TCPIP_STATE_ONHOLD for that EthIf controller, the
TcpIp module shall */
/* (a) call Up_LocalIpAddrAssignmentChg() with State
TCPIP_IPADDR_STATE_UNASSIGNED for all assigned IP addresses of the
related EthIf controller, */
TcpIp_NotifyLocalIpAddrAssignmentChg(CtrlIdx, TCPIP_IPADDR_STATE_UNASSIGNED);
/* (b) deactivate the communication within the TcpIp module for the related EthIf
controller, */
/* (c) release related resources, i.e. any socket using the EthIf controller shall be
closed and thereafter any IP address assigned to the EthIf controller shall be
unassigned,*/
for(int SocketId=0; SocketId < TCPIP_MAX_NOF_SOCKETS; SocketId++){
if((TcpIp_SocketAdmin[SocketId].ptrLocalAddr != NULL) && (TcpIp_SocketAdmin[SocketId].ptrLocalAddr->TcpIpCtrlRef == CtrlIdx))
{
TcpIp_Close(SocketId,FALSE);
}
}
/* (d) in case the no EthIf controller is assigned any more, all unbound sockets shall
be released as well */
boolean otherCtrls = FALSE;
for(int SocketId=0; SocketId < TCPIP_MAX_NOF_SOCKETS; SocketId++){
if(TcpIp_SocketAdmin[SocketId].ptrLocalAddr != NULL){
/* There are sockets assigned to other ctrl's */
otherCtrls = TRUE;
break;
}
}
if(otherCtrls == FALSE){
/* There are no other assigned controllers, release all unbound sockets */
for(int SocketId=0; SocketId < TCPIP_MAX_NOF_SOCKETS; SocketId++){
if(TcpIp_SocketAdmin[SocketId].socketHandle >= 0){
TcpIp_Close(SocketId,FALSE);
}
}
}
/* (e) enter the state TCPIP_STATE_SHUTDOWN for the EthIf controller. */
TcpIp_SwitchEthIfCtrlState(CtrlIdx, TCPIP_STATE_SHUTDOWN);
}
else if(TcpIp_CtrlAdmin[CtrlIdx].tcpipEthIfRequestedCtrlState == TCPIP_STATE_ONHOLD){
/** @req 4.2.2/SWS_TCPIP_00076 */
/* If TCPIP_STATE_ONHOLD is requested for an EthIf
controller and the current state is TCPIP_STATE_ONLINE for that EthIf controller,
the TcpIp module shall
(a) notify the upper layer via Up_LocalIpAddrAssignmentChg() with State
TCPIP_IPADDR_STATE_ONHOLD for all assigned IP addresses of the
related EthIf controller, and */
TcpIp_NotifyLocalIpAddrAssignmentChg(CtrlIdx, TCPIP_IPADDR_STATE_ONHOLD);
/* (b) deactivate the communication within the TcpIp module for the related EthIf
controller, and */
// IMPROVEMENT SimonG
//netif_set_down(&TcpIp_CtrlAdmin[CtrlIdx].tcpipNetif);
/* (c) enter the state TCPIP_STATE_ONHOLD for the EthIf controller.*/
TcpIp_SwitchEthIfCtrlState(CtrlIdx, TCPIP_STATE_ONHOLD);
}
}
static void TcpIp_HandleStateOnhold(uint8 CtrlIdx)
{
if(TcpIp_CtrlAdmin[CtrlIdx].tcpipEthIfRequestedCtrlState == TCPIP_STATE_OFFLINE){
/** @req 4.2.2/SWS_TCPIP_00077 */
TcpIp_SwitchEthIfCtrlState(CtrlIdx, TCPIP_STATE_SHUTDOWN);
}
else if(TcpIp_CtrlAdmin[CtrlIdx].tcpipEthIfRequestedCtrlState == TCPIP_STATE_ONLINE){
/** @req 4.2.2/SWS_TCPIP_00086 */
/* If TCPIP_STATE_ONLINE is requested for an EthIf
controller and the current state is TCPIP_STATE_ONHOLD for that EthIf controller,
the TcpIp module shall
(a) reactivate the communication within the TcpIp module for the related EthIf
controller, */
// IMPROVEMENT SimonG
//netif_set_up(&TcpIp_CtrlAdmin[CtrlIdx].tcpipNetif);
/* (b) call Up_LocalIpAddrAssignmentChg() with State
TCPIP_IPADDR_STATE_ASSIGNED for all assigned IP addresses of the
related EthIf controller, and */
TcpIp_NotifyLocalIpAddrAssignmentChg(CtrlIdx, TCPIP_IPADDR_STATE_ASSIGNED);
/* (c) enter the state TCPIP_STATE_ONLINE for the EthIf controller. */
TcpIp_SwitchEthIfCtrlState(CtrlIdx, TCPIP_STATE_ONLINE);
}
}
static void TcpIp_HandleStateStartup(uint8 CtrlIdx)
{
/** @req 4.2.2/SWS_TCPIP_00088 */
if(TcpIp_CtrlAdmin[CtrlIdx].tcpipEthIfRequestedCtrlState == TCPIP_STATE_OFFLINE){
/* If TCPIP_STATE_OFFLINE is requested for an EthIf
controller and the current state is TCPIP_STATE_STARTUP for that EthIf controller,
the TcpIp module shall
(a) abort all ongoing IP address assignment actions appropriate and */
#if LWIP_AUTOIP
autoip_stop(&TcpIp_CtrlAdmin[CtrlIdx].tcpipNetif);
#endif
#if LWIP_DHCP
dhcp_stop(&TcpIp_CtrlAdmin[CtrlIdx].tcpipNetif);
#endif
// IMPROVEMENT SimonG
//netif_set_down(&TcpIp_CtrlAdmin[CtrlIdx].tcpipNetif);
logger (LOG_INFO, "TcpIp_HandleStateStartup Aborting TCPIP_STATE_STARTUP going down.");
/* (b) enter the state TCPIP_STATE_OFFLINE for the EthIf controller. */
TcpIp_SwitchEthIfCtrlState(CtrlIdx, TCPIP_STATE_OFFLINE);
}
else if(TcpIp_CtrlAdmin[CtrlIdx].tcpipEthIfRequestedCtrlState == TCPIP_STATE_ONLINE){
/** @req 4.2.2/SWS_TCPIP_00085 */
/* If at least one IP address has been successfully assigned to
an EthIf controller and the current state is TCPIP_STATE_STARTUP for that EthIf
controller, the TcpIp module shall enter the state TCPIP_STATE_ONLINE for the
EthIf controller.*/
// IMPROVEMENT SimonG
logger (LOG_INFO, "TcpIp_HandleStateStartup Going on-line");
//if(netif_is_link_up(&TcpIp_CtrlAdmin[CtrlIdx].tcpipNetif)){
/* (b) enter the state TCPIP_STATE_OFFLINE for the EthIf controller. */
TcpIp_SwitchEthIfCtrlState(CtrlIdx, TCPIP_STATE_ONLINE);
TcpIp_NotifyLocalIpAddrAssignmentChg(CtrlIdx, TCPIP_IPADDR_STATE_ASSIGNED);
//}
}
}
static void TcpIp_HandleStateShutdown(uint8 CtrlIdx)
{
/** @req 4.2.2/SWS_TCPIP_00087 */
/* If the current state of an EthIf controller is
TCPIP_STATE_SHUTDOWN and all related resources have been released, the
TcpIp module shall enter the state TCPIP_STATE_OFFLINE for the EthIf controller.*/
// IMPROVEMENT how to find out when done
TcpIp_SwitchEthIfCtrlState(CtrlIdx, TCPIP_STATE_OFFLINE);
}
static void TcpIp_HandleSocketStateListening(TcpIp_SocketIdType SocketId)
{
#ifndef _WIN32
int clientFd;
struct sockaddr_in clientAddr;
int addrlen = sizeof(clientAddr);
clientFd = accept(TcpIp_SocketAdmin[SocketId].socketHandle, (struct sockaddr *)&clientAddr, (uint32 *)&addrlen);
if( clientFd != (-1))
{
Std_ReturnType accepted = E_NOT_OK;
/** @req 4.2.2/SWS_TCPIP_00114 */
/* Derive a separate socket */
TcpIp_SocketIdType socketIdConn;
if(E_OK == TcpIp_GetFirstFreeSocket(&socketIdConn)){
TcpIp_SocketAdmin[socketIdConn].socketHandle = clientFd;
TcpIp_SocketAdmin[socketIdConn].remoteAddr.domain = clientAddr.sin_family;
TcpIp_SocketAdmin[socketIdConn].remoteAddr.port = clientAddr.sin_port;
//uint8 length = (clientAddr.sin_family == TCPIP_AF_INET6 ? TCPIP_SA_DATA_SIZE_IPV6:TCPIP_SA_DATA_SIZE_IPV4);
TcpIp_IpAddr32To8(clientAddr.sin_addr.s_addr, TcpIp_SocketAdmin[socketIdConn].remoteAddr.addr);
//TcpIp_SocketAdmin[socketIdConn].remoteAddr.addr = inet_ntoa(clientAddr.sin_addr.s_addr);
TcpIp_SocketAdmin[socketIdConn].socketOwnerId = TcpIp_SocketAdmin[SocketId].socketOwnerId;
/* Call upper layer for acceptance */
if(TcpIp_Config.Config.SocketOwnerConfig.SocketOwnerList[TcpIp_SocketAdmin[socketIdConn].socketOwnerId].SocketOwnerTcpAcceptedFncPtr != NULL){
accepted = TcpIp_Config.Config.SocketOwnerConfig.SocketOwnerList[TcpIp_SocketAdmin[socketIdConn].socketOwnerId].SocketOwnerTcpAcceptedFncPtr(SocketId, socketIdConn, &TcpIp_SocketAdmin[socketIdConn].remoteAddr);
}
if(E_OK == accepted){
TcpIp_SocketAdmin[socketIdConn].socketState = TCPIP_SOCKET_TCP_READY;
TcpIp_SocketAdmin[socketIdConn].socketProtocolIsTcp = TRUE;
//int on = 1;
//ioctlsocket(clientFd, FIONBIO, &on); // Set socket to non block mode
// The POSIX way to do the above
int flags = fcntl(clientFd, F_GETFL, 0);
fcntl(clientFd, F_SETFL, flags | O_NONBLOCK);
}else{
close(clientFd);
TcpIp_FreeUpSocket(socketIdConn);
}
}
else{
close(clientFd);
}
}
#endif
}
static void TcpIp_HandleSocketStateTcpReady(TcpIp_SocketIdType SocketId)
{
int nBytes;
uint8 *dataPtr;
/* Note: Even it is not shown in the sequence diagram of section 9.3, TcpIp may
decouple the data reception if required. E.g. for reassembling of incoming IP
datagrams that are fragmented, TcpIp shall copy the received data to a TcpIp buffer
and decouple TcpIp_RxIndication() from SoAd_RxIndication() */
if (TcpIp_BufferGet(TCPIP_RX_BUFFER_SIZE, &dataPtr)) {
#ifndef _WIN32
do {
nBytes = recv(TcpIp_SocketAdmin[SocketId].socketHandle, dataPtr, TCPIP_RX_BUFFER_SIZE, 0);
TcpIp_SocketStatusCheck(SocketId);
if (nBytes > 0){
/* Call upper layer */
if(TcpIp_Config.Config.SocketOwnerConfig.SocketOwnerList[TcpIp_SocketAdmin[SocketId].socketOwnerId].SocketOwnerRxIndicationFncPtr != NULL){
TcpIp_Config.Config.SocketOwnerConfig.SocketOwnerList[TcpIp_SocketAdmin[SocketId].socketOwnerId].SocketOwnerRxIndicationFncPtr(SocketId, &TcpIp_SocketAdmin[SocketId].remoteAddr, dataPtr, nBytes);
}
}
} while (nBytes > 0);
#endif
TcpIp_BufferFree(dataPtr);
}else{
/** @req 4.2.2/SWS_TCPIP_00089 */
TCPIP_DET_REPORTERROR(TCPIP_MAINFUNCTION_SERVICE_ID, TCPIP_E_NOBUFS);
}
}
static void TcpIp_HandleSocketStateUdpReady(TcpIp_SocketIdType SocketId)
{
#ifndef _WIN32
char toAddrString[INET_ADDRSTRLEN];
int nBytes;
uint8 *dataPtr;
struct sockaddr_in fromAddr;
uint32 fromAddrLen = sizeof(fromAddr);
/* Note: Even it is not shown in the sequence diagram of section 9.3, TcpIp may
decouple the data reception if required. E.g. for reassembling of incoming IP
datagrams that are fragmented, TcpIp shall copy the received data to a TcpIp buffer
and decouple TcpIp_RxIndication() from SoAd_RxIndication() */
if (TcpIp_BufferGet(TCPIP_RX_BUFFER_SIZE, &dataPtr)) {
do {
nBytes = recvfrom(TcpIp_SocketAdmin[SocketId].socketHandle, dataPtr, TCPIP_RX_BUFFER_SIZE, 0, (struct sockaddr*)&fromAddr, &fromAddrLen);
TcpIp_SocketStatusCheck(SocketId);
if (nBytes > 0){
/* Call upper layer */
TcpIp_IpAddrToChar((char *)&toAddrString, fromAddr.sin_addr.s_addr);
logger_mod ((LOGGER_MOD_TCP|LOGGER_SUB_TCP_RECV), LOG_INFO, "TcpIp_RecvIpMessage from %s:%d bytesRecv [%d]",
toAddrString, ntohs(fromAddr.sin_port),
nBytes);
if(TcpIp_Config.Config.SocketOwnerConfig.SocketOwnerList[TcpIp_SocketAdmin[SocketId].socketOwnerId].SocketOwnerRxIndicationFncPtr != NULL){
TcpIp_Config.Config.SocketOwnerConfig.SocketOwnerList[TcpIp_SocketAdmin[SocketId].socketOwnerId].SocketOwnerRxIndicationFncPtr(SocketId, &TcpIp_SocketAdmin[SocketId].remoteAddr, dataPtr, nBytes);
}
}
} while (nBytes > 0);
TcpIp_BufferFree(dataPtr);
}else{
/** @req 4.2.2/SWS_TCPIP_00089 */
TCPIP_DET_REPORTERROR(TCPIP_MAINFUNCTION_SERVICE_ID, TCPIP_E_NOBUFS);
}
#endif
}
/**
* @brief TcpIp main function.
* @param void
* @return void
*/
/** @req 4.2.2/SWS_TCPIP_00026 */
void TcpIp_MainFunction(void){
for(int CtrlIdx=0; CtrlIdx < TCPIP_NOF_CONTROLLERS; CtrlIdx++)
{
/** @req 4.2.2/SWS_TCPIP_00026 */
switch (TcpIp_CtrlAdmin[CtrlIdx].tcpipEthIfCtrlState) {
case TCPIP_STATE_OFFLINE:
TcpIp_HandleStateOffline(CtrlIdx);
//IMPROVEMENT Simon G
// We are always online!
//TcpIp_CtrlAdmin[CtrlIdx].tcpipEthIfRequestedCtrlState = TCPIP_STATE_ONLINE;
//TcpIp_CtrlAdmin[CtrlIdx].tcpipEthIfCtrlState = TCPIP_STATE_STARTUP;
break;
case TCPIP_STATE_ONLINE:
TcpIp_HandleStateOnline(CtrlIdx);
break;
case TCPIP_STATE_ONHOLD:
TcpIp_HandleStateOnhold(CtrlIdx);
break;
case TCPIP_STATE_STARTUP:
TcpIp_HandleStateStartup(CtrlIdx);
break;
case TCPIP_STATE_SHUTDOWN:
TcpIp_HandleStateShutdown(CtrlIdx);
break;
default:
/* Should not happen. Let us have an DET error */
TCPIP_DET_REPORTERROR(TCPIP_MAINFUNCTION_SERVICE_ID, TCPIP_E_ARC_ILLEGAL_STATE);
break;
}
}
for (int i = 0; i < TCPIP_MAX_NOF_SOCKETS; i++) {
switch (TcpIp_SocketAdmin[i].socketState) {
case TCPIP_SOCKET_TCP_LISTENING:
TcpIp_HandleSocketStateListening(i);
break;
case TCPIP_SOCKET_TCP_READY:
TcpIp_HandleSocketStateTcpReady(i);
break;
case TCPIP_SOCKET_UDP_READY:
TcpIp_HandleSocketStateUdpReady(i);
break;
default:
/* Do nothing */
break;
}
}
}
|
2301_81045437/classic-platform
|
communication/TcpIp/src/TcpIp_Linos.c
|
C
|
unknown
| 62,100
|
#TCPIP
ifeq ($(CFG_GNULINUX),y)
obj-$(USE_TCPIP)-$(CFG_GNULINUX) += TcpIp_Linos.o
inc-$(USE_TCPIP)-$(CFG_GNULINUX) += $(ROOTDIR)/mcal/Eth/inc
else
obj-$(USE_TCPIP) += TcpIp.o
endif
obj-$(USE_TCPIP) += TcpIp_Cfg.o
inc-$(USE_TCPIP) += $(ROOTDIR)/communication/TcpIp/inc
vpath-$(USE_TCPIP) += $(ROOTDIR)/communication/TcpIp/src
|
2301_81045437/classic-platform
|
communication/TcpIp/tcpip.mod.mk
|
Makefile
|
unknown
| 346
|
# UdpNm
obj-$(USE_UDPNM) += UdpNm_PBCfg.o
obj-$(USE_UDPNM) += UdpNm.o
inc-$(USE_UDPNM) += $(ROOTDIR)/communication/UdpNm/inc
vpath-$(USE_UDPNM) += $(ROOTDIR)/communication/UdpNm/src
|
2301_81045437/classic-platform
|
communication/UdpNm/UdpNm.mod.mk
|
Makefile
|
unknown
| 187
|
/*-------------------------------- Arctic Core ------------------------------
* Copyright (C) 2013, ArcCore AB, Sweden, www.arccore.com.
* Contact: <contact@arccore.com>
*
* You may ONLY use this file:
* 1)if you have a valid commercial ArcCore license and then in accordance with
* the terms contained in the written license agreement between you and ArcCore,
* or alternatively
* 2)if you follow the terms found in GNU General Public License version 2 as
* published by the Free Software Foundation and appearing in the file
* LICENSE.GPL included in the packaging of this file or here
* <http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt>
*-------------------------------- Arctic Core -----------------------------*/
#ifndef UDPNM_H
#define UDPNM_H
#include "ComStack_Types.h"
#include "NmStack_Types.h"
#include "UdpNm_Cbk.h"
#define UDPNM_VENDOR_ID 60
#define UDPNM_MODULE_ID 33u
#define UDPNM_AR_RELEASE_MAJOR_VERSION 4u
#define UDPNM_AR_RELEASE_MINOR_VERSION 2u
#define UDPNM_AR_RELEASE_REVISION_VERSION 2u
#define UDPNM_AR_MAJOR_VERSION UDPNM_AR_RELEASE_MAJOR_VERSION
#define UDPNM_AR_MINOR_VERSION UDPNM_AR_RELEASE_MINOR_VERSION
#define UDPNM_AR_PATCH_VERSION UDPNM_AR_RELEASE_REVISION_VERSION
#define UDPNM_SW_MAJOR_VERSION 2u
#define UDPNM_SW_MINOR_VERSION 0u
#define UDPNM_SW_PATCH_VERSION 0u
#include "UdpNm_Cfg.h"
#include "UdpNm_PBCfg.h"
#include "UdpNm_ConfigTypes.h"
/** @req SWS_UdpNm_00018 */
#define UDPNM_E_NO_INIT 0x01u
#define UDPNM_E_INVALID_CHANNEL 0x02u
/** NM-Timeout Timer has abnormally expired outside of the Ready Sleep State;
* it may happen: (1) because of Bus-Off state, (2) if some ECU requests bus communication or node detection shortly
* before the NMTimeout Timer expires so that a NM message can not be transmitted in time;
* this race condition applies to event-triggered systems */
#define UDP_E_INVALID_PDUID 0x03u
#define UDPNM_E_INIT_FAILED 0x04u
#define UDPNM_E_PARAM_POINTER 0x12u
/** Run Time Errors */
#define UDPNM_E_NETWORK_TIMEOUT 0x02u
#define UDPNM_SERVICEID_INIT 0x01u
#define UDPNM_SERVICEID_PASSIVESTARTUP 0x0Eu
#define UDPNM_SERVICEID_NETWORKREQUEST 0x02u
#define UDPNM_SERVICEID_NETWORKRELEASE 0x03u
#define UDPNM_SERVICEID_DISABLECOMMUNICATION 0x0Cu
#define UDPNM_SERVICEID_ENABLECOMMUNICATION 0x0Du
#define UDPNM_SERVICEID_SETUSERDATA 0x04u
#define UDPNM_SERVICEID_GETUSERDATA 0x05u
#define UDPNM_SERVICEID_GETNODEIDENTIFIER 0x06u
#define UDPNM_SERVICEID_GETLOCALNODEIDENTIFIER 0x07u
#define UDPNM_SERVICEID_REPEATMESSAGEREQUEST 0x08u
#define UDPNM_SERVICEID_GETPDUDATA 0x0Au
#define UDPNM_SERVICEID_GETSTATE 0x0Bu
#define UDPNM_SERVICEID_GETVERSIONINFO 0x09u
#define UDPNM_SERVICEID_REQUESTBUSSYNCHRONIZATION 0x14u
#define UDPNM_SERVICEID_CHECKREMOTESLEEPINDICATION 0x11u
#define UDPNM_SERVICEID_SETCOORDBIT 0x12u
#define UDPNM_SERVICEID_SOADIFTXCONFIRMATION 0x0Fu
#define UDPNM_SERVICEID_SOADIFRXINDICATION 0x10u
#define UDPNM_SERVICEID_TRANSMIT 0x15u
#define UDPNM_SERVICEID_ARC_MAINFUNCTION 0x13u
/** @req SWS_UdpNm_00045 partial */
#define UDPNM_CBV_REPEAT_MESSAGE_REQUEST 0x01u
// Functions called by NM Interface
// --------------------------------
/** Initialize the complete UdpNm module, i.e. all channels which are activated */
void UdpNm_Init( const UdpNm_ConfigType* UdpNmConfigPtr );
/** Passive startup of the AUTOSAR Udp NM. It triggers the transition from Bus-
* Sleep Mode to the Network Mode in Repeat Message State.
* This service has no effect if the current state is not equal to Bus-Sleep Mode. In
* that case NM_E_NOT_EXECUTED is returned. */
Std_ReturnType UdpNm_PassiveStartUp( const NetworkHandleType nmChannelHandle );
/** Request the network, since ECU needs to communicate on the bus. Network
* state shall be changed to*/
Std_ReturnType UdpNm_NetworkRequest( const NetworkHandleType nmChannelHandle );
/** Release the network, since ECU doesn't have to communicate on the bus. Network
* state shall be changed to */
Std_ReturnType UdpNm_NetworkRelease( const NetworkHandleType nmChannelHandle );
/** Disable the NM PDU transmission ability due to a ISO14229 Communication
* Control (28hex) service */
Std_ReturnType UdpNm_DisableCommunication( const NetworkHandleType nmChannelHandle );
/** Enable the NM PDU transmission ability due to a ISO14229 Communication
* Control (28hex) service */
Std_ReturnType UdpNm_EnableCommunication( const NetworkHandleType nmChannelHandle );
/** Set user data for NM messages transmitted next on the bus. */
Std_ReturnType UdpNm_SetUserData( const NetworkHandleType nmChannelHandle, const uint8* nmUserDataPtr );
/** Get user data out of the most recently received NM message. */
Std_ReturnType UdpNm_GetUserData( const NetworkHandleType nmChannelHandle, uint8* const nmUserDataPtr );
/** Get node identifier out of the most recently received NM PDU. */
Std_ReturnType UdpNm_GetNodeIdentifier( const NetworkHandleType nmChannelHandle, uint8* const nmNodeIdPtr );
/** Get node identifier configured for the local node. */
Std_ReturnType UdpNm_GetLocalNodeIdentifier( const NetworkHandleType nmChannelHandle, uint8* const nmNodeIdPtr );
/** Set Repeat Message Request Bit for NM messages transmitted next on the bus. */
Std_ReturnType UdpNm_RepeatMessageRequest( const NetworkHandleType nmChannelHandle );
/** Get the whole PDU data out of the most recently received NM message. */
Std_ReturnType UdpNm_GetPduData( const NetworkHandleType nmChannelHandle, uint8* const nmPduDataPtr );
/** Returns the state and the mode of the network management. */
Std_ReturnType UdpNm_GetState( const NetworkHandleType nmChannelHandle, Nm_StateType* const nmStatePtr, Nm_ModeType* const nmModePtr );
/** This service returns the version information of this module. */
#if ( UDPNM_VERSION_INFO_API == STD_ON )
void UdpNm_GetVersionInfo(Std_VersionInfoType* versioninfo);
#endif /* UDPNM_VERSION_INFO_API */
/** Request bus synchronization. */
Std_ReturnType UdpNm_RequestBusSynchronization( const NetworkHandleType nmChannelHandle );
/** Check if remote sleep indication takes place or not. */
Std_ReturnType UdpNm_CheckRemoteSleepIndication( const NetworkHandleType nmChannelHandle, boolean* const NmRemoteSleepIndPtr );
/** Sets the NM coordinator ID in the control bit vector of each NM message. */
Std_ReturnType UdpNm_SetCoordBits( const NetworkHandleType nmChannelHandle, const uint8 nmCoordBits );
// Functions called by SoAd Interface
// ---------------------------------
/** This service confirms a previous successfully processed transmit request.
* This callback service is called by the SoAd and implemented by the UdpNm. */
void UdpNm_SoAdIfTxConfirmation( PduIdType UdpNmTxPduId );
/** This service indicates a successful reception of a received NM message to the
* UdpNm after passing all filters and validation checks.
* This callback service is called by the SoAd and implemented by the UdpNm. */
void UdpNm_SoAdIfRxIndication( PduIdType RxPduId, const PduInfoType* PduInfoPtr );
// UdpNm functions called by the PDU-Router
// ----------------------------------------
/** UdpNm_Transmit is implemented as an empty function and shall always return E_OK. */
Std_ReturnType UdpNm_Transmit( PduIdType UdpNmSrcPduId, const PduInfoType* UdpNmSrcPduInfoPtr );
#ifdef HOST_TEST
void UdpNm_Test_GetChannelRunTimeData(uint32 channelId, uint32* messageCycleTimeLeft, uint32* timeoutTimeLeft);
void UdpNm_Test_GetCbvPosition(uint32 channelId, UdpNm_PduPositionType* UdpCbvPosition);
#if (UDPNM_PNC_COUNT > 0)
Std_ReturnType UdpNm_Test_VerifyAllEiraBitsZero(void);
Std_ReturnType UdpNm_Test_VerifyAllEraBitsZero(void);
boolean UdpNm_Test_IsPnEiraBitSet(uint8 eiraByteIndex, uint8 pnBitIndex);
boolean UdpNm_Test_IsPnEraBitSet(uint8 chanIndex, uint8 eraByteIndex, uint8 pnBitIndex);
uint32 UdpNm_Test_GetEiraResetTimer(uint8 pnIdx);
uint32 UdpNm_Test_GetEraResetTimer(uint8 chanIdx, uint8 pnIdx);
#endif /* (UDPNM_PNC_COUNT > 0) */
#endif /* HOST_TEST */
#endif /* UDPNM_H */
|
2301_81045437/classic-platform
|
communication/UdpNm/inc/UdpNm.h
|
C
|
unknown
| 8,356
|
/*-------------------------------- Arctic Core ------------------------------
* Copyright (C) 2013, ArcCore AB, Sweden, www.arccore.com.
* Contact: <contact@arccore.com>
*
* You may ONLY use this file:
* 1)if you have a valid commercial ArcCore license and then in accordance with
* the terms contained in the written license agreement between you and ArcCore,
* or alternatively
* 2)if you follow the terms found in GNU General Public License version 2 as
* published by the Free Software Foundation and appearing in the file
* LICENSE.GPL included in the packaging of this file or here
* <http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt>
*-------------------------------- Arctic Core -----------------------------*/
#ifndef UDPNM_CBK_H_
#define UDPNM_CBK_H_
/* We need this to export pdu id's */
#include "UdpNm.h"
#endif /* UDPNM_CBK_H_ */
|
2301_81045437/classic-platform
|
communication/UdpNm/inc/UdpNm_Cbk.h
|
C
|
unknown
| 886
|
/*-------------------------------- Arctic Core ------------------------------
* Copyright (C) 2013, ArcCore AB, Sweden, www.arccore.com.
* Contact: <contact@arccore.com>
*
* You may ONLY use this file:
* 1)if you have a valid commercial ArcCore license and then in accordance with
* the terms contained in the written license agreement between you and ArcCore,
* or alternatively
* 2)if you follow the terms found in GNU General Public License version 2 as
* published by the Free Software Foundation and appearing in the file
* LICENSE.GPL included in the packaging of this file or here
* <http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt>
*-------------------------------- Arctic Core -----------------------------*/
#ifndef UDPNM_CONFIGTYPES_H_
#define UDPNM_CONFIGTYPES_H_
#if defined(USE_DEM)
#include "Dem.h"
#endif
/** @req SWS_UdpNm_00026 */
/** @req SWS_UdpNm_00201 */
/** @req SWS_UdpNm_00202 */
/** @req SWS_UdpNm_00203 */
/** @req SWS_UdpNm_00304 */
typedef enum {
UDPNM_PDU_BYTE_0 = 0x00,
UDPNM_PDU_BYTE_1 = 0x01,
UDPNM_PDU_OFF = 0xFF
} UdpNm_PduPositionType;
/** @req SWS_UdpNm_00202 */
/** @req SWS_UdpNm_00203 */
typedef struct {
const uint8 UdpNmNodeId;
const UdpNm_PduPositionType UdpNmPduCbvPosition; /**< @req SWS_UdpNm_00075 */
const uint8 UdpNmPduLength; /**< @req SWS_UdpNm_00076 */
const UdpNm_PduPositionType UdpNmPduNidPosition; /**< @req SWS_UdpNm_00074 */
const uint8 UdpNmUserDataLength; /* Not used */
const uint32 UdpNmMainFunctionPeriod;
const uint32 UdpNmMsgCycleOffset;
const uint32 UdpNmMsgCycleTime;
const uint32 UdpNmMsgTimeoutTime;
const uint32 UdpNmRemoteSleepIndTime; /**< @req SWS_UdpNm_00249 */
const uint32 UdpNmRepeatMessageTime; /**< @req SWS_UdpNm_00247 */
const uint32 UdpNmTimeoutTime; /**< @req SWS_UdpNm_00246 */
const uint32 UdpNmWaitBusSleepTime; /**< @req SWS_UdpNm_00248 */
const NetworkHandleType UdpNmComMChannelIdRef;
const PduIdType UdpNmRxPduId; /* Not used */
const PduIdType UdpNmTxPduId;
const boolean UdpNmPnEnable;
const boolean UdpNmPnEraCalcEnabled;
#if (UDPNM_COM_USER_DATA_SUPPORT == STD_ON)
const PduIdType UdpNmUserDataTxPduId;
#endif
#if ((UDPNM_PNC_COUNT > 0) && (UDPNM_PNC_ERA_CALC_ENABLED == STD_ON))
PduIdType UdpNmERARxNSduId; /* SDU carrying ERA */
#endif /* ((UDPNM_PNC_COUNT > 0) && (UDPNM_PNC_ERA_CALC_ENABLED == STD_ON)) */
} UdpNm_ChannelType;
#if defined(USE_DEM)
typedef struct {
Dem_EventIdType UdpNmTcpIpTransmitErrorDemEventId;
Dem_EventIdType UdpNmNetworkTimeoutDemEventId;
} UdpNm_DemEventReferencesType;
#endif
typedef struct {
uint8 UdpNmPnInfoOffset; /* Offset Index */
uint8 UdpNmPnInfoLen; /* PnInfo Length */
const uint8 *UdpNmPnInfoMask; /* Pointer PNC mask bytes */
const uint8 *UdpNmPnIndexToTimerMap; /* Mapping from PN index to reset timer index */
const uint8 *UdpNmTimerIndexToPnMap; /* Mapping from timer index to PN index */
#if UDPNM_PNC_EIRA_CALC_ENABLED == STD_ON
PduIdType UdpNmEIRARxNSduId; /* SDU carrying EIRA */
#endif
} UdpNm_PnInfoType;
/** @req SWS_UdpNm_00308 */
typedef struct {
const UdpNm_ChannelType* Channels;
const NetworkHandleType* ChannelMap;
const NetworkHandleType ChannelMapSize;
const UdpNm_PnInfoType* UdpNmPnInfo;
#if defined(USE_DEM)
const UdpNm_DemEventReferencesType* DemReferences;
#endif
} UdpNm_ConfigType;
#endif /* UDPNM_CONFIGTYPES_H_ */
|
2301_81045437/classic-platform
|
communication/UdpNm/inc/UdpNm_ConfigTypes.h
|
C
|
unknown
| 3,865
|
/*-------------------------------- Arctic Core ------------------------------
* Copyright (C) 2013, ArcCore AB, Sweden, www.arccore.com.
* Contact: <contact@arccore.com>
*
* You may ONLY use this file:
* 1)if you have a valid commercial ArcCore license and then in accordance with
* the terms contained in the written license agreement between you and ArcCore,
* or alternatively
* 2)if you follow the terms found in GNU General Public License version 2 as
* published by the Free Software Foundation and appearing in the file
* LICENSE.GPL included in the packaging of this file or here
* <http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt>
*-------------------------------- Arctic Core -----------------------------*/
/* Globally fulfilled requirements */
/** @req SWS_UdpNm_00131 - The AUTOSAR UdpNm algorithm shall support up to 250 nodes per NM-Cluster by default.*/
/** @req SWS_UdpNm_00081 - The code file structure shall include UdpNm_Lcfg.c and UdpNm_PBcfg.c. */
/** @req SWS_UdpNm_00044 - Header files UdpNm shall provide. */
/** @req SWS_UdpNm_00082 - Header files UdpNm shall include. *//** Memory mapping is done in MemMap.h instead of UdpNm_MemMap.h */
/** @req SWS_UdpNm_00083 - Header files containing data that UdpNm shall include. *//**SoAd.h and Nm.h are included, which includes SoAd_Cfg.h and Nm_Cfg.h */
/** @req SWS_UdpNm_00089 - The UdpNm state machine. */
/** @req SWS_UdpNm_00092 - UdpNm operational modes. */
/** @req SWS_UdpNm_00093 - Changes of the AUTOSAR UdpNm operational modes shall be signaled to the upper
* layer by means of call-back functions. */
/** @req SWS_UdpNm_00094 - UdpNm operational states. */
/** @req SWS_UdpNm_00146 - The UdpNm coordination algorithm shall be processor independent. */
/** @req SWS_UdpNm_00244 - The UdpNm module shall reject the execution of a service
called with an invalid parameter and shall inform the DET. */
/** @req SWS_UdpNm_00197 - Parameter type checking shall be performed at compile time. */
/** @req SWS_UdpNm_00198 - Parameter value check shall be performed at configuration time. */
/** @req SWS_UdpNm_00199 - Parameter value check shall be performed at execution time. */
/** @req SWS_UdpNm_00158 - Support of NM user data shall be statically configurable. */
/** @req SWS_UdpNm_00086 - Checked during configuration. */
/** @req SWS_UdpNm_00314 - Checked during configuration. */
#include "Platform_Types.h"
#include "ComStack_Types.h"
#include "UdpNm.h"
#include "UdpNm_Internal.h"
#include "Nm_Cbk.h"
#include "NmStack_Types.h"
#include "SchM_UdpNm.h"
#include "MemMap.h"
#include "SoAd.h"
#include "Nm.h"
#include <string.h>
/** @req SWS_UdpNm_00311 */
#if (UDPNM_COM_USER_DATA_SUPPORT == STD_ON)
#include "PduR_UdpNm.h"
#endif
#if (UDPNM_DEV_ERROR_DETECT == STD_ON)
#include "Det.h"
#endif
#if defined(USE_DEM)
#include "Dem.h"
#endif
static const UdpNm_ConfigType* UdpNm_ConfigPtr;
void UdpNm_MainFunction(NetworkHandleType nmChannelHandle);
/*lint -save -e785 Too few initializers for aggregate UdpNm_Internal. OK, the rest are set in UdpNm_Init.
* This is the only one that needs to be set before. */
UdpNm_InternalType UdpNm_Internal = {
.InitStatus = UDPNM_UNINIT,
};
/*lint -restore -e785 */
/** Initialize the complete UdpNm module, i.e. all channels which are activated */
/** @req SWS_UdpNm_00141 */
/** @req SWS_UdpNm_00143 */
/** @req SWS_UdpNm_00144 */
/** @req SWS_UdpNm_00145 */
/** @req SWS_UdpNm_00060 */
/** @req SWS_UdpNm_00061 */
/** @req SWS_UdpNm_00033 */
/** @req SWS_UdpNm_00039 */
/** @req SWS_UdpNm_00025 */
/** @req SWS_UdpNm_00085 */
/** @req SWS_UdpNm_00013 */
/** @req SWS_UdpNm_00208 */
void UdpNm_Init( const UdpNm_ConfigType* UdpNmConfigPtr ){
UDPNM_VALIDATE_NOTNULL(UdpNmConfigPtr, UDPNM_SERVICEID_INIT);
UdpNm_ConfigPtr = UdpNmConfigPtr;
for (uint8 channel = 0; channel < UDPNM_CHANNEL_COUNT; channel++) {
const UdpNm_ChannelType* ChannelConf = &UdpNm_ConfigPtr->Channels[channel];
UdpNm_Internal_ChannelType* ChannelInternal = &UdpNm_Internal.Channels[channel];
ChannelInternal->Mode = NM_MODE_BUS_SLEEP;
ChannelInternal->State = NM_STATE_BUS_SLEEP;
ChannelInternal->Requested = FALSE;
ChannelInternal->TimeoutTimeLeft = 0;
ChannelInternal->RepeatMessageTimeLeft = 0;
ChannelInternal->WaitBusSleepTimeLeft = 0;
ChannelInternal->MessageCycleTimeLeft = 0;
ChannelInternal->MessageTimeoutTimeLeft = 0;
memset(ChannelInternal->TxMessageSdu, 0x00, 8);
memset(ChannelInternal->RxMessageSdu, 0x00, 8);
uint8* destUserData = UdpNm_Internal_GetUserDataPtr(ChannelConf, ChannelInternal->TxMessageSdu);
uint8 userDataLength = UdpNm_Internal_GetUserDataLength(ChannelConf);
memset(destUserData, 0xFF, userDataLength);
#if (UDPNM_NODE_ID_ENABLED == STD_ON)
if (ChannelConf->UdpNmPduNidPosition != UDPNM_PDU_OFF) {
ChannelInternal->TxMessageSdu[ChannelConf->UdpNmPduNidPosition] = ChannelConf->UdpNmNodeId;
}
#endif
}
#if ((UDPNM_PNC_EIRA_CALC_ENABLED == STD_ON) && (UDPNM_PNC_COUNT > 0))
/* Initialize the PN reset timer */
for (uint8 i = 0; i < UDPNM_PNC_COUNT; i++) {
UdpNm_Internal.pnEIRATimers[i].timerRunning = FALSE;
UdpNm_Internal.pnEIRATimers[i].resetTimer = 0;
}
/** @req SWS_UdpNm_00344 */
memset(UdpNm_Internal.pnEIRABytes, 0, UDPNM_PNC_INFO_LEN); /* reset EIRA */
#endif
#if ((UDPNM_PNC_ERA_CALC_ENABLED == STD_ON) && (UDPNM_PNC_COUNT > 0))
for (uint8 chanIndex = 0; chanIndex < UDPNM_CHANNEL_COUNT; chanIndex++) {
for (uint8 timerIndex = 0; timerIndex < UDPNM_PNC_COUNT; timerIndex++) {
UdpNm_Internal.Channels[chanIndex].pnERATimers[timerIndex].timerRunning = FALSE;
UdpNm_Internal.Channels[chanIndex].pnERATimers[timerIndex].resetTimer = 0;
}
/** @req SWS_UdpNm_00355 */
memset(UdpNm_Internal.Channels[chanIndex].pnERABytes, 0, UDPNM_PNC_INFO_LEN);
}
#endif
UdpNm_Internal.InitStatus = UDPNM_INIT;
}
/** Passive startup of the AUTOSAR Udp NM. It triggers the transition from Bus-
* Sleep Mode to the Network Mode in Repeat Message State.
* This service has no effect if the current state is equal to Network Mode. In
* that case E_NOT_OK is returned. */
/** @req SWS_UdpNm_00095 */
/** @req SWS_UdpNm_00128 */
/** @req SWS_UdpNm_00147 */
/** @req SWS_UdpNm_00211 */
Std_ReturnType UdpNm_PassiveStartUp( const NetworkHandleType nmChannelHandle ){
UDPNM_VALIDATE_INIT(UDPNM_SERVICEID_PASSIVESTARTUP, E_NOT_OK);
UDPNM_VALIDATE_CHANNEL(nmChannelHandle, UDPNM_SERVICEID_PASSIVESTARTUP, E_NOT_OK);
const UdpNm_ChannelType* ChannelConf = &UdpNm_ConfigPtr->Channels[UdpNm_ConfigPtr->ChannelMap[nmChannelHandle]];
UdpNm_Internal_ChannelType* ChannelInternal = &UdpNm_Internal.Channels[UdpNm_ConfigPtr->ChannelMap[nmChannelHandle]];
Std_ReturnType status = E_OK;
if (ChannelInternal->Mode == NM_MODE_NETWORK) {
status = E_NOT_OK;
} else {
UdpNm_Internal_BusSleep_to_RepeatMessage(ChannelConf, ChannelInternal);
status = E_OK;
}
#if (UDPNM_PNC_COUNT > 0)
if (TRUE == ChannelConf->UdpNmPnEnable) {
/** @req SWS_UdpNm_00332 */
/** @req SWS_UdpNm_00333 */
UdpNm_Internal_SetPniCbv(ChannelConf, ChannelInternal);
}
#endif
return status;
}
#if (UDPNM_PASSIVE_MODE_ENABLED == STD_OFF)
/** Request the network, since ECU needs to communicate on the bus. Network
* state shall be changed to */
/** @req SWS_UdpNm_00110 */
/** @req SWS_UdpNm_00123 */
/** @req SWS_UdpNm_00129 */
/** @req SWS_UdpNm_00104 */
/** @req SWS_UdpNm_00213 */
Std_ReturnType UdpNm_NetworkRequest( const NetworkHandleType nmChannelHandle ){
UDPNM_VALIDATE_INIT(UDPNM_SERVICEID_NETWORKREQUEST, E_NOT_OK);
UDPNM_VALIDATE_CHANNEL(nmChannelHandle, UDPNM_SERVICEID_NETWORKREQUEST, E_NOT_OK);
const UdpNm_ChannelType* ChannelConf = &UdpNm_ConfigPtr->Channels[UdpNm_ConfigPtr->ChannelMap[nmChannelHandle]];
UdpNm_Internal_ChannelType* ChannelInternal = &UdpNm_Internal.Channels[UdpNm_ConfigPtr->ChannelMap[nmChannelHandle]];
ChannelInternal->Requested = TRUE;
if (ChannelInternal->Mode == NM_MODE_BUS_SLEEP) {
UdpNm_Internal_BusSleep_to_RepeatMessage(ChannelConf, ChannelInternal);
} else if (ChannelInternal->Mode == NM_MODE_PREPARE_BUS_SLEEP) {
UdpNm_Internal_PrepareBusSleep_to_RepeatMessage(ChannelConf, ChannelInternal);
} else if (ChannelInternal->Mode == NM_MODE_NETWORK) {
if (ChannelInternal->State == NM_STATE_READY_SLEEP) {
UdpNm_Internal_ReadySleep_to_NormalOperation(ChannelConf, ChannelInternal);
}
} else {
//Nothing to be done
}
#if (UDPNM_PNC_COUNT > 0)
if (TRUE == ChannelConf->UdpNmPnEnable) {
/** @req SWS_UdpNm_00332 */
/** @req SWS_UdpNm_00333 */
UdpNm_Internal_SetPniCbv(ChannelConf, ChannelInternal);
}
#endif
return E_OK;
}
/** Release the network, since ECU doesn't have to communicate on the bus. Network
* state shall be changed to */
/** @req SWS_UdpNm_00105 */
/** @req SWS_UdpNm_00214 */
Std_ReturnType UdpNm_NetworkRelease( const NetworkHandleType nmChannelHandle ){
UDPNM_VALIDATE_INIT(UDPNM_SERVICEID_NETWORKRELEASE, E_NOT_OK);
UDPNM_VALIDATE_CHANNEL(nmChannelHandle, UDPNM_SERVICEID_NETWORKRELEASE, E_NOT_OK);
UdpNm_Internal_ChannelType* ChannelInternal = &UdpNm_Internal.Channels[UdpNm_ConfigPtr->ChannelMap[nmChannelHandle]];
ChannelInternal->Requested = FALSE;
if (ChannelInternal->Mode == NM_MODE_NETWORK) {
if (ChannelInternal->State == NM_STATE_NORMAL_OPERATION) {
UdpNm_Internal_NormalOperation_to_ReadySleep(ChannelInternal);
}
}
return E_OK;
}
#endif
/** Disable the NM PDU transmission ability due to a ISO14229 Communication
* Control (28hex) service */
Std_ReturnType UdpNm_DisableCommunication( const NetworkHandleType nmChannelHandle ){
UDPNM_VALIDATE_INIT(UDPNM_SERVICEID_DISABLECOMMUNICATION, E_NOT_OK);
UDPNM_VALIDATE_CHANNEL(nmChannelHandle, UDPNM_SERVICEID_DISABLECOMMUNICATION, E_NOT_OK);
// Not implemented
return E_NOT_OK;
}
/** Enable the NM PDU transmission ability due to a ISO14229 Communication
* Control (28hex) service */
Std_ReturnType UdpNm_EnableCommunication( const NetworkHandleType nmChannelHandle ){
UDPNM_VALIDATE_INIT(UDPNM_SERVICEID_ENABLECOMMUNICATION, E_NOT_OK);
UDPNM_VALIDATE_CHANNEL(nmChannelHandle, UDPNM_SERVICEID_ENABLECOMMUNICATION, E_NOT_OK);
// Not implemented
return E_NOT_OK;
}
/** @req SWS_UdpNm_00312 */
#if ((UDPNM_USER_DATA_ENABLED == STD_ON) && ( UDPNM_COM_USER_DATA_SUPPORT == STD_OFF))
/** Set user data for NM messages transmitted next on the bus. */
/** @req SWS_UdpNm_00217 */
/** @req SWS_UdpNm_00159 */
Std_ReturnType UdpNm_SetUserData( const NetworkHandleType nmChannelHandle, const uint8* nmUserDataPtr ){
UDPNM_VALIDATE_INIT(UDPNM_SERVICEID_SETUSERDATA, E_NOT_OK);
UDPNM_VALIDATE_CHANNEL(nmChannelHandle, UDPNM_SERVICEID_SETUSERDATA, E_NOT_OK);
const UdpNm_ChannelType* ChannelConf = &UdpNm_ConfigPtr->Channels[UdpNm_ConfigPtr->ChannelMap[nmChannelHandle]];
UdpNm_Internal_ChannelType* ChannelInternal = &UdpNm_Internal.Channels[UdpNm_ConfigPtr->ChannelMap[nmChannelHandle]];
uint8* destUserData = UdpNm_Internal_GetUserDataPtr(ChannelConf, ChannelInternal->TxMessageSdu);
uint8 userDataLength = UdpNm_Internal_GetUserDataLength(ChannelConf);
memcpy(destUserData, nmUserDataPtr, userDataLength);
return E_OK;
}
#endif
#if (UDPNM_USER_DATA_ENABLED == STD_ON)
/** Get user data out of the most recently received NM message. */
/** @req SWS_UdpNm_00218 */
/** @req SWS_UdpNm_00160 */
Std_ReturnType UdpNm_GetUserData( const NetworkHandleType nmChannelHandle, uint8* const nmUserDataPtr ){
UDPNM_VALIDATE_INIT(UDPNM_SERVICEID_GETUSERDATA, E_NOT_OK);
UDPNM_VALIDATE_CHANNEL(nmChannelHandle, UDPNM_SERVICEID_GETUSERDATA, E_NOT_OK);
const UdpNm_ChannelType* ChannelConf = &UdpNm_ConfigPtr->Channels[UdpNm_ConfigPtr->ChannelMap[nmChannelHandle]];
UdpNm_Internal_ChannelType* ChannelInternal = &UdpNm_Internal.Channels[UdpNm_ConfigPtr->ChannelMap[nmChannelHandle]];
const uint8* sourceUserData = UdpNm_Internal_GetUserDataPtr(ChannelConf, ChannelInternal->RxMessageSdu);
uint8 userDataLength = UdpNm_Internal_GetUserDataLength(ChannelConf);
memcpy(nmUserDataPtr, sourceUserData, userDataLength);
return E_OK;
}
#endif
#if (UDPNM_NODE_ID_ENABLED == STD_ON)
/** Get node identifier out of the most recently received NM PDU. */
/** @req SWS_UdpNm_00219 */
/** @req SWS_UdpNm_00132 */
Std_ReturnType UdpNm_GetNodeIdentifier( const NetworkHandleType nmChannelHandle, uint8* const nmNodeIdPtr ){
UDPNM_VALIDATE_INIT(UDPNM_SERVICEID_GETNODEIDENTIFIER, E_NOT_OK);
UDPNM_VALIDATE_CHANNEL(nmChannelHandle, UDPNM_SERVICEID_GETNODEIDENTIFIER, E_NOT_OK);
const UdpNm_ChannelType* ChannelConf = &UdpNm_ConfigPtr->Channels[UdpNm_ConfigPtr->ChannelMap[nmChannelHandle]];
const UdpNm_Internal_ChannelType* ChannelInternal = &UdpNm_Internal.Channels[UdpNm_ConfigPtr->ChannelMap[nmChannelHandle]];
Std_ReturnType status = E_OK;
if (ChannelConf->UdpNmPduNidPosition == UDPNM_PDU_OFF) {
status = E_NOT_OK;
} else {
*nmNodeIdPtr = ChannelInternal->RxMessageSdu[ChannelConf->UdpNmPduNidPosition];
}
return status;
}
/** Get node identifier configured for the local node. */
/** @req SWS_UdpNm_00220 */
/** @req SWS_UdpNm_00133 */
Std_ReturnType UdpNm_GetLocalNodeIdentifier( const NetworkHandleType nmChannelHandle, uint8* const nmNodeIdPtr ){
UDPNM_VALIDATE_INIT(UDPNM_SERVICEID_GETLOCALNODEIDENTIFIER, E_NOT_OK);
UDPNM_VALIDATE_CHANNEL(nmChannelHandle, UDPNM_SERVICEID_GETLOCALNODEIDENTIFIER, E_NOT_OK);
const UdpNm_ChannelType* ChannelConf = &UdpNm_ConfigPtr->Channels[UdpNm_ConfigPtr->ChannelMap[nmChannelHandle]];
*nmNodeIdPtr = ChannelConf->UdpNmNodeId;
return E_OK;
}
#endif
#if (UDPNM_NODE_DETECTION_ENABLED == STD_ON)
/** Set Repeat Message Request Bit for NM messages transmitted next on the bus. */
/** @req SWS_UdpNm_00137 */
/** @req SWS_UdpNm_00120 */
/** @req SWS_UdpNm_00121 */
/** @req SWS_UdpNm_00112 */
/** @req SWS_UdpNm_00113 */
/** @req SWS_UdpNm_00135 */
/** @req SWS_UdpNm_00221 */
Std_ReturnType UdpNm_RepeatMessageRequest( const NetworkHandleType nmChannelHandle ){
UDPNM_VALIDATE_INIT(UDPNM_SERVICEID_REPEATMESSAGEREQUEST, E_NOT_OK);
UDPNM_VALIDATE_CHANNEL(nmChannelHandle, UDPNM_SERVICEID_REPEATMESSAGEREQUEST, E_NOT_OK);
const UdpNm_ChannelType* ChannelConf = &UdpNm_ConfigPtr->Channels[UdpNm_ConfigPtr->ChannelMap[nmChannelHandle]];
UdpNm_Internal_ChannelType* ChannelInternal = &UdpNm_Internal.Channels[UdpNm_ConfigPtr->ChannelMap[nmChannelHandle]];
Std_ReturnType status = E_NOT_OK;
if (ChannelConf->UdpNmPduCbvPosition != UDPNM_PDU_OFF) {
if (ChannelInternal->State == NM_STATE_READY_SLEEP) {
ChannelInternal->TxMessageSdu[ChannelConf->UdpNmPduCbvPosition] |= UDPNM_CBV_REPEAT_MESSAGE_REQUEST;
UdpNm_Internal_ReadySleep_to_RepeatMessage(ChannelConf, ChannelInternal);
status = E_OK;
} else if (ChannelInternal->State == NM_STATE_NORMAL_OPERATION) {
ChannelInternal->TxMessageSdu[ChannelConf->UdpNmPduCbvPosition] |= UDPNM_CBV_REPEAT_MESSAGE_REQUEST;
UdpNm_Internal_NormalOperation_to_RepeatMessage(ChannelConf, ChannelInternal);
status = E_OK;
} else {
//Nothing to be done
}
}
return status;
}
#endif
#if ((UDPNM_NODE_ID_ENABLED == STD_ON) || (UDPNM_NODE_DETECTION_ENABLED == STD_ON) || (UDPNM_USER_DATA_ENABLED == STD_ON))
/** Get the whole PDU data out of the most recently received NM message. */
/** @req SWS_UdpNm_00309 */
/** @req SWS_UdpNm_00138 */
/** @req SWS_UdpNm_00139 */
Std_ReturnType UdpNm_GetPduData( const NetworkHandleType nmChannelHandle, uint8* const nmPduDataPtr ){
UDPNM_VALIDATE_INIT(UDPNM_SERVICEID_GETPDUDATA, E_NOT_OK);
UDPNM_VALIDATE_CHANNEL(nmChannelHandle, UDPNM_SERVICEID_GETPDUDATA, E_NOT_OK);
const UdpNm_ChannelType* ChannelConf = &UdpNm_ConfigPtr->Channels[UdpNm_ConfigPtr->ChannelMap[nmChannelHandle]];
const UdpNm_Internal_ChannelType* ChannelInternal = &UdpNm_Internal.Channels[UdpNm_ConfigPtr->ChannelMap[nmChannelHandle]];
memcpy(nmPduDataPtr, ChannelInternal->RxMessageSdu, ChannelConf->UdpNmPduLength);
return E_OK;
}
#endif
/** Returns the state and the mode of the network management. */
/** @req SWS_UdpNm_00310 */
Std_ReturnType UdpNm_GetState( const NetworkHandleType nmChannelHandle, Nm_StateType* const nmStatePtr, Nm_ModeType* const nmModePtr ){
UDPNM_VALIDATE_INIT(UDPNM_SERVICEID_GETSTATE, E_NOT_OK);
UDPNM_VALIDATE_CHANNEL(nmChannelHandle, UDPNM_SERVICEID_GETSTATE, E_NOT_OK);
const UdpNm_Internal_ChannelType* ChannelInternal = &UdpNm_Internal.Channels[UdpNm_ConfigPtr->ChannelMap[nmChannelHandle]];
*nmStatePtr = ChannelInternal->State;
*nmModePtr = ChannelInternal->Mode;
return E_OK;
}
/** Request bus synchronization. */
Std_ReturnType UdpNm_RequestBusSynchronization( const NetworkHandleType nmChannelHandle ){
UDPNM_VALIDATE_INIT(UDPNM_SERVICEID_REQUESTBUSSYNCHRONIZATION, E_NOT_OK);
UDPNM_VALIDATE_CHANNEL(nmChannelHandle, UDPNM_SERVICEID_REQUESTBUSSYNCHRONIZATION, E_NOT_OK);
// Not implemented
return E_NOT_OK;
}
/** Check if remote sleep indication takes place or not. */
Std_ReturnType UdpNm_CheckRemoteSleepIndication( const NetworkHandleType nmChannelHandle, boolean* const nmRemoteSleepIndPtr ){
UDPNM_VALIDATE_INIT(UDPNM_SERVICEID_CHECKREMOTESLEEPINDICATION, E_NOT_OK);
UDPNM_VALIDATE_CHANNEL(nmChannelHandle, UDPNM_SERVICEID_CHECKREMOTESLEEPINDICATION, E_NOT_OK);
//lint -estring(920,pointer) /* cast to void */
(void)nmRemoteSleepIndPtr;
//lint +estring(920,pointer) /* cast to void */
// Not implemented
return E_NOT_OK;
}
/** Sets the NM coordinator ID in the control bit vector of each NM message. */
Std_ReturnType UdpNm_SetCoordBits( const NetworkHandleType nmChannelHandle, const uint8 nmCoordBits ){
UDPNM_VALIDATE_INIT(UDPNM_SERVICEID_CHECKREMOTESLEEPINDICATION, E_NOT_OK);
UDPNM_VALIDATE_CHANNEL(nmChannelHandle, UDPNM_SERVICEID_CHECKREMOTESLEEPINDICATION, E_NOT_OK);
// Not implemented
(void) nmCoordBits;
return E_NOT_OK;
}
// Functions called by SoAd
// ---------------------------------
/** This service confirms a previous successfully processed transmit request.
* This callback service is called by the SoAd and implemented by the UdpNm. */
/** @req SWS_UdpNm_00099 */
/** @req SWS_UdpNm_00228 */
/** @req SWS_UdpNm_00229 */
/** @req SWS_UdpNm_00230 */
/** @req SWS_UdpNm_00316 */
void UdpNm_SoAdIfTxConfirmation( PduIdType UdpNmTxPduId ){
UDPNM_VALIDATE_INIT(UDPNM_SERVICEID_SOADIFTXCONFIRMATION);
UDPNM_VALIDATE_PDUID(UdpNmTxPduId, UDPNM_SERVICEID_SOADIFTXCONFIRMATION);
const UdpNm_ChannelType* ChannelConf = &UdpNm_ConfigPtr->Channels[UdpNmTxPduId];
UdpNm_Internal_ChannelType* ChannelInternal = &UdpNm_Internal.Channels[UdpNmTxPduId];
if (ChannelInternal->Mode == NM_MODE_NETWORK) {
UdpNm_Internal_NetworkMode_to_NetworkMode(ChannelConf, ChannelInternal);
}
/* Message Timeout */
ChannelInternal->MessageTimeoutTimeLeft = ChannelConf->UdpNmMsgTimeoutTime;
#if (UDPNM_COM_USER_DATA_SUPPORT == STD_ON)
PduR_UdpNmTxConfirmation(UdpNmTxPduId);
#endif /* UDPNM_COM_USER_DATA_SUPPORT == STD_ON */
}
/** This service indicates a successful reception of a received NM message to the
* UdpNm after passing all filters and validation checks.
* This callback service is called by the SoAd and implemented by the UdpNm. */
/** @req SWS_UdpNm_00098 */
/** @req SWS_UdpNm_00119 */
/** @req SWS_UdpNm_00111 */
/** @req SWS_UdpNm_00124 */
/** @req SWS_UdpNm_00035 */
/** @req SWS_UdpNm_00037 */
/** @req SWS_UdpNm_00164 */
/** @req SWS_UdpNm_00165 */
/** @req SWS_UdpNm_00231 */
/** @req SWS_UdpNm_00232 partial */
/** @req SWS_UdpNm_00233 */
/*lint -e{818} Pointer parameter 'PduInfoPtr' could be declared as pointing to const */
void UdpNm_SoAdIfRxIndication( PduIdType RxPduId, const PduInfoType* PduInfoPtr ){
UDPNM_VALIDATE_INIT(UDPNM_SERVICEID_SOADIFRXINDICATION);
UDPNM_VALIDATE_NOTNULL(PduInfoPtr, UDPNM_SERVICEID_SOADIFRXINDICATION);
UDPNM_VALIDATE_PDUID(RxPduId, UDPNM_SERVICEID_SOADIFRXINDICATION);
const UdpNm_ChannelType* ChannelConf= &UdpNm_ConfigPtr->Channels[RxPduId];
UdpNm_Internal_ChannelType* ChannelInternal= &UdpNm_Internal.Channels[RxPduId];
Std_ReturnType ret;
ret = E_OK;
memcpy(ChannelInternal->RxMessageSdu, PduInfoPtr->SduDataPtr, ChannelConf->UdpNmPduLength);
boolean repeatMessageBitIndication = FALSE;
if (ChannelConf->UdpNmPduCbvPosition != UDPNM_PDU_OFF) {
uint8 cbv = ChannelInternal->RxMessageSdu[ChannelConf->UdpNmPduCbvPosition];
repeatMessageBitIndication = cbv & UDPNM_CBV_REPEAT_MESSAGE_REQUEST;
#if (UDPNM_PNC_COUNT > 0)
ret = UdpNm_Internal_RxProcess(ChannelConf, ChannelInternal, (boolean) ((cbv & UDPNM_CBV_PNI) > 0));
#endif
}
if (E_OK == ret) { /*lint !e774 ret evaluates E_OK always when UDPNM_PNC_COUNT = 0 */
if (ChannelInternal->Mode == NM_MODE_BUS_SLEEP) {
UdpNm_Internal_BusSleep_to_BusSleep(ChannelConf);
} else if (ChannelInternal->Mode == NM_MODE_PREPARE_BUS_SLEEP) {
UdpNm_Internal_PrepareBusSleep_to_RepeatMessage(ChannelConf, ChannelInternal);
} else if (ChannelInternal->Mode == NM_MODE_NETWORK) {
UdpNm_Internal_NetworkMode_to_NetworkMode(ChannelConf, ChannelInternal);
if (TRUE == repeatMessageBitIndication) {
if (ChannelInternal->State == NM_STATE_READY_SLEEP) {
UdpNm_Internal_ReadySleep_to_RepeatMessage(ChannelConf, ChannelInternal);
} else if (ChannelInternal->State == NM_STATE_NORMAL_OPERATION) {
UdpNm_Internal_NormalOperation_to_RepeatMessage(ChannelConf, ChannelInternal);
} else {
//Nothing to be done
}
}
} else {
//Nothing to be done
}
#if (UDPNM_PDU_RX_INDICATION_ENABLED == STD_ON)
// IMPROVEMENT: Add support for NM rx indication
#endif
/* Message Timeout */
ChannelInternal->MessageTimeoutTimeLeft = ChannelConf->UdpNmMsgTimeoutTime;
}
}
/** UdpNm_Transmit is implemented as an empty function and shall always return E_OK. */
/** @req SWS_UdpNm_00313 */
/** @req SWS_UdpNm_00315 */
#if (UDPNM_COM_USER_DATA_SUPPORT == STD_ON)
Std_ReturnType UdpNm_Transmit( PduIdType UdpNmSrcPduId, const PduInfoType* UdpNmSrcPduInfoPtr ){
UDPNM_VALIDATE_NOTNULL(UdpNmSrcPduInfoPtr, UDPNM_SERVICEID_TRANSMIT, E_OK);
(void) UdpNmSrcPduId;
return E_OK;
}
#endif
/** @req SWS_UdpNm_00224 */
/** @req SWS_UdpNm_00318 */
#if ( UDPNM_VERSION_INFO_API == STD_ON )
void UdpNm_GetVersionInfo(Std_VersionInfoType* versioninfo) {
UDPNM_VALIDATE_NOTNULL(versioninfo, UDPNM_SERVICEID_GETVERSIONINFO);
STD_GET_VERSION_INFO(versioninfo, UDPNM);
}
#endif /* UDPNM_VERSION_INFO_API */
// ----------------------------------------------------------------------------
// Internal functions
// ----------------------------------------------------------------------------
// Accessed through UdpNm_MainFunction_<channel>
/** @req SWS_UdpNm_00193 */
/** @req SWS_UdpNm_00194 */
/** @req SWS_UdpNm_00087 */
/** @req SWS_UdpNm_00088 */
/** @req SWS_UdpNm_00116 */
/** @req SWS_UdpNm_00108 */
/** @req SWS_UdpNm_00072 */
/** @req SWS_UdpNm_00237 */
/** @req SWS_UdpNm_00051 */
/** @req SWS_UdpNm_00161 */
/** @req SWS_UdpNm_00162 */
/** @req SWS_UdpNm_00234 */
void UdpNm_MainFunction(NetworkHandleType nmChannelHandle) {
UDPNM_VALIDATE_INIT(UDPNM_SERVICEID_ARC_MAINFUNCTION);
const NetworkHandleType chanIndex = UdpNm_ConfigPtr->ChannelMap[nmChannelHandle];
const UdpNm_ChannelType* ChannelConf = &UdpNm_ConfigPtr->Channels[chanIndex];
UdpNm_Internal_ChannelType* ChannelInternal = &UdpNm_Internal.Channels[chanIndex];
if (ChannelInternal->Mode == NM_MODE_NETWORK) {
UdpNm_Internal_TickTimeoutTime(ChannelConf, ChannelInternal);
UdpNm_Internal_TickMessageTimeoutTime(ChannelConf, ChannelInternal);
#if (UDPNM_PASSIVE_MODE_ENABLED != STD_ON)
if ((ChannelInternal->State == NM_STATE_REPEAT_MESSAGE) ||
(ChannelInternal->State == NM_STATE_NORMAL_OPERATION)) {
UdpNm_Internal_TickMessageCycleTime(ChannelConf, ChannelInternal);
}
#endif
if (ChannelInternal->State == NM_STATE_REPEAT_MESSAGE) {
UdpNm_Internal_TickRepeatMessageTime(ChannelConf, ChannelInternal);
}
} else if (ChannelInternal->Mode == NM_MODE_PREPARE_BUS_SLEEP) {
UdpNm_Internal_TickWaitBusSleepTime(ChannelConf, ChannelInternal);
} else {
//Nothing to be done
}
#if ((UDPNM_PNC_EIRA_CALC_ENABLED == STD_ON) && (UDPNM_PNC_COUNT > 0))
if (chanIndex == UDPNM_CHANNEL_INDEX_SHORTEST_PERIOD) {
UdpNm_Internal_TickPnEiraResetTime(ChannelConf->UdpNmMainFunctionPeriod);
}
#endif
#if ((UDPNM_PNC_ERA_CALC_ENABLED == STD_ON) && (UDPNM_PNC_COUNT > 0))
if (TRUE == ChannelConf->UdpNmPnEraCalcEnabled) {
UdpNm_Internal_TickPnEraResetTime(chanIndex);
}
#endif
}
// Timer helpers
// -------------
/** @req SWS_UdpNm_00206 */
/** @req SWS_UdpNm_00117 */
static inline void UdpNm_Internal_TickTimeoutTime( const UdpNm_ChannelType* ChannelConf, UdpNm_Internal_ChannelType* ChannelInternal ){
if (ChannelConf->UdpNmMainFunctionPeriod >= ChannelInternal->TimeoutTimeLeft) {
ChannelInternal->TimeoutTimeLeft = 0;
if (ChannelInternal->State == NM_STATE_REPEAT_MESSAGE) {
#if defined(USE_DEM)
if (UdpNm_ConfigPtr->DemReferences->UdpNmNetworkTimeoutDemEventId != DEM_EVENT_ID_NULL) {
Dem_ReportErrorStatus(UdpNm_ConfigPtr->DemReferences->UdpNmNetworkTimeoutDemEventId, DEM_EVENT_STATUS_FAILED);
}
#endif
UdpNm_Internal_RepeatMessage_to_RepeatMessage(ChannelConf, ChannelInternal);
#if (UDPNM_DEV_ERROR_DETECT == STD_ON)
UDPNM_DET_REPORTERROR(UDPNM_SERVICEID_ARC_MAINFUNCTION, UDPNM_E_NETWORK_TIMEOUT, 0);
#endif
} else if (ChannelInternal->State == NM_STATE_NORMAL_OPERATION) {
#if defined(USE_DEM)
if (UdpNm_ConfigPtr->DemReferences->UdpNmNetworkTimeoutDemEventId != DEM_EVENT_ID_NULL) {
Dem_ReportErrorStatus(UdpNm_ConfigPtr->DemReferences->UdpNmNetworkTimeoutDemEventId, DEM_EVENT_STATUS_FAILED);
}
#endif
UdpNm_Internal_NormalOperation_to_NormalOperation(ChannelConf, ChannelInternal);
#if (UDPNM_DEV_ERROR_DETECT == STD_ON)
UDPNM_DET_REPORTERROR(UDPNM_SERVICEID_ARC_MAINFUNCTION, UDPNM_E_NETWORK_TIMEOUT, 0);
#endif
} else if (ChannelInternal->State == NM_STATE_READY_SLEEP) {
UdpNm_Internal_ReadySleep_to_PrepareBusSleep(ChannelConf, ChannelInternal);
} else {
//Nothing to be done
}
} else {
ChannelInternal->TimeoutTimeLeft -= ChannelConf->UdpNmMainFunctionPeriod;
}
}
static inline void UdpNm_Internal_TickMessageTimeoutTime( const UdpNm_ChannelType* ChannelConf, UdpNm_Internal_ChannelType* ChannelInternal ){
if (ChannelConf->UdpNmMainFunctionPeriod >= ChannelInternal->MessageTimeoutTimeLeft) {
//Nm_TxTimeoutException(ChannelConf->UdpNmComMChannelIdRef); //This NM API is not supported yet
} else {
/* Message Timeout */
ChannelInternal->MessageTimeoutTimeLeft -= ChannelConf->UdpNmMainFunctionPeriod;
}
}
/** @req SWS_UdpNm_00102 */
/** @req SWS_UdpNm_00103 */
/** @req SWS_UdpNm_00106 */
/** @req SWS_UdpNm_00109 */
static inline void UdpNm_Internal_TickRepeatMessageTime( const UdpNm_ChannelType* ChannelConf, UdpNm_Internal_ChannelType* ChannelInternal ){
if (ChannelConf->UdpNmMainFunctionPeriod >= ChannelInternal->RepeatMessageTimeLeft) {
ChannelInternal->RepeatMessageTimeLeft = 0;
if (ChannelInternal->State == NM_STATE_REPEAT_MESSAGE) {
if (TRUE == ChannelInternal->Requested) {
UdpNm_Internal_RepeatMessage_to_NormalOperation(ChannelConf, ChannelInternal);
} else {
UdpNm_Internal_RepeatMessage_to_ReadySleep(ChannelConf, ChannelInternal);
}
}
} else {
ChannelInternal->RepeatMessageTimeLeft -= ChannelConf->UdpNmMainFunctionPeriod;
}
}
/** @req SWS_UdpNm_00115 */
static inline void UdpNm_Internal_TickWaitBusSleepTime( const UdpNm_ChannelType* ChannelConf, UdpNm_Internal_ChannelType* ChannelInternal ){
if (ChannelConf->UdpNmMainFunctionPeriod >= ChannelInternal->WaitBusSleepTimeLeft) {
ChannelInternal->WaitBusSleepTimeLeft = 0;
if (ChannelInternal->Mode == NM_MODE_PREPARE_BUS_SLEEP) {
UdpNm_Internal_PrepareBusSleep_to_BusSleep(ChannelConf, ChannelInternal);
}
} else {
ChannelInternal->WaitBusSleepTimeLeft -= ChannelConf->UdpNmMainFunctionPeriod;
}
}
/** @req SWS_UdpNm_00101 */
/** @req SWS_UdpNm_00005 */
/** @req SWS_UdpNm_00040 */
static inline void UdpNm_Internal_TickMessageCycleTime( const UdpNm_ChannelType* ChannelConf, UdpNm_Internal_ChannelType* ChannelInternal ){
if (ChannelConf->UdpNmMainFunctionPeriod >= ChannelInternal->MessageCycleTimeLeft) {
ChannelInternal->MessageCycleTimeLeft = 0;
if ((ChannelInternal->State == NM_STATE_REPEAT_MESSAGE) ||
(ChannelInternal->State == NM_STATE_NORMAL_OPERATION)) {
UdpNm_Internal_TransmitMessage(ChannelConf, ChannelInternal);
ChannelInternal->MessageCycleTimeLeft = ChannelConf->UdpNmMsgCycleTime;
ChannelInternal->MessageTimeoutTimeLeft = ChannelConf->UdpNmMsgTimeoutTime;
}
} else {
ChannelInternal->MessageCycleTimeLeft -= ChannelConf->UdpNmMainFunctionPeriod;
}
}
// Message helpers
// ---------------
/**
* @brief Handle periodic NM message transmission
* @param ChannelConf channel configuration
* @param ChannelInternal channel internal runtime data
* @return void
*/
/** @req SWS_UdpNm_00032 */
static inline void UdpNm_Internal_TransmitMessage( const UdpNm_ChannelType* ChannelConf,
UdpNm_Internal_ChannelType* ChannelInternal ) {
PduInfoType pdu = {
.SduDataPtr = ChannelInternal->TxMessageSdu,
.SduLength = ChannelConf->UdpNmPduLength,
};
#if ((UDPNM_USER_DATA_ENABLED == STD_ON) && (UDPNM_COM_USER_DATA_SUPPORT == STD_ON))
PduInfoType userData;
userData.SduDataPtr = UdpNm_Internal_GetUserDataPtr(ChannelConf, ChannelInternal->TxMessageSdu);
userData.SduLength = UdpNm_Internal_GetUserDataLength(ChannelConf);
/* IMPROVEMENT: Add Det error when transmit is failing */
/** @req SWS_UdpNm_00317 */
(void) PduR_UdpNmTriggerTransmit(ChannelConf->UdpNmUserDataTxPduId, &userData);
#if ((UDPNM_PNC_EIRA_CALC_ENABLED == STD_ON) && (UDPNM_PNC_COUNT > 0))
if (TRUE == ChannelConf->UdpNmPnEnable) {
UdpNm_Internal_ProcessTxPdu(&pdu.SduDataPtr[UdpNm_ConfigPtr->UdpNmPnInfo->UdpNmPnInfoOffset],
ChannelConf,
ChannelInternal
);
} else {
/* Do nothing */
}
#endif /* ((UDPNM_PNC_EIRA_CALC_ENABLED == STD_ON) && (UDPNM_PNC_COUNT > 0)) */
#endif /* ((UDPNM_USER_DATA_ENABLED == STD_ON) && (UDPNM_COM_USER_DATA_SUPPORT == STD_ON)) */
if (SoAd_IfTransmit(ChannelConf->UdpNmTxPduId, &pdu) != E_OK) {
#if defined(USE_DEM)
if (UdpNm_ConfigPtr->DemReferences->UdpNmNetworkTimeoutDemEventId != DEM_EVENT_ID_NULL) {
Dem_ReportErrorStatus(UdpNm_ConfigPtr->DemReferences->UdpNmTcpIpTransmitErrorDemEventId, DEM_EVENT_STATUS_FAILED);
}
#endif
}
}
static inline uint8 UdpNm_Internal_GetUserDataOffset( const UdpNm_ChannelType* ChannelConf ) {
uint8 userDataPos = 0;
userDataPos += (ChannelConf->UdpNmPduNidPosition == UDPNM_PDU_OFF) ? 0 : 1;
userDataPos += (ChannelConf->UdpNmPduCbvPosition == UDPNM_PDU_OFF) ? 0 : 1;
return userDataPos;
}
static inline uint8* UdpNm_Internal_GetUserDataPtr( const UdpNm_ChannelType* ChannelConf, uint8* MessageSduPtr ) {
uint8 userDataOffset = UdpNm_Internal_GetUserDataOffset(ChannelConf);
return &MessageSduPtr[userDataOffset];
}
static inline uint8 UdpNm_Internal_GetUserDataLength( const UdpNm_ChannelType* ChannelConf ) {
uint8 userDataOffset = UdpNm_Internal_GetUserDataOffset(ChannelConf);
return ChannelConf->UdpNmPduLength - userDataOffset;
}
static inline void UdpNm_Internal_ClearCbv( const UdpNm_ChannelType* ChannelConf, UdpNm_Internal_ChannelType* ChannelInternal ){
if (ChannelConf->UdpNmPduCbvPosition != UDPNM_PDU_OFF) {
ChannelInternal->TxMessageSdu[ChannelConf->UdpNmPduCbvPosition] = 0x00;
}
}
// Transition helpers
// ------------------
/** @req SWS_UdpNm_00096 */
/** @req SWS_UdpNm_00097 */
/** @req SWS_UdpNm_00100 */
static inline void UdpNm_Internal_PrepareBusSleep_to_RepeatMessage( const UdpNm_ChannelType* ChannelConf, UdpNm_Internal_ChannelType* ChannelInternal ) {
ChannelInternal->Mode = NM_MODE_NETWORK;
ChannelInternal->State = NM_STATE_REPEAT_MESSAGE;
ChannelInternal->TimeoutTimeLeft = ChannelConf->UdpNmTimeoutTime + ChannelConf->UdpNmMainFunctionPeriod;
ChannelInternal->RepeatMessageTimeLeft = ChannelConf->UdpNmRepeatMessageTime + ChannelConf->UdpNmMainFunctionPeriod;
ChannelInternal->MessageCycleTimeLeft = ChannelConf->UdpNmMsgCycleOffset + ChannelConf->UdpNmMainFunctionPeriod;
// Notify 'Network Mode'
Nm_NetworkMode(ChannelConf->UdpNmComMChannelIdRef);
}
/** @req SWS_UdpNm_00126 */
static inline void UdpNm_Internal_PrepareBusSleep_to_BusSleep( const UdpNm_ChannelType* ChannelConf, UdpNm_Internal_ChannelType* ChannelInternal ){
ChannelInternal->Mode = NM_MODE_BUS_SLEEP;
ChannelInternal->State = NM_STATE_BUS_SLEEP;
// Notify 'Bus-Sleep Mode'
Nm_BusSleepMode(ChannelConf->UdpNmComMChannelIdRef);
}
static inline void UdpNm_Internal_BusSleep_to_RepeatMessage( const UdpNm_ChannelType* ChannelConf, UdpNm_Internal_ChannelType* ChannelInternal ) {
ChannelInternal->Mode = NM_MODE_NETWORK;
ChannelInternal->State = NM_STATE_REPEAT_MESSAGE;
ChannelInternal->TimeoutTimeLeft = ChannelConf->UdpNmTimeoutTime + ChannelConf->UdpNmMainFunctionPeriod;
ChannelInternal->RepeatMessageTimeLeft = ChannelConf->UdpNmRepeatMessageTime + ChannelConf->UdpNmMainFunctionPeriod;
ChannelInternal->MessageCycleTimeLeft = ChannelConf->UdpNmMsgCycleOffset + ChannelConf->UdpNmMainFunctionPeriod;
// Notify 'Network Mode'
Nm_NetworkMode(ChannelConf->UdpNmComMChannelIdRef);
}
/** @req SWS_UdpNm_00127 */
static inline void UdpNm_Internal_BusSleep_to_BusSleep( const UdpNm_ChannelType* ChannelConf ){
#if (UDPNM_PNC_COUNT == 0)
Nm_NetworkStartIndication(ChannelConf->UdpNmComMChannelIdRef);
#else
/*lint -estring(920,pointer) Cast to void. OK, used depending on the config. */
(void) ChannelConf;
#endif
}
static inline void UdpNm_Internal_RepeatMessage_to_RepeatMessage( const UdpNm_ChannelType* ChannelConf, UdpNm_Internal_ChannelType* ChannelInternal ){
ChannelInternal->TimeoutTimeLeft = ChannelConf->UdpNmTimeoutTime;
}
/*lint -save -e715 Symbol ChannelConf not referenced. OK, depends on the define. */
/** @req SWS_UdpNm_00107 */
static inline void UdpNm_Internal_RepeatMessage_to_ReadySleep( const UdpNm_ChannelType* ChannelConf, UdpNm_Internal_ChannelType* ChannelInternal ){
ChannelInternal->Mode = NM_MODE_NETWORK;
ChannelInternal->State = NM_STATE_READY_SLEEP;
#if (UDPNM_NODE_DETECTION_ENABLED == STD_ON)
UdpNm_Internal_ClearCbv(ChannelConf, ChannelInternal);
#endif
}
/*lint -restore -e715 */
/*lint -save -e715 Symbol ChannelConf not referenced. OK, depends on the define. */
static inline void UdpNm_Internal_RepeatMessage_to_NormalOperation( const UdpNm_ChannelType* ChannelConf, UdpNm_Internal_ChannelType* ChannelInternal ){
ChannelInternal->Mode = NM_MODE_NETWORK;
ChannelInternal->State = NM_STATE_NORMAL_OPERATION;
#if (UDPNM_NODE_DETECTION_ENABLED == STD_ON)
UdpNm_Internal_ClearCbv(ChannelConf, ChannelInternal);
#endif
}
/*lint -restore -e715 */
static inline void UdpNm_Internal_NormalOperation_to_RepeatMessage( const UdpNm_ChannelType* ChannelConf, UdpNm_Internal_ChannelType* ChannelInternal ){
ChannelInternal->Mode = NM_MODE_NETWORK;
ChannelInternal->State = NM_STATE_REPEAT_MESSAGE;
ChannelInternal->RepeatMessageTimeLeft = ChannelConf->UdpNmRepeatMessageTime + ChannelConf->UdpNmMainFunctionPeriod;
ChannelInternal->MessageCycleTimeLeft = ChannelConf->UdpNmMsgCycleOffset + ChannelConf->UdpNmMainFunctionPeriod;
}
/** @req SWS_UdpNm_00118 */
static inline void UdpNm_Internal_NormalOperation_to_ReadySleep( UdpNm_Internal_ChannelType* ChannelInternal ){
ChannelInternal->Mode = NM_MODE_NETWORK;
ChannelInternal->State = NM_STATE_READY_SLEEP;
}
static inline void UdpNm_Internal_NormalOperation_to_NormalOperation( const UdpNm_ChannelType* ChannelConf, UdpNm_Internal_ChannelType* ChannelInternal ){
ChannelInternal->TimeoutTimeLeft = ChannelConf->UdpNmTimeoutTime;
}
static inline void UdpNm_Internal_ReadySleep_to_NormalOperation( const UdpNm_ChannelType* ChannelConf, UdpNm_Internal_ChannelType* ChannelInternal ){
ChannelInternal->Mode = NM_MODE_NETWORK;
ChannelInternal->State = NM_STATE_NORMAL_OPERATION;
ChannelInternal->MessageCycleTimeLeft = ChannelConf->UdpNmMsgCycleOffset + ChannelConf->UdpNmMainFunctionPeriod;
}
/** @req SWS_UdpNm_00114 */
static inline void UdpNm_Internal_ReadySleep_to_PrepareBusSleep( const UdpNm_ChannelType* ChannelConf, UdpNm_Internal_ChannelType* ChannelInternal ){
ChannelInternal->Mode = NM_MODE_PREPARE_BUS_SLEEP;
ChannelInternal->State = NM_STATE_PREPARE_BUS_SLEEP;
ChannelInternal->WaitBusSleepTimeLeft = ChannelConf->UdpNmWaitBusSleepTime;
// Notify 'Prepare Bus-Sleep Mode'
Nm_PrepareBusSleepMode(ChannelConf->UdpNmComMChannelIdRef);
}
static inline void UdpNm_Internal_ReadySleep_to_RepeatMessage( const UdpNm_ChannelType* ChannelConf, UdpNm_Internal_ChannelType* ChannelInternal ){
ChannelInternal->Mode = NM_MODE_NETWORK;
ChannelInternal->State = NM_STATE_REPEAT_MESSAGE;
ChannelInternal->RepeatMessageTimeLeft = ChannelConf->UdpNmRepeatMessageTime + ChannelConf->UdpNmMainFunctionPeriod;
ChannelInternal->MessageCycleTimeLeft = ChannelConf->UdpNmMsgCycleOffset + ChannelConf->UdpNmMainFunctionPeriod;
}
static inline void UdpNm_Internal_NetworkMode_to_NetworkMode( const UdpNm_ChannelType* ChannelConf, UdpNm_Internal_ChannelType* ChannelInternal ){
ChannelInternal->TimeoutTimeLeft = ChannelConf->UdpNmTimeoutTime + ChannelConf->UdpNmMainFunctionPeriod;
}
#if (UDPNM_PNC_COUNT > 0)
#if (UDPNM_PNC_EIRA_CALC_ENABLED == STD_ON)
/**
* @brief UdpNm_Internal_ResetEiraPnBits reset EIRA bits in case of timeout
* @param pnIndex - Indices of PNC which have timed out
* @param indexCount - No of PNC that have timed out
* @return void
*/
static void UdpNm_Internal_ResetEiraPnBits(const uint8 *pnIndex, uint8 indexCount) {
uint8 byteNo;
uint8 bit;
uint8 idx;
for (idx = 0; idx < indexCount; idx++) {
byteNo = pnIndex[idx] / 8;
bit = pnIndex[idx] % 8;
/** @req SWS_UdpNm_00351 */
UdpNm_Internal.pnEIRABytes[byteNo] &= ~(1u << bit); /* Reset PN bit */
}
#if (UDPNM_PDU_RX_INDICATION_ENABLED == STD_ON)
PduInfoType pdu = {
.SduDataPtr = &UdpNm_Internal.pnEIRABytes[0],
.SduLength = UdpNm_ConfigPtr->UdpNmPnInfo->UdpNmPnInfoLen,
};
/** @req SWS_UdpNm_00352 */
PduR_UdpNmRxIndication(UdpNm_ConfigPtr->UdpNmPnInfo->UdpNmEIRARxNSduId, &pdu);
#endif
}
static void UdpNm_Internal_TickPnEiraResetTime(uint32 period) {
uint8 pncIndexReset[UDPNM_PNC_COUNT] = {0};
uint8 len;
len = 0;
uint8 timerIdx;
SchM_Enter_UdpNm_EA_0();
for (timerIdx = 0; timerIdx < UDPNM_PNC_COUNT; timerIdx++) {
if (TRUE == UdpNm_Internal.pnEIRATimers[timerIdx].timerRunning) {
if (period >= UdpNm_Internal.pnEIRATimers[timerIdx].resetTimer) {
UdpNm_Internal.pnEIRATimers[timerIdx].timerRunning = FALSE;
pncIndexReset[len] = UdpNm_ConfigPtr->UdpNmPnInfo->UdpNmTimerIndexToPnMap[timerIdx];
len++;
} else {
UdpNm_Internal.pnEIRATimers[timerIdx].resetTimer -= period;
}
} else {
/* Do nothing */
}
}
if (len > 0) {
UdpNm_Internal_ResetEiraPnBits(pncIndexReset, len);
} else {
/* Do nothing */
}
SchM_Exit_UdpNm_EA_0();
}
/**
* @brief restartPNTimer Restart PN timers
* @param pnIndex - Index of PNC
* @return void
*/
static void restartPNTimer(uint8 pnIndex) {
uint8 timerIndex;
timerIndex = UdpNm_ConfigPtr->UdpNmPnInfo->UdpNmPnIndexToTimerMap[pnIndex];
UdpNm_Internal.pnEIRATimers[timerIndex].timerRunning = TRUE;
UdpNm_Internal.pnEIRATimers[timerIndex].resetTimer = UDPNM_PNC_RESET_TIME;
}
/**
* @brief restartTimerForInternalExternalRequests Identify the PN timer that needs to be restarted
* @param calcEIRA - EIRA of the new received/transmitted and filtered PDU
* @return void
*/
static void restartTimerForInternalExternalRequests(const uint8 *calcEIRA) {
uint8 byteNo;
uint8 bit;
uint8 byteEIRA;
for (byteNo = 0; byteNo < UDPNM_PNC_INFO_LEN; byteNo++) {
byteEIRA = calcEIRA[byteNo];
if (byteEIRA > 0) {
for (bit = 0; bit < 8; bit++) {
if (((byteEIRA >> bit) & UDPNM_LSBIT_MASK) == UDPNM_LSBIT_MASK) {
restartPNTimer((byteNo * 8) + bit); /*lint !e734 Loss of precision. OK, the result will not be bigger than what can fit in 8 bits. */
} else {
/* Do nothing */
}
}
} else {
/* Do nothing */
}
}
}
static void UdpNm_Internal_ProcessTxPdu(const uint8 * const pnInfo,
const UdpNm_ChannelType* ChannelConf,
UdpNm_Internal_ChannelType* ChannelInternal) {
uint8 calculatedEIRA[UDPNM_PNC_INFO_LEN] = {0};
boolean eiraIsZero = TRUE;
/* Using the main function service ID since that is where it is called from. */
UDPNM_VALIDATE_NOTNULL(pnInfo, UDPNM_SERVICEID_ARC_MAINFUNCTION);
for (uint8 byteNo = 0; byteNo < UDPNM_PNC_INFO_LEN; byteNo++) {
/* Accumulate internal requests */
calculatedEIRA[byteNo] = pnInfo[byteNo] & UdpNm_ConfigPtr->UdpNmPnInfo->UdpNmPnInfoMask[byteNo];
if (calculatedEIRA[byteNo] != 0) {
eiraIsZero = FALSE;
}
}
if (FALSE == eiraIsZero) {
/** @req SWS_UdpNm_00348 */
/** @req SWS_UdpNm_00349 */
/** @req SWS_UdpNm_00352 */
UdpNm_Internal_UpdateRequestArray(TRUE, calculatedEIRA, ChannelConf, ChannelInternal);
} else {
/* Do nothing */
}
}
#endif /* (UDPNM_PNC_EIRA_CALC_ENABLED == STD_ON) */
#if (UDPNM_PNC_ERA_CALC_ENABLED == STD_ON)
/**
* @brief restartPNERATimer restart PN timers
* @param pnIndex - Index of PNC
* @return void
*/
static void restartPNERATimer(UdpNm_Internal_ChannelType* ChannelInternal, uint8 pnIndex) {
uint8 timerIndex = UdpNm_ConfigPtr->UdpNmPnInfo->UdpNmPnIndexToTimerMap[pnIndex];
ChannelInternal->pnERATimers[timerIndex].timerRunning = TRUE;
ChannelInternal->pnERATimers[timerIndex].resetTimer = UDPNM_PNC_RESET_TIME;
}
/**
* @brief restartTimerForExternalRequests Identify the PN timer that needs to be restarted
* @param calcERA - ERA of the new received/transmitted and filtered PDU
* @return void
*/
static void restartTimerForExternalRequests(UdpNm_Internal_ChannelType* ChannelInternal,
const uint8 *calcERA) {
uint8 byteNo;
uint8 bit;
uint8 byteERA;
for (byteNo = 0; byteNo < UDPNM_PNC_INFO_LEN; byteNo++) {
byteERA = calcERA[byteNo];
if (byteERA > 0) {
for (bit = 0; bit < 8; bit++) {
if (((byteERA >> bit) & UDPNM_LSBIT_MASK) == UDPNM_LSBIT_MASK) {
restartPNERATimer(ChannelInternal, (byteNo * 8) + bit); /*lint !e734 Loss of precision. OK, the result will not be bigger than what can fit in 8 bits. */
} else {
/* Do nothing */
}
}
} else {
/* Do nothing */
}
}
}
/**
* @brief UdpNm_Internal_ResetEraPnbits Reset ERA bits in case of timeout
* @param pnIndex - Indices of PNC which have timed out
* @param indexCount - No of PNC that have timed out
* @return void
*/
static void UdpNm_Internal_ResetEraPnbits(uint8 chanIndex, const uint8 *pnIndex, uint8 indexCount) {
uint8 byteNo;
uint8 bit;
uint8 idx;
for (idx = 0; idx < indexCount; idx++) {
byteNo = pnIndex[idx] / 8;
bit = pnIndex[idx] % 8;
/** @req SWS_UdpNm_00360 */
UdpNm_Internal.Channels[chanIndex].pnERABytes[byteNo] &= ~(1u << bit); /* Reset PN bit */
}
PduInfoType pdu = {
.SduDataPtr = &UdpNm_Internal.Channels[chanIndex].pnERABytes[0],
.SduLength = UdpNm_ConfigPtr->UdpNmPnInfo->UdpNmPnInfoLen,
};
#if (UDPNM_PDU_RX_INDICATION_ENABLED == STD_ON)
/** @req SWS_UdpNm_00361 */
PduR_UdpNmRxIndication(UdpNm_ConfigPtr->Channels[chanIndex].UdpNmERARxNSduId, &pdu);
#endif
}
static void UdpNm_Internal_TickPnEraResetTime(const uint8 chanIdx) {
uint8 pncIndexReset[UDPNM_PNC_COUNT] = {0};
uint8 len = 0;
uint8 timerIdx;
SchM_Enter_UdpNm_EA_0();
for (timerIdx = 0; timerIdx < UDPNM_PNC_COUNT; timerIdx++) {
if (TRUE == UdpNm_Internal.Channels[chanIdx].pnERATimers[timerIdx].timerRunning) {
if (UdpNm_ConfigPtr->Channels[chanIdx].UdpNmMainFunctionPeriod >= UdpNm_Internal.Channels[chanIdx].pnERATimers[timerIdx].resetTimer) {
UdpNm_Internal.Channels[chanIdx].pnERATimers[timerIdx].timerRunning = FALSE;
pncIndexReset[len] = UdpNm_ConfigPtr->UdpNmPnInfo->UdpNmTimerIndexToPnMap[timerIdx];
len++;
} else {
UdpNm_Internal.Channels[chanIdx].pnERATimers[timerIdx].resetTimer -= UdpNm_ConfigPtr->Channels[chanIdx].UdpNmMainFunctionPeriod;
}
}
}
if (len > 0) {
UdpNm_Internal_ResetEraPnbits(chanIdx, pncIndexReset, len);
}
SchM_Exit_UdpNm_EA_0();
}
#endif /* UDPNM_PNC_ERA_CALC_ENABLED */
static void UdpNm_Internal_UpdateRequestArray(boolean updateEira,
const uint8 *calculatedRa,
const UdpNm_ChannelType *ChannelConf,
UdpNm_Internal_ChannelType *ChannelInternal) {
uint8 oldRequestArray[UDPNM_PNC_INFO_LEN] = {0};
boolean changed = FALSE;
uint8 *requestAggregate = NULL;
PduIdType sduId = 0;
SchM_Enter_UdpNm_EA_0();
#if (UDPNM_PNC_EIRA_CALC_ENABLED == STD_ON)
if (TRUE == updateEira) {
restartTimerForInternalExternalRequests(calculatedRa);
memcpy(&oldRequestArray[0], &UdpNm_Internal.pnEIRABytes[0], UDPNM_PNC_INFO_LEN);
requestAggregate = &UdpNm_Internal.pnEIRABytes[0];
sduId = UdpNm_ConfigPtr->UdpNmPnInfo->UdpNmEIRARxNSduId;
}
#endif
#if ((UDPNM_PNC_EIRA_CALC_ENABLED == STD_OFF) && (UDPNM_PNC_ERA_CALC_ENABLED == STD_ON))
if (!updateEira) {
#elif ((UDPNM_PNC_EIRA_CALC_ENABLED == STD_ON) && (UDPNM_PNC_ERA_CALC_ENABLED == STD_ON))
else {
#endif
#if (UDPNM_PNC_ERA_CALC_ENABLED == STD_ON)
restartTimerForExternalRequests(ChannelInternal, calculatedRa);
memcpy(&oldRequestArray[0], &ChannelInternal->pnERABytes[0], UDPNM_PNC_INFO_LEN);
requestAggregate = &ChannelInternal->pnERABytes[0];
sduId = ChannelConf->UdpNmERARxNSduId;
}
#endif
#if (((UDPNM_PNC_EIRA_CALC_ENABLED == STD_OFF) && (UDPNM_PNC_ERA_CALC_ENABLED == STD_ON)) || ((UDPNM_PNC_EIRA_CALC_ENABLED == STD_ON) && (UDPNM_PNC_ERA_CALC_ENABLED == STD_OFF)))
else {
/* We only end up here if only EIRA or ERA is enabled and the updateEira
* parameter does not match this which means a programming error.
* Improvement: Add Det error. */
return;
}
#endif
for (uint8 i = 0; i < UDPNM_PNC_INFO_LEN; i++) {
requestAggregate[i] |= calculatedRa[i];
if (requestAggregate[i] != oldRequestArray[i]) {
changed = TRUE;
}
}
SchM_Exit_UdpNm_EA_0();
#if (UDPNM_PDU_RX_INDICATION_ENABLED == STD_ON)
if (TRUE == changed) {
PduInfoType pdu = {
.SduDataPtr = requestAggregate,
.SduLength = UdpNm_ConfigPtr->UdpNmPnInfo->UdpNmPnInfoLen,
};
PduR_UdpNmRxIndication(sduId, &pdu);
} else {
/* Do nothing */
}
#else /* (UDPNM_PDU_RX_INDICATION_ENABLED == STD_ON) */
(void) changed;
#endif /* (UDPNM_PDU_RX_INDICATION_ENABLED == STD_OFF) */
}
static Std_ReturnType UdpNm_Internal_RxProcess(
const UdpNm_ChannelType* ChannelConf,
UdpNm_Internal_ChannelType* ChannelInternal,
boolean pni) {
uint8 calculatedRequestArray[UDPNM_PNC_INFO_LEN] = {0};
uint8 i;
Std_ReturnType ret;
boolean requestArrayIsZero;
requestArrayIsZero = TRUE;
/** @req SWS_UdpNm_00328 *//* No pn normal reception */
/** @req SWS_UdpNm_00329 *//* No pni in cbv - normal reception */
ret = E_OK;
if ((TRUE == ChannelConf->UdpNmPnEnable)
&& (TRUE == pni)){
/** @req SWS_UdpNm_00331 */
/* NM PDU Filter Algorithm */
/** @req SWS_UdpNm_00335 */
/** @req SWS_UdpNm_00336 */
/** @req SWS_UdpNm_00337 */
/** @req SWS_UdpNm_00338 */
/** @req SWS_UdpNm_00339 */
for (i = 0; i < UDPNM_PNC_INFO_LEN; i++) {
calculatedRequestArray[i] = ChannelInternal->RxMessageSdu[UdpNm_ConfigPtr->UdpNmPnInfo->UdpNmPnInfoOffset + i] &
UdpNm_ConfigPtr->UdpNmPnInfo->UdpNmPnInfoMask[i]; /* Accumulate external requests */
if (calculatedRequestArray[i] != 0) {
requestArrayIsZero = FALSE;
}
}
if (FALSE == requestArrayIsZero) {
#if (UDPNM_PNC_EIRA_CALC_ENABLED == STD_ON)
/** @req SWS_UdpNm_00347 */
/** @req SWS_UdpNm_00349 */
/** @req SWS_UdpNm_00352 */
UdpNm_Internal_UpdateRequestArray(TRUE, calculatedRequestArray, ChannelConf, ChannelInternal);
#endif /* (UDPNM_PNC_EIRA_CALC_ENABLED == STD_ON) */
#if (UDPNM_PNC_ERA_CALC_ENABLED == STD_ON)
if (TRUE == ChannelConf->UdpNmPnEraCalcEnabled) {
/** @req SWS_UdpNm_00357 */
/** @req SWS_UdpNm_00359 */
/** @req SWS_UdpNm_00361 */
UdpNm_Internal_UpdateRequestArray(FALSE, calculatedRequestArray, ChannelConf, ChannelInternal);
}
#endif /* (UDPNM_PNC_ERA_CALC_ENABLED == STD_ON) */
}
}
return ret;
}
static void UdpNm_Internal_SetPniCbv(
const UdpNm_ChannelType* ChannelConf,
UdpNm_Internal_ChannelType* ChannelInternal) {
if (ChannelConf->UdpNmPduCbvPosition != UDPNM_PDU_OFF) {
ChannelInternal->TxMessageSdu[ChannelConf->UdpNmPduCbvPosition] |= UDPNM_CBV_PNI;
}
}
#endif /* (UDPNM_PNC_COUNT > 0) */
#ifdef HOST_TEST
void UdpNm_Test_GetChannelRunTimeData(uint32 channelId, uint32* messageCycleTimeLeft, uint32* timeoutTimeLeft) {
const UdpNm_Internal_ChannelType* ChannelInternal = &UdpNm_Internal.Channels[channelId];
*messageCycleTimeLeft = ChannelInternal->MessageCycleTimeLeft;
*timeoutTimeLeft = ChannelInternal->TimeoutTimeLeft;
}
void UdpNm_Test_GetCbvPosition(uint32 channelId, UdpNm_PduPositionType* UdpCbvPosition) {
const UdpNm_Internal_ChannelType* ChannelInternal = &UdpNm_Internal.Channels[channelId];
const NetworkHandleType chanIndex = UdpNm_ConfigPtr->ChannelMap[channelId];
const UdpNm_ChannelType* ChannelConf = &UdpNm_ConfigPtr->Channels[chanIndex];
*UdpCbvPosition = (UdpNm_PduPositionType)ChannelInternal->TxMessageSdu[ChannelConf->UdpNmPduCbvPosition];
}
#if (UDPNM_PNC_COUNT > 0)
Std_ReturnType UdpNm_Test_VerifyAllEiraBitsZero(void) {
Std_ReturnType ret;
ret = E_OK;
for (uint8 i = 0; i < UDPNM_PNC_INFO_LEN; i++) {
if (UdpNm_Internal.pnEIRABytes[i] != 0) {
ret = E_NOT_OK;
break;
}
}
return ret;
}
Std_ReturnType UdpNm_Test_VerifyAllEraBitsZero(void) {
Std_ReturnType ret;
ret = E_OK;
for (uint8 chanIndex = 0; chanIndex < UDPNM_CHANNEL_COUNT; chanIndex++) {
for (uint8 eraByteindex = 0; eraByteindex < UDPNM_PNC_INFO_LEN; eraByteindex++) {
if (UdpNm_Internal.Channels[chanIndex].pnERABytes[eraByteindex] != 0) {
ret= E_NOT_OK;
break;
}
}
}
return ret;
}
boolean UdpNm_Test_IsPnEiraBitSet(uint8 eiraByteIndex, uint8 pnBitIndex) {
return (UdpNm_Internal.pnEIRABytes[eiraByteIndex] & (1u << pnBitIndex)) == (1u << pnBitIndex);
}
boolean UdpNm_Test_IsPnEraBitSet(uint8 chanIndex, uint8 eraByteIndex, uint8 pnBitIndex) {
boolean ret;
ret = FALSE;
if ((UdpNm_Internal.Channels[chanIndex].pnERABytes[eraByteIndex] & (1u << pnBitIndex)) == (1u << pnBitIndex)) {
ret = TRUE;
}
return ret;
}
uint32 UdpNm_Test_GetEiraResetTimer(uint8 pnIdx) {
return UdpNm_Internal.pnEIRATimers[UdpNm_ConfigPtr->UdpNmPnInfo->UdpNmPnIndexToTimerMap[pnIdx]].resetTimer;
}
uint32 UdpNm_Test_GetEraResetTimer(uint8 chanIdx, uint8 pnIdx) {
uint8 timerIdx = UdpNm_ConfigPtr->UdpNmPnInfo->UdpNmPnIndexToTimerMap[pnIdx];
return UdpNm_Internal.Channels[chanIdx].pnERATimers[timerIdx].resetTimer;
}
#endif /* (UDPNM_PNC_COUNT > 0) */
#endif /* HOST_TEST */
|
2301_81045437/classic-platform
|
communication/UdpNm/src/UdpNm.c
|
C
|
unknown
| 55,283
|
/*-------------------------------- Arctic Core ------------------------------
* Copyright (C) 2013, ArcCore AB, Sweden, www.arccore.com.
* Contact: <contact@arccore.com>
*
* You may ONLY use this file:
* 1)if you have a valid commercial ArcCore license and then in accordance with
* the terms contained in the written license agreement between you and ArcCore,
* or alternatively
* 2)if you follow the terms found in GNU General Public License version 2 as
* published by the Free Software Foundation and appearing in the file
* LICENSE.GPL included in the packaging of this file or here
* <http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt>
*-------------------------------- Arctic Core -----------------------------*/
#ifndef UDPNM_INTERNAL_H_
#define UDPNM_INTERNAL_H_
/*lint -emacro(904,UDPNM_VALIDATE,UDPNM_VALIDATE_INIT,UDPNM_VALIDATE_CHANNEL,UDPNM_VALIDATE_NOTNULL,UDPNM_VALIDATE_PDUID) 904 PC-Lint exception to MISRA 14.7 (validate DET macros) */
/** @req SWS_UdpNm_00223 @req SWS_UdpNm_00189 @req SWS_UdpNm_00190 @req SWS_UdpNm_00210 @req SWS_UdpNm_00196 */
#if (UDPNM_DEV_ERROR_DETECT == STD_ON)
#define UDPNM_DET_REPORTERROR(serviceId, errorId, instanceId) \
(void)Det_ReportError(UDPNM_MODULE_ID, (uint8)instanceId, serviceId, errorId)
#define UDPNM_VALIDATE(expression, serviceId, errorId, instanceId, ...) \
if (!(expression)) { \
UDPNM_DET_REPORTERROR(serviceId, errorId, instanceId); \
return __VA_ARGS__; \
}
#else
#define UDPNM_DET_REPORTERROR(...)
#define UDPNM_VALIDATE(...)
#endif
/** @req SWS_UdpNm_00191 */
#define UDPNM_VALIDATE_INIT(serviceID, ...) \
UDPNM_VALIDATE((UdpNm_Internal.InitStatus == UDPNM_INIT), serviceID, UDPNM_E_NO_INIT, 0, __VA_ARGS__)
/** @req SWS_UdpNm_00192 */
#define UDPNM_VALIDATE_CHANNEL(channel, serviceID, ...) \
UDPNM_VALIDATE( ((channel < UdpNm_ConfigPtr->ChannelMapSize) && ( UdpNm_ConfigPtr->ChannelMap[channel] < UDPNM_CHANNEL_COUNT )), serviceID, UDPNM_E_INVALID_CHANNEL, channel, __VA_ARGS__)
#define UDPNM_VALIDATE_NOTNULL(ptr, serviceID, ...) \
UDPNM_VALIDATE( (ptr != NULL), serviceID, UDPNM_E_PARAM_POINTER, 0, __VA_ARGS__)
#define UDPNM_VALIDATE_PDUID(pduid, serviceID, ...) \
UDPNM_VALIDATE( (pduid < UDPNM_CHANNEL_COUNT), serviceID, UDPNM_E_INVALID_CHANNEL, pduid, __VA_ARGS__)
#define UDPNM_CBV_PNI 0x40u
#define UDPNM_LSBIT_MASK 0x1u
typedef enum {
UDPNM_INIT,
UDPNM_UNINIT
} UdpNm_InitStatusType;
#if (UDPNM_PNC_COUNT > 0)
typedef struct{
uint32 resetTimer;
boolean timerRunning;
} UdpNm_Internal_PnTimerType;
#endif
typedef struct {
Nm_ModeType Mode;
Nm_StateType State;
boolean Requested;
uint32 TimeoutTimeLeft;
uint32 RepeatMessageTimeLeft;
uint32 WaitBusSleepTimeLeft;
uint32 MessageCycleTimeLeft;
uint32 MessageTimeoutTimeLeft;
uint8 TxMessageSdu[8];
uint8 RxMessageSdu[8];
#if (UDPNM_PNC_COUNT > 0)
/* @req SWS_UdpNm_00358 */
/* @req SWS_UdpNm_00371 */
UdpNm_Internal_PnTimerType pnERATimers[UDPNM_PNC_COUNT];
uint8 pnERABytes[UDPNM_PNC_INFO_LEN];
#endif
} UdpNm_Internal_ChannelType;
typedef struct {
UdpNm_InitStatusType InitStatus;
UdpNm_Internal_ChannelType Channels[UDPNM_CHANNEL_COUNT];
#if (UDPNM_PNC_COUNT > 0)
/* @req SWS_UdpNm_00345 */
/* @req SWS_UdpNm_00372 */
UdpNm_Internal_PnTimerType pnEIRATimers[UDPNM_PNC_COUNT];
uint8 pnEIRABytes[UDPNM_PNC_INFO_LEN];
#endif
} UdpNm_InternalType;
/* Timer helpers */
static inline void UdpNm_Internal_TickTimeoutTime( const UdpNm_ChannelType* ChannelConf, UdpNm_Internal_ChannelType* ChannelInternal );
static inline void UdpNm_Internal_TickMessageTimeoutTime( const UdpNm_ChannelType* ChannelConf, UdpNm_Internal_ChannelType* ChannelInternal );
static inline void UdpNm_Internal_TickRepeatMessageTime( const UdpNm_ChannelType* ChannelConf, UdpNm_Internal_ChannelType* ChannelInternal );
static inline void UdpNm_Internal_TickWaitBusSleepTime( const UdpNm_ChannelType* ChannelConf, UdpNm_Internal_ChannelType* ChannelInternal );
static inline void UdpNm_Internal_TickMessageCycleTime( const UdpNm_ChannelType* ChannelConf, UdpNm_Internal_ChannelType* ChannelInternal );
/* Message helpers */
static inline void UdpNm_Internal_TransmitMessage( const UdpNm_ChannelType* ChannelConf, UdpNm_Internal_ChannelType* ChannelInternal );
static inline uint8 UdpNm_Internal_GetUserDataOffset( const UdpNm_ChannelType* ChannelConf );
static inline uint8* UdpNm_Internal_GetUserDataPtr( const UdpNm_ChannelType* ChannelConf, uint8* MessageSduPtr );
static inline uint8 UdpNm_Internal_GetUserDataLength( const UdpNm_ChannelType* ChannelConf );
static inline void UdpNm_Internal_ClearCbv( const UdpNm_ChannelType* ChannelConf, UdpNm_Internal_ChannelType* ChannelInternal );
/* Transition helpers */
static inline void UdpNm_Internal_PrepareBusSleep_to_RepeatMessage( const UdpNm_ChannelType* ChannelConf, UdpNm_Internal_ChannelType* ChannelInternal );
static inline void UdpNm_Internal_PrepareBusSleep_to_BusSleep( const UdpNm_ChannelType* ChannelConf, UdpNm_Internal_ChannelType* ChannelInternal );
static inline void UdpNm_Internal_BusSleep_to_RepeatMessage( const UdpNm_ChannelType* ChannelConf, UdpNm_Internal_ChannelType* ChannelInternal );
static inline void UdpNm_Internal_BusSleep_to_BusSleep( const UdpNm_ChannelType* ChannelConf );
static inline void UdpNm_Internal_RepeatMessage_to_RepeatMessage( const UdpNm_ChannelType* ChannelConf, UdpNm_Internal_ChannelType* ChannelInternal );
static inline void UdpNm_Internal_RepeatMessage_to_ReadySleep( const UdpNm_ChannelType* ChannelConf, UdpNm_Internal_ChannelType* ChannelInternal );
static inline void UdpNm_Internal_RepeatMessage_to_NormalOperation( const UdpNm_ChannelType* ChannelConf, UdpNm_Internal_ChannelType* ChannelInternal );
static inline void UdpNm_Internal_NormalOperation_to_RepeatMessage( const UdpNm_ChannelType* ChannelConf, UdpNm_Internal_ChannelType* ChannelInternal );
static inline void UdpNm_Internal_NormalOperation_to_ReadySleep( UdpNm_Internal_ChannelType* ChannelInternal );
static inline void UdpNm_Internal_NormalOperation_to_NormalOperation( const UdpNm_ChannelType* ChannelConf, UdpNm_Internal_ChannelType* ChannelInternal );
static inline void UdpNm_Internal_ReadySleep_to_NormalOperation( const UdpNm_ChannelType* ChannelConf, UdpNm_Internal_ChannelType* ChannelInternal );
static inline void UdpNm_Internal_ReadySleep_to_PrepareBusSleep( const UdpNm_ChannelType* ChannelConf, UdpNm_Internal_ChannelType* ChannelInternal );
static inline void UdpNm_Internal_ReadySleep_to_RepeatMessage( const UdpNm_ChannelType* ChannelConf, UdpNm_Internal_ChannelType* ChannelInternal );
static inline void UdpNm_Internal_NetworkMode_to_NetworkMode( const UdpNm_ChannelType* ChannelConf, UdpNm_Internal_ChannelType* ChannelInternal );
#if (UDPNM_PNC_COUNT > 0)
/**
* @brief UdpNm_Internal_UpdateRequestArray A helper function to update the request array.
* @param updateEira TRUE if EIRA should be updated, FALSE if ERA should be updated.
* @param calculatedRa The data filtered with the pn filter mask.
* @param ChannelConf
* @param ChannelInternal
*/
static void UdpNm_Internal_UpdateRequestArray(boolean updateEira,
const uint8 *calculatedRa,
const UdpNm_ChannelType *ChannelConf,
UdpNm_Internal_ChannelType *ChannelInternal);
/**
* @brief NM filtering process done for each reception
* @param ChannelConf - Channel configuration
* @param ChannelInternal - Channel internal runtime data
* @param pni - PNI bit set in CBV?
* @return Reception valid or not
*/
static Std_ReturnType UdpNm_Internal_RxProcess(
const UdpNm_ChannelType* ChannelConf,
UdpNm_Internal_ChannelType* ChannelInternal,
boolean pni );
/**
* @brief UdpNm_Internal_ProcessTxPdu Pn filtering done for each send
* @param ChannelConf - Channel configuration
* @param ChannelInternal - Channel internal runtime data
* @return void
*/
static void UdpNm_Internal_ProcessTxPdu(const uint8 * const pnInfo,
const UdpNm_ChannelType* ChannelConf,
UdpNm_Internal_ChannelType* ChannelInternal);
/**
* @brief Set the PNI bit in CBV byte of Nm Pdu
* @param ChannelConf - channel configuration
* @param ChannelInternal - channel internal runtime data
* @return void
*/
static void UdpNm_Internal_SetPniCbv(
const UdpNm_ChannelType* ChannelConf,
UdpNm_Internal_ChannelType* ChannelInternal);
#if (UDPNM_PNC_EIRA_CALC_ENABLED == STD_ON)
/**
* @brief UdpNm_Internal_TickPnEiraResetTime Run PN reset timers every main function cycle
* @param void
* @return void
*/
static void UdpNm_Internal_TickPnEiraResetTime(uint32 period);
#endif /* (UDPNM_PNC_EIRA_CALC_ENABLED == STD_ON) */
#if (UDPNM_PNC_ERA_CALC_ENABLED == STD_ON)
/**
* @brief UdpNm_Internal_TickPnEraResetTime Run PN reset timers every main function cycle
* @param chanIdx
* @return
*/
static void UdpNm_Internal_TickPnEraResetTime(const uint8 chanIdx);
#endif /* (UDPNM_PNC_ERA_CALC_ENABLED == STD_ON) */
#endif /* (UDPNM_PNC_COUNT > 0) */
#endif /* UDPNM_INTERNAL_H_ */
|
2301_81045437/classic-platform
|
communication/UdpNm/src/UdpNm_Internal.h
|
C
|
unknown
| 9,410
|
# Xcp
obj-$(USE_XCP) += Xcp.o
obj-$(USE_XCP) += Xcp_FlashProgramming.o
obj-$(USE_XCP) += Xcp_OnlineCalibration.o
obj-$(USE_XCP) += Xcp_MemoryHelper.o
obj-$(USE_XCP) += Xcp_Cfg.o
obj-$(USE_XCP)-$(USE_CANIF) += XcpOnCan.o
obj-$(USE_XCP)-$(USE_SOAD) += XcpOnEth.o
ifeq ($(filter Xcp_Callout_Stubs.o,$(obj-y)),)
obj-$(USE_XCP) += Xcp_Callout_Stubs.o
endif
inc-$(USE_XCP) += $(ROOTDIR)/communication/Xcp/inc
inc-$(USE_XCP) += $(ROOTDIR)/communication/Xcp/src
vpath-$(USE_XCP) += $(ROOTDIR)/communication/Xcp/src
vpath-$(USE_XCP) += $(ROOTDIR)/communication/Xcp/integration
|
2301_81045437/classic-platform
|
communication/Xcp/Xcp.mod.mk
|
Makefile
|
unknown
| 590
|
/*-------------------------------- Arctic Core ------------------------------
* Copyright (C) 2013, ArcCore AB, Sweden, www.arccore.com.
* Contact: <contact@arccore.com>
*
* You may ONLY use this file:
* 1)if you have a valid commercial ArcCore license and then in accordance with
* the terms contained in the written license agreement between you and ArcCore,
* or alternatively
* 2)if you follow the terms found in GNU General Public License version 2 as
* published by the Free Software Foundation and appearing in the file
* LICENSE.GPL included in the packaging of this file or here
* <http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt>
*-------------------------------- Arctic Core -----------------------------*/
/** @reqSettings DEFAULT_SPECIFICATION_REVISION=4.1.3 */
/** @req 4.1.3/SWS_Xcp_00505 */ /*Provide Xcp.h - can not be tested with conventional module tests*/
#ifndef XCP_H_
#define XCP_H_
/*********************************************
* MODULE PARAMETERS *
*********************************************/
#define XCP_VENDOR_ID 60u
#define XCP_MODULE_ID 210u
#define XCP_SW_MAJOR_VERSION 2u
#define XCP_SW_MINOR_VERSION 0u
#define XCP_SW_PATCH_VERSION 0u
#define XCP_AR_RELEASE_MAJOR_VERSION 4u
#define XCP_AR_RELEASE_MINOR_VERSION 1u
#define XCP_AR_RELEASE_REVISION_VERSION 3u
#define XCP_PROTOCOL_MAJOR_VERSION 1u
#define XCP_PROTOCOL_MINOR_VERSION 0u
#define XCP_TRANSPORT_MAJOR_VERSION 1u
#define XCP_TRANSPORT_MINOR_VERSION 0u
#include "Xcp_Cfg.h"
#include "Xcp_ConfigTypes.h"
#if XCP_PROTOCOL == XCP_PROTOCOL_CAN
#include "XcpOnCan_Cbk.h"
#elif XCP_PROTOCOL == XCP_PROTOCOL_ETHERNET
#include "XcpOnEth_Cbk.h"
#endif
/*********************************************
* MAIN FUNCTIONS *
*********************************************/
/* This definitions are coming from ASR XCP Spec to identify Api Ids for Det report*/
#define XCP_API_ID_XCP_INIT 0x00u
#define XCP_API_ID_XCP_GETVERSIONINFO 0x01u
#define XCP_API_ID_XCP_RX_INDICATION 0x03u
#define XCP_API_ID_XCP_TX_CONFIRMATION 0x02u
#define XCP_API_ID_XCP_TRIGGERTRANSMIT 0x41u
#define XCP_API_ID_XCP_SETTRANSMISSIONMODE 0x05u
#define XCP_API_ID_XCP_MAINFUNCTION 0x04u
/* This definitions are necessary to identify additional Api Ids for Det report*/
#define XCP_API_ID_XCP_FIFO_GET 0xFFu
#define XCP_API_ID_XCP_FIFO_PUT 0xFEu
#define XCP_API_ID_XCP_FIFO_FREE 0xFDu
#define XCP_API_ID_XCP_FIFO_INIT 0xFBu
#define XCP_API_ID_XCP_PROCESSDAQ 0xFAu
#define XCP_API_ID_XCP_PROCESSCHANNEL 0xF9u
#define XCP_API_ID_XCP_TRANSMIT 0xF8u
/* Error Ids coming from ASR XCP*/
#define XCP_E_INIT_FAILED 0x04u
#define XCP_E_INV_POINTER 0x01u
#define XCP_E_NOT_INITIALIZED 0x02u
#define XCP_E_INVALID_PDUID 0x03u
#define XCP_E_NULL_POINTER 0x12u
#define XCP_E_INVALID_EVENT 0x13u
/* Additional Error Ids, necessary to identify more erroneous situation*/
#define XCP_E_MESSAGE_LOST 0xFFu
#if (XCP_VERSION_INFO_API == STD_ON)
void Xcp_GetVersionInfo(Std_VersionInfoType* versionInfo);
#endif /*XCP_VERION_INFO_API == STD_ON*/
void Xcp_Init(const Xcp_ConfigType* Xcp_ConfigPtr);
void Xcp_MainFunction(void);
void Xcp_MainFunction_Channel(uint32 channel);
#endif /* XCP_H_ */
|
2301_81045437/classic-platform
|
communication/Xcp/inc/Xcp.h
|
C
|
unknown
| 3,493
|
/*-------------------------------- Arctic Core ------------------------------
* Copyright (C) 2013, ArcCore AB, Sweden, www.arccore.com.
* Contact: <contact@arccore.com>
*
* You may ONLY use this file:
* 1)if you have a valid commercial ArcCore license and then in accordance with
* the terms contained in the written license agreement between you and ArcCore,
* or alternatively
* 2)if you follow the terms found in GNU General Public License version 2 as
* published by the Free Software Foundation and appearing in the file
* LICENSE.GPL included in the packaging of this file or here
* <http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt>
*-------------------------------- Arctic Core -----------------------------*/
/** @reqSettings DEFAULT_SPECIFICATION_REVISION=4.1.3 */
#ifndef XCP_CALLOUT_STUBS_H_
#define XCP_CALLOUT_STUBS_H_
#include "Xcp_Internal.h"
/**
* Function is used to initialize MTA (Memory Transfer Address) and its proper functions
* which shall be used when XCP reads and writes ceratin memory sections
* @param mta (output) Memory Transfer Address
* @param address (input) This value is sent by XCP Master tool
* @param extension (input) This value is sent by XCP Master tool
*/
extern void Xcp_Arc_MtaInit(
Xcp_MtaType* mta,
uint32 address,
uint8 extension);
/**
* This function is responsible to calculate the intended checksum algorithm, at the given example
* XCP_CHECKSUM_ADD_11 is used
* @param mtaPtr
* @param block (input) length of the block where the CRC is calculated
* @param type (output) type of the CRC calculation.
* @param response (output) the result of the CRC calculation over the block
*/
extern void Xcp_Arc_BuildChecksum(
Xcp_MtaType* mtaPtr,
uint32 block,
Xcp_ChecksumType* type,
uint32* response);
#if (XCP_FEATURE_PROTECTION == STD_ON)
/**
* Function called to retrieve seed that should be
* sent to master in a GetSeed/Unlock exchange
* @param res is the resource requested
* @param seed pointer to buffer that will hold seed (255 bytes max)
* @return number of bytes in seed
*/
extern uint8 Xcp_Arc_GetSeed(
Xcp_ProtectType res,
uint8* seed);
/**
* Function used for Seed & Key unlock
* @param res is the resource requested to be unlocked
* @param seed is the seed that was sent to the master
* @param seed_len is the length of @param seed
* @param key is the key sent from master
* @param key_len is the length of @param key
* @return E_OK for success, E_ERR for failure
*/
extern Std_ReturnType Xcp_Arc_Unlock(
Xcp_ProtectType res,
const uint8* seed,
uint8 seed_len,
const uint8* key,
uint8 key_len);
#endif /* XCP_FEATURE_PROTECTION == STD_ON */
#if(XCP_FEATURE_CALPAG == STD_ON)
/**
*
* @param mode
* @param segm
* @param page
* @param error
* @return
*/
Std_ReturnType Xcp_Arc_SetCalPage(
const uint8 mode,
const uint8 segm,
const uint8 page,
Xcp_ErrorType *error);
/**
*
* @param mode
* @param segm
* @param page
* @param error
* @return
*/
Std_ReturnType Xcp_Arc_GetCalPage(
const uint8 mode,
const uint8 segm,
uint8 *page,
Xcp_ErrorType *error);
/**
*
* @param sourceSegm
* @param sourcePage
* @param destSegm
* @param destPage
* @param error
* @return
*/
Std_ReturnType Xcp_Arc_CopyCalPage(
const uint8 sourceSegm,
const uint8 sourcePage,
const uint8 destSegm,
const uint8 destPage,
Xcp_ErrorType *error);
/**
*
* @param maxSegment
* @param error
* @return
*/
Std_ReturnType Xcp_Arc_GetPagProcessorInfo(
uint8 *maxSegment,
Xcp_ErrorType *error);
/**
*
* @param segmentNumber
* @param segmentInfo
* @param basicInfo
* @param error
* @return
*/
Std_ReturnType Xcp_Arc_GetSegmentInfo_GetBasicAddress(
const uint8 segmentNumber,
const uint8 segmentInfo,
uint32 *basicInfo,
Xcp_ErrorType *error);
/**
*
* @param segmentNumber
* @param responseData
* @param error
* @return
*/
Std_ReturnType Xcp_Arc_GetSegmentInfo_GetStandardInfo(
const uint8 segmentNumber,
Xcp_SegmentStandardInfoReturnType *responseData,
Xcp_ErrorType *error);
/**
*
* @param segmentNumber
* @param segmentInfo
* @param mappingInfo
* @param error
* @return
*/
Std_ReturnType Xcp_Arc_GetSegmentInfo_GetAddressMapping(
const uint8 segmentNumber,
const uint8 segmentInfo,
uint32 *mappingInfo,
Xcp_ErrorType *error);
/**
*
* @param segmentNumber
* @param pageNumber
* @param pageProperties
* @param initSegment
* @param error
* @return
*/
Std_ReturnType Xcp_Arc_GetPageInfo(
const uint8 segmentNumber,
const uint8 pageNumber,
uint8 *pageProperties,
uint8 *initSegment,
Xcp_ErrorType *error);
/**
*
* @param mode
* @param segmentNumber
* @param error
* @return
*/
Std_ReturnType Xcp_Arc_SetSegmentMode(
const uint8 mode,
const uint8 segmentNumber,
Xcp_ErrorType *error);
/**
*
* @param segmentNumber
* @param mode
* @param error
* @return
*/
Std_ReturnType Xcp_Arc_GetSegmentMode(
const uint8 segmentNumber,
uint8 *mode,
Xcp_ErrorType *error);
#endif /*XCP_FEATURE_CALPAG == STD_ON*/
#if(XCP_FEATURE_PGM == STD_ON)
/**
*
* @param clearRange
* @param error
* @return
*/
Std_ReturnType Xcp_Arc_ProgramClear_FunctionalAccess(
const uint32 clearRange,
Xcp_ErrorType *error);
/**
*
* @param mta
* @param clearRange
* @param error
* @return
*/
Std_ReturnType Xcp_Arc_ProgramClear_AbsoluteAccess(
Xcp_MtaType* mta,
const uint32 clearRange,
Xcp_ErrorType *error);
/**
*
* @param error
* @return
*/
Std_ReturnType Xcp_Arc_ProgramReset(
Xcp_ErrorType *error);
/**
*
* @param pgmProperties
* @param maxSector
* @param error
* @return
*/
Std_ReturnType Xcp_Arc_GetPgmProcessorInfo(
uint8 *pgmProperties,
uint8 *maxSector,
Xcp_ErrorType *error);
/**
*
* @param mode
* @param sectorNumber
* @param responseData
* @param error
* @return
*/
Std_ReturnType Xcp_Arc_GetSectorInfo_Mode0_1(
const uint8 mode,
const uint8 sectorNumber,
Xcp_GetSectorInfo_Mode0_1_ReturnType *responseData,
Xcp_ErrorType *error);
/**
*
* @param sectorNameLength
* @param error
* @return
*/
Std_ReturnType Xcp_Arc_GetSectorInfo_Mode2(
uint8 *sectorNameLength,
Xcp_ErrorType *error);
/**
*
* @param mta
* @param codeSize
* @param error
* @return
*/
Std_ReturnType Xcp_Arc_ProgramPrepare(
Xcp_MtaType* mta,
uint16 codeSize,
Xcp_ErrorType *error);
/**
*
* @param compressionMethod
* @param encryptionMethod
* @param programmingMethod
* @param accessMethod
* @param error
* @return
*/
Std_ReturnType Xcp_Arc_ProgramFormat(
const uint8 compressionMethod,
const uint8 encryptionMethod,
const uint8 programmingMethod,
const uint8 accessMethod,
Xcp_ErrorType *error);
/**
*
* @param mode
* @param type
* @param value
* @param error
* @return
*/
Std_ReturnType Xcp_Arc_ProgramVerify(
const uint8 mode,
const uint8 type,
const uint8 value,
Xcp_ErrorType *error);
/**
* Flash algorithm must be place here, Post increment of the MTA shall be performed here
* @param mta
* @param data
* @param len
* @param error
* @return
*/
Std_ReturnType Xcp_Arc_Program(
Xcp_MtaType* mta,
uint8* data,
uint32 len,
Xcp_ErrorType *error);
#endif /*XCP_FEATURE_PGM == STD_ON*/
/**
* This function together with Xcp_Arc_RecievePduAllowed is used to dynamically allow certain Pdus to receive and transmit messages.
* With the help of these functions the user can enable, disable certain communication channels, and in this way different session handling of
* Xcp can be performed.
* @param XcpTxPduId This Pdu Id is intended to use to send out Xcp message
* @return TRUE XcpTxPduId is allowed to use in this session
* FALSE XcpTxPduId is not allowed to use in this session
*/
boolean Xcp_Arc_TransmitPduAllowed(PduIdType XcpTxPduId);
/**
* This function together with Xcp_Arc_TransmitPduAllowed is used to dynamically allow certain Pdus to receive and transmit messages.
* With the help of these functions the user can enable, disable certain communication channels, and in this way different session handling of
* Xcp can be performed.
* @param XcpRxPduId This Pdu Id is intended to use to process incoming Xcp message
* @param XcpRxPduPtr Pointer to the incoming Xcp messages
* @return TRUE XcpRxPduId is allowed to use in this session
* FALSE XcpRxPduId is not allowed to use in this session
*/
boolean Xcp_Arc_RecievePduAllowed(PduIdType XcpRxPduId, PduInfoType* XcpRxPduPtr);
#endif /* XCP_CALLOUT_STUBS_H_ */
|
2301_81045437/classic-platform
|
communication/Xcp/inc/Xcp_Callout_Stubs.h
|
C
|
unknown
| 9,467
|
/*-------------------------------- Arctic Core ------------------------------
* Copyright (C) 2013, ArcCore AB, Sweden, www.arccore.com.
* Contact: <contact@arccore.com>
*
* You may ONLY use this file:
* 1)if you have a valid commercial ArcCore license and then in accordance with
* the terms contained in the written license agreement between you and ArcCore,
* or alternatively
* 2)if you follow the terms found in GNU General Public License version 2 as
* published by the Free Software Foundation and appearing in the file
* LICENSE.GPL included in the packaging of this file or here
* <http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt>
*-------------------------------- Arctic Core -----------------------------*/
/** @reqSettings DEFAULT_SPECIFICATION_REVISION=4.1.3 */
#include "Xcp_Cfg.h"
#ifndef XCP_CONFIGTYPES_H_
#define XCP_CONFIGTYPES_H_
#define XCP_IDENTIFICATION_ABSOLUTE 0x0u
#define XCP_IDENTIFICATION_RELATIVE_BYTE 0x1u
#define XCP_IDENTIFICATION_RELATIVE_WORD 0x2u
#define XCP_IDENTIFICATION_RELATIVE_WORD_ALIGNED 0x3u
/* ERROR CODES */
typedef enum {
XCP_ERR_CMD_SYNCH = 0x00u,
XCP_ERR_CMD_BUSY = 0x10u,
XCP_ERR_DAQ_ACTIVE = 0x11u,
XCP_ERR_PGM_ACTIVE = 0x12u,
XCP_ERR_CMD_UNKNOWN = 0x20u,
XCP_ERR_CMD_SYNTAX = 0x21u,
XCP_ERR_OUT_OF_RANGE = 0x22u,
XCP_ERR_WRITE_PROTECTED = 0x23u,
XCP_ERR_ACCESS_DENIED = 0x24u,
XCP_ERR_ACCESS_LOCKED = 0x25u,
XCP_ERR_PAGE_NOT_VALID = 0x26u,
XCP_ERR_MODE_NOT_VALID = 0x27u,
XCP_ERR_SEGMENT_NOT_VALID = 0x28u,
XCP_ERR_SEQUENCE = 0x29u,
XCP_ERR_DAQ_CONFIG = 0x2Au,
XCP_ERR_MEMORY_OVERFLOW = 0x30u,
XCP_ERR_GENERIC = 0x31u,
XCP_ERR_VERIFY = 0x32u,
} Xcp_ErrorType;
typedef enum {
XCP_TIMESTAMP_UNIT_1NS = 0x00u,
XCP_TIMESTAMP_UNIT_10NS = 0x01u,
XCP_TIMESTAMP_UNIT_100NS = 0x02u,
XCP_TIMESTAMP_UNIT_1US = 0x03u,
XCP_TIMESTAMP_UNIT_10US = 0x04u,
XCP_TIMESTAMP_UNIT_100US = 0x05u,
XCP_TIMESTAMP_UNIT_1MS = 0x06u,
XCP_TIMESTAMP_UNIT_10MS = 0x07u,
XCP_TIMESTAMP_UNIT_100MS = 0x08u,
XCP_TIMESTAMP_UNIT_1S = 0x09u,
XCP_TIMESTAMP_UNIT_1PS = 0x0Au,
XCP_TIMESTAMP_UNIT_10PS = 0x0Bu,
XCP_TIMESTAMP_UNIT_100PS = 0x0Cu,
} Xcp_TimestampUnitType;
typedef enum {
XCP_CHECKSUM_ADD_11 = 0x01u,
XCP_CHECKSUM_ADD_12 = 0x02u,
XCP_CHECKSUM_ADD_14 = 0x03u,
XCP_CHECKSUM_ADD_22 = 0x04u,
XCP_CHECKSUM_ADD_24 = 0x05u,
XCP_CHECKSUM_ADD_44 = 0x06u,
XCP_CHECKSUM_CRC_16 = 0x07u,
XCP_CHECKSUM_CRC_16_CITT = 0x08u,
XCP_CHECKSUM_CRC_32 = 0x09u,
XCP_CHECKSUM_USERDEFINE = 0xFFu,
} Xcp_ChecksumType;
typedef struct Xcp_SegmentStandardInfoReturnType {
uint8 maxPages;
uint8 addressExtension;
uint8 maxMapping;
uint8 compressionMethod;
uint8 encryptionMethod;
} Xcp_SegmentStandardInfoReturnType;
typedef struct Xcp_GetSectorInfo_Mode0_1_ReturnType {
uint8 clearSeqNum;
uint8 programSeqNum;
uint8 programMethod;
uint32 sectorInfo;
} Xcp_GetSectorInfo_Mode0_1_ReturnType;
typedef struct Xcp_MtaType {
uint8 (*get) (struct Xcp_MtaType* mta);
void (*write)(struct Xcp_MtaType* mta, uint8* data, uint32 len);
void (*read) (struct Xcp_MtaType* mta, uint8* data, uint32 len);
void (*flush)(struct Xcp_MtaType* mta);
uint32 address;
uint8 extension;
} Xcp_MtaType;
typedef struct Xcp_OdtEntryType {
uint32 XcpOdtEntryAddress;
uint8 XcpOdtEntryExtension;
uint8 XcpOdtEntryLength;
uint8 BitOffSet;
} Xcp_OdtEntryType;
struct Xcp_BufferType;
typedef struct Xcp_OdtType {
Xcp_OdtEntryType* XcpOdtEntry; /* 0 .. * */
uint8 XcpOdtEntriesCount; /* 0 .. 255 */
} Xcp_OdtType;
#define XCP_DAQLIST_MODE_SELECTED (1u << 0u)
#define XCP_DAQLIST_MODE_STIM (1u << 1u)
#define XCP_DAQLIST_MODE_TIMESTAMP (1u << 4u)
#define XCP_DAQLIST_MODE_PIDOFF (1u << 5u)
#define XCP_DAQLIST_MODE_RUNNING (1u << 6u)
#define XCP_DAQLIST_MODE_RESUME (1u << 7u)
typedef uint8 Xcp_DaqListModeEnum;
#define XCP_DAQLIST_PROPERTY_EVENTFIXED (1u << 0u)
#define XCP_DAQLIST_PROPERTY_PREDEFINED (1u << 1u)
#define XCP_DAQLIST_PROPERTY_DAQ (1u << 2u)
#define XCP_DAQLIST_PROPERTY_STIM (1u << 3u)
#define XCP_DAQLIST_PROPERTY_DAQ_STIM ((1u << 2u)|(1u << 3u))
typedef uint8 Xcp_DaqListPropertyEnum;
typedef const struct {
/**
* Pointer to an array of ODT structures this DAQ list will use
* [USER]: With static DAQ lists, this needs to be set
* to an array of XcpMaxOdt size.
* [INTERNAL]: With dynamic DAQ configuration.
*/
Xcp_OdtType *XcpOdt; /**< reference to an array of Odt's configured for this Daq list */
/**
* Fixed eventchannel for this daq or 0xFFFF
* 0 .. NumEvents-1
*/
uint16 FixedEventChannel;
/**
* Maximum number of ODT's in XcpOdt array
* [USER] : When static DAQ configuration
* [INTERNAL]: Dynamic DAQ configuration.
* 0 .. 252
*/
uint8 XcpMaxOdt;
Xcp_DaqListPropertyEnum Properties; /**< bitfield for the properties of the DAQ list */
} Xcp_DaqListCfgType;
typedef struct Xcp_DaqListType {
/**
* Pointer to an array of ODT structures this DAQ list will use
* [USER]: With static DAQ lists, this needs to be set
* to an array of XcpMaxOdt size.
* [INTERNAL]: With dynamic DAQ configuration.
*/
Xcp_OdtType *XcpOdt; /**< reference to an array of Odt's configured for this Daq list */
/**
* Used to create list of ongoing transmissions
* [INTERNAL/USER]
*/
struct Xcp_DaqListType *TxDaqListNext;
/**
* Next ptr of the event daq list
*/
struct Xcp_DaqListType *EventDaqListNext;
/**
* Used to create list of ongoing transmissions
* [INTERNAL/USER]
*/
Xcp_OdtType *NextOdtToSend;
/**
* Maximum number of ODT's in XcpOdt array
* [USER] : When static DAQ configuration
* [INTERNAL]: Dynamic DAQ configuration.
* 0 .. 252
*/
uint8 XcpMaxOdt;
Xcp_DaqListModeEnum Mode; /**< bitfield for the current mode of the DAQ list */
uint16 EventChannel; /* NOTE: Fixed channel vs current */
uint8 Prescaler;
uint8 Timer; // to be used with prescaler
uint8 Priority;
uint8 FirstPid;
} Xcp_DaqListType;
typedef enum {
XCP_EVENTCHANNEL_PROPERTY_DAQ = 1u << 2u,
XCP_EVENTCHANNEL_PROPERTY_STIM = 1u << 3u,
XCP_EVENTCHANNEL_PROPERTY_ALL = XCP_EVENTCHANNEL_PROPERTY_DAQ | XCP_EVENTCHANNEL_PROPERTY_STIM,
} Xcp_EventChannelPropertyEnum;
typedef struct {
/**
* Set to the name of the eventchannel or NULL
* [USER]
*/
const char* XcpEventChannelName;
/**
* Priority of event channel (0 .. 255)
* [IGNORED]
*/
const uint8 XcpEventChannelPriority;
/**
* Maximum number of entries in XcpEventChannelTriggeredDaqListRef
* [USER]
*
* 1 .. 255
* 0 = Unlimited
*/
const uint8 XcpEventChannelMaxDaqList;
/**
* Bitfield defining supported features
* [USER]
*/
const Xcp_EventChannelPropertyEnum XcpEventChannelProperties;
/**
* Cycle unit of event channel
* [USER]
*
* Set to 0 (XCP_TIMESTAMP_UNIT_1NS) if channel is not
* cyclic.
*/
const Xcp_TimestampUnitType XcpEventChannelUnit;
/**
* Number of cycle units between each trigger of event
* [USER]
*
* 0 .. 255
* 0 -> non cyclic
*/
const uint8 XcpEventChannelRate;
} Xcp_EventChannelType;
#define XCP_ACCESS_ECU_ACCESS_WITHOUT_XCP (1u << 0u)
#define XCP_ACCESS_ECU_ACCESS_WITH_XCP (1u << 1u)
#define XCP_ACCESS_XCP_READ_ACCESS_WITHOUT_ECU (1u << 2u)
#define XCP_ACCESS_READ_ACCESS_WITH_ECU (1u << 3u)
#define XCP_ACCESS_XCP_WRITE_ACCESS_WITHOUT_ECU (1u << 4u)
#define XCP_ACCESS_XCP_WRITE_ACCESS_WITH_ECU (1u << 5u)
#define XCP_ACCESS_ALL 0x3fu
typedef uint8 Xcp_AccessFlagsType;
#define XCP_PROTECT_NONE (uint8)(0u)
#define XCP_PROTECT_CALPAG (uint8)(1u << 0u)
#define XCP_PROTECT_DAQ (uint8)(1u << 2u)
#define XCP_PROTECT_STIM (uint8)(1u << 3u)
#define XCP_PROTECT_PGM (uint8)(1u << 4u)
typedef uint8 Xcp_ProtectType;
typedef enum {
XCP_COMPRESSION_METHOD_NONE = 0u,
} Xcp_CompressType;
typedef enum {
XCP_ENCRYPTION_METHOD_NONE = 0u,
} Xcp_EncryptionType;
typedef struct {
uint32 XcpSrc;
uint32 XcpDst;
uint32 XcpLen;
} Xcp_MemoryMappingType;
typedef struct {
Xcp_MemoryMappingType* XcpMapping;
uint32 XcpAddress;
uint32 XcpLength;
uint32 XcpMaxMapping;
uint8 XcpMaxPage;
uint8 XcpPageXcp;
uint8 XcpPageEcu;
uint8 XcpExtension;
const Xcp_AccessFlagsType XcpAccessFlags;
Xcp_CompressType XcpCompression;
Xcp_EncryptionType XcpEncryption;
} Xcp_SegmentType;
typedef struct {
const char* XcpCaption; /**< ASCII text describing device [USER] */
const char* XcpMC2File; /**< ASAM-MC2 filename without path and extension [USER] */
const char* XcpMC2Path; /**< ASAM-MC2 filename with path and extension [USER] */
const char* XcpMC2Url; /**< ASAM-MC2 url to file [USER] */
const char* XcpMC2Upload; /**< ASAM-MC2 file to upload [USER] */
} Xcp_InfoType;
/** Collection of runtime parameter*/
typedef struct {
/** Runtime parameter*/
Xcp_ProtectType XcpProtect;
/** Runtime parameter*/
uint16 XcpMaxDaq; /* 0 .. 65535, XCP_MAX_DAQ */
#if(XCP_DAQ_CONFIG_TYPE == DAQ_DYNAMIC)
/** Runtime parameter*/
uint32 XcpNumDynWordsAllocated;
#endif /*XCP_DAQ_CONFIG_TYPE == DAQ_DYNAMIC*/
} Xcp_RunTimeType;
/** State of the communication tx channels*/
typedef enum{
XCP_TX_CH_EMPTY = 0x00u,
XCP_TX_CH_RESERVED = 0x01u,
} Xcp_TxChStateType;
/** Collection of the configured communication tx channels*/
typedef struct{
#if (XCP_PROTOCOL == XCP_PROTOCOL_CAN)
uint8 data[XCP_MAX_DTO > XCP_MAX_CTO ? XCP_MAX_DTO : XCP_MAX_CTO];
#elif (XCP_PROTOCOL == XCP_PROTOCOL_ETHERNET)
uint8 data[XCP_MAX_DTO > XCP_MAX_CTO ? XCP_MAX_DTO + 4u : XCP_MAX_CTO + 4u];
#endif
PduLengthType len;
Xcp_TxChStateType state;
const PduIdType pduId;
} Xcp_TxChType;
/** @req 4.1.3/SWS_Xcp_00845 *//*Xcp_ConfigType definition - can not be tested with conventional module tests*/
typedef struct {
/** Collection of the configured communication tx channels*/
Xcp_TxChType *XcpTxCh;
/** Collection of runtime parameter*/
Xcp_RunTimeType *rt;
#if(XCP_DAQ_CONFIG_TYPE == DAQ_DYNAMIC)
/** references for dynamic allocation */
uint32 *ptrDynamicRamBuffer;
uint32 dynamicRamBufferSize;
#endif /*XCP_DAQ_CONFIG_TYPE == DAQ_DYNAMIC*/
/** Pointer to the statically allocated DAQ Lists*/
Xcp_DaqListType *XcpDaqList;
/** Pointer to the statically allocated DAQ Lists*/
const Xcp_DaqListCfgType *XcpDaqListCfg;
/** Number of statically allocated DAQ Lists*/
uint16 XcpDaqListSize;
/**
* Function is used to initialize MTA (Memory Transfer Address) and its proper functions to read and write
* that memory sections
* @param mta (output) Memory Transfer Address
* @param address (input) This value is sent by XCP Master tool
* @param extension (input) This value is sent by XCP Master tool
*/
void (*XcpMtaInit)(
Xcp_MtaType* mta,
uint32 address,
uint8 extension);
/**
* Function used for Seed & Key unlock
* @param res is the resource requested to be unlocked
* @param seed is the seed that was sent to the master
* @param seed_len is the length of @param seed
* @param key is the key sent from master
* @param key_len is the length of @param key
* @return E_OK for success, E_ERR for failure
*/
Std_ReturnType (*XcpUnlockFn)(
Xcp_ProtectType res,
const uint8* seed,
uint8 seed_len,
const uint8* key,
uint8 key_len);
/**
* Function called to retrieve seed that should be
* sent to master in a GetSeed/Unlock exchange
* @param res is the resource requested
* @param seed pointer to buffer that will hold seed (255 bytes max)
* @return number of bytes in seed
*/
uint8 (*XcpSeedFn)(
Xcp_ProtectType res,
uint8* seed);
/**
* Function called for a XCP user defined call from the master
* @param data data recieved from master (excluding the preceding 0xF1 for user defined)
* @param len length of the data in buffer
* @return
*/
Std_ReturnType (*XcpUserFn)(
void* data,
PduLengthType len);
#if(XCP_FEATURE_CALPAG == STD_ON)
/**
*
* @param mode
* @param segm
* @param page
* @param error
* @return
*/
Std_ReturnType (*XcpSetCalPage)(
const uint8 mode,
const uint8 segm,
const uint8 page,
Xcp_ErrorType *error);
/**
*
* @param mode
* @param segm
* @param page
* @param error
* @return
*/
Std_ReturnType (*XcpGetCalPage)(
const uint8 mode,
const uint8 segm,
uint8 *page,
Xcp_ErrorType *error);
/**
*
* @param sourceSegm
* @param sourcePage
* @param destSegm
* @param destPage
* @param error
* @return
*/
Std_ReturnType (*XcpCopyCalPage)(
const uint8 sourceSegm,
const uint8 sourcePage,
const uint8 destSegm,
const uint8 destPage,
Xcp_ErrorType *error);
/**
*
* @param maxSegment
* @param error
* @return
*/
Std_ReturnType (*XcpGetPagProcessorInfo)(
uint8 *maxSegment,
Xcp_ErrorType *error);
/**
*
* @param segmentNumber
* @param segmentInfo
* @param basicInfo
* @param error
* @return
*/
Std_ReturnType (*XcpGetSegmentInfo_GetBasicAddress)(
const uint8 segmentNumber,
const uint8 segmentInfo,
uint32 *basicInfo,
Xcp_ErrorType *error);
/**
*
* @param segmentNumber
* @param responseData
* @param error
* @return
*/
Std_ReturnType (*XcpGetSegmentInfo_GetStandardInfo)(
const uint8 segmentNumber,
Xcp_SegmentStandardInfoReturnType *responseData,
Xcp_ErrorType *error);
/**
*
* @param segmentNumber
* @param segmentInfo
* @param mappingInfo
* @param error
* @return
*/
Std_ReturnType (*XcpGetSegmentInfo_GetAddressMapping)(
const uint8 segmentNumber,
const uint8 segmentInfo,
uint32 *mappingInfo,
Xcp_ErrorType *error);
/**
*
* @param segmentNumber
* @param pageNumber
* @param pageProperties
* @param initSegment
* @param error
* @return
*/
Std_ReturnType (*XcpGetPageInfo)(
const uint8 segmentNumber,
const uint8 pageNumber,
uint8 *pageProperties,
uint8 *initSegment,
Xcp_ErrorType *error);
/**
*
* @param mode
* @param segmentNumber
* @param error
* @return
*/
Std_ReturnType (*XcpSetSegmentMode)(
const uint8 mode,
const uint8 segmentNumber,
Xcp_ErrorType *error);
/**
*
* @param segmentNumber
* @param mode
* @param error
* @return
*/
Std_ReturnType (*XcpGetSegmentMode)(
const uint8 segmentNumber,
uint8 *mode,
Xcp_ErrorType *error);
#endif /*XCP_FEATURE_CALPAG == STD_ON*/
#if(XCP_FEATURE_PGM == STD_ON)
/**
*
* @param clearRange
* @param error
* @return
*/
Std_ReturnType (*XcpProgramClear_FunctionalAccess)(
const uint32 clearRange,
Xcp_ErrorType *error);
/**
*
* @param mta
* @param clearRange
* @param error
* @return
*/
Std_ReturnType (*XcpProgramClear_AbsoluteAccess)(
Xcp_MtaType* mta,
uint32 clearRange,
Xcp_ErrorType *error);
/**
*
* @param error
* @return
*/
Std_ReturnType (*XcpProgramReset)(
Xcp_ErrorType *error);
/**
*
* @param pgmProperties
* @param maxSector
* @param error
* @return
*/
Std_ReturnType (*XcpGetPgmProcessorInfo)(
uint8 *pgmProperties,
uint8 *maxSector,
Xcp_ErrorType *error);
/**
*
* @param mode
* @param sectorNumber
* @param responseData
* @param error
* @return
*/
Std_ReturnType (*XcpGetSectorInfo_Mode0_1)(
const uint8 mode,
const uint8 sectorNumber,
Xcp_GetSectorInfo_Mode0_1_ReturnType *responseData,
Xcp_ErrorType *error);
/**
*
* @param sectorNameLength
* @param error
* @return
*/
Std_ReturnType (*XcpGetSectorInfo_Mode2)(
uint8 *sectorNameLength,
Xcp_ErrorType *error);
/**
*
* @param mta
* @param codeSize
* @param error
* @return
*/
Std_ReturnType (*XcpProgramPrepare)(
Xcp_MtaType* mta,
uint16 codeSize,
Xcp_ErrorType *error);
/**
*
* @param compressionMethod
* @param encryptionMethod
* @param programmingMethod
* @param accessMethod
* @param error
* @return
*/
Std_ReturnType (*XcpProgramFormat)(
const uint8 compressionMethod,
const uint8 encryptionMethod,
const uint8 programmingMethod,
const uint8 accessMethod,
Xcp_ErrorType *error);
/**
*
* @param mode
* @param type
* @param value
* @param error
* @return
*/
Std_ReturnType (*XcpProgramVerify)(
const uint8 mode,
const uint8 type,
const uint8 value,
Xcp_ErrorType *error);
/**
* Flash algorithm must be place here, Post increment of the MTA shall be performed here
* @param mta
* @param data
* @param len
* @param error
* @return
*/
Std_ReturnType (*XcpProgram)(
Xcp_MtaType* mta,
uint8* data,
uint32 len,
Xcp_ErrorType *error);
#endif /*XCP_FEATURE_PGM == STD_ON*/
/**
* This function is responsible to calculate the intended checksum algorithm, at the given example
* XCP_CHECKSUM_ADD_11 is used
* @param mtaPtr
* @param block (input) length of the block where the CRC is calculated
* @param type (output) type of the CRC calculation.
* @param response (output) the result of the CRC calculation over the block
*/
void (*XcpBuildChecksum)(
Xcp_MtaType* mtaPtr,
uint32 block,
Xcp_ChecksumType* type,
uint32* response);
/**
* This function together with Xcp_Arc_RecievePduAllowed is used to dynamically allow certain Pdus to receive and transmit messages.
* With the help of these functions the user can enable, disable certain communication channels, and in this way different session handling of
* Xcp can be performed.
* @param XcpTxPduId This Pdu Id is intended to use to send out Xcp message
* @return TRUE XcpTxPduId is allowed to use in this session
* FALSE XcpTxPduId is not allowed to use in this session
*/
boolean (*XcpTransmitPduAllowed)(PduIdType XcpTxPduId);
/**
* This function together with Xcp_Arc_TransmitPduAllowed is used to dynamically allow certain Pdus to receive and transmit messages.
* With the help of these functions the user can enable, disable certain communication channels, and in this way different session handling of
* Xcp can be performed.
* @param XcpRxPduId This Pdu Id is intended to use to process incoming Xcp message
* @param XcpRxPduPtr Pointer to the incoming Xcp messages
* @return TRUE XcpRxPduId is allowed to use in this session
* FALSE XcpRxPduId is not allowed to use in this session
*/
boolean (*XcpRecievePduAllowed)(PduIdType XcpRxPduId, PduInfoType* XcpRxPduPtr);
/** Config and Runtime parameter*/
const Xcp_EventChannelType *XcpEventChannel;
/** Config parameter*/
const Xcp_InfoType XcpInfo;
/** Config parameter*/
const Xcp_ProtectType XcpOriginalProtect; /**< Bitfield with currently locked features (Xcp_ProtectType) */
} Xcp_ConfigType;
extern const Xcp_ConfigType XcpConfig;
#endif /* XCP_CONFIGTYPES_H_ */
|
2301_81045437/classic-platform
|
communication/Xcp/inc/Xcp_ConfigTypes.h
|
C
|
unknown
| 21,741
|
/*-------------------------------- Arctic Core ------------------------------
* Copyright (C) 2013, ArcCore AB, Sweden, www.arccore.com.
* Contact: <contact@arccore.com>
*
* You may ONLY use this file:
* 1)if you have a valid commercial ArcCore license and then in accordance with
* the terms contained in the written license agreement between you and ArcCore,
* or alternatively
* 2)if you follow the terms found in GNU General Public License version 2 as
* published by the Free Software Foundation and appearing in the file
* LICENSE.GPL included in the packaging of this file or here
* <http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt>
*-------------------------------- Arctic Core -----------------------------*/
/** @reqSettings DEFAULT_SPECIFICATION_REVISION=4.1.3 */
#include "Xcp_Callout_Stubs.h"
#include <string.h>
/** This type encapsulate a possible Address Extension Type, normally this information is coming from Xcp Master */
typedef enum {
/** These are freely customizable */
XCP_MTA_EXTENSION_MEMORY = 0u,
XCP_MTA_EXTENSION_FLASH = 1u,
XCP_MTA_EXTENSION_DIO_PORT = 2u,
XCP_MTA_EXTENSION_DIO_CHAN = 3u,
/** This kind of memory extension is used by XCP.c for reading or writing some general information
* from XCP reserved memory (Ram), or reading from XCP Config (Flash) */
XCP_MTA_EXTENSION_MEMORY_INTERNAL = 0xFFu,
} Xcp_MtaExtentionType;
/** These example functions are used to read or write different memory sections */
static uint8 Xcp_MtaGetMemory(Xcp_MtaType* mta);
static void Xcp_MtaReadMemory(Xcp_MtaType* mta, uint8* data, uint32 len);
static void Xcp_MtaWriteMemory(Xcp_MtaType* mta, uint8* data, uint32 len);
/** Read a character from MTA */
static uint8 Xcp_MtaGetMemory(Xcp_MtaType* mta)
{
/** Post increment of the MTA shall be performed here*/
return *(uint8*)(mta->address++);
}
/** Read a character from memory */
static void Xcp_MtaReadMemory(Xcp_MtaType* mta, uint8* data, uint32 len)
{
Xcp_MemCpy(data, (void*)mta->address, len);
/** Post increment of the MTA shall be performed here*/
mta->address += len;
}
/** Write a character to memory */
static void Xcp_MtaWriteMemory(Xcp_MtaType* mta, uint8* data, uint32 len)
{
Xcp_MemCpy((void*)mta->address, data, len);
/** Post increment of the MTA shall be performed here*/
mta->address += len;
}
/**
* Function is used to initialize MTA (Memory Transfer Address) and its proper functions
* which shall be used when XCP reads and writes ceratin memory sections
* @param mta (output) Memory Transfer Address
* @param address (input) This value is sent by XCP Master tool
* @param extension (input) This value is sent by XCP Master tool
*/
void Xcp_Arc_MtaInit(
Xcp_MtaType* mta,
uint32 address,
uint8 extension)
{
mta->address = address;
mta->extension = extension;
if( (extension == (uint8)XCP_MTA_EXTENSION_MEMORY) ||
(extension == (uint8)XCP_MTA_EXTENSION_MEMORY_INTERNAL) )
{
mta->get = Xcp_MtaGetMemory;
mta->read = Xcp_MtaReadMemory;
mta->write = Xcp_MtaWriteMemory;
mta->flush = NULL;
}
else if(extension == (uint8)XCP_MTA_EXTENSION_FLASH)
{
mta->get = Xcp_MtaGetMemory;
mta->read = Xcp_MtaReadMemory;
mta->write = NULL;
mta->flush = NULL;
}
else
{
mta->get = NULL;
mta->read = NULL;
mta->write = NULL;
mta->flush = NULL;
}
}
/**
* This function is responsible to calculate the intended checksum algorithm, at the given example
* XCP_CHECKSUM_ADD_11 is used
* @param mtaPtr
* @param block (input) length of the block where the CRC is calculated
* @param type (output) type of the CRC calculation.
* @param response (output) the result of the CRC calculation over the block
*/
void Xcp_Arc_BuildChecksum(
Xcp_MtaType* mtaPtr,
uint32 block,
Xcp_ChecksumType* type,
uint32* response)
{
*type = XCP_CHECKSUM_ADD_11;
*response = 0u;
for (uint32 i = 0; i < block; i++)
{
*response += mtaPtr->get(mtaPtr);
}
/** Post increment of the MTA shall be performed here*/
mtaPtr->address += block;
}
#if (XCP_FEATURE_PROTECTION == STD_ON)
/**
* Function called to retrieve seed that should be
* sent to master in a GetSeed/Unlock exchange
* @param res is the resource requested
* @param seed pointer to buffer that will hold seed (255 bytes max)
* @return number of bytes in seed
*/
uint8 Xcp_Arc_GetSeed(
Xcp_ProtectType res,
uint8* seed)
{
(void)(res);
strcpy((char*)seed, "HELLO_BELLO");
return strlen((const char*)seed);
}
/**
* Function used for Seed & Key unlock
* @param res is the resource requested to be unlocked
* @param seed is the seed that was sent to the master
* @param seed_len is the length of @param seed
* @param key is the key sent from master
* @param key_len is the length of @param key
* @return E_OK for success, E_ERR for failure
*/
Std_ReturnType Xcp_Arc_Unlock(
Xcp_ProtectType res,
const uint8* seed,
uint8 seed_len,
const uint8* key,
uint8 key_len)
{
(void)(res);
if(seed_len != key_len)
return E_NOT_OK; /*lint !e904 allow multiple exit */
if(memcmp(seed, key, seed_len))
return E_NOT_OK; /*lint !e904 allow multiple exit */
return E_OK;
}
#endif /* XCP_FEATURE_PROTECTION == STD_ON */
#if(XCP_FEATURE_CALPAG == STD_ON)
/**
*
* @param mode
* @param segm
* @param page
* @param error
* @return
*/
Std_ReturnType Xcp_Arc_SetCalPage(
const uint8 mode,
const uint8 segm,
const uint8 page,
Xcp_ErrorType *error)
{
XCP_UNUSED(mode);
XCP_UNUSED(segm);
XCP_UNUSED(page);
*error = XCP_ERR_CMD_UNKNOWN;
return E_NOT_OK;
}
/**
*
* @param mode
* @param segm
* @param page
* @param error
* @return
*/
Std_ReturnType Xcp_Arc_GetCalPage(
const uint8 mode,
const uint8 segm,
uint8 *page,
Xcp_ErrorType *error)
{
XCP_UNUSED(mode);
XCP_UNUSED(segm);
XCP_UNUSED(page); /*lint !e920 Misra 2012 1.3 cast from pointer to void */
*error = XCP_ERR_CMD_UNKNOWN;
return E_NOT_OK;
}
/**
*
* @param sourceSegm
* @param sourcePage
* @param destSegm
* @param destPage
* @param error
* @return
*/
Std_ReturnType Xcp_Arc_CopyCalPage(
const uint8 sourceSegm,
const uint8 sourcePage,
const uint8 destSegm,
const uint8 destPage,
Xcp_ErrorType *error)
{
XCP_UNUSED(sourceSegm);
XCP_UNUSED(sourcePage);
XCP_UNUSED(destSegm);
XCP_UNUSED(destPage);
*error = XCP_ERR_CMD_UNKNOWN;
return E_NOT_OK;
}
/**
*
* @param maxSegment
* @param error
* @return
*/
Std_ReturnType Xcp_Arc_GetPagProcessorInfo(
uint8 *maxSegment,
Xcp_ErrorType *error)
{
XCP_UNUSED(maxSegment); /*lint !e920 Misra 2012 1.3 cast from pointer to void */
*error = XCP_ERR_CMD_UNKNOWN;
return E_NOT_OK;
}
/**
*
* @param segmentNumber
* @param segmentInfo
* @param basicInfo
* @param error
* @return
*/
Std_ReturnType Xcp_Arc_GetSegmentInfo_GetBasicAddress(
const uint8 segmentNumber,
const uint8 segmentInfo,
uint32 *basicInfo,
Xcp_ErrorType *error)
{
XCP_UNUSED(segmentNumber);
XCP_UNUSED(segmentInfo);
XCP_UNUSED(basicInfo); /*lint !e920 Misra 2012 1.3 cast from pointer to void */
*error = XCP_ERR_CMD_UNKNOWN;
return E_NOT_OK;
}
/**
*
* @param segmentNumber
* @param responseData
* @param error
* @return
*/
Std_ReturnType Xcp_Arc_GetSegmentInfo_GetStandardInfo(
const uint8 segmentNumber,
Xcp_SegmentStandardInfoReturnType *responseData,
Xcp_ErrorType *error)
{
XCP_UNUSED(segmentNumber);
XCP_UNUSED(responseData); /*lint !e920 Misra 2012 1.3 cast from pointer to void */
*error = XCP_ERR_CMD_UNKNOWN;
return E_NOT_OK;
}
/**
*
* @param segmentNumber
* @param segmentInfo
* @param mappingInfo
* @param error
* @return
*/
Std_ReturnType Xcp_Arc_GetSegmentInfo_GetAddressMapping(
const uint8 segmentNumber,
const uint8 segmentInfo,
uint32 *mappingInfo,
Xcp_ErrorType *error)
{
XCP_UNUSED(segmentNumber);
XCP_UNUSED(segmentInfo);
XCP_UNUSED(mappingInfo); /*lint !e920 Misra 2012 1.3 cast from pointer to void */
*error = XCP_ERR_CMD_UNKNOWN;
return E_NOT_OK;
}
/**
*
* @param segmentNumber
* @param pageNumber
* @param pageProperties
* @param initSegment
* @param error
* @return
*/
Std_ReturnType Xcp_Arc_GetPageInfo(
const uint8 segmentNumber,
const uint8 pageNumber,
uint8 *pageProperties,
uint8 *initSegment,
Xcp_ErrorType *error)
{
XCP_UNUSED(segmentNumber);
XCP_UNUSED(pageNumber);
XCP_UNUSED(pageProperties); /*lint !e920 Misra 2012 1.3 cast from pointer to void */
XCP_UNUSED(initSegment); /*lint !e920 Misra 2012 1.3 cast from pointer to void */
*error = XCP_ERR_CMD_UNKNOWN;
return E_NOT_OK;
}
/**
*
* @param mode
* @param segmentNumber
* @param error
* @return
*/
Std_ReturnType Xcp_Arc_SetSegmentMode(
const uint8 mode,
const uint8 segmentNumber,
Xcp_ErrorType *error)
{
XCP_UNUSED(mode);
XCP_UNUSED(segmentNumber);
*error = XCP_ERR_CMD_UNKNOWN;
return E_NOT_OK;
}
/**
*
* @param segmentNumber
* @param mode
* @param error
* @return
*/
Std_ReturnType Xcp_Arc_GetSegmentMode(
const uint8 segmentNumber,
uint8 *mode,
Xcp_ErrorType *error)
{
XCP_UNUSED(segmentNumber);
XCP_UNUSED(mode); /*lint !e920 Misra 2012 1.3 cast from pointer to void */
*error = XCP_ERR_CMD_UNKNOWN;
return E_NOT_OK;
}
#endif /*XCP_FEATURE_CALPAG == STD_ON*/
#if(XCP_FEATURE_PGM == STD_ON)
/**
*
* @param clearRange
* @param error
* @return
*/
Std_ReturnType Xcp_Arc_ProgramClear_FunctionalAccess(
const uint32 clearRange,
Xcp_ErrorType *error)
{
XCP_UNUSED(clearRange);
*error = XCP_ERR_CMD_UNKNOWN;
return E_NOT_OK;
}
/**
*
* @param mta
* @param clearRange
* @param error
* @return
*/
Std_ReturnType Xcp_Arc_ProgramClear_AbsoluteAccess(
Xcp_MtaType* mta,
const uint32 clearRange,
Xcp_ErrorType *error)
{
XCP_UNUSED(mta); /*lint !e920 Misra 2012 1.3 cast from pointer to void */
XCP_UNUSED(clearRange);
*error = XCP_ERR_CMD_UNKNOWN;
return E_NOT_OK;
}
/**
*
* @param error
* @return
*/
Std_ReturnType Xcp_Arc_ProgramReset(
Xcp_ErrorType *error)
{
*error = XCP_ERR_CMD_UNKNOWN;
return E_NOT_OK;
}
/**
*
* @param pgmProperties
* @param maxSector
* @param error
* @return
*/
Std_ReturnType Xcp_Arc_GetPgmProcessorInfo(
uint8 *pgmProperties,
uint8 *maxSector,
Xcp_ErrorType *error)
{
XCP_UNUSED(pgmProperties); /*lint !e920 Misra 2012 1.3 cast from pointer to void */
XCP_UNUSED(maxSector); /*lint !e920 Misra 2012 1.3 cast from pointer to void */
*error = XCP_ERR_CMD_UNKNOWN;
return E_NOT_OK;
}
/**
*
* @param mode
* @param sectorNumber
* @param responseData
* @param error
* @return
*/
Std_ReturnType Xcp_Arc_GetSectorInfo_Mode0_1(
const uint8 mode,
const uint8 sectorNumber,
Xcp_GetSectorInfo_Mode0_1_ReturnType *responseData,
Xcp_ErrorType *error)
{
XCP_UNUSED(mode);
XCP_UNUSED(sectorNumber);
XCP_UNUSED(responseData); /*lint !e920 Misra 2012 1.3 cast from pointer to void */
*error = XCP_ERR_CMD_UNKNOWN;
return E_NOT_OK;
}
/**
*
* @param sectorNameLength
* @param error
* @return
*/
Std_ReturnType Xcp_Arc_GetSectorInfo_Mode2(
uint8 *sectorNameLength,
Xcp_ErrorType *error)
{
XCP_UNUSED(sectorNameLength); /*lint !e920 Misra 2012 1.3 cast from pointer to void */
*error = XCP_ERR_CMD_UNKNOWN;
return E_NOT_OK;
}
/**
*
* @param mta
* @param codeSize
* @param error
* @return
*/
Std_ReturnType Xcp_Arc_ProgramPrepare(
Xcp_MtaType* mta,
uint16 codeSize,
Xcp_ErrorType *error)
{
XCP_UNUSED(mta); /*lint !e920 Misra 2012 1.3 cast from pointer to void */
XCP_UNUSED(codeSize);
*error = XCP_ERR_CMD_UNKNOWN;
return E_NOT_OK;
}
/**
*
* @param compressionMethod
* @param encryptionMethod
* @param programmingMethod
* @param accessMethod
* @param error
* @return
*/
Std_ReturnType Xcp_Arc_ProgramFormat(
const uint8 compressionMethod,
const uint8 encryptionMethod,
const uint8 programmingMethod,
const uint8 accessMethod,
Xcp_ErrorType *error)
{
XCP_UNUSED(compressionMethod);
XCP_UNUSED(encryptionMethod);
XCP_UNUSED(programmingMethod);
XCP_UNUSED(accessMethod);
*error = XCP_ERR_CMD_UNKNOWN;
return E_NOT_OK;
}
/**
*
* @param mode
* @param type
* @param value
* @param error
* @return
*/
Std_ReturnType Xcp_Arc_ProgramVerify(
const uint8 mode,
const uint8 type,
const uint8 value,
Xcp_ErrorType *error)
{
XCP_UNUSED(mode);
XCP_UNUSED(type);
XCP_UNUSED(value);
*error = XCP_ERR_CMD_UNKNOWN;
return E_NOT_OK;
}
/**
* Flash algorithm must be place here, Post increment of the MTA shall be performed here
* @param mta
* @param data
* @param len
* @param error
* @return
*/
Std_ReturnType Xcp_Arc_Program(
Xcp_MtaType* mta,
uint8* data,
uint32 len,
Xcp_ErrorType *error)
{
XCP_UNUSED(mta); /*lint !e920 Misra 2012 1.3 cast from pointer to void */
XCP_UNUSED(data); /*lint !e920 Misra 2012 1.3 cast from pointer to void */
XCP_UNUSED(len);
/** Post increment of the MTA shall be performed here*/
//mta->address += len;
*error = XCP_ERR_CMD_UNKNOWN;
return E_NOT_OK;
}
#endif /*XCP_FEATURE_PGM == STD_ON*/
/**
* This function together with Xcp_Arc_RecievePduAllowed is used to dynamically allow certain Pdus to receive and transmit messages.
* With the help of these functions the user can enable, disable certain communication channels, and in this way different session handling of
* Xcp can be performed.
* @param XcpTxPduId This Pdu Id is intended to use to send out Xcp message
* @return TRUE XcpTxPduId is allowed to use in this session
* FALSE XcpTxPduId is not allowed to use in this session
*/
boolean Xcp_Arc_TransmitPduAllowed(PduIdType XcpTxPduId) {
XCP_UNUSED(XcpTxPduId);
return TRUE;
}
/**
* This function together with Xcp_Arc_TransmitPduAllowed is used to dynamically allow certain Pdus to receive and transmit messages.
* With the help of these functions the user can enable, disable certain communication channels, and in this way different session handling of
* Xcp can be performed.
* @param XcpRxPduId This Pdu Id is intended to use to process incoming Xcp message
* @param XcpRxPduPtr Pointer to the incoming Xcp messages
* @return TRUE XcpRxPduId is allowed to use in this session
* FALSE XcpRxPduId is not allowed to use in this session
*/
boolean Xcp_Arc_RecievePduAllowed(PduIdType XcpRxPduId, PduInfoType* XcpRxPduPtr) {
XCP_UNUSED(XcpRxPduId);
XCP_UNUSED(XcpRxPduPtr); /*lint !e920 Misra 2012 1.3 cast from pointer to void */
return TRUE;
}
|
2301_81045437/classic-platform
|
communication/Xcp/integration/Xcp_Callout_Stubs.c
|
C
|
unknown
| 15,908
|
/*-------------------------------- Arctic Core ------------------------------
* Copyright (C) 2013, ArcCore AB, Sweden, www.arccore.com.
* Contact: <contact@arccore.com>
*
* You may ONLY use this file:
* 1)if you have a valid commercial ArcCore license and then in accordance with
* the terms contained in the written license agreement between you and ArcCore,
* or alternatively
* 2)if you follow the terms found in GNU General Public License version 2 as
* published by the Free Software Foundation and appearing in the file
* LICENSE.GPL included in the packaging of this file or here
* <http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt>
*-------------------------------- Arctic Core -----------------------------*/
/** @reqSettings DEFAULT_SPECIFICATION_REVISION=4.1.3 */
/*General requirement*/
/** @req 4.1.3/SWS_Xcp_00501 *//*It is about the code file structure of Xcp - can not be tested with conventional module tests*/
/** @req 4.1.3/SWS_Xcp_00500 *//*XCP shall access the location of the API by proper header inclusion - can not be tested with conventional module tests */
/** @req 4.1.3/SWS_Xcp_00502 *//*Header file structure - can not be tested with conventional module tests*/
/** @req 4.1.3/SWS_Xcp_00701 *//*Location of Xcp module in communication stack - can not be tested with conventional module tests*/
/** @req 4.1.3/SWS_Xcp_00702 *//*Unique PDU Id must be used for communication - can not be tested with conventional module tests*/
/** @req 4.1.3/SWS_Xcp_00703 *//*The AUTOSAR XCP Module shall support the ASAM XCP Specification Version 1.1.*/
/** @req 4.1.3/SWS_Xcp_00712 *//*For sending and receiving of calibration data, the sending and receiving APIs specified within the AUTOSAR BSW Bus Interfaces shall be used*/
/** @req 4.1.3/SWS_Xcp_00764 *//*The internal XCP states shall be available for debugging - can not be tested with conventional module tests */
/** @req 4.1.3/SWS_Xcp_00741 *//*Link-time and post-build-time configuration - can not be tested with conventional module tests*/
/** @req 4.1.3/SWS_Xcp_00742 *//*The XCP module shall support pre-compile time, link-time and post-build-time configuration - can not be tested with conventional module tests*/
/** @req 4.1.3/SWS_Xcp_00763 *//*Development errors*/
/** @req 4.1.3/SWS_Xcp_00801 *//*Imported type definitions - can not be tested with conventional module tests*/
/** @req 4.1.3/SWS_Xcp_00832 *//*Optional interface - can not be tested with conventional module tests*/
#include "Std_Types.h"
#include "Xcp_Internal.h"
static Xcp_BufferType Xcp_RxCtoBuffers[1];
static Xcp_BufferType Xcp_RxDtoBuffers[1]; // size should depend on STIM config, ignores it for now
static Xcp_BufferType Xcp_TxCtoBuffers[1];
static Xcp_FifoType Xcp_RxCtoFifoFree;
static Xcp_FifoType Xcp_RxDtoFifoFree;
static Xcp_FifoType Xcp_TxCtoFifoFree;
static Xcp_FifoType Xcp_FifoRxCto = { .free = &Xcp_RxCtoFifoFree };
Xcp_FifoType Xcp_FifoTxCto = { .free = &Xcp_TxCtoFifoFree };
static Xcp_DaqListType *Xcp_DaqTxList = 0;
static Xcp_DaqListType *Xcp_DaqTxListLast = 0;
static Xcp_DaqListType **XcpEventChannelTriggeredDaqListRef[XCP_EVENT_COUNT];
uint8 Xcp_Inited;
uint8 Xcp_Connected;
Xcp_MtaType Xcp_Mta;
const Xcp_ConfigType* xcpPtr;
static uint8 Xcp_TxOngoing = 0;
static Xcp_TransferType Xcp_Download;
static Xcp_DaqPtrStateType Xcp_DaqState;
static Xcp_TransferType Xcp_Upload;
static Xcp_CmdWorkType Xcp_Worker;
#if(XCP_FEATURE_PROTECTION == STD_ON)
static Xcp_UnlockType Xcp_Unlock;
#endif /*XCP_FEATURE_PROTECTION*/
#if (XCP_VERSION_INFO_API == STD_ON)
/**
* Returns the version information of this module.
*
* ServiceId: 0x01
*
* @param versioninfo
*/
/** @req 4.1.3/SWS_Xcp_00807 *//*Xcp_GetVersionInfo API definition*/
/** @req 4.1.3/SWS_Xcp_00825 *//*Check whether the parameter VersioninfoPtr is a NULL pointer*/
void Xcp_GetVersionInfo(Std_VersionInfoType* versionInfo)
{
DET_VALIDATE_NRV(versionInfo, XCP_API_ID_XCP_GETVERSIONINFO, XCP_E_INV_POINTER);
versionInfo->moduleID = (uint16)XCP_MODULE_ID;
versionInfo->vendorID = (uint16)XCP_VENDOR_ID;
versionInfo->sw_major_version = (uint8)XCP_SW_MAJOR_VERSION;
versionInfo->sw_minor_version = (uint8)XCP_SW_MINOR_VERSION;
versionInfo->sw_patch_version = (uint8)XCP_SW_PATCH_VERSION;
}
#endif /*XCP_VERSION_INFO_API == STD_ON*/
/**
* Initializing function
*
* ServiceId: 0x00
*
* @param Xcp_ConfigPtr
*/
/** @req 4.1.3/SWS_Xcp_00803 *//*Xcp_Init API definition*/
/** @req 4.1.3/SWS_Xcp_00802 *//*The function Xcp_Init shall internally store the configuration address to enable subsequent API calls to access the configuration.*/
/** @req 4.1.3/SWS_Xcp_00834 *//*Xcp_Init shall check the parameter Xcp_ConfigType for not being a NULL pointer*/
void Xcp_Init(const Xcp_ConfigType* Xcp_ConfigPtr)
{
DET_VALIDATE_NRV(Xcp_ConfigPtr, XCP_API_ID_XCP_INIT, XCP_E_INV_POINTER);
/** Save the pointer. */
xcpPtr = Xcp_ConfigPtr;
memset(xcpPtr->rt, 0, sizeof(*xcpPtr->rt));
Xcp_Fifo_Init(&Xcp_RxCtoFifoFree, Xcp_RxCtoBuffers, Xcp_RxCtoBuffers + sizeof(Xcp_RxCtoBuffers) / sizeof(Xcp_RxCtoBuffers[0]));
Xcp_Fifo_Init(&Xcp_RxDtoFifoFree, Xcp_RxDtoBuffers, Xcp_RxDtoBuffers + sizeof(Xcp_RxDtoBuffers) / sizeof(Xcp_RxDtoBuffers[0]));
Xcp_Fifo_Init(&Xcp_TxCtoFifoFree, Xcp_TxCtoBuffers, Xcp_TxCtoBuffers + sizeof(Xcp_TxCtoBuffers) / sizeof(Xcp_TxCtoBuffers[0]));
// init the preconfigured and the static daqs
for (uint16 daqNr = 0; daqNr < xcpPtr->XcpDaqListSize; daqNr++) {
Xcp_DaqListType* daq = xcpPtr->XcpDaqList + daqNr;
Xcp_DaqListCfgType* daqCfg = xcpPtr->XcpDaqListCfg + daqNr;
memset(daq, 0, sizeof(*daq));
daq->EventChannel = daqCfg->FixedEventChannel;
daq->XcpOdt = daqCfg->XcpOdt;
daq->XcpMaxOdt = daqCfg->XcpMaxOdt;
}
/* Initialize XcpMaxDaq which means the currently available DAQ number*/
xcpPtr->rt->XcpMaxDaq = xcpPtr->XcpDaqListSize;
//initialize daq - event runtime assignment table
for (uint16 eventNr = 0; eventNr < XCP_EVENT_COUNT; eventNr++) {
XcpEventChannelTriggeredDaqListRef[eventNr] = 0;
}
//create chain for the fixed events
for (uint16 eventNr = 0; eventNr < XCP_EVENT_COUNT; eventNr++) {
for (uint16 daqNr = 0; daqNr < xcpPtr->XcpDaqListSize; daqNr++) {
Xcp_DaqListType* daq = xcpPtr->XcpDaqList + daqNr;
if (daq->EventChannel == eventNr) {
if(XcpEventChannelTriggeredDaqListRef[eventNr] == 0) {
XcpEventChannelTriggeredDaqListRef[eventNr] = &daq->EventDaqListNext;
daq->EventDaqListNext = daq;
} else {
daq->EventDaqListNext = *XcpEventChannelTriggeredDaqListRef[eventNr];
*XcpEventChannelTriggeredDaqListRef[eventNr] = daq;
XcpEventChannelTriggeredDaqListRef[eventNr] = &daq->EventDaqListNext;
}
}
}
}
Xcp_TxOngoing = 0;
//Initialize Communication specific channel
#if (XCP_PROTOCOL == XCP_PROTOCOL_CAN)
Xcp_CanLayerInit();
#elif (XCP_PROTOCOL == XCP_PROTOCOL_ETHERNET)
Xcp_SoAdLayerInit();
#endif
Xcp_Inited = 1;
}
/**
* Function called from lower layers (CAN/Ethernet..) containing
* a received XCP packet.
*
* Can be called in interrupt context.
*
* @param data
* @param len
*/
void Xcp_RxIndication(const uint8* data, PduLengthType len) {
if (len > XCP_MAX_DTO) {
DEBUG(DEBUG_HIGH, "Xcp_RxIndication - length %d too long\n", len);
return;
}
if (len == 0) {
return;
}
uint8 pid = GET_UINT8(data, 0);
if (pid > XCP_PID_CMD_STIM_LAST) {
/* process xcp commands */
FIFO_GET_WRITE(Xcp_FifoRxCto, it) {
Xcp_MemCpy(it->data, data, len);
it->len = len;
}
}
}
/**
* Xcp_TxError sends an error message back to master
* @param code is the error code requested
*/
void Xcp_TxError(Xcp_ErrorType code) {
FIFO_GET_WRITE(Xcp_FifoTxCto, e)
{
SET_UINT8(e->data, 0, (uint8)XCP_PID_ERR);
SET_UINT8(e->data, 1, (uint8)code);
e->len = 2;
}
}
/**
* Xcp_TxSuccess sends a basic RES response without
* extra data to master
*/
void Xcp_TxSuccess(void) {
FIFO_GET_WRITE(Xcp_FifoTxCto, e)
{
SET_UINT8(e->data, 0, XCP_PID_RES);
e->len = 1;
}
}
/** @req 4.1.3/SWS_Xcp_00709 *//*The AUTOSAR XCP Module shall support Timestamped Data Transfer (read / write access).*/
/** @req 4.1.3/SWS_Xcp_00768 *//*The ECU local time shall be derived from the AUTOSAR OS*/
static uint32 Xcp_GetTimeStamp(void) {
#if(XCP_TIMESTAMP_SIZE)
TickType counter;
if(GetCounterValue(XCP_COUNTER_ID, &counter)) {
counter = 0;
}
#if(XCP_TIMESTAMP_SIZE == 1)
return counter % 256;
#elif(XCP_TIMESTAMP_SIZE == 2)
return counter % (256*256);
#else /*XCP_TIMESTAMP_SIZE == 4*/
return counter;
#endif
#else /*XCP_TIMESTAMP_SIZE == 0*/
return 0;
#endif
}
/** @req 4.1.3/SWS_Xcp_00705 *//*The AUTOSAR XCP Module shall support Synchronous data acquisition (measurement)*/
static void Xcp_ProcessDaq_DAQ(Xcp_DaqListType* daq) {
static Xcp_BufferType dto;
dto.len = 0;
Xcp_OdtType* odt = daq->NextOdtToSend;
#if (XCP_IDENTIFICATION == XCP_IDENTIFICATION_ABSOLUTE)
FIFO_ADD_U8(&dto, (odt - daq->XcpOdt + daq->FirstPid));
#else
FIFO_ADD_U8(&dto, odt - daq->XcpOdt);
#endif
#if (XCP_IDENTIFICATION == XCP_IDENTIFICATION_RELATIVE_WORD)
FIFO_ADD_U16(&dto, daq->XcpDaqListNumber);
#elif (XCP_IDENTIFICATION == XCP_IDENTIFICATION_RELATIVE_WORD_ALIGNED)
FIFO_ADD_U8 (&dto, 0); /* RESERVED */
FIFO_ADD_U16(&dto, daq - xcpPtr->XcpDaqList);
#elif (XCP_IDENTIFICATION == XCP_IDENTIFICATION_RELATIVE_BYTE)
FIFO_ADD_U8(&dto, daq - xcpPtr->XcpDaqList);
#endif
#if XCP_TIMESTAMP_SIZE != 0
if(odt == daq->XcpOdt) {
// only transmit timestamp on firt odt within daq
uint8 ts = daq->Mode & XCP_DAQLIST_MODE_TIMESTAMP;
if (ts) {
#if (XCP_TIMESTAMP_SIZE == 1)
FIFO_ADD_U8 (&dto, Xcp_GetTimeStamp());
#elif (XCP_TIMESTAMP_SIZE == 2)
FIFO_ADD_U16(&dto, Xcp_GetTimeStamp());
#elif (XCP_TIMESTAMP_SIZE == 4)
FIFO_ADD_U32(&dto, Xcp_GetTimeStamp());
#endif
}
}
#endif
Xcp_OdtEntryType* ent = odt->XcpOdtEntry;
Xcp_Fifo_Lock(); // all entries within an odt shall be consistent
for (uint8 i = 0; i < odt->XcpOdtEntriesCount; i++) {
uint8 len = ent->XcpOdtEntryLength;
Xcp_MtaType mta;
xcpPtr->XcpMtaInit(&mta, ent->XcpOdtEntryAddress, ent->XcpOdtEntryExtension);
if (len == 0 || len + dto.len > XCP_MAX_DTO) {
break;
}
Xcp_MtaRead(&mta, dto.data + dto.len, len);
dto.len += len;
ent++;
}
odt++;
if((daq->XcpMaxOdt > odt - daq->XcpOdt) && (odt->XcpOdtEntry != 0) && (odt->XcpOdtEntry->XcpOdtEntryLength != 0)) {
daq->NextOdtToSend = odt;
} else {
daq->NextOdtToSend = 0;
Xcp_DaqTxList = daq->TxDaqListNext;
daq->TxDaqListNext = 0;
if(!Xcp_DaqTxList) {
Xcp_DaqTxListLast = 0;
}
}
Xcp_Fifo_Unlock();
Std_ReturnType retVal = Xcp_Transmit(dto.data, dto.len);
if (E_OK != retVal) {
Xcp_TxOngoing = 0;
DEBUG(DEBUG_HIGH, "Xcp_Transmit_Main - failed to transmit\n");
}
}
/* Process all entries in event channel */
static void Xcp_ProcessChannel(uint16 event) {
if(XcpEventChannelTriggeredDaqListRef[event] == 0) {
// no daqs referenced, return
return;
}
Xcp_DaqListType *daq = *XcpEventChannelTriggeredDaqListRef[event];
do {
if (!(daq->Mode & XCP_DAQLIST_MODE_RUNNING)) {
continue;
}
daq->Timer++;
if (daq->Timer < daq->Prescaler) {
continue;
}
daq->Timer = 0;
if(daq->NextOdtToSend) {
// daq processing ongoing
// send daq overrun and continue with next
continue;
}
if(daq->XcpMaxOdt == 0 || daq->XcpOdt->XcpOdtEntriesCount == 0 || daq->XcpOdt->XcpOdtEntry->XcpOdtEntryLength == 0) {
// nothing to send in daq, continue
continue;
}
daq->NextOdtToSend = daq->XcpOdt;
Xcp_Fifo_Lock();
if(Xcp_DaqTxListLast) {
Xcp_DaqTxListLast->TxDaqListNext = daq;
Xcp_DaqTxListLast = daq;
Xcp_Fifo_Unlock();
} else {
Xcp_DaqTxList = Xcp_DaqTxListLast = daq;
if(!Xcp_TxOngoing) {
Xcp_TxOngoing = 3;
Xcp_Fifo_Unlock();
Xcp_ProcessDaq_DAQ(Xcp_DaqTxList);
} else {
Xcp_Fifo_Unlock();
}
}
daq = daq->EventDaqListNext;
} while(daq != *XcpEventChannelTriggeredDaqListRef[event]);
}
/**************************************************************************/
/**************************************************************************/
/**************************** GENERIC COMMANDS ****************************/
/**************************************************************************/
/**************************************************************************/
static Std_ReturnType Xcp_CmdConnect(uint8 pid, uint8* data, PduLengthType len) {
uint8 mode = GET_UINT8(data, 0);
DEBUG(DEBUG_HIGH, "Received connect mode %x\n", mode);
XCP_UNUSED(len);
XCP_UNUSED(pid);
if (mode != 0) {
RETURN_ERROR(XCP_ERR_CMD_UNKNOWN, "Xcp_CmdConnect\n");
}
uint16 endiantest = 0x100;
uint8 endian = *((uint8*)&endiantest); /*Byte order - 1:High byte first*/
uint8 resource = 0u;
uint8 comModeBasic = 0u;
#if (XCP_FEATURE_CALPAG == STD_ON)
resource |= 0x01u;
#endif
#if (XCP_FEATURE_DAQ == STD_ON)
resource |= 0x04u;
#endif
#if (XCP_FEATURE_STIM == STD_ON)
resource |= 0x08u;
#endif
#if (XCP_FEATURE_PGM == STD_ON)
resource |= 0x10u;
#endif
/* BYTE ORDER */
comModeBasic |= endian << 0;
/* ADDRESS_GRANULARITY */
//comModeBasic |= 0 << 1;
#if (XCP_FEATURE_BLOCKMODE == STD_ON)
/*SLAVE_BLOCK_MODE*/
comModeBasic |= 0x40u;
#endif
/* OPTIONAL */
//comModeBasic |= 0x00u;
if (!Xcp_Connected) {
/* restore varius state on a new connections */
xcpPtr->rt->XcpProtect = xcpPtr->XcpOriginalProtect;
}
Xcp_Connected = 1;
FIFO_GET_WRITE(Xcp_FifoTxCto, e)
{
FIFO_ADD_U8(e, XCP_PID_RES);
/* RESSOURCE */
FIFO_ADD_U8(e, resource);
/* COMM_MODE_BASIC */
FIFO_ADD_U8(e, comModeBasic);
FIFO_ADD_U8(e, XCP_MAX_CTO);
FIFO_ADD_U16(e, XCP_MAX_DTO);
FIFO_ADD_U8(e, XCP_PROTOCOL_MAJOR_VERSION);
FIFO_ADD_U8(e, XCP_TRANSPORT_MAJOR_VERSION);
}
return E_OK;
}
static Std_ReturnType Xcp_CmdGetStatus(uint8 pid, uint8* data, PduLengthType len) {
DEBUG(DEBUG_HIGH, "Received get_status\n");
XCP_UNUSED(pid);
XCP_UNUSED(data); /*lint !e920 Misra 2012 1.3 cast from pointer to void */
XCP_UNUSED(len);
/* find if any lists are running */
int running = 0;
for (int i = 0; i < xcpPtr->rt->XcpMaxDaq; i++) {
if (xcpPtr->XcpDaqList[i].Mode & XCP_DAQLIST_MODE_RUNNING) {
running = 1;
break;
}
}
FIFO_GET_WRITE(Xcp_FifoTxCto, e)
{
FIFO_ADD_U8(e, XCP_PID_RES);
FIFO_ADD_U8(e, 0u << 0u /* STORE_CAL_REQ */
| 0u << 2u /* STORE_DAQ_REQ */
| 0u << 3u /* CLEAR_DAQ_REQ */
| running << 6u /* DAQ_RUNNING */
| 0u << 7u /* RESUME */);
#if(XCP_FEATURE_PROTECTION == STD_ON)
FIFO_ADD_U8 (e, xcpPtr->rt->XcpProtect); /* Content resource protection */
#else
FIFO_ADD_U8(e, 0u); /* Content resource protection */
#endif
FIFO_ADD_U8(e, 0u); /* Reserved */
FIFO_ADD_U16(e, 0u); /* Session configuration ID */
}
return E_OK ;
}
static Std_ReturnType Xcp_CmdGetCommModeInfo(uint8 pid, uint8* data, PduLengthType len) {
uint8 commModeOptional = 0x00u
#if XCP_FEATURE_BLOCKMODE == STD_ON
| 1u << 0u /* MASTER_BLOCK_MODE */
#endif
| 0u << 1u; /* INTERLEAVED_MODE */
DEBUG(DEBUG_HIGH, "Received get_comm_mode_info\n");
XCP_UNUSED(pid);
XCP_UNUSED(data);/*lint !e920 Misra 2012 1.3 cast from pointer to void */
XCP_UNUSED(len);
FIFO_GET_WRITE(Xcp_FifoTxCto, e)
{
FIFO_ADD_U8(e, XCP_PID_RES);
FIFO_ADD_U8(e, 0); /* Reserved */
FIFO_ADD_U8(e, commModeOptional);
FIFO_ADD_U8(e, 0); /* Reserved */
FIFO_ADD_U8(e, XCP_MAX_RXTX_QUEUE - 1); /* MAX_BS */
FIFO_ADD_U8(e, 0); /* MIN_ST [100 microseconds] */
FIFO_ADD_U8(e, XCP_MAX_RXTX_QUEUE - 1); /* QUEUE_SIZE */
FIFO_ADD_U8(e, XCP_PROTOCOL_MAJOR_VERSION << 4 | XCP_PROTOCOL_MINOR_VERSION); /* Xcp driver version */
}
return E_OK;
}
static Std_ReturnType Xcp_CmdGetId(uint8 pid, uint8* data, PduLengthType len) {
uint8 idType = GET_UINT8(data, 0);
const char* text = NULL;
DEBUG(DEBUG_HIGH, "Received get_id %d\n", idType);
XCP_UNUSED(pid);
XCP_UNUSED(len);
if (idType == 0) {
text = xcpPtr->XcpInfo.XcpCaption;
} else if (idType == 1) {
text = xcpPtr->XcpInfo.XcpMC2File;
} else if (idType == 2) {
text = xcpPtr->XcpInfo.XcpMC2Path;
} else if (idType == 3) {
text = xcpPtr->XcpInfo.XcpMC2Url;
} else if (idType == 4) {
text = xcpPtr->XcpInfo.XcpMC2Upload;
}
uint8 text_len = 0;
if (text) {
text_len = strlen(text);
}
#if (XCP_MAX_CTO > 8)
if(text_len + 8 < XCP_MAX_CTO) {
FIFO_GET_WRITE(Xcp_FifoTxCto, e) {
FIFO_ADD_U8 (e, XCP_PID_RES);
FIFO_ADD_U8 (e, 1); /* Mode */
FIFO_ADD_U16 (e, 0); /* Reserved */
FIFO_ADD_U32 (e, text_len); /* Length */
if(text) {
Xcp_MtaType mta;
xcpPtr->XcpMtaInit(&mta, (uint32)text, XCP_MTA_EXTENSION_MEMORY_INTERNAL_FIXED);
Xcp_MtaRead(&mta, e->data+e->len, text_len);
e->len += text_len;
}
}
} else
#endif
{
xcpPtr->XcpMtaInit(&Xcp_Mta, (uint32) text, XCP_MTA_EXTENSION_MEMORY_INTERNAL_FIXED);
FIFO_GET_WRITE(Xcp_FifoTxCto, e)
{
FIFO_ADD_U8(e, XCP_PID_RES);
FIFO_ADD_U8(e, 0); /* Mode */
FIFO_ADD_U16(e, 0); /* Reserved */
FIFO_ADD_U32(e, text_len); /* Length */
}
}
return E_OK ;
}
static Std_ReturnType Xcp_CmdDisconnect(uint8 pid, uint8* data, PduLengthType len) {
XCP_UNUSED(len);
XCP_UNUSED(data);/*lint !e920 Misra 2012 1.3 cast from pointer to void */
XCP_UNUSED(pid);
if (Xcp_Connected) {
DEBUG(DEBUG_HIGH, "Received disconnect\n");
} else {
DEBUG(DEBUG_HIGH, "Invalid disconnect without connect\n");
}
Xcp_Connected = 0;
RETURN_SUCCESS();
}
static Std_ReturnType Xcp_CmdSync(uint8 pid, uint8* data, PduLengthType len) {
XCP_UNUSED(len);
XCP_UNUSED(data);/*lint !e920 Misra 2012 1.3 cast from pointer to void */
XCP_UNUSED(pid);
RETURN_ERROR(XCP_ERR_CMD_SYNCH, "Xcp_CmdSync\n");
}
static Std_ReturnType Xcp_CmdUser(uint8 pid, uint8* data, PduLengthType len) {
XCP_UNUSED(pid);
if (xcpPtr->XcpUserFn) {
return xcpPtr->XcpUserFn((uint8 *) data + 1, len - 1);
} else {
RETURN_ERROR(XCP_ERR_CMD_UNKNOWN, "Xcp_CmdUser\n");
}
}
/**************************************************************************/
/**************************************************************************/
/*********************** UPLOAD/DOWNLOAD COMMANDS *************************/
/**************************************************************************/
/**************************************************************************/
/**
* Worker function for blockmode uploads
*
* This function will be called once every main function run and send off
* a upload package, when done it will unregister itself from main process
*
*/
static void Xcp_CmdUpload_Worker(void) {
PduLengthType len = Xcp_Upload.rem;
PduLengthType off = XCP_ELEMENT_OFFSET(1);
PduLengthType max = XCP_MAX_CTO - off - 1;
if (len > max) {
len = max;
}
FIFO_GET_WRITE(Xcp_FifoTxCto, e)
{
SET_UINT8(e->data, 0, XCP_PID_RES);
for (PduLengthType i = 0; i < off; i++) {
SET_UINT8(e->data, i + 1, 0);
}
for (PduLengthType i = 0; i < len; i++) {
SET_UINT8(e->data, i + 1 + off, Xcp_MtaGet(&Xcp_Mta));
}
e->len = len + 1 + off;
}
Xcp_Upload.rem -= len;
if (Xcp_Upload.rem == 0) {
Xcp_Worker = NULL;
}
}
static Std_ReturnType Xcp_CmdUpload(uint8 pid, uint8* data, PduLengthType len) {
DEBUG(DEBUG_HIGH, "Received upload\n");
XCP_UNUSED(len);
XCP_UNUSED(pid);
Xcp_Upload.len = GET_UINT8(data, 0) * XCP_ELEMENT_SIZE;
Xcp_Upload.rem = Xcp_Upload.len;
#ifndef XCP_FEATURE_BLOCKMODE
if(Xcp_Upload.len + 1 > XCP_MAX_CTO) {
RETURN_ERROR(XCP_ERR_CMD_UNKNOWN, "Xcp_CmdUpload - Block mode not supported\n");
}
#endif
Xcp_Worker = Xcp_CmdUpload_Worker;
Xcp_Worker();
return E_OK ;
}
static Std_ReturnType Xcp_CmdShortUpload(uint8 pid, uint8* data, PduLengthType len) {
uint8 count = GET_UINT8(data, 0);
uint8 ext = GET_UINT8(data, 2);
uint32 addr = GET_UINT32(data, 3);
DEBUG(DEBUG_HIGH, "Received short upload\n");
XCP_UNUSED(len);
XCP_UNUSED(pid);
if (count > XCP_MAX_CTO - XCP_ELEMENT_SIZE) {
RETURN_ERROR(XCP_ERR_CMD_SYNTAX, "Xcp_CmdShortUpload - Too long data requested\n");
}
xcpPtr->XcpMtaInit(&Xcp_Mta, addr, ext);
if (Xcp_Mta.read == NULL) {
RETURN_ERROR(XCP_ERR_CMD_SYNTAX, "Xcp_CmdShortUpload - invalid memory address\n");
}
FIFO_GET_WRITE(Xcp_FifoTxCto, e)
{
SET_UINT8(e->data, 0, XCP_PID_RES);
#if (XCP_ELEMENT_SIZE > 1)
memset(e->data+1, 0, XCP_ELEMENT_SIZE - 1);
#endif
Xcp_MtaRead(&Xcp_Mta, e->data + XCP_ELEMENT_SIZE, count);
e->len = count + XCP_ELEMENT_SIZE;
}
return E_OK ;
}
static Std_ReturnType Xcp_CmdSetMTA(uint8 pid, uint8* data, PduLengthType len) {
int ext = GET_UINT8(data, 2);
int ptr = GET_UINT32(data, 3);
DEBUG(DEBUG_HIGH, "Received set_mta 0x%x, %d\n", ptr, ext);
XCP_UNUSED(pid);
XCP_UNUSED(len);
xcpPtr->XcpMtaInit(&Xcp_Mta, ptr, ext);
RETURN_SUCCESS();
}
static Std_ReturnType Xcp_CmdDownload(uint8 pid, uint8* data, PduLengthType len) {
uint32 rem = GET_UINT8(data, 0) * XCP_ELEMENT_SIZE;
uint32 off = XCP_ELEMENT_OFFSET(2) + 1;
DEBUG(DEBUG_HIGH, "Received download %d, %d\n", pid, len);
if (!Xcp_Mta.write) {
RETURN_ERROR(XCP_ERR_WRITE_PROTECTED, "Xcp_Download - Mta not inited\n");
}
#if(!XCP_FEATURE_BLOCKMODE)
if(rem + off > len) {
RETURN_ERROR(XCP_ERR_OUT_OF_RANGE, "Xcp_Download - Invalid length (%u, %u, %d)\n", rem, off, len);
}
#endif
if (pid == XCP_PID_CMD_CAL_DOWNLOAD) {
Xcp_Download.len = rem;
Xcp_Download.rem = rem;
}
/* check for sequence error */
if (Xcp_Download.rem != rem) {
DEBUG(DEBUG_HIGH, "Xcp_Download - Invalid next state (%u, %u)\n", rem, Xcp_Download.rem);
FIFO_GET_WRITE(Xcp_FifoTxCto, e) {
FIFO_ADD_U8(e, (uint8)XCP_PID_ERR);
FIFO_ADD_U8(e, (uint8)XCP_ERR_SEQUENCE);
FIFO_ADD_U8(e, Xcp_Download.rem / XCP_ELEMENT_SIZE);
}
return E_OK ;
}
/* write what we got this packet */
if (rem > len - off) {
rem = len - off;
}
Xcp_MtaWrite(&Xcp_Mta, (uint8*) data + off, rem);
Xcp_Download.rem -= rem;
if (Xcp_Download.rem) {
return E_OK;
}
Xcp_MtaFlush(&Xcp_Mta);
RETURN_SUCCESS();
}
static Std_ReturnType Xcp_CmdBuildChecksum(uint8 pid, uint8* data, PduLengthType len) {
Xcp_ChecksumType type;
uint32 response;
uint32 block = GET_UINT32(data, 3);
DEBUG(DEBUG_HIGH, "Received build_checksum %ul\n", (uint32) block);
XCP_UNUSED(pid);
XCP_UNUSED(len);
if (!xcpPtr->XcpBuildChecksum) {
/*No CRC user function is defined*/
RETURN_ERROR(XCP_ERR_CMD_UNKNOWN, "Xcp_CmdBuildChecksum\n");
}
if (!Xcp_Mta.get) {
RETURN_ERROR(XCP_ERR_OUT_OF_RANGE, "Xcp_CmdBuildChecksum - Mta not inited\n");
}
/*callout function is used to calculate CRC*/
xcpPtr->XcpBuildChecksum(&Xcp_Mta,block,&type,&response);
FIFO_GET_WRITE(Xcp_FifoTxCto, e)
{
FIFO_ADD_U8(e, XCP_PID_RES);
FIFO_ADD_U8(e, (uint8)type);
FIFO_ADD_U8(e, 0); /* reserved */
FIFO_ADD_U8(e, 0); /* reserved */
FIFO_ADD_U32(e, response);
}
return E_OK;
}
/**************************************************************************/
/**************************************************************************/
/*************************** DAQ/STIM COMMANDS ****************************/
/**************************************************************************/
/**************************************************************************/
static Std_ReturnType Xcp_CmdClearDaqList(uint8 pid, uint8* data, PduLengthType len) {
uint16 daqListNumber = GET_UINT16(data, 1);
DEBUG(DEBUG_HIGH, "Received ClearDaqList\n");
XCP_UNUSED(pid);
XCP_UNUSED(len);
if (daqListNumber >= xcpPtr->rt->XcpMaxDaq) {
RETURN_ERROR(XCP_ERR_OUT_OF_RANGE, "Error: daq list number out of range\n");
}
Xcp_DaqListType* daq = xcpPtr->XcpDaqList + daqListNumber;
if (daq->Mode & XCP_DAQLIST_MODE_RUNNING) {
daq->Mode &= ~XCP_DAQLIST_MODE_RUNNING; // ensure that the code isn't using running mode as indicator if daq list is in ready queue.
}
#if XCP_MIN_DAQ > 0
if(daqListNumber > XCP_MIN_DAQ)
#endif
{
for (int i = 0; i < daq->XcpMaxOdt; i++) {
Xcp_OdtType* odt = daq->XcpOdt + i;
for (int j = 0; j < odt->XcpOdtEntriesCount; j++) {
Xcp_OdtEntryType* entry = odt->XcpOdtEntry + j;
entry->XcpOdtEntryAddress = 0;
entry->XcpOdtEntryExtension = 0;
entry->XcpOdtEntryLength = 0;
entry->BitOffSet = 0xFF;
}
}
}
RETURN_SUCCESS();
}
static Std_ReturnType Xcp_CmdSetDaqPtr(uint8 pid, uint8* data, PduLengthType len) {
uint16 daqListNumber = GET_UINT16(data, 1);
uint8 odtNumber = GET_UINT8(data, 3);
uint8 odtEntryNumber = GET_UINT8(data, 4);
DEBUG(DEBUG_HIGH, "Received SetDaqPtr %u, %u, %u\n", daqListNumber,odtNumber, odtEntryNumber);
XCP_UNUSED(pid);
XCP_UNUSED(len);
if (daqListNumber >= xcpPtr->rt->XcpMaxDaq) {
RETURN_ERROR(XCP_ERR_OUT_OF_RANGE, "Error: daq list number out of range\n");
}
Xcp_DaqListType* daq = xcpPtr->XcpDaqList + daqListNumber;
if (daq->Mode & XCP_DAQLIST_MODE_RUNNING) {
RETURN_ERROR(XCP_ERR_DAQ_ACTIVE, "Error: DAQ running\n");
}
if (odtNumber >= daq->XcpMaxOdt) {
RETURN_ERROR(XCP_ERR_OUT_OF_RANGE, "Error: odt number out of range (%u, %u)\n", odtNumber, daq->XcpMaxOdt);
}
Xcp_OdtType* odt = daq->XcpOdt + odtNumber;
if (odtEntryNumber >= odt->XcpOdtEntriesCount) {
RETURN_ERROR(XCP_ERR_OUT_OF_RANGE, "Error: odt entry number out of range\n");
}
Xcp_OdtEntryType* odtEntry = odt->XcpOdtEntry + odtEntryNumber;
Xcp_DaqState.daq = daq;
Xcp_DaqState.odt = odt;
Xcp_DaqState.ptr = odtEntry;
RETURN_SUCCESS();
}
static Std_ReturnType Xcp_CmdWriteDaq(uint8 pid, uint8* data, PduLengthType len) {
DEBUG(DEBUG_HIGH, "Received WriteDaq\n");
XCP_UNUSED(pid);
XCP_UNUSED(len);
if (Xcp_DaqState.ptr == NULL) {
RETURN_ERROR(XCP_ERR_OUT_OF_RANGE, "Error: No more ODT entries in this ODT\n");
}
#if (XCP_MIN_DAQ > 0)
/* Check if DAQ list is write protected */
if (Xcp_DaqState.daq - xcpPtr->XcpDaqList < XCP_MIN_DAQ) {
RETURN_ERROR(XCP_ERR_WRITE_PROTECTED, "Error: DAQ-list is read only\n");
}
#endif
if (Xcp_DaqState.daq->Mode & XCP_DAQLIST_MODE_RUNNING) {
RETURN_ERROR(XCP_ERR_DAQ_ACTIVE, "Error: DAQ running\n");
}
uint8 maxOdtEntrySize;
uint8 granularityOdtEntrySize;
if (Xcp_DaqState.daq->Mode & XCP_DAQLIST_MODE_STIM) /* Get DAQ list Direction */
{
maxOdtEntrySize = XCP_MAX_ODT_ENTRY_SIZE_STIM;
granularityOdtEntrySize = XCP_GRANULARITY_ODT_ENTRY_SIZE_STIM;
} else {
maxOdtEntrySize = XCP_MAX_ODT_ENTRY_SIZE_DAQ;
granularityOdtEntrySize = XCP_GRANULARITY_ODT_ENTRY_SIZE_DAQ;
}
uint8 daqElemSize = GET_UINT8(data, 1);
if (daqElemSize > maxOdtEntrySize) {
RETURN_ERROR(XCP_ERR_OUT_OF_RANGE, "Error: DAQ list element size is invalid\n");
}
uint8 bitOffSet = GET_UINT8(data, 0);
if (bitOffSet <= 0x1F) {
if (daqElemSize == granularityOdtEntrySize) {
Xcp_DaqState.ptr->BitOffSet = bitOffSet;
} else {
RETURN_ERROR(XCP_ERR_OUT_OF_RANGE, "Error: Element size and granularity don't match\n");
}
} else {
Xcp_DaqState.ptr->BitOffSet = 0xFF;
}
Xcp_DaqState.ptr->XcpOdtEntryExtension = GET_UINT8(data, 2);
Xcp_DaqState.ptr->XcpOdtEntryAddress = GET_UINT32(data, 3);
Xcp_DaqState.ptr->XcpOdtEntryLength = daqElemSize;
Xcp_DaqState.ptr++;
if(Xcp_DaqState.odt->XcpOdtEntriesCount <= Xcp_DaqState.ptr - Xcp_DaqState.odt->XcpOdtEntry) {
Xcp_DaqState.ptr = NULL;
Xcp_DaqState.daq = NULL;
Xcp_DaqState.odt = NULL;
}
RETURN_SUCCESS();
}
static void Xcp_CmdSetDaqListMode_EventChannel(Xcp_DaqListType* daq, uint16 newEventChannelNumber) {
if(daq->EventChannel == newEventChannelNumber) {
// already allocated to event, return
return;
}
if (daq->EventChannel < XCP_EVENT_COUNT /* !=0xFFFF*/) {
//Remove daq ref from XcpEventChannelTriggeredDaqListRef
if(daq->EventDaqListNext == daq) {
// this is the only daq allocated to event, clear event list ptr
XcpEventChannelTriggeredDaqListRef[daq->EventChannel] = 0;
//Remove daq ref from chain, point the XcpEventChannelTriggeredDaqListRef to the rest
} else {
Xcp_DaqListType *daqP = daq->EventDaqListNext;
while(daqP->EventDaqListNext != daq) {
daqP = daqP->EventDaqListNext;
}
daqP->EventDaqListNext = daq->EventDaqListNext;
XcpEventChannelTriggeredDaqListRef[daq->EventChannel] = &daqP->EventDaqListNext;
}
}
if(newEventChannelNumber < XCP_EVENT_COUNT /* !=0xFFFF*/) {
// add daq to new event channel
if(XcpEventChannelTriggeredDaqListRef[newEventChannelNumber] == 0) {
XcpEventChannelTriggeredDaqListRef[newEventChannelNumber] = &daq->EventDaqListNext;
daq->EventDaqListNext = daq;
} else {
daq->EventDaqListNext = *XcpEventChannelTriggeredDaqListRef[newEventChannelNumber];
*XcpEventChannelTriggeredDaqListRef[newEventChannelNumber] = daq;
XcpEventChannelTriggeredDaqListRef[newEventChannelNumber] = &daq->EventDaqListNext;
}
}
daq->EventChannel = newEventChannelNumber;
}
static Std_ReturnType Xcp_CmdSetDaqListMode(uint8 pid, uint8* data, PduLengthType len) {
uint16 list = GET_UINT16(data, 1);
uint16 event = GET_UINT16(data, 3);
uint8 prio = GET_UINT8(data, 6);
uint8 mode = GET_UINT8(data, 0);
DEBUG(DEBUG_HIGH, "Received SetDaqListMode\n");
XCP_UNUSED(pid);
XCP_UNUSED(len);
if (list >= xcpPtr->rt->XcpMaxDaq || event >= XCP_EVENT_COUNT) {
RETURN_ERROR(XCP_ERR_OUT_OF_RANGE, "Error: daq list number out of range\n");
}
Xcp_DaqListType *daq = xcpPtr->XcpDaqList + list;
if (daq->Mode & XCP_DAQLIST_MODE_RUNNING) {
RETURN_ERROR(XCP_ERR_DAQ_ACTIVE, "Error: DAQ running\n");
}
/* Check to see if the event channel supports the direction of the DAQ list.
* Can DAQ list be set to requested direction.
* Is the DAQ Predefined or Event_fixed
* */
if(list < xcpPtr->XcpDaqListSize) {
// this is a static or predefined list
Xcp_DaqListCfgType *daqCfg = xcpPtr->XcpDaqListCfg + list;
if (!( ( (mode & XCP_DAQLIST_MODE_STIM)
&& (daqCfg->Properties & XCP_DAQLIST_PROPERTY_STIM)
) ||
( (!(mode & XCP_DAQLIST_MODE_STIM))
&& (daqCfg->Properties & XCP_DAQLIST_PROPERTY_DAQ)
)) ) {
RETURN_ERROR(XCP_ERR_CMD_SYNTAX, "Error: direction not allowed.\n");
}
if ((daqCfg->Properties & XCP_DAQLIST_PROPERTY_EVENTFIXED)
&& (event != daqCfg->FixedEventChannel)) {
RETURN_ERROR(XCP_ERR_DAQ_CONFIG, "Error: DAQ list has a fixed event channel\n");
}
}
if (!( ( (mode & XCP_DAQLIST_MODE_STIM)
&& ((uint8)xcpPtr->XcpEventChannel[event].XcpEventChannelProperties & (uint8)XCP_EVENTCHANNEL_PROPERTY_STIM)
) ||
( (!(mode & XCP_DAQLIST_MODE_STIM))
&& ((uint8)xcpPtr->XcpEventChannel[event].XcpEventChannelProperties & (uint8)XCP_EVENTCHANNEL_PROPERTY_DAQ)
)) ) {
RETURN_ERROR(XCP_ERR_CMD_SYNTAX, "Error: direction not allowed.\n");
}
#if (XCP_MIN_DAQ > 0)
if (list < XCP_MIN_DAQ) {
RETURN_ERROR(XCP_ERR_OUT_OF_RANGE, "Error: DAQ list is Predefined\n");
}
#endif
daq->Mode = (Xcp_DaqListModeEnum)((mode & 0x32) | (daq->Mode & ~0x32));
Xcp_CmdSetDaqListMode_EventChannel(daq, event);
daq->Prescaler = GET_UINT8(data, 5);
daq->Priority = prio;
RETURN_SUCCESS();
}
static Std_ReturnType Xcp_CmdGetDaqListMode(uint8 pid, uint8* data, PduLengthType len) {
uint16 daqListNumber = GET_UINT16(data, 1);
DEBUG(DEBUG_HIGH, "Received GetDaqListMode\n");
XCP_UNUSED(pid);
XCP_UNUSED(len);
if (daqListNumber >= xcpPtr->rt->XcpMaxDaq) {
RETURN_ERROR(XCP_ERR_OUT_OF_RANGE, "Error: DAQ list number out of range\n");
}
Xcp_DaqListType* daq = xcpPtr->XcpDaqList + daqListNumber;
FIFO_GET_WRITE(Xcp_FifoTxCto, e)
{
FIFO_ADD_U8(e, XCP_PID_RES);
FIFO_ADD_U8(e, daq->Mode); /* Mode */
FIFO_ADD_U16(e, 0); /* Reserved */
FIFO_ADD_U16(e, daq->EventChannel); /* Current Event Channel Number */
FIFO_ADD_U8(e, daq->Prescaler); /* Current Prescaler */
FIFO_ADD_U8(e, daq->Priority); /* Current DAQ list Priority */
}
return E_OK ;
}
static Std_ReturnType Xcp_CmdStartStopDaqList(uint8 pid, uint8* data, PduLengthType len) {
uint16 daqListNumber = GET_UINT16(data, 1);
DEBUG(DEBUG_HIGH, "Received StartStopDaqList\n");
XCP_UNUSED(pid);
XCP_UNUSED(len);
if (daqListNumber >= xcpPtr->rt->XcpMaxDaq) {
RETURN_ERROR(XCP_ERR_OUT_OF_RANGE, "Error: daq list number out of range\n");
}
Xcp_DaqListType* daq = xcpPtr->XcpDaqList + daqListNumber;
daq->FirstPid = 0;
for(int i = 0; i < daqListNumber; i++) {
daq->FirstPid += xcpPtr->XcpDaqList[i].XcpMaxOdt;
}
uint8 mode = GET_UINT8(data, 0);
if (mode == 0) {
/* STOP */
daq->Mode &= ~XCP_DAQLIST_MODE_RUNNING;
} else if (mode == 1) {
/* START */
daq->Mode |= XCP_DAQLIST_MODE_RUNNING;
} else if (mode == 2) {
/* SELECT */
daq->Mode |= XCP_DAQLIST_MODE_SELECTED;
} else {
RETURN_ERROR(XCP_ERR_MODE_NOT_VALID, "Error mode not valid\n");
}
FIFO_GET_WRITE(Xcp_FifoTxCto, e)
{
FIFO_ADD_U8(e, XCP_PID_RES);
FIFO_ADD_U8(e, daq->FirstPid);
}
return E_OK ;
}
static Std_ReturnType Xcp_CmdStartStopSynch(uint8 pid, uint8* data, PduLengthType len) {
uint8 mode = GET_UINT8(data, 0);
DEBUG(DEBUG_HIGH, "Received StartStopSynch %u\n", mode);
XCP_UNUSED(pid);
XCP_UNUSED(len);
Xcp_DaqListType* daq = xcpPtr->XcpDaqList;
if (mode == 0) {
/* STOP ALL */
for (int i = 0; i < xcpPtr->rt->XcpMaxDaq; i++) {
daq[i].Mode &= ~XCP_DAQLIST_MODE_RUNNING;
daq[i].Mode &= ~XCP_DAQLIST_MODE_SELECTED;
}
} else if (mode == 1) {
/* START SELECTED */
for (int i = 0; i < xcpPtr->rt->XcpMaxDaq; i++) {
if (daq[i].Mode & XCP_DAQLIST_MODE_SELECTED) {
daq[i].Mode |= XCP_DAQLIST_MODE_RUNNING;
daq[i].Mode &= ~XCP_DAQLIST_MODE_SELECTED;
}
}
} else if (mode == 2) {
/* STOP SELECTED */
for (int i = 0; i < xcpPtr->rt->XcpMaxDaq; i++) {
if (daq[i].Mode & XCP_DAQLIST_MODE_SELECTED) {
daq[i].Mode &= ~XCP_DAQLIST_MODE_RUNNING;
daq[i].Mode &= ~XCP_DAQLIST_MODE_SELECTED;
}
}
} else {
RETURN_ERROR(XCP_ERR_MODE_NOT_VALID, "Error mode not valid\n");
}
RETURN_SUCCESS();
}
static Std_ReturnType Xcp_CmdGetDaqClock(uint8 pid, uint8* data, PduLengthType len) {
DEBUG(DEBUG_HIGH, "Received GetDaqClock\n");
XCP_UNUSED(pid);
XCP_UNUSED(data);/*lint !e920 Misra 2012 1.3 cast from pointer to void */
XCP_UNUSED(len);
FIFO_GET_WRITE(Xcp_FifoTxCto, e) {
FIFO_ADD_U8(e, XCP_PID_RES);
FIFO_ADD_U8(e, 0); /* Alignment */
FIFO_ADD_U8(e, 0); /* Alignment */
FIFO_ADD_U8(e, 0); /* Alignment */
FIFO_ADD_U32(e, Xcp_GetTimeStamp());
}
return E_OK;
}
static Std_ReturnType Xcp_CmdReadDaq(uint8 pid, uint8* data, PduLengthType len) {
DEBUG(DEBUG_HIGH, "Received ReadDaq\n");
XCP_UNUSED(pid);
XCP_UNUSED(data);/*lint !e920 Misra 2012 1.3 cast from pointer to void */
XCP_UNUSED(len);
if (!Xcp_DaqState.ptr) {
RETURN_ERROR(XCP_ERR_DAQ_CONFIG, "Error: No more ODT entries in this ODT\n");
}
FIFO_GET_WRITE(Xcp_FifoTxCto, e) {
FIFO_ADD_U8(e, XCP_PID_RES);
FIFO_ADD_U8(e, Xcp_DaqState.ptr->BitOffSet);
FIFO_ADD_U8(e, Xcp_DaqState.ptr->XcpOdtEntryLength);
FIFO_ADD_U8(e, Xcp_DaqState.ptr->XcpOdtEntryExtension);
FIFO_ADD_U32(e, Xcp_DaqState.ptr->XcpOdtEntryAddress);
}
Xcp_DaqState.ptr++;
if(Xcp_DaqState.odt->XcpOdtEntriesCount <= Xcp_DaqState.ptr - Xcp_DaqState.odt->XcpOdtEntry) {
Xcp_DaqState.ptr = NULL;
Xcp_DaqState.daq = NULL;
Xcp_DaqState.odt = NULL;
}
return E_OK;
}
static Std_ReturnType Xcp_CmdGetDaqProcessorInfo(uint8 pid, uint8* data, PduLengthType len) {
uint8 daqProperties = 0x00u
#if (XCP_DAQ_CONFIG_TYPE == DAQ_DYNAMIC)
| 1 << 0 /* DAQ_CONFIG_TYPE */
#endif
#if (XCP_TIMESTAMP_SIZE > 0)
| 1 << 4 /* TIMESTAMP_SUPPORTED */
#endif
| 1 << 1 /* PRESCALER_SUPPORTED */
| 0 << 2 /* RESUME_SUPPORTED */
| 0 << 3 /* BIT_STIM_SUPPORTED */
| 0 << 5 /* PID_OFF_SUPPORTED */
| 0 << 6 /* OVERLOAD_MSB */
| 0 << 7 /* OVERLOAD_EVENT */;
DEBUG(DEBUG_HIGH, "Received GetDaqProcessorInfo\n");
XCP_UNUSED(pid);
XCP_UNUSED(data);/*lint !e920 Misra 2012 1.3 cast from pointer to void */
XCP_UNUSED(len);
FIFO_GET_WRITE(Xcp_FifoTxCto, e) {
FIFO_ADD_U8(e, XCP_PID_RES);
FIFO_ADD_U8(e, daqProperties);
FIFO_ADD_U16(e, xcpPtr->rt->XcpMaxDaq);
FIFO_ADD_U16(e, XCP_EVENT_COUNT);
FIFO_ADD_U8(e, XCP_MIN_DAQ);
FIFO_ADD_U8(e, 0 << 0 /* Optimisation_Type_0 */
| 0 << 1 /* Optimisation_Type_1 */
| 0 << 2 /* Optimisation_Type_2 */
| 0 << 3 /* Optimisation_Type_3 */
| 0 << 4 /* Address_Extension_ODT */
| 0 << 5 /* Address_Extension_DAQ */
| XCP_IDENTIFICATION << 6 /* Identification_Field_Type_0 and 1 */);
}
return E_OK;
}
static Std_ReturnType Xcp_CmdGetDaqResolutionInfo(uint8 pid, uint8* data, PduLengthType len) {
DEBUG(DEBUG_HIGH, "Received GetDaqResolutionInfo\n");
XCP_UNUSED(pid);
XCP_UNUSED(data);/*lint !e920 Misra 2012 1.3 cast from pointer to void */
XCP_UNUSED(len);
FIFO_GET_WRITE(Xcp_FifoTxCto, e) {
SET_UINT8(e->data, 0, XCP_PID_RES);
SET_UINT8(e->data, 1, XCP_GRANULARITY_ODT_ENTRY_SIZE_DAQ); /* GRANULARITY_ODT_ENTRY_SIZE_DAQ */
SET_UINT8(e->data, 2, XCP_MAX_ODT_ENTRY_SIZE_DAQ); /* MAX_ODT_ENTRY_SIZE_DAQ */
SET_UINT8(e->data, 3, XCP_GRANULARITY_ODT_ENTRY_SIZE_STIM); /* GRANULARITY_ODT_ENTRY_SIZE_STIM */
SET_UINT8(e->data, 4, XCP_MAX_ODT_ENTRY_SIZE_STIM); /* MAX_ODT_ENTRY_SIZE_STIM */
#if(XCP_TIMESTAMP_SIZE)
SET_UINT8 (e->data, 5, XCP_TIMESTAMP_SIZE << 0 /* TIMESTAMP_SIZE */
| 0 << 3 /* TIMESTAMP_FIXED */
| XCP_TIMESTAMP_UNIT << 4 /* TIMESTAMP_UNIT */);
SET_UINT16(e->data, 6, 1); /* TIMESTAMP_TICKS */
#else
SET_UINT8(e->data, 5, 0); /* TIMESTAMP_MODE */
SET_UINT16(e->data, 6, 0); /* TIMESTAMP_TICKS */
#endif
e->len = 8;
}
return E_OK ;
}
static Std_ReturnType Xcp_CmdGetDaqListInfo(uint8 pid, uint8* data, PduLengthType len) {
uint16 daqListNumber = GET_UINT16(data, 1);
/*temporary variable to calculate the maximum OdtEntry value of a given Daq*/
uint8 maxMaxOdtEntry = 0U;
uint8 Properties = 0;
DEBUG(DEBUG_HIGH, "Received GetDaqListInfo\n");
XCP_UNUSED(pid);
XCP_UNUSED(len);
if (daqListNumber >= xcpPtr->rt->XcpMaxDaq) {
RETURN_ERROR(XCP_ERR_OUT_OF_RANGE, "Error: Xcp_GetDaqListInfo list number out of range\n");
}
Xcp_DaqListType* daq = xcpPtr->XcpDaqList+daqListNumber;
for (uint8 odtNr = 0; odtNr < daq->XcpMaxOdt; odtNr++) {
Xcp_OdtType* odt = daq->XcpOdt + odtNr;
if (odt->XcpOdtEntriesCount > maxMaxOdtEntry) {
maxMaxOdtEntry = odt->XcpOdtEntriesCount;
}
}
#if XCP_MIN_DAQ > 0
if(daqListNumber < XCP_MIN_DAQ) {
Properties |= XCP_DAQLIST_PROPERTY_PREDEFINED;
}
#endif
if(daqListNumber < xcpPtr->XcpDaqListSize) {
Properties |= XCP_DAQLIST_PROPERTY_EVENTFIXED;
Properties |= xcpPtr->XcpDaqListCfg[daqListNumber].Properties & 0xC;
} else {
Properties |= XCP_DAQLIST_PROPERTY_DAQ_STIM;
}
FIFO_GET_WRITE(Xcp_FifoTxCto, e)
{
SET_UINT8(e->data, 0, XCP_PID_RES);
SET_UINT8(e->data, 1, Properties);
SET_UINT8(e->data, 2, daq->XcpMaxOdt); /* MAX_ODT */
SET_UINT8(e->data, 3, maxMaxOdtEntry); /* MAX_ODT_ENTRIES */
SET_UINT16(e->data, 4, daq->EventChannel); /* FIXED_EVENT */
e->len = 6;
}
return E_OK ;
}
static Std_ReturnType Xcp_CmdGetDaqEventInfo(uint8 pid, uint8* data, PduLengthType len) {
uint16 eventChannelNumber = GET_UINT16(data, 1);
DEBUG(DEBUG_HIGH, "Received GetDaqEventInfo\n");
XCP_UNUSED(pid);
XCP_UNUSED(len);
if (eventChannelNumber >= XCP_EVENT_COUNT) {
RETURN_ERROR(XCP_ERR_OUT_OF_RANGE, "Error: Xcp_CmdGetDaqEventInfo event channel number out of range\n");
}
const Xcp_EventChannelType* eventChannel = xcpPtr->XcpEventChannel + eventChannelNumber;
uint8 namelen = 0;
if (eventChannel->XcpEventChannelName) {
namelen = strlen(eventChannel->XcpEventChannelName);
xcpPtr->XcpMtaInit(&Xcp_Mta, (uint32) eventChannel->XcpEventChannelName,XCP_MTA_EXTENSION_MEMORY_INTERNAL_FIXED);
}
FIFO_GET_WRITE(Xcp_FifoTxCto, e)
{
SET_UINT8(e->data, 0, XCP_PID_RES);
SET_UINT8(e->data, 1, (uint8)eventChannel->XcpEventChannelProperties);
SET_UINT8(e->data, 2, eventChannel->XcpEventChannelMaxDaqList);
SET_UINT8(e->data, 3, namelen); /* Name length */
SET_UINT8(e->data, 4, eventChannel->XcpEventChannelRate); /* Cycle time */
SET_UINT8(e->data, 5, (uint8)eventChannel->XcpEventChannelUnit); /* Time unit */
SET_UINT8(e->data, 6, eventChannel->XcpEventChannelPriority); /* Event channel priority */
e->len = 7;
}
return E_OK ;
}
#if(XCP_DAQ_CONFIG_TYPE == DAQ_DYNAMIC)
static Std_ReturnType Xcp_CmdFreeDaq(uint8 pid, uint8* data, PduLengthType len) {
DEBUG(DEBUG_HIGH, "Received FreeDaq\n");
XCP_UNUSED(pid);
XCP_UNUSED(data);/*lint !e920 Misra 2012 1.3 cast from pointer to void */
XCP_UNUSED(len);
Xcp_Fifo_Lock();
// free daqs from tx list
Xcp_DaqListType **Xcp_DaqTxListPtr = &Xcp_DaqTxList;
Xcp_DaqTxListLast = 0;
while(*Xcp_DaqTxListPtr != 0) {
if(*Xcp_DaqTxListPtr - xcpPtr->XcpDaqList >= XCP_MIN_DAQ) {
// this is a dynamic daq, free it
*Xcp_DaqTxListPtr = (*Xcp_DaqTxListPtr)->TxDaqListNext;
} else {
Xcp_DaqTxListLast = *Xcp_DaqTxListPtr;
Xcp_DaqTxListPtr = &(*Xcp_DaqTxListPtr)->TxDaqListNext;
}
}
// free daqs from event lists
for(int event = 0; event < XCP_EVENT_COUNT; event++) {
if(XcpEventChannelTriggeredDaqListRef[event] != 0) {
Xcp_DaqListType *daqFirst = *XcpEventChannelTriggeredDaqListRef[event];
Xcp_DaqListType *daq = daqFirst->EventDaqListNext;
Xcp_DaqListType *daqNext;
do {
daqNext = daq->EventDaqListNext;
if(daqNext - xcpPtr->XcpDaqList >= XCP_MIN_DAQ) {
daq->EventDaqListNext = daqNext->EventDaqListNext;
} else {
daq = daqNext;
}
}while(daqFirst != daqNext);
if(daq - xcpPtr->XcpDaqList >= XCP_MIN_DAQ) {
// list is empty, clear ptr
XcpEventChannelTriggeredDaqListRef[event] = 0;
} else {
XcpEventChannelTriggeredDaqListRef[event] = &daq->EventDaqListNext;
}
}
}
Xcp_Fifo_Unlock();
/* we now only have minimum number of daq lists */
xcpPtr->rt->XcpMaxDaq = XCP_MIN_DAQ;
xcpPtr->rt->XcpNumDynWordsAllocated = 0;
Xcp_DaqState.dyn = XCP_DYNAMIC_STATE_FREE_DAQ;
RETURN_SUCCESS();
}
static uint8* Xcp_AllocDyn(uint32 bytes) {
uint8* retPtr;
uint32 numToAllocate = (bytes + 3) / 4;
if(xcpPtr->dynamicRamBufferSize < xcpPtr->rt->XcpNumDynWordsAllocated + numToAllocate) {
retPtr = NULL;
} else {
retPtr = (uint8*)&xcpPtr->ptrDynamicRamBuffer[xcpPtr->rt->XcpNumDynWordsAllocated];
xcpPtr->rt->XcpNumDynWordsAllocated += numToAllocate;
memset(retPtr, 0, numToAllocate * 4);
}
return retPtr;
}
static Std_ReturnType Xcp_CmdAllocDaq(uint8 pid, uint8* data, PduLengthType len) {
DEBUG(DEBUG_HIGH, "Received AllocDaq\n");
XCP_UNUSED(pid);
XCP_UNUSED(len);
if (!(Xcp_DaqState.dyn == XCP_DYNAMIC_STATE_FREE_DAQ)) {
Xcp_DaqState.dyn = XCP_DYNAMIC_STATE_UNDEFINED;
RETURN_ERROR(XCP_ERR_SEQUENCE, " ");
}
uint16 nrDaqs = GET_UINT16(data, 1);
Xcp_DaqListType *daqDyn = (Xcp_DaqListType*) Xcp_AllocDyn(sizeof(Xcp_DaqListType)*nrDaqs);
if (daqDyn == NULL) {
RETURN_ERROR(XCP_ERR_MEMORY_OVERFLOW, "Error, memory overflow");
}
for (uint16 daqNr = 0; daqNr < nrDaqs; daqNr++) {
Xcp_DaqListType* daq = daqDyn + daqNr;
daq->EventChannel = 0xFFFF;
}
/*lint -e{920} Do not take care of return value.*/
xcpPtr->rt->XcpMaxDaq = XCP_MIN_DAQ + nrDaqs;
Xcp_DaqState.dyn = XCP_DYNAMIC_STATE_ALLOC_DAQ;
RETURN_SUCCESS();
}
static Std_ReturnType Xcp_CmdAllocOdt(uint8 pid, uint8* data, PduLengthType len) {
DEBUG(DEBUG_HIGH, "Received AllocOdt\n");
XCP_UNUSED(pid);
XCP_UNUSED(len);
if (!(Xcp_DaqState.dyn == XCP_DYNAMIC_STATE_ALLOC_DAQ || Xcp_DaqState.dyn == XCP_DYNAMIC_STATE_ALLOC_ODT)) {
Xcp_DaqState.dyn = XCP_DYNAMIC_STATE_UNDEFINED;
RETURN_ERROR(XCP_ERR_SEQUENCE, " ");
}
Xcp_DaqState.dyn = XCP_DYNAMIC_STATE_ALLOC_ODT;
uint16 daqNr = GET_UINT16(data, 1);
uint8 nrOdts = GET_UINT8(data, 3);
if (daqNr >= xcpPtr->rt->XcpMaxDaq) {
RETURN_ERROR(XCP_ERR_OUT_OF_RANGE, "Requested allocation to predefined daq list %u", daqNr);
}
#if (XCP_MIN_DAQ > 0)
if (daqNr < XCP_MIN_DAQ) {
RETURN_ERROR(XCP_ERR_OUT_OF_RANGE, "Requested allocation to predefined daq list %u", daqNr);
}
#endif /* XCP_MIN_DAQ > 0 */
Xcp_DaqListType* daq = xcpPtr->XcpDaqList + daqNr;
if(daq->XcpOdt) {
Xcp_DaqState.dyn = XCP_DYNAMIC_STATE_UNDEFINED;
RETURN_ERROR(XCP_ERR_SEQUENCE, " ");
}
daq->XcpOdt = (Xcp_OdtType *)Xcp_AllocDyn(sizeof(daq->XcpOdt[0])*nrOdts);
if (daq->XcpOdt == NULL) {
RETURN_ERROR(XCP_ERR_MEMORY_OVERFLOW, "Error, memory overflow");
}
daq->XcpMaxOdt = nrOdts;
RETURN_SUCCESS();
}
static Std_ReturnType Xcp_CmdAllocOdtEntry(uint8 pid, uint8* data, PduLengthType len)
{
DEBUG(DEBUG_HIGH, "Received AllocOdtEntry\n");
XCP_UNUSED(pid);
XCP_UNUSED(len);
if (!(Xcp_DaqState.dyn == XCP_DYNAMIC_STATE_ALLOC_ODT || Xcp_DaqState.dyn == XCP_DYNAMIC_STATE_ALLOC_ODT_ENTRY)) {
Xcp_DaqState.dyn = XCP_DYNAMIC_STATE_UNDEFINED;
RETURN_ERROR(XCP_ERR_SEQUENCE, " ");
}
Xcp_DaqState.dyn = XCP_DYNAMIC_STATE_ALLOC_ODT_ENTRY;
uint16 daqNr = GET_UINT16(data, 1);
uint8 odtNr = GET_UINT8(data, 3);
uint8 odtEntriesCount = GET_UINT8(data, 4);
if (daqNr >= xcpPtr->rt->XcpMaxDaq) {
RETURN_ERROR(XCP_ERR_OUT_OF_RANGE, "Requested allocation to predefined daq list %u", daqNr);
}
#if (XCP_MIN_DAQ > 0)
if (daqNr < XCP_MIN_DAQ) {
RETURN_ERROR(XCP_ERR_OUT_OF_RANGE, "Requested allocation to predefined daq list %u", daqNr);
}
#endif /* XCP_MIN_DAQ > 0 */
Xcp_DaqListType* daq = xcpPtr->XcpDaqList + daqNr;
if (odtNr >= daq->XcpMaxOdt) {
RETURN_ERROR(XCP_ERR_OUT_OF_RANGE, "Requested allocation to invalid odt for daq %u, odt %u", daqNr, odtNr);
}
Xcp_OdtType* odt = daq->XcpOdt + odtNr;
if(odt->XcpOdtEntry) {
Xcp_DaqState.dyn = XCP_DYNAMIC_STATE_UNDEFINED;
RETURN_ERROR(XCP_ERR_SEQUENCE, " ");
}
odt->XcpOdtEntry = (Xcp_OdtEntryType *)Xcp_AllocDyn(sizeof(odt->XcpOdtEntry[0])*odtEntriesCount);
if (odt->XcpOdtEntry == NULL) {
RETURN_ERROR(XCP_ERR_MEMORY_OVERFLOW, "Error, memory overflow");
}
odt->XcpOdtEntriesCount = odtEntriesCount;
RETURN_SUCCESS();
}
#endif
/**************************************************************************/
/**************************************************************************/
/****************************** SEED & KEY ********************************/
/**************************************************************************/
/**************************************************************************/
#if(XCP_FEATURE_PROTECTION == STD_ON)
static Std_ReturnType Xcp_CmdGetSeed(uint8 pid, uint8* data, PduLengthType len)
{
uint8 mode = GET_UINT8(data, 0);
uint8 res = GET_UINT8(data, 1);
DEBUG(DEBUG_HIGH, "Received GetSeed(%u, %u)\n", mode, res);
XCP_UNUSED(pid);
XCP_UNUSED(len);
if(mode == 0) {
if( res != XCP_PROTECT_CALPAG
&& res != XCP_PROTECT_DAQ
&& res != XCP_PROTECT_STIM
&& res != XCP_PROTECT_PGM) {
RETURN_ERROR(XCP_ERR_OUT_OF_RANGE, "Requested invalid resource");
}
Xcp_Unlock.res = (Xcp_ProtectType)res;
Xcp_Unlock.key_len = 0;
Xcp_Unlock.key_rem = 0;
Xcp_Unlock.seed_len = xcpPtr->XcpSeedFn((Xcp_ProtectType)res, Xcp_Unlock.seed);
Xcp_Unlock.seed_rem = Xcp_Unlock.seed_len;
} else if(mode == 1) {
if(Xcp_Unlock.res == XCP_PROTECT_NONE) {
RETURN_ERROR(XCP_ERR_SEQUENCE, "Requested second part of seed before first");
}
} else {
RETURN_ERROR(XCP_ERR_GENERIC, "Requested invalid mode");
}
uint8 rem;
if(Xcp_Unlock.seed_rem > XCP_MAX_CTO - 2) {
rem = XCP_MAX_CTO - 2;
} else {
rem = Xcp_Unlock.seed_rem;
}
FIFO_GET_WRITE(Xcp_FifoTxCto, e) {
FIFO_ADD_U8(e, XCP_PID_RES);
FIFO_ADD_U8(e, Xcp_Unlock.seed_rem);
Xcp_MemCpy( e->data+e->len
, Xcp_Unlock.seed + Xcp_Unlock.seed_len - Xcp_Unlock.seed_rem
, rem);
e->len += rem;
Xcp_Unlock.seed_rem -= rem;
}
return E_OK;
}
static Std_ReturnType Xcp_CmdUnlock(uint8 pid, uint8* data, PduLengthType len)
{
uint8 rem = GET_UINT8(data, 0);
DEBUG(DEBUG_HIGH, "Received Unlock(%u)\n", rem);
XCP_UNUSED(pid);
if(Xcp_Unlock.res == XCP_PROTECT_NONE) {
RETURN_ERROR(XCP_ERR_SEQUENCE, "Requested unlock without requesting a seed");
}
/* if this is first call, setup state */
if(Xcp_Unlock.key_len == 0) {
Xcp_Unlock.key_len = rem;
Xcp_Unlock.key_rem = rem;
}
/* validate that we are in correct sync */
if(Xcp_Unlock.key_rem != rem) {
FIFO_GET_WRITE(Xcp_FifoTxCto, e) {
FIFO_ADD_U8 (e, (uint8)XCP_PID_ERR);
FIFO_ADD_U8 (e, (uint8)XCP_ERR_SEQUENCE);
FIFO_ADD_U8 (e, Xcp_Unlock.key_rem);
}
return E_OK; /*lint !e904 allow multiple exit */
}
if(rem > len - 1)
rem = len - 1;
Xcp_MemCpy( Xcp_Unlock.key + Xcp_Unlock.key_len - Xcp_Unlock.key_rem
, (uint8 *)data+1
, rem);
Xcp_Unlock.key_rem -= rem;
if(Xcp_Unlock.key_rem == 0) {
if(xcpPtr->XcpUnlockFn == NULL) {
RETURN_ERROR(XCP_ERR_GENERIC, "No unlock function defines");
}
if(xcpPtr->XcpUnlockFn( Xcp_Unlock.res
, Xcp_Unlock.seed
, Xcp_Unlock.seed_len
, Xcp_Unlock.key
, Xcp_Unlock.key_len) == E_OK) {
xcpPtr->rt->XcpProtect &= ~Xcp_Unlock.res;
} else {
RETURN_ERROR(XCP_ERR_ACCESS_LOCKED, "Failed to unlock resource");
}
}
RETURN_SUCCESS();
}
#endif
/**************************************************************************/
/**************************************************************************/
/*************************** COMMAND PROCESSOR ****************************/
/**************************************************************************/
/**************************************************************************/
/**
* Structure holding a map between command codes and the function
* implementing the command
*/
static const Xcp_CmdListType Xcp_CmdList[256-XCP_PID_CMD_STIM_LAST] =
{ [-XCP_PID_CMD_STIM_LAST+XCP_PID_CMD_STD_CONNECT] = {.fun = Xcp_CmdConnect, .len = 1 },
[-XCP_PID_CMD_STIM_LAST+XCP_PID_CMD_STD_DISCONNECT] = {.fun = Xcp_CmdDisconnect, .len = 0 },
[-XCP_PID_CMD_STIM_LAST+XCP_PID_CMD_STD_GET_STATUS] = {.fun = Xcp_CmdGetStatus, .len = 0 },
[-XCP_PID_CMD_STIM_LAST+XCP_PID_CMD_STD_GET_ID] = {.fun = Xcp_CmdGetId, .len = 1 },
[-XCP_PID_CMD_STIM_LAST+XCP_PID_CMD_STD_UPLOAD] = {.fun = Xcp_CmdUpload, .len = 1 },
[-XCP_PID_CMD_STIM_LAST+XCP_PID_CMD_STD_SHORT_UPLOAD] = {.fun = Xcp_CmdShortUpload, .len = 8 },
[-XCP_PID_CMD_STIM_LAST+XCP_PID_CMD_STD_SET_MTA] = {.fun = Xcp_CmdSetMTA, .len = 3 },
[-XCP_PID_CMD_STIM_LAST+XCP_PID_CMD_STD_SYNCH] = {.fun = Xcp_CmdSync, .len = 0 },
[-XCP_PID_CMD_STIM_LAST+XCP_PID_CMD_STD_GET_COMM_MODE_INFO] = {.fun = Xcp_CmdGetCommModeInfo, .len = 0 },
[-XCP_PID_CMD_STIM_LAST+XCP_PID_CMD_STD_BUILD_CHECKSUM] = {.fun = Xcp_CmdBuildChecksum, .len = 8 },
[-XCP_PID_CMD_STIM_LAST+XCP_PID_CMD_STD_TRANSPORT_LAYER_CMD] = {.fun = Xcp_CmdTransportLayer, .len = 1 },
[-XCP_PID_CMD_STIM_LAST+XCP_PID_CMD_STD_USER_CMD] = {.fun = Xcp_CmdUser, .len = 0 },
#if(XCP_FEATURE_PROTECTION == STD_ON)
/** @req 4.1.3/SWS_Xcp_00766 *//*The AUTOSAR XCP Module shall support the feature Seed & Key*/
[-XCP_PID_CMD_STIM_LAST+XCP_PID_CMD_STD_GET_SEED] = {.fun = Xcp_CmdGetSeed, .len = 0},
[-XCP_PID_CMD_STIM_LAST+XCP_PID_CMD_STD_UNLOCK] = {.fun = Xcp_CmdUnlock, .len = 3},
#endif
#if(XCP_FEATURE_PGM == STD_ON)
[-XCP_PID_CMD_STIM_LAST+XCP_PID_CMD_PGM_PROGRAM_START] = {.fun = Xcp_CmdProgramStart, .len = 0, .lock = XCP_PROTECT_PGM},
[-XCP_PID_CMD_STIM_LAST+XCP_PID_CMD_PGM_PROGRAM_CLEAR] = {.fun = Xcp_CmdProgramClear, .len = 7, .lock = XCP_PROTECT_PGM},
[-XCP_PID_CMD_STIM_LAST+XCP_PID_CMD_PGM_PROGRAM] = {.fun = Xcp_CmdProgram, .len = 2, .lock = XCP_PROTECT_PGM},
#if (XCP_FEATURE_BLOCKMODE == STD_ON)
[-XCP_PID_CMD_STIM_LAST+XCP_PID_CMD_PGM_PROGRAM_NEXT] = {.fun = Xcp_CmdProgram, .len = 2, .lock = XCP_PROTECT_PGM},
#endif /* XCP_FEATURE_BLOCKMODE == STD_ON */
[-XCP_PID_CMD_STIM_LAST+XCP_PID_CMD_PGM_PROGRAM_RESET] = {.fun = Xcp_CmdProgramReset, .len = 0, .lock = XCP_PROTECT_PGM},
[-XCP_PID_CMD_STIM_LAST+XCP_PID_CMD_PGM_GET_PGM_PROCESSOR_INFO] = {.fun = Xcp_CmdGetPgmProcessorInfo, .len = 0, .lock = XCP_PROTECT_PGM},
[-XCP_PID_CMD_STIM_LAST+XCP_PID_CMD_PGM_GET_SECTOR_INFO] = {.fun = Xcp_CmdGetSectorInfo, .len = 2, .lock = XCP_PROTECT_PGM},
[-XCP_PID_CMD_STIM_LAST+XCP_PID_CMD_PGM_PROGRAM_PREPARE] = {.fun = Xcp_CmdProgramPrepare, .len = 3, .lock = XCP_PROTECT_PGM},
[-XCP_PID_CMD_STIM_LAST+XCP_PID_CMD_PGM_PROGRAM_FORMAT] = {.fun = Xcp_CmdProgramFormat, .len = 4, .lock = XCP_PROTECT_PGM},
[-XCP_PID_CMD_STIM_LAST+XCP_PID_CMD_PGM_PROGRAM_VERIFY] = {.fun = Xcp_CmdProgramVerify, .len = 7, .lock = XCP_PROTECT_PGM},
#endif /* XCP_FEATURE_PGM == STD_ON */
#if(XCP_FEATURE_CALPAG == STD_ON)
/** @req 4.1.3/SWS_Xcp_00708 *//*The AUTOSAR XCP Module shall support Online memory calibration (read / write access).*/
[-XCP_PID_CMD_STIM_LAST+XCP_PID_CMD_PAG_SET_CAL_PAGE] = {.fun = Xcp_CmdSetCalPage , .len = 3, .lock = XCP_PROTECT_CALPAG},
[-XCP_PID_CMD_STIM_LAST+XCP_PID_CMD_PAG_GET_CAL_PAGE] = {.fun = Xcp_CmdGetCalPage , .len = 2, .lock = XCP_PROTECT_CALPAG},
[-XCP_PID_CMD_STIM_LAST+XCP_PID_CMD_PAG_GET_PAG_PROCESSOR_INFO] = {.fun = Xcp_CmdGetPagProcessorInfo , .len = 0, .lock = XCP_PROTECT_CALPAG},
[-XCP_PID_CMD_STIM_LAST+XCP_PID_CMD_PAG_GET_SEGMENT_INFO] = {.fun = Xcp_CmdGetSegmentInfo , .len = 3, .lock = XCP_PROTECT_CALPAG},
[-XCP_PID_CMD_STIM_LAST+XCP_PID_CMD_PAG_GET_PAGE_INFO] = {.fun = Xcp_CmdGetPageInfo , .len = 3, .lock = XCP_PROTECT_CALPAG},
[-XCP_PID_CMD_STIM_LAST+XCP_PID_CMD_PAG_SET_SEGMENT_MODE] = {.fun = Xcp_CmdSetSegmentMode , .len = 2, .lock = XCP_PROTECT_CALPAG},
[-XCP_PID_CMD_STIM_LAST+XCP_PID_CMD_PAG_GET_SEGMENT_MODE] = {.fun = Xcp_CmdGetSegmentMode , .len = 2, .lock = XCP_PROTECT_CALPAG},
[-XCP_PID_CMD_STIM_LAST+XCP_PID_CMD_PAG_COPY_CAL_PAGE] = {.fun = Xcp_CmdCopyCalPage , .len = 4, .lock = XCP_PROTECT_CALPAG},
#endif /* XCP_FEATURE_CALPAG == STD_ON */
/** @req 4.1.3/SWS_Xcp_00708 *//*The AUTOSAR XCP Module shall support Online memory calibration (read / write access).*/
[-XCP_PID_CMD_STIM_LAST+XCP_PID_CMD_CAL_DOWNLOAD] = { .fun = Xcp_CmdDownload, .len = 3, .lock = XCP_PROTECT_CALPAG },
#if(XCP_FEATURE_BLOCKMODE == STD_ON)
/** @req 4.1.3/SWS_Xcp_00711 *//*The AUTOSAR XCP Module shall support the feature Block communication mode*/
[-XCP_PID_CMD_STIM_LAST+XCP_PID_CMD_CAL_DOWNLOAD_NEXT] = { .fun = Xcp_CmdDownload, .len = 3, .lock = XCP_PROTECT_CALPAG },
#endif
[-XCP_PID_CMD_STIM_LAST+XCP_PID_CMD_DAQ_CLEAR_DAQ_LIST] = { .fun = Xcp_CmdClearDaqList, .len = 3, .lock = XCP_PROTECT_DAQ },
[-XCP_PID_CMD_STIM_LAST+XCP_PID_CMD_DAQ_SET_DAQ_PTR] = { .fun = Xcp_CmdSetDaqPtr, .len = 5, .lock = XCP_PROTECT_DAQ },
[-XCP_PID_CMD_STIM_LAST+XCP_PID_CMD_DAQ_WRITE_DAQ] = { .fun = Xcp_CmdWriteDaq, .len = 7, .lock = XCP_PROTECT_DAQ },
[-XCP_PID_CMD_STIM_LAST+XCP_PID_CMD_DAQ_SET_DAQ_LIST_MODE] = { .fun = Xcp_CmdSetDaqListMode, .len = 7, .lock = XCP_PROTECT_DAQ },
[-XCP_PID_CMD_STIM_LAST+XCP_PID_CMD_DAQ_GET_DAQ_LIST_MODE ] = { .fun = Xcp_CmdGetDaqListMode, .len = 3, .lock = XCP_PROTECT_DAQ },
[-XCP_PID_CMD_STIM_LAST+XCP_PID_CMD_DAQ_START_STOP_DAQ_LIST] = { .fun = Xcp_CmdStartStopDaqList, .len = 3, .lock = XCP_PROTECT_DAQ },
[-XCP_PID_CMD_STIM_LAST+XCP_PID_CMD_DAQ_START_STOP_SYNCH] = { .fun = Xcp_CmdStartStopSynch, .len = 1, .lock = XCP_PROTECT_DAQ },
[-XCP_PID_CMD_STIM_LAST+XCP_PID_CMD_DAQ_GET_DAQ_CLOCK] = { .fun = Xcp_CmdGetDaqClock, .len = 0, .lock = XCP_PROTECT_DAQ },
[-XCP_PID_CMD_STIM_LAST+XCP_PID_CMD_DAQ_READ_DAQ] = { .fun = Xcp_CmdReadDaq, .len = 0, .lock = XCP_PROTECT_DAQ },
[-XCP_PID_CMD_STIM_LAST+XCP_PID_CMD_DAQ_GET_DAQ_PROCESSOR_INFO] = { .fun = Xcp_CmdGetDaqProcessorInfo, .len = 0, .lock = XCP_PROTECT_DAQ },
[-XCP_PID_CMD_STIM_LAST+XCP_PID_CMD_DAQ_GET_DAQ_RESOLUTION_INFO] = { .fun = Xcp_CmdGetDaqResolutionInfo, .len = 0, .lock = XCP_PROTECT_DAQ },
[-XCP_PID_CMD_STIM_LAST+XCP_PID_CMD_DAQ_GET_DAQ_LIST_INFO] = { .fun = Xcp_CmdGetDaqListInfo, .len = 3, .lock = XCP_PROTECT_DAQ },
[-XCP_PID_CMD_STIM_LAST+XCP_PID_CMD_DAQ_GET_DAQ_EVENT_INFO] = { .fun = Xcp_CmdGetDaqEventInfo, .len = 3, .lock = XCP_PROTECT_DAQ },
#if(XCP_DAQ_CONFIG_TYPE == DAQ_DYNAMIC)
/** @req 4.1.3/SWS_Xcp_00706 *//*The AUTOSAR XCP Module shall support Dynamic DAQ Configuration.*/
[-XCP_PID_CMD_STIM_LAST+XCP_PID_CMD_DAQ_FREE_DAQ] = { .fun = Xcp_CmdFreeDaq, .len = 0, .lock = XCP_PROTECT_DAQ },
[-XCP_PID_CMD_STIM_LAST+XCP_PID_CMD_DAQ_ALLOC_DAQ] = { .fun = Xcp_CmdAllocDaq, .len = 3, .lock = XCP_PROTECT_DAQ },
[-XCP_PID_CMD_STIM_LAST+XCP_PID_CMD_DAQ_ALLOC_ODT] = { .fun = Xcp_CmdAllocOdt, .len = 4, .lock = XCP_PROTECT_DAQ },
[-XCP_PID_CMD_STIM_LAST+XCP_PID_CMD_DAQ_ALLOC_ODT_ENTRY] = { .fun = Xcp_CmdAllocOdtEntry, .len = 5, .lock = XCP_PROTECT_DAQ }
#endif
};
/**
* Xcp_Recieve_Main is the main process that executes all received commands.
*
* The function queues up replies for transmission. Which will be sent
* when Xcp_Transmit_Main function is called.
*/
static void Xcp_Recieve_Main(void) {
FIFO_FOR_READ(Xcp_FifoRxCto, it) {
uint8 pid = GET_UINT8(it->data, 0);
/* ignore commands when we are not connected */
if (!Xcp_Connected && pid != XCP_PID_CMD_STD_CONNECT && pid != XCP_PID_CMD_STD_TRANSPORT_LAYER_CMD) {
continue;
}
/* process standard commands */
const Xcp_CmdListType* cmd = Xcp_CmdList + (pid - XCP_PID_CMD_STIM_LAST);
if (pid > XCP_PID_CMD_STIM_LAST && cmd->fun) {
#if(XCP_FEATURE_PROTECTION == STD_ON)
if(cmd->lock & xcpPtr->rt->XcpProtect) {
Xcp_TxError(XCP_ERR_ACCESS_LOCKED);
continue;
}
#endif /*XCP_FEATURE_PROTECTION == STD_ON*/
if (cmd->len && it->len < cmd->len) {
DEBUG(DEBUG_HIGH, "Xcp_RxIndication_Main - Len %d to short for %u\n", it->len, pid);
return; /*lint !e904 allow multiple exit */
}
(void) cmd->fun(pid, it->data + 1, it->len - 1);
} else {
Xcp_TxError(XCP_ERR_CMD_UNKNOWN);
}
}
}
/**
* Xcp_TxConfirmation function is responsible to initiate a new message sending.
* Xcp communication layer (XcpOnCan or XcpOnEth) store that message and handles
* the sending to the communication channel and wait for the confirmation.
*/
void Xcp_TxConfirmation(void) {
Xcp_BufferType* it;
Std_ReturnType retVal;
if (NULL != (it = Xcp_Fifo_Get(&Xcp_FifoTxCto))) {
Xcp_TxOngoing = 3;
retVal = Xcp_Transmit(it->data, it->len);
Xcp_Fifo_Free(&Xcp_FifoTxCto, it);
if (E_OK != retVal) {
Xcp_TxOngoing = 0;
DEBUG(DEBUG_HIGH, "Xcp_Transmit_Main - failed to transmit\n");
}
} else if (Xcp_DaqTxList) {
Xcp_TxOngoing = 3;
Xcp_ProcessDaq_DAQ(Xcp_DaqTxList);
} else {
Xcp_TxOngoing = 0;
}
}
/**
* Scheduled function of the event channel
* @param channel
*/
void Xcp_MainFunction_Channel(uint32 channel) {
if(!Xcp_Inited)
{
DET_REPORTERROR(XCP_API_ID_XCP_MAINFUNCTION,XCP_E_NOT_INITIALIZED);
return; /*lint !e904 allow multiple exit */
}
else
{
DET_VALIDATE_NRV(channel < XCP_EVENT_COUNT, XCP_API_ID_XCP_MAINFUNCTION, XCP_E_INVALID_EVENT);
Xcp_ProcessChannel(channel);
}
}
/**
* Scheduled function of the XCP module
*
* ServiceId: 0x04
*
*/
/** @req 4.1.3/SWS_Xcp_00823 *//*Xcp_MainFunction API definition*/
/** @req 4.1.3/SWS_Xcp_00824 *//*Xcp_MainFunction shall be called cyclically - can not be tested with conventional module tests*/
void Xcp_MainFunction(void) {
DET_VALIDATE_NRV(Xcp_Inited, XCP_API_ID_XCP_MAINFUNCTION, XCP_E_NOT_INITIALIZED);
/* check if we have some queued worker */
if (Xcp_Worker) {
Xcp_Worker();
} else {
Xcp_Recieve_Main();
}
Xcp_Fifo_Lock();
if(!Xcp_TxOngoing && Xcp_FifoTxCto.front) { // this is an uggly fix to ensure that command responses are sent, move to commands instead
Xcp_Fifo_Unlock();
Xcp_TxConfirmation();
} else {
if(Xcp_TxOngoing){
Xcp_TxOngoing--;
if(Xcp_TxOngoing == 0) {
#if (XCP_PROTOCOL == XCP_PROTOCOL_CAN)
Xcp_CancelTxRequests();
#endif
}
}
Xcp_Fifo_Unlock();
}
}
|
2301_81045437/classic-platform
|
communication/Xcp/src/Xcp.c
|
C
|
unknown
| 65,792
|
/*-------------------------------- Arctic Core ------------------------------
* Copyright (C) 2013, ArcCore AB, Sweden, www.arccore.com.
* Contact: <contact@arccore.com>
*
* You may ONLY use this file:
* 1)if you have a valid commercial ArcCore license and then in accordance with
* the terms contained in the written license agreement between you and ArcCore,
* or alternatively
* 2)if you follow the terms found in GNU General Public License version 2 as
* published by the Free Software Foundation and appearing in the file
* LICENSE.GPL included in the packaging of this file or here
* <http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt>
*-------------------------------- Arctic Core -----------------------------*/
/** @reqSettings DEFAULT_SPECIFICATION_REVISION=4.1.3 */
/** @req 4.1.3/SWS_Xcp_00713 *//*Support Can communication*/
/** @req 4.1.3/SWS_Xcp_00714 *//*Use API provided for CanIf*/
/** @req 4.1.3/SWS_Xcp_00716 *//*Performance information must be exchanged between Slave and Master*/
/** @req 4.1.3/SWS_Xcp_00718 *//*Support GET_SLAVE_ID command*/
/** @req 4.1.3/SWS_Xcp_00715 *//*2 can Pdu needed*/
#include "Xcp_Internal.h"
#if (XCP_PROTOCOL == XCP_PROTOCOL_CAN)
#include "XcpOnCan_Cfg.h"
#include "CanIf.h"
typedef enum {
XCP_CAN_CMD_SET_DAQ_ID = 0xFD,
XCP_CAN_CMD_GET_DAQ_ID = 0xFE,
XCP_CAN_CMD_GET_SLAVE_ID = 0xFF,
} Xcp_CanCmdType;
/**
* This function is responsible to find an unused buffer/Pdu
* @param idxPtr
* @param pduIdPtr
* @return FALSE: There is no such Pdu
* TRUE: Empty buffer/Pdu has been found
*/
static boolean Xcp_FindFreeChannel(uint8* idxPtr, PduIdType* pduIdPtr)
{
uint8 idx;
for (idx = 0; idx < XCP_TX_CH_NUMBER; idx++) {
if ( (XCP_TX_CH_EMPTY == xcpPtr->XcpTxCh[idx].state) &&
(TRUE == xcpPtr->XcpTransmitPduAllowed(xcpPtr->XcpTxCh[idx].pduId)) ) {
*idxPtr = idx;
*pduIdPtr = xcpPtr->XcpTxCh[idx].pduId;
return TRUE;
}
}
return FALSE;
}
/**
* This function reserves buffer/Pdu which was found by Xcp_FindFreeChannel
* previously
* @param idxPtr
* @param pduIdPtr
* @return FALSE: There is no such Pdu
* TRUE: buffer/Pdu has been reserved
*/
static boolean Xcp_ReserveChannel(uint8* idxPtr, PduIdType* pduIdPtr)
{
if (Xcp_FindFreeChannel(idxPtr,pduIdPtr)) {
xcpPtr->XcpTxCh[*idxPtr].state = XCP_TX_CH_RESERVED;
return TRUE;
}
return FALSE;
}
/**
* This function frees up the previously reserves buffer/Pdu
* @param idx
*/
static void Xcp_FreeUpChannel(uint8 idx)
{
xcpPtr->XcpTxCh[idx].state = XCP_TX_CH_EMPTY;
xcpPtr->XcpTxCh[idx].len = 0;
}
void Xcp_CancelTxRequests() {
Xcp_CanLayerInit();
}
/**
* This function initializes the communication specific Xcp layer
*/
void Xcp_CanLayerInit(void)
{
for (uint8 idx = 0; idx < XCP_TX_CH_NUMBER; idx++) {
Xcp_FreeUpChannel(idx);
}
}
/**
* Transport protocol agnostic transmit function called by Xcp core system
*
* @param data
* @param len
* @return
* @info This function is designed to be reentrant, thus
* it works on static data with exclusive area protection.
*/
Std_ReturnType Xcp_Transmit(const uint8* data, PduLengthType len)
{
Std_ReturnType retVal = E_NOT_OK;
PduIdType pduId, pduId2;
PduInfoType pdu;
uint8 idx, idx2;
boolean freeChFound = FALSE;
/*-------------------------------------------*/
SchM_Enter_Xcp_EA_0(); /*Enter exclusive area*/
/*-------------------------------------------*/
freeChFound = Xcp_ReserveChannel(&idx, &pduId);
/*-------------------------------------------*/
SchM_Exit_Xcp_EA_0(); /*Exit exclusive area*/
/*-------------------------------------------*/
if (TRUE == freeChFound) {
//Free slot has been found, copy and try to send
Xcp_MemCpy(xcpPtr->XcpTxCh[idx].data, data, len);
xcpPtr->XcpTxCh[idx].len = len;
pdu.SduDataPtr = (uint8 *)xcpPtr->XcpTxCh[idx].data;
pdu.SduLength = xcpPtr->XcpTxCh[idx].len;
retVal = CanIf_Transmit(pduId, &pdu);
if (E_OK == retVal) {
//If there is free channel, available, indicate the next message handling
if (Xcp_FindFreeChannel(&idx2, &pduId2)) {
Xcp_TxConfirmation();
}
} else {
//Report to Det that the message is lost
DET_REPORTERROR(XCP_API_ID_XCP_TRANSMIT,XCP_E_MESSAGE_LOST);
//Channel with certain pdu is not available
Xcp_FreeUpChannel(idx);
}
}
return retVal;
}
/**
* Callback for finished transmit of PDU
*
* This function is called by the lower layers (i.e. FlexRay Interface, TTCAN Interface
* and Socket Adaptor or CDD) when an AUTOSAR XCP PDU has been transmitted
*
* Reentrant for different XcpTxPduIds, non reentrant for the same XcpTxPduId
*
* ServiceId: 0x02
*
* @param XcpRxPduId PDU-ID that has been transmitted
*/
/** @req 4.1.3/SWS_Xcp_00814 *//*Xcp_<module>TxConfirmation API definition*/
/** @req 4.1.3/SWS_Xcp_00840 *//*Send DET if the function Xcp_<module>TxConfirmation is called before the XCP was initialized successfully.*/
/** @req 4.1.3/SWS_Xcp_00841 *//*The call context is either on interrupt level (interrupt mode) or on task level, The Xcp module is initialized correctly. - can not be tested with conventional module tests*/
void Xcp_CanIfTxConfirmation(PduIdType XcpTxPduId)
{
DET_VALIDATE_NRV(Xcp_Inited,
XCP_API_ID_XCP_TX_CONFIRMATION,
XCP_E_NOT_INITIALIZED);
DET_VALIDATE_NRV(XcpTxPduId < XCP_TX_CH_NUMBER,
XCP_API_ID_XCP_TX_CONFIRMATION,
XCP_E_INVALID_PDUID);
//XcpTxPduId is expected to be configured starting from 0 in a consecutive order
Xcp_FreeUpChannel((uint8)XcpTxPduId);
Xcp_TxConfirmation();
}
/**
* Receive callback from CAN network layer
*
* This function is called by the lower layers (i.e. FlexRay Interface, TTCAN Interface
* and Socket Adaptor or CDD) when an AUTOSAR XCP PDU has been received
*
* Reentrant for different XcpRxPduIds,
* non reentrant for the same XcpRxPduId
*
* The function Xcp_<module>RxIndication might be called
* by the Xcp module�s environment in an interrupt context
*
* ServiceId: 0x03
*
* @param XcpRxPduId PDU-ID that has been received
* @param XcpRxPduPtr Pointer to SDU (Buffer of received payload)
*/
/** @req 4.1.3/SWS_Xcp_00813 *//*Xcp_<module>RxIndication API definition*/
/** @req 4.1.3/SWS_Xcp_00847 *//*Send DET if Xcp was not initialized, XcpRxPduPtr equals NULL_PTR, Invalid PDUID*/
void Xcp_CanIfRxIndication(PduIdType XcpRxPduId, PduInfoType* XcpRxPduPtr)
{
DET_VALIDATE_NRV(Xcp_Inited, XCP_API_ID_XCP_RX_INDICATION, XCP_E_NOT_INITIALIZED);
DET_VALIDATE_NRV(XcpRxPduPtr, XCP_API_ID_XCP_RX_INDICATION, XCP_E_INV_POINTER);
#if (XCP_FEATURE_GET_SLAVE_ID == STD_ON)
DET_VALIDATE_NRV((XcpRxPduId < XCP_RX_CH_NUMBER) ||
(XcpRxPduId == XCP_PDU_ID_BROADCAST),
XCP_API_ID_XCP_RX_INDICATION,
XCP_E_INVALID_PDUID);
#else
DET_VALIDATE_NRV(XcpRxPduId < XCP_RX_CH_NUMBER,
XCP_API_ID_XCP_RX_INDICATION,
XCP_E_INVALID_PDUID);
#endif
if (TRUE == xcpPtr->XcpRecievePduAllowed(XcpRxPduId, XcpRxPduPtr)) {
Xcp_RxIndication(XcpRxPduPtr->SduDataPtr, XcpRxPduPtr->SduLength);
}
}
/**
* Command that can be used for a master to discover
* all connected XCP slaves on a CAN bus
* @param data
* @param len
* @return
*/
#if(XCP_FEATURE_GET_SLAVE_ID == STD_ON)
static Std_ReturnType Xcp_CmdGetSlaveId(uint8* data, PduLengthType len)
{
uint8 p[4];
uint8 mode;
if(len < 4) {
RETURN_ERROR(XCP_ERR_CMD_SYNTAX, "Invalid length for get_slave_id %d", len);
}
p[0] = GET_UINT8(data, 0);
p[1] = GET_UINT8(data, 1);
p[2] = GET_UINT8(data, 2);
p[3] = 0;
mode = GET_UINT8(data, 3);
if(strcmp((char*)p, "XCP")) {
RETURN_ERROR(XCP_ERR_CMD_UNKNOWN, "Unknown get_id pattern %s", p);
}
if(mode == 0) {
FIFO_GET_WRITE(Xcp_FifoTxCto, e) {
FIFO_ADD_U8 (e, XCP_PID_RES);
FIFO_ADD_U8 (e, p[0]);
FIFO_ADD_U8 (e, p[1]);
FIFO_ADD_U8 (e, p[2]);
FIFO_ADD_U32(e, XCP_CAN_ID_RX);
}
} else if(mode == 1) {
FIFO_GET_WRITE(Xcp_FifoTxCto, e) {
FIFO_ADD_U8 (e, XCP_PID_RES);
FIFO_ADD_U8 (e, ~p[0]);
FIFO_ADD_U8 (e, ~p[1]);
FIFO_ADD_U8 (e, ~p[2]);
FIFO_ADD_U32(e, XCP_CAN_ID_RX);
}
} else {
RETURN_ERROR(XCP_ERR_CMD_UNKNOWN, "Invalid mode for get_slave_id: %u", mode);
}
return E_OK;
}
#endif /*XCP_FEATURE_GET_SLAVE_ID == STD_ON*/
/**
* Called when the core of xcp have received a transport layer command
* @param pid
* @param data
* @param len
* @return
*/
Std_ReturnType Xcp_CmdTransportLayer(uint8 pid, uint8* data, PduLengthType len)
{
#if(XCP_FEATURE_GET_SLAVE_ID == STD_ON)
Xcp_CanCmdType id = (Xcp_CanCmdType)GET_UINT8(data, 0);
XCP_UNUSED(pid);
if(id == XCP_CAN_CMD_GET_SLAVE_ID && len >= 2) {
return Xcp_CmdGetSlaveId((void*)((uint8*)data+1), len-1); /*lint !e904 allow multiple exit */
}
#else /*XCP_FEATURE_GET_SLAVE_ID == STD_ON*/
XCP_UNUSED(pid);
XCP_UNUSED(data); /*lint !e920 no issue this is dummy use */
XCP_UNUSED(len);
#endif
RETURN_ERROR(XCP_ERR_CMD_UNKNOWN, "Unknown transport cmd");
}
#endif /*XCP_PROTOCOL == XCP_PROTOCOL_CAN*/
|
2301_81045437/classic-platform
|
communication/Xcp/src/XcpOnCan.c
|
C
|
unknown
| 9,915
|
/*-------------------------------- Arctic Core ------------------------------
* Copyright (C) 2013, ArcCore AB, Sweden, www.arccore.com.
* Contact: <contact@arccore.com>
*
* You may ONLY use this file:
* 1)if you have a valid commercial ArcCore license and then in accordance with
* the terms contained in the written license agreement between you and ArcCore,
* or alternatively
* 2)if you follow the terms found in GNU General Public License version 2 as
* published by the Free Software Foundation and appearing in the file
* LICENSE.GPL included in the packaging of this file or here
* <http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt>
*-------------------------------- Arctic Core -----------------------------*/
/** @reqSettings DEFAULT_SPECIFICATION_REVISION=4.1.3 */
/** @req 4.1.3/SWS_Xcp_00733 *//* Support Eth communication*/
/** @req 4.1.3/SWS_Xcp_00734 *//* PDUs have to be transmitted and received using the transmitting and receive APIs provided
* by the AUTOSAR Socket Adaptor*/
/** @req 4.1.3/SWS_Xcp_00739 *//* The header and tail of an XCP on Ethernet message have to be set properly */
#include "Xcp_Internal.h"
#if (XCP_PROTOCOL == XCP_PROTOCOL_ETHERNET)
#include "XcpOnEth_Cfg.h"
#include "ComStack_Types.h"
#include "SoAd.h"
#define XCP_ETH_FRAME_LEN_IDX 0u
#define XCP_ETH_FRAME_CNTR_IDX 2u
#define XCP_ETH_FRAME_PID_IDX 4u
static uint16 Xcp_EthCtrTx = 0;
/**
* This function is responsible to find an unused buffer/Pdu
* @param idxPtr
* @param pduIdPtr
* @return FALSE: There is no such Pdu
* TRUE: Empty buffer/Pdu has been found
*/
static boolean Xcp_FindFreeChannel(uint8* idxPtr, PduIdType* pduIdPtr)
{
uint8 idx;
for (idx = 0; idx < XCP_TX_CH_NUMBER; idx++) {
if ( (XCP_TX_CH_EMPTY == xcpPtr->XcpTxCh[idx].state) &&
(TRUE == xcpPtr->XcpTransmitPduAllowed(xcpPtr->XcpTxCh[idx].pduId)) ) {
*idxPtr = idx;
*pduIdPtr = xcpPtr->XcpTxCh[idx].pduId;
return TRUE;
}
}
return FALSE;
}
/**
* This function reserves buffer/Pdu which was found by Xcp_FindFreeChannel
* previously
* @param idxPtr
* @param pduIdPtr
* @return FALSE: There is no such Pdu
* TRUE: buffer/Pdu has been reserved
*/
static boolean Xcp_ReserveChannel(uint8* idxPtr, PduIdType* pduIdPtr)
{
if (Xcp_FindFreeChannel(idxPtr,pduIdPtr)) {
xcpPtr->XcpTxCh[*idxPtr].state = XCP_TX_CH_RESERVED;
return TRUE;
}
return FALSE;
}
/**
* This function frees up the previously reserves buffer/Pdu
* @param idx
*/
static void Xcp_FreeUpChannel(uint8 idx)
{
xcpPtr->XcpTxCh[idx].state = XCP_TX_CH_EMPTY;
xcpPtr->XcpTxCh[idx].len = 0;
}
/**
* This function initializes the communication specific Xcp layer
*/
void Xcp_SoAdLayerInit(void)
{
for (uint8 idx = 0; idx < XCP_TX_CH_NUMBER; idx++) {
Xcp_FreeUpChannel(idx);
}
}
void Xcp_CancelTxRequests( void ) {
Xcp_SoAdLayerInit();
}
/**
* Receive callback from Eth network layer
*
* This function is called by the lower layers (i.e. FlexRay Interface, TTCAN Interface
* and Socket Adaptor or CDD) when an AUTOSAR XCP PDU has been received
*
* Reentrant for different XcpRxPduIds,
* non reentrant for the same XcpRxPduId
*
* The function Xcp_<module>RxIndication might be called
* by the Xcp module�s environment in an interrupt context
*
* ServiceId: 0x03
*
* @param XcpRxPduId PDU-ID that has been received
* @param XcpRxPduPtr Pointer to SDU (Buffer of received payload)
*/
/** @req 4.1.3/SWS_Xcp_00813 *//*Xcp_<module>RxIndication API definition*/
/** @req 4.1.3/SWS_Xcp_00847 *//*Send DET if Xcp was not initialized, XcpRxPduPtr equals NULL_PTR, Invalid PDUID*/
void Xcp_SoAdIfRxIndication(PduIdType XcpRxPduId, PduInfoType* XcpRxPduPtr)
{
uint16 length;
DET_VALIDATE_NRV(Xcp_Inited , XCP_API_ID_XCP_RX_INDICATION, XCP_E_NOT_INITIALIZED);
DET_VALIDATE_NRV(XcpRxPduPtr, XCP_API_ID_XCP_RX_INDICATION, XCP_E_INV_POINTER);
DET_VALIDATE_NRV(XcpRxPduId < XCP_RX_CH_NUMBER, XCP_API_ID_XCP_RX_INDICATION, XCP_E_INVALID_PDUID);
DET_VALIDATE_NRV(XcpRxPduPtr->SduLength > 4u, XCP_API_ID_XCP_RX_INDICATION, XCP_E_INVALID_PDUID);
length = GET_UINT16(XcpRxPduPtr->SduDataPtr, XCP_ETH_FRAME_LEN_IDX);
if (TRUE == xcpPtr->XcpRecievePduAllowed(XcpRxPduId, XcpRxPduPtr)) {
Xcp_RxIndication(XcpRxPduPtr->SduDataPtr + XCP_ETH_FRAME_PID_IDX, length);
// Reset message counter on CONNECT command
if (XcpRxPduPtr->SduDataPtr[4] == 0xFF) { // 0xFF is CONNECT command
Xcp_EthCtrTx = 0;
}
}
}
/**
* Callback for finished transmit of PDU
*
* This function is called by the lower layers (i.e. FlexRay Interface, TTCAN Interface
* and Socket Adaptor or CDD) when an AUTOSAR XCP PDU has been transmitted
*
* Reentrant for different XcpTxPduIds, non reentrant for the same XcpTxPduId
*
* ServiceId: 0x02
*
* @param XcpRxPduId PDU-ID that has been transmitted
*/
/** @req 4.1.3/SWS_Xcp_00814 *//*Xcp_<module>TxConfirmation API definition*/
/** @req 4.1.3/SWS_Xcp_00840 *//*Send DET if the function Xcp_<module>TxConfirmation is called before the XCP was initialized successfully.*/
/** @req 4.1.3/SWS_Xcp_00841 *//*The call context is either on interrupt level (interrupt mode) or on task level, The Xcp module is initialized correctly. - can not be tested with conventional module tests*/
void Xcp_SoAdIfTxConfirmation(PduIdType XcpTxPduId)
{
DET_VALIDATE_NRV(Xcp_Inited,
XCP_API_ID_XCP_TX_CONFIRMATION,
XCP_E_NOT_INITIALIZED);
DET_VALIDATE_NRV(XcpTxPduId < XCP_TX_CH_NUMBER ,
XCP_API_ID_XCP_TX_CONFIRMATION,
XCP_E_INVALID_PDUID);
//XcpTxPduId is expected to be configured starting from 0 in a consecutive order
Xcp_FreeUpChannel((uint8)XcpTxPduId);
Xcp_TxConfirmation();
}
/**
* Called by core Xcp to transmit data
* @param data
* @param len
* @return
*/
Std_ReturnType Xcp_Transmit(const uint8* data, PduLengthType len)
{
Std_ReturnType retVal = E_NOT_OK;
PduIdType pduId, pduId2;
uint8 idx, idx2;
boolean freeChFound = FALSE;
/*-------------------------------------------*/
SchM_Enter_Xcp_EA_0(); /*Enter exclusive area*/
/*-------------------------------------------*/
freeChFound = Xcp_ReserveChannel(&idx, &pduId);
/*-------------------------------------------*/
SchM_Exit_Xcp_EA_0(); /*Exit exclusive area*/
/*-------------------------------------------*/
if (TRUE == freeChFound) {
//Free slot has been found, copy and try to send
PduInfoType pdu;
SET_UINT16(xcpPtr->XcpTxCh[idx].data, 0, len);
SET_UINT16(xcpPtr->XcpTxCh[idx].data, 2, ++Xcp_EthCtrTx);
Xcp_MemCpy(xcpPtr->XcpTxCh[idx].data + 4, data, len);
xcpPtr->XcpTxCh[idx].len = len + 4;
pdu.SduDataPtr = (uint8 *)xcpPtr->XcpTxCh[idx].data;
pdu.SduLength = xcpPtr->XcpTxCh[idx].len;
retVal = SoAd_IfTransmit(pduId, &pdu);
if (E_OK == retVal) {
//If there is free channel, available, indicate the next message handling
if (Xcp_FindFreeChannel(&idx2, &pduId2)) {
Xcp_TxConfirmation();
}
} else {
//Channel with certain pdu is not available
Xcp_FreeUpChannel(idx);
}
}
return retVal;
}
/**
* Called when the core of xcp have received a transport layer command
* @param pid
* @param data
* @param len
* @return
*/
Std_ReturnType Xcp_CmdTransportLayer(uint8 pid, uint8* data, PduLengthType len)
{
Xcp_TxError(XCP_ERR_CMD_UNKNOWN);
return E_OK;
}
#endif /*XCP_PROTOCOL == XCP_PROTOCOL_ETHERNET*/
|
2301_81045437/classic-platform
|
communication/Xcp/src/XcpOnEth.c
|
C
|
unknown
| 7,979
|
/*-------------------------------- Arctic Core ------------------------------
* Copyright (C) 2013, ArcCore AB, Sweden, www.arccore.com.
* Contact: <contact@arccore.com>
*
* You may ONLY use this file:
* 1)if you have a valid commercial ArcCore license and then in accordance with
* the terms contained in the written license agreement between you and ArcCore,
* or alternatively
* 2)if you follow the terms found in GNU General Public License version 2 as
* published by the Free Software Foundation and appearing in the file
* LICENSE.GPL included in the packaging of this file or here
* <http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt>
*-------------------------------- Arctic Core -----------------------------*/
/** @reqSettings DEFAULT_SPECIFICATION_REVISION=4.1.3 */
#include "Xcp_Internal.h"
/**************************************************************************/
/**************************************************************************/
/*************************** PGM COMMANDS *********************************/
/**************************************************************************/
/**************************************************************************/
#if(XCP_FEATURE_PGM == STD_ON)
typedef struct {
int started;
uint8 format;
uint32 rem;
uint32 len;
} XcpProgramType;
XcpProgramType Xcp_Program;
Std_ReturnType Xcp_CmdProgramStart(uint8 pid, uint8* data, PduLengthType len)
{
uint8 commModePgm = 0x00u
#if (XCP_FEATURE_BLOCKMODE == STD_ON)
| 1 << 0 /* MASTER_BLOCK_MODE */
| 1 << 6 /* SLAVE_BLOCK_MODE */
#endif /*XCP_FEATURE_BLOCKMODE == STD_ON)*/
| 0 << 1; /* INTERLEAVED_MODE */
DEBUG(DEBUG_HIGH, "Received ProgramStart\n");
XCP_UNUSED(pid);
XCP_UNUSED(data);/*lint !e920 Misra 2012 1.3 cast from pointer to void */
XCP_UNUSED(len);
FIFO_GET_WRITE(Xcp_FifoTxCto, e) {
SET_UINT8 (e->data, 0, XCP_PID_RES);
SET_UINT8 (e->data, 1, 0); /* RESERVED */
SET_UINT8 (e->data, 2, commModePgm);
SET_UINT8 (e->data, 3, XCP_MAX_CTO); /* MAX_CTO_PGM */
SET_UINT8 (e->data, 4, XCP_MAX_RXTX_QUEUE-1); /* MAX_BS_PGM */
SET_UINT8 (e->data, 5, 0); /* MIN_ST_PGM [100 microseconds] */
SET_UINT8 (e->data, 6, XCP_MAX_RXTX_QUEUE-1); /* QUEUE_SIZE_PGM */
e->len = 7;
}
Xcp_Program.started = 1;
return E_OK;
}
Std_ReturnType Xcp_CmdProgramClear(uint8 pid, uint8* data, PduLengthType len)
{
Std_ReturnType retVal;
Xcp_ErrorType error;
uint8 mode = GET_UINT8 (data, 0);
uint32 clearRange = GET_UINT32(data, 3);
DEBUG(DEBUG_HIGH, "Received ProgramClear %u, %u\n", mode, clearRange);
XCP_UNUSED(pid);
XCP_UNUSED(len);
if(!Xcp_Program.started) {
RETURN_ERROR(XCP_ERR_GENERIC, "Xcp_CmdProgramClear - programming not started\n");
}
if(mode == 0x01) { /* functional access mode */
retVal = xcpPtr->XcpProgramClear_FunctionalAccess(clearRange, &error);
}
else if(mode == 0x00) { /* absolute access mode */
retVal = xcpPtr->XcpProgramClear_AbsoluteAccess(&Xcp_Mta, clearRange, &error);
}
else {
RETURN_ERROR(XCP_ERR_CMD_SYNTAX, "Xcp_CmdProgramClear - Mode argument is invalid\n");
}
if(retVal == E_OK) {
RETURN_SUCCESS();
} else {
RETURN_ERROR(error);
}
}
Std_ReturnType Xcp_CmdProgram(uint8 pid, uint8* data, PduLengthType len)
{
Std_ReturnType retVal;
Xcp_ErrorType error;
uint32 rem = GET_UINT8(data, 0) * XCP_ELEMENT_SIZE;
uint32 off = XCP_ELEMENT_OFFSET(2) + 1;
DEBUG(DEBUG_HIGH, "Received Program %d, %d\n", pid, len);
if(!Xcp_Program.started) {
RETURN_ERROR(XCP_ERR_GENERIC, "Xcp_CmdProgram - programming not started\n");
}
#if (XCP_FEATURE_BLOCKMODE == STD_OFF)
if(rem + off > len) {
RETURN_ERROR(XCP_ERR_OUT_OF_RANGE, "Xcp_CmdProgram - Invalid length (%d, %d, %d)\n", rem, off, len);
}
#endif /*XCP_FEATURE_BLOCKMODE == STD_OFF*/
if(pid == XCP_PID_CMD_PGM_PROGRAM) {
Xcp_Program.len = rem;
Xcp_Program.rem = rem;
}
/* check for sequence error */
if(Xcp_Program.rem != rem) {
DEBUG(DEBUG_HIGH, "Xcp_CmdProgram - Invalid next state (%u, %u)\n", rem, (unsigned)Xcp_Program.rem);
FIFO_GET_WRITE(Xcp_FifoTxCto, e) {
SET_UINT8 (e->data, 0, XCP_PID_ERR);
SET_UINT8 (e->data, 1, XCP_ERR_SEQUENCE);
SET_UINT8 (e->data, 2, Xcp_Program.rem / XCP_ELEMENT_SIZE);
e->len = 3;
}
return E_OK; /*lint !e904 allow multiple exit */
}
/* write what we got this packet */
if(rem > len - off) {
rem = len - off;
}
/* write actual data to flash via callout function */
retVal = xcpPtr->XcpProgram(&Xcp_Mta,(uint8*) data + off, rem, &error);
if(retVal == E_OK) {
Xcp_Program.rem -= rem;
if(Xcp_Program.rem) {
return E_OK; /*lint !e904 allow multiple exit */
}
RETURN_SUCCESS();
} else {
RETURN_ERROR(error);
}
}
Std_ReturnType Xcp_CmdProgramReset(uint8 pid, uint8* data, PduLengthType len)
{
Xcp_ErrorType error;
Std_ReturnType retVal;
XCP_UNUSED(pid);
XCP_UNUSED(data);/*lint !e920 Misra 2012 1.3 cast from pointer to void */
XCP_UNUSED(len);
if(!Xcp_Program.started) {
RETURN_ERROR(XCP_ERR_GENERIC, "Xcp_CmdProgramReset - programming not started\n");
}
Xcp_Program.started = 0;
Xcp_Connected = 0;
retVal = xcpPtr->XcpProgramReset(&error);
if(retVal == E_OK) {
RETURN_SUCCESS();
} else {
RETURN_ERROR(error);
}
}
Std_ReturnType Xcp_CmdGetPgmProcessorInfo(uint8 pid, uint8* data, PduLengthType len)
{
Xcp_ErrorType error;
Std_ReturnType retVal;
uint8 pgmProperties;
uint8 maxSector
DEBUG(DEBUG_HIGH, "Received GetPgmProcessorInfo");
XCP_UNUSED(pid);
XCP_UNUSED(len);
XCP_UNUSED(data);/*lint !e920 Misra 2012 1.3 cast from pointer to void */
retVal = xcpPtr->XcpGetPgmProcessorInfo(&pgmProperties, &maxSector, &error);
if(E_OK == retVal) {
FIFO_GET_WRITE(Xcp_FifoTxCto, e) {
FIFO_ADD_U8 (e, XCP_PID_RES);
FIFO_ADD_U8 (e, pgmProperties);
FIFO_ADD_U8 (e, maxSector);
}
return E_OK; /*lint !e904 allow multiple exit */
} else {
RETURN_ERROR(error);
}
}
Std_ReturnType Xcp_CmdGetSectorInfo(uint8 pid, uint8* data, PduLengthType len)
{
Xcp_ErrorType error;
uint8 mode = GET_UINT8(data, 0);
uint8 sectorNumber = GET_UINT8(data, 1);
DEBUG(DEBUG_HIGH, "Received GetSectorInfo(%u, %u)\n", mode,sectorNumber);
XCP_UNUSED(pid);
XCP_UNUSED(len);
if ((mode == 0) || (mode == 1)) {
Xcp_GetSectorInfo_Mode0_1_ReturnType responseData;
if(E_OK == xcpPtr->XcpGetSectorInfo_Mode0_1(
mode, sectorNumber, &responseData, &error)) {
FIFO_GET_WRITE(Xcp_FifoTxCto, e) {
FIFO_ADD_U8 (e, XCP_PID_RES);
FIFO_ADD_U8 (e, responseData.clearSeqNum);
FIFO_ADD_U8 (e, responseData.programSeqNum);
FIFO_ADD_U8 (e, responseData.programMethod);
FIFO_ADD_U32 (e, responseData.sectorInfo);
}
return E_OK; /*lint !e904 allow multiple exit */
} else {
RETURN_ERROR(error);
}
} else if (mode == 2) {
uint8 sectorNameLength;
if(E_OK == xcpPtr->XcpGetSectorInfo_Mode2(§orNameLength, &error)) {
FIFO_GET_WRITE(Xcp_FifoTxCto, e) {
FIFO_ADD_U8 (e, XCP_PID_RES);
FIFO_ADD_U8 (e, sectorNameLength);
}
return E_OK; /*lint !e904 allow multiple exit */
} else {
RETURN_ERROR(error);
}
} else {
RETURN_ERROR(XCP_ERR_CMD_SYNTAX, "Xcp_CmdGetSectorInfo - Mode argument is invalid\n");
}
}
Std_ReturnType Xcp_CmdProgramPrepare(uint8 pid, uint8* data, PduLengthType len)
{
Xcp_ErrorType error;
Std_ReturnType retVal;
uint16 codeSize = GET_UINT16(data, 1);
DEBUG(DEBUG_HIGH, "Received ProgramPrepare(%u)\n", codeSize);
XCP_UNUSED(pid);
XCP_UNUSED(len);
retVal = xcpPtr->XcpProgramPrepare(&Xcp_Mta, codeSize, &error);
if(retVal == E_OK) {
RETURN_SUCCESS();
} else {
RETURN_ERROR(error);
}
}
Std_ReturnType Xcp_CmdProgramFormat(uint8 pid, uint8* data, PduLengthType len)
{
Xcp_ErrorType error;
Std_ReturnType retVal;
uint8 compressionMethod = GET_UINT8(data, 0);
uint8 encryptionMethod = GET_UINT8(data, 1);
uint8 programmingMethod = GET_UINT8(data, 2);
uint8 accessMethod = GET_UINT8(data, 3);
DEBUG(DEBUG_HIGH, "Received ProgramFormat(%u, %u, %u, %u)\n",
compressionMethod,encryptionMethod,programmingMethod,accessMethod);
XCP_UNUSED(pid);
XCP_UNUSED(len);
retVal = xcpPtr->XcpProgramFormat(compressionMethod,encryptionMethod,programmingMethod,accessMethod, &error);
if(retVal == E_OK) {
RETURN_SUCCESS();
} else {
RETURN_ERROR(error);
}
}
Std_ReturnType Xcp_CmdProgramVerify(uint8 pid, uint8* data, PduLengthType len)
{
Xcp_ErrorType error;
Std_ReturnType retVal;
uint8 mode = GET_UINT8(data, 0);
uint16 type = GET_UINT16(data, 1);
uint32 value = GET_UINT32(data, 3);
DEBUG(DEBUG_HIGH, "Received ProgramVerify(%u, %u, %u)\n", mode, type, value);
XCP_UNUSED(pid);
XCP_UNUSED(len);
retVal = xcpPtr->XcpProgramVerify(mode, type, value, &error);
if(retVal == E_OK) {
RETURN_SUCCESS();
} else {
RETURN_ERROR(error);
}
}
#endif /*XCP_FEATURE_PGM == STD_ON*/
|
2301_81045437/classic-platform
|
communication/Xcp/src/Xcp_FlashProgramming.c
|
C
|
unknown
| 10,042
|
/*-------------------------------- Arctic Core ------------------------------
* Copyright (C) 2013, ArcCore AB, Sweden, www.arccore.com.
* Contact: <contact@arccore.com>
*
* You may ONLY use this file:
* 1)if you have a valid commercial ArcCore license and then in accordance with
* the terms contained in the written license agreement between you and ArcCore,
* or alternatively
* 2)if you follow the terms found in GNU General Public License version 2 as
* published by the Free Software Foundation and appearing in the file
* LICENSE.GPL included in the packaging of this file or here
* <http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt>
*-------------------------------- Arctic Core -----------------------------*/
/** @reqSettings DEFAULT_SPECIFICATION_REVISION=4.1.3 */
#ifndef XCP_INTERNAL_H_
#define XCP_INTERNAL_H_
#include "Xcp.h"
#include "SchM_Xcp.h"
#include <string.h>
#include <stdlib.h>
#if(XCP_DEV_ERROR_DETECT == STD_ON)
#include "Det.h"
#endif
#include "Os.h"
#include "ComStack_Types.h"
#include "debug.h"
/*lint -emacro(904,DET_VALIDATE,DET_VALIDATE_NRV,DET_VALIDATE_RV,RETURN_ERROR,RETURN_SUCCESS) 904 PC-Lint exception to MISRA 14.7 (validate DET macros)*/
/* HELPER DEFINES */
#define RETURN_ERROR(code, ...) do { \
DEBUG(DEBUG_HIGH,## __VA_ARGS__ );\
Xcp_TxError(code); \
return E_NOT_OK; \
} while(0)
#define RETURN_SUCCESS() do { \
Xcp_TxSuccess(); \
return E_OK; \
} while(0)
#if(XCP_DEV_ERROR_DETECT == STD_ON)
# define DET_VALIDATE(_exp, ApiId, ErrorId) \
if( !(_exp) ) { \
(void)Det_ReportError(XCP_MODULE_ID, 0, ApiId, ErrorId); \
}
# define DET_VALIDATE_NRV(_exp, ApiId, ErrorId) \
if( !(_exp) ) { \
(void)Det_ReportError(XCP_MODULE_ID, 0, ApiId, ErrorId); \
return; \
}
# define DET_VALIDATE_RV(_exp, ApiId, ErrorId, Return) \
if( !(_exp) ) { \
(void)Det_ReportError(XCP_MODULE_ID, 0, ApiId, ErrorId); \
return Return; \
}
# define DET_REPORTERROR(ApiId,ErrorId) (void)Det_ReportError(XCP_MODULE_ID, 0, ApiId, ErrorId)
#else
# define DET_VALIDATE(_exp, ApiId, ErrorId)
# define DET_VALIDATE_NRV(_exp, ApiId, ErrorId )
# define DET_VALIDATE_RV(_exp, ApiId, ErrorId, Return)
# define DET_REPORTERROR(ApiId,ErrorId)
#endif
/*********************************************
* PROTOCOL SETTINGS *
*********************************************/
/*Only element size 1 is supported*/
#define XCP_ELEMENT_SIZE 1
#define XCP_GRANULARITY_ODT_ENTRY_SIZE_DAQ 1
#define XCP_GRANULARITY_ODT_ENTRY_SIZE_STIM 1
#if(XCP_IDENTIFICATION == XCP_IDENTIFICATION_ABSOLUTE)
# define XCP_MAX_ODT_SIZE (XCP_MAX_DTO - 1) /**< defines the maximum number of bytes that can fit in a dto packages data area*/
#elif(XCP_IDENTIFICATION == XCP_IDENTIFICATION_RELATIVE_BYTE)
# define XCP_MAX_ODT_SIZE (XCP_MAX_DTO - 2) /**< defines the maximum number of bytes that can fit in a dto packages data area*/
#elif(XCP_IDENTIFICATION == XCP_IDENTIFICATION_RELATIVE_WORD)
# define XCP_MAX_ODT_SIZE (XCP_MAX_DTO - 3) /**< defines the maximum number of bytes that can fit in a dto packages data area*/
#elif(XCP_IDENTIFICATION == XCP_IDENTIFICATION_RELATIVE_WORD_ALIGNED)
# define XCP_MAX_ODT_SIZE (XCP_MAX_DTO - 4) /**< defines the maximum number of bytes that can fit in a dto packages data area*/
#endif
#ifndef XCP_MAX_ODT_ENTRY_SIZE_DAQ
# define XCP_MAX_ODT_ENTRY_SIZE_DAQ XCP_MAX_ODT_SIZE
#endif
#ifndef XCP_MAX_ODT_ENTRY_SIZE_STIM
# define XCP_MAX_ODT_ENTRY_SIZE_STIM XCP_MAX_ODT_SIZE
#endif
#if(XCP_GRANULARITY_ODT_ENTRY_SIZE_STIM > XCP_GRANULARITY_ODT_ENTRY_SIZE_DAQ)
# define XCP_GRANULARITY_ODT_ENTRY_SIZE_MIN XCP_GRANULARITY_ODT_ENTRY_SIZE_DAQ
# define XCP_GRANULARITY_ODT_ENTRY_SIZE_MAX XCP_GRANULARITY_ODT_ENTRY_SIZE_STIM
#else
# define XCP_GRANULARITY_ODT_ENTRY_SIZE_MIN XCP_GRANULARITY_ODT_ENTRY_SIZE_STIM
# define XCP_GRANULARITY_ODT_ENTRY_SIZE_MAX XCP_GRANULARITY_ODT_ENTRY_SIZE_DAQ
#endif
#ifndef XCP_MAX_ODT_ENTRIES
# define XCP_MAX_ODT_ENTRIES (XCP_MAX_ODT_SIZE / XCP_GRANULARITY_ODT_ENTRY_SIZE_MIN)
#endif
#define XCP_ELEMENT_OFFSET(base) (XCP_ELEMENT_SIZE - 1 - ( (base)+XCP_ELEMENT_SIZE-1 ) % XCP_ELEMENT_SIZE )
#if (XCP_MAX_DTO > XCP_MAX_CTO)
# define XCP_MAX_BUFFER XCP_MAX_DTO
#else
# define XCP_MAX_BUFFER XCP_MAX_CTO
#endif
/********************* COMMANDS *****************/
/* STANDARD COMMANDS */
/* OPTIONAL */
#define XCP_PID_CMD_STD_CONNECT 0xFF // N
#define XCP_PID_CMD_STD_DISCONNECT 0xFE // N
#define XCP_PID_CMD_STD_GET_STATUS 0xFD // N
#define XCP_PID_CMD_STD_SYNCH 0xFC // N
#define XCP_PID_CMD_STD_GET_COMM_MODE_INFO 0xFB // Y
#define XCP_PID_CMD_STD_GET_ID 0xFA // Y
#define XCP_PID_CMD_STD_SET_REQUEST 0xF9 // Y
#define XCP_PID_CMD_STD_GET_SEED 0xF8 // Y
#define XCP_PID_CMD_STD_UNLOCK 0xF7 // Y
#define XCP_PID_CMD_STD_SET_MTA 0xF6 // Y
#define XCP_PID_CMD_STD_UPLOAD 0xF5 // Y
#define XCP_PID_CMD_STD_SHORT_UPLOAD 0xF4 // Y
#define XCP_PID_CMD_STD_BUILD_CHECKSUM 0xF3 // Y
#define XCP_PID_CMD_STD_TRANSPORT_LAYER_CMD 0xF2 // Y
#define XCP_PID_CMD_STD_USER_CMD 0xF1 // Y
/* CALIBRATION COMMANDS */
/* OPTIONAL */
#define XCP_PID_CMD_CAL_DOWNLOAD 0xF0 // N
#define XCP_PID_CMD_CAL_DOWNLOAD_NEXT 0xEF // Y
#define XCP_PID_CMD_CAL_DOWNLOAD_MAX 0xEE // Y
#define XCP_PID_CMD_CAL_SHORT_DOWNLOAD 0xED // Y
#define XCP_PID_CMD_CAL_MODIFY_BITS 0xEC // Y
/* PAGE SWITCHING COMMANDS */
/* OPTIONAL */
#define XCP_PID_CMD_PAG_SET_CAL_PAGE 0xEB // Y
#define XCP_PID_CMD_PAG_GET_CAL_PAGE 0xEA // Y
#define XCP_PID_CMD_PAG_GET_PAG_PROCESSOR_INFO 0xE9 // Y
#define XCP_PID_CMD_PAG_GET_SEGMENT_INFO 0xE8 // Y
#define XCP_PID_CMD_PAG_GET_PAGE_INFO 0xE7 // Y
#define XCP_PID_CMD_PAG_SET_SEGMENT_MODE 0xE6 // Y
#define XCP_PID_CMD_PAG_GET_SEGMENT_MODE 0xE5 // Y
#define XCP_PID_CMD_PAG_COPY_CAL_PAGE 0xE4 // Y
/* DATA SCQUISITION AND STIMULATION COMMANDS */
/* OPTIONAL */
#define XCP_PID_CMD_DAQ_CLEAR_DAQ_LIST 0xE3 // N
#define XCP_PID_CMD_DAQ_SET_DAQ_PTR 0xE2 // N
#define XCP_PID_CMD_DAQ_WRITE_DAQ 0xE1 // N
#define XCP_PID_CMD_DAQ_SET_DAQ_LIST_MODE 0xE0 // N
#define XCP_PID_CMD_DAQ_GET_DAQ_LIST_MODE 0xDF // N
#define XCP_PID_CMD_DAQ_START_STOP_DAQ_LIST 0xDE // N
#define XCP_PID_CMD_DAQ_START_STOP_SYNCH 0xDD // N
#define XCP_PID_CMD_DAQ_GET_DAQ_CLOCK 0xDC // Y
#define XCP_PID_CMD_DAQ_READ_DAQ 0xDB // Y
#define XCP_PID_CMD_DAQ_GET_DAQ_PROCESSOR_INFO 0xDA // Y
#define XCP_PID_CMD_DAQ_GET_DAQ_RESOLUTION_INFO 0xD9 // Y
#define XCP_PID_CMD_DAQ_GET_DAQ_LIST_INFO 0xD8 // Y
#define XCP_PID_CMD_DAQ_GET_DAQ_EVENT_INFO 0xD7 // Y
#define XCP_PID_CMD_DAQ_FREE_DAQ 0xD6 // Y
#define XCP_PID_CMD_DAQ_ALLOC_DAQ 0xD5 // Y
#define XCP_PID_CMD_DAQ_ALLOC_ODT 0xD4 // Y
#define XCP_PID_CMD_DAQ_ALLOC_ODT_ENTRY 0xD3 // Y
/* NON-VOLATILE MEMORY PROGRAMMING COMMANDS */
/* OPTIONAL */
#define XCP_PID_CMD_PGM_PROGRAM_START 0xD2 // N
#define XCP_PID_CMD_PGM_PROGRAM_CLEAR 0xD1 // N
#define XCP_PID_CMD_PGM_PROGRAM 0xD0 // N
#define XCP_PID_CMD_PGM_PROGRAM_RESET 0xCF // N
#define XCP_PID_CMD_PGM_GET_PGM_PROCESSOR_INFO 0xCE // Y
#define XCP_PID_CMD_PGM_GET_SECTOR_INFO 0xCD // Y
#define XCP_PID_CMD_PGM_PROGRAM_PREPARE 0xCC // Y
#define XCP_PID_CMD_PGM_PROGRAM_FORMAT 0xCB // Y
#define XCP_PID_CMD_PGM_PROGRAM_NEXT 0xCA // Y
#define XCP_PID_CMD_PGM_PROGRAM_MAX 0xC9 // Y
#define XCP_PID_CMD_PGM_PROGRAM_VERIFY 0xC8 // Y
/* STIM LISTS */
#define XCP_PID_CMD_STIM_LAST 0xBF // Y
/* Exclusive areas */
#define SchM_Enter_Xcp(_area) SchM_Enter_Xcp_##_area()
#define SchM_Exit_Xcp(_area) SchM_Exit_Xcp_##_area()
#define XCP_UNUSED(x) (void)(x)
// SET ENDIANNESS
// BIG ENDIAN
#if defined(CFG_PPC) || defined(CFG_TMS570)
#define XPC_C32_0 0
#define XPC_C32_1 1
#define XPC_C32_2 2
#define XPC_C32_3 3
#define XPC_C16_0 0
#define XPC_C16_1 1
#else
// LITTLE ENDIAN
#define XPC_C32_0 3
#define XPC_C32_1 2
#define XPC_C32_2 1
#define XPC_C32_3 0
#define XPC_C16_0 1
#define XPC_C16_1 0
#endif
static inline uint8 GET_UINT8(const uint8* data, uint8 offset) {
return *(uint8*)(data + offset);
}
static inline uint16 GET_UINT16(const uint8* data, uint8 offset) {
uint8* location = (uint8*)(data + offset);
uint16 result = location[XPC_C16_0] << 8u;
result |= location[XPC_C16_1];
return result;
}
static inline uint32 GET_UINT32(const uint8* data, uint8 offset) {
uint8* location = (uint8*)(data + offset);
uint32 result = location[XPC_C32_0] << 24u;
result |= location[XPC_C32_1] << 16u;
result |= location[XPC_C32_2] << 8u;
result |= location[XPC_C32_3];
return result;
}
static inline void SET_UINT8(uint8* data, uint8 offset, uint8 value) {
*(uint8*)(data + offset) = value;
}
static inline void SET_UINT16(uint8* data, uint8 offset, uint16 value) {
uint8* location = (uint8*)(data + offset);
location[XPC_C16_0] = (uint8)((value & 0xFF00) >> 8u);
location[XPC_C16_1] = (uint8)(value & 0x00FF);
}
static inline void SET_UINT32(uint8* data, uint8 offset, uint32 value) {
uint8* location = (uint8*)(data + offset);
location[XPC_C32_0] = (uint8)((value & 0xFF000000) >> 24u);
location[XPC_C32_1] = (uint8)((value & 0x00FF0000) >> 16u);
location[XPC_C32_2] = (uint8)((value & 0x0000FF00) >> 8u);
location[XPC_C32_3] = (uint8)(value & 0x000000FF);
}
#define FIFO_GET_WRITE(fifo, it) \
for(Xcp_BufferType* it = Xcp_Fifo_Get(fifo.free); it; Xcp_Fifo_Put(&fifo, it), it = NULL)
#define FIFO_FOR_READ(fifo, it) \
for(Xcp_BufferType* it = Xcp_Fifo_Get(&fifo); it; Xcp_Fifo_Free(&fifo, it), it = Xcp_Fifo_Get(&fifo))
#define FIFO_ADD_U8(buffer, value) \
do { SET_UINT8((buffer)->data, (buffer)->len, value); (buffer)->len+=1; } while(0)
#define FIFO_ADD_U16(buffer, value) \
do { SET_UINT16((buffer)->data, (buffer)->len, value); (buffer)->len+=2; } while(0)
#define FIFO_ADD_U32(buffer, value) \
do { SET_UINT32((buffer)->data, (buffer)->len, value); (buffer)->len+=4; } while(0)
/* REPLY TYPES */
#define XCP_PID_RES 0xFFu
#define XCP_PID_ERR 0xFEu
#define XCP_PID_EV 0xFDu
#define XCP_PID_SERV 0xFCu
/* EVENT CODES */
#define XCP_EV_RESUME_MODE 0x00u
#define XCP_EV_CLEAR_DAQ 0x01u
#define XCP_EV_STORE_DAQ 0x02u
#define XCP_EV_STORE_CAL 0x03u
#define XCP_EV_CMD_PENDING 0x05u
#define XCP_EV_DAQ_OVERLOAD 0x06u
#define XCP_EV_SESSION_TERMINATED 0x07u
#define XCP_EV_USER 0xFEu
#define XCP_EV_TRANSPORT 0xFFu
/* COMMAND LIST FUNCTION CALLBACK */
typedef Std_ReturnType (*Xcp_CmdFuncType)(uint8, uint8*, PduLengthType);
typedef void (*Xcp_CmdWorkType)(void);
typedef struct {
Xcp_CmdFuncType fun; /**< pointer to function to use */
uint8 len; /**< minimum length of command */
uint8 lock; /**< locked by following types (Xcp_ProtectType) */
} Xcp_CmdListType;
/* INTERNAL STATE STRUCTURES */
typedef enum {
XCP_DYNAMIC_STATE_UNDEFINED = 0,
XCP_DYNAMIC_STATE_FREE_DAQ,
XCP_DYNAMIC_STATE_ALLOC_DAQ,
XCP_DYNAMIC_STATE_ALLOC_ODT,
XCP_DYNAMIC_STATE_ALLOC_ODT_ENTRY,
} Xcp_DaqListConfigStateEnum;
typedef struct {
Xcp_OdtEntryType* ptr;
Xcp_OdtType* odt;
Xcp_DaqListType* daq;
Xcp_DaqListConfigStateEnum dyn;
} Xcp_DaqPtrStateType;
typedef struct {
PduLengthType len; /**< Original upload size */
PduLengthType rem; /**< Remaining upload size */
} Xcp_TransferType;
typedef struct {
uint8 seed[255];
uint8 seed_len;
uint8 seed_rem;
uint8 key[255];
uint8 key_len;
uint8 key_rem;
Xcp_ProtectType res;
} Xcp_UnlockType;
/* RX/TX FIFO */
typedef struct Xcp_BufferType {
struct Xcp_BufferType* next;
PduLengthType len;
uint8 data[XCP_MAX_BUFFER];
} Xcp_BufferType;
typedef struct Xcp_FifoType {
Xcp_BufferType* front;
Xcp_BufferType* back;
struct Xcp_FifoType* free;
void* lock;
} Xcp_FifoType;
/* INTERNAL GLOBAL VARIABLES */
extern Xcp_FifoType Xcp_FifoTxCto;
extern uint8 Xcp_Inited;
extern const Xcp_ConfigType* xcpPtr;
extern Xcp_MtaType Xcp_Mta;
extern uint8 Xcp_Connected;
/* This function is used to enter exclusive area to avoid data correction.*/
static inline void Xcp_Fifo_Lock(void)
{
SchM_Enter_Xcp_EA_0();
}
/* This function is used to exit from exclusive area.*/
static inline void Xcp_Fifo_Unlock(void)
{
SchM_Exit_Xcp_EA_0();
}
/* This function retrieves the fist element from the FIFO q.*/
static inline Xcp_BufferType* Xcp_Fifo_Get(Xcp_FifoType* q)
{
DET_VALIDATE_RV(q, XCP_API_ID_XCP_FIFO_GET, XCP_E_NULL_POINTER,NULL);
Xcp_Fifo_Lock();
Xcp_BufferType* b = q->front;
if(b == NULL) {
/*FIFO is empty*/
Xcp_Fifo_Unlock();
return NULL; /*lint !e904 allow multiple exit */
}
/*retrieve b from the FIFO*/
q->front = b->next;
if(q->front == NULL) {
q->back = NULL;
}
b->next = NULL;
Xcp_Fifo_Unlock();
return b;
}
/* This function add the new element b to the FIFO q.*/
static inline void Xcp_Fifo_Put(Xcp_FifoType* q, Xcp_BufferType* b)
{
DET_VALIDATE_NRV(q, XCP_API_ID_XCP_FIFO_PUT, XCP_E_NULL_POINTER);
DET_VALIDATE_NRV(b, XCP_API_ID_XCP_FIFO_PUT, XCP_E_NULL_POINTER);
Xcp_Fifo_Lock();
b->next = NULL;
if(q->back) {
q->back->next = b; /*add pointer to b from the previous element*/
} else {
q->front = b; /*if there is no previous element add as first element*/
}
q->back = b;
Xcp_Fifo_Unlock();
}
/* This function release one element b by adding it to q->free FIFO.*/
static inline void Xcp_Fifo_Free(Xcp_FifoType* q, Xcp_BufferType* b)
{
DET_VALIDATE_NRV(q, XCP_API_ID_XCP_FIFO_FREE, XCP_E_NULL_POINTER);
DET_VALIDATE_NRV(b, XCP_API_ID_XCP_FIFO_FREE, XCP_E_NULL_POINTER);
if(b) {
b->len = 0;
Xcp_Fifo_Put(q->free, b);
}
}
/* This function initialize a FIFO q by the content defined by b and e pointer as start
* and end pointer respectively.*/
static inline void Xcp_Fifo_Init(Xcp_FifoType* q, Xcp_BufferType* b, Xcp_BufferType* e)
{
DET_VALIDATE_NRV(q, XCP_API_ID_XCP_FIFO_INIT, XCP_E_NULL_POINTER);
DET_VALIDATE_NRV(b, XCP_API_ID_XCP_FIFO_INIT, XCP_E_NULL_POINTER);
DET_VALIDATE_NRV(e, XCP_API_ID_XCP_FIFO_INIT, XCP_E_NULL_POINTER);
q->front = NULL;
q->back = NULL;
q->lock = NULL;
for(;b != e; b++) {
Xcp_Fifo_Put(q, b);
}
}
/* This kind of memory extension is used by XCP.c for reading or writing some general information
* from XCP reserved memory (Ram), or reading from XCP Config (Flash) */
#define XCP_MTA_EXTENSION_MEMORY_INTERNAL_FIXED 0xFFu
/* MTA HELPER FUNCTIONS */
static inline void Xcp_MtaFlush(Xcp_MtaType* mta) { if(mta->flush) mta->flush(mta); } /**< Will flush any remaining data to write */
static inline void Xcp_MtaWrite(Xcp_MtaType* mta, uint8* data, uint32 len) { mta->write(mta, data, len); }
static inline void Xcp_MtaRead (Xcp_MtaType* mta, uint8* data, uint32 len) { mta->read(mta, data, len);}
static inline uint8 Xcp_MtaGet (Xcp_MtaType* mta) { return mta->get(mta); }
/* PROGRAMMING COMMANDS */
extern Std_ReturnType Xcp_CmdProgramStart(uint8 pid, uint8* data, PduLengthType len);
extern Std_ReturnType Xcp_CmdProgramClear(uint8 pid, uint8* data, PduLengthType len);
extern Std_ReturnType Xcp_CmdProgram(uint8 pid, uint8* data, PduLengthType len);
extern Std_ReturnType Xcp_CmdProgramReset(uint8 pid, uint8* data, PduLengthType len);
extern Std_ReturnType Xcp_CmdProgramInfo(uint8 pid, uint8* data, PduLengthType len);
extern Std_ReturnType Xcp_CmdGetPgmProcessorInfo(uint8 pid, uint8* data, PduLengthType len);
extern Std_ReturnType Xcp_CmdGetSectorInfo(uint8 pid, uint8* data, PduLengthType len);
extern Std_ReturnType Xcp_CmdProgramPrepare(uint8 pid, uint8* data, PduLengthType len);
extern Std_ReturnType Xcp_CmdProgramFormat(uint8 pid, uint8* data, PduLengthType len);
extern Std_ReturnType Xcp_CmdProgramVerify(uint8 pid, uint8* data, PduLengthType len);
/* ONLINE CALIBRATION COMMANDS*/
extern Std_ReturnType Xcp_CmdSetSegmentMode(uint8 pid, uint8* data, PduLengthType len);
extern Std_ReturnType Xcp_CmdGetSegmentMode(uint8 pid, uint8* data, PduLengthType len);
extern Std_ReturnType Xcp_CmdSetCalPage(uint8 pid, uint8* data, PduLengthType len);
extern Std_ReturnType Xcp_CmdGetCalPage(uint8 pid, uint8* data, PduLengthType len);
extern Std_ReturnType Xcp_CmdGetPageInfo(uint8 pid, uint8* data, PduLengthType len);
extern Std_ReturnType Xcp_CmdCopyCalPage(uint8 pid, uint8* data, PduLengthType len);
extern Std_ReturnType Xcp_CmdGetPagProcessorInfo(uint8 pid, uint8* data, PduLengthType len);
extern Std_ReturnType Xcp_CmdGetSegmentInfo(uint8 pid, uint8* data, PduLengthType len);
/* CALLBACK FUNCTIONS */
extern void Xcp_RxIndication(const uint8* data, PduLengthType len);
extern void Xcp_TxConfirmation(void);
extern Std_ReturnType Xcp_Transmit(const uint8* data, PduLengthType len);
extern void Xcp_CancelTxRequests(void);
extern Std_ReturnType Xcp_CmdTransportLayer(uint8 pid, uint8* data, PduLengthType len);
extern void Xcp_TxError(Xcp_ErrorType code);
extern void Xcp_TxSuccess(void);
#if (XCP_PROTOCOL == XCP_PROTOCOL_CAN)
extern void Xcp_CanLayerInit(void);
#elif (XCP_PROTOCOL == XCP_PROTOCOL_ETHERNET)
extern void Xcp_SoAdLayerInit(void);
#endif
/* GENERIC HELPER FUNCTIONS */
extern void Xcp_MemCpy(void * dst, void const * src, size_t len);
#endif /* XCP_INTERNAL_H_ */
|
2301_81045437/classic-platform
|
communication/Xcp/src/Xcp_Internal.h
|
C
|
unknown
| 19,286
|
/*-------------------------------- Arctic Core ------------------------------
* Copyright (C) 2013, ArcCore AB, Sweden, www.arccore.com.
* Contact: <contact@arccore.com>
*
* You may ONLY use this file:
* 1)if you have a valid commercial ArcCore license and then in accordance with
* the terms contained in the written license agreement between you and ArcCore,
* or alternatively
* 2)if you follow the terms found in GNU General Public License version 2 as
* published by the Free Software Foundation and appearing in the file
* LICENSE.GPL included in the packaging of this file or here
* <http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt>
*-------------------------------- Arctic Core -----------------------------*/
/** @reqSettings DEFAULT_SPECIFICATION_REVISION=4.1.3 */
#include "Xcp_Internal.h"
/**
* Read a character from MTA
* @return
*/
static uint8 Xcp_MtaGetMemory(Xcp_MtaType* mta)
{
return *(uint8*)(mta->address++);
}
/**
* Read a character from memory
* @return
*/
static void Xcp_MtaReadMemory(Xcp_MtaType* mta, uint8* data, uint32 len)
{
Xcp_MemCpy(data, (void*)mta->address, len);
mta->address += len;
}
/**
* Write a character to memory
* @return
*/
static void Xcp_MtaWriteMemory(Xcp_MtaType* mta, uint8* data, uint32 len)
{
Xcp_MemCpy((void*)mta->address, data, len);
mta->address += len;
}
/**
* Set the MTA pointer to given address on given extension
* @param address
* @param extension
*/
void Xcp_MtaInit(Xcp_MtaType* mta, uint32 address, uint8 extension)
{
mta->address = address;
mta->extension = extension;
if(extension == XCP_MTA_EXTENSION_MEMORY)
{
mta->get = Xcp_MtaGetMemory;
mta->read = Xcp_MtaReadMemory;
mta->write = Xcp_MtaWriteMemory;
mta->flush = NULL;
}
else if(extension == XCP_MTA_EXTENSION_FLASH)
{
mta->get = Xcp_MtaGetMemory;
mta->read = Xcp_MtaReadMemory;
mta->write = NULL;
mta->flush = NULL;
}
else
{
mta->get = NULL;
mta->read = NULL;
mta->write = NULL;
mta->flush = NULL;
}
}
|
2301_81045437/classic-platform
|
communication/Xcp/src/Xcp_Memory.c
|
C
|
unknown
| 2,214
|
/*-------------------------------- Arctic Core ------------------------------
* Copyright (C) 2013, ArcCore AB, Sweden, www.arccore.com.
* Contact: <contact@arccore.com>
*
* You may ONLY use this file:
* 1)if you have a valid commercial ArcCore license and then in accordance with
* the terms contained in the written license agreement between you and ArcCore,
* or alternatively
* 2)if you follow the terms found in GNU General Public License version 2 as
* published by the Free Software Foundation and appearing in the file
* LICENSE.GPL included in the packaging of this file or here
* <http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt>
*-------------------------------- Arctic Core -----------------------------*/
/** @reqSettings DEFAULT_SPECIFICATION_REVISION=4.1.3 */
#include "Xcp_Internal.h"
void Xcp_MemCpy(void * dst, void const * src, size_t len)
{
#if defined (CFG_ZYNQ) && defined(__GNUC__)
uint8 * pDst = (uint8 *) dst;
uint8 const * pSrc = (uint8 const *) src;
while (len--)
{
*pDst++ = *pSrc++;
}
#else
memcpy(dst, src, len);
#endif
}
|
2301_81045437/classic-platform
|
communication/Xcp/src/Xcp_MemoryHelper.c
|
C
|
unknown
| 1,147
|
/*-------------------------------- Arctic Core ------------------------------
* Copyright (C) 2013, ArcCore AB, Sweden, www.arccore.com.
* Contact: <contact@arccore.com>
*
* You may ONLY use this file:
* 1)if you have a valid commercial ArcCore license and then in accordance with
* the terms contained in the written license agreement between you and ArcCore,
* or alternatively
* 2)if you follow the terms found in GNU General Public License version 2 as
* published by the Free Software Foundation and appearing in the file
* LICENSE.GPL included in the packaging of this file or here
* <http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt>
*-------------------------------- Arctic Core -----------------------------*/
/** @reqSettings DEFAULT_SPECIFICATION_REVISION=4.1.3 */
#include "Xcp_Internal.h"
/**************************************************************************/
/**************************************************************************/
/*************************** CAL/PAG COMMANDS *****************************/
/**************************************************************************/
/**************************************************************************/
#if(XCP_FEATURE_CALPAG == STD_ON)
Std_ReturnType Xcp_CmdSetCalPage(uint8 pid, uint8* data, PduLengthType len)
{
Xcp_ErrorType error;
Std_ReturnType retVal;
uint32 mode = GET_UINT8(data, 0);
uint32 segm = GET_UINT8(data, 1);
uint32 page = GET_UINT8(data, 2);
DEBUG(DEBUG_HIGH, "Received SetCalPage(0x%x, %u, %u)\n", mode, segm, page);
XCP_UNUSED(pid);
XCP_UNUSED(len);
retVal = xcpPtr->XcpSetCalPage(mode, segm, page, &error);
if(retVal == E_OK) {
RETURN_SUCCESS();
} else {
RETURN_ERROR(error);
}
}
Std_ReturnType Xcp_CmdGetCalPage(uint8 pid, uint8* data, PduLengthType len)
{
uint8 mode = GET_UINT8(data, 0);
uint8 segm = GET_UINT8(data, 1);
uint8 page = 0;
Xcp_ErrorType error;
Std_ReturnType retVal;
DEBUG(DEBUG_HIGH, "Received GetCalPage(0x%x, %u)\n", mode, segm);
XCP_UNUSED(pid);
XCP_UNUSED(len);
retVal = xcpPtr->XcpGetCalPage(mode, segm, &page, &error);
if(retVal == E_OK) {
FIFO_GET_WRITE(Xcp_FifoTxCto, e) {
FIFO_ADD_U8 (e, XCP_PID_RES);
FIFO_ADD_U8 (e, 0); /* reserved */
FIFO_ADD_U8 (e, 0); /* reserved */
FIFO_ADD_U8 (e, page);
}
return E_OK; /*lint !e904 allow multiple exit */
} else {
RETURN_ERROR(error);
}
}
Std_ReturnType Xcp_CmdCopyCalPage(uint8 pid, uint8* data, PduLengthType len)
{
uint8 sourceSegm = GET_UINT8(data, 0);
uint8 sourcePage = GET_UINT8(data, 1);
uint8 destSegm = GET_UINT8(data, 2);
uint8 destPage = GET_UINT8(data, 3);
Xcp_ErrorType error;
Std_ReturnType retVal;
DEBUG(DEBUG_HIGH, "Received CopyCalPage(0x%x, %u)\n", mode, segm);
XCP_UNUSED(pid);
XCP_UNUSED(len);
retVal = xcpPtr->XcpCopyCalPage(sourceSegm, sourcePage, destSegm, destPage, &error);
if(retVal == E_OK) {
RETURN_SUCCESS();
} else {
RETURN_ERROR(error);
}
}
Std_ReturnType Xcp_CmdGetPagProcessorInfo(uint8 pid, uint8* data, PduLengthType len)
{
uint8 maxSegment;
Xcp_ErrorType error;
Std_ReturnType retVal;
DEBUG(DEBUG_HIGH, "Received GetPagProcessorInfo\n");
XCP_UNUSED(pid);
XCP_UNUSED(data);/*lint !e920 Misra 2012 1.3 cast from pointer to void */
XCP_UNUSED(len);
retVal = xcpPtr->XcpGetPagProcessorInfo(&maxSegment, &error);
if(retVal == E_OK) {
FIFO_GET_WRITE(Xcp_FifoTxCto, e) {
FIFO_ADD_U8 (e, XCP_PID_RES);
FIFO_ADD_U8 (e, maxSegment);
FIFO_ADD_U8 (e, 0 << 0 /* FREEZE_SUPPORTED */);
}
return E_OK; /*lint !e904 allow multiple exit */
} else {
RETURN_ERROR(error);
}
}
Std_ReturnType Xcp_CmdGetSegmentInfo(uint8 pid, uint8* data, PduLengthType len)
{
uint8 mode = GET_UINT8(data, 0);
uint8 segmentNumber = GET_UINT8(data, 1);
Xcp_ErrorType error;
DEBUG(DEBUG_HIGH, "Received GetSegmentInfo(%u, %u, %u, %u)\n", mode, segm, info, mapi);
XCP_UNUSED(pid);
XCP_UNUSED(len);
if(mode == 0) {
uint8 segmentInfo = GET_UINT8(data, 2);
uint32 basicInfo;
if(E_OK == xcpPtr->XcpGetSegmentInfo_GetBasicAddress(segmentNumber,segmentInfo,&basicInfo,&error)) {
FIFO_GET_WRITE(Xcp_FifoTxCto, e) {
FIFO_ADD_U8 (e, XCP_PID_RES);
FIFO_ADD_U8 (e, 0); /* reserved */
FIFO_ADD_U8 (e, 0); /* reserved */
FIFO_ADD_U8 (e, 0); /* reserved */
FIFO_ADD_U32(e, basicInfo);
}
} else {
RETURN_ERROR(error);
}
} else if (mode == 1) {
Xcp_SegmentStandardInfoReturnType responseData;
if(E_OK == xcpPtr->XcpGetSegmentInfo_GetStandardInfo(segmentNumber,&responseData,&error)) {
FIFO_GET_WRITE(Xcp_FifoTxCto, e) {
FIFO_ADD_U8 (e, XCP_PID_RES);
FIFO_ADD_U8 (e, responseData.maxPages);
FIFO_ADD_U8 (e, responseData.addressExtension);
FIFO_ADD_U8 (e, responseData.maxMapping);
FIFO_ADD_U8 (e, responseData.compressionMethod);
FIFO_ADD_U8 (e, responseData.encryptionMethod);
}
} else {
RETURN_ERROR(error);
}
} else if (mode == 2) {
uint8 segmentInfo = GET_UINT8(data, 2);
uint32 mappingInfo;
if(E_OK == xcpPtr->XcpGetSegmentInfo_GetAddressMapping(segmentNumber,segmentInfo, &mappingInfo,&error)) {
FIFO_GET_WRITE(Xcp_FifoTxCto, e) {
FIFO_ADD_U8 (e, XCP_PID_RES);
FIFO_ADD_U8 (e, 0); /* reserved */
FIFO_ADD_U8 (e, 0); /* reserved */
FIFO_ADD_U8 (e, 0); /* reserved */
FIFO_ADD_U32(e, mappingInfo);
}
} else {
RETURN_ERROR(error);
}
} else {
RETURN_ERROR(XCP_ERR_CMD_SYNTAX, "Unsupported");
}
return E_OK;
}
Std_ReturnType Xcp_CmdGetPageInfo(uint8 pid, uint8* data, PduLengthType len)
{
uint8 segmentNumber = GET_UINT8(data, 1);
uint8 pageNumber = GET_UINT8(data, 2);
uint8 pageProperties;
uint8 initSegment;
Xcp_ErrorType error;
Std_ReturnType retVal;
DEBUG(DEBUG_HIGH, "Received GetPageInfo(%u, %u)\n", segmentNumber, pageNumber);
XCP_UNUSED(pid);
XCP_UNUSED(len);
retVal = xcpPtr->XcpGetPageInfo(segmentNumber,pageNumber,&pageProperties,&initSegment,&error);
if(retVal == E_OK) {
FIFO_GET_WRITE(Xcp_FifoTxCto, e) {
FIFO_ADD_U8 (e, XCP_PID_RES);
FIFO_ADD_U8 (e, pageProperties);
FIFO_ADD_U8 (e, initSegment);
}
return E_OK; /*lint !e904 allow multiple exit */
} else {
RETURN_ERROR(error);
}
}
Std_ReturnType Xcp_CmdSetSegmentMode(uint8 pid, uint8* data, PduLengthType len)
{
uint8 mode = GET_UINT8(data, 0);
uint8 segmentNumber = GET_UINT8(data, 1);
Xcp_ErrorType error;
Std_ReturnType retVal;
DEBUG(DEBUG_HIGH, "Received SetSegmentMode(%u, %u)\n", mode, segmentNumber);
XCP_UNUSED(pid);
XCP_UNUSED(len);
retVal = xcpPtr->XcpSetSegmentMode(mode, segmentNumber, &error);
if(retVal == E_OK) {
RETURN_SUCCESS();
} else {
RETURN_ERROR(error);
}
}
Std_ReturnType Xcp_CmdGetSegmentMode(uint8 pid, uint8* data, PduLengthType len)
{
uint8 segmentNumber = GET_UINT8(data, 1);
uint8 mode;
Xcp_ErrorType error;
Std_ReturnType retVal;
DEBUG(DEBUG_HIGH, "Received GetSegmentMode(%u)\n", segmentNumber);
XCP_UNUSED(pid);
XCP_UNUSED(len);
retVal = xcpPtr->XcpGetSegmentMode(segmentNumber,&mode, &error);
if(retVal == E_OK) {
FIFO_GET_WRITE(Xcp_FifoTxCto, e) {
FIFO_ADD_U8 (e, XCP_PID_RES);
FIFO_ADD_U8 (e, 0); /*reserved*/
FIFO_ADD_U8 (e, mode);
}
return E_OK; /*lint !e904 allow multiple exit */
} else {
RETURN_ERROR(error);
}
}
#endif /*XCP_FEATURE_CALPAG == STD_ON*/
|
2301_81045437/classic-platform
|
communication/Xcp/src/Xcp_OnlineCalibration.c
|
C
|
unknown
| 8,443
|
/*-------------------------------- Arctic Core ------------------------------
* Copyright (C) 2013, ArcCore AB, Sweden, www.arccore.com.
* Contact: <contact@arccore.com>
*
* You may ONLY use this file:
* 1)if you have a valid commercial ArcCore license and then in accordance with
* the terms contained in the written license agreement between you and ArcCore,
* or alternatively
* 2)if you follow the terms found in GNU General Public License version 2 as
* published by the Free Software Foundation and appearing in the file
* LICENSE.GPL included in the packaging of this file or here
* <http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt>
*-------------------------------- Arctic Core -----------------------------*/
/** @reqSettings DEFAULT_SPECIFICATION_REVISION=4.1.3 */
#include "Xcp_Internal.h"
#if(XCP_FEATURE_PGM)
typedef struct {
int started;
uint8 format;
uint32 rem;
uint32 len;
} XcpProgramType;
XcpProgramType Xcp_Program;
Std_ReturnType Xcp_CmdProgramStart(uint8 pid, uint8* data, PduLengthType len)
{
uint8 commModePgm = 0x00u
#if (XCP_FEATURE_BLOCKMODE == STD_ON)
| 1 << 0 /* MASTER_BLOCK_MODE */
| 1 << 6 /* SLAVE_BLOCK_MODE */
#endif
| 0 << 1; /* INTERLEAVED_MODE */
DEBUG(DEBUG_HIGH, "Received program_start\n");
FIFO_GET_WRITE(Xcp_FifoTx, e) {
SET_UINT8 (e->data, 0, XCP_PID_RES);
SET_UINT8 (e->data, 1, 0); /* RESERVED */
SET_UINT8 (e->data, 2, commModePgm);
SET_UINT8 (e->data, 3, XCP_MAX_CTO); /* MAX_CTO_PGM */
SET_UINT8 (e->data, 4, XCP_MAX_RXTX_QUEUE-1); /* MAX_BS_PGM */
SET_UINT8 (e->data, 5, 0); /* MIN_ST_PGM [100 microseconds] */
SET_UINT8 (e->data, 6, XCP_MAX_RXTX_QUEUE-1); /* QUEUE_SIZE_PGM */
e->len = 7;
}
Xcp_Program.started = 1;
XCP_UNUSED(pid);
XCP_UNUSED(data);
XCP_UNUSED(len);
return E_OK;
}
Std_ReturnType Xcp_CmdProgramClear(uint8 pid, uint8* data, PduLengthType len)
{
uint8 mode = GET_UINT8 (data, 0);
uint32 range = GET_UINT32(data, 3);
DEBUG(DEBUG_HIGH, "Received program_clear %u, %u\n", (unsigned)mode, (unsigned)range);
if(!Xcp_Program.started) {
RETURN_ERROR(XCP_ERR_GENERIC, "Xcp_CmdProgramClear - programming not started\n");
}
if(mode == 0x01) { /* functional access mode */
if(range & 0x01) { /* clear all calibration data areas */
}
if(range & 0x02) { /* clear all code areas, except boot */
}
if(range & 0x04) { /* clear all code NVRAM areas */
}
}
if(mode == 0x00) { /* absolute access mode */
}
XCP_UNUSED(pid);
XCP_UNUSED(len);
RETURN_ERROR(XCP_ERR_CMD_UNKNOWN, "Xcp_CmdProgramClear - mode implemented\n");
}
Std_ReturnType Xcp_CmdProgram(uint8 pid, uint8* data, PduLengthType len)
{
unsigned rem = GET_UINT8(data, 0) * XCP_ELEMENT_SIZE;
unsigned off = XCP_ELEMENT_OFFSET(2) + 1;
DEBUG(DEBUG_HIGH, "Received program %d, %d\n", pid, len);
if(!Xcp_Program.started) {
RETURN_ERROR(XCP_ERR_GENERIC, "Xcp_CmdProgramClear - programming not started\n");
}
#if(!XCP_FEATURE_BLOCKMODE)
if(rem + off > len) {
RETURN_ERROR(XCP_ERR_OUT_OF_RANGE, "Xcp_CmdProgram - Invalid length (%d, %d, %d)\n", rem, off, len);
}
#endif
if(pid == XCP_PID_CMD_PGM_PROGRAM) {
Xcp_Program.len = rem;
Xcp_Program.rem = rem;
}
/* check for sequence error */
if(Xcp_Program.rem != rem) {
DEBUG(DEBUG_HIGH, "Xcp_CmdProgram - Invalid next state (%u, %u)\n", rem, (unsigned)Xcp_Program.rem);
FIFO_GET_WRITE(Xcp_FifoTx, e) {
SET_UINT8 (e->data, 0, XCP_PID_ERR);
SET_UINT8 (e->data, 1, XCP_ERR_SEQUENCE);
SET_UINT8 (e->data, 2, Xcp_Program.rem / XCP_ELEMENT_SIZE);
e->len = 3;
}
return E_OK;
}
/* write what we got this packet */
if(rem > len - off) {
rem = len - off;
}
/* NOT IMPLEMENTED - write actual data to flash */
Xcp_Program.rem -= rem;
if(Xcp_Program.rem)
return E_OK;
RETURN_SUCCESS();
}
Std_ReturnType Xcp_CmdProgramReset(uint8 pid, uint8* data, PduLengthType len)
{
XCP_UNUSED(pid);
XCP_UNUSED(data);
XCP_UNUSED(len);
if(!Xcp_Program.started) {
RETURN_ERROR(XCP_ERR_GENERIC, "Xcp_CmdProgramClear - programming not started\n");
}
RETURN_ERROR(XCP_ERR_CMD_UNKNOWN, "Xcp_CmdProgramReset - not implemented\n");
}
typedef enum {
XCP_PGM_PROPERTY_ABSOLUTE_MODE = 1 << 0,
XCP_PGM_PROPERTY_FUNCTIONAL_MODE = 1 << 1,
XCP_PGM_PROPERTY_COMPRESSION_SUPPORTED = 1 << 2,
XCP_PGM_PROPERTY_COMPRESSION_REQUIRED = 1 << 3,
XCP_PGM_PROPERTY_ENCRYPTION_SUPPORTED = 1 << 4,
XCP_PGM_PROPERTY_ENCRYPTION_REQUIRED = 1 << 5,
XCP_PGM_PROPERTY_NON_SEQ_PGM_SUPPORTED = 1 << 6,
XCP_PGM_PROPERTY_NON_SEQ_PGM_REQUIRED = 1 << 7,
} Xcp_ProgramPropertiesType;
Std_ReturnType Xcp_CmdProgramInfo(uint8 pid, uint8* data, PduLengthType len)
{
XCP_UNUSED(pid);
XCP_UNUSED(data);
XCP_UNUSED(len);
FIFO_GET_WRITE(Xcp_FifoTx, e) {
FIFO_ADD_U8 (e, XCP_PID_RES);
FIFO_ADD_U8 (e, XCP_PGM_PROPERTY_FUNCTIONAL_MODE
| XCP_PGM_PROPERTY_NON_SEQ_PGM_SUPPORTED); /* PGM_PROPERTIES */
FIFO_ADD_U8 (e, 0); /* MAX_SECTOR */
}
return E_OK;
}
#endif /*XCP_FEATURE_PGM*/
|
2301_81045437/classic-platform
|
communication/Xcp/src/Xcp_Program.c
|
C
|
unknown
| 5,594
|
typedef unsigned char err_t;
typedef unsigned int u32_t;
typedef unsigned short u16_t;
typedef unsigned char u8_t;
typedef void sys_sem_t;
typedef void sys_mutex_t;
typedef size_t mem_size_t;
typedef size_t memp_t;
struct pbuf;
struct netif;
void* mem_malloc(mem_size_t size)
{
__coverity_alloc__(size);
}
void mem_free(void* mem)
{
__coverity_free__(mem);
}
void* memp_malloc(memp_t type)
{
__coverity_alloc_nosize__();
}
void memp_free(memp_t type, void* mem)
{
__coverity_free__(mem);
}
void sys_mutex_lock(sys_mutex_t* mutex)
{
__coverity_exclusive_lock_acquire__(mutex);
}
void sys_mutex_unlock(sys_mutex_t* mutex)
{
__coverity_exclusive_lock_release__(mutex);
}
u32_t sys_arch_sem_wait(sys_sem_t *sem, u32_t timeout)
{
__coverity_recursive_lock_acquire__(sem);
}
void sys_sem_signal(sys_sem_t *sem)
{
__coverity_recursive_lock_release__(sem);
}
err_t ethernet_input(struct pbuf *p, struct netif *inp)
{
__coverity_tainted_string_sink_content__(p);
}
err_t tcpip_input(struct pbuf *p, struct netif *inp)
{
__coverity_tainted_string_sink_content__(p);
}
err_t ip_input(struct pbuf *p, struct netif *inp)
{
__coverity_tainted_string_sink_content__(p);
}
err_t ip4_input(struct pbuf *p, struct netif *inp)
{
__coverity_tainted_string_sink_content__(p);
}
err_t ip6_input(struct pbuf *p, struct netif *inp)
{
__coverity_tainted_string_sink_content__(p);
}
err_t pbuf_take(struct pbuf *buf, const void *dataptr, u16_t len)
{
__coverity_tainted_string_argument__(buf);
__coverity_tainted_data_argument__(buf);
}
err_t pbuf_take_at(struct pbuf *buf, const void *dataptr, u16_t len, u16_t offset)
{
__coverity_tainted_string_argument__(buf);
__coverity_tainted_data_argument__(buf);
}
err_t pbuf_copy(struct pbuf *p_to, struct pbuf *p_from)
{
__coverity_tainted_data_transitive__(p_to, p_from);
}
u16_t pbuf_copy_partial(struct pbuf *p, void *dataptr, u16_t len, u16_t offset)
{
__coverity_tainted_string_argument__(dataptr);
__coverity_tainted_data_argument__(dataptr);
}
u8_t pbuf_get_at(struct pbuf* p, u16_t offset)
{
__coverity_tainted_data_return__();
}
void abort(void)
{
__coverity_panic__();
}
int check_path(char* path, size_t size)
{
if (size) {
__coverity_tainted_data_sanitize__(path);
return 1;
} else {
return 0;
}
}
|
2301_81045437/classic-platform
|
communication/lwip-2.0.3/contrib/Coverity/coverity.c
|
C
|
unknown
| 2,414
|
/** @file
*
* chargen server for lwip
*/
/*
* Copyright (c) 2003 NBS Card Technology, Paramus, NJ.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
* 3. The name of the author may not be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
* SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
* IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
* OF SUCH DAMAGE.
*
* This file is part of the lwIP TCP/IP stack.
*
* Author: David Haas <dhaas@alum.rpi.edu>
*
* Purpose: chargen server for testing and demonstration purposes
*
* This file implements a nice example of handling multiple tcp sockets in a
* server environment. Just call chargen_init() from your application after
* you have initialized lwip and added your network interfaces. Change the
* MAX_SERV option to increase or decrease the number of sessions supported.
*
* chargen will jam as much data as possible into the output socket, so it
* will take up a lot of CPU time. Therefore it will be a good idea to run it
* as the lowest possible priority (just ahead of any idle task).
*
* This is also a good example of how to support multiple sessions in an
* embedded system where you might not have fork().
*/
#include "lwip/opt.h"
#include "lwip/sys.h"
#include "lwip/sockets.h"
#include "lwip/mem.h"
#include <string.h>
#include "chargen.h"
#if LWIP_SOCKET
#define MAX_SERV 5 /* Maximum number of chargen services. Don't need too many */
#define CHARGEN_THREAD_NAME "chargen"
#define CHARGEN_PRIORITY 254 /* Really low priority */
#define CHARGEN_THREAD_STACKSIZE 0
#define SEND_SIZE TCP_SNDLOWAT /* If we only send this much, then when select
says we can send, we know we won't block */
struct charcb {
struct charcb *next;
int socket;
struct sockaddr_storage cliaddr;
socklen_t clilen;
char nextchar;
};
static struct charcb *charcb_list = 0;
/**************************************************************
* void close_chargen(struct charcb *p_charcb)
*
* Close the socket and remove this charcb from the list.
**************************************************************/
static void
close_chargen(struct charcb *p_charcb)
{
struct charcb *p_search_charcb;
/* Either an error or tcp connection closed on other
* end. Close here */
close(p_charcb->socket);
/* Free charcb */
if (charcb_list == p_charcb) {
charcb_list = p_charcb->next;
} else {
for (p_search_charcb = charcb_list; p_search_charcb; p_search_charcb = p_search_charcb->next) {
if (p_search_charcb->next == p_charcb) {
p_search_charcb->next = p_charcb->next;
break;
}
}
}
mem_free(p_charcb);
}
/**************************************************************
* void do_read(struct charcb *p_charcb)
*
* Socket definitely is ready for reading. Read a buffer from the socket and
* discard the data. If no data is read, then the socket is closed and the
* charcb is removed from the list and freed.
**************************************************************/
static int
do_read(struct charcb *p_charcb)
{
char buffer[80];
int readcount;
/* Read some data */
readcount = read(p_charcb->socket, &buffer, 80);
if (readcount <= 0) {
close_chargen(p_charcb);
return -1;
}
return 0;
}
/**************************************************************
* void chargen_thread(void *arg)
*
* chargen task. This server will wait for connections on well
* known TCP port number: 19. For every connection, the server will
* write as much data as possible to the tcp port.
**************************************************************/
static void
chargen_thread(void *arg)
{
int listenfd;
#if LWIP_IPV6
struct sockaddr_in6 chargen_saddr;
#else /* LWIP_IPV6 */
struct sockaddr_in chargen_saddr;
#endif /* LWIP_IPV6 */
fd_set readset;
fd_set writeset;
int i, maxfdp1;
struct charcb *p_charcb;
LWIP_UNUSED_ARG(arg);
memset(&chargen_saddr, 0, sizeof (chargen_saddr));
#if LWIP_IPV6
/* First acquire our socket for listening for connections */
listenfd = socket(AF_INET6, SOCK_STREAM, 0);
chargen_saddr.sin6_family = AF_INET6;
chargen_saddr.sin6_addr = in6addr_any;
chargen_saddr.sin6_port = lwip_htons(19); /* Chargen server port */
#else /* LWIP_IPV6 */
/* First acquire our socket for listening for connections */
listenfd = socket(AF_INET, SOCK_STREAM, 0);
chargen_saddr.sin_family = AF_INET;
chargen_saddr.sin_addr.s_addr = PP_HTONL(INADDR_ANY);
chargen_saddr.sin_port = lwip_htons(19); /* Chargen server port */
#endif /* LWIP_IPV6 */
LWIP_ASSERT("chargen_thread(): Socket create failed.", listenfd >= 0);
if (bind(listenfd, (struct sockaddr *) &chargen_saddr, sizeof (chargen_saddr)) == -1) {
LWIP_ASSERT("chargen_thread(): Socket bind failed.", 0);
}
/* Put socket into listening mode */
if (listen(listenfd, MAX_SERV) == -1) {
LWIP_ASSERT("chargen_thread(): Listen failed.", 0);
}
/* Wait forever for network input: This could be connections or data */
for (;;) {
maxfdp1 = listenfd + 1;
/* Determine what sockets need to be in readset */
FD_ZERO(&readset);
FD_ZERO(&writeset);
FD_SET(listenfd, &readset);
for (p_charcb = charcb_list; p_charcb; p_charcb = p_charcb->next) {
if (maxfdp1 < p_charcb->socket + 1) {
maxfdp1 = p_charcb->socket + 1;
}
FD_SET(p_charcb->socket, &readset);
FD_SET(p_charcb->socket, &writeset);
}
/* Wait for data or a new connection */
i = select(maxfdp1, &readset, &writeset, 0, 0);
if (i == 0) {
continue;
}
/* At least one descriptor is ready */
if (FD_ISSET(listenfd, &readset)) {
/* We have a new connection request!!! */
/* Lets create a new control block */
p_charcb = (struct charcb *) mem_malloc(sizeof (struct charcb));
if (p_charcb) {
p_charcb->socket = accept(listenfd,
(struct sockaddr *) &p_charcb->cliaddr,
&p_charcb->clilen);
if (p_charcb->socket < 0) {
mem_free(p_charcb);
} else {
/* Keep this tecb in our list */
p_charcb->next = charcb_list;
charcb_list = p_charcb;
p_charcb->nextchar = 0x21;
}
} else {
/* No memory to accept connection. Just accept and then close */
int sock;
struct sockaddr cliaddr;
socklen_t clilen;
sock = accept(listenfd, &cliaddr, &clilen);
if (sock >= 0) {
close(sock);
}
}
}
/* Go through list of connected clients and process data */
for (p_charcb = charcb_list; p_charcb; p_charcb = p_charcb->next) {
if (FD_ISSET(p_charcb->socket, &readset)) {
/* This socket is ready for reading. This could be because someone typed
* some characters or it could be because the socket is now closed. Try reading
* some data to see. */
if (do_read(p_charcb) < 0) {
break;
}
}
if (FD_ISSET(p_charcb->socket, &writeset)) {
char line[80];
char setchar = p_charcb->nextchar;
for (i = 0; i < 59; i++) {
line[i] = setchar;
if (++setchar == 0x7f) {
setchar = 0x21;
}
}
line[i] = 0;
strcat(line, "\n\r");
if (write(p_charcb->socket, line, strlen(line)) < 0) {
close_chargen(p_charcb);
break;
}
if (++p_charcb->nextchar == 0x7f) {
p_charcb->nextchar = 0x21;
}
}
}
}
}
/**************************************************************
* void chargen_init(void)
*
* This function initializes the chargen service. This function
* may only be called either before or after tasking has started.
**************************************************************/
void
chargen_init(void)
{
sys_thread_new(CHARGEN_THREAD_NAME, chargen_thread, 0, CHARGEN_THREAD_STACKSIZE, CHARGEN_PRIORITY);
}
#endif /* LWIP_SOCKET */
|
2301_81045437/classic-platform
|
communication/lwip-2.0.3/contrib/apps/chargen/chargen.c
|
C
|
unknown
| 9,506
|
#ifndef LWIP_CHARGEN_H
#define LWIP_CHARGEN_H
#include "lwip/opt.h"
#if LWIP_SOCKET
void chargen_init(void);
#endif /* LWIP_SOCKET */
#endif /* LWIP_CHARGEN_H */
|
2301_81045437/classic-platform
|
communication/lwip-2.0.3/contrib/apps/chargen/chargen.h
|
C
|
unknown
| 179
|
#include "lwip/opt.h"
#include "lwip/arch.h"
#include "lwip/api.h"
#include "httpserver-netconn.h"
#if LWIP_NETCONN
#ifndef HTTPD_DEBUG
#define HTTPD_DEBUG LWIP_DBG_OFF
#endif
static const char http_html_hdr[] = "HTTP/1.1 200 OK\r\nContent-type: text/html\r\n\r\n";
static const char http_index_html[] = "<html><head><title>Congrats!</title></head><body><h1>Welcome to our lwIP HTTP server!</h1><p>This is a small test page, served by httpserver-netconn.</body></html>";
/** Serve one HTTP connection accepted in the http thread */
static void
http_server_netconn_serve(struct netconn *conn)
{
struct netbuf *inbuf;
char *buf;
u16_t buflen;
err_t err;
/* Read the data from the port, blocking if nothing yet there.
We assume the request (the part we care about) is in one netbuf */
err = netconn_recv(conn, &inbuf);
if (err == ERR_OK) {
netbuf_data(inbuf, (void**)&buf, &buflen);
/* Is this an HTTP GET command? (only check the first 5 chars, since
there are other formats for GET, and we're keeping it very simple )*/
if (buflen>=5 &&
buf[0]=='G' &&
buf[1]=='E' &&
buf[2]=='T' &&
buf[3]==' ' &&
buf[4]=='/' ) {
/* Send the HTML header
* subtract 1 from the size, since we dont send the \0 in the string
* NETCONN_NOCOPY: our data is const static, so no need to copy it
*/
netconn_write(conn, http_html_hdr, sizeof(http_html_hdr)-1, NETCONN_NOCOPY);
/* Send our HTML page */
netconn_write(conn, http_index_html, sizeof(http_index_html)-1, NETCONN_NOCOPY);
}
}
/* Close the connection (server closes in HTTP) */
netconn_close(conn);
/* Delete the buffer (netconn_recv gives us ownership,
so we have to make sure to deallocate the buffer) */
netbuf_delete(inbuf);
}
/** The main function, never returns! */
static void
http_server_netconn_thread(void *arg)
{
struct netconn *conn, *newconn;
err_t err;
LWIP_UNUSED_ARG(arg);
/* Create a new TCP connection handle */
/* Bind to port 80 (HTTP) with default IP address */
#if LWIP_IPV6
conn = netconn_new(NETCONN_TCP_IPV6);
netconn_bind(conn, IP6_ADDR_ANY, 80);
#else /* LWIP_IPV6 */
conn = netconn_new(NETCONN_TCP);
netconn_bind(conn, IP_ADDR_ANY, 80);
#endif /* LWIP_IPV6 */
LWIP_ERROR("http_server: invalid conn", (conn != NULL), return;);
/* Put the connection into LISTEN state */
netconn_listen(conn);
do {
err = netconn_accept(conn, &newconn);
if (err == ERR_OK) {
http_server_netconn_serve(newconn);
netconn_delete(newconn);
}
} while(err == ERR_OK);
LWIP_DEBUGF(HTTPD_DEBUG,
("http_server_netconn_thread: netconn_accept received error %d, shutting down",
err));
netconn_close(conn);
netconn_delete(conn);
}
/** Initialize the HTTP server (start its thread) */
void
http_server_netconn_init(void)
{
sys_thread_new("http_server_netconn", http_server_netconn_thread, NULL, DEFAULT_THREAD_STACKSIZE, DEFAULT_THREAD_PRIO);
}
#endif /* LWIP_NETCONN*/
|
2301_81045437/classic-platform
|
communication/lwip-2.0.3/contrib/apps/httpserver/httpserver-netconn.c
|
C
|
unknown
| 3,172
|
#ifndef LWIP_HTTPSERVER_NETCONN_H
#define LWIP_HTTPSERVER_NETCONN_H
void http_server_netconn_init(void);
#endif /* LWIP_HTTPSERVER_NETCONN_H */
|
2301_81045437/classic-platform
|
communication/lwip-2.0.3/contrib/apps/httpserver/httpserver-netconn.h
|
C
|
unknown
| 152
|
#include "netio.h"
#include "lwip/opt.h"
#include "lwip/tcp.h"
/* See http://www.nwlab.net/art/netio/netio.html to get the netio tool */
#if LWIP_TCP
static err_t
netio_recv(void *arg, struct tcp_pcb *pcb, struct pbuf *p, err_t err)
{
LWIP_UNUSED_ARG(arg);
if (err == ERR_OK && p != NULL) {
tcp_recved(pcb, p->tot_len);
pbuf_free(p);
} else {
pbuf_free(p);
}
if (err == ERR_OK && p == NULL) {
tcp_arg(pcb, NULL);
tcp_sent(pcb, NULL);
tcp_recv(pcb, NULL);
tcp_close(pcb);
}
return ERR_OK;
}
static err_t
netio_accept(void *arg, struct tcp_pcb *pcb, err_t err)
{
LWIP_UNUSED_ARG(arg);
LWIP_UNUSED_ARG(err);
if (pcb != NULL) {
tcp_arg(pcb, NULL);
tcp_sent(pcb, NULL);
tcp_recv(pcb, netio_recv);
}
return ERR_OK;
}
void
netio_init(void)
{
struct tcp_pcb *pcb;
pcb = tcp_new_ip_type(IPADDR_TYPE_ANY);
tcp_bind(pcb, IP_ANY_TYPE, 18767);
pcb = tcp_listen(pcb);
tcp_accept(pcb, netio_accept);
}
#endif /* LWIP_TCP */
|
2301_81045437/classic-platform
|
communication/lwip-2.0.3/contrib/apps/netio/netio.c
|
C
|
unknown
| 1,048
|
#ifndef LWIP_NETIO_H
#define LWIP_NETIO_H
void netio_init(void);
#endif /* LWIP_NETIO_H */
|
2301_81045437/classic-platform
|
communication/lwip-2.0.3/contrib/apps/netio/netio.h
|
C
|
unknown
| 99
|
/**
* @file
* Ping sender module
*
*/
/*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
* 3. The name of the author may not be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
* SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
* IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
* OF SUCH DAMAGE.
*
* This file is part of the lwIP TCP/IP stack.
*
*/
/**
* This is an example of a "ping" sender (with raw API and socket API).
* It can be used as a start point to maintain opened a network connection, or
* like a network "watchdog" for your device.
*
*/
#include "lwip/opt.h"
#if LWIP_IPV4 && LWIP_RAW /* don't build if not configured for use in lwipopts.h */
#include "ping.h"
#include "lwip/mem.h"
#include "lwip/raw.h"
#include "lwip/icmp.h"
#include "lwip/netif.h"
#include "lwip/sys.h"
#include "lwip/timeouts.h"
#include "lwip/inet_chksum.h"
#if PING_USE_SOCKETS
#include "lwip/sockets.h"
#include "lwip/inet.h"
#endif /* PING_USE_SOCKETS */
/**
* PING_DEBUG: Enable debugging for PING.
*/
#ifndef PING_DEBUG
#define PING_DEBUG LWIP_DBG_ON
#endif
/** ping target - should be an "ip4_addr_t" */
#ifndef PING_TARGET
#define PING_TARGET (netif_default ? *netif_ip4_gw(netif_default) : (*IP4_ADDR_ANY4))
#endif
/** ping receive timeout - in milliseconds */
#ifndef PING_RCV_TIMEO
#define PING_RCV_TIMEO 1000
#endif
/** ping delay - in milliseconds */
#ifndef PING_DELAY
#define PING_DELAY 1000
#endif
/** ping identifier - must fit on a u16_t */
#ifndef PING_ID
#define PING_ID 0xAFAF
#endif
/** ping additional data size to include in the packet */
#ifndef PING_DATA_SIZE
#define PING_DATA_SIZE 32
#endif
/** ping result action - no default action */
#ifndef PING_RESULT
#define PING_RESULT(ping_ok)
#endif
/* ping variables */
static u16_t ping_seq_num;
static u32_t ping_time;
#if !PING_USE_SOCKETS
static struct raw_pcb *ping_pcb;
#endif /* PING_USE_SOCKETS */
/** Prepare a echo ICMP request */
static void
ping_prepare_echo( struct icmp_echo_hdr *iecho, u16_t len)
{
size_t i;
size_t data_len = len - sizeof(struct icmp_echo_hdr);
ICMPH_TYPE_SET(iecho, ICMP_ECHO);
ICMPH_CODE_SET(iecho, 0);
iecho->chksum = 0;
iecho->id = PING_ID;
iecho->seqno = lwip_htons(++ping_seq_num);
/* fill the additional data buffer with some data */
for(i = 0; i < data_len; i++) {
((char*)iecho)[sizeof(struct icmp_echo_hdr) + i] = (char)i;
}
iecho->chksum = inet_chksum(iecho, len);
}
#if PING_USE_SOCKETS
/* Ping using the socket ip */
static err_t
ping_send(int s, ip_addr_t *addr)
{
int err;
struct icmp_echo_hdr *iecho;
struct sockaddr_in to;
size_t ping_size = sizeof(struct icmp_echo_hdr) + PING_DATA_SIZE;
LWIP_ASSERT("ping_size is too big", ping_size <= 0xffff);
LWIP_ASSERT("ping: expect IPv4 address", !IP_IS_V6(addr));
iecho = (struct icmp_echo_hdr *)mem_malloc((mem_size_t)ping_size);
if (!iecho) {
return ERR_MEM;
}
ping_prepare_echo(iecho, (u16_t)ping_size);
to.sin_len = sizeof(to);
to.sin_family = AF_INET;
inet_addr_from_ipaddr(&to.sin_addr, ip_2_ip4(addr));
err = lwip_sendto(s, iecho, ping_size, 0, (struct sockaddr*)&to, sizeof(to));
mem_free(iecho);
return (err ? ERR_OK : ERR_VAL);
}
static void
ping_recv(int s)
{
char buf[64];
int len;
struct sockaddr_in from;
struct ip_hdr *iphdr;
struct icmp_echo_hdr *iecho;
int fromlen = sizeof(from);
while((len = lwip_recvfrom(s, buf, sizeof(buf), 0, (struct sockaddr*)&from, (socklen_t*)&fromlen)) > 0) {
if (len >= (int)(sizeof(struct ip_hdr)+sizeof(struct icmp_echo_hdr))) {
if (from.sin_family != AF_INET) {
/* Ping is not IPv4 */
LWIP_DEBUGF( PING_DEBUG, ("ping: invalid sin_family\n"));
} else {
ip4_addr_t fromaddr;
inet_addr_to_ipaddr(&fromaddr, &from.sin_addr);
LWIP_DEBUGF( PING_DEBUG, ("ping: recv "));
ip4_addr_debug_print(PING_DEBUG, &fromaddr);
LWIP_DEBUGF( PING_DEBUG, (" %"U32_F" ms\n", (sys_now() - ping_time)));
iphdr = (struct ip_hdr *)buf;
iecho = (struct icmp_echo_hdr *)(buf + (IPH_HL(iphdr) * 4));
if ((iecho->id == PING_ID) && (iecho->seqno == lwip_htons(ping_seq_num))) {
/* do some ping result processing */
PING_RESULT((ICMPH_TYPE(iecho) == ICMP_ER));
return;
} else {
LWIP_DEBUGF( PING_DEBUG, ("ping: drop\n"));
}
}
}
fromlen = sizeof(from);
}
if (len == 0) {
LWIP_DEBUGF( PING_DEBUG, ("ping: recv - %"U32_F" ms - timeout\n", (sys_now()-ping_time)));
}
/* do some ping result processing */
PING_RESULT(0);
}
static void
ping_thread(void *arg)
{
int s;
int ret;
ip_addr_t ping_target;
#if LWIP_SO_SNDRCVTIMEO_NONSTANDARD
int timeout = PING_RCV_TIMEO;
#else
struct timeval timeout;
timeout.tv_sec = PING_RCV_TIMEO/1000;
timeout.tv_usec = (PING_RCV_TIMEO%1000)*1000;
#endif
LWIP_UNUSED_ARG(arg);
if ((s = lwip_socket(AF_INET, SOCK_RAW, IP_PROTO_ICMP)) < 0) {
return;
}
ret = lwip_setsockopt(s, SOL_SOCKET, SO_RCVTIMEO, &timeout, sizeof(timeout));
LWIP_ASSERT("setting receive timeout failed", ret == 0);
while (1) {
ip_addr_copy_from_ip4(ping_target, PING_TARGET);
if (ping_send(s, &ping_target) == ERR_OK) {
LWIP_DEBUGF( PING_DEBUG, ("ping: send "));
ip_addr_debug_print(PING_DEBUG, &ping_target);
LWIP_DEBUGF( PING_DEBUG, ("\n"));
ping_time = sys_now();
ping_recv(s);
} else {
LWIP_DEBUGF( PING_DEBUG, ("ping: send "));
ip_addr_debug_print(PING_DEBUG, &ping_target);
LWIP_DEBUGF( PING_DEBUG, (" - error\n"));
}
sys_msleep(PING_DELAY);
}
}
#else /* PING_USE_SOCKETS */
/* Ping using the raw ip */
static u8_t
ping_recv(void *arg, struct raw_pcb *pcb, struct pbuf *p, const ip_addr_t *addr)
{
struct icmp_echo_hdr *iecho;
LWIP_UNUSED_ARG(arg);
LWIP_UNUSED_ARG(pcb);
LWIP_UNUSED_ARG(addr);
LWIP_ASSERT("p != NULL", p != NULL);
if ((p->tot_len >= (PBUF_IP_HLEN + sizeof(struct icmp_echo_hdr))) &&
pbuf_header(p, -PBUF_IP_HLEN) == 0) {
iecho = (struct icmp_echo_hdr *)p->payload;
if ((iecho->id == PING_ID) && (iecho->seqno == lwip_htons(ping_seq_num))) {
LWIP_DEBUGF( PING_DEBUG, ("ping: recv "));
ip_addr_debug_print(PING_DEBUG, addr);
LWIP_DEBUGF( PING_DEBUG, (" %"U32_F" ms\n", (sys_now()-ping_time)));
/* do some ping result processing */
PING_RESULT(1);
pbuf_free(p);
return 1; /* eat the packet */
}
/* not eaten, restore original packet */
pbuf_header(p, PBUF_IP_HLEN);
}
return 0; /* don't eat the packet */
}
static void
ping_send(struct raw_pcb *raw, ip_addr_t *addr)
{
struct pbuf *p;
struct icmp_echo_hdr *iecho;
size_t ping_size = sizeof(struct icmp_echo_hdr) + PING_DATA_SIZE;
LWIP_DEBUGF( PING_DEBUG, ("ping: send "));
ip_addr_debug_print(PING_DEBUG, addr);
LWIP_DEBUGF( PING_DEBUG, ("\n"));
LWIP_ASSERT("ping_size <= 0xffff", ping_size <= 0xffff);
p = pbuf_alloc(PBUF_IP, (u16_t)ping_size, PBUF_RAM);
if (!p) {
return;
}
if ((p->len == p->tot_len) && (p->next == NULL)) {
iecho = (struct icmp_echo_hdr *)p->payload;
ping_prepare_echo(iecho, (u16_t)ping_size);
raw_sendto(raw, p, addr);
ping_time = sys_now();
}
pbuf_free(p);
}
static void
ping_timeout(void *arg)
{
struct raw_pcb *pcb = (struct raw_pcb*)arg;
ip_addr_t ping_target;
LWIP_ASSERT("ping_timeout: no pcb given!", pcb != NULL);
ip_addr_copy_from_ip4(ping_target, PING_TARGET);
ping_send(pcb, &ping_target);
sys_timeout(PING_DELAY, ping_timeout, pcb);
}
static void
ping_raw_init(void)
{
ping_pcb = raw_new(IP_PROTO_ICMP);
LWIP_ASSERT("ping_pcb != NULL", ping_pcb != NULL);
raw_recv(ping_pcb, ping_recv, NULL);
raw_bind(ping_pcb, IP_ADDR_ANY);
sys_timeout(PING_DELAY, ping_timeout, ping_pcb);
}
void
ping_send_now(void)
{
ip_addr_t ping_target;
LWIP_ASSERT("ping_pcb != NULL", ping_pcb != NULL);
ip_addr_copy_from_ip4(ping_target, PING_TARGET);
ping_send(ping_pcb, &ping_target);
}
#endif /* PING_USE_SOCKETS */
void
ping_init(void)
{
#if PING_USE_SOCKETS
sys_thread_new("ping_thread", ping_thread, NULL, DEFAULT_THREAD_STACKSIZE, DEFAULT_THREAD_PRIO);
#else /* PING_USE_SOCKETS */
ping_raw_init();
#endif /* PING_USE_SOCKETS */
}
#endif /* LWIP_IPV4 && LWIP_RAW */
|
2301_81045437/classic-platform
|
communication/lwip-2.0.3/contrib/apps/ping/ping.c
|
C
|
unknown
| 9,837
|
#ifndef LWIP_PING_H
#define LWIP_PING_H
/**
* PING_USE_SOCKETS: Set to 1 to use sockets, otherwise the raw api is used
*/
#ifndef PING_USE_SOCKETS
#define PING_USE_SOCKETS LWIP_SOCKET
#endif
void ping_init(void);
#if !PING_USE_SOCKETS
void ping_send_now(void);
#endif /* !PING_USE_SOCKETS */
#endif /* LWIP_PING_H */
|
2301_81045437/classic-platform
|
communication/lwip-2.0.3/contrib/apps/ping/ping.h
|
C
|
unknown
| 345
|
/**
* @file
* RTP client/server module
*
*/
/*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
* 3. The name of the author may not be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
* SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
* IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
* OF SUCH DAMAGE.
*
* This file is part of the lwIP TCP/IP stack.
*
*/
#include "lwip/opt.h"
#if LWIP_SOCKET && LWIP_IGMP /* don't build if not configured for use in lwipopts.h */
#include "lwip/sys.h"
#include "lwip/sockets.h"
#include "rtp.h"
#include "rtpdata.h"
#include <string.h>
/** This is an example of a "RTP" client/server based on a MPEG4 bitstream (with socket API).
*/
/**
* RTP_DEBUG: Enable debugging for RTP.
*/
#ifndef RTP_DEBUG
#define RTP_DEBUG LWIP_DBG_ON
#endif
/** RTP stream port */
#ifndef RTP_STREAM_PORT
#define RTP_STREAM_PORT 4000
#endif
/** RTP stream multicast address as IPv4 address in "u32_t" format */
#ifndef RTP_STREAM_ADDRESS
#define RTP_STREAM_ADDRESS inet_addr("232.0.0.0")
#endif
/** RTP send delay - in milliseconds */
#ifndef RTP_SEND_DELAY
#define RTP_SEND_DELAY 40
#endif
/** RTP receive timeout - in milliseconds */
#ifndef RTP_RECV_TIMEOUT
#define RTP_RECV_TIMEOUT 2000
#endif
/** RTP stats display period - in received packets */
#ifndef RTP_RECV_STATS
#define RTP_RECV_STATS 50
#endif
/** RTP macro to let the application process the data */
#ifndef RTP_RECV_PROCESSING
#define RTP_RECV_PROCESSING(p,s)
#endif
/** RTP packet/payload size */
#define RTP_PACKET_SIZE 1500
#define RTP_PAYLOAD_SIZE 1024
/** RTP header constants */
#define RTP_VERSION 0x80
#define RTP_TIMESTAMP_INCREMENT 3600
#define RTP_SSRC 0
#define RTP_PAYLOADTYPE 96
#define RTP_MARKER_MASK 0x80
/** RTP message header */
#ifdef PACK_STRUCT_USE_INCLUDES
# include "arch/bpstruct.h"
#endif
PACK_STRUCT_BEGIN
struct rtp_hdr {
PACK_STRUCT_FLD_8(u8_t version);
PACK_STRUCT_FLD_8(u8_t payloadtype);
PACK_STRUCT_FIELD(u16_t seqNum);
PACK_STRUCT_FIELD(u32_t timestamp);
PACK_STRUCT_FIELD(u32_t ssrc);
} PACK_STRUCT_STRUCT;
PACK_STRUCT_END
#ifdef PACK_STRUCT_USE_INCLUDES
# include "arch/epstruct.h"
#endif
/** RTP packets */
static u8_t rtp_send_packet[RTP_PACKET_SIZE];
static u8_t rtp_recv_packet[RTP_PACKET_SIZE];
/**
* RTP send packets
*/
static void
rtp_send_packets( int sock, struct sockaddr_in* to)
{
struct rtp_hdr* rtphdr;
u8_t* rtp_payload;
int rtp_payload_size;
size_t rtp_data_index;
/* prepare RTP packet */
rtphdr = (struct rtp_hdr*)rtp_send_packet;
rtphdr->version = RTP_VERSION;
rtphdr->payloadtype = 0;
rtphdr->ssrc = PP_HTONL(RTP_SSRC);
rtphdr->timestamp = lwip_htonl(lwip_ntohl(rtphdr->timestamp) + RTP_TIMESTAMP_INCREMENT);
/* send RTP stream packets */
rtp_data_index = 0;
do {
rtp_payload = rtp_send_packet+sizeof(struct rtp_hdr);
rtp_payload_size = LWIP_MIN(RTP_PAYLOAD_SIZE, (sizeof(rtp_data) - rtp_data_index));
MEMCPY(rtp_payload, rtp_data + rtp_data_index, rtp_payload_size);
/* set MARKER bit in RTP header on the last packet of an image */
rtphdr->payloadtype = RTP_PAYLOADTYPE | (((rtp_data_index + rtp_payload_size)
>= sizeof(rtp_data)) ? RTP_MARKER_MASK : 0);
/* send RTP stream packet */
if (sendto(sock, rtp_send_packet, sizeof(struct rtp_hdr) + rtp_payload_size,
0, (struct sockaddr *)to, sizeof(struct sockaddr)) >= 0) {
rtphdr->seqNum = lwip_htons(lwip_ntohs(rtphdr->seqNum) + 1);
rtp_data_index += rtp_payload_size;
} else {
LWIP_DEBUGF(RTP_DEBUG, ("rtp_sender: not sendto==%i\n", errno));
}
}while (rtp_data_index < sizeof(rtp_data));
}
/**
* RTP send thread
*/
static void
rtp_send_thread(void *arg)
{
int sock;
struct sockaddr_in local;
struct sockaddr_in to;
u32_t rtp_stream_address;
LWIP_UNUSED_ARG(arg);
/* initialize RTP stream address */
rtp_stream_address = RTP_STREAM_ADDRESS;
/* if we got a valid RTP stream address... */
if (rtp_stream_address != 0) {
/* create new socket */
sock = socket(AF_INET, SOCK_DGRAM, 0);
if (sock >= 0) {
/* prepare local address */
memset(&local, 0, sizeof(local));
local.sin_family = AF_INET;
local.sin_port = PP_HTONS(INADDR_ANY);
local.sin_addr.s_addr = PP_HTONL(INADDR_ANY);
/* bind to local address */
if (bind(sock, (struct sockaddr *)&local, sizeof(local)) == 0) {
/* prepare RTP stream address */
memset(&to, 0, sizeof(to));
to.sin_family = AF_INET;
to.sin_port = PP_HTONS(RTP_STREAM_PORT);
to.sin_addr.s_addr = rtp_stream_address;
/* send RTP packets */
memset(rtp_send_packet, 0, sizeof(rtp_send_packet));
while (1) {
rtp_send_packets( sock, &to);
sys_msleep(RTP_SEND_DELAY);
}
}
/* close the socket */
closesocket(sock);
}
}
}
/**
* RTP recv thread
*/
static void
rtp_recv_thread(void *arg)
{
int sock;
struct sockaddr_in local;
struct sockaddr_in from;
int fromlen;
struct ip_mreq ipmreq;
struct rtp_hdr* rtphdr;
u32_t rtp_stream_address;
int timeout;
size_t result;
int recvrtppackets = 0;
int lostrtppackets = 0;
u16_t lastrtpseq = 0;
LWIP_UNUSED_ARG(arg);
/* initialize RTP stream address */
rtp_stream_address = RTP_STREAM_ADDRESS;
/* if we got a valid RTP stream address... */
if (rtp_stream_address != 0) {
/* create new socket */
sock = socket(AF_INET, SOCK_DGRAM, 0);
if (sock >= 0) {
/* prepare local address */
memset(&local, 0, sizeof(local));
local.sin_family = AF_INET;
local.sin_port = PP_HTONS(RTP_STREAM_PORT);
local.sin_addr.s_addr = PP_HTONL(INADDR_ANY);
/* bind to local address */
if (bind(sock, (struct sockaddr *)&local, sizeof(local)) == 0) {
/* set recv timeout */
timeout = RTP_RECV_TIMEOUT;
setsockopt(sock, SOL_SOCKET, SO_RCVTIMEO, (char *)&timeout, sizeof(timeout));
/* prepare multicast "ip_mreq" struct */
ipmreq.imr_multiaddr.s_addr = rtp_stream_address;
ipmreq.imr_interface.s_addr = PP_HTONL(INADDR_ANY);
/* join multicast group */
if (setsockopt(sock, IPPROTO_IP, IP_ADD_MEMBERSHIP, &ipmreq, sizeof(ipmreq)) == 0) {
/* receive RTP packets */
while(1) {
fromlen = sizeof(from);
result = recvfrom(sock, rtp_recv_packet, sizeof(rtp_recv_packet), 0,
(struct sockaddr *)&from, (socklen_t *)&fromlen);
if (result >= sizeof(struct rtp_hdr)) {
rtphdr = (struct rtp_hdr *)rtp_recv_packet;
recvrtppackets++;
if ((lastrtpseq == 0) || ((lastrtpseq + 1) == lwip_ntohs(rtphdr->seqNum))) {
RTP_RECV_PROCESSING((rtp_recv_packet + sizeof(rtp_hdr)),(result-sizeof(rtp_hdr)));
} else {
lostrtppackets++;
}
lastrtpseq = lwip_ntohs(rtphdr->seqNum);
if ((recvrtppackets % RTP_RECV_STATS) == 0) {
LWIP_DEBUGF(RTP_DEBUG, ("rtp_recv_thread: recv %6i packet(s) / lost %4i packet(s) (%.4f%%)...\n", recvrtppackets, lostrtppackets, (lostrtppackets*100.0)/recvrtppackets));
}
} else {
LWIP_DEBUGF(RTP_DEBUG, ("rtp_recv_thread: recv timeout...\n"));
}
}
/* leave multicast group */
setsockopt(sock, IPPROTO_IP, IP_DROP_MEMBERSHIP, &ipmreq, sizeof(ipmreq));
}
}
/* close the socket */
closesocket(sock);
}
}
}
void
rtp_init(void)
{
sys_thread_new("rtp_send_thread", rtp_send_thread, NULL, DEFAULT_THREAD_STACKSIZE, DEFAULT_THREAD_PRIO);
sys_thread_new("rtp_recv_thread", rtp_recv_thread, NULL, DEFAULT_THREAD_STACKSIZE, DEFAULT_THREAD_PRIO);
}
#endif /* LWIP_SOCKET && LWIP_IGMP */
|
2301_81045437/classic-platform
|
communication/lwip-2.0.3/contrib/apps/rtp/rtp.c
|
C
|
unknown
| 9,667
|
#ifndef LWIP_RTP_H
#define LWIP_RTP_H
#if LWIP_SOCKET && LWIP_IGMP
void rtp_init(void);
#endif /* LWIP_SOCKET && LWIP_IGMP */
#endif /* LWIP_RTP_H */
|
2301_81045437/classic-platform
|
communication/lwip-2.0.3/contrib/apps/rtp/rtp.h
|
C
|
unknown
| 160
|
const unsigned char rtp_data[] = {
0x00, 0x00, 0x01, 0xb0, 0xf5, 0x00, 0x00, 0x01,
0xb5, 0x09, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00,
0x01, 0x20, 0x00, 0x86, 0x84, 0x00, 0x67, 0x0c,
0x2c, 0x10, 0x90, 0x51, 0x8f, 0x00, 0x00, 0x01,
0xb2, 0x44, 0x69, 0x76, 0x58, 0x35, 0x30, 0x33,
0x62, 0x31, 0x33, 0x39, 0x33, 0x70, 0x00, 0x00,
0x01, 0xb2, 0x58, 0x76, 0x69, 0x44, 0x30, 0x30,
0x33, 0x39, 0x00, 0x00, 0x01, 0xb6, 0x18, 0x60,
0xab, 0x94, 0x03, 0xc0, 0xca, 0xc0, 0x3e, 0xd0,
0x78, 0x4f, 0xf9, 0x44, 0x91, 0xe9, 0xfa, 0xc9,
0xfe, 0xa1, 0xa4, 0xc1, 0x66, 0x03, 0x2e, 0x39,
0x0c, 0x7e, 0x0e, 0xaa, 0x02, 0x92, 0xf8, 0xd5,
0xec, 0xe2, 0x35, 0xb9, 0x35, 0x0c, 0xb3, 0x82,
0xa6, 0xad, 0xd0, 0xd1, 0xca, 0xb8, 0xe8, 0x10,
0x55, 0x78, 0x03, 0xc0, 0x38, 0x15, 0xba, 0xce,
0xe2, 0xea, 0x00, 0xc3, 0x60, 0xb1, 0x70, 0xf4,
0x14, 0x6c, 0x35, 0x4d, 0xe8, 0x5a, 0x1e, 0x58,
0xdf, 0x03, 0x01, 0xfd, 0x2a, 0x45, 0x54, 0xca,
0x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xec, 0x35, 0x6e,
0x45, 0xc1, 0x5e, 0x51, 0xd3, 0x67, 0x93, 0x6d,
0xaf, 0xd0, 0xe0, 0x2a, 0xea, 0x6a, 0x1e, 0x03,
0x0c, 0x38, 0xa4, 0x38, 0xea, 0x34, 0x41, 0x99,
0xcb, 0xe0, 0xcd, 0xda, 0xf2, 0xee, 0x86, 0x28,
0x83, 0x38, 0x0b, 0x13, 0xd1, 0x73, 0x1e, 0x4f,
0xb5, 0x18, 0x7d, 0xef, 0xed, 0x09, 0xdf, 0xf7,
0x4a, 0x91, 0xdb, 0x41, 0x84, 0xf7, 0x07, 0x14,
0x15, 0x3b, 0x01, 0xc5, 0x28, 0x41, 0x78, 0x9f,
0xf6, 0x92, 0xce, 0x06, 0xe0, 0xb9, 0x9d, 0xa0,
0xee, 0xf0, 0x25, 0xa9, 0xd4, 0xe0, 0x71, 0xb4,
0x66, 0x0c, 0x11, 0x47, 0x01, 0x89, 0x34, 0x62,
0x11, 0x60, 0x27, 0xa0, 0xfb, 0x1f, 0xfe, 0xd1,
0x50, 0x6e, 0x0e, 0x23, 0xc3, 0xd8, 0x0e, 0xe8,
0x53, 0xa7, 0x94, 0x03, 0x12, 0x41, 0x9a, 0x90,
0x97, 0xce, 0x87, 0x0d, 0x42, 0x9d, 0x07, 0xce,
0xff, 0xef, 0x4e, 0x07, 0x1a, 0x31, 0x08, 0x92,
0x98, 0x0c, 0x49, 0x46, 0x74, 0x22, 0x2a, 0xf1,
0x01, 0x51, 0x48, 0x26, 0xe9, 0xf5, 0xcd, 0xb0,
0x0c, 0x2e, 0xa1, 0x3d, 0x29, 0x05, 0x4f, 0xa0,
0x12, 0x06, 0x08, 0x9c, 0x94, 0x08, 0x60, 0xce,
0xd0, 0x96, 0x81, 0x81, 0x18, 0x62, 0x03, 0xcc,
0xba, 0x15, 0xd6, 0x91, 0x11, 0x14, 0x7e, 0xb2,
0x7e, 0xd4, 0x56, 0x74, 0x37, 0xdc, 0x82, 0xfb,
0x21, 0xa1, 0x93, 0x91, 0x60, 0x3d, 0xcb, 0x28,
0x4b, 0x52, 0xe9, 0x26, 0x4a, 0x0c, 0x32, 0xca,
0x31, 0xab, 0x10, 0x19, 0x6e, 0x76, 0x50, 0x1e,
0x7c, 0x89, 0x2f, 0x42, 0x4a, 0x46, 0xf8, 0xb1,
0x5e, 0xdc, 0xbe, 0x81, 0x4a, 0x0c, 0x4e, 0x6a,
0x31, 0x70, 0xd4, 0x17, 0x62, 0x30, 0xf8, 0xbb,
0xaa, 0xba, 0x06, 0x98, 0xf4, 0x05, 0x40, 0x7c,
0x8e, 0x81, 0x22, 0xc7, 0x8b, 0xf2, 0x67, 0x49,
0x64, 0x58, 0x1c, 0xb8, 0xa0, 0x6d, 0xb9, 0xea,
0x5b, 0x11, 0x47, 0x18, 0xe7, 0xd0, 0xbc, 0xce,
0xf3, 0x9d, 0x19, 0x10, 0x92, 0x95, 0x45, 0x47,
0x78, 0x87, 0x81, 0x32, 0x6b, 0xc0, 0xe5, 0x7a,
0x79, 0x25, 0x37, 0x0d, 0x05, 0x06, 0x73, 0x39,
0x50, 0x9f, 0x8f, 0x5d, 0x09, 0x24, 0x34, 0x32,
0x18, 0x04, 0x62, 0x9c, 0xe8, 0x1e, 0x06, 0x52,
0x88, 0x1e, 0x26, 0x01, 0x30, 0x36, 0x81, 0x60,
0x63, 0x41, 0x6a, 0x77, 0xa8, 0x42, 0xd4, 0xba,
0x1f, 0x0e, 0x79, 0x06, 0x2d, 0x16, 0x83, 0x00,
0xe3, 0xe6, 0xcb, 0xba, 0x82, 0x4a, 0x27, 0xd7,
0x5e, 0xdc, 0x58, 0x44, 0x19, 0x28, 0x0c, 0xc7,
0x2f, 0x57, 0xb2, 0x83, 0x83, 0x40, 0xcc, 0x1c,
0xb8, 0x99, 0x41, 0xb9, 0xb0, 0xc8, 0x1f, 0x36,
0x00, 0x75, 0x14, 0xa9, 0x25, 0x34, 0x87, 0x83,
0x05, 0x13, 0x16, 0x7d, 0x91, 0x40, 0x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x88,
0xb3, 0x3d, 0xee, 0x66, 0x64, 0x85, 0x53, 0x24,
0xe6, 0x49, 0xc8, 0x79, 0x0f, 0x55, 0xc6, 0x43,
0x20, 0x1f, 0x0a, 0x02, 0xad, 0x88, 0x90, 0x84,
0x56, 0x94, 0x85, 0x55, 0x1b, 0xe3, 0x0c, 0x7a,
0xb7, 0xbe, 0x6b, 0x33, 0x59, 0xd2, 0xd6, 0x77,
0xd9, 0x26, 0xb3, 0xfe, 0x70, 0xb5, 0xbb, 0xc9,
0x5b, 0xff, 0x39, 0x85, 0xbb, 0xdd, 0x51, 0xc9,
0xde, 0x3a, 0x38, 0xb0, 0xcc, 0x1d, 0xc0, 0x4e,
0x4c, 0xe3, 0x5b, 0x62, 0x11, 0xae, 0xbe, 0xa8,
0x86, 0x2f, 0xce, 0xdd, 0x19, 0x02, 0xc5, 0xee,
0xc2, 0x9a, 0x0b, 0x96, 0x95, 0x63, 0x9a, 0xfa,
0x83, 0x88, 0x74, 0x07, 0x1f, 0xd1, 0x02, 0x22,
0x2a, 0x0c, 0x45, 0xcb, 0x42, 0x64, 0x42, 0x41,
0xa7, 0x45, 0x21, 0x44, 0x83, 0x86, 0x03, 0x56,
0x80, 0x31, 0x21, 0x7d, 0x59, 0x10, 0x64, 0x19,
0x39, 0xd6, 0xe9, 0x1e, 0x9c, 0x5c, 0x44, 0xb1,
0x28, 0x39, 0x71, 0x5a, 0x62, 0x78, 0x91, 0x60,
0x7f, 0x2f, 0xff, 0xf0, 0x3d, 0x1c, 0x00, 0x60,
0xe7, 0x67, 0x74, 0xcb, 0x8c, 0x21, 0x40, 0x2c,
0x51, 0x0d, 0x75, 0x88, 0x40, 0x70, 0x38, 0x82,
0x01, 0xc6, 0xba, 0x0e, 0x26, 0x68, 0x56, 0x44,
0x0e, 0x34, 0xe6, 0x2b, 0x13, 0x69, 0x9a, 0x65,
0x85, 0x28, 0x79, 0x10, 0xf0, 0x31, 0x91, 0x61,
0x88, 0x54, 0xa2, 0xaf, 0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, 0x57,
0x2b, 0x82, 0xc3, 0x91, 0x72, 0x1a, 0xad, 0x62,
0x0e, 0x83, 0x89, 0x57, 0x81, 0x27, 0x50, 0x2f,
0x07, 0x3f, 0x07, 0x23, 0x3f, 0x17, 0xfc, 0xc4,
0x1d, 0xda, 0x18, 0x11, 0x3b, 0x6f, 0x50, 0x62,
0xc2, 0xf4, 0x40, 0x9d, 0xbc, 0x52, 0x88, 0x5c,
0x2b, 0x77, 0x28, 0x6e, 0xb9, 0x20, 0x2e, 0xad,
0x42, 0x68, 0x9f, 0x5e, 0x64, 0xbd, 0x36, 0x53,
0x0a, 0x4a, 0x46, 0x8d, 0x64, 0x2b, 0x22, 0x3b,
0xa6, 0xf5, 0x06, 0x76, 0x12, 0x89, 0xba, 0xc3,
0x24, 0x23, 0x10, 0xc0, 0x87, 0x92, 0xf0, 0xe6,
0xbe, 0x2b, 0x88, 0x6d, 0x34, 0x18, 0x1f, 0x95,
0x89, 0x01, 0x7b, 0xed, 0x07, 0x20, 0x0c, 0x44,
0xdb, 0x69, 0xae, 0x12, 0x20, 0x20, 0x8b, 0x40,
0x9e, 0x2c, 0x4f, 0x10, 0x9b, 0x5c, 0x24, 0x79,
0x78, 0x85, 0x12, 0x31, 0x98, 0x56, 0xf6, 0xde,
0xa2, 0xb4, 0x66, 0x43, 0x54, 0xa9, 0x76, 0xbc,
0xf0, 0x1c, 0x45, 0xba, 0x1a, 0x21, 0x28, 0x07,
0x3f, 0x81, 0x1e, 0x83, 0x06, 0x5d, 0x0c, 0x89,
0xa7, 0x94, 0x93, 0x80, 0xbd, 0xe9, 0xa0, 0xc3,
0xa0, 0x3c, 0xee, 0x9c, 0xf2, 0x12, 0x03, 0x85,
0x4f, 0x80, 0xea, 0x7a, 0xa2, 0xc8, 0x10, 0xae,
0x8c, 0x82, 0x46, 0x28, 0xc1, 0xc2, 0xf0, 0x77,
0x48, 0x69, 0xae, 0x48, 0x2b, 0xab, 0xe4, 0x0b,
0x5e, 0xa3, 0x91, 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0x1b, 0x09, 0x2b, 0x83,
0x10, 0x4c, 0xe2, 0x35, 0x9d, 0x13, 0x92, 0x80,
0x70, 0x66, 0x35, 0x6b, 0x77, 0x84, 0x6c, 0x64,
0xb9, 0xa5, 0x96, 0x13, 0xee, 0x0c, 0x41, 0xc8,
0xfa, 0x13, 0xb5, 0x9d, 0x25, 0x0a, 0x75, 0xde,
0x50, 0x70, 0x2f, 0xa7, 0x56, 0x37, 0x61, 0xb2,
0x42, 0x40, 0xae, 0x68, 0xcc, 0xa5, 0x07, 0x42,
0x4d, 0x0d, 0xad, 0xca, 0x0b, 0xd5, 0xa3, 0x21,
0x36, 0x9e, 0x8a, 0x22, 0xfd, 0x05, 0x88, 0x38,
0x82, 0x4a, 0x28, 0xc1, 0x6e, 0x92, 0xad, 0x43,
0x17, 0x4a, 0x34, 0x60, 0xfe, 0x10, 0x01, 0xe3,
0x75, 0x6e, 0x03, 0x82, 0x4b, 0xdc, 0xa2, 0xbd,
0x77, 0x28, 0x3b, 0xab, 0x77, 0x85, 0x21, 0x3c,
0xc1, 0x9b, 0x9c, 0xb6, 0x76, 0xdb, 0x67, 0x78,
0xb6, 0x5e, 0x21, 0x92, 0xde, 0x11, 0x4a, 0x20,
0x74, 0x08, 0xa4, 0xa1, 0xb8, 0xd3, 0x5e, 0x68,
0xd6, 0x57, 0x85, 0x01, 0x89, 0x0c, 0x5e, 0xa0,
0x07, 0x1a, 0x07, 0x09, 0xf7, 0x11, 0x02, 0xeb,
0x07, 0x1e, 0xd3, 0x46, 0xad, 0x11, 0x94, 0x74,
0x1d, 0xd7, 0x29, 0xc3, 0x62, 0xf7, 0x24, 0x1f,
0x7c, 0x18, 0x38, 0xf8, 0x30, 0xc2, 0x86, 0x12,
0x03, 0x9f, 0xea, 0x66, 0xc1, 0x83, 0x86, 0xc6,
0x5e, 0xa0, 0x39, 0xce, 0x51, 0x44, 0xda, 0xf8,
0x5f, 0x01, 0xc3, 0x4f, 0x61, 0xb5, 0xe8, 0x62,
0x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 0x72, 0xdc, 0x43, 0x04, 0x47, 0xc5,
0xa9, 0xb0, 0x9b, 0x7f
};
|
2301_81045437/classic-platform
|
communication/lwip-2.0.3/contrib/apps/rtp/rtpdata.h
|
C
|
unknown
| 105,990
|
/*
* Copyright (c) 2001-2003 Swedish Institute of Computer Science.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
* 3. The name of the author may not be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
* SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
* IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
* OF SUCH DAMAGE.
*
* This file is part of the lwIP TCP/IP stack.
*
* Author: Adam Dunkels <adam@sics.se>
*
*/
#include "shell.h"
#include "lwip/opt.h"
#if LWIP_NETCONN
#include <string.h>
#include <stdio.h>
#include "lwip/mem.h"
#include "lwip/debug.h"
#include "lwip/def.h"
#include "lwip/api.h"
#include "lwip/stats.h"
#ifdef WIN32
#define NEWLINE "\r\n"
#else /* WIN32 */
#define NEWLINE "\n"
#endif /* WIN32 */
/** Define this to 1 if you want to echo back all received characters
* (e.g. so they are displayed on a remote telnet)
*/
#ifndef SHELL_ECHO
#define SHELL_ECHO 0
#endif
#define BUFSIZE 1024
static unsigned char buffer[BUFSIZE];
struct command {
struct netconn *conn;
s8_t (* exec)(struct command *);
u8_t nargs;
char *args[10];
};
#include <stdio.h>
#include <stdlib.h>
#include <limits.h>
#define ESUCCESS 0
#define ESYNTAX -1
#define ETOOFEW -2
#define ETOOMANY -3
#define ECLOSED -4
#define NCONNS 10
static struct netconn *conns[NCONNS];
/* help_msg is split into 2 strings to prevent exceeding the C89 maximum length of 509 per string */
static char help_msg1[] = "Available commands:"NEWLINE"\
open [IP address] [TCP port]: opens a TCP connection to the specified address."NEWLINE"\
lstn [TCP port]: sets up a server on the specified port."NEWLINE"\
acpt [connection #]: waits for an incoming connection request."NEWLINE"\
send [connection #] [message]: sends a message on a TCP connection."NEWLINE"\
udpc [local UDP port] [IP address] [remote port]: opens a UDP \"connection\"."NEWLINE"\
udpl [local UDP port] [IP address] [remote port]: opens a UDP-Lite \"connection\"."NEWLINE"";
static char help_msg2[] = "udpn [local UDP port] [IP address] [remote port]: opens a UDP \"connection\" without checksums."NEWLINE"\
udpb [local port] [remote port]: opens a UDP broadcast \"connection\"."NEWLINE"\
usnd [connection #] [message]: sends a message on a UDP connection."NEWLINE"\
recv [connection #]: recieves data on a TCP or UDP connection."NEWLINE"\
clos [connection #]: closes a TCP or UDP connection."NEWLINE"\
stat: prints out lwIP statistics."NEWLINE"\
quit: quits."NEWLINE"";
#if LWIP_STATS
static char padding_10spaces[] = " ";
#define PROTOCOL_STATS (LINK_STATS && ETHARP_STATS && IPFRAG_STATS && IP_STATS && ICMP_STATS && UDP_STATS && TCP_STATS)
#if PROTOCOL_STATS
static const char* shell_stat_proto_names[] = {
#if LINK_STATS
"LINK ",
#endif
#if ETHARP_STATS
"ETHARP ",
#endif
#if IPFRAG_STATS
"IP_FRAG ",
#endif
#if IP_STATS
"IP ",
#endif
#if ICMP_STATS
"ICMP ",
#endif
#if UDP_STATS
"UDP ",
#endif
#if TCP_STATS
"TCP ",
#endif
"last"
};
static struct stats_proto* shell_stat_proto_stats[] = {
#if LINK_STATS
&lwip_stats.link,
#endif
#if ETHARP_STATS
&lwip_stats.etharp,
#endif
#if IPFRAG_STATS
&lwip_stats.ip_frag,
#endif
#if IP_STATS
&lwip_stats.ip,
#endif
#if ICMP_STATS
&lwip_stats.icmp,
#endif
#if UDP_STATS
&lwip_stats.udp,
#endif
#if TCP_STATS
&lwip_stats.tcp,
#endif
};
const size_t num_protostats = sizeof(shell_stat_proto_stats)/sizeof(struct stats_proto*);
static const char *stat_msgs_proto[] = {
" * transmitted ",
" * received ",
" forwarded ",
" * dropped ",
" * checksum errors ",
" * length errors ",
" * memory errors ",
" routing errors ",
" protocol errors ",
" option errors ",
" * misc errors ",
" cache hits "
};
#endif /* PROTOCOL_STATS */
#endif /* LWIP_STATS */
/*-----------------------------------------------------------------------------------*/
static void
sendstr(const char *str, struct netconn *conn)
{
netconn_write(conn, (const void *)str, strlen(str), NETCONN_NOCOPY);
}
/*-----------------------------------------------------------------------------------*/
static s8_t
com_open(struct command *com)
{
ip_addr_t ipaddr;
u16_t port;
int i;
err_t err;
long tmp;
if (ipaddr_aton(com->args[0], &ipaddr) == -1) {
sendstr(strerror(errno), com->conn);
return ESYNTAX;
}
tmp = strtol(com->args[1], NULL, 10);
if((tmp < 0) || (tmp > 0xffff)) {
sendstr("Invalid port number."NEWLINE, com->conn);
return ESUCCESS;
}
port = (u16_t)tmp;
/* Find the first unused connection in conns. */
for(i = 0; i < NCONNS && conns[i] != NULL; i++);
if (i == NCONNS) {
sendstr("No more connections available, sorry."NEWLINE, com->conn);
return ESUCCESS;
}
sendstr("Opening connection to ", com->conn);
netconn_write(com->conn, com->args[0], strlen(com->args[0]), NETCONN_COPY);
sendstr(":", com->conn);
netconn_write(com->conn, com->args[1], strlen(com->args[1]), NETCONN_COPY);
sendstr(NEWLINE, com->conn);
conns[i] = netconn_new(NETCONN_TCP);
if (conns[i] == NULL) {
sendstr("Could not create connection identifier (out of memory)."NEWLINE, com->conn);
return ESUCCESS;
}
err = netconn_connect(conns[i], &ipaddr, port);
if (err != ERR_OK) {
fprintf(stderr, "error %s"NEWLINE, lwip_strerr(err));
sendstr("Could not connect to remote host: ", com->conn);
#ifdef LWIP_DEBUG
sendstr(lwip_strerr(err), com->conn);
#else
sendstr("(debugging must be turned on for error message to appear)", com->conn);
#endif /* LWIP_DEBUG */
sendstr(NEWLINE, com->conn);
netconn_delete(conns[i]);
conns[i] = NULL;
return ESUCCESS;
}
sendstr("Opened connection, connection identifier is ", com->conn);
snprintf((char *)buffer, sizeof(buffer), "%d"NEWLINE, i);
netconn_write(com->conn, buffer, strlen((const char *)buffer), NETCONN_COPY);
return ESUCCESS;
}
/*-----------------------------------------------------------------------------------*/
static s8_t
com_lstn(struct command *com)
{
u16_t port;
int i;
err_t err;
long tmp;
tmp = strtol(com->args[0], NULL, 10);
if((tmp < 0) || (tmp > 0xffff)) {
sendstr("Invalid port number."NEWLINE, com->conn);
return ESUCCESS;
}
port = (u16_t)tmp;
/* Find the first unused connection in conns. */
for(i = 0; i < NCONNS && conns[i] != NULL; i++);
if (i == NCONNS) {
sendstr("No more connections available, sorry."NEWLINE, com->conn);
return ESUCCESS;
}
sendstr("Opening a listening connection on port ", com->conn);
netconn_write(com->conn, com->args[0], strlen(com->args[0]), NETCONN_COPY);
sendstr(NEWLINE, com->conn);
conns[i] = netconn_new(NETCONN_TCP);
if (conns[i] == NULL) {
sendstr("Could not create connection identifier (out of memory)."NEWLINE, com->conn);
return ESUCCESS;
}
err = netconn_bind(conns[i], IP_ADDR_ANY, port);
if (err != ERR_OK) {
netconn_delete(conns[i]);
conns[i] = NULL;
sendstr("Could not bind: ", com->conn);
#ifdef LWIP_DEBUG
sendstr(lwip_strerr(err), com->conn);
#else
sendstr("(debugging must be turned on for error message to appear)", com->conn);
#endif /* LWIP_DEBUG */
sendstr(NEWLINE, com->conn);
return ESUCCESS;
}
err = netconn_listen(conns[i]);
if (err != ERR_OK) {
netconn_delete(conns[i]);
conns[i] = NULL;
sendstr("Could not listen: ", com->conn);
#ifdef LWIP_DEBUG
sendstr(lwip_strerr(err), com->conn);
#else
sendstr("(debugging must be turned on for error message to appear)", com->conn);
#endif /* LWIP_DEBUG */
sendstr(NEWLINE, com->conn);
return ESUCCESS;
}
sendstr("Opened connection, connection identifier is ", com->conn);
snprintf((char *)buffer, sizeof(buffer), "%d"NEWLINE, i);
netconn_write(com->conn, buffer, strlen((const char *)buffer), NETCONN_COPY);
return ESUCCESS;
}
/*-----------------------------------------------------------------------------------*/
/*-----------------------------------------------------------------------------------*/
static s8_t
com_clos(struct command *com)
{
int i;
err_t err;
i = strtol(com->args[0], NULL, 10);
if (i > NCONNS) {
sendstr("Connection identifier too high."NEWLINE, com->conn);
return ESUCCESS;
}
if (conns[i] == NULL) {
sendstr("Connection identifier not in use."NEWLINE, com->conn);
return ESUCCESS;
}
err = netconn_close(conns[i]);
if (err != ERR_OK) {
sendstr("Could not close connection: ", com->conn);
#ifdef LWIP_DEBUG
sendstr(lwip_strerr(err), com->conn);
#else
sendstr("(debugging must be turned on for error message to appear)", com->conn);
#endif /* LWIP_DEBUG */
sendstr(NEWLINE, com->conn);
return ESUCCESS;
}
sendstr("Connection closed."NEWLINE, com->conn);
netconn_delete(conns[i]);
conns[i] = NULL;
return ESUCCESS;
}
/*-----------------------------------------------------------------------------------*/
static s8_t
com_acpt(struct command *com)
{
int i, j;
err_t err;
/* Find the first unused connection in conns. */
for(j = 0; j < NCONNS && conns[j] != NULL; j++);
if (j == NCONNS) {
sendstr("No more connections available, sorry."NEWLINE, com->conn);
return ESUCCESS;
}
i = strtol(com->args[0], NULL, 10);
if (i > NCONNS) {
sendstr("Connection identifier too high."NEWLINE, com->conn);
return ESUCCESS;
}
if (conns[i] == NULL) {
sendstr("Connection identifier not in use."NEWLINE, com->conn);
return ESUCCESS;
}
err = netconn_accept(conns[i], &conns[j]);
if (err != ERR_OK) {
sendstr("Could not accept connection: ", com->conn);
#ifdef LWIP_DEBUG
sendstr(lwip_strerr(err), com->conn);
#else
sendstr("(debugging must be turned on for error message to appear)", com->conn);
#endif /* LWIP_DEBUG */
sendstr(NEWLINE, com->conn);
return ESUCCESS;
}
sendstr("Accepted connection, connection identifier for new connection is ", com->conn);
snprintf((char *)buffer, sizeof(buffer), "%d"NEWLINE, j);
netconn_write(com->conn, buffer, strlen((const char *)buffer), NETCONN_COPY);
return ESUCCESS;
}
/*-----------------------------------------------------------------------------------*/
#if LWIP_STATS
static void
com_stat_write_mem(struct netconn *conn, struct stats_mem *elem, int i)
{
u16_t len;
char buf[100];
size_t slen;
#ifdef LWIP_DEBUG
LWIP_UNUSED_ARG(i);
slen = strlen(elem->name);
netconn_write(conn, elem->name, slen, NETCONN_COPY);
#else /* LWIP_DEBUG */
len = (u16_t)sprintf(buf, "%d", i);
slen = strlen(buf);
netconn_write(conn, buf, slen, NETCONN_COPY);
#endif /* LWIP_DEBUG */
if(slen < 10) {
netconn_write(conn, padding_10spaces, 10-slen, NETCONN_COPY);
}
len = (u16_t)sprintf(buf, " * available %"MEM_SIZE_F NEWLINE, elem->avail);
netconn_write(conn, buf, len, NETCONN_COPY);
len = (u16_t)sprintf(buf, " * used %"MEM_SIZE_F NEWLINE, elem->used);
netconn_write(conn, buf, len, NETCONN_COPY);
len = (u16_t)sprintf(buf, " * high water mark %"MEM_SIZE_F NEWLINE, elem->max);
netconn_write(conn, buf, len, NETCONN_COPY);
len = (u16_t)sprintf(buf, " * errors %"STAT_COUNTER_F NEWLINE, elem->err);
netconn_write(conn, buf, len, NETCONN_COPY);
len = (u16_t)sprintf(buf, " * illegal %"STAT_COUNTER_F NEWLINE, elem->illegal);
netconn_write(conn, buf, len, NETCONN_COPY);
}
static void
com_stat_write_sys(struct netconn *conn, struct stats_syselem *elem, const char *name)
{
u16_t len;
char buf[100];
size_t slen = strlen(name);
netconn_write(conn, name, slen, NETCONN_COPY);
if(slen < 10) {
netconn_write(conn, padding_10spaces, 10-slen, NETCONN_COPY);
}
len = (u16_t)sprintf(buf, " * used %"STAT_COUNTER_F NEWLINE, elem->used);
netconn_write(conn, buf, len, NETCONN_COPY);
len = (u16_t)sprintf(buf, " * high water mark %"STAT_COUNTER_F NEWLINE, elem->max);
netconn_write(conn, buf, len, NETCONN_COPY);
len = (u16_t)sprintf(buf, " * errors %"STAT_COUNTER_F NEWLINE, elem->err);
netconn_write(conn, buf, len, NETCONN_COPY);
}
static s8_t
com_stat(struct command *com)
{
#if PROTOCOL_STATS || MEMP_STATS
size_t i;
#endif /* PROTOCOL_STATS || MEMP_STATS */
#if PROTOCOL_STATS
size_t k;
char buf[100];
u16_t len;
/* protocol stats, @todo: add IGMP */
for(i = 0; i < num_protostats; i++) {
size_t s = sizeof(struct stats_proto)/sizeof(STAT_COUNTER);
STAT_COUNTER *c = &shell_stat_proto_stats[i]->xmit;
LWIP_ASSERT("stats not in sync", s == sizeof(stat_msgs_proto)/sizeof(char*));
netconn_write(com->conn, shell_stat_proto_names[i], strlen(shell_stat_proto_names[i]), NETCONN_COPY);
for(k = 0; k < s; k++) {
len = (u16_t)sprintf(buf, "%s%"STAT_COUNTER_F NEWLINE, stat_msgs_proto[k], c[k]);
netconn_write(com->conn, buf, len, NETCONN_COPY);
}
}
#endif /* PROTOCOL_STATS */
#if MEM_STATS
com_stat_write_mem(com->conn, &lwip_stats.mem, -1);
#endif /* MEM_STATS */
#if MEMP_STATS
for(i = 0; i < MEMP_MAX; i++) {
com_stat_write_mem(com->conn, lwip_stats.memp[i], -1);
}
#endif /* MEMP_STATS */
#if SYS_STATS
com_stat_write_sys(com->conn, &lwip_stats.sys.sem, "SEM ");
com_stat_write_sys(com->conn, &lwip_stats.sys.mutex, "MUTEX ");
com_stat_write_sys(com->conn, &lwip_stats.sys.mbox, "MBOX ");
#endif /* SYS_STATS */
return ESUCCESS;
}
#endif
/*-----------------------------------------------------------------------------------*/
static s8_t
com_send(struct command *com)
{
int i;
err_t err;
size_t len;
i = strtol(com->args[0], NULL, 10);
if (i > NCONNS) {
sendstr("Connection identifier too high."NEWLINE, com->conn);
return ESUCCESS;
}
if (conns[i] == NULL) {
sendstr("Connection identifier not in use."NEWLINE, com->conn);
return ESUCCESS;
}
len = strlen(com->args[1]);
com->args[1][len] = '\r';
com->args[1][len + 1] = '\n';
com->args[1][len + 2] = 0;
err = netconn_write(conns[i], com->args[1], len + 3, NETCONN_COPY);
if (err != ERR_OK) {
sendstr("Could not send data: ", com->conn);
#ifdef LWIP_DEBUG
sendstr(lwip_strerr(err), com->conn);
#else
sendstr("(debugging must be turned on for error message to appear)", com->conn);
#endif /* LWIP_DEBUG */
sendstr(NEWLINE, com->conn);
return ESUCCESS;
}
sendstr("Data enqueued for sending."NEWLINE, com->conn);
return ESUCCESS;
}
/*-----------------------------------------------------------------------------------*/
static s8_t
com_recv(struct command *com)
{
int i;
err_t err;
struct netbuf *buf;
u16_t len;
i = strtol(com->args[0], NULL, 10);
if (i > NCONNS) {
sendstr("Connection identifier too high."NEWLINE, com->conn);
return ESUCCESS;
}
if (conns[i] == NULL) {
sendstr("Connection identifier not in use."NEWLINE, com->conn);
return ESUCCESS;
}
err = netconn_recv(conns[i], &buf);
if (err == ERR_OK) {
netbuf_copy(buf, buffer, BUFSIZE);
len = netbuf_len(buf);
sendstr("Reading from connection:"NEWLINE, com->conn);
netconn_write(com->conn, buffer, len, NETCONN_COPY);
netbuf_delete(buf);
} else {
sendstr("EOF."NEWLINE, com->conn);
}
err = netconn_err(conns[i]);
if (err != ERR_OK) {
sendstr("Could not receive data: ", com->conn);
#ifdef LWIP_DEBUG
sendstr(lwip_strerr(err), com->conn);
#else
sendstr("(debugging must be turned on for error message to appear)", com->conn);
#endif /* LWIP_DEBUG */
sendstr(NEWLINE, com->conn);
return ESUCCESS;
}
return ESUCCESS;
}
/*-----------------------------------------------------------------------------------*/
static s8_t
com_udpc(struct command *com)
{
ip_addr_t ipaddr;
u16_t lport, rport;
int i;
err_t err;
long tmp;
tmp = strtol(com->args[0], NULL, 10);
if((tmp < 0) || (tmp > 0xffff)) {
sendstr("Invalid port number."NEWLINE, com->conn);
return ESUCCESS;
}
lport = (u16_t)tmp;
if (ipaddr_aton(com->args[1], &ipaddr) == -1) {
sendstr(strerror(errno), com->conn);
return ESYNTAX;
}
tmp = strtol(com->args[2], NULL, 10);
if((tmp < 0) || (tmp > 0xffff)) {
sendstr("Invalid port number."NEWLINE, com->conn);
return ESUCCESS;
}
rport = (u16_t)tmp;
/* Find the first unused connection in conns. */
for(i = 0; i < NCONNS && conns[i] != NULL; i++);
if (i == NCONNS) {
sendstr("No more connections available, sorry."NEWLINE, com->conn);
return ESUCCESS;
}
sendstr("Setting up UDP connection from port ", com->conn);
netconn_write(com->conn, com->args[0], strlen(com->args[0]), NETCONN_COPY);
sendstr(" to ", com->conn);
netconn_write(com->conn, com->args[1], strlen(com->args[1]), NETCONN_COPY);
sendstr(":", com->conn);
netconn_write(com->conn, com->args[2], strlen(com->args[2]), NETCONN_COPY);
sendstr(NEWLINE, com->conn);
conns[i] = netconn_new(NETCONN_UDP);
if (conns[i] == NULL) {
sendstr("Could not create connection identifier (out of memory)."NEWLINE, com->conn);
return ESUCCESS;
}
err = netconn_connect(conns[i], &ipaddr, rport);
if (err != ERR_OK) {
netconn_delete(conns[i]);
conns[i] = NULL;
sendstr("Could not connect to remote host: ", com->conn);
#ifdef LWIP_DEBUG
sendstr(lwip_strerr(err), com->conn);
#else
sendstr("(debugging must be turned on for error message to appear)", com->conn);
#endif /* LWIP_DEBUG */
sendstr(NEWLINE, com->conn);
return ESUCCESS;
}
err = netconn_bind(conns[i], IP_ADDR_ANY, lport);
if (err != ERR_OK) {
netconn_delete(conns[i]);
conns[i] = NULL;
sendstr("Could not bind: ", com->conn);
#ifdef LWIP_DEBUG
sendstr(lwip_strerr(err), com->conn);
#else
sendstr("(debugging must be turned on for error message to appear)", com->conn);
#endif /* LWIP_DEBUG */
sendstr(NEWLINE, com->conn);
return ESUCCESS;
}
sendstr("Connection set up, connection identifier is ", com->conn);
snprintf((char *)buffer, sizeof(buffer), "%d"NEWLINE, i);
netconn_write(com->conn, buffer, strlen((const char *)buffer), NETCONN_COPY);
return ESUCCESS;
}
/*-----------------------------------------------------------------------------------*/
static s8_t
com_udpl(struct command *com)
{
ip_addr_t ipaddr;
u16_t lport, rport;
int i;
err_t err;
long tmp;
tmp = strtol(com->args[0], NULL, 10);
if((tmp < 0) || (tmp > 0xffff)) {
sendstr("Invalid port number."NEWLINE, com->conn);
return ESUCCESS;
}
lport = (u16_t)tmp;
if (ipaddr_aton(com->args[1], &ipaddr) == -1) {
sendstr(strerror(errno), com->conn);
return ESYNTAX;
}
tmp = strtol(com->args[2], NULL, 10);
if((tmp < 0) || (tmp > 0xffff)) {
sendstr("Invalid port number."NEWLINE, com->conn);
return ESUCCESS;
}
rport = (u16_t)tmp;
/* Find the first unused connection in conns. */
for(i = 0; i < NCONNS && conns[i] != NULL; i++);
if (i == NCONNS) {
sendstr("No more connections available, sorry."NEWLINE, com->conn);
return ESUCCESS;
}
sendstr("Setting up UDP-Lite connection from port ", com->conn);
netconn_write(com->conn, com->args[0], strlen(com->args[0]), NETCONN_COPY);
sendstr(" to ", com->conn);
netconn_write(com->conn, com->args[1], strlen(com->args[1]), NETCONN_COPY);
sendstr(":", com->conn);
netconn_write(com->conn, com->args[2], strlen(com->args[2]), NETCONN_COPY);
sendstr(NEWLINE, com->conn);
conns[i] = netconn_new(NETCONN_UDPLITE);
if (conns[i] == NULL) {
sendstr("Could not create connection identifier (out of memory)."NEWLINE, com->conn);
return ESUCCESS;
}
err = netconn_connect(conns[i], &ipaddr, rport);
if (err != ERR_OK) {
netconn_delete(conns[i]);
conns[i] = NULL;
sendstr("Could not connect to remote host: ", com->conn);
#ifdef LWIP_DEBUG
sendstr(lwip_strerr(err), com->conn);
#else
sendstr("(debugging must be turned on for error message to appear)", com->conn);
#endif /* LWIP_DEBUG */
sendstr(NEWLINE, com->conn);
return ESUCCESS;
}
err = netconn_bind(conns[i], IP_ADDR_ANY, lport);
if (err != ERR_OK) {
netconn_delete(conns[i]);
conns[i] = NULL;
sendstr("Could not bind: ", com->conn);
#ifdef LWIP_DEBUG
sendstr(lwip_strerr(err), com->conn);
#else
sendstr("(debugging must be turned on for error message to appear)", com->conn);
#endif /* LWIP_DEBUG */
sendstr(NEWLINE, com->conn);
return ESUCCESS;
}
sendstr("Connection set up, connection identifier is ", com->conn);
snprintf((char *)buffer, sizeof(buffer), "%d"NEWLINE, i);
netconn_write(com->conn, buffer, strlen((const char *)buffer), NETCONN_COPY);
return ESUCCESS;
}
/*-----------------------------------------------------------------------------------*/
static s8_t
com_udpn(struct command *com)
{
ip_addr_t ipaddr;
u16_t lport, rport;
int i;
err_t err;
long tmp;
tmp = strtol(com->args[0], NULL, 10);
if((tmp < 0) || (tmp > 0xffff)) {
sendstr("Invalid port number."NEWLINE, com->conn);
return ESUCCESS;
}
lport = (u16_t)tmp;
if (ipaddr_aton(com->args[1], &ipaddr) == -1) {
sendstr(strerror(errno), com->conn);
return ESYNTAX;
}
tmp = strtol(com->args[2], NULL, 10);
if((tmp < 0) || (tmp > 0xffff)) {
sendstr("Invalid port number."NEWLINE, com->conn);
return ESUCCESS;
}
rport = (u16_t)tmp;
/* Find the first unused connection in conns. */
for(i = 0; i < NCONNS && conns[i] != NULL; i++);
if (i == NCONNS) {
sendstr("No more connections available, sorry."NEWLINE, com->conn);
return ESUCCESS;
}
sendstr("Setting up UDP connection without checksums from port ", com->conn);
netconn_write(com->conn, com->args[0], strlen(com->args[0]), NETCONN_COPY);
sendstr(" to ", com->conn);
netconn_write(com->conn, com->args[1], strlen(com->args[1]), NETCONN_COPY);
sendstr(":", com->conn);
netconn_write(com->conn, com->args[2], strlen(com->args[2]), NETCONN_COPY);
sendstr(NEWLINE, com->conn);
conns[i] = netconn_new(NETCONN_UDPNOCHKSUM);
if (conns[i] == NULL) {
sendstr("Could not create connection identifier (out of memory)."NEWLINE, com->conn);
return ESUCCESS;
}
err = netconn_connect(conns[i], &ipaddr, rport);
if (err != ERR_OK) {
netconn_delete(conns[i]);
conns[i] = NULL;
sendstr("Could not connect to remote host: ", com->conn);
#ifdef LWIP_DEBUG
sendstr(lwip_strerr(err), com->conn);
#else
sendstr("(debugging must be turned on for error message to appear)", com->conn);
#endif /* LWIP_DEBUG */
sendstr(NEWLINE, com->conn);
return ESUCCESS;
}
err = netconn_bind(conns[i], IP_ADDR_ANY, lport);
if (err != ERR_OK) {
netconn_delete(conns[i]);
conns[i] = NULL;
sendstr("Could not bind: ", com->conn);
#ifdef LWIP_DEBUG
sendstr(lwip_strerr(err), com->conn);
#else
sendstr("(debugging must be turned on for error message to appear)", com->conn);
#endif /* LWIP_DEBUG */
sendstr(NEWLINE, com->conn);
return ESUCCESS;
}
sendstr("Connection set up, connection identifier is ", com->conn);
snprintf((char *)buffer, sizeof(buffer), "%d"NEWLINE, i);
netconn_write(com->conn, buffer, strlen((const char *)buffer), NETCONN_COPY);
return ESUCCESS;
}
/*-----------------------------------------------------------------------------------*/
static s8_t
com_udpb(struct command *com)
{
ip_addr_t ipaddr;
#if LWIP_IPV4
u16_t lport;
#endif /* LWIP_IPV4 */
u16_t rport;
int i;
err_t err;
long tmp;
tmp = strtol(com->args[0], NULL, 10);
if((tmp < 0) || (tmp > 0xffff)) {
sendstr("Invalid port number."NEWLINE, com->conn);
return ESUCCESS;
}
#if LWIP_IPV4
lport = (u16_t)tmp;
#endif /* LWIP_IPV4 */
if (ipaddr_aton(com->args[1], &ipaddr) == -1) {
sendstr(strerror(errno), com->conn);
return ESYNTAX;
}
tmp = strtol(com->args[2], NULL, 10);
if((tmp < 0) || (tmp > 0xffff)) {
sendstr("Invalid port number."NEWLINE, com->conn);
return ESUCCESS;
}
rport = (u16_t)tmp;
/* Find the first unused connection in conns. */
for(i = 0; i < NCONNS && conns[i] != NULL; i++);
if (i == NCONNS) {
sendstr("No more connections available, sorry."NEWLINE, com->conn);
return ESUCCESS;
}
sendstr("Setting up UDP broadcast connection from port ", com->conn);
netconn_write(com->conn, com->args[0], strlen(com->args[0]), NETCONN_COPY);
sendstr(" to ", com->conn);
netconn_write(com->conn, com->args[1], strlen(com->args[1]), NETCONN_COPY);
sendstr(NEWLINE, com->conn);
conns[i] = netconn_new(NETCONN_UDP);
if (conns[i] == NULL) {
sendstr("Could not create connection identifier (out of memory)."NEWLINE, com->conn);
return ESUCCESS;
}
err = netconn_connect(conns[i], &ipaddr, rport);
if (err != ERR_OK) {
netconn_delete(conns[i]);
conns[i] = NULL;
sendstr("Could not connect to remote host: ", com->conn);
#ifdef LWIP_DEBUG
sendstr(lwip_strerr(err), com->conn);
#else
sendstr("(debugging must be turned on for error message to appear)", com->conn);
#endif /* LWIP_DEBUG */
sendstr(NEWLINE, com->conn);
return ESUCCESS;
}
#if LWIP_IPV4
if (IP_IS_V6(&ipaddr)) {
err = netconn_bind(conns[i], &ip_addr_broadcast, lport);
if (err != ERR_OK) {
netconn_delete(conns[i]);
conns[i] = NULL;
sendstr("Could not bind: ", com->conn);
#ifdef LWIP_DEBUG
sendstr(lwip_strerr(err), com->conn);
#else
sendstr("(debugging must be turned on for error message to appear)", com->conn);
#endif /* LWIP_DEBUG */
sendstr(NEWLINE, com->conn);
return ESUCCESS;
}
}
#endif /* LWIP_IPV4 */
sendstr("Connection set up, connection identifier is ", com->conn);
snprintf((char *)buffer, sizeof(buffer), "%d"NEWLINE, i);
netconn_write(com->conn, buffer, strlen((const char *)buffer), NETCONN_COPY);
return ESUCCESS;
}
/*-----------------------------------------------------------------------------------*/
static s8_t
com_usnd(struct command *com)
{
long i;
err_t err;
struct netbuf *buf;
char *mem;
u16_t len;
size_t tmp;
i = strtol(com->args[0], NULL, 10);
if (i > NCONNS) {
sendstr("Connection identifier too high."NEWLINE, com->conn);
return ESUCCESS;
}
if (conns[i] == NULL) {
sendstr("Connection identifier not in use."NEWLINE, com->conn);
return ESUCCESS;
}
tmp = strlen(com->args[1]) + 1;
if (tmp > 0xffff) {
sendstr("Invalid length."NEWLINE, com->conn);
return ESUCCESS;
}
len = (u16_t)tmp;
buf = netbuf_new();
mem = (char *)netbuf_alloc(buf, len);
if (mem == NULL) {
sendstr("Could not allocate memory for sending."NEWLINE, com->conn);
return ESUCCESS;
}
strncpy(mem, com->args[1], len);
err = netconn_send(conns[i], buf);
netbuf_delete(buf);
if (err != ERR_OK) {
sendstr("Could not send data: ", com->conn);
#ifdef LWIP_DEBUG
sendstr(lwip_strerr(err), com->conn);
#else
sendstr("(debugging must be turned on for error message to appear)", com->conn);
#endif /* LWIP_DEBUG */
sendstr(NEWLINE, com->conn);
return ESUCCESS;
}
sendstr("Data sent."NEWLINE, com->conn);
return ESUCCESS;
}
/*-----------------------------------------------------------------------------------*/
static s8_t
com_help(struct command *com)
{
sendstr(help_msg1, com->conn);
sendstr(help_msg2, com->conn);
return ESUCCESS;
}
/*-----------------------------------------------------------------------------------*/
static s8_t
parse_command(struct command *com, u32_t len)
{
u16_t i;
u16_t bufp;
if (strncmp((const char *)buffer, "open", 4) == 0) {
com->exec = com_open;
com->nargs = 2;
} else if (strncmp((const char *)buffer, "lstn", 4) == 0) {
com->exec = com_lstn;
com->nargs = 1;
} else if (strncmp((const char *)buffer, "acpt", 4) == 0) {
com->exec = com_acpt;
com->nargs = 1;
} else if (strncmp((const char *)buffer, "clos", 4) == 0) {
com->exec = com_clos;
com->nargs = 1;
#if LWIP_STATS
} else if (strncmp((const char *)buffer, "stat", 4) == 0) {
com->exec = com_stat;
com->nargs = 0;
#endif
} else if (strncmp((const char *)buffer, "send", 4) == 0) {
com->exec = com_send;
com->nargs = 2;
} else if (strncmp((const char *)buffer, "recv", 4) == 0) {
com->exec = com_recv;
com->nargs = 1;
} else if (strncmp((const char *)buffer, "udpc", 4) == 0) {
com->exec = com_udpc;
com->nargs = 3;
} else if (strncmp((const char *)buffer, "udpb", 4) == 0) {
com->exec = com_udpb;
com->nargs = 2;
} else if (strncmp((const char *)buffer, "udpl", 4) == 0) {
com->exec = com_udpl;
com->nargs = 3;
} else if (strncmp((const char *)buffer, "udpn", 4) == 0) {
com->exec = com_udpn;
com->nargs = 3;
} else if (strncmp((const char *)buffer, "usnd", 4) == 0) {
com->exec = com_usnd;
com->nargs = 2;
} else if (strncmp((const char *)buffer, "help", 4) == 0) {
com->exec = com_help;
com->nargs = 0;
} else if (strncmp((const char *)buffer, "quit", 4) == 0) {
printf("quit"NEWLINE);
return ECLOSED;
} else {
return ESYNTAX;
}
if (com->nargs == 0) {
return ESUCCESS;
}
bufp = 0;
for(; bufp < len && buffer[bufp] != ' '; bufp++);
for(i = 0; i < 10; i++) {
for(; bufp < len && buffer[bufp] == ' '; bufp++);
if (buffer[bufp] == '\r' ||
buffer[bufp] == '\n') {
buffer[bufp] = 0;
if (i < com->nargs - 1) {
return ETOOFEW;
}
if (i > com->nargs - 1) {
return ETOOMANY;
}
break;
}
if (bufp > len) {
return ETOOFEW;
}
com->args[i] = (char *)&buffer[bufp];
for(; bufp < len && buffer[bufp] != ' ' && buffer[bufp] != '\r' &&
buffer[bufp] != '\n'; bufp++) {
if (buffer[bufp] == '\\') {
buffer[bufp] = ' ';
}
}
if (bufp > len) {
return ESYNTAX;
}
buffer[bufp] = 0;
bufp++;
if (i == com->nargs - 1) {
break;
}
}
return ESUCCESS;
}
/*-----------------------------------------------------------------------------------*/
static void
shell_error(s8_t err, struct netconn *conn)
{
switch (err) {
case ESYNTAX:
sendstr("## Syntax error"NEWLINE, conn);
break;
case ETOOFEW:
sendstr("## Too few arguments to command given"NEWLINE, conn);
break;
case ETOOMANY:
sendstr("## Too many arguments to command given"NEWLINE, conn);
break;
case ECLOSED:
sendstr("## Connection closed"NEWLINE, conn);
break;
default:
/* unknown error, don't assert here */
break;
}
}
/*-----------------------------------------------------------------------------------*/
static void
prompt(struct netconn *conn)
{
sendstr("> ", conn);
}
/*-----------------------------------------------------------------------------------*/
static void
shell_main(struct netconn *conn)
{
struct pbuf *p;
u16_t len = 0, cur_len;
struct command com;
s8_t err;
int i;
err_t ret;
#if SHELL_ECHO
void *echomem;
#endif /* SHELL_ECHO */
do {
ret = netconn_recv_tcp_pbuf(conn, &p);
if (ret == ERR_OK) {
pbuf_copy_partial(p, &buffer[len], BUFSIZE - len, 0);
cur_len = p->tot_len;
len += cur_len;
#if SHELL_ECHO
echomem = mem_malloc(cur_len);
if (echomem != NULL) {
pbuf_copy_partial(p, echomem, cur_len, 0);
netconn_write(conn, echomem, cur_len, NETCONN_COPY);
mem_free(echomem);
}
#endif /* SHELL_ECHO */
pbuf_free(p);
if (((len > 0) && ((buffer[len-1] == '\r') || (buffer[len-1] == '\n'))) ||
(len >= BUFSIZE)) {
if (buffer[0] != 0xff &&
buffer[1] != 0xfe) {
err = parse_command(&com, len);
if (err == ESUCCESS) {
com.conn = conn;
err = com.exec(&com);
}
if (err == ECLOSED) {
printf("Closed"NEWLINE);
shell_error(err, conn);
goto close;
}
if (err != ESUCCESS) {
shell_error(err, conn);
}
} else {
sendstr(NEWLINE NEWLINE
"lwIP simple interactive shell."NEWLINE
"(c) Copyright 2001, Swedish Institute of Computer Science."NEWLINE
"Written by Adam Dunkels."NEWLINE
"For help, try the \"help\" command."NEWLINE, conn);
}
if (ret == ERR_OK) {
prompt(conn);
}
len = 0;
}
}
} while (ret == ERR_OK);
printf("err %s"NEWLINE, lwip_strerr(ret));
close:
netconn_close(conn);
for(i = 0; i < NCONNS; i++) {
if (conns[i] != NULL) {
netconn_delete(conns[i]);
}
conns[i] = NULL;
}
}
/*-----------------------------------------------------------------------------------*/
static void
shell_thread(void *arg)
{
struct netconn *conn, *newconn;
err_t err;
LWIP_UNUSED_ARG(arg);
#if LWIP_IPV6
conn = netconn_new(NETCONN_TCP_IPV6);
netconn_bind(conn, IP6_ADDR_ANY, 23);
#else /* LWIP_IPV6 */
conn = netconn_new(NETCONN_TCP);
netconn_bind(conn, IP_ADDR_ANY, 23);
#endif /* LWIP_IPV6 */
LWIP_ERROR("shell: invalid conn", (conn != NULL), return;);
netconn_listen(conn);
while (1) {
err = netconn_accept(conn, &newconn);
if (err == ERR_OK) {
shell_main(newconn);
netconn_delete(newconn);
}
}
}
/*-----------------------------------------------------------------------------------*/
void
shell_init(void)
{
sys_thread_new("shell_thread", shell_thread, NULL, DEFAULT_THREAD_STACKSIZE, DEFAULT_THREAD_PRIO);
}
#endif /* LWIP_NETCONN */
|
2301_81045437/classic-platform
|
communication/lwip-2.0.3/contrib/apps/shell/shell.c
|
C
|
unknown
| 35,981
|
/*
* Copyright (c) 2001-2003 Swedish Institute of Computer Science.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
* 3. The name of the author may not be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
* SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
* IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
* OF SUCH DAMAGE.
*
* This file is part of the lwIP TCP/IP stack.
*
* Author: Adam Dunkels <adam@sics.se>
*
*/
#ifndef LWIP_SHELL_H
#define LWIP_SHELL_H
void shell_init(void);
#endif /* LWIP_SHELL_H */
|
2301_81045437/classic-platform
|
communication/lwip-2.0.3/contrib/apps/shell/shell.h
|
C
|
unknown
| 1,738
|
/**
* @file
* SMTP client module
*
* Author: Simon Goldschmidt
*
* Example usage:
*
* void my_smtp_result_fn(void *arg, u8_t smtp_result, u16_t srv_err, err_t err)
* {
* printf("mail (%p) sent with results: 0x%02x, 0x%04x, 0x%08x\n", arg,
* smtp_result, srv_err, err);
* }
* static void my_smtp_test(void)
* {
* smtp_set_server_addr("mymailserver.org");
* -> set both username and password as NULL if no auth needed
* smtp_set_auth("username", "password");
* smtp_send_mail("sender", "recipient", "subject", "body", my_smtp_result_fn,
* some_argument);
* }
*
* When using from any other thread than the tcpip_thread (for NO_SYS==0), use
* smtp_send_mail_int()!
*
*
* SMTP_BODYDH usage:
*
* int my_smtp_bodydh_fn(void *arg, struct smtp_bodydh *bdh)
* {
* if(bdh->state >= 10) {
* return BDH_DONE;
* }
* sprintf(bdh->buffer,"Line #%2d\r\n",bdh->state);
* bdh->length = strlen(bdh->buffer);
* ++bdh->state;
* return BDH_WORKING;
* }
*
* smtp_send_mail_bodycback("sender", "recipient", "subject",
* my_smtp_bodydh_fn, my_smtp_result_fn, some_argument);
*
*/
#include "smtp.h"
#include "lwip/opt.h"
#if LWIP_TCP
#include "lwip/sys.h"
#include "lwip/sockets.h"
#include "lwip/tcp.h"
#include "lwip/dns.h"
#include <string.h>
#include <stdlib.h>
/** This is simple SMTP client for raw API.
* It is a minimal implementation of SMTP as specified in RFC 5321.
*
* @todo:
* - attachments (the main difficulty here is streaming base64-encoding to
* prevent having to allocate a buffer for the whole encoded file at once)
* - test with more mail servers...
*/
/**
* SMTP_DEBUG: Enable debugging for SNTP.
*/
#ifndef SMTP_DEBUG
#define SMTP_DEBUG LWIP_DBG_OFF
#endif
/** Maximum length reserved for server name */
#ifndef SMTP_MAX_SERVERNAME_LEN
#define SMTP_MAX_SERVERNAME_LEN 256
#endif
/** Maximum length reserved for username */
#ifndef SMTP_MAX_USERNAME_LEN
#define SMTP_MAX_USERNAME_LEN 32
#endif
/** Maximum length reserved for password */
#ifndef SMTP_MAX_PASS_LEN
#define SMTP_MAX_PASS_LEN 32
#endif
/** Set this to 0 if you know the authentication data will not change
* during the smtp session, which saves some heap space. */
#ifndef SMTP_COPY_AUTHDATA
#define SMTP_COPY_AUTHDATA 1
#endif
/** Set this to 0 to save some code space if you know for sure that all data
* passed to this module conforms to the requirements in the SMTP RFC.
* WARNING: use this with care!
*/
#ifndef SMTP_CHECK_DATA
#define SMTP_CHECK_DATA 1
#endif
/** Set this to 1 to enable AUTH PLAIN support */
#ifndef SMTP_SUPPORT_AUTH_PLAIN
#define SMTP_SUPPORT_AUTH_PLAIN 1
#endif
/** Set this to 1 to enable AUTH LOGIN support */
#ifndef SMTP_SUPPORT_AUTH_LOGIN
#define SMTP_SUPPORT_AUTH_LOGIN 1
#endif
/** TCP poll interval. Unit is 0.5 sec. */
#define SMTP_POLL_INTERVAL 4
/** TCP poll timeout while sending message body, reset after every
* successful write. 3 minutes */
#define SMTP_TIMEOUT_DATABLOCK ( 3 * 60 * SMTP_POLL_INTERVAL / 2)
/** TCP poll timeout while waiting for confirmation after sending the body.
* 10 minutes */
#define SMTP_TIMEOUT_DATATERM (10 * 60 * SMTP_POLL_INTERVAL / 2)
/** TCP poll timeout while not sending the body.
* This is somewhat lower than the RFC states (5 minutes for initial, MAIL
* and RCPT) but still OK for us here.
* 2 minutes */
#define SMTP_TIMEOUT ( 2 * 60 * SMTP_POLL_INTERVAL / 2)
/* the various debug levels for this file */
#define SMTP_DEBUG_TRACE (SMTP_DEBUG | LWIP_DBG_TRACE)
#define SMTP_DEBUG_STATE (SMTP_DEBUG | LWIP_DBG_STATE)
#define SMTP_DEBUG_WARN (SMTP_DEBUG | LWIP_DBG_LEVEL_WARNING)
#define SMTP_DEBUG_WARN_STATE (SMTP_DEBUG | LWIP_DBG_LEVEL_WARNING | LWIP_DBG_STATE)
#define SMTP_DEBUG_SERIOUS (SMTP_DEBUG | LWIP_DBG_LEVEL_SERIOUS)
#define SMTP_RX_BUF_LEN 255
#define SMTP_TX_BUF_LEN 255
#define SMTP_CRLF "\r\n"
#define SMTP_CRLF_LEN 2
#define SMTP_RESP_220 "220"
#define SMTP_RESP_235 "235"
#define SMTP_RESP_250 "250"
#define SMTP_RESP_334 "334"
#define SMTP_RESP_354 "354"
#define SMTP_RESP_LOGIN_UNAME "VXNlcm5hbWU6"
#define SMTP_RESP_LOGIN_PASS "UGFzc3dvcmQ6"
#define SMTP_KEYWORD_AUTH_SP "AUTH "
#define SMTP_KEYWORD_AUTH_EQ "AUTH="
#define SMTP_KEYWORD_AUTH_LEN 5
#define SMTP_AUTH_PARAM_PLAIN "PLAIN"
#define SMTP_AUTH_PARAM_LOGIN "LOGIN"
#define SMTP_CMD_EHLO_1 "EHLO ["
#define SMTP_CMD_EHLO_1_LEN 6
#define SMTP_CMD_EHLO_2 "]\r\n"
#define SMTP_CMD_EHLO_2_LEN 3
#define SMTP_CMD_AUTHPLAIN_1 "AUTH PLAIN "
#define SMTP_CMD_AUTHPLAIN_1_LEN 11
#define SMTP_CMD_AUTHPLAIN_2 "\r\n"
#define SMTP_CMD_AUTHPLAIN_2_LEN 2
#define SMTP_CMD_AUTHLOGIN "AUTH LOGIN\r\n"
#define SMTP_CMD_AUTHLOGIN_LEN 12
#define SMTP_CMD_MAIL_1 "MAIL FROM: <"
#define SMTP_CMD_MAIL_1_LEN 12
#define SMTP_CMD_MAIL_2 ">\r\n"
#define SMTP_CMD_MAIL_2_LEN 3
#define SMTP_CMD_RCPT_1 "RCPT TO: <"
#define SMTP_CMD_RCPT_1_LEN 10
#define SMTP_CMD_RCPT_2 ">\r\n"
#define SMTP_CMD_RCPT_2_LEN 3
#define SMTP_CMD_DATA "DATA\r\n"
#define SMTP_CMD_DATA_LEN 6
#define SMTP_CMD_HEADER_1 "From: <"
#define SMTP_CMD_HEADER_1_LEN 7
#define SMTP_CMD_HEADER_2 ">\r\nTo: <"
#define SMTP_CMD_HEADER_2_LEN 8
#define SMTP_CMD_HEADER_3 ">\r\nSubject: "
#define SMTP_CMD_HEADER_3_LEN 12
#define SMTP_CMD_HEADER_4 "\r\n\r\n"
#define SMTP_CMD_HEADER_4_LEN 4
#define SMTP_CMD_BODY_FINISHED "\r\n.\r\n"
#define SMTP_CMD_BODY_FINISHED_LEN 5
#define SMTP_CMD_QUIT "QUIT\r\n"
#define SMTP_CMD_QUIT_LEN 6
#if defined(SMTP_STAT_TX_BUF_MAX) && SMTP_STAT_TX_BUF_MAX
#define SMTP_TX_BUF_MAX(len) LWIP_MACRO(if((len) > smtp_tx_buf_len_max) smtp_tx_buf_len_max = (len);)
#else /* SMTP_STAT_TX_BUF_MAX */
#define SMTP_TX_BUF_MAX(len)
#endif /* SMTP_STAT_TX_BUF_MAX */
#if SMTP_COPY_AUTHDATA
#define SMTP_USERNAME(session) (session)->username
#define SMTP_PASS(session) (session)->pass
#define SMTP_AUTH_PLAIN_DATA(session) (session)->auth_plain
#define SMTP_AUTH_PLAIN_LEN(session) (session)->auth_plain_len
#else /* SMTP_COPY_AUTHDATA */
#define SMTP_USERNAME(session) smtp_username
#define SMTP_PASS(session) smtp_pass
#define SMTP_AUTH_PLAIN_DATA(session) smtp_auth_plain
#define SMTP_AUTH_PLAIN_LEN(session) smtp_auth_plain_len
#endif /* SMTP_COPY_AUTHDATA */
/* Memory allocation/deallocation can be overridden... */
#ifndef SMTP_STATE_MALLOC
#define SMTP_STATE_MALLOC(size) mem_malloc(size)
#define SMTP_STATE_FREE(ptr) mem_free(ptr)
#endif
#if SMTP_BODYDH
#ifndef SMTP_BODYDH_MALLOC
#define SMTP_BODYDH_MALLOC(size) mem_malloc(size)
#define SMTP_BODYDH_FREE(ptr) mem_free(ptr)
#endif
/* Some internal state return values */
#define BDHALLDATASENT 2
#define BDHSOMEDATASENT 1
enum bdh_handler_state {
BDH_SENDING, /* Serving the user function generating body content */
BDH_STOP /* User function stopped, closing */
};
#endif
/** State for SMTP client state machine */
enum smtp_session_state {
SMTP_NULL,
SMTP_HELO,
SMTP_AUTH_PLAIN,
SMTP_AUTH_LOGIN_UNAME,
SMTP_AUTH_LOGIN_PASS,
SMTP_AUTH_LOGIN,
SMTP_MAIL,
SMTP_RCPT,
SMTP_DATA,
SMTP_BODY,
SMTP_QUIT,
SMTP_CLOSED
};
#ifdef LWIP_DEBUG
/** State-to-string table for debugging */
const char *smtp_state_str[] = {
"SMTP_NULL",
"SMTP_HELO",
"SMTP_AUTH_PLAIN",
"SMTP_AUTH_LOGIN_UNAME",
"SMTP_AUTH_LOGIN_PASS",
"SMTP_AUTH_LOGIN",
"SMTP_MAIL",
"SMTP_RCPT",
"SMTP_DATA",
"SMTP_BODY",
"SMTP_QUIT",
"SMTP_CLOSED",
};
const char *smtp_result_strs[] = {
"SMTP_RESULT_OK",
"SMTP_RESULT_ERR_UNKNOWN",
"SMTP_RESULT_ERR_CONNECT",
"SMTP_RESULT_ERR_HOSTNAME",
"SMTP_RESULT_ERR_CLOSED",
"SMTP_RESULT_ERR_TIMEOUT",
"SMTP_RESULT_ERR_SVR_RESP",
};
#endif /* LWIP_DEBUG */
#if SMTP_BODYDH
struct smtp_bodydh_state {
smtp_bodycback_fn callback_fn; /* The function to call (again) */
u16_t state;
struct smtp_bodydh exposed; /* the user function structure */
};
#endif /* SMTP_BODYDH */
/** struct keeping the body and state of an smtp session */
struct smtp_session {
/** keeping the state of the smtp session */
enum smtp_session_state state;
/** timeout handling, if this reaches 0, the connection is closed */
u16_t timer;
/** helper buffer for transmit, not used for sending body */
char tx_buf[SMTP_TX_BUF_LEN + 1];
struct pbuf* p;
/** source email address */
const char* from;
/** size of the sourceemail address */
u16_t from_len;
/** target email address */
const char* to;
/** size of the target email address */
u16_t to_len;
/** subject of the email */
const char *subject;
/** length of the subject string */
u16_t subject_len;
/** this is the body of the mail to be sent */
const char* body;
/** this is the length of the body to be sent */
u16_t body_len;
/** amount of data from body already sent */
u16_t body_sent;
/** callback function to call when closed */
smtp_result_fn callback_fn;
/** argument for callback function */
void *callback_arg;
#if SMTP_COPY_AUTHDATA
/** Username to use for this request */
char *username;
/** Password to use for this request */
char *pass;
/** Username and password combined as necessary for PLAIN authentication */
char auth_plain[SMTP_MAX_USERNAME_LEN + SMTP_MAX_PASS_LEN + 3];
/** Length of smtp_auth_plain string (cannot use strlen since it includes \0) */
size_t auth_plain_len;
#endif /* SMTP_COPY_AUTHDATA */
#if SMTP_BODYDH
struct smtp_bodydh_state *bodydh;
#endif /* SMTP_BODYDH */
};
/** IP address or DNS name of the server to use for next SMTP request */
static char smtp_server[SMTP_MAX_SERVERNAME_LEN + 1];
/** TCP port of the server to use for next SMTP request */
static u16_t smtp_server_port = SMTP_DEFAULT_PORT;
/** Username to use for the next SMTP request */
static char *smtp_username;
/** Password to use for the next SMTP request */
static char *smtp_pass;
/** Username and password combined as necessary for PLAIN authentication */
static char smtp_auth_plain[SMTP_MAX_USERNAME_LEN + SMTP_MAX_PASS_LEN + 3];
/** Length of smtp_auth_plain string (cannot use strlen since it includes \0) */
static size_t smtp_auth_plain_len;
static err_t smtp_verify(const char *data, size_t data_len, u8_t linebreaks_allowed);
static err_t smtp_tcp_recv(void *arg, struct tcp_pcb *pcb, struct pbuf *p, err_t err);
static void smtp_tcp_err(void *arg, err_t err);
static err_t smtp_tcp_poll(void *arg, struct tcp_pcb *pcb);
static err_t smtp_tcp_sent(void *arg, struct tcp_pcb *pcb, u16_t len);
static err_t smtp_tcp_connected(void *arg, struct tcp_pcb *pcb, err_t err);
#if LWIP_DNS
static void smtp_dns_found(const char* hostname, const ip_addr_t *ipaddr, void *arg);
#endif /* LWIP_DNS */
static size_t smtp_base64_encode(char* target, size_t target_len, const char* source, size_t source_len);
static enum smtp_session_state smtp_prepare_mail(struct smtp_session *s, u16_t *tx_buf_len);
static void smtp_send_body(struct smtp_session *s, struct tcp_pcb *pcb);
static void smtp_process(void *arg, struct tcp_pcb *pcb, struct pbuf *p);
#if SMTP_BODYDH
static void smtp_send_body_data_handler(struct smtp_session *s, struct tcp_pcb *pcb);
#endif /* SMTP_BODYDH */
#ifdef LWIP_DEBUG
/** Convert an smtp result to a string */
const char*
smtp_result_str(u8_t smtp_result)
{
if (smtp_result > SMTP_RESULT_ERR_SVR_RESP) {
return "UNKNOWN";
}
return smtp_result_strs[smtp_result];
}
/** Null-terminates the payload of p for printing out messages.
* WARNING: use this only if p is not needed any more as the last byte of
* payload is deleted!
*/
static const char*
smtp_pbuf_str(struct pbuf* p)
{
if ((p == NULL) || (p->len == 0)) {
return "";
}
((char*)p->payload)[p->len] = 0;
return (const char*)p->payload;
}
#endif /* LWIP_DEBUG */
/** Set IP address or DNS name for next SMTP connection
*
* @param server IP address (in ASCII representation) or DNS name of the server
*/
void
smtp_set_server_addr(const char* server)
{
size_t len = 0;
if (server != NULL) {
len = strlen(server);
}
if (len > SMTP_MAX_SERVERNAME_LEN) {
len = SMTP_MAX_SERVERNAME_LEN;
}
MEMCPY(smtp_server, server, len);
}
/** Set TCP port for next SMTP connection
*
* @param port TCP port
*/
void
smtp_set_server_port(u16_t port)
{
smtp_server_port = port;
}
/** Set authentication parameters for next SMTP connection
*
* @param username login name as passed to the server
* @param pass password passed to the server together with username
*/
err_t
smtp_set_auth(const char* username, const char* pass)
{
size_t uname_len = 0;
size_t pass_len = 0;
memset(smtp_auth_plain, 0xfa, 64);
if (username != NULL) {
uname_len = strlen(username);
if (uname_len > SMTP_MAX_USERNAME_LEN) {
LWIP_DEBUGF(SMTP_DEBUG_SERIOUS, ("Username is too long, %d instead of %d\n",
(int)uname_len, SMTP_MAX_USERNAME_LEN));
return ERR_ARG;
}
}
if (pass != NULL) {
#if SMTP_SUPPORT_AUTH_LOGIN || SMTP_SUPPORT_AUTH_PLAIN
pass_len = strlen(pass);
if (pass_len > SMTP_MAX_PASS_LEN) {
LWIP_DEBUGF(SMTP_DEBUG_SERIOUS, ("Password is too long, %d instead of %d\n",
(int)uname_len, SMTP_MAX_USERNAME_LEN));
return ERR_ARG;
}
#else /* SMTP_SUPPORT_AUTH_LOGIN || SMTP_SUPPORT_AUTH_PLAIN */
LWIP_DEBUGF(SMTP_DEBUG_WARN, ("Password not supported as no authentication methods are activated\n"));
#endif /* SMTP_SUPPORT_AUTH_LOGIN || SMTP_SUPPORT_AUTH_PLAIN */
}
*smtp_auth_plain = 0;
if (username != NULL) {
smtp_username = smtp_auth_plain + 1;
strcpy(smtp_username, username);
}
if (pass != NULL) {
smtp_pass = smtp_auth_plain + uname_len + 2;
strcpy(smtp_pass, pass);
}
smtp_auth_plain_len = uname_len + pass_len + 2;
return ERR_OK;
}
#if SMTP_BODYDH
static void smtp_free_struct(struct smtp_session *s)
{
if (s->bodydh != NULL) {
SMTP_BODYDH_FREE(s->bodydh);
}
SMTP_STATE_FREE(s);
}
#else /* SMTP_BODYDH */
#define smtp_free_struct(x) SMTP_STATE_FREE(x)
#endif /* SMTP_BODYDH */
static struct tcp_pcb*
smtp_setup_pcb(struct smtp_session *s, const ip_addr_t* remote_ip)
{
struct tcp_pcb* pcb;
LWIP_UNUSED_ARG(remote_ip);
pcb = tcp_new_ip_type(IP_GET_TYPE(remote_ip));
if (pcb != NULL) {
tcp_arg(pcb, s);
tcp_recv(pcb, smtp_tcp_recv);
tcp_err(pcb, smtp_tcp_err);
tcp_poll(pcb, smtp_tcp_poll, SMTP_POLL_INTERVAL);
tcp_sent(pcb, smtp_tcp_sent);
}
return pcb;
}
/** The actual mail-sending function, called by smtp_send_mail and
* smtp_send_mail_static after setting up the struct smtp_session.
*/
static err_t
smtp_send_mail_alloced(struct smtp_session *s)
{
err_t err;
struct tcp_pcb* pcb = NULL;
ip_addr_t addr;
LWIP_ASSERT("no smtp_session supplied", s != NULL);
#if SMTP_CHECK_DATA
/* check that body conforms to RFC:
* - convert all single-CR or -LF in body to CRLF
* - only 7-bit ASCII is allowed
*/
if (smtp_verify(s->to, s->to_len, 0) != ERR_OK) {
return ERR_ARG;
}
if (smtp_verify(s->from, s->from_len, 0) != ERR_OK) {
return ERR_ARG;
}
if (smtp_verify(s->subject, s->subject_len, 0) != ERR_OK) {
return ERR_ARG;
}
#if SMTP_BODYDH
if (s->bodydh == NULL)
#endif /* SMTP_BODYDH */
{
if (smtp_verify(s->body, s->body_len, 0) != ERR_OK) {
return ERR_ARG;
}
}
#endif /* SMTP_CHECK_DATA */
#if SMTP_COPY_AUTHDATA
/* copy auth data, ensuring the first byte is always zero */
MEMCPY(s->auth_plain + 1, smtp_auth_plain + 1, smtp_auth_plain_len - 1);
s->auth_plain_len = smtp_auth_plain_len;
/* default username and pass is empty string */
s->username = s->auth_plain;
s->pass = s->auth_plain;
if (smtp_username != NULL) {
s->username += smtp_username - smtp_auth_plain;
}
if (smtp_pass != NULL) {
s->pass += smtp_pass - smtp_auth_plain;
}
#endif /* SMTP_COPY_AUTHDATA */
s->state = SMTP_NULL;
s->timer = SMTP_TIMEOUT;
#if LWIP_DNS
err = dns_gethostbyname(smtp_server, &addr, smtp_dns_found, s);
#else /* LWIP_DNS */
err = ipaddr_aton(smtp_server, &addr) ? ERR_OK : ERR_ARG;
#endif /* LWIP_DNS */
if (err == ERR_OK) {
pcb = smtp_setup_pcb(s, &addr);
if (pcb == NULL) {
err = ERR_MEM;
goto leave;
}
err = tcp_connect(pcb, &addr, smtp_server_port, smtp_tcp_connected);
if (err != ERR_OK) {
LWIP_DEBUGF(SMTP_DEBUG_WARN_STATE, ("tcp_connect failed: %d\n", (int)err));
goto deallocate_and_leave;
}
} else if (err != ERR_INPROGRESS) {
LWIP_DEBUGF(SMTP_DEBUG_WARN_STATE, ("dns_gethostbyname failed: %d\n", (int)err));
goto deallocate_and_leave;
}
return ERR_OK;
deallocate_and_leave:
if (pcb != NULL) {
tcp_arg(pcb, NULL);
tcp_close(pcb);
}
leave:
smtp_free_struct(s);
/* no need to call the callback here since we return != ERR_OK */
return err;
}
/** Send an email via the currently selected server, username and password.
*
* @param from source email address (must be NULL-terminated)
* @param to target email address (must be NULL-terminated)
* @param subject email subject (must be NULL-terminated)
* @param body email body (must be NULL-terminated)
* @param callback_fn callback function
* @param callback_arg user argument to callback_fn
* @returns - ERR_OK if structures were allocated and no error occured starting the connection
* (this does not mean the email has been successfully sent!)
* - another err_t on error.
*/
err_t
smtp_send_mail(const char* from, const char* to, const char* subject, const char* body,
smtp_result_fn callback_fn, void* callback_arg)
{
struct smtp_session* s;
size_t from_len = strlen(from);
size_t to_len = strlen(to);
size_t subject_len = strlen(subject);
size_t body_len = strlen(body);
size_t mem_len = sizeof(struct smtp_session);
char *sfrom, *sto, *ssubject, *sbody;
mem_len += from_len + to_len + subject_len + body_len + 4;
if (mem_len > 0xffff) {
/* too long! */
return ERR_MEM;
}
/* Allocate memory to keep this email's session state */
s = (struct smtp_session *)SMTP_STATE_MALLOC((mem_size_t)mem_len);
if (s == NULL) {
return ERR_MEM;
}
/* initialize the structure */
memset(s, 0, mem_len);
s->from = sfrom = (char*)s + sizeof(struct smtp_session);
s->from_len = (u16_t)from_len;
s->to = sto = sfrom + from_len + 1;
s->to_len = (u16_t)to_len;
s->subject = ssubject = sto + to_len + 1;
s->subject_len = (u16_t)subject_len;
s->body = sbody = ssubject + subject_len + 1;
s->body_len = (u16_t)body_len;
/* copy source and target email address */
/* cast to size_t is a hack to cast away constness */
MEMCPY(sfrom, from, from_len + 1);
MEMCPY(sto, to, to_len + 1);
MEMCPY(ssubject, subject, subject_len + 1);
MEMCPY(sbody, body, body_len + 1);
s->callback_fn = callback_fn;
s->callback_arg = callback_arg;
/* call the actual implementation of this function */
return smtp_send_mail_alloced(s);
}
/** Same as smtp_send_mail, but doesn't copy from, to, subject and body into
* an internal buffer to save memory.
* WARNING: the above data must stay untouched until the callback function is
* called (unless the function returns != ERR_OK)
*/
err_t
smtp_send_mail_static(const char *from, const char* to, const char* subject,
const char* body, smtp_result_fn callback_fn, void* callback_arg)
{
struct smtp_session* s;
size_t len;
s = (struct smtp_session*)SMTP_STATE_MALLOC(sizeof(struct smtp_session));
if (s == NULL) {
return ERR_MEM;
}
memset(s, 0, sizeof(struct smtp_session));
/* initialize the structure */
s->from = from;
len = strlen(from);
LWIP_ASSERT("string is too long", len <= 0xffff);
s->from_len = (u16_t)len;
s->to = to;
len = strlen(to);
LWIP_ASSERT("string is too long", len <= 0xffff);
s->to_len = (u16_t)len;
s->subject = subject;
len = strlen(subject);
LWIP_ASSERT("string is too long", len <= 0xffff);
s->subject_len = (u16_t)len;
s->body = body;
len = strlen(body);
LWIP_ASSERT("string is too long", len <= 0xffff);
s->body_len = (u16_t)len;
s->callback_fn = callback_fn;
s->callback_arg = callback_arg;
/* call the actual implementation of this function */
return smtp_send_mail_alloced(s);
}
/** Same as smpt_send_mail but takes a struct smtp_send_request as single
* parameter which contains all the other parameters.
* To be used with tcpip_callback to send mail from interrupt context or from
* another thread.
*
* WARNING: server and authentication must stay untouched until this function has run!
*
* Usage example:
* - allocate a struct smtp_send_request (in a way that is allowed in interrupt context)
* - fill the members of the struct as if calling smtp_send_mail
* - specify a callback_function
* - set callback_arg to the structure itself
* - call this function
* - wait for the callback function to be called
* - in the callback function, deallocate the structure (passed as arg)
*/
void
smtp_send_mail_int(void *arg)
{
struct smtp_send_request *req = (struct smtp_send_request*)arg;
err_t err;
LWIP_ASSERT("smtp_send_mail_int: no argument given", arg != NULL);
if (req->static_data) {
err = smtp_send_mail_static(req->from, req->to, req->subject, req->body,
req->callback_fn, req->callback_arg);
} else {
err = smtp_send_mail(req->from, req->to, req->subject, req->body,
req->callback_fn, req->callback_arg);
}
if ((err != ERR_OK) && (req->callback_fn != NULL)) {
req->callback_fn(req->callback_arg, SMTP_RESULT_ERR_UNKNOWN, 0, err);
}
}
#if SMTP_CHECK_DATA
/** Verify that a given string conforms to the SMTP rules
* (7-bit only, no single CR or LF,
* @todo: no line consisting of a single dot only)
*/
static err_t
smtp_verify(const char *data, size_t data_len, u8_t linebreaks_allowed)
{
size_t i;
u8_t last_was_cr = 0;
for (i = 0; i < data_len; i++) {
char current = data[i];
if ((current & 0x80) != 0) {
LWIP_DEBUGF(SMTP_DEBUG_WARN, ("smtp_verify: no 8-bit data supported: %s\n", data));
return ERR_ARG;
}
if (current == '\r') {
if (!linebreaks_allowed) {
LWIP_DEBUGF(SMTP_DEBUG_WARN, ("smtp_verify: found CR where no linebreaks allowed: %s\n", data));
return ERR_ARG;
}
if (last_was_cr) {
LWIP_DEBUGF(SMTP_DEBUG_WARN, ("smtp_verify: found double CR: %s\n", data));
return ERR_ARG;
}
last_was_cr = 1;
} else {
if (current == '\n') {
if (!last_was_cr) {
LWIP_DEBUGF(SMTP_DEBUG_WARN, ("smtp_verify: found LF without CR before: %s\n", data));
return ERR_ARG;
}
}
last_was_cr = 0;
}
}
return ERR_OK;
}
#endif /* SMTP_CHECK_DATA */
/** Frees the smpt_session and calls the callback function */
static void
smtp_free(struct smtp_session *s, u8_t result, u16_t srv_err, err_t err)
{
smtp_result_fn fn = s->callback_fn;
void *arg = s->callback_arg;
if (s->p != NULL) {
pbuf_free(s->p);
}
smtp_free_struct(s);
if (fn != NULL) {
fn(arg, result, srv_err, err);
}
}
/** Try to close a pcb and free the arg if successful */
static void
smtp_close(struct smtp_session *s, struct tcp_pcb *pcb, u8_t result,
u16_t srv_err, err_t err)
{
if (pcb != NULL) {
tcp_arg(pcb, NULL);
if (tcp_close(pcb) == ERR_OK) {
if (s != NULL) {
smtp_free(s, result, srv_err, err);
}
} else {
/* close failed, set back arg */
tcp_arg(pcb, s);
}
} else {
if (s != NULL) {
smtp_free(s, result, srv_err, err);
}
}
}
/** Raw API TCP err callback: pcb is already deallocated */
static void
smtp_tcp_err(void *arg, err_t err)
{
LWIP_UNUSED_ARG(err);
if (arg != NULL) {
LWIP_DEBUGF(SMTP_DEBUG_WARN_STATE, ("smtp_tcp_err: connection reset by remote host\n"));
smtp_free((struct smtp_session*)arg, SMTP_RESULT_ERR_CLOSED, 0, err);
}
}
/** Raw API TCP poll callback */
static err_t
smtp_tcp_poll(void *arg, struct tcp_pcb *pcb)
{
if (arg != NULL) {
struct smtp_session *s = (struct smtp_session*)arg;
if (s->timer != 0) {
s->timer--;
}
}
smtp_process(arg, pcb, NULL);
return ERR_OK;
}
/** Raw API TCP sent callback */
static err_t
smtp_tcp_sent(void *arg, struct tcp_pcb *pcb, u16_t len)
{
LWIP_UNUSED_ARG(len);
smtp_process(arg, pcb, NULL);
return ERR_OK;
}
/** Raw API TCP recv callback */
static err_t
smtp_tcp_recv(void *arg, struct tcp_pcb *pcb, struct pbuf *p, err_t err)
{
LWIP_UNUSED_ARG(err);
if (p != NULL) {
tcp_recved(pcb, p->tot_len);
smtp_process(arg, pcb, p);
} else {
LWIP_DEBUGF(SMTP_DEBUG_WARN_STATE, ("smtp_tcp_recv: connection closed by remote host\n"));
smtp_close((struct smtp_session*)arg, pcb, SMTP_RESULT_ERR_CLOSED, 0, err);
}
return ERR_OK;
}
static err_t
smtp_tcp_connected(void *arg, struct tcp_pcb *pcb, err_t err)
{
LWIP_UNUSED_ARG(arg);
if (err == ERR_OK) {
LWIP_DEBUGF(SMTP_DEBUG_STATE, ("smtp_connected: Waiting for 220\n"));
} else {
/* shouldn't happen, but we still check 'err', only to be sure */
LWIP_DEBUGF(SMTP_DEBUG_WARN, ("smtp_connected: %d\n", (int)err));
smtp_close((struct smtp_session*)arg, pcb, SMTP_RESULT_ERR_CONNECT, 0, err);
}
return ERR_OK;
}
#if LWIP_DNS
/** DNS callback
* If ipaddr is non-NULL, resolving succeeded, otherwise it failed.
*/
static void
smtp_dns_found(const char* hostname, const ip_addr_t *ipaddr, void *arg)
{
struct smtp_session *s = (struct smtp_session*)arg;
struct tcp_pcb *pcb;
err_t err;
u8_t result;
LWIP_UNUSED_ARG(hostname);
if (ipaddr != NULL) {
pcb = smtp_setup_pcb(s, ipaddr);
if (pcb != NULL) {
LWIP_DEBUGF(SMTP_DEBUG_STATE, ("smtp_dns_found: hostname resolved, connecting\n"));
err = tcp_connect(pcb, ipaddr, smtp_server_port, smtp_tcp_connected);
if (err == ERR_OK) {
return;
}
LWIP_DEBUGF(SMTP_DEBUG_WARN_STATE, ("tcp_connect failed: %d\n", (int)err));
result = SMTP_RESULT_ERR_CONNECT;
} else {
LWIP_DEBUGF(SMTP_DEBUG_STATE, ("smtp_dns_found: failed to allocate tcp pcb\n"));
result = SMTP_RESULT_ERR_MEM;
err = ERR_MEM;
}
} else {
LWIP_DEBUGF(SMTP_DEBUG_WARN_STATE, ("smtp_dns_found: failed to resolve hostname: %s\n",
hostname));
pcb = NULL;
result = SMTP_RESULT_ERR_HOSTNAME;
err = ERR_ARG;
}
smtp_close(s, pcb, result, 0, err);
}
#endif /* LWIP_DNS */
#if SMTP_SUPPORT_AUTH_PLAIN || SMTP_SUPPORT_AUTH_LOGIN
/** Table 6-bit-index-to-ASCII used for base64-encoding */
const u8_t base64_table[] = {
'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H',
'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P',
'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z',
'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h',
'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p',
'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z',
'0', '1', '2', '3', '4', '5', '6', '7', '8', '9',
'+', '/'
};
/** Base64 encoding */
static size_t
smtp_base64_encode(char* target, size_t target_len, const char* source, size_t source_len)
{
size_t i;
s8_t j;
size_t target_idx = 0;
size_t longer = (source_len % 3) ? (3 - (source_len % 3)) : 0;
size_t source_len_b64 = source_len + longer;
size_t len = (((source_len_b64) * 4) / 3);
u8_t x = 5;
u8_t current = 0;
LWIP_UNUSED_ARG(target_len);
LWIP_ASSERT("target_len is too short", target_len >= len);
for (i = 0; i < source_len_b64; i++) {
u8_t b = (i < source_len ? source[i] : 0);
for (j = 7; j >= 0; j--, x--) {
u8_t shift = ((b & (1 << j)) != 0) ? 1 : 0;
current |= shift << x;
if (x == 0) {
target[target_idx++] = base64_table[current];
x = 6;
current = 0;
}
}
}
for (i = len - longer; i < len; i++) {
target[i] = '=';
}
return len;
}
#endif /* SMTP_SUPPORT_AUTH_PLAIN || SMTP_SUPPORT_AUTH_LOGIN */
/** Parse pbuf to see if it contains the beginning of an answer.
* If so, it returns the contained response code as number between 1 and 999.
* If not, zero is returned.
*
* @param s smtp session struct
*/
static u16_t
smtp_is_response(struct smtp_session *s)
{
char digits[4];
long num;
if (s->p == NULL) {
return 0;
}
/* copy three digits and convert them to int */
if (pbuf_copy_partial(s->p, digits, 3, 0) != 3) {
/* pbuf was too short */
return 0;
}
digits[3] = 0;
num = strtol(digits, NULL, 10);
if ((num <= 0) || (num >= 1000)) {
/* failed to find response code at start of line */
return 0;
}
return (u16_t)num;
}
/** Parse pbuf to see if it contains a fully received answer.
* If one is found, ERR_OK is returned.
* If none is found, ERR_VAL is returned.
*
* A fully received answer is a 3-digit number followed by a space,
* some string and a CRLF as line ending.
*
* @param s smtp session struct
*/
static err_t
smtp_is_response_finished(struct smtp_session *s)
{
u8_t sp;
u16_t crlf;
u16_t offset;
if (s->p == NULL) {
return ERR_VAL;
}
offset = 0;
again:
/* We could check the response number here, but we trust the
* protocol definition which says the client can rely on it being
* the same on every line. */
/* find CRLF */
crlf = pbuf_memfind(s->p, SMTP_CRLF, SMTP_CRLF_LEN, offset + 4);
if (crlf == 0xFFFF) {
/* no CRLF found */
return ERR_VAL;
}
sp = pbuf_get_at(s->p, offset + 3);
if (sp == '-') {
/* no space after response code -> try next line */
offset = crlf + 2;
goto again;
} else if (sp == ' ') {
/* CRLF found after response code + space -> valid response */
return ERR_OK;
}
/* sp contains invalid character */
return ERR_VAL;
}
/** Prepare HELO/EHLO message */
static enum smtp_session_state
smtp_prepare_helo(struct smtp_session *s, u16_t *tx_buf_len, struct tcp_pcb *pcb)
{
size_t ipa_len;
const char *ipa = ipaddr_ntoa(&pcb->local_ip);
LWIP_ASSERT("ipaddr_ntoa returned NULL", ipa != NULL);
ipa_len = strlen(ipa);
LWIP_ASSERT("string too long", ipa_len <= (SMTP_TX_BUF_LEN-SMTP_CMD_EHLO_1_LEN-SMTP_CMD_EHLO_2_LEN));
*tx_buf_len = SMTP_CMD_EHLO_1_LEN + (u16_t)ipa_len + SMTP_CMD_EHLO_2_LEN;
LWIP_ASSERT("tx_buf overflow detected", *tx_buf_len <= SMTP_TX_BUF_LEN);
SMEMCPY(s->tx_buf, SMTP_CMD_EHLO_1, SMTP_CMD_EHLO_1_LEN);
MEMCPY(&s->tx_buf[SMTP_CMD_EHLO_1_LEN], ipa, ipa_len);
SMEMCPY(&s->tx_buf[SMTP_CMD_EHLO_1_LEN + ipa_len], SMTP_CMD_EHLO_2, SMTP_CMD_EHLO_2_LEN);
return SMTP_HELO;
}
#if SMTP_SUPPORT_AUTH_PLAIN || SMTP_SUPPORT_AUTH_LOGIN
/** Parse last server response (in rx_buf) for supported authentication method,
* create data to send out (to tx_buf), set tx_data_len correctly
* and return the next state.
*/
static enum smtp_session_state
smtp_prepare_auth_or_mail(struct smtp_session *s, u16_t *tx_buf_len)
{
/* check response for supported authentication method */
u16_t auth = pbuf_strstr(s->p, SMTP_KEYWORD_AUTH_SP);
if (auth == 0xFFFF) {
auth = pbuf_strstr(s->p, SMTP_KEYWORD_AUTH_EQ);
}
if (auth != 0xFFFF) {
u16_t crlf = pbuf_memfind(s->p, SMTP_CRLF, SMTP_CRLF_LEN, auth);
if ((crlf != 0xFFFF) && (crlf > auth)) {
/* use tx_buf temporarily */
u16_t copied = pbuf_copy_partial(s->p, s->tx_buf, crlf - auth, auth);
if (copied != 0) {
char *sep = s->tx_buf + SMTP_KEYWORD_AUTH_LEN;
s->tx_buf[copied] = 0;
#if SMTP_SUPPORT_AUTH_PLAIN
/* favour PLAIN over LOGIN since it involves less requests */
if (strstr(sep, SMTP_AUTH_PARAM_PLAIN) != NULL) {
size_t auth_len;
/* server supports AUTH PLAIN */
SMEMCPY(s->tx_buf, SMTP_CMD_AUTHPLAIN_1, SMTP_CMD_AUTHPLAIN_1_LEN);
/* add base64-encoded string "\0username\0password" */
auth_len = smtp_base64_encode(&s->tx_buf[SMTP_CMD_AUTHPLAIN_1_LEN],
SMTP_TX_BUF_LEN - SMTP_CMD_AUTHPLAIN_1_LEN, SMTP_AUTH_PLAIN_DATA(s),
SMTP_AUTH_PLAIN_LEN(s));
LWIP_ASSERT("string too long", auth_len <= (SMTP_TX_BUF_LEN-SMTP_CMD_AUTHPLAIN_1_LEN-SMTP_CMD_AUTHPLAIN_2_LEN));
*tx_buf_len = SMTP_CMD_AUTHPLAIN_1_LEN + SMTP_CMD_AUTHPLAIN_2_LEN + (u16_t)auth_len;
SMEMCPY(&s->tx_buf[SMTP_CMD_AUTHPLAIN_1_LEN + auth_len], SMTP_CMD_AUTHPLAIN_2,
SMTP_CMD_AUTHPLAIN_2_LEN);
return SMTP_AUTH_PLAIN;
} else
#endif /* SMTP_SUPPORT_AUTH_PLAIN */
{
#if SMTP_SUPPORT_AUTH_LOGIN
if (strstr(sep, SMTP_AUTH_PARAM_LOGIN) != NULL) {
/* server supports AUTH LOGIN */
*tx_buf_len = SMTP_CMD_AUTHLOGIN_LEN;
SMEMCPY(s->tx_buf, SMTP_CMD_AUTHLOGIN, SMTP_CMD_AUTHLOGIN_LEN);
return SMTP_AUTH_LOGIN_UNAME;
}
#endif /* SMTP_SUPPORT_AUTH_LOGIN */
}
}
}
}
/* server didnt's send correct keywords for AUTH, try sending directly */
return smtp_prepare_mail(s, tx_buf_len);
}
#endif /* SMTP_SUPPORT_AUTH_PLAIN || SMTP_SUPPORT_AUTH_LOGIN */
#if SMTP_SUPPORT_AUTH_LOGIN
/** Send base64-encoded username */
static enum smtp_session_state
smtp_prepare_auth_login_uname(struct smtp_session *s, u16_t *tx_buf_len)
{
size_t base64_len = smtp_base64_encode(s->tx_buf, SMTP_TX_BUF_LEN,
SMTP_USERNAME(s), strlen(SMTP_USERNAME(s)));
/* @todo: support base64-encoded longer than 64k */
LWIP_ASSERT("string too long", base64_len <= 0xffff);
LWIP_ASSERT("tx_buf overflow detected", base64_len + SMTP_CRLF_LEN <= SMTP_TX_BUF_LEN);
*tx_buf_len = (u16_t)base64_len + SMTP_CRLF_LEN;
SMEMCPY(&s->tx_buf[base64_len], SMTP_CRLF, SMTP_CRLF_LEN);
s->tx_buf[*tx_buf_len] = 0;
return SMTP_AUTH_LOGIN_PASS;
}
/** Send base64-encoded password */
static enum smtp_session_state
smtp_prepare_auth_login_pass(struct smtp_session *s, u16_t *tx_buf_len)
{
size_t base64_len = smtp_base64_encode(s->tx_buf, SMTP_TX_BUF_LEN,
SMTP_PASS(s), strlen(SMTP_PASS(s)));
/* @todo: support base64-encoded longer than 64k */
LWIP_ASSERT("string too long", base64_len <= 0xffff);
LWIP_ASSERT("tx_buf overflow detected", base64_len + SMTP_CRLF_LEN <= SMTP_TX_BUF_LEN);
*tx_buf_len = (u16_t)base64_len + SMTP_CRLF_LEN;
SMEMCPY(&s->tx_buf[base64_len], SMTP_CRLF, SMTP_CRLF_LEN);
s->tx_buf[*tx_buf_len] = 0;
return SMTP_AUTH_LOGIN;
}
#endif /* SMTP_SUPPORT_AUTH_LOGIN */
/** Prepare MAIL message */
static enum smtp_session_state
smtp_prepare_mail(struct smtp_session *s, u16_t *tx_buf_len)
{
char *target = s->tx_buf;
*tx_buf_len = SMTP_CMD_MAIL_1_LEN + SMTP_CMD_MAIL_2_LEN + s->from_len;
LWIP_ASSERT("tx_buf overflow detected", *tx_buf_len <= SMTP_TX_BUF_LEN);
target[*tx_buf_len] = 0;
SMEMCPY(target, SMTP_CMD_MAIL_1, SMTP_CMD_MAIL_1_LEN);
target += SMTP_CMD_MAIL_1_LEN;
MEMCPY(target, s->from, s->from_len);
target += s->from_len;
SMEMCPY(target, SMTP_CMD_MAIL_2, SMTP_CMD_MAIL_2_LEN);
return SMTP_MAIL;
}
/** Prepare RCPT message */
static enum smtp_session_state
smtp_prepare_rcpt(struct smtp_session *s, u16_t *tx_buf_len)
{
char *target = s->tx_buf;
*tx_buf_len = SMTP_CMD_RCPT_1_LEN + SMTP_CMD_RCPT_2_LEN + s->to_len;
LWIP_ASSERT("tx_buf overflow detected", *tx_buf_len <= SMTP_TX_BUF_LEN);
target[*tx_buf_len] = 0;
SMEMCPY(target, SMTP_CMD_RCPT_1, SMTP_CMD_RCPT_1_LEN);
target += SMTP_CMD_RCPT_1_LEN;
MEMCPY(target, s->to, s->to_len);
target += s->to_len;
SMEMCPY(target, SMTP_CMD_RCPT_2, SMTP_CMD_RCPT_2_LEN);
return SMTP_RCPT;
}
/** Prepare header of body */
static enum smtp_session_state
smtp_prepare_header(struct smtp_session *s, u16_t *tx_buf_len)
{
char *target = s->tx_buf;
*tx_buf_len = SMTP_CMD_HEADER_1_LEN + SMTP_CMD_HEADER_2_LEN +
SMTP_CMD_HEADER_3_LEN + SMTP_CMD_HEADER_4_LEN + s->from_len + s->to_len +
s->subject_len;
LWIP_ASSERT("tx_buf overflow detected", *tx_buf_len <= SMTP_TX_BUF_LEN);
target[*tx_buf_len] = 0;
SMEMCPY(target, SMTP_CMD_HEADER_1, SMTP_CMD_HEADER_1_LEN);
target += SMTP_CMD_HEADER_1_LEN;
MEMCPY(target, s->from, s->from_len);
target += s->from_len;
SMEMCPY(target, SMTP_CMD_HEADER_2, SMTP_CMD_HEADER_2_LEN);
target += SMTP_CMD_HEADER_2_LEN;
MEMCPY(target, s->to, s->to_len);
target += s->to_len;
SMEMCPY(target, SMTP_CMD_HEADER_3, SMTP_CMD_HEADER_3_LEN);
target += SMTP_CMD_HEADER_3_LEN;
MEMCPY(target, s->subject, s->subject_len);
target += s->subject_len;
SMEMCPY(target, SMTP_CMD_HEADER_4, SMTP_CMD_HEADER_4_LEN);
return SMTP_BODY;
}
/** Prepare QUIT message */
static enum smtp_session_state
smtp_prepare_quit(struct smtp_session *s, u16_t *tx_buf_len)
{
*tx_buf_len = SMTP_CMD_QUIT_LEN;
s->tx_buf[*tx_buf_len] = 0;
SMEMCPY(s->tx_buf, SMTP_CMD_QUIT, SMTP_CMD_QUIT_LEN);
LWIP_ASSERT("tx_buf overflow detected", *tx_buf_len <= SMTP_TX_BUF_LEN);
return SMTP_CLOSED;
}
/** If in state SMTP_BODY, try to send more body data */
static void
smtp_send_body(struct smtp_session *s, struct tcp_pcb *pcb)
{
err_t err;
if (s->state == SMTP_BODY) {
#if SMTP_BODYDH
if (s->bodydh) {
smtp_send_body_data_handler(s, pcb);
} else
#endif /* SMTP_BODYDH */
{
u16_t send_len = s->body_len - s->body_sent;
if (send_len > 0) {
u16_t snd_buf = tcp_sndbuf(pcb);
if (send_len > snd_buf) {
send_len = snd_buf;
}
if (send_len > 0) {
/* try to send something out */
err = tcp_write(pcb, &s->body[s->body_sent], (u16_t)send_len, TCP_WRITE_FLAG_COPY);
if (err == ERR_OK) {
s->timer = SMTP_TIMEOUT_DATABLOCK;
s->body_sent += send_len;
if (s->body_sent < s->body_len) {
LWIP_DEBUGF(SMTP_DEBUG_STATE, ("smtp_send_body: %d of %d bytes written\n",
s->body_sent, s->body_len));
}
}
}
}
}
if (s->body_sent == s->body_len) {
/* the whole body has been written, write last line */
LWIP_DEBUGF(SMTP_DEBUG_STATE, ("smtp_send_body: body completely written (%d bytes), appending end-of-body\n",
s->body_len));
err = tcp_write(pcb, SMTP_CMD_BODY_FINISHED, SMTP_CMD_BODY_FINISHED_LEN, 0);
if (err == ERR_OK) {
s->timer = SMTP_TIMEOUT_DATATERM;
LWIP_DEBUGF(SMTP_DEBUG_STATE, ("smtp_send_body: end-of-body written, changing state to %s\n",
smtp_state_str[SMTP_QUIT]));
/* last line written, change state, wait for confirmation */
s->state = SMTP_QUIT;
}
}
}
}
/** State machine-like implementation of an SMTP client.
*/
static void
smtp_process(void *arg, struct tcp_pcb *pcb, struct pbuf *p)
{
struct smtp_session* s = (struct smtp_session*)arg;
u16_t response_code = 0;
u16_t tx_buf_len = 0;
enum smtp_session_state next_state;
if (arg == NULL) {
/* already closed SMTP connection */
if (p != NULL) {
LWIP_DEBUGF(SMTP_DEBUG_TRACE, ("Received %d bytes after closing: %s\n",
p->tot_len, smtp_pbuf_str(p)));
pbuf_free(p);
}
return;
}
next_state = s->state;
if (p != NULL) {
/* received data */
if (s->p == NULL) {
s->p = p;
} else {
pbuf_cat(s->p, p);
}
} else {
/* idle timer, close connection if timed out */
if (s->timer == 0) {
LWIP_DEBUGF(SMTP_DEBUG_WARN_STATE, ("smtp_process: connection timed out, closing\n"));
smtp_close(s, pcb, SMTP_RESULT_ERR_TIMEOUT, 0, ERR_TIMEOUT);
return;
}
if (s->state == SMTP_BODY) {
smtp_send_body(s, pcb);
return;
}
}
response_code = smtp_is_response(s);
if (response_code) {
LWIP_DEBUGF(SMTP_DEBUG_TRACE, ("smtp_process: received response code: %d\n", response_code));
if (smtp_is_response_finished(s) != ERR_OK) {
LWIP_DEBUGF(SMTP_DEBUG_TRACE, ("smtp_process: partly received response code: %d\n", response_code));
/* wait for next packet to complete the respone */
return;
}
} else {
if (s->p != NULL) {
LWIP_DEBUGF(SMTP_DEBUG_WARN, ("smtp_process: unknown data received (%s)\n",
smtp_pbuf_str(s->p)));
pbuf_free(s->p);
s->p = NULL;
}
return;
}
switch(s->state)
{
case(SMTP_NULL):
/* wait for 220 */
if (response_code == 220) {
/* then send EHLO */
next_state = smtp_prepare_helo(s, &tx_buf_len, pcb);
}
break;
case(SMTP_HELO):
/* wait for 250 */
if (response_code == 250) {
#if SMTP_SUPPORT_AUTH_PLAIN || SMTP_SUPPORT_AUTH_LOGIN
/* then send AUTH or MAIL */
next_state = smtp_prepare_auth_or_mail(s, &tx_buf_len);
}
break;
case(SMTP_AUTH_LOGIN):
case(SMTP_AUTH_PLAIN):
/* wait for 235 */
if (response_code == 235) {
#endif /* SMTP_SUPPORT_AUTH_PLAIN || SMTP_SUPPORT_AUTH_LOGIN */
/* send MAIL */
next_state = smtp_prepare_mail(s, &tx_buf_len);
}
break;
#if SMTP_SUPPORT_AUTH_LOGIN
case(SMTP_AUTH_LOGIN_UNAME):
/* wait for 334 Username */
if (response_code == 334) {
if (pbuf_strstr(s->p, SMTP_RESP_LOGIN_UNAME) != 0xFFFF) {
/* send username */
next_state = smtp_prepare_auth_login_uname(s, &tx_buf_len);
}
}
break;
case(SMTP_AUTH_LOGIN_PASS):
/* wait for 334 Password */
if (response_code == 334) {
if (pbuf_strstr(s->p, SMTP_RESP_LOGIN_PASS) != 0xFFFF) {
/* send username */
next_state = smtp_prepare_auth_login_pass(s, &tx_buf_len);
}
}
break;
#endif /* SMTP_SUPPORT_AUTH_LOGIN */
case(SMTP_MAIL):
/* wait for 250 */
if (response_code == 250) {
/* send RCPT */
next_state = smtp_prepare_rcpt(s, &tx_buf_len);
}
break;
case(SMTP_RCPT):
/* wait for 250 */
if (response_code == 250) {
/* send DATA */
SMEMCPY(s->tx_buf, SMTP_CMD_DATA, SMTP_CMD_DATA_LEN);
tx_buf_len = SMTP_CMD_DATA_LEN;
next_state = SMTP_DATA;
}
break;
case(SMTP_DATA):
/* wait for 354 */
if (response_code == 354) {
/* send email header */
next_state = smtp_prepare_header(s, &tx_buf_len);
}
break;
case(SMTP_BODY):
/* nothing to be done here, handled somewhere else */
break;
case(SMTP_QUIT):
/* wait for 250 */
if (response_code == 250) {
/* send QUIT */
next_state = smtp_prepare_quit(s, &tx_buf_len);
}
break;
case(SMTP_CLOSED):
/* nothing to do, wait for connection closed from server */
return;
default:
LWIP_DEBUGF(SMTP_DEBUG_SERIOUS, ("Invalid state: %d/%s\n", (int)s->state,
smtp_state_str[s->state]));
break;
}
if (s->state == next_state) {
LWIP_DEBUGF(SMTP_DEBUG_WARN_STATE, ("smtp_process[%s]: unexpected response_code, closing: %d (%s)\n",
smtp_state_str[s->state], response_code, smtp_pbuf_str(s->p)));
/* close connection */
smtp_close(s, pcb, SMTP_RESULT_ERR_SVR_RESP, response_code, ERR_OK);
return;
}
if (tx_buf_len > 0) {
SMTP_TX_BUF_MAX(tx_buf_len);
if (tcp_write(pcb, s->tx_buf, tx_buf_len, TCP_WRITE_FLAG_COPY) == ERR_OK) {
LWIP_DEBUGF(SMTP_DEBUG_TRACE, ("smtp_process[%s]: received command %d (%s)\n",
smtp_state_str[s->state], response_code, smtp_pbuf_str(s->p)));
LWIP_DEBUGF(SMTP_DEBUG_TRACE, ("smtp_process[%s]: sent %"U16_F" bytes: \"%s\"\n",
smtp_state_str[s->state], tx_buf_len, s->tx_buf));
s->timer = SMTP_TIMEOUT;
pbuf_free(s->p);
s->p = NULL;
LWIP_DEBUGF(SMTP_DEBUG_STATE, ("smtp_process: changing state from %s to %s\n",
smtp_state_str[s->state], smtp_state_str[next_state]));
s->state = next_state;
if (next_state == SMTP_BODY) {
/* try to stream-send body data right now */
smtp_send_body(s, pcb);
} else if (next_state == SMTP_CLOSED) {
/* sent out all data, delete structure */
tcp_arg(pcb, NULL);
smtp_free(s, SMTP_RESULT_OK, 0, ERR_OK);
}
}
}
}
#if SMTP_BODYDH
/** Elementary sub-function to send data
*
* @returns: BDHALLDATASENT all data has been written
* BDHSOMEDATASENT some data has been written
* 0 no data has been written
*/
static int
smtp_send_bodyh_data(struct tcp_pcb *pcb, char **from, u16_t *howmany)
{
err_t err;
u16_t len = *howmany;
len = (u16_t)LWIP_MIN(len, tcp_sndbuf(pcb));
err = tcp_write(pcb, *from, len, TCP_WRITE_FLAG_COPY);
if (err == ERR_OK) {
*from += len;
if ((*howmany -= len) > 0) {
return BDHSOMEDATASENT;
}
return BDHALLDATASENT;
}
return 0;
}
/** Same as smtp_send_mail_static, but uses a callback function to send body data
*/
err_t
smtp_send_mail_bodycback(const char *from, const char* to, const char* subject,
smtp_bodycback_fn bodycback_fn, smtp_result_fn callback_fn, void* callback_arg)
{
struct smtp_session* s;
size_t len;
s = (struct smtp_session*)SMTP_STATE_MALLOC(sizeof(struct smtp_session));
if (s == NULL) {
return ERR_MEM;
}
memset(s, 0, sizeof(struct smtp_session));
s->bodydh = (struct smtp_bodydh_state*)SMTP_BODYDH_MALLOC(sizeof(struct smtp_bodydh_state));
if (s->bodydh == NULL) {
return ERR_MEM;
}
memset(s->bodydh, 0, sizeof(struct smtp_bodydh));
/* initialize the structure */
s->from = from;
len = strlen(from);
LWIP_ASSERT("string is too long", len <= 0xffff);
s->from_len = (u16_t)len;
s->to = to;
len = strlen(to);
LWIP_ASSERT("string is too long", len <= 0xffff);
s->to_len = (u16_t)len;
s->subject = subject;
len = strlen(subject);
LWIP_ASSERT("string is too long", len <= 0xffff);
s->subject_len = (u16_t)len;
s->body = NULL;
LWIP_ASSERT("string is too long", len <= 0xffff);
s->callback_fn = callback_fn;
s->callback_arg = callback_arg;
s->bodydh->callback_fn = bodycback_fn;
s->bodydh->state = BDH_SENDING;
/* call the actual implementation of this function */
return smtp_send_mail_alloced(s);
}
static void
smtp_send_body_data_handler(struct smtp_session *s, struct tcp_pcb *pcb)
{
struct smtp_bodydh_state *bdh = s->bodydh;
int res = 0, ret;
LWIP_ASSERT("s != NULL", s != NULL);
LWIP_ASSERT("bodydh != NULL", bdh != NULL);
/* resume any leftovers from prior memory constraints */
if (s->body_len) {
LWIP_DEBUGF(SMTP_DEBUG_TRACE, ("smtp_send_body_data_handler: resume\n"));
if((res = smtp_send_bodyh_data(pcb, (char **)&s->body, &s->body_len))
!= BDHALLDATASENT) {
s->body_sent = s->body_len - 1;
return;
}
}
ret = res;
/* all data on buffer has been queued, resume execution */
if (bdh->state == BDH_SENDING) {
LWIP_DEBUGF(SMTP_DEBUG_TRACE, ("smtp_send_body_data_handler: run\n"));
do {
ret |= res; /* remember if we once queued something to send */
bdh->exposed.length = 0;
if (bdh->callback_fn(s->callback_arg, &bdh->exposed) == BDH_DONE) {
bdh->state = BDH_STOP;
}
s->body = bdh->exposed.buffer;
s->body_len = bdh->exposed.length;
LWIP_DEBUGF(SMTP_DEBUG_TRACE, ("smtp_send_body_data_handler: trying to send %u bytes\n", (unsigned int)s->body_len));
} while (s->body_len &&
((res = smtp_send_bodyh_data(pcb, (char **)&s->body, &s->body_len)) == BDHALLDATASENT)
&& (bdh->state != BDH_STOP));
}
if ((bdh->state != BDH_SENDING) && (ret != BDHSOMEDATASENT)) {
LWIP_DEBUGF(SMTP_DEBUG_TRACE, ("smtp_send_body_data_handler: stop\n"));
s->body_sent = s->body_len;
} else {
LWIP_DEBUGF(SMTP_DEBUG_TRACE, ("smtp_send_body_data_handler: pause\n"));
s->body_sent = s->body_len - 1;
}
}
#endif /* SMTP_BODYDH */
#endif /* LWIP_TCP */
|
2301_81045437/classic-platform
|
communication/lwip-2.0.3/contrib/apps/smtp/smtp.c
|
C
|
unknown
| 49,258
|
#ifndef LWIP_SMTP_H
#define LWIP_SMTP_H
/** Set this to 1 to enable data handler callback on BODY */
#ifndef SMTP_BODYDH
#define SMTP_BODYDH 0
#endif
#include "lwip/err.h"
/** The default TCP port used for SMTP */
#define SMTP_DEFAULT_PORT 25
/** Email successfully sent */
#define SMTP_RESULT_OK 0
/** Unknown error */
#define SMTP_RESULT_ERR_UNKNOWN 1
/** Connection to server failed */
#define SMTP_RESULT_ERR_CONNECT 2
/** Failed to resolve server hostname */
#define SMTP_RESULT_ERR_HOSTNAME 3
/** Connection unexpectedly closed by remote server */
#define SMTP_RESULT_ERR_CLOSED 4
/** Connection timed out (server didn't respond in time) */
#define SMTP_RESULT_ERR_TIMEOUT 5
/** Server responded with an unknown response code */
#define SMTP_RESULT_ERR_SVR_RESP 6
/** Out of resources locally */
#define SMTP_RESULT_ERR_MEM 7
/** Prototype of an smtp callback function
*
* @param arg argument specified when initiating the email
* @param smtp_result result of the mail transfer (see defines SMTP_RESULT_*)
* @param srv_err if aborted by the server, this contains the error code received
* @param err an error returned by internal lwip functions, can help to specify
* the source of the error but must not necessarily be != ERR_OK
*/
typedef void (*smtp_result_fn)(void *arg, u8_t smtp_result, u16_t srv_err, err_t err);
/** This structure is used as argument for smtp_send_mail_int(),
* which in turn can be used with tcpip_callback() to send mail
* from interrupt context, e.g. like this:
* struct smtp_send_request *req; (to be filled)
* tcpip_callback_with_block(smtp_send_mail_int, (void*)req, 0);
*
* For member description, see parameter description of smtp_send_mail().
* When using with tcpip_callback, this structure has to stay allocated
* (e.g. using mem_malloc/mem_free) until its 'callback_fn' is called.
*/
struct smtp_send_request {
const char *from;
const char* to;
const char* subject;
const char* body;
smtp_result_fn callback_fn;
void* callback_arg;
/** If this is != 0, data is *not* copied into an extra buffer
* but used from the pointers supplied in this struct.
* This means less memory usage, but data must stay untouched until
* the callback function is called. */
u8_t static_data;
};
#if SMTP_BODYDH
#ifndef SMTP_BODYDH_BUFFER_SIZE
#define SMTP_BODYDH_BUFFER_SIZE 256
#endif /* SMTP_BODYDH_BUFFER_SIZE */
struct smtp_bodydh {
u16_t state;
u16_t length; /* Length of content in buffer */
char buffer[SMTP_BODYDH_BUFFER_SIZE]; /* buffer for generated content */
#ifdef SMTP_BODYDH_USER_SIZE
u8_t user[SMTP_BODYDH_USER_SIZE];
#endif /* SMTP_BODYDH_USER_SIZE */
};
enum bdh_retvals_e {
BDH_DONE = 0,
BDH_WORKING
};
/** Prototype of an smtp body callback function
* It receives a struct smtp_bodydh, and a buffer to write data,
* must return BDH_WORKING to be called again and BDH_DONE when
* it has finished processing. This one tries to fill one TCP buffer with
* data, your function will be repeatedly called until that happens; so if you
* know you'll be taking too long to serve your request, pause once in a while
* by writing length=0 to avoid hogging system resources
*
* @param arg argument specified when initiating the email
* @param smtp_bodydh state handling + buffer structure
*/
typedef int (*smtp_bodycback_fn)(void *arg, struct smtp_bodydh *bodydh);
err_t smtp_send_mail_bodycback(const char *from, const char* to, const char* subject,
smtp_bodycback_fn bodycback_fn, smtp_result_fn callback_fn, void* callback_arg);
#endif /* SMTP_BODYDH */
void smtp_set_server_addr(const char* server);
void smtp_set_server_port(u16_t port);
err_t smtp_set_auth(const char* username, const char* pass);
err_t smtp_send_mail(const char *from, const char* to, const char* subject, const char* body,
smtp_result_fn callback_fn, void* callback_arg);
err_t smtp_send_mail_static(const char *from, const char* to, const char* subject, const char* body,
smtp_result_fn callback_fn, void* callback_arg);
void smtp_send_mail_int(void *arg);
#ifdef LWIP_DEBUG
const char* smtp_result_str(u8_t smtp_result);
#endif
#endif /* LWIP_SMTP_H */
|
2301_81045437/classic-platform
|
communication/lwip-2.0.3/contrib/apps/smtp/smtp.h
|
C
|
unknown
| 4,381
|
/**
* @file
* lwip Private MIB
*
* @todo create MIB file for this example
* @note the lwip enterprise tree root (26381) is owned by the lwIP project.
* It is NOT allowed to allocate new objects under this ID (26381) without our,
* the lwip developers, permission!
*
* Please apply for your own ID with IANA: http://www.iana.org/numbers.html
*
* lwip OBJECT IDENTIFIER ::= { enterprises 26381 }
* example OBJECT IDENTIFIER ::= { lwip 1 }
*/
/*
* Copyright (c) 2006 Axon Digital Design B.V., The Netherlands.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
* 3. The name of the author may not be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
* SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
* IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
* OF SUCH DAMAGE.
*
* Author: Christiaan Simons <christiaan.simons@axon.tv>
*/
#include "private_mib.h"
#if LWIP_SNMP
/** Directory where the sensor files are */
#define SENSORS_DIR "w:\\sensors"
/** Set to 1 to read sensor values from files (in directory defined by SENSORS_DIR) */
#define SENSORS_USE_FILES 0
/** Set to 1 to search sensor files at startup (in directory defined by SENSORS_DIR) */
#define SENSORS_SEARCH_FILES 0
#if SENSORS_SEARCH_FILES
#include <sys/stat.h>
#include <sys/types.h>
#include <ctype.h>
#include <unistd.h>
#include <fcntl.h>
#include <dirent.h>
#endif /* SENSORS_SEARCH_FILES */
#include <string.h>
#include <stdio.h>
#include "lwip/apps/snmp_table.h"
#include "lwip/apps/snmp_scalar.h"
#if !SENSORS_USE_FILES || !SENSORS_SEARCH_FILES
/** When not using & searching files, defines the number of sensors */
#define SENSOR_COUNT 4
#endif /* !SENSORS_USE_FILES || !SENSORS_SEARCH_FILES */
/*
This example presents a table for a few (at most 10) sensors.
Sensor detection takes place at initialization (once only).
Sensors may and can not be added or removed after agent
has started. Note this is only a limitation of this crude example,
the agent does support dynamic object insertions and removals.
You'll need to manually create a directory called "sensors" and
a few single line text files with an integer temperature value.
The files must be called [0..9].txt.
./sensors/0.txt [content: 20]
./sensors/3.txt [content: 75]
The sensor values may be changed in runtime by editing the
text files in the "sensors" directory.
*/
#define SENSOR_MAX 10
#define SENSOR_NAME_LEN 20
struct sensor_inf
{
u8_t num;
char file[SENSOR_NAME_LEN + 1];
#if !SENSORS_USE_FILES
/** When not using files, contains the value of the sensor */
s32_t value;
#endif /* !SENSORS_USE_FILES */
};
static struct sensor_inf sensors[SENSOR_MAX];
static s16_t sensor_count_get_value(struct snmp_node_instance* instance, void* value);
static snmp_err_t sensor_table_get_cell_instance(const u32_t* column, const u32_t* row_oid, u8_t row_oid_len, struct snmp_node_instance* cell_instance);
static snmp_err_t sensor_table_get_next_cell_instance(const u32_t* column, struct snmp_obj_id* row_oid, struct snmp_node_instance* cell_instance);
static s16_t sensor_table_get_value(struct snmp_node_instance* instance, void* value);
static snmp_err_t sensor_table_set_value(struct snmp_node_instance* instance, u16_t len, void *value);
/* sensorentry .1.3.6.1.4.1.26381.1.1.1 (.level0.level1)
where level 0 is the table column (temperature/file name)
and level 1 the table row (sensor index) */
static const struct snmp_table_col_def sensor_table_columns[] = {
{ 1, SNMP_ASN1_TYPE_INTEGER, SNMP_NODE_INSTANCE_READ_WRITE },
{ 2, SNMP_ASN1_TYPE_OCTET_STRING, SNMP_NODE_INSTANCE_READ_ONLY }
};
/* sensortable .1.3.6.1.4.1.26381.1.1 */
static const struct snmp_table_node sensor_table = SNMP_TABLE_CREATE(
1, sensor_table_columns,
sensor_table_get_cell_instance, sensor_table_get_next_cell_instance,
sensor_table_get_value, snmp_set_test_ok, sensor_table_set_value);
/* sensorcount .1.3.6.1.4.1.26381.1.2 */
static const struct snmp_scalar_node sensor_count = SNMP_SCALAR_CREATE_NODE_READONLY(
2, SNMP_ASN1_TYPE_INTEGER, sensor_count_get_value);
/* example .1.3.6.1.4.1.26381.1 */
static const struct snmp_node* const example_nodes[] = {
&sensor_table.node.node,
&sensor_count.node.node
};
static const struct snmp_tree_node example_node = SNMP_CREATE_TREE_NODE(1, example_nodes);
static const u32_t prvmib_base_oid[] = { 1,3,6,1,4,1,26381,1 };
const struct snmp_mib mib_private = SNMP_MIB_CREATE(prvmib_base_oid, &example_node.node);
#if 0
/* for reference: we could also have expressed it like this: */
/* lwip .1.3.6.1.4.1.26381 */
static const struct snmp_node* const lwip_nodes[] = {
&example_node.node
};
static const struct snmp_tree_node lwip_node = SNMP_CREATE_TREE_NODE(26381, lwip_nodes);
/* enterprises .1.3.6.1.4.1 */
static const struct snmp_node* const enterprises_nodes[] = {
&lwip_node.node
};
static const struct snmp_tree_node enterprises_node = SNMP_CREATE_TREE_NODE(1, enterprises_nodes);
/* private .1.3.6.1.4 */
static const struct snmp_node* const private_nodes[] = {
&enterprises_node.node
};
static const struct snmp_tree_node private_root = SNMP_CREATE_TREE_NODE(0, private_nodes);
static const u32_t prvmib_base_oid[] = { 1,3,6,1,4 };
const struct snmp_mib mib_private = SNMP_MIB_CREATE(prvmib_base_oid, &private_root.node);
#endif
/**
* Initialises this private MIB before use.
* @see main.c
*/
void
lwip_privmib_init(void)
{
#if SENSORS_USE_FILES && SENSORS_SEARCH_FILES
char *buf, *ebuf, *cp;
size_t bufsize;
int nbytes;
struct stat sb;
struct dirent *dp;
int fd;
#else /* SENSORS_USE_FILES && SENSORS_SEARCH_FILES */
u8_t i;
#endif /* SENSORS_USE_FILES && SENSORS_SEARCH_FILES */
memset(sensors, 0, sizeof(sensors));
printf("SNMP private MIB start, detecting sensors.\n");
#if SENSORS_USE_FILES && SENSORS_SEARCH_FILES
/* look for sensors in sensors directory */
fd = open(SENSORS_DIR, O_RDONLY);
if (fd > -1)
{
fstat(fd, &sb);
bufsize = sb.st_size;
if (bufsize < (size_t)sb.st_blksize)
{
bufsize = sb.st_blksize;
}
buf = (char*)malloc(bufsize);
if (buf != NULL)
{
do
{
long base;
nbytes = getdirentries(fd, buf, bufsize, &base);
if (nbytes > 0)
{
ebuf = buf + nbytes;
cp = buf;
while (cp < ebuf)
{
dp = (struct dirent *)cp;
if (isdigit(dp->d_name[0]))
{
unsigned char idx = dp->d_name[0] - '0';
sensors[idx].num = idx+1;
strncpy(&sensors[idx].file[0], dp->d_name, SENSOR_NAME_LEN);
printf("%s\n", sensors[idx].file);
}
cp += dp->d_reclen;
}
}
}
while (nbytes > 0);
free(buf);
}
close(fd);
}
#else /* SENSORS_USE_FILES && SENSORS_SEARCH_FILES */
for (i = 0; i < SENSOR_COUNT; i++) {
sensors[i].num = i+1;
snprintf(sensors[i].file, sizeof(sensors[i].file), "%d.txt", i);
#if !SENSORS_USE_FILES
/* initialize sensor value to != zero */
sensors[i].value = 11 * (i+1);
#endif /* !SENSORS_USE_FILES */
}
#endif /* SENSORS_USE_FILE && SENSORS_SEARCH_FILES */
}
/* sensorcount .1.3.6.1.4.1.26381.1.2 */
static s16_t
sensor_count_get_value(struct snmp_node_instance* instance, void* value)
{
size_t count = 0;
u32_t *uint_ptr = (u32_t*)value;
LWIP_UNUSED_ARG(instance);
for(count=0; count<LWIP_ARRAYSIZE(sensors); count++) {
if(sensors[count].num == 0) {
*uint_ptr = (u32_t)count;
return sizeof(*uint_ptr);
}
}
return 0;
}
/* sensortable .1.3.6.1.4.1.26381.1.1 */
/* list of allowed value ranges for incoming OID */
static const struct snmp_oid_range sensor_table_oid_ranges[] = {
{ 1, SENSOR_MAX+1 }
};
static snmp_err_t
sensor_table_get_cell_instance(const u32_t* column, const u32_t* row_oid, u8_t row_oid_len, struct snmp_node_instance* cell_instance)
{
u32_t sensor_num;
size_t i;
LWIP_UNUSED_ARG(column);
/* check if incoming OID length and if values are in plausible range */
if(!snmp_oid_in_range(row_oid, row_oid_len, sensor_table_oid_ranges, LWIP_ARRAYSIZE(sensor_table_oid_ranges))) {
return SNMP_ERR_NOSUCHINSTANCE;
}
/* get sensor index from incoming OID */
sensor_num = row_oid[0];
/* find sensor with index */
for(i=0; i<LWIP_ARRAYSIZE(sensors); i++) {
if(sensors[i].num != 0) {
if(sensors[i].num == sensor_num) {
/* store sensor index for subsequent operations (get/test/set) */
cell_instance->reference.u32 = (u32_t)i;
return SNMP_ERR_NOERROR;
}
}
}
/* not found */
return SNMP_ERR_NOSUCHINSTANCE;
}
static snmp_err_t
sensor_table_get_next_cell_instance(const u32_t* column, struct snmp_obj_id* row_oid, struct snmp_node_instance* cell_instance)
{
size_t i;
struct snmp_next_oid_state state;
u32_t result_temp[LWIP_ARRAYSIZE(sensor_table_oid_ranges)];
LWIP_UNUSED_ARG(column);
/* init struct to search next oid */
snmp_next_oid_init(&state, row_oid->id, row_oid->len, result_temp, LWIP_ARRAYSIZE(sensor_table_oid_ranges));
/* iterate over all possible OIDs to find the next one */
for(i=0; i<LWIP_ARRAYSIZE(sensors); i++) {
if(sensors[i].num != 0) {
u32_t test_oid[LWIP_ARRAYSIZE(sensor_table_oid_ranges)];
test_oid[0] = sensors[i].num;
/* check generated OID: is it a candidate for the next one? */
snmp_next_oid_check(&state, test_oid, LWIP_ARRAYSIZE(sensor_table_oid_ranges), (void*)i);
}
}
/* did we find a next one? */
if(state.status == SNMP_NEXT_OID_STATUS_SUCCESS) {
snmp_oid_assign(row_oid, state.next_oid, state.next_oid_len);
/* store sensor index for subsequent operations (get/test/set) */
cell_instance->reference.u32 = (u32_t)(size_t)state.reference;
return SNMP_ERR_NOERROR;
}
/* not found */
return SNMP_ERR_NOSUCHINSTANCE;
}
static s16_t
sensor_table_get_value(struct snmp_node_instance* instance, void* value)
{
u32_t i = instance->reference.u32;
s32_t *temperature = (s32_t *)value;
switch (SNMP_TABLE_GET_COLUMN_FROM_OID(instance->instance_oid.id))
{
case 1: /* sensor value */
#if SENSORS_USE_FILES
FILE* sensf;
char senspath[sizeof(SENSORS_DIR)+1+SENSOR_NAME_LEN+1] = SENSORS_DIR"/";
strncpy(&senspath[sizeof(SENSORS_DIR)],
sensors[i].file,
SENSOR_NAME_LEN);
sensf = fopen(senspath,"r");
if (sensf != NULL)
{
fscanf(sensf,"%"S32_F,temperature);
fclose(sensf);
}
#else /* SENSORS_USE_FILES */
*temperature = sensors[i].value;
#endif /* SENSORS_USE_FILES */
return sizeof(s32_t);
case 2: /* file name */
MEMCPY(value, sensors[i].file, strlen(sensors[i].file));
return (u16_t)strlen(sensors[i].file);
default:
return 0;
}
}
static snmp_err_t
sensor_table_set_value(struct snmp_node_instance* instance, u16_t len, void *value)
{
u32_t i = instance->reference.u32;
s32_t *temperature = (s32_t *)value;
#if SENSORS_USE_FILES
FILE* sensf;
char senspath[sizeof(SENSORS_DIR)+1+SENSOR_NAME_LEN+1] = SENSORS_DIR"/";
strncpy(&senspath[sizeof(SENSORS_DIR)],
sensors[i].file,
SENSOR_NAME_LEN);
sensf = fopen(senspath, "w");
if (sensf != NULL)
{
fprintf(sensf, "%"S32_F, *temperature);
fclose(sensf);
}
#else /* SENSORS_USE_FILES */
sensors[i].value = *temperature;
#endif /* SENSORS_USE_FILES */
LWIP_UNUSED_ARG(len);
return SNMP_ERR_NOERROR;
}
#endif /* LWIP_SNMP */
|
2301_81045437/classic-platform
|
communication/lwip-2.0.3/contrib/apps/snmp_private_mib/lwip_prvmib.c
|
C
|
unknown
| 13,116
|
/**
* @file
* Exports Private lwIP MIB
*/
#ifndef LWIP_HDR_PRIVATE_MIB_H
#define LWIP_HDR_PRIVATE_MIB_H
#include "lwip/apps/snmp_opts.h"
#include "lwip/apps/snmp_core.h"
#ifdef __cplusplus
extern "C" {
#endif
/* export MIB */
extern const struct snmp_mib mib_private;
void lwip_privmib_init(void);
#ifdef __cplusplus
}
#endif
#endif
|
2301_81045437/classic-platform
|
communication/lwip-2.0.3/contrib/apps/snmp_private_mib/private_mib.h
|
C
|
unknown
| 371
|
#include "socket_examples.h"
#include "lwip/opt.h"
#if LWIP_SOCKET && (LWIP_IPV4 || LWIP_IPV6)
#include "lwip/sockets.h"
#include "lwip/sys.h"
#include <string.h>
#include <stdio.h>
#ifndef SOCK_TARGET_HOST4
#define SOCK_TARGET_HOST4 "192.168.1.1"
#endif
#ifndef SOCK_TARGET_HOST6
#define SOCK_TARGET_HOST6 "FE80::12:34FF:FE56:78AB"
#endif
#ifndef SOCK_TARGET_PORT
#define SOCK_TARGET_PORT 80
#endif
#ifndef SOCK_TARGET_MAXHTTPPAGESIZE
#define SOCK_TARGET_MAXHTTPPAGESIZE 1024
#endif
#ifndef SOCKET_EXAMPLES_RUN_PARALLEL
#define SOCKET_EXAMPLES_RUN_PARALLEL 0
#endif
const u8_t cmpbuf[8] = {0xab, 0xab, 0xab, 0xab, 0xab, 0xab, 0xab, 0xab};
/* a helper struct to ensure memory before/after fd_set is not touched */
typedef struct _xx
{
u8_t buf1[8];
fd_set readset;
u8_t buf2[8];
fd_set writeset;
u8_t buf3[8];
fd_set errset;
u8_t buf4[8];
} fdsets;
#define INIT_FDSETS(sets) do { \
memset((sets)->buf1, 0xab, 8); \
memset((sets)->buf2, 0xab, 8); \
memset((sets)->buf3, 0xab, 8); \
memset((sets)->buf4, 0xab, 8); \
}while(0)
#define CHECK_FDSETS(sets) do { \
LWIP_ASSERT("buf1 fail", !memcmp((sets)->buf1, cmpbuf, 8)); \
LWIP_ASSERT("buf2 fail", !memcmp((sets)->buf2, cmpbuf, 8)); \
LWIP_ASSERT("buf3 fail", !memcmp((sets)->buf3, cmpbuf, 8)); \
LWIP_ASSERT("buf4 fail", !memcmp((sets)->buf4, cmpbuf, 8)); \
}while(0)
static ip_addr_t dstaddr;
/** This is an example function that tests
blocking- and nonblocking connect. */
static void
sockex_nonblocking_connect(void *arg)
{
int s;
int ret;
u32_t opt;
#if LWIP_IPV6
struct sockaddr_in6 addr;
#else /* LWIP_IPV6 */
struct sockaddr_in addr;
#endif /* LWIP_IPV6 */
fdsets sets;
struct timeval tv;
u32_t ticks_a, ticks_b;
int err;
const ip_addr_t *ipaddr = (const ip_addr_t*)arg;
INIT_FDSETS(&sets);
/* set up address to connect to */
memset(&addr, 0, sizeof(addr));
#if LWIP_IPV6
addr.sin6_len = sizeof(addr);
addr.sin6_family = AF_INET6;
addr.sin6_port = PP_HTONS(SOCK_TARGET_PORT);
inet6_addr_from_ip6addr(&addr.sin6_addr, ip_2_ip6(ipaddr));
#else /* LWIP_IPV6 */
addr.sin_len = sizeof(addr);
addr.sin_family = AF_INET;
addr.sin_port = PP_HTONS(SOCK_TARGET_PORT);
inet_addr_from_ipaddr(&addr.sin_addr, ip_2_ip4(ipaddr));
#endif /* LWIP_IPV6 */
/* first try blocking: */
/* create the socket */
#if LWIP_IPV6
s = lwip_socket(AF_INET6, SOCK_STREAM, 0);
#else /* LWIP_IPV6 */
s = lwip_socket(AF_INET, SOCK_STREAM, 0);
#endif /* LWIP_IPV6 */
LWIP_ASSERT("s >= 0", s >= 0);
/* connect */
ret = lwip_connect(s, (struct sockaddr*)&addr, sizeof(addr));
/* should succeed */
LWIP_ASSERT("ret == 0", ret == 0);
/* write something */
ret = lwip_write(s, "test", 4);
LWIP_ASSERT("ret == 4", ret == 4);
/* close */
ret = lwip_close(s);
LWIP_ASSERT("ret == 0", ret == 0);
/* now try nonblocking and close before being connected */
/* create the socket */
#if LWIP_IPV6
s = lwip_socket(AF_INET6, SOCK_STREAM, 0);
#else /* LWIP_IPV6 */
s = lwip_socket(AF_INET, SOCK_STREAM, 0);
#endif /* LWIP_IPV6 */
LWIP_ASSERT("s >= 0", s >= 0);
/* nonblocking */
opt = lwip_fcntl(s, F_GETFL, 0);
LWIP_ASSERT("ret != -1", ret != -1);
opt |= O_NONBLOCK;
ret = lwip_fcntl(s, F_SETFL, opt);
LWIP_ASSERT("ret != -1", ret != -1);
/* connect */
ret = lwip_connect(s, (struct sockaddr*)&addr, sizeof(addr));
/* should have an error: "inprogress" */
LWIP_ASSERT("ret == -1", ret == -1);
err = errno;
LWIP_ASSERT("errno == EINPROGRESS", err == EINPROGRESS);
/* close */
ret = lwip_close(s);
LWIP_ASSERT("ret == 0", ret == 0);
/* try to close again, should fail with EBADF */
ret = lwip_close(s);
LWIP_ASSERT("ret == -1", ret == -1);
err = errno;
LWIP_ASSERT("errno == EBADF", err == EBADF);
printf("closing socket in nonblocking connect succeeded\n");
/* now try nonblocking, connect should succeed:
this test only works if it is fast enough, i.e. no breakpoints, please! */
/* create the socket */
#if LWIP_IPV6
s = lwip_socket(AF_INET6, SOCK_STREAM, 0);
#else /* LWIP_IPV6 */
s = lwip_socket(AF_INET, SOCK_STREAM, 0);
#endif /* LWIP_IPV6 */
LWIP_ASSERT("s >= 0", s >= 0);
/* nonblocking */
opt = 1;
ret = lwip_ioctl(s, FIONBIO, &opt);
LWIP_ASSERT("ret == 0", ret == 0);
/* connect */
ret = lwip_connect(s, (struct sockaddr*)&addr, sizeof(addr));
/* should have an error: "inprogress" */
LWIP_ASSERT("ret == -1", ret == -1);
err = errno;
LWIP_ASSERT("errno == EINPROGRESS", err == EINPROGRESS);
/* write should fail, too */
ret = lwip_write(s, "test", 4);
LWIP_ASSERT("ret == -1", ret == -1);
err = errno;
LWIP_ASSERT("errno == EINPROGRESS", err == EINPROGRESS);
CHECK_FDSETS(&sets);
FD_ZERO(&sets.readset);
CHECK_FDSETS(&sets);
FD_SET(s, &sets.readset);
CHECK_FDSETS(&sets);
FD_ZERO(&sets.writeset);
CHECK_FDSETS(&sets);
FD_SET(s, &sets.writeset);
CHECK_FDSETS(&sets);
FD_ZERO(&sets.errset);
CHECK_FDSETS(&sets);
FD_SET(s, &sets.errset);
CHECK_FDSETS(&sets);
tv.tv_sec = 0;
tv.tv_usec = 0;
/* select without waiting should fail */
ret = lwip_select(s + 1, &sets.readset, &sets.writeset, &sets.errset, &tv);
CHECK_FDSETS(&sets);
LWIP_ASSERT("ret == 0", ret == 0);
LWIP_ASSERT("!FD_ISSET(s, &writeset)", !FD_ISSET(s, &sets.writeset));
LWIP_ASSERT("!FD_ISSET(s, &readset)", !FD_ISSET(s, &sets.readset));
LWIP_ASSERT("!FD_ISSET(s, &errset)", !FD_ISSET(s, &sets.errset));
FD_ZERO(&sets.readset);
FD_SET(s, &sets.readset);
FD_ZERO(&sets.writeset);
FD_SET(s, &sets.writeset);
FD_ZERO(&sets.errset);
FD_SET(s, &sets.errset);
ticks_a = sys_now();
/* select with waiting should succeed */
ret = lwip_select(s + 1, &sets.readset, &sets.writeset, &sets.errset, NULL);
ticks_b = sys_now();
LWIP_ASSERT("ret == 1", ret == 1);
LWIP_ASSERT("FD_ISSET(s, &writeset)", FD_ISSET(s, &sets.writeset));
LWIP_ASSERT("!FD_ISSET(s, &readset)", !FD_ISSET(s, &sets.readset));
LWIP_ASSERT("!FD_ISSET(s, &errset)", !FD_ISSET(s, &sets.errset));
/* now write should succeed */
ret = lwip_write(s, "test", 4);
LWIP_ASSERT("ret == 4", ret == 4);
/* close */
ret = lwip_close(s);
LWIP_ASSERT("ret == 0", ret == 0);
printf("select() needed %d ticks to return writable\n", (int)(ticks_b - ticks_a));
/* now try nonblocking to invalid address:
this test only works if it is fast enough, i.e. no breakpoints, please! */
/* create the socket */
#if LWIP_IPV6
s = lwip_socket(AF_INET6, SOCK_STREAM, 0);
#else /* LWIP_IPV6 */
s = lwip_socket(AF_INET, SOCK_STREAM, 0);
#endif /* LWIP_IPV6 */
LWIP_ASSERT("s >= 0", s >= 0);
/* nonblocking */
opt = 1;
ret = lwip_ioctl(s, FIONBIO, &opt);
LWIP_ASSERT("ret == 0", ret == 0);
#if LWIP_IPV6
addr.sin6_addr.un.u8_addr[0]++; /* this should result in an invalid address */
#else /* LWIP_IPV6 */
addr.sin_addr.s_addr++; /* this should result in an invalid address */
#endif /* LWIP_IPV6 */
/* connect */
ret = lwip_connect(s, (struct sockaddr*)&addr, sizeof(addr));
/* should have an error: "inprogress" */
LWIP_ASSERT("ret == -1", ret == -1);
err = errno;
LWIP_ASSERT("errno == EINPROGRESS", err == EINPROGRESS);
/* write should fail, too */
ret = lwip_write(s, "test", 4);
LWIP_ASSERT("ret == -1", ret == -1);
err = errno;
LWIP_ASSERT("errno == EINPROGRESS", err == EINPROGRESS);
FD_ZERO(&sets.readset);
FD_SET(s, &sets.readset);
FD_ZERO(&sets.writeset);
FD_SET(s, &sets.writeset);
FD_ZERO(&sets.errset);
FD_SET(s, &sets.errset);
tv.tv_sec = 0;
tv.tv_usec = 0;
/* select without waiting should fail */
ret = lwip_select(s + 1, &sets.readset, &sets.writeset, &sets.errset, &tv);
LWIP_ASSERT("ret == 0", ret == 0);
FD_ZERO(&sets.readset);
FD_SET(s, &sets.readset);
FD_ZERO(&sets.writeset);
FD_SET(s, &sets.writeset);
FD_ZERO(&sets.errset);
FD_SET(s, &sets.errset);
ticks_a = sys_now();
/* select with waiting should eventually succeed and return errset! */
ret = lwip_select(s + 1, &sets.readset, &sets.writeset, &sets.errset, NULL);
ticks_b = sys_now();
LWIP_ASSERT("ret > 0", ret > 0);
LWIP_ASSERT("FD_ISSET(s, &errset)", FD_ISSET(s, &sets.errset));
/*LWIP_ASSERT("!FD_ISSET(s, &readset)", !FD_ISSET(s, &sets.readset));
LWIP_ASSERT("!FD_ISSET(s, &writeset)", !FD_ISSET(s, &sets.writeset));*/
/* close */
ret = lwip_close(s);
LWIP_ASSERT("ret == 0", ret == 0);
printf("select() needed %d ticks to return error\n", (int)(ticks_b - ticks_a));
printf("all tests done, thread ending\n");
}
/** This is an example function that tests
the recv function (timeout etc.). */
static void
sockex_testrecv(void *arg)
{
int s;
int ret;
int err;
int opt, opt2;
socklen_t opt2size;
#if LWIP_IPV6
struct sockaddr_in6 addr;
#else /* LWIP_IPV6 */
struct sockaddr_in addr;
#endif /* LWIP_IPV6 */
size_t len;
char rxbuf[SOCK_TARGET_MAXHTTPPAGESIZE];
fd_set readset;
fd_set errset;
struct timeval tv;
const ip_addr_t *ipaddr = (const ip_addr_t*)arg;
/* set up address to connect to */
memset(&addr, 0, sizeof(addr));
#if LWIP_IPV6
addr.sin6_len = sizeof(addr);
addr.sin6_family = AF_INET6;
addr.sin6_port = PP_HTONS(SOCK_TARGET_PORT);
inet6_addr_from_ip6addr(&addr.sin6_addr, ip_2_ip6(ipaddr));
#else /* LWIP_IPV6 */
addr.sin_len = sizeof(addr);
addr.sin_family = AF_INET;
addr.sin_port = PP_HTONS(SOCK_TARGET_PORT);
inet_addr_from_ipaddr(&addr.sin_addr, ip_2_ip4(ipaddr));
#endif /* LWIP_IPV6 */
/* first try blocking: */
/* create the socket */
#if LWIP_IPV6
s = lwip_socket(AF_INET6, SOCK_STREAM, 0);
#else /* LWIP_IPV6 */
s = lwip_socket(AF_INET, SOCK_STREAM, 0);
#endif /* LWIP_IPV6 */
LWIP_ASSERT("s >= 0", s >= 0);
/* connect */
ret = lwip_connect(s, (struct sockaddr*)&addr, sizeof(addr));
/* should succeed */
LWIP_ASSERT("ret == 0", ret == 0);
/* set recv timeout (100 ms) */
opt = 100;
ret = lwip_setsockopt(s, SOL_SOCKET, SO_RCVTIMEO, &opt, sizeof(int));
LWIP_ASSERT("ret == 0", ret == 0);
opt2 = 0;
opt2size = sizeof(opt2);
ret = lwip_getsockopt(s, SOL_SOCKET, SO_RCVTIMEO, &opt2, &opt2size);
LWIP_ASSERT("ret == 0", ret == 0);
LWIP_ASSERT("opt2size == sizeof(opt2)", opt2size == sizeof(opt2));
LWIP_ASSERT("opt == opt2", opt == opt2);
/* write the start of a GET request */
#define SNDSTR1 "G"
len = strlen(SNDSTR1);
ret = lwip_write(s, SNDSTR1, len);
LWIP_ASSERT("ret == len", ret == (int)len);
/* should time out if the other side is a good HTTP server */
ret = lwip_read(s, rxbuf, 1);
LWIP_ASSERT("ret == -1", ret == -1);
err = errno;
LWIP_ASSERT("errno == EAGAIN", err == EAGAIN);
/* write the rest of a GET request */
#define SNDSTR2 "ET / HTTP_1.1\r\n\r\n"
len = strlen(SNDSTR2);
ret = lwip_write(s, SNDSTR2, len);
LWIP_ASSERT("ret == len", ret == (int)len);
/* wait a while: should be enough for the server to send a response */
sys_msleep(1000);
/* should not time out but receive a response */
ret = lwip_read(s, rxbuf, SOCK_TARGET_MAXHTTPPAGESIZE);
LWIP_ASSERT("ret > 0", ret > 0);
/* now select should directly return because the socket is readable */
FD_ZERO(&readset);
FD_ZERO(&errset);
FD_SET(s, &readset);
FD_SET(s, &errset);
tv.tv_sec = 10;
tv.tv_usec = 0;
ret = lwip_select(s + 1, &readset, NULL, &errset, &tv);
LWIP_ASSERT("ret == 1", ret == 1);
LWIP_ASSERT("!FD_ISSET(s, &errset)", !FD_ISSET(s, &errset));
LWIP_ASSERT("FD_ISSET(s, &readset)", FD_ISSET(s, &readset));
/* should not time out but receive a response */
ret = lwip_read(s, rxbuf, SOCK_TARGET_MAXHTTPPAGESIZE);
/* might receive a second packet for HTTP/1.1 servers */
if (ret > 0) {
/* should return 0: closed */
ret = lwip_read(s, rxbuf, SOCK_TARGET_MAXHTTPPAGESIZE);
LWIP_ASSERT("ret == 0", ret == 0);
}
/* close */
ret = lwip_close(s);
LWIP_ASSERT("ret == 0", ret == 0);
printf("sockex_testrecv finished successfully\n");
}
/** helper struct for the 2 functions below (multithreaded: thread-argument) */
struct sockex_select_helper {
int socket;
int wait_read;
int expect_read;
int wait_write;
int expect_write;
int wait_err;
int expect_err;
int wait_ms;
sys_sem_t sem;
};
/** helper thread to wait for socket events using select */
static void
sockex_select_waiter(void *arg)
{
struct sockex_select_helper *helper = (struct sockex_select_helper *)arg;
int ret;
fd_set readset;
fd_set writeset;
fd_set errset;
struct timeval tv;
LWIP_ASSERT("helper != NULL", helper != NULL);
FD_ZERO(&readset);
FD_ZERO(&writeset);
FD_ZERO(&errset);
if (helper->wait_read) {
FD_SET(helper->socket, &readset);
}
if (helper->wait_write) {
FD_SET(helper->socket, &writeset);
}
if (helper->wait_err) {
FD_SET(helper->socket, &errset);
}
tv.tv_sec = helper->wait_ms / 1000;
tv.tv_usec = (helper->wait_ms % 1000) * 1000;
ret = lwip_select(helper->socket, &readset, &writeset, &errset, &tv);
if (helper->expect_read || helper->expect_write || helper->expect_err) {
LWIP_ASSERT("ret > 0", ret > 0);
} else {
LWIP_ASSERT("ret == 0", ret == 0);
}
if (helper->expect_read) {
LWIP_ASSERT("FD_ISSET(helper->socket, &readset)", FD_ISSET(helper->socket, &readset));
} else {
LWIP_ASSERT("!FD_ISSET(helper->socket, &readset)", !FD_ISSET(helper->socket, &readset));
}
if (helper->expect_write) {
LWIP_ASSERT("FD_ISSET(helper->socket, &writeset)", FD_ISSET(helper->socket, &writeset));
} else {
LWIP_ASSERT("!FD_ISSET(helper->socket, &writeset)", !FD_ISSET(helper->socket, &writeset));
}
if (helper->expect_err) {
LWIP_ASSERT("FD_ISSET(helper->socket, &errset)", FD_ISSET(helper->socket, &errset));
} else {
LWIP_ASSERT("!FD_ISSET(helper->socket, &errset)", !FD_ISSET(helper->socket, &errset));
}
sys_sem_signal(&helper->sem);
}
/** This is an example function that tests
more than one thread being active in select. */
static void
sockex_testtwoselects(void *arg)
{
int s1;
int s2;
int ret;
#if LWIP_IPV6
struct sockaddr_in6 addr;
#else /* LWIP_IPV6 */
struct sockaddr_in addr;
#endif /* LWIP_IPV6 */
size_t len;
err_t lwiperr;
struct sockex_select_helper h1, h2, h3, h4;
const ip_addr_t *ipaddr = (const ip_addr_t*)arg;
/* set up address to connect to */
memset(&addr, 0, sizeof(addr));
#if LWIP_IPV6
addr.sin6_len = sizeof(addr);
addr.sin6_family = AF_INET6;
addr.sin6_port = PP_HTONS(SOCK_TARGET_PORT);
inet6_addr_from_ip6addr(&addr.sin6_addr, ip_2_ip6(ipaddr));
#else /* LWIP_IPV6 */
addr.sin_len = sizeof(addr);
addr.sin_family = AF_INET;
addr.sin_port = PP_HTONS(SOCK_TARGET_PORT);
inet_addr_from_ipaddr(&addr.sin_addr, ip_2_ip4(ipaddr));
#endif /* LWIP_IPV6 */
/* create the sockets */
#if LWIP_IPV6
s1 = lwip_socket(AF_INET6, SOCK_STREAM, 0);
s2 = lwip_socket(AF_INET6, SOCK_STREAM, 0);
#else /* LWIP_IPV6 */
s1 = lwip_socket(AF_INET, SOCK_STREAM, 0);
s2 = lwip_socket(AF_INET, SOCK_STREAM, 0);
#endif /* LWIP_IPV6 */
LWIP_ASSERT("s1 >= 0", s1 >= 0);
LWIP_ASSERT("s2 >= 0", s2 >= 0);
/* connect, should succeed */
ret = lwip_connect(s1, (struct sockaddr*)&addr, sizeof(addr));
LWIP_ASSERT("ret == 0", ret == 0);
ret = lwip_connect(s2, (struct sockaddr*)&addr, sizeof(addr));
LWIP_ASSERT("ret == 0", ret == 0);
/* write the start of a GET request */
#define SNDSTR1 "G"
len = strlen(SNDSTR1);
ret = lwip_write(s1, SNDSTR1, len);
LWIP_ASSERT("ret == len", ret == (int)len);
ret = lwip_write(s2, SNDSTR1, len);
LWIP_ASSERT("ret == len", ret == (int)len);
h1.wait_read = 1;
h1.wait_write = 1;
h1.wait_err = 1;
h1.expect_read = 0;
h1.expect_write = 0;
h1.expect_err = 0;
lwiperr = sys_sem_new(&h1.sem, 0);
LWIP_ASSERT("lwiperr == ERR_OK", lwiperr == ERR_OK);
h1.socket = s1;
h1.wait_ms = 500;
h2 = h1;
lwiperr = sys_sem_new(&h2.sem, 0);
LWIP_ASSERT("lwiperr == ERR_OK", lwiperr == ERR_OK);
h2.socket = s2;
h2.wait_ms = 1000;
h3 = h1;
lwiperr = sys_sem_new(&h3.sem, 0);
LWIP_ASSERT("lwiperr == ERR_OK", lwiperr == ERR_OK);
h3.socket = s2;
h3.wait_ms = 1500;
h4 = h1;
lwiperr = sys_sem_new(&h4.sem, 0);
LWIP_ASSERT("lwiperr == ERR_OK", lwiperr == ERR_OK);
h4.socket = s2;
h4.wait_ms = 2000;
/* select: all sockets should time out if the other side is a good HTTP server */
sys_thread_new("sockex_select_waiter1", sockex_select_waiter, &h2, 0, 0);
sys_msleep(100);
sys_thread_new("sockex_select_waiter2", sockex_select_waiter, &h1, 0, 0);
sys_msleep(100);
sys_thread_new("sockex_select_waiter2", sockex_select_waiter, &h4, 0, 0);
sys_msleep(100);
sys_thread_new("sockex_select_waiter2", sockex_select_waiter, &h3, 0, 0);
sys_sem_wait(&h1.sem);
sys_sem_wait(&h2.sem);
sys_sem_wait(&h3.sem);
sys_sem_wait(&h4.sem);
/* close */
ret = lwip_close(s1);
LWIP_ASSERT("ret == 0", ret == 0);
ret = lwip_close(s2);
LWIP_ASSERT("ret == 0", ret == 0);
printf("sockex_testtwoselects finished successfully\n");
}
#if !SOCKET_EXAMPLES_RUN_PARALLEL
static void
socket_example_test(void* arg)
{
sockex_nonblocking_connect(arg);
sockex_testrecv(arg);
sockex_testtwoselects(arg);
}
#endif
void socket_examples_init(void)
{
#if LWIP_IPV6
IP_SET_TYPE_VAL(dstaddr, IPADDR_TYPE_V6);
ip6addr_aton(SOCK_TARGET_HOST6, ip_2_ip6(&dstaddr));
#else /* LWIP_IPV6 */
IP_SET_TYPE_VAL(dstaddr, IPADDR_TYPE_V4);
ip4addr_aton(SOCK_TARGET_HOST4, ip_2_ip4(&dstaddr));
#endif /* LWIP_IPV6 */
#if SOCKET_EXAMPLES_RUN_PARALLEL
sys_thread_new("sockex_nonblocking_connect", sockex_nonblocking_connect, &dstaddr, 0, 0);
sys_thread_new("sockex_testrecv", sockex_testrecv, &dstaddr, 0, 0);
sys_thread_new("sockex_testtwoselects", sockex_testtwoselects, &dstaddr, 0, 0);
#else
sys_thread_new("socket_example_test", socket_example_test, &dstaddr, 0, 0);
#endif
}
#endif /* LWIP_SOCKET */
|
2301_81045437/classic-platform
|
communication/lwip-2.0.3/contrib/apps/socket_examples/socket_examples.c
|
C
|
unknown
| 18,494
|
#ifndef LWIP_SOCKET_EXAMPLES_H
#define LWIP_SOCKET_EXAMPLES_H
void socket_examples_init(void);
#endif /* LWIP_SOCKET_EXAMPLES_H */
|
2301_81045437/classic-platform
|
communication/lwip-2.0.3/contrib/apps/socket_examples/socket_examples.h
|
C
|
unknown
| 139
|
/*
* Copyright (c) 2001-2003 Swedish Institute of Computer Science.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
* 3. The name of the author may not be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
* SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
* IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
* OF SUCH DAMAGE.
*
* This file is part of the lwIP TCP/IP stack.
*
* Author: Adam Dunkels <adam@sics.se>
*
*/
#include "tcpecho.h"
#include "lwip/opt.h"
#if LWIP_NETCONN
#include "lwip/sys.h"
#include "lwip/api.h"
/*-----------------------------------------------------------------------------------*/
static void
tcpecho_thread(void *arg)
{
struct netconn *conn, *newconn;
err_t err;
LWIP_UNUSED_ARG(arg);
/* Create a new connection identifier. */
/* Bind connection to well known port number 7. */
#if LWIP_IPV6
conn = netconn_new(NETCONN_TCP_IPV6);
netconn_bind(conn, IP6_ADDR_ANY, 7);
#else /* LWIP_IPV6 */
conn = netconn_new(NETCONN_TCP);
netconn_bind(conn, IP_ADDR_ANY, 7);
#endif /* LWIP_IPV6 */
LWIP_ERROR("tcpecho: invalid conn", (conn != NULL), return;);
/* Tell connection to go into listening mode. */
netconn_listen(conn);
while (1) {
/* Grab new connection. */
err = netconn_accept(conn, &newconn);
/*printf("accepted new connection %p\n", newconn);*/
/* Process the new connection. */
if (err == ERR_OK) {
struct netbuf *buf;
void *data;
u16_t len;
while ((err = netconn_recv(newconn, &buf)) == ERR_OK) {
/*printf("Recved\n");*/
do {
netbuf_data(buf, &data, &len);
err = netconn_write(newconn, data, len, NETCONN_COPY);
#if 0
if (err != ERR_OK) {
printf("tcpecho: netconn_write: error \"%s\"\n", lwip_strerr(err));
}
#endif
} while (netbuf_next(buf) >= 0);
netbuf_delete(buf);
}
/*printf("Got EOF, looping\n");*/
/* Close connection and discard connection identifier. */
netconn_close(newconn);
netconn_delete(newconn);
}
}
}
/*-----------------------------------------------------------------------------------*/
void
tcpecho_init(void)
{
sys_thread_new("tcpecho_thread", tcpecho_thread, NULL, DEFAULT_THREAD_STACKSIZE, DEFAULT_THREAD_PRIO);
}
/*-----------------------------------------------------------------------------------*/
#endif /* LWIP_NETCONN */
|
2301_81045437/classic-platform
|
communication/lwip-2.0.3/contrib/apps/tcpecho/tcpecho.c
|
C
|
unknown
| 3,694
|
/*
* Copyright (c) 2001-2003 Swedish Institute of Computer Science.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
* 3. The name of the author may not be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
* SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
* IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
* OF SUCH DAMAGE.
*
* This file is part of the lwIP TCP/IP stack.
*
* Author: Adam Dunkels <adam@sics.se>
*
*/
#ifndef LWIP_TCPECHO_H
#define LWIP_TCPECHO_H
void tcpecho_init(void);
#endif /* LWIP_TCPECHO_H */
|
2301_81045437/classic-platform
|
communication/lwip-2.0.3/contrib/apps/tcpecho/tcpecho.h
|
C
|
unknown
| 1,748
|
/*
* Copyright (c) 2001-2004 Swedish Institute of Computer Science.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
* 3. The name of the author may not be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
* SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
* IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
* OF SUCH DAMAGE.
*
* This file is part of and a contribution to the lwIP TCP/IP stack.
*
* Credits go to Adam Dunkels (and the current maintainers) of this software.
*
* Christiaan Simons rewrote this file to get a more stable echo example.
*/
/**
* @file
* TCP echo server example using raw API.
*
* Echos all bytes sent by connecting client,
* and passively closes when client is done.
*
*/
#include "lwip/opt.h"
#include "lwip/debug.h"
#include "lwip/stats.h"
#include "lwip/tcp.h"
#include "tcpecho_raw.h"
#if LWIP_TCP
static struct tcp_pcb *tcpecho_raw_pcb;
enum tcpecho_raw_states
{
ES_NONE = 0,
ES_ACCEPTED,
ES_RECEIVED,
ES_CLOSING
};
struct tcpecho_raw_state
{
u8_t state;
u8_t retries;
struct tcp_pcb *pcb;
/* pbuf (chain) to recycle */
struct pbuf *p;
};
static void
tcpecho_raw_free(struct tcpecho_raw_state *es)
{
if (es != NULL) {
if (es->p) {
/* free the buffer chain if present */
pbuf_free(es->p);
}
mem_free(es);
}
}
static void
tcpecho_raw_close(struct tcp_pcb *tpcb, struct tcpecho_raw_state *es)
{
tcp_arg(tpcb, NULL);
tcp_sent(tpcb, NULL);
tcp_recv(tpcb, NULL);
tcp_err(tpcb, NULL);
tcp_poll(tpcb, NULL, 0);
tcpecho_raw_free(es);
tcp_close(tpcb);
}
static void
tcpecho_raw_send(struct tcp_pcb *tpcb, struct tcpecho_raw_state *es)
{
struct pbuf *ptr;
err_t wr_err = ERR_OK;
while ((wr_err == ERR_OK) &&
(es->p != NULL) &&
(es->p->len <= tcp_sndbuf(tpcb))) {
ptr = es->p;
/* enqueue data for transmission */
wr_err = tcp_write(tpcb, ptr->payload, ptr->len, 1);
if (wr_err == ERR_OK) {
u16_t plen;
plen = ptr->len;
/* continue with next pbuf in chain (if any) */
es->p = ptr->next;
if(es->p != NULL) {
/* new reference! */
pbuf_ref(es->p);
}
/* chop first pbuf from chain */
pbuf_free(ptr);
/* we can read more data now */
tcp_recved(tpcb, plen);
} else if(wr_err == ERR_MEM) {
/* we are low on memory, try later / harder, defer to poll */
es->p = ptr;
} else {
/* other problem ?? */
}
}
}
static void
tcpecho_raw_error(void *arg, err_t err)
{
struct tcpecho_raw_state *es;
LWIP_UNUSED_ARG(err);
es = (struct tcpecho_raw_state *)arg;
tcpecho_raw_free(es);
}
static err_t
tcpecho_raw_poll(void *arg, struct tcp_pcb *tpcb)
{
err_t ret_err;
struct tcpecho_raw_state *es;
es = (struct tcpecho_raw_state *)arg;
if (es != NULL) {
if (es->p != NULL) {
/* there is a remaining pbuf (chain) */
tcpecho_raw_send(tpcb, es);
} else {
/* no remaining pbuf (chain) */
if(es->state == ES_CLOSING) {
tcpecho_raw_close(tpcb, es);
}
}
ret_err = ERR_OK;
} else {
/* nothing to be done */
tcp_abort(tpcb);
ret_err = ERR_ABRT;
}
return ret_err;
}
static err_t
tcpecho_raw_sent(void *arg, struct tcp_pcb *tpcb, u16_t len)
{
struct tcpecho_raw_state *es;
LWIP_UNUSED_ARG(len);
es = (struct tcpecho_raw_state *)arg;
es->retries = 0;
if(es->p != NULL) {
/* still got pbufs to send */
tcp_sent(tpcb, tcpecho_raw_sent);
tcpecho_raw_send(tpcb, es);
} else {
/* no more pbufs to send */
if(es->state == ES_CLOSING) {
tcpecho_raw_close(tpcb, es);
}
}
return ERR_OK;
}
static err_t
tcpecho_raw_recv(void *arg, struct tcp_pcb *tpcb, struct pbuf *p, err_t err)
{
struct tcpecho_raw_state *es;
err_t ret_err;
LWIP_ASSERT("arg != NULL",arg != NULL);
es = (struct tcpecho_raw_state *)arg;
if (p == NULL) {
/* remote host closed connection */
es->state = ES_CLOSING;
if(es->p == NULL) {
/* we're done sending, close it */
tcpecho_raw_close(tpcb, es);
} else {
/* we're not done yet */
tcpecho_raw_send(tpcb, es);
}
ret_err = ERR_OK;
} else if(err != ERR_OK) {
/* cleanup, for unknown reason */
if (p != NULL) {
pbuf_free(p);
}
ret_err = err;
}
else if(es->state == ES_ACCEPTED) {
/* first data chunk in p->payload */
es->state = ES_RECEIVED;
/* store reference to incoming pbuf (chain) */
es->p = p;
tcpecho_raw_send(tpcb, es);
ret_err = ERR_OK;
} else if (es->state == ES_RECEIVED) {
/* read some more data */
if(es->p == NULL) {
es->p = p;
tcpecho_raw_send(tpcb, es);
} else {
struct pbuf *ptr;
/* chain pbufs to the end of what we recv'ed previously */
ptr = es->p;
pbuf_cat(ptr,p);
}
ret_err = ERR_OK;
} else {
/* unkown es->state, trash data */
tcp_recved(tpcb, p->tot_len);
pbuf_free(p);
ret_err = ERR_OK;
}
return ret_err;
}
static err_t
tcpecho_raw_accept(void *arg, struct tcp_pcb *newpcb, err_t err)
{
err_t ret_err;
struct tcpecho_raw_state *es;
LWIP_UNUSED_ARG(arg);
if ((err != ERR_OK) || (newpcb == NULL)) {
return ERR_VAL;
}
/* Unless this pcb should have NORMAL priority, set its priority now.
When running out of pcbs, low priority pcbs can be aborted to create
new pcbs of higher priority. */
tcp_setprio(newpcb, TCP_PRIO_MIN);
es = (struct tcpecho_raw_state *)mem_malloc(sizeof(struct tcpecho_raw_state));
if (es != NULL) {
es->state = ES_ACCEPTED;
es->pcb = newpcb;
es->retries = 0;
es->p = NULL;
/* pass newly allocated es to our callbacks */
tcp_arg(newpcb, es);
tcp_recv(newpcb, tcpecho_raw_recv);
tcp_err(newpcb, tcpecho_raw_error);
tcp_poll(newpcb, tcpecho_raw_poll, 0);
tcp_sent(newpcb, tcpecho_raw_sent);
ret_err = ERR_OK;
} else {
ret_err = ERR_MEM;
}
return ret_err;
}
void
tcpecho_raw_init(void)
{
tcpecho_raw_pcb = tcp_new_ip_type(IPADDR_TYPE_ANY);
if (tcpecho_raw_pcb != NULL) {
err_t err;
err = tcp_bind(tcpecho_raw_pcb, IP_ANY_TYPE, 7);
if (err == ERR_OK) {
tcpecho_raw_pcb = tcp_listen(tcpecho_raw_pcb);
tcp_accept(tcpecho_raw_pcb, tcpecho_raw_accept);
} else {
/* abort? output diagnostic? */
}
} else {
/* abort? output diagnostic? */
}
}
#endif /* LWIP_TCP */
|
2301_81045437/classic-platform
|
communication/lwip-2.0.3/contrib/apps/tcpecho_raw/tcpecho_raw.c
|
C
|
unknown
| 7,901
|
/*
* Copyright (c) 2001-2004 Swedish Institute of Computer Science.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
* 3. The name of the author may not be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
* SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
* IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
* OF SUCH DAMAGE.
*
* This file is part of the lwIP TCP/IP stack.
*
*/
#ifndef LWIP_TCPECHO_RAW_H
#define LWIP_TCPECHO_RAW_H
void tcpecho_raw_init(void);
#endif /* LWIP_TCPECHO_RAW_H */
|
2301_81045437/classic-platform
|
communication/lwip-2.0.3/contrib/apps/tcpecho_raw/tcpecho_raw.h
|
C
|
unknown
| 1,718
|
/*
* Copyright (c) 2001-2003 Swedish Institute of Computer Science.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
* 3. The name of the author may not be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
* SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
* IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
* OF SUCH DAMAGE.
*
* This file is part of the lwIP TCP/IP stack.
*
* Author: Adam Dunkels <adam@sics.se>
*
*/
#include "udpecho.h"
#include "lwip/opt.h"
#if LWIP_NETCONN
#include "lwip/api.h"
#include "lwip/sys.h"
/*-----------------------------------------------------------------------------------*/
static void
udpecho_thread(void *arg)
{
struct netconn *conn;
struct netbuf *buf;
char buffer[4096];
err_t err;
LWIP_UNUSED_ARG(arg);
#if LWIP_IPV6
conn = netconn_new(NETCONN_UDP_IPV6);
netconn_bind(conn, IP6_ADDR_ANY, 7);
#else /* LWIP_IPV6 */
conn = netconn_new(NETCONN_UDP);
netconn_bind(conn, IP_ADDR_ANY, 7);
#endif /* LWIP_IPV6 */
LWIP_ERROR("udpecho: invalid conn", (conn != NULL), return;);
while (1) {
err = netconn_recv(conn, &buf);
if (err == ERR_OK) {
/* no need netconn_connect here, since the netbuf contains the address */
if(netbuf_copy(buf, buffer, sizeof(buffer)) != buf->p->tot_len) {
LWIP_DEBUGF(LWIP_DBG_ON, ("netbuf_copy failed\n"));
} else {
buffer[buf->p->tot_len] = '\0';
err = netconn_send(conn, buf);
if(err != ERR_OK) {
LWIP_DEBUGF(LWIP_DBG_ON, ("netconn_send failed: %d\n", (int)err));
} else {
LWIP_DEBUGF(LWIP_DBG_ON, ("got %s\n", buffer));
}
}
netbuf_delete(buf);
}
}
}
/*-----------------------------------------------------------------------------------*/
void
udpecho_init(void)
{
sys_thread_new("udpecho_thread", udpecho_thread, NULL, DEFAULT_THREAD_STACKSIZE, DEFAULT_THREAD_PRIO);
}
#endif /* LWIP_NETCONN */
|
2301_81045437/classic-platform
|
communication/lwip-2.0.3/contrib/apps/udpecho/udpecho.c
|
C
|
unknown
| 3,179
|
/*
* Copyright (c) 2001-2003 Swedish Institute of Computer Science.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
* 3. The name of the author may not be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
* SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
* IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
* OF SUCH DAMAGE.
*
* This file is part of the lwIP TCP/IP stack.
*
* Author: Adam Dunkels <adam@sics.se>
*
*/
#ifndef LWIP_UDPECHO_H
#define LWIP_UDPECHO_H
void udpecho_init(void);
#endif /* LWIP_UDPECHO_H */
|
2301_81045437/classic-platform
|
communication/lwip-2.0.3/contrib/apps/udpecho/udpecho.h
|
C
|
unknown
| 1,746
|
/*
* Copyright (c) 2016 Stephan Linz <linz@li-pro.net>, Li-Pro.Net
* All rights reserved.
*
* Based on examples provided by
* Iwan Budi Kusnanto <ibk@labhijau.net> (https://gist.github.com/iwanbk/1399729)
* Juri Haberland <juri@sapienti-sat.org> (https://lists.gnu.org/archive/html/lwip-users/2007-06/msg00078.html)
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
* 3. The name of the author may not be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
* SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
* IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
* OF SUCH DAMAGE.
*
* This file is part of and a contribution to the lwIP TCP/IP stack.
*
* Credits go to Adam Dunkels (and the current maintainers) of this software.
*
* Stephan Linz rewrote this file to get a basic echo example.
*/
/**
* @file
* UDP echo server example using raw API.
*
* Echos all bytes sent by connecting client,
* and passively closes when client is done.
*
*/
#include "lwip/opt.h"
#include "lwip/debug.h"
#include "lwip/stats.h"
#include "lwip/udp.h"
#include "udpecho_raw.h"
#if LWIP_UDP
static struct udp_pcb *udpecho_raw_pcb;
static void
udpecho_raw_recv(void *arg, struct udp_pcb *upcb, struct pbuf *p,
const ip_addr_t *addr, u16_t port)
{
LWIP_UNUSED_ARG(arg);
if (p != NULL) {
/* send received packet back to sender */
udp_sendto(upcb, p, addr, port);
/* free the pbuf */
pbuf_free(p);
}
}
void
udpecho_raw_init(void)
{
udpecho_raw_pcb = udp_new_ip_type(IPADDR_TYPE_ANY);
if (udpecho_raw_pcb != NULL) {
err_t err;
err = udp_bind(udpecho_raw_pcb, IP_ANY_TYPE, 7);
if (err == ERR_OK) {
udp_recv(udpecho_raw_pcb, udpecho_raw_recv, NULL);
} else {
/* abort? output diagnostic? */
}
} else {
/* abort? output diagnostic? */
}
}
#endif /* LWIP_UDP */
|
2301_81045437/classic-platform
|
communication/lwip-2.0.3/contrib/apps/udpecho_raw/udpecho_raw.c
|
C
|
unknown
| 3,074
|
/*
* Copyright (c) 2016 Stephan Linz <linz@li-pro.net>, Li-Pro.Net
* All rights reserved.
*
* Based on examples provided by
* Iwan Budi Kusnanto <ibk@labhijau.net> (https://gist.github.com/iwanbk/1399729)
* Juri Haberland <juri@sapienti-sat.org> (https://lists.gnu.org/archive/html/lwip-users/2007-06/msg00078.html)
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
* 3. The name of the author may not be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
* SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
* IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
* OF SUCH DAMAGE.
*
* This file is part of the lwIP TCP/IP stack.
*
*/
#ifndef LWIP_UDPECHO_RAW_H
#define LWIP_UDPECHO_RAW_H
void udpecho_raw_init(void);
#endif /* LWIP_UDPECHO_RAW_H */
|
2301_81045437/classic-platform
|
communication/lwip-2.0.3/contrib/apps/udpecho_raw/udpecho_raw.h
|
C
|
unknown
| 1,937
|
/*-------------------------------- Arctic Core ------------------------------
* Copyright (C) 2013, ArcCore AB, Sweden, www.arccore.com.
* Contact: <contact@arccore.com>
*
* You may ONLY use this file:
* 1)if you have a valid commercial ArcCore license and then in accordance with
* the terms contained in the written license agreement between you and ArcCore,
* or alternatively
* 2)if you follow the terms found in GNU General Public License version 2 as
* published by the Free Software Foundation and appearing in the file
* LICENSE.GPL included in the packaging of this file or here
* <http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt>
*-------------------------------- Arctic Core -----------------------------*/
#include "LwIpAdp.h"
#if defined(USE_ETHSM)
#include "EthSM.h"
#include "EthSM_Cbk.h"
#if (ETHSM_NOF_ETHIF_CONTROLLERS != 1)
#error "LWIP used assumes to have only one instance of Ethernet interface at the moment"
#endif
#endif
typedef struct {
LinkState linkState;
} LwIpAdp_InternalType;
static LwIpAdp_InternalType LwIpAdp_Intern = {
.linkState = LINK_DOWN
};
/**
* @brief Update function of tranciever link state from LWIP on behalf of ASR Eth Trcv module
* @param state
* @retval none
*/
void LwIpAdp_LinkStateUpdate(LinkState State){
if( (LwIpAdp_Intern.linkState != LINK_UP) && (State == LINK_UP)){
LwIpAdp_Intern.linkState = LINK_UP;
#if defined(USE_ETHSM) && (ETHSM_DUMMY_MODE == STD_OFF)
EthSM_TrcvLinkStateChg((ETHSM_NOF_ETHIF_CONTROLLERS-1),ETHTRCV_LINK_STATE_ACTIVE);
#endif
}
else if((LwIpAdp_Intern.linkState == LINK_UP) && (State != LINK_UP)){
LwIpAdp_Intern.linkState = State;
#if defined(USE_ETHSM) && (ETHSM_DUMMY_MODE == STD_OFF)
EthSM_TrcvLinkStateChg((ETHSM_NOF_ETHIF_CONTROLLERS-1),ETHTRCV_LINK_STATE_DOWN);
#endif
}
else{
/* Do nothing */
}
}
|
2301_81045437/classic-platform
|
communication/lwip-2.0.3/contrib/ports/ArcticCore/LwipAdp/LwIpAdp.c
|
C
|
unknown
| 1,958
|
/*-------------------------------- Arctic Core ------------------------------
* Copyright (C) 2013, ArcCore AB, Sweden, www.arccore.com.
* Contact: <contact@arccore.com>
*
* You may ONLY use this file:
* 1)if you have a valid commercial ArcCore license and then in accordance with
* the terms contained in the written license agreement between you and ArcCore,
* or alternatively
* 2)if you follow the terms found in GNU General Public License version 2 as
* published by the Free Software Foundation and appearing in the file
* LICENSE.GPL included in the packaging of this file or here
* <http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt>
*-------------------------------- Arctic Core -----------------------------*/
#ifndef LWIP_ADP_H
#define LWIP_ADP_H
#include "TcpIp_Types.h"
typedef enum {
NO_LINK,
AUTONEGOTIATE_RESTART,
AUTONEGOTIATE_COMPLETE,
LINK_UP,
LINK_DOWN
} LinkState;
void LwIpAdp_LinkStateUpdate(LinkState State);
void LwIpAdp_TcpIpStateUpdate(TcpIp_StateType State);
#endif /*LWIP_ADP_H*/
|
2301_81045437/classic-platform
|
communication/lwip-2.0.3/contrib/ports/ArcticCore/LwipAdp/LwIpAdp.h
|
C
|
unknown
| 1,082
|
/*
* Copyright (c) 2001-2003 Swedish Institute of Computer Science.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
* 3. The name of the author may not be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
* SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
* IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
* OF SUCH DAMAGE.
*
* This file is part of the lwIP TCP/IP stack.
*
* Author: Adam Dunkels <adam@sics.se>
*
*/
#ifndef __CC_H__
#define __CC_H__
#include "Std_Types.h"
#include <stdio.h>
#include <assert.h>
#define BYTE_ORDER LITTLE_ENDIAN
//typedef uint8 u8_t;
//typedef sint8 s8_t;
//typedef uint16 u16_t;
//typedef sint16 s16_t;
//typedef uint32 u32_t;
//typedef sint32 s32_t;
//typedef u32_t mem_ptr_t;
typedef uint32 sys_prot_t;
#define PACK_STRUCT_BEGIN
#define PACK_STRUCT_STRUCT __attribute__ ((__packed__))
#define PACK_STRUCT_END
#define PACK_STRUCT_FIELD(x) x
#define U16_F "u"
#define S16_F "d"
#define X16_F "x"
#define U32_F "u"
#define S32_F "d"
#define X32_F "x"
#define SZT_F "u"
#define LWIP_PLATFORM_DIAG(x) printf x
#define LWIP_PLATFORM_ASSERT(x) assert(0)
#define LWIP_RAND (u32_t)rand
#endif /* __CC_H__ */
|
2301_81045437/classic-platform
|
communication/lwip-2.0.3/contrib/ports/ArcticCore/arm_cm3/arch/cc.h
|
C
|
unknown
| 2,427
|
/*
* Copyright (c) 2001-2003 Swedish Institute of Computer Science.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
* 3. The name of the author may not be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
* SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
* IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
* OF SUCH DAMAGE.
*
* This file is part of the lwIP TCP/IP stack.
*
* Author: Adam Dunkels <adam@sics.se>
*
*/
#ifndef __PERF_H__
#define __PERF_H__
#define PERF_START /* null definition */
#define PERF_STOP(x) /* null definition */
#endif /* __PERF_H__ */
|
2301_81045437/classic-platform
|
communication/lwip-2.0.3/contrib/ports/ArcticCore/arm_cm3/arch/perf.h
|
C
|
unknown
| 1,798
|
/*
* Copyright (c) 2001-2003 Swedish Institute of Computer Science.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
* 3. The name of the author may not be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
* SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
* IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
* OF SUCH DAMAGE.
*
* This file is part of the lwIP TCP/IP stack.
*
* Author: Adam Dunkels <adam@sics.se>
*
*/
#ifndef __SYS_ARCH_H__
#define __SYS_ARCH_H__
#include "Os.h"
#include "Std_Types.h"
#include "mbox.h"
#define SYS_MBOX_NULL NULL
#define SYS_SEM_NULL NULL
#define LWIP_COMPAT_MUTEX 1
void pre_sys_init(void);
typedef OsSemType *sys_sem_t;
typedef OsMBoxType *sys_mbox_t;
typedef TaskType *sys_thread_t;
#define sys_msleep(x) Sleep(x)
#endif /* __SYS_ARCH_H__ */
|
2301_81045437/classic-platform
|
communication/lwip-2.0.3/contrib/ports/ArcticCore/arm_cm3/arch/sys_arch.h
|
C
|
unknown
| 2,033
|
/**
* @file
* Ethernet Interface Skeleton
*
*/
/*
* Copyright (c) 2001-2004 Swedish Institute of Computer Science.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
* 3. The name of the author may not be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
* SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
* IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
* OF SUCH DAMAGE.
*
* This file is part of the lwIP TCP/IP stack.
*
* Author: Adam Dunkels <adam@sics.se>
*
*/
/*
* This file is a skeleton for developing Ethernet network interface
* drivers for lwIP. Add code to the low_level functions and do a
* search-and-replace for the word "ethernetif" to replace it with
* something that better describes your network interface.
*/
#include "lwip/opt.h"
#include "lwip/def.h"
#include "lwip/pbuf.h"
#include "lwip/sys.h"
#include <lwip/stats.h>
#include <lwip/snmp.h>
#include "netif/etharp.h"
//#include "netif/ppp_oe.h"
#include "lwip/err.h"
#include "ethernetif.h"
#include "lwip/ethip6.h"
#include "lwip/tcpip.h"
#include "stm32_eth.h"
#include "stm32f10x.h"
#include "stm32f10x_rcc.h"
#include "stm32f10x_gpio.h"
#include "LwIpAdp.h"
#include <string.h>
#include "isr.h"
#include "irq_types.h"
/* TCP and ARP timeouts */
volatile int tcp_end_time, arp_end_time;
/* Define those to better describe your network interface. */
#define IFNAME0 's'
#define IFNAME1 't'
#define ETH_DMARxDesc_FrameLengthShift 16
#define ETH_ERROR ((uint32_t)0)
#define ETH_SUCCESS ((uint32_t)1)
/* Number of buffer descriptors used */
#define ETH_RXBUFNB 2
#define ETH_TXBUFNB 2
static uint32 outOfMemoryCounter = 0u;
/* Ethernet Rx & Tx DMA Descriptors */
ETH_DMADESCTypeDef DMARxDscrTab[ETH_RXBUFNB] __attribute__ ((aligned (16)));
ETH_DMADESCTypeDef DMATxDscrTab[ETH_TXBUFNB] __attribute__ ((aligned (16)));
/* Ethernet buffers */
uint8_t Rx_Buff[ETH_RXBUFNB][ETH_MAX_PACKET_SIZE] __attribute__ ((aligned (16)));
uint8_t Tx_Buff[ETH_TXBUFNB][ETH_MAX_PACKET_SIZE] __attribute__ ((aligned (16)));
ETH_DMADESCTypeDef *DMATxDesc = DMATxDscrTab;
extern ETH_DMADESCTypeDef *DMATxDescToSet;
extern ETH_DMADESCTypeDef *DMARxDescToGet;
typedef struct{
uint32_t length;
uint32_t buffer;
ETH_DMADESCTypeDef *descriptor;
}FrameTypeDef;
/* Forward declarations. */
static err_t low_level_output(struct netif *netif, struct pbuf *p);
FrameTypeDef ETH_RxPkt_ChainMode(void);
uint32_t ETH_TxPkt_ChainMode(uint16_t FrameLength);
static struct netif *netIfPtr = NULL;
/* Eth Isr routine */
static void Eth_Isr(void)
{
uint32_t res = 0;
while((ETH_GetRxPktSize() != 0) && (res == 0))
{
/* move received packet into a new pbuf */
struct pbuf *p = low_level_input();
if(p!=NULL){
if(netIfPtr != NULL){
/* TODO support multiple ip addresses on the same netif? */
tcpip_input(p, netIfPtr);
}
}else{
res = 1;
}
}
/* Clear the Eth DMA Rx IT pending bits */
ETH_DMAClearITPendingBit(ETH_DMA_IT_R);
ETH_DMAClearITPendingBit(ETH_DMA_IT_NIS);
ETH_DMAClearITPendingBit(ETH_DMA_IT_RO);
ETH_DMAClearITPendingBit(ETH_DMA_IT_RBU);
}
static void LwIP_EthernetIfStart(struct netif *netIf)
{
netIfPtr = netIf;
/* Enable the Ethernet Rx Interrupt */
ETH_DMAITConfig(ETH_DMA_IT_NIS | ETH_DMA_IT_R | ETH_DMA_IT_RO | ETH_DMA_IT_RBU, ENABLE);
}
#define PHY_ADDRESS 0x01 /* Relative to STM3210C-EVAL Board */
//#define MII_MODE /* MII mode for STM3210C-EVAL Board (MB784) (check jumpers setting) */
#define RMII_MODE /* RMII mode for STM3210C-EVAL Board (MB784) (check jumpers setting) */
/**
* @brief Configures the Ethernet Interface
* @param None
* @retval None
*/
static void Ethernet_Configuration(void)
{
ETH_InitTypeDef ETH_InitStructure;
/* MII/RMII Media interface selection ------------------------------------------*/
#ifdef MII_MODE /* Mode MII with STM3210C-EVAL */
GPIO_ETH_MediaInterfaceConfig(GPIO_ETH_MediaInterface_MII);
/* Get HSE clock = 25MHz on PA8 pin (MCO) */
RCC_MCOConfig(RCC_MCO_HSE);
#elif defined RMII_MODE /* Mode RMII with STM3210C-EVAL */
GPIO_ETH_MediaInterfaceConfig(GPIO_ETH_MediaInterface_RMII);
/* Set PLL3 clock output to 50MHz (25MHz /5 *10 =50MHz) */
RCC_PLL3Config(RCC_PLL3Mul_10);
/* Enable PLL3 */
RCC_PLL3Cmd(ENABLE);
/* Wait till PLL3 is ready */
while (RCC_GetFlagStatus(RCC_FLAG_PLL3RDY) == RESET)
{}
/* Get PLL3 clock on PA8 pin (MCO) */
RCC_MCOConfig(RCC_MCO_PLL3CLK);
#endif
/* Reset ETHERNET on AHB Bus */
ETH_DeInit();
/* Software reset */
ETH_SoftwareReset();
/* Wait for software reset */
while (ETH_GetSoftwareResetStatus() == SET);
/* ETHERNET Configuration ------------------------------------------------------*/
/* Call ETH_StructInit if you don't like to configure all ETH_InitStructure parameter */
ETH_StructInit(Ð_InitStructure);
/* Fill ETH_InitStructure parametrs */
/*------------------------ MAC -----------------------------------*/
ETH_InitStructure.ETH_AutoNegotiation = ETH_AutoNegotiation_Enable ;
ETH_InitStructure.ETH_LoopbackMode = ETH_LoopbackMode_Disable;
ETH_InitStructure.ETH_RetryTransmission = ETH_RetryTransmission_Disable;
ETH_InitStructure.ETH_AutomaticPadCRCStrip = ETH_AutomaticPadCRCStrip_Disable;
ETH_InitStructure.ETH_ReceiveAll = ETH_ReceiveAll_Disable;
ETH_InitStructure.ETH_BroadcastFramesReception = ETH_BroadcastFramesReception_Enable;
ETH_InitStructure.ETH_PromiscuousMode = ETH_PromiscuousMode_Disable;
ETH_InitStructure.ETH_MulticastFramesFilter = ETH_MulticastFramesFilter_Perfect;
ETH_InitStructure.ETH_UnicastFramesFilter = ETH_UnicastFramesFilter_Perfect;
#if CHECKSUM_BY_HARDWARE
ETH_InitStructure.ETH_ChecksumOffload = ETH_ChecksumOffload_Enable;
#endif
/*------------------------ DMA -----------------------------------*/
/* When we use the Checksum offload feature, we need to enable the Store and Forward mode:
the store and forward guarantee that a whole frame is stored in the FIFO, so the MAC can insert/verify the checksum,
if the checksum is OK the DMA can handle the frame otherwise the frame is dropped */
ETH_InitStructure.ETH_DropTCPIPChecksumErrorFrame = ETH_DropTCPIPChecksumErrorFrame_Enable;
ETH_InitStructure.ETH_ReceiveStoreForward = ETH_ReceiveStoreForward_Enable;
ETH_InitStructure.ETH_TransmitStoreForward = ETH_TransmitStoreForward_Enable;
ETH_InitStructure.ETH_ForwardErrorFrames = ETH_ForwardErrorFrames_Disable;
ETH_InitStructure.ETH_ForwardUndersizedGoodFrames = ETH_ForwardUndersizedGoodFrames_Disable;
ETH_InitStructure.ETH_SecondFrameOperate = ETH_SecondFrameOperate_Enable;
ETH_InitStructure.ETH_AddressAlignedBeats = ETH_AddressAlignedBeats_Enable;
ETH_InitStructure.ETH_FixedBurst = ETH_FixedBurst_Enable;
ETH_InitStructure.ETH_RxDMABurstLength = ETH_RxDMABurstLength_32Beat;
ETH_InitStructure.ETH_TxDMABurstLength = ETH_TxDMABurstLength_32Beat;
ETH_InitStructure.ETH_DMAArbitration = ETH_DMAArbitration_RoundRobin_RxTx_2_1;
/* Configure Ethernet */
if(ETH_Init(Ð_InitStructure, PHY_ADDRESS)){
LwIpAdp_LinkStateUpdate(LINK_UP);
}
}
/**
* In this function, the hardware should be initialized.
* Called from ethernetif_init().
*
* @param netif the already initialized lwip network interface structure
* for this ethernetif
*/
static void
low_level_init(struct netif *netif)
{
/* set MAC hardware address length */
netif->hwaddr_len = ETHARP_HWADDR_LEN;
uint8_t MACaddr[6] = ETH_MAC_ADDR;
/* Create isr for ethernet interrupt */
ISR_INSTALL_ISR2("Eth_Isr",Eth_Isr, ETH_IRQn, 3, 0);
/* Configure ethernet */
Ethernet_Configuration();
/* set MAC hardware address */
ETH_MACAddressConfig(ETH_MAC_Address0, MACaddr);
netif->hwaddr[0] = MACaddr[0];
netif->hwaddr[1] = MACaddr[1];
netif->hwaddr[2] = MACaddr[2];
netif->hwaddr[3] = MACaddr[3];
netif->hwaddr[4] = MACaddr[4];
netif->hwaddr[5] = MACaddr[5];
/* maximum transfer unit */
netif->mtu = 1500;
/* device capabilities */
/* don't set NETIF_FLAG_ETHARP if this device is not an ethernet one */
netif->flags = NETIF_FLAG_BROADCAST | NETIF_FLAG_ETHARP | NETIF_FLAG_LINK_UP | NETIF_FLAG_IGMP;
/* Initialize Tx Descriptors list: Chain Mode */
ETH_DMATxDescChainInit(DMATxDscrTab, &Tx_Buff[0][0], ETH_TXBUFNB);
/* Initialize Rx Descriptors list: Chain Mode */
ETH_DMARxDescChainInit(DMARxDscrTab, &Rx_Buff[0][0], ETH_RXBUFNB);
/* Enable Ethernet Rx interrrupt */
{ int i;
for(i=0; i<ETH_RXBUFNB; i++)
{
ETH_DMARxDescReceiveITConfig(&DMARxDscrTab[i], ENABLE);
}
}
#if CHECKSUM_BY_HARDWARE
/* Enable the checksum insertion for the Tx frames */
{ int i;
for(i=0; i<ETH_TXBUFNB; i++)
{
ETH_DMATxDescChecksumInsertionConfig(&DMATxDscrTab[i], ETH_DMATxDesc_ChecksumTCPUDPICMPFull);
}
}
#endif
/* Enable MAC and DMA transmission and reception */
ETH_Start();
}
void ethernetif_pre_tcpip_init(void){
}
/**
* Should be called at the beginning of the program to set up the
* network interface. It calls the function low_level_init() to do the
* actual setup of the hardware.
*
* This function should be passed as a parameter to netif_add().
*
* @param netif the lwip network interface structure for this ethernetif
* @return ERR_OK if the loopif is initialized
* ERR_MEM if private data couldn't be allocated
* any other err_t on error
*/
err_t
ethernetif_init(struct netif *netif)
{
LWIP_ASSERT("netif != NULL", (netif != NULL));
/*
* Initialize the snmp variables and counters inside the struct netif.
* The last argument should be replaced with your link speed, in units
* of bits per second.
*/
NETIF_INIT_SNMP(netif, snmp_ifType_ethernet_csmacd, 100000000);
netif->name[0] = IFNAME0;
netif->name[1] = IFNAME1;
/* We directly use etharp_output() here to save a function call.
* You can instead declare your own function an call etharp_output()
* from it if you have to do some checks before sending (e.g. if link
* is available...) */
netif->output = etharp_output;
netif->linkoutput = low_level_output;
#if LWIP_IPV6
netif->output_ip6 = ethip6_output;
#endif /* LWIP_IPV6 */
/* initialize the hardware */
low_level_init(netif);
LwIP_EthernetIfStart(netif);
return ERR_OK;
}
/*******************************************************************************
* Function Name : ETH_RxPkt_ChainMode
* Description : Receives a packet.
* Input : None
* Output : None
* Return : frame: farme size and location
*******************************************************************************/
FrameTypeDef ETH_RxPkt_ChainMode(void)
{
uint32_t framelength = 0;
FrameTypeDef frame = {0,0};
/* Check receive overflow */
if ((ETH->DMASR & ETH_DMASR_ROS) != (uint32_t)RESET){
/* Clear overflow flag */
ETH->DMASR = ETH_DMASR_ROS;
/* Resume DMA reception */
ETH->DMARPDR = 0;
}
if ((ETH->DMASR & ETH_DMASR_RBUS) != (uint32_t)RESET)
{
/* Clear RBUS ETHERNET DMA flag */
ETH->DMASR = ETH_DMASR_RBUS;
/* Resume DMA reception */
ETH->DMARPDR = 0;
}
/* Check if the descriptor is owned by the ETHERNET DMA (when set) or CPU (when reset) */
if((DMARxDescToGet->Status & ETH_DMARxDesc_OWN) != (uint32_t)RESET)
{
frame.length = ETH_ERROR;
/* Return error: OWN bit set */
LWIP_DEBUGF(NETIF_DEBUG, ("ETH_RxPkt_ChainMode: own bit set\n"));
return frame;
}
if(((DMARxDescToGet->Status & ETH_DMARxDesc_ES) == (uint32_t)RESET) &&
((DMARxDescToGet->Status & ETH_DMARxDesc_LS) != (uint32_t)RESET) &&
((DMARxDescToGet->Status & ETH_DMARxDesc_FS) != (uint32_t)RESET))
{
/* Get the Frame Length of the received packet: substruct 4 bytes of the CRC */
framelength = ((DMARxDescToGet->Status & ETH_DMARxDesc_FL) >> ETH_DMARxDesc_FrameLengthShift) - 4;
/* Get the addrees of the actual buffer */
frame.buffer = DMARxDescToGet->Buffer1Addr;
}
else
{
/* Return ERROR */
LWIP_DEBUGF(NETIF_DEBUG, ("ETH_RxPkt_ChainMode: receive error\n"));
framelength = ETH_ERROR;
}
frame.length = framelength;
frame.descriptor = DMARxDescToGet;
/* Update the ETHERNET DMA global Rx descriptor with next Rx decriptor */
/* Chained Mode */
/* Selects the next DMA Rx descriptor list for next buffer to read */
DMARxDescToGet = (ETH_DMADESCTypeDef*) (DMARxDescToGet->Buffer2NextDescAddr);
/* Return Frame */
return (frame);
}
/**
* Should allocate a pbuf and transfer the bytes of the incoming
* packet from the interface into the pbuf.
*
* @return a pbuf filled with the received packet (including MAC header)
* NULL on memory error
*/
struct pbuf *
low_level_input()
{
struct pbuf *p;
uint16_t len;
FrameTypeDef frame;
frame = ETH_RxPkt_ChainMode();
/* Obtain the size of the packet and put it into the "len"
variable. */
len = frame.length;
if(len != ETH_ERROR){
#if ETH_PAD_SIZE
len += ETH_PAD_SIZE; /* allow room for Ethernet padding */
#endif
/* We allocate a pbuf chain of pbufs from the pool. */
p = pbuf_alloc(PBUF_RAW, len, PBUF_POOL);
if (p != NULL){
#if ETH_PAD_SIZE
pbuf_header(p, -ETH_PAD_SIZE); /* drop the padding word */
#endif
memcpy((uint8_t*)p->payload, (uint8_t *)frame.buffer, frame.length);
}else{
/* Out of memory, Nothing to do but to through away data */
outOfMemoryCounter++;
}
/* Set Own bit of the Rx descriptor Status: gives the buffer back to ETHERNET DMA */
frame.descriptor->Status = ETH_DMARxDesc_OWN;
/* When Rx Buffer unavailable flag is set: clear it and resume reception */
if ((ETH->DMASR & ETH_DMASR_RBUS) != (uint32_t)RESET)
{
/* Clear RBUS ETHERNET DMA flag */
ETH->DMASR = ETH_DMASR_RBUS;
/* Resume DMA reception */
ETH->DMARPDR = 0;
}
}else{
/* Error, TODO how should we handle this */
LWIP_DEBUGF(NETIF_DEBUG, ("low_level_input: receive error\n"));
p = NULL;
}
return p;
}
/**
* This function should do the actual transmission of the packet. The packet is
* contained in the pbuf that is passed to the function. This pbuf
* might be chained.
*
* @param netif the lwip network interface structure for this ethernetif
* @param p the MAC packet to send (e.g. IP packet including MAC addresses and type)
* @return ERR_OK if the packet could be sent
* an err_t value if the packet couldn't be sent
*
* @note Returning ERR_MEM here if a DMA queue of your MAC is full can lead to
* strange results. You might consider waiting for space in the DMA queue
* to become availale since the stack doesn't retry to send a packet
* dropped because of memory failure (except for the TCP timers).
*/
static err_t
low_level_output(struct netif *netif, struct pbuf *p)
{
struct pbuf *q;
int l = 0;
uint8_t *buffer = (uint8_t *)(DMATxDescToSet->Buffer1Addr); /* Return Buffer address */
#if ETH_PAD_SIZE
pbuf_header(p, -ETH_PAD_SIZE); /* drop the padding word */
#endif
for(q = p; q != NULL; q = q->next)
{
memcpy((uint8_t*)&buffer[l], q->payload, q->len);
l = l + q->len;
}
return ETH_TxPkt_ChainMode(l);
}
/*******************************************************************************
* Function Name : ETH_TxPkt_ChainMode
* Description : Transmits a packet, from application buffer, pointed by ppkt.
* Input : - FrameLength: Tx Packet size.
* Output : None
* Return : ETH_ERROR: in case of Tx desc owned by DMA
* ETH_SUCCESS: for correct transmission
*******************************************************************************/
uint32_t ETH_TxPkt_ChainMode(uint16_t FrameLength)
{
uint32_t cnt = 0;
/* Check if the descriptor is owned by the ETHERNET DMA (when set) or CPU (when reset) */
while((DMATxDescToSet->Status & ETH_DMATxDesc_OWN) != (uint32_t)RESET)
{
/* OWN bit set. Loop here and wait since frames will not be resend */
cnt++;
if(cnt > 1000000)
{
/* timeout, notify error and return */
LWIP_DEBUGF(NETIF_DEBUG, ("ETH_TxPkt_ChainMode: own bit set\n"));
return ERR_MEM;
}
}
/* Setting the Frame Length: bits[12:0] */
DMATxDescToSet->ControlBufferSize = (FrameLength & ETH_DMATxDesc_TBS1);
/* Setting the last segment and first segment bits (in this case a frame is transmitted in one descriptor) */
DMATxDescToSet->Status |= ETH_DMATxDesc_LS | ETH_DMATxDesc_FS;
/* Set Own bit of the Tx descriptor Status: gives the buffer back to ETHERNET DMA */
DMATxDescToSet->Status |= ETH_DMATxDesc_OWN;
/* When Tx Buffer unavailable flag is set: clear it and resume transmission */
if ((ETH->DMASR & ETH_DMASR_TBUS) != (uint32_t)RESET)
{
/* Clear TBUS ETHERNET DMA flag */
ETH->DMASR = ETH_DMASR_TBUS;
/* Resume DMA transmission*/
ETH->DMATPDR = 0;
}
/* Update the ETHERNET DMA global Tx descriptor with next Tx decriptor */
/* Chained Mode */
/* Selects the next DMA Tx descriptor list for next buffer to send */
DMATxDescToSet = (ETH_DMADESCTypeDef*) (DMATxDescToSet->Buffer2NextDescAddr);
#if ETH_PAD_SIZE
pbuf_header(p, ETH_PAD_SIZE); /* reclaim the padding word */
#endif
/* Return SUCCESS */
return ERR_OK;
}
void EthIf_GetPhysAddr( uint8 CtrlIdx, uint8* PhysAddrPtr ){
uint8 macAddr[6] = ETH_MAC_ADDR;
PhysAddrPtr[0] = macAddr[0];
PhysAddrPtr[1] = macAddr[1];
PhysAddrPtr[2] = macAddr[2];
PhysAddrPtr[3] = macAddr[3];
PhysAddrPtr[4] = macAddr[4];
PhysAddrPtr[5] = macAddr[5];
}
Std_ReturnType EthIf_UpdatePhysAddrFilter( uint8 CtrlIdx, const uint8* PhysAddrPtr, Eth_FilterActionType Action ){
return E_NOT_OK;
}
|
2301_81045437/classic-platform
|
communication/lwip-2.0.3/contrib/ports/ArcticCore/arm_cm3/ethernetif.c
|
C
|
unknown
| 20,273
|
/*-------------------------------- Arctic Core ------------------------------
* Copyright (C) 2013, ArcCore AB, Sweden, www.arccore.com.
* Contact: <contact@arccore.com>
*
* You may ONLY use this file:
* 1)if you have a valid commercial ArcCore license and then in accordance with
* the terms contained in the written license agreement between you and ArcCore,
* or alternatively
* 2)if you follow the terms found in GNU General Public License version 2 as
* published by the Free Software Foundation and appearing in the file
* LICENSE.GPL included in the packaging of this file or here
* <http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt>
*-------------------------------- Arctic Core -----------------------------*/
#ifndef __ETHERNETIF_H__
#define __ETHERNETIF_H__
#include "lwip/err.h"
#include "lwip/netif.h"
err_t ethernetif_init(struct netif *netif);
void ethernetif_pre_tcpip_init(void);
struct pbuf * low_level_input();
/* ASR EthIf mockers */
#include "Eth_GeneralTypes.h"
/* EthIf controller IDs */
#define EthIfConf_EthIfController_EthIfController 0u
void EthIf_GetPhysAddr( uint8 CtrlIdx, uint8* PhysAddrPtr );
Std_ReturnType EthIf_UpdatePhysAddrFilter( uint8 CtrlIdx, const uint8* PhysAddrPtr, Eth_FilterActionType Action );
#endif
|
2301_81045437/classic-platform
|
communication/lwip-2.0.3/contrib/ports/ArcticCore/arm_cm3/ethernetif.h
|
C
|
unknown
| 1,310
|
#define LWIP_AR_MAJOR_VERSION 1
#define LWIP_AR_MINOR_VERSION 0
#define LWIP_AR_PATCH_VERSION 0
#define LWIP_SW_MAJOR_VERSION 1
#define LWIP_SW_MINOR_VERSION 0
#define LWIP_SW_PATCH_VERSION 0
/* New important lwip1.4.1 defines */
#define LWIP_TCPIP_CORE_LOCKING 1
#define LWIP_CHECKSUM_ON_COPY 0
#define LWIP_COMPAT_MUTEX_ALLOWED 1
#define TCPIP_MBOX_SIZE 50
#define MEMP_NUM_NETBUF 10
#define MEMP_NUM_TCPIP_MSG_INPKT 20
/* We want to be notified when the link changes status. */
#define LWIP_NETIF_STATUS_CALLBACK 1
/* Support IPV6(mandatory for doip) */
#define LWIP_IPV6 0
#include "LwIp_Cfg.h"
|
2301_81045437/classic-platform
|
communication/lwip-2.0.3/contrib/ports/ArcticCore/arm_cm3/lwipopts.h
|
C
|
unknown
| 656
|
/*
* Copyright (c) 2001-2003 Swedish Institute of Computer Science.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
* 3. The name of the author may not be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
* SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
* IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
* OF SUCH DAMAGE.
*
* This file is part of the lwIP TCP/IP stack.
*
* Author: Adam Dunkels <adam@sics.se>
*
*/
#ifndef __CC_H__
#define __CC_H__
#include "Std_Types.h"
#include <stdio.h>
#include <assert.h>
#if defined(CFG_ZYNQ) || defined(CFG_JAC6) || defined(CFG_S32K148)
#define BYTE_ORDER LITTLE_ENDIAN
#else
#define BYTE_ORDER BIG_ENDIAN
#endif
//typedef uint8 u8_t;
//typedef sint8 s8_t;
//typedef uint16 u16_t;
//typedef sint16 s16_t;
//typedef uint32 u32_t;
//typedef sint32 s32_t;
//typedef u32_t mem_ptr_t;
typedef uint32 sys_prot_t;
/* IMPROVEMENT - read it from compiler.h */
#define PACK_STRUCT_BEGIN
#if defined(__GNUC__)
#define PACK_STRUCT_STRUCT __attribute__ ((__packed__))
#elif defined (__ARMCC_VERSION)
#define PACK_STRUCT_STRUCT __attribute__ ((packed))
#elif defined(__ghs__)
#define PACK_STRUCT_STRUCT __attribute__ ((packed))
#else
#define PACK_STRUCT_STRUCT
#endif
#define PACK_STRUCT_END
#define PACK_STRUCT_FIELD(x) x
#define U16_F "u"
#define S16_F "d"
#define X16_F "x"
#define U32_F "u"
#define S32_F "d"
#define X32_F "x"
#define SZT_F "u"
#define LWIP_PLATFORM_DIAG(x) printf x
#define LWIP_PLATFORM_ASSERT(x) assert(0)
#define LWIP_RAND (u32_t)rand
#endif /* __CC_H__ */
|
2301_81045437/classic-platform
|
communication/lwip-2.0.3/contrib/ports/ArcticCore/asrIf/arch/cc.h
|
C
|
unknown
| 2,814
|
/*
* Copyright (c) 2001-2003 Swedish Institute of Computer Science.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
* 3. The name of the author may not be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
* SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
* IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
* OF SUCH DAMAGE.
*
* This file is part of the lwIP TCP/IP stack.
*
* Author: Adam Dunkels <adam@sics.se>
*
*/
#ifndef __PERF_H__
#define __PERF_H__
#define PERF_START /* null definition */
#define PERF_STOP(x) /* null definition */
#endif /* __PERF_H__ */
|
2301_81045437/classic-platform
|
communication/lwip-2.0.3/contrib/ports/ArcticCore/asrIf/arch/perf.h
|
C
|
unknown
| 1,798
|
/*
* Copyright (c) 2001-2003 Swedish Institute of Computer Science.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
* 3. The name of the author may not be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
* SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
* IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
* OF SUCH DAMAGE.
*
* This file is part of the lwIP TCP/IP stack.
*
* Author: Adam Dunkels <adam@sics.se>
*
*/
#ifndef __SYS_ARCH_H__
#define __SYS_ARCH_H__
#include "Os.h"
#include "os_sem.h"
#include "os_mbox.h"
#include "Std_Types.h"
#include "mbox.h"
#define SYS_MBOX_NULL NULL
#define SYS_SEM_NULL NULL
#define LWIP_COMPAT_MUTEX 1
void pre_sys_init(void);
typedef OsSemType * sys_sem_t;
typedef OsMBoxType* sys_mbox_t;
typedef TaskType sys_thread_t;
#define sys_msleep(x) Sleep(x)
#endif /* __SYS_ARCH_H__ */
|
2301_81045437/classic-platform
|
communication/lwip-2.0.3/contrib/ports/ArcticCore/asrIf/arch/sys_arch.h
|
C
|
unknown
| 2,075
|
/**
* @file
* Ethernet Interface Skeleton
*
*/
/*
* Copyright (c) 2001-2004 Swedish Institute of Computer Science.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
* 3. The name of the author may not be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
* SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
* IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
* OF SUCH DAMAGE.
*
* This file is part of the lwIP TCP/IP stack.
*
* Author: Adam Dunkels <adam@sics.se>
*
*/
/*
* This file is a skeleton for developing Ethernet network interface
* drivers for lwIP. Add code to the low_level functions and do a
* search-and-replace for the word "ethernetif" to replace it with
* something that better describes your network interface.
*/
#include "lwip/opt.h"
#include "lwip/def.h"
#include "lwip/pbuf.h"
#include "lwip/sys.h"
#include <lwip/stats.h>
#include <lwip/snmp.h>
#include "netif/etharp.h"
#include "netif/ppp_oe.h"
#include "lwip/err.h"
#include "ethernetif.h"
#include "lwip/ethip6.h"
#include "lwip/tcpip.h"
#include "Eth.h"
#include "LwIpAdp.h"
#include <string.h>
#include "isr.h"
#include "irq_types.h"
#if defined(CFG_JAC6)
#include "Eth_jacinto.h"
#endif
/* TCP and ARP timeouts */
volatile int tcp_end_time, arp_end_time;
static uint8 phyAddress = 32u; /* Invalid address or Phy is not initialised in this context */
static boolean ethCtrlInitRun = FALSE;
static boolean ethTrcvInitRun = FALSE;
/* Define those to better describe your network interface. */
#define IFNAME0 's'
#define IFNAME1 't'
#define ETH_HEADER_SIZE 14u
#define ETH_MAC_ADDR_SIZE 6u
#define READ32(address) (*(vuint32_t *)(address))
#define WRITE32(address, val) (*(volatile uint32_t*)(address) = val)
#define ETH_CTRL_INDEX 0u /* Assign HW_UNIT_0 to this index */
#define VLAN_HEADER_SIZE 4u
#define BMCR_REGISTER 0u
#define BMSR_REGISTER 1u
#define AUTONEG_ADVERTISE_REGISTER 4u
#define PHY_SOFT_RESET 0x8000u
#define ENABLE_AUTO_NEGOTIATION 0x1000u
#define ENABLE_100MBPS_DUPLEX 0x2100u
#if defined(CFG_ETH_PHY_DP83848C)
#define PHY_STATUS_REGISTER 0x10u
#define PHY_STATUS_LINK 0x0001u
#define PHY_STATUS_NO_AUTO_100 0x0005u
#define PHY_STATUS_LOOPBACK 0x0008u
#elif defined (CFG_ETH_PHY_TJA1100)
#define PHY_STATUS_REGISTER 0x01u
#define PHY_EXTENDED_STATUS_REGISTER 15u
#define PHY_EXTENDED_CONTROL_REGISTER 17u
#define PHY_CONFIG_REGISTER1 18u
#define PHY_STATUS_LINK 0x0004u
#define PHY_STATUS_NO_AUTO_100 0xE600u /*100BASE-T4,100BASE-X_FD,100BASE-X_HD,100BASE-T2_FD,100BASE-T2_HD*/
#define PHY_EXTENDED_STATUS_NO_AUTO_100 0x0080u
#define PHY_CONFIG_EN_BIT (2u)
#define PHY_CONFIG_MASTER_SLAVE_BIT (15u)
#else /* CFG_ETH_PHY_DP83865 */
#define PHY_STATUS_REGISTER 0x11u
#define PHY_STATUS_LINK 0x0004u
#define PHY_STATUS_NO_AUTO_100 0x000Eu
#define PHY_STATUS_LOOPBACK 0x0040u
#define RGMII_INBAND_STATUS_EN 0x0100U
#endif
#ifdef CFG_BRD_ZYNQ_ZC702
#define PORT_MIO_52 0xF80007D0
#define PORT_MIO_53 0xF80007D4
#endif
#if defined(CFG_JAC6)
#define GMAC_SW_MDIO_LINKSEL 0x00000080U
#define GMAC_SW_MDIO_LINKINTENB 0x00000040U
#define GMAC_SW_MDIO_PHYADDRMON_MASK 0x0000001FU
#define ETH_CTRL_TX_FRAME_MIN_SIZE 60u
#define ETH_CTRL_PAD
#if defined(CFG_ETH_HW_SHARE)
#define VLAN_TCI (0x0042u)
#endif
static GmacSw_HwRegType * const hwPtr = (GmacSw_HwRegType*) GMAC_SW_BASE;
#endif
/* Max wait cycles for actions to occur in busy wait***** */
#define ETH_MAX_BUSY_WAIT_CYCLES (uint32)1000
#define ETH_MDIO_WAIT_CYCLES 50u
/* Macro for busy waiting for a while */
#define BUSY_WAIT_A_WHILE(_regPtr, _mask, _val, _retPtr)\
*(_retPtr) = E_NOT_OK;\
for( uint32 i = 0; i < ETH_MAX_BUSY_WAIT_CYCLES; i++) {\
if( (*(_regPtr) & (_mask)) == (_val) ) {\
*(_retPtr) = E_OK;\
break;\
}\
}\
#define ETH_LINK_CHECK /* internal defines for the internal config and test */
LinkState linkStatus = NO_LINK;
/* Forward declarations. */
static err_t low_level_output(struct netif *netif, struct pbuf *p);
static uint8 Eth_TransHw_findPhyAdrs(uint8 ctrlIdx,uint8 startPhyAddr, uint8 endPhyAddr);
static Std_ReturnType Eth_TransHw_init(uint8 ctrlIdx);
static struct netif *netIfPtr = NULL;
/**
* @brief Mock up function for ETH_IF : Frames reception routine
* Call recurrently, Disable RX interrupt
* @param None
* @retval None
*/
void Ethernetif_RxFunc(void)
{
if((ethCtrlInitRun == FALSE) || (ethTrcvInitRun == FALSE)){
return;
}
#if defined(CFG_JAC6)
Eth_TransHw_linkUp(ETH_CTRL_INDEX);
#endif
if(linkStatus == LINK_UP){
#if defined(CFG_RH850)
Eth_Receive(ETH_CTRL_INDEX);
#else
#if defined(CFG_JAC6) && defined(CFG_ETH_HW_SHARE) /* Interrupt mode is not sharable */
Eth_TxConfirmation(ETH_CTRL_INDEX);
#endif
Eth_RxStatusType rxStatus; /* unused */
Eth_Receive(ETH_CTRL_INDEX,&rxStatus);
(void)rxStatus;
#endif
}
}
/**
* @brief Mock up function for ETH_IF : Frames reception function
* @param --
* @retval None
*/
void EthIf_RxIndication( uint8 CtrlIdx, Eth_FrameType FrameType, boolean IsBroadcast, uint8* PhysAddrPtr, Eth_DataType* DataPtr, uint16 LenByte )
{
struct pbuf *p;
uint8 macAdrs[ETH_MAC_ADDR_SIZE] = ETH_MAC_ADDR;
uint8 macBroadcastAdrs[ETH_MAC_ADDR_SIZE] = {0xFF,0xFF,0xFF,0xFF,0xFF,0xFF};
uint16 AdaptFrameType;
uint16 AdaptFrameType1;
#if ETH_PAD_SIZE
len += ETH_PAD_SIZE; /* allow room for Ethernet padding */
#endif
p = pbuf_alloc(PBUF_RAW, LenByte+ETH_HEADER_SIZE, PBUF_POOL);
if (p != NULL){
#if ETH_PAD_SIZE
pbuf_header(p, -ETH_PAD_SIZE); /* drop the padding word */
#endif
if(IsBroadcast == TRUE){
MEMCPY((uint8*)p->payload,macBroadcastAdrs,ETH_MAC_ADDR_SIZE);
}else{
MEMCPY((uint8*)p->payload,macAdrs,ETH_MAC_ADDR_SIZE);
}
MEMCPY((uint8*)p->payload+ETH_MAC_ADDR_SIZE,PhysAddrPtr,ETH_MAC_ADDR_SIZE);
#if defined(CFG_ZYNQ) || defined(CFG_JAC6)
AdaptFrameType = (uint16)(FrameType >> 8 ) + (uint16)(FrameType << 8);
MEMCPY((uint8*)p->payload+(2*ETH_MAC_ADDR_SIZE),&AdaptFrameType,sizeof(uint16));
if(AdaptFrameType == PP_HTONS(ETHTYPE_VLAN)){
AdaptFrameType1 = (uint16)(DataPtr[2]) + (uint16)(DataPtr[3] << 8);
MEMCPY((uint8*)p->payload+(2*ETH_MAC_ADDR_SIZE),&AdaptFrameType1,sizeof(uint16));
}
#else
MEMCPY((uint8*)p->payload+(2*ETH_MAC_ADDR_SIZE),&FrameType,sizeof(uint16));
#endif
if(AdaptFrameType != PP_HTONS(ETHTYPE_VLAN)){
MEMCPY((uint8*)p->payload+ETH_HEADER_SIZE,DataPtr,LenByte);
}else{
MEMCPY((uint8*)p->payload+ETH_HEADER_SIZE,&DataPtr[VLAN_HEADER_SIZE],(LenByte-VLAN_HEADER_SIZE));
}
if(netIfPtr != NULL){
tcpip_input(p, netIfPtr);
}
}else{
/* Out of memory, Nothing to do but to through away data */
return;
}
}
/**
* @brief Mock up function for ETH_IF : Transmit conmfirmation
* Doing nothing currently
* @param None
* @retval None
*/
void EthIf_TxConfirmation( uint8 CtrlIdx, uint8 BufIdx )
{
/* done */
}
void LwIP_EthernetIfStart(struct netif *netIf)
{
netIfPtr = netIf;
}
/**
* In this function, the hardware should be initialized.
* Called from ethernetif_init().
*
* @param netif the already initialized lwip network interface structure
* for this ethernetif
*/
static void
low_level_init(struct netif *netif)
{
/* set MAC hardware address length */
netif->hwaddr_len = ETHARP_HWADDR_LEN;
uint8_t MACaddr[6] = ETH_MAC_ADDR;
netif->hwaddr[0] = MACaddr[0];
netif->hwaddr[1] = MACaddr[1];
netif->hwaddr[2] = MACaddr[2];
netif->hwaddr[3] = MACaddr[3];
netif->hwaddr[4] = MACaddr[4];
netif->hwaddr[5] = MACaddr[5];
/* maximum transfer unit */
netif->mtu = 1500;
/* device capabilities */
/* don't set NETIF_FLAG_ETHARP if this device is not an ethernet one */
netif->flags = NETIF_FLAG_BROADCAST | NETIF_FLAG_ETHARP | NETIF_FLAG_LINK_UP | NETIF_FLAG_IGMP;
}
void ethernetif_pre_tcpip_init(void){
const uint8_t MACaddr[6] = ETH_MAC_ADDR;
#ifdef CFG_BRD_ZYNQ_ZC702
/* IMPROVE - port driver change is required*/
WRITE32(PORT_MIO_52,0x00001280);
WRITE32(PORT_MIO_53,0x00001280);
#endif
if(E_OK == Eth_ControllerInit(ETH_CTRL_INDEX,0)){
ethCtrlInitRun = TRUE;
}
#if defined(CFG_ZYNQ) || defined(CFG_JAC6)
#if (ETH_PHYS_ADRS_FILTER_API == STD_ON)
Eth_UpdatePhysAddrFilter(ETH_CTRL_INDEX,MACaddr,ETH_ADD_TO_FILTER);
#endif
#endif
#ifdef CHECKSUM_BY_HARDWARE
/* Do nothing at the moment */
#endif
Eth_SetControllerMode(ETH_CTRL_INDEX,ETH_MODE_ACTIVE);
#if defined(CFG_JAC6) && (LWIP_TRCV_ADRS != 32u)
phyAddress = LWIP_TRCV_ADRS;
#else
phyAddress = Eth_TransHw_findPhyAdrs(ETH_CTRL_INDEX,0,31);
#endif
if(phyAddress != 32u){
(void)Eth_TransHw_init(ETH_CTRL_INDEX);
}
}
/**
* Should be called at the beginning of the program to set up the
* network interface. It calls the function low_level_init() to do the
* actual setup of the hardware.
*
* This function should be passed as a parameter to netif_add().
*
* @param netif the lwip network interface structure for this ethernetif
* @return ERR_OK if the loopif is initialized
* ERR_MEM if private data couldn't be allocated
* any other err_t on error
*/
err_t
ethernetif_init(struct netif *netif)
{
LWIP_ASSERT("netif != NULL", (netif != NULL));
/*
* Initialize the snmp variables and counters inside the struct netif.
* The last argument should be replaced with your link speed, in units
* of bits per second.
*/
NETIF_INIT_SNMP(netif, snmp_ifType_ethernet_csmacd, 100000000);
netif->name[0] = IFNAME0;
netif->name[1] = IFNAME1;
/* We directly use etharp_output() here to save a function call.
* You can instead declare your own function an call etharp_output()
* from it if you have to do some checks before sending (e.g. if link
* is available...) */
netif->output = etharp_output;
netif->linkoutput = low_level_output;
#if LWIP_IPV6
netif->output_ip6 = ethip6_output;
#endif /* LWIP_IPV6 */
/* initialize the hardware */
low_level_init(netif);
LwIP_EthernetIfStart(netif);
return ERR_OK;
}
/**
* This function should do the actual transmission of the packet. The packet is
* contained in the pbuf that is passed to the function. This pbuf
* might be chained.
*
* @param netif the lwip network interface structure for this ethernetif
* @param p the MAC packet to send (e.g. IP packet including MAC addresses and type)
* @return ERR_OK if the packet could be sent
* an err_t value if the packet couldn't be sent
*
* @note Returning ERR_MEM here if a DMA queue of your MAC is full can lead to
* strange results. You might consider waiting for space in the DMA queue
* to become availale since the stack doesn't retry to send a packet
* dropped because of memory failure (except for the TCP timers).
*/
static err_t
low_level_output(struct netif *netif, struct pbuf *p)
{
struct pbuf *q;
int l = 0;
uint8 *buffer;
uint32 baseAddress;
uint32_t cnt = 0;
Eth_BufIdxType bufIndex = 0;
uint16 lenByte = 0;
Eth_FrameType frametype;
BufReq_ReturnType bufRes;
Std_ReturnType txRes;
bufRes = Eth_ProvideTxBuffer(ETH_CTRL_INDEX, &bufIndex,(Eth_DataType **) &baseAddress, &lenByte);
if(bufRes != BUFREQ_OK){
LWIP_DEBUGF(NETIF_DEBUG, ("send: buffer not available\n"));
/* Try to increase the number of ETH TX buffers */
return ERR_MEM;
}
#if ETH_PAD_SIZE
pbuf_header(p, -ETH_PAD_SIZE); /* drop the padding word */
#endif
buffer = (u8_t*)(baseAddress-ETH_HEADER_SIZE);
#if defined(CFG_JAC6) && defined(CFG_ETH_HW_SHARE)
for(q = p; q != NULL; q = q->next)
{
if(l == 0u){
SMEMCPY((u8_t*)buffer, q->payload, (ETH_MAC_ADDR_SIZE*2));
buffer[12] = (uint8)((ETHTYPE_VLAN >> 8u) & 0xFFu); /* 0x8100 */
buffer[13] = (uint8) (ETHTYPE_VLAN & 0xFFu);
buffer[14] = (uint8)((VLAN_TCI >> 8u) & 0xFFu);
buffer[15] = (uint8) (VLAN_TCI & 0xFFu);
SMEMCPY((u8_t*)&buffer[(ETH_MAC_ADDR_SIZE*2)+VLAN_HEADER_SIZE], (q->payload+(ETH_MAC_ADDR_SIZE*2)), (q->len-(ETH_MAC_ADDR_SIZE*2)));
l = ((q->len) + VLAN_HEADER_SIZE);
}else{
SMEMCPY((u8_t*)&buffer[l], q->payload, q->len);
l = l + q->len;
}
}
#else
for(q = p; q != NULL; q = q->next)
{
SMEMCPY((u8_t*)&buffer[l], q->payload, q->len);
l = l + q->len;
}
#endif
/* Try to send */
cnt = 0;
#if defined(CFG_ZYNQ) || defined(CFG_JAC6)
frametype = ((buffer[12] << 8) + buffer[13] );
#else
frametype = ((buffer[13] << 8) + buffer[12] );
#endif
#if defined(ETH_CTRL_PAD)
if(l < ETH_CTRL_TX_FRAME_MIN_SIZE){
for(uint8 i = l; i < ETH_CTRL_TX_FRAME_MIN_SIZE; i++){
buffer[i] = 0u;
}
l = ETH_CTRL_TX_FRAME_MIN_SIZE;
}
#endif
txRes = Eth_Transmit(ETH_CTRL_INDEX,bufIndex,frametype,TRUE,(l-ETH_HEADER_SIZE),buffer);
while(txRes == E_PENDING)
{
/* TXBD_READY bit set. Loop here and wait since frames will not be resend */
if(!(cnt % 500)){
Eth_TxConfirmation(ETH_CTRL_INDEX); /* only in POLLING mode */
txRes = Eth_Transmit(ETH_CTRL_INDEX,bufIndex,frametype,TRUE,(l-ETH_HEADER_SIZE),buffer);
}
cnt++;
if(cnt > 1000000)
{
/* timeout, notify error and return */
LWIP_DEBUGF(NETIF_DEBUG, ("send: not ready\n"));
return ERR_TIMEOUT;
}
}
#if ETH_PAD_SIZE
pbuf_header(p, ETH_PAD_SIZE); /* reclaim the padding word */
#endif
/* Return SUCCESS */
return ERR_OK;
}
/**
* Fetch PHY address:: mock up function for ETH tranciever
* @param startPhyAddr
* @param endPhyAddr
* @return phyAddr
*/
uint8 Eth_TransHw_findPhyAdrs(uint8 ctrlIdx, uint8 startPhyAddr, uint8 endPhyAddr)
{
uint8 phy_addr;
for (phy_addr = 0; phy_addr <= endPhyAddr; phy_addr++) {
#if !defined(CFG_JAC6)
uint8 Status;
uint16 Reg1;
uint16 Reg2;
Status = Eth_ReadMii(ctrlIdx,phy_addr, 2, &Reg1);
Status |= Eth_ReadMii(ctrlIdx,phy_addr,3, &Reg2); /* change it */
if ((Status == ETH_OK) &&
(Reg1 > 0x0000) && (Reg1 < 0xffff) &&
(Reg2 > 0x0000) && (Reg2 < 0xffff)) {
return phy_addr;
}
#else
for( uint32 i = 0; i < ETH_MDIO_WAIT_CYCLES; i++); /* Provide some time for MDIO module to find the PHYs available */
if(hwPtr->MDIO.MDIO_ALIVE & (0x1u << phy_addr)){
return phy_addr;
}
#endif
}
return phy_addr;
}
/**
* Link Setting up - Needed to be called from a cyclic routine
* precondition - phyAddress is valid
* @param ctrlIdx
* @return
*/
void Eth_TransHw_linkUp(uint8 ctrlIdx)
{
if(phyAddress != 32u){
uint16 statusValue = 0;
#if !defined(CFG_JAC6)
uint16 regValue;
if(linkStatus == NO_LINK)
{
/* Set auto neg advert register */
(void)Eth_WriteMii(ctrlIdx,phyAddress, AUTONEG_ADVERTISE_REGISTER, 0x01e1);
// Enable and start auto-negotiation
Eth_ReadMii(ctrlIdx,phyAddress,BMCR_REGISTER, ®Value);
Eth_WriteMii(ctrlIdx,phyAddress,BMCR_REGISTER, (regValue | 0x1200));
linkStatus = AUTONEGOTIATE_RESTART;
}
// Wait for Auto-Neg complete flag
Eth_ReadMii(ctrlIdx,phyAddress,BMSR_REGISTER,&statusValue);
if((statusValue & 0x0020 )== 0x0020){
linkStatus = AUTONEGOTIATE_COMPLETE;
}
Eth_ReadMii(ctrlIdx,phyAddress,PHY_STATUS_REGISTER,&statusValue);
if((statusValue & PHY_STATUS_LINK ) != 0){
linkStatus = LINK_UP;
}else{
linkStatus = LINK_DOWN;
}
LwIpAdp_LinkStateUpdate(linkStatus);
#else
Eth_ReadMii(ctrlIdx,phyAddress,PHY_STATUS_REGISTER,&statusValue);
if((statusValue & PHY_STATUS_LINK ) != 0){
linkStatus = LINK_UP;
}else{
linkStatus = LINK_DOWN;
}
LwIpAdp_LinkStateUpdate(linkStatus);
#endif
}else{
phyAddress = Eth_TransHw_findPhyAdrs(ETH_CTRL_INDEX,0,31);
if(phyAddress != 32u){
(void)Eth_TransHw_init(ETH_CTRL_INDEX);
}
}
}
/**
* @brief Mock up function for ETH Tranceiver : Initialise tranciever required
* @param ctrlIdx
* @retval Std_ReturnType
*/
Std_ReturnType Eth_TransHw_init(uint8 ctrlIdx)
{
if(ethCtrlInitRun != TRUE){ /* Tranciever is initialised after Eth controller initialisation */
return E_NOT_OK;
}
#if defined(CFG_ETH_PHY_DP83848C) || defined(CFG_ETH_PHY_DP83865) || defined(CFG_ETH_PHY_TJA1100)
uint16 phyStatus;
uint16 timeout;
#if defined(CFG_ETH_PHY_TJA1100)
uint16 extdPhyStatus;
#endif
uint16 regValue;
/* Wait for completion */
timeout = 10000;
/* Reset phy */
(void)Eth_WriteMii(ctrlIdx,phyAddress, BMCR_REGISTER, PHY_SOFT_RESET);
for(volatile uint16 i=0; i < 1000; i++){};
#if defined(CFG_JAC6) /* ETH_NO_AUTO_NEG */
hwPtr->MDIO.MDIO_USERPHYSEL0 |= GMAC_SW_MDIO_LINKSEL;
hwPtr->MDIO.MDIO_USERPHYSEL0 |= (GMAC_SW_MDIO_PHYADDRMON_MASK & phyAddress);
(void)Eth_ReadMii (ctrlIdx,phyAddress, BMCR_REGISTER, ®Value);
regValue &= ~ENABLE_AUTO_NEGOTIATION; // disable AN
(void)Eth_WriteMii(ctrlIdx,phyAddress, BMCR_REGISTER, (regValue | ENABLE_100MBPS_DUPLEX));
for(volatile uint16 i=0; i < ETH_MDIO_WAIT_CYCLES; i++){};
do
{
for(volatile uint16 i=0; i < ETH_MDIO_WAIT_CYCLES; i++){};
if ((timeout--) == 0) {
return E_NOT_OK;
}
Eth_ReadMii(ctrlIdx,phyAddress, PHY_STATUS_REGISTER, &phyStatus);
#if defined (CFG_ETH_PHY_TJA1100)
Eth_ReadMii(ctrlIdx,phyAddress, PHY_EXTENDED_STATUS_REGISTER, &extdPhyStatus);
#endif
}while
#if !defined (CFG_ETH_PHY_TJA1100)
((phyStatus & PHY_STATUS_NO_AUTO_100) != PHY_STATUS_NO_AUTO_100);
#else
(((phyStatus & PHY_STATUS_NO_AUTO_100) == 0u) && ((extdPhyStatus & PHY_EXTENDED_STATUS_NO_AUTO_100) != PHY_EXTENDED_STATUS_NO_AUTO_100));
#endif
#else //CFG_JAC6(ETH_NO_AUTO_NEG) end
#ifdef ETH_LINK_CHECK
Eth_TransHw_linkUp(ctrlIdx);
#else
/* Set auto neg advert register */
(void)Eth_WriteMii(ctrlIdx,phyAddress, AUTONEG_ADVERTISE_REGISTER, 0x01e1);
/* enable auto-negotiation */
(void)Eth_ReadMii (ctrlIdx,phyAddress, BMCR_REGISTER, ®Value);
(void)Eth_WriteMii(ctrlIdx,phyAddress, BMCR_REGISTER, (regValue | 0x1200));
do {
for(volatile uint16 i=0; i < 1000; i++){
}
if ((timeout--) == 0) {
return E_NOT_OK;
}
if (Eth_ReadMii(ctrlIdx,phyAddress, BMSR_REGISTER, &phyStatus) != 0) {
return E_NOT_OK;
}
if(phyStatus == 0xffff){
return E_NOT_OK;
}
} while (!(phyStatus & 0x0020)); // Should be 0x786D
#endif //ETH_LINK_CHECK end
#endif /* Auto negotiate end */
#ifdef ETH_PHYLOOPBACK /* physical line test */
(void)Eth_ReadMii (ctrlIdx,phyAddress, BMCR_REGISTER, ®Value);
(void)Eth_WriteMii(ctrlIdx,phyAddress, BMCR_REGISTER, (regValue | 0x6100)); // loopback with speed 100
do
{
for(volatile uint16 i=0; i < 1000; i++){};
if ((timeout--) == 0) {
return E_NOT_OK;
}
Eth_ReadMii(ctrlIdx,phyAddress, PHY_STATUS_REGISTER, &phyStatus);
}while (!(phyStatus & PHY_STATUS_LOOPBACK));
#endif /* physical line test */
#else /* other phy */
/* PHY device - MARVELL-88E1111 */
#define RGMII_TXRX_CLK_DELAY 0x0030
#define ASYMMETRIC_PAUSE 0x0800
#define PAUSE 0x0400
#define LINKSPEED_1000MBPS 0x0040
#define LINKSPEED_100MBPS 0x2000
#define LINKSPEED_10MBPS 0x0000
uint16 Val = 0;
uint32_t i;
enum{
ETH_SPEED_10MBPS,
ETH_SPEED_100MBPS,
ETH_SPEED_1000MBPS
};
uint16 speed = ETH_SPEED_100MBPS;
Eth_WriteMii(ctrlIdx,phyAddress, 22, 2); //page adres
Eth_ReadMii(ctrlIdx,phyAddress,21, &Val);
Val |= RGMII_TXRX_CLK_DELAY;
Eth_WriteMii(ctrlIdx,phyAddress, 21, Val);
Eth_WriteMii(ctrlIdx,phyAddress, 22, 0 );// page adrs
Eth_ReadMii(ctrlIdx,phyAddress, AUTONEG_ADVERTISE_REGISTER, &Val);
Val |= RGMII_TXRX_CLK_DELAY;/* ASYMMETRIC_PAUSE ?? */
Val |= PAUSE;
Eth_WriteMii(ctrlIdx,phyAddress, AUTONEG_ADVERTISE_REGISTER, Val);
Eth_ReadMii(ctrlIdx, phyAddress, BMCR_REGISTER, &Val);
Val &= ~LINKSPEED_1000MBPS;
Val &= ~LINKSPEED_100MBPS;
Val &= ~LINKSPEED_10MBPS;
if(speed == ETH_SPEED_100MBPS) {
Val |= LINKSPEED_100MBPS;
}
else if (speed == ETH_SPEED_1000MBPS) {
Val |= LINKSPEED_1000MBPS;
}
else {
Val |= LINKSPEED_10MBPS;
}
Eth_WriteMii( ctrlIdx,phyAddress, 9, 0); /* Dont advertise PHY speed of 1000 Mbps */
Eth_WriteMii(ctrlIdx,phyAddress, AUTONEG_ADVERTISE_REGISTER, 0x0100 |0x0080); // don't advertise 100mbps full duplex and 100mbps half resp
Eth_WriteMii(ctrlIdx,phyAddress,BMCR_REGISTER, Val | 0x8000); // reset mask added
for ( i=0; i < 100000; i++);
#endif
#if 0 /* Speed is set statically and configured */
Eth_Hw_SetSpeed(speed);
#endif
linkStatus = LINK_UP;
LwIpAdp_LinkStateUpdate(LINK_UP);
ethTrcvInitRun = TRUE;
return E_OK;
}
|
2301_81045437/classic-platform
|
communication/lwip-2.0.3/contrib/ports/ArcticCore/asrIf/ethernetif.c
|
C
|
unknown
| 23,745
|
/*-------------------------------- Arctic Core ------------------------------
* Copyright (C) 2013, ArcCore AB, Sweden, www.arccore.com.
* Contact: <contact@arccore.com>
*
* You may ONLY use this file:
* 1)if you have a valid commercial ArcCore license and then in accordance with
* the terms contained in the written license agreement between you and ArcCore,
* or alternatively
* 2)if you follow the terms found in GNU General Public License version 2 as
* published by the Free Software Foundation and appearing in the file
* LICENSE.GPL included in the packaging of this file or here
* <http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt>
*-------------------------------- Arctic Core -----------------------------*/
#ifndef __ETHERNETIF_H__
#define __ETHERNETIF_H__
#include "lwip/err.h"
#include "lwip/netif.h"
err_t ethernetif_init(struct netif *netif);
void ethernetif_pre_tcpip_init(void);
void Ethernetif_RxFunc(void);
void Eth_TransHw_linkUp(uint8 ctrlIdx);
#endif
|
2301_81045437/classic-platform
|
communication/lwip-2.0.3/contrib/ports/ArcticCore/asrIf/ethernetif.h
|
C
|
unknown
| 1,027
|
#ifndef ETH_LWIPOPTS_H_
#define ETH_LWIPOPTS_H_
#include "stddef.h"
#define LWIP_AR_MAJOR_VERSION 1
#define LWIP_AR_MINOR_VERSION 0
#define LWIP_AR_PATCH_VERSION 0
#define LWIP_SW_MAJOR_VERSION 1
#define LWIP_SW_MINOR_VERSION 0
#define LWIP_SW_PATCH_VERSION 0
/* New important lwip1.4.1 defines */
#define LWIP_TCPIP_CORE_LOCKING 1
#define LWIP_COMPAT_MUTEX_ALLOWED 1
#define LWIP_CHECKSUM_ON_COPY 1
#define TCPIP_MBOX_SIZE 50
#define MEMP_NUM_NETBUF 20
#define MEMP_NUM_TCPIP_MSG_INPKT 20
/* We want to be notified when the link changes status. */
#define LWIP_NETIF_STATUS_CALLBACK 1
/* Support IPV6(mandatory for doip) */
#define LWIP_IPV6 0
void * __memcpy(void * dst, void const * src,size_t len);
#include "LwIp_Cfg.h"
#endif
|
2301_81045437/classic-platform
|
communication/lwip-2.0.3/contrib/ports/ArcticCore/asrIf/lwipopts.h
|
C
|
unknown
| 806
|
/*-------------------------------- Arctic Core ------------------------------
* Copyright (C) 2013, ArcCore AB, Sweden, www.arccore.com.
* Contact: <contact@arccore.com>
*
* You may ONLY use this file:
* 1)if you have a valid commercial ArcCore license and then in accordance with
* the terms contained in the written license agreement between you and ArcCore,
* or alternatively
* 2)if you follow the terms found in GNU General Public License version 2 as
* published by the Free Software Foundation and appearing in the file
* LICENSE.GPL included in the packaging of this file or here
* <http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt>
*-------------------------------- Arctic Core -----------------------------*/
#include "lwipopts.h"
#include "Std_types.h"
void * __memcpy(void * dst, void const * src, size_t len)
{
uint8 * pDst = (uint8 *) dst;
uint8 const * pSrc = (uint8 const *) src;
while (len--)
{
*pDst++ = *pSrc++;
}
return (dst);
}
|
2301_81045437/classic-platform
|
communication/lwip-2.0.3/contrib/ports/ArcticCore/asrIf/memhdl.c
|
C
|
unknown
| 1,030
|
/*
* Copyright (c) 2001-2003 Swedish Institute of Computer Science.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
* 3. The name of the author may not be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
* SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
* IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
* OF SUCH DAMAGE.
*
* This file is part of the lwIP TCP/IP stack.
*
* Author: Adam Dunkels <adam@sics.se>
*
*/
#ifndef __CC_H__
#define __CC_H__
#include "Std_Types.h"
#include <stdio.h>
#include <assert.h>
#define BYTE_ORDER BIG_ENDIAN
//typedef uint8 u8_t;
//typedef sint8 s8_t;
//typedef uint16 u16_t;
//typedef sint16 s16_t;
//typedef uint32 u32_t;
//typedef sint32 s32_t;
//typedef u32_t mem_ptr_t;
typedef u32_t sys_prot_t;
#define PACK_STRUCT_BEGIN
#define PACK_STRUCT_STRUCT __attribute__ ((__packed__))
#define PACK_STRUCT_END
#define PACK_STRUCT_FIELD(x) x
#define U16_F "u"
#define S16_F "d"
#define X16_F "x"
#define U32_F "u"
#define S32_F "d"
#define X32_F "x"
#define SZT_F "u"
#define LWIP_PLATFORM_DIAG(x) printf x
#define LWIP_PLATFORM_ASSERT(x) assert(0)
#define LWIP_RAND (u32_t)rand
#endif /* __CC_H__ */
|
2301_81045437/classic-platform
|
communication/lwip-2.0.3/contrib/ports/ArcticCore/mpc5xxx/arch/cc.h
|
C
|
unknown
| 2,423
|
/*
* Copyright (c) 2001-2003 Swedish Institute of Computer Science.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
* 3. The name of the author may not be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
* SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
* IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
* OF SUCH DAMAGE.
*
* This file is part of the lwIP TCP/IP stack.
*
* Author: Adam Dunkels <adam@sics.se>
*
*/
#ifndef __PERF_H__
#define __PERF_H__
#define PERF_START /* null definition */
#define PERF_STOP(x) /* null definition */
#endif /* __PERF_H__ */
|
2301_81045437/classic-platform
|
communication/lwip-2.0.3/contrib/ports/ArcticCore/mpc5xxx/arch/perf.h
|
C
|
unknown
| 1,798
|
/*
* Copyright (c) 2001-2003 Swedish Institute of Computer Science.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
* 3. The name of the author may not be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
* SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
* IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
* OF SUCH DAMAGE.
*
* This file is part of the lwIP TCP/IP stack.
*
* Author: Adam Dunkels <adam@sics.se>
*
*/
#ifndef __SYS_ARCH_H__
#define __SYS_ARCH_H__
#include "Os.h"
#include "Std_Types.h"
#include "mbox.h"
#define LWIP_COMPAT_MUTEX 1
void pre_sys_init(void);
typedef OsSemType * sys_sem_t;
typedef OsMBoxType * sys_mbox_t;
typedef TaskType sys_thread_t;
#define sys_msleep(x) Sleep(x)
#endif /* __SYS_ARCH_H__ */
|
2301_81045437/classic-platform
|
communication/lwip-2.0.3/contrib/ports/ArcticCore/mpc5xxx/arch/sys_arch.h
|
C
|
unknown
| 1,975
|
/**
* @file
* Ethernet Interface Skeleton
*
*/
/*
* Copyright (c) 2001-2004 Swedish Institute of Computer Science.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
* 3. The name of the author may not be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
* SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
* IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
* OF SUCH DAMAGE.
*
* This file is part of the lwIP TCP/IP stack.
*
* Author: Adam Dunkels <adam@sics.se>
*
*/
/*
* This file is a skeleton for developing Ethernet network interface
* drivers for lwIP. Add code to the low_level functions and do a
* search-and-replace for the word "ethernetif" to replace it with
* something that better describes your network interface.
*/
#include "lwip/opt.h"
#include "lwip/def.h"
#include "lwip/pbuf.h"
#include "lwip/sys.h"
#include <lwip/stats.h>
#include <lwip/snmp.h>
#include "netif/etharp.h"
#include "netif/ppp_oe.h"
#include "lwip/err.h"
#include "ethernetif.h"
#include "lwip/ethip6.h"
#include "lwip/tcpip.h"
#include <string.h>
#include "isr.h"
#include "irq_types.h"
#include "mpc55xx.h"
#include "fec_5xxx.h"
#include "LwIpAdp.h"
/* TCP and ARP timeouts */
volatile int tcp_end_time, arp_end_time;
/* Define those to better describe your network interface. */
#define IFNAME0 's'
#define IFNAME1 't'
#define ETH_ERROR ((uint32_t)0)
#define ETH_SUCCESS ((uint32_t)1)
/* Forward declarations. */
static err_t low_level_output(struct netif *netif, struct pbuf *p);
static struct netif *netIfPtr = NULL;
/* Eth Isr routine */
static void Eth_Isr(void)
{
uint32_t res = 0;
uint32 ievent;
/* Check events */
ievent = FEC.EIR.R;
#if 0 /* error handling is not done , disable this piece of code in ISR */
if (ievent & (BABBLINGTRANSMIT | ETHBUS_ERROR | LATECOLLISION |
COLLISIONRETRYLIMIT | TRANSMITFIFOUNDERRUN)) {
/* transmit errors */
error = ievent;
}
if (ievent & HEARTBEAT_ERROR) {
/* Heartbeat error */
error = ievent;
}
if (ievent & GRACEFULSTOPACK) {
/* Graceful stop complete */
error = ievent;
}
#endif
while(fec_is_rx_data_available() && (res == 0))
{
/* move received packet into a new pbuf */
struct pbuf *p = low_level_input();
if(p!=NULL){
if(netIfPtr != NULL){
/* TODO support multiple ip addresses on the same netif? */
tcpip_input(p, netIfPtr);
}
}
else{
res = 1;
}
}
/* Clear events */
FEC.EIR.R = ievent;
#if defined(CFG_MPC5777M)
FEC.RDAR.B.RDAR = 1;
#else
FEC.RDAR.B.R_DES_ACTIVE = 1;
#endif
}
ISR(Eth_Isr_RXF){Eth_Isr();}
ISR(Eth_Isr_TXF){Eth_Isr();}
ISR(Eth_Isr_FEC){Eth_Isr();}
void LwIP_EthernetIfStart(struct netif *netIf)
{
netIfPtr = netIf;
fec_enable_reception();
}
/**
* In this function, the hardware should be initialized.
* Called from ethernetif_init().
*
* @param netif the already initialized lwip network interface structure
* for this ethernetif
*/
static void
low_level_init(struct netif *netif)
{
/* set MAC hardware address length */
netif->hwaddr_len = ETHARP_HWADDR_LEN;
uint8_t MACaddr[6] = ETH_MAC_ADDR;
/* Create isr for ethernet interrupt */
ISR_INSTALL_ISR2( "FecRXInt", Eth_Isr_RXF, FEC_RX, 3, 0 );
ISR_INSTALL_ISR2( "FecTXInt", Eth_Isr_TXF, FEC_TX, 3, 0 );
ISR_INSTALL_ISR2( "FecWorldInt", Eth_Isr_FEC, FEC_WORLD, 3, 0 );
netif->hwaddr[0] = MACaddr[0];
netif->hwaddr[1] = MACaddr[1];
netif->hwaddr[2] = MACaddr[2];
netif->hwaddr[3] = MACaddr[3];
netif->hwaddr[4] = MACaddr[4];
netif->hwaddr[5] = MACaddr[5];
/* maximum transfer unit */
netif->mtu = 1500;
/* device capabilities */
/* don't set NETIF_FLAG_ETHARP if this device is not an ethernet one */
netif->flags = NETIF_FLAG_BROADCAST | NETIF_FLAG_ETHARP | NETIF_FLAG_LINK_UP | NETIF_FLAG_IGMP;
fec_init(MACaddr);
}
void ethernetif_pre_tcpip_init(void){
}
/**
* Should be called at the beginning of the program to set up the
* network interface. It calls the function low_level_init() to do the
* actual setup of the hardware.
*
* This function should be passed as a parameter to netif_add().
*
* @param netif the lwip network interface structure for this ethernetif
* @return ERR_OK if the loopif is initialized
* ERR_MEM if private data couldn't be allocated
* any other err_t on error
*/
err_t
ethernetif_init(struct netif *netif)
{
LWIP_ASSERT("netif != NULL", (netif != NULL));
/*
* Initialize the snmp variables and counters inside the struct netif.
* The last argument should be replaced with your link speed, in units
* of bits per second.
*/
NETIF_INIT_SNMP(netif, snmp_ifType_ethernet_csmacd, 100000000);
netif->name[0] = IFNAME0;
netif->name[1] = IFNAME1;
/* We directly use etharp_output() here to save a function call.
* You can instead declare your own function an call etharp_output()
* from it if you have to do some checks before sending (e.g. if link
* is available...) */
netif->output = etharp_output;
netif->linkoutput = low_level_output;
#if LWIP_IPV6
netif->output_ip6 = ethip6_output;
#endif /* LWIP_IPV6 */
/* initialize the hardware */
low_level_init(netif);
LwIP_EthernetIfStart(netif);
return ERR_OK;
}
/**
* This function should do the actual transmission of the packet. The packet is
* contained in the pbuf that is passed to the function. This pbuf
* might be chained.
*
* @param netif the lwip network interface structure for this ethernetif
* @param p the MAC packet to send (e.g. IP packet including MAC addresses and type)
* @return ERR_OK if the packet could be sent
* an err_t value if the packet couldn't be sent
*
* @note Returning ERR_MEM here if a DMA queue of your MAC is full can lead to
* strange results. You might consider waiting for space in the DMA queue
* to become availale since the stack doesn't retry to send a packet
* dropped because of memory failure (except for the TCP timers).
*/
static err_t
low_level_output(struct netif *netif, struct pbuf *p)
{
uint32_t cnt = 0;
struct pbuf *q;
int l = 0;
uint8_t *buffer;
do{
buffer = fec_get_buffer_to_send();
/* TXBD_READY bit set. Loop here and wait since frames will not be resend */
cnt++;
if(cnt > 1000000)
{
/* timeout, notify error and return */
LWIP_DEBUGF(NETIF_DEBUG, ("fec_send: TXBD_READY set\n"));
return ERR_MEM;
}
}while(buffer == NULL);
#if ETH_PAD_SIZE
pbuf_header(p, -ETH_PAD_SIZE); /* drop the padding word */
#endif
for(q = p; q != NULL; q = q->next)
{
memcpy((uint8_t*)&buffer[l], q->payload, q->len);
l = l + q->len;
}
/* Try to send */
while(fec_send(buffer, l) != 0)
{
/* TXBD_READY bit set. Loop here and wait since frames will not be resend */
cnt++;
if(cnt > 1000000)
{
/* timeout, notify error and return */
LWIP_DEBUGF(NETIF_DEBUG, ("fec_send: TXBD_READY set\n"));
return ERR_MEM;
}
}
#if ETH_PAD_SIZE
pbuf_header(p, ETH_PAD_SIZE); /* reclaim the padding word */
#endif
/* Return SUCCESS */
return ERR_OK;
}
void EthIf_GetPhysAddr( uint8 CtrlIdx, uint8* PhysAddrPtr ){
uint8 macAddr[6] = ETH_MAC_ADDR;
PhysAddrPtr[0] = macAddr[0];
PhysAddrPtr[1] = macAddr[1];
PhysAddrPtr[2] = macAddr[2];
PhysAddrPtr[3] = macAddr[3];
PhysAddrPtr[4] = macAddr[4];
PhysAddrPtr[5] = macAddr[5];
}
Std_ReturnType EthIf_UpdatePhysAddrFilter( uint8 CtrlIdx, const uint8* PhysAddrPtr, Eth_FilterActionType Action ){
return E_NOT_OK;
}
|
2301_81045437/classic-platform
|
communication/lwip-2.0.3/contrib/ports/ArcticCore/mpc5xxx/ethernetif.c
|
C
|
unknown
| 9,405
|
/*-------------------------------- Arctic Core ------------------------------
* Copyright (C) 2013, ArcCore AB, Sweden, www.arccore.com.
* Contact: <contact@arccore.com>
*
* You may ONLY use this file:
* 1)if you have a valid commercial ArcCore license and then in accordance with
* the terms contained in the written license agreement between you and ArcCore,
* or alternatively
* 2)if you follow the terms found in GNU General Public License version 2 as
* published by the Free Software Foundation and appearing in the file
* LICENSE.GPL included in the packaging of this file or here
* <http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt>
*-------------------------------- Arctic Core -----------------------------*/
#ifndef __ETHERNETIF_H__
#define __ETHERNETIF_H__
#include "lwip/err.h"
#include "lwip/netif.h"
err_t ethernetif_init(struct netif *netif);
void ethernetif_pre_tcpip_init(void);
struct pbuf * low_level_input();
/* ASR EthIf mockers */
#include "Eth_GeneralTypes.h"
/* EthIf controller IDs */
#define EthIfConf_EthIfController_EthIfController 0u
void EthIf_GetPhysAddr( uint8 CtrlIdx, uint8* PhysAddrPtr );
Std_ReturnType EthIf_UpdatePhysAddrFilter( uint8 CtrlIdx, const uint8* PhysAddrPtr, Eth_FilterActionType Action );
#endif
|
2301_81045437/classic-platform
|
communication/lwip-2.0.3/contrib/ports/ArcticCore/mpc5xxx/ethernetif.h
|
C
|
unknown
| 1,306
|
/*-------------------------------- Arctic Core ------------------------------
* Copyright (C) 2013, ArcCore AB, Sweden, www.arccore.com.
* Contact: <contact@arccore.com>
*
* You may ONLY use this file:
* 1)if you have a valid commercial ArcCore license and then in accordance with
* the terms contained in the written license agreement between you and ArcCore,
* or alternatively
* 2)if you follow the terms found in GNU General Public License version 2 as
* published by the Free Software Foundation and appearing in the file
* LICENSE.GPL included in the packaging of this file or here
* <http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt>
*-------------------------------- Arctic Core -----------------------------*/
#include "mpc55xx.h"
#include "fec_5xxx.h"
#include "Mcu.h"
#include "lwip/pbuf.h"
#include "string.h"
#include "LwIpAdp.h"
#include "SchM_Eth.h"
/* Buf desc status macros */
#define BD_WRAP 0x2000
#define BD_INT 0x1000
#define BD_LAST 0x0800
#define RXBD_EMPTY 0x8000
#define RXBD_MISS 0x0100
#define RXBD_BCAST 0x0080
#define RXBD_MCAST 0x0040
#define RXBD_LG 0x0020
#define RXBD_NO 0x0010
#define RXBD_SH 0x0008
#define RXBD_CR 0x0004
#define RXBD_OV 0x0002
#define RXBD_TR 0x0001
#define RXBD_ERR (RXBD_LG | RXBD_NO | RXBD_CR | RXBD_OV | RXBD_TR)
#define TXBD_READY 0x8000
#define TXBD_CRC 0x0400
/* MII macros */
#define FEC_MII_DATA_ST 0x40000000
#define FEC_MII_DATA_OP_RD 0x20000000
#define FEC_MII_DATA_OP_WR 0x10000000
#define FEC_MII_DATA_PA_MSK 0x0f800000
#define FEC_MII_DATA_RA_MSK 0x007c0000
#define FEC_MII_DATA_TA 0x00020000
#define FEC_MII_DATA_DATAMSK 0x0000ffff
#define FEC_MII_DATA_RA_SHIFT 18
#define FEC_MII_DATA_PA_SHIFT 23
#define ETH_MAX_PACKET_SIZE 1518
#define ETH_DESC_BUFFER_SIZE 1536
/* Adjusted for maximum download speed, possible to save RAM memory but at the cost of performance
* Should be adjusted together with TCP_WND and TCP_SND_BUF.
* At least FEC_NOF_TX_BUF >= (TCP_SND_BUF+1*1496)/1496 and FEC_NOF_RX_BUF >= (TCP_WND+1*1496)/1496.
*
* Going below 6 rx buffer will have significant impact on performance and going above 6 buffer only
* marginally increases performance.
*/
#define FEC_NOF_TX_BUF 3
#define FEC_NOF_RX_BUF 6
static uint32 outOfMemoryCounter = 0u;
static uint8 phyAddress = 0u;
LinkState linkState = LINK_DOWN;
typedef struct Desc
{
volatile uint16 status;
volatile uint16 length;
volatile uint8 *pBuf;
} Desc_t;
/* Buffer descriptor rings must start
on a 32-bit boundary; however, it is recommended they are made 128-bit aligned. */
static Desc_t RxBD[FEC_NOF_RX_BUF] __attribute__ ((aligned (16)));// __attribute__ ((section (".no_cache")));
static Desc_t TxBD[FEC_NOF_TX_BUF] __attribute__ ((aligned (16)));// __attribute__ ((section (".no_cache")));
/* Buffers , let us set them aligned to just to be sure */
static uint8 RxBuf[FEC_NOF_RX_BUF][ETH_DESC_BUFFER_SIZE] __attribute__ ((aligned (16)));
static uint8 TxBuf[FEC_NOF_TX_BUF][ETH_DESC_BUFFER_SIZE] __attribute__ ((aligned (16)));
static volatile Desc_t *pRxBD = RxBD;
static volatile Desc_t *pTxBD = TxBD;
/**
* MII Management frame read operation
* @param phyAddr
* @param regAddr
* @param retVal
* @return OK(0) or NOK(-1)
*/
sint8 fec_mii_read(uint8 phyAddr, uint8 regAddr, uint16 * retVal)
{
uint32 reg;
uint32 phy;
volatile uint16 timeout = 0xffff;
reg = (uint32)regAddr << 18u;
phy = (uint32)phyAddr << 23u;
#if defined(CFG_MPC5777M)
FEC.MMFR.R = (FEC_MII_DATA_ST | FEC_MII_DATA_OP_RD | FEC_MII_DATA_TA | phy | reg);
#else
FEC.MDATA.R = (FEC_MII_DATA_ST | FEC_MII_DATA_OP_RD | FEC_MII_DATA_TA | phy | reg);
#endif
/* wait for int */
while ((timeout--) && (!(FEC.EIR.R & 0x00800000))) ;
if (timeout == 0) {
return -1;
}
/* clear interrupt */
FEC.EIR.R = 0x00800000;
/* read data */
#if defined(CFG_MPC5777M)
*retVal = (uint16) FEC.MMFR.R;
#else
*retVal = (uint16) FEC.MDATA.R;
#endif
return 0;
}
/**
* MII Management frame write operation
* @param phyAddr
* @param regAddr
* @param data
* @return OK(0) or NOK(-1)
*/
sint8 fec_mii_write(uint8 phyAddr, uint8 regAddr, uint32 data)
{
uint32 reg;
uint32 phy;
volatile uint16 timeout = 0xffff;
reg = (uint32)regAddr << 18u;
phy = (uint32)phyAddr << 23u;
#if defined(CFG_MPC5777M)
FEC.MMFR.R = (FEC_MII_DATA_ST | FEC_MII_DATA_OP_WR | FEC_MII_DATA_TA | phy | reg | data);
#else
FEC.MDATA.R = (FEC_MII_DATA_ST | FEC_MII_DATA_OP_WR | FEC_MII_DATA_TA | phy | reg | data);
#endif
/* wait for int */
while ((timeout--) && (!(FEC.EIR.R & 0x00800000))) ;
if (timeout == 0) {
return -1;
}
/* clear int */
FEC.EIR.R = 0x00800000;
return 0;
}
/**
* Fetch PHY address
* @param startPhyAddr
* @param endPhyAddr
* @return phyAddr
*/
uint8 fec_find_phy(uint8 startPhyAddr, uint8 endPhyAddr)
{
uint16 regValue = 0xffff;
uint8 phyAddr=startPhyAddr;
while( ( regValue == 0xffff ) || ( regValue == 0 ) )
{
(void)fec_mii_read(phyAddr, 0x0, ®Value);
if(( regValue == 0xffff ) || ( regValue == 0 )){
phyAddr++;
if(phyAddr > endPhyAddr){
phyAddr = 0xff;
regValue = 1;
}
}
}
return phyAddr;
}
/**
* Link Setting up - Needed to be called from a cyclic task
* precondition - phyAddress is valid and ofcourse FEC enabled
* @param
* @return
*/
void fec_linkUp(void)
{
/* IMPROVE - Link down can happen any time, not getting checked anywhere - needed to be checked */
if(phyAddress != 0){
uint16 regValue;
uint16 statusValue = 0;
if(linkState == LINK_DOWN)
{
/* Set auto neg advert register */
(void)fec_mii_write(phyAddress, 0x4, 0x01e1);
// Enable and start auto-negotiation
fec_mii_read(phyAddress,0x0000, ®Value);
fec_mii_write(phyAddress,0x0000, (regValue | 0x1200)/*&0xDFFF)*/);
linkState = AUTONEGOTIATE_RESTART;
}
// Wait for Auto-Neg complete flag
fec_mii_read(phyAddress,0x0001, &statusValue);
if((statusValue & 0x0020 )== 0x0020){
linkState = AUTONEGOTIATE_COMPLETE;
}
if((statusValue & 0x0004 )== 0x0004){
linkState = LINK_UP;
}
LwIpAdp_LinkStateUpdate(linkState);
}
}
#if 0
/**
* Initialize PHY, use when this method when polling mechanism is used that is to call
* fec_linkUp() during the start up (or)
* just call fec_linkUp() from the task even without calling this function
* @param phyAddr
* @return OK(0)
*/
sint8 fec_init_phy(void)
{
// Reset phy - SW Reset
(void)fec_mii_write(phyAddress, 0x0, 0x8000);
// wait for SW reset bit cleared
for(volatile uint16 i=0; i < 1000; i++){};
fec_linkUp();
return 0;
}
#endif
/**
* Initialise PHY, this function would be called in the beginning of the start up
* so take care to connect the network medium from the start up
* else use polling method - fec_linkUp (however linkdown is not handled currently )
* @param phyAddr
* @return OK(0)
*/
sint8 fec_init_phy(void)
{
uint16 timeout;
uint16 phyStatus;
uint16 regValue;
// Reset phy
(void)fec_mii_write(phyAddress, 0x0, 0x8000);
for(volatile uint16 i=0; i < 1000; i++){};
/* Set auto neg advert register */
(void)fec_mii_write(phyAddress, 0x4, 0x01e1);
/* enable auto-negotiation */
(void)fec_mii_read(phyAddress, 0x0, ®Value);
(void)fec_mii_write(phyAddress, 0x0, (regValue | 0x1200));
/* Wait for completion */
timeout = 10000;
do {
for(volatile uint16 i=0; i < 1000; i++){
}
if ((timeout--) == 0) {
return -1;
}
if (fec_mii_read(phyAddress, 0x1, &phyStatus) != 0) {
return -1;
}
if(phyStatus == 0xffff){
return -1;
}
} while (!(phyStatus & 0x0020)); // Should be 0x786D
return 0;
}
/**
* Set the MAC address for the address recognition
* @param macAddr
* @return
*/
void fec_set_macaddr(const uint8 *macAddr)
{
uint8 currByte;
uint32 crc = 0xffffffffu;
/* Calc crc */
for (uint8 byte = 0; byte < 6; byte++) {
currByte = macAddr[byte];
for (uint8 bit = 0; bit < 8; bit++) {
if ((currByte & 0x01) ^ (crc & 0x01)) {
crc >>= 1;
crc = crc ^ 0xedb88320u;
} else {
crc >>= 1;
}
currByte >>= 1;
}
}
crc = crc >> 26;
/* Set hash */
if (crc >= 32) {
FEC.IAUR.B.IADDR1 = (1u << (crc - 32));
FEC.IALR.B.IADDR2 = 0;
} else {
FEC.IAUR.B.IADDR1 = 0;
FEC.IALR.B.IADDR2 = (1u << crc);
}
/* Set phy addr */
FEC.PALR.B.PADDR1 = (macAddr[0] << 24) + (macAddr[1] << 16) + (macAddr[2] << 8) + macAddr[3];
FEC.PAUR.B.PADDR2 = (macAddr[4] << 24) + (macAddr[5] << 16) + 0x8808;
}
/**
* Initialize FEC module and bring it up
* @param macAddr
* @return OK(0)
*/
sint8 fec_init(const uint8 *macAddr)
{
FEC.ECR.B.RESET = 1;
FEC.ECR.B.ETHER_EN = 0;
#ifdef CFG_BRD_MPC5567FLEXECU2
#define PIN_FP_PROG 187
#define PIN_FPGA_DP_PD_B 137
#define PIN_FPGA_DP_PD_A 138
#define PIN_FPGA_SEL_SRC 203
#define PIN_FPGA_SW_RST 204
#define PIN_FPGA_DP_RST 205
SIU.PCR[PIN_FP_PROG].R = 0x0303;
SIU.PCR[PIN_FPGA_DP_PD_B].R = 0x0303;
SIU.PCR[PIN_FPGA_DP_PD_A].R = 0x0303;
SIU.PCR[PIN_FPGA_SEL_SRC].R = 0x0303;
SIU.PCR[PIN_FPGA_SW_RST].R = 0x0303;
SIU.PCR[PIN_FPGA_DP_RST].R = 0x0303;
SIU.GPDO[PIN_FP_PROG].R = 0;
SIU.GPDO[PIN_FPGA_SEL_SRC].R = 0;
SIU.GPDO[PIN_FPGA_SW_RST].R = 0;
SIU.GPDO[PIN_FPGA_DP_RST].R = 0;
SIU.GPDO[PIN_FPGA_DP_PD_A].R = 0;
SIU.GPDO[PIN_FPGA_DP_PD_B].R = 0;
SIU.GPDO[PIN_FP_PROG].R = 1;
#endif
/* Wait for reset to complete */
while (FEC.ECR.B.RESET) { } ;
#ifdef CFG_BRD_MPC5567FLEXECU2
SIU.GPDO[PIN_FPGA_SW_RST].R = 1;
SIU.GPDO[PIN_FPGA_DP_RST].R = 1;
#endif
#if defined(CFG_MPC5777M)
SIUL2.SCR0.B.FEC_MODE = 1;/* 0 - RMII is the default state ,1 - MII is selected*/
#endif
/* Interrupt Mask Register */
FEC.EIMR.R = 0;
/* Interrupt Event Register */
FEC.EIR.R = 0xFFFFFFFFu; /* Clear event register */
/* FIFO Transmit FIFO Watermark Register */
#if defined(CFG_MPC5777M)
FEC.TFWR.B.TFWR = 0x0;/* default 0=64bytes, 0x2=128bytes 0x3=192bytes */
#else
FEC.TFWR.B.X_WMRK = 0x0; /* default 0=64bytes, 0x2=128bytes 0x3=192bytes */
#endif
/* Set multicast address filter */
FEC.GALR.R = 0;
FEC.GAUR.R = 0;
FEC.OPD.B.PAUSE_DUR = 0x1;
/* Receive Control Register */
FEC.RCR.B.FCE = 0;
FEC.RCR.B.BC_REJ = 0;
FEC.RCR.B.PROM = 0;//Promiscuous mode disabled. Promiscuous mode -All frames are accepted regardless of address matching.
FEC.RCR.B.MII_MODE = 1;
#if defined(CFG_MPC5744P)
FEC.RCR.B.RMII_MODE = 1;
#endif
FEC.RCR.B.DRT = 0;
FEC.RCR.B.LOOP = 0;
FEC.RCR.B.MAX_FL = ETH_MAX_PACKET_SIZE;
#if defined(CFG_MPC5567)
#if (LWIP_IPV6==1)
FEC.RCR.R = 0x05EE000c; // ipv6 need promiscous,MII mode
#else
FEC.RCR.R = 0x05EE0004; // NOTE Compiler or debugger error? above don't work according to debugger
#endif
#endif
/* Transmit Control Register */
FEC.TCR.B.TFC_PAUSE = 0;
FEC.TCR.B.FDEN = 1;
FEC.TCR.B.HBC = 0;
FEC.TCR.B.GTS = 0;
#if defined(CFG_MPC5777M)
FEC.MSCR.B.DIS_PRE = 0;
#else
FEC.MSCR.B.DIS_PREAMBLE = 0;
#endif
#if defined(CFG_MPC5744P) || defined(CFG_MPC5777M)
uint32 clock = Mcu_Arc_GetPeripheralClock(PERIPHERAL_CLOCK_FEC_0);
#else
uint32 clock = Mcu_Arc_GetSystemClock();
#endif
/* MII Speed Control Register */
#if defined(CFG_MPC5777M)
FEC.MSCR.B.MII_SPEED = (clock / (5*1000000)); /* 1/(MII_SPEED x 2) of internal bus frequency = 2.5 MHz,value 16 -> 40 MHz * 1/(16*2) = 2.5 MHz */
#else
FEC.MSCR.B.MII_SPEED = (clock / (10*1000000)); /* If system clock 80 MHz, value 8 -> 80 MHz * 1/(4*8) = 2.5 MHz */
#endif
/* Receive Buffer Size Register */
FEC.EMRBR.R = ETH_DESC_BUFFER_SIZE;
/* Initialize descriptors */
for(uint8 i = 0; i < FEC_NOF_RX_BUF; i++)
{
if(i == (FEC_NOF_RX_BUF - 1)){
RxBD[i].status = RXBD_EMPTY | BD_WRAP; /* wrap */
}else{
RxBD[i].status = RXBD_EMPTY;
}
RxBD[i].length = 0;
RxBD[i].pBuf = RxBuf[i];
}
for(uint8 i = 0; i < FEC_NOF_TX_BUF; i++)
{
if(i == (FEC_NOF_TX_BUF - 1)){
TxBD[i].status = BD_WRAP; /* wrap */
}else{
TxBD[i].status = 0;
}
TxBD[i].length = 0;
TxBD[i].pBuf = TxBuf[i];
}
/* Set desciptor start addresses */
FEC.ERDSR.R = (uint32)&RxBD[0];
FEC.ETDSR.R = (uint32)&TxBD[0];
/* Set MAC address */
fec_set_macaddr(macAddr);
/* find phy */
#if defined(CFG_BRD_MPC5567FLEXECU2) || defined(CFG_MPC5777M)
phyAddress = 1u;
#else
phyAddress = fec_find_phy(0,31);/*loop to find the phy */
#endif
if(phyAddress != 0xff){
fec_init_phy();
}
/* Enable FEC */
/* Link can be established any time */
FEC.ECR.B.ETHER_EN = 1;
/* Enable events in maskreg */
/* NOTE: Add handling for all different errors before enabling here */
FEC.EIMR.R = HEARTBEAT_ERROR |
BABBLINGRECEIVER |
BABBLINGTRANSMIT |
GRACEFULSTOPACK |
/* TRANSMITFRAMEINT |
* TRANSMITBUFINT | */
RECEIVEFRAMEINT |
/* RECEIVEBUFINT |
* MIIIINT | */
ETHBUS_ERROR |
LATECOLLISION |
COLLISIONRETRYLIMIT |
TRANSMITFIFOUNDERRUN;
return 0;
}
/**
* Enable reception
* @param
* @return
*/
void fec_enable_reception()
{
/* Enable reception */
#if defined(CFG_MPC5777M)
FEC.RDAR.B.RDAR = 1;
#else
FEC.RDAR.B.R_DES_ACTIVE = 1;
#endif
}
/**
* Get the transmit buffer descriptor
* @param
* @return buf
*/
uint8 * fec_get_buffer_to_send()
{
uint8 *buf = NULL;
/* Note:
avoid reentrancy in general in handling the descriptor until TXBD_READY will be set in fec_send() */
if((pTxBD->status & TXBD_READY) == 0){
buf = (uint8 *)pTxBD->pBuf;
}
return buf;
}
/**
* Stop FEC module
* @param
* @return
*/
void fec_stop(void)
{
FEC.ECR.B.ETHER_EN = 0;
}
/**
* Send frame
* @param buf
* @param len
* @return OK(1) or NOK(0)
*/
sint8 fec_send(uint8 *buf, uint16 len)
{
sint8 ret = 0;
SchM_Enter_Eth_EA_0();
if((pTxBD->status & TXBD_READY) == 0){
/* Update buffer descriptor. */
pTxBD->length = len;
/* if caches flush them here... */
pTxBD->pBuf = buf;
/* Last descriptor, Wrap */
if((pTxBD->status & BD_WRAP) == BD_WRAP)
{
pTxBD->status = TXBD_CRC | TXBD_READY | BD_LAST | BD_WRAP;
pTxBD = &TxBD[0];
}
else
{
pTxBD->status = TXBD_CRC | TXBD_READY | BD_LAST;
pTxBD++;
}
/* Send immediately */
#if defined(CFG_MPC5777M)
FEC.TDAR.B.TDAR = 1;
#else
FEC.TDAR.B.X_DES_ACTIVE = 1;
#endif
}
else
{
ret = 1;
}
SchM_Exit_Eth_EA_0();
return ret;
}
/**
* Check if data has been received
* @param
* @return boolean
*/
boolean fec_is_rx_data_available(void)
{
return ((pRxBD->status & RXBD_EMPTY) == 0);
}
/**
* Should allocate a pbuf and transfer the bytes of the incoming
* packet from the interface into the pbuf.
*
* @return a pbuf filled with the received packet (including MAC header)
* NULL on memory error
*/
struct pbuf *
low_level_input(void)
{
struct pbuf *p = NULL;
if((pRxBD->status & RXBD_EMPTY) == 0)
{
uint16 len;
/* Obtain the size of the packet and put it into the "len"
variable. */
len = pRxBD->length;
#if ETH_PAD_SIZE
len += ETH_PAD_SIZE; /* allow room for Ethernet padding */
#endif
/* We allocate a pbuf chain of pbufs from the pool. */
p = pbuf_alloc(PBUF_RAW, len, PBUF_POOL);
if (p != NULL){
#if ETH_PAD_SIZE
pbuf_header(p, -ETH_PAD_SIZE); /* drop the padding word */
#endif
memcpy((uint8_t*)p->payload, (uint8_t*)pRxBD->pBuf, pRxBD->length);
}else{
/* Out of memory, Nothing to do but to through away data */
outOfMemoryCounter++;
}
/* Update descriptor for new reception */
if(pRxBD->status & BD_WRAP){ /* Last descriptor, Wrap */
pRxBD->length = 0;
pRxBD->status = RXBD_EMPTY | BD_WRAP;
pRxBD = &RxBD[0];
}
else{
pRxBD->length = 0;
pRxBD->status = RXBD_EMPTY;
pRxBD++;
}
}
return p;
}
|
2301_81045437/classic-platform
|
communication/lwip-2.0.3/contrib/ports/ArcticCore/mpc5xxx/fec_5xxx.c
|
C
|
unknown
| 17,673
|