diff --git a/android-headers.pc.in b/android-headers.pc.in
index 52cdc5d..9986ae3 100644
--- a/android-headers.pc.in
+++ b/android-headers.pc.in
@@ -1,4 +1,4 @@
Name: android-headers
Description: Provides the headers for the droid system
-Version: 11.0.0
+Version: 13.0.0
Cflags: -I@includedir@
diff --git a/android-version.h b/android-version.h
index 9c6b6fb..7eda3f2 100644
--- a/android-version.h
+++ b/android-version.h
@@ -1,7 +1,7 @@
#ifndef ANDROID_VERSION_H_
#define ANDROID_VERSION_H_
-#define ANDROID_VERSION_MAJOR 11
+#define ANDROID_VERSION_MAJOR 13
#define ANDROID_VERSION_MINOR 0
#define ANDROID_VERSION_PATCH 0
#define ANDROID_VERSION_PATCH2 0
diff --git a/android/api-level.h b/android/api-level.h
index 1b8af78..ecf318d 100644
--- a/android/api-level.h
+++ b/android/api-level.h
@@ -28,6 +28,13 @@
#pragma once
+/**
+ * @defgroup apilevels API Levels
+ *
+ * Defines functions and constants for working with Android API levels.
+ * @{
+ */
+
/**
* @file android/api-level.h
* @brief Functions and constants for dealing with multiple API levels.
@@ -50,9 +57,40 @@ __BEGIN_DECLS
/* This #ifndef should never be true except when doxygen is generating docs. */
#ifndef __ANDROID_API__
/**
- * `__ANDROID_API__` is the API level being targeted. For the OS,
- * this is `__ANDROID_API_FUTURE__`. For the NDK, this is set by the
- * compiler system based on the API level you claimed to target. See
+ * `__ANDROID_API__` is the [API
+ * level](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)
+ * this code is being built for. The resulting binaries are only guaranteed to
+ * be compatible with devices which have an API level greater than or equal to
+ * `__ANDROID_API__`.
+ *
+ * For NDK and APEX builds, this macro will always be defined. It is set
+ * automatically by Clang using the version suffix that is a part of the target
+ * name. For example, `__ANDROID_API__` will be 24 when Clang is given the
+ * argument `-target aarch64-linux-android24`.
+ *
+ * For non-APEX OS code, this defaults to __ANDROID_API_FUTURE__.
+ *
+ * The value of `__ANDROID_API__` can be compared to the named constants in
+ * ` Native windows that get removed must not be part of any active repeating or single/burst
* request or have any pending results. Consider updating repeating requests via
- * {@link ACaptureSessionOutput_setRepeatingRequest} and then wait for the last frame number
+ * {@link ACameraCaptureSession_setRepeatingRequest} and then wait for the last frame number
* when the sequence completes
- * {@link ACameraCaptureSession_captureCallback#onCaptureSequenceCompleted}.
Native windows that get added must not be part of any other registered ACaptureSessionOutput * and must be compatible. Compatible windows must have matching format, rotation and @@ -641,9 +650,7 @@ typedef struct ACaptureSessionOutput ACaptureSessionOutput; */ camera_status_t ACameraCaptureSession_updateSharedOutput(ACameraCaptureSession* session, ACaptureSessionOutput* output) __INTRODUCED_IN(28); -#endif /* __ANDROID_API__ >= 28 */ -#if __ANDROID_API__ >= 29 /** * The definition of final capture result callback with logical multi-camera support. * @@ -721,7 +728,15 @@ typedef struct ACameraCaptureSession_logicalCamera_captureCallbacks { * Same as ACameraCaptureSession_captureCallbacks */ void* context; + + /** + * Same as {@link ACameraCaptureSession_captureCallbacks#onCaptureStarted}. + */ ACameraCaptureSession_captureCallback_start onCaptureStarted; + + /** + * Same as {@link ACameraCaptureSession_captureCallbacks#onCaptureProgressed}. + */ ACameraCaptureSession_captureCallback_result onCaptureProgressed; /** @@ -759,10 +774,18 @@ typedef struct ACameraCaptureSession_logicalCamera_captureCallbacks { ACameraCaptureSession_logicalCamera_captureCallback_failed onLogicalCameraCaptureFailed; /** - * Same as ACameraCaptureSession_captureCallbacks + * Same as {@link ACameraCaptureSession_captureCallbacks#onCaptureSequenceCompleted}. */ ACameraCaptureSession_captureCallback_sequenceEnd onCaptureSequenceCompleted; + + /** + * Same as {@link ACameraCaptureSession_captureCallbacks#onCaptureSequenceAborted}. + */ ACameraCaptureSession_captureCallback_sequenceAbort onCaptureSequenceAborted; + + /** + * Same as {@link ACameraCaptureSession_captureCallbacks#onCaptureBufferLost}. + */ ACameraCaptureSession_captureCallback_bufferLost onCaptureBufferLost; } ACameraCaptureSession_logicalCamera_captureCallbacks; @@ -788,7 +811,183 @@ camera_status_t ACameraCaptureSession_logicalCamera_setRepeatingRequest( int numRequests, ACaptureRequest** requests, /*optional*/int* captureSequenceId) __INTRODUCED_IN(29); -#endif /* __ANDROID_API__ >= 29 */ +/** + * The definition of camera capture start callback. The same as + * {@link ACameraCaptureSession_captureCallbacks#onCaptureStarted}, except that + * it has the frame number of the capture as well. + * + * @param context The optional application context provided by user in + * {@link ACameraCaptureSession_captureCallbacks}. + * @param session The camera capture session of interest. + * @param request The capture request that is starting. Note that this pointer points to a copy of + * capture request sent by application, so the address is different to what + * application sent but the content will match. This request will be freed by + * framework immediately after this callback returns. + * @param timestamp The timestamp when the capture is started. This timestamp will match + * {@link ACAMERA_SENSOR_TIMESTAMP} of the {@link ACameraMetadata} in + * {@link ACameraCaptureSession_captureCallbacks#onCaptureCompleted} callback. + * @param frameNumber the frame number of the capture started + */ +typedef void (*ACameraCaptureSession_captureCallback_startV2)( + void* context, ACameraCaptureSession* session, + const ACaptureRequest* request, int64_t timestamp, int64_t frameNumber); +/** + * This has the same functionality as ACameraCaptureSession_captureCallbacks, + * with the exception that captureCallback_startV2 callback is + * used, instead of captureCallback_start, to support retrieving the frame number. + */ +typedef struct ACameraCaptureSession_captureCallbacksV2 { + /** + * Same as ACameraCaptureSession_captureCallbacks + */ + void* context; + + /** + * Same as {@link ACameraCaptureSession_captureCallbacks#onCaptureStarted}, + * except that it has the frame number of the capture added in the parameter + * list. + */ + ACameraCaptureSession_captureCallback_startV2 onCaptureStarted; + + /** + * Same as {@link ACameraCaptureSession_captureCallbacks#onCaptureProgressed}. + */ + ACameraCaptureSession_captureCallback_result onCaptureProgressed; + + /** + * Same as {@link ACameraCaptureSession_captureCallbacks#onCaptureCompleted}. + */ + ACameraCaptureSession_captureCallback_result onCaptureCompleted; + + /** + * Same as {@link ACameraCaptureSession_captureCallbacks#onCaptureFailed}. + */ + ACameraCaptureSession_captureCallback_failed onCaptureFailed; + + /** + * Same as {@link ACameraCaptureSession_captureCallbacks#onCaptureSequenceCompleted}. + */ + ACameraCaptureSession_captureCallback_sequenceEnd onCaptureSequenceCompleted; + + /** + * Same as {@link ACameraCaptureSession_captureCallbacks#onCaptureSequenceAborted}. + */ + ACameraCaptureSession_captureCallback_sequenceAbort onCaptureSequenceAborted; + + /** + * Same as {@link ACameraCaptureSession_captureCallbacks#onCaptureBufferLost}. + */ + ACameraCaptureSession_captureCallback_bufferLost onCaptureBufferLost; + + +} ACameraCaptureSession_captureCallbacksV2; + +/** + * This has the same functionality as ACameraCaptureSession_logicalCamera_captureCallbacks, + * with the exception that an captureCallback_startV2 callback is + * used, instead of captureCallback_start, to support retrieving frame number. + */ +typedef struct ACameraCaptureSession_logicalCamera_captureCallbacksV2 { + /** + * Same as ACameraCaptureSession_captureCallbacks + */ + void* context; + + /** + * Same as {@link ACameraCaptureSession_captureCallbacks#onCaptureStarted}, + * except that it has the frame number of the capture added in the parameter + * list. + */ + ACameraCaptureSession_captureCallback_startV2 onCaptureStarted; + + + /** + * Same as {@link ACameraCaptureSession_captureCallbacks#onCaptureProgressed}. + */ + ACameraCaptureSession_captureCallback_result onCaptureProgressed; + + /** + * Same as + * {@link ACameraCaptureSession_logicalCamera_captureCallbacks#onLogicalCaptureCompleted}. + */ + ACameraCaptureSession_logicalCamera_captureCallback_result onLogicalCameraCaptureCompleted; + + /** + * This callback is called instead of {@link onLogicalCameraCaptureCompleted} when the + * camera device failed to produce a capture result for the + * request. + * + *
Other requests are unaffected, and some or all image buffers from + * the capture may have been pushed to their respective output + * streams.
+ * + *Note that the ACaptureRequest pointer in the callback will not match what application has + * submitted, but the contents the ACaptureRequest will match what application submitted.
+ * + * @see ALogicalCameraCaptureFailure + */ + ACameraCaptureSession_logicalCamera_captureCallback_failed onLogicalCameraCaptureFailed; + + /** + * Same as {@link ACameraCaptureSession_captureCallbacks#onCaptureSequenceCompleted}. + */ + ACameraCaptureSession_captureCallback_sequenceEnd onCaptureSequenceCompleted; + + /** + * Same as {@link ACameraCaptureSession_captureCallbacks#onCaptureSequenceAborted}. + */ + ACameraCaptureSession_captureCallback_sequenceAbort onCaptureSequenceAborted; + + /** + * Same as {@link ACameraCaptureSession_captureCallbacks#onCaptureBufferLost}. + */ + ACameraCaptureSession_captureCallback_bufferLost onCaptureBufferLost; + +} ACameraCaptureSession_logicalCamera_captureCallbacksV2; + +/** + * This has the same functionality as ACameraCaptureSession_capture, with added + * support for v2 of camera callbacks, where the onCaptureStarted callback + * adds frame number in its parameter list. + */ +camera_status_t ACameraCaptureSession_captureV2( + ACameraCaptureSession* session, + /*optional*/ACameraCaptureSession_captureCallbacksV2* callbacks, + int numRequests, ACaptureRequest** requests, + /*optional*/int* captureSequenceId) __INTRODUCED_IN(33); + +/** + * This has the same functionality as ACameraCaptureSession_logical_setRepeatingRequest, with added + * support for v2 of logical multi-camera callbacks where the onCaptureStarted + * callback adds frame number in its parameter list. + */ +camera_status_t ACameraCaptureSession_setRepeatingRequestV2( + ACameraCaptureSession* session, + /*optional*/ACameraCaptureSession_captureCallbacksV2* callbacks, + int numRequests, ACaptureRequest** requests, + /*optional*/int* captureSequenceId) __INTRODUCED_IN(33); + +/** + * This has the same functionality as ACameraCaptureSession_logical_capture, with added + * support for v2 of logical multi-camera callbacks where the onCaptureStarted callback + * adds frame number in its parameter list. + */ +camera_status_t ACameraCaptureSession_logicalCamera_captureV2( + ACameraCaptureSession* session, + /*optional*/ACameraCaptureSession_logicalCamera_captureCallbacksV2* callbacks, + int numRequests, ACaptureRequest** requests, + /*optional*/int* captureSequenceId) __INTRODUCED_IN(33); + +/** + * This has the same functionality as ACameraCaptureSession_logical_setRepeatingRequest, with added + * support for v2 of logical multi-camera callbacks where the onCaptureStarted + * callback adds frame number in its parameter list. + */ +camera_status_t ACameraCaptureSession_logicalCamera_setRepeatingRequestV2( + ACameraCaptureSession* session, + /*optional*/ACameraCaptureSession_logicalCamera_captureCallbacksV2* callbacks, + int numRequests, ACaptureRequest** requests, + /*optional*/int* captureSequenceId) __INTRODUCED_IN(33); __END_DECLS diff --git a/camera/NdkCameraDevice.h b/camera/NdkCameraDevice.h index 1537bde..7be4bd3 100644 --- a/camera/NdkCameraDevice.h +++ b/camera/NdkCameraDevice.h @@ -44,8 +44,6 @@ __BEGIN_DECLS -#if __ANDROID_API__ >= 24 - /** * ACameraDevice is opaque type that provides access to a camera device. * @@ -126,6 +124,10 @@ typedef void (*ACameraDevice_StateCallback)(void* context, ACameraDevice* device */ typedef void (*ACameraDevice_ErrorStateCallback)(void* context, ACameraDevice* device, int error); +/** + * Applications' callbacks for camera device state changes, register with + * {@link ACameraManager_openCamera}. + */ typedef struct ACameraDevice_StateCallbacks { /// optional application context. void* context; @@ -200,6 +202,10 @@ camera_status_t ACameraDevice_close(ACameraDevice* device) __INTRODUCED_IN(24); */ const char* ACameraDevice_getId(const ACameraDevice* device) __INTRODUCED_IN(24); +/** + * Capture request pre-defined template types, used in {@link ACameraDevice_createCaptureRequest} + * and {@link ACameraDevice_createCaptureRequest_withPhysicalIds}. + */ typedef enum { /** * Create a request suitable for a camera preview window. Specifically, this @@ -303,10 +309,12 @@ camera_status_t ACameraDevice_createCaptureRequest( const ACameraDevice* device, ACameraDevice_request_template templateId, /*out*/ACaptureRequest** request) __INTRODUCED_IN(24); - +/** + * Opaque object for CaptureSessionOutput container, use + * {@link ACaptureSessionOutputContainer_create} to create an instance. + */ typedef struct ACaptureSessionOutputContainer ACaptureSessionOutputContainer; -typedef struct ACaptureSessionOutput ACaptureSessionOutput; /** * Create a capture session output container. @@ -687,10 +695,6 @@ camera_status_t ACameraDevice_createCaptureSession( const ACameraCaptureSession_stateCallbacks* callbacks, /*out*/ACameraCaptureSession** session) __INTRODUCED_IN(24); -#endif /* __ANDROID_API__ >= 24 */ - -#if __ANDROID_API__ >= 28 - /** * Create a shared ACaptureSessionOutput object. * @@ -782,10 +786,6 @@ camera_status_t ACameraDevice_createCaptureSessionWithSessionParameters( const ACameraCaptureSession_stateCallbacks* callbacks, /*out*/ACameraCaptureSession** session) __INTRODUCED_IN(28); -#endif /* __ANDROID_API__ >= 28 */ - -#if __ANDROID_API__ >= 29 - /** * Create a ACaptureSessionOutput object used for streaming from a physical * camera as part of a logical camera device. @@ -854,7 +854,7 @@ camera_status_t ACameraDevice_createCaptureRequest_withPhysicalIds( /*out*/ACaptureRequest** request) __INTRODUCED_IN(29); /** - * Check whether a particular {@ACaptureSessionOutputContainer} is supported by + * Check whether a particular {@link ACaptureSessionOutputContainer} is supported by * the camera device. * *This method performs a runtime check of a given {@link @@ -885,13 +885,12 @@ camera_status_t ACameraDevice_createCaptureRequest_withPhysicalIds( * device. *
The returned ACameraMetadata must be freed by the application by {@link ACameraMetadata_free} + * after application is done using it.
+ * + *The ACameraMetadata maintains a reference count to the underlying data, so + * it can be used independently of the Java object, and it remains valid even if + * the Java metadata is garbage collected. + * + * @param env the JNI environment. + * @param cameraMetadata the source + android.hardware.camera2.CameraMetadata from which the + * returned {@link ACameraMetadata} is a view. + * + * @return a valid ACameraMetadata pointer or NULL if cameraMetadata is null or not a valid + * instance of + * android.hardware.camera2.CameraMetadata. + * + */ +ACameraMetadata* ACameraMetadata_fromCameraMetadata(JNIEnv* env, jobject cameraMetadata) + __INTRODUCED_IN(30); +#endif /* __ANDROID_VNDK__ */ __END_DECLS diff --git a/camera/NdkCameraMetadataTags.h b/camera/NdkCameraMetadataTags.h index 5634982..9174adf 100644 --- a/camera/NdkCameraMetadataTags.h +++ b/camera/NdkCameraMetadataTags.h @@ -40,7 +40,6 @@ __BEGIN_DECLS -#if __ANDROID_API__ >= 24 typedef enum acamera_metadata_section { ACAMERA_COLOR_CORRECTION, @@ -73,6 +72,8 @@ typedef enum acamera_metadata_section { ACAMERA_DISTORTION_CORRECTION, ACAMERA_HEIC, ACAMERA_HEIC_INFO, + ACAMERA_AUTOMOTIVE, + ACAMERA_AUTOMOTIVE_LENS, ACAMERA_SECTION_COUNT, ACAMERA_VENDOR = 0x8000 @@ -116,6 +117,8 @@ typedef enum acamera_metadata_section_start { << 16, ACAMERA_HEIC_START = ACAMERA_HEIC << 16, ACAMERA_HEIC_INFO_START = ACAMERA_HEIC_INFO << 16, + ACAMERA_AUTOMOTIVE_START = ACAMERA_AUTOMOTIVE << 16, + ACAMERA_AUTOMOTIVE_LENS_START = ACAMERA_AUTOMOTIVE_LENS << 16, ACAMERA_VENDOR_START = ACAMERA_VENDOR << 16 } acamera_metadata_section_start_t; @@ -518,6 +521,14 @@ typedef enum acamera_metadata_tag { * region and output only the intersection rectangle as the metering region in the result * metadata. If the region is entirely outside the crop region, it will be ignored and * not reported in the result metadata.
+ *When setting the AE metering regions, the application must consider the additional + * crop resulted from the aspect ratio differences between the preview stream and + * ACAMERA_SCALER_CROP_REGION. For example, if the ACAMERA_SCALER_CROP_REGION is the full + * active array size with 4:3 aspect ratio, and the preview stream is 16:9, + * the boundary of AE regions will be [0, y_crop] and + * [active_width, active_height - 2 * y_crop] rather than [0, 0] and + * [active_width, active_height], where y_crop is the additional crop due to aspect ratio + * mismatch.
*Starting from API level 30, the coordinate system of activeArraySize or * preCorrectionActiveArraySize is used to represent post-zoomRatio field of view, not * pre-zoom field of view. This means that the same aeRegions values at different @@ -528,6 +539,13 @@ typedef enum acamera_metadata_tag { * scene as they do before. See ACAMERA_CONTROL_ZOOM_RATIO for details. Whether to use * activeArraySize or preCorrectionActiveArraySize still depends on distortion correction * mode.
+ *For camera devices with the + * CameraMetadata#REQUEST_AVAILABLE_CAPABILITIES_ULTRA_HIGH_RESOLUTION_SENSOR + * capability, + * ACAMERA_SENSOR_INFO_ACTIVE_ARRAY_SIZE_MAXIMUM_RESOLUTION / + * ACAMERA_SENSOR_INFO_PRE_CORRECTION_ACTIVE_ARRAY_SIZE_MAXIMUM_RESOLUTION must be used as the + * coordinate system for requests where ACAMERA_SENSOR_PIXEL_MODE is set to + * CameraMetadata#SENSOR_PIXEL_MODE_MAXIMUM_RESOLUTION.
*The data representation is int[5 * area_count].
* Every five elements represent a metering region of (xmin, ymin, xmax, ymax, weight).
* The rectangle is defined to be inclusive on xmin and ymin, but exclusive on xmax and
@@ -537,7 +555,10 @@ typedef enum acamera_metadata_tag {
* @see ACAMERA_DISTORTION_CORRECTION_MODE
* @see ACAMERA_SCALER_CROP_REGION
* @see ACAMERA_SENSOR_INFO_ACTIVE_ARRAY_SIZE
+ * @see ACAMERA_SENSOR_INFO_ACTIVE_ARRAY_SIZE_MAXIMUM_RESOLUTION
* @see ACAMERA_SENSOR_INFO_PRE_CORRECTION_ACTIVE_ARRAY_SIZE
+ * @see ACAMERA_SENSOR_INFO_PRE_CORRECTION_ACTIVE_ARRAY_SIZE_MAXIMUM_RESOLUTION
+ * @see ACAMERA_SENSOR_PIXEL_MODE
*/
ACAMERA_CONTROL_AE_REGIONS = // int32[5*area_count]
ACAMERA_CONTROL_START + 4,
@@ -709,6 +730,14 @@ typedef enum acamera_metadata_tag {
* region and output only the intersection rectangle as the metering region in the result
* metadata. If the region is entirely outside the crop region, it will be ignored and
* not reported in the result metadata.
When setting the AF metering regions, the application must consider the additional + * crop resulted from the aspect ratio differences between the preview stream and + * ACAMERA_SCALER_CROP_REGION. For example, if the ACAMERA_SCALER_CROP_REGION is the full + * active array size with 4:3 aspect ratio, and the preview stream is 16:9, + * the boundary of AF regions will be [0, y_crop] and + * [active_width, active_height - 2 * y_crop] rather than [0, 0] and + * [active_width, active_height], where y_crop is the additional crop due to aspect ratio + * mismatch.
*Starting from API level 30, the coordinate system of activeArraySize or * preCorrectionActiveArraySize is used to represent post-zoomRatio field of view, not * pre-zoom field of view. This means that the same afRegions values at different @@ -719,6 +748,12 @@ typedef enum acamera_metadata_tag { * scene as they do before. See ACAMERA_CONTROL_ZOOM_RATIO for details. Whether to use * activeArraySize or preCorrectionActiveArraySize still depends on distortion correction * mode.
+ *For camera devices with the + * CameraMetadata#REQUEST_AVAILABLE_CAPABILITIES_ULTRA_HIGH_RESOLUTION_SENSOR + * capability, ACAMERA_SENSOR_INFO_ACTIVE_ARRAY_SIZE_MAXIMUM_RESOLUTION / + * ACAMERA_SENSOR_INFO_PRE_CORRECTION_ACTIVE_ARRAY_SIZE_MAXIMUM_RESOLUTION must be used as the + * coordinate system for requests where ACAMERA_SENSOR_PIXEL_MODE is set to + * CameraMetadata#SENSOR_PIXEL_MODE_MAXIMUM_RESOLUTION.
*The data representation is int[5 * area_count].
* Every five elements represent a metering region of (xmin, ymin, xmax, ymax, weight).
* The rectangle is defined to be inclusive on xmin and ymin, but exclusive on xmax and
@@ -728,7 +763,10 @@ typedef enum acamera_metadata_tag {
* @see ACAMERA_DISTORTION_CORRECTION_MODE
* @see ACAMERA_SCALER_CROP_REGION
* @see ACAMERA_SENSOR_INFO_ACTIVE_ARRAY_SIZE
+ * @see ACAMERA_SENSOR_INFO_ACTIVE_ARRAY_SIZE_MAXIMUM_RESOLUTION
* @see ACAMERA_SENSOR_INFO_PRE_CORRECTION_ACTIVE_ARRAY_SIZE
+ * @see ACAMERA_SENSOR_INFO_PRE_CORRECTION_ACTIVE_ARRAY_SIZE_MAXIMUM_RESOLUTION
+ * @see ACAMERA_SENSOR_PIXEL_MODE
*/
ACAMERA_CONTROL_AF_REGIONS = // int32[5*area_count]
ACAMERA_CONTROL_START + 8,
@@ -816,11 +854,11 @@ typedef enum acamera_metadata_tag {
*
This control is only effective if ACAMERA_CONTROL_MODE is AUTO.
- *When set to the ON mode, the camera device's auto-white balance + *
When set to the AUTO mode, the camera device's auto-white balance * routine is enabled, overriding the application's selected * ACAMERA_COLOR_CORRECTION_TRANSFORM, ACAMERA_COLOR_CORRECTION_GAINS and * ACAMERA_COLOR_CORRECTION_MODE. Note that when ACAMERA_CONTROL_AE_MODE - * is OFF, the behavior of AWB is device dependent. It is recommened to + * is OFF, the behavior of AWB is device dependent. It is recommended to * also set AWB mode to OFF or lock AWB by using ACAMERA_CONTROL_AWB_LOCK before * setting AE mode to OFF.
*When set to the OFF mode, the camera device's auto-white balance @@ -895,6 +933,14 @@ typedef enum acamera_metadata_tag { * region and output only the intersection rectangle as the metering region in the result * metadata. If the region is entirely outside the crop region, it will be ignored and * not reported in the result metadata.
+ *When setting the AWB metering regions, the application must consider the additional + * crop resulted from the aspect ratio differences between the preview stream and + * ACAMERA_SCALER_CROP_REGION. For example, if the ACAMERA_SCALER_CROP_REGION is the full + * active array size with 4:3 aspect ratio, and the preview stream is 16:9, + * the boundary of AWB regions will be [0, y_crop] and + * [active_width, active_height - 2 * y_crop] rather than [0, 0] and + * [active_width, active_height], where y_crop is the additional crop due to aspect ratio + * mismatch.
*Starting from API level 30, the coordinate system of activeArraySize or * preCorrectionActiveArraySize is used to represent post-zoomRatio field of view, not * pre-zoom field of view. This means that the same awbRegions values at different @@ -905,6 +951,12 @@ typedef enum acamera_metadata_tag { * the scene as they do before. See ACAMERA_CONTROL_ZOOM_RATIO for details. Whether to use * activeArraySize or preCorrectionActiveArraySize still depends on distortion correction * mode.
+ *For camera devices with the + * CameraMetadata#REQUEST_AVAILABLE_CAPABILITIES_ULTRA_HIGH_RESOLUTION_SENSOR + * capability, ACAMERA_SENSOR_INFO_ACTIVE_ARRAY_SIZE_MAXIMUM_RESOLUTION / + * ACAMERA_SENSOR_INFO_PRE_CORRECTION_ACTIVE_ARRAY_SIZE_MAXIMUM_RESOLUTION must be used as the + * coordinate system for requests where ACAMERA_SENSOR_PIXEL_MODE is set to + * CameraMetadata#SENSOR_PIXEL_MODE_MAXIMUM_RESOLUTION.
*The data representation is int[5 * area_count].
* Every five elements represent a metering region of (xmin, ymin, xmax, ymax, weight).
* The rectangle is defined to be inclusive on xmin and ymin, but exclusive on xmax and
@@ -914,7 +966,10 @@ typedef enum acamera_metadata_tag {
* @see ACAMERA_DISTORTION_CORRECTION_MODE
* @see ACAMERA_SCALER_CROP_REGION
* @see ACAMERA_SENSOR_INFO_ACTIVE_ARRAY_SIZE
+ * @see ACAMERA_SENSOR_INFO_ACTIVE_ARRAY_SIZE_MAXIMUM_RESOLUTION
* @see ACAMERA_SENSOR_INFO_PRE_CORRECTION_ACTIVE_ARRAY_SIZE
+ * @see ACAMERA_SENSOR_INFO_PRE_CORRECTION_ACTIVE_ARRAY_SIZE_MAXIMUM_RESOLUTION
+ * @see ACAMERA_SENSOR_PIXEL_MODE
*/
ACAMERA_CONTROL_AWB_REGIONS = // int32[5*area_count]
ACAMERA_CONTROL_START + 12,
@@ -934,13 +989,15 @@ typedef enum acamera_metadata_tag {
*
*
This control (except for MANUAL) is only effective if
* ACAMERA_CONTROL_MODE != OFF and any 3A routine is active.
All intents are supported by all devices, except that: - * * ZERO_SHUTTER_LAG will be supported if ACAMERA_REQUEST_AVAILABLE_CAPABILITIES contains - * PRIVATE_REPROCESSING or YUV_REPROCESSING. - * * MANUAL will be supported if ACAMERA_REQUEST_AVAILABLE_CAPABILITIES contains - * MANUAL_SENSOR. - * * MOTION_TRACKING will be supported if ACAMERA_REQUEST_AVAILABLE_CAPABILITIES contains - * MOTION_TRACKING.
+ *All intents are supported by all devices, except that:
+ *If video stabilization is set to "PREVIEW_STABILIZATION", + * ACAMERA_LENS_OPTICAL_STABILIZATION_MODE is overridden. The camera sub-system may choose + * to turn on hardware based image stabilization in addition to software based stabilization + * if it deems that appropriate. + * This key may be a part of the available session keys, which camera clients may + * query via + * {@link ACameraManager_getCameraCharacteristics }. + * If this is the case, changing this key over the life-time of a capture session may + * cause delays / glitches.
* * @see ACAMERA_CONTROL_VIDEO_STABILIZATION_MODE * @see ACAMERA_LENS_OPTICAL_STABILIZATION_MODE @@ -1422,7 +1488,7 @@ typedef enum acamera_metadata_tag { * Any state (excluding LOCKED) | ACAMERA_CONTROL_AE_PRECAPTURE_TRIGGER is START, sequence done | FLASH_REQUIRED | Converged but too dark w/o flash after a precapture sequence, transient states are skipped by camera device. * Any state (excluding LOCKED) | ACAMERA_CONTROL_AE_PRECAPTURE_TRIGGER is START, sequence done | CONVERGED | Converged after a precapture sequence, transient states are skipped by camera device. * Any state (excluding LOCKED) | ACAMERA_CONTROL_AE_PRECAPTURE_TRIGGER is CANCEL, converged | FLASH_REQUIRED | Converged but too dark w/o flash after a precapture sequence is canceled, transient states are skipped by camera device. - * Any state (excluding LOCKED) | ACAMERA_CONTROL_AE_PRECAPTURE_TRIGGER is CANCEL, converged | CONVERGED | Converged after a precapture sequenceis canceled, transient states are skipped by camera device. + * Any state (excluding LOCKED) | ACAMERA_CONTROL_AE_PRECAPTURE_TRIGGER is CANCEL, converged | CONVERGED | Converged after a precapture sequences canceled, transient states are skipped by camera device. * CONVERGED | Camera device finished AE scan | FLASH_REQUIRED | Converged but too dark w/o flash after a new scan, transient states are skipped by camera device. * FLASH_REQUIRED | Camera device finished AE scan | CONVERGED | Converged after a new scan, transient states are skipped by camera device. * @@ -1658,7 +1724,7 @@ typedef enum acamera_metadata_tag { * * *Devices support post RAW sensitivity boost will advertise - * ACAMERA_CONTROL_POST_RAW_SENSITIVITY_BOOST key for controling + * ACAMERA_CONTROL_POST_RAW_SENSITIVITY_BOOST key for controlling * post RAW sensitivity boost.
*This key will be null for devices that do not support any RAW format
* outputs. For devices that do support RAW format outputs, this key will always
@@ -1841,7 +1907,7 @@ typedef enum acamera_metadata_tag {
*
When set to BOKEH_CONTINUOUS mode, configured streams dimension should not exceed this mode's @@ -1961,6 +2027,16 @@ typedef enum acamera_metadata_tag { * ACAMERA_CONTROL_ZOOM_RATIO is not 1.0, and ACAMERA_SCALER_CROP_REGION is set to be * windowboxing, the camera framework will override the ACAMERA_SCALER_CROP_REGION to be * the active array.
+ *In the capture request, if the application sets ACAMERA_CONTROL_ZOOM_RATIO to a + * value != 1.0, the ACAMERA_CONTROL_ZOOM_RATIO tag in the capture result reflects the + * effective zoom ratio achieved by the camera device, and the ACAMERA_SCALER_CROP_REGION + * adjusts for additional crops that are not zoom related. Otherwise, if the application + * sets ACAMERA_CONTROL_ZOOM_RATIO to 1.0, or does not set it at all, the + * ACAMERA_CONTROL_ZOOM_RATIO tag in the result metadata will also be 1.0.
+ *When the application requests a physical stream for a logical multi-camera, the + * ACAMERA_CONTROL_ZOOM_RATIO in the physical camera result metadata will be 1.0, and + * the ACAMERA_SCALER_CROP_REGION tag reflects the amount of zoom and crop done by the + * physical camera device.
* * @see ACAMERA_CONTROL_AE_REGIONS * @see ACAMERA_CONTROL_ZOOM_RATIO @@ -2107,6 +2183,55 @@ typedef enum acamera_metadata_tag { */ ACAMERA_FLASH_INFO_AVAILABLE = // byte (acamera_metadata_enum_android_flash_info_available_t) ACAMERA_FLASH_INFO_START, + /** + *Maximum flashlight brightness level.
+ * + *Type: int32
+ * + *This tag may appear in: + *
If this value is greater than 1, then the device supports controlling the + * flashlight brightness level via + * CameraManager#turnOnTorchWithStrengthLevel. + * If this value is equal to 1, flashlight brightness control is not supported. + * The value for this key will be null for devices with no flash unit.
+ *The maximum value is guaranteed to be safe to use for an indefinite duration in + * terms of device flashlight lifespan, but may be too bright for comfort for many + * use cases. Use the default torch brightness value to avoid problems with an + * over-bright flashlight.
+ */ + ACAMERA_FLASH_INFO_STRENGTH_MAXIMUM_LEVEL = // int32 + ACAMERA_FLASH_INFO_START + 2, + /** + *Default flashlight brightness level to be set via + * CameraManager#turnOnTorchWithStrengthLevel.
+ * + *Type: int32
+ * + *This tag may appear in: + *
If flash unit is available this will be greater than or equal to 1 and less
+ * or equal to ACAMERA_FLASH_INFO_STRENGTH_MAXIMUM_LEVEL.
Setting flashlight brightness above the default level
+ * (i.e.ACAMERA_FLASH_INFO_STRENGTH_DEFAULT_LEVEL) may make the device more
+ * likely to reach thermal throttling conditions and slow down, or drain the
+ * battery quicker than normal. To minimize such issues, it is recommended to
+ * start the flashlight at this default brightness until a user explicitly requests
+ * a brighter level.
+ * Note that the value for this key will be null for devices with no flash unit.
+ * The default level should always be > 0.
This list will include at least one non-zero resolution, plus (0,0) for indicating no
* thumbnail should be generated.
Below condiditions will be satisfied for this size list:
+ *Below conditions will be satisfied for this size list:
*If a camera device supports both OIS and digital image stabilization * (ACAMERA_CONTROL_VIDEO_STABILIZATION_MODE), turning both modes on may produce undesirable * interaction, so it is recommended not to enable both at the same time.
+ *If ACAMERA_CONTROL_VIDEO_STABILIZATION_MODE is set to "PREVIEW_STABILIZATION", + * ACAMERA_LENS_OPTICAL_STABILIZATION_MODE is overridden. The camera sub-system may choose + * to turn on hardware based image stabilization in addition to software based stabilization + * if it deems that appropriate. This key's value in the capture result will reflect which + * OIS mode was chosen.
*Not all devices will support OIS; see * ACAMERA_LENS_INFO_AVAILABLE_OPTICAL_STABILIZATION for * available controls.
* * @see ACAMERA_CONTROL_VIDEO_STABILIZATION_MODE * @see ACAMERA_LENS_INFO_AVAILABLE_OPTICAL_STABILIZATION + * @see ACAMERA_LENS_OPTICAL_STABILIZATION_MODE */ ACAMERA_LENS_OPTICAL_STABILIZATION_MODE = // byte (acamera_metadata_enum_android_lens_optical_stabilization_mode_t) ACAMERA_LENS_START + 4, @@ -2597,6 +2728,9 @@ typedef enum acamera_metadata_tag { * with PRIMARY_CAMERA. *When ACAMERA_LENS_POSE_REFERENCE is UNDEFINED, this position cannot be accurately
* represented by the camera device, and will be represented as (0, 0, 0).
When ACAMERA_LENS_POSE_REFERENCE is AUTOMOTIVE, then this position is relative to the + * origin of the automotive sensor coordinate system, which is at the center of the rear + * axle.
* * @see ACAMERA_LENS_DISTORTION * @see ACAMERA_LENS_INTRINSIC_CALIBRATION @@ -2638,7 +2772,7 @@ typedef enum acamera_metadata_tag { *When the state is STATIONARY, the lens parameters are not changing. This could be * either because the parameters are all fixed, or because the lens has had enough * time to reach the most recently-requested values. - * If all these lens parameters are not changable for a camera device, as listed below:
+ * If all these lens parameters are not changeable for a camera device, as listed below: *ACAMERA_LENS_INFO_MINIMUM_FOCUS_DISTANCE == 0), which means
* ACAMERA_LENS_FOCUS_DISTANCE parameter will always be 0.The correction coefficients to correct for this camera device's + * radial and tangential lens distortion for a + * CaptureRequest with ACAMERA_SENSOR_PIXEL_MODE set to + * CameraMetadata#SENSOR_PIXEL_MODE_MAXIMUM_RESOLUTION.
+ * + * @see ACAMERA_SENSOR_PIXEL_MODE + * + *Type: float[5]
+ * + *This tag may appear in: + *
Analogous to ACAMERA_LENS_DISTORTION, when ACAMERA_SENSOR_PIXEL_MODE is set to + * CameraMetadata#SENSOR_PIXEL_MODE_MAXIMUM_RESOLUTION.
+ * + * @see ACAMERA_LENS_DISTORTION + * @see ACAMERA_SENSOR_PIXEL_MODE + */ + ACAMERA_LENS_DISTORTION_MAXIMUM_RESOLUTION = // float[5] + ACAMERA_LENS_START + 14, + /** + *The parameters for this camera device's intrinsic + * calibration when ACAMERA_SENSOR_PIXEL_MODE is set to + * CameraMetadata#SENSOR_PIXEL_MODE_MAXIMUM_RESOLUTION.
+ * + * @see ACAMERA_SENSOR_PIXEL_MODE + * + *Type: float[5]
+ * + *This tag may appear in: + *
Analogous to ACAMERA_LENS_INTRINSIC_CALIBRATION, when ACAMERA_SENSOR_PIXEL_MODE is set to + * CameraMetadata#SENSOR_PIXEL_MODE_MAXIMUM_RESOLUTION.
+ * + * @see ACAMERA_LENS_INTRINSIC_CALIBRATION + * @see ACAMERA_SENSOR_PIXEL_MODE + */ + ACAMERA_LENS_INTRINSIC_CALIBRATION_MAXIMUM_RESOLUTION = // float[5] + ACAMERA_LENS_START + 15, ACAMERA_LENS_END, /** @@ -3045,7 +3224,7 @@ typedef enum acamera_metadata_tag { * the camera device. Using more streams simultaneously may require more hardware and * CPU resources that will consume more power. The image format for an output stream can * be any supported format provided by ACAMERA_SCALER_AVAILABLE_STREAM_CONFIGURATIONS. - * The formats defined in ACAMERA_SCALER_AVAILABLE_STREAM_CONFIGURATIONS can be catergorized + * The formats defined in ACAMERA_SCALER_AVAILABLE_STREAM_CONFIGURATIONS can be categorized * into the 3 stream types as below: *This is a subset of ACAMERA_REQUEST_AVAILABLE_REQUEST_KEYS which contains a list - * of keys that can be overridden using Builder#setPhysicalCameraKey. + * of keys that can be overridden using + * Builder#setPhysicalCameraKey. * The respective value of such request key can be obtained by calling - * Builder#getPhysicalCameraKey. Capture requests that contain - * individual physical device requests must be built via + * Builder#getPhysicalCameraKey. + * Capture requests that contain individual physical device requests must be built via * Set).
* * @see ACAMERA_REQUEST_AVAILABLE_REQUEST_KEYS */ ACAMERA_REQUEST_AVAILABLE_PHYSICAL_CAMERA_REQUEST_KEYS = // int32[n] ACAMERA_REQUEST_START + 17, + /** + *A map of all available 10-bit dynamic range profiles along with their + * capture request constraints.
+ * + *Type: int64[n*3] (acamera_metadata_enum_android_request_available_dynamic_range_profiles_map_t)
+ * + *This tag may appear in: + *
Devices supporting the 10-bit output capability + * CameraCharacteristics#REQUEST_AVAILABLE_CAPABILITIES_DYNAMIC_RANGE_TEN_BIT + * must list their supported dynamic range profiles. In case the camera is not able to + * support every possible profile combination within a single capture request, then the + * constraints must be listed here as well.
+ */ + ACAMERA_REQUEST_AVAILABLE_DYNAMIC_RANGE_PROFILES_MAP = // int64[n*3] (acamera_metadata_enum_android_request_available_dynamic_range_profiles_map_t) + ACAMERA_REQUEST_START + 19, ACAMERA_REQUEST_END, /** @@ -3429,6 +3628,12 @@ typedef enum acamera_metadata_tag { * coordinate system is post-zoom, meaning that the activeArraySize or * preCorrectionActiveArraySize covers the camera device's field of view "after" zoom. See * ACAMERA_CONTROL_ZOOM_RATIO for details. + *For camera devices with the + * CameraMetadata#REQUEST_AVAILABLE_CAPABILITIES_ULTRA_HIGH_RESOLUTION_SENSOR + * capability, ACAMERA_SENSOR_INFO_ACTIVE_ARRAY_SIZE_MAXIMUM_RESOLUTION / + * ACAMERA_SENSOR_INFO_PRE_CORRECTION_ACTIVE_ARRAY_SIZE_MAXIMUM_RESOLUTION must be used as the + * coordinate system for requests where ACAMERA_SENSOR_PIXEL_MODE is set to + * CameraMetadata#SENSOR_PIXEL_MODE_MAXIMUM_RESOLUTION.
*The data representation is int[4], which maps to (left, top, width, height).
* * @see ACAMERA_CONTROL_AE_TARGET_FPS_RANGE @@ -3437,7 +3642,10 @@ typedef enum acamera_metadata_tag { * @see ACAMERA_SCALER_AVAILABLE_MAX_DIGITAL_ZOOM * @see ACAMERA_SCALER_CROPPING_TYPE * @see ACAMERA_SENSOR_INFO_ACTIVE_ARRAY_SIZE + * @see ACAMERA_SENSOR_INFO_ACTIVE_ARRAY_SIZE_MAXIMUM_RESOLUTION * @see ACAMERA_SENSOR_INFO_PRE_CORRECTION_ACTIVE_ARRAY_SIZE + * @see ACAMERA_SENSOR_INFO_PRE_CORRECTION_ACTIVE_ARRAY_SIZE_MAXIMUM_RESOLUTION + * @see ACAMERA_SENSOR_PIXEL_MODE */ ACAMERA_SCALER_CROP_REGION = // int32[4] ACAMERA_SCALER_START, @@ -3495,8 +3703,8 @@ typedef enum acamera_metadata_tag { *Not all output formats may be supported in a configuration with * an input stream of a particular format. For more details, see * android.scaler.availableInputOutputFormatsMap.
- *The following table describes the minimum required output stream - * configurations based on the hardware level + *
For applications targeting SDK version older than 31, the following table + * describes the minimum required output stream configurations based on the hardware level * (ACAMERA_INFO_SUPPORTED_HARDWARE_LEVEL):
*Format | Size | Hardware Level | Notes * :-------------:|:--------------------------------------------:|:--------------:|:--------------: @@ -3508,6 +3716,31 @@ typedef enum acamera_metadata_tag { * YUV_420_888 | all output sizes available for JPEG | FULL | * YUV_420_888 | all output sizes available for JPEG, up to the maximum video size | LIMITED | * IMPLEMENTATION_DEFINED | same as YUV_420_888 | Any |
+ *For applications targeting SDK version 31 or newer, if the mobile device declares to be + * media performance class 12 or higher by setting + * VERSION#MEDIA_PERFORMANCE_CLASS to be 31 or larger, + * the primary camera devices (first rear/front camera in the camera ID list) will not + * support JPEG sizes smaller than 1080p. If the application configures a JPEG stream + * smaller than 1080p, the camera device will round up the JPEG image size to at least + * 1080p. The requirements for IMPLEMENTATION_DEFINED and YUV_420_888 stay the same. + * This new minimum required output stream configurations are illustrated by the table below:
+ *Format | Size | Hardware Level | Notes + * :-------------:|:--------------------------------------------:|:--------------:|:--------------: + * JPEG | ACAMERA_SENSOR_INFO_ACTIVE_ARRAY_SIZE | Any | + * JPEG | 1920x1080 (1080p) | Any | if 1080p <= activeArraySize + * YUV_420_888 | ACAMERA_SENSOR_INFO_ACTIVE_ARRAY_SIZE | FULL | + * YUV_420_888 | 1920x1080 (1080p) | FULL | if 1080p <= activeArraySize + * YUV_420_888 | 1280x720 (720) | FULL | if 720p <= activeArraySize + * YUV_420_888 | 640x480 (480p) | FULL | if 480p <= activeArraySize + * YUV_420_888 | 320x240 (240p) | FULL | if 240p <= activeArraySize + * YUV_420_888 | all output sizes available for FULL hardware level, up to the maximum video size | LIMITED | + * IMPLEMENTATION_DEFINED | same as YUV_420_888 | Any |
+ *For applications targeting SDK version 31 or newer, if the mobile device doesn't declare + * to be media performance class 12 or better by setting + * VERSION#MEDIA_PERFORMANCE_CLASS to be 31 or larger, + * or if the camera device isn't a primary rear/front camera, the minimum required output + * stream configurations are the same as for applications targeting SDK version older than + * 31.
*Refer to ACAMERA_REQUEST_AVAILABLE_CAPABILITIES for additional * mandatory stream configurations on a per-capability basis.
*Exception on 176x144 (QCIF) resolution: camera devices usually have a fixed capability for @@ -3539,8 +3772,6 @@ typedef enum acamera_metadata_tag { * set to either OFF or FAST.
*When multiple streams are used in a request, the minimum frame * duration will be max(individual stream min durations).
- *The minimum frame duration of a stream (of a particular format, size) - * is the same regardless of whether the stream is input or output.
*See ACAMERA_SENSOR_FRAME_DURATION and * ACAMERA_SCALER_AVAILABLE_STALL_DURATIONS for more details about * calculating the max frame rate.
@@ -3741,6 +3972,329 @@ typedef enum acamera_metadata_tag { ACAMERA_SCALER_AVAILABLE_RECOMMENDED_INPUT_OUTPUT_FORMATS_MAP = // int32 ACAMERA_SCALER_START + 15, + /** + *List of rotate-and-crop modes for ACAMERA_SCALER_ROTATE_AND_CROP that are supported by this camera device.
+ * + * @see ACAMERA_SCALER_ROTATE_AND_CROP + * + *Type: byte[n]
+ * + *This tag may appear in: + *
This entry lists the valid modes for ACAMERA_SCALER_ROTATE_AND_CROP for this camera device.
+ *Starting with API level 30, all devices will list at least ROTATE_AND_CROP_NONE.
+ * Devices with support for rotate-and-crop will additionally list at least
+ * ROTATE_AND_CROP_AUTO and ROTATE_AND_CROP_90.
Whether a rotation-and-crop operation is applied to processed + * outputs from the camera.
+ * + *Type: byte (acamera_metadata_enum_android_scaler_rotate_and_crop_t)
+ * + *This tag may appear in: + *
This control is primarily intended to help camera applications with no support for + * multi-window modes to work correctly on devices where multi-window scenarios are + * unavoidable, such as foldables or other devices with variable display geometry or more + * free-form window placement (such as laptops, which often place portrait-orientation apps + * in landscape with pillarboxing).
+ *If supported, the default value is ROTATE_AND_CROP_AUTO, which allows the camera API
+ * to enable backwards-compatibility support for applications that do not support resizing
+ * / multi-window modes, when the device is in fact in a multi-window mode (such as inset
+ * portrait on laptops, or on a foldable device in some fold states). In addition,
+ * ROTATE_AND_CROP_NONE and ROTATE_AND_CROP_90 will always be available if this control
+ * is supported by the device. If not supported, devices API level 30 or higher will always
+ * list only ROTATE_AND_CROP_NONE.
When CROP_AUTO is in use, and the camera API activates backward-compatibility mode,
+ * several metadata fields will also be parsed differently to ensure that coordinates are
+ * correctly handled for features like drawing face detection boxes or passing in
+ * tap-to-focus coordinates. The camera API will convert positions in the active array
+ * coordinate system to/from the cropped-and-rotated coordinate system to make the
+ * operation transparent for applications. The following controls are affected:
Capture results will contain the actual value selected by the API;
+ * ROTATE_AND_CROP_AUTO will never be seen in a capture result.
Applications can also select their preferred cropping mode, either to opt out of the + * backwards-compatibility treatment, or to use the cropping feature themselves as needed. + * In this case, no coordinate translation will be done automatically, and all controls + * will continue to use the normal active array coordinates.
+ *Cropping and rotating is done after the application of digital zoom (via either + * ACAMERA_SCALER_CROP_REGION or ACAMERA_CONTROL_ZOOM_RATIO), but before each individual + * output is further cropped and scaled. It only affects processed outputs such as + * YUV, PRIVATE, and JPEG. It has no effect on RAW outputs.
+ *When CROP_90 or CROP_270 are selected, there is a significant loss to the field of
+ * view. For example, with a 4:3 aspect ratio output of 1600x1200, CROP_90 will still
+ * produce 1600x1200 output, but these buffers are cropped from a vertical 3:4 slice at the
+ * center of the 4:3 area, then rotated to be 4:3, and then upscaled to 1600x1200. Only
+ * 56.25% of the original FOV is still visible. In general, for an aspect ratio of w:h,
+ * the crop and rotate operation leaves (h/w)^2 of the field of view visible. For 16:9,
+ * this is ~31.6%.
As a visual example, the figure below shows the effect of ROTATE_AND_CROP_90 on the
+ * outputs for the following parameters:
2000x1500(500, 375), size: (1000, 750) (4:3 aspect ratio)640x480 and YUV 1280x720ROTATE_AND_CROP_90
With these settings, the regions of the active array covered by the output streams are:
+ *(219, 375), size: (562, 750)(289, 375), size: (422, 750)Since the buffers are rotated, the buffers as seen by the application are:
+ *(781, 375) on active array, size: (640, 480), downscaled 1.17x from sensor pixels(711, 375) on active array, size: (1280, 720), upscaled 1.71x from sensor pixelsDefault YUV/PRIVATE size to use for requesting secure image buffers.
+ * + *Type: int32[2]
+ * + *This tag may appear in: + *
This entry lists the default size supported in the secure camera mode. This entry is + * optional on devices support the SECURE_IMAGE_DATA capability. This entry will be null + * if the camera device does not list SECURE_IMAGE_DATA capability.
+ *When the key is present, only a PRIVATE/YUV output of the specified size is guaranteed + * to be supported by the camera HAL in the secure camera mode. Any other format or + * resolutions might not be supported. Use + * {@link ACameraDevice_isSessionConfigurationSupported } + * API to query if a secure session configuration is supported if the device supports this + * API.
+ *If this key returns null on a device with SECURE_IMAGE_DATA capability, the application + * can assume all output sizes listed in the + * {@link ACAMERA_SCALER_AVAILABLE_MIN_FRAME_DURATIONS } + * are supported.
+ */ + ACAMERA_SCALER_DEFAULT_SECURE_IMAGE_SIZE = // int32[2] + ACAMERA_SCALER_START + 18, + /** + *The available multi-resolution stream configurations that this + * physical camera device supports + * (i.e. format, width, height, output/input stream).
+ * + *Type: int32[n*4] (acamera_metadata_enum_android_scaler_physical_camera_multi_resolution_stream_configurations_t)
+ * + *This tag may appear in: + *
This list contains a subset of the parent logical camera's multi-resolution stream + * configurations which belong to this physical camera, and it will advertise and will only + * advertise the maximum supported resolutions for a particular format.
+ *If this camera device isn't a physical camera device constituting a logical camera, + * but a standalone CameraMetadata#REQUEST_AVAILABLE_CAPABILITIES_ULTRA_HIGH_RESOLUTION_SENSOR + * camera, this field represents the multi-resolution input/output stream configurations of + * default mode and max resolution modes. The sizes will be the maximum resolution of a + * particular format for default mode and max resolution mode.
+ *This field will only be advertised if the device is a physical camera of a + * logical multi-camera device or an ultra high resolution sensor camera. For a logical + * multi-camera, the camera API will derive the logical camera’s multi-resolution stream + * configurations from all physical cameras. For an ultra high resolution sensor camera, this + * is used directly as the camera’s multi-resolution stream configurations.
+ */ + ACAMERA_SCALER_PHYSICAL_CAMERA_MULTI_RESOLUTION_STREAM_CONFIGURATIONS = + // int32[n*4] (acamera_metadata_enum_android_scaler_physical_camera_multi_resolution_stream_configurations_t) + ACAMERA_SCALER_START + 19, + /** + *The available stream configurations that this + * camera device supports (i.e. format, width, height, output/input stream) for a + * CaptureRequest with ACAMERA_SENSOR_PIXEL_MODE set to + * CameraMetadata#SENSOR_PIXEL_MODE_MAXIMUM_RESOLUTION.
+ * + * @see ACAMERA_SENSOR_PIXEL_MODE + * + *Type: int32[n*4] (acamera_metadata_enum_android_scaler_available_stream_configurations_maximum_resolution_t)
+ * + *This tag may appear in: + *
Analogous to ACAMERA_SCALER_AVAILABLE_STREAM_CONFIGURATIONS, for configurations + * which are applicable when ACAMERA_SENSOR_PIXEL_MODE is set to + * CameraMetadata#SENSOR_PIXEL_MODE_MAXIMUM_RESOLUTION.
+ *Not all output formats may be supported in a configuration with + * an input stream of a particular format. For more details, see + * android.scaler.availableInputOutputFormatsMapMaximumResolution.
+ * + * @see ACAMERA_SCALER_AVAILABLE_STREAM_CONFIGURATIONS + * @see ACAMERA_SENSOR_PIXEL_MODE + */ + ACAMERA_SCALER_AVAILABLE_STREAM_CONFIGURATIONS_MAXIMUM_RESOLUTION = + // int32[n*4] (acamera_metadata_enum_android_scaler_available_stream_configurations_maximum_resolution_t) + ACAMERA_SCALER_START + 20, + /** + *This lists the minimum frame duration for each + * format/size combination when the camera device is sent a CaptureRequest with + * ACAMERA_SENSOR_PIXEL_MODE set to + * CameraMetadata#SENSOR_PIXEL_MODE_MAXIMUM_RESOLUTION.
+ * + * @see ACAMERA_SENSOR_PIXEL_MODE + * + *Type: int64[4*n]
+ * + *This tag may appear in: + *
Analogous to ACAMERA_SCALER_AVAILABLE_MIN_FRAME_DURATIONS, for configurations + * which are applicable when ACAMERA_SENSOR_PIXEL_MODE is set to + * CameraMetadata#SENSOR_PIXEL_MODE_MAXIMUM_RESOLUTION.
+ *When multiple streams are used in a request (if supported, when ACAMERA_SENSOR_PIXEL_MODE + * is set to + * CameraMetadata#SENSOR_PIXEL_MODE_MAXIMUM_RESOLUTION), the + * minimum frame duration will be max(individual stream min durations).
+ *See ACAMERA_SENSOR_FRAME_DURATION and + * ACAMERA_SCALER_AVAILABLE_STALL_DURATIONS_MAXIMUM_RESOLUTION for more details about + * calculating the max frame rate.
+ * + * @see ACAMERA_SCALER_AVAILABLE_MIN_FRAME_DURATIONS + * @see ACAMERA_SCALER_AVAILABLE_STALL_DURATIONS_MAXIMUM_RESOLUTION + * @see ACAMERA_SENSOR_FRAME_DURATION + * @see ACAMERA_SENSOR_PIXEL_MODE + */ + ACAMERA_SCALER_AVAILABLE_MIN_FRAME_DURATIONS_MAXIMUM_RESOLUTION = + // int64[4*n] + ACAMERA_SCALER_START + 21, + /** + *This lists the maximum stall duration for each + * output format/size combination when CaptureRequests are submitted with + * ACAMERA_SENSOR_PIXEL_MODE set to + * CameraMetadata#SENSOR_PIXEL_MODE_MAXIMUM_RESOLUTION
+ * + * @see ACAMERA_SENSOR_PIXEL_MODE + * + *Type: int64[4*n]
+ * + *This tag may appear in: + *
Analogous to ACAMERA_SCALER_AVAILABLE_MIN_FRAME_DURATIONS, for configurations + * which are applicable when ACAMERA_SENSOR_PIXEL_MODE is set to + * CameraMetadata#SENSOR_PIXEL_MODE_MAXIMUM_RESOLUTION.
+ * + * @see ACAMERA_SCALER_AVAILABLE_MIN_FRAME_DURATIONS + * @see ACAMERA_SENSOR_PIXEL_MODE + */ + ACAMERA_SCALER_AVAILABLE_STALL_DURATIONS_MAXIMUM_RESOLUTION = + // int64[4*n] + ACAMERA_SCALER_START + 22, + /** + *Whether the camera device supports multi-resolution input or output streams
+ * + *Type: byte (acamera_metadata_enum_android_scaler_multi_resolution_stream_supported_t)
+ * + *This tag may appear in: + *
A logical multi-camera or an ultra high resolution camera may support multi-resolution + * input or output streams. With multi-resolution output streams, the camera device is able + * to output different resolution images depending on the current active physical camera or + * pixel mode. With multi-resolution input streams, the camera device can reprocess images + * of different resolutions from different physical cameras or sensor pixel modes.
+ *When set to TRUE:
+ *The stream use cases supported by this camera device.
+ * + *Type: int64[n] (acamera_metadata_enum_android_scaler_available_stream_use_cases_t)
+ * + *This tag may appear in: + *
The stream use case indicates the purpose of a particular camera stream from + * the end-user perspective. Some examples of camera use cases are: preview stream for + * live viewfinder shown to the user, still capture for generating high quality photo + * capture, video record for encoding the camera output for the purpose of future playback, + * and video call for live realtime video conferencing.
+ *With this flag, the camera device can optimize the image processing pipeline + * parameters, such as tuning, sensor mode, and ISP settings, independent of + * the properties of the immediate camera output surface. For example, if the output + * surface is a SurfaceTexture, the stream use case flag can be used to indicate whether + * the camera frames eventually go to display, video encoder, + * still image capture, or all of them combined.
+ *The application sets the use case of a camera stream by calling + * OutputConfiguration#setStreamUseCase.
+ *A camera device with + * CameraCharacteristics#REQUEST_AVAILABLE_CAPABILITIES_STREAM_USE_CASE + * capability must support the following stream use cases:
+ *The guaranteed stream combinations related to stream use case for a camera device with + * CameraCharacteristics#REQUEST_AVAILABLE_CAPABILITIES_STREAM_USE_CASE + * capability is documented in the camera device + * guideline. The + * application is strongly recommended to use one of the guaranteed stream combinations. + * If the application creates a session with a stream combination not in the guaranteed + * list, or with mixed DEFAULT and non-DEFAULT use cases within the same session, + * the camera device may ignore some stream use cases due to hardware constraints + * and implementation details.
+ *For stream combinations not covered by the stream use case mandatory lists, such as + * reprocessable session, constrained high speed session, or RAW stream combinations, the + * application should leave stream use cases within the session as DEFAULT.
+ */ + ACAMERA_SCALER_AVAILABLE_STREAM_USE_CASES = // int64[n] (acamera_metadata_enum_android_scaler_available_stream_use_cases_t) + ACAMERA_SCALER_START + 25, ACAMERA_SCALER_END, /** @@ -4195,6 +4749,25 @@ typedef enum acamera_metadata_tag { * *Also defines the direction of rolling shutter readout, which is from top to bottom in * the sensor's coordinate system.
+ *Starting with Android API level 32, camera clients that query the orientation via + * CameraCharacteristics#get on foldable devices which + * include logical cameras can receive a value that can dynamically change depending on the + * device/fold state. + * Clients are advised to not cache or store the orientation value of such logical sensors. + * In case repeated queries to CameraCharacteristics are not preferred, then clients can + * also access the entire mapping from device state to sensor orientation in + * DeviceStateSensorOrientationMap. + * Do note that a dynamically changing sensor orientation value in camera characteristics + * will not be the best way to establish the orientation per frame. Clients that want to + * know the sensor orientation of a particular captured frame should query the + * ACAMERA_LOGICAL_MULTI_CAMERA_ACTIVE_PHYSICAL_ID from the corresponding capture result and + * check the respective physical camera orientation.
+ *Native camera clients must query ACAMERA_INFO_DEVICE_STATE_ORIENTATIONS for the mapping + * between device state and camera sensor orientation. Dynamic updates to the sensor + * orientation are not supported in this code path.
+ * + * @see ACAMERA_INFO_DEVICE_STATE_ORIENTATIONS + * @see ACAMERA_LOGICAL_MULTI_CAMERA_ACTIVE_PHYSICAL_ID */ ACAMERA_SENSOR_ORIENTATION = // int32 ACAMERA_SENSOR_START + 14, @@ -4275,7 +4848,7 @@ typedef enum acamera_metadata_tag { * noise model used here is: *N(x) = sqrt(Sx + O)
*Where x represents the recorded signal of a CFA channel normalized to - * the range [0, 1], and S and O are the noise model coeffiecients for + * the range [0, 1], and S and O are the noise model coefficients for * that channel.
*A more detailed description of the noise model can be found in the * Adobe DNG specification for the NoiseProfile tag.
@@ -4324,7 +4897,7 @@ typedef enum acamera_metadata_tag { *Starting from Android Q, this key will not be present for a MONOCHROME camera, even if * the camera device has RAW capability.
@@ -4527,6 +5100,67 @@ typedef enum acamera_metadata_tag { */ ACAMERA_SENSOR_DYNAMIC_WHITE_LEVEL = // int32 ACAMERA_SENSOR_START + 29, + /** + *Switches sensor pixel mode between maximum resolution mode and default mode.
+ * + *Type: byte (acamera_metadata_enum_android_sensor_pixel_mode_t)
+ * + *This tag may appear in: + *
This key controls whether the camera sensor operates in
+ * CameraMetadata#SENSOR_PIXEL_MODE_MAXIMUM_RESOLUTION
+ * mode or not. By default, all camera devices operate in
+ * CameraMetadata#SENSOR_PIXEL_MODE_DEFAULT mode.
+ * When operating in
+ * CameraMetadata#SENSOR_PIXEL_MODE_DEFAULT mode, sensors
+ * with CameraMetadata#REQUEST_AVAILABLE_CAPABILITIES_ULTRA_HIGH_RESOLUTION_SENSOR
+ * capability would typically perform pixel binning in order to improve low light
+ * performance, noise reduction etc. However, in
+ * CameraMetadata#SENSOR_PIXEL_MODE_MAXIMUM_RESOLUTION
+ * mode (supported only
+ * by CameraMetadata#REQUEST_AVAILABLE_CAPABILITIES_ULTRA_HIGH_RESOLUTION_SENSOR
+ * sensors), sensors typically operate in unbinned mode allowing for a larger image size.
+ * The stream configurations supported in
+ * CameraMetadata#SENSOR_PIXEL_MODE_MAXIMUM_RESOLUTION
+ * mode are also different from those of
+ * CameraMetadata#SENSOR_PIXEL_MODE_DEFAULT mode.
+ * They can be queried through
+ * CameraCharacteristics#get with
+ * CameraCharacteristics#SCALER_STREAM_CONFIGURATION_MAP_MAXIMUM_RESOLUTION).
+ * Unless reported by both
+ * StreamConfigurationMaps, the outputs from
+ * android.scaler.streamConfigurationMapMaximumResolution and
+ * android.scaler.streamConfigurationMap
+ * must not be mixed in the same CaptureRequest. In other words, these outputs are
+ * exclusive to each other.
+ * This key does not need to be set for reprocess requests.
Whether RAW images requested have their bayer pattern as described by
+ * ACAMERA_SENSOR_INFO_BINNING_FACTOR.
Type: byte (acamera_metadata_enum_android_sensor_raw_binning_factor_used_t)
+ * + *This tag may appear in: + *
This key will only be present in devices advertising the
+ * CameraMetadata#REQUEST_AVAILABLE_CAPABILITIES_ULTRA_HIGH_RESOLUTION_SENSOR
+ * capability which also advertise REMOSAIC_REPROCESSING capability. On all other devices
+ * RAW targets will have a regular bayer pattern.
E.g. to calculate position of a pixel, (x,y), in a processed YUV output image with the * dimensions in ACAMERA_SENSOR_INFO_ACTIVE_ARRAY_SIZE given the position of a pixel, - * (x', y'), in the raw pixel array with dimensions give in + * (x', y'), in the raw pixel array with dimensions given in * ACAMERA_SENSOR_INFO_PIXEL_ARRAY_SIZE:
*Quality of lens shading correction applied - * to the image data.
+ *The area of the image sensor which corresponds to active pixels after any geometric + * distortion correction has been applied, when the sensor runs in maximum resolution mode.
* - *Type: byte (acamera_metadata_enum_android_shading_mode_t)
+ *Type: int32[4]
* *This tag may appear in: *
When set to OFF mode, no lens shading correction will be applied by the
- * camera device, and an identity lens shading map data will be provided
- * if ACAMERA_STATISTICS_LENS_SHADING_MAP_MODE == ON. For example, for lens
- * shading map with size of [ 4, 3 ],
- * the output android.statistics.lensShadingCorrectionMap for this case will be an identity
- * map shown below:
[ 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0,
- * 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0,
- * 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0,
- * 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0,
- * 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0,
- * 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0 ]
- *
- * When set to other modes, lens shading correction will be applied by the camera - * device. Applications can request lens shading map data by setting - * ACAMERA_STATISTICS_LENS_SHADING_MAP_MODE to ON, and then the camera device will provide lens - * shading map data in android.statistics.lensShadingCorrectionMap; the returned shading map - * data will be the one applied by the camera device for this capture request.
- *The shading map data may depend on the auto-exposure (AE) and AWB statistics, therefore
- * the reliability of the map data may be affected by the AE and AWB algorithms. When AE and
- * AWB are in AUTO modes(ACAMERA_CONTROL_AE_MODE != OFF and ACAMERA_CONTROL_AWB_MODE !=
- * OFF), to get best results, it is recommended that the applications wait for the AE and AWB
- * to be converged before using the returned shading map data.
Analogous to ACAMERA_SENSOR_INFO_ACTIVE_ARRAY_SIZE, when ACAMERA_SENSOR_PIXEL_MODE + * is set to + * CameraMetadata#SENSOR_PIXEL_MODE_MAXIMUM_RESOLUTION. + * Refer to ACAMERA_SENSOR_INFO_ACTIVE_ARRAY_SIZE for details, with sensor array related keys + * replaced with their + * CameraMetadata#SENSOR_PIXEL_MODE_MAXIMUM_RESOLUTION + * counterparts. + * This key will only be present for devices which advertise the + * CameraMetadata#REQUEST_AVAILABLE_CAPABILITIES_ULTRA_HIGH_RESOLUTION_SENSOR + * capability.
+ *The data representation is int[4], which maps to (left, top, width, height).
List of lens shading modes for ACAMERA_SHADING_MODE that are supported by this camera device.
+ *Dimensions of the full pixel array, possibly + * including black calibration pixels, when the sensor runs in maximum resolution mode. + * Analogous to ACAMERA_SENSOR_INFO_PIXEL_ARRAY_SIZE, when ACAMERA_SENSOR_PIXEL_MODE is + * set to + * CameraMetadata#SENSOR_PIXEL_MODE_MAXIMUM_RESOLUTION.
* - * @see ACAMERA_SHADING_MODE + * @see ACAMERA_SENSOR_INFO_PIXEL_ARRAY_SIZE + * @see ACAMERA_SENSOR_PIXEL_MODE * - *Type: byte[n]
+ *Type: int32[2]
* *This tag may appear in: *
This list contains lens shading modes that can be set for the camera device. - * Camera devices that support the MANUAL_POST_PROCESSING capability will always - * list OFF and FAST mode. This includes all FULL level devices. - * LEGACY devices will always only support FAST mode.
- */ + *The pixel count of the full pixel array of the image sensor, which covers + * ACAMERA_SENSOR_INFO_PHYSICAL_SIZE area. This represents the full pixel dimensions of + * the raw buffers produced by this sensor, when it runs in maximum resolution mode. That + * is, when ACAMERA_SENSOR_PIXEL_MODE is set to + * CameraMetadata#SENSOR_PIXEL_MODE_MAXIMUM_RESOLUTION. + * This key will only be present for devices which advertise the + * CameraMetadata#REQUEST_AVAILABLE_CAPABILITIES_ULTRA_HIGH_RESOLUTION_SENSOR + * capability.
+ * + * @see ACAMERA_SENSOR_INFO_PHYSICAL_SIZE + * @see ACAMERA_SENSOR_PIXEL_MODE + */ + ACAMERA_SENSOR_INFO_PIXEL_ARRAY_SIZE_MAXIMUM_RESOLUTION = // int32[2] + ACAMERA_SENSOR_INFO_START + 12, + /** + *The area of the image sensor which corresponds to active pixels prior to the + * application of any geometric distortion correction, when the sensor runs in maximum + * resolution mode. This key must be used for crop / metering regions, only when + * ACAMERA_SENSOR_PIXEL_MODE is set to + * CameraMetadata#SENSOR_PIXEL_MODE_MAXIMUM_RESOLUTION.
+ * + * @see ACAMERA_SENSOR_PIXEL_MODE + * + *Type: int32[4]
+ * + *This tag may appear in: + *
Analogous to ACAMERA_SENSOR_INFO_PRE_CORRECTION_ACTIVE_ARRAY_SIZE, + * when ACAMERA_SENSOR_PIXEL_MODE is set to + * CameraMetadata#SENSOR_PIXEL_MODE_MAXIMUM_RESOLUTION. + * This key will only be present for devices which advertise the + * CameraMetadata#REQUEST_AVAILABLE_CAPABILITIES_ULTRA_HIGH_RESOLUTION_SENSOR + * capability.
+ *The data representation is int[4], which maps to (left, top, width, height).
Dimensions of the group of pixels which are under the same color filter. + * This specifies the width and height (pair of integers) of the group of pixels which fall + * under the same color filter for ULTRA_HIGH_RESOLUTION sensors.
+ * + *Type: int32[2]
+ * + *This tag may appear in: + *
Sensors can have pixels grouped together under the same color filter in order + * to improve various aspects of imaging such as noise reduction, low light + * performance etc. These groups can be of various sizes such as 2X2 (quad bayer), + * 3X3 (nona-bayer). This key specifies the length and width of the pixels grouped under + * the same color filter.
+ *This key will not be present if REMOSAIC_REPROCESSING is not supported, since RAW images + * will have a regular bayer pattern.
+ *This key will not be present for sensors which don't have the + * CameraMetadata#REQUEST_AVAILABLE_CAPABILITIES_ULTRA_HIGH_RESOLUTION_SENSOR + * capability.
+ */ + ACAMERA_SENSOR_INFO_BINNING_FACTOR = // int32[2] + ACAMERA_SENSOR_INFO_START + 14, + ACAMERA_SENSOR_INFO_END, + + /** + *Quality of lens shading correction applied + * to the image data.
+ * + *Type: byte (acamera_metadata_enum_android_shading_mode_t)
+ * + *This tag may appear in: + *
When set to OFF mode, no lens shading correction will be applied by the
+ * camera device, and an identity lens shading map data will be provided
+ * if ACAMERA_STATISTICS_LENS_SHADING_MAP_MODE == ON. For example, for lens
+ * shading map with size of [ 4, 3 ],
+ * the output android.statistics.lensShadingCorrectionMap for this case will be an identity
+ * map shown below:
[ 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0,
+ * 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0,
+ * 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0,
+ * 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0,
+ * 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0,
+ * 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0 ]
+ *
+ * When set to other modes, lens shading correction will be applied by the camera + * device. Applications can request lens shading map data by setting + * ACAMERA_STATISTICS_LENS_SHADING_MAP_MODE to ON, and then the camera device will provide lens + * shading map data in android.statistics.lensShadingCorrectionMap; the returned shading map + * data will be the one applied by the camera device for this capture request.
+ *The shading map data may depend on the auto-exposure (AE) and AWB statistics, therefore
+ * the reliability of the map data may be affected by the AE and AWB algorithms. When AE and
+ * AWB are in AUTO modes(ACAMERA_CONTROL_AE_MODE != OFF and ACAMERA_CONTROL_AWB_MODE !=
+ * OFF), to get best results, it is recommended that the applications wait for the AE and AWB
+ * to be converged before using the returned shading map data.
List of lens shading modes for ACAMERA_SHADING_MODE that are supported by this camera device.
+ * + * @see ACAMERA_SHADING_MODE + * + *Type: byte[n]
+ * + *This tag may appear in: + *
This list contains lens shading modes that can be set for the camera device. + * Camera devices that support the MANUAL_POST_PROCESSING capability will always + * list OFF and FAST mode. This includes all FULL level devices. + * LEGACY devices will always only support FAST mode.
+ */ ACAMERA_SHADING_AVAILABLE_MODES = // byte[n] ACAMERA_SHADING_START + 2, ACAMERA_SHADING_END, @@ -5228,7 +5976,7 @@ typedef enum acamera_metadata_tag { *Since optical image stabilization generally involves motion much faster than the duration - * of individualq image exposure, multiple OIS samples can be included for a single capture + * of individual image exposure, multiple OIS samples can be included for a single capture * result. For example, if the OIS reporting operates at 200 Hz, a typical camera operating * at 30fps may have 6-7 OIS samples per capture result. This information can be combined * with the rolling shutter skew to account for lens motion during image exposure in @@ -5591,9 +6339,11 @@ typedef enum acamera_metadata_tag { *
The tonemap curve will be defined the following formula: - * * OUT = pow(IN, 1.0 / gamma) - * where IN and OUT is the input pixel value scaled to range [0.0, 1.0], + *
The tonemap curve will be defined the following formula:
+ *where IN and OUT is the input pixel value scaled to range [0.0, 1.0], * pow is the power function and gamma is the gamma value specified by this * key.
*The same curve will be applied to all color channels. The camera device @@ -5726,6 +6476,21 @@ typedef enum acamera_metadata_tag { */ ACAMERA_INFO_VERSION = // byte ACAMERA_INFO_START + 1, + /** + * + *
Type: int64[2*n]
+ * + *This tag may appear in: + *
HAL must populate the array with + * (hardware::camera::provider::V2_5::DeviceState, sensorOrientation) pairs for each + * supported device state bitwise combination.
+ */ + ACAMERA_INFO_DEVICE_STATE_ORIENTATIONS = // int64[2*n] + ACAMERA_INFO_START + 3, ACAMERA_INFO_END, /** @@ -6033,6 +6798,162 @@ typedef enum acamera_metadata_tag { */ ACAMERA_DEPTH_AVAILABLE_DYNAMIC_DEPTH_STALL_DURATIONS = // int64[4*n] ACAMERA_DEPTH_START + 8, + /** + *The available depth dataspace stream + * configurations that this camera device supports + * (i.e. format, width, height, output/input stream) when a CaptureRequest is submitted with + * ACAMERA_SENSOR_PIXEL_MODE set to + * CameraMetadata#SENSOR_PIXEL_MODE_MAXIMUM_RESOLUTION.
+ * + * @see ACAMERA_SENSOR_PIXEL_MODE + * + *Type: int32[n*4] (acamera_metadata_enum_android_depth_available_depth_stream_configurations_maximum_resolution_t)
+ * + *This tag may appear in: + *
Analogous to ACAMERA_DEPTH_AVAILABLE_DEPTH_STREAM_CONFIGURATIONS, for configurations which + * are applicable when ACAMERA_SENSOR_PIXEL_MODE is set to + * CameraMetadata#SENSOR_PIXEL_MODE_MAXIMUM_RESOLUTION.
+ * + * @see ACAMERA_DEPTH_AVAILABLE_DEPTH_STREAM_CONFIGURATIONS + * @see ACAMERA_SENSOR_PIXEL_MODE + */ + ACAMERA_DEPTH_AVAILABLE_DEPTH_STREAM_CONFIGURATIONS_MAXIMUM_RESOLUTION = + // int32[n*4] (acamera_metadata_enum_android_depth_available_depth_stream_configurations_maximum_resolution_t) + ACAMERA_DEPTH_START + 9, + /** + *This lists the minimum frame duration for each + * format/size combination for depth output formats when a CaptureRequest is submitted with + * ACAMERA_SENSOR_PIXEL_MODE set to + * CameraMetadata#SENSOR_PIXEL_MODE_MAXIMUM_RESOLUTION.
+ * + * @see ACAMERA_SENSOR_PIXEL_MODE + * + *Type: int64[4*n]
+ * + *This tag may appear in: + *
Analogous to ACAMERA_DEPTH_AVAILABLE_DEPTH_MIN_FRAME_DURATIONS, for configurations which + * are applicable when ACAMERA_SENSOR_PIXEL_MODE is set to + * CameraMetadata#SENSOR_PIXEL_MODE_MAXIMUM_RESOLUTION.
+ *See ACAMERA_SENSOR_FRAME_DURATION and + * ACAMERA_SCALER_AVAILABLE_STALL_DURATIONS_MAXIMUM_RESOLUTION for more details about + * calculating the max frame rate.
+ * + * @see ACAMERA_DEPTH_AVAILABLE_DEPTH_MIN_FRAME_DURATIONS + * @see ACAMERA_SCALER_AVAILABLE_STALL_DURATIONS_MAXIMUM_RESOLUTION + * @see ACAMERA_SENSOR_FRAME_DURATION + * @see ACAMERA_SENSOR_PIXEL_MODE + */ + ACAMERA_DEPTH_AVAILABLE_DEPTH_MIN_FRAME_DURATIONS_MAXIMUM_RESOLUTION = + // int64[4*n] + ACAMERA_DEPTH_START + 10, + /** + *This lists the maximum stall duration for each + * output format/size combination for depth streams for CaptureRequests where + * ACAMERA_SENSOR_PIXEL_MODE is set to + * CameraMetadata#SENSOR_PIXEL_MODE_MAXIMUM_RESOLUTION.
+ * + * @see ACAMERA_SENSOR_PIXEL_MODE + * + *Type: int64[4*n]
+ * + *This tag may appear in: + *
Analogous to ACAMERA_DEPTH_AVAILABLE_DEPTH_STALL_DURATIONS, for configurations which + * are applicable when ACAMERA_SENSOR_PIXEL_MODE is set to + * CameraMetadata#SENSOR_PIXEL_MODE_MAXIMUM_RESOLUTION.
+ * + * @see ACAMERA_DEPTH_AVAILABLE_DEPTH_STALL_DURATIONS + * @see ACAMERA_SENSOR_PIXEL_MODE + */ + ACAMERA_DEPTH_AVAILABLE_DEPTH_STALL_DURATIONS_MAXIMUM_RESOLUTION = + // int64[4*n] + ACAMERA_DEPTH_START + 11, + /** + *The available dynamic depth dataspace stream + * configurations that this camera device supports (i.e. format, width, height, + * output/input stream) for CaptureRequests where ACAMERA_SENSOR_PIXEL_MODE is set to + * CameraMetadata#SENSOR_PIXEL_MODE_MAXIMUM_RESOLUTION.
+ * + * @see ACAMERA_SENSOR_PIXEL_MODE + * + *Type: int32[n*4] (acamera_metadata_enum_android_depth_available_dynamic_depth_stream_configurations_maximum_resolution_t)
+ * + *This tag may appear in: + *
Analogous to ACAMERA_DEPTH_AVAILABLE_DYNAMIC_DEPTH_STREAM_CONFIGURATIONS, for configurations + * which are applicable when ACAMERA_SENSOR_PIXEL_MODE is set to + * CameraMetadata#SENSOR_PIXEL_MODE_MAXIMUM_RESOLUTION.
+ * + * @see ACAMERA_DEPTH_AVAILABLE_DYNAMIC_DEPTH_STREAM_CONFIGURATIONS + * @see ACAMERA_SENSOR_PIXEL_MODE + */ + ACAMERA_DEPTH_AVAILABLE_DYNAMIC_DEPTH_STREAM_CONFIGURATIONS_MAXIMUM_RESOLUTION = + // int32[n*4] (acamera_metadata_enum_android_depth_available_dynamic_depth_stream_configurations_maximum_resolution_t) + ACAMERA_DEPTH_START + 12, + /** + *This lists the minimum frame duration for each + * format/size combination for dynamic depth output streams for CaptureRequests where + * ACAMERA_SENSOR_PIXEL_MODE is set to + * CameraMetadata#SENSOR_PIXEL_MODE_MAXIMUM_RESOLUTION.
+ * + * @see ACAMERA_SENSOR_PIXEL_MODE + * + *Type: int64[4*n]
+ * + *This tag may appear in: + *
Analogous to ACAMERA_DEPTH_AVAILABLE_DYNAMIC_DEPTH_MIN_FRAME_DURATIONS, for configurations + * which are applicable when ACAMERA_SENSOR_PIXEL_MODE is set to + * CameraMetadata#SENSOR_PIXEL_MODE_MAXIMUM_RESOLUTION.
+ * + * @see ACAMERA_DEPTH_AVAILABLE_DYNAMIC_DEPTH_MIN_FRAME_DURATIONS + * @see ACAMERA_SENSOR_PIXEL_MODE + */ + ACAMERA_DEPTH_AVAILABLE_DYNAMIC_DEPTH_MIN_FRAME_DURATIONS_MAXIMUM_RESOLUTION = + // int64[4*n] + ACAMERA_DEPTH_START + 13, + /** + *This lists the maximum stall duration for each + * output format/size combination for dynamic depth streams for CaptureRequests where + * ACAMERA_SENSOR_PIXEL_MODE is set to + * CameraMetadata#SENSOR_PIXEL_MODE_MAXIMUM_RESOLUTION.
+ * + * @see ACAMERA_SENSOR_PIXEL_MODE + * + *Type: int64[4*n]
+ * + *This tag may appear in: + *
Analogous to ACAMERA_DEPTH_AVAILABLE_DYNAMIC_DEPTH_STALL_DURATIONS, for configurations + * which are applicable when ACAMERA_SENSOR_PIXEL_MODE is set to + * CameraMetadata#SENSOR_PIXEL_MODE_MAXIMUM_RESOLUTION.
+ * + * @see ACAMERA_DEPTH_AVAILABLE_DYNAMIC_DEPTH_STALL_DURATIONS + * @see ACAMERA_SENSOR_PIXEL_MODE + */ + ACAMERA_DEPTH_AVAILABLE_DYNAMIC_DEPTH_STALL_DURATIONS_MAXIMUM_RESOLUTION = + // int64[4*n] + ACAMERA_DEPTH_START + 14, ACAMERA_DEPTH_END, /** @@ -6253,8 +7174,154 @@ typedef enum acamera_metadata_tag { */ ACAMERA_HEIC_AVAILABLE_HEIC_STALL_DURATIONS = // int64[4*n] ACAMERA_HEIC_START + 2, + /** + *The available HEIC (ISO/IEC 23008-12) stream + * configurations that this camera device supports + * (i.e. format, width, height, output/input stream).
+ * + *Type: int32[n*4] (acamera_metadata_enum_android_heic_available_heic_stream_configurations_maximum_resolution_t)
+ * + *This tag may appear in: + *
Refer to ACAMERA_HEIC_AVAILABLE_HEIC_STREAM_CONFIGURATIONS for details.
+ *All the configuration tuples (format, width, height, input?) will contain
+ * AIMAGE_FORMAT_HEIC format as OUTPUT only.
This lists the minimum frame duration for each + * format/size combination for HEIC output formats for CaptureRequests where + * ACAMERA_SENSOR_PIXEL_MODE is set to + * CameraMetadata#SENSOR_PIXEL_MODE_MAXIMUM_RESOLUTION.
+ * + * @see ACAMERA_SENSOR_PIXEL_MODE + * + *Type: int64[4*n]
+ * + *This tag may appear in: + *
Refer to ACAMERA_HEIC_AVAILABLE_HEIC_MIN_FRAME_DURATIONS for details.
+ * + * @see ACAMERA_HEIC_AVAILABLE_HEIC_MIN_FRAME_DURATIONS + */ + ACAMERA_HEIC_AVAILABLE_HEIC_MIN_FRAME_DURATIONS_MAXIMUM_RESOLUTION = + // int64[4*n] + ACAMERA_HEIC_START + 4, + /** + *This lists the maximum stall duration for each + * output format/size combination for HEIC streams for CaptureRequests where + * ACAMERA_SENSOR_PIXEL_MODE is set to + * CameraMetadata#SENSOR_PIXEL_MODE_MAXIMUM_RESOLUTION.
+ * + * @see ACAMERA_SENSOR_PIXEL_MODE + * + *Type: int64[4*n]
+ * + *This tag may appear in: + *
Refer to ACAMERA_HEIC_AVAILABLE_HEIC_STALL_DURATIONS for details.
+ * + * @see ACAMERA_HEIC_AVAILABLE_HEIC_STALL_DURATIONS + */ + ACAMERA_HEIC_AVAILABLE_HEIC_STALL_DURATIONS_MAXIMUM_RESOLUTION = + // int64[4*n] + ACAMERA_HEIC_START + 5, ACAMERA_HEIC_END, + /** + *Location of the cameras on the automotive devices.
+ * + *Type: byte (acamera_metadata_enum_android_automotive_location_t)
+ * + *This tag may appear in: + *
This enum defines the locations of the cameras relative to the vehicle body frame on + * the automotive sensor coordinate system. + * If the system has FEATURE_AUTOMOTIVE, the camera will have this entry in its static + * metadata.
+ *Each side of the vehicle body frame on this coordinate system is defined as below:
+ *If the camera has either EXTERIOR_OTHER or EXTRA_OTHER, its static metadata will list + * the following entries, so that applications can determine the camera's exact location:
+ *The direction of the camera faces relative to the vehicle body frame and the + * passenger seats.
+ * + *Type: byte[n] (acamera_metadata_enum_android_automotive_lens_facing_t)
+ * + *This tag may appear in: + *
This enum defines the lens facing characteristic of the cameras on the automotive + * devices with locations ACAMERA_AUTOMOTIVE_LOCATION defines. If the system has + * FEATURE_AUTOMOTIVE, the camera will have this entry in its static metadata.
+ *When ACAMERA_AUTOMOTIVE_LOCATION is INTERIOR, this has one or more INTERIOR_* + * values or a single EXTERIOR_* value. When this has more than one INTERIOR_*, + * the first value must be the one for the seat closest to the optical axis. If this + * contains INTERIOR_OTHER, all other values will be ineffective.
+ *When ACAMERA_AUTOMOTIVE_LOCATION is EXTERIOR_* or EXTRA, this has a single + * EXTERIOR_* value.
+ *If a camera has INTERIOR_OTHER or EXTERIOR_OTHER, or more than one camera is at the + * same location and facing the same direction, their static metadata will list the + * following entries, so that applications can determine their lenses' exact facing + * directions:
+ *Preview stabilization, where the preview in addition to all other non-RAW streams are + * stabilized with the same quality of stabilization, is enabled. This mode aims to give + * clients a 'what you see is what you get' effect. In this mode, the FoV reduction will + * be a maximum of 20 % both horizontally and vertically + * (10% from left, right, top, bottom) for the given zoom ratio / crop region. + * The resultant FoV will also be the same across all processed streams + * (that have the same aspect ratio).
+ */ + ACAMERA_CONTROL_VIDEO_STABILIZATION_MODE_PREVIEW_STABILIZATION = 2, + } acamera_metadata_enum_android_control_video_stabilization_mode_t; // ACAMERA_CONTROL_AE_STATE @@ -7636,6 +8714,14 @@ typedef enum acamera_metadata_enum_acamera_lens_pose_reference { */ ACAMERA_LENS_POSE_REFERENCE_UNDEFINED = 2, + /** + *The value of ACAMERA_LENS_POSE_TRANSLATION is relative to the origin of the + * automotive sensor coordinate system, which is at the center of the rear axle.
+ * + * @see ACAMERA_LENS_POSE_TRANSLATION + */ + ACAMERA_LENS_POSE_REFERENCE_AUTOMOTIVE = 3, + } acamera_metadata_enum_android_lens_pose_reference_t; @@ -7949,7 +9035,7 @@ typedef enum acamera_metadata_enum_acamera_request_available_capabilities { * for the largest YUV_420_888 size. *If the device supports the {@link AIMAGE_FORMAT_RAW10 }, {@link AIMAGE_FORMAT_RAW12 }, {@link AIMAGE_FORMAT_Y8 }, then those can also be * captured at the same rate as the maximum-size YUV_420_888 resolution is.
- *In addition, the ACAMERA_SYNC_MAX_LATENCY field is guaranted to have a value between 0 + *
In addition, the ACAMERA_SYNC_MAX_LATENCY field is guaranteed to have a value between 0
* and 4, inclusive. ACAMERA_CONTROL_AE_LOCK_AVAILABLE and ACAMERA_CONTROL_AWB_LOCK_AVAILABLE
* are also guaranteed to be true so burst capture with these two locks ON yields
* consistent image output.
Even if the underlying physical cameras have different RAW characteristics (such as - * size or CFA pattern), a logical camera can still advertise RAW capability. In this - * case, when the application configures a RAW stream, the camera device will make sure - * the active physical camera will remain active to ensure consistent RAW output - * behavior, and not switch to other physical cameras.
+ *For a logical camera, typically the underlying physical cameras have different RAW + * capabilities (such as resolution or CFA pattern). There are two ways for the + * application to capture RAW images from the logical camera:
+ *The capture request and result metadata tags required for backward compatible camera - * functionalities will be solely based on the logical camera capabiltity. On the other + * functionalities will be solely based on the logical camera capability. On the other * hand, the use of manual capture controls (sensor or post-processing) with a * logical camera may result in unexpected behavior when the HAL decides to switch * between physical cameras with different characteristics under the hood. For example, @@ -8203,8 +9304,151 @@ typedef enum acamera_metadata_enum_acamera_request_available_capabilities { */ ACAMERA_REQUEST_AVAILABLE_CAPABILITIES_SYSTEM_CAMERA = 14, + /** + *
This camera device is capable of producing ultra high resolution images in
+ * addition to the image sizes described in the
+ * android.scaler.streamConfigurationMap.
+ * It can operate in 'default' mode and 'max resolution' mode. It generally does this
+ * by binning pixels in 'default' mode and not binning them in 'max resolution' mode.
+ * android.scaler.streamConfigurationMap describes the streams supported in 'default'
+ * mode.
+ * The stream configurations supported in 'max resolution' mode are described by
+ * android.scaler.streamConfigurationMapMaximumResolution.
+ * The maximum resolution mode pixel array size of a camera device
+ * (ACAMERA_SENSOR_INFO_PIXEL_ARRAY_SIZE) with this capability,
+ * will be at least 24 megapixels.
The camera device supports selecting a per-stream use case via + * OutputConfiguration#setStreamUseCase + * so that the device can optimize camera pipeline parameters such as tuning, sensor + * mode, or ISP settings for a specific user scenario. + * Some sample usages of this capability are:
+ *This capability requires the camera device to support the following + * stream use cases:
+ *CameraCharacteristics#SCALER_AVAILABLE_STREAM_USE_CASES + * lists all of the supported stream use cases.
+ *Refer to CameraDevice#createCaptureSession for the + * mandatory stream combinations involving stream use cases, which can also be queried + * via MandatoryStreamCombination.
+ */ + ACAMERA_REQUEST_AVAILABLE_CAPABILITIES_STREAM_USE_CASE = 19, + } acamera_metadata_enum_android_request_available_capabilities_t; +// ACAMERA_REQUEST_AVAILABLE_DYNAMIC_RANGE_PROFILES_MAP +typedef enum acamera_metadata_enum_acamera_request_available_dynamic_range_profiles_map { + /** + *8-bit SDR profile which is the default for all non 10-bit output capable devices.
+ */ + ACAMERA_REQUEST_AVAILABLE_DYNAMIC_RANGE_PROFILES_MAP_STANDARD = 0x1, + + /** + *10-bit pixel samples encoded using the Hybrid log-gamma transfer function.
+ */ + ACAMERA_REQUEST_AVAILABLE_DYNAMIC_RANGE_PROFILES_MAP_HLG10 = 0x2, + + /** + *10-bit pixel samples encoded using the SMPTE ST 2084 transfer function. + * This profile utilizes internal static metadata to increase the quality + * of the capture.
+ */ + ACAMERA_REQUEST_AVAILABLE_DYNAMIC_RANGE_PROFILES_MAP_HDR10 = 0x4, + + /** + *10-bit pixel samples encoded using the SMPTE ST 2084 transfer function. + * In contrast to HDR10, this profile uses internal per-frame metadata + * to further enhance the quality of the capture.
+ */ + ACAMERA_REQUEST_AVAILABLE_DYNAMIC_RANGE_PROFILES_MAP_HDR10_PLUS = 0x8, + + /** + *This is a camera mode for Dolby Vision capture optimized for a more scene + * accurate capture. This would typically differ from what a specific device + * might want to tune for a consumer optimized Dolby Vision general capture.
+ */ + ACAMERA_REQUEST_AVAILABLE_DYNAMIC_RANGE_PROFILES_MAP_DOLBY_VISION_10B_HDR_REF + = 0x10, + + /** + *This is the power optimized mode for 10-bit Dolby Vision HDR Reference Mode.
+ */ + ACAMERA_REQUEST_AVAILABLE_DYNAMIC_RANGE_PROFILES_MAP_DOLBY_VISION_10B_HDR_REF_PO + = 0x20, + + /** + *This is the camera mode for the default Dolby Vision capture mode for the + * specific device. This would be tuned by each specific device for consumer + * pleasing results that resonate with their particular audience. We expect + * that each specific device would have a different look for their default + * Dolby Vision capture.
+ */ + ACAMERA_REQUEST_AVAILABLE_DYNAMIC_RANGE_PROFILES_MAP_DOLBY_VISION_10B_HDR_OEM + = 0x40, + + /** + *This is the power optimized mode for 10-bit Dolby Vision HDR device specific + * capture Mode.
+ */ + ACAMERA_REQUEST_AVAILABLE_DYNAMIC_RANGE_PROFILES_MAP_DOLBY_VISION_10B_HDR_OEM_PO + = 0x80, + + /** + *This is the 8-bit version of the Dolby Vision reference capture mode optimized + * for scene accuracy.
+ */ + ACAMERA_REQUEST_AVAILABLE_DYNAMIC_RANGE_PROFILES_MAP_DOLBY_VISION_8B_HDR_REF + = 0x100, + + /** + *This is the power optimized mode for 8-bit Dolby Vision HDR Reference Mode.
+ */ + ACAMERA_REQUEST_AVAILABLE_DYNAMIC_RANGE_PROFILES_MAP_DOLBY_VISION_8B_HDR_REF_PO + = 0x200, + + /** + *This is the 8-bit version of device specific tuned and optimized Dolby Vision + * capture mode.
+ */ + ACAMERA_REQUEST_AVAILABLE_DYNAMIC_RANGE_PROFILES_MAP_DOLBY_VISION_8B_HDR_OEM + = 0x400, + + /** + *This is the power optimized mode for 8-bit Dolby Vision HDR device specific + * capture Mode.
+ */ + ACAMERA_REQUEST_AVAILABLE_DYNAMIC_RANGE_PROFILES_MAP_DOLBY_VISION_8B_HDR_OEM_PO + = 0x800, + + /** + * + */ + ACAMERA_REQUEST_AVAILABLE_DYNAMIC_RANGE_PROFILES_MAP_MAX = 0x1000, + +} acamera_metadata_enum_android_request_available_dynamic_range_profiles_map_t; + // ACAMERA_SCALER_AVAILABLE_STREAM_CONFIGURATIONS typedef enum acamera_metadata_enum_acamera_scaler_available_stream_configurations { @@ -8295,6 +9539,20 @@ typedef enum acamera_metadata_enum_acamera_scaler_available_recommended_stream_c ACAMERA_SCALER_AVAILABLE_RECOMMENDED_STREAM_CONFIGURATIONS_PUBLIC_END = 0x7, + /** + *If supported, the recommended 10-bit output stream configurations must include + * a subset of the advertised ImageFormat#YCBCR_P010 and + * ImageFormat#PRIVATE outputs that are optimized for power + * and performance when registered along with a supported 10-bit dynamic range profile. + * see android.hardware.camera2.params.OutputConfiguration#setDynamicRangeProfile for + * details.
+ */ + ACAMERA_SCALER_AVAILABLE_RECOMMENDED_STREAM_CONFIGURATIONS_10BIT_OUTPUT + = 0x8, + + ACAMERA_SCALER_AVAILABLE_RECOMMENDED_STREAM_CONFIGURATIONS_PUBLIC_END_3_8 + = 0x9, + /** *Vendor defined use cases. These depend on the vendor implementation.
*/ @@ -8303,6 +9561,149 @@ typedef enum acamera_metadata_enum_acamera_scaler_available_recommended_stream_c } acamera_metadata_enum_android_scaler_available_recommended_stream_configurations_t; +// ACAMERA_SCALER_ROTATE_AND_CROP +typedef enum acamera_metadata_enum_acamera_scaler_rotate_and_crop { + /** + *No rotate and crop is applied. Processed outputs are in the sensor orientation.
+ */ + ACAMERA_SCALER_ROTATE_AND_CROP_NONE = 0, + + /** + *Processed images are rotated by 90 degrees clockwise, and then cropped + * to the original aspect ratio.
+ */ + ACAMERA_SCALER_ROTATE_AND_CROP_90 = 1, + + /** + *Processed images are rotated by 180 degrees. Since the aspect ratio does not + * change, no cropping is performed.
+ */ + ACAMERA_SCALER_ROTATE_AND_CROP_180 = 2, + + /** + *Processed images are rotated by 270 degrees clockwise, and then cropped + * to the original aspect ratio.
+ */ + ACAMERA_SCALER_ROTATE_AND_CROP_270 = 3, + + /** + *The camera API automatically selects the best concrete value for + * rotate-and-crop based on the application's support for resizability and the current + * multi-window mode.
+ *If the application does not support resizing but the display mode for its main
+ * Activity is not in a typical orientation, the camera API will set ROTATE_AND_CROP_90
+ * or some other supported rotation value, depending on device configuration,
+ * to ensure preview and captured images are correctly shown to the user. Otherwise,
+ * ROTATE_AND_CROP_NONE will be selected.
When a value other than NONE is selected, several metadata fields will also be parsed + * differently to ensure that coordinates are correctly handled for features like drawing + * face detection boxes or passing in tap-to-focus coordinates. The camera API will + * convert positions in the active array coordinate system to/from the cropped-and-rotated + * coordinate system to make the operation transparent for applications.
+ *No coordinate mapping will be done when the application selects a non-AUTO mode.
+ */ + ACAMERA_SCALER_ROTATE_AND_CROP_AUTO = 4, + +} acamera_metadata_enum_android_scaler_rotate_and_crop_t; + +// ACAMERA_SCALER_PHYSICAL_CAMERA_MULTI_RESOLUTION_STREAM_CONFIGURATIONS +typedef enum acamera_metadata_enum_acamera_scaler_physical_camera_multi_resolution_stream_configurations { + ACAMERA_SCALER_PHYSICAL_CAMERA_MULTI_RESOLUTION_STREAM_CONFIGURATIONS_OUTPUT + = 0, + + ACAMERA_SCALER_PHYSICAL_CAMERA_MULTI_RESOLUTION_STREAM_CONFIGURATIONS_INPUT + = 1, + +} acamera_metadata_enum_android_scaler_physical_camera_multi_resolution_stream_configurations_t; + +// ACAMERA_SCALER_AVAILABLE_STREAM_CONFIGURATIONS_MAXIMUM_RESOLUTION +typedef enum acamera_metadata_enum_acamera_scaler_available_stream_configurations_maximum_resolution { + ACAMERA_SCALER_AVAILABLE_STREAM_CONFIGURATIONS_MAXIMUM_RESOLUTION_OUTPUT + = 0, + + ACAMERA_SCALER_AVAILABLE_STREAM_CONFIGURATIONS_MAXIMUM_RESOLUTION_INPUT + = 1, + +} acamera_metadata_enum_android_scaler_available_stream_configurations_maximum_resolution_t; + +// ACAMERA_SCALER_MULTI_RESOLUTION_STREAM_SUPPORTED +typedef enum acamera_metadata_enum_acamera_scaler_multi_resolution_stream_supported { + ACAMERA_SCALER_MULTI_RESOLUTION_STREAM_SUPPORTED_FALSE = 0, + + ACAMERA_SCALER_MULTI_RESOLUTION_STREAM_SUPPORTED_TRUE = 1, + +} acamera_metadata_enum_android_scaler_multi_resolution_stream_supported_t; + +// ACAMERA_SCALER_AVAILABLE_STREAM_USE_CASES +typedef enum acamera_metadata_enum_acamera_scaler_available_stream_use_cases { + /** + *Default stream use case.
+ *This use case is the same as when the application doesn't set any use case for + * the stream. The camera device uses the properties of the output target, such as + * format, dataSpace, or surface class type, to optimize the image processing pipeline.
+ */ + ACAMERA_SCALER_AVAILABLE_STREAM_USE_CASES_DEFAULT = 0x0, + + /** + *Live stream shown to the user.
+ *Optimized for performance and usability as a viewfinder, but not necessarily for + * image quality. The output is not meant to be persisted as saved images or video.
+ *No stall if ACAMERA_CONTROL_* are set to FAST. There may be stall if + * they are set to HIGH_QUALITY. This use case has the same behavior as the + * default SurfaceView and SurfaceTexture targets. Additionally, this use case can be + * used for in-app image analysis.
+ */ + ACAMERA_SCALER_AVAILABLE_STREAM_USE_CASES_PREVIEW = 0x1, + + /** + *Still photo capture.
+ *Optimized for high-quality high-resolution capture, and not expected to maintain + * preview-like frame rates.
+ *The stream may have stalls regardless of whether ACAMERA_CONTROL_* is HIGH_QUALITY. + * This use case has the same behavior as the default JPEG and RAW related formats.
+ */ + ACAMERA_SCALER_AVAILABLE_STREAM_USE_CASES_STILL_CAPTURE = 0x2, + + /** + *Recording video clips.
+ *Optimized for high-quality video capture, including high-quality image stabilization + * if supported by the device and enabled by the application. As a result, may produce + * output frames with a substantial lag from real time, to allow for highest-quality + * stabilization or other processing. As such, such an output is not suitable for drawing + * to screen directly, and is expected to be persisted to disk or similar for later + * playback or processing. Only streams that set the VIDEO_RECORD use case are guaranteed + * to have video stabilization applied when the video stabilization control is set + * to ON, as opposed to PREVIEW_STABILIZATION.
+ *This use case has the same behavior as the default MediaRecorder and MediaCodec + * targets.
+ */ + ACAMERA_SCALER_AVAILABLE_STREAM_USE_CASES_VIDEO_RECORD = 0x3, + + /** + *One single stream used for combined purposes of preview, video, and still capture.
+ *For such multi-purpose streams, the camera device aims to make the best tradeoff + * between the individual use cases. For example, the STILL_CAPTURE use case by itself + * may have stalls for achieving best image quality. But if combined with PREVIEW and + * VIDEO_RECORD, the camera device needs to trade off the additional image processing + * for speed so that preview and video recording aren't slowed down.
+ *Similarly, VIDEO_RECORD may produce frames with a substantial lag, but + * PREVIEW_VIDEO_STILL must have minimal output delay. This means that to enable video + * stabilization with this use case, the device must support and the app must select the + * PREVIEW_STABILIZATION mode for video stabilization.
+ */ + ACAMERA_SCALER_AVAILABLE_STREAM_USE_CASES_PREVIEW_VIDEO_STILL = 0x4, + + /** + *Long-running video call optimized for both power efficiency and video quality.
+ *The camera sensor may run in a lower-resolution mode to reduce power consumption + * at the cost of some image and digital zoom quality. Unlike VIDEO_RECORD, VIDEO_CALL + * outputs are expected to work in dark conditions, so are usually accompanied with + * variable frame rate settings to allow sufficient exposure time in low light.
+ */ + ACAMERA_SCALER_AVAILABLE_STREAM_USE_CASES_VIDEO_CALL = 0x5, + +} acamera_metadata_enum_android_scaler_available_stream_use_cases_t; + // ACAMERA_SENSOR_REFERENCE_ILLUMINANT1 typedef enum acamera_metadata_enum_acamera_sensor_reference_illuminant1 { @@ -8375,10 +9776,10 @@ typedef enum acamera_metadata_enum_acamera_sensor_test_pattern_mode { * respective color channel provided in * ACAMERA_SENSOR_TEST_PATTERN_DATA. *For example:
- *android.testPatternData = [0, 0xFFFFFFFF, 0xFFFFFFFF, 0]
+ * ACAMERA_SENSOR_TEST_PATTERN_DATA = [0, 0xFFFFFFFF, 0xFFFFFFFF, 0]
*
* All green pixels are 100% green. All red/blue pixels are black.
- * android.testPatternData = [0xFFFFFFFF, 0, 0xFFFFFFFF, 0]
+ * ACAMERA_SENSOR_TEST_PATTERN_DATA = [0xFFFFFFFF, 0, 0xFFFFFFFF, 0]
*
* All red pixels are 100% red. Only the odd green pixels
* are 100% green. All blue pixels are 100% black.
@@ -8461,6 +9862,42 @@ typedef enum acamera_metadata_enum_acamera_sensor_test_pattern_mode {
} acamera_metadata_enum_android_sensor_test_pattern_mode_t;
+// ACAMERA_SENSOR_PIXEL_MODE
+typedef enum acamera_metadata_enum_acamera_sensor_pixel_mode {
+ /**
+ * This is the default sensor pixel mode. This is the only sensor pixel mode
+ * supported unless a camera device advertises
+ * CameraMetadata#REQUEST_AVAILABLE_CAPABILITIES_ULTRA_HIGH_RESOLUTION_SENSOR.
+ */
+ ACAMERA_SENSOR_PIXEL_MODE_DEFAULT = 0,
+
+ /**
+ * This sensor pixel mode is offered by devices with capability
+ * CameraMetadata#REQUEST_AVAILABLE_CAPABILITIES_ULTRA_HIGH_RESOLUTION_SENSOR.
+ * In this mode, sensors typically do not bin pixels, as a result can offer larger
+ * image sizes.
+ */
+ ACAMERA_SENSOR_PIXEL_MODE_MAXIMUM_RESOLUTION = 1,
+
+} acamera_metadata_enum_android_sensor_pixel_mode_t;
+
+// ACAMERA_SENSOR_RAW_BINNING_FACTOR_USED
+typedef enum acamera_metadata_enum_acamera_sensor_raw_binning_factor_used {
+ /**
+ * The RAW targets in this capture have ACAMERA_SENSOR_INFO_BINNING_FACTOR as the
+ * bayer pattern.
+ *
+ * @see ACAMERA_SENSOR_INFO_BINNING_FACTOR
+ */
+ ACAMERA_SENSOR_RAW_BINNING_FACTOR_USED_TRUE = 0,
+
+ /**
+ * The RAW targets have a regular bayer pattern in this capture.
+ */
+ ACAMERA_SENSOR_RAW_BINNING_FACTOR_USED_FALSE = 1,
+
+} acamera_metadata_enum_android_sensor_raw_binning_factor_used_t;
+
// ACAMERA_SENSOR_INFO_COLOR_FILTER_ARRANGEMENT
typedef enum acamera_metadata_enum_acamera_sensor_info_color_filter_arrangement {
@@ -8684,7 +10121,7 @@ typedef enum acamera_metadata_enum_acamera_tonemap_mode {
ACAMERA_TONEMAP_MODE_HIGH_QUALITY = 2,
/**
- * Use the gamma value specified in ACAMERA_TONEMAP_GAMMA to peform
+ *
Use the gamma value specified in ACAMERA_TONEMAP_GAMMA to perform
* tonemapping.
* All color enhancement and tonemapping must be disabled, except
* for applying the tonemapping curve specified by ACAMERA_TONEMAP_GAMMA.
@@ -8696,7 +10133,7 @@ typedef enum acamera_metadata_enum_acamera_tonemap_mode {
/**
* Use the preset tonemapping curve specified in
- * ACAMERA_TONEMAP_PRESET_CURVE to peform tonemapping.
+ * ACAMERA_TONEMAP_PRESET_CURVE to perform tonemapping.
* All color enhancement and tonemapping must be disabled, except
* for applying the tonemapping curve specified by
* ACAMERA_TONEMAP_PRESET_CURVE.
@@ -8794,7 +10231,7 @@ typedef enum acamera_metadata_enum_acamera_info_supported_hardware_level {
* fire the flash for flash power metering during precapture, and then fire the flash
* for the final capture, if a flash is available on the device and the AE mode is set to
* enable the flash.
- * Devices that initially shipped with Android version Q or newer will not include any LEGACY-level devices.
+ * Devices that initially shipped with Android version Q or newer will not include any LEGACY-level devices.
*
* @see ACAMERA_CONTROL_AE_PRECAPTURE_TRIGGER
* @see ACAMERA_REQUEST_AVAILABLE_CAPABILITIES
@@ -8945,6 +10382,26 @@ typedef enum acamera_metadata_enum_acamera_depth_available_dynamic_depth_stream_
} acamera_metadata_enum_android_depth_available_dynamic_depth_stream_configurations_t;
+// ACAMERA_DEPTH_AVAILABLE_DEPTH_STREAM_CONFIGURATIONS_MAXIMUM_RESOLUTION
+typedef enum acamera_metadata_enum_acamera_depth_available_depth_stream_configurations_maximum_resolution {
+ ACAMERA_DEPTH_AVAILABLE_DEPTH_STREAM_CONFIGURATIONS_MAXIMUM_RESOLUTION_OUTPUT
+ = 0,
+
+ ACAMERA_DEPTH_AVAILABLE_DEPTH_STREAM_CONFIGURATIONS_MAXIMUM_RESOLUTION_INPUT
+ = 1,
+
+} acamera_metadata_enum_android_depth_available_depth_stream_configurations_maximum_resolution_t;
+
+// ACAMERA_DEPTH_AVAILABLE_DYNAMIC_DEPTH_STREAM_CONFIGURATIONS_MAXIMUM_RESOLUTION
+typedef enum acamera_metadata_enum_acamera_depth_available_dynamic_depth_stream_configurations_maximum_resolution {
+ ACAMERA_DEPTH_AVAILABLE_DYNAMIC_DEPTH_STREAM_CONFIGURATIONS_MAXIMUM_RESOLUTION_OUTPUT
+ = 0,
+
+ ACAMERA_DEPTH_AVAILABLE_DYNAMIC_DEPTH_STREAM_CONFIGURATIONS_MAXIMUM_RESOLUTION_INPUT
+ = 1,
+
+} acamera_metadata_enum_android_depth_available_dynamic_depth_stream_configurations_maximum_resolution_t;
+
// ACAMERA_LOGICAL_MULTI_CAMERA_SENSOR_SYNC_TYPE
typedef enum acamera_metadata_enum_acamera_logical_multi_camera_sensor_sync_type {
@@ -8996,9 +10453,179 @@ typedef enum acamera_metadata_enum_acamera_heic_available_heic_stream_configurat
} acamera_metadata_enum_android_heic_available_heic_stream_configurations_t;
+// ACAMERA_HEIC_AVAILABLE_HEIC_STREAM_CONFIGURATIONS_MAXIMUM_RESOLUTION
+typedef enum acamera_metadata_enum_acamera_heic_available_heic_stream_configurations_maximum_resolution {
+ ACAMERA_HEIC_AVAILABLE_HEIC_STREAM_CONFIGURATIONS_MAXIMUM_RESOLUTION_OUTPUT
+ = 0,
+
+ ACAMERA_HEIC_AVAILABLE_HEIC_STREAM_CONFIGURATIONS_MAXIMUM_RESOLUTION_INPUT
+ = 1,
+
+} acamera_metadata_enum_android_heic_available_heic_stream_configurations_maximum_resolution_t;
+
+
+
+// ACAMERA_AUTOMOTIVE_LOCATION
+typedef enum acamera_metadata_enum_acamera_automotive_location {
+ /**
+ * The camera device exists inside of the vehicle cabin.
+ */
+ ACAMERA_AUTOMOTIVE_LOCATION_INTERIOR = 0,
+
+ /**
+ * The camera exists outside of the vehicle body frame but not exactly on one of the
+ * exterior locations this enum defines. The applications should determine the exact
+ * location from ACAMERA_LENS_POSE_TRANSLATION.
+ *
+ * @see ACAMERA_LENS_POSE_TRANSLATION
+ */
+ ACAMERA_AUTOMOTIVE_LOCATION_EXTERIOR_OTHER = 1,
+
+ /**
+ * The camera device exists outside of the vehicle body frame and on its front side.
+ */
+ ACAMERA_AUTOMOTIVE_LOCATION_EXTERIOR_FRONT = 2,
+
+ /**
+ * The camera device exists outside of the vehicle body frame and on its rear side.
+ */
+ ACAMERA_AUTOMOTIVE_LOCATION_EXTERIOR_REAR = 3,
+
+ /**
+ * The camera device exists outside and on left side of the vehicle body frame.
+ */
+ ACAMERA_AUTOMOTIVE_LOCATION_EXTERIOR_LEFT = 4,
+
+ /**
+ * The camera device exists outside and on right side of the vehicle body frame.
+ */
+ ACAMERA_AUTOMOTIVE_LOCATION_EXTERIOR_RIGHT = 5,
+
+ /**
+ * The camera device exists on an extra vehicle, such as the trailer, but not exactly
+ * on one of front, rear, left, or right side. Applications should determine the exact
+ * location from ACAMERA_LENS_POSE_TRANSLATION.
+ *
+ * @see ACAMERA_LENS_POSE_TRANSLATION
+ */
+ ACAMERA_AUTOMOTIVE_LOCATION_EXTRA_OTHER = 6,
+
+ /**
+ * The camera device exists outside of the extra vehicle's body frame and on its front
+ * side.
+ */
+ ACAMERA_AUTOMOTIVE_LOCATION_EXTRA_FRONT = 7,
+
+ /**
+ * The camera device exists outside of the extra vehicle's body frame and on its rear
+ * side.
+ */
+ ACAMERA_AUTOMOTIVE_LOCATION_EXTRA_REAR = 8,
+
+ /**
+ * The camera device exists outside and on left side of the extra vehicle body.
+ */
+ ACAMERA_AUTOMOTIVE_LOCATION_EXTRA_LEFT = 9,
+
+ /**
+ * The camera device exists outside and on right side of the extra vehicle body.
+ */
+ ACAMERA_AUTOMOTIVE_LOCATION_EXTRA_RIGHT = 10,
+
+} acamera_metadata_enum_android_automotive_location_t;
+
+
+// ACAMERA_AUTOMOTIVE_LENS_FACING
+typedef enum acamera_metadata_enum_acamera_automotive_lens_facing {
+ /**
+ * The camera device faces the outside of the vehicle body frame but not exactly
+ * one of the exterior sides defined by this enum. Applications should determine
+ * the exact facing direction from ACAMERA_LENS_POSE_ROTATION and
+ * ACAMERA_LENS_POSE_TRANSLATION.
+ *
+ * @see ACAMERA_LENS_POSE_ROTATION
+ * @see ACAMERA_LENS_POSE_TRANSLATION
+ */
+ ACAMERA_AUTOMOTIVE_LENS_FACING_EXTERIOR_OTHER = 0,
+
+ /**
+ * The camera device faces the front of the vehicle body frame.
+ */
+ ACAMERA_AUTOMOTIVE_LENS_FACING_EXTERIOR_FRONT = 1,
+
+ /**
+ * The camera device faces the rear of the vehicle body frame.
+ */
+ ACAMERA_AUTOMOTIVE_LENS_FACING_EXTERIOR_REAR = 2,
+
+ /**
+ * The camera device faces the left side of the vehicle body frame.
+ */
+ ACAMERA_AUTOMOTIVE_LENS_FACING_EXTERIOR_LEFT = 3,
+
+ /**
+ * The camera device faces the right side of the vehicle body frame.
+ */
+ ACAMERA_AUTOMOTIVE_LENS_FACING_EXTERIOR_RIGHT = 4,
+
+ /**
+ * The camera device faces the inside of the vehicle body frame but not exactly
+ * one of seats described by this enum. Applications should determine the exact
+ * facing direction from ACAMERA_LENS_POSE_ROTATION and ACAMERA_LENS_POSE_TRANSLATION.
+ *
+ * @see ACAMERA_LENS_POSE_ROTATION
+ * @see ACAMERA_LENS_POSE_TRANSLATION
+ */
+ ACAMERA_AUTOMOTIVE_LENS_FACING_INTERIOR_OTHER = 5,
+
+ /**
+ * The camera device faces the left side seat of the first row.
+ */
+ ACAMERA_AUTOMOTIVE_LENS_FACING_INTERIOR_SEAT_ROW_1_LEFT = 6,
+
+ /**
+ * The camera device faces the center seat of the first row.
+ */
+ ACAMERA_AUTOMOTIVE_LENS_FACING_INTERIOR_SEAT_ROW_1_CENTER = 7,
+
+ /**
+ * The camera device faces the right seat of the first row.
+ */
+ ACAMERA_AUTOMOTIVE_LENS_FACING_INTERIOR_SEAT_ROW_1_RIGHT = 8,
+
+ /**
+ * The camera device faces the left side seat of the second row.
+ */
+ ACAMERA_AUTOMOTIVE_LENS_FACING_INTERIOR_SEAT_ROW_2_LEFT = 9,
+
+ /**
+ * The camera device faces the center seat of the second row.
+ */
+ ACAMERA_AUTOMOTIVE_LENS_FACING_INTERIOR_SEAT_ROW_2_CENTER = 10,
+
+ /**
+ * The camera device faces the right side seat of the second row.
+ */
+ ACAMERA_AUTOMOTIVE_LENS_FACING_INTERIOR_SEAT_ROW_2_RIGHT = 11,
+
+ /**
+ * The camera device faces the left side seat of the third row.
+ */
+ ACAMERA_AUTOMOTIVE_LENS_FACING_INTERIOR_SEAT_ROW_3_LEFT = 12,
+
+ /**
+ * The camera device faces the center seat of the third row.
+ */
+ ACAMERA_AUTOMOTIVE_LENS_FACING_INTERIOR_SEAT_ROW_3_CENTER = 13,
+
+ /**
+ * The camera device faces the right seat of the third row.
+ */
+ ACAMERA_AUTOMOTIVE_LENS_FACING_INTERIOR_SEAT_ROW_3_RIGHT = 14,
+
+} acamera_metadata_enum_android_automotive_lens_facing_t;
-#endif /* __ANDROID_API__ >= 24 */
__END_DECLS
diff --git a/camera/NdkCameraWindowType.h b/camera/NdkCameraWindowType.h
index 99f67e9..0838fba 100644
--- a/camera/NdkCameraWindowType.h
+++ b/camera/NdkCameraWindowType.h
@@ -44,10 +44,12 @@
*/
#ifdef __ANDROID_VNDK__
#include
-typedef native_handle_t ACameraWindowType;
+typedef const native_handle_t ACameraWindowType;
#else
#include
typedef ANativeWindow ACameraWindowType;
#endif
+/** @} */
+
#endif //_NDK_CAMERA_WINDOW_TYPE_H
diff --git a/camera/NdkCaptureRequest.h b/camera/NdkCaptureRequest.h
index d3f8826..d83c5b3 100644
--- a/camera/NdkCaptureRequest.h
+++ b/camera/NdkCaptureRequest.h
@@ -44,12 +44,10 @@
__BEGIN_DECLS
-#if __ANDROID_API__ >= 24
-
-// Container for output targets
+/** Container for output targets */
typedef struct ACameraOutputTargets ACameraOutputTargets;
-// Container for a single output target
+/** Container for a single output target */
typedef struct ACameraOutputTarget ACameraOutputTarget;
/**
@@ -304,10 +302,6 @@ camera_status_t ACaptureRequest_setEntry_rational(
*/
void ACaptureRequest_free(ACaptureRequest* request) __INTRODUCED_IN(24);
-#endif /* __ANDROID_API__ >= 24 */
-
-#if __ANDROID_API__ >= 28
-
/**
* Associate an arbitrary user context pointer to the {@link ACaptureRequest}
*
@@ -356,10 +350,6 @@ camera_status_t ACaptureRequest_getUserContext(
*/
ACaptureRequest* ACaptureRequest_copy(const ACaptureRequest* src) __INTRODUCED_IN(28);
-#endif /* __ANDROID_API__ >= 28 */
-
-#if __ANDROID_API__ >= 29
-
/**
* Get a metadata entry from input {@link ACaptureRequest} for
* a physical camera backing a logical multi-camera device.
@@ -393,10 +383,10 @@ camera_status_t ACaptureRequest_getConstEntry_physicalCamera(
* Set/change a camera capture control entry with unsigned 8 bits data type for
* a physical camera backing a logical multi-camera device.
*
- * Same as ACaptureRequest_setEntry_u8, except that if {@link tag} is contained
+ *
Same as ACaptureRequest_setEntry_u8, except that if tag is contained
* in {@link ACAMERA_REQUEST_AVAILABLE_PHYSICAL_CAMERA_REQUEST_KEYS}, this function
* sets the entry for a particular physical sub-camera backing the logical multi-camera.
- * If {@link tag} is not contained in
+ * If tag is not contained in
* {@link ACAMERA_REQUEST_AVAILABLE_PHYSICAL_CAMERA_REQUEST_KEYS}, the key will be ignored
* by the camera device.
*
@@ -423,10 +413,10 @@ camera_status_t ACaptureRequest_setEntry_physicalCamera_u8(
* Set/change a camera capture control entry with signed 32 bits data type for
* a physical camera of a logical multi-camera device.
*
- * Same as ACaptureRequest_setEntry_i32, except that if {@link tag} is contained
+ *
Same as ACaptureRequest_setEntry_i32, except that if tag is contained
* in {@link ACAMERA_REQUEST_AVAILABLE_PHYSICAL_CAMERA_REQUEST_KEYS}, this function
* sets the entry for a particular physical sub-camera backing the logical multi-camera.
- * If {@link tag} is not contained in
+ * If tag is not contained in
* {@link ACAMERA_REQUEST_AVAILABLE_PHYSICAL_CAMERA_REQUEST_KEYS}, the key will be ignored
* by the camera device.
*
@@ -453,10 +443,10 @@ camera_status_t ACaptureRequest_setEntry_physicalCamera_i32(
* Set/change a camera capture control entry with float data type for
* a physical camera of a logical multi-camera device.
*
- * Same as ACaptureRequest_setEntry_float, except that if {@link tag} is contained
+ *
Same as ACaptureRequest_setEntry_float, except that if tag is contained
* in {@link ACAMERA_REQUEST_AVAILABLE_PHYSICAL_CAMERA_REQUEST_KEYS}, this function
* sets the entry for a particular physical sub-camera backing the logical multi-camera.
- * If {@link tag} is not contained in
+ * If tag is not contained in
* {@link ACAMERA_REQUEST_AVAILABLE_PHYSICAL_CAMERA_REQUEST_KEYS}, the key will be ignored
* by the camera device.
*
@@ -483,10 +473,10 @@ camera_status_t ACaptureRequest_setEntry_physicalCamera_float(
* Set/change a camera capture control entry with signed 64 bits data type for
* a physical camera of a logical multi-camera device.
*
- * Same as ACaptureRequest_setEntry_i64, except that if {@link tag} is contained
+ *
Same as ACaptureRequest_setEntry_i64, except that if tag is contained
* in {@link ACAMERA_REQUEST_AVAILABLE_PHYSICAL_CAMERA_REQUEST_KEYS}, this function
* sets the entry for a particular physical sub-camera backing the logical multi-camera.
- * If {@link tag} is not contained in
+ * If tag is not contained in
* {@link ACAMERA_REQUEST_AVAILABLE_PHYSICAL_CAMERA_REQUEST_KEYS}, the key will be ignored
* by the camera device.
*
@@ -513,10 +503,10 @@ camera_status_t ACaptureRequest_setEntry_physicalCamera_i64(
* Set/change a camera capture control entry with double data type for
* a physical camera of a logical multi-camera device.
*
- * Same as ACaptureRequest_setEntry_double, except that if {@link tag} is contained
+ *
Same as ACaptureRequest_setEntry_double, except that if tag is contained
* in {@link ACAMERA_REQUEST_AVAILABLE_PHYSICAL_CAMERA_REQUEST_KEYS}, this function
* sets the entry for a particular physical sub-camera backing the logical multi-camera.
- * If {@link tag} is not contained in
+ * If tag is not contained in
* {@link ACAMERA_REQUEST_AVAILABLE_PHYSICAL_CAMERA_REQUEST_KEYS}, the key will be ignored
* by the camera device.
*
@@ -543,10 +533,10 @@ camera_status_t ACaptureRequest_setEntry_physicalCamera_double(
* Set/change a camera capture control entry with rational data type for
* a physical camera of a logical multi-camera device.
*
- * Same as ACaptureRequest_setEntry_rational, except that if {@link tag} is contained
+ *
Same as ACaptureRequest_setEntry_rational, except that if tag is contained
* in {@link ACAMERA_REQUEST_AVAILABLE_PHYSICAL_CAMERA_REQUEST_KEYS}, this function
* sets the entry for a particular physical sub-camera backing the logical multi-camera.
- * If {@link tag} is not contained in
+ * If tag is not contained in
* {@link ACAMERA_REQUEST_AVAILABLE_PHYSICAL_CAMERA_REQUEST_KEYS}, the key will be ignored
* by the camera device.
*
@@ -569,8 +559,6 @@ camera_status_t ACaptureRequest_setEntry_physicalCamera_rational(
ACaptureRequest* request, const char* physicalId, uint32_t tag,
uint32_t count, const ACameraMetadata_rational* data) __INTRODUCED_IN(29);
-#endif /* __ANDROID_API__ >= 29 */
-
__END_DECLS
#endif /* _NDK_CAPTURE_REQUEST_H */
diff --git a/cutils/android_filesystem_config.h b/cutils/android_filesystem_config.h
index b73a29b..0030887 100644
--- a/cutils/android_filesystem_config.h
+++ b/cutils/android_filesystem_config.h
@@ -34,16 +34,9 @@
* partition, from which the system reads passwd and group files.
*/
-#ifndef _ANDROID_FILESYSTEM_CONFIG_H_
-#define _ANDROID_FILESYSTEM_CONFIG_H_
+#pragma once
-#include
-
-#if !defined(__ANDROID_VNDK__) && !defined(EXCLUDE_FS_CONFIG_STRUCTURES)
-#include
-#endif
-
-/* This is the master Users and Groups config for the platform.
+/* This is the main Users and Groups config for the platform.
* DO NOT EVER RENUMBER
*/
@@ -134,6 +127,18 @@
#define AID_EXT_DATA_RW 1078 /* GID for app-private data directories on external storage */
#define AID_EXT_OBB_RW 1079 /* GID for OBB directories on external storage */
#define AID_CONTEXT_HUB 1080 /* GID for access to the Context Hub */
+#define AID_VIRTUALIZATIONSERVICE 1081 /* VirtualizationService daemon */
+#define AID_ARTD 1082 /* ART Service daemon */
+#define AID_UWB 1083 /* UWB subsystem */
+#define AID_THREAD_NETWORK 1084 /* Thread Network subsystem */
+#define AID_DICED 1085 /* Android's DICE daemon */
+#define AID_DMESGD 1086 /* dmesg parsing daemon for kernel report collection */
+#define AID_JC_WEAVER 1087 /* Javacard Weaver HAL - to manage omapi ARA rules */
+#define AID_JC_STRONGBOX 1088 /* Javacard Strongbox HAL - to manage omapi ARA rules */
+#define AID_JC_IDENTITYCRED 1089 /* Javacard Identity Cred HAL - to manage omapi ARA rules */
+#define AID_SDK_SANDBOX 1090 /* SDK sandbox virtual UID */
+#define AID_SECURITY_LOG_WRITER 1091 /* write to security log */
+#define AID_PRNG_SEEDER 1092 /* PRNG seeder daemon */
/* Changes to this file must be made in AOSP, *not* in internal branches. */
#define AID_SHELL 2000 /* adb and debug shell user */
@@ -161,6 +166,7 @@
#define AID_READPROC 3009 /* Allow /proc read access */
#define AID_WAKELOCK 3010 /* Allow system wakelock read/write access */
#define AID_UHID 3011 /* Allow read/write to /dev/uhid node */
+#define AID_READTRACEFS 3012 /* Allow tracefs read */
/* The range 5000-5999 is also reserved for vendor partition. */
#define AID_OEM_RESERVED_2_START 5000
@@ -210,6 +216,10 @@
*/
#define AID_OVERFLOWUID 65534 /* unmapped user in the user namespace */
+/* use the ranges below to determine whether a process is sdk sandbox */
+#define AID_SDK_SANDBOX_PROCESS_START 20000 /* start of uids allocated to sdk sandbox processes */
+#define AID_SDK_SANDBOX_PROCESS_END 29999 /* end of uids allocated to sdk sandbox processes */
+
/* use the ranges below to determine whether a process is isolated */
#define AID_ISOLATED_START 90000 /* start of uids for fully isolated sandboxed processes */
#define AID_ISOLATED_END 99999 /* end of uids for fully isolated sandboxed processes */
@@ -224,5 +234,3 @@
* documented at the top of this header file.
* Also see build/tools/fs_config for more details.
*/
-
-#endif
diff --git a/cutils/ashmem.h b/cutils/ashmem.h
index d80caa6..1913c1e 100644
--- a/cutils/ashmem.h
+++ b/cutils/ashmem.h
@@ -1,14 +1,20 @@
-/* cutils/ashmem.h
- **
- ** Copyright 2008 The Android Open Source Project
- **
- ** This file is dual licensed. It may be redistributed and/or modified
- ** under the terms of the Apache 2.0 License OR version 2 of the GNU
- ** General Public License.
+/*
+ * Copyright (C) 2008 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
*/
-#ifndef _CUTILS_ASHMEM_H
-#define _CUTILS_ASHMEM_H
+#pragma once
#include
@@ -30,5 +36,3 @@ int ashmem_get_size_region(int fd);
#ifdef __cplusplus
}
#endif
-
-#endif /* _CUTILS_ASHMEM_H */
diff --git a/cutils/list.h b/cutils/list.h
index dfdc53b..7eb8725 100644
--- a/cutils/list.h
+++ b/cutils/list.h
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2008-2013 The Android Open Source Project
+ * Copyright (C) 2008 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -14,8 +14,7 @@
* limitations under the License.
*/
-#ifndef _CUTILS_LIST_H_
-#define _CUTILS_LIST_H_
+#pragma once
#include
@@ -38,9 +37,6 @@ struct listnode
.prev = &(name), \
}
-#define list_for_each(node, list) \
- for ((node) = (list)->next; (node) != (list); (node) = (node)->next)
-
#define list_for_each_reverse(node, list) \
for ((node) = (list)->prev; (node) != (list); (node) = (node)->prev)
@@ -49,6 +45,10 @@ struct listnode
(node) != (list); \
(node) = (n), (n) = (node)->next)
+#define list_for_each(node, list) \
+ for (struct listnode* __n = ((node) = (list)->next)->next; (node) != (list); \
+ (node) = __n, __n = (node)->next)
+
static inline void list_init(struct listnode *node)
{
node->next = node;
@@ -84,5 +84,3 @@ static inline void list_remove(struct listnode *item)
#ifdef __cplusplus
};
#endif /* __cplusplus */
-
-#endif
diff --git a/cutils/multiuser.h b/cutils/multiuser.h
index 9a2305c..0575ccf 100644
--- a/cutils/multiuser.h
+++ b/cutils/multiuser.h
@@ -30,6 +30,8 @@ extern userid_t multiuser_get_user_id(uid_t uid);
extern appid_t multiuser_get_app_id(uid_t uid);
extern uid_t multiuser_get_uid(userid_t user_id, appid_t app_id);
+extern uid_t multiuser_get_sdk_sandbox_uid(userid_t user_id, appid_t app_id);
+extern uid_t multiuser_convert_sdk_sandbox_to_app_uid(uid_t uid);
extern gid_t multiuser_get_cache_gid(userid_t user_id, appid_t app_id);
extern gid_t multiuser_get_ext_gid(userid_t user_id, appid_t app_id);
diff --git a/cutils/properties.h b/cutils/properties.h
index d2e0871..78d8bc6 100644
--- a/cutils/properties.h
+++ b/cutils/properties.h
@@ -14,27 +14,30 @@
* limitations under the License.
*/
-#ifndef __CUTILS_PROPERTIES_H
-#define __CUTILS_PROPERTIES_H
+#pragma once
#include
#include
-#include
#include
+#if __has_include()
+#include
+#else
+#define PROP_VALUE_MAX 92
+#endif
+
#ifdef __cplusplus
extern "C" {
#endif
-/* System properties are *small* name value pairs managed by the
-** property service. If your data doesn't fit in the provided
-** space it is not appropriate for a system property.
-**
-** WARNING: system/bionic/include/sys/system_properties.h also defines
-** these, but with different names. (TODO: fix that)
-*/
-#define PROPERTY_KEY_MAX PROP_NAME_MAX
-#define PROPERTY_VALUE_MAX PROP_VALUE_MAX
+//
+// Deprecated.
+//
+// See for better API.
+//
+
+#define PROPERTY_KEY_MAX PROP_NAME_MAX
+#define PROPERTY_VALUE_MAX PROP_VALUE_MAX
/* property_get: returns the length of the value which will never be
** greater than PROPERTY_VALUE_MAX - 1 and will always be zero terminated.
@@ -146,5 +149,3 @@ int property_get(const char *key, char *value, const char *default_value) {
#ifdef __cplusplus
}
#endif
-
-#endif
diff --git a/cutils/qtaguid.h b/cutils/qtaguid.h
index 3f5e41f..a5ffb03 100644
--- a/cutils/qtaguid.h
+++ b/cutils/qtaguid.h
@@ -33,24 +33,6 @@ extern int qtaguid_tagSocket(int sockfd, int tag, uid_t uid);
*/
extern int qtaguid_untagSocket(int sockfd);
-/*
- * For the given uid, switch counter sets.
- * The kernel only keeps a limited number of sets.
- * 2 for now.
- */
-extern int qtaguid_setCounterSet(int counterSetNum, uid_t uid);
-
-/*
- * Delete all tag info that relates to the given tag an uid.
- * If the tag is 0, then ALL info about the uid is freed.
- * The delete data also affects active tagged sockets, which are
- * then untagged.
- * The calling process can only operate on its own tags.
- * Unless it is part of the happy AID_NET_BW_ACCT group.
- * In which case it can clobber everything.
- */
-extern int qtaguid_deleteTagData(int tag, uid_t uid);
-
/*
* Enable/disable qtaguid functionnality at a lower level.
* When pacified, the kernel will accept commands but do nothing.
diff --git a/cutils/threads.h b/cutils/threads.h
index ba4846e..0082c6c 100644
--- a/cutils/threads.h
+++ b/cutils/threads.h
@@ -14,15 +14,14 @@
* limitations under the License.
*/
-#ifndef _LIBS_CUTILS_THREADS_H
-#define _LIBS_CUTILS_THREADS_H
+#pragma once
#include
-#if !defined(_WIN32)
-#include
-#else
+#if defined(_WIN32)
#include
+#else
+#include
#endif
#ifdef __cplusplus
@@ -32,46 +31,10 @@ extern "C" {
//
// Deprecated: use android::base::GetThreadId instead, which doesn't truncate on Mac/Windows.
//
-
+#if !defined(__GLIBC__) || __GLIBC__ >= 2 && __GLIBC_MINOR__ < 32
extern pid_t gettid();
-
-//
-// Deprecated: use `_Thread_local` in C or `thread_local` in C++.
-//
-
-#if !defined(_WIN32)
-
-typedef struct {
- pthread_mutex_t lock;
- int has_tls;
- pthread_key_t tls;
-} thread_store_t;
-
-#define THREAD_STORE_INITIALIZER { PTHREAD_MUTEX_INITIALIZER, 0, 0 }
-
-#else // !defined(_WIN32)
-
-typedef struct {
- int lock_init;
- int has_tls;
- DWORD tls;
- CRITICAL_SECTION lock;
-} thread_store_t;
-
-#define THREAD_STORE_INITIALIZER { 0, 0, 0, {0, 0, 0, 0, 0, 0} }
-
-#endif // !defined(_WIN32)
-
-typedef void (*thread_store_destruct_t)(void* value);
-
-extern void* thread_store_get(thread_store_t* store);
-
-extern void thread_store_set(thread_store_t* store,
- void* value,
- thread_store_destruct_t destroy);
+#endif
#ifdef __cplusplus
}
#endif
-
-#endif /* _LIBS_CUTILS_THREADS_H */
diff --git a/cutils/trace.h b/cutils/trace.h
index c74ee3e..98ae0d4 100644
--- a/cutils/trace.h
+++ b/cutils/trace.h
@@ -75,7 +75,8 @@ __BEGIN_DECLS
#define ATRACE_TAG_AIDL (1<<24)
#define ATRACE_TAG_NNAPI (1<<25)
#define ATRACE_TAG_RRO (1<<26)
-#define ATRACE_TAG_LAST ATRACE_TAG_RRO
+#define ATRACE_TAG_THERMAL (1 << 27)
+#define ATRACE_TAG_LAST ATRACE_TAG_THERMAL
// Reserved for initialization.
#define ATRACE_TAG_NOT_READY (1ULL<<63)
@@ -102,14 +103,6 @@ void atrace_setup();
*/
void atrace_update_tags();
-/**
- * Set whether the process is debuggable. By default the process is not
- * considered debuggable. If the process is not debuggable then application-
- * level tracing is not allowed unless the ro.debuggable system property is
- * set to '1'.
- */
-void atrace_set_debuggable(bool debuggable);
-
/**
* Set whether tracing is enabled for the current process. This is used to
* prevent tracing within the Zygote process.
@@ -215,6 +208,71 @@ static inline void atrace_async_end(uint64_t tag, const char* name, int32_t cook
}
}
+/**
+ * Trace the beginning of an asynchronous event. In addition to the name and a
+ * cookie as in ATRACE_ASYNC_BEGIN/ATRACE_ASYNC_END, a track name argument is
+ * provided, which is the name of the row where this async event should be
+ * recorded. The track name, name, and cookie used to begin an event must be
+ * used to end it.
+ */
+#define ATRACE_ASYNC_FOR_TRACK_BEGIN(track_name, name, cookie) \
+ atrace_async_for_track_begin(ATRACE_TAG, track_name, name, cookie)
+static inline void atrace_async_for_track_begin(uint64_t tag, const char* track_name,
+ const char* name, int32_t cookie) {
+ if (CC_UNLIKELY(atrace_is_tag_enabled(tag))) {
+ void atrace_async_for_track_begin_body(const char*, const char*, int32_t);
+ atrace_async_for_track_begin_body(track_name, name, cookie);
+ }
+}
+
+/**
+ * Trace the end of an asynchronous event.
+ * This should correspond to a previous ATRACE_ASYNC_FOR_TRACK_BEGIN.
+ */
+#define ATRACE_ASYNC_FOR_TRACK_END(track_name, name, cookie) \
+ atrace_async_for_track_end(ATRACE_TAG, track_name, name, cookie)
+static inline void atrace_async_for_track_end(uint64_t tag, const char* track_name,
+ const char* name, int32_t cookie) {
+ if (CC_UNLIKELY(atrace_is_tag_enabled(tag))) {
+ void atrace_async_for_track_end_body(const char*, const char*, int32_t);
+ atrace_async_for_track_end_body(track_name, name, cookie);
+ }
+}
+
+/**
+ * Trace an instantaneous context. name is used to identify the context.
+ *
+ * An "instant" is an event with no defined duration. Visually is displayed like a single marker
+ * in the timeline (rather than a span, in the case of begin/end events).
+ *
+ * By default, instant events are added into a dedicated track that has the same name of the event.
+ * Use atrace_instant_for_track to put different instant events into the same timeline track/row.
+ */
+#define ATRACE_INSTANT(name) atrace_instant(ATRACE_TAG, name)
+static inline void atrace_instant(uint64_t tag, const char* name) {
+ if (CC_UNLIKELY(atrace_is_tag_enabled(tag))) {
+ void atrace_instant_body(const char*);
+ atrace_instant_body(name);
+ }
+}
+
+/**
+ * Trace an instantaneous context. name is used to identify the context.
+ * track_name is the name of the row where the event should be recorded.
+ *
+ * An "instant" is an event with no defined duration. Visually is displayed like a single marker
+ * in the timeline (rather than a span, in the case of begin/end events).
+ */
+#define ATRACE_INSTANT_FOR_TRACK(trackName, name) \
+ atrace_instant_for_track(ATRACE_TAG, trackName, name)
+static inline void atrace_instant_for_track(uint64_t tag, const char* track_name,
+ const char* name) {
+ if (CC_UNLIKELY(atrace_is_tag_enabled(tag))) {
+ void atrace_instant_for_track_body(const char*, const char*);
+ atrace_instant_for_track_body(track_name, name);
+ }
+}
+
/**
* Traces an integer counter value. name is used to identify the counter.
* This can be used to track how a value changes over time.
diff --git a/git-revisions.txt b/git-revisions.txt
index 07d56c0..87b9341 100644
--- a/git-revisions.txt
+++ b/git-revisions.txt
@@ -1,112 +1,142 @@
================================================
-bionic @ Sat Jun 6 16:00:47 EEST 2026
+bionic @ Sun Aug 23 15:27:35 CEST 2026
================================================
-+ cd /home/nekit/halium-11.0
++ cd /media/herrie/HaliumDisk/13.0
+ repo status bionic
+
+... A new version of repo (2.65) is available.
+... New version is available at: /media/herrie/HaliumDisk/13.0/.repo/repo/repo
+... The launcher is run from: /usr/bin/repo
+!!! The launcher is not writable. Please talk to your sysadmin or distro
+!!! to get an update installed.
+
nothing to commit (working directory clean)
-+ cd /home/nekit/halium-11.0/bionic
++ cd /media/herrie/HaliumDisk/13.0/bionic
+ git show-ref --head
-ecf6d056d329d737d4d3f38213d52e787c14035d HEAD
-3a003876ad043c5280e0fbb334e8d17c3d941bfc refs/remotes/github/lineage-18.1
-3a003876ad043c5280e0fbb334e8d17c3d941bfc refs/remotes/m/halium-11.0
+539b10df16647f3080e8e75c373e5ba53fc97e10 HEAD
+e0aac7df6f58138dae903b5d456c947a3f8092ea refs/remotes/github/lineage-20.0
+e0aac7df6f58138dae903b5d456c947a3f8092ea refs/remotes/m/halium-13.0
+ git remote -v
-github https://github.com/LineageOS/android_bionic (fetch)
-github https://github.com/LineageOS/android_bionic (push)
+github git@github.com:LineageOS/android_bionic (fetch)
+github git@github.com:LineageOS/android_bionic (push)
================================================
-hardware/libhardware @ Sat Jun 6 16:00:47 EEST 2026
+hardware/libhardware @ Sun Aug 23 15:27:35 CEST 2026
================================================
-+ cd /home/nekit/halium-11.0
++ cd /media/herrie/HaliumDisk/13.0
+ repo status hardware/libhardware
+
+... A new version of repo (2.65) is available.
+... New version is available at: /media/herrie/HaliumDisk/13.0/.repo/repo/repo
+... The launcher is run from: /usr/bin/repo
+!!! The launcher is not writable. Please talk to your sysadmin or distro
+!!! to get an update installed.
+
nothing to commit (working directory clean)
-+ cd /home/nekit/halium-11.0/hardware/libhardware
++ cd /media/herrie/HaliumDisk/13.0/hardware/libhardware
+ git show-ref --head
-4a374c17d502dd1d1628c8fe0065e908f39473b5 HEAD
-90e3ce2014c258736729a8da929f76d50dc19255 refs/remotes/github/lineage-18.1
-90e3ce2014c258736729a8da929f76d50dc19255 refs/remotes/m/halium-11.0
+cee335bc5cce6e50468eb131ea6cdebd0c47228c HEAD
+0eb202d7ebd7d2410eb2f62c908c0341964a4829 refs/remotes/github/lineage-20.0
+0eb202d7ebd7d2410eb2f62c908c0341964a4829 refs/remotes/m/halium-13.0
+ git remote -v
-github https://github.com/LineageOS/android_hardware_libhardware (fetch)
-github https://github.com/LineageOS/android_hardware_libhardware (push)
+github git@github.com:LineageOS/android_hardware_libhardware (fetch)
+github git@github.com:LineageOS/android_hardware_libhardware (push)
================================================
-hardware/libhardware_legacy @ Sat Jun 6 16:00:47 EEST 2026
+hardware/libhardware_legacy @ Sun Aug 23 15:27:35 CEST 2026
================================================
-+ cd /home/nekit/halium-11.0
++ cd /media/herrie/HaliumDisk/13.0
+ repo status hardware/libhardware_legacy
+
+... A new version of repo (2.65) is available.
+... New version is available at: /media/herrie/HaliumDisk/13.0/.repo/repo/repo
+... The launcher is run from: /usr/bin/repo
+!!! The launcher is not writable. Please talk to your sysadmin or distro
+!!! to get an update installed.
+
nothing to commit (working directory clean)
-+ cd /home/nekit/halium-11.0/hardware/libhardware_legacy
++ cd /media/herrie/HaliumDisk/13.0/hardware/libhardware_legacy
+ git show-ref --head
-22f705057482747bd4b7c5f3e9d60a12a4558257 HEAD
-3d8e91ff970ad955ad15632f47ceab4e97419041 refs/remotes/m/halium-11.0
-3d8e91ff970ad955ad15632f47ceab4e97419041 refs/tags/android-11.0.0_r46
+50d9f52f7a7d4c70f10d6a9dca9a1f83a16c85ca HEAD
+50d9f52f7a7d4c70f10d6a9dca9a1f83a16c85ca refs/remotes/github/lineage-20.0
+50d9f52f7a7d4c70f10d6a9dca9a1f83a16c85ca refs/remotes/m/halium-13.0
+ git remote -v
-aosp https://android.googlesource.com/platform/hardware/libhardware_legacy (fetch)
-aosp https://android.googlesource.com/platform/hardware/libhardware_legacy (push)
+github git@github.com:LineageOS/android_hardware_libhardware_legacy (fetch)
+github git@github.com:LineageOS/android_hardware_libhardware_legacy (push)
================================================
-system/core @ Sat Jun 6 16:00:47 EEST 2026
+system/core @ Sun Aug 23 15:27:35 CEST 2026
================================================
-+ cd /home/nekit/halium-11.0
++ cd /media/herrie/HaliumDisk/13.0
+ repo status system/core
+
+... A new version of repo (2.65) is available.
+... New version is available at: /media/herrie/HaliumDisk/13.0/.repo/repo/repo
+... The launcher is run from: /usr/bin/repo
+!!! The launcher is not writable. Please talk to your sysadmin or distro
+!!! to get an update installed.
+
nothing to commit (working directory clean)
-+ cd /home/nekit/halium-11.0/system/core
++ cd /media/herrie/HaliumDisk/13.0/system/core
+ git show-ref --head
-9177d014fa10fb636572e8379a13b4a042365c7b HEAD
-b5f8d6741cae769ef8390d44b77dca9708ccfa32 refs/remotes/github/lineage-18.1
-b5f8d6741cae769ef8390d44b77dca9708ccfa32 refs/remotes/m/halium-11.0
+d3f3ed3ecf31f5f50f46db8a701fa7336fe38f1d HEAD
+c0500ffe2cc283d61f1e3db1b2c979bfbd9beb8c refs/remotes/github/lineage-20.0
+c0500ffe2cc283d61f1e3db1b2c979bfbd9beb8c refs/remotes/m/halium-13.0
+ git remote -v
-github https://github.com/LineageOS/android_system_core (fetch)
-github https://github.com/LineageOS/android_system_core (push)
+github git@github.com:LineageOS/android_system_core (fetch)
+github git@github.com:LineageOS/android_system_core (push)
================================================
-system/media @ Sat Jun 6 16:00:47 EEST 2026
+system/media @ Sun Aug 23 15:27:35 CEST 2026
================================================
-+ cd /home/nekit/halium-11.0
++ cd /media/herrie/HaliumDisk/13.0
+ repo status system/media
+
+... A new version of repo (2.65) is available.
+... New version is available at: /media/herrie/HaliumDisk/13.0/.repo/repo/repo
+... The launcher is run from: /usr/bin/repo
+!!! The launcher is not writable. Please talk to your sysadmin or distro
+!!! to get an update installed.
+
nothing to commit (working directory clean)
-+ cd /home/nekit/halium-11.0/system/media
++ cd /media/herrie/HaliumDisk/13.0/system/media
+ git show-ref --head
-b432f63fcbf6fecb43631ac8ef0454fa770182a4 HEAD
-b432f63fcbf6fecb43631ac8ef0454fa770182a4 refs/remotes/github/lineage-18.1
-b432f63fcbf6fecb43631ac8ef0454fa770182a4 refs/remotes/m/halium-11.0
+41c2d1ab132fd5388d39418507263e77483fe987 HEAD
+41c2d1ab132fd5388d39418507263e77483fe987 refs/remotes/github/lineage-20.0
+41c2d1ab132fd5388d39418507263e77483fe987 refs/remotes/m/halium-13.0
+ git remote -v
-github https://github.com/LineageOS/android_system_media (fetch)
-github https://github.com/LineageOS/android_system_media (push)
+github git@github.com:LineageOS/android_system_media (fetch)
+github git@github.com:LineageOS/android_system_media (push)
================================================
-external/kernel-headers @ Sat Jun 6 16:00:47 EEST 2026
+external/kernel-headers @ Sun Aug 23 15:27:35 CEST 2026
================================================
-+ cd /home/nekit/halium-11.0
++ cd /media/herrie/HaliumDisk/13.0
+ repo status external/kernel-headers
+
+... A new version of repo (2.65) is available.
+... New version is available at: /media/herrie/HaliumDisk/13.0/.repo/repo/repo
+... The launcher is run from: /usr/bin/repo
+!!! The launcher is not writable. Please talk to your sysadmin or distro
+!!! to get an update installed.
+
nothing to commit (working directory clean)
-+ cd /home/nekit/halium-11.0/external/kernel-headers
++ cd /media/herrie/HaliumDisk/13.0/external/kernel-headers
+ git show-ref --head
-98de591de8a89211e0d97ce6da031ec142ee8b86 HEAD
-f88628cc2c0afb7a6a61f3c835d19179f00d6e16 refs/remotes/m/halium-11.0
-f88628cc2c0afb7a6a61f3c835d19179f00d6e16 refs/tags/android-11.0.0_r46
+954c396aab5c69b3f141bba3fea00ad054f52555 HEAD
+b79b9f30296c4c0690f549b0bef43b45d7666de9 refs/remotes/m/halium-13.0
+b79b9f30296c4c0690f549b0bef43b45d7666de9 refs/tags/android-13.0.0_r75
+ git remote -v
aosp https://android.googlesource.com/platform/external/kernel-headers (fetch)
aosp https://android.googlesource.com/platform/external/kernel-headers (push)
================================================
-external/libnfc-nxp @ Sat Jun 6 16:00:47 EEST 2026
+external/libnfc-nxp @ Sun Aug 23 15:27:35 CEST 2026
================================================
-+ cd /home/nekit/halium-11.0
-+ repo status external/libnfc-nxp
-nothing to commit (working directory clean)
-+ cd /home/nekit/halium-11.0/external/libnfc-nxp
-+ git show-ref --head
-e4fb0694ac4eb888f098598bd895587b71747ce5 HEAD
-e4fb0694ac4eb888f098598bd895587b71747ce5 refs/remotes/github/lineage-18.1
-e4fb0694ac4eb888f098598bd895587b71747ce5 refs/remotes/m/halium-11.0
-+ git remote -v
-github https://github.com/LineageOS/android_external_libnfc-nxp (fetch)
-github https://github.com/LineageOS/android_external_libnfc-nxp (push)
-
-
+WARNING: external/libnfc-nxp does not contain a Git repository
diff --git a/hardware/audio.h b/hardware/audio.h
index 536180d..daaa16f 100644
--- a/hardware/audio.h
+++ b/hardware/audio.h
@@ -30,12 +30,6 @@
#include
#include
-#ifdef __ARM_PCS_VFP
-#define FP_ATTRIB __attribute__((pcs("aapcs")))
-#else
-#define FP_ATTRIB
-#endif
-
__BEGIN_DECLS
/**
@@ -63,7 +57,8 @@ __BEGIN_DECLS
#define AUDIO_DEVICE_API_VERSION_2_0 HARDWARE_DEVICE_API_VERSION(2, 0)
#define AUDIO_DEVICE_API_VERSION_3_0 HARDWARE_DEVICE_API_VERSION(3, 0)
#define AUDIO_DEVICE_API_VERSION_3_1 HARDWARE_DEVICE_API_VERSION(3, 1)
-#define AUDIO_DEVICE_API_VERSION_CURRENT AUDIO_DEVICE_API_VERSION_3_1
+#define AUDIO_DEVICE_API_VERSION_3_2 HARDWARE_DEVICE_API_VERSION(3, 2)
+#define AUDIO_DEVICE_API_VERSION_CURRENT AUDIO_DEVICE_API_VERSION_3_2
/* Minimal audio HAL version supported by the audio framework */
#define AUDIO_DEVICE_API_VERSION_MIN AUDIO_DEVICE_API_VERSION_2_0
@@ -238,6 +233,24 @@ typedef struct sink_metadata {
struct record_track_metadata* tracks;
} sink_metadata_t;
+/* HAL version 3.2 and higher only. */
+typedef struct source_metadata_v7 {
+ size_t track_count;
+ /** Array of metadata of each track connected to this source. */
+ struct playback_track_metadata_v7* tracks;
+} source_metadata_v7_t;
+
+/* HAL version 3.2 and higher only. */
+typedef struct sink_metadata_v7 {
+ size_t track_count;
+ /** Array of metadata of each track connected to this sink. */
+ struct record_track_metadata_v7* tracks;
+} sink_metadata_v7_t;
+
+/** output stream callback method to indicate changes in supported latency modes */
+typedef void (*stream_latency_mode_callback_t)(
+ audio_latency_mode_t *modes, size_t num_modes, void *cookie);
+
/**
* audio_stream_out is the abstraction interface for the audio output hardware.
*
@@ -264,7 +277,7 @@ struct audio_stream_out {
* This method might produce multiple PCM outputs or hardware accelerated
* codecs, such as MP3 or AAC.
*/
- int (*set_volume)(struct audio_stream_out *stream, float left, float right) FP_ATTRIB;
+ int (*set_volume)(struct audio_stream_out *stream, float left, float right);
/**
* Write audio buffer to driver. Returns number of bytes written, or a
@@ -442,7 +455,150 @@ struct audio_stream_out {
int (*set_event_callback)(struct audio_stream_out *stream,
stream_event_callback_t callback,
void *cookie);
+
+ /**
+ * Called when the metadata of the stream's source has been changed.
+ * HAL version 3.2 and higher only.
+ * @param source_metadata Description of the audio that is played by the clients.
+ */
+ void (*update_source_metadata_v7)(struct audio_stream_out *stream,
+ const struct source_metadata_v7* source_metadata);
+
+ /**
+ * Returns the Dual Mono mode presentation setting.
+ *
+ * \param[in] stream the stream object.
+ * \param[out] mode current setting of Dual Mono mode.
+ *
+ * \return 0 if the position is successfully returned.
+ * -EINVAL if the arguments are invalid
+ * -ENOSYS if the function is not available
+ */
+ int (*get_dual_mono_mode)(struct audio_stream_out *stream, audio_dual_mono_mode_t *mode);
+
+ /**
+ * Sets the Dual Mono mode presentation on the output device.
+ *
+ * \param[in] stream the stream object.
+ * \param[in] mode selected Dual Mono mode.
+ *
+ * \return 0 in case of success.
+ * -EINVAL if the arguments are invalid
+ * -ENOSYS if the function is not available
+ */
+ int (*set_dual_mono_mode)(struct audio_stream_out *stream, const audio_dual_mono_mode_t mode);
+
+ /**
+ * Returns the Audio Description Mix level in dB.
+ *
+ * \param[in] stream the stream object.
+ * \param[out] leveldB the current Audio Description Mix Level in dB.
+ *
+ * \return 0 in case of success.
+ * -EINVAL if the arguments are invalid
+ * -ENOSYS if the function is not available
+ */
+ int (*get_audio_description_mix_level)(struct audio_stream_out *stream, float *leveldB);
+
+ /**
+ * Sets the Audio Description Mix level in dB.
+ *
+ * \param[in] stream the stream object.
+ * \param[in] leveldB Audio Description Mix Level in dB.
+ *
+ * \return 0 in case of success.
+ * -EINVAL if the arguments are invalid
+ * -ENOSYS if the function is not available
+ */
+ int (*set_audio_description_mix_level)(struct audio_stream_out *stream, const float leveldB);
+
+ /**
+ * Retrieves current playback rate parameters.
+ *
+ * \param[in] stream the stream object.
+ * \param[out] playbackRate current playback parameters.
+ *
+ * \return 0 in case of success.
+ * -EINVAL if the arguments are invalid
+ * -ENOSYS if the function is not available
+ */
+ int (*get_playback_rate_parameters)(struct audio_stream_out *stream,
+ audio_playback_rate_t *playbackRate);
+
+ /**
+ * Sets the playback rate parameters that control playback behavior.
+ *
+ * \param[in] stream the stream object.
+ * \param[in] playbackRate playback parameters.
+ *
+ * \return 0 in case of success.
+ * -EINVAL if the arguments are invalid
+ * -ENOSYS if the function is not available
+ */
+ int (*set_playback_rate_parameters)(struct audio_stream_out *stream,
+ const audio_playback_rate_t *playbackRate);
+
+ /**
+ * Indicates the requested latency mode for this output stream.
+ *
+ * The requested mode can be one of the modes returned by
+ * get_recommended_latency_modes().
+ *
+ * Support for this method is optional but mandated on specific spatial audio
+ * streams indicated by AUDIO_OUTPUT_FLAG_SPATIALIZER flag if they can be routed
+ * to a BT classic sink.
+ *
+ * \param[in] stream the stream object.
+ * \param[in] mode the requested latency mode.
+ * \return 0 in case of success.
+ * -EINVAL if the arguments are invalid
+ * -ENOSYS if the function is not available
+ */
+ int (*set_latency_mode)(struct audio_stream_out *stream, audio_latency_mode_t mode);
+
+ /**
+ * Indicates which latency modes are currently supported on this output stream.
+ * If the transport protocol (e.g Bluetooth A2DP) used by this output stream to reach
+ * the output device supports variable latency modes, the HAL indicates which
+ * modes are currently supported.
+ * The framework can then call setLatencyMode() with one of the supported modes to select
+ * the desired operation mode.
+ *
+ * Support for this method is optional but mandated on specific spatial audio
+ * streams indicated by AUDIO_OUTPUT_FLAG_SPATIALIZER flag if they can be routed
+ * to a BT classic sink.
+ *
+ * \return 0 in case of success.
+ * -EINVAL if the arguments are invalid
+ * -ENOSYS if the function is not available
+ * \param[in] stream the stream object.
+ * \param[out] modes the supported latency modes.
+ * \param[in/out] num_modes as input the maximum number of modes to return,
+ * as output the actual number of modes returned.
+ */
+ int (*get_recommended_latency_modes)(struct audio_stream_out *stream,
+ audio_latency_mode_t *modes, size_t *num_modes);
+
+ /**
+ * Set the callback interface for notifying changes in supported latency modes.
+ *
+ * Calling this method with a null pointer will result in clearing a previously set callback.
+ *
+ * Support for this method is optional but mandated on specific spatial audio
+ * streams indicated by AUDIO_OUTPUT_FLAG_SPATIALIZER flag if they can be routed
+ * to a BT classic sink.
+ *
+ * \param[in] stream the stream object.
+ * \param[in] callback the registered callback or null to unregister.
+ * \param[in] cookie the context to pass when calling the callback.
+ * \return 0 in case of success.
+ * -EINVAL if the arguments are invalid
+ * -ENOSYS if the function is not available
+ */
+ int (*set_latency_mode_callback)(struct audio_stream_out *stream,
+ stream_latency_mode_callback_t callback, void *cookie);
};
+
typedef struct audio_stream_out audio_stream_out_t;
struct audio_stream_in {
@@ -455,7 +611,7 @@ struct audio_stream_in {
/** set the input gain for the audio driver. This method is for
* for future use */
- int (*set_gain)(struct audio_stream_in *stream, float gain) FP_ATTRIB;
+ int (*set_gain)(struct audio_stream_in *stream, float gain);
/** Read audio buffer in from audio driver. Returns number of bytes read, or a
* negative status_t. If at least one frame was read prior to the error,
@@ -606,6 +762,14 @@ struct audio_stream_in {
*/
void (*update_sink_metadata)(struct audio_stream_in *stream,
const struct sink_metadata* sink_metadata);
+
+ /**
+ * Called when the metadata of the stream's sink has been changed.
+ * HAL version 3.2 and higher only.
+ * @param sink_metadata Description of the audio that is recorded by the clients.
+ */
+ void (*update_sink_metadata_v7)(struct audio_stream_in *stream,
+ const struct sink_metadata_v7* sink_metadata);
};
typedef struct audio_stream_in audio_stream_in_t;
@@ -700,14 +864,14 @@ struct audio_hw_device {
int (*init_check)(const struct audio_hw_device *dev);
/** set the audio volume of a voice call. Range is between 0.0 and 1.0 */
- int (*set_voice_volume)(struct audio_hw_device *dev, float volume) FP_ATTRIB;
+ int (*set_voice_volume)(struct audio_hw_device *dev, float volume);
/**
* set the audio volume for all audio activities other than voice call.
* Range between 0.0 and 1.0. If any value other than 0 is returned,
* the software mixer will emulate this capability.
*/
- int (*set_master_volume)(struct audio_hw_device *dev, float volume) FP_ATTRIB;
+ int (*set_master_volume)(struct audio_hw_device *dev, float volume);
/**
* Get the current master volume value for the HAL, if the HAL supports
@@ -716,7 +880,7 @@ struct audio_hw_device {
* the initial master volume across all HALs. HALs which do not support
* this method may leave it set to NULL.
*/
- int (*get_master_volume)(struct audio_hw_device *dev, float *volume) FP_ATTRIB;
+ int (*get_master_volume)(struct audio_hw_device *dev, float *volume);
/**
* set_mode is called when the audio mode changes. AUDIO_MODE_NORMAL mode
@@ -871,6 +1035,36 @@ struct audio_hw_device {
*/
int (*remove_device_effect)(struct audio_hw_device *dev,
audio_port_handle_t device, effect_handle_t effect);
+
+ /**
+ * Fills the list of supported attributes for a given audio port.
+ * As input, "port" contains the information (type, role, address etc...)
+ * needed by the HAL to identify the port.
+ * As output, "port" contains possible attributes (sampling rates, formats,
+ * channel masks, gain controllers...) for this port. The possible attributes
+ * are saved as audio profiles, which contains audio format and the supported
+ * sampling rates and channel masks.
+ */
+ int (*get_audio_port_v7)(struct audio_hw_device *dev,
+ struct audio_port_v7 *port);
+
+ /**
+ * Called when the state of the connection of an external device has been changed.
+ * The "port" parameter is only used as input and besides identifying the device
+ * port, also may contain additional information such as extra audio descriptors.
+ *
+ * HAL version 3.2 and higher only. If the HAL does not implement this method,
+ * it must leave the function entry as null, or return -ENOSYS. In this case
+ * the framework will use 'set_parameters', which can only pass the device address.
+ *
+ * @param dev the audio HAL device context.
+ * @param port device port identification and extra information.
+ * @param connected whether the external device is connected.
+ * @return retval operation completion status.
+ */
+ int (*set_device_connected_state_v7)(struct audio_hw_device *dev,
+ struct audio_port_v7 *port,
+ bool connected);
};
typedef struct audio_hw_device audio_hw_device_t;
diff --git a/hardware/audio_alsaops.h b/hardware/audio_alsaops.h
index 6a17a35..476c311 100644
--- a/hardware/audio_alsaops.h
+++ b/hardware/audio_alsaops.h
@@ -60,7 +60,7 @@ static inline enum pcm_format pcm_format_from_audio_format(audio_format_t format
case AUDIO_FORMAT_PCM_FLOAT: /* there is no equivalent for float */
default:
LOG_ALWAYS_FATAL("pcm_format_from_audio_format: invalid audio format %#x", format);
- return 0;
+ return PCM_FORMAT_INVALID; /* doesn't get here, assert called above */
}
}
@@ -94,7 +94,7 @@ static inline audio_format_t audio_format_from_pcm_format(enum pcm_format format
#endif
default:
LOG_ALWAYS_FATAL("audio_format_from_pcm_format: invalid pcm format %#x", format);
- return 0;
+ return AUDIO_FORMAT_INVALID; /* doesn't get here, assert called above */
}
}
diff --git a/hardware/audio_amplifier.h b/hardware/audio_amplifier.h
index 90a2127..4b6f634 100644
--- a/hardware/audio_amplifier.h
+++ b/hardware/audio_amplifier.h
@@ -132,6 +132,11 @@ typedef struct amplifier_device {
*/
int (*set_feedback)(struct amplifier_device *device,
void *adev, uint32_t devices, bool enable);
+
+ /**
+ * Amplifier calibration
+ */
+ int (*calibrate)(void *adev);
} amplifier_device_t;
typedef struct amplifier_module {
diff --git a/hardware/bluetooth.h b/hardware/bluetooth.h
index 3fe6aa8..95a0b6e 100644
--- a/hardware/bluetooth.h
+++ b/hardware/bluetooth.h
@@ -258,19 +258,26 @@ typedef struct
void *val;
} bt_property_t;
-/** Bluetooth Out Of Band data for bonding */
-typedef struct
-{
- uint8_t le_bt_dev_addr[7]; /* LE Bluetooth Device Address */
- uint8_t c192[16]; /* Simple Pairing Hash C-192 */
- uint8_t r192[16]; /* Simple Pairing Randomizer R-192 */
- uint8_t c256[16]; /* Simple Pairing Hash C-256 */
- uint8_t r256[16]; /* Simple Pairing Randomizer R-256 */
- uint8_t sm_tk[16]; /* Security Manager TK Value */
- uint8_t le_sc_c[16]; /* LE Secure Connections Confirmation Value */
- uint8_t le_sc_r[16]; /* LE Secure Connections Random Value */
-} bt_out_of_band_data_t;
-
+/** Represents the actual Out of Band data itself */
+typedef struct {
+ // Both
+ bool is_valid = false; /* Default to invalid data; force caller to verify */
+ uint8_t address[7]; /* Bluetooth Device Address (6) plus Address Type (1) */
+ uint8_t c[16]; /* Simple Pairing Hash C-192/256 (Classic or LE) */
+ uint8_t r[16]; /* Simple Pairing Randomizer R-192/256 (Classic or LE) */
+ uint8_t device_name[256]; /* Name of the device */
+
+ // Classic
+ uint8_t oob_data_length[2]; /* Classic only data Length. Value includes this
+ in length */
+ uint8_t class_of_device[2]; /* Class of Device (Classic or LE) */
+
+ // LE
+ uint8_t le_device_role; /* Supported and preferred role of device */
+ uint8_t sm_tk[16]; /* Security Manager TK Value (LE Only) */
+ uint8_t le_flags; /* LE Flags for discoverability and features */
+ uint8_t le_appearance[2]; /* For the appearance of the device */
+} bt_oob_data_t;
/** Bluetooth Device Type */
@@ -508,7 +515,8 @@ typedef struct {
/** Create Bluetooth Bond using out of band data */
int (*create_bond_out_of_band)(const RawAddress *bd_addr, int transport,
- const bt_out_of_band_data_t *oob_data);
+ const bt_oob_data_t *p192_data,
+ const bt_oob_data_t *p256_data);
/** Remove Bond */
int (*remove_bond)(const RawAddress *bd_addr);
diff --git a/hardware/boot_control.h b/hardware/boot_control.h
index 36a867d..abbf3f1 100644
--- a/hardware/boot_control.h
+++ b/hardware/boot_control.h
@@ -125,7 +125,14 @@ typedef struct boot_control_module {
*/
int (*isSlotMarkedSuccessful)(struct boot_control_module *module, unsigned slot);
- void* reserved[31];
+ /**
+ * Returns the active slot to boot into on the next boot. If
+ * setActiveBootSlot() has been called, the getter function should return
+ * the same slot as the one provided in the last setActiveBootSlot() call.
+ */
+ unsigned (*getActiveBootSlot)(struct boot_control_module *module);
+
+ void* reserved[30];
} boot_control_module_t;
diff --git a/hardware/keymaster0.h b/hardware/keymaster0.h
deleted file mode 100644
index 52ac64b..0000000
--- a/hardware/keymaster0.h
+++ /dev/null
@@ -1,149 +0,0 @@
-/*
- * Copyright (C) 2011 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#ifndef ANDROID_HARDWARE_KEYMASTER_0_H
-#define ANDROID_HARDWARE_KEYMASTER_0_H
-
-#include
-
-__BEGIN_DECLS
-
-/**
- * Keymaster0 device definition.
- */
-struct keymaster0_device {
- /**
- * Common methods of the keymaster device. This *must* be the first member of
- * keymaster0_device as users of this structure will cast a hw_device_t to
- * keymaster0_device pointer in contexts where it's known the hw_device_t references a
- * keymaster0_device.
- */
- struct hw_device_t common;
-
- /**
- * THIS IS DEPRECATED. Use the new "module_api_version" and "hal_api_version"
- * fields in the keymaster_module initialization instead.
- */
- uint32_t client_version;
-
- /**
- * See flags defined for keymaster0_device::flags in keymaster_common.h
- */
- uint32_t flags;
-
- void* context;
-
- /**
- * Generates a public and private key. The key-blob returned is opaque
- * and must subsequently provided for signing and verification.
- *
- * Returns: 0 on success or an error code less than 0.
- */
- int (*generate_keypair)(const struct keymaster0_device* dev,
- const keymaster_keypair_t key_type, const void* key_params,
- uint8_t** key_blob, size_t* key_blob_length);
-
- /**
- * Imports a public and private key pair. The imported keys will be in
- * PKCS#8 format with DER encoding (Java standard). The key-blob
- * returned is opaque and will be subsequently provided for signing
- * and verification.
- *
- * Returns: 0 on success or an error code less than 0.
- */
- int (*import_keypair)(const struct keymaster0_device* dev,
- const uint8_t* key, const size_t key_length,
- uint8_t** key_blob, size_t* key_blob_length);
-
- /**
- * Gets the public key part of a key pair. The public key must be in
- * X.509 format (Java standard) encoded byte array.
- *
- * Returns: 0 on success or an error code less than 0.
- * On error, x509_data should not be allocated.
- */
- int (*get_keypair_public)(const struct keymaster0_device* dev,
- const uint8_t* key_blob, const size_t key_blob_length,
- uint8_t** x509_data, size_t* x509_data_length);
-
- /**
- * Deletes the key pair associated with the key blob.
- *
- * This function is optional and should be set to NULL if it is not
- * implemented.
- *
- * Returns 0 on success or an error code less than 0.
- */
- int (*delete_keypair)(const struct keymaster0_device* dev,
- const uint8_t* key_blob, const size_t key_blob_length);
-
- /**
- * Deletes all keys in the hardware keystore. Used when keystore is
- * reset completely.
- *
- * This function is optional and should be set to NULL if it is not
- * implemented.
- *
- * Returns 0 on success or an error code less than 0.
- */
- int (*delete_all)(const struct keymaster0_device* dev);
-
- /**
- * Signs data using a key-blob generated before. This can use either
- * an asymmetric key or a secret key.
- *
- * Returns: 0 on success or an error code less than 0.
- */
- int (*sign_data)(const struct keymaster0_device* dev,
- const void* signing_params,
- const uint8_t* key_blob, const size_t key_blob_length,
- const uint8_t* data, const size_t data_length,
- uint8_t** signed_data, size_t* signed_data_length);
-
- /**
- * Verifies data signed with a key-blob. This can use either
- * an asymmetric key or a secret key.
- *
- * Returns: 0 on successful verification or an error code less than 0.
- */
- int (*verify_data)(const struct keymaster0_device* dev,
- const void* signing_params,
- const uint8_t* key_blob, const size_t key_blob_length,
- const uint8_t* signed_data, const size_t signed_data_length,
- const uint8_t* signature, const size_t signature_length);
-};
-typedef struct keymaster0_device keymaster0_device_t;
-
-
-/* Convenience API for opening and closing keymaster devices */
-
-static inline int keymaster0_open(const struct hw_module_t* module,
- keymaster0_device_t** device)
-{
- int rc = module->methods->open(module, KEYSTORE_KEYMASTER,
- TO_HW_DEVICE_T_OPEN(device));
-
- return rc;
-}
-
-static inline int keymaster0_close(keymaster0_device_t* device)
-{
- return device->common.close(&device->common);
-}
-
-__END_DECLS
-
-#endif // ANDROID_HARDWARE_KEYMASTER_0_H
diff --git a/hardware/keymaster_defs.h b/hardware/keymaster_defs.h
index 2fbfe46..930aceb 100644
--- a/hardware/keymaster_defs.h
+++ b/hardware/keymaster_defs.h
@@ -71,6 +71,7 @@ typedef enum {
KM_TAG_INCLUDE_UNIQUE_ID = KM_BOOL | 202, /* If true, attestation certificates for this key
* will contain an application-scoped and
* time-bounded device-unique ID. (keymaster2) */
+ KM_TAG_RSA_OAEP_MGF_DIGEST = KM_ENUM_REP | 203, /* keymaster_digest_t. */
/* Other hardware-enforced. */
KM_TAG_BLOB_USAGE_REQUIREMENTS = KM_ENUM | 301, /* keymaster_key_blob_usage_requirements_t */
@@ -94,6 +95,8 @@ typedef enum {
cryptographic operations with the key. */
KM_TAG_MAX_USES_PER_BOOT = KM_UINT | 404, /* Number of times the key can be used per
boot. */
+ KM_TAG_USAGE_COUNT_LIMIT = KM_UINT | 405, /* Number of cryptographic operations left
+ with the key.*/
/* User authentication */
KM_TAG_ALL_USERS = KM_BOOL | 500, /* Reserved for future use -- ignore */
@@ -115,8 +118,10 @@ typedef enum {
KM_TAG_ALLOW_WHILE_ON_BODY = KM_BOOL | 506, /* Allow key to be used after authentication timeout
* if device is still on-body (requires secure
* on-body sensor. */
+ KM_TAG_TRUSTED_USER_PRESENCE_REQUIRED = KM_BOOL | 507,/* Require test of user presence
+ * to use this key. */
KM_TAG_TRUSTED_CONFIRMATION_REQUIRED = KM_BOOL | 508, /* Require user confirmation through a
- * trusted UI to use this key */
+ * trusted UI to use this key. */
KM_TAG_UNLOCKED_DEVICE_REQUIRED = KM_BOOL | 509, /* Require the device screen to be unlocked if the
* key is used. */
@@ -162,10 +167,14 @@ typedef enum {
attestation */
KM_TAG_ATTESTATION_ID_MODEL = KM_BYTES | 717, /* Used to provide the device's model name to be
included in attestation */
- KM_TAG_DEVICE_UNIQUE_ATTESTATION = KM_BOOL | 720, /* Indicates StrongBox device-unique attestation
- is requested. */
+ KM_TAG_VENDOR_PATCHLEVEL = KM_UINT | 718, /* specifies the vendor image security patch
+ level with which the key may be used */
+ KM_TAG_BOOT_PATCHLEVEL = KM_UINT | 719, /* specifies the boot image (kernel) security
+ patch level with which the key may be used */
+ KM_TAG_DEVICE_UNIQUE_ATTESTATION = KM_BOOL | 720, /* Indicates StrongBox device-unique
+ attestation is requested. */
KM_TAG_IDENTITY_CREDENTIAL_KEY = KM_BOOL | 721, /* This is an identity credential key */
-
+ KM_TAG_STORAGE_KEY = KM_BOOL | 722, /* storage encryption key */
/* Tags used only to provide data to or receive data from operations */
KM_TAG_ASSOCIATED_DATA = KM_BYTES | 1000, /* Used to provide associated data for AEAD modes. */
@@ -177,8 +186,34 @@ typedef enum {
* bits. */
KM_TAG_RESET_SINCE_ID_ROTATION = KM_BOOL | 1004, /* Whether the device has beeen factory reset
- since the last unique ID rotation. Used for
- key attestation. */
+ since the last unique ID rotation. Used
+ for key attestation. */
+
+ KM_TAG_CONFIRMATION_TOKEN = KM_BYTES | 1005, /* used to deliver a cryptographic token
+ proving that the user confirmed a signing
+ request. */
+
+ KM_TAG_CERTIFICATE_SERIAL = KM_BIGNUM | 1006, /* The serial number that should be
+ set in the attestation certificate
+ to be generated. */
+
+ KM_TAG_CERTIFICATE_SUBJECT = KM_BYTES | 1007, /* A DER-encoded X.500 subject that should be
+ set in the attestation certificate
+ to be generated. */
+
+ KM_TAG_CERTIFICATE_NOT_BEFORE = KM_DATE | 1008, /* Epoch time in milliseconds of the start of
+ the to be generated certificate's validity.
+ The value should interpreted as too's
+ complement signed integer. Negative values
+ indicate dates before Jan 1970 */
+
+ KM_TAG_CERTIFICATE_NOT_AFTER = KM_DATE | 1009, /* Epoch time in milliseconds of the end of
+ the to be generated certificate's validity.
+ The value should interpreted as too's
+ complement signed integer. Negative values
+ indicate dates before Jan 1970 */
+ KM_TAG_MAX_BOOT_LEVEL = KM_UINT | 1010, /* Specifies a maximum boot level at which a key
+ should function. */
} keymaster_tag_t;
/**
@@ -269,6 +304,7 @@ typedef enum {
KM_EC_CURVE_P_256 = 1,
KM_EC_CURVE_P_384 = 2,
KM_EC_CURVE_P_521 = 3,
+ KM_EC_CURVE_CURVE_25519 = 4,
} keymaster_ec_curve_t;
/**
@@ -309,7 +345,8 @@ typedef enum {
KM_PURPOSE_VERIFY = 3, /* Usable with RSA, EC and HMAC keys. */
KM_PURPOSE_DERIVE_KEY = 4, /* Usable with EC keys. */
KM_PURPOSE_WRAP = 5, /* Usable with wrapped keys. */
-
+ KM_PURPOSE_AGREE_KEY = 6, /* Usable with EC keys. */
+ KM_PURPOSE_ATTEST_KEY = 7 /* Usabe with RSA and EC keys */
} keymaster_purpose_t;
typedef struct {
@@ -470,6 +507,13 @@ typedef enum {
KM_ERROR_EARLY_BOOT_ENDED = -73,
KM_ERROR_ATTESTATION_KEYS_NOT_PROVISIONED = -74,
KM_ERROR_ATTESTATION_IDS_NOT_PROVISIONED = -75,
+ KM_ERROR_INCOMPATIBLE_MGF_DIGEST = -78,
+ KM_ERROR_UNSUPPORTED_MGF_DIGEST = -79,
+ KM_ERROR_MISSING_NOT_BEFORE = -80,
+ KM_ERROR_MISSING_NOT_AFTER = -81,
+ KM_ERROR_MISSING_ISSUER_SUBJECT = -82,
+ KM_ERROR_INVALID_ISSUER_SUBJECT = -83,
+ KM_ERROR_BOOT_LEVEL_EXCEEDED = -84,
KM_ERROR_UNIMPLEMENTED = -100,
KM_ERROR_VERSION_MISMATCH = -101,
diff --git a/hardware/sensors-base.h b/hardware/sensors-base.h
index ef7eead..dbf99f5 100644
--- a/hardware/sensors-base.h
+++ b/hardware/sensors-base.h
@@ -52,6 +52,12 @@ enum {
SENSOR_TYPE_LOW_LATENCY_OFFBODY_DETECT = 34,
SENSOR_TYPE_ACCELEROMETER_UNCALIBRATED = 35,
SENSOR_TYPE_HINGE_ANGLE = 36,
+ SENSOR_TYPE_HEAD_TRACKER = 37,
+ SENSOR_TYPE_ACCELEROMETER_LIMITED_AXES = 38,
+ SENSOR_TYPE_GYROSCOPE_LIMITED_AXES = 39,
+ SENSOR_TYPE_ACCELEROMETER_LIMITED_AXES_UNCALIBRATED = 40,
+ SENSOR_TYPE_GYROSCOPE_LIMITED_AXES_UNCALIBRATED = 41,
+ SENSOR_TYPE_HEADING = 42,
SENSOR_TYPE_DEVICE_PRIVATE_BASE = 65536 /* 0x10000 */,
};
diff --git a/hardware/sensors.h b/hardware/sensors.h
index a03a409..6f4baf8 100644
--- a/hardware/sensors.h
+++ b/hardware/sensors.h
@@ -186,6 +186,12 @@ enum {
#define SENSOR_STRING_TYPE_LOW_LATENCY_OFFBODY_DETECT "android.sensor.low_latency_offbody_detect"
#define SENSOR_STRING_TYPE_ACCELEROMETER_UNCALIBRATED "android.sensor.accelerometer_uncalibrated"
#define SENSOR_STRING_TYPE_HINGE_ANGLE "android.sensor.hinge_angle"
+#define SENSOR_STRING_TYPE_HEAD_TRACKER "android.sensor.head_tracker"
+#define SENSOR_STRING_TYPE_ACCELEROMETER_LIMITED_AXES "android.sensor.accelerometer_limited_axes"
+#define SENSOR_STRING_TYPE_GYROSCOPE_LIMITED_AXES "android.sensor.gyroscope_limited_axes"
+#define SENSOR_STRING_TYPE_ACCELEROMETER_LIMITED_AXES_UNCALIBRATED "android.sensor.accelerometer_limited_axes_uncalibrated"
+#define SENSOR_STRING_TYPE_GYROSCOPE_LIMITED_AXES_UNCALIBRATED "android.sensor.gyroscope_limited_axes_uncalibrated"
+#define SENSOR_STRING_TYPE_HEADING "android.sensor.heading"
/**
* Values returned by the accelerometer in various locations in the universe.
@@ -291,6 +297,76 @@ typedef struct {
};
} additional_info_event_t;
+typedef struct {
+ float rx;
+ float ry;
+ float rz;
+ float vx;
+ float vy;
+ float vz;
+ int32_t discontinuity_count;
+} head_tracker_event_t;
+
+/**
+ * limited axes imu event data
+ */
+typedef struct {
+ union {
+ float calib[3];
+ struct {
+ float x;
+ float y;
+ float z;
+ };
+ };
+ union {
+ float supported[3];
+ struct {
+ float x_supported;
+ float y_supported;
+ float z_supported;
+ };
+ };
+} limited_axes_imu_event_t;
+
+/**
+ * limited axes uncalibrated imu event data
+ */
+typedef struct {
+ union {
+ float uncalib[3];
+ struct {
+ float x_uncalib;
+ float y_uncalib;
+ float z_uncalib;
+ };
+ };
+ union {
+ float bias[3];
+ struct {
+ float x_bias;
+ float y_bias;
+ float z_bias;
+ };
+ };
+ union {
+ float supported[3];
+ struct {
+ float x_supported;
+ float y_supported;
+ float z_supported;
+ };
+ };
+} limited_axes_imu_uncalibrated_event_t;
+
+/**
+ * Heading event data
+ */
+typedef struct {
+ float heading;
+ float accuracy;
+} heading_event_t;
+
/**
* Union of the various types of sensor data
* that can be returned.
@@ -368,6 +444,26 @@ typedef struct sensors_event_t {
* SENSOR_TYPE_ADDITIONAL_INFO for details.
*/
additional_info_event_t additional_info;
+
+ /* vector describing head orientation (added for legacy code support only) */
+ head_tracker_event_t head_tracker;
+
+ /*
+ * limited axes imu event, See
+ * SENSOR_TYPE_GYROSCOPE_LIMITED_AXES and
+ * SENSOR_TYPE_ACCELEROMETER_LIMITED_AXES for details.
+ */
+ limited_axes_imu_event_t limited_axes_imu;
+
+ /*
+ * limited axes imu uncalibrated event, See
+ * SENSOR_TYPE_GYROSCOPE_LIMITED_AXES_UNCALIBRATED and
+ * SENSOR_TYPE_ACCELEROMETER_LIMITED_AXES_UNCALIBRATED for details.
+ */
+ limited_axes_imu_uncalibrated_event_t limited_axes_imu_uncalibrated;
+
+ /* heading data containing value in degrees and its accuracy */
+ heading_event_t heading;
};
union {
diff --git a/libnfc-nxp/nfc_custom_config_example.h b/libnfc-nxp/nfc_custom_config_example.h
deleted file mode 100644
index d400bcc..0000000
--- a/libnfc-nxp/nfc_custom_config_example.h
+++ /dev/null
@@ -1,200 +0,0 @@
-/*
- * Copyright (C) 2010 NXP Semiconductors
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-
-/**
-* \file nfc_custom_config.h
-* \brief HAL Custom Configurations
-*
-*
-* \note This is the configuration header file of the HAL 4.0. custom configurable
-* parameters of the HAL 4.0 are provided in this file
-*
-* Project: NFC-FRI-1.1 / HAL4.0
-*
-* $Date: Fri Jun 11 16:44:31 2010 $
-* $Author: ing04880 $
-* $Revision: 1.11 $
-* $Aliases: NFC_FRI1.1_WK1023_R35_1 $
-*
-*/
-
-
-/*@{*/
-#ifndef NFC_CUSTOM_CONFIG_H
-#define NFC_CUSTOM_CONFIG_H
-/*@}*/
-
-
-/**
-* \name Hal
-*
-* File: \ref nfc_custom_config.h
-*
-*/
-
-
-/*
- *****************************************************************
- ********************** CUSTOM MACROS **************************
- *****************************************************************
- */
-
-/**< Max number of remote devices supported*/
-#define MAX_REMOTE_DEVICES 0x10
-
-
-/**< Default Session ID for Initialisation */
-#define DEFAULT_SESSION "NXP-NFC2"
-
-/** Resolution value for the timer, here the
- timer resolution is 100 milliseconds */
-#define TIMER_RESOLUTION 100U
-
-/**< Defines connection time out value for LLC timer,
- 500 is in milliseconds */
-#define LINK_CONNECTION_TIMEOUT 500U
-
-/**< Defines guard time out value for LLC timer,
- 250 is in milliseconds */
-#define LINK_GUARD_TIMEOUT 250U
-
-/**< Macro to Enable SMX Feature During
- * Initialisation */
-
-
-/* PLEASE NOTE: This Macro should be only enabled if there is a SMART_MX
- * Chip attached to the PN544.
- */
-/* #define NXP_HAL_ENABLE_SMX */
-
-
-
-/* PLEASE NOTE: Kindly change the DEFAULT_SESSION Macro for each of the
- * configuration change done for the below Macros
- */
-
-/**< External Clock Request Configuration for the NFC Device,
- 0x00U -> No Clock Request,
- 0x01U -> Clock Request through CLKREQ pin (GPIO pin 2),
- 0x02U -> Clock Request through NXP_EVT_CLK_REQUEST Event,
- */
-#define NXP_DEFAULT_CLK_REQUEST 0x00U
-
-/**< External Input Clock Setting for the NFC Device,
- 0x00U -> No Input Clock Required (Use the Xtal),
- 0x01U -> 13 MHZ,
- 0x02U -> 19.2 MHZ,
- 0x03U -> 26 MHZ,
- 0x04U -> 38.4 MHZ,
- 0x05U -> Custom (Set the Custome Clock Registry),
- */
-#define NXP_DEFAULT_INPUT_CLK 0x00U
-
-
-
-#define NFC_DEV_HWCONF_DEFAULT 0xBCU
-
-/**< TX LDO Configuration
- 0x00 -> 00b 3.0 V,
- 0x01 -> 01b 3.0 V,
- 0x02 -> 10b 2.7 V,
- 0x03 -> 11b 3.3 V,
-
- */
-#define NXP_DEFAULT_TX_LDO 0x00U
-
-
-/**< External Clock Request Configuration for the NFC Device,
- 0x00U -> No Power Request,
- 0x01U -> Power Request through CLKREQ pin (GPIO pin 2),
- 0x02U -> Power Request through PWR_REQUEST (GPIO Pin 3),
- */
-#define NXP_UICC_PWR_REQUEST 0x00U
-
-/**< UICC Bit Rate Configuration
- 0x02U -> 212Kbits/Sec
- 0x04U -> 424Kbits/Sec
- 0x08U -> 828Kbits/Sec
- */
-
-#define NXP_UICC_BIT_RATE 0x08U
-
-/**< Indicates PN544 Power Modes Configuration for the NFC Device,
- 0x00U -> PN544 stays in active bat mode
- (except when generating RF field)
- 0x01U -> PN544 goes in standby when possible otherwise
- stays in active bat mode
- 0x02U -> PN544 goes in idle mode as soon as it can
- (otherwise it is in active bat except when generating RF field)
- 0x03U -> PN544 goes in standby when possible otherwise goes in idle mode
- as soon as it can (otherwise it is in active bat except when
- generating RF field)
- */
-
-#define NXP_SYSTEM_PWR_STATUS 0x01U
-
-
-/**< System Event Notification
- 0x01 Overcurrent
- 0x02 PMUVCC Switch
- 0x04 External RF Field
- 0x08 Memory Violation
- 0x10 Temperature Overheat
- */
-
-#define NXP_SYSTEM_EVT_INFO 0x10U
-
-/**< NFCIP Active Mode Configuration
- 0x01 106 kbps
- 0x02 212 kbps
- 0x04 424 kbps
- */
-
-#define NXP_NFCIP_ACTIVE_DEFAULT 0x01U
-
-
-
-/* Reset the Default values of Host Link Timers */
-/* Macro to Enable the Host Side Link Timeout Configuration
- * 0x00 ----> Default Pre-defined Configuration;
- * 0x01 ----> Update only the Host Link Guard Timeout Configuration;
- * 0x03 ----> Update Both the Host Link Guard Timeout
- and ACK Timeout Configuration;
- */
-#define HOST_LINK_TIMEOUT 0x00U
-
-
-#define NXP_NFC_LINK_GRD_CFG_DEFAULT 0x0032U
-
-
-#define NXP_NFC_LINK_ACK_CFG_DEFAULT 0x0005U
-
-
-/* Macro to Enable the Interface Character Timeout Configuration
- * 0x00 ----> Default Pre-defined Configuration;
- * 0x01 ----> Update the IFC Timeout Default Configuration;
- */
-#define NXP_NFC_IFC_TIMEOUT 0x00
-
-
-#define NXP_NFC_IFC_CONFIG_DEFAULT 0x203AU
-
-
-#define NXP_NFCIP_PSL_BRS_DEFAULT 0x00U
-
-
-#endif /* NFC_CUSTOM_CONFIG_H */
diff --git a/libnfc-nxp/nfc_osal_deferred_call.h b/libnfc-nxp/nfc_osal_deferred_call.h
deleted file mode 100644
index 08396dc..0000000
--- a/libnfc-nxp/nfc_osal_deferred_call.h
+++ /dev/null
@@ -1,32 +0,0 @@
-#ifndef __NFC_OSAL_DEFERRED_CALL_H_
-#define __NFC_OSAL_DEFERRED_CALL_H_
-
-/**
- * \ingroup grp_osal_nfc
- *\brief Deferred call declaration.
- * This type of API is called from ClientApplication ( main thread) to notify
- * specific callback.
- */
-typedef pphLibNfc_DeferredCallback_t nfc_osal_def_call_t;
-
-/**
- * \ingroup grp_osal_nfc
- *\brief Deferred message specific info declaration.
- * This type information packed as WPARAM when \ref PHOSALNFC_MESSAGE_BASE type
- *windows message is posted to main thread.
- */
-typedef phLibNfc_DeferredCall_t nfc_osal_def_call_msg_t;
-
-/**
- * \ingroup grp_osal_nfc
- *\brief Deferred call declaration.
- * This Deferred call post message of type \ref PH_OSALNFC_TIMER_MSG along with
- * timer specific details.ain thread,which is responsible for timer callback notification
- * consumes of this message and notifies respctive timer callback.
- *\note: This API packs upper timer specific callback notification information and post
- *ref\PHOSALNFC_MESSAGE_BASE to main thread via windows post messaging mechanism.
- */
-
-void nfc_osal_deferred_call(nfc_osal_def_call_t func, void *param);
-
-#endif
\ No newline at end of file
diff --git a/libnfc-nxp/phDal4Nfc.h b/libnfc-nxp/phDal4Nfc.h
deleted file mode 100644
index 3cbb585..0000000
--- a/libnfc-nxp/phDal4Nfc.h
+++ /dev/null
@@ -1,619 +0,0 @@
-/*
- * Copyright (C) 2010 NXP Semiconductors
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-
-/*!
-
-* \file phDal4Nfc.h
-* \brief Common DAL for the upper layer.
-*
-* Project: NFC-FRI-1.1
-*
-* $Date: Tue Nov 10 13:56:45 2009 $
-* $Author: ing07299 $
-* $Revision: 1.38 $
-* $Aliases: NFC_FRI1.1_WK943_R32_1,NFC_FRI1.1_WK949_PREP1,NFC_FRI1.1_WK943_R32_10,NFC_FRI1.1_WK943_R32_13,NFC_FRI1.1_WK943_R32_14,NFC_FRI1.1_WK1007_R33_1,NFC_FRI1.1_WK1007_R33_4,NFC_FRI1.1_WK1017_PREP1,NFC_FRI1.1_WK1017_R34_1,NFC_FRI1.1_WK1017_R34_2,NFC_FRI1.1_WK1023_R35_1 $
-*
-*/
-
-#ifndef PHDAL4NFC_H
-#define PHDAL4NFC_H
-
-/**
-* \name DAl4 NFC
-*
-* File: \ref phDal4Nfc.h
-*
-*/
-/*@{*/
-#define PH_DAL4NFC_FILEREVISION "$Revision: 1.38 $" /**< \ingroup grp_file_attributes */
-#define PH_DAL4NFC_FILEALIASES "$Aliases: NFC_FRI1.1_WK943_R32_1,NFC_FRI1.1_WK949_PREP1,NFC_FRI1.1_WK943_R32_10,NFC_FRI1.1_WK943_R32_13,NFC_FRI1.1_WK943_R32_14,NFC_FRI1.1_WK1007_R33_1,NFC_FRI1.1_WK1007_R33_4,NFC_FRI1.1_WK1017_PREP1,NFC_FRI1.1_WK1017_R34_1,NFC_FRI1.1_WK1017_R34_2,NFC_FRI1.1_WK1023_R35_1 $"
- /**< \ingroup grp_file_attributes */
-/*@}*/
-/*************************** Includes *******************************/
-/** \defgroup grp_nfc_dal DAL Component
- *
- *
- *
- */
-#include
-/**< Basic type definitions */
-#include
-/**< Generic Interface Layer Function Definitions */
-#include
-/*********************** End of includes ****************************/
-
-/***************************** Macros *******************************/
- /**< Used for messaging by DAL as well as Upper Layers */
-#define PH_DAL4NFC_MESSAGE_BASE PH_LIBNFC_DEFERREDCALL_MSG
-
-/************************ End of macros *****************************/
-
-
-/********************* Structures and enums *************************/
-
-/**
- * \ingroup grp_nfc_dal
- *
- * DAL context : This contains the information of the upper layer callback
- * and hardware reference.
- */
-typedef struct phDal4Nfc_SContext
-{
- phNfcIF_sCallBack_t cb_if; /**1.Exports DAL interfaces and DAL layer context to upper layer.
- *Exported DAL interfaces are :
- *
.phDal4Nfc_Shutdown
- *
.phDal4Nfc_Write
- *
.phDal4Nfc_Read
- *
.phDal4Nfc_ReadWait
- *
.phDal4Nfc_ReadWaitCancel
- *
phDal4Nfc_Unregister
- *
.Registeres upper layer callbacks and upper layer context with DAL layer.
- *For details refer to \ref phNfcIF_sReference_t.
- *Registration details are valid unless upper layer calls \ref phDal4Nfc_Unregister()
- or \ref phDal4Nfc_Shutdown called.
-
- * \param[in,out] psRefer holds DAL exported interface references once registration
- * sucessful.This also contains transmit and receive buffer
- * references.
- *
- * \param[in] if_cb Contains upper layer callback reference details, which are used
- * by DAL layer during callback notification.
- * These callbacks gets registered with DAL layer.
- *
-
- * \param[out] psIFConf Currently this parameter not used.This parameter to be other than NULL.
- *
- *
- * \retval NFCSTATUS_SUCCESS Operation is successful.
- * \retval NFCSTATUS_INVALID_PARAMETER At least one parameter of the function is invalid.
- *
- *\msc
- *ClientApp,UpperLayer,phDal4Nfc;
- *ClientApp=>phDal4Nfc [label="phDal4Nfc_Config()",URL="\ref phDal4Nfc_Config"];
- *ClientApp<phDal4Nfc [label="phDal4Nfc_Register()",URL="\ref phDal4Nfc_Register"];
- *UpperLayer<phDal4Nfc [label="phDal4Nfc_Config()",URL="\ref phDal4Nfc_Config"];
- *ClientApp<phDal4Nfc [label="phDal4Nfc_Register()",URL="\ref phDal4Nfc_Register"];
- *UpperLayer<phDal4Nfc [label="phDal4Nfc_Unregister()",URL="\ref phDal4Nfc_Unregister"];
- *UpperLayer<
. Initialize parameters for HW Interface.
- *
. Initializing read and writer threads.
- *
. Initializing read and write task specific events and event specific configurations.
- *
. Initializing DAL layer specific details.
- *
- * \param[in] pContext DAL context provided by the upper layer.
- * The DAL context will be exported to the
- * upper layer via upper layer registration interface.
- * \param[in] pHwRef information of the hardware
- *
- * \retval NFCSTATUS_SUCCESS DAL initialization successful.
- * \retval NFCSTATUS_INVALID_DEVICE The device is not enumerated or the
- * Hardware Reference points to a device
- * which does not exist. Alternatively,
- * also already open devices produce this
- * error.
- * \retval NFCSTATUS_INVALID_PARAMETER At least one parameter of the function
- * is invalid.
- *
- *\msc
- *ClientApp,UpperLayer,phDal4Nfc;
- *ClientApp=>phDal4Nfc [label="phDal4Nfc_Config()",URL="\ref phDal4Nfc_Config"];
- *ClientApp<phDal4Nfc [label="phDal4Nfc_Register()",URL="\ref phDal4Nfc_Register"];
- *UpperLayer<phDal4Nfc [label="phDal4Nfc_Init()",URL="\ref phDal4Nfc_Init"];
- *UpperLayer<
.Releases all the resources.( context,memory resources,read/write buffers).
- *
.closes COMxx port which is used during DAL session.
- *
.Terminates Reader and writer tasks.
- *
- * \param[in] pContext DAL context is provided by the upper layer.
- * The DAL context earlier was given to the
- * upper layer through the
- * \ref \e phDal4Nfc_Register() function
- * \param[in] pHwRef hardware reference context.
- *
- * \retval NFCSTATUS_SUCCESS DAL shutdown successful
- * \retval NFCSTATUS_FAILED DAL shutdown failed(example.unable to
- * suspend thread, close HW Interface etc.)
- * \retval NFCSTATUS_INVALID_PARAMETER At least one parameter of the function
- * is invalid.
- *
- *\msc
- *ClientApp,UpperLayer,phDal4Nfc;
- *ClientApp=>phDal4Nfc [label="phDal4Nfc_Config()",URL="\ref phDal4Nfc_Config"];
- *ClientApp<phDal4Nfc [label="phDal4Nfc_Register()",URL="\ref phDal4Nfc_Register"];
- *UpperLayer<phDal4Nfc [label="phDal4Nfc_Init()",URL="\ref phDal4Nfc_Init"];
- *UpperLayer<phDal4Nfc [label="phDal4Nfc_Shutdown()",URL="\ref phDal4Nfc_Shutdown"];
- *ClientApp<phDal4Nfc [label="phDal4Nfc_Write()",URL="\ref phDal4Nfc_Write()"];
- *UpperLayer<phDal4Nfc [label="phDal4Nfc_DeferredCall()",URL="\ref phDal4Nfc_DeferredCall()"];
- *ClientApp=>phDal4Nfc [label="phDal4Nfc_DeferredCb()",URL="\ref phDal4Nfc_DeferredCb()"];
- *phDal4Nfc=>UpperLayer [label="send_complete",URL="\ref phDal4Nfc_DeferredCb()"];
- *ClientApp<phDal4Nfc [label="phDal4Nfc_Write()",URL="\ref phDal4Nfc_Write()"];
- *UpperLayer<phDal4Nfc [label="phDal4Nfc_DeferredCall()",URL="\ref phDal4Nfc_DeferredCall()"];
- *ClientApp=>phDal4Nfc [label="phDal4Nfc_DeferredCb()",URL="\ref phDal4Nfc_DeferredCb()"];
- *phDal4Nfc=>UpperLayer [label="send_complete",URL="\ref phDal4Nfc_DeferredCb()"];
- *ClientApp<phDal4Nfc [label="phDal4Nfc_Read()",URL="\ref phDal4Nfc_Read()"];
- *UpperLayer<phDal4Nfc [label="phDal4Nfc_DeferredCall()",URL="\ref phDal4Nfc_DeferredCall()"];
- *ClientApp=>phDal4Nfc [label="phDal4Nfc_DeferredCb()",URL="\ref phDal4Nfc_DeferredCb()"];
- *phDal4Nfc=>UpperLayer [label="receive_complete",URL="\ref phDal4Nfc_DeferredCb()"];
- *ClientApp<phDal4Nfc [label="phDal4Nfc_Write()",URL="\ref phDal4Nfc_Write()"];
- *UpperLayer<phDal4Nfc [label="phDal4Nfc_DeferredCall()",URL="\ref phDal4Nfc_DeferredCall()"];
- *ClientApp=>phDal4Nfc [label="phDal4Nfc_DeferredCb()",URL="\ref phDal4Nfc_DeferredCb()"];
- *phDal4Nfc=>UpperLayer [label="send_complete",URL="\ref phDal4Nfc_DeferredCb()"];
- *ClientApp<phDal4Nfc [label="phDal4Nfc_ReadWait()",URL="\ref phDal4Nfc_ReadWait()"];
- *UpperLayer<phDal4Nfc [label="phDal4Nfc_DeferredCall()",URL="\ref phDal4Nfc_DeferredCall()"];
- *ClientApp=>phDal4Nfc [label="phDal4Nfc_DeferredCb()",URL="\ref phDal4Nfc_DeferredCb()"];
- *phDal4Nfc=>UpperLayer [label="receive_complete",URL="\ref phDal4Nfc_DeferredCb()"];
- *ClientApp<phDal4Nfc [label="phDal4Nfc_Write()",URL="\ref phDal4Nfc_Write()"];
- *UpperLayer<phDal4Nfc [label="phDal4Nfc_DeferredCall()",URL="\ref phDal4Nfc_DeferredCall()"];
- *ClientApp=>phDal4Nfc [label="phDal4Nfc_DeferredCb()",URL="\ref Call phDal4Nfc_DeferredCb()"];
- *phDal4Nfc=>UpperLayer [label="send_complete",URL="\ref phDal4Nfc_DeferredCb()"];
- *ClientApp<phDal4Nfc [label="phDal4Nfc_ReadWait()",URL="\ref phDal4Nfc_ReadWait()"];
- *UpperLayer<phDal4Nfc [label="phDal4Nfc_ReadWaitCancel()",URL="\ref phDal4Nfc_ReadWaitCancel()"];
- **UpperLayer<phDal4Nfc [label="phDal4Nfc_Config()",URL="\ref phDal4Nfc_Config"];
- *ClientApp<phDal4Nfc [label="phDal4Nfc_Config()",URL="\ref phDal4Nfc_Config"];
- *ClientApp<phDal4Nfc [label="phDal4Nfc_Register()",URL="\ref phDal4Nfc_Register"];
- *UpperLayer<phDal4Nfc [label="phDal4Nfc_Init()",URL="\ref phDal4Nfc_Init"];
- *UpperLayer<phDal4Nfc [label="phDal4Nfc_Shutdown()",URL="\ref phDal4Nfc_Shutdown"];
- *UpperLayer<phDal4Nfc [label="phDal4Nfc_ConfigRelease()",URL="\ref phDal4Nfc_ConfigRelease"];
- *ClientApp<
-#else
-
-#ifdef _DAL_4_NFC_C
-#define _ext_
-#else
-#define _ext_ extern
-#endif
-
-typedef pphLibNfc_DeferredCallback_t pphDal4Nfc_Deferred_Call_t;
-
-typedef phLibNfc_DeferredCall_t phDal4Nfc_DeferredCall_Msg_t;
-
-#ifndef WIN32
-
-#ifdef USE_MQ_MESSAGE_QUEUE
-#include
-#define MQ_NAME_IDENTIFIER "/nfc_queue"
-
-_ext_ const struct mq_attr MQ_QUEUE_ATTRIBUTES
-#ifdef _DAL_4_NFC_C
- = { 0, /* flags */
- 10, /* max number of messages on queue */
- sizeof(phDal4Nfc_DeferredCall_Msg_t), /* max message size in bytes */
- 0 /* number of messages currently in the queue */
- }
-#endif
-;
-#endif
-
-#endif
-
-void phDal4Nfc_DeferredCall(pphDal4Nfc_Deferred_Call_t func, void *param);
-#endif
-#endif
-
-
diff --git a/libnfc-nxp/phDal4Nfc_messageQueueLib.h b/libnfc-nxp/phDal4Nfc_messageQueueLib.h
deleted file mode 100644
index b13823b..0000000
--- a/libnfc-nxp/phDal4Nfc_messageQueueLib.h
+++ /dev/null
@@ -1,50 +0,0 @@
-/*
- * Copyright (C) 2010 NXP Semiconductors
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-/**
- * \file phDalNfc_messageQueueLib.h
- * \brief DAL independant message queue implementation for android (can be used under linux too)
- *
- * Project: Trusted NFC Linux Lignt
- *
- * $Date: 13 aug 2009
- * $Author: Jonathan roux
- * $Revision: 1.0 $
- *
- */
-#ifndef PHDAL4NFC_MESSAGEQUEUE_H
-#define PHDAL4NFC_MESSAGEQUEUE_H
-
-#ifndef WIN32
-#ifdef ANDROID
-#include
-#else
-#include
-#endif
-
-typedef struct phDal4Nfc_Message_Wrapper
-{
- long mtype;
- phLibNfc_Message_t msg;
-} phDal4Nfc_Message_Wrapper_t;
-
-intptr_t phDal4Nfc_msgget(key_t key, int msgflg);
-int phDal4Nfc_msgctl(intptr_t msqid, int cmd, void *buf);
-int phDal4Nfc_msgsnd(intptr_t msqid, void * msgp, size_t msgsz, int msgflg);
-int phDal4Nfc_msgrcv(intptr_t msqid, void * msgp, size_t msgsz, long msgtyp, int msgflg);
-#endif
-
-#endif /* PHDAL4NFC_MESSAGEQUEUE_H */
diff --git a/libnfc-nxp/phDbgTrace.h b/libnfc-nxp/phDbgTrace.h
deleted file mode 100644
index b0890cb..0000000
--- a/libnfc-nxp/phDbgTrace.h
+++ /dev/null
@@ -1,153 +0,0 @@
-/*
- * Copyright (C) 2010 NXP Semiconductors
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-
-/**
- * \file phDbgTrace.h
- * Project: NFC-FRI-1.1 / HAL4.0
- *
- * $Date: Tue Apr 28 11:48:33 2009 $
- * $Author: ing08203 $
- * $Revision: 1.17 $
- * $Aliases: NFC_FRI1.1_WK918_R24_1,NFC_FRI1.1_WK920_PREP1,NFC_FRI1.1_WK920_R25_1,NFC_FRI1.1_WK922_PREP1,NFC_FRI1.1_WK922_R26_1,NFC_FRI1.1_WK924_PREP1,NFC_FRI1.1_WK924_R27_1,NFC_FRI1.1_WK926_R28_1,NFC_FRI1.1_WK928_R29_1,NFC_FRI1.1_WK930_R30_1,NFC_FRI1.1_WK934_PREP_1,NFC_FRI1.1_WK934_R31_1,NFC_FRI1.1_WK941_PREP1,NFC_FRI1.1_WK941_PREP2,NFC_FRI1.1_WK941_1,NFC_FRI1.1_WK943_R32_1,NFC_FRI1.1_WK949_PREP1,NFC_FRI1.1_WK943_R32_10,NFC_FRI1.1_WK943_R32_13,NFC_FRI1.1_WK943_R32_14,NFC_FRI1.1_WK1007_R33_1,NFC_FRI1.1_WK1007_R33_4,NFC_FRI1.1_WK1017_PREP1,NFC_FRI1.1_WK1017_R34_1,NFC_FRI1.1_WK1017_R34_2,NFC_FRI1.1_WK1023_R35_1 $
- *
- */
-
-/*@{*/
-#ifndef PHDBGTRACE_H
-#define PHDBGTRACE_H
-/*@}*/
-
-#include
-
-
-#ifdef PHDBG_TRACES
-#define MAX_TRACE_BUFFER 300
-
-#ifndef PHDBG_TRACES_LEVEL_0
-#ifndef PHDBG_TRACES_LEVEL_1
-#ifndef PHDBG_TRACES_LEVEL_2
-#define PHDBG_TRACES_LEVEL_0
-#endif
-#endif
-#endif
-
- extern char phOsalNfc_DbgTraceBuffer[];
-
- #ifdef PHDBG_TRACES_LEVEL_0
-
- /*indicates an error that causes a program to abort.*/
- #define PHDBG_FATAL_ERROR(Str) {\
- snprintf(phOsalNfc_DbgTraceBuffer,MAX_TRACE_BUFFER, \
- "FATAL ERROR in Module :%s\n",__FILE__);\
- phOsalNfc_DbgString(phOsalNfc_DbgTraceBuffer);\
- snprintf(phOsalNfc_DbgTraceBuffer, MAX_TRACE_BUFFER, \
- "In Function:%s\n",__FUNCTION__ ); \
- phOsalNfc_DbgString (phOsalNfc_DbgTraceBuffer);\
- }
-
- #define PHDBG_CRITICAL_ERROR(Str) {\
- snprintf(phOsalNfc_DbgTraceBuffer, MAX_TRACE_BUFFER, \
- "CRITICAL ERROR in Module :%s\n",__FILE__);\
- phOsalNfc_DbgString(phOsalNfc_DbgTraceBuffer);\
- snprintf(phOsalNfc_DbgTraceBuffer, MAX_TRACE_BUFFER, \
- "In Function:%s\n",__FUNCTION__ ); \
- phOsalNfc_DbgString (phOsalNfc_DbgTraceBuffer);\
- }
- #define PHDBG_WARNING(Str)
- #define PHDBG_INFO(Str)
- #endif /*End of PHDBG_TRACES_LEVEL_0 */
-
- #ifdef PHDBG_TRACES_LEVEL_1
-
- /*indicates an error that causes a program to abort.*/
- #define PHDBG_FATAL_ERROR(Str) {\
- snprintf(phOsalNfc_DbgTraceBuffer, MAX_TRACE_BUFFER, \
- "FATAL ERROR in Module :%s\n",__FILE__);\
- phOsalNfc_DbgString(phOsalNfc_DbgTraceBuffer);\
- snprintf(phOsalNfc_DbgTraceBuffer, MAX_TRACE_BUFFER, \
- "In Function:%s\n",__FUNCTION__ ); \
- phOsalNfc_DbgString (phOsalNfc_DbgTraceBuffer);\
- }
-
- #define PHDBG_CRITICAL_ERROR(Str) {\
- snprintf(phOsalNfc_DbgTraceBuffer, MAX_TRACE_BUFFER, \
- "CRITICAL ERROR in Module :%s\n",__FILE__);\
- phOsalNfc_DbgString(phOsalNfc_DbgTraceBuffer);\
- snprintf(phOsalNfc_DbgTraceBuffer, MAX_TRACE_BUFFER, \
- "In Function:%s\n",__FUNCTION__ ); \
- phOsalNfc_DbgString (phOsalNfc_DbgTraceBuffer);\
- }
- /*Normally this macro shall be used indicate system state that might cause problems in future.*/
- #define PHDBG_WARNING(Str) {\
- snprintf(phOsalNfc_DbgTraceBuffer, MAX_TRACE_BUFFER, \
- "WARNING :%s\n",__FILE__);\
- phOsalNfc_DbgString(phOsalNfc_DbgTraceBuffer);\
- phOsalNfc_DbgString (Str);\
- phOsalNfc_DbgString ("\n");\
- }
- #define PHDBG_INFO(Str)
- #endif /*End of PHDBG_TRACES_LEVEL_1 */
-
- #ifdef PHDBG_TRACES_LEVEL_2
-
- /*indicates an error that causes a program to abort.*/
- #define PHDBG_FATAL_ERROR(Str) {\
- snprintf(phOsalNfc_DbgTraceBuffer, MAX_TRACE_BUFFER, \
- "FATAL ERROR in Module :%s\n",__FILE__);\
- phOsalNfc_DbgString(phOsalNfc_DbgTraceBuffer);\
- snprintf(phOsalNfc_DbgTraceBuffer, MAX_TRACE_BUFFER, \
- "In Function:%s\n",__FUNCTION__ ); \
- phOsalNfc_DbgString (phOsalNfc_DbgTraceBuffer);\
- }
-
- #define PHDBG_CRITICAL_ERROR(Str) {\
- snprintf(phOsalNfc_DbgTraceBuffer, MAX_TRACE_BUFFER, \
- "CRITICAL ERROR in Module :%s\n",__FILE__);\
- phOsalNfc_DbgString(phOsalNfc_DbgTraceBuffer);\
- snprintf(phOsalNfc_DbgTraceBuffer, MAX_TRACE_BUFFER, \
- "In Function:%s\n",__FUNCTION__ ); \
- phOsalNfc_DbgString (phOsalNfc_DbgTraceBuffer);\
- }
- /*Normally this macro shall be used indicate system state that might cause problems in future.*/
- #define PHDBG_WARNING(Str) {\
- snprintf(phOsalNfc_DbgTraceBuffer, MAX_TRACE_BUFFER, \
- "WARNING :%s\n",__FILE__);\
- phOsalNfc_DbgString(phOsalNfc_DbgTraceBuffer);\
- phOsalNfc_DbgString (Str);\
- phOsalNfc_DbgString ("\n");\
- }
-
- #define PHDBG_INFO(Str) {\
- snprintf(phOsalNfc_DbgTraceBuffer, MAX_TRACE_BUFFER, \
- "DBG INFO :%s\n",__FILE__);\
- phOsalNfc_DbgString(phOsalNfc_DbgTraceBuffer);\
- phOsalNfc_DbgString (Str);\
- phOsalNfc_DbgString ("\n");\
- }
-
-
-
-#endif /*End of PHDBG_TRACES_LEVEL_2 */
-#else
-#define PHDBG_FATAL_ERROR(Str)
-#define PHDBG_CRITICAL_ERROR(Str)
-#define PHDBG_WARNING(Str)
-#define PHDBG_INFO(Str)
-
-
-#endif /*end of DEBUG trace*/
-#endif /* end of PHDBGTRACE_H */
diff --git a/libnfc-nxp/phDnldNfc.c b/libnfc-nxp/phDnldNfc.c
deleted file mode 100644
index c0b4b4c..0000000
--- a/libnfc-nxp/phDnldNfc.c
+++ /dev/null
@@ -1,3832 +0,0 @@
-/*
- * Copyright (C) 2010 NXP Semiconductors
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-/*!
-* =========================================================================== *
-* *
-* *
-* \file phDnldNfc.c *
-* \brief Download Mgmt Interface Source for the Firmware Download. *
-* *
-* *
-* Project: NFC-FRI-1.1 *
-* *
-* $Date: Tue Jun 28 14:25:44 2011 $ *
-* $Author: ing04880 $ *
-* $Revision: 1.33 $ *
-* $Aliases: $
-* *
-* =========================================================================== *
-*/
-
-
-/*
-################################################################################
-***************************** Header File Inclusion ****************************
-################################################################################
-*/
-#include
-#include
-#include
-#include
-#include
-#include
-#include
-#include
-#include
-#include
-/*
-################################################################################
-****************************** Macro Definitions *******************************
-################################################################################
-*/
-
-#ifndef STATIC
-#define STATIC static
-#endif
-
-#if defined (DNLD_SUMMARY) && !defined (DNLD_TRACE)
-#define DNLD_TRACE
-#endif
-
-/* #if defined(PHDBG_INFO) && defined (PHDBG_CRITICAL_ERROR) */
-#if defined(DNLD_TRACE)
-extern char phOsalNfc_DbgTraceBuffer[];
-
-#define MAX_TRACE_BUFFER 0x0410
-#define Trace_buffer phOsalNfc_DbgTraceBuffer
-/* #define DNLD_PRINT( str ) phOsalNfc_DbgTrace(str) */
-#define DNLD_PRINT( str ) phOsalNfc_DbgString(str)
-#define DNLD_DEBUG(str, arg) \
- { \
- snprintf(Trace_buffer,MAX_TRACE_BUFFER,str,arg); \
- phOsalNfc_DbgString(Trace_buffer); \
- }
-#define DNLD_PRINT_BUFFER(msg,buf,len) \
- { \
- snprintf(Trace_buffer,MAX_TRACE_BUFFER,"\n\t %s:",msg); \
- phOsalNfc_DbgString(Trace_buffer); \
- phOsalNfc_DbgTrace(buf,len); \
- phOsalNfc_DbgString("\r"); \
- }
-#else
-#define DNLD_PRINT( str )
-#define DNLD_DEBUG(str, arg)
-#define DNLD_PRINT_BUFFER(msg,buf,len)
-#endif
-
-#define DO_DELAY(period) usleep(period)
-
-/* delay after SW reset cmd in ms, required on uart for XTAL stability */
-#define PHDNLD_DNLD_DELAY 5000
-//#define PHDNLD_MAX_PACKET 0x0200U /* Max Total Packet Size is 512 */
-#define PHDNLD_MAX_PACKET 32U /* Max Total Packet Size is 512 */
-#define PHDNLD_DATA_SIZE ((PHDNLD_MAX_PACKET)- 8U) /* 0x01F8U */
- /* Max Data Size is 504 */
-#define PHDNLD_MIN_PACKET 0x03U /* Minimum Packet Size is 3*/
-
-#define DNLD_DEFAULT_RESPONSE_TIMEOUT 0x4000U
-
-#define NXP_FW_MIN_TX_RX_LEN 0x0AU
-
-
-#if defined( NXP_FW_MAX_TX_RX_LEN ) && \
- ( NXP_FW_MAX_TX_RX_LEN > NXP_FW_MIN_TX_RX_LEN )
-
-#define PHDNLD_FW_TX_RX_LEN NXP_FW_MAX_TX_RX_LEN
-
-#elif !defined( NXP_FW_MAX_TX_RX_LEN )
-
-/* To specify the Maximum TX/RX Len */
-#define NXP_FW_MAX_TX_RX_LEN 0x200
-#define PHDNLD_FW_TX_RX_LEN NXP_FW_MAX_TX_RX_LEN
-
-#else
-
-#define PHDNLD_FW_TX_RX_LEN NXP_FW_MIN_TX_RX_LEN
-
-#endif
-
-#define PHDNLD_FRAME_LEN_SIZE 0x02U
-#define PHDNLD_ADDR_SIZE 0x03U
-#define PHDNLD_DATA_LEN_SIZE 0x02U
-#define PHDNLD_FRAME_DATA_OFFSET 0x03U
-
-#define DNLD_SM_UNLOCK_MASK 0x01U
-#define DNLD_TRIM_MASK 0x02U
-#define DNLD_RESET_MASK 0x04U
-#define DNLD_VERIFY_MASK 0x08U
-#define DNLD_CRITICAL_MASK 0x10U
-
-
-#define NXP_NFC_IMAG_FW_MAX 0x05U
-
-#define PHDNLD_FW_PATCH_SEC 0x5FU
-
-#define PHDNLD_PAGE_SIZE 0x80U /* Page Size Configured for 64 Bytes */
-
-#define FW_MAX_SECTION 0x15U /* Max Number of Sections */
-
-#define DNLD_CRC16_SIZE 0x02U
-
-#define DNLD_CRC32_SIZE 0x04U
-
-#define DNLD_CFG_PG_ADDR 0x00008000U
-#define DNLD_FW_CODE_ADDR 0x00800000U
-#define DNLD_PATCH_CODE_ADDR 0x00018800U
-#define DNLD_PATCH_TABLE_ADDR 0x00008200U
-
-
-/* Raw Command to pass the Data in Download Mode */
-#define PHDNLD_CMD_RAW 0x00U
-/* Command to Reset the Device in Download Mode */
-#define PHDNLD_CMD_RESET 0x01U
-/* Command to Read from the Address specified in Download Mode */
-#define PHDNLD_CMD_READ 0x07U
-#define PHDNLD_CMD_READ_LEN 0x0005U
-/* Command to write to the Address specified in Download Mode */
-#define PHDNLD_CMD_WRITE 0x08U
-#define PHDNLD_CMD_SEC_WRITE 0x0CU
-#define PHDNLD_CMD_WRITE_MIN_LEN 0x0005U
-#define PHDNLD_CMD_WRITE_MAX_LEN PHDNLD_DATA_SIZE
-/* Command to verify the data written */
-#define PHDNLD_CMD_CHECK 0x06U
-#define PHDNLD_CMD_CHECK_LEN 0x0007U
-
-/* Command to Lock the */
-#define PHDNLD_CMD_LOCK 0x40U
-#define PHDNLD_CMD_LOCK_LEN 0x0002U
-
-
-/* Command to set the Host Interface properties */
-#define PHDNLD_CMD_SET_HIF 0x09U
-
-/* Command to Activate the Patches Updated */
-#define PHDNLD_CMD_ACTIVATE_PATCH 0x0AU
-
-/* Command to verify the Integrity of the data written */
-#define PHDNLD_CMD_CHECK_INTEGRITY 0x0BU
-
-/* Command to verify the Integrity of the data written */
-#define PHDNLD_CMD_ENCAPSULATE 0x0DU
-
-#define CHECK_INTEGRITY_RESP_CRC16_LEN 0x03U
-#define CHECK_INTEGRITY_RESP_CRC32_LEN 0x05U
-#define CHECK_INTEGRITY_RESP_COMP_LEN 0x10U
-
-
-/* Success Response to a Command Sent in the Download Mode */
-#define PHDNLD_RESP_SUCCESS 0x00U
-/* Timeout Response to a Command Sent in the Download Mode */
-#define PHDNLD_RESP_TIMEOUT 0x01U
-/* CRC Error Response to a Command Sent in the Download Mode */
-#define PHDNLD_RESP_CRC_ERROR 0x02U
-/* Access Denied Response to a Command Sent in the Download Mode */
-#define PHDNLD_RESP_ACCESS_DENIED 0x08U
-/* PROTOCOL Error Response to a Command Sent in the Download Mode */
-#define PHDNLD_RESP_PROTOCOL_ERROR 0x0BU
-/* Invalid parameter Response to a Command Sent in the Download Mode */
-#define PHDNLD_RESP_INVALID_PARAMETER 0x11U
-/* Command Not Supported Response to a Command Sent in the Download Mode */
-#define PHDNLD_RESP_CMD_NOT_SUPPORTED 0x13U
-/* Length parameter error Response to a Command Sent in the Download Mode */
-#define PHDNLD_RESP_INVALID_LENGTH 0x18U
-/* Checksum Error Response to a Command Sent in the Download Mode */
-#define PHDNLD_RESP_CHKSUM_ERROR 0x19U
-/* Version already uptodate Response to a Command Sent in the Download Mode */
-#define PHDNLD_RESP_VERSION_UPTODATE 0x1DU
-/* Memory operation error during the processing of
- the Command Frame in the Download Mode */
-#define PHDNLD_RESP_MEMORY_UPDATE_ERROR 0x20U
-/* The Chaining of the Command Frame was Successful in the Download Mode */
-#define PHDNLD_RESP_CHAINING_SUCCESS 0x21U
-/* The Command is not allowed anymore in the Download Mode */
-#define PHDNLD_RESP_CMD_NOT_ALLOWED 0xE0U
-/* The Error during the Chaining the Command Frame in the Download Mode */
-#define PHDNLD_RESP_CHAINING_ERROR 0xE6U
-/* Write Error Response to a Command Sent in the Download Mode */
-#define PHDNLD_RESP_WRITE_ERROR 0x74U
-
-#define PNDNLD_WORD_LEN 0x04U
-
-#define NXP_MAX_DNLD_RETRY 0x02U
-
-#define NXP_MAX_SECTION_WRITE 0x05U
-
-#define NXP_PATCH_VER_INDEX 0x05U
-
-
-/*
-################################################################################
-******************** Enumeration and Structure Definition **********************
-################################################################################
-*/
-
-typedef enum phDnldNfc_eSeqType{
- DNLD_SEQ_RESET = 0x00U,
- DNLD_SEQ_INIT,
- DNLD_SEQ_RAW,
- DNLD_SEQ_LOCK,
- DNLD_SEQ_UNLOCK,
- DNLD_SEQ_UPDATE,
- DNLD_SEQ_ROLLBACK,
- DNLD_SEQ_COMPLETE
-} phDnldNfc_eSeqType_t;
-
-typedef enum phDnldNfc_eState
-{
- phDnld_Reset_State = 0x00,
- phDnld_Unlock_State,
- phDnld_Upgrade_State,
- phDnld_Verify_State,
- phDnld_Complete_State,
- phDnld_Invalid_State
-}phDnldNfc_eState_t;
-
-
-typedef enum phDnldNfc_eSeq
-{
- phDnld_Reset_Seq = 0x00,
- phDnld_Activate_Patch,
- phDnld_Deactivate_Patch,
- phDnld_Update_Patch,
- phDnld_Update_Patchtable,
- phDnld_Lock_System,
- phDnld_Unlock_System,
- phDnld_Upgrade_Section,
- phDnld_Verify_Integrity,
- phDnld_Verify_Section,
- phDnld_Complete_Seq,
- phDnld_Raw_Upgrade,
- phDnld_Invalid_Seq
-}phDnldNfc_eSeq_t;
-
-typedef enum phDnldNfc_eChkCrc{
- CHK_INTEGRITY_CONFIG_PAGE_CRC = 0x00U,
- CHK_INTEGRITY_PATCH_TABLE_CRC = 0x01U,
- CHK_INTEGRITY_FLASH_CODE_CRC = 0x02U,
- CHK_INTEGRITY_PATCH_CODE_CRC = 0x03U,
- CHK_INTEGRITY_COMPLETE_CRC = 0xFFU
-} phDnldNfc_eChkCrc_t;
-
-
-
-typedef struct hw_comp_tbl
-{
- uint8_t hw_version[3];
- uint8_t compatibility;
-}hw_comp_tbl_t;
-
-
-typedef struct img_data_hdr
-{
- /* Image Identification */
- uint32_t img_id;
- /* Offset of the Data from the header */
- uint8_t img_data_offset;
- /* Number of fimware images available in the img_data */
- uint8_t no_of_fw_img;
- /* Fimware image Padding in the img_data */
- uint8_t fw_img_pad[2];
- /* HW Compatiblity table for the set of the Hardwares */
- hw_comp_tbl_t comp_tbl;
- /* This data consists of the firmware images required to download */
-}img_data_hdr_t;
-
-
-typedef struct fw_data_hdr
-{
- /* The data offset from the firmware header.
- * Just in case if in future we require to
- * add some more information.
- */
- uint8_t fw_hdr_len;
- /* Total size of all the sections which needs to be updated */
- uint8_t no_of_sections;
- uint8_t hw_comp_no;
- uint8_t fw_patch;
- uint32_t fw_version;
-}fw_data_hdr_t;
-
-
-
- /* This data consists all the sections that needs to be downloaded */
-typedef struct section_hdr
-{
- uint8_t section_hdr_len;
- uint8_t section_mem_type;
- uint8_t section_checksum;
- uint8_t section_conf;
- uint32_t section_address;
- uint32_t section_length;
-}section_hdr_t;
-
-typedef struct section_info
-{
- section_hdr_t *p_sec_hdr;
- uint8_t *p_trim_data;
- /* The section data consist of the Firmware binary required
- * to be loaded to the particular address.
- */
- uint8_t *p_sec_data;
- /* The Section checksum to verify the integrity of the section
- * data.
- */
- uint8_t *p_sec_chksum;
- /** \internal Index used to refer and process the
- * Firmware Section Data */
- volatile uint32_t section_offset;
-
- /** \internal Section Read Sequence */
- volatile uint8_t section_read;
-
- /** \internal Section Write Sequence */
- volatile uint8_t section_write;
-
- /** \internal TRIM Write Sequence */
- volatile uint8_t trim_write;
-
- volatile uint8_t sec_verify_retry;
-
-}section_info_t;
-
-
-typedef struct phDnldNfc_sParam
-{
- uint8_t data_addr[PHDNLD_ADDR_SIZE];
- uint8_t data_len[PHDNLD_DATA_LEN_SIZE];
- uint8_t data_packet[PHDNLD_DATA_SIZE];
-}phDnldNfc_sParam_t;
-
-typedef struct phDnldNfc_sDataHdr
-{
- uint8_t frame_type;
- uint8_t frame_length[PHDNLD_FRAME_LEN_SIZE];
-}phDnldNfc_sData_Hdr_t;
-
-typedef struct phDnldNfc_sRawHdr
-{
- uint8_t frame_type;
- uint8_t frame_length[PHDNLD_FRAME_LEN_SIZE];
-}phDnldNfc_sRawHdr_t;
-
-typedef struct phDnldNfc_sRawDataHdr
-{
- uint8_t data_addr[PHDNLD_ADDR_SIZE];
- uint8_t data_len[PHDNLD_DATA_LEN_SIZE];
-}phDnldNfc_sRawDataHdr_t;
-
-typedef struct phDnldNfc_sChkCrc16_Resp
-{
- uint8_t Chk_status;
- uint8_t Chk_Crc16[2];
-
-}phDnldNfc_sChkCrc16_Resp_t;
-
-typedef struct phDnldNfc_sChkCrc32_Resp
-{
- uint8_t Chk_status;
- uint8_t Chk_Crc32[4];
-
-}phDnldNfc_sChkCrc32_Resp_t;
-
-
-typedef struct phDnldNfc_sChkCrcComplete
-{
- phDnldNfc_sChkCrc16_Resp_t config_page;
- phDnldNfc_sChkCrc16_Resp_t patch_table;
- phDnldNfc_sChkCrc32_Resp_t flash_code;
- phDnldNfc_sChkCrc32_Resp_t patch_code;
-}phDnldNfc_sChkCrcComplete_t;
-
-typedef struct phDnldNfc_sData
-{
- uint8_t frame_type;
- uint8_t frame_length[PHDNLD_FRAME_LEN_SIZE];
- union param
- {
- phDnldNfc_sParam_t data_param;
- uint8_t response_data[PHDNLD_MAX_PACKET];
- uint8_t cmd_param;
- }param_info;
-}phDnldNfc_sData_t;
-
-#ifdef NXP_NFC_MULTIPLE_FW
-
-typedef struct phDnldNfc_sFwImageInfo
-{
- /** \internal Data Pointer to the Firmware header section of the Firmware */
- fw_data_hdr_t *p_fw_hdr;
- /** \internal Buffer pointer to store the Firmware Section Data */
- section_info_t *p_fw_sec;
- /** \internal Buffer pointer to store the Firmware Raw Data */
- uint8_t *p_fw_raw;
-}phDnldNfc_sFwImageInfo_t;
-
-#endif /* #ifdef NXP_NFC_MULTIPLE_FW */
-
-
-typedef struct phDnldNfc_TxInfo
-{
- uint8_t *transmit_frame;
-
- uint16_t tx_offset;
-
- /** \internal Remaining amount of data to be sent */
- uint16_t tx_len;
-
- uint16_t tx_total;
-
- /** \internal Chain information for the data to be sent */
- uint8_t tx_chain;
-
-}phDnldNfc_TxInfo_t;
-
-
-typedef struct phDnldNfc_RxInfo
-{
- /** \internal Total length of the received buffer */
- uint16_t rx_total;
- /** \internal Chain information of the received buffer */
- uint16_t rx_chain;
- /** \internal Remaining Data information to be read to complete the
- * Data Information.
- */
- uint16_t rx_remain;
-
- /** \internal Buffer to Send the Raw Data Frame */
- uint8_t raw_buffer_data[PHDNLD_MAX_PACKET
- + PHDNLD_PAGE_SIZE];
-}phDnldNfc_RxInfo_t;
-
-
-typedef struct phDnldNfc_sContext
-{
- /** \internal Structure to store the lower interface operations */
- phNfc_sLowerIF_t lower_interface;
-
- phNfc_sData_t *p_fw_version;
-
- /** \internal Pointer to the Hardware Reference Sturcture */
- phHal_sHwReference_t *p_hw_ref;
-
- /** \internal Pointer to the upper layer notification callback function */
- pphNfcIF_Notification_CB_t p_upper_notify;
- /** \internal Pointer to the upper layer context */
- void *p_upper_context;
-
- /** \internal Timer ID for the Download Abort */
- uint32_t timer_id;
- /** \internal Internal Download for the Download Abort */
- uint32_t dnld_timeout;
- /** \internal Data Pointer to the Image header section of the Firmware */
- img_data_hdr_t *p_img_hdr;
-
-#ifdef NXP_NFC_MULTIPLE_FW
- /** \internal Data Pointer to the Firmware Image Information */
- phDnldNfc_sFwImageInfo_t *p_img_info;
-#endif /* #ifdef NXP_NFC_MULTIPLE_FW */
-
- /** \internal Data Pointer to the Firmware header section of the Firmware */
- fw_data_hdr_t *p_fw_hdr;
- /** \internal Buffer pointer to store the Firmware Data */
- section_info_t *p_fw_sec;
- /** \internal Buffer pointer to store the Firmware Raw Data */
- uint8_t *p_fw_raw;
-
- /** \internal Previous Download Size */
- uint32_t prev_dnld_size;
-
- /** \internal Single Data Block to download the Firmware */
- uint8_t dnld_data[PHDNLD_MAX_PACKET
- + PHDNLD_PAGE_SIZE];
- /** \internal Index used to refer and process the Download Data */
- volatile uint32_t dnld_index;
-
- /** \internal Response Data to process the response */
- phDnldNfc_sData_t dnld_resp;
-
- /** \internal Previously downloaded data stored
- * to compare the written data */
- phNfc_sData_t dnld_store;
-
- /** \internal Previously downloaded trimmed data stored
- * to compare the written data */
- phNfc_sData_t trim_store;
-
- uint8_t *p_resp_buffer;
-
- phDnldNfc_sChkCrcComplete_t chk_integrity_crc;
-
- phDnldNfc_eChkCrc_t chk_integrity_param;
-
-#define NXP_FW_SW_VMID_TRIM
-#ifdef NXP_FW_SW_VMID_TRIM
-
-#define NXP_FW_VMID_TRIM_CHK_ADDR 0x0000813DU
-#define NXP_FW_VMID_CARD_MODE_ADDR 0x00009931U
-#define NXP_FW_VMID_RD_MODE_ADDR 0x00009981U
-
- uint8_t vmid_trim_update;
-#endif /* #ifdef NXP_FW_SW_VMID_TRIM */
-
- uint8_t cur_frame_info;
-
- uint8_t raw_mode_upgrade;
-
- uint8_t *p_patch_table_crc;
-
- uint8_t *p_flash_code_crc;
-
- uint8_t *p_patch_code_crc;
-
- uint16_t resp_length;
-
- /** \internal Current FW Section in Process */
- volatile uint8_t section_index;
-
- /** \internal Previous Command sent */
- volatile uint8_t prev_cmd;
-
- uint8_t dnld_retry;
-
- /** \internal Current Download State */
- volatile uint8_t cur_dnld_state;
- /** \internal Next Download State */
- volatile uint8_t next_dnld_state;
-
- /** \internal Current step in Download Sequence */
- volatile uint8_t cur_dnld_seq;
- /** \internal Next step in Download Sequence */
- volatile uint8_t next_dnld_seq;
-
- /* \internal Data Transmit information */
- phDnldNfc_TxInfo_t tx_info;
-
- /* \internal Data Receive information */
- phDnldNfc_RxInfo_t rx_info;
-
-
-}phDnldNfc_sContext_t;
-
-
-/*
-################################################################################
-******************** Global and Static Variables Definition ********************
-################################################################################
-*/
-
-#ifndef NFC_TIMER_CONTEXT
-static phDnldNfc_sContext_t *gpphDnldContext = NULL;
-#endif
-
-#ifdef NXP_FW_DNLD_CHECK_PHASE
-
-#define NXP_FW_DNLD_COMPLETE_PHASE 0x00U
-#define NXP_FW_DNLD_SYSTEM_PHASE 0x01U
-#define NXP_FW_DNLD_CFG_PHASE 0x02U
-#define NXP_FW_DNLD_DATA_PHASE 0x03U
-#define NXP_FW_DNLD_RAW_PHASE 0x04U
-#define NXP_FW_DNLD_INVALID_PHASE 0xFFU
-
-static uint8_t gphDnldPhase = NXP_FW_DNLD_COMPLETE_PHASE;
-
-#endif /* #ifdef NXP_FW_DNLD_CHECK_PHASE */
-
-/**/
-
-/*
-*************************** Static Function Declaration **************************
-*/
-
-STATIC
-NFCSTATUS
-phDnldNfc_Send_Command(
- phDnldNfc_sContext_t *psDnldContext,
- void *pHwRef,
- uint8_t cmd,
- void *params,
- uint16_t param_length
- );
-
-static
-NFCSTATUS
-phDnldNfc_Process_FW(
- phDnldNfc_sContext_t *psDnldContext,
- phHal_sHwReference_t *pHwRef
-#ifdef NXP_FW_PARAM
- ,
- uint8_t *nxp_nfc_fw,
- uint32_t fw_length
-#endif
- );
-
-STATIC
-void
-phDnldNfc_Send_Complete (
- void *psContext,
- void *pHwRef,
- phNfc_sTransactionInfo_t *pInfo
- );
-
-STATIC
-void
-phDnldNfc_Receive_Complete (
- void *psContext,
- void *pHwRef,
- phNfc_sTransactionInfo_t *pInfo
- );
-
-STATIC
-NFCSTATUS
-phDnldNfc_Process_Response(
- phDnldNfc_sContext_t *psDnldContext,
- void *pHwRef,
- void *pdata,
- uint16_t length
- );
-
-
-static
-NFCSTATUS
-phDnldNfc_Resume(
- phDnldNfc_sContext_t *psDnldContext,
- void *pHwRef,
- void *pdata,
- uint16_t length
- );
-
-static
-NFCSTATUS
-phDnldNfc_Resume_Write(
- phDnldNfc_sContext_t *psDnldContext,
- void *pHwRef
- );
-
-static
-NFCSTATUS
-phDnldNfc_Process_Write(
- phDnldNfc_sContext_t *psDnldContext,
- void *pHwRef,
- section_info_t *p_sec_info,
- uint32_t *p_sec_offset
- );
-
-static
-NFCSTATUS
-phDnldNfc_Sequence(
- phDnldNfc_sContext_t *psDnldContext,
- void *pHwRef,
- void *pdata,
- uint16_t length
- );
-
-static
-NFCSTATUS
-phDnldNfc_Upgrade_Sequence(
- phDnldNfc_sContext_t *psDnldContext,
- void *pHwRef,
- void *pdata,
- uint16_t length
- );
-
-STATIC
-NFCSTATUS
-phDnldNfc_Receive(
- void *psContext,
- void *pHwRef,
- uint8_t *pdata,
- uint16_t length
- );
-
-
-STATIC
-NFCSTATUS
-phDnldNfc_Send (
- void *psContext,
- void *pHwRef,
- uint8_t *pdata,
- uint16_t length
- );
-
-STATIC
-NFCSTATUS
-phDnldNfc_Set_Seq(
- phDnldNfc_sContext_t *psDnldContext,
- phDnldNfc_eSeqType_t seq_type
- );
-
-static
-void
-phDnldNfc_Notify(
- pphNfcIF_Notification_CB_t p_upper_notify,
- void *p_upper_context,
- void *pHwRef,
- uint8_t type,
- void *pInfo
- );
-
-STATIC
-NFCSTATUS
-phDnldNfc_Allocate_Resource (
- void **ppBuffer,
- uint16_t size
- );
-
-STATIC
-void
-phDnldNfc_Release_Resources (
- phDnldNfc_sContext_t **ppsDnldContext
- );
-
-STATIC
-void
-phDnldNfc_Release_Lower(
- phDnldNfc_sContext_t *psDnldContext,
- void *pHwRef
- );
-
-
-static
-NFCSTATUS
-phDnldNfc_Read(
- phDnldNfc_sContext_t *psDnldContext,
- void *pHwRef,
- section_info_t *p_sec_info
- );
-
-STATIC
-void
-phDnldNfc_Abort (
- uint32_t abort_id
-#ifdef NFC_TIMER_CONTEXT
- , void *dnld_cntxt
-#endif
- );
-
-
-#ifdef DNLD_CRC_CALC
-
-static
-void
-phDnldNfc_UpdateCrc16(
- uint8_t crcByte,
- uint16_t *pCrc
-);
-
-STATIC
-uint16_t
-phDnldNfc_ComputeCrc16(
- uint8_t *pData,
- uint16_t length
-);
-
-
-/*
-*************************** Function Definitions **************************
-*/
-#define CRC32_POLYNOMIAL 0xEDB88320L
-
-static uint32_t CRC32Table[0x100];
-
-void BuildCRCTable()
-{
- unsigned long crc;
- uint8_t i = 0, j = 0;
-
- for ( i = 0; i <= 0xFF ; i++ )
- {
- crc = i;
- for ( j = 8 ; j> 0; j-- )
- {
- if ( crc & 1 )
- {
- crc = ( crc>> 1 ) ^ CRC32_POLYNOMIAL;
- }
- else
- {
- crc>>= 1;
- }
- }
- CRC32Table[ i ] = crc;
- }
-}
-
-/*
-* This routine calculates the CRC for a block of data using the
-* table lookup method. It accepts an original value for the crc,
-* and returns the updated value.
-*/
-
-uint32_t CalculateCRC32( void *buffer , uint32_t count, uint32_t crc )
-{
- uint8_t *p;
- uint32_t temp1;
- uint32_t temp2;
-
- p = (uint8_t *) buffer;
- while ( count-- != 0 ) {
- temp1 = ( crc>> 8 ) & 0x00FFFFFFL;
- temp2 = CRC32Table[ ( (int) crc ^ *p++ ) & 0xff ];
- crc = temp1 ^ temp2;
- }
- return( crc );
-}
-
-
-static
-void
-phDnldNfc_UpdateCrc16(
- uint8_t crcByte,
- uint16_t *pCrc
-)
-{
- crcByte = (crcByte ^ (uint8_t)((*pCrc) & 0x00FF));
- crcByte = (crcByte ^ (uint8_t)(crcByte << 4));
- *pCrc = (*pCrc >> 8) ^ ((uint16_t)crcByte << 8) ^
- ((uint16_t)crcByte << 3) ^
- ((uint16_t)crcByte >> 4);
-}
-
-
-STATIC
-uint16_t
-phDnldNfc_ComputeCrc16(
- uint8_t *pData,
- uint16_t length
-)
-{
- uint8_t crc_byte = 0;
- uint16_t index = 0;
- uint16_t crc = 0;
-
-#ifdef CRC_A
- crc = 0x6363; /* ITU-V.41 */
-#else
- crc = 0xFFFF; /* ISO/IEC 13239 (formerly ISO/IEC 3309) */
-#endif /* #ifdef CRC_A */
-
- do
- {
- crc_byte = pData[index];
- phDnldNfc_UpdateCrc16(crc_byte, &crc);
- index++;
- } while (index < length);
-
-#ifndef INVERT_CRC
- crc = ~crc; /* ISO/IEC 13239 (formerly ISO/IEC 3309) */
-#endif /* #ifndef INVERT_CRC */
-
-/* *pCrc1 = (uint8_t) (crc & BYTE_MASK);
- *pCrc2 = (uint8_t) ((crc >> 8) & BYTE_MASK); */
- return crc ;
-}
-
-#endif /* #ifdef DNLD_CRC_CALC */
-
-
-/*!
- * \brief Allocation of the Download Interface resources.
- *
- * This function releases and frees all the resources used by Download Mode
- * Feature.
- */
-
-STATIC
-NFCSTATUS
-phDnldNfc_Allocate_Resource (
- void **ppBuffer,
- uint16_t size
- )
-{
- NFCSTATUS status = NFCSTATUS_SUCCESS;
-
- *ppBuffer = (void *) phOsalNfc_GetMemory(size);
- if( *ppBuffer != NULL )
- {
- (void )memset(((void *)*ppBuffer), 0,
- size);
- }
- else
- {
- *ppBuffer = NULL;
- status = PHNFCSTVAL(CID_NFC_DNLD,
- NFCSTATUS_INSUFFICIENT_RESOURCES);
- }
- return status;
-}
-
-
-/*!
- * \brief Release of the Download Interface resources.
- *
- * This function releases and frees all the resources used by Download layer.
- */
-
-STATIC
-void
-phDnldNfc_Release_Resources (
- phDnldNfc_sContext_t **ppsDnldContext
- )
-{
-
- if(NULL != (*ppsDnldContext)->p_resp_buffer)
- {
- phOsalNfc_FreeMemory((*ppsDnldContext)->p_resp_buffer);
- (*ppsDnldContext)->p_resp_buffer = NULL;
- }
- if(NULL != (*ppsDnldContext)->dnld_store.buffer)
- {
- phOsalNfc_FreeMemory((*ppsDnldContext)->dnld_store.buffer);
- (*ppsDnldContext)->dnld_store.buffer = NULL;
- (*ppsDnldContext)->dnld_store.length = 0;
- }
- if(NULL != (*ppsDnldContext)->trim_store.buffer)
- {
- phOsalNfc_FreeMemory((*ppsDnldContext)->trim_store.buffer);
- (*ppsDnldContext)->trim_store.buffer = NULL;
- (*ppsDnldContext)->trim_store.length = 0;
- }
- if(NULL != (*ppsDnldContext)->p_fw_sec)
- {
- phOsalNfc_FreeMemory((*ppsDnldContext)->p_fw_sec);
- (*ppsDnldContext)->p_fw_sec = NULL;
- }
- if ( NXP_INVALID_TIMER_ID != (*ppsDnldContext)->timer_id )
- {
- phOsalNfc_Timer_Stop((*ppsDnldContext)->timer_id );
- phOsalNfc_Timer_Delete((*ppsDnldContext)->timer_id );
- (*ppsDnldContext)->timer_id = NXP_INVALID_TIMER_ID;
- }
-
- phOsalNfc_FreeMemory((*ppsDnldContext));
- (*ppsDnldContext) = NULL;
-
- return ;
-}
-
-
-STATIC
-void
-phDnldNfc_Release_Lower(
- phDnldNfc_sContext_t *psDnldContext,
- void *pHwRef
- )
-{
- phNfc_sLowerIF_t *plower_if =
- &(psDnldContext->lower_interface);
- NFCSTATUS status = NFCSTATUS_SUCCESS;
-
- PHNFC_UNUSED_VARIABLE(status);
-
- if(NULL != plower_if->release)
- {
-#ifdef DNLD_LOWER_RELEASE
- status = plower_if->release((void *)plower_if->pcontext,
- (void *)pHwRef);
-#else
- PHNFC_UNUSED_VARIABLE(pHwRef);
-
-#endif
- (void)memset((void *)plower_if,
- 0, sizeof(phNfc_sLowerIF_t));
- DNLD_DEBUG(" FW_DNLD: Releasing the Lower Layer Resources: Status = %02X\n"
- ,status);
- }
-
- return;
-}
-
-
-
-static
-void
-phDnldNfc_Notify(
- pphNfcIF_Notification_CB_t p_upper_notify,
- void *p_upper_context,
- void *pHwRef,
- uint8_t type,
- void *pInfo
- )
-{
- if( ( NULL != p_upper_notify) )
- {
- /* Notify the to the Upper Layer */
- (p_upper_notify)(p_upper_context, pHwRef, type, pInfo);
- }
-}
-
-
-STATIC
-NFCSTATUS
-phDnldNfc_Set_Seq(
- phDnldNfc_sContext_t *psDnldContext,
- phDnldNfc_eSeqType_t seq_type
- )
-{
- NFCSTATUS status = NFCSTATUS_SUCCESS;
- static uint8_t prev_temp_state = 0;
- static uint8_t prev_temp_seq =
- (uint8_t) phDnld_Activate_Patch;
-
- switch(seq_type)
- {
- case DNLD_SEQ_RESET:
- case DNLD_SEQ_INIT:
- {
- psDnldContext->cur_dnld_state =
- (uint8_t) phDnld_Reset_State;
- psDnldContext->next_dnld_state =
- (uint8_t)phDnld_Upgrade_State;
- psDnldContext->cur_dnld_seq =
- (uint8_t)phDnld_Upgrade_Section;
- psDnldContext->next_dnld_seq =
- psDnldContext->cur_dnld_seq;
- break;
- }
- case DNLD_SEQ_RAW:
- {
- psDnldContext->cur_dnld_state =
- (uint8_t) phDnld_Reset_State;
- psDnldContext->next_dnld_state =
- (uint8_t)phDnld_Upgrade_State;
- psDnldContext->cur_dnld_seq =
- (uint8_t)phDnld_Raw_Upgrade;
- psDnldContext->next_dnld_seq =
- psDnldContext->cur_dnld_seq;
- break;
- }
- case DNLD_SEQ_UNLOCK:
- {
- psDnldContext->cur_dnld_state =
- (uint8_t) phDnld_Reset_State;
-
-#ifdef NXP_FW_DNLD_CHECK_PHASE
- if( NXP_FW_DNLD_SYSTEM_PHASE < gphDnldPhase )
- {
- psDnldContext->next_dnld_state =
- (uint8_t)phDnld_Upgrade_State;
- psDnldContext->cur_dnld_seq =
- (uint8_t)phDnld_Upgrade_Section;
- }
- else
-#endif /* NXP_FW_DNLD_CHECK_PHASE */
- {
- psDnldContext->next_dnld_state =
- (uint8_t) phDnld_Unlock_State;
- psDnldContext->cur_dnld_seq =
- (uint8_t) phDnld_Activate_Patch;
- }
- psDnldContext->next_dnld_seq =
- psDnldContext->cur_dnld_seq;
- break;
- }
- case DNLD_SEQ_LOCK:
- {
- psDnldContext->cur_dnld_state =
- (uint8_t) phDnld_Reset_State;
- psDnldContext->next_dnld_state =
- (uint8_t) phDnld_Reset_State;
- psDnldContext->cur_dnld_seq =
- (uint8_t) phDnld_Lock_System;
- psDnldContext->next_dnld_seq =
- psDnldContext->cur_dnld_seq;
- break;
- }
- case DNLD_SEQ_UPDATE:
- {
- prev_temp_state = (uint8_t) psDnldContext->cur_dnld_state;
- psDnldContext->cur_dnld_state =
- psDnldContext->next_dnld_state;
- /* psDnldContext->next_dnld_state =
- (uint8_t)phDnld_Invalid_State ; */
- prev_temp_seq = (uint8_t) psDnldContext->cur_dnld_seq;
- psDnldContext->cur_dnld_seq =
- psDnldContext->next_dnld_seq;
- break;
- }
- case DNLD_SEQ_ROLLBACK:
- {
- psDnldContext->cur_dnld_seq = (uint8_t) prev_temp_seq;
- psDnldContext->next_dnld_seq =
- (uint8_t)phDnld_Invalid_Seq ;
- prev_temp_seq = 0;
-
- psDnldContext->cur_dnld_state = (uint8_t) prev_temp_state;
- /* psDnldContext->next_dnld_state =
- (uint8_t)phDnld_Invalid_State ; */
- prev_temp_state = 0;
- break;
- }
- case DNLD_SEQ_COMPLETE:
- {
- psDnldContext->cur_dnld_state =
- (uint8_t) phDnld_Reset_State;
- psDnldContext->next_dnld_state =
- (uint8_t) phDnld_Verify_State;
- psDnldContext->cur_dnld_seq =
- (uint8_t) phDnld_Verify_Integrity;
- psDnldContext->next_dnld_seq =
- psDnldContext->cur_dnld_seq ;
- break;
- }
- default:
- {
- break;
- }
- }
-
- return status;
-}
-
-
-
-/*!
- * \brief Sends the data the corresponding peripheral device.
- *
- * This function sends the Download data to the connected NFC Pheripheral device
- */
-
-
- STATIC
- NFCSTATUS
- phDnldNfc_Send (
- void *psContext,
- void *pHwRef,
- uint8_t *pdata,
- uint16_t length
- )
-{
- phDnldNfc_sContext_t *psDnldContext= (phDnldNfc_sContext_t *)psContext;
- NFCSTATUS status = NFCSTATUS_SUCCESS;
-
- phNfc_sLowerIF_t *plower_if = &(psDnldContext->lower_interface);
-
- if( (NULL != plower_if)
- && (NULL != plower_if->send)
- )
- {
-#ifndef DNLD_SUMMARY
- DNLD_PRINT_BUFFER("Send Buffer",pdata,length);
-#endif
- status = plower_if->send((void *)plower_if->pcontext,
- (void *)pHwRef, pdata, length);
-
-#if defined(FW_DOWNLOAD_TIMER) && \
- (FW_DOWNLOAD_TIMER == 2)
- if (
- (NFCSTATUS_PENDING == status)
- && ( NXP_INVALID_TIMER_ID != psDnldContext->timer_id )
- )
- {
- psDnldContext->dnld_timeout = NXP_DNLD_COMPLETE_TIMEOUT;
-
- if ( psDnldContext->dnld_timeout
- < DNLD_DEFAULT_RESPONSE_TIMEOUT)
- {
- psDnldContext->dnld_timeout
- = DNLD_DEFAULT_RESPONSE_TIMEOUT;
- }
- /* Start the Download Timer */
- phOsalNfc_Timer_Start( psDnldContext->timer_id,
- psDnldContext->dnld_timeout,
- (ppCallBck_t) phDnldNfc_Abort
-#ifdef NFC_TIMER_CONTEXT
- , (void *) psDnldContext
-#endif
- );
-
- DNLD_DEBUG(" DNLD : Timer %X Started ", psDnldContext->timer_id);
- DNLD_DEBUG(" \t\t With %U Timeout \n", psDnldContext->dnld_timeout);
- }
-
-#endif /* (NXP_NFC_DNLD_TIMER == 1) */
- }
-
- return status;
-}
-
-
-/*!
- * \brief Receives the Download Mode Response from the corresponding peripheral device.
- *
- * This function receives the Download Command Response to the connected NFC
- * Pheripheral device.
- */
-
-STATIC
-NFCSTATUS
-phDnldNfc_Receive(
- void *psContext,
- void *pHwRef,
- uint8_t *pdata,
- uint16_t length
- )
-{
- phDnldNfc_sContext_t *psDnldContext= (phDnldNfc_sContext_t *)psContext;
- phNfc_sLowerIF_t *plower_if = NULL ;
- NFCSTATUS status = NFCSTATUS_SUCCESS;
-
- if(NULL == psDnldContext )
- {
- status = PHNFCSTVAL(CID_NFC_DNLD, NFCSTATUS_INVALID_PARAMETER);
- }
- else
- {
- plower_if = &(psDnldContext->lower_interface);
-
- if( (NULL != plower_if)
- && (NULL != plower_if->receive)
- )
- {
- status = plower_if->receive((void *)plower_if->pcontext,
- (void *)pHwRef, pdata, length);
- }
- }
- return status;
-}
-
-
-static
-NFCSTATUS
-phDnldNfc_Read(
- phDnldNfc_sContext_t *psDnldContext,
- void *pHwRef,
- section_info_t *p_sec_info
- )
-{
- NFCSTATUS status = NFCSTATUS_SUCCESS;
- phDnldNfc_sData_t *p_dnld_data =
- (phDnldNfc_sData_t *)psDnldContext->dnld_data;
- phDnldNfc_sParam_t *p_data_param =
- &p_dnld_data->param_info.data_param;
- uint32_t read_addr = (p_sec_info->p_sec_hdr->section_address
- + p_sec_info->section_offset);
- static unsigned sec_type = 0;
- uint8_t i = 0;
- uint16_t read_size = 0 ;
-
- sec_type = (unsigned int)p_sec_info->p_sec_hdr->section_mem_type;
-
- if( ( FALSE == p_sec_info->section_read )
- && ((sec_type & DNLD_TRIM_MASK))
- && (FALSE == p_sec_info->trim_write) )
- {
- read_size = (uint16_t) p_sec_info->p_sec_hdr->section_length;
- DNLD_DEBUG(" FW_DNLD: Section Read = %X \n", read_size);
- }
- else
- {
- if (( FALSE == p_sec_info->section_read )
- && ((sec_type & DNLD_VERIFY_MASK))
- )
- {
- read_size = (uint16_t)(psDnldContext->prev_dnld_size );
- DNLD_DEBUG(" FW_DNLD: Section Read = %X \n", read_size);
- }
- else if( ( TRUE == p_sec_info->section_read )
- && ( TRUE == p_sec_info->section_write )
- )
- {
- /*Already Read the Data Hence Ignore the Read */
- DNLD_DEBUG(" FW_DNLD: Already Read, Read Ignored, read_size = %X \n", read_size);
- }
- else
- {
- /* Ignore the Read */
- DNLD_DEBUG(" FW_DNLD: Section Read Status = %X \n", p_sec_info->section_read);
- DNLD_DEBUG(" FW_DNLD: Section Write Status = %X \n", p_sec_info->section_write);
- DNLD_DEBUG(" FW_DNLD: No Read Required, Read_size = %X \n", read_size);
- }
- }
-
- if (read_size != 0)
- {
-
- read_size = (uint16_t)((PHDNLD_DATA_SIZE >= read_size)?
- read_size: PHDNLD_DATA_SIZE);
-
- p_dnld_data->frame_length[i] = (uint8_t)0;
- /* Update the LSB of the Data and the Address Parameter*/
- p_data_param->data_addr[i] = (uint8_t)((read_addr >>
- (BYTE_SIZE + BYTE_SIZE)) & BYTE_MASK);
- p_data_param->data_len[i] = (uint8_t)((read_size >>
- BYTE_SIZE) & BYTE_MASK);
- i++;
-
- p_dnld_data->frame_length[i] = (uint8_t)
- ( PHDNLD_CMD_READ_LEN & BYTE_MASK);
- /* Update the 2nd byte of the Data and the Address Parameter*/
- p_data_param->data_addr[i] = (uint8_t)((read_addr >>
- BYTE_SIZE) & BYTE_MASK);
- p_data_param->data_len[i] = (uint8_t) (read_size & BYTE_MASK);
- i++;
-
- /* Update the 3rd byte of the the Address Parameter*/
- p_data_param->data_addr[i] = (uint8_t)(read_addr & BYTE_MASK);
-
- status = phDnldNfc_Send_Command( psDnldContext, pHwRef,
- PHDNLD_CMD_READ, NULL , 0 );
-
- if ( NFCSTATUS_PENDING == status )
- {
- p_sec_info->section_read = TRUE ;
- psDnldContext->next_dnld_state = phDnld_Upgrade_State;
- DNLD_DEBUG(" FW_DNLD: Memory Read at Address %X : ", read_addr);
- DNLD_DEBUG(" of Size %X \n", read_size);
- }
-
- }
- return status;
-}
-
-
-
-static
-NFCSTATUS
-phDnldNfc_Process_Write(
- phDnldNfc_sContext_t *psDnldContext,
- void *pHwRef,
- section_info_t *p_sec_info,
- uint32_t *p_sec_offset
- )
-{
- NFCSTATUS status = NFCSTATUS_SUCCESS;
- phDnldNfc_sData_t *p_dnld_data =
- (phDnldNfc_sData_t *)psDnldContext->dnld_data;
- phDnldNfc_sParam_t *dnld_data =
- &p_dnld_data->param_info.data_param;
- uint8_t *p_sm_trim_data = (uint8_t *)psDnldContext->
- dnld_resp.param_info.response_data;
- uint32_t dnld_addr = 0;
-#ifdef NXP_FW_SW_VMID_TRIM
- uint32_t trim_addr = 0;
-#endif /* #ifdef NXP_FW_SW_VMID_TRIM */
- static unsigned sec_type = 0;
- uint8_t i = 0;
- uint16_t dnld_size = 0;
- int cmp_val = 0x00;
-
-
- sec_type = (unsigned int)p_sec_info->p_sec_hdr->section_mem_type;
-
- status = phDnldNfc_Read(psDnldContext, pHwRef, p_sec_info);
- if( NFCSTATUS_PENDING != status )
- {
- if( (TRUE == p_sec_info->trim_write)
- && (TRUE == p_sec_info->section_read)
- && ((sec_type & DNLD_VERIFY_MASK))
- )
- {
- if(NULL != psDnldContext->trim_store.buffer)
- {
- uint32_t trim_cmp_size = psDnldContext->prev_dnld_size;
-
- if( p_sec_info->p_sec_hdr->section_address
- < (DNLD_CFG_PG_ADDR + PHDNLD_PAGE_SIZE) )
- {
- trim_cmp_size = trim_cmp_size - 2;
- }
-
- /* Below Comparison fails due to the checksum */
- cmp_val = phOsalNfc_MemCompare(
- psDnldContext->trim_store.buffer,
- &psDnldContext->dnld_resp.
- param_info.response_data[0]
- ,trim_cmp_size);
- DNLD_DEBUG(" FW_DNLD: %X Bytes Trim Write Complete ",
- psDnldContext->prev_dnld_size);
- DNLD_DEBUG(" Comparison Status %X\n", cmp_val);
- }
- p_sec_info->trim_write = FALSE;
- DNLD_DEBUG(" FW_DNLD: TRIMMED %X Bytes Write Complete\n", psDnldContext->prev_dnld_size);
- }
- else
- {
- if((NULL != psDnldContext->dnld_store.buffer)
- && ((sec_type & DNLD_VERIFY_MASK))
- && (TRUE == p_sec_info->section_write)
- && (TRUE == p_sec_info->section_read)
- )
- {
- cmp_val = phOsalNfc_MemCompare(
- psDnldContext->dnld_store.buffer,
- &psDnldContext->dnld_resp.
- param_info.response_data[0]
- ,psDnldContext->dnld_store.length);
- p_sec_info->section_read = FALSE;
- p_sec_info->section_write = FALSE;
- DNLD_DEBUG(" FW_DNLD: %X Bytes Write Complete ",
- psDnldContext->dnld_store.length);
- DNLD_DEBUG(" Comparison Status %X\n", cmp_val);
- }
- else
- {
- if(( TRUE == p_sec_info->section_write)
- && ( FALSE == p_sec_info->section_read)
- )
- {
- p_sec_info->section_write = FALSE;
- }
- }
- /* p_sec_info->section_read = FALSE; */
- }
-
- if (( 0 == psDnldContext->dnld_retry )
- && (0 == cmp_val)
- )
- {
- p_sec_info->sec_verify_retry = 0;
- p_sec_info->section_offset = p_sec_info->section_offset +
- psDnldContext->prev_dnld_size;
- psDnldContext->prev_dnld_size = 0;
- DNLD_DEBUG(" FW_DNLD: Memory Write Retry - %X \n",
- psDnldContext->dnld_retry);
- }
- else
- {
- p_sec_info->sec_verify_retry++;
- DNLD_DEBUG(" FW_DNLD: Memory Verification Failed, Retry = %X \n",
- p_sec_info->sec_verify_retry);
- }
-
- if( p_sec_info->sec_verify_retry < NXP_MAX_SECTION_WRITE )
- {
-
- dnld_addr = (p_sec_info->p_sec_hdr->section_address + *p_sec_offset);
- dnld_size = (uint16_t)(p_sec_info->p_sec_hdr->section_length
- - *p_sec_offset);
- }
- else
- {
- status = NFCSTATUS_FAILED;
- DNLD_DEBUG(" FW_DNLD: Memory Verification - Maximum Limit, Retry = %X \n",
- p_sec_info->sec_verify_retry);
- }
- }
-
-
- if (dnld_size != 0)
- {
-
- dnld_size = (uint16_t)((PHDNLD_DATA_SIZE >= dnld_size)?
- dnld_size: PHDNLD_DATA_SIZE);
-
- /* Update the LSB of the Data and the Address Parameter*/
- dnld_data->data_addr[i] = (uint8_t)((dnld_addr >>
- (BYTE_SIZE + BYTE_SIZE)) & BYTE_MASK);
- dnld_data->data_len[i] = (uint8_t)((dnld_size >> BYTE_SIZE)
- & BYTE_MASK);
- p_dnld_data->frame_length[i] = (uint8_t)
- (((dnld_size + PHDNLD_CMD_WRITE_MIN_LEN) >> BYTE_SIZE)
- & BYTE_MASK);
- i++;
- /* Update the 2nd byte of the Data and the Address Parameter*/
- dnld_data->data_addr[i] = (uint8_t)((dnld_addr >> BYTE_SIZE)
- & BYTE_MASK);
- dnld_data->data_len[i] = (uint8_t) (dnld_size & BYTE_MASK);
- p_dnld_data->frame_length[i] = (uint8_t) ((dnld_size +
- PHDNLD_CMD_WRITE_MIN_LEN) & BYTE_MASK);
- i++;
- /* Update the 3rd byte of the the Address Parameter*/
- dnld_data->data_addr[i] = (uint8_t)(dnld_addr & BYTE_MASK);
-
- (void)memcpy( dnld_data->data_packet,
- (p_sec_info->p_sec_data + *p_sec_offset), dnld_size );
-
- if( ((sec_type & DNLD_TRIM_MASK))
- && (p_sec_info->sec_verify_retry != 0)
- && (NULL != psDnldContext->trim_store.buffer)
- )
- {
- (void)memcpy( dnld_data->data_packet,
- psDnldContext->trim_store.buffer, dnld_size );
- }
- else if(((sec_type & DNLD_TRIM_MASK))
- && ( TRUE == p_sec_info->section_read )
- )
- {
- for(i = 0; i < *(p_sec_info->p_trim_data);i++)
- {
-
-#ifdef NXP_FW_SW_VMID_TRIM
-
-/*
-if(bit 0 of 0x813D is equal to 1) then
-
- Do not overwrite 0x9931 / 0x9981 during download
-
-else
-
- @0x9931 = 0x79 // card Mode
- @0x9981 = 0x79 // Reader Mode
-*/
- trim_addr = p_sec_info->p_sec_hdr->section_address
- + p_sec_info->p_trim_data[i+1];
- if (NXP_FW_VMID_TRIM_CHK_ADDR == trim_addr)
- {
- psDnldContext->vmid_trim_update =
- p_sm_trim_data[p_sec_info->p_trim_data[i+1]] ;
- }
-
- if((NXP_FW_VMID_CARD_MODE_ADDR == trim_addr)
- || (NXP_FW_VMID_RD_MODE_ADDR == trim_addr))
- {
- if (TRUE == psDnldContext->vmid_trim_update)
- {
- dnld_data->data_packet[p_sec_info->p_trim_data[i+1]] =
- p_sm_trim_data[p_sec_info->p_trim_data[i+1]] ;
- }
- }
- else
-
-#endif
- {
- dnld_data->data_packet[p_sec_info->p_trim_data[i+1]] =
- p_sm_trim_data[p_sec_info->p_trim_data[i+1]] ;
- }
- }
- if(NULL != psDnldContext->trim_store.buffer)
- {
- phOsalNfc_FreeMemory(psDnldContext->trim_store.buffer);
- psDnldContext->trim_store.buffer = NULL;
- psDnldContext->trim_store.length = 0;
- }
-#if 1
- (void)
- phDnldNfc_Allocate_Resource((void **)
- &(psDnldContext->trim_store.buffer),dnld_size);
-#else
- psDnldContext->trim_store.buffer =
- (uint8_t *) phOsalNfc_GetMemory(dnld_size);
-#endif
-
- if(NULL != psDnldContext->trim_store.buffer)
- {
- (void )memset((void *)psDnldContext->trim_store.buffer,0,
- dnld_size);
- (void)memcpy( psDnldContext->trim_store.buffer,
- dnld_data->data_packet, dnld_size );
- psDnldContext->trim_store.length = dnld_size;
- DNLD_DEBUG(" FW_DNLD: Write with Trimming at Address %X ", dnld_addr );
- DNLD_DEBUG(" of Size %X and ", dnld_size );
- DNLD_DEBUG(" with %X Trimming Values \n", *(p_sec_info->p_trim_data) );
-
- }
- }
- else
- {
- if(NULL != psDnldContext->dnld_store.buffer)
- {
- phOsalNfc_FreeMemory(psDnldContext->dnld_store.buffer);
- psDnldContext->dnld_store.buffer = NULL;
- psDnldContext->dnld_store.length = 0;
- }
-#if 1
- (void)
- phDnldNfc_Allocate_Resource((void **)
- &(psDnldContext->dnld_store.buffer),dnld_size);
-#else
- psDnldContext->dnld_store.buffer =
- (uint8_t *) phOsalNfc_GetMemory(dnld_size);
-#endif
- if(NULL != psDnldContext->dnld_store.buffer)
- {
- (void )memset((void *)psDnldContext->dnld_store.buffer,0,
- dnld_size);
- (void)memcpy( psDnldContext->dnld_store.buffer,
- dnld_data->data_packet, dnld_size );
- psDnldContext->dnld_store.length = dnld_size;
- DNLD_DEBUG(" FW_DNLD: Memory Write at Address %X ", dnld_addr );
- DNLD_DEBUG(" of Size %X ", dnld_size );
- }
- }
-
- if(PHDNLD_FW_PATCH_SEC != psDnldContext->p_fw_hdr->fw_patch)
- {
- status = phDnldNfc_Send_Command( psDnldContext, pHwRef,
- PHDNLD_CMD_WRITE, NULL , 0 );
- }
- else
- {
- status = phDnldNfc_Send_Command( psDnldContext, pHwRef,
- PHDNLD_CMD_SEC_WRITE, NULL , 0 );
- }
-
- DNLD_DEBUG(" FW_DNLD: Memory Write Status = %X \n", status);
- if ( NFCSTATUS_PENDING == status )
- {
- psDnldContext->prev_dnld_size = dnld_size;
- cmp_val = 0x00;
- if((sec_type & DNLD_TRIM_MASK))
- {
- p_sec_info->trim_write = TRUE;
- DNLD_DEBUG(" FW_DNLD: Bytes Downloaded (Trimming Values) = %X Bytes \n",
- dnld_size);
- }
- else
- {
- p_sec_info->section_write = TRUE;
- DNLD_DEBUG(" FW_DNLD: Bytes Downloaded = %X : ",
- (*p_sec_offset + dnld_size));
- DNLD_DEBUG(" Bytes Remaining = %X \n",
- (p_sec_info->p_sec_hdr->section_length -
- (*p_sec_offset + dnld_size)));
- }
-
- p_sec_info->section_read = FALSE;
- }
- }
- return status;
-}
-
-
-
-static
-NFCSTATUS
-phDnldNfc_Resume_Write(
- phDnldNfc_sContext_t *psDnldContext,
- void *pHwRef
- )
-{
- NFCSTATUS status = NFCSTATUS_SUCCESS;
- uint8_t sec_index = psDnldContext->section_index;
- section_info_t *p_sec_info = (psDnldContext->p_fw_sec + sec_index);
-
- while((sec_index < psDnldContext->p_fw_hdr->no_of_sections)
- && (NFCSTATUS_SUCCESS == status )
- )
- {
-
- status = phDnldNfc_Process_Write(psDnldContext, pHwRef,
- p_sec_info, (uint32_t *)&(p_sec_info->section_offset));
- if (NFCSTATUS_SUCCESS == status)
- {
- unsigned sec_type = 0;
- sec_type = (unsigned int)p_sec_info->p_sec_hdr->section_mem_type;
-
- p_sec_info->section_offset = 0;
- p_sec_info->section_read = FALSE;
- p_sec_info->section_write = FALSE;
- p_sec_info->trim_write = FALSE;
-
- DNLD_DEBUG(" FW_DNLD: Section %02X Download Complete\n", sec_index);
- if((sec_type & DNLD_RESET_MASK))
- {
- DNLD_DEBUG(" FW_DNLD: Reset After Section %02X Download \n", sec_index);
- status = phDnldNfc_Send_Command( psDnldContext, pHwRef,
- PHDNLD_CMD_RESET , NULL, 0 );
- }
- DNLD_PRINT("*******************************************\n\n");
-
- sec_index++;
-
-#ifdef NXP_FW_DNLD_CHECK_PHASE
- if( p_sec_info->p_sec_hdr->section_address
- < (DNLD_CFG_PG_ADDR + PHDNLD_PAGE_SIZE) )
- {
- gphDnldPhase = NXP_FW_DNLD_DATA_PHASE;
-
- }
-
- p_sec_info = (psDnldContext->p_fw_sec + sec_index);
-
- if( (sec_index < psDnldContext->p_fw_hdr->no_of_sections)
- && ( p_sec_info->p_sec_hdr->section_address
- < (DNLD_CFG_PG_ADDR + PHDNLD_PAGE_SIZE) )
- )
- {
- if( NXP_FW_DNLD_CFG_PHASE >= gphDnldPhase )
- {
- gphDnldPhase = NXP_FW_DNLD_CFG_PHASE;
- }
- else
- {
- sec_index++;
- p_sec_info = (psDnldContext->p_fw_sec + sec_index);
- }
- }
-#else
- p_sec_info = (psDnldContext->p_fw_sec + sec_index);
-#endif /* #ifdef NXP_FW_DNLD_CHECK_PHASE */
-
- psDnldContext->section_index = sec_index;
- /* psDnldContext->next_dnld_state = (uint8_t) phDnld_Upgrade_State; */
- }
- }
- if (NFCSTATUS_PENDING == status)
- {
- psDnldContext->next_dnld_state = (uint8_t) phDnld_Upgrade_State;
- }
- else if (NFCSTATUS_SUCCESS == status)
- {
- /* Reset the PN544 Device */
- psDnldContext->next_dnld_state = (uint8_t) phDnld_Complete_State;
- }
- else
- {
-
- }
- return status;
-}
-
-
-#define NXP_DNLD_SM_UNLOCK_ADDR 0x008002U
-
-#if !defined (ES_HW_VER)
-#define ES_HW_VER 32
-#endif
-
-#if (ES_HW_VER <= 30)
-#define NXP_DNLD_PATCH_ADDR 0x01AFFFU
-#else
-#define NXP_DNLD_PATCH_ADDR 0x01A1E0U
-#endif
-
-#if (ES_HW_VER <= 30)
-#define NXP_DNLD_PATCH_TABLE_ADDR 0x008107U
-#else
-#define NXP_DNLD_PATCH_TABLE_ADDR 0x00825AU
-#endif
-
-
-static
-NFCSTATUS
-phDnldNfc_Sequence(
- phDnldNfc_sContext_t *psDnldContext,
- void *pHwRef,
- void *pdata,
- uint16_t length
- )
-{
- NFCSTATUS status = NFCSTATUS_SUCCESS;
- uint32_t dnld_addr = 0;
- phDnldNfc_sData_t *p_dnld_data =
- (phDnldNfc_sData_t *)psDnldContext->dnld_data;
- phDnldNfc_sParam_t *p_data_param =
- & p_dnld_data->param_info.data_param;
- uint8_t *p_data = NULL;
- static uint32_t patch_size = 0;
-
-#if (ES_HW_VER == 32)
-
- static uint8_t patch_table[] = {0xA0, 0xA1, 0xE0, 0x80, 0xA9, 0x6C };
- static uint8_t patch_data[] = {0xA5, 0xD0, 0xFE, 0xA5, 0xD0, 0xFD, 0xA5,
- 0xD0, 0xFC, 0xA5, 0x02, 0x80, 0xA9, 0x75};
-
-#elif (ES_HW_VER == 31)
-
- static uint8_t patch_table[] = {0xA0, 0xAF, 0xE0, 0x80, 0x78, 0x84 };
- static uint8_t patch_data[] = {0xA5, 0xD0, 0xFE, 0xA5, 0xD0, 0xFD, 0xA5,
- 0xD0, 0xFC, 0xD0, 0xE0, 0xA5, 0x02, 0x80, 0x78, 0x8D};
-
-#elif (ES_HW_VER == 30)
-
- static uint8_t patch_table[] = {0x80, 0x91, 0x51, 0xA0, 0xAF,
- 0xFF, 0x80, 0x91, 0x5A};
- static uint8_t patch_data[] = {0x22};
-
-#endif
-
- static uint8_t unlock_data[] = {0x00, 0x00};
- static uint8_t lock_data[] = {0x0C, 0x00};
-
- uint8_t i = 0;
-
- PHNFC_UNUSED_VARIABLE(pdata);
- PHNFC_UNUSED_VARIABLE(length);
- switch(psDnldContext->cur_dnld_seq)
- {
- case phDnld_Reset_Seq:
- {
- status = phDnldNfc_Send_Command( psDnldContext, pHwRef,
- PHDNLD_CMD_RESET , NULL , 0 );
- /* status = (NFCSTATUS_PENDING == status)? NFCSTATUS_SUCCESS:
- status; */
- DNLD_DEBUG(" FW_DNLD: Reset Seq.. Status = %X \n", status);
-
- break;
- }
- case phDnld_Activate_Patch:
- {
- uint8_t patch_activate = 0x01;
- psDnldContext->next_dnld_seq =
- (uint8_t)phDnld_Update_Patch;
-#ifdef NXP_FW_DNLD_CHECK_PHASE
- gphDnldPhase = NXP_FW_DNLD_SYSTEM_PHASE;
-#endif /* NXP_FW_DNLD_CHECK_PHASE */
-
- status = phDnldNfc_Send_Command( psDnldContext, pHwRef,
- PHDNLD_CMD_ACTIVATE_PATCH , &patch_activate, sizeof(patch_activate) );
- DNLD_PRINT(" FW_DNLD: Activate the Patch Update .... \n");
- break;
- }
- case phDnld_Deactivate_Patch:
- {
- uint8_t patch_activate = 0x00;
-
- psDnldContext->next_dnld_state =
- (uint8_t)phDnld_Reset_State;
-
- status = phDnldNfc_Send_Command( psDnldContext, pHwRef,
- PHDNLD_CMD_ACTIVATE_PATCH , &patch_activate, sizeof(patch_activate) );
- DNLD_PRINT(" FW_DNLD: Deactivate the Patch Update .... \n");
- break;
- }
- case phDnld_Update_Patch:
- {
- dnld_addr = NXP_DNLD_PATCH_ADDR;
- patch_size = sizeof(patch_data) ;
- p_data = patch_data;
- psDnldContext->next_dnld_seq =
- (uint8_t)phDnld_Update_Patchtable;
- DNLD_PRINT(" FW_DNLD: Patch Update Seq.... \n");
- break;
- }
- case phDnld_Update_Patchtable:
- {
- dnld_addr = NXP_DNLD_PATCH_TABLE_ADDR;
- patch_size = sizeof(patch_table) ;
- p_data = patch_table;
-
- psDnldContext->next_dnld_state =
- (uint8_t)phDnld_Reset_State;
-
- DNLD_PRINT(" FW_DNLD: Patch Table Update Seq.... \n");
- break;
- }
- case phDnld_Unlock_System:
- {
- dnld_addr = NXP_DNLD_SM_UNLOCK_ADDR;
- patch_size = sizeof(unlock_data) ;
- p_data = unlock_data;
-#define NXP_FW_PATCH_DISABLE
-#ifdef NXP_FW_PATCH_DISABLE
- psDnldContext->next_dnld_seq =
- (uint8_t)phDnld_Deactivate_Patch;
-#else
- psDnldContext->next_dnld_state =
- (uint8_t)phDnld_Reset_State;
-#endif
-
- DNLD_PRINT(" FW_DNLD: System Memory Unlock Seq.... \n");
- break;
- }
- case phDnld_Lock_System:
- {
- dnld_addr = NXP_DNLD_SM_UNLOCK_ADDR;
- patch_size = sizeof(lock_data) ;
- p_data = lock_data;
- psDnldContext->next_dnld_state =
- (uint8_t) phDnld_Reset_State;
-
- DNLD_PRINT(" FW_DNLD: System Memory Lock Seq.... \n");
- break;
- }
- case phDnld_Upgrade_Section:
- {
- status = phDnldNfc_Resume_Write(
- psDnldContext, pHwRef );
- break;
- }
- case phDnld_Verify_Integrity:
- {
- psDnldContext->next_dnld_state =
- (uint8_t) phDnld_Reset_State;
-
- status = phDnldNfc_Send_Command( psDnldContext, pHwRef,
- PHDNLD_CMD_CHECK_INTEGRITY , NULL, 0 );
- DNLD_PRINT(" FW_DNLD: System Memory Integrity Check Sequence.... \n");
- break;
- }
- case phDnld_Verify_Section:
- {
- break;
- }
- default:
- {
- break;
- }
- }
-
- if( NFCSTATUS_SUCCESS == status)
- {
-
- /* Update the LSB of the Data and the Address Parameter*/
- p_data_param->data_addr[i] = (uint8_t)((dnld_addr >>
- (BYTE_SIZE + BYTE_SIZE))
- & BYTE_MASK);
- p_data_param->data_len[i] = (uint8_t)((patch_size >> BYTE_SIZE)
- & BYTE_MASK);
- p_dnld_data->frame_length[i] = (uint8_t)
- (((patch_size + PHDNLD_CMD_WRITE_MIN_LEN) >> BYTE_SIZE)
- & BYTE_MASK);
- i++;
- /* Update the 2nd byte of the Data and the Address Parameter*/
- p_data_param->data_addr[i] = (uint8_t)((dnld_addr >> BYTE_SIZE)
- & BYTE_MASK);
- p_data_param->data_len[i] = (uint8_t) (patch_size & BYTE_MASK);
- p_dnld_data->frame_length[i] = (uint8_t)
- ((patch_size + PHDNLD_CMD_WRITE_MIN_LEN)
- & BYTE_MASK);
- i++;
- /* Update the 3rd byte of the the Address Parameter*/
- p_data_param->data_addr[i] = (uint8_t)(dnld_addr & BYTE_MASK);
-
- status = phDnldNfc_Send_Command( psDnldContext, pHwRef,
- PHDNLD_CMD_WRITE,(void *)p_data , (uint8_t)patch_size );
-
- if (NFCSTATUS_PENDING != status)
- {
- status = phDnldNfc_Set_Seq(psDnldContext,
- DNLD_SEQ_ROLLBACK);
- }
- }
- return status;
-}
-
-#define FRAME_HEADER_LEN 0x03U
-
-
-static
-void
-phDnldNfc_Tx_Reset(phDnldNfc_sContext_t *psDnldContext)
-{
- psDnldContext->tx_info.transmit_frame = NULL;
- psDnldContext->tx_info.tx_total = 0x00;
- psDnldContext->tx_info.tx_offset = 0x00;
- psDnldContext->tx_info.tx_len = 0x00;
- psDnldContext->tx_info.tx_chain = FALSE;
-}
-
-STATIC
-bool_t
-phDnldNfc_Extract_Chunks(
- uint8_t *frame_data,
- uint16_t frame_offset,
- uint16_t frame_length,
- uint16_t max_frame ,
- uint16_t *chunk_length
- );
-
-
-STATIC
-bool_t
-phDnldNfc_Extract_Chunks(
- uint8_t *frame_data,
- uint16_t frame_offset,
- uint16_t frame_length,
- uint16_t max_frame ,
- uint16_t *chunk_length
- )
-{
- bool_t chunk_present = FALSE;
-
- if( 0 == frame_offset)
- {
- if( max_frame >= (frame_length
- - frame_offset))
- {
- *chunk_length = (frame_length - frame_offset);
- }
- else
- {
- *chunk_length = max_frame
- - FRAME_HEADER_LEN;
- chunk_present = TRUE;
- }
- }
- else
- {
- if( max_frame >= (frame_length
- - frame_offset))
- {
- *chunk_length = (frame_length - frame_offset);
- }
- else
- {
- *chunk_length = max_frame
- - FRAME_HEADER_LEN;
- chunk_present = TRUE;
- }
- }
-
- return chunk_present;
-}
-
-
-STATIC
-NFCSTATUS
-phDnldNfc_Send_Raw(
- phDnldNfc_sContext_t *psDnldContext,
- void *pHwRef,
- uint8_t *raw_frame,
- uint16_t frame_offset,
- uint16_t frame_length
- )
-{
- NFCSTATUS status = NFCSTATUS_SUCCESS;
- phDnldNfc_sRawHdr_t *raw_frame_hdr = ( phDnldNfc_sRawHdr_t * ) raw_frame;
-
- switch(raw_frame_hdr->frame_type)
- {
- case PHDNLD_CMD_RESET:
- {
- break;
- }
- case PHDNLD_CMD_READ:
- {
- /* TODO: To Update the length and the buffer to receive data */
- break;
- }
- case PHDNLD_CMD_WRITE:
- {
- psDnldContext->resp_length = PHDNLD_MIN_PACKET;
-
- break;
- }
- case PHDNLD_CMD_SEC_WRITE:
- {
- uint16_t tx_length = 0x00;
- uint16_t frame_offset =
- psDnldContext->tx_info.tx_offset;
- uint16_t chain =
- psDnldContext->tx_info.tx_chain;
-
- chain =
- phDnldNfc_Extract_Chunks(
- raw_frame,
- frame_offset,
- frame_length,
- PHDNLD_FW_TX_RX_LEN,
- &tx_length
- );
-
- if( TRUE == chain )
- {
- status = phDnldNfc_Send_Command( psDnldContext,
- pHwRef, PHDNLD_CMD_ENCAPSULATE,
- (raw_frame + frame_offset),
- tx_length);
- if(NFCSTATUS_PENDING == status)
- {
- psDnldContext->prev_cmd = raw_frame_hdr->frame_type;
- /* TODO: Update for the Chaining */
- psDnldContext->tx_info.tx_offset += tx_length;
- psDnldContext->tx_info.tx_chain = chain;
- }
- }
- else if (0 != frame_offset)
- {
- status = phDnldNfc_Send_Command( psDnldContext,
- pHwRef, PHDNLD_CMD_ENCAPSULATE,
- (raw_frame + frame_offset),
- tx_length);
- if(NFCSTATUS_PENDING == status)
- {
- psDnldContext->prev_cmd = raw_frame_hdr->frame_type;
- /* TODO: Update for the Chaining */
- psDnldContext->prev_dnld_size = frame_length;
- phDnldNfc_Tx_Reset(psDnldContext);
- }
- }
- else
- {
- psDnldContext->resp_length = PHDNLD_MIN_PACKET;
- }
-
- break;
- }
- case PHDNLD_CMD_CHECK:
- {
- psDnldContext->resp_length = PHDNLD_MIN_PACKET;
- break;
- }
- case PHDNLD_CMD_SET_HIF:
- {
- psDnldContext->resp_length = PHDNLD_MIN_PACKET;
- break;
- }
- case PHDNLD_CMD_ACTIVATE_PATCH:
- {
- psDnldContext->resp_length = PHDNLD_MIN_PACKET;
- break;
- }
- case PHDNLD_CMD_CHECK_INTEGRITY:
- {
- uint8_t integrity_param =
- *(raw_frame + FRAME_HEADER_LEN);
- switch(integrity_param)
- {
- case CHK_INTEGRITY_CONFIG_PAGE_CRC:
- case CHK_INTEGRITY_PATCH_TABLE_CRC:
- {
- psDnldContext->resp_length = PHDNLD_MIN_PACKET
- + CHECK_INTEGRITY_RESP_CRC16_LEN;
- break;
- }
- case CHK_INTEGRITY_FLASH_CODE_CRC:
- case CHK_INTEGRITY_PATCH_CODE_CRC:
- {
- psDnldContext->resp_length = PHDNLD_MIN_PACKET
- + CHECK_INTEGRITY_RESP_CRC32_LEN;
- break;
- }
- case CHK_INTEGRITY_COMPLETE_CRC:
- default:
- {
- psDnldContext->resp_length = PHDNLD_MIN_PACKET
- + CHECK_INTEGRITY_RESP_COMP_LEN;
- break;
- }
- }
- break;
- }
- default:
- {
- status = PHNFCSTVAL(CID_NFC_DNLD, NFCSTATUS_FEATURE_NOT_SUPPORTED);
- break;
- }
- }
-
- if (NFCSTATUS_SUCCESS == status)
- {
- status = phDnldNfc_Send( psDnldContext, pHwRef ,
- raw_frame, frame_length);
-
- if(NFCSTATUS_PENDING == status)
- {
- psDnldContext->prev_cmd = raw_frame_hdr->frame_type;
- /* TODO: Update for the Chaining */
- psDnldContext->prev_dnld_size = frame_length;
- }
- }
-
- return status;
-}
-
-
-static
-NFCSTATUS
-phDnldNfc_Raw_Write(
- phDnldNfc_sContext_t *psDnldContext,
- void *pHwRef
- )
-{
- NFCSTATUS status = NFCSTATUS_SUCCESS;
- uint32_t dnld_index = psDnldContext->dnld_index;
- uint32_t tx_length = 0;
- uint8_t *p_raw_sec_hdr = NULL;
- uint8_t dnld_flag = FALSE;
- uint8_t skip_frame = FALSE;
-
- if(NULL != psDnldContext->p_fw_raw)
- {
-
- if( (TRUE != psDnldContext->tx_info.tx_chain)
- && (0x00 == psDnldContext->dnld_retry)
- )
- {
- dnld_index = dnld_index + psDnldContext->prev_dnld_size;
- p_raw_sec_hdr = psDnldContext->p_fw_raw + dnld_index;
- dnld_index = dnld_index + *p_raw_sec_hdr;
- }
- else
- {
- phDnldNfc_sData_Hdr_t *p_dnld_raw = (phDnldNfc_sData_Hdr_t *)
- (psDnldContext->p_fw_raw +
- psDnldContext->dnld_index);
-
- tx_length = ((p_dnld_raw->frame_length[0] << BYTE_SIZE) |
- p_dnld_raw->frame_length[1]);
-
- tx_length = tx_length + PHDNLD_MIN_PACKET;
-
- status = phDnldNfc_Send_Raw( psDnldContext, pHwRef,
- (uint8_t *)(p_dnld_raw),
- psDnldContext->tx_info.tx_offset,
- (uint16_t)tx_length);
- }
-
-
-#define PHDNLD_MAJOR_OFFSET 0x04U
-#define PHDNLD_MINOR_OFFSET 0x05U
-#define PHDNLD_PHASE_OFFSET 0x06U
-#define PHDNLD_FRAMETYPE_OFFSET 0x07U
-
-#define PHDNLD_NO_OPERATION 0x00U
-#define PHDNLD_NORMAL_OPERATION 0x10U
-#define PHDNLD_ADVANCED_OPERATION 0x20U
-#define PHDNLD_SETUP_OPERATION 0x40U
-#define PHDNLD_RECOVER_OPERATION 0x80U
-#define PHDNLD_COMPLETE_OPERATION 0xF0U
-
-#define PHDNLD_TERMINATE_TYPE 0x0EU
-
-#define PHDNLD_MARKER_MASK 0x0FU
-
- while((NFCSTATUS_SUCCESS == status )
- && (FALSE == dnld_flag)
- )
- {
- phDnldNfc_sData_Hdr_t *p_dnld_raw = (phDnldNfc_sData_Hdr_t *)
- (psDnldContext->p_fw_raw + dnld_index);
- uint8_t frame_type = *(p_raw_sec_hdr + PHDNLD_FRAMETYPE_OFFSET);
-
- tx_length = ((p_dnld_raw->frame_length[0] << BYTE_SIZE) |
- p_dnld_raw->frame_length[1]);
-
- tx_length = tx_length + PHDNLD_MIN_PACKET;
-
- skip_frame = FALSE;
-
- if( (0x00 == *(p_raw_sec_hdr + PHDNLD_PHASE_OFFSET))
- || (0xFF == *(p_raw_sec_hdr + PHDNLD_PHASE_OFFSET))
- || !( psDnldContext->raw_mode_upgrade
- & (frame_type & (~PHDNLD_MARKER_MASK)) )
- )
- {
- dnld_index = dnld_index + tx_length;
- p_raw_sec_hdr = psDnldContext->p_fw_raw + dnld_index;
- dnld_index = dnld_index + *p_raw_sec_hdr;
- skip_frame = TRUE;
- }
- if (PHDNLD_TERMINATE_TYPE ==
- (frame_type & PHDNLD_MARKER_MASK))
- {
- if(TRUE != skip_frame)
- {
- psDnldContext->raw_mode_upgrade =
- (psDnldContext->raw_mode_upgrade &
- ~(frame_type & ~PHDNLD_MARKER_MASK));
- }
-
- if(PHDNLD_NO_OPERATION ==
- psDnldContext->raw_mode_upgrade)
- {
- dnld_flag = TRUE;
- }
- }
- else
- {
-
- }
-
- if((FALSE == skip_frame)
- && (FALSE == dnld_flag)
- )
- {
- status = phDnldNfc_Send_Raw( psDnldContext, pHwRef,
- (uint8_t *)(p_dnld_raw),
- psDnldContext->tx_info.tx_offset,
- (uint16_t)tx_length);
- }
-
- if( NFCSTATUS_PENDING == status )
- {
- psDnldContext->dnld_index = dnld_index;
- psDnldContext->cur_frame_info= frame_type;
- }
- }
- }
-
- return status;
-}
-
-static
-NFCSTATUS
-phDnldNfc_Upgrade_Sequence(
- phDnldNfc_sContext_t *psDnldContext,
- void *pHwRef,
- void *pdata,
- uint16_t length
- )
-{
- NFCSTATUS status = NFCSTATUS_SUCCESS;
-
- PHNFC_UNUSED_VARIABLE(pdata);
- PHNFC_UNUSED_VARIABLE(length);
-
- if(phDnld_Raw_Upgrade == psDnldContext->cur_dnld_seq)
- {
- status = phDnldNfc_Raw_Write( psDnldContext, pHwRef );
- }
- else
- {
- status = phDnldNfc_Resume_Write( psDnldContext, pHwRef );
- }
-
- return status;
-}
-
-
-
-static
-NFCSTATUS
-phDnldNfc_Resume(
- phDnldNfc_sContext_t *psDnldContext,
- void *pHwRef,
- void *pdata,
- uint16_t length
- )
-{
- NFCSTATUS status = NFCSTATUS_SUCCESS;
- phDnldNfc_eState_t dnld_next_state = (phDnldNfc_eState_t)
- psDnldContext->cur_dnld_state;
- phNfc_sCompletionInfo_t comp_info = {0,0,0};
-
- switch( dnld_next_state )
- {
- case phDnld_Reset_State:
- {
- status = phDnldNfc_Send_Command( psDnldContext, pHwRef,
- PHDNLD_CMD_RESET , NULL, 0 );
- switch( psDnldContext->cur_dnld_seq )
- {
- case phDnld_Update_Patchtable:
- {
- psDnldContext->next_dnld_state =
- (uint8_t)phDnld_Unlock_State;
- psDnldContext->next_dnld_seq =
- (uint8_t)phDnld_Unlock_System;
- break;
- }
-#ifdef NXP_FW_PATCH_DISABLE
- case phDnld_Deactivate_Patch:
-#else
- case phDnld_Unlock_System:
-#endif
- {
- psDnldContext->next_dnld_state =
- (uint8_t)phDnld_Upgrade_State;
- psDnldContext->next_dnld_seq =
- (uint8_t)phDnld_Upgrade_Section;
-#ifdef NXP_FW_DNLD_CHECK_PHASE
- gphDnldPhase = NXP_FW_DNLD_CFG_PHASE;
-#endif /* NXP_FW_DNLD_CHECK_PHASE */
- break;
- }
- case phDnld_Lock_System:
- {
-#if (NXP_FW_INTEGRITY_CHK >= 0x01)
- psDnldContext->next_dnld_state =
- (uint8_t)phDnld_Verify_State;
- psDnldContext->next_dnld_seq =
- (uint8_t)phDnld_Verify_Integrity;
-#else
- /* (void ) memset( (void *) &psDnldContext->chk_integrity_crc,
- 0, sizeof(psDnldContext->chk_integrity_crc)); */
- psDnldContext->next_dnld_state =
- (uint8_t) phDnld_Complete_State;
-#endif /* #if (NXP_FW_INTEGRITY_CHK >= 0x01) */
- break;
- }
- case phDnld_Verify_Integrity:
- {
- psDnldContext->next_dnld_state =
- (uint8_t) phDnld_Complete_State;
- break;
- }
- default:
- {
- status = (NFCSTATUS_PENDING == status)?
- NFCSTATUS_SUCCESS: status;
- break;
- }
- }
- break;
- }
- case phDnld_Unlock_State:
- {
-
- status = phDnldNfc_Sequence( psDnldContext, pHwRef,
- pdata, length);
- break;
- }
- case phDnld_Upgrade_State:
- {
- status = phDnldNfc_Upgrade_Sequence( psDnldContext, pHwRef,
- pdata, length);
- if ((NFCSTATUS_SUCCESS == status )
- && (phDnld_Complete_State == psDnldContext->next_dnld_state))
- {
-#if 0
- psDnldContext->cur_dnld_seq =
- (uint8_t)phDnld_Lock_System;
- psDnldContext->next_dnld_seq =
- psDnldContext->cur_dnld_seq;
-#endif
-#if (NXP_FW_INTEGRITY_CHK >= 0x01)
- psDnldContext->next_dnld_state =
- (uint8_t)phDnld_Verify_State;
- psDnldContext->next_dnld_seq =
- (uint8_t)phDnld_Verify_Integrity;
- psDnldContext->cur_dnld_seq =
- psDnldContext->next_dnld_seq;
- status = phDnldNfc_Sequence( psDnldContext,
- pHwRef, pdata, length);
-#else
- /* (void ) memset( (void *) &psDnldContext->chk_integrity_crc,
- 0, sizeof(psDnldContext->chk_integrity_crc)); */
- psDnldContext->next_dnld_state =
- (uint8_t) phDnld_Complete_State;
-#endif /* #if (NXP_FW_INTEGRITY_CHK >= 0x01) */
- }
- break;
- }
- case phDnld_Verify_State:
- {
- status = phDnldNfc_Sequence( psDnldContext,
- pHwRef, pdata, length);
- break;
- }
- case phDnld_Complete_State:
- {
- uint8_t integrity_chk = 0xA5;
-
-#if (NXP_FW_INTEGRITY_CHK >= 0x01)
- uint8_t verify_crc = 0x96;
-
- if ( (NULL != psDnldContext->p_flash_code_crc)
- && (NULL != psDnldContext->p_patch_code_crc)
- && (NULL != psDnldContext->p_patch_table_crc)
- )
- {
- uint8_t crc_i = 0;
- uint16_t patch_table_crc = 0;
- uint32_t flash_code_crc = 0;
- uint32_t patch_code_crc = 0;
-
- for (crc_i = 0; crc_i < DNLD_CRC32_SIZE; crc_i++ )
- {
- if (crc_i < DNLD_CRC16_SIZE )
- {
- patch_table_crc = patch_table_crc
- | psDnldContext->chk_integrity_crc.patch_table.Chk_Crc16[crc_i]
- << (crc_i * BYTE_SIZE) ;
- }
- flash_code_crc = flash_code_crc
- | psDnldContext->chk_integrity_crc.flash_code.Chk_Crc32[crc_i]
- << (crc_i * BYTE_SIZE) ;
- patch_code_crc = patch_code_crc
- | psDnldContext->chk_integrity_crc.patch_code.Chk_Crc32[crc_i]
- << (crc_i * BYTE_SIZE) ;
- }
- verify_crc =(uint8_t)( (*((uint32_t *) psDnldContext->p_flash_code_crc)) !=
- flash_code_crc );
- verify_crc |=(uint8_t)( (*((uint32_t *) psDnldContext->p_patch_code_crc)) !=
- patch_code_crc );
- verify_crc |=(uint8_t)( (*((uint16_t *) psDnldContext->p_patch_table_crc)) !=
- patch_table_crc );
- }
- else
- {
- DNLD_PRINT(" FW_DNLD: Flash, Patch code and Patch Table CRC ");
- DNLD_PRINT(" Not Available in the Firmware \n");
- }
-
-#endif /* #if (NXP_FW_INTEGRITY_CHK >= 0x01) */
-
- integrity_chk = psDnldContext->chk_integrity_crc.config_page.Chk_status +
- psDnldContext->chk_integrity_crc.patch_table.Chk_status +
- psDnldContext->chk_integrity_crc.flash_code.Chk_status +
- psDnldContext->chk_integrity_crc.patch_code.Chk_status;
-
- if ( ( 0 != integrity_chk )
-#if (NXP_FW_INTEGRITY_CHK >= 0x01)
- || ( 0 != verify_crc )
-#endif /* #if (NXP_FW_INTEGRITY_CHK >= 0x01) */
- )
- {
- status = PHNFCSTVAL(CID_NFC_DNLD, NFCSTATUS_FAILED);
- }
- break;
- }
- default:
- {
- status = PHNFCSTVAL(CID_NFC_DNLD, NFCSTATUS_FAILED);
- break;
- }
- }
-
- if (NFCSTATUS_PENDING == status)
- {
- /* Write/Receive is still pending */
- }
- else
- {
- pphNfcIF_Notification_CB_t p_upper_notify =
- psDnldContext->p_upper_notify;
- void *p_upper_context =
- psDnldContext->p_upper_context;
-
- DNLD_DEBUG(" FW_DNLD: Resume Termination Status = %X \n", status);
-
- comp_info.status = status;
-
- (void) phDal4Nfc_Unregister(
- psDnldContext->lower_interface.pcontext, pHwRef);
- phDnldNfc_Release_Lower(psDnldContext, pHwRef);
- phDnldNfc_Release_Resources(&psDnldContext);
-#ifndef NFC_TIMER_CONTEXT
- gpphDnldContext = psDnldContext;
-#endif
- /* Notify the Error/Success Scenario to the upper layer */
- phDnldNfc_Notify( p_upper_notify, p_upper_context, pHwRef, (uint8_t)
- ((NFCSTATUS_SUCCESS == comp_info.status )? NFC_IO_SUCCESS: NFC_IO_ERROR),
- &comp_info );
- }
- return status;
-}
-
-STATIC
-NFCSTATUS
-phDnldNfc_Process_Response(
- phDnldNfc_sContext_t *psDnldContext,
- void *pHwRef,
- void *pdata,
- uint16_t length
- )
-{
- NFCSTATUS status = NFCSTATUS_SUCCESS;
- phDnldNfc_sData_Hdr_t *resp_data =
- (phDnldNfc_sData_Hdr_t *) pdata;
-
- PHNFC_UNUSED_VARIABLE(pHwRef);
- DNLD_DEBUG(" FW_DNLD: Receive Length = %X \n", length );
- if(( psDnldContext->rx_info.rx_total == 0 )
- && (PHDNLD_MIN_PACKET <= length)
- )
- {
- psDnldContext->rx_info.rx_total =
- ((uint16_t)resp_data->frame_length[0] << BYTE_SIZE)|
- resp_data->frame_length[1];
- if( psDnldContext->rx_info.rx_total + PHDNLD_MIN_PACKET == length )
- {
-
- DNLD_DEBUG(" FW_DNLD: Success Memory Read = %X \n",
- psDnldContext->rx_info.rx_total);
-#ifndef DNLD_SUMMARY
- /* DNLD_PRINT_BUFFER("Receive Buffer",pdata,length); */
-#endif
-
- }
- else
- {
- /* status = phDnldNfc_Receive( psDnldContext, pHwRef,
- psDnldContext->p_resp_buffer,
- (uint8_t)((psDnldContext->rx_info.rx_total <= PHDNLD_MAX_PACKET)?
- psDnldContext->rx_info.rx_total: PHDNLD_MAX_PACKET) ); */
- DNLD_PRINT(" FW_DNLD: Invalid Receive length ");
- DNLD_DEBUG(": Length Expected = %X \n",
- (psDnldContext->rx_info.rx_total + PHDNLD_MIN_PACKET));
- status = PHNFCSTVAL( CID_NFC_DNLD,
- NFCSTATUS_INVALID_RECEIVE_LENGTH );
- }
- }
- else
- {
- /*TODO:*/
- psDnldContext->rx_info.rx_total = 0 ;
- status = PHNFCSTVAL( CID_NFC_DNLD,
- NFCSTATUS_INVALID_RECEIVE_LENGTH );
- }
-
- return status;
-}
-
-
-
-STATIC
-void
-phDnldNfc_Receive_Complete (
- void *psContext,
- void *pHwRef,
- phNfc_sTransactionInfo_t *pInfo
- )
-{
- NFCSTATUS status = NFCSTATUS_SUCCESS ;
- void *pdata = NULL ;
- phDnldNfc_sData_Hdr_t *resp_data = NULL;
- uint16_t length = 0 ;
- phNfc_sCompletionInfo_t comp_info = {0,0,0};
-
- DNLD_PRINT("\n FW_DNLD: Receive Response .... ");
- if ( (NULL != psContext)
- && (NULL != pInfo)
- && (NULL != pHwRef)
- )
- {
- phDnldNfc_sContext_t *psDnldContext =
- (phDnldNfc_sContext_t *)psContext;
- status = pInfo->status ;
- length = pInfo->length ;
- pdata = pInfo->buffer;
-
- if(status != NFCSTATUS_SUCCESS)
- {
- DNLD_DEBUG(" Failed. Status = %02X\n",status);
- /* Handle the Error Scenario */
- }
- else if (NULL == pdata)
- {
- DNLD_DEBUG(" Failed. No data received. pdata = %02X\n",pdata);
- /* Handle the Error Scenario */
- status = PHNFCSTVAL( CID_NFC_DNLD, NFCSTATUS_FAILED );
- }
- else if ((0 == length)
- || (PHDNLD_MIN_PACKET > length ))
- {
- DNLD_DEBUG(" Receive Response Length = %u .... \n",length);
- /* Handle the Error Scenario */
-#ifndef HAL_SW_DNLD_RLEN
- status = PHNFCSTVAL( CID_NFC_DNLD,
- NFCSTATUS_INVALID_RECEIVE_LENGTH );
-#endif
- }
- else
- {
-
-#if defined(FW_DOWNLOAD_TIMER) && \
- (FW_DOWNLOAD_TIMER == 2)
- if ( NXP_INVALID_TIMER_ID != psDnldContext->timer_id )
- {
- phOsalNfc_Timer_Stop( psDnldContext->timer_id );
- }
-
-#endif
-
-#ifndef DNLD_SUMMARY
- DNLD_PRINT_BUFFER("Receive Buffer",pdata,length);
-#endif
- DNLD_DEBUG(" Receive Response Length = %X. \n", length);
-
- resp_data = (phDnldNfc_sData_Hdr_t *) pdata;
-
- switch(resp_data->frame_type)
- {
- case PHDNLD_RESP_SUCCESS:
- {
- uint16_t resp_length =
- ((uint16_t)resp_data->frame_length[0] << BYTE_SIZE)|
- resp_data->frame_length[1];
- switch ( psDnldContext->prev_cmd )
- {
- case PHDNLD_CMD_READ :
- {
- if( PHDNLD_NO_OPERATION
- == psDnldContext->raw_mode_upgrade)
- {
- status = phDnldNfc_Process_Response(
- psDnldContext, pHwRef, pdata , length);
-
- if (NFCSTATUS_SUCCESS != status)
- {
- /* psDnldContext->dnld_retry++; */
- psDnldContext->dnld_retry = NXP_MAX_DNLD_RETRY;
- /* psDnldContext->dnld_retry < NXP_MAX_DNLD_RETRY */
- }
- }
- else
- {
-
- }
- break;
- }
- case PHDNLD_CMD_CHECK_INTEGRITY :
- {
- if( PHDNLD_NO_OPERATION
- == psDnldContext->raw_mode_upgrade)
- {
-#if (NXP_FW_INTEGRITY_CHK >= 0x01)
- phDnldNfc_sChkCrcComplete_t *p_dnld_crc_all =
- &psDnldContext->chk_integrity_crc;
- switch(psDnldContext->chk_integrity_param)
- {
- case CHK_INTEGRITY_CONFIG_PAGE_CRC:
- {
- (void)memcpy(&p_dnld_crc_all->config_page,
- (((uint8_t *)pdata) + PHDNLD_MIN_PACKET), resp_length);
- break;
- }
- case CHK_INTEGRITY_PATCH_TABLE_CRC:
- {
- (void)memcpy(&p_dnld_crc_all->patch_table,
- (((uint8_t *)pdata) + PHDNLD_MIN_PACKET), resp_length);
- break;
- }
- case CHK_INTEGRITY_FLASH_CODE_CRC:
- {
- (void)memcpy(&p_dnld_crc_all->flash_code,
- (((uint8_t *)pdata) + PHDNLD_MIN_PACKET), resp_length);
- break;
- }
- case CHK_INTEGRITY_PATCH_CODE_CRC:
- {
- (void)memcpy(&p_dnld_crc_all->patch_code,
- (((uint8_t *)pdata) + PHDNLD_MIN_PACKET), resp_length);
- break;
- }
- case CHK_INTEGRITY_COMPLETE_CRC:
- {
- (void)memcpy(p_dnld_crc_all,
- (((uint8_t *)pdata) + PHDNLD_MIN_PACKET), resp_length);
- DNLD_DEBUG(" FW_DNLD: Check Integrity Complete Structure Size = %X \n",
- sizeof(psDnldContext->chk_integrity_crc));
- break;
- }
- default:
- {
- status = PHNFCSTVAL(CID_NFC_DNLD,
- NFCSTATUS_FEATURE_NOT_SUPPORTED);
- break;
- }
- }
-#endif /* #if (NXP_FW_INTEGRITY_CHK >= 0x01) */
- }
- else
- {
- psDnldContext->raw_mode_upgrade =
- (PHDNLD_SETUP_OPERATION | PHDNLD_ADVANCED_OPERATION);
- /* psDnldContext->raw_mode_upgrade =
- (psDnldContext->raw_mode_upgrade &
- ( psDnldContext->cur_frame_info & ~PHDNLD_MARKER_MASK )); */
- }
- break;
- }
- case PHDNLD_CMD_WRITE:
- {
- psDnldContext->dnld_retry = 0;
- break;
- }
- case PHDNLD_CMD_SEC_WRITE:
- {
- psDnldContext->dnld_retry = 0;
- break;
- }
- case PHDNLD_CMD_ACTIVATE_PATCH:
- case PHDNLD_CMD_CHECK:
- default:
- {
- if( PHDNLD_NO_OPERATION
- == psDnldContext->raw_mode_upgrade)
- {
- if( ( (PHDNLD_MIN_PACKET > length)
- || ( 0 != resp_length) )
- )
- {
- psDnldContext->dnld_retry = NXP_MAX_DNLD_RETRY;
- status = PHNFCSTVAL( CID_NFC_DNLD,
- NFCSTATUS_INVALID_RECEIVE_LENGTH );
- }
- else
- {
- psDnldContext->dnld_retry = 0;
- }
- }
- else
- {
- psDnldContext->raw_mode_upgrade =
- (psDnldContext->raw_mode_upgrade & ~PHDNLD_RECOVER_OPERATION);
- }
- break;
- }
- } /* End of the Previous Command Switch Case */
- break;
- }/* Case PHDNLD_RESP_SUCCESS*/
- case PHDNLD_RESP_TIMEOUT:
- case PHDNLD_RESP_CRC_ERROR:
- case PHDNLD_RESP_WRITE_ERROR:
- {
- if(psDnldContext->dnld_retry < NXP_MAX_DNLD_RETRY )
- {
- psDnldContext->dnld_retry++;
- }
- status = PHNFCSTVAL(CID_NFC_DNLD,
- resp_data->frame_type);
- break;
- }
- /* fall through */
- case PHDNLD_RESP_ACCESS_DENIED:
- case PHDNLD_RESP_INVALID_PARAMETER:
- case PHDNLD_RESP_INVALID_LENGTH:
- /* Initial Frame Checksum */
- case PHDNLD_RESP_CHKSUM_ERROR:
- case PHDNLD_RESP_MEMORY_UPDATE_ERROR:
- {
- psDnldContext->dnld_retry = NXP_MAX_DNLD_RETRY;
- status = PHNFCSTVAL(CID_NFC_DNLD,
- resp_data->frame_type);
- break;
- }
- case PHDNLD_RESP_PROTOCOL_ERROR:
- {
- if(( PHDNLD_NO_OPERATION
- == psDnldContext->raw_mode_upgrade)
- || ( PHDNLD_ADVANCED_OPERATION
- == psDnldContext->raw_mode_upgrade)
- )
- {
- psDnldContext->dnld_retry = NXP_MAX_DNLD_RETRY;
- status = PHNFCSTVAL(CID_NFC_DNLD,
- NFCSTATUS_INVALID_FORMAT);
- }
- else if( (PHDNLD_NORMAL_OPERATION
- & psDnldContext->raw_mode_upgrade)
- )
- {
- psDnldContext->raw_mode_upgrade =
- (psDnldContext->raw_mode_upgrade & ~PHDNLD_NORMAL_OPERATION);
- }
- else if ( PHDNLD_RECOVER_OPERATION
- & psDnldContext->raw_mode_upgrade )
- {
- psDnldContext->dnld_retry = NXP_MAX_DNLD_RETRY;
- status = PHNFCSTVAL(CID_NFC_DNLD,
- NFCSTATUS_INVALID_FORMAT);
- }
- else
- {
- psDnldContext->raw_mode_upgrade =
- (psDnldContext->raw_mode_upgrade &
- ~( psDnldContext->cur_frame_info & ~PHDNLD_MARKER_MASK ));
- }
- break;
- }
- case PHDNLD_RESP_VERSION_UPTODATE:
- {
- /* TODO: to make sure that the Advance Frames are sent to get
- * the updated status */
- if ( PHDNLD_ADVANCED_OPERATION
- == psDnldContext->raw_mode_upgrade)
- {
- status = ( CID_NFC_DNLD << BYTE_SIZE ) ;
- }
- else if ( PHDNLD_NO_OPERATION
- != psDnldContext->raw_mode_upgrade)
- {
-
- psDnldContext->raw_mode_upgrade =
- (psDnldContext->raw_mode_upgrade &
- ~( psDnldContext->cur_frame_info & ~PHDNLD_MARKER_MASK ));
- }
- else
- {
- }
- break;
- }
- case PHDNLD_RESP_CMD_NOT_SUPPORTED:
- {
-
- if ( PHDNLD_NO_OPERATION
- == psDnldContext->raw_mode_upgrade)
- {
- status = PHNFCSTVAL(CID_NFC_DNLD,
- NFCSTATUS_FEATURE_NOT_SUPPORTED);
- }
- else if ( PHDNLD_ADVANCED_OPERATION
- == psDnldContext->raw_mode_upgrade)
- {
- status = PHNFCSTVAL(CID_NFC_DNLD,
- NFCSTATUS_FEATURE_NOT_SUPPORTED);
- }
-#if 0
- else if( (PHDNLD_NORMAL_OPERATION
- & psDnldContext->raw_mode_upgrade)
- )
- {
- psDnldContext->raw_mode_upgrade =
- (psDnldContext->raw_mode_upgrade & ~PHDNLD_NORMAL_OPERATION);
- }
- else if ( PHDNLD_SETUP_OPERATION
- & psDnldContext->raw_mode_upgrade )
- {
- psDnldContext->raw_mode_upgrade =
- (psDnldContext->raw_mode_upgrade & ~PHDNLD_SETUP_OPERATION);
- }
-#endif
- else
- {
- psDnldContext->raw_mode_upgrade =
- (psDnldContext->raw_mode_upgrade &
- ~( psDnldContext->cur_frame_info & ~PHDNLD_MARKER_MASK ));
- }
- break;
- }
- /* The Chaining of the Command Frame
- was Successful in the Download Mode */
- case PHDNLD_RESP_CHAINING_SUCCESS:
- {
- /* TODO: Handle the Corner Case Scenarios
- * the updated status */
- psDnldContext->dnld_retry = 0x00;
- break;
- }
-/* The Error during the Chaining the Command Frame in the Download Mode */
- case PHDNLD_RESP_CHAINING_ERROR:
- {
- /* TODO: Restart the Chunk in Corner Case
- * the updated status */
- psDnldContext->dnld_retry++;
- phDnldNfc_Tx_Reset(psDnldContext);
- break;
- }
-/* The Command is not allowed anymore in the Download Mode */
- case PHDNLD_RESP_CMD_NOT_ALLOWED:
- default:
- {
- psDnldContext->dnld_retry = NXP_MAX_DNLD_RETRY;
- status = PHNFCSTVAL(CID_NFC_DNLD,
- NFCSTATUS_NOT_ALLOWED);
- break;
- }
-
- } /* End of the Response Frame Type Switch */
-
- if (NFCSTATUS_PENDING != status)
- {
- if ((NFCSTATUS_SUCCESS != status) &&
- (psDnldContext->dnld_retry >= NXP_MAX_DNLD_RETRY))
- {
- pphNfcIF_Notification_CB_t p_upper_notify =
- psDnldContext->p_upper_notify;
- void *p_upper_context =
- psDnldContext->p_upper_context;
-
- comp_info.status = status;
- DNLD_DEBUG(" FW_DNLD: Termination in Receive, Status = %X \n", status);
- status = phDal4Nfc_Unregister(
- psDnldContext->lower_interface.pcontext, pHwRef);
- phDnldNfc_Release_Lower(psDnldContext, pHwRef);
- phDnldNfc_Release_Resources(&psDnldContext);
-#ifndef NFC_TIMER_CONTEXT
- gpphDnldContext = psDnldContext;
-#endif
- /* Notify the Error/Success Scenario to the upper layer */
- phDnldNfc_Notify( p_upper_notify, p_upper_context, pHwRef,
- (uint8_t) NFC_IO_ERROR, &comp_info );
- }
- else if ( (NFCSTATUS_SUCCESS != status) &&
- (NFCSTATUS_SUCCESS == PHNFCSTATUS(status))
- )
- {
- pphNfcIF_Notification_CB_t p_upper_notify =
- psDnldContext->p_upper_notify;
- void *p_upper_context =
- psDnldContext->p_upper_context;
-
- comp_info.status = NFCSTATUS_SUCCESS;
- DNLD_DEBUG(" FW_DNLD: Termination in Receive, Status = %X \n", status);
- status = phDal4Nfc_Unregister(
- psDnldContext->lower_interface.pcontext, pHwRef);
- phDnldNfc_Release_Lower(psDnldContext, pHwRef);
- phDnldNfc_Release_Resources(&psDnldContext);
-#ifndef NFC_TIMER_CONTEXT
- gpphDnldContext = psDnldContext;
-#endif
- /* Notify the Error/Success Scenario to the upper layer */
- phDnldNfc_Notify( p_upper_notify, p_upper_context, pHwRef,
- (uint8_t) NFC_IO_SUCCESS, &comp_info );
-
- }
- else if (NFCSTATUS_FEATURE_NOT_SUPPORTED == PHNFCSTATUS(status))
- {
- pphNfcIF_Notification_CB_t p_upper_notify =
- psDnldContext->p_upper_notify;
- void *p_upper_context =
- psDnldContext->p_upper_context;
-
- comp_info.status = status;
- DNLD_DEBUG(" FW_DNLD: Termination in Receive, Status = %X \n", status);
- status = phDal4Nfc_Unregister(
- psDnldContext->lower_interface.pcontext, pHwRef);
- phDnldNfc_Release_Lower(psDnldContext, pHwRef);
- phDnldNfc_Release_Resources(&psDnldContext);
-#ifndef NFC_TIMER_CONTEXT
- gpphDnldContext = psDnldContext;
-#endif
- /* Notify the Error/Success Scenario to the upper layer */
- phDnldNfc_Notify( p_upper_notify, p_upper_context, pHwRef,
- (uint8_t) NFC_IO_SUCCESS, &comp_info );
-
- }
- else
- {
- /* DNLD_PRINT(" FW_DNLD: Successful.\n"); */
- psDnldContext->resp_length = /* PHDNLD_MIN_PACKET */ 0 ;
- status = phDnldNfc_Set_Seq(psDnldContext,
- DNLD_SEQ_UPDATE);
- status = phDnldNfc_Resume( psDnldContext,
- pHwRef, pdata, length );
- }
- }
- } /* End of status != Success */
- }
-}
-
-
-STATIC
-void
-phDnldNfc_Send_Complete (
- void *psContext,
- void *pHwRef,
- phNfc_sTransactionInfo_t *pInfo
- )
-{
- NFCSTATUS status = NFCSTATUS_SUCCESS ;
- uint16_t length = 0;
-
- DNLD_PRINT(" FW_DNLD: Send Data .... ");
- if ( (NULL != psContext)
- && (NULL != pInfo)
- && (NULL != pHwRef)
- )
- {
- phDnldNfc_sContext_t *psDnldContext =
- (phDnldNfc_sContext_t *)psContext;
- status = pInfo->status ;
- length = pInfo->length ;
- if(status != NFCSTATUS_SUCCESS)
- {
- DNLD_DEBUG(" Failed. Status = %02X\n",status);
- /* Handle the Error Scenario */
- }
- else
- {
- DNLD_PRINT(" Successful.\n");
- (void)memset((void *)&psDnldContext->dnld_data, 0,
- sizeof(psDnldContext->dnld_data));
- if ((PHDNLD_CMD_SET_HIF != psDnldContext->prev_cmd)
- && (PHDNLD_CMD_RESET != psDnldContext->prev_cmd))
- {
- psDnldContext->rx_info.rx_total = 0;
- status = phDnldNfc_Receive( psDnldContext, pHwRef,
- (uint8_t *)(&psDnldContext->dnld_resp),
- psDnldContext->resp_length);
- }
- else
- {
- psDnldContext->resp_length = 0;
- psDnldContext->dnld_retry = 0;
- /* clock unstable after SW reset command, especially on UART
- * platform because of its sensitivity to clock. Experimentally
- * we found clock unstable for 750us. Delay for 5ms to be sure.
- */
- if( PHDNLD_CMD_RESET == psDnldContext->prev_cmd )
- {
- DO_DELAY(PHDNLD_DNLD_DELAY);
- }
-#if defined(FW_DOWNLOAD_TIMER) && \
- (FW_DOWNLOAD_TIMER == 2)
-
- if ( NXP_INVALID_TIMER_ID != psDnldContext->timer_id )
- {
- phOsalNfc_Timer_Stop( psDnldContext->timer_id );
- }
-#endif
-
- status = phDnldNfc_Set_Seq(psDnldContext,
- DNLD_SEQ_UPDATE);
- }
-
- if(NFCSTATUS_SUCCESS == status )
- {
- status = phDnldNfc_Resume( psDnldContext, pHwRef, NULL, length);
- }
-
- } /* End of status != Success */
-
- } /* End of Context != NULL */
-}
-
-
-
-STATIC
-NFCSTATUS
-phDnldNfc_Send_Command(
- phDnldNfc_sContext_t *psDnldContext,
- void *pHwRef,
- uint8_t cmd,
- void *params,
- uint16_t param_length
- )
-{
- NFCSTATUS status = NFCSTATUS_SUCCESS;
- uint16_t tx_length = 0;
- uint16_t rx_length = 0;
- uint8_t **pp_resp_data = &psDnldContext->p_resp_buffer;
- phDnldNfc_sData_t *p_dnld_data =
- (phDnldNfc_sData_t *)psDnldContext->dnld_data;
-
- switch(cmd)
- {
- case PHDNLD_CMD_RESET:
- {
- (void)memset((void *)&psDnldContext->dnld_data, 0,
- sizeof(psDnldContext->dnld_data));
- break;
- }
- case PHDNLD_CMD_READ:
- {
- phDnldNfc_sData_t *p_dnld_data =
- (phDnldNfc_sData_t *)psDnldContext->dnld_data;
- phDnldNfc_sParam_t *param_info = /* (phDnldNfc_sParam_t *)params */
- &p_dnld_data->param_info.data_param;
- tx_length = PHDNLD_CMD_READ_LEN;
- if (NULL != *pp_resp_data)
- {
- phOsalNfc_FreeMemory(*pp_resp_data);
- *pp_resp_data = NULL;
- }
- rx_length = (uint16_t) (((uint16_t)param_info->data_len[0]
- << BYTE_SIZE) + param_info->data_len[1]);
-
- psDnldContext->resp_length =
- (( rx_length + PHDNLD_MIN_PACKET ));
- (void)phDnldNfc_Allocate_Resource( (void **) pp_resp_data,
- rx_length);
- break;
- }
- case PHDNLD_CMD_WRITE:
- case PHDNLD_CMD_SEC_WRITE:
- {
- phDnldNfc_sData_t *p_dnld_data =
- (phDnldNfc_sData_t *)psDnldContext->dnld_data;
- phDnldNfc_sParam_t *param_info = /* (phDnldNfc_sParam_t *)params */
- &p_dnld_data->param_info.data_param;
- tx_length = (uint16_t) (((uint16_t)param_info->data_len[0]
- << BYTE_SIZE) + param_info->data_len[1]
- + PHDNLD_CMD_WRITE_MIN_LEN );
-
- psDnldContext->resp_length = PHDNLD_MIN_PACKET;
- if ((0 != param_length) && (NULL != params))
- {
- (void)memcpy(param_info->data_packet, params, param_length);
- }
- break;
- }
- case PHDNLD_CMD_CHECK:
- {
- tx_length = PHDNLD_CMD_CHECK_LEN;
- psDnldContext->resp_length = PHDNLD_MIN_PACKET;
- break;
- }
- case PHDNLD_CMD_ENCAPSULATE:
- {
- uint8_t i = 0x00;
- if ((0 != param_length) && (NULL != params))
- {
- p_dnld_data->frame_type =
- PHDNLD_CMD_ENCAPSULATE;
- (void)memcpy((void *)( ((uint8_t *)p_dnld_data)
- + PHDNLD_FRAME_DATA_OFFSET)
- , params, param_length);
- tx_length = param_length;
-
- p_dnld_data->frame_length[i++] =
- (uint8_t)(tx_length >> BYTE_SIZE);
- p_dnld_data->frame_length[i] =
- (uint8_t)( tx_length & BYTE_MASK );
- tx_length += PHDNLD_FRAME_DATA_OFFSET;
-
- psDnldContext->resp_length = PHDNLD_MIN_PACKET;
-
- status = phDnldNfc_Send( psDnldContext, pHwRef ,
- (uint8_t *)p_dnld_data, tx_length);
- }
- else
- {
- status = PHNFCSTVAL(CID_NFC_DNLD,
- NFCSTATUS_NOT_ALLOWED);
- }
- break;
- }
- case PHDNLD_CMD_SET_HIF:
- {
- tx_length++;
- psDnldContext->resp_length = PHDNLD_MIN_PACKET;
- break;
- }
- case PHDNLD_CMD_ACTIVATE_PATCH:
- {
- psDnldContext->resp_length = PHDNLD_MIN_PACKET;
- if ((NULL != params) && ( param_length > 0 ))
- {
- p_dnld_data->param_info.cmd_param =
- (*(uint8_t *)params);
- tx_length = param_length;
- }
- else
- {
- p_dnld_data->param_info.cmd_param = FALSE;
- tx_length++;
- }
- break;
- }
- case PHDNLD_CMD_CHECK_INTEGRITY:
- {
-#if (NXP_FW_INTEGRITY_CHK >= 0x01)
- if ((NULL != params) && ( param_length > 0 ))
- {
- psDnldContext->chk_integrity_param =
- (phDnldNfc_eChkCrc_t)(*(uint8_t *)params);
- tx_length = param_length;
- }
- else
- {
- psDnldContext->chk_integrity_param = CHK_INTEGRITY_COMPLETE_CRC;
- tx_length++;
- }
- p_dnld_data->param_info.cmd_param =
- (uint8_t) psDnldContext->chk_integrity_param;
- switch(psDnldContext->chk_integrity_param)
- {
- case CHK_INTEGRITY_CONFIG_PAGE_CRC:
- case CHK_INTEGRITY_PATCH_TABLE_CRC:
- {
- psDnldContext->resp_length = PHDNLD_MIN_PACKET
- + CHECK_INTEGRITY_RESP_CRC16_LEN;
- break;
- }
- case CHK_INTEGRITY_FLASH_CODE_CRC:
- case CHK_INTEGRITY_PATCH_CODE_CRC:
- {
- psDnldContext->resp_length = PHDNLD_MIN_PACKET
- + CHECK_INTEGRITY_RESP_CRC32_LEN;
- break;
- }
- case CHK_INTEGRITY_COMPLETE_CRC:
- default:
- {
- psDnldContext->resp_length = PHDNLD_MIN_PACKET
- + CHECK_INTEGRITY_RESP_COMP_LEN;
- break;
- }
- }
-#else
- tx_length++;
- p_dnld_data->param_info.cmd_param =
- (uint8_t) CHK_INTEGRITY_COMPLETE_CRC;
-
-#endif /* #if (NXP_FW_INTEGRITY_CHK >= 0x01) */
- break;
- }
- default:
- {
- status = PHNFCSTVAL(CID_NFC_DNLD, NFCSTATUS_FEATURE_NOT_SUPPORTED);
- break;
- }
- }
- if (NFCSTATUS_SUCCESS == status)
- {
- uint8_t i = 0;
-
- p_dnld_data->frame_type = cmd;
- p_dnld_data->frame_length[i++] =
- (uint8_t)(tx_length >> BYTE_SIZE);
- p_dnld_data->frame_length[i] =
- (uint8_t)( tx_length & BYTE_MASK );
- tx_length = tx_length + PHDNLD_MIN_PACKET;
- status = phDnldNfc_Send( psDnldContext, pHwRef ,
- (uint8_t *)p_dnld_data, tx_length);
- if(NFCSTATUS_PENDING == status)
- {
- psDnldContext->prev_cmd = cmd;
-
- if( PHDNLD_CMD_RESET == cmd )
- DO_DELAY(PHDNLD_DNLD_DELAY); //this seems like its on the wrong thread
- }
- }
-
- return status;
-}
-
-static
-NFCSTATUS
-phDnldNfc_Check_FW(
- phHal_sHwReference_t *pHwRef,
- fw_data_hdr_t *cur_fw_hdr
- )
-{
- NFCSTATUS status = NFCSTATUS_FAILED;
-
- if ( !pHwRef->device_info.fw_version )
- {
- /* Override the Firmware Version Check and upgrade*/;
- DNLD_PRINT(" FW_DNLD_CHK: Forceful Upgrade of the Firmware .... Required \n");
- status = NFCSTATUS_SUCCESS;
- }
- else if ( (pHwRef->device_info.fw_version >> (BYTE_SIZE * 2))
- != ( cur_fw_hdr->fw_version >> (BYTE_SIZE * 2) ))
- {
- /* Check for the Compatible Romlib Version for the Hardware */
- DNLD_PRINT(" FW_DNLD: IC Hardware Version Mismatch.. \n");
- status = PHNFCSTVAL( CID_NFC_DNLD, NFCSTATUS_NOT_ALLOWED );
- }
- else if (( pHwRef->device_info.fw_version < cur_fw_hdr->fw_version )
- )
- {
- /* TODO: Firmware Version Check and upgrade*/
- DNLD_PRINT(" FW_DNLD: Older Firmware Upgrading to newerone.... \n");
- status = NFCSTATUS_SUCCESS;
- }
-#ifdef NXP_FW_CHK_LATEST
- else if (( pHwRef->device_info.fw_version > cur_fw_hdr->fw_version )
- )
- {
- DNLD_PRINT(" FW_DNLD: Newer than the Stored One .... \n");
- status = PHNFCSTVAL( CID_NFC_DNLD, NFCSTATUS_NOT_ALLOWED );
- }
-#endif /* NXP_FW_CHK_LATEST */
- else
- {
- DNLD_PRINT(" FW_DNLD: Already Updated .... \n");
- status = ( CID_NFC_DNLD << BYTE_SIZE ) ;
- }
-
- return status;
- }
-
-
-static
-NFCSTATUS
-phDnldNfc_Process_FW(
- phDnldNfc_sContext_t *psDnldContext,
- phHal_sHwReference_t *pHwRef
-#ifdef NXP_FW_PARAM
- ,uint8_t *nxp_nfc_fw
- ,uint32_t nxp_fw_len
-#endif
- )
-{
- NFCSTATUS status = NFCSTATUS_FAILED;
- section_info_t *p_cur_sec = NULL;
- static unsigned sec_type;
- uint32_t fw_index = 0;
-#ifdef NXP_NFC_MULTIPLE_FW
- phDnldNfc_sFwImageInfo_t *p_cur_fw = NULL;
-#endif /* #ifdef NXP_NFC_MULTIPLE_FW */
- fw_data_hdr_t *cur_fw_hdr = NULL;
- uint8_t sec_index = 0;
- uint8_t i = 0;
-
- psDnldContext->p_img_hdr = (img_data_hdr_t *) nxp_nfc_fw;
-
-#ifdef NXP_NFC_MULTIPLE_FW
-
- /* TODO: Create a memory of pointers to store all the Firmwares */
- if( (NXP_NFC_IMAG_FW_MAX > psDnldContext->p_img_hdr->no_of_fw_img)
- && (0 != psDnldContext->p_img_hdr->no_of_fw_img)
- )
- {
- ( void )phDnldNfc_Allocate_Resource((void **)&psDnldContext->p_img_info,
- (psDnldContext->p_img_hdr->no_of_fw_img * sizeof(phDnldNfc_sFwImageInfo_t)));
-
- if(NULL != psDnldContext->p_img_info)
- {
- p_cur_fw = psDnldContext->p_img_info;
- }
- }
-#endif /* #ifdef NXP_NFC_MULTIPLE_FW */
-
- fw_index = sizeof (img_data_hdr_t);
-
- for ( i=0; i < psDnldContext->p_img_hdr->no_of_fw_img; i++ )
- {
-
- psDnldContext->p_fw_hdr = (fw_data_hdr_t *) ( nxp_nfc_fw + fw_index );
-
-#ifdef NXP_NFC_MULTIPLE_FW
- if(NULL != p_cur_fw)
- {
- ( p_cur_fw + i)->p_fw_hdr = psDnldContext->p_fw_hdr;
- }
-#endif /* #ifdef NXP_NFC_MULTIPLE_FW */
- cur_fw_hdr = psDnldContext->p_fw_hdr;
-
- fw_index = fw_index + (cur_fw_hdr->fw_hdr_len * PNDNLD_WORD_LEN);
-
- status = phDnldNfc_Check_FW( pHwRef, cur_fw_hdr);
-
- }
-
- if ( ( NFCSTATUS_SUCCESS == status )
-#if defined (NXP_FW_INTEGRITY_VERIFY)
- || (NFCSTATUS_SUCCESS == PHNFCSTATUS(status) )
-#endif /* !defined (NXP_FW_INTEGRITY_VERIFY) */
- )
- {
- if( (BYTE_MASK > cur_fw_hdr->no_of_sections)
- && (0 != cur_fw_hdr->no_of_sections)
- )
- {
- (void) phDnldNfc_Allocate_Resource((void **)&psDnldContext->p_fw_sec,
- (cur_fw_hdr->no_of_sections * sizeof(section_info_t)));
-
- if(NULL != psDnldContext->p_fw_sec)
- {
- DNLD_DEBUG(" FW_DNLD: FW Index : %x \n",
- fw_index );
-
- DNLD_DEBUG(" FW_DNLD: No of Sections : %x \n\n",
- cur_fw_hdr->no_of_sections);
-
- for(sec_index = 0; sec_index
- < cur_fw_hdr->no_of_sections; sec_index++ )
- {
- p_cur_sec = ((section_info_t *)
- (psDnldContext->p_fw_sec + sec_index ));
-
- p_cur_sec->p_sec_hdr = (section_hdr_t *)
- (nxp_nfc_fw + fw_index);
-
- DNLD_DEBUG(" FW_DNLD: Section %x \n", sec_index);
- DNLD_DEBUG(" FW_DNLD: Section Header Len : %x ",
- p_cur_sec->p_sec_hdr->section_hdr_len);
- DNLD_DEBUG(" Section Address : %x ",
- p_cur_sec->p_sec_hdr->section_address);
- DNLD_DEBUG(" Section Length : %x ",
- p_cur_sec->p_sec_hdr->section_length);
- DNLD_DEBUG(" Section Memory Type : %x \n",
- p_cur_sec->p_sec_hdr->section_mem_type);
-
- sec_type = (unsigned int)p_cur_sec->p_sec_hdr->section_mem_type;
-
- if((sec_type & DNLD_TRIM_MASK))
- {
- p_cur_sec->p_trim_data = (uint8_t *)
- (nxp_nfc_fw + fw_index + sizeof(section_hdr_t));
- }
- else
- {
- p_cur_sec->p_trim_data = NULL;
- }
-
- if (0 == sec_index)
- {
- if ((sec_type & DNLD_SM_UNLOCK_MASK))
- {
- (void)phDnldNfc_Set_Seq(psDnldContext,
- DNLD_SEQ_UNLOCK);
- }
- else
- {
- (void)phDnldNfc_Set_Seq(psDnldContext,
- DNLD_SEQ_INIT);
- }
- }
- p_cur_sec->section_read = FALSE;
-
- p_cur_sec->section_offset = 0;
-
- p_cur_sec->p_sec_data = ((uint8_t *) nxp_nfc_fw) + fw_index +
- (p_cur_sec->p_sec_hdr->section_hdr_len * PNDNLD_WORD_LEN);
-
- fw_index = fw_index +
- (p_cur_sec->p_sec_hdr->section_hdr_len * PNDNLD_WORD_LEN)
- + p_cur_sec->p_sec_hdr->section_length;
-
-
- if( 0 != p_cur_sec->p_sec_hdr->section_checksum )
- {
- DNLD_DEBUG(" FW_DNLD: Section checksum : %x \n",
- p_cur_sec->p_sec_hdr->section_checksum );
-
- p_cur_sec->p_sec_chksum = ( uint8_t *)(nxp_nfc_fw + fw_index);
-
- fw_index = fw_index +
- p_cur_sec->p_sec_hdr->section_checksum;
- }
-
- DNLD_DEBUG(" FW_DNLD: FW Index : %x \n", fw_index );
-
-#if (NXP_FW_INTEGRITY_CHK >= 0x01)
- switch( p_cur_sec->p_sec_hdr->section_address )
- {
- case DNLD_FW_CODE_ADDR:
- {
- psDnldContext->p_flash_code_crc =
- p_cur_sec->p_sec_data
- + p_cur_sec->p_sec_hdr->section_length
- - DNLD_CRC32_SIZE;
- break;
- }
- case DNLD_PATCH_CODE_ADDR:
- {
- psDnldContext->p_patch_code_crc =
- p_cur_sec->p_sec_data
- + p_cur_sec->p_sec_hdr->section_length
- - DNLD_CRC32_SIZE;
- break;
- }
- case DNLD_PATCH_TABLE_ADDR:
- {
- psDnldContext->p_patch_table_crc =
- p_cur_sec->p_sec_data
- + p_cur_sec->p_sec_hdr->section_length
- - DNLD_CRC16_SIZE;
- break;
- }
- default:
- {
- break;
- }
-
- } /* End of Address Switch */
-#endif /* #if (NXP_FW_INTEGRITY_CHK >= 0x01) */
- } /* End of For Loop */
- } /* End of the Null Check */
- else
- {
- status = PHNFCSTVAL(CID_NFC_DNLD,
- NFCSTATUS_INSUFFICIENT_RESOURCES);
- }
-
- }
- else if (
- (0 == cur_fw_hdr->no_of_sections)
- && (PHDNLD_FW_PATCH_SEC == cur_fw_hdr->fw_patch)
- )
- {
- psDnldContext->p_fw_raw = (uint8_t *)(nxp_nfc_fw + fw_index);
-
- psDnldContext->raw_mode_upgrade = PHDNLD_COMPLETE_OPERATION;
-
- (void)phDnldNfc_Set_Seq(psDnldContext,
- DNLD_SEQ_RAW);
- }
- else
- {
- DNLD_PRINT("********* Empty Section and Firmware ******************\n\n");
- }
-
- DNLD_PRINT("*******************************************\n\n");
-
- }
- return status;
-}
-
-#if !defined (NXP_FW_INTEGRITY_VERIFY)
-
-NFCSTATUS
-phDnldNfc_Run_Check(
- phHal_sHwReference_t *pHwRef
-#ifdef NXP_FW_PARAM
- ,uint8_t *nxp_nfc_fw
- uint32_t fw_length
-#endif
- )
-{
- NFCSTATUS status = NFCSTATUS_FAILED;
- uint32_t fw_index = 0;
- img_data_hdr_t *p_img_hdr = NULL;
- fw_data_hdr_t *p_fw_hdr = NULL;
- fw_data_hdr_t *cur_fw_hdr = NULL;
- uint8_t i = 0;
-
- p_img_hdr = (img_data_hdr_t *) nxp_nfc_fw;
-
- fw_index = sizeof (img_data_hdr_t);
-
- for ( i=0; i < p_img_hdr->no_of_fw_img; i++ )
- {
- p_fw_hdr = (fw_data_hdr_t *) ( nxp_nfc_fw + fw_index );
- /* TODO: Create a memory of pointers to store all the Firmwares */
- cur_fw_hdr = p_fw_hdr;
-
- fw_index = fw_index + (cur_fw_hdr->fw_hdr_len * PNDNLD_WORD_LEN);
-
- status = phDnldNfc_Check_FW( pHwRef, cur_fw_hdr);
- }
- return status;
-}
-
-#endif /* #if !defined (NXP_FW_INTEGRITY_VERIFY) */
-
-
-STATIC
-void
-phDnldNfc_Abort (
- uint32_t abort_id
-#ifdef NFC_TIMER_CONTEXT
- , void *dnld_cntxt
-#endif
- )
-{
-
- phNfc_sCompletionInfo_t comp_info = {0,0,0};
-
- phDnldNfc_sContext_t *p_dnld_context = NULL;
-
-#ifdef NFC_TIMER_CONTEXT
- p_dnld_context = (phDnldNfc_sContext_t *)dnld_cntxt;
-#else
- p_dnld_context = gpphDnldContext;
-#endif
-
- if ( ( NULL != p_dnld_context)
- && (abort_id == p_dnld_context->timer_id ))
- {
- pphNfcIF_Notification_CB_t p_upper_notify =
- p_dnld_context->p_upper_notify;
- void *p_upper_context =
- p_dnld_context->p_upper_context;
- phHal_sHwReference_t *pHwRef = p_dnld_context->p_hw_ref;
-
- (void)phDal4Nfc_Unregister(
- p_dnld_context->lower_interface.pcontext, pHwRef );
- phDnldNfc_Release_Lower(p_dnld_context, pHwRef);
- phDnldNfc_Release_Resources(&p_dnld_context);
-#ifndef NFC_TIMER_CONTEXT
- gpphDnldContext = p_dnld_context;
-#endif
-
- /* Notify the Error/Success Scenario to the upper layer */
- DNLD_DEBUG(" FW_DNLD: FW_DNLD Aborted with %x Timer Timeout \n",
- abort_id);
- comp_info.status = NFCSTATUS_FAILED ;
- phDnldNfc_Notify( p_upper_notify, p_upper_context,
- pHwRef, (uint8_t) NFC_IO_ERROR, &comp_info );
- }
-
- return ;
-}
-
-
-
-NFCSTATUS
-phDnldNfc_Upgrade (
- phHal_sHwReference_t *pHwRef,
-#ifdef NXP_FW_PARAM
- uint8_t type,
- uint8_t *nxp_nfc_fw,
- uint32_t fw_length,
-#endif
- pphNfcIF_Notification_CB_t upgrade_complete,
- void *context
- )
- {
- phDnldNfc_sContext_t *psDnldContext = NULL;
- phNfcIF_sReference_t dnldReference = { NULL,0,0 };
- phNfcIF_sCallBack_t if_callback = { NULL, NULL, NULL, NULL };
- phNfc_sLowerIF_t *plower_if = NULL;
- NFCSTATUS status = NFCSTATUS_SUCCESS;
-
- if( (NULL == pHwRef)
- )
- {
- status = PHNFCSTVAL(CID_NFC_DNLD, NFCSTATUS_INVALID_PARAMETER);
- }
- else
- {
- DNLD_PRINT(" FW_DNLD: Starting the FW Upgrade Sequence .... \n");
-
- (void)
- phDnldNfc_Allocate_Resource((void **)
- &psDnldContext,sizeof(phDnldNfc_sContext_t));
- if(psDnldContext != NULL)
- {
-#ifndef NFC_TIMER_CONTEXT
- gpphDnldContext = psDnldContext;
-#endif
- psDnldContext->p_hw_ref = pHwRef;
- psDnldContext->timer_id = NXP_INVALID_TIMER_ID;
-
- DNLD_PRINT(" FW_DNLD: Initialisation in Progress.... \n");
-
- if_callback.pif_ctxt = psDnldContext ;
- if_callback.send_complete = &phDnldNfc_Send_Complete;
- if_callback.receive_complete= &phDnldNfc_Receive_Complete;
- /* if_callback.notify = &phDnldNfc_Notify_Event; */
- plower_if = dnldReference.plower_if = &(psDnldContext->lower_interface);
- status = phDal4Nfc_Register(&dnldReference, if_callback,
- NULL);
- DNLD_DEBUG(" FW_DNLD: Lower Layer Register, Status = %02X\n",status);
-
- if( (NFCSTATUS_SUCCESS == status) && (NULL != plower_if->init))
- {
- /* psDnldContext->p_config_params = pHwConfig ; */
- status = plower_if->init((void *)plower_if->pcontext,
- (void *)pHwRef);
- DNLD_DEBUG(" FW_DNLD: Lower Layer Initialisation, Status = %02X\n",status);
- }
- else
- {
- /* TODO: Handle Initialisation in the Invalid State */
- }
- /* The Lower layer Initialisation successful */
- if (NFCSTATUS_SUCCESS == status)
- {
- psDnldContext->p_upper_notify = upgrade_complete;
- psDnldContext->p_upper_context = context;
-
- status = phDnldNfc_Process_FW( psDnldContext, pHwRef
-#ifdef NXP_FW_PARAM
- ,*nxp_nfc_fw , fw_length
-#endif
- );
-
- if (NFCSTATUS_SUCCESS == status)
- {
- status = phDnldNfc_Send_Command( psDnldContext, pHwRef,
- PHDNLD_CMD_RESET , NULL , 0 );
- if (NFCSTATUS_PENDING == status)
- {
- DNLD_PRINT("\n FW_DNLD: Initial Reset .... \n");
-
-#if defined(FW_DOWNLOAD_TIMER)
-
- psDnldContext->timer_id = phOsalNfc_Timer_Create( );
-
-#if (FW_DOWNLOAD_TIMER < 2)
- phOsalNfc_Timer_Start( psDnldContext->timer_id,
- NXP_DNLD_COMPLETE_TIMEOUT,
- (ppCallBck_t) phDnldNfc_Abort
-#ifdef NFC_TIMER_CONTEXT
- , (void *) psDnldContext
-#endif
- );
-
-#endif /* #if (FW_DOWNLOAD_TIMER < 2) */
-
-#endif /* #if defined(FW_DOWNLOAD_TIMER) */
-
- }
- }
- else if (NFCSTATUS_SUCCESS == PHNFCSTATUS(status))
- {
-#if defined (NXP_FW_INTEGRITY_VERIFY)
- /*
- * To check for the integrity if the firmware is already
- * Upgraded.
- */
- status = phDnldNfc_Send_Command( psDnldContext, pHwRef,
- PHDNLD_CMD_RESET , NULL , 0 );
- if (NFCSTATUS_PENDING == status)
- {
- DNLD_PRINT("\n FW_DNLD: Integrity Reset .... \n");
- (void)phDnldNfc_Set_Seq(psDnldContext, DNLD_SEQ_COMPLETE);
- status = PHNFCSTVAL( CID_NFC_DNLD,
- NFCSTATUS_PENDING );
-#if defined(FW_DOWNLOAD_TIMER)
- psDnldContext->timer_id = phOsalNfc_Timer_Create( );
-#if (FW_DOWNLOAD_TIMER < 2)
- phOsalNfc_Timer_Start( psDnldContext->timer_id,
- NXP_DNLD_COMPLETE_TIMEOUT,
- (ppCallBck_t) phDnldNfc_Abort
-#ifdef NFC_TIMER_CONTEXT
- , (void *) psDnldContext
-#endif
- );
-
-#endif /* #if (FW_DOWNLOAD_TIMER < 2) */
-
-#endif /* #if defined(FW_DOWNLOAD_TIMER) */
- }
-
-#else
- status = NFCSTATUS_SUCCESS;
-
-#endif /* #if defined (NXP_FW_INTEGRITY_VERIFY) */
-
- }
- else
- {
- DNLD_PRINT(" FW_DNLD Initialisation in Failed \n");
- }
- }
-
- if (NFCSTATUS_PENDING != PHNFCSTATUS(status))
- {
- (void)phDal4Nfc_Unregister(
- psDnldContext->lower_interface.pcontext, pHwRef);
- phDnldNfc_Release_Lower(psDnldContext, pHwRef);
- phDnldNfc_Release_Resources(&psDnldContext);
-#ifndef NFC_TIMER_CONTEXT
- gpphDnldContext = psDnldContext;
-#endif
- }
- } /* End of Status Check for Memory */
- else
- {
- status = PHNFCSTVAL(CID_NFC_DNLD, NFCSTATUS_INSUFFICIENT_RESOURCES);
-
- DNLD_PRINT(" FW_DNLD: Memory Allocation of Context Failed\n");
- }
- }
-
- return status;
- }
diff --git a/libnfc-nxp/phDnldNfc.h b/libnfc-nxp/phDnldNfc.h
deleted file mode 100644
index 7126413..0000000
--- a/libnfc-nxp/phDnldNfc.h
+++ /dev/null
@@ -1,137 +0,0 @@
-/*
- * Copyright (C) 2010 NXP Semiconductors
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-/*!
-* =========================================================================== *
-* *
-* *
-* \file phDnldNfc.h *
-* \brief Download Mgmt Header for the Generic Download Management. *
-* *
-* *
-* Project: NFC-FRI-1.1 *
-* *
-* $Date: Thu Aug 26 15:39:56 2010 $ *
-* $Author: ing04880 $ *
-* $Revision: 1.7 $ *
-* $Aliases: $
-* *
-* =========================================================================== *
-*/
-
-
-/*@{*/
-
-#ifndef PHDNLDNFC_H
-#define PHDNLDNFC_H
-
-/*@}*/
-/**
- * \name Download Mgmt
- *
- * File: \ref phDnldNfc.h
- *
- */
-/*@{*/
-#define PH_DNLDNFC_FILEREVISION "$Revision: 1.7 $" /**< \ingroup grp_file_attributes */
-#define PH_DNLDNFC_FILEALIASES "$Aliases: $" /**< \ingroup grp_file_attributes */
-/*@}*/
-
-/*
-################################################################################
-***************************** Header File Inclusion ****************************
-################################################################################
-*/
-
-#include
-#include
-
-/*
-################################################################################
-****************************** Macro Definitions *******************************
-################################################################################
-*/
-
-
-/*
-################################################################################
-******************** Enumeration and Structure Definition **********************
-################################################################################
-*/
-
-#ifndef NXP_FW_PARAM
-extern const uint8_t *nxp_nfc_fw;
-#endif /* NXP_FW_PARAM */
-
-
-
-
-/*
-################################################################################
-*********************** Function Prototype Declaration *************************
-################################################################################
-*/
-
-/**
- * \ingroup grp_hci_nfc
- *
- * The phDnldNfc_Upgrade function Upgrades the firmware of
- * connected NFC Device with the data provided.
- *
- * \param[in] pHwRef pHwRef is the Information of
- * the Device Interface Link .
- * \param[in] pHalNotify Upper layer Notification function
- * pointer.
- * \param[in] psContext psContext is the context of
- * the Upper Layer.
- *
- * \retval NFCSTATUS_PENDING Upgrade of Download Layer is in Progress.
- * \retval NFCSTATUS_INVALID_PARAMETER One or more of the supplied parameters
- * could not be interpreted properly.
- * \retval Other errors Errors related to the other layers
- *
- */
-
- extern
- NFCSTATUS
- phDnldNfc_Upgrade (
- phHal_sHwReference_t *pHwRef,
-#ifdef NXP_FW_PARAM
- uint8_t *nxp_nfc_fw,
- uint32_t fw_length,
-#endif
- pphNfcIF_Notification_CB_t upgrade_complete,
- void *context
- );
-
-
-#if !defined (NXP_FW_INTEGRITY_VERIFY)
-
-extern
-NFCSTATUS
-phDnldNfc_Run_Check(
- phHal_sHwReference_t *pHwRef
-#ifdef NXP_FW_PARAM
- ,uint8_t *nxp_nfc_fw
- uint32_t fw_length
-#endif
- );
-#endif /* #if !defined (NXP_FW_INTEGRITY_VERIFY) */
-
-
-#endif /* PHDNLDNFC_H */
-
-
diff --git a/libnfc-nxp/phFriNfc.h b/libnfc-nxp/phFriNfc.h
deleted file mode 100644
index 3677405..0000000
--- a/libnfc-nxp/phFriNfc.h
+++ /dev/null
@@ -1,156 +0,0 @@
-/*
- * Copyright (C) 2010 NXP Semiconductors
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-/*!
- * \file phFriNfc.h
- * \brief NFC FRI Main Header.
- *
- * Project: NFC-FRI
- *
- * $Date: Mon Dec 13 14:14:13 2010 $
- * $Author: ing02260 $
- * $Revision: 1.20 $
- * $Aliases: $
- *
- */
-
-#ifndef PHFRINFC_H /* */
-#define PHFRINFC_H /* */
-#include
-#include
-
-#define PH_HAL4_ENABLE
-
-#ifdef PH_HAL4_ENABLE
- #include
- #define LOCK_BITS_CHECK_ENABLE
-#endif
-
-#define FRINFC_READONLY_NDEF
-
-#ifdef DISABLE_MIFARE_MAPPING
-#define PH_FRINFC_MAP_MIFAREUL_DISABLED
-#define PH_FRINFC_MAP_MIFARESTD_DISABLED
-#define PH_FRINFC_MAP_DESFIRE_DISABLED
-#else
-#define PH_NDEF_MIFARE_ULC
-#endif
-
-#ifdef DISABLE_FELICA_MAPPING
-#define PH_FRINFC_MAP_FELICA_DISABLED
-#endif
-
-#ifdef DISABLE_JEWEL_MAPPING
-#define PH_FRINFC_MAP_TOPAZ_DISABLED
-#define PH_FRINFC_MAP_TOPAZ_DYNAMIC_DISABLED
-#endif
-
-#ifdef DISABLE_ISO15693_MAPPING
-#define PH_FRINFC_MAP_ISO15693_DISABLED
-#endif
-
-
-#ifdef DISABLE_FORMAT
-#define PH_FRINFC_FMT_DESFIRE_DISABLED
-#define PH_FRINFC_FMT_MIFAREUL_DISABLED
-#define PH_FRINFC_FMT_MIFARESTD_DISABLED
-#define PH_FRINFC_FMT_ISO15693_DISABLED
-#endif /* #ifdef DISABLE_FORMAT */
-
-#define PH_FRINFC_FMT_TOPAZ_DISABLED
-
-/*!
- * \name NFC FRI Main Header
- *
- * File: \ref phFriNfc.h
- *
- */
-/*@{*/
-
-#define PH_FRINFC_FILEREVISION "$Revision: 1.20 $" /**< \ingroup grp_file_attributes */
-#define PH_FRINFC_FILEALIASES "$Aliases: $" /**< \ingroup grp_file_attributes */
-
-/*@}*/
-
-
-/*!
- * \ingroup grp_fri_nfc_common
- *
- * \brief \copydoc page_cb Completion Routine
- *
- * NFC-FRI components that work in an overlapped style need to provide a function that is compatible
- * to this definition.\n\n
- * It is \b mandatory to define such a routine for components that interact with other components up or
- * down the stack. Moreover, such components shall provide a function within their API to enable the
- * setting of the \b Completion \b Routine address and parameters.
- *
- * \par First Parameter: Context
- * Set to the address of the called instance (component instance context structure). For instance,
- * a component that needs to give control to a component up the stack needs to call the completion
- * routine of the \b upper component. The value to assign to this parameter is the \b address of
- * the context structure instance of the called component. Such a structure usually contains all
- * variables, data or state information a component member needs for operation. The address of the
- * upper instance must be known by the lower (completing) instance. The mechanism to ensure that this
- * information is present involves the structure \ref phFriNfc_CplRt_t . See its documentation for
- * further information.
- *
- * \par Second Parameter: Status Value
- * The lower layer hands over the completion status via this parameter. The completion
- * routine that has been called needs to process the status in a way that is comparable to what
- * a regular function return value would require.
- *
- * \note The prototype of the component's \b Process(ing) functions has to be compatible to this
- * function pointer declaration for components interacting with others. In other cases, where
- * there is no interaction or asynchronous processing the definition of the \b Process(ing)
- * function can be arbitrary, if present at all.
- */
-
-typedef void (*pphFriNfc_Cr_t)(void*, NFCSTATUS);
-
-
-/*!
- * \ingroup grp_fri_nfc_common
- *
- * \brief Completion Routine structure
- *
- * This structure finds itself within each component that requires to report completion
- * to an upper (calling) component.\n\n
- * Depending on the actual implementation (static or dynamic completion information) the stack
- * initialisation \b or the calling component needs to inform the initialised \b or called component
- * about the completion path. This information is submitted via this structure.
- *
- */
-typedef struct phFriNfc_CplRt
-{
- pphFriNfc_Cr_t CompletionRoutine; /*!< Address of the upper Layer's \b Process(ing) function to call upon completion.
- * The stack initialiser (or depending on the implementation: the calling component)
- * needs to set this member to the address of the function that needs to be within
- * the completion path: A calling component would give its own processing function
- * address to the lower layer.
- */
- void *Context; /*!< Instance address (context) parameter.
- * The stack initialiser (or depending on the implementation: the calling component)
- * needs to set this member to the address of the component context structure instance
- * within the completion path: A calling component would give its own instance address
- * to the lower layer.
- */
-} phFriNfc_CplRt_t;
-
-
-#define NFCSTATUS_INVALID_DEVICE_REQUEST (0x10F5)
-
-
-#endif /* __PHFRINFC_H__ */
diff --git a/libnfc-nxp/phFriNfc_DesfireFormat.c b/libnfc-nxp/phFriNfc_DesfireFormat.c
deleted file mode 100644
index 50cf142..0000000
--- a/libnfc-nxp/phFriNfc_DesfireFormat.c
+++ /dev/null
@@ -1,1425 +0,0 @@
-/*
- * Copyright (C) 2010 NXP Semiconductors
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-/*!
-* \file phFriNfc_DesfireFormat.c
-* \brief This component encapsulates different format functinalities ,
-* for the Type4/Desfire card.
-*
-* Project: NFC-FRI
-*
-* $Date: Thu Oct 28 17:44:00 2010 $
-* $Author: ing02260 $
-* $Revision: 1.8 $
-* $Aliases: $
-*
-*/
-#include
-#include
-#include
-#include
-
-
-/* Following section details, how to wrap the native DESFire commands in to ISO commands
-Following are different native commands are wrapped under the ISO commands :
-1. Crate Application
-2. Select File
-3. Get version
-4. Create CC/NDEF File
-5. Write data to STD File
-In this File above commands are sent using the ISO Wrapper.
-
-Wrapping the native DESFire APDU's procedure
---------------------------------------------------------------------------------
-CLA INS P1 P2 Lc Data Le
-0x90 Cmd 0x00 0x00 Data Len Cmd. Par's 0x00
------------------------------------------------------------------------------------*/
-
-/****************************** Macro definitions start ********************************/
-/* This settings can be changed, depending on the requirement*/
-#define PH_FRINFC_DESF_PICC_NFC_KEY_SETTING 0x0FU
-
-#ifdef FRINFC_READONLY_NDEF
-
- #define READ_ONLY_NDEF_DESFIRE 0xFFU
- #define CC_BYTES_SIZE 0x0FU
- #define PH_FRINFC_DESF_READ_DATA_CMD 0xBDU
- #define NATIVE_WRAPPER_READ_DATA_LC_VALUE 0x07U
-
-#endif /* #ifdef FRINFC_READONLY_NDEF */
-
-#ifdef DESFIRE_FMT_EV1
-
-#define DESFIRE_CARD_TYPE_EV1 0x01U
-
-#define DESFIRE_EV1_MAPPING_VERSION 0x20U
-
-#define DESFIRE_EV1_HW_MAJOR_VERSION 0x01U
-#define DESFIRE_EV1_HW_MINOR_VERSION 0x00U
-#define DESFIRE_EV1_SW_MAJOR_VERSION 0x01U
-#define DESFIRE_EV1_SW_MINOR_VERSION 0x03U
-
-/* The below values are received for the command GET VERSION */
-#define DESFIRE_TAG_SIZE_IDENTIFIER_2K 0x16U
-#define DESFIRE_TAG_SIZE_IDENTIFIER_4K 0x18U
-#define DESFIRE_TAG_SIZE_IDENTIFIER_8K 0x1AU
-
-#define DESFIRE_2K_CARD 2048U
-#define DESFIRE_4K_CARD 4096U
-#define DESFIRE_8K_CARD 7680U
-
-#define DESFIRE_EV1_KEY_SETTINGS_2 0x21U
-
-#define DESFIRE_EV1_FIRST_AID_BYTE 0x01U
-#define DESFIRE_EV1_SECOND_AID_BYTE 0x00U
-#define DESFIRE_EV1_THIRD_AID_BYTE 0x00U
-
-#define DESFIRE_EV1_FIRST_ISO_FILE_ID 0x05U
-#define DESFIRE_EV1_SECOND_ISO_FILE_ID 0xE1U
-
-#define DESFIRE_EV1_ISO_APP_DF_NAME {0xD2, 0x76, 0x00, 0x00, 0x85, 0x01, 0x01}
-
-#define DESFIRE_EV1_CC_FILE_ID 0x01U
-#define DESFIRE_EV1_FIRST_CC_FILE_ID_BYTE 0x03U
-#define DESFIRE_EV1_SECOND_CC_FILE_ID_BYTE 0xE1U
-
-#define DESFIRE_EV1_NDEF_FILE_ID 0x02U
-#define DESFIRE_EV1_FIRST_NDEF_FILE_ID_BYTE 0x04U
-#define DESFIRE_EV1_SECOND_NDEF_FILE_ID_BYTE 0xE1U
-
-
-#define PH_FRINFC_DESF_STATE_REACTIVATE 0x0FU
-
-#endif /* #ifdef DESFIRE_FMT_EV1 */
-/****************************** Macro definitions end ********************************/
-/* Helper functions to create app/select app/create data file/read /write from the
-CC file and NDEF files */
-static void phFriNfc_Desf_HWrapISONativeCmds(phFriNfc_sNdefSmtCrdFmt_t *NdefSmtCrdFmt,uint8_t CmdType);
-
-/* Gets H/W version details*/
-static NFCSTATUS phFriNfc_Desf_HGetHWVersion(phFriNfc_sNdefSmtCrdFmt_t *NdefSmtCrdFmt);
-
-/* Gets S/W version details*/
-static NFCSTATUS phFriNfc_Desf_HGetSWVersion(phFriNfc_sNdefSmtCrdFmt_t *NdefSmtCrdFmt);
-
-/* Updates the version details to context structure*/
-static NFCSTATUS phFriNfc_Desf_HUpdateVersionDetails(phFriNfc_sNdefSmtCrdFmt_t *NdefSmtCrdFmt);
-
-/*Gets UID details*/
-static NFCSTATUS phFriNfc_Desf_HGetUIDDetails(phFriNfc_sNdefSmtCrdFmt_t * NdefSmtCrdFmt);
-
-/*Creates Application*/
-static NFCSTATUS phFriNfc_Desf_HCreateApp(phFriNfc_sNdefSmtCrdFmt_t *NdefSmtCrdFmt);
-
-/* Selects Application*/
-static NFCSTATUS phFriNfc_Desf_HSelectApp(phFriNfc_sNdefSmtCrdFmt_t *NdefSmtCrdFmt);
-
-/*Creates Capability Container File*/
-static NFCSTATUS phFriNfc_Desf_HCreatCCFile(phFriNfc_sNdefSmtCrdFmt_t *NdefSmtCrdFmt);
-
-/* Create NDEF File*/
-static NFCSTATUS phFriNfc_Desf_HCreatNDEFFile(phFriNfc_sNdefSmtCrdFmt_t *NdefSmtCrdFmt);
-
-/* Writes CC Bytes to CC File*/
-static NFCSTATUS phFriNfc_Desf_HWrCCBytes(phFriNfc_sNdefSmtCrdFmt_t *NdefSmtCrdFmt);
-
-/* Writes NDEF data into NDEF File*/
-static NFCSTATUS phFriNfc_Desf_HWrNDEFData(phFriNfc_sNdefSmtCrdFmt_t *NdefSmtCrdFmt);
-
-/* Transceive Cmd initiation*/
-static NFCSTATUS phFriNfc_Desf_HSendTransCmd(phFriNfc_sNdefSmtCrdFmt_t *NdefSmtCrdFmt);
-
-#ifdef FRINFC_READONLY_NDEF
-
-#if 0
-static
-NFCSTATUS
-phFriNfc_Desf_HReadOnlySelectCCFile (
- phFriNfc_sNdefSmtCrdFmt_t *NdefSmtCrdFmt);
-#endif /* #if 0 */
-
-static
-NFCSTATUS
-phFriNfc_Desf_HReadOnlyReadCCFile (
- phFriNfc_sNdefSmtCrdFmt_t *NdefSmtCrdFmt);
-
-static
-NFCSTATUS
-phFriNfc_Desf_HReadOnlyWriteCCFile (
- phFriNfc_sNdefSmtCrdFmt_t *NdefSmtCrdFmt);
-
-static
-NFCSTATUS
-phFriNfc_Desf_HReadOnlySelectApp (
- phFriNfc_sNdefSmtCrdFmt_t *NdefSmtCrdFmt);
-
-#ifdef DESFIRE_FMT_EV1
-
-static
-NFCSTATUS
-phFriNfc_Desf_HReadOnlySelectAppEV1 (
- phFriNfc_sNdefSmtCrdFmt_t *NdefSmtCrdFmt);
-
-#endif /* #ifdef DESFIRE_FMT_EV1 */
-
-#endif /* #ifdef FRINFC_READONLY_NDEF */
-
-void phFriNfc_Desfire_Reset( phFriNfc_sNdefSmtCrdFmt_t *NdefSmtCrdFmt)
-{
- /* This piece of code may not be useful for the current supported DESFire formatting feature*/
- /* Currently, s/w doesn't support authenticating either PICC Master key nor NFC Forum
- Application Master key*/
-
- /*NdefSmtCrdFmt->AddInfo.Type4Info.PICCMasterKey[] = PH_FRINFC_SMTCRDFMT_DESF_PICC_MASTER_KEY;
- NdefSmtCrdFmt->AddInfo.Type4Info.NFCForumMasterkey[] = PH_FRINFC_SMTCRDFMT_DESF_NFCFORUM_APP_KEY;*/
-
- /* reset to zero PICC and NFC FORUM master keys*/
- (void)memset((void *)NdefSmtCrdFmt->AddInfo.Type4Info.PICCMasterKey,
- 0x00,
- 16);
-
- (void)memset((void *)NdefSmtCrdFmt->AddInfo.Type4Info.NFCForumMasterkey,
- 0x00,
- 16);
- NdefSmtCrdFmt->AddInfo.Type4Info.PrevState = 0;
-
-}
-
-
-static void phFriNfc_Desf_HWrapISONativeCmds(phFriNfc_sNdefSmtCrdFmt_t *NdefSmtCrdFmt,uint8_t CmdType)
-{
-
- uint16_t i=0, CmdByte=1;
- uint8_t NdefFileBytes[] = PH_FRINFC_DESF_NDEFFILE_BYTES;
- uint8_t CCFileBytes[] = PH_FRINFC_DESF_CCFILE_BYTES;
-
-
- /* common elements for all the native commands*/
-
- /* Class Byte */
- NdefSmtCrdFmt->SendRecvBuf[i] = PH_FRINFC_DESF_NATIVE_CLASS_BYTE;
-
- /* let the place to store the cmd byte type, point to next index*/
- i += 2;
-
-
- /* P1/P2 offsets always set to zero */
- NdefSmtCrdFmt->SendRecvBuf[i] = PH_FRINFC_DESF_NATIVE_OFFSET_P1;
- i++;
- NdefSmtCrdFmt->SendRecvBuf[i] = PH_FRINFC_DESF_NATIVE_OFFSET_P2;
- i++;
-
- switch(CmdType)
- {
- case PH_FRINFC_DESF_GET_HW_VERSION_CMD :
- case PH_FRINFC_DESF_GET_SW_VERSION_CMD :
- case PH_FRINFC_DESF_GET_UID_CMD :
- {
- if (CmdType == PH_FRINFC_DESF_GET_HW_VERSION_CMD )
- {
- /* Instruction Cmd code */
- NdefSmtCrdFmt->SendRecvBuf[CmdByte] = PH_FRINFC_DESF_GET_VER_CMD;
- }
- else
- {
- /* Instruction Cmd code */
- NdefSmtCrdFmt->SendRecvBuf[CmdByte] = PH_FRINFC_DESF_PICC_ADDI_FRAME_RESP;
- }
-
- /* Lc: Length of wrapped data */
- NdefSmtCrdFmt->SendRecvBuf[i] = 0x00;
- i++;
-
- /* NO Data to send in this cmd*/
- /* we are not suppose to set Le*/
- /* set the length of the buffer*/
- NdefSmtCrdFmt->SendLength = i;
-
- break;
- }
-
- case PH_FRINFC_DESF_CREATEAPP_CMD:
- {
-#ifdef DESFIRE_FMT_EV1
- uint8_t df_name[] = DESFIRE_EV1_ISO_APP_DF_NAME;
-#endif /* #ifdef DESFIRE_FMT_EV1 */
-
- /* Instruction Cmd code */
- NdefSmtCrdFmt->SendRecvBuf[CmdByte] = PH_FRINFC_DESF_CREATE_AID_CMD;
-
-#ifdef DESFIRE_FMT_EV1
- if (DESFIRE_CARD_TYPE_EV1 == NdefSmtCrdFmt->CardType)
- {
- /* Lc: Length of wrapped data,
- here the magic number 2 is for the ISO File ID for the application */
- NdefSmtCrdFmt->SendRecvBuf[i] = (uint8_t)(PH_FRINFC_DESF_NATIVE_CRAPP_WRDT_LEN +
- sizeof (df_name) + 2);
- i++;
- /* NFC FORUM APPLICATION ID*/
- NdefSmtCrdFmt->SendRecvBuf[i] = DESFIRE_EV1_FIRST_AID_BYTE;
- i++;
- NdefSmtCrdFmt->SendRecvBuf[i] = DESFIRE_EV1_SECOND_AID_BYTE;
- i++;
- NdefSmtCrdFmt->SendRecvBuf[i] = DESFIRE_EV1_THIRD_AID_BYTE;
- i++;
- }
- else
-#endif /* #ifdef DESFIRE_FMT_EV1 */
- {
- /* Lc: Length of wrapped data */
- NdefSmtCrdFmt->SendRecvBuf[i] = PH_FRINFC_DESF_NATIVE_CRAPP_WRDT_LEN;
- i++;
- /* NFC FORUM APPLICATION ID*/
- NdefSmtCrdFmt->SendRecvBuf[i] = PH_FRINFC_DESF_FIRST_AID_BYTE;
- i++;
- NdefSmtCrdFmt->SendRecvBuf[i] = PH_FRINFC_DESF_SEC_AID_BYTE;
- i++;
- NdefSmtCrdFmt->SendRecvBuf[i] = PH_FRINFC_DESF_THIRD_AID_BYTE;
- i++;
- }
- /* set key settings and number of keys*/
- NdefSmtCrdFmt->SendRecvBuf[i] = PH_FRINFC_DESF_PICC_NFC_KEY_SETTING;
- i++;
-#ifdef DESFIRE_FMT_EV1
- if (DESFIRE_CARD_TYPE_EV1 == NdefSmtCrdFmt->CardType)
- {
- /* set key settings and number of keys*/
- NdefSmtCrdFmt->SendRecvBuf[i] = DESFIRE_EV1_KEY_SETTINGS_2;
- i++;
- }
- else
-#endif /* #ifdef DESFIRE_FMT_EV1 */
- {
- NdefSmtCrdFmt->SendRecvBuf[i] = PH_FRINFC_DESF_NFCFORUM_APP_NO_OF_KEYS;
- i++;
- }
-
-#ifdef DESFIRE_FMT_EV1
- if (DESFIRE_CARD_TYPE_EV1 == NdefSmtCrdFmt->CardType)
- {
- /* ISO File ID */
- NdefSmtCrdFmt->SendRecvBuf[i] = DESFIRE_EV1_FIRST_ISO_FILE_ID;
- i++;
- NdefSmtCrdFmt->SendRecvBuf[i] = DESFIRE_EV1_SECOND_ISO_FILE_ID;
- i++;
- /* DF file name */
- (void)memcpy ((void *)&NdefSmtCrdFmt->SendRecvBuf[i],
- (void *)df_name, sizeof (df_name));
- i = (uint16_t)(i + sizeof (df_name));
- }
-#endif /* #ifdef DESFIRE_FMT_EV1 */
-
- /* Le bytes*/
- NdefSmtCrdFmt->SendRecvBuf[i] = PH_FRINFC_DESF_NATIVE_LE_BYTE;
- i++;
-
-#ifdef DESFIRE_FMT_EV1
- if (DESFIRE_CARD_TYPE_EV1 == NdefSmtCrdFmt->CardType)
- {
- /* set the length of the buffer*/
- NdefSmtCrdFmt->SendLength = i;
- }
- else
-#endif /* #ifdef DESFIRE_FMT_EV1 */
- {
- NdefSmtCrdFmt->SendLength = PH_FRINFC_DESF_CREATEAPP_CMD_SNLEN;
- }
- break;
- }
-
- case PH_FRINFC_DESF_SELECTAPP_CMD:
- {
- /* Instruction Cmd code */
- NdefSmtCrdFmt->SendRecvBuf[CmdByte] = PH_FRINFC_DESF_SLECT_APP_CMD;
-
- /* Lc: Length of wrapped data */
- NdefSmtCrdFmt->SendRecvBuf[i] = PH_FRINFC_DESF_NATIVE_SLAPP_WRDT_LEN;
- i++;
-
-#ifdef DESFIRE_FMT_EV1
- if (DESFIRE_CARD_TYPE_EV1 == NdefSmtCrdFmt->CardType)
- {
- /* Data*/
- /* set the send buffer to create the application identifier*/
- NdefSmtCrdFmt->SendRecvBuf[i] = DESFIRE_EV1_FIRST_AID_BYTE;
- i++;
-
- NdefSmtCrdFmt->SendRecvBuf[i] = DESFIRE_EV1_SECOND_AID_BYTE;
- i++;
-
- NdefSmtCrdFmt->SendRecvBuf[i] = DESFIRE_EV1_THIRD_AID_BYTE;
- i++;
- }
- else
-#endif /* #ifdef DESFIRE_FMT_EV1 */
- {
- /* Data*/
- /* set the send buffer to create the application identifier*/
- NdefSmtCrdFmt->SendRecvBuf[i] = PH_FRINFC_DESF_FIRST_AID_BYTE;
- i++;
-
- NdefSmtCrdFmt->SendRecvBuf[i] = PH_FRINFC_DESF_SEC_AID_BYTE;
- i++;
-
- NdefSmtCrdFmt->SendRecvBuf[i] = PH_FRINFC_DESF_THIRD_AID_BYTE;
- i++;
- }
-
- /* Le bytes*/
- NdefSmtCrdFmt->SendRecvBuf[i] = PH_FRINFC_DESF_NATIVE_LE_BYTE;
- i++;
-
- /* set the length of the buffer*/
- NdefSmtCrdFmt->SendLength = PH_FRINFC_DESF_SELECTAPP_CMD_SNLEN;
- break;
- }
-
- case PH_FRINFC_DESF_CREATECC_CMD:
- {
- /* Instruction Cmd code */
- NdefSmtCrdFmt->SendRecvBuf[CmdByte] = PH_FRINFC_DESF_CREATE_DATA_FILE_CMD;
-
-#ifdef DESFIRE_FMT_EV1
- if (DESFIRE_CARD_TYPE_EV1 == NdefSmtCrdFmt->CardType)
- {
- /* Lc: Length of wrapped data,
- here the magic number 2 is added as part of the ISO File ID in the packet */
- NdefSmtCrdFmt->SendRecvBuf[i] = (uint8_t)
- (PH_FRINFC_DESF_NATIVE_CRCCNDEF_WRDT_LEN + 2);
- i++;
- /* set cc file id* */
- NdefSmtCrdFmt->SendRecvBuf[i] = DESFIRE_EV1_CC_FILE_ID;
- i++;
- /* ISO File ID */
- NdefSmtCrdFmt->SendRecvBuf[i] = DESFIRE_EV1_FIRST_CC_FILE_ID_BYTE;
- i++;
- NdefSmtCrdFmt->SendRecvBuf[i] = DESFIRE_EV1_SECOND_CC_FILE_ID_BYTE;
- i++;
- }
- else
-#endif /* #ifdef DESFIRE_FMT_EV1 */
- {
- /* Lc: Length of wrapped data */
- NdefSmtCrdFmt->SendRecvBuf[i] = PH_FRINFC_DESF_NATIVE_CRCCNDEF_WRDT_LEN;
- i++;
- /* set cc file id*/
- NdefSmtCrdFmt->SendRecvBuf[i] = PH_FRINFC_DESF_CC_FILE_ID;
- i++;
- }
-
- NdefSmtCrdFmt->SendRecvBuf[i] = PH_FRINFC_DESF_COMM_SETTINGS;
- i++;
-
- /* set the Access Rights are set to full read/write, full cntrl*/
- NdefSmtCrdFmt->SendRecvBuf[i] = 0xEE;
- i++;
- NdefSmtCrdFmt->SendRecvBuf[i] = 0xEE;
- i++;
-
- /* set the file size*/
- NdefSmtCrdFmt->SendRecvBuf[i] = PH_FRINFC_DESF_CC_FILE_SIZE;
- i++;
- NdefSmtCrdFmt->SendRecvBuf[i] = 0x00;
- i++;
- NdefSmtCrdFmt->SendRecvBuf[i] = 0x00;
- i++;
-
- /* Le bytes*/
- NdefSmtCrdFmt->SendRecvBuf[i] = PH_FRINFC_DESF_NATIVE_LE_BYTE;
- i++;
-#ifdef DESFIRE_FMT_EV1
- if (DESFIRE_CARD_TYPE_EV1 == NdefSmtCrdFmt->CardType)
- {
- /* set the length of the buffer*/
- NdefSmtCrdFmt->SendLength = i;
- }
- else
-#endif /* #ifdef DESFIRE_FMT_EV1 */
- {
- /* set the length of the buffer*/
- NdefSmtCrdFmt->SendLength = PH_FRINFC_DESF_CREATECCNDEF_CMD_SNLEN;
- }
- break;
- }
-
- case PH_FRINFC_DESF_CREATENDEF_CMD:
- {
- /* Instruction Cmd code */
- NdefSmtCrdFmt->SendRecvBuf[CmdByte] = PH_FRINFC_DESF_CREATE_DATA_FILE_CMD;
-
-#ifdef DESFIRE_FMT_EV1
- if (DESFIRE_CARD_TYPE_EV1 == NdefSmtCrdFmt->CardType)
- {
- /* Lc: Length of wrapped data,
- here the magic number 2 is added as part of the ISO File ID in the packet */
- NdefSmtCrdFmt->SendRecvBuf[i] = (uint8_t)
- (PH_FRINFC_DESF_NATIVE_CRCCNDEF_WRDT_LEN + 2);
- i++;
- /* set NDEF file id* */
- NdefSmtCrdFmt->SendRecvBuf[i] = DESFIRE_EV1_NDEF_FILE_ID;
- i++;
- /* ISO File ID */
- NdefSmtCrdFmt->SendRecvBuf[i] = DESFIRE_EV1_FIRST_NDEF_FILE_ID_BYTE;
- i++;
- NdefSmtCrdFmt->SendRecvBuf[i] = DESFIRE_EV1_SECOND_NDEF_FILE_ID_BYTE;
- i++;
- }
- else
-#endif /* #ifdef DESFIRE_FMT_EV1 */
- {
- /* Lc: Length of wrapped data */
- NdefSmtCrdFmt->SendRecvBuf[i] = PH_FRINFC_DESF_NATIVE_CRCCNDEF_WRDT_LEN;
- i++;
-
- /* set NDEF file id*/
- NdefSmtCrdFmt->SendRecvBuf[i] = PH_FRINFC_DESF_NDEF_FILE_ID;
- i++;
- }
- NdefSmtCrdFmt->SendRecvBuf[i] = PH_FRINFC_DESF_COMM_SETTINGS;
- i++;
-
- /* set the r/w access rights.Once Authentication part is fixed,
- we will use the constants*/
- NdefSmtCrdFmt->SendRecvBuf[i] = 0xEE;
- i++;
- NdefSmtCrdFmt->SendRecvBuf[i] = 0xEE;
- i++;
-
- NdefSmtCrdFmt->SendRecvBuf[i]= (uint8_t)NdefSmtCrdFmt->AddInfo.Type4Info.CardSize;
- i++;
- NdefSmtCrdFmt->SendRecvBuf[i]= (uint8_t)
- (NdefSmtCrdFmt->AddInfo.Type4Info.CardSize >> 8);
- i++;
- NdefSmtCrdFmt->SendRecvBuf[i]= (uint8_t)
- (NdefSmtCrdFmt->AddInfo.Type4Info.CardSize >> 16);
- i++;
-
- /* Le bytes*/
- NdefSmtCrdFmt->SendRecvBuf[i] = PH_FRINFC_DESF_NATIVE_LE_BYTE;
- i++;
-
-#ifdef DESFIRE_FMT_EV1
- if (DESFIRE_CARD_TYPE_EV1 == NdefSmtCrdFmt->CardType)
- {
- /* set the length of the buffer*/
- NdefSmtCrdFmt->SendLength = i;
- }
- else
-#endif /* #ifdef DESFIRE_FMT_EV1 */
- {
- /* set the length of the buffer*/
- NdefSmtCrdFmt->SendLength = PH_FRINFC_DESF_CREATECCNDEF_CMD_SNLEN;
- }
- break;
- }
-
- case PH_FRINFC_DESF_WRITECC_CMD:
- {
- /* Instruction Cmd code */
- NdefSmtCrdFmt->SendRecvBuf[CmdByte] = PH_FRINFC_DESF_WRITE_CMD;
-
- /* Lc: Length of wrapped data */
- NdefSmtCrdFmt->SendRecvBuf[i] = PH_FRINFC_DESF_NATIVE_WRCC_WRDT_LEN;
- i++;
-
-#ifdef DESFIRE_FMT_EV1
- if (DESFIRE_CARD_TYPE_EV1 == NdefSmtCrdFmt->CardType)
- {
- /* set the file id*/
- NdefSmtCrdFmt->SendRecvBuf[i] = DESFIRE_EV1_CC_FILE_ID;
- i++;
- }
- else
-#endif /* #ifdef DESFIRE_FMT_EV1 */
- {
- /* set the file id*/
- NdefSmtCrdFmt->SendRecvBuf[i] = PH_FRINFC_DESF_CC_FILE_ID;
- i++;
- }
-
- /* set the offset to zero*/
- NdefSmtCrdFmt->SendRecvBuf[i] = 0x00;
- i++;
- NdefSmtCrdFmt->SendRecvBuf[i] = 0x00;
- i++;
- NdefSmtCrdFmt->SendRecvBuf[i] = 0x00;
- i++;
-
- /* Set the length of data available to write*/
- NdefSmtCrdFmt->SendRecvBuf[i] = PH_FRINFC_DESF_CC_FILE_SIZE;
- i++;
- NdefSmtCrdFmt->SendRecvBuf[i] = 0x00;
- i++;
- NdefSmtCrdFmt->SendRecvBuf[i] = 0x00;
- i++;
-#ifdef DESFIRE_FMT_EV1
- if (DESFIRE_CARD_TYPE_EV1 == NdefSmtCrdFmt->CardType)
- {
- CCFileBytes[2] = (uint8_t)DESFIRE_EV1_MAPPING_VERSION;
-
- /* Length value is updated in the CC as per the card size received from
- the GetVersion command */
- CCFileBytes[11] = (uint8_t)
- (NdefSmtCrdFmt->AddInfo.Type4Info.CardSize >> 8);
- CCFileBytes[12] = (uint8_t)
- (NdefSmtCrdFmt->AddInfo.Type4Info.CardSize);
- }
-#endif /* #ifdef DESFIRE_FMT_EV1 */
- /*set the data to be written to the CC file*/
- (void)memcpy ((void *)&NdefSmtCrdFmt->SendRecvBuf[i],
- (void *)CCFileBytes, sizeof (CCFileBytes));
-#ifdef DESFIRE_FMT_EV1
-#else
- i++;
-#endif /* #ifdef DESFIRE_FMT_EV1 */
-
- i = (uint16_t)(i + sizeof (CCFileBytes));
-
- /* Le bytes*/
- NdefSmtCrdFmt->SendRecvBuf[i] = PH_FRINFC_DESF_NATIVE_LE_BYTE;
- i++;
-#ifdef DESFIRE_FMT_EV1
- if (DESFIRE_CARD_TYPE_EV1 == NdefSmtCrdFmt->CardType)
- {
- NdefSmtCrdFmt->SendLength = i;
- }
- else
-#endif /* #ifdef DESFIRE_FMT_EV1 */
- {
- NdefSmtCrdFmt->SendLength = PH_FRINFC_DESF_WRITECC_CMD_SNLEN;
- }
- break;
- }
-
- case PH_FRINFC_DESF_WRITENDEF_CMD:
- {
- /* Instruction Cmd code */
- NdefSmtCrdFmt->SendRecvBuf[CmdByte] = PH_FRINFC_DESF_WRITE_CMD;
-
- /* Lc: Length of wrapped data */
- NdefSmtCrdFmt->SendRecvBuf[i] = PH_FRINFC_DESF_NATIVE_WRNDEF_WRDT_LEN;
- i++;
-
-#ifdef DESFIRE_FMT_EV1
- if (DESFIRE_CARD_TYPE_EV1 == NdefSmtCrdFmt->CardType)
- {
- /* set the file id*/
- NdefSmtCrdFmt->SendRecvBuf[i] = DESFIRE_EV1_NDEF_FILE_ID;
- i++;
- }
- else
-#endif /* #ifdef DESFIRE_FMT_EV1 */
- {
- /* set the file id*/
- NdefSmtCrdFmt->SendRecvBuf[i] = PH_FRINFC_DESF_NDEF_FILE_ID;
- i++;
- }
-
- /* set the offset to zero*/
- NdefSmtCrdFmt->SendRecvBuf[i] = 0x00;
- i++;
- NdefSmtCrdFmt->SendRecvBuf[i] = 0x00;
- i++;
- NdefSmtCrdFmt->SendRecvBuf[i] = 0x00;
- i++;
-
- /* Set the length of data available to write*/
- NdefSmtCrdFmt->SendRecvBuf[i] = 0x02;
- i++;
- NdefSmtCrdFmt->SendRecvBuf[i] = 0x00;
- i++;
- NdefSmtCrdFmt->SendRecvBuf[i] = 0x00;
- i++;
-
- /*set the data to be written to the CC file*/
-
- (void)memcpy(&NdefSmtCrdFmt->SendRecvBuf[i],
- NdefFileBytes, sizeof (NdefFileBytes));
- i = (uint16_t)(i + sizeof (NdefFileBytes));
-
- /* Le bytes*/
- NdefSmtCrdFmt->SendRecvBuf[i] = PH_FRINFC_DESF_NATIVE_LE_BYTE;
- i++;
-
- NdefSmtCrdFmt->SendLength = PH_FRINFC_DESF_WRITENDEF_CMD_SNLEN;
- break;
- }
-
- default:
- {
- break;
- }
- }
-}
-
-static NFCSTATUS phFriNfc_Desf_HGetHWVersion(phFriNfc_sNdefSmtCrdFmt_t *NdefSmtCrdFmt)
-{
- NFCSTATUS status = NFCSTATUS_SUCCESS;
-#ifdef PH_HAL4_ENABLE
- /* Removed uint8_t i=0; */
-#else
- uint8_t i=0;
-#endif /* #ifdef PH_HAL4_ENABLE */
-
- /*set the state*/
- NdefSmtCrdFmt->State = PH_FRINFC_DESF_STATE_GET_HW_VERSION;
-
- /* Helper routine to wrap the native DESFire cmds*/
- phFriNfc_Desf_HWrapISONativeCmds(NdefSmtCrdFmt,PH_FRINFC_DESF_GET_HW_VERSION_CMD);
-
- status = phFriNfc_Desf_HSendTransCmd(NdefSmtCrdFmt);
-
- return ( status);
-}
-
-static NFCSTATUS phFriNfc_Desf_HGetSWVersion(phFriNfc_sNdefSmtCrdFmt_t *NdefSmtCrdFmt)
-{
-
- NFCSTATUS status = PHNFCSTVAL(CID_FRI_NFC_NDEF_SMTCRDFMT,
- NFCSTATUS_FORMAT_ERROR);
-
- if (NdefSmtCrdFmt->SendRecvBuf[*(NdefSmtCrdFmt->SendRecvLength)- 1] ==
- PH_FRINFC_DESF_PICC_ADDI_FRAME_RESP)
- {
- /*set the state*/
- NdefSmtCrdFmt->State = PH_FRINFC_DESF_STATE_GET_SW_VERSION;
-
- /* Helper routine to wrap the native DESFire cmds*/
- phFriNfc_Desf_HWrapISONativeCmds(NdefSmtCrdFmt,PH_FRINFC_DESF_GET_SW_VERSION_CMD);
-
- status = phFriNfc_Desf_HSendTransCmd(NdefSmtCrdFmt);
- }
- return status;
-}
-
-static NFCSTATUS phFriNfc_Desf_HUpdateVersionDetails(phFriNfc_sNdefSmtCrdFmt_t *NdefSmtCrdFmt)
-{
- NFCSTATUS status = PHNFCSTVAL(CID_NFC_NONE,
- NFCSTATUS_SUCCESS);
-
- if (NdefSmtCrdFmt->SendRecvBuf[*(NdefSmtCrdFmt->SendRecvLength) -
- PH_SMTCRDFMT_DESF_VAL1] == PH_FRINFC_DESF_PICC_ADDI_FRAME_RESP)
- {
- NdefSmtCrdFmt->AddInfo.Type4Info.MajorVersion = NdefSmtCrdFmt->SendRecvBuf[PH_SMTCRDFMT_DESF_VAL3];
- NdefSmtCrdFmt->AddInfo.Type4Info.MinorVersion = NdefSmtCrdFmt->SendRecvBuf[PH_SMTCRDFMT_DESF_VAL4];
-
- if ((PH_FRINFC_DESF4_MAJOR_VERSION == NdefSmtCrdFmt->AddInfo.Type4Info.MajorVersion) &&
- (PH_FRINFC_DESF4_MINOR_VERSION == NdefSmtCrdFmt->AddInfo.Type4Info.MinorVersion))
- {
- /* card size of DESFire4 type */
- NdefSmtCrdFmt->AddInfo.Type4Info.CardSize = PH_FRINFC_DESF4_MEMORY_SIZE;
-
- }
-#ifdef DESFIRE_FMT_EV1
- else if ((DESFIRE_EV1_SW_MAJOR_VERSION == NdefSmtCrdFmt->AddInfo.Type4Info.MajorVersion) &&
- (DESFIRE_EV1_SW_MINOR_VERSION == NdefSmtCrdFmt->AddInfo.Type4Info.MinorVersion))
- {
- NdefSmtCrdFmt->CardType = DESFIRE_CARD_TYPE_EV1;
- }
-#endif /* #ifdef DESFIRE_FMT_EV1 */
- else
- {
- // need to handle the Desfire8 type cards
- // need to use get free memory
- status = PHNFCSTVAL (CID_FRI_NFC_NDEF_SMTCRDFMT,
- NFCSTATUS_INVALID_REMOTE_DEVICE);
-
- }
-#ifdef DESFIRE_FMT_EV1
- if (DESFIRE_CARD_TYPE_EV1 == NdefSmtCrdFmt->CardType)
- {
- switch (NdefSmtCrdFmt->SendRecvBuf[5])
- {
- case DESFIRE_TAG_SIZE_IDENTIFIER_2K:
- {
- NdefSmtCrdFmt->AddInfo.Type4Info.CardSize = DESFIRE_2K_CARD;
- break;
- }
-
- case DESFIRE_TAG_SIZE_IDENTIFIER_4K:
- {
- NdefSmtCrdFmt->AddInfo.Type4Info.CardSize = DESFIRE_4K_CARD;
- break;
- }
-
- case DESFIRE_TAG_SIZE_IDENTIFIER_8K:
- {
- NdefSmtCrdFmt->AddInfo.Type4Info.CardSize = DESFIRE_8K_CARD;
- break;
- }
-
- default:
- {
- status = PHNFCSTVAL (CID_FRI_NFC_NDEF_SMTCRDFMT,
- NFCSTATUS_INVALID_REMOTE_DEVICE);
- break;
- }
- }
- }
-#endif /* #ifdef DESFIRE_FMT_EV1 */
- }
-
- return status;
-}
-
-static NFCSTATUS phFriNfc_Desf_HGetUIDDetails(phFriNfc_sNdefSmtCrdFmt_t * NdefSmtCrdFmt)
-{
-
- NFCSTATUS status = NFCSTATUS_PENDING;
- if (NdefSmtCrdFmt->SendRecvBuf[*(NdefSmtCrdFmt->SendRecvLength) -
- PH_SMTCRDFMT_DESF_VAL1] == PH_FRINFC_DESF_PICC_ADDI_FRAME_RESP)
- {
- /*set the state*/
- NdefSmtCrdFmt->State = PH_FRINFC_DESF_STATE_GET_UID;
-
- /* Helper routine to wrap the native desfire cmds*/
- phFriNfc_Desf_HWrapISONativeCmds(NdefSmtCrdFmt,PH_FRINFC_DESF_GET_UID_CMD);
-
- status = phFriNfc_Desf_HSendTransCmd(NdefSmtCrdFmt);
- }
-
- return status;
-
-}
-
-
-static NFCSTATUS phFriNfc_Desf_HCreateApp(phFriNfc_sNdefSmtCrdFmt_t *NdefSmtCrdFmt)
-{
- NFCSTATUS status = PHNFCSTVAL(CID_FRI_NFC_NDEF_SMTCRDFMT,
- NFCSTATUS_FORMAT_ERROR);
-
- if ( (NdefSmtCrdFmt->SendRecvBuf[PH_SMTCRDFMT_DESF_VAL14] == PH_FRINFC_DESF_NAT_WRAP_FIRST_RESP_BYTE)
- && (NdefSmtCrdFmt->SendRecvBuf[PH_SMTCRDFMT_DESF_VAL15] == PH_FRINFC_DESF_NAT_WRAP_SEC_RESP_BYTE ))
- {
- /*set the state*/
- NdefSmtCrdFmt->State = PH_FRINFC_DESF_STATE_CREATE_AID;
-
- /* Helper routine to wrap the native DESFire cmds*/
- phFriNfc_Desf_HWrapISONativeCmds(NdefSmtCrdFmt,PH_FRINFC_DESF_CREATEAPP_CMD);
-
- status = phFriNfc_Desf_HSendTransCmd(NdefSmtCrdFmt);
- }
- return ( status);
-}
-
-
-static NFCSTATUS phFriNfc_Desf_HSelectApp(phFriNfc_sNdefSmtCrdFmt_t *NdefSmtCrdFmt)
-{
-
- NFCSTATUS status = PHNFCSTVAL(CID_FRI_NFC_NDEF_SMTCRDFMT,
- NFCSTATUS_FORMAT_ERROR);
-
- /* check for the response of previous operation, before
- issuing the next command*/
-
- if ( (NdefSmtCrdFmt->SendRecvBuf[PH_SMTCRDFMT_DESF_VAL0] == PH_FRINFC_DESF_NAT_WRAP_FIRST_RESP_BYTE) &&
- (NdefSmtCrdFmt->SendRecvBuf[PH_SMTCRDFMT_DESF_VAL1] == PH_FRINFC_DESF_NAT_WRAP_SEC_RESP_BYTE ))
- {
- /*set the state*/
- NdefSmtCrdFmt->State = PH_FRINFC_DESF_STATE_SELECT_APP;
-
- /* Helper routine to wrap the native DESFire cmds*/
- phFriNfc_Desf_HWrapISONativeCmds(NdefSmtCrdFmt,PH_FRINFC_DESF_SELECTAPP_CMD);
-
- status = phFriNfc_Desf_HSendTransCmd(NdefSmtCrdFmt);
- }
- return ( status);
-
-}
-
-static NFCSTATUS phFriNfc_Desf_HCreatCCFile(phFriNfc_sNdefSmtCrdFmt_t *NdefSmtCrdFmt)
-{
- NFCSTATUS status = PHNFCSTVAL(CID_FRI_NFC_NDEF_SMTCRDFMT,
- NFCSTATUS_FORMAT_ERROR);
-
- if ( (NdefSmtCrdFmt->SendRecvBuf[PH_SMTCRDFMT_DESF_VAL0] == PH_FRINFC_DESF_NATIVE_RESP_BYTE1) &&
- (NdefSmtCrdFmt->SendRecvBuf[PH_SMTCRDFMT_DESF_VAL1] == PH_FRINFC_DESF_NATIVE_RESP_BYTE2 ))
- {
- /*set the state*/
- NdefSmtCrdFmt->State = PH_FRINFC_DESF_STATE_CREATE_CCFILE;
-
- /* Helper routine to wrap the native DESFire cmds*/
- phFriNfc_Desf_HWrapISONativeCmds(NdefSmtCrdFmt,PH_FRINFC_DESF_CREATECC_CMD);
-
- status = phFriNfc_Desf_HSendTransCmd(NdefSmtCrdFmt);
- }
- return ( status);
-}
-
-static NFCSTATUS phFriNfc_Desf_HCreatNDEFFile(phFriNfc_sNdefSmtCrdFmt_t *NdefSmtCrdFmt)
-{
-
- NFCSTATUS status = PHNFCSTVAL(CID_FRI_NFC_NDEF_SMTCRDFMT,
- NFCSTATUS_FORMAT_ERROR);
-
- if ( (NdefSmtCrdFmt->SendRecvBuf[PH_SMTCRDFMT_DESF_VAL0] == PH_FRINFC_DESF_NATIVE_RESP_BYTE1) &&
- (NdefSmtCrdFmt->SendRecvBuf[PH_SMTCRDFMT_DESF_VAL1] == PH_FRINFC_DESF_NATIVE_RESP_BYTE2 ))
- {
- /*set the state*/
- NdefSmtCrdFmt->State = PH_FRINFC_DESF_STATE_CREATE_NDEFFILE;
-
- /* Helper routine to wrap the native desfire cmds*/
- phFriNfc_Desf_HWrapISONativeCmds(NdefSmtCrdFmt,PH_FRINFC_DESF_CREATENDEF_CMD);
-
- status = phFriNfc_Desf_HSendTransCmd(NdefSmtCrdFmt);
-
- }
-
- return ( status);
-
-}
-
-static NFCSTATUS phFriNfc_Desf_HWrCCBytes(phFriNfc_sNdefSmtCrdFmt_t *NdefSmtCrdFmt)
-{
-
- NFCSTATUS result = PHNFCSTVAL(CID_FRI_NFC_NDEF_SMTCRDFMT,
- NFCSTATUS_FORMAT_ERROR);
- if ( (NdefSmtCrdFmt->SendRecvBuf[PH_SMTCRDFMT_DESF_VAL0] == PH_FRINFC_DESF_NATIVE_RESP_BYTE1) &&
- (NdefSmtCrdFmt->SendRecvBuf[PH_SMTCRDFMT_DESF_VAL1] == PH_FRINFC_DESF_NATIVE_RESP_BYTE2 ))
- {
-
- /*set the state*/
- NdefSmtCrdFmt->State = PH_FRINFC_DESF_STATE_WRITE_CC_FILE;
-
- /* Helper routine to wrap the native DESFire cmds*/
- phFriNfc_Desf_HWrapISONativeCmds(NdefSmtCrdFmt,PH_FRINFC_DESF_WRITECC_CMD);
-
- result = phFriNfc_Desf_HSendTransCmd(NdefSmtCrdFmt);
- }
- return (result);
-}
-
-static NFCSTATUS phFriNfc_Desf_HWrNDEFData(phFriNfc_sNdefSmtCrdFmt_t *NdefSmtCrdFmt)
-{
-
- NFCSTATUS Result = PHNFCSTVAL(CID_FRI_NFC_NDEF_SMTCRDFMT,
- NFCSTATUS_FORMAT_ERROR);
-
-
- if ( (NdefSmtCrdFmt->SendRecvBuf[PH_SMTCRDFMT_DESF_VAL0] == PH_FRINFC_DESF_NATIVE_RESP_BYTE1) &&
- (NdefSmtCrdFmt->SendRecvBuf[PH_SMTCRDFMT_DESF_VAL1] == PH_FRINFC_DESF_NATIVE_RESP_BYTE2 ))
- {
- /*set the state*/
- NdefSmtCrdFmt->State = PH_FRINFC_DESF_STATE_WRITE_NDEF_FILE;
-
- /* Helper routine to wrap the native DESFire cmds*/
- phFriNfc_Desf_HWrapISONativeCmds(NdefSmtCrdFmt,PH_FRINFC_DESF_WRITENDEF_CMD);
-
- Result = phFriNfc_Desf_HSendTransCmd(NdefSmtCrdFmt);
- }
- return (Result);
-}
-
-static NFCSTATUS phFriNfc_Desf_HSendTransCmd(phFriNfc_sNdefSmtCrdFmt_t *NdefSmtCrdFmt)
-{
-
- NFCSTATUS status = NFCSTATUS_SUCCESS;
-
- /* set the command type*/
-#ifdef PH_HAL4_ENABLE
- NdefSmtCrdFmt->Cmd.Iso144434Cmd = phHal_eIso14443_4_Raw;
-#else
- NdefSmtCrdFmt->Cmd.Iso144434Cmd = phHal_eIso14443_4_CmdListTClCmd;
-#endif /* #ifdef PH_HAL4_ENABLE */
-
- /* set the Additional Info*/
- NdefSmtCrdFmt->psDepAdditionalInfo.DepFlags.MetaChaining = 0;
- NdefSmtCrdFmt->psDepAdditionalInfo.DepFlags.NADPresent = 0;
-
- /*set the completion routines for the desfire card operations*/
- NdefSmtCrdFmt->SmtCrdFmtCompletionInfo.CompletionRoutine = phFriNfc_NdefSmtCrd_Process;
- NdefSmtCrdFmt->SmtCrdFmtCompletionInfo.Context = NdefSmtCrdFmt;
-
- /* set the receive length */
- *NdefSmtCrdFmt->SendRecvLength = PH_FRINFC_SMTCRDFMT_MAX_SEND_RECV_BUF_SIZE;
-
-
- /*Call the Overlapped HAL Transceive function */
- status = phFriNfc_OvrHal_Transceive(NdefSmtCrdFmt->LowerDevice,
- &NdefSmtCrdFmt->SmtCrdFmtCompletionInfo,
- NdefSmtCrdFmt->psRemoteDevInfo,
- NdefSmtCrdFmt->Cmd,
- &NdefSmtCrdFmt->psDepAdditionalInfo,
- NdefSmtCrdFmt->SendRecvBuf,
- NdefSmtCrdFmt->SendLength,
- NdefSmtCrdFmt->SendRecvBuf,
- NdefSmtCrdFmt->SendRecvLength);
-
- return (status);
-
-
-}
-
-NFCSTATUS phFriNfc_Desfire_Format(phFriNfc_sNdefSmtCrdFmt_t *NdefSmtCrdFmt)
-{
-
- NFCSTATUS status = NFCSTATUS_SUCCESS;
-#ifdef DESFIRE_FMT_EV1
- NdefSmtCrdFmt->CardType = 0;
-#endif /* #ifdef DESFIRE_FMT_EV1 */
- status = phFriNfc_Desf_HGetHWVersion(NdefSmtCrdFmt);
- return (status);
-}
-
-#ifdef FRINFC_READONLY_NDEF
-
-#if 0
-static
-NFCSTATUS
-phFriNfc_Desf_HReadOnlySelectCCFile (
- phFriNfc_sNdefSmtCrdFmt_t *NdefSmtCrdFmt)
-{
- NFCSTATUS result = NFCSTATUS_SUCCESS;
- return result;
-}
-#endif /* #if 0 */
-
-static
-NFCSTATUS
-phFriNfc_Desf_HReadOnlyReadCCFile (
- phFriNfc_sNdefSmtCrdFmt_t *NdefSmtCrdFmt)
-{
- NFCSTATUS result = NFCSTATUS_SUCCESS;
- uint16_t i = 0;
-
- if ((PH_FRINFC_DESF_NATIVE_RESP_BYTE1 ==
- NdefSmtCrdFmt->SendRecvBuf[(*NdefSmtCrdFmt->SendRecvLength - 2)])
- && (PH_FRINFC_DESF_NATIVE_RESP_BYTE2 ==
- NdefSmtCrdFmt->SendRecvBuf[(*NdefSmtCrdFmt->SendRecvLength - 1)]))
- {
- NdefSmtCrdFmt->State = PH_FRINFC_DESF_STATE_RO_READ_CC_FILE;
-
- /* Class Byte */
- NdefSmtCrdFmt->SendRecvBuf[i] = PH_FRINFC_DESF_NATIVE_CLASS_BYTE;
- i++;
-
- /* let the place to store the cmd byte type, point to next index
- Instruction Cmd code */
- NdefSmtCrdFmt->SendRecvBuf[i] = PH_FRINFC_DESF_READ_DATA_CMD;
- i++;
-
-
- /* P1/P2 offsets always set to zero */
- NdefSmtCrdFmt->SendRecvBuf[i] = PH_FRINFC_DESF_NATIVE_OFFSET_P1;
- i++;
- NdefSmtCrdFmt->SendRecvBuf[i] = PH_FRINFC_DESF_NATIVE_OFFSET_P2;
- i++;
-
- /* Lc: Length of wrapped data */
- NdefSmtCrdFmt->SendRecvBuf[i] = NATIVE_WRAPPER_READ_DATA_LC_VALUE;
- i++;
-
-#ifdef DESFIRE_FMT_EV1
- if (DESFIRE_CARD_TYPE_EV1 == NdefSmtCrdFmt->CardType)
- {
- /* set the file id*/
- NdefSmtCrdFmt->SendRecvBuf[i] = DESFIRE_EV1_CC_FILE_ID;
- i++;
- }
- else
-#endif /* #ifdef DESFIRE_FMT_EV1 */
- {
- /* set the file id*/
- NdefSmtCrdFmt->SendRecvBuf[i] = PH_FRINFC_DESF_CC_FILE_ID;
- i++;
- }
-
- /* set the offset to zero*/
- NdefSmtCrdFmt->SendRecvBuf[i] = 0x00;
- i++;
- NdefSmtCrdFmt->SendRecvBuf[i] = 0x00;
- i++;
- NdefSmtCrdFmt->SendRecvBuf[i] = 0x00;
- i++;
-
- /* Set the length of data available to read */
- NdefSmtCrdFmt->SendRecvBuf[i] = PH_FRINFC_DESF_CC_FILE_SIZE;
- i++;
- NdefSmtCrdFmt->SendRecvBuf[i] = 0x00;
- i++;
- NdefSmtCrdFmt->SendRecvBuf[i] = 0x00;
- i++;
-
- /* Le Value is set 0 */
- NdefSmtCrdFmt->SendRecvBuf[i] = PH_FRINFC_DESF_NATIVE_LE_BYTE;
- i++;
-
- NdefSmtCrdFmt->SendLength = i;
-
- result = phFriNfc_Desf_HSendTransCmd (NdefSmtCrdFmt);
- }
- else
- {
- result = PHNFCSTVAL(CID_FRI_NFC_NDEF_SMTCRDFMT,
- NFCSTATUS_FORMAT_ERROR);
- }
-
- return result;
-}
-
-static
-NFCSTATUS
-phFriNfc_Desf_HReadOnlyWriteCCFile (
- phFriNfc_sNdefSmtCrdFmt_t *NdefSmtCrdFmt)
-{
- NFCSTATUS result = NFCSTATUS_SUCCESS;
- uint8_t read_cc_btyes[CC_BYTES_SIZE] = {0};
- uint16_t i = 0;
-
- if ((PH_FRINFC_DESF_NATIVE_RESP_BYTE1 ==
- NdefSmtCrdFmt->SendRecvBuf[(*NdefSmtCrdFmt->SendRecvLength - 2)])
- && (PH_FRINFC_DESF_NATIVE_RESP_BYTE2 ==
- NdefSmtCrdFmt->SendRecvBuf[(*NdefSmtCrdFmt->SendRecvLength - 1)]))
- {
- NdefSmtCrdFmt->State = PH_FRINFC_DESF_STATE_RO_UPDATE_CC_FILE;
-
- memcpy ((void *)read_cc_btyes, (void *)NdefSmtCrdFmt->SendRecvBuf,
- sizeof (read_cc_btyes));
- read_cc_btyes[(sizeof (read_cc_btyes) - 1)] = READ_ONLY_NDEF_DESFIRE;
-
- /* Class Byte */
- NdefSmtCrdFmt->SendRecvBuf[i] = PH_FRINFC_DESF_NATIVE_CLASS_BYTE;
- i++;
-
- /* let the place to store the cmd byte type, point to next index
- Instruction Cmd code */
- NdefSmtCrdFmt->SendRecvBuf[i] = PH_FRINFC_DESF_WRITE_CMD;
- i++;
-
-
- /* P1/P2 offsets always set to zero */
- NdefSmtCrdFmt->SendRecvBuf[i] = PH_FRINFC_DESF_NATIVE_OFFSET_P1;
- i++;
- NdefSmtCrdFmt->SendRecvBuf[i] = PH_FRINFC_DESF_NATIVE_OFFSET_P2;
- i++;
-
- /* Lc: Length of wrapped data */
- NdefSmtCrdFmt->SendRecvBuf[i] = PH_FRINFC_DESF_NATIVE_WRCC_WRDT_LEN;
- i++;
-
-#ifdef DESFIRE_FMT_EV1
- if (DESFIRE_CARD_TYPE_EV1 == NdefSmtCrdFmt->CardType)
- {
- /* set the file id*/
- NdefSmtCrdFmt->SendRecvBuf[i] = DESFIRE_EV1_CC_FILE_ID;
- i++;
- }
- else
-#endif /* #ifdef DESFIRE_FMT_EV1 */
- {
- /* set the file id*/
- NdefSmtCrdFmt->SendRecvBuf[i] = PH_FRINFC_DESF_CC_FILE_ID;
- i++;
- }
-
- /* set the offset to zero*/
- NdefSmtCrdFmt->SendRecvBuf[i] = 0x00;
- i++;
- NdefSmtCrdFmt->SendRecvBuf[i] = 0x00;
- i++;
- NdefSmtCrdFmt->SendRecvBuf[i] = 0x00;
- i++;
-
- /* Set the length of data available to write*/
- NdefSmtCrdFmt->SendRecvBuf[i] = PH_FRINFC_DESF_CC_FILE_SIZE;
- i++;
- NdefSmtCrdFmt->SendRecvBuf[i] = 0x00;
- i++;
- NdefSmtCrdFmt->SendRecvBuf[i] = 0x00;
- i++;
-
- /*set the data to be written to the CC file*/
- (void)memcpy ((void *)&NdefSmtCrdFmt->SendRecvBuf[i],
- (void *)read_cc_btyes, sizeof (read_cc_btyes));
-#ifdef DESFIRE_FMT_EV1
-#else
- i++;
-#endif /* #ifdef DESFIRE_FMT_EV1 */
-
- i = (uint16_t)(i + sizeof (read_cc_btyes));
-
- /* Le bytes*/
- NdefSmtCrdFmt->SendRecvBuf[i] = PH_FRINFC_DESF_NATIVE_LE_BYTE;
- i++;
-#ifdef DESFIRE_FMT_EV1
- if (DESFIRE_CARD_TYPE_EV1 == NdefSmtCrdFmt->CardType)
- {
- NdefSmtCrdFmt->SendLength = i;
- }
- else
-#endif /* #ifdef DESFIRE_FMT_EV1 */
- {
- NdefSmtCrdFmt->SendLength = PH_FRINFC_DESF_WRITECC_CMD_SNLEN;
- }
-
- result = phFriNfc_Desf_HSendTransCmd (NdefSmtCrdFmt);
- }
- else
- {
- result = PHNFCSTVAL(CID_FRI_NFC_NDEF_SMTCRDFMT,
- NFCSTATUS_FORMAT_ERROR);
- }
-
- return result;
-}
-
-static
-NFCSTATUS
-phFriNfc_Desf_HReadOnlySelectApp (
- phFriNfc_sNdefSmtCrdFmt_t *NdefSmtCrdFmt)
-{
- NFCSTATUS result = NFCSTATUS_SUCCESS;
-
- NdefSmtCrdFmt->CardType = 0;
-
- NdefSmtCrdFmt->State = PH_FRINFC_DESF_STATE_RO_SELECT_APP;
-
- /* Helper routine to wrap the native DESFire cmds */
- phFriNfc_Desf_HWrapISONativeCmds (NdefSmtCrdFmt, PH_FRINFC_DESF_SELECTAPP_CMD);
-
- result = phFriNfc_Desf_HSendTransCmd (NdefSmtCrdFmt);
-
- return result;
-}
-
-#ifdef DESFIRE_FMT_EV1
-static
-NFCSTATUS
-phFriNfc_Desf_HReadOnlySelectAppEV1 (
- phFriNfc_sNdefSmtCrdFmt_t *NdefSmtCrdFmt)
-{
- NFCSTATUS result = NFCSTATUS_SUCCESS;
-
- NdefSmtCrdFmt->CardType = DESFIRE_CARD_TYPE_EV1;
-
- NdefSmtCrdFmt->State = PH_FRINFC_DESF_STATE_RO_SELECT_APP_EV1;
-
- /* Helper routine to wrap the native DESFire cmds */
- phFriNfc_Desf_HWrapISONativeCmds (NdefSmtCrdFmt, PH_FRINFC_DESF_SELECTAPP_CMD);
-
- result = phFriNfc_Desf_HSendTransCmd (NdefSmtCrdFmt);
-
- return result;
-}
-#endif /* #ifdef DESFIRE_FMT_EV1 */
-
-NFCSTATUS
-phFriNfc_Desfire_ConvertToReadOnly (
- phFriNfc_sNdefSmtCrdFmt_t *NdefSmtCrdFmt)
-{
- NFCSTATUS result = NFCSTATUS_SUCCESS;
-
-#ifdef DESFIRE_FMT_EV1
- result = phFriNfc_Desf_HReadOnlySelectAppEV1 (NdefSmtCrdFmt);
-#else
- result = phFriNfc_Desf_HReadOnlySelectApp (NdefSmtCrdFmt);
-#endif /* #ifdef DESFIRE_FMT_EV1 */
-
- return result;
-}
-
-#endif /* #ifdef FRINFC_READONLY_NDEF */
-
-void phFriNfc_Desf_Process( void *Context,
- NFCSTATUS Status)
-{
-
- phFriNfc_sNdefSmtCrdFmt_t *NdefSmtCrdFmt;
-
- NdefSmtCrdFmt = (phFriNfc_sNdefSmtCrdFmt_t *)Context;
-
- if((NFCSTATUS_SUCCESS & PHNFCSTBLOWER) == (Status & PHNFCSTBLOWER))
- {
- switch(NdefSmtCrdFmt->State)
- {
-#ifdef FRINFC_READONLY_NDEF
-#ifdef DESFIRE_FMT_EV1
- case PH_FRINFC_DESF_STATE_RO_SELECT_APP_EV1:
- {
- if ((PH_FRINFC_DESF_NATIVE_RESP_BYTE1 ==
- NdefSmtCrdFmt->SendRecvBuf[(*NdefSmtCrdFmt->SendRecvLength - 2)])
- && (PH_FRINFC_DESF_NATIVE_RESP_BYTE2 ==
- NdefSmtCrdFmt->SendRecvBuf[(*NdefSmtCrdFmt->SendRecvLength - 1)]))
- {
- Status = phFriNfc_Desf_HReadOnlyReadCCFile (NdefSmtCrdFmt);
- }
- else
- {
- Status = phFriNfc_Desf_HReadOnlySelectApp (NdefSmtCrdFmt);
- }
- break;
- }
-#endif /* #ifdef DESFIRE_FMT_EV1 */
-
- case PH_FRINFC_DESF_STATE_RO_SELECT_APP:
- {
- Status = phFriNfc_Desf_HReadOnlyReadCCFile (NdefSmtCrdFmt);
- break;
- }
-
- case PH_FRINFC_DESF_STATE_RO_READ_CC_FILE:
- {
- Status = phFriNfc_Desf_HReadOnlyWriteCCFile (NdefSmtCrdFmt);
- break;
- }
-
- case PH_FRINFC_DESF_STATE_RO_UPDATE_CC_FILE:
- {
- if ((PH_FRINFC_DESF_NATIVE_RESP_BYTE1 ==
- NdefSmtCrdFmt->SendRecvBuf[(*NdefSmtCrdFmt->SendRecvLength - 2)])
- && (PH_FRINFC_DESF_NATIVE_RESP_BYTE2 ==
- NdefSmtCrdFmt->SendRecvBuf[(*NdefSmtCrdFmt->SendRecvLength - 1)]))
- {
- /* SUCCESSFULL Formatting */
-#ifdef DESFIRE_FMT_EV1
- if (DESFIRE_CARD_TYPE_EV1 == NdefSmtCrdFmt->CardType)
- {
- Status = phFriNfc_OvrHal_Reconnect (
- NdefSmtCrdFmt->LowerDevice,
- &NdefSmtCrdFmt->SmtCrdFmtCompletionInfo,
- NdefSmtCrdFmt->psRemoteDevInfo);
-
- if (NFCSTATUS_PENDING == Status)
- {
- NdefSmtCrdFmt->State = PH_FRINFC_DESF_STATE_REACTIVATE;
- }
- }
-#endif /* #ifdef DESFIRE_FMT_EV1 */
- }
- else
- {
- Status = PHNFCSTVAL(CID_FRI_NFC_NDEF_SMTCRDFMT,
- NFCSTATUS_FORMAT_ERROR);
- }
- break;
- }
-
-#endif /* #ifdef FRINFC_READONLY_NDEF */
- case PH_FRINFC_DESF_STATE_GET_HW_VERSION:
- {
- /* Check and store the h/w and s/w specific details.
- Ex: Major/Minor version, memory storage info. */
-
- Status = phFriNfc_Desf_HGetSWVersion (NdefSmtCrdFmt);
-
- break;
- }
-
- case PH_FRINFC_DESF_STATE_GET_SW_VERSION:
- {
- /* Check and store the h/w and s/w specific details.
- Ex: Major/Minor version, memory storage info. */
-
- Status = phFriNfc_Desf_HUpdateVersionDetails (NdefSmtCrdFmt);
- if ( Status == NFCSTATUS_SUCCESS )
- {
- Status = phFriNfc_Desf_HGetUIDDetails (NdefSmtCrdFmt);
- }
- break;
- }
-
- case PH_FRINFC_DESF_STATE_GET_UID:
- {
- Status = phFriNfc_Desf_HCreateApp (NdefSmtCrdFmt);
- break;
- }
-
- case PH_FRINFC_DESF_STATE_CREATE_AID:
- {
- Status = phFriNfc_Desf_HSelectApp (NdefSmtCrdFmt);
- break;
- }
-
- case PH_FRINFC_DESF_STATE_SELECT_APP:
- {
- Status = phFriNfc_Desf_HCreatCCFile (NdefSmtCrdFmt);
- break;
- }
-
- case PH_FRINFC_DESF_STATE_CREATE_CCFILE:
- {
- Status = phFriNfc_Desf_HCreatNDEFFile (NdefSmtCrdFmt);
- break;
- }
-
- case PH_FRINFC_DESF_STATE_CREATE_NDEFFILE:
- {
- Status = phFriNfc_Desf_HWrCCBytes (NdefSmtCrdFmt);
- break;
- }
-
- case PH_FRINFC_DESF_STATE_WRITE_CC_FILE:
- {
- Status = phFriNfc_Desf_HWrNDEFData (NdefSmtCrdFmt);
- break;
- }
-
- case PH_FRINFC_DESF_STATE_WRITE_NDEF_FILE:
- {
- if ((PH_FRINFC_DESF_NATIVE_RESP_BYTE1 ==
- NdefSmtCrdFmt->SendRecvBuf[PH_SMTCRDFMT_DESF_VAL0]) &&
- (PH_FRINFC_DESF_NATIVE_RESP_BYTE2 ==
- NdefSmtCrdFmt->SendRecvBuf[PH_SMTCRDFMT_DESF_VAL1]))
- {
- NdefSmtCrdFmt->CardState = 0;
-#ifdef DESFIRE_FMT_EV1
- if (DESFIRE_CARD_TYPE_EV1 == NdefSmtCrdFmt->CardType)
- {
- Status = phFriNfc_OvrHal_Reconnect (
- NdefSmtCrdFmt->LowerDevice,
- &NdefSmtCrdFmt->SmtCrdFmtCompletionInfo,
- NdefSmtCrdFmt->psRemoteDevInfo);
-
- if (NFCSTATUS_PENDING == Status)
- {
- NdefSmtCrdFmt->State = PH_FRINFC_DESF_STATE_REACTIVATE;
- }
- }
- else
-#endif /* #ifdef DESFIRE_FMT_EV1 */
- {
- Status = PHNFCSTVAL (CID_NFC_NONE, NFCSTATUS_SUCCESS);
- }
- }
- break;
- }
-
-#ifdef DESFIRE_FMT_EV1
- case PH_FRINFC_DESF_STATE_REACTIVATE:
- {
- /* Do nothing */
- break;
- }
-#endif /* #ifdef DESFIRE_FMT_EV1 */
-
- default:
- {
- /*set the invalid state*/
- Status = PHNFCSTVAL (CID_FRI_NFC_NDEF_SMTCRDFMT,
- NFCSTATUS_INVALID_DEVICE_REQUEST);
- break;
- }
- }
- }
- /* Handle the all the error cases*/
- if ((NFCSTATUS_PENDING & PHNFCSTBLOWER) != (Status & PHNFCSTBLOWER))
- {
- /* call respective CR */
- phFriNfc_SmtCrdFmt_HCrHandler(NdefSmtCrdFmt,Status);
- }
-
-}
-
diff --git a/libnfc-nxp/phFriNfc_DesfireFormat.h b/libnfc-nxp/phFriNfc_DesfireFormat.h
deleted file mode 100644
index cabb9b0..0000000
--- a/libnfc-nxp/phFriNfc_DesfireFormat.h
+++ /dev/null
@@ -1,278 +0,0 @@
-/*
- * Copyright (C) 2010 NXP Semiconductors
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-/*!
-* \file phFriNfc_DesfireFormat.h
-* \brief Type4 Smart card formatting.
-*
-* Project: NFC-FRI
-*
-* $Date: Tue Jul 27 08:59:52 2010 $
-* $Author: ing02260 $
-* $Revision: 1.3 $
-* $Aliases: $
-*
-*/
-
-#ifndef PHFRINFC_DESFIREFORMAT_H
-#define PHFRINFC_DESFIREFORMAT_H
-
-
-/*! \ingroup grp_file_attributes
-* \name NDEF Smart Card Foramting
-*
-* File: \ref phFriNfc_DesfireFormat.h
-*
-*/
-/*@{*/
-
-/*@}*/
-
-
-/* Enum to represent the state variables*/
-enum{
-
- PH_FRINFC_DESF_STATE_CREATE_AID = 0,
- PH_FRINFC_DESF_STATE_SELECT_APP = 1,
- PH_FRINFC_DESF_STATE_CREATE_CCFILE = 2,
- PH_FRINFC_DESF_STATE_CREATE_NDEFFILE = 3,
- PH_FRINFC_DESF_STATE_WRITE_CC_FILE = 4,
- PH_FRINFC_DESF_STATE_WRITE_NDEF_FILE = 5,
- PH_FRINFC_DESF_STATE_DISCON = 6,
- PH_FRINFC_DESF_STATE_CON = 7,
- PH_FRINFC_DESF_STATE_POLL = 8,
- PH_FRINFC_DESF_STATE_GET_UID = 9,
- PH_FRINFC_DESF_STATE_GET_SW_VERSION = 10,
- PH_FRINFC_DESF_STATE_GET_HW_VERSION = 11,
-#ifdef FRINFC_READONLY_NDEF
-
-#ifdef DESFIRE_FMT_EV1
- PH_FRINFC_DESF_STATE_RO_SELECT_APP_EV1 = 100,
-#endif /* #ifdef DESFIRE_FMT_EV1 */
-
- PH_FRINFC_DESF_STATE_RO_SELECT_APP = 101,
- PH_FRINFC_DESF_STATE_RO_SELECT_CC_FILE = 102,
- PH_FRINFC_DESF_STATE_RO_READ_CC_FILE = 103,
- PH_FRINFC_DESF_STATE_RO_UPDATE_CC_FILE = 104,
-
-#endif /* #ifdef FRINFC_READONLY_NDEF */
-
- /* following are used in the ISO wrapper commands*/
- PH_FRINFC_DESF_CREATEAPP_CMD = 0,
- PH_FRINFC_DESF_SELECTAPP_CMD = 1,
- PH_FRINFC_DESF_CREATECC_CMD = 2,
- PH_FRINFC_DESF_CREATENDEF_CMD = 3,
- PH_FRINFC_DESF_WRITECC_CMD = 4,
-#ifdef FRINFC_READONLY_NDEF
- PH_FRINFC_DESF_WRITECC_CMD_READ_ONLY = 20,
-#endif /* #ifdef FRINFC_READONLY_NDEF */
- PH_FRINFC_DESF_WRITENDEF_CMD = 5,
- PH_FRINFC_DESF_GET_HW_VERSION_CMD = 6,
- PH_FRINFC_DESF_GET_SW_VERSION_CMD = 7,
- PH_FRINFC_DESF_GET_UID_CMD = 8,
- PH_FRINFC_DESF_WRITENDEF_CMD_SNLEN = 15,
- PH_FRINFC_DESF_WRITECC_CMD_SNLEN = 28,
- PH_FRINFC_DESF_CREATECCNDEF_CMD_SNLEN = 13,
- PH_FRINFC_DESF_SELECTAPP_CMD_SNLEN = 9,
- PH_FRINFC_DESF_CREATEAPP_CMD_SNLEN = 11,
- PH_FRINFC_DESF_NATIVE_OFFSET_P1 = 0x00,
- PH_FRINFC_DESF_NATIVE_OFFSET_P2 = 0x00,
- PH_FRINFC_DESF_NATIVE_LE_BYTE = 0x00,
- PH_FRINFC_DESF_NATIVE_CRAPP_WRDT_LEN = 5,
- PH_FRINFC_DESF_NATIVE_SLAPP_WRDT_LEN = 3,
- PH_FRINFC_DESF_NATIVE_CRCCNDEF_WRDT_LEN = 7,
- PH_FRINFC_DESF_NATIVE_WRCC_WRDT_LEN = 22,
- PH_FRINFC_DESF_NATIVE_WRNDEF_WRDT_LEN = 9
-
-};
-
-
-/* CC File contents*/
-
-#define PH_FRINFC_DESF_CCFILE_BYTES {0x00,0x0f,0x10,0x00,0x3B,0x00,0x34,0x04,0x06,0xE1,0x04,0x04,0x00,0x00,0x00 }
-#define PH_FRINFC_DESF_NDEFFILE_BYTES {0x00,0x00}
-#define PH_FRINFC_DESF_PICC_MASTER_KEY {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00 }
-#define PH_FRINFC_DESF_NFCFORUM_APP_KEY {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00 }
-#define PH_FRINFC_DESF_COMM_SETTINGS 0x00
-#define PH_FRINFC_DESF_CREATE_DATA_FILE_CMD 0xCD
-#define PH_FRINFC_DESF_NATIVE_CLASS_BYTE 0x90
-
-/* Constant defined to specify the NFC Forum Application ID : 0xEEEE10*/
-/* This is defined in order to support to N/W Byte order style : LSB : : MSB*/
-#define PH_FRINFC_DESF_FIRST_AID_BYTE 0x10
-#define PH_FRINFC_DESF_SEC_AID_BYTE 0xEE
-#define PH_FRINFC_DESF_THIRD_AID_BYTE 0xEE
-
-
-/* Create File command constants*/
-#define PH_FRINFC_DESF_CREATE_AID_CMD 0xCA
-
-/* Specifies the NFC Forum App Number of Keys*/
-#define PH_FRINFC_DESF_NFCFORUM_APP_NO_OF_KEYS 0x01
-
-#define PH_FRINFC_DESF_SLECT_APP_CMD 0x5A
-
-#define PH_FRINFC_DESF_GET_VER_CMD 0x60
-
-
-#define PH_FRINFC_DESF_NATIVE_RESP_BYTE1 0x91
-#define PH_FRINFC_DESF_NATIVE_RESP_BYTE2 0x00
-
-/* Create CC File Commands*/
-#define PH_FRINFC_DESF_CC_FILE_ID 0x03
-#define PH_FRINFC_DESF_CC_FILE_SIZE 0x0F
-#define PH_FRINFC_DESF_FIRST_BYTE_CC_ACCESS_RIGHTS 0x00
-#define PH_FRINFC_DESF_SEC_BYTE_CC_ACCESS_RIGHTS 0xE0
-
-
-/* Create NDEF File Commands*/
-#define PH_FRINFC_DESF_NDEF_FILE_ID 0x04
-#define PH_FRINFC_DESF_NDEF_FILE_SIZE 0x04
-#define PH_FRINFC_DESF_FIRST_BYTE_NDEF_ACCESS_RIGHTS 0xE0
-#define PH_FRINFC_DESF_SEC_BYTE_NDEF_ACCESS_RIGHTS 0xEE
-
-
-/* Write/Read Data commands/constants*/
-#define PH_FRINFC_DESF_WRITE_CMD 0x3D
-
-/* PICC additional frame response*/
-#define PH_FRINFC_DESF_PICC_ADDI_FRAME_RESP 0xAF
-
-/* Response for PICC native DESFire wrapper cmd*/
-#define PH_FRINFC_DESF_NAT_WRAP_FIRST_RESP_BYTE 0x91
-#define PH_FRINFC_DESF_NAT_WRAP_SEC_RESP_BYTE 0x00
-
-/* DESFire4 Major/Minor versions*/
-#define PH_FRINFC_DESF4_MAJOR_VERSION 0x00
-#define PH_FRINFC_DESF4_MINOR_VERSION 0x06
-
-/* DESFire4 memory size*/
-#define PH_FRINFC_DESF4_MEMORY_SIZE 0xEDE
-
-enum{
- PH_SMTCRDFMT_DESF_VAL0 = 0,
- PH_SMTCRDFMT_DESF_VAL1 = 1,
- PH_SMTCRDFMT_DESF_VAL2 = 2,
- PH_SMTCRDFMT_DESF_VAL3 = 3,
- PH_SMTCRDFMT_DESF_VAL4 = 4,
- PH_SMTCRDFMT_DESF_VAL14 = 14,
- PH_SMTCRDFMT_DESF_VAL15 = 15
-};
-
-
-
-/*!
-* \brief \copydoc page_reg Resets the component instance to the initial state and lets the component forget about
-* the list of registered items. Moreover, the lower device is set.
-*
-* \param[in] NdefSmtCrdFmt Pointer to a valid or uninitialized instance of \ref phFriNfc_sNdefSmtCrdFmt_t.
-*
-* \note This function has to be called at the beginning, after creating an instance of
-* \ref phFriNfc_sNdefSmtCrdFmt_t. Use this function to reset the instance of smart card
-formatting context variables.
-*/
-void phFriNfc_Desfire_Reset(phFriNfc_sNdefSmtCrdFmt_t *NdefSmtCrdFmt);
-
-/*!
-* \ingroup grp_fri_smart_card_formatting
-*
-* \brief Initiates the card formatting procedure for Remote Smart Card Type.
-*
-* \copydoc page_ovr The function initiates and formats the DESFire Card.After this
-* operation,remote card would be properly initialized and
-* Ndef Compliant.Depending upon the different card type, this
-* function handles formatting procedure.This function also handles
-* the different recovery procedures for different types of the cards.
-* For both Format and Recovery Management same API is used.
-*
-* \param[in] phFriNfc_sNdefSmartCardFmt_t Pointer to a valid instance of the \ref phFriNfc_sNdefSmartCardFmt_t
-* structure describing the component context.
-*
-* \retval NFCSTATUS_SUCCESS Card formatting has been successfully completed.
-* \retval NFCSTATUS_PENDING The action has been successfully triggered.
-* \retval NFCSTATUS_FORMAT_ERROR Error occured during the formatting procedure.
-* \retval NFCSTATUS_INVALID_REMOTE_DEVICE Card Type is unsupported.
-* \retval NFCSTATUS_INVALID_DEVICE_REQUEST Command or Operation types are mismatching.
-*
-*/
-NFCSTATUS phFriNfc_Desfire_Format(phFriNfc_sNdefSmtCrdFmt_t *NdefSmtCrdFmt);
-
-/*!
-* \brief \copydoc page_reg Resets the component instance to the initial state and lets the component forget about
-* the list of registered items. Moreover, the lower device is set.
-*
-* \param[in] NdefSmtCrdFmt Pointer to a valid or uninitialized instance of \ref phFriNfc_sNdefSmtCrdFmt_t.
-*
-* \note This function has to be called at the beginning, after creating an instance of
-* \ref phFriNfc_sNdefSmtCrdFmt_t. Use this function to reset the instance of smart card
-formatting context variables.
-*/
-void phFriNfc_Desfire_Reset(phFriNfc_sNdefSmtCrdFmt_t *NdefSmtCrdFmt);
-
-#ifdef FRINFC_READONLY_NDEF
-/*!
- * \ingroup grp_fri_smart_card_formatting
- *
- * \brief Initiates the conversion of the already NDEF formatted tag to READ ONLY.
- *
- * \copydoc page_ovr The function initiates the conversion of the already NDEF formatted
- * tag to READ ONLY. After this formation, remote card would be properly Ndef Compliant and READ ONLY.
- * Depending upon the different card type, this function handles formatting procedure.
- *
- * \param[in] phFriNfc_sNdefSmartCardFmt_t Pointer to a valid instance of the \ref phFriNfc_sNdefSmartCardFmt_t
- * structure describing the component context.
- *
- * \retval NFCSTATUS_SUCCESS Card formatting has been successfully completed.
- * \retval NFCSTATUS_PENDING The action has been successfully triggered.
- * \retval NFCSTATUS_FORMAT_ERROR Error occured during the formatting procedure.
- * \retval NFCSTATUS_INVALID_REMOTE_DEVICE Card Type is unsupported.
- * \retval NFCSTATUS_INVALID_DEVICE_REQUEST Command or Operation types are mismatching.
- *
- */
-NFCSTATUS
-phFriNfc_Desfire_ConvertToReadOnly (
- phFriNfc_sNdefSmtCrdFmt_t *NdefSmtCrdFmt);
-#endif /* #ifdef FRINFC_READONLY_NDEF */
-
-/**
-*\ingroup grp_fri_smart_card_formatting
-*
-* \brief Smart card Formatting \b Completion \b Routine or \b Process function
-*
-* \copydoc page_ovr Completion Routine: This function is called by the lower layer (OVR HAL)
-* when an I/O operation has finished. The internal state machine decides
-* whether to call into the lower device again or to complete the process
-* by calling into the upper layer's completion routine, stored within this
-* component's context (\ref phFriNfc_sNdefSmtCrdFmt_t).
-*
-* The function call scheme is according to \ref grp_interact. No State reset is performed during
-* operation.
-*
-* \param[in] Context The context of the current (not the lower/upper) instance, as set by the lower,
-* calling layer, upon its completion.
-* \param[in] Status The completion status of the lower layer (to be handled by the implementation of
-* the state machine of this function like a regular return value of an internally
-* called function).
-*
-* \note For general information about the completion routine interface please see \ref pphFriNfc_Cr_t . * The Different Status Values are as follows
-*
-*/
-void phFriNfc_Desf_Process(void *Context,
- NFCSTATUS Status);
-
-
-#endif
-
diff --git a/libnfc-nxp/phFriNfc_DesfireMap.c b/libnfc-nxp/phFriNfc_DesfireMap.c
deleted file mode 100644
index 2ce46ad..0000000
--- a/libnfc-nxp/phFriNfc_DesfireMap.c
+++ /dev/null
@@ -1,1830 +0,0 @@
-/*
- * Copyright (C) 2010 NXP Semiconductors
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-/*!
-* \file phFriNfc_Desfire.c
-* \brief This component encapsulates read/write/check ndef/process functionalities,
-* for the Desfire Card.
-*
-* Project: NFC-FRI
-*
-* $Date: Tue Jul 27 08:58:22 2010 $
-* $Author: ing02260 $
-* $Revision: 1.11 $
-* $Aliases: $
-*
-*/
-
-#ifndef PH_FRINFC_MAP_DESFIRE_DISABLED
-
-#include
-#include
-#include
-
-
-/*! \ingroup grp_file_attributes
-* \name NDEF Mapping
-*
-* File: \ref phFriNfc_Desfire.c
-*
-*/
-/*@{*/
-#define PHFRINFCNDEFMAP_FILEREVISION "$Revision: 1.11 $"
-#define PHFRINFCNDEFMAP_FILEALIASES "$Aliases: $"
-
-/*@}*/
-
-/***************** Start of MACROS ********************/
-#ifdef DESFIRE_EV1
- #define DESFIRE_EV1_P2_OFFSET_VALUE (0x0CU)
-#endif /* #ifdef DESFIRE_EV1 */
-
-/***************** End of MACROS ********************/
-
-/*@}*/
-
-/*!
- * \name Desfire Mapping - Helper Functions
- *
- */
-/*@{*/
-
-/*!
- * \brief \copydoc page_ovr Helper function for Desfire. This function specifies
- * the card is a Desfire card or not.
- */
-static NFCSTATUS phFriNfc_Desfire_SelectSmartTag( phFriNfc_NdefMap_t *NdefMap);
-
-/*!
- * \brief \copydoc page_ovr Helper function for Desfire. This function is used
- * to selct a file in the card.
- */
-static NFCSTATUS phFriNfc_Desfire_SelectFile ( phFriNfc_NdefMap_t *NdefMap);
-
-/*!
- * \brief \copydoc page_ovr Helper function for Desfire. This function is to
- * read the card.
- */
-static NFCSTATUS phFriNfc_Desfire_ReadBinary( phFriNfc_NdefMap_t *NdefMap);
-
-/*!
- * \brief \copydoc page_ovr Helper function for Desfire. This function is to
- * write to the card.
- */
-static NFCSTATUS phFriNfc_Desfire_UpdateBinary( phFriNfc_NdefMap_t *NdefMap);
-
-/*!
- * \brief \copydoc page_ovr Helper function for Desfire. This function is to
- * update the capability container of the card.
- */
-static NFCSTATUS phFriNfc_Desfire_Update_SmartTagCapContainer( phFriNfc_NdefMap_t *NdefMap);
-
-
-/* Completion Helper*/
-static void phFriNfc_Desfire_HCrHandler( phFriNfc_NdefMap_t *NdefMap,
- NFCSTATUS Status);
-
-/* Calculates the Le Bytes for Read Operation*/
-static uint32_t phFriNfc_Desfire_HGetLeBytes( phFriNfc_NdefMap_t *NdefMap);
-
-static NFCSTATUS phFriNfc_Desf_HChkAndParseTLV( phFriNfc_NdefMap_t *NdefMap,
- uint8_t BuffIndex);
-
-static NFCSTATUS phFriNfc_Desfire_HSetGet_NLEN( phFriNfc_NdefMap_t *NdefMap);
-
-static void phFriNfc_Desfire_HProcReadData( phFriNfc_NdefMap_t *NdefMap);
-
-static void phFriNfc_Desfire_HChkNDEFFileAccessRights( phFriNfc_NdefMap_t *NdefMap);
-static NFCSTATUS phFriNfc_Desfire_HSendTransCmd(phFriNfc_NdefMap_t *NdefMap,uint8_t SendRecvLen);
-
-#ifdef PH_HAL4_ENABLE
-
-#else
-
-/* Following are the API's are used to get the version of the desfire card*/
-static NFCSTATUS phFriNfc_Desfire_HGetHWVersion(phFriNfc_NdefMap_t *NdefMap);
-static NFCSTATUS phFriNfc_Desfire_HGetSWVersion(phFriNfc_NdefMap_t *NdefMap);
-static NFCSTATUS phFriNfc_Desfire_HGetUIDDetails(phFriNfc_NdefMap_t *NdefMap);
-static NFCSTATUS phFriNfc_Desfire_HUpdateVersionDetails(const phFriNfc_NdefMap_t *NdefMap);
-
-#endif /* #ifdef PH_HAL4_ENABLE */
-
-#ifdef PH_HAL4_ENABLE
-
-#else
-
-static NFCSTATUS phFriNfc_Desfire_HGetHWVersion(phFriNfc_NdefMap_t *NdefMap)
-{
-
- NFCSTATUS status = NFCSTATUS_PENDING;
-
- /*set the state*/
- NdefMap->State = PH_FRINFC_DESF_STATE_GET_HW_VERSION;
-
- /* Helper routine to wrap the native desfire cmds*/
- PH_FRINFC_DESF_ISO_NATIVE_WRAPPER();
- status = phFriNfc_Desfire_HSendTransCmd(NdefMap,PH_FRINFC_NDEFMAP_MAX_SEND_RECV_BUF_SIZE);
-
- return (status);
-}
-
-static NFCSTATUS phFriNfc_Desfire_HGetSWVersion(phFriNfc_NdefMap_t *NdefMap)
-{
-
- NFCSTATUS status = NFCSTATUS_PENDING;
- if( ( NdefMap->SendRecvBuf[*(NdefMap->SendRecvLength)- 1] == PH_FRINFC_DESF_NATIVE_GETVER_RESP) )
- {
- /*set the state*/
- NdefMap->State = PH_FRINFC_DESF_STATE_GET_SW_VERSION;
-
- /* Helper routine to wrap the native desfire commands*/
- PH_FRINFC_DESF_ISO_NATIVE_WRAPPER();
- status = phFriNfc_Desfire_HSendTransCmd(NdefMap,PH_FRINFC_NDEFMAP_MAX_SEND_RECV_BUF_SIZE);
- }
-#ifdef PH_HAL4_ENABLE
- else
- {
- status = PHNFCSTVAL(CID_FRI_NFC_NDEF_MAP,
- NFCSTATUS_INVALID_PARAMETER);
- }
-#endif /* #ifdef PH_HAL4_ENABLE */
- return status;
-}
-
-static NFCSTATUS phFriNfc_Desfire_HGetUIDDetails(phFriNfc_NdefMap_t *NdefMap)
-{
-
- NFCSTATUS status = NFCSTATUS_PENDING;
-
- if( ( NdefMap->SendRecvBuf[*(NdefMap->SendRecvLength)- 1] == PH_FRINFC_DESF_NATIVE_GETVER_RESP) )
- {
- /*set the state*/
- NdefMap->State = PH_FRINFC_DESF_STATE_GET_UID;
-
- /* Helper routine to wrap the native desfire commands*/
- PH_FRINFC_DESF_ISO_NATIVE_WRAPPER();
-
- status = phFriNfc_Desfire_HSendTransCmd(NdefMap,PH_FRINFC_NDEFMAP_MAX_SEND_RECV_BUF_SIZE);
- }
-#ifdef PH_HAL4_ENABLE
- else
- {
- status = PHNFCSTVAL(CID_FRI_NFC_NDEF_MAP,
- NFCSTATUS_INVALID_PARAMETER);
- }
-#endif /* #ifdef PH_HAL4_ENABLE */
- return status;
-
-}
-
-static NFCSTATUS phFriNfc_Desfire_HUpdateVersionDetails(const phFriNfc_NdefMap_t *NdefMap)
-{
- NFCSTATUS status = PHNFCSTVAL(CID_FRI_NFC_NDEF_MAP,
- NFCSTATUS_INVALID_PARAMETER);
-
- if( ( NdefMap->SendRecvBuf[*(NdefMap->SendRecvLength)- 1] == 0xAF) )
- {
-
- status = NFCSTATUS_SUCCESS;
-
- /* We do not need the following details presently.Retained for future use*/
- #if 0
- NdefMap->AddInfo.Type4Info.MajorVersion = NdefSmtCrdFmt->SendRecvBuf[3];
- NdefMap->AddInfo.Type4Info.MinorVersion = NdefSmtCrdFmt->SendRecvBuf[4];
- if ( ( NdefMap->AddInfo.Type4Info.MajorVersion == 0x00 )&&
- ( NdefMap->AddInfo.Type4Info.MinorVersion == 0x06 ))
- {
- /* card size of DESFire4 type */
- //NdefMap->AddInfo.Type4Info.CardSize = 0xEDE;
-
- }
- else
- {
- // need to handle the Desfire8 type cards
- // need to use get free memory
- }
- #endif
- }
- return status;
-}
-
-
-#endif /* #ifdef PH_HAL4_ENABLE */
-
-/*!
-* \brief Initiates Reading of NDEF information from the Desfire Card.
-*
-* The function initiates the reading of NDEF information from a Remote Device.
-* It performs a reset of the state and starts the action (state machine).
-* A periodic call of the \ref phFriNfcNdefMap_Process has to be
-* done once the action has been triggered.
-*/
-
-NFCSTATUS phFriNfc_Desfire_RdNdef( phFriNfc_NdefMap_t *NdefMap,
- uint8_t *PacketData,
- uint32_t *PacketDataLength,
- uint8_t Offset)
-{
- NFCSTATUS status = NFCSTATUS_PENDING;
-
- NdefMap->ApduBufferSize = *PacketDataLength;
- /* To return actual number of bytes read to the caller */
- NdefMap->NumOfBytesRead = PacketDataLength ;
- *NdefMap->NumOfBytesRead = 0;
-
- /* store the offset in to map context*/
- NdefMap->Offset = Offset;
-
- if( (Offset == PH_FRINFC_NDEFMAP_SEEK_CUR) &&
- (*NdefMap->DataCount == NdefMap->DesfireCapContainer.NdefDataLen))
- {
- /* No space on card for Reading : we have already
- reached the end of file !
- Offset is set to Continue Operation */
- status = PHNFCSTVAL(CID_FRI_NFC_NDEF_MAP,
- NFCSTATUS_EOF_NDEF_CONTAINER_REACHED);
- }
- else
- {
-
- /* reset the inter flag*/
- NdefMap->DesfireCapContainer.IsNlenPresentFlag = 0;
- NdefMap->DesfireCapContainer.SkipNlenBytesFlag = 0;
-
- /* Set the desfire read operation */
- NdefMap->DespOpFlag = PH_FRINFC_NDEFMAP_DESF_READ_OP;
-
- /* Save the packet data buffer address in the context */
- NdefMap->ApduBuffer = PacketData;
-
- NdefMap->PrevOperation = PH_FRINFC_NDEFMAP_READ_OPE;
-
-#ifdef DESFIRE_EV1
- /* Select smart tag operation. First step for the read operation. */
- if (PH_FRINFC_NDEFMAP_ISO14443_4A_CARD_EV1 == NdefMap->CardType)
- {
- status = phFriNfc_Desfire_SelectFile(NdefMap);
- }
- else
-#endif /* #ifdef DESFIRE_EV1 */
- {
- status = phFriNfc_Desfire_SelectSmartTag(NdefMap);
- }
- }
-
- return status;
-}
-
-/*!
-* \brief Initiates Writing of NDEF information to the Remote Device.
-*
-* The function initiates the writing of NDEF information to a Remote Device.
-* It performs a reset of the state and starts the action (state machine).
-* A periodic call of the \ref phFriNfcNdefMap_Process has to be done once the action
-* has been triggered.
-*/
-
-NFCSTATUS phFriNfc_Desfire_WrNdef( phFriNfc_NdefMap_t *NdefMap,
- uint8_t *PacketData,
- uint32_t *PacketDataLength,
- uint8_t Offset)
-{
- NFCSTATUS status = NFCSTATUS_PENDING;
-
- NdefMap->ApduBufferSize = *PacketDataLength;
- NdefMap->WrNdefPacketLength = PacketDataLength;
-
- /* Now, let's initialize *NdefMap->WrNdefPacketLength to zero.
- In case we get an error, this will be correctly set to "no byte written".
- In case there is no error, this will be updated later on, in the _process function.
- */
- *NdefMap->WrNdefPacketLength = 0;
-
- /* we have write access. */
- if( *NdefMap->DataCount >= PH_NFCFRI_NDEFMAP_DESF_NDEF_FILE_SIZE)
- {
- /* No space on card for writing : we have already
- reached the end of file !
- Offset is set to Continue Operation */
- status = PHNFCSTVAL(CID_FRI_NFC_NDEF_MAP,
- NFCSTATUS_EOF_NDEF_CONTAINER_REACHED);
- }
- else
- {
- /* Adapt the nb of bytes that the user would like to write */
-
- /*set the defire write operation*/
- NdefMap->DespOpFlag = PH_FRINFC_NDEFMAP_DESF_WRITE_OP;
- NdefMap->PrevOperation = PH_FRINFC_NDEFMAP_WRITE_OPE;
- NdefMap->Offset = Offset;
-
- /*Store the packet data buffer*/
- NdefMap->ApduBuffer = PacketData;
-
-#ifdef DESFIRE_EV1
- if (PH_FRINFC_NDEFMAP_ISO14443_4A_CARD_EV1 == NdefMap->CardType)
- {
- status = phFriNfc_Desfire_SelectFile(NdefMap);
- }
- else
-#endif /* #ifdef DESFIRE_EV1 */
- {
- /* Select smart tag operation. First step for the write operation. */
- status = phFriNfc_Desfire_SelectSmartTag (NdefMap);
- }
- }
- return status;
-}
-
-/*!
-* \brief Check whether a particular Remote Device is NDEF compliant.
-*
-* The function checks whether the peer device is NDEF compliant.
-*
-*/
-
-NFCSTATUS phFriNfc_Desfire_ChkNdef( phFriNfc_NdefMap_t *NdefMap)
-{
- NFCSTATUS status = NFCSTATUS_PENDING;
-
-#ifdef PH_HAL4_ENABLE
-
-#ifdef DESFIRE_EV1
- /* Reset card type */
- NdefMap->CardType = 0;
-#endif /* #ifdef DESFIRE_EV1 */
- /*Set the desfire operation flag*/
- NdefMap->DespOpFlag = PH_FRINFC_NDEFMAP_DESF_NDEF_CHK_OP;
-
- /*Call Select Smart tag Functinality*/
- status = phFriNfc_Desfire_SelectSmartTag(NdefMap);
-#else
- /* Need to get the version details of the card, to
- identify the the desfire4card type */
- status = phFriNfc_Desfire_HGetHWVersion(NdefMap);
-#endif
-
- return (status);
-}
-
-static NFCSTATUS phFriNfc_Desf_HChkAndParseTLV(phFriNfc_NdefMap_t *NdefMap, uint8_t BuffIndex)
-{
- NFCSTATUS status = NFCSTATUS_SUCCESS;
-
- if((NdefMap->SendRecvBuf[BuffIndex] <= 0x03) ||
- (NdefMap->SendRecvBuf[BuffIndex] >= 0x06) )
- {
- status = PHNFCSTVAL( CID_FRI_NFC_NDEF_MAP,
- NFCSTATUS_NO_NDEF_SUPPORT);
- }
- else
- {
- /* check for the type of TLV*/
- NdefMap->TLVFoundFlag =
- ((NdefMap->SendRecvBuf[BuffIndex] == 0x04)?
- PH_FRINFC_NDEFMAP_DESF_NDEF_CNTRL_TLV:
- PH_FRINFC_NDEFMAP_DESF_PROP_CNTRL_TLV);
-
- status = PHNFCSTVAL( CID_FRI_NFC_NDEF_MAP,
- NFCSTATUS_SUCCESS);
- }
- return status;
-}
-
-static NFCSTATUS phFriNfc_Desfire_HSetGet_NLEN(phFriNfc_NdefMap_t *NdefMap)
-{
-
- NFCSTATUS status = NFCSTATUS_PENDING;
-
- if ( PH_FRINFC_NDEFMAP_DESF_GET_LEN_OP == NdefMap->DespOpFlag)
- {
-
- /*Call Select Smart tag Functinality*/
- status = phFriNfc_Desfire_SelectSmartTag(NdefMap);
- }
- else
- {
-
- /* Get the Data Count and set it to NoOfBytesWritten
- Update the NLEN using Transceive cmd*/
-
- /*Form the packet for the update binary command*/
- NdefMap->SendRecvBuf[0] = 0x00;
- NdefMap->SendRecvBuf[1] = 0xD6;
-
- /* As we need to set the NLEN @ first 2 bytes of NDEF File*/
- /* set the p1/p2 offsets */
- NdefMap->SendRecvBuf[2] = 0x00; /* p1 */
- NdefMap->SendRecvBuf[3] = 0x00; /* p2 */
-
- /* Set only two bytes as NLEN*/
- NdefMap->SendRecvBuf[4] = 0x02;
-
- /* update NLEN */
- NdefMap->SendRecvBuf[5] = (uint8_t)(*NdefMap->DataCount >> PH_FRINFC_NDEFMAP_DESF_SHL8);
- NdefMap->SendRecvBuf[6] = (uint8_t)(*NdefMap->DataCount & (0x00ff));
-
- NdefMap->SendLength = 0x07 ;
-
- /* Change the state to Write */
- NdefMap->State = PH_FRINFC_NDEFMAP_DESF_STATE_UPDATE_BIN_END;
-
- status = phFriNfc_Desfire_HSendTransCmd(NdefMap,PH_FRINFC_NDEFMAP_DESF_RESP_OFFSET);
- }
- return status;
-}
-
-static void phFriNfc_Desfire_HProcReadData(phFriNfc_NdefMap_t *NdefMap)
-{
- NFCSTATUS Result = NFCSTATUS_PENDING;
- uint32_t BufferSize = 0;
- uint8_t BufIndex=0;
- uint16_t SizeToCpy=0;
-
- /* Need to check the Actual Ndef Length before copying the data to buffer*/
- /* Only NDEF data should be copied , rest all the data should be ignored*/
- /* Ex : Ndef File Size 50 bytes , but only 5 bytes(NLEN) are relavent to NDEF data*/
- /* component should only copy 5 bytes to user buffer*/
-
- /* Data has been read successfully in the TRX buffer. */
- /* copy it to the user buffer. */
-
- /* while copying need check the offset if its begin need to skip the first 2 bytes
- while copying. If its current no need to skip the first 2 bytes*/
-
- if ( NdefMap->Offset == PH_FRINFC_NDEFMAP_SEEK_BEGIN )
- {
- BufIndex = (uint8_t)(( NdefMap->DesfireCapContainer.IsNlenPresentFlag == 1 )?
- 0:PH_FRINFC_NDEFMAP_DESF_NLEN_SIZE_IN_BYTES);
-
- /* Update the latest NLEN to context*/
- NdefMap->DesfireCapContainer.NdefDataLen = ((*NdefMap->DataCount == 0)?
- ( (((uint16_t)NdefMap->SendRecvBuf[
- PH_FRINFC_NDEFMAP_DESF_CCLEN_BYTE_FIRST_INDEX])<<8)+ \
- NdefMap->SendRecvBuf[PH_FRINFC_NDEFMAP_DESF_CCLEN_BYTE_SECOND_INDEX]):
- NdefMap->DesfireCapContainer.NdefDataLen);
-
- /* Decide how many byes to be copied into user buffer: depending upon the actual NDEF
- size need to copy the content*/
- if ( (NdefMap->DesfireCapContainer.NdefDataLen) <= (*NdefMap->SendRecvLength - \
- (PH_FRINFC_NDEFMAP_DESF_RESP_OFFSET + BufIndex)))
- {
- SizeToCpy = NdefMap->DesfireCapContainer.NdefDataLen;
-
- }
- else
- {
- SizeToCpy = ((*NdefMap->SendRecvLength)-(PH_FRINFC_NDEFMAP_DESF_RESP_OFFSET+BufIndex));
- }
-
- /* Check do we have Ndef Data len > 0 present in the card.If No Ndef Data
- present in the card , set the card state to Initalised and set an Error*/
- if ( NdefMap->DesfireCapContainer.NdefDataLen == 0x00 )
- {
- NdefMap->CardState = PH_NDEFMAP_CARD_STATE_INITIALIZED;
- Result = PHNFCSTVAL(CID_FRI_NFC_NDEF_MAP, NFCSTATUS_EOF_NDEF_CONTAINER_REACHED);
-#ifdef PH_HAL4_ENABLE
-#else
- NdefMap->PrevOperation = 0;
-#endif /* #ifdef PH_HAL4_ENABLE */
- phFriNfc_Desfire_HCrHandler(NdefMap,Result);
- }
- else
- {
- (void)memcpy( (&(NdefMap->ApduBuffer[
- NdefMap->ApduBuffIndex])),
- (&(NdefMap->SendRecvBuf[BufIndex])),
- (SizeToCpy));
-
- /* Increment the Number of Bytes Read, which will be returned to the caller. */
- *NdefMap->NumOfBytesRead = (uint32_t)(*NdefMap->NumOfBytesRead + SizeToCpy);
-
- /*update the data count*/
- *NdefMap->DataCount = (uint16_t)(*NdefMap->DataCount + SizeToCpy);
-
- /*update the buffer index of the apdu buffer*/
- NdefMap->ApduBuffIndex = (uint16_t)(NdefMap->ApduBuffIndex + SizeToCpy);
- }
- }
- else
- {
- (void)memcpy( (&(NdefMap->ApduBuffer[
- NdefMap->ApduBuffIndex])),
- (NdefMap->SendRecvBuf),/* to avoid the length of the NDEF File*/
- (*(NdefMap->SendRecvLength)-(PH_FRINFC_NDEFMAP_DESF_RESP_OFFSET)));
-
- /* Increment the Number of Bytes Read, which will be returned to the caller. */
- *NdefMap->NumOfBytesRead +=( *NdefMap->SendRecvLength - \
- (PH_FRINFC_NDEFMAP_DESF_RESP_OFFSET));
-
- /*update the data count*/
- *NdefMap->DataCount += \
- (*NdefMap->SendRecvLength - (PH_FRINFC_NDEFMAP_DESF_RESP_OFFSET));
-
- /*update the buffer index of the apdu buffer*/
- NdefMap->ApduBuffIndex += \
- *NdefMap->SendRecvLength - (PH_FRINFC_NDEFMAP_DESF_RESP_OFFSET );
- }
-
- /* check whether we still have to read some more data. */
- if (*NdefMap->DataCount < NdefMap->DesfireCapContainer.NdefDataLen )
- {
- /* we have some bytes to read. */
-
- /* Now check, we still have bytes left in the user buffer. */
- BufferSize = NdefMap->ApduBufferSize - NdefMap->ApduBuffIndex;
- if(BufferSize != 0)
- {
- /* Before read need to set the flag to intimate the module to
- dont skip the first 2 bytes as we are in mode reading next
- continues available bytes, which will not contain the NLEN
- information in the begining part that is 2 bytes*/
- NdefMap->DesfireCapContainer.IsNlenPresentFlag = 1;
- /* Read Operation is not complete */
- Result = phFriNfc_Desfire_ReadBinary( NdefMap );
- /* handle the error in Transc function*/
- if ( (Result & PHNFCSTBLOWER) != (NFCSTATUS_PENDING & PHNFCSTBLOWER) )
- {
- /* call respective CR */
- phFriNfc_Desfire_HCrHandler(NdefMap,Result);
- }
- }
- else
- {
- /* There are some more bytes to read, but
- no space in the user buffer */
- Result = PHNFCSTVAL(CID_NFC_NONE,NFCSTATUS_SUCCESS);
- NdefMap->ApduBuffIndex =0;
- /* call respective CR */
- phFriNfc_Desfire_HCrHandler(NdefMap,Result);
- }
- }
- else
- {
- if (*NdefMap->DataCount == NdefMap->DesfireCapContainer.NdefDataLen )
- {
- /* we have read all the bytes available in the card. */
- Result = PHNFCSTVAL(CID_NFC_NONE,NFCSTATUS_SUCCESS);
-#ifdef PH_HAL4_ENABLE
- /* Do nothing */
-#else
- NdefMap->PrevOperation = 0;
-#endif /* #ifndef PH_HAL4_ENABLE */
- }
- else
- {
- /* The control should not come here. */
- /* we have actually read more byte than available in the card. */
- NdefMap->PrevOperation = 0;
-#ifndef PH_HAL4_ENABLE
- Result = PHNFCSTVAL(CID_FRI_NFC_NDEF_MAP,
- NFCSTATUS_CMD_ABORTED);
-#else
- Result = PHNFCSTVAL(CID_FRI_NFC_NDEF_MAP,
- NFCSTATUS_FAILED);
-#endif
- }
-
-
- NdefMap->ApduBuffIndex = 0;
-
- /* call respective CR */
- phFriNfc_Desfire_HCrHandler(NdefMap,Result);
- }
-}
-
-
-
-/*!
-* \brief Completion Routine, Processing function, needed to avoid long blocking.
-* \note The lower (Overlapped HAL) layer must register a pointer to this function as a Completion
-* Routine in order to be able to notify the component that an I/O has finished and data are
-* ready to be processed.
-*
-*/
-
-void phFriNfc_Desfire_Process(void *Context,
- NFCSTATUS Status)
-{
- /*Set the context to Map Module*/
- phFriNfc_NdefMap_t *NdefMap = (phFriNfc_NdefMap_t *)Context;
- uint8_t ErrFlag = 0;
- uint16_t NLength = 0,
- SendRecLen=0;
- uint32_t BytesRead = 0;
-
-
- /* Sujatha P: Fix for 0000255/0000257:[gk] MAP:Handling HAL Errors */
- if ( Status == NFCSTATUS_SUCCESS )
- {
- switch (NdefMap->State)
- {
-
-#ifdef PH_HAL4_ENABLE
-#else
-
- case PH_FRINFC_DESF_STATE_GET_HW_VERSION :
-
- /* Check and store the h/w and s/w specific details.
- Ex: Major/Minor version, memory storage info. */
- Status = phFriNfc_Desfire_HGetSWVersion(NdefMap);
-
- /* handle the error in Transc function*/
- if ( (Status & PHNFCSTBLOWER) != (NFCSTATUS_PENDING & PHNFCSTBLOWER))
- {
- /* call respective CR */
- phFriNfc_Desfire_HCrHandler(NdefMap,Status);
- }
-
- break;
-
- case PH_FRINFC_DESF_STATE_GET_SW_VERSION :
-
- /* Check and store the h/w and s/w specific details.
- Ex: Major/Minor version, memory storage info. */
-
- Status = phFriNfc_Desfire_HUpdateVersionDetails(NdefMap);
- if ( Status == NFCSTATUS_SUCCESS )
- {
- Status = phFriNfc_Desfire_HGetUIDDetails(NdefMap);
- /* handle the error in Transc function*/
- if ( (Status & PHNFCSTBLOWER) != (NFCSTATUS_PENDING & PHNFCSTBLOWER))
- {
- /* call respective CR */
- phFriNfc_Desfire_HCrHandler(NdefMap,Status);
- }
- }
-
- break;
-
- case PH_FRINFC_DESF_STATE_GET_UID :
-
- /*Set the desfire operation flag*/
- NdefMap->DespOpFlag = PH_FRINFC_NDEFMAP_DESF_NDEF_CHK_OP;
-
- /*Call Select Smart tag Functinality*/
- Status = phFriNfc_Desfire_SelectSmartTag(NdefMap);
-
- break;
-#endif /* #ifdef PH_HAL4_ENABLE */
-
-#ifdef DESFIRE_EV1
- case PH_FRINFC_NDEFMAP_DESF_STATE_SELECT_SMART_TAG_EV1:
- {
- if(( NdefMap->SendRecvBuf[(*(NdefMap->SendRecvLength) - 2)] ==
- PH_FRINFC_NDEFMAP_DESF_RAPDU_SW1_BYTE) &&
- (NdefMap->SendRecvBuf[(*(NdefMap->SendRecvLength) - 1)] ==
- PH_FRINFC_NDEFMAP_DESF_RAPDU_SW2_BYTE))
- {
- NdefMap->CardType = PH_FRINFC_NDEFMAP_ISO14443_4A_CARD_EV1;
-
- Status = phFriNfc_Desfire_SelectFile(NdefMap);
-
- /* handle the error in Transc function*/
- if ((Status & PHNFCSTBLOWER) != (NFCSTATUS_PENDING & PHNFCSTBLOWER))
- {
- /* call respective CR */
- phFriNfc_Desfire_HCrHandler(NdefMap,Status);
- }
- }
- else
- {
- NdefMap->CardType = PH_FRINFC_NDEFMAP_ISO14443_4A_CARD;
- /* The card is not the new desfire, so send select smart tag command
- of the old desfire */
- Status = phFriNfc_Desfire_SelectSmartTag(NdefMap);
-
-
- }
- break;
- }
-#endif /* #ifdef DESFIRE_EV1 */
-
- case PH_FRINFC_NDEFMAP_DESF_STATE_SELECT_SMART_TAG:
-#ifdef DESFIRE_EV1
- if(( NdefMap->SendRecvBuf[(*(NdefMap->SendRecvLength) - 2)] ==
- PH_FRINFC_NDEFMAP_DESF_RAPDU_SW1_BYTE) &&
- (NdefMap->SendRecvBuf[(*(NdefMap->SendRecvLength) - 1)] ==
- PH_FRINFC_NDEFMAP_DESF_RAPDU_SW2_BYTE))
-#else
- if(( NdefMap->SendRecvBuf[PH_FRINFC_NDEFMAP_DESF_SW1_INDEX] ==
- PH_FRINFC_NDEFMAP_DESF_RAPDU_SW1_BYTE) &&
- (NdefMap->SendRecvBuf[PH_FRINFC_NDEFMAP_DESF_SW2_INDEX] ==
- PH_FRINFC_NDEFMAP_DESF_RAPDU_SW2_BYTE))
-#endif /* #ifdef DESFIRE_EV1 */
- {
- Status = phFriNfc_Desfire_SelectFile(NdefMap);
-
- /* handle the error in Transc function*/
- if ( (Status & PHNFCSTBLOWER) != (NFCSTATUS_PENDING & PHNFCSTBLOWER))
- {
- /* call respective CR */
- phFriNfc_Desfire_HCrHandler(NdefMap,Status);
- }
- }
- else
- {
- /*Error " Smart Tag Functionality Not Supported"*/
- Status = PHNFCSTVAL(CID_FRI_NFC_NDEF_MAP,\
- NFCSTATUS_SMART_TAG_FUNC_NOT_SUPPORTED);
-#ifdef DESFIRE_EV1
- NdefMap->CardType = 0;
-#endif /* #ifdef DESFIRE_EV1 */
-
- /* call respective CR */
- phFriNfc_Desfire_HCrHandler(NdefMap,Status);
-
- }
-
- break;
-
- case PH_FRINFC_NDEFMAP_DESF_STATE_SELECT_FILE :
-
- if(( NdefMap->SendRecvBuf[PH_FRINFC_NDEFMAP_DESF_SW1_INDEX] == PH_FRINFC_NDEFMAP_DESF_RAPDU_SW1_BYTE) &&
- (NdefMap->SendRecvBuf[PH_FRINFC_NDEFMAP_DESF_SW2_INDEX] == PH_FRINFC_NDEFMAP_DESF_RAPDU_SW2_BYTE))
- {
- /*check for the which operation */
- if( (NdefMap->DespOpFlag == PH_FRINFC_NDEFMAP_DESF_READ_OP) ||
- (NdefMap->DespOpFlag == PH_FRINFC_NDEFMAP_DESF_NDEF_CHK_OP) ||
- (NdefMap->DespOpFlag == PH_FRINFC_NDEFMAP_DESF_GET_LEN_OP ))
- {
- /* call for read binary operation*/
- Status = phFriNfc_Desfire_ReadBinary(NdefMap);
-
- /* handle the error in Transc function*/
- if ( (Status & PHNFCSTBLOWER) != (NFCSTATUS_PENDING & PHNFCSTBLOWER) )
- {
- /* call respective CR */
- phFriNfc_Desfire_HCrHandler(NdefMap,Status);
- }
- }
- /*its a write Operation*/
- else if(NdefMap->DespOpFlag == PH_FRINFC_NDEFMAP_DESF_WRITE_OP )
- {
- Status = phFriNfc_Desfire_UpdateBinary (NdefMap);
- /* handle the error in Transc function*/
- if ( (Status & PHNFCSTBLOWER) != (NFCSTATUS_PENDING & PHNFCSTBLOWER))
- {
- /* call respective CR */
- phFriNfc_Desfire_HCrHandler(NdefMap,Status);
- }
- }
- else
- {
- /* unknown/invalid desfire operations*/
- Status = PHNFCSTVAL(CID_FRI_NFC_NDEF_MAP,\
- NFCSTATUS_INVALID_REMOTE_DEVICE);
-
- /* call respective CR */
- phFriNfc_Desfire_HCrHandler(NdefMap,Status);
- }
- }
- else
- {
- /*return Error " Select File Operation Failed"*/
- Status = PHNFCSTVAL(CID_FRI_NFC_NDEF_MAP,\
- NFCSTATUS_INVALID_REMOTE_DEVICE);
-
- /* call respective CR */
- phFriNfc_Desfire_HCrHandler(NdefMap,Status);
- }
- break;
-
- case PH_FRINFC_NDEFMAP_DESF_STATE_READ_CAP_CONT:
- if( (NdefMap->SendRecvBuf[(*(NdefMap->SendRecvLength)-2)] == PH_FRINFC_NDEFMAP_DESF_RAPDU_SW1_BYTE) &&
- (NdefMap->SendRecvBuf[(*(NdefMap->SendRecvLength)-1)] == PH_FRINFC_NDEFMAP_DESF_RAPDU_SW2_BYTE))
- {
- /* Read successful. */
- /*Update the smart tag capability container*/
- Status = phFriNfc_Desfire_Update_SmartTagCapContainer(NdefMap);
-
- if ( Status == NFCSTATUS_SUCCESS)
- {
- NdefMap->DespOpFlag = PH_FRINFC_NDEFMAP_DESF_GET_LEN_OP;
-#ifdef DESFIRE_EV1
- if (PH_FRINFC_NDEFMAP_ISO14443_4A_CARD_EV1 == NdefMap->CardType)
- {
- Status = phFriNfc_Desfire_SelectFile(NdefMap);
- }
- else
-#endif /* #ifdef DESFIRE_EV1 */
- {
- Status = phFriNfc_Desfire_HSetGet_NLEN(NdefMap);
- }
- /* handle the error in Transc function*/
- if ( (Status & PHNFCSTBLOWER) != (NFCSTATUS_PENDING & PHNFCSTBLOWER))
- {
- /* call respective CR */
- phFriNfc_Desfire_HCrHandler(NdefMap,Status);
- }
- }
- else
- {
- /* call respective CR */
- phFriNfc_Desfire_HCrHandler(NdefMap,Status);
-
- }
-
- }
- else
- {
- /*return Error " Capability Container Not Found"*/
- Status = PHNFCSTVAL(CID_FRI_NFC_NDEF_MAP,
- NFCSTATUS_INVALID_REMOTE_DEVICE);
- /* call respective CR */
- phFriNfc_Desfire_HCrHandler(NdefMap,Status);
- }
- break;
-
- case PH_FRINFC_NDEFMAP_DESF_STATE_READ_BIN:
-
- /* Check how many bytes have been read/returned from the card*/
- BytesRead = phFriNfc_Desfire_HGetLeBytes(NdefMap);
-
- /* set the send recev len*/
- SendRecLen = *NdefMap->SendRecvLength - (PH_FRINFC_NDEFMAP_DESF_RESP_OFFSET );
- if ( (NdefMap->DesfireCapContainer.SkipNlenBytesFlag == 1) && ((BytesRead == 1) || (BytesRead == 2 )))
- {
- BytesRead += PH_FRINFC_NDEFMAP_DESF_NLEN_SIZE_IN_BYTES; /* to take care of first 2 len bytes*/
-
- }
- else
- {
- /* Nothing to process*/
- ;
- }
- /* Read More Number Of Bytes than Expected*/
- if ( ( BytesRead == SendRecLen ) &&
- ((NdefMap->SendRecvBuf[(*NdefMap->SendRecvLength-2)] == PH_FRINFC_NDEFMAP_DESF_RAPDU_SW1_BYTE) &&
- (NdefMap->SendRecvBuf[(*NdefMap->SendRecvLength-1)] == PH_FRINFC_NDEFMAP_DESF_RAPDU_SW2_BYTE)))
-
- {
- /* this is to check the card state in first Read Operation*/
- if ( NdefMap->DespOpFlag == PH_FRINFC_NDEFMAP_DESF_GET_LEN_OP )
- {
- /* check the actual length of the ndef data : NLEN*/
- NLength = ( (((uint16_t)NdefMap->SendRecvBuf[0])<SendRecvBuf[1]);
- if (( NLength > PH_NFCFRI_NDEFMAP_DESF_NDEF_FILE_SIZE )||
- ( NLength == 0xFFFF))
- {
- ErrFlag = 1;
- Status = PHNFCSTVAL(CID_FRI_NFC_NDEF_MAP,
- NFCSTATUS_NO_NDEF_SUPPORT);
- }
- else
- {
- /* Store the NLEN into the context */
- NdefMap->DesfireCapContainer.NdefDataLen = NLength;
-
- Status = phFriNfc_MapTool_SetCardState( NdefMap,
- NLength);
- if ( Status == NFCSTATUS_SUCCESS )
- {
- /*Set the card type to Desfire*/
-#ifndef DESFIRE_EV1
- NdefMap->CardType = PH_FRINFC_NDEFMAP_ISO14443_4A_CARD;
-#endif /* #ifdef DESFIRE_EV1 */
- /*Set the state to specify True for Ndef Compliant*/
- NdefMap->State = PH_FRINFC_NDEFMAP_DESF_STATE_CHK_NDEF;
-
- /*set the data count back to zero*/;
- *NdefMap->DataCount = 0;
- /*set the apdu buffer index to zero*/
- NdefMap->ApduBuffIndex = 0;
- /* Set the Operationg flag to Complete check NDEF Operation*/
- NdefMap->DespOpFlag = PH_FRINFC_NDEFMAP_DESF_NDEF_CHK_OP;
-
- }
- /* call respective CR */
- phFriNfc_Desfire_HCrHandler(NdefMap,Status);
- }/* End ofNdefMap->DespOpFlag == PH_FRINFC_NDEFMAP_DESF_GET_LEN_OP*/
- }
- else if ( NdefMap->DespOpFlag == PH_FRINFC_NDEFMAP_DESF_READ_OP )
- {
- phFriNfc_Desfire_HProcReadData(NdefMap);
- }
- else
- {
- /* Invalid Desfire Operation */
- Status = PHNFCSTVAL(CID_FRI_NFC_NDEF_MAP,
- NFCSTATUS_INVALID_REMOTE_DEVICE);
- phFriNfc_Desfire_HCrHandler(NdefMap,Status);
- }
-
- }
- else
- {
- /*handle the Error case*/
- Status = PHNFCSTVAL(CID_FRI_NFC_NDEF_MAP,\
- NFCSTATUS_READ_FAILED);
- ErrFlag =1;
- }
- if( ErrFlag == 1)
- {
- *NdefMap->DataCount = 0;
-
- /*set the buffer index back to zero*/
- NdefMap->ApduBuffIndex = 0;
-
- /* call respective CR */
- phFriNfc_Desfire_HCrHandler(NdefMap,Status);
- }
-
- break;
-
- case PH_FRINFC_NDEFMAP_DESF_STATE_UPDATE_BIN_BEGIN:
- if( (NdefMap->SendRecvBuf[PH_FRINFC_NDEFMAP_DESF_SW1_INDEX] == PH_FRINFC_NDEFMAP_DESF_RAPDU_SW1_BYTE) &&
- (NdefMap->SendRecvBuf[PH_FRINFC_NDEFMAP_DESF_SW2_INDEX] == PH_FRINFC_NDEFMAP_DESF_RAPDU_SW2_BYTE))
- {
- /* Write operation was successful. */
- /* NdefMap->NumOfBytesWritten have been written on to the card.
- Update the DataCount and the ApduBufferIndex */
- *NdefMap->DataCount = (uint16_t)(*NdefMap->DataCount +
- NdefMap->NumOfBytesWritten);
- NdefMap->ApduBuffIndex = (uint16_t)(NdefMap->ApduBuffIndex +
- NdefMap->NumOfBytesWritten);
-
- /* Update the user-provided buffer size to write */
- *NdefMap->WrNdefPacketLength += NdefMap->NumOfBytesWritten;
-
- /* Call Upadte Binary function to check if some more bytes are to be written. */
- Status = phFriNfc_Desfire_UpdateBinary( NdefMap );
- }
- else
- {
- /*handle the Error case*/
- Status = PHNFCSTVAL(CID_FRI_NFC_NDEF_MAP,\
- NFCSTATUS_WRITE_FAILED);
-
- /*set the buffer index back to zero*/
- NdefMap->ApduBuffIndex = 0;
-
- /* call respective CR */
- phFriNfc_Desfire_HCrHandler(NdefMap,Status);
- }
- break;
- case PH_FRINFC_NDEFMAP_DESF_STATE_UPDATE_BIN_END :
- if((NdefMap->SendRecvBuf[PH_FRINFC_NDEFMAP_DESF_SW1_INDEX] == PH_FRINFC_NDEFMAP_DESF_RAPDU_SW1_BYTE) &&
- (NdefMap->SendRecvBuf[PH_FRINFC_NDEFMAP_DESF_SW2_INDEX] == PH_FRINFC_NDEFMAP_DESF_RAPDU_SW2_BYTE))
- {
- /* Updating NLEN operation was successful. */
- /* Entire Write Operation is complete*/
- /* Reset the relevant parameters. */
- Status = PHNFCSTVAL(CID_NFC_NONE,\
- NFCSTATUS_SUCCESS);
-
- /* set the state & Data len into context*/
- NdefMap->CardState = (uint8_t)((NdefMap->CardState ==
- PH_NDEFMAP_CARD_STATE_INITIALIZED)?
- PH_NDEFMAP_CARD_STATE_READ_WRITE :
- NdefMap->CardState);
-
- NdefMap->DesfireCapContainer.NdefDataLen = (uint16_t)(*NdefMap->WrNdefPacketLength);
-#ifdef PH_HAL4_ENABLE
- /* Do nothing */
-#else
- NdefMap->PrevOperation = 0;
-#endif /* #ifndef PH_HAL4_ENABLE */
-
- }
- else
- {
- NdefMap->PrevOperation = 0;
- /*handle the Error case*/
- Status = PHNFCSTVAL(CID_FRI_NFC_NDEF_MAP,\
- NFCSTATUS_WRITE_FAILED);
- }
-
- /*set the buffer index back to zero*/
- NdefMap->ApduBuffIndex = 0;
-
- /* call respective CR */
- phFriNfc_Desfire_HCrHandler(NdefMap,Status);
- break;
-
- default:
- /*define the invalid state*/
- Status = PHNFCSTVAL(CID_FRI_NFC_NDEF_MAP,\
- NFCSTATUS_INVALID_DEVICE_REQUEST);
- phFriNfc_Desfire_HCrHandler(NdefMap,Status);
- break;
- }
- }
- else
- {
- /* call respective CR */
- phFriNfc_Desfire_HCrHandler(NdefMap,Status);
- }
-}
-
-
-
-/*!
-* \brief this shall select the smart tag functinality of the Desfire card.
-*
-* Only when this command returns command completed it is a Smart Tag
-* compatible product.
-*
-*/
-static
-NFCSTATUS phFriNfc_Desfire_SelectSmartTag(phFriNfc_NdefMap_t *NdefMap)
-{
-
- NFCSTATUS status = NFCSTATUS_PENDING;
-#ifdef DESFIRE_EV1
- uint8_t card_type = PH_FRINFC_NDEFMAP_ISO14443_4A_CARD_EV1;
-#endif /* #ifdef DESFIRE_EV1 */
-
- /*form the packet for Select smart tag command*/
- NdefMap->SendRecvBuf[0] = 0x00; /* cls */
- NdefMap->SendRecvBuf[1] = 0xa4; /* ins */
- NdefMap->SendRecvBuf[2] = 0x04; /* p1 */
- NdefMap->SendRecvBuf[3] = 0x00; /* p2 */
- NdefMap->SendRecvBuf[4] = 0x07; /* lc */
-
- /* next 7 bytes specify the DF Name*/
- NdefMap->SendRecvBuf[5] = 0xd2;
- NdefMap->SendRecvBuf[6] = 0x76;
- NdefMap->SendRecvBuf[7] = 0x00;
- NdefMap->SendRecvBuf[8] = 0x00;
- NdefMap->SendRecvBuf[9] = 0x85;
- NdefMap->SendRecvBuf[10] = 0x01;
-
-#ifdef DESFIRE_EV1
-
- switch (NdefMap->DespOpFlag)
- {
- case PH_FRINFC_NDEFMAP_DESF_NDEF_CHK_OP:
- {
- /* First select the smart tag using the new desfire EV1 and increment the
- "sel_index" and if it fails then try the old desfire select smart tag
- command */
- if (0 == NdefMap->CardType)
- {
- /* p2
- NdefMap->SendRecvBuf[3] = DESFIRE_EV1_P2_OFFSET_VALUE; */
- NdefMap->SendRecvBuf[11] = 0x01;
- /* Le */
- NdefMap->SendRecvBuf[12] = 0x00;
- NdefMap->State = PH_FRINFC_NDEFMAP_DESF_STATE_SELECT_SMART_TAG_EV1;
- card_type = PH_FRINFC_NDEFMAP_ISO14443_4A_CARD_EV1;
- }
- else
- {
- NdefMap->SendRecvBuf[3] = 0x00; /* p2 */
- NdefMap->SendRecvBuf[11] = 0x00;
- NdefMap->State = PH_FRINFC_NDEFMAP_DESF_STATE_SELECT_SMART_TAG;
- card_type = PH_FRINFC_NDEFMAP_ISO14443_4A_CARD;
- }
- break;
- }
-
- case PH_FRINFC_NDEFMAP_DESF_READ_OP:
- default :
- {
- if (PH_FRINFC_NDEFMAP_ISO14443_4A_CARD_EV1 == NdefMap->CardType)
- {
- NdefMap->SendRecvBuf[11] = 0x01;
- NdefMap->SendRecvBuf[12] = 0x00;
- NdefMap->State = (uint8_t)PH_FRINFC_NDEFMAP_DESF_STATE_SELECT_SMART_TAG_EV1;
- card_type = PH_FRINFC_NDEFMAP_ISO14443_4A_CARD_EV1;
- }
- else
- {
- NdefMap->SendRecvBuf[11] = 0x00;
- NdefMap->State = (uint8_t)PH_FRINFC_NDEFMAP_DESF_STATE_SELECT_SMART_TAG;
- card_type = PH_FRINFC_NDEFMAP_ISO14443_4A_CARD;
- }
- break;
- }
- }
-
-#else /* #ifdef DESFIRE_EV1 */
-
- NdefMap->SendRecvBuf[11] = 0x00;
-
-#endif /* #ifdef DESFIRE_EV1 */
-
- /*Set the Send length*/
- NdefMap->SendLength = PH_FRINFC_NDEFMAP_DESF_CAPDU_SMARTTAG_PKT_SIZE;
-#ifdef DESFIRE_EV1
-
- if (PH_FRINFC_NDEFMAP_ISO14443_4A_CARD_EV1 == card_type)
- {
- /* Send length is updated for the NEW DESFIRE EV1 */
- NdefMap->SendLength = (uint16_t)(NdefMap->SendLength + 1);
- }
-
-#else
- /* Change the state to Select Smart Tag */
- NdefMap->State = PH_FRINFC_NDEFMAP_DESF_STATE_SELECT_SMART_TAG;
-#endif /* #ifdef DESFIRE_EV1 */
-
- status = phFriNfc_Desfire_HSendTransCmd(NdefMap,PH_FRINFC_NDEFMAP_DESF_RESP_OFFSET);
-
- return status;
-}
-
-/*!
-* \brief this shall select/access the capability container of the Desfire
-* card.
-*
-* This shall be used to identify, if NDEF data structure do exist on
-* the smart tag, we receive command completed status.
-*
-*/
-static
-NFCSTATUS phFriNfc_Desfire_SelectFile (phFriNfc_NdefMap_t *NdefMap)
-{
-
- NFCSTATUS status = NFCSTATUS_PENDING;
-
- /* check for the invalid/unknown desfire operations*/
- if ((NdefMap->DespOpFlag != PH_FRINFC_NDEFMAP_DESF_NDEF_CHK_OP)&& \
- (NdefMap->DespOpFlag != PH_FRINFC_NDEFMAP_DESF_READ_OP)&&\
- ( NdefMap->DespOpFlag != PH_FRINFC_NDEFMAP_DESF_WRITE_OP) &&
- ( NdefMap->DespOpFlag != PH_FRINFC_NDEFMAP_DESF_GET_LEN_OP))
- {
- status = PHNFCSTVAL(CID_FRI_NFC_NDEF_MAP, NFCSTATUS_INVALID_REMOTE_DEVICE);
- }
- else
- {
-
- /* Set the command*/
- //NdefMap->Cmd.Iso144434Cmd = phHal_eIso14443_4_CmdListTClCmd;
-
- /* Form the packet for select file command either for the
- Check Ndef/Read/Write functionalities*/
- NdefMap->SendRecvBuf[0] = 0x00; /* cls */
- NdefMap->SendRecvBuf[1] = 0xa4; /* ins */
- NdefMap->SendRecvBuf[2] = 0x00; /* p1 */
- NdefMap->SendRecvBuf[3] = 0x00; /* p2 */
- NdefMap->SendRecvBuf[4] = 0x02; /* lc */
-
-#ifdef DESFIRE_EV1
- if (PH_FRINFC_NDEFMAP_ISO14443_4A_CARD_EV1 == NdefMap->CardType)
- {
- NdefMap->SendRecvBuf[3] = DESFIRE_EV1_P2_OFFSET_VALUE; /* p2 */
- }
-#endif /* #ifdef DESFIRE_EV1 */
-
- if (NdefMap->DespOpFlag == PH_FRINFC_NDEFMAP_DESF_NDEF_CHK_OP)
-
- {
- /* cap container file identifier*/
- NdefMap->SendRecvBuf[5] = 0xe1;
- NdefMap->SendRecvBuf[6] = 0x03;
- }
- /* Mantis entry 0394 fixed */
- else
- {
- NdefMap->SendRecvBuf[5] = (uint8_t)((NdefMap->DesfireCapContainer.NdefMsgFid) >> PH_FRINFC_NDEFMAP_DESF_SHL8);
- NdefMap->SendRecvBuf[6] = (uint8_t)((NdefMap->DesfireCapContainer.NdefMsgFid) & (0x00ff));
- }
- /*Set the Send length*/
- NdefMap->SendLength = PH_FRINFC_NDEFMAP_DESF_CAPDU_SELECT_FILE_PKT_SIZE;
-
- /* Change the state to Select File */
- NdefMap->State = PH_FRINFC_NDEFMAP_DESF_STATE_SELECT_FILE;
-
- status = phFriNfc_Desfire_HSendTransCmd(NdefMap,PH_FRINFC_NDEFMAP_DESF_RESP_OFFSET);
-
- }
-
- return status;
-
-}
-
-/*!
-* \brief this shall read the data from Desfire card.
-*
-* This is used in two cases namely Reading the Capability container
-* data( le == 0 ) and reading the file data.Maximum bytes to be read during
-* a single read binary is known after the reading the data from the capability
-* conatainer.
-*
-*/
-static
-NFCSTATUS phFriNfc_Desfire_ReadBinary(phFriNfc_NdefMap_t *NdefMap)
-{
- NFCSTATUS status = NFCSTATUS_PENDING;
- uint32_t BytesToRead = 0;
- uint8_t BufIndex=0,OperFlag=0;
- uint16_t DataCnt=0;
-
- /* to read the capability container data*/
- if (NdefMap->DespOpFlag == PH_FRINFC_NDEFMAP_DESF_NDEF_CHK_OP )
- {
- /*specifies capability container shall be read*/
- NdefMap->SendRecvBuf[0] = 0x00;
- NdefMap->SendRecvBuf[1] = 0xb0;
- NdefMap->SendRecvBuf[2] = 0x00; /* p1 */
- NdefMap->SendRecvBuf[3] = 0x00; /* p2 */
- NdefMap->SendRecvBuf[4] = 0x0F; /* le */
-
- NdefMap->SendLength = PH_FRINFC_NDEFMAP_DESF_CAPDU_READ_BIN_PKT_SIZE;
-
- /* Change the state to Cap Container Read */
- NdefMap->State = PH_FRINFC_NDEFMAP_DESF_STATE_READ_CAP_CONT;
-
- /* set the send receive buffer length*/
- OperFlag = 1;
- }
- /*desfire file read operation*/
- else
- {
- NdefMap->SendRecvBuf[0] = 0x00;
- NdefMap->SendRecvBuf[1] = 0xb0;
-
- /*TBD the NLEN bytes*/
- if( *NdefMap->DataCount == 0 )
- {
- /* first read */
- /* set the offset p1 and p2*/
- NdefMap->SendRecvBuf[2] = 0;
- NdefMap->SendRecvBuf[3] = 0;
- }
- else
- {
- /* as the p1 of the 8bit is 0, p1 and p2 are used to store the
- ofset value*/
- DataCnt = *NdefMap->DataCount;
- DataCnt += PH_FRINFC_NDEFMAP_DESF_NLEN_SIZE_IN_BYTES;
- NdefMap->SendRecvBuf[2] = (uint8_t)((DataCnt)>> PH_FRINFC_NDEFMAP_DESF_SHL8);
- NdefMap->SendRecvBuf[3] = (uint8_t)((DataCnt)& (0x00ff));
- }
- /* calculate the Le Byte*/
- BytesToRead = phFriNfc_Desfire_HGetLeBytes(NdefMap);
-
- if ( NdefMap->Offset == PH_FRINFC_NDEFMAP_SEEK_BEGIN )
- {
- /* BufIndex represents the 2 NLEN bytes and decides about the presence of
- 2 bytes NLEN data*/
-
- BufIndex = (uint8_t)(( NdefMap->DesfireCapContainer.SkipNlenBytesFlag == 1 ) ?
- PH_FRINFC_NDEFMAP_DESF_NLEN_SIZE_IN_BYTES:0);
-
- if( ((BytesToRead == 1) || (BytesToRead == 2)) && (NdefMap->DesfireCapContainer.SkipNlenBytesFlag == 1))
- {
- BytesToRead += BufIndex;
- }
- }
-
- /* set the Le byte*/
- /* This following code is true for get nlen and current offset set*/
- NdefMap->SendRecvBuf[4]=(uint8_t) BytesToRead ;
-
- /* Change the state to Read */
- NdefMap->State = PH_FRINFC_NDEFMAP_DESF_STATE_READ_BIN;
-
- /*set the send length*/
- NdefMap->SendLength = PH_FRINFC_NDEFMAP_DESF_CAPDU_READ_BIN_PKT_SIZE;
- OperFlag = 2;
- }
-
- if (OperFlag == 1 )
- {
- status = phFriNfc_Desfire_HSendTransCmd(NdefMap,PH_FRINFC_NDEFMAP_MAX_SEND_RECV_BUF_SIZE);
- }
- else
- {
- status = phFriNfc_Desfire_HSendTransCmd(NdefMap,(uint8_t)(BytesToRead +PH_FRINFC_NDEFMAP_DESF_RESP_OFFSET));
- }
- return (status);
-}
-
-/*!
-* \brief this shall write the data to Desfire card.
-* Maximum bytes to be written during a single update binary
-* is known after the reading the data from the capability
-* conatainer.
-*
-* le filed specifes , how many bytes of data to be written to the
-* Card.
-*
-*/
-static
-NFCSTATUS phFriNfc_Desfire_UpdateBinary(phFriNfc_NdefMap_t *NdefMap)
-{
-
- NFCSTATUS status = NFCSTATUS_PENDING;
- uint16_t noOfBytesToWrite = 0, DataCnt=0,
- index=0;
-
- /* Do we have space in the file to write? */
- if ( (*NdefMap->DataCount < PH_NFCFRI_NDEFMAP_DESF_NDEF_FILE_SIZE) &&
- (NdefMap->ApduBuffIndex < NdefMap->ApduBufferSize))
- {
- /* Yes, we have some bytes to write */
- /* Check and set the card memory size , if user sent bytes are more than the
- card memory size*/
- if( (uint16_t)(NdefMap->ApduBufferSize - NdefMap->ApduBuffIndex) >\
- (uint16_t)(PH_NFCFRI_NDEFMAP_DESF_NDEF_FILE_SIZE - *NdefMap->DataCount))
- {
- NdefMap->ApduBufferSize =( (PH_NFCFRI_NDEFMAP_DESF_NDEF_FILE_SIZE) - (*NdefMap->DataCount + NdefMap->ApduBuffIndex));
- }
-
- /* Now, we have space in the card to write the data, */
- /*Form the packet for the update binary command*/
- NdefMap->SendRecvBuf[0] = 0x00;
- NdefMap->SendRecvBuf[1] = 0xD6;
-
- if( *NdefMap->DataCount == 0)
- {
- /* set the p1/p2 offsets */
- NdefMap->SendRecvBuf[2] = 0x00; /* p1 */
- NdefMap->SendRecvBuf[3] = 0x00; /* p2 */
- NdefMap->DesfireCapContainer.SkipNlenBytesFlag = 0;
- }
- else
- {
- /* as the p1 of the 8bit is 0, p1 and p2 are used to store the
- ofset value*/
- /* This sets card offset in a card for a write operation. + 2 is
- added as first 2 offsets represents the size of the NDEF Len present
- in the file*/
-
- DataCnt = *NdefMap->DataCount;
- DataCnt += PH_FRINFC_NDEFMAP_DESF_NLEN_SIZE_IN_BYTES;
- NdefMap->SendRecvBuf[2] = (uint8_t)((DataCnt)>> PH_FRINFC_NDEFMAP_DESF_SHL8);
- NdefMap->SendRecvBuf[3] = (uint8_t)((DataCnt)& (0x00ff));
- /* No need to attach 2 NLEN bytes at the begining.
- as we have already attached in the first write operation.*/
- NdefMap->DesfireCapContainer.SkipNlenBytesFlag = 1;
-
- }
-
- /* Calculate the bytes to write */
- if( (NdefMap->ApduBufferSize - NdefMap->ApduBuffIndex) >= (uint32_t)( NdefMap->DesfireCapContainer.MaxCmdSize ))
-
- {
- noOfBytesToWrite = ( ( NdefMap->DesfireCapContainer.SkipNlenBytesFlag == 1) ?
- NdefMap->DesfireCapContainer.MaxCmdSize :
- (NdefMap->DesfireCapContainer.MaxCmdSize - PH_FRINFC_NDEFMAP_DESF_NLEN_SIZE_IN_BYTES));
- }
- else
- {
- /* Read only till the available buffer space */
- noOfBytesToWrite = (uint16_t)(NdefMap->ApduBufferSize - NdefMap->ApduBuffIndex);
- }
-
- if ( NdefMap->Offset == PH_FRINFC_NDEFMAP_SEEK_BEGIN )
- {
- if ( NdefMap->DesfireCapContainer.SkipNlenBytesFlag == 1 )
- {
- index = 5;
- /* To Specify the NDEF data len written : updated at the of write cycle*/
- NdefMap->SendRecvBuf[4] = (uint8_t)noOfBytesToWrite;
- }
- else
- {
- /* Leave space to update NLEN */
- NdefMap->SendRecvBuf[5] = 0x00;
- NdefMap->SendRecvBuf[6] = 0x00;
- index =7;
- /* To Specify the NDEF data len written : updated at the of write cycle*/
- NdefMap->SendRecvBuf[4] = (uint8_t)noOfBytesToWrite + PH_FRINFC_NDEFMAP_DESF_NLEN_SIZE_IN_BYTES;
- }
-
- /* copy the data to SendRecvBuf from the apdu buffer*/
- (void)memcpy( &NdefMap->SendRecvBuf[index],
- &NdefMap->ApduBuffer[NdefMap->ApduBuffIndex],
- noOfBytesToWrite);
- NdefMap->SendLength = (noOfBytesToWrite + index);
- }
- else
- {
- NdefMap->SendRecvBuf[4] = (uint8_t)noOfBytesToWrite;
-
- /* copy the data to SendRecvBuf from the apdu buffer*/
- (void)memcpy( &NdefMap->SendRecvBuf[5],
- &NdefMap->ApduBuffer[NdefMap->ApduBuffIndex],
- noOfBytesToWrite);
- NdefMap->SendLength = (noOfBytesToWrite + 5);
- }
-
- /* Store the number of bytes being written in the context structure, so that
- the parameters can be updated, after a successful write operation. */
- NdefMap->NumOfBytesWritten = noOfBytesToWrite;
-
- /* Change the state to Write */
- NdefMap->State = PH_FRINFC_NDEFMAP_DESF_STATE_UPDATE_BIN_BEGIN;
-
- status = phFriNfc_Desfire_HSendTransCmd(NdefMap,PH_FRINFC_NDEFMAP_DESF_RESP_OFFSET);
-
- } /* if(NdefMap->ApduBuffIndex < NdefMap->ApduBufferSize) */
- else
- {
- if ( (*NdefMap->DataCount == PH_NFCFRI_NDEFMAP_DESF_NDEF_FILE_SIZE) ||
- (NdefMap->ApduBuffIndex == NdefMap->ApduBufferSize))
- {
- /* The NdefMap->DespOpFlag = PH_FRINFC_NDEFMAP_DESF_SET_LEN_OP is not
- required, because the DespOpFlag shall be WRITE_OP
- */
- /* Update the NLEN Bytes*/
-#ifdef PH_HAL4_ENABLE
- /* Do nothing */
-#else
- NdefMap->DespOpFlag = PH_FRINFC_NDEFMAP_DESF_SET_LEN_OP;
-#endif /* #ifdef PH_HAL4_ENABLE */
- status = phFriNfc_Desfire_HSetGet_NLEN(NdefMap);
- }
- else
- {
- /* The control should not come here.
- wrong internal calculation.
- we have actually written more than the space available
- in the card ! */
-#ifndef PH_HAL4_ENABLE
- status = PHNFCSTVAL(CID_FRI_NFC_NDEF_MAP,
- NFCSTATUS_CMD_ABORTED);
-#else
- status = PHNFCSTVAL(CID_FRI_NFC_NDEF_MAP,
- NFCSTATUS_FAILED);
-#endif
- /* Reset the relevant parameters. */
- NdefMap->ApduBuffIndex = 0;
- NdefMap->PrevOperation = 0;
-
- /* call respective CR */
- phFriNfc_Desfire_HCrHandler(NdefMap,status);
- }
-
- }
- /* if(*NdefMap->DataCount < PH_NFCFRI_NDEFMAP_DESF_NDEF_FILE_SIZE) */
-
- return status;
-}
-
-
-static void phFriNfc_Desfire_HChkNDEFFileAccessRights(phFriNfc_NdefMap_t *NdefMap)
-{
- if ( (NdefMap->DesfireCapContainer.ReadAccess == 0x00) &&
- (NdefMap->DesfireCapContainer.WriteAccess == 0x00 ))
- {
- /* Set the card state to Read/write State*/
- /* This state can be either INITIALISED or READWRITE. but default
- is INITIALISED */
- NdefMap->CardState = PH_NDEFMAP_CARD_STATE_READ_WRITE;
-
- }
- else if((NdefMap->DesfireCapContainer.ReadAccess == 0x00) &&
- (NdefMap->DesfireCapContainer.WriteAccess == 0xFF ))
- {
- /* Set the card state to Read Only State*/
- NdefMap->CardState = PH_NDEFMAP_CARD_STATE_READ_ONLY;
- }
- else
- {
- /* Set the card state to invalid State*/
- NdefMap->CardState = PH_NDEFMAP_CARD_STATE_INVALID;
- }
-}
-
-/*!
-* \brief this shall update the Desfire capability container structure.
-*
-* This function shall store version,maximum Ndef data structure size,
-* Read Access permissions, Write Access permissions , Maximum data size
-* that can be sent using a single Update Binary, maximum data size that
-* can be read from the Desfire using a singlr read binary.
-* These vaues shall be stored and used during the read/update binary
-* operations.
-*
-*/
-static
-NFCSTATUS phFriNfc_Desfire_Update_SmartTagCapContainer(phFriNfc_NdefMap_t *NdefMap)
-{
- uint16_t CapContSize = 0,
- /* this is initalised 2 because CCLEN includes the field size bytes i.e 2bytes*/
- CCLen= 0;
- uint8_t ErrFlag = 0;
-
- NFCSTATUS status= NFCSTATUS_SUCCESS;
-
- /*Check the Size of Cap Container */
- CapContSize = ( (((uint16_t)NdefMap->SendRecvBuf[PH_FRINFC_NDEFMAP_DESF_CCLEN_BYTE_FIRST_INDEX])<<8)+ \
- NdefMap->SendRecvBuf[PH_FRINFC_NDEFMAP_DESF_CCLEN_BYTE_SECOND_INDEX]);
-
- CCLen += 2;
-
- if ( (CapContSize < 0x0f) || (CapContSize == 0xffff))
- {
- ErrFlag =1;
- }
- else
- {
- /*Version : Smart Tag Spec version */
- /* check for the validity of Major and Minor Version numbers*/
- status = phFriNfc_MapTool_ChkSpcVer ( NdefMap,
- PH_FRINFC_NDEFMAP_DESF_VER_INDEX);
- if ( status != NFCSTATUS_SUCCESS )
- {
- ErrFlag =1;
- }
- else
- {
- CCLen += 1;
-
- /*Get Response APDU data size
- to check the integration s/w response size*/
-#ifdef PH_HAL4_ENABLE
- {
- uint16_t max_rsp_size =
- ((((uint16_t)NdefMap->SendRecvBuf[PH_FRINFC_NDEFMAP_DESF_MLE_BYTE_FIRST_INDEX]) << 8)\
- + NdefMap->SendRecvBuf[PH_FRINFC_NDEFMAP_DESF_MLE_BYTE_SECOND_INDEX]);
- NdefMap->DesfireCapContainer.MaxRespSize =
- ((max_rsp_size > PHHAL_MAX_DATASIZE)?
- (PHHAL_MAX_DATASIZE) : max_rsp_size);
- }
-#else
- NdefMap->DesfireCapContainer.MaxRespSize =
- ((((uint16_t)NdefMap->SendRecvBuf[PH_FRINFC_NDEFMAP_DESF_MLE_BYTE_FIRST_INDEX]) << 8)\
- +NdefMap->SendRecvBuf[PH_FRINFC_NDEFMAP_DESF_MLE_BYTE_SECOND_INDEX]);
-#endif /* #ifdef PH_HAL4_ENABLE */
-
- /*Get Command APDU data size*/
-#ifdef PH_HAL4_ENABLE
- {
- uint16_t max_cmd_size =
- ((((uint16_t)NdefMap->SendRecvBuf[PH_FRINFC_NDEFMAP_DESF_MLC_BYTE_FIRST_INDEX])<<8)\
- + NdefMap->SendRecvBuf[PH_FRINFC_NDEFMAP_DESF_MLC_BYTE_SECOND_INDEX]);
-
- NdefMap->DesfireCapContainer.MaxCmdSize =
- ((max_cmd_size > PHHAL_MAX_DATASIZE)?
- (PHHAL_MAX_DATASIZE): max_cmd_size);
- }
-#else
- NdefMap->DesfireCapContainer.MaxCmdSize =
- ((((uint16_t)NdefMap->SendRecvBuf[PH_FRINFC_NDEFMAP_DESF_MLC_BYTE_FIRST_INDEX])<<8)\
- +NdefMap->SendRecvBuf[PH_FRINFC_NDEFMAP_DESF_MLC_BYTE_SECOND_INDEX]);
-#endif /* #ifdef PH_HAL4_ENABLE */
- /* Check for the Validity of Cmd & Resp Size*/
- /* check the Validity of the Cmd Size*/
- if( (NdefMap->DesfireCapContainer.MaxRespSize < 0x0f) ||
- ( NdefMap->DesfireCapContainer.MaxCmdSize == 0x00))
- {
- ErrFlag=1;
-
- }
- else
- {
- CCLen += 4;
-
- /* Check and Parse the TLV structure */
- /* In future this chk can be extended to Propritery TLV */
- //status = phFriNfc_ChkAndParseTLV(NdefMap);
- status = phFriNfc_Desf_HChkAndParseTLV(NdefMap,PH_FRINFC_NDEFMAP_DESF_TLV_INDEX);
- if ( (status == NFCSTATUS_SUCCESS) && (NdefMap->TLVFoundFlag == PH_FRINFC_NDEFMAP_DESF_NDEF_CNTRL_TLV))
- {
- CCLen += 1;
-
- /* check the TLV length*/
- if ( (( NdefMap->SendRecvBuf[PH_FRINFC_NDEFMAP_DESF_TLV_LEN_INDEX]) > 0x00 ) &&
- (( NdefMap->SendRecvBuf[PH_FRINFC_NDEFMAP_DESF_TLV_LEN_INDEX]) <= 0xFE )&&
- (( NdefMap->SendRecvBuf[PH_FRINFC_NDEFMAP_DESF_TLV_LEN_INDEX]) == 0x06 ))
- {
- CCLen +=1;
- /* store the contents in to the container structure*/
- NdefMap->DesfireCapContainer.NdefMsgFid = ( (((uint16_t)NdefMap->SendRecvBuf[PH_FRINFC_NDEFMAP_DESF_NDEF_FILEID_BYTE_FIRST_INDEX])<SendRecvBuf[PH_FRINFC_NDEFMAP_DESF_NDEF_FILEID_BYTE_SECOND_INDEX]);
-
- CCLen +=2;
-
- /* Invalid Msg File Id : User Can't Have read/write Opeartion*/
- if ( (NdefMap->DesfireCapContainer.NdefMsgFid == 0xFFFF) ||
- (NdefMap->DesfireCapContainer.NdefMsgFid == 0xE102) ||
- (NdefMap->DesfireCapContainer.NdefMsgFid == 0xE103) ||
- (NdefMap->DesfireCapContainer.NdefMsgFid == 0x3F00) ||
- (NdefMap->DesfireCapContainer.NdefMsgFid == 0x3FFF ) )
- {
-
- ErrFlag=1;
- }
- else
- {
- /*Get Ndef Size*/
- NdefMap->DesfireCapContainer.NdefFileSize =
- ((((uint16_t)NdefMap->SendRecvBuf[PH_FRINFC_NDEFMAP_DESF_NDEF_FILESZ_BYTE_FIRST_INDEX])<<8)
- | (NdefMap->SendRecvBuf[PH_FRINFC_NDEFMAP_DESF_NDEF_FILESZ_BYTE_SECOND_INDEX] & 0x00ff));
-
-
- /*Check Ndef Size*/
- /* TBD : Do we need to minus 2 bytes of size it self?*/
- if ( ((NdefMap->DesfireCapContainer.NdefFileSize -2) <= 0x0004 ) ||
- ((NdefMap->DesfireCapContainer.NdefFileSize -2) == 0xFFFD ) )
- {
- ErrFlag=1;
- }
- else
- {
- CCLen +=2;
-
- /*Ndef File Read Access*/
- NdefMap->DesfireCapContainer.ReadAccess = NdefMap->\
- SendRecvBuf[PH_FRINFC_NDEFMAP_DESF_NDEF_FILERD_ACCESS_INDEX] ;
-
- /*Ndef File Write Access*/
- NdefMap->DesfireCapContainer.WriteAccess = NdefMap->SendRecvBuf[PH_FRINFC_NDEFMAP_DESF_NDEF_FILEWR_ACCESS_INDEX];
-
- CCLen +=2;
-
- phFriNfc_Desfire_HChkNDEFFileAccessRights(NdefMap);
- }
- }
- }
- else
- {
-
- /* TLV Lenth is of two byte value
- TBD: As the length of TLV is fixed for 6 bytes. We need not
- handle the 2 byte value*/
-
-
- }
- }
- else
- {
- if ( NdefMap->TLVFoundFlag == PH_FRINFC_NDEFMAP_DESF_PROP_CNTRL_TLV )
- {
- /*TBD: To Handle The Proprietery TLV*/
- }
- else
- {
- /*Invalid T found case*/
- ErrFlag =1;
- }
- }
- /* check for the entire LENGTH Validity
- CCLEN + TLV L value == CCLEN*/
- if ( CapContSize < CCLen )
- {
- ErrFlag=1;
- }
-
- }/* if NdefMap->DesfireCapContainer.MaxRespSize < 0x0f */
- }/* Chkeck Map Version*/
- }/* CC size invalid*/
- if( ErrFlag == 1 )
- {
- status = PHNFCSTVAL(CID_FRI_NFC_NDEF_MAP,
- NFCSTATUS_NO_NDEF_SUPPORT);
- }
- return ( status );
-}
-
-static uint32_t phFriNfc_Desfire_HGetLeBytes(phFriNfc_NdefMap_t *NdefMap)
-{
- /*Represents the LE byte*/
- uint16_t BytesToRead =0;
-
- if ( NdefMap->DespOpFlag == PH_FRINFC_NDEFMAP_DESF_GET_LEN_OP )
- {
- BytesToRead = PH_FRINFC_NDEFMAP_DESF_NLEN_SIZE_IN_BYTES;
- NdefMap->DesfireCapContainer.SkipNlenBytesFlag =0;
- }
- else
- {
-
- /* Calculate Le bytes : No of bytes to read*/
- /* Check for User Apdu Buffer Size and Msg Size of Desfire Capability container */
- if((NdefMap->ApduBufferSize - NdefMap->ApduBuffIndex) >= NdefMap->DesfireCapContainer.MaxRespSize)
- {
- /* We have enough buffer space to read the whole capability container
- size bytes
- Now, check do we have NdefMap->DesfireCapContainer.MaxRespSize to read ? */
-
- BytesToRead = (((NdefMap->DesfireCapContainer.NdefDataLen - *NdefMap->DataCount) >=
- NdefMap->DesfireCapContainer.MaxRespSize) ?
- NdefMap->DesfireCapContainer.MaxRespSize :
- (NdefMap->DesfireCapContainer.NdefDataLen -
- *NdefMap->DataCount));
- }
- else
- {
- /* Read only till the available buffer space */
- BytesToRead = (uint16_t)(NdefMap->ApduBufferSize - NdefMap->ApduBuffIndex);
- if(BytesToRead >= (uint16_t)(NdefMap->DesfireCapContainer.NdefDataLen - *NdefMap->DataCount))
- {
- BytesToRead = (NdefMap->DesfireCapContainer.NdefDataLen - *NdefMap->DataCount);
- }
- }
-
- NdefMap->DesfireCapContainer.SkipNlenBytesFlag =
- (uint8_t)(((NdefMap->Offset == PH_FRINFC_NDEFMAP_SEEK_BEGIN )&&( *NdefMap->DataCount == 0 )) ?
- 1 : 0);
-
- }
- return (BytesToRead);
-}
-
-
-
-/*!
-* \brief this shall notify the integration software with respective
-* success/error status along with the completion routines.
-*
-* This routine is called from the desfire process function.
-*
-*/
-
-static void phFriNfc_Desfire_HCrHandler( phFriNfc_NdefMap_t *NdefMap,
- NFCSTATUS Status)
-{
- /* set the state back to the Reset_Init state*/
- NdefMap->State = PH_FRINFC_NDEFMAP_STATE_RESET_INIT;
-
- switch(NdefMap->DespOpFlag)
- {
- /* check which routine has the problem and set the CR*/
- case PH_FRINFC_NDEFMAP_DESF_NDEF_CHK_OP :
- /* set the completion routine*/
- NdefMap->CompletionRoutine[PH_FRINFC_NDEFMAP_CR_CHK_NDEF].\
- CompletionRoutine(NdefMap->CompletionRoutine->Context,\
- Status);
- break;
-
- case PH_FRINFC_NDEFMAP_DESF_READ_OP :
- /* set the completion routine*/
- NdefMap->CompletionRoutine[PH_FRINFC_NDEFMAP_CR_RD_NDEF].\
- CompletionRoutine(NdefMap->CompletionRoutine->Context,\
- Status);
- break;
-
- case PH_FRINFC_NDEFMAP_DESF_WRITE_OP :
- /* set the completion routine*/
- NdefMap->CompletionRoutine[PH_FRINFC_NDEFMAP_CR_WR_NDEF].\
- CompletionRoutine(NdefMap->CompletionRoutine->Context,\
- Status);
- break;
-
- default :
- /* set the completion routine*/
- NdefMap->CompletionRoutine[PH_FRINFC_NDEFMAP_CR_INVALID_OPE].\
- CompletionRoutine(NdefMap->CompletionRoutine->Context,\
- Status);
- break;
-
- }
-}
-
-static NFCSTATUS phFriNfc_Desfire_HSendTransCmd(phFriNfc_NdefMap_t *NdefMap,uint8_t SendRecvLen)
-{
-
- NFCSTATUS status = NFCSTATUS_SUCCESS;
-
- /* set the command type*/
-#ifndef PH_HAL4_ENABLE
- NdefMap->Cmd.Iso144434Cmd = phHal_eIso14443_4_CmdListTClCmd;
-#else
- NdefMap->Cmd.Iso144434Cmd = phHal_eIso14443_4_Raw;
-#endif
-
- /* set the Additional Info*/
- NdefMap->psDepAdditionalInfo.DepFlags.MetaChaining = 0;
- NdefMap->psDepAdditionalInfo.DepFlags.NADPresent = 0;
-
- /*set the completion routines for the desfire card operations*/
- NdefMap->MapCompletionInfo.CompletionRoutine = phFriNfc_Desfire_Process;
- NdefMap->MapCompletionInfo.Context = NdefMap;
-
- /* set the receive length */
- *NdefMap->SendRecvLength = ((uint16_t)(SendRecvLen));
-
-
- /*Call the Overlapped HAL Transceive function */
- status = phFriNfc_OvrHal_Transceive(NdefMap->LowerDevice,
- &NdefMap->MapCompletionInfo,
- NdefMap->psRemoteDevInfo,
- NdefMap->Cmd,
- &NdefMap->psDepAdditionalInfo,
- NdefMap->SendRecvBuf,
- NdefMap->SendLength,
- NdefMap->SendRecvBuf,
- NdefMap->SendRecvLength);
-
- return (status);
-
-
-}
-
-
-#ifdef UNIT_TEST
-#include
-#endif
-
-#endif /* PH_FRINFC_MAP_DESFIRE_DISABLED */
diff --git a/libnfc-nxp/phFriNfc_DesfireMap.h b/libnfc-nxp/phFriNfc_DesfireMap.h
deleted file mode 100644
index 0432ab5..0000000
--- a/libnfc-nxp/phFriNfc_DesfireMap.h
+++ /dev/null
@@ -1,323 +0,0 @@
-/*
- * Copyright (C) 2010 NXP Semiconductors
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-/*
- * \file phFriNfc_Desfire.h
- * \brief NFC Ndef Mapping For Desfire Smart Card.
- *
- * Project: NFC-FRI
- *
- * $Date: Tue Jul 27 08:58:21 2010 $
- * $Author: ing02260 $
- * $Revision: 1.5 $
- * $Aliases: $
- *
- */
-
-#ifndef PHFRINFC_DESFIREMAP_H
-#define PHFRINFC_DESFIREMAP_H
-
-#include
-#ifdef PH_HAL4_ENABLE
-#include
-#else
-#include
-#endif
-#include
-#include
-#include
-
-
-
-/*!
- * \name Desfire - Standard constants
- *
- */
-/*@{*/
-#define PH_FRINFC_NDEFMAP_DESF_READ_OP 2 /*!< Desfire Operation Flag is Read */
-#define PH_FRINFC_NDEFMAP_DESF_WRITE_OP 3 /*!< Desfire Operation Flag is Write */
-#define PH_FRINFC_NDEFMAP_DESF_NDEF_CHK_OP 4 /*!< Desfire Operation Flag is Check Ndef */
-#define PH_FRINFC_NDEFMAP_DESF_GET_LEN_OP 5
-#define PH_FRINFC_NDEFMAP_DESF_SET_LEN_OP 6
-#define PH_FRINFC_NDEFMAP_DESF_RESP_OFFSET 2 /*!< Two Status Flag at the end of the
- Receive buffer*/
-#define PH_FRINFC_NDEFMAP_DESF_CAPDU_SMARTTAG_PKT_SIZE 12 /*!< Send Length for Smart Tag function*/
-#define PH_FRINFC_NDEFMAP_DESF_CAPDU_SELECT_FILE_PKT_SIZE 7 /*!< Send Length for Select File function */
-#define PH_FRINFC_NDEFMAP_DESF_CAPDU_READ_BIN_PKT_SIZE 5 /*!< Send Length for Reading a Packet */
-
-/*!
- * \name NDEF Mapping - states of the Finite State machine
- *
- */
-/*@{*/
-#ifdef DESFIRE_EV1
- #define PH_FRINFC_NDEFMAP_DESF_STATE_SELECT_SMART_TAG_EV1 4 /*!< Selection of Smart Tag is going on for Desfire EV1 */
-#endif /* #ifdef DESFIRE_EV1 */
-#define PH_FRINFC_NDEFMAP_DESF_STATE_SELECT_SMART_TAG 5 /*!< Selection of Smart Tag is going on */
-#define PH_FRINFC_NDEFMAP_DESF_STATE_SELECT_FILE 6 /*!< Selecting a file to read/write */
-#define PH_FRINFC_NDEFMAP_DESF_STATE_READ_CAP_CONT 7 /*!< Reading a capability container */
-#define PH_FRINFC_NDEFMAP_DESF_STATE_READ_BIN 8 /*!< Reading from the card */
-#define PH_FRINFC_NDEFMAP_DESF_STATE_UPDATE_BIN_BEGIN 60 /*!< Writing to the card */
-#define PH_FRINFC_NDEFMAP_DESF_STATE_UPDATE_BIN_END 61 /*!< Writing to the card */
-
-#define PH_FRINFC_NDEFMAP_DESF_STATE_CHK_NDEF 10 /*!< Check Ndef is in progress */
-#define PH_FRINFC_NDEFMAP_DESF_TLV_INDEX 7 /*!< Specifies the index of TLV Structure */
-#define PH_FRINFC_NDEFMAP_DESF_NDEF_CNTRL_TLV 0x04 /*!< Specifies the NDEF File Cntrl TLV */
-#define PH_FRINFC_NDEFMAP_DESF_PROP_CNTRL_TLV 0x05 /*!< Specifies the Propreitary File Cntrl TLV */
-
-/* Following Constants are used to navigate the Capability Container(CC)*/
-
-/*!< Following two indexes represents the CCLEN in CC*/
-#define PH_FRINFC_NDEFMAP_DESF_CCLEN_BYTE_FIRST_INDEX 0
-#define PH_FRINFC_NDEFMAP_DESF_CCLEN_BYTE_SECOND_INDEX 1
-
-/*!< Specifies the index of the Mapping Version in CC */
-#define PH_FRINFC_NDEFMAP_DESF_VER_INDEX 2
-
-/*!< Following two indexes represents the MLe bytes in CC*/
-#define PH_FRINFC_NDEFMAP_DESF_MLE_BYTE_FIRST_INDEX 3
-#define PH_FRINFC_NDEFMAP_DESF_MLE_BYTE_SECOND_INDEX 4
-
-/*!< Following two indexes represents the MLc bytes in CC*/
-#define PH_FRINFC_NDEFMAP_DESF_MLC_BYTE_FIRST_INDEX 5
-#define PH_FRINFC_NDEFMAP_DESF_MLC_BYTE_SECOND_INDEX 6
-
-/*!< Specifies the index of the TLV in CC */
-#define PH_FRINFC_NDEFMAP_DESF_TLV_INDEX 7
-
-/*!< Specifies the index of the TLV length in CC */
-#define PH_FRINFC_NDEFMAP_DESF_TLV_LEN_INDEX 8
-
-/*!< Following two indexes represents the NDEF file identifier in CC*/
-#define PH_FRINFC_NDEFMAP_DESF_NDEF_FILEID_BYTE_FIRST_INDEX 9
-#define PH_FRINFC_NDEFMAP_DESF_NDEF_FILEID_BYTE_SECOND_INDEX 10
-
-/*!< Following two indexes represents the NDEF file size in CC */
-#define PH_FRINFC_NDEFMAP_DESF_NDEF_FILESZ_BYTE_FIRST_INDEX 11
-#define PH_FRINFC_NDEFMAP_DESF_NDEF_FILESZ_BYTE_SECOND_INDEX 12
-
-/*!< Specifies the index of the NDEF file READ access byte in CC */
-#define PH_FRINFC_NDEFMAP_DESF_NDEF_FILERD_ACCESS_INDEX 13
-
-/*!< Specifies the index of the NDEF file WRITE access byte in CC */
-#define PH_FRINFC_NDEFMAP_DESF_NDEF_FILEWR_ACCESS_INDEX 14
-
-
-/* Macros to find Maximum NDEF File Size*/
-#define PH_NFCFRI_NDEFMAP_DESF_NDEF_FILE_SIZE (NdefMap->DesfireCapContainer.NdefFileSize - 2)
-/* Specifies the size of the NLEN Bytes*/
-#define PH_FRINFC_NDEFMAP_DESF_NLEN_SIZE_IN_BYTES 2
-
-
-/* Following constants are used with buffer index's*/
-#define PH_FRINFC_NDEFMAP_DESF_SW1_INDEX 0
-#define PH_FRINFC_NDEFMAP_DESF_SW2_INDEX 1
-
-
-/* Following constants are used for SW1 SW2 status codes*/
-#define PH_FRINFC_NDEFMAP_DESF_RAPDU_SW1_BYTE 0x90
-#define PH_FRINFC_NDEFMAP_DESF_RAPDU_SW2_BYTE 0x00
-
-
-/* Following constatnts for shift bytes*/
-#define PH_FRINFC_NDEFMAP_DESF_SHL8 8
-
-
-#define PH_FRINFC_DESF_GET_VER_CMD 0x60
-#define PH_FRINFC_DESF_NATIVE_CLASS_BYTE 0x90
-#define PH_FRINFC_DESF_NATIVE_OFFSET_P1 0x00
-#define PH_FRINFC_DESF_NATIVE_OFFSET_P2 0x00
-#define PH_FRINFC_DESF_NATIVE_GETVER_RESP 0xAF
-/*!
-* \name NDEF Mapping - states of the Finite State machine
-*
-*/
-/*@{*/
-
-typedef enum
-{
- PH_FRINFC_DESF_STATE_GET_UID,
- PH_FRINFC_DESF_STATE_GET_SW_VERSION,
- PH_FRINFC_DESF_STATE_GET_HW_VERSION
-
-}phFriNfc_eMapDesfireState;
-
-typedef enum
-{
- PH_FRINFC_DESF_IDX_0,
- PH_FRINFC_DESF_IDX_1,
- PH_FRINFC_DESF_IDX_2,
- PH_FRINFC_DESF_IDX_3,
- PH_FRINFC_DESF_IDX_4,
- PH_FRINFC_DESF_IDX_5
-
-}phFriNfc_eMapDesfireId;
-
-#define PH_FRINFC_DESF_ISO_NATIVE_WRAPPER() \
- do \
-{\
- NdefMap->SendRecvBuf[PH_FRINFC_DESF_IDX_0] = PH_FRINFC_DESF_NATIVE_CLASS_BYTE;\
- NdefMap->SendRecvBuf[PH_FRINFC_DESF_IDX_2] = PH_FRINFC_DESF_NATIVE_OFFSET_P1;\
- NdefMap->SendRecvBuf[PH_FRINFC_DESF_IDX_3] = PH_FRINFC_DESF_NATIVE_OFFSET_P2;\
- switch(NdefMap->State)\
-{\
- case PH_FRINFC_DESF_STATE_GET_HW_VERSION :\
- case PH_FRINFC_DESF_STATE_GET_SW_VERSION :\
- case PH_FRINFC_DESF_STATE_GET_UID :\
- if ( NdefMap->State == PH_FRINFC_DESF_STATE_GET_HW_VERSION )\
-{\
- NdefMap->SendRecvBuf[PH_FRINFC_DESF_IDX_1] = PH_FRINFC_DESF_GET_VER_CMD;\
-}\
- else\
-{\
- NdefMap->SendRecvBuf[PH_FRINFC_DESF_IDX_1] = 0xAF;\
-}\
- NdefMap->SendRecvBuf[PH_FRINFC_DESF_IDX_4] = 0x00;\
- NdefMap->SendLength = PH_FRINFC_DESF_IDX_5;\
- break;\
- default :\
- break;\
-}\
-} while(0)\
-
-
-
-
-
-/*!
- * \brief \copydoc page_ovr Initiates Reading of NDEF information from the Remote Device.
- *
- * The function initiates the reading of NDEF information from a Remote Device.
- * It performs a reset of the state and starts the action (state machine).
- * A periodic call of the \ref phFriNfc_NdefMap_Process has to be done once the action
- * has been triggered.
- *
- * \param[in] NdefMap Pointer to a valid instance of the \ref phFriNfc_NdefMap_t structure describing
- * the component context.
- *
- * \param[in] PacketData Pointer to a location that receives the NDEF Packet.
- *
- * \param[in,out] PacketDataLength Pointer to a variable receiving the length of the NDEF packet.
- *
- * \param[in] Offset Indicates whether the read operation shall start from the begining of the
- * file/card storage \b or continue from the last offset. The last Offset set is stored
- * within a context variable (must not be modified by the integration).
- * If the caller sets the value to \ref PH_FRINFC_NDEFMAP_SEEK_CUR, the component shall
- * start reading from the last offset set (continue where it has stopped before).
- * If set to \ref PH_FRINFC_NDEFMAP_SEEK_BEGIN, the component shall start reading
- * from the begining of the card (restarted)
- *
- * \retval NFCSTATUS_PENDING The action has been successfully triggered.
- * \retval NFCSTATUS_INVALID_DEVICE_REQUEST If Previous Operation is Write Ndef and Offset
- * is Current then this error is displayed.
- * \retval NFCSTATUS_EOF_NDEF_CONTAINER_REACHED No Space in the File to read.
- * \retval NFCSTATUS_MORE_INFORMATION There are more bytes to read in the card.
- * \retval NFCSTATUS_SUCCESS Last Byte of the card read.
- * \retval NFCSTATUS_INVALID_DEVICE The device has not been opened or has been disconnected
- * meanwhile.
- * \retval NFCSTATUS_CMD_ABORTED The caller/driver has aborted the request.
- * \retval NFCSTATUS_BUFFER_TOO_SMALL The buffer provided by the caller is too small.
- * \retval NFCSTATUS_RF_TIMEOUT No data has been received within the TIMEOUT period.
- *
- */
-
-NFCSTATUS phFriNfc_Desfire_RdNdef( phFriNfc_NdefMap_t *NdefMap,
- uint8_t *PacketData,
- uint32_t *PacketDataLength,
- uint8_t Offset);
-
-/*!
- * \brief \copydoc page_ovr Initiates Writing of NDEF information to the Remote Device.
- *
- * The function initiates the writing of NDEF information to a Remote Device.
- * It performs a reset of the state and starts the action (state machine).
- * A periodic call of the \ref phFriNfc_NdefMap_Process has to be done once the action
- * has been triggered.
- *
- * \param[in] NdefMap Pointer to a valid instance of the \ref phFriNfc_NdefMap_t structure describing
- * the component context.
- *
- * \param[in] PacketData Pointer to a location that holds the prepared NDEF Packet.
- *
- * \param[in,out] PacketDataLength Variable specifying the length of the prepared NDEF packet.
- *
- * \param[in] Offset Indicates whether the write operation shall start from the begining of the
- * file/card storage \b or continue from the last offset. The last Offset set is stored
- * within a context variable (must not be modified by the integration).
- * If the caller sets the value to \ref PH_FRINFC_NDEFMAP_SEEK_CUR, the component shall
- * start writing from the last offset set (continue where it has stopped before).
- * If set to \ref PH_FRINFC_NDEFMAP_SEEK_BEGIN, the component shall start writing
- * from the begining of the card (restarted)
- *
- * \retval NFCSTATUS_PENDING The action has been successfully triggered.
- * \retval NFCSTATUS_INVALID_DEVICE_REQUEST If Previous Operation is Write Ndef and Offset
- * is Current then this error is displayed.
- * \retval NFCSTATUS_EOF_NDEF_CONTAINER_REACHED Last byte is written to the card after this
- * no further writing is possible.
- * \retval NFCSTATUS_SUCCESS Buffer provided by the user is completely written
- * into the card.
- * \retval NFCSTATUS_INVALID_DEVICE The device has not been opened or has been disconnected
- * meanwhile.
- * \retval NFCSTATUS_CMD_ABORTED The caller/driver has aborted the request.
- * \retval NFCSTATUS_BUFFER_TOO_SMALL The buffer provided by the caller is too small.
- * \retval NFCSTATUS_RF_TIMEOUT No data has been received within the TIMEOUT period.
- *
- */
-
-NFCSTATUS phFriNfc_Desfire_WrNdef( phFriNfc_NdefMap_t *NdefMap,
- uint8_t *PacketData,
- uint32_t *PacketDataLength,
- uint8_t Offset);
-
-/*!
- * \brief \copydoc page_ovr Check whether a particulat Remote Device is NDEF compliant.
- *
- * The function checks whether the peer device is NDEF compliant.
- *
- * \param[in] NdefMap Pointer to a valid instance of the \ref phFriNfc_NdefMap_t structure describing
- * the component context.
- *
- * \retval NFCSTATUS_PENDING The action has been successfully triggered.
- * \retval NFCSTATUS_INVALID_PARAMETER At least one parameter of the function is invalid.
- * \retval NFCSTATUS_INVALID_DEVICE The device has not been opened or has been disconnected
- * meanwhile.
- * \retval NFCSTATUS_CMD_ABORTED The caller/driver has aborted the request.
- * \retval NFCSTATUS_BUFFER_TOO_SMALL The buffer provided by the caller is too small.
- * \retval NFCSTATUS_RF_TIMEOUT No data has been received within the TIMEOUT period.
- *
- */
-
-NFCSTATUS phFriNfc_Desfire_ChkNdef( phFriNfc_NdefMap_t *NdefMap);
-
-/*!
- * \brief \copydoc page_cb Completion Routine, Processing function, needed to avoid long blocking.
- *
- * The function call scheme is according to \ref grp_interact. No State reset is performed during operation.
- *
- * \copydoc pphFriNfc_Cr_t
- *
- * \note The lower (Overlapped HAL) layer must register a pointer to this function as a Completion
- * Routine in order to be able to notify the component that an I/O has finished and data are
- * ready to be processed.
- *
- */
-
-void phFriNfc_Desfire_Process( void *Context,
- NFCSTATUS Status);
-
-
-#endif /* PHFRINFC_DESFIREMAP_H */
-
diff --git a/libnfc-nxp/phFriNfc_FelicaMap.c b/libnfc-nxp/phFriNfc_FelicaMap.c
deleted file mode 100644
index c45f335..0000000
--- a/libnfc-nxp/phFriNfc_FelicaMap.c
+++ /dev/null
@@ -1,3065 +0,0 @@
-/*
- * Copyright (C) 2010 NXP Semiconductors
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-/*!
- * \file phFriNfc_FelicaMap.c
- * \brief This component encapsulates read/write/check ndef/process functionalities,
- * for the Felica Smart Card.
- *
- * Project: NFC-FRI
- *
- * $Date: Thu May 6 14:01:35 2010 $
- * $Author: ing07385 $
- * $Revision: 1.10 $
- * $Aliases: NFC_FRI1.1_WK1017_R34_4,NFC_FRI1.1_WK1023_R35_1 $
- *
- */
-
-#ifndef PH_FRINFC_MAP_FELICA_DISABLED
-
-#include
-#include
-#include
-#include
-
-
-/*! \ingroup grp_file_attributes
- * \name NDEF Mapping
- *
- * File: \ref phFriNfc_FelicaMap.c
- *
- */
-/*@{*/
-
-#define PHFRINFCNDEFMAP_FILEREVISION "$Revision: 1.10 $"
-#define PHFRINFCNDEFMAP_FILEALIASES "$Aliases: NFC_FRI1.1_WK1017_R34_4,NFC_FRI1.1_WK1023_R35_1 $"
-
-/*@}*/
-
-/* Helpers for Read and updating the attribute informations*/
-static NFCSTATUS phFriNfc_Felica_HRdAttrInfo(phFriNfc_NdefMap_t *NdefMap);
-static NFCSTATUS phFriNfc_Felica_HUpdateAttrInfo(phFriNfc_NdefMap_t *NdefMap);
-static NFCSTATUS phFriNfc_Felica_HCalCheckSum(const uint8_t *TempBuffer,
- uint8_t StartIndex,
- uint8_t EndIndex,
- uint16_t RecvChkSum);
-
-/* Helpers for Poll Related Operations*/
-static NFCSTATUS phFriNfc_Felica_HPollCard( phFriNfc_NdefMap_t *NdefMap,
- const uint8_t sysCode[],
- uint8_t state);
-
-static NFCSTATUS phFriNfc_Felica_HUpdateManufIdDetails(const phFriNfc_NdefMap_t *NdefMap);
-
-/*Helpers for Reading Operations*/
-static NFCSTATUS phFriNfc_Felica_HReadData(phFriNfc_NdefMap_t *NdefMap,uint8_t offset);
-static uint16_t phFriNfc_Felica_HGetMaximumBlksToRead(const phFriNfc_NdefMap_t *NdefMap,uint8_t NbcOrNmaxb );
-static void phFriNfc_Felica_HAfterRead_CopyDataToBuff(phFriNfc_NdefMap_t *NdefMap);
-static NFCSTATUS phFriNfc_Felica_HSetTransceiveForRead(phFriNfc_NdefMap_t *NdefMap,uint16_t TrxLen,uint8_t Offset);
-static uint16_t phFriNfc_Felica_HSetTrxLen(phFriNfc_NdefMap_t *NdefMap,uint16_t Nbc);
-static NFCSTATUS phFriNfc_Felica_HChkApduBuff_Size( phFriNfc_NdefMap_t *NdefMap);
-
-/* Helpers for Writing Operations*/
-static NFCSTATUS phFriNfc_Felica_HChkAttrBlkForWrOp(phFriNfc_NdefMap_t *NdefMap);
-static NFCSTATUS phFriNfc_Felica_HChkAttrBlkForRdOp(phFriNfc_NdefMap_t *NdefMap,
- uint32_t NdefLen);
-static NFCSTATUS phFriNfc_Felica_HUpdateAttrBlkForWrOp(phFriNfc_NdefMap_t *NdefMap,uint8_t isStarted);
-static NFCSTATUS phFriNfc_Felica_HUpdateData(phFriNfc_NdefMap_t *NdefMap);
-static NFCSTATUS phFriNfc_Felica_HWriteDataBlk(phFriNfc_NdefMap_t *NdefMap);
-
-/* Write Empty NDEF Message*/
-static NFCSTATUS phFriNfc_Felica_HWrEmptyMsg(phFriNfc_NdefMap_t *NdefMap);
-
-/*Helpers for common checks*/
-static NFCSTATUS phFriNfc_Felica_HCheckManufId(const phFriNfc_NdefMap_t *NdefMap);
-static void phFriNfc_Felica_HCrHandler(phFriNfc_NdefMap_t *NdefMap,
- uint8_t CrIndex,
- NFCSTATUS Status);
-
-static void phFriNfc_Felica_HInitInternalBuf(uint8_t *Buffer);
-
-static int phFriNfc_Felica_MemCompare ( void *s1, void *s2, unsigned int n );
-
-/*!
- * \brief returns maximum number of blocks can be read from the Felica Smart Card.
- *
- * The function is useful in reading of NDEF information from a felica tag.
- */
-
-static uint16_t phFriNfc_Felica_HGetMaximumBlksToRead(const phFriNfc_NdefMap_t *NdefMap, uint8_t NbcOrNmaxb )
-{
- uint16_t BlksToRead=0;
- uint32_t DataLen = 0;
- /* This part of the code is useful if we take account of Nbc blks reading*/
- if ( NbcOrNmaxb == PH_NFCFRI_NDEFMAP_FELI_NBC )
- {
- PH_NFCFRI_NDEFMAP_FELI_CAL_LEN_BYTES(NdefMap->FelicaAttrInfo.LenBytes[0],
- NdefMap->FelicaAttrInfo.LenBytes[1],
- NdefMap->FelicaAttrInfo.LenBytes[2],
- DataLen);
- /* Calculate Nbc*/
- BlksToRead = (uint16_t) ( ((DataLen % 16) == 0) ? (DataLen >> 4) : ((DataLen >> 4) +1) );
-
-
- }
- else if ( NbcOrNmaxb == PH_NFCFRI_NDEFMAP_FELI_NMAXB)
- {
- BlksToRead = NdefMap->FelicaAttrInfo.Nmaxb;
- }
- else
- {
- /* WARNING !!! code should not reach this point*/
- ;
- }
- return (BlksToRead);
-}
-
-/*!
- * \brief Initiates Reading of NDEF information from the Felica Card.
- *
- * The function initiates the reading of NDEF information from a Remote Device.
- * It performs a reset of the state and starts the action (state machine).
- * A periodic call of the \ref phFriNfcNdefMap_Process has to be
- * done once the action has been triggered.
- */
-
-NFCSTATUS phFriNfc_Felica_RdNdef( phFriNfc_NdefMap_t *NdefMap,
- uint8_t *PacketData,
- uint32_t *PacketDataLength,
- uint8_t Offset)
-{
-
- NFCSTATUS status = NFCSTATUS_PENDING;
- uint32_t Nbc = 0;
-
- NdefMap->ApduBufferSize = *PacketDataLength;
- /*Store the packet data buffer*/
- NdefMap->ApduBuffer = PacketData;
-
- NdefMap->NumOfBytesRead = PacketDataLength ;
- *NdefMap->NumOfBytesRead = 0;
- NdefMap->ApduBuffIndex = 0;
-
- NdefMap->PrevOperation = PH_FRINFC_NDEFMAP_READ_OPE;
- NdefMap->Felica.Offset = Offset;
-
- if( ( Offset == PH_FRINFC_NDEFMAP_SEEK_BEGIN )||( NdefMap->PrevOperation == PH_FRINFC_NDEFMAP_WRITE_OPE))
- {
- NdefMap->Felica.CurBlockNo = 0;
- NdefMap->Felica.OpFlag = PH_FRINFC_NDEFMAP_FELI_RD_ATTR_RD_OP;
- NdefMap->Felica.IntermediateCpyFlag = FALSE;
- NdefMap->Felica.IntermediateCpyLen = 0;
- NdefMap->Felica.Rd_NoBytesToCopy = 0;
- NdefMap->Felica.EofCardReachedFlag= FALSE ;
- NdefMap->Felica.LastBlkReachedFlag = FALSE;
- NdefMap->Felica.CurrBytesRead = 0;
-
- phFriNfc_Felica_HInitInternalBuf(NdefMap->Felica.Rd_BytesToCopyBuff);
-
- /* send request to read attribute information*/
- status = phFriNfc_Felica_HRdAttrInfo(NdefMap);
- /* handle the error in Transc function*/
- if ( (status & PHNFCSTBLOWER) != (NFCSTATUS_PENDING & PHNFCSTBLOWER))
- {
- /* call respective CR */
- phFriNfc_Felica_HCrHandler(NdefMap,PH_FRINFC_NDEFMAP_CR_CHK_NDEF,status);
- }
- }
- else
- {
- Nbc = phFriNfc_Felica_HGetMaximumBlksToRead(NdefMap,PH_NFCFRI_NDEFMAP_FELI_NBC);
-
- /* Offset = Current, but the read has reached the End of NBC Blocks */
- if(( ( Offset == PH_FRINFC_NDEFMAP_SEEK_CUR) && (NdefMap->Felica.CurBlockNo == Nbc)) &&
- (NdefMap->Felica.EofCardReachedFlag == FELICA_RD_WR_EOF_CARD_REACHED ))
- {
- status = PHNFCSTVAL(CID_FRI_NFC_NDEF_MAP, NFCSTATUS_EOF_NDEF_CONTAINER_REACHED);
- }
- else
- {
-
- NdefMap->Felica.CurrBytesRead = ((NdefMap->Felica.CurBlockNo * 16)- NdefMap->Felica.Rd_NoBytesToCopy);
- status = phFriNfc_Felica_HReadData(NdefMap,NdefMap->Felica.Offset);
-
- }
- }
- return (status);
-}
-
-/*Read Operation Related Helper Routines*/
-
-/*!
- * \brief Used in Read Opearation.Sets the Trx Buffer Len calls Transc Cmd.
- * After a successful read operation, function does checks the user buffer size
- * sets the status flags.
-*/
-
-static NFCSTATUS phFriNfc_Felica_HReadData(phFriNfc_NdefMap_t *NdefMap,uint8_t offset)
-{
- NFCSTATUS status = NFCSTATUS_PENDING;
- uint16_t Nbc=0,TranscLen=0;
-
- Nbc = phFriNfc_Felica_HGetMaximumBlksToRead(NdefMap,PH_NFCFRI_NDEFMAP_FELI_NBC);
- if( ( (NdefMap->ApduBufferSize - NdefMap->ApduBuffIndex) > 0) && (NdefMap->Felica.CurBlockNo < Nbc ))
- {
- /* if data is present in the internal buffer*/
- if (NdefMap->Felica.Rd_NoBytesToCopy > 0 )
- {
- /* copy data to external buffer*/
- phFriNfc_Felica_HAfterRead_CopyDataToBuff(NdefMap);
- /*Check the size of user buffer*/
- status = phFriNfc_Felica_HChkApduBuff_Size(NdefMap);
- if ( (status != NFCSTATUS_SUCCESS) && (NdefMap->Felica.IntermediateRdFlag == TRUE ))
- {
- /* set the transc len and call transc cmd*/
- TranscLen = phFriNfc_Felica_HSetTrxLen(NdefMap,Nbc);
- status= phFriNfc_Felica_HSetTransceiveForRead(NdefMap,TranscLen,offset);
- }
- else
- {
- /* Nothing to be done , if IntermediateRdFlag is set to zero*/
- ;
- }
- }
- else
- {
- /* set the transc len and call transc cmd*/
- TranscLen = phFriNfc_Felica_HSetTrxLen(NdefMap,Nbc);
- status= phFriNfc_Felica_HSetTransceiveForRead(NdefMap,TranscLen,offset);
- }
- }
- else
- {
- /* Chk the Buffer size*/
- status = phFriNfc_Felica_HChkApduBuff_Size(NdefMap);
- if ( (status != NFCSTATUS_SUCCESS) && (NdefMap->Felica.IntermediateRdFlag == TRUE ))
- {
- TranscLen = phFriNfc_Felica_HSetTrxLen(NdefMap,Nbc);
- status= phFriNfc_Felica_HSetTransceiveForRead(NdefMap,TranscLen,offset);
- }
- }
- return (status);
-}
-
-/*!
- * \brief Used in Read Opearation.Sets the Trx Buffer Len.
- */
-
-static uint16_t phFriNfc_Felica_HSetTrxLen(phFriNfc_NdefMap_t *NdefMap,uint16_t Nbc)
-{
- uint16_t TranscLen = 0,BlocksToRead=0;
-
- if( ( (NdefMap->ApduBufferSize - NdefMap->ApduBuffIndex)% 16) == 0)
- {
- BlocksToRead = (uint16_t)( (NdefMap->ApduBufferSize - NdefMap->ApduBuffIndex)/16 );
- }
- else
- {
- BlocksToRead = (uint16_t)(((NdefMap->ApduBufferSize - NdefMap->ApduBuffIndex)/16) +1);
- }
- if ( (BlocksToRead > Nbc) ||( (BlocksToRead) > ( Nbc - NdefMap->Felica.CurBlockNo)) )
- {
- BlocksToRead = Nbc - NdefMap->Felica.CurBlockNo;
- }
-
-
- if ( BlocksToRead >= NdefMap->FelicaAttrInfo.Nbr)
- {
- if( NdefMap->FelicaAttrInfo.Nbr < Nbc )
- {
- TranscLen = NdefMap->FelicaAttrInfo.Nbr*16;
- }
- else
- {
- TranscLen = Nbc*16;
- NdefMap->Felica.LastBlkReachedFlag =1;
- }
- }
- else
- {
- if (BlocksToRead <= Nbc )
- {
- if ( ( BlocksToRead * 16) == ((Nbc *16) - (NdefMap->Felica.CurBlockNo * 16)))
- {
- NdefMap->Felica.LastBlkReachedFlag =1;
-
- }
- TranscLen = BlocksToRead*16;
-
- }
- else
- {
- TranscLen = Nbc*16;
- }
- }
- /* As Cur Blk changes, to remember the exact len what we had set
- in the begining of each read operation*/
- NdefMap->Felica.TrxLen = TranscLen;
- return (TranscLen);
-}
-
-/*!
- * \brief Used in Read Opearation.After a successful read operation,
- * Copies the data to user buffer.
- */
-
-static void phFriNfc_Felica_HAfterRead_CopyDataToBuff(phFriNfc_NdefMap_t *NdefMap)
-{
- uint8_t ResetFlag = FALSE, ExtrBytesToCpy = FALSE;
- uint16_t Nbc=0;
- uint32_t DataLen=0;
-
- Nbc = phFriNfc_Felica_HGetMaximumBlksToRead(NdefMap,PH_NFCFRI_NDEFMAP_FELI_NBC );
-
- PH_NFCFRI_NDEFMAP_FELI_CAL_LEN_BYTES(NdefMap->FelicaAttrInfo.LenBytes[0],
- NdefMap->FelicaAttrInfo.LenBytes[1],
- NdefMap->FelicaAttrInfo.LenBytes[2],
- DataLen);
- /* Internal Buffer has some old read bytes to cpy to user buffer*/
- if( NdefMap->Felica.Rd_NoBytesToCopy > 0 )
- {
- if ( (NdefMap->ApduBufferSize - NdefMap->ApduBuffIndex) < NdefMap->Felica.Rd_NoBytesToCopy )
- {
- NdefMap->Felica.Rd_NoBytesToCopy -= (uint8_t)(NdefMap->ApduBufferSize - NdefMap->ApduBuffIndex);
-
- if (NdefMap->Felica.IntermediateCpyFlag == TRUE )
- {
- /*Copy data from the internal buffer to user buffer*/
- (void)memcpy( (&(NdefMap->ApduBuffer[NdefMap->ApduBuffIndex])),
- (&(NdefMap->Felica.Rd_BytesToCopyBuff[NdefMap->Felica.IntermediateCpyLen])),
- (NdefMap->ApduBufferSize - NdefMap->ApduBuffIndex));
-
-
-
- /* Store number of bytes copied frm internal buffer to User Buffer */
- NdefMap->Felica.IntermediateCpyLen += (uint8_t)(NdefMap->ApduBufferSize - NdefMap->ApduBuffIndex);
- NdefMap->Felica.IntermediateCpyFlag = 1;
-
- /* check do we reach len bytes any chance*/
- PH_NFCFRI_NDEFMAP_FELI_CAL_LEN_BYTES(NdefMap->FelicaAttrInfo.LenBytes[0],
- NdefMap->FelicaAttrInfo.LenBytes[1],
- NdefMap->FelicaAttrInfo.LenBytes[2],
- DataLen);
- /* Internal buffer has zero bytes for copy operation*/
- if ( NdefMap->Felica.Rd_NoBytesToCopy == 0)
- {
- NdefMap->Felica.EofCardReachedFlag =FELICA_RD_WR_EOF_CARD_REACHED;
- }
- }
- else
- {
- /*Copy data from the internal buffer to apdu buffer*/
- (void)memcpy( (&(NdefMap->ApduBuffer[NdefMap->ApduBuffIndex])),
- NdefMap->Felica.Rd_BytesToCopyBuff,
- (NdefMap->ApduBufferSize - NdefMap->ApduBuffIndex));
- }
- NdefMap->ApduBuffIndex += (uint8_t)(NdefMap->ApduBufferSize - NdefMap->ApduBuffIndex);
-
- }
- else if ( (NdefMap->ApduBufferSize - NdefMap->ApduBuffIndex) == NdefMap->Felica.Rd_NoBytesToCopy )
- {
- if ( NdefMap->Felica.IntermediateCpyFlag == TRUE )
- {
- /*Copy data internal buff to apdubuffer*/
- (void)memcpy( (&(NdefMap->ApduBuffer[NdefMap->ApduBuffIndex])),
- (&(NdefMap->Felica.Rd_BytesToCopyBuff[NdefMap->Felica.IntermediateCpyLen])),
- NdefMap->Felica.Rd_NoBytesToCopy);
- }
- else
- {
- /*Copy data internal buff to apdubuffer*/
- (void)memcpy( (&(NdefMap->ApduBuffer[NdefMap->ApduBuffIndex])),
- NdefMap->Felica.Rd_BytesToCopyBuff,
- NdefMap->Felica.Rd_NoBytesToCopy);
- }
-
- /*increment the index,internal buffer len*/
- NdefMap->ApduBuffIndex += NdefMap->Felica.Rd_NoBytesToCopy;
- NdefMap->Felica.Rd_NoBytesToCopy -= (uint8_t)(NdefMap->ApduBuffIndex);
-
- /* To reset the parameters*/
- ResetFlag = TRUE;
- }
- else
- {
- /* Extra Bytes to Copy from internal buffer to external buffer*/
- if ( NdefMap->Felica.IntermediateCpyFlag == TRUE )
- {
- /*Copy data internal buff to apdubuffer*/
- (void)memcpy( (&(NdefMap->ApduBuffer[NdefMap->ApduBuffIndex])),
- (&(NdefMap->Felica.Rd_BytesToCopyBuff[NdefMap->Felica.IntermediateCpyLen])),
- NdefMap->Felica.Rd_NoBytesToCopy);
- }
- else
- {
- /*Copy data internal buff to apdubuffer*/
- (void)memcpy( (&(NdefMap->ApduBuffer[NdefMap->ApduBuffIndex])),
- NdefMap->Felica.Rd_BytesToCopyBuff,
- NdefMap->Felica.Rd_NoBytesToCopy);
- }
- /*increment the index*/
- NdefMap->ApduBuffIndex += NdefMap->Felica.Rd_NoBytesToCopy;
-
- /* To reset the parameters*/
- ResetFlag = TRUE;
- }
- }/*End of Internal Buffer has some old read bytes to cpy to user buffer*/
- else
- {
- /* check if last block is reached*/
- if ( ((NdefMap->Felica.LastBlkReachedFlag == 1) && (( NdefMap->ApduBufferSize - NdefMap->ApduBuffIndex) >= 16)) )
- {
- /* greater than 16 but less than the data len size*/
- if (( NdefMap->ApduBufferSize - NdefMap->ApduBuffIndex) >= DataLen)
- {
- NdefMap->Felica.CurrBytesRead = (uint16_t)((DataLen) - (NdefMap->Felica.CurrBytesRead +
- NdefMap->ApduBuffIndex));
-
- (void)memcpy( (&(NdefMap->ApduBuffer[NdefMap->ApduBuffIndex])),
- (&(NdefMap->SendRecvBuf[13])),
- NdefMap->Felica.CurrBytesRead);
-
- NdefMap->ApduBuffIndex += NdefMap->Felica.CurrBytesRead;
- if ( NdefMap->ApduBuffIndex == DataLen)
- {
- ResetFlag = TRUE;
- }
- }
- else
- {
- /* need to check exact no. of bytes to copy to buffer*/
- if( ( (NdefMap->ApduBufferSize - NdefMap->ApduBuffIndex) <= NdefMap->Felica.TrxLen )||
- ((NdefMap->ApduBufferSize - NdefMap->ApduBuffIndex) <= DataLen ))
- {
-
- ExtrBytesToCpy = TRUE;
- }
- else
- {
- NdefMap->Felica.Rd_NoBytesToCopy = (uint8_t)(16-(( Nbc * 16) - (DataLen)));
-
- if ( NdefMap->Felica.Rd_NoBytesToCopy > (NdefMap->ApduBufferSize - NdefMap->ApduBuffIndex))
- {
- /*Reduce already copied bytes from the internal buffer*/
- NdefMap->Felica.Rd_NoBytesToCopy -= (uint8_t)(NdefMap->ApduBufferSize - NdefMap->ApduBuffIndex);
- ExtrBytesToCpy = TRUE;
- }
- else
- {
- ExtrBytesToCpy = FALSE;
- }
- }
- if ( ExtrBytesToCpy == TRUE )
- {
- NdefMap->Felica.CurrBytesRead = (uint16_t)((DataLen)- (NdefMap->Felica.CurrBytesRead +
- NdefMap->ApduBuffIndex));
-
- if(NdefMap->Felica.CurrBytesRead <
- (uint16_t)(NdefMap->ApduBufferSize -
- NdefMap->ApduBuffIndex))
- {
- (void)memcpy( (&(NdefMap->ApduBuffer[NdefMap->ApduBuffIndex])),
- (&(NdefMap->SendRecvBuf[13])),
- NdefMap->Felica.CurrBytesRead);
- }
- else
- {
- (void)memcpy( (&( NdefMap->ApduBuffer[NdefMap->ApduBuffIndex])),
- (&( NdefMap->SendRecvBuf[13])),
- (uint16_t)(NdefMap->ApduBufferSize - NdefMap->ApduBuffIndex));
- }
-
- if ( NdefMap->Felica.LastBlkReachedFlag == 1 )
- {
- NdefMap->Felica.Rd_NoBytesToCopy =
- (uint8_t)((NdefMap->Felica.CurrBytesRead >
- (uint16_t)(NdefMap->ApduBufferSize - NdefMap->ApduBuffIndex))?
- (NdefMap->Felica.CurrBytesRead -
- (uint16_t)(NdefMap->ApduBufferSize - NdefMap->ApduBuffIndex)):
- 0);
-
- ResetFlag = ((NdefMap->Felica.Rd_NoBytesToCopy == 0)?TRUE:FALSE);
-
- }
- else
- {
- NdefMap->Felica.Rd_NoBytesToCopy = (uint8_t)( NdefMap->Felica.TrxLen - (NdefMap->ApduBufferSize - NdefMap->ApduBuffIndex));
- }
-
- /* Copy remained bytes back into internal buffer*/
- (void)memcpy( NdefMap->Felica.Rd_BytesToCopyBuff,
- (&(NdefMap->SendRecvBuf[PH_NFCFRI_NDEFMAP_FELI_RESP_HEADER_LEN+(NdefMap->ApduBufferSize - NdefMap->ApduBuffIndex)])),
- NdefMap->Felica.Rd_NoBytesToCopy);
-
- /* set the intermediate flag : This flag remembers that there are still X no. bytes remained in
- Internal Buffer Ex: User has given only one byte buffer,needs to cpy one byte at a time*/
- NdefMap->Felica.IntermediateCpyFlag = TRUE;
-
- NdefMap->ApduBuffIndex += ((NdefMap->Felica.CurrBytesRead <
- (uint16_t)(NdefMap->ApduBufferSize -
- NdefMap->ApduBuffIndex))?
- NdefMap->Felica.CurrBytesRead:
- (uint16_t)(NdefMap->ApduBufferSize -
- NdefMap->ApduBuffIndex));
- }
- else
- {
- /*Copy data from the internal buffer to user buffer*/
- (void)memcpy( (&( NdefMap->ApduBuffer[NdefMap->ApduBuffIndex])),
- (&( NdefMap->SendRecvBuf[13])),
- NdefMap->Felica.Rd_NoBytesToCopy);
-
- NdefMap->ApduBuffIndex += NdefMap->Felica.Rd_NoBytesToCopy;
- ResetFlag = TRUE;
-
- }
- }
-
- }
- else
- {
- if ((NdefMap->ApduBufferSize - NdefMap->ApduBuffIndex) < NdefMap->Felica.TrxLen )
- {
- /* Calculate exactly remained bytes to copy to internal buffer and set it*/
- if ( NdefMap->Felica.LastBlkReachedFlag == 1)
- {
- NdefMap->Felica.Rd_NoBytesToCopy = (uint8_t)(16-(( Nbc * 16) - DataLen));
-
- if ( NdefMap->Felica.Rd_NoBytesToCopy > (NdefMap->ApduBufferSize - NdefMap->ApduBuffIndex))
- {
- /*Reduce already copied bytes from the internal buffer*/
- NdefMap->Felica.Rd_NoBytesToCopy -= (uint8_t)(NdefMap->ApduBufferSize - NdefMap->ApduBuffIndex);
- ExtrBytesToCpy = TRUE;
- }
- }
- else
- {
- NdefMap->Felica.Rd_NoBytesToCopy = (uint8_t)(NdefMap->Felica.TrxLen - (NdefMap->ApduBufferSize - NdefMap->ApduBuffIndex));
- ExtrBytesToCpy = TRUE;
- }
- if ( ExtrBytesToCpy == TRUE )
- {
- /*Copy the read data from trx buffer to apdu of size apdu*/
- (void)memcpy( (&(NdefMap->ApduBuffer[NdefMap->ApduBuffIndex])),
- (&(NdefMap->SendRecvBuf[13])),
- NdefMap->ApduBufferSize - NdefMap->ApduBuffIndex);
-
- /*copy bytesToCopy to internal buffer*/
- (void)memcpy( NdefMap->Felica.Rd_BytesToCopyBuff,
- (&(NdefMap->SendRecvBuf[13+(NdefMap->ApduBufferSize - NdefMap->ApduBuffIndex)])),
- NdefMap->Felica.Rd_NoBytesToCopy);
-
- NdefMap->Felica.IntermediateCpyFlag = TRUE;
- NdefMap->ApduBuffIndex += (uint16_t)NdefMap->ApduBufferSize - NdefMap->ApduBuffIndex;
- }
- else
- {
- /*Copy data from the internal buffer to user buffer*/
- (void)memcpy( (&(NdefMap->ApduBuffer[NdefMap->ApduBuffIndex])),
- (&(NdefMap->SendRecvBuf[13])),
- NdefMap->Felica.Rd_NoBytesToCopy);
-
- NdefMap->ApduBuffIndex += NdefMap->Felica.Rd_NoBytesToCopy;
- ResetFlag = TRUE;
-
- }
- if ( DataLen <= (NdefMap->ApduBufferSize - NdefMap->ApduBuffIndex) )
- {
- NdefMap->Felica.EofCardReachedFlag =FELICA_RD_WR_EOF_CARD_REACHED;
- }
- else
- {
- ;
- }
- }
- else if ((NdefMap->ApduBufferSize - NdefMap->ApduBuffIndex) == NdefMap->Felica.TrxLen )
- {
- /*Copy exactly remained last bytes to user buffer and increment the index*/
- /*13 : 1+12 : 1st byte entire pkt length + 12 bytes to skip manuf details*/
- (void)memcpy( (&(NdefMap->ApduBuffer[NdefMap->ApduBuffIndex])),
- (&(NdefMap->SendRecvBuf[13])),
- (NdefMap->Felica.TrxLen ));
-
- NdefMap->ApduBuffIndex += NdefMap->Felica.TrxLen;
- }
- else
- {
- if ((NdefMap->ApduBufferSize - NdefMap->ApduBuffIndex) > NdefMap->Felica.TrxLen )
- {
- /*Copy the data to apdu buffer and increment the index */
- (void)memcpy( (&(NdefMap->ApduBuffer[NdefMap->ApduBuffIndex])),
- (&(NdefMap->SendRecvBuf[PH_NFCFRI_NDEFMAP_FELI_RESP_HEADER_LEN])),
- NdefMap->Felica.TrxLen);
-
- NdefMap->ApduBuffIndex += (uint16_t)NdefMap->Felica.TrxLen;
- }
- }
- }
- }
- if ( ResetFlag == TRUE )
- {
- /* reset the internal buffer variables*/
- NdefMap->Felica.Rd_NoBytesToCopy =0;
- NdefMap->Felica.IntermediateCpyLen =0;
- NdefMap->Felica.IntermediateCpyFlag =FALSE;
- }
- return;
-}
-
-
-/*!
- * \brief Used in Read Opearation.After a successful read operation,
- Checks the relavent buffer sizes and set the status.Following function is used
- when we read the Nmaxb blocks. Retained for future purpose.
- */
-
-static NFCSTATUS phFriNfc_Felica_HChkApduBuff_Size( phFriNfc_NdefMap_t *NdefMap)
-{
- NFCSTATUS status = NFCSTATUS_PENDING;
- uint8_t ResetFlag = FALSE;
- uint32_t Nbc = 0;
- uint32_t DataLen = 0;
-
- Nbc = phFriNfc_Felica_HGetMaximumBlksToRead(NdefMap,PH_NFCFRI_NDEFMAP_FELI_NBC);
-
- /* set status to Success : User Buffer is full and Curblk < nmaxb*/
- if ( (( NdefMap->ApduBufferSize-NdefMap->ApduBuffIndex )== 0) &&
- (NdefMap->Felica.CurBlockNo < Nbc ))
- {
- status = PHNFCSTVAL(CID_NFC_NONE,
- NFCSTATUS_SUCCESS);
- /*Reset the index, internal buffer counters back to zero*/
- *NdefMap->NumOfBytesRead = NdefMap->ApduBuffIndex;
- NdefMap->ApduBuffIndex = 0;
-
- }/*if( (NdefMap->ApduBufferSize-NdefMap->ApduBuffIndex )== 0 && NdefMap->Felica.CurBlockNo < NdefMap->FelicaAttrInfo.Nmaxb )*/
- else
- {
- if (( ( NdefMap->ApduBufferSize-NdefMap->ApduBuffIndex )== 0) &&
- (NdefMap->Felica.CurBlockNo == Nbc ))
- {
- status = PHNFCSTVAL(CID_NFC_NONE,
- NFCSTATUS_SUCCESS);
-
- ResetFlag = ((NdefMap->Felica.Rd_NoBytesToCopy > 0 )?
- FALSE:
- TRUE);
- if( ResetFlag== FALSE)
- {
- *NdefMap->NumOfBytesRead = NdefMap->ApduBuffIndex;
- /*Reset the index, internal buffer counters back to zero*/
- NdefMap->ApduBuffIndex = 0;
- }
- }/*if ((NdefMap->ApduBufferSize-NdefMap->ApduBuffIndex )== 0 && NdefMap->Felica.CurBlockNo == NdefMap->FelicaAttrInfo.Nmaxb )*/
- else
- {
- /* reached reading all the blks available in the card: set EOF flag*/
- if ( NdefMap->ApduBuffIndex == (Nbc*16))
- {
- status = PHNFCSTVAL(CID_NFC_NONE,
- NFCSTATUS_SUCCESS);
- ResetFlag = TRUE;
- }
- else
- {
- if ((NdefMap->ApduBufferSize-NdefMap->ApduBuffIndex )> 0 )
- {
- if ( NdefMap->Felica.CurBlockNo == Nbc )
- {
- /* bytes pending in internal buffer , No Space in User Buffer*/
- if ( NdefMap->Felica.Rd_NoBytesToCopy > 0)
- {
- if ( NdefMap->Felica.EofCardReachedFlag == TRUE )
- {
- status = PHNFCSTVAL(CID_NFC_NONE,
- NFCSTATUS_SUCCESS);
- *NdefMap->NumOfBytesRead = NdefMap->ApduBuffIndex;
- NdefMap->ApduBuffIndex=0;
- }
- else
- {
- phFriNfc_Felica_HAfterRead_CopyDataToBuff(NdefMap);
- if( NdefMap->Felica.Rd_NoBytesToCopy > 0 )
- {
- status = PHNFCSTVAL(CID_NFC_NONE,
- NFCSTATUS_SUCCESS);
- *NdefMap->NumOfBytesRead = NdefMap->ApduBuffIndex;
- NdefMap->ApduBuffIndex=0;
- }
- else
- {
- /* EOF Card Reached set the internal EOF Flag*/
- status = PHNFCSTVAL(CID_NFC_NONE,
- NFCSTATUS_SUCCESS);
-
- ResetFlag = TRUE;
- }
- }
- }
- /* All bytes from internal buffer are copied and set eof flag*/
- else
- {
- status = PHNFCSTVAL(CID_NFC_NONE,
- NFCSTATUS_SUCCESS);
- ResetFlag = TRUE;
- }
- }
- else
- {
- /* This flag is set to ensure that, need of Read Opearation
- we completed coying the data from internal buffer to external buffer
- left some more bytes,in User bufer so initiate the read operation */
- NdefMap->Felica.IntermediateRdFlag = TRUE;
- }
- }
- else
- {
- status = PHNFCSTVAL(CID_NFC_NONE,
- NFCSTATUS_SUCCESS);
- }
- }
- }
- if ( ResetFlag == TRUE)
- {
- PH_NFCFRI_NDEFMAP_FELI_CAL_LEN_BYTES(NdefMap->FelicaAttrInfo.LenBytes[0],
- NdefMap->FelicaAttrInfo.LenBytes[1],
- NdefMap->FelicaAttrInfo.LenBytes[2],
- DataLen);
- if (NdefMap->ApduBuffIndex > DataLen)
- {
- *NdefMap->NumOfBytesRead = DataLen;
- }
- else
- {
- *NdefMap->NumOfBytesRead = NdefMap->ApduBuffIndex;
- }
- /*Reset the index, internal buffer counters back to zero*/
- NdefMap->ApduBuffIndex = 0;
- NdefMap->Felica.Rd_NoBytesToCopy=0;
- NdefMap->Felica.EofCardReachedFlag=FELICA_RD_WR_EOF_CARD_REACHED;
-
- }
-
- }
- return( status);
-}
-
-/*!
- * \brief Used in Read Opearation.Sets the transceive Command for read.
- */
-static NFCSTATUS phFriNfc_Felica_HSetTransceiveForRead(phFriNfc_NdefMap_t *NdefMap,uint16_t TrxLen,uint8_t Offset)
-{
- NFCSTATUS TrxStatus = NFCSTATUS_PENDING;
- uint16_t BufIndex=0,i=0;
-
- /* set the felica cmd */
-#ifdef PH_HAL4_ENABLE
- NdefMap->Cmd.FelCmd = (phNfc_eFelicaCmdList_t)phHal_eFelica_Raw;
-#else
- NdefMap->Cmd.FelCmd = phHal_eFelicaCmdListFelicaCmd;
-#endif /* #ifdef PH_HAL4_ENABLE */
-
- /*Change the state to Read */
- NdefMap->State = PH_NFCFRI_NDEFMAP_FELI_STATE_RD_BLOCK;
-
- /* set the complition routines for the mifare operations */
- NdefMap->MapCompletionInfo.CompletionRoutine = phFriNfc_Felica_Process;
- NdefMap->MapCompletionInfo.Context = NdefMap;
-
- /*set the additional informations for the data exchange*/
- NdefMap->psDepAdditionalInfo.DepFlags.MetaChaining = 0;
- NdefMap->psDepAdditionalInfo.DepFlags.NADPresent = 0;
-
- /* pkt len : updated at the end*/
- NdefMap->SendRecvBuf[BufIndex] = 0x00;
- BufIndex ++;
-
- NdefMap->SendRecvBuf[BufIndex] = 0x06;
- BufIndex++;
-
- /* IDm - Manufacturer Id : 8bytes*/
-#ifdef PH_HAL4_ENABLE
- (void)memcpy((&(NdefMap->SendRecvBuf[BufIndex])),
- (void * )(&(NdefMap->psRemoteDevInfo->RemoteDevInfo.Felica_Info.IDm)),
- 8);
-#else
- (void)memcpy((&(NdefMap->SendRecvBuf[BufIndex])),
- (void * )(&(NdefMap->psRemoteDevInfo->RemoteDevInfo.CardInfo212_424.Startup212_424.NFCID2t)),
- 8);
-#endif /* #ifdef PH_HAL4_ENABLE */
-
- BufIndex+=8;
-
- /*Number of Services (n=1 ==> 0x80)*/
- NdefMap->SendRecvBuf[BufIndex] = 0x01;
- BufIndex++;
-
- /*Service Code List*/
- NdefMap->SendRecvBuf[BufIndex] = 0x0B;
- BufIndex++;
-
- NdefMap->SendRecvBuf[BufIndex] = 0x00;
- BufIndex++;
-
- /*Number of Blocks to read*/
- NdefMap->SendRecvBuf[BufIndex] = (uint8_t)(TrxLen/16);
- BufIndex++;
- /* Set the Blk numbers as per the offset set by the user : Block List*/
- if ( Offset == PH_FRINFC_NDEFMAP_SEEK_BEGIN )
- {
- for ( i=0;i<(TrxLen/16);i++)
- {
- /*1st Service Code list : byte 1*/
- NdefMap->SendRecvBuf[BufIndex] = 0x80;
- BufIndex++;
-
- /* No. Of Blocks*/
- NdefMap->SendRecvBuf[BufIndex] = (uint8_t)(i + 1);
- BufIndex++;
- }
- }
- else
- {
- for ( i= 1;i<=(TrxLen/16);i++)
- {
- /*1st Service Code list : byte 1*/
- NdefMap->SendRecvBuf[BufIndex] = 0x80;
- BufIndex++;
-
- /* No. Of Blocks*/
- NdefMap->SendRecvBuf[BufIndex] = (uint8_t)(NdefMap->Felica.CurBlockNo + i);
- BufIndex++;
- }
- }
-
- /* len of entire pkt*/
- NdefMap->SendRecvBuf[PH_NFCFRI_NDEFMAP_FELI_PKT_LEN_INDEX] = (uint8_t) BufIndex;
-
- /* Set the Pkt Len*/
- NdefMap->SendLength = BufIndex;
-
- *NdefMap->SendRecvLength = NdefMap->TempReceiveLength;
-
- TrxStatus = phFriNfc_OvrHal_Transceive(NdefMap->LowerDevice,
- &NdefMap->MapCompletionInfo,
- NdefMap->psRemoteDevInfo,
- NdefMap->Cmd,
- &NdefMap->psDepAdditionalInfo,
- NdefMap->SendRecvBuf,
- NdefMap->SendLength,
- NdefMap->SendRecvBuf,
- NdefMap->SendRecvLength);
- return (TrxStatus);
-}
-
-/*!
- * \brief Initiates Writing of NDEF information to the Remote Device.
- *
- * The function initiates the writing of NDEF information to a Remote Device.
- * It performs a reset of the state and starts the action (state machine).
- * A periodic call of the \ref phFriNfcNdefMap_Process has to be done once the action
- * has been triggered.
- */
-
-NFCSTATUS phFriNfc_Felica_WrNdef( phFriNfc_NdefMap_t *NdefMap,
- uint8_t *PacketData,
- uint32_t *PacketDataLength,
- uint8_t Offset)
-{
-
- NFCSTATUS status = NFCSTATUS_PENDING;
-
- NdefMap->ApduBufferSize = *PacketDataLength;
- /*Store the packet data buffer*/
- NdefMap->ApduBuffer = PacketData;
-
- /* To Update the Acutal written bytes to context*/
- NdefMap->WrNdefPacketLength = PacketDataLength;
- *NdefMap->WrNdefPacketLength = 0;
-
-
- NdefMap->PrevOperation = PH_FRINFC_NDEFMAP_WRITE_OPE;
- NdefMap->Felica.Offset = Offset;
-
- NdefMap->Felica.OpFlag = PH_FRINFC_NDEFMAP_FELI_WR_ATTR_RD_OP;
- status = phFriNfc_Felica_HRdAttrInfo(NdefMap);
- /* handle the error in Transc function*/
- if ( (status & PHNFCSTBLOWER) != (NFCSTATUS_PENDING & PHNFCSTBLOWER))
- {
- /* call respective CR */
- phFriNfc_Felica_HCrHandler(NdefMap,PH_FRINFC_NDEFMAP_CR_CHK_NDEF,status);
- }
- return (status);
-}
-
-/*!
- * \brief Initiates Writing of Empty NDEF information to the Remote Device.
- *
- * The function initiates the writing empty of NDEF information to a Remote Device.
- * It performs a reset of the state and starts the action (state machine).
- * A periodic call of the \ref phFriNfcNdefMap_Process has to be done once the action
- * has been triggered.
- */
-
-NFCSTATUS phFriNfc_Felica_EraseNdef( phFriNfc_NdefMap_t *NdefMap)
-{
-
- NFCSTATUS status = NFCSTATUS_PENDING;
- static uint32_t PktDtLength =0;
-
- if ( NdefMap->CardState == PH_NDEFMAP_CARD_STATE_INVALID )
- {
- /* Card is in invalid state, cannot have any read/write
- operations*/
- status = PHNFCSTVAL(CID_FRI_NFC_NDEF_MAP,\
- NFCSTATUS_INVALID_FORMAT);
- }
- else if ( NdefMap->CardState == PH_NDEFMAP_CARD_STATE_READ_ONLY )
- {
- /*Can't write to the card :No Grants */
- status = PHNFCSTVAL(CID_FRI_NFC_NDEF_MAP,\
- NFCSTATUS_WRITE_FAILED);
- /* set the no. bytes written is zero*/
- NdefMap->WrNdefPacketLength = &PktDtLength;
- *NdefMap->WrNdefPacketLength = 0;
- }
- else
- {
-
- /* set the Operation*/
- NdefMap->Felica.OpFlag = PH_FRINFC_NDEFMAP_FELI_WR_EMPTY_MSG_OP;
-
- status = phFriNfc_Felica_HRdAttrInfo(NdefMap);
- }
- return (status);
-}
-
-
-/*!
- * \brief Used in Write Opearation.
- * check the value set for the Write Flag, in first write operation(begin), sets the
- * WR flag in attribute blck.
- * After a successful write operation, This function sets the WR flag off and updates
- * the LEN bytes in attribute Block.
- */
-
-static NFCSTATUS phFriNfc_Felica_HUpdateAttrBlkForWrOp(phFriNfc_NdefMap_t *NdefMap,uint8_t isStarted)
-{
- NFCSTATUS status = NFCSTATUS_PENDING;
-
- uint16_t ChkSum=0,index=0;
- uint8_t BufIndex=0, ErrFlag = FALSE;
- uint32_t TotNoWrittenBytes=0;
-
- /* Write Operation : Begin/End Check*/
-
- NdefMap->State =
- (( isStarted == FELICA_WRITE_STARTED )?
- PH_NFCFRI_NDEFMAP_FELI_STATE_ATTR_BLK_WR_BEGIN:
- PH_NFCFRI_NDEFMAP_FELI_STATE_ATTR_BLK_WR_END);
-
- if( ( NdefMap->State == PH_NFCFRI_NDEFMAP_FELI_STATE_ATTR_BLK_WR_BEGIN)||
- ( NdefMap->State == PH_NFCFRI_NDEFMAP_FELI_STATE_ATTR_BLK_WR_END) )
- {
-
- /* Set the Felica Cmd*/
-#ifdef PH_HAL4_ENABLE
- NdefMap->Cmd.FelCmd = (phNfc_eFelicaCmdList_t)phHal_eFelica_Raw;
-#else
- NdefMap->Cmd.FelCmd = phHal_eFelicaCmdListFelicaCmd;
-#endif /* #ifdef PH_HAL4_ENABLE */
-
- /* 1st byte represents the length of the cmd packet*/
- NdefMap->SendRecvBuf[BufIndex] = 0x00;
- BufIndex++;
-
- /* Write/Update command code*/
- NdefMap->SendRecvBuf[BufIndex] = 0x08;
- BufIndex++;
-
- /* IDm - Manufacturer Id : 8bytes*/
-#ifdef PH_HAL4_ENABLE
- (void)memcpy( (&(NdefMap->SendRecvBuf[BufIndex])),
- (void*)(&(NdefMap->psRemoteDevInfo->RemoteDevInfo.Felica_Info.IDm)),
- 8);
-#else
- (void)memcpy( (&(NdefMap->SendRecvBuf[BufIndex])),
- (void*)(&(NdefMap->psRemoteDevInfo->RemoteDevInfo.CardInfo212_424.Startup212_424.NFCID2t)),
- 8);
-#endif /* #ifdef PH_HAL4_ENABLE */
-
- BufIndex+=8;
-
- NdefMap->SendRecvBuf[BufIndex] = 0x01; /* Number of Services (n=1 ==> 0x80)*/
- BufIndex++;
-
- NdefMap->SendRecvBuf[BufIndex] = 0x09; /* Service Code List*/
- BufIndex++;
-
- NdefMap->SendRecvBuf[BufIndex] = 0x00; /* Service Code List*/
- BufIndex++;
-
- NdefMap->SendRecvBuf[BufIndex] = 0x01; /* Number of Blocks to Write*/
- BufIndex++;
-
- NdefMap->SendRecvBuf[BufIndex] = 0x80; /* 1st Block Element : byte 1*/
- BufIndex++;
-
- NdefMap->SendRecvBuf[BufIndex] = 0x00; /* 1st Block Element : byte 2, block 1*/
- BufIndex++;
-
- /* Fill Attribute Blk Information*/
- NdefMap->SendRecvBuf[BufIndex] = NdefMap->FelicaAttrInfo.Version;
- BufIndex++;
-
- NdefMap->SendRecvBuf[BufIndex] = NdefMap->FelicaAttrInfo.Nbr;
- BufIndex++;
-
- NdefMap->SendRecvBuf[BufIndex] = NdefMap->FelicaAttrInfo.Nbw;
- BufIndex++;
-
- NdefMap->SendRecvBuf[BufIndex] = (uint8_t)((NdefMap->FelicaAttrInfo.Nmaxb) >> 8);
- BufIndex++;
-
- NdefMap->SendRecvBuf[BufIndex] = (uint8_t)((NdefMap->FelicaAttrInfo.Nmaxb) & (0x00ff));
- BufIndex++;
-
- NdefMap->SendRecvBuf[BufIndex] = 0x00; /*RFU*/
- BufIndex++;
-
- NdefMap->SendRecvBuf[BufIndex] = 0x00; /*RFU*/
- BufIndex++;
-
- NdefMap->SendRecvBuf[BufIndex] = 0x00; /*RFU*/
- BufIndex++;
-
- NdefMap->SendRecvBuf[BufIndex] = 0x00; /*RFU*/
- BufIndex++;
-
- if (isStarted == FELICA_WRITE_STARTED )
- {
- NdefMap->SendRecvBuf[BufIndex] = 0x0F; /* Write Flag Made On*/
- BufIndex++;
-
- NdefMap->SendRecvBuf[BufIndex] = NdefMap->FelicaAttrInfo.RdWrFlag; /* Read write flag*/
- BufIndex++;
-
- /* Len Bytes*/
- NdefMap->SendRecvBuf[BufIndex] = NdefMap->FelicaAttrInfo.LenBytes[0];
- BufIndex++;
-
- NdefMap->SendRecvBuf[BufIndex] = NdefMap->FelicaAttrInfo.LenBytes[1];
- BufIndex++;
-
- NdefMap->SendRecvBuf[BufIndex] = NdefMap->FelicaAttrInfo.LenBytes[2];
- BufIndex++;
- }
- else
- {
- /* Case: Previous Write Operation failed and integration context continues with write
- operation with offset set to Current. In this case, if we find Internal Bytes remained in the
- felica context is true(>0) and current block number is Zero. Then we shouldn't allow the module
- to write the data to card, as this is a invalid case*/
- if ( (NdefMap->Felica.Wr_BytesRemained > 0) && (NdefMap->Felica.CurBlockNo == 0))
- {
- status = PHNFCSTVAL(CID_FRI_NFC_NDEF_MAP,
- NFCSTATUS_INVALID_PARAMETER);
- ErrFlag = TRUE;
- }
- else
- {
-
- NdefMap->SendRecvBuf[BufIndex] = 0x00; /* Write Flag Made Off*/
- BufIndex++;
-
- NdefMap->SendRecvBuf[BufIndex] = NdefMap->FelicaAttrInfo.RdWrFlag; /* Read write flag*/
- BufIndex++;
-
- if ( NdefMap->Felica.Wr_BytesRemained > 0 )
- {
- TotNoWrittenBytes = ( (NdefMap->Felica.CurBlockNo *16)- (16 - (NdefMap->Felica.Wr_BytesRemained)));
- }
- else
- {
- TotNoWrittenBytes = ( NdefMap->Felica.CurBlockNo *16);
-
- }
-
- /* Update Len Bytes*/
- NdefMap->SendRecvBuf[BufIndex] = (uint8_t)(( TotNoWrittenBytes & 0x00ff0000) >> 16);
- BufIndex++;
-
- NdefMap->SendRecvBuf[BufIndex] = (uint8_t)((TotNoWrittenBytes & 0x0000ff00) >> 8);
- BufIndex++;
-
- NdefMap->SendRecvBuf[BufIndex] = (uint8_t)(TotNoWrittenBytes & 0x000000ff);
- BufIndex++;
- }
- }
-
- if ( ErrFlag != TRUE )
- {
- /* check sum update*/
- for ( index = 16 ; index < 30 ; index ++)
- {
- ChkSum += NdefMap->SendRecvBuf[index];
- }
-
- /* fill check sum in command pkt*/
- NdefMap->SendRecvBuf[BufIndex] = (uint8_t)(ChkSum >> 8);
- BufIndex++;
-
- NdefMap->SendRecvBuf[BufIndex] = (uint8_t )(ChkSum & 0x00ff);
- BufIndex++;
-
- /* update length of the cmd pkt*/
- NdefMap->SendRecvBuf[PH_NFCFRI_NDEFMAP_FELI_PKT_LEN_INDEX] = BufIndex;
-
- *NdefMap->SendRecvLength = NdefMap->TempReceiveLength;
-
- /* Update the Send Len*/
- NdefMap->SendLength = BufIndex;
-
- /*set the completion routines for the desfire card operations*/
- NdefMap->MapCompletionInfo.CompletionRoutine = phFriNfc_NdefMap_Process;
- NdefMap->MapCompletionInfo.Context = NdefMap;
-
- /*set the additional informations for the data exchange*/
- NdefMap->psDepAdditionalInfo.DepFlags.MetaChaining = 0;
- NdefMap->psDepAdditionalInfo.DepFlags.NADPresent = 0;
-
- /*Call the Overlapped HAL Transceive function */
- status = phFriNfc_OvrHal_Transceive( NdefMap->LowerDevice,
- &NdefMap->MapCompletionInfo,
- NdefMap->psRemoteDevInfo,
- NdefMap->Cmd,
- &NdefMap->psDepAdditionalInfo,
- NdefMap->SendRecvBuf,
- NdefMap->SendLength,
- NdefMap->SendRecvBuf,
- NdefMap->SendRecvLength);
- }
- }
- else
- {
- status = PHNFCSTVAL(CID_FRI_NFC_NDEF_MAP,
- NFCSTATUS_INVALID_PARAMETER);
-
- }
- return (status);
-}
-
-static NFCSTATUS phFriNfc_Felica_HWrEmptyMsg(phFriNfc_NdefMap_t *NdefMap)
-{
- NFCSTATUS status = NFCSTATUS_PENDING;
-
- uint16_t ChkSum=0,index=0;
- uint8_t BufIndex=0;
-
- /* Write Operation : To Erase the present NDEF Data*/
-
- NdefMap->State = PH_NFCFRI_NDEFMAP_FELI_STATE_WR_EMPTY_MSG;
-
- /* Set the Felica Cmd*/
-#ifdef PH_HAL4_ENABLE
- NdefMap->Cmd.FelCmd = (phNfc_eFelicaCmdList_t)phHal_eFelica_Raw;
-#else
- NdefMap->Cmd.FelCmd = phHal_eFelicaCmdListFelicaCmd;
-#endif /* #ifdef PH_HAL4_ENABLE */
-
- /* 1st byte represents the length of the cmd packet*/
- NdefMap->SendRecvBuf[BufIndex] = 0x00;
- BufIndex++;
-
- /* Write/Update command code*/
- NdefMap->SendRecvBuf[BufIndex] = 0x08;
- BufIndex++;
-
- /* IDm - Manufacturer Id : 8bytes*/
-#ifdef PH_HAL4_ENABLE
- (void)memcpy( (&(NdefMap->SendRecvBuf[BufIndex])),
- (void*)(&(NdefMap->psRemoteDevInfo->RemoteDevInfo.Felica_Info.IDm)),
- 8);
-#else
- (void)memcpy( (&(NdefMap->SendRecvBuf[BufIndex])),
- (void*)(&(NdefMap->psRemoteDevInfo->RemoteDevInfo.CardInfo212_424.Startup212_424.NFCID2t)),
- 8);
-#endif /* #ifdef PH_HAL4_ENABLE */
-
-
- BufIndex+=8;
-
- NdefMap->SendRecvBuf[BufIndex] = 0x01; /* Number of Services (n=1 ==> 0x80)*/
- BufIndex++;
-
- NdefMap->SendRecvBuf[BufIndex] = 0x09; /* Service Code List*/
- BufIndex++;
-
- NdefMap->SendRecvBuf[BufIndex] = 0x00; /* Service Code List*/
- BufIndex++;
-
- NdefMap->SendRecvBuf[BufIndex] = 0x01; /* Number of Blocks to Write*/
- BufIndex++;
-
- NdefMap->SendRecvBuf[BufIndex] = 0x80; /* 1st Block Element : byte 1*/
- BufIndex++;
-
- NdefMap->SendRecvBuf[BufIndex] = 0x00; /* 1st Block Element : byte 2, block 1*/
- BufIndex++;
-
- /* Fill Attribute Blk Information*/
- NdefMap->SendRecvBuf[BufIndex] = NdefMap->FelicaAttrInfo.Version;
- BufIndex++;
-
- NdefMap->SendRecvBuf[BufIndex] = NdefMap->FelicaAttrInfo.Nbr;
- BufIndex++;
-
- NdefMap->SendRecvBuf[BufIndex] = NdefMap->FelicaAttrInfo.Nbw;
- BufIndex++;
-
- NdefMap->SendRecvBuf[BufIndex] = (uint8_t)((NdefMap->FelicaAttrInfo.Nmaxb) >> 8);
- BufIndex++;
-
- NdefMap->SendRecvBuf[BufIndex] = (uint8_t)((NdefMap->FelicaAttrInfo.Nmaxb) & (0x00ff));
- BufIndex++;
-
- NdefMap->SendRecvBuf[BufIndex] = 0x00; /*RFU*/
- BufIndex++;
-
- NdefMap->SendRecvBuf[BufIndex] = 0x00; /*RFU*/
- BufIndex++;
-
- NdefMap->SendRecvBuf[BufIndex] = 0x00; /*RFU*/
- BufIndex++;
-
- NdefMap->SendRecvBuf[BufIndex] = 0x00; /*RFU*/
- BufIndex++;
-
- NdefMap->SendRecvBuf[BufIndex] = NdefMap->FelicaAttrInfo.WriteFlag;
- BufIndex++;
-
- NdefMap->SendRecvBuf[BufIndex] = NdefMap->FelicaAttrInfo.RdWrFlag; /* Read write flag*/
- BufIndex++;
-
- /* Len Bytes are set to 0 : Empty Msg*/
- NdefMap->SendRecvBuf[BufIndex] = 0x00;
- BufIndex++;
-
- NdefMap->SendRecvBuf[BufIndex] = 0x00;
- BufIndex++;
-
- NdefMap->SendRecvBuf[BufIndex] = 0x00;
- BufIndex++;
-
- /* check sum update*/
- for ( index = 16 ; index < 30 ; index ++)
- {
- ChkSum += NdefMap->SendRecvBuf[index];
- }
-
- /* fill check sum in command pkt*/
- NdefMap->SendRecvBuf[BufIndex] = (uint8_t)(ChkSum >> 8);
- BufIndex++;
-
- NdefMap->SendRecvBuf[BufIndex] = (uint8_t )(ChkSum & 0x00ff);
- BufIndex++;
-
- /* update length of the cmd pkt*/
- NdefMap->SendRecvBuf[PH_NFCFRI_NDEFMAP_FELI_PKT_LEN_INDEX] = BufIndex;
-
- *NdefMap->SendRecvLength = NdefMap->TempReceiveLength;
-
- /* Update the Send Len*/
- NdefMap->SendLength = BufIndex;
-
- /*set the completion routines for the desfire card operations*/
- NdefMap->MapCompletionInfo.CompletionRoutine = phFriNfc_NdefMap_Process;
- NdefMap->MapCompletionInfo.Context = NdefMap;
-
- /*set the additional informations for the data exchange*/
- NdefMap->psDepAdditionalInfo.DepFlags.MetaChaining = 0;
- NdefMap->psDepAdditionalInfo.DepFlags.NADPresent = 0;
-
- /*Call the Overlapped HAL Transceive function */
- status = phFriNfc_OvrHal_Transceive( NdefMap->LowerDevice,
- &NdefMap->MapCompletionInfo,
- NdefMap->psRemoteDevInfo,
- NdefMap->Cmd,
- &NdefMap->psDepAdditionalInfo,
- NdefMap->SendRecvBuf,
- NdefMap->SendLength,
- NdefMap->SendRecvBuf,
- NdefMap->SendRecvLength);
-
- return (status);
-}
-
-
-
-
-/*!
- * \brief Used in Write Opearation.
- * This Function is called after a successful validation and storing of attribution block
- * content in to context.
- * If the write operation is initiated with begin,function initiates the write operation with
- * RdWr flag.
- * If the Offset is set to Current, Checks for the EOF card reached status and writes data to
- * The Card
- */
-
-static NFCSTATUS phFriNfc_Felica_HChkAttrBlkForWrOp(phFriNfc_NdefMap_t *NdefMap)
-{
- NFCSTATUS status = NFCSTATUS_PENDING;
- uint32_t DataLen=0;
-
- /*check RW Flag Access Rights*/
- /* set to read only cannot write*/
- if ( NdefMap->FelicaAttrInfo.RdWrFlag == 0x00)
-
- {
- status = PHNFCSTVAL(CID_FRI_NFC_NDEF_MAP,
- NFCSTATUS_INVALID_DEVICE_REQUEST);
- }
- else
- {
- if ( ( NdefMap->Felica.Offset == PH_FRINFC_NDEFMAP_SEEK_BEGIN) ||
- ( ( NdefMap->PrevOperation == PH_FRINFC_NDEFMAP_READ_OPE) &&
- (NdefMap->Felica.Offset != PH_FRINFC_NDEFMAP_SEEK_BEGIN ) ))
- {
- /* check allready written number of bytes and apdu buffer size*/
- if (NdefMap->ApduBufferSize > (uint32_t)(NdefMap->FelicaAttrInfo.Nmaxb *16))
- {
- NdefMap->Felica.EofCardReachedFlag = FELICA_EOF_REACHED_WR_WITH_BEGIN_OFFSET;
- }
- else
- {
- NdefMap->Felica.EofCardReachedFlag = FALSE;
- }
-
-
- /* reset the internal variables initiate toupdate the attribute blk*/
- NdefMap->Felica.Wr_BytesRemained = 0;
- NdefMap->Felica.CurBlockNo = 0;
- NdefMap->Felica.NoBlocksWritten = 0;
- phFriNfc_Felica_HInitInternalBuf(NdefMap->Felica.Wr_RemainedBytesBuff);
- status= phFriNfc_Felica_HUpdateAttrBlkForWrOp(NdefMap,FELICA_WRITE_STARTED);
-
- }
- else
- {
- if (NdefMap->Felica.Offset == PH_FRINFC_NDEFMAP_SEEK_CUR )
- {
- /* Calculate the Allready Written No. Of Blocks*/
- PH_NFCFRI_NDEFMAP_FELI_CAL_LEN_BYTES(NdefMap->FelicaAttrInfo.LenBytes[0],
- NdefMap->FelicaAttrInfo.LenBytes[1],
- NdefMap->FelicaAttrInfo.LenBytes[2],
- DataLen);
-
- if (( NdefMap->ApduBufferSize + (DataLen )) >
- (uint32_t)( NdefMap->FelicaAttrInfo.Nmaxb *16))
- {
- if(( DataLen ) == (uint32_t)(NdefMap->FelicaAttrInfo.Nmaxb *16) )
- {
- status = PHNFCSTVAL(CID_FRI_NFC_NDEF_MAP,
- NFCSTATUS_EOF_NDEF_CONTAINER_REACHED);
- }
- else
- {
-
- NdefMap->Felica.EofCardReachedFlag =FELICA_EOF_REACHED_WR_WITH_CURR_OFFSET;
- NdefMap->ApduBuffIndex =0;
- NdefMap->Felica.NoBlocksWritten = 0;
- status= phFriNfc_Felica_HUpdateAttrBlkForWrOp(NdefMap,FELICA_WRITE_STARTED);
- }
- }
- else
- {
- NdefMap->ApduBuffIndex =0;
- NdefMap->Felica.NoBlocksWritten = 0;
- status= phFriNfc_Felica_HUpdateAttrBlkForWrOp(NdefMap,FELICA_WRITE_STARTED);
- }
- }/*if (NdefMap->Felica.Offset == PH_FRINFC_NDEFMAP_SEEK_CUR )*/
- }
- }
- return (status);
-}
-
-/*!
- * \brief Used in Read Opearation.
- * This Function is called after a successful validation and storing of attribution block
- * content in to context.
- * While Offset is set to Current, Checks for the EOF card reached status and reads data from
- * The Card
- */
-
-static NFCSTATUS phFriNfc_Felica_HChkAttrBlkForRdOp(phFriNfc_NdefMap_t *NdefMap,
- uint32_t NdefLen)
-{
- NFCSTATUS status = NFCSTATUS_PENDING;
-
- /*check WR Flag Access Rights*/
- /* set to still writing data state only cannot Read*/
- if ( NdefMap->FelicaAttrInfo.WriteFlag == 0x0F )
- {
- status = PHNFCSTVAL(CID_FRI_NFC_NDEF_MAP,NFCSTATUS_READ_FAILED);
- /* As we are not able to continue with reading data
- bytes read set to zero*/
- *NdefMap->NumOfBytesRead = 0;
- }
- else
- {
- status = phFriNfc_MapTool_SetCardState( NdefMap,NdefLen);
- if ( status == NFCSTATUS_SUCCESS)
- {
- /* Read data From the card*/
- status = phFriNfc_Felica_HReadData(NdefMap,NdefMap->Felica.Offset);
- }
- }
-
- return (status);
-}
-
-/*!
- * \brief Used in Write Opearation.
- * This function writes the data in terms of blocks.
- * Each write operation supports,minimum Nbw blocks of bytes.
- * Also checks for the EOF,>=NBW,ApduBufferSize - NdefMap->ApduBuffIndex) > 0 )
- {
- /* Prepare the write cmd pkt for felica*/
- /* 1st byte represents the length of the cmd packet*/
- NdefMap->SendRecvBuf[BufIndex] = 0x00;
- BufIndex++;
-
- /* Write/Update command code*/
- NdefMap->SendRecvBuf[BufIndex] = 0x08;
- BufIndex++;
-
- /* IDm - Manufacturer Id : 8bytes*/
-#ifdef PH_HAL4_ENABLE
- (void)memcpy((&(NdefMap->SendRecvBuf[BufIndex])),
- (&(NdefMap->psRemoteDevInfo->RemoteDevInfo.Felica_Info.IDm)),
- 8);
-#else
- (void)memcpy((&(NdefMap->SendRecvBuf[BufIndex])),
- (&(NdefMap->psRemoteDevInfo->RemoteDevInfo.CardInfo212_424.Startup212_424.NFCID2t)),
- 8);
-#endif /* #ifdef PH_HAL4_ENABLE */
-
- BufIndex+=8;
-
- NdefMap->SendRecvBuf[BufIndex] = 0x01; /* Number of Services (n=1 ==> 0x80)*/
- BufIndex++;
-
- NdefMap->SendRecvBuf[BufIndex] = 0x09; /* Service Code List*/
- BufIndex++;
-
- NdefMap->SendRecvBuf[BufIndex] = 0x00; /* Service Code List*/
- BufIndex++;
-
- if ( NdefMap->Felica.EofCardReachedFlag == FELICA_EOF_REACHED_WR_WITH_BEGIN_OFFSET)
- {
- /* check for the eof card reached flag.Need to write only mamximum bytes(memory)to card.
- Used when, offset set to begin case*/
- BytesRemainedInCard= ( (NdefMap->FelicaAttrInfo.Nmaxb*16) - (NdefMap->Felica.CurBlockNo * 16));
- }
- else
- {
- /* Offset : Cuurent*/
- if ( NdefMap->Felica.EofCardReachedFlag == FELICA_EOF_REACHED_WR_WITH_CURR_OFFSET )
- {
- /* caculate previously written Ndef blks*/
- (void)phFriNfc_Felica_HGetMaximumBlksToRead(NdefMap,PH_NFCFRI_NDEFMAP_FELI_NBC);
-
- if ( NdefMap->Felica.Wr_BytesRemained )
- {
- TotNoWrittenBytes = ( (NdefMap->Felica.CurBlockNo *16)- (16 - (NdefMap->Felica.Wr_BytesRemained)));
- }
- else
- {
- TotNoWrittenBytes = ( NdefMap->Felica.CurBlockNo *16);
- }
- /* Determine exactly, how many bytes we can write*/
- BytesRemainedInCard = (NdefMap->FelicaAttrInfo.Nmaxb*16 - (TotNoWrittenBytes));
- }
-
- }
- /* Write Data Pending in the Internal Buffer*/
- if(NdefMap->Felica.Wr_BytesRemained > 0)
- {
- /* update the number of blocks to write with the block list elements*/
- /* Total Number of blocks to write*/
- NdefMap->SendRecvBuf[BufIndex] = 0;
- BufIndex++;
-
- /* Update this Total no. Bloks later*/
- NoOfBlks = BufIndex;
-
- /* As we are writing atleast one block*/
- TotNoBlks = 1;
-
- /* check do we have some extra bytes to write? in User Buffer*/
- if ( NdefMap->ApduBufferSize >(uint32_t) (16 - NdefMap->Felica.Wr_BytesRemained))
- {
- /* Have we reached EOF?*/
- if ( NdefMap->Felica.EofCardReachedFlag )
- {
- BytesRemained = BytesRemainedInCard;
- }
- else
- {
- /* This value tells how many extra bytes we can write other than internal buffer bytes*/
- BytesRemained = (uint8_t)NdefMap->ApduBufferSize - (16 - NdefMap->Felica.Wr_BytesRemained);
- }
-
- if ( BytesRemained )
- {
- /* Not reached EOF*/
- if (!NdefMap->Felica.EofCardReachedFlag)
- {
- /* Calculate How many blks we need to write*/
- BlkNo =((uint8_t)( BytesRemained )/16);
-
- /* check blocks to write exceeds nbw*/
- if ( BlkNo >= NdefMap->FelicaAttrInfo.Nbw )
- {
- BlkNo = NdefMap->FelicaAttrInfo.Nbw;
- /* No. Blks to write are more than Nbw*/
- NbwCheck = 1;
- }
- else
- {
- if ((( BytesRemained %16) == 0)&& (BlkNo == 0 ))
- {
- BlkNo=1;
- }
- }
- /* check do we need pad bytes?*/
- if( (!NbwCheck && (uint8_t)( BytesRemained)%16) != 0)
- {
- BlkNo++;
- PadBytes = (BlkNo * 16) - (uint8_t)( BytesRemained);
- NdefMap->Felica.PadByteFlag = TRUE;
- NdefMap->Felica.NoBlocksWritten = BlkNo;
- TotNoBlks += BlkNo;
-
- }
- else
- {
- if ( NbwCheck )
- {
- /* as we have to write only 8 blocks and already we have pad bytes so we have
- to strat from previous block*/
- TotNoBlks += BlkNo - 1;
- NdefMap->Felica.NoBlocksWritten = TotNoBlks-1;
- }
- else
- {
- if ( !(BytesRemained - (16 -NdefMap->Felica.Wr_BytesRemained)== 0 ))
- {
- TotNoBlks += BlkNo;
- }
- else
- {
-
- }
- if ( NdefMap->Felica.PadByteFlag )
- {
- NdefMap->Felica.NoBlocksWritten = TotNoBlks-1;
-
- }
- }
- }
- }
- else
- {
- /* we have reached the eof card & hv bytes to write*/
- BlkNo =(uint8_t)(( BytesRemained - ((16 -NdefMap->Felica.Wr_BytesRemained)) )/16);
-
- /* check are we exceeding the NBW limit, while a write?*/
- if ( BlkNo >= NdefMap->FelicaAttrInfo.Nbw )
- {
- BlkNo = NdefMap->FelicaAttrInfo.Nbw;
-
- /* No. Blks to write are more than Nbw*/
- NbwCheck = 1;
-
- }
- else
- {
- if ((( BytesRemained %16) == 0)&& (BlkNo == 0 ))
- {
- BlkNo=1;
- }
- }
-
- /*check Total how many blocks to write*/
- if(((!NbwCheck) &&( BytesRemained- (16 - NdefMap->Felica.Wr_BytesRemained))%16) != 0)
- {
- BlkNo++;
- PadBytes = (BlkNo * 16) - (uint8_t)( BytesRemained);
- NdefMap->Felica.PadByteFlag = TRUE;
- NdefMap->Felica.NoBlocksWritten = BlkNo;
- TotNoBlks += BlkNo;
-
- }
- else
- {
- if ( NbwCheck )
- {
- /* as we have to write only 8 blocks and already we have pad bytes so we have
- to strat from previous last block*/
- TotNoBlks += BlkNo - 1;
- NdefMap->Felica.NoBlocksWritten = TotNoBlks-1;
- }
- else
- {
- /* we need to write only one block ( bytesremanind + internal buffer size = 16)*/
- if ( !(BytesRemained - (16 -NdefMap->Felica.Wr_BytesRemained)== 0 ))
- {
- TotNoBlks += BlkNo;
- }
- else
- {
- ;/* we are not incrementing the Total no. of blocks to write*/
- }
-
- if ( NdefMap->Felica.PadByteFlag )
- {
- NdefMap->Felica.NoBlocksWritten = TotNoBlks -1;
-
- }
- }
- }
- }
- }/*if ( BytesRemained )*/
- else
- {
- ; /*Nothing to process here*/
- }
- }/*if ( NdefMap->ApduBufferSize >(uint32_t) (16 - NdefMap->Felica.Wr_BytesRemained))*/
- else
- {
- /* No new blks to write*/
- NdefMap->Felica.NoBlocksWritten = 0;
- }
- /* Prepare the Blk List for Write Operation*/
- /* Block List for NBw : 1st byte : two byte len list: 2nd byte is the block number*/
- for ( i=0; i< TotNoBlks; i++)
- {
- NdefMap->SendRecvBuf[BufIndex] = 0x80;
- BufIndex++;
- /* remember the previous Blk no and continue from there*/
- if ( NdefMap->Felica.PadByteFlag == TRUE )
- {
- NdefMap->SendRecvBuf[BufIndex] = NdefMap->Felica.CurBlockNo + i;
- BufIndex++;
- }
- else
- {
- CurBlk = NdefMap->Felica.CurBlockNo +1;
- NdefMap->SendRecvBuf[BufIndex] = CurBlk + i;
- BufIndex++;
- }
- }
- /* Copy relevant data to Transc buffer*/
- if((NdefMap->ApduBufferSize - NdefMap->ApduBuffIndex) >= (uint32_t)(16 - NdefMap->Felica.Wr_BytesRemained))
- {
-
- /*Copy the Remained bytes from the internal buffer to trxbuffer */
- (void)memcpy( (&(NdefMap->SendRecvBuf[BufIndex])),
- NdefMap->Felica.Wr_RemainedBytesBuff,
- NdefMap->Felica.Wr_BytesRemained);
-
- /*Increment the buff index*/
- BufIndex += NdefMap->Felica.Wr_BytesRemained;
-
-
- /*append copy 16-bytesToPad to trxBuffer*/
- (void)memcpy( (&(NdefMap->SendRecvBuf[BufIndex])),
- (&(NdefMap->ApduBuffer[NdefMap->ApduBuffIndex])),
- (16 - NdefMap->Felica.Wr_BytesRemained));
-
- /* Update Number Of Bytes Writtened*/
- NdefMap->NumOfBytesWritten = 16 - NdefMap->Felica.Wr_BytesRemained;
-
- /* increment the index*/
- BufIndex += 16 - NdefMap->Felica.Wr_BytesRemained;
-
- if ( BytesRemained )
- {
- if (!NdefMap->Felica.EofCardReachedFlag)
- {
- /* check nbw limit*/
- if ( NbwCheck != 1 )
- {
- /* Copy Extra Bytes other than the internal buffer bytes*/
- (void)memcpy( (&(NdefMap->SendRecvBuf[BufIndex])),
- (&(NdefMap->ApduBuffer[(16 - NdefMap->Felica.Wr_BytesRemained)])),
- (NdefMap->ApduBufferSize - (16 - NdefMap->Felica.Wr_BytesRemained)));
-
-
- /* Update Number Of Bytes Writtened*/
- NdefMap->NumOfBytesWritten += (uint16_t)(NdefMap->ApduBufferSize - (16 - NdefMap->Felica.Wr_BytesRemained));
-
- BufIndex += (uint8_t)(NdefMap->ApduBufferSize - (16 - NdefMap->Felica.Wr_BytesRemained));
-
- if ( PadBytes )
- {
- for(i= 0; i< PadBytes; i++)
- {
- NdefMap->SendRecvBuf[BufIndex] =0x00;
- BufIndex++;
- }
- /* no of bytes remained copy*/
- NdefMap->Felica.Wr_BytesRemained = (uint8_t)(16 - PadBytes);
-
- /*copy the data to internal buffer : Bytes remained*/
- (void)memcpy( NdefMap->Felica.Wr_RemainedBytesBuff,
- (&( NdefMap->ApduBuffer[(NdefMap->ApduBufferSize - NdefMap->Felica.Wr_BytesRemained)])),
- ( NdefMap->Felica.Wr_BytesRemained));
- }
- else
- {
- /* No Bytes in Internal buffer*/
- NdefMap->Felica.Wr_BytesRemained = 0;
- }
-
- }
- else
- {
-
- /*Copy Nbw*16 bytes of data to the trx buffer*/
- (void)memcpy( (&(NdefMap->SendRecvBuf[BufIndex])),
- (&(NdefMap->ApduBuffer[(16 - NdefMap->Felica.Wr_BytesRemained)])),
- (NdefMap->FelicaAttrInfo.Nbw - 1) * 16);
-
- /* increment the Buffindex*/
- BufIndex += ((NdefMap->FelicaAttrInfo.Nbw - 1 )*16);
-
- NdefMap->Felica.Wr_BytesRemained = 0;
- NdefMap->NumOfBytesWritten+= ((NdefMap->FelicaAttrInfo.Nbw -1)*16);
- NdefMap->Felica.PadByteFlag =FALSE;
- }
- }/*if (!NdefMap->Felica.EofCardReachedFlag)*/
- else
- {
- /* check nbw limit*/
- if ( NbwCheck != 1 )
- {
- /* handle EOF card reached case*/
- (void)memcpy( (&(NdefMap->SendRecvBuf[BufIndex])),
- (&(NdefMap->ApduBuffer[(16 - NdefMap->Felica.Wr_BytesRemained)])),
- ( BytesRemained - ((16 -NdefMap->Felica.Wr_BytesRemained) )));
-
- /* Update Number Of Bytes Writtened*/
- NdefMap->NumOfBytesWritten += (uint16_t)( BytesRemained - (16 -NdefMap->Felica.Wr_BytesRemained));
-
- BufIndex += (uint8_t)( BytesRemained - (16 -NdefMap->Felica.Wr_BytesRemained));
-
- if ( PadBytes )
- {
- for(i= 0; i< PadBytes; i++)
- {
- NdefMap->SendRecvBuf[BufIndex] =0x00;
- BufIndex++;
- }
-
- /*no of bytes remained copy*/
- NdefMap->Felica.Wr_BytesRemained = (uint8_t)(16 - PadBytes);
-
- /*copy the data to internal buffer : Bytes remained*/
- (void)memcpy(NdefMap->Felica.Wr_RemainedBytesBuff,
- (&(NdefMap->ApduBuffer[(NdefMap->ApduBufferSize - NdefMap->Felica.Wr_BytesRemained)])),
- (NdefMap->Felica.Wr_BytesRemained));
-
- }
- else
- {
- NdefMap->Felica.Wr_BytesRemained = 0;
- }
- }
- else
- {
-
- /*Copy Nbw*16 bytes of data to the trx buffer*/
- (void)memcpy((&(NdefMap->SendRecvBuf[BufIndex])),
- (&(NdefMap->ApduBuffer[(16 - NdefMap->Felica.Wr_BytesRemained)])),
- (NdefMap->FelicaAttrInfo.Nbw - 1) * 16);
-
- /* increment the Buffindex*/
- BufIndex += ((NdefMap->FelicaAttrInfo.Nbw - 1 )*16);
-
- NdefMap->Felica.Wr_BytesRemained = 0;
- NdefMap->NumOfBytesWritten+= ((NdefMap->FelicaAttrInfo.Nbw -1)*16);
-
- NdefMap->Felica.PadByteFlag =FALSE;
- }
- }
- }/*if ( BytesRemained )*/
- else
- {
- NdefMap->Felica.Wr_BytesRemained = 0;
- }
- /* Update Total No. of blocks writtened*/
- NdefMap->SendRecvBuf[NoOfBlks -1 ]=TotNoBlks;
- }/*if((NdefMap->ApduBufferSize - NdefMap->ApduBuffIndex) >= (uint32_t)(16 - NdefMap->Felica.Wr_BytesRemained))*/
- else
- {
- /*copy the internal buffer data to trx buffer*/
- (void)memcpy((&(NdefMap->SendRecvBuf[BufIndex])),
- NdefMap->Felica.Wr_RemainedBytesBuff,
- (NdefMap->Felica.Wr_BytesRemained));
-
- /* increment the index*/
- BufIndex+=NdefMap->Felica.Wr_BytesRemained;
-
- /*append the apdusize data to the trx buffer*/
- (void)memcpy((&(NdefMap->SendRecvBuf[BufIndex])),
- (&(NdefMap->ApduBuffer[NdefMap->ApduBuffIndex])),
- NdefMap->ApduBufferSize);
-
- /* Index increment*/
- BufIndex+= (uint8_t)NdefMap->ApduBufferSize;
-
- /* Tells how many bytes present in the internal buffer*/
- BytesRemained = NdefMap->Felica.Wr_BytesRemained + NdefMap->ApduBufferSize;
-
- PadBytes = (uint8_t)(16-BytesRemained);
-
- /* Pad empty bytes with Zeroes to complete 16 bytes*/
- for(i= 0; i< PadBytes; i++)
- {
- NdefMap->SendRecvBuf[BufIndex] =0x00;
- BufIndex++;
- }
-
- /* Update Number Of Bytes Writtened*/
- NdefMap->NumOfBytesWritten = (uint16_t)NdefMap->ApduBufferSize;
-
- /* Flag set to understand that , we have received less no. of bytes than
- present in the internal buffer*/
- NdefMap->Felica.IntermediateWrFlag = TRUE;
-
- if ( NdefMap->Felica.PadByteFlag )
- {
- NdefMap->Felica.NoBlocksWritten = 0;
- }
- }
-
- NdefMap->SendRecvBuf[PH_NFCFRI_NDEFMAP_FELI_PKT_LEN_INDEX] = BufIndex;
- NdefMap->SendLength = BufIndex;
- /* Update Total No. of blocks writtened*/
- NdefMap->SendRecvBuf[NoOfBlks -1 ]=TotNoBlks;
- }
- else
- {
- /*Fresh write, starting from a new block*/
- if ( (NdefMap->ApduBufferSize - NdefMap->ApduBuffIndex) >= (uint32_t)(16* NdefMap->FelicaAttrInfo.Nbw ))
- {
- /* check for the card size and write Nbw Blks*/
- if ( NdefMap->FelicaAttrInfo.Nmaxb - NdefMap->Felica.CurBlockNo >= NdefMap->FelicaAttrInfo.Nbw)
- {
- /* update the number of blocks to write with the block list elements*/
- /* Total Number of blocks to write*/
- NdefMap->SendRecvBuf[BufIndex] = NdefMap->FelicaAttrInfo.Nbw;
- BufIndex++;
-
- /* Block List for NBw : 1st byte : two byte len list: 2nd byte is the block number*/
- for ( i=1; i<= NdefMap->FelicaAttrInfo.Nbw; i++)
- {
- NdefMap->SendRecvBuf[BufIndex] = 0x80;
- BufIndex++;
-
- NdefMap->SendRecvBuf[BufIndex] = NdefMap->Felica.CurBlockNo + i;
- BufIndex++;
- }
- /*Copy Nbw*16 bytes of data to the trx buffer*/
-
- (void)memcpy((&(NdefMap->SendRecvBuf[BufIndex])),
- (&(NdefMap->ApduBuffer[NdefMap->ApduBuffIndex])),
- NdefMap->FelicaAttrInfo.Nbw * 16);
-
- /* increment the Buffindex*/
- BufIndex += (NdefMap->FelicaAttrInfo.Nbw*16);
-
- /* update the length*/
- NdefMap->SendRecvBuf[PH_NFCFRI_NDEFMAP_FELI_PKT_LEN_INDEX] = BufIndex;
-
- NdefMap->Felica.Wr_BytesRemained = 0;
- NdefMap->NumOfBytesWritten = (NdefMap->FelicaAttrInfo.Nbw*16);
- NdefMap->Felica.NoBlocksWritten = NdefMap->FelicaAttrInfo.Nbw;
-
- /* update the Send length*/
- NdefMap->SendLength = BufIndex;
-
- NdefMap->Felica.PadByteFlag = FALSE;
- }/*if ( NdefMap->FelicaAttrInfo.Nmaxb - NdefMap->Felica.CurBlockNo >= NdefMap->FelicaAttrInfo.Nbw)*/
- else
- {
- /* we need to write less than nbw blks*/
- /* update the number of blocks to write with the block list elements*/
- /* Total Number of blocks to write*/
- NdefMap->SendRecvBuf[BufIndex] = (uint8_t)( NdefMap->FelicaAttrInfo.Nmaxb - NdefMap->Felica.CurBlockNo);
- BufIndex++;
-
- /* Block List for NBw : 1st byte : two byte len list: 2nd byte is the block number*/
- for ( i=1; i<= (NdefMap->FelicaAttrInfo.Nmaxb - NdefMap->Felica.CurBlockNo); i++)
- {
- NdefMap->SendRecvBuf[BufIndex] = 0x80;
- BufIndex++;
- NdefMap->SendRecvBuf[BufIndex] = NdefMap->Felica.CurBlockNo + i;
- BufIndex++;
- }
-
- /*Copy Nbw*16 bytes of data to the trx buffer*/
- (void)memcpy((&(NdefMap->SendRecvBuf[BufIndex])),
- (&(NdefMap->ApduBuffer[NdefMap->ApduBuffIndex])),
- (NdefMap->FelicaAttrInfo.Nmaxb - NdefMap->Felica.CurBlockNo)*16);
-
- /* increment the Buffindex*/
- BufIndex += (uint8_t)((NdefMap->FelicaAttrInfo.Nmaxb - NdefMap->Felica.CurBlockNo )*16);
-
- /* update the length*/
- NdefMap->SendRecvBuf[PH_NFCFRI_NDEFMAP_FELI_PKT_LEN_INDEX] = BufIndex;
-
- NdefMap->NumOfBytesWritten = ((NdefMap->FelicaAttrInfo.Nmaxb - NdefMap->Felica.CurBlockNo)*16);
- NdefMap->Felica.NoBlocksWritten = (uint8_t)(NdefMap->FelicaAttrInfo.Nmaxb - NdefMap->Felica.CurBlockNo);
-
- /* update the Send length*/
- NdefMap->SendLength = BufIndex;
-
- NdefMap->Felica.PadByteFlag =FALSE;
- NdefMap->Felica.Wr_BytesRemained = 0;
- }
- }/* if ( (NdefMap->ApduBufferSize - NdefMap->ApduBuffIndex) >= (uint32_t)(16* NdefMap->FelicaAttrInfo.Nbw )) */
- else
- {
- /*chk eof reached*/
- if ( NdefMap->Felica.EofCardReachedFlag)
- {
- BlkNo =((uint8_t)(BytesRemainedInCard )/16);
- if(((uint8_t)( BytesRemainedInCard )%16) != 0)
- {
- BlkNo++;
- PadBytes = ((BlkNo * 16) - (uint8_t)(BytesRemainedInCard ));
- NdefMap->Felica.PadByteFlag = TRUE;
- }
- }
- else
- {
-
- BlkNo =((uint8_t)( NdefMap->ApduBufferSize - NdefMap->ApduBuffIndex)/16);
- if(((uint8_t)( NdefMap->ApduBufferSize - NdefMap->ApduBuffIndex)%16) != 0)
- {
- BlkNo++;
- PadBytes = (BlkNo * 16) - (uint8_t)( NdefMap->ApduBufferSize - NdefMap->ApduBuffIndex);
- NdefMap->Felica.PadByteFlag = TRUE;
-
- }
-
-
- }
-
- /* update the number of blocks to write with the block list elements*/
- /* Total Number of blocks to write*/
- NdefMap->SendRecvBuf[BufIndex] = BlkNo;
- BufIndex++;
-
- NdefMap->Felica.NoBlocksWritten = BlkNo;
-
- /* Block List for NBw : 1st byte : two byte len list: 2nd byte is the block number*/
- for ( i=0; i< BlkNo; i++)
- {
- NdefMap->SendRecvBuf[BufIndex] = 0x80;
- BufIndex++;
- {
- CurBlk = NdefMap->Felica.CurBlockNo +1;
- NdefMap->SendRecvBuf[BufIndex] = CurBlk + i;
- BufIndex++;
- }
- }
- if ( NdefMap->Felica.EofCardReachedFlag )
- {
- /*Copy last data to the trx buffer*/
- (void)memcpy((&(NdefMap->SendRecvBuf[BufIndex])),
- (&(NdefMap->ApduBuffer[NdefMap->ApduBuffIndex])),
- BytesRemainedInCard );
-
- /* increment the bufindex and bytes written*/
- BufIndex += (uint8_t )BytesRemainedInCard ;
- NdefMap->NumOfBytesWritten = (uint16_t)BytesRemainedInCard ;
- }
- else
- {
- /*Copy data to the trx buffer*/
- (void)memcpy((&(NdefMap->SendRecvBuf[BufIndex])),
- (&(NdefMap->ApduBuffer[NdefMap->ApduBuffIndex])),
- (NdefMap->ApduBufferSize - NdefMap->ApduBuffIndex));
-
- /* increment the bufindex and bytes written*/
- BufIndex += (uint8_t)(NdefMap->ApduBufferSize - NdefMap->ApduBuffIndex);
- NdefMap->NumOfBytesWritten = (uint8_t)(NdefMap->ApduBufferSize - NdefMap->ApduBuffIndex);
- }
- if ( PadBytes )
- {
- for(i= 0; i< PadBytes; i++)
- {
- NdefMap->SendRecvBuf[BufIndex] =0x00;
- BufIndex++;
- }
- /*no of bytes remained copy*/
- NdefMap->Felica.Wr_BytesRemained = (uint8_t)(16 - PadBytes);
-
- if ( NdefMap->Felica.EofCardReachedFlag )
- {
- /*copy the data to internal buffer : Bytes remained*/
- (void)memcpy(NdefMap->Felica.Wr_RemainedBytesBuff,
- (&(NdefMap->ApduBuffer[((BytesRemainedInCard - (BytesRemainedInCard % 16)))])),
- ( NdefMap->Felica.Wr_BytesRemained));
-
- }
- else
- {
- /*copy the data to internal buffer : Bytes remained*/
- (void)memcpy( NdefMap->Felica.Wr_RemainedBytesBuff,
- (&(NdefMap->ApduBuffer[((NdefMap->ApduBufferSize - NdefMap->Felica.Wr_BytesRemained))])),
- ( NdefMap->Felica.Wr_BytesRemained));
-
- }
- }/*if ( PadBytes )*/
- else
- {
- NdefMap->Felica.Wr_BytesRemained = 0;
- NdefMap->Felica.PadByteFlag = FALSE;
- }
- /* update the pkt len*/
- NdefMap->SendRecvBuf[PH_NFCFRI_NDEFMAP_FELI_PKT_LEN_INDEX] = BufIndex;
- NdefMap->SendLength = BufIndex;
- }
- }/* else of if ( (NdefMap->ApduBufferSize - NdefMap->ApduBuffIndex) >= (uint32_t)(16* NdefMap->FelicaAttrInfo.Nbw )) */
- status = phFriNfc_Felica_HWriteDataBlk(NdefMap);
- }
- else
- {
- /*0 represents the write operation ended*/
- status = phFriNfc_Felica_HUpdateAttrBlkForWrOp(NdefMap,FELICA_WRITE_ENDED);
- }
- return (status);
-}
-
-
-/*!
- * \brief Used in Write Opearation.
- * This function prepares and sends transcc Cmd Pkt.
- */
-
-static NFCSTATUS phFriNfc_Felica_HWriteDataBlk(phFriNfc_NdefMap_t *NdefMap)
-{
- NFCSTATUS status = NFCSTATUS_PENDING;
-
- /*set the additional informations for the data exchange*/
- NdefMap->psDepAdditionalInfo.DepFlags.MetaChaining = 0;
- NdefMap->psDepAdditionalInfo.DepFlags.NADPresent = 0;
-
- /*Set the ISO14434 command*/
-#ifdef PH_HAL4_ENABLE
- NdefMap->Cmd.FelCmd = (phNfc_eFelicaCmdList_t)phHal_eFelica_Raw;
-#else
- NdefMap->Cmd.FelCmd = phHal_eFelicaCmdListFelicaCmd;
-#endif /* #ifdef PH_HAL4_ENABLE */
-
- /* set the state*/
- NdefMap->State = PH_NFCFRI_NDEFMAP_FELI_STATE_WR_BLOCK;
-
- /* set send receive length*/
- *NdefMap->SendRecvLength = NdefMap->TempReceiveLength;
-
- /*Call the Overlapped HAL Transceive function */
- status = phFriNfc_OvrHal_Transceive( NdefMap->LowerDevice,
- &NdefMap->MapCompletionInfo,
- NdefMap->psRemoteDevInfo,
- NdefMap->Cmd,
- &NdefMap->psDepAdditionalInfo,
- NdefMap->SendRecvBuf,
- NdefMap->SendLength,
- NdefMap->SendRecvBuf,
- NdefMap->SendRecvLength);
- return (status);
-}
-
-/*!
- * \brief Check whether a particular Remote Device is NDEF compliant.
- * The function checks whether the peer device is NDEF compliant.
- */
-
-NFCSTATUS phFriNfc_Felica_ChkNdef( phFriNfc_NdefMap_t *NdefMap)
-{
- NFCSTATUS status = NFCSTATUS_PENDING;
- uint8_t sysCode[2];
-
- /* set the system code for selecting the wild card*/
- sysCode[0] = 0x12;
- sysCode[1] = 0xFC;
-
- status = phFriNfc_Felica_HPollCard( NdefMap,sysCode,PH_NFCFRI_NDEFMAP_FELI_STATE_SELECT_NDEF_APP);
-
- return (status);
-
-}
-/*!
- * \brief Check whether a particular Remote Device is NDEF compliant.
- * selects the sysCode and then NFC Forum Reference Applications
- */
-#ifdef PH_HAL4_ENABLE
-static NFCSTATUS phFriNfc_Felica_HPollCard( phFriNfc_NdefMap_t *NdefMap,
- const uint8_t sysCode[],
- uint8_t state)
-{
- NFCSTATUS status = NFCSTATUS_PENDING;
-
- /*Format the Poll Packet for selecting the system code passed as parameter */
- NdefMap->SendRecvBuf[0] = 0x06;
- NdefMap->SendRecvBuf[1] = 0x00;
- NdefMap->SendRecvBuf[2] = sysCode[0];
- NdefMap->SendRecvBuf[3] = sysCode[1];
- NdefMap->SendRecvBuf[4] = 0x01;
- NdefMap->SendRecvBuf[5] = 0x03;
-
- NdefMap->SendLength = 6;
-
- /*set the completion routines for the felica card operations*/
- NdefMap->MapCompletionInfo.CompletionRoutine = phFriNfc_Felica_Process;
- NdefMap->MapCompletionInfo.Context = NdefMap;
-
- /*Set Ndef State*/
- NdefMap->State = state;
-
- /* set the felica cmd */
- NdefMap->Cmd.FelCmd = (phNfc_eFelicaCmdList_t)phHal_eFelica_Raw;
-
- /*set the additional informations for the data exchange*/
- NdefMap->psDepAdditionalInfo.DepFlags.MetaChaining = 0;
- NdefMap->psDepAdditionalInfo.DepFlags.NADPresent = 0;
-
- status = phFriNfc_OvrHal_Transceive(NdefMap->LowerDevice,
- &NdefMap->MapCompletionInfo,
- NdefMap->psRemoteDevInfo,
- NdefMap->Cmd,
- &NdefMap->psDepAdditionalInfo,
- NdefMap->SendRecvBuf,
- NdefMap->SendLength,
- NdefMap->SendRecvBuf,
- NdefMap->SendRecvLength);
- return (status);
-}
-#endif
-
-
-#ifndef PH_HAL4_ENABLE
-static NFCSTATUS phFriNfc_Felica_HPollCard( phFriNfc_NdefMap_t *NdefMap,
- const uint8_t sysCode[],
- uint8_t state)
-{
- NFCSTATUS status = NFCSTATUS_PENDING;
-
- /*Format the Poll Packet for selecting the wild card "0xff 0xff as system code*/
- NdefMap->FelicaPollDetails.DevInputParam->FelicaPollPayload[0] = 0x00;
- NdefMap->FelicaPollDetails.DevInputParam->FelicaPollPayload[1] = sysCode[0];
- NdefMap->FelicaPollDetails.DevInputParam->FelicaPollPayload[2] = sysCode[1];
- NdefMap->FelicaPollDetails.DevInputParam->FelicaPollPayload[3] = 0x01;
- NdefMap->FelicaPollDetails.DevInputParam->FelicaPollPayload[4] = 0x03;
-
- /* set the length to zero*/
- NdefMap->FelicaPollDetails.DevInputParam->GeneralByteLength =0x00;
-
- NdefMap->NoOfDevices = PH_FRINFC_NDEFMAP_FELI_NUM_DEVICE_TO_DETECT;
-
- /*set the completion routines for the felica card operations*/
- NdefMap->MapCompletionInfo.CompletionRoutine = phFriNfc_Felica_Process;
- NdefMap->MapCompletionInfo.Context = NdefMap;
-
- /*Set Ndef State*/
- NdefMap->State = state;
-
- /* Harsha: This is a special case for felica.
- Make a copy of the remote device information and send it for
- polling. Return the original remote device information to the
- caller. The user does not need the updated results of the poll
- that we are going to call now. This is only used for checking
- whether the felica card is NDEF compliant or not. */
- (void) memcpy( &NdefMap->FelicaPollDetails.psTempRemoteDevInfo,
- NdefMap->psRemoteDevInfo,
- sizeof(phHal_sRemoteDevInformation_t));
-
- /* Reset the session opened flag */
- NdefMap->FelicaPollDetails.psTempRemoteDevInfo.SessionOpened = 0x00;
-
- /*Call the Overlapped HAL POLL function */
- status = phFriNfc_OvrHal_Poll( NdefMap->LowerDevice,
- &NdefMap->MapCompletionInfo,
- NdefMap->OpModeType,
- &NdefMap->FelicaPollDetails.psTempRemoteDevInfo,
- &NdefMap->NoOfDevices,
- NdefMap->FelicaPollDetails.DevInputParam);
-
- return (status);
-}
-#endif /* #ifndef PH_HAL4_ENABLE */
-/*!
- * \brief Checks validity of system code sent from the lower device, during poll operation.
- */
-
-static NFCSTATUS phFriNfc_Felica_HUpdateManufIdDetails(const phFriNfc_NdefMap_t *NdefMap)
-{
- NFCSTATUS status = NFCSTATUS_PENDING;
-
- /* Get the details from Poll Response packet */
- if (NdefMap->SendRecvLength >= (uint16_t*)20)
- {
- (void)memcpy( (uint8_t *)NdefMap->psRemoteDevInfo->RemoteDevInfo.Felica_Info.IDm,
- (uint8_t *)&NdefMap->SendRecvBuf[2], 8);
- (void)memcpy( (uint8_t *)NdefMap->psRemoteDevInfo->RemoteDevInfo.Felica_Info.PMm,
- (uint8_t *)&NdefMap->SendRecvBuf[10], 8);
- NdefMap->psRemoteDevInfo->RemoteDevInfo.Felica_Info.SystemCode[1] = NdefMap->SendRecvBuf[18];
- NdefMap->psRemoteDevInfo->RemoteDevInfo.Felica_Info.SystemCode[0] = NdefMap->SendRecvBuf[19];
- NdefMap->psRemoteDevInfo->RemoteDevInfo.Felica_Info.IDmLength = 8;
-
- /* copy the IDm and PMm in Manufacture Details Structure*/
- (void)memcpy( (uint8_t *)(NdefMap->FelicaManufDetails.ManufID),
- (uint8_t *)NdefMap->psRemoteDevInfo->RemoteDevInfo.Felica_Info.IDm,
- 8);
- (void)memcpy( (uint8_t *)(NdefMap->FelicaManufDetails.ManufParameter),
- (uint8_t *)NdefMap->psRemoteDevInfo->RemoteDevInfo.Felica_Info.PMm,
- 8);
- if((NdefMap->psRemoteDevInfo->RemoteDevInfo.Felica_Info.SystemCode[1] == 0x12)
- && (NdefMap->psRemoteDevInfo->RemoteDevInfo.Felica_Info.SystemCode[0] == 0xFC))
- {
- status = PHNFCSTVAL(CID_NFC_NONE, NFCSTATUS_SUCCESS);
- }
- else
- {
- status = PHNFCSTVAL(CID_FRI_NFC_NDEF_MAP,
- NFCSTATUS_NO_NDEF_SUPPORT);
- }
- }
- else
- {
- status = PHNFCSTVAL(CID_FRI_NFC_NDEF_MAP,
- NFCSTATUS_NO_NDEF_SUPPORT);
- }
-
- return (status);
-}
-
-
-/*!
- * \brief Completion Routine, Processing function, needed to avoid long blocking.
- * \note The lower (Overlapped HAL) layer must register a pointer to this function as a Completion
- * Routine in order to be able to notify the component that an I/O has finished and data are
- * ready to be processed.
- */
-
-void phFriNfc_Felica_Process(void *Context,
- NFCSTATUS Status)
-{
- uint8_t CRFlag = FALSE;
- uint16_t RecvTxLen = 0,
- BytesToRecv = 0,
- Nbc = 0;
- uint32_t TotNoWrittenBytes = 0,
- NDEFLen=0;
-
- /*Set the context to Map Module*/
- phFriNfc_NdefMap_t *NdefMap = (phFriNfc_NdefMap_t *)Context;
-
- if ( Status == NFCSTATUS_SUCCESS )
- {
- switch (NdefMap->State)
- {
- case PH_NFCFRI_NDEFMAP_FELI_STATE_SELECT_NDEF_APP:
-
- /* check the ndef compliency with the system code reecived in the RemoteDevInfo*/
- Status = phFriNfc_Felica_HUpdateManufIdDetails(NdefMap);
-
- if (Status == NFCSTATUS_SUCCESS)
- {
- /* Mantis ID : 645*/
- /* set the operation type to Check ndef type*/
- NdefMap->Felica.OpFlag = PH_FRINFC_NDEFMAP_FELI_CHK_NDEF_OP;
- Status = phFriNfc_Felica_HRdAttrInfo(NdefMap);
- /* handle the error in Transc function*/
- if ( (Status & PHNFCSTBLOWER) != (NFCSTATUS_PENDING & PHNFCSTBLOWER))
- {
- CRFlag = TRUE;
- }
- }
- else
- {
- CRFlag = TRUE;
- }
- if ( CRFlag == TRUE )
- {
- /* call respective CR */
- phFriNfc_Felica_HCrHandler(NdefMap,PH_FRINFC_NDEFMAP_CR_CHK_NDEF,Status);
-
- }
- break;
-
- case PH_NFCFRI_NDEFMAP_FELI_STATE_RD_ATTR:
- /* check for the status flag1 and status flag2for the successful read operation*/
- if ( NdefMap->SendRecvBuf[10] == 0x00)
- {
- /* check the Manuf Id in the receive buffer*/
- Status = phFriNfc_Felica_HCheckManufId(NdefMap);
- if ( Status == NFCSTATUS_SUCCESS)
- {
- /* Update the Attribute Information in to the context structure*/
- Status = phFriNfc_Felica_HUpdateAttrInfo(NdefMap);
- if ( Status == NFCSTATUS_SUCCESS )
- {
- PH_NFCFRI_NDEFMAP_FELI_CAL_LEN_BYTES(NdefMap->FelicaAttrInfo.LenBytes[0],
- NdefMap->FelicaAttrInfo.LenBytes[1],
- NdefMap->FelicaAttrInfo.LenBytes[2],
- NDEFLen);
-
- if ( NdefMap->Felica.OpFlag == PH_FRINFC_NDEFMAP_FELI_WR_ATTR_RD_OP )
- {
- /* Proceed With Write Functinality*/
- Status = phFriNfc_Felica_HChkAttrBlkForWrOp(NdefMap);
- /* handle the error in Transc function*/
- if ( (Status & PHNFCSTBLOWER) != (NFCSTATUS_PENDING & PHNFCSTBLOWER))
- {
- /* call respective CR */
- phFriNfc_Felica_HCrHandler(NdefMap,PH_FRINFC_NDEFMAP_CR_WR_NDEF,Status);
- }
- }
- else if( NdefMap->Felica.OpFlag == PH_FRINFC_NDEFMAP_FELI_RD_ATTR_RD_OP )
- {
- /* Proceed With Read Functinality*/
- Status = phFriNfc_Felica_HChkAttrBlkForRdOp(NdefMap,NDEFLen);
- if ( (Status & PHNFCSTBLOWER) != (NFCSTATUS_PENDING & PHNFCSTBLOWER))
- {
- /* call respective CR */
- phFriNfc_Felica_HCrHandler(NdefMap,PH_FRINFC_NDEFMAP_CR_RD_NDEF,Status);
- }
- }
- else if( NdefMap->Felica.OpFlag == PH_FRINFC_NDEFMAP_FELI_CHK_NDEF_OP )
- {
-
- Status = phFriNfc_MapTool_SetCardState( NdefMap,
- NDEFLen);
- /* check status value*/
- NdefMap->CardType = PH_FRINFC_NDEFMAP_FELICA_SMART_CARD;
- /*reset the buffer index*/
- NdefMap->ApduBuffIndex = 0;
- /* set the Next operation Flag to indicate need of reading attribute information*/
- NdefMap->Felica.OpFlag = PH_FRINFC_NDEFMAP_FELI_OP_NONE;
- /* call respective CR */
- phFriNfc_Felica_HCrHandler(NdefMap,PH_FRINFC_NDEFMAP_CR_CHK_NDEF,Status);
- }
- else if ( NdefMap->Felica.OpFlag == PH_FRINFC_NDEFMAP_FELI_WR_EMPTY_MSG_OP )
- {
- /* Proceed With Write Functinality*/
- Status = phFriNfc_Felica_HWrEmptyMsg(NdefMap);
- /* handle the error in Transc function*/
- if ( (Status & PHNFCSTBLOWER) != (NFCSTATUS_PENDING & PHNFCSTBLOWER))
- {
- /* call respective CR */
- phFriNfc_Felica_HCrHandler(NdefMap,PH_FRINFC_NDEFMAP_CR_ERASE_NDEF,Status);
- }
- }
- else
- {
-
- /* invalid operation occured*/
- Status = PHNFCSTVAL(CID_FRI_NFC_NDEF_MAP,\
- NFCSTATUS_INVALID_DEVICE_REQUEST);
- CRFlag =TRUE ;
- }
- }
- else
- {
- CRFlag =TRUE ;
- }
- }
- else
- {
- CRFlag =TRUE ;
- }
- }
- else
- {
- CRFlag =TRUE;
- /*handle the Error case*/
- Status = PHNFCSTVAL(CID_FRI_NFC_NDEF_MAP,\
- NFCSTATUS_READ_FAILED);
- }
- if ( CRFlag == TRUE )
- {
- /* call respective CR */
- phFriNfc_Felica_HCrHandler(NdefMap,PH_FRINFC_NDEFMAP_CR_RD_NDEF,Status);
- }
- break;
-
- case PH_NFCFRI_NDEFMAP_FELI_STATE_ATTR_BLK_WR_BEGIN:
- /* chk the status flags 1 and 2*/
- if ( NdefMap->SendRecvBuf[10] == 0x00 )
- {
- /* Update Data Call*/
- Status =phFriNfc_Felica_HUpdateData(NdefMap);
- if ( (Status & PHNFCSTBLOWER) != (NFCSTATUS_PENDING & PHNFCSTBLOWER))
- {
- /* call respective CR */
- phFriNfc_Felica_HCrHandler(NdefMap,PH_FRINFC_NDEFMAP_CR_WR_NDEF,Status);
- }
- }
- else
- {
- /*handle the Error case*/
- Status = PHNFCSTVAL(CID_FRI_NFC_NDEF_MAP,\
- NFCSTATUS_WRITE_FAILED);
- phFriNfc_Felica_HCrHandler(NdefMap,PH_FRINFC_NDEFMAP_CR_WR_NDEF,Status);
-
- }
- break;
- case PH_NFCFRI_NDEFMAP_FELI_STATE_ATTR_BLK_WR_END:
-
- /* chk the status flags 1 and 2*/
- if ( NdefMap->SendRecvBuf[10] == 0x00)
- {
- /* Entire Write Operation is complete*/
- Status = PHNFCSTVAL(CID_NFC_NONE,\
- NFCSTATUS_SUCCESS);
- }
- else
- {
- /*handle the Error case*/
- Status = PHNFCSTVAL(CID_FRI_NFC_NDEF_MAP,\
- NFCSTATUS_WRITE_FAILED);
- }
- phFriNfc_Felica_HCrHandler(NdefMap,PH_FRINFC_NDEFMAP_CR_WR_NDEF,Status);
- break;
-
- case PH_NFCFRI_NDEFMAP_FELI_STATE_WR_EMPTY_MSG :
-
- /* chk the status flags 1 and 2*/
- if ( NdefMap->SendRecvBuf[10] == 0x00)
- {
- /* Entire Write Operation is complete*/
- Status = PHNFCSTVAL(CID_NFC_NONE,\
- NFCSTATUS_SUCCESS);
- }
- else
- {
- /*handle the Error case*/
- Status = PHNFCSTVAL(CID_FRI_NFC_NDEF_MAP,\
- NFCSTATUS_WRITE_FAILED);
- }
- phFriNfc_Felica_HCrHandler(NdefMap,PH_FRINFC_NDEFMAP_CR_WR_NDEF,Status);
- break;
-
- case PH_NFCFRI_NDEFMAP_FELI_STATE_WR_BLOCK :
- if(NdefMap->SendRecvBuf[1] == PH_NFCFRI_NDEFMAP_FELI_WR_RESP_BYTE )
- {
- /* chk the status flags 1 and 2*/
- if ( NdefMap->SendRecvBuf[10] == 0x00 )
- {
- /* This is used when we have bytes less than 16 bytes*/
- if ( NdefMap->Felica.IntermediateWrFlag == TRUE )
- {
- /* after Successful write copy the last writtened bytes back to the
- internal buffer*/
- (void)memcpy( (&(NdefMap->Felica.Wr_RemainedBytesBuff[NdefMap->Felica.Wr_BytesRemained])),
- NdefMap->ApduBuffer,
- NdefMap->NumOfBytesWritten);
-
- NdefMap->Felica.Wr_BytesRemained +=
- (uint8_t)( NdefMap->NumOfBytesWritten);
-
- /* Increment the Send Buffer index */
- NdefMap->ApduBuffIndex +=
- NdefMap->NumOfBytesWritten;
-
- *NdefMap->WrNdefPacketLength = NdefMap->ApduBuffIndex;
- NdefMap->Felica.IntermediateWrFlag = FALSE;
- /* Call Update Data()*/
- Status = phFriNfc_Felica_HUpdateData(NdefMap);
- }
- else
- {
- /* update the index and bytes writtened*/
- NdefMap->ApduBuffIndex += NdefMap->NumOfBytesWritten;
- *NdefMap->WrNdefPacketLength = NdefMap->ApduBuffIndex;
- if ( NdefMap->Felica.EofCardReachedFlag )
- {
- if ( NdefMap->Felica.CurBlockNo < NdefMap->FelicaAttrInfo.Nmaxb)
- {
- NdefMap->Felica.CurBlockNo += NdefMap->Felica.NoBlocksWritten;
- }
- if (( NdefMap->Felica.CurBlockNo == NdefMap->FelicaAttrInfo.Nmaxb) &&
- ( NdefMap->ApduBuffIndex == (NdefMap->FelicaAttrInfo.Nmaxb*16)))
- {
- NdefMap->Felica.EofCardReachedFlag = FELICA_RD_WR_EOF_CARD_REACHED ;
- /*0 represents the write ended*/
- Status = phFriNfc_Felica_HUpdateAttrBlkForWrOp(NdefMap,FELICA_WRITE_ENDED);
- if( (Status & PHNFCSTBLOWER) != (NFCSTATUS_PENDING & PHNFCSTBLOWER))
- {
- /* call respective CR */
- phFriNfc_Felica_HCrHandler(NdefMap,PH_FRINFC_NDEFMAP_CR_WR_NDEF,Status);
- }
- }
- else
- {
- PH_NFCFRI_NDEFMAP_FELI_CAL_LEN_BYTES(NdefMap->FelicaAttrInfo.LenBytes[0],
- NdefMap->FelicaAttrInfo.LenBytes[1],
- NdefMap->FelicaAttrInfo.LenBytes[2],
- TotNoWrittenBytes);
- if ( ( NdefMap->Felica.CurBlockNo == NdefMap->FelicaAttrInfo.Nmaxb) &&
- ((TotNoWrittenBytes + NdefMap->ApduBuffIndex) == (uint32_t)(NdefMap->FelicaAttrInfo.Nmaxb*16)))
- {
- NdefMap->Felica.EofCardReachedFlag =FELICA_RD_WR_EOF_CARD_REACHED;
- /*0 represents the write ended*/
- Status = phFriNfc_Felica_HUpdateAttrBlkForWrOp(NdefMap,FELICA_WRITE_ENDED);
- if ( (Status & PHNFCSTBLOWER) != (NFCSTATUS_PENDING & PHNFCSTBLOWER))
- {
- /* call respective CR */
- phFriNfc_Felica_HCrHandler(NdefMap,PH_FRINFC_NDEFMAP_CR_WR_NDEF,Status);
- }
- }
- else
- {
- /* Call Update Data()*/
- Status = phFriNfc_Felica_HUpdateData(NdefMap);
- if ( (Status & PHNFCSTBLOWER) != (NFCSTATUS_PENDING & PHNFCSTBLOWER))
- {
- /* call respective CR */
- phFriNfc_Felica_HCrHandler(NdefMap,PH_FRINFC_NDEFMAP_CR_WR_NDEF,Status);
- }
- }
- }
- }/*if ( NdefMap->Felica.EofCardReachedFlag )*/
- else
- {
- NdefMap->Felica.CurBlockNo += NdefMap->Felica.NoBlocksWritten;
- /* Call Update Data()*/
- Status = phFriNfc_Felica_HUpdateData(NdefMap);
- if ( (Status & PHNFCSTBLOWER) != (NFCSTATUS_PENDING & PHNFCSTBLOWER))
- {
- /* call respective CR */
- phFriNfc_Felica_HCrHandler(NdefMap,PH_FRINFC_NDEFMAP_CR_WR_NDEF,Status);
- }
- }
- }
- }/*if ( NdefMap->SendRecvBuf[10] == 0x00 )*/
- else
- {
- /*handle the Error case*/
- Status = PHNFCSTVAL(CID_FRI_NFC_NDEF_MAP,\
- NFCSTATUS_WRITE_FAILED);
- CRFlag = TRUE;
-
- }
- }/*if(NdefMap->SendRecvBuf[1] == PH_NFCFRI_NDEFMAP_FELI_WR_RESP_BYTE )*/
- else
- {
- /*return Error "Invalid Write Response Code"*/
- Status = PHNFCSTVAL(CID_FRI_NFC_NDEF_MAP,
- NFCSTATUS_WRITE_FAILED);
- CRFlag = TRUE;
-
- }
- if ( CRFlag == TRUE )
- {
- /* Reset following parameters*/
- NdefMap->ApduBuffIndex=0;
- NdefMap->Felica.Wr_BytesRemained = 0;
- NdefMap->ApduBufferSize = 0;
- phFriNfc_Felica_HCrHandler(NdefMap,PH_FRINFC_NDEFMAP_CR_WR_NDEF,Status);
- }
-
- break;
-
- case PH_NFCFRI_NDEFMAP_FELI_STATE_RD_BLOCK :
-
- /* check the Manuf Id in the receive buffer*/
- Status = phFriNfc_Felica_HCheckManufId(NdefMap);
- if ( Status == NFCSTATUS_SUCCESS )
- {
- if(NdefMap->SendRecvBuf[1] == PH_NFCFRI_NDEFMAP_FELI_RD_RESP_BYTE )
- {
- /* calculate the Nmaxb*/
- Nbc = phFriNfc_Felica_HGetMaximumBlksToRead(NdefMap,PH_NFCFRI_NDEFMAP_FELI_NBC);
- /*get Receive length from the card for corss verifications*/
- RecvTxLen= phFriNfc_Felica_HSetTrxLen(NdefMap,Nbc);
- BytesToRecv = NdefMap->SendRecvBuf[12]*16;
-
- /* chk the status flags 1 */
- if ( NdefMap->SendRecvBuf[10] == 0x00)
- {
- if ( RecvTxLen == BytesToRecv)
- {
- NdefMap->Felica.CurBlockNo += (uint8_t)(RecvTxLen/16);
- phFriNfc_Felica_HAfterRead_CopyDataToBuff(NdefMap);
- Status = phFriNfc_Felica_HReadData(NdefMap,PH_FRINFC_NDEFMAP_SEEK_CUR);
- /* handle the error in Transc function*/
- if ( (Status & PHNFCSTBLOWER) != (NFCSTATUS_PENDING & PHNFCSTBLOWER))
- {
- CRFlag =TRUE;
- }
- }
- else
- {
- CRFlag =TRUE;
- Status = PHNFCSTVAL(CID_FRI_NFC_NDEF_MAP,
- NFCSTATUS_INVALID_RECEIVE_LENGTH);
- /*set the buffer index back to zero*/
- NdefMap->ApduBuffIndex = 0;
- NdefMap->Felica.Rd_NoBytesToCopy = 0;
- }
- }
- else
- {
- NdefMap->ApduBuffIndex=0;
- /*handle the Error case*/
- Status = PHNFCSTVAL(CID_FRI_NFC_NDEF_MAP,\
- NFCSTATUS_READ_FAILED);
- CRFlag =TRUE;
- }
- }
- else
- {
- CRFlag =TRUE;
- NdefMap->ApduBuffIndex=0;
- /*return Error "Invalid Read Response Code"*/
- Status = PHNFCSTVAL(CID_FRI_NFC_NDEF_MAP,
- NFCSTATUS_READ_FAILED);
- }
- }
- else
- {
- CRFlag =TRUE;
- }
- if ( CRFlag ==TRUE )
- {
- /* call respective CR */
- phFriNfc_Felica_HCrHandler(NdefMap,PH_FRINFC_NDEFMAP_CR_RD_NDEF,Status);
- }
- break;
-
- default:
- Status = PHNFCSTVAL(CID_FRI_NFC_NDEF_MAP,
- NFCSTATUS_INVALID_DEVICE_REQUEST);
- phFriNfc_Felica_HCrHandler(NdefMap, PH_FRINFC_NDEFMAP_CR_INVALID_OPE, Status);
- break;
-
-
- }
- }
- else
- {
- /* Call CR for unknown Error's*/
- switch ( NdefMap->State)
- {
- case PH_FRINFC_NDEFMAP_FELI_STATE_CHK_NDEF :
- case PH_NFCFRI_NDEFMAP_FELI_STATE_SELECT_WILD_CARD :
- case PH_NFCFRI_NDEFMAP_FELI_STATE_SELECT_NDEF_APP :
- case PH_NFCFRI_NDEFMAP_FELI_STATE_RD_ATTR :
- phFriNfc_Felica_HCrHandler(NdefMap, PH_FRINFC_NDEFMAP_CR_CHK_NDEF,
- Status);
- break;
- case PH_NFCFRI_NDEFMAP_FELI_STATE_WR_BLOCK :
- case PH_NFCFRI_NDEFMAP_FELI_STATE_ATTR_BLK_WR_BEGIN :
- case PH_NFCFRI_NDEFMAP_FELI_STATE_ATTR_BLK_WR_END :
- phFriNfc_Felica_HCrHandler(NdefMap, PH_FRINFC_NDEFMAP_CR_WR_NDEF,
- Status);
- break;
- case PH_NFCFRI_NDEFMAP_FELI_STATE_RD_BLOCK :
- phFriNfc_Felica_HCrHandler(NdefMap, PH_FRINFC_NDEFMAP_CR_RD_NDEF,
- Status);
- break;
- default :
- /*set the invalid state*/
- Status = PHNFCSTVAL(CID_FRI_NFC_NDEF_MAP, NFCSTATUS_INVALID_DEVICE_REQUEST);
- phFriNfc_Felica_HCrHandler(NdefMap, PH_FRINFC_NDEFMAP_CR_INVALID_OPE, Status);
- break;
- }
- }
-
-}
-
-/*!
- * \brief Prepares Cmd Pkt for reading attribute Blk information.
- */
-static NFCSTATUS phFriNfc_Felica_HRdAttrInfo(phFriNfc_NdefMap_t *NdefMap)
-{
-
- NFCSTATUS status = NFCSTATUS_PENDING;
- uint8_t BufIndex = 0;
-
- /* Set the Felica Cmd*/
-#ifdef PH_HAL4_ENABLE
- NdefMap->Cmd.FelCmd = (phNfc_eFelicaCmdList_t)phHal_eFelica_Raw;
-#else
- NdefMap->Cmd.FelCmd = phHal_eFelicaCmdListFelicaCmd;
-#endif /* #ifdef PH_HAL4_ENABLE */
-
- /*set the additional informations for the data exchange*/
- NdefMap->psDepAdditionalInfo.DepFlags.MetaChaining = 0;
- NdefMap->psDepAdditionalInfo.DepFlags.NADPresent = 0;
-
- /* 1st byte represents the length of the cmd packet*/
- NdefMap->SendRecvBuf[BufIndex] = 0x00;
- BufIndex++;
-
- /* Read/check command code*/
- NdefMap->SendRecvBuf[BufIndex] = 0x06;
- BufIndex++;
-
- /* IDm - Manufacturer Id : 8bytes*/
-#ifdef PH_HAL4_ENABLE
- (void)memcpy((&(NdefMap->SendRecvBuf[BufIndex])),
- (void * )&NdefMap->psRemoteDevInfo->RemoteDevInfo.Felica_Info.IDm,
- 8);
-#else
- (void)memcpy((&(NdefMap->SendRecvBuf[BufIndex])),
- (void * )&NdefMap->psRemoteDevInfo->RemoteDevInfo.CardInfo212_424.Startup212_424.NFCID2t,
- 8);
-
-#endif /* #ifdef PH_HAL4_ENABLE */
-
- BufIndex+=8;
-
- NdefMap->SendRecvBuf[BufIndex] = 0x01; /* Number of Services (n=1 ==> 0x80)*/
- BufIndex++;
-
- NdefMap->SendRecvBuf[BufIndex] = 0x0B; /* Service Code List*/
- BufIndex++;
-
- NdefMap->SendRecvBuf[BufIndex] = 0x00; /* Service Code List*/
- BufIndex++;
-
- NdefMap->SendRecvBuf[BufIndex] = 0x01; /* Number of Blocks to read)*/
- BufIndex++;
-
- NdefMap->SendRecvBuf[BufIndex] = 0x80; /* 1st Block Element : byte 1*/
- BufIndex++;
-
- NdefMap->SendRecvBuf[BufIndex] = 0x00; /* 1st Block Element : byte 2, block 1*/
- BufIndex++;
-
- NdefMap->SendRecvBuf[PH_NFCFRI_NDEFMAP_FELI_PKT_LEN_INDEX] = BufIndex;
-
- *NdefMap->SendRecvLength = NdefMap->TempReceiveLength;
-
- /* Update the Send Len*/
- NdefMap->SendLength = BufIndex;
-
- /* Change the state to PH_NFCFRI_NDEFMAP_FELI_STATE_RD_ATTR */
- NdefMap->State = PH_NFCFRI_NDEFMAP_FELI_STATE_RD_ATTR;
-
- /*set the completion routines for the desfire card operations*/
- NdefMap->MapCompletionInfo.CompletionRoutine = phFriNfc_NdefMap_Process;
- NdefMap->MapCompletionInfo.Context = NdefMap;
-
- /*Call the Overlapped HAL Transceive function */
- status = phFriNfc_OvrHal_Transceive( NdefMap->LowerDevice,
- &NdefMap->MapCompletionInfo,
- NdefMap->psRemoteDevInfo,
- NdefMap->Cmd,
- &NdefMap->psDepAdditionalInfo,
- NdefMap->SendRecvBuf,
- NdefMap->SendLength,
- NdefMap->SendRecvBuf,
- NdefMap->SendRecvLength);
- return (status);
-
-}
-
-/*!
- * \brief Validated manufacturer Details, during the read/write operations.
- */
-
-static NFCSTATUS phFriNfc_Felica_HCheckManufId(const phFriNfc_NdefMap_t *NdefMap)
-{
- NFCSTATUS status = NFCSTATUS_PENDING;
-
- uint8_t result = 0;
-
- /* check the stored manufacture id with the received manufacture id*/
- result = (uint8_t)(phFriNfc_Felica_MemCompare( (void *)(&(NdefMap->SendRecvBuf[2])),
- (void *)NdefMap->FelicaManufDetails.ManufID,
- 8));
-
- if ( result != 0)
- {
- status = PHNFCSTVAL(CID_FRI_NFC_NDEF_MAP, NFCSTATUS_INVALID_REMOTE_DEVICE);
-
- }
- else
- {
- status = PHNFCSTVAL(CID_NFC_NONE,NFCSTATUS_SUCCESS);
-
- }
- return (status);
-}
-
-static NFCSTATUS phFriNfc_Felica_HCalCheckSum(const uint8_t *TempBuffer,
- uint8_t StartIndex,
- uint8_t EndIndex,
- uint16_t RecvChkSum)
-{
- NFCSTATUS Result = NFCSTATUS_SUCCESS;
- uint16_t CheckSum=0,
- BufIndex=0;
-
- for(BufIndex = StartIndex;BufIndex <=EndIndex;BufIndex++)
- {
- CheckSum += TempBuffer[BufIndex];
- }
- if( RecvChkSum != CheckSum )
- {
- Result = PHNFCSTVAL(CID_FRI_NFC_NDEF_MAP,
- NFCSTATUS_INVALID_FORMAT);
- }
- return (Result);
-}
-
-
-
-
-
-
-
-
-
-
-
-/*!
- * \brief On successful read attribute blk information, this function validates and stores the
- * Attribute informations in to the context.
- */
-static NFCSTATUS phFriNfc_Felica_HUpdateAttrInfo(phFriNfc_NdefMap_t *NdefMap)
-{
- NFCSTATUS status = NFCSTATUS_PENDING;
- uint8_t CRFlag = FALSE,
- Nmaxb1, Nmaxb2 = 0,
- ChkSum1 = 0, ChkSum2=0;
-
- uint16_t Nmaxblk = 0,
- RecvChkSum=0,
- NdefBlk = 0;
- uint32_t DataLen =0;
-
-
- /* Validate T3VNo and NFCDevVNo */
- status = phFriNfc_MapTool_ChkSpcVer(NdefMap,
- PH_NFCFRI_NDEFMAP_FELI_VERSION_INDEX);
- if ( status != NFCSTATUS_SUCCESS )
- {
- CRFlag = TRUE;
- }
- else
- {
- /* get the Nmaxb from the receive buffer*/
- Nmaxb1 = NdefMap->SendRecvBuf[16];
- Nmaxb2 = NdefMap->SendRecvBuf[17];
-
- Nmaxblk = (((uint16_t)Nmaxb1 << 8) | (Nmaxb2 & 0x00ff));
-
- if ( Nmaxblk != 0 )
- {
- /* check the Nbr against the Nmaxb*/
- if ( NdefMap->SendRecvBuf[14] > Nmaxblk )
- {
- CRFlag = TRUE;
- }
- else
- {
- /*check Nbw > Nmaxb*/
- /*check the write flag validity*/
- /*check for the RFU bytes validity*/
- if ( (NdefMap->SendRecvBuf[15] > Nmaxblk) ||
- ((NdefMap->SendRecvBuf[22] != 0x00) && (NdefMap->SendRecvBuf[22] !=0x0f ))||
- ( (NdefMap->SendRecvBuf[23] != 0x00) && (NdefMap->SendRecvBuf[23] !=0x01 ))||
- ( NdefMap->SendRecvBuf[18] != 0x00) ||
- ( NdefMap->SendRecvBuf[19] != 0x00) ||
- ( NdefMap->SendRecvBuf[20] != 0x00) ||
- ( NdefMap->SendRecvBuf[21] != 0x00))
-
- {
- CRFlag = TRUE;
- }
- else
- {
- /* check the validity of the actual ndef data len*/
- PH_NFCFRI_NDEFMAP_FELI_CAL_LEN_BYTES( NdefMap->SendRecvBuf[24],
- NdefMap->SendRecvBuf[25],
- NdefMap->SendRecvBuf[26],
- DataLen);
-
-
- /* Calculate Nbc*/
- NdefBlk = (uint16_t )((( DataLen % 16) == 0 ) ? (DataLen >> 4) : ((DataLen >> 4) +1));
-
- /* check Nbc against Nmaxb*/
- if ((NdefBlk > Nmaxblk))
- {
- CRFlag = TRUE;
- }
- else
- {
- /*Store the attribute information in phFriNfc_Felica_AttrInfo*/
- NdefMap->FelicaAttrInfo.Version = NdefMap->SendRecvBuf[PH_NFCFRI_NDEFMAP_FELI_VERSION_INDEX];
- NdefMap->FelicaAttrInfo.Nbr = NdefMap->SendRecvBuf[14];
- NdefMap->FelicaAttrInfo.Nbw = NdefMap->SendRecvBuf[15];
-
- NdefMap->FelicaAttrInfo.Nmaxb = Nmaxblk;
-
- NdefMap->FelicaAttrInfo.WriteFlag = NdefMap->SendRecvBuf[22];
- NdefMap->FelicaAttrInfo.RdWrFlag = NdefMap->SendRecvBuf[23];
-
- /* Get CheckSum*/
- ChkSum1 = NdefMap->SendRecvBuf[27];
- ChkSum2 = NdefMap->SendRecvBuf[28];
-
- RecvChkSum = (((uint16_t)ChkSum1 << 8) | (ChkSum2 & 0x00ff));
-
- /* Check the check sum validity?*/
- status = phFriNfc_Felica_HCalCheckSum(NdefMap->SendRecvBuf,
- PH_NFCFRI_NDEFMAP_FELI_VERSION_INDEX,
- 26,
- RecvChkSum);
- if ( status != NFCSTATUS_SUCCESS )
- {
- CRFlag = TRUE;
- }
- else
- {
- /*check RW Flag Access Rights*/
- /* set to read only cannot write*/
- if ( NdefMap->FelicaAttrInfo.RdWrFlag == 0x00 )
- {
- NdefMap->CardState = PH_NDEFMAP_CARD_STATE_READ_ONLY;
- }
- else if ( NdefMap->FelicaAttrInfo.RdWrFlag == 0x01 ) // additional check for R/W access
- {
- NdefMap->CardState = PH_NDEFMAP_CARD_STATE_READ_WRITE;
- }
- else // otherwise invalid
- {
- NdefMap->CardState = PH_NDEFMAP_CARD_STATE_INVALID;
- }
-
- NdefMap->FelicaAttrInfo.LenBytes[0] = NdefMap->SendRecvBuf[24];
- NdefMap->FelicaAttrInfo.LenBytes[1] = NdefMap->SendRecvBuf[25];
- NdefMap->FelicaAttrInfo.LenBytes[2] = NdefMap->SendRecvBuf[26];
- status = PHNFCSTVAL(CID_NFC_NONE,NFCSTATUS_SUCCESS);
- }
- }
- }
- }
- }
- else
- {
- CRFlag = TRUE;
- }
- }
- if ( (status == NFCSTATUS_INVALID_FORMAT ) && (CRFlag == TRUE ))
- {
- NdefMap->CardState = PH_NDEFMAP_CARD_STATE_INVALID;
- }
- if ( CRFlag == TRUE )
- {
- /*Return Status Error “ Invalid Format”*/
- status = PHNFCSTVAL(CID_FRI_NFC_NDEF_MAP,NFCSTATUS_INVALID_FORMAT);
- }
-
- return (status);
-}
-
-/*!
- * \brief this shall notify the integration software with respective
- * success/error status along with the completion routines.
- */
-static void phFriNfc_Felica_HCrHandler(phFriNfc_NdefMap_t *NdefMap,
- uint8_t CrIndex,
- NFCSTATUS Status)
-{
- /* set the state back to the Reset_Init state*/
- NdefMap->State = PH_FRINFC_NDEFMAP_STATE_RESET_INIT;
-
- /* set the completion routine*/
- NdefMap->CompletionRoutine[CrIndex].
- CompletionRoutine(NdefMap->CompletionRoutine->Context, Status);
-}
-
-/*!
- * \brief this shall initialise the internal buffer data to zero.
- */
-static void phFriNfc_Felica_HInitInternalBuf(uint8_t *Buffer)
-{
- uint8_t index=0;
-
- for( index = 0; index< 16 ; index++)
- {
- Buffer[index] = 0;
- }
-}
-
-static int phFriNfc_Felica_MemCompare ( void *s1, void *s2, unsigned int n )
-{
- int8_t diff = 0;
- int8_t *char_1 =(int8_t *)s1;
- int8_t *char_2 =(int8_t *)s2;
- if(NULL == s1 || NULL == s2)
- {
- PHDBG_CRITICAL_ERROR("NULL pointer passed to memcompare");
- }
- else
- {
- for(;((n>0)&&(diff==0));n--,char_1++,char_2++)
- {
- diff = *char_1 - *char_2;
- }
- }
- return (int)diff;
-}
-
-
-#ifdef UNIT_TEST
-#include
-#endif
-
-#endif /* PH_FRINFC_MAP_FELICA_DISABLED */
diff --git a/libnfc-nxp/phFriNfc_FelicaMap.h b/libnfc-nxp/phFriNfc_FelicaMap.h
deleted file mode 100644
index 298ffff..0000000
--- a/libnfc-nxp/phFriNfc_FelicaMap.h
+++ /dev/null
@@ -1,286 +0,0 @@
-/*
- * Copyright (C) 2010 NXP Semiconductors
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-/*!
- * \file phFriNfc_FelicaMap.h
- * \brief NFC Ndef Mapping For Felica Smart Card.
- *
- * Project: NFC-FRI
- *
- * $Date: Wed Apr 8 14:37:05 2009 $
- * $Author: ing02260 $
- * $Revision: 1.4 $
- * $Aliases: NFC_FRI1.1_WK914_R22_1,NFC_FRI1.1_WK914_R22_2,NFC_FRI1.1_WK916_R23_1,NFC_FRI1.1_WK918_R24_1,NFC_FRI1.1_WK920_PREP1,NFC_FRI1.1_WK920_R25_1,NFC_FRI1.1_WK922_PREP1,NFC_FRI1.1_WK922_R26_1,NFC_FRI1.1_WK924_PREP1,NFC_FRI1.1_WK924_R27_1,NFC_FRI1.1_WK926_R28_1,NFC_FRI1.1_WK928_R29_1,NFC_FRI1.1_WK930_R30_1,NFC_FRI1.1_WK934_PREP_1,NFC_FRI1.1_WK934_R31_1,NFC_FRI1.1_WK941_PREP1,NFC_FRI1.1_WK941_PREP2,NFC_FRI1.1_WK941_1,NFC_FRI1.1_WK943_R32_1,NFC_FRI1.1_WK949_PREP1,NFC_FRI1.1_WK943_R32_10,NFC_FRI1.1_WK943_R32_13,NFC_FRI1.1_WK943_R32_14,NFC_FRI1.1_WK1007_R33_1,NFC_FRI1.1_WK1007_R33_4,NFC_FRI1.1_WK1017_PREP1,NFC_FRI1.1_WK1017_R34_1,NFC_FRI1.1_WK1017_R34_2,NFC_FRI1.1_WK1023_R35_1 $
- *
- */
-
-#ifndef PHFRINFC_FELICAMAP_H
-#define PHFRINFC_FELICAMAP_H
-
-#include
-#if !defined PH_HAL4_ENABLE
-#include
-#endif
-#include
-#include
-#include
-
-
-#ifndef PH_FRINFC_EXCLUDE_FROM_TESTFW /* */
-
-#define PH_FRINFC_NDEFMAP_FELICAMAP_FILEREVISION "$Revision: 1.4 $"
-#define PH_FRINFC_NDEFMAP_FELLICAMAP_FILEALIASES "$Aliases: NFC_FRI1.1_WK914_R22_1,NFC_FRI1.1_WK914_R22_2,NFC_FRI1.1_WK916_R23_1,NFC_FRI1.1_WK918_R24_1,NFC_FRI1.1_WK920_PREP1,NFC_FRI1.1_WK920_R25_1,NFC_FRI1.1_WK922_PREP1,NFC_FRI1.1_WK922_R26_1,NFC_FRI1.1_WK924_PREP1,NFC_FRI1.1_WK924_R27_1,NFC_FRI1.1_WK926_R28_1,NFC_FRI1.1_WK928_R29_1,NFC_FRI1.1_WK930_R30_1,NFC_FRI1.1_WK934_PREP_1,NFC_FRI1.1_WK934_R31_1,NFC_FRI1.1_WK941_PREP1,NFC_FRI1.1_WK941_PREP2,NFC_FRI1.1_WK941_1,NFC_FRI1.1_WK943_R32_1,NFC_FRI1.1_WK949_PREP1,NFC_FRI1.1_WK943_R32_10,NFC_FRI1.1_WK943_R32_13,NFC_FRI1.1_WK943_R32_14,NFC_FRI1.1_WK1007_R33_1,NFC_FRI1.1_WK1007_R33_4,NFC_FRI1.1_WK1017_PREP1,NFC_FRI1.1_WK1017_R34_1,NFC_FRI1.1_WK1017_R34_2,NFC_FRI1.1_WK1023_R35_1 $"
-
-/* NDEF Mapping - states of the Finite State machine */
-#define PH_NFCFRI_NDEFMAP_FELI_STATE_SELECT_WILD_CARD 1 /* Select Wild Card State*/
-#define PH_NFCFRI_NDEFMAP_FELI_STATE_SELECT_NDEF_APP 2 /* Select NFC Forum Application State*/
-#define PH_FRINFC_NDEFMAP_FELI_STATE_CHK_NDEF 3 /* Ndef Complient State*/
-#define PH_NFCFRI_NDEFMAP_FELI_STATE_RD_ATTR 4 /* Read Attribute Information State*/
-#define PH_NFCFRI_NDEFMAP_FELI_STATE_RD_BLOCK 5 /* Read Data state*/
-#define PH_NFCFRI_NDEFMAP_FELI_STATE_WR_BLOCK 6 /* Write Data State*/
-#define PH_NFCFRI_NDEFMAP_FELI_STATE_ATTR_BLK_WR_BEGIN 7 /* Write Attrib Blk for write Begin*/
-#define PH_NFCFRI_NDEFMAP_FELI_STATE_ATTR_BLK_WR_END 8 /* Write Attrib Blk for write End*/
-#define PH_NFCFRI_NDEFMAP_FELI_STATE_WR_EMPTY_MSG 9 /* write Empty Ndef Msg*/
-
-
-#define PH_NFCFRI_NDEFMAP_FELI_WR_RESP_BYTE 0x09 /* Write Cmd Response Byte*/
-#define PH_NFCFRI_NDEFMAP_FELI_RD_RESP_BYTE 0x07 /* Read Cmd Response Byte*/
-
-#define PH_NFCFRI_NDEFMAP_FELI_NMAXB 13 /* Nmaxb Identifier*/
-#define PH_NFCFRI_NDEFMAP_FELI_NBC 14 /* Nbc Identifier*/
-
-#define PH_FRINFC_NDEFMAP_FELI_OP_NONE 15 /* To Read the attribute information*/
-#define PH_FRINFC_NDEFMAP_FELI_WR_ATTR_RD_OP 16 /* To Read the attribute info. while a WR Operationg*/
-#define PH_FRINFC_NDEFMAP_FELI_RD_ATTR_RD_OP 17 /* To Read the attribute info. while a RD Operationg*/
-#define PH_FRINFC_NDEFMAP_FELI_CHK_NDEF_OP 18 /* To Process the read attribute info. while a ChkNdef Operation*/
-#define PH_FRINFC_NDEFMAP_FELI_WR_EMPTY_MSG_OP 19 /* To Process the Empty NDEF Msg while erasing the NDEF data*/
-
-#define PH_FRINFC_NDEFMAP_FELI_NUM_DEVICE_TO_DETECT 1
-
-#define PH_NFCFRI_NDEFMAP_FELI_RESP_HEADER_LEN 13 /* To skip response code, IDm, status flgas and Nb*/
-#define PH_NFCFRI_NDEFMAP_FELI_VERSION_INDEX 13 /* Specifies Index of the version in Attribute Resp Buffer*/
-#define PH_NFCFRI_NDEFMAP_FELI_PKT_LEN_INDEX 0 /* Specifies Index of the Packet Length*/
-
-
-/* To Handle the EOF staus*/
-#ifndef TRUE
-#define TRUE 1
-#endif /* #ifndef TRUE */
-
-#ifndef FALSE
-#define FALSE 0
-#endif /* #ifndef FALSE */
-
-
-/* NFC Device Major and Minor Version numbers*/
-/* !!CAUTION!! these needs to be updated periodically.Major and Minor version numbers
- should be compatible to the version number of currently implemented mapping document.
- Example : NFC Device version Number : 1.0 , specifies
- Major VNo is 1,
- Minor VNo is 0 */
-#define PH_NFCFRI_NDEFMAP_FELI_NFCDEV_MAJOR_VER_NUM 0x01
-#define PH_NFCFRI_NDEFMAP_FELI_NFCDEV_MINOR_VER_NUM 0x00
-
-/* Macros to find major and minor T3T version numbers*/
-#define PH_NFCFRI_NDEFMAP_FELI_GET_MAJOR_T3T_VERNO(a)\
-do\
-{\
- (((a) & (0xf0))>>(4))\
-}while (0)
-
-#define PH_NFCFRI_NDEFMAP_FELI_GET_MINOR_T3T_VERNO(a)\
-do\
-{\
- ((a) & (0x0f))\
-}while (0)
-
-
-/* Macro for LEN Byte Calculation*/
-#define PH_NFCFRI_NDEFMAP_FELI_CAL_LEN_BYTES(Byte1,Byte2,Byte3,DataLen)\
-do\
-{ \
- (DataLen) = (Byte1); \
- (DataLen) = (DataLen) << (16);\
- (DataLen) += (Byte2);\
- (DataLen) = (DataLen) << (8);\
- (DataLen) += (Byte3);\
-}while(0)
-
-
-
-
-/* Enum for the data write operations*/
-typedef enum
-{
- FELICA_WRITE_STARTED,
- FELICA_WRITE_ENDED,
- FELICA_EOF_REACHED_WR_WITH_BEGIN_OFFSET,
- FELICA_EOF_REACHED_WR_WITH_CURR_OFFSET,
- FELICA_RD_WR_EOF_CARD_REACHED,
- FELICA_WRITE_EMPTY_MSG
-
-}phFriNfc_FelicaError_t;
-
-
-
-/*!
- * \brief \copydoc page_ovr Initiates Reading of NDEF information from the Remote Device.
- *
- * The function initiates the reading of NDEF information from a Remote Device.
- * It performs a reset of the state and starts the action (state machine).
- * A periodic call of the \ref phFriNfc_NdefMap_Process has to be done once the action
- * has been triggered.
- *
- * \param[in] NdefMap Pointer to a valid instance of the \ref phFriNfc_NdefMap_t structure describing
- * the component context.
- *
- * \param[in] PacketData Pointer to a location that receives the NDEF Packet.
- *
- * \param[in,out] PacketDataLength Pointer to a variable receiving the length of the NDEF packet.
- *
- * \param[in] Offset Indicates whether the read operation shall start from the begining of the
- * file/card storage \b or continue from the last offset. The last Offset set is stored
- * within a context variable (must not be modified by the integration).
- * If the caller sets the value to \ref PH_FRINFC_NDEFMAP_SEEK_CUR, the component shall
- * start reading from the last offset set (continue where it has stopped before).
- * If set to \ref PH_FRINFC_NDEFMAP_SEEK_BEGIN, the component shall start reading
- * from the begining of the card (restarted)
- *
- * \retval NFCSTATUS_PENDING The action has been successfully triggered.
- * \retval NFCSTATUS_INVALID_DEVICE_REQUEST If Previous Operation is Write Ndef and Offset
- * is Current then this error is displayed.
- * \retval NFCSTATUS_EOF_NDEF_CONTAINER_REACHED No Space in the File to read.
- * \retval NFCSTATUS_SUCCESS Last Byte of the card read.
- * \retval NFCSTATUS_INVALID_DEVICE The device has not been opened or has been disconnected
- * meanwhile.
- * \retval NFCSTATUS_CMD_ABORTED The caller/driver has aborted the request.
- * \retval NFCSTATUS_RF_TIMEOUT No data has been received within the TIMEOUT period.
- *
- */
-
-NFCSTATUS phFriNfc_Felica_RdNdef( phFriNfc_NdefMap_t *NdefMap,
- uint8_t *PacketData,
- uint32_t *PacketDataLength,
- uint8_t Offset);
-
-/*!
- * \brief \copydoc page_ovr Initiates Writing of NDEF information to the Remote Device.
- *
- * The function initiates the writing of NDEF information to a Remote Device.
- * It performs a reset of the state and starts the action (state machine).
- * A periodic call of the \ref phFriNfc_NdefMap_Process has to be done once the action
- * has been triggered.
- *
- * \param[in] NdefMap Pointer to a valid instance of the \ref phFriNfc_NdefMap_t structure describing
- * the component context.
- *
- * \param[in] PacketData Pointer to a location that holds the prepared NDEF Packet.
- *
- * \param[in,out] PacketDataLength Variable specifying the length of the prepared NDEF packet.
- *
- * \param[in] Offset Indicates whether the write operation shall start from the begining of the
- * file/card storage \b or continue from the last offset. The last Offset set is stored
- * within a context variable (must not be modified by the integration).
- * If the caller sets the value to \ref PH_FRINFC_NDEFMAP_SEEK_CUR, the component shall
- * start writing from the last offset set (continue where it has stopped before).
- * If set to \ref PH_FRINFC_NDEFMAP_SEEK_BEGIN, the component shall start writing
- * from the begining of the card (restarted)
- *
- * \retval NFCSTATUS_PENDING The action has been successfully triggered.
- * \retval NFCSTATUS_INVALID_DEVICE_REQUEST If Previous Operation is Write Ndef and Offset
- * is Current then this error is displayed.
- * \retval NFCSTATUS_EOF_NDEF_CONTAINER_REACHED Last byte is written to the card after this
- * no further writing is possible.
- * \retval NFCSTATUS_SUCCESS Buffer provided by the user is completely written
- * into the card.
- * \retval NFCSTATUS_INVALID_DEVICE The device has not been opened or has been disconnected
- * meanwhile.
- * \retval NFCSTATUS_CMD_ABORTED The caller/driver has aborted the request.
- * \retval NFCSTATUS_RF_TIMEOUT No data has been received within the TIMEOUT period.
- *
- */
-
-NFCSTATUS phFriNfc_Felica_WrNdef( phFriNfc_NdefMap_t *NdefMap,
- uint8_t *PacketData,
- uint32_t *PacketDataLength,
- uint8_t Offset);
-
-/*!
- * \brief \copydoc page_ovr Initiates Writing of Empty NDEF information to the Remote Device.
- *
- * The function initiates the erasing of NDEF information to a Remote Device.
- * It performs a reset of the state and starts the action (state machine).
- * A periodic call of the \ref phFriNfc_NdefMap_Process has to be done once the action
- * has been triggered.
- *
- * \param[in] NdefMap Pointer to a valid instance of the \ref phFriNfc_NdefMap_t structure describing
- * the component context.
- *
- * \retval NFCSTATUS_PENDING The action has been successfully triggered.
- * \retval NFCSTATUS_SUCCESS Empty msessage is completely written
- * into the card.
- * \retval NFCSTATUS_INVALID_DEVICE The device has not been opened or has been disconnected
- * meanwhile.
- * \retval NFCSTATUS_CMD_ABORTED The caller/driver has aborted the request.
- * \retval NFCSTATUS_RF_TIMEOUT No data has been received within the TIMEOUT period.
- *
- */
-
-NFCSTATUS phFriNfc_Felica_EraseNdef( phFriNfc_NdefMap_t *NdefMap);
-
-
-/*!
- * \brief \copydoc page_ovr Check whether a particulat Remote Device is NDEF compliant.
- *
- * The function checks whether the peer device is NDEF compliant.
- *
- * \param[in] NdefMap Pointer to a valid instance of the \ref phFriNfc_NdefMap_t structure describing
- * the component context.
- *
- * \retval NFCSTATUS_PENDING The action has been successfully triggered.
- * \retval NFCSTATUS_INVALID_PARAMETER At least one parameter of the function is invalid.
- * \retval NFCSTATUS_INVALID_DEVICE The device has not been opened or has been disconnected
- * meanwhile.
- * \retval NFCSTATUS_CMD_ABORTED The caller/driver has aborted the request.
- * \retval NFCSTATUS_RF_TIMEOUT No data has been received within the TIMEOUT period.
- *
- */
-
-NFCSTATUS phFriNfc_Felica_ChkNdef( phFriNfc_NdefMap_t *NdefMap);
-
-/*!
- * \brief \copydoc page_cb Completion Routine, Processing function, needed to avoid long blocking.
- *
- * The function call scheme is according to \ref grp_interact. No State reset is performed during operation.
- *
- * \copydoc pphFriNfc_Cr_t
- *
- * \note The lower (Overlapped HAL) layer must register a pointer to this function as a Completion
- * Routine in order to be able to notify the component that an I/O has finished and data are
- * ready to be processed.
- *
- */
-
-void phFriNfc_Felica_Process(void *Context,
- NFCSTATUS Status);
-
-
-#endif /* PH_FRINFC_EXCLUDE_FROM_TESTFW */
-
-
-#endif /* PHFRINFC_FELICAMAP_H */
-
-
diff --git a/libnfc-nxp/phFriNfc_ISO15693Format.c b/libnfc-nxp/phFriNfc_ISO15693Format.c
deleted file mode 100644
index a477f2a..0000000
--- a/libnfc-nxp/phFriNfc_ISO15693Format.c
+++ /dev/null
@@ -1,578 +0,0 @@
-/*
- *
- * Copyright (C) 2010 NXP Semiconductors
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-/*!
-* \file phFriNfc_ISO15693Format.c
-* \brief This component encapsulates different format functinalities ,
-* for the ISO-15693 card.
-*
-* Project: NFC-FRI
-*
-* $Date: $
-* $Author: ing02260 $
-* $Revision: 1.0 $
-* $Aliases: $
-*
-*/
-
-#ifndef PH_FRINFC_FMT_ISO15693_DISABLED
-
-#include
-#include
-#include
-#include
-
-
-/****************************** Macro definitions start ********************************/
-/* State for the format */
-#define ISO15693_FORMAT 0x01U
-
-/* Bytes per block in the ISO-15693 */
-#define ISO15693_BYTES_PER_BLOCK 0x04U
-
-/* ISO-15693 Commands
-GET SYSTEM INFORMATION COMMAND
-*/
-#define ISO15693_GET_SYSTEM_INFO_CMD 0x2BU
-/* READ SINGLE BLOCK COMMAND */
-#define ISO15693_RD_SINGLE_BLK_CMD 0x20U
-/* WRITE SINGLE BLOCK COMMAND */
-#define ISO15693_WR_SINGLE_BLK_CMD 0x21U
-/* READ MULTIPLE BLOCK COMMAND */
-#define ISO15693_RD_MULTIPLE_BLKS_CMD 0x23U
-
-/* CC bytes
-CC BYTE 0 - Magic Number - 0xE1
-*/
-#define ISO15693_CC_MAGIC_NUM 0xE1U
-/* CC BYTE 1 - Mapping version and READ WRITE settings 0x40
-*/
-#define ISO15693_CC_VER_RW 0x40U
-/* CC BYTE 2 - max size is calaculated using the byte 3 multiplied by 8 */
-#define ISO15693_CC_MULTIPLE_FACTOR 0x08U
-
-/* Inventory command support mask for the CC byte 4 */
-#define ISO15693_INVENTORY_CMD_MASK 0x02U
-/* Read MULTIPLE blocks support mask for CC byte 4 */
-#define ISO15693_RDMULBLKS_CMD_MASK 0x01U
-/* Flags for the command */
-#define ISO15693_FMT_FLAGS 0x20U
-
-/* Read two blocks */
-#define ISO15693_RD_2_BLOCKS 0x02U
-
-/* TYPE identifier of the NDEF TLV */
-#define ISO15693_NDEF_TLV_TYPE_ID 0x03U
-/* Terminator TLV identifier */
-#define ISO15693_TERMINATOR_TLV_ID 0xFEU
-
-/* UID 7th byte value shall be 0xE0 */
-#define ISO15693_7TH_BYTE_UID_VALUE 0xE0U
-#define ISO15693_BYTE_7_INDEX 0x07U
-
-/* UID 6th byte value shall be 0x04 - NXP manufacturer */
-#define ISO15693_6TH_BYTE_UID_VALUE 0x04U
-#define ISO15693_BYTE_6_INDEX 0x06U
-
-#define ISO15693_EXTRA_RESPONSE_FLAG 0x01U
-
-#define ISO15693_GET_SYS_INFO_RESP_LEN 0x0EU
-#define ISO15693_DSFID_MASK 0x01U
-#define ISO15693_AFI_MASK 0x02U
-#define ISO15693_MAX_SIZE_MASK 0x04U
-#define ISO15693_ICREF_MASK 0x08U
-#define ISO15693_SKIP_DFSID 0x01U
-#define ISO15693_SKIP_AFI 0x01U
-#define ISO15693_BLOCK_SIZE_IN_BYTES_MASK 0x1FU
-
-
-/* MAXimum size of ICODE SLI/X */
-#define ISO15693_SLI_X_MAX_SIZE 112U
-/* MAXimum size of ICODE SLI/X - S */
-#define ISO15693_SLI_X_S_MAX_SIZE 160U
-/* MAXimum size of ICODE SLI/X - L */
-#define ISO15693_SLI_X_L_MAX_SIZE 32U
-/****************************** Macro definitions end ********************************/
-
-/****************************** Data structures start ********************************/
-typedef enum phFriNfc_ISO15693_FormatSeq
-{
- ISO15693_GET_SYS_INFO,
- ISO15693_RD_SINGLE_BLK_CHECK,
- ISO15693_WRITE_CC_FMT,
- ISO15693_WRITE_NDEF_TLV
-}phFriNfc_ISO15693_FormatSeq_t;
-/****************************** Data structures end ********************************/
-
-/*********************** Static function declarations start ***********************/
-static
-NFCSTATUS
-phFriNfc_ISO15693_H_ProFormat (
- phFriNfc_sNdefSmtCrdFmt_t *psNdefSmtCrdFmt);
-
-static
-NFCSTATUS
-phFriNfc_ISO15693_H_GetMaxDataSize (
- phFriNfc_sNdefSmtCrdFmt_t *psNdefSmtCrdFmt,
- uint8_t *p_recv_buf,
- uint8_t recv_length);
-
-static
-NFCSTATUS
-phFriNfc_ISO15693_H_FmtReadWrite (
- phFriNfc_sNdefSmtCrdFmt_t *psNdefSmtCrdFmt,
- uint8_t command,
- uint8_t *p_data,
- uint8_t data_length);
-/*********************** Static function declarations end ***********************/
-
-/*********************** Static function definitions start ***********************/
-
-static
-NFCSTATUS
-phFriNfc_ISO15693_H_FmtReadWrite (
- phFriNfc_sNdefSmtCrdFmt_t *psNdefSmtCrdFmt,
- uint8_t command,
- uint8_t *p_data,
- uint8_t data_length)
-{
- NFCSTATUS result = NFCSTATUS_SUCCESS;
- uint8_t send_index = 0;
-
- /* set the data for additional data exchange*/
- psNdefSmtCrdFmt->psDepAdditionalInfo.DepFlags.MetaChaining = 0;
- psNdefSmtCrdFmt->psDepAdditionalInfo.DepFlags.NADPresent = 0;
- psNdefSmtCrdFmt->psDepAdditionalInfo.NAD = 0;
-
- psNdefSmtCrdFmt->SmtCrdFmtCompletionInfo.CompletionRoutine =
- phFriNfc_ISO15693_FmtProcess;
- psNdefSmtCrdFmt->SmtCrdFmtCompletionInfo.Context = psNdefSmtCrdFmt;
-
- *psNdefSmtCrdFmt->SendRecvLength = PH_FRINFC_SMTCRDFMT_MAX_SEND_RECV_BUF_SIZE;
-
- psNdefSmtCrdFmt->Cmd.Iso15693Cmd = phHal_eIso15693_Cmd;
-
- *(psNdefSmtCrdFmt->SendRecvBuf + send_index) = (uint8_t)ISO15693_FMT_FLAGS;
- send_index = (uint8_t)(send_index + 1);
-
- *(psNdefSmtCrdFmt->SendRecvBuf + send_index) = (uint8_t)command;
- send_index = (uint8_t)(send_index + 1);
-
- (void)memcpy ((void *)(psNdefSmtCrdFmt->SendRecvBuf + send_index),
- (void *)psNdefSmtCrdFmt->psRemoteDevInfo->RemoteDevInfo.Iso15693_Info.Uid,
- psNdefSmtCrdFmt->psRemoteDevInfo->RemoteDevInfo.Iso15693_Info.UidLength);
- send_index = (uint8_t)(send_index +
- psNdefSmtCrdFmt->psRemoteDevInfo->RemoteDevInfo.Iso15693_Info.UidLength);
-
- switch (command)
- {
- case ISO15693_WR_SINGLE_BLK_CMD:
- case ISO15693_RD_MULTIPLE_BLKS_CMD:
- {
- *(psNdefSmtCrdFmt->SendRecvBuf + send_index) = (uint8_t)
- psNdefSmtCrdFmt->AddInfo.s_iso15693_info.current_block;
- send_index = (uint8_t)(send_index + 1);
-
- if (data_length)
- {
- (void)memcpy ((void *)(psNdefSmtCrdFmt->SendRecvBuf + send_index),
- (void *)p_data, data_length);
- send_index = (uint8_t)(send_index + data_length);
- }
- else
- {
- result = PHNFCSTVAL (CID_FRI_NFC_NDEF_SMTCRDFMT,
- NFCSTATUS_INVALID_DEVICE_REQUEST);
- }
- break;
- }
-
- case ISO15693_RD_SINGLE_BLK_CMD:
- {
- *(psNdefSmtCrdFmt->SendRecvBuf + send_index) = (uint8_t)
- psNdefSmtCrdFmt->AddInfo.s_iso15693_info.current_block;
- send_index = (uint8_t)(send_index + 1);
- break;
- }
-
- case ISO15693_GET_SYSTEM_INFO_CMD:
- {
- /* Dont do anything */
- break;
- }
-
- default:
- {
- result = PHNFCSTVAL (CID_FRI_NFC_NDEF_SMTCRDFMT,
- NFCSTATUS_INVALID_DEVICE_REQUEST);
- break;
- }
- }
-
- psNdefSmtCrdFmt->SendLength = send_index;
-
- if (!result)
- {
- result = phFriNfc_OvrHal_Transceive(psNdefSmtCrdFmt->LowerDevice,
- &psNdefSmtCrdFmt->SmtCrdFmtCompletionInfo,
- psNdefSmtCrdFmt->psRemoteDevInfo,
- psNdefSmtCrdFmt->Cmd,
- &psNdefSmtCrdFmt->psDepAdditionalInfo,
- psNdefSmtCrdFmt->SendRecvBuf,
- psNdefSmtCrdFmt->SendLength,
- psNdefSmtCrdFmt->SendRecvBuf,
- psNdefSmtCrdFmt->SendRecvLength);
- }
-
- return result;
-}
-
-static
-NFCSTATUS
-phFriNfc_ISO15693_H_GetMaxDataSize (
- phFriNfc_sNdefSmtCrdFmt_t *psNdefSmtCrdFmt,
- uint8_t *p_recv_buf,
- uint8_t recv_length)
-{
- NFCSTATUS result = NFCSTATUS_SUCCESS;
- phFriNfc_ISO15693_AddInfo_t *ps_iso15693_info =
- &(psNdefSmtCrdFmt->AddInfo.s_iso15693_info);
- phHal_sIso15693Info_t *ps_rem_iso_15693_info =
- &(psNdefSmtCrdFmt->psRemoteDevInfo->RemoteDevInfo.Iso15693_Info);
- uint8_t recv_index = 0;
-
- if ((ISO15693_GET_SYS_INFO_RESP_LEN == recv_length)
- && (ISO15693_MAX_SIZE_MASK == (*p_recv_buf & ISO15693_MAX_SIZE_MASK)))
- {
- uint8_t information_flag = *p_recv_buf;
- /* MAX size is present in the system information and
- also response length is correct */
- recv_index = (uint8_t)(recv_index + 1);
-
- if (!phOsalNfc_MemCompare ((void *)ps_rem_iso_15693_info->Uid,
- (void *)(p_recv_buf + recv_index),
- ps_rem_iso_15693_info->UidLength))
- {
- /* UID comaparision successful */
- uint8_t no_of_blocks = 0;
- uint8_t blk_size_in_bytes = 0;
- uint8_t ic_reference = 0;
-
- /* So skip the UID size compared in the received buffer */
- recv_index = (uint8_t)(recv_index +
- ps_rem_iso_15693_info->UidLength);
-
- if (information_flag & ISO15693_DSFID_MASK) {
- /* Skip DFSID */
- recv_index = (uint8_t)(recv_index + ISO15693_SKIP_DFSID);
- }
- if (information_flag & ISO15693_AFI_MASK) {
- /* Skip AFI */
- recv_index = (uint8_t)(recv_index + ISO15693_SKIP_AFI);
- }
-
- /* To get the number of blocks in the card */
- no_of_blocks = (uint8_t)(*(p_recv_buf + recv_index) + 1);
- recv_index = (uint8_t)(recv_index + 1);
-
- /* To get the each block size in bytes */
- blk_size_in_bytes = (uint8_t)((*(p_recv_buf + recv_index)
- & ISO15693_BLOCK_SIZE_IN_BYTES_MASK) + 1);
- recv_index = (uint8_t)(recv_index + 1);
-
- if (information_flag & ISO15693_ICREF_MASK) {
- /* Get the IC reference */
- ic_reference = (uint8_t)(*(p_recv_buf + recv_index));
- if (ic_reference == 0x03) {
- no_of_blocks = 8;
- }
- }
-
- /* calculate maximum data size in the card */
- ps_iso15693_info->max_data_size = (uint16_t)
- (no_of_blocks * blk_size_in_bytes);
-
- }
- else
- {
- result = PHNFCSTVAL (CID_FRI_NFC_NDEF_SMTCRDFMT,
- NFCSTATUS_INVALID_DEVICE_REQUEST);
- }
- }
- else
- {
- result = PHNFCSTVAL (CID_FRI_NFC_NDEF_SMTCRDFMT,
- NFCSTATUS_INVALID_DEVICE_REQUEST);
- }
-
-
- return result;
-}
-
-static
-NFCSTATUS
-phFriNfc_ISO15693_H_ProFormat (
- phFriNfc_sNdefSmtCrdFmt_t *psNdefSmtCrdFmt)
-{
- NFCSTATUS result = NFCSTATUS_SUCCESS;
- phFriNfc_ISO15693_AddInfo_t *ps_iso15693_info =
- &(psNdefSmtCrdFmt->AddInfo.s_iso15693_info);
- phFriNfc_ISO15693_FormatSeq_t e_format_seq =
- (phFriNfc_ISO15693_FormatSeq_t)
- ps_iso15693_info->format_seq;
- uint8_t command_type = 0;
- uint8_t a_send_byte[ISO15693_BYTES_PER_BLOCK] = {0};
- uint8_t send_length = 0;
- uint8_t send_index = 0;
- uint8_t format_complete = FALSE;
-
- switch (e_format_seq)
- {
- case ISO15693_GET_SYS_INFO:
- {
- /* RESPONSE received for GET SYSTEM INFO */
-
- if (!phFriNfc_ISO15693_H_GetMaxDataSize (psNdefSmtCrdFmt,
- (psNdefSmtCrdFmt->SendRecvBuf + ISO15693_EXTRA_RESPONSE_FLAG),
- (uint8_t)(*psNdefSmtCrdFmt->SendRecvLength -
- ISO15693_EXTRA_RESPONSE_FLAG)))
- {
- /* Send the READ SINGLE BLOCK COMMAND */
- command_type = ISO15693_RD_SINGLE_BLK_CMD;
- e_format_seq = ISO15693_RD_SINGLE_BLK_CHECK;
-
- /* Block number 0 to read */
- psNdefSmtCrdFmt->AddInfo.s_iso15693_info.current_block = 0x00;
- }
- else
- {
- result = PHNFCSTVAL (CID_FRI_NFC_NDEF_SMTCRDFMT,
- NFCSTATUS_INVALID_RECEIVE_LENGTH);
- }
- break;
- }
-
- case ISO15693_RD_SINGLE_BLK_CHECK:
- {
- /* RESPONSE received for READ SINGLE BLOCK
- received*/
-
- /* Check if Card is really fresh
- First 4 bytes must be 0 for fresh card */
-
- if ((psNdefSmtCrdFmt->AddInfo.s_iso15693_info.current_block == 0x00) &&
- (psNdefSmtCrdFmt->SendRecvBuf[1] != 0x00 ||
- psNdefSmtCrdFmt->SendRecvBuf[2] != 0x00 ||
- psNdefSmtCrdFmt->SendRecvBuf[3] != 0x00 ||
- psNdefSmtCrdFmt->SendRecvBuf[4] != 0x00))
- {
- result = PHNFCSTVAL (CID_FRI_NFC_NDEF_SMTCRDFMT, NFCSTATUS_INVALID_FORMAT);
- }
- else
- {
- /* prepare data for writing CC bytes */
-
- command_type = ISO15693_WR_SINGLE_BLK_CMD;
- e_format_seq = ISO15693_WRITE_CC_FMT;
-
- /* CC magic number */
- *a_send_byte = (uint8_t)ISO15693_CC_MAGIC_NUM;
- send_index = (uint8_t)(send_index + 1);
-
- /* CC Version and read/write access */
- *(a_send_byte + send_index) = (uint8_t) ISO15693_CC_VER_RW;
- send_index = (uint8_t)(send_index + 1);
-
- /* CC MAX data size, calculated during GET system information */
- *(a_send_byte + send_index) = (uint8_t) (ps_iso15693_info->max_data_size / ISO15693_CC_MULTIPLE_FACTOR);
- send_index = (uint8_t)(send_index + 1);
-
- switch (ps_iso15693_info->max_data_size)
- {
- case ISO15693_SLI_X_MAX_SIZE:
- {
- /* For SLI tags : Inventory Page read not supported */
- *(a_send_byte + send_index) = (uint8_t) ISO15693_RDMULBLKS_CMD_MASK;
- break;
- }
-
- case ISO15693_SLI_X_S_MAX_SIZE:
- {
- /* For SLI - S tags : Read multiple blocks not supported */
- *(a_send_byte + send_index) = (uint8_t) ISO15693_INVENTORY_CMD_MASK;
- break;
- }
-
- case ISO15693_SLI_X_L_MAX_SIZE:
- {
- /* For SLI - L tags : Read multiple blocks not supported */
- *(a_send_byte + send_index) = (uint8_t) ISO15693_INVENTORY_CMD_MASK;
- break;
- }
-
- default:
- {
- result = PHNFCSTVAL (CID_FRI_NFC_NDEF_SMTCRDFMT, NFCSTATUS_INVALID_DEVICE_REQUEST);
- break;
- }
- }
-
- send_index = (uint8_t)(send_index + 1);
-
- send_length = sizeof (a_send_byte);
- }
-
- break;
- }
-
- case ISO15693_WRITE_CC_FMT:
- {
- /* CC byte write succcessful.
- Prepare data for NDEF TLV writing */
- command_type = ISO15693_WR_SINGLE_BLK_CMD;
- e_format_seq = ISO15693_WRITE_NDEF_TLV;
-
- ps_iso15693_info->current_block = (uint16_t)
- (ps_iso15693_info->current_block + 1);
-
- /* NDEF TLV - Type byte updated to 0x03 */
- *a_send_byte = (uint8_t)ISO15693_NDEF_TLV_TYPE_ID;
- send_index = (uint8_t)(send_index + 1);
-
- /* NDEF TLV - Length byte updated to 0 */
- *(a_send_byte + send_index) = 0;
- send_index = (uint8_t)(send_index + 1);
-
- /* Terminator TLV - value updated to 0xFEU */
- *(a_send_byte + send_index) = (uint8_t)
- ISO15693_TERMINATOR_TLV_ID;
- send_index = (uint8_t)(send_index + 1);
-
- send_length = sizeof (a_send_byte);
- break;
- }
-
- case ISO15693_WRITE_NDEF_TLV:
- {
- /* SUCCESSFUL formatting complete */
- format_complete = TRUE;
- break;
- }
-
- default:
- {
- result = PHNFCSTVAL (CID_FRI_NFC_NDEF_SMTCRDFMT,
- NFCSTATUS_INVALID_DEVICE_REQUEST);
- break;
- }
- }
-
- if ((!format_complete) && (!result))
- {
- result = phFriNfc_ISO15693_H_FmtReadWrite (psNdefSmtCrdFmt,
- command_type, a_send_byte, send_length);
- }
-
- ps_iso15693_info->format_seq = (uint8_t)e_format_seq;
- return result;
-}
-
-/*********************** Static function definitions end ***********************/
-
-/*********************** External function definitions start ***********************/
-void
-phFriNfc_ISO15693_FmtReset (
- phFriNfc_sNdefSmtCrdFmt_t *psNdefSmtCrdFmt)
-{
- /* reset to ISO15693 data structure */
- (void)memset((void *)&(psNdefSmtCrdFmt->AddInfo.s_iso15693_info),
- 0x00, sizeof (phFriNfc_ISO15693_AddInfo_t));
- psNdefSmtCrdFmt->FmtProcStatus = 0;
-}
-
-NFCSTATUS
-phFriNfc_ISO15693_Format (
- phFriNfc_sNdefSmtCrdFmt_t *psNdefSmtCrdFmt)
-{
- NFCSTATUS result = NFCSTATUS_SUCCESS;
- phHal_sIso15693Info_t *ps_rem_iso_15693_info =
- &(psNdefSmtCrdFmt->psRemoteDevInfo->RemoteDevInfo.Iso15693_Info);
-
-
- if ((ISO15693_7TH_BYTE_UID_VALUE ==
- ps_rem_iso_15693_info->Uid[ISO15693_BYTE_7_INDEX])
- && (ISO15693_6TH_BYTE_UID_VALUE ==
- ps_rem_iso_15693_info->Uid[ISO15693_BYTE_6_INDEX]))
- {
- /* Check if the card is manufactured by NXP (6th byte
- index of UID value = 0x04 and the
- last byte of UID is 0xE0, only then the card detected
- is NDEF compliant */
- psNdefSmtCrdFmt->State = ISO15693_FORMAT;
-
- /* GET system information command to get the card size */
- result = phFriNfc_ISO15693_H_FmtReadWrite (psNdefSmtCrdFmt,
- ISO15693_GET_SYSTEM_INFO_CMD, NULL, 0);
- }
- else
- {
- result = PHNFCSTVAL (CID_FRI_NFC_NDEF_SMTCRDFMT,
- NFCSTATUS_INVALID_DEVICE_REQUEST);
- }
-
- return result;
-}
-
-void
-phFriNfc_ISO15693_FmtProcess (
- void *pContext,
- NFCSTATUS Status)
-{
- phFriNfc_sNdefSmtCrdFmt_t *psNdefSmtCrdFmt =
- (phFriNfc_sNdefSmtCrdFmt_t *)pContext;
-
- if((NFCSTATUS_SUCCESS & PHNFCSTBLOWER) == (Status & PHNFCSTBLOWER))
- {
- if (ISO15693_FORMAT == psNdefSmtCrdFmt->State)
- {
- /* Check for further formatting */
- Status = phFriNfc_ISO15693_H_ProFormat (psNdefSmtCrdFmt);
- }
- else
- {
- Status = PHNFCSTVAL (CID_FRI_NFC_NDEF_SMTCRDFMT,
- NFCSTATUS_INVALID_DEVICE_REQUEST);
- }
- }
- else
- {
- Status = PHNFCSTVAL (CID_FRI_NFC_NDEF_SMTCRDFMT,
- NFCSTATUS_FORMAT_ERROR);
- }
-
- /* Handle the all the error cases */
- if ((NFCSTATUS_PENDING & PHNFCSTBLOWER) != (Status & PHNFCSTBLOWER))
- {
- /* call respective CR */
- phFriNfc_SmtCrdFmt_HCrHandler (psNdefSmtCrdFmt, Status);
- }
-}
-/*********************** External function definitions end ***********************/
-
-
-#endif /* #ifndef PH_FRINFC_FMT_ISO15693_DISABLED */
-
diff --git a/libnfc-nxp/phFriNfc_ISO15693Format.h b/libnfc-nxp/phFriNfc_ISO15693Format.h
deleted file mode 100644
index 9dab3c1..0000000
--- a/libnfc-nxp/phFriNfc_ISO15693Format.h
+++ /dev/null
@@ -1,116 +0,0 @@
-/*
- * Copyright (C) 2010 NXP Semiconductors
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-/*!
-* \file phFriNfc_ISO15693Format.h
-* \brief ISO-15693 Smart card formatting.
-*
-* Project: NFC-FRI
-*
-* $Date: $
-* $Author: ing02260 $
-* $Revision: 1.0 $
-* $Aliases: $
-*
-*/
-
-#ifndef PHFRINFC_ISO15693FORMAT_H
-#define PHFRINFC_ISO15693FORMAT_H
-
-/****************************** Macro definitions start ********************************/
-
-/****************************** Macro definitions end ********************************/
-
-/****************************** Data structures start ********************************/
-
-/****************************** Data structures end ********************************/
-
-/*********************** External function declarations start ***********************/
-/*!
-* \brief \copydoc page_reg Resets the component instance to the initial state and lets the component forget about
-* the list of registered items. Moreover, the lower device is set.
-*
-* \param[in] NdefSmtCrdFmt Pointer to a valid or uninitialized instance of \ref phFriNfc_sNdefSmtCrdFmt_t.
-*
-* \note This function has to be called at the beginning, after creating an instance of
-* \ref phFriNfc_sNdefSmtCrdFmt_t. Use this function to reset the instance of smart card
-formatting context variables.
-*/
-void
-phFriNfc_ISO15693_FmtReset (
- phFriNfc_sNdefSmtCrdFmt_t *psNdefSmtCrdFmt);
-
-/*!
-* \ingroup grp_fri_smart_card_formatting
-*
-* \brief Initiates the card formatting procedure for Remote Smart Card Type.
-*
-* \copydoc page_ovr The function initiates and formats the ISO-15693 Card.After this
-* operation,remote card would be properly initialized and
-* Ndef Compliant.Depending upon the different card type, this
-* function handles formatting procedure.This function also handles
-* the different recovery procedures for different types of the cards.
-* For both Format and Recovery Management same API is used.
-*
-* \param[in] phFriNfc_sNdefSmartCardFmt_t Pointer to a valid instance of the \ref phFriNfc_sNdefSmartCardFmt_t
-* structure describing the component context.
-*
-* \retval NFCSTATUS_SUCCESS Card formatting has been successfully completed.
-* \retval NFCSTATUS_PENDING The action has been successfully triggered.
-* \retval NFCSTATUS_FORMAT_ERROR Error occured during the formatting procedure.
-* \retval NFCSTATUS_INVALID_REMOTE_DEVICE Card Type is unsupported.
-* \retval NFCSTATUS_INVALID_DEVICE_REQUEST Command or Operation types are mismatching.
-*
-*/
-NFCSTATUS
-phFriNfc_ISO15693_Format (
- phFriNfc_sNdefSmtCrdFmt_t *psNdefSmtCrdFmt);
-
-/**
-*\ingroup grp_fri_smart_card_formatting
-*
-* \brief Smart card Formatting \b Completion \b Routine or \b Process function
-*
-* \copydoc page_ovr Completion Routine: This function is called by the lower layer (OVR HAL)
-* when an I/O operation has finished. The internal state machine decides
-* whether to call into the lower device again or to complete the process
-* by calling into the upper layer's completion routine, stored within this
-* component's context (\ref phFriNfc_sNdefSmtCrdFmt_t).
-*
-* The function call scheme is according to \ref grp_interact. No State reset is performed during
-* operation.
-*
-* \param[in] Context The context of the current (not the lower/upper) instance, as set by the lower,
-* calling layer, upon its completion.
-* \param[in] Status The completion status of the lower layer (to be handled by the implementation of
-* the state machine of this function like a regular return value of an internally
-* called function).
-*
-* \note For general information about the completion routine interface please see \ref pphFriNfc_Cr_t .
-* The Different Status Values are as follows
-*
-*/
-void
-phFriNfc_ISO15693_FmtProcess (
- void *pContext,
- NFCSTATUS Status);
-
-/*********************** External function declarations end ***********************/
-
-#endif /* #define PHFRINFC_ISO15693FORMAT_H */
-
-
-
diff --git a/libnfc-nxp/phFriNfc_ISO15693Map.c b/libnfc-nxp/phFriNfc_ISO15693Map.c
deleted file mode 100644
index a21d9c8..0000000
--- a/libnfc-nxp/phFriNfc_ISO15693Map.c
+++ /dev/null
@@ -1,1819 +0,0 @@
-/*
- *
- * Copyright (C) 2010 NXP Semiconductors
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-/*!
-* \file phFriNfc_ISO15693Map.c
-* \brief This component encapsulates read/write/check ndef/process functionalities,
-* for the ISO-15693 Card.
-*
-* Project: NFC-FRI
-*
-* $Date: $
-* $Author: ing02260 $
-* $Revision: $
-* $Aliases: $
-*
-*/
-
-#ifndef PH_FRINFC_MAP_ISO15693_DISABLED
-
-#include
-#include
-#include
-#include
-#include
-#include
-#include
-#include
-#include
-
-/************************** START DATA STRUCTURE *********************/
-
-typedef enum phFriNfc_eChkNdefSeq
-{
- ISO15693_NDEF_TLV_T,
- ISO15693_NDEF_TLV_L,
- ISO15693_NDEF_TLV_V,
- ISO15693_PROP_TLV_L,
- ISO15693_PROP_TLV_V
-
-}phFriNfc_eChkNdefSeq_t;
-
-typedef enum phFriNfc_eWrNdefSeq
-{
- ISO15693_RD_BEFORE_WR_NDEF_L_0,
- ISO15693_WRITE_DATA,
- ISO15693_RD_BEFORE_WR_NDEF_L,
- ISO15693_WRITE_NDEF_TLV_L
-
-}phFriNfc_eWrNdefSeq_t;
-
-#ifdef FRINFC_READONLY_NDEF
-
-typedef enum phFriNfc_eRONdefSeq
-{
- ISO15693_RD_BEFORE_WR_CC,
- ISO15693_WRITE_CC,
- ISO15693_LOCK_BLOCK
-
-}phFriNfc_eRONdefSeq_t;
-
-#endif /* #ifdef FRINFC_READONLY_NDEF */
-
-/************************** END DATA STRUCTURE *********************/
-
-/************************** START MACROS definition *********************/
-
-
-
-
-/* UID bytes to differentiate ICODE cards */
-#define ISO15693_UID_BYTE_4 0x04U
-#define ISO15693_UID_BYTE_5 0x05U
-#define ISO15693_UID_BYTE_6 0x06U
-#define ISO15693_UID_BYTE_7 0x07U
-
-/* UID 7th byte value shall be 0xE0 */
-#define ISO15693_UIDBYTE_7_VALUE 0xE0U
-/* UID 6th byte value shall be 0x04 - NXP manufacturer */
-#define ISO15693_UIDBYTE_6_VALUE 0x04U
-
-
-/* UID value for
- SL2 ICS20
- SL2S2002
- */
-#define ISO15693_UIDBYTE_5_VALUE_SLI_X 0x01U
-/* Card size SL2 ICS20 / SL2S2002 */
-#define ISO15693_SL2_S2002_ICS20 112U
-
-/* UID value for
- SL2 ICS53,
- SL2 ICS54
- SL2S5302
-*/
-#define ISO15693_UIDBYTE_5_VALUE_SLI_X_S 0x02U
-#define ISO15693_UIDBYTE_4_VALUE_SLI_X_S 0x00U
-#define ISO15693_UIDBYTE_4_VALUE_SLI_X_SHC 0x80U
-#define ISO15693_UIDBYTE_4_VALUE_SLI_X_SY 0x40U
-/* SL2 ICS53, SL2 ICS54 and SL2S5302 */
-#define ISO15693_SL2_S5302_ICS53_ICS54 160U
-
-/* UID value for
- SL2 ICS50
- SL2 ICS51
- SL2S5002
-*/
-#define ISO15693_UIDBYTE_5_VALUE_SLI_X_L 0x03U
-#define ISO15693_UIDBYTE_4_VALUE_SLI_X_L 0x00U
-#define ISO15693_UIDBYTE_4_VALUE_SLI_X_LHC 0x80U
-/* SL2 ICS50, SL2 ICS51 and SL2S5002 */
-#define ISO15693_SL2_S5002_ICS50_ICS51 32U
-
-
-/* State Machine declaration
-CHECK NDEF state */
-#define ISO15693_CHECK_NDEF 0x01U
-/* READ NDEF state */
-#define ISO15693_READ_NDEF 0x02U
-/* WRITE NDEF state */
-#define ISO15693_WRITE_NDEF 0x03U
-#ifdef FRINFC_READONLY_NDEF
-
- /* READ ONLY NDEF state */
- #define ISO15693_READ_ONLY_NDEF 0x04U
-
- /* READ ONLY MASK byte for CC */
- #define ISO15693_CC_READ_ONLY_MASK 0x03U
-
- /* CC READ WRITE index */
- #define ISO15693_RW_BTYE_INDEX 0x01U
-
- /* LOCK BLOCK command */
- #define ISO15693_LOCK_BLOCK_CMD 0x22U
-
-#endif /* #ifdef FRINFC_READONLY_NDEF */
-
-/* CC Bytes
-Magic number */
-#define ISO15693_CC_MAGIC_BYTE 0xE1U
-/* Expected mapping version */
-#define ISO15693_MAPPING_VERSION 0x01U
-/* Major version is in upper 2 bits */
-#define ISO15693_MAJOR_VERSION_MASK 0xC0U
-
-/* CC indicating tag is capable of multi-block read */
-#define ISO15693_CC_USE_MBR 0x01U
-/* CC indicating tag is capable of inventory page read */
-#define ISO15693_CC_USE_IPR 0x02U
-/* EXTRA byte in the response */
-#define ISO15693_EXTRA_RESP_BYTE 0x01U
-
-/* Maximum card size multiplication factor */
-#define ISO15693_MULT_FACTOR 0x08U
-/* NIBBLE mask for READ WRITE access */
-#define ISO15693_LSB_NIBBLE_MASK 0x0FU
-#define ISO15693_RD_WR_PERMISSION 0x00U
-#define ISO15693_RD_ONLY_PERMISSION 0x03U
-
-/* READ command identifier */
-#define ISO15693_READ_COMMAND 0x20U
-
-/* READ multiple command identifier */
-#define ISO15693_READ_MULTIPLE_COMMAND 0x23U
-
-/* INVENTORY pageread command identifier */
-#define ICODE_INVENTORY_PAGEREAD_COMMAND 0xB0U
-#define INVENTORY_PAGEREAD_FLAGS 0x24U
-#define NXP_MANUFACTURING_CODE 0x04U
-
-/* WRITE command identifier */
-#define ISO15693_WRITE_COMMAND 0x21U
-/* FLAG option */
-#define ISO15693_FLAGS 0x20U
-
-/* RESPONSE length expected for single block READ */
-#define ISO15693_SINGLE_BLK_RD_RESP_LEN 0x04U
-/* NULL TLV identifier */
-#define ISO15693_NULL_TLV_ID 0x00U
-/* NDEF TLV, TYPE identifier */
-#define ISO15693_NDEF_TLV_TYPE_ID 0x03U
-
-/* 8 BIT shift */
-#define ISO15693_BTYE_SHIFT 0x08U
-
-/* Proprietary TLV TYPE identifier */
-#define ISO15693_PROP_TLV_ID 0xFDU
-
-/* CC SIZE in BYTES */
-#define ISO15693_CC_SIZE 0x04U
-
-/* To get the remaining size in the card.
-Inputs are
-1. maximum data size
-2. block number
-3. index of the block number */
-#define ISO15693_GET_REMAINING_SIZE(max_data_size, blk, index) \
- (max_data_size - ((blk * ISO15693_BYTES_PER_BLOCK) + index))
-
-#define ISO15693_GET_LEN_FIELD_BLOCK_NO(blk, byte_addr, ndef_size) \
- (((byte_addr + ((ndef_size >= ISO15693_THREE_BYTE_LENGTH_ID) ? 3 : 1)) > \
- (ISO15693_BYTES_PER_BLOCK - 1)) ? (blk + 1) : blk)
-
-#define ISO15693_GET_LEN_FIELD_BYTE_NO(blk, byte_addr, ndef_size) \
- (((byte_addr + ((ndef_size >= ISO15693_THREE_BYTE_LENGTH_ID) ? 3 : 1)) % \
- ISO15693_BYTES_PER_BLOCK))
-
-
-
-/************************** END MACROS definition *********************/
-
-/************************** START static functions declaration *********************/
-static
-NFCSTATUS
-phFriNfc_ISO15693_H_ProcessReadOnly (
- phFriNfc_NdefMap_t *psNdefMap);
-
-static
-NFCSTATUS
-phFriNfc_ISO15693_H_ProcessWriteNdef (
- phFriNfc_NdefMap_t *psNdefMap);
-
-static
-NFCSTATUS
-phFriNfc_ISO15693_H_ProcessReadNdef (
- phFriNfc_NdefMap_t *psNdefMap);
-
-static
-NFCSTATUS
-phFriNfc_ISO15693_H_ProcessCheckNdef (
- phFriNfc_NdefMap_t *psNdefMap);
-
-static
-void
-phFriNfc_ISO15693_H_Complete (
- phFriNfc_NdefMap_t *psNdefMap,
- NFCSTATUS Status);
-
-static
-NFCSTATUS
-phFriNfc_ISO15693_H_ReadWrite (
- phFriNfc_NdefMap_t *psNdefMap,
- uint8_t command,
- uint8_t *p_data,
- uint8_t data_length);
-
-static
-NFCSTATUS
-phFriNfc_ReadRemainingInMultiple (
- phFriNfc_NdefMap_t *psNdefMap,
- uint32_t startBlock);
-
-/************************** END static functions declaration *********************/
-
-/************************** START static functions definition *********************/
-
-static
-NFCSTATUS
-phFriNfc_ISO15693_H_ProcessWriteNdef (
- phFriNfc_NdefMap_t *psNdefMap)
-{
- NFCSTATUS result = NFCSTATUS_SUCCESS;
- phFriNfc_ISO15693Cont_t *ps_iso_15693_con =
- &(psNdefMap->ISO15693Container);
- phFriNfc_eWrNdefSeq_t e_wr_ndef_seq = (phFriNfc_eWrNdefSeq_t)
- psNdefMap->ISO15693Container.ndef_seq;
- uint8_t *p_recv_buf = NULL;
- uint8_t recv_length = 0;
- uint8_t write_flag = FALSE;
- uint8_t a_write_buf[ISO15693_BYTES_PER_BLOCK] = {0};
- uint8_t remaining_size = 0;
-
- switch (e_wr_ndef_seq)
- {
- case ISO15693_RD_BEFORE_WR_NDEF_L_0:
- {
- /* L byte is read */
- p_recv_buf = (psNdefMap->SendRecvBuf + ISO15693_EXTRA_RESP_BYTE);
- recv_length = (uint8_t)
- (*psNdefMap->SendRecvLength - ISO15693_EXTRA_RESP_BYTE);
-
- if (ISO15693_SINGLE_BLK_RD_RESP_LEN == recv_length)
- {
- /* Response length is correct */
- uint8_t byte_index = 0;
-
- /* Copy the recevied buffer */
- (void)memcpy ((void *)a_write_buf, (void *)p_recv_buf,
- recv_length);
-
- byte_index = ISO15693_GET_LEN_FIELD_BYTE_NO(
- ps_iso_15693_con->ndef_tlv_type_blk,
- ps_iso_15693_con->ndef_tlv_type_byte,
- psNdefMap->ApduBufferSize);
-
- /* Writing length field to 0, Update length field to 0 */
- *(a_write_buf + byte_index) = 0x00;
-
- if ((ISO15693_BYTES_PER_BLOCK - 1) != byte_index)
- {
- /* User data is updated in the buffer */
- byte_index = (uint8_t)(byte_index + 1);
- /* Block number shall be udate */
- remaining_size = (ISO15693_BYTES_PER_BLOCK - byte_index);
-
- if ((psNdefMap->ApduBufferSize - psNdefMap->ApduBuffIndex)
- < remaining_size)
- {
- remaining_size = (uint8_t)(psNdefMap->ApduBufferSize -
- psNdefMap->ApduBuffIndex);
- }
-
- /* Go to next byte to fill the write buffer */
- (void)memcpy ((void *)(a_write_buf + byte_index),
- (void *)(psNdefMap->ApduBuffer +
- psNdefMap->ApduBuffIndex), remaining_size);
-
- /* Write index updated */
- psNdefMap->ApduBuffIndex = (uint8_t)(psNdefMap->ApduBuffIndex +
- remaining_size);
- }
-
- /* After this write, user data can be written.
- Update the sequence accordingly */
- e_wr_ndef_seq = ISO15693_WRITE_DATA;
- write_flag = TRUE;
- } /* if (ISO15693_SINGLE_BLK_RD_RESP_LEN == recv_length) */
- else
- {
- result = PHNFCSTVAL(CID_FRI_NFC_NDEF_MAP,
- NFCSTATUS_INVALID_RECEIVE_LENGTH);
- }
- break;
- } /* case ISO15693_RD_BEFORE_WR_NDEF_L_0: */
-
- case ISO15693_RD_BEFORE_WR_NDEF_L:
- {
- p_recv_buf = (psNdefMap->SendRecvBuf + ISO15693_EXTRA_RESP_BYTE);
- recv_length = (uint8_t)(*psNdefMap->SendRecvLength -
- ISO15693_EXTRA_RESP_BYTE);
-
- if (ISO15693_SINGLE_BLK_RD_RESP_LEN == recv_length)
- {
- uint8_t byte_index = 0;
-
- (void)memcpy ((void *)a_write_buf, (void *)p_recv_buf,
- recv_length);
-
- byte_index = ISO15693_GET_LEN_FIELD_BYTE_NO(
- ps_iso_15693_con->ndef_tlv_type_blk,
- ps_iso_15693_con->ndef_tlv_type_byte,
- psNdefMap->ApduBuffIndex);
-
- *(a_write_buf + byte_index) = (uint8_t)psNdefMap->ApduBuffIndex;
- e_wr_ndef_seq = ISO15693_WRITE_NDEF_TLV_L;
- write_flag = TRUE;
- }
- else
- {
- result = PHNFCSTVAL(CID_FRI_NFC_NDEF_MAP,
- NFCSTATUS_INVALID_RECEIVE_LENGTH);
- }
- break;
- }
-
- case ISO15693_WRITE_DATA:
- {
- if ((psNdefMap->ApduBufferSize == psNdefMap->ApduBuffIndex)
- || (ps_iso_15693_con->current_block ==
- (ps_iso_15693_con->max_data_size / ISO15693_BYTES_PER_BLOCK)))
- {
- ps_iso_15693_con->current_block =
- ISO15693_GET_LEN_FIELD_BLOCK_NO(
- ps_iso_15693_con->ndef_tlv_type_blk,
- ps_iso_15693_con->ndef_tlv_type_byte,
- psNdefMap->ApduBuffIndex);
- e_wr_ndef_seq = ISO15693_RD_BEFORE_WR_NDEF_L;
- }
- else
- {
- remaining_size = ISO15693_BYTES_PER_BLOCK;
-
- ps_iso_15693_con->current_block = (uint16_t)
- (ps_iso_15693_con->current_block + 1);
-
- if ((psNdefMap->ApduBufferSize - psNdefMap->ApduBuffIndex)
- < remaining_size)
- {
- remaining_size = (uint8_t)(psNdefMap->ApduBufferSize -
- psNdefMap->ApduBuffIndex);
- }
-
- (void)memcpy ((void *)a_write_buf, (void *)
- (psNdefMap->ApduBuffer +
- psNdefMap->ApduBuffIndex), remaining_size);
-
- psNdefMap->ApduBuffIndex = (uint8_t)(psNdefMap->ApduBuffIndex +
- remaining_size);
- write_flag = TRUE;
- }
- break;
- } /* case ISO15693_WRITE_DATA: */
-
- case ISO15693_WRITE_NDEF_TLV_L:
- {
- *psNdefMap->WrNdefPacketLength = psNdefMap->ApduBuffIndex;
- ps_iso_15693_con->actual_ndef_size = psNdefMap->ApduBuffIndex;
- break;
- }
-
- default:
- {
- break;
- }
- } /* switch (e_wr_ndef_seq) */
-
- if (((0 == psNdefMap->ApduBuffIndex)
- || (*psNdefMap->WrNdefPacketLength != psNdefMap->ApduBuffIndex))
- && (!result))
- {
- if (FALSE == write_flag)
- {
- result = phFriNfc_ISO15693_H_ReadWrite (psNdefMap,
- ISO15693_READ_COMMAND, NULL, 0);
- }
- else
- {
- result = phFriNfc_ISO15693_H_ReadWrite (psNdefMap,
- ISO15693_WRITE_COMMAND,
- a_write_buf, sizeof (a_write_buf));
- }
- }
-
- psNdefMap->ISO15693Container.ndef_seq = (uint8_t)e_wr_ndef_seq;
- return result;
-}
-
-static
-NFCSTATUS
-phFriNfc_ISO15693_H_ReadWrite (
- phFriNfc_NdefMap_t *psNdefMap,
- uint8_t command,
- uint8_t *p_data,
- uint8_t data_length)
-{
- NFCSTATUS result = NFCSTATUS_SUCCESS;
- uint8_t send_index = 0;
-
- /* set the data for additional data exchange*/
- psNdefMap->psDepAdditionalInfo.DepFlags.MetaChaining = 0;
- psNdefMap->psDepAdditionalInfo.DepFlags.NADPresent = 0;
- psNdefMap->psDepAdditionalInfo.NAD = 0;
-
- psNdefMap->MapCompletionInfo.CompletionRoutine = phFriNfc_ISO15693_Process;
- psNdefMap->MapCompletionInfo.Context = psNdefMap;
-
- *psNdefMap->SendRecvLength = psNdefMap->TempReceiveLength;
-
- psNdefMap->Cmd.Iso15693Cmd = phHal_eIso15693_Cmd;
-
- *(psNdefMap->SendRecvBuf + send_index) = (uint8_t)ISO15693_FLAGS;
- send_index = (uint8_t)(send_index + 1);
-
- *(psNdefMap->SendRecvBuf + send_index) = (uint8_t)command;
- send_index = (uint8_t)(send_index + 1);
-
- (void)memcpy ((void *)(psNdefMap->SendRecvBuf + send_index),
- (void *)psNdefMap->psRemoteDevInfo->RemoteDevInfo.Iso15693_Info.Uid,
- psNdefMap->psRemoteDevInfo->RemoteDevInfo.Iso15693_Info.UidLength);
- send_index = (uint8_t)(send_index +
- psNdefMap->psRemoteDevInfo->RemoteDevInfo.Iso15693_Info.UidLength);
-
- *(psNdefMap->SendRecvBuf + send_index) = (uint8_t)
- psNdefMap->ISO15693Container.current_block;
- send_index = (uint8_t)(send_index + 1);
-
- if ((ISO15693_WRITE_COMMAND == command) ||
- (ISO15693_READ_MULTIPLE_COMMAND == command))
- {
- (void)memcpy ((void *)(psNdefMap->SendRecvBuf + send_index),
- (void *)p_data, data_length);
- send_index = (uint8_t)(send_index + data_length);
- }
-
- psNdefMap->SendLength = send_index;
- result = phFriNfc_OvrHal_Transceive(psNdefMap->LowerDevice,
- &psNdefMap->MapCompletionInfo,
- psNdefMap->psRemoteDevInfo,
- psNdefMap->Cmd,
- &psNdefMap->psDepAdditionalInfo,
- psNdefMap->SendRecvBuf,
- psNdefMap->SendLength,
- psNdefMap->SendRecvBuf,
- psNdefMap->SendRecvLength);
-
- return result;
-}
-
-static
-NFCSTATUS
-phFriNfc_ISO15693_H_Inventory_Page_Read (
- phFriNfc_NdefMap_t *psNdefMap,
- uint8_t command,
- uint8_t page,
- uint8_t numPages)
-{
- NFCSTATUS result = NFCSTATUS_SUCCESS;
- uint8_t send_index = 0;
-
- /* set the data for additional data exchange*/
- psNdefMap->psDepAdditionalInfo.DepFlags.MetaChaining = 0;
- psNdefMap->psDepAdditionalInfo.DepFlags.NADPresent = 0;
- psNdefMap->psDepAdditionalInfo.NAD = 0;
-
- psNdefMap->MapCompletionInfo.CompletionRoutine = phFriNfc_ISO15693_Process;
- psNdefMap->MapCompletionInfo.Context = psNdefMap;
-
- *psNdefMap->SendRecvLength = psNdefMap->TempReceiveLength;
-
- psNdefMap->Cmd.Iso15693Cmd = phHal_eIso15693_Cmd;
-
- *(psNdefMap->SendRecvBuf + send_index) = INVENTORY_PAGEREAD_FLAGS;
- send_index = (uint8_t)(send_index + 1);
-
- *(psNdefMap->SendRecvBuf + send_index) = (uint8_t)command;
- send_index = (uint8_t)(send_index + 1);
-
- *(psNdefMap->SendRecvBuf + send_index) = NXP_MANUFACTURING_CODE;
- send_index = (uint8_t)(send_index + 1);
-
- *(psNdefMap->SendRecvBuf + send_index) = 0x40;
- send_index = (uint8_t)(send_index + 1);
-
- (void)memcpy ((void *)(psNdefMap->SendRecvBuf + send_index),
- (void *)psNdefMap->psRemoteDevInfo->RemoteDevInfo.Iso15693_Info.Uid,
- psNdefMap->psRemoteDevInfo->RemoteDevInfo.Iso15693_Info.UidLength);
- send_index = (uint8_t)(send_index +
- psNdefMap->psRemoteDevInfo->RemoteDevInfo.Iso15693_Info.UidLength);
-
- *(psNdefMap->SendRecvBuf + send_index) = (uint8_t)
- page;
- send_index = (uint8_t)(send_index + 1);
-
- *(psNdefMap->SendRecvBuf + send_index) = (uint8_t)
- numPages;
- send_index = (uint8_t)(send_index + 1);
-
- psNdefMap->SendLength = send_index;
-
- result = phFriNfc_OvrHal_Transceive(psNdefMap->LowerDevice,
- &psNdefMap->MapCompletionInfo,
- psNdefMap->psRemoteDevInfo,
- psNdefMap->Cmd,
- &psNdefMap->psDepAdditionalInfo,
- psNdefMap->SendRecvBuf,
- psNdefMap->SendLength,
- psNdefMap->SendRecvBuf,
- psNdefMap->SendRecvLength);
-
- return result;
-}
-
-static
-NFCSTATUS
-phFriNfc_ISO15693_Reformat_Pageread_Buffer (
- uint8_t *p_recv_buf,
- uint8_t recv_length,
- uint8_t *p_dst_buf,
- uint8_t dst_length)
-{
- // Inventory page reads return an extra security byte per page
- // So we need to reformat the returned buffer in memory
- uint32_t i = 0;
- uint32_t reformatted_index = 0;
- while (i < recv_length) {
- // Going for another page of 16 bytes, check for space in dst buffer
- if (reformatted_index + 16 > dst_length) {
- break;
- }
- if (p_recv_buf[i] == 0x0F) {
- // Security, insert 16 0 bytes
- memset(&(p_dst_buf[reformatted_index]), 0, 16);
- reformatted_index += 16;
- i++;
- } else {
- // Skip security byte
- i++;
- if (i + 16 <= recv_length) {
- memcpy(&(p_dst_buf[reformatted_index]), &(p_recv_buf[i]), 16);
- reformatted_index += 16;
- } else {
- break;
- }
- i+=16;
- }
- }
- return reformatted_index;
-}
-
-static
-NFCSTATUS
-phFriNfc_ISO15693_H_ProcessReadNdef (
- phFriNfc_NdefMap_t *psNdefMap)
-{
- NFCSTATUS result = NFCSTATUS_SUCCESS;
- phFriNfc_ISO15693Cont_t *ps_iso_15693_con =
- &(psNdefMap->ISO15693Container);
- uint16_t remaining_data_size = 0;
- uint8_t *p_recv_buf =
- (psNdefMap->SendRecvBuf + ISO15693_EXTRA_RESP_BYTE);
- uint8_t recv_length = (uint8_t)
- (*psNdefMap->SendRecvLength - ISO15693_EXTRA_RESP_BYTE);
-
- uint8_t *reformatted_buf = (uint8_t*) phOsalNfc_GetMemory(ps_iso_15693_con->max_data_size);
-
- if (ps_iso_15693_con->read_capabilities & ISO15693_CC_USE_IPR)
- {
- uint8_t reformatted_size = phFriNfc_ISO15693_Reformat_Pageread_Buffer(p_recv_buf, recv_length,
- reformatted_buf, ps_iso_15693_con->max_data_size);
- p_recv_buf = reformatted_buf + (ps_iso_15693_con->current_block * ISO15693_BYTES_PER_BLOCK);
- recv_length = reformatted_size - (ps_iso_15693_con->current_block * ISO15693_BYTES_PER_BLOCK);
- }
- if (ps_iso_15693_con->store_length)
- {
- /* Continue Offset option selected
- So stored data already existing,
- copy the information to the user buffer
- */
- if (ps_iso_15693_con->store_length
- <= (psNdefMap->ApduBufferSize - psNdefMap->ApduBuffIndex))
- {
- /* Stored data length is less than or equal
- to the user expected size */
- (void)memcpy ((void *)(psNdefMap->ApduBuffer +
- psNdefMap->ApduBuffIndex),
- (void *)ps_iso_15693_con->store_read_data,
- ps_iso_15693_con->store_length);
-
- psNdefMap->ApduBuffIndex = (uint16_t)(psNdefMap->ApduBuffIndex +
- ps_iso_15693_con->store_length);
-
- remaining_data_size = ps_iso_15693_con->store_length;
-
- ps_iso_15693_con->store_length = 0;
- }
- else
- {
- /* stored length is more than the user expected size */
- remaining_data_size = (uint16_t)(ps_iso_15693_con->store_length -
- (psNdefMap->ApduBufferSize - psNdefMap->ApduBuffIndex));
-
- (void)memcpy ((void *)(psNdefMap->ApduBuffer +
- psNdefMap->ApduBuffIndex),
- (void *)ps_iso_15693_con->store_read_data,
- remaining_data_size);
-
- /* As stored data is more than the user expected data. So store
- the remaining bytes again into the data structure */
- (void)memcpy ((void *)ps_iso_15693_con->store_read_data,
- (void *)(ps_iso_15693_con->store_read_data +
- remaining_data_size),
- (ps_iso_15693_con->store_length - remaining_data_size));
-
- psNdefMap->ApduBuffIndex = (uint16_t)(psNdefMap->ApduBuffIndex +
- remaining_data_size);
-
- ps_iso_15693_con->store_length = (uint8_t)
- (ps_iso_15693_con->store_length - remaining_data_size);
- }
- } /* if (ps_iso_15693_con->store_length) */
- else
- {
- /* Data is read from the card. */
- uint8_t byte_index = 0;
-
- remaining_data_size = ps_iso_15693_con->remaining_size_to_read;
-
- /* Check if the block number is to read the first VALUE field */
- if (ISO15693_GET_VALUE_FIELD_BLOCK_NO(ps_iso_15693_con->ndef_tlv_type_blk,
- ps_iso_15693_con->ndef_tlv_type_byte,
- ps_iso_15693_con->actual_ndef_size)
- == ps_iso_15693_con->current_block)
- {
- /* Read from the beginning option selected,
- BYTE number may start from the middle */
- byte_index = (uint8_t)ISO15693_GET_VALUE_FIELD_BYTE_NO(
- ps_iso_15693_con->ndef_tlv_type_blk,
- ps_iso_15693_con->ndef_tlv_type_byte,
- ps_iso_15693_con->actual_ndef_size);
- }
-
- if ((psNdefMap->ApduBufferSize - psNdefMap->ApduBuffIndex)
- < remaining_data_size)
- {
- remaining_data_size = (uint8_t)
- (recv_length - byte_index);
- /* user input is less than the remaining card size */
- if ((psNdefMap->ApduBufferSize - psNdefMap->ApduBuffIndex)
- < (uint16_t)remaining_data_size)
- {
- /* user data required is less than the data read */
- remaining_data_size = (uint8_t)(psNdefMap->ApduBufferSize -
- psNdefMap->ApduBuffIndex);
-
- if (0 != (recv_length - (byte_index +
- remaining_data_size)))
- {
- /* Store the data for the continue read option */
- (void)memcpy ((void *)ps_iso_15693_con->store_read_data,
- (void *)(p_recv_buf + (byte_index +
- remaining_data_size)),
- (recv_length - (byte_index +
- remaining_data_size)));
-
- ps_iso_15693_con->store_length = (uint8_t)
- (recv_length - (byte_index +
- remaining_data_size));
- }
- }
- }
- else
- {
- /* user data required is equal or greater than the data read */
- if (remaining_data_size > (recv_length - byte_index))
- {
- remaining_data_size = (uint8_t)
- (recv_length - byte_index);
- }
- }
-
- /* Copy data in the user buffer */
- (void)memcpy ((void *)(psNdefMap->ApduBuffer +
- psNdefMap->ApduBuffIndex),
- (void *)(p_recv_buf + byte_index),
- remaining_data_size);
-
- /* Update the read index */
- psNdefMap->ApduBuffIndex = (uint16_t)(psNdefMap->ApduBuffIndex +
- remaining_data_size);
-
- } /* else part of if (ps_iso_15693_con->store_length) */
-
- /* Remaining size is decremented */
- ps_iso_15693_con->remaining_size_to_read = (uint8_t)
- (ps_iso_15693_con->remaining_size_to_read -
- remaining_data_size);
-
- if ((psNdefMap->ApduBuffIndex != psNdefMap->ApduBufferSize)
- && (0 != ps_iso_15693_con->remaining_size_to_read))
- {
- ps_iso_15693_con->current_block = (uint16_t)
- (ps_iso_15693_con->current_block + 1);
- /* READ again */
- if ((ps_iso_15693_con->read_capabilities & ISO15693_CC_USE_MBR) ||
- (ps_iso_15693_con->read_capabilities & ISO15693_CC_USE_IPR)) {
- result = phFriNfc_ReadRemainingInMultiple(psNdefMap, ps_iso_15693_con->current_block);
- }
- else {
- result = phFriNfc_ISO15693_H_ReadWrite (psNdefMap, ISO15693_READ_COMMAND,
- NULL, 0);
- }
- }
- else
- {
- /* Read completed, EITHER index has reached to the user size
- OR end of the card is reached
- update the user data structure with read data size */
- *psNdefMap->NumOfBytesRead = psNdefMap->ApduBuffIndex;
- }
- if (reformatted_buf != NULL) {
- phOsalNfc_FreeMemory(reformatted_buf);
- }
- return result;
-}
-
-static
-NFCSTATUS
-phFriNfc_ISO15693_H_CheckCCBytes (
- phFriNfc_NdefMap_t *psNdefMap)
-{
- NFCSTATUS result = NFCSTATUS_SUCCESS;
- phFriNfc_ISO15693Cont_t *ps_iso_15693_con =
- &(psNdefMap->ISO15693Container);
- uint8_t recv_index = 0;
- uint8_t *p_recv_buf = (psNdefMap->SendRecvBuf + 1);
-
- /* expected CC byte : E1 40 "MAX SIZE depends on tag" */
- if (ISO15693_CC_MAGIC_BYTE == *p_recv_buf)
- {
- /* 0xE1 magic byte found*/
- recv_index = (uint8_t)(recv_index + 1);
- uint8_t tag_major_version = (*(p_recv_buf + recv_index) & ISO15693_MAJOR_VERSION_MASK) >> 6;
- if (ISO15693_MAPPING_VERSION >= tag_major_version)
- {
- /* Correct mapping version found */
- switch (*(p_recv_buf + recv_index) & ISO15693_LSB_NIBBLE_MASK)
- {
- case ISO15693_RD_WR_PERMISSION:
- {
- /* READ/WRITE possible */
- psNdefMap->CardState = PH_NDEFMAP_CARD_STATE_READ_WRITE;
- break;
- }
-
- case ISO15693_RD_ONLY_PERMISSION:
- {
- /* ONLY READ possible, WRITE NOT possible */
- psNdefMap->CardState = PH_NDEFMAP_CARD_STATE_READ_ONLY;
- break;
- }
-
- default:
- {
- result = PHNFCSTVAL(CID_FRI_NFC_NDEF_MAP,
- NFCSTATUS_NO_NDEF_SUPPORT);
- break;
- }
- }
- recv_index = (uint8_t)(recv_index + 1);
-
- if (!result)
- {
- /* Update MAX SIZE */
- ps_iso_15693_con->max_data_size = (uint16_t)
- (*(p_recv_buf + recv_index) *
- ISO15693_MULT_FACTOR);
- recv_index = (uint8_t)(recv_index + 1);
- ps_iso_15693_con->read_capabilities = (*(p_recv_buf + recv_index));
-
-
- }
- }
- else
- {
- result = PHNFCSTVAL(CID_FRI_NFC_NDEF_MAP,
- NFCSTATUS_NO_NDEF_SUPPORT);
- }
- }
- else
- {
- result = PHNFCSTVAL(CID_FRI_NFC_NDEF_MAP,
- NFCSTATUS_NO_NDEF_SUPPORT);
- }
- return result;
-}
-
-static
-NFCSTATUS
-phFriNfc_ISO15693_H_ProcessCheckNdef (
- phFriNfc_NdefMap_t *psNdefMap)
-{
- NFCSTATUS result = NFCSTATUS_SUCCESS;
- phFriNfc_ISO15693Cont_t *ps_iso_15693_con =
- &(psNdefMap->ISO15693Container);
- phFriNfc_eChkNdefSeq_t e_chk_ndef_seq = (phFriNfc_eChkNdefSeq_t)
- psNdefMap->ISO15693Container.ndef_seq;
-
- uint8_t *p_recv_buf =
- (psNdefMap->SendRecvBuf + ISO15693_EXTRA_RESP_BYTE);
- uint8_t recv_length = (uint8_t)
- (*psNdefMap->SendRecvLength - ISO15693_EXTRA_RESP_BYTE);
- uint8_t parse_index = 0;
- static uint16_t prop_ndef_index = 0;
- uint8_t *reformatted_buf = (uint8_t*) phOsalNfc_GetMemory(ps_iso_15693_con->max_data_size);
-
- if (0 == ps_iso_15693_con->current_block)
- {
- /* Check CC byte */
- result = phFriNfc_ISO15693_H_CheckCCBytes (psNdefMap);
- parse_index = (uint8_t)(parse_index + recv_length);
- }
- else if (1 == ps_iso_15693_con->current_block &&
- (ps_iso_15693_con->read_capabilities & ISO15693_CC_USE_IPR))
- {
-
- uint8_t reformatted_size = phFriNfc_ISO15693_Reformat_Pageread_Buffer(p_recv_buf, recv_length,
- reformatted_buf, ps_iso_15693_con->max_data_size);
- // Skip initial CC bytes
- p_recv_buf = reformatted_buf + (ps_iso_15693_con->current_block * ISO15693_BYTES_PER_BLOCK);
- recv_length = reformatted_size - (ps_iso_15693_con->current_block * ISO15693_BYTES_PER_BLOCK);
- }
- else
- {
- /* Propreitary TLVs VALUE can end in between a block,
- so when that block is read, update the parse_index
- with byte address value */
- if (ISO15693_PROP_TLV_V == e_chk_ndef_seq)
- {
- parse_index = ps_iso_15693_con->ndef_tlv_type_byte;
- e_chk_ndef_seq = ISO15693_NDEF_TLV_T;
- }
- }
-
- while ((parse_index < recv_length)
- && (NFCSTATUS_SUCCESS == result)
- && (ISO15693_NDEF_TLV_V != e_chk_ndef_seq))
- {
- /* Parse
- 1. till the received length of the block
- 2. till there is no error during parse
- 3. till LENGTH field of NDEF TLV is found
- */
- switch (e_chk_ndef_seq)
- {
- case ISO15693_NDEF_TLV_T:
- {
- /* Expected value is 0x03 TYPE identifier
- of the NDEF TLV */
- prop_ndef_index = 0;
- switch (*(p_recv_buf + parse_index))
- {
- case ISO15693_NDEF_TLV_TYPE_ID:
- {
- /* Update the data structure with the byte address and
- the block number */
- ps_iso_15693_con->ndef_tlv_type_byte = parse_index;
- ps_iso_15693_con->ndef_tlv_type_blk =
- ps_iso_15693_con->current_block;
- e_chk_ndef_seq = ISO15693_NDEF_TLV_L;
-
- break;
- }
-
- case ISO15693_NULL_TLV_ID:
- {
- /* Dont do any thing, go to next byte */
- break;
- }
-
- case ISO15693_PROP_TLV_ID:
- {
- /* Move the sequence to find the length
- of the proprietary TLV */
- e_chk_ndef_seq = ISO15693_PROP_TLV_L;
- break;
- }
-
- default:
- {
- result = PHNFCSTVAL(CID_FRI_NFC_NDEF_MAP,
- NFCSTATUS_NO_NDEF_SUPPORT);
- break;
- }
- } /* switch (*(p_recv_buf + parse_index)) */
- break;
- }
-
- case ISO15693_PROP_TLV_L:
- {
- /* Length field of the proprietary TLV */
- switch (prop_ndef_index)
- {
- /* Length field can have 1 or 3 bytes depending
- on the data size, so check for each index byte */
- case 0:
- {
- /* 1st index of the length field of the TLV */
- if (0 == *(p_recv_buf + parse_index))
- {
- /* LENGTH is 0, not possible, so error */
- result = PHNFCSTVAL(CID_FRI_NFC_NDEF_MAP,
- NFCSTATUS_NO_NDEF_SUPPORT);
- e_chk_ndef_seq = ISO15693_NDEF_TLV_T;
- }
- else
- {
- if (ISO15693_THREE_BYTE_LENGTH_ID ==
- *(p_recv_buf + parse_index))
- {
- /* 3 byte LENGTH field identified, so increment the
- index, so next time 2nd byte is parsed */
- prop_ndef_index = (uint8_t)(prop_ndef_index + 1);
- }
- else
- {
- /* 1 byte LENGTH field identified, so "static"
- index is set to 0 and actual ndef size is
- copied to the data structure
- */
- ps_iso_15693_con->actual_ndef_size =
- *(p_recv_buf + parse_index);
- e_chk_ndef_seq = ISO15693_PROP_TLV_V;
- prop_ndef_index = 0;
- }
- }
- break;
- }
-
- case 1:
- {
- /* 2nd index of the LENGTH field that is MSB of the length,
- so the length is left shifted by 8 */
- ps_iso_15693_con->actual_ndef_size = (uint16_t)
- (*(p_recv_buf + parse_index) <<
- ISO15693_BTYE_SHIFT);
- prop_ndef_index = (uint8_t)(prop_ndef_index + 1);
- break;
- }
-
- case 2:
- {
- /* 3rd index of the LENGTH field that is LSB of the length,
- so the length ORed with the previously stored size */
- ps_iso_15693_con->actual_ndef_size = (uint16_t)
- (ps_iso_15693_con->actual_ndef_size |
- *(p_recv_buf + parse_index));
-
- e_chk_ndef_seq = ISO15693_PROP_TLV_V;
- prop_ndef_index = 0;
- break;
- }
-
- default:
- {
- result = PHNFCSTVAL(CID_FRI_NFC_NDEF_MAP,
- NFCSTATUS_INVALID_DEVICE_REQUEST);
- break;
- }
- } /* switch (prop_ndef_index) */
-
- if ((ISO15693_PROP_TLV_V == e_chk_ndef_seq)
- && (ISO15693_GET_REMAINING_SIZE(ps_iso_15693_con->max_data_size,
- ps_iso_15693_con->current_block, parse_index)
- <= ps_iso_15693_con->actual_ndef_size))
- {
- /* Check for the length field value has not exceeded the card size,
- if size is exceeded or then return error */
- e_chk_ndef_seq = ISO15693_NDEF_TLV_T;
- result = PHNFCSTVAL(CID_FRI_NFC_NDEF_MAP,
- NFCSTATUS_NO_NDEF_SUPPORT);
- }
- else
- {
- uint16_t prop_byte_addr = 0;
-
- /* skip the proprietary TLVs value field */
- prop_byte_addr = (uint16_t)
- ((ps_iso_15693_con->current_block * ISO15693_BYTES_PER_BLOCK) +
- parse_index + ps_iso_15693_con->actual_ndef_size);
-
- ps_iso_15693_con->ndef_tlv_type_byte = (uint8_t)(prop_byte_addr %
- ISO15693_BYTES_PER_BLOCK);
- ps_iso_15693_con->ndef_tlv_type_blk = (uint16_t)(prop_byte_addr /
- ISO15693_BYTES_PER_BLOCK);
- if (parse_index + ps_iso_15693_con->actual_ndef_size >=
- recv_length)
- {
- parse_index = (uint8_t)recv_length;
- }
- else
- {
- parse_index = (uint8_t)(parse_index +
- ps_iso_15693_con->actual_ndef_size);
- }
-
- }
- break;
- } /* case ISO15693_PROP_TLV_L: */
-
- case ISO15693_PROP_TLV_V:
- {
- uint8_t remaining_length = (uint8_t)(recv_length -
- parse_index);
-
- if ((ps_iso_15693_con->actual_ndef_size - prop_ndef_index)
- > remaining_length)
- {
- parse_index = (uint8_t)(parse_index + remaining_length);
- prop_ndef_index = (uint8_t)(prop_ndef_index + remaining_length);
- }
- else if ((ps_iso_15693_con->actual_ndef_size - prop_ndef_index)
- == remaining_length)
- {
- parse_index = (uint8_t)(parse_index + remaining_length);
- e_chk_ndef_seq = ISO15693_NDEF_TLV_T;
- prop_ndef_index = 0;
- }
- else
- {
- parse_index = (uint8_t)(parse_index +
- (ps_iso_15693_con->actual_ndef_size -
- prop_ndef_index));
- e_chk_ndef_seq = ISO15693_NDEF_TLV_T;
- prop_ndef_index = 0;
- }
- break;
- } /* case ISO15693_PROP_TLV_V: */
-
- case ISO15693_NDEF_TLV_L:
- {
- /* Length field of the NDEF TLV */
- switch (prop_ndef_index)
- {
- /* Length field can have 1 or 3 bytes depending
- on the data size, so check for each index byte */
- case 0:
- {
- /* 1st index of the length field of the TLV */
- if (0 == *(p_recv_buf + parse_index))
- {
- /* LENGTH is 0, card is in INITILIASED STATE */
- e_chk_ndef_seq = ISO15693_NDEF_TLV_V;
- ps_iso_15693_con->actual_ndef_size = 0;
- }
- else
- {
- prop_ndef_index = (uint8_t)(prop_ndef_index + 1);
-
- if (ISO15693_THREE_BYTE_LENGTH_ID ==
- *(p_recv_buf + parse_index))
- {
- /* At present no CARD supports more than 255 bytes,
- so error is returned */
- prop_ndef_index = (uint8_t)(prop_ndef_index + 1);
- result = PHNFCSTVAL(CID_FRI_NFC_NDEF_MAP,
- NFCSTATUS_NO_NDEF_SUPPORT);
- prop_ndef_index = 0;
- }
- else
- {
- /* 1 byte LENGTH field identified, so "static"
- index is set to 0 and actual ndef size is
- copied to the data structure
- */
- ps_iso_15693_con->actual_ndef_size =
- *(p_recv_buf + parse_index);
- /* next values are the DATA field of the NDEF TLV */
- e_chk_ndef_seq = ISO15693_NDEF_TLV_V;
- prop_ndef_index = 0;
- }
- }
- break;
- }
-
- case 1:
- {
- /* 2nd index of the LENGTH field that is MSB of the length,
- so the length is left shifted by 8 */
- ps_iso_15693_con->actual_ndef_size = (uint16_t)
- (*(p_recv_buf + parse_index) <<
- ISO15693_BTYE_SHIFT);
- prop_ndef_index = (uint8_t)(prop_ndef_index + 1);
- break;
- }
-
- case 2:
- {
- /* 3rd index of the LENGTH field that is LSB of the length,
- so the length ORed with the previously stored size */
- ps_iso_15693_con->actual_ndef_size = (uint16_t)
- (ps_iso_15693_con->actual_ndef_size |
- *(p_recv_buf + parse_index));
-
- e_chk_ndef_seq = ISO15693_NDEF_TLV_V;
- prop_ndef_index = 0;
- break;
- }
-
- default:
- {
- result = PHNFCSTVAL(CID_FRI_NFC_NDEF_MAP,
- NFCSTATUS_INVALID_DEVICE_REQUEST);
- break;
- }
- } /* switch (prop_ndef_index) */
-
- if ((ISO15693_NDEF_TLV_V == e_chk_ndef_seq)
- && (ISO15693_GET_REMAINING_SIZE(ps_iso_15693_con->max_data_size,
- /* parse_index + 1 is done because the data starts from the next index.
- "MOD" operation is used to know that parse_index >
- ISO15693_BYTES_PER_BLOCK, then block shall be incremented
- */
- (((parse_index + 1) % ISO15693_BYTES_PER_BLOCK) ?
- ps_iso_15693_con->current_block :
- ps_iso_15693_con->current_block + 1), ((parse_index + 1) %
- ISO15693_BYTES_PER_BLOCK))
- < ps_iso_15693_con->actual_ndef_size))
- {
- /* Check for the length field value has not exceeded the card size */
- e_chk_ndef_seq = ISO15693_NDEF_TLV_T;
- result = PHNFCSTVAL(CID_FRI_NFC_NDEF_MAP,
- NFCSTATUS_NO_NDEF_SUPPORT);
- }
- else
- {
- psNdefMap->CardState = (uint8_t)
- ((PH_NDEFMAP_CARD_STATE_READ_ONLY
- == psNdefMap->CardState) ?
- PH_NDEFMAP_CARD_STATE_READ_ONLY :
- ((ps_iso_15693_con->actual_ndef_size) ?
- PH_NDEFMAP_CARD_STATE_READ_WRITE :
- PH_NDEFMAP_CARD_STATE_INITIALIZED));
- }
- break;
- } /* case ISO15693_NDEF_TLV_L: */
-
- case ISO15693_NDEF_TLV_V:
- {
- break;
- }
-
- default:
- {
- result = PHNFCSTVAL(CID_FRI_NFC_NDEF_MAP,
- NFCSTATUS_INVALID_DEVICE_REQUEST);
- break;
- }
- } /* switch (e_chk_ndef_seq) */
- parse_index = (uint8_t)(parse_index + 1);
- } /* while ((parse_index < recv_length)
- && (NFCSTATUS_SUCCESS == result)
- && (ISO15693_NDEF_TLV_V != e_chk_ndef_seq)) */
-
- if (result)
- {
- /* Error returned while parsing, so STOP read */
- e_chk_ndef_seq = ISO15693_NDEF_TLV_T;
- prop_ndef_index = 0;
- }
- else if (ISO15693_NDEF_TLV_V != e_chk_ndef_seq)
- {
- /* READ again */
- if (ISO15693_PROP_TLV_V != e_chk_ndef_seq)
- {
- ps_iso_15693_con->current_block = (uint16_t)
- (ps_iso_15693_con->current_block + 1);
- }
- else
- {
- /* Proprietary TLV detected, so skip the proprietary blocks */
- ps_iso_15693_con->current_block = ps_iso_15693_con->ndef_tlv_type_blk;
- }
-
- uint32_t remaining_size = ISO15693_GET_REMAINING_SIZE(ps_iso_15693_con->max_data_size,
- ps_iso_15693_con->current_block, 0);
- if (remaining_size > 0)
- {
- if ((ps_iso_15693_con->read_capabilities & ISO15693_CC_USE_MBR) ||
- (ps_iso_15693_con->read_capabilities & ISO15693_CC_USE_IPR)) {
- result = phFriNfc_ReadRemainingInMultiple(psNdefMap, ps_iso_15693_con->current_block);
- } else {
- result = phFriNfc_ISO15693_H_ReadWrite (psNdefMap, ISO15693_READ_COMMAND,
- NULL, 0);
- }
- }
- else
- {
- /* End of card reached, error no NDEF information found */
- e_chk_ndef_seq = ISO15693_NDEF_TLV_T;
- prop_ndef_index = 0;
- /* Error, no size to parse */
- result = PHNFCSTVAL(CID_FRI_NFC_NDEF_MAP,
- NFCSTATUS_NO_NDEF_SUPPORT);
- }
-
- }
- else
- {
- /* Successful read with proper NDEF information updated */
- prop_ndef_index = 0;
- e_chk_ndef_seq = ISO15693_NDEF_TLV_T;
- psNdefMap->CardType = (uint8_t)PH_FRINFC_NDEFMAP_ISO15693_CARD;
- }
-
- psNdefMap->ISO15693Container.ndef_seq = (uint8_t)e_chk_ndef_seq;
-
- if (reformatted_buf != NULL) {
- phOsalNfc_FreeMemory(reformatted_buf);
- }
- return result;
-}
-
-static
-void
-phFriNfc_ISO15693_H_Complete (
- phFriNfc_NdefMap_t *psNdefMap,
- NFCSTATUS Status)
-{
- /* set the state back to the RESET_INIT state*/
- psNdefMap->State = PH_FRINFC_NDEFMAP_STATE_RESET_INIT;
-
- /* set the completion routine*/
- psNdefMap->CompletionRoutine[psNdefMap->ISO15693Container.cr_index].
- CompletionRoutine (psNdefMap->CompletionRoutine->Context, Status);
-}
-
-#ifdef FRINFC_READONLY_NDEF
-
-static
-NFCSTATUS
-phFriNfc_ISO15693_H_ProcessReadOnly (
- phFriNfc_NdefMap_t *psNdefMap)
-{
- NFCSTATUS result = NFCSTATUS_SUCCESS;
- phFriNfc_ISO15693Cont_t *ps_iso_15693_con =
- &(psNdefMap->ISO15693Container);
- phFriNfc_eRONdefSeq_t e_ro_ndef_seq = (phFriNfc_eRONdefSeq_t)
- ps_iso_15693_con->ndef_seq;
- uint8_t *p_recv_buf = (psNdefMap->SendRecvBuf +
- ISO15693_EXTRA_RESP_BYTE);
- uint8_t recv_length = (uint8_t)(*psNdefMap->SendRecvLength -
- ISO15693_EXTRA_RESP_BYTE);
- uint8_t a_write_buf[ISO15693_BYTES_PER_BLOCK] = {0};
-
- switch (e_ro_ndef_seq)
- {
- case ISO15693_RD_BEFORE_WR_CC:
- {
- if (ISO15693_SINGLE_BLK_RD_RESP_LEN == recv_length)
- {
- result = phFriNfc_ISO15693_H_CheckCCBytes (psNdefMap);
- /* Check CC bytes and also the card state for READ ONLY,
- if the card is already read only, then dont continue with
- next operation */
- if ((PH_NDEFMAP_CARD_STATE_READ_ONLY != psNdefMap->CardState)
- && (!result))
- {
- /* CC byte read successful */
- (void)memcpy ((void *)a_write_buf, (void *)p_recv_buf,
- sizeof (a_write_buf));
-
- /* Change the read write access to read only */
- *(a_write_buf + ISO15693_RW_BTYE_INDEX) = (uint8_t)
- (*(a_write_buf + ISO15693_RW_BTYE_INDEX) |
- ISO15693_CC_READ_ONLY_MASK);
-
- result = phFriNfc_ISO15693_H_ReadWrite (psNdefMap,
- ISO15693_WRITE_COMMAND, a_write_buf,
- sizeof (a_write_buf));
-
- e_ro_ndef_seq = ISO15693_WRITE_CC;
- }
- }
- break;
- }
-
- case ISO15693_WRITE_CC:
- {
- /* Write to CC is successful. */
- e_ro_ndef_seq = ISO15693_LOCK_BLOCK;
- /* Start the lock block command to lock the blocks */
- result = phFriNfc_ISO15693_H_ReadWrite (psNdefMap,
- ISO15693_LOCK_BLOCK_CMD, NULL, 0);
- break;
- }
-
- case ISO15693_LOCK_BLOCK:
- {
- if (ps_iso_15693_con->current_block ==
- ((ps_iso_15693_con->max_data_size / ISO15693_BYTES_PER_BLOCK) -
- 1))
- {
- /* End of card reached, READ ONLY successful */
- }
- else
- {
- /* current block is incremented */
- ps_iso_15693_con->current_block = (uint16_t)
- (ps_iso_15693_con->current_block + 1);
- /* Lock the current block */
- result = phFriNfc_ISO15693_H_ReadWrite (psNdefMap,
- ISO15693_LOCK_BLOCK_CMD, NULL, 0);
- }
- break;
- }
-
- default:
- {
- break;
- }
- }
-
- ps_iso_15693_con->ndef_seq = (uint8_t)e_ro_ndef_seq;
- return result;
-}
-
-#endif /* #ifdef FRINFC_READONLY_NDEF */
-/************************** END static functions definition *********************/
-
-/************************** START external functions *********************/
-
-NFCSTATUS
-phFriNfc_ISO15693_ChkNdef (
- phFriNfc_NdefMap_t *psNdefMap)
-{
- NFCSTATUS result = NFCSTATUS_SUCCESS;
- phHal_sIso15693Info_t *ps_iso_15693_info =
- &(psNdefMap->psRemoteDevInfo->RemoteDevInfo.Iso15693_Info);
-
- /* Update the previous operation with current operation.
- This becomes the previous operation after this execution */
- psNdefMap->PrevOperation = PH_FRINFC_NDEFMAP_CHECK_OPE;
- /* Update the CR index to know from which operation completion
- routine has to be called */
- psNdefMap->ISO15693Container.cr_index = PH_FRINFC_NDEFMAP_CR_CHK_NDEF;
- /* State update */
- psNdefMap->State = ISO15693_CHECK_NDEF;
- /* Reset the NDEF sequence */
- psNdefMap->ISO15693Container.ndef_seq = 0;
- psNdefMap->ISO15693Container.current_block = 0;
- psNdefMap->ISO15693Container.actual_ndef_size = 0;
- psNdefMap->ISO15693Container.ndef_tlv_type_blk = 0;
- psNdefMap->ISO15693Container.ndef_tlv_type_byte = 0;
- psNdefMap->ISO15693Container.store_length = 0;
- psNdefMap->ISO15693Container.remaining_size_to_read = 0;
- psNdefMap->ISO15693Container.read_capabilities = 0;
-
- if ((ISO15693_UIDBYTE_6_VALUE ==
- ps_iso_15693_info->Uid[ISO15693_UID_BYTE_6])
- && (ISO15693_UIDBYTE_7_VALUE ==
- ps_iso_15693_info->Uid[ISO15693_UID_BYTE_7]))
- {
- /* Check if the card is manufactured by NXP (6th byte
- index of UID value = 0x04 and the
- last byte i.e., 7th byte of UID is 0xE0, only then the card detected
- is NDEF compliant */
- switch (ps_iso_15693_info->Uid[ISO15693_UID_BYTE_5])
- {
- /* Check for supported tags, by checking the 5th byte index of UID */
- case ISO15693_UIDBYTE_5_VALUE_SLI_X:
- {
- /* ISO 15693 card type is ICODE SLI
- so maximum size is 112 */
- psNdefMap->ISO15693Container.max_data_size =
- ISO15693_SL2_S2002_ICS20;
- break;
- }
-
- case ISO15693_UIDBYTE_5_VALUE_SLI_X_S:
- {
- /* ISO 15693 card type is ICODE SLI/X S
- so maximum size depends on the 4th UID byte index */
- switch (ps_iso_15693_info->Uid[ISO15693_UID_BYTE_4])
- {
- case ISO15693_UIDBYTE_4_VALUE_SLI_X_S:
- case ISO15693_UIDBYTE_4_VALUE_SLI_X_SHC:
- case ISO15693_UIDBYTE_4_VALUE_SLI_X_SY:
- {
- /* Supported tags are with value (4th byte UID index)
- of 0x00, 0x80 and 0x40
- For these cards max size is 160 bytes */
- psNdefMap->ISO15693Container.max_data_size =
- ISO15693_SL2_S5302_ICS53_ICS54;
- break;
- }
-
- default:
- {
- /* Tag not supported */
- result = PHNFCSTVAL(CID_FRI_NFC_NDEF_MAP,
- NFCSTATUS_INVALID_DEVICE_REQUEST);
- break;
- }
- }
- break;
- }
-
- case ISO15693_UIDBYTE_5_VALUE_SLI_X_L:
- {
- /* ISO 15693 card type is ICODE SLI/X L
- so maximum size depends on the 4th UID byte index */
- switch (ps_iso_15693_info->Uid[ISO15693_UID_BYTE_4])
- {
- case ISO15693_UIDBYTE_4_VALUE_SLI_X_L:
- case ISO15693_UIDBYTE_4_VALUE_SLI_X_LHC:
- {
- /* Supported tags are with value (4th byte UID index)
- of 0x00 and 0x80
- For these cards max size is 32 bytes */
- psNdefMap->ISO15693Container.max_data_size =
- ISO15693_SL2_S5002_ICS50_ICS51;
- break;
- }
-
- default:
- {
- /* Tag not supported */
- result = PHNFCSTVAL(CID_FRI_NFC_NDEF_MAP,
- NFCSTATUS_INVALID_DEVICE_REQUEST);
- break;
- }
- }
- break;
- }
-
- default:
- {
- /* Tag not supported */
- result = PHNFCSTVAL(CID_FRI_NFC_NDEF_MAP,
- NFCSTATUS_INVALID_DEVICE_REQUEST);
- break;
- }
- }
- }
- else
- {
- /* Tag not supported */
- result = PHNFCSTVAL(CID_FRI_NFC_NDEF_MAP,
- NFCSTATUS_INVALID_DEVICE_REQUEST);
- }
-
- if (!result)
- {
- /* Start reading the data */
- result = phFriNfc_ISO15693_H_ReadWrite (psNdefMap, ISO15693_READ_COMMAND,
- NULL, 0);
- }
-
-
- return result;
-}
-
-NFCSTATUS
-phFriNfc_ISO15693_RdNdef (
- phFriNfc_NdefMap_t *psNdefMap,
- uint8_t *pPacketData,
- uint32_t *pPacketDataLength,
- uint8_t Offset)
-{
- NFCSTATUS result = NFCSTATUS_SUCCESS;
- phFriNfc_ISO15693Cont_t *ps_iso_15693_con =
- &(psNdefMap->ISO15693Container);
-
- /* Update the previous operation with current operation.
- This becomes the previous operation after this execution */
- psNdefMap->PrevOperation = PH_FRINFC_NDEFMAP_READ_OPE;
- /* Update the CR index to know from which operation completion
- routine has to be called */
- psNdefMap->ISO15693Container.cr_index = PH_FRINFC_NDEFMAP_CR_RD_NDEF;
- /* State update */
- psNdefMap->State = ISO15693_READ_NDEF;
- /* Copy user buffer to the context */
- psNdefMap->ApduBuffer = pPacketData;
- /* Copy user length to the context */
- psNdefMap->ApduBufferSize = *pPacketDataLength;
- /* Update the user memory size to a context variable */
- psNdefMap->NumOfBytesRead = pPacketDataLength;
- /* Number of bytes read from the card is zero.
- This variable returns the number of bytes read
- from the card. */
- *psNdefMap->NumOfBytesRead = 0;
- /* Index to know the length read */
- psNdefMap->ApduBuffIndex = 0;
- /* Store the offset in the context */
- psNdefMap->Offset = Offset;
-
- if ((!ps_iso_15693_con->remaining_size_to_read)
- && (!psNdefMap->Offset))
- {
- /* Entire data is already read from the card.
- There is no data to give */
- result = PHNFCSTVAL(CID_FRI_NFC_NDEF_MAP,
- NFCSTATUS_EOF_NDEF_CONTAINER_REACHED);
- }
- else if (0 == ps_iso_15693_con->actual_ndef_size)
- {
- /* Card is NDEF, but no data in the card. */
- result = PHNFCSTVAL(CID_FRI_NFC_NDEF_MAP,
- NFCSTATUS_READ_FAILED);
- }
- else if (PH_NDEFMAP_CARD_STATE_INITIALIZED == psNdefMap->CardState)
- {
- /* Card is NDEF, but no data in the card. */
- result = PHNFCSTVAL(CID_FRI_NFC_NDEF_MAP,
- NFCSTATUS_READ_FAILED);
- }
- else if (psNdefMap->Offset)
- {
- /* BEGIN offset, so reset the remaining read size and
- also the curretn block */
- ps_iso_15693_con->remaining_size_to_read =
- ps_iso_15693_con->actual_ndef_size;
- ps_iso_15693_con->current_block =
- ISO15693_GET_VALUE_FIELD_BLOCK_NO(
- ps_iso_15693_con->ndef_tlv_type_blk,
- ps_iso_15693_con->ndef_tlv_type_byte,
- ps_iso_15693_con->actual_ndef_size);
-
- // Check capabilities
- if ((ps_iso_15693_con->read_capabilities & ISO15693_CC_USE_MBR) ||
- (ps_iso_15693_con->read_capabilities & ISO15693_CC_USE_IPR)) {
- result = phFriNfc_ReadRemainingInMultiple(psNdefMap, ps_iso_15693_con->current_block);
- } else {
- result = phFriNfc_ISO15693_H_ReadWrite (psNdefMap, ISO15693_READ_COMMAND,
- NULL, 0);
- }
- }
- else
- {
- /* CONTINUE offset */
- if (ps_iso_15693_con->store_length > 0)
- {
- /* Previous read had extra bytes, so data is stored, so give that take
- that data from store. If more data is required, then read remaining bytes */
- result = phFriNfc_ISO15693_H_ProcessReadNdef (psNdefMap);
- }
- else
- {
- ps_iso_15693_con->current_block = (uint16_t)
- (ps_iso_15693_con->current_block + 1);
- result = phFriNfc_ISO15693_H_ReadWrite (psNdefMap,
- ISO15693_READ_COMMAND, NULL, 0);
- }
- }
-
- return result;
-}
-
-static
-NFCSTATUS
-phFriNfc_ReadRemainingInMultiple (
- phFriNfc_NdefMap_t *psNdefMap,
- uint32_t startBlock)
-{
- NFCSTATUS result = NFCSTATUS_FAILED;
- phFriNfc_ISO15693Cont_t *ps_iso_15693_con = &(psNdefMap->ISO15693Container);
-
- uint32_t remaining_size = ISO15693_GET_REMAINING_SIZE(ps_iso_15693_con->max_data_size,
- startBlock, 0);
- // Check capabilities
- if (ps_iso_15693_con->read_capabilities & ISO15693_CC_USE_MBR) {
- // Multi-page read command
- uint8_t mbread[1];
- mbread[0] = (remaining_size / ISO15693_BYTES_PER_BLOCK) - 1;
- result = phFriNfc_ISO15693_H_ReadWrite (psNdefMap, ISO15693_READ_MULTIPLE_COMMAND,
- mbread, 1);
- } else if (ps_iso_15693_con->read_capabilities & ISO15693_CC_USE_IPR) {
- uint32_t page = 0;
- uint32_t pagesToRead = (remaining_size / ISO15693_BYTES_PER_BLOCK / 4) - 1;
- if ((remaining_size % (ISO15693_BYTES_PER_BLOCK * ISO15693_BLOCKS_PER_PAGE)) != 0) {
- pagesToRead++;
- }
- result = phFriNfc_ISO15693_H_Inventory_Page_Read (psNdefMap, ICODE_INVENTORY_PAGEREAD_COMMAND,
- page, pagesToRead);
- // Inventory
- } else {
- result = NFCSTATUS_FAILED;
- }
- return result;
-}
-
-NFCSTATUS
-phFriNfc_ISO15693_WrNdef (
- phFriNfc_NdefMap_t *psNdefMap,
- uint8_t *pPacketData,
- uint32_t *pPacketDataLength,
- uint8_t Offset)
-{
- NFCSTATUS result = NFCSTATUS_SUCCESS;
- phFriNfc_ISO15693Cont_t *ps_iso_15693_con =
- &(psNdefMap->ISO15693Container);
- uint8_t a_write_buf[ISO15693_BYTES_PER_BLOCK] = {0};
-
- /* Update the previous operation with current operation.
- This becomes the previous operation after this execution */
- psNdefMap->PrevOperation = PH_FRINFC_NDEFMAP_WRITE_OPE;
- /* Update the CR index to know from which operation completion
- routine has to be called */
- psNdefMap->ISO15693Container.cr_index = PH_FRINFC_NDEFMAP_CR_WR_NDEF;
- /* State update */
- psNdefMap->State = ISO15693_WRITE_NDEF;
- /* Copy user buffer to the context */
- psNdefMap->ApduBuffer = pPacketData;
- /* Copy user length to the context */
- psNdefMap->ApduBufferSize = *pPacketDataLength;
- /* Update the user memory size to a context variable */
- psNdefMap->NumOfBytesRead = pPacketDataLength;
- /* Number of bytes written to the card is zero.
- This variable returns the number of bytes written
- to the card. */
- *psNdefMap->WrNdefPacketLength = 0;
- /* Index to know the length read */
- psNdefMap->ApduBuffIndex = 0;
- /* Store the offset in the context */
- psNdefMap->Offset = Offset;
-
- /* Set the current block correctly to write the length field to 0 */
- ps_iso_15693_con->current_block =
- ISO15693_GET_LEN_FIELD_BLOCK_NO(
- ps_iso_15693_con->ndef_tlv_type_blk,
- ps_iso_15693_con->ndef_tlv_type_byte,
- *pPacketDataLength);
-
- if (ISO15693_GET_LEN_FIELD_BYTE_NO(
- ps_iso_15693_con->ndef_tlv_type_blk,
- ps_iso_15693_con->ndef_tlv_type_byte,
- *pPacketDataLength))
- {
- /* Check the byte address to write. If length byte address is in between or
- is the last byte of the block, then READ before write
- reason, write should not corrupt other data
- */
- ps_iso_15693_con->ndef_seq = (uint8_t)ISO15693_RD_BEFORE_WR_NDEF_L_0;
- result = phFriNfc_ISO15693_H_ReadWrite (psNdefMap,
- ISO15693_READ_COMMAND, NULL, 0);
- }
- else
- {
- /* If length byte address is at the beginning of the block then WRITE
- length field to 0 and as also write user DATA */
- ps_iso_15693_con->ndef_seq = (uint8_t)ISO15693_WRITE_DATA;
-
- /* Length is made 0x00 */
- *a_write_buf = 0x00;
-
- /* Write remaining data */
- (void)memcpy ((void *)(a_write_buf + 1),
- (void *)psNdefMap->ApduBuffer,
- (ISO15693_BYTES_PER_BLOCK - 1));
-
- /* Write data */
- result = phFriNfc_ISO15693_H_ReadWrite (psNdefMap,
- ISO15693_WRITE_COMMAND,
- a_write_buf, ISO15693_BYTES_PER_BLOCK);
-
- /* Increment the index to keep track of bytes sent for write */
- psNdefMap->ApduBuffIndex = (uint16_t)(psNdefMap->ApduBuffIndex
- + (ISO15693_BYTES_PER_BLOCK - 1));
- }
-
- return result;
-}
-
-#ifdef FRINFC_READONLY_NDEF
-
-NFCSTATUS
-phFriNfc_ISO15693_ConvertToReadOnly (
- phFriNfc_NdefMap_t *psNdefMap)
-{
- NFCSTATUS result = NFCSTATUS_SUCCESS;
- phFriNfc_ISO15693Cont_t *ps_iso_15693_con =
- &(psNdefMap->ISO15693Container);
-
- psNdefMap->State = ISO15693_READ_ONLY_NDEF;
- /* READ CC bytes */
- ps_iso_15693_con->ndef_seq = (uint8_t)ISO15693_RD_BEFORE_WR_CC;
- ps_iso_15693_con->current_block = 0;
-
- result = phFriNfc_ISO15693_H_ReadWrite (psNdefMap,
- ISO15693_READ_COMMAND, NULL, 0);
-
- return result;
-}
-
-#endif /* #ifdef FRINFC_READONLY_NDEF */
-
-
-void
-phFriNfc_ISO15693_Process (
- void *pContext,
- NFCSTATUS Status)
-{
- phFriNfc_NdefMap_t *psNdefMap =
- (phFriNfc_NdefMap_t *)pContext;
-
- if ((NFCSTATUS_SUCCESS & PHNFCSTBLOWER) == (Status & PHNFCSTBLOWER))
- {
- switch (psNdefMap->State)
- {
- case ISO15693_CHECK_NDEF:
- {
- /* State = CHECK NDEF in progress */
- Status = phFriNfc_ISO15693_H_ProcessCheckNdef (psNdefMap);
- break;
- }
-
- case ISO15693_READ_NDEF:
- {
- /* State = READ NDEF in progress */
- Status = phFriNfc_ISO15693_H_ProcessReadNdef (psNdefMap);
- break;
- }
-
- case ISO15693_WRITE_NDEF:
- {
- /* State = WRITE NDEF in progress */
- Status = phFriNfc_ISO15693_H_ProcessWriteNdef (psNdefMap);
- break;
- }
-
-#ifdef FRINFC_READONLY_NDEF
- case ISO15693_READ_ONLY_NDEF:
- {
- /* State = RAD ONLY NDEF in progress */
- Status = phFriNfc_ISO15693_H_ProcessReadOnly (psNdefMap);
- break;
- }
-#endif /* #ifdef FRINFC_READONLY_NDEF */
-
- default:
- {
- break;
- }
- }
- }
-
- /* Call for the Completion Routine*/
- if (NFCSTATUS_PENDING != Status)
- {
- phFriNfc_ISO15693_H_Complete(psNdefMap, Status);
- }
-}
-
-/************************** END external functions *********************/
-
-#endif /* #ifndef PH_FRINFC_MAP_ISO15693_DISABLED */
diff --git a/libnfc-nxp/phFriNfc_ISO15693Map.h b/libnfc-nxp/phFriNfc_ISO15693Map.h
deleted file mode 100644
index f4c0c08..0000000
--- a/libnfc-nxp/phFriNfc_ISO15693Map.h
+++ /dev/null
@@ -1,219 +0,0 @@
-/*
- *
- * Copyright (C) 2010 NXP Semiconductors
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-/*
- * \file phFriNfc_ISO15693Map.h
- * \brief NFC Ndef Mapping For ISO-15693 Smart Card.
- *
- * Project: NFC-FRI
- *
- * $Date: $
- * $Author: ing02260 $
- * $Revision: $
- * $Aliases: $
- *
- */
-
-#ifndef PHFRINFC_ISO15693MAP_H
-#define PHFRINFC_ISO15693MAP_H
-
-/************************** START MACROS definition *********************/
-/* BYTES in a BLOCK */
-#define ISO15693_BYTES_PER_BLOCK 0x04U
-/* BLOCKS per page */
-#define ISO15693_BLOCKS_PER_PAGE 0x04U
-/* 3 BYTE value identifier for NDEF TLV */
-#define ISO15693_THREE_BYTE_LENGTH_ID 0xFFU
-
-/* Get the NDEF TLV VALUE field block and byte address */
-#define ISO15693_GET_VALUE_FIELD_BLOCK_NO(blk, byte_addr, ndef_size) \
- (((byte_addr + 1 + ((ndef_size >= ISO15693_THREE_BYTE_LENGTH_ID) ? 3 : 1)) > \
- (ISO15693_BYTES_PER_BLOCK - 1)) ? (blk + 1) : blk)
-
-#define ISO15693_GET_VALUE_FIELD_BYTE_NO(blk, byte_addr, ndef_size) \
- (((byte_addr + 1 + ((ndef_size >= ISO15693_THREE_BYTE_LENGTH_ID) ? 3 : 1)) % \
- ISO15693_BYTES_PER_BLOCK))
-
-/************************** END MACROS definition *********************/
-
-/************************** START Functions declaration *********************/
-/*!
- * \brief \copydoc page_ovr Initiates Reading of NDEF information from the Remote Device.
- *
- * The function initiates the reading of NDEF information from a Remote Device.
- * It performs a reset of the state and starts the action (state machine).
- * A periodic call of the \ref phFriNfc_NdefMap_Process has to be done once the action
- * has been triggered.
- *
- * \param[in] NdefMap Pointer to a valid instance of the \ref phFriNfc_NdefMap_t structure describing
- * the component context.
- *
- * \param[in] PacketData Pointer to a location that receives the NDEF Packet.
- *
- * \param[in,out] PacketDataLength Pointer to a variable receiving the length of the NDEF packet.
- *
- * \param[in] Offset Indicates whether the read operation shall start from the begining of the
- * file/card storage \b or continue from the last offset. The last Offset set is stored
- * within a context variable (must not be modified by the integration).
- * If the caller sets the value to \ref PH_FRINFC_NDEFMAP_SEEK_CUR, the component shall
- * start reading from the last offset set (continue where it has stopped before).
- * If set to \ref PH_FRINFC_NDEFMAP_SEEK_BEGIN, the component shall start reading
- * from the begining of the card (restarted)
- *
- * \retval NFCSTATUS_PENDING The action has been successfully triggered.
- * \retval NFCSTATUS_INVALID_DEVICE_REQUEST If Previous Operation is Write Ndef and Offset
- * is Current then this error is displayed.
- * \retval NFCSTATUS_EOF_NDEF_CONTAINER_REACHED No Space in the File to read.
- * \retval NFCSTATUS_MORE_INFORMATION There are more bytes to read in the card.
- * \retval NFCSTATUS_SUCCESS Last Byte of the card read.
- * \retval NFCSTATUS_INVALID_DEVICE The device has not been opened or has been disconnected
- * meanwhile.
- * \retval NFCSTATUS_CMD_ABORTED The caller/driver has aborted the request.
- * \retval NFCSTATUS_BUFFER_TOO_SMALL The buffer provided by the caller is too small.
- * \retval NFCSTATUS_RF_TIMEOUT No data has been received within the TIMEOUT period.
- *
- */
-
-NFCSTATUS
-phFriNfc_ISO15693_RdNdef (
- phFriNfc_NdefMap_t *psNdefMap,
- uint8_t *pPacketData,
- uint32_t *pPacketDataLength,
- uint8_t Offset);
-
-/*!
- * \brief \copydoc page_ovr Initiates Writing of NDEF information to the Remote Device.
- *
- * The function initiates the writing of NDEF information to a Remote Device.
- * It performs a reset of the state and starts the action (state machine).
- * A periodic call of the \ref phFriNfc_NdefMap_Process has to be done once the action
- * has been triggered.
- *
- * \param[in] NdefMap Pointer to a valid instance of the \ref phFriNfc_NdefMap_t structure describing
- * the component context.
- *
- * \param[in] PacketData Pointer to a location that holds the prepared NDEF Packet.
- *
- * \param[in,out] PacketDataLength Variable specifying the length of the prepared NDEF packet.
- *
- * \param[in] Offset Indicates whether the write operation shall start from the begining of the
- * file/card storage \b or continue from the last offset. The last Offset set is stored
- * within a context variable (must not be modified by the integration).
- * If the caller sets the value to \ref PH_FRINFC_NDEFMAP_SEEK_CUR, the component shall
- * start writing from the last offset set (continue where it has stopped before).
- * If set to \ref PH_FRINFC_NDEFMAP_SEEK_BEGIN, the component shall start writing
- * from the begining of the card (restarted)
- *
- * \retval NFCSTATUS_PENDING The action has been successfully triggered.
- * \retval NFCSTATUS_INVALID_DEVICE_REQUEST If Previous Operation is Write Ndef and Offset
- * is Current then this error is displayed.
- * \retval NFCSTATUS_EOF_NDEF_CONTAINER_REACHED Last byte is written to the card after this
- * no further writing is possible.
- * \retval NFCSTATUS_SUCCESS Buffer provided by the user is completely written
- * into the card.
- * \retval NFCSTATUS_INVALID_DEVICE The device has not been opened or has been disconnected
- * meanwhile.
- * \retval NFCSTATUS_CMD_ABORTED The caller/driver has aborted the request.
- * \retval NFCSTATUS_BUFFER_TOO_SMALL The buffer provided by the caller is too small.
- * \retval NFCSTATUS_RF_TIMEOUT No data has been received within the TIMEOUT period.
- *
- */
-
-NFCSTATUS
-phFriNfc_ISO15693_WrNdef (
- phFriNfc_NdefMap_t *psNdefMap,
- uint8_t *pPacketData,
- uint32_t *pPacketDataLength,
- uint8_t Offset);
-
-/*!
- * \brief \copydoc page_ovr Check whether a particulat Remote Device is NDEF compliant.
- *
- * The function checks whether the peer device is NDEF compliant.
- *
- * \param[in] NdefMap Pointer to a valid instance of the \ref phFriNfc_NdefMap_t structure describing
- * the component context.
- *
- * \retval NFCSTATUS_PENDING The action has been successfully triggered.
- * \retval NFCSTATUS_INVALID_PARAMETER At least one parameter of the function is invalid.
- * \retval NFCSTATUS_INVALID_DEVICE The device has not been opened or has been disconnected
- * meanwhile.
- * \retval NFCSTATUS_CMD_ABORTED The caller/driver has aborted the request.
- * \retval NFCSTATUS_BUFFER_TOO_SMALL The buffer provided by the caller is too small.
- * \retval NFCSTATUS_RF_TIMEOUT No data has been received within the TIMEOUT period.
- *
- */
-
-NFCSTATUS
-phFriNfc_ISO15693_ChkNdef (
- phFriNfc_NdefMap_t *psNdefMap);
-
-/*!
- * \brief \copydoc page_cb Completion Routine, Processing function, needed to avoid long blocking.
- *
- * The function call scheme is according to \ref grp_interact. No State reset is performed during operation.
- *
- * \copydoc pphFriNfc_Cr_t
- *
- * \note The lower (Overlapped HAL) layer must register a pointer to this function as a Completion
- * Routine in order to be able to notify the component that an I/O has finished and data are
- * ready to be processed.
- *
- */
-
-void
-phFriNfc_ISO15693_Process (
- void *pContext,
- NFCSTATUS Status);
-
-#ifdef FRINFC_READONLY_NDEF
-
-/*!
- * \brief \copydoc page_ovr Initiates Writing of NDEF information to the Remote Device.
- *
- * The function initiates the writing of NDEF information to a Remote Device.
- * It performs a reset of the state and starts the action (state machine).
- * A periodic call of the \ref phFriNfc_NdefMap_Process has to be done once the action
- * has been triggered.
- *
- * \param[in] psNdefMap Pointer to a valid instance of the \ref phFriNfc_NdefMap_t structure describing
- * the component context.
- *
- *
- * \retval NFCSTATUS_PENDING The action has been successfully triggered.
- * \retval NFCSTATUS_INVALID_DEVICE_REQUEST If Previous Operation is Write Ndef and Offset
- * is Current then this error is displayed.
- * \retval NFCSTATUS_EOF_NDEF_CONTAINER_REACHED Last byte is written to the card after this
- * no further writing is possible.
- * \retval NFCSTATUS_SUCCESS Buffer provided by the user is completely written
- * into the card.
- * \retval NFCSTATUS_INVALID_DEVICE The device has not been opened or has been disconnected
- * meanwhile.
- * \retval NFCSTATUS_CMD_ABORTED The caller/driver has aborted the request.
- * \retval NFCSTATUS_BUFFER_TOO_SMALL The buffer provided by the caller is too small.
- * \retval NFCSTATUS_RF_TIMEOUT No data has been received within the TIMEOUT period.
- *
- */
-NFCSTATUS
-phFriNfc_ISO15693_ConvertToReadOnly (
- phFriNfc_NdefMap_t *psNdefMap);
-
-#endif /* #ifdef FRINFC_READONLY_NDEF */
-
-/************************** END Functions declaration *********************/
-
-#endif /* #ifndef PHFRINFC_ISO15693MAP_H */
diff --git a/libnfc-nxp/phFriNfc_IntNdefMap.c b/libnfc-nxp/phFriNfc_IntNdefMap.c
deleted file mode 100644
index 8962fc6..0000000
--- a/libnfc-nxp/phFriNfc_IntNdefMap.c
+++ /dev/null
@@ -1,210 +0,0 @@
-/*
- * Copyright (C) 2010 NXP Semiconductors
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-/*!
- * \file phFriNfc_IntNdef.c
- * \brief NFC Ndef Internal Mapping File.
- *
- * Project: NFC-FRI
- *
- * $Date: Mon Sep 15 15:09:33 2008 $
- * $Author: ing08205 $
- * $Revision: 1.5 $
- * $Aliases: NFC_FRI1.1_WK838_R9_PREP2,NFC_FRI1.1_WK838_R9_1,NFC_FRI1.1_WK840_R10_PREP1,NFC_FRI1.1_WK840_R10_1,NFC_FRI1.1_WK842_R11_PREP1,NFC_FRI1.1_WK842_R11_PREP2,NFC_FRI1.1_WK842_R11_1,NFC_FRI1.1_WK844_PREP1,NFC_FRI1.1_WK844_R12_1,NFC_FRI1.1_WK846_PREP1,NFC_FRI1.1_WK846_R13_1,NFC_FRI1.1_WK848_PREP1,NFC_FRI1.1_WK848_R14_1,NFC_FRI1.1_WK850_PACK1,NFC_FRI1.1_WK851_PREP1,NFC_FRI1.1_WK850_R15_1,NFC_FRI1.1_WK902_PREP1,NFC_FRI1.1_WK902_R16_1,NFC_FRI1.1_WK904_PREP1,NFC_FRI1.1_WK904_R17_1,NFC_FRI1.1_WK906_R18_1,NFC_FRI1.1_WK908_PREP1,NFC_FRI1.1_WK908_R19_1,NFC_FRI1.1_WK910_PREP1,NFC_FRI1.1_WK910_R20_1,NFC_FRI1.1_WK912_PREP1,NFC_FRI1.1_WK912_R21_1,NFC_FRI1.1_WK914_PREP1,NFC_FRI1.1_WK914_R22_1,NFC_FRI1.1_WK914_R22_2,NFC_FRI1.1_WK916_R23_1,NFC_FRI1.1_WK918_R24_1,NFC_FRI1.1_WK920_PREP1,NFC_FRI1.1_WK920_R25_1,NFC_FRI1.1_WK922_PREP1,NFC_FRI1.1_WK922_R26_1,NFC_FRI1.1_WK924_PREP1,NFC_FRI1.1_WK924_R27_1,NFC_FRI1.1_WK926_R28_1,NFC_FRI1.1_WK928_R29_1,NFC_FRI1.1_WK930_R30_1,NFC_FRI1.1_WK934_PREP_1,NFC_FRI1.1_WK934_R31_1,NFC_FRI1.1_WK941_PREP1,NFC_FRI1.1_WK941_PREP2,NFC_FRI1.1_WK941_1,NFC_FRI1.1_WK943_R32_1,NFC_FRI1.1_WK949_PREP1,NFC_FRI1.1_WK943_R32_10,NFC_FRI1.1_WK943_R32_13,NFC_FRI1.1_WK943_R32_14,NFC_FRI1.1_WK1007_R33_1,NFC_FRI1.1_WK1007_R33_4,NFC_FRI1.1_WK1017_PREP1,NFC_FRI1.1_WK1017_R34_1,NFC_FRI1.1_WK1017_R34_2,NFC_FRI1.1_WK1023_R35_1 $
- *
- */
-
-#include
-#include
-
-#ifndef PH_FRINFC_MAP_MIFAREUL_DISABLED
-#include
-#endif /* PH_FRINFC_MAP_MIFAREUL_DISABLED*/
-
-#ifndef PH_FRINFC_MAP_MIFARESTD_DISABLED
-#include
-#endif /* PH_FRINFC_MAP_MIFARESTD_DISABLED */
-
-#ifndef PH_FRINFC_MAP_DESFIRE_DISABLED
-#include
-#endif /* PH_FRINFC_MAP_DESFIRE_DISABLED */
-
-#ifndef PH_FRINFC_MAP_FELICA_DISABLED
-#include
-#endif /* PH_FRINFC_MAP_FELICA_DISABLED */
-
-#include
-
-/*! \ingroup grp_file_attributes
- * \name NDEF Mapping
- *
- * File: \ref phFri_IntNdefMap.c
- * This file has functions which are used common across all the
- * typ1/type2/type3/type4 tags.
- *
- */
-/*@{*/
-#define PHFRINFCNDEFMAP_FILEREVISION "$Revision: 1.5 $"
-#define PHFRINFCNDEFMAP_FILEALIASES "$Aliases: NFC_FRI1.1_WK838_R9_PREP2,NFC_FRI1.1_WK838_R9_1,NFC_FRI1.1_WK840_R10_PREP1,NFC_FRI1.1_WK840_R10_1,NFC_FRI1.1_WK842_R11_PREP1,NFC_FRI1.1_WK842_R11_PREP2,NFC_FRI1.1_WK842_R11_1,NFC_FRI1.1_WK844_PREP1,NFC_FRI1.1_WK844_R12_1,NFC_FRI1.1_WK846_PREP1,NFC_FRI1.1_WK846_R13_1,NFC_FRI1.1_WK848_PREP1,NFC_FRI1.1_WK848_R14_1,NFC_FRI1.1_WK850_PACK1,NFC_FRI1.1_WK851_PREP1,NFC_FRI1.1_WK850_R15_1,NFC_FRI1.1_WK902_PREP1,NFC_FRI1.1_WK902_R16_1,NFC_FRI1.1_WK904_PREP1,NFC_FRI1.1_WK904_R17_1,NFC_FRI1.1_WK906_R18_1,NFC_FRI1.1_WK908_PREP1,NFC_FRI1.1_WK908_R19_1,NFC_FRI1.1_WK910_PREP1,NFC_FRI1.1_WK910_R20_1,NFC_FRI1.1_WK912_PREP1,NFC_FRI1.1_WK912_R21_1,NFC_FRI1.1_WK914_PREP1,NFC_FRI1.1_WK914_R22_1,NFC_FRI1.1_WK914_R22_2,NFC_FRI1.1_WK916_R23_1,NFC_FRI1.1_WK918_R24_1,NFC_FRI1.1_WK920_PREP1,NFC_FRI1.1_WK920_R25_1,NFC_FRI1.1_WK922_PREP1,NFC_FRI1.1_WK922_R26_1,NFC_FRI1.1_WK924_PREP1,NFC_FRI1.1_WK924_R27_1,NFC_FRI1.1_WK926_R28_1,NFC_FRI1.1_WK928_R29_1,NFC_FRI1.1_WK930_R30_1,NFC_FRI1.1_WK934_PREP_1,NFC_FRI1.1_WK934_R31_1,NFC_FRI1.1_WK941_PREP1,NFC_FRI1.1_WK941_PREP2,NFC_FRI1.1_WK941_1,NFC_FRI1.1_WK943_R32_1,NFC_FRI1.1_WK949_PREP1,NFC_FRI1.1_WK943_R32_10,NFC_FRI1.1_WK943_R32_13,NFC_FRI1.1_WK943_R32_14,NFC_FRI1.1_WK1007_R33_1,NFC_FRI1.1_WK1007_R33_4,NFC_FRI1.1_WK1017_PREP1,NFC_FRI1.1_WK1017_R34_1,NFC_FRI1.1_WK1017_R34_2,NFC_FRI1.1_WK1023_R35_1 $"
-/*@}*/
-
-
-/* \note This function has to be called at the beginning, after creating an
- * instance of \ref phFriNfc_NdefMap_t . Use this function to reset
- * the instance and/or switch to a different underlying device (
- * different NFC device or device mode, or different Remote Device).
- */
-
-
-#if 0
-NFCSTATUS phFriNfc_ChkAndParseTLV(phFriNfc_NdefMap_t *NdefMap)
-{
- NFCSTATUS status = NFCSTATUS_PENDING;
-
- switch ( NdefMap->CardType )
- {
- #ifndef PH_FRINFC_MAP_MIFAREUL_DISABLED
- case PH_FRINFC_NDEFMAP_MIFARE_UL_CARD :
-
-
- break;
-#endif /* PH_FRINFC_MAP_MIFAREUL_DISABLED */
-
-#ifndef PH_FRINFC_MAP_DESFIRE_DISABLED
- case PH_FRINFC_NDEFMAP_ISO14443_4A_CARD :
- status = phFriNfc_Desf_ChkAndParseTLV(NdefMap,PH_FRINFC_NDEFMAP_DESF_TLV_INDEX);
- return (status);
-
- break;
-#endif /* PH_FRINFC_MAP_DESFIRE_DISABLED */
-
-#ifndef PH_FRINFC_MAP_MIFARESTD_DISABLED
- case PH_FRINFC_NDEFMAP_MIFARE_STD_1K_CARD :
- case PH_FRINFC_NDEFMAP_MIFARE_STD_4K_CARD :
-
- break;
-#endif /* PH_FRINFC_MAP_MIFARESTD_DISABLED */
-
-#ifndef PH_FRINFC_MAP_FELICA_DISABLED
- case PH_FRINFC_NDEFMAP_FELICA_SMART_CARD :
- ;
- break;
-#endif /* PH_FRINFC_MAP_FELICA_DISABLED */
-
- default :
- /* Unknown card type. Return error */
- status = PHNFCSTVAL(CID_FRI_NFC_NDEF_MAP,\
- NFCSTATUS_INVALID_REMOTE_DEVICE);
-
- break;
- }
-
- return ( status);
-}
-#endif
-
-NFCSTATUS phFriNfc_NdefMap_SetCardState(phFriNfc_NdefMap_t *NdefMap,
- uint16_t Length)
-{
- NFCSTATUS Result = NFCSTATUS_SUCCESS;
- if(Length == PH_FRINFC_NDEFMAP_MFUL_VAL0)
- {
- NdefMap->CardState =(uint8_t) (((NdefMap->CardState ==
- PH_NDEFMAP_CARD_STATE_READ_ONLY) ||
- (NdefMap->CardState ==
- PH_NDEFMAP_CARD_STATE_INVALID))?
- PH_NDEFMAP_CARD_STATE_INVALID:
- NdefMap->CardState);
- }
- else
- {
- switch(NdefMap->CardState)
- {
- case PH_NDEFMAP_CARD_STATE_INITIALIZED:
- NdefMap->CardState =(uint8_t) ((NdefMap->CardState ==
- PH_NDEFMAP_CARD_STATE_INVALID)?
- NdefMap->CardState:
- PH_NDEFMAP_CARD_STATE_READ_WRITE);
- break;
-
- case PH_NDEFMAP_CARD_STATE_READ_ONLY:
- NdefMap->CardState =(uint8_t) ((NdefMap->CardState ==
- PH_NDEFMAP_CARD_STATE_INVALID)?
- NdefMap->CardState:
- PH_NDEFMAP_CARD_STATE_READ_ONLY);
- break;
-
- case PH_NDEFMAP_CARD_STATE_READ_WRITE:
- NdefMap->CardState =(uint8_t) ((NdefMap->CardState ==
- PH_NDEFMAP_CARD_STATE_INVALID)?
- NdefMap->CardState:
- PH_NDEFMAP_CARD_STATE_READ_WRITE);
- break;
-
- default:
- NdefMap->CardState = PH_NDEFMAP_CARD_STATE_INVALID;
- Result = PHNFCSTVAL(CID_FRI_NFC_NDEF_MAP,
- NFCSTATUS_NO_NDEF_SUPPORT);
- break;
- }
- }
- Result = ((NdefMap->CardState ==
- PH_NDEFMAP_CARD_STATE_INVALID)?
- PHNFCSTVAL(CID_FRI_NFC_NDEF_MAP,
- NFCSTATUS_NO_NDEF_SUPPORT):
- Result);
- return Result;
-}
-
-NFCSTATUS phFriNfc_NdefMap_CheckSpecVersion(phFriNfc_NdefMap_t *NdefMap,
- uint8_t VersionIndex)
-{
- NFCSTATUS status = NFCSTATUS_SUCCESS;
-
- uint8_t T3TVerNo = NdefMap->SendRecvBuf[VersionIndex];
-
- if ( T3TVerNo == 0 )
- {
- /*Return Status Error “ Invalid Format”*/
- status = PHNFCSTVAL(CID_FRI_NFC_NDEF_MAP,NFCSTATUS_INVALID_FORMAT);
- }
- else
- {
- /* calculate the major and minor version number of T3VerNo */
- if( (( PH_NFCFRI_NDEFMAP_NFCDEV_MAJOR_VER_NUM ==
- PH_NFCFRI_NDEFMAP_GET_MAJOR_TAG_VERNO(T3TVerNo ) )&&
- ( PH_NFCFRI_NDEFMAP_NFCDEV_MINOR_VER_NUM >=
- PH_NFCFRI_NDEFMAP_GET_MINOR_TAG_VERNO(T3TVerNo))) ||
- (( PH_NFCFRI_NDEFMAP_NFCDEV_MAJOR_VER_NUM ==
- PH_NFCFRI_NDEFMAP_GET_MAJOR_TAG_VERNO(T3TVerNo ) )&&
- ( PH_NFCFRI_NDEFMAP_NFCDEV_MINOR_VER_NUM <
- PH_NFCFRI_NDEFMAP_GET_MINOR_TAG_VERNO(T3TVerNo) )))
- {
- status = PHNFCSTVAL(CID_NFC_NONE,NFCSTATUS_SUCCESS);
- }
- else
- {
- if (( PH_NFCFRI_NDEFMAP_NFCDEV_MAJOR_VER_NUM <
- PH_NFCFRI_NDEFMAP_GET_MAJOR_TAG_VERNO(T3TVerNo) ) ||
- ( PH_NFCFRI_NDEFMAP_NFCDEV_MAJOR_VER_NUM >
- PH_NFCFRI_NDEFMAP_GET_MAJOR_TAG_VERNO(T3TVerNo)))
- {
- status = PHNFCSTVAL(CID_FRI_NFC_NDEF_MAP,NFCSTATUS_INVALID_FORMAT);
- }
- }
- }
- return (status);
-}
diff --git a/libnfc-nxp/phFriNfc_IntNdefMap.h b/libnfc-nxp/phFriNfc_IntNdefMap.h
deleted file mode 100644
index 1951000..0000000
--- a/libnfc-nxp/phFriNfc_IntNdefMap.h
+++ /dev/null
@@ -1,81 +0,0 @@
-/*
- * Copyright (C) 2010 NXP Semiconductors
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-/*
- * \file phFriNfc_IntNdefMap.h
- * \brief NFC Internal Ndef Mapping File.
- *
- * Project: NFC-FRI
- *
- * $Date: Mon Sep 15 15:10:49 2008 $
- * $Author: ing08205 $
- * $Revision: 1.5 $
- * $Aliases: NFC_FRI1.1_WK838_R9_PREP2,NFC_FRI1.1_WK838_R9_1,NFC_FRI1.1_WK840_R10_PREP1,NFC_FRI1.1_WK840_R10_1,NFC_FRI1.1_WK842_R11_PREP1,NFC_FRI1.1_WK842_R11_PREP2,NFC_FRI1.1_WK842_R11_1,NFC_FRI1.1_WK844_PREP1,NFC_FRI1.1_WK844_R12_1,NFC_FRI1.1_WK846_PREP1,NFC_FRI1.1_WK846_R13_1,NFC_FRI1.1_WK848_PREP1,NFC_FRI1.1_WK848_R14_1,NFC_FRI1.1_WK850_PACK1,NFC_FRI1.1_WK851_PREP1,NFC_FRI1.1_WK850_R15_1,NFC_FRI1.1_WK902_PREP1,NFC_FRI1.1_WK902_R16_1,NFC_FRI1.1_WK904_PREP1,NFC_FRI1.1_WK904_R17_1,NFC_FRI1.1_WK906_R18_1,NFC_FRI1.1_WK908_PREP1,NFC_FRI1.1_WK908_R19_1,NFC_FRI1.1_WK910_PREP1,NFC_FRI1.1_WK910_R20_1,NFC_FRI1.1_WK912_PREP1,NFC_FRI1.1_WK912_R21_1,NFC_FRI1.1_WK914_PREP1,NFC_FRI1.1_WK914_R22_1,NFC_FRI1.1_WK914_R22_2,NFC_FRI1.1_WK916_R23_1,NFC_FRI1.1_WK918_R24_1,NFC_FRI1.1_WK920_PREP1,NFC_FRI1.1_WK920_R25_1,NFC_FRI1.1_WK922_PREP1,NFC_FRI1.1_WK922_R26_1,NFC_FRI1.1_WK924_PREP1,NFC_FRI1.1_WK924_R27_1,NFC_FRI1.1_WK926_R28_1,NFC_FRI1.1_WK928_R29_1,NFC_FRI1.1_WK930_R30_1,NFC_FRI1.1_WK934_PREP_1,NFC_FRI1.1_WK934_R31_1,NFC_FRI1.1_WK941_PREP1,NFC_FRI1.1_WK941_PREP2,NFC_FRI1.1_WK941_1,NFC_FRI1.1_WK943_R32_1,NFC_FRI1.1_WK949_PREP1,NFC_FRI1.1_WK943_R32_10,NFC_FRI1.1_WK943_R32_13,NFC_FRI1.1_WK943_R32_14,NFC_FRI1.1_WK1007_R33_1,NFC_FRI1.1_WK1007_R33_4,NFC_FRI1.1_WK1017_PREP1,NFC_FRI1.1_WK1017_R34_1,NFC_FRI1.1_WK1017_R34_2,NFC_FRI1.1_WK1023_R35_1 $
- *
- */
-
-#ifndef PHFRINFC_INTNDEFMAP_H
-#define PHFRINFC_INTNDEFMAP_H
-
-#include
-#ifdef PH_HAL4_ENABLE
- #include
-#else
- #include
-#endif
-#include
-#include
-#include
-
-
-
-/*!
- * \name phFriNfc_IntNdefMap.h
- * This file has functions which are used common across all the
- typ1/type2/type3/type4 tags.
- *
- */
-/*@{*/
-
-#define PH_FRINFC_NDEFMAP_TLVLEN_ZERO 0
-
-/* NFC Device Major and Minor Version numbers*/
-/* !!CAUTION!! these needs to be updated periodically.Major and Minor version numbers
- should be compatible to the version number of currently implemented mapping document.
- Example : NFC Device version Number : 1.0 , specifies
- Major VNo is 1,
- Minor VNo is 0 */
-#define PH_NFCFRI_NDEFMAP_NFCDEV_MAJOR_VER_NUM 0x01
-#define PH_NFCFRI_NDEFMAP_NFCDEV_MINOR_VER_NUM 0x00
-
-/* Macros to find major and minor TAG : Ex:Type1/Type2/Type3/Type4 version numbers*/
-#define PH_NFCFRI_NDEFMAP_GET_MAJOR_TAG_VERNO(a) (((a) & (0xf0))>>(4))
-#define PH_NFCFRI_NDEFMAP_GET_MINOR_TAG_VERNO(a) ((a) & (0x0f))
-
-
-/*!
- * \name NDEF Mapping - states of the Finite State machine
- *
- */
-/*@{*/
-
-NFCSTATUS phFriNfc_NdefMap_CheckSpecVersion(phFriNfc_NdefMap_t *NdefMap,
- uint8_t VersionIndex);
-
-NFCSTATUS phFriNfc_NdefMap_SetCardState(phFriNfc_NdefMap_t *NdefMap,
- uint16_t Length);
-
-#endif /* PHFRINFC_INTNDEFMAP_H */
diff --git a/libnfc-nxp/phFriNfc_Llcp.c b/libnfc-nxp/phFriNfc_Llcp.c
deleted file mode 100644
index bf80722..0000000
--- a/libnfc-nxp/phFriNfc_Llcp.c
+++ /dev/null
@@ -1,1486 +0,0 @@
-/*
- * Copyright (C) 2010 NXP Semiconductors
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-/**
- * \file phFriNfc_Llcp.c
- * \brief NFC LLCP core
- *
- * Project: NFC-FRI
- *
- */
-
-/*include files*/
-#include
-#include
-
-#include
-#include
-
-/**
- * \internal
- * \name States of the LLC state machine.
- *
- */
-/*@{*/
-#define PHFRINFC_LLCP_STATE_RESET_INIT 0 /**< \internal Initial state.*/
-#define PHFRINFC_LLCP_STATE_CHECKED 1 /**< \internal The tag has been checked for LLCP compliance.*/
-#define PHFRINFC_LLCP_STATE_ACTIVATION 2 /**< \internal The deactivation phase.*/
-#define PHFRINFC_LLCP_STATE_PAX 3 /**< \internal Parameter exchange phase.*/
-#define PHFRINFC_LLCP_STATE_OPERATION_RECV 4 /**< \internal Normal operation phase (ready to receive).*/
-#define PHFRINFC_LLCP_STATE_OPERATION_SEND 5 /**< \internal Normal operation phase (ready to send).*/
-#define PHFRINFC_LLCP_STATE_DEACTIVATION 6 /**< \internal The deactivation phase.*/
-/*@}*/
-
-/**
- * \internal
- * \name Masks used for VERSION parsing.
- *
- */
-/*@{*/
-#define PHFRINFC_LLCP_VERSION_MAJOR_MASK 0xF0 /**< \internal Mask to apply to get major version number.*/
-#define PHFRINFC_LLCP_VERSION_MINOR_MASK 0x0F /**< \internal Mask to apply to get major version number.*/
-/*@}*/
-
-/**
- * \internal
- * \name Invalid values for parameters.
- *
- */
-/*@{*/
-#define PHFRINFC_LLCP_INVALID_VERSION 0x00 /**< \internal Invalid VERSION value.*/
-/*@}*/
-
-/**
- * \internal
- * \name Internal constants.
- *
- */
-/*@{*/
-#define PHFRINFC_LLCP_MAX_PARAM_TLV_LENGTH \
- (( PHFRINFC_LLCP_TLV_LENGTH_HEADER + PHFRINFC_LLCP_TLV_LENGTH_VERSION ) + \
- ( PHFRINFC_LLCP_TLV_LENGTH_HEADER + PHFRINFC_LLCP_TLV_LENGTH_MIUX ) + \
- ( PHFRINFC_LLCP_TLV_LENGTH_HEADER + PHFRINFC_LLCP_TLV_LENGTH_WKS ) + \
- ( PHFRINFC_LLCP_TLV_LENGTH_HEADER + PHFRINFC_LLCP_TLV_LENGTH_LTO ) + \
- ( PHFRINFC_LLCP_TLV_LENGTH_HEADER + PHFRINFC_LLCP_TLV_LENGTH_OPT )) /**< \internal Maximum size of link params TLV.*/
-/*@}*/
-
-
-
-/* --------------------------- Internal functions ------------------------------ */
-
-static void phFriNfc_Llcp_Receive_CB( void *pContext,
- NFCSTATUS status,
- phNfc_sData_t *psData);
-static NFCSTATUS phFriNfc_Llcp_HandleIncomingPacket( phFriNfc_Llcp_t *Llcp,
- phNfc_sData_t *psPacket );
-static void phFriNfc_Llcp_ResetLTO( phFriNfc_Llcp_t *Llcp );
-static NFCSTATUS phFriNfc_Llcp_InternalSend( phFriNfc_Llcp_t *Llcp,
- phFriNfc_Llcp_sPacketHeader_t *psHeader,
- phFriNfc_Llcp_sPacketSequence_t *psSequence,
- phNfc_sData_t *psInfo );
-static bool_t phFriNfc_Llcp_HandlePendingSend ( phFriNfc_Llcp_t *Llcp );
-
-static phNfc_sData_t * phFriNfc_Llcp_AllocateAndCopy(phNfc_sData_t * pOrig)
-{
- phNfc_sData_t * pDest = NULL;
-
- if (pOrig == NULL)
- {
- return NULL;
- }
-
- pDest = phOsalNfc_GetMemory(sizeof(phNfc_sData_t));
- if (pDest == NULL)
- {
- goto error;
- }
-
- pDest->buffer = phOsalNfc_GetMemory(pOrig->length);
- if (pDest->buffer == NULL)
- {
- goto error;
- }
-
- memcpy(pDest->buffer, pOrig->buffer, pOrig->length);
- pDest->length = pOrig->length;
-
- return pDest;
-
-error:
- if (pDest != NULL)
- {
- if (pDest->buffer != NULL)
- {
- phOsalNfc_FreeMemory(pDest->buffer);
- }
- phOsalNfc_FreeMemory(pDest);
- }
- return NULL;
-}
-
-static void phFriNfc_Llcp_Deallocate(phNfc_sData_t * pData)
-{
- if (pData != NULL)
- {
- if (pData->buffer != NULL)
- {
- phOsalNfc_FreeMemory(pData->buffer);
- }
- else
- {
- LLCP_PRINT("Warning, deallocating empty buffer");
- }
- phOsalNfc_FreeMemory(pData);
- }
-}
-
-static NFCSTATUS phFriNfc_Llcp_InternalDeactivate( phFriNfc_Llcp_t *Llcp )
-{
- phFriNfc_Llcp_Send_CB_t pfSendCB;
- void * pSendContext;
- if ((Llcp->state == PHFRINFC_LLCP_STATE_OPERATION_RECV) ||
- (Llcp->state == PHFRINFC_LLCP_STATE_OPERATION_SEND) ||
- (Llcp->state == PHFRINFC_LLCP_STATE_PAX) ||
- (Llcp->state == PHFRINFC_LLCP_STATE_ACTIVATION))
- {
- /* Update state */
- Llcp->state = PHFRINFC_LLCP_STATE_DEACTIVATION;
-
- /* Stop timer */
- phOsalNfc_Timer_Stop(Llcp->hSymmTimer);
-
- Llcp->psSendHeader = NULL;
- Llcp->psSendSequence = NULL;
- /* Return delayed send operation in error, in any */
- if (Llcp->psSendInfo != NULL)
- {
- phFriNfc_Llcp_Deallocate(Llcp->psSendInfo);
- Llcp->psSendInfo = NULL;
- }
- if (Llcp->pfSendCB != NULL)
- {
- /* Get Callback params */
- pfSendCB = Llcp->pfSendCB;
- pSendContext = Llcp->pSendContext;
- /* Reset callback params */
- Llcp->pfSendCB = NULL;
- Llcp->pSendContext = NULL;
- /* Call the callback */
- (pfSendCB)(pSendContext, NFCSTATUS_FAILED);
- }
-
- /* Notify service layer */
- Llcp->pfLink_CB(Llcp->pLinkContext, phFriNfc_LlcpMac_eLinkDeactivated);
-
- /* Forward check request to MAC layer */
- return phFriNfc_LlcpMac_Deactivate(&Llcp->MAC);
- }
-
- return NFCSTATUS_SUCCESS;
-}
-
-
-static NFCSTATUS phFriNfc_Llcp_SendSymm( phFriNfc_Llcp_t *Llcp )
-{
- phFriNfc_Llcp_sPacketHeader_t sHeader;
-
- sHeader.dsap = PHFRINFC_LLCP_SAP_LINK;
- sHeader.ssap = PHFRINFC_LLCP_SAP_LINK;
- sHeader.ptype = PHFRINFC_LLCP_PTYPE_SYMM;
- return phFriNfc_Llcp_InternalSend(Llcp, &sHeader, NULL, NULL);
-}
-
-
-static NFCSTATUS phFriNfc_Llcp_SendPax( phFriNfc_Llcp_t *Llcp, phFriNfc_Llcp_sLinkParameters_t *psLinkParams)
-{
- uint8_t pTLVBuffer[PHFRINFC_LLCP_MAX_PARAM_TLV_LENGTH];
- phNfc_sData_t sParamsTLV;
- phFriNfc_Llcp_sPacketHeader_t sHeader;
- NFCSTATUS result;
-
- /* Prepare link parameters TLV */
- sParamsTLV.buffer = pTLVBuffer;
- sParamsTLV.length = PHFRINFC_LLCP_MAX_PARAM_TLV_LENGTH;
- result = phFriNfc_Llcp_EncodeLinkParams(&sParamsTLV, psLinkParams, PHFRINFC_LLCP_VERSION);
- if (result != NFCSTATUS_SUCCESS)
- {
- /* Error while encoding */
- return NFCSTATUS_FAILED;
- }
-
- /* Check if ready to send */
- if (Llcp->state != PHFRINFC_LLCP_STATE_OPERATION_SEND)
- {
- /* No send pending, send the PAX packet */
- sHeader.dsap = PHFRINFC_LLCP_SAP_LINK;
- sHeader.ssap = PHFRINFC_LLCP_SAP_LINK;
- sHeader.ptype = PHFRINFC_LLCP_PTYPE_PAX;
- return phFriNfc_Llcp_InternalSend(Llcp, &sHeader, NULL, &sParamsTLV);
- }
- else
- {
- /* Error: A send is already pending, cannot send PAX */
- /* NOTE: this should not happen since PAX are sent before any other packet ! */
- return NFCSTATUS_FAILED;
- }
-}
-
-
-static NFCSTATUS phFriNfc_Llcp_SendDisconnect( phFriNfc_Llcp_t *Llcp )
-{
- phFriNfc_Llcp_sPacketHeader_t sHeader;
-
- /* Check if ready to send */
- if (Llcp->state != PHFRINFC_LLCP_STATE_OPERATION_SEND)
- {
- /* No send pending, send the DISC packet */
- sHeader.dsap = PHFRINFC_LLCP_SAP_LINK;
- sHeader.ssap = PHFRINFC_LLCP_SAP_LINK;
- sHeader.ptype = PHFRINFC_LLCP_PTYPE_DISC;
- return phFriNfc_Llcp_InternalSend(Llcp, &sHeader, NULL, NULL);
- }
- else
- {
- /* A send is already pending, raise a flag to send DISC as soon as possible */
- Llcp->bDiscPendingFlag = TRUE;
- return NFCSTATUS_PENDING;
- }
-}
-
-
-static void phFriNfc_Llcp_Timer_CB(uint32_t TimerId, void *pContext)
-{
- phFriNfc_Llcp_t *Llcp = (phFriNfc_Llcp_t*)pContext;
-
- PHNFC_UNUSED_VARIABLE(TimerId);
-
- /* Check current state */
- if (Llcp->state == PHFRINFC_LLCP_STATE_OPERATION_RECV)
- {
- /* No data is coming before LTO, disconnecting */
- phFriNfc_Llcp_InternalDeactivate(Llcp);
- }
- else if (Llcp->state == PHFRINFC_LLCP_STATE_OPERATION_SEND)
- {
- /* Send SYMM */
- phFriNfc_Llcp_SendSymm(Llcp);
- }
- else
- {
- /* Nothing to do if not in Normal Operation state */
- }
-}
-
-
-static NFCSTATUS phFriNfc_Llcp_HandleAggregatedPacket( phFriNfc_Llcp_t *Llcp,
- phNfc_sData_t *psRawPacket )
-{
- phNfc_sData_t sInfo;
- phNfc_sData_t sCurrentInfo;
- uint16_t length;
- NFCSTATUS status;
-
- /* Get info field */
- sInfo.buffer = psRawPacket->buffer + PHFRINFC_LLCP_PACKET_HEADER_SIZE;
- sInfo.length = psRawPacket->length - PHFRINFC_LLCP_PACKET_HEADER_SIZE;
-
- /* Check for empty info field */
- if (sInfo.length == 0)
- {
- return NFCSTATUS_FAILED;
- }
-
- /* Check consistency */
- while (sInfo.length != 0)
- {
- /* Check if enough room to read length */
- if (sInfo.length < sizeof(sInfo.length))
- {
- return NFCSTATUS_FAILED;
- }
- /* Read length */
- length = (sInfo.buffer[0] << 8) | sInfo.buffer[1];
- /* Update info buffer */
- sInfo.buffer += 2; /*Size of length field is 2*/
- sInfo.length -= 2; /*Size of length field is 2*/
- /* Check if declared length fits in remaining space */
- if (length > sInfo.length)
- {
- return NFCSTATUS_FAILED;
- }
- /* Update info buffer */
- sInfo.buffer += length;
- sInfo.length -= length;
- }
-
- /* Get info field */
- sInfo.buffer = psRawPacket->buffer + PHFRINFC_LLCP_PACKET_HEADER_SIZE;
- sInfo.length = psRawPacket->length - PHFRINFC_LLCP_PACKET_HEADER_SIZE;
-
- /* Handle aggregated packets */
- while (sInfo.length != 0)
- {
- /* Read length */
- length = (sInfo.buffer[0] << 8) | sInfo.buffer[1];
- /* Update info buffer */
- sInfo.buffer += 2; /* Size of length field is 2 */
- sInfo.length -= 2; /*Size of length field is 2*/
- /* Handle aggregated packet */
- sCurrentInfo.buffer=sInfo.buffer;
- sCurrentInfo.length=length;
- status = phFriNfc_Llcp_HandleIncomingPacket(Llcp, &sCurrentInfo);
- if ( (status != NFCSTATUS_SUCCESS) &&
- (status != NFCSTATUS_PENDING) )
- {
- /* TODO: Error: invalid frame */
- }
- /* Update info buffer */
- sInfo.buffer += length;
- sInfo.length -= length;
- }
- return NFCSTATUS_SUCCESS;
-}
-
-
-static NFCSTATUS phFriNfc_Llcp_ParseLinkParams( phNfc_sData_t *psParamsTLV,
- phFriNfc_Llcp_sLinkParameters_t *psParsedParams,
- uint8_t *pnParsedVersion )
-{
- NFCSTATUS status;
- uint8_t type;
- phFriNfc_Llcp_sLinkParameters_t sParams;
- phNfc_sData_t sValueBuffer;
- uint32_t offset = 0;
- uint8_t version = PHFRINFC_LLCP_INVALID_VERSION;
-
- /* Check for NULL pointers */
- if ((psParamsTLV == NULL) || (psParsedParams == NULL) || (pnParsedVersion == NULL))
- {
- return PHNFCSTVAL(CID_FRI_NFC_LLCP, NFCSTATUS_INVALID_PARAMETER);
- }
-
- /* Prepare default param structure */
- sParams.miu = PHFRINFC_LLCP_MIU_DEFAULT;
- sParams.wks = PHFRINFC_LLCP_WKS_DEFAULT;
- sParams.lto = PHFRINFC_LLCP_LTO_DEFAULT;
- sParams.option = PHFRINFC_LLCP_OPTION_DEFAULT;
-
- /* Decode TLV */
- while (offset < psParamsTLV->length)
- {
- status = phFriNfc_Llcp_DecodeTLV(psParamsTLV, &offset, &type, &sValueBuffer);
- if (status != NFCSTATUS_SUCCESS)
- {
- /* Error: Ill-formed TLV */
- return status;
- }
- switch(type)
- {
- case PHFRINFC_LLCP_TLV_TYPE_VERSION:
- {
- /* Check length */
- if (sValueBuffer.length != PHFRINFC_LLCP_TLV_LENGTH_VERSION)
- {
- /* Error : Ill-formed VERSION parameter TLV */
- break;
- }
- /* Get VERSION */
- version = sValueBuffer.buffer[0];
- break;
- }
- case PHFRINFC_LLCP_TLV_TYPE_MIUX:
- {
- /* Check length */
- if (sValueBuffer.length != PHFRINFC_LLCP_TLV_LENGTH_MIUX)
- {
- /* Error : Ill-formed MIUX parameter TLV */
- break;
- }
- /* Get MIU */
- sParams.miu = (PHFRINFC_LLCP_MIU_DEFAULT + ((sValueBuffer.buffer[0] << 8) | sValueBuffer.buffer[1])) & PHFRINFC_LLCP_TLV_MIUX_MASK;
- break;
- }
- case PHFRINFC_LLCP_TLV_TYPE_WKS:
- {
- /* Check length */
- if (sValueBuffer.length != PHFRINFC_LLCP_TLV_LENGTH_WKS)
- {
- /* Error : Ill-formed MIUX parameter TLV */
- break;
- }
- /* Get WKS */
- sParams.wks = (sValueBuffer.buffer[0] << 8) | sValueBuffer.buffer[1];
- /* Ignored bits must always be set */
- sParams.wks |= PHFRINFC_LLCP_TLV_WKS_MASK;
- break;
- }
- case PHFRINFC_LLCP_TLV_TYPE_LTO:
- {
- /* Check length */
- if (sValueBuffer.length != PHFRINFC_LLCP_TLV_LENGTH_LTO)
- {
- /* Error : Ill-formed LTO parameter TLV */
- break;
- }
- /* Get LTO */
- sParams.lto = sValueBuffer.buffer[0];
- break;
- }
- case PHFRINFC_LLCP_TLV_TYPE_OPT:
- {
- /* Check length */
- if (sValueBuffer.length != PHFRINFC_LLCP_TLV_LENGTH_OPT)
- {
- /* Error : Ill-formed OPT parameter TLV */
- break;;
- }
- /* Get OPT */
- sParams.option = sValueBuffer.buffer[0] & PHFRINFC_LLCP_TLV_OPT_MASK;
- break;
- }
- default:
- {
- /* Error : Unknown Type */
- break;
- }
- }
- }
-
- /* Check if a VERSION parameter has been provided */
- if (version == PHFRINFC_LLCP_INVALID_VERSION)
- {
- /* Error : Mandatory VERSION parameter not provided */
- return PHNFCSTVAL(CID_FRI_NFC_LLCP, NFCSTATUS_INVALID_PARAMETER);
- }
-
- /* Save response */
- *pnParsedVersion = version;
- memcpy(psParsedParams, &sParams, sizeof(phFriNfc_Llcp_sLinkParameters_t));
-
- return NFCSTATUS_SUCCESS;
-}
-
-
-static NFCSTATUS phFriNfc_Llcp_VersionAgreement( uint8_t localVersion,
- uint8_t remoteVersion,
- uint8_t *pNegociatedVersion )
-{
- uint8_t localMajor = localVersion & PHFRINFC_LLCP_VERSION_MAJOR_MASK;
- uint8_t localMinor = localVersion & PHFRINFC_LLCP_VERSION_MINOR_MASK;
- uint8_t remoteMajor = remoteVersion & PHFRINFC_LLCP_VERSION_MAJOR_MASK;
- uint8_t remoteMinor = remoteVersion & PHFRINFC_LLCP_VERSION_MINOR_MASK;
- uint8_t negociatedVersion;
-
- /* Check for NULL pointers */
- if (pNegociatedVersion == NULL)
- {
- return PHNFCSTVAL(CID_FRI_NFC_LLCP, NFCSTATUS_INVALID_PARAMETER);
- }
-
- /* Compare Major numbers */
- if (localMajor == remoteMajor)
- {
- /* Version agreement succeed : use lowest version */
- negociatedVersion = localMajor | ((remoteMinor remoteMajor)
- {
- /* Decide if versions are compatible */
- /* Currently, there is no backward compatibility to handle */
- return NFCSTATUS_FAILED;
- }
- else /* if (localMajor < remoteMajor) */
- {
- /* It is up to the remote host to decide if versions are compatible */
- /* Set negociated version to our local version, the remote will
- deacivate the link if its own version agreement fails */
- negociatedVersion = localVersion;
- }
-
- /* Save response */
- *pNegociatedVersion = negociatedVersion;
-
- return NFCSTATUS_SUCCESS;
-}
-
-
-static NFCSTATUS phFriNfc_Llcp_InternalActivate( phFriNfc_Llcp_t *Llcp,
- phNfc_sData_t *psParamsTLV)
-{
- NFCSTATUS status;
- phFriNfc_Llcp_sLinkParameters_t sRemoteParams;
- uint8_t remoteVersion;
- uint8_t negociatedVersion;
- const uint16_t nMaxHeaderSize = PHFRINFC_LLCP_PACKET_HEADER_SIZE +
- PHFRINFC_LLCP_PACKET_SEQUENCE_SIZE;
-
- /* Parse parameters */
- status = phFriNfc_Llcp_ParseLinkParams(psParamsTLV, &sRemoteParams, &remoteVersion);
- if (status != NFCSTATUS_SUCCESS)
- {
- /* Error: invalid parameters TLV */
- status = NFCSTATUS_FAILED;
- }
- else
- {
- /* Version agreement procedure */
- status = phFriNfc_Llcp_VersionAgreement(PHFRINFC_LLCP_VERSION , remoteVersion, &negociatedVersion);
- if (status != NFCSTATUS_SUCCESS)
- {
- /* Error: version agreement failed */
- status = NFCSTATUS_FAILED;
- }
- else
- {
- /* Save parameters */
- Llcp->version = negociatedVersion;
- memcpy(&Llcp->sRemoteParams, &sRemoteParams, sizeof(phFriNfc_Llcp_sLinkParameters_t));
-
- /* Update remote MIU to match local Tx buffer size */
- if (Llcp->nTxBufferLength < (Llcp->sRemoteParams.miu + nMaxHeaderSize))
- {
- Llcp->sRemoteParams.miu = Llcp->nTxBufferLength - nMaxHeaderSize;
- }
-
- /* Initiate Symmetry procedure by resetting LTO timer */
- /* NOTE: this also updates current state */
- phFriNfc_Llcp_ResetLTO(Llcp);
- }
- }
- /* Notify upper layer, if Activation failed CB called by Deactivate */
- if (status == NFCSTATUS_SUCCESS)
- {
- /* Link activated ! */
- Llcp->pfLink_CB(Llcp->pLinkContext, phFriNfc_LlcpMac_eLinkActivated);
- }
-
- return status;
-}
-
-
-static NFCSTATUS phFriNfc_Llcp_HandleMACLinkActivated( phFriNfc_Llcp_t *Llcp,
- phNfc_sData_t *psParamsTLV)
-{
- NFCSTATUS status = NFCSTATUS_SUCCESS;
-
- /* Create the timer */
- Llcp->hSymmTimer = phOsalNfc_Timer_Create();
- if (Llcp->hSymmTimer == PH_OSALNFC_INVALID_TIMER_ID)
- {
- /* Error: unable to create timer */
- return NFCSTATUS_INSUFFICIENT_RESOURCES;
- }
-
- /* Check if params received from MAC activation procedure */
- if (psParamsTLV == NULL)
- {
- /* No params with selected MAC mapping, enter PAX mode for parameter exchange */
- Llcp->state = PHFRINFC_LLCP_STATE_PAX;
- /* Set default MIU for PAX exchange */
- Llcp->sRemoteParams.miu = PHFRINFC_LLCP_MIU_DEFAULT;
- /* If the local device is the initiator, it must initiate PAX exchange */
- if (Llcp->eRole == phFriNfc_LlcpMac_ePeerTypeInitiator)
- {
- /* Send PAX */
- status = phFriNfc_Llcp_SendPax(Llcp, &Llcp->sLocalParams);
- }
- }
- else
- {
- /* Params exchanged during MAX activation, try LLC activation */
- status = phFriNfc_Llcp_InternalActivate(Llcp, psParamsTLV);
- }
-
- if (status == NFCSTATUS_SUCCESS)
- {
- /* Start listening for incoming packets */
- Llcp->sRxBuffer.length = Llcp->nRxBufferLength;
- phFriNfc_LlcpMac_Receive(&Llcp->MAC, &Llcp->sRxBuffer, phFriNfc_Llcp_Receive_CB, Llcp);
- }
-
- return status;
-}
-
-
-static void phFriNfc_Llcp_HandleMACLinkDeactivated( phFriNfc_Llcp_t *Llcp )
-{
- uint8_t state = Llcp->state;
-
- /* Delete the timer */
- if (Llcp->hSymmTimer != PH_OSALNFC_INVALID_TIMER_ID)
- {
- phOsalNfc_Timer_Delete(Llcp->hSymmTimer);
- }
-
- /* Reset state */
- Llcp->state = PHFRINFC_LLCP_STATE_RESET_INIT;
-
- switch (state)
- {
- case PHFRINFC_LLCP_STATE_DEACTIVATION:
- {
- /* The service layer has already been notified, nothing more to do */
- break;
- }
- default:
- {
- /* Notify service layer of link failure */
- Llcp->pfLink_CB(Llcp->pLinkContext, phFriNfc_LlcpMac_eLinkDeactivated);
- break;
- }
- }
-}
-
-
-static void phFriNfc_Llcp_ChkLlcp_CB( void *pContext,
- NFCSTATUS status )
-{
- /* Get monitor from context */
- phFriNfc_Llcp_t *Llcp = (phFriNfc_Llcp_t*)pContext;
-
- /* Update state */
- Llcp->state = PHFRINFC_LLCP_STATE_CHECKED;
-
- /* Invoke callback */
- Llcp->pfChk_CB(Llcp->pChkContext, status);
-}
-
-static void phFriNfc_Llcp_LinkStatus_CB( void *pContext,
- phFriNfc_LlcpMac_eLinkStatus_t eLinkStatus,
- phNfc_sData_t *psParamsTLV,
- phFriNfc_LlcpMac_ePeerType_t PeerRemoteDevType)
-{
- NFCSTATUS status;
-
- /* Get monitor from context */
- phFriNfc_Llcp_t *Llcp = (phFriNfc_Llcp_t*)pContext;
-
- /* Save the local peer role (initiator/target) */
- Llcp->eRole = PeerRemoteDevType;
-
- /* Check new link status */
- switch(eLinkStatus)
- {
- case phFriNfc_LlcpMac_eLinkActivated:
- {
- /* Handle MAC link activation */
- status = phFriNfc_Llcp_HandleMACLinkActivated(Llcp, psParamsTLV);
- if (status != NFCSTATUS_SUCCESS)
- {
- /* Error: LLC link activation procedure failed, deactivate MAC link */
- status = phFriNfc_Llcp_InternalDeactivate(Llcp);
- }
- break;
- }
- case phFriNfc_LlcpMac_eLinkDeactivated:
- {
- /* Handle MAC link deactivation (cannot fail) */
- phFriNfc_Llcp_HandleMACLinkDeactivated(Llcp);
- break;
- }
- default:
- {
- /* Warning: Unknown link status, should not happen */
- }
- }
-}
-
-
-static void phFriNfc_Llcp_ResetLTO( phFriNfc_Llcp_t *Llcp )
-{
- uint32_t nDuration = 0;
- uint8_t bIsReset = 0;
-
- /* Stop timer */
- phOsalNfc_Timer_Stop(Llcp->hSymmTimer);
-
-
- /* Update state */
- if (Llcp->state == PHFRINFC_LLCP_STATE_OPERATION_RECV)
- {
- Llcp->state = PHFRINFC_LLCP_STATE_OPERATION_SEND;
- }
- else if (Llcp->state == PHFRINFC_LLCP_STATE_OPERATION_SEND)
- {
- Llcp->state = PHFRINFC_LLCP_STATE_OPERATION_RECV;
- }
- else if (Llcp->state != PHFRINFC_LLCP_STATE_DEACTIVATION &&
- Llcp->state != PHFRINFC_LLCP_STATE_RESET_INIT)
- {
- bIsReset = 1;
- /* Not yet in OPERATION state, perform first reset */
- if (Llcp->eRole == phFriNfc_LlcpMac_ePeerTypeInitiator)
- {
- Llcp->state = PHFRINFC_LLCP_STATE_OPERATION_SEND;
- }
- else
- {
- Llcp->state = PHFRINFC_LLCP_STATE_OPERATION_RECV;
- }
- }
-
- /* Calculate timer duration */
- /* NOTE: nDuration is in 1/100s, and timer system takes values in 1/1000s */
- if (Llcp->state == PHFRINFC_LLCP_STATE_OPERATION_RECV)
- {
- /* Response must be received before LTO announced by remote peer */
- nDuration = Llcp->sRemoteParams.lto * 10;
- }
- else
- {
- if (bIsReset)
- {
- /* Immediately bounce SYMM back - it'll take
- * a while for the host to come up with something,
- * and maybe the remote is faster.
- */
- nDuration = 1;
- }
- else
- {
- /* Must answer before the local announced LTO */
- /* NOTE: to ensure the answer is completely sent before LTO, the
- timer is triggered _before_ LTO expiration */
- /* TODO: make sure time scope is enough, and avoid use of magic number */
- nDuration = (Llcp->sLocalParams.lto * 10) / 2;
- }
- }
-
- LLCP_DEBUG("Starting LLCP timer with duration %d", nDuration);
-
- /* Restart timer */
- phOsalNfc_Timer_Start(
- Llcp->hSymmTimer,
- nDuration,
- phFriNfc_Llcp_Timer_CB,
- Llcp);
-}
-
-
-static NFCSTATUS phFriNfc_Llcp_HandleLinkPacket( phFriNfc_Llcp_t *Llcp,
- phNfc_sData_t *psPacket )
-{
- NFCSTATUS result;
- phFriNfc_Llcp_sPacketHeader_t sHeader;
-
- /* Parse header */
- phFriNfc_Llcp_Buffer2Header(psPacket->buffer, 0, &sHeader);
-
- /* Check packet type */
- switch (sHeader.ptype)
- {
- case PHFRINFC_LLCP_PTYPE_SYMM:
- {
- /* Nothing to do, the LTO is handled upon all packet reception */
- result = NFCSTATUS_SUCCESS;
- break;
- }
-
- case PHFRINFC_LLCP_PTYPE_AGF:
- {
- /* Handle the aggregated packet */
- result = phFriNfc_Llcp_HandleAggregatedPacket(Llcp, psPacket);
- if (result != NFCSTATUS_SUCCESS)
- {
- /* Error: invalid info field, dropping frame */
- }
- break;
- }
-
- case PHFRINFC_LLCP_PTYPE_DISC:
- {
- /* Handle link disconnection request */
- result = phFriNfc_Llcp_InternalDeactivate(Llcp);
- break;
- }
-
-
- case PHFRINFC_LLCP_PTYPE_FRMR:
- {
- /* TODO: what to do upon reception of FRMR on Link SAP ? */
- result = NFCSTATUS_SUCCESS;
- break;
- }
-
- case PHFRINFC_LLCP_PTYPE_PAX:
- {
- /* Ignore PAX when in Normal Operation */
- result = NFCSTATUS_SUCCESS;
- break;
- }
-
- default:
- {
- /* Error: invalid ptype field, dropping packet */
- result = NFCSTATUS_FAILED;
- break;
- }
- }
-
- return result;
-}
-
-
-static NFCSTATUS phFriNfc_Llcp_HandleTransportPacket( phFriNfc_Llcp_t *Llcp,
- phNfc_sData_t *psPacket )
-{
- phFriNfc_Llcp_Recv_CB_t pfRecvCB;
- void *pContext;
- NFCSTATUS result = NFCSTATUS_SUCCESS;
-
- /* Forward to upper layer */
- if (Llcp->pfRecvCB != NULL)
- {
- /* Get callback details */
- pfRecvCB = Llcp->pfRecvCB;
- pContext = Llcp->pRecvContext;
- /* Reset callback details */
- Llcp->pfRecvCB = NULL;
- Llcp->pRecvContext = NULL;
- /* Call the callback */
- (pfRecvCB)(pContext, psPacket, NFCSTATUS_SUCCESS);
- }
-
- return result;
-}
-
-
-static bool_t phFriNfc_Llcp_HandlePendingSend ( phFriNfc_Llcp_t *Llcp )
-{
- phFriNfc_Llcp_sPacketHeader_t sHeader;
- phNfc_sData_t sInfoBuffer;
- phFriNfc_Llcp_sPacketHeader_t *psSendHeader = NULL;
- phFriNfc_Llcp_sPacketSequence_t *psSendSequence = NULL;
- phNfc_sData_t *psSendInfo = NULL;
- NFCSTATUS result;
- uint8_t bDeallocate = FALSE;
- uint8_t return_value = FALSE;
- /* Handle pending disconnection request */
- if (Llcp->bDiscPendingFlag == TRUE)
- {
- /* Last send si acheived, send the pending DISC packet */
- sHeader.dsap = PHFRINFC_LLCP_SAP_LINK;
- sHeader.ssap = PHFRINFC_LLCP_SAP_LINK;
- sHeader.ptype = PHFRINFC_LLCP_PTYPE_DISC;
- /* Set send params */
- psSendHeader = &sHeader;
- /* Reset flag */
- Llcp->bDiscPendingFlag = FALSE;
- }
- /* Handle pending frame reject request */
- else if (Llcp->bFrmrPendingFlag == TRUE)
- {
- /* Last send si acheived, send the pending FRMR packet */
- sInfoBuffer.buffer = Llcp->pFrmrInfo;
- sInfoBuffer.length = sizeof(Llcp->pFrmrInfo);
- /* Set send params */
- psSendHeader = &Llcp->sFrmrHeader;
- psSendInfo = &sInfoBuffer;
- /* Reset flag */
- Llcp->bFrmrPendingFlag = FALSE;
- }
- /* Handle pending service frame */
- else if (Llcp->pfSendCB != NULL)
- {
- /* Set send params */
- psSendHeader = Llcp->psSendHeader;
- psSendSequence = Llcp->psSendSequence;
- psSendInfo = Llcp->psSendInfo;
- /* Reset pending send infos */
- Llcp->psSendHeader = NULL;
- Llcp->psSendSequence = NULL;
- Llcp->psSendInfo = NULL;
- bDeallocate = TRUE;
- }
-
- /* Perform send, if needed */
- if (psSendHeader != NULL)
- {
- result = phFriNfc_Llcp_InternalSend(Llcp, psSendHeader, psSendSequence, psSendInfo);
- if ((result != NFCSTATUS_SUCCESS) && (result != NFCSTATUS_PENDING))
- {
- /* Error: send failed, impossible to recover */
- phFriNfc_Llcp_InternalDeactivate(Llcp);
- }
- return_value = TRUE;
- } else if (Llcp->pfSendCB == NULL) {
- // Nothing to send, send SYMM instead to allow peer to send something
- // if it wants.
- phFriNfc_Llcp_SendSymm(Llcp);
- return_value = TRUE;
- }
-
- if (bDeallocate)
- {
- phFriNfc_Llcp_Deallocate(psSendInfo);
- }
-
- return return_value;
-}
-
-static NFCSTATUS phFriNfc_Llcp_HandleIncomingPacket( phFriNfc_Llcp_t *Llcp,
- phNfc_sData_t *psPacket )
-{
- NFCSTATUS status = NFCSTATUS_SUCCESS;
- phFriNfc_Llcp_sPacketHeader_t sHeader;
-
- /* Parse header */
- phFriNfc_Llcp_Buffer2Header(psPacket->buffer, 0, &sHeader);
-
- /* Check destination */
- if (sHeader.dsap == PHFRINFC_LLCP_SAP_LINK)
- {
- /* Handle packet as destinated to the Link SAP */
- status = phFriNfc_Llcp_HandleLinkPacket(Llcp, psPacket);
- }
- else if (sHeader.dsap >= PHFRINFC_LLCP_SAP_NUMBER)
- {
- /* NOTE: this cannot happen since "psHeader->dsap" is only 6-bit wide */
- status = NFCSTATUS_FAILED;
- }
- else
- {
- /* Handle packet as destinated to the SDP and transport SAPs */
- status = phFriNfc_Llcp_HandleTransportPacket(Llcp, psPacket);
- }
- return status;
-}
-
-
-static void phFriNfc_Llcp_Receive_CB( void *pContext,
- NFCSTATUS status,
- phNfc_sData_t *psData)
-{
- /* Get monitor from context */
- phFriNfc_Llcp_t *Llcp = (phFriNfc_Llcp_t*)pContext;
- NFCSTATUS result = NFCSTATUS_SUCCESS;
- phFriNfc_Llcp_sPacketHeader_t sPacketHeader;
-
- /* Check reception status and for pending disconnection */
- if ((status != NFCSTATUS_SUCCESS) || (Llcp->bDiscPendingFlag == TRUE))
- {
- LLCP_DEBUG("\nReceived LLCP packet error - status = 0x%04x", status);
- /* Reset disconnection operation */
- Llcp->bDiscPendingFlag = FALSE;
- /* Deactivate the link */
- phFriNfc_Llcp_InternalDeactivate(Llcp);
- return;
- }
-
- /* Parse header */
- phFriNfc_Llcp_Buffer2Header(psData->buffer, 0, &sPacketHeader);
-
- if (sPacketHeader.ptype != PHFRINFC_LLCP_PTYPE_SYMM)
- {
- LLCP_PRINT_BUFFER("\nReceived LLCP packet :", psData->buffer, psData->length);
- }
- else
- {
- LLCP_PRINT("?");
- }
-
-
- /* Check new link status */
- switch(Llcp->state)
- {
- /* Handle packets in PAX-waiting state */
- case PHFRINFC_LLCP_STATE_PAX:
- {
- /* Check packet type */
- if (sPacketHeader.ptype == PHFRINFC_LLCP_PTYPE_PAX)
- {
- /* Params exchanged during MAC activation, try LLC activation */
- result = phFriNfc_Llcp_InternalActivate(Llcp, psData+PHFRINFC_LLCP_PACKET_HEADER_SIZE);
- /* If the local LLC is the target, it must answer the PAX */
- if (Llcp->eRole == phFriNfc_LlcpMac_ePeerTypeTarget)
- {
- /* Send PAX */
- result = phFriNfc_Llcp_SendPax(Llcp, &Llcp->sLocalParams);
- }
- }
- else
- {
- /* Warning: Received packet with unhandled type in PAX-waiting state, drop it */
- }
- break;
- }
-
- /* Handle normal operation packets */
- case PHFRINFC_LLCP_STATE_OPERATION_RECV:
- case PHFRINFC_LLCP_STATE_OPERATION_SEND:
- {
- /* Handle Symmetry procedure by resetting LTO timer */
- phFriNfc_Llcp_ResetLTO(Llcp);
- /* Handle packet */
- result = phFriNfc_Llcp_HandleIncomingPacket(Llcp, psData);
- if ( (result != NFCSTATUS_SUCCESS) &&
- (result != NFCSTATUS_PENDING) )
- {
- /* TODO: Error: invalid frame */
- }
- /* Perform pending send request, if any */
- phFriNfc_Llcp_HandlePendingSend(Llcp);
- break;
- }
-
- default:
- {
- /* Warning: Should not receive packets in other states, drop them */
- }
- }
-
- /* Restart reception */
- Llcp->sRxBuffer.length = Llcp->nRxBufferLength;
- phFriNfc_LlcpMac_Receive(&Llcp->MAC, &Llcp->sRxBuffer, phFriNfc_Llcp_Receive_CB, Llcp);
-}
-
-
-static void phFriNfc_Llcp_Send_CB( void *pContext,
- NFCSTATUS status )
-{
- /* Get monitor from context */
- phFriNfc_Llcp_t *Llcp = (phFriNfc_Llcp_t*)pContext;
- phFriNfc_Llcp_Send_CB_t pfSendCB;
- void *pSendContext;
-
- /* Call the upper layer callback if last packet sent was */
- /* NOTE: if Llcp->psSendHeader is not NULL, this means that the send operation is still not initiated */
- if (Llcp->psSendHeader == NULL)
- {
- if (Llcp->pfSendCB != NULL)
- {
- /* Get Callback params */
- pfSendCB = Llcp->pfSendCB;
- pSendContext = Llcp->pSendContext;
- /* Reset callback params */
- Llcp->pfSendCB = NULL;
- Llcp->pSendContext = NULL;
- /* Call the callback */
- (pfSendCB)(pSendContext, status);
- }
- }
-
- /* Check reception status */
- if (status != NFCSTATUS_SUCCESS)
- {
- /* Error: Reception failed, link must be down */
- phFriNfc_Llcp_InternalDeactivate(Llcp);
- }
-}
-
-
-static NFCSTATUS phFriNfc_Llcp_InternalSend( phFriNfc_Llcp_t *Llcp,
- phFriNfc_Llcp_sPacketHeader_t *psHeader,
- phFriNfc_Llcp_sPacketSequence_t *psSequence,
- phNfc_sData_t *psInfo )
-{
- NFCSTATUS status;
- phNfc_sData_t *psRawPacket = &Llcp->sTxBuffer; /* Use internal Tx buffer */
-
- /* Handle Symmetry procedure */
- phFriNfc_Llcp_ResetLTO(Llcp);
-
- /* Generate raw packet to send (aggregate header + sequence + info fields) */
- psRawPacket->length = 0;
- psRawPacket->length += phFriNfc_Llcp_Header2Buffer(psHeader, psRawPacket->buffer, psRawPacket->length);
- if (psSequence != NULL)
- {
- psRawPacket->length += phFriNfc_Llcp_Sequence2Buffer(psSequence, psRawPacket->buffer, psRawPacket->length);
- }
- if (psInfo != NULL)
- {
- memcpy(psRawPacket->buffer + psRawPacket->length, psInfo->buffer, psInfo->length);
- psRawPacket->length += psInfo->length;
- }
-
- if (psHeader->ptype != PHFRINFC_LLCP_PTYPE_SYMM)
- {
- LLCP_PRINT_BUFFER("\nSending LLCP packet :", psRawPacket->buffer, psRawPacket->length);
- }
- else
- {
- LLCP_PRINT("!");
- }
-
- /* Send raw packet */
- status = phFriNfc_LlcpMac_Send (
- &Llcp->MAC,
- psRawPacket,
- phFriNfc_Llcp_Send_CB,
- Llcp );
-
- return status;
-}
-
-/* ---------------------------- Public functions ------------------------------- */
-
-NFCSTATUS phFriNfc_Llcp_EncodeLinkParams( phNfc_sData_t *psRawBuffer,
- phFriNfc_Llcp_sLinkParameters_t *psLinkParams,
- uint8_t nVersion )
-{
- uint32_t nOffset = 0;
- uint16_t miux;
- uint16_t wks;
- uint8_t pValue[2];
- NFCSTATUS result = NFCSTATUS_SUCCESS;
-
- /* Check parameters */
- if ((psRawBuffer == NULL) || (psLinkParams == NULL))
- {
- return NFCSTATUS_INVALID_PARAMETER;
- }
-
- /* Encode mandatory VERSION field */
- if (result == NFCSTATUS_SUCCESS)
- {
- result = phFriNfc_Llcp_EncodeTLV(
- psRawBuffer,
- &nOffset,
- PHFRINFC_LLCP_TLV_TYPE_VERSION,
- PHFRINFC_LLCP_TLV_LENGTH_VERSION,
- &nVersion);
- }
-
- /* Encode mandatory VERSION field */
- if (result == NFCSTATUS_SUCCESS)
- {
- /* Encode MIUX field, if needed */
- if (psLinkParams->miu != PHFRINFC_LLCP_MIU_DEFAULT)
- {
- miux = (psLinkParams->miu - PHFRINFC_LLCP_MIU_DEFAULT) & PHFRINFC_LLCP_TLV_MIUX_MASK;
- pValue[0] = (miux >> 8) & 0xFF;
- pValue[1] = miux & 0xFF;
- result = phFriNfc_Llcp_EncodeTLV(
- psRawBuffer,
- &nOffset,
- PHFRINFC_LLCP_TLV_TYPE_MIUX,
- PHFRINFC_LLCP_TLV_LENGTH_MIUX,
- pValue);
- }
- }
-
- /* Encode WKS field */
- if (result == NFCSTATUS_SUCCESS)
- {
- wks = psLinkParams->wks | PHFRINFC_LLCP_TLV_WKS_MASK;
- pValue[0] = (wks >> 8) & 0xFF;
- pValue[1] = wks & 0xFF;
- result = phFriNfc_Llcp_EncodeTLV(
- psRawBuffer,
- &nOffset,
- PHFRINFC_LLCP_TLV_TYPE_WKS,
- PHFRINFC_LLCP_TLV_LENGTH_WKS,
- pValue);
- }
-
- /* Encode LTO field, if needed */
- if (result == NFCSTATUS_SUCCESS)
- {
- if (psLinkParams->lto != PHFRINFC_LLCP_LTO_DEFAULT)
- {
- result = phFriNfc_Llcp_EncodeTLV(
- psRawBuffer,
- &nOffset,
- PHFRINFC_LLCP_TLV_TYPE_LTO,
- PHFRINFC_LLCP_TLV_LENGTH_LTO,
- &psLinkParams->lto);
- }
- }
-
- /* Encode OPT field, if needed */
- if (result == NFCSTATUS_SUCCESS)
- {
- if (psLinkParams->option != PHFRINFC_LLCP_OPTION_DEFAULT)
- {
- result = phFriNfc_Llcp_EncodeTLV(
- psRawBuffer,
- &nOffset,
- PHFRINFC_LLCP_TLV_TYPE_OPT,
- PHFRINFC_LLCP_TLV_LENGTH_OPT,
- &psLinkParams->option);
- }
- }
-
- if (result != NFCSTATUS_SUCCESS)
- {
- /* Error: failed to encode TLV */
- return NFCSTATUS_FAILED;
- }
-
- /* Save new buffer size */
- psRawBuffer->length = nOffset;
-
- return result;
-}
-
-
-NFCSTATUS phFriNfc_Llcp_Reset( phFriNfc_Llcp_t *Llcp,
- void *LowerDevice,
- phFriNfc_Llcp_sLinkParameters_t *psLinkParams,
- void *pRxBuffer,
- uint16_t nRxBufferLength,
- void *pTxBuffer,
- uint16_t nTxBufferLength,
- phFriNfc_Llcp_LinkStatus_CB_t pfLink_CB,
- void *pContext )
-{
- const uint16_t nMaxHeaderSize = PHFRINFC_LLCP_PACKET_HEADER_SIZE +
- PHFRINFC_LLCP_PACKET_SEQUENCE_SIZE;
- NFCSTATUS result;
-
- /* Check parameters presence */
- if ((Llcp == NULL) || (LowerDevice == NULL) || (pfLink_CB == NULL) ||
- (pRxBuffer == NULL) || (pTxBuffer == NULL) )
- {
- return NFCSTATUS_INVALID_PARAMETER;
- }
-
- /* Check parameters value */
- if (psLinkParams->miu < PHFRINFC_LLCP_MIU_DEFAULT)
- {
- return NFCSTATUS_INVALID_PARAMETER;
- }
-
- /* Check if buffers are large enough to support minimal MIU */
- if ((nRxBufferLength < (nMaxHeaderSize + PHFRINFC_LLCP_MIU_DEFAULT)) ||
- (nTxBufferLength < (nMaxHeaderSize + PHFRINFC_LLCP_MIU_DEFAULT)) )
- {
- return NFCSTATUS_BUFFER_TOO_SMALL;
- }
-
- /* Check compatibility between reception buffer size and announced MIU */
- if (nRxBufferLength < (nMaxHeaderSize + psLinkParams->miu))
- {
- return NFCSTATUS_BUFFER_TOO_SMALL;
- }
-
- /* Start with a zero-filled monitor */
- memset(Llcp, 0x00, sizeof(phFriNfc_Llcp_t));
-
- /* Reset the MAC Mapping layer */
- result = phFriNfc_LlcpMac_Reset(&Llcp->MAC, LowerDevice, phFriNfc_Llcp_LinkStatus_CB, Llcp);
- if (result != NFCSTATUS_SUCCESS) {
- return result;
- }
-
- /* Save the working buffers */
- Llcp->sRxBuffer.buffer = pRxBuffer;
- Llcp->sRxBuffer.length = nRxBufferLength;
- Llcp->nRxBufferLength = nRxBufferLength;
- Llcp->sTxBuffer.buffer = pTxBuffer;
- Llcp->sTxBuffer.length = nTxBufferLength;
- Llcp->nTxBufferLength = nTxBufferLength;
-
- /* Save the link status callback references */
- Llcp->pfLink_CB = pfLink_CB;
- Llcp->pLinkContext = pContext;
-
- /* Save the local link parameters */
- memcpy(&Llcp->sLocalParams, psLinkParams, sizeof(phFriNfc_Llcp_sLinkParameters_t));
-
- return NFCSTATUS_SUCCESS;
-}
-
-
-NFCSTATUS phFriNfc_Llcp_ChkLlcp( phFriNfc_Llcp_t *Llcp,
- phHal_sRemoteDevInformation_t *psRemoteDevInfo,
- phFriNfc_Llcp_Check_CB_t pfCheck_CB,
- void *pContext )
-{
- /* Check parameters */
- if ( (Llcp == NULL) || (psRemoteDevInfo == NULL) || (pfCheck_CB == NULL) )
- {
- return PHNFCSTVAL(CID_FRI_NFC_LLCP, NFCSTATUS_INVALID_PARAMETER);
- }
-
- /* Check current state */
- if( Llcp->state != PHFRINFC_LLCP_STATE_RESET_INIT ) {
- return PHNFCSTVAL(CID_FRI_NFC_LLCP, NFCSTATUS_INVALID_STATE);
- }
-
- /* Save the compliance check callback */
- Llcp->pfChk_CB = pfCheck_CB;
- Llcp->pChkContext = pContext;
-
- /* Forward check request to MAC layer */
- return phFriNfc_LlcpMac_ChkLlcp(&Llcp->MAC, psRemoteDevInfo, phFriNfc_Llcp_ChkLlcp_CB, (void*)Llcp);
-}
-
-
-NFCSTATUS phFriNfc_Llcp_Activate( phFriNfc_Llcp_t *Llcp )
-{
- /* Check parameters */
- if (Llcp == NULL)
- {
- return PHNFCSTVAL(CID_FRI_NFC_LLCP, NFCSTATUS_INVALID_PARAMETER);
- }
-
- /* Check current state */
- if( Llcp->state != PHFRINFC_LLCP_STATE_CHECKED ) {
- return PHNFCSTVAL(CID_FRI_NFC_LLCP, NFCSTATUS_INVALID_STATE);
- }
-
- /* Update state */
- Llcp->state = PHFRINFC_LLCP_STATE_ACTIVATION;
-
- /* Reset any headers to send */
- Llcp->psSendHeader = NULL;
- Llcp->psSendSequence = NULL;
-
- /* Forward check request to MAC layer */
- return phFriNfc_LlcpMac_Activate(&Llcp->MAC);
-}
-
-
-NFCSTATUS phFriNfc_Llcp_Deactivate( phFriNfc_Llcp_t *Llcp )
-{
- NFCSTATUS status;
-
- /* Check parameters */
- if (Llcp == NULL)
- {
- return PHNFCSTVAL(CID_FRI_NFC_LLCP, NFCSTATUS_INVALID_PARAMETER);
- }
-
- /* Check current state */
- if( (Llcp->state != PHFRINFC_LLCP_STATE_OPERATION_RECV) &&
- (Llcp->state != PHFRINFC_LLCP_STATE_OPERATION_SEND) ) {
- return PHNFCSTVAL(CID_FRI_NFC_LLCP, NFCSTATUS_INVALID_STATE);
- }
-
- /* Send DISC packet */
- status = phFriNfc_Llcp_SendDisconnect(Llcp);
- if (status == NFCSTATUS_PENDING)
- {
- /* Wait for packet to be sent before deactivate link */
- return status;
- }
-
- /* Perform actual deactivation */
- return phFriNfc_Llcp_InternalDeactivate(Llcp);
-}
-
-
-NFCSTATUS phFriNfc_Llcp_GetLocalInfo( phFriNfc_Llcp_t *Llcp,
- phFriNfc_Llcp_sLinkParameters_t *pParams )
-{
- /* Check parameters */
- if ((Llcp == NULL) || (pParams == NULL))
- {
- return PHNFCSTVAL(CID_FRI_NFC_LLCP, NFCSTATUS_INVALID_PARAMETER);
- }
-
- /* Copy response */
- memcpy(pParams, &Llcp->sLocalParams, sizeof(phFriNfc_Llcp_sLinkParameters_t));
-
- return NFCSTATUS_SUCCESS;
-}
-
-
-NFCSTATUS phFriNfc_Llcp_GetRemoteInfo( phFriNfc_Llcp_t *Llcp,
- phFriNfc_Llcp_sLinkParameters_t *pParams )
-{
- /* Check parameters */
- if ((Llcp == NULL) || (pParams == NULL))
- {
- return PHNFCSTVAL(CID_FRI_NFC_LLCP, NFCSTATUS_INVALID_PARAMETER);
- }
-
- /* Copy response */
- memcpy(pParams, &Llcp->sRemoteParams, sizeof(phFriNfc_Llcp_sLinkParameters_t));
-
- return NFCSTATUS_SUCCESS;
-}
-
-
-NFCSTATUS phFriNfc_Llcp_Send( phFriNfc_Llcp_t *Llcp,
- phFriNfc_Llcp_sPacketHeader_t *psHeader,
- phFriNfc_Llcp_sPacketSequence_t *psSequence,
- phNfc_sData_t *psInfo,
- phFriNfc_Llcp_Send_CB_t pfSend_CB,
- void *pContext )
-{
- NFCSTATUS result;
- /* Check parameters */
- if ((Llcp == NULL) || (psHeader == NULL) || (pfSend_CB == NULL))
- {
- return PHNFCSTVAL(CID_FRI_NFC_LLCP, NFCSTATUS_INVALID_PARAMETER);
- }
-
- /* Check if previous phFriNfc_Llcp_Send() has finished */
- if (Llcp->pfSendCB != NULL)
- {
- /* Error: a send operation is already running */
- return PHNFCSTVAL(CID_FRI_NFC_LLCP, NFCSTATUS_REJECTED);
- }
-
- /* Save the callback parameters */
- Llcp->pfSendCB = pfSend_CB;
- Llcp->pSendContext = pContext;
-
- if (Llcp->state == PHFRINFC_LLCP_STATE_OPERATION_SEND)
- {
- /* Ready to send */
- result = phFriNfc_Llcp_InternalSend(Llcp, psHeader, psSequence, psInfo);
- }
- else if (Llcp->state == PHFRINFC_LLCP_STATE_OPERATION_RECV)
- {
- /* Not ready to send, save send params for later use */
- Llcp->psSendHeader = psHeader;
- Llcp->psSendSequence = psSequence;
- Llcp->psSendInfo = phFriNfc_Llcp_AllocateAndCopy(psInfo);
- result = NFCSTATUS_PENDING;
- }
- else
- {
- /* Incorrect state for sending ! */
- result = PHNFCSTVAL(CID_FRI_NFC_LLCP, NFCSTATUS_INVALID_STATE);;
- }
-
- if (result != NFCSTATUS_PENDING) {
- Llcp->pfSendCB = NULL;
- }
- return result;
-}
-
-
-NFCSTATUS phFriNfc_Llcp_Recv( phFriNfc_Llcp_t *Llcp,
- phFriNfc_Llcp_Recv_CB_t pfRecv_CB,
- void *pContext )
-{
- NFCSTATUS result = NFCSTATUS_SUCCESS;
-
- /* Check parameters */
- if ((Llcp == NULL) || (pfRecv_CB == NULL))
- {
- return PHNFCSTVAL(CID_FRI_NFC_LLCP, NFCSTATUS_INVALID_PARAMETER);
- }
-
- /* Check if previous phFriNfc_Llcp_Recv() has finished */
- if (Llcp->pfRecvCB != NULL)
- {
- /* Error: a send operation is already running */
- return PHNFCSTVAL(CID_FRI_NFC_LLCP, NFCSTATUS_REJECTED);
- }
-
- /* Save the callback parameters */
- Llcp->pfRecvCB = pfRecv_CB;
- Llcp->pRecvContext = pContext;
-
- /* NOTE: nothing more to do, the receive function is called in background */
-
- return result;
-}
diff --git a/libnfc-nxp/phFriNfc_Llcp.h b/libnfc-nxp/phFriNfc_Llcp.h
deleted file mode 100644
index 728697f..0000000
--- a/libnfc-nxp/phFriNfc_Llcp.h
+++ /dev/null
@@ -1,463 +0,0 @@
-/*
- * Copyright (C) 2010 NXP Semiconductors
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-/**
- * \file phFriNfc_Llcp.h
- * \brief NFC LLCP core
- *
- * Project: NFC-FRI
- *
- */
-
-#ifndef PHFRINFC_LLCP_H
-#define PHFRINFC_LLCP_H
-
-/*include files*/
-#include
-#include
-#include
-#include
-
-#include
-
-/**
- * \name NFC Forum Logical Link Control Protocol
- *
- * File: \ref phFriNfc_Llcp.h
- *
- */
-
-
-/** \defgroup grp_fri_nfc_llcp NFC Forum Logical Link Control Protocol Component
- *
- * TODO
- *
- */
-
-/*=========== DEBUG MACROS ===========*/
-
-/* LLCP TRACE Macros */
-#if defined(LLCP_TRACE)
-#include
-#include
-extern char phOsalNfc_DbgTraceBuffer[];
-#define LLCP_MAX_TRACE_BUFFER 150
-#define LLCP_PRINT( str ) phOsalNfc_DbgString(str)
-#define LLCP_DEBUG(str, arg) \
- { \
- snprintf(phOsalNfc_DbgTraceBuffer,LLCP_MAX_TRACE_BUFFER,str,arg); \
- phOsalNfc_DbgString(phOsalNfc_DbgTraceBuffer); \
- }
-#define LLCP_PRINT_BUFFER(msg,buf,len) \
- { \
- snprintf(phOsalNfc_DbgTraceBuffer,LLCP_MAX_TRACE_BUFFER,"\n\t %s:",msg); \
- phOsalNfc_DbgString(phOsalNfc_DbgTraceBuffer); \
- phOsalNfc_DbgTrace(buf,len); \
- phOsalNfc_DbgString("\r"); \
- }
-#else
-#define LLCP_PRINT( str )
-#define LLCP_DEBUG(str, arg)
-#define LLCP_PRINT_BUFFER(msg,buf,len)
-#endif
-
-
-/*=========== CONSTANTS ===========*/
-
-/**
- * \name LLCP local protocol version.
- *
- */
- /*@{*/
-#define PHFRINFC_LLCP_VERSION_MAJOR 0x01 /**< Major number of local LLCP version.*/
-#define PHFRINFC_LLCP_VERSION_MINOR 0x01 /**< Minor number of local LLCP version.*/
-#define PHFRINFC_LLCP_VERSION ((PHFRINFC_LLCP_VERSION_MAJOR << 4) | PHFRINFC_LLCP_VERSION_MINOR) /**< Local LLCP version.*/
-/*@}*/
-
-/**
- * \name LLCP packet types.
- *
- */
- /*@{*/
-#define PHFRINFC_LLCP_PTYPE_SYMM 0x00 /**< Symmetry.*/
-#define PHFRINFC_LLCP_PTYPE_PAX 0x01 /**< PArameter Exchange.*/
-#define PHFRINFC_LLCP_PTYPE_AGF 0x02 /**< AGgregated Frame.*/
-#define PHFRINFC_LLCP_PTYPE_UI 0x03 /**< Unnumbered Information.*/
-#define PHFRINFC_LLCP_PTYPE_CONNECT 0x04 /**< Connect.*/
-#define PHFRINFC_LLCP_PTYPE_DISC 0x05 /**< Disconnect.*/
-#define PHFRINFC_LLCP_PTYPE_CC 0x06 /**< Connection Complete.*/
-#define PHFRINFC_LLCP_PTYPE_DM 0x07 /**< Disconnected Mode.*/
-#define PHFRINFC_LLCP_PTYPE_FRMR 0x08 /**< FRaMe Reject.*/
-#define PHFRINFC_LLCP_PTYPE_SNL 0x09 /**< Service Name Lookup.*/
-#define PHFRINFC_LLCP_PTYPE_RESERVED1 0x0A /**< Reserved.*/
-#define PHFRINFC_LLCP_PTYPE_RESERVED2 0x0B /**< Reserved.*/
-#define PHFRINFC_LLCP_PTYPE_I 0x0C /**< Information.*/
-#define PHFRINFC_LLCP_PTYPE_RR 0x0D /**< Receive Ready.*/
-#define PHFRINFC_LLCP_PTYPE_RNR 0x0E /**< Receive Not Ready.*/
-#define PHFRINFC_LLCP_PTYPE_RESERVED3 0x0F /**< Reserved.*/
-/*@}*/
-
-/**
- * \name LLCP well-known SAPs.
- *
- */
- /*@{*/
-#define PHFRINFC_LLCP_SAP_LINK 0x00 /**< Link SAP.*/
-#define PHFRINFC_LLCP_SAP_SDP 0x01 /**< Service Discovery Protocol SAP.*/
-#define PHFRINFC_LLCP_SAP_WKS_FIRST 0x02 /**< Other Well-Known Services defined by the NFC Forum.*/
-#define PHFRINFC_LLCP_SAP_SDP_ADVERTISED_FIRST 0x10 /**< First SAP number from SDP-avertised SAP range.*/
-#define PHFRINFC_LLCP_SAP_SDP_UNADVERTISED_FIRST 0x20 /**< First SAP number from SDP-unavertised SAP range.*/
-#define PHFRINFC_LLCP_SAP_NUMBER 0x40 /**< Number of possible SAP values (also first invalid value).*/
-#define PHFRINFC_LLCP_SAP_DEFAULT 0xFF /**< Default number when a socket is created or reset */
-#define PHFRINFC_LLCP_SDP_ADVERTISED_NB 0x10 /**< Number of SDP advertised SAP slots */
-/*@}*/
-
-/**
- * \name LLCP well-known SAPs.
- *
- */
- /*@{*/
-#define PHFRINFC_LLCP_SERVICENAME_SDP "urn:nfc:sn:sdp" /**< Service Discovery Protocol name.*/
-/*@}*/
-
-/**
- * \name Length value for DM opCode
- *
- */
- /*@{*/
-#define PHFRINFC_LLCP_DM_LENGTH 0x01 /**< Length value for DM opCode */
-/*@}*/
-
-
-/**
- * \internal
- * \name Masks used with parameters value.
- *
- */
-/*@{*/
-#define PHFRINFC_LLCP_TLV_MIUX_MASK 0x07FF /**< \internal Mask to apply to MIUX TLV Value.*/
-#define PHFRINFC_LLCP_TLV_WKS_MASK 0x0001 /**< \internal Minimal bits to be set in WKS TLV Value.*/
-#define PHFRINFC_LLCP_TLV_RW_MASK 0x0F /**< \internal Mask to apply to RW TLV Value.*/
-#define PHFRINFC_LLCP_TLV_OPT_MASK 0x03 /**< \internal Mask to apply to OPT TLV Value.*/
-/*@}*/
-
-/**
- * \internal
- * \name Type codes for parameters in TLV.
- *
- */
-/*@{*/
-#define PHFRINFC_LLCP_TLV_TYPE_VERSION 0x01 /**< \internal VERSION parameter Type code.*/
-#define PHFRINFC_LLCP_TLV_TYPE_MIUX 0x02 /**< \internal MIUX parameter Type code.*/
-#define PHFRINFC_LLCP_TLV_TYPE_WKS 0x03 /**< \internal WKS parameter Type code.*/
-#define PHFRINFC_LLCP_TLV_TYPE_LTO 0x04 /**< \internal LTO parameter Type code.*/
-#define PHFRINFC_LLCP_TLV_TYPE_RW 0x05 /**< \internal RW parameter Type code.*/
-#define PHFRINFC_LLCP_TLV_TYPE_SN 0x06 /**< \internal SN parameter Type code.*/
-#define PHFRINFC_LLCP_TLV_TYPE_OPT 0x07 /**< \internal OPT parameter Type code.*/
-#define PHFRINFC_LLCP_TLV_TYPE_SDREQ 0x08 /**< \internal SDREQ parameter Type code.*/
-#define PHFRINFC_LLCP_TLV_TYPE_SDRES 0x09 /**< \internal SDRES parameter Type code.*/
-/*@}*/
-
-/**
- * \internal
- * \name Fixed Value length for parameters in TLV.
- *
- */
-/*@{*/
-#define PHFRINFC_LLCP_TLV_LENGTH_HEADER 2 /**< \internal Fixed length of Type and Length fields in TLV.*/
-#define PHFRINFC_LLCP_TLV_LENGTH_VERSION 1 /**< \internal Fixed length of VERSION parameter Value.*/
-#define PHFRINFC_LLCP_TLV_LENGTH_MIUX 2 /**< \internal Fixed length of MIUX parameter Value.*/
-#define PHFRINFC_LLCP_TLV_LENGTH_WKS 2 /**< \internal Fixed length of WKS parameter Value.*/
-#define PHFRINFC_LLCP_TLV_LENGTH_LTO 1 /**< \internal Fixed length of LTO parameter Value.*/
-#define PHFRINFC_LLCP_TLV_LENGTH_RW 1 /**< \internal Fixed length of RW parameter Value.*/
-#define PHFRINFC_LLCP_TLV_LENGTH_OPT 1 /**< \internal Fixed length of OPT parameter Value.*/
-/*@}*/
-
-/**
- * \name LLCP packet field sizes.
- *
- */
- /*@{*/
-#define PHFRINFC_LLCP_PACKET_HEADER_SIZE 2 /**< Size of the general packet header (DSAP+PTYPE+SSAP).*/
-#define PHFRINFC_LLCP_PACKET_SEQUENCE_SIZE 1 /**< Size of the sequence field, if present.*/
-#define PHFRINFC_LLCP_PACKET_MAX_SIZE (PHFRINFC_LLCP_PACKET_HEADER_SIZE + \
- PHFRINFC_LLCP_PACKET_SEQUENCE_SIZE + \
- PHFRINFC_LLCP_MIU_DEFAULT + \
- PHFRINFC_LLCP_TLV_MIUX_MASK) /**< Maximum size of a packet */
-/*@}*/
-
-/*========== MACROS ===========*/
-
-#define CHECK_SEND_RW(socket) ( (((socket)->socket_VS - (socket)->socket_VSA) % 16) < (socket)->remoteRW )
-
-/*========== ENUMERATES ===========*/
-
-typedef phFriNfc_LlcpMac_ePeerType_t phFriNfc_Llcp_eRole_t;
-
-typedef phFriNfc_LlcpMac_eLinkStatus_t phFriNfc_Llcp_eLinkStatus_t;
-
-/*========== CALLBACKS ===========*/
-
-typedef void (*phFriNfc_Llcp_Check_CB_t) (
- void *pContext,
- NFCSTATUS status
-);
-
-typedef void (*phFriNfc_Llcp_LinkStatus_CB_t) (
- void *pContext,
- phFriNfc_Llcp_eLinkStatus_t eLinkStatus
-);
-
-typedef void (*phFriNfc_Llcp_LinkSend_CB_t) (
- void *pContext,
- uint8_t socketIndex,
- NFCSTATUS status
-);
-
-typedef void (*phFriNfc_Llcp_Send_CB_t) (
- void *pContext,
- NFCSTATUS status
-);
-
-typedef void (*phFriNfc_Llcp_Recv_CB_t) (
- void *pContext,
- phNfc_sData_t *psData,
- NFCSTATUS status
-);
-
-/*========== STRUCTURES ===========*/
-
-typedef struct phFriNfc_Llcp_sPacketHeader
-{
- /**< The destination service access point*/
- unsigned dsap : 6;
-
- /**< The packet type*/
- unsigned ptype : 4;
-
- /**< The source service access point*/
- unsigned ssap : 6;
-
-} phFriNfc_Llcp_sPacketHeader_t;
-
-typedef struct phFriNfc_Llcp_sPacketSequence
-{
- /**< Sequence number for sending*/
- unsigned ns : 4;
-
- /**< Sequence number for reception*/
- unsigned nr : 4;
-
-} phFriNfc_Llcp_sPacketSequence_t;
-
-typedef struct phFriNfc_Llcp_sSendOperation
-{
- /**< Sequence number for sending*/
- phFriNfc_Llcp_sPacketHeader_t *psHeader;
-
- /**< Sequence number for sending*/
- phFriNfc_Llcp_sPacketSequence_t *psSequence;
-
- /**< Sequence number for sending*/
- phNfc_sData_t *psInfo;
-
- /**< Sequence number for sending*/
- phFriNfc_Llcp_Send_CB_t pfSend_CB;
-
- /**< Sequence number for sending*/
- void *pContext;
-
-} phFriNfc_Llcp_sSendOperation_t;
-
-typedef struct phFriNfc_Llcp_sRecvOperation
-{
- /**< Sequence number for sending*/
- uint8_t nSap;
-
- /**< Sequence number for sending*/
- phNfc_sData_t *psBuffer;
-
- /**< Sequence number for sending*/
- phFriNfc_Llcp_Recv_CB_t pfRecv_CB;
-
- /**< Sequence number for sending*/
- void *pContext;
-
-} phFriNfc_Llcp_sRecvOperation_t;
-
-typedef struct phFriNfc_Llcp
-{
- /**< The current state*/
- uint8_t state;
-
- /**< MAC mapping instance*/
- phFriNfc_LlcpMac_t MAC;
-
- /**< Local LLC role*/
- phFriNfc_LlcpMac_ePeerType_t eRole;
-
- /**< Local link parameters*/
- phFriNfc_Llcp_sLinkParameters_t sLocalParams;
-
- /**< Remote link parameters*/
- phFriNfc_Llcp_sLinkParameters_t sRemoteParams;
-
- /**< Negociated protocol version (major number on MSB, minor on LSB)*/
- uint8_t version;
-
- /**< Internal reception buffer, its size may vary during time but not exceed nRxBufferSize*/
- phNfc_sData_t sRxBuffer;
-
- /**< Actual size of reception buffer*/
- uint16_t nRxBufferLength;
-
- /**< Internal emission buffer, its size may vary during time but not exceed nTxBufferSize*/
- phNfc_sData_t sTxBuffer;
-
- /**< Actual size of emission buffer*/
- uint16_t nTxBufferLength;
-
- /**< Callback function for link status notification*/
- phFriNfc_Llcp_LinkStatus_CB_t pfLink_CB;
-
- /**< Callback context for link status notification*/
- void *pLinkContext;
-
- /**< Callback function for compliance checking*/
- phFriNfc_Llcp_Check_CB_t pfChk_CB;
-
- /**< Callback context for compliance checking*/
- void *pChkContext;
-
- /**< Symmetry timer*/
- uint32_t hSymmTimer;
-
- /**< Control frames buffer*/
- uint8_t pCtrlTxBuffer[10];
-
- /**< Control frames buffer size*/
- uint8_t pCtrlTxBufferLength;
-
- /**< DISC packet send pending flag*/
- bool_t bDiscPendingFlag;
-
- /**< FRMR packet send pending flag*/
- bool_t bFrmrPendingFlag;
-
- /**< Header of pending FRMR packet*/
- phFriNfc_Llcp_sPacketHeader_t sFrmrHeader;
-
- /**< Info field of pending FRMR packet*/
- uint8_t pFrmrInfo[4];
-
- /**< Send callback*/
- phFriNfc_Llcp_Send_CB_t pfSendCB;
-
- /**< Send callback*/
- void *pSendContext;
-
- /**< Pending send header*/
- phFriNfc_Llcp_sPacketHeader_t *psSendHeader;
-
- /**< Pending send sequence*/
- phFriNfc_Llcp_sPacketSequence_t *psSendSequence;
-
- /**< Pending send info*/
- phNfc_sData_t *psSendInfo;
-
- /**< Receive callback*/
- phFriNfc_Llcp_Recv_CB_t pfRecvCB;
-
- /**< Receive callback*/
- void *pRecvContext;
-
-} phFriNfc_Llcp_t;
-
-/*========== UNIONS ===========*/
-
-
-/*========== FUNCTIONS ===========*/
-
-/*!
- * \brief TODO
- */
-NFCSTATUS phFriNfc_Llcp_EncodeLinkParams( phNfc_sData_t *psRawBuffer,
- phFriNfc_Llcp_sLinkParameters_t *psLinkParams,
- uint8_t nVersion );
-
-
-/*!
- * \brief TODO
- */
-NFCSTATUS phFriNfc_Llcp_Reset( phFriNfc_Llcp_t *Llcp,
- void *LowerDevice,
- phFriNfc_Llcp_sLinkParameters_t *psLinkParams,
- void *pRxBuffer,
- uint16_t nRxBufferLength,
- void *pTxBuffer,
- uint16_t nTxBufferLength,
- phFriNfc_Llcp_LinkStatus_CB_t pfLink_CB,
- void *pContext );
-
-/*!
- * \brief TODO
- */
-NFCSTATUS phFriNfc_Llcp_ChkLlcp( phFriNfc_Llcp_t *Llcp,
- phHal_sRemoteDevInformation_t *psRemoteDevInfo,
- phFriNfc_Llcp_Check_CB_t pfCheck_CB,
- void *pContext );
-
-/*!
- * \brief TODO
- */
-NFCSTATUS phFriNfc_Llcp_Activate( phFriNfc_Llcp_t *Llcp );
-
-/*!
- * \brief TODO
- */
-NFCSTATUS phFriNfc_Llcp_Deactivate( phFriNfc_Llcp_t *Llcp );
-
-/*!
- * \brief TODO
- */
-NFCSTATUS phFriNfc_Llcp_GetLocalInfo( phFriNfc_Llcp_t *Llcp,
- phFriNfc_Llcp_sLinkParameters_t *pParams );
-
-/*!
- * \brief TODO
- */
-NFCSTATUS phFriNfc_Llcp_GetRemoteInfo( phFriNfc_Llcp_t *Llcp,
- phFriNfc_Llcp_sLinkParameters_t *pParams );
-
-/*!
- * \brief TODO
- */
-NFCSTATUS phFriNfc_Llcp_Send( phFriNfc_Llcp_t *Llcp,
- phFriNfc_Llcp_sPacketHeader_t *psHeader,
- phFriNfc_Llcp_sPacketSequence_t *psSequence,
- phNfc_sData_t *psInfo,
- phFriNfc_Llcp_Send_CB_t pfSend_CB,
- void *pContext );
-
-/*!
- * \brief TODO
- */
-NFCSTATUS phFriNfc_Llcp_Recv( phFriNfc_Llcp_t *Llcp,
- phFriNfc_Llcp_Recv_CB_t pfRecv_CB,
- void *pContext );
-
-
-#endif /* PHFRINFC_LLCP_H */
diff --git a/libnfc-nxp/phFriNfc_LlcpMac.c b/libnfc-nxp/phFriNfc_LlcpMac.c
deleted file mode 100644
index e68f5db..0000000
--- a/libnfc-nxp/phFriNfc_LlcpMac.c
+++ /dev/null
@@ -1,184 +0,0 @@
-/*
- * Copyright (C) 2010 NXP Semiconductors
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-/**
- * \file phFriNfc_LlcpMac.c
- * \brief NFC LLCP MAC Mappings For Different RF Technologies.
- *
- * Project: NFC-FRI
- *
- */
-
-
-/*include files*/
-#include
-#include
-#include
-#include
-#include
-
-NFCSTATUS phFriNfc_LlcpMac_Reset (phFriNfc_LlcpMac_t *LlcpMac,
- void *LowerDevice,
- phFriNfc_LlcpMac_LinkStatus_CB_t LinkStatus_Cb,
- void *pContext)
-{
- NFCSTATUS status = NFCSTATUS_SUCCESS;
- /* Store the Linkstatus callback function of the upper layer */
- LlcpMac->LinkStatus_Cb = LinkStatus_Cb;
-
- /* Store a pointer to the upper layer context */
- LlcpMac->LinkStatus_Context = pContext;
-
- /* Set the LinkStatus variable to the default state */
- LlcpMac->LinkState = phFriNfc_LlcpMac_eLinkDefault;
-
- /* Store a pointer to the lower layer */
- LlcpMac->LowerDevice = LowerDevice;
-
- LlcpMac->psRemoteDevInfo = NULL;
- LlcpMac->PeerRemoteDevType = 0;
- LlcpMac->MacType = 0;
- LlcpMac->MacReceive_Cb = NULL;
- LlcpMac->MacSend_Cb = NULL;
- LlcpMac->psSendBuffer = NULL;
- LlcpMac->RecvPending = 0;
- LlcpMac->SendPending = 0;
-
- return status;
-}
-
-NFCSTATUS phFriNfc_LlcpMac_ChkLlcp (phFriNfc_LlcpMac_t *LlcpMac,
- phHal_sRemoteDevInformation_t *psRemoteDevInfo,
- phFriNfc_LlcpMac_Chk_CB_t ChkLlcpMac_Cb,
- void *pContext)
-{
- NFCSTATUS status = NFCSTATUS_SUCCESS;
- if (NULL == LlcpMac || NULL == psRemoteDevInfo)
- {
- status = PHNFCSTVAL(CID_FRI_NFC_LLCP_MAC, NFCSTATUS_INVALID_PARAMETER);
- }
- else
- {
- /* Store the Remote Device info received from Device Discovery */
- LlcpMac->psRemoteDevInfo = psRemoteDevInfo;
-
- if(LlcpMac->psRemoteDevInfo->RemDevType == phHal_eNfcIP1_Initiator)
- {
- /* Set the PeerRemoteDevType variable to the Target type */
- LlcpMac->PeerRemoteDevType = phFriNfc_LlcpMac_ePeerTypeTarget;
- }
- else if(LlcpMac->psRemoteDevInfo->RemDevType == phHal_eNfcIP1_Target)
- {
- /* Set the PeerRemoteDevType variable to the Initiator type */
- LlcpMac->PeerRemoteDevType = phFriNfc_LlcpMac_ePeerTypeInitiator;
- }
-
- switch(LlcpMac->psRemoteDevInfo->RemDevType)
- {
- case phHal_eNfcIP1_Initiator:
- case phHal_eNfcIP1_Target:
- {
- /* Set the MAC mapping type detected */
- LlcpMac->MacType = phFriNfc_LlcpMac_eTypeNfcip;
-
- /* Register the lower layer to the MAC mapping component */
- status = phFriNfc_LlcpMac_Nfcip_Register (LlcpMac);
- if(status == NFCSTATUS_SUCCESS)
- {
- status = LlcpMac->LlcpMacInterface.chk(LlcpMac,ChkLlcpMac_Cb,pContext);
- }
- else
- {
- status = PHNFCSTVAL(CID_FRI_NFC_LLCP_MAC, NFCSTATUS_FAILED);
- }
- }break;
- default:
- {
- status = PHNFCSTVAL(CID_FRI_NFC_LLCP_MAC, NFCSTATUS_INVALID_DEVICE);
- }break;
- }
- }
-
- return status;
-}
-
-NFCSTATUS phFriNfc_LlcpMac_Activate (phFriNfc_LlcpMac_t *LlcpMac)
-{
- NFCSTATUS status = NFCSTATUS_SUCCESS;
-
- if(LlcpMac->LlcpMacInterface.activate == NULL)
- {
- status = PHNFCSTVAL(CID_FRI_NFC_LLCP_MAC, NFCSTATUS_INVALID_PARAMETER);
- }
- else
- {
- status = LlcpMac->LlcpMacInterface.activate(LlcpMac);
- }
- return status;
-}
-
-NFCSTATUS phFriNfc_LlcpMac_Deactivate (phFriNfc_LlcpMac_t *LlcpMac)
-{
- NFCSTATUS status = NFCSTATUS_SUCCESS;
- if(LlcpMac->LlcpMacInterface.deactivate == NULL)
- {
- status = PHNFCSTVAL(CID_FRI_NFC_LLCP_MAC, NFCSTATUS_INVALID_PARAMETER);
- }
- else
- {
- status = LlcpMac->LlcpMacInterface.deactivate(LlcpMac);
- }
- return status;
-}
-
-NFCSTATUS phFriNfc_LlcpMac_Send (phFriNfc_LlcpMac_t *LlcpMac,
- phNfc_sData_t *psData,
- phFriNfc_LlcpMac_Send_CB_t LlcpMacSend_Cb,
- void *pContext)
-{
- NFCSTATUS status = NFCSTATUS_SUCCESS;
-
- if(NULL== LlcpMac->LlcpMacInterface.send || NULL==psData || NULL==LlcpMacSend_Cb || NULL==pContext)
- {
- status = PHNFCSTVAL(CID_FRI_NFC_LLCP_MAC, NFCSTATUS_INVALID_PARAMETER);
- }
- else
- {
- status = LlcpMac->LlcpMacInterface.send(LlcpMac,psData,LlcpMacSend_Cb,pContext);
- }
- return status;
-}
-
-NFCSTATUS phFriNfc_LlcpMac_Receive (phFriNfc_LlcpMac_t *LlcpMac,
- phNfc_sData_t *psData,
- phFriNfc_LlcpMac_Reveive_CB_t ReceiveLlcpMac_Cb,
- void *pContext)
-{
- NFCSTATUS status = NFCSTATUS_SUCCESS;
-
- if(LlcpMac->LlcpMacInterface.receive == NULL || NULL==psData || NULL==ReceiveLlcpMac_Cb || NULL==pContext)
- {
- status = PHNFCSTVAL(CID_FRI_NFC_LLCP_MAC, NFCSTATUS_INVALID_PARAMETER);
- }
- else
- {
- status = LlcpMac->LlcpMacInterface.receive(LlcpMac,psData,ReceiveLlcpMac_Cb,pContext);
- }
- return status;
-
-}
-
-
diff --git a/libnfc-nxp/phFriNfc_LlcpMac.h b/libnfc-nxp/phFriNfc_LlcpMac.h
deleted file mode 100644
index 8cd4373..0000000
--- a/libnfc-nxp/phFriNfc_LlcpMac.h
+++ /dev/null
@@ -1,246 +0,0 @@
-/*
- * Copyright (C) 2010 NXP Semiconductors
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-
-/**
- * \file phFriNfc_LlcpMac.h
- * \brief NFC LLCP MAC Mappings For Different RF Technologies.
- *
- * Project: NFC-FRI
- *
- */
-
-#ifndef PHFRINFC_LLCPMAC_H
-#define PHFRINFC_LLCPMAC_H
-
-
-/*include files*/
-#include
-#include
-#include
-#include
-
-#include
-
-/**
- * \name LLCP MAC Mapping
- *
- * File: \ref phFriNfc_LlcpMac.h
- *
- */
-
-
-/** \defgroup grp_fri_nfc_llcp_mac LLCP MAC Mapping Component
- *
- * This component implements the different MAC mapping for a Logical Link Control Protocol communication,
- * as defined by the NFC Forum LLCP specifications.\n
- * The MAC component handles the mapping for the different technologies supported by LLCP
- *..This component provides an API to the upper layer with the following features:\n\n
- * - Reset the MAC mapping component
- * - \ref phFriNfc_LlcpMac_ChkLlcp
- * .
- * - Check the LLCP Compliancy
- * - \ref phFriNfc_LlcpMac_ChkLlcp
- * .
- * - Activate the LLCP link
- * - \ref phFriNfc_LlcpMac_Activate
- * .
- * - Deactivate the LLCP link
- * - \ref phFriNfc_LlcpMac_Deactivate
- * .
- * - Register the MAC component Interface with a specific technologie (NFCIP/ISO14443)
- * - \ref phFriNfc_LlcpMac_Register
- * .
- * - Send packets through the LLCP link
- * - \ref phFriNfc_LlcpMac_Send
- * .
- * - Receive packets through the LLCP link
- * - \ref phFriNfc_LlcpMac_Receive
- *
- */
-
-/**
- * \ingroup grp_fri_nfc_llcp_mac
- * \brief Declaration of a MAC type
- */
-struct phFriNfc_LlcpMac;
-typedef struct phFriNfc_LlcpMac phFriNfc_LlcpMac_t;
-
-/**
- * \ingroup grp_fri_nfc_llcp_mac
- *
- */
-/*========== ENUMERATES ===========*/
-
-/* Enum reperesents the different MAC mapping*/
-typedef enum phFriNfc_LlcpMac_eType
-{
- phFriNfc_LlcpMac_eTypeNfcip,
- phFriNfc_LlcpMac_eTypeIso14443
-}phFriNfc_LlcpMac_eType_t;
-
-/* Enum reperesents the different Peer type for a LLCP communication*/
-typedef enum phFriNfc_LlcpMac_ePeerType
-{
- phFriNfc_LlcpMac_ePeerTypeInitiator,
- phFriNfc_LlcpMac_ePeerTypeTarget
-}phFriNfc_LlcpMac_ePeerType_t;
-
-
-
-
-
-
-/*========== CALLBACKS ===========*/
-
-typedef void (*phFriNfc_LlcpMac_Chk_CB_t) (void *pContext,
- NFCSTATUS status);
-
-typedef void (*phFriNfc_LlcpMac_LinkStatus_CB_t) (void *pContext,
- phFriNfc_LlcpMac_eLinkStatus_t eLinkStatus,
- phNfc_sData_t *psData,
- phFriNfc_LlcpMac_ePeerType_t PeerRemoteDevType);
-
-typedef void (*phFriNfc_LlcpMac_Send_CB_t) (void *pContext,
- NFCSTATUS status);
-
-
-typedef void (*phFriNfc_LlcpMac_Reveive_CB_t) (void *pContext,
- NFCSTATUS status,
- phNfc_sData_t *psData);
-
-
-/*========== FUNCTIONS TYPES ===========*/
-
-typedef NFCSTATUS (*pphFriNfcLlpcMac_Chk_t) ( phFriNfc_LlcpMac_t *LlcpMac,
- phFriNfc_LlcpMac_Chk_CB_t ChkLlcpMac_Cb,
- void *pContext);
-
-typedef NFCSTATUS (*pphFriNfcLlpcMac_Activate_t) (phFriNfc_LlcpMac_t *LlcpMac);
-
-typedef NFCSTATUS (*pphFriNfcLlpcMac_Deactivate_t) (phFriNfc_LlcpMac_t *LlcpMac);
-
-typedef NFCSTATUS (*pphFriNfcLlpcMac_Send_t) (phFriNfc_LlcpMac_t *LlcpMac,
- phNfc_sData_t *psData,
- phFriNfc_LlcpMac_Send_CB_t LlcpMacSend_Cb,
- void *pContext);
-
-typedef NFCSTATUS (*pphFriNfcLlpcMac_Receive_t) (phFriNfc_LlcpMac_t *LlcpMac,
- phNfc_sData_t *psData,
- phFriNfc_LlcpMac_Reveive_CB_t LlcpMacReceive_Cb,
- void *pContext);
-
-/*========== STRUCTURES ===========*/
-
-/**
- * \ingroup grp_fri_nfc_llcp_mac
- * \brief Generic Interface structure with the Lower Layer
- */
-typedef struct phFriNfc_LlcpMac_Interface
-{
- pphFriNfcLlpcMac_Chk_t chk;
- pphFriNfcLlpcMac_Activate_t activate;
- pphFriNfcLlpcMac_Deactivate_t deactivate;
- pphFriNfcLlpcMac_Send_t send;
- pphFriNfcLlpcMac_Receive_t receive;
-} phFriNfc_LlcpMac_Interface_t;
-
-/**
- * \ingroup grp_fri_nfc_llcp_mac
- * \brief Definition of the MAC type
- */
-struct phFriNfc_LlcpMac
-{
- phFriNfc_LlcpMac_eLinkStatus_t LinkState;
- phHal_sRemoteDevInformation_t *psRemoteDevInfo;
- phFriNfc_LlcpMac_LinkStatus_CB_t LinkStatus_Cb;
- void *LinkStatus_Context;
- phFriNfc_LlcpMac_Interface_t LlcpMacInterface;
- phFriNfc_LlcpMac_ePeerType_t PeerRemoteDevType;
- phFriNfc_LlcpMac_eType_t MacType;
-
- /**<\internal Holds the completion routine informations of the Map Layer*/
- phFriNfc_CplRt_t MacCompletionInfo;
- void *LowerDevice;
- phFriNfc_LlcpMac_Send_CB_t MacSend_Cb;
- void *MacSend_Context;
- phFriNfc_LlcpMac_Reveive_CB_t MacReceive_Cb;
- void *MacReceive_Context;
- phNfc_sData_t *psReceiveBuffer;
- phNfc_sData_t *psSendBuffer;
- phNfc_sData_t sConfigParam;
- uint8_t RecvPending;
- uint8_t SendPending;
- uint8_t RecvStatus;
- phHal_uCmdList_t Cmd;
- phHal_sDepAdditionalInfo_t psDepAdditionalInfo;
-} ;
-
-
-/*
-################################################################################
-********************** MAC Interface Function Prototype ***********************
-################################################################################
-*/
-
-/**
- * \ingroup grp_fri_nfc_llcp_mac
- * \brief
- */
-NFCSTATUS phFriNfc_LlcpMac_Reset (phFriNfc_LlcpMac_t *LlcpMac,
- void *LowerDevice,
- phFriNfc_LlcpMac_LinkStatus_CB_t LinkStatus_Cb,
- void *pContext);
-/**
- * \ingroup grp_fri_nfc_llcp_mac
- * \brief
- */
-NFCSTATUS phFriNfc_LlcpMac_ChkLlcp (phFriNfc_LlcpMac_t *LlcpMac,
- phHal_sRemoteDevInformation_t *psRemoteDevInfo,
- phFriNfc_LlcpMac_Chk_CB_t ChkLlcpMac_Cb,
- void *pContext);
-
-/**
- * \ingroup grp_fri_nfc_llcp_mac
- * \brief
- */
-NFCSTATUS phFriNfc_LlcpMac_Activate (phFriNfc_LlcpMac_t *LlcpMac);
-
-/**
- * \ingroup grp_fri_nfc_llcp_mac
- * \brief
- */
-NFCSTATUS phFriNfc_LlcpMac_Deactivate (phFriNfc_LlcpMac_t *LlcpMac);
-
-/**
- * \ingroup grp_fri_nfc_llcp_mac
- * \brief
- */
-NFCSTATUS phFriNfc_LlcpMac_Send (phFriNfc_LlcpMac_t *LlcpMac,
- phNfc_sData_t *psData,
- phFriNfc_LlcpMac_Send_CB_t LlcpMacSend_Cb,
- void *pContext);
-
-/**
- * \ingroup grp_fri_nfc_llcp_mac
- * \brief
- */
-NFCSTATUS phFriNfc_LlcpMac_Receive (phFriNfc_LlcpMac_t *LlcpMac,
- phNfc_sData_t *psData,
- phFriNfc_LlcpMac_Reveive_CB_t ReceiveLlcpMac_Cb,
- void *pContext);
-
-#endif /* PHFRINFC_LLCPMAC_H */
diff --git a/libnfc-nxp/phFriNfc_LlcpMacNfcip.c b/libnfc-nxp/phFriNfc_LlcpMacNfcip.c
deleted file mode 100644
index 611571a..0000000
--- a/libnfc-nxp/phFriNfc_LlcpMacNfcip.c
+++ /dev/null
@@ -1,455 +0,0 @@
-/*
- * Copyright (C) 2010 NXP Semiconductors
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-
-/**
- * \file phFriNfc_LlcpMacNfcip.c
- * \brief NFC LLCP MAC Mappings For Different RF Technologies.
- *
- * Project: NFC-FRI
- *
- */
-
-
-/*include files*/
-#include
-#include
-#include
-#include
-#include
-#include
-
-static NFCSTATUS phFriNfc_LlcpMac_Nfcip_Send(phFriNfc_LlcpMac_t *LlcpMac,
- phNfc_sData_t *psData,
- phFriNfc_LlcpMac_Send_CB_t LlcpMacSend_Cb,
- void *pContext);
-
-
-static void phFriNfc_LlcpMac_Nfcip_TriggerRecvCb(phFriNfc_LlcpMac_t *LlcpMac,
- NFCSTATUS status)
-{
- phFriNfc_LlcpMac_Reveive_CB_t pfReceiveCB;
- void *pReceiveContext;
-
- if (LlcpMac->MacReceive_Cb != NULL)
- {
- /* Save callback params */
- pfReceiveCB = LlcpMac->MacReceive_Cb;
- pReceiveContext = LlcpMac->MacReceive_Context;
-
- /* Reset the pointer to the Receive Callback and Context*/
- LlcpMac->MacReceive_Cb = NULL;
- LlcpMac->MacReceive_Context = NULL;
-
- /* Call the receive callback */
- pfReceiveCB(pReceiveContext, status, LlcpMac->psReceiveBuffer);
- }
-}
-
-static void phFriNfc_LlcpMac_Nfcip_TriggerSendCb(phFriNfc_LlcpMac_t *LlcpMac,
- NFCSTATUS status)
-{
- phFriNfc_LlcpMac_Send_CB_t pfSendCB;
- void *pSendContext;
-
- if (LlcpMac->MacSend_Cb != NULL)
- {
- /* Save context in local variables */
- pfSendCB = LlcpMac->MacSend_Cb;
- pSendContext = LlcpMac->MacSend_Context;
-
- /* Reset the pointer to the Send Callback */
- LlcpMac->MacSend_Cb = NULL;
- LlcpMac->MacSend_Context = NULL;
-
- /* Call Send callback */
- pfSendCB(pSendContext, status);
- }
-}
-
-static NFCSTATUS phFriNfc_LlcpMac_Nfcip_Chk(phFriNfc_LlcpMac_t *LlcpMac,
- phFriNfc_LlcpMac_Chk_CB_t ChkLlcpMac_Cb,
- void *pContext)
-{
- NFCSTATUS status = NFCSTATUS_SUCCESS;
- uint8_t Llcp_Magic_Number[] = {0x46,0x66,0x6D};
-
- if(NULL == LlcpMac || NULL == ChkLlcpMac_Cb || NULL == pContext)
- {
- status = PHNFCSTVAL(CID_FRI_NFC_LLCP_MAC, NFCSTATUS_INVALID_PARAMETER);
- }
- else
- {
- status = (NFCSTATUS)memcmp(Llcp_Magic_Number,LlcpMac->psRemoteDevInfo->RemoteDevInfo.NfcIP_Info.ATRInfo,3);
- if(!status)
- {
- LlcpMac->sConfigParam.buffer = &LlcpMac->psRemoteDevInfo->RemoteDevInfo.NfcIP_Info.ATRInfo[3] ;
- LlcpMac->sConfigParam.length = (LlcpMac->psRemoteDevInfo->RemoteDevInfo.NfcIP_Info.ATRInfo_Length - 3);
- status = NFCSTATUS_SUCCESS;
- }
- else
- {
- status = PHNFCSTVAL(CID_FRI_NFC_LLCP_MAC, NFCSTATUS_FAILED);
- }
- ChkLlcpMac_Cb(pContext,status);
- }
-
- return status;
-}
-
-static NFCSTATUS phFriNfc_LlcpMac_Nfcip_Activate (phFriNfc_LlcpMac_t *LlcpMac)
-{
- NFCSTATUS status = NFCSTATUS_SUCCESS;
-
- if(LlcpMac == NULL)
- {
- status = PHNFCSTVAL(CID_FRI_NFC_LLCP_MAC, NFCSTATUS_INVALID_PARAMETER);
- }
- else
- {
- LlcpMac->LinkState = phFriNfc_LlcpMac_eLinkActivated;
- LlcpMac->LinkStatus_Cb(LlcpMac->LinkStatus_Context,
- LlcpMac->LinkState,
- &LlcpMac->sConfigParam,
- LlcpMac->PeerRemoteDevType);
- }
-
- return status;
-}
-
-static NFCSTATUS phFriNfc_LlcpMac_Nfcip_Deactivate (phFriNfc_LlcpMac_t *LlcpMac)
-{
- NFCSTATUS status = NFCSTATUS_SUCCESS;
-
- if(NULL == LlcpMac)
- {
- status = PHNFCSTVAL(CID_FRI_NFC_LLCP_MAC, NFCSTATUS_INVALID_PARAMETER);
- }
- else
- {
- /* Set the flag of LinkStatus to deactivate */
- LlcpMac->LinkState = phFriNfc_LlcpMac_eLinkDeactivated;
-
- if (LlcpMac->SendPending)
- {
- /* Reset Flag */
- LlcpMac->SendPending = FALSE;
- phFriNfc_LlcpMac_Nfcip_TriggerSendCb(LlcpMac, NFCSTATUS_FAILED);
- }
-
- if (LlcpMac->RecvPending)
- {
- /* Reset Flag */
- LlcpMac->RecvPending = FALSE;
- phFriNfc_LlcpMac_Nfcip_TriggerRecvCb(LlcpMac, NFCSTATUS_FAILED);
- }
-
- LlcpMac->LinkStatus_Cb(LlcpMac->LinkStatus_Context,
- LlcpMac->LinkState,
- NULL,
- LlcpMac->PeerRemoteDevType);
- }
-
- return status;
-}
-
-static void phFriNfc_LlcpMac_Nfcip_Send_Cb(void *pContext,
- NFCSTATUS Status)
-{
- phFriNfc_LlcpMac_t *LlcpMac = (phFriNfc_LlcpMac_t *)pContext;
-
-#ifdef LLCP_CHANGES
- if(gpphLibContext->LibNfcState.next_state
- == eLibNfcHalStateShutdown)
- {
- phLibNfc_Pending_Shutdown();
- Status = NFCSTATUS_SHUTDOWN;
- }
-#endif /* #ifdef LLCP_CHANGES */
-
- /* Reset Send and Receive Flag */
- LlcpMac->SendPending = FALSE;
- LlcpMac->RecvPending = FALSE;
-
- phFriNfc_LlcpMac_Nfcip_TriggerSendCb(LlcpMac, Status);
-
-}
-
-static void phFriNfc_LlcpMac_Nfcip_Receive_Cb(void *pContext,
- NFCSTATUS Status)
-{
- phFriNfc_LlcpMac_t *LlcpMac = (phFriNfc_LlcpMac_t *)pContext;
-#ifdef LLCP_CHANGES
-
- phFriNfc_LlcpMac_Send_CB_t pfSendCB;
- void *pSendContext;
-
-
- if(gpphLibContext->LibNfcState.next_state
- == eLibNfcHalStateShutdown)
- {
- phLibNfc_Pending_Shutdown();
- Status = NFCSTATUS_SHUTDOWN;
- }
-
- if (NFCSTATUS_SHUTDOWN == Status)
- {
- /* Save context in local variables */
- pfSendCB = LlcpMac->MacSend_Cb;
- pSendContext = LlcpMac->MacSend_Context;
-
- /* Reset the pointer to the Send Callback */
- LlcpMac->MacSend_Cb = NULL;
- LlcpMac->MacSend_Context = NULL;
-
- /* Reset Send and Receive Flag */
- LlcpMac->SendPending = FALSE;
- LlcpMac->RecvPending = FALSE;
- }
-
-#endif /* #ifdef LLCP_CHANGES */
-
- phFriNfc_LlcpMac_Nfcip_TriggerRecvCb(LlcpMac, Status);
-
-#ifdef LLCP_CHANGES
-
- if (NFCSTATUS_SHUTDOWN == Status)
- {
- if ((LlcpMac->SendPending) && (NULL != pfSendCB))
- {
- pfSendCB(pSendContext, Status);
- }
- }
- else
-
-#endif /* #ifdef LLCP_CHANGES */
- {
- /* Test if a send is pending */
- if(LlcpMac->SendPending)
- {
- Status = phFriNfc_LlcpMac_Nfcip_Send(LlcpMac,LlcpMac->psSendBuffer,LlcpMac->MacSend_Cb,LlcpMac->MacSend_Context);
- }
-}
-}
-
-static void phFriNfc_LlcpMac_Nfcip_Transceive_Cb(void *pContext,
- NFCSTATUS Status)
-{
- phFriNfc_LlcpMac_t *LlcpMac = (phFriNfc_LlcpMac_t *)pContext;
-
-#ifdef LLCP_CHANGES
- if(gpphLibContext->LibNfcState.next_state
- == eLibNfcHalStateShutdown)
- {
- phLibNfc_Pending_Shutdown();
- Status = NFCSTATUS_SHUTDOWN;
- }
-#endif /* #ifdef LLCP_CHANGES */
-
- /* Reset Send and Receive Flag */
- LlcpMac->SendPending = FALSE;
- LlcpMac->RecvPending = FALSE;
-
- /* Call the callbacks */
- phFriNfc_LlcpMac_Nfcip_TriggerSendCb(LlcpMac, Status);
- phFriNfc_LlcpMac_Nfcip_TriggerRecvCb(LlcpMac, Status);
-}
-
-static NFCSTATUS phFriNfc_LlcpMac_Nfcip_Send(phFriNfc_LlcpMac_t *LlcpMac,
- phNfc_sData_t *psData,
- phFriNfc_LlcpMac_Send_CB_t LlcpMacSend_Cb,
- void *pContext)
-{
- NFCSTATUS status = NFCSTATUS_SUCCESS;
-
- if(NULL == LlcpMac || NULL == psData || NULL == LlcpMacSend_Cb || NULL == pContext)
- {
- status = PHNFCSTVAL(CID_FRI_NFC_LLCP_MAC, NFCSTATUS_INVALID_PARAMETER);
- }
- else if(LlcpMac->MacSend_Cb != NULL && LlcpMac->PeerRemoteDevType == phFriNfc_LlcpMac_ePeerTypeInitiator)
- {
- /*Previous callback is pending */
- status = NFCSTATUS_REJECTED;
- }
- else
- {
- /* Save the LlcpMacSend_Cb */
- LlcpMac->MacSend_Cb = LlcpMacSend_Cb;
- LlcpMac->MacSend_Context = pContext;
-
- switch(LlcpMac->PeerRemoteDevType)
- {
- case phFriNfc_LlcpMac_ePeerTypeInitiator:
- {
- if(LlcpMac->RecvPending)
- {
- /*set the completion routines for the LLCP Transceive function*/
- LlcpMac->MacCompletionInfo.CompletionRoutine = phFriNfc_LlcpMac_Nfcip_Transceive_Cb;
- LlcpMac->MacCompletionInfo.Context = LlcpMac;
-
- /* set the command type*/
- LlcpMac->Cmd.NfcIP1Cmd = phHal_eNfcIP1_Raw;
-
- /* set the Additional Info*/
- LlcpMac->psDepAdditionalInfo.DepFlags.MetaChaining = 0;
- LlcpMac->psDepAdditionalInfo.DepFlags.NADPresent = 0;
- LlcpMac->SendPending = TRUE;
-
- status = phFriNfc_OvrHal_Transceive(LlcpMac->LowerDevice,
- &LlcpMac->MacCompletionInfo,
- LlcpMac->psRemoteDevInfo,
- LlcpMac->Cmd,
- &LlcpMac->psDepAdditionalInfo,
- psData->buffer,
- (uint16_t)psData->length,
- LlcpMac->psReceiveBuffer->buffer,
- (uint16_t*)&LlcpMac->psReceiveBuffer->length);
- }
- else
- {
- LlcpMac->SendPending = TRUE;
- LlcpMac->psSendBuffer = psData;
- return status = NFCSTATUS_PENDING;
- }
- }break;
- case phFriNfc_LlcpMac_ePeerTypeTarget:
- {
- if(!LlcpMac->RecvPending)
- {
- LlcpMac->SendPending = TRUE;
- LlcpMac->psSendBuffer = psData;
- return status = NFCSTATUS_PENDING;
- }
- else
- {
- /*set the completion routines for the LLCP Send function*/
- LlcpMac->MacCompletionInfo.CompletionRoutine = phFriNfc_LlcpMac_Nfcip_Send_Cb;
- LlcpMac->MacCompletionInfo.Context = LlcpMac;
- status = phFriNfc_OvrHal_Send(LlcpMac->LowerDevice,
- &LlcpMac->MacCompletionInfo,
- LlcpMac->psRemoteDevInfo,
- psData->buffer,
- (uint16_t)psData->length);
- }
- }break;
- default:
- {
- status = PHNFCSTVAL(CID_FRI_NFC_LLCP_MAC, NFCSTATUS_INVALID_DEVICE);
- }break;
- }
- }
- return status;
-}
-
-static NFCSTATUS phFriNfc_LlcpMac_Nfcip_Receive(phFriNfc_LlcpMac_t *LlcpMac,
- phNfc_sData_t *psData,
- phFriNfc_LlcpMac_Reveive_CB_t LlcpMacReceive_Cb,
- void *pContext)
-{
- NFCSTATUS status = NFCSTATUS_SUCCESS;
- if(NULL == LlcpMac || NULL==psData || NULL == LlcpMacReceive_Cb || NULL == pContext)
- {
- status = PHNFCSTVAL(CID_FRI_NFC_LLCP_MAC, NFCSTATUS_INVALID_PARAMETER);
- }
- else if(LlcpMac->MacReceive_Cb != NULL)
- {
- /*Previous callback is pending */
- status = NFCSTATUS_REJECTED;
- }
- else
- {
- /* Save the LlcpMacReceive_Cb */
- LlcpMac->MacReceive_Cb = LlcpMacReceive_Cb;
- LlcpMac->MacReceive_Context = pContext;
-
- /* Save the pointer to the receive buffer */
- LlcpMac->psReceiveBuffer= psData;
-
- switch(LlcpMac->PeerRemoteDevType)
- {
- case phFriNfc_LlcpMac_ePeerTypeInitiator:
- {
- if(LlcpMac->SendPending)
- {
- /*set the completion routines for the LLCP Transceive function*/
- LlcpMac->MacCompletionInfo.CompletionRoutine = phFriNfc_LlcpMac_Nfcip_Transceive_Cb;
- LlcpMac->MacCompletionInfo.Context = LlcpMac;
- /* set the command type*/
- LlcpMac->Cmd.NfcIP1Cmd = phHal_eNfcIP1_Raw;
- /* set the Additional Info*/
- LlcpMac->psDepAdditionalInfo.DepFlags.MetaChaining = 0;
- LlcpMac->psDepAdditionalInfo.DepFlags.NADPresent = 0;
- LlcpMac->RecvPending = TRUE;
-
- status = phFriNfc_OvrHal_Transceive(LlcpMac->LowerDevice,
- &LlcpMac->MacCompletionInfo,
- LlcpMac->psRemoteDevInfo,
- LlcpMac->Cmd,
- &LlcpMac->psDepAdditionalInfo,
- LlcpMac->psSendBuffer->buffer,
- (uint16_t)LlcpMac->psSendBuffer->length,
- psData->buffer,
- (uint16_t*)&psData->length);
- }
- else
- {
- LlcpMac->RecvPending = TRUE;
- return status = NFCSTATUS_PENDING;
- }
- }break;
- case phFriNfc_LlcpMac_ePeerTypeTarget:
- {
- /*set the completion routines for the LLCP Receive function*/
- LlcpMac->MacCompletionInfo.CompletionRoutine = phFriNfc_LlcpMac_Nfcip_Receive_Cb;
- /* save the context of LlcpMacNfcip */
- LlcpMac->MacCompletionInfo.Context = LlcpMac;
- LlcpMac->RecvPending = TRUE;
-
- status = phFriNfc_OvrHal_Receive(LlcpMac->LowerDevice,
- &LlcpMac->MacCompletionInfo,
- LlcpMac->psRemoteDevInfo,
- LlcpMac->psReceiveBuffer->buffer,
- (uint16_t*)&LlcpMac->psReceiveBuffer->length);
- }break;
- default:
- {
- status = PHNFCSTVAL(CID_FRI_NFC_LLCP_MAC, NFCSTATUS_INVALID_DEVICE);
- }break;
- }
- }
- return status;
-}
-
-
-NFCSTATUS phFriNfc_LlcpMac_Nfcip_Register (phFriNfc_LlcpMac_t *LlcpMac)
-{
- NFCSTATUS status = NFCSTATUS_SUCCESS;
-
- if(NULL != LlcpMac)
- {
- LlcpMac->LlcpMacInterface.chk = phFriNfc_LlcpMac_Nfcip_Chk;
- LlcpMac->LlcpMacInterface.activate = phFriNfc_LlcpMac_Nfcip_Activate;
- LlcpMac->LlcpMacInterface.deactivate = phFriNfc_LlcpMac_Nfcip_Deactivate;
- LlcpMac->LlcpMacInterface.send = phFriNfc_LlcpMac_Nfcip_Send;
- LlcpMac->LlcpMacInterface.receive = phFriNfc_LlcpMac_Nfcip_Receive;
-
- return NFCSTATUS_SUCCESS;
- }
- else
- {
- return status = PHNFCSTVAL(CID_FRI_NFC_LLCP_MAC, NFCSTATUS_FAILED);
- }
-}
diff --git a/libnfc-nxp/phFriNfc_LlcpMacNfcip.h b/libnfc-nxp/phFriNfc_LlcpMacNfcip.h
deleted file mode 100644
index 945ddc9..0000000
--- a/libnfc-nxp/phFriNfc_LlcpMacNfcip.h
+++ /dev/null
@@ -1,50 +0,0 @@
-/*
- * Copyright (C) 2010 NXP Semiconductors
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-/**
- * \file phFriNfc_LlcpMacNfcip.h
- * \brief NFC LLCP MAC Mapping for NFCIP.
- *
- * Project: NFC-FRI
- *
- */
-
-#ifndef PHFRINFC_LLCPMACNFCIP_H
-#define PHFRINFC_LLCPMACNFCIP_H
-
-
-/*include files*/
-#include
-#include
-#include
-#include
-
-/**
- * \name MAC Mapping for NFCIP
- *
- * File: \ref phFriNfc_LlcpMacNfcip.h
- *
- */
-
-
-/** \defgroup grp_fri_nfc_llcp_macnfcip NFCIP MAC Mapping
- *
- * TODO
- *
- */
-NFCSTATUS phFriNfc_LlcpMac_Nfcip_Register (phFriNfc_LlcpMac_t *LlcpMac);
-
-#endif /* PHFRINFC_LLCPMACNFCIP_H */
diff --git a/libnfc-nxp/phFriNfc_LlcpTransport.c b/libnfc-nxp/phFriNfc_LlcpTransport.c
deleted file mode 100644
index 51f520e..0000000
--- a/libnfc-nxp/phFriNfc_LlcpTransport.c
+++ /dev/null
@@ -1,2293 +0,0 @@
-/*
- * Copyright (C) 2010 NXP Semiconductors
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-/**
- * \file phFriNfc_LlcpTransport.c
- * \brief
- *
- * Project: NFC-FRI
- *
- */
-
-/*include files*/
-#include
-#include
-#include
-#include
-#include
-#include
-#include
-#include
-#include
-
-/* local macros */
-
-/* Check if (a <= x < b) */
-#define IS_BETWEEN(x, a, b) (((x)>=(a)) && ((x)<(b)))
-
-static NFCSTATUS phFriNfc_LlcpTransport_RegisterName(phFriNfc_LlcpTransport_Socket_t* pLlcpSocket,
- uint8_t nSap,
- phNfc_sData_t *psServiceName);
-
-static NFCSTATUS phFriNfc_LlcpTransport_DiscoverServicesEx(phFriNfc_LlcpTransport_t *psTransport);
-
-static void phFriNfc_LlcpTransport_Send_CB(void *pContext,
- NFCSTATUS status);
-
-static NFCSTATUS phFriNfc_LlcpTransport_GetFreeSap(phFriNfc_LlcpTransport_t * psTransport, phNfc_sData_t *psServiceName, uint8_t * pnSap)
-{
- uint8_t i;
- uint8_t sap;
- uint8_t min_sap_range, max_sap_range;
- phFriNfc_LlcpTransport_Socket_t* pSocketTable = psTransport->pSocketTable;
-
- /* Calculate authorized SAP range */
- if ((psServiceName != NULL) && (psServiceName->length > 0))
- {
- /* Make sure that we will return the same SAP if service name was already used in the past */
- for(i=0 ; ipCachedServiceNames[i].sServiceName.length > 0) &&
- (memcmp(psTransport->pCachedServiceNames[i].sServiceName.buffer, psServiceName->buffer, psServiceName->length) == 0))
- {
- /* Service name matched in cached service names list */
- *pnSap = psTransport->pCachedServiceNames[i].nSap;
- return NFCSTATUS_SUCCESS;
- }
- }
-
- /* SDP advertised service */
- min_sap_range = PHFRINFC_LLCP_SAP_SDP_ADVERTISED_FIRST;
- max_sap_range = PHFRINFC_LLCP_SAP_SDP_UNADVERTISED_FIRST;
- }
- else
- {
- /* Non-SDP advertised service */
- min_sap_range = PHFRINFC_LLCP_SAP_SDP_UNADVERTISED_FIRST;
- max_sap_range = PHFRINFC_LLCP_SAP_NUMBER;
- }
-
- /* Try all possible SAPs */
- for(sap=min_sap_range ; sap= phFriNfc_LlcpTransportSocket_eSocketBound) &&
- (pSocketTable[i].socket_sSap == sap))
- {
- /* SAP is already in use */
- break;
- }
- }
-
- if (i >= PHFRINFC_LLCP_NB_SOCKET_MAX)
- {
- /* No socket is using current SAP, proceed with binding */
- *pnSap = sap;
- return NFCSTATUS_SUCCESS;
- }
- }
-
- /* If we reach this point, it means that no SAP is free */
- return NFCSTATUS_INSUFFICIENT_RESOURCES;
-}
-
-static NFCSTATUS phFriNfc_LlcpTransport_EncodeSdreqTlv(phNfc_sData_t *psTlvData,
- uint32_t *pOffset,
- uint8_t nTid,
- phNfc_sData_t *psServiceName)
-{
- NFCSTATUS result;
- uint32_t nTlvOffset = *pOffset;
- uint32_t nTlvStartOffset = nTlvOffset;
-
- /* Encode the TID */
- result = phFriNfc_Llcp_EncodeTLV(psTlvData,
- &nTlvOffset,
- PHFRINFC_LLCP_TLV_TYPE_SDREQ,
- 1,
- &nTid);
- if (result != NFCSTATUS_SUCCESS)
- {
- goto clean_and_return;
- }
-
- /* Encode the service name itself */
- result = phFriNfc_Llcp_AppendTLV(psTlvData,
- nTlvStartOffset,
- &nTlvOffset,
- psServiceName->length,
- psServiceName->buffer);
- if (result != NFCSTATUS_SUCCESS)
- {
- goto clean_and_return;
- }
-
-clean_and_return:
- /* Save offset if no error occured */
- if (result == NFCSTATUS_SUCCESS)
- {
- *pOffset = nTlvOffset;
- }
-
- return result;
-}
-
-static NFCSTATUS phFriNfc_LlcpTransport_EncodeSdresTlv(phNfc_sData_t *psTlvData,
- uint32_t *pOffset,
- uint8_t nTid,
- uint8_t nSap)
-{
- NFCSTATUS result;
- uint32_t nTlvStartOffset = *pOffset;
-
- /* Encode the TID */
- result = phFriNfc_Llcp_EncodeTLV(psTlvData,
- pOffset,
- PHFRINFC_LLCP_TLV_TYPE_SDRES,
- 1,
- &nTid);
- if (result != NFCSTATUS_SUCCESS)
- {
- goto clean_and_return;
- }
-
- /* Encode the service name itself */
- result = phFriNfc_Llcp_AppendTLV(psTlvData,
- nTlvStartOffset,
- pOffset,
- 1,
- &nSap);
- if (result != NFCSTATUS_SUCCESS)
- {
- goto clean_and_return;
- }
-
-clean_and_return:
- /* Restore previous offset if an error occured */
- if (result != NFCSTATUS_SUCCESS)
- {
- *pOffset = nTlvStartOffset;
- }
-
- return result;
-}
-
-static phFriNfc_LlcpTransport_Socket_t* phFriNfc_LlcpTransport_ServiceNameLoockup(phFriNfc_LlcpTransport_t *psTransport,
- phNfc_sData_t *pServiceName)
-{
- uint32_t index;
- uint8_t cacheIndex;
- phFriNfc_Llcp_CachedServiceName_t * pCachedServiceName;
- phFriNfc_LlcpTransport_Socket_t * pSocket;
-
- /* Search a socket with the SN */
- for(index=0;indexpSocketTable[index];
- /* Test if the CO socket is in Listen state or the CL socket is bound
- and if its SN is the good one */
- if((((pSocket->eSocket_Type == phFriNfc_LlcpTransport_eConnectionOriented)
- && (pSocket->eSocket_State == phFriNfc_LlcpTransportSocket_eSocketRegistered))
- || ((pSocket->eSocket_Type == phFriNfc_LlcpTransport_eConnectionLess)
- && (pSocket->eSocket_State == phFriNfc_LlcpTransportSocket_eSocketBound)))
- &&
- (pServiceName->length == pSocket->sServiceName.length)
- && !memcmp(pServiceName->buffer, pSocket->sServiceName.buffer, pServiceName->length))
- {
- /* Add new entry to cached service name/sap if not already in table */
- for(cacheIndex=0;cacheIndexpCachedServiceNames[cacheIndex];
- if (pCachedServiceName->sServiceName.buffer != NULL)
- {
- if ((pCachedServiceName->sServiceName.length == pServiceName->length) &&
- (memcmp(pCachedServiceName->sServiceName.buffer, pServiceName->buffer, pServiceName->length) == 0))
- {
- /* Already registered */
- break;
- }
- }
- else
- {
- /* Reached end of existing entries and not found the service name,
- * => Add the new entry
- */
- pCachedServiceName->nSap = pSocket->socket_sSap;
- pCachedServiceName->sServiceName.buffer = phOsalNfc_GetMemory(pServiceName->length);
- if (pCachedServiceName->sServiceName.buffer == NULL)
- {
- /* Unable to cache this entry, so report this service as not found */
- return NULL;
- }
- memcpy(pCachedServiceName->sServiceName.buffer, pServiceName->buffer, pServiceName->length);
- pCachedServiceName->sServiceName.length = pServiceName->length;
- break;
- }
- }
-
- return pSocket;
- }
- }
-
- return NULL;
-}
-
-
-static NFCSTATUS phFriNfc_LlcpTransport_DiscoveryAnswer(phFriNfc_LlcpTransport_t *psTransport)
-{
- NFCSTATUS result = NFCSTATUS_PENDING;
- phNfc_sData_t sInfoBuffer;
- uint32_t nTlvOffset;
- uint8_t index;
- uint8_t nTid, nSap;
-
- /* Test if a send is pending */
- if(!testAndSetSendPending(psTransport))
- {
- /* Set the header */
- psTransport->sLlcpHeader.dsap = PHFRINFC_LLCP_SAP_SDP;
- psTransport->sLlcpHeader.ptype = PHFRINFC_LLCP_PTYPE_SNL;
- psTransport->sLlcpHeader.ssap = PHFRINFC_LLCP_SAP_SDP;
-
- /* Prepare the info buffer */
- sInfoBuffer.buffer = psTransport->pDiscoveryBuffer;
- sInfoBuffer.length = sizeof(psTransport->pDiscoveryBuffer);
-
- /* Encode as many requests as possible */
- nTlvOffset = 0;
- for(index=0 ; indexnDiscoveryResListSize ; index++)
- {
- /* Get current TID/SAP and try to encode them in SNL frame */
- nTid = psTransport->nDiscoveryResTidList[index];
- nSap = psTransport->nDiscoveryResSapList[index];
- /* Encode response */
- result = phFriNfc_LlcpTransport_EncodeSdresTlv(&sInfoBuffer,
- &nTlvOffset,
- nTid,
- nSap);
- if (result != NFCSTATUS_SUCCESS)
- {
- /* Impossible to fit the entire response */
- /* TODO: support reponse framgentation */
- break;
- }
- }
-
- /* Reset list size to be able to handle a new request */
- psTransport->nDiscoveryResListSize = 0;
-
- /* Update buffer length to match real TLV size */
- sInfoBuffer.length = nTlvOffset;
-
- /* Send SNL frame */
- result = phFriNfc_Llcp_Send(psTransport->pLlcp,
- &psTransport->sLlcpHeader,
- NULL,
- &sInfoBuffer,
- phFriNfc_LlcpTransport_Send_CB,
- psTransport);
- }
- else
- {
- /* Impossible to send now, this function will be called again on next opportunity */
- }
-
- return result;
-}
-
-
-static void Handle_Discovery_IncomingFrame(phFriNfc_LlcpTransport_t *psTransport,
- phNfc_sData_t *psData)
-{
- NFCSTATUS result;
- phNfc_sData_t sValue;
- phNfc_sData_t sResponseData;
- phNfc_sData_t sServiceName;
- uint32_t nInTlvOffset;
- uint8_t nType;
- uint8_t nTid;
- uint8_t nSap;
- pphFriNfc_Cr_t pfSavedCb;
- void *pfSavedContext;
- phFriNfc_LlcpTransport_Socket_t *pSocket;
-
-
- /* Prepare buffer */
- sResponseData.buffer = psTransport->pDiscoveryBuffer;
- sResponseData.length = sizeof(psTransport->pDiscoveryBuffer);
-
- /* Parse all TLVs in frame */
- nInTlvOffset = 0;
- while(nInTlvOffset < psData->length)
- {
- result = phFriNfc_Llcp_DecodeTLV(psData,
- &nInTlvOffset,
- &nType,
- &sValue );
- switch(nType)
- {
- case PHFRINFC_LLCP_TLV_TYPE_SDREQ:
- if (sValue.length < 2)
- {
- /* Erroneous request, ignore */
- break;
- }
- /* Decode TID */
- nTid = sValue.buffer[0];
- /* Decode service name */
- sServiceName.buffer = sValue.buffer + 1;
- sServiceName.length = sValue.length - 1;
-
- /* Handle SDP service name */
- if((sServiceName.length == sizeof(PHFRINFC_LLCP_SERVICENAME_SDP)-1)
- && !memcmp(sServiceName.buffer, PHFRINFC_LLCP_SERVICENAME_SDP, sServiceName.length))
- {
- nSap = PHFRINFC_LLCP_SAP_SDP;
- }
- else
- {
- /* Match service name in socket list */
- pSocket = phFriNfc_LlcpTransport_ServiceNameLoockup(psTransport, &sServiceName);
- if (pSocket != NULL)
- {
- nSap = pSocket->socket_sSap;
- }
- else
- {
- nSap = 0;
- }
- }
-
- /* Encode response */
- if (psTransport->nDiscoveryResListSize < PHFRINFC_LLCP_SNL_RESPONSE_MAX)
- {
- psTransport->nDiscoveryResSapList[psTransport->nDiscoveryResListSize] = nSap;
- psTransport->nDiscoveryResTidList[psTransport->nDiscoveryResListSize] = nTid;
- psTransport->nDiscoveryResListSize++;
- }
- else
- {
- /* Remote peer is sending more than max. allowed requests (max. 256
- different TID values), drop invalid requests to avoid buffer overflow
- */
- }
- break;
-
- case PHFRINFC_LLCP_TLV_TYPE_SDRES:
- if (psTransport->pfDiscover_Cb == NULL)
- {
- /* Ignore response when no requests are pending */
- break;
- }
- if (sValue.length != 2)
- {
- /* Erroneous response, ignore it */
- break;
- }
- /* Decode TID and SAP */
- nTid = sValue.buffer[0];
- if (nTid >= psTransport->nDiscoveryListSize)
- {
- /* Unkown TID, ignore it */
- break;
- }
- nSap = sValue.buffer[1];
- /* Save response */
- psTransport->pnDiscoverySapList[nTid] = nSap;
- /* Update response counter */
- psTransport->nDiscoveryResOffset++;
- break;
-
- default:
- /* Ignored */
- break;
- }
- }
-
- /* If discovery requests have been received, send response */
- if (psTransport->nDiscoveryResListSize > 0)
- {
- phFriNfc_LlcpTransport_DiscoveryAnswer(psTransport);
- }
-
- /* If all discovery responses have been received, trigger callback (if any) */
- if ((psTransport->pfDiscover_Cb != NULL) &&
- (psTransport->nDiscoveryResOffset >= psTransport->nDiscoveryListSize))
- {
- pfSavedCb = psTransport->pfDiscover_Cb;
- pfSavedContext = psTransport->pDiscoverContext;
-
- psTransport->pfDiscover_Cb = NULL;
- psTransport->pDiscoverContext = NULL;
-
- pfSavedCb(pfSavedContext, NFCSTATUS_SUCCESS);
- }
-}
-
-
-/* TODO: comment function Transport recv CB */
-static void phFriNfc_LlcpTransport__Recv_CB(void *pContext,
- phNfc_sData_t *psData,
- NFCSTATUS status)
-{
- phFriNfc_Llcp_sPacketHeader_t sLlcpLocalHeader;
- uint8_t dsap;
- uint8_t ptype;
- uint8_t ssap;
-
- phFriNfc_LlcpTransport_t* pLlcpTransport = (phFriNfc_LlcpTransport_t*)pContext;
-
- if(status != NFCSTATUS_SUCCESS)
- {
- pLlcpTransport->LinkStatusError = TRUE;
- }
- else
- {
- phFriNfc_Llcp_Buffer2Header( psData->buffer,0x00, &sLlcpLocalHeader);
-
- dsap = (uint8_t)sLlcpLocalHeader.dsap;
- ptype = (uint8_t)sLlcpLocalHeader.ptype;
- ssap = (uint8_t)sLlcpLocalHeader.ssap;
-
- /* Update the length value (without the header length) */
- psData->length = psData->length - PHFRINFC_LLCP_PACKET_HEADER_SIZE;
-
- /* Update the buffer pointer */
- psData->buffer = psData->buffer + PHFRINFC_LLCP_PACKET_HEADER_SIZE;
-
- switch(ptype)
- {
- /* Connectionless */
- case PHFRINFC_LLCP_PTYPE_UI:
- {
- Handle_Connectionless_IncommingFrame(pLlcpTransport,
- psData,
- dsap,
- ssap);
- }break;
-
- /* Service Discovery Protocol */
- case PHFRINFC_LLCP_PTYPE_SNL:
- {
- if ((ssap == PHFRINFC_LLCP_SAP_SDP) && (dsap == PHFRINFC_LLCP_SAP_SDP))
- {
- Handle_Discovery_IncomingFrame(pLlcpTransport,
- psData);
- }
- else
- {
- /* Ignore frame if source and destination are not the SDP service */
- }
- }break;
-
- /* Connection oriented */
- /* NOTE: forward reserved PTYPE to enable FRMR sending */
- case PHFRINFC_LLCP_PTYPE_CONNECT:
- case PHFRINFC_LLCP_PTYPE_CC:
- case PHFRINFC_LLCP_PTYPE_DISC:
- case PHFRINFC_LLCP_PTYPE_DM:
- case PHFRINFC_LLCP_PTYPE_I:
- case PHFRINFC_LLCP_PTYPE_RR:
- case PHFRINFC_LLCP_PTYPE_RNR:
- case PHFRINFC_LLCP_PTYPE_FRMR:
- case PHFRINFC_LLCP_PTYPE_RESERVED1:
- case PHFRINFC_LLCP_PTYPE_RESERVED2:
- case PHFRINFC_LLCP_PTYPE_RESERVED3:
- {
- Handle_ConnectionOriented_IncommingFrame(pLlcpTransport,
- psData,
- dsap,
- ptype,
- ssap);
- }break;
- default:
- {
-
- }break;
- }
-
- /*Restart the Receive Loop */
- status = phFriNfc_Llcp_Recv(pLlcpTransport->pLlcp,
- phFriNfc_LlcpTransport__Recv_CB,
- pLlcpTransport);
- }
-}
-
-bool_t testAndSetSendPending(phFriNfc_LlcpTransport_t* transport) {
- bool_t currentValue;
- pthread_mutex_lock(&transport->mutex);
- currentValue = transport->bSendPending;
- transport->bSendPending = TRUE;
- pthread_mutex_unlock(&transport->mutex);
- return currentValue;
-}
-
-void clearSendPending(phFriNfc_LlcpTransport_t* transport) {
- pthread_mutex_lock(&transport->mutex);
- transport->bSendPending = FALSE;
- pthread_mutex_unlock(&transport->mutex);
-}
-
-/* TODO: comment function Transport recv CB */
-static void phFriNfc_LlcpTransport_Send_CB(void *pContext,
- NFCSTATUS status)
-{
- phFriNfc_LlcpTransport_t *psTransport = (phFriNfc_LlcpTransport_t*)pContext;
- NFCSTATUS result = NFCSTATUS_FAILED;
- phNfc_sData_t sFrmrBuffer;
- phFriNfc_Llcp_LinkSend_CB_t pfSavedCb;
- void *pSavedContext;
- phFriNfc_LlcpTransport_Socket_t *pCurrentSocket = NULL;
- uint8_t index;
-
- // Store callbacks and socket index, so they can safely be
- // overwritten by any code in the callback itself.
- pfSavedCb = psTransport->pfLinkSendCb;
- pSavedContext = psTransport->pLinkSendContext;
- psTransport->pfLinkSendCb = NULL;
- psTransport->pLinkSendContext = NULL;
- index = psTransport->socketIndex;
-
- /* 1 - Reset the FLAG send pending*/
- clearSendPending(psTransport);
-
- /* 2 - Handle pending error responses */
- if(psTransport->bFrmrPending)
- {
- if (!testAndSetSendPending(psTransport)) {
- /* Reset FRMR pending */
- psTransport->bFrmrPending = FALSE;
-
- /* Send Frmr */
- sFrmrBuffer.buffer = psTransport->FrmrInfoBuffer;
- sFrmrBuffer.length = 0x04; /* Size of FRMR Information field */
-
- result = phFriNfc_Llcp_Send(psTransport->pLlcp,
- &psTransport->sLlcpHeader,
- NULL,
- &sFrmrBuffer,
- phFriNfc_LlcpTransport_Send_CB,
- psTransport);
- }
- }
- else if(psTransport->bDmPending)
- {
- /* Reset DM pending */
- psTransport->bDmPending = FALSE;
-
- /* Send DM pending */
- result = phFriNfc_LlcpTransport_SendDisconnectMode(psTransport,
- psTransport->DmInfoBuffer[0],
- psTransport->DmInfoBuffer[1],
- psTransport->DmInfoBuffer[2]);
- }
-
- /* 3 - Call the original callback */
- if (pfSavedCb != NULL)
- {
- (*pfSavedCb)(pSavedContext, index, status);
- }
-
-
- /* 4 - Handle pending send operations */
-
- /* Check for pending discovery requests/responses */
- if (psTransport->nDiscoveryResListSize > 0)
- {
- phFriNfc_LlcpTransport_DiscoveryAnswer(psTransport);
- }
- if ( (psTransport->pfDiscover_Cb != NULL) &&
- (psTransport->nDiscoveryReqOffset < psTransport->nDiscoveryListSize) )
- {
- result = phFriNfc_LlcpTransport_DiscoverServicesEx(psTransport);
- }
-
- /* Init index */
- index = psTransport->socketIndex;
-
- /* Check all sockets for pending operation */
- do
- {
- /* Modulo-increment index */
- index = (index + 1) % PHFRINFC_LLCP_NB_SOCKET_MAX;
-
- pCurrentSocket = &psTransport->pSocketTable[index];
-
- /* Dispatch to the corresponding transport layer */
- if (pCurrentSocket->eSocket_Type == phFriNfc_LlcpTransport_eConnectionOriented)
- {
- result = phFriNfc_LlcpTransport_ConnectionOriented_HandlePendingOperations(pCurrentSocket);
- }
- else if (pCurrentSocket->eSocket_Type == phFriNfc_LlcpTransport_eConnectionLess)
- {
- result = phFriNfc_LlcpTransport_Connectionless_HandlePendingOperations(pCurrentSocket);
- }
-
- if (result != NFCSTATUS_FAILED)
- {
- /* Stop looping if pending operation has been found */
- break;
- }
-
- } while(index != psTransport->socketIndex);
-}
-
-
-/* TODO: comment function Transport reset */
-NFCSTATUS phFriNfc_LlcpTransport_Reset (phFriNfc_LlcpTransport_t *pLlcpTransport,
- phFriNfc_Llcp_t *pLlcp)
-{
- NFCSTATUS status = NFCSTATUS_SUCCESS;
- uint8_t i;
-
- /* Check for NULL pointers */
- if(pLlcpTransport == NULL || pLlcp == NULL)
- {
- status = PHNFCSTVAL(CID_FRI_NFC_LLCP_TRANSPORT, NFCSTATUS_INVALID_PARAMETER);
- }
- else
- {
- /* Reset Transport structure */
- pLlcpTransport->pLlcp = pLlcp;
- pLlcpTransport->LinkStatusError = FALSE;
- pLlcpTransport->bSendPending = FALSE;
- pLlcpTransport->bRecvPending = FALSE;
- pLlcpTransport->bDmPending = FALSE;
- pLlcpTransport->bFrmrPending = FALSE;
- pLlcpTransport->socketIndex = FALSE;
- pLlcpTransport->LinkStatusError = 0;
- pLlcpTransport->pfDiscover_Cb = NULL;
-
- /* Initialize cached service name/sap table */
- memset(pLlcpTransport->pCachedServiceNames, 0x00, sizeof(phFriNfc_Llcp_CachedServiceName_t)*PHFRINFC_LLCP_SDP_ADVERTISED_NB);
-
- /* Reset all the socket info in the table */
- for(i=0;ipSocketTable[i].eSocket_State = phFriNfc_LlcpTransportSocket_eSocketDefault;
- pLlcpTransport->pSocketTable[i].eSocket_Type = phFriNfc_LlcpTransport_eDefaultType;
- pLlcpTransport->pSocketTable[i].index = i;
- pLlcpTransport->pSocketTable[i].pContext = NULL;
- pLlcpTransport->pSocketTable[i].pListenContext = NULL;
- pLlcpTransport->pSocketTable[i].pAcceptContext = NULL;
- pLlcpTransport->pSocketTable[i].pRejectContext = NULL;
- pLlcpTransport->pSocketTable[i].pConnectContext = NULL;
- pLlcpTransport->pSocketTable[i].pDisconnectContext = NULL;
- pLlcpTransport->pSocketTable[i].pSendContext = NULL;
- pLlcpTransport->pSocketTable[i].pRecvContext = NULL;
- pLlcpTransport->pSocketTable[i].pSocketErrCb = NULL;
- pLlcpTransport->pSocketTable[i].bufferLinearLength = 0;
- pLlcpTransport->pSocketTable[i].bufferSendMaxLength = 0;
- pLlcpTransport->pSocketTable[i].bufferRwMaxLength = 0;
- pLlcpTransport->pSocketTable[i].ReceiverBusyCondition = FALSE;
- pLlcpTransport->pSocketTable[i].RemoteBusyConditionInfo = FALSE;
- pLlcpTransport->pSocketTable[i].socket_sSap = PHFRINFC_LLCP_SAP_DEFAULT;
- pLlcpTransport->pSocketTable[i].socket_dSap = PHFRINFC_LLCP_SAP_DEFAULT;
- pLlcpTransport->pSocketTable[i].bSocketRecvPending = FALSE;
- pLlcpTransport->pSocketTable[i].bSocketSendPending = FALSE;
- pLlcpTransport->pSocketTable[i].bSocketListenPending = FALSE;
- pLlcpTransport->pSocketTable[i].bSocketDiscPending = FALSE;
- pLlcpTransport->pSocketTable[i].bSocketConnectPending = FALSE;
- pLlcpTransport->pSocketTable[i].bSocketAcceptPending = FALSE;
- pLlcpTransport->pSocketTable[i].bSocketRRPending = FALSE;
- pLlcpTransport->pSocketTable[i].bSocketRNRPending = FALSE;
- pLlcpTransport->pSocketTable[i].psTransport = pLlcpTransport;
- pLlcpTransport->pSocketTable[i].pfSocketSend_Cb = NULL;
- pLlcpTransport->pSocketTable[i].pfSocketRecv_Cb = NULL;
- pLlcpTransport->pSocketTable[i].pfSocketRecvFrom_Cb = NULL;
- pLlcpTransport->pSocketTable[i].pfSocketListen_Cb = NULL;
- pLlcpTransport->pSocketTable[i].pfSocketConnect_Cb = NULL;
- pLlcpTransport->pSocketTable[i].pfSocketDisconnect_Cb = NULL;
- pLlcpTransport->pSocketTable[i].socket_VS = 0;
- pLlcpTransport->pSocketTable[i].socket_VSA = 0;
- pLlcpTransport->pSocketTable[i].socket_VR = 0;
- pLlcpTransport->pSocketTable[i].socket_VRA = 0;
- pLlcpTransport->pSocketTable[i].remoteRW = 0;
- pLlcpTransport->pSocketTable[i].localRW = 0;
- pLlcpTransport->pSocketTable[i].remoteMIU = 0;
- pLlcpTransport->pSocketTable[i].localMIUX = 0;
- pLlcpTransport->pSocketTable[i].index = 0;
- pLlcpTransport->pSocketTable[i].indexRwRead = 0;
- pLlcpTransport->pSocketTable[i].indexRwWrite = 0;
-
- memset(&pLlcpTransport->pSocketTable[i].sSocketOption, 0x00, sizeof(phFriNfc_LlcpTransport_sSocketOptions_t));
-
- if (pLlcpTransport->pSocketTable[i].sServiceName.buffer != NULL) {
- phOsalNfc_FreeMemory(pLlcpTransport->pSocketTable[i].sServiceName.buffer);
- }
- pLlcpTransport->pSocketTable[i].sServiceName.buffer = NULL;
- pLlcpTransport->pSocketTable[i].sServiceName.length = 0;
- }
-
- /* Start The Receive Loop */
- status = phFriNfc_Llcp_Recv(pLlcpTransport->pLlcp,
- phFriNfc_LlcpTransport__Recv_CB,
- pLlcpTransport);
- }
- return status;
-}
-
-/* TODO: comment function Transport CloseAll */
-NFCSTATUS phFriNfc_LlcpTransport_CloseAll (phFriNfc_LlcpTransport_t *pLlcpTransport)
-{
- NFCSTATUS status = NFCSTATUS_SUCCESS;
- phFriNfc_Llcp_CachedServiceName_t * pCachedServiceName;
- uint8_t i;
-
- /* Check for NULL pointers */
- if(pLlcpTransport == NULL)
- {
- status = PHNFCSTVAL(CID_FRI_NFC_LLCP_TRANSPORT, NFCSTATUS_INVALID_PARAMETER);
- }
-
- /* Close all sockets */
- for(i=0;ipSocketTable[i].eSocket_Type == phFriNfc_LlcpTransport_eConnectionOriented)
- {
- switch(pLlcpTransport->pSocketTable[i].eSocket_State)
- {
- case phFriNfc_LlcpTransportSocket_eSocketConnected:
- case phFriNfc_LlcpTransportSocket_eSocketConnecting:
- case phFriNfc_LlcpTransportSocket_eSocketAccepted:
- case phFriNfc_LlcpTransportSocket_eSocketDisconnected:
- case phFriNfc_LlcpTransportSocket_eSocketDisconnecting:
- case phFriNfc_LlcpTransportSocket_eSocketRejected:
- phFriNfc_LlcpTransport_Close(&pLlcpTransport->pSocketTable[i]);
- break;
- default:
- /* Do nothing */
- break;
- }
- }
- else
- {
- phFriNfc_LlcpTransport_Close(&pLlcpTransport->pSocketTable[i]);
- }
- }
-
- /* Reset cached service name/sap table */
- for(i=0;ipCachedServiceNames[i];
-
- pCachedServiceName->nSap = 0;
- if (pCachedServiceName->sServiceName.buffer != NULL)
- {
- phOsalNfc_FreeMemory(pCachedServiceName->sServiceName.buffer);
- pCachedServiceName->sServiceName.buffer = NULL;
- }
- pCachedServiceName->sServiceName.length = 0;
- }
-
- return status;
-}
-
-
-/* TODO: comment function Transport LinkSend */
-NFCSTATUS phFriNfc_LlcpTransport_LinkSend( phFriNfc_LlcpTransport_t *LlcpTransport,
- phFriNfc_Llcp_sPacketHeader_t *psHeader,
- phFriNfc_Llcp_sPacketSequence_t *psSequence,
- phNfc_sData_t *psInfo,
- phFriNfc_Llcp_LinkSend_CB_t pfSend_CB,
- uint8_t socketIndex,
- void *pContext )
-{
- NFCSTATUS status;
- /* Check if a send is already ongoing */
- if (LlcpTransport->pfLinkSendCb != NULL)
- {
- return NFCSTATUS_BUSY;
- }
- /* Save callback details */
- LlcpTransport->pfLinkSendCb = pfSend_CB;
- LlcpTransport->pLinkSendContext = pContext;
- LlcpTransport->socketIndex = socketIndex;
-
- /* Call the link-level send function */
- status = phFriNfc_Llcp_Send(LlcpTransport->pLlcp, psHeader, psSequence, psInfo, phFriNfc_LlcpTransport_Send_CB, (void*)LlcpTransport);
- if (status != NFCSTATUS_PENDING && status != NFCSTATUS_SUCCESS) {
- // Clear out callbacks
- LlcpTransport->pfLinkSendCb = NULL;
- LlcpTransport->pLinkSendContext = NULL;
- }
- return status;
-}
-
-
-/* TODO: comment function Transport SendFrameReject */
-NFCSTATUS phFriNfc_LlcpTransport_SendFrameReject(phFriNfc_LlcpTransport_t *psTransport,
- uint8_t dsap,
- uint8_t rejectedPTYPE,
- uint8_t ssap,
- phFriNfc_Llcp_sPacketSequence_t* sLlcpSequence,
- uint8_t WFlag,
- uint8_t IFlag,
- uint8_t RFlag,
- uint8_t SFlag,
- uint8_t vs,
- uint8_t vsa,
- uint8_t vr,
- uint8_t vra)
-{
- NFCSTATUS status = NFCSTATUS_SUCCESS;
- phNfc_sData_t sFrmrBuffer;
- uint8_t flagValue;
- uint8_t sequence = 0;
- uint8_t index;
- uint8_t socketFound = FALSE;
-
- /* Search a socket waiting for a FRAME */
- for(index=0;indexpSocketTable[index].socket_sSap == dsap
- && psTransport->pSocketTable[index].socket_dSap == ssap)
- {
- /* socket found */
- socketFound = TRUE;
- break;
- }
- }
-
- /* Test if a socket has been found */
- if(socketFound)
- {
- /* Set socket state to disconnected */
- psTransport->pSocketTable[index].eSocket_State = phFriNfc_LlcpTransportSocket_eSocketDefault;
-
- /* Call ErrCB due to a FRMR*/
- psTransport->pSocketTable[index].pSocketErrCb( psTransport->pSocketTable[index].pContext,PHFRINFC_LLCP_ERR_FRAME_REJECTED);
-
- /* Close the socket */
- status = phFriNfc_LlcpTransport_ConnectionOriented_Close(&psTransport->pSocketTable[index]);
-
- /* Set FRMR Header */
- psTransport->sLlcpHeader.dsap = ssap;
- psTransport->sLlcpHeader.ptype = PHFRINFC_LLCP_PTYPE_FRMR;
- psTransport->sLlcpHeader.ssap = dsap;
-
- /* Set FRMR Information Field */
- flagValue = (WFlag<<7) | (IFlag<<6) | (RFlag<<5) | (SFlag<<4) | rejectedPTYPE;
- if (sLlcpSequence != NULL)
- {
- sequence = (uint8_t)((sLlcpSequence->ns<<4)|(sLlcpSequence->nr));
- }
-
- psTransport->FrmrInfoBuffer[0] = flagValue;
- psTransport->FrmrInfoBuffer[1] = sequence;
- psTransport->FrmrInfoBuffer[2] = (vs<<4)|vr ;
- psTransport->FrmrInfoBuffer[3] = (vsa<<4)|vra ;
-
- /* Test if a send is pending */
- if(testAndSetSendPending(psTransport))
- {
- psTransport->bFrmrPending = TRUE;
- status = NFCSTATUS_PENDING;
- }
- else
- {
- sFrmrBuffer.buffer = psTransport->FrmrInfoBuffer;
- sFrmrBuffer.length = 0x04; /* Size of FRMR Information field */
-
- /* Send FRMR frame */
- status = phFriNfc_Llcp_Send(psTransport->pLlcp,
- &psTransport->sLlcpHeader,
- NULL,
- &sFrmrBuffer,
- phFriNfc_LlcpTransport_Send_CB,
- psTransport);
- }
- }
- else
- {
- /* No active socket*/
- /* FRMR Frame not handled*/
- }
- return status;
-}
-
-
-/* TODO: comment function Transport SendDisconnectMode (NOTE: used only
- * for requests not bound to a socket, like "service not found")
- */
-NFCSTATUS phFriNfc_LlcpTransport_SendDisconnectMode(phFriNfc_LlcpTransport_t* psTransport,
- uint8_t dsap,
- uint8_t ssap,
- uint8_t dmOpCode)
-{
- NFCSTATUS status = NFCSTATUS_SUCCESS;
-
- /* Test if a send is pending */
- if(testAndSetSendPending(psTransport))
- {
- /* DM pending */
- psTransport->bDmPending = TRUE;
-
- /* Store DM Info */
- psTransport->DmInfoBuffer[0] = dsap;
- psTransport->DmInfoBuffer[1] = ssap;
- psTransport->DmInfoBuffer[2] = dmOpCode;
-
- status = NFCSTATUS_PENDING;
- }
- else
- {
- /* Set the header */
- psTransport->sDmHeader.dsap = dsap;
- psTransport->sDmHeader.ptype = PHFRINFC_LLCP_PTYPE_DM;
- psTransport->sDmHeader.ssap = ssap;
-
- /* Save Operation Code to be provided in DM frame payload */
- psTransport->DmInfoBuffer[2] = dmOpCode;
- psTransport->sDmPayload.buffer = &psTransport->DmInfoBuffer[2];
- psTransport->sDmPayload.length = PHFRINFC_LLCP_DM_LENGTH;
-
- /* Send DM frame */
- status = phFriNfc_Llcp_Send(psTransport->pLlcp,
- &psTransport->sDmHeader,
- NULL,
- &psTransport->sDmPayload,
- phFriNfc_LlcpTransport_Send_CB,
- psTransport);
- }
-
- return status;
-}
-
-
-/**
-* \ingroup grp_lib_nfc
-* \brief Get the local options of a socket.
-*
-* This function returns the local options (maximum packet size and receive window size) used
-* for a given connection-oriented socket. This function shall not be used with connectionless
-* sockets.
-*
-* \param[out] pLlcpSocket A pointer to a phFriNfc_LlcpTransport_Socket_t.
-* \param[in] psLocalOptions A pointer to be filled with the local options of the socket.
-*
-* \retval NFCSTATUS_SUCCESS Operation successful.
-* \retval NFCSTATUS_INVALID_PARAMETER One or more of the supplied parameters
-* could not be properly interpreted.
-* \retval NFCSTATUS_INVALID_STATE The socket is not in a valid state, or not of
-* a valid type to perform the requsted operation.
-* \retval NFCSTATUS_NOT_INITIALISED Indicates stack is not yet initialized.
-* \retval NFCSTATUS_SHUTDOWN Shutdown in progress.
-* \retval NFCSTATUS_FAILED Operation failed.
-*/
-NFCSTATUS phFriNfc_LlcpTransport_SocketGetLocalOptions(phFriNfc_LlcpTransport_Socket_t *pLlcpSocket,
- phLibNfc_Llcp_sSocketOptions_t *psLocalOptions)
-{
- NFCSTATUS status = NFCSTATUS_SUCCESS;
-
- /* Check for NULL pointers */
- if (pLlcpSocket == NULL || psLocalOptions == NULL)
- {
- status = PHNFCSTVAL(CID_FRI_NFC_LLCP_TRANSPORT, NFCSTATUS_INVALID_PARAMETER);
- }
- /* Test the socket type */
- else if(pLlcpSocket->eSocket_Type != phFriNfc_LlcpTransport_eConnectionOriented)
- {
- status = PHNFCSTVAL(CID_FRI_NFC_LLCP_TRANSPORT, NFCSTATUS_INVALID_PARAMETER);
- }
- /* Test the socket state */
- else if(pLlcpSocket->eSocket_State == phFriNfc_LlcpTransportSocket_eSocketDefault)
- {
- status = PHNFCSTVAL(CID_FRI_NFC_LLCP_TRANSPORT, NFCSTATUS_INVALID_STATE);
- }
- else
- {
- status = phFriNfc_LlcpTransport_ConnectionOriented_SocketGetLocalOptions(pLlcpSocket,
- psLocalOptions);
- }
-
- return status;
-}
-
-
-/**
-* \ingroup grp_lib_nfc
-* \brief Get the local options of a socket.
-*
-* This function returns the remote options (maximum packet size and receive window size) used
-* for a given connection-oriented socket. This function shall not be used with connectionless
-* sockets.
-*
-* \param[out] pLlcpSocket A pointer to a phFriNfc_LlcpTransport_Socket_t.
-* \param[in] psRemoteOptions A pointer to be filled with the remote options of the socket.
-*
-* \retval NFCSTATUS_SUCCESS Operation successful.
-* \retval NFCSTATUS_INVALID_PARAMETER One or more of the supplied parameters
-* could not be properly interpreted.
-* \retval NFCSTATUS_INVALID_STATE The socket is not in a valid state, or not of
-* a valid type to perform the requsted operation.
-* \retval NFCSTATUS_NOT_INITIALISED Indicates stack is not yet initialized.
-* \retval NFCSTATUS_SHUTDOWN Shutdown in progress.
-* \retval NFCSTATUS_FAILED Operation failed.
-*/
-NFCSTATUS phFriNfc_LlcpTransport_SocketGetRemoteOptions(phFriNfc_LlcpTransport_Socket_t* pLlcpSocket,
- phLibNfc_Llcp_sSocketOptions_t* psRemoteOptions)
-{
- NFCSTATUS status = NFCSTATUS_SUCCESS;
-
- /* Check for NULL pointers */
- if (pLlcpSocket == NULL || psRemoteOptions == NULL)
- {
- status = PHNFCSTVAL(CID_FRI_NFC_LLCP_TRANSPORT, NFCSTATUS_INVALID_PARAMETER);
- }
- /* Test the socket type */
- else if(pLlcpSocket->eSocket_Type != phFriNfc_LlcpTransport_eConnectionOriented)
- {
- status = PHNFCSTVAL(CID_FRI_NFC_LLCP_TRANSPORT, NFCSTATUS_INVALID_PARAMETER);
- }
- /* Test the socket state */
- else if(pLlcpSocket->eSocket_State != phFriNfc_LlcpTransportSocket_eSocketConnected)
- {
- status = PHNFCSTVAL(CID_FRI_NFC_LLCP_TRANSPORT, NFCSTATUS_INVALID_STATE);
- }
- else
- {
- status = phFriNfc_LlcpTransport_ConnectionOriented_SocketGetRemoteOptions(pLlcpSocket,
- psRemoteOptions);
- }
-
- return status;
-}
-
-
-static NFCSTATUS phFriNfc_LlcpTransport_DiscoverServicesEx(phFriNfc_LlcpTransport_t *psTransport)
-{
- NFCSTATUS result = NFCSTATUS_PENDING;
- phNfc_sData_t sInfoBuffer;
- phNfc_sData_t *psServiceName;
- uint32_t nTlvOffset;
-
- /* Test if a send is pending */
- if(!testAndSetSendPending(psTransport))
- {
- /* Set the header */
- psTransport->sLlcpHeader.dsap = PHFRINFC_LLCP_SAP_SDP;
- psTransport->sLlcpHeader.ptype = PHFRINFC_LLCP_PTYPE_SNL;
- psTransport->sLlcpHeader.ssap = PHFRINFC_LLCP_SAP_SDP;
-
- /* Prepare the info buffer */
- sInfoBuffer.buffer = psTransport->pDiscoveryBuffer;
- sInfoBuffer.length = sizeof(psTransport->pDiscoveryBuffer);
-
- /* Encode as many requests as possible */
- nTlvOffset = 0;
- while(psTransport->nDiscoveryReqOffset < psTransport->nDiscoveryListSize)
- {
- /* Get current service name and try to encode it in SNL frame */
- psServiceName = &psTransport->psDiscoveryServiceNameList[psTransport->nDiscoveryReqOffset];
- result = phFriNfc_LlcpTransport_EncodeSdreqTlv(&sInfoBuffer,
- &nTlvOffset,
- psTransport->nDiscoveryReqOffset,
- psServiceName);
- if (result != NFCSTATUS_SUCCESS)
- {
- /* Impossible to fit more requests in a single frame,
- * will be continued on next opportunity
- */
- break;
- }
-
- /* Update request counter */
- psTransport->nDiscoveryReqOffset++;
- }
-
- /* Update buffer length to match real TLV size */
- sInfoBuffer.length = nTlvOffset;
-
- /* Send SNL frame */
- result = phFriNfc_Llcp_Send(psTransport->pLlcp,
- &psTransport->sLlcpHeader,
- NULL,
- &sInfoBuffer,
- phFriNfc_LlcpTransport_Send_CB,
- psTransport);
- }
- else
- {
- /* Impossible to send now, this function will be called again on next opportunity */
- }
-
- return result;
-}
-
-/*!
-* \ingroup grp_fri_nfc
-* \brief Discover remote services SAP using SDP protocol.
- */
-NFCSTATUS phFriNfc_LlcpTransport_DiscoverServices( phFriNfc_LlcpTransport_t *pLlcpTransport,
- phNfc_sData_t *psServiceNameList,
- uint8_t *pnSapList,
- uint8_t nListSize,
- pphFriNfc_Cr_t pDiscover_Cb,
- void *pContext )
-{
- NFCSTATUS result = NFCSTATUS_FAILED;
-
- /* Save request details */
- pLlcpTransport->psDiscoveryServiceNameList = psServiceNameList;
- pLlcpTransport->pnDiscoverySapList = pnSapList;
- pLlcpTransport->nDiscoveryListSize = nListSize;
- pLlcpTransport->pfDiscover_Cb = pDiscover_Cb;
- pLlcpTransport->pDiscoverContext = pContext;
-
- /* Reset internal counters */
- pLlcpTransport->nDiscoveryReqOffset = 0;
- pLlcpTransport->nDiscoveryResOffset = 0;
-
- /* Perform request */
- result = phFriNfc_LlcpTransport_DiscoverServicesEx(pLlcpTransport);
-
- return result;
-}
-
-
- /**
-* \ingroup grp_fri_nfc
-* \brief Create a socket on a LLCP-connected device.
-*
-* This function creates a socket for a given LLCP link. Sockets can be of two types :
-* connection-oriented and connectionless. If the socket is connection-oriented, the caller
-* must provide a working buffer to the socket in order to handle incoming data. This buffer
-* must be large enough to fit the receive window (RW * MIU), the remaining space being
-* used as a linear buffer to store incoming data as a stream. Data will be readable later
-* using the phLibNfc_LlcpTransport_Recv function.
-* The options and working buffer are not required if the socket is used as a listening socket,
-* since it cannot be directly used for communication.
-*
-* \param[in] pLlcpSocketTable A pointer to a table of PHFRINFC_LLCP_NB_SOCKET_DEFAULT sockets.
-* \param[in] eType The socket type.
-* \param[in] psOptions The options to be used with the socket.
-* \param[in] psWorkingBuffer A working buffer to be used by the library.
-* \param[out] pLlcpSocket A pointer on the socket to be filled with a
- socket found on the socket table.
-* \param[in] pErr_Cb The callback to be called each time the socket
-* is in error.
-* \param[in] pContext Upper layer context to be returned in the callback.
-*
-* \retval NFCSTATUS_SUCCESS Operation successful.
-* \retval NFCSTATUS_INVALID_PARAMETER One or more of the supplied parameters
-* could not be properly interpreted.
-* \retval NFCSTATUS_BUFFER_TOO_SMALL The working buffer is too small for the MIU and RW
-* declared in the options.
-* \retval NFCSTATUS_INSUFFICIENT_RESOURCES No more socket handle available.
-* \retval NFCSTATUS_FAILED Operation failed.
-* */
-NFCSTATUS phFriNfc_LlcpTransport_Socket(phFriNfc_LlcpTransport_t *pLlcpTransport,
- phFriNfc_LlcpTransport_eSocketType_t eType,
- phFriNfc_LlcpTransport_sSocketOptions_t *psOptions,
- phNfc_sData_t *psWorkingBuffer,
- phFriNfc_LlcpTransport_Socket_t **pLlcpSocket,
- pphFriNfc_LlcpTransportSocketErrCb_t pErr_Cb,
- void *pContext)
-{
- NFCSTATUS status = NFCSTATUS_SUCCESS;
- phFriNfc_Llcp_sLinkParameters_t LlcpLinkParamInfo;
- uint8_t index=0;
- uint8_t cpt;
-
- /* Check for NULL pointers */
- if ( ((psOptions == NULL) && (eType == phFriNfc_LlcpTransport_eConnectionOriented))
- || ((psWorkingBuffer == NULL) && (eType == phFriNfc_LlcpTransport_eConnectionOriented))
- || (pLlcpSocket == NULL)
- || (pErr_Cb == NULL)
- || (pContext == NULL)
- || (pLlcpTransport == NULL))
- {
- status = PHNFCSTVAL(CID_FRI_NFC_LLCP_TRANSPORT, NFCSTATUS_INVALID_PARAMETER);
- return status;
- }
- /* Test the socket type*/
- else if(eType != phFriNfc_LlcpTransport_eConnectionOriented && eType != phFriNfc_LlcpTransport_eConnectionLess)
- {
- status = PHNFCSTVAL(CID_FRI_NFC_LLCP_TRANSPORT, NFCSTATUS_INVALID_PARAMETER);
- return status;
- }
- /* Connectionless sockets don't support options */
- else if ((psOptions != NULL) && (eType == phFriNfc_LlcpTransport_eConnectionLess))
- {
- status = PHNFCSTVAL(CID_FRI_NFC_LLCP_TRANSPORT, NFCSTATUS_INVALID_PARAMETER);
- return status;
- }
-
- /* Get the local parameters of the LLCP Link */
- status = phFriNfc_Llcp_GetLocalInfo(pLlcpTransport->pLlcp,&LlcpLinkParamInfo);
- if(status != NFCSTATUS_SUCCESS)
- {
- status = PHNFCSTVAL(CID_FRI_NFC_LLCP_TRANSPORT, NFCSTATUS_FAILED);
- return status;
- }
- else
- {
- /* Search a socket free in the Socket Table*/
- do
- {
- if(pLlcpTransport->pSocketTable[index].eSocket_State == phFriNfc_LlcpTransportSocket_eSocketDefault)
- {
- /* Set the socket pointer to socket of the table */
- *pLlcpSocket = &pLlcpTransport->pSocketTable[index];
-
- /* Store the socket info in the socket pointer */
- pLlcpTransport->pSocketTable[index].eSocket_Type = eType;
- pLlcpTransport->pSocketTable[index].pSocketErrCb = pErr_Cb;
-
- /* Store the context of the upper layer */
- pLlcpTransport->pSocketTable[index].pContext = pContext;
-
- /* Set the pointers to the different working buffers */
- if (eType == phFriNfc_LlcpTransport_eConnectionOriented)
- {
- /* Test the socket options */
- if (psOptions->rw > PHFRINFC_LLCP_RW_MAX)
- {
- status = PHNFCSTVAL(CID_FRI_NFC_LLCP_TRANSPORT, NFCSTATUS_INVALID_PARAMETER);
- return status;
- }
-
- /* Set socket options */
- memcpy(&pLlcpTransport->pSocketTable[index].sSocketOption, psOptions, sizeof(phFriNfc_LlcpTransport_sSocketOptions_t));
-
- /* Set socket local params (MIUX & RW) */
- pLlcpTransport->pSocketTable[index].localMIUX = (pLlcpTransport->pSocketTable[index].sSocketOption.miu - PHFRINFC_LLCP_MIU_DEFAULT) & PHFRINFC_LLCP_TLV_MIUX_MASK;
- pLlcpTransport->pSocketTable[index].localRW = pLlcpTransport->pSocketTable[index].sSocketOption.rw & PHFRINFC_LLCP_TLV_RW_MASK;
-
- /* Set the Max length for the Send and Receive Window Buffer */
- pLlcpTransport->pSocketTable[index].bufferSendMaxLength = pLlcpTransport->pSocketTable[index].sSocketOption.miu;
- pLlcpTransport->pSocketTable[index].bufferRwMaxLength = pLlcpTransport->pSocketTable[index].sSocketOption.miu * ((pLlcpTransport->pSocketTable[index].sSocketOption.rw & PHFRINFC_LLCP_TLV_RW_MASK));
- pLlcpTransport->pSocketTable[index].bufferLinearLength = psWorkingBuffer->length - pLlcpTransport->pSocketTable[index].bufferSendMaxLength - pLlcpTransport->pSocketTable[index].bufferRwMaxLength;
-
- /* Test the connection oriented buffers length */
- if((pLlcpTransport->pSocketTable[index].bufferSendMaxLength + pLlcpTransport->pSocketTable[index].bufferRwMaxLength) > psWorkingBuffer->length
- || ((pLlcpTransport->pSocketTable[index].bufferLinearLength < PHFRINFC_LLCP_MIU_DEFAULT) && (pLlcpTransport->pSocketTable[index].bufferLinearLength != 0)))
- {
- status = PHNFCSTVAL(CID_FRI_NFC_LLCP_TRANSPORT, NFCSTATUS_BUFFER_TOO_SMALL);
- return status;
- }
-
- /* Set the pointer and the length for the Receive Window Buffer */
- for(cpt=0;cptpSocketTable[index].localRW;cpt++)
- {
- pLlcpTransport->pSocketTable[index].sSocketRwBufferTable[cpt].buffer = psWorkingBuffer->buffer + (cpt*pLlcpTransport->pSocketTable[index].sSocketOption.miu);
- pLlcpTransport->pSocketTable[index].sSocketRwBufferTable[cpt].length = 0;
- }
-
- /* Set the pointer and the length for the Send Buffer */
- pLlcpTransport->pSocketTable[index].sSocketSendBuffer.buffer = psWorkingBuffer->buffer + pLlcpTransport->pSocketTable[index].bufferRwMaxLength;
- pLlcpTransport->pSocketTable[index].sSocketSendBuffer.length = pLlcpTransport->pSocketTable[index].bufferSendMaxLength;
-
- /** Set the pointer and the length for the Linear Buffer */
- pLlcpTransport->pSocketTable[index].sSocketLinearBuffer.buffer = psWorkingBuffer->buffer + pLlcpTransport->pSocketTable[index].bufferRwMaxLength + pLlcpTransport->pSocketTable[index].bufferSendMaxLength;
- pLlcpTransport->pSocketTable[index].sSocketLinearBuffer.length = pLlcpTransport->pSocketTable[index].bufferLinearLength;
-
- if(pLlcpTransport->pSocketTable[index].sSocketLinearBuffer.length != 0)
- {
- /* Init Cyclic Fifo */
- phFriNfc_Llcp_CyclicFifoInit(&pLlcpTransport->pSocketTable[index].sCyclicFifoBuffer,
- pLlcpTransport->pSocketTable[index].sSocketLinearBuffer.buffer,
- pLlcpTransport->pSocketTable[index].sSocketLinearBuffer.length);
- }
- }
- /* Handle connectionless socket with buffering option */
- else if (eType == phFriNfc_LlcpTransport_eConnectionLess)
- {
- /* Determine how many packets can be bufferized in working buffer */
- if (psWorkingBuffer != NULL)
- {
- /* NOTE: the extra byte is used to store SSAP */
- pLlcpTransport->pSocketTable[index].localRW = psWorkingBuffer->length / (pLlcpTransport->pLlcp->sLocalParams.miu + 1);
- }
- else
- {
- pLlcpTransport->pSocketTable[index].localRW = 0;
- }
-
- if (pLlcpTransport->pSocketTable[index].localRW > PHFRINFC_LLCP_RW_MAX)
- {
- pLlcpTransport->pSocketTable[index].localRW = PHFRINFC_LLCP_RW_MAX;
- }
-
- /* Set the pointers and the lengths for buffering */
- for(cpt=0 ; cptpSocketTable[index].localRW ; cpt++)
- {
- pLlcpTransport->pSocketTable[index].sSocketRwBufferTable[cpt].buffer = psWorkingBuffer->buffer + (cpt*(pLlcpTransport->pLlcp->sLocalParams.miu + 1));
- pLlcpTransport->pSocketTable[index].sSocketRwBufferTable[cpt].length = 0;
- }
-
- /* Set other socket internals */
- pLlcpTransport->pSocketTable[index].indexRwRead = 0;
- pLlcpTransport->pSocketTable[index].indexRwWrite = 0;
- }
-
- /* Store index of the socket */
- pLlcpTransport->pSocketTable[index].index = index;
-
- /* Set the socket into created state */
- pLlcpTransport->pSocketTable[index].eSocket_State = phFriNfc_LlcpTransportSocket_eSocketCreated;
- return status;
- }
- else
- {
- index++;
- }
- }while(indexClose a socket on a LLCP-connected device.
-*
-* This function closes a LLCP socket previously created using phFriNfc_LlcpTransport_Socket.
-* If the socket was connected, it is first disconnected, and then closed.
-*
-* \param[in] pLlcpSocket A pointer to a phFriNfc_LlcpTransport_Socket_t.
-
-* \retval NFCSTATUS_SUCCESS Operation successful.
-* \retval NFCSTATUS_INVALID_PARAMETER One or more of the supplied parameters
-* could not be properly interpreted.
-* \retval NFCSTATUS_FAILED Operation failed.
-*/
-NFCSTATUS phFriNfc_LlcpTransport_Close(phFriNfc_LlcpTransport_Socket_t* pLlcpSocket)
-{
- NFCSTATUS status = NFCSTATUS_SUCCESS;
-
- /* Check for NULL pointers */
- if( pLlcpSocket == NULL)
- {
- status = PHNFCSTVAL(CID_FRI_NFC_LLCP_TRANSPORT, NFCSTATUS_INVALID_PARAMETER);
- }
- else if(pLlcpSocket->eSocket_Type == phFriNfc_LlcpTransport_eConnectionOriented)
- {
- status = phFriNfc_LlcpTransport_ConnectionOriented_Close(pLlcpSocket);
- }
- else if(pLlcpSocket->eSocket_Type == phFriNfc_LlcpTransport_eConnectionLess)
- {
- status = phFriNfc_LlcpTransport_Connectionless_Close(pLlcpSocket);
- }
- else
- {
- status = PHNFCSTVAL(CID_FRI_NFC_LLCP_TRANSPORT, NFCSTATUS_INVALID_PARAMETER);
- }
-
- return status;
-}
-
-/**
-* \ingroup grp_fri_nfc
-* \brief Bind a socket to a local SAP.
-*
-* This function binds the socket to a local Service Access Point.
-*
-* \param[in] pLlcpSocket A pointer to a phFriNfc_LlcpTransport_Socket_t.
-* \param[in] nSap The SAP number to bind with, or 0 for auto-bind to a free SAP.
-* \param[in] psServiceName A pointer to Service Name, or NULL if no service name.
-*
-* \retval NFCSTATUS_SUCCESS Operation successful.
-* \retval NFCSTATUS_INVALID_PARAMETER One or more of the supplied parameters
-* could not be properly interpreted.
-* \retval NFCSTATUS_INVALID_STATE The socket is not in a valid state, or not of
-* a valid type to perform the requsted operation.
-* \retval NFCSTATUS_ALREADY_REGISTERED The selected SAP is already bound to another
- socket.
-* \retval NFCSTATUS_FAILED Operation failed.
-*/
-
-NFCSTATUS phFriNfc_LlcpTransport_Bind(phFriNfc_LlcpTransport_Socket_t *pLlcpSocket,
- uint8_t nSap,
- phNfc_sData_t *psServiceName)
-{
- NFCSTATUS status = NFCSTATUS_SUCCESS;
- uint8_t i;
- uint8_t min_sap_range;
- uint8_t max_sap_range;
-
- /* Check for NULL pointers */
- if(pLlcpSocket == NULL)
- {
- status = PHNFCSTVAL(CID_FRI_NFC_LLCP_TRANSPORT, NFCSTATUS_INVALID_PARAMETER);
- }
- else if(pLlcpSocket->eSocket_State != phFriNfc_LlcpTransportSocket_eSocketCreated)
- {
- status = PHNFCSTVAL(CID_FRI_NFC_LLCP_TRANSPORT, NFCSTATUS_INVALID_STATE);
- }
- else
- {
- /* Calculate authorized SAP range */
- if ((psServiceName != NULL) && (psServiceName->length > 0))
- {
- /* SDP advertised service */
- min_sap_range = PHFRINFC_LLCP_SAP_SDP_ADVERTISED_FIRST;
- max_sap_range = PHFRINFC_LLCP_SAP_SDP_UNADVERTISED_FIRST;
- }
- else
- {
- /* Non-SDP advertised service */
- min_sap_range = PHFRINFC_LLCP_SAP_SDP_UNADVERTISED_FIRST;
- max_sap_range = PHFRINFC_LLCP_SAP_NUMBER;
- }
-
- /* Handle dynamic SAP allocation */
- if (nSap == 0)
- {
- status = phFriNfc_LlcpTransport_GetFreeSap(pLlcpSocket->psTransport, psServiceName, &nSap);
- if (status != NFCSTATUS_SUCCESS)
- {
- return status;
- }
- }
-
- /* Test the SAP range */
- if(!IS_BETWEEN(nSap, min_sap_range, max_sap_range) &&
- !IS_BETWEEN(nSap, PHFRINFC_LLCP_SAP_WKS_FIRST, PHFRINFC_LLCP_SAP_SDP_ADVERTISED_FIRST))
- {
- status = PHNFCSTVAL(CID_FRI_NFC_LLCP_TRANSPORT, NFCSTATUS_INVALID_PARAMETER);
- }
- else
- {
- /* Test if the nSap it is used by another socket */
- for(i=0;ipsTransport->pSocketTable[i].socket_sSap == nSap)
- {
- return status = PHNFCSTVAL(CID_FRI_NFC_LLCP_TRANSPORT, NFCSTATUS_ALREADY_REGISTERED);
- }
- }
- /* Set service name */
- status = phFriNfc_LlcpTransport_RegisterName(pLlcpSocket, nSap, psServiceName);
- if (status != NFCSTATUS_SUCCESS)
- {
- return status;
- }
- /* Set the nSap value of the socket */
- pLlcpSocket->socket_sSap = nSap;
- /* Set the socket state */
- pLlcpSocket->eSocket_State = phFriNfc_LlcpTransportSocket_eSocketBound;
- }
- }
- return status;
-}
-
-/*********************************************/
-/* ConnectionOriented */
-/*********************************************/
-
-/**
-* \ingroup grp_fri_nfc
-* \brief Listen for incoming connection requests on a socket.
-*
-* This function switches a socket into a listening state and registers a callback on
-* incoming connection requests. In this state, the socket is not able to communicate
-* directly. The listening state is only available for connection-oriented sockets
-* which are still not connected. The socket keeps listening until it is closed, and
-* thus can trigger several times the pListen_Cb callback.
-*
-*
-* \param[in] pLlcpSocket A pointer to a phFriNfc_LlcpTransport_Socket_t.
-* \param[in] pListen_Cb The callback to be called each time the
-* socket receive a connection request.
-* \param[in] pContext Upper layer context to be returned in
-* the callback.
-*
-* \retval NFCSTATUS_SUCCESS Operation successful.
-* \retval NFCSTATUS_INVALID_PARAMETER One or more of the supplied parameters
-* could not be properly interpreted.
-* \retval NFCSTATUS_INVALID_STATE The socket is not in a valid state to switch
-* to listening state.
-* \retval NFCSTATUS_FAILED Operation failed.
-*/
-NFCSTATUS phFriNfc_LlcpTransport_Listen(phFriNfc_LlcpTransport_Socket_t* pLlcpSocket,
- pphFriNfc_LlcpTransportSocketListenCb_t pListen_Cb,
- void* pContext)
-{
- NFCSTATUS status = NFCSTATUS_SUCCESS;
-
- /* Check for NULL pointers */
- if(pLlcpSocket == NULL || pListen_Cb == NULL|| pContext == NULL )
- {
- status = PHNFCSTVAL(CID_FRI_NFC_LLCP_TRANSPORT, NFCSTATUS_INVALID_PARAMETER);
- }
- /* Check for socket state */
- else if(pLlcpSocket->eSocket_State != phFriNfc_LlcpTransportSocket_eSocketBound)
- {
- status = PHNFCSTVAL(CID_FRI_NFC_LLCP_TRANSPORT, NFCSTATUS_INVALID_STATE);
- }
- /* Check for socket type */
- else if(pLlcpSocket->eSocket_Type != phFriNfc_LlcpTransport_eConnectionOriented)
- {
- status = PHNFCSTVAL(CID_FRI_NFC_LLCP_TRANSPORT, NFCSTATUS_INVALID_PARAMETER);
- }
- /* Test if a listen is not pending with this socket */
- else if(pLlcpSocket->bSocketListenPending)
- {
- status = PHNFCSTVAL(CID_FRI_NFC_LLCP_TRANSPORT, NFCSTATUS_INVALID_PARAMETER);
- }
- else
- {
- status = phFriNfc_LlcpTransport_ConnectionOriented_Listen(pLlcpSocket,
- pListen_Cb,
- pContext);
- }
- return status;
-}
-
-
-/**
-* \ingroup grp_fri_nfc
-* \brief Register the socket service name.
-*
-* This function changes the service name of the corresponding socket.
-*
-* \param[in] pLlcpSocket A pointer to a phFriNfc_LlcpTransport_Socket_t.
-* \param[in] nSap SAP number associated to the service name.
-* \param[in] psServiceName A pointer to a Service Name.
-*
-* \retval NFCSTATUS_SUCCESS Operation successful.
-* \retval NFCSTATUS_INVALID_PARAMETER One or more of the supplied parameters
-* could not be properly interpreted.
-* \retval NFCSTATUS_FAILED Operation failed.
-*/
-static NFCSTATUS phFriNfc_LlcpTransport_RegisterName(phFriNfc_LlcpTransport_Socket_t* pLlcpSocket,
- uint8_t nSap,
- phNfc_sData_t *psServiceName)
-{
- phFriNfc_LlcpTransport_t * psTransport = pLlcpSocket->psTransport;
- uint8_t index;
- uint8_t bSnMatch, bSapMatch;
-
- /* Check in cache if sap has been used for different service name */
- for(index=0 ; indexpCachedServiceNames[index].sServiceName.length == 0)
- {
- /* Reached end of table */
- break;
- }
-
- bSnMatch = (memcmp(psTransport->pCachedServiceNames[index].sServiceName.buffer, psServiceName->buffer, psServiceName->length) == 0);
- bSapMatch = psTransport->pCachedServiceNames[index].nSap == nSap;
- if(bSnMatch && bSapMatch)
- {
- /* Request match cache */
- break;
- }
- else if((bSnMatch && !bSapMatch) || (!bSnMatch && bSapMatch))
- {
- /* Request mismatch with cache */
- return NFCSTATUS_INVALID_PARAMETER;
- }
- }
-
- /* Handle service with no name */
- if (psServiceName == NULL)
- {
- if (pLlcpSocket->sServiceName.buffer != NULL)
- {
- phOsalNfc_FreeMemory(pLlcpSocket->sServiceName.buffer);
- }
- pLlcpSocket->sServiceName.buffer = NULL;
- pLlcpSocket->sServiceName.length = 0;
- }
- else
- {
- /* Check if name already in use */
- for(index=0;indexpsTransport->pSocketTable[index];
-
- if( (pCurrentSocket->eSocket_State != phFriNfc_LlcpTransportSocket_eSocketBound)
- && (pCurrentSocket->eSocket_State != phFriNfc_LlcpTransportSocket_eSocketRegistered))
- {
- /* Only bound or listening sockets may have a service name */
- continue;
- }
- if(pCurrentSocket->sServiceName.length != psServiceName->length) {
- /* Service name do not match, check next */
- continue;
- }
- if(memcmp(pCurrentSocket->sServiceName.buffer, psServiceName->buffer, psServiceName->length) == 0)
- {
- /* Service name already in use */
- return NFCSTATUS_INVALID_PARAMETER;
- }
- }
-
- /* Store the listen socket SN */
- pLlcpSocket->sServiceName.length = psServiceName->length;
- pLlcpSocket->sServiceName.buffer = phOsalNfc_GetMemory(psServiceName->length);
- if (pLlcpSocket->sServiceName.buffer == NULL)
- {
- return NFCSTATUS_NOT_ENOUGH_MEMORY;
- }
- memcpy(pLlcpSocket->sServiceName.buffer, psServiceName->buffer, psServiceName->length);
- }
-
- return NFCSTATUS_SUCCESS;
-}
-
-/**
-* \ingroup grp_fri_nfc
-* \brief Accept an incoming connection request for a socket.
-*
-* This functions allows the client to accept an incoming connection request.
-* It must be used with the socket provided within the listen callback. The socket
-* is implicitly switched to the connected state when the function is called.
-*
-* \param[in] pLlcpSocket A pointer to a phFriNfc_LlcpTransport_Socket_t.
-* \param[in] psOptions The options to be used with the socket.
-* \param[in] psWorkingBuffer A working buffer to be used by the library.
-* \param[in] pErr_Cb The callback to be called each time the accepted socket
-* is in error.
-* \param[in] pContext Upper layer context to be returned in the callback.
-*
-* \retval NFCSTATUS_SUCCESS Operation successful.
-* \retval NFCSTATUS_INVALID_PARAMETER One or more of the supplied parameters
-* could not be properly interpreted.
-* \retval NFCSTATUS_BUFFER_TOO_SMALL The working buffer is too small for the MIU and RW
-* declared in the options.
-* \retval NFCSTATUS_FAILED Operation failed.
-*/
-NFCSTATUS phFriNfc_LlcpTransport_Accept(phFriNfc_LlcpTransport_Socket_t* pLlcpSocket,
- phFriNfc_LlcpTransport_sSocketOptions_t* psOptions,
- phNfc_sData_t* psWorkingBuffer,
- pphFriNfc_LlcpTransportSocketErrCb_t pErr_Cb,
- pphFriNfc_LlcpTransportSocketAcceptCb_t pAccept_RspCb,
- void* pContext)
-{
- NFCSTATUS status = NFCSTATUS_SUCCESS;
-
- /* Check for NULL pointers */
- if(pLlcpSocket == NULL || psOptions == NULL || psWorkingBuffer == NULL || pErr_Cb == NULL || pContext == NULL)
- {
- status = PHNFCSTVAL(CID_FRI_NFC_LLCP_TRANSPORT, NFCSTATUS_INVALID_PARAMETER);
- }
- /* Check for socket state */
- else if(pLlcpSocket->eSocket_State != phFriNfc_LlcpTransportSocket_eSocketBound)
- {
- status = PHNFCSTVAL(CID_FRI_NFC_LLCP_TRANSPORT, NFCSTATUS_INVALID_STATE);
- }
- /* Check for socket type */
- else if(pLlcpSocket->eSocket_Type != phFriNfc_LlcpTransport_eConnectionOriented)
- {
- status = PHNFCSTVAL(CID_FRI_NFC_LLCP_TRANSPORT, NFCSTATUS_INVALID_PARAMETER);
- }
- /* Test the socket options */
- else if(psOptions->rw > PHFRINFC_LLCP_RW_MAX)
- {
- status = PHNFCSTVAL(CID_FRI_NFC_LLCP_TRANSPORT, NFCSTATUS_INVALID_PARAMETER);
- }
- else
- {
- /* Set the Max length for the Send and Receive Window Buffer */
- pLlcpSocket->bufferSendMaxLength = psOptions->miu;
- pLlcpSocket->bufferRwMaxLength = psOptions->miu * ((psOptions->rw & PHFRINFC_LLCP_TLV_RW_MASK));
- pLlcpSocket->bufferLinearLength = psWorkingBuffer->length - pLlcpSocket->bufferSendMaxLength - pLlcpSocket->bufferRwMaxLength;
-
- /* Test the buffers length */
- if((pLlcpSocket->bufferSendMaxLength + pLlcpSocket->bufferRwMaxLength) > psWorkingBuffer->length
- || ((pLlcpSocket->bufferLinearLength < PHFRINFC_LLCP_MIU_DEFAULT) && (pLlcpSocket->bufferLinearLength != 0)))
- {
- status = PHNFCSTVAL(CID_FRI_NFC_LLCP_TRANSPORT, NFCSTATUS_BUFFER_TOO_SMALL);
- }
- else
- {
- pLlcpSocket->psTransport->socketIndex = pLlcpSocket->index;
-
- status = phFriNfc_LlcpTransport_ConnectionOriented_Accept(pLlcpSocket,
- psOptions,
- psWorkingBuffer,
- pErr_Cb,
- pAccept_RspCb,
- pContext);
- }
- }
- return status;
-}
-
- /**
-* \ingroup grp_fri_nfc
-* \brief Reject an incoming connection request for a socket.
-*
-* This functions allows the client to reject an incoming connection request.
-* It must be used with the socket provided within the listen callback. The socket
-* is implicitly closed when the function is called.
-*
-* \param[in] pLlcpSocket A pointer to a phFriNfc_LlcpTransport_Socket_t.
-* \param[in] pReject_RspCb The callback to be call when the Reject operation is completed
-* \param[in] pContext Upper layer context to be returned in the callback.
-*
-* \retval NFCSTATUS_SUCCESS Operation successful.
-* \retval NFCSTATUS_INVALID_PARAMETER One or more of the supplied parameters
-* could not be properly interpreted.
-* \retval NFCSTATUS_FAILED Operation failed.
-*/
-NFCSTATUS phFriNfc_LlcpTransport_Reject( phFriNfc_LlcpTransport_Socket_t* pLlcpSocket,
- pphFriNfc_LlcpTransportSocketRejectCb_t pReject_RspCb,
- void *pContext)
-{
- NFCSTATUS status = NFCSTATUS_SUCCESS;
-
- /* Check for NULL pointers */
- if(pLlcpSocket == NULL)
- {
- status = PHNFCSTVAL(CID_FRI_NFC_LLCP_TRANSPORT, NFCSTATUS_INVALID_PARAMETER);
- }
- /* Check for socket state */
- else if(pLlcpSocket->eSocket_State != phFriNfc_LlcpTransportSocket_eSocketBound)
- {
- status = PHNFCSTVAL(CID_FRI_NFC_LLCP_TRANSPORT, NFCSTATUS_INVALID_STATE);
- }
- /* Check for socket type */
- else if(pLlcpSocket->eSocket_Type != phFriNfc_LlcpTransport_eConnectionOriented)
- {
- status = PHNFCSTVAL(CID_FRI_NFC_LLCP_TRANSPORT, NFCSTATUS_INVALID_PARAMETER);
- }
- else
- {
- status = phLibNfc_LlcpTransport_ConnectionOriented_Reject(pLlcpSocket,
- pReject_RspCb,
- pContext);
- }
-
- return status;
-}
-
-/**
-* \ingroup grp_fri_nfc
-* \brief Try to establish connection with a socket on a remote SAP.
-*
-* This function tries to connect to a given SAP on the remote peer. If the
-* socket is not bound to a local SAP, it is implicitly bound to a free SAP.
-*
-* \param[in] pLlcpSocket A pointer to a phFriNfc_LlcpTransport_Socket_t.
-* \param[in] nSap The destination SAP to connect to.
-* \param[in] pConnect_RspCb The callback to be called when the connection
-* operation is completed.
-* \param[in] pContext Upper layer context to be returned in
-* the callback.
-*
-* \retval NFCSTATUS_SUCCESS Operation successful.
-* \retval NFCSTATUS_INVALID_PARAMETER One or more of the supplied parameters
-* could not be properly interpreted.
-* \retval NFCSTATUS_PENDING Connection operation is in progress,
-* pConnect_RspCb will be called upon completion.
-* \retval NFCSTATUS_INVALID_STATE The socket is not in a valid state, or not of
-* a valid type to perform the requsted operation.
-* \retval NFCSTATUS_FAILED Operation failed.
-*/
-NFCSTATUS phFriNfc_LlcpTransport_Connect( phFriNfc_LlcpTransport_Socket_t* pLlcpSocket,
- uint8_t nSap,
- pphFriNfc_LlcpTransportSocketConnectCb_t pConnect_RspCb,
- void* pContext)
-{
- NFCSTATUS status = NFCSTATUS_SUCCESS;
- uint8_t nLocalSap;
-
- /* Check for NULL pointers */
- if(pLlcpSocket == NULL || pConnect_RspCb == NULL || pContext == NULL)
- {
- status = PHNFCSTVAL(CID_FRI_NFC_LLCP_TRANSPORT, NFCSTATUS_INVALID_PARAMETER);
- }
- /* Test the port number value */
- else if(nSap<02 || nSap>63)
- {
- status = PHNFCSTVAL(CID_FRI_NFC_LLCP_TRANSPORT, NFCSTATUS_INVALID_PARAMETER);
- }
- /* Test if the socket is a connectionOriented socket */
- else if(pLlcpSocket->eSocket_Type != phFriNfc_LlcpTransport_eConnectionOriented)
- {
- status = PHNFCSTVAL(CID_FRI_NFC_LLCP_TRANSPORT, NFCSTATUS_INVALID_PARAMETER);
- }
- /* Test if the socket has a service name */
- else if(pLlcpSocket->sServiceName.length != 0)
- {
- status = PHNFCSTVAL(CID_FRI_NFC_LLCP_TRANSPORT, NFCSTATUS_INVALID_STATE);
- }
- /* Test if the socket is not in connecting or connected state*/
- else if(pLlcpSocket->eSocket_State != phFriNfc_LlcpTransportSocket_eSocketCreated && pLlcpSocket->eSocket_State != phFriNfc_LlcpTransportSocket_eSocketBound)
- {
- status = PHNFCSTVAL(CID_FRI_NFC_LLCP_TRANSPORT, NFCSTATUS_INVALID_STATE);
- }
- else
- {
- /* Implicit bind if socket is not already bound */
- if(pLlcpSocket->eSocket_State != phFriNfc_LlcpTransportSocket_eSocketBound)
- {
- /* Bind to a free sap */
- status = phFriNfc_LlcpTransport_GetFreeSap(pLlcpSocket->psTransport, NULL, &nLocalSap);
- if (status != NFCSTATUS_SUCCESS)
- {
- return status;
- }
- pLlcpSocket->socket_sSap = nLocalSap;
- }
-
- /* Test the SAP range for non SDP-advertised services */
- if(!IS_BETWEEN(pLlcpSocket->socket_sSap, PHFRINFC_LLCP_SAP_SDP_UNADVERTISED_FIRST, PHFRINFC_LLCP_SAP_NUMBER))
- {
- status = PHNFCSTVAL(CID_FRI_NFC_LLCP_TRANSPORT, NFCSTATUS_INVALID_PARAMETER);
- }
- else
- {
- status = phFriNfc_LlcpTransport_ConnectionOriented_Connect(pLlcpSocket,
- nSap,
- NULL,
- pConnect_RspCb,
- pContext);
- }
- }
-
- return status;
-}
-
-/**
-* \ingroup grp_fri_nfc
-* \brief Try to establish connection with a socket on a remote service, given its URI.
-*
-* This function tries to connect to a SAP designated by an URI. If the
-* socket is not bound to a local SAP, it is implicitly bound to a free SAP.
-*
-* \param[in] pLlcpSocket A pointer to a phFriNfc_LlcpTransport_Socket_t.
-* \param[in] psUri The URI corresponding to the destination SAP to connect to.
-* \param[in] pConnect_RspCb The callback to be called when the connection
-* operation is completed.
-* \param[in] pContext Upper layer context to be returned in
-* the callback.
-*
-* \retval NFCSTATUS_SUCCESS Operation successful.
-* \retval NFCSTATUS_INVALID_PARAMETER One or more of the supplied parameters
-* could not be properly interpreted.
-* \retval NFCSTATUS_PENDING Connection operation is in progress,
-* pConnect_RspCb will be called upon completion.
-* \retval NFCSTATUS_INVALID_STATE The socket is not in a valid state, or not of
-* a valid type to perform the requsted operation.
-* \retval NFCSTATUS_NOT_INITIALISED Indicates stack is not yet initialized.
-* \retval NFCSTATUS_SHUTDOWN Shutdown in progress.
-* \retval NFCSTATUS_FAILED Operation failed.
-*/
-NFCSTATUS phFriNfc_LlcpTransport_ConnectByUri(phFriNfc_LlcpTransport_Socket_t* pLlcpSocket,
- phNfc_sData_t* psUri,
- pphFriNfc_LlcpTransportSocketConnectCb_t pConnect_RspCb,
- void* pContext)
-{
- NFCSTATUS status = NFCSTATUS_SUCCESS;
- uint8_t nLocalSap;
-
- /* Check for NULL pointers */
- if(pLlcpSocket == NULL || pConnect_RspCb == NULL || pContext == NULL)
- {
- status = PHNFCSTVAL(CID_FRI_NFC_LLCP_TRANSPORT, NFCSTATUS_INVALID_PARAMETER);
- }
- /* Test if the socket is a connectionOriented socket */
- else if(pLlcpSocket->eSocket_Type != phFriNfc_LlcpTransport_eConnectionOriented)
- {
- status = PHNFCSTVAL(CID_FRI_NFC_LLCP_TRANSPORT, NFCSTATUS_INVALID_PARAMETER);
- }
- /* Test if the socket is not in connect pending or connected state*/
- else if(pLlcpSocket->eSocket_State == phFriNfc_LlcpTransportSocket_eSocketConnecting || pLlcpSocket->eSocket_State == phFriNfc_LlcpTransportSocket_eSocketConnected)
- {
- status = PHNFCSTVAL(CID_FRI_NFC_LLCP_TRANSPORT, NFCSTATUS_INVALID_PARAMETER);
- }
- /* Test the length of the SN */
- else if(psUri->length > PHFRINFC_LLCP_SN_MAX_LENGTH)
- {
- status = PHNFCSTVAL(CID_FRI_NFC_LLCP_TRANSPORT, NFCSTATUS_INVALID_PARAMETER);
- }
- else
- {
- /* Implicit bind if socket is not already bound */
- if(pLlcpSocket->eSocket_State != phFriNfc_LlcpTransportSocket_eSocketBound)
- {
- /* Bind to a free sap */
- status = phFriNfc_LlcpTransport_GetFreeSap(pLlcpSocket->psTransport, NULL, &nLocalSap);
- if (status != NFCSTATUS_SUCCESS)
- {
- return status;
- }
- pLlcpSocket->socket_sSap = nLocalSap;
- }
-
- /* Test the SAP range for non SDP-advertised services */
- if(!IS_BETWEEN(pLlcpSocket->socket_sSap, PHFRINFC_LLCP_SAP_SDP_UNADVERTISED_FIRST, PHFRINFC_LLCP_SAP_NUMBER))
- {
- status = PHNFCSTVAL(CID_FRI_NFC_LLCP_TRANSPORT, NFCSTATUS_INVALID_PARAMETER);
- }
- else
- {
- status = phFriNfc_LlcpTransport_ConnectionOriented_Connect(pLlcpSocket,
- PHFRINFC_LLCP_SAP_DEFAULT,
- psUri,
- pConnect_RspCb,
- pContext);
- }
- }
-
- return status;
-}
-
-/**
-* \ingroup grp_lib_nfc
-* \brief Disconnect a currently connected socket.
-*
-* This function initiates the disconnection of a previously connected socket.
-*
-* \param[in] pLlcpSocket A pointer to a phFriNfc_LlcpTransport_Socket_t.
-* \param[in] pDisconnect_RspCb The callback to be called when the
-* operation is completed.
-* \param[in] pContext Upper layer context to be returned in
-* the callback.
-*
-* \retval NFCSTATUS_SUCCESS Operation successful.
-* \retval NFCSTATUS_INVALID_PARAMETER One or more of the supplied parameters
-* could not be properly interpreted.
-* \retval NFCSTATUS_PENDING Disconnection operation is in progress,
-* pDisconnect_RspCb will be called upon completion.
-* \retval NFCSTATUS_INVALID_STATE The socket is not in a valid state, or not of
-* a valid type to perform the requsted operation.
-* \retval NFCSTATUS_NOT_INITIALISED Indicates stack is not yet initialized.
-* \retval NFCSTATUS_SHUTDOWN Shutdown in progress.
-* \retval NFCSTATUS_FAILED Operation failed.
-*/
-NFCSTATUS phFriNfc_LlcpTransport_Disconnect(phFriNfc_LlcpTransport_Socket_t* pLlcpSocket,
- pphLibNfc_LlcpSocketDisconnectCb_t pDisconnect_RspCb,
- void* pContext)
-{
- NFCSTATUS status = NFCSTATUS_SUCCESS;
-
- /* Check for NULL pointers */
- if(pLlcpSocket == NULL || pDisconnect_RspCb == NULL || pContext == NULL)
- {
- status = PHNFCSTVAL(CID_FRI_NFC_LLCP_TRANSPORT, NFCSTATUS_INVALID_PARAMETER);
- }
- /* Test if the socket is a connectionOriented socket */
- else if(pLlcpSocket->eSocket_Type != phFriNfc_LlcpTransport_eConnectionOriented)
- {
- status = PHNFCSTVAL(CID_FRI_NFC_LLCP_TRANSPORT, NFCSTATUS_INVALID_PARAMETER);
- }
- /* Test if the socket is connected state*/
- else if(pLlcpSocket->eSocket_State != phFriNfc_LlcpTransportSocket_eSocketConnected)
- {
- status = PHNFCSTVAL(CID_FRI_NFC_LLCP_TRANSPORT, NFCSTATUS_INVALID_PARAMETER);
- }
- else
- {
- status = phLibNfc_LlcpTransport_ConnectionOriented_Disconnect(pLlcpSocket,
- pDisconnect_RspCb,
- pContext);
- }
-
- return status;
-}
-
-/**
-* \ingroup grp_fri_nfc
-* \brief Send data on a socket.
-*
-* This function is used to write data on a socket. This function
-* can only be called on a connection-oriented socket which is already
-* in a connected state.
-*
-*
-* \param[in] pLlcpSocket A pointer to a phFriNfc_LlcpTransport_Socket_t.
-* \param[in] psBuffer The buffer containing the data to send.
-* \param[in] pSend_RspCb The callback to be called when the
-* operation is completed.
-* \param[in] pContext Upper layer context to be returned in
-* the callback.
-*
-* \retval NFCSTATUS_SUCCESS Operation successful.
-* \retval NFCSTATUS_INVALID_PARAMETER One or more of the supplied parameters
-* could not be properly interpreted.
-* \retval NFCSTATUS_PENDING Reception operation is in progress,
-* pSend_RspCb will be called upon completion.
-* \retval NFCSTATUS_INVALID_STATE The socket is not in a valid state, or not of
-* a valid type to perform the requsted operation.
-* \retval NFCSTATUS_FAILED Operation failed.
-*/
-NFCSTATUS phFriNfc_LlcpTransport_Send(phFriNfc_LlcpTransport_Socket_t* pLlcpSocket,
- phNfc_sData_t* psBuffer,
- pphFriNfc_LlcpTransportSocketSendCb_t pSend_RspCb,
- void* pContext)
-{
- NFCSTATUS status = NFCSTATUS_SUCCESS;
-
- /* Check for NULL pointers */
- if(pLlcpSocket == NULL || psBuffer == NULL || pSend_RspCb == NULL || pContext == NULL)
- {
- status = PHNFCSTVAL(CID_FRI_NFC_LLCP_TRANSPORT, NFCSTATUS_INVALID_PARAMETER);
- }
- /* Test if the socket is a connectionOriented socket */
- else if(pLlcpSocket->eSocket_Type != phFriNfc_LlcpTransport_eConnectionOriented)
- {
- status = PHNFCSTVAL(CID_FRI_NFC_LLCP_TRANSPORT, NFCSTATUS_INVALID_PARAMETER);
- }
- /* Test if the socket is in connected state */
- else if(pLlcpSocket->eSocket_State != phFriNfc_LlcpTransportSocket_eSocketConnected)
- {
- status = PHNFCSTVAL(CID_FRI_NFC_LLCP_TRANSPORT, NFCSTATUS_INVALID_STATE);
- }
- /* Test the length of the buffer */
- else if(psBuffer->length > pLlcpSocket->remoteMIU )
- {
- status = PHNFCSTVAL(CID_FRI_NFC_LLCP_TRANSPORT, NFCSTATUS_INVALID_PARAMETER);
- }
- /* Test if a send is pending */
- else if(pLlcpSocket->pfSocketSend_Cb != NULL)
- {
- status = PHNFCSTVAL(CID_FRI_NFC_LLCP_TRANSPORT, NFCSTATUS_REJECTED);
- }
- else
- {
- status = phFriNfc_LlcpTransport_ConnectionOriented_Send(pLlcpSocket,
- psBuffer,
- pSend_RspCb,
- pContext);
- }
-
- return status;
-}
-
- /**
-* \ingroup grp_fri_nfc
-* \brief Read data on a socket.
-*
-* This function is used to read data from a socket. It reads at most the
-* size of the reception buffer, but can also return less bytes if less bytes
-* are available. If no data is available, the function will be pending until
-* more data comes, and the response will be sent by the callback. This function
-* can only be called on a connection-oriented socket.
-*
-*
-* \param[in] pLlcpSocket A pointer to a phFriNfc_LlcpTransport_Socket_t.
-* \param[in] psBuffer The buffer receiving the data.
-* \param[in] pRecv_RspCb The callback to be called when the
-* operation is completed.
-* \param[in] pContext Upper layer context to be returned in
-* the callback.
-*
-* \retval NFCSTATUS_SUCCESS Operation successful.
-* \retval NFCSTATUS_INVALID_PARAMETER One or more of the supplied parameters
-* could not be properly interpreted.
-* \retval NFCSTATUS_PENDING Reception operation is in progress,
-* pRecv_RspCb will be called upon completion.
-* \retval NFCSTATUS_INVALID_STATE The socket is not in a valid state, or not of
-* a valid type to perform the requsted operation.
-* \retval NFCSTATUS_FAILED Operation failed.
-*/
-NFCSTATUS phFriNfc_LlcpTransport_Recv( phFriNfc_LlcpTransport_Socket_t* pLlcpSocket,
- phNfc_sData_t* psBuffer,
- pphFriNfc_LlcpTransportSocketRecvCb_t pRecv_RspCb,
- void* pContext)
-{
- NFCSTATUS status = NFCSTATUS_SUCCESS;
-
- /* Check for NULL pointers */
- if(pLlcpSocket == NULL || psBuffer == NULL || pRecv_RspCb == NULL || pContext == NULL)
- {
- status = PHNFCSTVAL(CID_FRI_NFC_LLCP_TRANSPORT, NFCSTATUS_INVALID_PARAMETER);
- }
- /* Test if the socket is a connectionOriented socket */
- else if(pLlcpSocket->eSocket_Type != phFriNfc_LlcpTransport_eConnectionOriented)
- {
- status = PHNFCSTVAL(CID_FRI_NFC_LLCP_TRANSPORT, NFCSTATUS_INVALID_PARAMETER);
- }
- /* Test if the socket is in connected state */
- else if(pLlcpSocket->eSocket_State == phFriNfc_LlcpTransportSocket_eSocketDefault)
- {
- status = PHNFCSTVAL(CID_FRI_NFC_LLCP_TRANSPORT, NFCSTATUS_INVALID_PARAMETER);
- }
- /* Test if a receive is pending */
- else if(pLlcpSocket->bSocketRecvPending == TRUE)
- {
- status = PHNFCSTVAL(CID_FRI_NFC_LLCP_TRANSPORT, NFCSTATUS_REJECTED);
- }
- else
- {
- status = phFriNfc_LlcpTransport_ConnectionOriented_Recv(pLlcpSocket,
- psBuffer,
- pRecv_RspCb,
- pContext);
- }
-
- return status;
-}
-
-/*****************************************/
-/* ConnectionLess */
-/*****************************************/
-
-/**
-* \ingroup grp_fri_nfc
-* \brief Send data on a socket to a given destination SAP.
-*
-* This function is used to write data on a socket to a given destination SAP.
-* This function can only be called on a connectionless socket.
-*
-*
-* \param[in] pLlcpSocket A pointer to a LlcpSocket created.
-* \param[in] nSap The destination SAP.
-* \param[in] psBuffer The buffer containing the data to send.
-* \param[in] pSend_RspCb The callback to be called when the
-* operation is completed.
-* \param[in] pContext Upper layer context to be returned in
-* the callback.
-*
-* \retval NFCSTATUS_SUCCESS Operation successful.
-* \retval NFCSTATUS_INVALID_PARAMETER One or more of the supplied parameters
-* could not be properly interpreted.
-* \retval NFCSTATUS_PENDING Reception operation is in progress,
-* pSend_RspCb will be called upon completion.
-* \retval NFCSTATUS_INVALID_STATE The socket is not in a valid state, or not of
-* a valid type to perform the requsted operation.
-* \retval NFCSTATUS_FAILED Operation failed.
-*/
-NFCSTATUS phFriNfc_LlcpTransport_SendTo( phFriNfc_LlcpTransport_Socket_t *pLlcpSocket,
- uint8_t nSap,
- phNfc_sData_t *psBuffer,
- pphFriNfc_LlcpTransportSocketSendCb_t pSend_RspCb,
- void* pContext)
-{
- NFCSTATUS status = NFCSTATUS_SUCCESS;
- phFriNfc_Llcp_sLinkParameters_t LlcpRemoteLinkParamInfo;
-
- if(pLlcpSocket == NULL || psBuffer == NULL || pSend_RspCb == NULL || pContext == NULL)
- {
- status = PHNFCSTVAL(CID_FRI_NFC_LLCP_TRANSPORT, NFCSTATUS_INVALID_PARAMETER);
- }
- /* Test the port number value */
- else if(nSap<2 || nSap>63)
- {
- status = PHNFCSTVAL(CID_FRI_NFC_LLCP_TRANSPORT, NFCSTATUS_INVALID_PARAMETER);
- }
- /* Test if the socket is a connectionless socket */
- else if(pLlcpSocket->eSocket_Type != phFriNfc_LlcpTransport_eConnectionLess)
- {
- status = PHNFCSTVAL(CID_FRI_NFC_LLCP_TRANSPORT, NFCSTATUS_INVALID_PARAMETER);
- }
- /* Test if the socket is in an updated state */
- else if(pLlcpSocket->eSocket_State != phFriNfc_LlcpTransportSocket_eSocketBound)
- {
- status = PHNFCSTVAL(CID_FRI_NFC_LLCP_TRANSPORT, NFCSTATUS_INVALID_STATE);
- }
- /* Test if a send is pending */
- else if(pLlcpSocket->pfSocketSend_Cb != NULL)
- {
- status = PHNFCSTVAL(CID_FRI_NFC_LLCP_TRANSPORT, NFCSTATUS_REJECTED);
- }
- else
- {
- /* Get the local parameters of the LLCP Link */
- status = phFriNfc_Llcp_GetRemoteInfo(pLlcpSocket->psTransport->pLlcp,&LlcpRemoteLinkParamInfo);
- if(status != NFCSTATUS_SUCCESS)
- {
- status = PHNFCSTVAL(CID_FRI_NFC_LLCP_TRANSPORT, NFCSTATUS_FAILED);
- }
- /* Test the length of the socket buffer for ConnectionLess mode*/
- else if(psBuffer->length > LlcpRemoteLinkParamInfo.miu)
- {
- status = PHNFCSTVAL(CID_FRI_NFC_LLCP_TRANSPORT, NFCSTATUS_INVALID_PARAMETER);
- }
- /* Test if the link is in error state */
- else if(pLlcpSocket->psTransport->LinkStatusError)
- {
- status = PHNFCSTVAL(CID_FRI_NFC_LLCP_TRANSPORT, NFCSTATUS_REJECTED);
- }
- else
- {
- status = phFriNfc_LlcpTransport_Connectionless_SendTo(pLlcpSocket,
- nSap,
- psBuffer,
- pSend_RspCb,
- pContext);
- }
- }
-
- return status;
-}
-
-
- /**
-* \ingroup grp_lib_nfc
-* \brief Read data on a socket and get the source SAP.
-*
-* This function is the same as phLibNfc_Llcp_Recv, except that the callback includes
-* the source SAP. This functions can only be called on a connectionless socket.
-*
-*
-* \param[in] pLlcpSocket A pointer to a LlcpSocket created.
-* \param[in] psBuffer The buffer receiving the data.
-* \param[in] pRecv_RspCb The callback to be called when the
-* operation is completed.
-* \param[in] pContext Upper layer context to be returned in
-* the callback.
-*
-* \retval NFCSTATUS_SUCCESS Operation successful.
-* \retval NFCSTATUS_INVALID_PARAMETER One or more of the supplied parameters
-* could not be properly interpreted.
-* \retval NFCSTATUS_PENDING Reception operation is in progress,
-* pRecv_RspCb will be called upon completion.
-* \retval NFCSTATUS_INVALID_STATE The socket is not in a valid state, or not of
-* a valid type to perform the requsted operation.
-* \retval NFCSTATUS_NOT_INITIALISED Indicates stack is not yet initialized.
-* \retval NFCSTATUS_SHUTDOWN Shutdown in progress.
-* \retval NFCSTATUS_FAILED Operation failed.
-*/
-NFCSTATUS phFriNfc_LlcpTransport_RecvFrom( phFriNfc_LlcpTransport_Socket_t *pLlcpSocket,
- phNfc_sData_t* psBuffer,
- pphFriNfc_LlcpTransportSocketRecvFromCb_t pRecv_Cb,
- void* pContext)
-{
- NFCSTATUS status = NFCSTATUS_SUCCESS;
- if(pLlcpSocket == NULL || psBuffer == NULL || pRecv_Cb == NULL || pContext == NULL)
- {
- status = PHNFCSTVAL(CID_FRI_NFC_LLCP_TRANSPORT, NFCSTATUS_INVALID_PARAMETER);
- }
- /* Test if the socket is a connectionless socket */
- else if(pLlcpSocket->eSocket_Type != phFriNfc_LlcpTransport_eConnectionLess)
- {
- status = PHNFCSTVAL(CID_FRI_NFC_LLCP_TRANSPORT, NFCSTATUS_INVALID_PARAMETER);
- }
- /* Test if the socket is in an updated state */
- else if(pLlcpSocket->eSocket_State != phFriNfc_LlcpTransportSocket_eSocketBound)
- {
- status = PHNFCSTVAL(CID_FRI_NFC_LLCP_TRANSPORT, NFCSTATUS_INVALID_STATE);
- }
- else
- {
- if(pLlcpSocket->bSocketRecvPending)
- {
- status = PHNFCSTVAL(CID_FRI_NFC_LLCP_TRANSPORT, NFCSTATUS_REJECTED);
- }
- else
- {
- status = phLibNfc_LlcpTransport_Connectionless_RecvFrom(pLlcpSocket,
- psBuffer,
- pRecv_Cb,
- pContext);
- }
- }
-
- return status;
-}
diff --git a/libnfc-nxp/phFriNfc_LlcpTransport.h b/libnfc-nxp/phFriNfc_LlcpTransport.h
deleted file mode 100644
index 2f83439..0000000
--- a/libnfc-nxp/phFriNfc_LlcpTransport.h
+++ /dev/null
@@ -1,794 +0,0 @@
-/*
- * Copyright (C) 2010 NXP Semiconductors
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-/**
- * \file phFriNfc_LlcpTransport.h
- * \brief
- *
- * Project: NFC-FRI
- *
- */
-
-#ifndef PHFRINFC_LLCP_TRANSPORT_H
-#define PHFRINFC_LLCP_TRANSPORT_H
-#include
-#include
-#include
-#include
-#include
-#include
-#ifdef ANDROID
-#include
-#include
-#endif
-
-
-typedef uint32_t phFriNfc_Socket_Handle;
-
-/**
- * \ingroup grp_fri_nfc_llcp_mac
- * \brief Declaration of a TRANSPORT type
- */
-struct phFriNfc_LlcpTransport;
-typedef struct phFriNfc_LlcpTransport phFriNfc_LlcpTransport_t;
-
-struct phFriNfc_LlcpTransport_Socket;
-typedef struct phFriNfc_LlcpTransport_Socket phFriNfc_LlcpTransport_Socket_t;
-
-struct phFriNfc_Llcp_CachedServiceName;
-typedef struct phFriNfc_Llcp_CachedServiceName phFriNfc_Llcp_CachedServiceName_t;
-
-/*========== ENUMERATES ===========*/
-
-/* Enum reperesents the different LLCP Link status*/
-typedef enum phFriNfc_LlcpTransportSocket_eSocketState
-{
- phFriNfc_LlcpTransportSocket_eSocketDefault,
- phFriNfc_LlcpTransportSocket_eSocketCreated,
- phFriNfc_LlcpTransportSocket_eSocketBound,
- phFriNfc_LlcpTransportSocket_eSocketRegistered,
- phFriNfc_LlcpTransportSocket_eSocketConnected,
- phFriNfc_LlcpTransportSocket_eSocketConnecting,
- phFriNfc_LlcpTransportSocket_eSocketAccepted,
- phFriNfc_LlcpTransportSocket_eSocketDisconnected,
- phFriNfc_LlcpTransportSocket_eSocketDisconnecting,
- phFriNfc_LlcpTransportSocket_eSocketRejected,
-}phFriNfc_LlcpTransportSocket_eSocketState_t;
-
-
-
-/*========== CALLBACKS ===========*/
-
-/**
-*\ingroup grp_fri_nfc
-*
-* \brief LLCP socket error notification callback definition
-*/
-typedef void (*pphFriNfc_LlcpTransportSocketErrCb_t) ( void* pContext,
- uint8_t nErrCode);
-
-
-/**
-*\ingroup grp_fri_nfc
-*
-* \brief LLCP socket listen callback definition
-*/
-typedef void (*pphFriNfc_LlcpTransportSocketListenCb_t) (void* pContext,
- phFriNfc_LlcpTransport_Socket_t *IncomingSocket);
-
-/**
-*\ingroup grp_fri_nfc
-*
-* \brief LLCP socket connect callback definition
-*/
-typedef void (*pphFriNfc_LlcpTransportSocketConnectCb_t) ( void* pContext,
- uint8_t nErrCode,
- NFCSTATUS status);
-
-/**
-*\ingroup grp_fri_nfc
-*
-* \brief LLCP socket disconnect callback definition
-*/
-typedef void (*pphFriNfc_LlcpTransportSocketDisconnectCb_t) (void* pContext,
- NFCSTATUS status);
-
-/**
-*\ingroup grp_fri_nfc
-*
-* \brief LLCP socket accept callback definition
-*/
-typedef void (*pphFriNfc_LlcpTransportSocketAcceptCb_t) (void* pContext,
- NFCSTATUS status);
-
-/**
-*\ingroup grp_fri_nfc
-*
-* \brief LLCP socket reject callback definition
-*/
-typedef void (*pphFriNfc_LlcpTransportSocketRejectCb_t) (void* pContext,
- NFCSTATUS status);
-
-/**
-*\ingroup grp_fri_nfc
-*
-* \brief LLCP socket reception callback definition
-*/
-typedef void (*pphFriNfc_LlcpTransportSocketRecvCb_t) (void* pContext,
- NFCSTATUS status);
-
-/**
-*\ingroup grp_fri_nfc
-*
-* \brief LLCP socket reception with SSAP callback definition
-*/
-typedef void (*pphFriNfc_LlcpTransportSocketRecvFromCb_t) (void* pContext,
- uint8_t ssap,
- NFCSTATUS status);
-
-/**
-*\ingroup grp_fri_nfc
-*
-* \brief LLCP socket emission callback definition
-*/
-typedef void (*pphFriNfc_LlcpTransportSocketSendCb_t) (void* pContext,
- NFCSTATUS status);
-
-
-/*========== STRUCTURES ===========*/
-/**
- * \ingroup grp_fri_nfc_llcp_mac
- * \brief Declaration of a SOCKET type
- */
-struct phFriNfc_LlcpTransport_Socket
-{
- phFriNfc_LlcpTransportSocket_eSocketState_t eSocket_State;
- phFriNfc_LlcpTransport_eSocketType_t eSocket_Type;
- phFriNfc_LlcpTransport_sSocketOptions_t sSocketOption;
- pphFriNfc_LlcpTransportSocketErrCb_t pSocketErrCb;
-
- /* Remote and local socket info */
- uint8_t socket_sSap;
- uint8_t socket_dSap;
- // TODO: copy service name (could be deallocated by upper layer)
- phNfc_sData_t sServiceName;
- uint8_t remoteRW;
- uint8_t localRW;
- uint16_t remoteMIU;
- uint16_t localMIUX;
- uint8_t index;
-
- /* SDP related fields */
- uint8_t nTid;
-
- /* Information Flags */
- bool_t bSocketRecvPending;
- bool_t bSocketSendPending;
- bool_t bSocketListenPending;
- bool_t bSocketDiscPending;
- bool_t bSocketConnectPending;
- bool_t bSocketAcceptPending;
- bool_t bSocketRRPending;
- bool_t bSocketRNRPending;
-
- /* Buffers */
- phNfc_sData_t sSocketSendBuffer;
- phNfc_sData_t sSocketLinearBuffer;
- phNfc_sData_t* sSocketRecvBuffer;
- uint32_t *receivedLength;
- uint32_t bufferLinearLength;
- uint32_t bufferSendMaxLength;
- uint32_t bufferRwMaxLength;
- bool_t ReceiverBusyCondition;
- bool_t RemoteBusyConditionInfo;
- UTIL_FIFO_BUFFER sCyclicFifoBuffer;
- uint32_t indexRwRead;
- uint32_t indexRwWrite;
-
- /* Construction Frame */
- phFriNfc_Llcp_sPacketHeader_t sLlcpHeader;
- phFriNfc_Llcp_sPacketSequence_t sSequence;
- uint8_t socket_VS;
- uint8_t socket_VSA;
- uint8_t socket_VR;
- uint8_t socket_VRA;
-
- /* Callbacks */
- pphFriNfc_LlcpTransportSocketAcceptCb_t pfSocketAccept_Cb;
- pphFriNfc_LlcpTransportSocketSendCb_t pfSocketSend_Cb;
- pphFriNfc_LlcpTransportSocketRecvFromCb_t pfSocketRecvFrom_Cb;
- pphFriNfc_LlcpTransportSocketRecvCb_t pfSocketRecv_Cb;
- pphFriNfc_LlcpTransportSocketListenCb_t pfSocketListen_Cb;
- pphFriNfc_LlcpTransportSocketConnectCb_t pfSocketConnect_Cb;
- pphFriNfc_LlcpTransportSocketDisconnectCb_t pfSocketDisconnect_Cb;
-
- /* Table of PHFRINFC_LLCP_RW_MAX Receive Windows Buffers */
- phNfc_sData_t sSocketRwBufferTable[PHFRINFC_LLCP_RW_MAX];
-
- /* Pointer a the socket table */
- phFriNfc_LlcpTransport_t *psTransport;
- /* Context */
- void *pListenContext;
- void *pAcceptContext;
- void *pRejectContext;
- void *pConnectContext;
- void *pDisconnectContext;
- void *pSendContext;
- void *pRecvContext;
- void *pContext;
-};
-
-/**
- * \ingroup grp_fri_nfc_llcp_mac
- * \brief TODO
- */
-struct phFriNfc_Llcp_CachedServiceName
-{
- phNfc_sData_t sServiceName;
- uint8_t nSap;
-};
-
-
-/**
- * \ingroup grp_fri_nfc_llcp_mac
- * \brief Declaration of a TRANSPORT Type with a table of PHFRINFC_LLCP_NB_SOCKET_DEFAULT sockets
- * and a pointer a Llcp layer
- */
-struct phFriNfc_LlcpTransport
-{
- phFriNfc_LlcpTransport_Socket_t pSocketTable[PHFRINFC_LLCP_NB_SOCKET_MAX];
- phFriNfc_Llcp_CachedServiceName_t pCachedServiceNames[PHFRINFC_LLCP_SDP_ADVERTISED_NB];
- phFriNfc_Llcp_t *pLlcp;
- pthread_mutex_t mutex;
- bool_t bSendPending;
- bool_t bRecvPending;
- bool_t bDmPending;
- bool_t bFrmrPending;
-
- phFriNfc_Llcp_LinkSend_CB_t pfLinkSendCb;
- void *pLinkSendContext;
-
- uint8_t socketIndex;
-
- /**< Info field of pending FRMR packet*/
- uint8_t FrmrInfoBuffer[4];
- phFriNfc_Llcp_sPacketHeader_t sLlcpHeader;
- phFriNfc_Llcp_sPacketSequence_t sSequence;
-
- /**< Info field of pending DM packet*/
- phFriNfc_Llcp_sPacketHeader_t sDmHeader;
- phNfc_sData_t sDmPayload;
- uint8_t DmInfoBuffer[3];
-
- uint8_t LinkStatusError;
-
- /**< Service discovery related infos */
- phNfc_sData_t *psDiscoveryServiceNameList;
- uint8_t *pnDiscoverySapList;
- uint8_t nDiscoveryListSize;
- uint8_t nDiscoveryReqOffset;
- uint8_t nDiscoveryResOffset;
-
- uint8_t nDiscoveryResTidList[PHFRINFC_LLCP_SNL_RESPONSE_MAX];
- uint8_t nDiscoveryResSapList[PHFRINFC_LLCP_SNL_RESPONSE_MAX];
- uint8_t nDiscoveryResListSize;
-
- uint8_t pDiscoveryBuffer[PHFRINFC_LLCP_MIU_DEFAULT];
- pphFriNfc_Cr_t pfDiscover_Cb;
- void *pDiscoverContext;
-
-};
-
-/*
-################################################################################
-********************** TRANSPORT Interface Function Prototype *****************
-################################################################################
-*/
-
-bool_t testAndSetSendPending(phFriNfc_LlcpTransport_t* transport);
-
-void clearSendPending(phFriNfc_LlcpTransport_t* transport);
-
- /**
-* \ingroup grp_fri_nfc
-* \brief Create a socket on a LLCP-connected device.
-*
-*/
-NFCSTATUS phFriNfc_LlcpTransport_Reset (phFriNfc_LlcpTransport_t *pLlcpSocketTable,
- phFriNfc_Llcp_t *pLlcp);
-
-
-/**
-* \ingroup grp_fri_nfc
-* \brief Close all existing sockets.
-*
-*/
-NFCSTATUS phFriNfc_LlcpTransport_CloseAll (phFriNfc_LlcpTransport_t *pLlcpSocketTable);
-
-
-/**
-* \ingroup grp_fri_nfc
-* \brief Used by transport layers to request a send on link layer.
-*
-*/
-NFCSTATUS phFriNfc_LlcpTransport_LinkSend( phFriNfc_LlcpTransport_t *LlcpTransport,
- phFriNfc_Llcp_sPacketHeader_t *psHeader,
- phFriNfc_Llcp_sPacketSequence_t *psSequence,
- phNfc_sData_t *psInfo,
- phFriNfc_Llcp_LinkSend_CB_t pfSend_CB,
- uint8_t socketIndex,
- void *pContext );
-
-
-/**
-* \ingroup grp_fri_nfc
-* \brief Used by transport layers to send a DM frame.
-*
-* This function is only used when the DM is not related to a DISC on a socket.
-*/
-NFCSTATUS phFriNfc_LlcpTransport_SendDisconnectMode(phFriNfc_LlcpTransport_t* psTransport,
- uint8_t dsap,
- uint8_t ssap,
- uint8_t dmOpCode);
-
-/**
-* \ingroup grp_fri_nfc
-* \brief Used by transport layers to send a FRMR frame.
-*
-*/
-NFCSTATUS phFriNfc_LlcpTransport_SendFrameReject(phFriNfc_LlcpTransport_t *psTransport,
- uint8_t dsap,
- uint8_t rejectedPTYPE,
- uint8_t ssap,
- phFriNfc_Llcp_sPacketSequence_t* sLlcpSequence,
- uint8_t WFlag,
- uint8_t IFlag,
- uint8_t RFlag,
- uint8_t SFlag,
- uint8_t vs,
- uint8_t vsa,
- uint8_t vr,
- uint8_t vra);
-
-/*!
-* \ingroup grp_fri_nfc
-* \brief Discover remote services SAP using SDP protocol.
- */
-NFCSTATUS phFriNfc_LlcpTransport_DiscoverServices( phFriNfc_LlcpTransport_t *pLlcpTransport,
- phNfc_sData_t *psServiceNameList,
- uint8_t *pnSapList,
- uint8_t nListSize,
- pphFriNfc_Cr_t pDiscover_Cb,
- void *pContext );
-
-/**
-* \ingroup grp_lib_nfc
-* \brief Get the local options of a socket.
-*
-* This function returns the local options (maximum packet size and receive window size) used
-* for a given connection-oriented socket. This function shall not be used with connectionless
-* sockets.
-*
-* \param[out] pLlcpSocket A pointer to a phFriNfc_LlcpTransport_Socket_t.
-* \param[in] psLocalOptions A pointer to be filled with the local options of the socket.
-*
-* \retval NFCSTATUS_SUCCESS Operation successful.
-* \retval NFCSTATUS_INVALID_PARAMETER One or more of the supplied parameters
-* could not be properly interpreted.
-* \retval NFCSTATUS_INVALID_STATE The socket is not in a valid state, or not of
-* a valid type to perform the requsted operation.
-* \retval NFCSTATUS_NOT_INITIALISED Indicates stack is not yet initialized.
-* \retval NFCSTATUS_SHUTDOWN Shutdown in progress.
-* \retval NFCSTATUS_FAILED Operation failed.
-*/
-NFCSTATUS phFriNfc_LlcpTransport_SocketGetLocalOptions(phFriNfc_LlcpTransport_Socket_t *pLlcpSocket,
- phLibNfc_Llcp_sSocketOptions_t *psLocalOptions);
-
-
-/**
-* \ingroup grp_lib_nfc
-* \brief Get the local options of a socket.
-*
-* This function returns the remote options (maximum packet size and receive window size) used
-* for a given connection-oriented socket. This function shall not be used with connectionless
-* sockets.
-*
-* \param[out] pLlcpSocket A pointer to a phFriNfc_LlcpTransport_Socket_t.
-* \param[in] psRemoteOptions A pointer to be filled with the remote options of the socket.
-*
-* \retval NFCSTATUS_SUCCESS Operation successful.
-* \retval NFCSTATUS_INVALID_PARAMETER One or more of the supplied parameters
-* could not be properly interpreted.
-* \retval NFCSTATUS_INVALID_STATE The socket is not in a valid state, or not of
-* a valid type to perform the requsted operation.
-* \retval NFCSTATUS_NOT_INITIALISED Indicates stack is not yet initialized.
-* \retval NFCSTATUS_SHUTDOWN Shutdown in progress.
-* \retval NFCSTATUS_FAILED Operation failed.
-*/
-NFCSTATUS phFriNfc_LlcpTransport_SocketGetRemoteOptions(phFriNfc_LlcpTransport_Socket_t* pLlcpSocket,
- phLibNfc_Llcp_sSocketOptions_t* psRemoteOptions);
-
-
- /**
-* \ingroup grp_fri_nfc
-* \brief Create a socket on a LLCP-connected device.
-*
-* This function creates a socket for a given LLCP link. Sockets can be of two types :
-* connection-oriented and connectionless. If the socket is connection-oriented, the caller
-* must provide a working buffer to the socket in order to handle incoming data. This buffer
-* must be large enough to fit the receive window (RW * MIU), the remaining space being
-* used as a linear buffer to store incoming data as a stream. Data will be readable later
-* using the phLibNfc_LlcpTransport_Recv function.
-* The options and working buffer are not required if the socket is used as a listening socket,
-* since it cannot be directly used for communication.
-*
-* \param[in] pLlcpSocketTable A pointer to a table of PHFRINFC_LLCP_NB_SOCKET_DEFAULT sockets.
-* \param[in] eType The socket type.
-* \param[in] psOptions The options to be used with the socket.
-* \param[in] psWorkingBuffer A working buffer to be used by the library.
-* \param[out] pLlcpSocket A pointer to a socket pointer to be filled with a
- socket found on the socket table.
-* \param[in] pErr_Cb The callback to be called each time the socket
-* is in error.
-* \param[in] pContext Upper layer context to be returned in the callback.
-*
-* \retval NFCSTATUS_SUCCESS Operation successful.
-* \retval NFCSTATUS_INVALID_PARAMETER One or more of the supplied parameters
-* could not be properly interpreted.
-* \retval NFCSTATUS_BUFFER_TOO_SMALL The working buffer is too small for the MIU and RW
-* declared in the options.
-* \retval NFCSTATUS_INSUFFICIENT_RESOURCES No more socket handle available.
-* \retval NFCSTATUS_FAILED Operation failed.
-* */
-NFCSTATUS phFriNfc_LlcpTransport_Socket(phFriNfc_LlcpTransport_t *pLlcpSocketTable,
- phFriNfc_LlcpTransport_eSocketType_t eType,
- phFriNfc_LlcpTransport_sSocketOptions_t* psOptions,
- phNfc_sData_t* psWorkingBuffer,
- phFriNfc_LlcpTransport_Socket_t **pLlcpSocket,
- pphFriNfc_LlcpTransportSocketErrCb_t pErr_Cb,
- void* pContext);
-
-/**
-* \ingroup grp_fri_nfc
-* \brief Close a socket on a LLCP-connected device.
-*
-* This function closes a LLCP socket previously created using phFriNfc_LlcpTransport_Socket.
-* If the socket was connected, it is first disconnected, and then closed.
-*
-* \param[in] pLlcpSocket A pointer to a phFriNfc_LlcpTransport_Socket_t.
-
-* \retval NFCSTATUS_SUCCESS Operation successful.
-* \retval NFCSTATUS_INVALID_PARAMETER One or more of the supplied parameters
-* could not be properly interpreted.
-* \retval NFCSTATUS_FAILED Operation failed.
-*/
-NFCSTATUS phFriNfc_LlcpTransport_Close(phFriNfc_LlcpTransport_Socket_t* pLlcpSocket);
-
-
-/**
-* \ingroup grp_fri_nfc
-* \brief Bind a socket to a local SAP.
-*
-* This function binds the socket to a local Service Access Point.
-*
-* \param[out] pLlcpSocket A pointer to a phFriNfc_LlcpTransport_Socket_t.
-* \param[in] pConfigInfo A port number for a specific socket
-* \param TODO
-*
-* \retval NFCSTATUS_SUCCESS Operation successful.
-* \retval NFCSTATUS_INVALID_PARAMETER One or more of the supplied parameters
-* could not be properly interpreted.
-* \retval NFCSTATUS_INVALID_STATE The socket is not in a valid state, or not of
-* a valid type to perform the requsted operation.
-* \retval NFCSTATUS_ALREADY_REGISTERED The selected SAP is already bound to another
- socket.
-* \retval NFCSTATUS_FAILED Operation failed.
-*/
-NFCSTATUS phFriNfc_LlcpTransport_Bind(phFriNfc_LlcpTransport_Socket_t *pLlcpSocket,
- uint8_t nSap,
- phNfc_sData_t *psServiceName);
-
-/**
-* \ingroup grp_fri_nfc
-* \brief Listen for incoming connection requests on a socket.
-*
-* This function switches a socket into a listening state and registers a callback on
-* incoming connection requests. In this state, the socket is not able to communicate
-* directly. The listening state is only available for connection-oriented sockets
-* which are still not connected. The socket keeps listening until it is closed, and
-* thus can trigger several times the pListen_Cb callback.
-*
-*
-* \param[in] pLlcpSocket A pointer to a phFriNfc_LlcpTransport_Socket_t.
-* \param[in] pListen_Cb The callback to be called each time the
-* socket receive a connection request.
-* \param[in] pContext Upper layer context to be returned in
-* the callback.
-*
-* \retval NFCSTATUS_SUCCESS Operation successful.
-* \retval NFCSTATUS_INVALID_PARAMETER One or more of the supplied parameters
-* could not be properly interpreted.
-* \retval NFCSTATUS_INVALID_STATE The socket is not in a valid state to switch
-* to listening state.
-* \retval NFCSTATUS_FAILED Operation failed.
-*/
-NFCSTATUS phFriNfc_LlcpTransport_Listen(phFriNfc_LlcpTransport_Socket_t* pLlcpSocket,
- pphFriNfc_LlcpTransportSocketListenCb_t pListen_Cb,
- void* pContext);
-
-/**
-* \ingroup grp_fri_nfc
-* \brief Accept an incoming connection request for a socket.
-*
-* This functions allows the client to accept an incoming connection request.
-* It must be used with the socket provided within the listen callback. The socket
-* is implicitly switched to the connected state when the function is called.
-*
-* \param[in] pLlcpSocket A pointer to a phFriNfc_LlcpTransport_Socket_t.
-* \param[in] psOptions The options to be used with the socket.
-* \param[in] psWorkingBuffer A working buffer to be used by the library.
-* \param[in] pErr_Cb The callback to be called each time the accepted socket
-* is in error.
-* \param[in] pAccept_RspCb The callback to be called when the Accept operation is completed
-* \param[in] pContext Upper layer context to be returned in the callback.
-*
-* \retval NFCSTATUS_SUCCESS Operation successful.
-* \retval NFCSTATUS_INVALID_PARAMETER One or more of the supplied parameters
-* could not be properly interpreted.
-* \retval NFCSTATUS_BUFFER_TOO_SMALL The working buffer is too small for the MIU and RW
-* declared in the options.
-* \retval NFCSTATUS_FAILED Operation failed.
-*/
-NFCSTATUS phFriNfc_LlcpTransport_Accept(phFriNfc_LlcpTransport_Socket_t* pLlcpSocket,
- phFriNfc_LlcpTransport_sSocketOptions_t* psOptions,
- phNfc_sData_t* psWorkingBuffer,
- pphFriNfc_LlcpTransportSocketErrCb_t pErr_Cb,
- pphFriNfc_LlcpTransportSocketAcceptCb_t pAccept_RspCb,
- void* pContext);
-
- /**
-* \ingroup grp_fri_nfc
-* \brief Reject an incoming connection request for a socket.
-*
-* This functions allows the client to reject an incoming connection request.
-* It must be used with the socket provided within the listen callback. The socket
-* is implicitly closed when the function is called.
-*
-* \param[in] pLlcpSocket A pointer to a phFriNfc_LlcpTransport_Socket_t.
-* \param[in] pReject_RspCb The callback to be called when the Reject operation is completed
-* \param[in] pContext Upper layer context to be returned in the callback.
-*
-* \retval NFCSTATUS_SUCCESS Operation successful.
-* \retval NFCSTATUS_INVALID_PARAMETER One or more of the supplied parameters
-* could not be properly interpreted.
-* \retval NFCSTATUS_FAILED Operation failed.
-*/
-NFCSTATUS phFriNfc_LlcpTransport_Reject( phFriNfc_LlcpTransport_Socket_t* pLlcpSocket,
- pphFriNfc_LlcpTransportSocketRejectCb_t pReject_RspCb,
- void *pContext);
-/**
-* \ingroup grp_fri_nfc
-* \brief Try to establish connection with a socket on a remote SAP.
-*
-* This function tries to connect to a given SAP on the remote peer. If the
-* socket is not bound to a local SAP, it is implicitly bound to a free SAP.
-*
-* \param[in] pLlcpSocket A pointer to a phFriNfc_LlcpTransport_Socket_t.
-* \param[in] nSap The destination SAP to connect to.
-* \param[in] pConnect_RspCb The callback to be called when the connection
-* operation is completed.
-* \param[in] pContext Upper layer context to be returned in
-* the callback.
-*
-* \retval NFCSTATUS_SUCCESS Operation successful.
-* \retval NFCSTATUS_INVALID_PARAMETER One or more of the supplied parameters
-* could not be properly interpreted.
-* \retval NFCSTATUS_PENDING Connection operation is in progress,
-* pConnect_RspCb will be called upon completion.
-* \retval NFCSTATUS_INVALID_STATE The socket is not in a valid state, or not of
-* a valid type to perform the requsted operation.
-* \retval NFCSTATUS_FAILED Operation failed.
-*/
-NFCSTATUS phFriNfc_LlcpTransport_Connect( phFriNfc_LlcpTransport_Socket_t* pLlcpSocket,
- uint8_t nSap,
- pphFriNfc_LlcpTransportSocketConnectCb_t pConnect_RspCb,
- void* pContext);
-
-/**
-* \ingroup grp_fri_nfc
-* \brief Try to establish connection with a socket on a remote service, given its URI.
-*
-* This function tries to connect to a SAP designated by an URI. If the
-* socket is not bound to a local SAP, it is implicitly bound to a free SAP.
-*
-* \param[in] pLlcpSocket A pointer to a phFriNfc_LlcpTransport_Socket_t.
-* \param[in] psUri The URI corresponding to the destination SAP to connect to.
-* \param[in] pConnect_RspCb The callback to be called when the connection
-* operation is completed.
-* \param[in] pContext Upper layer context to be returned in
-* the callback.
-*
-* \retval NFCSTATUS_SUCCESS Operation successful.
-* \retval NFCSTATUS_INVALID_PARAMETER One or more of the supplied parameters
-* could not be properly interpreted.
-* \retval NFCSTATUS_PENDING Connection operation is in progress,
-* pConnect_RspCb will be called upon completion.
-* \retval NFCSTATUS_INVALID_STATE The socket is not in a valid state, or not of
-* a valid type to perform the requsted operation.
-* \retval NFCSTATUS_NOT_INITIALISED Indicates stack is not yet initialized.
-* \retval NFCSTATUS_SHUTDOWN Shutdown in progress.
-* \retval NFCSTATUS_FAILED Operation failed.
-*/
-NFCSTATUS phFriNfc_LlcpTransport_ConnectByUri(phFriNfc_LlcpTransport_Socket_t* pLlcpSocket,
- phNfc_sData_t* psUri,
- pphFriNfc_LlcpTransportSocketConnectCb_t pConnect_RspCb,
- void* pContext);
-
-/**
-* \ingroup grp_lib_nfc
-* \brief Disconnect a currently connected socket.
-*
-* This function initiates the disconnection of a previously connected socket.
-*
-* \param[in] pLlcpSocket A pointer to a phFriNfc_LlcpTransport_Socket_t.
-* \param[in] pDisconnect_RspCb The callback to be called when the
-* operation is completed.
-* \param[in] pContext Upper layer context to be returned in
-* the callback.
-*
-* \retval NFCSTATUS_SUCCESS Operation successful.
-* \retval NFCSTATUS_INVALID_PARAMETER One or more of the supplied parameters
-* could not be properly interpreted.
-* \retval NFCSTATUS_PENDING Disconnection operation is in progress,
-* pDisconnect_RspCb will be called upon completion.
-* \retval NFCSTATUS_INVALID_STATE The socket is not in a valid state, or not of
-* a valid type to perform the requsted operation.
-* \retval NFCSTATUS_NOT_INITIALISED Indicates stack is not yet initialized.
-* \retval NFCSTATUS_SHUTDOWN Shutdown in progress.
-* \retval NFCSTATUS_FAILED Operation failed.
-*/
-NFCSTATUS phFriNfc_LlcpTransport_Disconnect(phFriNfc_LlcpTransport_Socket_t* pLlcpSocket,
- pphLibNfc_LlcpSocketDisconnectCb_t pDisconnect_RspCb,
- void* pContext);
-
-/**
-* \ingroup grp_fri_nfc
-* \brief Send data on a socket.
-*
-* This function is used to write data on a socket. This function
-* can only be called on a connection-oriented socket which is already
-* in a connected state.
-*
-*
-* \param[in] hSocket Socket handle obtained during socket creation.
-* \param[in] psBuffer The buffer containing the data to send.
-* \param[in] pSend_RspCb The callback to be called when the
-* operation is completed.
-* \param[in] pContext Upper layer context to be returned in
-* the callback.
-*
-* \retval NFCSTATUS_SUCCESS Operation successful.
-* \retval NFCSTATUS_INVALID_PARAMETER One or more of the supplied parameters
-* could not be properly interpreted.
-* \retval NFCSTATUS_PENDING Reception operation is in progress,
-* pSend_RspCb will be called upon completion.
-* \retval NFCSTATUS_INVALID_STATE The socket is not in a valid state, or not of
-* a valid type to perform the requsted operation.
-* \retval NFCSTATUS_FAILED Operation failed.
-*/
-NFCSTATUS phFriNfc_LlcpTransport_Send(phFriNfc_LlcpTransport_Socket_t* pLlcpSocket,
- phNfc_sData_t* psBuffer,
- pphFriNfc_LlcpTransportSocketSendCb_t pSend_RspCb,
- void* pContext);
-
-/**
-* \ingroup grp_fri_nfc
-* \brief Read data on a socket.
-*
-* This function is used to read data from a socket. It reads at most the
-* size of the reception buffer, but can also return less bytes if less bytes
-* are available. If no data is available, the function will be pending until
-* more data comes, and the response will be sent by the callback. This function
-* can only be called on a connection-oriented socket.
-*
-*
-* \param[in] hSocket Socket handle obtained during socket creation.
-* \param[in] psBuffer The buffer receiving the data.
-* \param[in] pRecv_RspCb The callback to be called when the
-* operation is completed.
-* \param[in] pContext Upper layer context to be returned in
-* the callback.
-*
-* \retval NFCSTATUS_SUCCESS Operation successful.
-* \retval NFCSTATUS_INVALID_PARAMETER One or more of the supplied parameters
-* could not be properly interpreted.
-* \retval NFCSTATUS_PENDING Reception operation is in progress,
-* pRecv_RspCb will be called upon completion.
-* \retval NFCSTATUS_INVALID_STATE The socket is not in a valid state, or not of
-* a valid type to perform the requsted operation.
-* \retval NFCSTATUS_FAILED Operation failed.
-*/
-NFCSTATUS phFriNfc_LlcpTransport_Recv( phFriNfc_LlcpTransport_Socket_t* pLlcpSocket,
- phNfc_sData_t* psBuffer,
- pphFriNfc_LlcpTransportSocketRecvCb_t pRecv_RspCb,
- void* pContext);
-
-
-
- /**
-* \ingroup grp_lib_nfc
-* \brief Read data on a socket and get the source SAP.
-*
-* This function is the same as phLibNfc_Llcp_Recv, except that the callback includes
-* the source SAP. This functions can only be called on a connectionless socket.
-*
-*
-* \param[in] pLlcpSocket A pointer to a LlcpSocket created.
-* \param[in] psBuffer The buffer receiving the data.
-* \param[in] pRecv_RspCb The callback to be called when the
-* operation is completed.
-* \param[in] pContext Upper layer context to be returned in
-* the callback.
-*
-* \retval NFCSTATUS_SUCCESS Operation successful.
-* \retval NFCSTATUS_INVALID_PARAMETER One or more of the supplied parameters
-* could not be properly interpreted.
-* \retval NFCSTATUS_PENDING Reception operation is in progress,
-* pRecv_RspCb will be called upon completion.
-* \retval NFCSTATUS_INVALID_STATE The socket is not in a valid state, or not of
-* a valid type to perform the requsted operation.
-* \retval NFCSTATUS_NOT_INITIALISED Indicates stack is not yet initialized.
-* \retval NFCSTATUS_SHUTDOWN Shutdown in progress.
-* \retval NFCSTATUS_FAILED Operation failed.
-*/
-NFCSTATUS phFriNfc_LlcpTransport_RecvFrom( phFriNfc_LlcpTransport_Socket_t *pLlcpSocket,
- phNfc_sData_t* psBuffer,
- pphFriNfc_LlcpTransportSocketRecvFromCb_t pRecv_Cb,
- void *pContext);
-
-/**
-* \ingroup grp_fri_nfc
-* \brief Send data on a socket to a given destination SAP.
-*
-* This function is used to write data on a socket to a given destination SAP.
-* This function can only be called on a connectionless socket.
-*
-*
-* \param[in] pLlcpSocket A pointer to a LlcpSocket created.
-* \param[in] nSap The destination SAP.
-* \param[in] psBuffer The buffer containing the data to send.
-* \param[in] pSend_RspCb The callback to be called when the
-* operation is completed.
-* \param[in] pContext Upper layer context to be returned in
-* the callback.
-*
-* \retval NFCSTATUS_SUCCESS Operation successful.
-* \retval NFCSTATUS_INVALID_PARAMETER One or more of the supplied parameters
-* could not be properly interpreted.
-* \retval NFCSTATUS_PENDING Reception operation is in progress,
-* pSend_RspCb will be called upon completion.
-* \retval NFCSTATUS_INVALID_STATE The socket is not in a valid state, or not of
-* a valid type to perform the requsted operation.
-* \retval NFCSTATUS_NOT_INITIALISED Indicates stack is not yet initialized.
-* \retval NFCSTATUS_SHUTDOWN Shutdown in progress.
-* \retval NFCSTATUS_FAILED Operation failed.
-*/
-NFCSTATUS phFriNfc_LlcpTransport_SendTo( phFriNfc_LlcpTransport_Socket_t *pLlcpSocket,
- uint8_t nSap,
- phNfc_sData_t* psBuffer,
- pphFriNfc_LlcpTransportSocketSendCb_t pSend_RspCb,
- void* pContext);
-#endif /* PHFRINFC_LLCP_TRANSPORT_H */
diff --git a/libnfc-nxp/phFriNfc_LlcpTransport_Connection.c b/libnfc-nxp/phFriNfc_LlcpTransport_Connection.c
deleted file mode 100644
index 4fb50ab..0000000
--- a/libnfc-nxp/phFriNfc_LlcpTransport_Connection.c
+++ /dev/null
@@ -1,2481 +0,0 @@
-/*
- * Copyright (C) 2010 NXP Semiconductors
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-/**
- * \file phFriNfc_LlcpTransport_Connection.c
- * \brief
- *
- * Project: NFC-FRI
- *
- */
-/*include files*/
-#define LOG_TAG "NFC"
-#include
-#include
-#include
-#include
-#include
-#include
-#include
-#include
-#include
-
-/* Function definition */
-static NFCSTATUS phFriNfc_Llcp_Send_ReceiveReady_Frame(phFriNfc_LlcpTransport_Socket_t* pLlcpSocket);
-static NFCSTATUS phFriNfc_Llcp_Send_ReceiveNotReady_Frame(phFriNfc_LlcpTransport_Socket_t* pLlcpSocket);
-
-static NFCSTATUS static_performSendInfo(phFriNfc_LlcpTransport_Socket_t * psLlcpSocket);
-/********** End Function definition ***********/
-
-/* TODO: comment functionphFriNfc_LlcpTransport_ConnectionOriented_SendLlcp_CB */
-static void phFriNfc_LlcpTransport_ConnectionOriented_SendLlcp_CB(void* pContext,
- uint8_t socketIndex,
- NFCSTATUS status)
-{
- phFriNfc_LlcpTransport_t *psTransport;
- phFriNfc_LlcpTransport_Socket_t psTempLlcpSocket;
- NFCSTATUS result;
- /* Get Send CB context */
- psTransport = (phFriNfc_LlcpTransport_t*)pContext;
-
- if(status == NFCSTATUS_SUCCESS)
- {
- /* Test the socket */
- switch(psTransport->pSocketTable[socketIndex].eSocket_State)
- {
- case phFriNfc_LlcpTransportSocket_eSocketAccepted:
- {
- /* Set socket state to Connected */
- psTransport->pSocketTable[socketIndex].eSocket_State = phFriNfc_LlcpTransportSocket_eSocketConnected;
- /* Call the Accept Callback */
- psTransport->pSocketTable[socketIndex].pfSocketAccept_Cb(psTransport->pSocketTable[socketIndex].pAcceptContext,status);
- psTransport->pSocketTable[socketIndex].pfSocketAccept_Cb = NULL;
- psTransport->pSocketTable[socketIndex].pAcceptContext = NULL;
- }break;
-
- case phFriNfc_LlcpTransportSocket_eSocketRejected:
- {
- /* Store the Llcp socket in a local Llcp socket */
- psTempLlcpSocket = psTransport->pSocketTable[socketIndex];
-
- /* Reset the socket and set the socket state to default */
- result = phFriNfc_LlcpTransport_Close(&psTransport->pSocketTable[socketIndex]);
-
- /* Call the Reject Callback */
- psTempLlcpSocket.pfSocketSend_Cb(psTempLlcpSocket.pRejectContext,status);
- psTempLlcpSocket.pfSocketSend_Cb = NULL;
- }break;
-
- case phFriNfc_LlcpTransportSocket_eSocketConnected:
- {
- if(!psTransport->pSocketTable[socketIndex].bSocketSendPending && psTransport->pSocketTable[socketIndex].pfSocketSend_Cb != NULL)
- {
- psTransport->pSocketTable[socketIndex].pfSocketSend_Cb(psTransport->pSocketTable[socketIndex].pSendContext,status);
- psTransport->pSocketTable[socketIndex].pfSocketSend_Cb = NULL;
- }
- }break;
- default:
- /* Nothing to do */
- break;
- }
- }
- else
- {
- /* Send CB error */
- if(!psTransport->pSocketTable[socketIndex].bSocketSendPending && psTransport->pSocketTable[socketIndex].pfSocketSend_Cb != NULL)
- {
- psTransport->pSocketTable[socketIndex].pfSocketSend_Cb(psTransport->pSocketTable[socketIndex].pSendContext,status);
- psTransport->pSocketTable[socketIndex].pfSocketSend_Cb = NULL;
- }
- }
-}
-
-
-NFCSTATUS phFriNfc_LlcpTransport_ConnectionOriented_HandlePendingOperations(phFriNfc_LlcpTransport_Socket_t *pSocket)
-{
- NFCSTATUS result = NFCSTATUS_FAILED;
- phFriNfc_LlcpTransport_t *psTransport = pSocket->psTransport;
- /* I FRAME */
- if(pSocket->bSocketSendPending == TRUE)
- {
- /* Test the RW window */
- if(CHECK_SEND_RW(pSocket))
- {
- if (!testAndSetSendPending(psTransport)) {
- result = static_performSendInfo(pSocket);
- if (result != NFCSTATUS_SUCCESS && result != NFCSTATUS_PENDING) {
- clearSendPending(psTransport);
- }
- }
- }
- }
- /* RR FRAME */
- else if(pSocket->bSocketRRPending == TRUE)
- {
- /* Reset RR pending */
- pSocket->bSocketRRPending = FALSE;
-
- /* Send RR Frame */
- result = phFriNfc_Llcp_Send_ReceiveReady_Frame(pSocket);
- }
- /* RNR Frame */
- else if(pSocket->bSocketRNRPending == TRUE)
- {
- /* Reset RNR pending */
- pSocket->bSocketRNRPending = FALSE;
-
- /* Send RNR Frame */
- result = phFriNfc_Llcp_Send_ReceiveNotReady_Frame(pSocket);
- }
- /* CC Frame */
- else if(pSocket->bSocketAcceptPending == TRUE)
- {
- if (!testAndSetSendPending(psTransport))
- {
- /* Reset Accept pending */
- pSocket->bSocketAcceptPending = FALSE;
-
- /* Fill the psLlcpHeader stuture with the DSAP,CC PTYPE and the SSAP */
- pSocket->sLlcpHeader.dsap = pSocket->socket_dSap;
- pSocket->sLlcpHeader.ptype = PHFRINFC_LLCP_PTYPE_CC;
- pSocket->sLlcpHeader.ssap = pSocket->socket_sSap;
-
- /* Set the socket state to accepted */
- pSocket->eSocket_State = phFriNfc_LlcpTransportSocket_eSocketAccepted;
-
- /* Send a CC Frame */
- result = phFriNfc_LlcpTransport_LinkSend(psTransport,
- &pSocket->sLlcpHeader,
- NULL,
- &pSocket->sSocketSendBuffer,
- phFriNfc_LlcpTransport_ConnectionOriented_SendLlcp_CB,
- pSocket->index,
- psTransport);
-
- if (result != NFCSTATUS_SUCCESS && result != NFCSTATUS_PENDING) {
- clearSendPending(psTransport);
- }
- }
- }
- /* CONNECT FRAME */
- else if(pSocket->bSocketConnectPending == TRUE)
- {
- if (!testAndSetSendPending(psTransport))
- {
- /* Reset Accept pending */
- pSocket->bSocketConnectPending = FALSE;
-
- /* Set the socket in connecting state */
- pSocket->eSocket_State = phFriNfc_LlcpTransportSocket_eSocketConnecting;
-
- /* send CONNECT */
- result = phFriNfc_LlcpTransport_LinkSend(psTransport,
- &pSocket->sLlcpHeader,
- NULL,
- &pSocket->sSocketSendBuffer,
- phFriNfc_LlcpTransport_ConnectionOriented_SendLlcp_CB,
- pSocket->index,
- psTransport);
-
- if (result != NFCSTATUS_SUCCESS && result != NFCSTATUS_PENDING) {
- clearSendPending(psTransport);
- }
- }
- }
- /* DISC FRAME */
- else if(pSocket->bSocketDiscPending == TRUE)
- {
- if (!testAndSetSendPending(psTransport))
- {
- /* Reset Disc Pending */
- pSocket->bSocketDiscPending = FALSE;
-
- /* Set the socket in connecting state */
- pSocket->eSocket_State = phFriNfc_LlcpTransportSocket_eSocketDisconnecting;
-
- /* Send DISC */
- result = phFriNfc_LlcpTransport_LinkSend(psTransport,
- &pSocket->sLlcpHeader,
- NULL,
- &pSocket->sSocketSendBuffer,
- phFriNfc_LlcpTransport_ConnectionOriented_SendLlcp_CB,
- pSocket->index,
- psTransport);
-
- if (result != NFCSTATUS_SUCCESS && result != NFCSTATUS_PENDING) {
- clearSendPending(psTransport);
- }
- /* Call ErrCB due to a DISC */
- pSocket->pSocketErrCb(pSocket->pContext, PHFRINFC_LLCP_ERR_DISCONNECTED);
- }
- }
- return result;
-}
-
-static NFCSTATUS static_performSendInfo(phFriNfc_LlcpTransport_Socket_t * psLlcpSocket)
-{
- phFriNfc_LlcpTransport_t *psTransport = psLlcpSocket->psTransport;
- NFCSTATUS status;
-
- /* Set the Header */
- psLlcpSocket->sLlcpHeader.dsap = psLlcpSocket->socket_dSap;
- psLlcpSocket->sLlcpHeader.ptype = PHFRINFC_LLCP_PTYPE_I;
- psLlcpSocket->sLlcpHeader.ssap = psLlcpSocket->socket_sSap;
-
- /* Set Sequence Numbers */
- psLlcpSocket->sSequence.ns = psLlcpSocket->socket_VS;
- psLlcpSocket->sSequence.nr = psLlcpSocket->socket_VR;
-
- /* Update the VRA */
- psLlcpSocket->socket_VRA = psLlcpSocket->socket_VR;
-
-
- /* Send I_PDU */
- status = phFriNfc_LlcpTransport_LinkSend(psTransport,
- &psLlcpSocket->sLlcpHeader,
- &psLlcpSocket->sSequence,
- &psLlcpSocket->sSocketSendBuffer,
- phFriNfc_LlcpTransport_ConnectionOriented_SendLlcp_CB,
- psLlcpSocket->index,
- psLlcpSocket->psTransport);
- if (status == NFCSTATUS_SUCCESS || status == NFCSTATUS_PENDING) {
- /* Update VS */
- psLlcpSocket->socket_VS = (psLlcpSocket->socket_VS+1)%16;
-
- /* Reset Send Pending */
- psLlcpSocket->bSocketSendPending = FALSE;
- }
-
- return status;
-}
-
-static void phFriNfc_LlcpTransport_ConnectionOriented_Abort(phFriNfc_LlcpTransport_Socket_t * pLlcpSocket)
-{
- if (pLlcpSocket->pfSocketSend_Cb != NULL)
- {
- pLlcpSocket->pfSocketSend_Cb(pLlcpSocket->pSendContext, NFCSTATUS_ABORTED);
- pLlcpSocket->pfSocketSend_Cb = NULL;
- }
- pLlcpSocket->pSendContext = NULL;
- if (pLlcpSocket->pfSocketRecv_Cb != NULL)
- {
- pLlcpSocket->pfSocketRecv_Cb(pLlcpSocket->pRecvContext, NFCSTATUS_ABORTED);
- pLlcpSocket->pfSocketRecv_Cb = NULL;
- }
- pLlcpSocket->pRecvContext = NULL;
- if (pLlcpSocket->pfSocketAccept_Cb != NULL)
- {
- pLlcpSocket->pfSocketAccept_Cb(pLlcpSocket->pAcceptContext, NFCSTATUS_ABORTED);
- pLlcpSocket->pfSocketAccept_Cb = NULL;
- }
- pLlcpSocket->pAcceptContext = NULL;
- if (pLlcpSocket->pfSocketConnect_Cb != NULL)
- {
- pLlcpSocket->pfSocketConnect_Cb(pLlcpSocket->pConnectContext, 0, NFCSTATUS_ABORTED);
- pLlcpSocket->pfSocketConnect_Cb = NULL;
- }
- pLlcpSocket->pConnectContext = NULL;
- if (pLlcpSocket->pfSocketDisconnect_Cb != NULL)
- {
- pLlcpSocket->pfSocketDisconnect_Cb(pLlcpSocket->pDisconnectContext, NFCSTATUS_ABORTED);
- pLlcpSocket->pfSocketDisconnect_Cb = NULL;
- }
- pLlcpSocket->pDisconnectContext = NULL;
-
- pLlcpSocket->pfSocketRecvFrom_Cb = NULL;
- pLlcpSocket->pfSocketListen_Cb = NULL;
- pLlcpSocket->pListenContext = NULL;
-}
-
-
-static NFCSTATUS phFriNfc_Llcp_Send_ReceiveReady_Frame(phFriNfc_LlcpTransport_Socket_t* pLlcpSocket)
-{
- NFCSTATUS status = NFCSTATUS_SUCCESS;
-
- /* Test if a send is pending */
- if(testAndSetSendPending(pLlcpSocket->psTransport))
- {
- pLlcpSocket->bSocketRRPending = TRUE;
- status = NFCSTATUS_PENDING;
- }
- else
- {
- /* Set the header of the RR frame */
- pLlcpSocket->sLlcpHeader.dsap = pLlcpSocket->socket_dSap;
- pLlcpSocket->sLlcpHeader.ptype = PHFRINFC_LLCP_PTYPE_RR;
- pLlcpSocket->sLlcpHeader.ssap = pLlcpSocket->socket_sSap;
-
- /* Set sequence number for RR Frame */
- pLlcpSocket->sSequence.ns = 0;
- pLlcpSocket->sSequence.nr = pLlcpSocket->socket_VR;
-
- /* Update VRA */
- pLlcpSocket->socket_VRA = (uint8_t)pLlcpSocket->sSequence.nr;
-
- /* Send RR frame */
- status = phFriNfc_LlcpTransport_LinkSend(pLlcpSocket->psTransport,
- &pLlcpSocket->sLlcpHeader,
- &pLlcpSocket->sSequence,
- NULL,
- phFriNfc_LlcpTransport_ConnectionOriented_SendLlcp_CB,
- pLlcpSocket->index,
- pLlcpSocket->psTransport);
- if (status != NFCSTATUS_SUCCESS && status != NFCSTATUS_PENDING) {
- clearSendPending(pLlcpSocket->psTransport);
- }
- }
-
- return status;
-}
-
-static NFCSTATUS phFriNfc_Llcp_Send_ReceiveNotReady_Frame(phFriNfc_LlcpTransport_Socket_t* pLlcpSocket)
-{
- NFCSTATUS status = NFCSTATUS_SUCCESS;
-
-
- /* Test if a send is pending */
- if(testAndSetSendPending(pLlcpSocket->psTransport))
- {
- pLlcpSocket->bSocketRNRPending = TRUE;
- status = NFCSTATUS_PENDING;
- }
- else
- {
- /* Set the header of the RNR frame */
- pLlcpSocket->sLlcpHeader.dsap = pLlcpSocket->socket_dSap;
- pLlcpSocket->sLlcpHeader.ptype = PHFRINFC_LLCP_PTYPE_RNR;
- pLlcpSocket->sLlcpHeader.ssap = pLlcpSocket->socket_sSap;
-
- /* Set sequence number for RNR Frame */
- pLlcpSocket->sSequence.ns = 0x00;
- pLlcpSocket->sSequence.nr = pLlcpSocket->socket_VR;
-
- /* Update VRA */
- pLlcpSocket->socket_VRA = (uint8_t)pLlcpSocket->sSequence.nr;
-
- /* Send RNR frame */
- status = phFriNfc_LlcpTransport_LinkSend(pLlcpSocket->psTransport,
- &pLlcpSocket->sLlcpHeader,
- &pLlcpSocket->sSequence,
- NULL,
- phFriNfc_LlcpTransport_ConnectionOriented_SendLlcp_CB,
- pLlcpSocket->index,
- pLlcpSocket->psTransport);
- if (status != NFCSTATUS_SUCCESS && status != NFCSTATUS_PENDING) {
- clearSendPending(pLlcpSocket->psTransport);
- }
- }
- return status;
-}
-
-static NFCSTATUS phFriNfc_Llcp_GetSocket_Params(phNfc_sData_t *psParamsTLV,
- phNfc_sData_t *psServiceName,
- uint8_t *pRemoteRW_Size,
- uint16_t *pRemoteMIU)
-{
- NFCSTATUS status = NFCSTATUS_SUCCESS;
- phNfc_sData_t sValueBuffer;
- uint32_t offset = 0;
- uint8_t type;
-
- /* Check for NULL pointers */
- if ((psParamsTLV == NULL) || (pRemoteRW_Size == NULL) || (pRemoteMIU == NULL))
- {
- return PHNFCSTVAL(CID_FRI_NFC_LLCP, NFCSTATUS_INVALID_PARAMETER);
- }
- else
- {
- /* Decode TLV */
- while (offset < psParamsTLV->length)
- {
- status = phFriNfc_Llcp_DecodeTLV(psParamsTLV, &offset, &type,&sValueBuffer);
- if (status != NFCSTATUS_SUCCESS)
- {
- /* Error: Ill-formed TLV */
- return status;
- }
- switch(type)
- {
- case PHFRINFC_LLCP_TLV_TYPE_SN:
- {
- /* Test if a SN is present in the TLV */
- if(sValueBuffer.length == 0)
- {
- /* Error : Ill-formed SN parameter TLV */
- break;
- }
- /* Get the Service Name */
- *psServiceName = sValueBuffer;
- }break;
-
- case PHFRINFC_LLCP_TLV_TYPE_RW:
- {
- /* Check length */
- if (sValueBuffer.length != PHFRINFC_LLCP_TLV_LENGTH_RW)
- {
- /* Error : Ill-formed MIUX parameter TLV */
- break;
- }
- *pRemoteRW_Size = sValueBuffer.buffer[0];
- }break;
-
- case PHFRINFC_LLCP_TLV_TYPE_MIUX:
- {
- /* Check length */
- if (sValueBuffer.length != PHFRINFC_LLCP_TLV_LENGTH_MIUX)
- {
- /* Error : Ill-formed MIUX parameter TLV */
- break;
- }
- *pRemoteMIU = PHFRINFC_LLCP_MIU_DEFAULT + (((sValueBuffer.buffer[0] << 8) | sValueBuffer.buffer[1]) & PHFRINFC_LLCP_TLV_MIUX_MASK);
- }break;
-
- default:
- {
- /* Error : Unknown type */
- break;
- }
- }
- }
- }
- return status;
-}
-
-
-/* TODO: comment function Handle_ConnectFrame */
-static void Handle_ConnectionFrame(phFriNfc_LlcpTransport_t *psTransport,
- phNfc_sData_t *psData,
- uint8_t dsap,
- uint8_t ssap)
-{
- NFCSTATUS status = NFCSTATUS_SUCCESS;
-
- uint8_t index;
- uint8_t socketFound = FALSE;
- phFriNfc_LlcpTransport_Socket_t *pLlcpSocket = NULL;
- phFriNfc_LlcpTransport_Socket_t *psLocalLlcpSocket = NULL;
- pphFriNfc_LlcpTransportSocketListenCb_t pListen_Cb = NULL;
- void *pListenContext = NULL;
-
- phNfc_sData_t sServiceName;
- uint8_t remoteRW = PHFRINFC_LLCP_RW_DEFAULT;
- uint16_t remoteMIU = PHFRINFC_LLCP_MIU_DEFAULT;
-
- status = phFriNfc_Llcp_GetSocket_Params(psData,
- &sServiceName,
- &remoteRW,
- &remoteMIU);
-
- if(status != NFCSTATUS_SUCCESS)
- {
- /* Incorrect TLV */
- /* send FRMR */
- status = phFriNfc_LlcpTransport_SendFrameReject(psTransport,
- dsap,
- PHFRINFC_LLCP_PTYPE_CONNECT,
- ssap,
- 0x00,
- 0x00,
- 0x00,
- 0x00,
- 0x00,
- 0x00,
- 0x00,
- 0x00,
- 0x00);
- }
- else
- {
- if(dsap == PHFRINFC_LLCP_SAP_SDP)
- {
- /* Search a socket with the SN */
- for(index=0;indexpSocketTable[index].bSocketListenPending
- && (sServiceName.length == psTransport->pSocketTable[index].sServiceName.length)
- && !memcmp(sServiceName.buffer,psTransport->pSocketTable[index].sServiceName.buffer,sServiceName.length))
- {
- /* socket with the SN found */
- socketFound = TRUE;
-
- psLocalLlcpSocket = &psTransport->pSocketTable[index];
-
- /* Get the new ssap number, it is the ssap number of the socket found */
- dsap = psLocalLlcpSocket->socket_sSap;
- /* Get the ListenCB of the socket */
- pListen_Cb = psLocalLlcpSocket->pfSocketListen_Cb;
- pListenContext = psLocalLlcpSocket->pListenContext;
- break;
- }
- }
- }
- else
- {
- /* Search a socket with the DSAP */
- for(index=0;indexpSocketTable[index].bSocketListenPending && psTransport->pSocketTable[index].socket_sSap == dsap)
- {
- /* socket with the SN found */
- socketFound = TRUE;
-
- psLocalLlcpSocket = &psTransport->pSocketTable[index];
-
- /* Get the Listen CB and the Context of the socket */
- pListen_Cb = psLocalLlcpSocket->pfSocketListen_Cb;
- pListenContext = psLocalLlcpSocket->pListenContext;
- break;
- }
- }
- }
- }
-
- /* Test if a socket has beeen found */
- if(socketFound)
- {
- /* Reset the FLAG socketFound*/
- socketFound = FALSE;
-
- /* Search a socket free and no socket connect on this DSAP*/
- for(index=0;indexpSocketTable[index].eSocket_State == phFriNfc_LlcpTransportSocket_eSocketDefault && socketFound != TRUE)
- {
- socketFound = TRUE;
-
- psTransport->pSocketTable[index].index = index;
-
- /* Create a communication socket */
- pLlcpSocket = &psTransport->pSocketTable[index];
-
- /* Set the communication option of the Remote Socket */
- pLlcpSocket->remoteMIU = remoteMIU;
- pLlcpSocket->remoteRW = remoteRW;
-
- /* Set SSAP/DSAP of the new socket created for the communication with the remote */
- pLlcpSocket->socket_dSap = ssap;
- pLlcpSocket->socket_sSap = dsap;
-
- /* Set the state and the type of the new socket */
- pLlcpSocket->eSocket_State = phFriNfc_LlcpTransportSocket_eSocketBound;
- pLlcpSocket->eSocket_Type = phFriNfc_LlcpTransport_eConnectionOriented;
-
- }
- else if(((psTransport->pSocketTable[index].eSocket_State == phFriNfc_LlcpTransportSocket_eSocketConnected)
- || (psTransport->pSocketTable[index].eSocket_State == phFriNfc_LlcpTransportSocket_eSocketAccepted))
- && ((psTransport->pSocketTable[index].socket_sSap == ssap)&&(psTransport->pSocketTable[index].socket_dSap == dsap)))
-
- {
- socketFound = FALSE;
-
- if(pLlcpSocket != NULL)
- {
- /* Reset Socket Information */
- pLlcpSocket->remoteMIU = 0;
- pLlcpSocket->remoteRW = 0;
-
- /* Set SSAP/DSAP of the new socket created for the communication with the remote */
- pLlcpSocket->socket_dSap = 0;
- pLlcpSocket->socket_sSap = 0;
-
- /* Set the state and the type of the new socket */
- pLlcpSocket->eSocket_State = phFriNfc_LlcpTransportSocket_eSocketDefault;
- pLlcpSocket->eSocket_Type = phFriNfc_LlcpTransport_eDefaultType;
- break;
- }
- }
- }
-
-
-
- /* Test if a socket has been found */
- if(socketFound)
- {
- /* Call the Listen CB */
- pListen_Cb(pListenContext,pLlcpSocket);
- }
- else
- {
- /* No more socket are available */
- /* Send a DM (0x21) */
- status = phFriNfc_LlcpTransport_SendDisconnectMode (psTransport,
- ssap,
- dsap,
- PHFRINFC_LLCP_DM_OPCODE_SOCKET_NOT_AVAILABLE);
- }
- }
- else
- {
- /* Service Name not found or Port number not found */
- /* Send a DM (0x02) */
- status = phFriNfc_LlcpTransport_SendDisconnectMode (psTransport,
- ssap,
- dsap,
- PHFRINFC_LLCP_DM_OPCODE_SAP_NOT_FOUND);
- }
-}
-
-/* TODO: comment function Handle_ConnectFrame */
-static void Handle_ConnectionCompleteFrame(phFriNfc_LlcpTransport_t *psTransport,
- phNfc_sData_t *psData,
- uint8_t dsap,
- uint8_t ssap)
-{
- NFCSTATUS status = NFCSTATUS_SUCCESS;
- uint8_t index;
- uint8_t remoteRW = PHFRINFC_LLCP_RW_DEFAULT;
- uint16_t remoteMIU = PHFRINFC_LLCP_MIU_DEFAULT;
- uint8_t socketFound = FALSE;
- phFriNfc_LlcpTransport_Socket_t* psLocalLlcpSocket = NULL;
-
- status = phFriNfc_Llcp_GetSocket_Params(psData,
- NULL,
- &remoteRW,
- &remoteMIU);
-
- if(status != NFCSTATUS_SUCCESS)
- {
- /* Incorrect TLV */
- /* send FRMR */
- status = phFriNfc_LlcpTransport_SendFrameReject(psTransport,
- dsap,
- PHFRINFC_LLCP_PTYPE_CC,
- ssap,
- 0x00,
- 0x00,
- 0x00,
- 0x00,
- 0x00,
- 0x00,
- 0x00,
- 0x00,
- 0x00);
- }
- else
- {
- /* Search a socket in connecting state and with the good SSAP */
- for(index=0;indexpSocketTable[index].eSocket_State == phFriNfc_LlcpTransportSocket_eSocketConnecting
- && psTransport->pSocketTable[index].socket_sSap == dsap)
- {
- /* socket with the SN found */
- socketFound = TRUE;
-
- /* Update the DSAP value with the incomming Socket sSap */
- psTransport->pSocketTable[index].socket_dSap = ssap;
-
- /* Store a pointer to the socket found */
- psLocalLlcpSocket = &psTransport->pSocketTable[index];
- break;
- }
- }
- /* Test if a socket has been found */
- if(socketFound)
- {
- /* Set the socket state to connected */
- psLocalLlcpSocket->eSocket_State = phFriNfc_LlcpTransportSocket_eSocketConnected;
-
- /* Reset the socket_VS,socket_VR,socket_VSA and socket_VRA variables */
- psLocalLlcpSocket->socket_VR = 0;
- psLocalLlcpSocket->socket_VRA = 0;
- psLocalLlcpSocket->socket_VS = 0;
- psLocalLlcpSocket->socket_VSA = 0;
-
- /* Store the Remote parameters (MIU,RW) */
- psLocalLlcpSocket->remoteMIU = remoteMIU;
- psLocalLlcpSocket->remoteRW = remoteRW;
-
- /* Call the Connect CB and reset callback info */
- psLocalLlcpSocket->pfSocketConnect_Cb(psLocalLlcpSocket->pConnectContext,0x00,NFCSTATUS_SUCCESS);
- psLocalLlcpSocket->pfSocketConnect_Cb = NULL;
- psLocalLlcpSocket->pConnectContext = NULL;
- }
- else
- {
- /* No socket Active */
- /* CC Frame not handled */
- }
- }
-}
-
-/* TODO: comment function Handle_DisconnectFrame */
-static void Handle_DisconnectFrame(phFriNfc_LlcpTransport_t *psTransport,
- uint8_t dsap,
- uint8_t ssap)
-{
- NFCSTATUS status = NFCSTATUS_SUCCESS;
- uint8_t index;
- uint8_t socketFound = FALSE;
- phFriNfc_LlcpTransport_Socket_t* psLocalLlcpSocket = NULL;
-
- /* Search a socket in connected state and the good SSAP */
- for(index=0;indexpSocketTable[index].eSocket_State == phFriNfc_LlcpTransportSocket_eSocketConnected
- && psTransport->pSocketTable[index].socket_sSap == dsap)
- {
- /* socket found */
- socketFound = TRUE;
-
- /* Store a pointer to the socket found */
- psLocalLlcpSocket = &psTransport->pSocketTable[index];
- break;
- }
- }
-
- /* Test if a socket has been found */
- if(socketFound)
- {
- /* Test if a send IFRAME is pending with this socket */
- if((psLocalLlcpSocket->bSocketSendPending == TRUE) || (psLocalLlcpSocket->bSocketRecvPending == TRUE))
- {
- /* Call the send CB, a disconnect abort the send request */
- if (psLocalLlcpSocket->pfSocketSend_Cb != NULL && psLocalLlcpSocket->bSocketSendPending == TRUE)
- {
- /* Copy CB + context in local variables */
- pphFriNfc_LlcpTransportSocketSendCb_t pfSendCb = psLocalLlcpSocket->pfSocketSend_Cb;
- void* pSendContext = psLocalLlcpSocket->pSendContext;
- /* Reset CB + context */
- psLocalLlcpSocket->pfSocketSend_Cb = NULL;
- psLocalLlcpSocket->pSendContext = NULL;
- /* Perform callback */
- pfSendCb(pSendContext, NFCSTATUS_FAILED);
- }
- /* Call the send CB, a disconnect abort the receive request */
- if (psLocalLlcpSocket->pfSocketRecv_Cb != NULL && psLocalLlcpSocket->bSocketRecvPending == TRUE)
- {
- /* Copy CB + context in local variables */
- pphFriNfc_LlcpTransportSocketRecvCb_t pfRecvCb = psLocalLlcpSocket->pfSocketRecv_Cb;
- void* pRecvContext = psLocalLlcpSocket->pRecvContext;
- /* Reset CB + context */
- psLocalLlcpSocket->pfSocketRecv_Cb = NULL;
- psLocalLlcpSocket->pRecvContext = NULL;
- /* Perform callback */
- pfRecvCb(pRecvContext, NFCSTATUS_FAILED);
- }
- psLocalLlcpSocket->bSocketRecvPending = FALSE;
- psLocalLlcpSocket->bSocketSendPending = FALSE;
- }
-
- /* Update the socket state */
- psLocalLlcpSocket->eSocket_State = phFriNfc_LlcpTransportSocket_eSocketDisconnecting;
-
- /* Send a DM*/
- /* TODO: use a socket internal flag to save */
- status = phFriNfc_LlcpTransport_SendDisconnectMode(psTransport,
- ssap,
- dsap,
- PHFRINFC_LLCP_DM_OPCODE_DISCONNECTED);
-
- /* Call ErrCB due to a DISC */
- psTransport->pSocketTable[index].pSocketErrCb(psTransport->pSocketTable[index].pContext, PHFRINFC_LLCP_ERR_DISCONNECTED);
- }
- else
- {
- /* No socket Active */
- /* DISC Frame not handled */
- }
-}
-
-/* TODO: comment function Handle_ConnectFrame */
-static void Handle_DisconnetModeFrame(phFriNfc_LlcpTransport_t *psTransport,
- phNfc_sData_t *psData,
- uint8_t dsap,
- uint8_t ssap)
-{
- NFCSTATUS status = NFCSTATUS_SUCCESS;
- uint8_t index;
- uint8_t socketFound = FALSE;
- uint8_t dmOpCode;
- phFriNfc_LlcpTransport_Socket_t *psLocalLlcpSocket = NULL;
-
- /* Test if the DM buffer is correct */
- if(psData->length != PHFRINFC_LLCP_DM_LENGTH)
- {
- /* send FRMR */
- status = phFriNfc_LlcpTransport_SendFrameReject(psTransport,
- dsap,
- PHFRINFC_LLCP_PTYPE_DM,
- ssap,
- 0x00,
- 0x00,
- 0x00,
- 0x00,
- 0x00,
- 0x00,
- 0x00,
- 0x00,
- 0x00);
- }
- else
- {
- /* Search a socket waiting for a DM (Disconnecting State) */
- for(index=0;indexpSocketTable[index].eSocket_State == phFriNfc_LlcpTransportSocket_eSocketDisconnecting
- || psTransport->pSocketTable[index].eSocket_State == phFriNfc_LlcpTransportSocket_eSocketConnecting)
- && psTransport->pSocketTable[index].socket_sSap == dsap)
- {
- /* socket found */
- socketFound = TRUE;
-
- /* Store a pointer to the socket found */
- psLocalLlcpSocket = &psTransport->pSocketTable[index];
- break;
- }
- }
-
- /* Test if a socket has been found */
- if(socketFound)
- {
- /* Set dmOpcode */
- dmOpCode = psData->buffer[0];
-
- switch(dmOpCode)
- {
- case PHFRINFC_LLCP_DM_OPCODE_DISCONNECTED:
- {
- /* Set the socket state to disconnected */
- psLocalLlcpSocket->eSocket_State = phFriNfc_LlcpTransportSocket_eSocketCreated;
-
- /* Call Disconnect CB */
- if (psLocalLlcpSocket->pfSocketDisconnect_Cb != NULL)
- {
- psLocalLlcpSocket->pfSocketDisconnect_Cb(psLocalLlcpSocket->pDisconnectContext,NFCSTATUS_SUCCESS);
- psLocalLlcpSocket->pfSocketDisconnect_Cb = NULL;
- }
-
- }break;
-
- case PHFRINFC_LLCP_DM_OPCODE_CONNECT_REJECTED:
- case PHFRINFC_LLCP_DM_OPCODE_CONNECT_NOT_ACCEPTED:
- case PHFRINFC_LLCP_DM_OPCODE_SAP_NOT_ACTIVE:
- case PHFRINFC_LLCP_DM_OPCODE_SAP_NOT_FOUND:
- case PHFRINFC_LLCP_DM_OPCODE_SOCKET_NOT_AVAILABLE:
- {
- /* Set the socket state to bound */
- psLocalLlcpSocket->eSocket_State = phFriNfc_LlcpTransportSocket_eSocketCreated;
- if(psLocalLlcpSocket->pfSocketConnect_Cb != NULL)
- {
- /* Call Connect CB */
- psLocalLlcpSocket->pfSocketConnect_Cb(psLocalLlcpSocket->pConnectContext,dmOpCode,NFCSTATUS_FAILED);
- psLocalLlcpSocket->pfSocketConnect_Cb = NULL;
- }
- }break;
- }
- }
- }
-}
-
-/* TODO: comment function Handle_Receive_IFrame */
-static void Handle_Receive_IFrame(phFriNfc_LlcpTransport_t *psTransport,
- phNfc_sData_t *psData,
- uint8_t dsap,
- uint8_t ssap)
-{
- NFCSTATUS status = NFCSTATUS_SUCCESS;
-
- phFriNfc_LlcpTransport_Socket_t* psLocalLlcpSocket = NULL;
- phFriNfc_Llcp_sPacketSequence_t sLlcpLocalSequence;
-
- uint32_t dataLengthAvailable = 0;
- uint32_t dataLengthWrite = 0;
- uint8_t index;
- uint8_t socketFound = FALSE;
- uint8_t WFlag = 0;
- uint8_t IFlag = 0;
- uint8_t RFlag = 0;
- uint8_t SFlag = 0;
- uint8_t nr_val;
- uint32_t offset = 0;
- uint32_t rw_offset;
-
- /* Get NS and NR Value of the I Frame*/
- phFriNfc_Llcp_Buffer2Sequence( psData->buffer, offset, &sLlcpLocalSequence);
-
-
- /* Update the buffer pointer */
- psData->buffer = psData->buffer + PHFRINFC_LLCP_PACKET_SEQUENCE_SIZE;
-
- /* Update the length value (without the header length) */
- psData->length = psData->length - PHFRINFC_LLCP_PACKET_SEQUENCE_SIZE;
-
- /* Search a socket waiting for an I FRAME (Connected State) */
- for(index=0;indexpSocketTable[index].eSocket_State == phFriNfc_LlcpTransportSocket_eSocketConnected)
- || (psTransport->pSocketTable[index].eSocket_State == phFriNfc_LlcpTransportSocket_eSocketAccepted))
- && psTransport->pSocketTable[index].socket_sSap == dsap
- && psTransport->pSocketTable[index].socket_dSap == ssap)
- {
- /* socket found */
- socketFound = TRUE;
-
- /* Store a pointer to the socket found */
- psLocalLlcpSocket = &psTransport->pSocketTable[index];
- break;
- }
- }
-
- /* Test if a socket has been found */
- if(socketFound)
- {
- /* Test NS */
- /*if(sLlcpLocalSequence.ns != psLocalLlcpSocket->socket_VR)
- {
- SFlag = TRUE;
- }*/
-
- /* Calculate offset of current frame in RW, and check validity */
- if(sLlcpLocalSequence.ns >= psLocalLlcpSocket->socket_VRA)
- {
- rw_offset = sLlcpLocalSequence.ns - psLocalLlcpSocket->socket_VRA;
- }
- else
- {
- rw_offset = 16 - (psLocalLlcpSocket->socket_VRA - sLlcpLocalSequence.ns);
- }
- if(rw_offset >= psLocalLlcpSocket->localRW)
- {
- /* FRMR 0x01 */
- SFlag = TRUE;
- }
-
- /* Check Info length */
- if(psData->length > (uint32_t)(psLocalLlcpSocket->localMIUX + PHFRINFC_LLCP_MIU_DEFAULT))
- {
- IFlag = TRUE;
- }
-
-
- /* Test NR */
- nr_val = (uint8_t)sLlcpLocalSequence.nr;
- do
- {
- if(nr_val == psLocalLlcpSocket->socket_VS)
- {
- break;
- }
-
- nr_val = (nr_val+1)%16;
-
- if(nr_val == psLocalLlcpSocket->socket_VSA)
- {
- /* FRMR 0x02 */
- RFlag = TRUE;
- break;
- }
- }while(nr_val != sLlcpLocalSequence.nr);
-
-
- if( WFlag != 0 || IFlag != 0 || RFlag != 0 || SFlag != 0)
- {
- /* Send FRMR */
- status = phFriNfc_LlcpTransport_SendFrameReject(psTransport,
- dsap,
- PHFRINFC_LLCP_PTYPE_I,
- ssap,
- &sLlcpLocalSequence,
- WFlag,
- IFlag,
- RFlag,
- SFlag,
- psLocalLlcpSocket->socket_VS,
- psLocalLlcpSocket->socket_VSA,
- psLocalLlcpSocket->socket_VR,
- psLocalLlcpSocket->socket_VRA);
-
- }
- else
- {
- /* Update VSA */
- psLocalLlcpSocket->socket_VSA = (uint8_t)sLlcpLocalSequence.nr;
-
- /* Test if the Linear Buffer length is null */
- if(psLocalLlcpSocket->bufferLinearLength == 0)
- {
- /* Test if a Receive is pending and RW empty */
- if(psLocalLlcpSocket->bSocketRecvPending == TRUE && (psLocalLlcpSocket->indexRwWrite == psLocalLlcpSocket->indexRwRead))
- {
- /* Reset Flag */
- psLocalLlcpSocket->bSocketRecvPending = FALSE;
-
- /* Save I_FRAME into the Receive Buffer */
- memcpy(psLocalLlcpSocket->sSocketRecvBuffer->buffer,psData->buffer,psData->length);
- psLocalLlcpSocket->sSocketRecvBuffer->length = psData->length;
-
- /* Update VR */
- psLocalLlcpSocket->socket_VR = (psLocalLlcpSocket->socket_VR+1)%16;
-
- /* Call the Receive CB */
- psLocalLlcpSocket->pfSocketRecv_Cb(psLocalLlcpSocket->pRecvContext, NFCSTATUS_SUCCESS);
- psLocalLlcpSocket->pfSocketRecv_Cb = NULL;
-
- /* Test if a send is pending with this socket */
- if(psLocalLlcpSocket->bSocketSendPending == TRUE && CHECK_SEND_RW(psLocalLlcpSocket))
- {
- /* Test if a send is pending at LLC layer */
- if(!testAndSetSendPending(psLocalLlcpSocket->psTransport))
- {
- status = static_performSendInfo(psLocalLlcpSocket);
- if (status != NFCSTATUS_SUCCESS && status != NFCSTATUS_PENDING) {
- clearSendPending(psTransport);
- }
- }
- }
- else
- {
- /* RR */
- status = phFriNfc_Llcp_Send_ReceiveReady_Frame(psLocalLlcpSocket);
- }
- }
- else
- {
- /* Test if RW is full */
- if((psLocalLlcpSocket->indexRwWrite - psLocalLlcpSocket->indexRwRead)localRW)
- {
- if(psLocalLlcpSocket->sSocketRwBufferTable[(psLocalLlcpSocket->indexRwWrite%psLocalLlcpSocket->localRW)].length == 0)
- {
- /* Save I_FRAME into the RW Buffers */
- memcpy(psLocalLlcpSocket->sSocketRwBufferTable[(psLocalLlcpSocket->indexRwWrite%psLocalLlcpSocket->localRW)].buffer,psData->buffer,psData->length);
- psLocalLlcpSocket->sSocketRwBufferTable[(psLocalLlcpSocket->indexRwWrite%psLocalLlcpSocket->localRW)].length = psData->length;
-
- if(psLocalLlcpSocket->ReceiverBusyCondition != TRUE)
- {
- /* Receiver Busy condition */
- psLocalLlcpSocket->ReceiverBusyCondition = TRUE;
-
- /* Send RNR */
- status = phFriNfc_Llcp_Send_ReceiveNotReady_Frame(psLocalLlcpSocket);
- }
- /* Update the RW write index */
- psLocalLlcpSocket->indexRwWrite++;
- }
- }
- }
- }
- else
- {
- /* Copy the buffer into the RW buffer */
- memcpy(psLocalLlcpSocket->sSocketRwBufferTable[(psLocalLlcpSocket->indexRwWrite%psLocalLlcpSocket->localRW)].buffer,psData->buffer,psData->length);
-
- /* Update the length */
- psLocalLlcpSocket->sSocketRwBufferTable[(psLocalLlcpSocket->indexRwWrite%psLocalLlcpSocket->localRW)].length = psData->length;
-
- /* Test the length of the available place in the linear buffer */
- dataLengthAvailable = phFriNfc_Llcp_CyclicFifoAvailable(&psLocalLlcpSocket->sCyclicFifoBuffer);
-
- if(dataLengthAvailable >= psLocalLlcpSocket->sSocketRwBufferTable[(psLocalLlcpSocket->indexRwWrite%psLocalLlcpSocket->localRW)].length)
- {
- /* Store Data into the linear buffer */
- dataLengthWrite = phFriNfc_Llcp_CyclicFifoWrite(&psLocalLlcpSocket->sCyclicFifoBuffer,
- psLocalLlcpSocket->sSocketRwBufferTable[(psLocalLlcpSocket->indexRwWrite%psLocalLlcpSocket->localRW)].buffer,
- psLocalLlcpSocket->sSocketRwBufferTable[(psLocalLlcpSocket->indexRwWrite%psLocalLlcpSocket->localRW)].length);
-
- /* Update VR */
- psLocalLlcpSocket->socket_VR = (psLocalLlcpSocket->socket_VR+1)%16;
-
- /* Update the length */
- psLocalLlcpSocket->sSocketRwBufferTable[(psLocalLlcpSocket->indexRwWrite%psLocalLlcpSocket->localRW)].length = 0x00;
-
- /* Test if a Receive Pending*/
- if(psLocalLlcpSocket->bSocketRecvPending == TRUE)
- {
- /* Reset Flag */
- psLocalLlcpSocket->bSocketRecvPending = FALSE;
-
- phFriNfc_LlcpTransport_ConnectionOriented_Recv(psLocalLlcpSocket,
- psLocalLlcpSocket->sSocketRecvBuffer,
- psLocalLlcpSocket->pfSocketRecv_Cb,
- psLocalLlcpSocket->pRecvContext);
- }
-
- /* Test if a send is pending with this socket */
- if((psLocalLlcpSocket->bSocketSendPending == TRUE) && CHECK_SEND_RW(psLocalLlcpSocket))
- {
- /* Test if a send is pending at LLC layer */
- if(!testAndSetSendPending(psLocalLlcpSocket->psTransport))
- {
- status = static_performSendInfo(psLocalLlcpSocket);
- if (status != NFCSTATUS_SUCCESS && status != NFCSTATUS_PENDING) {
- clearSendPending(psTransport);
- }
- }
- }
- else
- {
- /* RR */
- status = phFriNfc_Llcp_Send_ReceiveReady_Frame(psLocalLlcpSocket);
- }
- }
- else
- {
- if(psLocalLlcpSocket->ReceiverBusyCondition != TRUE)
- {
- /* Receiver Busy condition */
- psLocalLlcpSocket->ReceiverBusyCondition = TRUE;
-
- /* Send RNR */
- status = phFriNfc_Llcp_Send_ReceiveNotReady_Frame(psLocalLlcpSocket);
- }
-
- /* Update the RW write index */
- psLocalLlcpSocket->indexRwWrite++;
- }
- }
- }
- }
- else
- {
- /* No active socket*/
- /* I FRAME not Handled */
- }
-}
-
-static void Handle_ReceiveReady_Frame(phFriNfc_LlcpTransport_t *psTransport,
- phNfc_sData_t *psData,
- uint8_t dsap,
- uint8_t ssap)
-{
- NFCSTATUS status = NFCSTATUS_SUCCESS;
- uint8_t index;
- uint8_t socketFound = FALSE;
- uint8_t WFlag = 0;
- uint8_t IFlag = 0;
- uint8_t RFlag = 0;
- uint8_t SFlag = 0;
- uint32_t offset = 0;
- uint8_t nr_val;
-
- phFriNfc_LlcpTransport_Socket_t* psLocalLlcpSocket = NULL;
- phFriNfc_Llcp_sPacketSequence_t sLlcpLocalSequence;
-
- /* Get NS and NR Value of the I Frame*/
- phFriNfc_Llcp_Buffer2Sequence( psData->buffer, offset, &sLlcpLocalSequence);
-
- /* Search a socket waiting for an RR FRAME (Connected State) */
- for(index=0;indexpSocketTable[index].eSocket_State == phFriNfc_LlcpTransportSocket_eSocketConnected
- && psTransport->pSocketTable[index].socket_sSap == dsap
- && psTransport->pSocketTable[index].socket_dSap == ssap)
- {
- /* socket found */
- socketFound = TRUE;
-
- /* Store a pointer to the socket found */
- psLocalLlcpSocket = &psTransport->pSocketTable[index];
- psLocalLlcpSocket->index = psTransport->pSocketTable[index].index;
- break;
- }
- }
-
- /* Test if a socket has been found */
- if(socketFound)
- {
- /* Test NR */
- nr_val = (uint8_t)sLlcpLocalSequence.nr;
- do
- {
- if(nr_val == psLocalLlcpSocket->socket_VS)
- {
- break;
- }
-
- nr_val = (nr_val+1)%16;
-
- if(nr_val == psLocalLlcpSocket->socket_VSA)
- {
- RFlag = TRUE;
- break;
- }
-
- }while(nr_val != sLlcpLocalSequence.nr);
-
-
- /* Test if Info field present */
- if(psData->length > 1)
- {
- WFlag = TRUE;
- IFlag = TRUE;
- }
-
- if (WFlag || IFlag || RFlag || SFlag)
- {
- /* Send FRMR */
- status = phFriNfc_LlcpTransport_SendFrameReject(psTransport,
- dsap, PHFRINFC_LLCP_PTYPE_RR, ssap,
- &sLlcpLocalSequence,
- WFlag, IFlag, RFlag, SFlag,
- psLocalLlcpSocket->socket_VS,
- psLocalLlcpSocket->socket_VSA,
- psLocalLlcpSocket->socket_VR,
- psLocalLlcpSocket->socket_VRA);
- }
- else
- {
- /* Test Receiver Busy condition */
- if(psLocalLlcpSocket->RemoteBusyConditionInfo == TRUE)
- {
- /* Notify the upper layer */
- psLocalLlcpSocket->pSocketErrCb(psLocalLlcpSocket->pContext,PHFRINFC_LLCP_ERR_NOT_BUSY_CONDITION);
- psLocalLlcpSocket->RemoteBusyConditionInfo = FALSE;
- }
- /* Update VSA */
- psLocalLlcpSocket->socket_VSA = (uint8_t)sLlcpLocalSequence.nr;
-
- /* Test if a send is pendind */
- if(psLocalLlcpSocket->bSocketSendPending == TRUE)
- {
- /* Test the RW window */
- if(CHECK_SEND_RW(psLocalLlcpSocket))
- {
- /* Test if a send is pending at LLC layer */
- if(!testAndSetSendPending(psLocalLlcpSocket->psTransport))
- {
- status = static_performSendInfo(psLocalLlcpSocket);
- if (status != NFCSTATUS_SUCCESS && status != NFCSTATUS_PENDING) {
- clearSendPending(psTransport);
- }
- }
- }
- }
- }
- }
- else
- {
- /* No active socket*/
- /* RR Frame not handled*/
- }
-}
-
-static void Handle_ReceiveNotReady_Frame(phFriNfc_LlcpTransport_t *psTransport,
- phNfc_sData_t *psData,
- uint8_t dsap,
- uint8_t ssap)
-{
- NFCSTATUS status = NFCSTATUS_SUCCESS;
- uint8_t index;
- uint8_t socketFound = FALSE;
- bool_t bWFlag = 0;
- bool_t bIFlag = 0;
- bool_t bRFlag = 0;
- bool_t bSFlag = 0;
- uint32_t offset = 0;
- uint8_t nr_val;
-
- phFriNfc_LlcpTransport_Socket_t* psLocalLlcpSocket = NULL;
- phFriNfc_Llcp_sPacketSequence_t sLlcpLocalSequence;
-
- /* Get NS and NR Value of the I Frame*/
- phFriNfc_Llcp_Buffer2Sequence( psData->buffer, offset, &sLlcpLocalSequence);
-
- /* Search a socket waiting for an RNR FRAME (Connected State) */
- for(index=0;indexpSocketTable[index].eSocket_State == phFriNfc_LlcpTransportSocket_eSocketConnected
- && psTransport->pSocketTable[index].socket_sSap == dsap
- && psTransport->pSocketTable[index].socket_dSap == ssap)
- {
- /* socket found */
- socketFound = TRUE;
-
- /* Store a pointer to the socket found */
- psLocalLlcpSocket = &psTransport->pSocketTable[index];
- break;
- }
- }
-
- /* Test if a socket has been found */
- if(socketFound)
- {
- /* Test NR */
- nr_val = (uint8_t)sLlcpLocalSequence.nr;
- do
- {
-
- if(nr_val == psLocalLlcpSocket->socket_VS)
- {
- break;
- }
-
- nr_val = (nr_val+1)%16;
-
- if(nr_val == psLocalLlcpSocket->socket_VSA)
- {
- /* FRMR 0x02 */
- bRFlag = TRUE;
- break;
- }
- }while(nr_val != sLlcpLocalSequence.nr);
-
- /* Test if Info field present */
- if(psData->length > 1)
- {
- /* Send FRMR */
- bWFlag = TRUE;
- bIFlag = TRUE;
- }
-
- if( bWFlag != 0 || bIFlag != 0 || bRFlag != 0 || bSFlag != 0)
- {
- /* Send FRMR */
- status = phFriNfc_LlcpTransport_SendFrameReject(psTransport,
- dsap, PHFRINFC_LLCP_PTYPE_RNR, ssap,
- &sLlcpLocalSequence,
- bWFlag, bIFlag, bRFlag, bSFlag,
- psLocalLlcpSocket->socket_VS,
- psLocalLlcpSocket->socket_VSA,
- psLocalLlcpSocket->socket_VR,
- psLocalLlcpSocket->socket_VRA);
- }
- else
- {
- /* Notify the upper layer */
- psLocalLlcpSocket->pSocketErrCb(psTransport->pSocketTable[index].pContext,PHFRINFC_LLCP_ERR_BUSY_CONDITION);
- psLocalLlcpSocket->RemoteBusyConditionInfo = TRUE;
-
- /* Update VSA */
- psLocalLlcpSocket->socket_VSA = (uint8_t)sLlcpLocalSequence.nr;
-
- /* Test if a send is pendind */
- if(psLocalLlcpSocket->bSocketSendPending == TRUE && CHECK_SEND_RW(psLocalLlcpSocket))
- {
- /* Test if a send is pending at LLC layer */
- if(!testAndSetSendPending(psLocalLlcpSocket->psTransport))
- {
- status = static_performSendInfo(psLocalLlcpSocket);
- if (status != NFCSTATUS_SUCCESS && status != NFCSTATUS_PENDING) {
- clearSendPending(psTransport);
- }
- }
- }
- }
- }
- else
- {
- /* No active socket*/
- /* RNR Frame not handled*/
- }
-}
-
-static void Handle_FrameReject_Frame(phFriNfc_LlcpTransport_t *psTransport,
- uint8_t dsap,
- uint8_t ssap)
-{
- NFCSTATUS status = NFCSTATUS_SUCCESS;
- uint8_t index;
- uint8_t socketFound = FALSE;
-
- /* Search a socket waiting for a FRAME */
- for(index=0;indexpSocketTable[index].socket_sSap == dsap
- && psTransport->pSocketTable[index].socket_dSap == ssap)
- {
- /* socket found */
- socketFound = TRUE;
- break;
- }
- }
-
- /* Test if a socket has been found */
- if(socketFound)
- {
- /* Set socket state to disconnected */
- psTransport->pSocketTable[index].eSocket_State = phFriNfc_LlcpTransportSocket_eSocketDisconnected;
-
- /* Call ErrCB due to a FRMR*/
- psTransport->pSocketTable[index].pSocketErrCb( psTransport->pSocketTable[index].pContext,PHFRINFC_LLCP_ERR_FRAME_REJECTED);
-
- /* Close the socket */
- status = phFriNfc_LlcpTransport_ConnectionOriented_Close(&psTransport->pSocketTable[index]);
- }
- else
- {
- /* No active socket*/
- /* FRMR Frame not handled*/
- }
-}
-
-/* TODO: comment function Handle_ConnectionOriented_IncommingFrame */
-void Handle_ConnectionOriented_IncommingFrame(phFriNfc_LlcpTransport_t *psTransport,
- phNfc_sData_t *psData,
- uint8_t dsap,
- uint8_t ptype,
- uint8_t ssap)
-{
- phFriNfc_Llcp_sPacketSequence_t sSequence = {0,0};
-
- switch(ptype)
- {
- case PHFRINFC_LLCP_PTYPE_CONNECT:
- {
- Handle_ConnectionFrame(psTransport,
- psData,
- dsap,
- ssap);
- }break;
-
- case PHFRINFC_LLCP_PTYPE_DISC:
- {
- Handle_DisconnectFrame(psTransport,
- dsap,
- ssap);
- }break;
-
- case PHFRINFC_LLCP_PTYPE_CC:
- {
- Handle_ConnectionCompleteFrame(psTransport,
- psData,
- dsap,
- ssap);
- }break;
-
- case PHFRINFC_LLCP_PTYPE_DM:
- {
- Handle_DisconnetModeFrame(psTransport,
- psData,
- dsap,
- ssap);
- }break;
-
- case PHFRINFC_LLCP_PTYPE_FRMR:
- {
- Handle_FrameReject_Frame(psTransport,
- dsap,
- ssap);
- }break;
-
- case PHFRINFC_LLCP_PTYPE_I:
- {
- Handle_Receive_IFrame(psTransport,
- psData,
- dsap,
- ssap);
- }break;
-
- case PHFRINFC_LLCP_PTYPE_RR:
- {
- Handle_ReceiveReady_Frame(psTransport,
- psData,
- dsap,
- ssap);
- }break;
-
- case PHFRINFC_LLCP_PTYPE_RNR:
- {
- Handle_ReceiveNotReady_Frame(psTransport,
- psData,
- dsap,
- ssap);
- }break;
-
- case PHFRINFC_LLCP_PTYPE_RESERVED1:
- case PHFRINFC_LLCP_PTYPE_RESERVED2:
- case PHFRINFC_LLCP_PTYPE_RESERVED3:
- {
- phFriNfc_LlcpTransport_SendFrameReject( psTransport,
- dsap, ptype, ssap,
- &sSequence,
- TRUE, FALSE, FALSE, FALSE,
- 0, 0, 0, 0);
- }break;
- }
-}
-
-/**
-* \ingroup grp_lib_nfc
-* \brief Get the local options of a socket.
-*
-* This function returns the local options (maximum packet size and receive window size) used
-* for a given connection-oriented socket. This function shall not be used with connectionless
-* sockets.
-*
-* \param[out] pLlcpSocket A pointer to a phFriNfc_LlcpTransport_Socket_t.
-* \param[in] psLocalOptions A pointer to be filled with the local options of the socket.
-*
-* \retval NFCSTATUS_SUCCESS Operation successful.
-* \retval NFCSTATUS_INVALID_PARAMETER One or more of the supplied parameters
-* could not be properly interpreted.
-* \retval NFCSTATUS_INVALID_STATE The socket is not in a valid state, or not of
-* a valid type to perform the requsted operation.
-* \retval NFCSTATUS_NOT_INITIALISED Indicates stack is not yet initialized.
-* \retval NFCSTATUS_SHUTDOWN Shutdown in progress.
-* \retval NFCSTATUS_FAILED Operation failed.
-*/
-NFCSTATUS phFriNfc_LlcpTransport_ConnectionOriented_SocketGetLocalOptions(phFriNfc_LlcpTransport_Socket_t *pLlcpSocket,
- phLibNfc_Llcp_sSocketOptions_t *psLocalOptions)
-{
- NFCSTATUS status = NFCSTATUS_SUCCESS;
-
- /* Get Local MIUX */
- psLocalOptions->miu = pLlcpSocket->sSocketOption.miu;
-
- /* Get Local Receive Window */
- psLocalOptions->rw = pLlcpSocket->sSocketOption.rw;
-
- return status;
-}
-
-/**
-* \ingroup grp_lib_nfc
-* \brief Get the local options of a socket.
-*
-* This function returns the remote options (maximum packet size and receive window size) used
-* for a given connection-oriented socket. This function shall not be used with connectionless
-* sockets.
-*
-* \param[out] pLlcpSocket A pointer to a phFriNfc_LlcpTransport_Socket_t.
-* \param[in] psRemoteOptions A pointer to be filled with the remote options of the socket.
-*
-* \retval NFCSTATUS_SUCCESS Operation successful.
-* \retval NFCSTATUS_INVALID_PARAMETER One or more of the supplied parameters
-* could not be properly interpreted.
-* \retval NFCSTATUS_INVALID_STATE The socket is not in a valid state, or not of
-* a valid type to perform the requsted operation.
-* \retval NFCSTATUS_NOT_INITIALISED Indicates stack is not yet initialized.
-* \retval NFCSTATUS_SHUTDOWN Shutdown in progress.
-* \retval NFCSTATUS_FAILED Operation failed.
-*/
-NFCSTATUS phFriNfc_LlcpTransport_ConnectionOriented_SocketGetRemoteOptions(phFriNfc_LlcpTransport_Socket_t* pLlcpSocket,
- phLibNfc_Llcp_sSocketOptions_t* psRemoteOptions)
-{
- NFCSTATUS status = NFCSTATUS_SUCCESS;
-
- /* Get Remote MIUX */
- psRemoteOptions->miu = pLlcpSocket->remoteMIU;
-
- /* Get Remote Receive Window */
- psRemoteOptions->rw = pLlcpSocket->remoteRW;
-
- return status;
-}
-
-
-/**
-* \ingroup grp_fri_nfc
-* \brief Listen for incoming connection requests on a socket.
-*
-* This function switches a socket into a listening state and registers a callback on
-* incoming connection requests. In this state, the socket is not able to communicate
-* directly. The listening state is only available for connection-oriented sockets
-* which are still not connected. The socket keeps listening until it is closed, and
-* thus can trigger several times the pListen_Cb callback.
-*
-*
-* \param[in] pLlcpSocket A pointer to a phFriNfc_LlcpTransport_Socket_t.
-* \param[in] pListen_Cb The callback to be called each time the
-* socket receive a connection request.
-* \param[in] pContext Upper layer context to be returned in
-* the callback.
-*
-* \retval NFCSTATUS_SUCCESS Operation successful.
-* \retval NFCSTATUS_INVALID_PARAMETER One or more of the supplied parameters
-* could not be properly interpreted.
-* \retval NFCSTATUS_INVALID_STATE The socket is not in a valid state to switch
-* to listening state.
-* \retval NFCSTATUS_FAILED Operation failed.
-*/
-NFCSTATUS phFriNfc_LlcpTransport_ConnectionOriented_Listen(phFriNfc_LlcpTransport_Socket_t* pLlcpSocket,
- pphFriNfc_LlcpTransportSocketListenCb_t pListen_Cb,
- void* pContext)
-{
- NFCSTATUS status = NFCSTATUS_SUCCESS;
-
- /* Store the listen callback */
- pLlcpSocket->pfSocketListen_Cb = pListen_Cb;
-
- /* store the context */
- pLlcpSocket->pListenContext = pContext;
-
- /* Set RecvPending to TRUE */
- pLlcpSocket->bSocketListenPending = TRUE;
-
- /* Set the socket state*/
- pLlcpSocket->eSocket_State = phFriNfc_LlcpTransportSocket_eSocketRegistered;
-
- return status;
-}
-
-/**
-* \ingroup grp_fri_nfc
-* \brief Accept an incoming connection request for a socket.
-*
-* This functions allows the client to accept an incoming connection request.
-* It must be used with the socket provided within the listen callback. The socket
-* is implicitly switched to the connected state when the function is called.
-*
-* \param[in] pLlcpSocket A pointer to a phFriNfc_LlcpTransport_Socket_t.
-* \param[in] psOptions The options to be used with the socket.
-* \param[in] psWorkingBuffer A working buffer to be used by the library.
-* \param[in] pErr_Cb The callback to be called each time the accepted socket
-* is in error.
-* \param[in] pAccept_RspCb The callback to be called when the Accept operation is completed
-* \param[in] pContext Upper layer context to be returned in the callback.
-*
-* \retval NFCSTATUS_SUCCESS Operation successful.
-* \retval NFCSTATUS_INVALID_PARAMETER One or more of the supplied parameters
-* could not be properly interpreted.
-* \retval NFCSTATUS_BUFFER_TOO_SMALL The working buffer is too small for the MIU and RW
-* declared in the options.
-* \retval NFCSTATUS_FAILED Operation failed.
-*/
-NFCSTATUS phFriNfc_LlcpTransport_ConnectionOriented_Accept(phFriNfc_LlcpTransport_Socket_t* pLlcpSocket,
- phFriNfc_LlcpTransport_sSocketOptions_t* psOptions,
- phNfc_sData_t* psWorkingBuffer,
- pphFriNfc_LlcpTransportSocketErrCb_t pErr_Cb,
- pphFriNfc_LlcpTransportSocketAcceptCb_t pAccept_RspCb,
- void* pContext)
-
-{
- NFCSTATUS status = NFCSTATUS_SUCCESS;
-
- uint32_t offset = 0;
- uint8_t miux[2];
- uint8_t i;
- /* Store the options in the socket */
- memcpy(&pLlcpSocket->sSocketOption, psOptions, sizeof(phFriNfc_LlcpTransport_sSocketOptions_t));
-
- /* Set socket local params (MIUX & RW) */
- pLlcpSocket ->localMIUX = (pLlcpSocket->sSocketOption.miu - PHFRINFC_LLCP_MIU_DEFAULT) & PHFRINFC_LLCP_TLV_MIUX_MASK;
- pLlcpSocket ->localRW = pLlcpSocket->sSocketOption.rw & PHFRINFC_LLCP_TLV_RW_MASK;
-
- /* Set the pointer and the length for the Receive Window Buffer */
- for(i=0;ilocalRW;i++)
- {
- pLlcpSocket->sSocketRwBufferTable[i].buffer = psWorkingBuffer->buffer + (i*pLlcpSocket->sSocketOption.miu);
- pLlcpSocket->sSocketRwBufferTable[i].length = 0;
- }
-
- /* Set the pointer and the length for the Send Buffer */
- pLlcpSocket->sSocketSendBuffer.buffer = psWorkingBuffer->buffer + pLlcpSocket->bufferRwMaxLength;
- pLlcpSocket->sSocketSendBuffer.length = pLlcpSocket->bufferSendMaxLength;
-
- /* Set the pointer and the length for the Linear Buffer */
- pLlcpSocket->sSocketLinearBuffer.buffer = psWorkingBuffer->buffer + pLlcpSocket->bufferRwMaxLength + pLlcpSocket->bufferSendMaxLength;
- pLlcpSocket->sSocketLinearBuffer.length = pLlcpSocket->bufferLinearLength;
-
- if(pLlcpSocket->sSocketLinearBuffer.length != 0)
- {
- /* Init Cyclic Fifo */
- phFriNfc_Llcp_CyclicFifoInit(&pLlcpSocket->sCyclicFifoBuffer,
- pLlcpSocket->sSocketLinearBuffer.buffer,
- pLlcpSocket->sSocketLinearBuffer.length);
- }
-
- pLlcpSocket->pSocketErrCb = pErr_Cb;
- pLlcpSocket->pContext = pContext;
-
- /* store the pointer to the Accept callback */
- pLlcpSocket->pfSocketAccept_Cb = pAccept_RspCb;
- pLlcpSocket->pAcceptContext = pContext;
-
- /* Reset the socket_VS,socket_VR,socket_VSA and socket_VRA variables */
- pLlcpSocket->socket_VR = 0;
- pLlcpSocket->socket_VRA = 0;
- pLlcpSocket->socket_VS = 0;
- pLlcpSocket->socket_VSA = 0;
-
- /* MIUX */
- if(pLlcpSocket->localMIUX != PHFRINFC_LLCP_MIUX_DEFAULT)
- {
- /* Encode MIUX value */
- phFriNfc_Llcp_EncodeMIUX(pLlcpSocket->localMIUX,
- miux);
-
- /* Encode MIUX in TLV format */
- status = phFriNfc_Llcp_EncodeTLV(&pLlcpSocket->sSocketSendBuffer,
- &offset,
- PHFRINFC_LLCP_TLV_TYPE_MIUX,
- PHFRINFC_LLCP_TLV_LENGTH_MIUX,
- miux);
- if(status != NFCSTATUS_SUCCESS)
- {
- /* Call the CB */
- status = PHNFCSTVAL(CID_FRI_NFC_LLCP_TRANSPORT, NFCSTATUS_FAILED);
- goto clean_and_return;
- }
- }
-
- /* Receive Window */
- if(pLlcpSocket->sSocketOption.rw != PHFRINFC_LLCP_RW_DEFAULT)
- {
- /* Encode RW value */
- phFriNfc_Llcp_EncodeRW(&pLlcpSocket->sSocketOption.rw);
-
- /* Encode RW in TLV format */
- status = phFriNfc_Llcp_EncodeTLV(&pLlcpSocket->sSocketSendBuffer,
- &offset,
- PHFRINFC_LLCP_TLV_TYPE_RW,
- PHFRINFC_LLCP_TLV_LENGTH_RW,
- &pLlcpSocket->sSocketOption.rw);
- if(status != NFCSTATUS_SUCCESS)
- {
- /* Call the CB */
- status = PHNFCSTVAL(CID_FRI_NFC_LLCP_TRANSPORT, NFCSTATUS_FAILED);
- goto clean_and_return;
- }
- }
-
-
- /* Test if a send is pending */
- if(testAndSetSendPending(pLlcpSocket->psTransport))
- {
- pLlcpSocket->bSocketAcceptPending = TRUE;
-
- /* Update Send Buffer length value */
- pLlcpSocket->sSocketSendBuffer.length = offset;
-
- status = NFCSTATUS_PENDING;
- }
- else
- {
- /* Fill the psLlcpHeader stuture with the DSAP,CC PTYPE and the SSAP */
- pLlcpSocket->sLlcpHeader.dsap = pLlcpSocket->socket_dSap;
- pLlcpSocket->sLlcpHeader.ptype = PHFRINFC_LLCP_PTYPE_CC;
- pLlcpSocket->sLlcpHeader.ssap = pLlcpSocket->socket_sSap;
-
- /* Set the socket state to accepted */
- pLlcpSocket->eSocket_State = phFriNfc_LlcpTransportSocket_eSocketAccepted;
-
- /* Update Send Buffer length value */
- pLlcpSocket->sSocketSendBuffer.length = offset;
-
- /* Send a CC Frame */
- status = phFriNfc_LlcpTransport_LinkSend(pLlcpSocket->psTransport,
- &pLlcpSocket->sLlcpHeader,
- NULL,
- &pLlcpSocket->sSocketSendBuffer,
- phFriNfc_LlcpTransport_ConnectionOriented_SendLlcp_CB,
- pLlcpSocket->index,
- pLlcpSocket->psTransport);
- if (status != NFCSTATUS_SUCCESS && status != NFCSTATUS_PENDING) {
- clearSendPending(pLlcpSocket->psTransport);
- }
- }
-
-clean_and_return:
- if(status != NFCSTATUS_PENDING)
- {
- LLCP_PRINT("Release Accept callback");
- pLlcpSocket->pfSocketAccept_Cb = NULL;
- pLlcpSocket->pAcceptContext = NULL;
- }
-
- return status;
-}
-
- /**
-* \ingroup grp_fri_nfc
-* \brief Reject an incoming connection request for a socket.
-*
-* This functions allows the client to reject an incoming connection request.
-* It must be used with the socket provided within the listen callback. The socket
-* is implicitly closed when the function is called.
-*
-* \param[in] pLlcpSocket A pointer to a phFriNfc_LlcpTransport_Socket_t.
-*
-* \retval NFCSTATUS_SUCCESS Operation successful.
-* \retval NFCSTATUS_INVALID_PARAMETER One or more of the supplied parameters
-* could not be properly interpreted.
-* \retval NFCSTATUS_FAILED Operation failed.
-*/
-NFCSTATUS phLibNfc_LlcpTransport_ConnectionOriented_Reject( phFriNfc_LlcpTransport_Socket_t* pLlcpSocket,
- pphFriNfc_LlcpTransportSocketRejectCb_t pReject_RspCb,
- void *pContext)
-{
- NFCSTATUS status = NFCSTATUS_SUCCESS;
-
- /* Set the state of the socket */
- pLlcpSocket->eSocket_State = phFriNfc_LlcpTransportSocket_eSocketRejected;
-
- /* Store the Reject callback */
- pLlcpSocket->pfSocketSend_Cb = pReject_RspCb;
- pLlcpSocket->pRejectContext = pContext;
-
- /* Send a DM*/
- status = phFriNfc_LlcpTransport_SendDisconnectMode(pLlcpSocket->psTransport,
- pLlcpSocket->socket_dSap,
- pLlcpSocket->socket_sSap,
- PHFRINFC_LLCP_DM_OPCODE_CONNECT_REJECTED);
-
- return status;
-}
-
-/**
-* \ingroup grp_fri_nfc
-* \brief Try to establish connection with a socket on a remote SAP.
-*
-* This function tries to connect to a given SAP on the remote peer. If the
-* socket is not bound to a local SAP, it is implicitly bound to a free SAP.
-*
-* \param[in] pLlcpSocket A pointer to a phFriNfc_LlcpTransport_Socket_t.
-* \param[in] nSap The destination SAP to connect to.
-* \param[in] psUri The URI corresponding to the destination SAP to connect to.
-* \param[in] pConnect_RspCb The callback to be called when the connection
-* operation is completed.
-* \param[in] pContext Upper layer context to be returned in
-* the callback.
-*
-* \retval NFCSTATUS_SUCCESS Operation successful.
-* \retval NFCSTATUS_INVALID_PARAMETER One or more of the supplied parameters
-* could not be properly interpreted.
-* \retval NFCSTATUS_PENDING Connection operation is in progress,
-* pConnect_RspCb will be called upon completion.
-* \retval NFCSTATUS_INVALID_STATE The socket is not in a valid state, or not of
-* a valid type to perform the requsted operation.
-* \retval NFCSTATUS_FAILED Operation failed.
-*/
-NFCSTATUS phFriNfc_LlcpTransport_ConnectionOriented_Connect( phFriNfc_LlcpTransport_Socket_t* pLlcpSocket,
- uint8_t nSap,
- phNfc_sData_t* psUri,
- pphFriNfc_LlcpTransportSocketConnectCb_t pConnect_RspCb,
- void* pContext)
-{
- NFCSTATUS status = NFCSTATUS_SUCCESS;
- uint32_t offset = 0;
- uint8_t miux[2];
-
- /* Test if a nSap is present */
- if(nSap != PHFRINFC_LLCP_SAP_DEFAULT)
- {
- /* Set DSAP port number with the nSap value */
- pLlcpSocket->socket_dSap = nSap;
- }
- else
- {
- /* Set DSAP port number with the SDP port number */
- pLlcpSocket->socket_dSap = PHFRINFC_LLCP_SAP_SDP;
- }
-
- /* Store the Connect callback and context */
- pLlcpSocket->pfSocketConnect_Cb = pConnect_RspCb;
- pLlcpSocket->pConnectContext = pContext;
-
- /* Set the socket Header */
- pLlcpSocket->sLlcpHeader.dsap = pLlcpSocket->socket_dSap;
- pLlcpSocket->sLlcpHeader.ptype = PHFRINFC_LLCP_PTYPE_CONNECT;
- pLlcpSocket->sLlcpHeader.ssap = pLlcpSocket->socket_sSap;
-
- /* MIUX */
- if(pLlcpSocket->localMIUX != PHFRINFC_LLCP_MIUX_DEFAULT)
- {
- /* Encode MIUX value */
- phFriNfc_Llcp_EncodeMIUX(pLlcpSocket->localMIUX,
- miux);
-
- /* Encode MIUX in TLV format */
- status = phFriNfc_Llcp_EncodeTLV(&pLlcpSocket->sSocketSendBuffer,
- &offset,
- PHFRINFC_LLCP_TLV_TYPE_MIUX,
- PHFRINFC_LLCP_TLV_LENGTH_MIUX,
- miux);
- if(status != NFCSTATUS_SUCCESS)
- {
- status = PHNFCSTVAL(CID_FRI_NFC_LLCP_TRANSPORT, NFCSTATUS_FAILED);
- goto clean_and_return;
- }
- }
-
- /* Receive Window */
- if(pLlcpSocket->sSocketOption.rw != PHFRINFC_LLCP_RW_DEFAULT)
- {
- /* Encode RW value */
- phFriNfc_Llcp_EncodeRW(&pLlcpSocket->sSocketOption.rw);
-
- /* Encode RW in TLV format */
- status = phFriNfc_Llcp_EncodeTLV(&pLlcpSocket->sSocketSendBuffer,
- &offset,
- PHFRINFC_LLCP_TLV_TYPE_RW,
- PHFRINFC_LLCP_TLV_LENGTH_RW,
- &pLlcpSocket->sSocketOption.rw);
- if(status != NFCSTATUS_SUCCESS)
- {
- status = PHNFCSTVAL(CID_FRI_NFC_LLCP_TRANSPORT, NFCSTATUS_FAILED);
- goto clean_and_return;
- }
- }
-
- /* Test if a Service Name is present */
- if(psUri != NULL)
- {
- /* Encode SN in TLV format */
- status = phFriNfc_Llcp_EncodeTLV(&pLlcpSocket->sSocketSendBuffer,
- &offset,
- PHFRINFC_LLCP_TLV_TYPE_SN,
- (uint8_t)psUri->length,
- psUri->buffer);
- if(status != NFCSTATUS_SUCCESS)
- {
- status = PHNFCSTVAL(CID_FRI_NFC_LLCP_TRANSPORT, NFCSTATUS_FAILED);
- goto clean_and_return;
- }
- }
-
- /* Test if a send is pending */
- if(testAndSetSendPending(pLlcpSocket->psTransport))
- {
- pLlcpSocket->bSocketConnectPending = TRUE;
-
- /* Update Send Buffer length value */
- pLlcpSocket->sSocketSendBuffer.length = offset;
-
- status = NFCSTATUS_PENDING;
- }
- else
- {
- /* Update Send Buffer length value */
- pLlcpSocket->sSocketSendBuffer.length = offset;
-
- /* Set the socket in connecting state */
- pLlcpSocket->eSocket_State = phFriNfc_LlcpTransportSocket_eSocketConnecting;
-
- status = phFriNfc_LlcpTransport_LinkSend(pLlcpSocket->psTransport,
- &pLlcpSocket->sLlcpHeader,
- NULL,
- &pLlcpSocket->sSocketSendBuffer,
- phFriNfc_LlcpTransport_ConnectionOriented_SendLlcp_CB,
- pLlcpSocket->index,
- pLlcpSocket->psTransport);
- if (status != NFCSTATUS_SUCCESS && status != NFCSTATUS_PENDING) {
- clearSendPending(pLlcpSocket->psTransport);
- }
- }
-
-clean_and_return:
- if(status != NFCSTATUS_PENDING)
- {
- LLCP_PRINT("Release Connect callback");
- pLlcpSocket->pfSocketConnect_Cb = NULL;
- pLlcpSocket->pConnectContext = NULL;
- }
-
- return status;
-}
-
-
-/**
-* \ingroup grp_lib_nfc
-* \brief Disconnect a currently connected socket.
-*
-* This function initiates the disconnection of a previously connected socket.
-*
-* \param[in] pLlcpSocket A pointer to a phFriNfc_LlcpTransport_Socket_t.
-* \param[in] pDisconnect_RspCb The callback to be called when the
-* operation is completed.
-* \param[in] pContext Upper layer context to be returned in
-* the callback.
-*
-* \retval NFCSTATUS_SUCCESS Operation successful.
-* \retval NFCSTATUS_INVALID_PARAMETER One or more of the supplied parameters
-* could not be properly interpreted.
-* \retval NFCSTATUS_PENDING Disconnection operation is in progress,
-* pDisconnect_RspCb will be called upon completion.
-* \retval NFCSTATUS_INVALID_STATE The socket is not in a valid state, or not of
-* a valid type to perform the requsted operation.
-* \retval NFCSTATUS_NOT_INITIALISED Indicates stack is not yet initialized.
-* \retval NFCSTATUS_SHUTDOWN Shutdown in progress.
-* \retval NFCSTATUS_FAILED Operation failed.
-*/
-NFCSTATUS phLibNfc_LlcpTransport_ConnectionOriented_Disconnect(phFriNfc_LlcpTransport_Socket_t* pLlcpSocket,
- pphLibNfc_LlcpSocketDisconnectCb_t pDisconnect_RspCb,
- void* pContext)
-{
- NFCSTATUS status = NFCSTATUS_SUCCESS;
-
- /* Store the Disconnect callback and context*/
- pLlcpSocket->pfSocketDisconnect_Cb = pDisconnect_RspCb;
- pLlcpSocket->pDisconnectContext = pContext;
-
- /* Set the socket in connecting state */
- pLlcpSocket->eSocket_State = phFriNfc_LlcpTransportSocket_eSocketDisconnecting;
-
- /* Test if a send IFRAME is pending with this socket */
- if((pLlcpSocket->bSocketSendPending == TRUE) || (pLlcpSocket->bSocketRecvPending == TRUE))
- {
- pLlcpSocket->bSocketSendPending = FALSE;
- pLlcpSocket->bSocketRecvPending = FALSE;
-
- /* Call the send CB, a disconnect abort the send request */
- if (pLlcpSocket->pfSocketSend_Cb != NULL)
- {
- /* Copy CB + context in local variables */
- pphFriNfc_LlcpTransportSocketSendCb_t pfSendCb = pLlcpSocket->pfSocketSend_Cb;
- void* pSendContext = pLlcpSocket->pSendContext;
- /* Reset CB + context */
- pLlcpSocket->pfSocketSend_Cb = NULL;
- pLlcpSocket->pSendContext = NULL;
- /* Perform callback */
- pfSendCb(pSendContext, NFCSTATUS_FAILED);
- }
- /* Call the send CB, a disconnect abort the receive request */
- if (pLlcpSocket->pfSocketRecv_Cb != NULL)
- {
- /* Copy CB + context in local variables */
- pphFriNfc_LlcpTransportSocketRecvCb_t pfRecvCb = pLlcpSocket->pfSocketRecv_Cb;
- void* pRecvContext = pLlcpSocket->pRecvContext;
- /* Reset CB + context */
- pLlcpSocket->pfSocketRecv_Cb = NULL;
- pLlcpSocket->pRecvContext = NULL;
- /* Perform callback */
- pfRecvCb(pRecvContext, NFCSTATUS_FAILED);
- }
- }
-
- /* Test if a send is pending */
- if( testAndSetSendPending(pLlcpSocket->psTransport))
- {
- pLlcpSocket->bSocketDiscPending = TRUE;
- status = NFCSTATUS_PENDING;
- }
- else
- {
- /* Set the socket Header */
- pLlcpSocket->sLlcpHeader.dsap = pLlcpSocket->socket_dSap;
- pLlcpSocket->sLlcpHeader.ptype = PHFRINFC_LLCP_PTYPE_DISC;
- pLlcpSocket->sLlcpHeader.ssap = pLlcpSocket->socket_sSap;
-
- status = phFriNfc_LlcpTransport_LinkSend(pLlcpSocket->psTransport,
- &pLlcpSocket->sLlcpHeader,
- NULL,
- NULL,
- phFriNfc_LlcpTransport_ConnectionOriented_SendLlcp_CB,
- pLlcpSocket->index,
- pLlcpSocket->psTransport);
- if(status != NFCSTATUS_SUCCESS && status != NFCSTATUS_PENDING)
- {
- clearSendPending(pLlcpSocket->psTransport);
- LLCP_PRINT("Release Disconnect callback");
- pLlcpSocket->pfSocketDisconnect_Cb = NULL;
- pLlcpSocket->pDisconnectContext = NULL;
- }
- }
-
- return status;
-}
-
-/* TODO: comment function phFriNfc_LlcpTransport_Connectionless_SendTo_CB */
-static void phFriNfc_LlcpTransport_ConnectionOriented_DisconnectClose_CB(void* pContext,
- NFCSTATUS status)
-{
- phFriNfc_LlcpTransport_Socket_t *pLlcpSocket = (phFriNfc_LlcpTransport_Socket_t*)pContext;
-
- if(status == NFCSTATUS_SUCCESS)
- {
- /* Reset the pointer to the socket closed */
- pLlcpSocket->eSocket_State = phFriNfc_LlcpTransportSocket_eSocketDefault;
- pLlcpSocket->eSocket_Type = phFriNfc_LlcpTransport_eDefaultType;
- pLlcpSocket->pContext = NULL;
- pLlcpSocket->pSocketErrCb = NULL;
- pLlcpSocket->socket_sSap = PHFRINFC_LLCP_SAP_DEFAULT;
- pLlcpSocket->socket_dSap = PHFRINFC_LLCP_SAP_DEFAULT;
- pLlcpSocket->bSocketRecvPending = FALSE;
- pLlcpSocket->bSocketSendPending = FALSE;
- pLlcpSocket->bSocketListenPending = FALSE;
- pLlcpSocket->bSocketDiscPending = FALSE;
- pLlcpSocket->socket_VS = 0;
- pLlcpSocket->socket_VSA = 0;
- pLlcpSocket->socket_VR = 0;
- pLlcpSocket->socket_VRA = 0;
-
- pLlcpSocket->indexRwRead = 0;
- pLlcpSocket->indexRwWrite = 0;
-
- phFriNfc_LlcpTransport_ConnectionOriented_Abort(pLlcpSocket);
-
- memset(&pLlcpSocket->sSocketOption, 0x00, sizeof(phFriNfc_LlcpTransport_sSocketOptions_t));
-
- if (pLlcpSocket->sServiceName.buffer != NULL) {
- phOsalNfc_FreeMemory(pLlcpSocket->sServiceName.buffer);
- }
- pLlcpSocket->sServiceName.buffer = NULL;
- pLlcpSocket->sServiceName.length = 0;
- }
- else
- {
- /* Disconnect close Error */
- }
-}
-
-/**
-* \ingroup grp_fri_nfc
-* \brief Close a socket on a LLCP-connected device.
-*
-* This function closes a LLCP socket previously created using phFriNfc_LlcpTransport_Socket.
-* If the socket was connected, it is first disconnected, and then closed.
-*
-* \param[in] pLlcpSocket A pointer to a phFriNfc_LlcpTransport_Socket_t.
-
-* \retval NFCSTATUS_SUCCESS Operation successful.
-* \retval NFCSTATUS_INVALID_PARAMETER One or more of the supplied parameters
-* could not be properly interpreted.
-* \retval NFCSTATUS_FAILED Operation failed.
-*/
-NFCSTATUS phFriNfc_LlcpTransport_ConnectionOriented_Close(phFriNfc_LlcpTransport_Socket_t* pLlcpSocket)
-{
- NFCSTATUS status = NFCSTATUS_SUCCESS;
-
- if(pLlcpSocket->eSocket_State == phFriNfc_LlcpTransportSocket_eSocketConnected)
- {
- status = phLibNfc_LlcpTransport_ConnectionOriented_Disconnect(pLlcpSocket,
- phFriNfc_LlcpTransport_ConnectionOriented_DisconnectClose_CB,
- pLlcpSocket);
- }
- else
- {
- LLCP_PRINT("Socket not connected, no need to disconnect");
- /* Reset the pointer to the socket closed */
- pLlcpSocket->eSocket_State = phFriNfc_LlcpTransportSocket_eSocketDefault;
- pLlcpSocket->eSocket_Type = phFriNfc_LlcpTransport_eDefaultType;
- pLlcpSocket->pContext = NULL;
- pLlcpSocket->pSocketErrCb = NULL;
- pLlcpSocket->socket_sSap = PHFRINFC_LLCP_SAP_DEFAULT;
- pLlcpSocket->socket_dSap = PHFRINFC_LLCP_SAP_DEFAULT;
- pLlcpSocket->bSocketRecvPending = FALSE;
- pLlcpSocket->bSocketSendPending = FALSE;
- pLlcpSocket->bSocketListenPending = FALSE;
- pLlcpSocket->bSocketDiscPending = FALSE;
- pLlcpSocket->RemoteBusyConditionInfo = FALSE;
- pLlcpSocket->ReceiverBusyCondition = FALSE;
- pLlcpSocket->socket_VS = 0;
- pLlcpSocket->socket_VSA = 0;
- pLlcpSocket->socket_VR = 0;
- pLlcpSocket->socket_VRA = 0;
-
- pLlcpSocket->indexRwRead = 0;
- pLlcpSocket->indexRwWrite = 0;
-
- phFriNfc_LlcpTransport_ConnectionOriented_Abort(pLlcpSocket);
-
- memset(&pLlcpSocket->sSocketOption, 0x00, sizeof(phFriNfc_LlcpTransport_sSocketOptions_t));
-
- if (pLlcpSocket->sServiceName.buffer != NULL) {
- phOsalNfc_FreeMemory(pLlcpSocket->sServiceName.buffer);
- }
- pLlcpSocket->sServiceName.buffer = NULL;
- pLlcpSocket->sServiceName.length = 0;
- }
- return NFCSTATUS_SUCCESS;
-}
-
-
-/**
-* \ingroup grp_fri_nfc
-* \brief Send data on a socket.
-*
-* This function is used to write data on a socket. This function
-* can only be called on a connection-oriented socket which is already
-* in a connected state.
-*
-*
-* \param[in] pLlcpSocket A pointer to a phFriNfc_LlcpTransport_Socket_t.
-* \param[in] psBuffer The buffer containing the data to send.
-* \param[in] pSend_RspCb The callback to be called when the
-* operation is completed.
-* \param[in] pContext Upper layer context to be returned in
-* the callback.
-*
-* \retval NFCSTATUS_SUCCESS Operation successful.
-* \retval NFCSTATUS_INVALID_PARAMETER One or more of the supplied parameters
-* could not be properly interpreted.
-* \retval NFCSTATUS_PENDING Reception operation is in progress,
-* pSend_RspCb will be called upon completion.
-* \retval NFCSTATUS_INVALID_STATE The socket is not in a valid state, or not of
-* a valid type to perform the requsted operation.
-* \retval NFCSTATUS_FAILED Operation failed.
-*/
-NFCSTATUS phFriNfc_LlcpTransport_ConnectionOriented_Send(phFriNfc_LlcpTransport_Socket_t* pLlcpSocket,
- phNfc_sData_t* psBuffer,
- pphFriNfc_LlcpTransportSocketSendCb_t pSend_RspCb,
- void* pContext)
-{
- NFCSTATUS status = NFCSTATUS_SUCCESS;
-
-
- /* Test the RW window */
- if(!CHECK_SEND_RW(pLlcpSocket))
- {
- /* Store the Send CB and context */
- pLlcpSocket->pfSocketSend_Cb = pSend_RspCb;
- pLlcpSocket->pSendContext = pContext;
-
- /* Set Send pending */
- pLlcpSocket->bSocketSendPending = TRUE;
-
- /* Store send buffer pointer */
- pLlcpSocket->sSocketSendBuffer = *psBuffer;
-
- /* Set status */
- status = NFCSTATUS_PENDING;
- }
- else
- {
- /* Store send buffer pointer */
- pLlcpSocket->sSocketSendBuffer = *psBuffer;
-
- /* Store the Send CB and context */
- pLlcpSocket->pfSocketSend_Cb = pSend_RspCb;
- pLlcpSocket->pSendContext = pContext;
-
- /* Test if a send is pending */
- if(testAndSetSendPending(pLlcpSocket->psTransport))
- {
- /* Set Send pending */
- pLlcpSocket->bSocketSendPending = TRUE;
-
- /* Set status */
- status = NFCSTATUS_PENDING;
- }
- else
- {
- /* Store the Send CB and context */
- pLlcpSocket->pfSocketSend_Cb = pSend_RspCb;
- pLlcpSocket->pSendContext = pContext;
-
- status = static_performSendInfo(pLlcpSocket);
-
- if(status != NFCSTATUS_SUCCESS && status != NFCSTATUS_PENDING)
- {
- clearSendPending(pLlcpSocket->psTransport);
- LLCP_PRINT("Release Send callback");
- pLlcpSocket->pfSocketSend_Cb = NULL;
- pLlcpSocket->pSendContext = NULL;
- }
- }
-
- }
- return status;
-}
-
-
- /**
-* \ingroup grp_fri_nfc
-* \brief Read data on a socket.
-*
-* This function is used to read data from a socket. It reads at most the
-* size of the reception buffer, but can also return less bytes if less bytes
-* are available. If no data is available, the function will be pending until
-* more data comes, and the response will be sent by the callback. This function
-* can only be called on a connection-oriented socket.
-*
-*
-* \param[in] pLlcpSocket A pointer to a phFriNfc_LlcpTransport_Socket_t.
-* \param[in] psBuffer The buffer receiving the data.
-* \param[in] pRecv_RspCb The callback to be called when the
-* operation is completed.
-* \param[in] pContext Upper layer context to be returned in
-* the callback.
-*
-* \retval NFCSTATUS_SUCCESS Operation successful.
-* \retval NFCSTATUS_INVALID_PARAMETER One or more of the supplied parameters
-* could not be properly interpreted.
-* \retval NFCSTATUS_PENDING Reception operation is in progress,
-* pRecv_RspCb will be called upon completion.
-* \retval NFCSTATUS_INVALID_STATE The socket is not in a valid state, or not of
-* a valid type to perform the requsted operation.
-* \retval NFCSTATUS_FAILED Operation failed.
-*/
-NFCSTATUS phFriNfc_LlcpTransport_ConnectionOriented_Recv( phFriNfc_LlcpTransport_Socket_t* pLlcpSocket,
- phNfc_sData_t* psBuffer,
- pphFriNfc_LlcpTransportSocketRecvCb_t pRecv_RspCb,
- void* pContext)
-{
- NFCSTATUS status = NFCSTATUS_SUCCESS;
- uint32_t dataLengthStored = 0;
- uint32_t dataLengthAvailable = 0;
- uint32_t dataLengthRead = 0;
- uint32_t dataLengthWrite = 0;
- bool_t dataBufferized = FALSE;
-
- /* Test if the WorkingBuffer Length is null */
- if(pLlcpSocket->bufferLinearLength == 0)
- {
- if (pLlcpSocket->eSocket_State != phFriNfc_LlcpTransportSocket_eSocketConnected)
- {
- return NFCSTATUS_FAILED;
- }
-
- /* Test If data is present in the RW Buffer */
- if(pLlcpSocket->indexRwRead != pLlcpSocket->indexRwWrite)
- {
- if(pLlcpSocket->sSocketRwBufferTable[(pLlcpSocket->indexRwRead%pLlcpSocket->localRW)].length != 0)
- {
- /* Save I_FRAME into the Receive Buffer */
- memcpy(psBuffer->buffer,pLlcpSocket->sSocketRwBufferTable[(pLlcpSocket->indexRwRead%pLlcpSocket->localRW)].buffer,pLlcpSocket->sSocketRwBufferTable[(pLlcpSocket->indexRwRead%pLlcpSocket->localRW)].length);
- psBuffer->length = pLlcpSocket->sSocketRwBufferTable[(pLlcpSocket->indexRwRead%pLlcpSocket->localRW)].length;
-
- dataBufferized = TRUE;
-
- /* Update VR */
- pLlcpSocket->socket_VR = (pLlcpSocket->socket_VR+1)%16;
-
- /* Update RW Buffer length */
- pLlcpSocket->sSocketRwBufferTable[(pLlcpSocket->indexRwRead%pLlcpSocket->localRW)].length = 0;
-
- /* Update Value Rw Read Index*/
- pLlcpSocket->indexRwRead++;
- }
- }
-
- if(dataBufferized == TRUE)
- {
- /* Call the Receive CB */
- pRecv_RspCb(pContext,NFCSTATUS_SUCCESS);
-
- if(pLlcpSocket->ReceiverBusyCondition == TRUE)
- {
- /* Reset the ReceiverBusyCondition Flag */
- pLlcpSocket->ReceiverBusyCondition = FALSE;
- /* RR */
- /* TODO: report status? */
- phFriNfc_Llcp_Send_ReceiveReady_Frame(pLlcpSocket);
- }
- }
- else
- {
- /* Set Receive pending */
- pLlcpSocket->bSocketRecvPending = TRUE;
-
- /* Store the buffer pointer */
- pLlcpSocket->sSocketRecvBuffer = psBuffer;
-
- /* Store the Recv CB and context */
- pLlcpSocket->pfSocketRecv_Cb = pRecv_RspCb;
- pLlcpSocket->pRecvContext = pContext;
-
- /* Set status */
- status = NFCSTATUS_PENDING;
- }
- }
- else
- {
- /* Test if data is present in the linear buffer*/
- dataLengthStored = phFriNfc_Llcp_CyclicFifoUsage(&pLlcpSocket->sCyclicFifoBuffer);
-
- if(dataLengthStored != 0)
- {
- if(psBuffer->length > dataLengthStored)
- {
- psBuffer->length = dataLengthStored;
- }
-
- /* Read data from the linear buffer */
- dataLengthRead = phFriNfc_Llcp_CyclicFifoFifoRead(&pLlcpSocket->sCyclicFifoBuffer,
- psBuffer->buffer,
- psBuffer->length);
-
- if(dataLengthRead != 0)
- {
- /* Test If data is present in the RW Buffer */
- while(pLlcpSocket->indexRwRead != pLlcpSocket->indexRwWrite)
- {
- /* Get the data length available in the linear buffer */
- dataLengthAvailable = phFriNfc_Llcp_CyclicFifoAvailable(&pLlcpSocket->sCyclicFifoBuffer);
-
- /* Exit if not enough memory available in linear buffer */
- if(dataLengthAvailable < pLlcpSocket->sSocketRwBufferTable[(pLlcpSocket->indexRwRead%pLlcpSocket->localRW)].length)
- {
- break;
- }
-
- /* Write data into the linear buffer */
- dataLengthWrite = phFriNfc_Llcp_CyclicFifoWrite(&pLlcpSocket->sCyclicFifoBuffer,
- pLlcpSocket->sSocketRwBufferTable[(pLlcpSocket->indexRwRead%pLlcpSocket->localRW)].buffer,
- pLlcpSocket->sSocketRwBufferTable[(pLlcpSocket->indexRwRead%pLlcpSocket->localRW)].length);
- /* Update VR */
- pLlcpSocket->socket_VR = (pLlcpSocket->socket_VR+1)%16;
-
- /* Set flag bufferized to TRUE */
- dataBufferized = TRUE;
-
- /* Update RW Buffer length */
- pLlcpSocket->sSocketRwBufferTable[(pLlcpSocket->indexRwRead%pLlcpSocket->localRW)].length = 0;
-
- /* Update Value Rw Read Index*/
- pLlcpSocket->indexRwRead++;
- }
-
- /* Test if data has been bufferized after a read access */
- if(dataBufferized == TRUE)
- {
- /* Get the data length available in the linear buffer */
- dataLengthAvailable = phFriNfc_Llcp_CyclicFifoAvailable(&pLlcpSocket->sCyclicFifoBuffer);
- if((dataLengthAvailable >= pLlcpSocket->sSocketOption.miu) && (pLlcpSocket->ReceiverBusyCondition == TRUE))
- {
- /* Reset the ReceiverBusyCondition Flag */
- pLlcpSocket->ReceiverBusyCondition = FALSE;
- /* RR */
- /* TODO: report status? */
- phFriNfc_Llcp_Send_ReceiveReady_Frame(pLlcpSocket);
- }
- }
-
- /* Call the Receive CB */
- pRecv_RspCb(pContext,NFCSTATUS_SUCCESS);
- }
- else
- {
- /* Call the Receive CB */
- status = NFCSTATUS_FAILED;
- }
- }
- else
- {
- if (pLlcpSocket->eSocket_State != phFriNfc_LlcpTransportSocket_eSocketConnected)
- {
- status = NFCSTATUS_FAILED;
- }
- else
- {
- /* Set Receive pending */
- pLlcpSocket->bSocketRecvPending = TRUE;
-
- /* Store the buffer pointer */
- pLlcpSocket->sSocketRecvBuffer = psBuffer;
-
- /* Store the Recv CB and context */
- pLlcpSocket->pfSocketRecv_Cb = pRecv_RspCb;
- pLlcpSocket->pRecvContext = pContext;
-
- /* Set status */
- status = NFCSTATUS_PENDING;
- }
- }
- }
-
- if(status != NFCSTATUS_PENDING)
- {
- /* Note: The receive callback must be released to avoid being called at abort */
- LLCP_PRINT("Release Receive callback");
- pLlcpSocket->pfSocketRecv_Cb = NULL;
- pLlcpSocket->pRecvContext = NULL;
- }
-
- return status;
-}
-
-
diff --git a/libnfc-nxp/phFriNfc_LlcpTransport_Connection.h b/libnfc-nxp/phFriNfc_LlcpTransport_Connection.h
deleted file mode 100644
index 07ec1fb..0000000
--- a/libnfc-nxp/phFriNfc_LlcpTransport_Connection.h
+++ /dev/null
@@ -1,302 +0,0 @@
-/*
- * Copyright (C) 2010 NXP Semiconductors
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-/**
- * \file phFriNfc_LlcpTransport_Connection.h
- * \brief
- *
- * Project: NFC-FRI
- *
- */
-#ifndef PHFRINFC_LLCP_TRANSPORT_CONNECTION_H
-#define PHFRINFC_LLCP_TRANSPORT_CONNECTION_H
-/*include files*/
-#include
-#include
-#include
-
-#include
-
-void Handle_ConnectionOriented_IncommingFrame(phFriNfc_LlcpTransport_t *pLlcpTransport,
- phNfc_sData_t *psData,
- uint8_t dsap,
- uint8_t ptype,
- uint8_t ssap);
-
-NFCSTATUS phFriNfc_LlcpTransport_ConnectionOriented_HandlePendingOperations(phFriNfc_LlcpTransport_Socket_t *pSocket);
-
-/**
-* \ingroup grp_lib_nfc
-* \brief Get the local options of a socket.
-*
-* This function returns the local options (maximum packet size and receive window size) used
-* for a given connection-oriented socket. This function shall not be used with connectionless
-* sockets.
-*
-* \param[out] pLlcpSocket A pointer to a phFriNfc_LlcpTransport_Socket_t.
-* \param[in] psLocalOptions A pointer to be filled with the local options of the socket.
-*
-* \retval NFCSTATUS_SUCCESS Operation successful.
-* \retval NFCSTATUS_INVALID_PARAMETER One or more of the supplied parameters
-* could not be properly interpreted.
-* \retval NFCSTATUS_INVALID_STATE The socket is not in a valid state, or not of
-* a valid type to perform the requsted operation.
-* \retval NFCSTATUS_NOT_INITIALISED Indicates stack is not yet initialized.
-* \retval NFCSTATUS_SHUTDOWN Shutdown in progress.
-* \retval NFCSTATUS_FAILED Operation failed.
-*/
-NFCSTATUS phFriNfc_LlcpTransport_ConnectionOriented_SocketGetLocalOptions(phFriNfc_LlcpTransport_Socket_t *pLlcpSocket,
- phLibNfc_Llcp_sSocketOptions_t *psLocalOptions);
-
-/**
-* \ingroup grp_lib_nfc
-* \brief Get the local options of a socket.
-*
-* This function returns the remote options (maximum packet size and receive window size) used
-* for a given connection-oriented socket. This function shall not be used with connectionless
-* sockets.
-*
-* \param[out] pLlcpSocket A pointer to a phFriNfc_LlcpTransport_Socket_t.
-* \param[in] psRemoteOptions A pointer to be filled with the remote options of the socket.
-*
-* \retval NFCSTATUS_SUCCESS Operation successful.
-* \retval NFCSTATUS_INVALID_PARAMETER One or more of the supplied parameters
-* could not be properly interpreted.
-* \retval NFCSTATUS_INVALID_STATE The socket is not in a valid state, or not of
-* a valid type to perform the requsted operation.
-* \retval NFCSTATUS_NOT_INITIALISED Indicates stack is not yet initialized.
-* \retval NFCSTATUS_SHUTDOWN Shutdown in progress.
-* \retval NFCSTATUS_FAILED Operation failed.
-*/
-NFCSTATUS phFriNfc_LlcpTransport_ConnectionOriented_SocketGetRemoteOptions(phFriNfc_LlcpTransport_Socket_t* pLlcpSocket,
- phLibNfc_Llcp_sSocketOptions_t* psRemoteOptions);
-
-/**
-* \ingroup grp_fri_nfc
-* \brief Close a socket on a LLCP-connected device.
-*
-* This function closes a LLCP socket previously created using phFriNfc_LlcpTransport_Socket.
-* If the socket was connected, it is first disconnected, and then closed.
-*
-* \param[in] pLlcpSocket A pointer to a phFriNfc_LlcpTransport_Socket_t.
-
-* \retval NFCSTATUS_SUCCESS Operation successful.
-* \retval NFCSTATUS_INVALID_PARAMETER One or more of the supplied parameters
-* could not be properly interpreted.
-* \retval NFCSTATUS_FAILED Operation failed.
-*/
-NFCSTATUS phFriNfc_LlcpTransport_ConnectionOriented_Close(phFriNfc_LlcpTransport_Socket_t* pLlcpSocket);
-
-/**
-* \ingroup grp_fri_nfc
-* \brief Listen for incoming connection requests on a socket.
-*
-* This function switches a socket into a listening state and registers a callback on
-* incoming connection requests. In this state, the socket is not able to communicate
-* directly. The listening state is only available for connection-oriented sockets
-* which are still not connected. The socket keeps listening until it is closed, and
-* thus can trigger several times the pListen_Cb callback.
-*
-*
-* \param[in] pLlcpSocket A pointer to a phFriNfc_LlcpTransport_Socket_t.
-* \param[in] pListen_Cb The callback to be called each time the
-* socket receive a connection request.
-* \param[in] pContext Upper layer context to be returned in
-* the callback.
-*
-* \retval NFCSTATUS_SUCCESS Operation successful.
-* \retval NFCSTATUS_INVALID_PARAMETER One or more of the supplied parameters
-* could not be properly interpreted.
-* \retval NFCSTATUS_INVALID_STATE The socket is not in a valid state to switch
-* to listening state.
-* \retval NFCSTATUS_FAILED Operation failed.
-*/
-NFCSTATUS phFriNfc_LlcpTransport_ConnectionOriented_Listen(phFriNfc_LlcpTransport_Socket_t* pLlcpSocket,
- pphFriNfc_LlcpTransportSocketListenCb_t pListen_Cb,
- void* pContext);
-
-
-/**
-* \ingroup grp_fri_nfc
-* \brief Accept an incoming connection request for a socket.
-*
-* This functions allows the client to accept an incoming connection request.
-* It must be used with the socket provided within the listen callback. The socket
-* is implicitly switched to the connected state when the function is called.
-*
-* \param[in] pLlcpSocket A pointer to a phFriNfc_LlcpTransport_Socket_t.
-* \param[in] psOptions The options to be used with the socket.
-* \param[in] psWorkingBuffer A working buffer to be used by the library.
-* \param[in] pErr_Cb The callback to be called each time the accepted socket
-* is in error.
-* \param[in] pAccept_RspCb The callback to be called when the Accept operation is completed
-* \param[in] pContext Upper layer context to be returned in the callback.
-*
-* \retval NFCSTATUS_SUCCESS Operation successful.
-* \retval NFCSTATUS_INVALID_PARAMETER One or more of the supplied parameters
-* could not be properly interpreted.
-* \retval NFCSTATUS_BUFFER_TOO_SMALL The working buffer is too small for the MIU and RW
-* declared in the options.
-* \retval NFCSTATUS_FAILED Operation failed.
-*/
-NFCSTATUS phFriNfc_LlcpTransport_ConnectionOriented_Accept(phFriNfc_LlcpTransport_Socket_t* pLlcpSocket,
- phFriNfc_LlcpTransport_sSocketOptions_t* psOptions,
- phNfc_sData_t* psWorkingBuffer,
- pphFriNfc_LlcpTransportSocketErrCb_t pErr_Cb,
- pphFriNfc_LlcpTransportSocketAcceptCb_t pAccept_RspCb,
- void* pContext);
-
-
- /**
-* \ingroup grp_fri_nfc
-* \brief Reject an incoming connection request for a socket.
-*
-* This functions allows the client to reject an incoming connection request.
-* It must be used with the socket provided within the listen callback. The socket
-* is implicitly closed when the function is called.
-*
-* \param[in] pLlcpSocket A pointer to a phFriNfc_LlcpTransport_Socket_t.
-* \param[in] pReject_RspCb The callback to be called when the Reject operation is completed
-* \param[in] pContext Upper layer context to be returned in the callback.
-*
-* \retval NFCSTATUS_SUCCESS Operation successful.
-* \retval NFCSTATUS_INVALID_PARAMETER One or more of the supplied parameters
-* could not be properly interpreted.
-* \retval NFCSTATUS_FAILED Operation failed.
-*/
-NFCSTATUS phLibNfc_LlcpTransport_ConnectionOriented_Reject( phFriNfc_LlcpTransport_Socket_t* pLlcpSocket,
- pphFriNfc_LlcpTransportSocketRejectCb_t pReject_RspCb,
- void *pContext);
-
-/**
-* \ingroup grp_fri_nfc
-* \brief Try to establish connection with a socket on a remote SAP.
-*
-* This function tries to connect to a given SAP on the remote peer. If the
-* socket is not bound to a local SAP, it is implicitly bound to a free SAP.
-*
-* \param[in] pLlcpSocket A pointer to a phFriNfc_LlcpTransport_Socket_t.
-* \param[in] nSap The destination SAP to connect to.
-* \param[in] psUri The URI corresponding to the destination SAP to connect to.
-* \param[in] pConnect_RspCb The callback to be called when the connection
-* operation is completed.
-* \param[in] pContext Upper layer context to be returned in
-* the callback.
-*
-* \retval NFCSTATUS_SUCCESS Operation successful.
-* \retval NFCSTATUS_INVALID_PARAMETER One or more of the supplied parameters
-* could not be properly interpreted.
-* \retval NFCSTATUS_PENDING Connection operation is in progress,
-* pConnect_RspCb will be called upon completion.
-* \retval NFCSTATUS_INVALID_STATE The socket is not in a valid state, or not of
-* a valid type to perform the requsted operation.
-* \retval NFCSTATUS_FAILED Operation failed.
-*/
-NFCSTATUS phFriNfc_LlcpTransport_ConnectionOriented_Connect( phFriNfc_LlcpTransport_Socket_t* pLlcpSocket,
- uint8_t nSap,
- phNfc_sData_t* psUri,
- pphFriNfc_LlcpTransportSocketConnectCb_t pConnect_RspCb,
- void* pContext);
-
-/**
-* \ingroup grp_lib_nfc
-* \brief Disconnect a currently connected socket.
-*
-* This function initiates the disconnection of a previously connected socket.
-*
-* \param[in] pLlcpSocket A pointer to a phFriNfc_LlcpTransport_Socket_t.
-* \param[in] pDisconnect_RspCb The callback to be called when the
-* operation is completed.
-* \param[in] pContext Upper layer context to be returned in
-* the callback.
-*
-* \retval NFCSTATUS_SUCCESS Operation successful.
-* \retval NFCSTATUS_INVALID_PARAMETER One or more of the supplied parameters
-* could not be properly interpreted.
-* \retval NFCSTATUS_PENDING Disconnection operation is in progress,
-* pDisconnect_RspCb will be called upon completion.
-* \retval NFCSTATUS_INVALID_STATE The socket is not in a valid state, or not of
-* a valid type to perform the requsted operation.
-* \retval NFCSTATUS_NOT_INITIALISED Indicates stack is not yet initialized.
-* \retval NFCSTATUS_SHUTDOWN Shutdown in progress.
-* \retval NFCSTATUS_FAILED Operation failed.
-*/
-NFCSTATUS phLibNfc_LlcpTransport_ConnectionOriented_Disconnect(phFriNfc_LlcpTransport_Socket_t* pLlcpSocket,
- pphLibNfc_LlcpSocketDisconnectCb_t pDisconnect_RspCb,
- void* pContext);
-
-/**
-* \ingroup grp_fri_nfc
-* \brief Send data on a socket.
-*
-* This function is used to write data on a socket. This function
-* can only be called on a connection-oriented socket which is already
-* in a connected state.
-*
-*
-* \param[in] pLlcpSocket A pointer to a phFriNfc_LlcpTransport_Socket_t.
-* \param[in] psBuffer The buffer containing the data to send.
-* \param[in] pSend_RspCb The callback to be called when the
-* operation is completed.
-* \param[in] pContext Upper layer context to be returned in
-* the callback.
-*
-* \retval NFCSTATUS_SUCCESS Operation successful.
-* \retval NFCSTATUS_INVALID_PARAMETER One or more of the supplied parameters
-* could not be properly interpreted.
-* \retval NFCSTATUS_PENDING Reception operation is in progress,
-* pSend_RspCb will be called upon completion.
-* \retval NFCSTATUS_INVALID_STATE The socket is not in a valid state, or not of
-* a valid type to perform the requsted operation.
-* \retval NFCSTATUS_FAILED Operation failed.
-*/
-NFCSTATUS phFriNfc_LlcpTransport_ConnectionOriented_Send(phFriNfc_LlcpTransport_Socket_t* pLlcpSocket,
- phNfc_sData_t* psBuffer,
- pphFriNfc_LlcpTransportSocketSendCb_t pSend_RspCb,
- void* pContext);
-
- /**
-* \ingroup grp_fri_nfc
-* \brief Read data on a socket.
-*
-* This function is used to read data from a socket. It reads at most the
-* size of the reception buffer, but can also return less bytes if less bytes
-* are available. If no data is available, the function will be pending until
-* more data comes, and the response will be sent by the callback. This function
-* can only be called on a connection-oriented socket.
-*
-*
-* \param[in] pLlcpSocket A pointer to a phFriNfc_LlcpTransport_Socket_t.
-* \param[in] psBuffer The buffer receiving the data.
-* \param[in] pRecv_RspCb The callback to be called when the
-* operation is completed.
-* \param[in] pContext Upper layer context to be returned in
-* the callback.
-*
-* \retval NFCSTATUS_SUCCESS Operation successful.
-* \retval NFCSTATUS_INVALID_PARAMETER One or more of the supplied parameters
-* could not be properly interpreted.
-* \retval NFCSTATUS_PENDING Reception operation is in progress,
-* pRecv_RspCb will be called upon completion.
-* \retval NFCSTATUS_INVALID_STATE The socket is not in a valid state, or not of
-* a valid type to perform the requsted operation.
-* \retval NFCSTATUS_FAILED Operation failed.
-*/
-NFCSTATUS phFriNfc_LlcpTransport_ConnectionOriented_Recv( phFriNfc_LlcpTransport_Socket_t* pLlcpSocket,
- phNfc_sData_t* psBuffer,
- pphFriNfc_LlcpTransportSocketRecvCb_t pRecv_RspCb,
- void* pContext);
-#endif /* PHFRINFC_LLCP_TRANSPORT_CONNECTION_H */
diff --git a/libnfc-nxp/phFriNfc_LlcpTransport_Connectionless.c b/libnfc-nxp/phFriNfc_LlcpTransport_Connectionless.c
deleted file mode 100644
index 37bf14f..0000000
--- a/libnfc-nxp/phFriNfc_LlcpTransport_Connectionless.c
+++ /dev/null
@@ -1,364 +0,0 @@
-/*
- * Copyright (C) 2010 NXP Semiconductors
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-/**
- * \file phFriNfc_LlcpTransport_Connectionless.c
- * \brief
- *
- * Project: NFC-FRI
- *
- */
-/*include files*/
-#include
-#include
-#include
-#include
-#include
-#include
-
-static void phFriNfc_LlcpTransport_Connectionless_SendTo_CB(void* pContext,
- uint8_t socketIndex,
- NFCSTATUS status);
-
-NFCSTATUS phFriNfc_LlcpTransport_Connectionless_HandlePendingOperations(phFriNfc_LlcpTransport_Socket_t *pSocket)
-{
- NFCSTATUS status = NFCSTATUS_FAILED;
-
- /* Check if something is pending and if transport layer is ready to send */
- if ((pSocket->pfSocketSend_Cb != NULL) &&
- (pSocket->psTransport->bSendPending == FALSE))
- {
- /* Fill the psLlcpHeader stuture with the DSAP,PTYPE and the SSAP */
- pSocket->sLlcpHeader.dsap = pSocket->socket_dSap;
- pSocket->sLlcpHeader.ptype = PHFRINFC_LLCP_PTYPE_UI;
- pSocket->sLlcpHeader.ssap = pSocket->socket_sSap;
-
- /* Send to data to the approiate socket */
- status = phFriNfc_LlcpTransport_LinkSend(pSocket->psTransport,
- &pSocket->sLlcpHeader,
- NULL,
- &pSocket->sSocketSendBuffer,
- phFriNfc_LlcpTransport_Connectionless_SendTo_CB,
- pSocket->index,
- pSocket);
- }
- else
- {
- /* Cannot send now, retry later */
- }
-
- return status;
-}
-
-
-/* TODO: comment function Handle_Connectionless_IncommingFrame */
-void Handle_Connectionless_IncommingFrame(phFriNfc_LlcpTransport_t *pLlcpTransport,
- phNfc_sData_t *psData,
- uint8_t dsap,
- uint8_t ssap)
-{
- phFriNfc_LlcpTransport_Socket_t * pSocket = NULL;
- uint8_t i = 0;
- uint8_t writeIndex;
-
- /* Look through the socket table for a match */
- for(i=0;ipSocketTable[i].socket_sSap == dsap)
- {
- /* Socket found ! */
- pSocket = &pLlcpTransport->pSocketTable[i];
-
- /* Forward directly to application if a read is pending */
- if (pSocket->bSocketRecvPending == TRUE)
- {
- /* Reset the RecvPending variable */
- pSocket->bSocketRecvPending = FALSE;
-
- /* Copy the received buffer into the receive buffer */
- memcpy(pSocket->sSocketRecvBuffer->buffer, psData->buffer, psData->length);
-
- /* Update the received length */
- *pSocket->receivedLength = psData->length;
-
- /* call the recv callback */
- pSocket->pfSocketRecvFrom_Cb(pSocket->pRecvContext, ssap, NFCSTATUS_SUCCESS);
- pSocket->pfSocketRecvFrom_Cb = NULL;
- }
- /* If no read is pending, try to bufferize for later reading */
- else
- {
- if((pSocket->indexRwWrite - pSocket->indexRwRead) < pSocket->localRW)
- {
- writeIndex = pSocket->indexRwWrite % pSocket->localRW;
- /* Save SSAP */
- pSocket->sSocketRwBufferTable[writeIndex].buffer[0] = ssap;
- /* Save UI frame payload */
- memcpy(pSocket->sSocketRwBufferTable[writeIndex].buffer + 1,
- psData->buffer,
- psData->length);
- pSocket->sSocketRwBufferTable[writeIndex].length = psData->length;
-
- /* Update the RW write index */
- pSocket->indexRwWrite++;
- }
- else
- {
- /* Unable to bufferize the packet, drop it */
- }
- }
- break;
- }
- }
-}
-
-/* TODO: comment function phFriNfc_LlcpTransport_Connectionless_SendTo_CB */
-static void phFriNfc_LlcpTransport_Connectionless_SendTo_CB(void* pContext,
- uint8_t socketIndex,
- NFCSTATUS status)
-{
- phFriNfc_LlcpTransport_Socket_t * pLlcpSocket = (phFriNfc_LlcpTransport_Socket_t*)pContext;
- pphFriNfc_LlcpTransportSocketSendCb_t pfSavedCallback;
-
- /* Call the send callback */
- pfSavedCallback = pLlcpSocket->pfSocketSend_Cb;
- if (pfSavedCallback != NULL)
- {
- pLlcpSocket->pfSocketSend_Cb = NULL;
- pfSavedCallback(pLlcpSocket->pSendContext, status);
- }
-}
-
-static void phFriNfc_LlcpTransport_Connectionless_Abort(phFriNfc_LlcpTransport_Socket_t* pLlcpSocket)
-{
- if (pLlcpSocket->pfSocketSend_Cb != NULL)
- {
- pLlcpSocket->pfSocketSend_Cb(pLlcpSocket->pSendContext, NFCSTATUS_ABORTED);
- pLlcpSocket->pSendContext = NULL;
- pLlcpSocket->pfSocketSend_Cb = NULL;
- }
- if (pLlcpSocket->pfSocketRecvFrom_Cb != NULL)
- {
- pLlcpSocket->pfSocketRecvFrom_Cb(pLlcpSocket->pRecvContext, 0, NFCSTATUS_ABORTED);
- pLlcpSocket->pRecvContext = NULL;
- pLlcpSocket->pfSocketRecvFrom_Cb = NULL;
- pLlcpSocket->pfSocketRecv_Cb = NULL;
- }
- pLlcpSocket->pAcceptContext = NULL;
- pLlcpSocket->pfSocketAccept_Cb = NULL;
- pLlcpSocket->pListenContext = NULL;
- pLlcpSocket->pfSocketListen_Cb = NULL;
- pLlcpSocket->pConnectContext = NULL;
- pLlcpSocket->pfSocketConnect_Cb = NULL;
- pLlcpSocket->pDisconnectContext = NULL;
- pLlcpSocket->pfSocketDisconnect_Cb = NULL;
-}
-
-/**
-* \ingroup grp_fri_nfc
-* \brief Close a socket on a LLCP-connectionless device.
-*
-* This function closes a LLCP socket previously created using phFriNfc_LlcpTransport_Socket.
-*
-* \param[in] pLlcpSocket A pointer to a phFriNfc_LlcpTransport_Socket_t.
-
-* \retval NFCSTATUS_SUCCESS Operation successful.
-* \retval NFCSTATUS_INVALID_PARAMETER One or more of the supplied parameters
-* could not be properly interpreted.
-* \retval NFCSTATUS_FAILED Operation failed.
-*/
-NFCSTATUS phFriNfc_LlcpTransport_Connectionless_Close(phFriNfc_LlcpTransport_Socket_t* pLlcpSocket)
-{
- /* Reset the pointer to the socket closed */
- pLlcpSocket->eSocket_State = phFriNfc_LlcpTransportSocket_eSocketDefault;
- pLlcpSocket->eSocket_Type = phFriNfc_LlcpTransport_eDefaultType;
- pLlcpSocket->pContext = NULL;
- pLlcpSocket->pSocketErrCb = NULL;
- pLlcpSocket->socket_sSap = PHFRINFC_LLCP_SAP_DEFAULT;
- pLlcpSocket->socket_dSap = PHFRINFC_LLCP_SAP_DEFAULT;
- pLlcpSocket->bSocketRecvPending = FALSE;
- pLlcpSocket->bSocketSendPending = FALSE;
- pLlcpSocket->bSocketListenPending = FALSE;
- pLlcpSocket->bSocketDiscPending = FALSE;
- pLlcpSocket->RemoteBusyConditionInfo = FALSE;
- pLlcpSocket->ReceiverBusyCondition = FALSE;
- pLlcpSocket->socket_VS = 0;
- pLlcpSocket->socket_VSA = 0;
- pLlcpSocket->socket_VR = 0;
- pLlcpSocket->socket_VRA = 0;
-
- phFriNfc_LlcpTransport_Connectionless_Abort(pLlcpSocket);
-
- memset(&pLlcpSocket->sSocketOption, 0x00, sizeof(phFriNfc_LlcpTransport_sSocketOptions_t));
-
- if (pLlcpSocket->sServiceName.buffer != NULL) {
- phOsalNfc_FreeMemory(pLlcpSocket->sServiceName.buffer);
- }
- pLlcpSocket->sServiceName.buffer = NULL;
- pLlcpSocket->sServiceName.length = 0;
-
- return NFCSTATUS_SUCCESS;
-}
-
-/**
-* \ingroup grp_fri_nfc
-* \brief Send data on a socket to a given destination SAP.
-*
-* This function is used to write data on a socket to a given destination SAP.
-* This function can only be called on a connectionless socket.
-*
-*
-* \param[in] pLlcpSocket A pointer to a LlcpSocket created.
-* \param[in] nSap The destination SAP.
-* \param[in] psBuffer The buffer containing the data to send.
-* \param[in] pSend_RspCb The callback to be called when the
-* operation is completed.
-* \param[in] pContext Upper layer context to be returned in
-* the callback.
-*
-* \retval NFCSTATUS_SUCCESS Operation successful.
-* \retval NFCSTATUS_INVALID_PARAMETER One or more of the supplied parameters
-* could not be properly interpreted.
-* \retval NFCSTATUS_PENDING Reception operation is in progress,
-* pSend_RspCb will be called upon completion.
-* \retval NFCSTATUS_INVALID_STATE The socket is not in a valid state, or not of
-* a valid type to perform the requsted operation.
-* \retval NFCSTATUS_NOT_INITIALISED Indicates stack is not yet initialized.
-* \retval NFCSTATUS_SHUTDOWN Shutdown in progress.
-* \retval NFCSTATUS_FAILED Operation failed.
-*/
-NFCSTATUS phFriNfc_LlcpTransport_Connectionless_SendTo(phFriNfc_LlcpTransport_Socket_t *pLlcpSocket,
- uint8_t nSap,
- phNfc_sData_t* psBuffer,
- pphFriNfc_LlcpTransportSocketSendCb_t pSend_RspCb,
- void* pContext)
-{
- NFCSTATUS status = NFCSTATUS_FAILED;
-
- /* Store send callback and context*/
- pLlcpSocket->pfSocketSend_Cb = pSend_RspCb;
- pLlcpSocket->pSendContext = pContext;
-
- /* Test if a send is already pending at transport level */
- if(pLlcpSocket->psTransport->bSendPending == TRUE)
- {
- /* Save the request so it can be handled in phFriNfc_LlcpTransport_Connectionless_HandlePendingOperations() */
- pLlcpSocket->sSocketSendBuffer = *psBuffer;
- pLlcpSocket->socket_dSap = nSap;
- status = NFCSTATUS_PENDING;
- }
- else
- {
- /* Fill the psLlcpHeader stuture with the DSAP,PTYPE and the SSAP */
- pLlcpSocket->sLlcpHeader.dsap = nSap;
- pLlcpSocket->sLlcpHeader.ptype = PHFRINFC_LLCP_PTYPE_UI;
- pLlcpSocket->sLlcpHeader.ssap = pLlcpSocket->socket_sSap;
-
- /* Send to data to the approiate socket */
- status = phFriNfc_LlcpTransport_LinkSend(pLlcpSocket->psTransport,
- &pLlcpSocket->sLlcpHeader,
- NULL,
- psBuffer,
- phFriNfc_LlcpTransport_Connectionless_SendTo_CB,
- pLlcpSocket->index,
- pLlcpSocket);
- }
-
- return status;
-}
-
-
- /**
-* \ingroup grp_lib_nfc
-* \brief Read data on a socket and get the source SAP.
-*
-* This function is the same as phLibNfc_Llcp_Recv, except that the callback includes
-* the source SAP. This functions can only be called on a connectionless socket.
-*
-*
-* \param[in] pLlcpSocket A pointer to a LlcpSocket created.
-* \param[in] psBuffer The buffer receiving the data.
-* \param[in] pRecv_RspCb The callback to be called when the
-* operation is completed.
-* \param[in] pContext Upper layer context to be returned in
-* the callback.
-*
-* \retval NFCSTATUS_SUCCESS Operation successful.
-* \retval NFCSTATUS_INVALID_PARAMETER One or more of the supplied parameters
-* could not be properly interpreted.
-* \retval NFCSTATUS_PENDING Reception operation is in progress,
-* pRecv_RspCb will be called upon completion.
-* \retval NFCSTATUS_INVALID_STATE The socket is not in a valid state, or not of
-* a valid type to perform the requsted operation.
-* \retval NFCSTATUS_NOT_INITIALISED Indicates stack is not yet initialized.
-* \retval NFCSTATUS_SHUTDOWN Shutdown in progress.
-* \retval NFCSTATUS_FAILED Operation failed.
-*/
-NFCSTATUS phLibNfc_LlcpTransport_Connectionless_RecvFrom(phFriNfc_LlcpTransport_Socket_t *pLlcpSocket,
- phNfc_sData_t* psBuffer,
- pphFriNfc_LlcpTransportSocketRecvFromCb_t pRecv_Cb,
- void *pContext)
-{
- NFCSTATUS status = NFCSTATUS_PENDING;
- uint8_t readIndex;
- uint8_t ssap;
-
- if(pLlcpSocket->bSocketRecvPending)
- {
- status = PHNFCSTVAL(CID_FRI_NFC_LLCP_TRANSPORT, NFCSTATUS_REJECTED);
- }
- else
- {
- /* Check if pending packets in RW */
- if(pLlcpSocket->indexRwRead != pLlcpSocket->indexRwWrite)
- {
- readIndex = pLlcpSocket->indexRwRead % pLlcpSocket->localRW;
-
- /* Extract ssap and buffer from RW buffer */
- ssap = pLlcpSocket->sSocketRwBufferTable[readIndex].buffer[0];
- memcpy(psBuffer->buffer,
- pLlcpSocket->sSocketRwBufferTable[readIndex].buffer + 1,
- pLlcpSocket->sSocketRwBufferTable[readIndex].length);
- psBuffer->length = pLlcpSocket->sSocketRwBufferTable[readIndex].length;
-
- /* Reset RW buffer length */
- pLlcpSocket->sSocketRwBufferTable[readIndex].length = 0;
-
- /* Update Value Rw Read Index */
- pLlcpSocket->indexRwRead++;
-
- /* call the recv callback */
- pRecv_Cb(pContext, ssap, NFCSTATUS_SUCCESS);
-
- status = NFCSTATUS_SUCCESS;
- }
- /* Otherwise, wait for a packet to come */
- else
- {
- /* Store the callback and context*/
- pLlcpSocket->pfSocketRecvFrom_Cb = pRecv_Cb;
- pLlcpSocket->pRecvContext = pContext;
-
- /* Store the pointer to the receive buffer */
- pLlcpSocket->sSocketRecvBuffer = psBuffer;
- pLlcpSocket->receivedLength = &psBuffer->length;
-
- /* Set RecvPending to TRUE */
- pLlcpSocket->bSocketRecvPending = TRUE;
- }
- }
- return status;
-}
diff --git a/libnfc-nxp/phFriNfc_LlcpTransport_Connectionless.h b/libnfc-nxp/phFriNfc_LlcpTransport_Connectionless.h
deleted file mode 100644
index 2fa263e..0000000
--- a/libnfc-nxp/phFriNfc_LlcpTransport_Connectionless.h
+++ /dev/null
@@ -1,120 +0,0 @@
-/*
- * Copyright (C) 2010 NXP Semiconductors
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-/**
- * \file phFriNfc_LlcpTransport_Connectionless.h
- * \brief
- *
- * Project: NFC-FRI
- *
- */
-#ifndef PHFRINFC_LLCP_TRANSPORT_CONNECTIONLESS_H
-#define PHFRINFC_LLCP_TRANSPORT_CONNECTIONLESS_H
-/*include files*/
-#include
-#include
-#include
-
-#include
-
-
-void Handle_Connectionless_IncommingFrame(phFriNfc_LlcpTransport_t *pLlcpTransport,
- phNfc_sData_t *psData,
- uint8_t dsap,
- uint8_t ssap);
-
-NFCSTATUS phFriNfc_LlcpTransport_Connectionless_HandlePendingOperations(phFriNfc_LlcpTransport_Socket_t *pSocket);
-
-/**
-* \ingroup grp_fri_nfc
-* \brief Close a socket on a LLCP-connectionless device.
-*
-* This function closes a LLCP socket previously created using phFriNfc_LlcpTransport_Socket.
-*
-* \param[in] pLlcpSocket A pointer to a phFriNfc_LlcpTransport_Socket_t.
-
-* \retval NFCSTATUS_SUCCESS Operation successful.
-* \retval NFCSTATUS_INVALID_PARAMETER One or more of the supplied parameters
-* could not be properly interpreted.
-* \retval NFCSTATUS_FAILED Operation failed.
-*/
-NFCSTATUS phFriNfc_LlcpTransport_Connectionless_Close(phFriNfc_LlcpTransport_Socket_t* pLlcpSocket);
-
-/**
-* \ingroup grp_fri_nfc
-* \brief Send data on a socket to a given destination SAP.
-*
-* This function is used to write data on a socket to a given destination SAP.
-* This function can only be called on a connectionless socket.
-*
-*
-* \param[in] pLlcpSocket A pointer to a LlcpSocket created.
-* \param[in] nSap The destination SAP.
-* \param[in] psBuffer The buffer containing the data to send.
-* \param[in] pSend_RspCb The callback to be called when the
-* operation is completed.
-* \param[in] pContext Upper layer context to be returned in
-* the callback.
-*
-* \retval NFCSTATUS_SUCCESS Operation successful.
-* \retval NFCSTATUS_INVALID_PARAMETER One or more of the supplied parameters
-* could not be properly interpreted.
-* \retval NFCSTATUS_PENDING Reception operation is in progress,
-* pSend_RspCb will be called upon completion.
-* \retval NFCSTATUS_INVALID_STATE The socket is not in a valid state, or not of
-* a valid type to perform the requsted operation.
-* \retval NFCSTATUS_NOT_INITIALISED Indicates stack is not yet initialized.
-* \retval NFCSTATUS_SHUTDOWN Shutdown in progress.
-* \retval NFCSTATUS_FAILED Operation failed.
-*/
-NFCSTATUS phFriNfc_LlcpTransport_Connectionless_SendTo(phFriNfc_LlcpTransport_Socket_t *pLlcpSocket,
- uint8_t nSap,
- phNfc_sData_t* psBuffer,
- pphFriNfc_LlcpTransportSocketSendCb_t pSend_RspCb,
- void* pContext);
-
- /**
-* \ingroup grp_lib_nfc
-* \brief Read data on a socket and get the source SAP.
-*
-* This function is the same as phLibNfc_Llcp_Recv, except that the callback includes
-* the source SAP. This functions can only be called on a connectionless socket.
-*
-*
-* \param[in] pLlcpSocket A pointer to a LlcpSocket created.
-* \param[in] psBuffer The buffer receiving the data.
-* \param[in] pRecv_RspCb The callback to be called when the
-* operation is completed.
-* \param[in] pContext Upper layer context to be returned in
-* the callback.
-*
-* \retval NFCSTATUS_SUCCESS Operation successful.
-* \retval NFCSTATUS_INVALID_PARAMETER One or more of the supplied parameters
-* could not be properly interpreted.
-* \retval NFCSTATUS_PENDING Reception operation is in progress,
-* pRecv_RspCb will be called upon completion.
-* \retval NFCSTATUS_INVALID_STATE The socket is not in a valid state, or not of
-* a valid type to perform the requsted operation.
-* \retval NFCSTATUS_NOT_INITIALISED Indicates stack is not yet initialized.
-* \retval NFCSTATUS_SHUTDOWN Shutdown in progress.
-* \retval NFCSTATUS_FAILED Operation failed.
-*/
-NFCSTATUS phLibNfc_LlcpTransport_Connectionless_RecvFrom(phFriNfc_LlcpTransport_Socket_t *pLlcpSocket,
- phNfc_sData_t* psBuffer,
- pphFriNfc_LlcpTransportSocketRecvFromCb_t pRecv_Cb,
- void* pContext);
-
-#endif /* PHFRINFC_LLCP_TRANSPORT_CONNECTIONLESS_H */
diff --git a/libnfc-nxp/phFriNfc_LlcpUtils.c b/libnfc-nxp/phFriNfc_LlcpUtils.c
deleted file mode 100644
index 750f513..0000000
--- a/libnfc-nxp/phFriNfc_LlcpUtils.c
+++ /dev/null
@@ -1,387 +0,0 @@
-/*
- * Copyright (C) 2010 NXP Semiconductors
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-/**
- * \file phFriNfc_Llcp.c
- * \brief NFC LLCP core
- *
- * Project: NFC-FRI
- *
- */
-
-/*include files*/
-#include
-#include
-#include
-#include
-#include
-
-NFCSTATUS phFriNfc_Llcp_DecodeTLV( phNfc_sData_t *psRawData,
- uint32_t *pOffset,
- uint8_t *pType,
- phNfc_sData_t *psValueBuffer )
-{
- uint8_t type;
- uint8_t length;
- uint32_t offset = *pOffset;
-
- /* Check for NULL pointers */
- if ((psRawData == NULL) || (pOffset == NULL) || (pType == NULL) || (psValueBuffer == NULL))
- {
- return PHNFCSTVAL(CID_FRI_NFC_LLCP, NFCSTATUS_INVALID_PARAMETER);
- }
-
- /* Check offset */
- if (offset > psRawData->length)
- {
- return PHNFCSTVAL(CID_FRI_NFC_LLCP, NFCSTATUS_INVALID_PARAMETER);
- }
-
- /* Check if enough room for Type and Length (with overflow check) */
- if ((offset+2 > psRawData->length) && (offset+2 > offset))
- {
- return PHNFCSTVAL(CID_FRI_NFC_LLCP, NFCSTATUS_INVALID_PARAMETER);
- }
-
- /* Get Type and Length from current TLV, and update offset */
- type = psRawData->buffer[offset];
- length = psRawData->buffer[offset+1];
- offset += 2;
-
- /* Check if enough room for Value with announced Length (with overflow check) */
- if ((offset+length > psRawData->length) && (offset+length > offset))
- {
- return PHNFCSTVAL(CID_FRI_NFC_LLCP, NFCSTATUS_INVALID_PARAMETER);
- }
-
- /* Save response, and update offset */
- *pType = type;
- psValueBuffer->buffer = psRawData->buffer + offset;
- psValueBuffer->length = length;
- offset += length;
-
- /* Save updated offset */
- *pOffset = offset;
-
- return NFCSTATUS_SUCCESS;
-}
-
-NFCSTATUS phFriNfc_Llcp_EncodeTLV( phNfc_sData_t *psValueBuffer,
- uint32_t *pOffset,
- uint8_t type,
- uint8_t length,
- uint8_t *pValue)
-{
- uint32_t offset = *pOffset;
- uint32_t finalOffset = offset + 2 + length; /* 2 stands for Type and Length fields size */
- uint8_t i;
-
- /* Check for NULL pointers */
- if ((psValueBuffer == NULL) || (pOffset == NULL) || (pValue == NULL))
- {
- return PHNFCSTVAL(CID_FRI_NFC_LLCP, NFCSTATUS_INVALID_PARAMETER);
- }
-
- /* Check offset */
- if (offset > psValueBuffer->length)
- {
- return PHNFCSTVAL(CID_FRI_NFC_LLCP, NFCSTATUS_INVALID_PARAMETER);
- }
-
- /* Check if enough room for Type, Length and Value (with overflow check) */
- if ((finalOffset > psValueBuffer->length) || (finalOffset < offset))
- {
- return PHNFCSTVAL(CID_FRI_NFC_LLCP, NFCSTATUS_INVALID_PARAMETER);
- }
-
- /* Set the TYPE */
- psValueBuffer->buffer[offset] = type;
- offset += 1;
-
- /* Set the LENGTH */
- psValueBuffer->buffer[offset] = length;
- offset += 1;
-
- /* Set the VALUE */
- for(i=0;ibuffer[offset] = pValue[i];
- }
-
- /* Save updated offset */
- *pOffset = offset;
-
- return NFCSTATUS_SUCCESS;
-}
-
-NFCSTATUS phFriNfc_Llcp_AppendTLV( phNfc_sData_t *psValueBuffer,
- uint32_t nTlvOffset,
- uint32_t *pCurrentOffset,
- uint8_t length,
- uint8_t *pValue)
-{
- uint32_t offset = *pCurrentOffset;
- uint32_t finalOffset = offset + length;
-
- /* Check for NULL pointers */
- if ((psValueBuffer == NULL) || (pCurrentOffset == NULL) || (pValue == NULL))
- {
- return PHNFCSTVAL(CID_FRI_NFC_LLCP, NFCSTATUS_INVALID_PARAMETER);
- }
-
- /* Check offset */
- if (offset > psValueBuffer->length)
- {
- return PHNFCSTVAL(CID_FRI_NFC_LLCP, NFCSTATUS_INVALID_PARAMETER);
- }
-
- /* Check if enough room for Type and Length (with overflow check) */
- if ((finalOffset > psValueBuffer->length) || (finalOffset < offset))
- {
- return PHNFCSTVAL(CID_FRI_NFC_LLCP, NFCSTATUS_INVALID_PARAMETER);
- }
-
- /* Update the LENGTH */
- psValueBuffer->buffer[nTlvOffset+1] += length;
-
- /* Set the VALUE */
- memcpy(psValueBuffer->buffer + offset, pValue, length);
- offset += length;
-
- /* Save updated offset */
- *pCurrentOffset = offset;
-
- return NFCSTATUS_SUCCESS;
-}
-
-
-/* TODO: comment function EncodeMIUX */
-void phFriNfc_Llcp_EncodeMIUX(uint16_t miux,
- uint8_t* pMiuxEncoded)
-{
- /* MASK */
- miux = miux & PHFRINFC_LLCP_TLV_MIUX_MASK;
-
- pMiuxEncoded[0] = miux >> 8;
- pMiuxEncoded[1] = miux & 0xff;
-}
-
-/* TODO: comment function EncodeRW */
-void phFriNfc_Llcp_EncodeRW(uint8_t *pRw)
-{
- /* MASK */
- *pRw = *pRw & PHFRINFC_LLCP_TLV_RW_MASK;
-}
-
-/**
- * Initializes a Fifo Cyclic Buffer to point to some allocated memory.
- */
-void phFriNfc_Llcp_CyclicFifoInit(P_UTIL_FIFO_BUFFER pUtilFifo,
- const uint8_t *pBuffStart,
- uint32_t buffLength)
-{
- pUtilFifo->pBuffStart = (uint8_t *)pBuffStart;
- pUtilFifo->pBuffEnd = (uint8_t *)pBuffStart + buffLength-1;
- pUtilFifo->pIn = (uint8_t *)pBuffStart;
- pUtilFifo->pOut = (uint8_t *)pBuffStart;
- pUtilFifo->bFull = FALSE;
-}
-
-/**
- * Clears the Fifo Cyclic Buffer - loosing any data that was in it.
- */
-void phFriNfc_Llcp_CyclicFifoClear(P_UTIL_FIFO_BUFFER pUtilFifo)
-{
- pUtilFifo->pIn = pUtilFifo->pBuffStart;
- pUtilFifo->pOut = pUtilFifo->pBuffStart;
- pUtilFifo->bFull = FALSE;
-}
-
-/**
- * Attempts to write dataLength bytes to the specified Fifo Cyclic Buffer.
- */
-uint32_t phFriNfc_Llcp_CyclicFifoWrite(P_UTIL_FIFO_BUFFER pUtilFifo,
- uint8_t *pData,
- uint32_t dataLength)
-{
- uint32_t dataLengthWritten = 0;
- uint8_t * pNext;
-
- while(dataLengthWritten < dataLength)
- {
- pNext = (uint8_t*)pUtilFifo->pIn+1;
-
- if(pNext > pUtilFifo->pBuffEnd)
- {
- //Wrap around
- pNext = pUtilFifo->pBuffStart;
- }
-
- if(pUtilFifo->bFull)
- {
- //Full
- break;
- }
-
- if(pNext == pUtilFifo->pOut)
- {
- // Trigger Full flag
- pUtilFifo->bFull = TRUE;
- }
-
- dataLengthWritten++;
- *pNext = *pData++;
- pUtilFifo->pIn = pNext;
- }
-
- return dataLengthWritten;
-}
-
-/**
- * Attempts to read dataLength bytes from the specified Fifo Cyclic Buffer.
- */
-uint32_t phFriNfc_Llcp_CyclicFifoFifoRead(P_UTIL_FIFO_BUFFER pUtilFifo,
- uint8_t *pBuffer,
- uint32_t dataLength)
-{
- uint32_t dataLengthRead = 0;
- uint8_t * pNext;
-
- while(dataLengthRead < dataLength)
- {
- if((pUtilFifo->pOut == pUtilFifo->pIn) && (pUtilFifo->bFull == FALSE))
- {
- //No more bytes in buffer
- break;
- }
- else
- {
- dataLengthRead++;
-
- if(pUtilFifo->pOut == pUtilFifo->pBuffEnd)
- {
- /* Wrap around */
- pNext = pUtilFifo->pBuffStart;
- }
- else
- {
- pNext = (uint8_t*)pUtilFifo->pOut + 1;
- }
-
- *pBuffer++ = *pNext;
-
- pUtilFifo->pOut = pNext;
-
- pUtilFifo->bFull = FALSE;
- }
- }
-
- return dataLengthRead;
-}
-
-/**
- * Returns the number of bytes currently stored in Fifo Cyclic Buffer.
- */
-uint32_t phFriNfc_Llcp_CyclicFifoUsage(P_UTIL_FIFO_BUFFER pUtilFifo)
-{
- uint32_t dataLength;
- uint8_t * pIn = (uint8_t *)pUtilFifo->pIn;
- uint8_t * pOut = (uint8_t *)pUtilFifo->pOut;
-
- if (pUtilFifo->bFull)
- {
- dataLength = pUtilFifo->pBuffEnd - pUtilFifo->pBuffStart + 1;
- }
- else
- {
- if(pIn >= pOut)
- {
- dataLength = pIn - pOut;
- }
- else
- {
- dataLength = pUtilFifo->pBuffEnd - pOut;
- dataLength += (pIn+1) - pUtilFifo->pBuffStart;
- }
- }
-
- return dataLength;
-}
-
-
-/**
- * Returns the available room for writing in Fifo Cyclic Buffer.
- */
-uint32_t phFriNfc_Llcp_CyclicFifoAvailable(P_UTIL_FIFO_BUFFER pUtilFifo)
-{
- uint32_t dataLength;
- uint32_t size;
- uint8_t * pIn = (uint8_t *)pUtilFifo->pIn;
- uint8_t * pOut = (uint8_t *)pUtilFifo->pOut;
-
- if (pUtilFifo->bFull)
- {
- dataLength = 0;
- }
- else
- {
- if(pIn >= pOut)
- {
- size = pUtilFifo->pBuffEnd - pUtilFifo->pBuffStart + 1;
- dataLength = size - (pIn - pOut);
- }
- else
- {
- dataLength = pOut - pIn;
- }
- }
-
- return dataLength;
-}
-
-
-
-uint32_t phFriNfc_Llcp_Header2Buffer( phFriNfc_Llcp_sPacketHeader_t *psHeader, uint8_t *pBuffer, uint32_t nOffset )
-{
- uint32_t nOriginalOffset = nOffset;
- pBuffer[nOffset++] = (uint8_t)((psHeader->dsap << 2) | (psHeader->ptype >> 2));
- pBuffer[nOffset++] = (uint8_t)((psHeader->ptype << 6) | psHeader->ssap);
- return nOffset - nOriginalOffset;
-}
-
-uint32_t phFriNfc_Llcp_Sequence2Buffer( phFriNfc_Llcp_sPacketSequence_t *psSequence, uint8_t *pBuffer, uint32_t nOffset )
-{
- uint32_t nOriginalOffset = nOffset;
- pBuffer[nOffset++] = (uint8_t)((psSequence->ns << 4) | (psSequence->nr));
- return nOffset - nOriginalOffset;
-}
-
-uint32_t phFriNfc_Llcp_Buffer2Header( uint8_t *pBuffer, uint32_t nOffset, phFriNfc_Llcp_sPacketHeader_t *psHeader )
-{
- psHeader->dsap = (pBuffer[nOffset] & 0xFC) >> 2;
- psHeader->ptype = ((pBuffer[nOffset] & 0x03) << 2) | ((pBuffer[nOffset+1] & 0xC0) >> 6);
- psHeader->ssap = pBuffer[nOffset+1] & 0x3F;
- return PHFRINFC_LLCP_PACKET_HEADER_SIZE;
-}
-
-uint32_t phFriNfc_Llcp_Buffer2Sequence( uint8_t *pBuffer, uint32_t nOffset, phFriNfc_Llcp_sPacketSequence_t *psSequence )
-{
- psSequence->ns = pBuffer[nOffset] >> 4;
- psSequence->nr = pBuffer[nOffset] & 0x0F;
- return PHFRINFC_LLCP_PACKET_SEQUENCE_SIZE;
-}
-
-
diff --git a/libnfc-nxp/phFriNfc_LlcpUtils.h b/libnfc-nxp/phFriNfc_LlcpUtils.h
deleted file mode 100644
index 9dcb95a..0000000
--- a/libnfc-nxp/phFriNfc_LlcpUtils.h
+++ /dev/null
@@ -1,138 +0,0 @@
-/*
- * Copyright (C) 2010 NXP Semiconductors
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-/**
- * \file phFriNfc_LlcpUtils.h
- * \brief NFC LLCP utils
- *
- * Project: NFC-FRI
- *
- */
-
-#ifndef PHFRINFC_LLCPUTILS_H
-#define PHFRINFC_LLCPUTILS_H
-
-/*include files*/
-#include
-#include
-#include
-#include
-#include
-
-/**
- * \name NFC Forum Logical Link Control Protocol Utils
- *
- * File: \ref phFriNfc_LlcpUtils.h
- *
- */
-
-/**
- * UTIL_FIFO_BUFFER - A Cyclic FIFO buffer
- * If pIn == pOut the buffer is empty.
- */
-typedef struct UTIL_FIFO_BUFFER
-{
- uint8_t *pBuffStart; /* Points to first valid location in buffer */
- uint8_t *pBuffEnd; /* Points to last valid location in buffer */
- volatile uint8_t *pIn; /* Points to 1 before where the next TU1 will enter buffer */
- volatile uint8_t *pOut; /* Points to 1 before where the next TU1 will leave buffer */
- volatile bool_t bFull; /* TRUE if buffer is full */
-}UTIL_FIFO_BUFFER, *P_UTIL_FIFO_BUFFER;
-
-
-/** \defgroup grp_fri_nfc_llcp NFC Forum Logical Link Control Protocol Component
- *
- * TODO
- *
- */
-
-NFCSTATUS phFriNfc_Llcp_DecodeTLV( phNfc_sData_t *psRawData,
- uint32_t *pOffset,
- uint8_t *pType,
- phNfc_sData_t *psValueBuffer );
-
-NFCSTATUS phFriNfc_Llcp_EncodeTLV( phNfc_sData_t *psValueBuffer,
- uint32_t *pOffset,
- uint8_t type,
- uint8_t length,
- uint8_t *pValue);
-
-NFCSTATUS phFriNfc_Llcp_AppendTLV( phNfc_sData_t *psValueBuffer,
- uint32_t nTlvOffset,
- uint32_t *pCurrentOffset,
- uint8_t length,
- uint8_t *pValue);
-
-void phFriNfc_Llcp_EncodeMIUX(uint16_t pMiux,
- uint8_t* pMiuxEncoded);
-
-void phFriNfc_Llcp_EncodeRW(uint8_t *pRw);
-
-/**
- * Initializes a Fifo Cyclic Buffer to point to some allocated memory.
- */
-void phFriNfc_Llcp_CyclicFifoInit(P_UTIL_FIFO_BUFFER sUtilFifo,
- const uint8_t *pBuffStart,
- uint32_t buffLength);
-
-/**
- * Clears the Fifo Cyclic Buffer - loosing any data that was in it.
- */
-void phFriNfc_Llcp_CyclicFifoClear(P_UTIL_FIFO_BUFFER sUtilFifo);
-
-
-/**
- * Attempts to write dataLength bytes to the specified Fifo Cyclic Buffer.
- */
-uint32_t phFriNfc_Llcp_CyclicFifoWrite(P_UTIL_FIFO_BUFFER sUtilFifo,
- uint8_t *pData,
- uint32_t dataLength);
-
-/**
- * Attempts to read dataLength bytes from the specified Fifo Cyclic Buffer.
- */
-uint32_t phFriNfc_Llcp_CyclicFifoFifoRead(P_UTIL_FIFO_BUFFER sUtilFifo,
- uint8_t *pBuffer,
- uint32_t dataLength);
-
-/**
- * Returns the number of bytes currently stored in Fifo Cyclic Buffer.
- */
-uint32_t phFriNfc_Llcp_CyclicFifoUsage(P_UTIL_FIFO_BUFFER sUtilFifo);
-
-/**
- * Returns the available room for writing in Fifo Cyclic Buffer.
- */
-uint32_t phFriNfc_Llcp_CyclicFifoAvailable(P_UTIL_FIFO_BUFFER sUtilFifo);
-
-uint32_t phFriNfc_Llcp_Header2Buffer( phFriNfc_Llcp_sPacketHeader_t *psHeader,
- uint8_t *pBuffer,
- uint32_t nOffset );
-
-uint32_t phFriNfc_Llcp_Sequence2Buffer( phFriNfc_Llcp_sPacketSequence_t *psSequence,
- uint8_t *pBuffer,
- uint32_t nOffset );
-
-uint32_t phFriNfc_Llcp_Buffer2Header( uint8_t *pBuffer,
- uint32_t nOffset,
- phFriNfc_Llcp_sPacketHeader_t *psHeader );
-
-uint32_t phFriNfc_Llcp_Buffer2Sequence( uint8_t *pBuffer,
- uint32_t nOffset,
- phFriNfc_Llcp_sPacketSequence_t *psSequence );
-
-
-#endif /* PHFRINFC_LLCPUTILS_H */
diff --git a/libnfc-nxp/phFriNfc_MapTools.c b/libnfc-nxp/phFriNfc_MapTools.c
deleted file mode 100644
index 2e05d33..0000000
--- a/libnfc-nxp/phFriNfc_MapTools.c
+++ /dev/null
@@ -1,228 +0,0 @@
-/*
- * Copyright (C) 2010 NXP Semiconductors
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-/*!
- * \file phFriNfc_MapTools.c
- * \brief NFC Ndef Internal Mapping File.
- *
- * Project: NFC-FRI
- *
- * $Date: Fri Oct 15 13:50:54 2010 $
- * $Author: ing02260 $
- * $Revision: 1.6 $
- * $Aliases: $
- *
- */
-
-#include
-#include
-
-#ifndef PH_FRINFC_MAP_MIFAREUL_DISABLED
-#include
-#endif /* PH_FRINFC_MAP_MIFAREUL_DISABLED*/
-
-#ifndef PH_FRINFC_MAP_MIFARESTD_DISABLED
-#include
-#endif /* PH_FRINFC_MAP_MIFARESTD_DISABLED */
-
-#ifndef PH_FRINFC_MAP_DESFIRE_DISABLED
-#include
-#endif /* PH_FRINFC_MAP_DESFIRE_DISABLED */
-
-#ifndef PH_FRINFC_MAP_FELICA_DISABLED
-#include
-#endif /* PH_FRINFC_MAP_FELICA_DISABLED */
-
-#include
-
-/*! \ingroup grp_file_attributes
- * \name NDEF Mapping
- *
- * File: \ref phFriNfc_MapTools.c
- * This file has functions which are used common across all the
- * typ1/type2/type3/type4 tags.
- *
- */
-/*@{*/
-#define PHFRINFCNDEFMAP_FILEREVISION "$Revision: 1.6 $"
-#define PHFRINFCNDEFMAP_FILEALIASES "$Aliases: $"
-/*@}*/
-
-NFCSTATUS phFriNfc_MapTool_SetCardState(phFriNfc_NdefMap_t *NdefMap,
- uint32_t Length)
-{
- NFCSTATUS Result = NFCSTATUS_SUCCESS;
- if(Length == PH_FRINFC_NDEFMAP_MFUL_VAL0)
- {
- /* As the NDEF LEN / TLV Len is Zero, irrespective of any state the card
- shall be set to INITIALIZED STATE*/
- NdefMap->CardState =(uint8_t) (((NdefMap->CardState ==
- PH_NDEFMAP_CARD_STATE_READ_ONLY) ||
- (NdefMap->CardState ==
- PH_NDEFMAP_CARD_STATE_INVALID))?
- PH_NDEFMAP_CARD_STATE_INVALID:
- PH_NDEFMAP_CARD_STATE_INITIALIZED);
- }
- else
- {
- switch(NdefMap->CardState)
- {
- case PH_NDEFMAP_CARD_STATE_INITIALIZED:
- NdefMap->CardState =(uint8_t) ((NdefMap->CardState ==
- PH_NDEFMAP_CARD_STATE_INVALID)?
- NdefMap->CardState:
- PH_NDEFMAP_CARD_STATE_READ_WRITE);
- break;
-
- case PH_NDEFMAP_CARD_STATE_READ_ONLY:
- NdefMap->CardState = (uint8_t)((NdefMap->CardState ==
- PH_NDEFMAP_CARD_STATE_INVALID)?
- NdefMap->CardState:
- PH_NDEFMAP_CARD_STATE_READ_ONLY);
- break;
-
- case PH_NDEFMAP_CARD_STATE_READ_WRITE:
- NdefMap->CardState = (uint8_t)((NdefMap->CardState ==
- PH_NDEFMAP_CARD_STATE_INVALID)?
- NdefMap->CardState:
- PH_NDEFMAP_CARD_STATE_READ_WRITE);
- if (NdefMap->CardType == PH_FRINFC_NDEFMAP_MIFARE_STD_1K_CARD ||
- NdefMap->CardType == PH_FRINFC_NDEFMAP_MIFARE_STD_4K_CARD)
- {
- if(NdefMap->StdMifareContainer.ReadOnlySectorIndex &&
- NdefMap->StdMifareContainer.SectorTrailerBlockNo == NdefMap->StdMifareContainer.currentBlock )
- {
- NdefMap->CardState = (uint8_t)((NdefMap->CardState ==
- PH_NDEFMAP_CARD_STATE_INVALID)?
- NdefMap->CardState:
- PH_NDEFMAP_CARD_STATE_READ_ONLY);
- }
- }
- break;
-
- default:
- NdefMap->CardState = PH_NDEFMAP_CARD_STATE_INVALID;
- Result = PHNFCSTVAL(CID_FRI_NFC_NDEF_MAP,
- NFCSTATUS_NO_NDEF_SUPPORT);
- break;
- }
- }
- Result = ((NdefMap->CardState ==
- PH_NDEFMAP_CARD_STATE_INVALID)?
- PHNFCSTVAL(CID_FRI_NFC_NDEF_MAP,
- NFCSTATUS_NO_NDEF_SUPPORT):
- Result);
- return Result;
-}
-
-/* To check mapping spec version */
-
-NFCSTATUS phFriNfc_MapTool_ChkSpcVer( const phFriNfc_NdefMap_t *NdefMap,
- uint8_t VersionIndex)
-{
- NFCSTATUS status = NFCSTATUS_SUCCESS;
-
- uint8_t TagVerNo = NdefMap->SendRecvBuf[VersionIndex];
-
- if ( TagVerNo == 0 )
- {
- /*Return Status Error “ Invalid Format”*/
- status = PHNFCSTVAL(CID_FRI_NFC_NDEF_MAP,NFCSTATUS_INVALID_FORMAT);
- }
- else
- {
- switch (NdefMap->CardType)
- {
- case PH_FRINFC_NDEFMAP_MIFARE_STD_1K_CARD:
- case PH_FRINFC_NDEFMAP_MIFARE_STD_4K_CARD:
- {
- /* calculate the major and minor version number of Mifare std version number */
- status = (( (( PH_NFCFRI_MFSTDMAP_NFCDEV_MAJOR_VER_NUM ==
- PH_NFCFRI_MFSTDMAP_GET_MAJOR_TAG_VERNO(TagVerNo ) )&&
- ( PH_NFCFRI_MFSTDMAP_NFCDEV_MINOR_VER_NUM ==
- PH_NFCFRI_MFSTDMAP_GET_MINOR_TAG_VERNO(TagVerNo))) ||
- (( PH_NFCFRI_MFSTDMAP_NFCDEV_MAJOR_VER_NUM ==
- PH_NFCFRI_MFSTDMAP_GET_MAJOR_TAG_VERNO(TagVerNo ) )&&
- ( PH_NFCFRI_MFSTDMAP_NFCDEV_MINOR_VER_NUM <
- PH_NFCFRI_MFSTDMAP_GET_MINOR_TAG_VERNO(TagVerNo) )))?
- NFCSTATUS_SUCCESS:
- PHNFCSTVAL(CID_FRI_NFC_NDEF_MAP,
- NFCSTATUS_INVALID_FORMAT));
- break;
- }
-
-#ifdef DESFIRE_EV1
- case PH_FRINFC_NDEFMAP_ISO14443_4A_CARD_EV1:
- {
- /* calculate the major and minor version number of T3VerNo */
- if( (( PH_NFCFRI_NDEFMAP_NFCDEV_MAJOR_VER_NUM_2 ==
- PH_NFCFRI_NDEFMAP_GET_MAJOR_TAG_VERNO(TagVerNo ) )&&
- ( PH_NFCFRI_NDEFMAP_NFCDEV_MINOR_VER_NUM ==
- PH_NFCFRI_NDEFMAP_GET_MINOR_TAG_VERNO(TagVerNo))) ||
- (( PH_NFCFRI_NDEFMAP_NFCDEV_MAJOR_VER_NUM_2 ==
- PH_NFCFRI_NDEFMAP_GET_MAJOR_TAG_VERNO(TagVerNo ) )&&
- ( PH_NFCFRI_NDEFMAP_NFCDEV_MINOR_VER_NUM <
- PH_NFCFRI_NDEFMAP_GET_MINOR_TAG_VERNO(TagVerNo) )))
- {
- status = PHNFCSTVAL(CID_NFC_NONE,NFCSTATUS_SUCCESS);
- }
- else
- {
- if (( PH_NFCFRI_NDEFMAP_NFCDEV_MAJOR_VER_NUM_2 <
- PH_NFCFRI_NDEFMAP_GET_MAJOR_TAG_VERNO(TagVerNo) ) ||
- ( PH_NFCFRI_NDEFMAP_NFCDEV_MAJOR_VER_NUM_2 >
- PH_NFCFRI_NDEFMAP_GET_MAJOR_TAG_VERNO(TagVerNo)))
- {
- status = PHNFCSTVAL(CID_FRI_NFC_NDEF_MAP,NFCSTATUS_INVALID_FORMAT);
- }
- }
- break;
- }
-#endif /* #ifdef DESFIRE_EV1 */
-
- default:
- {
- /* calculate the major and minor version number of T3VerNo */
- if( (( PH_NFCFRI_NDEFMAP_NFCDEV_MAJOR_VER_NUM ==
- PH_NFCFRI_NDEFMAP_GET_MAJOR_TAG_VERNO(TagVerNo ) )&&
- ( PH_NFCFRI_NDEFMAP_NFCDEV_MINOR_VER_NUM ==
- PH_NFCFRI_NDEFMAP_GET_MINOR_TAG_VERNO(TagVerNo))) ||
- (( PH_NFCFRI_NDEFMAP_NFCDEV_MAJOR_VER_NUM ==
- PH_NFCFRI_NDEFMAP_GET_MAJOR_TAG_VERNO(TagVerNo ) )&&
- ( PH_NFCFRI_NDEFMAP_NFCDEV_MINOR_VER_NUM <
- PH_NFCFRI_NDEFMAP_GET_MINOR_TAG_VERNO(TagVerNo) )))
- {
- status = PHNFCSTVAL(CID_NFC_NONE,NFCSTATUS_SUCCESS);
- }
- else
- {
- if (( PH_NFCFRI_NDEFMAP_NFCDEV_MAJOR_VER_NUM <
- PH_NFCFRI_NDEFMAP_GET_MAJOR_TAG_VERNO(TagVerNo) ) ||
- ( PH_NFCFRI_NDEFMAP_NFCDEV_MAJOR_VER_NUM >
- PH_NFCFRI_NDEFMAP_GET_MAJOR_TAG_VERNO(TagVerNo)))
- {
- status = PHNFCSTVAL(CID_FRI_NFC_NDEF_MAP,NFCSTATUS_INVALID_FORMAT);
- }
- }
- break;
- }
-
-
- }
- }
-
- return (status);
-}
diff --git a/libnfc-nxp/phFriNfc_MapTools.h b/libnfc-nxp/phFriNfc_MapTools.h
deleted file mode 100644
index e9eda20..0000000
--- a/libnfc-nxp/phFriNfc_MapTools.h
+++ /dev/null
@@ -1,95 +0,0 @@
-/*
- * Copyright (C) 2010 NXP Semiconductors
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-/*
- * \file phFriNfc_MapTools.h
- * \brief NFC Internal Ndef Mapping File.
- *
- * Project: NFC-FRI
- *
- * $Date: Fri Oct 15 13:50:54 2010 $
- * $Author: ing02260 $
- * $Revision: 1.6 $
- * $Aliases: $
- *
- */
-
-#ifndef PHFRINFC_MAPTOOLS_H
-#define PHFRINFC_MAPTOOLS_H
-
-#include
-#ifdef PH_HAL4_ENABLE
-#include
-#else
-#include